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,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({
|
|
@@ -272,8 +333,8 @@ const PUBLIC_ERROR_CODES = {
|
|
|
272
333
|
})
|
|
273
334
|
};
|
|
274
335
|
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;
|
|
336
|
+
const MAX_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 20971520)();
|
|
337
|
+
const MIN_MULTIPART_IMAGE_UPLOAD_BYTES = /* @__PURE__ */ (() => 10485760)();
|
|
277
338
|
const REJECTED_UPLOAD_MIME_TYPE_SET = /* @__PURE__ */ new Set([
|
|
278
339
|
"application/octet-stream",
|
|
279
340
|
"multipart/form-data",
|
|
@@ -301,10 +362,11 @@ var CalmLensError = class extends Error {
|
|
|
301
362
|
var _ref, _options$message;
|
|
302
363
|
const code = "getId" in errorCode ? errorCode.getId() : errorCode.id;
|
|
303
364
|
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}
|
|
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 });
|
|
305
366
|
this.name = "CalmLensError";
|
|
306
367
|
this.code = code;
|
|
307
368
|
this.details = options === null || options === void 0 ? void 0 : options.details;
|
|
369
|
+
this.status = options === null || options === void 0 ? void 0 : options.status;
|
|
308
370
|
}
|
|
309
371
|
};
|
|
310
372
|
const calmLensError = (errorCode, options) => new CalmLensError(errorCode, options);
|
|
@@ -331,73 +393,11 @@ function _objectWithoutProperties(e, t) {
|
|
|
331
393
|
return i;
|
|
332
394
|
}
|
|
333
395
|
//#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
396
|
//#region src/client/CalmLensUtils.ts
|
|
396
397
|
const _excluded = ["text", "name"];
|
|
397
|
-
/** Converts `text.moderate()` options into a plain-text asset submission. */
|
|
398
398
|
const toTextAssetOptions = (_ref) => {
|
|
399
399
|
let { text, name } = _ref, options = _objectWithoutProperties(_ref, _excluded);
|
|
400
|
-
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" });
|
|
401
401
|
return _objectSpread2(_objectSpread2({}, options), {}, {
|
|
402
402
|
name: name !== null && name !== void 0 ? name : "text",
|
|
403
403
|
content: {
|
|
@@ -406,25 +406,5 @@ const toTextAssetOptions = (_ref) => {
|
|
|
406
406
|
}
|
|
407
407
|
});
|
|
408
408
|
};
|
|
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
409
|
//#endregion
|
|
430
|
-
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 };
|