@samva/webhooks 0.21.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,591 +0,0 @@
1
- //#region src/decoder.gen.ts
2
- const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3
- const validate0 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate1(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate3(value["data"]));
4
- const validate1 = (value) => typeof value === "string" && value === "message.sent";
5
- const validate2 = (value) => typeof value === "string";
6
- const validate3 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "channel") && Object.hasOwn(value, "messageId") && Object.hasOwn(value, "organizationId") && (!Object.hasOwn(value, "mailboxId") || validate4(value["mailboxId"])) && (!Object.hasOwn(value, "channel") || validate7(value["channel"])) && (!Object.hasOwn(value, "status") || validate8(value["status"])) && (!Object.hasOwn(value, "metadata") || validate11(value["metadata"])) && (!Object.hasOwn(value, "cost") || validate14(value["cost"])) && (!Object.hasOwn(value, "recipient") || validate8(value["recipient"])) && (!Object.hasOwn(value, "occurredAt") || validate8(value["occurredAt"])) && (!Object.hasOwn(value, "failureReason") || validate8(value["failureReason"])) && (!Object.hasOwn(value, "errorCode") || validate8(value["errorCode"])) && (!Object.hasOwn(value, "conversationId") || validate8(value["conversationId"])) && (!Object.hasOwn(value, "isBillable") || validate32(value["isBillable"])) && (!Object.hasOwn(value, "messageType") || validate8(value["messageType"])) && (!Object.hasOwn(value, "subject") || validate8(value["subject"])) && (!Object.hasOwn(value, "toEmails") || validate41(value["toEmails"])) && (!Object.hasOwn(value, "providerMessageId") || validate8(value["providerMessageId"])) && (!Object.hasOwn(value, "hasAttachments") || validate32(value["hasAttachments"])) && (!Object.hasOwn(value, "isAutoReply") || validate32(value["isAutoReply"])) && (!Object.hasOwn(value, "to") || validate8(value["to"])) && (!Object.hasOwn(value, "from") || validate8(value["from"])) && (!Object.hasOwn(value, "body") || validate8(value["body"])) && (!Object.hasOwn(value, "direction") || validate63(value["direction"])) && (!Object.hasOwn(value, "errorMessage") || validate8(value["errorMessage"])) && (!Object.hasOwn(value, "messageId") || validate2(value["messageId"])) && (!Object.hasOwn(value, "organizationId") || validate2(value["organizationId"]));
7
- const validate4 = (value) => validate5(value) || validate6(value);
8
- const validate5 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^mbx_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
9
- const validate6 = (value) => value === null;
10
- const validate7 = (value) => typeof value === "string" && value === "email";
11
- const validate8 = (value) => validate2(value) || validate6(value);
12
- const validate11 = (value) => validate12(value) || validate6(value);
13
- const validate12 = (value) => isObject(value);
14
- const validate14 = (value) => validate15(value) || validate6(value);
15
- const validate15 = (value) => typeof value === "number" && Number.isFinite(value);
16
- const validate32 = (value) => validate33(value) || validate6(value);
17
- const validate33 = (value) => typeof value === "boolean";
18
- const validate41 = (value) => validate42(value) || validate6(value);
19
- const validate42 = (value) => Array.isArray(value) && Array.isArray(value) && value.every(validate2);
20
- const validate63 = (value) => validate64(value) || validate6(value);
21
- const validate64 = (value) => typeof value === "string" && (value === "inbound" || value === "outbound");
22
- const validate71 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate72(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate3(value["data"]));
23
- const validate72 = (value) => typeof value === "string" && value === "message.delivered";
24
- const validate142 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate143(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate3(value["data"]));
25
- const validate143 = (value) => typeof value === "string" && value === "message.failed";
26
- const validate213 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate214(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate216(value["data"]));
27
- const validate214 = (value) => typeof value === "string" && value === "message.bounced";
28
- const validate216 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "channel") && Object.hasOwn(value, "recipient") && Object.hasOwn(value, "occurredAt") && Object.hasOwn(value, "messageId") && Object.hasOwn(value, "organizationId") && (!Object.hasOwn(value, "mailboxId") || validate4(value["mailboxId"])) && (!Object.hasOwn(value, "channel") || validate7(value["channel"])) && (!Object.hasOwn(value, "status") || validate8(value["status"])) && (!Object.hasOwn(value, "metadata") || validate11(value["metadata"])) && (!Object.hasOwn(value, "cost") || validate14(value["cost"])) && (!Object.hasOwn(value, "recipient") || validate2(value["recipient"])) && (!Object.hasOwn(value, "occurredAt") || validate2(value["occurredAt"])) && (!Object.hasOwn(value, "failureReason") || validate8(value["failureReason"])) && (!Object.hasOwn(value, "errorCode") || validate8(value["errorCode"])) && (!Object.hasOwn(value, "conversationId") || validate8(value["conversationId"])) && (!Object.hasOwn(value, "isBillable") || validate32(value["isBillable"])) && (!Object.hasOwn(value, "messageType") || validate8(value["messageType"])) && (!Object.hasOwn(value, "subject") || validate8(value["subject"])) && (!Object.hasOwn(value, "toEmails") || validate41(value["toEmails"])) && (!Object.hasOwn(value, "providerMessageId") || validate8(value["providerMessageId"])) && (!Object.hasOwn(value, "hasAttachments") || validate32(value["hasAttachments"])) && (!Object.hasOwn(value, "isAutoReply") || validate32(value["isAutoReply"])) && (!Object.hasOwn(value, "to") || validate8(value["to"])) && (!Object.hasOwn(value, "from") || validate8(value["from"])) && (!Object.hasOwn(value, "body") || validate8(value["body"])) && (!Object.hasOwn(value, "direction") || validate63(value["direction"])) && (!Object.hasOwn(value, "errorMessage") || validate8(value["errorMessage"])) && (!Object.hasOwn(value, "messageId") || validate2(value["messageId"])) && (!Object.hasOwn(value, "organizationId") || validate2(value["organizationId"]));
29
- const validate280 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate281(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate216(value["data"]));
30
- const validate281 = (value) => typeof value === "string" && value === "message.complained";
31
- const validate347 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate348(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate3(value["data"]));
32
- const validate348 = (value) => typeof value === "string" && value === "message.received";
33
- const validate418 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate419(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate421(value["data"]));
34
- const validate419 = (value) => typeof value === "string" && value === "message.opened";
35
- const validate421 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "messageId") && Object.hasOwn(value, "organizationId") && Object.hasOwn(value, "channel") && Object.hasOwn(value, "deliveryId") && Object.hasOwn(value, "recipient") && Object.hasOwn(value, "occurredAt") && Object.hasOwn(value, "firstOpen") && Object.hasOwn(value, "machine") && Object.hasOwn(value, "machineReason") && (!Object.hasOwn(value, "messageId") || validate422(value["messageId"])) && (!Object.hasOwn(value, "organizationId") || validate423(value["organizationId"])) && (!Object.hasOwn(value, "channel") || validate7(value["channel"])) && (!Object.hasOwn(value, "deliveryId") || validate425(value["deliveryId"])) && (!Object.hasOwn(value, "recipient") || validate2(value["recipient"])) && (!Object.hasOwn(value, "occurredAt") || validate2(value["occurredAt"])) && (!Object.hasOwn(value, "userAgent") || validate8(value["userAgent"])) && (!Object.hasOwn(value, "ipAddress") || validate8(value["ipAddress"])) && (!Object.hasOwn(value, "firstOpen") || validate33(value["firstOpen"])) && (!Object.hasOwn(value, "machine") || validate33(value["machine"])) && (!Object.hasOwn(value, "machineReason") || validate436(value["machineReason"])) && (!Object.hasOwn(value, "country") || validate8(value["country"])) && (!Object.hasOwn(value, "city") || validate8(value["city"])) && (!Object.hasOwn(value, "asn") || validate14(value["asn"])) && (!Object.hasOwn(value, "code") || validate8(value["code"])) && (!Object.hasOwn(value, "linkIndex") || validate14(value["linkIndex"])) && (!Object.hasOwn(value, "destinationUrl") || validate8(value["destinationUrl"])) && (!Object.hasOwn(value, "metadata") || validate11(value["metadata"])) && (!Object.hasOwn(value, "campaignId") || validate460(value["campaignId"])) && (!Object.hasOwn(value, "campaignRunId") || validate463(value["campaignRunId"]));
36
- const validate422 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^msg_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
37
- const validate423 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^org_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
38
- const validate425 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^mdel_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
39
- const validate436 = (value) => validate437(value) || validate6(value);
40
- const validate437 = (value) => typeof value === "string" && (value === "google-image-proxy" || value === "apple-mail-privacy" || value === "scanner-user-agent" || value === "scanner-asn" || value === "too-fast");
41
- const validate460 = (value) => validate461(value) || validate6(value);
42
- const validate461 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^camp_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
43
- const validate463 = (value) => validate464(value) || validate6(value);
44
- const validate464 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^crun_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
45
- const validate466 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate467(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate469(value["data"]));
46
- const validate467 = (value) => typeof value === "string" && value === "message.clicked";
47
- const validate469 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "messageId") && Object.hasOwn(value, "organizationId") && Object.hasOwn(value, "channel") && Object.hasOwn(value, "deliveryId") && Object.hasOwn(value, "recipient") && Object.hasOwn(value, "occurredAt") && Object.hasOwn(value, "url") && Object.hasOwn(value, "linkTags") && Object.hasOwn(value, "firstClick") && Object.hasOwn(value, "machine") && Object.hasOwn(value, "machineReason") && (!Object.hasOwn(value, "messageId") || validate422(value["messageId"])) && (!Object.hasOwn(value, "organizationId") || validate423(value["organizationId"])) && (!Object.hasOwn(value, "channel") || validate7(value["channel"])) && (!Object.hasOwn(value, "deliveryId") || validate425(value["deliveryId"])) && (!Object.hasOwn(value, "recipient") || validate2(value["recipient"])) && (!Object.hasOwn(value, "occurredAt") || validate2(value["occurredAt"])) && (!Object.hasOwn(value, "userAgent") || validate8(value["userAgent"])) && (!Object.hasOwn(value, "ipAddress") || validate8(value["ipAddress"])) && (!Object.hasOwn(value, "url") || validate2(value["url"])) && (!Object.hasOwn(value, "linkTags") || validate483(value["linkTags"])) && (!Object.hasOwn(value, "firstClick") || validate33(value["firstClick"])) && (!Object.hasOwn(value, "machine") || validate33(value["machine"])) && (!Object.hasOwn(value, "machineReason") || validate436(value["machineReason"])) && (!Object.hasOwn(value, "country") || validate8(value["country"])) && (!Object.hasOwn(value, "city") || validate8(value["city"])) && (!Object.hasOwn(value, "asn") || validate14(value["asn"])) && (!Object.hasOwn(value, "code") || validate8(value["code"])) && (!Object.hasOwn(value, "linkIndex") || validate14(value["linkIndex"])) && (!Object.hasOwn(value, "destinationUrl") || validate8(value["destinationUrl"])) && (!Object.hasOwn(value, "metadata") || validate11(value["metadata"])) && (!Object.hasOwn(value, "campaignId") || validate460(value["campaignId"])) && (!Object.hasOwn(value, "campaignRunId") || validate463(value["campaignRunId"]));
48
- const validate483 = (value) => isObject(value) && isObject(value) && Object.entries(value).every(([key, item]) => validate42(item));
49
- const validate518 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate519(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate521(value["data"]));
50
- const validate519 = (value) => typeof value === "string" && value === "contact.created";
51
- const validate521 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "contactId") && Object.hasOwn(value, "status") && Object.hasOwn(value, "name") && Object.hasOwn(value, "identities") && Object.hasOwn(value, "tags") && Object.hasOwn(value, "createdAt") && Object.hasOwn(value, "updatedAt") && (!Object.hasOwn(value, "contactId") || validate522(value["contactId"])) && (!Object.hasOwn(value, "status") || validate523(value["status"])) && (!Object.hasOwn(value, "name") || validate2(value["name"])) && (!Object.hasOwn(value, "displayName") || validate525(value["displayName"])) && (!Object.hasOwn(value, "identities") || validate530(value["identities"])) && (!Object.hasOwn(value, "tags") || validate42(value["tags"])) && (!Object.hasOwn(value, "externalId") || validate525(value["externalId"])) && (!Object.hasOwn(value, "createdAt") || validate2(value["createdAt"])) && (!Object.hasOwn(value, "updatedAt") || validate2(value["updatedAt"]));
52
- const validate522 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^contact_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
53
- const validate523 = (value) => typeof value === "string" && (value === "active" || value === "paused" || value === "blocked" || value === "archived");
54
- const validate525 = (value) => validate8(value) || validate6(value);
55
- const validate530 = (value) => Array.isArray(value) && Array.isArray(value) && value.every(validate531);
56
- const validate531 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "identifier") && Object.hasOwn(value, "verified") && (!Object.hasOwn(value, "type") || validate532(value["type"])) && (!Object.hasOwn(value, "identifier") || validate2(value["identifier"])) && (!Object.hasOwn(value, "verified") || validate33(value["verified"]));
57
- const validate532 = (value) => typeof value === "string" && (value === "email" || value === "phone");
58
- const validate544 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate545(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate521(value["data"]));
59
- const validate545 = (value) => typeof value === "string" && value === "contact.updated";
60
- const validate570 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate571(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate521(value["data"]));
61
- const validate571 = (value) => typeof value === "string" && value === "contact.deleted";
62
- const validate596 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate597(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate599(value["data"]));
63
- const validate597 = (value) => typeof value === "string" && value === "contact.subscribed";
64
- const validate599 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "organizationId") && Object.hasOwn(value, "contactId") && Object.hasOwn(value, "groupId") && Object.hasOwn(value, "groupName") && Object.hasOwn(value, "source") && Object.hasOwn(value, "occurredAt") && (!Object.hasOwn(value, "organizationId") || validate423(value["organizationId"])) && (!Object.hasOwn(value, "contactId") || validate522(value["contactId"])) && (!Object.hasOwn(value, "email") || validate8(value["email"])) && (!Object.hasOwn(value, "groupId") || validate2(value["groupId"])) && (!Object.hasOwn(value, "groupName") || validate2(value["groupName"])) && (!Object.hasOwn(value, "contactGroupId") || validate607(value["contactGroupId"])) && (!Object.hasOwn(value, "unsubscribeGroupId") || validate610(value["unsubscribeGroupId"])) && (!Object.hasOwn(value, "consentIp") || validate8(value["consentIp"])) && (!Object.hasOwn(value, "consentSource") || validate8(value["consentSource"])) && (!Object.hasOwn(value, "source") || validate619(value["source"])) && (!Object.hasOwn(value, "messageId") || validate620(value["messageId"])) && (!Object.hasOwn(value, "campaignId") || validate460(value["campaignId"])) && (!Object.hasOwn(value, "campaignRunId") || validate463(value["campaignRunId"])) && (!Object.hasOwn(value, "occurredAt") || validate2(value["occurredAt"]));
65
- const validate607 = (value) => validate608(value) || validate6(value);
66
- const validate608 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^cgrp_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
67
- const validate610 = (value) => validate611(value) || validate6(value);
68
- const validate611 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^unsub_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
69
- const validate619 = (value) => typeof value === "string" && (value === "link" || value === "api" || value === "manual" || value === "complaint");
70
- const validate620 = (value) => validate422(value) || validate6(value);
71
- const validate630 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate631(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate599(value["data"]));
72
- const validate631 = (value) => typeof value === "string" && value === "contact.unsubscribed";
73
- const validate664 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate665(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate599(value["data"]));
74
- const validate665 = (value) => typeof value === "string" && value === "contact.resubscribed";
75
- const validate698 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate699(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate701(value["data"]));
76
- const validate699 = (value) => typeof value === "string" && value === "contact.consent_changed";
77
- const validate701 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "organizationId") && Object.hasOwn(value, "contactId") && Object.hasOwn(value, "identity") && Object.hasOwn(value, "channel") && Object.hasOwn(value, "status") && Object.hasOwn(value, "previousStatus") && Object.hasOwn(value, "source") && Object.hasOwn(value, "capturedAt") && (!Object.hasOwn(value, "organizationId") || validate423(value["organizationId"])) && (!Object.hasOwn(value, "contactId") || validate522(value["contactId"])) && (!Object.hasOwn(value, "identity") || validate704(value["identity"])) && (!Object.hasOwn(value, "channel") || validate7(value["channel"])) && (!Object.hasOwn(value, "status") || validate709(value["status"])) && (!Object.hasOwn(value, "previousStatus") || validate710(value["previousStatus"])) && (!Object.hasOwn(value, "source") || validate2(value["source"])) && (!Object.hasOwn(value, "capturedAt") || validate2(value["capturedAt"]));
78
- const validate704 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "id") && Object.hasOwn(value, "type") && Object.hasOwn(value, "identifier") && (!Object.hasOwn(value, "id") || validate705(value["id"])) && (!Object.hasOwn(value, "type") || validate532(value["type"])) && (!Object.hasOwn(value, "identifier") || validate2(value["identifier"]));
79
- const validate705 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^cident_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
80
- const validate709 = (value) => typeof value === "string" && (value === "opted_in" || value === "opted_out");
81
- const validate710 = (value) => validate709(value) || validate6(value);
82
- const validate715 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate716(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate718(value["data"]));
83
- const validate716 = (value) => typeof value === "string" && value === "conversation.created";
84
- const validate718 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "conversationId") && Object.hasOwn(value, "organizationId") && Object.hasOwn(value, "channels") && Object.hasOwn(value, "primaryChannel") && Object.hasOwn(value, "status") && Object.hasOwn(value, "createdAt") && Object.hasOwn(value, "updatedAt") && (!Object.hasOwn(value, "conversationId") || validate719(value["conversationId"])) && (!Object.hasOwn(value, "organizationId") || validate423(value["organizationId"])) && (!Object.hasOwn(value, "title") || validate525(value["title"])) && (!Object.hasOwn(value, "channels") || validate726(value["channels"])) && (!Object.hasOwn(value, "primaryChannel") || validate7(value["primaryChannel"])) && (!Object.hasOwn(value, "status") || validate729(value["status"])) && (!Object.hasOwn(value, "primaryContactId") || validate730(value["primaryContactId"])) && (!Object.hasOwn(value, "createdAt") || validate2(value["createdAt"])) && (!Object.hasOwn(value, "updatedAt") || validate2(value["updatedAt"]));
85
- const validate719 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^conv_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
86
- const validate726 = (value) => Array.isArray(value) && Array.isArray(value) && value.every(validate7);
87
- const validate729 = (value) => typeof value === "string" && (value === "active" || value === "waiting" || value === "resolved" || value === "escalated" || value === "archived");
88
- const validate730 = (value) => validate731(value) || validate6(value);
89
- const validate731 = (value) => validate522(value) || validate6(value);
90
- const validate737 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate738(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate718(value["data"]));
91
- const validate738 = (value) => typeof value === "string" && value === "conversation.updated";
92
- const validate759 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate760(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate718(value["data"]));
93
- const validate760 = (value) => typeof value === "string" && value === "conversation.archived";
94
- const validate781 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate782(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate784(value["data"]));
95
- const validate782 = (value) => typeof value === "string" && value === "webhook.created";
96
- const validate784 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "webhookId") && Object.hasOwn(value, "organizationId") && Object.hasOwn(value, "name") && Object.hasOwn(value, "url") && Object.hasOwn(value, "eventTypes") && Object.hasOwn(value, "channels") && Object.hasOwn(value, "status") && Object.hasOwn(value, "createdAt") && Object.hasOwn(value, "updatedAt") && (!Object.hasOwn(value, "webhookId") || validate785(value["webhookId"])) && (!Object.hasOwn(value, "organizationId") || validate423(value["organizationId"])) && (!Object.hasOwn(value, "name") || validate2(value["name"])) && (!Object.hasOwn(value, "url") || validate2(value["url"])) && (!Object.hasOwn(value, "eventTypes") || validate42(value["eventTypes"])) && (!Object.hasOwn(value, "channels") || validate41(value["channels"])) && (!Object.hasOwn(value, "status") || validate795(value["status"])) && (!Object.hasOwn(value, "createdAt") || validate2(value["createdAt"])) && (!Object.hasOwn(value, "updatedAt") || validate2(value["updatedAt"]));
97
- const validate785 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^wep_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
98
- const validate795 = (value) => typeof value === "string" && (value === "active" || value === "disabled");
99
- const validate798 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate799(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate784(value["data"]));
100
- const validate799 = (value) => typeof value === "string" && value === "webhook.updated";
101
- const validate815 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate816(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate784(value["data"]));
102
- const validate816 = (value) => typeof value === "string" && value === "webhook.deleted";
103
- const validate832 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate833(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate12(value["data"]));
104
- const validate833 = (value) => typeof value === "string" && value === "webhook.test";
105
- const validate836 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate837(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate839(value["data"]));
106
- const validate837 = (value) => typeof value === "string" && value === "domain.updated";
107
- const validate839 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "domainId") && Object.hasOwn(value, "organizationId") && Object.hasOwn(value, "domain") && Object.hasOwn(value, "previousPhase") && Object.hasOwn(value, "phase") && Object.hasOwn(value, "dns") && Object.hasOwn(value, "provider") && Object.hasOwn(value, "operationId") && Object.hasOwn(value, "checkedAt") && Object.hasOwn(value, "nextCheckAt") && Object.hasOwn(value, "failure") && Object.hasOwn(value, "updatedAt") && (!Object.hasOwn(value, "domainId") || validate840(value["domainId"])) && (!Object.hasOwn(value, "organizationId") || validate423(value["organizationId"])) && (!Object.hasOwn(value, "domain") || validate2(value["domain"])) && (!Object.hasOwn(value, "previousPhase") || validate843(value["previousPhase"])) && (!Object.hasOwn(value, "phase") || validate843(value["phase"])) && (!Object.hasOwn(value, "dns") || validate845(value["dns"])) && (!Object.hasOwn(value, "provider") || validate852(value["provider"])) && (!Object.hasOwn(value, "operationId") || validate862(value["operationId"])) && (!Object.hasOwn(value, "checkedAt") || validate8(value["checkedAt"])) && (!Object.hasOwn(value, "nextCheckAt") || validate8(value["nextCheckAt"])) && (!Object.hasOwn(value, "failure") || validate871(value["failure"])) && (!Object.hasOwn(value, "updatedAt") || validate2(value["updatedAt"]));
108
- const validate840 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^dom_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
109
- const validate843 = (value) => typeof value === "string" && (value === "dns-setup" || value === "provisioning" || value === "verifying" || value === "ready" || value === "degraded" || value === "failed");
110
- const validate845 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "observed") && Object.hasOwn(value, "total") && Object.hasOwn(value, "satisfied") && Object.hasOwn(value, "missing") && Object.hasOwn(value, "mismatch") && Object.hasOwn(value, "unknown") && (!Object.hasOwn(value, "observed") || validate33(value["observed"])) && (!Object.hasOwn(value, "total") || validate847(value["total"])) && (!Object.hasOwn(value, "satisfied") || validate847(value["satisfied"])) && (!Object.hasOwn(value, "missing") || validate847(value["missing"])) && (!Object.hasOwn(value, "mismatch") || validate847(value["mismatch"])) && (!Object.hasOwn(value, "unknown") || validate847(value["unknown"]));
111
- const validate847 = (value) => typeof value === "number" && Number.isInteger(value);
112
- const validate852 = (value) => validate853(value) || validate6(value);
113
- const validate853 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "identity") && (!Object.hasOwn(value, "identity") || validate854(value["identity"])) && (!Object.hasOwn(value, "dkim") || validate855(value["dkim"])) && (!Object.hasOwn(value, "mailFrom") || validate855(value["mailFrom"]));
114
- const validate854 = (value) => typeof value === "string" && (value === "pending" || value === "verified" || value === "failed" || value === "unknown");
115
- const validate855 = (value) => validate854(value) || validate6(value);
116
- const validate862 = (value) => validate863(value) || validate6(value);
117
- const validate863 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^op_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
118
- const validate871 = (value) => validate872(value) || validate6(value);
119
- const validate872 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "code") && Object.hasOwn(value, "message") && Object.hasOwn(value, "failedAt") && (!Object.hasOwn(value, "code") || validate2(value["code"])) && (!Object.hasOwn(value, "message") || validate2(value["message"])) && (!Object.hasOwn(value, "failedAt") || validate2(value["failedAt"]));
120
- const validate878 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate879(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate881(value["data"]));
121
- const validate879 = (value) => typeof value === "string" && value === "domain.warming.updated";
122
- const validate881 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "domainId") && Object.hasOwn(value, "organizationId") && Object.hasOwn(value, "domain") && Object.hasOwn(value, "planId") && Object.hasOwn(value, "reason") && Object.hasOwn(value, "status") && Object.hasOwn(value, "holdReason") && Object.hasOwn(value, "batch") && Object.hasOwn(value, "updatedAt") && (!Object.hasOwn(value, "domainId") || validate2(value["domainId"])) && (!Object.hasOwn(value, "organizationId") || validate2(value["organizationId"])) && (!Object.hasOwn(value, "domain") || validate2(value["domain"])) && (!Object.hasOwn(value, "planId") || validate2(value["planId"])) && (!Object.hasOwn(value, "reason") || validate886(value["reason"])) && (!Object.hasOwn(value, "status") || validate887(value["status"])) && (!Object.hasOwn(value, "holdReason") || validate8(value["holdReason"])) && (!Object.hasOwn(value, "batch") || validate891(value["batch"])) && (!Object.hasOwn(value, "updatedAt") || validate2(value["updatedAt"]));
123
- const validate886 = (value) => typeof value === "string" && (value === "plan-created" || value === "policy-updated" || value === "window-opened" || value === "window-cancelled" || value === "paused" || value === "resumed" || value === "held" || value === "completed");
124
- const validate887 = (value) => typeof value === "string" && (value === "active" || value === "paused" || value === "completed");
125
- const validate891 = (value) => validate892(value) || validate6(value);
126
- const validate892 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "id") && Object.hasOwn(value, "sequence") && Object.hasOwn(value, "startsAt") && Object.hasOwn(value, "endsAt") && Object.hasOwn(value, "allowanceRecipients") && Object.hasOwn(value, "dailyGrowthPercent") && Object.hasOwn(value, "targetDailyRecipients") && (!Object.hasOwn(value, "id") || validate2(value["id"])) && (!Object.hasOwn(value, "sequence") || validate15(value["sequence"])) && (!Object.hasOwn(value, "startsAt") || validate2(value["startsAt"])) && (!Object.hasOwn(value, "endsAt") || validate2(value["endsAt"])) && (!Object.hasOwn(value, "allowanceRecipients") || validate15(value["allowanceRecipients"])) && (!Object.hasOwn(value, "dailyGrowthPercent") || validate15(value["dailyGrowthPercent"])) && (!Object.hasOwn(value, "targetDailyRecipients") || validate15(value["targetDailyRecipients"]));
127
- const validate902 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate903(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate905(value["data"]));
128
- const validate903 = (value) => typeof value === "string" && value === "mailbox.message.received";
129
- const validate905 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "mailboxId") && Object.hasOwn(value, "namespaceId") && Object.hasOwn(value, "message") && Object.hasOwn(value, "thread") && (!Object.hasOwn(value, "mailboxId") || validate5(value["mailboxId"])) && (!Object.hasOwn(value, "namespaceId") || validate907(value["namespaceId"])) && (!Object.hasOwn(value, "message") || validate910(value["message"])) && (!Object.hasOwn(value, "thread") || validate939(value["thread"]));
130
- const validate907 = (value) => validate908(value) || validate6(value);
131
- const validate908 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^ns_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
132
- const validate910 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "id") && Object.hasOwn(value, "threadId") && Object.hasOwn(value, "from") && Object.hasOwn(value, "to") && Object.hasOwn(value, "cc") && Object.hasOwn(value, "subject") && Object.hasOwn(value, "text") && Object.hasOwn(value, "replyText") && Object.hasOwn(value, "attachments") && Object.hasOwn(value, "occurredAt") && (!Object.hasOwn(value, "id") || validate422(value["id"])) && (!Object.hasOwn(value, "channel") || validate7(value["channel"])) && (!Object.hasOwn(value, "threadId") || validate913(value["threadId"])) && (!Object.hasOwn(value, "from") || validate914(value["from"])) && (!Object.hasOwn(value, "to") || validate42(value["to"])) && (!Object.hasOwn(value, "cc") || validate42(value["cc"])) && (!Object.hasOwn(value, "subject") || validate8(value["subject"])) && (!Object.hasOwn(value, "text") || validate8(value["text"])) && (!Object.hasOwn(value, "replyText") || validate8(value["replyText"])) && (!Object.hasOwn(value, "attachments") || validate932(value["attachments"])) && (!Object.hasOwn(value, "occurredAt") || validate2(value["occurredAt"]));
133
- const validate913 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^thread_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
134
- const validate914 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "address") && (!Object.hasOwn(value, "address") || validate2(value["address"])) && (!Object.hasOwn(value, "name") || validate8(value["name"]));
135
- const validate932 = (value) => Array.isArray(value) && Array.isArray(value) && value.every(validate933);
136
- const validate933 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "id") && Object.hasOwn(value, "filename") && Object.hasOwn(value, "contentType") && Object.hasOwn(value, "size") && (!Object.hasOwn(value, "id") || validate934(value["id"])) && (!Object.hasOwn(value, "filename") || validate2(value["filename"])) && (!Object.hasOwn(value, "contentType") || validate2(value["contentType"])) && (!Object.hasOwn(value, "size") || validate15(value["size"]));
137
- const validate934 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^att_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
138
- const validate939 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "id") && Object.hasOwn(value, "subject") && Object.hasOwn(value, "preview") && (!Object.hasOwn(value, "id") || validate913(value["id"])) && (!Object.hasOwn(value, "endpointId") || validate941(value["endpointId"])) && (!Object.hasOwn(value, "subject") || validate8(value["subject"])) && (!Object.hasOwn(value, "preview") || validate8(value["preview"]));
139
- const validate941 = (value) => validate942(value) || validate6(value);
140
- const validate942 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^mbxep_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
141
- const validate950 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate951(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate953(value["data"]));
142
- const validate951 = (value) => typeof value === "string" && value === "mailbox.message.sent";
143
- const validate953 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "mailboxId") && Object.hasOwn(value, "namespaceId") && Object.hasOwn(value, "actionId") && Object.hasOwn(value, "actor") && Object.hasOwn(value, "message") && (!Object.hasOwn(value, "mailboxId") || validate5(value["mailboxId"])) && (!Object.hasOwn(value, "namespaceId") || validate907(value["namespaceId"])) && (!Object.hasOwn(value, "actionId") || validate958(value["actionId"])) && (!Object.hasOwn(value, "state") || validate959(value["state"])) && (!Object.hasOwn(value, "acceptedAt") || validate2(value["acceptedAt"])) && (!Object.hasOwn(value, "actor") || validate961(value["actor"])) && (!Object.hasOwn(value, "message") || validate910(value["message"]));
144
- const validate958 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^mbxact_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
145
- const validate959 = (value) => typeof value === "string" && value === "completed";
146
- const validate961 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "kind") && Object.hasOwn(value, "id") && Object.hasOwn(value, "source") && (!Object.hasOwn(value, "kind") || validate962(value["kind"])) && (!Object.hasOwn(value, "id") || validate2(value["id"])) && (!Object.hasOwn(value, "displayName") || validate8(value["displayName"])) && (!Object.hasOwn(value, "source") || validate967(value["source"]));
147
- const validate962 = (value) => typeof value === "string" && (value === "user" || value === "apiKey" || value === "extension" || value === "externalAgent" || value === "samvaAgent" || value === "system");
148
- const validate967 = (value) => typeof value === "string" && (value === "humanUi" || value === "externalApi" || value === "externalAgent" || value === "extension" || value === "system");
149
- const validate997 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate998(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate1000(value["data"]));
150
- const validate998 = (value) => typeof value === "string" && value === "mailbox.action.pending_approval";
151
- const validate1000 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "mailboxId") && Object.hasOwn(value, "namespaceId") && Object.hasOwn(value, "action") && Object.hasOwn(value, "draft") && (!Object.hasOwn(value, "mailboxId") || validate5(value["mailboxId"])) && (!Object.hasOwn(value, "namespaceId") || validate907(value["namespaceId"])) && (!Object.hasOwn(value, "action") || validate1005(value["action"])) && (!Object.hasOwn(value, "draft") || validate1035(value["draft"]));
152
- const validate1005 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "id") && Object.hasOwn(value, "type") && Object.hasOwn(value, "threadId") && Object.hasOwn(value, "reason") && Object.hasOwn(value, "proposedBy") && Object.hasOwn(value, "createdAt") && (!Object.hasOwn(value, "id") || validate958(value["id"])) && (!Object.hasOwn(value, "type") || validate1007(value["type"])) && (!Object.hasOwn(value, "state") || validate1008(value["state"])) && (!Object.hasOwn(value, "decision") || validate1009(value["decision"])) && (!Object.hasOwn(value, "threadId") || validate1021(value["threadId"])) && (!Object.hasOwn(value, "reason") || validate8(value["reason"])) && (!Object.hasOwn(value, "proposedBy") || validate961(value["proposedBy"])) && (!Object.hasOwn(value, "createdAt") || validate2(value["createdAt"]));
153
- const validate1007 = (value) => typeof value === "string" && (value === "sendMessage" || value === "reply" || value === "updateDraft" || value === "createNote" || value === "assignThread" || value === "changeThreadState" || value === "call" || value === "extensionRequest");
154
- const validate1008 = (value) => typeof value === "string" && value === "approvalRequired";
155
- const validate1009 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "outcome") && Object.hasOwn(value, "reason") && Object.hasOwn(value, "policyId") && Object.hasOwn(value, "source") && Object.hasOwn(value, "decidedAt") && (!Object.hasOwn(value, "outcome") || validate1010(value["outcome"])) && (!Object.hasOwn(value, "reason") || validate8(value["reason"])) && (!Object.hasOwn(value, "policyId") || validate1014(value["policyId"])) && (!Object.hasOwn(value, "source") || validate1017(value["source"])) && (!Object.hasOwn(value, "decidedAt") || validate2(value["decidedAt"]));
156
- const validate1010 = (value) => typeof value === "string" && (value === "allow" || value === "requireApproval" || value === "deny");
157
- const validate1014 = (value) => validate1015(value) || validate6(value);
158
- const validate1015 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^mbxpol_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
159
- const validate1017 = (value) => validate1018(value) || validate6(value);
160
- const validate1018 = (value) => typeof value === "string" && (value === "grant" || value === "installation" || value === "policy");
161
- const validate1021 = (value) => validate913(value) || validate6(value);
162
- const validate1035 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "to") && Object.hasOwn(value, "cc") && Object.hasOwn(value, "subject") && (!Object.hasOwn(value, "to") || validate42(value["to"])) && (!Object.hasOwn(value, "cc") || validate42(value["cc"])) && (!Object.hasOwn(value, "subject") || validate8(value["subject"]));
163
- const validate1043 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate1044(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate1046(value["data"]));
164
- const validate1044 = (value) => typeof value === "string" && value === "mailbox.action.resolved";
165
- const validate1046 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "mailboxId") && Object.hasOwn(value, "namespaceId") && Object.hasOwn(value, "action") && Object.hasOwn(value, "resolution") && (!Object.hasOwn(value, "mailboxId") || validate5(value["mailboxId"])) && (!Object.hasOwn(value, "namespaceId") || validate907(value["namespaceId"])) && (!Object.hasOwn(value, "action") || validate1051(value["action"])) && (!Object.hasOwn(value, "resolution") || validate1065(value["resolution"]));
166
- const validate1051 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "id") && Object.hasOwn(value, "type") && Object.hasOwn(value, "threadId") && Object.hasOwn(value, "proposedBy") && Object.hasOwn(value, "createdAt") && (!Object.hasOwn(value, "id") || validate958(value["id"])) && (!Object.hasOwn(value, "type") || validate1007(value["type"])) && (!Object.hasOwn(value, "threadId") || validate1021(value["threadId"])) && (!Object.hasOwn(value, "proposedBy") || validate961(value["proposedBy"])) && (!Object.hasOwn(value, "createdAt") || validate2(value["createdAt"]));
167
- const validate1065 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "outcome") && Object.hasOwn(value, "actor") && Object.hasOwn(value, "resolvedAt") && Object.hasOwn(value, "reason") && (!Object.hasOwn(value, "outcome") || validate1066(value["outcome"])) && (!Object.hasOwn(value, "actor") || validate961(value["actor"])) && (!Object.hasOwn(value, "resolvedAt") || validate2(value["resolvedAt"])) && (!Object.hasOwn(value, "reason") || validate8(value["reason"]));
168
- const validate1066 = (value) => typeof value === "string" && (value === "approved" || value === "denied" || value === "cancelled");
169
- const validate1078 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate1079(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate1081(value["data"]));
170
- const validate1079 = (value) => typeof value === "string" && value === "mailbox.message.quarantined";
171
- const validate1081 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "mailboxId") && Object.hasOwn(value, "namespaceId") && Object.hasOwn(value, "disposition") && Object.hasOwn(value, "reason") && Object.hasOwn(value, "source") && Object.hasOwn(value, "message") && (!Object.hasOwn(value, "mailboxId") || validate5(value["mailboxId"])) && (!Object.hasOwn(value, "namespaceId") || validate907(value["namespaceId"])) && (!Object.hasOwn(value, "disposition") || validate1086(value["disposition"])) && (!Object.hasOwn(value, "reason") || validate1087(value["reason"])) && (!Object.hasOwn(value, "source") || validate1088(value["source"])) && (!Object.hasOwn(value, "message") || validate1089(value["message"]));
172
- const validate1086 = (value) => typeof value === "string" && (value === "quarantined" || value === "isolated");
173
- const validate1087 = (value) => typeof value === "string" && (value === "spam" || value === "dmarc" || value === "virus" || value === "virus_unscanned" || value === "phishing" || value === "fraud" || value === "prompt_injection");
174
- const validate1088 = (value) => typeof value === "string" && (value === "receipt" || value === "classifier");
175
- const validate1089 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "id") && Object.hasOwn(value, "from") && Object.hasOwn(value, "subject") && Object.hasOwn(value, "receivedAt") && (!Object.hasOwn(value, "id") || validate422(value["id"])) && (!Object.hasOwn(value, "from") || validate914(value["from"])) && (!Object.hasOwn(value, "subject") || validate8(value["subject"])) && (!Object.hasOwn(value, "receivedAt") || validate2(value["receivedAt"]));
176
- const validate1100 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate1101(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate1103(value["data"]));
177
- const validate1101 = (value) => typeof value === "string" && value === "mailbox.message.released";
178
- const validate1103 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "mailboxId") && Object.hasOwn(value, "namespaceId") && Object.hasOwn(value, "releasedBy") && Object.hasOwn(value, "reason") && Object.hasOwn(value, "message") && Object.hasOwn(value, "thread") && (!Object.hasOwn(value, "mailboxId") || validate5(value["mailboxId"])) && (!Object.hasOwn(value, "namespaceId") || validate907(value["namespaceId"])) && (!Object.hasOwn(value, "releasedBy") || validate961(value["releasedBy"])) && (!Object.hasOwn(value, "reason") || validate1087(value["reason"])) && (!Object.hasOwn(value, "message") || validate910(value["message"])) && (!Object.hasOwn(value, "thread") || validate939(value["thread"]));
179
- const validate1156 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate1157(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate1159(value["data"]));
180
- const validate1157 = (value) => typeof value === "string" && value === "mailbox.message.discarded";
181
- const validate1159 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "mailboxId") && Object.hasOwn(value, "namespaceId") && Object.hasOwn(value, "discardedBy") && Object.hasOwn(value, "disposition") && Object.hasOwn(value, "reason") && Object.hasOwn(value, "message") && (!Object.hasOwn(value, "mailboxId") || validate5(value["mailboxId"])) && (!Object.hasOwn(value, "namespaceId") || validate907(value["namespaceId"])) && (!Object.hasOwn(value, "discardedBy") || validate961(value["discardedBy"])) && (!Object.hasOwn(value, "disposition") || validate1086(value["disposition"])) && (!Object.hasOwn(value, "reason") || validate1087(value["reason"])) && (!Object.hasOwn(value, "message") || validate1089(value["message"]));
182
- const validate1184 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "type") && Object.hasOwn(value, "timestamp") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "type") || validate1185(value["type"])) && (!Object.hasOwn(value, "timestamp") || validate2(value["timestamp"])) && (!Object.hasOwn(value, "data") || validate1187(value["data"]));
183
- const validate1185 = (value) => typeof value === "string" && value === "journey.webhook";
184
- const validate1187 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "organizationId") && Object.hasOwn(value, "journeyId") && Object.hasOwn(value, "journeyVersion") && Object.hasOwn(value, "runId") && Object.hasOwn(value, "nodeId") && Object.hasOwn(value, "contact") && Object.hasOwn(value, "data") && (!Object.hasOwn(value, "organizationId") || validate423(value["organizationId"])) && (!Object.hasOwn(value, "journeyId") || validate1189(value["journeyId"])) && (!Object.hasOwn(value, "journeyVersion") || validate847(value["journeyVersion"])) && (!Object.hasOwn(value, "runId") || validate1191(value["runId"])) && (!Object.hasOwn(value, "nodeId") || validate2(value["nodeId"])) && (!Object.hasOwn(value, "contact") || validate1193(value["contact"])) && (!Object.hasOwn(value, "data") || validate12(value["data"]));
185
- const validate1189 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^jrny_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
186
- const validate1191 = (value) => typeof value === "string" && typeof value === "string" && (/* @__PURE__ */ new RegExp("^jrun_[0-9a-hjkmnp-tv-z]{16,24}$", "u")).test(value);
187
- const validate1193 = (value) => isObject(value) && isObject(value) && Object.hasOwn(value, "id") && Object.hasOwn(value, "externalId") && Object.hasOwn(value, "email") && (!Object.hasOwn(value, "id") || validate522(value["id"])) && (!Object.hasOwn(value, "externalId") || validate8(value["externalId"])) && (!Object.hasOwn(value, "email") || validate8(value["email"]));
188
- /** Narrow an event to a structurally valid payload known to this package. */
189
- const isKnownEvent = (value) => {
190
- switch (value.type) {
191
- case "message.sent": return validate0(value);
192
- case "message.delivered": return validate71(value);
193
- case "message.failed": return validate142(value);
194
- case "message.bounced": return validate213(value);
195
- case "message.complained": return validate280(value);
196
- case "message.received": return validate347(value);
197
- case "message.opened": return validate418(value);
198
- case "message.clicked": return validate466(value);
199
- case "contact.created": return validate518(value);
200
- case "contact.updated": return validate544(value);
201
- case "contact.deleted": return validate570(value);
202
- case "contact.subscribed": return validate596(value);
203
- case "contact.unsubscribed": return validate630(value);
204
- case "contact.resubscribed": return validate664(value);
205
- case "contact.consent_changed": return validate698(value);
206
- case "conversation.created": return validate715(value);
207
- case "conversation.updated": return validate737(value);
208
- case "conversation.archived": return validate759(value);
209
- case "webhook.created": return validate781(value);
210
- case "webhook.updated": return validate798(value);
211
- case "webhook.deleted": return validate815(value);
212
- case "webhook.test": return validate832(value);
213
- case "domain.updated": return validate836(value);
214
- case "domain.warming.updated": return validate878(value);
215
- case "mailbox.message.received": return validate902(value);
216
- case "mailbox.message.sent": return validate950(value);
217
- case "mailbox.action.pending_approval": return validate997(value);
218
- case "mailbox.action.resolved": return validate1043(value);
219
- case "mailbox.message.quarantined": return validate1078(value);
220
- case "mailbox.message.released": return validate1100(value);
221
- case "mailbox.message.discarded": return validate1156(value);
222
- case "journey.webhook": return validate1184(value);
223
- default: return false;
224
- }
225
- };
226
- const validateEvent = (value) => {
227
- if (!isObject(value) || typeof value.type !== "string" || typeof value.timestamp !== "string" || !Object.hasOwn(value, "data")) return false;
228
- switch (value.type) {
229
- case "message.sent": return validate0(value);
230
- case "message.delivered": return validate71(value);
231
- case "message.failed": return validate142(value);
232
- case "message.bounced": return validate213(value);
233
- case "message.complained": return validate280(value);
234
- case "message.received": return validate347(value);
235
- case "message.opened": return validate418(value);
236
- case "message.clicked": return validate466(value);
237
- case "contact.created": return validate518(value);
238
- case "contact.updated": return validate544(value);
239
- case "contact.deleted": return validate570(value);
240
- case "contact.subscribed": return validate596(value);
241
- case "contact.unsubscribed": return validate630(value);
242
- case "contact.resubscribed": return validate664(value);
243
- case "contact.consent_changed": return validate698(value);
244
- case "conversation.created": return validate715(value);
245
- case "conversation.updated": return validate737(value);
246
- case "conversation.archived": return validate759(value);
247
- case "webhook.created": return validate781(value);
248
- case "webhook.updated": return validate798(value);
249
- case "webhook.deleted": return validate815(value);
250
- case "webhook.test": return validate832(value);
251
- case "domain.updated": return validate836(value);
252
- case "domain.warming.updated": return validate878(value);
253
- case "mailbox.message.received": return validate902(value);
254
- case "mailbox.message.sent": return validate950(value);
255
- case "mailbox.action.pending_approval": return validate997(value);
256
- case "mailbox.action.resolved": return validate1043(value);
257
- case "mailbox.message.quarantined": return validate1078(value);
258
- case "mailbox.message.released": return validate1100(value);
259
- case "mailbox.message.discarded": return validate1156(value);
260
- case "journey.webhook": return validate1184(value);
261
- default: return true;
262
- }
263
- };
264
- //#endregion
265
- //#region src/errors.ts
266
- /**
267
- * Base class for every failure this package reports while verifying a webhook delivery.
268
- *
269
- * Each subclass carries a literal `_tag` (also used as `name`), so you can branch on the failure
270
- * with a `switch` or Effect's `catchTag`. `detail` is a human-readable reason for your logs; do not
271
- * echo it to the sender, and do not match on its wording.
272
- */
273
- var WebhookVerificationError = class extends Error {
274
- /** Discriminant naming the concrete failure; equal to the subclass name. */
275
- _tag;
276
- /** Human-readable reason for logs. The wording is not a stable contract. */
277
- detail;
278
- constructor(tag, options) {
279
- super(options.detail);
280
- this.name = tag;
281
- this._tag = tag;
282
- this.detail = options.detail;
283
- }
284
- };
285
- /**
286
- * The signing secret is unusable: it lacks the `whsec_` prefix, the remainder is not Base64, or
287
- * the decoded key length is outside the accepted range (`detail` names the range). This is a
288
- * configuration error on the receiving side, not a bad delivery; copy the endpoint's signing
289
- * secret from Samva again.
290
- */
291
- var InvalidWebhookSecretError = class extends WebhookVerificationError {
292
- constructor(options) {
293
- super("InvalidWebhookSecretError", options);
294
- }
295
- };
296
- /**
297
- * One of the `webhook-id`, `webhook-timestamp`, or `webhook-signature` headers is missing or
298
- * empty; `header` names it. The request is not a Samva delivery, or something between Samva and
299
- * your handler stripped the headers.
300
- */
301
- var InvalidWebhookHeadersError = class extends WebhookVerificationError {
302
- /** The first signing header, in id, timestamp, signature order, that is missing or empty. */
303
- header;
304
- constructor(options) {
305
- super("InvalidWebhookHeadersError", options);
306
- this.header = options.header;
307
- }
308
- };
309
- /**
310
- * The `webhook-timestamp` header is not an integer count of Unix seconds, it lies further from the
311
- * current time than the replay tolerance, or the tolerance you passed is negative or not finite.
312
- * A delivery outside the tolerance is rejected even when its signature is valid; that bounds how
313
- * long a captured request can be replayed. Repeated failures on genuine deliveries usually mean
314
- * the receiving server's clock is wrong.
315
- */
316
- var WebhookTimestampError = class extends WebhookVerificationError {
317
- constructor(options) {
318
- super("WebhookTimestampError", options);
319
- }
320
- };
321
- /**
322
- * No signature in the `webhook-signature` header matches the delivery, or no verification key was
323
- * supplied. Treat the request as forged and reject it. When genuine deliveries fail, the usual
324
- * causes are the wrong endpoint secret or a body that was parsed and re-serialized before
325
- * verification instead of passed through as the exact bytes received.
326
- */
327
- var WebhookSignatureError = class extends WebhookVerificationError {
328
- constructor(options) {
329
- super("WebhookSignatureError", options);
330
- }
331
- };
332
- /**
333
- * The signature is valid, but the body is not UTF-8 JSON holding exactly the `type`,
334
- * `timestamp`, and `data` fields of a Samva event envelope.
335
- */
336
- var MalformedWebhookPayloadError = class extends WebhookVerificationError {
337
- constructor(options) {
338
- super("MalformedWebhookPayloadError", options);
339
- }
340
- };
341
- /**
342
- * The runtime's Web Crypto implementation could not import a key or compute a signature, none of
343
- * the supplied public keys could be imported, or the Effect entrypoint could not read the request
344
- * body. Points at the runtime or its configuration rather than at the delivery.
345
- */
346
- var WebhookCryptoError = class extends WebhookVerificationError {
347
- constructor(options) {
348
- super("WebhookCryptoError", options);
349
- }
350
- };
351
- //#endregion
352
- //#region src/protocol.ts
353
- /**
354
- * Header carrying the delivery's unique message ID. Retries of the same delivery reuse it, so it
355
- * is the key for deduplicating deliveries you have already handled.
356
- */
357
- const WEBHOOK_ID_HEADER = "webhook-id";
358
- /** Header carrying the time Samva signed the delivery, as integer Unix seconds. */
359
- const WEBHOOK_TIMESTAMP_HEADER = "webhook-timestamp";
360
- /**
361
- * Header carrying one or more space-separated `<version>,<base64 signature>` entries. More than one
362
- * entry appears while a signing secret is being rotated; a delivery verifies when any entry of the
363
- * expected version matches.
364
- */
365
- const WEBHOOK_SIGNATURE_HEADER = "webhook-signature";
366
- /**
367
- * Replay tolerance, in seconds, used when a caller passes no `toleranceSeconds`. A delivery whose
368
- * `webhook-timestamp` differs from the current time by more than this, in either direction, is
369
- * rejected with {@link WebhookTimestampError}.
370
- */
371
- const DEFAULT_TOLERANCE_SECONDS = 300;
372
- const SECRET_PREFIX = "whsec_";
373
- const ASYMMETRIC_ALGORITHM = {
374
- name: "RSASSA-PKCS1-v1_5",
375
- hash: "SHA-256"
376
- };
377
- const MINIMUM_SECRET_BYTES = 24;
378
- const MAXIMUM_SECRET_BYTES = 64;
379
- const GENERATED_SECRET_BYTES = 32;
380
- const encoder = new TextEncoder();
381
- const toBytes = (body) => typeof body === "string" ? encoder.encode(body) : body;
382
- const toCryptoBytes = (bytes) => new Uint8Array(bytes);
383
- const bytesToBase64 = (bytes) => {
384
- let binary = "";
385
- for (const byte of bytes) binary += String.fromCharCode(byte);
386
- return btoa(binary);
387
- };
388
- const base64ToBytes = (encoded) => {
389
- const binary = atob(encoded);
390
- return Uint8Array.from(binary, (character) => character.charCodeAt(0));
391
- };
392
- const decodeSecret = (secret) => {
393
- if (!secret.startsWith(SECRET_PREFIX)) throw new InvalidWebhookSecretError({ detail: "Webhook secret must start with whsec_" });
394
- const decoded = (() => {
395
- try {
396
- return base64ToBytes(secret.slice(6));
397
- } catch {
398
- throw new InvalidWebhookSecretError({ detail: "Webhook secret is not valid Base64" });
399
- }
400
- })();
401
- if (decoded.byteLength < MINIMUM_SECRET_BYTES || decoded.byteLength > MAXIMUM_SECRET_BYTES) throw new InvalidWebhookSecretError({ detail: `Webhook secret must decode to ${MINIMUM_SECRET_BYTES}-${MAXIMUM_SECRET_BYTES} bytes` });
402
- return decoded;
403
- };
404
- const importHmacKey = async (secret) => {
405
- const secretBytes = decodeSecret(secret);
406
- try {
407
- return await crypto.subtle.importKey("raw", toCryptoBytes(secretBytes), {
408
- name: "HMAC",
409
- hash: "SHA-256"
410
- }, false, ["sign"]);
411
- } catch (cause) {
412
- throw new WebhookCryptoError({ detail: `Unable to import webhook signing key: ${cause instanceof Error ? cause.message : String(cause)}` });
413
- }
414
- };
415
- const importVerificationKey = async (publicKey) => {
416
- try {
417
- return await crypto.subtle.importKey("spki", toCryptoBytes(base64ToBytes(publicKey.trim())), ASYMMETRIC_ALGORITHM, false, ["verify"]);
418
- } catch {
419
- return;
420
- }
421
- };
422
- const signedBytes = (id, timestamp, body) => {
423
- const prefix = encoder.encode(`${id}.${timestamp}.`);
424
- const material = new Uint8Array(prefix.byteLength + body.byteLength);
425
- material.set(prefix);
426
- material.set(body, prefix.byteLength);
427
- return material;
428
- };
429
- const hmac = async (secret, id, timestamp, body) => {
430
- const key = await importHmacKey(secret);
431
- try {
432
- return new Uint8Array(await crypto.subtle.sign("HMAC", key, toCryptoBytes(signedBytes(id, timestamp, body))));
433
- } catch (cause) {
434
- throw new WebhookCryptoError({ detail: `Unable to sign webhook: ${cause instanceof Error ? cause.message : String(cause)}` });
435
- }
436
- };
437
- const asymmetricMatch = async (key, candidate, content) => {
438
- try {
439
- return await crypto.subtle.verify(ASYMMETRIC_ALGORITHM, key, toCryptoBytes(candidate), content);
440
- } catch {
441
- return false;
442
- }
443
- };
444
- const timingSafeEqual = (left, right) => {
445
- if (left.byteLength !== right.byteLength) return false;
446
- let difference = 0;
447
- for (let index = 0; index < left.byteLength; index += 1) difference |= (left[index] ?? 0) ^ (right[index] ?? 0);
448
- return difference === 0;
449
- };
450
- const signatureCandidates = (header, expected) => header.split(" ").map((candidate) => candidate.split(",", 2)).flatMap(([version, encoded]) => {
451
- if (version !== expected || encoded === void 0) return [];
452
- try {
453
- return [base64ToBytes(encoded)];
454
- } catch {
455
- return [];
456
- }
457
- });
458
- const parseEvent = (body) => {
459
- try {
460
- const parsed = JSON.parse(new TextDecoder("utf-8", {
461
- fatal: true,
462
- ignoreBOM: false
463
- }).decode(body));
464
- if (!validateEvent(parsed)) throw new MalformedWebhookPayloadError({ detail: "Webhook event does not match its payload schema" });
465
- return parsed;
466
- } catch {
467
- throw new MalformedWebhookPayloadError({ detail: "Webhook body must be valid UTF-8 JSON matching a Samva event payload schema" });
468
- }
469
- };
470
- /**
471
- * Creates a random `whsec_`-prefixed signing secret from the runtime's secure random source.
472
- * Samva issues each endpoint's secret for you; use this to sign test deliveries with
473
- * {@link signWebhook}.
474
- */
475
- const generateWebhookSecret = () => {
476
- const bytes = crypto.getRandomValues(new Uint8Array(GENERATED_SECRET_BYTES));
477
- return `${SECRET_PREFIX}${bytesToBase64(bytes)}`;
478
- };
479
- /**
480
- * Builds the bytes every signature version covers: `<id>.<timestamp>.<body>`. Use it to verify a
481
- * signature with your own crypto code; {@link verifyWebhookAt} and
482
- * {@link verifyWebhookAtWithPublicKeys} build it for you.
483
- */
484
- const webhookSignedContent = (input) => signedBytes(input.id, input.timestamp, toBytes(input.body));
485
- /** Formats raw signature bytes as one `<version>,<base64>` entry of the `webhook-signature` header. */
486
- const encodeWebhookSignature = (version, signature) => `${version},${bytesToBase64(signature)}`;
487
- /**
488
- * Computes the `v1` HMAC-SHA256 signature Samva sends, formatted as one `webhook-signature`
489
- * entry. Use it to produce signed test deliveries for your handler.
490
- *
491
- * `timestamp` is Unix seconds; a number is stringified, and the verifier requires an integer.
492
- * Rejects with {@link InvalidWebhookSecretError} for an unusable secret and
493
- * {@link WebhookCryptoError} when Web Crypto fails.
494
- */
495
- const signWebhook = async (input) => {
496
- const timestamp = String(input.timestamp);
497
- const signature = await hmac(input.secret, input.id, timestamp, toBytes(input.body));
498
- return encodeWebhookSignature("v1", signature);
499
- };
500
- const requireHeader = (header, value) => {
501
- if (value === null || value === void 0) throw new InvalidWebhookHeadersError({
502
- header,
503
- detail: `${header} header is missing`
504
- });
505
- if (value.length === 0) throw new InvalidWebhookHeadersError({
506
- header,
507
- detail: `${header} header is empty`
508
- });
509
- return value;
510
- };
511
- const requireHeaders = (values) => ({
512
- id: requireHeader(WEBHOOK_ID_HEADER, values.id),
513
- timestamp: requireHeader(WEBHOOK_TIMESTAMP_HEADER, values.timestamp),
514
- signature: requireHeader(WEBHOOK_SIGNATURE_HEADER, values.signature)
515
- });
516
- const freshHeaders = (input) => {
517
- const { id, timestamp, signature } = requireHeaders(input.headers);
518
- const timestampSeconds = Number(timestamp);
519
- if (!Number.isInteger(timestampSeconds)) throw new WebhookTimestampError({ detail: "webhook-timestamp must be Unix seconds" });
520
- const toleranceSeconds = input.toleranceSeconds ?? 300;
521
- if (!Number.isFinite(toleranceSeconds) || toleranceSeconds < 0) throw new WebhookTimestampError({ detail: "Webhook tolerance must be non-negative" });
522
- if (Math.abs(input.nowMilliseconds / 1e3 - timestampSeconds) > toleranceSeconds) throw new WebhookTimestampError({ detail: "Webhook timestamp is outside the replay tolerance" });
523
- return {
524
- id,
525
- timestamp,
526
- signature
527
- };
528
- };
529
- /**
530
- * Verifies a `v1` (HMAC-SHA256) delivery against an explicit current time. The `verify` and
531
- * `verifyRequest` entry points call this with the current clock; call it directly when your
532
- * framework owns the clock or a test needs a fixed time.
533
- *
534
- * Checks, in order: all three headers are present and non-empty; the timestamp is integer Unix seconds within
535
- * `toleranceSeconds` of `nowMilliseconds`; some `v1` entry in the signature header matches, using
536
- * a constant-time comparison; the body has a valid envelope and known event payloads match their schema. Unknown event types pass
537
- * through with untyped data. The replay window rejects stale
538
- * deliveries but does not detect a repeat inside it; deduplicate on the returned `id`.
539
- *
540
- * Rejects with {@link InvalidWebhookHeadersError}, {@link WebhookTimestampError},
541
- * {@link InvalidWebhookSecretError}, {@link WebhookSignatureError},
542
- * {@link MalformedWebhookPayloadError}, or {@link WebhookCryptoError}.
543
- */
544
- const verifyWebhookAt = async (input) => {
545
- const { id, timestamp, signature } = freshHeaders(input);
546
- const body = toBytes(input.body);
547
- const expected = await hmac(input.secret, id, timestamp, body);
548
- if (!signatureCandidates(signature, "v1").some((candidate) => timingSafeEqual(expected, candidate))) throw new WebhookSignatureError({ detail: "Webhook signature verification failed" });
549
- return {
550
- id,
551
- event: parseEvent(body)
552
- };
553
- };
554
- /**
555
- * Verifies a `v2` (RSASSA-PKCS1-v1_5, SHA-256) delivery against one or more public keys, each a
556
- * Base64-encoded SPKI DER key. Pass several keys during a key rotation; the delivery verifies when
557
- * any `v2` signature entry matches any key.
558
- *
559
- * Header, timestamp, and envelope checks match {@link verifyWebhookAt}. Keys that fail to import
560
- * are skipped. Rejects with {@link WebhookSignatureError} when `publicKeys` is empty or nothing
561
- * matches, and {@link WebhookCryptoError} when none of the keys imports.
562
- */
563
- const verifyWebhookAtWithPublicKeys = async (input) => {
564
- const { id, timestamp, signature } = freshHeaders(input);
565
- if (input.publicKeys.length === 0) throw new WebhookSignatureError({ detail: "No webhook verification key is available" });
566
- const keys = (await Promise.all(input.publicKeys.map(importVerificationKey))).filter((key) => key !== void 0);
567
- if (keys.length === 0) throw new WebhookCryptoError({ detail: "Unable to import any webhook verification key: keys must be Base64 SPKI DER" });
568
- const body = toBytes(input.body);
569
- const content = toCryptoBytes(signedBytes(id, timestamp, body));
570
- const candidates = signatureCandidates(signature, "v2");
571
- if (!(await Promise.all(keys.flatMap((key) => candidates.map((candidate) => asymmetricMatch(key, candidate, content))))).includes(true)) throw new WebhookSignatureError({ detail: "Webhook signature verification failed" });
572
- return {
573
- id,
574
- event: parseEvent(body)
575
- };
576
- };
577
- /**
578
- * Reads the three signing headers from a Fetch API `Headers` object, for code that needs a header
579
- * value, such as the timestamp, before or beside verification. Throws
580
- * {@link InvalidWebhookHeadersError}, naming the header, when one is missing or empty; call it
581
- * inside the same error handling as the verification that follows.
582
- */
583
- const readWebhookHeaders = (headers) => requireHeaders({
584
- id: headers.get(WEBHOOK_ID_HEADER),
585
- timestamp: headers.get(WEBHOOK_TIMESTAMP_HEADER),
586
- signature: headers.get(WEBHOOK_SIGNATURE_HEADER)
587
- });
588
- //#endregion
589
- export { WebhookTimestampError as _, encodeWebhookSignature as a, signWebhook as c, webhookSignedContent as d, InvalidWebhookHeadersError as f, WebhookSignatureError as g, WebhookCryptoError as h, WEBHOOK_TIMESTAMP_HEADER as i, verifyWebhookAt as l, MalformedWebhookPayloadError as m, WEBHOOK_ID_HEADER as n, generateWebhookSecret as o, InvalidWebhookSecretError as p, WEBHOOK_SIGNATURE_HEADER as r, readWebhookHeaders as s, DEFAULT_TOLERANCE_SECONDS as t, verifyWebhookAtWithPublicKeys as u, WebhookVerificationError as v, isKnownEvent as y };
590
-
591
- //# sourceMappingURL=protocol-D0_izLnI.js.map