diff --git a/packages/schemas/src/foundations/jsonb-types.ts b/packages/schemas/src/foundations/jsonb-types.ts index 9cfb41065..c2720e50f 100644 --- a/packages/schemas/src/foundations/jsonb-types.ts +++ b/packages/schemas/src/foundations/jsonb-types.ts @@ -200,3 +200,24 @@ export type Translation = { export const translationGuard: z.ZodType = z.lazy(() => z.record(z.string().or(translationGuard)) ); + +/** + * Hooks + */ + +export type HookConfig = { + /** We don't need `type` since v1 only has web hook */ + // type: 'web'; + /** Method fixed to `POST` */ + url: string; + /** Additional headers that attach to the request */ + headers: Record; + /** Only retry when status code >= 500 */ + retries: number; // +}; + +export const hookConfigGuard: z.ZodType = z.object({ + url: z.string(), + headers: z.record(z.string()), + retries: z.number(), +}); diff --git a/packages/schemas/tables/hooks.sql b/packages/schemas/tables/hooks.sql new file mode 100644 index 000000000..d879fb6c0 --- /dev/null +++ b/packages/schemas/tables/hooks.sql @@ -0,0 +1,9 @@ +create table hooks ( + id varchar(128) not null, + event varchar(128) not null, + config jsonb /* @use HookConfig */ not null, + created_at timestamptz not null default(now()), + primary key (id) +); + +create index hooks__event on hooks (event);