calmlens 0.18.3 → 0.20.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 (82) hide show
  1. package/bin/calmlens.js +5682 -5036
  2. package/cjs/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-C07aL9Vq.d.ts} +2 -2
  3. package/cjs/{BrowserUpload-UxIAGNdv.js → BrowserUpload-CjSHjx3C.js} +1 -1
  4. package/{esm/CalmLensAppClient-CV_K26Ce.d.ts → cjs/CalmLensAppClient-DDLojj0P.d.ts} +3 -3
  5. package/cjs/{CalmLensAppClient-D6p7MAFz.js → CalmLensAppClient-NaCxOVlM.js} +32 -11
  6. package/cjs/{CalmLensConnection-CYoUl5go.js → CalmLensOptionKeys-p2QK687A.js} +430 -9
  7. package/cjs/{CalmLensServerClient-p23cl97D.js → CalmLensServerClient-BDzTthxE.js} +173 -55
  8. package/cjs/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-C-jsjn8m.d.ts} +54 -30
  9. package/cjs/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-COJbOuiv.d.ts} +2677 -30
  10. package/cjs/{ModerationContextLimits-DCLXMxyA.js → ModerationContextLimits-2nIv7Zh3.js} +495 -49
  11. package/cjs/{ReactUpload-BcdNWLiU.js → ReactUpload-BdTRCTGA.js} +1 -1
  12. package/cjs/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-CRJNPB5T.d.ts} +1 -1
  13. package/{esm/TestTriggers-By07LR31-CmK0yTyR.d.ts → cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
  14. package/cjs/{TestTriggers-DTc_iMJF-BjMPq4_3.js → TestTriggers-DbhsNPdg-DjvVuc2h.js} +434 -74
  15. package/cjs/{UploadController-Cxu0bufo.js → UploadController-MLVs97Zt.js} +17 -5
  16. package/{esm/WebhookPayload-2aL31v0J.d.ts → cjs/WebhookPayload-DkukERKE.d.ts} +29 -3
  17. package/cjs/app.d.ts +6 -6
  18. package/cjs/app.js +2 -2
  19. package/cjs/elements.d.ts +3 -3
  20. package/cjs/elements.js +3 -3
  21. package/cjs/{index-CI4BzN4W.d.ts → index-DxbJ_Xaa.d.ts} +7 -6
  22. package/cjs/index.d.ts +5 -5
  23. package/cjs/index.js +1 -1
  24. package/cjs/react-native.d.ts +3 -3
  25. package/cjs/react-native.js +3 -3
  26. package/cjs/react.d.ts +3 -3
  27. package/cjs/react.js +4 -4
  28. package/cjs/server.d.ts +6 -6
  29. package/cjs/server.js +2 -2
  30. package/cjs/test-inputs.d.ts +1 -1
  31. package/cjs/test-inputs.js +9 -9
  32. package/cjs/testing.d.ts +12 -8
  33. package/cjs/testing.js +298 -35
  34. package/{esm/ui-wIiMfqMB.d.ts → cjs/ui-BSqPGKrZ.d.ts} +17 -4
  35. package/cjs/{ui-C0XXJS52.js → ui-CX1z2pD9.js} +13 -10
  36. package/cjs/ui.d.ts +2 -2
  37. package/cjs/ui.js +2 -2
  38. package/cjs/vue.d.ts +5 -5
  39. package/cjs/vue.js +3 -3
  40. package/esm/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-C07aL9Vq.d.ts} +2 -2
  41. package/esm/{BrowserUpload-BXG2isHV.js → BrowserUpload-CAVkRotw.js} +1 -1
  42. package/{cjs/CalmLensAppClient-CV_K26Ce.d.ts → esm/CalmLensAppClient-DDLojj0P.d.ts} +3 -3
  43. package/esm/{CalmLensAppClient-BMgXamoN.js → CalmLensAppClient-PQ9VBvlW.js} +28 -7
  44. package/esm/{CalmLensConnection-DBoDh06c.js → CalmLensOptionKeys-Do2mPP6w.js} +407 -10
  45. package/esm/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-C-jsjn8m.d.ts} +54 -30
  46. package/esm/{CalmLensServerClient-Dt7rCITa.js → CalmLensServerClient-C_H5aAsV.js} +165 -47
  47. package/esm/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-COJbOuiv.d.ts} +2677 -30
  48. package/esm/{ModerationContextLimits-KMQ8puoa.js → ModerationContextLimits-Chw-AzgL.js} +462 -46
  49. package/esm/{ReactUpload-CFy_wETY.js → ReactUpload-CMmL0R5Q.js} +1 -1
  50. package/esm/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-CRJNPB5T.d.ts} +1 -1
  51. package/{cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts → esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
  52. package/esm/{TestTriggers-DTc_iMJF-HfB533Gx.js → TestTriggers-DbhsNPdg-CUdrv8Nm.js} +405 -72
  53. package/esm/{UploadController-Cs-bxUbt.js → UploadController-BJZghJpg.js} +17 -5
  54. package/{cjs/WebhookPayload-2aL31v0J.d.ts → esm/WebhookPayload-DkukERKE.d.ts} +29 -3
  55. package/esm/app.d.ts +6 -6
  56. package/esm/app.js +2 -2
  57. package/esm/elements.d.ts +3 -3
  58. package/esm/elements.js +3 -3
  59. package/esm/{index-CI4BzN4W.d.ts → index-DxbJ_Xaa.d.ts} +7 -6
  60. package/esm/index.d.ts +5 -5
  61. package/esm/index.js +1 -1
  62. package/esm/react-native.d.ts +3 -3
  63. package/esm/react-native.js +3 -3
  64. package/esm/react.d.ts +3 -3
  65. package/esm/react.js +4 -4
  66. package/esm/server.d.ts +6 -6
  67. package/esm/server.js +2 -2
  68. package/esm/test-inputs.d.ts +1 -1
  69. package/esm/test-inputs.js +1 -1
  70. package/esm/testing.d.ts +12 -8
  71. package/esm/testing.js +287 -23
  72. package/{cjs/ui-wIiMfqMB.d.ts → esm/ui-BSqPGKrZ.d.ts} +17 -4
  73. package/esm/{ui-BqYkISSE.js → ui-CXH7xJpb.js} +12 -9
  74. package/esm/ui.d.ts +2 -2
  75. package/esm/ui.js +2 -2
  76. package/esm/vue.d.ts +5 -5
  77. package/esm/vue.js +3 -3
  78. package/package.json +1 -1
  79. package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +0 -91
  80. package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +0 -46
  81. /package/cjs/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
  82. /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 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 one of the organisation's own preset policies, 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-CyiUWW66.js
659
+ // src/contract/SharedConstants-DxUCZwLZ.js
596
660
  const IMPERSONATION_COOKIE_NAME = "CL_impersonation";
597
661
  const DAY_MS = 864e5;
598
662
  const YEAR_MS = 365 * DAY_MS;
@@ -790,8 +854,159 @@ 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 MIN_MULTIPART_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
794
- const REJECTED_UPLOAD_MIME_TYPE_SET = /* @__PURE__ */ new Set([
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)();
860
+ const normalizeUploadMimeType = (mimeType) => mimeType.toLowerCase().split(";")[0]?.trim() || mimeType.toLowerCase().trim();
861
+ 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.`;
862
+ const DOMAIN = "calmlens.com";
863
+ // src/client/CalmLensTransformSchema.ts
864
+ /** The image transform options' schema, with only the rules the SDK checks. */
865
+ const TRANSFORM_OPTIONS_SCHEMA = {
866
+ type: "object",
867
+ properties: {
868
+ format: {
869
+ type: "string",
870
+ enum: [
871
+ "jpg",
872
+ "png",
873
+ "webp",
874
+ "avif",
875
+ "gif"
876
+ ]
877
+ },
878
+ width: {
879
+ type: "integer",
880
+ minimum: 1,
881
+ maximum: 1e4
882
+ },
883
+ height: {
884
+ type: "integer",
885
+ minimum: 1,
886
+ maximum: 1e4
887
+ },
888
+ dpr: {
889
+ type: "number",
890
+ minimum: 1,
891
+ maximum: 3
892
+ },
893
+ anim: { type: "boolean" },
894
+ background: { type: "string" },
895
+ blur: { type: "number" },
896
+ redact: {
897
+ type: "object",
898
+ properties: {
899
+ text: { type: "boolean" },
900
+ personalInformation: { type: "boolean" },
901
+ faces: { type: "boolean" }
902
+ }
903
+ },
904
+ border: {
905
+ type: "object",
906
+ properties: {
907
+ color: { type: "string" },
908
+ width: { type: "number" }
909
+ }
910
+ },
911
+ brightness: { type: "number" },
912
+ contrast: { type: "number" },
913
+ quality: { oneOf: [{
914
+ type: "integer",
915
+ minimum: 1,
916
+ maximum: 100
917
+ }, {
918
+ type: "string",
919
+ enum: [
920
+ "low",
921
+ "medium",
922
+ "high"
923
+ ]
924
+ }] },
925
+ fit: {
926
+ type: "string",
927
+ enum: [
928
+ "scale-down",
929
+ "contain",
930
+ "pad",
931
+ "squeeze",
932
+ "cover",
933
+ "crop"
934
+ ]
935
+ },
936
+ flip: {
937
+ type: "string",
938
+ enum: [
939
+ "h",
940
+ "v",
941
+ "hv"
942
+ ]
943
+ },
944
+ gamma: { type: "number" },
945
+ segment: {
946
+ type: "string",
947
+ enum: ["foreground"]
948
+ },
949
+ gravity: { oneOf: [{
950
+ type: "string",
951
+ enum: [
952
+ "face",
953
+ "left",
954
+ "right",
955
+ "top",
956
+ "bottom",
957
+ "center",
958
+ "auto",
959
+ "entropy"
960
+ ]
961
+ }, {
962
+ type: "object",
963
+ properties: {
964
+ mode: {
965
+ type: "string",
966
+ enum: ["remainder", "box-center"]
967
+ },
968
+ x: { type: "number" },
969
+ y: { type: "number" }
970
+ },
971
+ required: ["mode"]
972
+ }] },
973
+ rotate: {
974
+ type: "integer",
975
+ enum: [
976
+ 0,
977
+ 90,
978
+ 180,
979
+ 270
980
+ ]
981
+ },
982
+ saturation: { type: "number" },
983
+ sharpen: { type: "number" },
984
+ trim: { oneOf: [{
985
+ type: "string",
986
+ enum: ["border"]
987
+ }, {
988
+ type: "object",
989
+ properties: {
990
+ top: { type: "number" },
991
+ bottom: { type: "number" },
992
+ left: { type: "number" },
993
+ right: { type: "number" },
994
+ width: { type: "number" },
995
+ height: { type: "number" },
996
+ border: { oneOf: [{ type: "boolean" }, {
997
+ type: "object",
998
+ properties: {
999
+ color: { type: "string" },
1000
+ tolerance: { type: "number" },
1001
+ keep: { type: "number" }
1002
+ }
1003
+ }] }
1004
+ }
1005
+ }] }
1006
+ }
1007
+ };
1008
+ // src/client/CalmLensUploadMimeTypes.ts
1009
+ const UPLOAD_MIME_REJECTED = [
795
1010
  "application/octet-stream",
796
1011
  "multipart/form-data",
797
1012
  "multipart/mixed",
@@ -799,11 +1014,47 @@ const REJECTED_UPLOAD_MIME_TYPE_SET = /* @__PURE__ */ new Set([
799
1014
  "multipart/related",
800
1015
  "multipart/signed",
801
1016
  "multipart/encrypted"
802
- ]);
803
- const normalizeUploadMimeType = (mimeType) => mimeType.toLowerCase().split(";")[0]?.trim() || mimeType.toLowerCase().trim();
804
- const isRejectedUploadMimeType = (mimeType) => REJECTED_UPLOAD_MIME_TYPE_SET.has(normalizeUploadMimeType(mimeType));
805
- 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
- const DOMAIN = "calmlens.com";
1017
+ ];
1018
+ const UPLOAD_MIME_PREFIXES = [
1019
+ "image/",
1020
+ "video/",
1021
+ "audio/",
1022
+ "text/"
1023
+ ];
1024
+ const UPLOAD_MIME_SUFFIXES = ["+json", "+xml"];
1025
+ const UPLOAD_MIME_TYPES = [
1026
+ "application/pdf",
1027
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1028
+ "application/msword",
1029
+ "application/rtf",
1030
+ "application/vnd.oasis.opendocument.text",
1031
+ "application/javascript",
1032
+ "application/json",
1033
+ "application/x-javascript",
1034
+ "application/x-yaml",
1035
+ "application/xml",
1036
+ "application/yaml"
1037
+ ];
1038
+ // src/client/CalmLensViewerClaims.ts
1039
+ /** The ISO 3166-1 alpha-2 countries a viewer's `region` can be. EU is not a viewer country. */
1040
+ 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(" "));
1041
+ /** The European Union's member countries, which the `EU` jurisdiction covers. */
1042
+ 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(" "));
1043
+ /**
1044
+ * The claims to send, with `region` and `ageConfirmed` in that order, or `undefined` when the
1045
+ * value isn't an object of only a viewer country `region` and a boolean `ageConfirmed`.
1046
+ */
1047
+ const parseViewerClaims = (value) => {
1048
+ if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
1049
+ const { region, ageConfirmed, ...rest } = value;
1050
+ if (Object.keys(rest).length) return void 0;
1051
+ if (region !== void 0 && (typeof region !== "string" || !VIEWER_COUNTRIES.has(region))) return void 0;
1052
+ if (ageConfirmed !== void 0 && typeof ageConfirmed !== "boolean") return void 0;
1053
+ return {
1054
+ ...region !== void 0 && { region },
1055
+ ...ageConfirmed !== void 0 && { ageConfirmed }
1056
+ };
1057
+ };
807
1058
  // src/client/CalmLensUtils.ts
808
1059
  const assertHttpUrl = (name, value) => {
809
1060
  if (value === void 0) return;
@@ -828,6 +1079,8 @@ const validateConnectionOptions = (options) => {
828
1079
  if ("requestBackend" in options) throw invalidConfig("requestBackend is no longer supported; pass a fetch implementation as fetch");
829
1080
  validateRequestOptions(options);
830
1081
  assertInteger("maxResponseBytes", options.maxResponseBytes, 1);
1082
+ const { partSizeBytes } = options;
1083
+ 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
1084
  for (const name of ["fetch", "uploadFetch"]) if (options[name] !== void 0 && typeof options[name] !== "function") throw invalidConfig(`${name} must be a function`);
832
1085
  assertHttpUrl("baseUrl", options.baseUrl);
833
1086
  };
@@ -859,8 +1112,61 @@ const validateRequestOptions = (options) => {
859
1112
  assertInteger("uploadTimeoutMs", options.uploadTimeoutMs, 1);
860
1113
  assertInteger("maxRetries", options.maxRetries, 0);
861
1114
  };
1115
+ /**
1116
+ * Option keys of methods that send no request of their own, or that take keys of their own beside
1117
+ * a request's; CalmLensOptionKeys, generated from the API, has the rest.
1118
+ */
1119
+ const LOCAL_OPTION_KEYS = {
1120
+ "assets.waitForDecision": [
1121
+ "assetId",
1122
+ "signal",
1123
+ "timeoutMs"
1124
+ ],
1125
+ "cdn.getAssetUrl": [
1126
+ "assetIdentifier",
1127
+ "lens",
1128
+ "resource",
1129
+ "transform",
1130
+ "viewerClaims"
1131
+ ],
1132
+ "cdn.serve": [
1133
+ "assetIdentifier",
1134
+ "init",
1135
+ "lens",
1136
+ "resource",
1137
+ "transform",
1138
+ "viewerClaims"
1139
+ ],
1140
+ "uploadTokens.sign": [
1141
+ "expiresInSeconds",
1142
+ "externalId",
1143
+ "uploadPresetId"
1144
+ ]
1145
+ };
1146
+ /** Uploads also take an `idempotencyKey`, which the SDK sends as a header. */
1147
+ const IDEMPOTENT_OPERATIONS = [
1148
+ "assets.create",
1149
+ "assets.classify",
1150
+ "assets.uploadPart",
1151
+ "text.classify"
1152
+ ];
1153
+ /**
1154
+ * Throws `sdk/invalid-argument` for an option `operation` doesn't take, such as a misspelt key,
1155
+ * instead of silently dropping it. `apiKeys` is the client's generated table of the keys each
1156
+ * method sends to the API. Anything other than an object is left to the method's own checks.
1157
+ */
1158
+ const checkOptionKeys = (options, operation, apiKeys) => {
1159
+ if (!options || typeof options !== "object" || Array.isArray(options)) return;
1160
+ const allowed = LOCAL_OPTION_KEYS[operation] ?? apiKeys[operation];
1161
+ if (!allowed) throw new Error(`No option keys for ${operation}`);
1162
+ const unknown = Object.keys(options).filter((key) => !allowed.includes(key) && !(key === "idempotencyKey" && IDEMPOTENT_OPERATIONS.includes(operation)));
1163
+ if (unknown.length) throw invalidArgument(`Unknown option${unknown.length > 1 ? "s" : ""} for ${operation}: ${unknown.join(", ")}`, {
1164
+ operation,
1165
+ options: unknown
1166
+ });
1167
+ };
862
1168
  const toTextAssetOptions = ({ text, name, ...options }) => {
863
- if (typeof text !== "string" || !text.trim()) throw new CalmLensError(API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Text to classify must be a non-empty string" });
1169
+ if (typeof text !== "string" || !text.trim()) throw invalidArgument("Text to classify must be a non-empty string");
864
1170
  return {
865
1171
  ...options,
866
1172
  name: name ?? "text",
@@ -895,6 +1201,16 @@ const encodePathSegment = (value, name) => {
895
1201
  if (value === "." || value === "..") throw invalidArgument(`${name} cannot be "." or ".."`);
896
1202
  return encodeURIComponent(value);
897
1203
  };
1204
+ /**
1205
+ * Whether the API accepts an upload of this MIME type: an image, audio, video, text, document or
1206
+ * website type, not a container such as `application/octet-stream`. It refuses any other type with
1207
+ * `upload/invalid-mime-type`.
1208
+ */
1209
+ const isAcceptedUploadMimeType = (mimeType) => {
1210
+ const type = normalizeUploadMimeType(mimeType);
1211
+ if (UPLOAD_MIME_REJECTED.includes(type)) return false;
1212
+ return UPLOAD_MIME_PREFIXES.some((prefix) => type.startsWith(prefix)) || UPLOAD_MIME_SUFFIXES.some((suffix) => type.endsWith(suffix)) || UPLOAD_MIME_TYPES.includes(type);
1213
+ };
898
1214
  const TRANSFORM_OPTION_NAME = /^[a-z][a-zA-Z0-9]*$/;
899
1215
  const TRANSFORM_COLOUR_KEYS = /* @__PURE__ */ new Set([
900
1216
  "background",
@@ -923,29 +1239,132 @@ const appendTransformOptions = (pairs, key, value) => {
923
1239
  else throw invalidArgument(`Transform option "${key}" must be a string, number, boolean or object`);
924
1240
  pairs.push(`${key}=${encodeTransformComponent(text)}`);
925
1241
  };
1242
+ const hasRuleType = (type, value) => {
1243
+ switch (type) {
1244
+ case "object": return isPlainObject(value);
1245
+ case "string":
1246
+ case "boolean": return typeof value === type;
1247
+ case "number": return typeof value === "number" && Number.isFinite(value);
1248
+ case "integer": return typeof value === "number" && Number.isInteger(value);
1249
+ default: return true;
1250
+ }
1251
+ };
926
1252
  /**
927
- * Serializes structured transforms as a CDN selector, one path segment per step, such as
928
- * `fit=cover,width=640/blur=12`. Option keys are sorted so equal transforms share a URL, nested
929
- * keys are dotted (`border.color`), colours are hex without `#`, and values are percent-encoded.
1253
+ * Checks transform options against the image transform schema, as the CDN does, and returns the
1254
+ * dotted keys it doesn't know and those whose values it refuses (or that are required and missing).
1255
+ * `null` options are left out of a selector, so they are not checked.
930
1256
  */
931
- const serializeTransform = (transform) => {
932
- const steps = Array.isArray(transform) ? transform : [transform];
933
- if (steps.length === 0) throw invalidArgument("Transform needs at least one step");
934
- return steps.map((step) => {
935
- if (!isPlainObject(step)) throw invalidArgument("Transform steps must be objects");
936
- if (step.type !== "imageTransform") throw invalidArgument("Transform type must be \"imageTransform\"");
937
- if (step.options !== void 0 && step.options !== null && !isPlainObject(step.options)) throw invalidArgument("Transform options must be an object");
938
- const pairs = [];
939
- for (const key of Object.keys(step.options ?? {}).sort()) {
940
- if (!TRANSFORM_OPTION_NAME.test(key)) throw invalidArgument(`Transform option "${key}" is not a valid name`);
941
- appendTransformOptions(pairs, key, step.options[key]);
1257
+ const checkTransformOptions = (options) => {
1258
+ const unknownKeys = [];
1259
+ const invalidKeys = [];
1260
+ const check = (schema, value, key) => {
1261
+ const rule = schema.oneOf ? schema.oneOf.find(({ type }) => hasRuleType(type, value)) : schema;
1262
+ if (!rule || !hasRuleType(rule.type, value) || rule.enum && !rule.enum.includes(value) || rule.minimum !== void 0 && value < rule.minimum || rule.maximum !== void 0 && value > rule.maximum) {
1263
+ invalidKeys.push(key);
1264
+ return;
1265
+ }
1266
+ if (rule.type !== "object") return;
1267
+ const object = value;
1268
+ const path = (name) => key ? `${key}.${name}` : name;
1269
+ for (const name of rule.required ?? []) if (object[name] === void 0 || object[name] === null) invalidKeys.push(path(name));
1270
+ for (const name of Object.keys(object).sort()) {
1271
+ if (object[name] === void 0 || object[name] === null) continue;
1272
+ const child = rule.properties?.[name];
1273
+ if (child) check(child, object[name], path(name));
1274
+ else unknownKeys.push(path(name));
1275
+ }
1276
+ };
1277
+ check(TRANSFORM_OPTIONS_SCHEMA, options, "");
1278
+ return {
1279
+ unknownKeys,
1280
+ invalidKeys
1281
+ };
1282
+ };
1283
+ /**
1284
+ * Reads a CDN selector, the path segment after `/rendered` as sent (still percent-encoded), as the
1285
+ * CDN does (packages/shared/src/TransformSelector.ts): an optional first `@lens`, then `key=value`
1286
+ * options with dotted keys for nested ones (a bare key is `true`). Values are numbers, `true`,
1287
+ * `false`, hex colours (`#` added) for colour options, or text. Throws on anything the CDN refuses
1288
+ * as `asset/invalid-transform`. Used by the mock CDN.
1289
+ */
1290
+ const parseTransformSelector = (selector) => {
1291
+ if (!selector) return {};
1292
+ const fail = () => /* @__PURE__ */ new Error(`Invalid transform selector "${selector}"`);
1293
+ if (selector.includes("/")) throw fail();
1294
+ const decode = (text) => {
1295
+ try {
1296
+ return decodeURIComponent(text);
1297
+ } catch {
1298
+ throw fail();
1299
+ }
1300
+ };
1301
+ const entries = selector.split(",");
1302
+ let lens;
1303
+ if (entries[0].startsWith("@")) {
1304
+ lens = decode(entries.shift().slice(1));
1305
+ if (!/^[a-z0-9-]{1,50}$/.test(lens)) throw fail();
1306
+ }
1307
+ if (!entries.length) return { lens };
1308
+ const options = {};
1309
+ for (const entry of entries) {
1310
+ if (!entry || entry.startsWith("@")) throw fail();
1311
+ const separator = entry.indexOf("=");
1312
+ const key = separator === -1 ? entry : entry.slice(0, separator);
1313
+ const parts = key.split(".");
1314
+ if (!parts.every((part) => TRANSFORM_OPTION_NAME.test(part))) throw fail();
1315
+ let value = true;
1316
+ if (separator !== -1) {
1317
+ const text = decode(entry.slice(separator + 1));
1318
+ if (text === "") throw fail();
1319
+ value = TRANSFORM_COLOUR_KEYS.has(key) && HEX_COLOUR.test(`#${text}`) ? `#${text.toLowerCase()}` : /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(text) ? Number(text) : text === "true" || text === "false" ? text === "true" : text;
1320
+ }
1321
+ let target = options;
1322
+ for (const part of parts.slice(0, -1)) {
1323
+ const next = target[part];
1324
+ if (next !== void 0 && !isPlainObject(next)) throw fail();
1325
+ target = target[part] ??= {};
942
1326
  }
943
- if (pairs.length === 0) throw invalidArgument("Transform steps need at least one option");
944
- return pairs.join(",");
945
- }).join("/");
1327
+ const last = parts.at(-1);
1328
+ if (last in target) throw fail();
1329
+ target[last] = value;
1330
+ }
1331
+ return {
1332
+ lens,
1333
+ options
1334
+ };
1335
+ };
1336
+ /** Throws `sdk/invalid-argument` naming each transform option the CDN would refuse. */
1337
+ const assertTransformOptions = (options) => {
1338
+ const { unknownKeys, invalidKeys } = checkTransformOptions(options);
1339
+ if (!unknownKeys.length && !invalidKeys.length) return;
1340
+ const problems = [...unknownKeys.length ? [`unknown option${unknownKeys.length > 1 ? "s" : ""} ${unknownKeys.join(", ")}`] : [], ...invalidKeys.length ? [`invalid value${invalidKeys.length > 1 ? "s" : ""} for ${invalidKeys.join(", ")}`] : []];
1341
+ throw invalidArgument(`Transform options are invalid: ${problems.join("; ")}. Pass the options themselves, such as { width: 640, format: "webp" }.`, {
1342
+ unknownKeys,
1343
+ invalidKeys
1344
+ });
1345
+ };
1346
+ /**
1347
+ * Serializes structured transform options as a CDN selector, such as `fit=cover,width=640`. Option
1348
+ * keys are sorted so equal transforms share a URL, nested keys are dotted (`border.color`),
1349
+ * colours are hex without `#`, and values are percent-encoded.
1350
+ */
1351
+ const serializeTransform = (transform) => {
1352
+ if (!isPlainObject(transform)) throw invalidArgument("Transform options must be an object");
1353
+ assertTransformOptions(transform);
1354
+ const pairs = [];
1355
+ for (const key of Object.keys(transform).sort()) {
1356
+ if (!TRANSFORM_OPTION_NAME.test(key)) throw invalidArgument(`Transform option "${key}" is not a valid name`);
1357
+ appendTransformOptions(pairs, key, transform[key]);
1358
+ }
1359
+ if (pairs.length === 0) throw invalidArgument("A transform needs at least one option");
1360
+ return pairs.join(",");
946
1361
  };
947
1362
  /** Returns the selector string the API and CDN accept for a string or structured transform. */
948
- const transformSelector = (transform) => transform === void 0 || typeof transform === "string" ? transform : serializeTransform(transform);
1363
+ const transformSelector = (transform) => {
1364
+ if (transform === void 0 || typeof transform !== "string") return transform === void 0 ? void 0 : serializeTransform(transform);
1365
+ if (/[/?#]/.test(transform) || transform.includes("..") || transform.startsWith("@")) throw invalidArgument("Transform cannot contain \"/\", \"..\", \"?\" or \"#\", or start with \"@\"");
1366
+ return transform;
1367
+ };
949
1368
  const DEFAULT_CDN_BASE_URL = `https://cdn.${DOMAIN}/v1`;
950
1369
  const CDN_RESOURCES = /* @__PURE__ */ new Set([
951
1370
  "original",
@@ -992,19 +1411,16 @@ const appendCdnSelector = (url, options) => {
992
1411
  const path = appendCdnPathSelector(url, options);
993
1412
  const query = new URLSearchParams();
994
1413
  if (options.viewerClaims !== void 0) {
995
- const claims = VIEWER_CLAIMS_SCHEMA.safeParse(options.viewerClaims);
996
- if (!claims.success) throw invalidArgument("Invalid viewerClaims");
997
- query.set("viewerClaims", JSON.stringify(claims.data));
1414
+ const claims = parseViewerClaims(options.viewerClaims);
1415
+ if (!claims) throw invalidArgument("Invalid viewerClaims");
1416
+ query.set("viewerClaims", JSON.stringify(claims));
998
1417
  }
999
1418
  return query.size ? `${path}?${query}` : path;
1000
1419
  };
1001
1420
  const appendCdnPathSelector = (url, options) => {
1002
- if (options.lens) url = `${url}/@${encodePathSegment(options.lens, "Lens")}`;
1003
- if (!options.transform) return url;
1004
- if (typeof options.transform !== "string") return `${url}/${serializeTransform(options.transform)}`;
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)}`;
1421
+ const transform = transformSelector(options.transform);
1422
+ const selector = [...options.lens ? [`@${encodePathSegment(options.lens, "Lens")}`] : [], ...transform ? [typeof options.transform === "string" ? encodeURI(transform) : transform] : []].join(",");
1423
+ return selector ? `${url}/${selector}` : url;
1008
1424
  };
1009
1425
  const appendQueryValue = (parts, key, value) => {
1010
1426
  if (value === void 0 || value === null) return;
@@ -1034,11 +1450,11 @@ const stringifyQuery = (query) => {
1034
1450
  */
1035
1451
  const isAssetDecided = (asset) => asset.classification.moderation.status !== "pending" || asset.classification.status === "failed";
1036
1452
  const DECISION_POLL_DELAY_FACTOR = 1.5;
1037
- const DECISION_POLL_MAX_DELAY_MS = 5e3;
1453
+ const DECISION_POLL_MAX_DELAY_MS = 2e3;
1038
1454
  const DEFAULT_DECISION_TIMEOUT_MS = 6e4;
1039
1455
  /**
1040
1456
  * Retrieves an asset until it has a decision, waiting 0.5s between checks and 1.5 times longer
1041
- * each time, up to 5s. Rejects with `sdk/timeout` once `timeoutMs` passes without one.
1457
+ * each time, up to 2s. Rejects with `sdk/timeout` once `timeoutMs` passes without one.
1042
1458
  */
1043
1459
  const pollForDecision = async (retrieve, { timeoutMs = DEFAULT_DECISION_TIMEOUT_MS, signal }, sleep, now = Date.now) => {
1044
1460
  if (!Number.isFinite(timeoutMs) || timeoutMs < 0) throw invalidArgument("timeoutMs must be a non-negative number");
@@ -1063,7 +1479,7 @@ const pollForDecision = async (retrieve, { timeoutMs = DEFAULT_DECISION_TIMEOUT_
1063
1479
  };
1064
1480
  // src/client/CalmLensVersion.ts
1065
1481
  /** This SDK's version, from its package.json. */
1066
- const SDK_VERSION = "0.18.3";
1482
+ const SDK_VERSION = "0.20.0";
1067
1483
  const runtimeName = () => {
1068
1484
  const runtime = globalThis;
1069
1485
  if (isReactNativeRuntime()) return "react-native";
@@ -1111,4 +1527,4 @@ const selectModerationContextItems = (items) => {
1111
1527
  }
1112
1528
  return selected;
1113
1529
  };
1114
- export { invalidArgument as A, MAX_IMAGE_UPLOAD_BYTES as C, CALMLENS_ERROR_CODES as D, isRejectedUploadMimeType as E, API_ERROR_CODES as M, API_ERROR_DEFINITIONS as N, CalmLensError as O, DOMAIN as S, getRejectedUploadMimeTypeError as T, validateAppClientOptions as _, getUserAgent as a, validateServerClientOptions as b, DEFAULT_CDN_BASE_URL as c, pollForDecision as d, randomUuid as f, transformSelector as g, toTextAssetOptions as h, SDK_VERSION as i, invalidConfig as j, SDK_ERROR_CODES as k, encodePathSegment as l, stringifyQuery as m, MODERATION_CONTEXT_USED_ITEMS as n, isBrowserRuntime as o, serializeTransform as p, selectModerationContextItems as r, isReactNativeRuntime as s, MODERATION_CONTEXT_USED_CHARACTERS as t, getAssetUrl as u, validateBatchAssetsOptions as v, MIN_MULTIPART_IMAGE_UPLOAD_BYTES as w, validateSignedUrlOptions as x, validateRequestOptions as y };
1530
+ export { MAX_NON_IMAGE_UPLOAD_BYTES as A, validateRequestOptions as C, DOMAIN as D, EU_COUNTRIES as E, invalidArgument as F, invalidConfig as I, API_ERROR_CODES as L, CALMLENS_ERROR_CODES as M, CalmLensError as N, MAX_DIRECT_IMAGE_UPLOAD_BYTES as O, SDK_ERROR_CODES as P, API_ERROR_DEFINITIONS as R, validateBatchAssetsOptions as S, validateSignedUrlOptions as T, serializeTransform as _, getUserAgent as a, transformSelector as b, DEFAULT_CDN_BASE_URL as c, encodePathSegment as d, getAssetUrl as f, randomUuid as g, pollForDecision as h, SDK_VERSION as i, getRejectedUploadMimeTypeError as j, MAX_IMAGE_UPLOAD_BYTES as k, checkOptionKeys as l, parseTransformSelector as m, MODERATION_CONTEXT_USED_ITEMS as n, isBrowserRuntime as o, isAcceptedUploadMimeType as p, selectModerationContextItems as r, isReactNativeRuntime as s, MODERATION_CONTEXT_USED_CHARACTERS as t, checkTransformOptions as u, stringifyQuery as v, validateServerClientOptions as w, validateAppClientOptions as x, toTextAssetOptions as y };
@@ -1,4 +1,4 @@
1
- import { n as createUploadController } from "./UploadController-Cs-bxUbt.js";
1
+ import { n as createUploadController } from "./UploadController-BJZghJpg.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 { I as UploadSnapshot, M as UploadController, N as UploadControllerOptions, P as UploadFile } from "./ui-wIiMfqMB.js";
1
+ import { F as UploadFile, L as UploadSnapshot, N as UploadController, P as UploadControllerOptions } from "./ui-BSqPGKrZ.js";
2
2
  interface UseCalmLensUploadResult<F extends UploadFile = UploadFile> extends UploadSnapshot<F> {
3
3
  controller: UploadController<F>;
4
4
  addFiles: UploadController<F>["addFiles"];