calmlens 0.4.0 → 0.18.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.
Files changed (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +673 -130
  3. package/bin/calmlens.js +15994 -1164
  4. package/bin/package.json +1 -0
  5. package/cjs/BrowserUpload-BT091eOB.d.ts +11 -0
  6. package/cjs/BrowserUpload-CQwXEGFv.js +10 -0
  7. package/cjs/CalmLensAppClient-CHQGu-Do.js +89 -0
  8. package/cjs/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
  9. package/cjs/CalmLensConnection-B8Bu2j3y.js +659 -0
  10. package/cjs/CalmLensServerClient-C5o2A8MW.js +645 -0
  11. package/cjs/CalmLensServerClient-JtP687a3.d.ts +235 -0
  12. package/cjs/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
  13. package/cjs/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
  14. package/cjs/CryptoUtils-B_x8lMIx-YBW1-bvL.js +42 -0
  15. package/cjs/FileIcons-Ob003MdS.js +175 -0
  16. package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +91 -0
  17. package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
  18. package/cjs/ModerationContextLimits-DelWfmiJ.js +1311 -0
  19. package/cjs/ReactUpload-CAyCsyG6.d.ts +17 -0
  20. package/cjs/ReactUpload-Cfg5JYUq.js +54 -0
  21. package/cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
  22. package/cjs/TestTriggers-DTc_iMJF-BjMPq4_3.js +1327 -0
  23. package/cjs/UploadController-BGO1eyzb.js +618 -0
  24. package/cjs/WebhookPayload-2aL31v0J.d.ts +352 -0
  25. package/cjs/app.d.ts +7 -0
  26. package/cjs/app.js +13 -0
  27. package/cjs/elements.d.ts +88 -0
  28. package/cjs/elements.js +555 -0
  29. package/cjs/file-icons.d.ts +67 -0
  30. package/cjs/file-icons.js +10 -0
  31. package/cjs/index-CI4BzN4W.d.ts +252 -0
  32. package/cjs/index.d.ts +6 -163
  33. package/cjs/index.js +9 -796
  34. package/cjs/react-native.d.ts +56 -0
  35. package/cjs/react-native.js +495 -0
  36. package/cjs/react.d.ts +30 -0
  37. package/cjs/react.js +370 -0
  38. package/cjs/server.d.ts +33 -0
  39. package/cjs/server.js +20 -0
  40. package/cjs/test-inputs.d.ts +2 -0
  41. package/cjs/test-inputs.js +10 -0
  42. package/cjs/testing.d.ts +309 -80
  43. package/cjs/testing.js +10453 -689
  44. package/cjs/ui-CC1GOoMg.js +583 -0
  45. package/cjs/ui-wIiMfqMB.d.ts +526 -0
  46. package/cjs/ui.d.ts +2 -0
  47. package/cjs/ui.js +27 -0
  48. package/cjs/vue.d.ts +490 -0
  49. package/cjs/vue.js +419 -0
  50. package/esm/BrowserUpload-BT091eOB.d.ts +11 -0
  51. package/esm/BrowserUpload-D2xBWqhm.js +5 -0
  52. package/esm/CalmLensAppClient-CV_K26Ce.d.ts +40 -0
  53. package/esm/CalmLensAppClient-DuFas_dW.js +84 -0
  54. package/esm/CalmLensConnection-MxwwLXdl.js +582 -0
  55. package/esm/CalmLensServerClient-D80_mKpW.js +586 -0
  56. package/esm/CalmLensServerClient-JtP687a3.d.ts +235 -0
  57. package/esm/CalmLensTypes-9Vt16pc7.d.ts +40400 -0
  58. package/esm/Classification-94kSYWZw-CMnQKW13.d.ts +5873 -0
  59. package/esm/CryptoUtils-B_x8lMIx-DhuWGzqn.js +25 -0
  60. package/esm/FileIcons-M6dzjFxd.js +128 -0
  61. package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +46 -0
  62. package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +67 -0
  63. package/esm/ModerationContextLimits-BaX2QnU8.js +1114 -0
  64. package/esm/ReactUpload-CAyCsyG6.d.ts +17 -0
  65. package/esm/ReactUpload-CL2XC8WS.js +37 -0
  66. package/esm/TestTriggers-By07LR31-CmK0yTyR.d.ts +271 -0
  67. package/esm/TestTriggers-DTc_iMJF-HfB533Gx.js +1267 -0
  68. package/esm/UploadController-qjoYGCwx.js +589 -0
  69. package/esm/WebhookPayload-2aL31v0J.d.ts +352 -0
  70. package/esm/app.d.ts +7 -0
  71. package/esm/app.js +4 -0
  72. package/esm/elements.d.ts +88 -0
  73. package/esm/elements.js +528 -0
  74. package/esm/file-icons.d.ts +67 -0
  75. package/esm/file-icons.js +1 -0
  76. package/esm/index-CI4BzN4W.d.ts +252 -0
  77. package/esm/index.d.ts +6 -163
  78. package/esm/index.js +1 -794
  79. package/esm/react-native.d.ts +56 -0
  80. package/esm/react-native.js +467 -0
  81. package/esm/react.d.ts +30 -0
  82. package/esm/react.js +343 -0
  83. package/esm/server.d.ts +33 -0
  84. package/esm/server.js +4 -0
  85. package/esm/styles.css +147 -0
  86. package/esm/svelte/CalmLensMedia.svelte +134 -0
  87. package/esm/svelte/CalmLensUploader.svelte +175 -0
  88. package/esm/svelte/Icon.svelte +7 -0
  89. package/esm/svelte/index.d.ts +37 -0
  90. package/esm/svelte/index.js +6 -0
  91. package/esm/test-inputs.d.ts +2 -0
  92. package/esm/test-inputs.js +1 -0
  93. package/esm/testing.d.ts +309 -80
  94. package/esm/testing.js +10432 -656
  95. package/esm/ui-CCY3yXFn.js +458 -0
  96. package/esm/ui-wIiMfqMB.d.ts +526 -0
  97. package/esm/ui.d.ts +2 -0
  98. package/esm/ui.js +3 -0
  99. package/esm/vue.d.ts +490 -0
  100. package/esm/vue.js +392 -0
  101. package/package.json +173 -34
  102. package/cjs/CalmLensTypes-DkqoKBwF.d.ts +0 -1761
  103. package/cjs/CalmLensUtils-CjdO9v--.js +0 -549
  104. package/esm/CalmLensTypes-DkqoKBwF.d.ts +0 -1761
  105. package/esm/CalmLensUtils-B3Eiz2Ro.js +0 -430
@@ -1,549 +0,0 @@
1
- let sendable_error = require("sendable-error");
2
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/asyncToGenerator.js
3
- function asyncGeneratorStep(n, t, e, r, o, a, c) {
4
- try {
5
- var i = n[a](c), u = i.value;
6
- } catch (n) {
7
- e(n);
8
- return;
9
- }
10
- i.done ? t(u) : Promise.resolve(u).then(r, o);
11
- }
12
- function _asyncToGenerator(n) {
13
- return function() {
14
- var t = this, e = arguments;
15
- return new Promise(function(r, o) {
16
- var a = n.apply(t, e);
17
- function _next(n) {
18
- asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
19
- }
20
- function _throw(n) {
21
- asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
22
- }
23
- _next(void 0);
24
- });
25
- };
26
- }
27
- //#endregion
28
- //#region ../shared/src/AssetPayload.ts
29
- const uint8ArrayInputToNumbers = (value) => {
30
- if (Array.isArray(value)) return value;
31
- return Array.from(value);
32
- };
33
- const bufferInputToBytes = (value) => {
34
- if (value instanceof ArrayBuffer) return new Uint8Array(value);
35
- return Uint8Array.from(value);
36
- };
37
- const 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.";
38
- const MULTIPART_PART_TOO_SMALL_ERROR = `Multipart upload parts must be at least 5MiB except the final part.`;
39
- const getRawBase64 = (value) => {
40
- const markerIndex = value.indexOf(";base64,");
41
- if (markerIndex === -1) return value;
42
- return value.slice(markerIndex + 8);
43
- };
44
- const validateBase64PayloadString = (payload, options) => {
45
- const raw = getRawBase64(payload.base64).replace(/\s/g, "");
46
- if ((options === null || options === void 0 ? void 0 : options.multipart) && raw.length % 4 !== 0) return {
47
- ok: false,
48
- error: BASE64_PART_BOUNDARY_ERROR
49
- };
50
- return { ok: true };
51
- };
52
- const isReadableStream = (value) => typeof value === "object" && value !== null && "getReader" in value && typeof value.getReader === "function";
53
- const assetToData = (payload) => {
54
- if ("plainText" in payload && payload.plainText !== void 0) return new TextEncoder().encode(payload.plainText);
55
- if ("data" in payload && payload.data) return payload.data;
56
- if ("buffer" in payload) {
57
- if (payload.buffer instanceof ArrayBuffer) return payload.buffer;
58
- return bufferInputToBytes(payload.buffer);
59
- }
60
- if (payload.uint8Array !== void 0) return Uint8Array.from(uint8ArrayInputToNumbers(payload.uint8Array));
61
- if (payload.base64 === void 0) throw new Error("Invalid asset payload");
62
- const raw = getRawBase64(payload.base64);
63
- if (typeof Buffer !== "undefined") return Uint8Array.from(Buffer.from(raw, "base64"));
64
- const binary = atob(raw);
65
- return Uint8Array.from(binary, (char) => char.charCodeAt(0));
66
- };
67
- const assetDataToUint8Array = function() {
68
- var _ref = _asyncToGenerator(function* (data) {
69
- if (data instanceof Response) return new Uint8Array(yield data.arrayBuffer());
70
- if (isReadableStream(data)) return new Uint8Array(yield new Response(data).arrayBuffer());
71
- if (data instanceof Blob) return new Uint8Array(yield data.arrayBuffer());
72
- if (data instanceof ArrayBuffer) return new Uint8Array(data);
73
- return data;
74
- });
75
- return function assetDataToUint8Array(_x) {
76
- return _ref.apply(this, arguments);
77
- };
78
- }();
79
- const getAssetPayloadByteLength = (payload) => {
80
- if ("plainText" in payload && payload.plainText !== void 0) return new TextEncoder().encode(payload.plainText).byteLength;
81
- if ("data" in payload && payload.data) {
82
- if (payload.data instanceof Blob) return payload.data.size;
83
- if (payload.data instanceof Response) {
84
- const contentLength = payload.data.headers.get("content-length");
85
- return contentLength ? Number(contentLength) : void 0;
86
- }
87
- return;
88
- }
89
- if ("buffer" in payload && payload.buffer) return payload.buffer.byteLength;
90
- if (payload.uint8Array !== void 0) {
91
- if (Array.isArray(payload.uint8Array)) return payload.uint8Array.length;
92
- return payload.uint8Array.byteLength;
93
- }
94
- if (payload.base64 === void 0) return;
95
- const raw = getRawBase64(payload.base64).replace(/\s/g, "");
96
- const padding = raw.endsWith("==") ? 2 : raw.endsWith("=") ? 1 : 0;
97
- return Math.max(0, Math.floor(raw.length * 3 / 4) - padding);
98
- };
99
- const validateAssetPayload = (payload, options) => {
100
- if ("base64" in payload && payload.base64 !== void 0) {
101
- const validation = validateBase64PayloadString(payload, options);
102
- if (!validation.ok) return {
103
- ok: false,
104
- error: validation.error
105
- };
106
- }
107
- const byteLength = getAssetPayloadByteLength(payload);
108
- if ((options === null || options === void 0 ? void 0 : options.multipart) && !options.isFinal && byteLength !== void 0 && byteLength < 5242880) return {
109
- ok: false,
110
- error: MULTIPART_PART_TOO_SMALL_ERROR
111
- };
112
- return { ok: true };
113
- };
114
- //#endregion
115
- //#region ../shared/src/JsonUtils.ts
116
- const stringifyJsonCanonical = (value) => JSON.stringify(value, (_key, nestedValue) => {
117
- if (!nestedValue || typeof nestedValue !== "object" || Array.isArray(nestedValue)) return nestedValue;
118
- return Object.fromEntries(Object.keys(nestedValue).sort().map((key) => [key, nestedValue[key]]));
119
- });
120
- //#endregion
121
- //#region ../shared/src/PublicErrorCodes.ts
122
- const PUBLIC_ERROR_CODES = {
123
- MISSING_TOKEN: new sendable_error.ErrorCode({
124
- id: "auth/missing-token",
125
- defaultMessage: "Authentication required. Send your project API key in the X-Api-Key header.",
126
- status: 401
127
- }),
128
- INVALID_API_KEY: new sendable_error.ErrorCode({
129
- id: "auth/invalid-api-key",
130
- defaultMessage: "The API key is invalid, revoked or expired. Create a key under Developer → API Keys.",
131
- status: 401
132
- }),
133
- API_KEY_PROJECT_MISMATCH: new sendable_error.ErrorCode({
134
- id: "auth/project-mismatch",
135
- defaultMessage: "This API key belongs to a different project. Use a key created for the project that owns this resource.",
136
- status: 403
137
- }),
138
- API_KEY_NOT_ACCEPTED: new sendable_error.ErrorCode({
139
- id: "auth/api-key-not-accepted",
140
- defaultMessage: "API keys are only accepted by the public API at /v1.",
141
- status: 403
142
- }),
143
- FILE_TOO_LARGE: new sendable_error.ErrorCode({
144
- id: "upload/file-too-large",
145
- defaultMessage: "File size exceeds limit. Maximum size for images is 10MB, for other files is 5GB.",
146
- status: 400
147
- }),
148
- IMAGE_REQUIRES_MULTIPART_UPLOAD: new sendable_error.ErrorCode({
149
- id: "upload/image-requires-multipart-upload",
150
- defaultMessage: "Images of 10MB or more must use a multipart upload.",
151
- status: 400
152
- }),
153
- MULTIPART_IMAGE_TOO_SMALL: new sendable_error.ErrorCode({
154
- id: "upload/multipart-image-too-small",
155
- defaultMessage: "Multipart image uploads must total at least 10MB.",
156
- status: 400
157
- }),
158
- MULTIPART_IMAGE_TOO_LARGE: new sendable_error.ErrorCode({
159
- id: "upload/multipart-image-too-large",
160
- defaultMessage: "Multipart image uploads cannot exceed 20MB.",
161
- status: 400
162
- }),
163
- IMAGE_EXCEEDED_MAX_DIMENSIONS: new sendable_error.ErrorCode({
164
- id: "upload/image-exceeded-max-dimensions",
165
- defaultMessage: "Image exceeds maximum dimensions. Maximum dimensions are 12,000px.",
166
- status: 400
167
- }),
168
- UPLOAD_LIMIT_EXCEEDED: new sendable_error.ErrorCode({
169
- id: "upload/limit-exceeded",
170
- defaultMessage: "Upload limit exceeded. You have used all your free uploads. Please upgrade to Plus or Pro for unlimited uploads.",
171
- status: 403
172
- }),
173
- INVALID_UPLOAD_MIME_TYPE: new sendable_error.ErrorCode({
174
- id: "upload/invalid-mime-type",
175
- defaultMessage: "Upload file type is not supported. 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.",
176
- status: 400
177
- }),
178
- INVALID_EVENT_CURSOR: new sendable_error.ErrorCode({
179
- id: "events/invalid-cursor",
180
- defaultMessage: "The events cursor is invalid. Use the cursor from a previous response, or omit it to start from now.",
181
- status: 400
182
- }),
183
- INVALID_UPLOAD_PAYLOAD: new sendable_error.ErrorCode({
184
- id: "upload/invalid-payload",
185
- defaultMessage: "Upload payload is invalid.",
186
- status: 400
187
- }),
188
- USE_UPLOAD_PART: new sendable_error.ErrorCode({
189
- id: "upload/use-upload-part",
190
- defaultMessage: "Use uploadPart for multipart upload parts after the first part",
191
- status: 409
192
- }),
193
- UPLOAD_NOT_OPEN: new sendable_error.ErrorCode({
194
- id: "upload/not-open",
195
- defaultMessage: "Asset is not accepting additional parts",
196
- status: 409
197
- }),
198
- INVALID_UPLOAD_PART_NUMBER: new sendable_error.ErrorCode({
199
- id: "upload/invalid-part-number",
200
- defaultMessage: "Multipart upload part number is invalid.",
201
- status: 409
202
- }),
203
- UPLOAD_MISSING: new sendable_error.ErrorCode({
204
- id: "upload/missing",
205
- defaultMessage: "Multipart upload state is missing",
206
- status: 409
207
- }),
208
- ASSET_NOT_FOUND: new sendable_error.ErrorCode({
209
- id: "asset/not-found",
210
- defaultMessage: "Asset not found",
211
- status: 404
212
- }),
213
- PROJECT_NOT_FOUND: new sendable_error.ErrorCode({
214
- id: "project/not-found",
215
- defaultMessage: "Project not found",
216
- status: 404
217
- }),
218
- ASSET_UPDATE_FAILED: new sendable_error.ErrorCode({
219
- id: "asset/update-failed",
220
- defaultMessage: "Failed to update asset",
221
- status: 500
222
- }),
223
- ASSET_SAFETY_HELD: new sendable_error.ErrorCode({
224
- id: "asset/safety-held",
225
- defaultMessage: "Asset access is restricted by a safety hold.",
226
- status: 423
227
- }),
228
- ASSET_NOT_RETRYABLE: new sendable_error.ErrorCode({
229
- id: "asset/not-retryable",
230
- defaultMessage: "Only assets that failed to process (status error) can be retried.",
231
- status: 409
232
- }),
233
- ASSET_CONTENT_UNAVAILABLE: new sendable_error.ErrorCode({
234
- id: "asset/content-unavailable",
235
- defaultMessage: "This asset's content is no longer stored, so it can't be processed again. Upload it again instead.",
236
- status: 409
237
- }),
238
- SUPPORT_TICKET_NOT_FOUND: new sendable_error.ErrorCode({
239
- id: "support/ticket-not-found",
240
- defaultMessage: "Support ticket not found.",
241
- status: 404
242
- }),
243
- DUPLICATE_EXTERNAL_ID: new sendable_error.ErrorCode({
244
- id: "asset/duplicate-external-id",
245
- defaultMessage: "An asset with this externalId already exists in the project.",
246
- status: 409
247
- }),
248
- FOLDER_NOT_FOUND: new sendable_error.ErrorCode({
249
- id: "folder/not-found",
250
- defaultMessage: "Folder not found",
251
- status: 404
252
- }),
253
- DUPLICATE_FOLDER_NAME: new sendable_error.ErrorCode({
254
- id: "folder/duplicate-name",
255
- defaultMessage: "A folder with this name already exists in this location.",
256
- status: 409
257
- }),
258
- FOLDER_NOT_EMPTY: new sendable_error.ErrorCode({
259
- id: "folder/not-empty",
260
- defaultMessage: "Folder must be empty before it can be deleted.",
261
- status: 409
262
- }),
263
- FOLDER_PARENT_CYCLE: new sendable_error.ErrorCode({
264
- id: "folder/parent-cycle",
265
- defaultMessage: "A folder cannot be moved inside itself or one of its descendants.",
266
- status: 409
267
- }),
268
- LENS_VERSION_CONFLICT: new sendable_error.ErrorCode({
269
- id: "lens/version-conflict",
270
- defaultMessage: "Lens updates require a version greater than the current version.",
271
- status: 409
272
- })
273
- };
274
- PUBLIC_ERROR_CODES.MISSING_TOKEN, PUBLIC_ERROR_CODES.INVALID_API_KEY, PUBLIC_ERROR_CODES.API_KEY_PROJECT_MISMATCH;
275
- const MAX_IMAGE_UPLOAD_BYTES = 20971520;
276
- const MIN_MULTIPART_IMAGE_UPLOAD_BYTES = 10485760;
277
- const REJECTED_UPLOAD_MIME_TYPE_SET = /* @__PURE__ */ new Set([
278
- "application/octet-stream",
279
- "multipart/form-data",
280
- "multipart/mixed",
281
- "multipart/alternative",
282
- "multipart/related",
283
- "multipart/signed",
284
- "multipart/encrypted"
285
- ]);
286
- const normalizeUploadMimeType = (mimeType) => {
287
- var _mimeType$toLowerCase;
288
- return ((_mimeType$toLowerCase = mimeType.toLowerCase().split(";")[0]) === null || _mimeType$toLowerCase === void 0 ? void 0 : _mimeType$toLowerCase.trim()) || mimeType.toLowerCase().trim();
289
- };
290
- const isRejectedUploadMimeType = (mimeType) => REJECTED_UPLOAD_MIME_TYPE_SET.has(normalizeUploadMimeType(mimeType));
291
- const 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.`;
292
- const DOMAIN = "calmlens.com";
293
- //#endregion
294
- //#region src/client/CalmLensError.ts
295
- const SDK_ERRORS = { NO_CDN_FETCH: {
296
- id: "sdk/no-cdn-fetch",
297
- defaultMessage: "No fetch implementation is available for CDN requests"
298
- } };
299
- var CalmLensError = class extends Error {
300
- constructor(errorCode, options) {
301
- var _ref, _options$message;
302
- const code = "getId" in errorCode ? errorCode.getId() : errorCode.id;
303
- const defaultMessage = "getDefaultMessage" in errorCode ? errorCode.getDefaultMessage() : errorCode.defaultMessage;
304
- super(`[calmlens] ${(_ref = (_options$message = options === null || options === void 0 ? void 0 : options.message) !== null && _options$message !== void 0 ? _options$message : defaultMessage) !== null && _ref !== void 0 ? _ref : code}`);
305
- this.name = "CalmLensError";
306
- this.code = code;
307
- this.details = options === null || options === void 0 ? void 0 : options.details;
308
- }
309
- };
310
- const calmLensError = (errorCode, options) => new CalmLensError(errorCode, options);
311
- //#endregion
312
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/objectWithoutPropertiesLoose.js
313
- function _objectWithoutPropertiesLoose(r, e) {
314
- if (null == r) return {};
315
- var t = {};
316
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
317
- if (e.includes(n)) continue;
318
- t[n] = r[n];
319
- }
320
- return t;
321
- }
322
- //#endregion
323
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/objectWithoutProperties.js
324
- function _objectWithoutProperties(e, t) {
325
- if (null == e) return {};
326
- var o, r, i = _objectWithoutPropertiesLoose(e, t);
327
- if (Object.getOwnPropertySymbols) {
328
- var s = Object.getOwnPropertySymbols(e);
329
- for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
330
- }
331
- return i;
332
- }
333
- //#endregion
334
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/typeof.js
335
- function _typeof(o) {
336
- "@babel/helpers - typeof";
337
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
338
- return typeof o;
339
- } : function(o) {
340
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
341
- }, _typeof(o);
342
- }
343
- //#endregion
344
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPrimitive.js
345
- function toPrimitive(t, r) {
346
- if ("object" != _typeof(t) || !t) return t;
347
- var e = t[Symbol.toPrimitive];
348
- if (void 0 !== e) {
349
- var i = e.call(t, r || "default");
350
- if ("object" != _typeof(i)) return i;
351
- throw new TypeError("@@toPrimitive must return a primitive value.");
352
- }
353
- return ("string" === r ? String : Number)(t);
354
- }
355
- //#endregion
356
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPropertyKey.js
357
- function toPropertyKey(t) {
358
- var i = toPrimitive(t, "string");
359
- return "symbol" == _typeof(i) ? i : i + "";
360
- }
361
- //#endregion
362
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/defineProperty.js
363
- function _defineProperty(e, r, t) {
364
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
365
- value: t,
366
- enumerable: !0,
367
- configurable: !0,
368
- writable: !0
369
- }) : e[r] = t, e;
370
- }
371
- //#endregion
372
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/objectSpread2.js
373
- function ownKeys(e, r) {
374
- var t = Object.keys(e);
375
- if (Object.getOwnPropertySymbols) {
376
- var o = Object.getOwnPropertySymbols(e);
377
- r && (o = o.filter(function(r) {
378
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
379
- })), t.push.apply(t, o);
380
- }
381
- return t;
382
- }
383
- function _objectSpread2(e) {
384
- for (var r = 1; r < arguments.length; r++) {
385
- var t = null != arguments[r] ? arguments[r] : {};
386
- r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
387
- _defineProperty(e, r, t[r]);
388
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
389
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
390
- });
391
- }
392
- return e;
393
- }
394
- //#endregion
395
- //#region src/client/CalmLensUtils.ts
396
- const _excluded = ["text", "name"];
397
- /** Converts `text.moderate()` options into a plain-text asset submission. */
398
- const toTextAssetOptions = (_ref) => {
399
- let { text, name } = _ref, options = _objectWithoutProperties(_ref, _excluded);
400
- if (typeof text !== "string" || text.trim().length === 0) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Text to moderate must be a non-empty string" });
401
- return _objectSpread2(_objectSpread2({}, options), {}, {
402
- name: name !== null && name !== void 0 ? name : "text",
403
- content: {
404
- plainText: text,
405
- type: "text/plain"
406
- }
407
- });
408
- };
409
- function verifyWebhookSignature(_x) {
410
- return _verifyWebhookSignature.apply(this, arguments);
411
- }
412
- function _verifyWebhookSignature() {
413
- _verifyWebhookSignature = _asyncToGenerator(function* ({ payload, signatureHex, secret }) {
414
- const encoder = new TextEncoder();
415
- const normalizePayload = typeof payload === "string" ? payload : JSON.stringify(payload);
416
- const key = yield crypto.subtle.importKey("raw", encoder.encode(secret), {
417
- name: "HMAC",
418
- hash: "SHA-256"
419
- }, false, ["sign"]);
420
- const sig = yield crypto.subtle.sign("HMAC", key, encoder.encode(normalizePayload));
421
- const hex = Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("");
422
- if (hex.length !== signatureHex.length) return false;
423
- let diff = 0;
424
- for (let i = 0; i < hex.length; i++) diff |= hex.charCodeAt(i) ^ signatureHex.charCodeAt(i);
425
- return diff === 0;
426
- });
427
- return _verifyWebhookSignature.apply(this, arguments);
428
- }
429
- //#endregion
430
- Object.defineProperty(exports, "CalmLensError", {
431
- enumerable: true,
432
- get: function() {
433
- return CalmLensError;
434
- }
435
- });
436
- Object.defineProperty(exports, "DOMAIN", {
437
- enumerable: true,
438
- get: function() {
439
- return DOMAIN;
440
- }
441
- });
442
- Object.defineProperty(exports, "MAX_IMAGE_UPLOAD_BYTES", {
443
- enumerable: true,
444
- get: function() {
445
- return MAX_IMAGE_UPLOAD_BYTES;
446
- }
447
- });
448
- Object.defineProperty(exports, "MIN_MULTIPART_IMAGE_UPLOAD_BYTES", {
449
- enumerable: true,
450
- get: function() {
451
- return MIN_MULTIPART_IMAGE_UPLOAD_BYTES;
452
- }
453
- });
454
- Object.defineProperty(exports, "PUBLIC_ERROR_CODES", {
455
- enumerable: true,
456
- get: function() {
457
- return PUBLIC_ERROR_CODES;
458
- }
459
- });
460
- Object.defineProperty(exports, "SDK_ERRORS", {
461
- enumerable: true,
462
- get: function() {
463
- return SDK_ERRORS;
464
- }
465
- });
466
- Object.defineProperty(exports, "_asyncToGenerator", {
467
- enumerable: true,
468
- get: function() {
469
- return _asyncToGenerator;
470
- }
471
- });
472
- Object.defineProperty(exports, "_objectSpread2", {
473
- enumerable: true,
474
- get: function() {
475
- return _objectSpread2;
476
- }
477
- });
478
- Object.defineProperty(exports, "_objectWithoutProperties", {
479
- enumerable: true,
480
- get: function() {
481
- return _objectWithoutProperties;
482
- }
483
- });
484
- Object.defineProperty(exports, "assetDataToUint8Array", {
485
- enumerable: true,
486
- get: function() {
487
- return assetDataToUint8Array;
488
- }
489
- });
490
- Object.defineProperty(exports, "assetToData", {
491
- enumerable: true,
492
- get: function() {
493
- return assetToData;
494
- }
495
- });
496
- Object.defineProperty(exports, "calmLensError", {
497
- enumerable: true,
498
- get: function() {
499
- return calmLensError;
500
- }
501
- });
502
- Object.defineProperty(exports, "getAssetPayloadByteLength", {
503
- enumerable: true,
504
- get: function() {
505
- return getAssetPayloadByteLength;
506
- }
507
- });
508
- Object.defineProperty(exports, "getRawBase64", {
509
- enumerable: true,
510
- get: function() {
511
- return getRawBase64;
512
- }
513
- });
514
- Object.defineProperty(exports, "getRejectedUploadMimeTypeError", {
515
- enumerable: true,
516
- get: function() {
517
- return getRejectedUploadMimeTypeError;
518
- }
519
- });
520
- Object.defineProperty(exports, "isRejectedUploadMimeType", {
521
- enumerable: true,
522
- get: function() {
523
- return isRejectedUploadMimeType;
524
- }
525
- });
526
- Object.defineProperty(exports, "stringifyJsonCanonical", {
527
- enumerable: true,
528
- get: function() {
529
- return stringifyJsonCanonical;
530
- }
531
- });
532
- Object.defineProperty(exports, "toTextAssetOptions", {
533
- enumerable: true,
534
- get: function() {
535
- return toTextAssetOptions;
536
- }
537
- });
538
- Object.defineProperty(exports, "validateAssetPayload", {
539
- enumerable: true,
540
- get: function() {
541
- return validateAssetPayload;
542
- }
543
- });
544
- Object.defineProperty(exports, "verifyWebhookSignature", {
545
- enumerable: true,
546
- get: function() {
547
- return verifyWebhookSignature;
548
- }
549
- });