calmlens 0.21.0 → 0.22.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 +3 -2
- package/bin/calmlens.js +571 -67
- package/{esm/BrowserUpload-D-NnAN7g.d.ts → cjs/BrowserUpload-BWjZ9ntu.d.ts} +2 -2
- package/cjs/{BrowserUpload-CeSwiMo5.js → BrowserUpload-Bwlib4Zc.js} +1 -1
- package/{esm/CalmLensAppClient-gG16T2py.d.ts → cjs/CalmLensAppClient-BaW3ddUR.d.ts} +1 -1
- package/cjs/{CalmLensAppClient-0UVCuNqW.js → CalmLensAppClient-DUYMo9PZ.js} +3 -3
- package/cjs/{CalmLensOptionKeys-CYY6elxg.js → CalmLensOptionKeys-YvgV995V.js} +139 -31
- package/cjs/{CalmLensServerClient-nfu6_YEW.js → CalmLensServerClient-3N-gdsxC.js} +61 -4
- package/cjs/{CalmLensServerClient-BHx3x_nZ.d.ts → CalmLensServerClient-BKzn8zmp.d.ts} +38 -2
- package/cjs/{CalmLensTypes-CUB0YYVz.d.ts → CalmLensTypes-BDKwThbO.d.ts} +612 -53
- package/{esm/Core-C82YmjjX.d.ts → cjs/Core-C33pkBmf.d.ts} +7 -4
- package/cjs/{Core-Dc3cteU7.js → Core-Cm5Z1oJ9.js} +9 -6
- package/cjs/{ModerationContextLimits-BxOmeSqq.js → ModerationContextLimits-ud1xpZRK.js} +61 -2
- package/cjs/{ReactUpload-BK2O3dnK.js → ReactUpload-DQ0BYISX.js} +1 -1
- package/cjs/{ReactUpload-DiiXfKvj.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
- package/cjs/{TestTriggers-BTyXtX0Q-ATuFDhLX.js → TestTriggers-D29T_R0M-D6Bu-Mln.js} +16 -16
- package/cjs/{UploadController-DLyiLDTB.js → UploadController-l8fZM2qT.js} +2 -2
- package/cjs/{WebhookPayload-BLT2y_Jy.d.ts → WebhookPayload-Dt6DttS0.d.ts} +28 -1
- package/cjs/app.d.ts +5 -5
- package/cjs/app.js +2 -2
- package/cjs/elements.d.ts +4 -4
- package/cjs/elements.js +4 -4
- package/{esm/index-CKRgjV16.d.ts → cjs/index-Bde1wjiw.d.ts} +2 -2
- package/cjs/index.d.ts +4 -4
- package/cjs/index.js +1 -1
- package/cjs/react-native.d.ts +2 -2
- package/cjs/react-native.js +4 -4
- package/cjs/react.d.ts +3 -3
- package/cjs/react.js +5 -5
- package/cjs/server.d.ts +5 -5
- package/cjs/server.js +2 -2
- package/cjs/test-inputs.js +13 -13
- package/cjs/testing.d.ts +10 -6
- package/cjs/testing.js +332 -54
- package/cjs/{ui-CZ8exACq.js → ui-BRA4HQ8r.js} +3 -3
- package/cjs/{ui-CTBUxnVp.d.ts → ui-YQuvbidU.d.ts} +2 -2
- package/cjs/ui.d.ts +2 -2
- package/cjs/ui.js +3 -3
- package/cjs/vue.d.ts +5 -5
- package/cjs/vue.js +4 -4
- package/{cjs/BrowserUpload-D-NnAN7g.d.ts → esm/BrowserUpload-BWjZ9ntu.d.ts} +2 -2
- package/esm/{BrowserUpload-i9OhCzMJ.js → BrowserUpload-GRZVB0G_.js} +1 -1
- package/esm/{CalmLensAppClient-CK4_Py0c.js → CalmLensAppClient-B5QIJ6KS.js} +3 -3
- package/{cjs/CalmLensAppClient-gG16T2py.d.ts → esm/CalmLensAppClient-BaW3ddUR.d.ts} +1 -1
- package/esm/{CalmLensOptionKeys-BGZlIsT2.js → CalmLensOptionKeys-BG7Qrh8-.js} +139 -31
- package/esm/{CalmLensServerClient-BHx3x_nZ.d.ts → CalmLensServerClient-BKzn8zmp.d.ts} +38 -2
- package/esm/{CalmLensServerClient-dAQUcDWb.js → CalmLensServerClient-bRUAebi-.js} +61 -4
- package/esm/{CalmLensTypes-CUB0YYVz.d.ts → CalmLensTypes-BDKwThbO.d.ts} +612 -53
- package/esm/{Core-BxeIud_S.js → Core-BvQe4moS.js} +9 -6
- package/{cjs/Core-C82YmjjX.d.ts → esm/Core-C33pkBmf.d.ts} +7 -4
- package/esm/{ModerationContextLimits-B6_RalCQ.js → ModerationContextLimits-CrxSnVZ3.js} +61 -2
- package/esm/{ReactUpload-DxwVqfX1.js → ReactUpload-BMO8saxT.js} +1 -1
- package/esm/{ReactUpload-DiiXfKvj.d.ts → ReactUpload-DhF8mm51.d.ts} +1 -1
- package/esm/{TestTriggers-BTyXtX0Q-GRB9jQwo.js → TestTriggers-D29T_R0M-Ztc74ucs.js} +16 -16
- package/esm/{UploadController-D9Z-h00Q.js → UploadController-DnJrWiE4.js} +2 -2
- package/esm/{WebhookPayload-BLT2y_Jy.d.ts → WebhookPayload-Dt6DttS0.d.ts} +28 -1
- package/esm/app.d.ts +5 -5
- package/esm/app.js +2 -2
- package/esm/elements.d.ts +4 -4
- package/esm/elements.js +4 -4
- package/{cjs/index-CKRgjV16.d.ts → esm/index-Bde1wjiw.d.ts} +2 -2
- package/esm/index.d.ts +4 -4
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +2 -2
- package/esm/react-native.js +4 -4
- package/esm/react.d.ts +3 -3
- package/esm/react.js +5 -5
- package/esm/server.d.ts +5 -5
- package/esm/server.js +2 -2
- package/esm/test-inputs.js +1 -1
- package/esm/testing.d.ts +10 -6
- package/esm/testing.js +326 -48
- package/esm/{ui-CTBUxnVp.d.ts → ui-YQuvbidU.d.ts} +2 -2
- package/esm/{ui-Cr7s6JHm.js → ui-heryDd6g.js} +3 -3
- package/esm/ui.d.ts +2 -2
- package/esm/ui.js +3 -3
- package/esm/vue.d.ts +5 -5
- package/esm/vue.js +4 -4
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as UploadItem$1, I as UploadSnapshot$1, M as UploadController, N as UploadControllerOptions$1, O as CalmLensUpload$1, P as UploadFile, h as UploaderProps$1 } from "./Core-
|
|
2
|
-
import { t as UseCalmLensUploadResult$1 } from "./ReactUpload-
|
|
1
|
+
import { F as UploadItem$1, I as UploadSnapshot$1, M as UploadController, N as UploadControllerOptions$1, O as CalmLensUpload$1, P as UploadFile, h as UploaderProps$1 } from "./Core-C33pkBmf.js";
|
|
2
|
+
import { t as UseCalmLensUploadResult$1 } from "./ReactUpload-DhF8mm51.js";
|
|
3
3
|
type UploadItem<F extends UploadFile = File> = UploadItem$1<F>;
|
|
4
4
|
type CalmLensUpload<F extends UploadFile = File> = CalmLensUpload$1<F>;
|
|
5
5
|
type UploadSnapshot<F extends UploadFile = File> = UploadSnapshot$1<F>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_UploadController = require("./UploadController-
|
|
1
|
+
const require_UploadController = require("./UploadController-l8fZM2qT.js");
|
|
2
2
|
// src/ui/BrowserUpload.ts
|
|
3
3
|
/** Creates an upload queue for the browser components, such as one a form starts on submit. */
|
|
4
4
|
const createUploadController = (options) => require_UploadController.createUploadController(options);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as CalmLensAppClientOptions,
|
|
1
|
+
import { D as CalmLensAppClientOptions, Lt as RetrieveAssetOptions, an as UploadedAsset, en as UploadAssetPartOptions, in as UploadPresetSubmitAssetOptions, j as CdnAssetUrlOptions } from "./CalmLensTypes-BDKwThbO.js";
|
|
2
2
|
declare const inspectSymbol: unique symbol;
|
|
3
3
|
/**
|
|
4
4
|
* The CalmLens client for browsers and React Native apps. It uploads through an upload preset,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_ModerationContextLimits = require("./ModerationContextLimits-
|
|
2
|
-
const require_CalmLensOptionKeys = require("./CalmLensOptionKeys-
|
|
1
|
+
const require_ModerationContextLimits = require("./ModerationContextLimits-ud1xpZRK.js");
|
|
2
|
+
const require_CalmLensOptionKeys = require("./CalmLensOptionKeys-YvgV995V.js");
|
|
3
3
|
// src/client/CalmLensAppClient.ts
|
|
4
4
|
const inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
|
5
5
|
/** `options`, once `checkOptionKeys` finds only keys `operation` takes. */
|
|
@@ -74,7 +74,7 @@ var CalmLensAppClient = class {
|
|
|
74
74
|
});
|
|
75
75
|
return require_CalmLensOptionKeys.expectUploadedAsset(data);
|
|
76
76
|
}
|
|
77
|
-
const data = await this.#connection.
|
|
77
|
+
const data = await this.#connection.submitUpload(this.uploadsPath, options, wait, token ? { Authorization: `Bearer ${token}` } : {});
|
|
78
78
|
const uploaded = require_CalmLensOptionKeys.expectUploadedAsset(data);
|
|
79
79
|
if (token) this.#uploadTokens.set(uploaded.id, token);
|
|
80
80
|
return uploaded;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_ModerationContextLimits = require("./ModerationContextLimits-
|
|
1
|
+
const require_ModerationContextLimits = require("./ModerationContextLimits-ud1xpZRK.js");
|
|
2
2
|
// src/contract/AssetPayload.js
|
|
3
3
|
const bufferInputToBytes = (value) => {
|
|
4
4
|
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
@@ -135,18 +135,97 @@ const splitsIntoParts = (content, partSizeBytes) => {
|
|
|
135
135
|
* build a Blob from bytes, and every fetch accepts a Uint8Array.
|
|
136
136
|
*/
|
|
137
137
|
const toBodyBytes = (value) => value.buffer instanceof ArrayBuffer ? value : Uint8Array.from(value);
|
|
138
|
-
|
|
138
|
+
/** The bytes of an upload's content or part, as a Blob, bytes or a one-shot stream. */
|
|
139
|
+
const toUploadData = (payload) => {
|
|
139
140
|
const data = assetToData(payload);
|
|
140
141
|
if (data instanceof Response) {
|
|
141
142
|
if (!data.body) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Response upload data must have a body" });
|
|
142
143
|
return data.body;
|
|
143
144
|
}
|
|
144
|
-
if (data instanceof
|
|
145
|
+
if (data instanceof Blob) return data;
|
|
146
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
145
147
|
if ("getReader" in data) return data;
|
|
146
148
|
return toBodyBytes(data);
|
|
147
149
|
};
|
|
150
|
+
/** An upload's bytes as a raw part body (parts after the first carry no options). */
|
|
151
|
+
const toRawUploadBody = (payload) => toUploadData(payload);
|
|
152
|
+
const textEncoder = new TextEncoder();
|
|
153
|
+
/**
|
|
154
|
+
* An upload form: `multipart/form-data` with the asset's fields as the JSON `options` part, then
|
|
155
|
+
* the bytes as the `file` part. Asset fields never go in the URL, which proxies and servers log.
|
|
156
|
+
* Bytes stay bytes (React Native can't build a Blob from them), a Blob stays a Blob, and a stream
|
|
157
|
+
* is wrapped so the file is still sent as it is read.
|
|
158
|
+
*/
|
|
159
|
+
const toUploadForm = (options, payload) => {
|
|
160
|
+
const boundary = `calmlens-${require_ModerationContextLimits.randomUuid()}`;
|
|
161
|
+
const head = `--${boundary}\r\nContent-Disposition: form-data; name="options"\r\nContent-Type: application/json\r\n\r\n${JSON.stringify(options)}\r\n--${boundary}\r\nContent-Disposition: form-data; name="file"\r\nContent-Type: ${payload.type.replace(/[\r\n]/g, "")}\r\n\r\n`;
|
|
162
|
+
const tail = `\r\n--${boundary}--\r\n`;
|
|
163
|
+
const contentType = `multipart/form-data; boundary=${boundary}`;
|
|
164
|
+
const data = toUploadData(payload);
|
|
165
|
+
if (data instanceof Blob) return {
|
|
166
|
+
body: new Blob([
|
|
167
|
+
head,
|
|
168
|
+
data,
|
|
169
|
+
tail
|
|
170
|
+
]),
|
|
171
|
+
contentType
|
|
172
|
+
};
|
|
173
|
+
const headBytes = textEncoder.encode(head);
|
|
174
|
+
const tailBytes = textEncoder.encode(tail);
|
|
175
|
+
if (data instanceof Uint8Array) {
|
|
176
|
+
const body = new Uint8Array(headBytes.length + data.length + tailBytes.length);
|
|
177
|
+
body.set(headBytes);
|
|
178
|
+
body.set(data, headBytes.length);
|
|
179
|
+
body.set(tailBytes, headBytes.length + data.length);
|
|
180
|
+
return {
|
|
181
|
+
body,
|
|
182
|
+
contentType
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const reader = data.getReader();
|
|
186
|
+
let stage = "head";
|
|
187
|
+
return {
|
|
188
|
+
body: new ReadableStream({
|
|
189
|
+
async pull(controller) {
|
|
190
|
+
if (stage === "head") {
|
|
191
|
+
stage = "file";
|
|
192
|
+
controller.enqueue(headBytes);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (stage === "done") return;
|
|
196
|
+
const { done, value } = await reader.read();
|
|
197
|
+
if (!done) {
|
|
198
|
+
if (value.byteLength) controller.enqueue(value);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
stage = "done";
|
|
202
|
+
controller.enqueue(tailBytes);
|
|
203
|
+
controller.close();
|
|
204
|
+
},
|
|
205
|
+
cancel: (reason) => reader.cancel(reason)
|
|
206
|
+
}),
|
|
207
|
+
contentType
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
/** The options an upload sends, without the transport ones and without empty values. */
|
|
211
|
+
const uploadFields = (options) => Object.fromEntries(UPLOAD_OPTION_KEYS.flatMap((key) => options[key] === void 0 || options[key] === null ? [] : [[key, options[key]]]));
|
|
212
|
+
/** The asset fields an upload carries in its body: the API refuses them in the query string. */
|
|
213
|
+
const UPLOAD_OPTION_KEYS = [
|
|
214
|
+
"name",
|
|
215
|
+
"description",
|
|
216
|
+
"processingOptions",
|
|
217
|
+
"visibility",
|
|
218
|
+
"metadata",
|
|
219
|
+
"tags",
|
|
220
|
+
"authorId",
|
|
221
|
+
"context",
|
|
222
|
+
"externalId",
|
|
223
|
+
"externalUrl",
|
|
224
|
+
"folderId",
|
|
225
|
+
"uploadPresetId"
|
|
226
|
+
];
|
|
148
227
|
const setOptionalQueryValue = (params, key, value) => {
|
|
149
|
-
if (value !== void 0 && value !== null) params.set(key,
|
|
228
|
+
if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
150
229
|
};
|
|
151
230
|
const assertValidUploadMimeType = (mimeType) => {
|
|
152
231
|
if (!require_ModerationContextLimits.isAcceptedUploadMimeType(mimeType)) throw new require_ModerationContextLimits.CalmLensError(require_ModerationContextLimits.API_ERROR_CODES.UNSUPPORTED_UPLOAD_TYPE, {
|
|
@@ -313,54 +392,62 @@ var CalmLensConnection = class {
|
|
|
313
392
|
deadline: "body"
|
|
314
393
|
});
|
|
315
394
|
}
|
|
316
|
-
upload(url,
|
|
395
|
+
upload(url, body, headers, idempotencyKey, text) {
|
|
317
396
|
return this.transport.json({
|
|
318
397
|
method: "POST",
|
|
319
398
|
url,
|
|
320
399
|
headers,
|
|
321
|
-
body
|
|
400
|
+
body,
|
|
322
401
|
idempotencyKey,
|
|
323
|
-
timeoutMs:
|
|
402
|
+
timeoutMs: text ? this.timeoutMs : this.options.uploadTimeoutMs,
|
|
324
403
|
deadline: "body",
|
|
325
404
|
fetch: this.options.uploadFetch
|
|
326
405
|
});
|
|
327
406
|
}
|
|
328
407
|
/**
|
|
329
|
-
* Uploads file content or a first multipart part to `uploadsPath` (`.../assets`)
|
|
330
|
-
*
|
|
408
|
+
* Uploads file content or a first multipart part to `uploadsPath` (`.../assets`). Plain text
|
|
409
|
+
* goes as a JSON body; other content as an upload form, the asset's fields in its options part
|
|
410
|
+
* and the bytes in its file part. Either way the query holds only transport values.
|
|
331
411
|
*/
|
|
332
|
-
|
|
333
|
-
const query = new URLSearchParams();
|
|
334
|
-
query.set("name", options.name);
|
|
335
|
-
query.set("wait", String(wait));
|
|
336
|
-
setOptionalQueryValue(query, "description", options.description);
|
|
337
|
-
setOptionalQueryValue(query, "processingOptions", options.processingOptions);
|
|
338
|
-
setOptionalQueryValue(query, "visibility", options.visibility);
|
|
339
|
-
setOptionalQueryValue(query, "metadata", options.metadata);
|
|
340
|
-
setOptionalQueryValue(query, "tags", options.tags);
|
|
341
|
-
setOptionalQueryValue(query, "authorId", options.authorId);
|
|
342
|
-
setOptionalQueryValue(query, "context", options.context);
|
|
343
|
-
setOptionalQueryValue(query, "externalId", options.externalId);
|
|
344
|
-
setOptionalQueryValue(query, "externalUrl", options.externalUrl);
|
|
345
|
-
setOptionalQueryValue(query, "folderId", options.folderId);
|
|
346
|
-
setOptionalQueryValue(query, "uploadPresetId", options.uploadPresetId);
|
|
412
|
+
submitUpload(uploadsPath, options, wait, authHeaders = {}) {
|
|
347
413
|
const isMultipart = "part" in options;
|
|
348
414
|
const payload = isMultipart ? options.part : options.content;
|
|
415
|
+
const multipartOptions = options;
|
|
416
|
+
const idempotencyKey = options.idempotencyKey ?? newIdempotencyKey();
|
|
417
|
+
const fields = uploadFields(options);
|
|
418
|
+
if (isTextPayload(payload)) {
|
|
419
|
+
const { sizeInBytes: _size, ...text } = payload;
|
|
420
|
+
const body = isMultipart ? {
|
|
421
|
+
...fields,
|
|
422
|
+
part: text,
|
|
423
|
+
...multipartOptions.sizeInBytes === void 0 ? {} : { sizeInBytes: multipartOptions.sizeInBytes },
|
|
424
|
+
...multipartOptions.totalSizeInBytes === void 0 ? {} : { totalSizeInBytes: multipartOptions.totalSizeInBytes }
|
|
425
|
+
} : {
|
|
426
|
+
...fields,
|
|
427
|
+
content: text
|
|
428
|
+
};
|
|
429
|
+
return this.upload(this.url(uploadsPath, { wait }), JSON.stringify(body), {
|
|
430
|
+
...authHeaders,
|
|
431
|
+
"Content-Type": "application/json"
|
|
432
|
+
}, idempotencyKey, true);
|
|
433
|
+
}
|
|
434
|
+
const query = new URLSearchParams();
|
|
435
|
+
query.set("wait", String(wait));
|
|
349
436
|
query.set("contentType", payload.type);
|
|
350
437
|
setOptionalQueryValue(query, "sizeInBytes", payload.sizeInBytes ?? getAssetPayloadByteLength(payload));
|
|
351
438
|
if (isMultipart) {
|
|
352
439
|
const part = payload;
|
|
353
|
-
const multipartOptions = options;
|
|
354
440
|
query.set("partNumber", String(part.partNumber ?? 1));
|
|
355
441
|
query.set("isFinal", String(part.isFinal ?? false));
|
|
356
442
|
setOptionalQueryValue(query, "sizeInBytes", part.sizeInBytes ?? multipartOptions.sizeInBytes);
|
|
357
443
|
setOptionalQueryValue(query, "totalSizeInBytes", multipartOptions.totalSizeInBytes);
|
|
358
444
|
}
|
|
359
|
-
|
|
445
|
+
const form = toUploadForm(fields, payload);
|
|
446
|
+
return this.upload(this.url(`${uploadsPath}?${query}`), form.body, {
|
|
360
447
|
...authHeaders,
|
|
361
|
-
"Content-Type":
|
|
448
|
+
"Content-Type": form.contentType,
|
|
362
449
|
"X-CalmLens-Upload": isMultipart ? "part" : "content"
|
|
363
|
-
},
|
|
450
|
+
}, idempotencyKey, false);
|
|
364
451
|
}
|
|
365
452
|
/** Content larger than this is uploaded in parts. */
|
|
366
453
|
get partSizeBytes() {
|
|
@@ -380,7 +467,7 @@ var CalmLensConnection = class {
|
|
|
380
467
|
const count = Math.ceil(source.size / partSize);
|
|
381
468
|
const key = idempotencyKey ?? newIdempotencyKey();
|
|
382
469
|
const part = (partNumber) => source.slice((partNumber - 1) * partSize, Math.min(partNumber * partSize, source.size));
|
|
383
|
-
const first = await this.
|
|
470
|
+
const first = await this.submitUpload(uploadsPath, {
|
|
384
471
|
...fields,
|
|
385
472
|
part: {
|
|
386
473
|
...part(1),
|
|
@@ -434,10 +521,10 @@ var CalmLensConnection = class {
|
|
|
434
521
|
});
|
|
435
522
|
if (wait !== void 0) query.set("wait", String(wait));
|
|
436
523
|
setOptionalQueryValue(query, "sizeInBytes", part.sizeInBytes ?? getAssetPayloadByteLength(part));
|
|
437
|
-
return this.upload(this.url(`${partPath}?${query}`), part, {
|
|
524
|
+
return this.upload(this.url(`${partPath}?${query}`), toRawUploadBody(part), {
|
|
438
525
|
...authHeaders,
|
|
439
526
|
"X-CalmLens-Upload": "part"
|
|
440
|
-
}, idempotencyKey ?? newIdempotencyKey());
|
|
527
|
+
}, idempotencyKey ?? newIdempotencyKey(), isTextPayload(part));
|
|
441
528
|
}
|
|
442
529
|
};
|
|
443
530
|
// src/client/CalmLensOptionKeys.ts
|
|
@@ -672,6 +759,9 @@ const SERVER_OPTION_KEYS = {
|
|
|
672
759
|
"transform",
|
|
673
760
|
"type"
|
|
674
761
|
],
|
|
762
|
+
"metadataFields.delete": ["fieldId", "revision"],
|
|
763
|
+
"metadataFields.ensure": ["fields", "revision"],
|
|
764
|
+
"metadataFields.list": [],
|
|
675
765
|
"policies.assign": ["policyId"],
|
|
676
766
|
"policies.create": [
|
|
677
767
|
"description",
|
|
@@ -715,6 +805,12 @@ const SERVER_OPTION_KEYS = {
|
|
|
715
805
|
"presetVersion",
|
|
716
806
|
"revision"
|
|
717
807
|
],
|
|
808
|
+
"projectSettings.get": [],
|
|
809
|
+
"projectSettings.update": [
|
|
810
|
+
"revision",
|
|
811
|
+
"searchIndexingBudgetUnits",
|
|
812
|
+
"settings"
|
|
813
|
+
],
|
|
718
814
|
"text.classify": [
|
|
719
815
|
"authorId",
|
|
720
816
|
"context",
|
|
@@ -729,6 +825,18 @@ const SERVER_OPTION_KEYS = {
|
|
|
729
825
|
"text",
|
|
730
826
|
"uploadPresetId",
|
|
731
827
|
"visibility"
|
|
828
|
+
],
|
|
829
|
+
"uploadPresets.delete": ["uploadPresetId"],
|
|
830
|
+
"uploadPresets.ensure": ["uploadPresets"],
|
|
831
|
+
"uploadPresets.iterate": [
|
|
832
|
+
"cursor",
|
|
833
|
+
"pageSize",
|
|
834
|
+
"sort"
|
|
835
|
+
],
|
|
836
|
+
"uploadPresets.list": [
|
|
837
|
+
"cursor",
|
|
838
|
+
"pageSize",
|
|
839
|
+
"sort"
|
|
732
840
|
]
|
|
733
841
|
};
|
|
734
842
|
/** The option keys each `CalmLensAppClient` method sends to the API. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_ModerationContextLimits = require("./ModerationContextLimits-
|
|
2
|
-
const require_CalmLensOptionKeys = require("./CalmLensOptionKeys-
|
|
1
|
+
const require_ModerationContextLimits = require("./ModerationContextLimits-ud1xpZRK.js");
|
|
2
|
+
const require_CalmLensOptionKeys = require("./CalmLensOptionKeys-YvgV995V.js");
|
|
3
3
|
const require_CryptoUtils_B_x8lMIx = require("./CryptoUtils-B_x8lMIx-YBW1-bvL.js");
|
|
4
4
|
// src/contract/JsonUtils.js
|
|
5
5
|
const stringifyJsonCanonical = (value) => JSON.stringify(value, (_key, nestedValue) => {
|
|
@@ -222,6 +222,8 @@ const inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
|
|
222
222
|
*/
|
|
223
223
|
var CalmLensServerClient = class CalmLensServerClient {
|
|
224
224
|
#apiKey;
|
|
225
|
+
/** The options this client was created with, without the API key, for `withRequestOptions`. */
|
|
226
|
+
#options;
|
|
225
227
|
#settings;
|
|
226
228
|
#lenses;
|
|
227
229
|
#connection;
|
|
@@ -249,6 +251,7 @@ var CalmLensServerClient = class CalmLensServerClient {
|
|
|
249
251
|
if ((require_ModerationContextLimits.isBrowserRuntime() || require_ModerationContextLimits.isReactNativeRuntime()) && !options.dangerouslyAllowBrowser) throw require_ModerationContextLimits.invalidConfig("CalmLensServerClient is running in a browser or app, where anyone could read the API key. Call CalmLens from your server, upload from the browser or app with CalmLensAppClient, or set dangerouslyAllowBrowser: true for trusted internal tools.");
|
|
250
252
|
const { apiKey, ...rest } = options;
|
|
251
253
|
this.#apiKey = apiKey;
|
|
254
|
+
this.#options = rest;
|
|
252
255
|
this.#settings = {
|
|
253
256
|
...require_CalmLensOptionKeys.resolveConnectionOptions(rest),
|
|
254
257
|
cdnBaseUrl: (rest.cdnBaseUrl ?? require_CalmLensOptionKeys.getMockHooks(rest)?.defaultCdnBaseUrl ?? require_ModerationContextLimits.DEFAULT_CDN_BASE_URL).replace(/\/+$/, "")
|
|
@@ -266,7 +269,7 @@ var CalmLensServerClient = class CalmLensServerClient {
|
|
|
266
269
|
withRequestOptions(options) {
|
|
267
270
|
require_ModerationContextLimits.validateRequestOptions(options);
|
|
268
271
|
return new CalmLensServerClient({
|
|
269
|
-
...this.#
|
|
272
|
+
...this.#options,
|
|
270
273
|
...options,
|
|
271
274
|
apiKey: this.#apiKey
|
|
272
275
|
}, this.#lenses);
|
|
@@ -300,7 +303,7 @@ var CalmLensServerClient = class CalmLensServerClient {
|
|
|
300
303
|
partPath: (assetId) => `/assets/${encodeURIComponent(assetId)}/part`,
|
|
301
304
|
retrieve: (assetId) => this.buildAssets().retrieve({ assetId })
|
|
302
305
|
}));
|
|
303
|
-
if ("content" in body || "part" in body) return require_CalmLensOptionKeys.expectAsset(await this.#connection.
|
|
306
|
+
if ("content" in body || "part" in body) return require_CalmLensOptionKeys.expectAsset(await this.#connection.submitUpload(uploadsPath, body, wait));
|
|
304
307
|
const { idempotencyKey, ...fields } = body;
|
|
305
308
|
const data = await this.#connection.json("POST", uploadsPath, {
|
|
306
309
|
query: { wait },
|
|
@@ -773,6 +776,60 @@ sign: async (options) => {
|
|
|
773
776
|
};
|
|
774
777
|
}
|
|
775
778
|
/**
|
|
779
|
+
* The project's upload presets: the rules for uploads from browsers and apps. `ensure` creates or
|
|
780
|
+
* replaces presets by key, for deploys that declare them in code; send each preset's `revision`
|
|
781
|
+
* to refuse a change made since you read it.
|
|
782
|
+
*/
|
|
783
|
+
get uploadPresets() {
|
|
784
|
+
return {
|
|
785
|
+
/** Lists one page of the project's upload presets, oldest first unless `sort` says otherwise. */
|
|
786
|
+
list: async (options = {}) => this.request("GET", `${this.projectPath}/upload-presets`, { query: checked("uploadPresets.list", options) }),
|
|
787
|
+
/** Yields every upload preset of the project, fetching pages as needed. */
|
|
788
|
+
iterate: (options = {}) => {
|
|
789
|
+
checked("uploadPresets.iterate", options);
|
|
790
|
+
return this.iteratePages((cursor) => this.uploadPresets.list({
|
|
791
|
+
...options,
|
|
792
|
+
cursor
|
|
793
|
+
}));
|
|
794
|
+
},
|
|
795
|
+
/**
|
|
796
|
+
* Creates each preset, or replaces it with the definition sent, by key. Every preset is
|
|
797
|
+
* checked before any is saved. Returns the stored presets in the order sent.
|
|
798
|
+
*/
|
|
799
|
+
ensure: async (options) => this.request("PUT", `${this.projectPath}/upload-presets`, { body: checked("uploadPresets.ensure", options) }),
|
|
800
|
+
/** Deletes an upload preset; assets already uploaded through it stay. */
|
|
801
|
+
delete: async (options) => {
|
|
802
|
+
const { uploadPresetId } = checked("uploadPresets.delete", options);
|
|
803
|
+
await this.request("DELETE", `/upload-presets/${requireId(uploadPresetId, "Upload preset ID")}`);
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* The project's settings, with defaults filled in. `update` replaces them: settings left out
|
|
809
|
+
* return to their defaults. Send the `revision` you read to refuse a change made since.
|
|
810
|
+
*/
|
|
811
|
+
get projectSettings() {
|
|
812
|
+
return {
|
|
813
|
+
get: async () => this.request("GET", `${this.projectPath}/settings`),
|
|
814
|
+
update: async (options) => this.request("PUT", `${this.projectPath}/settings`, { body: checked("projectSettings.update", options) })
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* The project's metadata fields. They share the project settings' `revision`; `ensure` creates
|
|
819
|
+
* or replaces fields by ID and keeps the others.
|
|
820
|
+
*/
|
|
821
|
+
get metadataFields() {
|
|
822
|
+
return {
|
|
823
|
+
list: async () => this.request("GET", `${this.projectPath}/metadata-fields`),
|
|
824
|
+
ensure: async (options) => this.request("PUT", `${this.projectPath}/metadata-fields`, { body: checked("metadataFields.ensure", options) }),
|
|
825
|
+
/** Deletes a field definition; assets keep their values. */
|
|
826
|
+
delete: async (options) => {
|
|
827
|
+
const { fieldId, ...query } = checked("metadataFields.delete", options);
|
|
828
|
+
await this.request("DELETE", `${this.projectPath}/metadata-fields/${requireId(fieldId, "Metadata field ID")}`, { query });
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
776
833
|
* The project's lenses: named image transforms the CDN applies at `/@<identifier>`. The CDN
|
|
777
834
|
* serves files made with each lens's current definition. `ensureLenses` creates or changes
|
|
778
835
|
* lenses by identifier, for applications that declare theirs in code.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { d as HashListEntry, u as HashList } from "./Classification-Q5zGpR8l-CEWjnE39.js";
|
|
2
|
-
import { $ as
|
|
3
|
-
import "./WebhookPayload-
|
|
2
|
+
import { $ as GetAssetInfoOptions, $t as UpgradePolicyOptions, Bt as SetPolicyAutomaticUpdatesOptions, Ct as ListHashListEntriesOptions, Dt as ListUploadPresetsOptions, E as BatchAssetsResponse, En as ProjectSettingsResource, Et as ListPoliciesOptions, F as ClassifyTextOptions, Ft as RequestOptions, G as EnsureLensOptions, H as DecideAssetOptions, Ht as SignUploadTokenOptions, It as ResetPolicyOptions, J as EnsureUploadPresetsOptions, Jt as UpdateFolderOptions, K as EnsureLensesOptions, Kt as SubmitAssetOptions, L as CreateFolderOptions, Ln as Policy, Lt as RetrieveAssetOptions, Mt as PolicyIdOptions, N as CdnServeOptions, Nt as PolicyPage, O as CalmLensServerClientOptions, On as UploadPreset, Ot as MoveAssetOptions, Pt as RemoveAssetContentOptions, Q as FolderPage, Qt as UpdateProjectSettingsOptions, R as CreateHashListOptions, Rt as RetryAssetOptions, St as ListFoldersOptions, T as BatchAssetsOptions, Tn as MetadataFieldsResource, Tt as ListLensesOptions, U as DeleteAssetOptions, Un as AssetInfo, Ut as SignedAssetUrl, V as CreatePolicyOptions, Vn as AssetSearchQuery, Vt as SignAssetUrlOptions, W as DeleteMetadataFieldOptions, Wt as SignedUploadToken, X as ExplainAssetOptions, Xt as UpdateLensOptions, Y as EnsureUploadPresetsResponse, Yt as UpdateHashListOptions, Z as FolderIdOptions, Zt as UpdatePolicyOptions, _ as AssetSearchResponse, _t as LensPage, a as AssetChildrenPage, bt as ListAssetsOptions, cn as WaitForAssetDecisionOptions, ct as IterateAssetsOptions, dt as IterateHashListsOptions, en as UploadAssetPartOptions, et as HashListEntryIdOptions, ft as IterateLensesOptions, g as AssetPage, gt as LensIdOptions, ht as Lens, j as CdnAssetUrlOptions, kt as MoveFolderOptions, lt as IterateFoldersOptions, mt as IterateUploadPresetsOptions, n as Asset, nn as UploadPresetIdOptions, nt as HashListIdOptions, on as VerifyWebhookSignatureOptions, ot as IterateAssetChildrenOptions, pn as GetEventsResponse, pt as IteratePoliciesOptions, q as EnsureMetadataFieldsOptions, qt as UpdateAssetOptions, rn as UploadPresetPage, rt as HashListPage, st as IterateAssetTimelineOptions, t as AddHashListEntryOptions, tt as HashListEntryPage, ut as IterateHashListEntriesOptions, vt as ListAssetChildrenOptions, w as AssignPolicyOptions, wn as Folder, wt as ListHashListsOptions, xt as ListEventsOptions, y as AssetTimelinePage, yt as ListAssetTimelineOptions, z as CreateLensOptions } from "./CalmLensTypes-BDKwThbO.js";
|
|
3
|
+
import "./WebhookPayload-Dt6DttS0.js";
|
|
4
4
|
interface LensCache {
|
|
5
5
|
readonly ensuredLenses: Map<string, Lens>;
|
|
6
6
|
readonly pendingEnsureLenses: Map<string, Promise<void>>;
|
|
@@ -282,6 +282,42 @@ declare class CalmLensServerClient {
|
|
|
282
282
|
/** Chooses the policy the project moderates with. */
|
|
283
283
|
assign: (options: AssignPolicyOptions) => Promise<Policy>;
|
|
284
284
|
};
|
|
285
|
+
/**
|
|
286
|
+
* The project's upload presets: the rules for uploads from browsers and apps. `ensure` creates or
|
|
287
|
+
* replaces presets by key, for deploys that declare them in code; send each preset's `revision`
|
|
288
|
+
* to refuse a change made since you read it.
|
|
289
|
+
*/
|
|
290
|
+
get uploadPresets(): {
|
|
291
|
+
/** Lists one page of the project's upload presets, oldest first unless `sort` says otherwise. */
|
|
292
|
+
list: (options?: ListUploadPresetsOptions) => Promise<UploadPresetPage>;
|
|
293
|
+
/** Yields every upload preset of the project, fetching pages as needed. */
|
|
294
|
+
iterate: (options?: IterateUploadPresetsOptions) => AsyncGenerator<UploadPreset, void, undefined>;
|
|
295
|
+
/**
|
|
296
|
+
* Creates each preset, or replaces it with the definition sent, by key. Every preset is
|
|
297
|
+
* checked before any is saved. Returns the stored presets in the order sent.
|
|
298
|
+
*/
|
|
299
|
+
ensure: (options: EnsureUploadPresetsOptions) => Promise<EnsureUploadPresetsResponse>;
|
|
300
|
+
/** Deletes an upload preset; assets already uploaded through it stay. */
|
|
301
|
+
delete: (options: UploadPresetIdOptions) => Promise<void>;
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* The project's settings, with defaults filled in. `update` replaces them: settings left out
|
|
305
|
+
* return to their defaults. Send the `revision` you read to refuse a change made since.
|
|
306
|
+
*/
|
|
307
|
+
get projectSettings(): {
|
|
308
|
+
get: () => Promise<ProjectSettingsResource>;
|
|
309
|
+
update: (options: UpdateProjectSettingsOptions) => Promise<ProjectSettingsResource>;
|
|
310
|
+
};
|
|
311
|
+
/**
|
|
312
|
+
* The project's metadata fields. They share the project settings' `revision`; `ensure` creates
|
|
313
|
+
* or replaces fields by ID and keeps the others.
|
|
314
|
+
*/
|
|
315
|
+
get metadataFields(): {
|
|
316
|
+
list: () => Promise<MetadataFieldsResource>;
|
|
317
|
+
ensure: (options: EnsureMetadataFieldsOptions) => Promise<MetadataFieldsResource>;
|
|
318
|
+
/** Deletes a field definition; assets keep their values. */
|
|
319
|
+
delete: (options: DeleteMetadataFieldOptions) => Promise<void>;
|
|
320
|
+
};
|
|
285
321
|
/**
|
|
286
322
|
* The project's lenses: named image transforms the CDN applies at `/@<identifier>`. The CDN
|
|
287
323
|
* serves files made with each lens's current definition. `ensureLenses` creates or changes
|