@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.
@@ -1245,6 +1245,7 @@ declare const ASSET_SCHEMA: zod.ZodObject<{
1245
1245
  audioTranscribed: zod.ZodBoolean;
1246
1246
  segments: zod.ZodArray<zod.ZodObject<{
1247
1247
  source: zod.ZodEnum<{
1248
+ clip: "clip";
1248
1249
  frame: "frame";
1249
1250
  "frame-text": "frame-text";
1250
1251
  speech: "speech";
@@ -3518,4 +3519,4 @@ interface ModerateTextOptions extends Omit<SubmitAssetCommonOptions, "name" | "v
3518
3519
  name?: string;
3519
3520
  }
3520
3521
  //#endregion
3521
- export { GetEventsResponse as A, EventFacts as B, UpdateAssetOptions as C, GetAssetChildrenResponse as D, VerifyWebhookSignatureOptions as E, Folder as F, AssetType as G, EventType as H, TypedEvent as I, ProcessingOptions as J, AssetVisibility as K, EventCategory as L, RequestErrorCode as M, AssetBinaryPayloadInput as N, GetAssetResponse as O, Lens as P, EventFact as R, SubmitAssetOptions as S, UploadAssetPartOptions as T, Asset as U, EventSeverity as V, AssetStatus as W, MultipartUploadOptions as _, CreateAssetSignedUrlOptions as a, RetrieveAssetOptions as b, EnsureLensOptions as c, ListAssetChildrenOptions as d, ListAssetsOptions as f, MoveFolderOptions as g, MoveAssetOptions as h, CdnServeOptions as i, PostAssetSignedUrlResponse as j, GetAssetsPageResponse as k, EnsureLensesOptions as l, ModerateTextOptions as m, CalmLensClientOptions as n, CreateFolderOptions as o, ListEventsOptions as p, MetadataItem as q, CdnAssetUrlOptions as r, CreateMultipartUploadPartOptions as s, AssetContentOptions as t, FolderIdOptions as u, MultipartUploadPartOptions as v, UpdateFolderOptions as w, RetryAssetOptions as x, RequestOptions as y, EventFactValues as z };
3522
+ export { GetEventsResponse as A, EventFactValues as B, UpdateAssetOptions as C, GetAssetChildrenResponse as D, VerifyWebhookSignatureOptions as E, Folder as F, AssetStatus as G, EventSeverity as H, Event as I, MetadataItem as J, AssetType as K, TypedEvent as L, RequestErrorCode as M, AssetBinaryPayloadInput as N, GetAssetResponse as O, Lens as P, EventCategory as R, SubmitAssetOptions as S, UploadAssetPartOptions as T, EventType as U, EventFacts as V, Asset as W, ProcessingOptions as Y, MultipartUploadOptions as _, CreateAssetSignedUrlOptions as a, RetrieveAssetOptions as b, EnsureLensOptions as c, ListAssetChildrenOptions as d, ListAssetsOptions as f, MoveFolderOptions as g, MoveAssetOptions as h, CdnServeOptions as i, PostAssetSignedUrlResponse as j, GetAssetsPageResponse as k, EnsureLensesOptions as l, ModerateTextOptions as m, CalmLensClientOptions as n, CreateFolderOptions as o, ListEventsOptions as p, AssetVisibility as q, CdnAssetUrlOptions as r, CreateMultipartUploadPartOptions as s, AssetContentOptions as t, FolderIdOptions as u, MultipartUploadPartOptions as v, UpdateFolderOptions as w, RetryAssetOptions as x, RequestOptions as y, EventFact as z };
@@ -395,6 +395,27 @@ function _objectWithoutProperties(e, t) {
395
395
  //#endregion
396
396
  //#region src/client/CalmLensUtils.ts
397
397
  const _excluded = ["text", "name"];
398
+ const invalidOptions = (message) => calmLensError({ id: "upload/invalid-payload" }, { message });
399
+ const assertHttpUrl = (name, value) => {
400
+ if (value === void 0) return;
401
+ let url;
402
+ try {
403
+ url = new URL(value);
404
+ } catch (_unused) {}
405
+ if (!url || url.protocol !== "https:" && url.protocol !== "http:") throw invalidOptions(`${name} must be an absolute http(s) URL`);
406
+ };
407
+ /**
408
+ * Checks client options before the client sets anything up. `CalmLensClient` and
409
+ * `MockCalmLensClient` share it so both reject the same configuration.
410
+ */
411
+ const validateClientOptions = (options) => {
412
+ if (!options || typeof options !== "object") throw invalidOptions("Client options are required");
413
+ if (!options.apiKey) throw invalidOptions("API key is required");
414
+ if (!options.projectId) throw invalidOptions("Project ID is required");
415
+ if (options.timeoutMs !== void 0 && (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs <= 0)) throw invalidOptions("timeoutMs must be a positive integer");
416
+ assertHttpUrl("baseUrl", options.baseUrl);
417
+ assertHttpUrl("cdnBaseUrl", options.cdnBaseUrl);
418
+ };
398
419
  const toTextAssetOptions = (_ref) => {
399
420
  let { text, name } = _ref, options = _objectWithoutProperties(_ref, _excluded);
400
421
  if (typeof text !== "string" || !text.trim()) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Text to moderate must be a non-empty string" });
@@ -407,4 +428,4 @@ const toTextAssetOptions = (_ref) => {
407
428
  });
408
429
  };
409
430
  //#endregion
410
- export { validateAssetPayload as _, calmLensError as a, MIN_MULTIPART_IMAGE_UPLOAD_BYTES as c, PUBLIC_ERROR_CODES as d, stringifyJsonCanonical as f, getRawBase64 as g, getAssetPayloadByteLength as h, SDK_ERRORS as i, getRejectedUploadMimeTypeError as l, assetToData as m, _objectWithoutProperties as n, DOMAIN as o, assetDataToUint8Array as p, CalmLensError as r, MAX_IMAGE_UPLOAD_BYTES as s, toTextAssetOptions as t, isRejectedUploadMimeType as u, _asyncToGenerator as v, _objectSpread2 as y };
431
+ export { getRawBase64 as _, SDK_ERRORS as a, _objectSpread2 as b, MAX_IMAGE_UPLOAD_BYTES as c, isRejectedUploadMimeType as d, PUBLIC_ERROR_CODES as f, getAssetPayloadByteLength as g, assetToData as h, CalmLensError as i, MIN_MULTIPART_IMAGE_UPLOAD_BYTES as l, assetDataToUint8Array as m, validateClientOptions as n, calmLensError as o, stringifyJsonCanonical as p, _objectWithoutProperties as r, DOMAIN as s, toTextAssetOptions as t, getRejectedUploadMimeTypeError as u, validateAssetPayload as v, _asyncToGenerator as y };
package/esm/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as GetEventsResponse, B as EventFacts, C as UpdateAssetOptions, D as GetAssetChildrenResponse, E as VerifyWebhookSignatureOptions, F as Folder, G as AssetType, H as EventType, I as TypedEvent, J as ProcessingOptions, K as AssetVisibility, L as EventCategory, M as RequestErrorCode, O as GetAssetResponse, P as Lens, R as EventFact, S as SubmitAssetOptions, T as UploadAssetPartOptions, U as Asset, V as EventSeverity, W as AssetStatus, _ as MultipartUploadOptions, 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, q as MetadataItem, r as CdnAssetUrlOptions, s as CreateMultipartUploadPartOptions, t as AssetContentOptions, u as FolderIdOptions, v as MultipartUploadPartOptions, w as UpdateFolderOptions, x as RetryAssetOptions, y as RequestOptions, z as EventFactValues } from "./CalmLensTypes-DG_kHVqY.js";
1
+ import { A as GetEventsResponse, B as EventFactValues, C as UpdateAssetOptions, D as GetAssetChildrenResponse, E as VerifyWebhookSignatureOptions, F as Folder, G as AssetStatus, H as EventSeverity, I as Event, J as MetadataItem, K as AssetType, L as TypedEvent, M as RequestErrorCode, O as GetAssetResponse, P as Lens, R as EventCategory, S as SubmitAssetOptions, T as UploadAssetPartOptions, U as EventType, V as EventFacts, W as Asset, Y as ProcessingOptions, _ as MultipartUploadOptions, 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, q as AssetVisibility, r as CdnAssetUrlOptions, s as CreateMultipartUploadPartOptions, t as AssetContentOptions, u as FolderIdOptions, v as MultipartUploadPartOptions, w as UpdateFolderOptions, x as RetryAssetOptions, y as RequestOptions, z as EventFact } from "./CalmLensTypes-BpmT60j-.js";
2
2
  import * as zod from "zod";
3
3
  //#region ../shared/src/Classification.d.ts
4
4
  declare const CLASSIFICATION_CATEGORY_SCHEMA: zod.ZodEnum<{
@@ -1348,6 +1348,7 @@ declare const CLASSIFICATION_REPORT_SCHEMA: zod.ZodObject<{
1348
1348
  audioTranscribed: zod.ZodBoolean;
1349
1349
  segments: zod.ZodArray<zod.ZodObject<{
1350
1350
  source: zod.ZodEnum<{
1351
+ clip: "clip";
1351
1352
  frame: "frame";
1352
1353
  "frame-text": "frame-text";
1353
1354
  speech: "speech";
@@ -2731,6 +2732,15 @@ export declare const WEBHOOK_TIMESTAMP_HEADER = "x-calmlens-timestamp";
2731
2732
  export declare const WEBHOOK_SIGNATURE_HEADER = "x-calmlens-signature";
2732
2733
  /** Deliveries whose timestamp is further than this from the receiver's clock are rejected. */
2733
2734
  export declare const WEBHOOK_SIGNATURE_TOLERANCE_SECONDS = 300;
2735
+ /** The JSON body of a webhook delivery for a stored event. */
2736
+ export declare const toWebhookEventPayload: (event: Event) => WebhookEventPayload;
2737
+ /** Headers for one signed delivery of `body`. */
2738
+ export declare const createWebhookHeaders: (options: {
2739
+ secret: string;
2740
+ body: string;
2741
+ deliveryId: string;
2742
+ timestampSeconds?: number;
2743
+ }) => Promise<Record<string, string>>;
2734
2744
  /**
2735
2745
  * Verifies a webhook delivery: `x-calmlens-signature` must contain a `v1=` HMAC-SHA256 of
2736
2746
  * `"<x-calmlens-timestamp>.<raw body>"`, and the timestamp must be within `toleranceSeconds`
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as validateAssetPayload, a as calmLensError, c as MIN_MULTIPART_IMAGE_UPLOAD_BYTES, d as PUBLIC_ERROR_CODES, f as stringifyJsonCanonical, g as getRawBase64, h as getAssetPayloadByteLength, i as SDK_ERRORS, l as getRejectedUploadMimeTypeError, m as assetToData, n as _objectWithoutProperties, o as DOMAIN, r as CalmLensError, s as MAX_IMAGE_UPLOAD_BYTES, t as toTextAssetOptions, u as isRejectedUploadMimeType, v as _asyncToGenerator, y as _objectSpread2 } from "./CalmLensUtils-BQEgxGWk.js";
1
+ import { _ as getRawBase64, a as SDK_ERRORS, b as _objectSpread2, c as MAX_IMAGE_UPLOAD_BYTES, d as isRejectedUploadMimeType, f as PUBLIC_ERROR_CODES, g as getAssetPayloadByteLength, h as assetToData, i as CalmLensError, l as MIN_MULTIPART_IMAGE_UPLOAD_BYTES, n as validateClientOptions, o as calmLensError, p as stringifyJsonCanonical, r as _objectWithoutProperties, s as DOMAIN, t as toTextAssetOptions, u as getRejectedUploadMimeTypeError, v as validateAssetPayload, y as _asyncToGenerator } from "./CalmLensUtils-UthMaLx_.js";
2
2
  import * as zod from "zod";
3
3
  import "zod/v4";
4
4
  import { Api, FetchRequestBackend, RequestCoalescingMiddleware, RequestEvent, getErrorResponse, isRequestError } from "api-def";
@@ -201,7 +201,8 @@ zod.object({
201
201
  source: zod.enum([
202
202
  "frame",
203
203
  "speech",
204
- "frame-text"
204
+ "frame-text",
205
+ "clip"
205
206
  ]),
206
207
  startSeconds: zod.number().nonnegative(),
207
208
  endSeconds: zod.number().nonnegative(),
@@ -245,6 +246,24 @@ const WEBHOOK_TIMESTAMP_HEADER = "x-calmlens-timestamp";
245
246
  const WEBHOOK_SIGNATURE_HEADER = "x-calmlens-signature";
246
247
  /** Deliveries whose timestamp is further than this from the receiver's clock are rejected. */
247
248
  const WEBHOOK_SIGNATURE_TOLERANCE_SECONDS = 300;
249
+ /** The JSON body of a webhook delivery for a stored event. */
250
+ const toWebhookEventPayload = (event) => {
251
+ var _event$description, _event$assetId, _event$asset;
252
+ return {
253
+ id: event.id,
254
+ type: event.type,
255
+ createdAt: event.createdAt,
256
+ projectId: event.projectId,
257
+ data: {
258
+ severity: event.severity,
259
+ title: event.title,
260
+ description: (_event$description = event.description) !== null && _event$description !== void 0 ? _event$description : null,
261
+ assetId: (_event$assetId = event.assetId) !== null && _event$assetId !== void 0 ? _event$assetId : null,
262
+ asset: (_event$asset = event.asset) !== null && _event$asset !== void 0 ? _event$asset : null,
263
+ facts: event.facts
264
+ }
265
+ };
266
+ };
248
267
  const encoder = new TextEncoder();
249
268
  const hmacSha256Hex = function() {
250
269
  var _ref = _asyncToGenerator(function* (secret, message) {
@@ -275,7 +294,8 @@ const createWebhookSignatureHeader = function() {
275
294
  return _ref2.apply(this, arguments);
276
295
  };
277
296
  }();
278
- (function() {
297
+ /** Headers for one signed delivery of `body`. */
298
+ const createWebhookHeaders = function() {
279
299
  var _ref3 = _asyncToGenerator(function* (options) {
280
300
  var _options$timestampSec;
281
301
  const timestamp = (_options$timestampSec = options.timestampSeconds) !== null && _options$timestampSec !== void 0 ? _options$timestampSec : Math.floor(Date.now() / 1e3);
@@ -289,7 +309,7 @@ const createWebhookSignatureHeader = function() {
289
309
  return function createWebhookHeaders(_x6) {
290
310
  return _ref3.apply(this, arguments);
291
311
  };
292
- })();
312
+ }();
293
313
  /**
294
314
  * Verifies a webhook delivery: `x-calmlens-signature` must contain a `v1=` HMAC-SHA256 of
295
315
  * `"<x-calmlens-timestamp>.<raw body>"`, and the timestamp must be within `toleranceSeconds`
@@ -438,16 +458,42 @@ const requestSignal = (options, signal) => {
438
458
  ].filter((value) => value != null);
439
459
  return AbortSignal.any(signals);
440
460
  };
441
- const safeFetch = (fetchImpl, options) => function() {
442
- var _ref = _asyncToGenerator(function* (input, init) {
461
+ /** Copies a fully read body into a new Response, so later JSON parsing cannot hit the network. */
462
+ const toBufferedResponse = function() {
463
+ var _ref = _asyncToGenerator(function* (response) {
464
+ const body = response.status === 204 || response.status === 304 ? null : yield response.arrayBuffer();
465
+ const headers = new Headers(response.headers);
466
+ headers.delete("content-encoding");
467
+ headers.delete("content-length");
468
+ const buffered = new Response(body, {
469
+ status: response.status,
470
+ statusText: response.statusText,
471
+ headers
472
+ });
473
+ Object.defineProperty(buffered, "url", { value: response.url });
474
+ return buffered;
475
+ });
476
+ return function toBufferedResponse(_x) {
477
+ return _ref.apply(this, arguments);
478
+ };
479
+ }();
480
+ /**
481
+ * Wraps fetch with the client's deadline, cancellation and redirect policy. Every failure,
482
+ * including body reads, decompression and truncated bodies when `bufferBody` is set, becomes a
483
+ * `CalmLensError` (`sdk/transport-error`, `sdk/timeout` or `sdk/cancelled`) with the original
484
+ * error as its `cause`.
485
+ */
486
+ const safeFetch = (fetchImpl, options, { bufferBody }) => function() {
487
+ var _ref2 = _asyncToGenerator(function* (input, init) {
443
488
  var _init$signal;
444
489
  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);
445
490
  try {
446
491
  signal.throwIfAborted();
447
- return yield fetchImpl(input, _objectSpread2(_objectSpread2({}, init), {}, {
492
+ const response = yield fetchImpl(input, _objectSpread2(_objectSpread2({}, init), {}, {
448
493
  redirect: "error",
449
494
  signal
450
495
  }));
496
+ return bufferBody ? yield toBufferedResponse(response) : response;
451
497
  } catch (cause) {
452
498
  var _signal$reason;
453
499
  throw 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" }, {
@@ -456,8 +502,8 @@ const safeFetch = (fetchImpl, options) => function() {
456
502
  });
457
503
  }
458
504
  });
459
- return function(_x, _x2) {
460
- return _ref.apply(this, arguments);
505
+ return function(_x2, _x3) {
506
+ return _ref2.apply(this, arguments);
461
507
  };
462
508
  }();
463
509
  const createApi = (options) => {
@@ -473,7 +519,7 @@ const createApi = (options) => {
473
519
  if (context.error) throw normalizeApiError(context.error);
474
520
  } }
475
521
  ],
476
- 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 FetchRequestBackend(safeFetch(globalThis.fetch, options))
522
+ 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 FetchRequestBackend(safeFetch(globalThis.fetch, options, { bufferBody: true }))
477
523
  });
478
524
  };
479
525
  const isApiErrorPayload = (value) => {
@@ -667,9 +713,7 @@ var CalmLensClient = class CalmLensClient {
667
713
  this.pendingEnsureLenses = /* @__PURE__ */ new Map();
668
714
  this.multipartImageUploadSizes = /* @__PURE__ */ new Map();
669
715
  this.multipartUploadQueues = /* @__PURE__ */ new Map();
670
- if (!options.apiKey) throw calmLensError({ id: "upload/invalid-payload" }, { message: "API key is required" });
671
- if (!options.projectId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Project ID is required" });
672
- if (options.timeoutMs !== void 0 && (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs <= 0)) throw calmLensError({ id: "upload/invalid-payload" }, { message: "timeoutMs must be a positive integer" });
716
+ validateClientOptions(options);
673
717
  this.options = _objectSpread2({}, options);
674
718
  this.options.baseUrl = (_this$options$baseUrl = this.options.baseUrl) !== null && _this$options$baseUrl !== void 0 ? _this$options$baseUrl : `https://api.${DOMAIN}/v1`;
675
719
  this.options.cdnBaseUrl = (_this$options$cdnBase = this.options.cdnBaseUrl) !== null && _this$options$cdnBase !== void 0 ? _this$options$cdnBase : `https://cdn.${DOMAIN}/v1`;
@@ -684,11 +728,11 @@ var CalmLensClient = class CalmLensClient {
684
728
  return client;
685
729
  }
686
730
  getUploadFetch() {
687
- var _this$options$request, _ref2, _this$options$uploadF;
731
+ var _this$options$request, _ref3, _this$options$uploadF;
688
732
  const requestBackendFetch = (_this$options$request = this.options.requestBackend) === null || _this$options$request === void 0 ? void 0 : _this$options$request.fetch;
689
- 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;
733
+ 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;
690
734
  if (!fetchImpl) throw calmLensError(SDK_ERRORS.NO_CDN_FETCH);
691
- return safeFetch(fetchImpl, this.options);
735
+ return safeFetch(fetchImpl, this.options, { bufferBody: true });
692
736
  }
693
737
  submitRawAssetUpload(options, queue) {
694
738
  var _this = this;
@@ -777,7 +821,7 @@ var CalmLensClient = class CalmLensClient {
777
821
  try {
778
822
  data = yield response.json();
779
823
  } catch (cause) {
780
- throw 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" }, {
824
+ throw calmLensError({ id: response.ok ? "sdk/invalid-response" : "sdk/http-error" }, {
781
825
  message: `Invalid JSON response (HTTP ${response.status})`,
782
826
  status: response.status,
783
827
  cause
@@ -820,9 +864,9 @@ var CalmLensClient = class CalmLensClient {
820
864
  * Create a CDN URL for asset content or previews.
821
865
  * Private assets require an authenticated request or signed URL.
822
866
  */
823
- getAssetUrl: (_ref3) => {
867
+ getAssetUrl: (_ref4) => {
824
868
  var _options$resource;
825
- let { assetIdentifier } = _ref3, options = _objectWithoutProperties(_ref3, _excluded3);
869
+ let { assetIdentifier } = _ref4, options = _objectWithoutProperties(_ref4, _excluded3);
826
870
  if (!assetIdentifier) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset identifier is required" });
827
871
  const resource = (_options$resource = options.resource) !== null && _options$resource !== void 0 ? _options$resource : "content";
828
872
  const url = `${this.options.cdnBaseUrl.replace(/\/$/, "")}/assets/${encodeURIComponent(this.options.projectId)}/${encodeURIComponent(assetIdentifier)}/${resource}`;
@@ -833,15 +877,15 @@ var CalmLensClient = class CalmLensClient {
833
877
  * Private assets are authenticated with the client's API key.
834
878
  */
835
879
  serve: function() {
836
- var _ref5 = _asyncToGenerator(function* (_ref4) {
880
+ var _ref6 = _asyncToGenerator(function* (_ref5) {
837
881
  var _this$options$cdnFetc;
838
- let { assetIdentifier, init } = _ref4, urlOptions = _objectWithoutProperties(_ref4, _excluded4);
882
+ let { assetIdentifier, init } = _ref5, urlOptions = _objectWithoutProperties(_ref5, _excluded4);
839
883
  const fetchImpl = (_this$options$cdnFetc = _this3.options.cdnFetch) !== null && _this$options$cdnFetc !== void 0 ? _this$options$cdnFetc : globalThis.fetch;
840
884
  if (!fetchImpl) throw calmLensError(SDK_ERRORS.NO_CDN_FETCH);
841
- return safeFetch(fetchImpl, _this3.options)(_this3.cdn.getAssetUrl(_objectSpread2({ assetIdentifier }, urlOptions)), withApiKeyHeader(init, _this3.options.apiKey));
885
+ return safeFetch(fetchImpl, _this3.options, { bufferBody: false })(_this3.cdn.getAssetUrl(_objectSpread2({ assetIdentifier }, urlOptions)), withApiKeyHeader(init, _this3.options.apiKey));
842
886
  });
843
- return function serve(_x3) {
844
- return _ref5.apply(this, arguments);
887
+ return function serve(_x4) {
888
+ return _ref6.apply(this, arguments);
845
889
  };
846
890
  }()
847
891
  };
@@ -849,11 +893,11 @@ var CalmLensClient = class CalmLensClient {
849
893
  get text() {
850
894
  var _this4 = this;
851
895
  return { moderate: function() {
852
- var _ref6 = _asyncToGenerator(function* (options) {
896
+ var _ref7 = _asyncToGenerator(function* (options) {
853
897
  return _this4.assets.moderate(toTextAssetOptions(options));
854
898
  });
855
- return function moderate(_x4) {
856
- return _ref6.apply(this, arguments);
899
+ return function moderate(_x5) {
900
+ return _ref7.apply(this, arguments);
857
901
  };
858
902
  }() };
859
903
  }
@@ -866,15 +910,15 @@ var CalmLensClient = class CalmLensClient {
866
910
  * @returns Promise with paginated assets
867
911
  */
868
912
  list: function() {
869
- var _ref7 = _asyncToGenerator(function* (options) {
913
+ var _ref8 = _asyncToGenerator(function* (options) {
870
914
  var _options$pageIndex;
871
915
  return (yield _this5.endpoints.getAssetsPage.submit({
872
916
  params: { projectId: _this5.options.projectId },
873
917
  query: _objectSpread2(_objectSpread2({}, options), {}, { pageIndex: (_options$pageIndex = options.pageIndex) !== null && _options$pageIndex !== void 0 ? _options$pageIndex : 0 })
874
918
  })).data;
875
919
  });
876
- return function list(_x5) {
877
- return _ref7.apply(this, arguments);
920
+ return function list(_x6) {
921
+ return _ref8.apply(this, arguments);
878
922
  };
879
923
  }(),
880
924
  /**
@@ -883,25 +927,25 @@ var CalmLensClient = class CalmLensClient {
883
927
  * @returns Promise with asset data
884
928
  */
885
929
  retrieve: function() {
886
- var _ref8 = _asyncToGenerator(function* ({ assetId }) {
930
+ var _ref9 = _asyncToGenerator(function* ({ assetId }) {
887
931
  if (!assetId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
888
932
  return (yield _this5.endpoints.getAsset.submit({ params: { assetId } })).data;
889
933
  });
890
- return function retrieve(_x6) {
891
- return _ref8.apply(this, arguments);
934
+ return function retrieve(_x7) {
935
+ return _ref9.apply(this, arguments);
892
936
  };
893
937
  }(),
894
938
  update: function() {
895
- var _ref10 = _asyncToGenerator(function* (_ref9) {
896
- let { assetId } = _ref9, body = _objectWithoutProperties(_ref9, _excluded5);
939
+ var _ref11 = _asyncToGenerator(function* (_ref10) {
940
+ let { assetId } = _ref10, body = _objectWithoutProperties(_ref10, _excluded5);
897
941
  if (!assetId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
898
942
  return (yield _this5.endpoints.patchAsset.submit({
899
943
  params: { assetId },
900
944
  body
901
945
  })).data;
902
946
  });
903
- return function update(_x7) {
904
- return _ref10.apply(this, arguments);
947
+ return function update(_x8) {
948
+ return _ref11.apply(this, arguments);
905
949
  };
906
950
  }(),
907
951
  /**
@@ -911,17 +955,17 @@ var CalmLensClient = class CalmLensClient {
911
955
  * @returns Promise with paginated child assets
912
956
  */
913
957
  listChildren: function() {
914
- var _ref12 = _asyncToGenerator(function* (_ref11) {
958
+ var _ref13 = _asyncToGenerator(function* (_ref12) {
915
959
  var _options$pageIndex2;
916
- let { assetId } = _ref11, options = _objectWithoutProperties(_ref11, _excluded6);
960
+ let { assetId } = _ref12, options = _objectWithoutProperties(_ref12, _excluded6);
917
961
  if (!assetId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
918
962
  return (yield _this5.endpoints.getAssetChildren.submit({
919
963
  params: { assetId },
920
964
  query: _objectSpread2(_objectSpread2({}, options), {}, { pageIndex: (_options$pageIndex2 = options.pageIndex) !== null && _options$pageIndex2 !== void 0 ? _options$pageIndex2 : 0 })
921
965
  })).data;
922
966
  });
923
- return function listChildren(_x8) {
924
- return _ref12.apply(this, arguments);
967
+ return function listChildren(_x9) {
968
+ return _ref13.apply(this, arguments);
925
969
  };
926
970
  }(),
927
971
  /**
@@ -931,7 +975,7 @@ var CalmLensClient = class CalmLensClient {
931
975
  * @returns Promise with created asset
932
976
  */
933
977
  create: function() {
934
- var _ref13 = _asyncToGenerator(function* (options) {
978
+ var _ref14 = _asyncToGenerator(function* (options) {
935
979
  const body = prepareSubmitAssetOptions(options);
936
980
  if ("content" in body || "part" in body) return yield _this5.submitRawAssetUpload(body, true);
937
981
  return (yield _this5.endpoints.postUploadAsset.submit({
@@ -940,8 +984,8 @@ var CalmLensClient = class CalmLensClient {
940
984
  query: { queue: true }
941
985
  })).data;
942
986
  });
943
- return function create(_x9) {
944
- return _ref13.apply(this, arguments);
987
+ return function create(_x10) {
988
+ return _ref14.apply(this, arguments);
945
989
  };
946
990
  }(),
947
991
  /**
@@ -952,7 +996,7 @@ var CalmLensClient = class CalmLensClient {
952
996
  * @returns Promise with created and analyzed asset
953
997
  */
954
998
  moderate: function() {
955
- var _ref14 = _asyncToGenerator(function* (options) {
999
+ var _ref15 = _asyncToGenerator(function* (options) {
956
1000
  if ("content" in options && "plainText" in options.content && (typeof options.content.plainText !== "string" || !options.content.plainText.trim())) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Text to moderate must be a non-empty string" });
957
1001
  const body = prepareSubmitAssetOptions(options);
958
1002
  if ("content" in body || "part" in body) return yield _this5.submitRawAssetUpload(body, false);
@@ -962,8 +1006,8 @@ var CalmLensClient = class CalmLensClient {
962
1006
  query: { queue: false }
963
1007
  })).data;
964
1008
  });
965
- return function moderate(_x10) {
966
- return _ref14.apply(this, arguments);
1009
+ return function moderate(_x11) {
1010
+ return _ref15.apply(this, arguments);
967
1011
  };
968
1012
  }(),
969
1013
  /**
@@ -973,7 +1017,7 @@ var CalmLensClient = class CalmLensClient {
973
1017
  * @returns Promise with asset data
974
1018
  */
975
1019
  uploadPart: function() {
976
- var _ref15 = _asyncToGenerator(function* ({ assetId, part }) {
1020
+ var _ref16 = _asyncToGenerator(function* ({ assetId, part }) {
977
1021
  var _part$sizeInBytes3, _this$multipartUpload;
978
1022
  if (!assetId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
979
1023
  if (!part) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Part options are required" });
@@ -991,8 +1035,8 @@ var CalmLensClient = class CalmLensClient {
991
1035
  }
992
1036
  return yield _this5.submitRawAssetPart(assetId, part, (_this$multipartUpload = _this5.multipartUploadQueues.get(assetId)) !== null && _this$multipartUpload !== void 0 ? _this$multipartUpload : false);
993
1037
  });
994
- return function uploadPart(_x11) {
995
- return _ref15.apply(this, arguments);
1038
+ return function uploadPart(_x12) {
1039
+ return _ref16.apply(this, arguments);
996
1040
  };
997
1041
  }(),
998
1042
  /**
@@ -1001,9 +1045,9 @@ var CalmLensClient = class CalmLensClient {
1001
1045
  * auth cookies or API keys to the CDN on every media request.
1002
1046
  */
1003
1047
  createSignedUrl: function() {
1004
- var _ref17 = _asyncToGenerator(function* (_ref16) {
1048
+ var _ref18 = _asyncToGenerator(function* (_ref17) {
1005
1049
  var _options$resource2, _options$expiresInSec;
1006
- let { assetId } = _ref16, options = _objectWithoutProperties(_ref16, _excluded7);
1050
+ let { assetId } = _ref17, options = _objectWithoutProperties(_ref17, _excluded7);
1007
1051
  if (!assetId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
1008
1052
  if (options.lens && options.transform) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Specify either a lens or a transform, not both" });
1009
1053
  return (yield _this5.endpoints.postAssetSignedUrl.submit({
@@ -1016,20 +1060,20 @@ var CalmLensClient = class CalmLensClient {
1016
1060
  params: { assetId }
1017
1061
  })).data;
1018
1062
  });
1019
- return function createSignedUrl(_x12) {
1020
- return _ref17.apply(this, arguments);
1063
+ return function createSignedUrl(_x13) {
1064
+ return _ref18.apply(this, arguments);
1021
1065
  };
1022
1066
  }(),
1023
1067
  move: function() {
1024
- var _ref18 = _asyncToGenerator(function* ({ assetId, folderId }) {
1068
+ var _ref19 = _asyncToGenerator(function* ({ assetId, folderId }) {
1025
1069
  if (!assetId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
1026
1070
  return (yield _this5.endpoints.moveAsset.submit({
1027
1071
  params: { assetId },
1028
1072
  body: { folderId }
1029
1073
  })).data;
1030
1074
  });
1031
- return function move(_x13) {
1032
- return _ref18.apply(this, arguments);
1075
+ return function move(_x14) {
1076
+ return _ref19.apply(this, arguments);
1033
1077
  };
1034
1078
  }(),
1035
1079
  /**
@@ -1037,12 +1081,12 @@ var CalmLensClient = class CalmLensClient {
1037
1081
  * moderated like a new upload; its content must still be stored.
1038
1082
  */
1039
1083
  retry: function() {
1040
- var _ref19 = _asyncToGenerator(function* ({ assetId }) {
1084
+ var _ref20 = _asyncToGenerator(function* ({ assetId }) {
1041
1085
  if (!assetId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
1042
1086
  return (yield _this5.endpoints.retryAsset.submit({ params: { assetId } })).data;
1043
1087
  });
1044
- return function retry(_x14) {
1045
- return _ref19.apply(this, arguments);
1088
+ return function retry(_x15) {
1089
+ return _ref20.apply(this, arguments);
1046
1090
  };
1047
1091
  }()
1048
1092
  };
@@ -1056,14 +1100,14 @@ var CalmLensClient = class CalmLensClient {
1056
1100
  * reshaped as `{ id, type, createdAt, projectId, data }`.
1057
1101
  */
1058
1102
  list: function() {
1059
- var _ref20 = _asyncToGenerator(function* (options = {}) {
1103
+ var _ref21 = _asyncToGenerator(function* (options = {}) {
1060
1104
  return (yield _this6.endpoints.getEvents.submit({
1061
1105
  params: { projectId: _this6.options.projectId },
1062
1106
  query: options
1063
1107
  })).data;
1064
1108
  });
1065
1109
  return function list() {
1066
- return _ref20.apply(this, arguments);
1110
+ return _ref21.apply(this, arguments);
1067
1111
  };
1068
1112
  }() };
1069
1113
  }
@@ -1071,65 +1115,65 @@ list: function() {
1071
1115
  var _this7 = this;
1072
1116
  return {
1073
1117
  list: function() {
1074
- var _ref21 = _asyncToGenerator(function* () {
1118
+ var _ref22 = _asyncToGenerator(function* () {
1075
1119
  return (yield _this7.endpoints.getFolders.submit({ params: { projectId: _this7.options.projectId } })).data.folders;
1076
1120
  });
1077
1121
  return function list() {
1078
- return _ref21.apply(this, arguments);
1122
+ return _ref22.apply(this, arguments);
1079
1123
  };
1080
1124
  }(),
1081
1125
  retrieve: function() {
1082
- var _ref22 = _asyncToGenerator(function* ({ folderId }) {
1126
+ var _ref23 = _asyncToGenerator(function* ({ folderId }) {
1083
1127
  if (!folderId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
1084
1128
  return (yield _this7.endpoints.getFolder.submit({ params: { folderId } })).data;
1085
1129
  });
1086
- return function retrieve(_x15) {
1087
- return _ref22.apply(this, arguments);
1130
+ return function retrieve(_x16) {
1131
+ return _ref23.apply(this, arguments);
1088
1132
  };
1089
1133
  }(),
1090
1134
  create: function() {
1091
- var _ref23 = _asyncToGenerator(function* (options) {
1135
+ var _ref24 = _asyncToGenerator(function* (options) {
1092
1136
  return (yield _this7.endpoints.postFolder.submit({
1093
1137
  params: { projectId: _this7.options.projectId },
1094
1138
  body: options
1095
1139
  })).data;
1096
1140
  });
1097
- return function create(_x16) {
1098
- return _ref23.apply(this, arguments);
1141
+ return function create(_x17) {
1142
+ return _ref24.apply(this, arguments);
1099
1143
  };
1100
1144
  }(),
1101
1145
  update: function() {
1102
- var _ref25 = _asyncToGenerator(function* (_ref24) {
1103
- let { folderId } = _ref24, body = _objectWithoutProperties(_ref24, _excluded8);
1146
+ var _ref26 = _asyncToGenerator(function* (_ref25) {
1147
+ let { folderId } = _ref25, body = _objectWithoutProperties(_ref25, _excluded8);
1104
1148
  if (!folderId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
1105
1149
  return (yield _this7.endpoints.patchFolder.submit({
1106
1150
  params: { folderId },
1107
1151
  body
1108
1152
  })).data;
1109
1153
  });
1110
- return function update(_x17) {
1111
- return _ref25.apply(this, arguments);
1154
+ return function update(_x18) {
1155
+ return _ref26.apply(this, arguments);
1112
1156
  };
1113
1157
  }(),
1114
1158
  delete: function() {
1115
- var _ref26 = _asyncToGenerator(function* ({ folderId }) {
1159
+ var _ref27 = _asyncToGenerator(function* ({ folderId }) {
1116
1160
  if (!folderId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
1117
1161
  yield _this7.endpoints.deleteFolder.submit({ params: { folderId } });
1118
1162
  });
1119
- return function _delete(_x18) {
1120
- return _ref26.apply(this, arguments);
1163
+ return function _delete(_x19) {
1164
+ return _ref27.apply(this, arguments);
1121
1165
  };
1122
1166
  }(),
1123
1167
  move: function() {
1124
- var _ref27 = _asyncToGenerator(function* ({ folderId, parentId }) {
1168
+ var _ref28 = _asyncToGenerator(function* ({ folderId, parentId }) {
1125
1169
  if (!folderId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
1126
1170
  return (yield _this7.endpoints.moveFolder.submit({
1127
1171
  params: { folderId },
1128
1172
  body: { parentId }
1129
1173
  })).data;
1130
1174
  });
1131
- return function move(_x19) {
1132
- return _ref27.apply(this, arguments);
1175
+ return function move(_x20) {
1176
+ return _ref28.apply(this, arguments);
1133
1177
  };
1134
1178
  }()
1135
1179
  };
@@ -1193,4 +1237,4 @@ list: function() {
1193
1237
  }
1194
1238
  };
1195
1239
  //#endregion
1196
- export { CalmLensClient, CalmLensError, MEDIA_TEST_SIGNALS, WEBHOOK_DELIVERY_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, WEBHOOK_TIMESTAMP_HEADER, generateMediaTestCode, verifyWebhookSignature };
1240
+ export { CalmLensClient, CalmLensError, MEDIA_TEST_SIGNALS, WEBHOOK_DELIVERY_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, WEBHOOK_TIMESTAMP_HEADER, createWebhookHeaders, generateMediaTestCode, toWebhookEventPayload, verifyWebhookSignature };