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
@@ -1,6 +1,6 @@
1
- import { d as HashListEntry, u as HashList } from "./Classification-CMM2tZpJ-IdIh63n0.js";
2
- import { $ as FolderPage, At as ResetPolicyOptions, B as CreateHashListOptions, D as BatchAssetsResponse, Dt as RequestAssetReviewOptions, E as BatchAssetsOptions, Et as RemoveAssetContentOptions, Ft as SetPolicyAutomaticUpdatesOptions, G as DeleteAssetOptions, Gt as UpdateLensOptions, Ht as UpdateAssetOptions, I as ClassifyTextOptions, In as AssetSearchQuery, It as SignAssetUrlOptions, J as EnsureLensesOptions, Jt as UpgradePolicyOptions, K as DeleteMetadataFieldOptions, Kt as UpdatePolicyOptions, Lt as SignUploadTokenOptions, M as CdnAssetUrlOptions, Mn as Policy, Mt as RetrieveAssetOptions, Nt as RetryAssetOptions, P as CdnServeOptions, Q as FolderIdOptions, Qt as UploadPresetPage, Rn as AssetInfo, Rt as SignedAssetUrl, T as AssignPolicyOptions, Tt as PolicyPage, U as CreatePolicyOptions, Ut as UpdateFolderOptions, V as CreateLensOptions, Vt as SubmitAssetOptions, W as DecideAssetOptions, Wt as UpdateHashListOptions, X as EnsureUploadPresetsOptions, Y as EnsureMetadataFieldsOptions, Yt as UploadAssetPartOptions, Z as EnsureUploadPresetsResponse, Zt as UploadPresetIdOptions, _ as AssetPage, _t as ListLensesOptions, b as AssetTimelinePage, bn as MetadataFieldsResource, bt as MoveAssetOptions, ct as LensIdOptions, dt as ListAssetTimelineOptions, et as GetAssetInfoOptions, ft as ListAssetsOptions, gt as ListHashListsOptions, ht as ListHashListEntriesOptions, it as HashListPage, jt as RetrieveAssetByExternalIdOptions, k as CalmLensServerClientOptions, kt as RequestOptions, ln as GetEventsResponse, lt as LensPage, mt as ListFoldersOptions, nt as HashListEntryPage, o as AssetChildrenPage, pt as ListEventsOptions, q as EnsureLensOptions, qt as UpdateProjectSettingsOptions, r as Asset, rn as WaitForAssetDecisionOptions, rt as HashListIdOptions, sn as AssetReviewRequest, st as Lens, t as AddHashListEntryOptions, tn as VerifyWebhookSignatureOptions, tt as HashListEntryIdOptions, ut as ListAssetChildrenOptions, v as AssetSearchResponse, vt as ListPoliciesOptions, wt as PolicyIdOptions, xn as ProjectSettingsResource, xt as MoveFolderOptions, yn as Folder, yt as ListUploadPresetsOptions, z as CreateFolderOptions, zt as SignedUploadToken } from "./CalmLensTypes-C2blKgTu.js";
3
- import { d as ListPromise, l as CalmLensResponse, r as CdnResponse } from "./WebhookPayload-DZWlnvcY.js";
1
+ import { c as HashList, l as HashListEntry } from "./Classification-DbXUPSvH-C0o2t4mg.js";
2
+ import { $ as FolderPage, At as ResetPolicyOptions, B as CreateHashListOptions, Bn as AssetInfo, Cn as ProjectSettingsResource, D as BatchAssetsResponse, Dt as RequestAssetReviewOptions, E as BatchAssetsOptions, Et as RemoveAssetContentOptions, Ft as SetPolicyAutomaticUpdatesOptions, G as DeleteAssetOptions, Gt as UpdateLensOptions, Ht as UpdateAssetOptions, I as ClassifyTextOptions, It as SignAssetUrlOptions, J as EnsureLensesOptions, Jt as UpgradePolicyOptions, K as DeleteMetadataFieldOptions, Kt as UpdatePolicyOptions, Lt as SignUploadTokenOptions, M as CdnAssetUrlOptions, Mt as RetrieveAssetOptions, Nt as RetryAssetOptions, P as CdnServeOptions, Pn as Policy, Q as FolderIdOptions, Qt as UploadPresetPage, Rn as AssetSearchQuery, Rt as SignedAssetUrl, Sn as MetadataFieldsResource, T as AssignPolicyOptions, Tt as PolicyPage, U as CreatePolicyOptions, Ut as UpdateFolderOptions, V as CreateLensOptions, Vt as SubmitAssetOptions, W as DecideAssetOptions, Wt as UpdateHashListOptions, X as EnsureUploadPresetsOptions, Y as EnsureMetadataFieldsOptions, Yt as UploadAssetPartOptions, Z as EnsureUploadPresetsResponse, Zt as UploadPresetIdOptions, _ as AssetPage, _t as ListLensesOptions, b as AssetTimelinePage, bt as MoveAssetOptions, ct as LensIdOptions, dt as ListAssetTimelineOptions, et as GetAssetInfoOptions, ft as ListAssetsOptions, gt as ListHashListsOptions, ht as ListHashListEntriesOptions, it as HashListPage, jt as RetrieveAssetByExternalIdOptions, k as CalmLensServerClientOptions, kt as RequestOptions, ln as GetEventsResponse, lt as LensPage, mt as ListFoldersOptions, nt as HashListEntryPage, o as AssetChildrenPage, pt as ListEventsOptions, q as EnsureLensOptions, qt as UpdateProjectSettingsOptions, r as Asset, rn as WaitForAssetDecisionOptions, rt as HashListIdOptions, sn as AssetReviewRequest, st as Lens, t as AddHashListEntryOptions, tn as VerifyWebhookSignatureOptions, tt as HashListEntryIdOptions, ut as ListAssetChildrenOptions, v as AssetSearchResponse, vt as ListPoliciesOptions, wt as PolicyIdOptions, xn as Folder, xt as MoveFolderOptions, yt as ListUploadPresetsOptions, z as CreateFolderOptions, zt as SignedUploadToken } from "./CalmLensTypes-fAgF0_lq.js";
3
+ import { d as ListPromise, l as CalmLensResponse, r as CdnResponse } from "./WebhookPayload-DlGoY_db.js";
4
4
  interface TransportRequest {
5
5
  /** The client method sending the request, such as `assets.retrieve`, for hooks and logs. */
6
6
  operation?: string;
@@ -242,13 +242,17 @@ declare class CalmLensServerClient {
242
242
  list: (options?: ListEventsOptions, requestOptions?: RequestOptions) => ListPromise<GetEventsResponse>;
243
243
  /**
244
244
  * Retrieves the asset an event is about, as it is now, such as one from `events.list` or a
245
- * parsed webhook delivery; events carry only the asset's ID. Resolves to `null` for an
246
- * event that isn't about an asset, and rejects with `asset/not-found` once the asset is
247
- * deleted. The asset's `eventSequence` orders it against events: an event with a higher
248
- * `assetSequence` happened after this state, one with an equal or lower one is reflected in it.
245
+ * parsed webhook delivery; events carry only the asset's ID, in `resource`. Resolves to
246
+ * `null` for an event that isn't about an asset, and rejects with `asset/not-found` once the
247
+ * asset is deleted. The asset's `sequence` orders it against events: an event with a higher
248
+ * `resource.sequence` happened after this state, one with an equal or lower one is reflected
249
+ * in it.
249
250
  */
250
251
  retrieveAsset: (event: {
251
- readonly assetId?: string | null;
252
+ readonly resource?: {
253
+ readonly kind: string;
254
+ readonly id: string;
255
+ } | null;
252
256
  }, requestOptions?: RequestOptions) => Promise<CalmLensResponse<Asset> | null>;
253
257
  };
254
258
  get folders(): {
@@ -1,5 +1,6 @@
1
- const require_ModerationContextLimits = require("./ModerationContextLimits-DHu2jHpo.js");
2
- const require_CalmLensConnection = require("./CalmLensConnection-DBgV8D1B.js");
1
+ const require_CalmLensError = require("./CalmLensError-DPHJaVjX.js");
2
+ const require_ModerationContextLimits = require("./ModerationContextLimits-BVBkcgSU.js");
3
+ const require_CalmLensConnection = require("./CalmLensConnection-og0jh-Fw.js");
3
4
  const require_CryptoUtils_BLCa_oZe = require("./CryptoUtils-BLCa-oZe-leCkr1ko.js");
4
5
  // src/contract/JsonUtils.js
5
6
  const stringifyJsonCanonical = (value) => JSON.stringify(value, (_key, nestedValue) => {
@@ -56,11 +57,11 @@ const decodeUploadToken = (token) => {
56
57
  * give the same token every time, for comparing with known tokens in tests.
57
58
  */
58
59
  const signUploadTokenWithApiKey = async (apiKey, options, { now = Date.now(), nonce = crypto.randomUUID() } = {}) => {
59
- if (!options || typeof options !== "object") throw require_ModerationContextLimits.invalidArgument("Options are required");
60
+ if (!options || typeof options !== "object") throw require_CalmLensError.invalidArgument("Options are required");
60
61
  const { uploadPresetId, externalId, expiresIn = 600 } = options;
61
62
  require_ModerationContextLimits.encodePathSegment(uploadPresetId, "Upload preset ID");
62
- if (!Number.isInteger(expiresIn) || expiresIn < 1 || expiresIn > 3600) throw require_ModerationContextLimits.invalidArgument(`expiresIn must be a whole number from 1 to ${UPLOAD_TOKEN_MAX_TTL_SECONDS}`);
63
- if (externalId !== void 0 && (typeof externalId !== "string" || !externalId)) throw require_ModerationContextLimits.invalidArgument("externalId must be a non-empty string");
63
+ if (!Number.isInteger(expiresIn) || expiresIn < 1 || expiresIn > 3600) throw require_CalmLensError.invalidArgument(`expiresIn must be a whole number from 1 to ${UPLOAD_TOKEN_MAX_TTL_SECONDS}`);
64
+ if (externalId !== void 0 && (typeof externalId !== "string" || !externalId)) throw require_CalmLensError.invalidArgument("externalId must be a non-empty string");
64
65
  const expiresAt = now + expiresIn * 1e3;
65
66
  return {
66
67
  token: await signUploadToken({
@@ -95,7 +96,7 @@ const payloadToText = (payload) => {
95
96
  const view = ArrayBuffer.isView(payload) ? new Uint8Array(payload.buffer, payload.byteOffset, payload.byteLength) : new Uint8Array(payload);
96
97
  return new TextDecoder("utf-8", { fatal: false }).decode(view);
97
98
  }
98
- throw require_ModerationContextLimits.invalidArgument("Webhook payload must be the raw request body as a string, Uint8Array/Buffer or ArrayBuffer, not parsed JSON");
99
+ throw require_CalmLensError.invalidArgument("Webhook payload must be the raw request body as a string, Uint8Array/Buffer or ArrayBuffer, not parsed JSON");
99
100
  };
100
101
  /**
101
102
  * Verifies a webhook delivery: `x-calmlens-signature` must contain a `v1=` HMAC-SHA256 of
@@ -129,17 +130,17 @@ async function verifyWebhookSignature(options) {
129
130
  * so keep a default branch when you switch on `type`.
130
131
  */
131
132
  async function parseWebhookEvent(options) {
132
- if (!await verifyWebhookSignature(options)) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.INVALID_WEBHOOK_SIGNATURE, { message: "Webhook signature or timestamp did not verify" });
133
+ if (!await verifyWebhookSignature(options)) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_WEBHOOK_SIGNATURE, { message: "Webhook signature or timestamp did not verify" });
133
134
  let event;
134
135
  try {
135
136
  event = JSON.parse(payloadToText(options.payload));
136
137
  } catch (cause) {
137
- throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.INVALID_WEBHOOK_PAYLOAD, {
138
+ throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_WEBHOOK_PAYLOAD, {
138
139
  message: "Webhook body is not JSON",
139
140
  cause
140
141
  });
141
142
  }
142
- if (!isWebhookEvent(event)) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.INVALID_WEBHOOK_PAYLOAD, { message: "Webhook body is not a CalmLens event" });
143
+ if (!isWebhookEvent(event)) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_WEBHOOK_PAYLOAD, { message: "Webhook body is not a CalmLens event" });
143
144
  return event;
144
145
  }
145
146
  const isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
@@ -152,8 +153,8 @@ const isOptional = (value, type, nullable) => value === void 0 || nullable && va
152
153
  */
153
154
  const isWebhookEvent = (value) => {
154
155
  if (!isObject(value) || typeof value.id !== "string" || typeof value.type !== "string" || typeof value.projectId !== "string" || typeof value.createdAt !== "number") return false;
155
- const { severity, title, description, assetId, assetSequence, facts } = value;
156
- return isOptional(severity, "string", false) && isOptional(title, "string", false) && isOptional(description, "string", true) && isOptional(assetId, "string", true) && isOptional(assetSequence, "number", true) && (facts === void 0 || Array.isArray(facts) && facts.every((fact) => isObject(fact) && typeof fact.key === "string" && "value" in fact && isOptional(fact.url, "string", false)));
156
+ const { severity, title, description, resource, facts } = value;
157
+ return isOptional(severity, "string", false) && isOptional(title, "string", false) && isOptional(description, "string", true) && (resource === void 0 || resource === null || isObject(resource) && typeof resource.kind === "string" && typeof resource.id === "string" && typeof resource.sequence === "number") && (facts === void 0 || Array.isArray(facts) && facts.every((fact) => isObject(fact) && typeof fact.key === "string" && "value" in fact && isOptional(fact.url, "string", false)));
157
158
  };
158
159
  /**
159
160
  * The value of one of an event's facts, by key, or `undefined` when the event doesn't carry it.
@@ -177,13 +178,13 @@ const getEventFacts = (event) => {
177
178
  */
178
179
  const isTestWebhookEvent = (event) => Array.isArray(event?.facts) && event.facts.some((fact) => fact?.key === "test" && fact.value === true);
179
180
  /**
180
- * Whether to apply `event` after `lastSequence`, the highest `assetSequence` you have applied for
181
- * its asset (`null` or `undefined` when none). Deliveries can arrive out of order: an event about
182
- * an asset is newer only with a higher `assetSequence`, so a retried or repeated delivery of an
183
- * earlier one returns `false`. Events that aren't about an asset have no sequence and are always
184
- * new. Store the event's `assetSequence` per `assetId` once you have applied it.
181
+ * Whether to apply `event` after `lastSequence`, the highest `resource.sequence` you have applied
182
+ * for its resource (`null` or `undefined` when none). Deliveries can arrive out of order: an event
183
+ * about a resource is newer only with a higher sequence, so a retried or repeated delivery of an
184
+ * earlier one returns `false`. Events about no resource have no sequence and are always new.
185
+ * Store the event's `resource.sequence` per `resource.id` once you have applied it.
185
186
  */
186
- const isNewerAssetEvent = (event, lastSequence) => event.assetSequence === null || event.assetSequence === void 0 || lastSequence === null || lastSequence === void 0 || event.assetSequence > lastSequence;
187
+ const isNewerEvent = (event, lastSequence) => !event.resource || lastSequence === null || lastSequence === void 0 || event.resource.sequence > lastSequence;
187
188
  // src/client/ServedAssetInfo.ts
188
189
  function parseServedAssetInfo(header) {
189
190
  if (!header) return void 0;
@@ -308,7 +309,7 @@ var CalmLensServerClient = class {
308
309
  constructor(clientOptions = {}, lenses) {
309
310
  const options = withEnvironmentDefaults(clientOptions);
310
311
  require_ModerationContextLimits.validateServerClientOptions(options);
311
- if ((require_ModerationContextLimits.isBrowserRuntime() || require_ModerationContextLimits.isReactNativeRuntime()) && !options.dangerouslyAllowBrowser) throw require_ModerationContextLimits.invalidConfig("CalmLensServerClient is running in a browser or app, where anyone could read the API key. Call CalmLens from your server, upload from the browser or app with CalmLensAppClient, or set dangerouslyAllowBrowser: true for trusted internal tools.");
312
+ if ((require_ModerationContextLimits.isBrowserRuntime() || require_ModerationContextLimits.isReactNativeRuntime()) && !options.dangerouslyAllowBrowser) throw require_CalmLensError.invalidConfig("CalmLensServerClient is running in a browser or app, where anyone could read the API key. Call CalmLens from your server, upload from the browser or app with CalmLensAppClient, or set dangerouslyAllowBrowser: true for trusted internal tools.");
312
313
  const { apiKey, projectId, ...rest } = options;
313
314
  this.#apiKey = apiKey;
314
315
  this.#settings = {
@@ -358,8 +359,8 @@ var CalmLensServerClient = class {
358
359
  "PATCH",
359
360
  "DELETE"
360
361
  ];
361
- if (typeof method !== "string" || !methods.includes(method)) throw require_ModerationContextLimits.invalidArgument(`method must be one of ${methods.join(", ")}`);
362
- if (typeof path !== "string" || !path.startsWith("/") || path.startsWith("//")) throw require_ModerationContextLimits.invalidArgument("path must start with \"/\", such as \"/assets/asset_123\"");
362
+ if (typeof method !== "string" || !methods.includes(method)) throw require_CalmLensError.invalidArgument(`method must be one of ${methods.join(", ")}`);
363
+ if (typeof path !== "string" || !path.startsWith("/") || path.startsWith("//")) throw require_CalmLensError.invalidArgument("path must start with \"/\", such as \"/assets/asset_123\"");
363
364
  const { headers: callHeaders, ...rest } = requestOptions ?? {};
364
365
  return this.#send(void 0, {
365
366
  ...rest,
@@ -438,7 +439,7 @@ var CalmLensServerClient = class {
438
439
  expiresIn: expiresIn ?? 900,
439
440
  ...location.resource !== void 0 ? { resource: location.resource } : {}
440
441
  } });
441
- if (!signed || typeof signed.url !== "string" || !signed.url || typeof signed.expiresAt !== "number") throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.INVALID_RESPONSE, { message: "The API returned no signed asset URL" });
442
+ if (!signed || typeof signed.url !== "string" || !signed.url || typeof signed.expiresAt !== "number") throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, { message: "The API returned no signed asset URL" });
442
443
  return require_ModerationContextLimits.copyLastResponse({
443
444
  url: require_ModerationContextLimits.appendSignedLocation(signed.url, location),
444
445
  expiresAt: signed.expiresAt
@@ -462,7 +463,7 @@ var CalmLensServerClient = class {
462
463
  serve: async (options, requestOptions) => {
463
464
  const { init, resource = "rendered", ...urlOptions } = checked("cdn.serve", options);
464
465
  const connection = this.#connection.forCall("cdn.serve", requestOptions);
465
- if (requestOptions?.extraBody) throw require_ModerationContextLimits.invalidArgument("cdn.serve sends no body: extraBody can't apply");
466
+ if (requestOptions?.extraBody) throw require_CalmLensError.invalidArgument("cdn.serve sends no body: extraBody can't apply");
466
467
  const url = this.cdn.getAssetUrl({
467
468
  ...urlOptions,
468
469
  resource
@@ -687,12 +688,13 @@ sign: async (options) => {
687
688
  } })),
688
689
  /**
689
690
  * Retrieves the asset an event is about, as it is now, such as one from `events.list` or a
690
- * parsed webhook delivery; events carry only the asset's ID. Resolves to `null` for an
691
- * event that isn't about an asset, and rejects with `asset/not-found` once the asset is
692
- * deleted. The asset's `eventSequence` orders it against events: an event with a higher
693
- * `assetSequence` happened after this state, one with an equal or lower one is reflected in it.
691
+ * parsed webhook delivery; events carry only the asset's ID, in `resource`. Resolves to
692
+ * `null` for an event that isn't about an asset, and rejects with `asset/not-found` once the
693
+ * asset is deleted. The asset's `sequence` orders it against events: an event with a higher
694
+ * `resource.sequence` happened after this state, one with an equal or lower one is reflected
695
+ * in it.
694
696
  */
695
- retrieveAsset: async (event, requestOptions) => event.assetId ? this.assets.retrieve({ assetId: event.assetId }, requestOptions) : null
697
+ retrieveAsset: async (event, requestOptions) => event.resource?.kind === "asset" ? this.assets.retrieve({ assetId: event.resource.id }, requestOptions) : null
696
698
  };
697
699
  }
698
700
  get folders() {
@@ -891,7 +893,7 @@ sign: async (options) => {
891
893
  */
892
894
  async ensureLens(options, requestOptions) {
893
895
  checked("ensureLens", options);
894
- if (!options?.identifier) throw require_ModerationContextLimits.invalidArgument("Lens identifier is required");
896
+ if (!options?.identifier) throw require_CalmLensError.invalidArgument("Lens identifier is required");
895
897
  const [lens] = await this.ensureLenses({ lenses: [options] }, requestOptions);
896
898
  return lens;
897
899
  }
@@ -903,8 +905,8 @@ sign: async (options) => {
903
905
  async ensureLenses(options, requestOptions) {
904
906
  require_CalmLensConnection.validateCallOptions(requestOptions);
905
907
  const { lenses } = checked("ensureLenses", options);
906
- if (!Array.isArray(lenses) || lenses.length === 0) throw require_ModerationContextLimits.invalidArgument("At least one lens is required");
907
- if (lenses.some((option) => !option?.identifier)) throw require_ModerationContextLimits.invalidArgument("Lens identifier is required");
908
+ if (!Array.isArray(lenses) || lenses.length === 0) throw require_CalmLensError.invalidArgument("At least one lens is required");
909
+ if (lenses.some((option) => !option?.identifier)) throw require_CalmLensError.invalidArgument("Lens identifier is required");
908
910
  for (const lens of lenses) checked("ensureLens", lens);
909
911
  const { ensuredLenses, pendingEnsureLenses } = this.#lenses;
910
912
  const missingOptions = [];
@@ -928,7 +930,7 @@ sign: async (options) => {
928
930
  }
929
931
  return lenses.map((option) => {
930
932
  const lens = ensuredLenses.get(getEnsureLensCacheKey(option));
931
- if (!lens) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.INVALID_RESPONSE, { message: `CalmLens did not return lens "${option.identifier}"` });
933
+ if (!lens) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, { message: `CalmLens did not return lens "${option.identifier}"` });
932
934
  return lens;
933
935
  });
934
936
  }
@@ -938,11 +940,11 @@ sign: async (options) => {
938
940
  async #submitEnsureLensesChunk(options, requestOptions) {
939
941
  const result = await this.#send("ensureLenses", requestOptions, "PUT", `${this.#projectPath}/lenses`, { body: { lenses: options } });
940
942
  const returned = Array.isArray(result?.lenses) ? result.lenses : [];
941
- if (returned.length !== options.length) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.INVALID_RESPONSE, { message: `Expected ${options.length} lenses but CalmLens returned ${returned.length}` });
943
+ if (returned.length !== options.length) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, { message: `Expected ${options.length} lenses but CalmLens returned ${returned.length}` });
942
944
  const { ensuredLenses } = this.#lenses;
943
945
  for (const [index, lens] of returned.entries()) {
944
946
  const optionsForLens = options[index];
945
- if (lens?.identifier !== optionsForLens.identifier) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.SDK_ERROR_CODES.INVALID_RESPONSE, { message: `Expected lens "${optionsForLens.identifier}" at position ${index}` });
947
+ if (lens?.identifier !== optionsForLens.identifier) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, { message: `Expected lens "${optionsForLens.identifier}" at position ${index}` });
946
948
  for (const [cacheKey, cachedLens] of ensuredLenses) if (cachedLens.identifier === optionsForLens.identifier) ensuredLenses.delete(cacheKey);
947
949
  ensuredLenses.set(getEnsureLensCacheKey(optionsForLens), lens);
948
950
  }
@@ -996,10 +998,10 @@ Object.defineProperty(exports, "getEventFacts", {
996
998
  return getEventFacts;
997
999
  }
998
1000
  });
999
- Object.defineProperty(exports, "isNewerAssetEvent", {
1001
+ Object.defineProperty(exports, "isNewerEvent", {
1000
1002
  enumerable: true,
1001
1003
  get: function() {
1002
- return isNewerAssetEvent;
1004
+ return isNewerEvent;
1003
1005
  }
1004
1006
  });
1005
1007
  Object.defineProperty(exports, "isTestWebhookEvent", {
@@ -19,9 +19,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
19
19
  value: mod,
20
20
  enumerable: true
21
21
  }) : target, mod));
22
+ const require_CalmLensError = require("./CalmLensError-DPHJaVjX.js");
22
23
  const require_CryptoUtils_BLCa_oZe = require("./CryptoUtils-BLCa-oZe-leCkr1ko.js");
23
24
  let zod = require("zod");
24
- zod = __toESM(zod, 1);
25
+ let zod$1 = __toESM(zod, 1);
26
+ zod = __toESM(zod);
25
27
  // src/contract/ModerationCategories-CHFRoeWV.js
26
28
  const CLASSIFICATION_CATEGORIES = [
27
29
  "sexual",
@@ -34,7 +36,7 @@ const CLASSIFICATION_CATEGORIES = [
34
36
  "profanity"
35
37
  ];
36
38
  // src/contract/LazySchema-BKMpWIaF.js
37
- const registryMap = zod.globalRegistry._map;
39
+ const registryMap = zod$1.globalRegistry._map;
38
40
  /**
39
41
  * A schema built the first time anything reads it, rather than when its module loads. Building
40
42
  * Zod schemas costs a new isolate CPU before its first request, so a module whose schemas most
@@ -150,7 +152,7 @@ const JURISDICTIONS = {
150
152
  optional: false
151
153
  }
152
154
  };
153
- const JURISDICTION_SCHEMA = /* @__PURE__ */ lazySchema(() => zod.enum(Object.keys(JURISDICTIONS)));
155
+ const JURISDICTION_SCHEMA = /* @__PURE__ */ lazySchema(() => zod$1.enum(Object.keys(JURISDICTIONS)));
154
156
  Object.keys(JURISDICTIONS).filter((code) => !JURISDICTIONS[code].optional);
155
157
  Object.keys(JURISDICTIONS).filter((code) => JURISDICTIONS[code].optional);
156
158
  new Set("AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW".split(" "));
@@ -1178,9 +1180,9 @@ function getModerationQualifierInfo(qualifier) {
1178
1180
  return MODERATION_QUALIFIER_INFO[qualifier];
1179
1181
  }
1180
1182
  /** Authenticated test inputs can add regional delivery restrictions without inventing evidence. */
1181
- const TEST_REGIONAL_ACTIONS_SCHEMA = /* @__PURE__ */ lazySchema(() => zod.array(zod.object({
1183
+ const TEST_REGIONAL_ACTIONS_SCHEMA = /* @__PURE__ */ lazySchema(() => zod$1.array(zod$1.object({
1182
1184
  region: JURISDICTION_SCHEMA.exclude(["global"]),
1183
- action: zod.enum([
1185
+ action: zod$1.enum([
1184
1186
  "limit",
1185
1187
  "age-restrict",
1186
1188
  "block"
@@ -1646,45 +1648,45 @@ const TEST_FACE_AGE_PRESETS = {
1646
1648
  }
1647
1649
  };
1648
1650
  const TEST_FACE_AGE_MAX = 120;
1649
- const basisPoints = /* @__PURE__ */ lazySchema(() => zod.number().int().min(0).max(TEST_DETECTION_BOX_MAX));
1651
+ const basisPoints = /* @__PURE__ */ lazySchema(() => zod$1.number().int().min(0).max(TEST_DETECTION_BOX_MAX));
1650
1652
  const detectionShape = {
1651
- box: /* @__PURE__ */ lazySchema(() => zod.tuple([
1653
+ box: /* @__PURE__ */ lazySchema(() => zod$1.tuple([
1652
1654
  basisPoints,
1653
1655
  basisPoints,
1654
1656
  basisPoints,
1655
1657
  basisPoints
1656
1658
  ])),
1657
- confidence: /* @__PURE__ */ lazySchema(() => zod.number().int().min(0).max(100).optional())
1659
+ confidence: /* @__PURE__ */ lazySchema(() => zod$1.number().int().min(0).max(100).optional())
1658
1660
  };
1659
1661
  const fitsImage = ({ box: [left, top, width, height] }) => left + width <= 1e4 && top + height <= 1e4;
1660
1662
  const BOX_MESSAGE = msg("A box must lie inside the image: left + width and top + height are at most 10000.");
1661
- const ageYears = /* @__PURE__ */ lazySchema(() => zod.number().int().min(0).max(120));
1662
- const TEST_DETECTED_PERSON_SCHEMA = /* @__PURE__ */ lazySchema(() => zod.object(detectionShape).strict().refine(fitsImage, BOX_MESSAGE));
1663
- const TEST_DETECTED_FACE_SCHEMA = /* @__PURE__ */ lazySchema(() => zod.object({
1663
+ const ageYears = /* @__PURE__ */ lazySchema(() => zod$1.number().int().min(0).max(120));
1664
+ const TEST_DETECTED_PERSON_SCHEMA = /* @__PURE__ */ lazySchema(() => zod$1.object(detectionShape).strict().refine(fitsImage, BOX_MESSAGE));
1665
+ const TEST_DETECTED_FACE_SCHEMA = /* @__PURE__ */ lazySchema(() => zod$1.object({
1664
1666
  ...detectionShape,
1665
- age: zod.union([zod.enum(["adult", "minor"]), zod.object({
1667
+ age: zod$1.union([zod$1.enum(["adult", "minor"]), zod$1.object({
1666
1668
  low: ageYears,
1667
1669
  high: ageYears
1668
1670
  }).strict().refine(({ low, high }) => low <= high, msg("An age range's low must not be above its high."))]).optional()
1669
1671
  }).strict().refine(fitsImage, BOX_MESSAGE));
1670
1672
  /** Person and face detection results a test image reports instead of running detection. */
1671
- const TEST_DETECTIONS_SCHEMA = /* @__PURE__ */ lazySchema(() => zod.object({
1672
- people: zod.union([zod.array(TEST_DETECTED_PERSON_SCHEMA).max(32), zod.literal("unavailable")]).optional(),
1673
- faces: zod.union([zod.array(TEST_DETECTED_FACE_SCHEMA).max(32), zod.literal("unavailable")]).optional()
1673
+ const TEST_DETECTIONS_SCHEMA = /* @__PURE__ */ lazySchema(() => zod$1.object({
1674
+ people: zod$1.union([zod$1.array(TEST_DETECTED_PERSON_SCHEMA).max(32), zod$1.literal("unavailable")]).optional(),
1675
+ faces: zod$1.union([zod$1.array(TEST_DETECTED_FACE_SCHEMA).max(32), zod$1.literal("unavailable")]).optional()
1674
1676
  }).strict());
1675
1677
  /** Each row is one qualifying instance. Unselected qualifiers are explicitly absent. */
1676
- const TEST_INPUT_SCHEMA = /* @__PURE__ */ lazySchema(() => zod.object({
1678
+ const TEST_INPUT_SCHEMA = /* @__PURE__ */ lazySchema(() => zod$1.object({
1677
1679
  regionalActions: TEST_REGIONAL_ACTIONS_SCHEMA.optional(),
1678
- unassessedCategories: zod.array(zod.enum(CLASSIFICATION_CATEGORIES)).max(CLASSIFICATION_CATEGORIES.length).optional(),
1679
- instances: zod.array(zod.object({
1680
- category: zod.enum(CLASSIFICATION_CATEGORIES),
1681
- score: zod.number().min(0).max(1).optional(),
1682
- action: zod.enum([
1680
+ unassessedCategories: zod$1.array(zod$1.enum(CLASSIFICATION_CATEGORIES)).max(CLASSIFICATION_CATEGORIES.length).optional(),
1681
+ instances: zod$1.array(zod$1.object({
1682
+ category: zod$1.enum(CLASSIFICATION_CATEGORIES),
1683
+ score: zod$1.number().min(0).max(1).optional(),
1684
+ action: zod$1.enum([
1683
1685
  "limit",
1684
1686
  "age-restrict",
1685
1687
  "block"
1686
1688
  ]).optional(),
1687
- qualifiers: zod.array(zod.enum(MODERATION_QUALIFIERS)).max(64)
1689
+ qualifiers: zod$1.array(zod$1.enum(MODERATION_QUALIFIERS)).max(64)
1688
1690
  }).strict().superRefine((instance, context) => {
1689
1691
  if (new Set(instance.qualifiers).size !== instance.qualifiers.length || instance.qualifiers.some((q) => getModerationQualifierInfo(q).category !== instance.category || "fromInput" in getModerationQualifierInfo(q))) context.addIssue({
1690
1692
  code: "custom",
@@ -1978,6 +1980,26 @@ async function detectTestImage(image, key, { whole = true } = {}) {
1978
1980
  if (!scenario || !whole) return scenario;
1979
1981
  return matchesTestImageGrid(image, grid, paintTestImageGrid(data.subarray(0, 18 + length), testImagePalette(scenario))) ? scenario : void 0;
1980
1982
  }
1983
+ // src/client/CalmLensTestInputArguments.ts
1984
+ /**
1985
+ * Runs a test input generator with the caller's scenario and key, reporting an invalid one as an
1986
+ * `sdk/invalid-argument` CalmLensError (naming the offending scenario field) instead of the
1987
+ * contract's raw validation error.
1988
+ */
1989
+ async function withValidTestInputArguments(key, generate) {
1990
+ if (!TEST_INPUT_KEY_PATTERN.test(key)) throw require_CalmLensError.invalidArgument("key must be a test input key: 32 lowercase hexadecimal characters");
1991
+ try {
1992
+ return await generate();
1993
+ } catch (error) {
1994
+ if (error instanceof zod.ZodError) {
1995
+ const [issue] = error.issues;
1996
+ const path = (issue?.path ?? []).map((segment) => typeof segment === "number" ? segment : String(segment));
1997
+ throw require_CalmLensError.invalidArgument(`Invalid test scenario at ${path.length ? path.join(".") : "scenario"}: ${issue?.message ?? error.message}`, { path });
1998
+ }
1999
+ if (error instanceof RangeError) throw require_CalmLensError.invalidArgument(error.message);
2000
+ throw error;
2001
+ }
2002
+ }
1981
2003
  Object.defineProperty(exports, "CLASSIFICATION_CATEGORIES", {
1982
2004
  enumerable: true,
1983
2005
  get: function() {
@@ -2074,3 +2096,9 @@ Object.defineProperty(exports, "testInputForSignal", {
2074
2096
  return testInputForSignal;
2075
2097
  }
2076
2098
  });
2099
+ Object.defineProperty(exports, "withValidTestInputArguments", {
2100
+ enumerable: true,
2101
+ get: function() {
2102
+ return withValidTestInputArguments;
2103
+ }
2104
+ });