@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/esm/testing.js CHANGED
@@ -1,4 +1,4 @@
1
- import { b as _objectSpread2, d as isRejectedUploadMimeType, f as PUBLIC_ERROR_CODES, g as getAssetPayloadByteLength, h as assetToData, m as assetDataToUint8Array, n as validateClientOptions, o as calmLensError, p as stringifyJsonCanonical, r as _objectWithoutProperties, t as toTextAssetOptions, u as getRejectedUploadMimeTypeError, v as validateAssetPayload, y as _asyncToGenerator } from "./CalmLensUtils-BZsX8yeO.js";
1
+ import { C as _objectSpread2, S as _asyncToGenerator, _ as assetDataToUint8Array, a as validateClientOptions, 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, t as appendCdnSelector, v as assetToData, x as validateAssetPayload, y as getAssetPayloadByteLength } from "./CalmLensUtils-Bnikzonc.js";
2
2
  import * as zod from "zod";
3
3
  //#region ../shared/src/Permissions.ts
4
4
  const ACTION_SCHEMA = zod.enum([
@@ -211,12 +211,6 @@ var InMemoryMockDatabaseStorage = class {
211
211
  };
212
212
  //#endregion
213
213
  //#region src/testing/MockUtils.ts
214
- const appendCdnSelector = (url, options) => {
215
- if (options.lens && options.transform) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Specify either a lens or a transform, not both" });
216
- if (options.lens) return `${url}/@${encodeURIComponent(options.lens)}`;
217
- if (!options.transform) return url;
218
- return `${url}/${encodeURI(options.transform.replace(/^\/+/, ""))}`;
219
- };
220
214
  const inferAssetType = (options) => {
221
215
  if ("url" in options) return "website";
222
216
  const type = "content" in options ? options.content.type : options.part.type;
@@ -310,6 +304,15 @@ var MockCalmLensClient = class {
310
304
  callsTo(operation) {
311
305
  return this.calls.filter((call) => call.operation === operation);
312
306
  }
307
+ findOwnAsset(assetId) {
308
+ var _this = this;
309
+ return _asyncToGenerator(function* () {
310
+ if (!assetId) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
311
+ const asset = yield _this.databaseStorage.getAsset(assetId);
312
+ if (!asset || asset.projectId !== _this.options.projectId) throw calmLensError(PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
313
+ return asset;
314
+ })();
315
+ }
313
316
  begin(operation, options) {
314
317
  this.calls.push({
315
318
  operation,
@@ -322,32 +325,32 @@ var MockCalmLensClient = class {
322
325
  }
323
326
  }
324
327
  get cdn() {
325
- var _this = this;
328
+ var _this2 = this;
326
329
  return {
327
330
  getAssetUrl: (_ref) => {
328
331
  var _options$resource;
329
332
  let { assetIdentifier } = _ref, options = _objectWithoutProperties(_ref, _excluded);
330
333
  if (!assetIdentifier) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset identifier is required" });
331
334
  const resource = (_options$resource = options.resource) !== null && _options$resource !== void 0 ? _options$resource : "content";
332
- const url = `${this.cdnBaseUrl.replace(/\/$/, "")}/assets/${encodeURIComponent(this.options.projectId)}/${encodeURIComponent(assetIdentifier)}/${resource}`;
335
+ const url = `${this.cdnBaseUrl.replace(/\/$/, "")}/assets/${encodeURIComponent(this.options.projectId)}/${encodePathSegment(assetIdentifier, "Asset identifier")}/${resource}`;
333
336
  return appendCdnSelector(url, options);
334
337
  },
335
338
  serve: function() {
336
339
  var _ref2 = _asyncToGenerator(function* (serveOptions) {
337
340
  var _asset$folderId, _await$this$databaseS, _this$databaseStorage, _this$databaseStorage2, _storedContent$type;
338
- _this.begin("cdn.serve", serveOptions);
341
+ _this2.begin("cdn.serve", serveOptions);
339
342
  const { assetIdentifier } = serveOptions, options = _objectWithoutProperties(serveOptions, _excluded2);
340
343
  if (!assetIdentifier) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset identifier is required" });
341
- const asset = (yield _this.databaseStorage.listAssets(_this.options.projectId)).find((asset) => asset.id === assetIdentifier || asset.externalId === assetIdentifier);
344
+ const asset = (yield _this2.databaseStorage.listAssets(_this2.options.projectId)).find((asset) => asset.id === assetIdentifier || asset.externalId === assetIdentifier);
342
345
  if (!asset) return new Response("Asset not found", { status: 404 });
343
- 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({
346
+ 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({
344
347
  code: "asset/api-key-missing-permission",
345
348
  message: "This API key needs assets:download permission for this asset’s folder."
346
349
  }), {
347
350
  status: 403,
348
351
  headers: { "Content-Type": "application/json" }
349
352
  });
350
- const storedContent = yield _this.imageStorage.getContent(asset.id);
353
+ const storedContent = yield _this2.imageStorage.getContent(asset.id);
351
354
  if (!storedContent) return new Response("Asset content not found", { status: 404 });
352
355
  const parts = [...storedContent.parts.entries()].sort(([left], [right]) => left - right).map(([, value]) => value);
353
356
  const byteLength = parts.reduce((sum, value) => sum + value.byteLength, 0);
@@ -361,7 +364,7 @@ var MockCalmLensClient = class {
361
364
  status: 200,
362
365
  headers: {
363
366
  "Content-Type": (_storedContent$type = storedContent.type) !== null && _storedContent$type !== void 0 ? _storedContent$type : "application/octet-stream",
364
- "X-Mock-CalmLens-CDN-URL": _this.cdn.getAssetUrl(_objectSpread2({ assetIdentifier }, options))
367
+ "X-Mock-CalmLens-CDN-URL": _this2.cdn.getAssetUrl(_objectSpread2({ assetIdentifier }, options))
365
368
  }
366
369
  });
367
370
  });
@@ -372,16 +375,16 @@ var MockCalmLensClient = class {
372
375
  };
373
376
  }
374
377
  get events() {
375
- var _this2 = this;
378
+ var _this3 = this;
376
379
  return {
377
380
  /** The mock does not record events; it always returns an empty page at "now". */
378
381
  list: function() {
379
382
  var _ref3 = _asyncToGenerator(function* (options = {}) {
380
383
  var _options$after;
381
- _this2.begin("events.list", options);
384
+ _this3.begin("events.list", options);
382
385
  return {
383
386
  events: [],
384
- cursor: (_options$after = options.after) !== null && _options$after !== void 0 ? _options$after : `${_this2.now()}_`,
387
+ cursor: (_options$after = options.after) !== null && _options$after !== void 0 ? _options$after : `${_this3.now()}_`,
385
388
  hasMore: false
386
389
  };
387
390
  });
@@ -391,11 +394,11 @@ list: function() {
391
394
  }() };
392
395
  }
393
396
  get text() {
394
- var _this3 = this;
397
+ var _this4 = this;
395
398
  return { moderate: function() {
396
399
  var _ref4 = _asyncToGenerator(function* (options) {
397
- _this3.begin("text.moderate", options);
398
- return _this3.moderateAsset(toTextAssetOptions(options));
400
+ _this4.begin("text.moderate", options);
401
+ return _this4.moderateAsset(toTextAssetOptions(options));
399
402
  });
400
403
  return function moderate(_x2) {
401
404
  return _ref4.apply(this, arguments);
@@ -403,286 +406,313 @@ list: function() {
403
406
  }() };
404
407
  }
405
408
  get assets() {
406
- var _this4 = this;
409
+ var _this5 = this;
407
410
  return {
408
411
  list: function() {
409
- var _ref5 = _asyncToGenerator(function* (options) {
412
+ var _ref5 = _asyncToGenerator(function* (options = {}) {
410
413
  var _options$pageIndex;
411
- _this4.begin("assets.list", options);
412
- const assets = yield _this4.databaseStorage.listAssets(_this4.options.projectId);
414
+ _this5.begin("assets.list", options);
415
+ const assets = yield _this5.databaseStorage.listAssets(_this5.options.projectId);
413
416
  return createPage(assets, _objectSpread2(_objectSpread2({}, options), {}, { pageIndex: (_options$pageIndex = options.pageIndex) !== null && _options$pageIndex !== void 0 ? _options$pageIndex : 0 }));
414
417
  });
415
- return function list(_x3) {
418
+ return function list() {
416
419
  return _ref5.apply(this, arguments);
417
420
  };
418
421
  }(),
419
422
  retrieve: function() {
420
423
  var _ref6 = _asyncToGenerator(function* (options) {
421
- _this4.begin("assets.retrieve", options);
424
+ _this5.begin("assets.retrieve", options);
422
425
  const { assetId } = options;
423
426
  if (!assetId) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
424
- const asset = yield _this4.databaseStorage.getAsset(assetId);
427
+ const asset = yield _this5.databaseStorage.getAsset(assetId);
425
428
  if (!asset) throw calmLensError(PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
426
429
  return asset;
427
430
  });
428
- return function retrieve(_x4) {
431
+ return function retrieve(_x3) {
429
432
  return _ref6.apply(this, arguments);
430
433
  };
431
434
  }(),
432
435
  listChildren: function() {
433
- var _ref7 = _asyncToGenerator(function* (childrenOptions) {
436
+ var _ref7 = _asyncToGenerator(function* (childrenOptions = {}) {
434
437
  var _options$pageIndex2;
435
- _this4.begin("assets.listChildren", childrenOptions);
438
+ _this5.begin("assets.listChildren", childrenOptions);
436
439
  const { assetId } = childrenOptions, options = _objectWithoutProperties(childrenOptions, _excluded3);
437
440
  if (!assetId) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
438
- const assets = yield _this4.databaseStorage.listAssets(_this4.options.projectId);
441
+ const assets = yield _this5.databaseStorage.listAssets(_this5.options.projectId);
439
442
  return createPage(assets.filter((asset) => asset.parentId === assetId), _objectSpread2(_objectSpread2({}, options), {}, { pageIndex: (_options$pageIndex2 = options.pageIndex) !== null && _options$pageIndex2 !== void 0 ? _options$pageIndex2 : 0 }));
440
443
  });
441
- return function listChildren(_x5) {
444
+ return function listChildren() {
442
445
  return _ref7.apply(this, arguments);
443
446
  };
444
447
  }(),
445
448
  update: function() {
446
449
  var _ref8 = _asyncToGenerator(function* (options) {
447
- _this4.begin("assets.update", options);
450
+ _this5.begin("assets.update", options);
448
451
  const { assetId } = options, body = _objectWithoutProperties(options, _excluded4);
449
452
  if (!assetId) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
450
- const asset = yield _this4.databaseStorage.getAsset(assetId);
451
- if (!asset || asset.projectId !== _this4.options.projectId) throw calmLensError(PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
453
+ const asset = yield _this5.databaseStorage.getAsset(assetId);
454
+ if (!asset || asset.projectId !== _this5.options.projectId) throw calmLensError(PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
452
455
  const changes = Object.fromEntries(Object.entries(body).filter(([, value]) => value !== void 0));
453
- return _this4.databaseStorage.updateAsset(_objectSpread2(_objectSpread2(_objectSpread2({}, asset), changes), {}, { updatedAt: _this4.now() }));
456
+ return _this5.databaseStorage.updateAsset(_objectSpread2(_objectSpread2(_objectSpread2({}, asset), changes), {}, { updatedAt: _this5.now() }));
454
457
  });
455
- return function update(_x6) {
458
+ return function update(_x4) {
456
459
  return _ref8.apply(this, arguments);
457
460
  };
458
461
  }(),
459
462
  create: function() {
460
463
  var _ref9 = _asyncToGenerator(function* (options) {
461
- _this4.begin("assets.create", options);
462
- return _this4.createAsset(options, _this4.queuedStatus);
464
+ _this5.begin("assets.create", options);
465
+ return _this5.createAsset(options, _this5.queuedStatus);
463
466
  });
464
- return function create(_x7) {
467
+ return function create(_x5) {
465
468
  return _ref9.apply(this, arguments);
466
469
  };
467
470
  }(),
468
471
  moderate: function() {
469
472
  var _ref10 = _asyncToGenerator(function* (options) {
470
- _this4.begin("assets.moderate", options);
471
- return _this4.moderateAsset(options);
473
+ _this5.begin("assets.moderate", options);
474
+ return _this5.moderateAsset(options);
472
475
  });
473
- return function moderate(_x8) {
476
+ return function moderate(_x6) {
474
477
  return _ref10.apply(this, arguments);
475
478
  };
476
479
  }(),
477
480
  uploadPart: function() {
478
481
  var _ref11 = _asyncToGenerator(function* (options) {
479
482
  var _asset$uploadPartsRec;
480
- _this4.begin("assets.uploadPart", options);
483
+ _this5.begin("assets.uploadPart", options);
481
484
  const { assetId, part } = options;
482
485
  if (!assetId) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
483
486
  if (!part) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Part options are required" });
484
- const asset = yield _this4.databaseStorage.getAsset(assetId);
487
+ const asset = yield _this5.databaseStorage.getAsset(assetId);
485
488
  if (!asset) throw calmLensError(PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
486
489
  const validation = validateAssetPayload(part, {
487
490
  multipart: true,
488
491
  isFinal: part.isFinal
489
492
  });
490
493
  if (!validation.ok) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: validation.error });
491
- yield _this4.imageStorage.putPart(assetId, part);
494
+ yield _this5.imageStorage.putPart(assetId, part);
492
495
  const updated = _objectSpread2(_objectSpread2({}, asset), {}, {
493
- status: part.isFinal ? _this4.queuedStatus : "uploading",
496
+ status: part.isFinal ? _this5.queuedStatus : "uploading",
494
497
  uploadPartsReceived: Math.max((_asset$uploadPartsRec = asset.uploadPartsReceived) !== null && _asset$uploadPartsRec !== void 0 ? _asset$uploadPartsRec : 0, part.partNumber),
495
- updatedAt: _this4.now()
498
+ updatedAt: _this5.now()
496
499
  });
497
- return _this4.databaseStorage.updateAsset(updated);
500
+ return _this5.databaseStorage.updateAsset(updated);
498
501
  });
499
- return function uploadPart(_x9) {
502
+ return function uploadPart(_x7) {
500
503
  return _ref11.apply(this, arguments);
501
504
  };
502
505
  }(),
503
506
  createSignedUrl: function() {
504
507
  var _ref12 = _asyncToGenerator(function* (signedUrlOptions) {
505
508
  var _options$expiresInSec, _options$resource2;
506
- _this4.begin("assets.createSignedUrl", signedUrlOptions);
509
+ _this5.begin("assets.createSignedUrl", signedUrlOptions);
507
510
  const { assetId } = signedUrlOptions, options = _objectWithoutProperties(signedUrlOptions, _excluded5);
508
511
  if (!assetId) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
509
- if (!(yield _this4.databaseStorage.getAsset(assetId))) throw calmLensError(PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
512
+ if (!(yield _this5.databaseStorage.getAsset(assetId))) throw calmLensError(PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
510
513
  const expiresInSeconds = (_options$expiresInSec = options.expiresInSeconds) !== null && _options$expiresInSec !== void 0 ? _options$expiresInSec : 900;
511
514
  const resource = (_options$resource2 = options.resource) !== null && _options$resource2 !== void 0 ? _options$resource2 : "content";
512
515
  if (options.lens && options.transform) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Specify either a lens or a transform, not both" });
513
516
  const selector = options.lens ? `&lens=${encodeURIComponent(options.lens)}` : options.transform ? `&transform=${encodeURIComponent(options.transform)}` : "";
514
517
  return {
515
- url: `${_this4.signedUrlBaseUrl}/assets/${assetId}/${resource}?expiresInSeconds=${expiresInSeconds}${selector}`,
516
- expiresAt: _this4.now() + expiresInSeconds * 1e3
518
+ url: `${_this5.signedUrlBaseUrl}/assets/${assetId}/${resource}?expiresInSeconds=${expiresInSeconds}${selector}`,
519
+ expiresAt: _this5.now() + expiresInSeconds * 1e3
517
520
  };
518
521
  });
519
- return function createSignedUrl(_x10) {
522
+ return function createSignedUrl(_x8) {
520
523
  return _ref12.apply(this, arguments);
521
524
  };
522
525
  }(),
523
526
  move: function() {
524
527
  var _ref13 = _asyncToGenerator(function* (options) {
525
- _this4.begin("assets.move", options);
528
+ _this5.begin("assets.move", options);
526
529
  const { assetId, folderId } = options;
527
530
  if (!assetId) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
528
- const asset = yield _this4.databaseStorage.getAsset(assetId);
529
- if (!asset || asset.projectId !== _this4.options.projectId) throw calmLensError(PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
531
+ const asset = yield _this5.databaseStorage.getAsset(assetId);
532
+ if (!asset || asset.projectId !== _this5.options.projectId) throw calmLensError(PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
530
533
  if (folderId !== null && folderId !== void 0) {
531
- if (!(yield _this4.resolveFolder(folderId))) throw calmLensError(PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
534
+ if (!(yield _this5.resolveFolder(folderId))) throw calmLensError(PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
532
535
  }
533
536
  const updated = _objectSpread2(_objectSpread2({}, asset), {}, {
534
537
  folderId: folderId !== null && folderId !== void 0 ? folderId : null,
535
- updatedAt: _this4.now()
538
+ updatedAt: _this5.now()
536
539
  });
537
- return _this4.databaseStorage.updateAsset(updated);
540
+ return _this5.databaseStorage.updateAsset(updated);
538
541
  });
539
- return function move(_x11) {
542
+ return function move(_x9) {
540
543
  return _ref13.apply(this, arguments);
541
544
  };
542
545
  }(),
543
546
  retry: function() {
544
547
  var _ref14 = _asyncToGenerator(function* (options) {
545
- _this4.begin("assets.retry", options);
548
+ _this5.begin("assets.retry", options);
546
549
  const { assetId } = options;
547
550
  if (!assetId) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset ID is required" });
548
- const asset = yield _this4.databaseStorage.getAsset(assetId);
549
- if (!asset || asset.projectId !== _this4.options.projectId) throw calmLensError(PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
551
+ const asset = yield _this5.databaseStorage.getAsset(assetId);
552
+ if (!asset || asset.projectId !== _this5.options.projectId) throw calmLensError(PUBLIC_ERROR_CODES.ASSET_NOT_FOUND);
550
553
  if (asset.status !== "error") throw calmLensError(PUBLIC_ERROR_CODES.ASSET_NOT_RETRYABLE);
551
- return _this4.databaseStorage.updateAsset(_objectSpread2(_objectSpread2({}, asset), {}, {
554
+ return _this5.databaseStorage.updateAsset(_objectSpread2(_objectSpread2({}, asset), {}, {
552
555
  status: "pending",
553
- updatedAt: _this4.now()
556
+ updatedAt: _this5.now()
554
557
  }));
555
558
  });
556
- return function retry(_x12) {
559
+ return function retry(_x10) {
557
560
  return _ref14.apply(this, arguments);
558
561
  };
562
+ }(),
563
+ deleteContent: function() {
564
+ var _ref15 = _asyncToGenerator(function* (options) {
565
+ var _asset$storageDeleted;
566
+ _this5.begin("assets.deleteContent", options);
567
+ const asset = yield _this5.findOwnAsset(options.assetId);
568
+ yield _this5.imageStorage.deleteContent(asset.id);
569
+ return _this5.databaseStorage.updateAsset(_objectSpread2(_objectSpread2({}, asset), {}, {
570
+ extractedText: null,
571
+ storageDeletedAt: (_asset$storageDeleted = asset.storageDeletedAt) !== null && _asset$storageDeleted !== void 0 ? _asset$storageDeleted : _this5.now(),
572
+ updatedAt: _this5.now()
573
+ }));
574
+ });
575
+ return function deleteContent(_x11) {
576
+ return _ref15.apply(this, arguments);
577
+ };
578
+ }(),
579
+ delete: function() {
580
+ var _ref16 = _asyncToGenerator(function* (options) {
581
+ _this5.begin("assets.delete", options);
582
+ const asset = yield _this5.findOwnAsset(options.assetId);
583
+ yield _this5.imageStorage.deleteContent(asset.id);
584
+ yield _this5.databaseStorage.deleteAsset(asset.id);
585
+ });
586
+ return function _delete(_x12) {
587
+ return _ref16.apply(this, arguments);
588
+ };
559
589
  }()
560
590
  };
561
591
  }
562
592
  get folders() {
563
- var _this5 = this;
593
+ var _this6 = this;
564
594
  return {
565
595
  list: function() {
566
- var _ref15 = _asyncToGenerator(function* () {
567
- _this5.begin("folders.list", void 0);
568
- return [..._this5.databaseStorage.listFolders ? yield _this5.databaseStorage.listFolders(_this5.options.projectId) : []].sort((a, b) => a.name.localeCompare(b.name));
596
+ var _ref17 = _asyncToGenerator(function* () {
597
+ _this6.begin("folders.list", void 0);
598
+ return [..._this6.databaseStorage.listFolders ? yield _this6.databaseStorage.listFolders(_this6.options.projectId) : []].sort((a, b) => a.name.localeCompare(b.name));
569
599
  });
570
600
  return function list() {
571
- return _ref15.apply(this, arguments);
601
+ return _ref17.apply(this, arguments);
572
602
  };
573
603
  }(),
574
604
  retrieve: function() {
575
- var _ref16 = _asyncToGenerator(function* (options) {
576
- _this5.begin("folders.retrieve", options);
605
+ var _ref18 = _asyncToGenerator(function* (options) {
606
+ _this6.begin("folders.retrieve", options);
577
607
  const { folderId } = options;
578
608
  if (!folderId) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder ID is required" });
579
- const folder = yield _this5.resolveFolder(folderId);
609
+ const folder = yield _this6.resolveFolder(folderId);
580
610
  if (!folder) throw calmLensError(PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
581
611
  return folder;
582
612
  });
583
613
  return function retrieve(_x13) {
584
- return _ref16.apply(this, arguments);
614
+ return _ref18.apply(this, arguments);
585
615
  };
586
616
  }(),
587
617
  create: function() {
588
- var _ref17 = _asyncToGenerator(function* (options) {
618
+ var _ref19 = _asyncToGenerator(function* (options) {
589
619
  var _options$parentId, _options$parentId2;
590
- _this5.begin("folders.create", options);
620
+ _this6.begin("folders.create", options);
591
621
  if (!options.name) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder name is required" });
592
622
  if (options.parentId) {
593
- if (!(yield _this5.resolveFolder(options.parentId))) throw calmLensError(PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
623
+ if (!(yield _this6.resolveFolder(options.parentId))) throw calmLensError(PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
594
624
  }
595
- yield _this5.assertUniqueFolderName(options.name, (_options$parentId = options.parentId) !== null && _options$parentId !== void 0 ? _options$parentId : null);
625
+ yield _this6.assertUniqueFolderName(options.name, (_options$parentId = options.parentId) !== null && _options$parentId !== void 0 ? _options$parentId : null);
596
626
  const folder = {
597
- id: _this5.createId(),
598
- projectId: _this5.options.projectId,
627
+ id: _this6.createId(),
628
+ projectId: _this6.options.projectId,
599
629
  parentId: (_options$parentId2 = options.parentId) !== null && _options$parentId2 !== void 0 ? _options$parentId2 : null,
600
630
  name: options.name,
601
- createdAt: _this5.now(),
602
- updatedAt: _this5.now()
631
+ createdAt: _this6.now(),
632
+ updatedAt: _this6.now()
603
633
  };
604
- if (_this5.databaseStorage.createFolder) return yield _this5.databaseStorage.createFolder(folder);
634
+ if (_this6.databaseStorage.createFolder) return yield _this6.databaseStorage.createFolder(folder);
605
635
  return folder;
606
636
  });
607
637
  return function create(_x14) {
608
- return _ref17.apply(this, arguments);
638
+ return _ref19.apply(this, arguments);
609
639
  };
610
640
  }(),
611
641
  update: function() {
612
- var _ref18 = _asyncToGenerator(function* (options) {
613
- _this5.begin("folders.update", options);
642
+ var _ref20 = _asyncToGenerator(function* (options) {
643
+ _this6.begin("folders.update", options);
614
644
  const { folderId } = options, body = _objectWithoutProperties(options, _excluded6);
615
645
  if (!folderId) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder ID is required" });
616
- const folder = yield _this5.resolveFolder(folderId);
646
+ const folder = yield _this6.resolveFolder(folderId);
617
647
  if (!folder) throw calmLensError(PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
618
648
  if (body.name !== void 0 && body.name !== folder.name) {
619
649
  var _folder$parentId;
620
- yield _this5.assertUniqueFolderName(body.name, (_folder$parentId = folder.parentId) !== null && _folder$parentId !== void 0 ? _folder$parentId : null, folderId);
650
+ yield _this6.assertUniqueFolderName(body.name, (_folder$parentId = folder.parentId) !== null && _folder$parentId !== void 0 ? _folder$parentId : null, folderId);
621
651
  }
622
- const updated = _objectSpread2(_objectSpread2(_objectSpread2({}, folder), body.name !== void 0 ? { name: body.name } : {}), {}, { updatedAt: _this5.now() });
623
- if (_this5.databaseStorage.updateFolder) return yield _this5.databaseStorage.updateFolder(updated);
652
+ const updated = _objectSpread2(_objectSpread2(_objectSpread2({}, folder), body.name !== void 0 ? { name: body.name } : {}), {}, { updatedAt: _this6.now() });
653
+ if (_this6.databaseStorage.updateFolder) return yield _this6.databaseStorage.updateFolder(updated);
624
654
  return updated;
625
655
  });
626
656
  return function update(_x15) {
627
- return _ref18.apply(this, arguments);
657
+ return _ref20.apply(this, arguments);
628
658
  };
629
659
  }(),
630
660
  delete: function() {
631
- var _ref19 = _asyncToGenerator(function* (options) {
632
- _this5.begin("folders.delete", options);
661
+ var _ref21 = _asyncToGenerator(function* (options) {
662
+ _this6.begin("folders.delete", options);
633
663
  const { folderId } = options;
634
664
  if (!folderId) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder ID is required" });
635
- if (!(yield _this5.resolveFolder(folderId))) throw calmLensError(PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
636
- const hasAssets = (yield _this5.databaseStorage.listAssets(_this5.options.projectId)).some((asset) => asset.folderId === folderId);
637
- const hasChildren = (_this5.databaseStorage.listFolders ? yield _this5.databaseStorage.listFolders(_this5.options.projectId) : []).some((f) => f.parentId === folderId);
665
+ if (!(yield _this6.resolveFolder(folderId))) throw calmLensError(PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
666
+ const hasAssets = (yield _this6.databaseStorage.listAssets(_this6.options.projectId)).some((asset) => asset.folderId === folderId);
667
+ const hasChildren = (_this6.databaseStorage.listFolders ? yield _this6.databaseStorage.listFolders(_this6.options.projectId) : []).some((f) => f.parentId === folderId);
638
668
  if (hasAssets || hasChildren) throw calmLensError(PUBLIC_ERROR_CODES.FOLDER_NOT_EMPTY, { details: {
639
669
  hasAssets,
640
670
  hasChildren
641
671
  } });
642
- if (_this5.databaseStorage.deleteFolder) yield _this5.databaseStorage.deleteFolder(folderId);
672
+ if (_this6.databaseStorage.deleteFolder) yield _this6.databaseStorage.deleteFolder(folderId);
643
673
  });
644
674
  return function _delete(_x16) {
645
- return _ref19.apply(this, arguments);
675
+ return _ref21.apply(this, arguments);
646
676
  };
647
677
  }(),
648
678
  move: function() {
649
- var _ref20 = _asyncToGenerator(function* (options) {
650
- _this5.begin("folders.move", options);
679
+ var _ref22 = _asyncToGenerator(function* (options) {
680
+ _this6.begin("folders.move", options);
651
681
  const { folderId, parentId } = options;
652
682
  if (!folderId) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Folder ID is required" });
653
- const folder = yield _this5.resolveFolder(folderId);
683
+ const folder = yield _this6.resolveFolder(folderId);
654
684
  if (!folder) throw calmLensError(PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
655
685
  const targetParentId = parentId !== null && parentId !== void 0 ? parentId : null;
656
686
  if (targetParentId) {
657
- const parent = yield _this5.resolveFolder(targetParentId);
687
+ const parent = yield _this6.resolveFolder(targetParentId);
658
688
  if (!parent) throw calmLensError(PUBLIC_ERROR_CODES.FOLDER_NOT_FOUND);
659
689
  let candidate = parent;
660
690
  const visited = /* @__PURE__ */ new Set();
661
691
  while (candidate) {
662
692
  if (candidate.id === folderId || visited.has(candidate.id)) throw calmLensError(PUBLIC_ERROR_CODES.FOLDER_PARENT_CYCLE);
663
693
  visited.add(candidate.id);
664
- candidate = candidate.parentId ? yield _this5.resolveFolder(candidate.parentId) : void 0;
694
+ candidate = candidate.parentId ? yield _this6.resolveFolder(candidate.parentId) : void 0;
665
695
  }
666
696
  }
667
- if (targetParentId !== folder.parentId) yield _this5.assertUniqueFolderName(folder.name, targetParentId, folderId);
697
+ if (targetParentId !== folder.parentId) yield _this6.assertUniqueFolderName(folder.name, targetParentId, folderId);
668
698
  const updated = _objectSpread2(_objectSpread2({}, folder), {}, {
669
699
  parentId: targetParentId,
670
- updatedAt: _this5.now()
700
+ updatedAt: _this6.now()
671
701
  });
672
- if (_this5.databaseStorage.updateFolder) return yield _this5.databaseStorage.updateFolder(updated);
702
+ if (_this6.databaseStorage.updateFolder) return yield _this6.databaseStorage.updateFolder(updated);
673
703
  return updated;
674
704
  });
675
705
  return function move(_x17) {
676
- return _ref20.apply(this, arguments);
706
+ return _ref22.apply(this, arguments);
677
707
  };
678
708
  }()
679
709
  };
680
710
  }
681
711
  ensureLens(options) {
682
- var _this6 = this;
712
+ var _this7 = this;
683
713
  return _asyncToGenerator(function* () {
684
- _this6.begin("ensureLens", options);
685
- return _this6.ensureLensDefinition(options);
714
+ _this7.begin("ensureLens", options);
715
+ return _this7.ensureLensDefinition(options);
686
716
  })();
687
717
  }
688
718
  ensureLensDefinition(options) {
@@ -713,22 +743,22 @@ list: function() {
713
743
  } });
714
744
  }
715
745
  ensureLenses(options) {
716
- var _this7 = this;
746
+ var _this8 = this;
717
747
  return _asyncToGenerator(function* () {
718
- _this7.begin("ensureLenses", options);
748
+ _this8.begin("ensureLenses", options);
719
749
  if (options.lenses.length === 0) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "At least one lens is required" });
720
- return options.lenses.map((option) => _this7.ensureLensDefinition(option));
750
+ return options.lenses.map((option) => _this8.ensureLensDefinition(option));
721
751
  })();
722
752
  }
723
753
  moderateAsset(options) {
724
- var _this8 = this;
754
+ var _this9 = this;
725
755
  return _asyncToGenerator(function* () {
726
756
  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" });
727
- return _this8.createAsset(options, _this8.analyzedStatus);
757
+ return _this9.createAsset(options, _this9.analyzedStatus);
728
758
  })();
729
759
  }
730
760
  createAsset(options, status) {
731
- var _this9 = this;
761
+ var _this10 = this;
732
762
  return _asyncToGenerator(function* () {
733
763
  var _options$folderId, _options$visibility, _options$part$partNum;
734
764
  if (!("content" in options) && !("url" in options) && !("part" in options)) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Either file content, URL, or multipart part is required" });
@@ -750,13 +780,13 @@ list: function() {
750
780
  });
751
781
  if (!validation.ok) throw calmLensError(PUBLIC_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: validation.error });
752
782
  }
753
- const id = _this9.createId();
754
- const now = _this9.now();
783
+ const id = _this10.createId();
784
+ const now = _this10.now();
755
785
  const type = inferAssetType(options);
756
- const sizeInBytes = _this9.getSizeInBytes(options);
786
+ const sizeInBytes = _this10.getSizeInBytes(options);
757
787
  const asset = {
758
788
  id,
759
- projectId: _this9.options.projectId,
789
+ projectId: _this10.options.projectId,
760
790
  folderId: (_options$folderId = options.folderId) !== null && _options$folderId !== void 0 ? _options$folderId : null,
761
791
  createdAt: now,
762
792
  updatedAt: now,
@@ -773,24 +803,24 @@ list: function() {
773
803
  uploadPartsReceived: "part" in options ? (_options$part$partNum = options.part.partNumber) !== null && _options$part$partNum !== void 0 ? _options$part$partNum : 1 : void 0
774
804
  };
775
805
  if ("content" in options) {
776
- if (!("plainText" in options.content)) yield _this9.imageStorage.putContent(id, options.content);
777
- } else if ("part" in options) yield _this9.imageStorage.putPart(id, options.part);
778
- return _this9.databaseStorage.createAsset(asset);
806
+ if (!("plainText" in options.content)) yield _this10.imageStorage.putContent(id, options.content);
807
+ } else if ("part" in options) yield _this10.imageStorage.putPart(id, options.part);
808
+ return _this10.databaseStorage.createAsset(asset);
779
809
  })();
780
810
  }
781
811
  resolveFolder(folderId) {
782
- var _this10 = this;
812
+ var _this11 = this;
783
813
  return _asyncToGenerator(function* () {
784
- if (!_this10.databaseStorage.getFolder) return void 0;
785
- const folder = yield _this10.databaseStorage.getFolder(folderId);
786
- if (!folder || folder.projectId !== _this10.options.projectId) return;
814
+ if (!_this11.databaseStorage.getFolder) return void 0;
815
+ const folder = yield _this11.databaseStorage.getFolder(folderId);
816
+ if (!folder || folder.projectId !== _this11.options.projectId) return;
787
817
  return folder;
788
818
  })();
789
819
  }
790
820
  assertUniqueFolderName(name, parentId, excludeFolderId) {
791
- var _this11 = this;
821
+ var _this12 = this;
792
822
  return _asyncToGenerator(function* () {
793
- 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 calmLensError(PUBLIC_ERROR_CODES.DUPLICATE_FOLDER_NAME, { message: `A folder named "${name}" already exists in this location.` });
823
+ 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 calmLensError(PUBLIC_ERROR_CODES.DUPLICATE_FOLDER_NAME, { message: `A folder named "${name}" already exists in this location.` });
794
824
  })();
795
825
  }
796
826
  getSizeInBytes(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calmlens/sdk",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Censkh/CalmLens.git",
@@ -18,17 +18,13 @@
18
18
  "node": ">=22"
19
19
  },
20
20
  "scripts": {
21
- "generate:fixtures": "bun scripts/generateFixtures.ts",
22
21
  "prepublishOnly": "npm run check && npm run test && npm run build",
23
22
  "test": "bun test --parallel=4 tests",
24
- "example:start": "cd example && npm run start",
25
23
  "check:fix": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check --write",
26
24
  "check": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check",
27
25
  "cleanup": "rimraf esm && rimraf cjs && rimraf bin",
28
26
  "build": "npm run cleanup && rolldown -c rolldown.config.mjs && node scripts/post-build.js && npm run verify:package",
29
- "verify:package": "node scripts/verify-package.mjs",
30
- "website:dev": "cd website && npm run start",
31
- "website:deploy": "cd website && npm run deploy"
27
+ "verify:package": "node scripts/verify-package.mjs"
32
28
  },
33
29
  "keywords": [
34
30
  "typescript",
@@ -51,8 +47,8 @@
51
47
  "devDependencies": {
52
48
  "@biomejs/biome": "^2.5.15",
53
49
  "@oxc-project/runtime": "0.148.0",
54
- "@types/bun": "^1.3.13",
55
- "@types/node": "22.20.2",
50
+ "@types/bun": "^1.4.2",
51
+ "@types/node": "26.6.1",
56
52
  "rimraf": "6.1.3",
57
53
  "rolldown": "1.2.13",
58
54
  "rolldown-plugin-dts": "0.28.7",