calmlens 0.4.0 → 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 +61 -39
- package/bin/calmlens.js +217 -80
- package/cjs/CalmLensTypes-DG_kHVqY.d.ts +3521 -0
- package/cjs/{CalmLensUtils-CjdO9v--.js → CalmLensUtils-0QaxbI3A.js} +95 -93
- package/cjs/index.d.ts +2602 -24
- package/cjs/index.js +533 -124
- package/cjs/testing.d.ts +2 -2
- package/cjs/testing.js +6 -27
- package/esm/CalmLensTypes-DG_kHVqY.d.ts +3521 -0
- package/esm/{CalmLensUtils-B3Eiz2Ro.js → CalmLensUtils-BQEgxGWk.js} +68 -88
- package/esm/index.d.ts +2602 -24
- package/esm/index.js +526 -124
- package/esm/testing.d.ts +2 -2
- package/esm/testing.js +5 -4
- package/package.json +2 -2
- package/cjs/CalmLensTypes-DkqoKBwF.d.ts +0 -1761
- package/esm/CalmLensTypes-DkqoKBwF.d.ts +0 -1761
|
@@ -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({
|
|
@@ -272,8 +355,8 @@ const PUBLIC_ERROR_CODES = {
|
|
|
272
355
|
})
|
|
273
356
|
};
|
|
274
357
|
PUBLIC_ERROR_CODES.MISSING_TOKEN, PUBLIC_ERROR_CODES.INVALID_API_KEY, PUBLIC_ERROR_CODES.API_KEY_PROJECT_MISMATCH;
|
|
275
|
-
const MAX_IMAGE_UPLOAD_BYTES = 20971520;
|
|
276
|
-
const MIN_MULTIPART_IMAGE_UPLOAD_BYTES = 10485760;
|
|
358
|
+
const MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
359
|
+
const MIN_MULTIPART_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
277
360
|
const REJECTED_UPLOAD_MIME_TYPE_SET = /* @__PURE__ */ new Set([
|
|
278
361
|
"application/octet-stream",
|
|
279
362
|
"multipart/form-data",
|
|
@@ -301,10 +384,11 @@ var CalmLensError = class extends Error {
|
|
|
301
384
|
var _ref, _options$message;
|
|
302
385
|
const code = "getId" in errorCode ? errorCode.getId() : errorCode.id;
|
|
303
386
|
const defaultMessage = "getDefaultMessage" in errorCode ? errorCode.getDefaultMessage() : errorCode.defaultMessage;
|
|
304
|
-
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 });
|
|
305
388
|
this.name = "CalmLensError";
|
|
306
389
|
this.code = code;
|
|
307
390
|
this.details = options === null || options === void 0 ? void 0 : options.details;
|
|
391
|
+
this.status = options === null || options === void 0 ? void 0 : options.status;
|
|
308
392
|
}
|
|
309
393
|
};
|
|
310
394
|
const calmLensError = (errorCode, options) => new CalmLensError(errorCode, options);
|
|
@@ -331,73 +415,11 @@ function _objectWithoutProperties(e, t) {
|
|
|
331
415
|
return i;
|
|
332
416
|
}
|
|
333
417
|
//#endregion
|
|
334
|
-
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/typeof.js
|
|
335
|
-
function _typeof(o) {
|
|
336
|
-
"@babel/helpers - typeof";
|
|
337
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
338
|
-
return typeof o;
|
|
339
|
-
} : function(o) {
|
|
340
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
341
|
-
}, _typeof(o);
|
|
342
|
-
}
|
|
343
|
-
//#endregion
|
|
344
|
-
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPrimitive.js
|
|
345
|
-
function toPrimitive(t, r) {
|
|
346
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
347
|
-
var e = t[Symbol.toPrimitive];
|
|
348
|
-
if (void 0 !== e) {
|
|
349
|
-
var i = e.call(t, r || "default");
|
|
350
|
-
if ("object" != _typeof(i)) return i;
|
|
351
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
352
|
-
}
|
|
353
|
-
return ("string" === r ? String : Number)(t);
|
|
354
|
-
}
|
|
355
|
-
//#endregion
|
|
356
|
-
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPropertyKey.js
|
|
357
|
-
function toPropertyKey(t) {
|
|
358
|
-
var i = toPrimitive(t, "string");
|
|
359
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
360
|
-
}
|
|
361
|
-
//#endregion
|
|
362
|
-
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/defineProperty.js
|
|
363
|
-
function _defineProperty(e, r, t) {
|
|
364
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
365
|
-
value: t,
|
|
366
|
-
enumerable: !0,
|
|
367
|
-
configurable: !0,
|
|
368
|
-
writable: !0
|
|
369
|
-
}) : e[r] = t, e;
|
|
370
|
-
}
|
|
371
|
-
//#endregion
|
|
372
|
-
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/objectSpread2.js
|
|
373
|
-
function ownKeys(e, r) {
|
|
374
|
-
var t = Object.keys(e);
|
|
375
|
-
if (Object.getOwnPropertySymbols) {
|
|
376
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
377
|
-
r && (o = o.filter(function(r) {
|
|
378
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
379
|
-
})), t.push.apply(t, o);
|
|
380
|
-
}
|
|
381
|
-
return t;
|
|
382
|
-
}
|
|
383
|
-
function _objectSpread2(e) {
|
|
384
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
385
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
386
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
387
|
-
_defineProperty(e, r, t[r]);
|
|
388
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
389
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
return e;
|
|
393
|
-
}
|
|
394
|
-
//#endregion
|
|
395
418
|
//#region src/client/CalmLensUtils.ts
|
|
396
419
|
const _excluded = ["text", "name"];
|
|
397
|
-
/** Converts `text.moderate()` options into a plain-text asset submission. */
|
|
398
420
|
const toTextAssetOptions = (_ref) => {
|
|
399
421
|
let { text, name } = _ref, options = _objectWithoutProperties(_ref, _excluded);
|
|
400
|
-
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" });
|
|
401
423
|
return _objectSpread2(_objectSpread2({}, options), {}, {
|
|
402
424
|
name: name !== null && name !== void 0 ? name : "text",
|
|
403
425
|
content: {
|
|
@@ -406,26 +428,6 @@ const toTextAssetOptions = (_ref) => {
|
|
|
406
428
|
}
|
|
407
429
|
});
|
|
408
430
|
};
|
|
409
|
-
function verifyWebhookSignature(_x) {
|
|
410
|
-
return _verifyWebhookSignature.apply(this, arguments);
|
|
411
|
-
}
|
|
412
|
-
function _verifyWebhookSignature() {
|
|
413
|
-
_verifyWebhookSignature = _asyncToGenerator(function* ({ payload, signatureHex, secret }) {
|
|
414
|
-
const encoder = new TextEncoder();
|
|
415
|
-
const normalizePayload = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
416
|
-
const key = yield crypto.subtle.importKey("raw", encoder.encode(secret), {
|
|
417
|
-
name: "HMAC",
|
|
418
|
-
hash: "SHA-256"
|
|
419
|
-
}, false, ["sign"]);
|
|
420
|
-
const sig = yield crypto.subtle.sign("HMAC", key, encoder.encode(normalizePayload));
|
|
421
|
-
const hex = Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
422
|
-
if (hex.length !== signatureHex.length) return false;
|
|
423
|
-
let diff = 0;
|
|
424
|
-
for (let i = 0; i < hex.length; i++) diff |= hex.charCodeAt(i) ^ signatureHex.charCodeAt(i);
|
|
425
|
-
return diff === 0;
|
|
426
|
-
});
|
|
427
|
-
return _verifyWebhookSignature.apply(this, arguments);
|
|
428
|
-
}
|
|
429
431
|
//#endregion
|
|
430
432
|
Object.defineProperty(exports, "CalmLensError", {
|
|
431
433
|
enumerable: true,
|
|
@@ -463,6 +465,12 @@ Object.defineProperty(exports, "SDK_ERRORS", {
|
|
|
463
465
|
return SDK_ERRORS;
|
|
464
466
|
}
|
|
465
467
|
});
|
|
468
|
+
Object.defineProperty(exports, "__toESM", {
|
|
469
|
+
enumerable: true,
|
|
470
|
+
get: function() {
|
|
471
|
+
return __toESM;
|
|
472
|
+
}
|
|
473
|
+
});
|
|
466
474
|
Object.defineProperty(exports, "_asyncToGenerator", {
|
|
467
475
|
enumerable: true,
|
|
468
476
|
get: function() {
|
|
@@ -541,9 +549,3 @@ Object.defineProperty(exports, "validateAssetPayload", {
|
|
|
541
549
|
return validateAssetPayload;
|
|
542
550
|
}
|
|
543
551
|
});
|
|
544
|
-
Object.defineProperty(exports, "verifyWebhookSignature", {
|
|
545
|
-
enumerable: true,
|
|
546
|
-
get: function() {
|
|
547
|
-
return verifyWebhookSignature;
|
|
548
|
-
}
|
|
549
|
-
});
|