diff options
Diffstat (limited to 'packages/shared')
| -rw-r--r-- | packages/shared/config.ts | 8 | ||||
| -rw-r--r-- | packages/shared/queues.ts | 8 | ||||
| -rw-r--r-- | packages/shared/types/webhooks.ts | 30 |
3 files changed, 34 insertions, 12 deletions
diff --git a/packages/shared/config.ts b/packages/shared/config.ts index df9a5764..9e5741b7 100644 --- a/packages/shared/config.ts +++ b/packages/shared/config.ts @@ -56,12 +56,6 @@ const allEnv = z.object({ DATA_DIR: z.string().default(""), MAX_ASSET_SIZE_MB: z.coerce.number().default(4), INFERENCE_LANG: z.string().default("english"), - WEBHOOK_URLS: z - .string() - .transform((val) => val.split(",")) - .pipe(z.array(z.string().url())) - .optional(), - WEBHOOK_TOKEN: z.string().optional(), WEBHOOK_TIMEOUT_SEC: z.coerce.number().default(5), WEBHOOK_RETRY_TIMES: z.coerce.number().int().min(0).default(3), // Build only flag @@ -143,8 +137,6 @@ const serverConfigSchema = allEnv.transform((val) => { disableNewReleaseCheck: val.DISABLE_NEW_RELEASE_CHECK, usingLegacySeparateContainers: val.USING_LEGACY_SEPARATE_CONTAINERS, webhook: { - urls: val.WEBHOOK_URLS, - token: val.WEBHOOK_TOKEN, timeoutSec: val.WEBHOOK_TIMEOUT_SEC, retryTimes: val.WEBHOOK_RETRY_TIMES, }, diff --git a/packages/shared/queues.ts b/packages/shared/queues.ts index b0002a29..cbe58f8d 100644 --- a/packages/shared/queues.ts +++ b/packages/shared/queues.ts @@ -159,10 +159,10 @@ export const AssetPreprocessingQueue = }, ); -//Webhook worker +// Webhook worker export const zWebhookRequestSchema = z.object({ bookmarkId: z.string(), - operation: z.enum(["crawled"]), + operation: z.enum(["crawled", "created", "edited"]), }); export type ZWebhookRequest = z.infer<typeof zWebhookRequestSchema>; export const WebhookQueue = new SqliteQueue<ZWebhookRequest>( @@ -176,9 +176,9 @@ export const WebhookQueue = new SqliteQueue<ZWebhookRequest>( }, ); -export async function triggerWebhookWorker( +export async function triggerWebhook( bookmarkId: string, - operation: "crawled", + operation: ZWebhookRequest["operation"], ) { await WebhookQueue.enqueue({ bookmarkId, diff --git a/packages/shared/types/webhooks.ts b/packages/shared/types/webhooks.ts new file mode 100644 index 00000000..8d425ad9 --- /dev/null +++ b/packages/shared/types/webhooks.ts @@ -0,0 +1,30 @@ +import { z } from "zod"; + +const MAX_WEBHOOK_URL_LENGTH = 500; +const MAX_WEBHOOK_TOKEN_LENGTH = 100; + +export const zWebhookEventSchema = z.enum(["created", "edited", "crawled"]); +export type ZWebhookEvent = z.infer<typeof zWebhookEventSchema>; + +export const zWebhookSchema = z.object({ + id: z.string(), + url: z.string().url(), + events: z.array(zWebhookEventSchema), + hasToken: z.boolean(), + createdAt: z.date(), +}); + +export type ZWebhook = z.infer<typeof zWebhookSchema>; + +export const zNewWebhookSchema = z.object({ + url: z.string().max(MAX_WEBHOOK_URL_LENGTH).url(), + events: z.array(zWebhookEventSchema).min(1), + token: z.string().max(MAX_WEBHOOK_TOKEN_LENGTH).optional(), +}); + +export const zUpdateWebhookSchema = z.object({ + webhookId: z.string(), + url: z.string().max(MAX_WEBHOOK_URL_LENGTH).url().optional(), + events: z.array(zWebhookEventSchema).min(1).optional(), + token: z.string().max(MAX_WEBHOOK_TOKEN_LENGTH).nullish(), +}); |
