calmlens 0.18.3 → 0.19.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/bin/calmlens.js +5373 -5002
- package/cjs/{BrowserUpload-UxIAGNdv.js → BrowserUpload-CJ4Xc9bR.js} +1 -1
- package/cjs/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-RkxV_Vv7.d.ts} +2 -2
- package/{esm/CalmLensAppClient-CV_K26Ce.d.ts → cjs/CalmLensAppClient-B5gfOB6J.d.ts} +3 -3
- package/cjs/{CalmLensAppClient-D6p7MAFz.js → CalmLensAppClient-LHMEQ-UZ.js} +32 -11
- package/cjs/{CalmLensConnection-CYoUl5go.js → CalmLensOptionKeys-BUj7v5AG.js} +368 -8
- package/cjs/{CalmLensServerClient-p23cl97D.js → CalmLensServerClient-BVOEUT_v.js} +167 -54
- package/cjs/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-DCSbwIBs.d.ts} +53 -29
- package/cjs/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-DpU-hXq2.d.ts} +2677 -30
- package/cjs/{ModerationContextLimits-DCLXMxyA.js → ModerationContextLimits-FDpQmw_T.js} +195 -41
- package/cjs/{ReactUpload-BcdNWLiU.js → ReactUpload-BvpW4hJi.js} +1 -1
- package/cjs/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-huIMnOJ4.d.ts} +1 -1
- package/cjs/{TestTriggers-DTc_iMJF-BjMPq4_3.js → TestTriggers-CMwMrbjy-K0YBzu2a.js} +433 -73
- package/{esm/TestTriggers-By07LR31-CmK0yTyR.d.ts → cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
- package/cjs/{UploadController-Cxu0bufo.js → UploadController-D4qOZZc3.js} +17 -5
- package/{esm/WebhookPayload-2aL31v0J.d.ts → cjs/WebhookPayload-CQg8BBZQ.d.ts} +29 -3
- package/cjs/app.d.ts +6 -6
- package/cjs/app.js +2 -2
- package/cjs/elements.d.ts +3 -3
- package/cjs/elements.js +3 -3
- package/cjs/{index-CI4BzN4W.d.ts → index-BcDDQJF2.d.ts} +7 -6
- package/cjs/index.d.ts +5 -5
- package/cjs/index.js +1 -1
- package/cjs/react-native.d.ts +3 -3
- package/cjs/react-native.js +3 -3
- package/cjs/react.d.ts +3 -3
- package/cjs/react.js +4 -4
- package/cjs/server.d.ts +6 -6
- package/cjs/server.js +2 -2
- package/cjs/test-inputs.d.ts +1 -1
- package/cjs/test-inputs.js +9 -9
- package/cjs/testing.d.ts +7 -6
- package/cjs/testing.js +189 -29
- package/{esm/ui-wIiMfqMB.d.ts → cjs/ui-B23r8BvW.d.ts} +17 -4
- package/cjs/{ui-C0XXJS52.js → ui-Dq-cm6Rx.js} +13 -10
- package/cjs/ui.d.ts +2 -2
- package/cjs/ui.js +2 -2
- package/cjs/vue.d.ts +5 -5
- package/cjs/vue.js +3 -3
- package/esm/{BrowserUpload-BXG2isHV.js → BrowserUpload-DpzS2bbj.js} +1 -1
- package/esm/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-RkxV_Vv7.d.ts} +2 -2
- package/{cjs/CalmLensAppClient-CV_K26Ce.d.ts → esm/CalmLensAppClient-B5gfOB6J.d.ts} +3 -3
- package/esm/{CalmLensAppClient-BMgXamoN.js → CalmLensAppClient-BjlvBweS.js} +28 -7
- package/esm/{CalmLensConnection-DBoDh06c.js → CalmLensOptionKeys-BKez0Wiw.js} +351 -9
- package/esm/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-DCSbwIBs.d.ts} +53 -29
- package/esm/{CalmLensServerClient-Dt7rCITa.js → CalmLensServerClient-DemxbNMn.js} +159 -46
- package/esm/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-DpU-hXq2.d.ts} +2677 -30
- package/esm/{ModerationContextLimits-KMQ8puoa.js → ModerationContextLimits-lLfmyLni.js} +176 -40
- package/esm/{ReactUpload-CFy_wETY.js → ReactUpload-6klucehl.js} +1 -1
- package/esm/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-huIMnOJ4.d.ts} +1 -1
- package/esm/{TestTriggers-DTc_iMJF-HfB533Gx.js → TestTriggers-CMwMrbjy-bdowBBKw.js} +404 -71
- package/{cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts → esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
- package/esm/{UploadController-Cs-bxUbt.js → UploadController-UxP6gj7A.js} +17 -5
- package/{cjs/WebhookPayload-2aL31v0J.d.ts → esm/WebhookPayload-CQg8BBZQ.d.ts} +29 -3
- package/esm/app.d.ts +6 -6
- package/esm/app.js +2 -2
- package/esm/elements.d.ts +3 -3
- package/esm/elements.js +3 -3
- package/esm/{index-CI4BzN4W.d.ts → index-BcDDQJF2.d.ts} +7 -6
- package/esm/index.d.ts +5 -5
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +3 -3
- package/esm/react-native.js +3 -3
- package/esm/react.d.ts +3 -3
- package/esm/react.js +4 -4
- package/esm/server.d.ts +6 -6
- package/esm/server.js +2 -2
- package/esm/test-inputs.d.ts +1 -1
- package/esm/test-inputs.js +1 -1
- package/esm/testing.d.ts +7 -6
- package/esm/testing.js +178 -17
- package/{cjs/ui-wIiMfqMB.d.ts → esm/ui-B23r8BvW.d.ts} +17 -4
- package/esm/{ui-BqYkISSE.js → ui-Bn29rfAi.js} +12 -9
- package/esm/ui.d.ts +2 -2
- package/esm/ui.js +2 -2
- package/esm/vue.d.ts +5 -5
- package/esm/vue.js +3 -3
- package/package.json +1 -1
- package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +0 -91
- package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +0 -46
- /package/cjs/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
- /package/esm/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { r as VIEWER_CLAIMS_SCHEMA } from "./Jurisdiction-FusEXb4U-1ov6m5yE.js";
|
|
2
1
|
// src/client/CalmLensErrorCodes.ts
|
|
3
2
|
/** Error codes the CalmLens API documents, by name. */
|
|
4
3
|
const API_ERROR_CODES = {
|
|
@@ -7,6 +6,8 @@ const API_ERROR_CODES = {
|
|
|
7
6
|
INVALID_VIEWER_REGION: "viewer/invalid-region",
|
|
8
7
|
VIEWER_REGION_REQUIRED: "viewer/region-required",
|
|
9
8
|
REGIONAL_EVIDENCE_REQUIRED: "asset/regional-evidence-required",
|
|
9
|
+
SIGNED_URL_EXPIRED: "signed-url/expired",
|
|
10
|
+
SIGNED_URL_INVALID: "signed-url/invalid",
|
|
10
11
|
INVALID_TYPE: "validation/invalid-type",
|
|
11
12
|
TOO_SMALL: "validation/too-small",
|
|
12
13
|
TOO_BIG: "validation/too-big",
|
|
@@ -34,9 +35,11 @@ const API_ERROR_CODES = {
|
|
|
34
35
|
API_KEY_NOT_ACCEPTED: "auth/api-key-not-accepted",
|
|
35
36
|
PERMISSION_DENIED: "auth/permission-denied",
|
|
36
37
|
FILE_TOO_LARGE: "upload/file-too-large",
|
|
37
|
-
MULTIPART_IMAGE_TOO_SMALL: "upload/multipart-image-too-small",
|
|
38
38
|
MULTIPART_IMAGE_TOO_LARGE: "upload/multipart-image-too-large",
|
|
39
39
|
IMAGE_EXCEEDED_MAX_DIMENSIONS: "upload/image-exceeded-max-dimensions",
|
|
40
|
+
IMAGE_INVALID_INPUT: "image/invalid-input",
|
|
41
|
+
IMAGE_UNSUPPORTED_FORMAT: "image/unsupported-format",
|
|
42
|
+
IMAGE_INPUT_LIMIT: "image/input-limit",
|
|
40
43
|
UPLOAD_LIMIT_EXCEEDED: "upload/limit-exceeded",
|
|
41
44
|
SPEND_LIMIT_REACHED: "upload/spend-limit-reached",
|
|
42
45
|
INVALID_UPLOAD_MIME_TYPE: "upload/invalid-mime-type",
|
|
@@ -77,6 +80,15 @@ const API_ERROR_CODES = {
|
|
|
77
80
|
HASH_LIST_LIMIT_REACHED: "hash-list/limit-reached",
|
|
78
81
|
HASH_LIST_ENTRY_LIMIT_REACHED: "hash-list/entry-limit-reached",
|
|
79
82
|
HASH_LIST_ASSET_NOT_HASHED: "hash-list/asset-not-hashed",
|
|
83
|
+
POLICY_NOT_FOUND: "policy/not-found",
|
|
84
|
+
POLICY_REVISION_CONFLICT: "policy/revision-conflict",
|
|
85
|
+
POLICY_PROJECTS_CHANGED: "policy/projects-changed",
|
|
86
|
+
POLICY_IN_USE: "policy/in-use",
|
|
87
|
+
POLICY_USED_BY_ANOTHER_PROJECT: "policy/used-by-another-project",
|
|
88
|
+
POLICY_NO_PRESET: "policy/no-preset",
|
|
89
|
+
POLICY_PRESET_VERSION_CONFLICT: "policy/preset-version-conflict",
|
|
90
|
+
POLICY_PRESET_UPDATE_UNAVAILABLE: "policy/preset-update-unavailable",
|
|
91
|
+
POLICY_AUTOMATIC_UPDATES_UNAVAILABLE: "policy/automatic-updates-unavailable",
|
|
80
92
|
UPLOAD_PRESET_NOT_FOUND: "upload-preset/not-found",
|
|
81
93
|
UPLOAD_PRESET_DISABLED: "upload-preset/disabled",
|
|
82
94
|
UPLOAD_PRESET_TOKEN_REQUIRED: "upload-preset/token-required",
|
|
@@ -124,6 +136,14 @@ const API_ERROR_DEFINITIONS = {
|
|
|
124
136
|
status: 403,
|
|
125
137
|
message: "This asset needs moderation evidence for the newly served jurisdiction."
|
|
126
138
|
},
|
|
139
|
+
"signed-url/expired": {
|
|
140
|
+
status: 403,
|
|
141
|
+
message: "The signed URL has expired. Create a new one on your server."
|
|
142
|
+
},
|
|
143
|
+
"signed-url/invalid": {
|
|
144
|
+
status: 403,
|
|
145
|
+
message: "The signed URL's signature doesn't match its asset, resource, lens, transform, expiry or viewer claims. Use the URL exactly as created."
|
|
146
|
+
},
|
|
127
147
|
"validation/invalid-type": {
|
|
128
148
|
status: 400,
|
|
129
149
|
message: "A field has the wrong type. details.issues lists each problem."
|
|
@@ -232,10 +252,6 @@ const API_ERROR_DEFINITIONS = {
|
|
|
232
252
|
status: 400,
|
|
233
253
|
message: "File size exceeds limit. Maximum direct image size is 10 MiB, audio/video size is 50 MiB, and other files is 5,000 MiB."
|
|
234
254
|
},
|
|
235
|
-
"upload/multipart-image-too-small": {
|
|
236
|
-
status: 400,
|
|
237
|
-
message: "Multipart image uploads must total at least 10 MiB."
|
|
238
|
-
},
|
|
239
255
|
"upload/multipart-image-too-large": {
|
|
240
256
|
status: 400,
|
|
241
257
|
message: "Multipart image uploads cannot exceed 20 MiB."
|
|
@@ -244,6 +260,18 @@ const API_ERROR_DEFINITIONS = {
|
|
|
244
260
|
status: 400,
|
|
245
261
|
message: "Image exceeds maximum dimensions. Maximum dimensions are 12,000px."
|
|
246
262
|
},
|
|
263
|
+
"image/invalid-input": {
|
|
264
|
+
status: 422,
|
|
265
|
+
message: "The image is corrupt or cannot be decoded. Upload a valid image file."
|
|
266
|
+
},
|
|
267
|
+
"image/unsupported-format": {
|
|
268
|
+
status: 422,
|
|
269
|
+
message: "This image format is not supported. Convert it to PNG, JPEG or WebP before uploading."
|
|
270
|
+
},
|
|
271
|
+
"image/input-limit": {
|
|
272
|
+
status: 422,
|
|
273
|
+
message: "The image exceeds the processing byte or pixel limit. Reduce its size before uploading."
|
|
274
|
+
},
|
|
247
275
|
"upload/limit-exceeded": {
|
|
248
276
|
status: 403,
|
|
249
277
|
message: "Upload limit exceeded. This project's organisation has used its free uploads. Set up billing to continue uploading."
|
|
@@ -404,6 +432,42 @@ const API_ERROR_DEFINITIONS = {
|
|
|
404
432
|
status: 409,
|
|
405
433
|
message: "This asset has no perceptual hash. Only image assets that finished processing can be added."
|
|
406
434
|
},
|
|
435
|
+
"policy/not-found": {
|
|
436
|
+
status: 404,
|
|
437
|
+
message: "Policy not found. Check the policy ID in the portal."
|
|
438
|
+
},
|
|
439
|
+
"policy/revision-conflict": {
|
|
440
|
+
status: 409,
|
|
441
|
+
message: "The policy changed. Retrieve it again and retry with its current revision."
|
|
442
|
+
},
|
|
443
|
+
"policy/projects-changed": {
|
|
444
|
+
status: 409,
|
|
445
|
+
message: "The projects using this policy changed. Retrieve it again and review the affected projects before saving."
|
|
446
|
+
},
|
|
447
|
+
"policy/in-use": {
|
|
448
|
+
status: 409,
|
|
449
|
+
message: "Projects or upload presets still use this policy. Choose another policy for each of them before deleting it."
|
|
450
|
+
},
|
|
451
|
+
"policy/used-by-another-project": {
|
|
452
|
+
status: 409,
|
|
453
|
+
message: "Another project uses or owns this policy, so it can only be changed from the portal or that project."
|
|
454
|
+
},
|
|
455
|
+
"policy/no-preset": {
|
|
456
|
+
status: 400,
|
|
457
|
+
message: "This policy has no preset baseline."
|
|
458
|
+
},
|
|
459
|
+
"policy/preset-version-conflict": {
|
|
460
|
+
status: 409,
|
|
461
|
+
message: "The preset changed. Review the latest differences and retry with its version."
|
|
462
|
+
},
|
|
463
|
+
"policy/preset-update-unavailable": {
|
|
464
|
+
status: 409,
|
|
465
|
+
message: "Only an unchanged copy of an older preset version can be updated. Reset or review your changes first."
|
|
466
|
+
},
|
|
467
|
+
"policy/automatic-updates-unavailable": {
|
|
468
|
+
status: 409,
|
|
469
|
+
message: "Automatic updates can only be switched on for a saved copy of a project's preset policy, and off for one that has them."
|
|
470
|
+
},
|
|
407
471
|
"upload-preset/not-found": {
|
|
408
472
|
status: 404,
|
|
409
473
|
message: "Upload preset not found. Check the preset ID in the portal."
|
|
@@ -592,7 +656,7 @@ const invalidArgument = (message, details) => new CalmLensError(SDK_ERROR_CODES.
|
|
|
592
656
|
details
|
|
593
657
|
});
|
|
594
658
|
const invalidConfig = (message) => new CalmLensError(SDK_ERROR_CODES.INVALID_CONFIG, { message });
|
|
595
|
-
// src/contract/SharedConstants-
|
|
659
|
+
// src/contract/SharedConstants-CrqW8Uco.js
|
|
596
660
|
const IMPERSONATION_COOKIE_NAME = "CL_impersonation";
|
|
597
661
|
const DAY_MS = 864e5;
|
|
598
662
|
const YEAR_MS = 365 * DAY_MS;
|
|
@@ -790,7 +854,9 @@ const THIRD_PARTY_COOKIES = {
|
|
|
790
854
|
};
|
|
791
855
|
[...Object.values(FIRST_PARTY_COOKIES), ...Object.values(THIRD_PARTY_COOKIES)];
|
|
792
856
|
const MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
793
|
-
const
|
|
857
|
+
const MAX_DIRECT_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
858
|
+
const MAX_NON_IMAGE_UPLOAD_MB = 5e3;
|
|
859
|
+
const MAX_NON_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => MAX_NON_IMAGE_UPLOAD_MB * 1024 * 1024)();
|
|
794
860
|
const REJECTED_UPLOAD_MIME_TYPE_SET = /* @__PURE__ */ new Set([
|
|
795
861
|
"application/octet-stream",
|
|
796
862
|
"multipart/form-data",
|
|
@@ -804,6 +870,26 @@ const normalizeUploadMimeType = (mimeType) => mimeType.toLowerCase().split(";")[
|
|
|
804
870
|
const isRejectedUploadMimeType = (mimeType) => REJECTED_UPLOAD_MIME_TYPE_SET.has(normalizeUploadMimeType(mimeType));
|
|
805
871
|
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.`;
|
|
806
872
|
const DOMAIN = "calmlens.com";
|
|
873
|
+
// src/client/CalmLensViewerClaims.ts
|
|
874
|
+
/** The ISO 3166-1 alpha-2 countries a viewer's `region` can be. EU is not a viewer country. */
|
|
875
|
+
const 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(" "));
|
|
876
|
+
/** The European Union's member countries, which the `EU` jurisdiction covers. */
|
|
877
|
+
const 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(" "));
|
|
878
|
+
/**
|
|
879
|
+
* The claims to send, with `region` and `ageConfirmed` in that order, or `undefined` when the
|
|
880
|
+
* value isn't an object of only a viewer country `region` and a boolean `ageConfirmed`.
|
|
881
|
+
*/
|
|
882
|
+
const parseViewerClaims = (value) => {
|
|
883
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
884
|
+
const { region, ageConfirmed, ...rest } = value;
|
|
885
|
+
if (Object.keys(rest).length) return void 0;
|
|
886
|
+
if (region !== void 0 && (typeof region !== "string" || !VIEWER_COUNTRIES.has(region))) return void 0;
|
|
887
|
+
if (ageConfirmed !== void 0 && typeof ageConfirmed !== "boolean") return void 0;
|
|
888
|
+
return {
|
|
889
|
+
...region !== void 0 && { region },
|
|
890
|
+
...ageConfirmed !== void 0 && { ageConfirmed }
|
|
891
|
+
};
|
|
892
|
+
};
|
|
807
893
|
// src/client/CalmLensUtils.ts
|
|
808
894
|
const assertHttpUrl = (name, value) => {
|
|
809
895
|
if (value === void 0) return;
|
|
@@ -828,6 +914,8 @@ const validateConnectionOptions = (options) => {
|
|
|
828
914
|
if ("requestBackend" in options) throw invalidConfig("requestBackend is no longer supported; pass a fetch implementation as fetch");
|
|
829
915
|
validateRequestOptions(options);
|
|
830
916
|
assertInteger("maxResponseBytes", options.maxResponseBytes, 1);
|
|
917
|
+
const { partSizeBytes } = options;
|
|
918
|
+
if (partSizeBytes !== void 0 && (!Number.isSafeInteger(partSizeBytes) || partSizeBytes < 5242880 || partSizeBytes > 67108864)) throw invalidConfig("partSizeBytes must be an integer from 5 MiB (5242880) to 64 MiB (67108864)");
|
|
831
919
|
for (const name of ["fetch", "uploadFetch"]) if (options[name] !== void 0 && typeof options[name] !== "function") throw invalidConfig(`${name} must be a function`);
|
|
832
920
|
assertHttpUrl("baseUrl", options.baseUrl);
|
|
833
921
|
};
|
|
@@ -859,8 +947,61 @@ const validateRequestOptions = (options) => {
|
|
|
859
947
|
assertInteger("uploadTimeoutMs", options.uploadTimeoutMs, 1);
|
|
860
948
|
assertInteger("maxRetries", options.maxRetries, 0);
|
|
861
949
|
};
|
|
950
|
+
/**
|
|
951
|
+
* Option keys of methods that send no request of their own, or that take keys of their own beside
|
|
952
|
+
* a request's; CalmLensOptionKeys, generated from the API, has the rest.
|
|
953
|
+
*/
|
|
954
|
+
const LOCAL_OPTION_KEYS = {
|
|
955
|
+
"assets.waitForDecision": [
|
|
956
|
+
"assetId",
|
|
957
|
+
"signal",
|
|
958
|
+
"timeoutMs"
|
|
959
|
+
],
|
|
960
|
+
"cdn.getAssetUrl": [
|
|
961
|
+
"assetIdentifier",
|
|
962
|
+
"lens",
|
|
963
|
+
"resource",
|
|
964
|
+
"transform",
|
|
965
|
+
"viewerClaims"
|
|
966
|
+
],
|
|
967
|
+
"cdn.serve": [
|
|
968
|
+
"assetIdentifier",
|
|
969
|
+
"init",
|
|
970
|
+
"lens",
|
|
971
|
+
"resource",
|
|
972
|
+
"transform",
|
|
973
|
+
"viewerClaims"
|
|
974
|
+
],
|
|
975
|
+
"uploadTokens.sign": [
|
|
976
|
+
"expiresInSeconds",
|
|
977
|
+
"externalId",
|
|
978
|
+
"uploadPresetId"
|
|
979
|
+
]
|
|
980
|
+
};
|
|
981
|
+
/** Uploads also take an `idempotencyKey`, which the SDK sends as a header. */
|
|
982
|
+
const IDEMPOTENT_OPERATIONS = [
|
|
983
|
+
"assets.create",
|
|
984
|
+
"assets.classify",
|
|
985
|
+
"assets.uploadPart",
|
|
986
|
+
"text.classify"
|
|
987
|
+
];
|
|
988
|
+
/**
|
|
989
|
+
* Throws `sdk/invalid-argument` for an option `operation` doesn't take, such as a misspelt key,
|
|
990
|
+
* instead of silently dropping it. `apiKeys` is the client's generated table of the keys each
|
|
991
|
+
* method sends to the API. Anything other than an object is left to the method's own checks.
|
|
992
|
+
*/
|
|
993
|
+
const checkOptionKeys = (options, operation, apiKeys) => {
|
|
994
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) return;
|
|
995
|
+
const allowed = LOCAL_OPTION_KEYS[operation] ?? apiKeys[operation];
|
|
996
|
+
if (!allowed) throw new Error(`No option keys for ${operation}`);
|
|
997
|
+
const unknown = Object.keys(options).filter((key) => !allowed.includes(key) && !(key === "idempotencyKey" && IDEMPOTENT_OPERATIONS.includes(operation)));
|
|
998
|
+
if (unknown.length) throw invalidArgument(`Unknown option${unknown.length > 1 ? "s" : ""} for ${operation}: ${unknown.join(", ")}`, {
|
|
999
|
+
operation,
|
|
1000
|
+
options: unknown
|
|
1001
|
+
});
|
|
1002
|
+
};
|
|
862
1003
|
const toTextAssetOptions = ({ text, name, ...options }) => {
|
|
863
|
-
if (typeof text !== "string" || !text.trim()) throw
|
|
1004
|
+
if (typeof text !== "string" || !text.trim()) throw invalidArgument("Text to classify must be a non-empty string");
|
|
864
1005
|
return {
|
|
865
1006
|
...options,
|
|
866
1007
|
name: name ?? "text",
|
|
@@ -924,28 +1065,26 @@ const appendTransformOptions = (pairs, key, value) => {
|
|
|
924
1065
|
pairs.push(`${key}=${encodeTransformComponent(text)}`);
|
|
925
1066
|
};
|
|
926
1067
|
/**
|
|
927
|
-
* Serializes structured
|
|
928
|
-
*
|
|
929
|
-
*
|
|
1068
|
+
* Serializes structured transform options as a CDN selector, such as `fit=cover,width=640`. Option
|
|
1069
|
+
* keys are sorted so equal transforms share a URL, nested keys are dotted (`border.color`),
|
|
1070
|
+
* colours are hex without `#`, and values are percent-encoded.
|
|
930
1071
|
*/
|
|
931
1072
|
const serializeTransform = (transform) => {
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
if (!
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
if (!TRANSFORM_OPTION_NAME.test(key)) throw invalidArgument(`Transform option "${key}" is not a valid name`);
|
|
941
|
-
appendTransformOptions(pairs, key, step.options[key]);
|
|
942
|
-
}
|
|
943
|
-
if (pairs.length === 0) throw invalidArgument("Transform steps need at least one option");
|
|
944
|
-
return pairs.join(",");
|
|
945
|
-
}).join("/");
|
|
1073
|
+
if (!isPlainObject(transform)) throw invalidArgument("Transform options must be an object");
|
|
1074
|
+
const pairs = [];
|
|
1075
|
+
for (const key of Object.keys(transform).sort()) {
|
|
1076
|
+
if (!TRANSFORM_OPTION_NAME.test(key)) throw invalidArgument(`Transform option "${key}" is not a valid name`);
|
|
1077
|
+
appendTransformOptions(pairs, key, transform[key]);
|
|
1078
|
+
}
|
|
1079
|
+
if (pairs.length === 0) throw invalidArgument("A transform needs at least one option");
|
|
1080
|
+
return pairs.join(",");
|
|
946
1081
|
};
|
|
947
1082
|
/** Returns the selector string the API and CDN accept for a string or structured transform. */
|
|
948
|
-
const transformSelector = (transform) =>
|
|
1083
|
+
const transformSelector = (transform) => {
|
|
1084
|
+
if (transform === void 0 || typeof transform !== "string") return transform === void 0 ? void 0 : serializeTransform(transform);
|
|
1085
|
+
if (/[/?#]/.test(transform) || transform.includes("..") || transform.startsWith("@")) throw invalidArgument("Transform cannot contain \"/\", \"..\", \"?\" or \"#\", or start with \"@\"");
|
|
1086
|
+
return transform;
|
|
1087
|
+
};
|
|
949
1088
|
const DEFAULT_CDN_BASE_URL = `https://cdn.${DOMAIN}/v1`;
|
|
950
1089
|
const CDN_RESOURCES = /* @__PURE__ */ new Set([
|
|
951
1090
|
"original",
|
|
@@ -992,19 +1131,16 @@ const appendCdnSelector = (url, options) => {
|
|
|
992
1131
|
const path = appendCdnPathSelector(url, options);
|
|
993
1132
|
const query = new URLSearchParams();
|
|
994
1133
|
if (options.viewerClaims !== void 0) {
|
|
995
|
-
const claims =
|
|
996
|
-
if (!claims
|
|
997
|
-
query.set("viewerClaims", JSON.stringify(claims
|
|
1134
|
+
const claims = parseViewerClaims(options.viewerClaims);
|
|
1135
|
+
if (!claims) throw invalidArgument("Invalid viewerClaims");
|
|
1136
|
+
query.set("viewerClaims", JSON.stringify(claims));
|
|
998
1137
|
}
|
|
999
1138
|
return query.size ? `${path}?${query}` : path;
|
|
1000
1139
|
};
|
|
1001
1140
|
const appendCdnPathSelector = (url, options) => {
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
const transform = options.transform.replace(/^\/+/, "");
|
|
1006
|
-
if (transform.includes("..") || transform.includes("?") || transform.includes("#")) throw invalidArgument("Transform cannot contain \"..\", \"?\" or \"#\"");
|
|
1007
|
-
return `${url}/${encodeURI(transform)}`;
|
|
1141
|
+
const transform = transformSelector(options.transform);
|
|
1142
|
+
const selector = [...options.lens ? [`@${encodePathSegment(options.lens, "Lens")}`] : [], ...transform ? [typeof options.transform === "string" ? encodeURI(transform) : transform] : []].join(",");
|
|
1143
|
+
return selector ? `${url}/${selector}` : url;
|
|
1008
1144
|
};
|
|
1009
1145
|
const appendQueryValue = (parts, key, value) => {
|
|
1010
1146
|
if (value === void 0 || value === null) return;
|
|
@@ -1034,11 +1170,11 @@ const stringifyQuery = (query) => {
|
|
|
1034
1170
|
*/
|
|
1035
1171
|
const isAssetDecided = (asset) => asset.classification.moderation.status !== "pending" || asset.classification.status === "failed";
|
|
1036
1172
|
const DECISION_POLL_DELAY_FACTOR = 1.5;
|
|
1037
|
-
const DECISION_POLL_MAX_DELAY_MS =
|
|
1173
|
+
const DECISION_POLL_MAX_DELAY_MS = 2e3;
|
|
1038
1174
|
const DEFAULT_DECISION_TIMEOUT_MS = 6e4;
|
|
1039
1175
|
/**
|
|
1040
1176
|
* Retrieves an asset until it has a decision, waiting 0.5s between checks and 1.5 times longer
|
|
1041
|
-
* each time, up to
|
|
1177
|
+
* each time, up to 2s. Rejects with `sdk/timeout` once `timeoutMs` passes without one.
|
|
1042
1178
|
*/
|
|
1043
1179
|
const pollForDecision = async (retrieve, { timeoutMs = DEFAULT_DECISION_TIMEOUT_MS, signal }, sleep, now = Date.now) => {
|
|
1044
1180
|
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) throw invalidArgument("timeoutMs must be a non-negative number");
|
|
@@ -1063,7 +1199,7 @@ const pollForDecision = async (retrieve, { timeoutMs = DEFAULT_DECISION_TIMEOUT_
|
|
|
1063
1199
|
};
|
|
1064
1200
|
// src/client/CalmLensVersion.ts
|
|
1065
1201
|
/** This SDK's version, from its package.json. */
|
|
1066
|
-
const SDK_VERSION = "0.
|
|
1202
|
+
const SDK_VERSION = "0.19.0";
|
|
1067
1203
|
const runtimeName = () => {
|
|
1068
1204
|
const runtime = globalThis;
|
|
1069
1205
|
if (isReactNativeRuntime()) return "react-native";
|
|
@@ -1111,4 +1247,4 @@ const selectModerationContextItems = (items) => {
|
|
|
1111
1247
|
}
|
|
1112
1248
|
return selected;
|
|
1113
1249
|
};
|
|
1114
|
-
export {
|
|
1250
|
+
export { CALMLENS_ERROR_CODES as A, EU_COUNTRIES as C, MAX_NON_IMAGE_UPLOAD_BYTES as D, MAX_IMAGE_UPLOAD_BYTES as E, API_ERROR_CODES as F, API_ERROR_DEFINITIONS as I, SDK_ERROR_CODES as M, invalidArgument as N, getRejectedUploadMimeTypeError as O, invalidConfig as P, validateSignedUrlOptions as S, MAX_DIRECT_IMAGE_UPLOAD_BYTES as T, transformSelector as _, getUserAgent as a, validateRequestOptions as b, DEFAULT_CDN_BASE_URL as c, getAssetUrl as d, pollForDecision as f, toTextAssetOptions as g, stringifyQuery as h, SDK_VERSION as i, CalmLensError as j, isRejectedUploadMimeType as k, checkOptionKeys as l, serializeTransform as m, MODERATION_CONTEXT_USED_ITEMS as n, isBrowserRuntime as o, randomUuid as p, selectModerationContextItems as r, isReactNativeRuntime as s, MODERATION_CONTEXT_USED_CHARACTERS as t, encodePathSegment as u, validateAppClientOptions as v, DOMAIN as w, validateServerClientOptions as x, validateBatchAssetsOptions as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createUploadController } from "./UploadController-
|
|
1
|
+
import { n as createUploadController } from "./UploadController-UxP6gj7A.js";
|
|
2
2
|
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
// src/ui/ReactUpload.ts
|
|
4
4
|
/** Re-renders with a controller's snapshot. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { F as UploadFile, L as UploadSnapshot, N as UploadController, P as UploadControllerOptions } from "./ui-B23r8BvW.js";
|
|
2
2
|
interface UseCalmLensUploadResult<F extends UploadFile = UploadFile> extends UploadSnapshot<F> {
|
|
3
3
|
controller: UploadController<F>;
|
|
4
4
|
addFiles: UploadController<F>["addFiles"];
|