@calmlens/sdk 0.8.0 → 0.9.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.
@@ -412,6 +412,7 @@ const validateClientOptions = (options) => {
412
412
  if (!options || typeof options !== "object") throw invalidOptions("Client options are required");
413
413
  if (!options.apiKey) throw invalidOptions("API key is required");
414
414
  if (!options.projectId) throw invalidOptions("Project ID is required");
415
+ encodePathSegment(options.projectId, "Project ID");
415
416
  if (options.timeoutMs !== void 0 && (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs <= 0)) throw invalidOptions("timeoutMs must be a positive integer");
416
417
  assertHttpUrl("baseUrl", options.baseUrl);
417
418
  assertHttpUrl("cdnBaseUrl", options.cdnBaseUrl);
@@ -427,5 +428,45 @@ const toTextAssetOptions = (_ref) => {
427
428
  }
428
429
  });
429
430
  };
431
+ /**
432
+ * Encodes an identifier as one URL path segment. `.` and `..` are rejected because URL
433
+ * resolution would treat them as relative segments and send the request to another route.
434
+ */
435
+ const encodePathSegment = (value, name) => {
436
+ if (typeof value !== "string" || !value) throw invalidOptions(`${name} is required`);
437
+ if (value === "." || value === "..") throw invalidOptions(`${name} cannot be "." or ".."`);
438
+ return encodeURIComponent(value);
439
+ };
440
+ /** Appends a CDN lens (`/@name`) or direct transform selector to an asset URL. */
441
+ const appendCdnSelector = (url, options) => {
442
+ if (options.lens && options.transform) throw invalidOptions("Specify either a lens or a transform, not both");
443
+ if (options.lens) return `${url}/@${encodePathSegment(options.lens, "Lens")}`;
444
+ if (!options.transform) return url;
445
+ const transform = options.transform.replace(/^\/+/, "");
446
+ if (transform.includes("..") || transform.includes("?") || transform.includes("#")) throw invalidOptions("Transform cannot contain \"..\", \"?\" or \"#\"");
447
+ return `${url}/${encodeURI(transform)}`;
448
+ };
449
+ const appendQueryValue = (parts, key, value) => {
450
+ if (value === void 0 || value === null) return;
451
+ if (Array.isArray(value)) {
452
+ for (const [index, item] of value.entries()) appendQueryValue(parts, `${key}[${index}]`, item);
453
+ return;
454
+ }
455
+ if (typeof value === "object") {
456
+ for (const [field, item] of Object.entries(value)) appendQueryValue(parts, `${key}[${field}]`, item);
457
+ return;
458
+ }
459
+ parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
460
+ };
461
+ /**
462
+ * Serialises a query object the way the API parses it (qs bracket notation), for example
463
+ * `ordering[0][field]=createdAt&ordering[0][direction]=DESC`. Every key and value is
464
+ * percent-encoded and missing values are omitted.
465
+ */
466
+ const stringifyQuery = (query) => {
467
+ const parts = [];
468
+ for (const [key, value] of Object.entries(query)) appendQueryValue(parts, key, value);
469
+ return parts.join("&");
470
+ };
430
471
  //#endregion
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 };
472
+ export { _objectSpread2 as C, _asyncToGenerator as S, assetDataToUint8Array as _, validateClientOptions as a, getRawBase64 as b, SDK_ERRORS as c, MAX_IMAGE_UPLOAD_BYTES as d, MIN_MULTIPART_IMAGE_UPLOAD_BYTES as f, stringifyJsonCanonical as g, PUBLIC_ERROR_CODES as h, toTextAssetOptions as i, calmLensError as l, isRejectedUploadMimeType as m, encodePathSegment as n, _objectWithoutProperties as o, getRejectedUploadMimeTypeError as p, stringifyQuery as r, CalmLensError as s, appendCdnSelector as t, DOMAIN as u, assetToData as v, validateAssetPayload as x, getAssetPayloadByteLength as y };
package/esm/index.d.ts CHANGED
@@ -1,4 +1,4 @@
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-B7hr0SBv.js";
1
+ import { A as GetAssetResponse, B as EventCategory, C as RetryAssetOptions, D as UploadAssetPartOptions, E as UpdateFolderOptions, G as EventType, H as EventFactValues, I as Lens, J as AssetType, K as Asset, L as Folder, M as GetEventsResponse, N as PostAssetSignedUrlResponse, O as VerifyWebhookSignatureOptions, P as RequestErrorCode, R as Event, S as RetrieveAssetOptions, T as UpdateAssetOptions, U as EventFacts, V as EventFact, W as EventSeverity, X as MetadataItem, Y as AssetVisibility, Z as ProcessingOptions, _ as MoveAssetOptions, a as CreateAssetSignedUrlOptions, b as MultipartUploadPartOptions, c as DeleteAssetContentOptions, d as EnsureLensesOptions, f as FolderIdOptions, g as ModerateTextOptions, h as ListEventsOptions, i as CdnServeOptions, j as GetAssetsPageResponse, k as GetAssetChildrenResponse, l as DeleteAssetOptions, m as ListAssetsOptions, n as CalmLensClientOptions, o as CreateFolderOptions, p as ListAssetChildrenOptions, q as AssetStatus, r as CdnAssetUrlOptions, s as CreateMultipartUploadPartOptions, t as AssetContentOptions, u as EnsureLensOptions, v as MoveFolderOptions, w as SubmitAssetOptions, x as RequestOptions, y as MultipartUploadOptions, z as TypedEvent } from "./CalmLensTypes-CZqyni4p.js";
2
2
  import * as zod from "zod";
3
3
  //#region ../shared/src/AssetSearch.d.ts
4
4
  declare const ASSET_SEARCH_QUERY_SCHEMA: zod.ZodObject<{
@@ -7501,7 +7501,7 @@ declare class CalmLensClient {
7501
7501
  * @param options - Pagination and filtering options
7502
7502
  * @returns Promise with paginated assets
7503
7503
  */
7504
- list: (options: ListAssetsOptions) => Promise<GetAssetsPageResponse>;
7504
+ list: (options?: ListAssetsOptions) => Promise<GetAssetsPageResponse>;
7505
7505
  /**
7506
7506
  * Retrieve a specific asset by ID
7507
7507
  * @param assetId - The asset ID
@@ -7515,7 +7515,7 @@ declare class CalmLensClient {
7515
7515
  * @param options - Pagination options
7516
7516
  * @returns Promise with paginated child assets
7517
7517
  */
7518
- listChildren: ({ assetId, ...options }: ListAssetChildrenOptions) => Promise<GetAssetChildrenResponse>;
7518
+ listChildren: ({ assetId, ...options }?: ListAssetChildrenOptions) => Promise<GetAssetChildrenResponse>;
7519
7519
  /**
7520
7520
  * Submit a new asset for processing (queued asynchronously)
7521
7521
  * The asset will be queued for classification and returned immediately.
@@ -7550,6 +7550,14 @@ declare class CalmLensClient {
7550
7550
  * moderated like a new upload; its content must still be stored.
7551
7551
  */
7552
7552
  retry: ({ assetId }: RetryAssetOptions) => Promise<Asset>;
7553
+ /**
7554
+ * Removes an asset's stored content (source, preview and retained extracted text) while
7555
+ * keeping the asset record, metadata and moderation report. The returned asset has
7556
+ * `storageDeletedAt` set; the CDN no longer serves it.
7557
+ */
7558
+ deleteContent: ({ assetId }: DeleteAssetContentOptions) => Promise<Asset>;
7559
+ /** Deletes an asset record together with its stored content. */
7560
+ delete: ({ assetId }: DeleteAssetOptions) => Promise<void>;
7553
7561
  };
7554
7562
  get events(): {
7555
7563
  /**
@@ -7620,4 +7628,4 @@ export declare const createWebhookHeaders: (options: {
7620
7628
  */
7621
7629
  export declare function verifyWebhookSignature({ payload, signature, timestamp, secret, toleranceSeconds, now }: VerifyWebhookSignatureOptions): Promise<boolean>;
7622
7630
  //#endregion
7623
- export { type Asset, type GetAssetChildrenResponse as AssetChildrenPage, type AssetContentOptions, type GetAssetsPageResponse as AssetPage, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetStatus, type AssetType, type AssetVisibility, CalmLensClient, type CalmLensClientOptions, type CalmLensErrorDetails, type CdnAssetUrlOptions, type CdnServeOptions, type ClassificationCategoryReport, type ClassificationReport, type CreateAssetSignedUrlOptions, type CreateFolderOptions, type CreateMultipartUploadPartOptions, type EnsureLensOptions, type EnsureLensesOptions, type EventCategory, type EventFact, type EventFactValues, type EventFacts, type EventSeverity, type EventType, type GetEventsResponse as EventsPage, type Folder, type FolderIdOptions, type Lens, type ListAssetChildrenOptions, type ListAssetsOptions, type ListEventsOptions, type MetadataItem, type ModerateTextOptions, type MoveAssetOptions, type MoveFolderOptions, type MultipartUploadOptions, type MultipartUploadPartOptions, type ProcessingOptions, type RequestOptions, type RetrieveAssetOptions, type RetryAssetOptions, type SubmitAssetOptions, type TypedEvent, type UpdateAssetOptions, type UpdateFolderOptions, type UploadAssetPartOptions, type VerifyWebhookSignatureOptions, type WebhookEventPayload };
7631
+ export { type Asset, type GetAssetChildrenResponse as AssetChildrenPage, type AssetContentOptions, type GetAssetsPageResponse as AssetPage, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetStatus, type AssetType, type AssetVisibility, CalmLensClient, type CalmLensClientOptions, type CalmLensErrorDetails, type CdnAssetUrlOptions, type CdnServeOptions, type ClassificationCategoryReport, type ClassificationReport, type CreateAssetSignedUrlOptions, type CreateFolderOptions, type CreateMultipartUploadPartOptions, type DeleteAssetContentOptions, type DeleteAssetOptions, type EnsureLensOptions, type EnsureLensesOptions, type EventCategory, type EventFact, type EventFactValues, type EventFacts, type EventSeverity, type EventType, type GetEventsResponse as EventsPage, type Folder, type FolderIdOptions, type Lens, type ListAssetChildrenOptions, type ListAssetsOptions, type ListEventsOptions, type MetadataItem, type ModerateTextOptions, type MoveAssetOptions, type MoveFolderOptions, type MultipartUploadOptions, type MultipartUploadPartOptions, type ProcessingOptions, type RequestOptions, type RetrieveAssetOptions, type RetryAssetOptions, type SubmitAssetOptions, type TypedEvent, type UpdateAssetOptions, type UpdateFolderOptions, type UploadAssetPartOptions, type VerifyWebhookSignatureOptions, type WebhookEventPayload };
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
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-BZsX8yeO.js";
1
+ import { C as _objectSpread2, S as _asyncToGenerator, a as validateClientOptions, b as getRawBase64, c as SDK_ERRORS, d as MAX_IMAGE_UPLOAD_BYTES, f as MIN_MULTIPART_IMAGE_UPLOAD_BYTES, g as stringifyJsonCanonical, h as PUBLIC_ERROR_CODES, i as toTextAssetOptions, l as calmLensError, m as isRejectedUploadMimeType, n as encodePathSegment, o as _objectWithoutProperties, p as getRejectedUploadMimeTypeError, r as stringifyQuery, s as CalmLensError, t as appendCdnSelector, u as DOMAIN, v as assetToData, x as validateAssetPayload, y as getAssetPayloadByteLength } from "./CalmLensUtils-Bnikzonc.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";
@@ -242,6 +242,42 @@ function generateMediaTestCode(signal, projectId) {
242
242
  return `Calm Lens test ${[...suffix].map((character) => HEX_WORDS[Number.parseInt(character, 16)]).join(" ")} ${signal.replace(/[.-]/g, " ")} end test`;
243
243
  }
244
244
  //#endregion
245
+ //#region ../shared/src/CryptoUtils.ts
246
+ const encoder = new TextEncoder();
247
+ /** Lowercase hex of `bytes`, two characters per byte. */
248
+ const bytesToHex = (bytes) => Array.from(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
249
+ (function() {
250
+ var _ref = _asyncToGenerator(function* (value) {
251
+ return bytesToHex(yield crypto.subtle.digest("SHA-256", encoder.encode(value)));
252
+ });
253
+ return function sha256Hex(_x) {
254
+ return _ref.apply(this, arguments);
255
+ };
256
+ })();
257
+ /** HMAC-SHA256 of `message` keyed with `secret` (both UTF-8 encoded), as lowercase hex. */
258
+ const hmacSha256Hex = function() {
259
+ var _ref2 = _asyncToGenerator(function* (secret, message) {
260
+ const key = yield crypto.subtle.importKey("raw", encoder.encode(secret), {
261
+ name: "HMAC",
262
+ hash: "SHA-256"
263
+ }, false, ["sign"]);
264
+ return bytesToHex(yield crypto.subtle.sign("HMAC", key, encoder.encode(message)));
265
+ });
266
+ return function hmacSha256Hex(_x2, _x3) {
267
+ return _ref2.apply(this, arguments);
268
+ };
269
+ }();
270
+ /**
271
+ * Compares two strings without leaking, through timing, where they first differ. Strings of
272
+ * different lengths are unequal immediately (the length itself is not secret here).
273
+ */
274
+ const timingSafeEqual = (a, b) => {
275
+ if (a.length !== b.length) return false;
276
+ let difference = 0;
277
+ for (let index = 0; index < a.length; index++) difference |= a.charCodeAt(index) ^ b.charCodeAt(index);
278
+ return difference === 0;
279
+ };
280
+ //#endregion
245
281
  //#region src/client/CalmLensWebhooks.ts
246
282
  const WEBHOOK_DELIVERY_HEADER = "x-calmlens-delivery";
247
283
  const WEBHOOK_TIMESTAMP_HEADER = "x-calmlens-timestamp";
@@ -266,39 +302,18 @@ const toWebhookEventPayload = (event) => {
266
302
  }
267
303
  };
268
304
  };
269
- const encoder = new TextEncoder();
270
- const hmacSha256Hex = function() {
271
- var _ref = _asyncToGenerator(function* (secret, message) {
272
- const key = yield crypto.subtle.importKey("raw", encoder.encode(secret), {
273
- name: "HMAC",
274
- hash: "SHA-256"
275
- }, false, ["sign"]);
276
- const signature = yield crypto.subtle.sign("HMAC", key, encoder.encode(message));
277
- return Array.from(new Uint8Array(signature), (byte) => byte.toString(16).padStart(2, "0")).join("");
278
- });
279
- return function hmacSha256Hex(_x, _x2) {
280
- return _ref.apply(this, arguments);
281
- };
282
- }();
283
- /** Constant-time comparison of two strings of the same length. */
284
- const timingSafeEqual = (a, b) => {
285
- if (a.length !== b.length) return false;
286
- let diff = 0;
287
- for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
288
- return diff === 0;
289
- };
290
305
  /** `v1=<hex HMAC-SHA256 of "<timestamp>.<body>">`, the `x-calmlens-signature` header value. */
291
306
  const createWebhookSignatureHeader = function() {
292
- var _ref2 = _asyncToGenerator(function* (secret, timestamp, body) {
307
+ var _ref = _asyncToGenerator(function* (secret, timestamp, body) {
293
308
  return `v1=${yield hmacSha256Hex(secret, `${timestamp}.${body}`)}`;
294
309
  });
295
- return function createWebhookSignatureHeader(_x3, _x4, _x5) {
296
- return _ref2.apply(this, arguments);
310
+ return function createWebhookSignatureHeader(_x, _x2, _x3) {
311
+ return _ref.apply(this, arguments);
297
312
  };
298
313
  }();
299
314
  /** Headers for one signed delivery of `body`. */
300
315
  const createWebhookHeaders = function() {
301
- var _ref3 = _asyncToGenerator(function* (options) {
316
+ var _ref2 = _asyncToGenerator(function* (options) {
302
317
  var _options$timestampSec;
303
318
  const timestamp = (_options$timestampSec = options.timestampSeconds) !== null && _options$timestampSec !== void 0 ? _options$timestampSec : Math.floor(Date.now() / 1e3);
304
319
  return {
@@ -308,8 +323,8 @@ const createWebhookHeaders = function() {
308
323
  [WEBHOOK_SIGNATURE_HEADER]: yield createWebhookSignatureHeader(options.secret, timestamp, options.body)
309
324
  };
310
325
  });
311
- return function createWebhookHeaders(_x6) {
312
- return _ref3.apply(this, arguments);
326
+ return function createWebhookHeaders(_x4) {
327
+ return _ref2.apply(this, arguments);
313
328
  };
314
329
  }();
315
330
  /**
@@ -317,7 +332,7 @@ const createWebhookHeaders = function() {
317
332
  * `"<x-calmlens-timestamp>.<raw body>"`, and the timestamp must be within `toleranceSeconds`
318
333
  * (default 300) of now. Returns `false` for anything missing or malformed.
319
334
  */
320
- function verifyWebhookSignature(_x7) {
335
+ function verifyWebhookSignature(_x5) {
321
336
  return _verifyWebhookSignature.apply(this, arguments);
322
337
  }
323
338
  function _verifyWebhookSignature() {
@@ -425,12 +440,6 @@ const prepareSubmitAssetOptions = (options) => {
425
440
  }
426
441
  return options;
427
442
  };
428
- const appendCdnSelector = (url, options) => {
429
- if (options.lens && options.transform) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Specify either a lens or a transform, not both" });
430
- if (options.lens) return `${url}/@${encodeURIComponent(options.lens)}`;
431
- if (!options.transform) return url;
432
- return `${url}/${encodeURI(options.transform.replace(/^\/+/, ""))}`;
433
- };
434
443
  const getEnsureLensCacheKey = (options) => {
435
444
  var _options$description, _options$transforms;
436
445
  return stringifyJsonCanonical({
@@ -512,6 +521,7 @@ const createApi = (options) => {
512
521
  return new Api({
513
522
  name: "Calm Lens",
514
523
  baseUrl: options.baseUrl,
524
+ config: { queryHandling: { stringify: stringifyQuery } },
515
525
  middleware: [
516
526
  RequestCoalescingMiddleware(),
517
527
  { beforeSend: (context) => {
@@ -643,12 +653,32 @@ const createEndpoints = (api) => {
643
653
  method: "post",
644
654
  path: "/assets/:assetId/retry"
645
655
  });
656
+ const deleteAsset = api.endpoint().paramsOf().responseOf().build({
657
+ id: "deleteAsset",
658
+ method: "delete",
659
+ path: "/assets/:assetId"
660
+ });
661
+ const deleteAssetContent = api.endpoint().paramsOf().responseOf().build({
662
+ id: "deleteAssetContent",
663
+ method: "delete",
664
+ path: "/assets/:assetId/content"
665
+ });
646
666
  const getEvents = api.endpoint().paramsOf().queryOf().responseOf().build({
647
667
  id: "getEvents",
648
668
  method: "get",
649
669
  path: "/projects/:projectId/events"
650
670
  });
651
- return {
671
+ const ensureLens = api.endpoint().bodyOf().paramsOf().responseOf().build({
672
+ id: "ensureLens",
673
+ method: "put",
674
+ path: "/lenses/:lensIdentifier"
675
+ });
676
+ const ensureLenses = api.endpoint().bodyOf().paramsOf().responseOf().build({
677
+ id: "ensureLenses",
678
+ method: "put",
679
+ path: "/projects/:projectId/lenses"
680
+ });
681
+ return encodePathParams({
652
682
  getFolders,
653
683
  getFolder,
654
684
  postFolder,
@@ -665,18 +695,23 @@ const createEndpoints = (api) => {
665
695
  postAssetPart,
666
696
  moveAsset,
667
697
  retryAsset,
668
- ensureLens: api.endpoint().bodyOf().paramsOf().responseOf().build({
669
- id: "ensureLens",
670
- method: "put",
671
- path: "/lenses/:lensIdentifier"
672
- }),
673
- ensureLenses: api.endpoint().bodyOf().paramsOf().responseOf().build({
674
- id: "ensureLenses",
675
- method: "put",
676
- path: "/projects/:projectId/lenses"
677
- }),
698
+ deleteAsset,
699
+ deleteAssetContent,
700
+ ensureLens,
701
+ ensureLenses,
678
702
  getEvents
679
- };
703
+ });
704
+ };
705
+ /**
706
+ * api-def inserts `/:param` values into the path verbatim, so every endpoint encodes its path
707
+ * params here: an ID can never add path segments, a query string or a fragment.
708
+ */
709
+ const encodePathParams = (endpoints) => {
710
+ for (const endpoint of Object.values(endpoints)) {
711
+ const submit = endpoint.submit.bind(endpoint);
712
+ endpoint.submit = (config) => submit(_objectSpread2(_objectSpread2({}, config), {}, { params: config.params && Object.fromEntries(Object.entries(config.params).map(([key, value]) => [key, encodePathSegment(value, key)])) }));
713
+ }
714
+ return endpoints;
680
715
  };
681
716
  var CalmLensClient = class CalmLensClient {
682
717
  /**
@@ -802,7 +837,7 @@ var CalmLensClient = class CalmLensClient {
802
837
  isFinal: String((_part$isFinal2 = part.isFinal) !== null && _part$isFinal2 !== void 0 ? _part$isFinal2 : false)
803
838
  });
804
839
  setOptionalQueryValue(query, "sizeInBytes", (_part$sizeInBytes2 = part.sizeInBytes) !== null && _part$sizeInBytes2 !== void 0 ? _part$sizeInBytes2 : getAssetPayloadByteLength(part));
805
- const url = `${_this2.options.baseUrl.replace(/\/$/, "")}/assets/${encodeURIComponent(assetId)}/part?${query}`;
840
+ const url = `${_this2.options.baseUrl.replace(/\/$/, "")}/assets/${encodePathSegment(assetId, "Asset ID")}/part?${query}`;
806
841
  const response = yield _this2.getUploadFetch()(url, {
807
842
  method: "POST",
808
843
  headers: {
@@ -877,7 +912,7 @@ var CalmLensClient = class CalmLensClient {
877
912
  let { assetIdentifier } = _ref4, options = _objectWithoutProperties(_ref4, _excluded3);
878
913
  if (!assetIdentifier) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset identifier is required" });
879
914
  const resource = (_options$resource = options.resource) !== null && _options$resource !== void 0 ? _options$resource : "content";
880
- const url = `${this.options.cdnBaseUrl.replace(/\/$/, "")}/assets/${encodeURIComponent(this.options.projectId)}/${encodeURIComponent(assetIdentifier)}/${resource}`;
915
+ const url = `${this.options.cdnBaseUrl.replace(/\/$/, "")}/assets/${encodeURIComponent(this.options.projectId)}/${encodePathSegment(assetIdentifier, "Asset identifier")}/${resource}`;
881
916
  return appendCdnSelector(url, options);
882
917
  },
883
918
  /**
@@ -929,14 +964,14 @@ var CalmLensClient = class CalmLensClient {
929
964
  * @returns Promise with paginated assets
930
965
  */
931
966
  list: function() {
932
- var _ref9 = _asyncToGenerator(function* (options) {
967
+ var _ref9 = _asyncToGenerator(function* (options = {}) {
933
968
  var _options$pageIndex;
934
969
  return (yield _this5.endpoints.getAssetsPage.submit({
935
970
  params: { projectId: _this5.options.projectId },
936
971
  query: _objectSpread2(_objectSpread2({}, options), {}, { pageIndex: (_options$pageIndex = options.pageIndex) !== null && _options$pageIndex !== void 0 ? _options$pageIndex : 0 })
937
972
  })).data;
938
973
  });
939
- return function list(_x7) {
974
+ return function list() {
940
975
  return _ref9.apply(this, arguments);
941
976
  };
942
977
  }(),
@@ -950,7 +985,7 @@ var CalmLensClient = class CalmLensClient {
950
985
  if (!assetId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
951
986
  return (yield _this5.endpoints.getAsset.submit({ params: { assetId } })).data;
952
987
  });
953
- return function retrieve(_x8) {
988
+ return function retrieve(_x7) {
954
989
  return _ref10.apply(this, arguments);
955
990
  };
956
991
  }(),
@@ -963,7 +998,7 @@ var CalmLensClient = class CalmLensClient {
963
998
  body
964
999
  })).data;
965
1000
  });
966
- return function update(_x9) {
1001
+ return function update(_x8) {
967
1002
  return _ref12.apply(this, arguments);
968
1003
  };
969
1004
  }(),
@@ -974,7 +1009,7 @@ var CalmLensClient = class CalmLensClient {
974
1009
  * @returns Promise with paginated child assets
975
1010
  */
976
1011
  listChildren: function() {
977
- var _ref14 = _asyncToGenerator(function* (_ref13) {
1012
+ var _ref14 = _asyncToGenerator(function* (_ref13 = {}) {
978
1013
  var _options$pageIndex2;
979
1014
  let { assetId } = _ref13, options = _objectWithoutProperties(_ref13, _excluded6);
980
1015
  if (!assetId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
@@ -983,7 +1018,7 @@ var CalmLensClient = class CalmLensClient {
983
1018
  query: _objectSpread2(_objectSpread2({}, options), {}, { pageIndex: (_options$pageIndex2 = options.pageIndex) !== null && _options$pageIndex2 !== void 0 ? _options$pageIndex2 : 0 })
984
1019
  })).data;
985
1020
  });
986
- return function listChildren(_x10) {
1021
+ return function listChildren() {
987
1022
  return _ref14.apply(this, arguments);
988
1023
  };
989
1024
  }(),
@@ -1003,7 +1038,7 @@ var CalmLensClient = class CalmLensClient {
1003
1038
  query: { queue: true }
1004
1039
  })).data;
1005
1040
  });
1006
- return function create(_x11) {
1041
+ return function create(_x9) {
1007
1042
  return _ref15.apply(this, arguments);
1008
1043
  };
1009
1044
  }(),
@@ -1025,7 +1060,7 @@ var CalmLensClient = class CalmLensClient {
1025
1060
  query: { queue: false }
1026
1061
  })).data;
1027
1062
  });
1028
- return function moderate(_x12) {
1063
+ return function moderate(_x10) {
1029
1064
  return _ref16.apply(this, arguments);
1030
1065
  };
1031
1066
  }(),
@@ -1054,7 +1089,7 @@ var CalmLensClient = class CalmLensClient {
1054
1089
  }
1055
1090
  return yield _this5.submitRawAssetPart(assetId, part, (_this$multipartUpload = _this5.multipartUploadQueues.get(assetId)) !== null && _this$multipartUpload !== void 0 ? _this$multipartUpload : false);
1056
1091
  });
1057
- return function uploadPart(_x13) {
1092
+ return function uploadPart(_x11) {
1058
1093
  return _ref17.apply(this, arguments);
1059
1094
  };
1060
1095
  }(),
@@ -1079,7 +1114,7 @@ var CalmLensClient = class CalmLensClient {
1079
1114
  params: { assetId }
1080
1115
  })).data;
1081
1116
  });
1082
- return function createSignedUrl(_x14) {
1117
+ return function createSignedUrl(_x12) {
1083
1118
  return _ref19.apply(this, arguments);
1084
1119
  };
1085
1120
  }(),
@@ -1091,7 +1126,7 @@ var CalmLensClient = class CalmLensClient {
1091
1126
  body: { folderId }
1092
1127
  })).data;
1093
1128
  });
1094
- return function move(_x15) {
1129
+ return function move(_x13) {
1095
1130
  return _ref20.apply(this, arguments);
1096
1131
  };
1097
1132
  }(),
@@ -1104,9 +1139,33 @@ var CalmLensClient = class CalmLensClient {
1104
1139
  if (!assetId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
1105
1140
  return (yield _this5.endpoints.retryAsset.submit({ params: { assetId } })).data;
1106
1141
  });
1107
- return function retry(_x16) {
1142
+ return function retry(_x14) {
1108
1143
  return _ref21.apply(this, arguments);
1109
1144
  };
1145
+ }(),
1146
+ /**
1147
+ * Removes an asset's stored content (source, preview and retained extracted text) while
1148
+ * keeping the asset record, metadata and moderation report. The returned asset has
1149
+ * `storageDeletedAt` set; the CDN no longer serves it.
1150
+ */
1151
+ deleteContent: function() {
1152
+ var _ref22 = _asyncToGenerator(function* ({ assetId }) {
1153
+ if (!assetId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
1154
+ return (yield _this5.endpoints.deleteAssetContent.submit({ params: { assetId } })).data;
1155
+ });
1156
+ return function deleteContent(_x15) {
1157
+ return _ref22.apply(this, arguments);
1158
+ };
1159
+ }(),
1160
+ /** Deletes an asset record together with its stored content. */
1161
+ delete: function() {
1162
+ var _ref23 = _asyncToGenerator(function* ({ assetId }) {
1163
+ if (!assetId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
1164
+ yield _this5.endpoints.deleteAsset.submit({ params: { assetId } });
1165
+ });
1166
+ return function _delete(_x16) {
1167
+ return _ref23.apply(this, arguments);
1168
+ };
1110
1169
  }()
1111
1170
  };
1112
1171
  }
@@ -1119,14 +1178,14 @@ var CalmLensClient = class CalmLensClient {
1119
1178
  * reshaped as `{ id, type, createdAt, projectId, data }`.
1120
1179
  */
1121
1180
  list: function() {
1122
- var _ref22 = _asyncToGenerator(function* (options = {}) {
1181
+ var _ref24 = _asyncToGenerator(function* (options = {}) {
1123
1182
  return (yield _this6.endpoints.getEvents.submit({
1124
1183
  params: { projectId: _this6.options.projectId },
1125
1184
  query: options
1126
1185
  })).data;
1127
1186
  });
1128
1187
  return function list() {
1129
- return _ref22.apply(this, arguments);
1188
+ return _ref24.apply(this, arguments);
1130
1189
  };
1131
1190
  }() };
1132
1191
  }
@@ -1134,36 +1193,36 @@ list: function() {
1134
1193
  var _this7 = this;
1135
1194
  return {
1136
1195
  list: function() {
1137
- var _ref23 = _asyncToGenerator(function* () {
1196
+ var _ref25 = _asyncToGenerator(function* () {
1138
1197
  return (yield _this7.endpoints.getFolders.submit({ params: { projectId: _this7.options.projectId } })).data.folders;
1139
1198
  });
1140
1199
  return function list() {
1141
- return _ref23.apply(this, arguments);
1200
+ return _ref25.apply(this, arguments);
1142
1201
  };
1143
1202
  }(),
1144
1203
  retrieve: function() {
1145
- var _ref24 = _asyncToGenerator(function* ({ folderId }) {
1204
+ var _ref26 = _asyncToGenerator(function* ({ folderId }) {
1146
1205
  if (!folderId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
1147
1206
  return (yield _this7.endpoints.getFolder.submit({ params: { folderId } })).data;
1148
1207
  });
1149
1208
  return function retrieve(_x17) {
1150
- return _ref24.apply(this, arguments);
1209
+ return _ref26.apply(this, arguments);
1151
1210
  };
1152
1211
  }(),
1153
1212
  create: function() {
1154
- var _ref25 = _asyncToGenerator(function* (options) {
1213
+ var _ref27 = _asyncToGenerator(function* (options) {
1155
1214
  return (yield _this7.endpoints.postFolder.submit({
1156
1215
  params: { projectId: _this7.options.projectId },
1157
1216
  body: options
1158
1217
  })).data;
1159
1218
  });
1160
1219
  return function create(_x18) {
1161
- return _ref25.apply(this, arguments);
1220
+ return _ref27.apply(this, arguments);
1162
1221
  };
1163
1222
  }(),
1164
1223
  update: function() {
1165
- var _ref27 = _asyncToGenerator(function* (_ref26) {
1166
- let { folderId } = _ref26, body = _objectWithoutProperties(_ref26, _excluded8);
1224
+ var _ref29 = _asyncToGenerator(function* (_ref28) {
1225
+ let { folderId } = _ref28, body = _objectWithoutProperties(_ref28, _excluded8);
1167
1226
  if (!folderId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
1168
1227
  return (yield _this7.endpoints.patchFolder.submit({
1169
1228
  params: { folderId },
@@ -1171,20 +1230,20 @@ list: function() {
1171
1230
  })).data;
1172
1231
  });
1173
1232
  return function update(_x19) {
1174
- return _ref27.apply(this, arguments);
1233
+ return _ref29.apply(this, arguments);
1175
1234
  };
1176
1235
  }(),
1177
1236
  delete: function() {
1178
- var _ref28 = _asyncToGenerator(function* ({ folderId }) {
1237
+ var _ref30 = _asyncToGenerator(function* ({ folderId }) {
1179
1238
  if (!folderId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
1180
1239
  yield _this7.endpoints.deleteFolder.submit({ params: { folderId } });
1181
1240
  });
1182
1241
  return function _delete(_x20) {
1183
- return _ref28.apply(this, arguments);
1242
+ return _ref30.apply(this, arguments);
1184
1243
  };
1185
1244
  }(),
1186
1245
  move: function() {
1187
- var _ref29 = _asyncToGenerator(function* ({ folderId, parentId }) {
1246
+ var _ref31 = _asyncToGenerator(function* ({ folderId, parentId }) {
1188
1247
  if (!folderId) throw calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
1189
1248
  return (yield _this7.endpoints.moveFolder.submit({
1190
1249
  params: { folderId },
@@ -1192,7 +1251,7 @@ list: function() {
1192
1251
  })).data;
1193
1252
  });
1194
1253
  return function move(_x21) {
1195
- return _ref29.apply(this, arguments);
1254
+ return _ref31.apply(this, arguments);
1196
1255
  };
1197
1256
  }()
1198
1257
  };
package/esm/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
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-B7hr0SBv.js";
1
+ import { A as GetAssetResponse, C as RetryAssetOptions, D as UploadAssetPartOptions, E as UpdateFolderOptions, F as AssetBinaryPayloadInput, I as Lens, K as Asset, L as Folder, M as GetEventsResponse, N as PostAssetSignedUrlResponse, S as RetrieveAssetOptions, T as UpdateAssetOptions, _ as MoveAssetOptions, a as CreateAssetSignedUrlOptions, c as DeleteAssetContentOptions, d as EnsureLensesOptions, f as FolderIdOptions, g as ModerateTextOptions, h as ListEventsOptions, i as CdnServeOptions, j as GetAssetsPageResponse, k as GetAssetChildrenResponse, l as DeleteAssetOptions, m as ListAssetsOptions, n as CalmLensClientOptions, o as CreateFolderOptions, p as ListAssetChildrenOptions, q as AssetStatus, r as CdnAssetUrlOptions, u as EnsureLensOptions, v as MoveFolderOptions, w as SubmitAssetOptions } from "./CalmLensTypes-CZqyni4p.js";
2
2
  import * as zod from "zod";
3
3
  //#region ../shared/src/Permissions.d.ts
4
4
  declare const GRANT_SCHEMA: zod.ZodObject<{
@@ -107,7 +107,7 @@ interface MockCalmLensClientOptions extends CalmLensClientOptions {
107
107
  };
108
108
  }
109
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";
110
+ type MockCalmLensOperation = "assets.list" | "assets.retrieve" | "assets.update" | "assets.listChildren" | "assets.create" | "assets.moderate" | "assets.uploadPart" | "assets.createSignedUrl" | "assets.move" | "assets.retry" | "assets.deleteContent" | "assets.delete" | "text.moderate" | "cdn.serve" | "events.list" | "folders.list" | "folders.retrieve" | "folders.create" | "folders.update" | "folders.delete" | "folders.move" | "ensureLens" | "ensureLenses";
111
111
  /** One recorded call: the method and the options object it was given, exactly as passed. */
112
112
  interface MockCalmLensCall {
113
113
  operation: MockCalmLensOperation;
@@ -145,6 +145,7 @@ export declare class MockCalmLensClient {
145
145
  }): void;
146
146
  /** Calls recorded for one operation, oldest first. */
147
147
  callsTo(operation: MockCalmLensOperation): MockCalmLensCall[];
148
+ private findOwnAsset;
148
149
  private begin;
149
150
  get cdn(): {
150
151
  getAssetUrl: ({ assetIdentifier, ...options }: CdnAssetUrlOptions) => string;
@@ -158,9 +159,9 @@ export declare class MockCalmLensClient {
158
159
  moderate: (options: ModerateTextOptions) => Promise<Asset>;
159
160
  };
160
161
  get assets(): {
161
- list: (options: ListAssetsOptions) => Promise<GetAssetsPageResponse>;
162
+ list: (options?: ListAssetsOptions) => Promise<GetAssetsPageResponse>;
162
163
  retrieve: (options: RetrieveAssetOptions) => Promise<GetAssetResponse>;
163
- listChildren: (childrenOptions: ListAssetChildrenOptions) => Promise<GetAssetChildrenResponse>;
164
+ listChildren: (childrenOptions?: ListAssetChildrenOptions) => Promise<GetAssetChildrenResponse>;
164
165
  update: (options: UpdateAssetOptions) => Promise<Asset>;
165
166
  create: (options: SubmitAssetOptions) => Promise<Asset>;
166
167
  moderate: (options: SubmitAssetOptions) => Promise<Asset>;
@@ -168,6 +169,8 @@ export declare class MockCalmLensClient {
168
169
  createSignedUrl: (signedUrlOptions: CreateAssetSignedUrlOptions) => Promise<PostAssetSignedUrlResponse>;
169
170
  move: (options: MoveAssetOptions) => Promise<Asset>;
170
171
  retry: (options: RetryAssetOptions) => Promise<Asset>;
172
+ deleteContent: (options: DeleteAssetContentOptions) => Promise<Asset>;
173
+ delete: (options: DeleteAssetOptions) => Promise<void>;
171
174
  };
172
175
  get folders(): {
173
176
  list: () => Promise<Folder[]>;