calmlens 0.29.1 → 0.29.2

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 (50) hide show
  1. package/bin/calmlens.js +24 -2
  2. package/cjs/{BrowserUpload-CsxEB1Pr.js → BrowserUpload-CCXt4DAY.js} +1 -1
  3. package/cjs/{CalmLensAppClient-BWMcQM9v.js → CalmLensAppClient-ea-qXkmD.js} +7 -6
  4. package/cjs/{CalmLensConnection-DBgV8D1B.js → CalmLensConnection-BrySN2M3.js} +29 -28
  5. package/cjs/CalmLensError-DPHJaVjX.js +1066 -0
  6. package/cjs/{CalmLensServerClient-DYO3geSA.js → CalmLensServerClient-FD7H7KvL.js} +21 -20
  7. package/cjs/{TestTriggers-uL2Ec8Vt-cPmmKvYd.js → CalmLensTestInputArguments-BXDBAOg_.js} +50 -22
  8. package/cjs/{Core-Bl-aESvN.js → Core-DMFa3EUp.js} +4 -3
  9. package/cjs/{ModerationContextLimits-DHu2jHpo.js → ModerationContextLimits-1XP4ZTQk.js} +67 -1126
  10. package/cjs/{ReactUpload-BFVNyWoI.js → ReactUpload-gaeiPSeH.js} +1 -1
  11. package/cjs/{TestTriggers-dognME9k-PWyIfHMI.d.ts → TestTriggers-CFnel6a9.d.ts} +1 -2
  12. package/cjs/{UploadController-VM1qYwNq.js → UploadController-CyPTBuZg.js} +6 -6
  13. package/cjs/app.js +22 -21
  14. package/cjs/elements.js +4 -4
  15. package/cjs/index.js +21 -20
  16. package/cjs/react-native.js +4 -4
  17. package/cjs/react.js +5 -5
  18. package/cjs/server.js +22 -21
  19. package/cjs/test-inputs.d.ts +6 -2
  20. package/cjs/test-inputs.js +23 -13
  21. package/cjs/testing.d.ts +3 -3
  22. package/cjs/testing.js +138 -133
  23. package/cjs/{ui-BCiLF8cU.js → ui-DNP1uWQy.js} +2 -2
  24. package/cjs/ui.js +3 -3
  25. package/cjs/vue.js +4 -4
  26. package/esm/{BrowserUpload-DB3WpaC1.js → BrowserUpload-Bu6eWqQS.js} +1 -1
  27. package/esm/{CalmLensAppClient-Dg-jPs4B.js → CalmLensAppClient-xp-fH6Lz.js} +3 -2
  28. package/esm/{CalmLensConnection-Di7K7Wnl.js → CalmLensConnection-DwG5yBk2.js} +2 -1
  29. package/esm/CalmLensError-BDWThPCr.js +917 -0
  30. package/esm/{CalmLensServerClient-Pdp7TI8y.js → CalmLensServerClient-CKlNBBo3.js} +3 -2
  31. package/esm/{TestTriggers-uL2Ec8Vt-DYbTEJWm.js → CalmLensTestInputArguments-Xh4GIadS.js} +22 -1
  32. package/esm/{Core-CKk4teFu.js → Core-DnCeTmvS.js} +3 -2
  33. package/esm/{ModerationContextLimits-xvxUjGfL.js → ModerationContextLimits-CtAyz60h.js} +3 -918
  34. package/esm/{ReactUpload-DY5qQ70s.js → ReactUpload-D30YlRui.js} +1 -1
  35. package/esm/{TestTriggers-dognME9k-PWyIfHMI.d.ts → TestTriggers-CFnel6a9.d.ts} +1 -2
  36. package/esm/{UploadController-wyor-5Z2.js → UploadController-DENryQ8H.js} +2 -2
  37. package/esm/app.js +3 -2
  38. package/esm/elements.js +4 -4
  39. package/esm/index.js +3 -1
  40. package/esm/react-native.js +4 -4
  41. package/esm/react.js +5 -5
  42. package/esm/server.js +3 -2
  43. package/esm/test-inputs.d.ts +6 -2
  44. package/esm/test-inputs.js +12 -1
  45. package/esm/testing.d.ts +3 -3
  46. package/esm/testing.js +11 -7
  47. package/esm/{ui-BqF49fSy.js → ui-DUEBbRJ0.js} +2 -2
  48. package/esm/ui.js +3 -3
  49. package/esm/vue.js +4 -4
  50. package/package.json +1 -1
package/cjs/testing.js CHANGED
@@ -1,15 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_TestTriggers_uL2Ec8Vt = require("./TestTriggers-uL2Ec8Vt-cPmmKvYd.js");
3
- const require_ModerationContextLimits = require("./ModerationContextLimits-DHu2jHpo.js");
4
- const require_CalmLensServerClient = require("./CalmLensServerClient-DYO3geSA.js");
5
- const require_CalmLensConnection = require("./CalmLensConnection-DBgV8D1B.js");
2
+ const require_CalmLensTestInputArguments = require("./CalmLensTestInputArguments-BXDBAOg_.js");
3
+ const require_CalmLensError = require("./CalmLensError-DPHJaVjX.js");
4
+ const require_ModerationContextLimits = require("./ModerationContextLimits-1XP4ZTQk.js");
5
+ const require_CalmLensServerClient = require("./CalmLensServerClient-FD7H7KvL.js");
6
+ const require_CalmLensConnection = require("./CalmLensConnection-BrySN2M3.js");
6
7
  const require_CryptoUtils_BLCa_oZe = require("./CryptoUtils-BLCa-oZe-leCkr1ko.js");
7
- const require_CalmLensAppClient = require("./CalmLensAppClient-BWMcQM9v.js");
8
- const require_UploadController = require("./UploadController-VM1qYwNq.js");
8
+ const require_CalmLensAppClient = require("./CalmLensAppClient-ea-qXkmD.js");
9
+ const require_UploadController = require("./UploadController-CyPTBuZg.js");
9
10
  let zod = require("zod");
10
- zod = require_TestTriggers_uL2Ec8Vt.__toESM(zod, 1);
11
+ let zod$1 = require_CalmLensTestInputArguments.__toESM(zod, 1);
12
+ zod = require_CalmLensTestInputArguments.__toESM(zod);
11
13
  // src/contract/MediaTestTriggers.js
12
- const MEDIA_TEST_SIGNALS = [...require_TestTriggers_uL2Ec8Vt.CLASSIFICATION_CATEGORIES, "violence.graphic"];
14
+ const MEDIA_TEST_SIGNALS = [...require_CalmLensTestInputArguments.CLASSIFICATION_CATEGORIES, "violence.graphic"];
13
15
  const HEX_WORDS = [
14
16
  "zero",
15
17
  "one",
@@ -29,9 +31,9 @@ const HEX_WORDS = [
29
31
  "foxtrot"
30
32
  ];
31
33
  /** Read this aloud, or render it as large, high-contrast text in a video frame. */
32
- async function generateMediaTestCode(signal, testInputKey) {
34
+ async function generateMediaTestCode$1(signal, testInputKey) {
33
35
  if (!MEDIA_TEST_SIGNALS.includes(signal)) throw new RangeError("Unsupported media test signal");
34
- return `Calm Lens test ${[...await require_TestTriggers_uL2Ec8Vt.getTestInputTag("media", signal, testInputKey)].map((character) => HEX_WORDS[Number.parseInt(character, 16)]).join(" ")} ${signal.replace(/[.-]/g, " ")} end test`;
36
+ return `Calm Lens test ${[...await require_CalmLensTestInputArguments.getTestInputTag("media", signal, testInputKey)].map((character) => HEX_WORDS[Number.parseInt(character, 16)]).join(" ")} ${signal.replace(/[.-]/g, " ")} end test`;
35
37
  }
36
38
  /**
37
39
  * The character an asset ID starts with (after `asset_`) to say the region it lives in: the asset
@@ -7919,7 +7921,7 @@ const isZodTypeExtends = (type, zodType) => {
7919
7921
  createMetaType({
7920
7922
  id: "foreignKey",
7921
7923
  check: (type) => {
7922
- if (isZodTypeExtends(type, zod.ZodString) || isZodTypeExtends(type, zod.ZodNumber)) return { success: true };
7924
+ if (isZodTypeExtends(type, zod$1.ZodString) || isZodTypeExtends(type, zod$1.ZodNumber)) return { success: true };
7923
7925
  return {
7924
7926
  success: false,
7925
7927
  message: "Foreign key must be a string or number"
@@ -7929,7 +7931,7 @@ createMetaType({
7929
7931
  createMetaType({
7930
7932
  id: "primaryKey",
7931
7933
  check: (type) => {
7932
- if (isZodTypeExtends(type, zod.ZodString) || isZodTypeExtends(type, zod.ZodNumber)) return { success: true };
7934
+ if (isZodTypeExtends(type, zod$1.ZodString) || isZodTypeExtends(type, zod$1.ZodNumber)) return { success: true };
7933
7935
  return {
7934
7936
  success: false,
7935
7937
  message: "Primary key must be a string or number"
@@ -8050,7 +8052,7 @@ const EXAMPLE_IDS = {
8050
8052
  * every stored model's IDs by prefix is a separate change (it surfaces about a thousand call sites
8051
8053
  * across the packages that build records from plain strings).
8052
8054
  */
8053
- 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]] });
8055
+ const idField = (prefix) => zod$1.string().regex(idPattern(prefix), { message: `Must be a valid ID: "${prefix}_" followed by 20 letters or digits` }).meta({ examples: [EXAMPLE_IDS[prefix]] });
8054
8056
  // src/contract/Permissions-Dwk78TtG.js
8055
8057
  /** Every permission action, in the order the docs and the portal list them. */
8056
8058
  const PERMISSION_ACTIONS = [
@@ -8086,7 +8088,7 @@ const PERMISSION_ACTIONS = [
8086
8088
  "reviews:write",
8087
8089
  "project:manage"
8088
8090
  ];
8089
- const ACTION_SCHEMA = /* @__PURE__ */ require_TestTriggers_uL2Ec8Vt.lazySchema(() => zod.enum(PERMISSION_ACTIONS));
8091
+ const ACTION_SCHEMA = /* @__PURE__ */ require_CalmLensTestInputArguments.lazySchema(() => zod$1.enum(PERMISSION_ACTIONS));
8090
8092
  const PROJECT_ACTIONS = [...[
8091
8093
  "settings",
8092
8094
  "members",
@@ -8102,12 +8104,12 @@ const PROJECT_ACTIONS = [...[
8102
8104
  const isProjectAction = (action) => PROJECT_ACTIONS.includes(action);
8103
8105
  /** The actions that include `action`: its feature's write action and project:manage. */
8104
8106
  const actionsImplying = (action) => !isProjectAction(action) || action === "project:manage" ? [] : action.endsWith(":read") ? [action.replace(/:read$/, ":write"), "project:manage"] : ["project:manage"];
8105
- const GRANT_SCHEMA = /* @__PURE__ */ require_TestTriggers_uL2Ec8Vt.lazySchema(() => zod.object({
8106
- actions: zod.array(ACTION_SCHEMA),
8107
+ const GRANT_SCHEMA = /* @__PURE__ */ require_CalmLensTestInputArguments.lazySchema(() => zod$1.object({
8108
+ actions: zod$1.array(ACTION_SCHEMA),
8107
8109
  folderId: idField("fldr").nullable(),
8108
- includeSubfolders: zod.boolean()
8110
+ includeSubfolders: zod$1.boolean()
8109
8111
  }).strict().refine((g) => g.folderId === null || !g.actions.some(isProjectAction), "Project configuration permissions require project scope"));
8110
- const GRANTS_SCHEMA = /* @__PURE__ */ require_TestTriggers_uL2Ec8Vt.lazySchema(() => zod.array(GRANT_SCHEMA).max(100));
8112
+ const GRANTS_SCHEMA = /* @__PURE__ */ require_CalmLensTestInputArguments.lazySchema(() => zod$1.array(GRANT_SCHEMA).max(100));
8111
8113
  [...PERMISSION_ACTIONS.filter((a) => !isProjectAction(a))];
8112
8114
  [...PERMISSION_ACTIONS.filter((a) => !isProjectAction(a))];
8113
8115
  const permits = (grants, action, folderId, folders) => grants.some((grant) => {
@@ -8349,7 +8351,7 @@ var MockDecision = class {
8349
8351
  #people;
8350
8352
  #faces;
8351
8353
  constructor(status) {
8352
- if (!OUTCOMES.includes(status)) throw require_ModerationContextLimits.invalidArgument(`status must be one of ${OUTCOMES.join(", ")}`);
8354
+ if (!OUTCOMES.includes(status)) throw require_CalmLensError.invalidArgument(`status must be one of ${OUTCOMES.join(", ")}`);
8353
8355
  this.status = status;
8354
8356
  }
8355
8357
  /**
@@ -8359,13 +8361,13 @@ var MockDecision = class {
8359
8361
  */
8360
8362
  flag(category, score, qualifiers = {}) {
8361
8363
  this.#checkCategory(category);
8362
- if (this.status === "pending" || this.status === "failed") throw require_ModerationContextLimits.invalidArgument(`a ${this.status} decision has no findings`);
8363
- if (this.#flags.has(category) || this.#notEvaluated.has(category)) throw require_ModerationContextLimits.invalidArgument(`${category} is already in this decision`);
8364
- if (!isScore(score)) throw require_ModerationContextLimits.invalidArgument(`${category}'s score must be from 0 to 1`);
8364
+ if (this.status === "pending" || this.status === "failed") throw require_CalmLensError.invalidArgument(`a ${this.status} decision has no findings`);
8365
+ if (this.#flags.has(category) || this.#notEvaluated.has(category)) throw require_CalmLensError.invalidArgument(`${category} is already in this decision`);
8366
+ if (!isScore(score)) throw require_CalmLensError.invalidArgument(`${category}'s score must be from 0 to 1`);
8365
8367
  const known = MOCK_QUALIFIERS[category];
8366
8368
  for (const [qualifier, qualifierScore] of Object.entries(qualifiers)) {
8367
- if (!known.includes(qualifier)) throw require_ModerationContextLimits.invalidArgument(`${qualifier} is not a qualifier of ${category}`);
8368
- if (!isScore(qualifierScore)) throw require_ModerationContextLimits.invalidArgument(`${qualifier}'s score must be from 0 to 1`);
8369
+ if (!known.includes(qualifier)) throw require_CalmLensError.invalidArgument(`${qualifier} is not a qualifier of ${category}`);
8370
+ if (!isScore(qualifierScore)) throw require_CalmLensError.invalidArgument(`${qualifier}'s score must be from 0 to 1`);
8369
8371
  }
8370
8372
  this.#flags.set(category, {
8371
8373
  score,
@@ -8376,8 +8378,8 @@ var MockDecision = class {
8376
8378
  /** Marks `category` as not assessed (`not-evaluated` for reason `not-supported`). */
8377
8379
  notEvaluated(category) {
8378
8380
  this.#checkCategory(category);
8379
- if (this.status === "pending" || this.status === "failed") throw require_ModerationContextLimits.invalidArgument(`a ${this.status} decision has no findings`);
8380
- if (this.#flags.has(category) || this.#notEvaluated.has(category)) throw require_ModerationContextLimits.invalidArgument(`${category} is already in this decision`);
8381
+ if (this.status === "pending" || this.status === "failed") throw require_CalmLensError.invalidArgument(`a ${this.status} decision has no findings`);
8382
+ if (this.#flags.has(category) || this.#notEvaluated.has(category)) throw require_CalmLensError.invalidArgument(`${category} is already in this decision`);
8381
8383
  this.#notEvaluated.add(category);
8382
8384
  return this;
8383
8385
  }
@@ -8387,9 +8389,9 @@ var MockDecision = class {
8387
8389
  * decision (`decide` on the mock) clears it; `assets.decide` doesn't, as with the API.
8388
8390
  */
8389
8391
  pendingReview(reason, uncertainCategories = []) {
8390
- if (this.status === "pending" || this.status === "failed") throw require_ModerationContextLimits.invalidArgument(`a ${this.status} decision can't wait for review`);
8391
- if (reason !== "sampled" && reason !== "uncertain") throw require_ModerationContextLimits.invalidArgument("reason must be sampled or uncertain");
8392
- if (reason === "sampled" && uncertainCategories.length) throw require_ModerationContextLimits.invalidArgument("a sampled review has no uncertain categories");
8392
+ if (this.status === "pending" || this.status === "failed") throw require_CalmLensError.invalidArgument(`a ${this.status} decision can't wait for review`);
8393
+ if (reason !== "sampled" && reason !== "uncertain") throw require_CalmLensError.invalidArgument("reason must be sampled or uncertain");
8394
+ if (reason === "sampled" && uncertainCategories.length) throw require_CalmLensError.invalidArgument("a sampled review has no uncertain categories");
8393
8395
  for (const category of uncertainCategories) this.#checkCategory(category);
8394
8396
  this.#pendingReview = {
8395
8397
  reason,
@@ -8453,7 +8455,7 @@ var MockDecision = class {
8453
8455
  return this.#linkDetection && structuredClone(this.#linkDetection);
8454
8456
  }
8455
8457
  #checkCategory(category) {
8456
- if (!MOCK_CATEGORIES.includes(category)) throw require_ModerationContextLimits.invalidArgument(`${category} is not a CalmLens category`);
8458
+ if (!MOCK_CATEGORIES.includes(category)) throw require_CalmLensError.invalidArgument(`${category} is not a CalmLens category`);
8457
8459
  }
8458
8460
  /**
8459
8461
  * The report a decided asset gets, as the API sends it: every category (unflagged ones
@@ -8953,7 +8955,7 @@ const createPage = (items, query, { scope, fail, defaultPageSize = 50, defaultSo
8953
8955
  const pageSize = query.pageSize ?? defaultPageSize;
8954
8956
  if (typeof pageSize !== "number" || !Number.isFinite(pageSize) || pageSize < 1) throw fail("validation/too-small", "pageSize");
8955
8957
  if (pageSize > 100) throw fail("validation/too-big", "pageSize");
8956
- if (!Number.isInteger(pageSize)) throw require_ModerationContextLimits.invalidArgument("Invalid page size");
8958
+ if (!Number.isInteger(pageSize)) throw require_CalmLensError.invalidArgument("Invalid page size");
8957
8959
  const ordering = query.sort?.length ? [...query.sort] : [...defaultSort];
8958
8960
  if (!ordering.some(({ field }) => field === "id")) ordering.push({
8959
8961
  field: "id",
@@ -9349,7 +9351,7 @@ const MOCK_UPLOAD_PRESET_KEYS = [
9349
9351
  */
9350
9352
  const checkMockUploadPreset = (preset) => {
9351
9353
  const unknown = Object.keys(preset).filter((key) => !MOCK_UPLOAD_PRESET_KEYS.includes(key));
9352
- if (unknown.length) throw require_ModerationContextLimits.invalidArgument(`Unknown mockOptions.preset key${unknown.length > 1 ? "s" : ""}: ${unknown.join(", ")}`, { options: unknown });
9354
+ if (unknown.length) throw require_CalmLensError.invalidArgument(`Unknown mockOptions.preset key${unknown.length > 1 ? "s" : ""}: ${unknown.join(", ")}`, { options: unknown });
9353
9355
  };
9354
9356
  const MAX_PAGE_SIZE = 100;
9355
9357
  /** Entries with a lower PDQ quality never match (HashList.ts, HASH_MATCH_MIN_QUALITY). */
@@ -9401,7 +9403,7 @@ const isStoredAsset = (value) => typeof value === "object" && value !== null &&
9401
9403
  const toDecision = (value) => {
9402
9404
  if (value instanceof MockDecision) return value;
9403
9405
  if (typeof value === "string") return new MockDecision(value);
9404
- throw require_ModerationContextLimits.invalidArgument("a decision must be a status or a mockDecision(...)");
9406
+ throw require_CalmLensError.invalidArgument("a decision must be a status or a mockDecision(...)");
9405
9407
  };
9406
9408
  /** An asset's portal link, as event facts carry it. */
9407
9409
  const assetNameFact = (asset) => ({
@@ -9560,8 +9562,8 @@ var ApiFailure = class {
9560
9562
  * `asset/duplicate-external-id`, naming the stored asset that holds the external ID in
9561
9563
  * `details.assetId`, like the API.
9562
9564
  */
9563
- const duplicateExternalId = (holder) => fail(require_ModerationContextLimits.API_ERROR_CODES.DUPLICATE_EXTERNAL_ID, { details: { assetId: holder.id } });
9564
- const fail = (code, { message, details } = {}) => new ApiFailure(require_ModerationContextLimits.API_ERROR_DEFINITIONS[code].status, code, message ?? require_ModerationContextLimits.API_ERROR_DEFINITIONS[code].message, details);
9565
+ const duplicateExternalId = (holder) => fail(require_CalmLensError.API_ERROR_CODES.DUPLICATE_EXTERNAL_ID, { details: { assetId: holder.id } });
9566
+ const fail = (code, { message, details } = {}) => new ApiFailure(require_CalmLensError.API_ERROR_DEFINITIONS[code].status, code, message ?? require_CalmLensError.API_ERROR_DEFINITIONS[code].message, details);
9565
9567
  /**
9566
9568
  * A request the API's schema refuses: `validation/invalid-request` with HTTP 400, listing the field
9567
9569
  * and its issue code (such as `validation/too-big`) in `details.issues`.
@@ -9590,7 +9592,7 @@ const decodeMockGrant = (segment) => {
9590
9592
  expiresAt: Number(match[3])
9591
9593
  };
9592
9594
  };
9593
- const invalidField = (code, path) => new ApiFailure(400, require_ModerationContextLimits.API_ERROR_CODES.INVALID_REQUEST, `Invalid ${path}`, { issues: [{
9595
+ const invalidField = (code, path) => new ApiFailure(400, require_CalmLensError.API_ERROR_CODES.INVALID_REQUEST, `Invalid ${path}`, { issues: [{
9594
9596
  path,
9595
9597
  message: `Invalid ${path}`,
9596
9598
  code
@@ -9626,9 +9628,9 @@ const indexOfBytes = (haystack, needle, from = 0) => {
9626
9628
  */
9627
9629
  const readUploadForm = (request) => {
9628
9630
  const contentType = request.headers.get("content-type") ?? "";
9629
- if (contentType.split(";")[0].trim().toLowerCase() !== "multipart/form-data") throw new ApiFailure(415, require_ModerationContextLimits.API_ERROR_CODES.UNSUPPORTED_CONTENT_TYPE, "Send a raw upload as multipart/form-data: an options part, then a file part.", { contentType: contentType.split(";")[0].trim() || null });
9631
+ if (contentType.split(";")[0].trim().toLowerCase() !== "multipart/form-data") throw new ApiFailure(415, require_CalmLensError.API_ERROR_CODES.UNSUPPORTED_CONTENT_TYPE, "Send a raw upload as multipart/form-data: an options part, then a file part.", { contentType: contentType.split(";")[0].trim() || null });
9630
9632
  const boundary = /;\s*boundary=(?:"([^"]+)"|([^;\s]+))/i.exec(contentType);
9631
- const invalid = (message) => fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message });
9633
+ const invalid = (message) => fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message });
9632
9634
  if (!boundary) throw invalid("The multipart/form-data Content-Type needs a boundary");
9633
9635
  const encoder = new TextEncoder();
9634
9636
  const delimiter = encoder.encode(`\r\n--${boundary[1] ?? boundary[2]}`);
@@ -9661,7 +9663,7 @@ const readUploadForm = (request) => {
9661
9663
  /** A request that names asset fields in its query, which the API refuses. */
9662
9664
  const assertNoUploadOptionsInQuery = (query) => {
9663
9665
  const fields = UPLOAD_OPTION_KEYS.filter((key) => query.has(key));
9664
- if (fields.length) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_OPTIONS_IN_QUERY, { details: { fields } });
9666
+ if (fields.length) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_OPTIONS_IN_QUERY, { details: { fields } });
9665
9667
  };
9666
9668
  /**
9667
9669
  * Refuses `metadata` the API's schema refuses (METADATA_ITEM_SCHEMA): it is `null` or a list of
@@ -9688,7 +9690,7 @@ const MOCK_PRESET_NAMES = {
9688
9690
  * personal information and profanity, `block` otherwise) and no rules. The mock holds no built-in
9689
9691
  * preset settings, and uploads are never decided by a policy.
9690
9692
  */
9691
- const mockPresetSettings = () => ({ categorySettings: Object.fromEntries(require_TestTriggers_uL2Ec8Vt.CLASSIFICATION_CATEGORIES.map((category) => [category, {
9693
+ const mockPresetSettings = () => ({ categorySettings: Object.fromEntries(require_CalmLensTestInputArguments.CLASSIFICATION_CATEGORIES.map((category) => [category, {
9692
9694
  action: category === "personal-information" || category === "profanity" ? "allow" : "block",
9693
9695
  allowances: [],
9694
9696
  restrictions: []
@@ -9700,13 +9702,13 @@ const mockPresetSettings = () => ({ categorySettings: Object.fromEntries(require
9700
9702
  const checkPolicySettings = (settings) => {
9701
9703
  const categories = settings?.categorySettings;
9702
9704
  if (!categories || typeof categories !== "object") throw invalidField("validation/invalid-type", "settings.categorySettings");
9703
- for (const category of require_TestTriggers_uL2Ec8Vt.CLASSIFICATION_CATEGORIES) {
9705
+ for (const category of require_CalmLensTestInputArguments.CLASSIFICATION_CATEGORIES) {
9704
9706
  const value = categories[category];
9705
9707
  if (!value || typeof value !== "object") throw invalidField("validation/invalid-type", `settings.categorySettings.${category}`);
9706
9708
  for (const key of ["allowances", "restrictions"]) if (!Array.isArray(value[key])) throw invalidField("validation/invalid-type", `settings.categorySettings.${category}.${key}`);
9707
9709
  if (typeof value.action !== "string") throw invalidField("validation/invalid-value", `settings.categorySettings.${category}.action`);
9708
9710
  }
9709
- for (const key of Object.keys(categories)) if (!require_TestTriggers_uL2Ec8Vt.CLASSIFICATION_CATEGORIES.includes(key)) throw invalidField("validation/unknown-field", `settings.categorySettings.${key}`);
9711
+ for (const key of Object.keys(categories)) if (!require_CalmLensTestInputArguments.CLASSIFICATION_CATEGORIES.includes(key)) throw invalidField("validation/unknown-field", `settings.categorySettings.${key}`);
9710
9712
  };
9711
9713
  /** The client methods that send a request, the one it is recorded under first. */
9712
9714
  const operationsOf = (request) => {
@@ -9848,7 +9850,7 @@ var MockCalmLensApi = class {
9848
9850
  this.policies = /* @__PURE__ */ new Map();
9849
9851
  this.hashLists = /* @__PURE__ */ new Map();
9850
9852
  this.hashListEntries = /* @__PURE__ */ new Map();
9851
- this.pageFailure = (code, path) => code === "cursor/invalid" ? fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_CURSOR) : invalidField(code, path ?? "pageSize");
9853
+ this.pageFailure = (code, path) => code === "cursor/invalid" ? fail(require_CalmLensError.API_ERROR_CODES.INVALID_CURSOR) : invalidField(code, path ?? "pageSize");
9852
9854
  this.configuredPresets = /* @__PURE__ */ new Map();
9853
9855
  this.settingsRevision = 1;
9854
9856
  this.projectSettingsValues = {};
@@ -9868,10 +9870,10 @@ var MockCalmLensApi = class {
9868
9870
  */
9869
9871
  failNextRequest(failure, options = {}) {
9870
9872
  const { times = 1, ...rest } = options;
9871
- if (times !== Number.POSITIVE_INFINITY && !(Number.isSafeInteger(times) && times >= 1)) throw require_ModerationContextLimits.invalidArgument("times must be a positive whole number");
9872
- if (options.operation !== void 0 && !MOCK_OPERATIONS.includes(options.operation)) throw require_ModerationContextLimits.invalidArgument(`${options.operation} is not a client method that sends requests`);
9873
- if (!(typeof failure === "string" && failure in require_ModerationContextLimits.API_ERROR_DEFINITIONS) && (options.details !== void 0 || options.retryAfter !== void 0)) throw require_ModerationContextLimits.invalidArgument("details and retryAfter apply only to an API error code");
9874
- if (options.retryAfter !== void 0 && !(Number.isInteger(options.retryAfter) && options.retryAfter >= 0)) throw require_ModerationContextLimits.invalidArgument("retryAfter must be a whole number of seconds");
9873
+ if (times !== Number.POSITIVE_INFINITY && !(Number.isSafeInteger(times) && times >= 1)) throw require_CalmLensError.invalidArgument("times must be a positive whole number");
9874
+ if (options.operation !== void 0 && !MOCK_OPERATIONS.includes(options.operation)) throw require_CalmLensError.invalidArgument(`${options.operation} is not a client method that sends requests`);
9875
+ if (!(typeof failure === "string" && failure in require_CalmLensError.API_ERROR_DEFINITIONS) && (options.details !== void 0 || options.retryAfter !== void 0)) throw require_CalmLensError.invalidArgument("details and retryAfter apply only to an API error code");
9876
+ if (options.retryAfter !== void 0 && !(Number.isInteger(options.retryAfter) && options.retryAfter >= 0)) throw require_CalmLensError.invalidArgument("retryAfter must be a whole number of seconds");
9875
9877
  this.pendingFailures.push({
9876
9878
  failure,
9877
9879
  remaining: times,
@@ -9891,11 +9893,11 @@ var MockCalmLensApi = class {
9891
9893
  try {
9892
9894
  key = new URL(url).href;
9893
9895
  } catch {
9894
- throw require_ModerationContextLimits.invalidArgument("url must be an absolute URL");
9896
+ throw require_CalmLensError.invalidArgument("url must be an absolute URL");
9895
9897
  }
9896
- if (typeof type !== "string" || !type.trim()) throw require_ModerationContextLimits.invalidArgument("type must be a content type, such as image/png");
9898
+ if (typeof type !== "string" || !type.trim()) throw require_CalmLensError.invalidArgument("type must be a content type, such as image/png");
9897
9899
  const bytes = typeof content === "string" ? new TextEncoder().encode(content) : content instanceof ArrayBuffer ? new Uint8Array(content.slice(0)) : content instanceof Uint8Array ? new Uint8Array(content) : void 0;
9898
- if (!bytes) throw require_ModerationContextLimits.invalidArgument("content must be bytes or a string");
9900
+ if (!bytes) throw require_CalmLensError.invalidArgument("content must be bytes or a string");
9899
9901
  this.servedUrls.set(key, {
9900
9902
  bytes,
9901
9903
  type: type.trim()
@@ -9951,7 +9953,7 @@ var MockCalmLensApi = class {
9951
9953
  }
9952
9954
  /** Applies a reviewer's decision to a stored asset (see `MockCalmLensServerClient.decide`). */
9953
9955
  async decide(assetId, decision) {
9954
- if (!REVIEW_DECISIONS.includes(decision)) throw require_ModerationContextLimits.invalidArgument(`decision must be one of ${REVIEW_DECISIONS.join(", ")}`);
9956
+ if (!REVIEW_DECISIONS.includes(decision)) throw require_CalmLensError.invalidArgument(`decision must be one of ${REVIEW_DECISIONS.join(", ")}`);
9955
9957
  let asset;
9956
9958
  try {
9957
9959
  asset = await this.findOwnAsset(assetId);
@@ -9972,7 +9974,7 @@ var MockCalmLensApi = class {
9972
9974
  } catch (failure) {
9973
9975
  throw this.toError(failure);
9974
9976
  }
9975
- if (asset.classification.status !== "processing") throw require_ModerationContextLimits.invalidArgument(`asset ${assetId} isn't processing`);
9977
+ if (asset.classification.status !== "processing") throw require_CalmLensError.invalidArgument(`asset ${assetId} isn't processing`);
9976
9978
  const settled = decision === void 0 ? void 0 : toDecision(decision);
9977
9979
  return this.toPublished(await this.moderateStored(asset, "complete", settled));
9978
9980
  }
@@ -9992,11 +9994,11 @@ var MockCalmLensApi = class {
9992
9994
  if (!note) throw invalidField("validation/too-small", "note");
9993
9995
  if (note.length > MAX_DECISION_NOTE_LENGTH) throw invalidField("validation/too-big", "note");
9994
9996
  const asset = await this.findOwnAsset(assetId);
9995
- if (asset.upload.status === "uploading" || asset.classification.status === "processing") throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_PROCESSING);
9997
+ if (asset.upload.status === "uploading" || asset.classification.status === "processing") throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_PROCESSING);
9996
9998
  const status = asset.classification.moderation.decision;
9997
- if (decision !== "purged" && decision !== "blocked" && status === null) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_DECISION_NOT_ALLOWED);
9998
- if (status === decision) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_DECISION_UNCHANGED);
9999
- if (decision !== "purged" && decision !== "blocked" && status === "purged") throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_CONTENT_PURGED);
9999
+ if (decision !== "purged" && decision !== "blocked" && status === null) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_DECISION_NOT_ALLOWED);
10000
+ if (status === decision) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_DECISION_UNCHANGED);
10001
+ if (decision !== "purged" && decision !== "blocked" && status === "purged") throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_CONTENT_PURGED);
10000
10002
  return this.recordDecision(asset, decision, { note });
10001
10003
  }
10002
10004
  /**
@@ -10050,7 +10052,7 @@ var MockCalmLensApi = class {
10050
10052
  toError(failure) {
10051
10053
  if (!(failure instanceof ApiFailure)) return failure;
10052
10054
  const requestId = `mock-request-${++this.requestCount}`;
10053
- return new require_ModerationContextLimits.CalmLensError(failure.code, {
10055
+ return new require_CalmLensError.CalmLensError(failure.code, {
10054
10056
  message: failure.message,
10055
10057
  status: failure.status,
10056
10058
  details: failure.details ?? {},
@@ -10103,7 +10105,7 @@ var MockCalmLensApi = class {
10103
10105
  const pending = this.pendingFailures[index];
10104
10106
  const { failure, details, retryAfter } = pending;
10105
10107
  if (--pending.remaining <= 0) this.pendingFailures.splice(index, 1);
10106
- if (typeof failure === "string" && failure in require_ModerationContextLimits.API_ERROR_DEFINITIONS) return this.answered(call, this.failureResponse(fail(failure, { details }), url, retryAfter));
10108
+ if (typeof failure === "string" && failure in require_CalmLensError.API_ERROR_DEFINITIONS) return this.answered(call, this.failureResponse(fail(failure, { details }), url, retryAfter));
10107
10109
  throw this.toFailureError(failure);
10108
10110
  }
10109
10111
  const response = cdn ? await this.serveCdn(request) : await this.answer(request, operations[0], session);
@@ -10119,7 +10121,7 @@ var MockCalmLensApi = class {
10119
10121
  if (failure === "timeout") {
10120
10122
  const cause = /* @__PURE__ */ new Error("The operation timed out.");
10121
10123
  cause.name = "TimeoutError";
10122
- return new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.TIMEOUT, {
10124
+ return new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.TIMEOUT, {
10123
10125
  message: "Request timed out",
10124
10126
  cause
10125
10127
  });
@@ -10178,7 +10180,7 @@ var MockCalmLensApi = class {
10178
10180
  /** Answers an API request: the API key, idempotency, then the route. */
10179
10181
  async answer(request, operation, session) {
10180
10182
  const { url, headers } = request;
10181
- if (!(request.segments[0] === "upload-presets") && headers.get("x-api-key") !== this.apiKey) return this.failureResponse(fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_API_KEY), url);
10183
+ if (!(request.segments[0] === "upload-presets") && headers.get("x-api-key") !== this.apiKey) return this.failureResponse(fail(require_CalmLensError.API_ERROR_CODES.INVALID_API_KEY), url);
10182
10184
  const key = operation && IDEMPOTENT_OPERATIONS.includes(operation) ? headers.get("idempotency-key")?.replace(/^[\t\n\r ]+|[\t\n\r ]+$/g, "") : void 0;
10183
10185
  const upload = headers.get("x-calmlens-upload");
10184
10186
  const contentType = headers.get("content-type");
@@ -10197,10 +10199,10 @@ var MockCalmLensApi = class {
10197
10199
  formOptions ?? null
10198
10200
  ]);
10199
10201
  if (key !== void 0) {
10200
- if (!isValidIdempotencyKey(key)) return this.failureResponse(fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_IDEMPOTENCY_KEY), url);
10202
+ if (!isValidIdempotencyKey(key)) return this.failureResponse(fail(require_CalmLensError.API_ERROR_CODES.INVALID_IDEMPOTENCY_KEY), url);
10201
10203
  const saved = this.idempotentResults.get(key);
10202
10204
  if (saved) {
10203
- if (saved.fingerprint !== fingerprint) return this.failureResponse(fail(require_ModerationContextLimits.API_ERROR_CODES.IDEMPOTENCY_KEY_REUSED), url);
10205
+ if (saved.fingerprint !== fingerprint) return this.failureResponse(fail(require_CalmLensError.API_ERROR_CODES.IDEMPOTENCY_KEY_REUSED), url);
10204
10206
  return this.response(saved.status, saved.body, url, {
10205
10207
  "Content-Type": "application/json",
10206
10208
  "Idempotent-Replayed": "true"
@@ -10228,7 +10230,7 @@ var MockCalmLensApi = class {
10228
10230
  const { method, segments } = request;
10229
10231
  const [root, id, action, ...rest] = segments;
10230
10232
  if (root === "projects") {
10231
- if (id !== this.projectId) throw fail(require_ModerationContextLimits.API_ERROR_CODES.API_KEY_PROJECT_MISMATCH);
10233
+ if (id !== this.projectId) throw fail(require_CalmLensError.API_ERROR_CODES.API_KEY_PROJECT_MISMATCH);
10232
10234
  switch (`${method} ${segments.slice(2).join("/")}`) {
10233
10235
  case "POST assets": return [200, await this.createAsset(request)];
10234
10236
  case "GET assets": return [200, await this.listAssets(request.query)];
@@ -10307,10 +10309,10 @@ var MockCalmLensApi = class {
10307
10309
  case "POST entries": return this.addHashListEntry(id, this.json(request));
10308
10310
  }
10309
10311
  if (root === "hash-list-entries" && id !== void 0 && method === "DELETE" && !action) {
10310
- if (!this.hashListEntries.delete(id)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.HASH_LIST_ENTRY_NOT_FOUND);
10312
+ if (!this.hashListEntries.delete(id)) throw fail(require_CalmLensError.API_ERROR_CODES.HASH_LIST_ENTRY_NOT_FOUND);
10311
10313
  return [200, {}];
10312
10314
  }
10313
- throw fail(require_ModerationContextLimits.API_ERROR_CODES.ROUTE_NOT_FOUND, { message: `No route for ${method} /${segments.join("/")}` });
10315
+ throw fail(require_CalmLensError.API_ERROR_CODES.ROUTE_NOT_FOUND, { message: `No route for ${method} /${segments.join("/")}` });
10314
10316
  }
10315
10317
  /** The project's policy, after creating the organisation's own General policy on first use. */
10316
10318
  ensurePolicies() {
@@ -10362,7 +10364,7 @@ var MockCalmLensApi = class {
10362
10364
  findPolicy(policyId) {
10363
10365
  this.ensurePolicies();
10364
10366
  const policy = this.policies.get(policyId);
10365
- if (!policy) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_NOT_FOUND);
10367
+ if (!policy) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_NOT_FOUND);
10366
10368
  return policy;
10367
10369
  }
10368
10370
  /** A page of the organisation's policies, oldest first unless `sort` says otherwise. */
@@ -10381,7 +10383,7 @@ var MockCalmLensApi = class {
10381
10383
  this.ensurePolicies();
10382
10384
  const { name, description, settings, presetId } = body;
10383
10385
  const preset = typeof presetId === "string" ? presetId : void 0;
10384
- 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(require_ModerationContextLimits.API_ERROR_CODES.INVALID_VALUE, { message: "Send settings with a name, or presetId" });
10386
+ 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(require_CalmLensError.API_ERROR_CODES.INVALID_VALUE, { message: "Send settings with a name, or presetId" });
10385
10387
  if (!preset) checkPolicySettings(settings);
10386
10388
  const policy = this.newPolicy({
10387
10389
  name: typeof name === "string" && name.trim() ? name.trim() : MOCK_PRESET_NAMES[preset],
@@ -10398,7 +10400,7 @@ var MockCalmLensApi = class {
10398
10400
  }
10399
10401
  /** Saves new values under the next revision, once `revision` is the current one. */
10400
10402
  savePolicy(policy, revision, values) {
10401
- if (revision !== policy.revision) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_REVISION_CONFLICT);
10403
+ if (revision !== policy.revision) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_REVISION_CONFLICT);
10402
10404
  const saved = {
10403
10405
  ...policy,
10404
10406
  ...values,
@@ -10421,17 +10423,17 @@ var MockCalmLensApi = class {
10421
10423
  /** Resets a `pinned` or `copy` policy to its preset release, or upgrades it to the latest. */
10422
10424
  restorePolicy(policyId, operation, body) {
10423
10425
  const policy = this.findPolicy(policyId);
10424
- if (!policy.preset || policy.followsPreset) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_NO_PRESET);
10425
- if (body.presetVersion !== policy.preset.version) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_PRESET_VERSION_CONFLICT);
10426
- if (operation === "upgrade") throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_PRESET_UPDATE_UNAVAILABLE);
10426
+ if (!policy.preset || policy.followsPreset) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_NO_PRESET);
10427
+ if (body.presetVersion !== policy.preset.version) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_PRESET_VERSION_CONFLICT);
10428
+ if (operation === "upgrade") throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_PRESET_UPDATE_UNAVAILABLE);
10427
10429
  return this.savePolicy(policy, body.revision, { settings: structuredClone(policy.baseline) });
10428
10430
  }
10429
10431
  setPolicyAutomaticUpdates(policyId, body) {
10430
10432
  const policy = this.findPolicy(policyId);
10431
10433
  const enabled = body.enabled === true;
10432
- if (!policy.preset?.own || policy.followsPreset === enabled) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_AUTOMATIC_UPDATES_UNAVAILABLE);
10433
- if (body.revision !== policy.revision) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_REVISION_CONFLICT);
10434
- if (body.presetVersion !== 1) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_PRESET_VERSION_CONFLICT);
10434
+ if (!policy.preset?.own || policy.followsPreset === enabled) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_AUTOMATIC_UPDATES_UNAVAILABLE);
10435
+ if (body.revision !== policy.revision) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_REVISION_CONFLICT);
10436
+ if (body.presetVersion !== 1) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_PRESET_VERSION_CONFLICT);
10435
10437
  return this.savePolicy(policy, body.revision, {
10436
10438
  followsPreset: enabled,
10437
10439
  ...enabled ? {
@@ -10443,7 +10445,7 @@ var MockCalmLensApi = class {
10443
10445
  }
10444
10446
  deletePolicy(policyId) {
10445
10447
  const policy = this.findPolicy(policyId);
10446
- if (policy.id === this.projectPolicyId) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_IN_USE);
10448
+ if (policy.id === this.projectPolicyId) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_IN_USE);
10447
10449
  this.policies.delete(policy.id);
10448
10450
  return {};
10449
10451
  }
@@ -10454,7 +10456,7 @@ var MockCalmLensApi = class {
10454
10456
  }
10455
10457
  createHashList(body) {
10456
10458
  const { name, description, action } = body;
10457
- if (typeof name !== "string" || !name.trim() || action !== "flag" && action !== "block") throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "A hash list needs a name and an action of flag or block" });
10459
+ if (typeof name !== "string" || !name.trim() || action !== "flag" && action !== "block") throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "A hash list needs a name and an action of flag or block" });
10458
10460
  const now = this.now();
10459
10461
  const list = {
10460
10462
  id: this.createId("hl"),
@@ -10476,7 +10478,7 @@ var MockCalmLensApi = class {
10476
10478
  }
10477
10479
  findHashList(hashListId) {
10478
10480
  const list = this.hashLists.get(hashListId);
10479
- if (!list) throw fail(require_ModerationContextLimits.API_ERROR_CODES.HASH_LIST_NOT_FOUND);
10481
+ if (!list) throw fail(require_CalmLensError.API_ERROR_CODES.HASH_LIST_NOT_FOUND);
10480
10482
  return list;
10481
10483
  }
10482
10484
  updateHashList(hashListId, body) {
@@ -10508,14 +10510,14 @@ var MockCalmLensApi = class {
10508
10510
  let hash = typeof body.hash === "string" ? body.hash.trim().toLowerCase() : void 0;
10509
10511
  let quality = typeof body.quality === "number" ? body.quality : null;
10510
10512
  const assetId = typeof body.assetId === "string" ? body.assetId : void 0;
10511
- if (hash === void 0 === (assetId === void 0)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Send either hash or assetId" });
10513
+ if (hash === void 0 === (assetId === void 0)) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Send either hash or assetId" });
10512
10514
  if (assetId) {
10513
10515
  const { content } = await this.findOwnAsset(assetId);
10514
- if (!content.perceptualHash) throw fail(require_ModerationContextLimits.API_ERROR_CODES.HASH_LIST_ASSET_NOT_HASHED);
10516
+ if (!content.perceptualHash) throw fail(require_CalmLensError.API_ERROR_CODES.HASH_LIST_ASSET_NOT_HASHED);
10515
10517
  hash = content.perceptualHash;
10516
10518
  quality = content.perceptualHashQuality ?? null;
10517
10519
  }
10518
- if (!/^[0-9a-f]{64}$/.test(hash)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Use a PDQ hash of 64 hexadecimal characters" });
10520
+ if (!/^[0-9a-f]{64}$/.test(hash)) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Use a PDQ hash of 64 hexadecimal characters" });
10519
10521
  const existing = [...this.hashListEntries.values()].find((entry) => entry.hashListId === list.id && entry.hash === hash);
10520
10522
  if (existing) return [200, existing];
10521
10523
  const entry = {
@@ -10570,13 +10572,13 @@ var MockCalmLensApi = class {
10570
10572
  }
10571
10573
  async findOwnAsset(assetId) {
10572
10574
  const asset = await this.databaseStorage.getAsset(assetId);
10573
- if (!asset || asset.projectId !== this.projectId) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_NOT_FOUND);
10575
+ if (!asset || asset.projectId !== this.projectId) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_NOT_FOUND);
10574
10576
  return asset;
10575
10577
  }
10576
10578
  /** `GET /projects/:projectId/assets/by-external-id/:externalId`: the asset with that external ID. */
10577
10579
  async findByExternalId(externalId) {
10578
10580
  const asset = (await this.databaseStorage.listAssets(this.projectId)).find((candidate) => candidate.externalId === externalId);
10579
- if (!asset) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_NOT_FOUND);
10581
+ if (!asset) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_NOT_FOUND);
10580
10582
  return asset;
10581
10583
  }
10582
10584
  /**
@@ -10618,10 +10620,10 @@ var MockCalmLensApi = class {
10618
10620
  if (note !== void 0 && !note) throw invalidField("validation/too-small", "note");
10619
10621
  if (note && note.length > MAX_DECISION_NOTE_LENGTH) throw invalidField("validation/too-big", "note");
10620
10622
  const asset = await this.findOwnAsset(assetId);
10621
- if (asset.content.safetyHold) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_HELD, { details: { hold: "safety" } });
10623
+ if (asset.content.safetyHold) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_HELD, { details: { hold: "safety" } });
10622
10624
  const decision = asset.classification.moderation.decision;
10623
10625
  const reason = asset.parentId ? "child-asset" : asset.upload.status === "uploading" || asset.classification.status !== "completed" || decision === null ? "not-moderated" : decision === "purged" || asset.content.status === "removed" ? "content-unavailable" : void 0;
10624
- if (reason) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_NOT_REVIEWABLE, { details: { reason } });
10626
+ if (reason) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_NOT_REVIEWABLE, { details: { reason } });
10625
10627
  const waiting = this.pendingReviewOf(asset);
10626
10628
  if (waiting) return [200, waiting];
10627
10629
  const now = this.now();
@@ -10689,7 +10691,7 @@ var MockCalmLensApi = class {
10689
10691
  try {
10690
10692
  assets = filterAssets(assets, filter);
10691
10693
  } catch (error) {
10692
- if (error instanceof MockInvalidFilter) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_FILTER);
10694
+ if (error instanceof MockInvalidFilter) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_FILTER);
10693
10695
  throw error;
10694
10696
  }
10695
10697
  return createPage(assets, page, {
@@ -10733,8 +10735,8 @@ var MockCalmLensApi = class {
10733
10735
  const pageSize = this.integer(query, "pageSize", 50);
10734
10736
  if (pageSize < 1) throw invalidField("validation/too-small", "pageSize");
10735
10737
  if (pageSize > 100) throw invalidField("validation/too-big", "pageSize");
10736
- if (asset.content.safetyHold) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_HELD, { details: { hold: "safety" } });
10737
- if (query.get("cursor") !== null) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_CURSOR);
10738
+ if (asset.content.safetyHold) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_HELD, { details: { hold: "safety" } });
10739
+ if (query.get("cursor") !== null) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_CURSOR);
10738
10740
  return {
10739
10741
  items: [],
10740
10742
  nextCursor: null,
@@ -10764,7 +10766,7 @@ var MockCalmLensApi = class {
10764
10766
  async moveAsset(assetId, body) {
10765
10767
  const asset = await this.findOwnAsset(assetId);
10766
10768
  const folderId = body.folderId ?? null;
10767
- if (folderId !== null && !await this.resolveFolder(folderId)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.FOLDER_NOT_FOUND);
10769
+ if (folderId !== null && !await this.resolveFolder(folderId)) throw fail(require_CalmLensError.API_ERROR_CODES.FOLDER_NOT_FOUND);
10768
10770
  return this.databaseStorage.updateAsset({
10769
10771
  ...asset,
10770
10772
  folderId,
@@ -10789,7 +10791,7 @@ var MockCalmLensApi = class {
10789
10791
  if (unknown !== void 0) throw invalidField("validation/unknown-field", unknown);
10790
10792
  for (const key of fields) if (body[key] === null) throw invalidField("validation/invalid-type", key);
10791
10793
  const { assetId, externalId } = body;
10792
- if (assetId === void 0 === (externalId === void 0)) throw new ApiFailure(400, require_ModerationContextLimits.API_ERROR_CODES.INVALID_REQUEST, "Send either assetId or externalId", { issues: [{
10794
+ if (assetId === void 0 === (externalId === void 0)) throw new ApiFailure(400, require_CalmLensError.API_ERROR_CODES.INVALID_REQUEST, "Send either assetId or externalId", { issues: [{
10793
10795
  path: "",
10794
10796
  message: "Send either assetId or externalId",
10795
10797
  code: "custom"
@@ -10803,9 +10805,9 @@ var MockCalmLensApi = class {
10803
10805
  let asset;
10804
10806
  if (externalId !== void 0) {
10805
10807
  asset = (await this.databaseStorage.listAssets(this.projectId)).find((candidate) => candidate.externalId === externalId);
10806
- if (!asset) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_NOT_FOUND);
10808
+ if (!asset) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_NOT_FOUND);
10807
10809
  } else asset = await this.findOwnAsset(String(assetId));
10808
- if (asset.content.safetyHold) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_HELD);
10810
+ if (asset.content.safetyHold) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_HELD);
10809
10811
  const expiresAt = this.now() + expiresIn * 1e3;
10810
10812
  const grant = encodeMockGrant({
10811
10813
  assetId: asset.id,
@@ -10820,8 +10822,8 @@ var MockCalmLensApi = class {
10820
10822
  }
10821
10823
  async retryAsset(assetId) {
10822
10824
  const asset = await this.findOwnAsset(assetId);
10823
- if (asset.classification.status !== "failed" || asset.classification.moderation.decision !== null) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_NOT_RETRYABLE);
10824
- if (asset.content.status === "removed") throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_CONTENT_UNAVAILABLE);
10825
+ if (asset.classification.status !== "failed" || asset.classification.moderation.decision !== null) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_NOT_RETRYABLE);
10826
+ if (asset.content.status === "removed") throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_CONTENT_UNAVAILABLE);
10825
10827
  const retried = await this.databaseStorage.updateAsset(await this.applyOutcome(asset, "pending"));
10826
10828
  this.recordLifecycleEvent("asset.retried", retried);
10827
10829
  return this.moderateStored(retried, "retry");
@@ -10940,9 +10942,9 @@ var MockCalmLensApi = class {
10940
10942
  try {
10941
10943
  options = JSON.parse(form.options);
10942
10944
  } catch {
10943
- throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "The options part must be a JSON object with the asset's fields" });
10945
+ throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "The options part must be a JSON object with the asset's fields" });
10944
10946
  }
10945
- if (!options || typeof options !== "object" || Array.isArray(options)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "The options part must be a JSON object with the asset's fields" });
10947
+ if (!options || typeof options !== "object" || Array.isArray(options)) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "The options part must be a JSON object with the asset's fields" });
10946
10948
  const unknown = Object.keys(options).find((key) => !UPLOAD_OPTION_KEYS.includes(key));
10947
10949
  if (unknown !== void 0) throw invalidField("validation/unknown-field", unknown);
10948
10950
  if (typeof options.name !== "string") throw invalidField("validation/invalid-type", "name");
@@ -10970,21 +10972,21 @@ var MockCalmLensApi = class {
10970
10972
  applyUploadPreset(fields) {
10971
10973
  if (!fields.uploadPresetId) return fields;
10972
10974
  const preset = [...this.configuredPresets.values()].find(({ id }) => id === fields.uploadPresetId);
10973
- if (!preset) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_NOT_FOUND);
10974
- if (!preset.enabled) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_DISABLED);
10975
- if (preset.folderId && fields.folderId && fields.folderId !== preset.folderId) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field: "folderId" } });
10976
- if (fields.visibility && fields.visibility !== preset.visibility) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field: "visibility" } });
10975
+ if (!preset) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_NOT_FOUND);
10976
+ if (!preset.enabled) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_DISABLED);
10977
+ if (preset.folderId && fields.folderId && fields.folderId !== preset.folderId) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field: "folderId" } });
10978
+ if (fields.visibility && fields.visibility !== preset.visibility) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field: "visibility" } });
10977
10979
  const contentType = fields.contentType;
10978
10980
  if (preset.allowedContentTypes?.length && contentType !== void 0 && !require_UploadController.isFileAccepted({
10979
10981
  name: fields.name,
10980
10982
  type: contentType
10981
- }, preset.allowedContentTypes.join(","))) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, { details: {
10983
+ }, preset.allowedContentTypes.join(","))) throw fail(require_CalmLensError.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, { details: {
10982
10984
  source: "preset",
10983
10985
  contentType,
10984
10986
  allowedContentTypes: preset.allowedContentTypes
10985
10987
  } });
10986
10988
  const size = fields.part?.totalSizeInBytes ?? fields.bytes?.byteLength;
10987
- if (preset.maxSizeInBytes && size !== void 0 && size > preset.maxSizeInBytes) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_TOO_LARGE, { details: {
10989
+ if (preset.maxSizeInBytes && size !== void 0 && size > preset.maxSizeInBytes) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_TOO_LARGE, { details: {
10988
10990
  limitBytes: preset.maxSizeInBytes,
10989
10991
  source: "preset"
10990
10992
  } });
@@ -10999,13 +11001,13 @@ var MockCalmLensApi = class {
10999
11001
  };
11000
11002
  }
11001
11003
  async storeAsset(fields, queue) {
11002
- if (!fields.name) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset name is required" });
11004
+ if (!fields.name) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset name is required" });
11003
11005
  const served = fields.url === void 0 ? void 0 : this.servedContent(fields.url);
11004
11006
  const fetched = served && inferAssetType(served.type) !== "website" ? served : void 0;
11005
11007
  const { part } = fields;
11006
11008
  const contentType = fetched ? fetched.type : fields.contentType;
11007
11009
  const bytes = fetched?.bytes ?? fields.bytes ?? /* @__PURE__ */ new Uint8Array(0);
11008
- if (contentType !== void 0 && !require_ModerationContextLimits.isAcceptedUploadMimeType(contentType)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, {
11010
+ if (contentType !== void 0 && !require_ModerationContextLimits.isAcceptedUploadMimeType(contentType)) throw fail(require_CalmLensError.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, {
11009
11011
  message: require_ModerationContextLimits.getRejectedUploadMimeTypeError(contentType),
11010
11012
  details: {
11011
11013
  mimeType: contentType,
@@ -11014,7 +11016,7 @@ var MockCalmLensApi = class {
11014
11016
  });
11015
11017
  const type = served ? inferAssetType(served.type) : fields.url === void 0 ? inferAssetType(contentType ?? "") : urlAssetType(fields.url);
11016
11018
  if (part) {
11017
- if (part.partNumber > 1) throw fail(require_ModerationContextLimits.API_ERROR_CODES.USE_UPLOAD_PART);
11019
+ if (part.partNumber > 1) throw fail(require_CalmLensError.API_ERROR_CODES.USE_UPLOAD_PART);
11018
11020
  const partSize = bytes.byteLength;
11019
11021
  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);
11020
11022
  if (sizeError) throw this.sizeFailure(sizeError);
@@ -11022,7 +11024,7 @@ var MockCalmLensApi = class {
11022
11024
  multipart: true,
11023
11025
  isFinal: part.isFinal
11024
11026
  });
11025
- if (!validation.ok) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: validation.error });
11027
+ if (!validation.ok) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: validation.error });
11026
11028
  if (!part.isFinal) {
11027
11029
  const totalError = this.multipartTotalSizeError(part.totalSizeInBytes, partSize, false);
11028
11030
  if (totalError) throw fail(totalError);
@@ -11148,9 +11150,9 @@ var MockCalmLensApi = class {
11148
11150
  const partNumber = this.integer(query, "partNumber", 0);
11149
11151
  const isFinal = query.get("isFinal") === "true";
11150
11152
  const asset = await this.findOwnAsset(assetId);
11151
- if (asset.upload.status !== "uploading") throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_NOT_OPEN);
11153
+ if (asset.upload.status !== "uploading") throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_NOT_OPEN);
11152
11154
  const expectedPartNumber = (asset.upload.partsReceived ?? 0) + 1;
11153
- if (partNumber !== expectedPartNumber) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PART_NUMBER, {
11155
+ if (partNumber !== expectedPartNumber) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PART_NUMBER, {
11154
11156
  message: `Expected part ${expectedPartNumber}`,
11155
11157
  details: {
11156
11158
  expectedPartNumber,
@@ -11165,7 +11167,7 @@ var MockCalmLensApi = class {
11165
11167
  multipart: true,
11166
11168
  isFinal
11167
11169
  });
11168
- if (!validation.ok) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: validation.error });
11170
+ if (!validation.ok) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: validation.error });
11169
11171
  await this.imageStorage.putPart(assetId, {
11170
11172
  uint8Array: bytes,
11171
11173
  partNumber,
@@ -11199,11 +11201,11 @@ var MockCalmLensApi = class {
11199
11201
  /** Like the API: image uploads in parts total at most 20 MiB, at any size below that. */
11200
11202
  multipartImageSizeError(type, sizeInBytes) {
11201
11203
  if (type !== "image") return void 0;
11202
- if (sizeInBytes > require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES) return require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_TOO_LARGE;
11204
+ if (sizeInBytes > require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES) return require_CalmLensError.API_ERROR_CODES.UPLOAD_TOO_LARGE;
11203
11205
  }
11204
11206
  /** The failure for a size error code, with the limit `upload/too-large` carries. */
11205
11207
  sizeFailure(code) {
11206
- return fail(code, code === require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_TOO_LARGE ? { details: {
11208
+ return fail(code, code === require_CalmLensError.API_ERROR_CODES.UPLOAD_TOO_LARGE ? { details: {
11207
11209
  limitBytes: require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES,
11208
11210
  source: "plan"
11209
11211
  } } : {});
@@ -11211,7 +11213,7 @@ var MockCalmLensApi = class {
11211
11213
  /** Like the API: the parts may not overshoot a declared total, and must reach it at the end. */
11212
11214
  multipartTotalSizeError(totalSizeInBytes, receivedSizeInBytes, isFinal) {
11213
11215
  if (totalSizeInBytes === void 0) return void 0;
11214
- return receivedSizeInBytes > totalSizeInBytes || isFinal && receivedSizeInBytes !== totalSizeInBytes ? require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_SIZE_MISMATCH : void 0;
11216
+ return receivedSizeInBytes > totalSizeInBytes || isFinal && receivedSizeInBytes !== totalSizeInBytes ? require_CalmLensError.API_ERROR_CODES.UPLOAD_SIZE_MISMATCH : void 0;
11215
11217
  }
11216
11218
  /**
11217
11219
  * The content a URL upload fetches from a URL `serveUrl` registered, or undefined: then the
@@ -11566,7 +11568,7 @@ var MockCalmLensApi = class {
11566
11568
  * applied in the API's order (token, content type, size), and checks of its uploads.
11567
11569
  */
11568
11570
  async presetRoute(request, uploadPresetId, rest, session) {
11569
- if (!session) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_NOT_FOUND);
11571
+ if (!session) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_NOT_FOUND);
11570
11572
  const { preset } = session;
11571
11573
  const toUploaded = (asset) => ({
11572
11574
  id: asset.id,
@@ -11585,7 +11587,7 @@ var MockCalmLensApi = class {
11585
11587
  });
11586
11588
  const [assetId, action] = rest;
11587
11589
  if (assetId !== void 0) {
11588
- if (!session.uploads.has(assetId)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_NOT_FOUND);
11590
+ if (!session.uploads.has(assetId)) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_NOT_FOUND);
11589
11591
  const asset = await this.findOwnAsset(assetId);
11590
11592
  if (request.method === "POST" && action === "part") return toUploaded(await this.uploadPart(assetId, request));
11591
11593
  if (request.method === "GET" && action === void 0) return toUploaded(asset);
@@ -11594,26 +11596,26 @@ var MockCalmLensApi = class {
11594
11596
  if (request.method !== "POST") throw new ApiFailure(404, "not-found", "No such route");
11595
11597
  const fields = this.uploadFields(request);
11596
11598
  const token = request.headers.get("authorization");
11597
- if (preset.access === "token" && !token) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_TOKEN_REQUIRED);
11599
+ if (preset.access === "token" && !token) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_TOKEN_REQUIRED);
11598
11600
  const tokenExternalId = token ? require_CalmLensServerClient.decodeUploadToken(token.replace(/^Bearer /, ""))?.claims.x : void 0;
11599
- if (fields.externalId && fields.externalId !== tokenExternalId) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field: "externalId" } });
11601
+ if (fields.externalId && fields.externalId !== tokenExternalId) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field: "externalId" } });
11600
11602
  for (const field of [
11601
11603
  "metadata",
11602
11604
  "tags",
11603
11605
  "authorId",
11604
11606
  "context",
11605
11607
  "processingOptions"
11606
- ]) if (fields[field] !== void 0 && fields[field] !== null) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field } });
11608
+ ]) if (fields[field] !== void 0 && fields[field] !== null) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field } });
11607
11609
  if (preset.allowedContentTypes && !require_UploadController.isFileAccepted({
11608
11610
  name: fields.name,
11609
11611
  type: fields.contentType ?? ""
11610
- }, preset.allowedContentTypes.join(","))) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, { details: {
11612
+ }, preset.allowedContentTypes.join(","))) throw fail(require_CalmLensError.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, { details: {
11611
11613
  source: "preset",
11612
11614
  contentType: fields.contentType ?? "",
11613
11615
  allowedContentTypes: preset.allowedContentTypes
11614
11616
  } });
11615
11617
  const size = fields.part?.totalSizeInBytes ?? fields.bytes?.byteLength;
11616
- if (preset.maxSizeInBytes != null && size !== void 0 && size > preset.maxSizeInBytes) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_TOO_LARGE, { details: {
11618
+ if (preset.maxSizeInBytes != null && size !== void 0 && size > preset.maxSizeInBytes) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_TOO_LARGE, { details: {
11617
11619
  limitBytes: preset.maxSizeInBytes,
11618
11620
  source: "preset"
11619
11621
  } });
@@ -11656,7 +11658,7 @@ var MockCalmLensApi = class {
11656
11658
  };
11657
11659
  const match = /^mock_(\d+)~(.*)$/.exec(cursor);
11658
11660
  const position = match && match[2] === filter ? Number(match[1]) : NaN;
11659
- if (!Number.isSafeInteger(position) || position > this.eventFeed.length) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_CURSOR);
11661
+ if (!Number.isSafeInteger(position) || position > this.eventFeed.length) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_CURSOR);
11660
11662
  const items = [];
11661
11663
  let next = position;
11662
11664
  while (next < this.eventFeed.length && items.length < pageSize) {
@@ -11712,7 +11714,7 @@ var MockCalmLensApi = class {
11712
11714
  }
11713
11715
  async createFolder(body) {
11714
11716
  const name = body.name;
11715
- if (typeof name !== "string" || !name) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder name is required" });
11717
+ if (typeof name !== "string" || !name) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder name is required" });
11716
11718
  const parentId = body.parentId ?? null;
11717
11719
  if (parentId) await this.findOwnFolder(parentId);
11718
11720
  await this.assertUniqueFolderName(name, parentId);
@@ -11742,7 +11744,7 @@ var MockCalmLensApi = class {
11742
11744
  await this.findOwnFolder(folderId);
11743
11745
  const hasAssets = (await this.databaseStorage.listAssets(this.projectId)).some((asset) => asset.folderId === folderId);
11744
11746
  const hasChildren = (await this.databaseStorage.listFolders?.(this.projectId) ?? []).some((folder) => folder.parentId === folderId);
11745
- if (hasAssets || hasChildren) throw fail(require_ModerationContextLimits.API_ERROR_CODES.FOLDER_NOT_EMPTY, { details: {
11747
+ if (hasAssets || hasChildren) throw fail(require_CalmLensError.API_ERROR_CODES.FOLDER_NOT_EMPTY, { details: {
11746
11748
  hasAssets,
11747
11749
  hasChildren
11748
11750
  } });
@@ -11755,7 +11757,7 @@ var MockCalmLensApi = class {
11755
11757
  let candidate = await this.findOwnFolder(targetParentId);
11756
11758
  const visited = /* @__PURE__ */ new Set();
11757
11759
  while (candidate) {
11758
- if (candidate.id === folderId || visited.has(candidate.id)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.FOLDER_PARENT_CYCLE);
11760
+ if (candidate.id === folderId || visited.has(candidate.id)) throw fail(require_CalmLensError.API_ERROR_CODES.FOLDER_PARENT_CYCLE);
11759
11761
  visited.add(candidate.id);
11760
11762
  candidate = candidate.parentId ? await this.resolveFolder(candidate.parentId) : void 0;
11761
11763
  }
@@ -11774,11 +11776,11 @@ var MockCalmLensApi = class {
11774
11776
  }
11775
11777
  async findOwnFolder(folderId) {
11776
11778
  const folder = await this.resolveFolder(folderId);
11777
- if (!folder) throw fail(require_ModerationContextLimits.API_ERROR_CODES.FOLDER_NOT_FOUND);
11779
+ if (!folder) throw fail(require_CalmLensError.API_ERROR_CODES.FOLDER_NOT_FOUND);
11778
11780
  return folder;
11779
11781
  }
11780
11782
  async assertUniqueFolderName(name, parentId, excludeFolderId) {
11781
- if ((await this.databaseStorage.listFolders?.(this.projectId) ?? []).find((folder) => folder.id !== excludeFolderId && (folder.parentId ?? null) === parentId && folder.name === name)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.DUPLICATE_FOLDER_NAME, { message: `A folder named "${name}" already exists in this location.` });
11783
+ if ((await this.databaseStorage.listFolders?.(this.projectId) ?? []).find((folder) => folder.id !== excludeFolderId && (folder.parentId ?? null) === parentId && folder.name === name)) throw fail(require_CalmLensError.API_ERROR_CODES.DUPLICATE_FOLDER_NAME, { message: `A folder named "${name}" already exists in this location.` });
11782
11784
  }
11783
11785
  /** A page of the project's upload presets, oldest first unless `sort` says otherwise. */
11784
11786
  listUploadPresets(query) {
@@ -11799,7 +11801,7 @@ var MockCalmLensApi = class {
11799
11801
  if (typeof definition.key !== "string" || !definition.key) throw invalidField("validation/invalid-type", `uploadPresets.${index}.key`);
11800
11802
  if (typeof definition.name !== "string" || !definition.name) throw invalidField("validation/invalid-type", `uploadPresets.${index}.name`);
11801
11803
  const existing = this.configuredPresets.get(definition.key);
11802
- if (definition.revision !== void 0 && definition.revision !== (existing?.revision ?? 0)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_REVISION_CONFLICT, { details: {
11804
+ if (definition.revision !== void 0 && definition.revision !== (existing?.revision ?? 0)) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_REVISION_CONFLICT, { details: {
11803
11805
  key: definition.key,
11804
11806
  revision: existing?.revision ?? 0
11805
11807
  } });
@@ -11819,7 +11821,7 @@ var MockCalmLensApi = class {
11819
11821
  dailyUploadLimit: definition.dailyUploadLimit ?? null,
11820
11822
  allowedOrigins: list(definition.allowedOrigins)
11821
11823
  };
11822
- if (values.access === "anyone" && !values.dailyUploadLimit) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_DAILY_LIMIT_REQUIRED);
11824
+ if (values.access === "anyone" && !values.dailyUploadLimit) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_DAILY_LIMIT_REQUIRED);
11823
11825
  return {
11824
11826
  existing,
11825
11827
  values
@@ -11844,7 +11846,7 @@ var MockCalmLensApi = class {
11844
11846
  }
11845
11847
  deleteUploadPreset(uploadPresetId) {
11846
11848
  const preset = [...this.configuredPresets.values()].find(({ id }) => id === uploadPresetId);
11847
- if (!preset) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_NOT_FOUND);
11849
+ if (!preset) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_NOT_FOUND);
11848
11850
  this.configuredPresets.delete(preset.key);
11849
11851
  return {};
11850
11852
  }
@@ -11873,7 +11875,7 @@ var MockCalmLensApi = class {
11873
11875
  };
11874
11876
  }
11875
11877
  checkSettingsRevision(revision) {
11876
- if (revision !== void 0 && revision !== null && Number(revision) !== this.settingsRevision) throw fail(require_ModerationContextLimits.API_ERROR_CODES.PROJECT_SETTINGS_REVISION_CONFLICT);
11878
+ if (revision !== void 0 && revision !== null && Number(revision) !== this.settingsRevision) throw fail(require_CalmLensError.API_ERROR_CODES.PROJECT_SETTINGS_REVISION_CONFLICT);
11877
11879
  }
11878
11880
  /** Replaces the settings: those left out return to their defaults. */
11879
11881
  updateProjectSettings(body) {
@@ -11908,7 +11910,7 @@ var MockCalmLensApi = class {
11908
11910
  return this.toMetadataFields();
11909
11911
  }
11910
11912
  deleteMetadataField(fieldId, query) {
11911
- if (!this.metadataFieldList.some(({ id }) => id === fieldId)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.METADATA_FIELD_NOT_FOUND, { details: { fieldId } });
11913
+ if (!this.metadataFieldList.some(({ id }) => id === fieldId)) throw fail(require_CalmLensError.API_ERROR_CODES.METADATA_FIELD_NOT_FOUND, { details: { fieldId } });
11912
11914
  this.checkSettingsRevision(query.get("revision") ?? void 0);
11913
11915
  this.metadataFieldList = this.metadataFieldList.filter(({ id }) => id !== fieldId);
11914
11916
  this.settingsRevision += 1;
@@ -11956,12 +11958,12 @@ var MockCalmLensApi = class {
11956
11958
  createLens(body) {
11957
11959
  const definition = body;
11958
11960
  if (typeof definition.identifier !== "string" || !definition.identifier) throw invalidField("validation/invalid-type", "identifier");
11959
- if (this.lenses.has(definition.identifier)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.LENS_IDENTIFIER_TAKEN, { details: { identifier: definition.identifier } });
11961
+ if (this.lenses.has(definition.identifier)) throw fail(require_CalmLensError.API_ERROR_CODES.LENS_IDENTIFIER_TAKEN, { details: { identifier: definition.identifier } });
11960
11962
  return this.saveNewLens(definition);
11961
11963
  }
11962
11964
  findLens(lensId) {
11963
11965
  const lens = [...this.lenses.values()].find((candidate) => candidate.id === lensId);
11964
- if (!lens) throw fail(require_ModerationContextLimits.API_ERROR_CODES.LENS_NOT_FOUND);
11966
+ if (!lens) throw fail(require_CalmLensError.API_ERROR_CODES.LENS_NOT_FOUND);
11965
11967
  return lens;
11966
11968
  }
11967
11969
  updateLens(lensId, body) {
@@ -12266,7 +12268,7 @@ const apis = /* @__PURE__ */ new WeakMap();
12266
12268
  /** The in-memory API a mock server client runs against, for `MockCalmLensAppClient`. */
12267
12269
  const getMockApi = (client) => {
12268
12270
  const api = apis.get(client);
12269
- if (!api) throw require_ModerationContextLimits.invalidConfig("mockOptions.server must be a MockCalmLensServerClient");
12271
+ if (!api) throw require_CalmLensError.invalidConfig("mockOptions.server must be a MockCalmLensServerClient");
12270
12272
  return api;
12271
12273
  };
12272
12274
  /**
@@ -12395,7 +12397,7 @@ var MockCalmLensServerClient = class extends require_CalmLensServerClient.CalmLe
12395
12397
  * `clearFailures`. Queued after other failures, it fails the requests they don't.
12396
12398
  */
12397
12399
  failRequests(failure = "transport-error", options = {}) {
12398
- if (options && "times" in options) throw require_ModerationContextLimits.invalidArgument("failRequests fails every request: use failNextRequest for times");
12400
+ if (options && "times" in options) throw require_CalmLensError.invalidArgument("failRequests fails every request: use failNextRequest for times");
12399
12401
  this.#api.failNextRequest(failure, {
12400
12402
  ...options,
12401
12403
  times: Number.POSITIVE_INFINITY
@@ -12529,6 +12531,9 @@ const createWebhookHeaders = async (options) => {
12529
12531
  [require_CalmLensServerClient.WEBHOOK_SIGNATURE_HEADER]: await createWebhookSignatureHeader(options.secret, timestamp, options.body)
12530
12532
  };
12531
12533
  };
12534
+ // src/testing.ts
12535
+ /** A spoken media test phrase for `signal`, signed with the project's test input key. */
12536
+ const generateMediaTestCode = (signal, key) => require_CalmLensTestInputArguments.withValidTestInputArguments(key, () => generateMediaTestCode$1(signal, key));
12532
12537
  exports.InMemoryMockDatabaseStorage = InMemoryMockDatabaseStorage;
12533
12538
  exports.InMemoryMockImageStorage = InMemoryMockImageStorage;
12534
12539
  exports.MEDIA_TEST_SIGNALS = MEDIA_TEST_SIGNALS;