calmlens 0.29.1 → 0.30.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 (86) hide show
  1. package/bin/calmlens.js +39 -18
  2. package/cjs/{BrowserUpload-CsxEB1Pr.js → BrowserUpload-BNeTp6eF.js} +1 -1
  3. package/cjs/{BrowserUpload-CeGsM9h1.d.ts → BrowserUpload-DS6KT6o_.d.ts} +2 -2
  4. package/{esm/CalmLensAppClient-D-BD_Ny1.d.ts → cjs/CalmLensAppClient-B4vzxEzg.d.ts} +1 -1
  5. package/cjs/{CalmLensAppClient-BWMcQM9v.js → CalmLensAppClient-ClqGwUbl.js} +7 -6
  6. package/cjs/{CalmLensConnection-DBgV8D1B.js → CalmLensConnection-og0jh-Fw.js} +29 -28
  7. package/cjs/CalmLensError-DPHJaVjX.js +1066 -0
  8. package/cjs/{CalmLensServerClient-BYN_N0lt.d.ts → CalmLensServerClient-BJl2Hsxr.d.ts} +12 -8
  9. package/cjs/{CalmLensServerClient-DYO3geSA.js → CalmLensServerClient-KsXM77rO.js} +37 -35
  10. package/cjs/{TestTriggers-uL2Ec8Vt-cPmmKvYd.js → CalmLensTestInputArguments-BXDBAOg_.js} +50 -22
  11. package/cjs/{CalmLensTypes-C2blKgTu.d.ts → CalmLensTypes-fAgF0_lq.d.ts} +206 -6
  12. package/cjs/{Classification-CMM2tZpJ-IdIh63n0.d.ts → Classification-DbXUPSvH-C0o2t4mg.d.ts} +15 -30
  13. package/cjs/{Core-CNmoxDCW.d.ts → Core-DL531ZPG.d.ts} +2 -2
  14. package/cjs/{Core-Bl-aESvN.js → Core-eDiPpil9.js} +4 -3
  15. package/cjs/{ModerationContextLimits-DHu2jHpo.js → ModerationContextLimits-BVBkcgSU.js} +67 -1126
  16. package/{esm/ReactUpload-kqEe6gcN.d.ts → cjs/ReactUpload-BoS0lr7U.d.ts} +1 -1
  17. package/cjs/{ReactUpload-BFVNyWoI.js → ReactUpload-DAPAzAwY.js} +1 -1
  18. package/{esm/TestTriggers-dognME9k-PWyIfHMI.d.ts → cjs/TestTriggers-CLjF01NU.d.ts} +2 -3
  19. package/cjs/{UploadController-VM1qYwNq.js → UploadController-BElzwMic.js} +6 -6
  20. package/{esm/WebhookPayload-DZWlnvcY.d.ts → cjs/WebhookPayload-DlGoY_db.d.ts} +11 -7
  21. package/cjs/app.d.ts +6 -6
  22. package/cjs/app.js +22 -21
  23. package/cjs/elements.d.ts +4 -4
  24. package/cjs/elements.js +4 -4
  25. package/cjs/{index-Dl2qwS8L.d.ts → index-ChrzzIRt.d.ts} +3 -3
  26. package/cjs/index.d.ts +5 -5
  27. package/cjs/index.js +21 -20
  28. package/cjs/react-native.d.ts +2 -2
  29. package/cjs/react-native.js +4 -4
  30. package/cjs/react.d.ts +4 -4
  31. package/cjs/react.js +5 -5
  32. package/cjs/server.d.ts +12 -12
  33. package/cjs/server.js +23 -22
  34. package/cjs/test-inputs.d.ts +6 -2
  35. package/cjs/test-inputs.js +23 -13
  36. package/cjs/testing.d.ts +14 -10
  37. package/cjs/testing.js +154 -147
  38. package/cjs/{ui-BCiLF8cU.js → ui-COjb2Hx6.js} +2 -2
  39. package/cjs/{ui-BtmJC-f9.d.ts → ui-DpZOLeVs.d.ts} +2 -2
  40. package/cjs/ui.d.ts +2 -2
  41. package/cjs/ui.js +3 -3
  42. package/cjs/vue.d.ts +5 -5
  43. package/cjs/vue.js +4 -4
  44. package/esm/{BrowserUpload-DB3WpaC1.js → BrowserUpload-BCmj5eGu.js} +1 -1
  45. package/esm/{BrowserUpload-CeGsM9h1.d.ts → BrowserUpload-DS6KT6o_.d.ts} +2 -2
  46. package/{cjs/CalmLensAppClient-D-BD_Ny1.d.ts → esm/CalmLensAppClient-B4vzxEzg.d.ts} +1 -1
  47. package/esm/{CalmLensAppClient-Dg-jPs4B.js → CalmLensAppClient-DcPVLn2y.js} +3 -2
  48. package/esm/{CalmLensConnection-Di7K7Wnl.js → CalmLensConnection-Pm-g6a1l.js} +2 -1
  49. package/esm/CalmLensError-BDWThPCr.js +917 -0
  50. package/esm/{CalmLensServerClient-BYN_N0lt.d.ts → CalmLensServerClient-BJl2Hsxr.d.ts} +12 -8
  51. package/esm/{CalmLensServerClient-Pdp7TI8y.js → CalmLensServerClient-C2HGsjkT.js} +18 -16
  52. package/esm/{TestTriggers-uL2Ec8Vt-DYbTEJWm.js → CalmLensTestInputArguments-Xh4GIadS.js} +22 -1
  53. package/esm/{CalmLensTypes-C2blKgTu.d.ts → CalmLensTypes-fAgF0_lq.d.ts} +206 -6
  54. package/esm/{Classification-CMM2tZpJ-IdIh63n0.d.ts → Classification-DbXUPSvH-C0o2t4mg.d.ts} +15 -30
  55. package/esm/{Core-CNmoxDCW.d.ts → Core-DL531ZPG.d.ts} +2 -2
  56. package/esm/{Core-CKk4teFu.js → Core-KYgLJ0eb.js} +3 -2
  57. package/esm/{ModerationContextLimits-xvxUjGfL.js → ModerationContextLimits-DmjWgTBa.js} +3 -918
  58. package/{cjs/ReactUpload-kqEe6gcN.d.ts → esm/ReactUpload-BoS0lr7U.d.ts} +1 -1
  59. package/esm/{ReactUpload-DY5qQ70s.js → ReactUpload-QW_RNxFp.js} +1 -1
  60. package/{cjs/TestTriggers-dognME9k-PWyIfHMI.d.ts → esm/TestTriggers-CLjF01NU.d.ts} +2 -3
  61. package/esm/{UploadController-wyor-5Z2.js → UploadController-Civ7QPwT.js} +2 -2
  62. package/{cjs/WebhookPayload-DZWlnvcY.d.ts → esm/WebhookPayload-DlGoY_db.d.ts} +11 -7
  63. package/esm/app.d.ts +6 -6
  64. package/esm/app.js +3 -2
  65. package/esm/elements.d.ts +4 -4
  66. package/esm/elements.js +4 -4
  67. package/esm/{index-Dl2qwS8L.d.ts → index-ChrzzIRt.d.ts} +3 -3
  68. package/esm/index.d.ts +5 -5
  69. package/esm/index.js +3 -1
  70. package/esm/react-native.d.ts +2 -2
  71. package/esm/react-native.js +4 -4
  72. package/esm/react.d.ts +4 -4
  73. package/esm/react.js +5 -5
  74. package/esm/server.d.ts +12 -12
  75. package/esm/server.js +4 -3
  76. package/esm/test-inputs.d.ts +6 -2
  77. package/esm/test-inputs.js +12 -1
  78. package/esm/testing.d.ts +14 -10
  79. package/esm/testing.js +27 -21
  80. package/esm/{ui-BqF49fSy.js → ui-BVXgDCO2.js} +2 -2
  81. package/esm/{ui-BtmJC-f9.d.ts → ui-DpZOLeVs.d.ts} +2 -2
  82. package/esm/ui.d.ts +2 -2
  83. package/esm/ui.js +3 -3
  84. package/esm/vue.d.ts +5 -5
  85. package/esm/vue.js +4 -4
  86. 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-BVBkcgSU.js");
5
+ const require_CalmLensServerClient = require("./CalmLensServerClient-KsXM77rO.js");
6
+ const require_CalmLensConnection = require("./CalmLensConnection-og0jh-Fw.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-ClqGwUbl.js");
9
+ const require_UploadController = require("./UploadController-BElzwMic.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) => {
@@ -9843,12 +9845,12 @@ var MockCalmLensApi = class {
9843
9845
  this.waitedMs = 0;
9844
9846
  this.publishAssets = (_key, value) => isStoredAsset(value) ? {
9845
9847
  ...value,
9846
- eventSequence: this.eventSequenceOf(value.id)
9848
+ sequence: this.eventSequenceOf(value.id)
9847
9849
  } : value;
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()
@@ -9913,32 +9915,35 @@ var MockCalmLensApi = class {
9913
9915
  return this.pushEvent(input);
9914
9916
  }
9915
9917
  /** Adds an event to the feed, filling the fields the API always sets. */
9916
- pushEvent(input) {
9918
+ pushEvent({ assetId, ...input }) {
9917
9919
  const now = this.now();
9920
+ const sequence = assetId ? (this.assetEventSequences.get(assetId) ?? 0) + 1 : null;
9921
+ if (assetId && sequence !== null) this.assetEventSequences.set(assetId, sequence);
9918
9922
  const event = {
9919
9923
  id: this.createId("evt"),
9920
9924
  projectId: this.projectId,
9921
9925
  severity: "low",
9922
9926
  title: input.type,
9923
9927
  description: null,
9924
- assetId: null,
9925
9928
  actor: MOCK_API_KEY_ACTOR,
9926
9929
  facts: [],
9927
9930
  createdAt: now,
9928
- ...input
9931
+ ...input,
9932
+ resource: assetId && sequence !== null ? {
9933
+ kind: "asset",
9934
+ id: assetId,
9935
+ sequence
9936
+ } : null
9929
9937
  };
9930
- const sequence = event.assetId ? (this.assetEventSequences.get(event.assetId) ?? 0) + 1 : null;
9931
- if (event.assetId && sequence !== null) this.assetEventSequences.set(event.assetId, sequence);
9932
- event.assetSequence = sequence;
9933
9938
  this.eventFeed.push(event);
9934
9939
  return event;
9935
9940
  }
9936
- /** The `assetSequence` of the latest event about an asset, or 0 before its first. */
9941
+ /** The `resource.sequence` of the latest event about an asset, or 0 before its first. */
9937
9942
  eventSequenceOf(assetId) {
9938
9943
  return this.assetEventSequences.get(assetId) ?? 0;
9939
9944
  }
9940
9945
  /**
9941
- * A copy of a stored asset as the API returns it, with its `eventSequence` as it is now. The
9946
+ * A copy of a stored asset as the API returns it, with its `sequence` as it is now. The
9942
9947
  * mock keeps each asset's sequence itself rather than in `databaseStorage`, whose
9943
9948
  * implementations needn't know about it, so every asset leaving the mock passes through here
9944
9949
  * or `publishAssets`.
@@ -9946,12 +9951,12 @@ var MockCalmLensApi = class {
9946
9951
  toPublished(asset) {
9947
9952
  return {
9948
9953
  ...structuredClone(asset),
9949
- eventSequence: this.eventSequenceOf(asset.id)
9954
+ sequence: this.eventSequenceOf(asset.id)
9950
9955
  };
9951
9956
  }
9952
9957
  /** Applies a reviewer's decision to a stored asset (see `MockCalmLensServerClient.decide`). */
9953
9958
  async decide(assetId, decision) {
9954
- if (!REVIEW_DECISIONS.includes(decision)) throw require_ModerationContextLimits.invalidArgument(`decision must be one of ${REVIEW_DECISIONS.join(", ")}`);
9959
+ if (!REVIEW_DECISIONS.includes(decision)) throw require_CalmLensError.invalidArgument(`decision must be one of ${REVIEW_DECISIONS.join(", ")}`);
9955
9960
  let asset;
9956
9961
  try {
9957
9962
  asset = await this.findOwnAsset(assetId);
@@ -9972,7 +9977,7 @@ var MockCalmLensApi = class {
9972
9977
  } catch (failure) {
9973
9978
  throw this.toError(failure);
9974
9979
  }
9975
- if (asset.classification.status !== "processing") throw require_ModerationContextLimits.invalidArgument(`asset ${assetId} isn't processing`);
9980
+ if (asset.classification.status !== "processing") throw require_CalmLensError.invalidArgument(`asset ${assetId} isn't processing`);
9976
9981
  const settled = decision === void 0 ? void 0 : toDecision(decision);
9977
9982
  return this.toPublished(await this.moderateStored(asset, "complete", settled));
9978
9983
  }
@@ -9992,11 +9997,11 @@ var MockCalmLensApi = class {
9992
9997
  if (!note) throw invalidField("validation/too-small", "note");
9993
9998
  if (note.length > MAX_DECISION_NOTE_LENGTH) throw invalidField("validation/too-big", "note");
9994
9999
  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);
10000
+ if (asset.upload.status === "uploading" || asset.classification.status === "processing") throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_PROCESSING);
9996
10001
  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);
10002
+ if (decision !== "purged" && decision !== "blocked" && status === null) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_DECISION_NOT_ALLOWED);
10003
+ if (status === decision) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_DECISION_UNCHANGED);
10004
+ if (decision !== "purged" && decision !== "blocked" && status === "purged") throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_CONTENT_PURGED);
10000
10005
  return this.recordDecision(asset, decision, { note });
10001
10006
  }
10002
10007
  /**
@@ -10050,7 +10055,7 @@ var MockCalmLensApi = class {
10050
10055
  toError(failure) {
10051
10056
  if (!(failure instanceof ApiFailure)) return failure;
10052
10057
  const requestId = `mock-request-${++this.requestCount}`;
10053
- return new require_ModerationContextLimits.CalmLensError(failure.code, {
10058
+ return new require_CalmLensError.CalmLensError(failure.code, {
10054
10059
  message: failure.message,
10055
10060
  status: failure.status,
10056
10061
  details: failure.details ?? {},
@@ -10103,7 +10108,7 @@ var MockCalmLensApi = class {
10103
10108
  const pending = this.pendingFailures[index];
10104
10109
  const { failure, details, retryAfter } = pending;
10105
10110
  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));
10111
+ if (typeof failure === "string" && failure in require_CalmLensError.API_ERROR_DEFINITIONS) return this.answered(call, this.failureResponse(fail(failure, { details }), url, retryAfter));
10107
10112
  throw this.toFailureError(failure);
10108
10113
  }
10109
10114
  const response = cdn ? await this.serveCdn(request) : await this.answer(request, operations[0], session);
@@ -10119,7 +10124,7 @@ var MockCalmLensApi = class {
10119
10124
  if (failure === "timeout") {
10120
10125
  const cause = /* @__PURE__ */ new Error("The operation timed out.");
10121
10126
  cause.name = "TimeoutError";
10122
- return new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.TIMEOUT, {
10127
+ return new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.TIMEOUT, {
10123
10128
  message: "Request timed out",
10124
10129
  cause
10125
10130
  });
@@ -10178,7 +10183,7 @@ var MockCalmLensApi = class {
10178
10183
  /** Answers an API request: the API key, idempotency, then the route. */
10179
10184
  async answer(request, operation, session) {
10180
10185
  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);
10186
+ 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
10187
  const key = operation && IDEMPOTENT_OPERATIONS.includes(operation) ? headers.get("idempotency-key")?.replace(/^[\t\n\r ]+|[\t\n\r ]+$/g, "") : void 0;
10183
10188
  const upload = headers.get("x-calmlens-upload");
10184
10189
  const contentType = headers.get("content-type");
@@ -10197,10 +10202,10 @@ var MockCalmLensApi = class {
10197
10202
  formOptions ?? null
10198
10203
  ]);
10199
10204
  if (key !== void 0) {
10200
- if (!isValidIdempotencyKey(key)) return this.failureResponse(fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_IDEMPOTENCY_KEY), url);
10205
+ if (!isValidIdempotencyKey(key)) return this.failureResponse(fail(require_CalmLensError.API_ERROR_CODES.INVALID_IDEMPOTENCY_KEY), url);
10201
10206
  const saved = this.idempotentResults.get(key);
10202
10207
  if (saved) {
10203
- if (saved.fingerprint !== fingerprint) return this.failureResponse(fail(require_ModerationContextLimits.API_ERROR_CODES.IDEMPOTENCY_KEY_REUSED), url);
10208
+ if (saved.fingerprint !== fingerprint) return this.failureResponse(fail(require_CalmLensError.API_ERROR_CODES.IDEMPOTENCY_KEY_REUSED), url);
10204
10209
  return this.response(saved.status, saved.body, url, {
10205
10210
  "Content-Type": "application/json",
10206
10211
  "Idempotent-Replayed": "true"
@@ -10228,7 +10233,7 @@ var MockCalmLensApi = class {
10228
10233
  const { method, segments } = request;
10229
10234
  const [root, id, action, ...rest] = segments;
10230
10235
  if (root === "projects") {
10231
- if (id !== this.projectId) throw fail(require_ModerationContextLimits.API_ERROR_CODES.API_KEY_PROJECT_MISMATCH);
10236
+ if (id !== this.projectId) throw fail(require_CalmLensError.API_ERROR_CODES.API_KEY_PROJECT_MISMATCH);
10232
10237
  switch (`${method} ${segments.slice(2).join("/")}`) {
10233
10238
  case "POST assets": return [200, await this.createAsset(request)];
10234
10239
  case "GET assets": return [200, await this.listAssets(request.query)];
@@ -10307,10 +10312,10 @@ var MockCalmLensApi = class {
10307
10312
  case "POST entries": return this.addHashListEntry(id, this.json(request));
10308
10313
  }
10309
10314
  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);
10315
+ if (!this.hashListEntries.delete(id)) throw fail(require_CalmLensError.API_ERROR_CODES.HASH_LIST_ENTRY_NOT_FOUND);
10311
10316
  return [200, {}];
10312
10317
  }
10313
- throw fail(require_ModerationContextLimits.API_ERROR_CODES.ROUTE_NOT_FOUND, { message: `No route for ${method} /${segments.join("/")}` });
10318
+ throw fail(require_CalmLensError.API_ERROR_CODES.ROUTE_NOT_FOUND, { message: `No route for ${method} /${segments.join("/")}` });
10314
10319
  }
10315
10320
  /** The project's policy, after creating the organisation's own General policy on first use. */
10316
10321
  ensurePolicies() {
@@ -10362,7 +10367,7 @@ var MockCalmLensApi = class {
10362
10367
  findPolicy(policyId) {
10363
10368
  this.ensurePolicies();
10364
10369
  const policy = this.policies.get(policyId);
10365
- if (!policy) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_NOT_FOUND);
10370
+ if (!policy) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_NOT_FOUND);
10366
10371
  return policy;
10367
10372
  }
10368
10373
  /** A page of the organisation's policies, oldest first unless `sort` says otherwise. */
@@ -10381,7 +10386,7 @@ var MockCalmLensApi = class {
10381
10386
  this.ensurePolicies();
10382
10387
  const { name, description, settings, presetId } = body;
10383
10388
  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" });
10389
+ 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
10390
  if (!preset) checkPolicySettings(settings);
10386
10391
  const policy = this.newPolicy({
10387
10392
  name: typeof name === "string" && name.trim() ? name.trim() : MOCK_PRESET_NAMES[preset],
@@ -10398,7 +10403,7 @@ var MockCalmLensApi = class {
10398
10403
  }
10399
10404
  /** Saves new values under the next revision, once `revision` is the current one. */
10400
10405
  savePolicy(policy, revision, values) {
10401
- if (revision !== policy.revision) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_REVISION_CONFLICT);
10406
+ if (revision !== policy.revision) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_REVISION_CONFLICT);
10402
10407
  const saved = {
10403
10408
  ...policy,
10404
10409
  ...values,
@@ -10421,17 +10426,17 @@ var MockCalmLensApi = class {
10421
10426
  /** Resets a `pinned` or `copy` policy to its preset release, or upgrades it to the latest. */
10422
10427
  restorePolicy(policyId, operation, body) {
10423
10428
  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);
10429
+ if (!policy.preset || policy.followsPreset) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_NO_PRESET);
10430
+ if (body.presetVersion !== policy.preset.version) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_PRESET_VERSION_CONFLICT);
10431
+ if (operation === "upgrade") throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_PRESET_UPDATE_UNAVAILABLE);
10427
10432
  return this.savePolicy(policy, body.revision, { settings: structuredClone(policy.baseline) });
10428
10433
  }
10429
10434
  setPolicyAutomaticUpdates(policyId, body) {
10430
10435
  const policy = this.findPolicy(policyId);
10431
10436
  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);
10437
+ if (!policy.preset?.own || policy.followsPreset === enabled) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_AUTOMATIC_UPDATES_UNAVAILABLE);
10438
+ if (body.revision !== policy.revision) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_REVISION_CONFLICT);
10439
+ if (body.presetVersion !== 1) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_PRESET_VERSION_CONFLICT);
10435
10440
  return this.savePolicy(policy, body.revision, {
10436
10441
  followsPreset: enabled,
10437
10442
  ...enabled ? {
@@ -10443,7 +10448,7 @@ var MockCalmLensApi = class {
10443
10448
  }
10444
10449
  deletePolicy(policyId) {
10445
10450
  const policy = this.findPolicy(policyId);
10446
- if (policy.id === this.projectPolicyId) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_IN_USE);
10451
+ if (policy.id === this.projectPolicyId) throw fail(require_CalmLensError.API_ERROR_CODES.POLICY_IN_USE);
10447
10452
  this.policies.delete(policy.id);
10448
10453
  return {};
10449
10454
  }
@@ -10454,7 +10459,7 @@ var MockCalmLensApi = class {
10454
10459
  }
10455
10460
  createHashList(body) {
10456
10461
  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" });
10462
+ 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
10463
  const now = this.now();
10459
10464
  const list = {
10460
10465
  id: this.createId("hl"),
@@ -10476,7 +10481,7 @@ var MockCalmLensApi = class {
10476
10481
  }
10477
10482
  findHashList(hashListId) {
10478
10483
  const list = this.hashLists.get(hashListId);
10479
- if (!list) throw fail(require_ModerationContextLimits.API_ERROR_CODES.HASH_LIST_NOT_FOUND);
10484
+ if (!list) throw fail(require_CalmLensError.API_ERROR_CODES.HASH_LIST_NOT_FOUND);
10480
10485
  return list;
10481
10486
  }
10482
10487
  updateHashList(hashListId, body) {
@@ -10508,14 +10513,14 @@ var MockCalmLensApi = class {
10508
10513
  let hash = typeof body.hash === "string" ? body.hash.trim().toLowerCase() : void 0;
10509
10514
  let quality = typeof body.quality === "number" ? body.quality : null;
10510
10515
  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" });
10516
+ if (hash === void 0 === (assetId === void 0)) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Send either hash or assetId" });
10512
10517
  if (assetId) {
10513
10518
  const { content } = await this.findOwnAsset(assetId);
10514
- if (!content.perceptualHash) throw fail(require_ModerationContextLimits.API_ERROR_CODES.HASH_LIST_ASSET_NOT_HASHED);
10519
+ if (!content.perceptualHash) throw fail(require_CalmLensError.API_ERROR_CODES.HASH_LIST_ASSET_NOT_HASHED);
10515
10520
  hash = content.perceptualHash;
10516
10521
  quality = content.perceptualHashQuality ?? null;
10517
10522
  }
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" });
10523
+ 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
10524
  const existing = [...this.hashListEntries.values()].find((entry) => entry.hashListId === list.id && entry.hash === hash);
10520
10525
  if (existing) return [200, existing];
10521
10526
  const entry = {
@@ -10570,13 +10575,13 @@ var MockCalmLensApi = class {
10570
10575
  }
10571
10576
  async findOwnAsset(assetId) {
10572
10577
  const asset = await this.databaseStorage.getAsset(assetId);
10573
- if (!asset || asset.projectId !== this.projectId) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_NOT_FOUND);
10578
+ if (!asset || asset.projectId !== this.projectId) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_NOT_FOUND);
10574
10579
  return asset;
10575
10580
  }
10576
10581
  /** `GET /projects/:projectId/assets/by-external-id/:externalId`: the asset with that external ID. */
10577
10582
  async findByExternalId(externalId) {
10578
10583
  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);
10584
+ if (!asset) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_NOT_FOUND);
10580
10585
  return asset;
10581
10586
  }
10582
10587
  /**
@@ -10618,10 +10623,10 @@ var MockCalmLensApi = class {
10618
10623
  if (note !== void 0 && !note) throw invalidField("validation/too-small", "note");
10619
10624
  if (note && note.length > MAX_DECISION_NOTE_LENGTH) throw invalidField("validation/too-big", "note");
10620
10625
  const asset = await this.findOwnAsset(assetId);
10621
- if (asset.content.safetyHold) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_HELD, { details: { hold: "safety" } });
10626
+ if (asset.content.safetyHold) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_HELD, { details: { hold: "safety" } });
10622
10627
  const decision = asset.classification.moderation.decision;
10623
10628
  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 } });
10629
+ if (reason) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_NOT_REVIEWABLE, { details: { reason } });
10625
10630
  const waiting = this.pendingReviewOf(asset);
10626
10631
  if (waiting) return [200, waiting];
10627
10632
  const now = this.now();
@@ -10689,7 +10694,7 @@ var MockCalmLensApi = class {
10689
10694
  try {
10690
10695
  assets = filterAssets(assets, filter);
10691
10696
  } catch (error) {
10692
- if (error instanceof MockInvalidFilter) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_FILTER);
10697
+ if (error instanceof MockInvalidFilter) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_FILTER);
10693
10698
  throw error;
10694
10699
  }
10695
10700
  return createPage(assets, page, {
@@ -10733,8 +10738,8 @@ var MockCalmLensApi = class {
10733
10738
  const pageSize = this.integer(query, "pageSize", 50);
10734
10739
  if (pageSize < 1) throw invalidField("validation/too-small", "pageSize");
10735
10740
  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);
10741
+ if (asset.content.safetyHold) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_HELD, { details: { hold: "safety" } });
10742
+ if (query.get("cursor") !== null) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_CURSOR);
10738
10743
  return {
10739
10744
  items: [],
10740
10745
  nextCursor: null,
@@ -10764,7 +10769,7 @@ var MockCalmLensApi = class {
10764
10769
  async moveAsset(assetId, body) {
10765
10770
  const asset = await this.findOwnAsset(assetId);
10766
10771
  const folderId = body.folderId ?? null;
10767
- if (folderId !== null && !await this.resolveFolder(folderId)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.FOLDER_NOT_FOUND);
10772
+ if (folderId !== null && !await this.resolveFolder(folderId)) throw fail(require_CalmLensError.API_ERROR_CODES.FOLDER_NOT_FOUND);
10768
10773
  return this.databaseStorage.updateAsset({
10769
10774
  ...asset,
10770
10775
  folderId,
@@ -10789,7 +10794,7 @@ var MockCalmLensApi = class {
10789
10794
  if (unknown !== void 0) throw invalidField("validation/unknown-field", unknown);
10790
10795
  for (const key of fields) if (body[key] === null) throw invalidField("validation/invalid-type", key);
10791
10796
  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: [{
10797
+ 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
10798
  path: "",
10794
10799
  message: "Send either assetId or externalId",
10795
10800
  code: "custom"
@@ -10803,9 +10808,9 @@ var MockCalmLensApi = class {
10803
10808
  let asset;
10804
10809
  if (externalId !== void 0) {
10805
10810
  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);
10811
+ if (!asset) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_NOT_FOUND);
10807
10812
  } else asset = await this.findOwnAsset(String(assetId));
10808
- if (asset.content.safetyHold) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_HELD);
10813
+ if (asset.content.safetyHold) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_HELD);
10809
10814
  const expiresAt = this.now() + expiresIn * 1e3;
10810
10815
  const grant = encodeMockGrant({
10811
10816
  assetId: asset.id,
@@ -10820,8 +10825,8 @@ var MockCalmLensApi = class {
10820
10825
  }
10821
10826
  async retryAsset(assetId) {
10822
10827
  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);
10828
+ if (asset.classification.status !== "failed" || asset.classification.moderation.decision !== null) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_NOT_RETRYABLE);
10829
+ if (asset.content.status === "removed") throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_CONTENT_UNAVAILABLE);
10825
10830
  const retried = await this.databaseStorage.updateAsset(await this.applyOutcome(asset, "pending"));
10826
10831
  this.recordLifecycleEvent("asset.retried", retried);
10827
10832
  return this.moderateStored(retried, "retry");
@@ -10940,9 +10945,9 @@ var MockCalmLensApi = class {
10940
10945
  try {
10941
10946
  options = JSON.parse(form.options);
10942
10947
  } 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" });
10948
+ 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
10949
  }
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" });
10950
+ 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
10951
  const unknown = Object.keys(options).find((key) => !UPLOAD_OPTION_KEYS.includes(key));
10947
10952
  if (unknown !== void 0) throw invalidField("validation/unknown-field", unknown);
10948
10953
  if (typeof options.name !== "string") throw invalidField("validation/invalid-type", "name");
@@ -10970,21 +10975,21 @@ var MockCalmLensApi = class {
10970
10975
  applyUploadPreset(fields) {
10971
10976
  if (!fields.uploadPresetId) return fields;
10972
10977
  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" } });
10978
+ if (!preset) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_NOT_FOUND);
10979
+ if (!preset.enabled) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_DISABLED);
10980
+ if (preset.folderId && fields.folderId && fields.folderId !== preset.folderId) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field: "folderId" } });
10981
+ if (fields.visibility && fields.visibility !== preset.visibility) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field: "visibility" } });
10977
10982
  const contentType = fields.contentType;
10978
10983
  if (preset.allowedContentTypes?.length && contentType !== void 0 && !require_UploadController.isFileAccepted({
10979
10984
  name: fields.name,
10980
10985
  type: contentType
10981
- }, preset.allowedContentTypes.join(","))) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, { details: {
10986
+ }, preset.allowedContentTypes.join(","))) throw fail(require_CalmLensError.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, { details: {
10982
10987
  source: "preset",
10983
10988
  contentType,
10984
10989
  allowedContentTypes: preset.allowedContentTypes
10985
10990
  } });
10986
10991
  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: {
10992
+ if (preset.maxSizeInBytes && size !== void 0 && size > preset.maxSizeInBytes) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_TOO_LARGE, { details: {
10988
10993
  limitBytes: preset.maxSizeInBytes,
10989
10994
  source: "preset"
10990
10995
  } });
@@ -10999,13 +11004,13 @@ var MockCalmLensApi = class {
10999
11004
  };
11000
11005
  }
11001
11006
  async storeAsset(fields, queue) {
11002
- if (!fields.name) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset name is required" });
11007
+ if (!fields.name) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset name is required" });
11003
11008
  const served = fields.url === void 0 ? void 0 : this.servedContent(fields.url);
11004
11009
  const fetched = served && inferAssetType(served.type) !== "website" ? served : void 0;
11005
11010
  const { part } = fields;
11006
11011
  const contentType = fetched ? fetched.type : fields.contentType;
11007
11012
  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, {
11013
+ if (contentType !== void 0 && !require_ModerationContextLimits.isAcceptedUploadMimeType(contentType)) throw fail(require_CalmLensError.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, {
11009
11014
  message: require_ModerationContextLimits.getRejectedUploadMimeTypeError(contentType),
11010
11015
  details: {
11011
11016
  mimeType: contentType,
@@ -11014,7 +11019,7 @@ var MockCalmLensApi = class {
11014
11019
  });
11015
11020
  const type = served ? inferAssetType(served.type) : fields.url === void 0 ? inferAssetType(contentType ?? "") : urlAssetType(fields.url);
11016
11021
  if (part) {
11017
- if (part.partNumber > 1) throw fail(require_ModerationContextLimits.API_ERROR_CODES.USE_UPLOAD_PART);
11022
+ if (part.partNumber > 1) throw fail(require_CalmLensError.API_ERROR_CODES.USE_UPLOAD_PART);
11018
11023
  const partSize = bytes.byteLength;
11019
11024
  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
11025
  if (sizeError) throw this.sizeFailure(sizeError);
@@ -11022,7 +11027,7 @@ var MockCalmLensApi = class {
11022
11027
  multipart: true,
11023
11028
  isFinal: part.isFinal
11024
11029
  });
11025
- if (!validation.ok) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: validation.error });
11030
+ if (!validation.ok) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: validation.error });
11026
11031
  if (!part.isFinal) {
11027
11032
  const totalError = this.multipartTotalSizeError(part.totalSizeInBytes, partSize, false);
11028
11033
  if (totalError) throw fail(totalError);
@@ -11063,7 +11068,7 @@ var MockCalmLensApi = class {
11063
11068
  context: contextItems.length ? { items: contextItems } : null,
11064
11069
  tags: fields.tags ?? [],
11065
11070
  visibility: fields.visibility ?? "private",
11066
- eventSequence: 0,
11071
+ sequence: 0,
11067
11072
  content: {
11068
11073
  status: keepContent ? "stored" : "temporary",
11069
11074
  removalReason: null,
@@ -11148,9 +11153,9 @@ var MockCalmLensApi = class {
11148
11153
  const partNumber = this.integer(query, "partNumber", 0);
11149
11154
  const isFinal = query.get("isFinal") === "true";
11150
11155
  const asset = await this.findOwnAsset(assetId);
11151
- if (asset.upload.status !== "uploading") throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_NOT_OPEN);
11156
+ if (asset.upload.status !== "uploading") throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_NOT_OPEN);
11152
11157
  const expectedPartNumber = (asset.upload.partsReceived ?? 0) + 1;
11153
- if (partNumber !== expectedPartNumber) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PART_NUMBER, {
11158
+ if (partNumber !== expectedPartNumber) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PART_NUMBER, {
11154
11159
  message: `Expected part ${expectedPartNumber}`,
11155
11160
  details: {
11156
11161
  expectedPartNumber,
@@ -11165,7 +11170,7 @@ var MockCalmLensApi = class {
11165
11170
  multipart: true,
11166
11171
  isFinal
11167
11172
  });
11168
- if (!validation.ok) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: validation.error });
11173
+ if (!validation.ok) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: validation.error });
11169
11174
  await this.imageStorage.putPart(assetId, {
11170
11175
  uint8Array: bytes,
11171
11176
  partNumber,
@@ -11199,11 +11204,11 @@ var MockCalmLensApi = class {
11199
11204
  /** Like the API: image uploads in parts total at most 20 MiB, at any size below that. */
11200
11205
  multipartImageSizeError(type, sizeInBytes) {
11201
11206
  if (type !== "image") return void 0;
11202
- if (sizeInBytes > require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES) return require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_TOO_LARGE;
11207
+ if (sizeInBytes > require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES) return require_CalmLensError.API_ERROR_CODES.UPLOAD_TOO_LARGE;
11203
11208
  }
11204
11209
  /** The failure for a size error code, with the limit `upload/too-large` carries. */
11205
11210
  sizeFailure(code) {
11206
- return fail(code, code === require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_TOO_LARGE ? { details: {
11211
+ return fail(code, code === require_CalmLensError.API_ERROR_CODES.UPLOAD_TOO_LARGE ? { details: {
11207
11212
  limitBytes: require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES,
11208
11213
  source: "plan"
11209
11214
  } } : {});
@@ -11211,7 +11216,7 @@ var MockCalmLensApi = class {
11211
11216
  /** Like the API: the parts may not overshoot a declared total, and must reach it at the end. */
11212
11217
  multipartTotalSizeError(totalSizeInBytes, receivedSizeInBytes, isFinal) {
11213
11218
  if (totalSizeInBytes === void 0) return void 0;
11214
- return receivedSizeInBytes > totalSizeInBytes || isFinal && receivedSizeInBytes !== totalSizeInBytes ? require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_SIZE_MISMATCH : void 0;
11219
+ return receivedSizeInBytes > totalSizeInBytes || isFinal && receivedSizeInBytes !== totalSizeInBytes ? require_CalmLensError.API_ERROR_CODES.UPLOAD_SIZE_MISMATCH : void 0;
11215
11220
  }
11216
11221
  /**
11217
11222
  * The content a URL upload fetches from a URL `serveUrl` registered, or undefined: then the
@@ -11566,7 +11571,7 @@ var MockCalmLensApi = class {
11566
11571
  * applied in the API's order (token, content type, size), and checks of its uploads.
11567
11572
  */
11568
11573
  async presetRoute(request, uploadPresetId, rest, session) {
11569
- if (!session) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_NOT_FOUND);
11574
+ if (!session) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_NOT_FOUND);
11570
11575
  const { preset } = session;
11571
11576
  const toUploaded = (asset) => ({
11572
11577
  id: asset.id,
@@ -11585,7 +11590,7 @@ var MockCalmLensApi = class {
11585
11590
  });
11586
11591
  const [assetId, action] = rest;
11587
11592
  if (assetId !== void 0) {
11588
- if (!session.uploads.has(assetId)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.ASSET_NOT_FOUND);
11593
+ if (!session.uploads.has(assetId)) throw fail(require_CalmLensError.API_ERROR_CODES.ASSET_NOT_FOUND);
11589
11594
  const asset = await this.findOwnAsset(assetId);
11590
11595
  if (request.method === "POST" && action === "part") return toUploaded(await this.uploadPart(assetId, request));
11591
11596
  if (request.method === "GET" && action === void 0) return toUploaded(asset);
@@ -11594,26 +11599,26 @@ var MockCalmLensApi = class {
11594
11599
  if (request.method !== "POST") throw new ApiFailure(404, "not-found", "No such route");
11595
11600
  const fields = this.uploadFields(request);
11596
11601
  const token = request.headers.get("authorization");
11597
- if (preset.access === "token" && !token) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_TOKEN_REQUIRED);
11602
+ if (preset.access === "token" && !token) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_TOKEN_REQUIRED);
11598
11603
  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" } });
11604
+ if (fields.externalId && fields.externalId !== tokenExternalId) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field: "externalId" } });
11600
11605
  for (const field of [
11601
11606
  "metadata",
11602
11607
  "tags",
11603
11608
  "authorId",
11604
11609
  "context",
11605
11610
  "processingOptions"
11606
- ]) if (fields[field] !== void 0 && fields[field] !== null) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field } });
11611
+ ]) if (fields[field] !== void 0 && fields[field] !== null) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_FIELD_NOT_ALLOWED, { details: { field } });
11607
11612
  if (preset.allowedContentTypes && !require_UploadController.isFileAccepted({
11608
11613
  name: fields.name,
11609
11614
  type: fields.contentType ?? ""
11610
- }, preset.allowedContentTypes.join(","))) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, { details: {
11615
+ }, preset.allowedContentTypes.join(","))) throw fail(require_CalmLensError.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, { details: {
11611
11616
  source: "preset",
11612
11617
  contentType: fields.contentType ?? "",
11613
11618
  allowedContentTypes: preset.allowedContentTypes
11614
11619
  } });
11615
11620
  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: {
11621
+ if (preset.maxSizeInBytes != null && size !== void 0 && size > preset.maxSizeInBytes) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_TOO_LARGE, { details: {
11617
11622
  limitBytes: preset.maxSizeInBytes,
11618
11623
  source: "preset"
11619
11624
  } });
@@ -11646,7 +11651,7 @@ var MockCalmLensApi = class {
11646
11651
  const assetId = query.get("assetId");
11647
11652
  if (assetId !== null && !isId(assetId, "asset")) throw invalidField("validation/invalid-format", "assetId");
11648
11653
  const filter = btoa(JSON.stringify([[...new Set(types)].sort(), assetId]));
11649
- const matches = (event) => (!types.length || types.includes(event.type)) && (assetId === null || event.assetId === assetId);
11654
+ const matches = (event) => (!types.length || types.includes(event.type)) && (assetId === null || event.resource?.id === assetId);
11650
11655
  const cursor = query.get("cursor");
11651
11656
  if (!cursor) return {
11652
11657
  items: [],
@@ -11656,7 +11661,7 @@ var MockCalmLensApi = class {
11656
11661
  };
11657
11662
  const match = /^mock_(\d+)~(.*)$/.exec(cursor);
11658
11663
  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);
11664
+ if (!Number.isSafeInteger(position) || position > this.eventFeed.length) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_CURSOR);
11660
11665
  const items = [];
11661
11666
  let next = position;
11662
11667
  while (next < this.eventFeed.length && items.length < pageSize) {
@@ -11712,7 +11717,7 @@ var MockCalmLensApi = class {
11712
11717
  }
11713
11718
  async createFolder(body) {
11714
11719
  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" });
11720
+ if (typeof name !== "string" || !name) throw fail(require_CalmLensError.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder name is required" });
11716
11721
  const parentId = body.parentId ?? null;
11717
11722
  if (parentId) await this.findOwnFolder(parentId);
11718
11723
  await this.assertUniqueFolderName(name, parentId);
@@ -11742,7 +11747,7 @@ var MockCalmLensApi = class {
11742
11747
  await this.findOwnFolder(folderId);
11743
11748
  const hasAssets = (await this.databaseStorage.listAssets(this.projectId)).some((asset) => asset.folderId === folderId);
11744
11749
  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: {
11750
+ if (hasAssets || hasChildren) throw fail(require_CalmLensError.API_ERROR_CODES.FOLDER_NOT_EMPTY, { details: {
11746
11751
  hasAssets,
11747
11752
  hasChildren
11748
11753
  } });
@@ -11755,7 +11760,7 @@ var MockCalmLensApi = class {
11755
11760
  let candidate = await this.findOwnFolder(targetParentId);
11756
11761
  const visited = /* @__PURE__ */ new Set();
11757
11762
  while (candidate) {
11758
- if (candidate.id === folderId || visited.has(candidate.id)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.FOLDER_PARENT_CYCLE);
11763
+ if (candidate.id === folderId || visited.has(candidate.id)) throw fail(require_CalmLensError.API_ERROR_CODES.FOLDER_PARENT_CYCLE);
11759
11764
  visited.add(candidate.id);
11760
11765
  candidate = candidate.parentId ? await this.resolveFolder(candidate.parentId) : void 0;
11761
11766
  }
@@ -11774,11 +11779,11 @@ var MockCalmLensApi = class {
11774
11779
  }
11775
11780
  async findOwnFolder(folderId) {
11776
11781
  const folder = await this.resolveFolder(folderId);
11777
- if (!folder) throw fail(require_ModerationContextLimits.API_ERROR_CODES.FOLDER_NOT_FOUND);
11782
+ if (!folder) throw fail(require_CalmLensError.API_ERROR_CODES.FOLDER_NOT_FOUND);
11778
11783
  return folder;
11779
11784
  }
11780
11785
  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.` });
11786
+ 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
11787
  }
11783
11788
  /** A page of the project's upload presets, oldest first unless `sort` says otherwise. */
11784
11789
  listUploadPresets(query) {
@@ -11799,7 +11804,7 @@ var MockCalmLensApi = class {
11799
11804
  if (typeof definition.key !== "string" || !definition.key) throw invalidField("validation/invalid-type", `uploadPresets.${index}.key`);
11800
11805
  if (typeof definition.name !== "string" || !definition.name) throw invalidField("validation/invalid-type", `uploadPresets.${index}.name`);
11801
11806
  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: {
11807
+ if (definition.revision !== void 0 && definition.revision !== (existing?.revision ?? 0)) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_REVISION_CONFLICT, { details: {
11803
11808
  key: definition.key,
11804
11809
  revision: existing?.revision ?? 0
11805
11810
  } });
@@ -11819,7 +11824,7 @@ var MockCalmLensApi = class {
11819
11824
  dailyUploadLimit: definition.dailyUploadLimit ?? null,
11820
11825
  allowedOrigins: list(definition.allowedOrigins)
11821
11826
  };
11822
- if (values.access === "anyone" && !values.dailyUploadLimit) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_DAILY_LIMIT_REQUIRED);
11827
+ if (values.access === "anyone" && !values.dailyUploadLimit) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_DAILY_LIMIT_REQUIRED);
11823
11828
  return {
11824
11829
  existing,
11825
11830
  values
@@ -11844,7 +11849,7 @@ var MockCalmLensApi = class {
11844
11849
  }
11845
11850
  deleteUploadPreset(uploadPresetId) {
11846
11851
  const preset = [...this.configuredPresets.values()].find(({ id }) => id === uploadPresetId);
11847
- if (!preset) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_NOT_FOUND);
11852
+ if (!preset) throw fail(require_CalmLensError.API_ERROR_CODES.UPLOAD_PRESET_NOT_FOUND);
11848
11853
  this.configuredPresets.delete(preset.key);
11849
11854
  return {};
11850
11855
  }
@@ -11873,7 +11878,7 @@ var MockCalmLensApi = class {
11873
11878
  };
11874
11879
  }
11875
11880
  checkSettingsRevision(revision) {
11876
- if (revision !== void 0 && revision !== null && Number(revision) !== this.settingsRevision) throw fail(require_ModerationContextLimits.API_ERROR_CODES.PROJECT_SETTINGS_REVISION_CONFLICT);
11881
+ if (revision !== void 0 && revision !== null && Number(revision) !== this.settingsRevision) throw fail(require_CalmLensError.API_ERROR_CODES.PROJECT_SETTINGS_REVISION_CONFLICT);
11877
11882
  }
11878
11883
  /** Replaces the settings: those left out return to their defaults. */
11879
11884
  updateProjectSettings(body) {
@@ -11908,7 +11913,7 @@ var MockCalmLensApi = class {
11908
11913
  return this.toMetadataFields();
11909
11914
  }
11910
11915
  deleteMetadataField(fieldId, query) {
11911
- if (!this.metadataFieldList.some(({ id }) => id === fieldId)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.METADATA_FIELD_NOT_FOUND, { details: { fieldId } });
11916
+ if (!this.metadataFieldList.some(({ id }) => id === fieldId)) throw fail(require_CalmLensError.API_ERROR_CODES.METADATA_FIELD_NOT_FOUND, { details: { fieldId } });
11912
11917
  this.checkSettingsRevision(query.get("revision") ?? void 0);
11913
11918
  this.metadataFieldList = this.metadataFieldList.filter(({ id }) => id !== fieldId);
11914
11919
  this.settingsRevision += 1;
@@ -11956,12 +11961,12 @@ var MockCalmLensApi = class {
11956
11961
  createLens(body) {
11957
11962
  const definition = body;
11958
11963
  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 } });
11964
+ if (this.lenses.has(definition.identifier)) throw fail(require_CalmLensError.API_ERROR_CODES.LENS_IDENTIFIER_TAKEN, { details: { identifier: definition.identifier } });
11960
11965
  return this.saveNewLens(definition);
11961
11966
  }
11962
11967
  findLens(lensId) {
11963
11968
  const lens = [...this.lenses.values()].find((candidate) => candidate.id === lensId);
11964
- if (!lens) throw fail(require_ModerationContextLimits.API_ERROR_CODES.LENS_NOT_FOUND);
11969
+ if (!lens) throw fail(require_CalmLensError.API_ERROR_CODES.LENS_NOT_FOUND);
11965
11970
  return lens;
11966
11971
  }
11967
11972
  updateLens(lensId, body) {
@@ -12266,7 +12271,7 @@ const apis = /* @__PURE__ */ new WeakMap();
12266
12271
  /** The in-memory API a mock server client runs against, for `MockCalmLensAppClient`. */
12267
12272
  const getMockApi = (client) => {
12268
12273
  const api = apis.get(client);
12269
- if (!api) throw require_ModerationContextLimits.invalidConfig("mockOptions.server must be a MockCalmLensServerClient");
12274
+ if (!api) throw require_CalmLensError.invalidConfig("mockOptions.server must be a MockCalmLensServerClient");
12270
12275
  return api;
12271
12276
  };
12272
12277
  /**
@@ -12395,7 +12400,7 @@ var MockCalmLensServerClient = class extends require_CalmLensServerClient.CalmLe
12395
12400
  * `clearFailures`. Queued after other failures, it fails the requests they don't.
12396
12401
  */
12397
12402
  failRequests(failure = "transport-error", options = {}) {
12398
- if (options && "times" in options) throw require_ModerationContextLimits.invalidArgument("failRequests fails every request: use failNextRequest for times");
12403
+ if (options && "times" in options) throw require_CalmLensError.invalidArgument("failRequests fails every request: use failNextRequest for times");
12399
12404
  this.#api.failNextRequest(failure, {
12400
12405
  ...options,
12401
12406
  times: Number.POSITIVE_INFINITY
@@ -12512,8 +12517,7 @@ const toWebhookEventPayload = (event) => ({
12512
12517
  severity: event.severity,
12513
12518
  title: event.title,
12514
12519
  description: event.description ?? null,
12515
- assetId: event.assetId ?? null,
12516
- assetSequence: event.assetSequence ?? null,
12520
+ resource: event.resource ?? null,
12517
12521
  facts: event.facts,
12518
12522
  createdAt: event.createdAt
12519
12523
  });
@@ -12529,6 +12533,9 @@ const createWebhookHeaders = async (options) => {
12529
12533
  [require_CalmLensServerClient.WEBHOOK_SIGNATURE_HEADER]: await createWebhookSignatureHeader(options.secret, timestamp, options.body)
12530
12534
  };
12531
12535
  };
12536
+ // src/testing.ts
12537
+ /** A spoken media test phrase for `signal`, signed with the project's test input key. */
12538
+ const generateMediaTestCode = (signal, key) => require_CalmLensTestInputArguments.withValidTestInputArguments(key, () => generateMediaTestCode$1(signal, key));
12532
12539
  exports.InMemoryMockDatabaseStorage = InMemoryMockDatabaseStorage;
12533
12540
  exports.InMemoryMockImageStorage = InMemoryMockImageStorage;
12534
12541
  exports.MEDIA_TEST_SIGNALS = MEDIA_TEST_SIGNALS;