calmlens 0.3.1 → 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 +72 -39
- package/bin/calmlens.js +240 -79
- package/cjs/CalmLensTypes-DG_kHVqY.d.ts +3521 -0
- package/cjs/{CalmLensUtils-DocJkqQj.js → CalmLensUtils-0QaxbI3A.js} +105 -93
- package/cjs/index.d.ts +2607 -24
- package/cjs/index.js +548 -120
- package/cjs/testing.d.ts +3 -2
- package/cjs/testing.js +39 -45
- package/esm/CalmLensTypes-DG_kHVqY.d.ts +3521 -0
- package/esm/{CalmLensUtils--N_91gHC.js → CalmLensUtils-BQEgxGWk.js} +78 -88
- package/esm/index.d.ts +2607 -24
- package/esm/index.js +541 -120
- package/esm/testing.d.ts +3 -2
- package/esm/testing.js +38 -22
- package/package.json +2 -2
- package/cjs/CalmLensTypes-Bnq4u8HJ.d.ts +0 -1758
- package/esm/CalmLensTypes-Bnq4u8HJ.d.ts +0 -1758
|
@@ -1,4 +1,65 @@
|
|
|
1
1
|
import { ErrorCode } from "sendable-error";
|
|
2
|
+
//#region \0@oxc-project+runtime@0.148.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.148.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.148.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.148.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.148.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
|
|
2
63
|
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/asyncToGenerator.js
|
|
3
64
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
4
65
|
try {
|
|
@@ -142,7 +203,7 @@ const PUBLIC_ERROR_CODES = {
|
|
|
142
203
|
}),
|
|
143
204
|
FILE_TOO_LARGE: new ErrorCode({
|
|
144
205
|
id: "upload/file-too-large",
|
|
145
|
-
defaultMessage: "File size exceeds limit. Maximum
|
|
206
|
+
defaultMessage: "File size exceeds limit. Maximum direct image size is 10MB, audio/video size is 50MiB, and other files is 5GB.",
|
|
146
207
|
status: 400
|
|
147
208
|
}),
|
|
148
209
|
IMAGE_REQUIRES_MULTIPART_UPLOAD: new ErrorCode({
|
|
@@ -225,6 +286,16 @@ const PUBLIC_ERROR_CODES = {
|
|
|
225
286
|
defaultMessage: "Asset access is restricted by a safety hold.",
|
|
226
287
|
status: 423
|
|
227
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
|
+
}),
|
|
228
299
|
SUPPORT_TICKET_NOT_FOUND: new ErrorCode({
|
|
229
300
|
id: "support/ticket-not-found",
|
|
230
301
|
defaultMessage: "Support ticket not found.",
|
|
@@ -262,8 +333,8 @@ const PUBLIC_ERROR_CODES = {
|
|
|
262
333
|
})
|
|
263
334
|
};
|
|
264
335
|
PUBLIC_ERROR_CODES.MISSING_TOKEN, PUBLIC_ERROR_CODES.INVALID_API_KEY, PUBLIC_ERROR_CODES.API_KEY_PROJECT_MISMATCH;
|
|
265
|
-
const MAX_IMAGE_UPLOAD_BYTES = 20971520;
|
|
266
|
-
const MIN_MULTIPART_IMAGE_UPLOAD_BYTES = 10485760;
|
|
336
|
+
const MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
337
|
+
const MIN_MULTIPART_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
267
338
|
const REJECTED_UPLOAD_MIME_TYPE_SET = /* @__PURE__ */ new Set([
|
|
268
339
|
"application/octet-stream",
|
|
269
340
|
"multipart/form-data",
|
|
@@ -291,10 +362,11 @@ var CalmLensError = class extends Error {
|
|
|
291
362
|
var _ref, _options$message;
|
|
292
363
|
const code = "getId" in errorCode ? errorCode.getId() : errorCode.id;
|
|
293
364
|
const defaultMessage = "getDefaultMessage" in errorCode ? errorCode.getDefaultMessage() : errorCode.defaultMessage;
|
|
294
|
-
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}
|
|
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 });
|
|
295
366
|
this.name = "CalmLensError";
|
|
296
367
|
this.code = code;
|
|
297
368
|
this.details = options === null || options === void 0 ? void 0 : options.details;
|
|
369
|
+
this.status = options === null || options === void 0 ? void 0 : options.status;
|
|
298
370
|
}
|
|
299
371
|
};
|
|
300
372
|
const calmLensError = (errorCode, options) => new CalmLensError(errorCode, options);
|
|
@@ -321,73 +393,11 @@ function _objectWithoutProperties(e, t) {
|
|
|
321
393
|
return i;
|
|
322
394
|
}
|
|
323
395
|
//#endregion
|
|
324
|
-
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/typeof.js
|
|
325
|
-
function _typeof(o) {
|
|
326
|
-
"@babel/helpers - typeof";
|
|
327
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
328
|
-
return typeof o;
|
|
329
|
-
} : function(o) {
|
|
330
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
331
|
-
}, _typeof(o);
|
|
332
|
-
}
|
|
333
|
-
//#endregion
|
|
334
|
-
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPrimitive.js
|
|
335
|
-
function toPrimitive(t, r) {
|
|
336
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
337
|
-
var e = t[Symbol.toPrimitive];
|
|
338
|
-
if (void 0 !== e) {
|
|
339
|
-
var i = e.call(t, r || "default");
|
|
340
|
-
if ("object" != _typeof(i)) return i;
|
|
341
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
342
|
-
}
|
|
343
|
-
return ("string" === r ? String : Number)(t);
|
|
344
|
-
}
|
|
345
|
-
//#endregion
|
|
346
|
-
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPropertyKey.js
|
|
347
|
-
function toPropertyKey(t) {
|
|
348
|
-
var i = toPrimitive(t, "string");
|
|
349
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
350
|
-
}
|
|
351
|
-
//#endregion
|
|
352
|
-
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/defineProperty.js
|
|
353
|
-
function _defineProperty(e, r, t) {
|
|
354
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
355
|
-
value: t,
|
|
356
|
-
enumerable: !0,
|
|
357
|
-
configurable: !0,
|
|
358
|
-
writable: !0
|
|
359
|
-
}) : e[r] = t, e;
|
|
360
|
-
}
|
|
361
|
-
//#endregion
|
|
362
|
-
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/objectSpread2.js
|
|
363
|
-
function ownKeys(e, r) {
|
|
364
|
-
var t = Object.keys(e);
|
|
365
|
-
if (Object.getOwnPropertySymbols) {
|
|
366
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
367
|
-
r && (o = o.filter(function(r) {
|
|
368
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
369
|
-
})), t.push.apply(t, o);
|
|
370
|
-
}
|
|
371
|
-
return t;
|
|
372
|
-
}
|
|
373
|
-
function _objectSpread2(e) {
|
|
374
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
375
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
376
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
377
|
-
_defineProperty(e, r, t[r]);
|
|
378
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
379
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
return e;
|
|
383
|
-
}
|
|
384
|
-
//#endregion
|
|
385
396
|
//#region src/client/CalmLensUtils.ts
|
|
386
397
|
const _excluded = ["text", "name"];
|
|
387
|
-
/** Converts `text.moderate()` options into a plain-text asset submission. */
|
|
388
398
|
const toTextAssetOptions = (_ref) => {
|
|
389
399
|
let { text, name } = _ref, options = _objectWithoutProperties(_ref, _excluded);
|
|
390
|
-
if (typeof text !== "string" || text.trim()
|
|
400
|
+
if (typeof text !== "string" || !text.trim()) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Text to moderate must be a non-empty string" });
|
|
391
401
|
return _objectSpread2(_objectSpread2({}, options), {}, {
|
|
392
402
|
name: name !== null && name !== void 0 ? name : "text",
|
|
393
403
|
content: {
|
|
@@ -396,25 +406,5 @@ const toTextAssetOptions = (_ref) => {
|
|
|
396
406
|
}
|
|
397
407
|
});
|
|
398
408
|
};
|
|
399
|
-
function verifyWebhookSignature(_x) {
|
|
400
|
-
return _verifyWebhookSignature.apply(this, arguments);
|
|
401
|
-
}
|
|
402
|
-
function _verifyWebhookSignature() {
|
|
403
|
-
_verifyWebhookSignature = _asyncToGenerator(function* ({ payload, signatureHex, secret }) {
|
|
404
|
-
const encoder = new TextEncoder();
|
|
405
|
-
const normalizePayload = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
406
|
-
const key = yield crypto.subtle.importKey("raw", encoder.encode(secret), {
|
|
407
|
-
name: "HMAC",
|
|
408
|
-
hash: "SHA-256"
|
|
409
|
-
}, false, ["sign"]);
|
|
410
|
-
const sig = yield crypto.subtle.sign("HMAC", key, encoder.encode(normalizePayload));
|
|
411
|
-
const hex = Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
412
|
-
if (hex.length !== signatureHex.length) return false;
|
|
413
|
-
let diff = 0;
|
|
414
|
-
for (let i = 0; i < hex.length; i++) diff |= hex.charCodeAt(i) ^ signatureHex.charCodeAt(i);
|
|
415
|
-
return diff === 0;
|
|
416
|
-
});
|
|
417
|
-
return _verifyWebhookSignature.apply(this, arguments);
|
|
418
|
-
}
|
|
419
409
|
//#endregion
|
|
420
|
-
export {
|
|
410
|
+
export { validateAssetPayload as _, calmLensError as a, MIN_MULTIPART_IMAGE_UPLOAD_BYTES as c, PUBLIC_ERROR_CODES as d, stringifyJsonCanonical as f, getRawBase64 as g, getAssetPayloadByteLength as h, SDK_ERRORS as i, getRejectedUploadMimeTypeError as l, assetToData as m, _objectWithoutProperties as n, DOMAIN as o, assetDataToUint8Array as p, CalmLensError as r, MAX_IMAGE_UPLOAD_BYTES as s, toTextAssetOptions as t, isRejectedUploadMimeType as u, _asyncToGenerator as v, _objectSpread2 as y };
|