@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.
package/cjs/testing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_CalmLensUtils = require("./CalmLensUtils-CJ6o7KRU.js");
2
+ const require_CalmLensUtils = require("./CalmLensUtils-CArkVfj0.js");
3
3
  let zod = require("zod");
4
4
  zod = require_CalmLensUtils.__toESM(zod);
5
5
  //#region ../shared/src/Permissions.ts
@@ -213,12 +213,6 @@ var InMemoryMockDatabaseStorage = class {
213
213
  };
214
214
  //#endregion
215
215
  //#region src/testing/MockUtils.ts
216
- const appendCdnSelector = (url, options) => {
217
- if (options.lens && options.transform) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Specify either a lens or a transform, not both" });
218
- if (options.lens) return `${url}/@${encodeURIComponent(options.lens)}`;
219
- if (!options.transform) return url;
220
- return `${url}/${encodeURI(options.transform.replace(/^\/+/, ""))}`;
221
- };
222
216
  const inferAssetType = (options) => {
223
217
  if ("url" in options) return "website";
224
218
  const type = "content" in options ? options.content.type : options.part.type;
@@ -312,6 +306,15 @@ var MockCalmLensClient = class {
312
306
  callsTo(operation) {
313
307
  return this.calls.filter((call) => call.operation === operation);
314
308
  }
309
+ findOwnAsset(assetId) {
310
+ var _this = this;
311
+ return require_CalmLensUtils._asyncToGenerator(function* () {
312
+ if (!assetId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
313
+ const asset = yield _this.databaseStorage.getAsset(assetId);
314
+ if (!asset || asset.projectId !== _this.options.projectId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
315
+ return asset;
316
+ })();
317
+ }
315
318
  begin(operation, options) {
316
319
  this.calls.push({
317
320
  operation,
@@ -324,32 +327,32 @@ var MockCalmLensClient = class {
324
327
  }
325
328
  }
326
329
  get cdn() {
327
- var _this = this;
330
+ var _this2 = this;
328
331
  return {
329
332
  getAssetUrl: (_ref) => {
330
333
  var _options$resource;
331
334
  let { assetIdentifier } = _ref, options = require_CalmLensUtils._objectWithoutProperties(_ref, _excluded);
332
335
  if (!assetIdentifier) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset identifier is required" });
333
336
  const resource = (_options$resource = options.resource) !== null && _options$resource !== void 0 ? _options$resource : "content";
334
- const url = `${this.cdnBaseUrl.replace(/\/$/, "")}/assets/${encodeURIComponent(this.options.projectId)}/${encodeURIComponent(assetIdentifier)}/${resource}`;
335
- return appendCdnSelector(url, options);
337
+ const url = `${this.cdnBaseUrl.replace(/\/$/, "")}/assets/${encodeURIComponent(this.options.projectId)}/${require_CalmLensUtils.encodePathSegment(assetIdentifier, "Asset identifier")}/${resource}`;
338
+ return require_CalmLensUtils.appendCdnSelector(url, options);
336
339
  },
337
340
  serve: function() {
338
341
  var _ref2 = require_CalmLensUtils._asyncToGenerator(function* (serveOptions) {
339
342
  var _asset$folderId, _await$this$databaseS, _this$databaseStorage, _this$databaseStorage2, _storedContent$type;
340
- _this.begin("cdn.serve", serveOptions);
343
+ _this2.begin("cdn.serve", serveOptions);
341
344
  const { assetIdentifier } = serveOptions, options = require_CalmLensUtils._objectWithoutProperties(serveOptions, _excluded2);
342
345
  if (!assetIdentifier) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset identifier is required" });
343
- const asset = (yield _this.databaseStorage.listAssets(_this.options.projectId)).find((asset) => asset.id === assetIdentifier || asset.externalId === assetIdentifier);
346
+ const asset = (yield _this2.databaseStorage.listAssets(_this2.options.projectId)).find((asset) => asset.id === assetIdentifier || asset.externalId === assetIdentifier);
344
347
  if (!asset) return new Response("Asset not found", { status: 404 });
345
- if (asset.visibility !== "public" && !permits(_this.apiKeyGrants, "assets:download", (_asset$folderId = asset.folderId) !== null && _asset$folderId !== void 0 ? _asset$folderId : null, (_await$this$databaseS = yield (_this$databaseStorage = (_this$databaseStorage2 = _this.databaseStorage).listFolders) === null || _this$databaseStorage === void 0 ? void 0 : _this$databaseStorage.call(_this$databaseStorage2, _this.options.projectId)) !== null && _await$this$databaseS !== void 0 ? _await$this$databaseS : [])) return new Response(JSON.stringify({
348
+ if (asset.visibility !== "public" && !permits(_this2.apiKeyGrants, "assets:download", (_asset$folderId = asset.folderId) !== null && _asset$folderId !== void 0 ? _asset$folderId : null, (_await$this$databaseS = yield (_this$databaseStorage = (_this$databaseStorage2 = _this2.databaseStorage).listFolders) === null || _this$databaseStorage === void 0 ? void 0 : _this$databaseStorage.call(_this$databaseStorage2, _this2.options.projectId)) !== null && _await$this$databaseS !== void 0 ? _await$this$databaseS : [])) return new Response(JSON.stringify({
346
349
  code: "asset/api-key-missing-permission",
347
350
  message: "This API key needs assets:download permission for this asset’s folder."
348
351
  }), {
349
352
  status: 403,
350
353
  headers: { "Content-Type": "application/json" }
351
354
  });
352
- const storedContent = yield _this.imageStorage.getContent(asset.id);
355
+ const storedContent = yield _this2.imageStorage.getContent(asset.id);
353
356
  if (!storedContent) return new Response("Asset content not found", { status: 404 });
354
357
  const parts = [...storedContent.parts.entries()].sort(([left], [right]) => left - right).map(([, value]) => value);
355
358
  const byteLength = parts.reduce((sum, value) => sum + value.byteLength, 0);
@@ -363,7 +366,7 @@ var MockCalmLensClient = class {
363
366
  status: 200,
364
367
  headers: {
365
368
  "Content-Type": (_storedContent$type = storedContent.type) !== null && _storedContent$type !== void 0 ? _storedContent$type : "application/octet-stream",
366
- "X-Mock-CalmLens-CDN-URL": _this.cdn.getAssetUrl(require_CalmLensUtils._objectSpread2({ assetIdentifier }, options))
369
+ "X-Mock-CalmLens-CDN-URL": _this2.cdn.getAssetUrl(require_CalmLensUtils._objectSpread2({ assetIdentifier }, options))
367
370
  }
368
371
  });
369
372
  });
@@ -374,16 +377,16 @@ var MockCalmLensClient = class {
374
377
  };
375
378
  }
376
379
  get events() {
377
- var _this2 = this;
380
+ var _this3 = this;
378
381
  return {
379
382
  /** The mock does not record events; it always returns an empty page at "now". */
380
383
  list: function() {
381
384
  var _ref3 = require_CalmLensUtils._asyncToGenerator(function* (options = {}) {
382
385
  var _options$after;
383
- _this2.begin("events.list", options);
386
+ _this3.begin("events.list", options);
384
387
  return {
385
388
  events: [],
386
- cursor: (_options$after = options.after) !== null && _options$after !== void 0 ? _options$after : `${_this2.now()}_`,
389
+ cursor: (_options$after = options.after) !== null && _options$after !== void 0 ? _options$after : `${_this3.now()}_`,
387
390
  hasMore: false
388
391
  };
389
392
  });
@@ -393,11 +396,11 @@ list: function() {
393
396
  }() };
394
397
  }
395
398
  get text() {
396
- var _this3 = this;
399
+ var _this4 = this;
397
400
  return { moderate: function() {
398
401
  var _ref4 = require_CalmLensUtils._asyncToGenerator(function* (options) {
399
- _this3.begin("text.moderate", options);
400
- return _this3.moderateAsset(require_CalmLensUtils.toTextAssetOptions(options));
402
+ _this4.begin("text.moderate", options);
403
+ return _this4.moderateAsset(require_CalmLensUtils.toTextAssetOptions(options));
401
404
  });
402
405
  return function moderate(_x2) {
403
406
  return _ref4.apply(this, arguments);
@@ -405,286 +408,313 @@ list: function() {
405
408
  }() };
406
409
  }
407
410
  get assets() {
408
- var _this4 = this;
411
+ var _this5 = this;
409
412
  return {
410
413
  list: function() {
411
- var _ref5 = require_CalmLensUtils._asyncToGenerator(function* (options) {
414
+ var _ref5 = require_CalmLensUtils._asyncToGenerator(function* (options = {}) {
412
415
  var _options$pageIndex;
413
- _this4.begin("assets.list", options);
414
- const assets = yield _this4.databaseStorage.listAssets(_this4.options.projectId);
416
+ _this5.begin("assets.list", options);
417
+ const assets = yield _this5.databaseStorage.listAssets(_this5.options.projectId);
415
418
  return createPage(assets, require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, options), {}, { pageIndex: (_options$pageIndex = options.pageIndex) !== null && _options$pageIndex !== void 0 ? _options$pageIndex : 0 }));
416
419
  });
417
- return function list(_x3) {
420
+ return function list() {
418
421
  return _ref5.apply(this, arguments);
419
422
  };
420
423
  }(),
421
424
  retrieve: function() {
422
425
  var _ref6 = require_CalmLensUtils._asyncToGenerator(function* (options) {
423
- _this4.begin("assets.retrieve", options);
426
+ _this5.begin("assets.retrieve", options);
424
427
  const { assetId } = options;
425
428
  if (!assetId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
426
- const asset = yield _this4.databaseStorage.getAsset(assetId);
429
+ const asset = yield _this5.databaseStorage.getAsset(assetId);
427
430
  if (!asset) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
428
431
  return asset;
429
432
  });
430
- return function retrieve(_x4) {
433
+ return function retrieve(_x3) {
431
434
  return _ref6.apply(this, arguments);
432
435
  };
433
436
  }(),
434
437
  listChildren: function() {
435
- var _ref7 = require_CalmLensUtils._asyncToGenerator(function* (childrenOptions) {
438
+ var _ref7 = require_CalmLensUtils._asyncToGenerator(function* (childrenOptions = {}) {
436
439
  var _options$pageIndex2;
437
- _this4.begin("assets.listChildren", childrenOptions);
440
+ _this5.begin("assets.listChildren", childrenOptions);
438
441
  const { assetId } = childrenOptions, options = require_CalmLensUtils._objectWithoutProperties(childrenOptions, _excluded3);
439
442
  if (!assetId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
440
- const assets = yield _this4.databaseStorage.listAssets(_this4.options.projectId);
443
+ const assets = yield _this5.databaseStorage.listAssets(_this5.options.projectId);
441
444
  return createPage(assets.filter((asset) => asset.parentId === assetId), require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, options), {}, { pageIndex: (_options$pageIndex2 = options.pageIndex) !== null && _options$pageIndex2 !== void 0 ? _options$pageIndex2 : 0 }));
442
445
  });
443
- return function listChildren(_x5) {
446
+ return function listChildren() {
444
447
  return _ref7.apply(this, arguments);
445
448
  };
446
449
  }(),
447
450
  update: function() {
448
451
  var _ref8 = require_CalmLensUtils._asyncToGenerator(function* (options) {
449
- _this4.begin("assets.update", options);
452
+ _this5.begin("assets.update", options);
450
453
  const { assetId } = options, body = require_CalmLensUtils._objectWithoutProperties(options, _excluded4);
451
454
  if (!assetId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
452
- const asset = yield _this4.databaseStorage.getAsset(assetId);
453
- if (!asset || asset.projectId !== _this4.options.projectId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
455
+ const asset = yield _this5.databaseStorage.getAsset(assetId);
456
+ if (!asset || asset.projectId !== _this5.options.projectId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
454
457
  const changes = Object.fromEntries(Object.entries(body).filter(([, value]) => value !== void 0));
455
- return _this4.databaseStorage.updateAsset(require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, asset), changes), {}, { updatedAt: _this4.now() }));
458
+ return _this5.databaseStorage.updateAsset(require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, asset), changes), {}, { updatedAt: _this5.now() }));
456
459
  });
457
- return function update(_x6) {
460
+ return function update(_x4) {
458
461
  return _ref8.apply(this, arguments);
459
462
  };
460
463
  }(),
461
464
  create: function() {
462
465
  var _ref9 = require_CalmLensUtils._asyncToGenerator(function* (options) {
463
- _this4.begin("assets.create", options);
464
- return _this4.createAsset(options, _this4.queuedStatus);
466
+ _this5.begin("assets.create", options);
467
+ return _this5.createAsset(options, _this5.queuedStatus);
465
468
  });
466
- return function create(_x7) {
469
+ return function create(_x5) {
467
470
  return _ref9.apply(this, arguments);
468
471
  };
469
472
  }(),
470
473
  moderate: function() {
471
474
  var _ref10 = require_CalmLensUtils._asyncToGenerator(function* (options) {
472
- _this4.begin("assets.moderate", options);
473
- return _this4.moderateAsset(options);
475
+ _this5.begin("assets.moderate", options);
476
+ return _this5.moderateAsset(options);
474
477
  });
475
- return function moderate(_x8) {
478
+ return function moderate(_x6) {
476
479
  return _ref10.apply(this, arguments);
477
480
  };
478
481
  }(),
479
482
  uploadPart: function() {
480
483
  var _ref11 = require_CalmLensUtils._asyncToGenerator(function* (options) {
481
484
  var _asset$uploadPartsRec;
482
- _this4.begin("assets.uploadPart", options);
485
+ _this5.begin("assets.uploadPart", options);
483
486
  const { assetId, part } = options;
484
487
  if (!assetId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
485
488
  if (!part) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Part options are required" });
486
- const asset = yield _this4.databaseStorage.getAsset(assetId);
489
+ const asset = yield _this5.databaseStorage.getAsset(assetId);
487
490
  if (!asset) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
488
491
  const validation = require_CalmLensUtils.validateAssetPayload(part, {
489
492
  multipart: true,
490
493
  isFinal: part.isFinal
491
494
  });
492
495
  if (!validation.ok) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: validation.error });
493
- yield _this4.imageStorage.putPart(assetId, part);
496
+ yield _this5.imageStorage.putPart(assetId, part);
494
497
  const updated = require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, asset), {}, {
495
- status: part.isFinal ? _this4.queuedStatus : "uploading",
498
+ status: part.isFinal ? _this5.queuedStatus : "uploading",
496
499
  uploadPartsReceived: Math.max((_asset$uploadPartsRec = asset.uploadPartsReceived) !== null && _asset$uploadPartsRec !== void 0 ? _asset$uploadPartsRec : 0, part.partNumber),
497
- updatedAt: _this4.now()
500
+ updatedAt: _this5.now()
498
501
  });
499
- return _this4.databaseStorage.updateAsset(updated);
502
+ return _this5.databaseStorage.updateAsset(updated);
500
503
  });
501
- return function uploadPart(_x9) {
504
+ return function uploadPart(_x7) {
502
505
  return _ref11.apply(this, arguments);
503
506
  };
504
507
  }(),
505
508
  createSignedUrl: function() {
506
509
  var _ref12 = require_CalmLensUtils._asyncToGenerator(function* (signedUrlOptions) {
507
510
  var _options$expiresInSec, _options$resource2;
508
- _this4.begin("assets.createSignedUrl", signedUrlOptions);
511
+ _this5.begin("assets.createSignedUrl", signedUrlOptions);
509
512
  const { assetId } = signedUrlOptions, options = require_CalmLensUtils._objectWithoutProperties(signedUrlOptions, _excluded5);
510
513
  if (!assetId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
511
- if (!(yield _this4.databaseStorage.getAsset(assetId))) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
514
+ if (!(yield _this5.databaseStorage.getAsset(assetId))) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
512
515
  const expiresInSeconds = (_options$expiresInSec = options.expiresInSeconds) !== null && _options$expiresInSec !== void 0 ? _options$expiresInSec : 900;
513
516
  const resource = (_options$resource2 = options.resource) !== null && _options$resource2 !== void 0 ? _options$resource2 : "content";
514
517
  if (options.lens && options.transform) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Specify either a lens or a transform, not both" });
515
518
  const selector = options.lens ? `&lens=${encodeURIComponent(options.lens)}` : options.transform ? `&transform=${encodeURIComponent(options.transform)}` : "";
516
519
  return {
517
- url: `${_this4.signedUrlBaseUrl}/assets/${assetId}/${resource}?expiresInSeconds=${expiresInSeconds}${selector}`,
518
- expiresAt: _this4.now() + expiresInSeconds * 1e3
520
+ url: `${_this5.signedUrlBaseUrl}/assets/${assetId}/${resource}?expiresInSeconds=${expiresInSeconds}${selector}`,
521
+ expiresAt: _this5.now() + expiresInSeconds * 1e3
519
522
  };
520
523
  });
521
- return function createSignedUrl(_x10) {
524
+ return function createSignedUrl(_x8) {
522
525
  return _ref12.apply(this, arguments);
523
526
  };
524
527
  }(),
525
528
  move: function() {
526
529
  var _ref13 = require_CalmLensUtils._asyncToGenerator(function* (options) {
527
- _this4.begin("assets.move", options);
530
+ _this5.begin("assets.move", options);
528
531
  const { assetId, folderId } = options;
529
532
  if (!assetId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
530
- const asset = yield _this4.databaseStorage.getAsset(assetId);
531
- if (!asset || asset.projectId !== _this4.options.projectId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
533
+ const asset = yield _this5.databaseStorage.getAsset(assetId);
534
+ if (!asset || asset.projectId !== _this5.options.projectId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
532
535
  if (folderId !== null && folderId !== void 0) {
533
- if (!(yield _this4.resolveFolder(folderId))) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
536
+ if (!(yield _this5.resolveFolder(folderId))) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
534
537
  }
535
538
  const updated = require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, asset), {}, {
536
539
  folderId: folderId !== null && folderId !== void 0 ? folderId : null,
537
- updatedAt: _this4.now()
540
+ updatedAt: _this5.now()
538
541
  });
539
- return _this4.databaseStorage.updateAsset(updated);
542
+ return _this5.databaseStorage.updateAsset(updated);
540
543
  });
541
- return function move(_x11) {
544
+ return function move(_x9) {
542
545
  return _ref13.apply(this, arguments);
543
546
  };
544
547
  }(),
545
548
  retry: function() {
546
549
  var _ref14 = require_CalmLensUtils._asyncToGenerator(function* (options) {
547
- _this4.begin("assets.retry", options);
550
+ _this5.begin("assets.retry", options);
548
551
  const { assetId } = options;
549
552
  if (!assetId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
550
- const asset = yield _this4.databaseStorage.getAsset(assetId);
551
- if (!asset || asset.projectId !== _this4.options.projectId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
553
+ const asset = yield _this5.databaseStorage.getAsset(assetId);
554
+ if (!asset || asset.projectId !== _this5.options.projectId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
552
555
  if (asset.status !== "error") throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.ASSET_NOT_RETRYABLE);
553
- return _this4.databaseStorage.updateAsset(require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, asset), {}, {
556
+ return _this5.databaseStorage.updateAsset(require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, asset), {}, {
554
557
  status: "pending",
555
- updatedAt: _this4.now()
558
+ updatedAt: _this5.now()
556
559
  }));
557
560
  });
558
- return function retry(_x12) {
561
+ return function retry(_x10) {
559
562
  return _ref14.apply(this, arguments);
560
563
  };
564
+ }(),
565
+ deleteContent: function() {
566
+ var _ref15 = require_CalmLensUtils._asyncToGenerator(function* (options) {
567
+ var _asset$storageDeleted;
568
+ _this5.begin("assets.deleteContent", options);
569
+ const asset = yield _this5.findOwnAsset(options.assetId);
570
+ yield _this5.imageStorage.deleteContent(asset.id);
571
+ return _this5.databaseStorage.updateAsset(require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, asset), {}, {
572
+ extractedText: null,
573
+ storageDeletedAt: (_asset$storageDeleted = asset.storageDeletedAt) !== null && _asset$storageDeleted !== void 0 ? _asset$storageDeleted : _this5.now(),
574
+ updatedAt: _this5.now()
575
+ }));
576
+ });
577
+ return function deleteContent(_x11) {
578
+ return _ref15.apply(this, arguments);
579
+ };
580
+ }(),
581
+ delete: function() {
582
+ var _ref16 = require_CalmLensUtils._asyncToGenerator(function* (options) {
583
+ _this5.begin("assets.delete", options);
584
+ const asset = yield _this5.findOwnAsset(options.assetId);
585
+ yield _this5.imageStorage.deleteContent(asset.id);
586
+ yield _this5.databaseStorage.deleteAsset(asset.id);
587
+ });
588
+ return function _delete(_x12) {
589
+ return _ref16.apply(this, arguments);
590
+ };
561
591
  }()
562
592
  };
563
593
  }
564
594
  get folders() {
565
- var _this5 = this;
595
+ var _this6 = this;
566
596
  return {
567
597
  list: function() {
568
- var _ref15 = require_CalmLensUtils._asyncToGenerator(function* () {
569
- _this5.begin("folders.list", void 0);
570
- return [..._this5.databaseStorage.listFolders ? yield _this5.databaseStorage.listFolders(_this5.options.projectId) : []].sort((a, b) => a.name.localeCompare(b.name));
598
+ var _ref17 = require_CalmLensUtils._asyncToGenerator(function* () {
599
+ _this6.begin("folders.list", void 0);
600
+ return [..._this6.databaseStorage.listFolders ? yield _this6.databaseStorage.listFolders(_this6.options.projectId) : []].sort((a, b) => a.name.localeCompare(b.name));
571
601
  });
572
602
  return function list() {
573
- return _ref15.apply(this, arguments);
603
+ return _ref17.apply(this, arguments);
574
604
  };
575
605
  }(),
576
606
  retrieve: function() {
577
- var _ref16 = require_CalmLensUtils._asyncToGenerator(function* (options) {
578
- _this5.begin("folders.retrieve", options);
607
+ var _ref18 = require_CalmLensUtils._asyncToGenerator(function* (options) {
608
+ _this6.begin("folders.retrieve", options);
579
609
  const { folderId } = options;
580
610
  if (!folderId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder ID is required" });
581
- const folder = yield _this5.resolveFolder(folderId);
611
+ const folder = yield _this6.resolveFolder(folderId);
582
612
  if (!folder) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
583
613
  return folder;
584
614
  });
585
615
  return function retrieve(_x13) {
586
- return _ref16.apply(this, arguments);
616
+ return _ref18.apply(this, arguments);
587
617
  };
588
618
  }(),
589
619
  create: function() {
590
- var _ref17 = require_CalmLensUtils._asyncToGenerator(function* (options) {
620
+ var _ref19 = require_CalmLensUtils._asyncToGenerator(function* (options) {
591
621
  var _options$parentId, _options$parentId2;
592
- _this5.begin("folders.create", options);
622
+ _this6.begin("folders.create", options);
593
623
  if (!options.name) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder name is required" });
594
624
  if (options.parentId) {
595
- if (!(yield _this5.resolveFolder(options.parentId))) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
625
+ if (!(yield _this6.resolveFolder(options.parentId))) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
596
626
  }
597
- yield _this5.assertUniqueFolderName(options.name, (_options$parentId = options.parentId) !== null && _options$parentId !== void 0 ? _options$parentId : null);
627
+ yield _this6.assertUniqueFolderName(options.name, (_options$parentId = options.parentId) !== null && _options$parentId !== void 0 ? _options$parentId : null);
598
628
  const folder = {
599
- id: _this5.createId(),
600
- projectId: _this5.options.projectId,
629
+ id: _this6.createId(),
630
+ projectId: _this6.options.projectId,
601
631
  parentId: (_options$parentId2 = options.parentId) !== null && _options$parentId2 !== void 0 ? _options$parentId2 : null,
602
632
  name: options.name,
603
- createdAt: _this5.now(),
604
- updatedAt: _this5.now()
633
+ createdAt: _this6.now(),
634
+ updatedAt: _this6.now()
605
635
  };
606
- if (_this5.databaseStorage.createFolder) return yield _this5.databaseStorage.createFolder(folder);
636
+ if (_this6.databaseStorage.createFolder) return yield _this6.databaseStorage.createFolder(folder);
607
637
  return folder;
608
638
  });
609
639
  return function create(_x14) {
610
- return _ref17.apply(this, arguments);
640
+ return _ref19.apply(this, arguments);
611
641
  };
612
642
  }(),
613
643
  update: function() {
614
- var _ref18 = require_CalmLensUtils._asyncToGenerator(function* (options) {
615
- _this5.begin("folders.update", options);
644
+ var _ref20 = require_CalmLensUtils._asyncToGenerator(function* (options) {
645
+ _this6.begin("folders.update", options);
616
646
  const { folderId } = options, body = require_CalmLensUtils._objectWithoutProperties(options, _excluded6);
617
647
  if (!folderId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder ID is required" });
618
- const folder = yield _this5.resolveFolder(folderId);
648
+ const folder = yield _this6.resolveFolder(folderId);
619
649
  if (!folder) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
620
650
  if (body.name !== void 0 && body.name !== folder.name) {
621
651
  var _folder$parentId;
622
- yield _this5.assertUniqueFolderName(body.name, (_folder$parentId = folder.parentId) !== null && _folder$parentId !== void 0 ? _folder$parentId : null, folderId);
652
+ yield _this6.assertUniqueFolderName(body.name, (_folder$parentId = folder.parentId) !== null && _folder$parentId !== void 0 ? _folder$parentId : null, folderId);
623
653
  }
624
- const updated = require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, folder), body.name !== void 0 ? { name: body.name } : {}), {}, { updatedAt: _this5.now() });
625
- if (_this5.databaseStorage.updateFolder) return yield _this5.databaseStorage.updateFolder(updated);
654
+ const updated = require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, folder), body.name !== void 0 ? { name: body.name } : {}), {}, { updatedAt: _this6.now() });
655
+ if (_this6.databaseStorage.updateFolder) return yield _this6.databaseStorage.updateFolder(updated);
626
656
  return updated;
627
657
  });
628
658
  return function update(_x15) {
629
- return _ref18.apply(this, arguments);
659
+ return _ref20.apply(this, arguments);
630
660
  };
631
661
  }(),
632
662
  delete: function() {
633
- var _ref19 = require_CalmLensUtils._asyncToGenerator(function* (options) {
634
- _this5.begin("folders.delete", options);
663
+ var _ref21 = require_CalmLensUtils._asyncToGenerator(function* (options) {
664
+ _this6.begin("folders.delete", options);
635
665
  const { folderId } = options;
636
666
  if (!folderId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder ID is required" });
637
- if (!(yield _this5.resolveFolder(folderId))) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
638
- const hasAssets = (yield _this5.databaseStorage.listAssets(_this5.options.projectId)).some((asset) => asset.folderId === folderId);
639
- const hasChildren = (_this5.databaseStorage.listFolders ? yield _this5.databaseStorage.listFolders(_this5.options.projectId) : []).some((f) => f.parentId === folderId);
667
+ if (!(yield _this6.resolveFolder(folderId))) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
668
+ const hasAssets = (yield _this6.databaseStorage.listAssets(_this6.options.projectId)).some((asset) => asset.folderId === folderId);
669
+ const hasChildren = (_this6.databaseStorage.listFolders ? yield _this6.databaseStorage.listFolders(_this6.options.projectId) : []).some((f) => f.parentId === folderId);
640
670
  if (hasAssets || hasChildren) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.FOLDER_NOT_EMPTY, { details: {
641
671
  hasAssets,
642
672
  hasChildren
643
673
  } });
644
- if (_this5.databaseStorage.deleteFolder) yield _this5.databaseStorage.deleteFolder(folderId);
674
+ if (_this6.databaseStorage.deleteFolder) yield _this6.databaseStorage.deleteFolder(folderId);
645
675
  });
646
676
  return function _delete(_x16) {
647
- return _ref19.apply(this, arguments);
677
+ return _ref21.apply(this, arguments);
648
678
  };
649
679
  }(),
650
680
  move: function() {
651
- var _ref20 = require_CalmLensUtils._asyncToGenerator(function* (options) {
652
- _this5.begin("folders.move", options);
681
+ var _ref22 = require_CalmLensUtils._asyncToGenerator(function* (options) {
682
+ _this6.begin("folders.move", options);
653
683
  const { folderId, parentId } = options;
654
684
  if (!folderId) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder ID is required" });
655
- const folder = yield _this5.resolveFolder(folderId);
685
+ const folder = yield _this6.resolveFolder(folderId);
656
686
  if (!folder) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
657
687
  const targetParentId = parentId !== null && parentId !== void 0 ? parentId : null;
658
688
  if (targetParentId) {
659
- const parent = yield _this5.resolveFolder(targetParentId);
689
+ const parent = yield _this6.resolveFolder(targetParentId);
660
690
  if (!parent) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
661
691
  let candidate = parent;
662
692
  const visited = /* @__PURE__ */ new Set();
663
693
  while (candidate) {
664
694
  if (candidate.id === folderId || visited.has(candidate.id)) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.FOLDER_PARENT_CYCLE);
665
695
  visited.add(candidate.id);
666
- candidate = candidate.parentId ? yield _this5.resolveFolder(candidate.parentId) : void 0;
696
+ candidate = candidate.parentId ? yield _this6.resolveFolder(candidate.parentId) : void 0;
667
697
  }
668
698
  }
669
- if (targetParentId !== folder.parentId) yield _this5.assertUniqueFolderName(folder.name, targetParentId, folderId);
699
+ if (targetParentId !== folder.parentId) yield _this6.assertUniqueFolderName(folder.name, targetParentId, folderId);
670
700
  const updated = require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, folder), {}, {
671
701
  parentId: targetParentId,
672
- updatedAt: _this5.now()
702
+ updatedAt: _this6.now()
673
703
  });
674
- if (_this5.databaseStorage.updateFolder) return yield _this5.databaseStorage.updateFolder(updated);
704
+ if (_this6.databaseStorage.updateFolder) return yield _this6.databaseStorage.updateFolder(updated);
675
705
  return updated;
676
706
  });
677
707
  return function move(_x17) {
678
- return _ref20.apply(this, arguments);
708
+ return _ref22.apply(this, arguments);
679
709
  };
680
710
  }()
681
711
  };
682
712
  }
683
713
  ensureLens(options) {
684
- var _this6 = this;
714
+ var _this7 = this;
685
715
  return require_CalmLensUtils._asyncToGenerator(function* () {
686
- _this6.begin("ensureLens", options);
687
- return _this6.ensureLensDefinition(options);
716
+ _this7.begin("ensureLens", options);
717
+ return _this7.ensureLensDefinition(options);
688
718
  })();
689
719
  }
690
720
  ensureLensDefinition(options) {
@@ -715,22 +745,22 @@ list: function() {
715
745
  } });
716
746
  }
717
747
  ensureLenses(options) {
718
- var _this7 = this;
748
+ var _this8 = this;
719
749
  return require_CalmLensUtils._asyncToGenerator(function* () {
720
- _this7.begin("ensureLenses", options);
750
+ _this8.begin("ensureLenses", options);
721
751
  if (options.lenses.length === 0) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "At least one lens is required" });
722
- return options.lenses.map((option) => _this7.ensureLensDefinition(option));
752
+ return options.lenses.map((option) => _this8.ensureLensDefinition(option));
723
753
  })();
724
754
  }
725
755
  moderateAsset(options) {
726
- var _this8 = this;
756
+ var _this9 = this;
727
757
  return require_CalmLensUtils._asyncToGenerator(function* () {
728
758
  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" });
729
- return _this8.createAsset(options, _this8.analyzedStatus);
759
+ return _this9.createAsset(options, _this9.analyzedStatus);
730
760
  })();
731
761
  }
732
762
  createAsset(options, status) {
733
- var _this9 = this;
763
+ var _this10 = this;
734
764
  return require_CalmLensUtils._asyncToGenerator(function* () {
735
765
  var _options$folderId, _options$visibility, _options$part$partNum;
736
766
  if (!("content" in options) && !("url" in options) && !("part" in options)) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Either file content, URL, or multipart part is required" });
@@ -752,13 +782,13 @@ list: function() {
752
782
  });
753
783
  if (!validation.ok) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: validation.error });
754
784
  }
755
- const id = _this9.createId();
756
- const now = _this9.now();
785
+ const id = _this10.createId();
786
+ const now = _this10.now();
757
787
  const type = inferAssetType(options);
758
- const sizeInBytes = _this9.getSizeInBytes(options);
788
+ const sizeInBytes = _this10.getSizeInBytes(options);
759
789
  const asset = {
760
790
  id,
761
- projectId: _this9.options.projectId,
791
+ projectId: _this10.options.projectId,
762
792
  folderId: (_options$folderId = options.folderId) !== null && _options$folderId !== void 0 ? _options$folderId : null,
763
793
  createdAt: now,
764
794
  updatedAt: now,
@@ -775,24 +805,24 @@ list: function() {
775
805
  uploadPartsReceived: "part" in options ? (_options$part$partNum = options.part.partNumber) !== null && _options$part$partNum !== void 0 ? _options$part$partNum : 1 : void 0
776
806
  };
777
807
  if ("content" in options) {
778
- if (!("plainText" in options.content)) yield _this9.imageStorage.putContent(id, options.content);
779
- } else if ("part" in options) yield _this9.imageStorage.putPart(id, options.part);
780
- return _this9.databaseStorage.createAsset(asset);
808
+ if (!("plainText" in options.content)) yield _this10.imageStorage.putContent(id, options.content);
809
+ } else if ("part" in options) yield _this10.imageStorage.putPart(id, options.part);
810
+ return _this10.databaseStorage.createAsset(asset);
781
811
  })();
782
812
  }
783
813
  resolveFolder(folderId) {
784
- var _this10 = this;
814
+ var _this11 = this;
785
815
  return require_CalmLensUtils._asyncToGenerator(function* () {
786
- if (!_this10.databaseStorage.getFolder) return void 0;
787
- const folder = yield _this10.databaseStorage.getFolder(folderId);
788
- if (!folder || folder.projectId !== _this10.options.projectId) return;
816
+ if (!_this11.databaseStorage.getFolder) return void 0;
817
+ const folder = yield _this11.databaseStorage.getFolder(folderId);
818
+ if (!folder || folder.projectId !== _this11.options.projectId) return;
789
819
  return folder;
790
820
  })();
791
821
  }
792
822
  assertUniqueFolderName(name, parentId, excludeFolderId) {
793
- var _this11 = this;
823
+ var _this12 = this;
794
824
  return require_CalmLensUtils._asyncToGenerator(function* () {
795
- if ((_this11.databaseStorage.listFolders ? yield _this11.databaseStorage.listFolders(_this11.options.projectId) : []).find((f) => f.id !== excludeFolderId && f.parentId === (parentId !== null && parentId !== void 0 ? parentId : null) && f.name === name)) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.DUPLICATE_FOLDER_NAME, { message: `A folder named "${name}" already exists in this location.` });
825
+ if ((_this12.databaseStorage.listFolders ? yield _this12.databaseStorage.listFolders(_this12.options.projectId) : []).find((f) => f.id !== excludeFolderId && f.parentId === (parentId !== null && parentId !== void 0 ? parentId : null) && f.name === name)) throw require_CalmLensUtils.calmLensError(require_CalmLensUtils.PUBLIC_ERROR_CODES.DUPLICATE_FOLDER_NAME, { message: `A folder named "${name}" already exists in this location.` });
796
826
  })();
797
827
  }
798
828
  getSizeInBytes(options) {
@@ -3542,6 +3542,12 @@ interface RetrieveAssetOptions {
3542
3542
  interface RetryAssetOptions {
3543
3543
  assetId: string;
3544
3544
  }
3545
+ interface DeleteAssetOptions {
3546
+ assetId: string;
3547
+ }
3548
+ interface DeleteAssetContentOptions {
3549
+ assetId: string;
3550
+ }
3545
3551
  type UpdateAssetOptions = PatchAssetBody & {
3546
3552
  assetId: string;
3547
3553
  };
@@ -3624,4 +3630,4 @@ interface ModerateTextOptions extends Omit<SubmitAssetCommonOptions, "name" | "v
3624
3630
  name?: string;
3625
3631
  }
3626
3632
  //#endregion
3627
- 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 };
3633
+ export { GetAssetResponse as A, EventCategory as B, RetryAssetOptions as C, UploadAssetPartOptions as D, UpdateFolderOptions as E, AssetBinaryPayloadInput as F, EventType as G, EventFactValues as H, Lens as I, AssetType as J, Asset as K, Folder as L, GetEventsResponse as M, PostAssetSignedUrlResponse as N, VerifyWebhookSignatureOptions as O, RequestErrorCode as P, Event as R, RetrieveAssetOptions as S, UpdateAssetOptions as T, EventFacts as U, EventFact as V, EventSeverity as W, MetadataItem as X, AssetVisibility as Y, ProcessingOptions as Z, MoveAssetOptions as _, CreateAssetSignedUrlOptions as a, MultipartUploadPartOptions as b, DeleteAssetContentOptions as c, EnsureLensesOptions as d, FolderIdOptions as f, ModerateTextOptions as g, ListEventsOptions as h, CdnServeOptions as i, GetAssetsPageResponse as j, GetAssetChildrenResponse as k, DeleteAssetOptions as l, ListAssetsOptions as m, CalmLensClientOptions as n, CreateFolderOptions as o, ListAssetChildrenOptions as p, AssetStatus as q, CdnAssetUrlOptions as r, CreateMultipartUploadPartOptions as s, AssetContentOptions as t, EnsureLensOptions as u, MoveFolderOptions as v, SubmitAssetOptions as w, RequestOptions as x, MultipartUploadOptions as y, TypedEvent as z };