feat: Added Webhooks in Management API V2 (#4949)

Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
This commit is contained in:
victorvhs017
2025-03-25 11:28:44 -03:00
committed by GitHub
parent afb39e4aba
commit 46f06f4c0e
68 changed files with 3029 additions and 709 deletions

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Webhook" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP;

View File

@@ -48,7 +48,7 @@ model Webhook {
id String @id @default(cuid())
name String?
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
updatedAt DateTime @default(now()) @updatedAt @map(name: "updated_at")
url String
source WebhookSource @default(user)
environment Environment @relation(fields: [environmentId], references: [id], onDelete: Cascade)

View File

@@ -0,0 +1,5 @@
export enum PrismaErrorType {
UniqueConstraintViolation = "P2002",
RecordDoesNotExist = "P2015",
RelatedRecordDoesNotExist = "P2025",
}

View File

@@ -0,0 +1,41 @@
import type { Organization } from "@prisma/client";
import { z } from "zod";
import { extendZodWithOpenApi } from "zod-openapi";
extendZodWithOpenApi(z);
export const ZOrganizationWhiteLabel = z.object({
logoUrl: z.string().nullable(),
});
export const ZOrganizationBilling = z.object({
stripeCustomerId: z.string().nullable(),
plan: z.enum(["free", "startup", "scale", "enterprise"]).default("free"),
period: z.enum(["monthly", "yearly"]).default("monthly"),
limits: z
.object({
projects: z.number().nullable(),
monthly: z.object({
responses: z.number().nullable(),
miu: z.number().nullable(),
}),
})
.default({
projects: 3,
monthly: {
responses: 1500,
miu: 2000,
},
}),
periodStart: z.coerce.date().nullable(),
});
export const ZOrganization = z.object({
id: z.string().cuid2(),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
name: z.string(),
whitelabel: ZOrganizationWhiteLabel,
billing: ZOrganizationBilling as z.ZodType<Organization["billing"]>,
isAIEnabled: z.boolean().default(false) as z.ZodType<Organization["isAIEnabled"]>,
}) satisfies z.ZodType<Organization>;

View File

@@ -1,14 +1,42 @@
import type { Webhook } from "@prisma/client";
import { z } from "zod";
import { extendZodWithOpenApi } from "zod-openapi";
extendZodWithOpenApi(z);
export const ZWebhook = z.object({
id: z.string().cuid2(),
name: z.string().nullable(),
createdAt: z.date(),
updatedAt: z.date(),
url: z.string().url(),
source: z.enum(["user", "zapier", "make", "n8n"]),
environmentId: z.string().cuid2(),
triggers: z.array(z.enum(["responseFinished", "responseCreated", "responseUpdated"])),
surveyIds: z.array(z.string().cuid2()),
id: z.string().cuid2().openapi({
description: "The ID of the webhook",
}),
name: z.string().nullable().openapi({
description: "The name of the webhook",
}),
createdAt: z.date().openapi({
description: "The date and time the webhook was created",
example: "2021-01-01T00:00:00.000Z",
}),
updatedAt: z.date().openapi({
description: "The date and time the webhook was last updated",
example: "2021-01-01T00:00:00.000Z",
}),
url: z.string().url().openapi({
description: "The URL of the webhook",
}),
source: z.enum(["user", "zapier", "make", "n8n"]).openapi({
description: "The source of the webhook",
}),
environmentId: z.string().cuid2().openapi({
description: "The ID of the environment",
}),
triggers: z.array(z.enum(["responseFinished", "responseCreated", "responseUpdated"])).openapi({
description: "The triggers of the webhook",
}),
surveyIds: z.array(z.string().cuid2()).openapi({
description: "The IDs of the surveys ",
}),
}) satisfies z.ZodType<Webhook>;
ZWebhook.openapi({
ref: "webhook",
description: "A webhook",
});