@calmlens/sdk 0.8.1 → 0.9.1
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/{CalmLensTypes-B7hr0SBv.d.ts → CalmLensTypes-CZqyni4p.d.ts} +7 -1
- package/cjs/{CalmLensUtils-CJ6o7KRU.js → CalmLensUtils-B6vwJijv.js} +79 -0
- package/cjs/index.d.ts +12 -4
- package/cjs/index.js +93 -49
- package/cjs/testing.d.ts +7 -4
- package/cjs/testing.js +163 -133
- package/esm/{CalmLensTypes-B7hr0SBv.d.ts → CalmLensTypes-CZqyni4p.d.ts} +7 -1
- package/esm/{CalmLensUtils-BZsX8yeO.js → CalmLensUtils-O1xk_Ts0.js} +62 -1
- package/esm/index.d.ts +12 -4
- package/esm/index.js +92 -48
- package/esm/testing.d.ts +7 -4
- package/esm/testing.js +162 -132
- package/package.json +1 -1
|
@@ -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 {
|
|
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 };
|
|
@@ -288,6 +288,26 @@ const PUBLIC_ERROR_CODES = {
|
|
|
288
288
|
defaultMessage: "Multipart upload state is missing",
|
|
289
289
|
status: 409
|
|
290
290
|
}),
|
|
291
|
+
UPLOAD_SIZE_MISMATCH: new sendable_error.ErrorCode({
|
|
292
|
+
id: "upload/size-mismatch",
|
|
293
|
+
defaultMessage: "The uploaded parts do not add up to the totalSizeInBytes declared when the multipart upload started.",
|
|
294
|
+
status: 400
|
|
295
|
+
}),
|
|
296
|
+
INVALID_IDEMPOTENCY_KEY: new sendable_error.ErrorCode({
|
|
297
|
+
id: "idempotency/invalid-key",
|
|
298
|
+
defaultMessage: "The Idempotency-Key header must be 1 to 255 printable ASCII characters, such as a UUID.",
|
|
299
|
+
status: 400
|
|
300
|
+
}),
|
|
301
|
+
IDEMPOTENCY_KEY_REUSED: new sendable_error.ErrorCode({
|
|
302
|
+
id: "idempotency/key-reused",
|
|
303
|
+
defaultMessage: "This Idempotency-Key was already used for a different request. Use a new key for each distinct request.",
|
|
304
|
+
status: 409
|
|
305
|
+
}),
|
|
306
|
+
IDEMPOTENT_REQUEST_IN_PROGRESS: new sendable_error.ErrorCode({
|
|
307
|
+
id: "idempotency/request-in-progress",
|
|
308
|
+
defaultMessage: "A request with this Idempotency-Key is still being processed. Retry after the Retry-After delay to receive its result.",
|
|
309
|
+
status: 409
|
|
310
|
+
}),
|
|
291
311
|
ASSET_NOT_FOUND: new sendable_error.ErrorCode({
|
|
292
312
|
id: "asset/not-found",
|
|
293
313
|
defaultMessage: "Asset not found",
|
|
@@ -434,6 +454,7 @@ const validateClientOptions = (options) => {
|
|
|
434
454
|
if (!options || typeof options !== "object") throw invalidOptions("Client options are required");
|
|
435
455
|
if (!options.apiKey) throw invalidOptions("API key is required");
|
|
436
456
|
if (!options.projectId) throw invalidOptions("Project ID is required");
|
|
457
|
+
encodePathSegment(options.projectId, "Project ID");
|
|
437
458
|
if (options.timeoutMs !== void 0 && (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs <= 0)) throw invalidOptions("timeoutMs must be a positive integer");
|
|
438
459
|
assertHttpUrl("baseUrl", options.baseUrl);
|
|
439
460
|
assertHttpUrl("cdnBaseUrl", options.cdnBaseUrl);
|
|
@@ -449,6 +470,46 @@ const toTextAssetOptions = (_ref) => {
|
|
|
449
470
|
}
|
|
450
471
|
});
|
|
451
472
|
};
|
|
473
|
+
/**
|
|
474
|
+
* Encodes an identifier as one URL path segment. `.` and `..` are rejected because URL
|
|
475
|
+
* resolution would treat them as relative segments and send the request to another route.
|
|
476
|
+
*/
|
|
477
|
+
const encodePathSegment = (value, name) => {
|
|
478
|
+
if (typeof value !== "string" || !value) throw invalidOptions(`${name} is required`);
|
|
479
|
+
if (value === "." || value === "..") throw invalidOptions(`${name} cannot be "." or ".."`);
|
|
480
|
+
return encodeURIComponent(value);
|
|
481
|
+
};
|
|
482
|
+
/** Appends a CDN lens (`/@name`) or direct transform selector to an asset URL. */
|
|
483
|
+
const appendCdnSelector = (url, options) => {
|
|
484
|
+
if (options.lens && options.transform) throw invalidOptions("Specify either a lens or a transform, not both");
|
|
485
|
+
if (options.lens) return `${url}/@${encodePathSegment(options.lens, "Lens")}`;
|
|
486
|
+
if (!options.transform) return url;
|
|
487
|
+
const transform = options.transform.replace(/^\/+/, "");
|
|
488
|
+
if (transform.includes("..") || transform.includes("?") || transform.includes("#")) throw invalidOptions("Transform cannot contain \"..\", \"?\" or \"#\"");
|
|
489
|
+
return `${url}/${encodeURI(transform)}`;
|
|
490
|
+
};
|
|
491
|
+
const appendQueryValue = (parts, key, value) => {
|
|
492
|
+
if (value === void 0 || value === null) return;
|
|
493
|
+
if (Array.isArray(value)) {
|
|
494
|
+
for (const [index, item] of value.entries()) appendQueryValue(parts, `${key}[${index}]`, item);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (typeof value === "object") {
|
|
498
|
+
for (const [field, item] of Object.entries(value)) appendQueryValue(parts, `${key}[${field}]`, item);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* Serialises a query object the way the API parses it (qs bracket notation), for example
|
|
505
|
+
* `ordering[0][field]=createdAt&ordering[0][direction]=DESC`. Every key and value is
|
|
506
|
+
* percent-encoded and missing values are omitted.
|
|
507
|
+
*/
|
|
508
|
+
const stringifyQuery = (query) => {
|
|
509
|
+
const parts = [];
|
|
510
|
+
for (const [key, value] of Object.entries(query)) appendQueryValue(parts, key, value);
|
|
511
|
+
return parts.join("&");
|
|
512
|
+
};
|
|
452
513
|
//#endregion
|
|
453
514
|
Object.defineProperty(exports, "CalmLensError", {
|
|
454
515
|
enumerable: true,
|
|
@@ -510,6 +571,12 @@ Object.defineProperty(exports, "_objectWithoutProperties", {
|
|
|
510
571
|
return _objectWithoutProperties;
|
|
511
572
|
}
|
|
512
573
|
});
|
|
574
|
+
Object.defineProperty(exports, "appendCdnSelector", {
|
|
575
|
+
enumerable: true,
|
|
576
|
+
get: function() {
|
|
577
|
+
return appendCdnSelector;
|
|
578
|
+
}
|
|
579
|
+
});
|
|
513
580
|
Object.defineProperty(exports, "assetDataToUint8Array", {
|
|
514
581
|
enumerable: true,
|
|
515
582
|
get: function() {
|
|
@@ -528,6 +595,12 @@ Object.defineProperty(exports, "calmLensError", {
|
|
|
528
595
|
return calmLensError;
|
|
529
596
|
}
|
|
530
597
|
});
|
|
598
|
+
Object.defineProperty(exports, "encodePathSegment", {
|
|
599
|
+
enumerable: true,
|
|
600
|
+
get: function() {
|
|
601
|
+
return encodePathSegment;
|
|
602
|
+
}
|
|
603
|
+
});
|
|
531
604
|
Object.defineProperty(exports, "getAssetPayloadByteLength", {
|
|
532
605
|
enumerable: true,
|
|
533
606
|
get: function() {
|
|
@@ -558,6 +631,12 @@ Object.defineProperty(exports, "stringifyJsonCanonical", {
|
|
|
558
631
|
return stringifyJsonCanonical;
|
|
559
632
|
}
|
|
560
633
|
});
|
|
634
|
+
Object.defineProperty(exports, "stringifyQuery", {
|
|
635
|
+
enumerable: true,
|
|
636
|
+
get: function() {
|
|
637
|
+
return stringifyQuery;
|
|
638
|
+
}
|
|
639
|
+
});
|
|
561
640
|
Object.defineProperty(exports, "toTextAssetOptions", {
|
|
562
641
|
enumerable: true,
|
|
563
642
|
get: function() {
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
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
|
|
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 }
|
|
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/cjs/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_CalmLensUtils = require("./CalmLensUtils-
|
|
2
|
+
const require_CalmLensUtils = require("./CalmLensUtils-B6vwJijv.js");
|
|
3
3
|
let zod = require("zod");
|
|
4
4
|
zod = require_CalmLensUtils.__toESM(zod);
|
|
5
5
|
require("zod/v4");
|
|
@@ -442,12 +442,6 @@ const prepareSubmitAssetOptions = (options) => {
|
|
|
442
442
|
}
|
|
443
443
|
return options;
|
|
444
444
|
};
|
|
445
|
-
const appendCdnSelector = (url, options) => {
|
|
446
|
-
if (options.lens && options.transform) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Specify either a lens or a transform, not both" });
|
|
447
|
-
if (options.lens) return `${url}/@${encodeURIComponent(options.lens)}`;
|
|
448
|
-
if (!options.transform) return url;
|
|
449
|
-
return `${url}/${encodeURI(options.transform.replace(/^\/+/, ""))}`;
|
|
450
|
-
};
|
|
451
445
|
const getEnsureLensCacheKey = (options) => {
|
|
452
446
|
var _options$description, _options$transforms;
|
|
453
447
|
return require_CalmLensUtils.stringifyJsonCanonical({
|
|
@@ -529,6 +523,7 @@ const createApi = (options) => {
|
|
|
529
523
|
return new api_def.Api({
|
|
530
524
|
name: "Calm Lens",
|
|
531
525
|
baseUrl: options.baseUrl,
|
|
526
|
+
config: { queryHandling: { stringify: require_CalmLensUtils.stringifyQuery } },
|
|
532
527
|
middleware: [
|
|
533
528
|
(0, api_def.RequestCoalescingMiddleware)(),
|
|
534
529
|
{ beforeSend: (context) => {
|
|
@@ -660,12 +655,32 @@ const createEndpoints = (api) => {
|
|
|
660
655
|
method: "post",
|
|
661
656
|
path: "/assets/:assetId/retry"
|
|
662
657
|
});
|
|
658
|
+
const deleteAsset = api.endpoint().paramsOf().responseOf().build({
|
|
659
|
+
id: "deleteAsset",
|
|
660
|
+
method: "delete",
|
|
661
|
+
path: "/assets/:assetId"
|
|
662
|
+
});
|
|
663
|
+
const deleteAssetContent = api.endpoint().paramsOf().responseOf().build({
|
|
664
|
+
id: "deleteAssetContent",
|
|
665
|
+
method: "delete",
|
|
666
|
+
path: "/assets/:assetId/content"
|
|
667
|
+
});
|
|
663
668
|
const getEvents = api.endpoint().paramsOf().queryOf().responseOf().build({
|
|
664
669
|
id: "getEvents",
|
|
665
670
|
method: "get",
|
|
666
671
|
path: "/projects/:projectId/events"
|
|
667
672
|
});
|
|
668
|
-
|
|
673
|
+
const ensureLens = api.endpoint().bodyOf().paramsOf().responseOf().build({
|
|
674
|
+
id: "ensureLens",
|
|
675
|
+
method: "put",
|
|
676
|
+
path: "/lenses/:lensIdentifier"
|
|
677
|
+
});
|
|
678
|
+
const ensureLenses = api.endpoint().bodyOf().paramsOf().responseOf().build({
|
|
679
|
+
id: "ensureLenses",
|
|
680
|
+
method: "put",
|
|
681
|
+
path: "/projects/:projectId/lenses"
|
|
682
|
+
});
|
|
683
|
+
return encodePathParams({
|
|
669
684
|
getFolders,
|
|
670
685
|
getFolder,
|
|
671
686
|
postFolder,
|
|
@@ -682,18 +697,23 @@ const createEndpoints = (api) => {
|
|
|
682
697
|
postAssetPart,
|
|
683
698
|
moveAsset,
|
|
684
699
|
retryAsset,
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
}),
|
|
690
|
-
ensureLenses: api.endpoint().bodyOf().paramsOf().responseOf().build({
|
|
691
|
-
id: "ensureLenses",
|
|
692
|
-
method: "put",
|
|
693
|
-
path: "/projects/:projectId/lenses"
|
|
694
|
-
}),
|
|
700
|
+
deleteAsset,
|
|
701
|
+
deleteAssetContent,
|
|
702
|
+
ensureLens,
|
|
703
|
+
ensureLenses,
|
|
695
704
|
getEvents
|
|
696
|
-
};
|
|
705
|
+
});
|
|
706
|
+
};
|
|
707
|
+
/**
|
|
708
|
+
* api-def inserts `/:param` values into the path verbatim, so every endpoint encodes its path
|
|
709
|
+
* params here: an ID can never add path segments, a query string or a fragment.
|
|
710
|
+
*/
|
|
711
|
+
const encodePathParams = (endpoints) => {
|
|
712
|
+
for (const endpoint of Object.values(endpoints)) {
|
|
713
|
+
const submit = endpoint.submit.bind(endpoint);
|
|
714
|
+
endpoint.submit = (config) => submit(require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, config), {}, { params: config.params && Object.fromEntries(Object.entries(config.params).map(([key, value]) => [key, require_CalmLensUtils.encodePathSegment(value, key)])) }));
|
|
715
|
+
}
|
|
716
|
+
return endpoints;
|
|
697
717
|
};
|
|
698
718
|
var CalmLensClient = class CalmLensClient {
|
|
699
719
|
/**
|
|
@@ -819,7 +839,7 @@ var CalmLensClient = class CalmLensClient {
|
|
|
819
839
|
isFinal: String((_part$isFinal2 = part.isFinal) !== null && _part$isFinal2 !== void 0 ? _part$isFinal2 : false)
|
|
820
840
|
});
|
|
821
841
|
setOptionalQueryValue(query, "sizeInBytes", (_part$sizeInBytes2 = part.sizeInBytes) !== null && _part$sizeInBytes2 !== void 0 ? _part$sizeInBytes2 : require_CalmLensUtils.getAssetPayloadByteLength(part));
|
|
822
|
-
const url = `${_this2.options.baseUrl.replace(/\/$/, "")}/assets/${
|
|
842
|
+
const url = `${_this2.options.baseUrl.replace(/\/$/, "")}/assets/${require_CalmLensUtils.encodePathSegment(assetId, "Asset ID")}/part?${query}`;
|
|
823
843
|
const response = yield _this2.getUploadFetch()(url, {
|
|
824
844
|
method: "POST",
|
|
825
845
|
headers: {
|
|
@@ -894,8 +914,8 @@ var CalmLensClient = class CalmLensClient {
|
|
|
894
914
|
let { assetIdentifier } = _ref4, options = require_CalmLensUtils._objectWithoutProperties(_ref4, _excluded3);
|
|
895
915
|
if (!assetIdentifier) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset identifier is required" });
|
|
896
916
|
const resource = (_options$resource = options.resource) !== null && _options$resource !== void 0 ? _options$resource : "content";
|
|
897
|
-
const url = `${this.options.cdnBaseUrl.replace(/\/$/, "")}/assets/${encodeURIComponent(this.options.projectId)}/${
|
|
898
|
-
return appendCdnSelector(url, options);
|
|
917
|
+
const url = `${this.options.cdnBaseUrl.replace(/\/$/, "")}/assets/${encodeURIComponent(this.options.projectId)}/${require_CalmLensUtils.encodePathSegment(assetIdentifier, "Asset identifier")}/${resource}`;
|
|
918
|
+
return require_CalmLensUtils.appendCdnSelector(url, options);
|
|
899
919
|
},
|
|
900
920
|
/**
|
|
901
921
|
* Fetch asset content or previews from the CDN.
|
|
@@ -946,14 +966,14 @@ var CalmLensClient = class CalmLensClient {
|
|
|
946
966
|
* @returns Promise with paginated assets
|
|
947
967
|
*/
|
|
948
968
|
list: function() {
|
|
949
|
-
var _ref9 = require_CalmLensUtils._asyncToGenerator(function* (options) {
|
|
969
|
+
var _ref9 = require_CalmLensUtils._asyncToGenerator(function* (options = {}) {
|
|
950
970
|
var _options$pageIndex;
|
|
951
971
|
return (yield _this5.endpoints.getAssetsPage.submit({
|
|
952
972
|
params: { projectId: _this5.options.projectId },
|
|
953
973
|
query: require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, options), {}, { pageIndex: (_options$pageIndex = options.pageIndex) !== null && _options$pageIndex !== void 0 ? _options$pageIndex : 0 })
|
|
954
974
|
})).data;
|
|
955
975
|
});
|
|
956
|
-
return function list(
|
|
976
|
+
return function list() {
|
|
957
977
|
return _ref9.apply(this, arguments);
|
|
958
978
|
};
|
|
959
979
|
}(),
|
|
@@ -967,7 +987,7 @@ var CalmLensClient = class CalmLensClient {
|
|
|
967
987
|
if (!assetId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
|
|
968
988
|
return (yield _this5.endpoints.getAsset.submit({ params: { assetId } })).data;
|
|
969
989
|
});
|
|
970
|
-
return function retrieve(
|
|
990
|
+
return function retrieve(_x7) {
|
|
971
991
|
return _ref10.apply(this, arguments);
|
|
972
992
|
};
|
|
973
993
|
}(),
|
|
@@ -980,7 +1000,7 @@ var CalmLensClient = class CalmLensClient {
|
|
|
980
1000
|
body
|
|
981
1001
|
})).data;
|
|
982
1002
|
});
|
|
983
|
-
return function update(
|
|
1003
|
+
return function update(_x8) {
|
|
984
1004
|
return _ref12.apply(this, arguments);
|
|
985
1005
|
};
|
|
986
1006
|
}(),
|
|
@@ -991,7 +1011,7 @@ var CalmLensClient = class CalmLensClient {
|
|
|
991
1011
|
* @returns Promise with paginated child assets
|
|
992
1012
|
*/
|
|
993
1013
|
listChildren: function() {
|
|
994
|
-
var _ref14 = require_CalmLensUtils._asyncToGenerator(function* (_ref13) {
|
|
1014
|
+
var _ref14 = require_CalmLensUtils._asyncToGenerator(function* (_ref13 = {}) {
|
|
995
1015
|
var _options$pageIndex2;
|
|
996
1016
|
let { assetId } = _ref13, options = require_CalmLensUtils._objectWithoutProperties(_ref13, _excluded6);
|
|
997
1017
|
if (!assetId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
|
|
@@ -1000,7 +1020,7 @@ var CalmLensClient = class CalmLensClient {
|
|
|
1000
1020
|
query: require_CalmLensUtils._objectSpread2(require_CalmLensUtils._objectSpread2({}, options), {}, { pageIndex: (_options$pageIndex2 = options.pageIndex) !== null && _options$pageIndex2 !== void 0 ? _options$pageIndex2 : 0 })
|
|
1001
1021
|
})).data;
|
|
1002
1022
|
});
|
|
1003
|
-
return function listChildren(
|
|
1023
|
+
return function listChildren() {
|
|
1004
1024
|
return _ref14.apply(this, arguments);
|
|
1005
1025
|
};
|
|
1006
1026
|
}(),
|
|
@@ -1020,7 +1040,7 @@ var CalmLensClient = class CalmLensClient {
|
|
|
1020
1040
|
query: { queue: true }
|
|
1021
1041
|
})).data;
|
|
1022
1042
|
});
|
|
1023
|
-
return function create(
|
|
1043
|
+
return function create(_x9) {
|
|
1024
1044
|
return _ref15.apply(this, arguments);
|
|
1025
1045
|
};
|
|
1026
1046
|
}(),
|
|
@@ -1042,7 +1062,7 @@ var CalmLensClient = class CalmLensClient {
|
|
|
1042
1062
|
query: { queue: false }
|
|
1043
1063
|
})).data;
|
|
1044
1064
|
});
|
|
1045
|
-
return function moderate(
|
|
1065
|
+
return function moderate(_x10) {
|
|
1046
1066
|
return _ref16.apply(this, arguments);
|
|
1047
1067
|
};
|
|
1048
1068
|
}(),
|
|
@@ -1071,7 +1091,7 @@ var CalmLensClient = class CalmLensClient {
|
|
|
1071
1091
|
}
|
|
1072
1092
|
return yield _this5.submitRawAssetPart(assetId, part, (_this$multipartUpload = _this5.multipartUploadQueues.get(assetId)) !== null && _this$multipartUpload !== void 0 ? _this$multipartUpload : false);
|
|
1073
1093
|
});
|
|
1074
|
-
return function uploadPart(
|
|
1094
|
+
return function uploadPart(_x11) {
|
|
1075
1095
|
return _ref17.apply(this, arguments);
|
|
1076
1096
|
};
|
|
1077
1097
|
}(),
|
|
@@ -1096,7 +1116,7 @@ var CalmLensClient = class CalmLensClient {
|
|
|
1096
1116
|
params: { assetId }
|
|
1097
1117
|
})).data;
|
|
1098
1118
|
});
|
|
1099
|
-
return function createSignedUrl(
|
|
1119
|
+
return function createSignedUrl(_x12) {
|
|
1100
1120
|
return _ref19.apply(this, arguments);
|
|
1101
1121
|
};
|
|
1102
1122
|
}(),
|
|
@@ -1108,7 +1128,7 @@ var CalmLensClient = class CalmLensClient {
|
|
|
1108
1128
|
body: { folderId }
|
|
1109
1129
|
})).data;
|
|
1110
1130
|
});
|
|
1111
|
-
return function move(
|
|
1131
|
+
return function move(_x13) {
|
|
1112
1132
|
return _ref20.apply(this, arguments);
|
|
1113
1133
|
};
|
|
1114
1134
|
}(),
|
|
@@ -1121,9 +1141,33 @@ var CalmLensClient = class CalmLensClient {
|
|
|
1121
1141
|
if (!assetId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
|
|
1122
1142
|
return (yield _this5.endpoints.retryAsset.submit({ params: { assetId } })).data;
|
|
1123
1143
|
});
|
|
1124
|
-
return function retry(
|
|
1144
|
+
return function retry(_x14) {
|
|
1125
1145
|
return _ref21.apply(this, arguments);
|
|
1126
1146
|
};
|
|
1147
|
+
}(),
|
|
1148
|
+
/**
|
|
1149
|
+
* Removes an asset's stored content (source, preview and retained extracted text) while
|
|
1150
|
+
* keeping the asset record, metadata and moderation report. The returned asset has
|
|
1151
|
+
* `storageDeletedAt` set; the CDN no longer serves it.
|
|
1152
|
+
*/
|
|
1153
|
+
deleteContent: function() {
|
|
1154
|
+
var _ref22 = require_CalmLensUtils._asyncToGenerator(function* ({ assetId }) {
|
|
1155
|
+
if (!assetId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
|
|
1156
|
+
return (yield _this5.endpoints.deleteAssetContent.submit({ params: { assetId } })).data;
|
|
1157
|
+
});
|
|
1158
|
+
return function deleteContent(_x15) {
|
|
1159
|
+
return _ref22.apply(this, arguments);
|
|
1160
|
+
};
|
|
1161
|
+
}(),
|
|
1162
|
+
/** Deletes an asset record together with its stored content. */
|
|
1163
|
+
delete: function() {
|
|
1164
|
+
var _ref23 = require_CalmLensUtils._asyncToGenerator(function* ({ assetId }) {
|
|
1165
|
+
if (!assetId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Asset ID is required" });
|
|
1166
|
+
yield _this5.endpoints.deleteAsset.submit({ params: { assetId } });
|
|
1167
|
+
});
|
|
1168
|
+
return function _delete(_x16) {
|
|
1169
|
+
return _ref23.apply(this, arguments);
|
|
1170
|
+
};
|
|
1127
1171
|
}()
|
|
1128
1172
|
};
|
|
1129
1173
|
}
|
|
@@ -1136,14 +1180,14 @@ var CalmLensClient = class CalmLensClient {
|
|
|
1136
1180
|
* reshaped as `{ id, type, createdAt, projectId, data }`.
|
|
1137
1181
|
*/
|
|
1138
1182
|
list: function() {
|
|
1139
|
-
var
|
|
1183
|
+
var _ref24 = require_CalmLensUtils._asyncToGenerator(function* (options = {}) {
|
|
1140
1184
|
return (yield _this6.endpoints.getEvents.submit({
|
|
1141
1185
|
params: { projectId: _this6.options.projectId },
|
|
1142
1186
|
query: options
|
|
1143
1187
|
})).data;
|
|
1144
1188
|
});
|
|
1145
1189
|
return function list() {
|
|
1146
|
-
return
|
|
1190
|
+
return _ref24.apply(this, arguments);
|
|
1147
1191
|
};
|
|
1148
1192
|
}() };
|
|
1149
1193
|
}
|
|
@@ -1151,36 +1195,36 @@ list: function() {
|
|
|
1151
1195
|
var _this7 = this;
|
|
1152
1196
|
return {
|
|
1153
1197
|
list: function() {
|
|
1154
|
-
var
|
|
1198
|
+
var _ref25 = require_CalmLensUtils._asyncToGenerator(function* () {
|
|
1155
1199
|
return (yield _this7.endpoints.getFolders.submit({ params: { projectId: _this7.options.projectId } })).data.folders;
|
|
1156
1200
|
});
|
|
1157
1201
|
return function list() {
|
|
1158
|
-
return
|
|
1202
|
+
return _ref25.apply(this, arguments);
|
|
1159
1203
|
};
|
|
1160
1204
|
}(),
|
|
1161
1205
|
retrieve: function() {
|
|
1162
|
-
var
|
|
1206
|
+
var _ref26 = require_CalmLensUtils._asyncToGenerator(function* ({ folderId }) {
|
|
1163
1207
|
if (!folderId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
|
|
1164
1208
|
return (yield _this7.endpoints.getFolder.submit({ params: { folderId } })).data;
|
|
1165
1209
|
});
|
|
1166
1210
|
return function retrieve(_x17) {
|
|
1167
|
-
return
|
|
1211
|
+
return _ref26.apply(this, arguments);
|
|
1168
1212
|
};
|
|
1169
1213
|
}(),
|
|
1170
1214
|
create: function() {
|
|
1171
|
-
var
|
|
1215
|
+
var _ref27 = require_CalmLensUtils._asyncToGenerator(function* (options) {
|
|
1172
1216
|
return (yield _this7.endpoints.postFolder.submit({
|
|
1173
1217
|
params: { projectId: _this7.options.projectId },
|
|
1174
1218
|
body: options
|
|
1175
1219
|
})).data;
|
|
1176
1220
|
});
|
|
1177
1221
|
return function create(_x18) {
|
|
1178
|
-
return
|
|
1222
|
+
return _ref27.apply(this, arguments);
|
|
1179
1223
|
};
|
|
1180
1224
|
}(),
|
|
1181
1225
|
update: function() {
|
|
1182
|
-
var
|
|
1183
|
-
let { folderId } =
|
|
1226
|
+
var _ref29 = require_CalmLensUtils._asyncToGenerator(function* (_ref28) {
|
|
1227
|
+
let { folderId } = _ref28, body = require_CalmLensUtils._objectWithoutProperties(_ref28, _excluded8);
|
|
1184
1228
|
if (!folderId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
|
|
1185
1229
|
return (yield _this7.endpoints.patchFolder.submit({
|
|
1186
1230
|
params: { folderId },
|
|
@@ -1188,20 +1232,20 @@ list: function() {
|
|
|
1188
1232
|
})).data;
|
|
1189
1233
|
});
|
|
1190
1234
|
return function update(_x19) {
|
|
1191
|
-
return
|
|
1235
|
+
return _ref29.apply(this, arguments);
|
|
1192
1236
|
};
|
|
1193
1237
|
}(),
|
|
1194
1238
|
delete: function() {
|
|
1195
|
-
var
|
|
1239
|
+
var _ref30 = require_CalmLensUtils._asyncToGenerator(function* ({ folderId }) {
|
|
1196
1240
|
if (!folderId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
|
|
1197
1241
|
yield _this7.endpoints.deleteFolder.submit({ params: { folderId } });
|
|
1198
1242
|
});
|
|
1199
1243
|
return function _delete(_x20) {
|
|
1200
|
-
return
|
|
1244
|
+
return _ref30.apply(this, arguments);
|
|
1201
1245
|
};
|
|
1202
1246
|
}(),
|
|
1203
1247
|
move: function() {
|
|
1204
|
-
var
|
|
1248
|
+
var _ref31 = require_CalmLensUtils._asyncToGenerator(function* ({ folderId, parentId }) {
|
|
1205
1249
|
if (!folderId) throw require_CalmLensUtils.calmLensError({ id: "upload/invalid-payload" }, { message: "Folder ID is required" });
|
|
1206
1250
|
return (yield _this7.endpoints.moveFolder.submit({
|
|
1207
1251
|
params: { folderId },
|
|
@@ -1209,7 +1253,7 @@ list: function() {
|
|
|
1209
1253
|
})).data;
|
|
1210
1254
|
});
|
|
1211
1255
|
return function move(_x21) {
|
|
1212
|
-
return
|
|
1256
|
+
return _ref31.apply(this, arguments);
|
|
1213
1257
|
};
|
|
1214
1258
|
}()
|
|
1215
1259
|
};
|
package/cjs/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
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
|
|
162
|
+
list: (options?: ListAssetsOptions) => Promise<GetAssetsPageResponse>;
|
|
162
163
|
retrieve: (options: RetrieveAssetOptions) => Promise<GetAssetResponse>;
|
|
163
|
-
listChildren: (childrenOptions
|
|
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[]>;
|