cal/packages/prisma/zod/webhook.ts
Carina Wollendorfer 84efda07e9
Team webhooks (#8917)
* allow event type specific webhooks for all event types

* first version of team webhooks

* add empty view

* design fixes when no teams + invalidate query on delete/update

* linke to new webhooks page with teamId in query

* make one button with dropdown instead of a button for every team

* add subtitle to dropdown

* add avatar fallback

* authorization when editing webhook

* fix event type webhooks

* fix authorization for delete handler

* code clean up

* fix disabled switch

* add migration

* fix subscriberUrlReservered function and fix authorization

* fix type error

* fix type error

* fix switch not updating

* make sure webhooks are triggered for the correct even types

* code clean up

* only show teams were user has write access

* make webhooks read-only for members

* fix comment

* fix type error

* fix webhook tests for team event types

* implement feedback

* code clean up from feedback

* code clean up (feedback)

* throw error if param missing in subscriberUrlReservered

* handle null/undefined values in getWebhooks itself

* better variable naming

* better check if webhook is readonly

* create assertPartOfTeamWithRequiredAccessLevel to remove duplicate code

---------

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
Co-authored-by: alannnc <alannnc@gmail.com>
2023-05-23 01:15:29 +00:00

38 lines
1.2 KiB
TypeScript
Executable File

import * as z from "zod"
import * as imports from "../zod-utils"
import { WebhookTriggerEvents } from "@prisma/client"
import { CompleteUser, UserModel, CompleteTeam, TeamModel, CompleteEventType, EventTypeModel, CompleteApp, AppModel } from "./index"
export const _WebhookModel = z.object({
id: z.string(),
userId: z.number().int().nullish(),
teamId: z.number().int().nullish(),
eventTypeId: z.number().int().nullish(),
subscriberUrl: z.string().url(),
payloadTemplate: z.string().nullish(),
createdAt: z.date(),
active: z.boolean(),
eventTriggers: z.nativeEnum(WebhookTriggerEvents).array(),
appId: z.string().nullish(),
secret: z.string().nullish(),
})
export interface CompleteWebhook extends z.infer<typeof _WebhookModel> {
user?: CompleteUser | null
team?: CompleteTeam | null
eventType?: CompleteEventType | null
app?: CompleteApp | null
}
/**
* WebhookModel contains all relations on your model in addition to the scalars
*
* NOTE: Lazy required in case of potential circular dependencies within schema
*/
export const WebhookModel: z.ZodSchema<CompleteWebhook> = z.lazy(() => _WebhookModel.extend({
user: UserModel.nullish(),
team: TeamModel.nullish(),
eventType: EventTypeModel.nullish(),
app: AppModel.nullish(),
}))