@q9labsai/chalk-client 4.0.0
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.
- package/LICENSE +21 -0
- package/README.md +173 -0
- package/dist/access/base64-url.d.ts +2 -0
- package/dist/access/base64-url.d.ts.map +1 -0
- package/dist/access/episode-diagnostic-credential.d.ts +11 -0
- package/dist/access/episode-diagnostic-credential.d.ts.map +1 -0
- package/dist/access/grant.d.ts +53 -0
- package/dist/access/grant.d.ts.map +1 -0
- package/dist/access/grant.test.helpers.d.ts +10 -0
- package/dist/access/grant.test.helpers.d.ts.map +1 -0
- package/dist/access/manager.d.ts +36 -0
- package/dist/access/manager.d.ts.map +1 -0
- package/dist/chat-files/http-transport.d.ts +8 -0
- package/dist/chat-files/http-transport.d.ts.map +1 -0
- package/dist/chat-files/index.d.ts +3 -0
- package/dist/chat-files/index.d.ts.map +1 -0
- package/dist/chat-files/types.d.ts +37 -0
- package/dist/chat-files/types.d.ts.map +1 -0
- package/dist/chunk-5VXGLI3T.js +3385 -0
- package/dist/chunk-O22WFBKF.js +5161 -0
- package/dist/chunk-PBCGWE2V.js +811 -0
- package/dist/chunk-PBSYXPNJ.js +23 -0
- package/dist/chunk-QVHR3RMB.js +1229 -0
- package/dist/client.d.ts +6785 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/collaboration/index.d.ts +3 -0
- package/dist/collaboration/index.d.ts.map +1 -0
- package/dist/collaboration/types.d.ts +94 -0
- package/dist/collaboration/types.d.ts.map +1 -0
- package/dist/collaboration/wire.d.ts +19 -0
- package/dist/collaboration/wire.d.ts.map +1 -0
- package/dist/connection/dependencies.d.ts +112 -0
- package/dist/connection/dependencies.d.ts.map +1 -0
- package/dist/connection/diagnostics.d.ts +52 -0
- package/dist/connection/diagnostics.d.ts.map +1 -0
- package/dist/connection/index.d.ts +47 -0
- package/dist/connection/index.d.ts.map +1 -0
- package/dist/connection/lifecycle.d.ts +58 -0
- package/dist/connection/lifecycle.d.ts.map +1 -0
- package/dist/connection/media-devices.d.ts +6 -0
- package/dist/connection/media-devices.d.ts.map +1 -0
- package/dist/connection/production.d.ts +13 -0
- package/dist/connection/production.d.ts.map +1 -0
- package/dist/connection/snapshot.d.ts +23 -0
- package/dist/connection/snapshot.d.ts.map +1 -0
- package/dist/connection/types.d.ts +128 -0
- package/dist/connection/types.d.ts.map +1 -0
- package/dist/effect.d.ts +19 -0
- package/dist/effect.d.ts.map +1 -0
- package/dist/effect.js +7846 -0
- package/dist/episode-diagnostic-runtime.test.helpers.d.ts +3 -0
- package/dist/episode-diagnostic-runtime.test.helpers.d.ts.map +1 -0
- package/dist/generated/http-api.d.ts +6658 -0
- package/dist/generated/http-api.d.ts.map +1 -0
- package/dist/generated/schemas.d.ts +12076 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/sync.d.ts +3947 -0
- package/dist/generated/sync.d.ts.map +1 -0
- package/dist/generated/whiteboard-v1.d.ts +334 -0
- package/dist/generated/whiteboard-v1.d.ts.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +152 -0
- package/dist/media/client.d.ts +18 -0
- package/dist/media/client.d.ts.map +1 -0
- package/dist/media/cloudflare-sfu.d.ts +5 -0
- package/dist/media/cloudflare-sfu.d.ts.map +1 -0
- package/dist/media/index.d.ts +3 -0
- package/dist/media/index.d.ts.map +1 -0
- package/dist/media/index.js +24 -0
- package/dist/media/plane.d.ts +24 -0
- package/dist/media/plane.d.ts.map +1 -0
- package/dist/media/tracks.d.ts +21 -0
- package/dist/media/tracks.d.ts.map +1 -0
- package/dist/media/transport.d.ts +3 -0
- package/dist/media/transport.d.ts.map +1 -0
- package/dist/media/types.d.ts +114 -0
- package/dist/media/types.d.ts.map +1 -0
- package/dist/server/chunk-A6YMG5FM.js +61 -0
- package/dist/server/client.d.cts +2 -0
- package/dist/server/client.d.ts +3 -0
- package/dist/server/client.d.ts.map +1 -0
- package/dist/server/errors.d.cts +18 -0
- package/dist/server/errors.d.ts +19 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/index.cjs +551 -0
- package/dist/server/index.d.cts +3 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +474 -0
- package/dist/server/server-only.cjs +40 -0
- package/dist/server/server-only.d.cts +1 -0
- package/dist/server/server-only.d.ts +2 -0
- package/dist/server/server-only.d.ts.map +1 -0
- package/dist/server/server-only.js +9 -0
- package/dist/server/transport.d.cts +12 -0
- package/dist/server/transport.d.ts +13 -0
- package/dist/server/transport.d.ts.map +1 -0
- package/dist/server/types.d.cts +201 -0
- package/dist/server/types.d.ts +202 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/space-client/chat-controller-helpers.d.ts +15 -0
- package/dist/space-client/chat-controller-helpers.d.ts.map +1 -0
- package/dist/space-client/chat-controller.d.ts +34 -0
- package/dist/space-client/chat-controller.d.ts.map +1 -0
- package/dist/space-client/controller-effects.d.ts +45 -0
- package/dist/space-client/controller-effects.d.ts.map +1 -0
- package/dist/space-client/controller-parity.test.helpers.d.ts +150 -0
- package/dist/space-client/controller-parity.test.helpers.d.ts.map +1 -0
- package/dist/space-client/core.d.ts +52 -0
- package/dist/space-client/core.d.ts.map +1 -0
- package/dist/space-client/core.test.helpers.d.ts +14 -0
- package/dist/space-client/core.test.helpers.d.ts.map +1 -0
- package/dist/space-client/effect.d.ts +44 -0
- package/dist/space-client/effect.d.ts.map +1 -0
- package/dist/space-client/episode-diagnostic-registry.d.ts +13 -0
- package/dist/space-client/episode-diagnostic-registry.d.ts.map +1 -0
- package/dist/space-client/episode-diagnostic-render-registry.d.ts +4 -0
- package/dist/space-client/episode-diagnostic-render-registry.d.ts.map +1 -0
- package/dist/space-client/episode-diagnostic-runtime.d.ts +102 -0
- package/dist/space-client/episode-diagnostic-runtime.d.ts.map +1 -0
- package/dist/space-client/errors.d.ts +11 -0
- package/dist/space-client/errors.d.ts.map +1 -0
- package/dist/space-client/index.d.ts +5 -0
- package/dist/space-client/index.d.ts.map +1 -0
- package/dist/space-client/media-controller.d.ts +30 -0
- package/dist/space-client/media-controller.d.ts.map +1 -0
- package/dist/space-client/media-controller.test.helpers.d.ts +105 -0
- package/dist/space-client/media-controller.test.helpers.d.ts.map +1 -0
- package/dist/space-client/media-device-selection.d.ts +13 -0
- package/dist/space-client/media-device-selection.d.ts.map +1 -0
- package/dist/space-client/participants-controller.d.ts +33 -0
- package/dist/space-client/participants-controller.d.ts.map +1 -0
- package/dist/space-client/promise-facade.d.ts +12 -0
- package/dist/space-client/promise-facade.d.ts.map +1 -0
- package/dist/space-client/reactions-controller.d.ts +19 -0
- package/dist/space-client/reactions-controller.d.ts.map +1 -0
- package/dist/space-client/space-client.d.ts +5 -0
- package/dist/space-client/space-client.d.ts.map +1 -0
- package/dist/space-client/store.d.ts +29 -0
- package/dist/space-client/store.d.ts.map +1 -0
- package/dist/space-client/types.d.ts +222 -0
- package/dist/space-client/types.d.ts.map +1 -0
- package/dist/space-client/whiteboard-controller.d.ts +17 -0
- package/dist/space-client/whiteboard-controller.d.ts.map +1 -0
- package/dist/sync/browser.d.ts +9 -0
- package/dist/sync/browser.d.ts.map +1 -0
- package/dist/sync/canonical.d.ts +7 -0
- package/dist/sync/canonical.d.ts.map +1 -0
- package/dist/sync/errors.d.ts +9 -0
- package/dist/sync/errors.d.ts.map +1 -0
- package/dist/sync/index.d.ts +13 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +51 -0
- package/dist/sync/react-native.d.ts +42 -0
- package/dist/sync/react-native.d.ts.map +1 -0
- package/dist/sync/types.d.ts +28 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/v1-client.d.ts +59 -0
- package/dist/sync/v1-client.d.ts.map +1 -0
- package/dist/sync/v1-codec.d.ts +5 -0
- package/dist/sync/v1-codec.d.ts.map +1 -0
- package/dist/sync/v1-create.d.ts +12 -0
- package/dist/sync/v1-create.d.ts.map +1 -0
- package/dist/sync/v1-persistence.d.ts +10 -0
- package/dist/sync/v1-persistence.d.ts.map +1 -0
- package/dist/sync/v1-platform-persistence.d.ts +26 -0
- package/dist/sync/v1-platform-persistence.d.ts.map +1 -0
- package/dist/sync/v1-reducer.d.ts +17 -0
- package/dist/sync/v1-reducer.d.ts.map +1 -0
- package/dist/sync/v1-types.d.ts +197 -0
- package/dist/sync/v1-types.d.ts.map +1 -0
- package/dist/telemetry/attributes.d.ts +7 -0
- package/dist/telemetry/attributes.d.ts.map +1 -0
- package/dist/telemetry/client.d.ts +44 -0
- package/dist/telemetry/client.d.ts.map +1 -0
- package/dist/telemetry/delivery.d.ts +107 -0
- package/dist/telemetry/delivery.d.ts.map +1 -0
- package/dist/telemetry/exporter.d.ts +38 -0
- package/dist/telemetry/exporter.d.ts.map +1 -0
- package/dist/telemetry/index.d.ts +7 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +48 -0
- package/dist/telemetry/journey.d.ts +52 -0
- package/dist/telemetry/journey.d.ts.map +1 -0
- package/dist/telemetry/random.d.ts +18 -0
- package/dist/telemetry/random.d.ts.map +1 -0
- package/dist/telemetry/rtc.d.ts +35 -0
- package/dist/telemetry/rtc.d.ts.map +1 -0
- package/dist/telemetry/storage.d.ts +22 -0
- package/dist/telemetry/storage.d.ts.map +1 -0
- package/dist/telemetry/sync.d.ts +10 -0
- package/dist/telemetry/sync.d.ts.map +1 -0
- package/dist/telemetry/test-support.d.ts +51 -0
- package/dist/telemetry/test-support.d.ts.map +1 -0
- package/dist/telemetry/trace.d.ts +18 -0
- package/dist/telemetry/trace.d.ts.map +1 -0
- package/dist/telemetry/types.d.ts +109 -0
- package/dist/telemetry/types.d.ts.map +1 -0
- package/dist/webhooks/chunk-UNMJZNTZ.js +31 -0
- package/dist/webhooks/errors.d.cts +8 -0
- package/dist/webhooks/errors.d.ts +9 -0
- package/dist/webhooks/errors.d.ts.map +1 -0
- package/dist/webhooks/generated/event-v1.d.cts +764 -0
- package/dist/webhooks/generated/event-v1.d.ts +765 -0
- package/dist/webhooks/generated/event-v1.d.ts.map +1 -0
- package/dist/webhooks/generated/fixtures-v1.d.cts +46 -0
- package/dist/webhooks/generated/fixtures-v1.d.ts +47 -0
- package/dist/webhooks/generated/fixtures-v1.d.ts.map +1 -0
- package/dist/webhooks/index.cjs +1242 -0
- package/dist/webhooks/index.d.cts +5 -0
- package/dist/webhooks/index.d.ts +6 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +1197 -0
- package/dist/webhooks/processor.d.cts +21 -0
- package/dist/webhooks/processor.d.ts +22 -0
- package/dist/webhooks/processor.d.ts.map +1 -0
- package/dist/webhooks/server-only.cjs +36 -0
- package/dist/webhooks/server-only.d.cts +1 -0
- package/dist/webhooks/server-only.d.ts +2 -0
- package/dist/webhooks/server-only.d.ts.map +1 -0
- package/dist/webhooks/server-only.js +9 -0
- package/dist/webhooks/test.cjs +160 -0
- package/dist/webhooks/test.d.cts +42 -0
- package/dist/webhooks/test.d.ts +43 -0
- package/dist/webhooks/test.d.ts.map +1 -0
- package/dist/webhooks/test.js +137 -0
- package/dist/webhooks/types.d.cts +55 -0
- package/dist/webhooks/types.d.ts +56 -0
- package/dist/webhooks/types.d.ts.map +1 -0
- package/dist/webhooks/validate.d.cts +5 -0
- package/dist/webhooks/validate.d.ts +6 -0
- package/dist/webhooks/validate.d.ts.map +1 -0
- package/dist/webhooks/verify.d.cts +10 -0
- package/dist/webhooks/verify.d.ts +11 -0
- package/dist/webhooks/verify.d.ts.map +1 -0
- package/dist/whiteboard/file-http-transport.d.ts +9 -0
- package/dist/whiteboard/file-http-transport.d.ts.map +1 -0
- package/dist/whiteboard/index.d.ts +7 -0
- package/dist/whiteboard/index.d.ts.map +1 -0
- package/dist/whiteboard/types.d.ts +139 -0
- package/dist/whiteboard/types.d.ts.map +1 -0
- package/dist/whiteboard/v1-client.d.ts +18 -0
- package/dist/whiteboard/v1-client.d.ts.map +1 -0
- package/dist/whiteboard/v1-codec.d.ts +5 -0
- package/dist/whiteboard/v1-codec.d.ts.map +1 -0
- package/dist/whiteboard/v1-create.d.ts +8 -0
- package/dist/whiteboard/v1-create.d.ts.map +1 -0
- package/dist/whiteboard/v1-multipart.d.ts +30 -0
- package/dist/whiteboard/v1-multipart.d.ts.map +1 -0
- package/dist/whiteboard/v1-persistence.d.ts +9 -0
- package/dist/whiteboard/v1-persistence.d.ts.map +1 -0
- package/package.json +222 -0
|
@@ -0,0 +1,1242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/webhooks/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
WebhookServerOnlyError: () => WebhookServerOnlyError,
|
|
24
|
+
WebhookVerificationError: () => WebhookVerificationError,
|
|
25
|
+
createWebhookProcessor: () => createWebhookProcessor,
|
|
26
|
+
knownWebhookEventNamesV1: () => knownWebhookEventNamesV1,
|
|
27
|
+
toWebhookResponse: () => toWebhookResponse,
|
|
28
|
+
verifyWebhook: () => verifyWebhook,
|
|
29
|
+
webhookEventSchemaV1: () => webhookEventSchemaV1
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
|
|
33
|
+
// src/webhooks/errors.ts
|
|
34
|
+
var messages = {
|
|
35
|
+
missing_headers: "Required webhook headers are missing.",
|
|
36
|
+
malformed_headers: "Webhook headers are malformed.",
|
|
37
|
+
invalid_secret: "A webhook signing secret is invalid.",
|
|
38
|
+
stale_timestamp: "The webhook timestamp is outside the allowed tolerance.",
|
|
39
|
+
invalid_signature: "The webhook signature is invalid.",
|
|
40
|
+
invalid_json: "The webhook body is not valid JSON.",
|
|
41
|
+
identifier_mismatch: "The webhook identifiers do not match.",
|
|
42
|
+
unsupported_api_version: "The webhook API version is unsupported.",
|
|
43
|
+
invalid_event_body: "The webhook Event body is invalid."
|
|
44
|
+
};
|
|
45
|
+
var WebhookVerificationError = class extends Error {
|
|
46
|
+
code;
|
|
47
|
+
constructor(code) {
|
|
48
|
+
super(messages[code]);
|
|
49
|
+
this.name = "WebhookVerificationError";
|
|
50
|
+
this.code = code;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var WebhookServerOnlyError = class extends Error {
|
|
54
|
+
constructor() {
|
|
55
|
+
super("Chalk webhook receivers are available only in server and edge runtimes.");
|
|
56
|
+
this.name = "WebhookServerOnlyError";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/webhooks/generated/event-v1.ts
|
|
61
|
+
var webhookEventSchemaV1 = {
|
|
62
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
63
|
+
$id: "https://chalk.dev/contracts/webhooks/v1/event.schema.json",
|
|
64
|
+
title: "Chalk webhook Event version 1",
|
|
65
|
+
type: "object",
|
|
66
|
+
required: ["id", "event", "api_version", "occurred_at", "tenant_id", "data"],
|
|
67
|
+
properties: {
|
|
68
|
+
id: {
|
|
69
|
+
$ref: "#/$defs/uuid"
|
|
70
|
+
},
|
|
71
|
+
event: {
|
|
72
|
+
type: "string"
|
|
73
|
+
},
|
|
74
|
+
api_version: {
|
|
75
|
+
const: 1
|
|
76
|
+
},
|
|
77
|
+
occurred_at: {
|
|
78
|
+
$ref: "#/$defs/timestamp"
|
|
79
|
+
},
|
|
80
|
+
tenant_id: {
|
|
81
|
+
$ref: "#/$defs/uuid"
|
|
82
|
+
},
|
|
83
|
+
data: {
|
|
84
|
+
type: "object"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
additionalProperties: true,
|
|
88
|
+
oneOf: [
|
|
89
|
+
{
|
|
90
|
+
$ref: "#/$defs/spaceCreated"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
$ref: "#/$defs/spaceUpdated"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
$ref: "#/$defs/spaceArchived"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
$ref: "#/$defs/spaceRestored"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
$ref: "#/$defs/episodeStarted"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
$ref: "#/$defs/episodeEnded"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
$ref: "#/$defs/participantJoined"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
$ref: "#/$defs/participantLeft"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
$ref: "#/$defs/recordingStarted"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
$ref: "#/$defs/recordingCompleted"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
$ref: "#/$defs/recordingFailed"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
$ref: "#/$defs/transcriptStarted"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
$ref: "#/$defs/transcriptCompleted"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
$ref: "#/$defs/transcriptFailed"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
$ref: "#/$defs/endpointTest"
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
$defs: {
|
|
136
|
+
uuid: {
|
|
137
|
+
type: "string",
|
|
138
|
+
format: "uuid",
|
|
139
|
+
pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
|
|
140
|
+
},
|
|
141
|
+
timestamp: {
|
|
142
|
+
type: "string",
|
|
143
|
+
format: "date-time",
|
|
144
|
+
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$"
|
|
145
|
+
},
|
|
146
|
+
nullableTimestamp: {
|
|
147
|
+
oneOf: [
|
|
148
|
+
{
|
|
149
|
+
$ref: "#/$defs/timestamp"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
type: "null"
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
nullableUUID: {
|
|
157
|
+
oneOf: [
|
|
158
|
+
{
|
|
159
|
+
$ref: "#/$defs/uuid"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
type: "null"
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
failure: {
|
|
167
|
+
oneOf: [
|
|
168
|
+
{
|
|
169
|
+
type: "null"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
type: "object",
|
|
173
|
+
required: ["code"],
|
|
174
|
+
properties: {
|
|
175
|
+
code: {
|
|
176
|
+
type: "string",
|
|
177
|
+
minLength: 1,
|
|
178
|
+
maxLength: 96
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
additionalProperties: true
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
},
|
|
185
|
+
spaceObject: {
|
|
186
|
+
type: "object",
|
|
187
|
+
required: ["id", "name", "slug", "media_plane", "created_at", "updated_at"],
|
|
188
|
+
properties: {
|
|
189
|
+
id: {
|
|
190
|
+
$ref: "#/$defs/uuid"
|
|
191
|
+
},
|
|
192
|
+
name: {
|
|
193
|
+
type: "string"
|
|
194
|
+
},
|
|
195
|
+
slug: {
|
|
196
|
+
type: "string"
|
|
197
|
+
},
|
|
198
|
+
media_plane: {
|
|
199
|
+
type: "string"
|
|
200
|
+
},
|
|
201
|
+
archived_at: {
|
|
202
|
+
$ref: "#/$defs/nullableTimestamp"
|
|
203
|
+
},
|
|
204
|
+
created_at: {
|
|
205
|
+
$ref: "#/$defs/timestamp"
|
|
206
|
+
},
|
|
207
|
+
updated_at: {
|
|
208
|
+
$ref: "#/$defs/timestamp"
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
additionalProperties: true
|
|
212
|
+
},
|
|
213
|
+
episodeObject: {
|
|
214
|
+
type: "object",
|
|
215
|
+
required: ["id", "space_id", "status", "started_at", "ended_at", "created_at", "updated_at"],
|
|
216
|
+
properties: {
|
|
217
|
+
id: {
|
|
218
|
+
$ref: "#/$defs/uuid"
|
|
219
|
+
},
|
|
220
|
+
space_id: {
|
|
221
|
+
$ref: "#/$defs/uuid"
|
|
222
|
+
},
|
|
223
|
+
status: {
|
|
224
|
+
enum: ["active", "ended"]
|
|
225
|
+
},
|
|
226
|
+
started_at: {
|
|
227
|
+
$ref: "#/$defs/timestamp"
|
|
228
|
+
},
|
|
229
|
+
ended_at: {
|
|
230
|
+
$ref: "#/$defs/nullableTimestamp"
|
|
231
|
+
},
|
|
232
|
+
created_at: {
|
|
233
|
+
$ref: "#/$defs/timestamp"
|
|
234
|
+
},
|
|
235
|
+
updated_at: {
|
|
236
|
+
$ref: "#/$defs/timestamp"
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
additionalProperties: true
|
|
240
|
+
},
|
|
241
|
+
participantObject: {
|
|
242
|
+
type: "object",
|
|
243
|
+
required: ["id", "identity_id", "space_id", "episode_id", "name", "status", "joined_at", "left_at"],
|
|
244
|
+
properties: {
|
|
245
|
+
id: {
|
|
246
|
+
$ref: "#/$defs/uuid"
|
|
247
|
+
},
|
|
248
|
+
identity_id: {
|
|
249
|
+
$ref: "#/$defs/nullableUUID"
|
|
250
|
+
},
|
|
251
|
+
space_id: {
|
|
252
|
+
$ref: "#/$defs/uuid"
|
|
253
|
+
},
|
|
254
|
+
episode_id: {
|
|
255
|
+
$ref: "#/$defs/uuid"
|
|
256
|
+
},
|
|
257
|
+
name: {
|
|
258
|
+
type: ["string", "null"]
|
|
259
|
+
},
|
|
260
|
+
status: {
|
|
261
|
+
enum: ["active", "left"]
|
|
262
|
+
},
|
|
263
|
+
joined_at: {
|
|
264
|
+
$ref: "#/$defs/timestamp"
|
|
265
|
+
},
|
|
266
|
+
left_at: {
|
|
267
|
+
$ref: "#/$defs/nullableTimestamp"
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
additionalProperties: true
|
|
271
|
+
},
|
|
272
|
+
recordingObject: {
|
|
273
|
+
type: "object",
|
|
274
|
+
required: ["id", "space_id", "episode_id", "status", "started_at", "completed_at", "failed_at", "failure", "created_at", "updated_at"],
|
|
275
|
+
properties: {
|
|
276
|
+
id: {
|
|
277
|
+
$ref: "#/$defs/uuid"
|
|
278
|
+
},
|
|
279
|
+
space_id: {
|
|
280
|
+
$ref: "#/$defs/uuid"
|
|
281
|
+
},
|
|
282
|
+
episode_id: {
|
|
283
|
+
$ref: "#/$defs/uuid"
|
|
284
|
+
},
|
|
285
|
+
status: {
|
|
286
|
+
enum: ["started", "completed", "failed"]
|
|
287
|
+
},
|
|
288
|
+
started_at: {
|
|
289
|
+
$ref: "#/$defs/timestamp"
|
|
290
|
+
},
|
|
291
|
+
completed_at: {
|
|
292
|
+
$ref: "#/$defs/nullableTimestamp"
|
|
293
|
+
},
|
|
294
|
+
failed_at: {
|
|
295
|
+
$ref: "#/$defs/nullableTimestamp"
|
|
296
|
+
},
|
|
297
|
+
failure: {
|
|
298
|
+
$ref: "#/$defs/failure"
|
|
299
|
+
},
|
|
300
|
+
created_at: {
|
|
301
|
+
$ref: "#/$defs/timestamp"
|
|
302
|
+
},
|
|
303
|
+
updated_at: {
|
|
304
|
+
$ref: "#/$defs/timestamp"
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
additionalProperties: true
|
|
308
|
+
},
|
|
309
|
+
transcriptObject: {
|
|
310
|
+
type: "object",
|
|
311
|
+
required: ["id", "recording_id", "space_id", "episode_id", "status", "languages", "started_at", "completed_at", "failed_at", "failure", "created_at", "updated_at"],
|
|
312
|
+
properties: {
|
|
313
|
+
id: {
|
|
314
|
+
$ref: "#/$defs/uuid"
|
|
315
|
+
},
|
|
316
|
+
recording_id: {
|
|
317
|
+
$ref: "#/$defs/uuid"
|
|
318
|
+
},
|
|
319
|
+
space_id: {
|
|
320
|
+
$ref: "#/$defs/uuid"
|
|
321
|
+
},
|
|
322
|
+
episode_id: {
|
|
323
|
+
$ref: "#/$defs/uuid"
|
|
324
|
+
},
|
|
325
|
+
status: {
|
|
326
|
+
enum: ["started", "completed", "failed"]
|
|
327
|
+
},
|
|
328
|
+
languages: {
|
|
329
|
+
type: "array",
|
|
330
|
+
items: {
|
|
331
|
+
type: "string"
|
|
332
|
+
},
|
|
333
|
+
uniqueItems: true
|
|
334
|
+
},
|
|
335
|
+
started_at: {
|
|
336
|
+
$ref: "#/$defs/timestamp"
|
|
337
|
+
},
|
|
338
|
+
completed_at: {
|
|
339
|
+
$ref: "#/$defs/nullableTimestamp"
|
|
340
|
+
},
|
|
341
|
+
failed_at: {
|
|
342
|
+
$ref: "#/$defs/nullableTimestamp"
|
|
343
|
+
},
|
|
344
|
+
failure: {
|
|
345
|
+
$ref: "#/$defs/failure"
|
|
346
|
+
},
|
|
347
|
+
created_at: {
|
|
348
|
+
$ref: "#/$defs/timestamp"
|
|
349
|
+
},
|
|
350
|
+
updated_at: {
|
|
351
|
+
$ref: "#/$defs/timestamp"
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
additionalProperties: true
|
|
355
|
+
},
|
|
356
|
+
spaceData: {
|
|
357
|
+
type: "object",
|
|
358
|
+
required: ["object"],
|
|
359
|
+
properties: {
|
|
360
|
+
object: {
|
|
361
|
+
$ref: "#/$defs/spaceObject"
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
additionalProperties: true
|
|
365
|
+
},
|
|
366
|
+
spaceUpdatedData: {
|
|
367
|
+
type: "object",
|
|
368
|
+
required: ["object", "changed_fields"],
|
|
369
|
+
properties: {
|
|
370
|
+
object: {
|
|
371
|
+
$ref: "#/$defs/spaceObject"
|
|
372
|
+
},
|
|
373
|
+
changed_fields: {
|
|
374
|
+
type: "array",
|
|
375
|
+
minItems: 1,
|
|
376
|
+
uniqueItems: true,
|
|
377
|
+
items: {
|
|
378
|
+
enum: ["admission_policy", "default_episode_duration_seconds", "linger_window_seconds", "maximum_episode_duration_seconds", "media_plane", "metadata", "name", "recurring_policy", "slug"]
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
additionalProperties: true
|
|
383
|
+
},
|
|
384
|
+
episodeData: {
|
|
385
|
+
type: "object",
|
|
386
|
+
required: ["object"],
|
|
387
|
+
properties: {
|
|
388
|
+
object: {
|
|
389
|
+
$ref: "#/$defs/episodeObject"
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
additionalProperties: true
|
|
393
|
+
},
|
|
394
|
+
participantData: {
|
|
395
|
+
type: "object",
|
|
396
|
+
required: ["object"],
|
|
397
|
+
properties: {
|
|
398
|
+
object: {
|
|
399
|
+
$ref: "#/$defs/participantObject"
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
additionalProperties: true
|
|
403
|
+
},
|
|
404
|
+
recordingData: {
|
|
405
|
+
type: "object",
|
|
406
|
+
required: ["object"],
|
|
407
|
+
properties: {
|
|
408
|
+
object: {
|
|
409
|
+
$ref: "#/$defs/recordingObject"
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
additionalProperties: true
|
|
413
|
+
},
|
|
414
|
+
transcriptData: {
|
|
415
|
+
type: "object",
|
|
416
|
+
required: ["object"],
|
|
417
|
+
properties: {
|
|
418
|
+
object: {
|
|
419
|
+
$ref: "#/$defs/transcriptObject"
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
additionalProperties: true
|
|
423
|
+
},
|
|
424
|
+
spaceCreated: {
|
|
425
|
+
$ref: "#/$defs/spaceCreatedShape"
|
|
426
|
+
},
|
|
427
|
+
spaceCreatedShape: {
|
|
428
|
+
properties: {
|
|
429
|
+
event: {
|
|
430
|
+
const: "space.created"
|
|
431
|
+
},
|
|
432
|
+
data: {
|
|
433
|
+
$ref: "#/$defs/spaceData"
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
spaceUpdated: {
|
|
438
|
+
properties: {
|
|
439
|
+
event: {
|
|
440
|
+
const: "space.updated"
|
|
441
|
+
},
|
|
442
|
+
data: {
|
|
443
|
+
$ref: "#/$defs/spaceUpdatedData"
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
spaceArchived: {
|
|
448
|
+
properties: {
|
|
449
|
+
event: {
|
|
450
|
+
const: "space.archived"
|
|
451
|
+
},
|
|
452
|
+
data: {
|
|
453
|
+
allOf: [
|
|
454
|
+
{
|
|
455
|
+
$ref: "#/$defs/spaceData"
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
properties: {
|
|
459
|
+
object: {
|
|
460
|
+
required: ["archived_at"],
|
|
461
|
+
properties: {
|
|
462
|
+
archived_at: {
|
|
463
|
+
$ref: "#/$defs/timestamp"
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
]
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
spaceRestored: {
|
|
474
|
+
properties: {
|
|
475
|
+
event: {
|
|
476
|
+
const: "space.restored"
|
|
477
|
+
},
|
|
478
|
+
data: {
|
|
479
|
+
$ref: "#/$defs/spaceData"
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
episodeStarted: {
|
|
484
|
+
properties: {
|
|
485
|
+
event: {
|
|
486
|
+
const: "episode.started"
|
|
487
|
+
},
|
|
488
|
+
data: {
|
|
489
|
+
allOf: [
|
|
490
|
+
{
|
|
491
|
+
$ref: "#/$defs/episodeData"
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
properties: {
|
|
495
|
+
object: {
|
|
496
|
+
properties: {
|
|
497
|
+
status: {
|
|
498
|
+
const: "active"
|
|
499
|
+
},
|
|
500
|
+
ended_at: {
|
|
501
|
+
type: "null"
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
]
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
episodeEnded: {
|
|
512
|
+
properties: {
|
|
513
|
+
event: {
|
|
514
|
+
const: "episode.ended"
|
|
515
|
+
},
|
|
516
|
+
data: {
|
|
517
|
+
allOf: [
|
|
518
|
+
{
|
|
519
|
+
$ref: "#/$defs/episodeData"
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
properties: {
|
|
523
|
+
object: {
|
|
524
|
+
properties: {
|
|
525
|
+
status: {
|
|
526
|
+
const: "ended"
|
|
527
|
+
},
|
|
528
|
+
ended_at: {
|
|
529
|
+
$ref: "#/$defs/timestamp"
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
]
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
participantJoined: {
|
|
540
|
+
properties: {
|
|
541
|
+
event: {
|
|
542
|
+
const: "participant.joined"
|
|
543
|
+
},
|
|
544
|
+
data: {
|
|
545
|
+
allOf: [
|
|
546
|
+
{
|
|
547
|
+
$ref: "#/$defs/participantData"
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
properties: {
|
|
551
|
+
object: {
|
|
552
|
+
properties: {
|
|
553
|
+
status: {
|
|
554
|
+
const: "active"
|
|
555
|
+
},
|
|
556
|
+
left_at: {
|
|
557
|
+
type: "null"
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
]
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
participantLeft: {
|
|
568
|
+
properties: {
|
|
569
|
+
event: {
|
|
570
|
+
const: "participant.left"
|
|
571
|
+
},
|
|
572
|
+
data: {
|
|
573
|
+
allOf: [
|
|
574
|
+
{
|
|
575
|
+
$ref: "#/$defs/participantData"
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
properties: {
|
|
579
|
+
object: {
|
|
580
|
+
properties: {
|
|
581
|
+
status: {
|
|
582
|
+
const: "left"
|
|
583
|
+
},
|
|
584
|
+
left_at: {
|
|
585
|
+
$ref: "#/$defs/timestamp"
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
]
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
recordingStarted: {
|
|
596
|
+
properties: {
|
|
597
|
+
event: {
|
|
598
|
+
const: "recording.started"
|
|
599
|
+
},
|
|
600
|
+
data: {
|
|
601
|
+
allOf: [
|
|
602
|
+
{
|
|
603
|
+
$ref: "#/$defs/recordingData"
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
properties: {
|
|
607
|
+
object: {
|
|
608
|
+
properties: {
|
|
609
|
+
status: {
|
|
610
|
+
const: "started"
|
|
611
|
+
},
|
|
612
|
+
completed_at: {
|
|
613
|
+
type: "null"
|
|
614
|
+
},
|
|
615
|
+
failed_at: {
|
|
616
|
+
type: "null"
|
|
617
|
+
},
|
|
618
|
+
failure: {
|
|
619
|
+
type: "null"
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
]
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
recordingCompleted: {
|
|
630
|
+
properties: {
|
|
631
|
+
event: {
|
|
632
|
+
const: "recording.completed"
|
|
633
|
+
},
|
|
634
|
+
data: {
|
|
635
|
+
allOf: [
|
|
636
|
+
{
|
|
637
|
+
$ref: "#/$defs/recordingData"
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
properties: {
|
|
641
|
+
object: {
|
|
642
|
+
properties: {
|
|
643
|
+
status: {
|
|
644
|
+
const: "completed"
|
|
645
|
+
},
|
|
646
|
+
completed_at: {
|
|
647
|
+
$ref: "#/$defs/timestamp"
|
|
648
|
+
},
|
|
649
|
+
failed_at: {
|
|
650
|
+
type: "null"
|
|
651
|
+
},
|
|
652
|
+
failure: {
|
|
653
|
+
type: "null"
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
]
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
recordingFailed: {
|
|
664
|
+
properties: {
|
|
665
|
+
event: {
|
|
666
|
+
const: "recording.failed"
|
|
667
|
+
},
|
|
668
|
+
data: {
|
|
669
|
+
allOf: [
|
|
670
|
+
{
|
|
671
|
+
$ref: "#/$defs/recordingData"
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
properties: {
|
|
675
|
+
object: {
|
|
676
|
+
properties: {
|
|
677
|
+
status: {
|
|
678
|
+
const: "failed"
|
|
679
|
+
},
|
|
680
|
+
completed_at: {
|
|
681
|
+
type: "null"
|
|
682
|
+
},
|
|
683
|
+
failed_at: {
|
|
684
|
+
$ref: "#/$defs/timestamp"
|
|
685
|
+
},
|
|
686
|
+
failure: {
|
|
687
|
+
type: "object"
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
]
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
transcriptStarted: {
|
|
698
|
+
properties: {
|
|
699
|
+
event: {
|
|
700
|
+
const: "transcript.started"
|
|
701
|
+
},
|
|
702
|
+
data: {
|
|
703
|
+
allOf: [
|
|
704
|
+
{
|
|
705
|
+
$ref: "#/$defs/transcriptData"
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
properties: {
|
|
709
|
+
object: {
|
|
710
|
+
properties: {
|
|
711
|
+
status: {
|
|
712
|
+
const: "started"
|
|
713
|
+
},
|
|
714
|
+
completed_at: {
|
|
715
|
+
type: "null"
|
|
716
|
+
},
|
|
717
|
+
failed_at: {
|
|
718
|
+
type: "null"
|
|
719
|
+
},
|
|
720
|
+
failure: {
|
|
721
|
+
type: "null"
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
]
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
},
|
|
731
|
+
transcriptCompleted: {
|
|
732
|
+
properties: {
|
|
733
|
+
event: {
|
|
734
|
+
const: "transcript.completed"
|
|
735
|
+
},
|
|
736
|
+
data: {
|
|
737
|
+
allOf: [
|
|
738
|
+
{
|
|
739
|
+
$ref: "#/$defs/transcriptData"
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
properties: {
|
|
743
|
+
object: {
|
|
744
|
+
properties: {
|
|
745
|
+
status: {
|
|
746
|
+
const: "completed"
|
|
747
|
+
},
|
|
748
|
+
completed_at: {
|
|
749
|
+
$ref: "#/$defs/timestamp"
|
|
750
|
+
},
|
|
751
|
+
failed_at: {
|
|
752
|
+
type: "null"
|
|
753
|
+
},
|
|
754
|
+
failure: {
|
|
755
|
+
type: "null"
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
]
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
},
|
|
765
|
+
transcriptFailed: {
|
|
766
|
+
properties: {
|
|
767
|
+
event: {
|
|
768
|
+
const: "transcript.failed"
|
|
769
|
+
},
|
|
770
|
+
data: {
|
|
771
|
+
allOf: [
|
|
772
|
+
{
|
|
773
|
+
$ref: "#/$defs/transcriptData"
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
properties: {
|
|
777
|
+
object: {
|
|
778
|
+
properties: {
|
|
779
|
+
status: {
|
|
780
|
+
const: "failed"
|
|
781
|
+
},
|
|
782
|
+
completed_at: {
|
|
783
|
+
type: "null"
|
|
784
|
+
},
|
|
785
|
+
failed_at: {
|
|
786
|
+
$ref: "#/$defs/timestamp"
|
|
787
|
+
},
|
|
788
|
+
failure: {
|
|
789
|
+
type: "object"
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
]
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
},
|
|
799
|
+
endpointTest: {
|
|
800
|
+
properties: {
|
|
801
|
+
event: {
|
|
802
|
+
const: "endpoint.test"
|
|
803
|
+
},
|
|
804
|
+
data: {
|
|
805
|
+
type: "object",
|
|
806
|
+
required: ["object"],
|
|
807
|
+
properties: {
|
|
808
|
+
object: {
|
|
809
|
+
type: "object",
|
|
810
|
+
required: ["endpoint_id"],
|
|
811
|
+
properties: {
|
|
812
|
+
endpoint_id: {
|
|
813
|
+
$ref: "#/$defs/uuid"
|
|
814
|
+
}
|
|
815
|
+
},
|
|
816
|
+
additionalProperties: true
|
|
817
|
+
}
|
|
818
|
+
},
|
|
819
|
+
additionalProperties: true
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
var knownWebhookEventNamesV1 = [
|
|
826
|
+
"space.created",
|
|
827
|
+
"space.updated",
|
|
828
|
+
"space.archived",
|
|
829
|
+
"space.restored",
|
|
830
|
+
"episode.started",
|
|
831
|
+
"episode.ended",
|
|
832
|
+
"participant.joined",
|
|
833
|
+
"participant.left",
|
|
834
|
+
"recording.started",
|
|
835
|
+
"recording.completed",
|
|
836
|
+
"recording.failed",
|
|
837
|
+
"transcript.started",
|
|
838
|
+
"transcript.completed",
|
|
839
|
+
"transcript.failed",
|
|
840
|
+
"endpoint.test"
|
|
841
|
+
];
|
|
842
|
+
|
|
843
|
+
// src/webhooks/validate.ts
|
|
844
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
845
|
+
var resolveRef = (ref) => {
|
|
846
|
+
const name = ref.startsWith("#/$defs/") ? ref.slice(8) : "";
|
|
847
|
+
return webhookEventSchemaV1.$defs[name];
|
|
848
|
+
};
|
|
849
|
+
var typeMatchers = {
|
|
850
|
+
array: Array.isArray,
|
|
851
|
+
integer: Number.isInteger,
|
|
852
|
+
null: (value) => value === null,
|
|
853
|
+
object: isObject
|
|
854
|
+
};
|
|
855
|
+
var matchesType = (value, type) => typeMatchers[type]?.(value) ?? typeof value === type;
|
|
856
|
+
var hasUniqueItems = (values) => {
|
|
857
|
+
const serialized = values.map((value) => JSON.stringify(value));
|
|
858
|
+
return new Set(serialized).size === serialized.length;
|
|
859
|
+
};
|
|
860
|
+
var isUtcMillisecondTimestamp = (value) => {
|
|
861
|
+
const milliseconds = Date.parse(value);
|
|
862
|
+
return Number.isFinite(milliseconds) && new Date(milliseconds).toISOString() === value;
|
|
863
|
+
};
|
|
864
|
+
var validatesReference = (value, schema) => {
|
|
865
|
+
if (typeof schema.$ref !== "string") return void 0;
|
|
866
|
+
const resolved = resolveRef(schema.$ref);
|
|
867
|
+
return resolved !== void 0 && validateSchema(value, resolved);
|
|
868
|
+
};
|
|
869
|
+
var validatesConstants = (value, schema) => {
|
|
870
|
+
if ("const" in schema && !Object.is(value, schema.const)) return false;
|
|
871
|
+
return !Array.isArray(schema.enum) || schema.enum.some((entry) => Object.is(entry, value));
|
|
872
|
+
};
|
|
873
|
+
var validatesDeclaredType = (value, schema) => {
|
|
874
|
+
if (typeof schema.type === "string") return matchesType(value, schema.type);
|
|
875
|
+
return !Array.isArray(schema.type) || schema.type.some((type) => typeof type === "string" && matchesType(value, type));
|
|
876
|
+
};
|
|
877
|
+
var validatesCompositions = (value, schema) => {
|
|
878
|
+
const oneOfMatches = Array.isArray(schema.oneOf) ? schema.oneOf.filter((entry) => isObject(entry) && validateSchema(value, entry)).length : 1;
|
|
879
|
+
if (oneOfMatches !== 1) return false;
|
|
880
|
+
return !Array.isArray(schema.allOf) || schema.allOf.every((entry) => isObject(entry) && validateSchema(value, entry));
|
|
881
|
+
};
|
|
882
|
+
var validatesPattern = (value, schema) => typeof schema.pattern !== "string" || new RegExp(schema.pattern, "u").test(value);
|
|
883
|
+
var validatesFormat = (value, schema) => schema.format !== "date-time" || isUtcMillisecondTimestamp(value);
|
|
884
|
+
var validatesMinimumLength = (value, schema) => typeof schema.minLength !== "number" || value.length >= schema.minLength;
|
|
885
|
+
var validatesMaximumLength = (value, schema) => typeof schema.maxLength !== "number" || value.length <= schema.maxLength;
|
|
886
|
+
var stringValidators = [validatesPattern, validatesFormat, validatesMinimumLength, validatesMaximumLength];
|
|
887
|
+
var validatesString = (value, schema) => stringValidators.every((validate) => validate(value, schema));
|
|
888
|
+
var validatesMinimumItems = (value, schema) => typeof schema.minItems !== "number" || value.length >= schema.minItems;
|
|
889
|
+
var validatesUniqueItems = (value, schema) => schema.uniqueItems !== true || hasUniqueItems(value);
|
|
890
|
+
var validatesItems = (value, schema) => !isObject(schema.items) || value.every((entry) => validateSchema(entry, schema.items));
|
|
891
|
+
var arrayValidators = [validatesMinimumItems, validatesUniqueItems, validatesItems];
|
|
892
|
+
var validatesArray = (value, schema) => arrayValidators.every((validate) => validate(value, schema));
|
|
893
|
+
var validatesRequiredProperties = (value, schema) => !Array.isArray(schema.required) || schema.required.every((key) => typeof key === "string" && key in value);
|
|
894
|
+
var validatesProperties = (value, schema) => {
|
|
895
|
+
if (!isObject(schema.properties)) return true;
|
|
896
|
+
if (!validatesRequiredProperties(value, schema)) return false;
|
|
897
|
+
return Object.entries(schema.properties).every(([key, propertySchema]) => !(key in value) || isObject(propertySchema) && validateSchema(value[key], propertySchema));
|
|
898
|
+
};
|
|
899
|
+
var schemaValidators = [validatesConstants, validatesDeclaredType, validatesCompositions];
|
|
900
|
+
var validatesValueConstraints = (value, schema) => {
|
|
901
|
+
if (typeof value === "string") return validatesString(value, schema);
|
|
902
|
+
if (Array.isArray(value)) return validatesArray(value, schema);
|
|
903
|
+
if (isObject(value)) return validatesProperties(value, schema);
|
|
904
|
+
return true;
|
|
905
|
+
};
|
|
906
|
+
var validateSchema = (value, schema) => {
|
|
907
|
+
const referenceResult = validatesReference(value, schema);
|
|
908
|
+
if (referenceResult !== void 0) return referenceResult;
|
|
909
|
+
if (!schemaValidators.every((validate) => validate(value, schema))) return false;
|
|
910
|
+
return validatesValueConstraints(value, schema);
|
|
911
|
+
};
|
|
912
|
+
var validateWebhookEnvelopeV1 = (value) => {
|
|
913
|
+
const { oneOf: _oneOf, ...envelopeSchema } = webhookEventSchemaV1;
|
|
914
|
+
return validateSchema(value, envelopeSchema);
|
|
915
|
+
};
|
|
916
|
+
var validateKnownWebhookEventV1 = (value) => validateSchema(value, webhookEventSchemaV1);
|
|
917
|
+
|
|
918
|
+
// src/webhooks/verify.ts
|
|
919
|
+
var DEFAULT_TOLERANCE_SECONDS = 300;
|
|
920
|
+
var MAX_HEADER_LENGTH = 4096;
|
|
921
|
+
var MAX_SIGNATURES = 32;
|
|
922
|
+
var MAX_SECRETS = 16;
|
|
923
|
+
var MAX_BODY_BYTES = 256 * 1024;
|
|
924
|
+
var encoder = new TextEncoder();
|
|
925
|
+
var decoder = new TextDecoder("utf-8", { fatal: true });
|
|
926
|
+
var knownNames = new Set(knownWebhookEventNamesV1);
|
|
927
|
+
var normalizeHeaderValue = (value, allowArray) => {
|
|
928
|
+
if (!Array.isArray(value)) return value;
|
|
929
|
+
if (!allowArray || value.length === 0) throw new WebhookVerificationError("malformed_headers");
|
|
930
|
+
return value.join(" ");
|
|
931
|
+
};
|
|
932
|
+
var getRecordHeader = (headers, name, allowArray) => {
|
|
933
|
+
const entries = Object.entries(headers).filter(([key]) => key.toLowerCase() === name);
|
|
934
|
+
if (entries.length > 1) throw new WebhookVerificationError("malformed_headers");
|
|
935
|
+
return normalizeHeaderValue(entries[0]?.[1], allowArray);
|
|
936
|
+
};
|
|
937
|
+
var getHeader = (headers, name, allowArray = false) => {
|
|
938
|
+
if (headers instanceof Headers) return headers.get(name) ?? void 0;
|
|
939
|
+
return getRecordHeader(headers, name, allowArray);
|
|
940
|
+
};
|
|
941
|
+
var parseBase64 = (value) => {
|
|
942
|
+
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u.test(value)) return void 0;
|
|
943
|
+
try {
|
|
944
|
+
const binary = atob(value);
|
|
945
|
+
return Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
946
|
+
} catch {
|
|
947
|
+
return void 0;
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
var decodeSecrets = (secrets) => {
|
|
951
|
+
if (!Array.isArray(secrets) || secrets.length === 0 || secrets.length > MAX_SECRETS) {
|
|
952
|
+
throw new WebhookVerificationError("invalid_secret");
|
|
953
|
+
}
|
|
954
|
+
return secrets.map(decodeSecret);
|
|
955
|
+
};
|
|
956
|
+
var decodeSecret = (secret) => {
|
|
957
|
+
if (typeof secret !== "string") throw new WebhookVerificationError("invalid_secret");
|
|
958
|
+
if (!secret.startsWith("whsec_")) throw new WebhookVerificationError("invalid_secret");
|
|
959
|
+
return requireSecretBytes(parseBase64(secret.slice(6)));
|
|
960
|
+
};
|
|
961
|
+
var requireSecretBytes = (decoded) => {
|
|
962
|
+
if (decoded === void 0) throw new WebhookVerificationError("invalid_secret");
|
|
963
|
+
if (decoded.length !== 32) throw new WebhookVerificationError("invalid_secret");
|
|
964
|
+
return decoded;
|
|
965
|
+
};
|
|
966
|
+
var parseTimestamp = (timestampValue) => {
|
|
967
|
+
if (timestampValue.length > 16 || !/^[0-9]+$/u.test(timestampValue)) throw new WebhookVerificationError("malformed_headers");
|
|
968
|
+
const timestamp = Number(timestampValue);
|
|
969
|
+
if (!Number.isSafeInteger(timestamp)) throw new WebhookVerificationError("malformed_headers");
|
|
970
|
+
return timestamp;
|
|
971
|
+
};
|
|
972
|
+
var parseSignature = (part) => {
|
|
973
|
+
const match = /^v1,([A-Za-z0-9+/]+={0,2})$/u.exec(part);
|
|
974
|
+
if (!match) throw new WebhookVerificationError("malformed_headers");
|
|
975
|
+
return requireSignatureBytes(parseBase64(match[1] ?? ""));
|
|
976
|
+
};
|
|
977
|
+
var requireSignatureBytes = (bytes) => {
|
|
978
|
+
if (bytes === void 0) throw new WebhookVerificationError("malformed_headers");
|
|
979
|
+
if (bytes.length !== 32) throw new WebhookVerificationError("malformed_headers");
|
|
980
|
+
return bytes;
|
|
981
|
+
};
|
|
982
|
+
var parseSignatures = (signatureValue) => {
|
|
983
|
+
if (signatureValue.length > MAX_HEADER_LENGTH) throw new WebhookVerificationError("malformed_headers");
|
|
984
|
+
const parts = signatureValue.split(" ");
|
|
985
|
+
if (parts.length === 0 || parts.length > MAX_SIGNATURES) throw new WebhookVerificationError("malformed_headers");
|
|
986
|
+
return parts.map(parseSignature);
|
|
987
|
+
};
|
|
988
|
+
var requireHeader = (headers, name, allowArray = false) => {
|
|
989
|
+
const value = getHeader(headers, name, allowArray);
|
|
990
|
+
if (value === void 0) throw new WebhookVerificationError("missing_headers");
|
|
991
|
+
return value;
|
|
992
|
+
};
|
|
993
|
+
var parseHeaders = (headers) => {
|
|
994
|
+
const id = requireHeader(headers, "webhook-id");
|
|
995
|
+
const timestampValue = requireHeader(headers, "webhook-timestamp");
|
|
996
|
+
const signatureValue = requireHeader(headers, "webhook-signature", true);
|
|
997
|
+
if (id.length === 0 || id.length > 128) throw new WebhookVerificationError("malformed_headers");
|
|
998
|
+
return { id, timestamp: parseTimestamp(timestampValue), timestampValue, signatures: parseSignatures(signatureValue) };
|
|
999
|
+
};
|
|
1000
|
+
var signedPayload = (id, timestamp, rawBody) => {
|
|
1001
|
+
const prefix = encoder.encode(`${id}.${timestamp}.`);
|
|
1002
|
+
const payload = new Uint8Array(prefix.length + rawBody.length);
|
|
1003
|
+
payload.set(prefix);
|
|
1004
|
+
payload.set(rawBody, prefix.length);
|
|
1005
|
+
return payload;
|
|
1006
|
+
};
|
|
1007
|
+
var constantTimeEqual = (left, right) => {
|
|
1008
|
+
let difference = left.length ^ right.length;
|
|
1009
|
+
const length = Math.max(left.length, right.length);
|
|
1010
|
+
for (let index = 0; index < length; index += 1) difference |= (left[index] ?? 0) ^ (right[index] ?? 0);
|
|
1011
|
+
return difference === 0;
|
|
1012
|
+
};
|
|
1013
|
+
var signatureSetMatches = (expected, signatures) => {
|
|
1014
|
+
let matched = false;
|
|
1015
|
+
for (const supplied of signatures) matched = constantTimeEqual(expected, supplied) || matched;
|
|
1016
|
+
return matched;
|
|
1017
|
+
};
|
|
1018
|
+
var signPayload = async (payload, secret) => {
|
|
1019
|
+
const key = await crypto.subtle.importKey("raw", new Uint8Array(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
1020
|
+
return new Uint8Array(await crypto.subtle.sign("HMAC", key, new Uint8Array(payload)));
|
|
1021
|
+
};
|
|
1022
|
+
var verifySignature = async (payload, secrets, signatures) => {
|
|
1023
|
+
let matched = false;
|
|
1024
|
+
for (const secret of secrets) {
|
|
1025
|
+
matched = signatureSetMatches(await signPayload(payload, secret), signatures) || matched;
|
|
1026
|
+
}
|
|
1027
|
+
if (!matched) throw new WebhookVerificationError("invalid_signature");
|
|
1028
|
+
};
|
|
1029
|
+
var isFreezable = (value) => Boolean(value) && typeof value === "object";
|
|
1030
|
+
var deepFreeze = (value) => {
|
|
1031
|
+
if (!isFreezable(value)) return value;
|
|
1032
|
+
if (Object.isFrozen(value)) return value;
|
|
1033
|
+
for (const child of Object.values(value)) deepFreeze(child);
|
|
1034
|
+
Object.freeze(value);
|
|
1035
|
+
return value;
|
|
1036
|
+
};
|
|
1037
|
+
var validateTolerance = (tolerance) => {
|
|
1038
|
+
if (!Number.isSafeInteger(tolerance) || tolerance < 0) throw new WebhookVerificationError("malformed_headers");
|
|
1039
|
+
};
|
|
1040
|
+
var currentSeconds = (now) => {
|
|
1041
|
+
const currentTimeMilliseconds = now instanceof Date ? now.getTime() : Number.NaN;
|
|
1042
|
+
if (!Number.isFinite(currentTimeMilliseconds)) throw new WebhookVerificationError("stale_timestamp");
|
|
1043
|
+
return Math.floor(currentTimeMilliseconds / 1e3);
|
|
1044
|
+
};
|
|
1045
|
+
var validateTimestamp = (timestamp, tolerance, now) => {
|
|
1046
|
+
validateTolerance(tolerance);
|
|
1047
|
+
if (Math.abs(currentSeconds(now) - timestamp) > tolerance) throw new WebhookVerificationError("stale_timestamp");
|
|
1048
|
+
};
|
|
1049
|
+
var parseBody = (rawBody) => {
|
|
1050
|
+
try {
|
|
1051
|
+
return JSON.parse(decoder.decode(rawBody));
|
|
1052
|
+
} catch {
|
|
1053
|
+
throw new WebhookVerificationError("invalid_json");
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
var invalidApiVersion = (body) => typeof body === "object" && body !== null && "api_version" in body && body.api_version !== 1;
|
|
1057
|
+
var assertValidEnvelope = (body) => {
|
|
1058
|
+
if (validateWebhookEnvelopeV1(body)) return;
|
|
1059
|
+
if (invalidApiVersion(body)) throw new WebhookVerificationError("unsupported_api_version");
|
|
1060
|
+
throw new WebhookVerificationError("invalid_event_body");
|
|
1061
|
+
};
|
|
1062
|
+
var assertEventShape = (body) => {
|
|
1063
|
+
if (typeof body.event !== "string") throw new WebhookVerificationError("invalid_event_body");
|
|
1064
|
+
if (!isEventData(body.data)) throw new WebhookVerificationError("invalid_event_body");
|
|
1065
|
+
};
|
|
1066
|
+
var isEventData = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1067
|
+
var validateEnvelope = (body, headerId) => {
|
|
1068
|
+
assertValidEnvelope(body);
|
|
1069
|
+
if (body.api_version !== 1) throw new WebhookVerificationError("unsupported_api_version");
|
|
1070
|
+
if (body.id !== headerId) throw new WebhookVerificationError("identifier_mismatch");
|
|
1071
|
+
assertEventShape(body);
|
|
1072
|
+
};
|
|
1073
|
+
var validatedEvent = (body, headerId) => {
|
|
1074
|
+
validateEnvelope(body, headerId);
|
|
1075
|
+
if (!knownNames.has(body.event)) return deepFreeze(body);
|
|
1076
|
+
if (!validateKnownWebhookEventV1(body)) throw new WebhookVerificationError("invalid_event_body");
|
|
1077
|
+
return deepFreeze(body);
|
|
1078
|
+
};
|
|
1079
|
+
var verifyWebhook = async (input) => {
|
|
1080
|
+
assertBodySize(input.rawBody);
|
|
1081
|
+
const parsedHeaders = parseHeaders(input.headers);
|
|
1082
|
+
validateTimestamp(parsedHeaders.timestamp, input.toleranceSeconds ?? DEFAULT_TOLERANCE_SECONDS, input.now?.() ?? /* @__PURE__ */ new Date());
|
|
1083
|
+
const secrets = decodeSecrets(input.secrets);
|
|
1084
|
+
await verifySignature(signedPayload(parsedHeaders.id, parsedHeaders.timestampValue, input.rawBody), secrets, parsedHeaders.signatures);
|
|
1085
|
+
return validatedEvent(parseBody(input.rawBody), parsedHeaders.id);
|
|
1086
|
+
};
|
|
1087
|
+
function assertBodySize(rawBody) {
|
|
1088
|
+
if (rawBody.byteLength > MAX_BODY_BYTES) throw new WebhookVerificationError("invalid_event_body");
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
// src/webhooks/processor.ts
|
|
1092
|
+
var knownNames2 = new Set(knownWebhookEventNamesV1);
|
|
1093
|
+
var MAX_LEASE_MILLISECONDS = 3e5;
|
|
1094
|
+
var result = (value) => Object.freeze(value);
|
|
1095
|
+
var observe = (callback) => {
|
|
1096
|
+
if (!callback) return;
|
|
1097
|
+
try {
|
|
1098
|
+
void Promise.resolve(callback()).catch(() => void 0);
|
|
1099
|
+
} catch {
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
var emitDiagnostic = (callback, event, startedAt) => {
|
|
1103
|
+
observe(callback ? () => callback(Object.freeze({ ...event, durationMilliseconds: Math.max(0, performance.now() - startedAt) })) : void 0);
|
|
1104
|
+
};
|
|
1105
|
+
var safeRetryAfter = (value) => {
|
|
1106
|
+
if (!Number.isFinite(value) || value <= 0) return 1;
|
|
1107
|
+
return Math.min(300, Math.ceil(value));
|
|
1108
|
+
};
|
|
1109
|
+
var releaseLease = async (inbox, eventId, token) => {
|
|
1110
|
+
try {
|
|
1111
|
+
await inbox.release({ eventId, token });
|
|
1112
|
+
} catch {
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
var failedResult = (options, startedAt, errorCode, identity = {}) => {
|
|
1116
|
+
emitDiagnostic(options.onDiagnostic, { phase: "failed", outcome: "failed", ...identity }, startedAt);
|
|
1117
|
+
return result({ status: 500, outcome: "failed", errorCode, ...identity });
|
|
1118
|
+
};
|
|
1119
|
+
var loadSecrets = async (options, startedAt) => {
|
|
1120
|
+
try {
|
|
1121
|
+
const secrets = typeof options.secrets === "function" ? await options.secrets() : options.secrets;
|
|
1122
|
+
return { ok: true, secrets };
|
|
1123
|
+
} catch {
|
|
1124
|
+
return { ok: false, failure: failedResult(options, startedAt, "secret_provider_unavailable") };
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
var rejectedResult = (options, startedAt, error) => {
|
|
1128
|
+
const errorCode = error instanceof WebhookVerificationError ? error.code : "verification_failed";
|
|
1129
|
+
if (errorCode === "invalid_secret") return failedResult(options, startedAt, errorCode);
|
|
1130
|
+
emitDiagnostic(options.onDiagnostic, { phase: "rejected", outcome: "rejected" }, startedAt);
|
|
1131
|
+
return result({ status: errorCode === "invalid_signature" ? 401 : 400, outcome: "rejected", errorCode });
|
|
1132
|
+
};
|
|
1133
|
+
var verifyInput = async (input, secrets, options, startedAt) => {
|
|
1134
|
+
try {
|
|
1135
|
+
return await verifyWebhook({ ...input, secrets, toleranceSeconds: options.toleranceSeconds });
|
|
1136
|
+
} catch (error) {
|
|
1137
|
+
return rejectedResult(options, startedAt, error);
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
var acquireLease = async (options, leaseMilliseconds, identity, startedAt) => {
|
|
1141
|
+
try {
|
|
1142
|
+
const claim = await options.inbox.acquire({ eventId: identity.eventId, leaseMilliseconds });
|
|
1143
|
+
if (claim.state === "completed") return result({ status: 200, outcome: "duplicate", ...identity });
|
|
1144
|
+
if (claim.state === "busy") return result({ status: 503, outcome: "busy", retryAfterSeconds: safeRetryAfter(claim.retryAfterSeconds), ...identity });
|
|
1145
|
+
return claim;
|
|
1146
|
+
} catch {
|
|
1147
|
+
return failedResult(options, startedAt, "inbox_unavailable", identity);
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
var knownHandler = (event, handlers) => handlers[event.event];
|
|
1151
|
+
var handleKnownEvent = async (event, options) => {
|
|
1152
|
+
const handler = knownHandler(event, options.handlers);
|
|
1153
|
+
if (typeof handler !== "function") return "handler_missing";
|
|
1154
|
+
await handler(event);
|
|
1155
|
+
return void 0;
|
|
1156
|
+
};
|
|
1157
|
+
var observeUnknownEvent = (event, callback) => {
|
|
1158
|
+
if (!callback) return;
|
|
1159
|
+
observe(() => callback(event));
|
|
1160
|
+
};
|
|
1161
|
+
var handleAuthenticatedEvent = async (event, options) => {
|
|
1162
|
+
if (knownNames2.has(event.event)) return handleKnownEvent(event, options);
|
|
1163
|
+
observeUnknownEvent(event, options.onUnknownEvent);
|
|
1164
|
+
return void 0;
|
|
1165
|
+
};
|
|
1166
|
+
var handleEvent = async (event, claim, options, identity, startedAt) => {
|
|
1167
|
+
try {
|
|
1168
|
+
const errorCode = await handleAuthenticatedEvent(event, options);
|
|
1169
|
+
if (errorCode) {
|
|
1170
|
+
await releaseLease(options.inbox, event.id, claim.token);
|
|
1171
|
+
return failedResult(options, startedAt, errorCode, identity);
|
|
1172
|
+
}
|
|
1173
|
+
emitDiagnostic(options.onDiagnostic, { phase: "handled", outcome: "processed", ...identity }, startedAt);
|
|
1174
|
+
return void 0;
|
|
1175
|
+
} catch {
|
|
1176
|
+
await releaseLease(options.inbox, event.id, claim.token);
|
|
1177
|
+
return failedResult(options, startedAt, "handler_failed", identity);
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
var completeLease = async (claim, options, identity, startedAt) => {
|
|
1181
|
+
try {
|
|
1182
|
+
await options.inbox.complete({ eventId: identity.eventId, token: claim.token });
|
|
1183
|
+
return void 0;
|
|
1184
|
+
} catch {
|
|
1185
|
+
return failedResult(options, startedAt, "inbox_complete_failed", identity);
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
var requireSecretLoad = (load) => {
|
|
1189
|
+
if (!load.ok) throw new ProcessingStopped(load.failure);
|
|
1190
|
+
return load.secrets;
|
|
1191
|
+
};
|
|
1192
|
+
var requireValue = (value) => {
|
|
1193
|
+
if ("status" in value) throw new ProcessingStopped(value);
|
|
1194
|
+
return value;
|
|
1195
|
+
};
|
|
1196
|
+
var requireSuccess = (failure) => {
|
|
1197
|
+
if (failure) throw new ProcessingStopped(failure);
|
|
1198
|
+
};
|
|
1199
|
+
var ProcessingStopped = class extends Error {
|
|
1200
|
+
constructor(processResult) {
|
|
1201
|
+
super("Webhook processing stopped with a bounded result.");
|
|
1202
|
+
this.processResult = processResult;
|
|
1203
|
+
}
|
|
1204
|
+
processResult;
|
|
1205
|
+
};
|
|
1206
|
+
var runProcessingStages = async (input, options, leaseMilliseconds, startedAt) => {
|
|
1207
|
+
const secrets = requireSecretLoad(await loadSecrets(options, startedAt));
|
|
1208
|
+
const event = requireValue(await verifyInput(input, secrets, options, startedAt));
|
|
1209
|
+
const identity = { eventId: event.id, eventName: event.event, apiVersion: event.api_version };
|
|
1210
|
+
emitDiagnostic(options.onDiagnostic, { phase: "verified", outcome: "processed", ...identity }, startedAt);
|
|
1211
|
+
const claim = requireValue(await acquireLease(options, leaseMilliseconds, identity, startedAt));
|
|
1212
|
+
emitDiagnostic(options.onDiagnostic, { phase: "acquired", outcome: "processed", ...identity }, startedAt);
|
|
1213
|
+
requireSuccess(await handleEvent(event, claim, options, identity, startedAt));
|
|
1214
|
+
requireSuccess(await completeLease(claim, options, identity, startedAt));
|
|
1215
|
+
const outcome = knownNames2.has(event.event) ? "processed" : "ignored";
|
|
1216
|
+
emitDiagnostic(options.onDiagnostic, { phase: "completed", outcome, ...identity }, startedAt);
|
|
1217
|
+
return result({ status: 200, outcome, ...identity });
|
|
1218
|
+
};
|
|
1219
|
+
var processWebhook = async (input, options, leaseMilliseconds) => {
|
|
1220
|
+
const startedAt = performance.now();
|
|
1221
|
+
try {
|
|
1222
|
+
return await runProcessingStages(input, options, leaseMilliseconds, startedAt);
|
|
1223
|
+
} catch (error) {
|
|
1224
|
+
if (error instanceof ProcessingStopped) return error.processResult;
|
|
1225
|
+
throw error;
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
var createWebhookProcessor = (options) => {
|
|
1229
|
+
const leaseMilliseconds = options.leaseMilliseconds ?? 3e4;
|
|
1230
|
+
if (!validLeaseMilliseconds(leaseMilliseconds)) {
|
|
1231
|
+
throw new RangeError("Webhook leaseMilliseconds must be an integer from 1 through 300000.");
|
|
1232
|
+
}
|
|
1233
|
+
return {
|
|
1234
|
+
process: (input) => processWebhook(input, options, leaseMilliseconds)
|
|
1235
|
+
};
|
|
1236
|
+
};
|
|
1237
|
+
var validLeaseMilliseconds = (value) => Number.isInteger(value) && value >= 1 && value <= MAX_LEASE_MILLISECONDS;
|
|
1238
|
+
var toWebhookResponse = (processResult) => {
|
|
1239
|
+
const headers = new Headers();
|
|
1240
|
+
if (processResult.retryAfterSeconds !== void 0) headers.set("Retry-After", String(processResult.retryAfterSeconds));
|
|
1241
|
+
return new Response(null, { status: processResult.status, headers });
|
|
1242
|
+
};
|