@calmlens/sdk 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +554 -2
- package/bin/calmlens.js +1323 -0
- package/cjs/CalmLensTypes-DG_kHVqY.d.ts +3521 -0
- package/cjs/CalmLensUtils-0QaxbI3A.js +551 -0
- package/cjs/index.d.ts +2741 -0
- package/cjs/index.js +1206 -0
- package/cjs/package.json +3 -0
- package/cjs/testing.d.ts +149 -0
- package/cjs/testing.js +702 -0
- package/esm/CalmLensTypes-DG_kHVqY.d.ts +3521 -0
- package/esm/CalmLensUtils-BQEgxGWk.js +410 -0
- package/esm/index.d.ts +2741 -0
- package/esm/index.js +1196 -0
- package/esm/package.json +3 -0
- package/esm/testing.d.ts +149 -0
- package/esm/testing.js +696 -0
- package/package.json +88 -4
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
let sendable_error = require("sendable-error");
|
|
24
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/typeof.js
|
|
25
|
+
function _typeof(o) {
|
|
26
|
+
"@babel/helpers - typeof";
|
|
27
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
28
|
+
return typeof o;
|
|
29
|
+
} : function(o) {
|
|
30
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
31
|
+
}, _typeof(o);
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPrimitive.js
|
|
35
|
+
function toPrimitive(t, r) {
|
|
36
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
37
|
+
var e = t[Symbol.toPrimitive];
|
|
38
|
+
if (void 0 !== e) {
|
|
39
|
+
var i = e.call(t, r || "default");
|
|
40
|
+
if ("object" != _typeof(i)) return i;
|
|
41
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
42
|
+
}
|
|
43
|
+
return ("string" === r ? String : Number)(t);
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPropertyKey.js
|
|
47
|
+
function toPropertyKey(t) {
|
|
48
|
+
var i = toPrimitive(t, "string");
|
|
49
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/defineProperty.js
|
|
53
|
+
function _defineProperty(e, r, t) {
|
|
54
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
55
|
+
value: t,
|
|
56
|
+
enumerable: !0,
|
|
57
|
+
configurable: !0,
|
|
58
|
+
writable: !0
|
|
59
|
+
}) : e[r] = t, e;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/objectSpread2.js
|
|
63
|
+
function ownKeys(e, r) {
|
|
64
|
+
var t = Object.keys(e);
|
|
65
|
+
if (Object.getOwnPropertySymbols) {
|
|
66
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
67
|
+
r && (o = o.filter(function(r) {
|
|
68
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
69
|
+
})), t.push.apply(t, o);
|
|
70
|
+
}
|
|
71
|
+
return t;
|
|
72
|
+
}
|
|
73
|
+
function _objectSpread2(e) {
|
|
74
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
75
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
76
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
77
|
+
_defineProperty(e, r, t[r]);
|
|
78
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
79
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return e;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/asyncToGenerator.js
|
|
86
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
87
|
+
try {
|
|
88
|
+
var i = n[a](c), u = i.value;
|
|
89
|
+
} catch (n) {
|
|
90
|
+
e(n);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
94
|
+
}
|
|
95
|
+
function _asyncToGenerator(n) {
|
|
96
|
+
return function() {
|
|
97
|
+
var t = this, e = arguments;
|
|
98
|
+
return new Promise(function(r, o) {
|
|
99
|
+
var a = n.apply(t, e);
|
|
100
|
+
function _next(n) {
|
|
101
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
102
|
+
}
|
|
103
|
+
function _throw(n) {
|
|
104
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
105
|
+
}
|
|
106
|
+
_next(void 0);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region ../shared/src/AssetPayload.ts
|
|
112
|
+
const uint8ArrayInputToNumbers = (value) => {
|
|
113
|
+
if (Array.isArray(value)) return value;
|
|
114
|
+
return Array.from(value);
|
|
115
|
+
};
|
|
116
|
+
const bufferInputToBytes = (value) => {
|
|
117
|
+
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
118
|
+
return Uint8Array.from(value);
|
|
119
|
+
};
|
|
120
|
+
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.";
|
|
121
|
+
const MULTIPART_PART_TOO_SMALL_ERROR = `Multipart upload parts must be at least 5MiB except the final part.`;
|
|
122
|
+
const getRawBase64 = (value) => {
|
|
123
|
+
const markerIndex = value.indexOf(";base64,");
|
|
124
|
+
if (markerIndex === -1) return value;
|
|
125
|
+
return value.slice(markerIndex + 8);
|
|
126
|
+
};
|
|
127
|
+
const validateBase64PayloadString = (payload, options) => {
|
|
128
|
+
const raw = getRawBase64(payload.base64).replace(/\s/g, "");
|
|
129
|
+
if ((options === null || options === void 0 ? void 0 : options.multipart) && raw.length % 4 !== 0) return {
|
|
130
|
+
ok: false,
|
|
131
|
+
error: BASE64_PART_BOUNDARY_ERROR
|
|
132
|
+
};
|
|
133
|
+
return { ok: true };
|
|
134
|
+
};
|
|
135
|
+
const isReadableStream = (value) => typeof value === "object" && value !== null && "getReader" in value && typeof value.getReader === "function";
|
|
136
|
+
const assetToData = (payload) => {
|
|
137
|
+
if ("plainText" in payload && payload.plainText !== void 0) return new TextEncoder().encode(payload.plainText);
|
|
138
|
+
if ("data" in payload && payload.data) return payload.data;
|
|
139
|
+
if ("buffer" in payload) {
|
|
140
|
+
if (payload.buffer instanceof ArrayBuffer) return payload.buffer;
|
|
141
|
+
return bufferInputToBytes(payload.buffer);
|
|
142
|
+
}
|
|
143
|
+
if (payload.uint8Array !== void 0) return Uint8Array.from(uint8ArrayInputToNumbers(payload.uint8Array));
|
|
144
|
+
if (payload.base64 === void 0) throw new Error("Invalid asset payload");
|
|
145
|
+
const raw = getRawBase64(payload.base64);
|
|
146
|
+
if (typeof Buffer !== "undefined") return Uint8Array.from(Buffer.from(raw, "base64"));
|
|
147
|
+
const binary = atob(raw);
|
|
148
|
+
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
149
|
+
};
|
|
150
|
+
const assetDataToUint8Array = function() {
|
|
151
|
+
var _ref = _asyncToGenerator(function* (data) {
|
|
152
|
+
if (data instanceof Response) return new Uint8Array(yield data.arrayBuffer());
|
|
153
|
+
if (isReadableStream(data)) return new Uint8Array(yield new Response(data).arrayBuffer());
|
|
154
|
+
if (data instanceof Blob) return new Uint8Array(yield data.arrayBuffer());
|
|
155
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
156
|
+
return data;
|
|
157
|
+
});
|
|
158
|
+
return function assetDataToUint8Array(_x) {
|
|
159
|
+
return _ref.apply(this, arguments);
|
|
160
|
+
};
|
|
161
|
+
}();
|
|
162
|
+
const getAssetPayloadByteLength = (payload) => {
|
|
163
|
+
if ("plainText" in payload && payload.plainText !== void 0) return new TextEncoder().encode(payload.plainText).byteLength;
|
|
164
|
+
if ("data" in payload && payload.data) {
|
|
165
|
+
if (payload.data instanceof Blob) return payload.data.size;
|
|
166
|
+
if (payload.data instanceof Response) {
|
|
167
|
+
const contentLength = payload.data.headers.get("content-length");
|
|
168
|
+
return contentLength ? Number(contentLength) : void 0;
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if ("buffer" in payload && payload.buffer) return payload.buffer.byteLength;
|
|
173
|
+
if (payload.uint8Array !== void 0) {
|
|
174
|
+
if (Array.isArray(payload.uint8Array)) return payload.uint8Array.length;
|
|
175
|
+
return payload.uint8Array.byteLength;
|
|
176
|
+
}
|
|
177
|
+
if (payload.base64 === void 0) return;
|
|
178
|
+
const raw = getRawBase64(payload.base64).replace(/\s/g, "");
|
|
179
|
+
const padding = raw.endsWith("==") ? 2 : raw.endsWith("=") ? 1 : 0;
|
|
180
|
+
return Math.max(0, Math.floor(raw.length * 3 / 4) - padding);
|
|
181
|
+
};
|
|
182
|
+
const validateAssetPayload = (payload, options) => {
|
|
183
|
+
if ("base64" in payload && payload.base64 !== void 0) {
|
|
184
|
+
const validation = validateBase64PayloadString(payload, options);
|
|
185
|
+
if (!validation.ok) return {
|
|
186
|
+
ok: false,
|
|
187
|
+
error: validation.error
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const byteLength = getAssetPayloadByteLength(payload);
|
|
191
|
+
if ((options === null || options === void 0 ? void 0 : options.multipart) && !options.isFinal && byteLength !== void 0 && byteLength < 5242880) return {
|
|
192
|
+
ok: false,
|
|
193
|
+
error: MULTIPART_PART_TOO_SMALL_ERROR
|
|
194
|
+
};
|
|
195
|
+
return { ok: true };
|
|
196
|
+
};
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region ../shared/src/JsonUtils.ts
|
|
199
|
+
const stringifyJsonCanonical = (value) => JSON.stringify(value, (_key, nestedValue) => {
|
|
200
|
+
if (!nestedValue || typeof nestedValue !== "object" || Array.isArray(nestedValue)) return nestedValue;
|
|
201
|
+
return Object.fromEntries(Object.keys(nestedValue).sort().map((key) => [key, nestedValue[key]]));
|
|
202
|
+
});
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region ../shared/src/PublicErrorCodes.ts
|
|
205
|
+
const PUBLIC_ERROR_CODES = {
|
|
206
|
+
MISSING_TOKEN: new sendable_error.ErrorCode({
|
|
207
|
+
id: "auth/missing-token",
|
|
208
|
+
defaultMessage: "Authentication required. Send your project API key in the X-Api-Key header.",
|
|
209
|
+
status: 401
|
|
210
|
+
}),
|
|
211
|
+
INVALID_API_KEY: new sendable_error.ErrorCode({
|
|
212
|
+
id: "auth/invalid-api-key",
|
|
213
|
+
defaultMessage: "The API key is invalid, revoked or expired. Create a key under Developer → API Keys.",
|
|
214
|
+
status: 401
|
|
215
|
+
}),
|
|
216
|
+
API_KEY_PROJECT_MISMATCH: new sendable_error.ErrorCode({
|
|
217
|
+
id: "auth/project-mismatch",
|
|
218
|
+
defaultMessage: "This API key belongs to a different project. Use a key created for the project that owns this resource.",
|
|
219
|
+
status: 403
|
|
220
|
+
}),
|
|
221
|
+
API_KEY_NOT_ACCEPTED: new sendable_error.ErrorCode({
|
|
222
|
+
id: "auth/api-key-not-accepted",
|
|
223
|
+
defaultMessage: "API keys are only accepted by the public API at /v1.",
|
|
224
|
+
status: 403
|
|
225
|
+
}),
|
|
226
|
+
FILE_TOO_LARGE: new sendable_error.ErrorCode({
|
|
227
|
+
id: "upload/file-too-large",
|
|
228
|
+
defaultMessage: "File size exceeds limit. Maximum direct image size is 10MB, audio/video size is 50MiB, and other files is 5GB.",
|
|
229
|
+
status: 400
|
|
230
|
+
}),
|
|
231
|
+
IMAGE_REQUIRES_MULTIPART_UPLOAD: new sendable_error.ErrorCode({
|
|
232
|
+
id: "upload/image-requires-multipart-upload",
|
|
233
|
+
defaultMessage: "Images of 10MB or more must use a multipart upload.",
|
|
234
|
+
status: 400
|
|
235
|
+
}),
|
|
236
|
+
MULTIPART_IMAGE_TOO_SMALL: new sendable_error.ErrorCode({
|
|
237
|
+
id: "upload/multipart-image-too-small",
|
|
238
|
+
defaultMessage: "Multipart image uploads must total at least 10MB.",
|
|
239
|
+
status: 400
|
|
240
|
+
}),
|
|
241
|
+
MULTIPART_IMAGE_TOO_LARGE: new sendable_error.ErrorCode({
|
|
242
|
+
id: "upload/multipart-image-too-large",
|
|
243
|
+
defaultMessage: "Multipart image uploads cannot exceed 20MB.",
|
|
244
|
+
status: 400
|
|
245
|
+
}),
|
|
246
|
+
IMAGE_EXCEEDED_MAX_DIMENSIONS: new sendable_error.ErrorCode({
|
|
247
|
+
id: "upload/image-exceeded-max-dimensions",
|
|
248
|
+
defaultMessage: "Image exceeds maximum dimensions. Maximum dimensions are 12,000px.",
|
|
249
|
+
status: 400
|
|
250
|
+
}),
|
|
251
|
+
UPLOAD_LIMIT_EXCEEDED: new sendable_error.ErrorCode({
|
|
252
|
+
id: "upload/limit-exceeded",
|
|
253
|
+
defaultMessage: "Upload limit exceeded. You have used all your free uploads. Please upgrade to Plus or Pro for unlimited uploads.",
|
|
254
|
+
status: 403
|
|
255
|
+
}),
|
|
256
|
+
INVALID_UPLOAD_MIME_TYPE: new sendable_error.ErrorCode({
|
|
257
|
+
id: "upload/invalid-mime-type",
|
|
258
|
+
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.",
|
|
259
|
+
status: 400
|
|
260
|
+
}),
|
|
261
|
+
INVALID_EVENT_CURSOR: new sendable_error.ErrorCode({
|
|
262
|
+
id: "events/invalid-cursor",
|
|
263
|
+
defaultMessage: "The events cursor is invalid. Use the cursor from a previous response, or omit it to start from now.",
|
|
264
|
+
status: 400
|
|
265
|
+
}),
|
|
266
|
+
INVALID_UPLOAD_PAYLOAD: new sendable_error.ErrorCode({
|
|
267
|
+
id: "upload/invalid-payload",
|
|
268
|
+
defaultMessage: "Upload payload is invalid.",
|
|
269
|
+
status: 400
|
|
270
|
+
}),
|
|
271
|
+
USE_UPLOAD_PART: new sendable_error.ErrorCode({
|
|
272
|
+
id: "upload/use-upload-part",
|
|
273
|
+
defaultMessage: "Use uploadPart for multipart upload parts after the first part",
|
|
274
|
+
status: 409
|
|
275
|
+
}),
|
|
276
|
+
UPLOAD_NOT_OPEN: new sendable_error.ErrorCode({
|
|
277
|
+
id: "upload/not-open",
|
|
278
|
+
defaultMessage: "Asset is not accepting additional parts",
|
|
279
|
+
status: 409
|
|
280
|
+
}),
|
|
281
|
+
INVALID_UPLOAD_PART_NUMBER: new sendable_error.ErrorCode({
|
|
282
|
+
id: "upload/invalid-part-number",
|
|
283
|
+
defaultMessage: "Multipart upload part number is invalid.",
|
|
284
|
+
status: 409
|
|
285
|
+
}),
|
|
286
|
+
UPLOAD_MISSING: new sendable_error.ErrorCode({
|
|
287
|
+
id: "upload/missing",
|
|
288
|
+
defaultMessage: "Multipart upload state is missing",
|
|
289
|
+
status: 409
|
|
290
|
+
}),
|
|
291
|
+
ASSET_NOT_FOUND: new sendable_error.ErrorCode({
|
|
292
|
+
id: "asset/not-found",
|
|
293
|
+
defaultMessage: "Asset not found",
|
|
294
|
+
status: 404
|
|
295
|
+
}),
|
|
296
|
+
PROJECT_NOT_FOUND: new sendable_error.ErrorCode({
|
|
297
|
+
id: "project/not-found",
|
|
298
|
+
defaultMessage: "Project not found",
|
|
299
|
+
status: 404
|
|
300
|
+
}),
|
|
301
|
+
ASSET_UPDATE_FAILED: new sendable_error.ErrorCode({
|
|
302
|
+
id: "asset/update-failed",
|
|
303
|
+
defaultMessage: "Failed to update asset",
|
|
304
|
+
status: 500
|
|
305
|
+
}),
|
|
306
|
+
ASSET_SAFETY_HELD: new sendable_error.ErrorCode({
|
|
307
|
+
id: "asset/safety-held",
|
|
308
|
+
defaultMessage: "Asset access is restricted by a safety hold.",
|
|
309
|
+
status: 423
|
|
310
|
+
}),
|
|
311
|
+
ASSET_NOT_RETRYABLE: new sendable_error.ErrorCode({
|
|
312
|
+
id: "asset/not-retryable",
|
|
313
|
+
defaultMessage: "Only assets that failed to process (status error) can be retried.",
|
|
314
|
+
status: 409
|
|
315
|
+
}),
|
|
316
|
+
ASSET_CONTENT_UNAVAILABLE: new sendable_error.ErrorCode({
|
|
317
|
+
id: "asset/content-unavailable",
|
|
318
|
+
defaultMessage: "This asset's content is no longer stored, so it can't be processed again. Upload it again instead.",
|
|
319
|
+
status: 409
|
|
320
|
+
}),
|
|
321
|
+
SUPPORT_TICKET_NOT_FOUND: new sendable_error.ErrorCode({
|
|
322
|
+
id: "support/ticket-not-found",
|
|
323
|
+
defaultMessage: "Support ticket not found.",
|
|
324
|
+
status: 404
|
|
325
|
+
}),
|
|
326
|
+
DUPLICATE_EXTERNAL_ID: new sendable_error.ErrorCode({
|
|
327
|
+
id: "asset/duplicate-external-id",
|
|
328
|
+
defaultMessage: "An asset with this externalId already exists in the project.",
|
|
329
|
+
status: 409
|
|
330
|
+
}),
|
|
331
|
+
FOLDER_NOT_FOUND: new sendable_error.ErrorCode({
|
|
332
|
+
id: "folder/not-found",
|
|
333
|
+
defaultMessage: "Folder not found",
|
|
334
|
+
status: 404
|
|
335
|
+
}),
|
|
336
|
+
DUPLICATE_FOLDER_NAME: new sendable_error.ErrorCode({
|
|
337
|
+
id: "folder/duplicate-name",
|
|
338
|
+
defaultMessage: "A folder with this name already exists in this location.",
|
|
339
|
+
status: 409
|
|
340
|
+
}),
|
|
341
|
+
FOLDER_NOT_EMPTY: new sendable_error.ErrorCode({
|
|
342
|
+
id: "folder/not-empty",
|
|
343
|
+
defaultMessage: "Folder must be empty before it can be deleted.",
|
|
344
|
+
status: 409
|
|
345
|
+
}),
|
|
346
|
+
FOLDER_PARENT_CYCLE: new sendable_error.ErrorCode({
|
|
347
|
+
id: "folder/parent-cycle",
|
|
348
|
+
defaultMessage: "A folder cannot be moved inside itself or one of its descendants.",
|
|
349
|
+
status: 409
|
|
350
|
+
}),
|
|
351
|
+
LENS_VERSION_CONFLICT: new sendable_error.ErrorCode({
|
|
352
|
+
id: "lens/version-conflict",
|
|
353
|
+
defaultMessage: "Lens updates require a version greater than the current version.",
|
|
354
|
+
status: 409
|
|
355
|
+
})
|
|
356
|
+
};
|
|
357
|
+
PUBLIC_ERROR_CODES.MISSING_TOKEN, PUBLIC_ERROR_CODES.INVALID_API_KEY, PUBLIC_ERROR_CODES.API_KEY_PROJECT_MISMATCH;
|
|
358
|
+
const MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
359
|
+
const MIN_MULTIPART_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
360
|
+
const REJECTED_UPLOAD_MIME_TYPE_SET = /* @__PURE__ */ new Set([
|
|
361
|
+
"application/octet-stream",
|
|
362
|
+
"multipart/form-data",
|
|
363
|
+
"multipart/mixed",
|
|
364
|
+
"multipart/alternative",
|
|
365
|
+
"multipart/related",
|
|
366
|
+
"multipart/signed",
|
|
367
|
+
"multipart/encrypted"
|
|
368
|
+
]);
|
|
369
|
+
const normalizeUploadMimeType = (mimeType) => {
|
|
370
|
+
var _mimeType$toLowerCase;
|
|
371
|
+
return ((_mimeType$toLowerCase = mimeType.toLowerCase().split(";")[0]) === null || _mimeType$toLowerCase === void 0 ? void 0 : _mimeType$toLowerCase.trim()) || mimeType.toLowerCase().trim();
|
|
372
|
+
};
|
|
373
|
+
const isRejectedUploadMimeType = (mimeType) => REJECTED_UPLOAD_MIME_TYPE_SET.has(normalizeUploadMimeType(mimeType));
|
|
374
|
+
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.`;
|
|
375
|
+
const DOMAIN = "calmlens.com";
|
|
376
|
+
//#endregion
|
|
377
|
+
//#region src/client/CalmLensError.ts
|
|
378
|
+
const SDK_ERRORS = { NO_CDN_FETCH: {
|
|
379
|
+
id: "sdk/no-cdn-fetch",
|
|
380
|
+
defaultMessage: "No fetch implementation is available for CDN requests"
|
|
381
|
+
} };
|
|
382
|
+
var CalmLensError = class extends Error {
|
|
383
|
+
constructor(errorCode, options) {
|
|
384
|
+
var _ref, _options$message;
|
|
385
|
+
const code = "getId" in errorCode ? errorCode.getId() : errorCode.id;
|
|
386
|
+
const defaultMessage = "getDefaultMessage" in errorCode ? errorCode.getDefaultMessage() : errorCode.defaultMessage;
|
|
387
|
+
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 });
|
|
388
|
+
this.name = "CalmLensError";
|
|
389
|
+
this.code = code;
|
|
390
|
+
this.details = options === null || options === void 0 ? void 0 : options.details;
|
|
391
|
+
this.status = options === null || options === void 0 ? void 0 : options.status;
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
const calmLensError = (errorCode, options) => new CalmLensError(errorCode, options);
|
|
395
|
+
//#endregion
|
|
396
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/objectWithoutPropertiesLoose.js
|
|
397
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
398
|
+
if (null == r) return {};
|
|
399
|
+
var t = {};
|
|
400
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
401
|
+
if (e.includes(n)) continue;
|
|
402
|
+
t[n] = r[n];
|
|
403
|
+
}
|
|
404
|
+
return t;
|
|
405
|
+
}
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/objectWithoutProperties.js
|
|
408
|
+
function _objectWithoutProperties(e, t) {
|
|
409
|
+
if (null == e) return {};
|
|
410
|
+
var o, r, i = _objectWithoutPropertiesLoose(e, t);
|
|
411
|
+
if (Object.getOwnPropertySymbols) {
|
|
412
|
+
var s = Object.getOwnPropertySymbols(e);
|
|
413
|
+
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
414
|
+
}
|
|
415
|
+
return i;
|
|
416
|
+
}
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/client/CalmLensUtils.ts
|
|
419
|
+
const _excluded = ["text", "name"];
|
|
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
|
+
//#endregion
|
|
432
|
+
Object.defineProperty(exports, "CalmLensError", {
|
|
433
|
+
enumerable: true,
|
|
434
|
+
get: function() {
|
|
435
|
+
return CalmLensError;
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
Object.defineProperty(exports, "DOMAIN", {
|
|
439
|
+
enumerable: true,
|
|
440
|
+
get: function() {
|
|
441
|
+
return DOMAIN;
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
Object.defineProperty(exports, "MAX_IMAGE_UPLOAD_BYTES", {
|
|
445
|
+
enumerable: true,
|
|
446
|
+
get: function() {
|
|
447
|
+
return MAX_IMAGE_UPLOAD_BYTES;
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
Object.defineProperty(exports, "MIN_MULTIPART_IMAGE_UPLOAD_BYTES", {
|
|
451
|
+
enumerable: true,
|
|
452
|
+
get: function() {
|
|
453
|
+
return MIN_MULTIPART_IMAGE_UPLOAD_BYTES;
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
Object.defineProperty(exports, "PUBLIC_ERROR_CODES", {
|
|
457
|
+
enumerable: true,
|
|
458
|
+
get: function() {
|
|
459
|
+
return PUBLIC_ERROR_CODES;
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
Object.defineProperty(exports, "SDK_ERRORS", {
|
|
463
|
+
enumerable: true,
|
|
464
|
+
get: function() {
|
|
465
|
+
return SDK_ERRORS;
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
Object.defineProperty(exports, "__toESM", {
|
|
469
|
+
enumerable: true,
|
|
470
|
+
get: function() {
|
|
471
|
+
return __toESM;
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
Object.defineProperty(exports, "_asyncToGenerator", {
|
|
475
|
+
enumerable: true,
|
|
476
|
+
get: function() {
|
|
477
|
+
return _asyncToGenerator;
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
Object.defineProperty(exports, "_objectSpread2", {
|
|
481
|
+
enumerable: true,
|
|
482
|
+
get: function() {
|
|
483
|
+
return _objectSpread2;
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
Object.defineProperty(exports, "_objectWithoutProperties", {
|
|
487
|
+
enumerable: true,
|
|
488
|
+
get: function() {
|
|
489
|
+
return _objectWithoutProperties;
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
Object.defineProperty(exports, "assetDataToUint8Array", {
|
|
493
|
+
enumerable: true,
|
|
494
|
+
get: function() {
|
|
495
|
+
return assetDataToUint8Array;
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
Object.defineProperty(exports, "assetToData", {
|
|
499
|
+
enumerable: true,
|
|
500
|
+
get: function() {
|
|
501
|
+
return assetToData;
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
Object.defineProperty(exports, "calmLensError", {
|
|
505
|
+
enumerable: true,
|
|
506
|
+
get: function() {
|
|
507
|
+
return calmLensError;
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
Object.defineProperty(exports, "getAssetPayloadByteLength", {
|
|
511
|
+
enumerable: true,
|
|
512
|
+
get: function() {
|
|
513
|
+
return getAssetPayloadByteLength;
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
Object.defineProperty(exports, "getRawBase64", {
|
|
517
|
+
enumerable: true,
|
|
518
|
+
get: function() {
|
|
519
|
+
return getRawBase64;
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
Object.defineProperty(exports, "getRejectedUploadMimeTypeError", {
|
|
523
|
+
enumerable: true,
|
|
524
|
+
get: function() {
|
|
525
|
+
return getRejectedUploadMimeTypeError;
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
Object.defineProperty(exports, "isRejectedUploadMimeType", {
|
|
529
|
+
enumerable: true,
|
|
530
|
+
get: function() {
|
|
531
|
+
return isRejectedUploadMimeType;
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
Object.defineProperty(exports, "stringifyJsonCanonical", {
|
|
535
|
+
enumerable: true,
|
|
536
|
+
get: function() {
|
|
537
|
+
return stringifyJsonCanonical;
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
Object.defineProperty(exports, "toTextAssetOptions", {
|
|
541
|
+
enumerable: true,
|
|
542
|
+
get: function() {
|
|
543
|
+
return toTextAssetOptions;
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
Object.defineProperty(exports, "validateAssetPayload", {
|
|
547
|
+
enumerable: true,
|
|
548
|
+
get: function() {
|
|
549
|
+
return validateAssetPayload;
|
|
550
|
+
}
|
|
551
|
+
});
|