The Open Source DocuSign Alternative.
TypeScript digital-signaturedocument-signingdocusign-alternativee-signatureesignesignaturenext-authnextjsopen-sourcepades-standardpdfpdf-signpdf-signaturepostgresqlprismaself-hostedsigningtypescript
chore: use cuids for webhooks
Mythiec2daa964c00d
diff --git a/apps/web/src/app/(dashboard)/settings/webhooks/[id]/page.tsx b/apps/web/src/app/(dashboard)/settings/webhooks/[id]/page.tsxindex 9c1dd0307..c451482d4 100644--- a/apps/web/src/app/(dashboard)/settings/webhooks/[id]/page.tsx+++ b/apps/web/src/app/(dashboard)/settings/webhooks/[id]/page.tsx@@ -33,7 +33,7 @@ type TEditWebhookFormSchema = z.infer<typeof ZEditWebhookFormSchema>;export type WebhookPageOptions = {params: {- id: number;+ id: string;};};@@ -43,7 +43,7 @@ export default function WebhookPage({ params }: WebhookPageOptions) {const { data: webhook, isLoading } = trpc.webhook.getWebhookById.useQuery({- id: Number(params.id),+ id: params.id,},{ enabled: !!params.id },);@@ -63,7 +63,7 @@ export default function WebhookPage({ params }: WebhookPageOptions) {const onSubmit = async (data: TEditWebhookFormSchema) => {try {await updateWebhook({- id: Number(params.id),+ id: params.id,...data,});diff --git a/packages/lib/server-only/webhooks/delete-webhook-by-id.ts b/packages/lib/server-only/webhooks/delete-webhook-by-id.tsindex 306d0ca9c..7821d310d 100644--- a/packages/lib/server-only/webhooks/delete-webhook-by-id.ts+++ b/packages/lib/server-only/webhooks/delete-webhook-by-id.ts@@ -1,7 +1,7 @@import { prisma } from '@documenso/prisma';export type DeleteWebhookByIdOptions = {- id: number;+ id: string;userId: number;};diff --git a/packages/lib/server-only/webhooks/edit-webhook.ts b/packages/lib/server-only/webhooks/edit-webhook.tsindex 4177bb2bf..0717c5ad9 100644--- a/packages/lib/server-only/webhooks/edit-webhook.ts+++ b/packages/lib/server-only/webhooks/edit-webhook.ts@@ -3,7 +3,7 @@ import type { Prisma } from '@prisma/client';import { prisma } from '@documenso/prisma';export type EditWebhookOptions = {- id: number;+ id: string;data: Prisma.WebhookUpdateInput;userId: number;};diff --git a/packages/lib/server-only/webhooks/get-webhook-by-id.ts b/packages/lib/server-only/webhooks/get-webhook-by-id.tsindex 82dbb70ef..96fc2c4be 100644--- a/packages/lib/server-only/webhooks/get-webhook-by-id.ts+++ b/packages/lib/server-only/webhooks/get-webhook-by-id.ts@@ -1,7 +1,7 @@import { prisma } from '@documenso/prisma';export type GetWebhookByIdOptions = {- id: number;+ id: string;userId: number;};diff --git a/packages/lib/server-only/webhooks/zapier/subscribe.ts b/packages/lib/server-only/webhooks/zapier/subscribe.tsindex 6fa22ab5f..af12c1daa 100644--- a/packages/lib/server-only/webhooks/zapier/subscribe.ts+++ b/packages/lib/server-only/webhooks/zapier/subscribe.ts@@ -7,7 +7,9 @@ import { validateApiToken } from './validateApiToken';export const subscribeHandler = async (req: NextApiRequest, res: NextApiResponse) => {try {const { authorization } = req.headers;+const { webhookUrl, eventTrigger } = req.body;+const user = await validateApiToken({ authorization });const createdWebhook = await prisma.webhook.create({diff --git a/packages/lib/server-only/webhooks/zapier/unsubscribe.ts b/packages/lib/server-only/webhooks/zapier/unsubscribe.tsindex 30ee1e25a..7da0e8110 100644--- a/packages/lib/server-only/webhooks/zapier/unsubscribe.ts+++ b/packages/lib/server-only/webhooks/zapier/unsubscribe.ts@@ -7,7 +7,9 @@ import { validateApiToken } from './validateApiToken';export const unsubscribeHandler = async (req: NextApiRequest, res: NextApiResponse) => {try {const { authorization } = req.headers;+const { webhookId } = req.body;+const user = await validateApiToken({ authorization });const deletedWebhook = await prisma.webhook.delete({diff --git a/packages/prisma/migrations/20240227003622_migrate_to_cuids_for_webhooks/migration.sql b/packages/prisma/migrations/20240227003622_migrate_to_cuids_for_webhooks/migration.sqlnew file mode 100644index 000000000..cd8fd9589--- /dev/null+++ b/packages/prisma/migrations/20240227003622_migrate_to_cuids_for_webhooks/migration.sql@@ -0,0 +1,12 @@+/*+ Warnings:++ - The primary key for the `Webhook` table will be changed. If it partially fails, the table could be left without primary key constraint.++*/+-- AlterTable+ALTER TABLE "Webhook" DROP CONSTRAINT "Webhook_pkey",+ALTER COLUMN "id" DROP DEFAULT,+ALTER COLUMN "id" SET DATA TYPE TEXT,+ADD CONSTRAINT "Webhook_pkey" PRIMARY KEY ("id");+DROP SEQUENCE "Webhook_id_seq";diff --git a/packages/prisma/schema.prisma b/packages/prisma/schema.prismaindex bc6bbfd4b..bac5de1b7 100644--- a/packages/prisma/schema.prisma+++ b/packages/prisma/schema.prisma@@ -19,19 +19,19 @@ enum Role {}model User {- id Int @id @default(autoincrement())+ id Int @id @default(autoincrement())name String?- customerId String? @unique- email String @unique+ customerId String? @unique+ email String @uniqueemailVerified DateTime?password String?source String?signature String?- createdAt DateTime @default(now())- updatedAt DateTime @default(now()) @updatedAt- lastSignedIn DateTime @default(now())- roles Role[] @default([USER])- identityProvider IdentityProvider @default(DOCUMENSO)+ createdAt DateTime @default(now())+ updatedAt DateTime @default(now()) @updatedAt+ lastSignedIn DateTime @default(now())+ roles Role[] @default([USER])+ identityProvider IdentityProvider @default(DOCUMENSO)accounts Account[]sessions Session[]Document Document[]@@ -41,9 +41,9 @@ model User {ownedPendingTeams TeamPending[]teamMembers TeamMember[]twoFactorSecret String?- twoFactorEnabled Boolean @default(false)+ twoFactorEnabled Boolean @default(false)twoFactorBackupCodes String?-+VerificationToken VerificationToken[]ApiToken ApiToken[]Template Template[]@@ -106,7 +106,7 @@ enum WebhookTriggerEvents {}model Webhook {- id Int @id @default(autoincrement())+ id String @id @default(cuid())webhookUrl StringeventTriggers WebhookTriggerEvents[]secret String?diff --git a/packages/trpc/server/webhook-router/schema.ts b/packages/trpc/server/webhook-router/schema.tsindex def654a70..8e0e31f42 100644--- a/packages/trpc/server/webhook-router/schema.ts+++ b/packages/trpc/server/webhook-router/schema.ts@@ -11,22 +11,22 @@ export const ZCreateWebhookFormSchema = z.object({enabled: z.boolean(),});+export type TCreateWebhookFormSchema = z.infer<typeof ZCreateWebhookFormSchema>;+export const ZGetWebhookByIdQuerySchema = z.object({- id: z.number(),+ id: z.string(),});+export type TGetWebhookByIdQuerySchema = z.infer<typeof ZGetWebhookByIdQuerySchema>;+export const ZEditWebhookMutationSchema = ZCreateWebhookFormSchema.extend({- id: z.number(),+ id: z.string(),});+export type TEditWebhookMutationSchema = z.infer<typeof ZEditWebhookMutationSchema>;+export const ZDeleteWebhookMutationSchema = z.object({- id: z.number(),+ id: z.string(),});-export type TCreateWebhookFormSchema = z.infer<typeof ZCreateWebhookFormSchema>;--export type TGetWebhookByIdQuerySchema = z.infer<typeof ZGetWebhookByIdQuerySchema>;-export type TDeleteWebhookMutationSchema = z.infer<typeof ZDeleteWebhookMutationSchema>;--export type TEditWebhookMutationSchema = z.infer<typeof ZEditWebhookMutationSchema>;