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,87 @@
|
|
|
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
|
|
1
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
|
|
2
85
|
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/asyncToGenerator.js
|
|
3
86
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
4
87
|
try {
|
|
@@ -142,7 +225,7 @@ const PUBLIC_ERROR_CODES = {
|
|
|
142
225
|
}),
|
|
143
226
|
FILE_TOO_LARGE: new sendable_error.ErrorCode({
|
|
144
227
|
id: "upload/file-too-large",
|
|
145
|
-
defaultMessage: "File size exceeds limit. Maximum
|
|
228
|
+
defaultMessage: "File size exceeds limit. Maximum direct image size is 10MB, audio/video size is 50MiB, and other files is 5GB.",
|
|
146
229
|
status: 400
|
|
147
230
|
}),
|
|
148
231
|
IMAGE_REQUIRES_MULTIPART_UPLOAD: new sendable_error.ErrorCode({
|
|
@@ -225,6 +308,16 @@ const PUBLIC_ERROR_CODES = {
|
|
|
225
308
|
defaultMessage: "Asset access is restricted by a safety hold.",
|
|
226
309
|
status: 423
|
|
227
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
|
+
}),
|
|
228
321
|
SUPPORT_TICKET_NOT_FOUND: new sendable_error.ErrorCode({
|
|
229
322
|
id: "support/ticket-not-found",
|
|
230
323
|
defaultMessage: "Support ticket not found.",
|
|
@@ -262,8 +355,8 @@ const PUBLIC_ERROR_CODES = {
|
|
|
262
355
|
})
|
|
263
356
|
};
|
|
264
357
|
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;
|
|
358
|
+
const MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
359
|
+
const MIN_MULTIPART_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
267
360
|
const REJECTED_UPLOAD_MIME_TYPE_SET = /* @__PURE__ */ new Set([
|
|
268
361
|
"application/octet-stream",
|
|
269
362
|
"multipart/form-data",
|
|
@@ -291,10 +384,11 @@ var CalmLensError = class extends Error {
|
|
|
291
384
|
var _ref, _options$message;
|
|
292
385
|
const code = "getId" in errorCode ? errorCode.getId() : errorCode.id;
|
|
293
386
|
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}
|
|
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 });
|
|
295
388
|
this.name = "CalmLensError";
|
|
296
389
|
this.code = code;
|
|
297
390
|
this.details = options === null || options === void 0 ? void 0 : options.details;
|
|
391
|
+
this.status = options === null || options === void 0 ? void 0 : options.status;
|
|
298
392
|
}
|
|
299
393
|
};
|
|
300
394
|
const calmLensError = (errorCode, options) => new CalmLensError(errorCode, options);
|
|
@@ -321,73 +415,11 @@ function _objectWithoutProperties(e, t) {
|
|
|
321
415
|
return i;
|
|
322
416
|
}
|
|
323
417
|
//#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
418
|
//#region src/client/CalmLensUtils.ts
|
|
386
419
|
const _excluded = ["text", "name"];
|
|
387
|
-
/** Converts `text.moderate()` options into a plain-text asset submission. */
|
|
388
420
|
const toTextAssetOptions = (_ref) => {
|
|
389
421
|
let { text, name } = _ref, options = _objectWithoutProperties(_ref, _excluded);
|
|
390
|
-
if (typeof text !== "string" || text.trim()
|
|
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" });
|
|
391
423
|
return _objectSpread2(_objectSpread2({}, options), {}, {
|
|
392
424
|
name: name !== null && name !== void 0 ? name : "text",
|
|
393
425
|
content: {
|
|
@@ -396,26 +428,6 @@ const toTextAssetOptions = (_ref) => {
|
|
|
396
428
|
}
|
|
397
429
|
});
|
|
398
430
|
};
|
|
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
431
|
//#endregion
|
|
420
432
|
Object.defineProperty(exports, "CalmLensError", {
|
|
421
433
|
enumerable: true,
|
|
@@ -453,6 +465,12 @@ Object.defineProperty(exports, "SDK_ERRORS", {
|
|
|
453
465
|
return SDK_ERRORS;
|
|
454
466
|
}
|
|
455
467
|
});
|
|
468
|
+
Object.defineProperty(exports, "__toESM", {
|
|
469
|
+
enumerable: true,
|
|
470
|
+
get: function() {
|
|
471
|
+
return __toESM;
|
|
472
|
+
}
|
|
473
|
+
});
|
|
456
474
|
Object.defineProperty(exports, "_asyncToGenerator", {
|
|
457
475
|
enumerable: true,
|
|
458
476
|
get: function() {
|
|
@@ -531,9 +549,3 @@ Object.defineProperty(exports, "validateAssetPayload", {
|
|
|
531
549
|
return validateAssetPayload;
|
|
532
550
|
}
|
|
533
551
|
});
|
|
534
|
-
Object.defineProperty(exports, "verifyWebhookSignature", {
|
|
535
|
-
enumerable: true,
|
|
536
|
-
get: function() {
|
|
537
|
-
return verifyWebhookSignature;
|
|
538
|
-
}
|
|
539
|
-
});
|