Skip to content
File

Blob: src/worker/contracts/webhook.ts

typescript46 lines
1import { eg, type TypeFromCodec } from "@cloudflare/util-en-garde";
2import {
3 BranchName,
4 CommitSha,
5 ProjectId,
6 RunId,
7 UnixTimestampMs,
8 WebhookProvider,
9 WebhookDeliveryOutcome,
10 WebhookEventKind,
11} from "@/contracts";
12export const WebhookTriggerPayload = eg.exactStrict(
13 eg.object({
14 provider: WebhookProvider,
15 deliveryId: eg.string,
16 eventKind: WebhookEventKind,
17 eventName: eg.string,
18 repoUrl: eg.string,
19 ref: eg.union([eg.string, eg.null]),
20 branch: eg.union([BranchName, eg.null]),
21 commitSha: eg.union([CommitSha, eg.null]),
22 beforeSha: eg.union([CommitSha, eg.null]),
23 }),
24);
25export type WebhookTriggerPayload = TypeFromCodec<typeof WebhookTriggerPayload>;
26export const RecordVerifiedWebhookDeliveryInput = eg.exactStrict(
27 eg.object({
28 projectId: ProjectId,
29 payload: WebhookTriggerPayload,
30 outcome: WebhookDeliveryOutcome,
31 verifiedWebhookUpdatedAt: UnixTimestampMs,
32 }),
33);
34export type RecordVerifiedWebhookDeliveryInput = TypeFromCodec<typeof RecordVerifiedWebhookDeliveryInput>;
35export const RecordVerifiedWebhookDeliveryResult = eg.exactStrict(
36 eg.object({
37 outcome: WebhookDeliveryOutcome,
38 duplicate: eg.boolean,
39 runId: eg.union([RunId, eg.null]),
40 queuedAt: eg.union([UnixTimestampMs, eg.null]),
41 executable: eg.union([eg.boolean, eg.null]),
42 staleVerification: eg.boolean,
43 }),
44);
45export type RecordVerifiedWebhookDeliveryResult = TypeFromCodec<typeof RecordVerifiedWebhookDeliveryResult>;