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
package/esm/testing.js CHANGED
@@ -1,10 +1,10 @@
1
- import { A as invalidArgument, C as MAX_IMAGE_UPLOAD_BYTES, E as isRejectedUploadMimeType, M as API_ERROR_CODES, N as API_ERROR_DEFINITIONS, O as CalmLensError, T as getRejectedUploadMimeTypeError, _ as validateAppClientOptions, b as validateServerClientOptions, f as randomUuid, j as invalidConfig, k as SDK_ERROR_CODES, r as selectModerationContextItems, w as MIN_MULTIPART_IMAGE_UPLOAD_BYTES } from "./ModerationContextLimits-KMQ8puoa.js";
2
- import { a as WEBHOOK_TIMESTAMP_HEADER, l as signUploadTokenWithApiKey, n as WEBHOOK_DELIVERY_HEADER, r as WEBHOOK_SIGNATURE_HEADER, t as CalmLensServerClient, u as stringifyJsonCanonical } from "./CalmLensServerClient-Dt7rCITa.js";
3
- import { d as assetDataToUint8Array, f as assetToData, n as MOCK_HOOKS, p as validateAssetPayload, u as sleep } from "./CalmLensConnection-DBoDh06c.js";
1
+ import { F as invalidArgument, I as invalidConfig, L as API_ERROR_CODES, N as CalmLensError, P as SDK_ERROR_CODES, R as API_ERROR_DEFINITIONS, g as randomUuid, j as getRejectedUploadMimeTypeError, k as MAX_IMAGE_UPLOAD_BYTES, m as parseTransformSelector, p as isAcceptedUploadMimeType, r as selectModerationContextItems, u as checkTransformOptions, w as validateServerClientOptions, x as validateAppClientOptions } from "./ModerationContextLimits-Chw-AzgL.js";
2
+ import { a as WEBHOOK_TIMESTAMP_HEADER, l as signUploadTokenWithApiKey, n as WEBHOOK_DELIVERY_HEADER, r as WEBHOOK_SIGNATURE_HEADER, t as CalmLensServerClient, u as stringifyJsonCanonical } from "./CalmLensServerClient-C_H5aAsV.js";
3
+ import { _ as validateAssetPayload, a as MOCK_HOOKS, g as assetToData, h as assetDataToUint8Array, m as sleep } from "./CalmLensOptionKeys-Do2mPP6w.js";
4
4
  import { t as hmacSha256Hex } from "./CryptoUtils-B_x8lMIx-DhuWGzqn.js";
5
- import { t as CalmLensAppClient } from "./CalmLensAppClient-BMgXamoN.js";
6
- import { a as placeholderHashToDataURL, r as isFileAccepted } from "./UploadController-Cs-bxUbt.js";
7
- import { s as getTestInputTag, u as CLASSIFICATION_CATEGORIES } from "./TestTriggers-DTc_iMJF-HfB533Gx.js";
5
+ import { t as CalmLensAppClient } from "./CalmLensAppClient-PQ9VBvlW.js";
6
+ import { a as placeholderHashToDataURL, r as isFileAccepted } from "./UploadController-BJZghJpg.js";
7
+ import { s as getTestInputTag, u as CLASSIFICATION_CATEGORIES } from "./TestTriggers-DbhsNPdg-CUdrv8Nm.js";
8
8
  import * as zod from "zod";
9
9
  // src/contract/MediaTestTriggers.js
10
10
  const MEDIA_TEST_SIGNALS = [...CLASSIFICATION_CATEGORIES, "violence.graphic"];
@@ -31,7 +31,7 @@ async function generateMediaTestCode(signal, testInputKey) {
31
31
  if (!MEDIA_TEST_SIGNALS.includes(signal)) throw new RangeError("Unsupported media test signal");
32
32
  return `Calm Lens test ${[...await getTestInputTag("media", signal, testInputKey)].map((character) => HEX_WORDS[Number.parseInt(character, 16)]).join(" ")} ${signal.replace(/[.-]/g, " ")} end test`;
33
33
  }
34
- // src/contract/Ids-aHyP9ZcF.js
34
+ // src/contract/Ids-D2XfVlL6.js
35
35
  var __defProp = Object.defineProperty;
36
36
  var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
37
37
  var __exportAll = (all, no_symbols) => {
@@ -7906,6 +7906,7 @@ const ID_PREFIXES = {
7906
7906
  user: "user",
7907
7907
  member: "mem",
7908
7908
  invitation: "inv",
7909
+ transfer: "xfer",
7909
7910
  supportTicket: "tkt",
7910
7911
  supportTicketMessage: "msg",
7911
7912
  humanReview: "rev",
@@ -7966,6 +7967,7 @@ const EXAMPLE_IDS = {
7966
7967
  user: "user_4Rk9Xm2Lq7Vt3Wb8Np6C",
7967
7968
  mem: "mem_9Xm4Rk7Lq2Vt8Wb3Np5C",
7968
7969
  inv: "inv_3Qk8Xm2Rt9Lv4Wb7Np6C",
7970
+ xfer: "xfer_6Lq2Xm8Rk4Vt9Wb3Np7C",
7969
7971
  tkt: "tkt_6Xm2Rk9Lq4Vt7Wb3Np8C",
7970
7972
  msg: "msg_2Rk7Xm4Lq9Vt3Wb8Np5C",
7971
7973
  rev: "rev_8Xm3Rk2Lq7Vt9Wb4Np6C",
@@ -7982,8 +7984,8 @@ const EXAMPLE_IDS = {
7982
7984
  * every stored model's IDs by prefix is a separate change (it surfaces about a thousand call sites
7983
7985
  * across the packages that build records from plain strings).
7984
7986
  */
7985
- const idField = (prefix) => zod.string().regex(idPattern(prefix), { message: `Must be an ID starting with "${prefix}_"` }).meta({ examples: [EXAMPLE_IDS[prefix]] });
7986
- // src/contract/Permissions-DjKQmOVp.js
7987
+ const idField = (prefix) => zod.string().regex(idPattern(prefix), { message: `Must be a valid ID: "${prefix}_" followed by 20 letters or digits` }).meta({ examples: [EXAMPLE_IDS[prefix]] });
7988
+ // src/contract/Permissions-C2KeOlab.js
7987
7989
  const ACTION_SCHEMA = zod.enum([
7988
7990
  "assets:read",
7989
7991
  "assets:download",
@@ -8011,6 +8013,8 @@ const ACTION_SCHEMA = zod.enum([
8011
8013
  "upload-presets:write",
8012
8014
  "hash-lists:read",
8013
8015
  "hash-lists:write",
8016
+ "policies:read",
8017
+ "policies:write",
8014
8018
  "reviews:read",
8015
8019
  "reviews:write",
8016
8020
  "project:manage"
@@ -8024,6 +8028,7 @@ const PROJECT_ACTIONS = [...[
8024
8028
  "lenses",
8025
8029
  "upload-presets",
8026
8030
  "hash-lists",
8031
+ "policies",
8027
8032
  "reviews"
8028
8033
  ].flatMap((feature) => [`${feature}:read`, `${feature}:write`]), "project:manage"];
8029
8034
  const isProjectAction = (action) => PROJECT_ACTIONS.includes(action);
@@ -8579,6 +8584,60 @@ const REVIEW_DECISIONS = [
8579
8584
  "blocked",
8580
8585
  "purged"
8581
8586
  ];
8587
+ /**
8588
+ * A client method, named like its path on the client. A request is recorded under the first
8589
+ * method that sends it; `callsTo` and `failNextRequest` also match the others (see
8590
+ * `MockCalmLensCall`).
8591
+ */
8592
+ const MOCK_OPERATIONS = [
8593
+ "assets.list",
8594
+ "assets.iterate",
8595
+ "assets.search",
8596
+ "assets.retrieve",
8597
+ "assets.waitForDecision",
8598
+ "assets.update",
8599
+ "assets.listChildren",
8600
+ "assets.iterateChildren",
8601
+ "assets.create",
8602
+ "assets.classify",
8603
+ "assets.uploadPart",
8604
+ "assets.createSignedUrl",
8605
+ "assets.move",
8606
+ "assets.retry",
8607
+ "assets.explain",
8608
+ "assets.decide",
8609
+ "assets.deleteContent",
8610
+ "assets.delete",
8611
+ "assets.batch",
8612
+ "text.classify",
8613
+ "cdn.serve",
8614
+ "events.list",
8615
+ "events.pages",
8616
+ "folders.list",
8617
+ "folders.retrieve",
8618
+ "folders.create",
8619
+ "folders.update",
8620
+ "folders.delete",
8621
+ "folders.move",
8622
+ "hashLists.list",
8623
+ "hashLists.retrieve",
8624
+ "hashLists.create",
8625
+ "hashLists.update",
8626
+ "hashLists.delete",
8627
+ "hashLists.listEntries",
8628
+ "hashLists.addEntry",
8629
+ "hashLists.removeEntry",
8630
+ "policies.list",
8631
+ "policies.retrieve",
8632
+ "policies.create",
8633
+ "policies.update",
8634
+ "policies.applyPreset",
8635
+ "policies.setAutomaticUpdates",
8636
+ "policies.delete",
8637
+ "policies.assign",
8638
+ "ensureLens",
8639
+ "ensureLenses"
8640
+ ];
8582
8641
  const MAX_PAGE_SIZE = 100;
8583
8642
  const MAX_DECISION_NOTE_LENGTH = 1499;
8584
8643
  /** How the API names a reviewer acting through an unnamed API key. */
@@ -8656,6 +8715,26 @@ var ApiFailure = class {
8656
8715
  const fail = (code, { message, details } = {}) => new ApiFailure(API_ERROR_DEFINITIONS[code].status, code, message ?? API_ERROR_DEFINITIONS[code].message, details);
8657
8716
  /** A request the API's schema refuses: `validation/<zod issue>` with HTTP 400 and the field. */
8658
8717
  const invalidField = (code, path) => new ApiFailure(400, code, `Invalid ${path}`, { path });
8718
+ /**
8719
+ * Refuses `metadata` the API's schema refuses (METADATA_ITEM_SCHEMA): it is `null` or a list of
8720
+ * `{ id, value }` objects with a string `id` and any JSON `value`.
8721
+ */
8722
+ const checkMetadata = (metadata) => {
8723
+ if (metadata === void 0 || metadata === null) return;
8724
+ if (!Array.isArray(metadata)) throw invalidField("validation/invalid-type", "metadata");
8725
+ metadata.forEach((item, index) => {
8726
+ if (typeof item !== "object" || item === null || Array.isArray(item)) throw invalidField("validation/invalid-type", `metadata.${index}`);
8727
+ if (typeof item.id !== "string") throw invalidField("validation/invalid-type", `metadata.${index}.id`);
8728
+ if (item.value === void 0) throw invalidField("validation/invalid-value", `metadata.${index}.value`);
8729
+ });
8730
+ };
8731
+ /** The built-in presets the mock knows, by display name. */
8732
+ const MOCK_PRESET_NAMES = {
8733
+ "general-community": "General",
8734
+ "children-platform": "Kids",
8735
+ "education-support": "Learning and support",
8736
+ "wholesome-community": "Teen-safe"
8737
+ };
8659
8738
  /** The client methods that send a request, the one it is recorded under first. */
8660
8739
  const operationsOf = (request) => {
8661
8740
  const { method, segments, query, cdn } = request;
@@ -8667,6 +8746,8 @@ const operationsOf = (request) => {
8667
8746
  case "lenses": return ["ensureLenses", "ensureLens"];
8668
8747
  case "folders": return method === "GET" ? ["folders.list"] : ["folders.create"];
8669
8748
  case "hash-lists": return method === "GET" ? ["hashLists.list"] : ["hashLists.create"];
8749
+ case "policies": return method === "GET" ? ["policies.list"] : ["policies.create"];
8750
+ case "policy": return ["policies.assign"];
8670
8751
  case "assets/search": return ["assets.search"];
8671
8752
  case "assets/batch": return ["assets.batch"];
8672
8753
  case "assets":
@@ -8674,6 +8755,11 @@ const operationsOf = (request) => {
8674
8755
  if (query.get("queue") === "true") return ["assets.create"];
8675
8756
  return isTextUpload(request) ? ["assets.classify", "text.classify"] : ["assets.classify"];
8676
8757
  }
8758
+ if (segments[2] === "policies" && segments[3] !== void 0) {
8759
+ if (segments[4] === "preset") return ["policies.applyPreset"];
8760
+ if (segments[4] === "automatic-updates") return ["policies.setAutomaticUpdates"];
8761
+ return method === "GET" ? ["policies.retrieve"] : method === "PATCH" ? ["policies.update"] : ["policies.delete"];
8762
+ }
8677
8763
  return [];
8678
8764
  }
8679
8765
  if (root === "upload-presets") {
@@ -8710,6 +8796,7 @@ const isTextUpload = (request) => request.headers.get("x-calmlens-upload") === "
8710
8796
  const SUCCESS_STATUS = {
8711
8797
  "folders.create": 201,
8712
8798
  "hashLists.create": 201,
8799
+ "policies.create": 201,
8713
8800
  "assets.batch": 202
8714
8801
  };
8715
8802
  const decodeSegment = (segment) => {
@@ -8740,6 +8827,7 @@ var MockCalmLensApi = class {
8740
8827
  this.pendingFailures = [];
8741
8828
  this.requestCount = 0;
8742
8829
  this.waitedMs = 0;
8830
+ this.policies = /* @__PURE__ */ new Map();
8743
8831
  this.hashLists = /* @__PURE__ */ new Map();
8744
8832
  this.hashListEntries = /* @__PURE__ */ new Map();
8745
8833
  this.pageFailure = (code, path) => code === "validation/invalid-cursor" ? fail(API_ERROR_CODES.INVALID_CURSOR) : invalidField(code, path ?? "pageSize");
@@ -8754,6 +8842,8 @@ var MockCalmLensApi = class {
8754
8842
  }
8755
8843
  /** Queues a failure for the next request, or the next one `operation` sends. */
8756
8844
  failNextRequest(failure, options = {}) {
8845
+ if (options.operation !== void 0 && !MOCK_OPERATIONS.includes(options.operation)) throw invalidArgument(`${options.operation} is not a client method that sends requests`);
8846
+ if (!(typeof failure === "string" && failure in API_ERROR_DEFINITIONS) && (options.details !== void 0 || options.retryAfter !== void 0)) throw invalidArgument("details and retryAfter apply only to an API error code");
8757
8847
  if (options.retryAfter !== void 0 && !(Number.isInteger(options.retryAfter) && options.retryAfter >= 0)) throw invalidArgument("retryAfter must be a whole number of seconds");
8758
8848
  this.pendingFailures.push({
8759
8849
  failure,
@@ -8932,6 +9022,7 @@ var MockCalmLensApi = class {
8932
9022
  method: (init?.method ?? "GET").toUpperCase(),
8933
9023
  url,
8934
9024
  segments: path.split("/").filter(Boolean).map(decodeSegment),
9025
+ rawSegments: path.split("/").filter(Boolean),
8935
9026
  query: new URLSearchParams(queryIndex === -1 ? "" : relative.slice(queryIndex + 1)),
8936
9027
  headers,
8937
9028
  bytes,
@@ -9074,6 +9165,17 @@ var MockCalmLensApi = class {
9074
9165
  case "GET hash-lists": return [200, this.listHashLists(request.query)];
9075
9166
  case "POST hash-lists": return [201, this.createHashList(this.json(request))];
9076
9167
  case "PUT lenses": return [200, this.ensureLenses(this.json(request))];
9168
+ case "GET policies": return [200, this.listPolicies()];
9169
+ case "POST policies": return [201, this.createPolicy(this.json(request))];
9170
+ case "PUT policy": return [200, this.assignPolicy(this.json(request))];
9171
+ }
9172
+ const [, , collection, policyId, policyAction, ...more] = segments;
9173
+ if (collection === "policies" && policyId !== void 0 && more.length === 0) switch (`${method} ${policyAction ?? ""}`) {
9174
+ case "GET ": return [200, this.toPolicy(this.findPolicy(policyId))];
9175
+ case "PATCH ": return [200, this.updatePolicy(policyId, this.json(request))];
9176
+ case "DELETE ": return [200, this.deletePolicy(policyId)];
9177
+ case "POST preset": return [200, this.applyPolicyPreset(policyId, this.json(request))];
9178
+ case "PUT automatic-updates": return [200, this.setPolicyAutomaticUpdates(policyId, this.json(request))];
9077
9179
  }
9078
9180
  }
9079
9181
  if (root === "upload-presets" && id !== void 0 && action === "assets") return [200, await this.presetRoute(request, id, rest, session)];
@@ -9109,6 +9211,134 @@ var MockCalmLensApi = class {
9109
9211
  }
9110
9212
  throw fail(API_ERROR_CODES.ROUTE_NOT_FOUND, { message: `No route for ${method} /${segments.join("/")}` });
9111
9213
  }
9214
+ ensurePolicies() {
9215
+ if (this.projectPolicyId) return;
9216
+ const now = this.now();
9217
+ const general = this.newPolicy({
9218
+ name: MOCK_PRESET_NAMES["general-community"],
9219
+ settings: { categorySettings: {} },
9220
+ automaticUpdates: true,
9221
+ preset: {
9222
+ id: "general-community",
9223
+ version: 1,
9224
+ own: true
9225
+ },
9226
+ createdAt: now
9227
+ });
9228
+ this.projectPolicyId = general.id;
9229
+ }
9230
+ newPolicy(values) {
9231
+ const policy = {
9232
+ id: this.createId("pol"),
9233
+ name: values.name,
9234
+ description: values.description ?? "",
9235
+ settings: values.settings,
9236
+ revision: 1,
9237
+ automaticUpdates: values.automaticUpdates ?? false,
9238
+ preset: values.preset ?? null,
9239
+ baseline: structuredClone(values.settings),
9240
+ createdAt: values.createdAt,
9241
+ updatedAt: values.createdAt
9242
+ };
9243
+ this.policies.set(policy.id, policy);
9244
+ return policy;
9245
+ }
9246
+ toPolicy(policy) {
9247
+ const { baseline: _baseline, preset, ...rest } = policy;
9248
+ return {
9249
+ ...structuredClone(rest),
9250
+ preset: preset && {
9251
+ ...preset,
9252
+ latestVersion: 1
9253
+ },
9254
+ projectIds: policy.id === this.projectPolicyId ? [this.projectId] : []
9255
+ };
9256
+ }
9257
+ findPolicy(policyId) {
9258
+ this.ensurePolicies();
9259
+ const policy = this.policies.get(policyId);
9260
+ if (!policy) throw fail(API_ERROR_CODES.POLICY_NOT_FOUND);
9261
+ return policy;
9262
+ }
9263
+ listPolicies() {
9264
+ this.ensurePolicies();
9265
+ return {
9266
+ policies: [...this.policies.values()].map((policy) => this.toPolicy(policy)),
9267
+ projectPolicyId: this.projectPolicyId
9268
+ };
9269
+ }
9270
+ createPolicy(body) {
9271
+ this.ensurePolicies();
9272
+ const { name, description, settings, presetId } = body;
9273
+ const preset = typeof presetId === "string" ? presetId : void 0;
9274
+ if (settings === void 0 === (preset === void 0) || preset !== void 0 && !(preset in MOCK_PRESET_NAMES) || preset === void 0 && (typeof name !== "string" || !name.trim())) throw fail(API_ERROR_CODES.INVALID_VALUE, { message: "Send settings with a name, or presetId" });
9275
+ const policy = this.newPolicy({
9276
+ name: typeof name === "string" && name.trim() ? name.trim() : MOCK_PRESET_NAMES[preset],
9277
+ ...typeof description === "string" ? { description } : {},
9278
+ settings: preset ? { categorySettings: {} } : settings,
9279
+ ...preset ? { preset: {
9280
+ id: preset,
9281
+ version: 1,
9282
+ own: false
9283
+ } } : {},
9284
+ createdAt: this.now()
9285
+ });
9286
+ return this.toPolicy(policy);
9287
+ }
9288
+ /** Saves new values under the next revision, once `revision` is the current one. */
9289
+ savePolicy(policy, revision, values) {
9290
+ if (revision !== policy.revision) throw fail(API_ERROR_CODES.POLICY_REVISION_CONFLICT);
9291
+ const saved = {
9292
+ ...policy,
9293
+ ...values,
9294
+ revision: policy.revision + 1,
9295
+ updatedAt: this.now()
9296
+ };
9297
+ this.policies.set(policy.id, saved);
9298
+ return this.toPolicy(saved);
9299
+ }
9300
+ updatePolicy(policyId, body) {
9301
+ const policy = this.findPolicy(policyId);
9302
+ return this.savePolicy(policy, body.revision, {
9303
+ ...typeof body.name === "string" ? { name: body.name.trim() } : {},
9304
+ ...typeof body.description === "string" ? { description: body.description } : {},
9305
+ ...body.settings !== void 0 ? { settings: body.settings } : {},
9306
+ automaticUpdates: false
9307
+ });
9308
+ }
9309
+ applyPolicyPreset(policyId, body) {
9310
+ const policy = this.findPolicy(policyId);
9311
+ if (!policy.preset || policy.automaticUpdates) throw fail(API_ERROR_CODES.POLICY_NO_PRESET);
9312
+ if (body.presetVersion !== policy.preset.version) throw fail(API_ERROR_CODES.POLICY_PRESET_VERSION_CONFLICT);
9313
+ if (body.operation === "update") throw fail(API_ERROR_CODES.POLICY_PRESET_UPDATE_UNAVAILABLE);
9314
+ return this.savePolicy(policy, body.revision, { settings: structuredClone(policy.baseline) });
9315
+ }
9316
+ setPolicyAutomaticUpdates(policyId, body) {
9317
+ const policy = this.findPolicy(policyId);
9318
+ const enabled = body.enabled === true;
9319
+ if (!policy.preset?.own || policy.automaticUpdates === enabled) throw fail(API_ERROR_CODES.POLICY_AUTOMATIC_UPDATES_UNAVAILABLE);
9320
+ if (body.revision !== policy.revision) throw fail(API_ERROR_CODES.POLICY_REVISION_CONFLICT);
9321
+ if (body.presetVersion !== 1) throw fail(API_ERROR_CODES.POLICY_PRESET_VERSION_CONFLICT);
9322
+ return this.savePolicy(policy, body.revision, {
9323
+ automaticUpdates: enabled,
9324
+ ...enabled ? {
9325
+ name: MOCK_PRESET_NAMES[policy.preset.id],
9326
+ description: "",
9327
+ settings: structuredClone(policy.baseline)
9328
+ } : {}
9329
+ });
9330
+ }
9331
+ deletePolicy(policyId) {
9332
+ const policy = this.findPolicy(policyId);
9333
+ if (policy.id === this.projectPolicyId) throw fail(API_ERROR_CODES.POLICY_IN_USE);
9334
+ this.policies.delete(policy.id);
9335
+ return {};
9336
+ }
9337
+ assignPolicy(body) {
9338
+ const policy = this.findPolicy(String(body.policyId));
9339
+ this.projectPolicyId = policy.id;
9340
+ return this.toPolicy(policy);
9341
+ }
9112
9342
  createHashList(body) {
9113
9343
  const { name, description, action } = body;
9114
9344
  if (typeof name !== "string" || !name.trim() || action !== "flag" && action !== "block") throw fail(API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "A hash list needs a name and an action of flag or block" });
@@ -9292,6 +9522,8 @@ var MockCalmLensApi = class {
9292
9522
  });
9293
9523
  }
9294
9524
  async updateAsset(assetId, body) {
9525
+ checkMetadata(body.metadata);
9526
+ if (body.name === null) throw invalidField("validation/invalid-type", "name");
9295
9527
  const asset = await this.findOwnAsset(assetId);
9296
9528
  if (body.externalId) {
9297
9529
  if ((await this.databaseStorage.listAssets(this.projectId)).some((other) => other.id !== asset.id && other.externalId === body.externalId)) throw fail(API_ERROR_CODES.DUPLICATE_EXTERNAL_ID);
@@ -9319,6 +9551,13 @@ var MockCalmLensApi = class {
9319
9551
  });
9320
9552
  }
9321
9553
  async createSignedUrl(assetId, body) {
9554
+ for (const key of [
9555
+ "viewerClaims",
9556
+ "resource",
9557
+ "lens",
9558
+ "transform",
9559
+ "expiresInSeconds"
9560
+ ]) if (body[key] === null) throw invalidField(key === "resource" ? "validation/invalid-value" : "validation/invalid-type", key);
9322
9561
  const asset = await this.findOwnAsset(assetId);
9323
9562
  const expiresInSeconds = body.expiresInSeconds ?? 900;
9324
9563
  const resource = body.resource ?? "rendered";
@@ -9438,7 +9677,11 @@ var MockCalmLensApi = class {
9438
9677
  /** The upload fields of `POST .../assets`: raw uploads carry them in the query. */
9439
9678
  uploadFields(request) {
9440
9679
  const upload = request.headers.get("x-calmlens-upload");
9441
- if (upload !== "content" && upload !== "part") return this.json(request);
9680
+ if (upload !== "content" && upload !== "part") {
9681
+ const body = this.json(request);
9682
+ checkMetadata(body.metadata);
9683
+ return body;
9684
+ }
9442
9685
  const { query } = request;
9443
9686
  const text = (name) => query.get(name) ?? void 0;
9444
9687
  const parsed = (name) => {
@@ -9451,6 +9694,7 @@ var MockCalmLensApi = class {
9451
9694
  }
9452
9695
  };
9453
9696
  const total = query.get("totalSizeInBytes");
9697
+ checkMetadata(parsed("metadata"));
9454
9698
  return {
9455
9699
  name: query.get("name") ?? "",
9456
9700
  description: text("description"),
@@ -9479,7 +9723,7 @@ var MockCalmLensApi = class {
9479
9723
  if (!fields.name) throw fail(API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset name is required" });
9480
9724
  const { contentType, part } = fields;
9481
9725
  const bytes = fields.bytes ?? /* @__PURE__ */ new Uint8Array(0);
9482
- if (contentType !== void 0 && isRejectedUploadMimeType(contentType)) throw fail(API_ERROR_CODES.INVALID_UPLOAD_MIME_TYPE, {
9726
+ if (contentType !== void 0 && !isAcceptedUploadMimeType(contentType)) throw fail(API_ERROR_CODES.INVALID_UPLOAD_MIME_TYPE, {
9483
9727
  message: getRejectedUploadMimeTypeError(contentType),
9484
9728
  details: { mimeType: contentType }
9485
9729
  });
@@ -9487,7 +9731,7 @@ var MockCalmLensApi = class {
9487
9731
  if (part) {
9488
9732
  if (part.partNumber > 1) throw fail(API_ERROR_CODES.USE_UPLOAD_PART);
9489
9733
  const partSize = bytes.byteLength;
9490
- const sizeError = (part.totalSizeInBytes === void 0 ? void 0 : this.multipartImageSizeError(type, part.totalSizeInBytes, true)) ?? (part.isFinal ? this.multipartTotalSizeError(part.totalSizeInBytes, partSize, true) ?? this.multipartImageSizeError(type, partSize, true) : void 0);
9734
+ const sizeError = (part.totalSizeInBytes === void 0 ? void 0 : this.multipartImageSizeError(type, part.totalSizeInBytes)) ?? (part.isFinal ? this.multipartTotalSizeError(part.totalSizeInBytes, partSize, true) ?? this.multipartImageSizeError(type, partSize) : void 0);
9491
9735
  if (sizeError) throw fail(sizeError);
9492
9736
  const validation = validateAssetPayload({ uint8Array: bytes }, {
9493
9737
  multipart: true,
@@ -9599,7 +9843,7 @@ var MockCalmLensApi = class {
9599
9843
  });
9600
9844
  const received = (asset.content.sizeInBytes ?? 0) + bytes.byteLength;
9601
9845
  const upload = this.openUploads.get(assetId);
9602
- const sizeError = this.multipartImageSizeError(asset.type, received, isFinal) ?? this.multipartTotalSizeError(upload?.totalSizeInBytes, received, isFinal);
9846
+ const sizeError = this.multipartImageSizeError(asset.type, received) ?? this.multipartTotalSizeError(upload?.totalSizeInBytes, received, isFinal);
9603
9847
  if (sizeError) throw fail(sizeError);
9604
9848
  const validation = validateAssetPayload({ uint8Array: bytes }, {
9605
9849
  multipart: true,
@@ -9636,11 +9880,10 @@ var MockCalmLensApi = class {
9636
9880
  this.recordProcessingEvents(stored, decision);
9637
9881
  return stored;
9638
9882
  }
9639
- /** Like the API: image uploads in parts total 10 MiB (checked at the last part) to 20 MiB. */
9640
- multipartImageSizeError(type, sizeInBytes, isFinal) {
9883
+ /** Like the API: image uploads in parts total at most 20 MiB, at any size below that. */
9884
+ multipartImageSizeError(type, sizeInBytes) {
9641
9885
  if (type !== "image") return void 0;
9642
9886
  if (sizeInBytes > MAX_IMAGE_UPLOAD_BYTES) return API_ERROR_CODES.MULTIPART_IMAGE_TOO_LARGE;
9643
- if (isFinal && sizeInBytes < MIN_MULTIPART_IMAGE_UPLOAD_BYTES) return API_ERROR_CODES.MULTIPART_IMAGE_TOO_SMALL;
9644
9887
  }
9645
9888
  /** Like the API: the parts may not overshoot a declared total, and must reach it at the end. */
9646
9889
  multipartTotalSizeError(totalSizeInBytes, receivedSizeInBytes, isFinal) {
@@ -9912,7 +10155,8 @@ var MockCalmLensApi = class {
9912
10155
  if (!cursor) return {
9913
10156
  items: [],
9914
10157
  nextCursor: `mock_${this.eventFeed.length}`,
9915
- hasMore: false
10158
+ hasMore: false,
10159
+ excludedTypes: []
9916
10160
  };
9917
10161
  const match = /^mock_(\d+)$/.exec(cursor);
9918
10162
  const position = match ? Number(match[1]) : NaN;
@@ -9922,7 +10166,8 @@ var MockCalmLensApi = class {
9922
10166
  return {
9923
10167
  items,
9924
10168
  nextCursor: `mock_${next}`,
9925
- hasMore: next < this.eventFeed.length
10169
+ hasMore: next < this.eventFeed.length,
10170
+ excludedTypes: []
9926
10171
  };
9927
10172
  }
9928
10173
  /**
@@ -10067,7 +10312,7 @@ var MockCalmLensApi = class {
10067
10312
  this.lenses.set(lens.identifier, lens);
10068
10313
  return lens;
10069
10314
  }
10070
- if (existing.name === options.name && (existing.description ?? null) === (options.description ?? null) && existing.type === options.type && existing.active === options.active && stringifyJsonCanonical(existing.transforms ?? null) === stringifyJsonCanonical(options.transforms ?? null) && existing.version === options.version) return existing;
10315
+ if (existing.name === options.name && (existing.description ?? null) === (options.description ?? null) && existing.type === options.type && existing.active === options.active && stringifyJsonCanonical(existing.transform ?? null) === stringifyJsonCanonical(options.transform ?? null) && existing.version === options.version) return existing;
10071
10316
  if (options.version > existing.version) {
10072
10317
  const lens = {
10073
10318
  ...existing,
@@ -10096,6 +10341,17 @@ var MockCalmLensApi = class {
10096
10341
  code: "asset/not-found",
10097
10342
  message: "Asset not found"
10098
10343
  }, url);
10344
+ const invalidTransform = () => this.jsonResponse(400, {
10345
+ code: "asset/invalid-transform",
10346
+ message: "Invalid transform selector"
10347
+ }, url);
10348
+ let selector;
10349
+ try {
10350
+ selector = parseTransformSelector(request.rawSegments.slice(4).join("/"));
10351
+ } catch {
10352
+ return invalidTransform();
10353
+ }
10354
+ if (resource === "original" && (selector.lens || selector.options)) return invalidTransform();
10099
10355
  if (root !== "assets" || projectId !== this.projectId || !assetIdentifier) return notFound();
10100
10356
  const asset = (await this.databaseStorage.listAssets(this.projectId)).find((asset) => asset.id === assetIdentifier || asset.externalId === assetIdentifier);
10101
10357
  if (!asset) return notFound();
@@ -10133,6 +10389,13 @@ var MockCalmLensApi = class {
10133
10389
  code: "asset/api-key-missing-permission",
10134
10390
  message: "This API key needs assets:download permission for this asset’s folder."
10135
10391
  }, url);
10392
+ if (selector.options) {
10393
+ const { unknownKeys, invalidKeys } = checkTransformOptions(selector.options);
10394
+ if (unknownKeys.length || invalidKeys.length) return this.jsonResponse(400, {
10395
+ code: "asset/invalid-transform-options",
10396
+ message: `Invalid transform options: ${[...unknownKeys, ...invalidKeys].join(", ")}`
10397
+ }, url);
10398
+ }
10136
10399
  const parts = [...storedContent.parts.entries()].sort(([left], [right]) => left - right).map(([, value]) => value);
10137
10400
  const bytes = new Uint8Array(parts.reduce((sum, value) => sum + value.byteLength, 0));
10138
10401
  let offset = 0;
@@ -10241,7 +10504,6 @@ var InMemoryMockDatabaseStorage = class {
10241
10504
  this.folders.delete(folderId);
10242
10505
  }
10243
10506
  };
10244
- // src/testing/MockCalmLensServerClient.ts
10245
10507
  const apis = /* @__PURE__ */ new WeakMap();
10246
10508
  /** The in-memory API a mock server client runs against, for `MockCalmLensAppClient`. */
10247
10509
  const getMockApi = (client) => {
@@ -10289,7 +10551,11 @@ var MockCalmLensServerClient = class extends CalmLensServerClient {
10289
10551
  * `mockOptions`. `maxRetries` defaults to 0, so a failed request fails once; retry backoff and
10290
10552
  * `assets.waitForDecision` take no real time.
10291
10553
  */
10292
- constructor(options) {
10554
+ constructor(input) {
10555
+ const options = {
10556
+ ...input,
10557
+ projectId: input.projectId ?? "project-1"
10558
+ };
10293
10559
  validateServerClientOptions(options);
10294
10560
  const { mockOptions = {}, ...clientOptions } = options;
10295
10561
  const api = new MockCalmLensApi({
@@ -10391,7 +10657,6 @@ var MockCalmLensServerClient = class extends CalmLensServerClient {
10391
10657
  }
10392
10658
  };
10393
10659
  // src/testing/MockCalmLensAppClient.ts
10394
- const MOCK_PROJECT_ID = "proj_0000000000000000c1a5";
10395
10660
  /**
10396
10661
  * The real `CalmLensAppClient`, answered by the in-memory API of a `MockCalmLensServerClient`.
10397
10662
  * The API applies `mockOptions.preset` to this client's uploads like CalmLens applies an upload
@@ -10414,7 +10679,6 @@ var MockCalmLensAppClient = class extends CalmLensAppClient {
10414
10679
  folderId: null,
10415
10680
  includeSubfolders: true
10416
10681
  }]),
10417
- projectId: MOCK_PROJECT_ID,
10418
10682
  mockOptions: { moderate: mockOptions.moderate }
10419
10683
  });
10420
10684
  let endpoints;
@@ -1,5 +1,5 @@
1
- import { Dt as ViewerClaims, k as CdnTransform, m as AssetModerationStatus, w as CalmLensAppClientOptions } from "./CalmLensTypes-9Vt16pc7.js";
2
- import { t as CalmLensAppClient } from "./CalmLensAppClient-CV_K26Ce.js";
1
+ import { E as CalmLensAppClientOptions, Mt as ViewerClaims, h as AssetModerationStatus, j as CdnTransform } from "./CalmLensTypes-COJbOuiv.js";
2
+ import { t as CalmLensAppClient } from "./CalmLensAppClient-DDLojj0P.js";
3
3
  /**
4
4
  * The parts of an asset, as the API or a webhook returns it, that the media component reads.
5
5
  * Assets from `CalmLensServerClient` fit as they are.
@@ -469,13 +469,26 @@ declare const ICON_ATTRIBUTES: {
469
469
  readonly "stroke-linejoin": "round";
470
470
  readonly "aria-hidden": "true";
471
471
  };
472
+ interface ProgressFetchOptions {
473
+ /**
474
+ * The size of everything this fetch will send, such as the file's size. An upload larger than
475
+ * the client's `partSizeBytes` goes in several requests, and only this total keeps the
476
+ * reported share of the file from restarting with each part.
477
+ */
478
+ totalBytes?: number;
479
+ }
472
480
  /**
473
481
  * A `fetch` that reports how many bytes of the request body have been sent, which `fetch` itself
474
482
  * can't do. It sends through `XMLHttpRequest`, so the upload components pass it to
475
483
  * `CalmLensAppClient` as `uploadFetch`. Without `XMLHttpRequest` it falls back to `fetch` and
476
484
  * reports nothing.
485
+ *
486
+ * The count runs across the requests sent through it: `sentBytes` adds the bodies of earlier
487
+ * requests that succeeded, so a file uploaded in parts keeps counting up. `totalBytes` is
488
+ * `options.totalBytes` when given, otherwise those earlier bodies plus the current one. Create
489
+ * one for each file.
477
490
  */
478
- declare const createProgressFetch: (onProgress: (sentBytes: number, totalBytes: number) => void) => ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>);
491
+ declare const createProgressFetch: (onProgress: (sentBytes: number, totalBytes: number) => void, { totalBytes }?: ProgressFetchOptions) => ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>);
479
492
  /**
480
493
  * The components' stylesheet, also shipped as `calmlens/styles.css`. The React components
481
494
  * render it themselves (React hoists it into the head, on the server too); with Vue, Svelte or
@@ -523,4 +536,4 @@ declare const CALMLENS_THEME: {
523
536
  * as the stylesheet mixes them from the page's text colour.
524
537
  */
525
538
  declare const resolveTheme: (overrides?: Partial<CalmLensTheme>) => CalmLensTheme;
526
- export { CustomUploadResult as A, MediaAsset as B, getDropzoneHint as C, resolveMessages as D, getUploadItemOutcome as E, UploadItem as F, MediaState as G, MediaOptions as H, UploadSnapshot as I, resolveMediaProps as J, getMediaState as K, UploadStage as L, UploadController as M, UploadControllerOptions as N, CalmLensUpload as O, UploadFile as P, createUploadController as R, formatMessage as S, getUploadItemMessage as T, MediaSettings as U, MediaImageSource as V, MediaSource as W, UploadItemView as _, createProgressFetch as a, describeUploader as b, IconName as c, UploaderDisplayOptions as d, UploaderProps as f, DEFAULT_MESSAGES as g, CalmLensMessages as h, CALMLENS_STYLES as i, UploadClient as j, CustomUploadContext as k, MediaDisplayOptions as l, getMediaLoadKey as m, CalmLensTheme as n, ICONS as o, getMediaAspectRatio as p, pickMediaSource as q, resolveTheme as r, ICON_ATTRIBUTES as s, CALMLENS_THEME as t, MediaProps as u, UploaderView as v, getMediaUnavailableMessage as w, formatBytes as x, describeUploadItem as y, isFileAccepted as z };
539
+ export { CustomUploadContext as A, isFileAccepted as B, formatMessage as C, getUploadItemOutcome as D, getUploadItemMessage as E, UploadFile as F, MediaSource as G, MediaImageSource as H, UploadItem as I, pickMediaSource as J, MediaState as K, UploadSnapshot as L, UploadClient as M, UploadController as N, resolveMessages as O, UploadControllerOptions as P, UploadStage as R, formatBytes as S, getMediaUnavailableMessage as T, MediaOptions as U, MediaAsset as V, MediaSettings as W, resolveMediaProps as Y, DEFAULT_MESSAGES as _, ProgressFetchOptions as a, describeUploadItem as b, ICON_ATTRIBUTES as c, MediaProps as d, UploaderDisplayOptions as f, CalmLensMessages as g, getMediaLoadKey as h, CALMLENS_STYLES as i, CustomUploadResult as j, CalmLensUpload as k, IconName as l, getMediaAspectRatio as m, CalmLensTheme as n, createProgressFetch as o, UploaderProps as p, getMediaState as q, resolveTheme as r, ICONS as s, CALMLENS_THEME as t, MediaDisplayOptions as u, UploadItemView as v, getDropzoneHint as w, describeUploader as x, UploaderView as y, createUploadController as z };
@@ -1,6 +1,5 @@
1
- import { g as transformSelector, p as serializeTransform, u as getAssetUrl } from "./ModerationContextLimits-KMQ8puoa.js";
2
- import { t as EU_COUNTRIES } from "./Jurisdiction-FusEXb4U-1ov6m5yE.js";
3
- import { a as placeholderHashToDataURL } from "./UploadController-Cs-bxUbt.js";
1
+ import { E as EU_COUNTRIES, _ as serializeTransform, b as transformSelector, f as getAssetUrl } from "./ModerationContextLimits-Chw-AzgL.js";
2
+ import { a as placeholderHashToDataURL } from "./UploadController-BJZghJpg.js";
4
3
  import { a as getFileIcon, c as renderFileIconSvg } from "./FileIcons-M6dzjFxd.js";
5
4
  // src/ui/Icons.ts
6
5
  /** Path data for the components' 24×24 stroke icons, so every framework draws the same ones. */
@@ -47,7 +46,14 @@ const decodePlaceholderHash = (hash) => {
47
46
  }
48
47
  return decodedPlaceholders.get(hash);
49
48
  };
50
- const joinTransforms = (base, extra) => [transformSelector(base), extra && serializeTransform(extra)].filter(Boolean).join(",") || void 0;
49
+ const withWidth = (base, width) => {
50
+ if (width === void 0) return base;
51
+ if (base === void 0 || typeof base !== "string") return {
52
+ ...base,
53
+ width
54
+ };
55
+ return [transformSelector(base), serializeTransform({ width })].filter(Boolean).join(",");
56
+ };
51
57
  /**
52
58
  * Fills the props left unset from `asset`, if there is one: the project and ID, its moderation
53
59
  * status, `video` or `audio` for those asset types, and its stored preview's ThumbHash, average
@@ -126,7 +132,7 @@ const buildMediaState = ({ projectId, assetId, status = "allowed", contentRemove
126
132
  ...asset,
127
133
  resource: chosen,
128
134
  lens: rendered ? lens : void 0,
129
- transform: rendered ? joinTransforms(transform, options.extra) : void 0
135
+ transform: rendered ? withWidth(transform, options.width) : void 0
130
136
  });
131
137
  };
132
138
  if (type === "audio") return {
@@ -144,10 +150,7 @@ const buildMediaState = ({ projectId, assetId, status = "allowed", contentRemove
144
150
  placeholderUrl
145
151
  };
146
152
  const sources = [...new Set(widths ?? [])].filter((width) => Number.isSafeInteger(width) && width > 0).sort((a, b) => a - b).map((width) => ({
147
- src: build({ extra: {
148
- type: "imageTransform",
149
- options: { width }
150
- } }),
153
+ src: build({ width }),
151
154
  width
152
155
  }));
153
156
  return {
package/esm/ui.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as CustomUploadResult, B as MediaAsset, C as getDropzoneHint, D as resolveMessages, E as getUploadItemOutcome, F as UploadItem, G as MediaState, H as MediaOptions, I as UploadSnapshot, J as resolveMediaProps, K as getMediaState, L as UploadStage, M as UploadController, N as UploadControllerOptions, O as CalmLensUpload, P as UploadFile, R as createUploadController, S as formatMessage, T as getUploadItemMessage, U as MediaSettings, V as MediaImageSource, W as MediaSource, _ as UploadItemView, a as createProgressFetch, b as describeUploader, c as IconName, d as UploaderDisplayOptions, f as UploaderProps, g as DEFAULT_MESSAGES, h as CalmLensMessages, i as CALMLENS_STYLES, j as UploadClient, k as CustomUploadContext, l as MediaDisplayOptions, m as getMediaLoadKey, n as CalmLensTheme, o as ICONS, p as getMediaAspectRatio, q as pickMediaSource, r as resolveTheme, s as ICON_ATTRIBUTES, t as CALMLENS_THEME, u as MediaProps, v as UploaderView, w as getMediaUnavailableMessage, x as formatBytes, y as describeUploadItem, z as isFileAccepted } from "./ui-wIiMfqMB.js";
2
- export { CALMLENS_STYLES, CALMLENS_THEME, type CalmLensMessages, type CalmLensTheme, type CalmLensUpload, type CustomUploadContext, type CustomUploadResult, DEFAULT_MESSAGES, ICONS, ICON_ATTRIBUTES, type IconName, type MediaAsset, type MediaDisplayOptions, type MediaImageSource, type MediaOptions, type MediaProps, type MediaSettings, type MediaSource, type MediaState, type UploadClient, UploadController, type UploadControllerOptions, type UploadFile, type UploadItem, type UploadItemView, type UploadSnapshot, type UploadStage, type UploaderDisplayOptions, type UploaderProps, type UploaderView, createProgressFetch, createUploadController, describeUploadItem, describeUploader, formatBytes, formatMessage, getDropzoneHint, getMediaAspectRatio, getMediaLoadKey, getMediaState, getMediaUnavailableMessage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, pickMediaSource, resolveMediaProps, resolveMessages, resolveTheme };
1
+ import { A as CustomUploadContext, B as isFileAccepted, C as formatMessage, D as getUploadItemOutcome, E as getUploadItemMessage, F as UploadFile, G as MediaSource, H as MediaImageSource, I as UploadItem, J as pickMediaSource, K as MediaState, L as UploadSnapshot, M as UploadClient, N as UploadController, O as resolveMessages, P as UploadControllerOptions, R as UploadStage, S as formatBytes, T as getMediaUnavailableMessage, U as MediaOptions, V as MediaAsset, W as MediaSettings, Y as resolveMediaProps, _ as DEFAULT_MESSAGES, a as ProgressFetchOptions, b as describeUploadItem, c as ICON_ATTRIBUTES, d as MediaProps, f as UploaderDisplayOptions, g as CalmLensMessages, h as getMediaLoadKey, i as CALMLENS_STYLES, j as CustomUploadResult, k as CalmLensUpload, l as IconName, m as getMediaAspectRatio, n as CalmLensTheme, o as createProgressFetch, p as UploaderProps, q as getMediaState, r as resolveTheme, s as ICONS, t as CALMLENS_THEME, u as MediaDisplayOptions, v as UploadItemView, w as getDropzoneHint, x as describeUploader, y as UploaderView, z as createUploadController } from "./ui-BSqPGKrZ.js";
2
+ export { CALMLENS_STYLES, CALMLENS_THEME, type CalmLensMessages, type CalmLensTheme, type CalmLensUpload, type CustomUploadContext, type CustomUploadResult, DEFAULT_MESSAGES, ICONS, ICON_ATTRIBUTES, type IconName, type MediaAsset, type MediaDisplayOptions, type MediaImageSource, type MediaOptions, type MediaProps, type MediaSettings, type MediaSource, type MediaState, type ProgressFetchOptions, type UploadClient, UploadController, type UploadControllerOptions, type UploadFile, type UploadItem, type UploadItemView, type UploadSnapshot, type UploadStage, type UploaderDisplayOptions, type UploaderProps, type UploaderView, createProgressFetch, createUploadController, describeUploadItem, describeUploader, formatBytes, formatMessage, getDropzoneHint, getMediaAspectRatio, getMediaLoadKey, getMediaState, getMediaUnavailableMessage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, pickMediaSource, resolveMediaProps, resolveMessages, resolveTheme };
package/esm/ui.js CHANGED
@@ -1,3 +1,3 @@
1
- import { _ as getMediaState, a as getMediaAspectRatio, b as ICONS, c as describeUploadItem, d as formatMessage, f as getDropzoneHint, g as resolveMessages, h as getUploadItemOutcome, i as resolveTheme, l as describeUploader, m as getUploadItemMessage, o as getMediaLoadKey, p as getMediaUnavailableMessage, r as CALMLENS_THEME, s as DEFAULT_MESSAGES, t as CALMLENS_STYLES, u as formatBytes, v as pickMediaSource, x as ICON_ATTRIBUTES, y as resolveMediaProps } from "./ui-BqYkISSE.js";
2
- import { i as createProgressFetch, n as createUploadController, r as isFileAccepted, t as UploadController } from "./UploadController-Cs-bxUbt.js";
1
+ import { _ as getMediaState, a as getMediaAspectRatio, b as ICONS, c as describeUploadItem, d as formatMessage, f as getDropzoneHint, g as resolveMessages, h as getUploadItemOutcome, i as resolveTheme, l as describeUploader, m as getUploadItemMessage, o as getMediaLoadKey, p as getMediaUnavailableMessage, r as CALMLENS_THEME, s as DEFAULT_MESSAGES, t as CALMLENS_STYLES, u as formatBytes, v as pickMediaSource, x as ICON_ATTRIBUTES, y as resolveMediaProps } from "./ui-CXH7xJpb.js";
2
+ import { i as createProgressFetch, n as createUploadController, r as isFileAccepted, t as UploadController } from "./UploadController-BJZghJpg.js";
3
3
  export { CALMLENS_STYLES, CALMLENS_THEME, DEFAULT_MESSAGES, ICONS, ICON_ATTRIBUTES, UploadController, createProgressFetch, createUploadController, describeUploadItem, describeUploader, formatBytes, formatMessage, getDropzoneHint, getMediaAspectRatio, getMediaLoadKey, getMediaState, getMediaUnavailableMessage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, pickMediaSource, resolveMediaProps, resolveMessages, resolveTheme };