calmlens 0.29.1 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/calmlens.js +39 -18
- package/cjs/{BrowserUpload-CsxEB1Pr.js → BrowserUpload-BNeTp6eF.js} +1 -1
- package/cjs/{BrowserUpload-CeGsM9h1.d.ts → BrowserUpload-DS6KT6o_.d.ts} +2 -2
- package/{esm/CalmLensAppClient-D-BD_Ny1.d.ts → cjs/CalmLensAppClient-B4vzxEzg.d.ts} +1 -1
- package/cjs/{CalmLensAppClient-BWMcQM9v.js → CalmLensAppClient-ClqGwUbl.js} +7 -6
- package/cjs/{CalmLensConnection-DBgV8D1B.js → CalmLensConnection-og0jh-Fw.js} +29 -28
- package/cjs/CalmLensError-DPHJaVjX.js +1066 -0
- package/cjs/{CalmLensServerClient-BYN_N0lt.d.ts → CalmLensServerClient-BJl2Hsxr.d.ts} +12 -8
- package/cjs/{CalmLensServerClient-DYO3geSA.js → CalmLensServerClient-KsXM77rO.js} +37 -35
- package/cjs/{TestTriggers-uL2Ec8Vt-cPmmKvYd.js → CalmLensTestInputArguments-BXDBAOg_.js} +50 -22
- package/cjs/{CalmLensTypes-C2blKgTu.d.ts → CalmLensTypes-fAgF0_lq.d.ts} +206 -6
- package/cjs/{Classification-CMM2tZpJ-IdIh63n0.d.ts → Classification-DbXUPSvH-C0o2t4mg.d.ts} +15 -30
- package/cjs/{Core-CNmoxDCW.d.ts → Core-DL531ZPG.d.ts} +2 -2
- package/cjs/{Core-Bl-aESvN.js → Core-eDiPpil9.js} +4 -3
- package/cjs/{ModerationContextLimits-DHu2jHpo.js → ModerationContextLimits-BVBkcgSU.js} +67 -1126
- package/{esm/ReactUpload-kqEe6gcN.d.ts → cjs/ReactUpload-BoS0lr7U.d.ts} +1 -1
- package/cjs/{ReactUpload-BFVNyWoI.js → ReactUpload-DAPAzAwY.js} +1 -1
- package/{esm/TestTriggers-dognME9k-PWyIfHMI.d.ts → cjs/TestTriggers-CLjF01NU.d.ts} +2 -3
- package/cjs/{UploadController-VM1qYwNq.js → UploadController-BElzwMic.js} +6 -6
- package/{esm/WebhookPayload-DZWlnvcY.d.ts → cjs/WebhookPayload-DlGoY_db.d.ts} +11 -7
- package/cjs/app.d.ts +6 -6
- package/cjs/app.js +22 -21
- package/cjs/elements.d.ts +4 -4
- package/cjs/elements.js +4 -4
- package/cjs/{index-Dl2qwS8L.d.ts → index-ChrzzIRt.d.ts} +3 -3
- package/cjs/index.d.ts +5 -5
- package/cjs/index.js +21 -20
- package/cjs/react-native.d.ts +2 -2
- package/cjs/react-native.js +4 -4
- package/cjs/react.d.ts +4 -4
- package/cjs/react.js +5 -5
- package/cjs/server.d.ts +12 -12
- package/cjs/server.js +23 -22
- package/cjs/test-inputs.d.ts +6 -2
- package/cjs/test-inputs.js +23 -13
- package/cjs/testing.d.ts +14 -10
- package/cjs/testing.js +154 -147
- package/cjs/{ui-BCiLF8cU.js → ui-COjb2Hx6.js} +2 -2
- package/cjs/{ui-BtmJC-f9.d.ts → ui-DpZOLeVs.d.ts} +2 -2
- package/cjs/ui.d.ts +2 -2
- package/cjs/ui.js +3 -3
- package/cjs/vue.d.ts +5 -5
- package/cjs/vue.js +4 -4
- package/esm/{BrowserUpload-DB3WpaC1.js → BrowserUpload-BCmj5eGu.js} +1 -1
- package/esm/{BrowserUpload-CeGsM9h1.d.ts → BrowserUpload-DS6KT6o_.d.ts} +2 -2
- package/{cjs/CalmLensAppClient-D-BD_Ny1.d.ts → esm/CalmLensAppClient-B4vzxEzg.d.ts} +1 -1
- package/esm/{CalmLensAppClient-Dg-jPs4B.js → CalmLensAppClient-DcPVLn2y.js} +3 -2
- package/esm/{CalmLensConnection-Di7K7Wnl.js → CalmLensConnection-Pm-g6a1l.js} +2 -1
- package/esm/CalmLensError-BDWThPCr.js +917 -0
- package/esm/{CalmLensServerClient-BYN_N0lt.d.ts → CalmLensServerClient-BJl2Hsxr.d.ts} +12 -8
- package/esm/{CalmLensServerClient-Pdp7TI8y.js → CalmLensServerClient-C2HGsjkT.js} +18 -16
- package/esm/{TestTriggers-uL2Ec8Vt-DYbTEJWm.js → CalmLensTestInputArguments-Xh4GIadS.js} +22 -1
- package/esm/{CalmLensTypes-C2blKgTu.d.ts → CalmLensTypes-fAgF0_lq.d.ts} +206 -6
- package/esm/{Classification-CMM2tZpJ-IdIh63n0.d.ts → Classification-DbXUPSvH-C0o2t4mg.d.ts} +15 -30
- package/esm/{Core-CNmoxDCW.d.ts → Core-DL531ZPG.d.ts} +2 -2
- package/esm/{Core-CKk4teFu.js → Core-KYgLJ0eb.js} +3 -2
- package/esm/{ModerationContextLimits-xvxUjGfL.js → ModerationContextLimits-DmjWgTBa.js} +3 -918
- package/{cjs/ReactUpload-kqEe6gcN.d.ts → esm/ReactUpload-BoS0lr7U.d.ts} +1 -1
- package/esm/{ReactUpload-DY5qQ70s.js → ReactUpload-QW_RNxFp.js} +1 -1
- package/{cjs/TestTriggers-dognME9k-PWyIfHMI.d.ts → esm/TestTriggers-CLjF01NU.d.ts} +2 -3
- package/esm/{UploadController-wyor-5Z2.js → UploadController-Civ7QPwT.js} +2 -2
- package/{cjs/WebhookPayload-DZWlnvcY.d.ts → esm/WebhookPayload-DlGoY_db.d.ts} +11 -7
- package/esm/app.d.ts +6 -6
- package/esm/app.js +3 -2
- package/esm/elements.d.ts +4 -4
- package/esm/elements.js +4 -4
- package/esm/{index-Dl2qwS8L.d.ts → index-ChrzzIRt.d.ts} +3 -3
- package/esm/index.d.ts +5 -5
- package/esm/index.js +3 -1
- package/esm/react-native.d.ts +2 -2
- package/esm/react-native.js +4 -4
- package/esm/react.d.ts +4 -4
- package/esm/react.js +5 -5
- package/esm/server.d.ts +12 -12
- package/esm/server.js +4 -3
- package/esm/test-inputs.d.ts +6 -2
- package/esm/test-inputs.js +12 -1
- package/esm/testing.d.ts +14 -10
- package/esm/testing.js +27 -21
- package/esm/{ui-BqF49fSy.js → ui-BVXgDCO2.js} +2 -2
- package/esm/{ui-BtmJC-f9.d.ts → ui-DpZOLeVs.d.ts} +2 -2
- package/esm/ui.d.ts +2 -2
- package/esm/ui.js +3 -3
- package/esm/vue.d.ts +5 -5
- package/esm/vue.js +4 -4
- package/package.json +1 -1
|
@@ -0,0 +1,917 @@
|
|
|
1
|
+
// src/client/CalmLensErrorCodes.ts
|
|
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 = /* @__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.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
|
+
};
|
|
917
|
+
export { invalidConfig as C, invalidArgument as S, API_ERROR_DEFINITIONS as T, CalmLensTimeoutError as _, CalmLensCancelledError as a, MAX_ERROR_BODY_LENGTH as b, CalmLensConnectionError as c, CalmLensInvalidResponseError as d, CalmLensNotFoundError as f, CalmLensServerError as g, CalmLensRateLimitError as h, CalmLensBadRequestError as i, CalmLensError as l, CalmLensPermissionDeniedError as m, CalmLensApiError as n, CalmLensConfigurationError as o, CalmLensPayloadTooLargeError as p, CalmLensAuthenticationError as r, CalmLensConflictError as s, CALMLENS_ERROR_CODES as t, CalmLensInvalidArgumentError as u, CalmLensUnprocessableEntityError as v, API_ERROR_CODES as w, SDK_ERROR_CODES as x, CalmLensWebhookVerificationError as y };
|