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.
@@ -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 size for images is 10MB, for other files is 5GB.",
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().length === 0) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Text to moderate must be a non-empty string" });
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 { getAssetPayloadByteLength as _, CalmLensError as a, _asyncToGenerator as b, DOMAIN as c, getRejectedUploadMimeTypeError as d, isRejectedUploadMimeType as f, assetToData as g, assetDataToUint8Array as h, _objectWithoutProperties as i, MAX_IMAGE_UPLOAD_BYTES as l, stringifyJsonCanonical as m, verifyWebhookSignature as n, SDK_ERRORS as o, PUBLIC_ERROR_CODES as p, _objectSpread2 as r, calmLensError as s, toTextAssetOptions as t, MIN_MULTIPART_IMAGE_UPLOAD_BYTES as u, getRawBase64 as v, validateAssetPayload as y };
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 };