@calmlens/sdk 0.5.0 → 0.6.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.
package/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_CalmLensUtils = require("./CalmLensUtils-0QaxbI3A.js");
2
+ const require_CalmLensUtils = require("./CalmLensUtils-DA1_j5-P.js");
3
3
  let zod = require("zod");
4
4
  zod = require_CalmLensUtils.__toESM(zod);
5
5
  require("zod/v4");
@@ -203,7 +203,8 @@ zod.object({
203
203
  source: zod.enum([
204
204
  "frame",
205
205
  "speech",
206
- "frame-text"
206
+ "frame-text",
207
+ "clip"
207
208
  ]),
208
209
  startSeconds: zod.number().nonnegative(),
209
210
  endSeconds: zod.number().nonnegative(),
@@ -247,6 +248,24 @@ const WEBHOOK_TIMESTAMP_HEADER = "x-calmlens-timestamp";
247
248
  const WEBHOOK_SIGNATURE_HEADER = "x-calmlens-signature";
248
249
  /** Deliveries whose timestamp is further than this from the receiver's clock are rejected. */
249
250
  const WEBHOOK_SIGNATURE_TOLERANCE_SECONDS = 300;
251
+ /** The JSON body of a webhook delivery for a stored event. */
252
+ const toWebhookEventPayload = (event) => {
253
+ var _event$description, _event$assetId, _event$asset;
254
+ return {
255
+ id: event.id,
256
+ type: event.type,
257
+ createdAt: event.createdAt,
258
+ projectId: event.projectId,
259
+ data: {
260
+ severity: event.severity,
261
+ title: event.title,
262
+ description: (_event$description = event.description) !== null && _event$description !== void 0 ? _event$description : null,
263
+ assetId: (_event$assetId = event.assetId) !== null && _event$assetId !== void 0 ? _event$assetId : null,
264
+ asset: (_event$asset = event.asset) !== null && _event$asset !== void 0 ? _event$asset : null,
265
+ facts: event.facts
266
+ }
267
+ };
268
+ };
250
269
  const encoder = new TextEncoder();
251
270
  const hmacSha256Hex = function() {
252
271
  var _ref = require_CalmLensUtils._asyncToGenerator(function* (secret, message) {
@@ -277,7 +296,8 @@ const createWebhookSignatureHeader = function() {
277
296
  return _ref2.apply(this, arguments);
278
297
  };
279
298
  }();
280
- (function() {
299
+ /** Headers for one signed delivery of `body`. */
300
+ const createWebhookHeaders = function() {
281
301
  var _ref3 = require_CalmLensUtils._asyncToGenerator(function* (options) {
282
302
  var _options$timestampSec;
283
303
  const timestamp = (_options$timestampSec = options.timestampSeconds) !== null && _options$timestampSec !== void 0 ? _options$timestampSec : Math.floor(Date.now() / 1e3);
@@ -291,7 +311,7 @@ const createWebhookSignatureHeader = function() {
291
311
  return function createWebhookHeaders(_x6) {
292
312
  return _ref3.apply(this, arguments);
293
313
  };
294
- })();
314
+ }();
295
315
  /**
296
316
  * Verifies a webhook delivery: `x-calmlens-signature` must contain a `v1=` HMAC-SHA256 of
297
317
  * `"<x-calmlens-timestamp>.<raw body>"`, and the timestamp must be within `toleranceSeconds`
@@ -440,16 +460,42 @@ const requestSignal = (options, signal) => {
440
460
  ].filter((value) => value != null);
441
461
  return AbortSignal.any(signals);
442
462
  };
443
- const safeFetch = (fetchImpl, options) => function() {
444
- var _ref = require_CalmLensUtils._asyncToGenerator(function* (input, init) {
463
+ /** Copies a fully read body into a new Response, so later JSON parsing cannot hit the network. */
464
+ const toBufferedResponse = function() {
465
+ var _ref = require_CalmLensUtils._asyncToGenerator(function* (response) {
466
+ const body = response.status === 204 || response.status === 304 ? null : yield response.arrayBuffer();
467
+ const headers = new Headers(response.headers);
468
+ headers.delete("content-encoding");
469
+ headers.delete("content-length");
470
+ const buffered = new Response(body, {
471
+ status: response.status,
472
+ statusText: response.statusText,
473
+ headers
474
+ });
475
+ Object.defineProperty(buffered, "url", { value: response.url });
476
+ return buffered;
477
+ });
478
+ return function toBufferedResponse(_x) {
479
+ return _ref.apply(this, arguments);
480
+ };
481
+ }();
482
+ /**
483
+ * Wraps fetch with the client's deadline, cancellation and redirect policy. Every failure,
484
+ * including body reads, decompression and truncated bodies when `bufferBody` is set, becomes a
485
+ * `CalmLensError` (`sdk/transport-error`, `sdk/timeout` or `sdk/cancelled`) with the original
486
+ * error as its `cause`.
487
+ */
488
+ const safeFetch = (fetchImpl, options, { bufferBody }) => function() {
489
+ var _ref2 = require_CalmLensUtils._asyncToGenerator(function* (input, init) {
445
490
  var _init$signal;
446
491
  const signal = requestSignal(options, (_init$signal = init === null || init === void 0 ? void 0 : init.signal) !== null && _init$signal !== void 0 ? _init$signal : input instanceof Request ? input.signal : void 0);
447
492
  try {
448
493
  signal.throwIfAborted();
449
- return yield fetchImpl(input, require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, init), {}, {
494
+ const response = yield fetchImpl(input, require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, init), {}, {
450
495
  redirect: "error",
451
496
  signal
452
497
  }));
498
+ return bufferBody ? yield toBufferedResponse(response) : response;
453
499
  } catch (cause) {
454
500
  var _signal$reason;
455
501
  throw require_CalmLensUtils.calmLensError({ id: signal.aborted ? ((_signal$reason = signal.reason) === null || _signal$reason === void 0 ? void 0 : _signal$reason.name) === "TimeoutError" ? "sdk/timeout" : "sdk/cancelled" : "sdk/transport-error" }, {
@@ -458,8 +504,8 @@ const safeFetch = (fetchImpl, options) => function() {
458
504
  });
459
505
  }
460
506
  });
461
- return function(_x, _x2) {
462
- return _ref.apply(this, arguments);
507
+ return function(_x2, _x3) {
508
+ return _ref2.apply(this, arguments);
463
509
  };
464
510
  }();
465
511
  const createApi = (options) => {
@@ -475,7 +521,7 @@ const createApi = (options) => {
475
521
  if (context.error) throw normalizeApiError(context.error);
476
522
  } }
477
523
  ],
478
- requestBackend: options.requestBackend ? Object.assign(Object.create(options.requestBackend), "fetch" in options.requestBackend && typeof options.requestBackend.fetch === "function" ? { fetch: safeFetch(options.requestBackend.fetch, options) } : {}) : new api_def.FetchRequestBackend(safeFetch(globalThis.fetch, options))
524
+ requestBackend: options.requestBackend ? Object.assign(Object.create(options.requestBackend), "fetch" in options.requestBackend && typeof options.requestBackend.fetch === "function" ? { fetch: safeFetch(options.requestBackend.fetch, options, { bufferBody: true }) } : {}) : new api_def.FetchRequestBackend(safeFetch(globalThis.fetch, options, { bufferBody: true }))
479
525
  });
480
526
  };
481
527
  const isApiErrorPayload = (value) => {
@@ -669,9 +715,7 @@ var CalmLensClient = class CalmLensClient {
669
715
  this.pendingEnsureLenses = /* @__PURE__ */ new Map();
670
716
  this.multipartImageUploadSizes = /* @__PURE__ */ new Map();
671
717
  this.multipartUploadQueues = /* @__PURE__ */ new Map();
672
- if (!options.apiKey) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "API key is required" });
673
- if (!options.projectId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Project ID is required" });
674
- if (options.timeoutMs !== void 0 && (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs <= 0)) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "timeoutMs must be a positive integer" });
718
+ require_CalmLensUtils.validateClientOptions(options);
675
719
  this.options = require_CalmLensUtils._objectSpread2({}, options);
676
720
  this.options.baseUrl = (_this$options$baseUrl = this.options.baseUrl) !== null && _this$options$baseUrl !== void 0 ? _this$options$baseUrl : `https://api.${require_CalmLensUtils.DOMAIN}/v1`;
677
721
  this.options.cdnBaseUrl = (_this$options$cdnBase = this.options.cdnBaseUrl) !== null && _this$options$cdnBase !== void 0 ? _this$options$cdnBase : `https://cdn.${require_CalmLensUtils.DOMAIN}/v1`;
@@ -686,11 +730,11 @@ var CalmLensClient = class CalmLensClient {
686
730
  return client;
687
731
  }
688
732
  getUploadFetch() {
689
- var _this$options$request, _ref2, _this$options$uploadF;
733
+ var _this$options$request, _ref3, _this$options$uploadF;
690
734
  const requestBackendFetch = (_this$options$request = this.options.requestBackend) === null || _this$options$request === void 0 ? void 0 : _this$options$request.fetch;
691
- const fetchImpl = (_ref2 = (_this$options$uploadF = this.options.uploadFetch) !== null && _this$options$uploadF !== void 0 ? _this$options$uploadF : requestBackendFetch) !== null && _ref2 !== void 0 ? _ref2 : globalThis.fetch;
735
+ const fetchImpl = (_ref3 = (_this$options$uploadF = this.options.uploadFetch) !== null && _this$options$uploadF !== void 0 ? _this$options$uploadF : requestBackendFetch) !== null && _ref3 !== void 0 ? _ref3 : globalThis.fetch;
692
736
  if (!fetchImpl) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.SDK_ERRORS.NO_CDN_FETCH);
693
- return safeFetch(fetchImpl, this.options);
737
+ return safeFetch(fetchImpl, this.options, { bufferBody: true });
694
738
  }
695
739
  submitRawAssetUpload(options, queue) {
696
740
  var _this = this;
@@ -779,7 +823,7 @@ var CalmLensClient = class CalmLensClient {
779
823
  try {
780
824
  data = yield response.json();
781
825
  } catch (cause) {
782
- throw require_CalmLensUtils.calmLensError({ id: cause instanceof Error && ["TimeoutError", "AbortError"].includes(cause.name) ? cause.name === "TimeoutError" ? "sdk/timeout" : "sdk/cancelled" : response.ok ? "sdk/invalid-response" : "sdk/http-error" }, {
826
+ throw require_CalmLensUtils.calmLensError({ id: response.ok ? "sdk/invalid-response" : "sdk/http-error" }, {
783
827
  message: `Invalid JSON response (HTTP ${response.status})`,
784
828
  status: response.status,
785
829
  cause
@@ -822,9 +866,9 @@ var CalmLensClient = class CalmLensClient {
822
866
  * Create a CDN URL for asset content or previews.
823
867
  * Private assets require an authenticated request or signed URL.
824
868
  */
825
- getAssetUrl: (_ref3) => {
869
+ getAssetUrl: (_ref4) => {
826
870
  var _options$resource;
827
- let { assetIdentifier } = _ref3, options = require_CalmLensUtils._objectWithoutProperties(_ref3, _excluded3);
871
+ let { assetIdentifier } = _ref4, options = require_CalmLensUtils._objectWithoutProperties(_ref4, _excluded3);
828
872
  if (!assetIdentifier) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset identifier is required" });
829
873
  const resource = (_options$resource = options.resource) !== null && _options$resource !== void 0 ? _options$resource : "content";
830
874
  const url = `${this.options.cdnBaseUrl.replace(/\/$/, "")}/assets/${encodeURIComponent(this.options.projectId)}/${encodeURIComponent(assetIdentifier)}/${resource}`;
@@ -835,15 +879,15 @@ var CalmLensClient = class CalmLensClient {
835
879
  * Private assets are authenticated with the client's API key.
836
880
  */
837
881
  serve: function() {
838
- var _ref5 = require_CalmLensUtils._asyncToGenerator(function* (_ref4) {
882
+ var _ref6 = require_CalmLensUtils._asyncToGenerator(function* (_ref5) {
839
883
  var _this$options$cdnFetc;
840
- let { assetIdentifier, init } = _ref4, urlOptions = require_CalmLensUtils._objectWithoutProperties(_ref4, _excluded4);
884
+ let { assetIdentifier, init } = _ref5, urlOptions = require_CalmLensUtils._objectWithoutProperties(_ref5, _excluded4);
841
885
  const fetchImpl = (_this$options$cdnFetc = _this3.options.cdnFetch) !== null && _this$options$cdnFetc !== void 0 ? _this$options$cdnFetc : globalThis.fetch;
842
886
  if (!fetchImpl) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.SDK_ERRORS.NO_CDN_FETCH);
843
- return safeFetch(fetchImpl, _this3.options)(_this3.cdn.getAssetUrl(require_CalmLensUtils._objectSpread2({ assetIdentifier }, urlOptions)), withApiKeyHeader(init, _this3.options.apiKey));
887
+ return safeFetch(fetchImpl, _this3.options, { bufferBody: false })(_this3.cdn.getAssetUrl(require_CalmLensUtils._objectSpread2({ assetIdentifier }, urlOptions)), withApiKeyHeader(init, _this3.options.apiKey));
844
888
  });
845
- return function serve(_x3) {
846
- return _ref5.apply(this, arguments);
889
+ return function serve(_x4) {
890
+ return _ref6.apply(this, arguments);
847
891
  };
848
892
  }()
849
893
  };
@@ -851,11 +895,11 @@ var CalmLensClient = class CalmLensClient {
851
895
  get text() {
852
896
  var _this4 = this;
853
897
  return { moderate: function() {
854
- var _ref6 = require_CalmLensUtils._asyncToGenerator(function* (options) {
898
+ var _ref7 = require_CalmLensUtils._asyncToGenerator(function* (options) {
855
899
  return _this4.assets.moderate(require_CalmLensUtils.toTextAssetOptions(options));
856
900
  });
857
- return function moderate(_x4) {
858
- return _ref6.apply(this, arguments);
901
+ return function moderate(_x5) {
902
+ return _ref7.apply(this, arguments);
859
903
  };
860
904
  }() };
861
905
  }
@@ -868,15 +912,15 @@ var CalmLensClient = class CalmLensClient {
868
912
  * @returns Promise with paginated assets
869
913
  */
870
914
  list: function() {
871
- var _ref7 = require_CalmLensUtils._asyncToGenerator(function* (options) {
915
+ var _ref8 = require_CalmLensUtils._asyncToGenerator(function* (options) {
872
916
  var _options$pageIndex;
873
917
  return (yield _this5.endpoints.getAssetsPage.submit({
874
918
  params: { projectId: _this5.options.projectId },
875
919
  query: require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, options), {}, { pageIndex: (_options$pageIndex = options.pageIndex) !== null && _options$pageIndex !== void 0 ? _options$pageIndex : 0 })
876
920
  })).data;
877
921
  });
878
- return function list(_x5) {
879
- return _ref7.apply(this, arguments);
922
+ return function list(_x6) {
923
+ return _ref8.apply(this, arguments);
880
924
  };
881
925
  }(),
882
926
  /**
@@ -885,25 +929,25 @@ var CalmLensClient = class CalmLensClient {
885
929
  * @returns Promise with asset data
886
930
  */
887
931
  retrieve: function() {
888
- var _ref8 = require_CalmLensUtils._asyncToGenerator(function* ({ assetId }) {
932
+ var _ref9 = require_CalmLensUtils._asyncToGenerator(function* ({ assetId }) {
889
933
  if (!assetId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
890
934
  return (yield _this5.endpoints.getAsset.submit({ params: { assetId } })).data;
891
935
  });
892
- return function retrieve(_x6) {
893
- return _ref8.apply(this, arguments);
936
+ return function retrieve(_x7) {
937
+ return _ref9.apply(this, arguments);
894
938
  };
895
939
  }(),
896
940
  update: function() {
897
- var _ref10 = require_CalmLensUtils._asyncToGenerator(function* (_ref9) {
898
- let { assetId } = _ref9, body = require_CalmLensUtils._objectWithoutProperties(_ref9, _excluded5);
941
+ var _ref11 = require_CalmLensUtils._asyncToGenerator(function* (_ref10) {
942
+ let { assetId } = _ref10, body = require_CalmLensUtils._objectWithoutProperties(_ref10, _excluded5);
899
943
  if (!assetId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
900
944
  return (yield _this5.endpoints.patchAsset.submit({
901
945
  params: { assetId },
902
946
  body
903
947
  })).data;
904
948
  });
905
- return function update(_x7) {
906
- return _ref10.apply(this, arguments);
949
+ return function update(_x8) {
950
+ return _ref11.apply(this, arguments);
907
951
  };
908
952
  }(),
909
953
  /**
@@ -913,17 +957,17 @@ var CalmLensClient = class CalmLensClient {
913
957
  * @returns Promise with paginated child assets
914
958
  */
915
959
  listChildren: function() {
916
- var _ref12 = require_CalmLensUtils._asyncToGenerator(function* (_ref11) {
960
+ var _ref13 = require_CalmLensUtils._asyncToGenerator(function* (_ref12) {
917
961
  var _options$pageIndex2;
918
- let { assetId } = _ref11, options = require_CalmLensUtils._objectWithoutProperties(_ref11, _excluded6);
962
+ let { assetId } = _ref12, options = require_CalmLensUtils._objectWithoutProperties(_ref12, _excluded6);
919
963
  if (!assetId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
920
964
  return (yield _this5.endpoints.getAssetChildren.submit({
921
965
  params: { assetId },
922
966
  query: require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, options), {}, { pageIndex: (_options$pageIndex2 = options.pageIndex) !== null && _options$pageIndex2 !== void 0 ? _options$pageIndex2 : 0 })
923
967
  })).data;
924
968
  });
925
- return function listChildren(_x8) {
926
- return _ref12.apply(this, arguments);
969
+ return function listChildren(_x9) {
970
+ return _ref13.apply(this, arguments);
927
971
  };
928
972
  }(),
929
973
  /**
@@ -933,7 +977,7 @@ var CalmLensClient = class CalmLensClient {
933
977
  * @returns Promise with created asset
934
978
  */
935
979
  create: function() {
936
- var _ref13 = require_CalmLensUtils._asyncToGenerator(function* (options) {
980
+ var _ref14 = require_CalmLensUtils._asyncToGenerator(function* (options) {
937
981
  const body = prepareSubmitAssetOptions(options);
938
982
  if ("content" in body || "part" in body) return yield _this5.submitRawAssetUpload(body, true);
939
983
  return (yield _this5.endpoints.postUploadAsset.submit({
@@ -942,8 +986,8 @@ var CalmLensClient = class CalmLensClient {
942
986
  query: { queue: true }
943
987
  })).data;
944
988
  });
945
- return function create(_x9) {
946
- return _ref13.apply(this, arguments);
989
+ return function create(_x10) {
990
+ return _ref14.apply(this, arguments);
947
991
  };
948
992
  }(),
949
993
  /**
@@ -954,7 +998,7 @@ var CalmLensClient = class CalmLensClient {
954
998
  * @returns Promise with created and analyzed asset
955
999
  */
956
1000
  moderate: function() {
957
- var _ref14 = require_CalmLensUtils._asyncToGenerator(function* (options) {
1001
+ var _ref15 = require_CalmLensUtils._asyncToGenerator(function* (options) {
958
1002
  if ("content" in options && "plainText" in options.content && (typeof options.content.plainText !== "string" || !options.content.plainText.trim())) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Text to moderate must be a non-empty string" });
959
1003
  const body = prepareSubmitAssetOptions(options);
960
1004
  if ("content" in body || "part" in body) return yield _this5.submitRawAssetUpload(body, false);
@@ -964,8 +1008,8 @@ var CalmLensClient = class CalmLensClient {
964
1008
  query: { queue: false }
965
1009
  })).data;
966
1010
  });
967
- return function moderate(_x10) {
968
- return _ref14.apply(this, arguments);
1011
+ return function moderate(_x11) {
1012
+ return _ref15.apply(this, arguments);
969
1013
  };
970
1014
  }(),
971
1015
  /**
@@ -975,7 +1019,7 @@ var CalmLensClient = class CalmLensClient {
975
1019
  * @returns Promise with asset data
976
1020
  */
977
1021
  uploadPart: function() {
978
- var _ref15 = require_CalmLensUtils._asyncToGenerator(function* ({ assetId, part }) {
1022
+ var _ref16 = require_CalmLensUtils._asyncToGenerator(function* ({ assetId, part }) {
979
1023
  var _part$sizeInBytes3, _this$multipartUpload;
980
1024
  if (!assetId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
981
1025
  if (!part) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Part options are required" });
@@ -993,8 +1037,8 @@ var CalmLensClient = class CalmLensClient {
993
1037
  }
994
1038
  return yield _this5.submitRawAssetPart(assetId, part, (_this$multipartUpload = _this5.multipartUploadQueues.get(assetId)) !== null && _this$multipartUpload !== void 0 ? _this$multipartUpload : false);
995
1039
  });
996
- return function uploadPart(_x11) {
997
- return _ref15.apply(this, arguments);
1040
+ return function uploadPart(_x12) {
1041
+ return _ref16.apply(this, arguments);
998
1042
  };
999
1043
  }(),
1000
1044
  /**
@@ -1003,9 +1047,9 @@ var CalmLensClient = class CalmLensClient {
1003
1047
  * auth cookies or API keys to the CDN on every media request.
1004
1048
  */
1005
1049
  createSignedUrl: function() {
1006
- var _ref17 = require_CalmLensUtils._asyncToGenerator(function* (_ref16) {
1050
+ var _ref18 = require_CalmLensUtils._asyncToGenerator(function* (_ref17) {
1007
1051
  var _options$resource2, _options$expiresInSec;
1008
- let { assetId } = _ref16, options = require_CalmLensUtils._objectWithoutProperties(_ref16, _excluded7);
1052
+ let { assetId } = _ref17, options = require_CalmLensUtils._objectWithoutProperties(_ref17, _excluded7);
1009
1053
  if (!assetId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
1010
1054
  if (options.lens && options.transform) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Specify either a lens or a transform, not both" });
1011
1055
  return (yield _this5.endpoints.postAssetSignedUrl.submit({
@@ -1018,20 +1062,20 @@ var CalmLensClient = class CalmLensClient {
1018
1062
  params: { assetId }
1019
1063
  })).data;
1020
1064
  });
1021
- return function createSignedUrl(_x12) {
1022
- return _ref17.apply(this, arguments);
1065
+ return function createSignedUrl(_x13) {
1066
+ return _ref18.apply(this, arguments);
1023
1067
  };
1024
1068
  }(),
1025
1069
  move: function() {
1026
- var _ref18 = require_CalmLensUtils._asyncToGenerator(function* ({ assetId, folderId }) {
1070
+ var _ref19 = require_CalmLensUtils._asyncToGenerator(function* ({ assetId, folderId }) {
1027
1071
  if (!assetId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
1028
1072
  return (yield _this5.endpoints.moveAsset.submit({
1029
1073
  params: { assetId },
1030
1074
  body: { folderId }
1031
1075
  })).data;
1032
1076
  });
1033
- return function move(_x13) {
1034
- return _ref18.apply(this, arguments);
1077
+ return function move(_x14) {
1078
+ return _ref19.apply(this, arguments);
1035
1079
  };
1036
1080
  }(),
1037
1081
  /**
@@ -1039,12 +1083,12 @@ var CalmLensClient = class CalmLensClient {
1039
1083
  * moderated like a new upload; its content must still be stored.
1040
1084
  */
1041
1085
  retry: function() {
1042
- var _ref19 = require_CalmLensUtils._asyncToGenerator(function* ({ assetId }) {
1086
+ var _ref20 = require_CalmLensUtils._asyncToGenerator(function* ({ assetId }) {
1043
1087
  if (!assetId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
1044
1088
  return (yield _this5.endpoints.retryAsset.submit({ params: { assetId } })).data;
1045
1089
  });
1046
- return function retry(_x14) {
1047
- return _ref19.apply(this, arguments);
1090
+ return function retry(_x15) {
1091
+ return _ref20.apply(this, arguments);
1048
1092
  };
1049
1093
  }()
1050
1094
  };
@@ -1058,14 +1102,14 @@ var CalmLensClient = class CalmLensClient {
1058
1102
  * reshaped as `{ id, type, createdAt, projectId, data }`.
1059
1103
  */
1060
1104
  list: function() {
1061
- var _ref20 = require_CalmLensUtils._asyncToGenerator(function* (options = {}) {
1105
+ var _ref21 = require_CalmLensUtils._asyncToGenerator(function* (options = {}) {
1062
1106
  return (yield _this6.endpoints.getEvents.submit({
1063
1107
  params: { projectId: _this6.options.projectId },
1064
1108
  query: options
1065
1109
  })).data;
1066
1110
  });
1067
1111
  return function list() {
1068
- return _ref20.apply(this, arguments);
1112
+ return _ref21.apply(this, arguments);
1069
1113
  };
1070
1114
  }() };
1071
1115
  }
@@ -1073,65 +1117,65 @@ list: function() {
1073
1117
  var _this7 = this;
1074
1118
  return {
1075
1119
  list: function() {
1076
- var _ref21 = require_CalmLensUtils._asyncToGenerator(function* () {
1120
+ var _ref22 = require_CalmLensUtils._asyncToGenerator(function* () {
1077
1121
  return (yield _this7.endpoints.getFolders.submit({ params: { projectId: _this7.options.projectId } })).data.folders;
1078
1122
  });
1079
1123
  return function list() {
1080
- return _ref21.apply(this, arguments);
1124
+ return _ref22.apply(this, arguments);
1081
1125
  };
1082
1126
  }(),
1083
1127
  retrieve: function() {
1084
- var _ref22 = require_CalmLensUtils._asyncToGenerator(function* ({ folderId }) {
1128
+ var _ref23 = require_CalmLensUtils._asyncToGenerator(function* ({ folderId }) {
1085
1129
  if (!folderId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
1086
1130
  return (yield _this7.endpoints.getFolder.submit({ params: { folderId } })).data;
1087
1131
  });
1088
- return function retrieve(_x15) {
1089
- return _ref22.apply(this, arguments);
1132
+ return function retrieve(_x16) {
1133
+ return _ref23.apply(this, arguments);
1090
1134
  };
1091
1135
  }(),
1092
1136
  create: function() {
1093
- var _ref23 = require_CalmLensUtils._asyncToGenerator(function* (options) {
1137
+ var _ref24 = require_CalmLensUtils._asyncToGenerator(function* (options) {
1094
1138
  return (yield _this7.endpoints.postFolder.submit({
1095
1139
  params: { projectId: _this7.options.projectId },
1096
1140
  body: options
1097
1141
  })).data;
1098
1142
  });
1099
- return function create(_x16) {
1100
- return _ref23.apply(this, arguments);
1143
+ return function create(_x17) {
1144
+ return _ref24.apply(this, arguments);
1101
1145
  };
1102
1146
  }(),
1103
1147
  update: function() {
1104
- var _ref25 = require_CalmLensUtils._asyncToGenerator(function* (_ref24) {
1105
- let { folderId } = _ref24, body = require_CalmLensUtils._objectWithoutProperties(_ref24, _excluded8);
1148
+ var _ref26 = require_CalmLensUtils._asyncToGenerator(function* (_ref25) {
1149
+ let { folderId } = _ref25, body = require_CalmLensUtils._objectWithoutProperties(_ref25, _excluded8);
1106
1150
  if (!folderId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
1107
1151
  return (yield _this7.endpoints.patchFolder.submit({
1108
1152
  params: { folderId },
1109
1153
  body
1110
1154
  })).data;
1111
1155
  });
1112
- return function update(_x17) {
1113
- return _ref25.apply(this, arguments);
1156
+ return function update(_x18) {
1157
+ return _ref26.apply(this, arguments);
1114
1158
  };
1115
1159
  }(),
1116
1160
  delete: function() {
1117
- var _ref26 = require_CalmLensUtils._asyncToGenerator(function* ({ folderId }) {
1161
+ var _ref27 = require_CalmLensUtils._asyncToGenerator(function* ({ folderId }) {
1118
1162
  if (!folderId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
1119
1163
  yield _this7.endpoints.deleteFolder.submit({ params: { folderId } });
1120
1164
  });
1121
- return function _delete(_x18) {
1122
- return _ref26.apply(this, arguments);
1165
+ return function _delete(_x19) {
1166
+ return _ref27.apply(this, arguments);
1123
1167
  };
1124
1168
  }(),
1125
1169
  move: function() {
1126
- var _ref27 = require_CalmLensUtils._asyncToGenerator(function* ({ folderId, parentId }) {
1170
+ var _ref28 = require_CalmLensUtils._asyncToGenerator(function* ({ folderId, parentId }) {
1127
1171
  if (!folderId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
1128
1172
  return (yield _this7.endpoints.moveFolder.submit({
1129
1173
  params: { folderId },
1130
1174
  body: { parentId }
1131
1175
  })).data;
1132
1176
  });
1133
- return function move(_x19) {
1134
- return _ref27.apply(this, arguments);
1177
+ return function move(_x20) {
1178
+ return _ref28.apply(this, arguments);
1135
1179
  };
1136
1180
  }()
1137
1181
  };
@@ -1202,5 +1246,7 @@ exports.WEBHOOK_DELIVERY_HEADER = WEBHOOK_DELIVERY_HEADER;
1202
1246
  exports.WEBHOOK_SIGNATURE_HEADER = WEBHOOK_SIGNATURE_HEADER;
1203
1247
  exports.WEBHOOK_SIGNATURE_TOLERANCE_SECONDS = WEBHOOK_SIGNATURE_TOLERANCE_SECONDS;
1204
1248
  exports.WEBHOOK_TIMESTAMP_HEADER = WEBHOOK_TIMESTAMP_HEADER;
1249
+ exports.createWebhookHeaders = createWebhookHeaders;
1205
1250
  exports.generateMediaTestCode = generateMediaTestCode;
1251
+ exports.toWebhookEventPayload = toWebhookEventPayload;
1206
1252
  exports.verifyWebhookSignature = verifyWebhookSignature;
package/cjs/testing.d.ts CHANGED
@@ -1,19 +1,31 @@
1
- import { A as GetEventsResponse, D as GetAssetChildrenResponse, F as Folder, N as AssetBinaryPayloadInput, O as GetAssetResponse, P as Lens, S as SubmitAssetOptions, T as UploadAssetPartOptions, U as Asset, W as AssetStatus, a as CreateAssetSignedUrlOptions, b as RetrieveAssetOptions, c as EnsureLensOptions, d as ListAssetChildrenOptions, f as ListAssetsOptions, g as MoveFolderOptions, h as MoveAssetOptions, i as CdnServeOptions, j as PostAssetSignedUrlResponse, k as GetAssetsPageResponse, l as EnsureLensesOptions, m as ModerateTextOptions, n as CalmLensClientOptions, o as CreateFolderOptions, p as ListEventsOptions, r as CdnAssetUrlOptions, u as FolderIdOptions, w as UpdateFolderOptions, x as RetryAssetOptions } from "./CalmLensTypes-DG_kHVqY.js";
1
+ import { A as GetEventsResponse, C as UpdateAssetOptions, D as GetAssetChildrenResponse, F as Folder, G as AssetStatus, N as AssetBinaryPayloadInput, O as GetAssetResponse, P as Lens, S as SubmitAssetOptions, T as UploadAssetPartOptions, W as Asset, a as CreateAssetSignedUrlOptions, b as RetrieveAssetOptions, c as EnsureLensOptions, d as ListAssetChildrenOptions, f as ListAssetsOptions, g as MoveFolderOptions, h as MoveAssetOptions, i as CdnServeOptions, j as PostAssetSignedUrlResponse, k as GetAssetsPageResponse, l as EnsureLensesOptions, m as ModerateTextOptions, n as CalmLensClientOptions, o as CreateFolderOptions, p as ListEventsOptions, r as CdnAssetUrlOptions, u as FolderIdOptions, w as UpdateFolderOptions, x as RetryAssetOptions } from "./CalmLensTypes-BpmT60j-.js";
2
2
  import * as zod from "zod";
3
3
  //#region ../shared/src/Permissions.d.ts
4
4
  declare const GRANT_SCHEMA: zod.ZodObject<{
5
5
  actions: zod.ZodArray<zod.ZodEnum<{
6
+ "api-keys:read": "api-keys:read";
7
+ "api-keys:write": "api-keys:write";
6
8
  "assets:create": "assets:create";
7
9
  "assets:delete": "assets:delete";
8
10
  "assets:download": "assets:download";
9
11
  "assets:read": "assets:read";
10
12
  "assets:share": "assets:share";
11
13
  "assets:update": "assets:update";
14
+ "connectors:read": "connectors:read";
15
+ "connectors:write": "connectors:write";
12
16
  "folders:create": "folders:create";
13
17
  "folders:delete": "folders:delete";
14
18
  "folders:read": "folders:read";
15
19
  "folders:update": "folders:update";
20
+ "lenses:read": "lenses:read";
21
+ "lenses:write": "lenses:write";
22
+ "members:read": "members:read";
23
+ "members:write": "members:write";
24
+ "metadata:read": "metadata:read";
25
+ "metadata:write": "metadata:write";
16
26
  "project:manage": "project:manage";
27
+ "settings:read": "settings:read";
28
+ "settings:write": "settings:write";
17
29
  }>>;
18
30
  folderId: zod.ZodNullable<zod.ZodString>;
19
31
  includeSubfolders: zod.ZodBoolean;
@@ -92,9 +104,21 @@ interface MockCalmLensClientOptions extends CalmLensClientOptions {
92
104
  queuedStatus?: AssetStatus;
93
105
  analyzedStatus?: AssetStatus;
94
106
  signedUrlBaseUrl?: string;
95
- cdnBaseUrl?: string;
96
107
  };
97
108
  }
109
+ /** A `MockCalmLensClient` method, named like its path on the client. */
110
+ type MockCalmLensOperation = "assets.list" | "assets.retrieve" | "assets.update" | "assets.listChildren" | "assets.create" | "assets.moderate" | "assets.uploadPart" | "assets.createSignedUrl" | "assets.move" | "assets.retry" | "text.moderate" | "cdn.serve" | "events.list" | "folders.list" | "folders.retrieve" | "folders.create" | "folders.update" | "folders.delete" | "folders.move" | "ensureLens" | "ensureLenses";
111
+ /** One recorded call: the method and the options object it was given, exactly as passed. */
112
+ interface MockCalmLensCall {
113
+ operation: MockCalmLensOperation;
114
+ options: unknown;
115
+ }
116
+ /**
117
+ * What a simulated request failure throws: `"transport-error"` and `"timeout"` throw the same
118
+ * `CalmLensError` the real client throws for a network failure (`sdk/transport-error`) or a
119
+ * deadline (`sdk/timeout`); any `Error` is thrown as given.
120
+ */
121
+ type MockRequestFailure = "transport-error" | "timeout" | Error;
98
122
  export declare class MockCalmLensClient {
99
123
  private readonly options;
100
124
  readonly databaseStorage: MockDatabaseStorage;
@@ -107,10 +131,24 @@ export declare class MockCalmLensClient {
107
131
  private readonly signedUrlBaseUrl;
108
132
  private readonly cdnBaseUrl;
109
133
  private readonly lenses;
134
+ private readonly pendingFailures;
135
+ /** Every call made through this client, oldest first. */
136
+ readonly calls: MockCalmLensCall[];
137
+ /** Accepts the same options as `CalmLensClient` (validated the same way), plus `mockOptions`. */
110
138
  constructor(options: MockCalmLensClientOptions);
139
+ /**
140
+ * Makes the next call (or the next call to `operation`) throw `failure` instead of running,
141
+ * as if the request never completed. Queue several to fail several calls in a row.
142
+ */
143
+ failNextRequest(failure?: MockRequestFailure, { operation }?: {
144
+ operation?: MockCalmLensOperation;
145
+ }): void;
146
+ /** Calls recorded for one operation, oldest first. */
147
+ callsTo(operation: MockCalmLensOperation): MockCalmLensCall[];
148
+ private begin;
111
149
  get cdn(): {
112
150
  getAssetUrl: ({ assetIdentifier, ...options }: CdnAssetUrlOptions) => string;
113
- serve: ({ assetIdentifier, ...options }: CdnServeOptions) => Promise<Response>;
151
+ serve: (serveOptions: CdnServeOptions) => Promise<Response>;
114
152
  };
115
153
  get events(): {
116
154
  /** The mock does not record events; it always returns an empty page at "now". */
@@ -121,29 +159,32 @@ export declare class MockCalmLensClient {
121
159
  };
122
160
  get assets(): {
123
161
  list: (options: ListAssetsOptions) => Promise<GetAssetsPageResponse>;
124
- retrieve: ({ assetId }: RetrieveAssetOptions) => Promise<GetAssetResponse>;
125
- listChildren: ({ assetId, ...options }: ListAssetChildrenOptions) => Promise<GetAssetChildrenResponse>;
162
+ retrieve: (options: RetrieveAssetOptions) => Promise<GetAssetResponse>;
163
+ listChildren: (childrenOptions: ListAssetChildrenOptions) => Promise<GetAssetChildrenResponse>;
164
+ update: (options: UpdateAssetOptions) => Promise<Asset>;
126
165
  create: (options: SubmitAssetOptions) => Promise<Asset>;
127
166
  moderate: (options: SubmitAssetOptions) => Promise<Asset>;
128
- uploadPart: ({ assetId, part }: UploadAssetPartOptions) => Promise<Asset>;
129
- createSignedUrl: ({ assetId, ...options }: CreateAssetSignedUrlOptions) => Promise<PostAssetSignedUrlResponse>;
130
- move: ({ assetId, folderId }: MoveAssetOptions) => Promise<Asset>;
131
- retry: ({ assetId }: RetryAssetOptions) => Promise<Asset>;
167
+ uploadPart: (options: UploadAssetPartOptions) => Promise<Asset>;
168
+ createSignedUrl: (signedUrlOptions: CreateAssetSignedUrlOptions) => Promise<PostAssetSignedUrlResponse>;
169
+ move: (options: MoveAssetOptions) => Promise<Asset>;
170
+ retry: (options: RetryAssetOptions) => Promise<Asset>;
132
171
  };
133
172
  get folders(): {
134
173
  list: () => Promise<Folder[]>;
135
- retrieve: ({ folderId }: FolderIdOptions) => Promise<Folder>;
174
+ retrieve: (options: FolderIdOptions) => Promise<Folder>;
136
175
  create: (options: CreateFolderOptions) => Promise<Folder>;
137
- update: ({ folderId, ...body }: UpdateFolderOptions) => Promise<Folder>;
138
- delete: ({ folderId }: FolderIdOptions) => Promise<void>;
139
- move: ({ folderId, parentId }: MoveFolderOptions) => Promise<Folder>;
176
+ update: (options: UpdateFolderOptions) => Promise<Folder>;
177
+ delete: (options: FolderIdOptions) => Promise<void>;
178
+ move: (options: MoveFolderOptions) => Promise<Folder>;
140
179
  };
141
180
  ensureLens(options: EnsureLensOptions): Promise<Lens>;
142
- ensureLenses({ lenses }: EnsureLensesOptions): Promise<Lens[]>;
181
+ private ensureLensDefinition;
182
+ ensureLenses(options: EnsureLensesOptions): Promise<Lens[]>;
183
+ private moderateAsset;
143
184
  private createAsset;
144
185
  private resolveFolder;
145
186
  private assertUniqueFolderName;
146
187
  private getSizeInBytes;
147
188
  }
148
189
  //#endregion
149
- export type { MockCalmLensClientOptions, MockDatabaseStorage, MockImageStorage, MockStoredContent };
190
+ export type { MockCalmLensCall, MockCalmLensClientOptions, MockCalmLensOperation, MockDatabaseStorage, MockImageStorage, MockRequestFailure, MockStoredContent };