calmlens 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -9
- package/bin/calmlens.js +1329 -664
- package/cjs/{BrowserUpload-CjSHjx3C.js → BrowserUpload-CeSwiMo5.js} +1 -1
- package/cjs/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-D-NnAN7g.d.ts} +2 -2
- package/cjs/{CalmLensAppClient-NaCxOVlM.js → CalmLensAppClient-0UVCuNqW.js} +30 -10
- package/cjs/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-gG16T2py.d.ts} +13 -3
- package/cjs/{CalmLensOptionKeys-p2QK687A.js → CalmLensOptionKeys-CYY6elxg.js} +183 -347
- package/cjs/{CalmLensServerClient-C-jsjn8m.d.ts → CalmLensServerClient-BHx3x_nZ.d.ts} +106 -48
- package/cjs/{CalmLensServerClient-BDzTthxE.js → CalmLensServerClient-nfu6_YEW.js} +288 -88
- package/cjs/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-CUB0YYVz.d.ts} +26601 -27354
- package/cjs/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/cjs/Core-C82YmjjX.d.ts +823 -0
- package/cjs/Core-Dc3cteU7.js +998 -0
- package/cjs/FileIcons-4qSX7DW2.d.ts +67 -0
- package/cjs/{ModerationContextLimits-2nIv7Zh3.js → ModerationContextLimits-BxOmeSqq.js} +669 -269
- package/cjs/{ReactUpload-BdTRCTGA.js → ReactUpload-BK2O3dnK.js} +1 -1
- package/cjs/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DiiXfKvj.d.ts} +1 -1
- package/cjs/{TestTriggers-DbhsNPdg-DjvVuc2h.js → TestTriggers-BTyXtX0Q-ATuFDhLX.js} +342 -34
- package/{esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → cjs/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/cjs/{UploadController-MLVs97Zt.js → UploadController-DLyiLDTB.js} +34 -14
- package/cjs/{WebhookPayload-DkukERKE.d.ts → WebhookPayload-BLT2y_Jy.d.ts} +93 -86
- package/cjs/app.d.ts +6 -7
- package/cjs/app.js +4 -3
- package/cjs/elements.d.ts +123 -22
- package/cjs/elements.js +553 -156
- package/cjs/file-icons.d.ts +2 -67
- package/cjs/index-CKRgjV16.d.ts +16 -0
- package/cjs/index.d.ts +5 -6
- package/cjs/index.js +3 -2
- package/cjs/react-native.d.ts +52 -11
- package/cjs/react-native.js +231 -99
- package/cjs/react.d.ts +42 -9
- package/cjs/react.js +381 -118
- package/cjs/server.d.ts +48 -7
- package/cjs/server.js +7 -3
- package/cjs/test-inputs.d.ts +2 -2
- package/cjs/test-inputs.js +13 -9
- package/cjs/testing.d.ts +24 -14
- package/cjs/testing.js +1413 -402
- package/cjs/ui-CTBUxnVp.d.ts +139 -0
- package/cjs/ui-CZ8exACq.js +1359 -0
- package/cjs/ui.d.ts +3 -2
- package/cjs/ui.js +45 -22
- package/cjs/vue.d.ts +802 -199
- package/cjs/vue.js +359 -127
- package/esm/{BrowserUpload-C07aL9Vq.d.ts → BrowserUpload-D-NnAN7g.d.ts} +2 -2
- package/esm/{BrowserUpload-CAVkRotw.js → BrowserUpload-i9OhCzMJ.js} +1 -1
- package/esm/{CalmLensAppClient-PQ9VBvlW.js → CalmLensAppClient-CK4_Py0c.js} +30 -10
- package/esm/{CalmLensAppClient-DDLojj0P.d.ts → CalmLensAppClient-gG16T2py.d.ts} +13 -3
- package/esm/{CalmLensOptionKeys-Do2mPP6w.js → CalmLensOptionKeys-BGZlIsT2.js} +182 -340
- package/esm/{CalmLensServerClient-C-jsjn8m.d.ts → CalmLensServerClient-BHx3x_nZ.d.ts} +106 -48
- package/esm/{CalmLensServerClient-C_H5aAsV.js → CalmLensServerClient-dAQUcDWb.js} +265 -89
- package/esm/{CalmLensTypes-COJbOuiv.d.ts → CalmLensTypes-CUB0YYVz.d.ts} +26601 -27354
- package/esm/{Classification-D3SkprrQ-CMnQKW13.d.ts → Classification-Q5zGpR8l-CEWjnE39.d.ts} +731 -607
- package/esm/Core-BxeIud_S.js +843 -0
- package/esm/Core-C82YmjjX.d.ts +823 -0
- package/esm/FileIcons-4qSX7DW2.d.ts +67 -0
- package/esm/{ModerationContextLimits-Chw-AzgL.js → ModerationContextLimits-B6_RalCQ.js} +624 -254
- package/esm/{ReactUpload-CRJNPB5T.d.ts → ReactUpload-DiiXfKvj.d.ts} +1 -1
- package/esm/{ReactUpload-CMmL0R5Q.js → ReactUpload-DxwVqfX1.js} +1 -1
- package/esm/{TestTriggers-DbhsNPdg-CUdrv8Nm.js → TestTriggers-BTyXtX0Q-GRB9jQwo.js} +319 -35
- package/{cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts → esm/TestTriggers-D0pYHbkr-D5T0VdSn.d.ts} +146 -8
- package/esm/{UploadController-BJZghJpg.js → UploadController-D9Z-h00Q.js} +34 -14
- package/esm/{WebhookPayload-DkukERKE.d.ts → WebhookPayload-BLT2y_Jy.d.ts} +93 -86
- package/esm/app.d.ts +6 -7
- package/esm/app.js +3 -3
- package/esm/elements.d.ts +123 -22
- package/esm/elements.js +497 -128
- package/esm/file-icons.d.ts +2 -67
- package/esm/index-CKRgjV16.d.ts +16 -0
- package/esm/index.d.ts +5 -6
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +52 -11
- package/esm/react-native.js +205 -75
- package/esm/react.d.ts +42 -9
- package/esm/react.js +327 -91
- package/esm/server.d.ts +48 -7
- package/esm/server.js +3 -3
- package/esm/styles.css +142 -22
- package/esm/svelte/AssetViewer.svelte +25 -0
- package/esm/svelte/CalmLensAsset.svelte +318 -0
- package/esm/svelte/CalmLensDocumentViewer.svelte +7 -0
- package/esm/svelte/CalmLensImageViewer.svelte +7 -0
- package/esm/svelte/CalmLensSpreadsheetViewer.svelte +7 -0
- package/esm/svelte/CalmLensTextViewer.svelte +7 -0
- package/esm/svelte/CalmLensWebsiteViewer.svelte +7 -0
- package/esm/svelte/index.d.ts +29 -6
- package/esm/svelte/index.js +7 -2
- package/esm/test-inputs.d.ts +2 -2
- package/esm/test-inputs.js +1 -1
- package/esm/testing.d.ts +24 -14
- package/esm/testing.js +1409 -398
- package/esm/ui-CTBUxnVp.d.ts +139 -0
- package/esm/ui-Cr7s6JHm.js +1258 -0
- package/esm/ui.d.ts +3 -2
- package/esm/ui.js +4 -3
- package/esm/vue.d.ts +802 -199
- package/esm/vue.js +308 -103
- package/package.json +3 -1
- package/cjs/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/cjs/index-DxbJ_Xaa.d.ts +0 -253
- package/cjs/ui-BSqPGKrZ.d.ts +0 -539
- package/cjs/ui-CX1z2pD9.js +0 -586
- package/esm/ModerationContext-9lGm-Mna-CcmbRnOy.d.ts +0 -67
- package/esm/index-DxbJ_Xaa.d.ts +0 -253
- package/esm/svelte/CalmLensMedia.svelte +0 -134
- package/esm/ui-BSqPGKrZ.d.ts +0 -539
- package/esm/ui-CXH7xJpb.js +0 -461
|
@@ -1,63 +1,63 @@
|
|
|
1
1
|
// src/client/CalmLensErrorCodes.ts
|
|
2
2
|
/** Error codes the CalmLens API documents, by name. */
|
|
3
3
|
const API_ERROR_CODES = {
|
|
4
|
-
INVALID_VIEWER_CLAIMS: "viewer/invalid
|
|
4
|
+
INVALID_VIEWER_CLAIMS: "viewer-claims/invalid",
|
|
5
5
|
AGE_CONFIRMATION_REQUIRED: "viewer/age-confirmation-required",
|
|
6
|
-
INVALID_VIEWER_REGION: "viewer/invalid
|
|
6
|
+
INVALID_VIEWER_REGION: "viewer-region/invalid",
|
|
7
7
|
VIEWER_REGION_REQUIRED: "viewer/region-required",
|
|
8
8
|
REGIONAL_EVIDENCE_REQUIRED: "asset/regional-evidence-required",
|
|
9
9
|
SIGNED_URL_EXPIRED: "signed-url/expired",
|
|
10
10
|
SIGNED_URL_INVALID: "signed-url/invalid",
|
|
11
|
+
SIGNED_URL_ORIGINAL_NOT_GRANTED: "signed-url/original-not-granted",
|
|
12
|
+
INVALID_REQUEST: "validation/invalid-request",
|
|
11
13
|
INVALID_TYPE: "validation/invalid-type",
|
|
12
14
|
TOO_SMALL: "validation/too-small",
|
|
13
15
|
TOO_BIG: "validation/too-big",
|
|
14
16
|
INVALID_FORMAT: "validation/invalid-format",
|
|
15
17
|
INVALID_VALUE: "validation/invalid-value",
|
|
16
18
|
UNKNOWN_FIELD: "validation/unknown-field",
|
|
17
|
-
UNSUPPORTED_CONTENT_TYPE: "
|
|
18
|
-
INVALID_FILTER: "
|
|
19
|
-
|
|
20
|
-
ROUTE_NOT_FOUND: "
|
|
21
|
-
INTERNAL_ERROR: "
|
|
19
|
+
UNSUPPORTED_CONTENT_TYPE: "request/unsupported-content-type",
|
|
20
|
+
INVALID_FILTER: "filter/invalid",
|
|
21
|
+
UNSUPPORTED_ORDERING_FIELD: "ordering/unsupported-field",
|
|
22
|
+
ROUTE_NOT_FOUND: "request/route-not-found",
|
|
23
|
+
INTERNAL_ERROR: "server/internal-error",
|
|
22
24
|
UNAUTHENTICATED: "auth/unauthenticated",
|
|
23
|
-
TOKEN_EXPIRED: "
|
|
24
|
-
INVALID_TOKEN: "
|
|
25
|
+
TOKEN_EXPIRED: "session-token/expired",
|
|
26
|
+
INVALID_TOKEN: "session-token/invalid",
|
|
25
27
|
SEARCH_UNAVAILABLE: "search/unavailable",
|
|
26
|
-
INVALID_TRANSFORM: "
|
|
27
|
-
INVALID_TRANSFORM_OPTIONS: "
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
API_KEY_PROJECT_MISMATCH: "auth/project-mismatch",
|
|
35
|
-
API_KEY_NOT_ACCEPTED: "auth/api-key-not-accepted",
|
|
28
|
+
INVALID_TRANSFORM: "transform/invalid",
|
|
29
|
+
INVALID_TRANSFORM_OPTIONS: "transform-options/invalid",
|
|
30
|
+
REMOTE_URL_TOO_MANY_REDIRECTS: "remote-url/too-many-redirects",
|
|
31
|
+
INVALID_CURSOR: "cursor/invalid",
|
|
32
|
+
MISSING_API_KEY: "api-key/missing",
|
|
33
|
+
INVALID_API_KEY: "api-key/invalid",
|
|
34
|
+
API_KEY_PROJECT_MISMATCH: "api-key/project-mismatch",
|
|
35
|
+
API_KEY_NOT_ACCEPTED: "api-key/not-accepted",
|
|
36
36
|
PERMISSION_DENIED: "auth/permission-denied",
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
INVALID_UPLOAD_MIME_TYPE: "upload/invalid-mime-type",
|
|
46
|
-
INVALID_UPLOAD_PAYLOAD: "upload/invalid-payload",
|
|
37
|
+
UPLOAD_TOO_LARGE: "upload/too-large",
|
|
38
|
+
DOCUMENT_TOO_MANY_ITEMS: "document/too-many-items",
|
|
39
|
+
INVALID_IMAGE: "image/invalid",
|
|
40
|
+
IMAGE_TOO_LARGE: "image/too-large",
|
|
41
|
+
FREE_UPLOADS_EXHAUSTED: "usage/free-uploads-exhausted",
|
|
42
|
+
UPLOADS_PAUSED: "usage/uploads-paused",
|
|
43
|
+
UNSUPPORTED_UPLOAD_TYPE: "upload/unsupported-type",
|
|
44
|
+
INVALID_UPLOAD_PAYLOAD: "upload-payload/invalid",
|
|
47
45
|
USE_UPLOAD_PART: "upload/use-upload-part",
|
|
48
46
|
UPLOAD_NOT_OPEN: "upload/not-open",
|
|
49
|
-
INVALID_UPLOAD_PART_NUMBER: "upload/invalid-
|
|
47
|
+
INVALID_UPLOAD_PART_NUMBER: "upload-part/invalid-number",
|
|
50
48
|
UPLOAD_MISSING: "upload/missing",
|
|
51
49
|
UPLOAD_SIZE_MISMATCH: "upload/size-mismatch",
|
|
52
50
|
INVALID_IDEMPOTENCY_KEY: "idempotency/invalid-key",
|
|
53
51
|
IDEMPOTENCY_KEY_REUSED: "idempotency/key-reused",
|
|
54
52
|
IDEMPOTENT_REQUEST_IN_PROGRESS: "idempotency/request-in-progress",
|
|
53
|
+
NO_RENDERED_VERSION: "asset/no-rendered-version",
|
|
55
54
|
ASSET_NOT_FOUND: "asset/not-found",
|
|
56
55
|
PROJECT_NOT_FOUND: "project/not-found",
|
|
56
|
+
ASSET_CHILD_NOT_DELETABLE: "asset/child-not-deletable",
|
|
57
57
|
ASSET_REVIEW_CHANGED: "asset/review-changed",
|
|
58
58
|
ASSET_REVIEW_NOTE_REQUIRED: "asset/review-note-required",
|
|
59
59
|
ASSET_UPDATE_FAILED: "asset/update-failed",
|
|
60
|
-
|
|
60
|
+
ASSET_HELD: "asset/held",
|
|
61
61
|
ASSET_PROCESSING: "asset/processing",
|
|
62
62
|
ASSET_DECISION_NOT_ALLOWED: "asset/decision-not-allowed",
|
|
63
63
|
ASSET_DECISION_UNCHANGED: "asset/decision-unchanged",
|
|
@@ -67,18 +67,19 @@ const API_ERROR_CODES = {
|
|
|
67
67
|
ASSET_NOT_DECIDED: "asset/not-decided",
|
|
68
68
|
ASSET_POLICY_CHANGED: "asset/policy-changed",
|
|
69
69
|
ASSET_REVIEWED: "asset/reviewed",
|
|
70
|
-
SUPPORT_TICKET_NOT_FOUND: "support/
|
|
70
|
+
SUPPORT_TICKET_NOT_FOUND: "support-ticket/not-found",
|
|
71
71
|
DUPLICATE_EXTERNAL_ID: "asset/duplicate-external-id",
|
|
72
72
|
FOLDER_NOT_FOUND: "folder/not-found",
|
|
73
73
|
DUPLICATE_FOLDER_NAME: "folder/duplicate-name",
|
|
74
74
|
FOLDER_NOT_EMPTY: "folder/not-empty",
|
|
75
75
|
FOLDER_PARENT_CYCLE: "folder/parent-cycle",
|
|
76
|
-
|
|
76
|
+
LENS_NOT_FOUND: "lens/not-found",
|
|
77
|
+
LENS_IDENTIFIER_TAKEN: "lens/identifier-taken",
|
|
77
78
|
LENS_IDENTIFIER_RESERVED: "lens/identifier-reserved",
|
|
78
79
|
HASH_LIST_NOT_FOUND: "hash-list/not-found",
|
|
79
|
-
HASH_LIST_ENTRY_NOT_FOUND: "hash-list/
|
|
80
|
+
HASH_LIST_ENTRY_NOT_FOUND: "hash-list-entry/not-found",
|
|
80
81
|
HASH_LIST_LIMIT_REACHED: "hash-list/limit-reached",
|
|
81
|
-
HASH_LIST_ENTRY_LIMIT_REACHED: "hash-list/
|
|
82
|
+
HASH_LIST_ENTRY_LIMIT_REACHED: "hash-list-entry/limit-reached",
|
|
82
83
|
HASH_LIST_ASSET_NOT_HASHED: "hash-list/asset-not-hashed",
|
|
83
84
|
POLICY_NOT_FOUND: "policy/not-found",
|
|
84
85
|
POLICY_REVISION_CONFLICT: "policy/revision-conflict",
|
|
@@ -92,18 +93,16 @@ const API_ERROR_CODES = {
|
|
|
92
93
|
UPLOAD_PRESET_NOT_FOUND: "upload-preset/not-found",
|
|
93
94
|
UPLOAD_PRESET_DISABLED: "upload-preset/disabled",
|
|
94
95
|
UPLOAD_PRESET_TOKEN_REQUIRED: "upload-preset/token-required",
|
|
95
|
-
REMOTE_URL_NOT_ALLOWED: "
|
|
96
|
-
|
|
97
|
-
UPLOAD_PRESET_CONTENT_TYPE_NOT_ALLOWED: "upload-preset/content-type-not-allowed",
|
|
98
|
-
UPLOAD_PRESET_TOO_LARGE: "upload-preset/too-large",
|
|
96
|
+
REMOTE_URL_NOT_ALLOWED: "remote-url/not-allowed",
|
|
97
|
+
WEBSITE_RATE_LIMIT_REACHED: "upload/website-rate-limit-reached",
|
|
99
98
|
UPLOAD_PRESET_DAILY_LIMIT_REACHED: "upload-preset/daily-limit-reached",
|
|
100
99
|
UPLOAD_PRESET_ORIGIN_NOT_ALLOWED: "upload-preset/origin-not-allowed",
|
|
101
100
|
UPLOAD_PRESET_FIELD_NOT_ALLOWED: "upload-preset/field-not-allowed",
|
|
102
101
|
UPLOAD_TOKEN_INVALID: "upload-token/invalid",
|
|
103
102
|
UPLOAD_TOKEN_EXPIRED: "upload-token/expired",
|
|
104
103
|
UPLOAD_TOKEN_USED: "upload-token/used",
|
|
105
|
-
INVALID_REMOTE_URL: "
|
|
106
|
-
REMOTE_URL_UNAVAILABLE: "
|
|
104
|
+
INVALID_REMOTE_URL: "remote-url/invalid",
|
|
105
|
+
REMOTE_URL_UNAVAILABLE: "remote-url/unavailable",
|
|
107
106
|
APPEAL_NOT_FOUND: "appeal/not-found",
|
|
108
107
|
APPEAL_JUDGMENT_NOT_FOUND: "appeal/judgment-not-found",
|
|
109
108
|
APPEAL_ASSET_NOT_FOUND: "appeal/asset-not-found",
|
|
@@ -111,12 +110,11 @@ const API_ERROR_CODES = {
|
|
|
111
110
|
APPEAL_ALREADY_REVIEWED: "appeal/already-reviewed",
|
|
112
111
|
APPEAL_DECISION_CHANGED: "appeal/decision-changed",
|
|
113
112
|
APPEAL_INVALID_ACTION: "appeal/invalid-action",
|
|
114
|
-
APPEAL_SAFETY_HELD: "appeal/safety-held",
|
|
115
113
|
APPEAL_CONTENT_UNAVAILABLE: "appeal/content-unavailable"
|
|
116
114
|
};
|
|
117
115
|
/** The HTTP status and default message the API returns with each documented error code. */
|
|
118
116
|
const API_ERROR_DEFINITIONS = {
|
|
119
|
-
"viewer/invalid
|
|
117
|
+
"viewer-claims/invalid": {
|
|
120
118
|
status: 400,
|
|
121
119
|
message: "Supply a viewerClaims object with an optional region and boolean ageConfirmed."
|
|
122
120
|
},
|
|
@@ -124,7 +122,7 @@ const API_ERROR_DEFINITIONS = {
|
|
|
124
122
|
status: 403,
|
|
125
123
|
message: "Your application has not confirmed age-restricted delivery for this viewer."
|
|
126
124
|
},
|
|
127
|
-
"viewer/invalid
|
|
125
|
+
"viewer-region/invalid": {
|
|
128
126
|
status: 400,
|
|
129
127
|
message: "Supply the viewer's ISO country code, such as DE or GB."
|
|
130
128
|
},
|
|
@@ -142,49 +140,57 @@ const API_ERROR_DEFINITIONS = {
|
|
|
142
140
|
},
|
|
143
141
|
"signed-url/invalid": {
|
|
144
142
|
status: 403,
|
|
145
|
-
message: "The signed URL's
|
|
143
|
+
message: "The signed asset URL's grant wasn't signed for this project, or was changed after signing. Use the URL as created, adding only resources, selectors and viewer claims."
|
|
144
|
+
},
|
|
145
|
+
"signed-url/original-not-granted": {
|
|
146
|
+
status: 403,
|
|
147
|
+
message: "This signed asset URL doesn't grant the original file. Sign it with original access."
|
|
148
|
+
},
|
|
149
|
+
"validation/invalid-request": {
|
|
150
|
+
status: 400,
|
|
151
|
+
message: "The request's parameters, query or body are invalid. details.issues lists each problem, with its path and issue code."
|
|
146
152
|
},
|
|
147
153
|
"validation/invalid-type": {
|
|
148
154
|
status: 400,
|
|
149
|
-
message: "
|
|
155
|
+
message: "Issue code in details.issues: a field has the wrong type."
|
|
150
156
|
},
|
|
151
157
|
"validation/too-small": {
|
|
152
158
|
status: 400,
|
|
153
|
-
message: "
|
|
159
|
+
message: "Issue code in details.issues: a value is below its minimum."
|
|
154
160
|
},
|
|
155
161
|
"validation/too-big": {
|
|
156
162
|
status: 400,
|
|
157
|
-
message: "
|
|
163
|
+
message: "Issue code in details.issues: a value is above its maximum."
|
|
158
164
|
},
|
|
159
165
|
"validation/invalid-format": {
|
|
160
166
|
status: 400,
|
|
161
|
-
message: "
|
|
167
|
+
message: "Issue code in details.issues: a string is not in the required format, such as an ID or URL."
|
|
162
168
|
},
|
|
163
169
|
"validation/invalid-value": {
|
|
164
170
|
status: 400,
|
|
165
|
-
message: "
|
|
171
|
+
message: "Issue code in details.issues: a field has a value it cannot take."
|
|
166
172
|
},
|
|
167
173
|
"validation/unknown-field": {
|
|
168
174
|
status: 400,
|
|
169
|
-
message: "
|
|
175
|
+
message: "Issue code in details.issues: the request has a field this endpoint does not accept."
|
|
170
176
|
},
|
|
171
|
-
"
|
|
177
|
+
"request/unsupported-content-type": {
|
|
172
178
|
status: 415,
|
|
173
179
|
message: "Send the request body as application/json."
|
|
174
180
|
},
|
|
175
|
-
"
|
|
181
|
+
"filter/invalid": {
|
|
176
182
|
status: 400,
|
|
177
183
|
message: "The filter has invalid syntax or names a field that can't be filtered."
|
|
178
184
|
},
|
|
179
|
-
"
|
|
185
|
+
"ordering/unsupported-field": {
|
|
180
186
|
status: 400,
|
|
181
187
|
message: "The list cannot be ordered by this field."
|
|
182
188
|
},
|
|
183
|
-
"
|
|
189
|
+
"request/route-not-found": {
|
|
184
190
|
status: 404,
|
|
185
191
|
message: "No endpoint matches this method and path."
|
|
186
192
|
},
|
|
187
|
-
"
|
|
193
|
+
"server/internal-error": {
|
|
188
194
|
status: 500,
|
|
189
195
|
message: "An internal error occurred. Retry later, and quote requestId to support."
|
|
190
196
|
},
|
|
@@ -192,11 +198,11 @@ const API_ERROR_DEFINITIONS = {
|
|
|
192
198
|
status: 401,
|
|
193
199
|
message: "Authentication required."
|
|
194
200
|
},
|
|
195
|
-
"
|
|
201
|
+
"session-token/expired": {
|
|
196
202
|
status: 401,
|
|
197
203
|
message: "The session token has expired. Sign in again."
|
|
198
204
|
},
|
|
199
|
-
"
|
|
205
|
+
"session-token/invalid": {
|
|
200
206
|
status: 401,
|
|
201
207
|
message: "The session token is invalid. Sign in again."
|
|
202
208
|
},
|
|
@@ -204,87 +210,71 @@ const API_ERROR_DEFINITIONS = {
|
|
|
204
210
|
status: 503,
|
|
205
211
|
message: "Search is temporarily unavailable. Retry later."
|
|
206
212
|
},
|
|
207
|
-
"
|
|
213
|
+
"transform/invalid": {
|
|
208
214
|
status: 400,
|
|
209
215
|
message: "The transform names an unknown type or is not a valid selector."
|
|
210
216
|
},
|
|
211
|
-
"
|
|
217
|
+
"transform-options/invalid": {
|
|
212
218
|
status: 400,
|
|
213
219
|
message: "The transform's options are invalid for its type."
|
|
214
220
|
},
|
|
215
|
-
"
|
|
221
|
+
"remote-url/too-many-redirects": {
|
|
216
222
|
status: 400,
|
|
217
223
|
message: "The remote URL redirected too many times."
|
|
218
224
|
},
|
|
219
|
-
"
|
|
220
|
-
status: 409,
|
|
221
|
-
message: "The asset's content is held for a copyright claim and cannot be changed."
|
|
222
|
-
},
|
|
223
|
-
"asset/api-key-missing-permission": {
|
|
224
|
-
status: 403,
|
|
225
|
-
message: "This API key needs assets:download permission for this asset's folder."
|
|
226
|
-
},
|
|
227
|
-
"validation/invalid-cursor": {
|
|
225
|
+
"cursor/invalid": {
|
|
228
226
|
status: 400,
|
|
229
227
|
message: "The cursor is invalid or belongs to a different query."
|
|
230
228
|
},
|
|
231
|
-
"
|
|
229
|
+
"api-key/missing": {
|
|
232
230
|
status: 401,
|
|
233
231
|
message: "Authentication required. Send your project API key in the X-Api-Key header."
|
|
234
232
|
},
|
|
235
|
-
"
|
|
233
|
+
"api-key/invalid": {
|
|
236
234
|
status: 401,
|
|
237
235
|
message: "The API key is invalid, revoked or expired. Create a key under Developer → API Keys."
|
|
238
236
|
},
|
|
239
|
-
"
|
|
237
|
+
"api-key/project-mismatch": {
|
|
240
238
|
status: 403,
|
|
241
239
|
message: "This API key belongs to a different project. Use a key created for the project that owns this resource."
|
|
242
240
|
},
|
|
243
|
-
"
|
|
241
|
+
"api-key/not-accepted": {
|
|
244
242
|
status: 403,
|
|
245
243
|
message: "API keys are only accepted by the public API at /v1."
|
|
246
244
|
},
|
|
247
245
|
"auth/permission-denied": {
|
|
248
246
|
status: 403,
|
|
249
|
-
message: "This API key lacks a permission the request needs, such as assets:
|
|
250
|
-
},
|
|
251
|
-
"upload/file-too-large": {
|
|
252
|
-
status: 400,
|
|
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."
|
|
247
|
+
message: "This API key lacks a permission the request needs (details.permission names it, such as assets:download for an asset's folder), or the resource belongs to another project."
|
|
254
248
|
},
|
|
255
|
-
"upload/
|
|
256
|
-
status:
|
|
257
|
-
message: "
|
|
258
|
-
},
|
|
259
|
-
"upload/image-exceeded-max-dimensions": {
|
|
260
|
-
status: 400,
|
|
261
|
-
message: "Image exceeds maximum dimensions. Maximum dimensions are 12,000px."
|
|
249
|
+
"upload/too-large": {
|
|
250
|
+
status: 413,
|
|
251
|
+
message: "The file is larger than allowed. details.limitBytes is the limit, and details.source says whether it is the plan's (`plan`) or the upload preset's (`preset`)."
|
|
262
252
|
},
|
|
263
|
-
"
|
|
253
|
+
"document/too-many-items": {
|
|
264
254
|
status: 422,
|
|
265
|
-
message: "The
|
|
255
|
+
message: "The document holds more embedded images or audio and video files than can be moderated: details.limit is `images` or `media` and details.maximum the most allowed. Split it into smaller documents."
|
|
266
256
|
},
|
|
267
|
-
"image/
|
|
257
|
+
"image/invalid": {
|
|
268
258
|
status: 422,
|
|
269
|
-
message: "
|
|
259
|
+
message: "The image is corrupt or cannot be decoded. Upload a valid image file."
|
|
270
260
|
},
|
|
271
|
-
"image/
|
|
261
|
+
"image/too-large": {
|
|
272
262
|
status: 422,
|
|
273
|
-
message: "The image exceeds
|
|
263
|
+
message: "The image exceeds a processing limit: details.limit is `bytes`, `pixels` or `dimension`. Reduce its size before uploading."
|
|
274
264
|
},
|
|
275
|
-
"
|
|
265
|
+
"usage/free-uploads-exhausted": {
|
|
276
266
|
status: 403,
|
|
277
|
-
message: "
|
|
267
|
+
message: "This project's organisation has used its free uploads. Set up billing to continue uploading."
|
|
278
268
|
},
|
|
279
|
-
"
|
|
269
|
+
"usage/uploads-paused": {
|
|
280
270
|
status: 402,
|
|
281
271
|
message: "Uploads to this project are paused by its organisation's usage limits. See details.reason; an owner can review them in Billing."
|
|
282
272
|
},
|
|
283
|
-
"upload/
|
|
284
|
-
status:
|
|
285
|
-
message: "
|
|
273
|
+
"upload/unsupported-type": {
|
|
274
|
+
status: 415,
|
|
275
|
+
message: "The file type is not accepted. details.source is `calmlens` when CalmLens cannot store and process it (use a concrete MIME type such as image/png, application/pdf or text/plain) or `preset` when the upload preset doesn't allow it."
|
|
286
276
|
},
|
|
287
|
-
"upload/invalid
|
|
277
|
+
"upload-payload/invalid": {
|
|
288
278
|
status: 400,
|
|
289
279
|
message: "Upload payload is invalid."
|
|
290
280
|
},
|
|
@@ -296,7 +286,7 @@ const API_ERROR_DEFINITIONS = {
|
|
|
296
286
|
status: 409,
|
|
297
287
|
message: "Asset is not accepting additional parts"
|
|
298
288
|
},
|
|
299
|
-
"upload/invalid-
|
|
289
|
+
"upload-part/invalid-number": {
|
|
300
290
|
status: 409,
|
|
301
291
|
message: "Multipart upload part number is invalid."
|
|
302
292
|
},
|
|
@@ -320,6 +310,10 @@ const API_ERROR_DEFINITIONS = {
|
|
|
320
310
|
status: 409,
|
|
321
311
|
message: "A request with this Idempotency-Key is still being processed. Retry after the Retry-After delay to receive its result."
|
|
322
312
|
},
|
|
313
|
+
"asset/no-rendered-version": {
|
|
314
|
+
status: 404,
|
|
315
|
+
message: "This asset has no such resource: text and spreadsheets have no rendered version or preview, and documents, audio and video get theirs once processing makes them. Check the asset's `content.rendered` and `content.preview`, or request its original resource instead."
|
|
316
|
+
},
|
|
323
317
|
"asset/not-found": {
|
|
324
318
|
status: 404,
|
|
325
319
|
message: "Asset not found"
|
|
@@ -328,6 +322,10 @@ const API_ERROR_DEFINITIONS = {
|
|
|
328
322
|
status: 404,
|
|
329
323
|
message: "Project not found"
|
|
330
324
|
},
|
|
325
|
+
"asset/child-not-deletable": {
|
|
326
|
+
status: 409,
|
|
327
|
+
message: "This asset was extracted from another asset (its `parentId`), so it can't be deleted on its own. Delete the asset it was extracted from instead, which deletes it too."
|
|
328
|
+
},
|
|
331
329
|
"asset/review-changed": {
|
|
332
330
|
status: 409,
|
|
333
331
|
message: "The asset changed during review. Refresh and review the current decision."
|
|
@@ -340,9 +338,9 @@ const API_ERROR_DEFINITIONS = {
|
|
|
340
338
|
status: 500,
|
|
341
339
|
message: "Failed to update asset"
|
|
342
340
|
},
|
|
343
|
-
"asset/
|
|
341
|
+
"asset/held": {
|
|
344
342
|
status: 423,
|
|
345
|
-
message: "
|
|
343
|
+
message: "The asset is held and this request can't change or deliver it. details.hold is `safety` for a safety hold or `copyright` for a copyright claim."
|
|
346
344
|
},
|
|
347
345
|
"asset/processing": {
|
|
348
346
|
status: 409,
|
|
@@ -380,7 +378,7 @@ const API_ERROR_DEFINITIONS = {
|
|
|
380
378
|
status: 409,
|
|
381
379
|
message: "A reviewer has decided this asset, so its moderation can't be re-run."
|
|
382
380
|
},
|
|
383
|
-
"support/
|
|
381
|
+
"support-ticket/not-found": {
|
|
384
382
|
status: 404,
|
|
385
383
|
message: "Support ticket not found."
|
|
386
384
|
},
|
|
@@ -404,9 +402,13 @@ const API_ERROR_DEFINITIONS = {
|
|
|
404
402
|
status: 409,
|
|
405
403
|
message: "A folder cannot be moved inside itself or one of its descendants."
|
|
406
404
|
},
|
|
407
|
-
"lens/
|
|
405
|
+
"lens/not-found": {
|
|
406
|
+
status: 404,
|
|
407
|
+
message: "Lens not found. Check the lens ID or identifier in the portal."
|
|
408
|
+
},
|
|
409
|
+
"lens/identifier-taken": {
|
|
408
410
|
status: 409,
|
|
409
|
-
message: "
|
|
411
|
+
message: "The project already has a lens with this identifier. Update that lens, or give this one another identifier."
|
|
410
412
|
},
|
|
411
413
|
"lens/identifier-reserved": {
|
|
412
414
|
status: 409,
|
|
@@ -416,7 +418,7 @@ const API_ERROR_DEFINITIONS = {
|
|
|
416
418
|
status: 404,
|
|
417
419
|
message: "Hash list not found. Check the list ID in the portal."
|
|
418
420
|
},
|
|
419
|
-
"hash-list/
|
|
421
|
+
"hash-list-entry/not-found": {
|
|
420
422
|
status: 404,
|
|
421
423
|
message: "Hash list entry not found."
|
|
422
424
|
},
|
|
@@ -424,7 +426,7 @@ const API_ERROR_DEFINITIONS = {
|
|
|
424
426
|
status: 409,
|
|
425
427
|
message: "This project has the most hash lists it can hold. Delete a list to add another."
|
|
426
428
|
},
|
|
427
|
-
"hash-list/
|
|
429
|
+
"hash-list-entry/limit-reached": {
|
|
428
430
|
status: 409,
|
|
429
431
|
message: "This project's hash lists hold the most entries they can. Remove entries to add more."
|
|
430
432
|
},
|
|
@@ -480,22 +482,14 @@ const API_ERROR_DEFINITIONS = {
|
|
|
480
482
|
status: 401,
|
|
481
483
|
message: "This upload preset only accepts uploads with an upload token. Sign one on your server with uploadTokens.sign and pass it to the client."
|
|
482
484
|
},
|
|
483
|
-
"
|
|
485
|
+
"remote-url/not-allowed": {
|
|
484
486
|
status: 403,
|
|
485
487
|
message: "This project doesn't accept URLs from this domain. Change the allowed or blocked domains under Project settings."
|
|
486
488
|
},
|
|
487
|
-
"upload/website-rate-limit-
|
|
489
|
+
"upload/website-rate-limit-reached": {
|
|
488
490
|
status: 429,
|
|
489
491
|
message: "This project has submitted too many websites in the last minute. Wait for the Retry-After period, or lower the pace of submissions."
|
|
490
492
|
},
|
|
491
|
-
"upload-preset/content-type-not-allowed": {
|
|
492
|
-
status: 415,
|
|
493
|
-
message: "This upload preset doesn't accept this file type."
|
|
494
|
-
},
|
|
495
|
-
"upload-preset/too-large": {
|
|
496
|
-
status: 413,
|
|
497
|
-
message: "This file is larger than the upload preset allows."
|
|
498
|
-
},
|
|
499
493
|
"upload-preset/daily-limit-reached": {
|
|
500
494
|
status: 429,
|
|
501
495
|
message: "You have reached this upload preset's daily upload limit. Try again after midnight UTC."
|
|
@@ -520,11 +514,11 @@ const API_ERROR_DEFINITIONS = {
|
|
|
520
514
|
status: 409,
|
|
521
515
|
message: "The upload token has already been used. Each token uploads one asset."
|
|
522
516
|
},
|
|
523
|
-
"
|
|
517
|
+
"remote-url/invalid": {
|
|
524
518
|
status: 400,
|
|
525
519
|
message: "Remote URLs must use HTTP or HTTPS and cannot target private networks, localhost names or URL credentials."
|
|
526
520
|
},
|
|
527
|
-
"
|
|
521
|
+
"remote-url/unavailable": {
|
|
528
522
|
status: 422,
|
|
529
523
|
message: "The URL responded with an error status. Check that it is publicly reachable."
|
|
530
524
|
},
|
|
@@ -556,10 +550,6 @@ const API_ERROR_DEFINITIONS = {
|
|
|
556
550
|
status: 400,
|
|
557
551
|
message: "The decision's action is not valid for this appeal."
|
|
558
552
|
},
|
|
559
|
-
"appeal/safety-held": {
|
|
560
|
-
status: 409,
|
|
561
|
-
message: "A safety hold prevents this appeal from being submitted or applied."
|
|
562
|
-
},
|
|
563
553
|
"appeal/content-unavailable": {
|
|
564
554
|
status: 409,
|
|
565
555
|
message: "The appeal's content is unavailable, or the asset's content was purged, so it can only be blocked."
|
|
@@ -597,8 +587,9 @@ const CALMLENS_ERROR_CODES = {
|
|
|
597
587
|
...SDK_ERROR_CODES
|
|
598
588
|
};
|
|
599
589
|
const BRAND = Symbol.for("calmlens.sdk.CalmLensError");
|
|
600
|
-
const RETRYABLE_STATUSES = /* @__PURE__ */ new Set([
|
|
590
|
+
const RETRYABLE_STATUSES$1 = /* @__PURE__ */ new Set([
|
|
601
591
|
429,
|
|
592
|
+
500,
|
|
602
593
|
502,
|
|
603
594
|
503,
|
|
604
595
|
504
|
|
@@ -643,12 +634,12 @@ var CalmLensError = class CalmLensError extends Error {
|
|
|
643
634
|
}
|
|
644
635
|
/**
|
|
645
636
|
* Whether repeating the same request may succeed: transport failures, timeouts (a request's
|
|
646
|
-
* `timeoutMs` or `waitForDecision`'s deadline), throttling (429), gateway errors (502, 503, 504)
|
|
637
|
+
* `timeoutMs` or `waitForDecision`'s deadline), throttling (429), internal and gateway errors (500, 502, 503, 504)
|
|
647
638
|
* and idempotent requests still in progress. Only repeat a create or upload with the same
|
|
648
639
|
* `idempotencyKey`.
|
|
649
640
|
*/
|
|
650
641
|
isRetryable() {
|
|
651
|
-
return RETRYABLE_CODES.has(this.code) || this.status !== void 0 && RETRYABLE_STATUSES.has(this.status);
|
|
642
|
+
return RETRYABLE_CODES.has(this.code) || this.status !== void 0 && RETRYABLE_STATUSES$1.has(this.status);
|
|
652
643
|
}
|
|
653
644
|
};
|
|
654
645
|
const invalidArgument = (message, details) => new CalmLensError(SDK_ERROR_CODES.INVALID_ARGUMENT, {
|
|
@@ -656,6 +647,304 @@ const invalidArgument = (message, details) => new CalmLensError(SDK_ERROR_CODES.
|
|
|
656
647
|
details
|
|
657
648
|
});
|
|
658
649
|
const invalidConfig = (message) => new CalmLensError(SDK_ERROR_CODES.INVALID_CONFIG, { message });
|
|
650
|
+
// src/client/CalmLensVersion.ts
|
|
651
|
+
/** This SDK's version, from its package.json. */
|
|
652
|
+
const SDK_VERSION = "0.21.0";
|
|
653
|
+
const runtimeName = () => {
|
|
654
|
+
const runtime = globalThis;
|
|
655
|
+
if (isReactNativeRuntime()) return "react-native";
|
|
656
|
+
if (runtime.Bun?.version) return `bun/${runtime.Bun.version}`;
|
|
657
|
+
if (runtime.Deno?.version?.deno) return `deno/${runtime.Deno.version.deno}`;
|
|
658
|
+
if (runtime.navigator?.userAgent === "Cloudflare-Workers") return "workerd";
|
|
659
|
+
if (runtime.process?.versions?.node) return `node/${runtime.process.versions.node}`;
|
|
660
|
+
return "unknown";
|
|
661
|
+
};
|
|
662
|
+
/** The `User-Agent` the SDK sends from server runtimes, e.g. `calmlens-js/0.10.0 (node/22.12.0)`. */
|
|
663
|
+
const getUserAgent = () => `calmlens-js/${SDK_VERSION} (${runtimeName()})`;
|
|
664
|
+
/** True in a web page, where API keys would be visible to every visitor. */
|
|
665
|
+
const isBrowserRuntime = () => typeof globalThis.window !== "undefined" && typeof globalThis.document !== "undefined";
|
|
666
|
+
/** True in a React Native app, where an API key ships inside the app for anyone to extract. */
|
|
667
|
+
const isReactNativeRuntime = () => globalThis.navigator?.product === "ReactNative";
|
|
668
|
+
const RETRY_MAX_DELAY_MS = 8e3;
|
|
669
|
+
const RETRYABLE_STATUSES = /* @__PURE__ */ new Set([
|
|
670
|
+
429,
|
|
671
|
+
500,
|
|
672
|
+
502,
|
|
673
|
+
503,
|
|
674
|
+
504
|
|
675
|
+
]);
|
|
676
|
+
const timeoutReason = () => {
|
|
677
|
+
const reason = /* @__PURE__ */ new Error("The operation timed out.");
|
|
678
|
+
reason.name = "TimeoutError";
|
|
679
|
+
return reason;
|
|
680
|
+
};
|
|
681
|
+
/**
|
|
682
|
+
* Links the callers' signals and a per-attempt deadline. `AbortSignal.any` holds its sources
|
|
683
|
+
* weakly, so a long-lived caller signal doesn't collect a listener per streamed response;
|
|
684
|
+
* runtimes without it get explicit listeners that `release` removes.
|
|
685
|
+
*/
|
|
686
|
+
const createAttemptSignal = (signals, timeoutMs) => {
|
|
687
|
+
const callers = signals.filter((signal) => signal !== void 0);
|
|
688
|
+
const deadline = new AbortController();
|
|
689
|
+
let timedOut = false;
|
|
690
|
+
let signal;
|
|
691
|
+
let onAbort;
|
|
692
|
+
if (typeof AbortSignal.any === "function") signal = AbortSignal.any([...callers, deadline.signal]);
|
|
693
|
+
else {
|
|
694
|
+
const controller = new AbortController();
|
|
695
|
+
signal = controller.signal;
|
|
696
|
+
onAbort = (event) => controller.abort(event.target.reason);
|
|
697
|
+
for (const source of [...callers, deadline.signal]) if (source.aborted) controller.abort(source.reason);
|
|
698
|
+
else source.addEventListener("abort", onAbort, { once: true });
|
|
699
|
+
}
|
|
700
|
+
let timer = timeoutMs === void 0 ? void 0 : setTimeout(() => {
|
|
701
|
+
timedOut = true;
|
|
702
|
+
deadline.abort(timeoutReason());
|
|
703
|
+
}, timeoutMs);
|
|
704
|
+
return {
|
|
705
|
+
signal,
|
|
706
|
+
isTimedOut: () => timedOut,
|
|
707
|
+
isCancelled: () => callers.some((caller) => caller.aborted),
|
|
708
|
+
clearDeadline: () => {
|
|
709
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
710
|
+
timer = void 0;
|
|
711
|
+
},
|
|
712
|
+
release: () => {
|
|
713
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
714
|
+
timer = void 0;
|
|
715
|
+
if (onAbort) for (const caller of callers) caller.removeEventListener("abort", onAbort);
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
};
|
|
719
|
+
/**
|
|
720
|
+
* A redirect the SDK must not follow: it would send the API key to another origin. Browsers report
|
|
721
|
+
* a manual redirect as an opaque response; other runtimes return the 3xx with its Location.
|
|
722
|
+
*/
|
|
723
|
+
const isRedirect = (response) => response.type === "opaqueredirect" || response.status >= 300 && response.status < 400 && response.headers.has("location");
|
|
724
|
+
/** Turns anything thrown while sending or reading a request into a `CalmLensError`. */
|
|
725
|
+
const toFailure = (cause, attempt) => {
|
|
726
|
+
if (CalmLensError.isCalmLensError(cause)) return cause;
|
|
727
|
+
if (attempt.isCancelled()) return new CalmLensError(SDK_ERROR_CODES.CANCELLED, {
|
|
728
|
+
message: "Request cancelled",
|
|
729
|
+
cause
|
|
730
|
+
});
|
|
731
|
+
if (attempt.isTimedOut()) return new CalmLensError(SDK_ERROR_CODES.TIMEOUT, {
|
|
732
|
+
message: "Request timed out",
|
|
733
|
+
cause
|
|
734
|
+
});
|
|
735
|
+
return new CalmLensError(SDK_ERROR_CODES.TRANSPORT_ERROR, {
|
|
736
|
+
message: "Request failed",
|
|
737
|
+
cause
|
|
738
|
+
});
|
|
739
|
+
};
|
|
740
|
+
const sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
741
|
+
if (signal?.aborted) {
|
|
742
|
+
reject(new CalmLensError(SDK_ERROR_CODES.CANCELLED, { message: "Request cancelled" }));
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
const onAbort = () => {
|
|
746
|
+
clearTimeout(timer);
|
|
747
|
+
reject(new CalmLensError(SDK_ERROR_CODES.CANCELLED, { message: "Request cancelled" }));
|
|
748
|
+
};
|
|
749
|
+
const timer = setTimeout(() => {
|
|
750
|
+
signal?.removeEventListener("abort", onAbort);
|
|
751
|
+
resolve();
|
|
752
|
+
}, ms);
|
|
753
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
754
|
+
});
|
|
755
|
+
/** Exponential backoff with jitter: half the delay is fixed, the other half random. */
|
|
756
|
+
const getRetryDelayMs = (attempt, random = Math.random) => {
|
|
757
|
+
const delay = Math.min(RETRY_MAX_DELAY_MS, 500 * 2 ** attempt);
|
|
758
|
+
return Math.round(delay / 2 + random() * (delay / 2));
|
|
759
|
+
};
|
|
760
|
+
/** Parses `Retry-After` as seconds or an HTTP date, in seconds from `now`. */
|
|
761
|
+
const parseRetryAfter = (value, now = Date.now()) => {
|
|
762
|
+
if (!value) return void 0;
|
|
763
|
+
const trimmed = value.trim();
|
|
764
|
+
if (/^\d+$/.test(trimmed)) return Number(trimmed);
|
|
765
|
+
const date = Date.parse(trimmed);
|
|
766
|
+
if (Number.isNaN(date)) return void 0;
|
|
767
|
+
return Math.max(0, Math.ceil((date - now) / 1e3));
|
|
768
|
+
};
|
|
769
|
+
/** Bodies that can be sent again unchanged. Streams are consumed by the first attempt. */
|
|
770
|
+
const isReplayableBody = (body) => body === void 0 || body === null || typeof body === "string" || body instanceof Blob || body instanceof ArrayBuffer || ArrayBuffer.isView(body) || body instanceof URLSearchParams;
|
|
771
|
+
const isApiErrorPayload = (value) => !!value && typeof value === "object" && typeof value.code === "string";
|
|
772
|
+
/** Reads at most `limit` bytes of a body, failing with `sdk/response-too-large` beyond that. */
|
|
773
|
+
const readBody = async (response, limit) => {
|
|
774
|
+
const declared = Number(response.headers.get("content-length"));
|
|
775
|
+
const tooLarge = () => new CalmLensError(SDK_ERROR_CODES.RESPONSE_TOO_LARGE, {
|
|
776
|
+
message: `Response body exceeds ${limit} bytes`,
|
|
777
|
+
status: response.status,
|
|
778
|
+
requestId: response.headers.get("x-request-id") ?? void 0,
|
|
779
|
+
headers: response.headers
|
|
780
|
+
});
|
|
781
|
+
if (Number.isFinite(declared) && declared > limit) {
|
|
782
|
+
await response.body?.cancel().catch(() => {});
|
|
783
|
+
throw tooLarge();
|
|
784
|
+
}
|
|
785
|
+
if (!response.body) return /* @__PURE__ */ new Uint8Array(0);
|
|
786
|
+
const reader = response.body.getReader();
|
|
787
|
+
const chunks = [];
|
|
788
|
+
let total = 0;
|
|
789
|
+
for (;;) {
|
|
790
|
+
const { done, value } = await reader.read();
|
|
791
|
+
if (done) break;
|
|
792
|
+
total += value.byteLength;
|
|
793
|
+
if (total > limit) {
|
|
794
|
+
await reader.cancel().catch(() => {});
|
|
795
|
+
throw tooLarge();
|
|
796
|
+
}
|
|
797
|
+
chunks.push(value);
|
|
798
|
+
}
|
|
799
|
+
const bytes = new Uint8Array(total);
|
|
800
|
+
let offset = 0;
|
|
801
|
+
for (const chunk of chunks) {
|
|
802
|
+
bytes.set(chunk, offset);
|
|
803
|
+
offset += chunk.byteLength;
|
|
804
|
+
}
|
|
805
|
+
return bytes;
|
|
806
|
+
};
|
|
807
|
+
const responseInfo = (response) => ({
|
|
808
|
+
status: response.status,
|
|
809
|
+
requestId: response.headers.get("x-request-id") ?? void 0,
|
|
810
|
+
headers: response.headers,
|
|
811
|
+
retryAfter: parseRetryAfter(response.headers.get("retry-after"))
|
|
812
|
+
});
|
|
813
|
+
/** The `CalmLensError` for a non-2xx response whose body has been read. */
|
|
814
|
+
const toHttpError = (response, bytes) => {
|
|
815
|
+
let data;
|
|
816
|
+
try {
|
|
817
|
+
data = JSON.parse(new TextDecoder().decode(bytes));
|
|
818
|
+
} catch {}
|
|
819
|
+
if (isApiErrorPayload(data)) {
|
|
820
|
+
const { code, message, details, requestId } = data;
|
|
821
|
+
const info = responseInfo(response);
|
|
822
|
+
return new CalmLensError(code, {
|
|
823
|
+
message: message ?? code,
|
|
824
|
+
...info,
|
|
825
|
+
requestId: info.requestId ?? (typeof requestId === "string" ? requestId : void 0),
|
|
826
|
+
details
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
return new CalmLensError(SDK_ERROR_CODES.HTTP_ERROR, {
|
|
830
|
+
message: `HTTP ${response.status}`,
|
|
831
|
+
...responseInfo(response)
|
|
832
|
+
});
|
|
833
|
+
};
|
|
834
|
+
/** Sends requests with the client's credentials, deadlines, retries and response limits. */
|
|
835
|
+
var CalmLensTransport = class {
|
|
836
|
+
constructor(settings) {
|
|
837
|
+
this.settings = settings;
|
|
838
|
+
this.sleep = settings.sleep ?? sleep;
|
|
839
|
+
}
|
|
840
|
+
headersFor(request) {
|
|
841
|
+
const headers = new Headers(request.init?.headers);
|
|
842
|
+
for (const [name, value] of Object.entries(request.headers ?? {})) headers.set(name, value);
|
|
843
|
+
if (!headers.has("accept") && request.deadline === "body") headers.set("accept", "application/json");
|
|
844
|
+
if (this.settings.apiKey) headers.set("x-api-key", this.settings.apiKey);
|
|
845
|
+
if (!isBrowserRuntime()) headers.set("user-agent", getUserAgent());
|
|
846
|
+
if (request.idempotencyKey) headers.set("idempotency-key", request.idempotencyKey);
|
|
847
|
+
return Object.fromEntries(headers.entries());
|
|
848
|
+
}
|
|
849
|
+
canRetry(request) {
|
|
850
|
+
return this.settings.maxRetries > 0 && (request.method === "GET" || request.method === "HEAD" || !!request.idempotencyKey) && isReplayableBody(request.body);
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Sends a request and returns the response, retrying transport failures, timeouts, 429, 500, 502–504 and
|
|
854
|
+
* `idempotency/request-in-progress` when the request is safe to repeat. Non-2xx responses
|
|
855
|
+
* throw unless `allowHttpErrors` is set. Call `release` once the body has been read.
|
|
856
|
+
*/
|
|
857
|
+
async send(request, { allowHttpErrors = false } = {}) {
|
|
858
|
+
const fetchImpl = request.fetch ?? this.settings.fetch;
|
|
859
|
+
const retryable = this.canRetry(request);
|
|
860
|
+
const headers = this.headersFor(request);
|
|
861
|
+
for (let attemptNumber = 0;; attemptNumber++) {
|
|
862
|
+
const canRetryAgain = retryable && attemptNumber < this.settings.maxRetries;
|
|
863
|
+
const attempt = createAttemptSignal([this.settings.signal, request.init?.signal ?? void 0], request.timeoutMs);
|
|
864
|
+
let response;
|
|
865
|
+
try {
|
|
866
|
+
if (attempt.signal.aborted) throw attempt.signal.reason;
|
|
867
|
+
response = await fetchImpl(request.url, {
|
|
868
|
+
...request.init,
|
|
869
|
+
method: request.method,
|
|
870
|
+
headers,
|
|
871
|
+
body: request.body,
|
|
872
|
+
redirect: "manual",
|
|
873
|
+
signal: attempt.signal,
|
|
874
|
+
duplex: "half"
|
|
875
|
+
});
|
|
876
|
+
if (isRedirect(response)) {
|
|
877
|
+
await response.body?.cancel().catch(() => {});
|
|
878
|
+
throw new CalmLensError(SDK_ERROR_CODES.HTTP_ERROR, {
|
|
879
|
+
message: `Unexpected redirect (HTTP ${response.status})`,
|
|
880
|
+
...responseInfo(response),
|
|
881
|
+
status: response.status || void 0
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
} catch (cause) {
|
|
885
|
+
attempt.release();
|
|
886
|
+
const failure = toFailure(cause, attempt);
|
|
887
|
+
if (canRetryAgain && failure.isRetryable()) {
|
|
888
|
+
await this.sleep(getRetryDelayMs(attemptNumber), this.settings.signal);
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
throw failure;
|
|
892
|
+
}
|
|
893
|
+
if (request.deadline === "headers") attempt.clearDeadline();
|
|
894
|
+
if (response.ok) return {
|
|
895
|
+
response,
|
|
896
|
+
attempt
|
|
897
|
+
};
|
|
898
|
+
if (allowHttpErrors) {
|
|
899
|
+
const retryAfter = parseRetryAfter(response.headers.get("retry-after"));
|
|
900
|
+
const delayMs = retryAfter !== void 0 ? retryAfter * 1e3 : getRetryDelayMs(attemptNumber);
|
|
901
|
+
if (!canRetryAgain || !RETRYABLE_STATUSES.has(response.status) || delayMs > 6e4) return {
|
|
902
|
+
response,
|
|
903
|
+
attempt
|
|
904
|
+
};
|
|
905
|
+
attempt.release();
|
|
906
|
+
await response.body?.cancel().catch(() => {});
|
|
907
|
+
await this.sleep(delayMs, this.settings.signal);
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
let error;
|
|
911
|
+
try {
|
|
912
|
+
error = toHttpError(response, await readBody(response, this.settings.maxResponseBytes));
|
|
913
|
+
} catch (cause) {
|
|
914
|
+
error = toFailure(cause, attempt);
|
|
915
|
+
} finally {
|
|
916
|
+
attempt.release();
|
|
917
|
+
}
|
|
918
|
+
const retryDelayMs = error.retryAfter !== void 0 ? error.retryAfter * 1e3 : getRetryDelayMs(attemptNumber);
|
|
919
|
+
if (canRetryAgain && retryDelayMs <= 6e4 && error.isRetryable()) {
|
|
920
|
+
await this.sleep(retryDelayMs, this.settings.signal);
|
|
921
|
+
continue;
|
|
922
|
+
}
|
|
923
|
+
throw error;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
/** Sends a request and parses its JSON response body. */
|
|
927
|
+
async json(request) {
|
|
928
|
+
const { response, attempt } = await this.send(request);
|
|
929
|
+
try {
|
|
930
|
+
const bytes = await readBody(response, this.settings.maxResponseBytes);
|
|
931
|
+
if (bytes.byteLength === 0 && (response.status === 204 || request.method === "DELETE")) return;
|
|
932
|
+
try {
|
|
933
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
934
|
+
} catch (cause) {
|
|
935
|
+
throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
936
|
+
message: `Invalid JSON response (HTTP ${response.status})`,
|
|
937
|
+
...responseInfo(response),
|
|
938
|
+
cause
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
} catch (cause) {
|
|
942
|
+
throw toFailure(cause, attempt);
|
|
943
|
+
} finally {
|
|
944
|
+
attempt.release();
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
};
|
|
659
948
|
// src/contract/SharedConstants-DxUCZwLZ.js
|
|
660
949
|
const IMPERSONATION_COOKIE_NAME = "CL_impersonation";
|
|
661
950
|
const DAY_MS = 864e5;
|
|
@@ -1028,6 +1317,14 @@ const UPLOAD_MIME_TYPES = [
|
|
|
1028
1317
|
"application/msword",
|
|
1029
1318
|
"application/rtf",
|
|
1030
1319
|
"application/vnd.oasis.opendocument.text",
|
|
1320
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
1321
|
+
"application/vnd.ms-excel.sheet.macroenabled.12",
|
|
1322
|
+
"application/vnd.ms-excel",
|
|
1323
|
+
"application/vnd.oasis.opendocument.spreadsheet",
|
|
1324
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
1325
|
+
"application/vnd.ms-powerpoint.presentation.macroenabled.12",
|
|
1326
|
+
"application/vnd.ms-powerpoint",
|
|
1327
|
+
"application/vnd.oasis.opendocument.presentation",
|
|
1031
1328
|
"application/javascript",
|
|
1032
1329
|
"application/json",
|
|
1033
1330
|
"application/x-javascript",
|
|
@@ -1035,26 +1332,6 @@ const UPLOAD_MIME_TYPES = [
|
|
|
1035
1332
|
"application/xml",
|
|
1036
1333
|
"application/yaml"
|
|
1037
1334
|
];
|
|
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
|
-
};
|
|
1058
1335
|
// src/client/CalmLensUtils.ts
|
|
1059
1336
|
const assertHttpUrl = (name, value) => {
|
|
1060
1337
|
if (value === void 0) return;
|
|
@@ -1103,6 +1380,8 @@ const validateAppClientOptions = (options) => {
|
|
|
1103
1380
|
if ("apiKey" in options && options.apiKey !== void 0) throw invalidConfig("CalmLensAppClient never takes an API key, which anyone using the browser or app could read. Upload through uploadPresetId, and keep the API key in CalmLensServerClient on your server.");
|
|
1104
1381
|
if (!options.uploadPresetId) throw invalidConfig("Upload preset ID is required");
|
|
1105
1382
|
configPathSegment(options.uploadPresetId, "Upload preset ID");
|
|
1383
|
+
if (options.projectId !== void 0) configPathSegment(options.projectId, "Project ID");
|
|
1384
|
+
assertHttpUrl("cdnBaseUrl", options.cdnBaseUrl);
|
|
1106
1385
|
if (options.token !== void 0 && typeof options.token !== "string" && typeof options.token !== "function") throw invalidConfig("token must be a string or a function that returns one");
|
|
1107
1386
|
validateConnectionOptions(options);
|
|
1108
1387
|
};
|
|
@@ -1112,6 +1391,16 @@ const validateRequestOptions = (options) => {
|
|
|
1112
1391
|
assertInteger("uploadTimeoutMs", options.uploadTimeoutMs, 1);
|
|
1113
1392
|
assertInteger("maxRetries", options.maxRetries, 0);
|
|
1114
1393
|
};
|
|
1394
|
+
/** The options that name an asset's CDN URL and a resource beneath it. */
|
|
1395
|
+
const CDN_LOCATION_KEYS = [
|
|
1396
|
+
"assetId",
|
|
1397
|
+
"externalId",
|
|
1398
|
+
"lens",
|
|
1399
|
+
"projectId",
|
|
1400
|
+
"resource",
|
|
1401
|
+
"transform",
|
|
1402
|
+
"viewerClaims"
|
|
1403
|
+
];
|
|
1115
1404
|
/**
|
|
1116
1405
|
* Option keys of methods that send no request of their own, or that take keys of their own beside
|
|
1117
1406
|
* a request's; CalmLensOptionKeys, generated from the API, has the rest.
|
|
@@ -1122,23 +1411,10 @@ const LOCAL_OPTION_KEYS = {
|
|
|
1122
1411
|
"signal",
|
|
1123
1412
|
"timeoutMs"
|
|
1124
1413
|
],
|
|
1125
|
-
"cdn.getAssetUrl":
|
|
1126
|
-
|
|
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
|
-
],
|
|
1414
|
+
"cdn.getAssetUrl": CDN_LOCATION_KEYS,
|
|
1415
|
+
"cdn.serve": [...CDN_LOCATION_KEYS, "init"],
|
|
1140
1416
|
"uploadTokens.sign": [
|
|
1141
|
-
"
|
|
1417
|
+
"expiresIn",
|
|
1142
1418
|
"externalId",
|
|
1143
1419
|
"uploadPresetId"
|
|
1144
1420
|
]
|
|
@@ -1204,7 +1480,7 @@ const encodePathSegment = (value, name) => {
|
|
|
1204
1480
|
/**
|
|
1205
1481
|
* Whether the API accepts an upload of this MIME type: an image, audio, video, text, document or
|
|
1206
1482
|
* website type, not a container such as `application/octet-stream`. It refuses any other type with
|
|
1207
|
-
* `upload/
|
|
1483
|
+
* `upload/unsupported-type`.
|
|
1208
1484
|
*/
|
|
1209
1485
|
const isAcceptedUploadMimeType = (mimeType) => {
|
|
1210
1486
|
const type = normalizeUploadMimeType(mimeType);
|
|
@@ -1285,7 +1561,7 @@ const checkTransformOptions = (options) => {
|
|
|
1285
1561
|
* CDN does (packages/shared/src/TransformSelector.ts): an optional first `@lens`, then `key=value`
|
|
1286
1562
|
* options with dotted keys for nested ones (a bare key is `true`). Values are numbers, `true`,
|
|
1287
1563
|
* `false`, hex colours (`#` added) for colour options, or text. Throws on anything the CDN refuses
|
|
1288
|
-
* as `
|
|
1564
|
+
* as `transform/invalid`. Used by the mock CDN.
|
|
1289
1565
|
*/
|
|
1290
1566
|
const parseTransformSelector = (selector) => {
|
|
1291
1567
|
if (!selector) return {};
|
|
@@ -1366,13 +1642,6 @@ const transformSelector = (transform) => {
|
|
|
1366
1642
|
return transform;
|
|
1367
1643
|
};
|
|
1368
1644
|
const DEFAULT_CDN_BASE_URL = `https://cdn.${DOMAIN}/v1`;
|
|
1369
|
-
const CDN_RESOURCES = /* @__PURE__ */ new Set([
|
|
1370
|
-
"original",
|
|
1371
|
-
"rendered",
|
|
1372
|
-
"placeholder"
|
|
1373
|
-
]);
|
|
1374
|
-
/** The longest signed URL lifetime the API accepts: 24 hours. */
|
|
1375
|
-
const MAX_SIGNED_URL_SECONDS = 86400;
|
|
1376
1645
|
/** The operations `assets.batch` runs. */
|
|
1377
1646
|
const ASSET_BATCH_OPERATIONS = ["delete", "remove-content"];
|
|
1378
1647
|
/** Refuses a batch the API would reject for its size, an ID or the operation. */
|
|
@@ -1381,79 +1650,27 @@ const validateBatchAssetsOptions = ({ assetIds, operation }) => {
|
|
|
1381
1650
|
if (assetIds.some((assetId) => typeof assetId !== "string" || !assetId)) throw invalidArgument("Every asset ID must be a non-empty string");
|
|
1382
1651
|
if (!ASSET_BATCH_OPERATIONS.includes(operation)) throw invalidArgument(`operation must be one of ${ASSET_BATCH_OPERATIONS.join(", ")}`);
|
|
1383
1652
|
};
|
|
1384
|
-
const validateSignedUrlOptions = (options) => {
|
|
1385
|
-
const { resource = "rendered", lens, transform, expiresInSeconds } = options;
|
|
1386
|
-
if (resource !== "original" && resource !== "rendered") throw invalidArgument("A signed URL's resource must be original or rendered");
|
|
1387
|
-
if (resource === "original" && (lens !== void 0 || transform !== void 0)) throw invalidArgument("Lenses and transforms apply only to the rendered resource");
|
|
1388
|
-
if (expiresInSeconds !== void 0 && (!Number.isInteger(expiresInSeconds) || expiresInSeconds < 1 || expiresInSeconds > MAX_SIGNED_URL_SECONDS)) throw invalidArgument("expiresInSeconds must be a whole number from 1 to 86400");
|
|
1389
|
-
};
|
|
1390
|
-
/**
|
|
1391
|
-
* Builds an asset's CDN URL without a client: no API key and no request, so it works in browsers.
|
|
1392
|
-
* `CalmLensServerClient`'s `cdn.getAssetUrl` uses it too.
|
|
1393
|
-
*
|
|
1394
|
-
* `resource` is `rendered` (default), `original` or `placeholder`. Only `rendered` takes a lens or
|
|
1395
|
-
* transform, and it serves images in the best format the browser accepts. A
|
|
1396
|
-
* placeholder is a small blurred PNG that the CDN serves publicly for every asset whatever its
|
|
1397
|
-
* visibility or moderation status, without requiring age confirmation.
|
|
1398
|
-
*/
|
|
1399
|
-
const getAssetUrl = ({ projectId, assetIdentifier, cdnBaseUrl = DEFAULT_CDN_BASE_URL, resource = "rendered", ...options }) => {
|
|
1400
|
-
if (!CDN_RESOURCES.has(resource)) throw invalidArgument("resource must be original, rendered or placeholder");
|
|
1401
|
-
if (resource === "original" && (options.lens !== void 0 || options.transform !== void 0)) throw invalidArgument("Lenses and transforms apply only to the rendered resource");
|
|
1402
|
-
if (resource === "placeholder" && (options.lens !== void 0 || options.transform !== void 0)) throw invalidArgument("A placeholder takes no lens or transform");
|
|
1403
|
-
const url = `${cdnBaseUrl.replace(/\/+$/, "")}/assets/${encodePathSegment(projectId, "Project ID")}/${encodePathSegment(assetIdentifier, "Asset identifier")}/${resource}`;
|
|
1404
|
-
return appendCdnSelector(url, options);
|
|
1405
|
-
};
|
|
1406
1653
|
/**
|
|
1407
|
-
*
|
|
1408
|
-
*
|
|
1654
|
+
* Serialises a query object the way the API reads it: plain values as text, lists of IDs and enum
|
|
1655
|
+
* values comma-separated, and structured values as JSON. Every key and value is percent-encoded
|
|
1656
|
+
* and missing values are omitted.
|
|
1409
1657
|
*/
|
|
1410
|
-
const
|
|
1411
|
-
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
if (!claims) throw invalidArgument("Invalid viewerClaims");
|
|
1416
|
-
query.set("viewerClaims", JSON.stringify(claims));
|
|
1417
|
-
}
|
|
1418
|
-
return query.size ? `${path}?${query}` : path;
|
|
1419
|
-
};
|
|
1420
|
-
const appendCdnPathSelector = (url, options) => {
|
|
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;
|
|
1424
|
-
};
|
|
1425
|
-
const appendQueryValue = (parts, key, value) => {
|
|
1426
|
-
if (value === void 0 || value === null) return;
|
|
1427
|
-
if (Array.isArray(value)) {
|
|
1428
|
-
for (const [index, item] of value.entries()) appendQueryValue(parts, `${key}[${index}]`, item);
|
|
1429
|
-
return;
|
|
1430
|
-
}
|
|
1431
|
-
if (typeof value === "object") {
|
|
1432
|
-
for (const [field, item] of Object.entries(value)) appendQueryValue(parts, `${key}[${field}]`, item);
|
|
1433
|
-
return;
|
|
1434
|
-
}
|
|
1435
|
-
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
1436
|
-
};
|
|
1658
|
+
const stringifyQuery = (query) => Object.entries(query).flatMap(([key, value]) => {
|
|
1659
|
+
if (value === void 0 || value === null) return [];
|
|
1660
|
+
const text = Array.isArray(value) ? value.every((item) => typeof item === "string" || typeof item === "number") ? value.join(",") : JSON.stringify(value) : typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
1661
|
+
return [`${encodeURIComponent(key)}=${encodeURIComponent(text)}`];
|
|
1662
|
+
}).join("&");
|
|
1437
1663
|
/**
|
|
1438
|
-
*
|
|
1439
|
-
* `
|
|
1440
|
-
* percent-encoded and missing values are omitted.
|
|
1664
|
+
* Whether an asset is settled: its `classification.status` is `completed` (moderation decided it)
|
|
1665
|
+
* or `failed`. `assets.waitForDecision` returns at the first such state.
|
|
1441
1666
|
*/
|
|
1442
|
-
const
|
|
1443
|
-
const parts = [];
|
|
1444
|
-
for (const [key, value] of Object.entries(query)) appendQueryValue(parts, key, value);
|
|
1445
|
-
return parts.join("&");
|
|
1446
|
-
};
|
|
1447
|
-
/**
|
|
1448
|
-
* Whether an asset has a moderation decision (`classification.moderation.status` is no longer
|
|
1449
|
-
* `pending`) or failed processing; `assets.waitForDecision` returns at the first such state.
|
|
1450
|
-
*/
|
|
1451
|
-
const isAssetDecided = (asset) => asset.classification.moderation.status !== "pending" || asset.classification.status === "failed";
|
|
1667
|
+
const isAssetDecided = (asset) => asset.classification.status === "completed" || asset.classification.status === "failed";
|
|
1452
1668
|
const DECISION_POLL_DELAY_FACTOR = 1.5;
|
|
1453
1669
|
const DECISION_POLL_MAX_DELAY_MS = 2e3;
|
|
1454
1670
|
const DEFAULT_DECISION_TIMEOUT_MS = 6e4;
|
|
1455
1671
|
/**
|
|
1456
|
-
* Retrieves an asset until it
|
|
1672
|
+
* Retrieves an asset until it is settled (see `isAssetDecided`), waiting 0.5s between checks and
|
|
1673
|
+
* 1.5 times longer
|
|
1457
1674
|
* each time, up to 2s. Rejects with `sdk/timeout` once `timeoutMs` passes without one.
|
|
1458
1675
|
*/
|
|
1459
1676
|
const pollForDecision = async (retrieve, { timeoutMs = DEFAULT_DECISION_TIMEOUT_MS, signal }, sleep, now = Date.now) => {
|
|
@@ -1477,24 +1694,177 @@ const pollForDecision = async (retrieve, { timeoutMs = DEFAULT_DECISION_TIMEOUT_
|
|
|
1477
1694
|
delay = Math.min(DECISION_POLL_MAX_DELAY_MS, delay * DECISION_POLL_DELAY_FACTOR);
|
|
1478
1695
|
}
|
|
1479
1696
|
};
|
|
1480
|
-
// src/client/
|
|
1481
|
-
/**
|
|
1482
|
-
const
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
if (
|
|
1490
|
-
|
|
1697
|
+
// src/client/CalmLensViewerClaims.ts
|
|
1698
|
+
/** The ISO 3166-1 alpha-2 countries a viewer's `region` can be. EU is not a viewer country. */
|
|
1699
|
+
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(" "));
|
|
1700
|
+
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(" "));
|
|
1701
|
+
/**
|
|
1702
|
+
* The claims to send, with `region` and `ageConfirmed` in that order, or `undefined` when the
|
|
1703
|
+
* value isn't an object of only a viewer country `region` and a boolean `ageConfirmed`.
|
|
1704
|
+
*/
|
|
1705
|
+
const parseViewerClaims = (value) => {
|
|
1706
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
1707
|
+
const { region, ageConfirmed, ...rest } = value;
|
|
1708
|
+
if (Object.keys(rest).length) return void 0;
|
|
1709
|
+
if (region !== void 0 && (typeof region !== "string" || !VIEWER_COUNTRIES.has(region))) return void 0;
|
|
1710
|
+
if (ageConfirmed !== void 0 && typeof ageConfirmed !== "boolean") return void 0;
|
|
1711
|
+
return {
|
|
1712
|
+
...region !== void 0 && { region },
|
|
1713
|
+
...ageConfirmed !== void 0 && { ageConfirmed }
|
|
1714
|
+
};
|
|
1715
|
+
};
|
|
1716
|
+
// src/client/CalmLensCdn.ts
|
|
1717
|
+
const ASSET_RESOURCE_PATHS = {
|
|
1718
|
+
original: "original",
|
|
1719
|
+
rendered: "rendered",
|
|
1720
|
+
preview: "preview",
|
|
1721
|
+
placeholder: "placeholder",
|
|
1722
|
+
hls: "hls/index.m3u8",
|
|
1723
|
+
embed: "embed",
|
|
1724
|
+
info: "info"
|
|
1725
|
+
};
|
|
1726
|
+
/** The prefix of an asset URL segment that names the asset by its external ID. */
|
|
1727
|
+
const EXTERNAL_ID_SEGMENT_PREFIX = "ext:";
|
|
1728
|
+
/** Every CDN resource beneath an asset URL, as `getAssetUrl` and `signAssetUrl` accept them. */
|
|
1729
|
+
const CDN_RESOURCES = Object.keys(ASSET_RESOURCE_PATHS);
|
|
1730
|
+
const UNSELECTABLE = /* @__PURE__ */ new Set([
|
|
1731
|
+
"original",
|
|
1732
|
+
"hls",
|
|
1733
|
+
"embed",
|
|
1734
|
+
"placeholder",
|
|
1735
|
+
"info"
|
|
1736
|
+
]);
|
|
1737
|
+
/** The longest signed URL lifetime the API accepts: 24 hours. */
|
|
1738
|
+
const MAX_SIGNED_URL_EXPIRES_IN = 86400;
|
|
1739
|
+
/**
|
|
1740
|
+
* The asset segment of a CDN URL: the asset ID, or `ext:` and the URL-encoded external ID. Exactly
|
|
1741
|
+
* one of them must be given.
|
|
1742
|
+
*/
|
|
1743
|
+
const getAssetSegment = (options) => {
|
|
1744
|
+
const { assetId, externalId } = options;
|
|
1745
|
+
if (assetId === void 0 === (externalId === void 0)) throw invalidArgument("Pass either assetId or externalId");
|
|
1746
|
+
if (assetId !== void 0) return encodePathSegment(assetId, "Asset ID");
|
|
1747
|
+
if (typeof externalId !== "string" || !externalId) throw invalidArgument("External ID is required");
|
|
1748
|
+
return `${EXTERNAL_ID_SEGMENT_PREFIX}${encodeURIComponent(externalId)}`;
|
|
1749
|
+
};
|
|
1750
|
+
/**
|
|
1751
|
+
* The viewer claims a URL carries: the region, and `ageConfirmed` only when true. Unconfirmed age
|
|
1752
|
+
* and no region are the CDN's defaults, left out so default URLs stay cacheable.
|
|
1753
|
+
*/
|
|
1754
|
+
const toUrlViewerClaims = (claims) => {
|
|
1755
|
+
if (claims === void 0) return void 0;
|
|
1756
|
+
const parsed = parseViewerClaims(claims);
|
|
1757
|
+
if (!parsed) throw invalidArgument("Invalid viewerClaims");
|
|
1758
|
+
const { region, ageConfirmed } = parsed;
|
|
1759
|
+
if (!region && ageConfirmed !== true) return void 0;
|
|
1760
|
+
return {
|
|
1761
|
+
...region ? { region } : {},
|
|
1762
|
+
...ageConfirmed === true ? { ageConfirmed } : {}
|
|
1763
|
+
};
|
|
1764
|
+
};
|
|
1765
|
+
/** The `?viewerClaims=` query of a URL with these claims, or an empty string for the defaults. */
|
|
1766
|
+
const viewerClaimsQuery = (claims) => {
|
|
1767
|
+
const sent = toUrlViewerClaims(claims);
|
|
1768
|
+
return sent ? `?${new URLSearchParams({ viewerClaims: JSON.stringify(sent) })}` : "";
|
|
1769
|
+
};
|
|
1770
|
+
/**
|
|
1771
|
+
* Appends a resource, its `@lens` and transform selector, and the viewer claims to an asset URL
|
|
1772
|
+
* (public or signed). Without `resource` the URL stays the asset URL, which takes no selector.
|
|
1773
|
+
*/
|
|
1774
|
+
const appendAssetLocation = (assetUrl, location) => {
|
|
1775
|
+
const { resource, lens, transform, viewerClaims } = location;
|
|
1776
|
+
const selected = lens !== void 0 || transform !== void 0;
|
|
1777
|
+
let path = assetUrl;
|
|
1778
|
+
if (resource === void 0) {
|
|
1779
|
+
if (selected) throw invalidArgument("A lens or transform needs a resource, such as rendered");
|
|
1780
|
+
} else {
|
|
1781
|
+
if (typeof resource !== "string" || !Object.hasOwn(ASSET_RESOURCE_PATHS, resource)) throw invalidArgument(`resource must be one of ${CDN_RESOURCES.join(", ")}`);
|
|
1782
|
+
if (UNSELECTABLE.has(resource) && selected) throw invalidArgument(`The ${resource} resource takes no lens or transform`);
|
|
1783
|
+
path = `${assetUrl}/${ASSET_RESOURCE_PATHS[resource]}`;
|
|
1784
|
+
const selector = transformSelector(transform);
|
|
1785
|
+
const parts = [...lens !== void 0 ? [`@${encodePathSegment(lens, "Lens")}`] : [], ...selector ? [typeof transform === "string" ? encodeURI(selector) : selector] : []];
|
|
1786
|
+
if (parts.length) path = `${path}/${parts.join(",")}`;
|
|
1787
|
+
}
|
|
1788
|
+
return `${path}${viewerClaimsQuery(viewerClaims)}`;
|
|
1789
|
+
};
|
|
1790
|
+
/** An asset's public URL beneath a CDN base URL, with any resource, selector and claims. */
|
|
1791
|
+
const buildAssetUrl = (cdnBaseUrl, projectId, options) => {
|
|
1792
|
+
const { assetId, externalId, resource, lens, transform, viewerClaims } = options;
|
|
1793
|
+
const base = `${cdnBaseUrl.replace(/\/+$/, "")}/assets/${encodePathSegment(projectId, "Project ID")}/${getAssetSegment({
|
|
1794
|
+
assetId,
|
|
1795
|
+
externalId
|
|
1796
|
+
})}`;
|
|
1797
|
+
return appendAssetLocation(base, {
|
|
1798
|
+
resource,
|
|
1799
|
+
lens,
|
|
1800
|
+
transform,
|
|
1801
|
+
viewerClaims
|
|
1802
|
+
});
|
|
1803
|
+
};
|
|
1804
|
+
/** Checks `signAssetUrl`'s own options as the API does, before anything is sent. */
|
|
1805
|
+
const validateSignAssetUrlOptions = (options) => {
|
|
1806
|
+
const { expiresIn, original } = options;
|
|
1807
|
+
if (expiresIn !== void 0 && (!Number.isInteger(expiresIn) || expiresIn < 1 || expiresIn > 86400)) throw invalidArgument(`expiresIn must be a whole number from 1 to ${MAX_SIGNED_URL_EXPIRES_IN}`);
|
|
1808
|
+
if (original !== void 0 && typeof original !== "boolean") throw invalidArgument("original must be a boolean");
|
|
1809
|
+
getAssetSegment(options);
|
|
1810
|
+
appendAssetLocation("", options);
|
|
1811
|
+
};
|
|
1812
|
+
/** An asset URL without its query: the viewer claims it carried, if any, are returned apart. */
|
|
1813
|
+
const splitAssetUrl = (url) => {
|
|
1814
|
+
const [path = "", query] = url.split("?", 2);
|
|
1815
|
+
const base = path.replace(/\/+$/, "");
|
|
1816
|
+
const raw = query ? new URLSearchParams(query).get("viewerClaims") : null;
|
|
1817
|
+
if (raw === null) return { base };
|
|
1818
|
+
try {
|
|
1819
|
+
return {
|
|
1820
|
+
base,
|
|
1821
|
+
claims: JSON.parse(raw)
|
|
1822
|
+
};
|
|
1823
|
+
} catch {
|
|
1824
|
+
throw invalidArgument("The asset URL's viewerClaims are not JSON");
|
|
1825
|
+
}
|
|
1826
|
+
};
|
|
1827
|
+
const isAssetInfo = (value) => {
|
|
1828
|
+
if (!value || typeof value !== "object") return false;
|
|
1829
|
+
const info = value;
|
|
1830
|
+
return typeof info.id === "string" && typeof info.projectId === "string" && typeof info.type === "string" && !!info.content && typeof info.content === "object" && (info.availability === "available" || info.availability === "age-restricted" || info.availability === "unavailable");
|
|
1831
|
+
};
|
|
1832
|
+
/**
|
|
1833
|
+
* The display info of an asset URL (public or signed): `{url}/info`, an allowlist of the asset's
|
|
1834
|
+
* public fields and whether this viewer can see it now (`availability`). Viewer claims come from
|
|
1835
|
+
* `viewerClaims`, else from the URL. A refusal throws `CalmLensError` with the CDN's code, such as
|
|
1836
|
+
* `signed-url/expired` or `asset/not-found`.
|
|
1837
|
+
*/
|
|
1838
|
+
const getAssetInfo = async (url, options = {}) => {
|
|
1839
|
+
if (typeof url !== "string" || !URL.canParse(url)) throw invalidArgument("url must be an absolute asset URL");
|
|
1840
|
+
const { base, claims } = splitAssetUrl(url);
|
|
1841
|
+
const infoUrl = `${base}/info${viewerClaimsQuery(options.viewerClaims ?? claims)}`;
|
|
1842
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
1843
|
+
let response;
|
|
1844
|
+
try {
|
|
1845
|
+
response = await fetcher(infoUrl, {
|
|
1846
|
+
headers: { Accept: "application/json" },
|
|
1847
|
+
signal: options.signal
|
|
1848
|
+
});
|
|
1849
|
+
} catch (cause) {
|
|
1850
|
+
if (options.signal?.aborted) throw cause;
|
|
1851
|
+
throw new CalmLensError(SDK_ERROR_CODES.TRANSPORT_ERROR, {
|
|
1852
|
+
message: "The asset's info could not be fetched",
|
|
1853
|
+
cause
|
|
1854
|
+
});
|
|
1855
|
+
}
|
|
1856
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
1857
|
+
if (!response.ok) throw toHttpError(response, bytes);
|
|
1858
|
+
let data;
|
|
1859
|
+
try {
|
|
1860
|
+
data = JSON.parse(new TextDecoder().decode(bytes));
|
|
1861
|
+
} catch {}
|
|
1862
|
+
if (!isAssetInfo(data)) throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
1863
|
+
message: "The CDN returned no asset info",
|
|
1864
|
+
status: response.status
|
|
1865
|
+
});
|
|
1866
|
+
return data;
|
|
1491
1867
|
};
|
|
1492
|
-
/** The `User-Agent` the SDK sends from server runtimes, e.g. `calmlens-js/0.10.0 (node/22.12.0)`. */
|
|
1493
|
-
const getUserAgent = () => `calmlens-js/${SDK_VERSION} (${runtimeName()})`;
|
|
1494
|
-
/** True in a web page, where API keys would be visible to every visitor. */
|
|
1495
|
-
const isBrowserRuntime = () => typeof globalThis.window !== "undefined" && typeof globalThis.document !== "undefined";
|
|
1496
|
-
/** True in a React Native app, where an API key ships inside the app for anyone to extract. */
|
|
1497
|
-
const isReactNativeRuntime = () => globalThis.navigator?.product === "ReactNative";
|
|
1498
1868
|
// src/contract/ModerationContextLimits-BIMUlk2e.js
|
|
1499
1869
|
/** The most recent earlier posts CalmLens uses. */
|
|
1500
1870
|
const MODERATION_CONTEXT_USED_ITEMS = 5;
|
|
@@ -1527,4 +1897,4 @@ const selectModerationContextItems = (items) => {
|
|
|
1527
1897
|
}
|
|
1528
1898
|
return selected;
|
|
1529
1899
|
};
|
|
1530
|
-
export {
|
|
1900
|
+
export { getRejectedUploadMimeTypeError as A, invalidArgument as B, validateBatchAssetsOptions as C, MAX_DIRECT_IMAGE_UPLOAD_BYTES as D, DOMAIN as E, isBrowserRuntime as F, API_ERROR_CODES as H, isReactNativeRuntime as I, CALMLENS_ERROR_CODES as L, CalmLensTransport as M, sleep as N, MAX_IMAGE_UPLOAD_BYTES as O, SDK_VERSION as P, CalmLensError as R, validateAppClientOptions as S, validateServerClientOptions as T, API_ERROR_DEFINITIONS as U, invalidConfig as V, randomUuid as _, appendAssetLocation as a, toTextAssetOptions as b, toUrlViewerClaims as c, checkOptionKeys as d, checkTransformOptions as f, pollForDecision as g, parseTransformSelector as h, CDN_RESOURCES as i, normalizeUploadMimeType as j, MAX_NON_IMAGE_UPLOAD_BYTES as k, validateSignAssetUrlOptions as l, isAcceptedUploadMimeType as m, MODERATION_CONTEXT_USED_ITEMS as n, buildAssetUrl as o, encodePathSegment as p, selectModerationContextItems as r, getAssetInfo as s, MODERATION_CONTEXT_USED_CHARACTERS as t, DEFAULT_CDN_BASE_URL as u, serializeTransform as v, validateRequestOptions as w, transformSelector as x, stringifyQuery as y, SDK_ERROR_CODES as z };
|