calmlens 0.18.3 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/bin/calmlens.js +5682 -5036
  2. package/cjs/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-C07aL9Vq.d.ts} +2 -2
  3. package/cjs/{BrowserUpload-UxIAGNdv.js → BrowserUpload-CjSHjx3C.js} +1 -1
  4. package/{esm/CalmLensAppClient-CV_K26Ce.d.ts → cjs/CalmLensAppClient-DDLojj0P.d.ts} +3 -3
  5. package/cjs/{CalmLensAppClient-D6p7MAFz.js → CalmLensAppClient-NaCxOVlM.js} +32 -11
  6. package/cjs/{CalmLensConnection-CYoUl5go.js → CalmLensOptionKeys-p2QK687A.js} +430 -9
  7. package/cjs/{CalmLensServerClient-p23cl97D.js → CalmLensServerClient-BDzTthxE.js} +173 -55
  8. package/cjs/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-C-jsjn8m.d.ts} +54 -30
  9. package/cjs/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-COJbOuiv.d.ts} +2677 -30
  10. package/cjs/{ModerationContextLimits-DCLXMxyA.js → ModerationContextLimits-2nIv7Zh3.js} +495 -49
  11. package/cjs/{ReactUpload-BcdNWLiU.js → ReactUpload-BdTRCTGA.js} +1 -1
  12. package/cjs/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-CRJNPB5T.d.ts} +1 -1
  13. package/{esm/TestTriggers-By07LR31-CmK0yTyR.d.ts → cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
  14. package/cjs/{TestTriggers-DTc_iMJF-BjMPq4_3.js → TestTriggers-DbhsNPdg-DjvVuc2h.js} +434 -74
  15. package/cjs/{UploadController-Cxu0bufo.js → UploadController-MLVs97Zt.js} +17 -5
  16. package/{esm/WebhookPayload-2aL31v0J.d.ts → cjs/WebhookPayload-DkukERKE.d.ts} +29 -3
  17. package/cjs/app.d.ts +6 -6
  18. package/cjs/app.js +2 -2
  19. package/cjs/elements.d.ts +3 -3
  20. package/cjs/elements.js +3 -3
  21. package/cjs/{index-CI4BzN4W.d.ts → index-DxbJ_Xaa.d.ts} +7 -6
  22. package/cjs/index.d.ts +5 -5
  23. package/cjs/index.js +1 -1
  24. package/cjs/react-native.d.ts +3 -3
  25. package/cjs/react-native.js +3 -3
  26. package/cjs/react.d.ts +3 -3
  27. package/cjs/react.js +4 -4
  28. package/cjs/server.d.ts +6 -6
  29. package/cjs/server.js +2 -2
  30. package/cjs/test-inputs.d.ts +1 -1
  31. package/cjs/test-inputs.js +9 -9
  32. package/cjs/testing.d.ts +12 -8
  33. package/cjs/testing.js +298 -35
  34. package/{esm/ui-wIiMfqMB.d.ts → cjs/ui-BSqPGKrZ.d.ts} +17 -4
  35. package/cjs/{ui-C0XXJS52.js → ui-CX1z2pD9.js} +13 -10
  36. package/cjs/ui.d.ts +2 -2
  37. package/cjs/ui.js +2 -2
  38. package/cjs/vue.d.ts +5 -5
  39. package/cjs/vue.js +3 -3
  40. package/esm/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-C07aL9Vq.d.ts} +2 -2
  41. package/esm/{BrowserUpload-BXG2isHV.js → BrowserUpload-CAVkRotw.js} +1 -1
  42. package/{cjs/CalmLensAppClient-CV_K26Ce.d.ts → esm/CalmLensAppClient-DDLojj0P.d.ts} +3 -3
  43. package/esm/{CalmLensAppClient-BMgXamoN.js → CalmLensAppClient-PQ9VBvlW.js} +28 -7
  44. package/esm/{CalmLensConnection-DBoDh06c.js → CalmLensOptionKeys-Do2mPP6w.js} +407 -10
  45. package/esm/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-C-jsjn8m.d.ts} +54 -30
  46. package/esm/{CalmLensServerClient-Dt7rCITa.js → CalmLensServerClient-C_H5aAsV.js} +165 -47
  47. package/esm/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-COJbOuiv.d.ts} +2677 -30
  48. package/esm/{ModerationContextLimits-KMQ8puoa.js → ModerationContextLimits-Chw-AzgL.js} +462 -46
  49. package/esm/{ReactUpload-CFy_wETY.js → ReactUpload-CMmL0R5Q.js} +1 -1
  50. package/esm/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-CRJNPB5T.d.ts} +1 -1
  51. package/{cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts → esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
  52. package/esm/{TestTriggers-DTc_iMJF-HfB533Gx.js → TestTriggers-DbhsNPdg-CUdrv8Nm.js} +405 -72
  53. package/esm/{UploadController-Cs-bxUbt.js → UploadController-BJZghJpg.js} +17 -5
  54. package/{cjs/WebhookPayload-2aL31v0J.d.ts → esm/WebhookPayload-DkukERKE.d.ts} +29 -3
  55. package/esm/app.d.ts +6 -6
  56. package/esm/app.js +2 -2
  57. package/esm/elements.d.ts +3 -3
  58. package/esm/elements.js +3 -3
  59. package/esm/{index-CI4BzN4W.d.ts → index-DxbJ_Xaa.d.ts} +7 -6
  60. package/esm/index.d.ts +5 -5
  61. package/esm/index.js +1 -1
  62. package/esm/react-native.d.ts +3 -3
  63. package/esm/react-native.js +3 -3
  64. package/esm/react.d.ts +3 -3
  65. package/esm/react.js +4 -4
  66. package/esm/server.d.ts +6 -6
  67. package/esm/server.js +2 -2
  68. package/esm/test-inputs.d.ts +1 -1
  69. package/esm/test-inputs.js +1 -1
  70. package/esm/testing.d.ts +12 -8
  71. package/esm/testing.js +287 -23
  72. package/{cjs/ui-wIiMfqMB.d.ts → esm/ui-BSqPGKrZ.d.ts} +17 -4
  73. package/esm/{ui-BqYkISSE.js → ui-CXH7xJpb.js} +12 -9
  74. package/esm/ui.d.ts +2 -2
  75. package/esm/ui.js +2 -2
  76. package/esm/vue.d.ts +5 -5
  77. package/esm/vue.js +3 -3
  78. package/package.json +1 -1
  79. package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +0 -91
  80. package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +0 -46
  81. /package/cjs/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
  82. /package/esm/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
- import { A as invalidArgument, O as CalmLensError, b as validateServerClientOptions, c as DEFAULT_CDN_BASE_URL, d as pollForDecision, g as transformSelector, h as toTextAssetOptions, j as invalidConfig, k as SDK_ERROR_CODES, l as encodePathSegment, o as isBrowserRuntime, s as isReactNativeRuntime, u as getAssetUrl, v as validateBatchAssetsOptions, x as validateSignedUrlOptions, y as validateRequestOptions } from "./ModerationContextLimits-KMQ8puoa.js";
2
- import { a as getMockHooks, c as prepareSubmitAssetOptions, l as resolveConnectionOptions, o as invalidPayload, r as expectAsset, s as newIdempotencyKey, t as CalmLensConnection } from "./CalmLensConnection-DBoDh06c.js";
1
+ import { C as validateRequestOptions, F as invalidArgument, I as invalidConfig, N as CalmLensError, P as SDK_ERROR_CODES, S as validateBatchAssetsOptions, T as validateSignedUrlOptions, b as transformSelector, c as DEFAULT_CDN_BASE_URL, d as encodePathSegment, f as getAssetUrl, h as pollForDecision, l as checkOptionKeys, o as isBrowserRuntime, s as isReactNativeRuntime, w as validateServerClientOptions, y as toTextAssetOptions } from "./ModerationContextLimits-Chw-AzgL.js";
2
+ import { c as getMockHooks, d as prepareSubmitAssetOptions, f as resolveConnectionOptions, i as CalmLensConnection, l as invalidPayload, n as NULLABLE_OPTION_KEYS, o as expectAsset, p as splitsIntoParts, r as SERVER_OPTION_KEYS, u as newIdempotencyKey } from "./CalmLensOptionKeys-Do2mPP6w.js";
3
3
  import { n as sha256Hex, r as timingSafeEqual, t as hmacSha256Hex } from "./CryptoUtils-B_x8lMIx-DhuWGzqn.js";
4
4
  // src/contract/JsonUtils.js
5
5
  const stringifyJsonCanonical = (value) => JSON.stringify(value, (_key, nestedValue) => {
@@ -142,11 +142,21 @@ const getEnsureLensCacheKey = (options) => stringifyJsonCanonical({
142
142
  description: options.description ?? null,
143
143
  type: options.type,
144
144
  active: options.active,
145
- transforms: options.transforms ?? null,
145
+ transform: options.transform ?? null,
146
146
  version: options.version
147
147
  });
148
148
  const requireId = (value, name) => encodePathSegment(value, name);
149
149
  /**
150
+ * `options`, once `checkOptionKeys` finds only keys `operation` takes, without the options given as
151
+ * `null` that the API refuses as `null`: those are left out, as if omitted.
152
+ */
153
+ const checked = (operation, options) => {
154
+ checkOptionKeys(options, operation, SERVER_OPTION_KEYS);
155
+ if (!options || typeof options !== "object" || Array.isArray(options)) return options;
156
+ const nullable = NULLABLE_OPTION_KEYS[operation] ?? [];
157
+ return Object.fromEntries(Object.entries(options).filter(([key, value]) => value !== null || nullable.includes(key)));
158
+ };
159
+ /**
150
160
  * Iterators stop rather than loop: a page that says more follow must not hand back a cursor this
151
161
  * iteration has already sent, which would repeat the same pages forever.
152
162
  */
@@ -234,8 +244,15 @@ var CalmLensServerClient = class CalmLensServerClient {
234
244
  return this.#connection.json(method, path, options);
235
245
  }
236
246
  async submitAsset(options, queue) {
237
- const body = prepareSubmitAssetOptions(options, { deferUploadChecks: this.#connection.deferUploadChecks });
247
+ const body = prepareSubmitAssetOptions(options, {
248
+ deferUploadChecks: this.#connection.deferUploadChecks,
249
+ partSizeBytes: this.#connection.partSizeBytes
250
+ });
238
251
  const uploadsPath = `${this.projectPath}/assets`;
252
+ if ("content" in body && splitsIntoParts(body.content, this.#connection.partSizeBytes)) return expectAsset(await this.#connection.submitInParts(uploadsPath, body, queue, {
253
+ partPath: (assetId) => `/assets/${encodeURIComponent(assetId)}/part`,
254
+ retrieve: (assetId) => this.buildAssets().retrieve({ assetId })
255
+ }));
239
256
  if ("content" in body || "part" in body) return expectAsset(await this.#connection.submitRawUpload(uploadsPath, body, queue));
240
257
  const { idempotencyKey, ...fields } = body;
241
258
  const data = await this.#connection.json("POST", uploadsPath, {
@@ -250,9 +267,12 @@ var CalmLensServerClient = class CalmLensServerClient {
250
267
  /**
251
268
  * Builds a CDN URL for asset content or a preview, without a request. Private assets
252
269
  * need a signed URL (`assets.createSignedUrl`) or an authenticated request; public
253
- * age-restricted assets additionally require `viewerClaims.ageConfirmed: true`.
270
+ * age-restricted assets additionally require `viewerClaims.ageConfirmed: true`. Your
271
+ * platform confirms the viewer's age; CalmLens does not verify this claim, and anyone can
272
+ * add it to a public URL.
254
273
  */
255
- getAssetUrl: ({ assetIdentifier, ...options }) => {
274
+ getAssetUrl: (urlOptions) => {
275
+ const { assetIdentifier, ...options } = checked("cdn.getAssetUrl", urlOptions);
256
276
  const { projectId, cdnBaseUrl } = this.#settings;
257
277
  return getAssetUrl({
258
278
  projectId,
@@ -266,7 +286,8 @@ var CalmLensServerClient = class CalmLensServerClient {
266
286
  * the `Response` as soon as headers arrive, so the body streams. Non-2xx responses are
267
287
  * returned, not thrown; `timeoutMs` covers only the wait for headers.
268
288
  */
269
- serve: async ({ assetIdentifier, init, ...urlOptions }) => {
289
+ serve: async (options) => {
290
+ const { assetIdentifier, init, ...urlOptions } = checked("cdn.serve", options);
270
291
  const url = this.cdn.getAssetUrl({
271
292
  assetIdentifier,
272
293
  ...urlOptions
@@ -290,7 +311,7 @@ var CalmLensServerClient = class CalmLensServerClient {
290
311
  * Moderates text and waits for the decision. Sends `text` as `text/plain` content named
291
312
  * `text` unless you pass `name`.
292
313
  */
293
- classify: async (options) => this.buildAssets().classify(toTextAssetOptions(options)) };
314
+ classify: async (options) => this.buildAssets().classify(toTextAssetOptions(checked("text.classify", options))) };
294
315
  }
295
316
  /** Assets: uploads, moderation and management. */
296
317
  get assets() {
@@ -307,31 +328,44 @@ classify: async (options) => this.buildAssets().classify(toTextAssetOptions(opti
307
328
  * browser or app, which passes it to `CalmLensAppClient` as `token`.
308
329
  */
309
330
  sign: async (options) => {
310
- return signUploadTokenWithApiKey(this.#apiKey, options, this.#connection.hooks?.uploadTokenTime());
331
+ return signUploadTokenWithApiKey(this.#apiKey, checked("uploadTokens.sign", options), this.#connection.hooks?.uploadTokenTime());
311
332
  } };
312
333
  }
313
334
  buildAssets() {
314
335
  return {
315
336
  /** Searches accessible assets by keyword or a natural-language description. */
316
- search: async (options) => this.request("GET", `${this.projectPath}/assets/search`, { query: options }),
337
+ search: async (options) => this.request("GET", `${this.projectPath}/assets/search`, { query: checked("assets.search", options) }),
317
338
  /** Lists one page of the project's assets, with optional filter and ordering. */
318
- list: async (options = {}) => this.request("GET", `${this.projectPath}/assets`, { query: options }),
339
+ list: async (options = {}) => this.request("GET", `${this.projectPath}/assets`, { query: checked("assets.list", options) }),
319
340
  /**
320
341
  * Yields every asset matching `options`, fetching pages as needed. The cursor keeps the position
321
342
  * stable when other assets are inserted or deleted.
322
343
  */
323
- iterate: (options = {}) => this.iteratePages((cursor) => this.buildAssets().list({
324
- ...options,
325
- cursor
326
- })),
344
+ iterate: (options = {}) => {
345
+ checked("assets.iterate", options);
346
+ return this.iteratePages((cursor) => this.buildAssets().list({
347
+ ...options,
348
+ cursor
349
+ }));
350
+ },
327
351
  /** Retrieves an asset with its status and classification results. */
328
- retrieve: async ({ assetId }) => this.request("GET", `/assets/${requireId(assetId, "Asset ID")}`),
352
+ retrieve: async (options) => {
353
+ const { assetId } = checked("assets.retrieve", options);
354
+ return this.request("GET", `/assets/${requireId(assetId, "Asset ID")}`);
355
+ },
329
356
  /** Updates an asset's editable fields. */
330
- update: async ({ assetId, ...body }) => this.request("PATCH", `/assets/${requireId(assetId, "Asset ID")}`, { body }),
357
+ update: async (options) => {
358
+ const { assetId, ...body } = checked("assets.update", options);
359
+ return this.request("PATCH", `/assets/${requireId(assetId, "Asset ID")}`, { body });
360
+ },
331
361
  /** Lists one page of the assets extracted from a website or multimedia document. */
332
- listChildren: async ({ assetId, ...options } = {}) => this.request("GET", `/assets/${requireId(assetId, "Asset ID")}/children`, { query: options }),
362
+ listChildren: async (options = {}) => {
363
+ const { assetId, ...query } = checked("assets.listChildren", options);
364
+ return this.request("GET", `/assets/${requireId(assetId, "Asset ID")}/children`, { query });
365
+ },
333
366
  /** Yields every child of an asset, fetching pages as needed. */
334
367
  iterateChildren: (options) => {
368
+ checked("assets.iterateChildren", options);
335
369
  requireId(options?.assetId, "Asset ID");
336
370
  return this.iteratePages((cursor) => this.buildAssets().listChildren({
337
371
  ...options,
@@ -343,12 +377,13 @@ sign: async (options) => {
343
377
  * status `processing` (or `uploading` for the first multipart part). Retried safely with an
344
378
  * `Idempotency-Key`.
345
379
  */
346
- create: async (options) => this.submitAsset(options, true),
380
+ create: async (options) => this.submitAsset(checked("assets.create", options), true),
347
381
  /**
348
382
  * Uploads an asset and waits for its moderation decision. Audio and video still finish
349
383
  * in the background. Retried safely with an `Idempotency-Key`.
350
384
  */
351
- classify: async (options) => {
385
+ classify: async (classifyOptions) => {
386
+ const options = checked("assets.classify", classifyOptions);
352
387
  if (options && "content" in options && "plainText" in options.content && (typeof options.content.plainText !== "string" || !options.content.plainText.trim())) throw invalidPayload("Text to classify must be a non-empty string");
353
388
  return this.submitAsset(options, false);
354
389
  },
@@ -356,7 +391,8 @@ sign: async (options) => {
356
391
  * Uploads the next part of a multipart upload. The upload's queue mode, chosen when it
357
392
  * started, applies when the final part arrives; pass `queue` to override it.
358
393
  */
359
- uploadPart: async ({ assetId, ...options }) => {
394
+ uploadPart: async (partOptions) => {
395
+ const { assetId, ...options } = checked("assets.uploadPart", partOptions);
360
396
  const encodedAssetId = requireId(assetId, "Asset ID");
361
397
  return expectAsset(await this.#connection.uploadPart(`/assets/${encodedAssetId}/part`, options));
362
398
  },
@@ -364,7 +400,8 @@ sign: async (options) => {
364
400
  * Creates a short-lived signed CDN URL, so browsers can load private content without
365
401
  * an API key.
366
402
  */
367
- createSignedUrl: async ({ assetId, ...options }) => {
403
+ createSignedUrl: async (signedUrlOptions) => {
404
+ const { assetId, ...options } = checked("assets.createSignedUrl", signedUrlOptions);
368
405
  const encodedAssetId = requireId(assetId, "Asset ID");
369
406
  validateSignedUrlOptions(options);
370
407
  return this.request("POST", `/assets/${encodedAssetId}/signed-url`, { body: {
@@ -376,20 +413,29 @@ sign: async (options) => {
376
413
  } });
377
414
  },
378
415
  /** Moves an asset into a folder, or to the project root with `folderId: null`. */
379
- move: async ({ assetId, folderId }) => this.request("POST", `/assets/${requireId(assetId, "Asset ID")}/move`, { body: { folderId } }),
416
+ move: async (options) => {
417
+ const { assetId, folderId } = checked("assets.move", options);
418
+ return this.request("POST", `/assets/${requireId(assetId, "Asset ID")}/move`, { body: { folderId } });
419
+ },
380
420
  /**
381
421
  * Processes an asset that failed (classification status `failed`) again. It returns to
382
422
  * `processing` and is
383
423
  * moderated like a new upload; its content must still be stored.
384
424
  */
385
- retry: async ({ assetId }) => this.request("POST", `/assets/${requireId(assetId, "Asset ID")}/retry`),
425
+ retry: async (options) => {
426
+ const { assetId } = checked("assets.retry", options);
427
+ return this.request("POST", `/assets/${requireId(assetId, "Asset ID")}/retry`);
428
+ },
386
429
  /**
387
430
  * Records a reviewer's decision, replacing the policy's: the asset's moderation status
388
431
  * becomes `decision`, the note joins its review history and the matching `asset.<status>`
389
432
  * event is sent. An asset still pending moderation can only be blocked or purged. Purging
390
433
  * needs `confirmPurge: true` and permanently deletes the stored content.
391
434
  */
392
- decide: async ({ assetId, ...body }) => this.request("POST", `/assets/${requireId(assetId, "Asset ID")}/decision`, { body }),
435
+ decide: async (options) => {
436
+ const { assetId, ...body } = checked("assets.decide", options);
437
+ return this.request("POST", `/assets/${requireId(assetId, "Asset ID")}/decision`, { body });
438
+ },
393
439
  /**
394
440
  * Completes the policy evidence behind a decided asset's moderation decision: the report's
395
441
  * `classification.moderation.evidence` becomes `full` and every action stays as
@@ -397,13 +443,17 @@ sign: async (options) => {
397
443
  * and returns in `processing`; use it when the policy has changed since the decision
398
444
  * (`asset/policy-changed`).
399
445
  */
400
- explain: async ({ assetId, rerun }) => this.request("POST", `/assets/${requireId(assetId, "Asset ID")}/explain`, { body: rerun ? { rerun } : {} }),
446
+ explain: async (options) => {
447
+ const { assetId, rerun } = checked("assets.explain", options);
448
+ return this.request("POST", `/assets/${requireId(assetId, "Asset ID")}/explain`, { body: rerun ? { rerun } : {} });
449
+ },
401
450
  /**
402
451
  * Waits until an asset's `classification.moderation.status` is no longer `pending` (`allowed`,
403
452
  * `limited`, `age-restricted`, `blocked` or `purged`), or its `classification.status` is `failed`, and returns that asset, checking every few seconds. Rejects with `sdk/timeout` if there is no
404
453
  * decision within `timeoutMs` (default 60000). Webhooks report decisions without polling.
405
454
  */
406
- waitForDecision: async ({ assetId, ...options }) => {
455
+ waitForDecision: async (waitOptions) => {
456
+ const { assetId, ...options } = checked("assets.waitForDecision", waitOptions);
407
457
  requireId(assetId, "Asset ID");
408
458
  const client = options.signal ? this.withRequestOptions({ signal: options.signal }) : this;
409
459
  return pollForDecision(() => client.assets.retrieve({ assetId }), options, this.#connection.sleep, this.#connection.hooks?.now);
@@ -413,9 +463,13 @@ sign: async (options) => {
413
463
  * keeping the asset record, metadata and classification results. The returned asset has
414
464
  * `content.status` set to `removed` and `content.removalReason` to `requested`; the CDN no longer serves it.
415
465
  */
416
- deleteContent: async ({ assetId }) => this.request("DELETE", `/assets/${requireId(assetId, "Asset ID")}/content`),
466
+ deleteContent: async (options) => {
467
+ const { assetId } = checked("assets.deleteContent", options);
468
+ return this.request("DELETE", `/assets/${requireId(assetId, "Asset ID")}/content`);
469
+ },
417
470
  /** Deletes an asset record together with its stored content. */
418
- delete: async ({ assetId }) => {
471
+ delete: async (options) => {
472
+ const { assetId } = checked("assets.delete", options);
419
473
  await this.request("DELETE", `/assets/${requireId(assetId, "Asset ID")}`);
420
474
  },
421
475
  /**
@@ -426,7 +480,8 @@ sign: async (options) => {
426
480
  * `asset.deleted` or `asset.content-removed` for each asset. Assets under a safety hold
427
481
  * are skipped. Not retried: it carries no `Idempotency-Key`.
428
482
  */
429
- batch: async ({ assetIds, operation }) => {
483
+ batch: async (options) => {
484
+ const { assetIds, operation } = checked("assets.batch", options);
430
485
  validateBatchAssetsOptions({
431
486
  assetIds,
432
487
  operation
@@ -445,13 +500,13 @@ sign: async (options) => {
445
500
  * for "now", then poll with each response's `nextCursor`. Webhook deliveries carry the same
446
501
  * events reshaped as `{ id, type, createdAt, projectId, data }`.
447
502
  */
448
- list: async (options = {}) => this.request("GET", `${this.projectPath}/events`, { query: { ...options } }),
503
+ list: async (options = {}) => this.request("GET", `${this.projectPath}/events`, { query: { ...checked("events.list", options) } }),
449
504
  /**
450
505
  * Yields pages of events after `cursor` until no more are waiting. Save each page's
451
506
  * `nextCursor` to resume later. Without `cursor`, yields one empty page whose `nextCursor`
452
507
  * is "now".
453
508
  */
454
- pages: (options = {}) => this.iterateEventPages(options)
509
+ pages: (options = {}) => this.iterateEventPages(checked("events.pages", options))
455
510
  };
456
511
  }
457
512
  async *iterateEventPages(options) {
@@ -486,17 +541,27 @@ sign: async (options) => {
486
541
  * Lists one page of child folders, sorted by name unless `ordering` says otherwise. Pass
487
542
  * `nextCursor` as `cursor` for the next page; fetch a branch when it is opened.
488
543
  */
489
- list: async (options = {}) => this.request("GET", `${this.projectPath}/folders`, { query: options }),
490
- retrieve: async ({ folderId }) => this.request("GET", `/folders/${requireId(folderId, "Folder ID")}`),
544
+ list: async (options = {}) => this.request("GET", `${this.projectPath}/folders`, { query: checked("folders.list", options) }),
545
+ retrieve: async (options) => {
546
+ const { folderId } = checked("folders.retrieve", options);
547
+ return this.request("GET", `/folders/${requireId(folderId, "Folder ID")}`);
548
+ },
491
549
  /** Creates a folder at the project root or inside `parentId`. */
492
- create: async (options) => this.request("POST", `${this.projectPath}/folders`, { body: options }),
493
- update: async ({ folderId, ...body }) => this.request("PATCH", `/folders/${requireId(folderId, "Folder ID")}`, { body }),
550
+ create: async (options) => this.request("POST", `${this.projectPath}/folders`, { body: checked("folders.create", options) }),
551
+ update: async (options) => {
552
+ const { folderId, ...body } = checked("folders.update", options);
553
+ return this.request("PATCH", `/folders/${requireId(folderId, "Folder ID")}`, { body });
554
+ },
494
555
  /** Deletes an empty folder; throws `folder/not-empty` otherwise. */
495
- delete: async ({ folderId }) => {
556
+ delete: async (options) => {
557
+ const { folderId } = checked("folders.delete", options);
496
558
  await this.request("DELETE", `/folders/${requireId(folderId, "Folder ID")}`);
497
559
  },
498
560
  /** Moves a folder under `parentId`, or to the project root with `parentId: null`. */
499
- move: async ({ folderId, parentId }) => this.request("POST", `/folders/${requireId(folderId, "Folder ID")}/move`, { body: { parentId } })
561
+ move: async (options) => {
562
+ const { folderId, parentId } = checked("folders.move", options);
563
+ return this.request("POST", `/folders/${requireId(folderId, "Folder ID")}/move`, { body: { parentId } });
564
+ }
500
565
  };
501
566
  }
502
567
  /**
@@ -506,29 +571,80 @@ sign: async (options) => {
506
571
  get hashLists() {
507
572
  return {
508
573
  /** Lists one page of the project's hash lists, newest first. */
509
- list: async (options = {}) => this.request("GET", `${this.projectPath}/hash-lists`, { query: options }),
510
- retrieve: async ({ hashListId }) => this.request("GET", `/hash-lists/${requireId(hashListId, "Hash list ID")}`),
511
- create: async (options) => this.request("POST", `${this.projectPath}/hash-lists`, { body: options }),
574
+ list: async (options = {}) => this.request("GET", `${this.projectPath}/hash-lists`, { query: checked("hashLists.list", options) }),
575
+ retrieve: async (options) => {
576
+ const { hashListId } = checked("hashLists.retrieve", options);
577
+ return this.request("GET", `/hash-lists/${requireId(hashListId, "Hash list ID")}`);
578
+ },
579
+ create: async (options) => this.request("POST", `${this.projectPath}/hash-lists`, { body: checked("hashLists.create", options) }),
512
580
  /** Renames a list or changes its action; the new action applies to later uploads. */
513
- update: async ({ hashListId, ...body }) => this.request("PATCH", `/hash-lists/${requireId(hashListId, "Hash list ID")}`, { body }),
581
+ update: async (options) => {
582
+ const { hashListId, ...body } = checked("hashLists.update", options);
583
+ return this.request("PATCH", `/hash-lists/${requireId(hashListId, "Hash list ID")}`, { body });
584
+ },
514
585
  /** Deletes the list and every entry in it. */
515
- delete: async ({ hashListId }) => {
586
+ delete: async (options) => {
587
+ const { hashListId } = checked("hashLists.delete", options);
516
588
  await this.request("DELETE", `/hash-lists/${requireId(hashListId, "Hash list ID")}`);
517
589
  },
518
590
  /** Lists one page of a list's entries, newest first. */
519
- listEntries: async ({ hashListId, ...query }) => this.request("GET", `/hash-lists/${requireId(hashListId, "Hash list ID")}/entries`, { query }),
591
+ listEntries: async (options) => {
592
+ const { hashListId, ...query } = checked("hashLists.listEntries", options);
593
+ return this.request("GET", `/hash-lists/${requireId(hashListId, "Hash list ID")}/entries`, { query });
594
+ },
520
595
  /** Adds a hash, or an image asset's hash; a hash already in the list returns its entry. */
521
- addEntry: async ({ hashListId, ...body }) => this.request("POST", `/hash-lists/${requireId(hashListId, "Hash list ID")}/entries`, { body }),
522
- removeEntry: async ({ entryId }) => {
596
+ addEntry: async (options) => {
597
+ const { hashListId, ...body } = checked("hashLists.addEntry", options);
598
+ return this.request("POST", `/hash-lists/${requireId(hashListId, "Hash list ID")}/entries`, { body });
599
+ },
600
+ removeEntry: async (options) => {
601
+ const { entryId } = checked("hashLists.removeEntry", options);
523
602
  await this.request("DELETE", `/hash-list-entries/${requireId(entryId, "Hash list entry ID")}`);
524
603
  }
525
604
  };
526
605
  }
527
606
  /**
607
+ * Moderation policies belong to the project's organisation and its projects share them. Every
608
+ * change sends the policy's `revision`, so a policy changed since is refused. Through a
609
+ * project's key you can change only policies no other project uses or owns.
610
+ */
611
+ get policies() {
612
+ const policyPath = (policyId) => `${this.projectPath}/policies/${requireId(policyId, "Policy ID")}`;
613
+ return {
614
+ /** Lists the organisation's policies and the ID of the one the project uses. */
615
+ list: async () => this.request("GET", `${this.projectPath}/policies`),
616
+ retrieve: async (options) => this.request("GET", policyPath(checked("policies.retrieve", options).policyId)),
617
+ /** Creates a policy from `settings`, or a copy of a built-in preset with `presetId`. */
618
+ create: async (options) => this.request("POST", `${this.projectPath}/policies`, { body: checked("policies.create", options) }),
619
+ /** Changes the name, description or settings; later moderation uses them. */
620
+ update: async (options) => {
621
+ const { policyId, ...body } = checked("policies.update", options);
622
+ return this.request("PATCH", policyPath(policyId), { body });
623
+ },
624
+ /** Resets a preset copy to its pinned version, or updates an unchanged copy to the latest. */
625
+ applyPreset: async (options) => {
626
+ const { policyId, ...body } = checked("policies.applyPreset", options);
627
+ return this.request("POST", `${policyPath(policyId)}/preset`, { body });
628
+ },
629
+ /** Switches automatic updates on or off for the organisation's own preset policy. */
630
+ setAutomaticUpdates: async (options) => {
631
+ const { policyId, ...body } = checked("policies.setAutomaticUpdates", options);
632
+ return this.request("PUT", `${policyPath(policyId)}/automatic-updates`, { body });
633
+ },
634
+ /** Deletes a policy that no project or upload preset uses. */
635
+ delete: async (options) => {
636
+ await this.request("DELETE", policyPath(checked("policies.delete", options).policyId));
637
+ },
638
+ /** Chooses the policy the project moderates with. */
639
+ assign: async (options) => this.request("PUT", `${this.projectPath}/policy`, { body: checked("policies.assign", options) })
640
+ };
641
+ }
642
+ /**
528
643
  * Create a named lens at any positive version, or update it with a greater version.
529
644
  * Supplying the same definition and version is idempotent.
530
645
  */
531
646
  async ensureLens(options) {
647
+ checked("ensureLens", options);
532
648
  if (!options?.identifier) throw invalidArgument("Lens identifier is required");
533
649
  const [lens] = await this.ensureLenses({ lenses: [options] });
534
650
  return lens;
@@ -538,9 +654,11 @@ sign: async (options) => {
538
654
  * consecutive requests of at most {@link ENSURE_LENSES_MAX_PER_REQUEST} definitions, in order.
539
655
  * Each lens follows the same versioning and idempotency rules as ensureLens().
540
656
  */
541
- async ensureLenses({ lenses }) {
657
+ async ensureLenses(options) {
658
+ const { lenses } = checked("ensureLenses", options);
542
659
  if (!Array.isArray(lenses) || lenses.length === 0) throw invalidArgument("At least one lens is required");
543
660
  if (lenses.some((option) => !option?.identifier)) throw invalidArgument("Lens identifier is required");
661
+ for (const lens of lenses) checked("ensureLens", lens);
544
662
  const { ensuredLenses, pendingEnsureLenses } = this.#lenses;
545
663
  const missingOptions = [];
546
664
  const missingKeys = /* @__PURE__ */ new Set();