calmlens 0.20.0 → 0.22.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/README.md +15 -10
- package/bin/calmlens.js +1848 -679
- package/cjs/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
- package/cjs/{BrowserUpload-CjSHjx3C.js → BrowserUpload-Bwlib4Zc.js} +1 -1
- package/cjs/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
- package/cjs/{CalmLensAppClient-NaCxOVlM.js → CalmLensAppClient-DUYMo9PZ.js} +30 -10
- package/cjs/{CalmLensOptionKeys-p2QK687A.js → CalmLensOptionKeys-YvgV995V.js} +318 -374
- package/cjs/{CalmLensServerClient-BDzTthxE.js → CalmLensServerClient-3N-gdsxC.js} +346 -89
- package/cjs/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
- package/cjs/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
- package/cjs/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/cjs/Core-C33pkBmf.d.ts +826 -0
- package/cjs/Core-Cm5Z1oJ9.js +1001 -0
- package/cjs/FileIcons-4qSX7DW2.d.ts +67 -0
- package/cjs/{ModerationContextLimits-2nIv7Zh3.js → ModerationContextLimits-ud1xpZRK.js} +727 -268
- package/cjs/{ReactUpload-BdTRCTGA.js → ReactUpload-DQ0BYISX.js} +1 -1
- package/cjs/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
- package/{esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → cjs/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/cjs/{TestTriggers-DbhsNPdg-DjvVuc2h.js → TestTriggers-D29T_R0M-D6Bu-Mln.js} +355 -47
- package/cjs/{UploadController-MLVs97Zt.js → UploadController-l8fZM2qT.js} +34 -14
- package/{esm/WebhookPayload-DkukERKE.d.ts → cjs/WebhookPayload-Dt6DttS0.d.ts} +120 -86
- package/cjs/app.d.ts +6 -7
- package/cjs/app.js +4 -3
- package/cjs/elements.d.ts +123 -22
- package/cjs/elements.js +553 -156
- package/cjs/file-icons.d.ts +2 -67
- package/cjs/index-Bde1wjiw.d.ts +16 -0
- package/cjs/index.d.ts +5 -6
- package/cjs/index.js +3 -2
- package/cjs/react-native.d.ts +52 -11
- package/cjs/react-native.js +231 -99
- package/cjs/react.d.ts +42 -9
- package/cjs/react.js +381 -118
- package/cjs/server.d.ts +48 -7
- package/cjs/server.js +7 -3
- package/cjs/test-inputs.d.ts +2 -2
- package/cjs/test-inputs.js +13 -9
- package/cjs/testing.d.ts +29 -15
- package/cjs/testing.js +1722 -433
- package/cjs/ui-BRA4HQ8r.js +1359 -0
- package/cjs/ui-YQuvbidU.d.ts +139 -0
- package/cjs/ui.d.ts +3 -2
- package/cjs/ui.js +45 -22
- package/cjs/vue.d.ts +802 -199
- package/cjs/vue.js +359 -127
- package/esm/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-BWjZ9ntu.d.ts} +2 -2
- package/esm/{BrowserUpload-CAVkRotw.js → BrowserUpload-GRZVB0G_.js} +1 -1
- package/esm/{CalmLensAppClient-PQ9VBvlW.js → CalmLensAppClient-B5QIJ6KS.js} +30 -10
- package/esm/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-BaW3ddUR.d.ts} +13 -3
- package/esm/{CalmLensOptionKeys-Do2mPP6w.js → CalmLensOptionKeys-BG7Qrh8-.js} +317 -367
- package/esm/CalmLensServerClient-BKzn8zmp.d.ts +353 -0
- package/esm/{CalmLensServerClient-C_H5aAsV.js → CalmLensServerClient-bRUAebi-.js} +323 -90
- package/esm/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-BDKwThbO.d.ts} +26993 -27187
- package/esm/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/esm/Core-BvQe4moS.js +846 -0
- package/esm/Core-C33pkBmf.d.ts +826 -0
- package/esm/FileIcons-4qSX7DW2.d.ts +67 -0
- package/esm/{ModerationContextLimits-Chw-AzgL.js → ModerationContextLimits-CrxSnVZ3.js} +682 -253
- package/esm/{ReactUpload-CMmL0R5Q.js → ReactUpload-BMO8saxT.js} +1 -1
- package/esm/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
- package/{cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → esm/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/esm/{TestTriggers-DbhsNPdg-CUdrv8Nm.js → TestTriggers-D29T_R0M-Ztc74ucs.js} +332 -48
- package/esm/{UploadController-BJZghJpg.js → UploadController-DnJrWiE4.js} +34 -14
- package/{cjs/WebhookPayload-DkukERKE.d.ts → esm/WebhookPayload-Dt6DttS0.d.ts} +120 -86
- package/esm/app.d.ts +6 -7
- package/esm/app.js +3 -3
- package/esm/elements.d.ts +123 -22
- package/esm/elements.js +497 -128
- package/esm/file-icons.d.ts +2 -67
- package/esm/index-Bde1wjiw.d.ts +16 -0
- package/esm/index.d.ts +5 -6
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +52 -11
- package/esm/react-native.js +205 -75
- package/esm/react.d.ts +42 -9
- package/esm/react.js +327 -91
- package/esm/server.d.ts +48 -7
- package/esm/server.js +3 -3
- package/esm/styles.css +142 -22
- package/esm/svelte/AssetViewer.svelte +25 -0
- package/esm/svelte/CalmLensAsset.svelte +318 -0
- package/esm/svelte/CalmLensDocumentViewer.svelte +7 -0
- package/esm/svelte/CalmLensImageViewer.svelte +7 -0
- package/esm/svelte/CalmLensSpreadsheetViewer.svelte +7 -0
- package/esm/svelte/CalmLensTextViewer.svelte +7 -0
- package/esm/svelte/CalmLensWebsiteViewer.svelte +7 -0
- package/esm/svelte/index.d.ts +29 -6
- package/esm/svelte/index.js +7 -2
- package/esm/test-inputs.d.ts +2 -2
- package/esm/test-inputs.js +1 -1
- package/esm/testing.d.ts +29 -15
- package/esm/testing.js +1718 -429
- package/esm/ui-YQuvbidU.d.ts +139 -0
- package/esm/ui-heryDd6g.js +1258 -0
- package/esm/ui.d.ts +3 -2
- package/esm/ui.js +4 -3
- package/esm/vue.d.ts +802 -199
- package/esm/vue.js +308 -103
- package/package.json +4 -2
- package/cjs/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
- package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/cjs/index-DxbJ_Xaa.d.ts +0 -253
- package/cjs/ui-BSqPGKrZ.d.ts +0 -539
- package/cjs/ui-CX1z2pD9.js +0 -586
- package/esm/CalmLensServerClient-C-jsjn8m.d.ts +0 -259
- package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/esm/index-DxbJ_Xaa.d.ts +0 -253
- package/esm/svelte/CalmLensMedia.svelte +0 -134
- package/esm/ui-BSqPGKrZ.d.ts +0 -539
- package/esm/ui-CXH7xJpb.js +0 -461
package/bin/calmlens.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// src/cli/index.ts
|
|
3
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
3
4
|
import { parseArgs } from "node:util";
|
|
4
5
|
// package.json
|
|
5
|
-
var version = "0.
|
|
6
|
+
var version = "0.22.0";
|
|
6
7
|
|
|
7
8
|
// src/contract/ModerationCategories-CHFRoeWV.js
|
|
8
9
|
var CLASSIFICATION_CATEGORIES = [
|
|
@@ -22,380 +23,67 @@ var stringifyJsonCanonical = (value) => JSON.stringify(value, (_key, nestedValue
|
|
|
22
23
|
return Object.fromEntries(Object.keys(nestedValue).sort().map((key) => [key, nestedValue[key]]));
|
|
23
24
|
});
|
|
24
25
|
|
|
25
|
-
// src/contract/AssetPayload.js
|
|
26
|
-
var bufferInputToBytes = (value) => {
|
|
27
|
-
if (value instanceof ArrayBuffer)
|
|
28
|
-
return new Uint8Array(value);
|
|
29
|
-
return Uint8Array.from(value);
|
|
30
|
-
};
|
|
31
|
-
var BASE64_PART_BOUNDARY_ERROR = "Invalid base64 part. For multipart uploads, split the original bytes first, then base64-encode each part. Do not split one full base64 string into substrings.";
|
|
32
|
-
var MULTIPART_PART_TOO_SMALL_ERROR = `Multipart upload parts must be at least 5MiB except the final part.`;
|
|
33
|
-
var getRawBase64 = (value) => {
|
|
34
|
-
const markerIndex = value.indexOf(";base64,");
|
|
35
|
-
if (markerIndex === -1)
|
|
36
|
-
return value;
|
|
37
|
-
return value.slice(markerIndex + 8);
|
|
38
|
-
};
|
|
39
|
-
var validateBase64PayloadString = (payload, options) => {
|
|
40
|
-
const raw = getRawBase64(payload.base64).replace(/\s/g, "");
|
|
41
|
-
if (options?.multipart && raw.length % 4 !== 0)
|
|
42
|
-
return {
|
|
43
|
-
ok: false,
|
|
44
|
-
error: BASE64_PART_BOUNDARY_ERROR
|
|
45
|
-
};
|
|
46
|
-
return { ok: true };
|
|
47
|
-
};
|
|
48
|
-
var assetToData = (payload) => {
|
|
49
|
-
if ("plainText" in payload && payload.plainText !== undefined)
|
|
50
|
-
return new TextEncoder().encode(payload.plainText);
|
|
51
|
-
if ("data" in payload && payload.data)
|
|
52
|
-
return payload.data;
|
|
53
|
-
if ("buffer" in payload) {
|
|
54
|
-
if (payload.buffer instanceof ArrayBuffer)
|
|
55
|
-
return payload.buffer;
|
|
56
|
-
return bufferInputToBytes(payload.buffer);
|
|
57
|
-
}
|
|
58
|
-
if (payload.uint8Array !== undefined)
|
|
59
|
-
return Uint8Array.from(payload.uint8Array);
|
|
60
|
-
if (payload.base64 === undefined)
|
|
61
|
-
throw new Error("Invalid asset payload");
|
|
62
|
-
const raw = getRawBase64(payload.base64);
|
|
63
|
-
if (typeof Buffer !== "undefined")
|
|
64
|
-
return Uint8Array.from(Buffer.from(raw, "base64"));
|
|
65
|
-
const binary = atob(raw);
|
|
66
|
-
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
67
|
-
};
|
|
68
|
-
var getAssetPayloadByteLength = (payload) => {
|
|
69
|
-
if ("plainText" in payload && payload.plainText !== undefined)
|
|
70
|
-
return new TextEncoder().encode(payload.plainText).byteLength;
|
|
71
|
-
if ("data" in payload && payload.data) {
|
|
72
|
-
if (payload.data instanceof Blob)
|
|
73
|
-
return payload.data.size;
|
|
74
|
-
if (payload.data instanceof Response) {
|
|
75
|
-
const contentLength = payload.data.headers.get("content-length");
|
|
76
|
-
return contentLength ? Number(contentLength) : undefined;
|
|
77
|
-
}
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if ("buffer" in payload && payload.buffer)
|
|
81
|
-
return payload.buffer.byteLength;
|
|
82
|
-
if (payload.uint8Array !== undefined) {
|
|
83
|
-
if (Array.isArray(payload.uint8Array))
|
|
84
|
-
return payload.uint8Array.length;
|
|
85
|
-
return payload.uint8Array.byteLength;
|
|
86
|
-
}
|
|
87
|
-
if (payload.base64 === undefined)
|
|
88
|
-
return;
|
|
89
|
-
const raw = getRawBase64(payload.base64).replace(/\s/g, "");
|
|
90
|
-
const padding = raw.endsWith("==") ? 2 : raw.endsWith("=") ? 1 : 0;
|
|
91
|
-
return Math.max(0, Math.floor(raw.length * 3 / 4) - padding);
|
|
92
|
-
};
|
|
93
|
-
var validateAssetPayload = (payload, options) => {
|
|
94
|
-
if ("base64" in payload && payload.base64 !== undefined) {
|
|
95
|
-
const validation = validateBase64PayloadString(payload, options);
|
|
96
|
-
if (!validation.ok)
|
|
97
|
-
return {
|
|
98
|
-
ok: false,
|
|
99
|
-
error: validation.error
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
const byteLength = getAssetPayloadByteLength(payload);
|
|
103
|
-
if (options?.multipart && !options.isFinal && byteLength !== undefined && byteLength < 5242880)
|
|
104
|
-
return {
|
|
105
|
-
ok: false,
|
|
106
|
-
error: MULTIPART_PART_TOO_SMALL_ERROR
|
|
107
|
-
};
|
|
108
|
-
return { ok: true };
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// src/contract/Media.js
|
|
112
|
-
var MAX_MEDIA_UPLOAD_BYTES = 52428800;
|
|
113
|
-
|
|
114
|
-
// src/contract/ModerationContextLimits-BIMUlk2e.js
|
|
115
|
-
var countModerationContextCharacters = (text) => {
|
|
116
|
-
let count = 0;
|
|
117
|
-
for (const _ of text)
|
|
118
|
-
count++;
|
|
119
|
-
return count;
|
|
120
|
-
};
|
|
121
|
-
var selectModerationContextItems = (items) => {
|
|
122
|
-
const selected = [];
|
|
123
|
-
let characters = 0;
|
|
124
|
-
for (let index = items.length - 1;index >= 0; index--) {
|
|
125
|
-
if (selected.length === 5)
|
|
126
|
-
break;
|
|
127
|
-
const item = items[index];
|
|
128
|
-
const length = countModerationContextCharacters(item.text);
|
|
129
|
-
if (selected.length && characters + length > 2000)
|
|
130
|
-
break;
|
|
131
|
-
selected.unshift(item);
|
|
132
|
-
characters += length;
|
|
133
|
-
}
|
|
134
|
-
return selected;
|
|
135
|
-
};
|
|
136
|
-
// src/contract/SharedConstants-DxUCZwLZ.js
|
|
137
|
-
var IMPERSONATION_COOKIE_NAME = "CL_impersonation";
|
|
138
|
-
var DAY_MS = 86400000;
|
|
139
|
-
var YEAR_MS = 365 * DAY_MS;
|
|
140
|
-
var FIRST_PARTY_COOKIES = {
|
|
141
|
-
ACCEPTED_COOKIES_VERSION: {
|
|
142
|
-
name: "CL_acceptedCookiesVersion",
|
|
143
|
-
description: "Records your cookie choice: the version of this cookie list you answered and whether you allowed functional and analytics cookies",
|
|
144
|
-
expirationDescription: "1 year",
|
|
145
|
-
expirationMs: YEAR_MS,
|
|
146
|
-
type: "essential",
|
|
147
|
-
providerName: "CalmLens"
|
|
148
|
-
},
|
|
149
|
-
EVER_LOGGED_IN: {
|
|
150
|
-
name: "CL_everLoggedIn",
|
|
151
|
-
description: "Remembers which sign-in method you last used on this device so the sign-in page can suggest it",
|
|
152
|
-
expirationDescription: "10 years",
|
|
153
|
-
type: "functional",
|
|
154
|
-
providerName: "CalmLens"
|
|
155
|
-
},
|
|
156
|
-
ID_TOKEN: {
|
|
157
|
-
name: "CL_idToken",
|
|
158
|
-
description: "Authentication token that keeps you signed in (HttpOnly)",
|
|
159
|
-
expirationDescription: "When the token expires (about 1 hour); renewed while you are signed in",
|
|
160
|
-
type: "essential",
|
|
161
|
-
providerName: "CalmLens"
|
|
162
|
-
},
|
|
163
|
-
ID_TOKEN_EXPIRES_AT: {
|
|
164
|
-
name: "CL_idTokenExpiresAt",
|
|
165
|
-
description: "When the current authentication token expires, so it can be renewed in time",
|
|
166
|
-
expirationDescription: "10 years, or until you sign out",
|
|
167
|
-
type: "essential",
|
|
168
|
-
providerName: "CalmLens"
|
|
169
|
-
},
|
|
170
|
-
REFRESH_TOKEN: {
|
|
171
|
-
name: "CL_refreshToken",
|
|
172
|
-
description: "Token used to renew your sign-in without asking for your password again (HttpOnly)",
|
|
173
|
-
expirationDescription: "10 years, or until you sign out",
|
|
174
|
-
type: "essential",
|
|
175
|
-
providerName: "CalmLens"
|
|
176
|
-
},
|
|
177
|
-
LOGGED_IN: {
|
|
178
|
-
name: "CL_loggedIn",
|
|
179
|
-
description: "Indicates that you are signed in, so pages can show the signed-in view",
|
|
180
|
-
expirationDescription: "10 years, or until you sign out",
|
|
181
|
-
type: "essential",
|
|
182
|
-
providerName: "CalmLens"
|
|
183
|
-
},
|
|
184
|
-
IMPERSONATION: {
|
|
185
|
-
name: IMPERSONATION_COOKIE_NAME,
|
|
186
|
-
description: "Staff support access only: lets an authorised CalmLens staff member view the service as a specific user for support, security, safety or legal reasons. Only honoured for staff accounts and never set for other users",
|
|
187
|
-
expirationDescription: "Session",
|
|
188
|
-
type: "essential",
|
|
189
|
-
providerName: "CalmLens"
|
|
190
|
-
},
|
|
191
|
-
MAINTENANCE_BYPASS: {
|
|
192
|
-
name: "CL_maintenanceBypass",
|
|
193
|
-
description: "Staff only: allows authorised staff to use the site while it is in maintenance mode (HttpOnly)",
|
|
194
|
-
expirationDescription: "1 hour",
|
|
195
|
-
expirationMs: 3600000,
|
|
196
|
-
type: "essential",
|
|
197
|
-
providerName: "CalmLens"
|
|
198
|
-
},
|
|
199
|
-
WAITLIST_BYPASS: {
|
|
200
|
-
name: "CL_waitlistBypass",
|
|
201
|
-
description: "Staff only: allows authorised staff to use the site while access is limited to the waitlist (HttpOnly)",
|
|
202
|
-
expirationDescription: "1 hour",
|
|
203
|
-
expirationMs: 3600000,
|
|
204
|
-
type: "essential",
|
|
205
|
-
providerName: "CalmLens"
|
|
206
|
-
},
|
|
207
|
-
SIGN_IN_CODE: {
|
|
208
|
-
name: "CL_signInCode",
|
|
209
|
-
description: "Records that you entered the sign-in code while access is limited to the waitlist, so you can sign in (HttpOnly)",
|
|
210
|
-
expirationDescription: "30 days",
|
|
211
|
-
expirationMs: 30 * DAY_MS,
|
|
212
|
-
type: "essential",
|
|
213
|
-
providerName: "CalmLens"
|
|
214
|
-
},
|
|
215
|
-
SIGN_IN_CODE_ACCEPTED: {
|
|
216
|
-
name: "CL_signInCodeAccepted",
|
|
217
|
-
description: "Indicates that you entered the sign-in code, so the sign-in page shows the sign-in options",
|
|
218
|
-
expirationDescription: "30 days",
|
|
219
|
-
expirationMs: 30 * DAY_MS,
|
|
220
|
-
type: "essential",
|
|
221
|
-
providerName: "CalmLens"
|
|
222
|
-
},
|
|
223
|
-
PRE_RENDERED_WIDTH: {
|
|
224
|
-
name: "CL_preRenderedWidth",
|
|
225
|
-
description: "Your browser's viewport width, so pages are rendered with the right layout for your screen",
|
|
226
|
-
expirationDescription: "30 days",
|
|
227
|
-
expirationMs: 30 * DAY_MS,
|
|
228
|
-
type: "essential",
|
|
229
|
-
providerName: "CalmLens"
|
|
230
|
-
},
|
|
231
|
-
SELECTED_PROJECT_ID: {
|
|
232
|
-
name: "CL_selectedProjectId",
|
|
233
|
-
description: "Remembers the project you last selected in the portal",
|
|
234
|
-
expirationDescription: "1 year",
|
|
235
|
-
expirationMs: YEAR_MS,
|
|
236
|
-
type: "functional",
|
|
237
|
-
providerName: "CalmLens"
|
|
238
|
-
},
|
|
239
|
-
SELECTED_ORGANISATION_ID: {
|
|
240
|
-
name: "CL_selectedOrganisationId",
|
|
241
|
-
description: "Remembers the organisation you last selected in the portal",
|
|
242
|
-
expirationDescription: "1 year",
|
|
243
|
-
expirationMs: YEAR_MS,
|
|
244
|
-
type: "functional",
|
|
245
|
-
providerName: "CalmLens"
|
|
246
|
-
},
|
|
247
|
-
ASSET_DASHBOARD_STATE: {
|
|
248
|
-
name: "CL_assetDashboardState",
|
|
249
|
-
description: "Remembers your asset dashboard view (view mode, filters, sorting and folder)",
|
|
250
|
-
expirationDescription: "1 year",
|
|
251
|
-
expirationMs: YEAR_MS,
|
|
252
|
-
type: "functional",
|
|
253
|
-
providerName: "CalmLens"
|
|
254
|
-
},
|
|
255
|
-
ASSET_VIEW: {
|
|
256
|
-
name: "CL_assetView",
|
|
257
|
-
description: "Remembers whether you chose the grid or table view for an asset's sub-assets (one cookie per asset, named CL_assetView_<assetId>)",
|
|
258
|
-
expirationDescription: "30 days",
|
|
259
|
-
expirationMs: 30 * DAY_MS,
|
|
260
|
-
type: "functional",
|
|
261
|
-
providerName: "CalmLens",
|
|
262
|
-
isPrefix: true
|
|
263
|
-
},
|
|
264
|
-
PORTAL_GUIDANCE_HIDDEN: {
|
|
265
|
-
name: "CL_portalGuidanceHidden",
|
|
266
|
-
description: "Remembers whether you hid next-step tips for a project",
|
|
267
|
-
expirationDescription: "1 year",
|
|
268
|
-
expirationMs: YEAR_MS,
|
|
269
|
-
type: "functional",
|
|
270
|
-
providerName: "CalmLens",
|
|
271
|
-
isPrefix: true
|
|
272
|
-
},
|
|
273
|
-
PORTAL_LAYOUT_SPLIT_PANE: {
|
|
274
|
-
name: "CL_portalLayoutSplitPane",
|
|
275
|
-
description: "Remembers the width you set for the portal sidebar",
|
|
276
|
-
expirationDescription: "1 year",
|
|
277
|
-
expirationMs: YEAR_MS,
|
|
278
|
-
type: "functional",
|
|
279
|
-
providerName: "CalmLens"
|
|
280
|
-
},
|
|
281
|
-
DOCS_UI_LIBRARY: {
|
|
282
|
-
name: "CL_docsUiLibrary",
|
|
283
|
-
description: "Remembers the UI library you selected for documentation examples",
|
|
284
|
-
expirationDescription: "1 year",
|
|
285
|
-
expirationMs: YEAR_MS,
|
|
286
|
-
type: "functional",
|
|
287
|
-
providerName: "CalmLens"
|
|
288
|
-
},
|
|
289
|
-
DOCS_LANGUAGE: {
|
|
290
|
-
name: "CL_docsLanguage",
|
|
291
|
-
description: "Remembers the programming language you selected for documentation examples",
|
|
292
|
-
expirationDescription: "1 year",
|
|
293
|
-
expirationMs: YEAR_MS,
|
|
294
|
-
type: "functional",
|
|
295
|
-
providerName: "CalmLens"
|
|
296
|
-
},
|
|
297
|
-
SEARCH_SDK_LANGUAGE: {
|
|
298
|
-
name: "CL_searchSdkLanguage",
|
|
299
|
-
description: "Remembers the SDK you chose to filter documentation search results by",
|
|
300
|
-
expirationDescription: "1 year",
|
|
301
|
-
expirationMs: YEAR_MS,
|
|
302
|
-
type: "functional",
|
|
303
|
-
providerName: "CalmLens"
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
var THIRD_PARTY_COOKIES = {
|
|
307
|
-
GOOGLE_ANALYTICS: {
|
|
308
|
-
name: "_ga",
|
|
309
|
-
description: "Google Analytics distinguishes visitors and maintains session state, only with analytics consent",
|
|
310
|
-
expirationDescription: "2 years",
|
|
311
|
-
type: "analytics",
|
|
312
|
-
providerName: "Google Analytics",
|
|
313
|
-
isPrefix: true
|
|
314
|
-
},
|
|
315
|
-
GOOGLE_AD_CLICK: {
|
|
316
|
-
name: "_gcl",
|
|
317
|
-
description: "Links consented ad clicks to signups; no personalised advertising",
|
|
318
|
-
expirationDescription: "Up to 90 days",
|
|
319
|
-
type: "marketing",
|
|
320
|
-
providerName: "Google",
|
|
321
|
-
isPrefix: true
|
|
322
|
-
},
|
|
323
|
-
GOOGLE_CAMPAIGN: {
|
|
324
|
-
name: "_gac",
|
|
325
|
-
description: "Stores consented campaign attribution",
|
|
326
|
-
expirationDescription: "Up to 90 days",
|
|
327
|
-
type: "marketing",
|
|
328
|
-
providerName: "Google",
|
|
329
|
-
isPrefix: true
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
[...Object.values(FIRST_PARTY_COOKIES), ...Object.values(THIRD_PARTY_COOKIES)];
|
|
333
|
-
var MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
334
|
-
var MAX_DIRECT_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
335
|
-
var MAX_NON_IMAGE_UPLOAD_MB = 5000;
|
|
336
|
-
var MAX_NON_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => MAX_NON_IMAGE_UPLOAD_MB * 1024 * 1024)();
|
|
337
|
-
var normalizeUploadMimeType = (mimeType) => mimeType.toLowerCase().split(";")[0]?.trim() || mimeType.toLowerCase().trim();
|
|
338
|
-
var getRejectedUploadMimeTypeError = (mimeType) => `${normalizeUploadMimeType(mimeType)} is not a valid upload file type. Uploads must use a concrete file MIME type that CalmLens can store and process, such as image/png, image/jpeg, application/pdf, or text/plain.`;
|
|
339
|
-
var DOMAIN = "calmlens.com";
|
|
340
26
|
// src/client/CalmLensErrorCodes.ts
|
|
341
27
|
var API_ERROR_CODES = {
|
|
342
|
-
INVALID_VIEWER_CLAIMS: "viewer/invalid
|
|
28
|
+
INVALID_VIEWER_CLAIMS: "viewer-claims/invalid",
|
|
343
29
|
AGE_CONFIRMATION_REQUIRED: "viewer/age-confirmation-required",
|
|
344
|
-
INVALID_VIEWER_REGION: "viewer/invalid
|
|
30
|
+
INVALID_VIEWER_REGION: "viewer-region/invalid",
|
|
345
31
|
VIEWER_REGION_REQUIRED: "viewer/region-required",
|
|
346
32
|
REGIONAL_EVIDENCE_REQUIRED: "asset/regional-evidence-required",
|
|
347
33
|
SIGNED_URL_EXPIRED: "signed-url/expired",
|
|
348
34
|
SIGNED_URL_INVALID: "signed-url/invalid",
|
|
35
|
+
SIGNED_URL_ORIGINAL_NOT_GRANTED: "signed-url/original-not-granted",
|
|
36
|
+
INVALID_REQUEST: "validation/invalid-request",
|
|
349
37
|
INVALID_TYPE: "validation/invalid-type",
|
|
350
38
|
TOO_SMALL: "validation/too-small",
|
|
351
39
|
TOO_BIG: "validation/too-big",
|
|
352
40
|
INVALID_FORMAT: "validation/invalid-format",
|
|
353
41
|
INVALID_VALUE: "validation/invalid-value",
|
|
354
42
|
UNKNOWN_FIELD: "validation/unknown-field",
|
|
355
|
-
UNSUPPORTED_CONTENT_TYPE: "
|
|
356
|
-
INVALID_FILTER: "
|
|
357
|
-
|
|
358
|
-
ROUTE_NOT_FOUND: "
|
|
359
|
-
INTERNAL_ERROR: "
|
|
43
|
+
UNSUPPORTED_CONTENT_TYPE: "request/unsupported-content-type",
|
|
44
|
+
INVALID_FILTER: "filter/invalid",
|
|
45
|
+
UNSUPPORTED_ORDERING_FIELD: "ordering/unsupported-field",
|
|
46
|
+
ROUTE_NOT_FOUND: "request/route-not-found",
|
|
47
|
+
INTERNAL_ERROR: "server/internal-error",
|
|
360
48
|
UNAUTHENTICATED: "auth/unauthenticated",
|
|
361
|
-
TOKEN_EXPIRED: "
|
|
362
|
-
INVALID_TOKEN: "
|
|
49
|
+
TOKEN_EXPIRED: "session-token/expired",
|
|
50
|
+
INVALID_TOKEN: "session-token/invalid",
|
|
363
51
|
SEARCH_UNAVAILABLE: "search/unavailable",
|
|
364
|
-
INVALID_TRANSFORM: "
|
|
365
|
-
INVALID_TRANSFORM_OPTIONS: "
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
API_KEY_PROJECT_MISMATCH: "auth/project-mismatch",
|
|
373
|
-
API_KEY_NOT_ACCEPTED: "auth/api-key-not-accepted",
|
|
52
|
+
INVALID_TRANSFORM: "transform/invalid",
|
|
53
|
+
INVALID_TRANSFORM_OPTIONS: "transform-options/invalid",
|
|
54
|
+
REMOTE_URL_TOO_MANY_REDIRECTS: "remote-url/too-many-redirects",
|
|
55
|
+
INVALID_CURSOR: "cursor/invalid",
|
|
56
|
+
MISSING_API_KEY: "api-key/missing",
|
|
57
|
+
INVALID_API_KEY: "api-key/invalid",
|
|
58
|
+
API_KEY_PROJECT_MISMATCH: "api-key/project-mismatch",
|
|
59
|
+
API_KEY_NOT_ACCEPTED: "api-key/not-accepted",
|
|
374
60
|
PERMISSION_DENIED: "auth/permission-denied",
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
61
|
+
UPLOAD_TOO_LARGE: "upload/too-large",
|
|
62
|
+
DOCUMENT_TOO_MANY_ITEMS: "document/too-many-items",
|
|
63
|
+
MEDIA_DURATION_LIMIT: "media/duration-limit",
|
|
64
|
+
INVALID_IMAGE: "image/invalid",
|
|
65
|
+
IMAGE_TOO_LARGE: "image/too-large",
|
|
66
|
+
FREE_UPLOADS_EXHAUSTED: "usage/free-uploads-exhausted",
|
|
67
|
+
UPLOADS_PAUSED: "usage/uploads-paused",
|
|
68
|
+
UNSUPPORTED_UPLOAD_TYPE: "upload/unsupported-type",
|
|
69
|
+
INVALID_UPLOAD_PAYLOAD: "upload-payload/invalid",
|
|
70
|
+
UPLOAD_OPTIONS_IN_QUERY: "upload/options-in-query",
|
|
385
71
|
USE_UPLOAD_PART: "upload/use-upload-part",
|
|
386
72
|
UPLOAD_NOT_OPEN: "upload/not-open",
|
|
387
|
-
INVALID_UPLOAD_PART_NUMBER: "upload/invalid-
|
|
73
|
+
INVALID_UPLOAD_PART_NUMBER: "upload-part/invalid-number",
|
|
388
74
|
UPLOAD_MISSING: "upload/missing",
|
|
389
75
|
UPLOAD_SIZE_MISMATCH: "upload/size-mismatch",
|
|
390
76
|
INVALID_IDEMPOTENCY_KEY: "idempotency/invalid-key",
|
|
391
77
|
IDEMPOTENCY_KEY_REUSED: "idempotency/key-reused",
|
|
392
78
|
IDEMPOTENT_REQUEST_IN_PROGRESS: "idempotency/request-in-progress",
|
|
79
|
+
NO_RENDERED_VERSION: "asset/no-rendered-version",
|
|
393
80
|
ASSET_NOT_FOUND: "asset/not-found",
|
|
394
81
|
PROJECT_NOT_FOUND: "project/not-found",
|
|
82
|
+
ASSET_CHILD_NOT_DELETABLE: "asset/child-not-deletable",
|
|
395
83
|
ASSET_REVIEW_CHANGED: "asset/review-changed",
|
|
396
84
|
ASSET_REVIEW_NOTE_REQUIRED: "asset/review-note-required",
|
|
397
85
|
ASSET_UPDATE_FAILED: "asset/update-failed",
|
|
398
|
-
|
|
86
|
+
ASSET_HELD: "asset/held",
|
|
399
87
|
ASSET_PROCESSING: "asset/processing",
|
|
400
88
|
ASSET_DECISION_NOT_ALLOWED: "asset/decision-not-allowed",
|
|
401
89
|
ASSET_DECISION_UNCHANGED: "asset/decision-unchanged",
|
|
@@ -405,18 +93,19 @@ var API_ERROR_CODES = {
|
|
|
405
93
|
ASSET_NOT_DECIDED: "asset/not-decided",
|
|
406
94
|
ASSET_POLICY_CHANGED: "asset/policy-changed",
|
|
407
95
|
ASSET_REVIEWED: "asset/reviewed",
|
|
408
|
-
SUPPORT_TICKET_NOT_FOUND: "support/
|
|
96
|
+
SUPPORT_TICKET_NOT_FOUND: "support-ticket/not-found",
|
|
409
97
|
DUPLICATE_EXTERNAL_ID: "asset/duplicate-external-id",
|
|
410
98
|
FOLDER_NOT_FOUND: "folder/not-found",
|
|
411
99
|
DUPLICATE_FOLDER_NAME: "folder/duplicate-name",
|
|
412
100
|
FOLDER_NOT_EMPTY: "folder/not-empty",
|
|
413
101
|
FOLDER_PARENT_CYCLE: "folder/parent-cycle",
|
|
414
|
-
|
|
102
|
+
LENS_NOT_FOUND: "lens/not-found",
|
|
103
|
+
LENS_IDENTIFIER_TAKEN: "lens/identifier-taken",
|
|
415
104
|
LENS_IDENTIFIER_RESERVED: "lens/identifier-reserved",
|
|
416
105
|
HASH_LIST_NOT_FOUND: "hash-list/not-found",
|
|
417
|
-
HASH_LIST_ENTRY_NOT_FOUND: "hash-list/
|
|
106
|
+
HASH_LIST_ENTRY_NOT_FOUND: "hash-list-entry/not-found",
|
|
418
107
|
HASH_LIST_LIMIT_REACHED: "hash-list/limit-reached",
|
|
419
|
-
HASH_LIST_ENTRY_LIMIT_REACHED: "hash-list/
|
|
108
|
+
HASH_LIST_ENTRY_LIMIT_REACHED: "hash-list-entry/limit-reached",
|
|
420
109
|
HASH_LIST_ASSET_NOT_HASHED: "hash-list/asset-not-hashed",
|
|
421
110
|
POLICY_NOT_FOUND: "policy/not-found",
|
|
422
111
|
POLICY_REVISION_CONFLICT: "policy/revision-conflict",
|
|
@@ -430,18 +119,24 @@ var API_ERROR_CODES = {
|
|
|
430
119
|
UPLOAD_PRESET_NOT_FOUND: "upload-preset/not-found",
|
|
431
120
|
UPLOAD_PRESET_DISABLED: "upload-preset/disabled",
|
|
432
121
|
UPLOAD_PRESET_TOKEN_REQUIRED: "upload-preset/token-required",
|
|
433
|
-
REMOTE_URL_NOT_ALLOWED: "
|
|
434
|
-
|
|
435
|
-
UPLOAD_PRESET_CONTENT_TYPE_NOT_ALLOWED: "upload-preset/content-type-not-allowed",
|
|
436
|
-
UPLOAD_PRESET_TOO_LARGE: "upload-preset/too-large",
|
|
122
|
+
REMOTE_URL_NOT_ALLOWED: "remote-url/not-allowed",
|
|
123
|
+
WEBSITE_RATE_LIMIT_REACHED: "upload/website-rate-limit-reached",
|
|
437
124
|
UPLOAD_PRESET_DAILY_LIMIT_REACHED: "upload-preset/daily-limit-reached",
|
|
438
125
|
UPLOAD_PRESET_ORIGIN_NOT_ALLOWED: "upload-preset/origin-not-allowed",
|
|
439
126
|
UPLOAD_PRESET_FIELD_NOT_ALLOWED: "upload-preset/field-not-allowed",
|
|
127
|
+
UPLOAD_PRESET_REVISION_CONFLICT: "upload-preset/revision-conflict",
|
|
128
|
+
UPLOAD_PRESET_KEY_TAKEN: "upload-preset/key-taken",
|
|
129
|
+
UPLOAD_PRESET_DAILY_LIMIT_REQUIRED: "upload-preset/daily-limit-required",
|
|
130
|
+
UPLOAD_PRESET_INVALID_FOLDER: "upload-preset/invalid-folder",
|
|
131
|
+
UPLOAD_PRESET_INVALID_POLICY: "upload-preset/invalid-policy",
|
|
132
|
+
PROJECT_SETTINGS_REVISION_CONFLICT: "project-settings/revision-conflict",
|
|
133
|
+
SEARCH_ESTIMATE_CHANGED: "search/estimate-changed",
|
|
134
|
+
METADATA_FIELD_NOT_FOUND: "metadata-field/not-found",
|
|
440
135
|
UPLOAD_TOKEN_INVALID: "upload-token/invalid",
|
|
441
136
|
UPLOAD_TOKEN_EXPIRED: "upload-token/expired",
|
|
442
137
|
UPLOAD_TOKEN_USED: "upload-token/used",
|
|
443
|
-
INVALID_REMOTE_URL: "
|
|
444
|
-
REMOTE_URL_UNAVAILABLE: "
|
|
138
|
+
INVALID_REMOTE_URL: "remote-url/invalid",
|
|
139
|
+
REMOTE_URL_UNAVAILABLE: "remote-url/unavailable",
|
|
445
140
|
APPEAL_NOT_FOUND: "appeal/not-found",
|
|
446
141
|
APPEAL_JUDGMENT_NOT_FOUND: "appeal/judgment-not-found",
|
|
447
142
|
APPEAL_ASSET_NOT_FOUND: "appeal/asset-not-found",
|
|
@@ -449,7 +144,6 @@ var API_ERROR_CODES = {
|
|
|
449
144
|
APPEAL_ALREADY_REVIEWED: "appeal/already-reviewed",
|
|
450
145
|
APPEAL_DECISION_CHANGED: "appeal/decision-changed",
|
|
451
146
|
APPEAL_INVALID_ACTION: "appeal/invalid-action",
|
|
452
|
-
APPEAL_SAFETY_HELD: "appeal/safety-held",
|
|
453
147
|
APPEAL_CONTENT_UNAVAILABLE: "appeal/content-unavailable"
|
|
454
148
|
};
|
|
455
149
|
|
|
@@ -469,7 +163,7 @@ var SDK_ERROR_CODES = {
|
|
|
469
163
|
};
|
|
470
164
|
var CALMLENS_ERROR_CODES = { ...API_ERROR_CODES, ...SDK_ERROR_CODES };
|
|
471
165
|
var BRAND = Symbol.for("calmlens.sdk.CalmLensError");
|
|
472
|
-
var RETRYABLE_STATUSES = new Set([429, 502, 503, 504]);
|
|
166
|
+
var RETRYABLE_STATUSES = new Set([429, 500, 502, 503, 504]);
|
|
473
167
|
var RETRYABLE_CODES = new Set([
|
|
474
168
|
SDK_ERROR_CODES.TRANSPORT_ERROR,
|
|
475
169
|
SDK_ERROR_CODES.TIMEOUT,
|
|
@@ -502,6 +196,9 @@ class CalmLensError extends Error {
|
|
|
502
196
|
static [Symbol.hasInstance](value) {
|
|
503
197
|
return CalmLensError.isCalmLensError(value);
|
|
504
198
|
}
|
|
199
|
+
isLocal() {
|
|
200
|
+
return this.status === undefined;
|
|
201
|
+
}
|
|
505
202
|
isNotFound() {
|
|
506
203
|
return this.status === 404;
|
|
507
204
|
}
|
|
@@ -536,7 +233,7 @@ var isReactNativeRuntime = () => globalThis.navigator?.product === "ReactNative"
|
|
|
536
233
|
var RETRY_BASE_DELAY_MS = 500;
|
|
537
234
|
var RETRY_MAX_DELAY_MS = 8000;
|
|
538
235
|
var RETRY_AFTER_MAX_MS = 60000;
|
|
539
|
-
var RETRYABLE_STATUSES2 = new Set([429, 502, 503, 504]);
|
|
236
|
+
var RETRYABLE_STATUSES2 = new Set([429, 500, 502, 503, 504]);
|
|
540
237
|
var timeoutReason = () => {
|
|
541
238
|
const reason = new Error("The operation timed out.");
|
|
542
239
|
reason.name = "TimeoutError";
|
|
@@ -786,30 +483,234 @@ class CalmLensTransport {
|
|
|
786
483
|
throw error;
|
|
787
484
|
}
|
|
788
485
|
}
|
|
789
|
-
async json(request) {
|
|
790
|
-
const { response, attempt } = await this.send(request);
|
|
791
|
-
try {
|
|
792
|
-
const bytes = await readBody(response, this.settings.maxResponseBytes);
|
|
793
|
-
if (bytes.byteLength === 0 && (response.status === 204 || request.method === "DELETE")) {
|
|
794
|
-
return;
|
|
795
|
-
}
|
|
796
|
-
try {
|
|
797
|
-
return JSON.parse(new TextDecoder().decode(bytes));
|
|
798
|
-
} catch (cause) {
|
|
799
|
-
throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
800
|
-
message: `Invalid JSON response (HTTP ${response.status})`,
|
|
801
|
-
...responseInfo(response),
|
|
802
|
-
cause
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
} catch (cause) {
|
|
806
|
-
throw toFailure(cause, attempt);
|
|
807
|
-
} finally {
|
|
808
|
-
attempt.release();
|
|
809
|
-
}
|
|
486
|
+
async json(request) {
|
|
487
|
+
const { response, attempt } = await this.send(request);
|
|
488
|
+
try {
|
|
489
|
+
const bytes = await readBody(response, this.settings.maxResponseBytes);
|
|
490
|
+
if (bytes.byteLength === 0 && (response.status === 204 || request.method === "DELETE")) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
try {
|
|
494
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
495
|
+
} catch (cause) {
|
|
496
|
+
throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
497
|
+
message: `Invalid JSON response (HTTP ${response.status})`,
|
|
498
|
+
...responseInfo(response),
|
|
499
|
+
cause
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
} catch (cause) {
|
|
503
|
+
throw toFailure(cause, attempt);
|
|
504
|
+
} finally {
|
|
505
|
+
attempt.release();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/contract/SharedConstants-DxUCZwLZ.js
|
|
511
|
+
var IMPERSONATION_COOKIE_NAME = "CL_impersonation";
|
|
512
|
+
var DAY_MS = 86400000;
|
|
513
|
+
var YEAR_MS = 365 * DAY_MS;
|
|
514
|
+
var FIRST_PARTY_COOKIES = {
|
|
515
|
+
ACCEPTED_COOKIES_VERSION: {
|
|
516
|
+
name: "CL_acceptedCookiesVersion",
|
|
517
|
+
description: "Records your cookie choice: the version of this cookie list you answered and whether you allowed functional and analytics cookies",
|
|
518
|
+
expirationDescription: "1 year",
|
|
519
|
+
expirationMs: YEAR_MS,
|
|
520
|
+
type: "essential",
|
|
521
|
+
providerName: "CalmLens"
|
|
522
|
+
},
|
|
523
|
+
EVER_LOGGED_IN: {
|
|
524
|
+
name: "CL_everLoggedIn",
|
|
525
|
+
description: "Remembers which sign-in method you last used on this device so the sign-in page can suggest it",
|
|
526
|
+
expirationDescription: "10 years",
|
|
527
|
+
type: "functional",
|
|
528
|
+
providerName: "CalmLens"
|
|
529
|
+
},
|
|
530
|
+
ID_TOKEN: {
|
|
531
|
+
name: "CL_idToken",
|
|
532
|
+
description: "Authentication token that keeps you signed in (HttpOnly)",
|
|
533
|
+
expirationDescription: "When the token expires (about 1 hour); renewed while you are signed in",
|
|
534
|
+
type: "essential",
|
|
535
|
+
providerName: "CalmLens"
|
|
536
|
+
},
|
|
537
|
+
ID_TOKEN_EXPIRES_AT: {
|
|
538
|
+
name: "CL_idTokenExpiresAt",
|
|
539
|
+
description: "When the current authentication token expires, so it can be renewed in time",
|
|
540
|
+
expirationDescription: "10 years, or until you sign out",
|
|
541
|
+
type: "essential",
|
|
542
|
+
providerName: "CalmLens"
|
|
543
|
+
},
|
|
544
|
+
REFRESH_TOKEN: {
|
|
545
|
+
name: "CL_refreshToken",
|
|
546
|
+
description: "Token used to renew your sign-in without asking for your password again (HttpOnly)",
|
|
547
|
+
expirationDescription: "10 years, or until you sign out",
|
|
548
|
+
type: "essential",
|
|
549
|
+
providerName: "CalmLens"
|
|
550
|
+
},
|
|
551
|
+
LOGGED_IN: {
|
|
552
|
+
name: "CL_loggedIn",
|
|
553
|
+
description: "Indicates that you are signed in, so pages can show the signed-in view",
|
|
554
|
+
expirationDescription: "10 years, or until you sign out",
|
|
555
|
+
type: "essential",
|
|
556
|
+
providerName: "CalmLens"
|
|
557
|
+
},
|
|
558
|
+
IMPERSONATION: {
|
|
559
|
+
name: IMPERSONATION_COOKIE_NAME,
|
|
560
|
+
description: "Staff support access only: lets an authorised CalmLens staff member view the service as a specific user for support, security, safety or legal reasons. Only honoured for staff accounts and never set for other users",
|
|
561
|
+
expirationDescription: "Session",
|
|
562
|
+
type: "essential",
|
|
563
|
+
providerName: "CalmLens"
|
|
564
|
+
},
|
|
565
|
+
MAINTENANCE_BYPASS: {
|
|
566
|
+
name: "CL_maintenanceBypass",
|
|
567
|
+
description: "Staff only: allows authorised staff to use the site while it is in maintenance mode (HttpOnly)",
|
|
568
|
+
expirationDescription: "1 hour",
|
|
569
|
+
expirationMs: 3600000,
|
|
570
|
+
type: "essential",
|
|
571
|
+
providerName: "CalmLens"
|
|
572
|
+
},
|
|
573
|
+
WAITLIST_BYPASS: {
|
|
574
|
+
name: "CL_waitlistBypass",
|
|
575
|
+
description: "Staff only: allows authorised staff to use the site while access is limited to the waitlist (HttpOnly)",
|
|
576
|
+
expirationDescription: "1 hour",
|
|
577
|
+
expirationMs: 3600000,
|
|
578
|
+
type: "essential",
|
|
579
|
+
providerName: "CalmLens"
|
|
580
|
+
},
|
|
581
|
+
SIGN_IN_CODE: {
|
|
582
|
+
name: "CL_signInCode",
|
|
583
|
+
description: "Records that you entered the sign-in code while access is limited to the waitlist, so you can sign in (HttpOnly)",
|
|
584
|
+
expirationDescription: "30 days",
|
|
585
|
+
expirationMs: 30 * DAY_MS,
|
|
586
|
+
type: "essential",
|
|
587
|
+
providerName: "CalmLens"
|
|
588
|
+
},
|
|
589
|
+
SIGN_IN_CODE_ACCEPTED: {
|
|
590
|
+
name: "CL_signInCodeAccepted",
|
|
591
|
+
description: "Indicates that you entered the sign-in code, so the sign-in page shows the sign-in options",
|
|
592
|
+
expirationDescription: "30 days",
|
|
593
|
+
expirationMs: 30 * DAY_MS,
|
|
594
|
+
type: "essential",
|
|
595
|
+
providerName: "CalmLens"
|
|
596
|
+
},
|
|
597
|
+
PRE_RENDERED_WIDTH: {
|
|
598
|
+
name: "CL_preRenderedWidth",
|
|
599
|
+
description: "Your browser's viewport width, so pages are rendered with the right layout for your screen",
|
|
600
|
+
expirationDescription: "30 days",
|
|
601
|
+
expirationMs: 30 * DAY_MS,
|
|
602
|
+
type: "essential",
|
|
603
|
+
providerName: "CalmLens"
|
|
604
|
+
},
|
|
605
|
+
SELECTED_PROJECT_ID: {
|
|
606
|
+
name: "CL_selectedProjectId",
|
|
607
|
+
description: "Remembers the project you last selected in the portal",
|
|
608
|
+
expirationDescription: "1 year",
|
|
609
|
+
expirationMs: YEAR_MS,
|
|
610
|
+
type: "functional",
|
|
611
|
+
providerName: "CalmLens"
|
|
612
|
+
},
|
|
613
|
+
SELECTED_ORGANISATION_ID: {
|
|
614
|
+
name: "CL_selectedOrganisationId",
|
|
615
|
+
description: "Remembers the organisation you last selected in the portal",
|
|
616
|
+
expirationDescription: "1 year",
|
|
617
|
+
expirationMs: YEAR_MS,
|
|
618
|
+
type: "functional",
|
|
619
|
+
providerName: "CalmLens"
|
|
620
|
+
},
|
|
621
|
+
ASSET_DASHBOARD_STATE: {
|
|
622
|
+
name: "CL_assetDashboardState",
|
|
623
|
+
description: "Remembers your asset dashboard view (view mode, filters, sorting and folder)",
|
|
624
|
+
expirationDescription: "1 year",
|
|
625
|
+
expirationMs: YEAR_MS,
|
|
626
|
+
type: "functional",
|
|
627
|
+
providerName: "CalmLens"
|
|
628
|
+
},
|
|
629
|
+
ASSET_VIEW: {
|
|
630
|
+
name: "CL_assetView",
|
|
631
|
+
description: "Remembers whether you chose the grid or table view for an asset's sub-assets (one cookie per asset, named CL_assetView_<assetId>)",
|
|
632
|
+
expirationDescription: "30 days",
|
|
633
|
+
expirationMs: 30 * DAY_MS,
|
|
634
|
+
type: "functional",
|
|
635
|
+
providerName: "CalmLens",
|
|
636
|
+
isPrefix: true
|
|
637
|
+
},
|
|
638
|
+
PORTAL_GUIDANCE_HIDDEN: {
|
|
639
|
+
name: "CL_portalGuidanceHidden",
|
|
640
|
+
description: "Remembers whether you hid next-step tips for a project",
|
|
641
|
+
expirationDescription: "1 year",
|
|
642
|
+
expirationMs: YEAR_MS,
|
|
643
|
+
type: "functional",
|
|
644
|
+
providerName: "CalmLens",
|
|
645
|
+
isPrefix: true
|
|
646
|
+
},
|
|
647
|
+
PORTAL_LAYOUT_SPLIT_PANE: {
|
|
648
|
+
name: "CL_portalLayoutSplitPane",
|
|
649
|
+
description: "Remembers the width you set for the portal sidebar",
|
|
650
|
+
expirationDescription: "1 year",
|
|
651
|
+
expirationMs: YEAR_MS,
|
|
652
|
+
type: "functional",
|
|
653
|
+
providerName: "CalmLens"
|
|
654
|
+
},
|
|
655
|
+
DOCS_UI_LIBRARY: {
|
|
656
|
+
name: "CL_docsUiLibrary",
|
|
657
|
+
description: "Remembers the UI library you selected for documentation examples",
|
|
658
|
+
expirationDescription: "1 year",
|
|
659
|
+
expirationMs: YEAR_MS,
|
|
660
|
+
type: "functional",
|
|
661
|
+
providerName: "CalmLens"
|
|
662
|
+
},
|
|
663
|
+
DOCS_LANGUAGE: {
|
|
664
|
+
name: "CL_docsLanguage",
|
|
665
|
+
description: "Remembers the programming language you selected for documentation examples",
|
|
666
|
+
expirationDescription: "1 year",
|
|
667
|
+
expirationMs: YEAR_MS,
|
|
668
|
+
type: "functional",
|
|
669
|
+
providerName: "CalmLens"
|
|
670
|
+
},
|
|
671
|
+
SEARCH_SDK_LANGUAGE: {
|
|
672
|
+
name: "CL_searchSdkLanguage",
|
|
673
|
+
description: "Remembers the SDK you chose to filter documentation search results by",
|
|
674
|
+
expirationDescription: "1 year",
|
|
675
|
+
expirationMs: YEAR_MS,
|
|
676
|
+
type: "functional",
|
|
677
|
+
providerName: "CalmLens"
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
var THIRD_PARTY_COOKIES = {
|
|
681
|
+
GOOGLE_ANALYTICS: {
|
|
682
|
+
name: "_ga",
|
|
683
|
+
description: "Google Analytics distinguishes visitors and maintains session state, only with analytics consent",
|
|
684
|
+
expirationDescription: "2 years",
|
|
685
|
+
type: "analytics",
|
|
686
|
+
providerName: "Google Analytics",
|
|
687
|
+
isPrefix: true
|
|
688
|
+
},
|
|
689
|
+
GOOGLE_AD_CLICK: {
|
|
690
|
+
name: "_gcl",
|
|
691
|
+
description: "Links consented ad clicks to signups; no personalised advertising",
|
|
692
|
+
expirationDescription: "Up to 90 days",
|
|
693
|
+
type: "marketing",
|
|
694
|
+
providerName: "Google",
|
|
695
|
+
isPrefix: true
|
|
696
|
+
},
|
|
697
|
+
GOOGLE_CAMPAIGN: {
|
|
698
|
+
name: "_gac",
|
|
699
|
+
description: "Stores consented campaign attribution",
|
|
700
|
+
expirationDescription: "Up to 90 days",
|
|
701
|
+
type: "marketing",
|
|
702
|
+
providerName: "Google",
|
|
703
|
+
isPrefix: true
|
|
810
704
|
}
|
|
811
|
-
}
|
|
812
|
-
|
|
705
|
+
};
|
|
706
|
+
[...Object.values(FIRST_PARTY_COOKIES), ...Object.values(THIRD_PARTY_COOKIES)];
|
|
707
|
+
var MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
708
|
+
var MAX_DIRECT_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
709
|
+
var MAX_NON_IMAGE_UPLOAD_MB = 5000;
|
|
710
|
+
var MAX_NON_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => MAX_NON_IMAGE_UPLOAD_MB * 1024 * 1024)();
|
|
711
|
+
var normalizeUploadMimeType = (mimeType) => mimeType.toLowerCase().split(";")[0]?.trim() || mimeType.toLowerCase().trim();
|
|
712
|
+
var getRejectedUploadMimeTypeError = (mimeType) => `${normalizeUploadMimeType(mimeType)} is not a valid upload file type. Uploads must use a concrete file MIME type that CalmLens can store and process, such as image/png, image/jpeg, application/pdf, or text/plain.`;
|
|
713
|
+
var DOMAIN = "calmlens.com";
|
|
813
714
|
// src/client/CalmLensTransformSchema.ts
|
|
814
715
|
var TRANSFORM_OPTIONS_SCHEMA = {
|
|
815
716
|
type: "object",
|
|
@@ -1008,6 +909,14 @@ var UPLOAD_MIME_TYPES = [
|
|
|
1008
909
|
"application/msword",
|
|
1009
910
|
"application/rtf",
|
|
1010
911
|
"application/vnd.oasis.opendocument.text",
|
|
912
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
913
|
+
"application/vnd.ms-excel.sheet.macroenabled.12",
|
|
914
|
+
"application/vnd.ms-excel",
|
|
915
|
+
"application/vnd.oasis.opendocument.spreadsheet",
|
|
916
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
917
|
+
"application/vnd.ms-powerpoint.presentation.macroenabled.12",
|
|
918
|
+
"application/vnd.ms-powerpoint",
|
|
919
|
+
"application/vnd.oasis.opendocument.presentation",
|
|
1011
920
|
"application/javascript",
|
|
1012
921
|
"application/json",
|
|
1013
922
|
"application/x-javascript",
|
|
@@ -1016,25 +925,6 @@ var UPLOAD_MIME_TYPES = [
|
|
|
1016
925
|
"application/yaml"
|
|
1017
926
|
];
|
|
1018
927
|
|
|
1019
|
-
// src/client/CalmLensViewerClaims.ts
|
|
1020
|
-
var VIEWER_COUNTRIES = new Set("AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW".split(" "));
|
|
1021
|
-
var EU_COUNTRIES = new Set("AT BE BG HR CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE".split(" "));
|
|
1022
|
-
var parseViewerClaims = (value) => {
|
|
1023
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
1024
|
-
return;
|
|
1025
|
-
const { region, ageConfirmed, ...rest } = value;
|
|
1026
|
-
if (Object.keys(rest).length)
|
|
1027
|
-
return;
|
|
1028
|
-
if (region !== undefined && (typeof region !== "string" || !VIEWER_COUNTRIES.has(region)))
|
|
1029
|
-
return;
|
|
1030
|
-
if (ageConfirmed !== undefined && typeof ageConfirmed !== "boolean")
|
|
1031
|
-
return;
|
|
1032
|
-
return {
|
|
1033
|
-
...region !== undefined && { region },
|
|
1034
|
-
...ageConfirmed !== undefined && { ageConfirmed }
|
|
1035
|
-
};
|
|
1036
|
-
};
|
|
1037
|
-
|
|
1038
928
|
// src/client/CalmLensUtils.ts
|
|
1039
929
|
var assertHttpUrl = (name, value) => {
|
|
1040
930
|
if (value === undefined)
|
|
@@ -1096,11 +986,20 @@ var validateRequestOptions = (options) => {
|
|
|
1096
986
|
assertInteger("uploadTimeoutMs", options.uploadTimeoutMs, 1);
|
|
1097
987
|
assertInteger("maxRetries", options.maxRetries, 0);
|
|
1098
988
|
};
|
|
989
|
+
var CDN_LOCATION_KEYS = [
|
|
990
|
+
"assetId",
|
|
991
|
+
"externalId",
|
|
992
|
+
"lens",
|
|
993
|
+
"projectId",
|
|
994
|
+
"resource",
|
|
995
|
+
"transform",
|
|
996
|
+
"viewerClaims"
|
|
997
|
+
];
|
|
1099
998
|
var LOCAL_OPTION_KEYS = {
|
|
1100
999
|
"assets.waitForDecision": ["assetId", "signal", "timeoutMs"],
|
|
1101
|
-
"cdn.getAssetUrl":
|
|
1102
|
-
"cdn.serve": [
|
|
1103
|
-
"uploadTokens.sign": ["
|
|
1000
|
+
"cdn.getAssetUrl": CDN_LOCATION_KEYS,
|
|
1001
|
+
"cdn.serve": [...CDN_LOCATION_KEYS, "init"],
|
|
1002
|
+
"uploadTokens.sign": ["expiresIn", "externalId", "uploadPresetId"]
|
|
1104
1003
|
};
|
|
1105
1004
|
var IDEMPOTENT_OPERATIONS = [
|
|
1106
1005
|
"assets.create",
|
|
@@ -1265,13 +1164,6 @@ var transformSelector = (transform) => {
|
|
|
1265
1164
|
return transform;
|
|
1266
1165
|
};
|
|
1267
1166
|
var DEFAULT_CDN_BASE_URL = `https://cdn.${DOMAIN}/v1`;
|
|
1268
|
-
var CDN_RESOURCES = new Set([
|
|
1269
|
-
"original",
|
|
1270
|
-
"rendered",
|
|
1271
|
-
"placeholder"
|
|
1272
|
-
]);
|
|
1273
|
-
var DEFAULT_SIGNED_URL_EXPIRES_IN_SECONDS = 60 * 15;
|
|
1274
|
-
var MAX_SIGNED_URL_SECONDS = 60 * 60 * 24;
|
|
1275
1167
|
var ASSET_BATCH_MAX_ASSETS = 500;
|
|
1276
1168
|
var ASSET_BATCH_OPERATIONS = ["delete", "remove-content"];
|
|
1277
1169
|
var validateBatchAssetsOptions = ({ assetIds, operation }) => {
|
|
@@ -1285,79 +1177,13 @@ var validateBatchAssetsOptions = ({ assetIds, operation }) => {
|
|
|
1285
1177
|
throw invalidArgument(`operation must be one of ${ASSET_BATCH_OPERATIONS.join(", ")}`);
|
|
1286
1178
|
}
|
|
1287
1179
|
};
|
|
1288
|
-
var
|
|
1289
|
-
const { resource = "rendered", lens, transform, expiresInSeconds } = options;
|
|
1290
|
-
if (resource !== "original" && resource !== "rendered") {
|
|
1291
|
-
throw invalidArgument("A signed URL's resource must be original or rendered");
|
|
1292
|
-
}
|
|
1293
|
-
if (resource === "original" && (lens !== undefined || transform !== undefined)) {
|
|
1294
|
-
throw invalidArgument("Lenses and transforms apply only to the rendered resource");
|
|
1295
|
-
}
|
|
1296
|
-
if (expiresInSeconds !== undefined && (!Number.isInteger(expiresInSeconds) || expiresInSeconds < 1 || expiresInSeconds > MAX_SIGNED_URL_SECONDS)) {
|
|
1297
|
-
throw invalidArgument("expiresInSeconds must be a whole number from 1 to 86400");
|
|
1298
|
-
}
|
|
1299
|
-
};
|
|
1300
|
-
var getAssetUrl = ({
|
|
1301
|
-
projectId,
|
|
1302
|
-
assetIdentifier,
|
|
1303
|
-
cdnBaseUrl = DEFAULT_CDN_BASE_URL,
|
|
1304
|
-
resource = "rendered",
|
|
1305
|
-
...options
|
|
1306
|
-
}) => {
|
|
1307
|
-
if (!CDN_RESOURCES.has(resource)) {
|
|
1308
|
-
throw invalidArgument("resource must be original, rendered or placeholder");
|
|
1309
|
-
}
|
|
1310
|
-
if (resource === "original" && (options.lens !== undefined || options.transform !== undefined)) {
|
|
1311
|
-
throw invalidArgument("Lenses and transforms apply only to the rendered resource");
|
|
1312
|
-
}
|
|
1313
|
-
if (resource === "placeholder" && (options.lens !== undefined || options.transform !== undefined)) {
|
|
1314
|
-
throw invalidArgument("A placeholder takes no lens or transform");
|
|
1315
|
-
}
|
|
1316
|
-
const url = `${cdnBaseUrl.replace(/\/+$/, "")}/assets/${encodePathSegment(projectId, "Project ID")}/${encodePathSegment(assetIdentifier, "Asset identifier")}/${resource}`;
|
|
1317
|
-
return appendCdnSelector(url, options);
|
|
1318
|
-
};
|
|
1319
|
-
var appendCdnSelector = (url, options) => {
|
|
1320
|
-
const path = appendCdnPathSelector(url, options);
|
|
1321
|
-
const query = new URLSearchParams;
|
|
1322
|
-
if (options.viewerClaims !== undefined) {
|
|
1323
|
-
const claims = parseViewerClaims(options.viewerClaims);
|
|
1324
|
-
if (!claims)
|
|
1325
|
-
throw invalidArgument("Invalid viewerClaims");
|
|
1326
|
-
query.set("viewerClaims", JSON.stringify(claims));
|
|
1327
|
-
}
|
|
1328
|
-
return query.size ? `${path}?${query}` : path;
|
|
1329
|
-
};
|
|
1330
|
-
var appendCdnPathSelector = (url, options) => {
|
|
1331
|
-
const transform = transformSelector(options.transform);
|
|
1332
|
-
const selector = [
|
|
1333
|
-
...options.lens ? [`@${encodePathSegment(options.lens, "Lens")}`] : [],
|
|
1334
|
-
...transform ? [typeof options.transform === "string" ? encodeURI(transform) : transform] : []
|
|
1335
|
-
].join(",");
|
|
1336
|
-
return selector ? `${url}/${selector}` : url;
|
|
1337
|
-
};
|
|
1338
|
-
var appendQueryValue = (parts, key, value) => {
|
|
1180
|
+
var stringifyQuery = (query) => Object.entries(query).flatMap(([key, value]) => {
|
|
1339
1181
|
if (value === undefined || value === null)
|
|
1340
|
-
return;
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
}
|
|
1346
|
-
if (typeof value === "object") {
|
|
1347
|
-
for (const [field, item] of Object.entries(value)) {
|
|
1348
|
-
appendQueryValue(parts, `${key}[${field}]`, item);
|
|
1349
|
-
}
|
|
1350
|
-
return;
|
|
1351
|
-
}
|
|
1352
|
-
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
1353
|
-
};
|
|
1354
|
-
var stringifyQuery = (query) => {
|
|
1355
|
-
const parts = [];
|
|
1356
|
-
for (const [key, value] of Object.entries(query))
|
|
1357
|
-
appendQueryValue(parts, key, value);
|
|
1358
|
-
return parts.join("&");
|
|
1359
|
-
};
|
|
1360
|
-
var isAssetDecided = (asset) => asset.classification.moderation.status !== "pending" || asset.classification.status === "failed";
|
|
1182
|
+
return [];
|
|
1183
|
+
const text = Array.isArray(value) ? value.every((item) => typeof item === "string" || typeof item === "number") ? value.join(",") : JSON.stringify(value) : typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
1184
|
+
return [`${encodeURIComponent(key)}=${encodeURIComponent(text)}`];
|
|
1185
|
+
}).join("&");
|
|
1186
|
+
var isAssetDecided = (asset) => asset.classification.status === "completed" || asset.classification.status === "failed";
|
|
1361
1187
|
var DECISION_POLL_FIRST_DELAY_MS = 500;
|
|
1362
1188
|
var DECISION_POLL_DELAY_FACTOR = 1.5;
|
|
1363
1189
|
var DECISION_POLL_MAX_DELAY_MS = 2000;
|
|
@@ -1394,6 +1220,280 @@ var pollForDecision = async (retrieve, {
|
|
|
1394
1220
|
}
|
|
1395
1221
|
};
|
|
1396
1222
|
|
|
1223
|
+
// src/client/CalmLensViewerClaims.ts
|
|
1224
|
+
var VIEWER_COUNTRIES = new Set("AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW".split(" "));
|
|
1225
|
+
var EU_COUNTRIES = new Set("AT BE BG HR CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE".split(" "));
|
|
1226
|
+
var parseViewerClaims = (value) => {
|
|
1227
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
1228
|
+
return;
|
|
1229
|
+
const { region, ageConfirmed, ...rest } = value;
|
|
1230
|
+
if (Object.keys(rest).length)
|
|
1231
|
+
return;
|
|
1232
|
+
if (region !== undefined && (typeof region !== "string" || !VIEWER_COUNTRIES.has(region)))
|
|
1233
|
+
return;
|
|
1234
|
+
if (ageConfirmed !== undefined && typeof ageConfirmed !== "boolean")
|
|
1235
|
+
return;
|
|
1236
|
+
return {
|
|
1237
|
+
...region !== undefined && { region },
|
|
1238
|
+
...ageConfirmed !== undefined && { ageConfirmed }
|
|
1239
|
+
};
|
|
1240
|
+
};
|
|
1241
|
+
|
|
1242
|
+
// src/client/CalmLensCdn.ts
|
|
1243
|
+
var ASSET_RESOURCE_PATHS = {
|
|
1244
|
+
original: "original",
|
|
1245
|
+
rendered: "rendered",
|
|
1246
|
+
preview: "preview",
|
|
1247
|
+
placeholder: "placeholder",
|
|
1248
|
+
hls: "hls/index.m3u8",
|
|
1249
|
+
embed: "embed",
|
|
1250
|
+
info: "info"
|
|
1251
|
+
};
|
|
1252
|
+
var EXTERNAL_ID_SEGMENT_PREFIX = "ext:";
|
|
1253
|
+
var CDN_RESOURCES = Object.keys(ASSET_RESOURCE_PATHS);
|
|
1254
|
+
var UNSELECTABLE = new Set([
|
|
1255
|
+
"original",
|
|
1256
|
+
"hls",
|
|
1257
|
+
"embed",
|
|
1258
|
+
"placeholder",
|
|
1259
|
+
"info"
|
|
1260
|
+
]);
|
|
1261
|
+
var DEFAULT_SIGNED_URL_EXPIRES_IN = 60 * 15;
|
|
1262
|
+
var MAX_SIGNED_URL_EXPIRES_IN = 60 * 60 * 24;
|
|
1263
|
+
var getAssetSegment = (options) => {
|
|
1264
|
+
const { assetId, externalId } = options;
|
|
1265
|
+
if (assetId === undefined === (externalId === undefined)) {
|
|
1266
|
+
throw invalidArgument("Pass either assetId or externalId");
|
|
1267
|
+
}
|
|
1268
|
+
if (assetId !== undefined)
|
|
1269
|
+
return encodePathSegment(assetId, "Asset ID");
|
|
1270
|
+
if (typeof externalId !== "string" || !externalId) {
|
|
1271
|
+
throw invalidArgument("External ID is required");
|
|
1272
|
+
}
|
|
1273
|
+
return `${EXTERNAL_ID_SEGMENT_PREFIX}${encodeURIComponent(externalId)}`;
|
|
1274
|
+
};
|
|
1275
|
+
var toUrlViewerClaims = (claims) => {
|
|
1276
|
+
if (claims === undefined)
|
|
1277
|
+
return;
|
|
1278
|
+
const parsed = parseViewerClaims(claims);
|
|
1279
|
+
if (!parsed)
|
|
1280
|
+
throw invalidArgument("Invalid viewerClaims");
|
|
1281
|
+
const { region, ageConfirmed } = parsed;
|
|
1282
|
+
if (!region && ageConfirmed !== true)
|
|
1283
|
+
return;
|
|
1284
|
+
return { ...region ? { region } : {}, ...ageConfirmed === true ? { ageConfirmed } : {} };
|
|
1285
|
+
};
|
|
1286
|
+
var viewerClaimsQuery = (claims) => {
|
|
1287
|
+
const sent = toUrlViewerClaims(claims);
|
|
1288
|
+
return sent ? `?${new URLSearchParams({ viewerClaims: JSON.stringify(sent) })}` : "";
|
|
1289
|
+
};
|
|
1290
|
+
var appendAssetLocation = (assetUrl, location) => {
|
|
1291
|
+
const { resource, lens, transform, viewerClaims } = location;
|
|
1292
|
+
const selected = lens !== undefined || transform !== undefined;
|
|
1293
|
+
let path = assetUrl;
|
|
1294
|
+
if (resource === undefined) {
|
|
1295
|
+
if (selected)
|
|
1296
|
+
throw invalidArgument("A lens or transform needs a resource, such as rendered");
|
|
1297
|
+
} else {
|
|
1298
|
+
if (typeof resource !== "string" || !Object.hasOwn(ASSET_RESOURCE_PATHS, resource)) {
|
|
1299
|
+
throw invalidArgument(`resource must be one of ${CDN_RESOURCES.join(", ")}`);
|
|
1300
|
+
}
|
|
1301
|
+
if (UNSELECTABLE.has(resource) && selected) {
|
|
1302
|
+
throw invalidArgument(`The ${resource} resource takes no lens or transform`);
|
|
1303
|
+
}
|
|
1304
|
+
path = `${assetUrl}/${ASSET_RESOURCE_PATHS[resource]}`;
|
|
1305
|
+
const selector = transformSelector(transform);
|
|
1306
|
+
const parts = [
|
|
1307
|
+
...lens !== undefined ? [`@${encodePathSegment(lens, "Lens")}`] : [],
|
|
1308
|
+
...selector ? [typeof transform === "string" ? encodeURI(selector) : selector] : []
|
|
1309
|
+
];
|
|
1310
|
+
if (parts.length)
|
|
1311
|
+
path = `${path}/${parts.join(",")}`;
|
|
1312
|
+
}
|
|
1313
|
+
return `${path}${viewerClaimsQuery(viewerClaims)}`;
|
|
1314
|
+
};
|
|
1315
|
+
var buildAssetUrl = (cdnBaseUrl, projectId, options) => {
|
|
1316
|
+
const { assetId, externalId, resource, lens, transform, viewerClaims } = options;
|
|
1317
|
+
const base = `${cdnBaseUrl.replace(/\/+$/, "")}/assets/${encodePathSegment(projectId, "Project ID")}/${getAssetSegment({ assetId, externalId })}`;
|
|
1318
|
+
return appendAssetLocation(base, { resource, lens, transform, viewerClaims });
|
|
1319
|
+
};
|
|
1320
|
+
var validateSignAssetUrlOptions = (options) => {
|
|
1321
|
+
const { expiresIn, original } = options;
|
|
1322
|
+
if (expiresIn !== undefined && (!Number.isInteger(expiresIn) || expiresIn < 1 || expiresIn > MAX_SIGNED_URL_EXPIRES_IN)) {
|
|
1323
|
+
throw invalidArgument(`expiresIn must be a whole number from 1 to ${MAX_SIGNED_URL_EXPIRES_IN}`);
|
|
1324
|
+
}
|
|
1325
|
+
if (original !== undefined && typeof original !== "boolean") {
|
|
1326
|
+
throw invalidArgument("original must be a boolean");
|
|
1327
|
+
}
|
|
1328
|
+
getAssetSegment(options);
|
|
1329
|
+
appendAssetLocation("", options);
|
|
1330
|
+
};
|
|
1331
|
+
var splitAssetUrl = (url) => {
|
|
1332
|
+
const [path = "", query] = url.split("?", 2);
|
|
1333
|
+
const base = path.replace(/\/+$/, "");
|
|
1334
|
+
const raw = query ? new URLSearchParams(query).get("viewerClaims") : null;
|
|
1335
|
+
if (raw === null)
|
|
1336
|
+
return { base };
|
|
1337
|
+
try {
|
|
1338
|
+
return { base, claims: JSON.parse(raw) };
|
|
1339
|
+
} catch {
|
|
1340
|
+
throw invalidArgument("The asset URL's viewerClaims are not JSON");
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
var isAssetInfo = (value) => {
|
|
1344
|
+
if (!value || typeof value !== "object")
|
|
1345
|
+
return false;
|
|
1346
|
+
const info = value;
|
|
1347
|
+
return typeof info.id === "string" && typeof info.projectId === "string" && typeof info.type === "string" && !!info.content && typeof info.content === "object" && (info.availability === "available" || info.availability === "age-restricted" || info.availability === "unavailable");
|
|
1348
|
+
};
|
|
1349
|
+
var getAssetInfo = async (url, options = {}) => {
|
|
1350
|
+
if (typeof url !== "string" || !URL.canParse(url)) {
|
|
1351
|
+
throw invalidArgument("url must be an absolute asset URL");
|
|
1352
|
+
}
|
|
1353
|
+
const { base, claims } = splitAssetUrl(url);
|
|
1354
|
+
const infoUrl = `${base}/info${viewerClaimsQuery(options.viewerClaims ?? claims)}`;
|
|
1355
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
1356
|
+
let response;
|
|
1357
|
+
try {
|
|
1358
|
+
response = await fetcher(infoUrl, {
|
|
1359
|
+
headers: { Accept: "application/json" },
|
|
1360
|
+
signal: options.signal
|
|
1361
|
+
});
|
|
1362
|
+
} catch (cause) {
|
|
1363
|
+
if (options.signal?.aborted)
|
|
1364
|
+
throw cause;
|
|
1365
|
+
throw new CalmLensError(SDK_ERROR_CODES.TRANSPORT_ERROR, {
|
|
1366
|
+
message: "The asset's info could not be fetched",
|
|
1367
|
+
cause
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
1371
|
+
if (!response.ok)
|
|
1372
|
+
throw toHttpError(response, bytes);
|
|
1373
|
+
let data;
|
|
1374
|
+
try {
|
|
1375
|
+
data = JSON.parse(new TextDecoder().decode(bytes));
|
|
1376
|
+
} catch {}
|
|
1377
|
+
if (!isAssetInfo(data)) {
|
|
1378
|
+
throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
1379
|
+
message: "The CDN returned no asset info",
|
|
1380
|
+
status: response.status
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
return data;
|
|
1384
|
+
};
|
|
1385
|
+
|
|
1386
|
+
// src/contract/AssetPayload.js
|
|
1387
|
+
var bufferInputToBytes = (value) => {
|
|
1388
|
+
if (value instanceof ArrayBuffer)
|
|
1389
|
+
return new Uint8Array(value);
|
|
1390
|
+
return Uint8Array.from(value);
|
|
1391
|
+
};
|
|
1392
|
+
var BASE64_PART_BOUNDARY_ERROR = "Invalid base64 part. For multipart uploads, split the original bytes first, then base64-encode each part. Do not split one full base64 string into substrings.";
|
|
1393
|
+
var MULTIPART_PART_TOO_SMALL_ERROR = `Multipart upload parts must be at least 5MiB except the final part.`;
|
|
1394
|
+
var getRawBase64 = (value) => {
|
|
1395
|
+
const markerIndex = value.indexOf(";base64,");
|
|
1396
|
+
if (markerIndex === -1)
|
|
1397
|
+
return value;
|
|
1398
|
+
return value.slice(markerIndex + 8);
|
|
1399
|
+
};
|
|
1400
|
+
var validateBase64PayloadString = (payload, options) => {
|
|
1401
|
+
const raw = getRawBase64(payload.base64).replace(/\s/g, "");
|
|
1402
|
+
if (options?.multipart && raw.length % 4 !== 0)
|
|
1403
|
+
return {
|
|
1404
|
+
ok: false,
|
|
1405
|
+
error: BASE64_PART_BOUNDARY_ERROR
|
|
1406
|
+
};
|
|
1407
|
+
return { ok: true };
|
|
1408
|
+
};
|
|
1409
|
+
var assetToData = (payload) => {
|
|
1410
|
+
if ("plainText" in payload && payload.plainText !== undefined)
|
|
1411
|
+
return new TextEncoder().encode(payload.plainText);
|
|
1412
|
+
if ("data" in payload && payload.data)
|
|
1413
|
+
return payload.data;
|
|
1414
|
+
if ("buffer" in payload) {
|
|
1415
|
+
if (payload.buffer instanceof ArrayBuffer)
|
|
1416
|
+
return payload.buffer;
|
|
1417
|
+
return bufferInputToBytes(payload.buffer);
|
|
1418
|
+
}
|
|
1419
|
+
if (payload.uint8Array !== undefined)
|
|
1420
|
+
return Uint8Array.from(payload.uint8Array);
|
|
1421
|
+
if (payload.base64 === undefined)
|
|
1422
|
+
throw new Error("Invalid asset payload");
|
|
1423
|
+
const raw = getRawBase64(payload.base64);
|
|
1424
|
+
if (typeof Buffer !== "undefined")
|
|
1425
|
+
return Uint8Array.from(Buffer.from(raw, "base64"));
|
|
1426
|
+
const binary = atob(raw);
|
|
1427
|
+
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
1428
|
+
};
|
|
1429
|
+
var getAssetPayloadByteLength = (payload) => {
|
|
1430
|
+
if ("plainText" in payload && payload.plainText !== undefined)
|
|
1431
|
+
return new TextEncoder().encode(payload.plainText).byteLength;
|
|
1432
|
+
if ("data" in payload && payload.data) {
|
|
1433
|
+
if (payload.data instanceof Blob)
|
|
1434
|
+
return payload.data.size;
|
|
1435
|
+
if (payload.data instanceof Response) {
|
|
1436
|
+
const contentLength = payload.data.headers.get("content-length");
|
|
1437
|
+
return contentLength ? Number(contentLength) : undefined;
|
|
1438
|
+
}
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
if ("buffer" in payload && payload.buffer)
|
|
1442
|
+
return payload.buffer.byteLength;
|
|
1443
|
+
if (payload.uint8Array !== undefined) {
|
|
1444
|
+
if (Array.isArray(payload.uint8Array))
|
|
1445
|
+
return payload.uint8Array.length;
|
|
1446
|
+
return payload.uint8Array.byteLength;
|
|
1447
|
+
}
|
|
1448
|
+
if (payload.base64 === undefined)
|
|
1449
|
+
return;
|
|
1450
|
+
const raw = getRawBase64(payload.base64).replace(/\s/g, "");
|
|
1451
|
+
const padding = raw.endsWith("==") ? 2 : raw.endsWith("=") ? 1 : 0;
|
|
1452
|
+
return Math.max(0, Math.floor(raw.length * 3 / 4) - padding);
|
|
1453
|
+
};
|
|
1454
|
+
var validateAssetPayload = (payload, options) => {
|
|
1455
|
+
if ("base64" in payload && payload.base64 !== undefined) {
|
|
1456
|
+
const validation = validateBase64PayloadString(payload, options);
|
|
1457
|
+
if (!validation.ok)
|
|
1458
|
+
return {
|
|
1459
|
+
ok: false,
|
|
1460
|
+
error: validation.error
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
const byteLength = getAssetPayloadByteLength(payload);
|
|
1464
|
+
if (options?.multipart && !options.isFinal && byteLength !== undefined && byteLength < 5242880)
|
|
1465
|
+
return {
|
|
1466
|
+
ok: false,
|
|
1467
|
+
error: MULTIPART_PART_TOO_SMALL_ERROR
|
|
1468
|
+
};
|
|
1469
|
+
return { ok: true };
|
|
1470
|
+
};
|
|
1471
|
+
|
|
1472
|
+
// src/contract/Media-B2PMcUf7.js
|
|
1473
|
+
var MAX_MEDIA_UPLOAD_BYTES = 52428800;
|
|
1474
|
+
var MAX_LONG_MEDIA_UPLOAD_BYTES = 2147483648;
|
|
1475
|
+
// src/contract/ModerationContextLimits-BIMUlk2e.js
|
|
1476
|
+
var countModerationContextCharacters = (text) => {
|
|
1477
|
+
let count = 0;
|
|
1478
|
+
for (const _ of text)
|
|
1479
|
+
count++;
|
|
1480
|
+
return count;
|
|
1481
|
+
};
|
|
1482
|
+
var selectModerationContextItems = (items) => {
|
|
1483
|
+
const selected = [];
|
|
1484
|
+
let characters = 0;
|
|
1485
|
+
for (let index = items.length - 1;index >= 0; index--) {
|
|
1486
|
+
if (selected.length === 5)
|
|
1487
|
+
break;
|
|
1488
|
+
const item = items[index];
|
|
1489
|
+
const length = countModerationContextCharacters(item.text);
|
|
1490
|
+
if (selected.length && characters + length > 2000)
|
|
1491
|
+
break;
|
|
1492
|
+
selected.unshift(item);
|
|
1493
|
+
characters += length;
|
|
1494
|
+
}
|
|
1495
|
+
return selected;
|
|
1496
|
+
};
|
|
1397
1497
|
// src/client/CalmLensConnection.ts
|
|
1398
1498
|
var DEFAULT_TIMEOUT_MS = 120000;
|
|
1399
1499
|
var MOCK_HOOKS = Symbol.for("@calmlens/sdk.mockHooks");
|
|
@@ -1433,7 +1533,7 @@ var splitsIntoParts = (content, partSizeBytes) => {
|
|
|
1433
1533
|
};
|
|
1434
1534
|
var DEFAULT_MAX_RESPONSE_BYTES = 32 * 1024 * 1024;
|
|
1435
1535
|
var toBodyBytes = (value) => value.buffer instanceof ArrayBuffer ? value : Uint8Array.from(value);
|
|
1436
|
-
var
|
|
1536
|
+
var toUploadData = (payload) => {
|
|
1437
1537
|
const data = assetToData(payload);
|
|
1438
1538
|
if (data instanceof Response) {
|
|
1439
1539
|
if (!data.body) {
|
|
@@ -1443,24 +1543,93 @@ var toRawUploadBody = (payload) => {
|
|
|
1443
1543
|
}
|
|
1444
1544
|
return data.body;
|
|
1445
1545
|
}
|
|
1446
|
-
if (data instanceof
|
|
1546
|
+
if (data instanceof Blob)
|
|
1447
1547
|
return data;
|
|
1448
|
-
|
|
1449
|
-
|
|
1548
|
+
if (data instanceof ArrayBuffer)
|
|
1549
|
+
return new Uint8Array(data);
|
|
1550
|
+
if ("getReader" in data)
|
|
1450
1551
|
return data;
|
|
1451
|
-
}
|
|
1452
1552
|
return toBodyBytes(data);
|
|
1453
1553
|
};
|
|
1554
|
+
var toRawUploadBody = (payload) => toUploadData(payload);
|
|
1555
|
+
var textEncoder = new TextEncoder;
|
|
1556
|
+
var toUploadForm = (options, payload) => {
|
|
1557
|
+
const boundary = `calmlens-${randomUuid()}`;
|
|
1558
|
+
const head = `--${boundary}\r
|
|
1559
|
+
Content-Disposition: form-data; name="options"\r
|
|
1560
|
+
Content-Type: application/json\r
|
|
1561
|
+
\r
|
|
1562
|
+
${JSON.stringify(options)}\r
|
|
1563
|
+
--${boundary}\r
|
|
1564
|
+
Content-Disposition: form-data; name="file"\r
|
|
1565
|
+
Content-Type: ${payload.type.replace(/[\r\n]/g, "")}\r
|
|
1566
|
+
\r
|
|
1567
|
+
`;
|
|
1568
|
+
const tail = `\r
|
|
1569
|
+
--${boundary}--\r
|
|
1570
|
+
`;
|
|
1571
|
+
const contentType = `multipart/form-data; boundary=${boundary}`;
|
|
1572
|
+
const data = toUploadData(payload);
|
|
1573
|
+
if (data instanceof Blob)
|
|
1574
|
+
return { body: new Blob([head, data, tail]), contentType };
|
|
1575
|
+
const headBytes = textEncoder.encode(head);
|
|
1576
|
+
const tailBytes = textEncoder.encode(tail);
|
|
1577
|
+
if (data instanceof Uint8Array) {
|
|
1578
|
+
const body = new Uint8Array(headBytes.length + data.length + tailBytes.length);
|
|
1579
|
+
body.set(headBytes);
|
|
1580
|
+
body.set(data, headBytes.length);
|
|
1581
|
+
body.set(tailBytes, headBytes.length + data.length);
|
|
1582
|
+
return { body, contentType };
|
|
1583
|
+
}
|
|
1584
|
+
const reader = data.getReader();
|
|
1585
|
+
let stage = "head";
|
|
1586
|
+
const body = new ReadableStream({
|
|
1587
|
+
async pull(controller) {
|
|
1588
|
+
if (stage === "head") {
|
|
1589
|
+
stage = "file";
|
|
1590
|
+
controller.enqueue(headBytes);
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1593
|
+
if (stage === "done")
|
|
1594
|
+
return;
|
|
1595
|
+
const { done, value } = await reader.read();
|
|
1596
|
+
if (!done) {
|
|
1597
|
+
if (value.byteLength)
|
|
1598
|
+
controller.enqueue(value);
|
|
1599
|
+
return;
|
|
1600
|
+
}
|
|
1601
|
+
stage = "done";
|
|
1602
|
+
controller.enqueue(tailBytes);
|
|
1603
|
+
controller.close();
|
|
1604
|
+
},
|
|
1605
|
+
cancel: (reason) => reader.cancel(reason)
|
|
1606
|
+
});
|
|
1607
|
+
return { body, contentType };
|
|
1608
|
+
};
|
|
1609
|
+
var uploadFields = (options) => Object.fromEntries(UPLOAD_OPTION_KEYS.flatMap((key) => options[key] === undefined || options[key] === null ? [] : [[key, options[key]]]));
|
|
1610
|
+
var UPLOAD_OPTION_KEYS = [
|
|
1611
|
+
"name",
|
|
1612
|
+
"description",
|
|
1613
|
+
"processingOptions",
|
|
1614
|
+
"visibility",
|
|
1615
|
+
"metadata",
|
|
1616
|
+
"tags",
|
|
1617
|
+
"authorId",
|
|
1618
|
+
"context",
|
|
1619
|
+
"externalId",
|
|
1620
|
+
"externalUrl",
|
|
1621
|
+
"folderId",
|
|
1622
|
+
"uploadPresetId"
|
|
1623
|
+
];
|
|
1454
1624
|
var setOptionalQueryValue = (params, key, value) => {
|
|
1455
|
-
if (value !== undefined && value !== null)
|
|
1456
|
-
params.set(key,
|
|
1457
|
-
}
|
|
1625
|
+
if (value !== undefined && value !== null)
|
|
1626
|
+
params.set(key, String(value));
|
|
1458
1627
|
};
|
|
1459
1628
|
var assertValidUploadMimeType = (mimeType) => {
|
|
1460
1629
|
if (!isAcceptedUploadMimeType(mimeType)) {
|
|
1461
|
-
throw new CalmLensError(API_ERROR_CODES.
|
|
1630
|
+
throw new CalmLensError(API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, {
|
|
1462
1631
|
message: getRejectedUploadMimeTypeError(mimeType),
|
|
1463
|
-
details: { mimeType }
|
|
1632
|
+
details: { mimeType, source: "calmlens" }
|
|
1464
1633
|
});
|
|
1465
1634
|
}
|
|
1466
1635
|
};
|
|
@@ -1475,17 +1644,23 @@ var assertDeclaredPayloadSize = (payload, declared = payload.sizeInBytes) => {
|
|
|
1475
1644
|
throw invalidPayload("sizeInBytes must match the payload byte length");
|
|
1476
1645
|
}
|
|
1477
1646
|
};
|
|
1478
|
-
var
|
|
1479
|
-
const size = content.sizeInBytes ?? getAssetPayloadByteLength(content);
|
|
1647
|
+
var assertUploadSize = (type, size, inParts) => {
|
|
1480
1648
|
if (size === undefined)
|
|
1481
1649
|
return;
|
|
1482
|
-
const
|
|
1483
|
-
const [limit, message] =
|
|
1650
|
+
const mime = type.toLowerCase();
|
|
1651
|
+
const [limit, message] = mime.startsWith("image/") ? [
|
|
1484
1652
|
MAX_DIRECT_IMAGE_UPLOAD_BYTES,
|
|
1485
1653
|
"Images uploaded in one request can be at most 10 MiB; upload larger images in parts"
|
|
1486
|
-
] :
|
|
1487
|
-
|
|
1488
|
-
|
|
1654
|
+
] : mime.startsWith("audio/") || mime.startsWith("video/") ? [
|
|
1655
|
+
inParts ? MAX_LONG_MEDIA_UPLOAD_BYTES : MAX_MEDIA_UPLOAD_BYTES,
|
|
1656
|
+
"Audio and video files can be at most 50 MiB in one request, or 2 GiB in parts"
|
|
1657
|
+
] : [MAX_NON_IMAGE_UPLOAD_BYTES, "Files can be at most 5,000 MiB"];
|
|
1658
|
+
if (size > limit) {
|
|
1659
|
+
throw new CalmLensError(API_ERROR_CODES.UPLOAD_TOO_LARGE, {
|
|
1660
|
+
message,
|
|
1661
|
+
details: { limitBytes: limit, source: "plan" }
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1489
1664
|
};
|
|
1490
1665
|
var prepareSubmitAssetOptions = (options, {
|
|
1491
1666
|
deferUploadChecks = false,
|
|
@@ -1517,12 +1692,14 @@ var prepareSubmitAssetOptions = (options, {
|
|
|
1517
1692
|
}
|
|
1518
1693
|
if (!deferUploadChecks && inParts && isImageMimeType(options.content.type)) {
|
|
1519
1694
|
if ((getAssetPayloadByteLength(options.content) ?? 0) > MAX_IMAGE_UPLOAD_BYTES) {
|
|
1520
|
-
throw new CalmLensError(API_ERROR_CODES.
|
|
1521
|
-
message: "Multipart image uploads cannot exceed
|
|
1695
|
+
throw new CalmLensError(API_ERROR_CODES.UPLOAD_TOO_LARGE, {
|
|
1696
|
+
message: "Multipart image uploads cannot exceed 20 MiB.",
|
|
1697
|
+
details: { limitBytes: MAX_IMAGE_UPLOAD_BYTES, source: "plan" }
|
|
1522
1698
|
});
|
|
1523
1699
|
}
|
|
1524
|
-
} else if (!deferUploadChecks)
|
|
1525
|
-
|
|
1700
|
+
} else if (!deferUploadChecks) {
|
|
1701
|
+
assertUploadSize(options.content.type, options.content.sizeInBytes ?? getAssetPayloadByteLength(options.content), inParts);
|
|
1702
|
+
}
|
|
1526
1703
|
if (!("plainText" in options.content)) {
|
|
1527
1704
|
const validation = validateAssetPayload(options.content);
|
|
1528
1705
|
if (!validation.ok)
|
|
@@ -1535,11 +1712,15 @@ var prepareSubmitAssetOptions = (options, {
|
|
|
1535
1712
|
const partSizeInBytes = options.part.sizeInBytes ?? getAssetPayloadByteLength(options.part);
|
|
1536
1713
|
if (!deferUploadChecks && isImageMimeType(options.part.type) && partSizeInBytes !== undefined) {
|
|
1537
1714
|
if (partSizeInBytes > MAX_IMAGE_UPLOAD_BYTES) {
|
|
1538
|
-
throw new CalmLensError(API_ERROR_CODES.
|
|
1539
|
-
message: "Multipart image uploads cannot exceed
|
|
1715
|
+
throw new CalmLensError(API_ERROR_CODES.UPLOAD_TOO_LARGE, {
|
|
1716
|
+
message: "Multipart image uploads cannot exceed 20 MiB.",
|
|
1717
|
+
details: { limitBytes: MAX_IMAGE_UPLOAD_BYTES, source: "plan" }
|
|
1540
1718
|
});
|
|
1541
1719
|
}
|
|
1542
1720
|
}
|
|
1721
|
+
if (!deferUploadChecks && !isImageMimeType(options.part.type)) {
|
|
1722
|
+
assertUploadSize(options.part.type, options.totalSizeInBytes, true);
|
|
1723
|
+
}
|
|
1543
1724
|
const validation = validateAssetPayload(options.part, {
|
|
1544
1725
|
multipart: true,
|
|
1545
1726
|
isFinal: deferUploadChecks || options.part.isFinal
|
|
@@ -1559,7 +1740,7 @@ var newIdempotencyKey = () => randomUuid();
|
|
|
1559
1740
|
var isTextPayload = (payload) => ("plainText" in payload);
|
|
1560
1741
|
var hasStringStatus = (value) => !!value && typeof value === "object" && typeof value.status === "string";
|
|
1561
1742
|
var isAsset = (data) => !!data && typeof data === "object" && typeof data.id === "string" && !!data.id && hasStringStatus(data.classification) && hasStringStatus(data.upload) && typeof data.classification?.moderation?.status === "string";
|
|
1562
|
-
var isUploadedAsset = (data) => !!data && typeof data === "object" && typeof data.id === "string" && !!data.id;
|
|
1743
|
+
var isUploadedAsset = (data) => !!data && typeof data === "object" && typeof data.id === "string" && !!data.id && hasStringStatus(data.classification) && hasStringStatus(data.upload);
|
|
1563
1744
|
var expectUploadedAsset = (data) => {
|
|
1564
1745
|
if (!isUploadedAsset(data)) {
|
|
1565
1746
|
throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
@@ -1637,54 +1818,56 @@ class CalmLensConnection {
|
|
|
1637
1818
|
deadline: "body"
|
|
1638
1819
|
});
|
|
1639
1820
|
}
|
|
1640
|
-
upload(url,
|
|
1821
|
+
upload(url, body, headers, idempotencyKey, text) {
|
|
1641
1822
|
return this.transport.json({
|
|
1642
1823
|
method: "POST",
|
|
1643
1824
|
url,
|
|
1644
1825
|
headers,
|
|
1645
|
-
body
|
|
1826
|
+
body,
|
|
1646
1827
|
idempotencyKey,
|
|
1647
|
-
timeoutMs:
|
|
1828
|
+
timeoutMs: text ? this.timeoutMs : this.options.uploadTimeoutMs,
|
|
1648
1829
|
deadline: "body",
|
|
1649
1830
|
fetch: this.options.uploadFetch
|
|
1650
1831
|
});
|
|
1651
1832
|
}
|
|
1652
|
-
|
|
1653
|
-
const query = new URLSearchParams;
|
|
1654
|
-
query.set("name", options.name);
|
|
1655
|
-
query.set("queue", String(queue));
|
|
1656
|
-
setOptionalQueryValue(query, "description", options.description);
|
|
1657
|
-
setOptionalQueryValue(query, "processingOptions", options.processingOptions);
|
|
1658
|
-
setOptionalQueryValue(query, "visibility", options.visibility);
|
|
1659
|
-
setOptionalQueryValue(query, "metadata", options.metadata);
|
|
1660
|
-
setOptionalQueryValue(query, "authorId", options.authorId);
|
|
1661
|
-
setOptionalQueryValue(query, "context", options.context);
|
|
1662
|
-
setOptionalQueryValue(query, "externalId", options.externalId);
|
|
1663
|
-
setOptionalQueryValue(query, "externalUrl", options.externalUrl);
|
|
1664
|
-
setOptionalQueryValue(query, "folderId", options.folderId);
|
|
1665
|
-
setOptionalQueryValue(query, "uploadPresetId", options.uploadPresetId);
|
|
1833
|
+
submitUpload(uploadsPath, options, wait, authHeaders = {}) {
|
|
1666
1834
|
const isMultipart = "part" in options;
|
|
1667
1835
|
const payload = isMultipart ? options.part : options.content;
|
|
1836
|
+
const multipartOptions = options;
|
|
1837
|
+
const idempotencyKey = options.idempotencyKey ?? newIdempotencyKey();
|
|
1838
|
+
const fields = uploadFields(options);
|
|
1839
|
+
if (isTextPayload(payload)) {
|
|
1840
|
+
const { sizeInBytes: _size, ...text } = payload;
|
|
1841
|
+
const body = isMultipart ? {
|
|
1842
|
+
...fields,
|
|
1843
|
+
part: text,
|
|
1844
|
+
...multipartOptions.sizeInBytes === undefined ? {} : { sizeInBytes: multipartOptions.sizeInBytes },
|
|
1845
|
+
...multipartOptions.totalSizeInBytes === undefined ? {} : { totalSizeInBytes: multipartOptions.totalSizeInBytes }
|
|
1846
|
+
} : { ...fields, content: text };
|
|
1847
|
+
return this.upload(this.url(uploadsPath, { wait }), JSON.stringify(body), { ...authHeaders, "Content-Type": "application/json" }, idempotencyKey, true);
|
|
1848
|
+
}
|
|
1849
|
+
const query = new URLSearchParams;
|
|
1850
|
+
query.set("wait", String(wait));
|
|
1668
1851
|
query.set("contentType", payload.type);
|
|
1669
1852
|
setOptionalQueryValue(query, "sizeInBytes", payload.sizeInBytes ?? getAssetPayloadByteLength(payload));
|
|
1670
1853
|
if (isMultipart) {
|
|
1671
1854
|
const part = payload;
|
|
1672
|
-
const multipartOptions = options;
|
|
1673
1855
|
query.set("partNumber", String(part.partNumber ?? 1));
|
|
1674
1856
|
query.set("isFinal", String(part.isFinal ?? false));
|
|
1675
1857
|
setOptionalQueryValue(query, "sizeInBytes", part.sizeInBytes ?? multipartOptions.sizeInBytes);
|
|
1676
1858
|
setOptionalQueryValue(query, "totalSizeInBytes", multipartOptions.totalSizeInBytes);
|
|
1677
1859
|
}
|
|
1678
|
-
|
|
1860
|
+
const form = toUploadForm(fields, payload);
|
|
1861
|
+
return this.upload(this.url(`${uploadsPath}?${query}`), form.body, {
|
|
1679
1862
|
...authHeaders,
|
|
1680
|
-
"Content-Type":
|
|
1863
|
+
"Content-Type": form.contentType,
|
|
1681
1864
|
"X-CalmLens-Upload": isMultipart ? "part" : "content"
|
|
1682
|
-
},
|
|
1865
|
+
}, idempotencyKey, false);
|
|
1683
1866
|
}
|
|
1684
1867
|
get partSizeBytes() {
|
|
1685
1868
|
return this.options.partSizeBytes ?? DEFAULT_PART_SIZE_BYTES;
|
|
1686
1869
|
}
|
|
1687
|
-
async submitInParts(uploadsPath, options,
|
|
1870
|
+
async submitInParts(uploadsPath, options, wait, {
|
|
1688
1871
|
authHeaders = {},
|
|
1689
1872
|
partPath,
|
|
1690
1873
|
onStarted,
|
|
@@ -1696,12 +1879,12 @@ class CalmLensConnection {
|
|
|
1696
1879
|
const count = Math.ceil(source.size / partSize);
|
|
1697
1880
|
const key = idempotencyKey ?? newIdempotencyKey();
|
|
1698
1881
|
const part = (partNumber) => source.slice((partNumber - 1) * partSize, Math.min(partNumber * partSize, source.size));
|
|
1699
|
-
const first = await this.
|
|
1882
|
+
const first = await this.submitUpload(uploadsPath, {
|
|
1700
1883
|
...fields,
|
|
1701
1884
|
part: { ...part(1), type: content.type, partNumber: 1, isFinal: false },
|
|
1702
1885
|
totalSizeInBytes: source.size,
|
|
1703
1886
|
idempotencyKey: key
|
|
1704
|
-
},
|
|
1887
|
+
}, wait, authHeaders);
|
|
1705
1888
|
const assetId = expectUploadedAsset(first).id;
|
|
1706
1889
|
onStarted?.(assetId);
|
|
1707
1890
|
let result = first;
|
|
@@ -1728,7 +1911,7 @@ class CalmLensConnection {
|
|
|
1728
1911
|
}
|
|
1729
1912
|
return result;
|
|
1730
1913
|
}
|
|
1731
|
-
uploadPart(partPath, { part,
|
|
1914
|
+
uploadPart(partPath, { part, wait, idempotencyKey }, authHeaders = {}) {
|
|
1732
1915
|
if (!part)
|
|
1733
1916
|
throw invalidArgument("Part options are required");
|
|
1734
1917
|
assertDeclaredPayloadSize(part);
|
|
@@ -1742,66 +1925,89 @@ class CalmLensConnection {
|
|
|
1742
1925
|
partNumber: String(part.partNumber),
|
|
1743
1926
|
isFinal: String(part.isFinal ?? false)
|
|
1744
1927
|
});
|
|
1745
|
-
if (
|
|
1746
|
-
query.set("
|
|
1928
|
+
if (wait !== undefined)
|
|
1929
|
+
query.set("wait", String(wait));
|
|
1747
1930
|
setOptionalQueryValue(query, "sizeInBytes", part.sizeInBytes ?? getAssetPayloadByteLength(part));
|
|
1748
|
-
return this.upload(this.url(`${partPath}?${query}`), part, { ...authHeaders, "X-CalmLens-Upload": "part" }, idempotencyKey ?? newIdempotencyKey());
|
|
1931
|
+
return this.upload(this.url(`${partPath}?${query}`), toRawUploadBody(part), { ...authHeaders, "X-CalmLens-Upload": "part" }, idempotencyKey ?? newIdempotencyKey(), isTextPayload(part));
|
|
1749
1932
|
}
|
|
1750
1933
|
}
|
|
1751
1934
|
|
|
1752
1935
|
// src/client/CalmLensOptionKeys.ts
|
|
1753
1936
|
var SERVER_OPTION_KEYS = {
|
|
1754
1937
|
"assets.batch": ["assetIds", "operation"],
|
|
1755
|
-
"assets.classify": ["authorId", "content", "context", "description", "externalId", "externalUrl", "folderId", "isFinal", "metadata", "name", "part", "processingOptions", "sizeInBytes", "totalSizeInBytes", "uploadPresetId", "url", "visibility"],
|
|
1756
|
-
"assets.create": ["authorId", "content", "context", "description", "externalId", "externalUrl", "folderId", "isFinal", "metadata", "name", "part", "processingOptions", "sizeInBytes", "totalSizeInBytes", "uploadPresetId", "url", "visibility"],
|
|
1757
|
-
"assets.createSignedUrl": ["assetId", "expiresInSeconds", "lens", "resource", "transform", "viewerClaims"],
|
|
1938
|
+
"assets.classify": ["authorId", "content", "context", "description", "externalId", "externalUrl", "folderId", "isFinal", "metadata", "name", "part", "processingOptions", "sizeInBytes", "tags", "totalSizeInBytes", "uploadPresetId", "url", "visibility"],
|
|
1939
|
+
"assets.create": ["authorId", "content", "context", "description", "externalId", "externalUrl", "folderId", "isFinal", "metadata", "name", "part", "processingOptions", "sizeInBytes", "tags", "totalSizeInBytes", "uploadPresetId", "url", "visibility"],
|
|
1758
1940
|
"assets.decide": ["assetId", "confirmPurge", "decision", "note"],
|
|
1759
1941
|
"assets.delete": ["assetId"],
|
|
1760
|
-
"assets.deleteContent": ["assetId"],
|
|
1761
1942
|
"assets.explain": ["assetId", "rerun"],
|
|
1762
|
-
"assets.iterate": ["cursor", "filter", "
|
|
1763
|
-
"assets.iterateChildren": ["assetId", "cursor", "
|
|
1764
|
-
"assets.
|
|
1765
|
-
"assets.
|
|
1943
|
+
"assets.iterate": ["cursor", "filter", "pageSize", "sort"],
|
|
1944
|
+
"assets.iterateChildren": ["assetId", "cursor", "pageSize", "sort"],
|
|
1945
|
+
"assets.iterateTimeline": ["assetId", "cursor", "pageSize"],
|
|
1946
|
+
"assets.list": ["cursor", "filter", "pageSize", "sort"],
|
|
1947
|
+
"assets.listChildren": ["assetId", "cursor", "pageSize", "sort"],
|
|
1948
|
+
"assets.listTimeline": ["assetId", "cursor", "pageSize"],
|
|
1766
1949
|
"assets.move": ["assetId", "folderId"],
|
|
1950
|
+
"assets.removeContent": ["assetId"],
|
|
1767
1951
|
"assets.retrieve": ["assetId"],
|
|
1768
1952
|
"assets.retry": ["assetId"],
|
|
1769
|
-
"assets.search": ["
|
|
1953
|
+
"assets.search": ["mode", "pageSize", "query"],
|
|
1770
1954
|
"assets.update": ["assetId", "description", "externalId", "externalUrl", "metadata", "name", "tags", "visibility"],
|
|
1771
|
-
"assets.uploadPart": ["assetId", "part", "
|
|
1772
|
-
|
|
1955
|
+
"assets.uploadPart": ["assetId", "part", "wait"],
|
|
1956
|
+
"cdn.signAssetUrl": ["assetId", "expiresIn", "externalId", "lens", "original", "projectId", "resource", "transform", "viewerClaims"],
|
|
1957
|
+
ensureLens: ["active", "description", "identifier", "name", "transform", "type"],
|
|
1773
1958
|
ensureLenses: ["lenses"],
|
|
1774
|
-
"events.list": ["cursor", "pageSize"],
|
|
1775
|
-
"events.pages": ["cursor", "pageSize"],
|
|
1959
|
+
"events.list": ["assetId", "cursor", "pageSize", "types"],
|
|
1960
|
+
"events.pages": ["assetId", "cursor", "pageSize", "types"],
|
|
1776
1961
|
"folders.create": ["name", "parentId"],
|
|
1777
1962
|
"folders.delete": ["folderId"],
|
|
1778
|
-
"folders.
|
|
1963
|
+
"folders.iterate": ["cursor", "pageSize", "parentId", "search", "sort"],
|
|
1964
|
+
"folders.list": ["cursor", "pageSize", "parentId", "search", "sort"],
|
|
1779
1965
|
"folders.move": ["folderId", "parentId"],
|
|
1780
1966
|
"folders.retrieve": ["folderId"],
|
|
1781
1967
|
"folders.update": ["folderId", "name"],
|
|
1782
1968
|
"hashLists.addEntry": ["assetId", "hash", "hashListId", "label", "quality"],
|
|
1783
1969
|
"hashLists.create": ["action", "description", "name"],
|
|
1784
1970
|
"hashLists.delete": ["hashListId"],
|
|
1785
|
-
"hashLists.
|
|
1786
|
-
"hashLists.
|
|
1971
|
+
"hashLists.iterate": ["cursor", "pageSize", "sort"],
|
|
1972
|
+
"hashLists.iterateEntries": ["cursor", "hashListId", "pageSize", "sort"],
|
|
1973
|
+
"hashLists.list": ["cursor", "pageSize", "sort"],
|
|
1974
|
+
"hashLists.listEntries": ["cursor", "hashListId", "pageSize", "sort"],
|
|
1787
1975
|
"hashLists.removeEntry": ["entryId"],
|
|
1788
1976
|
"hashLists.retrieve": ["hashListId"],
|
|
1789
1977
|
"hashLists.update": ["action", "description", "hashListId", "name"],
|
|
1790
|
-
"
|
|
1978
|
+
"lenses.create": ["active", "description", "identifier", "name", "transform", "type"],
|
|
1979
|
+
"lenses.delete": ["lensId"],
|
|
1980
|
+
"lenses.iterate": ["cursor", "pageSize", "sort"],
|
|
1981
|
+
"lenses.list": ["cursor", "pageSize", "sort"],
|
|
1982
|
+
"lenses.retrieve": ["lensId"],
|
|
1983
|
+
"lenses.update": ["active", "description", "lensId", "name", "transform", "type"],
|
|
1984
|
+
"metadataFields.delete": ["fieldId", "revision"],
|
|
1985
|
+
"metadataFields.ensure": ["fields", "revision"],
|
|
1986
|
+
"metadataFields.list": [],
|
|
1791
1987
|
"policies.assign": ["policyId"],
|
|
1792
1988
|
"policies.create": ["description", "name", "presetId", "settings"],
|
|
1793
1989
|
"policies.delete": ["policyId"],
|
|
1794
|
-
"policies.
|
|
1990
|
+
"policies.iterate": ["cursor", "pageSize", "sort"],
|
|
1991
|
+
"policies.list": ["cursor", "pageSize", "sort"],
|
|
1992
|
+
"policies.reset": ["policyId", "presetVersion", "revision"],
|
|
1795
1993
|
"policies.retrieve": ["policyId"],
|
|
1994
|
+
"policies.retrieveAssigned": [],
|
|
1796
1995
|
"policies.setAutomaticUpdates": ["enabled", "policyId", "presetVersion", "revision"],
|
|
1797
1996
|
"policies.update": ["description", "name", "policyId", "revision", "settings"],
|
|
1798
|
-
"
|
|
1997
|
+
"policies.upgrade": ["policyId", "presetVersion", "revision"],
|
|
1998
|
+
"projectSettings.get": [],
|
|
1999
|
+
"projectSettings.update": ["revision", "searchIndexingBudgetUnits", "settings"],
|
|
2000
|
+
"text.classify": ["authorId", "context", "description", "externalId", "externalUrl", "folderId", "metadata", "name", "processingOptions", "tags", "text", "uploadPresetId", "visibility"],
|
|
2001
|
+
"uploadPresets.delete": ["uploadPresetId"],
|
|
2002
|
+
"uploadPresets.ensure": ["uploadPresets"],
|
|
2003
|
+
"uploadPresets.iterate": ["cursor", "pageSize", "sort"],
|
|
2004
|
+
"uploadPresets.list": ["cursor", "pageSize", "sort"]
|
|
1799
2005
|
};
|
|
1800
2006
|
var NULLABLE_OPTION_KEYS = {
|
|
1801
|
-
"assets.classify": ["authorId", "context", "description", "externalId", "folderId", "metadata", "processingOptions", "uploadPresetId", "visibility"],
|
|
1802
|
-
"assets.create": ["authorId", "context", "description", "externalId", "folderId", "metadata", "processingOptions", "uploadPresetId", "visibility"],
|
|
1803
|
-
"assets.iterate": ["filter"
|
|
1804
|
-
"assets.list": ["filter"
|
|
2007
|
+
"assets.classify": ["authorId", "context", "description", "externalId", "folderId", "metadata", "processingOptions", "tags", "uploadPresetId", "visibility"],
|
|
2008
|
+
"assets.create": ["authorId", "context", "description", "externalId", "folderId", "metadata", "processingOptions", "tags", "uploadPresetId", "visibility"],
|
|
2009
|
+
"assets.iterate": ["filter"],
|
|
2010
|
+
"assets.list": ["filter"],
|
|
1805
2011
|
"assets.move": ["folderId"],
|
|
1806
2012
|
"assets.update": ["description", "externalId", "externalUrl", "metadata", "tags", "visibility"],
|
|
1807
2013
|
"folders.create": ["parentId"],
|
|
@@ -1809,7 +2015,9 @@ var NULLABLE_OPTION_KEYS = {
|
|
|
1809
2015
|
"hashLists.addEntry": ["label", "quality"],
|
|
1810
2016
|
"hashLists.create": ["description"],
|
|
1811
2017
|
"hashLists.update": ["description"],
|
|
1812
|
-
"
|
|
2018
|
+
"lenses.create": ["description", "transform"],
|
|
2019
|
+
"lenses.update": ["description", "transform"],
|
|
2020
|
+
"text.classify": ["authorId", "context", "description", "externalId", "folderId", "metadata", "processingOptions", "tags", "uploadPresetId", "visibility"]
|
|
1813
2021
|
};
|
|
1814
2022
|
|
|
1815
2023
|
// src/contract/CryptoUtils-B_x8lMIx.js
|
|
@@ -1850,19 +2058,15 @@ var signUploadToken = async (claims, apiKey) => {
|
|
|
1850
2058
|
var signUploadTokenWithApiKey = async (apiKey, options, { now = Date.now(), nonce = crypto.randomUUID() } = {}) => {
|
|
1851
2059
|
if (!options || typeof options !== "object")
|
|
1852
2060
|
throw invalidArgument("Options are required");
|
|
1853
|
-
const {
|
|
1854
|
-
uploadPresetId,
|
|
1855
|
-
externalId,
|
|
1856
|
-
expiresInSeconds = UPLOAD_TOKEN_DEFAULT_TTL_SECONDS
|
|
1857
|
-
} = options;
|
|
2061
|
+
const { uploadPresetId, externalId, expiresIn = UPLOAD_TOKEN_DEFAULT_TTL_SECONDS } = options;
|
|
1858
2062
|
encodePathSegment(uploadPresetId, "Upload preset ID");
|
|
1859
|
-
if (!Number.isInteger(
|
|
1860
|
-
throw invalidArgument(`
|
|
2063
|
+
if (!Number.isInteger(expiresIn) || expiresIn < 1 || expiresIn > UPLOAD_TOKEN_MAX_TTL_SECONDS) {
|
|
2064
|
+
throw invalidArgument(`expiresIn must be a whole number from 1 to ${UPLOAD_TOKEN_MAX_TTL_SECONDS}`);
|
|
1861
2065
|
}
|
|
1862
2066
|
if (externalId !== undefined && (typeof externalId !== "string" || !externalId)) {
|
|
1863
2067
|
throw invalidArgument("externalId must be a non-empty string");
|
|
1864
2068
|
}
|
|
1865
|
-
const expiresAt = now +
|
|
2069
|
+
const expiresAt = now + expiresIn * 1000;
|
|
1866
2070
|
const token = await signUploadToken({
|
|
1867
2071
|
v: 1,
|
|
1868
2072
|
u: uploadPresetId,
|
|
@@ -1937,8 +2141,7 @@ var getEnsureLensCacheKey = (options) => stringifyJsonCanonical({
|
|
|
1937
2141
|
description: options.description ?? null,
|
|
1938
2142
|
type: options.type,
|
|
1939
2143
|
active: options.active,
|
|
1940
|
-
transform: options.transform ?? null
|
|
1941
|
-
version: options.version
|
|
2144
|
+
transform: options.transform ?? null
|
|
1942
2145
|
});
|
|
1943
2146
|
var requireId = (value, name) => encodePathSegment(value, name);
|
|
1944
2147
|
var checked = (operation, options) => {
|
|
@@ -1961,6 +2164,7 @@ var inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
|
|
1961
2164
|
|
|
1962
2165
|
class CalmLensServerClient {
|
|
1963
2166
|
#apiKey;
|
|
2167
|
+
#options;
|
|
1964
2168
|
#settings;
|
|
1965
2169
|
#lenses;
|
|
1966
2170
|
#connection;
|
|
@@ -1974,6 +2178,7 @@ class CalmLensServerClient {
|
|
|
1974
2178
|
}
|
|
1975
2179
|
const { apiKey, ...rest } = options;
|
|
1976
2180
|
this.#apiKey = apiKey;
|
|
2181
|
+
this.#options = rest;
|
|
1977
2182
|
this.#settings = {
|
|
1978
2183
|
...resolveConnectionOptions(rest),
|
|
1979
2184
|
cdnBaseUrl: (rest.cdnBaseUrl ?? getMockHooks(rest)?.defaultCdnBaseUrl ?? DEFAULT_CDN_BASE_URL).replace(/\/+$/, "")
|
|
@@ -1983,7 +2188,7 @@ class CalmLensServerClient {
|
|
|
1983
2188
|
}
|
|
1984
2189
|
withRequestOptions(options) {
|
|
1985
2190
|
validateRequestOptions(options);
|
|
1986
|
-
return new CalmLensServerClient({ ...this.#
|
|
2191
|
+
return new CalmLensServerClient({ ...this.#options, ...options, apiKey: this.#apiKey }, this.#lenses);
|
|
1987
2192
|
}
|
|
1988
2193
|
[inspectSymbol]() {
|
|
1989
2194
|
const { projectId, baseUrl } = this.#settings;
|
|
@@ -1999,24 +2204,24 @@ class CalmLensServerClient {
|
|
|
1999
2204
|
request(method, path, options = {}) {
|
|
2000
2205
|
return this.#connection.json(method, path, options);
|
|
2001
2206
|
}
|
|
2002
|
-
async submitAsset(options,
|
|
2207
|
+
async submitAsset(options, wait) {
|
|
2003
2208
|
const body = prepareSubmitAssetOptions(options, {
|
|
2004
2209
|
deferUploadChecks: this.#connection.deferUploadChecks,
|
|
2005
2210
|
partSizeBytes: this.#connection.partSizeBytes
|
|
2006
2211
|
});
|
|
2007
2212
|
const uploadsPath = `${this.projectPath}/assets`;
|
|
2008
2213
|
if ("content" in body && splitsIntoParts(body.content, this.#connection.partSizeBytes)) {
|
|
2009
|
-
return expectAsset(await this.#connection.submitInParts(uploadsPath, body,
|
|
2214
|
+
return expectAsset(await this.#connection.submitInParts(uploadsPath, body, wait, {
|
|
2010
2215
|
partPath: (assetId) => `/assets/${encodeURIComponent(assetId)}/part`,
|
|
2011
2216
|
retrieve: (assetId) => this.buildAssets().retrieve({ assetId })
|
|
2012
2217
|
}));
|
|
2013
2218
|
}
|
|
2014
2219
|
if ("content" in body || "part" in body) {
|
|
2015
|
-
return expectAsset(await this.#connection.
|
|
2220
|
+
return expectAsset(await this.#connection.submitUpload(uploadsPath, body, wait));
|
|
2016
2221
|
}
|
|
2017
2222
|
const { idempotencyKey, ...fields } = body;
|
|
2018
2223
|
const data = await this.#connection.json("POST", uploadsPath, {
|
|
2019
|
-
query: {
|
|
2224
|
+
query: { wait },
|
|
2020
2225
|
body: fields,
|
|
2021
2226
|
idempotencyKey: idempotencyKey ?? newIdempotencyKey()
|
|
2022
2227
|
});
|
|
@@ -2025,13 +2230,32 @@ class CalmLensServerClient {
|
|
|
2025
2230
|
get cdn() {
|
|
2026
2231
|
return {
|
|
2027
2232
|
getAssetUrl: (urlOptions) => {
|
|
2028
|
-
const {
|
|
2029
|
-
|
|
2030
|
-
|
|
2233
|
+
const { projectId, ...options } = checked("cdn.getAssetUrl", urlOptions);
|
|
2234
|
+
return buildAssetUrl(this.#settings.cdnBaseUrl, projectId ?? this.#settings.projectId, options);
|
|
2235
|
+
},
|
|
2236
|
+
signAssetUrl: async (signOptions) => {
|
|
2237
|
+
const options = checked("cdn.signAssetUrl", signOptions);
|
|
2238
|
+
validateSignAssetUrlOptions(options);
|
|
2239
|
+
const { projectId, assetId, externalId, expiresIn, original, ...location } = options;
|
|
2240
|
+
const project = requireId(projectId ?? this.#settings.projectId, "Project ID");
|
|
2241
|
+
const signed = await this.request("POST", `/projects/${project}/signed-asset-urls`, {
|
|
2242
|
+
body: {
|
|
2243
|
+
...assetId !== undefined ? { assetId } : { externalId },
|
|
2244
|
+
expiresIn: expiresIn ?? DEFAULT_SIGNED_URL_EXPIRES_IN,
|
|
2245
|
+
original: original ?? false
|
|
2246
|
+
}
|
|
2247
|
+
});
|
|
2248
|
+
if (!signed || typeof signed.url !== "string" || !signed.url || typeof signed.expiresAt !== "number") {
|
|
2249
|
+
throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
2250
|
+
message: "The API returned no signed asset URL"
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
return { url: appendAssetLocation(signed.url, location), expiresAt: signed.expiresAt };
|
|
2031
2254
|
},
|
|
2255
|
+
getAssetInfo: (url, options = {}) => getAssetInfo(url, { ...options, fetch: this.#settings.cdnFetch }),
|
|
2032
2256
|
serve: async (options) => {
|
|
2033
|
-
const {
|
|
2034
|
-
const url = this.cdn.getAssetUrl({
|
|
2257
|
+
const { init, resource = "rendered", ...urlOptions } = checked("cdn.serve", options);
|
|
2258
|
+
const url = this.cdn.getAssetUrl({ ...urlOptions, resource });
|
|
2035
2259
|
const method = init?.method?.toUpperCase() ?? "GET";
|
|
2036
2260
|
const { response } = await this.#connection.transport.send({
|
|
2037
2261
|
method,
|
|
@@ -2086,38 +2310,36 @@ class CalmLensServerClient {
|
|
|
2086
2310
|
query
|
|
2087
2311
|
});
|
|
2088
2312
|
},
|
|
2313
|
+
listTimeline: async (options) => {
|
|
2314
|
+
const { assetId, ...query } = checked("assets.listTimeline", options);
|
|
2315
|
+
const assetPath = `${this.projectPath}/assets/${requireId(assetId, "Asset ID")}`;
|
|
2316
|
+
return this.request("GET", `${assetPath}/timeline`, {
|
|
2317
|
+
query
|
|
2318
|
+
});
|
|
2319
|
+
},
|
|
2320
|
+
iterateTimeline: (options) => {
|
|
2321
|
+
checked("assets.iterateTimeline", options);
|
|
2322
|
+
requireId(options?.assetId, "Asset ID");
|
|
2323
|
+
return this.iteratePages((cursor) => this.buildAssets().listTimeline({ ...options, cursor }));
|
|
2324
|
+
},
|
|
2089
2325
|
iterateChildren: (options) => {
|
|
2090
2326
|
checked("assets.iterateChildren", options);
|
|
2091
2327
|
requireId(options?.assetId, "Asset ID");
|
|
2092
2328
|
return this.iteratePages((cursor) => this.buildAssets().listChildren({ ...options, cursor }));
|
|
2093
2329
|
},
|
|
2094
|
-
create: async (options) => this.submitAsset(checked("assets.create", options),
|
|
2330
|
+
create: async (options) => this.submitAsset(checked("assets.create", options), false),
|
|
2095
2331
|
classify: async (classifyOptions) => {
|
|
2096
2332
|
const options = checked("assets.classify", classifyOptions);
|
|
2097
2333
|
if (options && "content" in options && "plainText" in options.content && (typeof options.content.plainText !== "string" || !options.content.plainText.trim())) {
|
|
2098
2334
|
throw invalidPayload("Text to classify must be a non-empty string");
|
|
2099
2335
|
}
|
|
2100
|
-
return this.submitAsset(options,
|
|
2336
|
+
return this.submitAsset(options, true);
|
|
2101
2337
|
},
|
|
2102
2338
|
uploadPart: async (partOptions) => {
|
|
2103
2339
|
const { assetId, ...options } = checked("assets.uploadPart", partOptions);
|
|
2104
2340
|
const encodedAssetId = requireId(assetId, "Asset ID");
|
|
2105
2341
|
return expectAsset(await this.#connection.uploadPart(`/assets/${encodedAssetId}/part`, options));
|
|
2106
2342
|
},
|
|
2107
|
-
createSignedUrl: async (signedUrlOptions) => {
|
|
2108
|
-
const { assetId, ...options } = checked("assets.createSignedUrl", signedUrlOptions);
|
|
2109
|
-
const encodedAssetId = requireId(assetId, "Asset ID");
|
|
2110
|
-
validateSignedUrlOptions(options);
|
|
2111
|
-
return this.request("POST", `/assets/${encodedAssetId}/signed-url`, {
|
|
2112
|
-
body: {
|
|
2113
|
-
viewerClaims: options.viewerClaims,
|
|
2114
|
-
resource: options.resource,
|
|
2115
|
-
expiresInSeconds: options.expiresInSeconds ?? DEFAULT_SIGNED_URL_EXPIRES_IN_SECONDS,
|
|
2116
|
-
lens: options.lens,
|
|
2117
|
-
transform: transformSelector(options.transform)
|
|
2118
|
-
}
|
|
2119
|
-
});
|
|
2120
|
-
},
|
|
2121
2343
|
move: async (options) => {
|
|
2122
2344
|
const { assetId, folderId } = checked("assets.move", options);
|
|
2123
2345
|
return this.request("POST", `/assets/${requireId(assetId, "Asset ID")}/move`, {
|
|
@@ -2144,8 +2366,8 @@ class CalmLensServerClient {
|
|
|
2144
2366
|
const client = options.signal ? this.withRequestOptions({ signal: options.signal }) : this;
|
|
2145
2367
|
return pollForDecision(() => client.assets.retrieve({ assetId }), options, this.#connection.sleep, this.#connection.hooks?.now);
|
|
2146
2368
|
},
|
|
2147
|
-
|
|
2148
|
-
const { assetId } = checked("assets.
|
|
2369
|
+
removeContent: async (options) => {
|
|
2370
|
+
const { assetId } = checked("assets.removeContent", options);
|
|
2149
2371
|
return this.request("DELETE", `/assets/${requireId(assetId, "Asset ID")}/content`);
|
|
2150
2372
|
},
|
|
2151
2373
|
delete: async (options) => {
|
|
@@ -2163,9 +2385,12 @@ class CalmLensServerClient {
|
|
|
2163
2385
|
}
|
|
2164
2386
|
get events() {
|
|
2165
2387
|
return {
|
|
2166
|
-
list: async (options = {}) =>
|
|
2167
|
-
|
|
2168
|
-
|
|
2388
|
+
list: async (options = {}) => {
|
|
2389
|
+
const { types, ...query } = checked("events.list", options);
|
|
2390
|
+
return this.request("GET", `${this.projectPath}/events`, {
|
|
2391
|
+
query: { ...query, types: types?.length ? types.join(",") : undefined }
|
|
2392
|
+
});
|
|
2393
|
+
},
|
|
2169
2394
|
pages: (options = {}) => this.iterateEventPages(checked("events.pages", options))
|
|
2170
2395
|
};
|
|
2171
2396
|
}
|
|
@@ -2201,6 +2426,10 @@ class CalmLensServerClient {
|
|
|
2201
2426
|
list: async (options = {}) => this.request("GET", `${this.projectPath}/folders`, {
|
|
2202
2427
|
query: checked("folders.list", options)
|
|
2203
2428
|
}),
|
|
2429
|
+
iterate: (options = {}) => {
|
|
2430
|
+
checked("folders.iterate", options);
|
|
2431
|
+
return this.iteratePages((cursor) => this.folders.list({ ...options, cursor }));
|
|
2432
|
+
},
|
|
2204
2433
|
retrieve: async (options) => {
|
|
2205
2434
|
const { folderId } = checked("folders.retrieve", options);
|
|
2206
2435
|
return this.request("GET", `/folders/${requireId(folderId, "Folder ID")}`);
|
|
@@ -2229,6 +2458,10 @@ class CalmLensServerClient {
|
|
|
2229
2458
|
list: async (options = {}) => this.request("GET", `${this.projectPath}/hash-lists`, {
|
|
2230
2459
|
query: checked("hashLists.list", options)
|
|
2231
2460
|
}),
|
|
2461
|
+
iterate: (options = {}) => {
|
|
2462
|
+
checked("hashLists.iterate", options);
|
|
2463
|
+
return this.iteratePages((cursor) => this.hashLists.list({ ...options, cursor }));
|
|
2464
|
+
},
|
|
2232
2465
|
retrieve: async (options) => {
|
|
2233
2466
|
const { hashListId } = checked("hashLists.retrieve", options);
|
|
2234
2467
|
return this.request("GET", `/hash-lists/${requireId(hashListId, "Hash list ID")}`);
|
|
@@ -2246,6 +2479,11 @@ class CalmLensServerClient {
|
|
|
2246
2479
|
const { hashListId } = checked("hashLists.delete", options);
|
|
2247
2480
|
await this.request("DELETE", `/hash-lists/${requireId(hashListId, "Hash list ID")}`);
|
|
2248
2481
|
},
|
|
2482
|
+
iterateEntries: (options) => {
|
|
2483
|
+
checked("hashLists.iterateEntries", options);
|
|
2484
|
+
requireId(options?.hashListId, "Hash list ID");
|
|
2485
|
+
return this.iteratePages((cursor) => this.hashLists.listEntries({ ...options, cursor }));
|
|
2486
|
+
},
|
|
2249
2487
|
listEntries: async (options) => {
|
|
2250
2488
|
const { hashListId, ...query } = checked("hashLists.listEntries", options);
|
|
2251
2489
|
return this.request("GET", `/hash-lists/${requireId(hashListId, "Hash list ID")}/entries`, {
|
|
@@ -2263,20 +2501,26 @@ class CalmLensServerClient {
|
|
|
2263
2501
|
};
|
|
2264
2502
|
}
|
|
2265
2503
|
get policies() {
|
|
2266
|
-
const policyPath = (policyId) =>
|
|
2504
|
+
const policyPath = (policyId) => `/policies/${requireId(policyId, "Policy ID")}`;
|
|
2267
2505
|
return {
|
|
2268
|
-
list: async () => this.request("GET",
|
|
2506
|
+
list: async (options = {}) => this.request("GET", "/policies", { query: checked("policies.list", options) }),
|
|
2507
|
+
iterate: (options = {}) => {
|
|
2508
|
+
checked("policies.iterate", options);
|
|
2509
|
+
return this.iteratePages((cursor) => this.policies.list({ ...options, cursor }));
|
|
2510
|
+
},
|
|
2269
2511
|
retrieve: async (options) => this.request("GET", policyPath(checked("policies.retrieve", options).policyId)),
|
|
2270
|
-
create: async (options) => this.request("POST",
|
|
2271
|
-
body: checked("policies.create", options)
|
|
2272
|
-
}),
|
|
2512
|
+
create: async (options) => this.request("POST", "/policies", { body: checked("policies.create", options) }),
|
|
2273
2513
|
update: async (options) => {
|
|
2274
2514
|
const { policyId, ...body } = checked("policies.update", options);
|
|
2275
2515
|
return this.request("PATCH", policyPath(policyId), { body });
|
|
2276
2516
|
},
|
|
2277
|
-
|
|
2278
|
-
const { policyId, ...body } = checked("policies.
|
|
2279
|
-
return this.request("POST", `${policyPath(policyId)}/
|
|
2517
|
+
reset: async (options) => {
|
|
2518
|
+
const { policyId, ...body } = checked("policies.reset", options);
|
|
2519
|
+
return this.request("POST", `${policyPath(policyId)}/reset`, { body });
|
|
2520
|
+
},
|
|
2521
|
+
upgrade: async (options) => {
|
|
2522
|
+
const { policyId, ...body } = checked("policies.upgrade", options);
|
|
2523
|
+
return this.request("POST", `${policyPath(policyId)}/upgrade`, { body });
|
|
2280
2524
|
},
|
|
2281
2525
|
setAutomaticUpdates: async (options) => {
|
|
2282
2526
|
const { policyId, ...body } = checked("policies.setAutomaticUpdates", options);
|
|
@@ -2285,11 +2529,86 @@ class CalmLensServerClient {
|
|
|
2285
2529
|
delete: async (options) => {
|
|
2286
2530
|
await this.request("DELETE", policyPath(checked("policies.delete", options).policyId));
|
|
2287
2531
|
},
|
|
2532
|
+
retrieveAssigned: async () => this.request("GET", `${this.projectPath}/policy`),
|
|
2288
2533
|
assign: async (options) => this.request("PUT", `${this.projectPath}/policy`, {
|
|
2289
2534
|
body: checked("policies.assign", options)
|
|
2290
2535
|
})
|
|
2291
2536
|
};
|
|
2292
2537
|
}
|
|
2538
|
+
get uploadPresets() {
|
|
2539
|
+
return {
|
|
2540
|
+
list: async (options = {}) => this.request("GET", `${this.projectPath}/upload-presets`, {
|
|
2541
|
+
query: checked("uploadPresets.list", options)
|
|
2542
|
+
}),
|
|
2543
|
+
iterate: (options = {}) => {
|
|
2544
|
+
checked("uploadPresets.iterate", options);
|
|
2545
|
+
return this.iteratePages((cursor) => this.uploadPresets.list({ ...options, cursor }));
|
|
2546
|
+
},
|
|
2547
|
+
ensure: async (options) => this.request("PUT", `${this.projectPath}/upload-presets`, {
|
|
2548
|
+
body: checked("uploadPresets.ensure", options)
|
|
2549
|
+
}),
|
|
2550
|
+
delete: async (options) => {
|
|
2551
|
+
const { uploadPresetId } = checked("uploadPresets.delete", options);
|
|
2552
|
+
await this.request("DELETE", `/upload-presets/${requireId(uploadPresetId, "Upload preset ID")}`);
|
|
2553
|
+
}
|
|
2554
|
+
};
|
|
2555
|
+
}
|
|
2556
|
+
get projectSettings() {
|
|
2557
|
+
return {
|
|
2558
|
+
get: async () => this.request("GET", `${this.projectPath}/settings`),
|
|
2559
|
+
update: async (options) => this.request("PUT", `${this.projectPath}/settings`, {
|
|
2560
|
+
body: checked("projectSettings.update", options)
|
|
2561
|
+
})
|
|
2562
|
+
};
|
|
2563
|
+
}
|
|
2564
|
+
get metadataFields() {
|
|
2565
|
+
return {
|
|
2566
|
+
list: async () => this.request("GET", `${this.projectPath}/metadata-fields`),
|
|
2567
|
+
ensure: async (options) => this.request("PUT", `${this.projectPath}/metadata-fields`, {
|
|
2568
|
+
body: checked("metadataFields.ensure", options)
|
|
2569
|
+
}),
|
|
2570
|
+
delete: async (options) => {
|
|
2571
|
+
const { fieldId, ...query } = checked("metadataFields.delete", options);
|
|
2572
|
+
await this.request("DELETE", `${this.projectPath}/metadata-fields/${requireId(fieldId, "Metadata field ID")}`, { query });
|
|
2573
|
+
}
|
|
2574
|
+
};
|
|
2575
|
+
}
|
|
2576
|
+
get lenses() {
|
|
2577
|
+
const lensPath = (lensId) => `/lenses/${requireId(lensId, "Lens ID")}`;
|
|
2578
|
+
const forget = (matches) => {
|
|
2579
|
+
for (const [cacheKey, lens] of this.#lenses.ensuredLenses)
|
|
2580
|
+
if (matches(lens))
|
|
2581
|
+
this.#lenses.ensuredLenses.delete(cacheKey);
|
|
2582
|
+
};
|
|
2583
|
+
return {
|
|
2584
|
+
list: async (options = {}) => this.request("GET", `${this.projectPath}/lenses`, {
|
|
2585
|
+
query: checked("lenses.list", options)
|
|
2586
|
+
}),
|
|
2587
|
+
iterate: (options = {}) => {
|
|
2588
|
+
checked("lenses.iterate", options);
|
|
2589
|
+
return this.iteratePages((cursor) => this.lenses.list({ ...options, cursor }));
|
|
2590
|
+
},
|
|
2591
|
+
create: async (options) => {
|
|
2592
|
+
const lens = await this.request("POST", `${this.projectPath}/lenses`, {
|
|
2593
|
+
body: checked("lenses.create", options)
|
|
2594
|
+
});
|
|
2595
|
+
forget((cached) => cached.identifier === lens.identifier);
|
|
2596
|
+
return lens;
|
|
2597
|
+
},
|
|
2598
|
+
retrieve: async (options) => this.request("GET", lensPath(checked("lenses.retrieve", options).lensId)),
|
|
2599
|
+
update: async (options) => {
|
|
2600
|
+
const { lensId, ...body } = checked("lenses.update", options);
|
|
2601
|
+
const lens = await this.request("PATCH", lensPath(lensId), { body });
|
|
2602
|
+
forget((cached) => cached.id === lens.id);
|
|
2603
|
+
return lens;
|
|
2604
|
+
},
|
|
2605
|
+
delete: async (options) => {
|
|
2606
|
+
const { lensId } = checked("lenses.delete", options);
|
|
2607
|
+
await this.request("DELETE", lensPath(lensId));
|
|
2608
|
+
forget((cached) => cached.id === lensId);
|
|
2609
|
+
}
|
|
2610
|
+
};
|
|
2611
|
+
}
|
|
2293
2612
|
async ensureLens(options) {
|
|
2294
2613
|
checked("ensureLens", options);
|
|
2295
2614
|
if (!options?.identifier)
|
|
@@ -4316,23 +4635,168 @@ function handleIntersectionResults(result, left, right) {
|
|
|
4316
4635
|
result.value = merged.data;
|
|
4317
4636
|
return result;
|
|
4318
4637
|
}
|
|
4638
|
+
var $ZodTuple = /* @__PURE__ */ $constructor("$ZodTuple", (inst, def) => {
|
|
4639
|
+
$ZodType.init(inst, def);
|
|
4640
|
+
const items = def.items;
|
|
4641
|
+
const memo = globalConfig.memoizer;
|
|
4642
|
+
memo?.attach(inst);
|
|
4643
|
+
inst._zod.parse = (payload, ctx) => {
|
|
4644
|
+
const input = payload.value;
|
|
4645
|
+
if (!Array.isArray(input)) {
|
|
4646
|
+
payload.issues.push({
|
|
4647
|
+
input,
|
|
4648
|
+
inst,
|
|
4649
|
+
expected: "tuple",
|
|
4650
|
+
code: "invalid_type"
|
|
4651
|
+
});
|
|
4652
|
+
return payload;
|
|
4653
|
+
}
|
|
4654
|
+
payload.value = memo ? memo.alloc(inst, payload, [], ctx) : [];
|
|
4655
|
+
const proms = [];
|
|
4656
|
+
const optinStart = getTupleOptStart(items, "optin");
|
|
4657
|
+
const optoutStart = getTupleOptStart(items, "optout");
|
|
4658
|
+
if (!def.rest) {
|
|
4659
|
+
if (input.length < optinStart) {
|
|
4660
|
+
payload.issues.push({
|
|
4661
|
+
code: "too_small",
|
|
4662
|
+
minimum: optinStart,
|
|
4663
|
+
inclusive: true,
|
|
4664
|
+
input,
|
|
4665
|
+
inst,
|
|
4666
|
+
origin: "array"
|
|
4667
|
+
});
|
|
4668
|
+
return payload;
|
|
4669
|
+
}
|
|
4670
|
+
if (input.length > items.length) {
|
|
4671
|
+
payload.issues.push({
|
|
4672
|
+
code: "too_big",
|
|
4673
|
+
maximum: items.length,
|
|
4674
|
+
inclusive: true,
|
|
4675
|
+
input,
|
|
4676
|
+
inst,
|
|
4677
|
+
origin: "array"
|
|
4678
|
+
});
|
|
4679
|
+
}
|
|
4680
|
+
}
|
|
4681
|
+
const itemResults = new Array(items.length);
|
|
4682
|
+
const abortEarly = def.rest ? ctx?.abortEarly : undefined;
|
|
4683
|
+
let itemAborted = false;
|
|
4684
|
+
for (let i = 0;i < items.length; i++) {
|
|
4685
|
+
const r = items[i]._zod.run({ value: input[i], issues: [] }, ctx);
|
|
4686
|
+
if (r instanceof Promise) {
|
|
4687
|
+
proms.push(r.then((rr) => {
|
|
4688
|
+
itemResults[i] = rr;
|
|
4689
|
+
}));
|
|
4690
|
+
} else {
|
|
4691
|
+
itemResults[i] = r;
|
|
4692
|
+
if (abortEarly && !itemAborted && r.issues.length)
|
|
4693
|
+
itemAborted = aborted(r);
|
|
4694
|
+
}
|
|
4695
|
+
}
|
|
4696
|
+
if (def.rest && !itemAborted) {
|
|
4697
|
+
let i = items.length - 1;
|
|
4698
|
+
const rest = input.slice(items.length);
|
|
4699
|
+
let seen = payload.issues.length;
|
|
4700
|
+
for (const el of rest) {
|
|
4701
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
4702
|
+
if (aborted(payload, seen))
|
|
4703
|
+
break;
|
|
4704
|
+
seen = payload.issues.length;
|
|
4705
|
+
}
|
|
4706
|
+
i++;
|
|
4707
|
+
const result = def.rest._zod.run({ value: el, issues: [] }, ctx);
|
|
4708
|
+
if (result instanceof Promise) {
|
|
4709
|
+
proms.push(result.then((r) => handleTupleResult(r, payload, i)));
|
|
4710
|
+
} else {
|
|
4711
|
+
handleTupleResult(result, payload, i);
|
|
4712
|
+
}
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4715
|
+
if (proms.length) {
|
|
4716
|
+
return Promise.all(proms).then(() => handleTupleResults(itemResults, payload, items, input, optoutStart));
|
|
4717
|
+
}
|
|
4718
|
+
return handleTupleResults(itemResults, payload, items, input, optoutStart);
|
|
4719
|
+
};
|
|
4720
|
+
});
|
|
4721
|
+
function getTupleOptStart(items, key) {
|
|
4722
|
+
for (let i = items.length - 1;i >= 0; i--) {
|
|
4723
|
+
const omittable = key === "optin" ? items[i]._zod.optin !== undefined : items[i]._zod.optout === "optional";
|
|
4724
|
+
if (!omittable)
|
|
4725
|
+
return i + 1;
|
|
4726
|
+
}
|
|
4727
|
+
return 0;
|
|
4728
|
+
}
|
|
4729
|
+
function handleTupleResult(result, final, index) {
|
|
4730
|
+
if (result.issues.length) {
|
|
4731
|
+
final.issues.push(...prefixIssues(index, result.issues));
|
|
4732
|
+
}
|
|
4733
|
+
final.value[index] = result.value;
|
|
4734
|
+
}
|
|
4735
|
+
function handleTupleResults(itemResults, final, items, input, optoutStart) {
|
|
4736
|
+
for (let i = 0;i < items.length; i++) {
|
|
4737
|
+
const r = itemResults[i];
|
|
4738
|
+
const isPresent = i < input.length;
|
|
4739
|
+
if (!isPresent && i >= optoutStart && items[i]._zod.optin === "optional") {
|
|
4740
|
+
final.value.length = i;
|
|
4741
|
+
break;
|
|
4742
|
+
}
|
|
4743
|
+
if (r.issues.length) {
|
|
4744
|
+
if (!isPresent && i >= optoutStart) {
|
|
4745
|
+
final.value.length = i;
|
|
4746
|
+
break;
|
|
4747
|
+
}
|
|
4748
|
+
final.issues.push(...prefixIssues(i, r.issues));
|
|
4749
|
+
}
|
|
4750
|
+
final.value[i] = r.value;
|
|
4751
|
+
}
|
|
4752
|
+
for (let i = final.value.length - 1;i >= input.length; i--) {
|
|
4753
|
+
if (items[i]._zod.optout === "optional" && final.value[i] === undefined) {
|
|
4754
|
+
final.value.length = i;
|
|
4755
|
+
} else {
|
|
4756
|
+
break;
|
|
4757
|
+
}
|
|
4758
|
+
}
|
|
4759
|
+
return final;
|
|
4760
|
+
}
|
|
4319
4761
|
var $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
|
|
4320
4762
|
$ZodType.init(inst, def);
|
|
4321
|
-
const values = getEnumValues(def.entries);
|
|
4322
|
-
const valuesSet = new Set(values);
|
|
4323
|
-
inst._zod.values = valuesSet;
|
|
4763
|
+
const values = getEnumValues(def.entries);
|
|
4764
|
+
const valuesSet = new Set(values);
|
|
4765
|
+
inst._zod.values = valuesSet;
|
|
4766
|
+
defineLazyInternal(inst, "pattern", (zod) => {
|
|
4767
|
+
const patternValues = getEnumValues(zod.def.entries).filter((k) => propertyKeyTypes.has(typeof k));
|
|
4768
|
+
return new RegExp(patternValues.length ? `^(${patternValues.map((o) => escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$");
|
|
4769
|
+
});
|
|
4770
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
4771
|
+
const input = payload.value;
|
|
4772
|
+
if (valuesSet.has(input)) {
|
|
4773
|
+
return payload;
|
|
4774
|
+
}
|
|
4775
|
+
payload.issues.push({
|
|
4776
|
+
code: "invalid_value",
|
|
4777
|
+
values,
|
|
4778
|
+
input,
|
|
4779
|
+
inst
|
|
4780
|
+
});
|
|
4781
|
+
return payload;
|
|
4782
|
+
};
|
|
4783
|
+
});
|
|
4784
|
+
var $ZodLiteral = /* @__PURE__ */ $constructor("$ZodLiteral", (inst, def) => {
|
|
4785
|
+
$ZodType.init(inst, def);
|
|
4786
|
+
const values = new Set(def.values);
|
|
4787
|
+
inst._zod.values = values;
|
|
4324
4788
|
defineLazyInternal(inst, "pattern", (zod) => {
|
|
4325
|
-
const
|
|
4326
|
-
return new RegExp(
|
|
4789
|
+
const vals = zod.def.values;
|
|
4790
|
+
return new RegExp(vals.length ? `^(${vals.map((o) => typeof o === "string" ? escapeRegex(o) : o ? escapeRegex(o.toString()) : String(o)).join("|")})$` : "^[^\\s\\S]$");
|
|
4327
4791
|
});
|
|
4328
4792
|
inst._zod.parse = (payload, _ctx) => {
|
|
4329
4793
|
const input = payload.value;
|
|
4330
|
-
if (
|
|
4794
|
+
if (values.has(input)) {
|
|
4331
4795
|
return payload;
|
|
4332
4796
|
}
|
|
4333
4797
|
payload.issues.push({
|
|
4334
4798
|
code: "invalid_value",
|
|
4335
|
-
values,
|
|
4799
|
+
values: def.values,
|
|
4336
4800
|
input,
|
|
4337
4801
|
inst
|
|
4338
4802
|
});
|
|
@@ -5855,6 +6319,45 @@ var enumProcessor = (schema, _ctx, json, _params) => {
|
|
|
5855
6319
|
json.type = "string";
|
|
5856
6320
|
json.enum = values;
|
|
5857
6321
|
};
|
|
6322
|
+
var literalProcessor = (schema, ctx, json, params) => {
|
|
6323
|
+
const def = schema._zod.def;
|
|
6324
|
+
if (def.values.length === 0) {
|
|
6325
|
+
json.not = {};
|
|
6326
|
+
return;
|
|
6327
|
+
}
|
|
6328
|
+
const vals = [];
|
|
6329
|
+
for (const val of def.values) {
|
|
6330
|
+
if (val === undefined) {
|
|
6331
|
+
if (handleUnrepresentable(schema, ctx, json, params, "Literal `undefined` cannot be represented in JSON Schema"))
|
|
6332
|
+
return;
|
|
6333
|
+
} else if (typeof val === "bigint") {
|
|
6334
|
+
if (handleUnrepresentable(schema, ctx, json, params, "BigInt literals cannot be represented in JSON Schema"))
|
|
6335
|
+
return;
|
|
6336
|
+
vals.push(Number(val));
|
|
6337
|
+
} else {
|
|
6338
|
+
vals.push(val);
|
|
6339
|
+
}
|
|
6340
|
+
}
|
|
6341
|
+
if (vals.length === 0) {} else if (vals.length === 1) {
|
|
6342
|
+
const val = vals[0];
|
|
6343
|
+
json.type = val === null ? "null" : typeof val;
|
|
6344
|
+
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
6345
|
+
json.enum = [val];
|
|
6346
|
+
} else {
|
|
6347
|
+
json.const = val;
|
|
6348
|
+
}
|
|
6349
|
+
} else {
|
|
6350
|
+
if (vals.every((v) => typeof v === "number"))
|
|
6351
|
+
json.type = "number";
|
|
6352
|
+
if (vals.every((v) => typeof v === "string"))
|
|
6353
|
+
json.type = "string";
|
|
6354
|
+
if (vals.every((v) => typeof v === "boolean"))
|
|
6355
|
+
json.type = "boolean";
|
|
6356
|
+
if (vals.every((v) => v === null))
|
|
6357
|
+
json.type = "null";
|
|
6358
|
+
json.enum = vals;
|
|
6359
|
+
}
|
|
6360
|
+
};
|
|
5858
6361
|
var customProcessor = (schema, ctx, json, params) => {
|
|
5859
6362
|
handleUnrepresentable(schema, ctx, json, params, "Custom types cannot be represented in JSON Schema");
|
|
5860
6363
|
};
|
|
@@ -5954,6 +6457,70 @@ var intersectionProcessor = (schema, ctx, json, params) => {
|
|
|
5954
6457
|
json.allOf = allOf;
|
|
5955
6458
|
ctx.intersections.push(allOf);
|
|
5956
6459
|
};
|
|
6460
|
+
var tupleProcessor = (schema, ctx, _json, params) => {
|
|
6461
|
+
const json = _json;
|
|
6462
|
+
const def = schema._zod.def;
|
|
6463
|
+
json.type = "array";
|
|
6464
|
+
const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
|
|
6465
|
+
const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
|
|
6466
|
+
const prefixItems = def.items.map((x, i) => processSchema(x, ctx, {
|
|
6467
|
+
...params,
|
|
6468
|
+
path: [...params.path, prefixPath, i]
|
|
6469
|
+
}));
|
|
6470
|
+
const rest = def.rest ? processSchema(def.rest, ctx, {
|
|
6471
|
+
...params,
|
|
6472
|
+
path: [...params.path, restPath, ...ctx.target === "openapi-3.0" ? [def.items.length] : []]
|
|
6473
|
+
}) : null;
|
|
6474
|
+
let minItems = def.items.length;
|
|
6475
|
+
while (minItems > 0) {
|
|
6476
|
+
const item = def.items[minItems - 1];
|
|
6477
|
+
const optional = ctx.io === "input" ? inputOptin(item) !== undefined : item._zod.optout === "optional";
|
|
6478
|
+
if (!optional)
|
|
6479
|
+
break;
|
|
6480
|
+
minItems--;
|
|
6481
|
+
}
|
|
6482
|
+
const maxItems = def.items.length;
|
|
6483
|
+
const isClosed = !def.rest;
|
|
6484
|
+
if (ctx.target === "draft-2020-12") {
|
|
6485
|
+
json.prefixItems = prefixItems;
|
|
6486
|
+
if (isClosed) {
|
|
6487
|
+
json.items = false;
|
|
6488
|
+
} else if (rest) {
|
|
6489
|
+
json.items = rest;
|
|
6490
|
+
}
|
|
6491
|
+
if (minItems > 0)
|
|
6492
|
+
json.minItems = minItems;
|
|
6493
|
+
if (isClosed)
|
|
6494
|
+
json.maxItems = maxItems;
|
|
6495
|
+
} else if (ctx.target === "openapi-3.0") {
|
|
6496
|
+
json.items = {
|
|
6497
|
+
anyOf: prefixItems
|
|
6498
|
+
};
|
|
6499
|
+
if (rest) {
|
|
6500
|
+
json.items.anyOf.push(rest);
|
|
6501
|
+
}
|
|
6502
|
+
if (minItems > 0)
|
|
6503
|
+
json.minItems = minItems;
|
|
6504
|
+
if (isClosed)
|
|
6505
|
+
json.maxItems = maxItems;
|
|
6506
|
+
} else {
|
|
6507
|
+
json.items = prefixItems;
|
|
6508
|
+
if (isClosed) {
|
|
6509
|
+
json.additionalItems = false;
|
|
6510
|
+
} else if (rest) {
|
|
6511
|
+
json.additionalItems = rest;
|
|
6512
|
+
}
|
|
6513
|
+
if (minItems > 0)
|
|
6514
|
+
json.minItems = minItems;
|
|
6515
|
+
if (isClosed)
|
|
6516
|
+
json.maxItems = maxItems;
|
|
6517
|
+
}
|
|
6518
|
+
const { minimum, maximum } = aggregateChecks(schema);
|
|
6519
|
+
if (typeof minimum === "number")
|
|
6520
|
+
json.minItems = minimum;
|
|
6521
|
+
if (typeof maximum === "number")
|
|
6522
|
+
json.maxItems = maximum;
|
|
6523
|
+
};
|
|
5957
6524
|
var pendingRecords = new WeakMap;
|
|
5958
6525
|
var nullableProcessor = (schema, ctx, json, params) => {
|
|
5959
6526
|
const def = schema._zod.def;
|
|
@@ -6489,6 +7056,39 @@ function intersection(left, right) {
|
|
|
6489
7056
|
right
|
|
6490
7057
|
});
|
|
6491
7058
|
}
|
|
7059
|
+
var ZodTuple = /* @__PURE__ */ $constructor("ZodTuple", (inst, def) => {
|
|
7060
|
+
_ensureDefaultMemoizer();
|
|
7061
|
+
$ZodTuple.init(inst, def);
|
|
7062
|
+
ZodType.init(inst, def);
|
|
7063
|
+
inst._zod.processJSONSchema = (ctx, json, params) => tupleProcessor(inst, ctx, json, params);
|
|
7064
|
+
}, {
|
|
7065
|
+
rest(rest) {
|
|
7066
|
+
return this.clone({
|
|
7067
|
+
...this._zod.def,
|
|
7068
|
+
rest
|
|
7069
|
+
});
|
|
7070
|
+
},
|
|
7071
|
+
partial() {
|
|
7072
|
+
const def = this._zod.def;
|
|
7073
|
+
if (def.checks?.length)
|
|
7074
|
+
throw new Error(".partial() cannot be used on tuple schemas containing refinements");
|
|
7075
|
+
return this.clone({
|
|
7076
|
+
...def,
|
|
7077
|
+
items: def.items.map((item) => new ZodOptional({ type: "optional", innerType: item }))
|
|
7078
|
+
});
|
|
7079
|
+
}
|
|
7080
|
+
});
|
|
7081
|
+
function tuple(items, _paramsOrRest, _params) {
|
|
7082
|
+
const hasRest = _paramsOrRest instanceof $ZodType;
|
|
7083
|
+
const params = hasRest ? _params : _paramsOrRest;
|
|
7084
|
+
const rest = hasRest ? _paramsOrRest : null;
|
|
7085
|
+
return new ZodTuple({
|
|
7086
|
+
type: "tuple",
|
|
7087
|
+
items,
|
|
7088
|
+
rest,
|
|
7089
|
+
...normalizeParams(params)
|
|
7090
|
+
});
|
|
7091
|
+
}
|
|
6492
7092
|
var ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
6493
7093
|
$ZodEnum.init(inst, def);
|
|
6494
7094
|
ZodType.init(inst, def);
|
|
@@ -6535,6 +7135,27 @@ function _enum(values, params) {
|
|
|
6535
7135
|
...normalizeParams(params)
|
|
6536
7136
|
});
|
|
6537
7137
|
}
|
|
7138
|
+
var ZodLiteral = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
|
|
7139
|
+
$ZodLiteral.init(inst, def);
|
|
7140
|
+
ZodType.init(inst, def);
|
|
7141
|
+
inst._zod.processJSONSchema = (ctx, json, params) => literalProcessor(inst, ctx, json, params);
|
|
7142
|
+
inst.values = new Set(def.values);
|
|
7143
|
+
Object.defineProperty(inst, "value", {
|
|
7144
|
+
get() {
|
|
7145
|
+
if (def.values.length > 1) {
|
|
7146
|
+
throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
|
|
7147
|
+
}
|
|
7148
|
+
return def.values[0];
|
|
7149
|
+
}
|
|
7150
|
+
});
|
|
7151
|
+
});
|
|
7152
|
+
function literal(value, params) {
|
|
7153
|
+
return new ZodLiteral({
|
|
7154
|
+
type: "literal",
|
|
7155
|
+
values: Array.isArray(value) ? value : [value],
|
|
7156
|
+
...normalizeParams(params)
|
|
7157
|
+
});
|
|
7158
|
+
}
|
|
6538
7159
|
var ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
|
|
6539
7160
|
_ensureDefaultMemoizer();
|
|
6540
7161
|
$ZodTransform.init(inst, def);
|
|
@@ -6707,63 +7328,63 @@ function superRefine(fn, params) {
|
|
|
6707
7328
|
return _superRefine(fn, params);
|
|
6708
7329
|
}
|
|
6709
7330
|
|
|
6710
|
-
// src/contract/Jurisdiction-
|
|
7331
|
+
// src/contract/Jurisdiction-LWQvqyxL.js
|
|
6711
7332
|
var JURISDICTIONS = {
|
|
6712
7333
|
global: {
|
|
6713
7334
|
name: "Global",
|
|
6714
7335
|
ageCheckStandard: "any",
|
|
6715
|
-
|
|
7336
|
+
optional: false
|
|
6716
7337
|
},
|
|
6717
7338
|
DE: {
|
|
6718
7339
|
name: "Germany",
|
|
6719
7340
|
ageCheckStandard: "any",
|
|
6720
|
-
|
|
7341
|
+
optional: false
|
|
6721
7342
|
},
|
|
6722
7343
|
AT: {
|
|
6723
7344
|
name: "Austria",
|
|
6724
7345
|
ageCheckStandard: "any",
|
|
6725
|
-
|
|
7346
|
+
optional: false
|
|
6726
7347
|
},
|
|
6727
7348
|
FR: {
|
|
6728
7349
|
name: "France",
|
|
6729
7350
|
ageCheckStandard: "any",
|
|
6730
|
-
|
|
7351
|
+
optional: false
|
|
6731
7352
|
},
|
|
6732
7353
|
GB: {
|
|
6733
7354
|
name: "United Kingdom",
|
|
6734
7355
|
ageCheckStandard: "verified",
|
|
6735
|
-
|
|
7356
|
+
optional: false
|
|
6736
7357
|
},
|
|
6737
7358
|
EU: {
|
|
6738
7359
|
name: "European Union",
|
|
6739
7360
|
ageCheckStandard: "verified",
|
|
6740
|
-
|
|
7361
|
+
optional: true
|
|
6741
7362
|
},
|
|
6742
7363
|
AU: {
|
|
6743
7364
|
name: "Australia",
|
|
6744
7365
|
ageCheckStandard: "verified",
|
|
6745
|
-
|
|
7366
|
+
optional: false
|
|
6746
7367
|
},
|
|
6747
7368
|
BR: {
|
|
6748
7369
|
name: "Brazil",
|
|
6749
7370
|
ageCheckStandard: "verified",
|
|
6750
|
-
|
|
7371
|
+
optional: false
|
|
6751
7372
|
}
|
|
6752
7373
|
};
|
|
6753
7374
|
var JURISDICTION_SCHEMA = _enum(Object.keys(JURISDICTIONS));
|
|
6754
|
-
Object.keys(JURISDICTIONS).filter((code) => !JURISDICTIONS[code].
|
|
6755
|
-
var
|
|
6756
|
-
_enum(
|
|
7375
|
+
Object.keys(JURISDICTIONS).filter((code) => !JURISDICTIONS[code].optional);
|
|
7376
|
+
var OPTIONAL_JURISDICTIONS = Object.keys(JURISDICTIONS).filter((code) => JURISDICTIONS[code].optional);
|
|
7377
|
+
_enum(OPTIONAL_JURISDICTIONS).array().refine((codes) => new Set(codes).size === codes.length, { message: "jurisdiction/duplicate" });
|
|
6757
7378
|
var SERVED_JURISDICTIONS_SCHEMA = JURISDICTION_SCHEMA.array().min(1).refine((regions) => regions.includes("global") && new Set(regions).size === regions.length, { message: "jurisdiction/global-required-or-duplicate" });
|
|
6758
7379
|
var COUNTRIES = new Set("AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW".split(" "));
|
|
6759
7380
|
var VIEWER_REGION_SCHEMA = _enum([...COUNTRIES]).describe("Viewer's ISO 3166-1 alpha-2 country, supplied by your integration; not the proxy server's country. EU is not a viewer country.");
|
|
6760
7381
|
var EU_COUNTRIES2 = new Set("AT BE BG HR CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE".split(" "));
|
|
6761
7382
|
var VIEWER_CLAIMS_SCHEMA = object({
|
|
6762
7383
|
region: VIEWER_REGION_SCHEMA.optional().describe("Viewer country. Defaults to the country of the connection reaching CalmLens; proxies should forward the viewer country explicitly."),
|
|
6763
|
-
ageConfirmed: boolean2().optional().describe("Your platform's confirmation that the viewer passed its age check, so age-restricted content may be delivered. Defaults to false. Your platform confirms the viewer's age; CalmLens does not verify this claim. Anyone requesting
|
|
7384
|
+
ageConfirmed: boolean2().optional().describe("Your platform's confirmation that the viewer passed its age check, so age-restricted content may be delivered. Defaults to false. Your platform confirms the viewer's age; CalmLens does not verify this claim. Anyone requesting an asset's URL, public or signed, can set it: a signed URL's signature does not cover viewer claims, so the claim is not an access control. To restrict who can load an age-restricted asset, make it private and issue signed URLs only to viewers who passed your age check.")
|
|
6764
7385
|
}).strict();
|
|
6765
7386
|
|
|
6766
|
-
// src/contract/TestRegionalActions-
|
|
7387
|
+
// src/contract/TestRegionalActions-C2mw3ntb.js
|
|
6767
7388
|
var msg = (text) => text;
|
|
6768
7389
|
var MODERATION_QUALIFIER_INFO = {
|
|
6769
7390
|
"sexual-pornographic-media": {
|
|
@@ -7060,6 +7681,24 @@ var MODERATION_QUALIFIER_INFO = {
|
|
|
7060
7681
|
description: msg("Pornographic content showing or describing sex with an animal or with a dead body, or a sexual act that threatens a person's life or is likely to cause serious injury to the anus, breasts or genitals, including realistic drawn or generated depictions."),
|
|
7061
7682
|
exclusions: "Consensual adult content without such an act, including bondage, role play or rough play; non-sexual images of animals, death or injury; reports, education, support or discussion that present no such material."
|
|
7062
7683
|
},
|
|
7684
|
+
"sexual-strangulation": {
|
|
7685
|
+
category: "sexual",
|
|
7686
|
+
kind: "harm",
|
|
7687
|
+
harmOption: false,
|
|
7688
|
+
displayName: msg("Pornographic strangulation or suffocation"),
|
|
7689
|
+
description: msg("A pornographic image or video frame showing a person strangling, choking or suffocating another: pressure on the neck from a hand, arm or ligature, or breathing blocked by covering the mouth and nose, smothering or compressing the chest. Realistic staged, generated or computer-made depictions count."),
|
|
7690
|
+
exclusions: "A person alone in the image holding their own throat or miming being choked; a hand resting on the shoulder, jaw or chest without gripping the throat; collars and choker jewellery; oral sex, including gagging, without breathing deliberately held off; non-sexual violence, combat sport or medical images; drawings or animation that don't look real; reports, education or support that show no such image.",
|
|
7691
|
+
inputs: ["image"]
|
|
7692
|
+
},
|
|
7693
|
+
"sexual-incest": {
|
|
7694
|
+
category: "sexual",
|
|
7695
|
+
kind: "harm",
|
|
7696
|
+
harmOption: false,
|
|
7697
|
+
displayName: msg("Pornographic incest"),
|
|
7698
|
+
description: msg("A pornographic image or video frame showing sexual activity between people who are, or are presented as, related as parent, grandparent, child, grandchild, brother, sister, half-brother, half-sister, uncle, aunt, nephew or niece, including by adoption. The relationship can be shown by the image or by its caption, title, dialogue or other accompanying text. Realistic staged, generated or computer-made depictions count."),
|
|
7699
|
+
exclusions: "Step, foster and in-law relationships between adults; a family word that is plainly a nickname or fanciful, such as daddy between adult partners; drawings or animation that don't look real; non-sexual family images; reports or discussion that show no such image. Someone presented as under 18 is Sexualised minors.",
|
|
7700
|
+
inputs: ["image"]
|
|
7701
|
+
},
|
|
7063
7702
|
"sexual-minors": {
|
|
7064
7703
|
category: "sexual",
|
|
7065
7704
|
kind: "harm",
|
|
@@ -7763,7 +8402,7 @@ var TEST_REGIONAL_ACTIONS_SCHEMA = array(object({
|
|
|
7763
8402
|
])
|
|
7764
8403
|
}).strict()).max(7).refine((entries) => new Set(entries.map((entry) => entry.region)).size === entries.length, "Choose each region once");
|
|
7765
8404
|
|
|
7766
|
-
// src/contract/TestTriggers-
|
|
8405
|
+
// src/contract/TestTriggers-D29T_R0M.js
|
|
7767
8406
|
var TEST_IMAGE_GRID_LEVELS = [
|
|
7768
8407
|
72,
|
|
7769
8408
|
128,
|
|
@@ -7828,6 +8467,32 @@ function testInputForSignal(signal, kind = "text") {
|
|
|
7828
8467
|
}] });
|
|
7829
8468
|
}
|
|
7830
8469
|
}
|
|
8470
|
+
var TEST_DETECTION_BOX_MAX = 1e4;
|
|
8471
|
+
var basisPoints = number2().int().min(0).max(TEST_DETECTION_BOX_MAX);
|
|
8472
|
+
var detectionShape = {
|
|
8473
|
+
box: tuple([
|
|
8474
|
+
basisPoints,
|
|
8475
|
+
basisPoints,
|
|
8476
|
+
basisPoints,
|
|
8477
|
+
basisPoints
|
|
8478
|
+
]),
|
|
8479
|
+
confidence: number2().int().min(0).max(100).optional()
|
|
8480
|
+
};
|
|
8481
|
+
var fitsImage = ({ box: [left, top, width, height] }) => left + width <= 1e4 && top + height <= 1e4;
|
|
8482
|
+
var BOX_MESSAGE = msg("A box must lie inside the image: left + width and top + height are at most 10000.");
|
|
8483
|
+
var ageYears = number2().int().min(0).max(120);
|
|
8484
|
+
var TEST_DETECTED_PERSON_SCHEMA = object(detectionShape).strict().refine(fitsImage, BOX_MESSAGE);
|
|
8485
|
+
var TEST_DETECTED_FACE_SCHEMA = object({
|
|
8486
|
+
...detectionShape,
|
|
8487
|
+
age: union([_enum(["adult", "minor"]), object({
|
|
8488
|
+
low: ageYears,
|
|
8489
|
+
high: ageYears
|
|
8490
|
+
}).strict().refine(({ low, high }) => low <= high, msg("An age range's low must not be above its high."))]).optional()
|
|
8491
|
+
}).strict().refine(fitsImage, BOX_MESSAGE);
|
|
8492
|
+
var TEST_DETECTIONS_SCHEMA = object({
|
|
8493
|
+
people: union([array(TEST_DETECTED_PERSON_SCHEMA).max(32), literal("unavailable")]).optional(),
|
|
8494
|
+
faces: union([array(TEST_DETECTED_FACE_SCHEMA).max(32), literal("unavailable")]).optional()
|
|
8495
|
+
}).strict();
|
|
7831
8496
|
var TEST_INPUT_SCHEMA = object({
|
|
7832
8497
|
regionalActions: TEST_REGIONAL_ACTIONS_SCHEMA.optional(),
|
|
7833
8498
|
unassessedCategories: array(_enum(CLASSIFICATION_CATEGORIES)).max(CLASSIFICATION_CATEGORIES.length).optional(),
|
|
@@ -7847,7 +8512,8 @@ var TEST_INPUT_SCHEMA = object({
|
|
|
7847
8512
|
code: "custom",
|
|
7848
8513
|
message: "Choose unique content qualifiers from this category; input-type facts are automatic."
|
|
7849
8514
|
});
|
|
7850
|
-
})).max(128)
|
|
8515
|
+
})).max(128),
|
|
8516
|
+
detections: TEST_DETECTIONS_SCHEMA.optional()
|
|
7851
8517
|
}).strict().superRefine((scenario, context) => {
|
|
7852
8518
|
if (scenario.instances.some((instance) => instance.action !== undefined) && scenario.instances.some((instance) => instance.action === undefined))
|
|
7853
8519
|
context.addIssue({
|
|
@@ -7902,21 +8568,428 @@ var TEST_INPUT_PRESETS = {
|
|
|
7902
8568
|
}, {
|
|
7903
8569
|
category: "harassment",
|
|
7904
8570
|
qualifiers: ["harassment-threat"]
|
|
7905
|
-
}] }
|
|
8571
|
+
}] },
|
|
8572
|
+
oneFace: {
|
|
8573
|
+
instances: [],
|
|
8574
|
+
detections: {
|
|
8575
|
+
people: [{ box: [
|
|
8576
|
+
2500,
|
|
8577
|
+
1500,
|
|
8578
|
+
5000,
|
|
8579
|
+
8500
|
|
8580
|
+
] }],
|
|
8581
|
+
faces: [{ box: [
|
|
8582
|
+
3500,
|
|
8583
|
+
2000,
|
|
8584
|
+
3000,
|
|
8585
|
+
3500
|
|
8586
|
+
] }]
|
|
8587
|
+
}
|
|
8588
|
+
},
|
|
8589
|
+
noFace: {
|
|
8590
|
+
instances: [],
|
|
8591
|
+
detections: {
|
|
8592
|
+
people: [],
|
|
8593
|
+
faces: []
|
|
8594
|
+
}
|
|
8595
|
+
},
|
|
8596
|
+
adultFace: {
|
|
8597
|
+
instances: [],
|
|
8598
|
+
detections: {
|
|
8599
|
+
people: [{ box: [
|
|
8600
|
+
2500,
|
|
8601
|
+
1500,
|
|
8602
|
+
5000,
|
|
8603
|
+
8500
|
|
8604
|
+
] }],
|
|
8605
|
+
faces: [{
|
|
8606
|
+
box: [
|
|
8607
|
+
3500,
|
|
8608
|
+
2000,
|
|
8609
|
+
3000,
|
|
8610
|
+
3500
|
|
8611
|
+
],
|
|
8612
|
+
age: "adult"
|
|
8613
|
+
}]
|
|
8614
|
+
}
|
|
8615
|
+
},
|
|
8616
|
+
minorFace: {
|
|
8617
|
+
instances: [],
|
|
8618
|
+
detections: {
|
|
8619
|
+
people: [{ box: [
|
|
8620
|
+
2500,
|
|
8621
|
+
1500,
|
|
8622
|
+
5000,
|
|
8623
|
+
8500
|
|
8624
|
+
] }],
|
|
8625
|
+
faces: [{
|
|
8626
|
+
box: [
|
|
8627
|
+
3500,
|
|
8628
|
+
2000,
|
|
8629
|
+
3000,
|
|
8630
|
+
3500
|
|
8631
|
+
],
|
|
8632
|
+
age: "minor"
|
|
8633
|
+
}]
|
|
8634
|
+
}
|
|
8635
|
+
},
|
|
8636
|
+
group: {
|
|
8637
|
+
instances: [],
|
|
8638
|
+
detections: {
|
|
8639
|
+
people: [
|
|
8640
|
+
{ box: [
|
|
8641
|
+
500,
|
|
8642
|
+
2000,
|
|
8643
|
+
2800,
|
|
8644
|
+
8000
|
|
8645
|
+
] },
|
|
8646
|
+
{ box: [
|
|
8647
|
+
3600,
|
|
8648
|
+
2000,
|
|
8649
|
+
2800,
|
|
8650
|
+
8000
|
|
8651
|
+
] },
|
|
8652
|
+
{ box: [
|
|
8653
|
+
6700,
|
|
8654
|
+
2000,
|
|
8655
|
+
2800,
|
|
8656
|
+
8000
|
|
8657
|
+
] }
|
|
8658
|
+
],
|
|
8659
|
+
faces: [
|
|
8660
|
+
{ box: [
|
|
8661
|
+
1200,
|
|
8662
|
+
2500,
|
|
8663
|
+
1400,
|
|
8664
|
+
2000
|
|
8665
|
+
] },
|
|
8666
|
+
{ box: [
|
|
8667
|
+
4300,
|
|
8668
|
+
2500,
|
|
8669
|
+
1400,
|
|
8670
|
+
2000
|
|
8671
|
+
] },
|
|
8672
|
+
{ box: [
|
|
8673
|
+
7400,
|
|
8674
|
+
2500,
|
|
8675
|
+
1400,
|
|
8676
|
+
2000
|
|
8677
|
+
] }
|
|
8678
|
+
]
|
|
8679
|
+
}
|
|
8680
|
+
}
|
|
7906
8681
|
};
|
|
7907
|
-
var tag = async (payload, key) => (await hmacSha256Hex(key, `calmlens-test:
|
|
8682
|
+
var tag = async (payload, key) => (await hmacSha256Hex(key, `calmlens-test:v2:${payload}`)).slice(0, 32);
|
|
8683
|
+
var toBase64Url2 = (bytes) => btoa(String.fromCharCode(...bytes)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
8684
|
+
var envelope = (scenario) => new TextEncoder().encode(JSON.stringify(TEST_INPUT_SCHEMA.parse(scenario)));
|
|
7908
8685
|
async function generateTestTextCode(scenario, key) {
|
|
7909
8686
|
if (!/^[a-f0-9]{32}$/.test(key))
|
|
7910
8687
|
throw new TypeError("Invalid test input key");
|
|
7911
|
-
const payload =
|
|
8688
|
+
const payload = toBase64Url2(envelope(typeof scenario === "string" ? testInputForSignal(scenario) : scenario));
|
|
7912
8689
|
if (payload.length > 8000)
|
|
7913
8690
|
throw new RangeError("Test scenario is too large");
|
|
7914
8691
|
return `<!calmlens-test ${await tag(payload, key)} ${payload}>`;
|
|
7915
8692
|
}
|
|
8693
|
+
// src/cli/configuration.ts
|
|
8694
|
+
class ConfigurationError extends Error {
|
|
8695
|
+
}
|
|
8696
|
+
var SECTIONS = ["policies", "policy", "uploadPresets", "lenses", "metadataFields", "settings"];
|
|
8697
|
+
var isObject2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
8698
|
+
var parseConfiguration = (text, source = "calmlens.config.json") => {
|
|
8699
|
+
let value;
|
|
8700
|
+
try {
|
|
8701
|
+
value = JSON.parse(text);
|
|
8702
|
+
} catch (error) {
|
|
8703
|
+
throw new ConfigurationError(`${source} isn't valid JSON: ${error.message}`);
|
|
8704
|
+
}
|
|
8705
|
+
if (!isObject2(value))
|
|
8706
|
+
throw new ConfigurationError(`${source} must hold a JSON object.`);
|
|
8707
|
+
for (const key of Object.keys(value))
|
|
8708
|
+
if (key !== "$schema" && !SECTIONS.includes(key))
|
|
8709
|
+
throw new ConfigurationError(`${source} has an unknown section "${key}". Use ${SECTIONS.join(", ")}.`);
|
|
8710
|
+
for (const section of ["policies", "uploadPresets", "lenses", "metadataFields", "settings"]) {
|
|
8711
|
+
if (value[section] === undefined)
|
|
8712
|
+
continue;
|
|
8713
|
+
if (!isObject2(value[section]))
|
|
8714
|
+
throw new ConfigurationError(`${source}: "${section}" must be an object.`);
|
|
8715
|
+
if (section === "settings")
|
|
8716
|
+
continue;
|
|
8717
|
+
for (const [name, item] of Object.entries(value[section]))
|
|
8718
|
+
if (!isObject2(item))
|
|
8719
|
+
throw new ConfigurationError(`${source}: ${section} "${name}" must be an object.`);
|
|
8720
|
+
}
|
|
8721
|
+
if (value.policy !== undefined && typeof value.policy !== "string")
|
|
8722
|
+
throw new ConfigurationError(`${source}: "policy" must be a policy name.`);
|
|
8723
|
+
const config = value;
|
|
8724
|
+
for (const [name, policy] of Object.entries(config.policies ?? {}))
|
|
8725
|
+
if (!policy.presetId && !policy.settings)
|
|
8726
|
+
throw new ConfigurationError(`${source}: policy "${name}" needs "presetId", "settings" or both.`);
|
|
8727
|
+
return config;
|
|
8728
|
+
};
|
|
8729
|
+
var collect = async (items) => {
|
|
8730
|
+
const all = [];
|
|
8731
|
+
for await (const item of items)
|
|
8732
|
+
all.push(item);
|
|
8733
|
+
return all;
|
|
8734
|
+
};
|
|
8735
|
+
var readConfigurationState = async (client, config) => {
|
|
8736
|
+
const presetsNamePolicies = Object.values(config.uploadPresets ?? {}).some((preset) => preset.policy !== undefined);
|
|
8737
|
+
const [policies, assignedPolicy, uploadPresets, lenses, metadataFields, settings] = await Promise.all([
|
|
8738
|
+
config.policies || config.policy !== undefined || presetsNamePolicies ? collect(client.policies.iterate()) : [],
|
|
8739
|
+
config.policy !== undefined ? client.policies.retrieveAssigned() : undefined,
|
|
8740
|
+
config.uploadPresets ? collect(client.uploadPresets.iterate()) : [],
|
|
8741
|
+
config.lenses ? collect(client.lenses.iterate()) : [],
|
|
8742
|
+
config.metadataFields ? client.metadataFields.list() : undefined,
|
|
8743
|
+
config.settings ? client.projectSettings.get() : undefined
|
|
8744
|
+
]);
|
|
8745
|
+
return {
|
|
8746
|
+
policies,
|
|
8747
|
+
assignedPolicy,
|
|
8748
|
+
uploadPresets,
|
|
8749
|
+
lenses,
|
|
8750
|
+
metadataFields: metadataFields?.fields ?? [],
|
|
8751
|
+
settings: settings?.settings,
|
|
8752
|
+
settingsRevision: settings?.revision ?? metadataFields?.revision
|
|
8753
|
+
};
|
|
8754
|
+
};
|
|
8755
|
+
var canonical = (value) => JSON.stringify(value ?? null, (_key, item) => isObject2(item) ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : item);
|
|
8756
|
+
var same = (a, b) => canonical(a) === canonical(b);
|
|
8757
|
+
var LABELS = {
|
|
8758
|
+
policy: "policy",
|
|
8759
|
+
assignment: "project policy",
|
|
8760
|
+
metadataField: "metadata field",
|
|
8761
|
+
settings: "project settings",
|
|
8762
|
+
lens: "lens",
|
|
8763
|
+
uploadPreset: "upload preset"
|
|
8764
|
+
};
|
|
8765
|
+
var presetValues = (definition) => {
|
|
8766
|
+
const list = (value) => value?.length ? [...new Set(value)] : null;
|
|
8767
|
+
return {
|
|
8768
|
+
key: definition.key,
|
|
8769
|
+
name: definition.name,
|
|
8770
|
+
access: definition.access ?? "token",
|
|
8771
|
+
enabled: definition.enabled ?? true,
|
|
8772
|
+
allowedContentTypes: list(definition.allowedContentTypes),
|
|
8773
|
+
maxSizeInBytes: definition.maxSizeInBytes ?? null,
|
|
8774
|
+
folderId: definition.folderId ?? null,
|
|
8775
|
+
policyId: definition.policyId ?? null,
|
|
8776
|
+
visibility: definition.visibility ?? "private",
|
|
8777
|
+
processingOptions: definition.processingOptions ?? null,
|
|
8778
|
+
revealDecision: definition.revealDecision ?? false,
|
|
8779
|
+
dailyUploadLimit: definition.dailyUploadLimit ?? null,
|
|
8780
|
+
allowedOrigins: list(definition.allowedOrigins)
|
|
8781
|
+
};
|
|
8782
|
+
};
|
|
8783
|
+
var lensValues = (identifier, lens) => ({
|
|
8784
|
+
identifier,
|
|
8785
|
+
name: lens.name,
|
|
8786
|
+
description: lens.description ?? null,
|
|
8787
|
+
type: lens.type ?? "image",
|
|
8788
|
+
active: lens.active ?? true,
|
|
8789
|
+
transform: lens.transform ?? null
|
|
8790
|
+
});
|
|
8791
|
+
var changedFields = (desired, current) => Object.keys(desired).filter((key) => !same(desired[key], current[key]));
|
|
8792
|
+
var policyNamed = (state, name) => {
|
|
8793
|
+
const matches = state.policies.filter((policy) => policy.name === name);
|
|
8794
|
+
if (matches.length > 1)
|
|
8795
|
+
throw new ConfigurationError(`The organisation has ${matches.length} policies named "${name}". Rename all but one in the portal.`);
|
|
8796
|
+
return matches[0];
|
|
8797
|
+
};
|
|
8798
|
+
var planConfiguration = (config, state, options = {}) => {
|
|
8799
|
+
const changes = [];
|
|
8800
|
+
let unchanged = 0;
|
|
8801
|
+
const update = (kind, name, fields) => {
|
|
8802
|
+
if (fields.length)
|
|
8803
|
+
changes.push({ kind, action: "update", name, fields });
|
|
8804
|
+
else
|
|
8805
|
+
unchanged++;
|
|
8806
|
+
};
|
|
8807
|
+
const knownPolicy = (name) => {
|
|
8808
|
+
if (!config.policies?.[name] && !policyNamed(state, name))
|
|
8809
|
+
throw new ConfigurationError(`No policy is named "${name}": add it under "policies" or create it in the portal.`);
|
|
8810
|
+
};
|
|
8811
|
+
const prune = (kind, held, listed) => {
|
|
8812
|
+
if (options.prune) {
|
|
8813
|
+
for (const name of held)
|
|
8814
|
+
if (!(name in listed))
|
|
8815
|
+
changes.push({ kind, action: "delete", name });
|
|
8816
|
+
}
|
|
8817
|
+
};
|
|
8818
|
+
for (const [name, definition] of Object.entries(config.policies ?? {})) {
|
|
8819
|
+
const existing = policyNamed(state, name);
|
|
8820
|
+
if (!existing)
|
|
8821
|
+
changes.push({ kind: "policy", action: "create", name });
|
|
8822
|
+
else
|
|
8823
|
+
update("policy", name, [
|
|
8824
|
+
...definition.description !== undefined && definition.description !== existing.description ? ["description"] : [],
|
|
8825
|
+
...definition.settings && !same(definition.settings, existing.settings) ? ["settings"] : []
|
|
8826
|
+
]);
|
|
8827
|
+
}
|
|
8828
|
+
if (config.policy !== undefined) {
|
|
8829
|
+
knownPolicy(config.policy);
|
|
8830
|
+
if (policyNamed(state, config.policy)?.id === state.assignedPolicy?.id)
|
|
8831
|
+
unchanged++;
|
|
8832
|
+
else
|
|
8833
|
+
changes.push({ kind: "assignment", action: "update", name: config.policy });
|
|
8834
|
+
}
|
|
8835
|
+
if (config.metadataFields) {
|
|
8836
|
+
const current = new Map(state.metadataFields.map((field) => [field.id, field]));
|
|
8837
|
+
for (const [id, field] of Object.entries(config.metadataFields)) {
|
|
8838
|
+
const existing = current.get(id);
|
|
8839
|
+
if (!existing)
|
|
8840
|
+
changes.push({ kind: "metadataField", action: "create", name: id });
|
|
8841
|
+
else
|
|
8842
|
+
update("metadataField", id, changedFields({ id, ...field }, existing));
|
|
8843
|
+
}
|
|
8844
|
+
prune("metadataField", [...current.keys()], config.metadataFields);
|
|
8845
|
+
}
|
|
8846
|
+
if (config.settings)
|
|
8847
|
+
update("settings", "settings", changedFields(config.settings, state.settings ?? {}));
|
|
8848
|
+
if (config.lenses) {
|
|
8849
|
+
const current = new Map(state.lenses.map((lens) => [lens.identifier, lens]));
|
|
8850
|
+
for (const [identifier, lens] of Object.entries(config.lenses)) {
|
|
8851
|
+
const existing = current.get(identifier);
|
|
8852
|
+
if (!existing)
|
|
8853
|
+
changes.push({ kind: "lens", action: "create", name: identifier });
|
|
8854
|
+
else
|
|
8855
|
+
update("lens", identifier, changedFields(lensValues(identifier, lens), existing));
|
|
8856
|
+
}
|
|
8857
|
+
prune("lens", [...current.keys()], config.lenses);
|
|
8858
|
+
}
|
|
8859
|
+
if (config.uploadPresets) {
|
|
8860
|
+
const current = new Map(state.uploadPresets.map((preset) => [preset.key, preset]));
|
|
8861
|
+
for (const [key, { policy, ...preset }] of Object.entries(config.uploadPresets)) {
|
|
8862
|
+
if (policy !== undefined)
|
|
8863
|
+
knownPolicy(policy);
|
|
8864
|
+
const existing = current.get(key);
|
|
8865
|
+
if (!existing) {
|
|
8866
|
+
changes.push({ kind: "uploadPreset", action: "create", name: key });
|
|
8867
|
+
continue;
|
|
8868
|
+
}
|
|
8869
|
+
const policyId = policy === undefined ? null : policyNamed(state, policy)?.id ?? policy;
|
|
8870
|
+
update("uploadPreset", key, changedFields(presetValues({ ...preset, key, policyId }), existing).map((field) => field === "policyId" ? "policy" : field));
|
|
8871
|
+
}
|
|
8872
|
+
prune("uploadPreset", [...current.keys()], config.uploadPresets);
|
|
8873
|
+
}
|
|
8874
|
+
return { changes, unchanged };
|
|
8875
|
+
};
|
|
8876
|
+
var formatPlan = (plan) => {
|
|
8877
|
+
const items = (count) => `${count} item${count === 1 ? "" : "s"}`;
|
|
8878
|
+
if (!plan.changes.length)
|
|
8879
|
+
return `No changes: ${items(plan.unchanged)} already match the file.
|
|
8880
|
+
`;
|
|
8881
|
+
const symbol = { create: "+", update: "~", delete: "-" };
|
|
8882
|
+
const lines = plan.changes.map((change) => {
|
|
8883
|
+
const subject = change.kind === "settings" ? LABELS.settings : `${LABELS[change.kind]} "${change.name}"`;
|
|
8884
|
+
const fields = change.fields?.length ? ` (${change.fields.join(", ")})` : "";
|
|
8885
|
+
return ` ${symbol[change.action]} ${subject}${fields}`;
|
|
8886
|
+
});
|
|
8887
|
+
const count = (action) => plan.changes.filter((change) => change.action === action).length;
|
|
8888
|
+
return `${lines.join(`
|
|
8889
|
+
`)}
|
|
8890
|
+
|
|
8891
|
+
${count("create")} to create, ${count("update")} to update, ${count("delete")} to delete, ${plan.unchanged} unchanged.
|
|
8892
|
+
`;
|
|
8893
|
+
};
|
|
8894
|
+
var applyConfiguration = async (client, config, state, plan, log = () => {}) => {
|
|
8895
|
+
const changes = (kind, deletes = false) => plan.changes.filter((change) => change.kind === kind && change.action === "delete" === deletes);
|
|
8896
|
+
const plural = (count, noun, many = `${noun}s`) => `${count} ${count === 1 ? noun : many}`;
|
|
8897
|
+
const policyIds = new Map(state.policies.map((policy) => [policy.name, policy.id]));
|
|
8898
|
+
const policyIdOf = (name) => policyIds.get(name);
|
|
8899
|
+
for (const change of changes("policy")) {
|
|
8900
|
+
const { presetId, settings, description } = config.policies[change.name];
|
|
8901
|
+
const existing = state.policies.find((policy) => policy.name === change.name);
|
|
8902
|
+
if (existing) {
|
|
8903
|
+
await client.policies.update({
|
|
8904
|
+
policyId: existing.id,
|
|
8905
|
+
revision: existing.revision,
|
|
8906
|
+
...description !== undefined && { description },
|
|
8907
|
+
...settings && { settings }
|
|
8908
|
+
});
|
|
8909
|
+
log(`Updated policy "${change.name}".`);
|
|
8910
|
+
continue;
|
|
8911
|
+
}
|
|
8912
|
+
const created = await client.policies.create({
|
|
8913
|
+
name: change.name,
|
|
8914
|
+
...description !== undefined && { description },
|
|
8915
|
+
...presetId ? { presetId } : { settings }
|
|
8916
|
+
});
|
|
8917
|
+
policyIds.set(change.name, created.id);
|
|
8918
|
+
if (presetId && settings)
|
|
8919
|
+
await client.policies.update({
|
|
8920
|
+
policyId: created.id,
|
|
8921
|
+
revision: created.revision,
|
|
8922
|
+
settings
|
|
8923
|
+
});
|
|
8924
|
+
log(`Created policy "${change.name}".`);
|
|
8925
|
+
}
|
|
8926
|
+
for (const change of changes("assignment")) {
|
|
8927
|
+
await client.policies.assign({ policyId: policyIdOf(change.name) });
|
|
8928
|
+
log(`The project now moderates with policy "${change.name}".`);
|
|
8929
|
+
}
|
|
8930
|
+
let revision = state.settingsRevision;
|
|
8931
|
+
const fields = changes("metadataField");
|
|
8932
|
+
if (fields.length) {
|
|
8933
|
+
({ revision } = await client.metadataFields.ensure({
|
|
8934
|
+
revision,
|
|
8935
|
+
fields: fields.map((change) => ({
|
|
8936
|
+
id: change.name,
|
|
8937
|
+
...config.metadataFields[change.name]
|
|
8938
|
+
}))
|
|
8939
|
+
}));
|
|
8940
|
+
log(`Saved ${plural(fields.length, "metadata field")}.`);
|
|
8941
|
+
}
|
|
8942
|
+
for (const change of changes("metadataField", true)) {
|
|
8943
|
+
await client.metadataFields.delete({ fieldId: change.name, revision });
|
|
8944
|
+
({ revision } = await client.metadataFields.list());
|
|
8945
|
+
log(`Deleted metadata field "${change.name}".`);
|
|
8946
|
+
}
|
|
8947
|
+
if (changes("settings").length) {
|
|
8948
|
+
await client.projectSettings.update({
|
|
8949
|
+
revision,
|
|
8950
|
+
settings: { ...state.settings, ...config.settings }
|
|
8951
|
+
});
|
|
8952
|
+
log("Saved the project settings.");
|
|
8953
|
+
}
|
|
8954
|
+
const lenses = changes("lens");
|
|
8955
|
+
if (lenses.length) {
|
|
8956
|
+
await client.ensureLenses({
|
|
8957
|
+
lenses: lenses.map((change) => lensValues(change.name, config.lenses[change.name]))
|
|
8958
|
+
});
|
|
8959
|
+
log(`Saved ${plural(lenses.length, "lens", "lenses")}.`);
|
|
8960
|
+
}
|
|
8961
|
+
for (const change of changes("lens", true)) {
|
|
8962
|
+
const lens = state.lenses.find((candidate) => candidate.identifier === change.name);
|
|
8963
|
+
await client.lenses.delete({ lensId: lens.id });
|
|
8964
|
+
log(`Deleted lens "${change.name}".`);
|
|
8965
|
+
}
|
|
8966
|
+
const presets = changes("uploadPreset");
|
|
8967
|
+
if (presets.length) {
|
|
8968
|
+
await client.uploadPresets.ensure({
|
|
8969
|
+
uploadPresets: presets.map((change) => {
|
|
8970
|
+
const { policy, ...preset } = config.uploadPresets[change.name];
|
|
8971
|
+
const existing = state.uploadPresets.find((candidate) => candidate.key === change.name);
|
|
8972
|
+
return {
|
|
8973
|
+
...preset,
|
|
8974
|
+
key: change.name,
|
|
8975
|
+
revision: existing?.revision ?? 0,
|
|
8976
|
+
policyId: policy === undefined ? null : policyIdOf(policy)
|
|
8977
|
+
};
|
|
8978
|
+
})
|
|
8979
|
+
});
|
|
8980
|
+
log(`Saved ${plural(presets.length, "upload preset")}.`);
|
|
8981
|
+
}
|
|
8982
|
+
for (const change of changes("uploadPreset", true)) {
|
|
8983
|
+
const preset = state.uploadPresets.find((candidate) => candidate.key === change.name);
|
|
8984
|
+
await client.uploadPresets.delete({ uploadPresetId: preset.id });
|
|
8985
|
+
log(`Deleted upload preset "${change.name}".`);
|
|
8986
|
+
}
|
|
8987
|
+
};
|
|
8988
|
+
|
|
7916
8989
|
// src/cli/listen.ts
|
|
7917
8990
|
import { randomBytes } from "node:crypto";
|
|
7918
8991
|
|
|
7919
|
-
// src/contract/Ids-
|
|
8992
|
+
// src/contract/Ids-BESMSxGb.js
|
|
7920
8993
|
var __defProp = Object.defineProperty;
|
|
7921
8994
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
|
|
7922
8995
|
var __exportAll = (all, no_symbols) => {
|
|
@@ -8067,7 +9140,7 @@ function slugify2(input) {
|
|
|
8067
9140
|
return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
8068
9141
|
}
|
|
8069
9142
|
var captureStackTrace2 = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
|
|
8070
|
-
function
|
|
9143
|
+
function isObject3(data) {
|
|
8071
9144
|
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
8072
9145
|
}
|
|
8073
9146
|
var allowsEval2 = /* @__PURE__ */ cached2(() => {
|
|
@@ -8083,7 +9156,7 @@ var allowsEval2 = /* @__PURE__ */ cached2(() => {
|
|
|
8083
9156
|
}
|
|
8084
9157
|
});
|
|
8085
9158
|
function isPlainObject3(o) {
|
|
8086
|
-
if (
|
|
9159
|
+
if (isObject3(o) === false)
|
|
8087
9160
|
return false;
|
|
8088
9161
|
const ctor = o.constructor;
|
|
8089
9162
|
if (ctor === undefined)
|
|
@@ -8091,7 +9164,7 @@ function isPlainObject3(o) {
|
|
|
8091
9164
|
if (typeof ctor !== "function")
|
|
8092
9165
|
return true;
|
|
8093
9166
|
const prot = ctor.prototype;
|
|
8094
|
-
if (
|
|
9167
|
+
if (isObject3(prot) === false)
|
|
8095
9168
|
return false;
|
|
8096
9169
|
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false)
|
|
8097
9170
|
return false;
|
|
@@ -10605,7 +11678,7 @@ var $ZodObject2 = /* @__PURE__ */ $constructor2("$ZodObject", (inst, def) => {
|
|
|
10605
11678
|
}
|
|
10606
11679
|
return propValues;
|
|
10607
11680
|
});
|
|
10608
|
-
const isObject$1 =
|
|
11681
|
+
const isObject$1 = isObject3;
|
|
10609
11682
|
const catchall = def.catchall;
|
|
10610
11683
|
let value;
|
|
10611
11684
|
const memo = globalConfig2.memoizer;
|
|
@@ -10753,7 +11826,7 @@ var $ZodObjectJIT2 = /* @__PURE__ */ $constructor2("$ZodObjectJIT", (inst, def)
|
|
|
10753
11826
|
return doc.compile();
|
|
10754
11827
|
};
|
|
10755
11828
|
let fastpass;
|
|
10756
|
-
const isObject$2 =
|
|
11829
|
+
const isObject$2 = isObject3;
|
|
10757
11830
|
const jit = !globalConfig2.jitless;
|
|
10758
11831
|
const fastEnabled = jit && allowsEval2.value;
|
|
10759
11832
|
const catchall = def.catchall;
|
|
@@ -10943,7 +12016,7 @@ var $ZodDiscriminatedUnion2 = /* @__PURE__ */ $constructor2("$ZodDiscriminatedUn
|
|
|
10943
12016
|
const disc = cached2(() => discriminatorMap(def));
|
|
10944
12017
|
inst._zod.parse = (payload, ctx) => {
|
|
10945
12018
|
const input = payload.value;
|
|
10946
|
-
if (!
|
|
12019
|
+
if (!isObject3(input)) {
|
|
10947
12020
|
payload.issues.push({
|
|
10948
12021
|
code: "invalid_type",
|
|
10949
12022
|
expected: "object",
|
|
@@ -11122,8 +12195,8 @@ var $ZodTuple2 = /* @__PURE__ */ $constructor2("$ZodTuple", (inst, def) => {
|
|
|
11122
12195
|
}
|
|
11123
12196
|
payload.value = memo ? memo.alloc(inst, payload, [], ctx) : [];
|
|
11124
12197
|
const proms = [];
|
|
11125
|
-
const optinStart =
|
|
11126
|
-
const optoutStart =
|
|
12198
|
+
const optinStart = getTupleOptStart2(items, "optin");
|
|
12199
|
+
const optoutStart = getTupleOptStart2(items, "optout");
|
|
11127
12200
|
if (!def.rest) {
|
|
11128
12201
|
if (input.length < optinStart) {
|
|
11129
12202
|
payload.issues.push({
|
|
@@ -11180,28 +12253,28 @@ var $ZodTuple2 = /* @__PURE__ */ $constructor2("$ZodTuple", (inst, def) => {
|
|
|
11180
12253
|
issues: []
|
|
11181
12254
|
}, ctx);
|
|
11182
12255
|
if (result instanceof Promise)
|
|
11183
|
-
proms.push(result.then((r) =>
|
|
12256
|
+
proms.push(result.then((r) => handleTupleResult2(r, payload, i)));
|
|
11184
12257
|
else
|
|
11185
|
-
|
|
12258
|
+
handleTupleResult2(result, payload, i);
|
|
11186
12259
|
}
|
|
11187
12260
|
}
|
|
11188
12261
|
if (proms.length)
|
|
11189
|
-
return Promise.all(proms).then(() =>
|
|
11190
|
-
return
|
|
12262
|
+
return Promise.all(proms).then(() => handleTupleResults2(itemResults, payload, items, input, optoutStart));
|
|
12263
|
+
return handleTupleResults2(itemResults, payload, items, input, optoutStart);
|
|
11191
12264
|
};
|
|
11192
12265
|
});
|
|
11193
|
-
function
|
|
12266
|
+
function getTupleOptStart2(items, key) {
|
|
11194
12267
|
for (let i = items.length - 1;i >= 0; i--)
|
|
11195
12268
|
if (!(key === "optin" ? items[i]._zod.optin !== undefined : items[i]._zod.optout === "optional"))
|
|
11196
12269
|
return i + 1;
|
|
11197
12270
|
return 0;
|
|
11198
12271
|
}
|
|
11199
|
-
function
|
|
12272
|
+
function handleTupleResult2(result, final, index) {
|
|
11200
12273
|
if (result.issues.length)
|
|
11201
12274
|
final.issues.push(...prefixIssues2(index, result.issues));
|
|
11202
12275
|
final.value[index] = result.value;
|
|
11203
12276
|
}
|
|
11204
|
-
function
|
|
12277
|
+
function handleTupleResults2(itemResults, final, items, input, optoutStart) {
|
|
11205
12278
|
for (let i = 0;i < items.length; i++) {
|
|
11206
12279
|
const r = itemResults[i];
|
|
11207
12280
|
const isPresent = i < input.length;
|
|
@@ -14568,7 +15641,7 @@ var schemas_exports = /* @__PURE__ */ __exportAll({
|
|
|
14568
15641
|
ZodJWT: () => ZodJWT,
|
|
14569
15642
|
ZodKSUID: () => ZodKSUID,
|
|
14570
15643
|
ZodLazy: () => ZodLazy,
|
|
14571
|
-
ZodLiteral: () =>
|
|
15644
|
+
ZodLiteral: () => ZodLiteral2,
|
|
14572
15645
|
ZodMAC: () => ZodMAC,
|
|
14573
15646
|
ZodMap: () => ZodMap,
|
|
14574
15647
|
ZodNaN: () => ZodNaN,
|
|
@@ -14594,7 +15667,7 @@ var schemas_exports = /* @__PURE__ */ __exportAll({
|
|
|
14594
15667
|
ZodSymbol: () => ZodSymbol,
|
|
14595
15668
|
ZodTemplateLiteral: () => ZodTemplateLiteral,
|
|
14596
15669
|
ZodTransform: () => ZodTransform2,
|
|
14597
|
-
ZodTuple: () =>
|
|
15670
|
+
ZodTuple: () => ZodTuple2,
|
|
14598
15671
|
ZodType: () => ZodType2,
|
|
14599
15672
|
ZodULID: () => ZodULID,
|
|
14600
15673
|
ZodURL: () => ZodURL,
|
|
@@ -14655,7 +15728,7 @@ var schemas_exports = /* @__PURE__ */ __exportAll({
|
|
|
14655
15728
|
keyof: () => keyof,
|
|
14656
15729
|
ksuid: () => ksuid2,
|
|
14657
15730
|
lazy: () => lazy,
|
|
14658
|
-
literal: () =>
|
|
15731
|
+
literal: () => literal2,
|
|
14659
15732
|
looseObject: () => looseObject,
|
|
14660
15733
|
looseRecord: () => looseRecord,
|
|
14661
15734
|
mac: () => mac2,
|
|
@@ -14690,7 +15763,7 @@ var schemas_exports = /* @__PURE__ */ __exportAll({
|
|
|
14690
15763
|
symbol: () => symbol,
|
|
14691
15764
|
templateLiteral: () => templateLiteral,
|
|
14692
15765
|
transform: () => transform2,
|
|
14693
|
-
tuple: () =>
|
|
15766
|
+
tuple: () => tuple2,
|
|
14694
15767
|
uint32: () => uint32,
|
|
14695
15768
|
uint64: () => uint64,
|
|
14696
15769
|
ulid: () => ulid2,
|
|
@@ -15624,7 +16697,7 @@ function intersection2(left, right) {
|
|
|
15624
16697
|
right
|
|
15625
16698
|
});
|
|
15626
16699
|
}
|
|
15627
|
-
var
|
|
16700
|
+
var ZodTuple2 = /* @__PURE__ */ $constructor2("ZodTuple", (inst, def) => {
|
|
15628
16701
|
_ensureDefaultMemoizer2();
|
|
15629
16702
|
$ZodTuple2.init(inst, def);
|
|
15630
16703
|
ZodType2.init(inst, def);
|
|
@@ -15649,9 +16722,9 @@ var ZodTuple = /* @__PURE__ */ $constructor2("ZodTuple", (inst, def) => {
|
|
|
15649
16722
|
});
|
|
15650
16723
|
}
|
|
15651
16724
|
});
|
|
15652
|
-
function
|
|
16725
|
+
function tuple2(items, _paramsOrRest, _params) {
|
|
15653
16726
|
const hasRest = _paramsOrRest instanceof $ZodType2;
|
|
15654
|
-
return new
|
|
16727
|
+
return new ZodTuple2({
|
|
15655
16728
|
type: "tuple",
|
|
15656
16729
|
items,
|
|
15657
16730
|
rest: hasRest ? _paramsOrRest : null,
|
|
@@ -15787,7 +16860,7 @@ function nativeEnum(entries, params) {
|
|
|
15787
16860
|
...normalizeParams2(params)
|
|
15788
16861
|
});
|
|
15789
16862
|
}
|
|
15790
|
-
var
|
|
16863
|
+
var ZodLiteral2 = /* @__PURE__ */ $constructor2("ZodLiteral", (inst, def) => {
|
|
15791
16864
|
$ZodLiteral2.init(inst, def);
|
|
15792
16865
|
ZodType2.init(inst, def);
|
|
15793
16866
|
inst._zod.processJSONSchema = (ctx, json, params) => literalProcessor2(inst, ctx, json, params);
|
|
@@ -15798,8 +16871,8 @@ var ZodLiteral = /* @__PURE__ */ $constructor2("ZodLiteral", (inst, def) => {
|
|
|
15798
16871
|
return def.values[0];
|
|
15799
16872
|
} });
|
|
15800
16873
|
});
|
|
15801
|
-
function
|
|
15802
|
-
return new
|
|
16874
|
+
function literal2(value, params) {
|
|
16875
|
+
return new ZodLiteral2({
|
|
15803
16876
|
type: "literal",
|
|
15804
16877
|
values: Array.isArray(value) ? value : [value],
|
|
15805
16878
|
...normalizeParams2(params)
|
|
@@ -16068,7 +17141,7 @@ var ZodFunction = /* @__PURE__ */ $constructor2("ZodFunction", (inst, def) => {
|
|
|
16068
17141
|
function _function(params) {
|
|
16069
17142
|
return new ZodFunction({
|
|
16070
17143
|
type: "function",
|
|
16071
|
-
input: Array.isArray(params?.input) ?
|
|
17144
|
+
input: Array.isArray(params?.input) ? tuple2(params?.input) : params?.input ?? array2(unknown2()),
|
|
16072
17145
|
output: params?.output ?? unknown2()
|
|
16073
17146
|
});
|
|
16074
17147
|
}
|
|
@@ -16204,6 +17277,7 @@ var ID_PREFIXES = {
|
|
|
16204
17277
|
member: "mem",
|
|
16205
17278
|
invitation: "inv",
|
|
16206
17279
|
transfer: "xfer",
|
|
17280
|
+
assetBatch: "batch",
|
|
16207
17281
|
supportTicket: "tkt",
|
|
16208
17282
|
supportTicketMessage: "msg",
|
|
16209
17283
|
humanReview: "rev",
|
|
@@ -16235,11 +17309,13 @@ var newId = (prefix) => `${prefix}_${randomBase62(20)}`;
|
|
|
16235
17309
|
var toWebhookEventPayload = (event) => ({
|
|
16236
17310
|
id: event.id,
|
|
16237
17311
|
projectId: event.projectId,
|
|
17312
|
+
actor: event.actor,
|
|
16238
17313
|
type: event.type,
|
|
16239
17314
|
severity: event.severity,
|
|
16240
17315
|
title: event.title,
|
|
16241
17316
|
description: event.description ?? null,
|
|
16242
17317
|
assetId: event.assetId ?? null,
|
|
17318
|
+
assetSequence: event.assetSequence ?? null,
|
|
16243
17319
|
asset: event.asset ?? null,
|
|
16244
17320
|
facts: event.facts,
|
|
16245
17321
|
createdAt: event.createdAt
|
|
@@ -16256,11 +17332,13 @@ var createWebhookHeaders = async (options) => {
|
|
|
16256
17332
|
};
|
|
16257
17333
|
// src/cli/listen.ts
|
|
16258
17334
|
var FORWARD_TIMEOUT_MS = 1e4;
|
|
17335
|
+
var RETRY_DELAYS_MS = [1000, 2000, 4000, 8000, 15000, 30000];
|
|
17336
|
+
var MAX_RETRY_AFTER_MS = 60000;
|
|
16259
17337
|
var MAX_BACKOFF_MS = 30000;
|
|
16260
17338
|
var FATAL_ERROR_CODES = new Set([
|
|
16261
|
-
"
|
|
16262
|
-
"
|
|
16263
|
-
"
|
|
17339
|
+
"api-key/missing",
|
|
17340
|
+
"api-key/invalid",
|
|
17341
|
+
"api-key/project-mismatch",
|
|
16264
17342
|
"project/not-found"
|
|
16265
17343
|
]);
|
|
16266
17344
|
var createLocalSigningSecret = () => `whsec_local_${randomBytes(24).toString("hex")}`;
|
|
@@ -16271,7 +17349,7 @@ var forwardEvent = async (event, options) => {
|
|
|
16271
17349
|
const headers = await createWebhookHeaders({
|
|
16272
17350
|
secret: options.secret,
|
|
16273
17351
|
body,
|
|
16274
|
-
deliveryId: newId("dlv")
|
|
17352
|
+
deliveryId: options.deliveryId ?? newId("dlv")
|
|
16275
17353
|
});
|
|
16276
17354
|
const response = await (options.fetchImpl ?? fetch)(options.forwardTo, {
|
|
16277
17355
|
method: "POST",
|
|
@@ -16279,7 +17357,13 @@ var forwardEvent = async (event, options) => {
|
|
|
16279
17357
|
body,
|
|
16280
17358
|
signal: AbortSignal.timeout(FORWARD_TIMEOUT_MS)
|
|
16281
17359
|
});
|
|
16282
|
-
|
|
17360
|
+
const retryAfter = Number(response.headers.get("retry-after"));
|
|
17361
|
+
return {
|
|
17362
|
+
ok: response.ok,
|
|
17363
|
+
status: response.status,
|
|
17364
|
+
durationMs: Date.now() - startedAt,
|
|
17365
|
+
...(response.status === 429 || response.status === 503) && Number.isFinite(retryAfter) && retryAfter > 0 ? { retryAfterSeconds: retryAfter } : {}
|
|
17366
|
+
};
|
|
16283
17367
|
} catch (error) {
|
|
16284
17368
|
const cause = error.cause?.code;
|
|
16285
17369
|
return {
|
|
@@ -16289,10 +17373,12 @@ var forwardEvent = async (event, options) => {
|
|
|
16289
17373
|
};
|
|
16290
17374
|
}
|
|
16291
17375
|
};
|
|
17376
|
+
var isRetryable = (result) => !result.ok && (result.status === undefined || result.status === 408 || result.status === 425 || result.status === 429 || result.status >= 500);
|
|
16292
17377
|
var formatTime = (date) => date.toTimeString().slice(0, 8);
|
|
16293
|
-
var formatForwardLine = (event, result, now = new Date) => {
|
|
17378
|
+
var formatForwardLine = (event, result, now = new Date, retry) => {
|
|
16294
17379
|
const outcome = result.status ? `${result.status}${result.ok ? "" : " (handler returned an error)"}` : `failed: ${result.error}${result.error === "ECONNREFUSED" ? " (is your server running?)" : ""}`;
|
|
16295
|
-
|
|
17380
|
+
const attempt = retry && retry.attempts > 1 && (retry.attempt > 1 || !result.ok) ? ` attempt ${retry.attempt} of ${retry.attempts}${retry.delayMs === undefined ? isRetryable(result) ? ", giving up" : "" : `, retrying in ${Math.round(retry.delayMs / 1000)}s`}` : "";
|
|
17381
|
+
return `${formatTime(now)} ${event.type.padEnd(16)} ${event.id} → ${outcome} [${result.durationMs}ms]${attempt}`;
|
|
16296
17382
|
};
|
|
16297
17383
|
var sleep2 = (ms, signal) => new Promise((resolve) => {
|
|
16298
17384
|
if (signal?.aborted)
|
|
@@ -16303,6 +17389,24 @@ var sleep2 = (ms, signal) => new Promise((resolve) => {
|
|
|
16303
17389
|
resolve();
|
|
16304
17390
|
}, { once: true });
|
|
16305
17391
|
});
|
|
17392
|
+
var deliverEvent = async (event, options) => {
|
|
17393
|
+
const log = options.log ?? ((line) => process.stdout.write(`${line}
|
|
17394
|
+
`));
|
|
17395
|
+
const delays = options.retryDelaysMs ?? RETRY_DELAYS_MS;
|
|
17396
|
+
const attempts = delays.length + 1;
|
|
17397
|
+
const deliveryId = newId("dlv");
|
|
17398
|
+
for (let attempt = 1;; attempt++) {
|
|
17399
|
+
const result = await forwardEvent(event, { ...options, deliveryId });
|
|
17400
|
+
const baseDelay = delays[attempt - 1];
|
|
17401
|
+
const delayMs = isRetryable(result) && baseDelay !== undefined ? Math.max(baseDelay, Math.min(MAX_RETRY_AFTER_MS, (result.retryAfterSeconds ?? 0) * 1000)) : undefined;
|
|
17402
|
+
log(formatForwardLine(event, result, new Date, { attempt, attempts, delayMs }));
|
|
17403
|
+
if (delayMs === undefined || options.signal?.aborted)
|
|
17404
|
+
return result;
|
|
17405
|
+
await sleep2(delayMs, options.signal);
|
|
17406
|
+
if (options.signal?.aborted)
|
|
17407
|
+
return result;
|
|
17408
|
+
}
|
|
17409
|
+
};
|
|
16306
17410
|
var unavailableEventTypes = (excludedTypes, requested) => requested.size ? excludedTypes.filter((type) => requested.has(type)) : [...excludedTypes];
|
|
16307
17411
|
var describeEventTypes = (requested, unavailableTypes) => {
|
|
16308
17412
|
const unavailable = new Set(unavailableTypes);
|
|
@@ -16318,6 +17422,22 @@ var unavailableWarning = (unavailableTypes) => [
|
|
|
16318
17422
|
""
|
|
16319
17423
|
].join(`
|
|
16320
17424
|
`);
|
|
17425
|
+
var inAssetOrder = (events) => {
|
|
17426
|
+
const byAsset = new Map;
|
|
17427
|
+
for (const event of events)
|
|
17428
|
+
if (event.assetId)
|
|
17429
|
+
byAsset.set(event.assetId, [...byAsset.get(event.assetId) ?? [], event]);
|
|
17430
|
+
for (const assetEvents of byAsset.values())
|
|
17431
|
+
assetEvents.sort((a, b) => (a.assetSequence ?? 0) - (b.assetSequence ?? 0));
|
|
17432
|
+
const next = new Map;
|
|
17433
|
+
return events.map((event) => {
|
|
17434
|
+
if (!event.assetId)
|
|
17435
|
+
return event;
|
|
17436
|
+
const index = next.get(event.assetId) ?? 0;
|
|
17437
|
+
next.set(event.assetId, index + 1);
|
|
17438
|
+
return byAsset.get(event.assetId)[index];
|
|
17439
|
+
});
|
|
17440
|
+
};
|
|
16321
17441
|
var listen = async (options) => {
|
|
16322
17442
|
const { client, signal } = options;
|
|
16323
17443
|
const log = options.log ?? ((line) => process.stdout.write(`${line}
|
|
@@ -16334,10 +17454,12 @@ var listen = async (options) => {
|
|
|
16334
17454
|
if (failures > 0)
|
|
16335
17455
|
log(`${formatTime(new Date)} Reconnected to CalmLens.`);
|
|
16336
17456
|
failures = 0;
|
|
16337
|
-
for (const event of page.items) {
|
|
17457
|
+
for (const event of inAssetOrder(page.items)) {
|
|
16338
17458
|
if (eventTypes.size > 0 && !eventTypes.has(event.type))
|
|
16339
17459
|
continue;
|
|
16340
|
-
|
|
17460
|
+
await deliverEvent(event, { ...options, log });
|
|
17461
|
+
if (signal?.aborted)
|
|
17462
|
+
return;
|
|
16341
17463
|
}
|
|
16342
17464
|
cursor = page.nextCursor;
|
|
16343
17465
|
if (!page.hasMore)
|
|
@@ -16474,19 +17596,34 @@ Usage:
|
|
|
16474
17596
|
calmlens logout
|
|
16475
17597
|
calmlens listen --forward-to <url> [options]
|
|
16476
17598
|
calmlens trigger [sexual|violence|self-harm|harassment|hate|criminal-activity|clean] [options]
|
|
17599
|
+
calmlens plan [--config <path>] [--prune]
|
|
17600
|
+
calmlens apply [--config <path>] [--prune]
|
|
16477
17601
|
|
|
16478
|
-
|
|
17602
|
+
Install it with \`brew install calmlens/sdks/calmlens\` (after
|
|
17603
|
+
\`brew tap calmlens/sdks https://github.com/CalmLens/sdks\`), the install script at
|
|
17604
|
+
https://calmlens.com/install.sh, a download from https://github.com/CalmLens/sdks/releases,
|
|
17605
|
+
or \`npm install -g calmlens\`. See https://calmlens.com/docs/guides/local-development.
|
|
16479
17606
|
|
|
16480
17607
|
Commands:
|
|
16481
17608
|
login Sign in through your browser and choose a project. The CLI keeps the key it
|
|
16482
17609
|
receives, so listen and trigger need no API key or project ID.
|
|
16483
17610
|
logout Revoke and forget the key from login.
|
|
16484
|
-
listen Forward your project's events to a local webhook handler with the same
|
|
16485
|
-
(
|
|
16486
|
-
|
|
17611
|
+
listen Forward your project's events to a local webhook handler with the same flat
|
|
17612
|
+
body (id, projectId, actor, type, severity, title, description, assetId,
|
|
17613
|
+
assetSequence, asset, facts, createdAt) and headers (x-calmlens-delivery,
|
|
17614
|
+
x-calmlens-timestamp, x-calmlens-signature: v1=...) as real deliveries. No
|
|
17615
|
+
public URL needed. Like real deliveries, network errors, timeouts, 408, 425, 429
|
|
17616
|
+
and 5xx responses are retried, up to 7 attempts with the same delivery ID, here
|
|
17617
|
+
after 1, 2, 4, 8, 15 and 30 seconds (longer if Retry-After asks, up to 60).
|
|
16487
17618
|
trigger Moderate a harmless test comment so CalmLens creates real events. Each trigger
|
|
16488
|
-
counts as one upload. Test comments other than clean
|
|
16489
|
-
test input key (
|
|
17619
|
+
counts as one upload. Test comments other than clean are signed with the
|
|
17620
|
+
project's test input key (Project settings → Test inputs in the portal).
|
|
17621
|
+
plan Compare calmlens.config.json with the project: its policies (by name, with the
|
|
17622
|
+
project's policy), upload presets (by key), lenses (by identifier), metadata
|
|
17623
|
+
fields (by ID) and settings. Prints what apply would change and changes nothing.
|
|
17624
|
+
apply Make the changes plan prints. Each is sent with the revision just read, so a
|
|
17625
|
+
change made meanwhile in the portal or by another deploy is refused, not lost.
|
|
17626
|
+
See https://calmlens.com/docs/guides/configuration-as-code.
|
|
16490
17627
|
|
|
16491
17628
|
Options:
|
|
16492
17629
|
--forward-to <url> Local webhook URL, e.g. http://localhost:3000/api/webhooks/calmlens
|
|
@@ -16499,6 +17636,9 @@ Options:
|
|
|
16499
17636
|
--test-key <key> Project's test input key, for trigger (default: $CALMLENS_TEST_INPUT_KEY)
|
|
16500
17637
|
--env-file <path> Load environment variables from a file, e.g. .env.local
|
|
16501
17638
|
--interval <seconds> Seconds between checks for new events (default: 2)
|
|
17639
|
+
--config <path> For plan and apply: the configuration file (default: calmlens.config.json)
|
|
17640
|
+
--prune For plan and apply: also delete upload presets, lenses and metadata
|
|
17641
|
+
fields the file doesn't list (never policies)
|
|
16502
17642
|
--api-url <url> API base URL (default: $CALMLENS_API_URL or https://api.calmlens.com/v1)
|
|
16503
17643
|
-v, --version Show the CLI version
|
|
16504
17644
|
-h, --help Show this help
|
|
@@ -16529,6 +17669,8 @@ var main = async () => {
|
|
|
16529
17669
|
interval: { type: "string" },
|
|
16530
17670
|
"api-url": { type: "string" },
|
|
16531
17671
|
"read-only": { type: "boolean" },
|
|
17672
|
+
config: { type: "string" },
|
|
17673
|
+
prune: { type: "boolean" },
|
|
16532
17674
|
"no-browser": { type: "boolean" },
|
|
16533
17675
|
help: { type: "boolean", short: "h" },
|
|
16534
17676
|
version: { type: "boolean", short: "v" }
|
|
@@ -16637,10 +17779,10 @@ var main = async () => {
|
|
|
16637
17779
|
const testInputKey = (values["test-key"] ?? process.env.CALMLENS_TEST_INPUT_KEY)?.trim();
|
|
16638
17780
|
if (!testInputKey)
|
|
16639
17781
|
fail(`trigger ${kind} needs your project's test input key: pass --test-key <key> or set CALMLENS_TEST_INPUT_KEY.
|
|
16640
|
-
` + "Copy it from
|
|
17782
|
+
` + "Copy it from Project settings → Test inputs in the CalmLens portal.");
|
|
16641
17783
|
if (!TEST_INPUT_KEY_PATTERN.test(testInputKey))
|
|
16642
17784
|
fail(`"${testInputKey}" isn't a test input key: it is 32 lowercase hexadecimal characters.
|
|
16643
|
-
` + "Copy it from
|
|
17785
|
+
` + "Copy it from Project settings → Test inputs in the CalmLens portal.");
|
|
16644
17786
|
text = await generateTestTextCode(kind, testInputKey);
|
|
16645
17787
|
}
|
|
16646
17788
|
try {
|
|
@@ -16655,6 +17797,33 @@ var main = async () => {
|
|
|
16655
17797
|
}
|
|
16656
17798
|
return;
|
|
16657
17799
|
}
|
|
17800
|
+
if (command === "plan" || command === "apply") {
|
|
17801
|
+
const path = values.config ?? "calmlens.config.json";
|
|
17802
|
+
let text;
|
|
17803
|
+
try {
|
|
17804
|
+
text = await readFile2(path, "utf8");
|
|
17805
|
+
} catch {
|
|
17806
|
+
return fail(`Couldn't read ${path}. Pass --config <path> to use another file.`);
|
|
17807
|
+
}
|
|
17808
|
+
try {
|
|
17809
|
+
const config = parseConfiguration(text, path);
|
|
17810
|
+
const state = await readConfigurationState(client, config);
|
|
17811
|
+
const plan = planConfiguration(config, state, { prune: Boolean(values.prune) });
|
|
17812
|
+
process.stdout.write(formatPlan(plan));
|
|
17813
|
+
if (command === "apply" && plan.changes.length) {
|
|
17814
|
+
await applyConfiguration(client, config, state, plan, (line) => process.stdout.write(`${line}
|
|
17815
|
+
`));
|
|
17816
|
+
process.stdout.write(`Applied.
|
|
17817
|
+
`);
|
|
17818
|
+
}
|
|
17819
|
+
} catch (error) {
|
|
17820
|
+
if (error instanceof CalmLensError && error.code.endsWith("/revision-conflict"))
|
|
17821
|
+
fail(`${describeError(error)}
|
|
17822
|
+
Something changed since it was read. Run \`calmlens ${command}\` again to see the latest differences.`);
|
|
17823
|
+
fail(error instanceof ConfigurationError ? error.message : `${command === "apply" ? "Apply" : "Plan"} failed: ${describeError(error)}`);
|
|
17824
|
+
}
|
|
17825
|
+
return;
|
|
17826
|
+
}
|
|
16658
17827
|
fail(`Unknown command "${command}".
|
|
16659
17828
|
|
|
16660
17829
|
${HELP}`);
|