calmlens 0.18.3 → 0.20.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.
Files changed (82) hide show
  1. package/bin/calmlens.js +5682 -5036
  2. package/cjs/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-C07aL9Vq.d.ts} +2 -2
  3. package/cjs/{BrowserUpload-UxIAGNdv.js → BrowserUpload-CjSHjx3C.js} +1 -1
  4. package/{esm/CalmLensAppClient-CV_K26Ce.d.ts → cjs/CalmLensAppClient-DDLojj0P.d.ts} +3 -3
  5. package/cjs/{CalmLensAppClient-D6p7MAFz.js → CalmLensAppClient-NaCxOVlM.js} +32 -11
  6. package/cjs/{CalmLensConnection-CYoUl5go.js → CalmLensOptionKeys-p2QK687A.js} +430 -9
  7. package/cjs/{CalmLensServerClient-p23cl97D.js → CalmLensServerClient-BDzTthxE.js} +173 -55
  8. package/cjs/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-C-jsjn8m.d.ts} +54 -30
  9. package/cjs/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-COJbOuiv.d.ts} +2677 -30
  10. package/cjs/{ModerationContextLimits-DCLXMxyA.js → ModerationContextLimits-2nIv7Zh3.js} +495 -49
  11. package/cjs/{ReactUpload-BcdNWLiU.js → ReactUpload-BdTRCTGA.js} +1 -1
  12. package/cjs/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-CRJNPB5T.d.ts} +1 -1
  13. package/{esm/TestTriggers-By07LR31-CmK0yTyR.d.ts → cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
  14. package/cjs/{TestTriggers-DTc_iMJF-BjMPq4_3.js → TestTriggers-DbhsNPdg-DjvVuc2h.js} +434 -74
  15. package/cjs/{UploadController-Cxu0bufo.js → UploadController-MLVs97Zt.js} +17 -5
  16. package/{esm/WebhookPayload-2aL31v0J.d.ts → cjs/WebhookPayload-DkukERKE.d.ts} +29 -3
  17. package/cjs/app.d.ts +6 -6
  18. package/cjs/app.js +2 -2
  19. package/cjs/elements.d.ts +3 -3
  20. package/cjs/elements.js +3 -3
  21. package/cjs/{index-CI4BzN4W.d.ts → index-DxbJ_Xaa.d.ts} +7 -6
  22. package/cjs/index.d.ts +5 -5
  23. package/cjs/index.js +1 -1
  24. package/cjs/react-native.d.ts +3 -3
  25. package/cjs/react-native.js +3 -3
  26. package/cjs/react.d.ts +3 -3
  27. package/cjs/react.js +4 -4
  28. package/cjs/server.d.ts +6 -6
  29. package/cjs/server.js +2 -2
  30. package/cjs/test-inputs.d.ts +1 -1
  31. package/cjs/test-inputs.js +9 -9
  32. package/cjs/testing.d.ts +12 -8
  33. package/cjs/testing.js +298 -35
  34. package/{esm/ui-wIiMfqMB.d.ts → cjs/ui-BSqPGKrZ.d.ts} +17 -4
  35. package/cjs/{ui-C0XXJS52.js → ui-CX1z2pD9.js} +13 -10
  36. package/cjs/ui.d.ts +2 -2
  37. package/cjs/ui.js +2 -2
  38. package/cjs/vue.d.ts +5 -5
  39. package/cjs/vue.js +3 -3
  40. package/esm/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-C07aL9Vq.d.ts} +2 -2
  41. package/esm/{BrowserUpload-BXG2isHV.js → BrowserUpload-CAVkRotw.js} +1 -1
  42. package/{cjs/CalmLensAppClient-CV_K26Ce.d.ts → esm/CalmLensAppClient-DDLojj0P.d.ts} +3 -3
  43. package/esm/{CalmLensAppClient-BMgXamoN.js → CalmLensAppClient-PQ9VBvlW.js} +28 -7
  44. package/esm/{CalmLensConnection-DBoDh06c.js → CalmLensOptionKeys-Do2mPP6w.js} +407 -10
  45. package/esm/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-C-jsjn8m.d.ts} +54 -30
  46. package/esm/{CalmLensServerClient-Dt7rCITa.js → CalmLensServerClient-C_H5aAsV.js} +165 -47
  47. package/esm/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-COJbOuiv.d.ts} +2677 -30
  48. package/esm/{ModerationContextLimits-KMQ8puoa.js → ModerationContextLimits-Chw-AzgL.js} +462 -46
  49. package/esm/{ReactUpload-CFy_wETY.js → ReactUpload-CMmL0R5Q.js} +1 -1
  50. package/esm/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-CRJNPB5T.d.ts} +1 -1
  51. package/{cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts → esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
  52. package/esm/{TestTriggers-DTc_iMJF-HfB533Gx.js → TestTriggers-DbhsNPdg-CUdrv8Nm.js} +405 -72
  53. package/esm/{UploadController-Cs-bxUbt.js → UploadController-BJZghJpg.js} +17 -5
  54. package/{cjs/WebhookPayload-2aL31v0J.d.ts → esm/WebhookPayload-DkukERKE.d.ts} +29 -3
  55. package/esm/app.d.ts +6 -6
  56. package/esm/app.js +2 -2
  57. package/esm/elements.d.ts +3 -3
  58. package/esm/elements.js +3 -3
  59. package/esm/{index-CI4BzN4W.d.ts → index-DxbJ_Xaa.d.ts} +7 -6
  60. package/esm/index.d.ts +5 -5
  61. package/esm/index.js +1 -1
  62. package/esm/react-native.d.ts +3 -3
  63. package/esm/react-native.js +3 -3
  64. package/esm/react.d.ts +3 -3
  65. package/esm/react.js +4 -4
  66. package/esm/server.d.ts +6 -6
  67. package/esm/server.js +2 -2
  68. package/esm/test-inputs.d.ts +1 -1
  69. package/esm/test-inputs.js +1 -1
  70. package/esm/testing.d.ts +12 -8
  71. package/esm/testing.js +287 -23
  72. package/{cjs/ui-wIiMfqMB.d.ts → esm/ui-BSqPGKrZ.d.ts} +17 -4
  73. package/esm/{ui-BqYkISSE.js → ui-CXH7xJpb.js} +12 -9
  74. package/esm/ui.d.ts +2 -2
  75. package/esm/ui.js +2 -2
  76. package/esm/vue.d.ts +5 -5
  77. package/esm/vue.js +3 -3
  78. package/package.json +1 -1
  79. package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +0 -91
  80. package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +0 -46
  81. /package/cjs/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
  82. /package/esm/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
@@ -1,9 +1,5 @@
1
- import { A as invalidArgument, C as MAX_IMAGE_UPLOAD_BYTES, E as isRejectedUploadMimeType, M as API_ERROR_CODES, O as CalmLensError, T as getRejectedUploadMimeTypeError, a as getUserAgent, f as randomUuid, k as SDK_ERROR_CODES, m as stringifyQuery, o as isBrowserRuntime, r as selectModerationContextItems, w as MIN_MULTIPART_IMAGE_UPLOAD_BYTES } from "./ModerationContextLimits-KMQ8puoa.js";
1
+ import { A as MAX_NON_IMAGE_UPLOAD_BYTES, F as invalidArgument, L as API_ERROR_CODES, N as CalmLensError, O as MAX_DIRECT_IMAGE_UPLOAD_BYTES, P as SDK_ERROR_CODES, a as getUserAgent, g as randomUuid, j as getRejectedUploadMimeTypeError, k as MAX_IMAGE_UPLOAD_BYTES, o as isBrowserRuntime, p as isAcceptedUploadMimeType, r as selectModerationContextItems, v as stringifyQuery } from "./ModerationContextLimits-Chw-AzgL.js";
2
2
  // src/contract/AssetPayload.js
3
- const uint8ArrayInputToNumbers = (value) => {
4
- if (Array.isArray(value)) return value;
5
- return Array.from(value);
6
- };
7
3
  const bufferInputToBytes = (value) => {
8
4
  if (value instanceof ArrayBuffer) return new Uint8Array(value);
9
5
  return Uint8Array.from(value);
@@ -31,7 +27,7 @@ const assetToData = (payload) => {
31
27
  if (payload.buffer instanceof ArrayBuffer) return payload.buffer;
32
28
  return bufferInputToBytes(payload.buffer);
33
29
  }
34
- if (payload.uint8Array !== void 0) return Uint8Array.from(uint8ArrayInputToNumbers(payload.uint8Array));
30
+ if (payload.uint8Array !== void 0) return Uint8Array.from(payload.uint8Array);
35
31
  if (payload.base64 === void 0) throw new Error("Invalid asset payload");
36
32
  const raw = getRawBase64(payload.base64);
37
33
  if (typeof Buffer !== "undefined") return Uint8Array.from(Buffer.from(raw, "base64"));
@@ -80,6 +76,9 @@ const validateAssetPayload = (payload, options) => {
80
76
  };
81
77
  return { ok: true };
82
78
  };
79
+ // src/contract/Media.js
80
+ /** Limits shared with the media decoder. Oversized clips fail; they are never truncated. */
81
+ const MAX_MEDIA_UPLOAD_BYTES = 52428800;
83
82
  const RETRY_MAX_DELAY_MS = 8e3;
84
83
  const RETRYABLE_STATUSES = /* @__PURE__ */ new Set([
85
84
  429,
@@ -366,6 +365,41 @@ var CalmLensTransport = class {
366
365
  const MOCK_HOOKS = Symbol.for("@calmlens/sdk.mockHooks");
367
366
  /** The mock hooks in client options, if a mock client set them. */
368
367
  const getMockHooks = (options) => options[MOCK_HOOKS];
368
+ /** Content larger than this is uploaded in parts of this size (`partSizeBytes`). */
369
+ const DEFAULT_PART_SIZE_BYTES = 8388608;
370
+ /**
371
+ * The size of content the client can split, read again and resend: bytes, base64 and Blobs.
372
+ * Streams and Responses can be read only once, and text stays one request.
373
+ */
374
+ const getSplittableContent = (content) => {
375
+ if ("plainText" in content && content.plainText !== void 0) return void 0;
376
+ if ("data" in content && content.data !== void 0) {
377
+ const { data } = content;
378
+ if (!(data instanceof Blob)) return void 0;
379
+ return {
380
+ size: data.size,
381
+ slice: (start, end) => ({ data: data.slice(start, end) })
382
+ };
383
+ }
384
+ const size = getAssetPayloadByteLength(content);
385
+ if (size === void 0) return void 0;
386
+ let bytes;
387
+ return {
388
+ size,
389
+ slice: (start, end) => {
390
+ if (!bytes) {
391
+ const data = assetToData(content);
392
+ bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
393
+ }
394
+ return { uint8Array: bytes.subarray(start, end) };
395
+ }
396
+ };
397
+ };
398
+ /** Whether `content` goes in parts: its size is known, it can be resent, and it's over a part. */
399
+ const splitsIntoParts = (content, partSizeBytes) => {
400
+ const splittable = getSplittableContent(content);
401
+ return splittable !== void 0 && splittable.size > partSizeBytes;
402
+ };
369
403
  /**
370
404
  * Bytes as a fetch body. They're sent as they are rather than in a Blob: React Native can't
371
405
  * build a Blob from bytes, and every fetch accepts a Uint8Array.
@@ -385,7 +419,7 @@ const setOptionalQueryValue = (params, key, value) => {
385
419
  if (value !== void 0 && value !== null) params.set(key, typeof value === "string" ? value : JSON.stringify(value));
386
420
  };
387
421
  const assertValidUploadMimeType = (mimeType) => {
388
- if (isRejectedUploadMimeType(mimeType)) throw new CalmLensError(API_ERROR_CODES.INVALID_UPLOAD_MIME_TYPE, {
422
+ if (!isAcceptedUploadMimeType(mimeType)) throw new CalmLensError(API_ERROR_CODES.INVALID_UPLOAD_MIME_TYPE, {
389
423
  message: getRejectedUploadMimeTypeError(mimeType),
390
424
  details: { mimeType }
391
425
  });
@@ -398,8 +432,20 @@ const assertDeclaredPayloadSize = (payload, declared = payload.sizeInBytes) => {
398
432
  const measured = data instanceof ArrayBuffer || ArrayBuffer.isView(data) ? data.byteLength : getAssetPayloadByteLength(payload);
399
433
  if (!Number.isSafeInteger(declared) || declared < 0 || measured !== void 0 && measured !== declared) throw invalidPayload("sizeInBytes must match the payload byte length");
400
434
  };
435
+ /**
436
+ * Refuses one-request content whose known size is over the API's limit for its type: images up
437
+ * to 10 MiB (larger ones are uploaded in parts), audio and video up to 50 MiB, other files up to
438
+ * 5,000 MiB. Nothing is sent, so an oversized file fails at once instead of after its upload.
439
+ */
440
+ const assertDirectUploadSize = (content) => {
441
+ const size = content.sizeInBytes ?? getAssetPayloadByteLength(content);
442
+ if (size === void 0) return;
443
+ const type = content.type.toLowerCase();
444
+ const [limit, message] = type.startsWith("image/") ? [MAX_DIRECT_IMAGE_UPLOAD_BYTES, "Images uploaded in one request can be at most 10 MiB; upload larger images in parts"] : type.startsWith("audio/") || type.startsWith("video/") ? [MAX_MEDIA_UPLOAD_BYTES, "Audio and video files can be at most 50 MiB"] : [MAX_NON_IMAGE_UPLOAD_BYTES, "Files can be at most 5,000 MiB"];
445
+ if (size > limit) throw new CalmLensError(API_ERROR_CODES.FILE_TOO_LARGE, { message });
446
+ };
401
447
  /** Checks upload options before anything is sent. */
402
- const prepareSubmitAssetOptions = (options, { deferUploadChecks = false } = {}) => {
448
+ const prepareSubmitAssetOptions = (options, { deferUploadChecks = false, partSizeBytes = DEFAULT_PART_SIZE_BYTES } = {}) => {
403
449
  if (!options || typeof options !== "object") throw invalidArgument("Asset options are required");
404
450
  if (!("content" in options) && !("url" in options) && !("part" in options)) throw invalidPayload("Either file content, URL, or multipart part is required");
405
451
  if (!options.name) throw invalidPayload("Asset name is required");
@@ -408,6 +454,11 @@ const prepareSubmitAssetOptions = (options, { deferUploadChecks = false } = {})
408
454
  if ("content" in options) {
409
455
  assertDeclaredPayloadSize(options.content);
410
456
  assertValidUploadMimeType(options.content.type);
457
+ const inParts = splitsIntoParts(options.content, partSizeBytes);
458
+ if (inParts && (options.idempotencyKey?.length ?? 0) > 240) throw invalidArgument(`idempotencyKey can be at most 240 characters for an upload sent in parts`);
459
+ if (!deferUploadChecks && inParts && isImageMimeType(options.content.type)) {
460
+ if ((getAssetPayloadByteLength(options.content) ?? 0) > MAX_IMAGE_UPLOAD_BYTES) throw new CalmLensError(API_ERROR_CODES.MULTIPART_IMAGE_TOO_LARGE, { message: "Multipart image uploads cannot exceed 20MB." });
461
+ } else if (!deferUploadChecks) assertDirectUploadSize(options.content);
411
462
  if (!("plainText" in options.content)) {
412
463
  const validation = validateAssetPayload(options.content);
413
464
  if (!validation.ok) throw invalidPayload(validation.error);
@@ -419,7 +470,6 @@ const prepareSubmitAssetOptions = (options, { deferUploadChecks = false } = {})
419
470
  const partSizeInBytes = options.part.sizeInBytes ?? getAssetPayloadByteLength(options.part);
420
471
  if (!deferUploadChecks && isImageMimeType(options.part.type) && partSizeInBytes !== void 0) {
421
472
  if (partSizeInBytes > MAX_IMAGE_UPLOAD_BYTES) throw new CalmLensError(API_ERROR_CODES.MULTIPART_IMAGE_TOO_LARGE, { message: "Multipart image uploads cannot exceed 20MB." });
422
- if (options.part.isFinal && partSizeInBytes < MIN_MULTIPART_IMAGE_UPLOAD_BYTES) throw new CalmLensError(API_ERROR_CODES.MULTIPART_IMAGE_TOO_SMALL, { message: "Multipart image uploads must total at least 10MB." });
423
473
  }
424
474
  const validation = validateAssetPayload(options.part, {
425
475
  multipart: true,
@@ -558,6 +608,63 @@ var CalmLensConnection = class {
558
608
  "X-CalmLens-Upload": isMultipart ? "part" : "content"
559
609
  }, options.idempotencyKey ?? newIdempotencyKey());
560
610
  }
611
+ /** Content larger than this is uploaded in parts. */
612
+ get partSizeBytes() {
613
+ return this.options.partSizeBytes ?? 8388608;
614
+ }
615
+ /**
616
+ * Uploads content larger than `partSizeBytes` in parts: the first to `uploadsPath` with the
617
+ * upload's fields, the rest to `partPath(assetId)`. Each part carries its own Idempotency-Key
618
+ * (`<key>:part-<n>`), so it is retried safely and a repeated call with the same key resumes the
619
+ * upload. A part the API already has is skipped, and a final part that finds the upload already
620
+ * completed reads it back with `retrieve`.
621
+ */
622
+ async submitInParts(uploadsPath, options, queue, { authHeaders = {}, partPath, onStarted, retrieve }) {
623
+ const { content, idempotencyKey, ...fields } = options;
624
+ const source = getSplittableContent(content);
625
+ const partSize = this.partSizeBytes;
626
+ const count = Math.ceil(source.size / partSize);
627
+ const key = idempotencyKey ?? newIdempotencyKey();
628
+ const part = (partNumber) => source.slice((partNumber - 1) * partSize, Math.min(partNumber * partSize, source.size));
629
+ const first = await this.submitRawUpload(uploadsPath, {
630
+ ...fields,
631
+ part: {
632
+ ...part(1),
633
+ type: content.type,
634
+ partNumber: 1,
635
+ isFinal: false
636
+ },
637
+ totalSizeInBytes: source.size,
638
+ idempotencyKey: key
639
+ }, queue, authHeaders);
640
+ const assetId = expectUploadedAsset(first).id;
641
+ onStarted?.(assetId);
642
+ let result = first;
643
+ for (let partNumber = 2; partNumber <= count;) {
644
+ const isFinal = partNumber === count;
645
+ try {
646
+ result = await this.uploadPart(partPath(assetId), {
647
+ part: {
648
+ ...part(partNumber),
649
+ partNumber,
650
+ isFinal
651
+ },
652
+ idempotencyKey: `${key}:part-${partNumber}`
653
+ }, authHeaders);
654
+ partNumber++;
655
+ } catch (error) {
656
+ if (!(error instanceof CalmLensError)) throw error;
657
+ const expected = error.details?.expectedPartNumber;
658
+ if (error.code === API_ERROR_CODES.INVALID_UPLOAD_PART_NUMBER && typeof expected === "number" && expected > partNumber && expected <= count) {
659
+ partNumber = expected;
660
+ continue;
661
+ }
662
+ if (isFinal && error.code === API_ERROR_CODES.UPLOAD_NOT_OPEN) return retrieve(assetId);
663
+ throw error;
664
+ }
665
+ }
666
+ return result;
667
+ }
561
668
  /** Uploads the next part of a multipart upload to `partPath` (`.../assets/{id}/part`). */
562
669
  uploadPart(partPath, { part, queue, idempotencyKey }, authHeaders = {}) {
563
670
  if (!part) throw invalidArgument("Part options are required");
@@ -579,4 +686,294 @@ var CalmLensConnection = class {
579
686
  }, idempotencyKey ?? newIdempotencyKey());
580
687
  }
581
688
  };
582
- export { getMockHooks as a, prepareSubmitAssetOptions as c, assetDataToUint8Array as d, assetToData as f, expectUploadedAsset as i, resolveConnectionOptions as l, MOCK_HOOKS as n, invalidPayload as o, validateAssetPayload as p, expectAsset as r, newIdempotencyKey as s, CalmLensConnection as t, sleep as u };
689
+ // src/client/CalmLensOptionKeys.ts
690
+ /** The option keys each `CalmLensServerClient` method sends to the API. */
691
+ const SERVER_OPTION_KEYS = {
692
+ "assets.batch": ["assetIds", "operation"],
693
+ "assets.classify": [
694
+ "authorId",
695
+ "content",
696
+ "context",
697
+ "description",
698
+ "externalId",
699
+ "externalUrl",
700
+ "folderId",
701
+ "isFinal",
702
+ "metadata",
703
+ "name",
704
+ "part",
705
+ "processingOptions",
706
+ "sizeInBytes",
707
+ "totalSizeInBytes",
708
+ "uploadPresetId",
709
+ "url",
710
+ "visibility"
711
+ ],
712
+ "assets.create": [
713
+ "authorId",
714
+ "content",
715
+ "context",
716
+ "description",
717
+ "externalId",
718
+ "externalUrl",
719
+ "folderId",
720
+ "isFinal",
721
+ "metadata",
722
+ "name",
723
+ "part",
724
+ "processingOptions",
725
+ "sizeInBytes",
726
+ "totalSizeInBytes",
727
+ "uploadPresetId",
728
+ "url",
729
+ "visibility"
730
+ ],
731
+ "assets.createSignedUrl": [
732
+ "assetId",
733
+ "expiresInSeconds",
734
+ "lens",
735
+ "resource",
736
+ "transform",
737
+ "viewerClaims"
738
+ ],
739
+ "assets.decide": [
740
+ "assetId",
741
+ "confirmPurge",
742
+ "decision",
743
+ "note"
744
+ ],
745
+ "assets.delete": ["assetId"],
746
+ "assets.deleteContent": ["assetId"],
747
+ "assets.explain": ["assetId", "rerun"],
748
+ "assets.iterate": [
749
+ "cursor",
750
+ "filter",
751
+ "folderId",
752
+ "ordering",
753
+ "pageSize"
754
+ ],
755
+ "assets.iterateChildren": [
756
+ "assetId",
757
+ "cursor",
758
+ "ordering",
759
+ "pageSize"
760
+ ],
761
+ "assets.list": [
762
+ "cursor",
763
+ "filter",
764
+ "folderId",
765
+ "ordering",
766
+ "pageSize"
767
+ ],
768
+ "assets.listChildren": [
769
+ "assetId",
770
+ "cursor",
771
+ "ordering",
772
+ "pageSize"
773
+ ],
774
+ "assets.move": ["assetId", "folderId"],
775
+ "assets.retrieve": ["assetId"],
776
+ "assets.retry": ["assetId"],
777
+ "assets.search": [
778
+ "limit",
779
+ "mode",
780
+ "query"
781
+ ],
782
+ "assets.update": [
783
+ "assetId",
784
+ "description",
785
+ "externalId",
786
+ "externalUrl",
787
+ "metadata",
788
+ "name",
789
+ "tags",
790
+ "visibility"
791
+ ],
792
+ "assets.uploadPart": [
793
+ "assetId",
794
+ "part",
795
+ "queue"
796
+ ],
797
+ "ensureLens": [
798
+ "active",
799
+ "description",
800
+ "identifier",
801
+ "name",
802
+ "transform",
803
+ "type",
804
+ "version"
805
+ ],
806
+ "ensureLenses": ["lenses"],
807
+ "events.list": ["cursor", "pageSize"],
808
+ "events.pages": ["cursor", "pageSize"],
809
+ "folders.create": ["name", "parentId"],
810
+ "folders.delete": ["folderId"],
811
+ "folders.list": [
812
+ "cursor",
813
+ "ordering",
814
+ "pageSize",
815
+ "parentId",
816
+ "search"
817
+ ],
818
+ "folders.move": ["folderId", "parentId"],
819
+ "folders.retrieve": ["folderId"],
820
+ "folders.update": ["folderId", "name"],
821
+ "hashLists.addEntry": [
822
+ "assetId",
823
+ "hash",
824
+ "hashListId",
825
+ "label",
826
+ "quality"
827
+ ],
828
+ "hashLists.create": [
829
+ "action",
830
+ "description",
831
+ "name"
832
+ ],
833
+ "hashLists.delete": ["hashListId"],
834
+ "hashLists.list": [
835
+ "cursor",
836
+ "ordering",
837
+ "pageSize"
838
+ ],
839
+ "hashLists.listEntries": [
840
+ "cursor",
841
+ "hashListId",
842
+ "ordering",
843
+ "pageSize"
844
+ ],
845
+ "hashLists.removeEntry": ["entryId"],
846
+ "hashLists.retrieve": ["hashListId"],
847
+ "hashLists.update": [
848
+ "action",
849
+ "description",
850
+ "hashListId",
851
+ "name"
852
+ ],
853
+ "policies.applyPreset": [
854
+ "operation",
855
+ "policyId",
856
+ "presetVersion",
857
+ "revision"
858
+ ],
859
+ "policies.assign": ["policyId"],
860
+ "policies.create": [
861
+ "description",
862
+ "name",
863
+ "presetId",
864
+ "settings"
865
+ ],
866
+ "policies.delete": ["policyId"],
867
+ "policies.list": [],
868
+ "policies.retrieve": ["policyId"],
869
+ "policies.setAutomaticUpdates": [
870
+ "enabled",
871
+ "policyId",
872
+ "presetVersion",
873
+ "revision"
874
+ ],
875
+ "policies.update": [
876
+ "description",
877
+ "name",
878
+ "policyId",
879
+ "revision",
880
+ "settings"
881
+ ],
882
+ "text.classify": [
883
+ "authorId",
884
+ "context",
885
+ "description",
886
+ "externalId",
887
+ "externalUrl",
888
+ "folderId",
889
+ "metadata",
890
+ "name",
891
+ "processingOptions",
892
+ "text",
893
+ "uploadPresetId",
894
+ "visibility"
895
+ ]
896
+ };
897
+ /** The option keys each `CalmLensAppClient` method sends to the API. */
898
+ const APP_OPTION_KEYS = {
899
+ "assets.classify": [
900
+ "content",
901
+ "description",
902
+ "externalUrl",
903
+ "name",
904
+ "part",
905
+ "sizeInBytes",
906
+ "totalSizeInBytes"
907
+ ],
908
+ "assets.create": [
909
+ "content",
910
+ "description",
911
+ "externalUrl",
912
+ "name",
913
+ "part",
914
+ "sizeInBytes",
915
+ "totalSizeInBytes"
916
+ ],
917
+ "assets.retrieve": ["assetId"],
918
+ "assets.uploadPart": [
919
+ "assetId",
920
+ "part",
921
+ "queue"
922
+ ]
923
+ };
924
+ /**
925
+ * The option keys each `CalmLensServerClient` method sends as `null` when given `null`; any
926
+ * other option given as `null` is left out, as the API refuses `null` for it.
927
+ */
928
+ const NULLABLE_OPTION_KEYS = {
929
+ "assets.classify": [
930
+ "authorId",
931
+ "context",
932
+ "description",
933
+ "externalId",
934
+ "folderId",
935
+ "metadata",
936
+ "processingOptions",
937
+ "uploadPresetId",
938
+ "visibility"
939
+ ],
940
+ "assets.create": [
941
+ "authorId",
942
+ "context",
943
+ "description",
944
+ "externalId",
945
+ "folderId",
946
+ "metadata",
947
+ "processingOptions",
948
+ "uploadPresetId",
949
+ "visibility"
950
+ ],
951
+ "assets.iterate": ["filter", "folderId"],
952
+ "assets.list": ["filter", "folderId"],
953
+ "assets.move": ["folderId"],
954
+ "assets.update": [
955
+ "description",
956
+ "externalId",
957
+ "externalUrl",
958
+ "metadata",
959
+ "tags",
960
+ "visibility"
961
+ ],
962
+ "folders.create": ["parentId"],
963
+ "folders.move": ["parentId"],
964
+ "hashLists.addEntry": ["label", "quality"],
965
+ "hashLists.create": ["description"],
966
+ "hashLists.update": ["description"],
967
+ "text.classify": [
968
+ "authorId",
969
+ "context",
970
+ "description",
971
+ "externalId",
972
+ "folderId",
973
+ "metadata",
974
+ "processingOptions",
975
+ "uploadPresetId",
976
+ "visibility"
977
+ ]
978
+ };
979
+ export { validateAssetPayload as _, MOCK_HOOKS as a, getMockHooks as c, prepareSubmitAssetOptions as d, resolveConnectionOptions as f, assetToData as g, assetDataToUint8Array as h, CalmLensConnection as i, invalidPayload as l, sleep as m, NULLABLE_OPTION_KEYS as n, expectAsset as o, splitsIntoParts as p, SERVER_OPTION_KEYS as r, expectUploadedAsset as s, APP_OPTION_KEYS as t, newIdempotencyKey as u };
@@ -1,6 +1,6 @@
1
1
  import { o as HashList, s as HashListEntry } from "./ModerationContext-9lGm-Mna-CcmbRnOy.js";
2
- import { $ as IterateAssetsOptions, A as ClassifyTextOptions, B as EnsureLensesOptions, C as BatchAssetsResponse, Ct as UploadAssetPartOptions, E as CdnAssetUrlOptions, Et as VerifyWebhookSignatureOptions, G as HashListEntryIdOptions, H as FolderIdOptions, I as DecideAssetOptions, J as HashListPage, Jt as AssetSearchQuery, K as HashListEntryPage, L as DeleteAssetContentOptions, M as CreateAssetSignedUrlOptions, Mt as GetEventsResponse, N as CreateFolderOptions, Nt as PostAssetSignedUrlResponse, O as CdnServeOptions, Ot as WaitForAssetDecisionOptions, P as CreateHashListOptions, Q as IterateAssetChildrenOptions, R as DeleteAssetOptions, S as BatchAssetsOptions, St as UpdateHashListOptions, T as CalmLensServerClientOptions, U as FolderPage, Ut as Folder, V as ExplainAssetOptions, _t as SignedUploadToken, at as ListFoldersOptions, bt as UpdateAssetOptions, ct as MoveAssetOptions, et as Lens, ft as RequestOptions, g as AssetSearchResponse, gt as SignUploadTokenOptions, h as AssetPage, i as AssetChildrenPage, it as ListEventsOptions, lt as MoveFolderOptions, mt as RetryAssetOptions, n as Asset, nt as ListAssetChildrenOptions, ot as ListHashListEntriesOptions, pt as RetrieveAssetOptions, q as HashListIdOptions, rt as ListAssetsOptions, st as ListHashListsOptions, t as AddHashListEntryOptions, xt as UpdateFolderOptions, yt as SubmitAssetOptions, z as EnsureLensOptions } from "./CalmLensTypes-9Vt16pc7.js";
3
- import "./WebhookPayload-2aL31v0J.js";
2
+ import { A as CdnServeOptions, B as DeleteAssetContentOptions, C as AssignPolicyOptions, Ct as SubmitAssetOptions, D as CalmLensServerClientOptions, Dt as UpdatePolicyOptions, Et as UpdateHashListOptions, F as CreateFolderOptions, G as FolderIdOptions, H as EnsureLensOptions, I as CreateHashListOptions, J as HashListEntryIdOptions, Jt as Folder, K as FolderPage, Lt as GetEventsResponse, M as ClassifyTextOptions, Nt as WaitForAssetDecisionOptions, O as CdnAssetUrlOptions, Ot as UploadAssetPartOptions, P as CreateAssetSignedUrlOptions, R as CreatePolicyOptions, Rt as PostAssetSignedUrlResponse, T as BatchAssetsResponse, Tt as UpdateFolderOptions, U as EnsureLensesOptions, V as DeleteAssetOptions, W as ExplainAssetOptions, X as HashListIdOptions, Y as HashListEntryPage, Yt as Policy, Z as HashListPage, _ as AssetSearchResponse, _t as RetryAssetOptions, a as AssetChildrenPage, at as ListEventsOptions, bt as SignUploadTokenOptions, ct as ListHashListsOptions, en as AssetSearchQuery, et as IterateAssetChildrenOptions, g as AssetPage, gt as RetrieveAssetOptions, ht as RequestOptions, it as ListAssetsOptions, jt as VerifyWebhookSignatureOptions, lt as MoveAssetOptions, mt as PolicyList, n as ApplyPolicyPresetOptions, nt as Lens, ot as ListFoldersOptions, pt as PolicyIdOptions, r as Asset, rt as ListAssetChildrenOptions, st as ListHashListEntriesOptions, t as AddHashListEntryOptions, tt as IterateAssetsOptions, ut as MoveFolderOptions, w as BatchAssetsOptions, wt as UpdateAssetOptions, xt as SignedUploadToken, yt as SetPolicyAutomaticUpdatesOptions, z as DecideAssetOptions } from "./CalmLensTypes-COJbOuiv.js";
3
+ import "./WebhookPayload-DkukERKE.js";
4
4
  interface LensCache {
5
5
  readonly ensuredLenses: Map<string, Lens>;
6
6
  readonly pendingEnsureLenses: Map<string, Promise<void>>;
@@ -50,15 +50,17 @@ declare class CalmLensServerClient {
50
50
  /**
51
51
  * Builds a CDN URL for asset content or a preview, without a request. Private assets
52
52
  * need a signed URL (`assets.createSignedUrl`) or an authenticated request; public
53
- * age-restricted assets additionally require `viewerClaims.ageConfirmed: true`.
53
+ * age-restricted assets additionally require `viewerClaims.ageConfirmed: true`. Your
54
+ * platform confirms the viewer's age; CalmLens does not verify this claim, and anyone can
55
+ * add it to a public URL.
54
56
  */
55
- getAssetUrl: ({ assetIdentifier, ...options }: CdnAssetUrlOptions) => string;
57
+ getAssetUrl: (urlOptions: CdnAssetUrlOptions) => string;
56
58
  /**
57
59
  * Fetches asset content or a preview from the CDN with the client's API key, and returns
58
60
  * the `Response` as soon as headers arrive, so the body streams. Non-2xx responses are
59
61
  * returned, not thrown; `timeoutMs` covers only the wait for headers.
60
62
  */
61
- serve: ({ assetIdentifier, init, ...urlOptions }: CdnServeOptions) => Promise<Response>;
63
+ serve: (options: CdnServeOptions) => Promise<Response>;
62
64
  };
63
65
  get text(): {
64
66
  /**
@@ -81,11 +83,11 @@ declare class CalmLensServerClient {
81
83
  */
82
84
  iterate: (options?: IterateAssetsOptions) => AsyncGenerator<Asset, void, undefined>;
83
85
  /** Retrieves an asset with its status and classification results. */
84
- retrieve: ({ assetId }: RetrieveAssetOptions) => Promise<Asset>;
86
+ retrieve: (options: RetrieveAssetOptions) => Promise<Asset>;
85
87
  /** Updates an asset's editable fields. */
86
- update: ({ assetId, ...body }: UpdateAssetOptions) => Promise<Asset>;
88
+ update: (options: UpdateAssetOptions) => Promise<Asset>;
87
89
  /** Lists one page of the assets extracted from a website or multimedia document. */
88
- listChildren: ({ assetId, ...options }?: ListAssetChildrenOptions) => Promise<AssetChildrenPage>;
90
+ listChildren: (options?: ListAssetChildrenOptions) => Promise<AssetChildrenPage>;
89
91
  /** Yields every child of an asset, fetching pages as needed. */
90
92
  iterateChildren: (options: IterateAssetChildrenOptions) => AsyncGenerator<Asset, void, undefined>;
91
93
  /**
@@ -98,32 +100,32 @@ declare class CalmLensServerClient {
98
100
  * Uploads an asset and waits for its moderation decision. Audio and video still finish
99
101
  * in the background. Retried safely with an `Idempotency-Key`.
100
102
  */
101
- classify: (options: SubmitAssetOptions) => Promise<Asset>;
103
+ classify: (classifyOptions: SubmitAssetOptions) => Promise<Asset>;
102
104
  /**
103
105
  * Uploads the next part of a multipart upload. The upload's queue mode, chosen when it
104
106
  * started, applies when the final part arrives; pass `queue` to override it.
105
107
  */
106
- uploadPart: ({ assetId, ...options }: UploadAssetPartOptions) => Promise<Asset>;
108
+ uploadPart: (partOptions: UploadAssetPartOptions) => Promise<Asset>;
107
109
  /**
108
110
  * Creates a short-lived signed CDN URL, so browsers can load private content without
109
111
  * an API key.
110
112
  */
111
- createSignedUrl: ({ assetId, ...options }: CreateAssetSignedUrlOptions) => Promise<PostAssetSignedUrlResponse>;
113
+ createSignedUrl: (signedUrlOptions: CreateAssetSignedUrlOptions) => Promise<PostAssetSignedUrlResponse>;
112
114
  /** Moves an asset into a folder, or to the project root with `folderId: null`. */
113
- move: ({ assetId, folderId }: MoveAssetOptions) => Promise<Asset>;
115
+ move: (options: MoveAssetOptions) => Promise<Asset>;
114
116
  /**
115
117
  * Processes an asset that failed (classification status `failed`) again. It returns to
116
118
  * `processing` and is
117
119
  * moderated like a new upload; its content must still be stored.
118
120
  */
119
- retry: ({ assetId }: RetryAssetOptions) => Promise<Asset>;
121
+ retry: (options: RetryAssetOptions) => Promise<Asset>;
120
122
  /**
121
123
  * Records a reviewer's decision, replacing the policy's: the asset's moderation status
122
124
  * becomes `decision`, the note joins its review history and the matching `asset.<status>`
123
125
  * event is sent. An asset still pending moderation can only be blocked or purged. Purging
124
126
  * needs `confirmPurge: true` and permanently deletes the stored content.
125
127
  */
126
- decide: ({ assetId, ...body }: DecideAssetOptions) => Promise<Asset>;
128
+ decide: (options: DecideAssetOptions) => Promise<Asset>;
127
129
  /**
128
130
  * Completes the policy evidence behind a decided asset's moderation decision: the report's
129
131
  * `classification.moderation.evidence` becomes `full` and every action stays as
@@ -131,21 +133,21 @@ declare class CalmLensServerClient {
131
133
  * and returns in `processing`; use it when the policy has changed since the decision
132
134
  * (`asset/policy-changed`).
133
135
  */
134
- explain: ({ assetId, rerun }: ExplainAssetOptions) => Promise<Asset>;
136
+ explain: (options: ExplainAssetOptions) => Promise<Asset>;
135
137
  /**
136
138
  * Waits until an asset's `classification.moderation.status` is no longer `pending` (`allowed`,
137
139
  * `limited`, `age-restricted`, `blocked` or `purged`), or its `classification.status` is `failed`, and returns that asset, checking every few seconds. Rejects with `sdk/timeout` if there is no
138
140
  * decision within `timeoutMs` (default 60000). Webhooks report decisions without polling.
139
141
  */
140
- waitForDecision: ({ assetId, ...options }: WaitForAssetDecisionOptions) => Promise<Asset>;
142
+ waitForDecision: (waitOptions: WaitForAssetDecisionOptions) => Promise<Asset>;
141
143
  /**
142
144
  * Removes an asset's stored content (source, preview and retained extracted text) while
143
145
  * keeping the asset record, metadata and classification results. The returned asset has
144
146
  * `content.status` set to `removed` and `content.removalReason` to `requested`; the CDN no longer serves it.
145
147
  */
146
- deleteContent: ({ assetId }: DeleteAssetContentOptions) => Promise<Asset>;
148
+ deleteContent: (options: DeleteAssetContentOptions) => Promise<Asset>;
147
149
  /** Deletes an asset record together with its stored content. */
148
- delete: ({ assetId }: DeleteAssetOptions) => Promise<void>;
150
+ delete: (options: DeleteAssetOptions) => Promise<void>;
149
151
  /**
150
152
  * Deletes up to 500 assets (`operation: "delete"`) or removes their stored content
151
153
  * (`"remove-content"`) in one request. Every asset must exist in the project and the key
@@ -154,7 +156,7 @@ declare class CalmLensServerClient {
154
156
  * `asset.deleted` or `asset.content-removed` for each asset. Assets under a safety hold
155
157
  * are skipped. Not retried: it carries no `Idempotency-Key`.
156
158
  */
157
- batch: ({ assetIds, operation }: BatchAssetsOptions) => Promise<BatchAssetsResponse>;
159
+ batch: (options: BatchAssetsOptions) => Promise<BatchAssetsResponse>;
158
160
  };
159
161
  /**
160
162
  * Signs upload tokens on your server, so a browser or app can upload through an upload preset
@@ -190,14 +192,14 @@ declare class CalmLensServerClient {
190
192
  * `nextCursor` as `cursor` for the next page; fetch a branch when it is opened.
191
193
  */
192
194
  list: (options?: ListFoldersOptions) => Promise<FolderPage>;
193
- retrieve: ({ folderId }: FolderIdOptions) => Promise<Folder>;
195
+ retrieve: (options: FolderIdOptions) => Promise<Folder>;
194
196
  /** Creates a folder at the project root or inside `parentId`. */
195
197
  create: (options: CreateFolderOptions) => Promise<Folder>;
196
- update: ({ folderId, ...body }: UpdateFolderOptions) => Promise<Folder>;
198
+ update: (options: UpdateFolderOptions) => Promise<Folder>;
197
199
  /** Deletes an empty folder; throws `folder/not-empty` otherwise. */
198
- delete: ({ folderId }: FolderIdOptions) => Promise<void>;
200
+ delete: (options: FolderIdOptions) => Promise<void>;
199
201
  /** Moves a folder under `parentId`, or to the project root with `parentId: null`. */
200
- move: ({ folderId, parentId }: MoveFolderOptions) => Promise<Folder>;
202
+ move: (options: MoveFolderOptions) => Promise<Folder>;
201
203
  };
202
204
  /**
203
205
  * Hash lists hold PDQ hashes of images the project never wants again. Image uploads are
@@ -206,17 +208,39 @@ declare class CalmLensServerClient {
206
208
  get hashLists(): {
207
209
  /** Lists one page of the project's hash lists, newest first. */
208
210
  list: (options?: ListHashListsOptions) => Promise<HashListPage>;
209
- retrieve: ({ hashListId }: HashListIdOptions) => Promise<HashList>;
211
+ retrieve: (options: HashListIdOptions) => Promise<HashList>;
210
212
  create: (options: CreateHashListOptions) => Promise<HashList>;
211
213
  /** Renames a list or changes its action; the new action applies to later uploads. */
212
- update: ({ hashListId, ...body }: UpdateHashListOptions) => Promise<HashList>;
214
+ update: (options: UpdateHashListOptions) => Promise<HashList>;
213
215
  /** Deletes the list and every entry in it. */
214
- delete: ({ hashListId }: HashListIdOptions) => Promise<void>;
216
+ delete: (options: HashListIdOptions) => Promise<void>;
215
217
  /** Lists one page of a list's entries, newest first. */
216
- listEntries: ({ hashListId, ...query }: ListHashListEntriesOptions) => Promise<HashListEntryPage>;
218
+ listEntries: (options: ListHashListEntriesOptions) => Promise<HashListEntryPage>;
217
219
  /** Adds a hash, or an image asset's hash; a hash already in the list returns its entry. */
218
- addEntry: ({ hashListId, ...body }: AddHashListEntryOptions) => Promise<HashListEntry>;
219
- removeEntry: ({ entryId }: HashListEntryIdOptions) => Promise<void>;
220
+ addEntry: (options: AddHashListEntryOptions) => Promise<HashListEntry>;
221
+ removeEntry: (options: HashListEntryIdOptions) => Promise<void>;
222
+ };
223
+ /**
224
+ * Moderation policies belong to the project's organisation and its projects share them. Every
225
+ * change sends the policy's `revision`, so a policy changed since is refused. Through a
226
+ * project's key you can change only policies no other project uses or owns.
227
+ */
228
+ get policies(): {
229
+ /** Lists the organisation's policies and the ID of the one the project uses. */
230
+ list: () => Promise<PolicyList>;
231
+ retrieve: (options: PolicyIdOptions) => Promise<Policy>;
232
+ /** Creates a policy from `settings`, or a copy of a built-in preset with `presetId`. */
233
+ create: (options: CreatePolicyOptions) => Promise<Policy>;
234
+ /** Changes the name, description or settings; later moderation uses them. */
235
+ update: (options: UpdatePolicyOptions) => Promise<Policy>;
236
+ /** Resets a preset copy to its pinned version, or updates an unchanged copy to the latest. */
237
+ applyPreset: (options: ApplyPolicyPresetOptions) => Promise<Policy>;
238
+ /** Switches automatic updates on or off for the organisation's own preset policy. */
239
+ setAutomaticUpdates: (options: SetPolicyAutomaticUpdatesOptions) => Promise<Policy>;
240
+ /** Deletes a policy that no project or upload preset uses. */
241
+ delete: (options: PolicyIdOptions) => Promise<void>;
242
+ /** Chooses the policy the project moderates with. */
243
+ assign: (options: AssignPolicyOptions) => Promise<Policy>;
220
244
  };
221
245
  /**
222
246
  * Create a named lens at any positive version, or update it with a greater version.
@@ -228,7 +252,7 @@ declare class CalmLensServerClient {
228
252
  * consecutive requests of at most {@link ENSURE_LENSES_MAX_PER_REQUEST} definitions, in order.
229
253
  * Each lens follows the same versioning and idempotency rules as ensureLens().
230
254
  */
231
- ensureLenses({ lenses }: EnsureLensesOptions): Promise<Lens[]>;
255
+ ensureLenses(options: EnsureLensesOptions): Promise<Lens[]>;
232
256
  private submitEnsureLenses;
233
257
  private submitEnsureLensesChunk;
234
258
  }