calmlens 0.29.1 → 0.29.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/calmlens.js +24 -2
- package/cjs/{BrowserUpload-CsxEB1Pr.js → BrowserUpload-CCXt4DAY.js} +1 -1
- package/cjs/{CalmLensAppClient-BWMcQM9v.js → CalmLensAppClient-ea-qXkmD.js} +7 -6
- package/cjs/{CalmLensConnection-DBgV8D1B.js → CalmLensConnection-BrySN2M3.js} +29 -28
- package/cjs/CalmLensError-DPHJaVjX.js +1066 -0
- package/cjs/{CalmLensServerClient-DYO3geSA.js → CalmLensServerClient-FD7H7KvL.js} +21 -20
- package/cjs/{TestTriggers-uL2Ec8Vt-cPmmKvYd.js → CalmLensTestInputArguments-BXDBAOg_.js} +50 -22
- package/cjs/{Core-Bl-aESvN.js → Core-DMFa3EUp.js} +4 -3
- package/cjs/{ModerationContextLimits-DHu2jHpo.js → ModerationContextLimits-1XP4ZTQk.js} +67 -1126
- package/cjs/{ReactUpload-BFVNyWoI.js → ReactUpload-gaeiPSeH.js} +1 -1
- package/cjs/{TestTriggers-dognME9k-PWyIfHMI.d.ts → TestTriggers-CFnel6a9.d.ts} +1 -2
- package/cjs/{UploadController-VM1qYwNq.js → UploadController-CyPTBuZg.js} +6 -6
- package/cjs/app.js +22 -21
- package/cjs/elements.js +4 -4
- package/cjs/index.js +21 -20
- package/cjs/react-native.js +4 -4
- package/cjs/react.js +5 -5
- package/cjs/server.js +22 -21
- package/cjs/test-inputs.d.ts +6 -2
- package/cjs/test-inputs.js +23 -13
- package/cjs/testing.d.ts +3 -3
- package/cjs/testing.js +138 -133
- package/cjs/{ui-BCiLF8cU.js → ui-DNP1uWQy.js} +2 -2
- package/cjs/ui.js +3 -3
- package/cjs/vue.js +4 -4
- package/esm/{BrowserUpload-DB3WpaC1.js → BrowserUpload-Bu6eWqQS.js} +1 -1
- package/esm/{CalmLensAppClient-Dg-jPs4B.js → CalmLensAppClient-xp-fH6Lz.js} +3 -2
- package/esm/{CalmLensConnection-Di7K7Wnl.js → CalmLensConnection-DwG5yBk2.js} +2 -1
- package/esm/CalmLensError-BDWThPCr.js +917 -0
- package/esm/{CalmLensServerClient-Pdp7TI8y.js → CalmLensServerClient-CKlNBBo3.js} +3 -2
- package/esm/{TestTriggers-uL2Ec8Vt-DYbTEJWm.js → CalmLensTestInputArguments-Xh4GIadS.js} +22 -1
- package/esm/{Core-CKk4teFu.js → Core-DnCeTmvS.js} +3 -2
- package/esm/{ModerationContextLimits-xvxUjGfL.js → ModerationContextLimits-CtAyz60h.js} +3 -918
- package/esm/{ReactUpload-DY5qQ70s.js → ReactUpload-D30YlRui.js} +1 -1
- package/esm/{TestTriggers-dognME9k-PWyIfHMI.d.ts → TestTriggers-CFnel6a9.d.ts} +1 -2
- package/esm/{UploadController-wyor-5Z2.js → UploadController-DENryQ8H.js} +2 -2
- package/esm/app.js +3 -2
- package/esm/elements.js +4 -4
- package/esm/index.js +3 -1
- package/esm/react-native.js +4 -4
- package/esm/react.js +5 -5
- package/esm/server.js +3 -2
- package/esm/test-inputs.d.ts +6 -2
- package/esm/test-inputs.js +12 -1
- package/esm/testing.d.ts +3 -3
- package/esm/testing.js +11 -7
- package/esm/{ui-BqF49fSy.js → ui-DUEBbRJ0.js} +2 -2
- package/esm/ui.js +3 -3
- package/esm/vue.js +4 -4
- package/package.json +1 -1
|
@@ -1,919 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/** Error codes the CalmLens API documents, by name. */
|
|
3
|
-
const API_ERROR_CODES = {
|
|
4
|
-
INVALID_VIEWER_CLAIMS: "viewer-claims/invalid",
|
|
5
|
-
AGE_CONFIRMATION_REQUIRED: "viewer/age-confirmation-required",
|
|
6
|
-
INVALID_VIEWER_REGION: "viewer-region/invalid",
|
|
7
|
-
VIEWER_REGION_REQUIRED: "viewer/region-required",
|
|
8
|
-
REGIONAL_EVIDENCE_REQUIRED: "asset/regional-evidence-required",
|
|
9
|
-
SIGNED_URL_EXPIRED: "signed-url/expired",
|
|
10
|
-
SIGNED_URL_INVALID: "signed-url/invalid",
|
|
11
|
-
SIGNED_URL_ORIGINAL_NOT_GRANTED: "signed-url/original-not-granted",
|
|
12
|
-
INVALID_REQUEST: "validation/invalid-request",
|
|
13
|
-
INVALID_TYPE: "validation/invalid-type",
|
|
14
|
-
TOO_SMALL: "validation/too-small",
|
|
15
|
-
TOO_BIG: "validation/too-big",
|
|
16
|
-
INVALID_FORMAT: "validation/invalid-format",
|
|
17
|
-
INVALID_VALUE: "validation/invalid-value",
|
|
18
|
-
UNKNOWN_FIELD: "validation/unknown-field",
|
|
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",
|
|
24
|
-
UNAUTHENTICATED: "auth/unauthenticated",
|
|
25
|
-
TOKEN_EXPIRED: "session-token/expired",
|
|
26
|
-
INVALID_TOKEN: "session-token/invalid",
|
|
27
|
-
SEARCH_UNAVAILABLE: "search/unavailable",
|
|
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
|
-
PERMISSION_DENIED: "auth/permission-denied",
|
|
37
|
-
UPLOAD_TOO_LARGE: "upload/too-large",
|
|
38
|
-
DOCUMENT_TOO_MANY_ITEMS: "document/too-many-items",
|
|
39
|
-
MEDIA_DURATION_LIMIT: "media/duration-limit",
|
|
40
|
-
INVALID_IMAGE: "image/invalid",
|
|
41
|
-
IMAGE_TOO_LARGE: "image/too-large",
|
|
42
|
-
FREE_UPLOADS_EXHAUSTED: "usage/free-uploads-exhausted",
|
|
43
|
-
WEBSITE_BILLING_REQUIRED: "payment/billing-required",
|
|
44
|
-
UPLOADS_PAUSED: "usage/uploads-paused",
|
|
45
|
-
UNSUPPORTED_UPLOAD_TYPE: "upload/unsupported-type",
|
|
46
|
-
INVALID_UPLOAD_PAYLOAD: "upload-payload/invalid",
|
|
47
|
-
UPLOAD_OPTIONS_IN_QUERY: "upload/options-in-query",
|
|
48
|
-
USE_UPLOAD_PART: "upload/use-upload-part",
|
|
49
|
-
UPLOAD_NOT_OPEN: "upload/not-open",
|
|
50
|
-
INVALID_UPLOAD_PART_NUMBER: "upload-part/invalid-number",
|
|
51
|
-
UPLOAD_MISSING: "upload/missing",
|
|
52
|
-
UPLOAD_SIZE_MISMATCH: "upload/size-mismatch",
|
|
53
|
-
INVALID_IDEMPOTENCY_KEY: "idempotency/invalid-key",
|
|
54
|
-
IDEMPOTENCY_KEY_REUSED: "idempotency/key-reused",
|
|
55
|
-
IDEMPOTENT_REQUEST_IN_PROGRESS: "idempotency/request-in-progress",
|
|
56
|
-
NO_RENDERED_VERSION: "asset/no-rendered-version",
|
|
57
|
-
ASSET_NOT_FOUND: "asset/not-found",
|
|
58
|
-
PROJECT_NOT_FOUND: "project/not-found",
|
|
59
|
-
ASSET_CHILD_NOT_DELETABLE: "asset/child-not-deletable",
|
|
60
|
-
ASSET_REVIEW_CHANGED: "asset/review-changed",
|
|
61
|
-
ASSET_REVIEW_NOTE_REQUIRED: "asset/review-note-required",
|
|
62
|
-
ASSET_UPDATE_FAILED: "asset/update-failed",
|
|
63
|
-
ASSET_HELD: "asset/held",
|
|
64
|
-
ASSET_PROCESSING: "asset/processing",
|
|
65
|
-
ASSET_DECISION_NOT_ALLOWED: "asset/decision-not-allowed",
|
|
66
|
-
ASSET_DECISION_UNCHANGED: "asset/decision-unchanged",
|
|
67
|
-
ASSET_NOT_RETRYABLE: "asset/not-retryable",
|
|
68
|
-
ASSET_CONTENT_UNAVAILABLE: "asset/content-unavailable",
|
|
69
|
-
ASSET_CONTENT_PURGED: "asset/content-purged",
|
|
70
|
-
ASSET_NOT_REVIEWABLE: "asset/not-reviewable",
|
|
71
|
-
SUPPORT_TICKET_NOT_FOUND: "support-ticket/not-found",
|
|
72
|
-
DUPLICATE_EXTERNAL_ID: "asset/duplicate-external-id",
|
|
73
|
-
FOLDER_NOT_FOUND: "folder/not-found",
|
|
74
|
-
DUPLICATE_FOLDER_NAME: "folder/duplicate-name",
|
|
75
|
-
FOLDER_NOT_EMPTY: "folder/not-empty",
|
|
76
|
-
FOLDER_PARENT_CYCLE: "folder/parent-cycle",
|
|
77
|
-
LENS_NOT_FOUND: "lens/not-found",
|
|
78
|
-
LENS_IDENTIFIER_TAKEN: "lens/identifier-taken",
|
|
79
|
-
LENS_IDENTIFIER_RESERVED: "lens/identifier-reserved",
|
|
80
|
-
HASH_LIST_NOT_FOUND: "hash-list/not-found",
|
|
81
|
-
HASH_LIST_ENTRY_NOT_FOUND: "hash-list-entry/not-found",
|
|
82
|
-
HASH_LIST_LIMIT_REACHED: "hash-list/limit-reached",
|
|
83
|
-
HASH_LIST_ENTRY_LIMIT_REACHED: "hash-list-entry/limit-reached",
|
|
84
|
-
HASH_LIST_ENTRY_QUALITY_TOO_LOW: "hash-list-entry/quality-too-low",
|
|
85
|
-
HASH_LIST_ASSET_NOT_HASHED: "hash-list/asset-not-hashed",
|
|
86
|
-
POLICY_NOT_FOUND: "policy/not-found",
|
|
87
|
-
POLICY_REVISION_CONFLICT: "policy/revision-conflict",
|
|
88
|
-
POLICY_PROJECTS_CHANGED: "policy/projects-changed",
|
|
89
|
-
POLICY_IN_USE: "policy/in-use",
|
|
90
|
-
POLICY_USED_BY_ANOTHER_PROJECT: "policy/used-by-another-project",
|
|
91
|
-
POLICY_NO_PRESET: "policy/no-preset",
|
|
92
|
-
POLICY_PRESET_VERSION_CONFLICT: "policy/preset-version-conflict",
|
|
93
|
-
POLICY_PRESET_UPDATE_UNAVAILABLE: "policy/preset-update-unavailable",
|
|
94
|
-
POLICY_AUTOMATIC_UPDATES_UNAVAILABLE: "policy/automatic-updates-unavailable",
|
|
95
|
-
UPLOAD_PRESET_NOT_FOUND: "upload-preset/not-found",
|
|
96
|
-
UPLOAD_PRESET_DISABLED: "upload-preset/disabled",
|
|
97
|
-
UPLOAD_PRESET_TOKEN_REQUIRED: "upload-preset/token-required",
|
|
98
|
-
REMOTE_URL_NOT_ALLOWED: "remote-url/not-allowed",
|
|
99
|
-
UPLOAD_RATE_LIMIT_REACHED: "upload/rate-limit-reached",
|
|
100
|
-
UPLOAD_PRESET_DAILY_LIMIT_REACHED: "upload-preset/daily-limit-reached",
|
|
101
|
-
UPLOAD_PRESET_ORIGIN_NOT_ALLOWED: "upload-preset/origin-not-allowed",
|
|
102
|
-
UPLOAD_PRESET_FIELD_NOT_ALLOWED: "upload-preset/field-not-allowed",
|
|
103
|
-
UPLOAD_PRESET_REVISION_CONFLICT: "upload-preset/revision-conflict",
|
|
104
|
-
UPLOAD_PRESET_KEY_TAKEN: "upload-preset/key-taken",
|
|
105
|
-
UPLOAD_PRESET_DAILY_LIMIT_REQUIRED: "upload-preset/daily-limit-required",
|
|
106
|
-
UPLOAD_PRESET_INVALID_FOLDER: "upload-preset/invalid-folder",
|
|
107
|
-
UPLOAD_PRESET_INVALID_POLICY: "upload-preset/invalid-policy",
|
|
108
|
-
PROJECT_SETTINGS_REVISION_CONFLICT: "project-settings/revision-conflict",
|
|
109
|
-
SEARCH_ESTIMATE_CHANGED: "search/estimate-changed",
|
|
110
|
-
METADATA_FIELD_NOT_FOUND: "metadata-field/not-found",
|
|
111
|
-
UPLOAD_TOKEN_INVALID: "upload-token/invalid",
|
|
112
|
-
UPLOAD_TOKEN_EXPIRED: "upload-token/expired",
|
|
113
|
-
UPLOAD_TOKEN_USED: "upload-token/used",
|
|
114
|
-
INVALID_REMOTE_URL: "remote-url/invalid",
|
|
115
|
-
REMOTE_URL_UNAVAILABLE: "remote-url/unavailable",
|
|
116
|
-
APPEAL_NOT_FOUND: "appeal/not-found",
|
|
117
|
-
APPEAL_JUDGMENT_NOT_FOUND: "appeal/judgment-not-found",
|
|
118
|
-
APPEAL_ASSET_NOT_FOUND: "appeal/asset-not-found",
|
|
119
|
-
APPEAL_PERMISSION_DENIED: "appeal/permission-denied",
|
|
120
|
-
APPEAL_ALREADY_REVIEWED: "appeal/already-reviewed",
|
|
121
|
-
APPEAL_DECISION_CHANGED: "appeal/decision-changed",
|
|
122
|
-
APPEAL_INVALID_ACTION: "appeal/invalid-action",
|
|
123
|
-
APPEAL_CONTENT_UNAVAILABLE: "appeal/content-unavailable"
|
|
124
|
-
};
|
|
125
|
-
/** The HTTP status and default message the API returns with each documented error code. */
|
|
126
|
-
const API_ERROR_DEFINITIONS = {
|
|
127
|
-
"viewer-claims/invalid": {
|
|
128
|
-
status: 400,
|
|
129
|
-
message: "Supply a viewerClaims object with an optional region and boolean ageConfirmed."
|
|
130
|
-
},
|
|
131
|
-
"viewer/age-confirmation-required": {
|
|
132
|
-
status: 403,
|
|
133
|
-
message: "Your application has not confirmed age-restricted delivery for this viewer."
|
|
134
|
-
},
|
|
135
|
-
"viewer-region/invalid": {
|
|
136
|
-
status: 400,
|
|
137
|
-
message: "Supply the viewer's ISO country code, such as DE or GB."
|
|
138
|
-
},
|
|
139
|
-
"viewer/region-required": {
|
|
140
|
-
status: 403,
|
|
141
|
-
message: "Supply the viewer region when regional delivery controls apply."
|
|
142
|
-
},
|
|
143
|
-
"asset/regional-evidence-required": {
|
|
144
|
-
status: 403,
|
|
145
|
-
message: "This asset needs moderation evidence for the newly served jurisdiction."
|
|
146
|
-
},
|
|
147
|
-
"signed-url/expired": {
|
|
148
|
-
status: 403,
|
|
149
|
-
message: "The signed URL has expired. Create a new one on your server."
|
|
150
|
-
},
|
|
151
|
-
"signed-url/invalid": {
|
|
152
|
-
status: 403,
|
|
153
|
-
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."
|
|
154
|
-
},
|
|
155
|
-
"signed-url/original-not-granted": {
|
|
156
|
-
status: 403,
|
|
157
|
-
message: "This signed asset URL doesn't grant the original file. Sign a URL for the original resource."
|
|
158
|
-
},
|
|
159
|
-
"validation/invalid-request": {
|
|
160
|
-
status: 400,
|
|
161
|
-
message: "The request's parameters, query or body are invalid. details.issues lists each problem, with its path and issue code."
|
|
162
|
-
},
|
|
163
|
-
"validation/invalid-type": {
|
|
164
|
-
status: 400,
|
|
165
|
-
message: "Issue code in details.issues: a field has the wrong type."
|
|
166
|
-
},
|
|
167
|
-
"validation/too-small": {
|
|
168
|
-
status: 400,
|
|
169
|
-
message: "Issue code in details.issues: a value is below its minimum."
|
|
170
|
-
},
|
|
171
|
-
"validation/too-big": {
|
|
172
|
-
status: 400,
|
|
173
|
-
message: "Issue code in details.issues: a value is above its maximum."
|
|
174
|
-
},
|
|
175
|
-
"validation/invalid-format": {
|
|
176
|
-
status: 400,
|
|
177
|
-
message: "Issue code in details.issues: a string is not in the required format, such as an ID or URL."
|
|
178
|
-
},
|
|
179
|
-
"validation/invalid-value": {
|
|
180
|
-
status: 400,
|
|
181
|
-
message: "Issue code in details.issues: a field has a value it cannot take."
|
|
182
|
-
},
|
|
183
|
-
"validation/unknown-field": {
|
|
184
|
-
status: 400,
|
|
185
|
-
message: "Issue code in details.issues: the request has a field this endpoint does not accept."
|
|
186
|
-
},
|
|
187
|
-
"request/unsupported-content-type": {
|
|
188
|
-
status: 415,
|
|
189
|
-
message: "Send the request body as application/json."
|
|
190
|
-
},
|
|
191
|
-
"filter/invalid": {
|
|
192
|
-
status: 400,
|
|
193
|
-
message: "The filter has invalid syntax or names a field that can't be filtered."
|
|
194
|
-
},
|
|
195
|
-
"ordering/unsupported-field": {
|
|
196
|
-
status: 400,
|
|
197
|
-
message: "The list cannot be ordered by this field."
|
|
198
|
-
},
|
|
199
|
-
"request/route-not-found": {
|
|
200
|
-
status: 404,
|
|
201
|
-
message: "No endpoint matches this method and path."
|
|
202
|
-
},
|
|
203
|
-
"server/internal-error": {
|
|
204
|
-
status: 500,
|
|
205
|
-
message: "An internal error occurred. Retry later, and quote requestId to support."
|
|
206
|
-
},
|
|
207
|
-
"auth/unauthenticated": {
|
|
208
|
-
status: 401,
|
|
209
|
-
message: "Authentication required."
|
|
210
|
-
},
|
|
211
|
-
"session-token/expired": {
|
|
212
|
-
status: 401,
|
|
213
|
-
message: "The session token has expired. Sign in again."
|
|
214
|
-
},
|
|
215
|
-
"session-token/invalid": {
|
|
216
|
-
status: 401,
|
|
217
|
-
message: "The session token is invalid. Sign in again."
|
|
218
|
-
},
|
|
219
|
-
"search/unavailable": {
|
|
220
|
-
status: 503,
|
|
221
|
-
message: "Search is temporarily unavailable. Retry later."
|
|
222
|
-
},
|
|
223
|
-
"transform/invalid": {
|
|
224
|
-
status: 400,
|
|
225
|
-
message: "The transform names an unknown type or is not a valid selector."
|
|
226
|
-
},
|
|
227
|
-
"transform-options/invalid": {
|
|
228
|
-
status: 400,
|
|
229
|
-
message: "The transform's options are invalid for its type."
|
|
230
|
-
},
|
|
231
|
-
"remote-url/too-many-redirects": {
|
|
232
|
-
status: 400,
|
|
233
|
-
message: "The remote URL redirected too many times."
|
|
234
|
-
},
|
|
235
|
-
"cursor/invalid": {
|
|
236
|
-
status: 400,
|
|
237
|
-
message: "The cursor is invalid or belongs to a different query."
|
|
238
|
-
},
|
|
239
|
-
"api-key/missing": {
|
|
240
|
-
status: 401,
|
|
241
|
-
message: "Authentication required. Send your project API key in the X-Api-Key header."
|
|
242
|
-
},
|
|
243
|
-
"api-key/invalid": {
|
|
244
|
-
status: 401,
|
|
245
|
-
message: "The API key is invalid, revoked or expired. Create a key under Developer → API Keys."
|
|
246
|
-
},
|
|
247
|
-
"api-key/project-mismatch": {
|
|
248
|
-
status: 403,
|
|
249
|
-
message: "This API key belongs to a different project. Use a key created for the project that owns this resource."
|
|
250
|
-
},
|
|
251
|
-
"api-key/not-accepted": {
|
|
252
|
-
status: 403,
|
|
253
|
-
message: "API keys are only accepted by the public API at /v1."
|
|
254
|
-
},
|
|
255
|
-
"auth/permission-denied": {
|
|
256
|
-
status: 403,
|
|
257
|
-
message: "This API key lacks a permission the request needs (details.permission names it, such as assets:download for an asset's folder, and details.role the least role that includes it), or the resource belongs to another project."
|
|
258
|
-
},
|
|
259
|
-
"upload/too-large": {
|
|
260
|
-
status: 413,
|
|
261
|
-
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
|
-
},
|
|
263
|
-
"document/too-many-items": {
|
|
264
|
-
status: 422,
|
|
265
|
-
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
|
-
},
|
|
267
|
-
"media/duration-limit": {
|
|
268
|
-
status: 422,
|
|
269
|
-
message: "The audio or video is longer than allowed: details.durationSeconds is what its file states and details.limitSeconds the limit. Trim it or split it into separate uploads; before billing is set up, setting it up raises the limit."
|
|
270
|
-
},
|
|
271
|
-
"image/invalid": {
|
|
272
|
-
status: 422,
|
|
273
|
-
message: "The image is corrupt or cannot be decoded. Upload a valid image file."
|
|
274
|
-
},
|
|
275
|
-
"image/too-large": {
|
|
276
|
-
status: 422,
|
|
277
|
-
message: "The image exceeds a processing limit: details.limit is `bytes`, `pixels` or `dimension`. Reduce its size before uploading."
|
|
278
|
-
},
|
|
279
|
-
"usage/free-uploads-exhausted": {
|
|
280
|
-
status: 403,
|
|
281
|
-
message: "This project's organisation has used its free uploads. Set up billing to continue uploading."
|
|
282
|
-
},
|
|
283
|
-
"payment/billing-required": {
|
|
284
|
-
status: 409,
|
|
285
|
-
message: "Set up billing to upload websites."
|
|
286
|
-
},
|
|
287
|
-
"usage/uploads-paused": {
|
|
288
|
-
status: 402,
|
|
289
|
-
message: "This upload would pass its organisation's usage limits, so it was refused. See details.reason; an owner can review them in Billing."
|
|
290
|
-
},
|
|
291
|
-
"upload/unsupported-type": {
|
|
292
|
-
status: 415,
|
|
293
|
-
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 (details.contentType and details.allowedContentTypes say what was sent and what it accepts)."
|
|
294
|
-
},
|
|
295
|
-
"upload-payload/invalid": {
|
|
296
|
-
status: 400,
|
|
297
|
-
message: "Upload payload is invalid."
|
|
298
|
-
},
|
|
299
|
-
"upload/options-in-query": {
|
|
300
|
-
status: 400,
|
|
301
|
-
message: "Send the asset's name and fields in the request body (the JSON body, or the options part of a multipart/form-data upload), not in the query string."
|
|
302
|
-
},
|
|
303
|
-
"upload/use-upload-part": {
|
|
304
|
-
status: 409,
|
|
305
|
-
message: "Use uploadPart for multipart upload parts after the first part"
|
|
306
|
-
},
|
|
307
|
-
"upload/not-open": {
|
|
308
|
-
status: 409,
|
|
309
|
-
message: "Asset is not accepting additional parts"
|
|
310
|
-
},
|
|
311
|
-
"upload-part/invalid-number": {
|
|
312
|
-
status: 409,
|
|
313
|
-
message: "Multipart upload part number is invalid."
|
|
314
|
-
},
|
|
315
|
-
"upload/missing": {
|
|
316
|
-
status: 409,
|
|
317
|
-
message: "Multipart upload state is missing"
|
|
318
|
-
},
|
|
319
|
-
"upload/size-mismatch": {
|
|
320
|
-
status: 400,
|
|
321
|
-
message: "The uploaded parts do not add up to the totalSizeInBytes declared when the multipart upload started."
|
|
322
|
-
},
|
|
323
|
-
"idempotency/invalid-key": {
|
|
324
|
-
status: 400,
|
|
325
|
-
message: "The Idempotency-Key header must be 1 to 255 printable ASCII characters, such as a UUID."
|
|
326
|
-
},
|
|
327
|
-
"idempotency/key-reused": {
|
|
328
|
-
status: 409,
|
|
329
|
-
message: "This Idempotency-Key was already used for a different request. Use a new key for each distinct request."
|
|
330
|
-
},
|
|
331
|
-
"idempotency/request-in-progress": {
|
|
332
|
-
status: 409,
|
|
333
|
-
message: "A request with this Idempotency-Key is still being processed. Retry after the Retry-After delay to receive its result."
|
|
334
|
-
},
|
|
335
|
-
"asset/no-rendered-version": {
|
|
336
|
-
status: 404,
|
|
337
|
-
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."
|
|
338
|
-
},
|
|
339
|
-
"asset/not-found": {
|
|
340
|
-
status: 404,
|
|
341
|
-
message: "Asset not found"
|
|
342
|
-
},
|
|
343
|
-
"project/not-found": {
|
|
344
|
-
status: 404,
|
|
345
|
-
message: "Project not found"
|
|
346
|
-
},
|
|
347
|
-
"asset/child-not-deletable": {
|
|
348
|
-
status: 409,
|
|
349
|
-
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."
|
|
350
|
-
},
|
|
351
|
-
"asset/review-changed": {
|
|
352
|
-
status: 409,
|
|
353
|
-
message: "The asset changed during review. Refresh and review the current decision."
|
|
354
|
-
},
|
|
355
|
-
"asset/review-note-required": {
|
|
356
|
-
status: 400,
|
|
357
|
-
message: "A note is required when changing the decision."
|
|
358
|
-
},
|
|
359
|
-
"asset/update-failed": {
|
|
360
|
-
status: 500,
|
|
361
|
-
message: "Failed to update asset"
|
|
362
|
-
},
|
|
363
|
-
"asset/held": {
|
|
364
|
-
status: 423,
|
|
365
|
-
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."
|
|
366
|
-
},
|
|
367
|
-
"asset/processing": {
|
|
368
|
-
status: 409,
|
|
369
|
-
message: "Wait for the asset to finish uploading and processing before deciding it."
|
|
370
|
-
},
|
|
371
|
-
"asset/decision-not-allowed": {
|
|
372
|
-
status: 409,
|
|
373
|
-
message: "This asset has no moderation decision yet, so it can only be blocked or purged. Allow, limit or age-restrict it once moderation has decided it."
|
|
374
|
-
},
|
|
375
|
-
"asset/decision-unchanged": {
|
|
376
|
-
status: 409,
|
|
377
|
-
message: "The asset already has this moderation status."
|
|
378
|
-
},
|
|
379
|
-
"asset/not-retryable": {
|
|
380
|
-
status: 409,
|
|
381
|
-
message: "Only assets that failed to process (status error) can be retried."
|
|
382
|
-
},
|
|
383
|
-
"asset/content-unavailable": {
|
|
384
|
-
status: 409,
|
|
385
|
-
message: "This asset's content is no longer stored, so it can't be processed again. Upload it again instead."
|
|
386
|
-
},
|
|
387
|
-
"asset/content-purged": {
|
|
388
|
-
status: 409,
|
|
389
|
-
message: "This asset's content was purged, so it can only be blocked. Upload it again to have it moderated afresh."
|
|
390
|
-
},
|
|
391
|
-
"asset/not-reviewable": {
|
|
392
|
-
status: 409,
|
|
393
|
-
message: "The human review queue can't take this asset. details.reason is `child-asset` for content extracted from another asset (report the uploaded asset instead), `not-moderated` while it has no moderation decision yet, or `content-unavailable` when its content is no longer stored."
|
|
394
|
-
},
|
|
395
|
-
"support-ticket/not-found": {
|
|
396
|
-
status: 404,
|
|
397
|
-
message: "Support ticket not found."
|
|
398
|
-
},
|
|
399
|
-
"asset/duplicate-external-id": {
|
|
400
|
-
status: 409,
|
|
401
|
-
message: "An asset with this externalId already exists in the project."
|
|
402
|
-
},
|
|
403
|
-
"folder/not-found": {
|
|
404
|
-
status: 404,
|
|
405
|
-
message: "Folder not found"
|
|
406
|
-
},
|
|
407
|
-
"folder/duplicate-name": {
|
|
408
|
-
status: 409,
|
|
409
|
-
message: "A folder with this name already exists in this location."
|
|
410
|
-
},
|
|
411
|
-
"folder/not-empty": {
|
|
412
|
-
status: 409,
|
|
413
|
-
message: "Folder must be empty before it can be deleted."
|
|
414
|
-
},
|
|
415
|
-
"folder/parent-cycle": {
|
|
416
|
-
status: 409,
|
|
417
|
-
message: "A folder cannot be moved inside itself or one of its descendants."
|
|
418
|
-
},
|
|
419
|
-
"lens/not-found": {
|
|
420
|
-
status: 404,
|
|
421
|
-
message: "Lens not found. Check the lens ID or identifier in the portal."
|
|
422
|
-
},
|
|
423
|
-
"lens/identifier-taken": {
|
|
424
|
-
status: 409,
|
|
425
|
-
message: "The project already has a lens with this identifier. Update that lens, or give this one another identifier."
|
|
426
|
-
},
|
|
427
|
-
"lens/identifier-reserved": {
|
|
428
|
-
status: 409,
|
|
429
|
-
message: "The identifier belongs to a built-in lens (thumbnail, sm, md, lg, xl or 2xl). Give the lens another identifier."
|
|
430
|
-
},
|
|
431
|
-
"hash-list/not-found": {
|
|
432
|
-
status: 404,
|
|
433
|
-
message: "Hash list not found. Check the list ID in the portal."
|
|
434
|
-
},
|
|
435
|
-
"hash-list-entry/not-found": {
|
|
436
|
-
status: 404,
|
|
437
|
-
message: "Hash list entry not found."
|
|
438
|
-
},
|
|
439
|
-
"hash-list/limit-reached": {
|
|
440
|
-
status: 409,
|
|
441
|
-
message: "This project has the most hash lists it can hold. Delete a list to add another."
|
|
442
|
-
},
|
|
443
|
-
"hash-list-entry/limit-reached": {
|
|
444
|
-
status: 409,
|
|
445
|
-
message: "This project's hash lists hold the most entries they can. Remove entries to add more."
|
|
446
|
-
},
|
|
447
|
-
"hash-list-entry/quality-too-low": {
|
|
448
|
-
status: 422,
|
|
449
|
-
message: "This hash cannot be matched. Use a more detailed image or a hash of higher quality."
|
|
450
|
-
},
|
|
451
|
-
"hash-list/asset-not-hashed": {
|
|
452
|
-
status: 409,
|
|
453
|
-
message: "This asset has no perceptual hash. Only image assets that finished processing can be added."
|
|
454
|
-
},
|
|
455
|
-
"policy/not-found": {
|
|
456
|
-
status: 404,
|
|
457
|
-
message: "Policy not found. Check the policy ID in the portal."
|
|
458
|
-
},
|
|
459
|
-
"policy/revision-conflict": {
|
|
460
|
-
status: 409,
|
|
461
|
-
message: "The policy changed. Retrieve it again and retry with its current revision."
|
|
462
|
-
},
|
|
463
|
-
"policy/projects-changed": {
|
|
464
|
-
status: 409,
|
|
465
|
-
message: "The projects using this policy changed. Retrieve it again and review the affected projects before saving."
|
|
466
|
-
},
|
|
467
|
-
"policy/in-use": {
|
|
468
|
-
status: 409,
|
|
469
|
-
message: "Projects or upload presets still use this policy. Choose another policy for each of them before deleting it."
|
|
470
|
-
},
|
|
471
|
-
"policy/used-by-another-project": {
|
|
472
|
-
status: 409,
|
|
473
|
-
message: "Another project uses this policy, so it can only be changed from the portal or that project."
|
|
474
|
-
},
|
|
475
|
-
"policy/no-preset": {
|
|
476
|
-
status: 400,
|
|
477
|
-
message: "This policy has no preset baseline."
|
|
478
|
-
},
|
|
479
|
-
"policy/preset-version-conflict": {
|
|
480
|
-
status: 409,
|
|
481
|
-
message: "The preset changed. Review the latest differences and retry with its version."
|
|
482
|
-
},
|
|
483
|
-
"policy/preset-update-unavailable": {
|
|
484
|
-
status: 409,
|
|
485
|
-
message: "Only an unchanged copy of an older preset version can be updated. Reset or review your changes first."
|
|
486
|
-
},
|
|
487
|
-
"policy/automatic-updates-unavailable": {
|
|
488
|
-
status: 409,
|
|
489
|
-
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."
|
|
490
|
-
},
|
|
491
|
-
"upload-preset/not-found": {
|
|
492
|
-
status: 404,
|
|
493
|
-
message: "Upload preset not found. Check the preset ID in the portal."
|
|
494
|
-
},
|
|
495
|
-
"upload-preset/disabled": {
|
|
496
|
-
status: 403,
|
|
497
|
-
message: "This upload preset is paused. Turn it on in the portal to accept uploads."
|
|
498
|
-
},
|
|
499
|
-
"upload-preset/token-required": {
|
|
500
|
-
status: 401,
|
|
501
|
-
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."
|
|
502
|
-
},
|
|
503
|
-
"remote-url/not-allowed": {
|
|
504
|
-
status: 403,
|
|
505
|
-
message: "This project doesn't accept URLs from this domain. Change the allowed or blocked domains under Project settings."
|
|
506
|
-
},
|
|
507
|
-
"upload/rate-limit-reached": {
|
|
508
|
-
status: 429,
|
|
509
|
-
message: "This organisation has started too many uploads in the last 10 seconds. Wait for the Retry-After period, or lower the pace of uploads."
|
|
510
|
-
},
|
|
511
|
-
"upload-preset/daily-limit-reached": {
|
|
512
|
-
status: 429,
|
|
513
|
-
message: "You have reached this upload preset's daily upload limit. Try again after midnight UTC."
|
|
514
|
-
},
|
|
515
|
-
"upload-preset/origin-not-allowed": {
|
|
516
|
-
status: 403,
|
|
517
|
-
message: "This site isn't allowed to upload through this upload preset."
|
|
518
|
-
},
|
|
519
|
-
"upload-preset/field-not-allowed": {
|
|
520
|
-
status: 400,
|
|
521
|
-
message: "This field is set by the upload preset or the upload token and can't be changed by the upload."
|
|
522
|
-
},
|
|
523
|
-
"upload-preset/revision-conflict": {
|
|
524
|
-
status: 409,
|
|
525
|
-
message: "The upload preset changed, or was created or deleted, since you read it. Retrieve it again and retry with its current revision."
|
|
526
|
-
},
|
|
527
|
-
"upload-preset/key-taken": {
|
|
528
|
-
status: 409,
|
|
529
|
-
message: "Another upload preset in this project has this key. Choose a different key."
|
|
530
|
-
},
|
|
531
|
-
"upload-preset/daily-limit-required": {
|
|
532
|
-
status: 400,
|
|
533
|
-
message: "A preset that anyone can upload to needs a daily upload limit."
|
|
534
|
-
},
|
|
535
|
-
"upload-preset/invalid-folder": {
|
|
536
|
-
status: 400,
|
|
537
|
-
message: "The folder isn't in this project. Choose a folder from this project and try again."
|
|
538
|
-
},
|
|
539
|
-
"upload-preset/invalid-policy": {
|
|
540
|
-
status: 400,
|
|
541
|
-
message: "The policy isn't one of this organisation's. Choose one of its policies and try again."
|
|
542
|
-
},
|
|
543
|
-
"project-settings/revision-conflict": {
|
|
544
|
-
status: 409,
|
|
545
|
-
message: "The project's settings or metadata fields changed since you read them. Retrieve them again and retry with the current revision."
|
|
546
|
-
},
|
|
547
|
-
"search/estimate-changed": {
|
|
548
|
-
status: 409,
|
|
549
|
-
message: "Turning on AI media search needs a searchIndexingBudgetUnits of at least the current indexing estimate, which details.indexingUnits gives."
|
|
550
|
-
},
|
|
551
|
-
"metadata-field/not-found": {
|
|
552
|
-
status: 404,
|
|
553
|
-
message: "The project has no metadata field with this ID."
|
|
554
|
-
},
|
|
555
|
-
"upload-token/invalid": {
|
|
556
|
-
status: 401,
|
|
557
|
-
message: "The upload token is invalid. Sign a new one on your server with an active API key for this project."
|
|
558
|
-
},
|
|
559
|
-
"upload-token/expired": {
|
|
560
|
-
status: 401,
|
|
561
|
-
message: "The upload token has expired. Sign a new one on your server."
|
|
562
|
-
},
|
|
563
|
-
"upload-token/used": {
|
|
564
|
-
status: 409,
|
|
565
|
-
message: "The upload token has already been used. Each token uploads one asset."
|
|
566
|
-
},
|
|
567
|
-
"remote-url/invalid": {
|
|
568
|
-
status: 400,
|
|
569
|
-
message: "Remote URLs must use HTTP or HTTPS and cannot target private networks, localhost names or URL credentials."
|
|
570
|
-
},
|
|
571
|
-
"remote-url/unavailable": {
|
|
572
|
-
status: 422,
|
|
573
|
-
message: "The URL responded with an error status. Check that it is publicly reachable."
|
|
574
|
-
},
|
|
575
|
-
"appeal/not-found": {
|
|
576
|
-
status: 404,
|
|
577
|
-
message: "The appeal does not exist in this project."
|
|
578
|
-
},
|
|
579
|
-
"appeal/judgment-not-found": {
|
|
580
|
-
status: 404,
|
|
581
|
-
message: "The judgment event is unavailable, belongs to another project or cannot supply an asset decision. Supply explicit context instead."
|
|
582
|
-
},
|
|
583
|
-
"appeal/asset-not-found": {
|
|
584
|
-
status: 404,
|
|
585
|
-
message: "The linked asset does not exist in this project."
|
|
586
|
-
},
|
|
587
|
-
"appeal/permission-denied": {
|
|
588
|
-
status: 403,
|
|
589
|
-
message: "You cannot review this project's appeals."
|
|
590
|
-
},
|
|
591
|
-
"appeal/already-reviewed": {
|
|
592
|
-
status: 409,
|
|
593
|
-
message: "A reviewer already resolved this appeal."
|
|
594
|
-
},
|
|
595
|
-
"appeal/decision-changed": {
|
|
596
|
-
status: 409,
|
|
597
|
-
message: "The linked asset's decision changed after the appealed decision. Submit a new appeal for the current decision."
|
|
598
|
-
},
|
|
599
|
-
"appeal/invalid-action": {
|
|
600
|
-
status: 400,
|
|
601
|
-
message: "The decision's action is not valid for this appeal."
|
|
602
|
-
},
|
|
603
|
-
"appeal/content-unavailable": {
|
|
604
|
-
status: 409,
|
|
605
|
-
message: "The appeal's content is unavailable, or the asset's content was purged, so it can only be blocked."
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
// src/client/CalmLensError.ts
|
|
609
|
-
/** Codes for failures the SDK detects itself, before or instead of an API error response. */
|
|
610
|
-
const SDK_ERROR_CODES = {
|
|
611
|
-
/** The request could not be completed: DNS, TLS, a refused or reset connection, a truncated body. */
|
|
612
|
-
TRANSPORT_ERROR: "sdk/transport-error",
|
|
613
|
-
/** The request did not finish within `timeoutMs`. */
|
|
614
|
-
TIMEOUT: "sdk/timeout",
|
|
615
|
-
/** The caller's `AbortSignal` cancelled the request. */
|
|
616
|
-
CANCELLED: "sdk/cancelled",
|
|
617
|
-
/** A successful response whose body is not the JSON the operation returns. */
|
|
618
|
-
INVALID_RESPONSE: "sdk/invalid-response",
|
|
619
|
-
/** An HTTP failure without a CalmLens error body, for example from a proxy, or a redirect. */
|
|
620
|
-
HTTP_ERROR: "sdk/http-error",
|
|
621
|
-
/** A response body larger than `maxResponseBytes`. */
|
|
622
|
-
RESPONSE_TOO_LARGE: "sdk/response-too-large",
|
|
623
|
-
/** A method argument is missing or invalid, for example an empty asset ID. */
|
|
624
|
-
INVALID_ARGUMENT: "sdk/invalid-argument",
|
|
625
|
-
/** The client options are invalid, for example a missing API key. */
|
|
626
|
-
INVALID_CONFIG: "sdk/invalid-config",
|
|
627
|
-
/** No `fetch` implementation is available in this runtime. */
|
|
628
|
-
NO_FETCH: "sdk/no-fetch",
|
|
629
|
-
/** A webhook delivery whose signature or timestamp did not verify. */
|
|
630
|
-
INVALID_WEBHOOK_SIGNATURE: "sdk/invalid-webhook-signature",
|
|
631
|
-
/** A verified webhook delivery whose body is not a webhook event. */
|
|
632
|
-
INVALID_WEBHOOK_PAYLOAD: "sdk/invalid-webhook-payload"
|
|
633
|
-
};
|
|
634
|
-
/** Every error code the SDK can throw: the documented API codes and the SDK's own `sdk/*` codes. */
|
|
635
|
-
const CALMLENS_ERROR_CODES = {
|
|
636
|
-
...API_ERROR_CODES,
|
|
637
|
-
...SDK_ERROR_CODES
|
|
638
|
-
};
|
|
639
|
-
const KIND_PARENTS = {
|
|
640
|
-
error: null,
|
|
641
|
-
api: "error",
|
|
642
|
-
"bad-request": "api",
|
|
643
|
-
authentication: "api",
|
|
644
|
-
"permission-denied": "api",
|
|
645
|
-
"not-found": "api",
|
|
646
|
-
conflict: "api",
|
|
647
|
-
"payload-too-large": "api",
|
|
648
|
-
"unprocessable-entity": "api",
|
|
649
|
-
"rate-limit": "api",
|
|
650
|
-
server: "api",
|
|
651
|
-
connection: "error",
|
|
652
|
-
timeout: "error",
|
|
653
|
-
cancelled: "error",
|
|
654
|
-
"invalid-argument": "error",
|
|
655
|
-
configuration: "invalid-argument",
|
|
656
|
-
"invalid-response": "error",
|
|
657
|
-
"webhook-verification": "error"
|
|
658
|
-
};
|
|
659
|
-
const STATUS_KINDS = {
|
|
660
|
-
400: "bad-request",
|
|
661
|
-
401: "authentication",
|
|
662
|
-
403: "permission-denied",
|
|
663
|
-
404: "not-found",
|
|
664
|
-
409: "conflict",
|
|
665
|
-
413: "payload-too-large",
|
|
666
|
-
422: "unprocessable-entity",
|
|
667
|
-
429: "rate-limit"
|
|
668
|
-
};
|
|
669
|
-
/** The kinds of the SDK's own codes, whatever the status. */
|
|
670
|
-
const CODE_KINDS = {
|
|
671
|
-
"sdk/transport-error": "connection",
|
|
672
|
-
"sdk/timeout": "timeout",
|
|
673
|
-
"sdk/cancelled": "cancelled",
|
|
674
|
-
"sdk/invalid-response": "invalid-response",
|
|
675
|
-
"sdk/response-too-large": "invalid-response",
|
|
676
|
-
"sdk/invalid-argument": "invalid-argument",
|
|
677
|
-
"sdk/invalid-config": "configuration",
|
|
678
|
-
"sdk/no-fetch": "configuration",
|
|
679
|
-
"sdk/invalid-webhook-signature": "webhook-verification",
|
|
680
|
-
"sdk/invalid-webhook-payload": "webhook-verification"
|
|
681
|
-
};
|
|
682
|
-
/**
|
|
683
|
-
* The kind of an error with `code` and `status`: the SDK's own codes by code; any other error by
|
|
684
|
-
* its HTTP status when the API answered (`api` for a status without a kind of its own, or a
|
|
685
|
-
* hidden one); and an error the SDK raised before sending, such as `upload/unsupported-type`, as
|
|
686
|
-
* `invalid-argument`.
|
|
687
|
-
*/
|
|
688
|
-
const errorKindOf = (code, status) => {
|
|
689
|
-
const byCode = CODE_KINDS[code];
|
|
690
|
-
if (byCode) return byCode;
|
|
691
|
-
if (status === void 0) return code === "sdk/http-error" ? "api" : "invalid-argument";
|
|
692
|
-
if (status >= 500) return "server";
|
|
693
|
-
return STATUS_KINDS[status] ?? "api";
|
|
694
|
-
};
|
|
695
|
-
/** Whether `kind` is `ancestor` or one of its descendants. */
|
|
696
|
-
const isErrorKind = (kind, ancestor) => {
|
|
697
|
-
for (let current = kind; current; current = KIND_PARENTS[current]) if (current === ancestor) return true;
|
|
698
|
-
return false;
|
|
699
|
-
};
|
|
700
|
-
/** The longest API error body an error keeps. */
|
|
701
|
-
const MAX_ERROR_BODY_LENGTH = 4096;
|
|
702
|
-
const BRAND = Symbol.for("calmlens.sdk.CalmLensError");
|
|
703
|
-
const RETRYABLE_STATUSES$1 = /* @__PURE__ */ new Set([
|
|
704
|
-
429,
|
|
705
|
-
500,
|
|
706
|
-
502,
|
|
707
|
-
503,
|
|
708
|
-
504
|
|
709
|
-
]);
|
|
710
|
-
const RETRYABLE_CODES = /* @__PURE__ */ new Set([
|
|
711
|
-
SDK_ERROR_CODES.TRANSPORT_ERROR,
|
|
712
|
-
SDK_ERROR_CODES.TIMEOUT,
|
|
713
|
-
API_ERROR_CODES.IDEMPOTENT_REQUEST_IN_PROGRESS
|
|
714
|
-
]);
|
|
715
|
-
/**
|
|
716
|
-
* Every failure the SDK reports, whether the API returned an error or the request never
|
|
717
|
-
* completed. Branch on `code`; `status`, `requestId`, `headers` and `retryAfter` describe the
|
|
718
|
-
* HTTP response when there was one, and `cause` holds the underlying error.
|
|
719
|
-
*
|
|
720
|
-
* `instanceof CalmLensError` and `CalmLensError.isCalmLensError(value)` both recognise errors
|
|
721
|
-
* from any copy of the SDK, so they work when ESM and CommonJS builds are loaded side by side.
|
|
722
|
-
*/
|
|
723
|
-
var CalmLensError = class CalmLensError extends Error {
|
|
724
|
-
static {
|
|
725
|
-
this.kind = "error";
|
|
726
|
-
}
|
|
727
|
-
constructor(code, options = {}) {
|
|
728
|
-
const id = typeof code === "string" ? code : code.id;
|
|
729
|
-
const defaultMessage = typeof code === "string" ? void 0 : code.defaultMessage;
|
|
730
|
-
super(`[calmlens] ${options.message ?? defaultMessage ?? id}`, { cause: options.cause });
|
|
731
|
-
const kind = errorKindOf(id, options.status);
|
|
732
|
-
if (new.target === CalmLensError) {
|
|
733
|
-
const KindClass = ERROR_CLASSES[kind];
|
|
734
|
-
if (KindClass !== CalmLensError) return new KindClass(code, options);
|
|
735
|
-
}
|
|
736
|
-
this.name = new.target.name;
|
|
737
|
-
this.kind = kind;
|
|
738
|
-
this.body = options.body?.slice(0, MAX_ERROR_BODY_LENGTH);
|
|
739
|
-
this.code = id;
|
|
740
|
-
this.status = options.status;
|
|
741
|
-
this.details = options.details;
|
|
742
|
-
this.requestId = options.requestId;
|
|
743
|
-
this.headers = options.headers;
|
|
744
|
-
this.retryAfter = options.retryAfter;
|
|
745
|
-
Object.defineProperty(this, BRAND, { value: true });
|
|
746
|
-
}
|
|
747
|
-
/** True for any `CalmLensError`, including one created by another copy or build of the SDK. */
|
|
748
|
-
static isCalmLensError(value) {
|
|
749
|
-
return typeof value === "object" && value !== null && value[BRAND] === true;
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* `error instanceof CalmLensNotFoundError` (or any kind's class) is true for errors of that kind
|
|
753
|
-
* and its descendants, from any copy of the SDK.
|
|
754
|
-
*/
|
|
755
|
-
static [Symbol.hasInstance](value) {
|
|
756
|
-
if (!CalmLensError.isCalmLensError(value)) return false;
|
|
757
|
-
const expected = this.kind;
|
|
758
|
-
if (expected === "error") return true;
|
|
759
|
-
const { kind } = value;
|
|
760
|
-
return kind in KIND_PARENTS && isErrorKind(kind, expected);
|
|
761
|
-
}
|
|
762
|
-
/** Whether this error is of `kind` or a kind beneath it, such as `api` for a `not-found` error. */
|
|
763
|
-
isKind(kind) {
|
|
764
|
-
return isErrorKind(this.kind, kind);
|
|
765
|
-
}
|
|
766
|
-
/**
|
|
767
|
-
* Whether the SDK raised this error itself, with no HTTP response: before sending (an invalid
|
|
768
|
-
* argument or option, or content it checks first, such as `upload/unsupported-type`), or because
|
|
769
|
-
* no response arrived (a timeout, a cancellation or a connection failure). The code is the one
|
|
770
|
-
* the API would use; there is no `status` or `requestId`, so branch on `code`.
|
|
771
|
-
*/
|
|
772
|
-
isLocal() {
|
|
773
|
-
return this.status === void 0;
|
|
774
|
-
}
|
|
775
|
-
/** The resource does not exist or is not visible to this API key. */
|
|
776
|
-
isNotFound() {
|
|
777
|
-
return this.status === 404;
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* Whether repeating the same request may succeed: transport failures, timeouts (a request's
|
|
781
|
-
* `timeoutMs` or `waitForDecision`'s deadline), throttling (429), internal and gateway errors (500, 502, 503, 504)
|
|
782
|
-
* and idempotent requests still in progress. Only repeat a create or upload with the same
|
|
783
|
-
* `idempotencyKey`.
|
|
784
|
-
*/
|
|
785
|
-
isRetryable() {
|
|
786
|
-
return RETRYABLE_CODES.has(this.code) || this.status !== void 0 && RETRYABLE_STATUSES$1.has(this.status);
|
|
787
|
-
}
|
|
788
|
-
};
|
|
789
|
-
const invalidArgument = (message, details) => new CalmLensError(SDK_ERROR_CODES.INVALID_ARGUMENT, {
|
|
790
|
-
message,
|
|
791
|
-
details
|
|
792
|
-
});
|
|
793
|
-
const invalidConfig = (message) => new CalmLensError(SDK_ERROR_CODES.INVALID_CONFIG, { message });
|
|
794
|
-
/** The API, or a proxy in front of it, answered with a non-2xx status. */
|
|
795
|
-
var CalmLensApiError = class extends CalmLensError {
|
|
796
|
-
static {
|
|
797
|
-
this.kind = "api";
|
|
798
|
-
}
|
|
799
|
-
};
|
|
800
|
-
/** HTTP 400: the request was invalid. */
|
|
801
|
-
var CalmLensBadRequestError = class extends CalmLensApiError {
|
|
802
|
-
static {
|
|
803
|
-
this.kind = "bad-request";
|
|
804
|
-
}
|
|
805
|
-
};
|
|
806
|
-
/** HTTP 401: the API key is missing or invalid. */
|
|
807
|
-
var CalmLensAuthenticationError = class extends CalmLensApiError {
|
|
808
|
-
static {
|
|
809
|
-
this.kind = "authentication";
|
|
810
|
-
}
|
|
811
|
-
};
|
|
812
|
-
/** HTTP 403: the API key lacks a grant, or the viewer can't see the asset. */
|
|
813
|
-
var CalmLensPermissionDeniedError = class extends CalmLensApiError {
|
|
814
|
-
static {
|
|
815
|
-
this.kind = "permission-denied";
|
|
816
|
-
}
|
|
817
|
-
};
|
|
818
|
-
/** HTTP 404: the resource doesn't exist or isn't visible to the API key. */
|
|
819
|
-
var CalmLensNotFoundError = class extends CalmLensApiError {
|
|
820
|
-
static {
|
|
821
|
-
this.kind = "not-found";
|
|
822
|
-
}
|
|
823
|
-
};
|
|
824
|
-
/** HTTP 409: the request conflicts with the resource's state, such as a changed revision. */
|
|
825
|
-
var CalmLensConflictError = class extends CalmLensApiError {
|
|
826
|
-
static {
|
|
827
|
-
this.kind = "conflict";
|
|
828
|
-
}
|
|
829
|
-
};
|
|
830
|
-
/** HTTP 413: the content is over a size limit. */
|
|
831
|
-
var CalmLensPayloadTooLargeError = class extends CalmLensApiError {
|
|
832
|
-
static {
|
|
833
|
-
this.kind = "payload-too-large";
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
/** HTTP 422: the content can't be processed. */
|
|
837
|
-
var CalmLensUnprocessableEntityError = class extends CalmLensApiError {
|
|
838
|
-
static {
|
|
839
|
-
this.kind = "unprocessable-entity";
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
/** HTTP 429: too many requests; `retryAfter` says how long to wait. */
|
|
843
|
-
var CalmLensRateLimitError = class extends CalmLensApiError {
|
|
844
|
-
static {
|
|
845
|
-
this.kind = "rate-limit";
|
|
846
|
-
}
|
|
847
|
-
};
|
|
848
|
-
/** HTTP 500 or above: the API failed. */
|
|
849
|
-
var CalmLensServerError = class extends CalmLensApiError {
|
|
850
|
-
static {
|
|
851
|
-
this.kind = "server";
|
|
852
|
-
}
|
|
853
|
-
};
|
|
854
|
-
/** No complete response: the connection failed or was cut (`sdk/transport-error`). */
|
|
855
|
-
var CalmLensConnectionError = class extends CalmLensError {
|
|
856
|
-
static {
|
|
857
|
-
this.kind = "connection";
|
|
858
|
-
}
|
|
859
|
-
};
|
|
860
|
-
/** A request took longer than its timeout, or a wait reached its deadline (`sdk/timeout`). */
|
|
861
|
-
var CalmLensTimeoutError = class extends CalmLensError {
|
|
862
|
-
static {
|
|
863
|
-
this.kind = "timeout";
|
|
864
|
-
}
|
|
865
|
-
};
|
|
866
|
-
/** The caller cancelled the call through a signal (`sdk/cancelled`). */
|
|
867
|
-
var CalmLensCancelledError = class extends CalmLensError {
|
|
868
|
-
static {
|
|
869
|
-
this.kind = "cancelled";
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
/** The SDK refused the call before sending anything. */
|
|
873
|
-
var CalmLensInvalidArgumentError = class extends CalmLensError {
|
|
874
|
-
static {
|
|
875
|
-
this.kind = "invalid-argument";
|
|
876
|
-
}
|
|
877
|
-
};
|
|
878
|
-
/** The client's configuration is invalid (`sdk/invalid-config`, `sdk/no-fetch`). */
|
|
879
|
-
var CalmLensConfigurationError = class extends CalmLensInvalidArgumentError {
|
|
880
|
-
static {
|
|
881
|
-
this.kind = "configuration";
|
|
882
|
-
}
|
|
883
|
-
};
|
|
884
|
-
/** A response wasn't what the operation returns (`sdk/invalid-response`, `sdk/response-too-large`). */
|
|
885
|
-
var CalmLensInvalidResponseError = class extends CalmLensError {
|
|
886
|
-
static {
|
|
887
|
-
this.kind = "invalid-response";
|
|
888
|
-
}
|
|
889
|
-
};
|
|
890
|
-
/** A webhook delivery couldn't be verified or parsed. */
|
|
891
|
-
var CalmLensWebhookVerificationError = class extends CalmLensError {
|
|
892
|
-
static {
|
|
893
|
-
this.kind = "webhook-verification";
|
|
894
|
-
}
|
|
895
|
-
};
|
|
896
|
-
/** Each kind's class. */
|
|
897
|
-
const ERROR_CLASSES = {
|
|
898
|
-
error: CalmLensError,
|
|
899
|
-
api: CalmLensApiError,
|
|
900
|
-
"bad-request": CalmLensBadRequestError,
|
|
901
|
-
authentication: CalmLensAuthenticationError,
|
|
902
|
-
"permission-denied": CalmLensPermissionDeniedError,
|
|
903
|
-
"not-found": CalmLensNotFoundError,
|
|
904
|
-
conflict: CalmLensConflictError,
|
|
905
|
-
"payload-too-large": CalmLensPayloadTooLargeError,
|
|
906
|
-
"unprocessable-entity": CalmLensUnprocessableEntityError,
|
|
907
|
-
"rate-limit": CalmLensRateLimitError,
|
|
908
|
-
server: CalmLensServerError,
|
|
909
|
-
connection: CalmLensConnectionError,
|
|
910
|
-
timeout: CalmLensTimeoutError,
|
|
911
|
-
cancelled: CalmLensCancelledError,
|
|
912
|
-
"invalid-argument": CalmLensInvalidArgumentError,
|
|
913
|
-
configuration: CalmLensConfigurationError,
|
|
914
|
-
"invalid-response": CalmLensInvalidResponseError,
|
|
915
|
-
"webhook-verification": CalmLensWebhookVerificationError
|
|
916
|
-
};
|
|
1
|
+
const require_CalmLensError = require("./CalmLensError-DPHJaVjX.js");
|
|
917
2
|
// src/client/CalmLensLogging.ts
|
|
918
3
|
const LOG_LEVELS = [
|
|
919
4
|
"off",
|
|
@@ -936,7 +21,7 @@ const readEnv = (name) => {
|
|
|
936
21
|
/** The log level: the option, else `CALMLENS_LOG` from the environment, else `off`. */
|
|
937
22
|
const resolveLogLevel = (option, fromEnv) => {
|
|
938
23
|
if (option !== void 0) {
|
|
939
|
-
if (!LOG_LEVELS.includes(option)) throw invalidConfig(`logLevel must be one of ${LOG_LEVELS.join(", ")}`);
|
|
24
|
+
if (!LOG_LEVELS.includes(option)) throw require_CalmLensError.invalidConfig(`logLevel must be one of ${LOG_LEVELS.join(", ")}`);
|
|
940
25
|
return option;
|
|
941
26
|
}
|
|
942
27
|
const env = fromEnv ? readEnv("CALMLENS_LOG")?.toLowerCase() : void 0;
|
|
@@ -981,7 +66,7 @@ const AUTO_PAGING_TO_ARRAY_MAX = 1e4;
|
|
|
981
66
|
* iteration has already sent, which would repeat the same pages forever.
|
|
982
67
|
*/
|
|
983
68
|
const assertNewCursor = (sent, cursor) => {
|
|
984
|
-
if (sent.has(cursor)) throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
69
|
+
if (sent.has(cursor)) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
985
70
|
message: "The API returned a cursor it had already returned, with more pages to follow",
|
|
986
71
|
details: { cursor }
|
|
987
72
|
});
|
|
@@ -1006,7 +91,7 @@ const autoPaging = (first) => {
|
|
|
1006
91
|
[Symbol.asyncIterator]: () => items(),
|
|
1007
92
|
async autoPagingToArray(options) {
|
|
1008
93
|
const limit = options?.limit;
|
|
1009
|
-
if (!Number.isInteger(limit) || limit < 1 || limit > 1e4) throw invalidArgument(`autoPagingToArray needs a limit from 1 to ${AUTO_PAGING_TO_ARRAY_MAX}; iterate with for await for more`);
|
|
94
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 1e4) throw require_CalmLensError.invalidArgument(`autoPagingToArray needs a limit from 1 to ${AUTO_PAGING_TO_ARRAY_MAX}; iterate with for await for more`);
|
|
1010
95
|
const collected = [];
|
|
1011
96
|
for await (const item of items()) {
|
|
1012
97
|
collected.push(item);
|
|
@@ -1017,7 +102,7 @@ const autoPaging = (first) => {
|
|
|
1017
102
|
};
|
|
1018
103
|
};
|
|
1019
104
|
const toListPage = (data, source, cursor) => {
|
|
1020
|
-
if (!data || typeof data !== "object" || !Array.isArray(data.items)) throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, { message: "The API returned a list without items" });
|
|
105
|
+
if (!data || typeof data !== "object" || !Array.isArray(data.items)) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, { message: "The API returned a list without items" });
|
|
1021
106
|
const hasNextPage = () => data.hasMore === true && typeof data.nextCursor === "string" && data.nextCursor !== "" && (source.feed || data.items.length > 0);
|
|
1022
107
|
const page = data;
|
|
1023
108
|
if (cursor !== void 0) requestCursors.set(page, cursor);
|
|
@@ -1032,7 +117,7 @@ const toListPage = (data, source, cursor) => {
|
|
|
1032
117
|
value: () => {
|
|
1033
118
|
const next = data.nextCursor ?? void 0;
|
|
1034
119
|
return list(async () => {
|
|
1035
|
-
if (!hasNextPage()) throw invalidArgument("There is no next page; check hasNextPage() first");
|
|
120
|
+
if (!hasNextPage()) throw require_CalmLensError.invalidArgument("There is no next page; check hasNextPage() first");
|
|
1036
121
|
if (next !== void 0 && next === cursor) assertNewCursor(/* @__PURE__ */ new Set([next]), next);
|
|
1037
122
|
return toListPage(await source.fetchPage(next), source, next);
|
|
1038
123
|
});
|
|
@@ -1067,7 +152,7 @@ const listPages = (fetchPage, { cursor, feed = false } = {}) => {
|
|
|
1067
152
|
};
|
|
1068
153
|
// src/client/CalmLensVersion.ts
|
|
1069
154
|
/** This SDK's version, from its package.json. */
|
|
1070
|
-
const SDK_VERSION = "0.29.
|
|
155
|
+
const SDK_VERSION = "0.29.2";
|
|
1071
156
|
const runtimeName = () => {
|
|
1072
157
|
const runtime = globalThis;
|
|
1073
158
|
if (isReactNativeRuntime()) return "react-native";
|
|
@@ -1148,28 +233,28 @@ const createAttemptSignal = (signals, timeoutMs) => {
|
|
|
1148
233
|
const isRedirect = (response) => response.type === "opaqueredirect" || response.status >= 300 && response.status < 400 && response.headers.has("location");
|
|
1149
234
|
/** Turns anything thrown while sending or reading a request into a `CalmLensError`. */
|
|
1150
235
|
const toFailure = (cause, attempt) => {
|
|
1151
|
-
if (CalmLensError.isCalmLensError(cause)) return cause;
|
|
1152
|
-
if (attempt.isCancelled()) return new CalmLensError(SDK_ERROR_CODES.CANCELLED, {
|
|
236
|
+
if (require_CalmLensError.CalmLensError.isCalmLensError(cause)) return cause;
|
|
237
|
+
if (attempt.isCancelled()) return new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.CANCELLED, {
|
|
1153
238
|
message: "Request cancelled",
|
|
1154
239
|
cause
|
|
1155
240
|
});
|
|
1156
|
-
if (attempt.isTimedOut()) return new CalmLensError(SDK_ERROR_CODES.TIMEOUT, {
|
|
241
|
+
if (attempt.isTimedOut()) return new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.TIMEOUT, {
|
|
1157
242
|
message: "Request timed out",
|
|
1158
243
|
cause
|
|
1159
244
|
});
|
|
1160
|
-
return new CalmLensError(SDK_ERROR_CODES.TRANSPORT_ERROR, {
|
|
245
|
+
return new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.TRANSPORT_ERROR, {
|
|
1161
246
|
message: "Request failed",
|
|
1162
247
|
cause
|
|
1163
248
|
});
|
|
1164
249
|
};
|
|
1165
250
|
const sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
1166
251
|
if (signal?.aborted) {
|
|
1167
|
-
reject(new CalmLensError(SDK_ERROR_CODES.CANCELLED, { message: "Request cancelled" }));
|
|
252
|
+
reject(new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.CANCELLED, { message: "Request cancelled" }));
|
|
1168
253
|
return;
|
|
1169
254
|
}
|
|
1170
255
|
const onAbort = () => {
|
|
1171
256
|
clearTimeout(timer);
|
|
1172
|
-
reject(new CalmLensError(SDK_ERROR_CODES.CANCELLED, { message: "Request cancelled" }));
|
|
257
|
+
reject(new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.CANCELLED, { message: "Request cancelled" }));
|
|
1173
258
|
};
|
|
1174
259
|
const timer = setTimeout(() => {
|
|
1175
260
|
signal?.removeEventListener("abort", onAbort);
|
|
@@ -1197,7 +282,7 @@ const isApiErrorPayload = (value) => !!value && typeof value === "object" && typ
|
|
|
1197
282
|
/** Reads at most `limit` bytes of a body, failing with `sdk/response-too-large` beyond that. */
|
|
1198
283
|
const readBody = async (response, limit) => {
|
|
1199
284
|
const declared = Number(response.headers.get("content-length"));
|
|
1200
|
-
const tooLarge = () => new CalmLensError(SDK_ERROR_CODES.RESPONSE_TOO_LARGE, {
|
|
285
|
+
const tooLarge = () => new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.RESPONSE_TOO_LARGE, {
|
|
1201
286
|
message: `Response body exceeds ${limit} bytes`,
|
|
1202
287
|
status: response.status,
|
|
1203
288
|
requestId: response.headers.get("x-request-id") ?? void 0,
|
|
@@ -1237,7 +322,7 @@ const responseInfo = (response) => ({
|
|
|
1237
322
|
});
|
|
1238
323
|
/** The `CalmLensError` for a non-2xx response whose body has been read. */
|
|
1239
324
|
const toHttpError = (response, bytes) => {
|
|
1240
|
-
const body = new TextDecoder().decode(bytes.subarray(0, MAX_ERROR_BODY_LENGTH * 4)).slice(0, MAX_ERROR_BODY_LENGTH);
|
|
325
|
+
const body = new TextDecoder().decode(bytes.subarray(0, require_CalmLensError.MAX_ERROR_BODY_LENGTH * 4)).slice(0, require_CalmLensError.MAX_ERROR_BODY_LENGTH);
|
|
1241
326
|
let data;
|
|
1242
327
|
try {
|
|
1243
328
|
data = JSON.parse(new TextDecoder().decode(bytes));
|
|
@@ -1245,7 +330,7 @@ const toHttpError = (response, bytes) => {
|
|
|
1245
330
|
if (isApiErrorPayload(data)) {
|
|
1246
331
|
const { code, message, details, requestId } = data;
|
|
1247
332
|
const info = responseInfo(response);
|
|
1248
|
-
return new CalmLensError(code, {
|
|
333
|
+
return new require_CalmLensError.CalmLensError(code, {
|
|
1249
334
|
message: message ?? code,
|
|
1250
335
|
...info,
|
|
1251
336
|
requestId: info.requestId ?? (typeof requestId === "string" ? requestId : void 0),
|
|
@@ -1253,7 +338,7 @@ const toHttpError = (response, bytes) => {
|
|
|
1253
338
|
body
|
|
1254
339
|
});
|
|
1255
340
|
}
|
|
1256
|
-
return new CalmLensError(SDK_ERROR_CODES.HTTP_ERROR, {
|
|
341
|
+
return new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.HTTP_ERROR, {
|
|
1257
342
|
message: `HTTP ${response.status}`,
|
|
1258
343
|
...responseInfo(response),
|
|
1259
344
|
body
|
|
@@ -1331,7 +416,7 @@ var CalmLensTransport = class {
|
|
|
1331
416
|
for (let attemptNumber = 0;; attemptNumber++) {
|
|
1332
417
|
const canRetryAgain = retryable && attemptNumber < this.maxRetriesFor(request);
|
|
1333
418
|
const remainingMs = deadlineAt === void 0 ? void 0 : deadlineAt - now();
|
|
1334
|
-
if (remainingMs !== void 0 && remainingMs <= 0) throw new CalmLensError(SDK_ERROR_CODES.TIMEOUT, { message: "The call's deadline passed" });
|
|
419
|
+
if (remainingMs !== void 0 && remainingMs <= 0) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.TIMEOUT, { message: "The call's deadline passed" });
|
|
1335
420
|
const attempt = createAttemptSignal(this.signalsFor(request), remainingMs === void 0 ? request.timeoutMs : Math.min(request.timeoutMs ?? remainingMs, remainingMs));
|
|
1336
421
|
const started = now();
|
|
1337
422
|
const report = (outcome, delayMs) => this.report({
|
|
@@ -1359,7 +444,7 @@ var CalmLensTransport = class {
|
|
|
1359
444
|
});
|
|
1360
445
|
if (isRedirect(response)) {
|
|
1361
446
|
await response.body?.cancel().catch(() => {});
|
|
1362
|
-
throw new CalmLensError(SDK_ERROR_CODES.HTTP_ERROR, {
|
|
447
|
+
throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.HTTP_ERROR, {
|
|
1363
448
|
message: `Unexpected redirect (HTTP ${response.status})`,
|
|
1364
449
|
...responseInfo(response),
|
|
1365
450
|
status: response.status || void 0
|
|
@@ -1432,7 +517,7 @@ var CalmLensTransport = class {
|
|
|
1432
517
|
try {
|
|
1433
518
|
data = JSON.parse(new TextDecoder().decode(bytes));
|
|
1434
519
|
} catch (cause) {
|
|
1435
|
-
throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
520
|
+
throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
1436
521
|
message: `Invalid JSON response (HTTP ${response.status})`,
|
|
1437
522
|
...responseInfo(response),
|
|
1438
523
|
cause
|
|
@@ -1846,55 +931,55 @@ const assertHttpUrl = (name, value) => {
|
|
|
1846
931
|
try {
|
|
1847
932
|
url = new URL(value);
|
|
1848
933
|
} catch {}
|
|
1849
|
-
if (!url || url.protocol !== "https:" && url.protocol !== "http:") throw invalidConfig(`${name} must be an absolute http(s) URL`);
|
|
934
|
+
if (!url || url.protocol !== "https:" && url.protocol !== "http:") throw require_CalmLensError.invalidConfig(`${name} must be an absolute http(s) URL`);
|
|
1850
935
|
};
|
|
1851
936
|
const assertInteger = (name, value, minimum) => {
|
|
1852
|
-
if (value !== void 0 && (!Number.isSafeInteger(value) || value < minimum)) throw invalidConfig(minimum === 0 ? `${name} must be a non-negative integer` : `${name} must be a positive integer`);
|
|
937
|
+
if (value !== void 0 && (!Number.isSafeInteger(value) || value < minimum)) throw require_CalmLensError.invalidConfig(minimum === 0 ? `${name} must be a non-negative integer` : `${name} must be a positive integer`);
|
|
1853
938
|
};
|
|
1854
939
|
const configPathSegment = (value, name) => {
|
|
1855
940
|
try {
|
|
1856
941
|
encodePathSegment(value, name);
|
|
1857
942
|
} catch (error) {
|
|
1858
|
-
throw invalidConfig(error.message.replace(/^\[calmlens\] /, ""));
|
|
943
|
+
throw require_CalmLensError.invalidConfig(error.message.replace(/^\[calmlens\] /, ""));
|
|
1859
944
|
}
|
|
1860
945
|
};
|
|
1861
946
|
/** Checks the options both clients share: where requests go and how they're sent. */
|
|
1862
947
|
const validateConnectionOptions = (options) => {
|
|
1863
|
-
if ("requestBackend" in options) throw invalidConfig("requestBackend is no longer supported; pass a fetch implementation as fetch");
|
|
948
|
+
if ("requestBackend" in options) throw require_CalmLensError.invalidConfig("requestBackend is no longer supported; pass a fetch implementation as fetch");
|
|
1864
949
|
validateRequestOptions(options);
|
|
1865
950
|
assertInteger("maxResponseBytes", options.maxResponseBytes, 1);
|
|
1866
951
|
const { partSizeBytes } = options;
|
|
1867
|
-
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)");
|
|
1868
|
-
for (const name of ["fetch", "uploadFetch"]) if (options[name] !== void 0 && typeof options[name] !== "function") throw invalidConfig(`${name} must be a function`);
|
|
952
|
+
if (partSizeBytes !== void 0 && (!Number.isSafeInteger(partSizeBytes) || partSizeBytes < 5242880 || partSizeBytes > 67108864)) throw require_CalmLensError.invalidConfig("partSizeBytes must be an integer from 5 MiB (5242880) to 64 MiB (67108864)");
|
|
953
|
+
for (const name of ["fetch", "uploadFetch"]) if (options[name] !== void 0 && typeof options[name] !== "function") throw require_CalmLensError.invalidConfig(`${name} must be a function`);
|
|
1869
954
|
assertHttpUrl("baseUrl", options.baseUrl);
|
|
1870
955
|
const { appInfo, onAttempt, logger } = options;
|
|
1871
|
-
if (appInfo !== void 0 && (!appInfo || typeof appInfo.name !== "string" || !/^[\x21-\x7e]+$/.test(appInfo.name) || appInfo.version !== void 0 && !/^[\x21-\x7e]+$/.test(String(appInfo.version)) || appInfo.url !== void 0 && !/^[\x20-\x7e]+$/.test(String(appInfo.url)))) throw invalidConfig("appInfo needs a name, and a version, without spaces, and a url, in printable ASCII");
|
|
1872
|
-
if (onAttempt !== void 0 && typeof onAttempt !== "function") throw invalidConfig("onAttempt must be a function");
|
|
1873
|
-
if (logger !== void 0 && (!logger || typeof logger.debug !== "function" || typeof logger.info !== "function")) throw invalidConfig("logger must have debug and info methods, as console does");
|
|
956
|
+
if (appInfo !== void 0 && (!appInfo || typeof appInfo.name !== "string" || !/^[\x21-\x7e]+$/.test(appInfo.name) || appInfo.version !== void 0 && !/^[\x21-\x7e]+$/.test(String(appInfo.version)) || appInfo.url !== void 0 && !/^[\x20-\x7e]+$/.test(String(appInfo.url)))) throw require_CalmLensError.invalidConfig("appInfo needs a name, and a version, without spaces, and a url, in printable ASCII");
|
|
957
|
+
if (onAttempt !== void 0 && typeof onAttempt !== "function") throw require_CalmLensError.invalidConfig("onAttempt must be a function");
|
|
958
|
+
if (logger !== void 0 && (!logger || typeof logger.debug !== "function" || typeof logger.info !== "function")) throw require_CalmLensError.invalidConfig("logger must have debug and info methods, as console does");
|
|
1874
959
|
};
|
|
1875
960
|
/**
|
|
1876
961
|
* Checks server client options before the client sets anything up. `CalmLensServerClient` and
|
|
1877
962
|
* `MockCalmLensServerClient` share it so both reject the same configuration.
|
|
1878
963
|
*/
|
|
1879
964
|
const validateServerClientOptions = (options) => {
|
|
1880
|
-
if (!options || typeof options !== "object") throw invalidConfig("Client options are required");
|
|
1881
|
-
if (!options.apiKey || typeof options.apiKey !== "string") throw invalidConfig("API key is required");
|
|
1882
|
-
if (!/^[\x21-\x7e]+$/.test(options.apiKey)) throw invalidConfig("API key must be printable ASCII without spaces");
|
|
1883
|
-
if (!options.projectId) throw invalidConfig("Project ID is required");
|
|
965
|
+
if (!options || typeof options !== "object") throw require_CalmLensError.invalidConfig("Client options are required");
|
|
966
|
+
if (!options.apiKey || typeof options.apiKey !== "string") throw require_CalmLensError.invalidConfig("API key is required");
|
|
967
|
+
if (!/^[\x21-\x7e]+$/.test(options.apiKey)) throw require_CalmLensError.invalidConfig("API key must be printable ASCII without spaces");
|
|
968
|
+
if (!options.projectId) throw require_CalmLensError.invalidConfig("Project ID is required");
|
|
1884
969
|
configPathSegment(options.projectId, "Project ID");
|
|
1885
970
|
validateConnectionOptions(options);
|
|
1886
|
-
if (options.cdnFetch !== void 0 && typeof options.cdnFetch !== "function") throw invalidConfig("cdnFetch must be a function");
|
|
971
|
+
if (options.cdnFetch !== void 0 && typeof options.cdnFetch !== "function") throw require_CalmLensError.invalidConfig("cdnFetch must be a function");
|
|
1887
972
|
assertHttpUrl("cdnBaseUrl", options.cdnBaseUrl);
|
|
1888
973
|
};
|
|
1889
974
|
/** Checks app client options before the client sets anything up. */
|
|
1890
975
|
const validateAppClientOptions = (options) => {
|
|
1891
|
-
if (!options || typeof options !== "object") throw invalidConfig("Client options are required");
|
|
1892
|
-
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.");
|
|
1893
|
-
if (!options.uploadPresetId) throw invalidConfig("Upload preset ID is required");
|
|
976
|
+
if (!options || typeof options !== "object") throw require_CalmLensError.invalidConfig("Client options are required");
|
|
977
|
+
if ("apiKey" in options && options.apiKey !== void 0) throw require_CalmLensError.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.");
|
|
978
|
+
if (!options.uploadPresetId) throw require_CalmLensError.invalidConfig("Upload preset ID is required");
|
|
1894
979
|
configPathSegment(options.uploadPresetId, "Upload preset ID");
|
|
1895
980
|
if (options.projectId !== void 0) configPathSegment(options.projectId, "Project ID");
|
|
1896
981
|
assertHttpUrl("cdnBaseUrl", options.cdnBaseUrl);
|
|
1897
|
-
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");
|
|
982
|
+
if (options.token !== void 0 && typeof options.token !== "string" && typeof options.token !== "function") throw require_CalmLensError.invalidConfig("token must be a string or a function that returns one");
|
|
1898
983
|
validateConnectionOptions(options);
|
|
1899
984
|
};
|
|
1900
985
|
/** Checks a client's request defaults. */
|
|
@@ -1948,13 +1033,13 @@ const checkOptionKeys = (options, operation, apiKeys) => {
|
|
|
1948
1033
|
const allowed = LOCAL_OPTION_KEYS[operation] ?? apiKeys[operation];
|
|
1949
1034
|
if (!allowed) throw new Error(`No option keys for ${operation}`);
|
|
1950
1035
|
const unknown = Object.keys(options).filter((key) => !allowed.includes(key) && !(key === "idempotencyKey" && IDEMPOTENT_OPERATIONS.includes(operation)));
|
|
1951
|
-
if (unknown.length) throw invalidArgument(`Unknown option${unknown.length > 1 ? "s" : ""} for ${operation}: ${unknown.join(", ")}`, {
|
|
1036
|
+
if (unknown.length) throw require_CalmLensError.invalidArgument(`Unknown option${unknown.length > 1 ? "s" : ""} for ${operation}: ${unknown.join(", ")}`, {
|
|
1952
1037
|
operation,
|
|
1953
1038
|
options: unknown
|
|
1954
1039
|
});
|
|
1955
1040
|
};
|
|
1956
1041
|
const toTextAssetOptions = ({ text, name, ...options }) => {
|
|
1957
|
-
if (typeof text !== "string" || !text.trim()) throw invalidArgument("Text to classify must be a non-empty string");
|
|
1042
|
+
if (typeof text !== "string" || !text.trim()) throw require_CalmLensError.invalidArgument("Text to classify must be a non-empty string");
|
|
1958
1043
|
return {
|
|
1959
1044
|
...options,
|
|
1960
1045
|
name: name ?? "text",
|
|
@@ -1985,8 +1070,8 @@ const randomUuid = () => {
|
|
|
1985
1070
|
* resolution would treat them as relative segments and send the request to another route.
|
|
1986
1071
|
*/
|
|
1987
1072
|
const encodePathSegment = (value, name) => {
|
|
1988
|
-
if (typeof value !== "string" || !value) throw invalidArgument(`${name} is required`);
|
|
1989
|
-
if (value === "." || value === "..") throw invalidArgument(`${name} cannot be "." or ".."`);
|
|
1073
|
+
if (typeof value !== "string" || !value) throw require_CalmLensError.invalidArgument(`${name} is required`);
|
|
1074
|
+
if (value === "." || value === "..") throw require_CalmLensError.invalidArgument(`${name} cannot be "." or ".."`);
|
|
1990
1075
|
return encodeURIComponent(value);
|
|
1991
1076
|
};
|
|
1992
1077
|
/**
|
|
@@ -2013,7 +1098,7 @@ const appendTransformOptions = (pairs, key, value) => {
|
|
|
2013
1098
|
if (value === void 0 || value === null) return;
|
|
2014
1099
|
if (isPlainObject(value)) {
|
|
2015
1100
|
for (const child of Object.keys(value).sort()) {
|
|
2016
|
-
if (!TRANSFORM_OPTION_NAME.test(child)) throw invalidArgument(`Transform option "${key}.${child}" is not a valid name`);
|
|
1101
|
+
if (!TRANSFORM_OPTION_NAME.test(child)) throw require_CalmLensError.invalidArgument(`Transform option "${key}.${child}" is not a valid name`);
|
|
2017
1102
|
appendTransformOptions(pairs, `${key}.${child}`, value[child]);
|
|
2018
1103
|
}
|
|
2019
1104
|
return;
|
|
@@ -2024,7 +1109,7 @@ const appendTransformOptions = (pairs, key, value) => {
|
|
|
2024
1109
|
text = hex ? hex[1].toLowerCase() : value;
|
|
2025
1110
|
} else if (typeof value === "boolean") text = String(value);
|
|
2026
1111
|
else if (typeof value === "number" && Number.isFinite(value)) text = String(value);
|
|
2027
|
-
else throw invalidArgument(`Transform option "${key}" must be a string, number, boolean or object`);
|
|
1112
|
+
else throw require_CalmLensError.invalidArgument(`Transform option "${key}" must be a string, number, boolean or object`);
|
|
2028
1113
|
pairs.push(`${key}=${encodeTransformComponent(text)}`);
|
|
2029
1114
|
};
|
|
2030
1115
|
const hasRuleType = (type, value) => {
|
|
@@ -2126,7 +1211,7 @@ const assertTransformOptions = (options) => {
|
|
|
2126
1211
|
const { unknownKeys, invalidKeys } = checkTransformOptions(options);
|
|
2127
1212
|
if (!unknownKeys.length && !invalidKeys.length) return;
|
|
2128
1213
|
const problems = [...unknownKeys.length ? [`unknown option${unknownKeys.length > 1 ? "s" : ""} ${unknownKeys.join(", ")}`] : [], ...invalidKeys.length ? [`invalid value${invalidKeys.length > 1 ? "s" : ""} for ${invalidKeys.join(", ")}`] : []];
|
|
2129
|
-
throw invalidArgument(`Transform options are invalid: ${problems.join("; ")}. Pass the options themselves, such as { width: 640, format: "webp" }.`, {
|
|
1214
|
+
throw require_CalmLensError.invalidArgument(`Transform options are invalid: ${problems.join("; ")}. Pass the options themselves, such as { width: 640, format: "webp" }.`, {
|
|
2130
1215
|
unknownKeys,
|
|
2131
1216
|
invalidKeys
|
|
2132
1217
|
});
|
|
@@ -2137,20 +1222,20 @@ const assertTransformOptions = (options) => {
|
|
|
2137
1222
|
* colours are hex without `#`, and values are percent-encoded.
|
|
2138
1223
|
*/
|
|
2139
1224
|
const serializeTransform = (transform) => {
|
|
2140
|
-
if (!isPlainObject(transform)) throw invalidArgument("Transform options must be an object");
|
|
1225
|
+
if (!isPlainObject(transform)) throw require_CalmLensError.invalidArgument("Transform options must be an object");
|
|
2141
1226
|
assertTransformOptions(transform);
|
|
2142
1227
|
const pairs = [];
|
|
2143
1228
|
for (const key of Object.keys(transform).sort()) {
|
|
2144
|
-
if (!TRANSFORM_OPTION_NAME.test(key)) throw invalidArgument(`Transform option "${key}" is not a valid name`);
|
|
1229
|
+
if (!TRANSFORM_OPTION_NAME.test(key)) throw require_CalmLensError.invalidArgument(`Transform option "${key}" is not a valid name`);
|
|
2145
1230
|
appendTransformOptions(pairs, key, transform[key]);
|
|
2146
1231
|
}
|
|
2147
|
-
if (pairs.length === 0) throw invalidArgument("A transform needs at least one option");
|
|
1232
|
+
if (pairs.length === 0) throw require_CalmLensError.invalidArgument("A transform needs at least one option");
|
|
2148
1233
|
return pairs.join(",");
|
|
2149
1234
|
};
|
|
2150
1235
|
/** Returns the selector string the API and CDN accept for a string or structured transform. */
|
|
2151
1236
|
const transformSelector = (transform) => {
|
|
2152
1237
|
if (transform === void 0 || typeof transform !== "string") return transform === void 0 ? void 0 : serializeTransform(transform);
|
|
2153
|
-
if (/[/?#]/.test(transform) || transform.includes("..") || transform.startsWith("@")) throw invalidArgument("Transform cannot contain \"/\", \"..\", \"?\" or \"#\", or start with \"@\"");
|
|
1238
|
+
if (/[/?#]/.test(transform) || transform.includes("..") || transform.startsWith("@")) throw require_CalmLensError.invalidArgument("Transform cannot contain \"/\", \"..\", \"?\" or \"#\", or start with \"@\"");
|
|
2154
1239
|
return transform;
|
|
2155
1240
|
};
|
|
2156
1241
|
const DEFAULT_CDN_BASE_URL = `https://cdn.${DOMAIN}/v1`;
|
|
@@ -2158,9 +1243,9 @@ const DEFAULT_CDN_BASE_URL = `https://cdn.${DOMAIN}/v1`;
|
|
|
2158
1243
|
const ASSET_BATCH_OPERATIONS = ["delete", "remove-content"];
|
|
2159
1244
|
/** Refuses a batch the API would reject for its size, an ID or the operation. */
|
|
2160
1245
|
const validateBatchAssetsOptions = ({ assetIds, operation }) => {
|
|
2161
|
-
if (!Array.isArray(assetIds) || assetIds.length < 1 || assetIds.length > 500) throw invalidArgument(`assetIds must list 1 to 500 asset IDs`);
|
|
2162
|
-
if (assetIds.some((assetId) => typeof assetId !== "string" || !assetId)) throw invalidArgument("Every asset ID must be a non-empty string");
|
|
2163
|
-
if (!ASSET_BATCH_OPERATIONS.includes(operation)) throw invalidArgument(`operation must be one of ${ASSET_BATCH_OPERATIONS.join(", ")}`);
|
|
1246
|
+
if (!Array.isArray(assetIds) || assetIds.length < 1 || assetIds.length > 500) throw require_CalmLensError.invalidArgument(`assetIds must list 1 to 500 asset IDs`);
|
|
1247
|
+
if (assetIds.some((assetId) => typeof assetId !== "string" || !assetId)) throw require_CalmLensError.invalidArgument("Every asset ID must be a non-empty string");
|
|
1248
|
+
if (!ASSET_BATCH_OPERATIONS.includes(operation)) throw require_CalmLensError.invalidArgument(`operation must be one of ${ASSET_BATCH_OPERATIONS.join(", ")}`);
|
|
2164
1249
|
};
|
|
2165
1250
|
/**
|
|
2166
1251
|
* Serialises a query object the way the API reads it: plain values as text, lists of IDs and enum
|
|
@@ -2186,17 +1271,17 @@ const DEFAULT_DECISION_TIMEOUT_MS = 6e4;
|
|
|
2186
1271
|
* without one, or the call's `deadlineAt`, whichever comes first.
|
|
2187
1272
|
*/
|
|
2188
1273
|
const pollForDecision = async (retrieve, { timeoutMs = DEFAULT_DECISION_TIMEOUT_MS, signal, deadlineAt }, sleep, now = Date.now) => {
|
|
2189
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) throw invalidArgument("timeoutMs must be a non-negative number");
|
|
1274
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) throw require_CalmLensError.invalidArgument("timeoutMs must be a non-negative number");
|
|
2190
1275
|
const started = now();
|
|
2191
1276
|
const deadline = started + timeoutMs;
|
|
2192
1277
|
let delay = 500;
|
|
2193
1278
|
for (;;) {
|
|
2194
|
-
if (signal?.aborted) throw new CalmLensError(SDK_ERROR_CODES.CANCELLED, { message: "Request cancelled" });
|
|
1279
|
+
if (signal?.aborted) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.CANCELLED, { message: "Request cancelled" });
|
|
2195
1280
|
const asset = await retrieve();
|
|
2196
1281
|
if (isAssetDecided(asset)) return asset;
|
|
2197
1282
|
const remaining = deadline - now();
|
|
2198
1283
|
const wait = Math.min(delay, remaining);
|
|
2199
|
-
if (remaining <= 0 || deadlineAt !== void 0 && now() + wait >= deadlineAt) throw new CalmLensError(SDK_ERROR_CODES.TIMEOUT, {
|
|
1284
|
+
if (remaining <= 0 || deadlineAt !== void 0 && now() + wait >= deadlineAt) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.TIMEOUT, {
|
|
2200
1285
|
message: `Asset ${asset.id} had no moderation decision after ${now() - started}ms (classification status: ${asset.classification.status}, moderation decision: ${asset.classification.moderation.decision})`,
|
|
2201
1286
|
details: {
|
|
2202
1287
|
assetId: asset.id,
|
|
@@ -2256,9 +1341,9 @@ const MAX_SIGNED_URL_EXPIRES_IN = 86400;
|
|
|
2256
1341
|
*/
|
|
2257
1342
|
const getAssetSegment = (options) => {
|
|
2258
1343
|
const { assetId, externalId } = options;
|
|
2259
|
-
if (assetId === void 0 === (externalId === void 0)) throw invalidArgument("Pass either assetId or externalId");
|
|
1344
|
+
if (assetId === void 0 === (externalId === void 0)) throw require_CalmLensError.invalidArgument("Pass either assetId or externalId");
|
|
2260
1345
|
if (assetId !== void 0) return encodePathSegment(assetId, "Asset ID");
|
|
2261
|
-
if (typeof externalId !== "string" || !externalId) throw invalidArgument("External ID is required");
|
|
1346
|
+
if (typeof externalId !== "string" || !externalId) throw require_CalmLensError.invalidArgument("External ID is required");
|
|
2262
1347
|
return `${EXTERNAL_ID_SEGMENT_PREFIX}${encodeURIComponent(externalId)}`;
|
|
2263
1348
|
};
|
|
2264
1349
|
/**
|
|
@@ -2268,7 +1353,7 @@ const getAssetSegment = (options) => {
|
|
|
2268
1353
|
const toUrlViewerClaims = (claims) => {
|
|
2269
1354
|
if (claims === void 0) return void 0;
|
|
2270
1355
|
const parsed = parseViewerClaims(claims);
|
|
2271
|
-
if (!parsed) throw invalidArgument("Invalid viewerClaims");
|
|
1356
|
+
if (!parsed) throw require_CalmLensError.invalidArgument("Invalid viewerClaims");
|
|
2272
1357
|
const { region, ageConfirmed } = parsed;
|
|
2273
1358
|
if (!region && ageConfirmed !== true) return void 0;
|
|
2274
1359
|
return {
|
|
@@ -2290,10 +1375,10 @@ const appendAssetLocation = (assetUrl, location) => {
|
|
|
2290
1375
|
const selected = lens !== void 0 || transform !== void 0;
|
|
2291
1376
|
let path = assetUrl;
|
|
2292
1377
|
if (resource === void 0) {
|
|
2293
|
-
if (selected) throw invalidArgument("A lens or transform needs a resource, such as rendered");
|
|
1378
|
+
if (selected) throw require_CalmLensError.invalidArgument("A lens or transform needs a resource, such as rendered");
|
|
2294
1379
|
} else {
|
|
2295
|
-
if (typeof resource !== "string" || !Object.hasOwn(ASSET_RESOURCE_PATHS, resource)) throw invalidArgument(`resource must be one of ${CDN_RESOURCES.join(", ")}`);
|
|
2296
|
-
if (UNSELECTABLE.has(resource) && selected) throw invalidArgument(`The ${resource} resource takes no lens or transform`);
|
|
1380
|
+
if (typeof resource !== "string" || !Object.hasOwn(ASSET_RESOURCE_PATHS, resource)) throw require_CalmLensError.invalidArgument(`resource must be one of ${CDN_RESOURCES.join(", ")}`);
|
|
1381
|
+
if (UNSELECTABLE.has(resource) && selected) throw require_CalmLensError.invalidArgument(`The ${resource} resource takes no lens or transform`);
|
|
2297
1382
|
path = `${assetUrl}/${ASSET_RESOURCE_PATHS[resource]}`;
|
|
2298
1383
|
const selector = transformSelector(transform);
|
|
2299
1384
|
const parts = [...lens !== void 0 ? [`@${encodePathSegment(lens, "Lens")}`] : [], ...selector ? [typeof transform === "string" ? encodeURI(selector) : selector] : []];
|
|
@@ -2307,7 +1392,7 @@ const appendAssetLocation = (assetUrl, location) => {
|
|
|
2307
1392
|
*/
|
|
2308
1393
|
const appendSignedLocation = (signedUrl, location) => {
|
|
2309
1394
|
const resourcePath = location.resource === void 0 ? "" : `/${ASSET_RESOURCE_PATHS[location.resource]}`;
|
|
2310
|
-
if (!signedUrl.endsWith(resourcePath)) throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, { message: "The signed asset URL doesn't end in the resource it was signed for" });
|
|
1395
|
+
if (!signedUrl.endsWith(resourcePath)) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, { message: "The signed asset URL doesn't end in the resource it was signed for" });
|
|
2311
1396
|
return `${signedUrl}${appendAssetLocation("", location).slice(resourcePath.length)}`;
|
|
2312
1397
|
};
|
|
2313
1398
|
/** An asset's public URL beneath a CDN base URL, with any resource, selector and claims. */
|
|
@@ -2327,7 +1412,7 @@ const buildAssetUrl = (cdnBaseUrl, projectId, options) => {
|
|
|
2327
1412
|
/** Checks `signAssetUrl`'s own options as the API does, before anything is sent. */
|
|
2328
1413
|
const validateSignAssetUrlOptions = (options) => {
|
|
2329
1414
|
const { expiresIn } = options;
|
|
2330
|
-
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}`);
|
|
1415
|
+
if (expiresIn !== void 0 && (!Number.isInteger(expiresIn) || expiresIn < 1 || expiresIn > 86400)) throw require_CalmLensError.invalidArgument(`expiresIn must be a whole number from 1 to ${MAX_SIGNED_URL_EXPIRES_IN}`);
|
|
2331
1416
|
getAssetSegment(options);
|
|
2332
1417
|
appendAssetLocation("", options);
|
|
2333
1418
|
};
|
|
@@ -2354,7 +1439,7 @@ const splitAssetUrl = (url) => {
|
|
|
2354
1439
|
claims: JSON.parse(raw)
|
|
2355
1440
|
};
|
|
2356
1441
|
} catch {
|
|
2357
|
-
throw invalidArgument("The asset URL's viewerClaims are not JSON");
|
|
1442
|
+
throw require_CalmLensError.invalidArgument("The asset URL's viewerClaims are not JSON");
|
|
2358
1443
|
}
|
|
2359
1444
|
};
|
|
2360
1445
|
const isAssetInfo = (value) => {
|
|
@@ -2369,7 +1454,7 @@ const isAssetInfo = (value) => {
|
|
|
2369
1454
|
* `signed-url/expired` or `asset/not-found`.
|
|
2370
1455
|
*/
|
|
2371
1456
|
const getAssetInfo = async (url, options = {}) => {
|
|
2372
|
-
if (typeof url !== "string" || !URL.canParse(url)) throw invalidArgument("url must be an absolute asset URL");
|
|
1457
|
+
if (typeof url !== "string" || !URL.canParse(url)) throw require_CalmLensError.invalidArgument("url must be an absolute asset URL");
|
|
2373
1458
|
const { base, claims } = splitAssetUrl(url);
|
|
2374
1459
|
const infoUrl = `${base}/info${viewerClaimsQuery(options.viewerClaims ?? claims)}`;
|
|
2375
1460
|
const fetcher = options.fetch ?? globalThis.fetch;
|
|
@@ -2381,7 +1466,7 @@ const getAssetInfo = async (url, options = {}) => {
|
|
|
2381
1466
|
});
|
|
2382
1467
|
} catch (cause) {
|
|
2383
1468
|
if (options.signal?.aborted) throw cause;
|
|
2384
|
-
throw new CalmLensError(SDK_ERROR_CODES.TRANSPORT_ERROR, {
|
|
1469
|
+
throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.TRANSPORT_ERROR, {
|
|
2385
1470
|
message: "The asset's info could not be fetched",
|
|
2386
1471
|
cause
|
|
2387
1472
|
});
|
|
@@ -2392,7 +1477,7 @@ const getAssetInfo = async (url, options = {}) => {
|
|
|
2392
1477
|
try {
|
|
2393
1478
|
data = JSON.parse(new TextDecoder().decode(bytes));
|
|
2394
1479
|
} catch {}
|
|
2395
|
-
if (!isAssetInfo(data)) throw new CalmLensError(SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
1480
|
+
if (!isAssetInfo(data)) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, {
|
|
2396
1481
|
message: "The CDN returned no asset info",
|
|
2397
1482
|
status: response.status
|
|
2398
1483
|
});
|
|
@@ -2430,18 +1515,6 @@ const selectModerationContextItems = (items) => {
|
|
|
2430
1515
|
}
|
|
2431
1516
|
return selected;
|
|
2432
1517
|
};
|
|
2433
|
-
Object.defineProperty(exports, "API_ERROR_CODES", {
|
|
2434
|
-
enumerable: true,
|
|
2435
|
-
get: function() {
|
|
2436
|
-
return API_ERROR_CODES;
|
|
2437
|
-
}
|
|
2438
|
-
});
|
|
2439
|
-
Object.defineProperty(exports, "API_ERROR_DEFINITIONS", {
|
|
2440
|
-
enumerable: true,
|
|
2441
|
-
get: function() {
|
|
2442
|
-
return API_ERROR_DEFINITIONS;
|
|
2443
|
-
}
|
|
2444
|
-
});
|
|
2445
1518
|
Object.defineProperty(exports, "ASSET_RESOURCE_PATHS", {
|
|
2446
1519
|
enumerable: true,
|
|
2447
1520
|
get: function() {
|
|
@@ -2454,132 +1527,18 @@ Object.defineProperty(exports, "AUTO_PAGING_TO_ARRAY_MAX", {
|
|
|
2454
1527
|
return AUTO_PAGING_TO_ARRAY_MAX;
|
|
2455
1528
|
}
|
|
2456
1529
|
});
|
|
2457
|
-
Object.defineProperty(exports, "CALMLENS_ERROR_CODES", {
|
|
2458
|
-
enumerable: true,
|
|
2459
|
-
get: function() {
|
|
2460
|
-
return CALMLENS_ERROR_CODES;
|
|
2461
|
-
}
|
|
2462
|
-
});
|
|
2463
1530
|
Object.defineProperty(exports, "CDN_RESOURCES", {
|
|
2464
1531
|
enumerable: true,
|
|
2465
1532
|
get: function() {
|
|
2466
1533
|
return CDN_RESOURCES;
|
|
2467
1534
|
}
|
|
2468
1535
|
});
|
|
2469
|
-
Object.defineProperty(exports, "CalmLensApiError", {
|
|
2470
|
-
enumerable: true,
|
|
2471
|
-
get: function() {
|
|
2472
|
-
return CalmLensApiError;
|
|
2473
|
-
}
|
|
2474
|
-
});
|
|
2475
|
-
Object.defineProperty(exports, "CalmLensAuthenticationError", {
|
|
2476
|
-
enumerable: true,
|
|
2477
|
-
get: function() {
|
|
2478
|
-
return CalmLensAuthenticationError;
|
|
2479
|
-
}
|
|
2480
|
-
});
|
|
2481
|
-
Object.defineProperty(exports, "CalmLensBadRequestError", {
|
|
2482
|
-
enumerable: true,
|
|
2483
|
-
get: function() {
|
|
2484
|
-
return CalmLensBadRequestError;
|
|
2485
|
-
}
|
|
2486
|
-
});
|
|
2487
|
-
Object.defineProperty(exports, "CalmLensCancelledError", {
|
|
2488
|
-
enumerable: true,
|
|
2489
|
-
get: function() {
|
|
2490
|
-
return CalmLensCancelledError;
|
|
2491
|
-
}
|
|
2492
|
-
});
|
|
2493
|
-
Object.defineProperty(exports, "CalmLensConfigurationError", {
|
|
2494
|
-
enumerable: true,
|
|
2495
|
-
get: function() {
|
|
2496
|
-
return CalmLensConfigurationError;
|
|
2497
|
-
}
|
|
2498
|
-
});
|
|
2499
|
-
Object.defineProperty(exports, "CalmLensConflictError", {
|
|
2500
|
-
enumerable: true,
|
|
2501
|
-
get: function() {
|
|
2502
|
-
return CalmLensConflictError;
|
|
2503
|
-
}
|
|
2504
|
-
});
|
|
2505
|
-
Object.defineProperty(exports, "CalmLensConnectionError", {
|
|
2506
|
-
enumerable: true,
|
|
2507
|
-
get: function() {
|
|
2508
|
-
return CalmLensConnectionError;
|
|
2509
|
-
}
|
|
2510
|
-
});
|
|
2511
|
-
Object.defineProperty(exports, "CalmLensError", {
|
|
2512
|
-
enumerable: true,
|
|
2513
|
-
get: function() {
|
|
2514
|
-
return CalmLensError;
|
|
2515
|
-
}
|
|
2516
|
-
});
|
|
2517
|
-
Object.defineProperty(exports, "CalmLensInvalidArgumentError", {
|
|
2518
|
-
enumerable: true,
|
|
2519
|
-
get: function() {
|
|
2520
|
-
return CalmLensInvalidArgumentError;
|
|
2521
|
-
}
|
|
2522
|
-
});
|
|
2523
|
-
Object.defineProperty(exports, "CalmLensInvalidResponseError", {
|
|
2524
|
-
enumerable: true,
|
|
2525
|
-
get: function() {
|
|
2526
|
-
return CalmLensInvalidResponseError;
|
|
2527
|
-
}
|
|
2528
|
-
});
|
|
2529
|
-
Object.defineProperty(exports, "CalmLensNotFoundError", {
|
|
2530
|
-
enumerable: true,
|
|
2531
|
-
get: function() {
|
|
2532
|
-
return CalmLensNotFoundError;
|
|
2533
|
-
}
|
|
2534
|
-
});
|
|
2535
|
-
Object.defineProperty(exports, "CalmLensPayloadTooLargeError", {
|
|
2536
|
-
enumerable: true,
|
|
2537
|
-
get: function() {
|
|
2538
|
-
return CalmLensPayloadTooLargeError;
|
|
2539
|
-
}
|
|
2540
|
-
});
|
|
2541
|
-
Object.defineProperty(exports, "CalmLensPermissionDeniedError", {
|
|
2542
|
-
enumerable: true,
|
|
2543
|
-
get: function() {
|
|
2544
|
-
return CalmLensPermissionDeniedError;
|
|
2545
|
-
}
|
|
2546
|
-
});
|
|
2547
|
-
Object.defineProperty(exports, "CalmLensRateLimitError", {
|
|
2548
|
-
enumerable: true,
|
|
2549
|
-
get: function() {
|
|
2550
|
-
return CalmLensRateLimitError;
|
|
2551
|
-
}
|
|
2552
|
-
});
|
|
2553
|
-
Object.defineProperty(exports, "CalmLensServerError", {
|
|
2554
|
-
enumerable: true,
|
|
2555
|
-
get: function() {
|
|
2556
|
-
return CalmLensServerError;
|
|
2557
|
-
}
|
|
2558
|
-
});
|
|
2559
|
-
Object.defineProperty(exports, "CalmLensTimeoutError", {
|
|
2560
|
-
enumerable: true,
|
|
2561
|
-
get: function() {
|
|
2562
|
-
return CalmLensTimeoutError;
|
|
2563
|
-
}
|
|
2564
|
-
});
|
|
2565
1536
|
Object.defineProperty(exports, "CalmLensTransport", {
|
|
2566
1537
|
enumerable: true,
|
|
2567
1538
|
get: function() {
|
|
2568
1539
|
return CalmLensTransport;
|
|
2569
1540
|
}
|
|
2570
1541
|
});
|
|
2571
|
-
Object.defineProperty(exports, "CalmLensUnprocessableEntityError", {
|
|
2572
|
-
enumerable: true,
|
|
2573
|
-
get: function() {
|
|
2574
|
-
return CalmLensUnprocessableEntityError;
|
|
2575
|
-
}
|
|
2576
|
-
});
|
|
2577
|
-
Object.defineProperty(exports, "CalmLensWebhookVerificationError", {
|
|
2578
|
-
enumerable: true,
|
|
2579
|
-
get: function() {
|
|
2580
|
-
return CalmLensWebhookVerificationError;
|
|
2581
|
-
}
|
|
2582
|
-
});
|
|
2583
1542
|
Object.defineProperty(exports, "DEFAULT_CDN_BASE_URL", {
|
|
2584
1543
|
enumerable: true,
|
|
2585
1544
|
get: function() {
|
|
@@ -2622,12 +1581,6 @@ Object.defineProperty(exports, "MODERATION_CONTEXT_USED_ITEMS", {
|
|
|
2622
1581
|
return MODERATION_CONTEXT_USED_ITEMS;
|
|
2623
1582
|
}
|
|
2624
1583
|
});
|
|
2625
|
-
Object.defineProperty(exports, "SDK_ERROR_CODES", {
|
|
2626
|
-
enumerable: true,
|
|
2627
|
-
get: function() {
|
|
2628
|
-
return SDK_ERROR_CODES;
|
|
2629
|
-
}
|
|
2630
|
-
});
|
|
2631
1584
|
Object.defineProperty(exports, "SDK_VERSION", {
|
|
2632
1585
|
enumerable: true,
|
|
2633
1586
|
get: function() {
|
|
@@ -2694,18 +1647,6 @@ Object.defineProperty(exports, "getRejectedUploadMimeTypeError", {
|
|
|
2694
1647
|
return getRejectedUploadMimeTypeError;
|
|
2695
1648
|
}
|
|
2696
1649
|
});
|
|
2697
|
-
Object.defineProperty(exports, "invalidArgument", {
|
|
2698
|
-
enumerable: true,
|
|
2699
|
-
get: function() {
|
|
2700
|
-
return invalidArgument;
|
|
2701
|
-
}
|
|
2702
|
-
});
|
|
2703
|
-
Object.defineProperty(exports, "invalidConfig", {
|
|
2704
|
-
enumerable: true,
|
|
2705
|
-
get: function() {
|
|
2706
|
-
return invalidConfig;
|
|
2707
|
-
}
|
|
2708
|
-
});
|
|
2709
1650
|
Object.defineProperty(exports, "isAcceptedUploadMimeType", {
|
|
2710
1651
|
enumerable: true,
|
|
2711
1652
|
get: function() {
|