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
package/cjs/testing.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const require_ModerationContextLimits = require("./ModerationContextLimits-
|
|
4
|
-
const require_CalmLensServerClient = require("./CalmLensServerClient-
|
|
5
|
-
const require_CalmLensOptionKeys = require("./CalmLensOptionKeys-
|
|
2
|
+
const require_TestTriggers_D29T_R0M = require("./TestTriggers-D29T_R0M-D6Bu-Mln.js");
|
|
3
|
+
const require_ModerationContextLimits = require("./ModerationContextLimits-ud1xpZRK.js");
|
|
4
|
+
const require_CalmLensServerClient = require("./CalmLensServerClient-3N-gdsxC.js");
|
|
5
|
+
const require_CalmLensOptionKeys = require("./CalmLensOptionKeys-YvgV995V.js");
|
|
6
6
|
const require_CryptoUtils_B_x8lMIx = require("./CryptoUtils-B_x8lMIx-YBW1-bvL.js");
|
|
7
|
-
const require_CalmLensAppClient = require("./CalmLensAppClient-
|
|
8
|
-
const require_UploadController = require("./UploadController-
|
|
7
|
+
const require_CalmLensAppClient = require("./CalmLensAppClient-DUYMo9PZ.js");
|
|
8
|
+
const require_UploadController = require("./UploadController-l8fZM2qT.js");
|
|
9
9
|
let zod = require("zod");
|
|
10
|
-
zod =
|
|
10
|
+
zod = require_TestTriggers_D29T_R0M.__toESM(zod, 1);
|
|
11
11
|
// src/contract/MediaTestTriggers.js
|
|
12
|
-
const MEDIA_TEST_SIGNALS = [...
|
|
12
|
+
const MEDIA_TEST_SIGNALS = [...require_TestTriggers_D29T_R0M.CLASSIFICATION_CATEGORIES, "violence.graphic"];
|
|
13
13
|
const HEX_WORDS = [
|
|
14
14
|
"zero",
|
|
15
15
|
"one",
|
|
@@ -31,7 +31,7 @@ const HEX_WORDS = [
|
|
|
31
31
|
/** Read this aloud, or render it as large, high-contrast text in a video frame. */
|
|
32
32
|
async function generateMediaTestCode(signal, testInputKey) {
|
|
33
33
|
if (!MEDIA_TEST_SIGNALS.includes(signal)) throw new RangeError("Unsupported media test signal");
|
|
34
|
-
return `Calm Lens test ${[...await
|
|
34
|
+
return `Calm Lens test ${[...await require_TestTriggers_D29T_R0M.getTestInputTag("media", signal, testInputKey)].map((character) => HEX_WORDS[Number.parseInt(character, 16)]).join(" ")} ${signal.replace(/[.-]/g, " ")} end test`;
|
|
35
35
|
}
|
|
36
36
|
// src/contract/Ids-BESMSxGb.js
|
|
37
37
|
var __defProp = Object.defineProperty;
|
|
@@ -7989,7 +7989,7 @@ const EXAMPLE_IDS = {
|
|
|
7989
7989
|
* across the packages that build records from plain strings).
|
|
7990
7990
|
*/
|
|
7991
7991
|
const idField = (prefix) => zod.string().regex(idPattern(prefix), { message: `Must be a valid ID: "${prefix}_" followed by 20 letters or digits` }).meta({ examples: [EXAMPLE_IDS[prefix]] });
|
|
7992
|
-
// src/contract/Permissions-
|
|
7992
|
+
// src/contract/Permissions-DPNlE8m-.js
|
|
7993
7993
|
const ACTION_SCHEMA = zod.enum([
|
|
7994
7994
|
"assets:read",
|
|
7995
7995
|
"assets:download",
|
|
@@ -8046,10 +8046,13 @@ const GRANT_SCHEMA = zod.object({
|
|
|
8046
8046
|
const GRANTS_SCHEMA = zod.array(GRANT_SCHEMA).max(100);
|
|
8047
8047
|
zod.enum([
|
|
8048
8048
|
"admin",
|
|
8049
|
+
"configurator",
|
|
8049
8050
|
"editor",
|
|
8050
8051
|
"viewer",
|
|
8051
8052
|
"custom"
|
|
8052
8053
|
]);
|
|
8054
|
+
[...ACTION_SCHEMA.options.filter((a) => !isProjectAction(a))];
|
|
8055
|
+
[...ACTION_SCHEMA.options.filter((a) => !isProjectAction(a))];
|
|
8053
8056
|
const permits = (grants, action, folderId, folders) => grants.some((grant) => {
|
|
8054
8057
|
if (![action, ...actionsImplying(action)].some((held) => grant.actions.includes(held))) return false;
|
|
8055
8058
|
if (grant.folderId === null) return true;
|
|
@@ -8355,6 +8358,8 @@ var MockDecision = class {
|
|
|
8355
8358
|
action: action(score)
|
|
8356
8359
|
}])),
|
|
8357
8360
|
explanationComplete: true,
|
|
8361
|
+
policy: null,
|
|
8362
|
+
pendingReview: null,
|
|
8358
8363
|
source: "policy",
|
|
8359
8364
|
rule: null,
|
|
8360
8365
|
automatedStatus: status,
|
|
@@ -9145,7 +9150,16 @@ const MOCK_OPERATIONS = [
|
|
|
9145
9150
|
"lenses.update",
|
|
9146
9151
|
"lenses.delete",
|
|
9147
9152
|
"ensureLens",
|
|
9148
|
-
"ensureLenses"
|
|
9153
|
+
"ensureLenses",
|
|
9154
|
+
"uploadPresets.list",
|
|
9155
|
+
"uploadPresets.iterate",
|
|
9156
|
+
"uploadPresets.ensure",
|
|
9157
|
+
"uploadPresets.delete",
|
|
9158
|
+
"projectSettings.get",
|
|
9159
|
+
"projectSettings.update",
|
|
9160
|
+
"metadataFields.list",
|
|
9161
|
+
"metadataFields.ensure",
|
|
9162
|
+
"metadataFields.delete"
|
|
9149
9163
|
];
|
|
9150
9164
|
const MAX_PAGE_SIZE = 100;
|
|
9151
9165
|
const MAX_DECISION_NOTE_LENGTH = 1499;
|
|
@@ -9228,7 +9242,8 @@ const mockPlaceholderPng = (thumbhash) => Uint8Array.from(atob(require_UploadCon
|
|
|
9228
9242
|
const NO_RENDERING = {
|
|
9229
9243
|
rendered: null,
|
|
9230
9244
|
preview: null,
|
|
9231
|
-
hls: null
|
|
9245
|
+
hls: null,
|
|
9246
|
+
hlsStatus: null
|
|
9232
9247
|
};
|
|
9233
9248
|
/** The size of the waveform the API makes as an audio asset's preview. */
|
|
9234
9249
|
const WAVEFORM_SIZE = {
|
|
@@ -9286,7 +9301,8 @@ const mockRendering = (asset, processed) => {
|
|
|
9286
9301
|
...unsized
|
|
9287
9302
|
},
|
|
9288
9303
|
preview: preview(unsized),
|
|
9289
|
-
hls: null
|
|
9304
|
+
hls: null,
|
|
9305
|
+
hlsStatus: null
|
|
9290
9306
|
};
|
|
9291
9307
|
case "website": return {
|
|
9292
9308
|
rendered: {
|
|
@@ -9295,7 +9311,8 @@ const mockRendering = (asset, processed) => {
|
|
|
9295
9311
|
...unsized
|
|
9296
9312
|
},
|
|
9297
9313
|
preview: preview(unsized),
|
|
9298
|
-
hls: null
|
|
9314
|
+
hls: null,
|
|
9315
|
+
hlsStatus: null
|
|
9299
9316
|
};
|
|
9300
9317
|
case "multimedia-document":
|
|
9301
9318
|
if (SPREADSHEET_MIME_TYPES.includes(mimeType)) return NO_RENDERING;
|
|
@@ -9306,7 +9323,8 @@ const mockRendering = (asset, processed) => {
|
|
|
9306
9323
|
...unsized
|
|
9307
9324
|
},
|
|
9308
9325
|
preview: processed ? preview(unsized) : null,
|
|
9309
|
-
hls: null
|
|
9326
|
+
hls: null,
|
|
9327
|
+
hlsStatus: null
|
|
9310
9328
|
};
|
|
9311
9329
|
case "video": return {
|
|
9312
9330
|
rendered: {
|
|
@@ -9315,7 +9333,8 @@ const mockRendering = (asset, processed) => {
|
|
|
9315
9333
|
...unsized
|
|
9316
9334
|
},
|
|
9317
9335
|
preview: null,
|
|
9318
|
-
hls: null
|
|
9336
|
+
hls: null,
|
|
9337
|
+
hlsStatus: null
|
|
9319
9338
|
};
|
|
9320
9339
|
case "audio": return {
|
|
9321
9340
|
rendered: {
|
|
@@ -9325,7 +9344,8 @@ const mockRendering = (asset, processed) => {
|
|
|
9325
9344
|
...processed && { peaks: [] }
|
|
9326
9345
|
},
|
|
9327
9346
|
preview: processed ? preview(WAVEFORM_SIZE) : null,
|
|
9328
|
-
hls: null
|
|
9347
|
+
hls: null,
|
|
9348
|
+
hlsStatus: null
|
|
9329
9349
|
};
|
|
9330
9350
|
default: return NO_RENDERING;
|
|
9331
9351
|
}
|
|
@@ -9384,6 +9404,74 @@ const invalidField = (code, path) => new ApiFailure(400, require_ModerationConte
|
|
|
9384
9404
|
message: `Invalid ${path}`,
|
|
9385
9405
|
code
|
|
9386
9406
|
}] });
|
|
9407
|
+
/** The asset fields an upload carries in its body; the API refuses them in the query string. */
|
|
9408
|
+
const UPLOAD_OPTION_KEYS = [
|
|
9409
|
+
"name",
|
|
9410
|
+
"description",
|
|
9411
|
+
"processingOptions",
|
|
9412
|
+
"visibility",
|
|
9413
|
+
"metadata",
|
|
9414
|
+
"tags",
|
|
9415
|
+
"authorId",
|
|
9416
|
+
"context",
|
|
9417
|
+
"externalId",
|
|
9418
|
+
"externalUrl",
|
|
9419
|
+
"folderId",
|
|
9420
|
+
"uploadPresetId"
|
|
9421
|
+
];
|
|
9422
|
+
const indexOfBytes = (haystack, needle, from = 0) => {
|
|
9423
|
+
for (let index = haystack.indexOf(needle[0], from); index !== -1;) {
|
|
9424
|
+
if (index + needle.length > haystack.length) return -1;
|
|
9425
|
+
let offset = 1;
|
|
9426
|
+
while (offset < needle.length && haystack[index + offset] === needle[offset]) offset++;
|
|
9427
|
+
if (offset === needle.length) return index;
|
|
9428
|
+
index = haystack.indexOf(needle[0], index + 1);
|
|
9429
|
+
}
|
|
9430
|
+
return -1;
|
|
9431
|
+
};
|
|
9432
|
+
/**
|
|
9433
|
+
* Reads a raw upload's `multipart/form-data` body like the API: an `options` part, then a `file`
|
|
9434
|
+
* part, then the closing boundary. Anything else is refused.
|
|
9435
|
+
*/
|
|
9436
|
+
const readUploadForm = (request) => {
|
|
9437
|
+
const contentType = request.headers.get("content-type") ?? "";
|
|
9438
|
+
if (contentType.split(";")[0].trim().toLowerCase() !== "multipart/form-data") throw new ApiFailure(415, require_ModerationContextLimits.API_ERROR_CODES.UNSUPPORTED_CONTENT_TYPE, "Send a raw upload as multipart/form-data: an options part, then a file part.", { contentType: contentType.split(";")[0].trim() || null });
|
|
9439
|
+
const boundary = /;\s*boundary=(?:"([^"]+)"|([^;\s]+))/i.exec(contentType);
|
|
9440
|
+
const invalid = (message) => fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message });
|
|
9441
|
+
if (!boundary) throw invalid("The multipart/form-data Content-Type needs a boundary");
|
|
9442
|
+
const encoder = new TextEncoder();
|
|
9443
|
+
const delimiter = encoder.encode(`\r\n--${boundary[1] ?? boundary[2]}`);
|
|
9444
|
+
const body = new Uint8Array(2 + request.bytes.length);
|
|
9445
|
+
body.set(encoder.encode("\r\n"));
|
|
9446
|
+
body.set(request.bytes, 2);
|
|
9447
|
+
const parts = [];
|
|
9448
|
+
let at = indexOfBytes(body, delimiter);
|
|
9449
|
+
while (at !== -1) {
|
|
9450
|
+
const start = at + delimiter.length;
|
|
9451
|
+
if (body[start] === 45 && body[start + 1] === 45) break;
|
|
9452
|
+
const headerEnd = indexOfBytes(body, encoder.encode("\r\n\r\n"), start);
|
|
9453
|
+
const next = headerEnd === -1 ? -1 : indexOfBytes(body, delimiter, headerEnd + 4);
|
|
9454
|
+
if (next === -1) throw invalid("The upload body ended before its closing boundary");
|
|
9455
|
+
const headers = new TextDecoder().decode(body.slice(start, headerEnd));
|
|
9456
|
+
const name = /content-disposition:\s*form-data\s*;[^\r\n]*?\bname="([^"]*)"/i.exec(headers)?.[1];
|
|
9457
|
+
parts.push({
|
|
9458
|
+
name,
|
|
9459
|
+
content: body.slice(headerEnd + 4, next)
|
|
9460
|
+
});
|
|
9461
|
+
at = next;
|
|
9462
|
+
}
|
|
9463
|
+
if (at === -1) throw invalid("The upload body ended before its closing boundary");
|
|
9464
|
+
if (parts.length !== 2 || parts[0].name !== "options" || parts[1].name !== "file") throw invalid("The upload form must hold an options part, then a file part");
|
|
9465
|
+
return {
|
|
9466
|
+
options: new TextDecoder().decode(parts[0].content),
|
|
9467
|
+
bytes: parts[1].content
|
|
9468
|
+
};
|
|
9469
|
+
};
|
|
9470
|
+
/** A request that names asset fields in its query, which the API refuses. */
|
|
9471
|
+
const assertNoUploadOptionsInQuery = (query) => {
|
|
9472
|
+
const fields = UPLOAD_OPTION_KEYS.filter((key) => query.has(key));
|
|
9473
|
+
if (fields.length) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_OPTIONS_IN_QUERY, { details: { fields } });
|
|
9474
|
+
};
|
|
9387
9475
|
/**
|
|
9388
9476
|
* Refuses `metadata` the API's schema refuses (METADATA_ITEM_SCHEMA): it is `null` or a list of
|
|
9389
9477
|
* `{ id, value }` objects with a string `id` and any JSON `value`.
|
|
@@ -9409,7 +9497,7 @@ const MOCK_PRESET_NAMES = {
|
|
|
9409
9497
|
* personal information and profanity, `block` otherwise) and no rules. The mock holds no built-in
|
|
9410
9498
|
* preset settings, and uploads are never decided by a policy.
|
|
9411
9499
|
*/
|
|
9412
|
-
const mockPresetSettings = () => ({ categorySettings: Object.fromEntries(
|
|
9500
|
+
const mockPresetSettings = () => ({ categorySettings: Object.fromEntries(require_TestTriggers_D29T_R0M.CLASSIFICATION_CATEGORIES.map((category) => [category, {
|
|
9413
9501
|
action: category === "personal-information" || category === "profanity" ? "allow" : "block",
|
|
9414
9502
|
allowances: [],
|
|
9415
9503
|
restrictions: []
|
|
@@ -9421,13 +9509,13 @@ const mockPresetSettings = () => ({ categorySettings: Object.fromEntries(require
|
|
|
9421
9509
|
const checkPolicySettings = (settings) => {
|
|
9422
9510
|
const categories = settings?.categorySettings;
|
|
9423
9511
|
if (!categories || typeof categories !== "object") throw invalidField("validation/invalid-type", "settings.categorySettings");
|
|
9424
|
-
for (const category of
|
|
9512
|
+
for (const category of require_TestTriggers_D29T_R0M.CLASSIFICATION_CATEGORIES) {
|
|
9425
9513
|
const value = categories[category];
|
|
9426
9514
|
if (!value || typeof value !== "object") throw invalidField("validation/invalid-type", `settings.categorySettings.${category}`);
|
|
9427
9515
|
for (const key of ["allowances", "restrictions"]) if (!Array.isArray(value[key])) throw invalidField("validation/invalid-type", `settings.categorySettings.${category}.${key}`);
|
|
9428
9516
|
if (typeof value.action !== "string") throw invalidField("validation/invalid-value", `settings.categorySettings.${category}.action`);
|
|
9429
9517
|
}
|
|
9430
|
-
for (const key of Object.keys(categories)) if (!
|
|
9518
|
+
for (const key of Object.keys(categories)) if (!require_TestTriggers_D29T_R0M.CLASSIFICATION_CATEGORIES.includes(key)) throw invalidField("validation/unknown-field", `settings.categorySettings.${key}`);
|
|
9431
9519
|
};
|
|
9432
9520
|
/** The client methods that send a request, the one it is recorded under first. */
|
|
9433
9521
|
const operationsOf = (request) => {
|
|
@@ -9441,6 +9529,9 @@ const operationsOf = (request) => {
|
|
|
9441
9529
|
case "folders": return method === "GET" ? ["folders.list", "folders.iterate"] : ["folders.create"];
|
|
9442
9530
|
case "hash-lists": return method === "GET" ? ["hashLists.list", "hashLists.iterate"] : ["hashLists.create"];
|
|
9443
9531
|
case "policy": return method === "GET" ? ["policies.retrieveAssigned"] : ["policies.assign"];
|
|
9532
|
+
case "upload-presets": return method === "GET" ? ["uploadPresets.list", "uploadPresets.iterate"] : ["uploadPresets.ensure"];
|
|
9533
|
+
case "settings": return method === "GET" ? ["projectSettings.get"] : ["projectSettings.update"];
|
|
9534
|
+
case "metadata-fields": return method === "GET" ? ["metadataFields.list"] : ["metadataFields.ensure"];
|
|
9444
9535
|
case "assets/search": return ["assets.search"];
|
|
9445
9536
|
case "assets/batch": return ["assets.batch"];
|
|
9446
9537
|
case "signed-asset-urls": return ["cdn.signAssetUrl"];
|
|
@@ -9450,6 +9541,7 @@ const operationsOf = (request) => {
|
|
|
9450
9541
|
return isTextUpload(request) ? ["assets.classify", "text.classify"] : ["assets.classify"];
|
|
9451
9542
|
}
|
|
9452
9543
|
if (segments[2] === "assets" && segments[4] === "timeline" && segments.length === 5) return ["assets.listTimeline", "assets.iterateTimeline"];
|
|
9544
|
+
if (segments[2] === "metadata-fields" && segments.length === 4) return ["metadataFields.delete"];
|
|
9453
9545
|
return [];
|
|
9454
9546
|
}
|
|
9455
9547
|
if (root === "policies") {
|
|
@@ -9461,6 +9553,7 @@ const operationsOf = (request) => {
|
|
|
9461
9553
|
return method === "GET" ? ["policies.retrieve"] : method === "PATCH" ? ["policies.update"] : ["policies.delete"];
|
|
9462
9554
|
}
|
|
9463
9555
|
if (root === "lenses" && segments[1] !== void 0) return method === "GET" ? ["lenses.retrieve"] : method === "PATCH" ? ["lenses.update"] : ["lenses.delete"];
|
|
9556
|
+
if (root === "upload-presets" && segments.length === 2) return ["uploadPresets.delete"];
|
|
9464
9557
|
if (root === "upload-presets") {
|
|
9465
9558
|
if (segments[3] === void 0) return [query.get("wait") === "false" ? "assets.create" : "assets.classify"];
|
|
9466
9559
|
return segments[4] === "part" ? ["assets.uploadPart"] : ["assets.retrieve"];
|
|
@@ -9489,7 +9582,15 @@ const operationsOf = (request) => {
|
|
|
9489
9582
|
}
|
|
9490
9583
|
return [];
|
|
9491
9584
|
};
|
|
9492
|
-
|
|
9585
|
+
/** A plain-text upload: the SDKs send text as a JSON body with `content.plainText`. */
|
|
9586
|
+
const isTextUpload = (request) => {
|
|
9587
|
+
if (request.headers.get("x-calmlens-upload")) return false;
|
|
9588
|
+
try {
|
|
9589
|
+
return typeof JSON.parse(new TextDecoder().decode(request.bytes))?.content?.plainText === "string";
|
|
9590
|
+
} catch {
|
|
9591
|
+
return false;
|
|
9592
|
+
}
|
|
9593
|
+
};
|
|
9493
9594
|
/** Like the API: a new folder is 201 Created, a queued batch 202 Accepted, everything else 200. */
|
|
9494
9595
|
const SUCCESS_STATUS = {
|
|
9495
9596
|
"folders.create": 201,
|
|
@@ -9533,6 +9634,10 @@ var MockCalmLensApi = class {
|
|
|
9533
9634
|
this.hashLists = /* @__PURE__ */ new Map();
|
|
9534
9635
|
this.hashListEntries = /* @__PURE__ */ new Map();
|
|
9535
9636
|
this.pageFailure = (code, path) => code === "cursor/invalid" ? fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_CURSOR) : invalidField(code, path ?? "pageSize");
|
|
9637
|
+
this.configuredPresets = /* @__PURE__ */ new Map();
|
|
9638
|
+
this.settingsRevision = 1;
|
|
9639
|
+
this.projectSettingsValues = {};
|
|
9640
|
+
this.metadataFieldList = [];
|
|
9536
9641
|
this.options = options;
|
|
9537
9642
|
this.projectId = options.projectId;
|
|
9538
9643
|
this.apiKey = options.apiKey;
|
|
@@ -9774,9 +9879,20 @@ var MockCalmLensApi = class {
|
|
|
9774
9879
|
}
|
|
9775
9880
|
return failure;
|
|
9776
9881
|
}
|
|
9777
|
-
describeBody(
|
|
9882
|
+
describeBody(request) {
|
|
9883
|
+
const { bytes, headers } = request;
|
|
9778
9884
|
if (bytes.byteLength === 0) return void 0;
|
|
9779
9885
|
const type = headers.get("content-type") ?? "";
|
|
9886
|
+
if (type.startsWith("multipart/form-data")) try {
|
|
9887
|
+
const form = readUploadForm(request);
|
|
9888
|
+
const file = request.query.get("contentType") ?? "";
|
|
9889
|
+
return {
|
|
9890
|
+
options: JSON.parse(form.options),
|
|
9891
|
+
file: file.startsWith("text/") ? new TextDecoder().decode(form.bytes) : form.bytes.slice()
|
|
9892
|
+
};
|
|
9893
|
+
} catch {
|
|
9894
|
+
return bytes.slice();
|
|
9895
|
+
}
|
|
9780
9896
|
const text = () => new TextDecoder().decode(bytes);
|
|
9781
9897
|
if (type === "application/json") try {
|
|
9782
9898
|
return JSON.parse(text());
|
|
@@ -9818,13 +9934,20 @@ var MockCalmLensApi = class {
|
|
|
9818
9934
|
if (!(request.segments[0] === "upload-presets") && headers.get("x-api-key") !== this.apiKey) return this.failureResponse(fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_API_KEY), url);
|
|
9819
9935
|
const key = headers.get("idempotency-key")?.replace(/^[\t\n\r ]+|[\t\n\r ]+$/g, "");
|
|
9820
9936
|
const upload = headers.get("x-calmlens-upload");
|
|
9937
|
+
const contentType = headers.get("content-type");
|
|
9938
|
+
const isForm = !!upload && /^multipart\/form-data\b/i.test(contentType ?? "");
|
|
9939
|
+
let formOptions;
|
|
9940
|
+
if (isForm && request.segments.at(-1) !== "part") try {
|
|
9941
|
+
formOptions = readUploadForm(request).options;
|
|
9942
|
+
} catch {}
|
|
9821
9943
|
const fingerprint = JSON.stringify([
|
|
9822
9944
|
request.method,
|
|
9823
9945
|
request.segments,
|
|
9824
9946
|
[...request.query].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0),
|
|
9825
|
-
|
|
9947
|
+
isForm ? "multipart/form-data" : contentType,
|
|
9826
9948
|
upload,
|
|
9827
|
-
upload ? request.bytes.byteLength : new TextDecoder().decode(request.bytes)
|
|
9949
|
+
upload ? request.bytes.byteLength : new TextDecoder().decode(request.bytes),
|
|
9950
|
+
formOptions ?? null
|
|
9828
9951
|
]);
|
|
9829
9952
|
if (key !== void 0) {
|
|
9830
9953
|
if (!isValidIdempotencyKey(key)) return this.failureResponse(fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_IDEMPOTENCY_KEY), url);
|
|
@@ -9875,8 +9998,17 @@ var MockCalmLensApi = class {
|
|
|
9875
9998
|
case "POST lenses": return [201, this.createLens(this.json(request))];
|
|
9876
9999
|
case "GET policy": return [200, this.toPolicy(this.findPolicy(this.ensurePolicies()))];
|
|
9877
10000
|
case "PUT policy": return [200, this.assignPolicy(this.json(request))];
|
|
10001
|
+
case "GET upload-presets": return [200, this.listUploadPresets(request.query)];
|
|
10002
|
+
case "PUT upload-presets": return [200, this.ensureUploadPresets(this.json(request))];
|
|
10003
|
+
case "GET settings": return [200, this.toProjectSettings()];
|
|
10004
|
+
case "PUT settings": return [200, this.updateProjectSettings(this.json(request))];
|
|
10005
|
+
case "GET metadata-fields": return [200, this.toMetadataFields()];
|
|
10006
|
+
case "PUT metadata-fields": return [200, this.ensureMetadataFields(this.json(request))];
|
|
9878
10007
|
}
|
|
9879
10008
|
const [, , collection, itemId, itemAction, ...more] = segments;
|
|
10009
|
+
if (collection === "metadata-fields" && itemId !== void 0 && itemAction === void 0) {
|
|
10010
|
+
if (method === "DELETE") return [200, this.deleteMetadataField(itemId, request.query)];
|
|
10011
|
+
}
|
|
9880
10012
|
if (collection === "assets" && itemId !== void 0 && itemAction === "timeline" && more.length === 0 && method === "GET") return [200, await this.listTimeline(itemId, request.query)];
|
|
9881
10013
|
}
|
|
9882
10014
|
if (root === "policies" && rest.length === 0) {
|
|
@@ -9897,6 +10029,9 @@ var MockCalmLensApi = class {
|
|
|
9897
10029
|
case "PATCH": return [200, this.updateLens(id, this.json(request))];
|
|
9898
10030
|
case "DELETE": return [200, this.deleteLens(id)];
|
|
9899
10031
|
}
|
|
10032
|
+
if (root === "upload-presets" && id !== void 0 && action === void 0) {
|
|
10033
|
+
if (method === "DELETE") return [200, this.deleteUploadPreset(id)];
|
|
10034
|
+
}
|
|
9900
10035
|
if (root === "upload-presets" && id !== void 0 && action === "assets") return [200, await this.presetRoute(request, id, rest, session)];
|
|
9901
10036
|
if (root === "assets" && id !== void 0 && rest.length === 0) switch (`${method} ${action ?? ""}`) {
|
|
9902
10037
|
case "GET ": return [200, await this.findOwnAsset(id)];
|
|
@@ -10452,42 +10587,49 @@ var MockCalmLensApi = class {
|
|
|
10452
10587
|
await this.databaseStorage.deleteAsset(id);
|
|
10453
10588
|
}
|
|
10454
10589
|
}
|
|
10455
|
-
/**
|
|
10590
|
+
/**
|
|
10591
|
+
* The upload fields of `POST .../assets`, from the JSON body (text and URLs) or an upload form's
|
|
10592
|
+
* options (files). Like the API, asset fields in the query are refused.
|
|
10593
|
+
*/
|
|
10456
10594
|
uploadFields(request) {
|
|
10595
|
+
const { query } = request;
|
|
10596
|
+
assertNoUploadOptionsInQuery(query);
|
|
10457
10597
|
const upload = request.headers.get("x-calmlens-upload");
|
|
10458
10598
|
if (upload !== "content" && upload !== "part") {
|
|
10459
10599
|
const body = this.json(request);
|
|
10460
10600
|
checkMetadata(body.metadata);
|
|
10461
|
-
|
|
10601
|
+
const { content, part, sizeInBytes: _size, totalSizeInBytes, ...fields } = body;
|
|
10602
|
+
const text = content ?? part;
|
|
10603
|
+
if (text === void 0) return fields;
|
|
10604
|
+
if (typeof text.plainText !== "string" || typeof text.type !== "string") throw invalidField("validation/invalid-type", content ? "content" : "part");
|
|
10605
|
+
return {
|
|
10606
|
+
...fields,
|
|
10607
|
+
contentType: text.type,
|
|
10608
|
+
bytes: new TextEncoder().encode(text.plainText),
|
|
10609
|
+
part: part ? {
|
|
10610
|
+
partNumber: typeof part.partNumber === "number" ? part.partNumber : 1,
|
|
10611
|
+
isFinal: part.isFinal === true,
|
|
10612
|
+
totalSizeInBytes: typeof totalSizeInBytes === "number" ? totalSizeInBytes : void 0
|
|
10613
|
+
} : void 0
|
|
10614
|
+
};
|
|
10462
10615
|
}
|
|
10463
|
-
const
|
|
10464
|
-
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
|
|
10468
|
-
|
|
10469
|
-
|
|
10470
|
-
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10616
|
+
const form = readUploadForm(request);
|
|
10617
|
+
let options;
|
|
10618
|
+
try {
|
|
10619
|
+
options = JSON.parse(form.options);
|
|
10620
|
+
} catch {
|
|
10621
|
+
throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "The options part must be a JSON object with the asset's fields" });
|
|
10622
|
+
}
|
|
10623
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "The options part must be a JSON object with the asset's fields" });
|
|
10624
|
+
const unknown = Object.keys(options).find((key) => !UPLOAD_OPTION_KEYS.includes(key));
|
|
10625
|
+
if (unknown !== void 0) throw invalidField("validation/unknown-field", unknown);
|
|
10626
|
+
if (typeof options.name !== "string") throw invalidField("validation/invalid-type", "name");
|
|
10627
|
+
checkMetadata(options.metadata);
|
|
10474
10628
|
const total = query.get("totalSizeInBytes");
|
|
10475
|
-
checkMetadata(parsed("metadata"));
|
|
10476
10629
|
return {
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
visibility: text("visibility"),
|
|
10481
|
-
metadata: parsed("metadata"),
|
|
10482
|
-
tags: parsed("tags"),
|
|
10483
|
-
authorId: text("authorId"),
|
|
10484
|
-
context: parsed("context"),
|
|
10485
|
-
externalId: text("externalId"),
|
|
10486
|
-
externalUrl: text("externalUrl"),
|
|
10487
|
-
folderId: text("folderId"),
|
|
10488
|
-
uploadPresetId: text("uploadPresetId"),
|
|
10489
|
-
contentType: query.get("contentType") ?? request.headers.get("content-type") ?? "",
|
|
10490
|
-
bytes: request.bytes,
|
|
10630
|
+
...options,
|
|
10631
|
+
contentType: query.get("contentType") ?? "",
|
|
10632
|
+
bytes: form.bytes,
|
|
10491
10633
|
part: upload === "part" ? {
|
|
10492
10634
|
partNumber: this.integer(query, "partNumber", 1),
|
|
10493
10635
|
isFinal: query.get("isFinal") === "true",
|
|
@@ -10541,6 +10683,7 @@ var MockCalmLensApi = class {
|
|
|
10541
10683
|
id,
|
|
10542
10684
|
projectId: this.projectId,
|
|
10543
10685
|
parentId: null,
|
|
10686
|
+
parentPages: [],
|
|
10544
10687
|
folderId: fields.folderId ?? null,
|
|
10545
10688
|
uploadPresetId: fields.uploadPresetId ?? null,
|
|
10546
10689
|
createdAt: now,
|
|
@@ -10590,6 +10733,8 @@ var MockCalmLensApi = class {
|
|
|
10590
10733
|
status: "pending",
|
|
10591
10734
|
manualReviews: [],
|
|
10592
10735
|
automatedStatus: null,
|
|
10736
|
+
policy: null,
|
|
10737
|
+
pendingReview: null,
|
|
10593
10738
|
source: null,
|
|
10594
10739
|
rule: null,
|
|
10595
10740
|
explanationComplete: null,
|
|
@@ -11162,6 +11307,139 @@ var MockCalmLensApi = class {
|
|
|
11162
11307
|
async assertUniqueFolderName(name, parentId, excludeFolderId) {
|
|
11163
11308
|
if ((await this.databaseStorage.listFolders?.(this.projectId) ?? []).find((folder) => folder.id !== excludeFolderId && (folder.parentId ?? null) === parentId && folder.name === name)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.DUPLICATE_FOLDER_NAME, { message: `A folder named "${name}" already exists in this location.` });
|
|
11164
11309
|
}
|
|
11310
|
+
/** A page of the project's upload presets, oldest first unless `sort` says otherwise. */
|
|
11311
|
+
listUploadPresets(query) {
|
|
11312
|
+
return createPage([...this.configuredPresets.values()], this.pageQuery(query), {
|
|
11313
|
+
scope: `upload-presets:${this.projectId}`,
|
|
11314
|
+
fail: this.pageFailure,
|
|
11315
|
+
defaultSort: [{
|
|
11316
|
+
field: "createdAt",
|
|
11317
|
+
direction: "asc"
|
|
11318
|
+
}]
|
|
11319
|
+
});
|
|
11320
|
+
}
|
|
11321
|
+
/** Like the API: every preset's revision and settings are checked before any is saved. */
|
|
11322
|
+
ensureUploadPresets(body) {
|
|
11323
|
+
const definitions = Array.isArray(body.uploadPresets) ? body.uploadPresets : [];
|
|
11324
|
+
if (definitions.length === 0) throw invalidField("validation/too-small", "uploadPresets");
|
|
11325
|
+
return { uploadPresets: definitions.map((definition, index) => {
|
|
11326
|
+
if (typeof definition.key !== "string" || !definition.key) throw invalidField("validation/invalid-type", `uploadPresets.${index}.key`);
|
|
11327
|
+
if (typeof definition.name !== "string" || !definition.name) throw invalidField("validation/invalid-type", `uploadPresets.${index}.name`);
|
|
11328
|
+
const existing = this.configuredPresets.get(definition.key);
|
|
11329
|
+
if (definition.revision !== void 0 && definition.revision !== (existing?.revision ?? 0)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_REVISION_CONFLICT, { details: {
|
|
11330
|
+
key: definition.key,
|
|
11331
|
+
revision: existing?.revision ?? 0
|
|
11332
|
+
} });
|
|
11333
|
+
const list = (value) => Array.isArray(value) && value.length ? [...new Set(value)] : null;
|
|
11334
|
+
const values = {
|
|
11335
|
+
key: definition.key,
|
|
11336
|
+
name: definition.name,
|
|
11337
|
+
access: definition.access ?? "token",
|
|
11338
|
+
enabled: definition.enabled ?? true,
|
|
11339
|
+
allowedContentTypes: list(definition.allowedContentTypes),
|
|
11340
|
+
maxSizeInBytes: definition.maxSizeInBytes ?? null,
|
|
11341
|
+
folderId: definition.folderId ?? null,
|
|
11342
|
+
policyId: definition.policyId ?? null,
|
|
11343
|
+
visibility: definition.visibility ?? "private",
|
|
11344
|
+
processingOptions: definition.processingOptions ?? null,
|
|
11345
|
+
revealDecision: definition.revealDecision ?? false,
|
|
11346
|
+
dailyUploadLimit: definition.dailyUploadLimit ?? null,
|
|
11347
|
+
allowedOrigins: list(definition.allowedOrigins)
|
|
11348
|
+
};
|
|
11349
|
+
if (values.access === "anyone" && !values.dailyUploadLimit) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_DAILY_LIMIT_REQUIRED);
|
|
11350
|
+
return {
|
|
11351
|
+
existing,
|
|
11352
|
+
values
|
|
11353
|
+
};
|
|
11354
|
+
}).map(({ existing, values }) => {
|
|
11355
|
+
if (existing) {
|
|
11356
|
+
if (Object.entries(values).every(([key, value]) => require_CalmLensServerClient.stringifyJsonCanonical(value) === require_CalmLensServerClient.stringifyJsonCanonical(existing[key] ?? null))) return existing;
|
|
11357
|
+
}
|
|
11358
|
+
const now = this.now();
|
|
11359
|
+
const preset = {
|
|
11360
|
+
id: existing?.id ?? this.createId("preset"),
|
|
11361
|
+
projectId: this.projectId,
|
|
11362
|
+
createdByUserId: null,
|
|
11363
|
+
...values,
|
|
11364
|
+
revision: (existing?.revision ?? 0) + 1,
|
|
11365
|
+
createdAt: existing?.createdAt ?? now,
|
|
11366
|
+
updatedAt: now
|
|
11367
|
+
};
|
|
11368
|
+
this.configuredPresets.set(preset.key, preset);
|
|
11369
|
+
return preset;
|
|
11370
|
+
}) };
|
|
11371
|
+
}
|
|
11372
|
+
deleteUploadPreset(uploadPresetId) {
|
|
11373
|
+
const preset = [...this.configuredPresets.values()].find(({ id }) => id === uploadPresetId);
|
|
11374
|
+
if (!preset) throw fail(require_ModerationContextLimits.API_ERROR_CODES.UPLOAD_PRESET_NOT_FOUND);
|
|
11375
|
+
this.configuredPresets.delete(preset.key);
|
|
11376
|
+
return {};
|
|
11377
|
+
}
|
|
11378
|
+
toProjectSettings() {
|
|
11379
|
+
return {
|
|
11380
|
+
projectId: this.projectId,
|
|
11381
|
+
revision: this.settingsRevision,
|
|
11382
|
+
settings: {
|
|
11383
|
+
optOutJurisdictions: [],
|
|
11384
|
+
blockUnmoderatedAssets: true,
|
|
11385
|
+
storeSensitiveMetadata: false,
|
|
11386
|
+
streamingEnabled: false,
|
|
11387
|
+
aiMediaSearchEnabled: false,
|
|
11388
|
+
remoteUrlRule: null,
|
|
11389
|
+
websiteSubmissionsPerMinute: null,
|
|
11390
|
+
...this.projectSettingsValues,
|
|
11391
|
+
humanReview: {
|
|
11392
|
+
allowedSamplePercent: 0,
|
|
11393
|
+
restrictedSamplePercent: 0,
|
|
11394
|
+
uncertaintyMarginPercent: 0,
|
|
11395
|
+
reviewMissingEvidence: false,
|
|
11396
|
+
...this.projectSettingsValues.humanReview
|
|
11397
|
+
}
|
|
11398
|
+
}
|
|
11399
|
+
};
|
|
11400
|
+
}
|
|
11401
|
+
checkSettingsRevision(revision) {
|
|
11402
|
+
if (revision !== void 0 && revision !== null && Number(revision) !== this.settingsRevision) throw fail(require_ModerationContextLimits.API_ERROR_CODES.PROJECT_SETTINGS_REVISION_CONFLICT);
|
|
11403
|
+
}
|
|
11404
|
+
/** Replaces the settings: those left out return to their defaults. */
|
|
11405
|
+
updateProjectSettings(body) {
|
|
11406
|
+
this.checkSettingsRevision(body.revision);
|
|
11407
|
+
const settings = body.settings;
|
|
11408
|
+
if (!settings || typeof settings !== "object" || Array.isArray(settings)) throw invalidField("validation/invalid-type", "settings");
|
|
11409
|
+
const before = require_CalmLensServerClient.stringifyJsonCanonical(this.toProjectSettings().settings);
|
|
11410
|
+
const previous = this.projectSettingsValues;
|
|
11411
|
+
this.projectSettingsValues = { ...settings };
|
|
11412
|
+
if (require_CalmLensServerClient.stringifyJsonCanonical(this.toProjectSettings().settings) === before) this.projectSettingsValues = previous;
|
|
11413
|
+
else this.settingsRevision += 1;
|
|
11414
|
+
return this.toProjectSettings();
|
|
11415
|
+
}
|
|
11416
|
+
toMetadataFields() {
|
|
11417
|
+
return {
|
|
11418
|
+
projectId: this.projectId,
|
|
11419
|
+
revision: this.settingsRevision,
|
|
11420
|
+
fields: this.metadataFieldList
|
|
11421
|
+
};
|
|
11422
|
+
}
|
|
11423
|
+
/** Creates or replaces fields by ID, keeping the others in order. */
|
|
11424
|
+
ensureMetadataFields(body) {
|
|
11425
|
+
this.checkSettingsRevision(body.revision);
|
|
11426
|
+
const fields = Array.isArray(body.fields) ? body.fields : [];
|
|
11427
|
+
if (fields.length === 0) throw invalidField("validation/too-small", "fields");
|
|
11428
|
+
const byId = new Map(fields.map((field) => [field.id, field]));
|
|
11429
|
+
const merged = [...this.metadataFieldList.map((field) => byId.get(field.id) ?? field), ...fields.filter((field) => !this.metadataFieldList.some(({ id }) => id === field.id))];
|
|
11430
|
+
if (require_CalmLensServerClient.stringifyJsonCanonical(merged) !== require_CalmLensServerClient.stringifyJsonCanonical(this.metadataFieldList)) {
|
|
11431
|
+
this.metadataFieldList = merged;
|
|
11432
|
+
this.settingsRevision += 1;
|
|
11433
|
+
}
|
|
11434
|
+
return this.toMetadataFields();
|
|
11435
|
+
}
|
|
11436
|
+
deleteMetadataField(fieldId, query) {
|
|
11437
|
+
if (!this.metadataFieldList.some(({ id }) => id === fieldId)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.METADATA_FIELD_NOT_FOUND, { details: { fieldId } });
|
|
11438
|
+
this.checkSettingsRevision(query.get("revision") ?? void 0);
|
|
11439
|
+
this.metadataFieldList = this.metadataFieldList.filter(({ id }) => id !== fieldId);
|
|
11440
|
+
this.settingsRevision += 1;
|
|
11441
|
+
return this.toMetadataFields();
|
|
11442
|
+
}
|
|
11165
11443
|
/** Saves each lens in order, like the API: new ones, or a changed definition. */
|
|
11166
11444
|
ensureLenses(body) {
|
|
11167
11445
|
const lenses = Array.isArray(body.lenses) ? body.lenses : [];
|
|
@@ -11381,8 +11659,8 @@ var MockCalmLensApi = class {
|
|
|
11381
11659
|
const { url, query } = request;
|
|
11382
11660
|
const isPrivate = asset.visibility !== "public";
|
|
11383
11661
|
if (isPrivate && !authorised) return this.jsonResponse(404, {
|
|
11384
|
-
code: "asset/not-
|
|
11385
|
-
message: "Asset
|
|
11662
|
+
code: "asset/not-found",
|
|
11663
|
+
message: "Asset not found"
|
|
11386
11664
|
}, url);
|
|
11387
11665
|
let claims = {};
|
|
11388
11666
|
try {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const require_ModerationContextLimits = require("./ModerationContextLimits-
|
|
2
|
-
const require_UploadController = require("./UploadController-
|
|
3
|
-
require("./Core-
|
|
1
|
+
const require_ModerationContextLimits = require("./ModerationContextLimits-ud1xpZRK.js");
|
|
2
|
+
const require_UploadController = require("./UploadController-l8fZM2qT.js");
|
|
3
|
+
require("./Core-Cm5Z1oJ9.js");
|
|
4
4
|
// src/ui/viewers/PdfLoader.ts
|
|
5
5
|
let loading;
|
|
6
6
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./CalmLensTypes-
|
|
2
|
-
import { G as AssetSession, W as AssetOptions, Y as AssetView, at as ImageViewerOptions, ct as TextViewerOptions, ft as WebsiteViewerOptions, it as DocumentViewerOptions, ot as PdfAssetOptions, st as SpreadsheetViewerOptions, ut as ViewerOptions } from "./Core-
|
|
1
|
+
import "./CalmLensTypes-BDKwThbO.js";
|
|
2
|
+
import { G as AssetSession, W as AssetOptions, Y as AssetView, at as ImageViewerOptions, ct as TextViewerOptions, ft as WebsiteViewerOptions, it as DocumentViewerOptions, ot as PdfAssetOptions, st as SpreadsheetViewerOptions, ut as ViewerOptions } from "./Core-C33pkBmf.js";
|
|
3
3
|
import "pdfjs-dist";
|
|
4
4
|
/** A viewer mounted into an element, which it owns the children of. */
|
|
5
5
|
interface AssetViewer<O extends ViewerOptions = ViewerOptions> {
|
package/cjs/ui.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as getAssetViewKey, A as CustomUploadResult, B as AssetDisplay, C as formatMessage, D as resolveMessages, E as getUploadItemOutcome, F as UploadItem, G as AssetSession, H as AssetImageOptions, I as UploadSnapshot, J as AssetVideoOptions, K as AssetSessionState, L as UploadStage, M as UploadController, N as UploadControllerOptions, O as CalmLensUpload, P as UploadFile, Q as getAssetView, R as createUploadController, S as formatBytes, T as getUploadItemMessage, U as AssetImageSource, V as AssetDocumentOptions, W as AssetOptions, X as MediaPlayback, Y as AssetView, Z as getAssetAspectRatio, _ as DEFAULT_MESSAGES, _t as formatViewerMessage, a as ProgressFetchOptions, at as ImageViewerOptions, b as describeUploadItem, c as ICON_ATTRIBUTES, ct as TextViewerOptions, d as AssetDisplayOptions, dt as ViewerTextOptions, et as getPeakHeights, f as AssetEventHandlers, ft as WebsiteViewerOptions, g as CalmLensMessages, gt as ViewerMessages, h as UploaderProps, ht as DEFAULT_VIEWER_MESSAGES, i as CALMLENS_STYLES, it as DocumentViewerOptions, j as UploadClient, k as CustomUploadContext, l as IconName, lt as ViewerAsset, m as UploaderDisplayOptions, mt as isSpreadsheetFormat, n as CalmLensTheme, nt as pickAssetSource, o as createProgressFetch, ot as PdfAssetOptions, p as AssetProps, pt as getAssetViewerKind, q as AssetSpreadsheetOptions, r as resolveTheme, rt as AssetViewerKind, s as ICONS, st as SpreadsheetViewerOptions, t as CALMLENS_THEME, tt as getPlayedPercent, u as ASSET_FILE_ICON_SIZE, ut as ViewerOptions, v as UploadItemView, vt as resolveViewerMessages, w as getDropzoneHint, x as describeUploader, y as UploaderView, z as isFileAccepted } from "./Core-
|
|
2
|
-
import { C as ViewerState, S as AssetViewer, _ as spreadsheetColumnIndex, a as isMountedViewerKind, b as createWebsiteViewer, c as AssetViewerOptionsByKind, d as createTextViewer, f as SpreadsheetCell, g as parseSpreadsheetText, h as getSpreadsheetPage, i as getMountedViewerOptions, l as VIEWER_STYLES, m as SpreadsheetSheet, n as AssetViewerMount, o as ASSET_VIEWERS, p as SpreadsheetRow, r as MountedViewerKind, s as AssetViewerName, t as MediaStreamPlayer, u as createSpreadsheetViewer, v as loadPdfJs, x as createDocumentViewer, y as createImageViewer } from "./ui-
|
|
1
|
+
import { $ as getAssetViewKey, A as CustomUploadResult, B as AssetDisplay, C as formatMessage, D as resolveMessages, E as getUploadItemOutcome, F as UploadItem, G as AssetSession, H as AssetImageOptions, I as UploadSnapshot, J as AssetVideoOptions, K as AssetSessionState, L as UploadStage, M as UploadController, N as UploadControllerOptions, O as CalmLensUpload, P as UploadFile, Q as getAssetView, R as createUploadController, S as formatBytes, T as getUploadItemMessage, U as AssetImageSource, V as AssetDocumentOptions, W as AssetOptions, X as MediaPlayback, Y as AssetView, Z as getAssetAspectRatio, _ as DEFAULT_MESSAGES, _t as formatViewerMessage, a as ProgressFetchOptions, at as ImageViewerOptions, b as describeUploadItem, c as ICON_ATTRIBUTES, ct as TextViewerOptions, d as AssetDisplayOptions, dt as ViewerTextOptions, et as getPeakHeights, f as AssetEventHandlers, ft as WebsiteViewerOptions, g as CalmLensMessages, gt as ViewerMessages, h as UploaderProps, ht as DEFAULT_VIEWER_MESSAGES, i as CALMLENS_STYLES, it as DocumentViewerOptions, j as UploadClient, k as CustomUploadContext, l as IconName, lt as ViewerAsset, m as UploaderDisplayOptions, mt as isSpreadsheetFormat, n as CalmLensTheme, nt as pickAssetSource, o as createProgressFetch, ot as PdfAssetOptions, p as AssetProps, pt as getAssetViewerKind, q as AssetSpreadsheetOptions, r as resolveTheme, rt as AssetViewerKind, s as ICONS, st as SpreadsheetViewerOptions, t as CALMLENS_THEME, tt as getPlayedPercent, u as ASSET_FILE_ICON_SIZE, ut as ViewerOptions, v as UploadItemView, vt as resolveViewerMessages, w as getDropzoneHint, x as describeUploader, y as UploaderView, z as isFileAccepted } from "./Core-C33pkBmf.js";
|
|
2
|
+
import { C as ViewerState, S as AssetViewer, _ as spreadsheetColumnIndex, a as isMountedViewerKind, b as createWebsiteViewer, c as AssetViewerOptionsByKind, d as createTextViewer, f as SpreadsheetCell, g as parseSpreadsheetText, h as getSpreadsheetPage, i as getMountedViewerOptions, l as VIEWER_STYLES, m as SpreadsheetSheet, n as AssetViewerMount, o as ASSET_VIEWERS, p as SpreadsheetRow, r as MountedViewerKind, s as AssetViewerName, t as MediaStreamPlayer, u as createSpreadsheetViewer, v as loadPdfJs, x as createDocumentViewer, y as createImageViewer } from "./ui-YQuvbidU.js";
|
|
3
3
|
export { ASSET_FILE_ICON_SIZE, ASSET_VIEWERS, type AssetDisplay, type AssetDisplayOptions, type AssetDocumentOptions, type AssetEventHandlers, type AssetImageOptions, type AssetImageSource, type AssetOptions, type AssetProps, AssetSession, type AssetSessionState, type AssetSpreadsheetOptions, type AssetVideoOptions, type AssetView, type AssetViewer, type AssetViewerKind, AssetViewerMount, AssetViewerName, AssetViewerOptionsByKind, CALMLENS_STYLES, CALMLENS_THEME, type CalmLensMessages, type CalmLensTheme, type CalmLensUpload, type CustomUploadContext, type CustomUploadResult, DEFAULT_MESSAGES, DEFAULT_VIEWER_MESSAGES, type DocumentViewerOptions, ICONS, ICON_ATTRIBUTES, type IconName, type ImageViewerOptions, type MediaPlayback, MediaStreamPlayer, type MountedViewerKind, type PdfAssetOptions, type ProgressFetchOptions, type SpreadsheetCell, type SpreadsheetRow, type SpreadsheetSheet, type SpreadsheetViewerOptions, type TextViewerOptions, type UploadClient, UploadController, type UploadControllerOptions, type UploadFile, type UploadItem, type UploadItemView, type UploadSnapshot, type UploadStage, type UploaderDisplayOptions, type UploaderProps, type UploaderView, VIEWER_STYLES, type ViewerAsset, type ViewerMessages, type ViewerOptions, type ViewerState, type ViewerTextOptions, type WebsiteViewerOptions, createDocumentViewer, createImageViewer, createProgressFetch, createSpreadsheetViewer, createTextViewer, createUploadController, createWebsiteViewer, describeUploadItem, describeUploader, formatBytes, formatMessage, formatViewerMessage, getAssetAspectRatio, getAssetView, getAssetViewKey, getAssetViewerKind, getDropzoneHint, getMountedViewerOptions, getPeakHeights, getPlayedPercent, getSpreadsheetPage, getUploadItemMessage, getUploadItemOutcome, isFileAccepted, isMountedViewerKind, isSpreadsheetFormat, loadPdfJs, parseSpreadsheetText, pickAssetSource, resolveMessages, resolveTheme, resolveViewerMessages, spreadsheetColumnIndex };
|
package/cjs/ui.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_ui = require("./ui-
|
|
3
|
-
const require_UploadController = require("./UploadController-
|
|
4
|
-
const require_Core = require("./Core-
|
|
2
|
+
const require_ui = require("./ui-BRA4HQ8r.js");
|
|
3
|
+
const require_UploadController = require("./UploadController-l8fZM2qT.js");
|
|
4
|
+
const require_Core = require("./Core-Cm5Z1oJ9.js");
|
|
5
5
|
exports.ASSET_FILE_ICON_SIZE = require_Core.ASSET_FILE_ICON_SIZE;
|
|
6
6
|
exports.ASSET_VIEWERS = require_ui.ASSET_VIEWERS;
|
|
7
7
|
exports.AssetSession = require_Core.AssetSession;
|