@calmlens/sdk 0.10.0 → 0.11.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/README.md +1 -1
- package/cjs/{CalmLensTypes-BfweJTMS.d.ts → CalmLensTypes-BZ-nxhr_.d.ts} +32 -3
- package/cjs/{CalmLensWebhooks-DJnaLpRy.js → CalmLensWebhooks-CH2PaPs0.js} +44 -1
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +13 -4
- package/cjs/testing.d.ts +1 -1
- package/cjs/testing.js +3 -2
- package/esm/{CalmLensTypes-BfweJTMS.d.ts → CalmLensTypes-BZ-nxhr_.d.ts} +32 -3
- package/esm/{CalmLensWebhooks-DLUozliX.js → CalmLensWebhooks-3Otbubyf.js} +39 -2
- package/esm/index.d.ts +2 -2
- package/esm/index.js +13 -4
- package/esm/testing.d.ts +1 -1
- package/esm/testing.js +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -195,7 +195,7 @@ For several lenses, use `ensureLenses()` to perform all ensures in one request.
|
|
|
195
195
|
const [normal, uhd] = await client.ensureLenses({ lenses: [normalLens, uhdLens] });
|
|
196
196
|
```
|
|
197
197
|
|
|
198
|
-
The CDN uses named lenses with an `@` prefix in URLs, such as `/content/@picmagic-normal`. The SDK adds it automatically when you supply `lens`. Use `transform` for one-off direct transforms, for example `client.cdn.serve({ assetIdentifier: assetId, transform: "imageTransform[format=png,width=1024]"
|
|
198
|
+
The CDN uses named lenses with an `@` prefix in URLs, such as `/content/@picmagic-normal`. The SDK adds it automatically when you supply `lens`. Use `transform` for one-off direct transforms, either as structured steps, for example `client.cdn.serve({ assetIdentifier: assetId, transform: { type: "imageTransform", options: { format: "png", width: 1024 } } })`, or as a selector string such as `"imageTransform[format=png,width=1024]"`. Pass an array of steps to chain transforms. `assets.createSignedUrl` accepts the same forms. Supply either `lens` or `transform`, not both. The resolved lens version is part of CalmLens's CDN cache and ETag identity, so changing a lens with the next version invalidates prior derived output.
|
|
199
199
|
|
|
200
200
|
##### assets.list(options)
|
|
201
201
|
|
|
@@ -4997,6 +4997,8 @@ interface EventFieldInfo {
|
|
|
4997
4997
|
display: EventFieldDisplay;
|
|
4998
4998
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
4999
4999
|
hidden?: boolean;
|
|
5000
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5001
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5000
5002
|
}
|
|
5001
5003
|
interface EventFieldDefinition<TSchema extends zod.ZodType = zod.ZodType> extends EventFieldInfo {
|
|
5002
5004
|
schema: TSchema;
|
|
@@ -5036,6 +5038,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5036
5038
|
display: EventFieldDisplay;
|
|
5037
5039
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5038
5040
|
hidden?: boolean;
|
|
5041
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5042
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5039
5043
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5040
5044
|
key: string;
|
|
5041
5045
|
}[];
|
|
@@ -5099,6 +5103,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5099
5103
|
display: EventFieldDisplay;
|
|
5100
5104
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5101
5105
|
hidden?: boolean;
|
|
5106
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5107
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5102
5108
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5103
5109
|
key: string;
|
|
5104
5110
|
}[];
|
|
@@ -5168,6 +5174,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5168
5174
|
display: EventFieldDisplay;
|
|
5169
5175
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5170
5176
|
hidden?: boolean;
|
|
5177
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5178
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5171
5179
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5172
5180
|
key: string;
|
|
5173
5181
|
}[];
|
|
@@ -5228,6 +5236,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5228
5236
|
display: EventFieldDisplay;
|
|
5229
5237
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5230
5238
|
hidden?: boolean;
|
|
5239
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5240
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5231
5241
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5232
5242
|
key: string;
|
|
5233
5243
|
}[];
|
|
@@ -5284,6 +5294,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5284
5294
|
display: EventFieldDisplay;
|
|
5285
5295
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5286
5296
|
hidden?: boolean;
|
|
5297
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5298
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5287
5299
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5288
5300
|
key: string;
|
|
5289
5301
|
}[];
|
|
@@ -5342,6 +5354,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5342
5354
|
display: EventFieldDisplay;
|
|
5343
5355
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5344
5356
|
hidden?: boolean;
|
|
5357
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5358
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5345
5359
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5346
5360
|
key: string;
|
|
5347
5361
|
}[];
|
|
@@ -5390,6 +5404,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5390
5404
|
display: EventFieldDisplay;
|
|
5391
5405
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5392
5406
|
hidden?: boolean;
|
|
5407
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5408
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5393
5409
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5394
5410
|
key: string;
|
|
5395
5411
|
}[];
|
|
@@ -5431,6 +5447,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5431
5447
|
display: EventFieldDisplay;
|
|
5432
5448
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5433
5449
|
hidden?: boolean;
|
|
5450
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5451
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5434
5452
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5435
5453
|
key: string;
|
|
5436
5454
|
}[];
|
|
@@ -5475,6 +5493,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5475
5493
|
display: EventFieldDisplay;
|
|
5476
5494
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5477
5495
|
hidden?: boolean;
|
|
5496
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5497
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5478
5498
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5479
5499
|
key: string;
|
|
5480
5500
|
}[];
|
|
@@ -5516,6 +5536,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5516
5536
|
display: EventFieldDisplay;
|
|
5517
5537
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5518
5538
|
hidden?: boolean;
|
|
5539
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5540
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5519
5541
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5520
5542
|
key: string;
|
|
5521
5543
|
}[];
|
|
@@ -5569,6 +5591,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5569
5591
|
display: EventFieldDisplay;
|
|
5570
5592
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5571
5593
|
hidden?: boolean;
|
|
5594
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5595
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5572
5596
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5573
5597
|
key: string;
|
|
5574
5598
|
}[];
|
|
@@ -8383,6 +8407,11 @@ type LensTransform = {
|
|
|
8383
8407
|
type: string;
|
|
8384
8408
|
options: unknown;
|
|
8385
8409
|
};
|
|
8410
|
+
/**
|
|
8411
|
+
* A CDN transform: a selector string such as `imageTransform[format=png,width=1024]`, or one
|
|
8412
|
+
* or more structured steps such as `{ type: "imageTransform", options: { format: "png" } }`.
|
|
8413
|
+
*/
|
|
8414
|
+
type CdnTransform = string | LensTransform | LensTransform[];
|
|
8386
8415
|
/** A named, versioned CDN transformation. */
|
|
8387
8416
|
type Lens = Omit<zod.infer<typeof LENS_SCHEMA>, "transforms"> & {
|
|
8388
8417
|
transforms?: LensTransform[] | null;
|
|
@@ -8443,7 +8472,7 @@ interface CdnAssetUrlOptions {
|
|
|
8443
8472
|
assetIdentifier: string;
|
|
8444
8473
|
resource?: "content" | "preview";
|
|
8445
8474
|
lens?: string;
|
|
8446
|
-
transform?:
|
|
8475
|
+
transform?: CdnTransform;
|
|
8447
8476
|
}
|
|
8448
8477
|
interface CdnServeOptions extends CdnAssetUrlOptions {
|
|
8449
8478
|
init?: RequestInit;
|
|
@@ -8452,7 +8481,7 @@ interface CreateAssetSignedUrlOptions {
|
|
|
8452
8481
|
assetId: string;
|
|
8453
8482
|
resource?: "content" | "preview";
|
|
8454
8483
|
lens?: string;
|
|
8455
|
-
transform?:
|
|
8484
|
+
transform?: CdnTransform;
|
|
8456
8485
|
expiresInSeconds?: number;
|
|
8457
8486
|
}
|
|
8458
8487
|
type EnsureLensOptions = Pick<Lens, "identifier" | "name" | "description" | "type" | "active" | "transforms" | "version">;
|
|
@@ -8581,4 +8610,4 @@ interface ModerateTextOptions extends Omit<SubmitAssetCommonOptions, "name" | "v
|
|
|
8581
8610
|
name?: string;
|
|
8582
8611
|
}
|
|
8583
8612
|
//#endregion
|
|
8584
|
-
export {
|
|
8613
|
+
export { TypedEvent as $, ListEventsOptions as A, UpdateAssetOptions as B, ImageTransformOptions as C, LensTransform as D, Lens as E, MultipartUploadPartOptions as F, WebhookPayloadInput as G, UploadAssetPartOptions as H, RequestOptions as I, GetEventsResponse as J, AssetSearchQuery as K, RetrieveAssetOptions as L, MoveAssetOptions as M, MoveFolderOptions as N, ListAssetChildrenOptions as O, MultipartUploadOptions as P, Event as Q, RetryAssetOptions as R, IdempotencyOptions as S, IterateAssetsOptions as T, VerifyWebhookSignatureOptions as U, UpdateFolderOptions as V, WebhookHeadersInput as W, AssetBinaryPayloadInput as X, PostAssetSignedUrlResponse as Y, Folder as Z, DeleteAssetContentOptions as _, AssetSearchResponse as a, EventType as at, EnsureLensesOptions as b, AssetType as c, ClassificationReport as ct, CdnAssetUrlOptions as d, EventCategory as et, CdnServeOptions as f, CreateMultipartUploadPartOptions as g, CreateFolderOptions as h, AssetPage as i, EventSeverity as it, ModerateTextOptions as j, ListAssetsOptions as k, AssetVisibility as l, MetadataItem as lt, CreateAssetSignedUrlOptions as m, AssetChildrenPage as n, EventFactValues as nt, AssetSearchResult as o, ClassificationCategory as ot, CdnTransform as p, WebhookEventPayload as q, AssetContentOptions as r, EventFacts as rt, AssetStatus as s, ClassificationCategoryReport as st, Asset as t, EventFact as tt, CalmLensClientOptions as u, ProcessingOptions as ut, DeleteAssetOptions as v, IterateAssetChildrenOptions as w, FolderIdOptions as x, EnsureLensOptions as y, SubmitAssetOptions as z };
|
|
@@ -428,14 +428,51 @@ const encodePathSegment = (value, name) => {
|
|
|
428
428
|
if (value === "." || value === "..") throw invalidArgument(`${name} cannot be "." or ".."`);
|
|
429
429
|
return encodeURIComponent(value);
|
|
430
430
|
};
|
|
431
|
+
const TRANSFORM_TYPE_PATTERN = /^[A-Za-z0-9_]+$/;
|
|
432
|
+
/** Percent-encodes everything except RFC 3986 unreserved characters (`A-Z a-z 0-9 - . _ ~`). */
|
|
433
|
+
const encodeTransformComponent = (value) => encodeURIComponent(value).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
434
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
435
|
+
const appendTransformOptions = (pairs, key, value) => {
|
|
436
|
+
if (value === void 0 || value === null) return;
|
|
437
|
+
if (isPlainObject(value)) {
|
|
438
|
+
for (const child of Object.keys(value).sort()) appendTransformOptions(pairs, `${key}[${child}]`, value[child]);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
let text;
|
|
442
|
+
if (typeof value === "string") text = value;
|
|
443
|
+
else if (typeof value === "boolean") text = String(value);
|
|
444
|
+
else if (typeof value === "number" && Number.isFinite(value)) text = String(value);
|
|
445
|
+
else throw invalidArgument(`Transform option "${key}" must be a string, number, boolean or object`);
|
|
446
|
+
pairs.push(`${encodeTransformComponent(key)}=${encodeTransformComponent(text)}`);
|
|
447
|
+
};
|
|
448
|
+
/**
|
|
449
|
+
* Serializes structured transforms as a CDN selector, such as
|
|
450
|
+
* `imageTransform[format=png,width=1024]`. Option keys are sorted so equal transforms share a
|
|
451
|
+
* URL; nested keys (`border[color]`) and values are percent-encoded.
|
|
452
|
+
*/
|
|
453
|
+
const serializeTransform = (transform) => {
|
|
454
|
+
const steps = Array.isArray(transform) ? transform : [transform];
|
|
455
|
+
if (steps.length === 0) throw invalidArgument("Transform needs at least one step");
|
|
456
|
+
return steps.map((step) => {
|
|
457
|
+
if (!isPlainObject(step)) throw invalidArgument("Transform steps must be objects");
|
|
458
|
+
if (typeof step.type !== "string" || !TRANSFORM_TYPE_PATTERN.test(step.type)) throw invalidArgument("Transform type must contain only letters, digits and underscores");
|
|
459
|
+
if (step.options !== void 0 && step.options !== null && !isPlainObject(step.options)) throw invalidArgument("Transform options must be an object");
|
|
460
|
+
const pairs = [];
|
|
461
|
+
for (const key of Object.keys(step.options ?? {}).sort()) appendTransformOptions(pairs, key, step.options[key]);
|
|
462
|
+
return `${step.type}[${pairs.join(",")}]`;
|
|
463
|
+
}).join(",");
|
|
464
|
+
};
|
|
465
|
+
/** Returns the selector string the API and CDN accept for a string or structured transform. */
|
|
466
|
+
const transformSelector = (transform) => transform === void 0 || typeof transform === "string" ? transform : serializeTransform(transform);
|
|
431
467
|
/** Appends a CDN lens (`/@name`) or direct transform selector to an asset URL. */
|
|
432
468
|
const appendCdnSelector = (url, options) => {
|
|
433
469
|
if (options.lens && options.transform) throw invalidArgument("Specify either a lens or a transform, not both");
|
|
434
470
|
if (options.lens) return `${url}/@${encodePathSegment(options.lens, "Lens")}`;
|
|
435
471
|
if (!options.transform) return url;
|
|
472
|
+
if (typeof options.transform !== "string") return `${url}/${serializeTransform(options.transform)}`;
|
|
436
473
|
const transform = options.transform.replace(/^\/+/, "");
|
|
437
474
|
if (transform.includes("..") || transform.includes("?") || transform.includes("#")) throw invalidArgument("Transform cannot contain \"..\", \"?\" or \"#\"");
|
|
438
|
-
return `${url}/${encodeURI(transform)}`;
|
|
475
|
+
return `${url}/${encodeURI(transform).replace(/%5B/g, "[").replace(/%5D/g, "]")}`;
|
|
439
476
|
};
|
|
440
477
|
const appendQueryValue = (parts, key, value) => {
|
|
441
478
|
if (value === void 0 || value === null) return;
|
|
@@ -715,6 +752,12 @@ Object.defineProperty(exports, "toTextAssetOptions", {
|
|
|
715
752
|
return toTextAssetOptions;
|
|
716
753
|
}
|
|
717
754
|
});
|
|
755
|
+
Object.defineProperty(exports, "transformSelector", {
|
|
756
|
+
enumerable: true,
|
|
757
|
+
get: function() {
|
|
758
|
+
return transformSelector;
|
|
759
|
+
}
|
|
760
|
+
});
|
|
718
761
|
Object.defineProperty(exports, "validateAssetPayload", {
|
|
719
762
|
enumerable: true,
|
|
720
763
|
get: function() {
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as TypedEvent, A as ListEventsOptions, B as UpdateAssetOptions, C as ImageTransformOptions, D as LensTransform, E as Lens, F as MultipartUploadPartOptions, G as WebhookPayloadInput, H as UploadAssetPartOptions, I as RequestOptions, J as GetEventsResponse, K as AssetSearchQuery, L as RetrieveAssetOptions, M as MoveAssetOptions, N as MoveFolderOptions, O as ListAssetChildrenOptions, P as MultipartUploadOptions, R as RetryAssetOptions, S as IdempotencyOptions, T as IterateAssetsOptions, U as VerifyWebhookSignatureOptions, V as UpdateFolderOptions, W as WebhookHeadersInput, Y as PostAssetSignedUrlResponse, Z as Folder, _ as DeleteAssetContentOptions, a as AssetSearchResponse, at as EventType, b as EnsureLensesOptions, c as AssetType, ct as ClassificationReport, d as CdnAssetUrlOptions, et as EventCategory, f as CdnServeOptions, g as CreateMultipartUploadPartOptions, h as CreateFolderOptions, i as AssetPage, it as EventSeverity, j as ModerateTextOptions, k as ListAssetsOptions, l as AssetVisibility, lt as MetadataItem, m as CreateAssetSignedUrlOptions, n as AssetChildrenPage, nt as EventFactValues, o as AssetSearchResult, p as CdnTransform, q as WebhookEventPayload, r as AssetContentOptions, rt as EventFacts, s as AssetStatus, st as ClassificationCategoryReport, t as Asset, tt as EventFact, u as CalmLensClientOptions, ut as ProcessingOptions, v as DeleteAssetOptions, w as IterateAssetChildrenOptions, x as FolderIdOptions, y as EnsureLensOptions, z as SubmitAssetOptions } from "./CalmLensTypes-BZ-nxhr_.js";
|
|
2
2
|
//#region src/client/CalmLensClient.d.ts
|
|
3
3
|
interface ClientState {
|
|
4
4
|
readonly options: Omit<CalmLensClientOptions, "apiKey"> & {
|
|
@@ -379,4 +379,4 @@ export declare function verifyWebhookSignature(options: VerifyWebhookSignatureOp
|
|
|
379
379
|
*/
|
|
380
380
|
export declare function parseWebhookEvent(options: VerifyWebhookSignatureOptions): Promise<WebhookEventPayload>;
|
|
381
381
|
//#endregion
|
|
382
|
-
export { type ApiErrorCode, type Asset, type AssetChildrenPage, type AssetContentOptions, type AssetPage, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetStatus, type AssetType, type AssetVisibility, CalmLensClient, type CalmLensClientOptions, type CalmLensErrorCode, type CalmLensErrorDetails, type CalmLensErrorOptions, 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 IdempotencyOptions, type ImageTransformOptions, type IterateAssetChildrenOptions, type IterateAssetsOptions, type Lens, type LensTransform, 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 SdkErrorCode, type SubmitAssetOptions, type TypedEvent, type UpdateAssetOptions, type UpdateFolderOptions, type UploadAssetPartOptions, type VerifyWebhookSignatureOptions, type WebhookEventPayload, type WebhookHeadersInput, type WebhookPayloadInput };
|
|
382
|
+
export { type ApiErrorCode, type Asset, type AssetChildrenPage, type AssetContentOptions, type AssetPage, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetStatus, type AssetType, type AssetVisibility, CalmLensClient, type CalmLensClientOptions, type CalmLensErrorCode, type CalmLensErrorDetails, type CalmLensErrorOptions, type CdnAssetUrlOptions, type CdnServeOptions, type CdnTransform, 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 IdempotencyOptions, type ImageTransformOptions, type IterateAssetChildrenOptions, type IterateAssetsOptions, type Lens, type LensTransform, 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 SdkErrorCode, type SubmitAssetOptions, type TypedEvent, type UpdateAssetOptions, type UpdateFolderOptions, type UploadAssetPartOptions, type VerifyWebhookSignatureOptions, type WebhookEventPayload, type WebhookHeadersInput, type WebhookPayloadInput };
|
package/cjs/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_CalmLensWebhooks = require("./CalmLensWebhooks-
|
|
2
|
+
const require_CalmLensWebhooks = require("./CalmLensWebhooks-CH2PaPs0.js");
|
|
3
3
|
//#endregion
|
|
4
4
|
//#region src/client/CalmLensVersion.ts
|
|
5
5
|
/** This SDK's version, from its package.json. */
|
|
6
|
-
const SDK_VERSION = "0.
|
|
6
|
+
const SDK_VERSION = "0.11.0";
|
|
7
7
|
const runtimeName = () => {
|
|
8
8
|
const runtime = globalThis;
|
|
9
9
|
if (runtime.Bun?.version) return `bun/${runtime.Bun.version}`;
|
|
@@ -72,6 +72,11 @@ const createAttemptSignal = (signals, timeoutMs) => {
|
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* A redirect the SDK must not follow: it would send the API key to another origin. Browsers report
|
|
77
|
+
* a manual redirect as an opaque response; other runtimes return the 3xx with its Location.
|
|
78
|
+
*/
|
|
79
|
+
const isRedirect = (response) => response.type === "opaqueredirect" || response.status >= 300 && response.status < 400 && response.headers.has("location");
|
|
75
80
|
/** Turns anything thrown while sending or reading a request into a `CalmLensError`. */
|
|
76
81
|
const toFailure = (cause, attempt) => {
|
|
77
82
|
if (require_CalmLensWebhooks.CalmLensError.isCalmLensError(cause)) return cause;
|
|
@@ -220,10 +225,14 @@ var CalmLensTransport = class {
|
|
|
220
225
|
method: request.method,
|
|
221
226
|
headers,
|
|
222
227
|
body: request.body,
|
|
223
|
-
redirect: "
|
|
228
|
+
redirect: "manual",
|
|
224
229
|
signal: attempt.signal,
|
|
225
230
|
duplex: "half"
|
|
226
231
|
});
|
|
232
|
+
if (isRedirect(response)) {
|
|
233
|
+
await response.body?.cancel().catch(() => {});
|
|
234
|
+
throw new require_CalmLensWebhooks.CalmLensError(require_CalmLensWebhooks.SDK_ERROR_CODES.TRANSPORT_ERROR, { message: `Unexpected redirect (HTTP ${response.status})` });
|
|
235
|
+
}
|
|
227
236
|
} catch (cause) {
|
|
228
237
|
attempt.release();
|
|
229
238
|
const failure = toFailure(cause, attempt);
|
|
@@ -668,7 +677,7 @@ moderate: async (options) => this.assets.moderate(require_CalmLensWebhooks.toTex
|
|
|
668
677
|
resource: options.resource ?? "content",
|
|
669
678
|
expiresInSeconds: options.expiresInSeconds ?? 900,
|
|
670
679
|
lens: options.lens,
|
|
671
|
-
transform: options.transform
|
|
680
|
+
transform: require_CalmLensWebhooks.transformSelector(options.transform)
|
|
672
681
|
} });
|
|
673
682
|
},
|
|
674
683
|
/** Moves an asset into a folder, or to the project root with `folderId: null`. */
|
package/cjs/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as TypedEvent, A as ListEventsOptions, B as UpdateAssetOptions, E as Lens, H as UploadAssetPartOptions, J as GetEventsResponse, K as AssetSearchQuery, L as RetrieveAssetOptions, M as MoveAssetOptions, N as MoveFolderOptions, O as ListAssetChildrenOptions, Q as Event, R as RetryAssetOptions, T as IterateAssetsOptions, V as UpdateFolderOptions, X as AssetBinaryPayloadInput, Y as PostAssetSignedUrlResponse, Z as Folder, _ as DeleteAssetContentOptions, a as AssetSearchResponse, b as EnsureLensesOptions, d as CdnAssetUrlOptions, f as CdnServeOptions, h as CreateFolderOptions, i as AssetPage, j as ModerateTextOptions, k as ListAssetsOptions, m as CreateAssetSignedUrlOptions, n as AssetChildrenPage, ot as ClassificationCategory, q as WebhookEventPayload, s as AssetStatus, t as Asset, u as CalmLensClientOptions, v as DeleteAssetOptions, w as IterateAssetChildrenOptions, x as FolderIdOptions, y as EnsureLensOptions, z as SubmitAssetOptions } from "./CalmLensTypes-BZ-nxhr_.js";
|
|
2
2
|
import * as zod from "zod";
|
|
3
3
|
//#region ../shared/src/TestTriggers.d.ts
|
|
4
4
|
type ClassificationTestSignal = ClassificationCategory | "sexual.involving-minors" | "violence.graphic";
|
package/cjs/testing.js
CHANGED
|
@@ -21,7 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
//#endregion
|
|
24
|
-
const require_CalmLensWebhooks = require("./CalmLensWebhooks-
|
|
24
|
+
const require_CalmLensWebhooks = require("./CalmLensWebhooks-CH2PaPs0.js");
|
|
25
25
|
let zod = require("zod");
|
|
26
26
|
zod = __toESM(zod);
|
|
27
27
|
require("zod/v4");
|
|
@@ -936,7 +936,8 @@ var MockCalmLensClient = class {
|
|
|
936
936
|
if (options.lens && options.transform) throw require_CalmLensWebhooks.invalidArgument("Specify either a lens or a transform, not both");
|
|
937
937
|
const expiresInSeconds = options.expiresInSeconds ?? 900;
|
|
938
938
|
const resource = options.resource ?? "content";
|
|
939
|
-
const
|
|
939
|
+
const transform = require_CalmLensWebhooks.transformSelector(options.transform);
|
|
940
|
+
const selector = options.lens ? `&lens=${encodeURIComponent(options.lens)}` : transform ? `&transform=${encodeURIComponent(transform)}` : "";
|
|
940
941
|
return {
|
|
941
942
|
url: `${this.signedUrlBaseUrl}/assets/${asset.id}/${resource}?expiresInSeconds=${expiresInSeconds}${selector}`,
|
|
942
943
|
expiresAt: this.now() + expiresInSeconds * 1e3
|
|
@@ -4997,6 +4997,8 @@ interface EventFieldInfo {
|
|
|
4997
4997
|
display: EventFieldDisplay;
|
|
4998
4998
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
4999
4999
|
hidden?: boolean;
|
|
5000
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5001
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5000
5002
|
}
|
|
5001
5003
|
interface EventFieldDefinition<TSchema extends zod.ZodType = zod.ZodType> extends EventFieldInfo {
|
|
5002
5004
|
schema: TSchema;
|
|
@@ -5036,6 +5038,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5036
5038
|
display: EventFieldDisplay;
|
|
5037
5039
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5038
5040
|
hidden?: boolean;
|
|
5041
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5042
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5039
5043
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5040
5044
|
key: string;
|
|
5041
5045
|
}[];
|
|
@@ -5099,6 +5103,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5099
5103
|
display: EventFieldDisplay;
|
|
5100
5104
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5101
5105
|
hidden?: boolean;
|
|
5106
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5107
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5102
5108
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5103
5109
|
key: string;
|
|
5104
5110
|
}[];
|
|
@@ -5168,6 +5174,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5168
5174
|
display: EventFieldDisplay;
|
|
5169
5175
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5170
5176
|
hidden?: boolean;
|
|
5177
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5178
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5171
5179
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5172
5180
|
key: string;
|
|
5173
5181
|
}[];
|
|
@@ -5228,6 +5236,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5228
5236
|
display: EventFieldDisplay;
|
|
5229
5237
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5230
5238
|
hidden?: boolean;
|
|
5239
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5240
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5231
5241
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5232
5242
|
key: string;
|
|
5233
5243
|
}[];
|
|
@@ -5284,6 +5294,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5284
5294
|
display: EventFieldDisplay;
|
|
5285
5295
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5286
5296
|
hidden?: boolean;
|
|
5297
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5298
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5287
5299
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5288
5300
|
key: string;
|
|
5289
5301
|
}[];
|
|
@@ -5342,6 +5354,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5342
5354
|
display: EventFieldDisplay;
|
|
5343
5355
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5344
5356
|
hidden?: boolean;
|
|
5357
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5358
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5345
5359
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5346
5360
|
key: string;
|
|
5347
5361
|
}[];
|
|
@@ -5390,6 +5404,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5390
5404
|
display: EventFieldDisplay;
|
|
5391
5405
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5392
5406
|
hidden?: boolean;
|
|
5407
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5408
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5393
5409
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5394
5410
|
key: string;
|
|
5395
5411
|
}[];
|
|
@@ -5431,6 +5447,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5431
5447
|
display: EventFieldDisplay;
|
|
5432
5448
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5433
5449
|
hidden?: boolean;
|
|
5450
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5451
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5434
5452
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5435
5453
|
key: string;
|
|
5436
5454
|
}[];
|
|
@@ -5475,6 +5493,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5475
5493
|
display: EventFieldDisplay;
|
|
5476
5494
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5477
5495
|
hidden?: boolean;
|
|
5496
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5497
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5478
5498
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5479
5499
|
key: string;
|
|
5480
5500
|
}[];
|
|
@@ -5516,6 +5536,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5516
5536
|
display: EventFieldDisplay;
|
|
5517
5537
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5518
5538
|
hidden?: boolean;
|
|
5539
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5540
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5519
5541
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5520
5542
|
key: string;
|
|
5521
5543
|
}[];
|
|
@@ -5569,6 +5591,8 @@ declare const EVENT_TYPE_INFO: {
|
|
|
5569
5591
|
display: EventFieldDisplay;
|
|
5570
5592
|
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
5571
5593
|
hidden?: boolean;
|
|
5594
|
+
/** Display names for `enum` and `list` values that don't read well humanized. */
|
|
5595
|
+
valueLabels?: Readonly<Record<string, string>>;
|
|
5572
5596
|
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
5573
5597
|
key: string;
|
|
5574
5598
|
}[];
|
|
@@ -8383,6 +8407,11 @@ type LensTransform = {
|
|
|
8383
8407
|
type: string;
|
|
8384
8408
|
options: unknown;
|
|
8385
8409
|
};
|
|
8410
|
+
/**
|
|
8411
|
+
* A CDN transform: a selector string such as `imageTransform[format=png,width=1024]`, or one
|
|
8412
|
+
* or more structured steps such as `{ type: "imageTransform", options: { format: "png" } }`.
|
|
8413
|
+
*/
|
|
8414
|
+
type CdnTransform = string | LensTransform | LensTransform[];
|
|
8386
8415
|
/** A named, versioned CDN transformation. */
|
|
8387
8416
|
type Lens = Omit<zod.infer<typeof LENS_SCHEMA>, "transforms"> & {
|
|
8388
8417
|
transforms?: LensTransform[] | null;
|
|
@@ -8443,7 +8472,7 @@ interface CdnAssetUrlOptions {
|
|
|
8443
8472
|
assetIdentifier: string;
|
|
8444
8473
|
resource?: "content" | "preview";
|
|
8445
8474
|
lens?: string;
|
|
8446
|
-
transform?:
|
|
8475
|
+
transform?: CdnTransform;
|
|
8447
8476
|
}
|
|
8448
8477
|
interface CdnServeOptions extends CdnAssetUrlOptions {
|
|
8449
8478
|
init?: RequestInit;
|
|
@@ -8452,7 +8481,7 @@ interface CreateAssetSignedUrlOptions {
|
|
|
8452
8481
|
assetId: string;
|
|
8453
8482
|
resource?: "content" | "preview";
|
|
8454
8483
|
lens?: string;
|
|
8455
|
-
transform?:
|
|
8484
|
+
transform?: CdnTransform;
|
|
8456
8485
|
expiresInSeconds?: number;
|
|
8457
8486
|
}
|
|
8458
8487
|
type EnsureLensOptions = Pick<Lens, "identifier" | "name" | "description" | "type" | "active" | "transforms" | "version">;
|
|
@@ -8581,4 +8610,4 @@ interface ModerateTextOptions extends Omit<SubmitAssetCommonOptions, "name" | "v
|
|
|
8581
8610
|
name?: string;
|
|
8582
8611
|
}
|
|
8583
8612
|
//#endregion
|
|
8584
|
-
export {
|
|
8613
|
+
export { TypedEvent as $, ListEventsOptions as A, UpdateAssetOptions as B, ImageTransformOptions as C, LensTransform as D, Lens as E, MultipartUploadPartOptions as F, WebhookPayloadInput as G, UploadAssetPartOptions as H, RequestOptions as I, GetEventsResponse as J, AssetSearchQuery as K, RetrieveAssetOptions as L, MoveAssetOptions as M, MoveFolderOptions as N, ListAssetChildrenOptions as O, MultipartUploadOptions as P, Event as Q, RetryAssetOptions as R, IdempotencyOptions as S, IterateAssetsOptions as T, VerifyWebhookSignatureOptions as U, UpdateFolderOptions as V, WebhookHeadersInput as W, AssetBinaryPayloadInput as X, PostAssetSignedUrlResponse as Y, Folder as Z, DeleteAssetContentOptions as _, AssetSearchResponse as a, EventType as at, EnsureLensesOptions as b, AssetType as c, ClassificationReport as ct, CdnAssetUrlOptions as d, EventCategory as et, CdnServeOptions as f, CreateMultipartUploadPartOptions as g, CreateFolderOptions as h, AssetPage as i, EventSeverity as it, ModerateTextOptions as j, ListAssetsOptions as k, AssetVisibility as l, MetadataItem as lt, CreateAssetSignedUrlOptions as m, AssetChildrenPage as n, EventFactValues as nt, AssetSearchResult as o, ClassificationCategory as ot, CdnTransform as p, WebhookEventPayload as q, AssetContentOptions as r, EventFacts as rt, AssetStatus as s, ClassificationCategoryReport as st, Asset as t, EventFact as tt, CalmLensClientOptions as u, ProcessingOptions as ut, DeleteAssetOptions as v, IterateAssetChildrenOptions as w, FolderIdOptions as x, EnsureLensOptions as y, SubmitAssetOptions as z };
|
|
@@ -428,14 +428,51 @@ const encodePathSegment = (value, name) => {
|
|
|
428
428
|
if (value === "." || value === "..") throw invalidArgument(`${name} cannot be "." or ".."`);
|
|
429
429
|
return encodeURIComponent(value);
|
|
430
430
|
};
|
|
431
|
+
const TRANSFORM_TYPE_PATTERN = /^[A-Za-z0-9_]+$/;
|
|
432
|
+
/** Percent-encodes everything except RFC 3986 unreserved characters (`A-Z a-z 0-9 - . _ ~`). */
|
|
433
|
+
const encodeTransformComponent = (value) => encodeURIComponent(value).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
434
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
435
|
+
const appendTransformOptions = (pairs, key, value) => {
|
|
436
|
+
if (value === void 0 || value === null) return;
|
|
437
|
+
if (isPlainObject(value)) {
|
|
438
|
+
for (const child of Object.keys(value).sort()) appendTransformOptions(pairs, `${key}[${child}]`, value[child]);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
let text;
|
|
442
|
+
if (typeof value === "string") text = value;
|
|
443
|
+
else if (typeof value === "boolean") text = String(value);
|
|
444
|
+
else if (typeof value === "number" && Number.isFinite(value)) text = String(value);
|
|
445
|
+
else throw invalidArgument(`Transform option "${key}" must be a string, number, boolean or object`);
|
|
446
|
+
pairs.push(`${encodeTransformComponent(key)}=${encodeTransformComponent(text)}`);
|
|
447
|
+
};
|
|
448
|
+
/**
|
|
449
|
+
* Serializes structured transforms as a CDN selector, such as
|
|
450
|
+
* `imageTransform[format=png,width=1024]`. Option keys are sorted so equal transforms share a
|
|
451
|
+
* URL; nested keys (`border[color]`) and values are percent-encoded.
|
|
452
|
+
*/
|
|
453
|
+
const serializeTransform = (transform) => {
|
|
454
|
+
const steps = Array.isArray(transform) ? transform : [transform];
|
|
455
|
+
if (steps.length === 0) throw invalidArgument("Transform needs at least one step");
|
|
456
|
+
return steps.map((step) => {
|
|
457
|
+
if (!isPlainObject(step)) throw invalidArgument("Transform steps must be objects");
|
|
458
|
+
if (typeof step.type !== "string" || !TRANSFORM_TYPE_PATTERN.test(step.type)) throw invalidArgument("Transform type must contain only letters, digits and underscores");
|
|
459
|
+
if (step.options !== void 0 && step.options !== null && !isPlainObject(step.options)) throw invalidArgument("Transform options must be an object");
|
|
460
|
+
const pairs = [];
|
|
461
|
+
for (const key of Object.keys(step.options ?? {}).sort()) appendTransformOptions(pairs, key, step.options[key]);
|
|
462
|
+
return `${step.type}[${pairs.join(",")}]`;
|
|
463
|
+
}).join(",");
|
|
464
|
+
};
|
|
465
|
+
/** Returns the selector string the API and CDN accept for a string or structured transform. */
|
|
466
|
+
const transformSelector = (transform) => transform === void 0 || typeof transform === "string" ? transform : serializeTransform(transform);
|
|
431
467
|
/** Appends a CDN lens (`/@name`) or direct transform selector to an asset URL. */
|
|
432
468
|
const appendCdnSelector = (url, options) => {
|
|
433
469
|
if (options.lens && options.transform) throw invalidArgument("Specify either a lens or a transform, not both");
|
|
434
470
|
if (options.lens) return `${url}/@${encodePathSegment(options.lens, "Lens")}`;
|
|
435
471
|
if (!options.transform) return url;
|
|
472
|
+
if (typeof options.transform !== "string") return `${url}/${serializeTransform(options.transform)}`;
|
|
436
473
|
const transform = options.transform.replace(/^\/+/, "");
|
|
437
474
|
if (transform.includes("..") || transform.includes("?") || transform.includes("#")) throw invalidArgument("Transform cannot contain \"..\", \"?\" or \"#\"");
|
|
438
|
-
return `${url}/${encodeURI(transform)}`;
|
|
475
|
+
return `${url}/${encodeURI(transform).replace(/%5B/g, "[").replace(/%5D/g, "]")}`;
|
|
439
476
|
};
|
|
440
477
|
const appendQueryValue = (parts, key, value) => {
|
|
441
478
|
if (value === void 0 || value === null) return;
|
|
@@ -553,4 +590,4 @@ async function parseWebhookEvent(options) {
|
|
|
553
590
|
return event;
|
|
554
591
|
}
|
|
555
592
|
//#endregion
|
|
556
|
-
export {
|
|
593
|
+
export { getAssetPayloadByteLength as A, MAX_IMAGE_UPLOAD_BYTES as C, stringifyJsonCanonical as D, isRejectedUploadMimeType as E, validateAssetPayload as M, assetDataToUint8Array as O, DOMAIN as S, getRejectedUploadMimeTypeError as T, SDK_ERROR_CODES as _, parseWebhookEvent as a, API_ERROR_CODES as b, appendCdnSelector as c, toTextAssetOptions as d, transformSelector as f, CalmLensError as g, CALMLENS_ERROR_CODES as h, WEBHOOK_TIMESTAMP_HEADER as i, getRawBase64 as j, assetToData as k, encodePathSegment as l, validateRequestOptions as m, WEBHOOK_SIGNATURE_HEADER as n, verifyWebhookSignature as o, validateClientOptions as p, WEBHOOK_SIGNATURE_TOLERANCE_SECONDS as r, hmacSha256Hex as s, WEBHOOK_DELIVERY_HEADER as t, stringifyQuery as u, invalidArgument as v, MIN_MULTIPART_IMAGE_UPLOAD_BYTES as w, API_ERROR_DEFINITIONS as x, invalidConfig as y };
|
package/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as TypedEvent, A as ListEventsOptions, B as UpdateAssetOptions, C as ImageTransformOptions, D as LensTransform, E as Lens, F as MultipartUploadPartOptions, G as WebhookPayloadInput, H as UploadAssetPartOptions, I as RequestOptions, J as GetEventsResponse, K as AssetSearchQuery, L as RetrieveAssetOptions, M as MoveAssetOptions, N as MoveFolderOptions, O as ListAssetChildrenOptions, P as MultipartUploadOptions, R as RetryAssetOptions, S as IdempotencyOptions, T as IterateAssetsOptions, U as VerifyWebhookSignatureOptions, V as UpdateFolderOptions, W as WebhookHeadersInput, Y as PostAssetSignedUrlResponse, Z as Folder, _ as DeleteAssetContentOptions, a as AssetSearchResponse, at as EventType, b as EnsureLensesOptions, c as AssetType, ct as ClassificationReport, d as CdnAssetUrlOptions, et as EventCategory, f as CdnServeOptions, g as CreateMultipartUploadPartOptions, h as CreateFolderOptions, i as AssetPage, it as EventSeverity, j as ModerateTextOptions, k as ListAssetsOptions, l as AssetVisibility, lt as MetadataItem, m as CreateAssetSignedUrlOptions, n as AssetChildrenPage, nt as EventFactValues, o as AssetSearchResult, p as CdnTransform, q as WebhookEventPayload, r as AssetContentOptions, rt as EventFacts, s as AssetStatus, st as ClassificationCategoryReport, t as Asset, tt as EventFact, u as CalmLensClientOptions, ut as ProcessingOptions, v as DeleteAssetOptions, w as IterateAssetChildrenOptions, x as FolderIdOptions, y as EnsureLensOptions, z as SubmitAssetOptions } from "./CalmLensTypes-BZ-nxhr_.js";
|
|
2
2
|
//#region src/client/CalmLensClient.d.ts
|
|
3
3
|
interface ClientState {
|
|
4
4
|
readonly options: Omit<CalmLensClientOptions, "apiKey"> & {
|
|
@@ -379,4 +379,4 @@ export declare function verifyWebhookSignature(options: VerifyWebhookSignatureOp
|
|
|
379
379
|
*/
|
|
380
380
|
export declare function parseWebhookEvent(options: VerifyWebhookSignatureOptions): Promise<WebhookEventPayload>;
|
|
381
381
|
//#endregion
|
|
382
|
-
export { type ApiErrorCode, type Asset, type AssetChildrenPage, type AssetContentOptions, type AssetPage, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetStatus, type AssetType, type AssetVisibility, CalmLensClient, type CalmLensClientOptions, type CalmLensErrorCode, type CalmLensErrorDetails, type CalmLensErrorOptions, 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 IdempotencyOptions, type ImageTransformOptions, type IterateAssetChildrenOptions, type IterateAssetsOptions, type Lens, type LensTransform, 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 SdkErrorCode, type SubmitAssetOptions, type TypedEvent, type UpdateAssetOptions, type UpdateFolderOptions, type UploadAssetPartOptions, type VerifyWebhookSignatureOptions, type WebhookEventPayload, type WebhookHeadersInput, type WebhookPayloadInput };
|
|
382
|
+
export { type ApiErrorCode, type Asset, type AssetChildrenPage, type AssetContentOptions, type AssetPage, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetStatus, type AssetType, type AssetVisibility, CalmLensClient, type CalmLensClientOptions, type CalmLensErrorCode, type CalmLensErrorDetails, type CalmLensErrorOptions, type CdnAssetUrlOptions, type CdnServeOptions, type CdnTransform, 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 IdempotencyOptions, type ImageTransformOptions, type IterateAssetChildrenOptions, type IterateAssetsOptions, type Lens, type LensTransform, 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 SdkErrorCode, type SubmitAssetOptions, type TypedEvent, type UpdateAssetOptions, type UpdateFolderOptions, type UploadAssetPartOptions, type VerifyWebhookSignatureOptions, type WebhookEventPayload, type WebhookHeadersInput, type WebhookPayloadInput };
|
package/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as getAssetPayloadByteLength, C as MAX_IMAGE_UPLOAD_BYTES, D as stringifyJsonCanonical, E as isRejectedUploadMimeType, M as validateAssetPayload, T as getRejectedUploadMimeTypeError, _ as SDK_ERROR_CODES, a as parseWebhookEvent, b as API_ERROR_CODES, c as appendCdnSelector, d as toTextAssetOptions, f as transformSelector, g as CalmLensError, h as CALMLENS_ERROR_CODES, i as WEBHOOK_TIMESTAMP_HEADER, j as getRawBase64, k as assetToData, l as encodePathSegment, m as validateRequestOptions, n as WEBHOOK_SIGNATURE_HEADER, o as verifyWebhookSignature, p as validateClientOptions, r as WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, t as WEBHOOK_DELIVERY_HEADER, u as stringifyQuery, v as invalidArgument, w as MIN_MULTIPART_IMAGE_UPLOAD_BYTES, y as invalidConfig } from "./CalmLensWebhooks-3Otbubyf.js";
|
|
2
2
|
//#endregion
|
|
3
3
|
//#region src/client/CalmLensVersion.ts
|
|
4
4
|
/** This SDK's version, from its package.json. */
|
|
5
|
-
const SDK_VERSION = "0.
|
|
5
|
+
const SDK_VERSION = "0.11.0";
|
|
6
6
|
const runtimeName = () => {
|
|
7
7
|
const runtime = globalThis;
|
|
8
8
|
if (runtime.Bun?.version) return `bun/${runtime.Bun.version}`;
|
|
@@ -71,6 +71,11 @@ const createAttemptSignal = (signals, timeoutMs) => {
|
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* A redirect the SDK must not follow: it would send the API key to another origin. Browsers report
|
|
76
|
+
* a manual redirect as an opaque response; other runtimes return the 3xx with its Location.
|
|
77
|
+
*/
|
|
78
|
+
const isRedirect = (response) => response.type === "opaqueredirect" || response.status >= 300 && response.status < 400 && response.headers.has("location");
|
|
74
79
|
/** Turns anything thrown while sending or reading a request into a `CalmLensError`. */
|
|
75
80
|
const toFailure = (cause, attempt) => {
|
|
76
81
|
if (CalmLensError.isCalmLensError(cause)) return cause;
|
|
@@ -219,10 +224,14 @@ var CalmLensTransport = class {
|
|
|
219
224
|
method: request.method,
|
|
220
225
|
headers,
|
|
221
226
|
body: request.body,
|
|
222
|
-
redirect: "
|
|
227
|
+
redirect: "manual",
|
|
223
228
|
signal: attempt.signal,
|
|
224
229
|
duplex: "half"
|
|
225
230
|
});
|
|
231
|
+
if (isRedirect(response)) {
|
|
232
|
+
await response.body?.cancel().catch(() => {});
|
|
233
|
+
throw new CalmLensError(SDK_ERROR_CODES.TRANSPORT_ERROR, { message: `Unexpected redirect (HTTP ${response.status})` });
|
|
234
|
+
}
|
|
226
235
|
} catch (cause) {
|
|
227
236
|
attempt.release();
|
|
228
237
|
const failure = toFailure(cause, attempt);
|
|
@@ -667,7 +676,7 @@ moderate: async (options) => this.assets.moderate(toTextAssetOptions(options)) }
|
|
|
667
676
|
resource: options.resource ?? "content",
|
|
668
677
|
expiresInSeconds: options.expiresInSeconds ?? 900,
|
|
669
678
|
lens: options.lens,
|
|
670
|
-
transform: options.transform
|
|
679
|
+
transform: transformSelector(options.transform)
|
|
671
680
|
} });
|
|
672
681
|
},
|
|
673
682
|
/** Moves an asset into a folder, or to the project root with `folderId: null`. */
|
package/esm/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as TypedEvent, A as ListEventsOptions, B as UpdateAssetOptions, E as Lens, H as UploadAssetPartOptions, J as GetEventsResponse, K as AssetSearchQuery, L as RetrieveAssetOptions, M as MoveAssetOptions, N as MoveFolderOptions, O as ListAssetChildrenOptions, Q as Event, R as RetryAssetOptions, T as IterateAssetsOptions, V as UpdateFolderOptions, X as AssetBinaryPayloadInput, Y as PostAssetSignedUrlResponse, Z as Folder, _ as DeleteAssetContentOptions, a as AssetSearchResponse, b as EnsureLensesOptions, d as CdnAssetUrlOptions, f as CdnServeOptions, h as CreateFolderOptions, i as AssetPage, j as ModerateTextOptions, k as ListAssetsOptions, m as CreateAssetSignedUrlOptions, n as AssetChildrenPage, ot as ClassificationCategory, q as WebhookEventPayload, s as AssetStatus, t as Asset, u as CalmLensClientOptions, v as DeleteAssetOptions, w as IterateAssetChildrenOptions, x as FolderIdOptions, y as EnsureLensOptions, z as SubmitAssetOptions } from "./CalmLensTypes-BZ-nxhr_.js";
|
|
2
2
|
import * as zod from "zod";
|
|
3
3
|
//#region ../shared/src/TestTriggers.d.ts
|
|
4
4
|
type ClassificationTestSignal = ClassificationCategory | "sexual.involving-minors" | "violence.graphic";
|
package/esm/testing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as
|
|
1
|
+
import { A as getAssetPayloadByteLength, D as stringifyJsonCanonical, E as isRejectedUploadMimeType, M as validateAssetPayload, O as assetDataToUint8Array, T as getRejectedUploadMimeTypeError, _ as SDK_ERROR_CODES, b as API_ERROR_CODES, c as appendCdnSelector, d as toTextAssetOptions, f as transformSelector, g as CalmLensError, i as WEBHOOK_TIMESTAMP_HEADER, k as assetToData, l as encodePathSegment, n as WEBHOOK_SIGNATURE_HEADER, p as validateClientOptions, s as hmacSha256Hex, t as WEBHOOK_DELIVERY_HEADER, v as invalidArgument, x as API_ERROR_DEFINITIONS } from "./CalmLensWebhooks-3Otbubyf.js";
|
|
2
2
|
import * as zod from "zod";
|
|
3
3
|
import "zod/v4";
|
|
4
4
|
//#region ../shared/src/ModerationCategoryDefinitions.ts
|
|
@@ -912,7 +912,8 @@ var MockCalmLensClient = class {
|
|
|
912
912
|
if (options.lens && options.transform) throw invalidArgument("Specify either a lens or a transform, not both");
|
|
913
913
|
const expiresInSeconds = options.expiresInSeconds ?? 900;
|
|
914
914
|
const resource = options.resource ?? "content";
|
|
915
|
-
const
|
|
915
|
+
const transform = transformSelector(options.transform);
|
|
916
|
+
const selector = options.lens ? `&lens=${encodeURIComponent(options.lens)}` : transform ? `&transform=${encodeURIComponent(transform)}` : "";
|
|
916
917
|
return {
|
|
917
918
|
url: `${this.signedUrlBaseUrl}/assets/${asset.id}/${resource}?expiresInSeconds=${expiresInSeconds}${selector}`,
|
|
918
919
|
expiresAt: this.now() + expiresInSeconds * 1e3
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calmlens/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Official CalmLens SDK for JavaScript and TypeScript: content moderation, asset storage and CDN delivery.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://calmlens.com/docs/sdk/javascript",
|