@calmlens/sdk 0.9.0 → 0.10.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/LICENSE +21 -0
- package/README.md +156 -60
- package/cjs/CalmLensTypes-BfweJTMS.d.ts +8584 -0
- package/cjs/CalmLensWebhooks-DJnaLpRy.js +741 -0
- package/cjs/index.d.ts +276 -7525
- package/cjs/index.js +662 -1184
- package/cjs/testing.d.ts +83 -8
- package/cjs/testing.js +991 -596
- package/esm/CalmLensTypes-BfweJTMS.d.ts +8584 -0
- package/esm/CalmLensWebhooks-DLUozliX.js +556 -0
- package/esm/index.d.ts +276 -7525
- package/esm/index.js +648 -1168
- package/esm/testing.d.ts +83 -8
- package/esm/testing.js +960 -592
- package/package.json +24 -18
- package/cjs/CalmLensTypes-CZqyni4p.d.ts +0 -3633
- package/cjs/CalmLensUtils-CArkVfj0.js +0 -637
- package/esm/CalmLensTypes-CZqyni4p.d.ts +0 -3633
- package/esm/CalmLensUtils-Bnikzonc.js +0 -472
|
@@ -1,472 +0,0 @@
|
|
|
1
|
-
import { ErrorCode } from "sendable-error";
|
|
2
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
3
|
-
function _typeof(o) {
|
|
4
|
-
"@babel/helpers - typeof";
|
|
5
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
6
|
-
return typeof o;
|
|
7
|
-
} : function(o) {
|
|
8
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
9
|
-
}, _typeof(o);
|
|
10
|
-
}
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
13
|
-
function toPrimitive(t, r) {
|
|
14
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
15
|
-
var e = t[Symbol.toPrimitive];
|
|
16
|
-
if (void 0 !== e) {
|
|
17
|
-
var i = e.call(t, r || "default");
|
|
18
|
-
if ("object" != _typeof(i)) return i;
|
|
19
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
20
|
-
}
|
|
21
|
-
return ("string" === r ? String : Number)(t);
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
25
|
-
function toPropertyKey(t) {
|
|
26
|
-
var i = toPrimitive(t, "string");
|
|
27
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
28
|
-
}
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
31
|
-
function _defineProperty(e, r, t) {
|
|
32
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
33
|
-
value: t,
|
|
34
|
-
enumerable: !0,
|
|
35
|
-
configurable: !0,
|
|
36
|
-
writable: !0
|
|
37
|
-
}) : e[r] = t, e;
|
|
38
|
-
}
|
|
39
|
-
//#endregion
|
|
40
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/objectSpread2.js
|
|
41
|
-
function ownKeys(e, r) {
|
|
42
|
-
var t = Object.keys(e);
|
|
43
|
-
if (Object.getOwnPropertySymbols) {
|
|
44
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
45
|
-
r && (o = o.filter(function(r) {
|
|
46
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
47
|
-
})), t.push.apply(t, o);
|
|
48
|
-
}
|
|
49
|
-
return t;
|
|
50
|
-
}
|
|
51
|
-
function _objectSpread2(e) {
|
|
52
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
53
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
54
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
55
|
-
_defineProperty(e, r, t[r]);
|
|
56
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
57
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
return e;
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/asyncToGenerator.js
|
|
64
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
65
|
-
try {
|
|
66
|
-
var i = n[a](c), u = i.value;
|
|
67
|
-
} catch (n) {
|
|
68
|
-
e(n);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
72
|
-
}
|
|
73
|
-
function _asyncToGenerator(n) {
|
|
74
|
-
return function() {
|
|
75
|
-
var t = this, e = arguments;
|
|
76
|
-
return new Promise(function(r, o) {
|
|
77
|
-
var a = n.apply(t, e);
|
|
78
|
-
function _next(n) {
|
|
79
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
80
|
-
}
|
|
81
|
-
function _throw(n) {
|
|
82
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
83
|
-
}
|
|
84
|
-
_next(void 0);
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region ../shared/src/AssetPayload.ts
|
|
90
|
-
const uint8ArrayInputToNumbers = (value) => {
|
|
91
|
-
if (Array.isArray(value)) return value;
|
|
92
|
-
return Array.from(value);
|
|
93
|
-
};
|
|
94
|
-
const bufferInputToBytes = (value) => {
|
|
95
|
-
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
96
|
-
return Uint8Array.from(value);
|
|
97
|
-
};
|
|
98
|
-
const BASE64_PART_BOUNDARY_ERROR = "Invalid base64 part. For multipart uploads, split the original bytes first, then base64-encode each part. Do not split one full base64 string into substrings.";
|
|
99
|
-
const MULTIPART_PART_TOO_SMALL_ERROR = `Multipart upload parts must be at least 5MiB except the final part.`;
|
|
100
|
-
const getRawBase64 = (value) => {
|
|
101
|
-
const markerIndex = value.indexOf(";base64,");
|
|
102
|
-
if (markerIndex === -1) return value;
|
|
103
|
-
return value.slice(markerIndex + 8);
|
|
104
|
-
};
|
|
105
|
-
const validateBase64PayloadString = (payload, options) => {
|
|
106
|
-
const raw = getRawBase64(payload.base64).replace(/\s/g, "");
|
|
107
|
-
if ((options === null || options === void 0 ? void 0 : options.multipart) && raw.length % 4 !== 0) return {
|
|
108
|
-
ok: false,
|
|
109
|
-
error: BASE64_PART_BOUNDARY_ERROR
|
|
110
|
-
};
|
|
111
|
-
return { ok: true };
|
|
112
|
-
};
|
|
113
|
-
const isReadableStream = (value) => typeof value === "object" && value !== null && "getReader" in value && typeof value.getReader === "function";
|
|
114
|
-
const assetToData = (payload) => {
|
|
115
|
-
if ("plainText" in payload && payload.plainText !== void 0) return new TextEncoder().encode(payload.plainText);
|
|
116
|
-
if ("data" in payload && payload.data) return payload.data;
|
|
117
|
-
if ("buffer" in payload) {
|
|
118
|
-
if (payload.buffer instanceof ArrayBuffer) return payload.buffer;
|
|
119
|
-
return bufferInputToBytes(payload.buffer);
|
|
120
|
-
}
|
|
121
|
-
if (payload.uint8Array !== void 0) return Uint8Array.from(uint8ArrayInputToNumbers(payload.uint8Array));
|
|
122
|
-
if (payload.base64 === void 0) throw new Error("Invalid asset payload");
|
|
123
|
-
const raw = getRawBase64(payload.base64);
|
|
124
|
-
if (typeof Buffer !== "undefined") return Uint8Array.from(Buffer.from(raw, "base64"));
|
|
125
|
-
const binary = atob(raw);
|
|
126
|
-
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
127
|
-
};
|
|
128
|
-
const assetDataToUint8Array = function() {
|
|
129
|
-
var _ref = _asyncToGenerator(function* (data) {
|
|
130
|
-
if (data instanceof Response) return new Uint8Array(yield data.arrayBuffer());
|
|
131
|
-
if (isReadableStream(data)) return new Uint8Array(yield new Response(data).arrayBuffer());
|
|
132
|
-
if (data instanceof Blob) return new Uint8Array(yield data.arrayBuffer());
|
|
133
|
-
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
134
|
-
return data;
|
|
135
|
-
});
|
|
136
|
-
return function assetDataToUint8Array(_x) {
|
|
137
|
-
return _ref.apply(this, arguments);
|
|
138
|
-
};
|
|
139
|
-
}();
|
|
140
|
-
const getAssetPayloadByteLength = (payload) => {
|
|
141
|
-
if ("plainText" in payload && payload.plainText !== void 0) return new TextEncoder().encode(payload.plainText).byteLength;
|
|
142
|
-
if ("data" in payload && payload.data) {
|
|
143
|
-
if (payload.data instanceof Blob) return payload.data.size;
|
|
144
|
-
if (payload.data instanceof Response) {
|
|
145
|
-
const contentLength = payload.data.headers.get("content-length");
|
|
146
|
-
return contentLength ? Number(contentLength) : void 0;
|
|
147
|
-
}
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if ("buffer" in payload && payload.buffer) return payload.buffer.byteLength;
|
|
151
|
-
if (payload.uint8Array !== void 0) {
|
|
152
|
-
if (Array.isArray(payload.uint8Array)) return payload.uint8Array.length;
|
|
153
|
-
return payload.uint8Array.byteLength;
|
|
154
|
-
}
|
|
155
|
-
if (payload.base64 === void 0) return;
|
|
156
|
-
const raw = getRawBase64(payload.base64).replace(/\s/g, "");
|
|
157
|
-
const padding = raw.endsWith("==") ? 2 : raw.endsWith("=") ? 1 : 0;
|
|
158
|
-
return Math.max(0, Math.floor(raw.length * 3 / 4) - padding);
|
|
159
|
-
};
|
|
160
|
-
const validateAssetPayload = (payload, options) => {
|
|
161
|
-
if ("base64" in payload && payload.base64 !== void 0) {
|
|
162
|
-
const validation = validateBase64PayloadString(payload, options);
|
|
163
|
-
if (!validation.ok) return {
|
|
164
|
-
ok: false,
|
|
165
|
-
error: validation.error
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
const byteLength = getAssetPayloadByteLength(payload);
|
|
169
|
-
if ((options === null || options === void 0 ? void 0 : options.multipart) && !options.isFinal && byteLength !== void 0 && byteLength < 5242880) return {
|
|
170
|
-
ok: false,
|
|
171
|
-
error: MULTIPART_PART_TOO_SMALL_ERROR
|
|
172
|
-
};
|
|
173
|
-
return { ok: true };
|
|
174
|
-
};
|
|
175
|
-
//#endregion
|
|
176
|
-
//#region ../shared/src/JsonUtils.ts
|
|
177
|
-
const stringifyJsonCanonical = (value) => JSON.stringify(value, (_key, nestedValue) => {
|
|
178
|
-
if (!nestedValue || typeof nestedValue !== "object" || Array.isArray(nestedValue)) return nestedValue;
|
|
179
|
-
return Object.fromEntries(Object.keys(nestedValue).sort().map((key) => [key, nestedValue[key]]));
|
|
180
|
-
});
|
|
181
|
-
//#endregion
|
|
182
|
-
//#region ../shared/src/PublicErrorCodes.ts
|
|
183
|
-
const PUBLIC_ERROR_CODES = {
|
|
184
|
-
MISSING_TOKEN: new ErrorCode({
|
|
185
|
-
id: "auth/missing-token",
|
|
186
|
-
defaultMessage: "Authentication required. Send your project API key in the X-Api-Key header.",
|
|
187
|
-
status: 401
|
|
188
|
-
}),
|
|
189
|
-
INVALID_API_KEY: new ErrorCode({
|
|
190
|
-
id: "auth/invalid-api-key",
|
|
191
|
-
defaultMessage: "The API key is invalid, revoked or expired. Create a key under Developer → API Keys.",
|
|
192
|
-
status: 401
|
|
193
|
-
}),
|
|
194
|
-
API_KEY_PROJECT_MISMATCH: new ErrorCode({
|
|
195
|
-
id: "auth/project-mismatch",
|
|
196
|
-
defaultMessage: "This API key belongs to a different project. Use a key created for the project that owns this resource.",
|
|
197
|
-
status: 403
|
|
198
|
-
}),
|
|
199
|
-
API_KEY_NOT_ACCEPTED: new ErrorCode({
|
|
200
|
-
id: "auth/api-key-not-accepted",
|
|
201
|
-
defaultMessage: "API keys are only accepted by the public API at /v1.",
|
|
202
|
-
status: 403
|
|
203
|
-
}),
|
|
204
|
-
FILE_TOO_LARGE: new ErrorCode({
|
|
205
|
-
id: "upload/file-too-large",
|
|
206
|
-
defaultMessage: "File size exceeds limit. Maximum direct image size is 10MB, audio/video size is 50MiB, and other files is 5GB.",
|
|
207
|
-
status: 400
|
|
208
|
-
}),
|
|
209
|
-
IMAGE_REQUIRES_MULTIPART_UPLOAD: new ErrorCode({
|
|
210
|
-
id: "upload/image-requires-multipart-upload",
|
|
211
|
-
defaultMessage: "Images of 10MB or more must use a multipart upload.",
|
|
212
|
-
status: 400
|
|
213
|
-
}),
|
|
214
|
-
MULTIPART_IMAGE_TOO_SMALL: new ErrorCode({
|
|
215
|
-
id: "upload/multipart-image-too-small",
|
|
216
|
-
defaultMessage: "Multipart image uploads must total at least 10MB.",
|
|
217
|
-
status: 400
|
|
218
|
-
}),
|
|
219
|
-
MULTIPART_IMAGE_TOO_LARGE: new ErrorCode({
|
|
220
|
-
id: "upload/multipart-image-too-large",
|
|
221
|
-
defaultMessage: "Multipart image uploads cannot exceed 20MB.",
|
|
222
|
-
status: 400
|
|
223
|
-
}),
|
|
224
|
-
IMAGE_EXCEEDED_MAX_DIMENSIONS: new ErrorCode({
|
|
225
|
-
id: "upload/image-exceeded-max-dimensions",
|
|
226
|
-
defaultMessage: "Image exceeds maximum dimensions. Maximum dimensions are 12,000px.",
|
|
227
|
-
status: 400
|
|
228
|
-
}),
|
|
229
|
-
UPLOAD_LIMIT_EXCEEDED: new ErrorCode({
|
|
230
|
-
id: "upload/limit-exceeded",
|
|
231
|
-
defaultMessage: "Upload limit exceeded. You have used all your free uploads. Please upgrade to Plus or Pro for unlimited uploads.",
|
|
232
|
-
status: 403
|
|
233
|
-
}),
|
|
234
|
-
INVALID_UPLOAD_MIME_TYPE: new ErrorCode({
|
|
235
|
-
id: "upload/invalid-mime-type",
|
|
236
|
-
defaultMessage: "Upload file type is not supported. Uploads must use a concrete file MIME type that CalmLens can store and process, such as image/png, image/jpeg, application/pdf, or text/plain.",
|
|
237
|
-
status: 400
|
|
238
|
-
}),
|
|
239
|
-
INVALID_EVENT_CURSOR: new ErrorCode({
|
|
240
|
-
id: "events/invalid-cursor",
|
|
241
|
-
defaultMessage: "The events cursor is invalid. Use the cursor from a previous response, or omit it to start from now.",
|
|
242
|
-
status: 400
|
|
243
|
-
}),
|
|
244
|
-
INVALID_UPLOAD_PAYLOAD: new ErrorCode({
|
|
245
|
-
id: "upload/invalid-payload",
|
|
246
|
-
defaultMessage: "Upload payload is invalid.",
|
|
247
|
-
status: 400
|
|
248
|
-
}),
|
|
249
|
-
USE_UPLOAD_PART: new ErrorCode({
|
|
250
|
-
id: "upload/use-upload-part",
|
|
251
|
-
defaultMessage: "Use uploadPart for multipart upload parts after the first part",
|
|
252
|
-
status: 409
|
|
253
|
-
}),
|
|
254
|
-
UPLOAD_NOT_OPEN: new ErrorCode({
|
|
255
|
-
id: "upload/not-open",
|
|
256
|
-
defaultMessage: "Asset is not accepting additional parts",
|
|
257
|
-
status: 409
|
|
258
|
-
}),
|
|
259
|
-
INVALID_UPLOAD_PART_NUMBER: new ErrorCode({
|
|
260
|
-
id: "upload/invalid-part-number",
|
|
261
|
-
defaultMessage: "Multipart upload part number is invalid.",
|
|
262
|
-
status: 409
|
|
263
|
-
}),
|
|
264
|
-
UPLOAD_MISSING: new ErrorCode({
|
|
265
|
-
id: "upload/missing",
|
|
266
|
-
defaultMessage: "Multipart upload state is missing",
|
|
267
|
-
status: 409
|
|
268
|
-
}),
|
|
269
|
-
ASSET_NOT_FOUND: new ErrorCode({
|
|
270
|
-
id: "asset/not-found",
|
|
271
|
-
defaultMessage: "Asset not found",
|
|
272
|
-
status: 404
|
|
273
|
-
}),
|
|
274
|
-
PROJECT_NOT_FOUND: new ErrorCode({
|
|
275
|
-
id: "project/not-found",
|
|
276
|
-
defaultMessage: "Project not found",
|
|
277
|
-
status: 404
|
|
278
|
-
}),
|
|
279
|
-
ASSET_UPDATE_FAILED: new ErrorCode({
|
|
280
|
-
id: "asset/update-failed",
|
|
281
|
-
defaultMessage: "Failed to update asset",
|
|
282
|
-
status: 500
|
|
283
|
-
}),
|
|
284
|
-
ASSET_SAFETY_HELD: new ErrorCode({
|
|
285
|
-
id: "asset/safety-held",
|
|
286
|
-
defaultMessage: "Asset access is restricted by a safety hold.",
|
|
287
|
-
status: 423
|
|
288
|
-
}),
|
|
289
|
-
ASSET_NOT_RETRYABLE: new ErrorCode({
|
|
290
|
-
id: "asset/not-retryable",
|
|
291
|
-
defaultMessage: "Only assets that failed to process (status error) can be retried.",
|
|
292
|
-
status: 409
|
|
293
|
-
}),
|
|
294
|
-
ASSET_CONTENT_UNAVAILABLE: new ErrorCode({
|
|
295
|
-
id: "asset/content-unavailable",
|
|
296
|
-
defaultMessage: "This asset's content is no longer stored, so it can't be processed again. Upload it again instead.",
|
|
297
|
-
status: 409
|
|
298
|
-
}),
|
|
299
|
-
SUPPORT_TICKET_NOT_FOUND: new ErrorCode({
|
|
300
|
-
id: "support/ticket-not-found",
|
|
301
|
-
defaultMessage: "Support ticket not found.",
|
|
302
|
-
status: 404
|
|
303
|
-
}),
|
|
304
|
-
DUPLICATE_EXTERNAL_ID: new ErrorCode({
|
|
305
|
-
id: "asset/duplicate-external-id",
|
|
306
|
-
defaultMessage: "An asset with this externalId already exists in the project.",
|
|
307
|
-
status: 409
|
|
308
|
-
}),
|
|
309
|
-
FOLDER_NOT_FOUND: new ErrorCode({
|
|
310
|
-
id: "folder/not-found",
|
|
311
|
-
defaultMessage: "Folder not found",
|
|
312
|
-
status: 404
|
|
313
|
-
}),
|
|
314
|
-
DUPLICATE_FOLDER_NAME: new ErrorCode({
|
|
315
|
-
id: "folder/duplicate-name",
|
|
316
|
-
defaultMessage: "A folder with this name already exists in this location.",
|
|
317
|
-
status: 409
|
|
318
|
-
}),
|
|
319
|
-
FOLDER_NOT_EMPTY: new ErrorCode({
|
|
320
|
-
id: "folder/not-empty",
|
|
321
|
-
defaultMessage: "Folder must be empty before it can be deleted.",
|
|
322
|
-
status: 409
|
|
323
|
-
}),
|
|
324
|
-
FOLDER_PARENT_CYCLE: new ErrorCode({
|
|
325
|
-
id: "folder/parent-cycle",
|
|
326
|
-
defaultMessage: "A folder cannot be moved inside itself or one of its descendants.",
|
|
327
|
-
status: 409
|
|
328
|
-
}),
|
|
329
|
-
LENS_VERSION_CONFLICT: new ErrorCode({
|
|
330
|
-
id: "lens/version-conflict",
|
|
331
|
-
defaultMessage: "Lens updates require a version greater than the current version.",
|
|
332
|
-
status: 409
|
|
333
|
-
})
|
|
334
|
-
};
|
|
335
|
-
PUBLIC_ERROR_CODES.MISSING_TOKEN, PUBLIC_ERROR_CODES.INVALID_API_KEY, PUBLIC_ERROR_CODES.API_KEY_PROJECT_MISMATCH;
|
|
336
|
-
const MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
337
|
-
const MIN_MULTIPART_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
338
|
-
const REJECTED_UPLOAD_MIME_TYPE_SET = /* @__PURE__ */ new Set([
|
|
339
|
-
"application/octet-stream",
|
|
340
|
-
"multipart/form-data",
|
|
341
|
-
"multipart/mixed",
|
|
342
|
-
"multipart/alternative",
|
|
343
|
-
"multipart/related",
|
|
344
|
-
"multipart/signed",
|
|
345
|
-
"multipart/encrypted"
|
|
346
|
-
]);
|
|
347
|
-
const normalizeUploadMimeType = (mimeType) => {
|
|
348
|
-
var _mimeType$toLowerCase;
|
|
349
|
-
return ((_mimeType$toLowerCase = mimeType.toLowerCase().split(";")[0]) === null || _mimeType$toLowerCase === void 0 ? void 0 : _mimeType$toLowerCase.trim()) || mimeType.toLowerCase().trim();
|
|
350
|
-
};
|
|
351
|
-
const isRejectedUploadMimeType = (mimeType) => REJECTED_UPLOAD_MIME_TYPE_SET.has(normalizeUploadMimeType(mimeType));
|
|
352
|
-
const getRejectedUploadMimeTypeError = (mimeType) => `${normalizeUploadMimeType(mimeType)} is not a valid upload file type. Uploads must use a concrete file MIME type that CalmLens can store and process, such as image/png, image/jpeg, application/pdf, or text/plain.`;
|
|
353
|
-
const DOMAIN = "calmlens.com";
|
|
354
|
-
//#endregion
|
|
355
|
-
//#region src/client/CalmLensError.ts
|
|
356
|
-
const SDK_ERRORS = { NO_CDN_FETCH: {
|
|
357
|
-
id: "sdk/no-cdn-fetch",
|
|
358
|
-
defaultMessage: "No fetch implementation is available for CDN requests"
|
|
359
|
-
} };
|
|
360
|
-
var CalmLensError = class extends Error {
|
|
361
|
-
constructor(errorCode, options) {
|
|
362
|
-
var _ref, _options$message;
|
|
363
|
-
const code = "getId" in errorCode ? errorCode.getId() : errorCode.id;
|
|
364
|
-
const defaultMessage = "getDefaultMessage" in errorCode ? errorCode.getDefaultMessage() : errorCode.defaultMessage;
|
|
365
|
-
super(`[calmlens] ${(_ref = (_options$message = options === null || options === void 0 ? void 0 : options.message) !== null && _options$message !== void 0 ? _options$message : defaultMessage) !== null && _ref !== void 0 ? _ref : code}`, { cause: options === null || options === void 0 ? void 0 : options.cause });
|
|
366
|
-
this.name = "CalmLensError";
|
|
367
|
-
this.code = code;
|
|
368
|
-
this.details = options === null || options === void 0 ? void 0 : options.details;
|
|
369
|
-
this.status = options === null || options === void 0 ? void 0 : options.status;
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
const calmLensError = (errorCode, options) => new CalmLensError(errorCode, options);
|
|
373
|
-
//#endregion
|
|
374
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/objectWithoutPropertiesLoose.js
|
|
375
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
376
|
-
if (null == r) return {};
|
|
377
|
-
var t = {};
|
|
378
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
379
|
-
if (e.includes(n)) continue;
|
|
380
|
-
t[n] = r[n];
|
|
381
|
-
}
|
|
382
|
-
return t;
|
|
383
|
-
}
|
|
384
|
-
//#endregion
|
|
385
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/objectWithoutProperties.js
|
|
386
|
-
function _objectWithoutProperties(e, t) {
|
|
387
|
-
if (null == e) return {};
|
|
388
|
-
var o, r, i = _objectWithoutPropertiesLoose(e, t);
|
|
389
|
-
if (Object.getOwnPropertySymbols) {
|
|
390
|
-
var s = Object.getOwnPropertySymbols(e);
|
|
391
|
-
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
392
|
-
}
|
|
393
|
-
return i;
|
|
394
|
-
}
|
|
395
|
-
//#endregion
|
|
396
|
-
//#region src/client/CalmLensUtils.ts
|
|
397
|
-
const _excluded = ["text", "name"];
|
|
398
|
-
const invalidOptions = (message) => calmLensError({ id: "upload/invalid-payload" }, { message });
|
|
399
|
-
const assertHttpUrl = (name, value) => {
|
|
400
|
-
if (value === void 0) return;
|
|
401
|
-
let url;
|
|
402
|
-
try {
|
|
403
|
-
url = new URL(value);
|
|
404
|
-
} catch (_unused) {}
|
|
405
|
-
if (!url || url.protocol !== "https:" && url.protocol !== "http:") throw invalidOptions(`${name} must be an absolute http(s) URL`);
|
|
406
|
-
};
|
|
407
|
-
/**
|
|
408
|
-
* Checks client options before the client sets anything up. `CalmLensClient` and
|
|
409
|
-
* `MockCalmLensClient` share it so both reject the same configuration.
|
|
410
|
-
*/
|
|
411
|
-
const validateClientOptions = (options) => {
|
|
412
|
-
if (!options || typeof options !== "object") throw invalidOptions("Client options are required");
|
|
413
|
-
if (!options.apiKey) throw invalidOptions("API key is required");
|
|
414
|
-
if (!options.projectId) throw invalidOptions("Project ID is required");
|
|
415
|
-
encodePathSegment(options.projectId, "Project ID");
|
|
416
|
-
if (options.timeoutMs !== void 0 && (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs <= 0)) throw invalidOptions("timeoutMs must be a positive integer");
|
|
417
|
-
assertHttpUrl("baseUrl", options.baseUrl);
|
|
418
|
-
assertHttpUrl("cdnBaseUrl", options.cdnBaseUrl);
|
|
419
|
-
};
|
|
420
|
-
const toTextAssetOptions = (_ref) => {
|
|
421
|
-
let { text, name } = _ref, options = _objectWithoutProperties(_ref, _excluded);
|
|
422
|
-
if (typeof text !== "string" || !text.trim()) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Text to moderate must be a non-empty string" });
|
|
423
|
-
return _objectSpread2(_objectSpread2({}, options), {}, {
|
|
424
|
-
name: name !== null && name !== void 0 ? name : "text",
|
|
425
|
-
content: {
|
|
426
|
-
plainText: text,
|
|
427
|
-
type: "text/plain"
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
};
|
|
431
|
-
/**
|
|
432
|
-
* Encodes an identifier as one URL path segment. `.` and `..` are rejected because URL
|
|
433
|
-
* resolution would treat them as relative segments and send the request to another route.
|
|
434
|
-
*/
|
|
435
|
-
const encodePathSegment = (value, name) => {
|
|
436
|
-
if (typeof value !== "string" || !value) throw invalidOptions(`${name} is required`);
|
|
437
|
-
if (value === "." || value === "..") throw invalidOptions(`${name} cannot be "." or ".."`);
|
|
438
|
-
return encodeURIComponent(value);
|
|
439
|
-
};
|
|
440
|
-
/** Appends a CDN lens (`/@name`) or direct transform selector to an asset URL. */
|
|
441
|
-
const appendCdnSelector = (url, options) => {
|
|
442
|
-
if (options.lens && options.transform) throw invalidOptions("Specify either a lens or a transform, not both");
|
|
443
|
-
if (options.lens) return `${url}/@${encodePathSegment(options.lens, "Lens")}`;
|
|
444
|
-
if (!options.transform) return url;
|
|
445
|
-
const transform = options.transform.replace(/^\/+/, "");
|
|
446
|
-
if (transform.includes("..") || transform.includes("?") || transform.includes("#")) throw invalidOptions("Transform cannot contain \"..\", \"?\" or \"#\"");
|
|
447
|
-
return `${url}/${encodeURI(transform)}`;
|
|
448
|
-
};
|
|
449
|
-
const appendQueryValue = (parts, key, value) => {
|
|
450
|
-
if (value === void 0 || value === null) return;
|
|
451
|
-
if (Array.isArray(value)) {
|
|
452
|
-
for (const [index, item] of value.entries()) appendQueryValue(parts, `${key}[${index}]`, item);
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
if (typeof value === "object") {
|
|
456
|
-
for (const [field, item] of Object.entries(value)) appendQueryValue(parts, `${key}[${field}]`, item);
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
460
|
-
};
|
|
461
|
-
/**
|
|
462
|
-
* Serialises a query object the way the API parses it (qs bracket notation), for example
|
|
463
|
-
* `ordering[0][field]=createdAt&ordering[0][direction]=DESC`. Every key and value is
|
|
464
|
-
* percent-encoded and missing values are omitted.
|
|
465
|
-
*/
|
|
466
|
-
const stringifyQuery = (query) => {
|
|
467
|
-
const parts = [];
|
|
468
|
-
for (const [key, value] of Object.entries(query)) appendQueryValue(parts, key, value);
|
|
469
|
-
return parts.join("&");
|
|
470
|
-
};
|
|
471
|
-
//#endregion
|
|
472
|
-
export { _objectSpread2 as C, _asyncToGenerator as S, assetDataToUint8Array as _, validateClientOptions as a, getRawBase64 as b, SDK_ERRORS as c, MAX_IMAGE_UPLOAD_BYTES as d, MIN_MULTIPART_IMAGE_UPLOAD_BYTES as f, stringifyJsonCanonical as g, PUBLIC_ERROR_CODES as h, toTextAssetOptions as i, calmLensError as l, isRejectedUploadMimeType as m, encodePathSegment as n, _objectWithoutProperties as o, getRejectedUploadMimeTypeError as p, stringifyQuery as r, CalmLensError as s, appendCdnSelector as t, DOMAIN as u, assetToData as v, validateAssetPayload as x, getAssetPayloadByteLength as y };
|