mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-06 05:40:02 -06:00
feat: Added Webhooks in Management API V2 (#4949)
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Webhook" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP;
|
||||
@@ -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)
|
||||
|
||||
5
packages/database/types/error.ts
Normal file
5
packages/database/types/error.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export enum PrismaErrorType {
|
||||
UniqueConstraintViolation = "P2002",
|
||||
RecordDoesNotExist = "P2015",
|
||||
RelatedRecordDoesNotExist = "P2025",
|
||||
}
|
||||
41
packages/database/zod/organizations.ts
Normal file
41
packages/database/zod/organizations.ts
Normal 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>;
|
||||
@@ -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",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user