calmlens 0.18.3 → 0.20.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/bin/calmlens.js +5682 -5036
- package/cjs/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-C07aL9Vq.d.ts} +2 -2
- package/cjs/{BrowserUpload-UxIAGNdv.js → BrowserUpload-CjSHjx3C.js} +1 -1
- package/{esm/CalmLensAppClient-CV_K26Ce.d.ts → cjs/CalmLensAppClient-DDLojj0P.d.ts} +3 -3
- package/cjs/{CalmLensAppClient-D6p7MAFz.js → CalmLensAppClient-NaCxOVlM.js} +32 -11
- package/cjs/{CalmLensConnection-CYoUl5go.js → CalmLensOptionKeys-p2QK687A.js} +430 -9
- package/cjs/{CalmLensServerClient-p23cl97D.js → CalmLensServerClient-BDzTthxE.js} +173 -55
- package/cjs/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-C-jsjn8m.d.ts} +54 -30
- package/cjs/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-COJbOuiv.d.ts} +2677 -30
- package/cjs/{ModerationContextLimits-DCLXMxyA.js → ModerationContextLimits-2nIv7Zh3.js} +495 -49
- package/cjs/{ReactUpload-BcdNWLiU.js → ReactUpload-BdTRCTGA.js} +1 -1
- package/cjs/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-CRJNPB5T.d.ts} +1 -1
- package/{esm/TestTriggers-By07LR31-CmK0yTyR.d.ts → cjs/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
- package/cjs/{TestTriggers-DTc_iMJF-BjMPq4_3.js → TestTriggers-DbhsNPdg-DjvVuc2h.js} +434 -74
- package/cjs/{UploadController-Cxu0bufo.js → UploadController-MLVs97Zt.js} +17 -5
- package/{esm/WebhookPayload-2aL31v0J.d.ts → cjs/WebhookPayload-DkukERKE.d.ts} +29 -3
- package/cjs/app.d.ts +6 -6
- package/cjs/app.js +2 -2
- package/cjs/elements.d.ts +3 -3
- package/cjs/elements.js +3 -3
- package/cjs/{index-CI4BzN4W.d.ts → index-DxbJ_Xaa.d.ts} +7 -6
- package/cjs/index.d.ts +5 -5
- package/cjs/index.js +1 -1
- package/cjs/react-native.d.ts +3 -3
- package/cjs/react-native.js +3 -3
- package/cjs/react.d.ts +3 -3
- package/cjs/react.js +4 -4
- package/cjs/server.d.ts +6 -6
- package/cjs/server.js +2 -2
- package/cjs/test-inputs.d.ts +1 -1
- package/cjs/test-inputs.js +9 -9
- package/cjs/testing.d.ts +12 -8
- package/cjs/testing.js +298 -35
- package/{esm/ui-wIiMfqMB.d.ts → cjs/ui-BSqPGKrZ.d.ts} +17 -4
- package/cjs/{ui-C0XXJS52.js → ui-CX1z2pD9.js} +13 -10
- package/cjs/ui.d.ts +2 -2
- package/cjs/ui.js +2 -2
- package/cjs/vue.d.ts +5 -5
- package/cjs/vue.js +3 -3
- package/esm/{BrowserUpload-BT091eOB.d.ts → BrowserUpload-C07aL9Vq.d.ts} +2 -2
- package/esm/{BrowserUpload-BXG2isHV.js → BrowserUpload-CAVkRotw.js} +1 -1
- package/{cjs/CalmLensAppClient-CV_K26Ce.d.ts → esm/CalmLensAppClient-DDLojj0P.d.ts} +3 -3
- package/esm/{CalmLensAppClient-BMgXamoN.js → CalmLensAppClient-PQ9VBvlW.js} +28 -7
- package/esm/{CalmLensConnection-DBoDh06c.js → CalmLensOptionKeys-Do2mPP6w.js} +407 -10
- package/esm/{CalmLensServerClient-JtP687a3.d.ts → CalmLensServerClient-C-jsjn8m.d.ts} +54 -30
- package/esm/{CalmLensServerClient-Dt7rCITa.js → CalmLensServerClient-C_H5aAsV.js} +165 -47
- package/esm/{CalmLensTypes-9Vt16pc7.d.ts → CalmLensTypes-COJbOuiv.d.ts} +2677 -30
- package/esm/{ModerationContextLimits-KMQ8puoa.js → ModerationContextLimits-Chw-AzgL.js} +462 -46
- package/esm/{ReactUpload-CFy_wETY.js → ReactUpload-CMmL0R5Q.js} +1 -1
- package/esm/{ReactUpload-CAyCsyG6.d.ts → ReactUpload-CRJNPB5T.d.ts} +1 -1
- package/{cjs/TestTriggers-By07LR31-CmK0yTyR.d.ts → esm/TestTriggers-D-fwfhEP-hlaP1oW2.d.ts} +13 -7
- package/esm/{TestTriggers-DTc_iMJF-HfB533Gx.js → TestTriggers-DbhsNPdg-CUdrv8Nm.js} +405 -72
- package/esm/{UploadController-Cs-bxUbt.js → UploadController-BJZghJpg.js} +17 -5
- package/{cjs/WebhookPayload-2aL31v0J.d.ts → esm/WebhookPayload-DkukERKE.d.ts} +29 -3
- package/esm/app.d.ts +6 -6
- package/esm/app.js +2 -2
- package/esm/elements.d.ts +3 -3
- package/esm/elements.js +3 -3
- package/esm/{index-CI4BzN4W.d.ts → index-DxbJ_Xaa.d.ts} +7 -6
- package/esm/index.d.ts +5 -5
- package/esm/index.js +1 -1
- package/esm/react-native.d.ts +3 -3
- package/esm/react-native.js +3 -3
- package/esm/react.d.ts +3 -3
- package/esm/react.js +4 -4
- package/esm/server.d.ts +6 -6
- package/esm/server.js +2 -2
- package/esm/test-inputs.d.ts +1 -1
- package/esm/test-inputs.js +1 -1
- package/esm/testing.d.ts +12 -8
- package/esm/testing.js +287 -23
- package/{cjs/ui-wIiMfqMB.d.ts → esm/ui-BSqPGKrZ.d.ts} +17 -4
- package/esm/{ui-BqYkISSE.js → ui-CXH7xJpb.js} +12 -9
- package/esm/ui.d.ts +2 -2
- package/esm/ui.js +2 -2
- package/esm/vue.d.ts +5 -5
- package/esm/vue.js +3 -3
- package/package.json +1 -1
- package/cjs/Jurisdiction-FusEXb4U-zVs21tDv.js +0 -91
- package/esm/Jurisdiction-FusEXb4U-1ov6m5yE.js +0 -46
- /package/cjs/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
- /package/esm/{Classification-94kSYWZw-CMnQKW13.d.ts → Classification-D3SkprrQ-CMnQKW13.d.ts} +0 -0
package/cjs/testing.js
CHANGED
|
@@ -1,16 +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
|
|
2
|
+
const require_TestTriggers_DbhsNPdg = require("./TestTriggers-DbhsNPdg-DjvVuc2h.js");
|
|
3
|
+
const require_ModerationContextLimits = require("./ModerationContextLimits-2nIv7Zh3.js");
|
|
4
|
+
const require_CalmLensServerClient = require("./CalmLensServerClient-BDzTthxE.js");
|
|
5
|
+
const require_CalmLensOptionKeys = require("./CalmLensOptionKeys-p2QK687A.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-
|
|
9
|
-
const require_TestTriggers_DTc_iMJF = require("./TestTriggers-DTc_iMJF-BjMPq4_3.js");
|
|
7
|
+
const require_CalmLensAppClient = require("./CalmLensAppClient-NaCxOVlM.js");
|
|
8
|
+
const require_UploadController = require("./UploadController-MLVs97Zt.js");
|
|
10
9
|
let zod = require("zod");
|
|
11
|
-
zod =
|
|
10
|
+
zod = require_TestTriggers_DbhsNPdg.__toESM(zod, 1);
|
|
12
11
|
// src/contract/MediaTestTriggers.js
|
|
13
|
-
const MEDIA_TEST_SIGNALS = [...
|
|
12
|
+
const MEDIA_TEST_SIGNALS = [...require_TestTriggers_DbhsNPdg.CLASSIFICATION_CATEGORIES, "violence.graphic"];
|
|
14
13
|
const HEX_WORDS = [
|
|
15
14
|
"zero",
|
|
16
15
|
"one",
|
|
@@ -32,9 +31,9 @@ const HEX_WORDS = [
|
|
|
32
31
|
/** Read this aloud, or render it as large, high-contrast text in a video frame. */
|
|
33
32
|
async function generateMediaTestCode(signal, testInputKey) {
|
|
34
33
|
if (!MEDIA_TEST_SIGNALS.includes(signal)) throw new RangeError("Unsupported media test signal");
|
|
35
|
-
return `Calm Lens test ${[...await
|
|
34
|
+
return `Calm Lens test ${[...await require_TestTriggers_DbhsNPdg.getTestInputTag("media", signal, testInputKey)].map((character) => HEX_WORDS[Number.parseInt(character, 16)]).join(" ")} ${signal.replace(/[.-]/g, " ")} end test`;
|
|
36
35
|
}
|
|
37
|
-
// src/contract/Ids-
|
|
36
|
+
// src/contract/Ids-D2XfVlL6.js
|
|
38
37
|
var __defProp = Object.defineProperty;
|
|
39
38
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
|
|
40
39
|
var __exportAll = (all, no_symbols) => {
|
|
@@ -7909,6 +7908,7 @@ const ID_PREFIXES = {
|
|
|
7909
7908
|
user: "user",
|
|
7910
7909
|
member: "mem",
|
|
7911
7910
|
invitation: "inv",
|
|
7911
|
+
transfer: "xfer",
|
|
7912
7912
|
supportTicket: "tkt",
|
|
7913
7913
|
supportTicketMessage: "msg",
|
|
7914
7914
|
humanReview: "rev",
|
|
@@ -7969,6 +7969,7 @@ const EXAMPLE_IDS = {
|
|
|
7969
7969
|
user: "user_4Rk9Xm2Lq7Vt3Wb8Np6C",
|
|
7970
7970
|
mem: "mem_9Xm4Rk7Lq2Vt8Wb3Np5C",
|
|
7971
7971
|
inv: "inv_3Qk8Xm2Rt9Lv4Wb7Np6C",
|
|
7972
|
+
xfer: "xfer_6Lq2Xm8Rk4Vt9Wb3Np7C",
|
|
7972
7973
|
tkt: "tkt_6Xm2Rk9Lq4Vt7Wb3Np8C",
|
|
7973
7974
|
msg: "msg_2Rk7Xm4Lq9Vt3Wb8Np5C",
|
|
7974
7975
|
rev: "rev_8Xm3Rk2Lq7Vt9Wb4Np6C",
|
|
@@ -7985,8 +7986,8 @@ const EXAMPLE_IDS = {
|
|
|
7985
7986
|
* every stored model's IDs by prefix is a separate change (it surfaces about a thousand call sites
|
|
7986
7987
|
* across the packages that build records from plain strings).
|
|
7987
7988
|
*/
|
|
7988
|
-
const idField = (prefix) => zod.string().regex(idPattern(prefix), { message: `Must be
|
|
7989
|
-
// src/contract/Permissions-
|
|
7989
|
+
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]] });
|
|
7990
|
+
// src/contract/Permissions-C2KeOlab.js
|
|
7990
7991
|
const ACTION_SCHEMA = zod.enum([
|
|
7991
7992
|
"assets:read",
|
|
7992
7993
|
"assets:download",
|
|
@@ -8014,6 +8015,8 @@ const ACTION_SCHEMA = zod.enum([
|
|
|
8014
8015
|
"upload-presets:write",
|
|
8015
8016
|
"hash-lists:read",
|
|
8016
8017
|
"hash-lists:write",
|
|
8018
|
+
"policies:read",
|
|
8019
|
+
"policies:write",
|
|
8017
8020
|
"reviews:read",
|
|
8018
8021
|
"reviews:write",
|
|
8019
8022
|
"project:manage"
|
|
@@ -8027,6 +8030,7 @@ const PROJECT_ACTIONS = [...[
|
|
|
8027
8030
|
"lenses",
|
|
8028
8031
|
"upload-presets",
|
|
8029
8032
|
"hash-lists",
|
|
8033
|
+
"policies",
|
|
8030
8034
|
"reviews"
|
|
8031
8035
|
].flatMap((feature) => [`${feature}:read`, `${feature}:write`]), "project:manage"];
|
|
8032
8036
|
const isProjectAction = (action) => PROJECT_ACTIONS.includes(action);
|
|
@@ -8582,6 +8586,60 @@ const REVIEW_DECISIONS = [
|
|
|
8582
8586
|
"blocked",
|
|
8583
8587
|
"purged"
|
|
8584
8588
|
];
|
|
8589
|
+
/**
|
|
8590
|
+
* A client method, named like its path on the client. A request is recorded under the first
|
|
8591
|
+
* method that sends it; `callsTo` and `failNextRequest` also match the others (see
|
|
8592
|
+
* `MockCalmLensCall`).
|
|
8593
|
+
*/
|
|
8594
|
+
const MOCK_OPERATIONS = [
|
|
8595
|
+
"assets.list",
|
|
8596
|
+
"assets.iterate",
|
|
8597
|
+
"assets.search",
|
|
8598
|
+
"assets.retrieve",
|
|
8599
|
+
"assets.waitForDecision",
|
|
8600
|
+
"assets.update",
|
|
8601
|
+
"assets.listChildren",
|
|
8602
|
+
"assets.iterateChildren",
|
|
8603
|
+
"assets.create",
|
|
8604
|
+
"assets.classify",
|
|
8605
|
+
"assets.uploadPart",
|
|
8606
|
+
"assets.createSignedUrl",
|
|
8607
|
+
"assets.move",
|
|
8608
|
+
"assets.retry",
|
|
8609
|
+
"assets.explain",
|
|
8610
|
+
"assets.decide",
|
|
8611
|
+
"assets.deleteContent",
|
|
8612
|
+
"assets.delete",
|
|
8613
|
+
"assets.batch",
|
|
8614
|
+
"text.classify",
|
|
8615
|
+
"cdn.serve",
|
|
8616
|
+
"events.list",
|
|
8617
|
+
"events.pages",
|
|
8618
|
+
"folders.list",
|
|
8619
|
+
"folders.retrieve",
|
|
8620
|
+
"folders.create",
|
|
8621
|
+
"folders.update",
|
|
8622
|
+
"folders.delete",
|
|
8623
|
+
"folders.move",
|
|
8624
|
+
"hashLists.list",
|
|
8625
|
+
"hashLists.retrieve",
|
|
8626
|
+
"hashLists.create",
|
|
8627
|
+
"hashLists.update",
|
|
8628
|
+
"hashLists.delete",
|
|
8629
|
+
"hashLists.listEntries",
|
|
8630
|
+
"hashLists.addEntry",
|
|
8631
|
+
"hashLists.removeEntry",
|
|
8632
|
+
"policies.list",
|
|
8633
|
+
"policies.retrieve",
|
|
8634
|
+
"policies.create",
|
|
8635
|
+
"policies.update",
|
|
8636
|
+
"policies.applyPreset",
|
|
8637
|
+
"policies.setAutomaticUpdates",
|
|
8638
|
+
"policies.delete",
|
|
8639
|
+
"policies.assign",
|
|
8640
|
+
"ensureLens",
|
|
8641
|
+
"ensureLenses"
|
|
8642
|
+
];
|
|
8585
8643
|
const MAX_PAGE_SIZE = 100;
|
|
8586
8644
|
const MAX_DECISION_NOTE_LENGTH = 1499;
|
|
8587
8645
|
/** How the API names a reviewer acting through an unnamed API key. */
|
|
@@ -8659,6 +8717,26 @@ var ApiFailure = class {
|
|
|
8659
8717
|
const fail = (code, { message, details } = {}) => new ApiFailure(require_ModerationContextLimits.API_ERROR_DEFINITIONS[code].status, code, message ?? require_ModerationContextLimits.API_ERROR_DEFINITIONS[code].message, details);
|
|
8660
8718
|
/** A request the API's schema refuses: `validation/<zod issue>` with HTTP 400 and the field. */
|
|
8661
8719
|
const invalidField = (code, path) => new ApiFailure(400, code, `Invalid ${path}`, { path });
|
|
8720
|
+
/**
|
|
8721
|
+
* Refuses `metadata` the API's schema refuses (METADATA_ITEM_SCHEMA): it is `null` or a list of
|
|
8722
|
+
* `{ id, value }` objects with a string `id` and any JSON `value`.
|
|
8723
|
+
*/
|
|
8724
|
+
const checkMetadata = (metadata) => {
|
|
8725
|
+
if (metadata === void 0 || metadata === null) return;
|
|
8726
|
+
if (!Array.isArray(metadata)) throw invalidField("validation/invalid-type", "metadata");
|
|
8727
|
+
metadata.forEach((item, index) => {
|
|
8728
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) throw invalidField("validation/invalid-type", `metadata.${index}`);
|
|
8729
|
+
if (typeof item.id !== "string") throw invalidField("validation/invalid-type", `metadata.${index}.id`);
|
|
8730
|
+
if (item.value === void 0) throw invalidField("validation/invalid-value", `metadata.${index}.value`);
|
|
8731
|
+
});
|
|
8732
|
+
};
|
|
8733
|
+
/** The built-in presets the mock knows, by display name. */
|
|
8734
|
+
const MOCK_PRESET_NAMES = {
|
|
8735
|
+
"general-community": "General",
|
|
8736
|
+
"children-platform": "Kids",
|
|
8737
|
+
"education-support": "Learning and support",
|
|
8738
|
+
"wholesome-community": "Teen-safe"
|
|
8739
|
+
};
|
|
8662
8740
|
/** The client methods that send a request, the one it is recorded under first. */
|
|
8663
8741
|
const operationsOf = (request) => {
|
|
8664
8742
|
const { method, segments, query, cdn } = request;
|
|
@@ -8670,6 +8748,8 @@ const operationsOf = (request) => {
|
|
|
8670
8748
|
case "lenses": return ["ensureLenses", "ensureLens"];
|
|
8671
8749
|
case "folders": return method === "GET" ? ["folders.list"] : ["folders.create"];
|
|
8672
8750
|
case "hash-lists": return method === "GET" ? ["hashLists.list"] : ["hashLists.create"];
|
|
8751
|
+
case "policies": return method === "GET" ? ["policies.list"] : ["policies.create"];
|
|
8752
|
+
case "policy": return ["policies.assign"];
|
|
8673
8753
|
case "assets/search": return ["assets.search"];
|
|
8674
8754
|
case "assets/batch": return ["assets.batch"];
|
|
8675
8755
|
case "assets":
|
|
@@ -8677,6 +8757,11 @@ const operationsOf = (request) => {
|
|
|
8677
8757
|
if (query.get("queue") === "true") return ["assets.create"];
|
|
8678
8758
|
return isTextUpload(request) ? ["assets.classify", "text.classify"] : ["assets.classify"];
|
|
8679
8759
|
}
|
|
8760
|
+
if (segments[2] === "policies" && segments[3] !== void 0) {
|
|
8761
|
+
if (segments[4] === "preset") return ["policies.applyPreset"];
|
|
8762
|
+
if (segments[4] === "automatic-updates") return ["policies.setAutomaticUpdates"];
|
|
8763
|
+
return method === "GET" ? ["policies.retrieve"] : method === "PATCH" ? ["policies.update"] : ["policies.delete"];
|
|
8764
|
+
}
|
|
8680
8765
|
return [];
|
|
8681
8766
|
}
|
|
8682
8767
|
if (root === "upload-presets") {
|
|
@@ -8713,6 +8798,7 @@ const isTextUpload = (request) => request.headers.get("x-calmlens-upload") === "
|
|
|
8713
8798
|
const SUCCESS_STATUS = {
|
|
8714
8799
|
"folders.create": 201,
|
|
8715
8800
|
"hashLists.create": 201,
|
|
8801
|
+
"policies.create": 201,
|
|
8716
8802
|
"assets.batch": 202
|
|
8717
8803
|
};
|
|
8718
8804
|
const decodeSegment = (segment) => {
|
|
@@ -8743,6 +8829,7 @@ var MockCalmLensApi = class {
|
|
|
8743
8829
|
this.pendingFailures = [];
|
|
8744
8830
|
this.requestCount = 0;
|
|
8745
8831
|
this.waitedMs = 0;
|
|
8832
|
+
this.policies = /* @__PURE__ */ new Map();
|
|
8746
8833
|
this.hashLists = /* @__PURE__ */ new Map();
|
|
8747
8834
|
this.hashListEntries = /* @__PURE__ */ new Map();
|
|
8748
8835
|
this.pageFailure = (code, path) => code === "validation/invalid-cursor" ? fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_CURSOR) : invalidField(code, path ?? "pageSize");
|
|
@@ -8757,6 +8844,8 @@ var MockCalmLensApi = class {
|
|
|
8757
8844
|
}
|
|
8758
8845
|
/** Queues a failure for the next request, or the next one `operation` sends. */
|
|
8759
8846
|
failNextRequest(failure, options = {}) {
|
|
8847
|
+
if (options.operation !== void 0 && !MOCK_OPERATIONS.includes(options.operation)) throw require_ModerationContextLimits.invalidArgument(`${options.operation} is not a client method that sends requests`);
|
|
8848
|
+
if (!(typeof failure === "string" && failure in require_ModerationContextLimits.API_ERROR_DEFINITIONS) && (options.details !== void 0 || options.retryAfter !== void 0)) throw require_ModerationContextLimits.invalidArgument("details and retryAfter apply only to an API error code");
|
|
8760
8849
|
if (options.retryAfter !== void 0 && !(Number.isInteger(options.retryAfter) && options.retryAfter >= 0)) throw require_ModerationContextLimits.invalidArgument("retryAfter must be a whole number of seconds");
|
|
8761
8850
|
this.pendingFailures.push({
|
|
8762
8851
|
failure,
|
|
@@ -8935,6 +9024,7 @@ var MockCalmLensApi = class {
|
|
|
8935
9024
|
method: (init?.method ?? "GET").toUpperCase(),
|
|
8936
9025
|
url,
|
|
8937
9026
|
segments: path.split("/").filter(Boolean).map(decodeSegment),
|
|
9027
|
+
rawSegments: path.split("/").filter(Boolean),
|
|
8938
9028
|
query: new URLSearchParams(queryIndex === -1 ? "" : relative.slice(queryIndex + 1)),
|
|
8939
9029
|
headers,
|
|
8940
9030
|
bytes,
|
|
@@ -9077,6 +9167,17 @@ var MockCalmLensApi = class {
|
|
|
9077
9167
|
case "GET hash-lists": return [200, this.listHashLists(request.query)];
|
|
9078
9168
|
case "POST hash-lists": return [201, this.createHashList(this.json(request))];
|
|
9079
9169
|
case "PUT lenses": return [200, this.ensureLenses(this.json(request))];
|
|
9170
|
+
case "GET policies": return [200, this.listPolicies()];
|
|
9171
|
+
case "POST policies": return [201, this.createPolicy(this.json(request))];
|
|
9172
|
+
case "PUT policy": return [200, this.assignPolicy(this.json(request))];
|
|
9173
|
+
}
|
|
9174
|
+
const [, , collection, policyId, policyAction, ...more] = segments;
|
|
9175
|
+
if (collection === "policies" && policyId !== void 0 && more.length === 0) switch (`${method} ${policyAction ?? ""}`) {
|
|
9176
|
+
case "GET ": return [200, this.toPolicy(this.findPolicy(policyId))];
|
|
9177
|
+
case "PATCH ": return [200, this.updatePolicy(policyId, this.json(request))];
|
|
9178
|
+
case "DELETE ": return [200, this.deletePolicy(policyId)];
|
|
9179
|
+
case "POST preset": return [200, this.applyPolicyPreset(policyId, this.json(request))];
|
|
9180
|
+
case "PUT automatic-updates": return [200, this.setPolicyAutomaticUpdates(policyId, this.json(request))];
|
|
9080
9181
|
}
|
|
9081
9182
|
}
|
|
9082
9183
|
if (root === "upload-presets" && id !== void 0 && action === "assets") return [200, await this.presetRoute(request, id, rest, session)];
|
|
@@ -9112,6 +9213,134 @@ var MockCalmLensApi = class {
|
|
|
9112
9213
|
}
|
|
9113
9214
|
throw fail(require_ModerationContextLimits.API_ERROR_CODES.ROUTE_NOT_FOUND, { message: `No route for ${method} /${segments.join("/")}` });
|
|
9114
9215
|
}
|
|
9216
|
+
ensurePolicies() {
|
|
9217
|
+
if (this.projectPolicyId) return;
|
|
9218
|
+
const now = this.now();
|
|
9219
|
+
const general = this.newPolicy({
|
|
9220
|
+
name: MOCK_PRESET_NAMES["general-community"],
|
|
9221
|
+
settings: { categorySettings: {} },
|
|
9222
|
+
automaticUpdates: true,
|
|
9223
|
+
preset: {
|
|
9224
|
+
id: "general-community",
|
|
9225
|
+
version: 1,
|
|
9226
|
+
own: true
|
|
9227
|
+
},
|
|
9228
|
+
createdAt: now
|
|
9229
|
+
});
|
|
9230
|
+
this.projectPolicyId = general.id;
|
|
9231
|
+
}
|
|
9232
|
+
newPolicy(values) {
|
|
9233
|
+
const policy = {
|
|
9234
|
+
id: this.createId("pol"),
|
|
9235
|
+
name: values.name,
|
|
9236
|
+
description: values.description ?? "",
|
|
9237
|
+
settings: values.settings,
|
|
9238
|
+
revision: 1,
|
|
9239
|
+
automaticUpdates: values.automaticUpdates ?? false,
|
|
9240
|
+
preset: values.preset ?? null,
|
|
9241
|
+
baseline: structuredClone(values.settings),
|
|
9242
|
+
createdAt: values.createdAt,
|
|
9243
|
+
updatedAt: values.createdAt
|
|
9244
|
+
};
|
|
9245
|
+
this.policies.set(policy.id, policy);
|
|
9246
|
+
return policy;
|
|
9247
|
+
}
|
|
9248
|
+
toPolicy(policy) {
|
|
9249
|
+
const { baseline: _baseline, preset, ...rest } = policy;
|
|
9250
|
+
return {
|
|
9251
|
+
...structuredClone(rest),
|
|
9252
|
+
preset: preset && {
|
|
9253
|
+
...preset,
|
|
9254
|
+
latestVersion: 1
|
|
9255
|
+
},
|
|
9256
|
+
projectIds: policy.id === this.projectPolicyId ? [this.projectId] : []
|
|
9257
|
+
};
|
|
9258
|
+
}
|
|
9259
|
+
findPolicy(policyId) {
|
|
9260
|
+
this.ensurePolicies();
|
|
9261
|
+
const policy = this.policies.get(policyId);
|
|
9262
|
+
if (!policy) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_NOT_FOUND);
|
|
9263
|
+
return policy;
|
|
9264
|
+
}
|
|
9265
|
+
listPolicies() {
|
|
9266
|
+
this.ensurePolicies();
|
|
9267
|
+
return {
|
|
9268
|
+
policies: [...this.policies.values()].map((policy) => this.toPolicy(policy)),
|
|
9269
|
+
projectPolicyId: this.projectPolicyId
|
|
9270
|
+
};
|
|
9271
|
+
}
|
|
9272
|
+
createPolicy(body) {
|
|
9273
|
+
this.ensurePolicies();
|
|
9274
|
+
const { name, description, settings, presetId } = body;
|
|
9275
|
+
const preset = typeof presetId === "string" ? presetId : void 0;
|
|
9276
|
+
if (settings === void 0 === (preset === void 0) || preset !== void 0 && !(preset in MOCK_PRESET_NAMES) || preset === void 0 && (typeof name !== "string" || !name.trim())) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_VALUE, { message: "Send settings with a name, or presetId" });
|
|
9277
|
+
const policy = this.newPolicy({
|
|
9278
|
+
name: typeof name === "string" && name.trim() ? name.trim() : MOCK_PRESET_NAMES[preset],
|
|
9279
|
+
...typeof description === "string" ? { description } : {},
|
|
9280
|
+
settings: preset ? { categorySettings: {} } : settings,
|
|
9281
|
+
...preset ? { preset: {
|
|
9282
|
+
id: preset,
|
|
9283
|
+
version: 1,
|
|
9284
|
+
own: false
|
|
9285
|
+
} } : {},
|
|
9286
|
+
createdAt: this.now()
|
|
9287
|
+
});
|
|
9288
|
+
return this.toPolicy(policy);
|
|
9289
|
+
}
|
|
9290
|
+
/** Saves new values under the next revision, once `revision` is the current one. */
|
|
9291
|
+
savePolicy(policy, revision, values) {
|
|
9292
|
+
if (revision !== policy.revision) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_REVISION_CONFLICT);
|
|
9293
|
+
const saved = {
|
|
9294
|
+
...policy,
|
|
9295
|
+
...values,
|
|
9296
|
+
revision: policy.revision + 1,
|
|
9297
|
+
updatedAt: this.now()
|
|
9298
|
+
};
|
|
9299
|
+
this.policies.set(policy.id, saved);
|
|
9300
|
+
return this.toPolicy(saved);
|
|
9301
|
+
}
|
|
9302
|
+
updatePolicy(policyId, body) {
|
|
9303
|
+
const policy = this.findPolicy(policyId);
|
|
9304
|
+
return this.savePolicy(policy, body.revision, {
|
|
9305
|
+
...typeof body.name === "string" ? { name: body.name.trim() } : {},
|
|
9306
|
+
...typeof body.description === "string" ? { description: body.description } : {},
|
|
9307
|
+
...body.settings !== void 0 ? { settings: body.settings } : {},
|
|
9308
|
+
automaticUpdates: false
|
|
9309
|
+
});
|
|
9310
|
+
}
|
|
9311
|
+
applyPolicyPreset(policyId, body) {
|
|
9312
|
+
const policy = this.findPolicy(policyId);
|
|
9313
|
+
if (!policy.preset || policy.automaticUpdates) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_NO_PRESET);
|
|
9314
|
+
if (body.presetVersion !== policy.preset.version) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_PRESET_VERSION_CONFLICT);
|
|
9315
|
+
if (body.operation === "update") throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_PRESET_UPDATE_UNAVAILABLE);
|
|
9316
|
+
return this.savePolicy(policy, body.revision, { settings: structuredClone(policy.baseline) });
|
|
9317
|
+
}
|
|
9318
|
+
setPolicyAutomaticUpdates(policyId, body) {
|
|
9319
|
+
const policy = this.findPolicy(policyId);
|
|
9320
|
+
const enabled = body.enabled === true;
|
|
9321
|
+
if (!policy.preset?.own || policy.automaticUpdates === enabled) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_AUTOMATIC_UPDATES_UNAVAILABLE);
|
|
9322
|
+
if (body.revision !== policy.revision) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_REVISION_CONFLICT);
|
|
9323
|
+
if (body.presetVersion !== 1) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_PRESET_VERSION_CONFLICT);
|
|
9324
|
+
return this.savePolicy(policy, body.revision, {
|
|
9325
|
+
automaticUpdates: enabled,
|
|
9326
|
+
...enabled ? {
|
|
9327
|
+
name: MOCK_PRESET_NAMES[policy.preset.id],
|
|
9328
|
+
description: "",
|
|
9329
|
+
settings: structuredClone(policy.baseline)
|
|
9330
|
+
} : {}
|
|
9331
|
+
});
|
|
9332
|
+
}
|
|
9333
|
+
deletePolicy(policyId) {
|
|
9334
|
+
const policy = this.findPolicy(policyId);
|
|
9335
|
+
if (policy.id === this.projectPolicyId) throw fail(require_ModerationContextLimits.API_ERROR_CODES.POLICY_IN_USE);
|
|
9336
|
+
this.policies.delete(policy.id);
|
|
9337
|
+
return {};
|
|
9338
|
+
}
|
|
9339
|
+
assignPolicy(body) {
|
|
9340
|
+
const policy = this.findPolicy(String(body.policyId));
|
|
9341
|
+
this.projectPolicyId = policy.id;
|
|
9342
|
+
return this.toPolicy(policy);
|
|
9343
|
+
}
|
|
9115
9344
|
createHashList(body) {
|
|
9116
9345
|
const { name, description, action } = body;
|
|
9117
9346
|
if (typeof name !== "string" || !name.trim() || action !== "flag" && action !== "block") throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "A hash list needs a name and an action of flag or block" });
|
|
@@ -9295,6 +9524,8 @@ var MockCalmLensApi = class {
|
|
|
9295
9524
|
});
|
|
9296
9525
|
}
|
|
9297
9526
|
async updateAsset(assetId, body) {
|
|
9527
|
+
checkMetadata(body.metadata);
|
|
9528
|
+
if (body.name === null) throw invalidField("validation/invalid-type", "name");
|
|
9298
9529
|
const asset = await this.findOwnAsset(assetId);
|
|
9299
9530
|
if (body.externalId) {
|
|
9300
9531
|
if ((await this.databaseStorage.listAssets(this.projectId)).some((other) => other.id !== asset.id && other.externalId === body.externalId)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.DUPLICATE_EXTERNAL_ID);
|
|
@@ -9322,6 +9553,13 @@ var MockCalmLensApi = class {
|
|
|
9322
9553
|
});
|
|
9323
9554
|
}
|
|
9324
9555
|
async createSignedUrl(assetId, body) {
|
|
9556
|
+
for (const key of [
|
|
9557
|
+
"viewerClaims",
|
|
9558
|
+
"resource",
|
|
9559
|
+
"lens",
|
|
9560
|
+
"transform",
|
|
9561
|
+
"expiresInSeconds"
|
|
9562
|
+
]) if (body[key] === null) throw invalidField(key === "resource" ? "validation/invalid-value" : "validation/invalid-type", key);
|
|
9325
9563
|
const asset = await this.findOwnAsset(assetId);
|
|
9326
9564
|
const expiresInSeconds = body.expiresInSeconds ?? 900;
|
|
9327
9565
|
const resource = body.resource ?? "rendered";
|
|
@@ -9441,7 +9679,11 @@ var MockCalmLensApi = class {
|
|
|
9441
9679
|
/** The upload fields of `POST .../assets`: raw uploads carry them in the query. */
|
|
9442
9680
|
uploadFields(request) {
|
|
9443
9681
|
const upload = request.headers.get("x-calmlens-upload");
|
|
9444
|
-
if (upload !== "content" && upload !== "part")
|
|
9682
|
+
if (upload !== "content" && upload !== "part") {
|
|
9683
|
+
const body = this.json(request);
|
|
9684
|
+
checkMetadata(body.metadata);
|
|
9685
|
+
return body;
|
|
9686
|
+
}
|
|
9445
9687
|
const { query } = request;
|
|
9446
9688
|
const text = (name) => query.get(name) ?? void 0;
|
|
9447
9689
|
const parsed = (name) => {
|
|
@@ -9454,6 +9696,7 @@ var MockCalmLensApi = class {
|
|
|
9454
9696
|
}
|
|
9455
9697
|
};
|
|
9456
9698
|
const total = query.get("totalSizeInBytes");
|
|
9699
|
+
checkMetadata(parsed("metadata"));
|
|
9457
9700
|
return {
|
|
9458
9701
|
name: query.get("name") ?? "",
|
|
9459
9702
|
description: text("description"),
|
|
@@ -9482,7 +9725,7 @@ var MockCalmLensApi = class {
|
|
|
9482
9725
|
if (!fields.name) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_PAYLOAD, { message: "Asset name is required" });
|
|
9483
9726
|
const { contentType, part } = fields;
|
|
9484
9727
|
const bytes = fields.bytes ?? /* @__PURE__ */ new Uint8Array(0);
|
|
9485
|
-
if (contentType !== void 0 && require_ModerationContextLimits.
|
|
9728
|
+
if (contentType !== void 0 && !require_ModerationContextLimits.isAcceptedUploadMimeType(contentType)) throw fail(require_ModerationContextLimits.API_ERROR_CODES.INVALID_UPLOAD_MIME_TYPE, {
|
|
9486
9729
|
message: require_ModerationContextLimits.getRejectedUploadMimeTypeError(contentType),
|
|
9487
9730
|
details: { mimeType: contentType }
|
|
9488
9731
|
});
|
|
@@ -9490,9 +9733,9 @@ var MockCalmLensApi = class {
|
|
|
9490
9733
|
if (part) {
|
|
9491
9734
|
if (part.partNumber > 1) throw fail(require_ModerationContextLimits.API_ERROR_CODES.USE_UPLOAD_PART);
|
|
9492
9735
|
const partSize = bytes.byteLength;
|
|
9493
|
-
const sizeError = (part.totalSizeInBytes === void 0 ? void 0 : this.multipartImageSizeError(type, part.totalSizeInBytes
|
|
9736
|
+
const sizeError = (part.totalSizeInBytes === void 0 ? void 0 : this.multipartImageSizeError(type, part.totalSizeInBytes)) ?? (part.isFinal ? this.multipartTotalSizeError(part.totalSizeInBytes, partSize, true) ?? this.multipartImageSizeError(type, partSize) : void 0);
|
|
9494
9737
|
if (sizeError) throw fail(sizeError);
|
|
9495
|
-
const validation =
|
|
9738
|
+
const validation = require_CalmLensOptionKeys.validateAssetPayload({ uint8Array: bytes }, {
|
|
9496
9739
|
multipart: true,
|
|
9497
9740
|
isFinal: part.isFinal
|
|
9498
9741
|
});
|
|
@@ -9602,9 +9845,9 @@ var MockCalmLensApi = class {
|
|
|
9602
9845
|
});
|
|
9603
9846
|
const received = (asset.content.sizeInBytes ?? 0) + bytes.byteLength;
|
|
9604
9847
|
const upload = this.openUploads.get(assetId);
|
|
9605
|
-
const sizeError = this.multipartImageSizeError(asset.type, received
|
|
9848
|
+
const sizeError = this.multipartImageSizeError(asset.type, received) ?? this.multipartTotalSizeError(upload?.totalSizeInBytes, received, isFinal);
|
|
9606
9849
|
if (sizeError) throw fail(sizeError);
|
|
9607
|
-
const validation =
|
|
9850
|
+
const validation = require_CalmLensOptionKeys.validateAssetPayload({ uint8Array: bytes }, {
|
|
9608
9851
|
multipart: true,
|
|
9609
9852
|
isFinal
|
|
9610
9853
|
});
|
|
@@ -9639,11 +9882,10 @@ var MockCalmLensApi = class {
|
|
|
9639
9882
|
this.recordProcessingEvents(stored, decision);
|
|
9640
9883
|
return stored;
|
|
9641
9884
|
}
|
|
9642
|
-
/** Like the API: image uploads in parts total
|
|
9643
|
-
multipartImageSizeError(type, sizeInBytes
|
|
9885
|
+
/** Like the API: image uploads in parts total at most 20 MiB, at any size below that. */
|
|
9886
|
+
multipartImageSizeError(type, sizeInBytes) {
|
|
9644
9887
|
if (type !== "image") return void 0;
|
|
9645
9888
|
if (sizeInBytes > require_ModerationContextLimits.MAX_IMAGE_UPLOAD_BYTES) return require_ModerationContextLimits.API_ERROR_CODES.MULTIPART_IMAGE_TOO_LARGE;
|
|
9646
|
-
if (isFinal && sizeInBytes < require_ModerationContextLimits.MIN_MULTIPART_IMAGE_UPLOAD_BYTES) return require_ModerationContextLimits.API_ERROR_CODES.MULTIPART_IMAGE_TOO_SMALL;
|
|
9647
9889
|
}
|
|
9648
9890
|
/** Like the API: the parts may not overshoot a declared total, and must reach it at the end. */
|
|
9649
9891
|
multipartTotalSizeError(totalSizeInBytes, receivedSizeInBytes, isFinal) {
|
|
@@ -9915,7 +10157,8 @@ var MockCalmLensApi = class {
|
|
|
9915
10157
|
if (!cursor) return {
|
|
9916
10158
|
items: [],
|
|
9917
10159
|
nextCursor: `mock_${this.eventFeed.length}`,
|
|
9918
|
-
hasMore: false
|
|
10160
|
+
hasMore: false,
|
|
10161
|
+
excludedTypes: []
|
|
9919
10162
|
};
|
|
9920
10163
|
const match = /^mock_(\d+)$/.exec(cursor);
|
|
9921
10164
|
const position = match ? Number(match[1]) : NaN;
|
|
@@ -9925,7 +10168,8 @@ var MockCalmLensApi = class {
|
|
|
9925
10168
|
return {
|
|
9926
10169
|
items,
|
|
9927
10170
|
nextCursor: `mock_${next}`,
|
|
9928
|
-
hasMore: next < this.eventFeed.length
|
|
10171
|
+
hasMore: next < this.eventFeed.length,
|
|
10172
|
+
excludedTypes: []
|
|
9929
10173
|
};
|
|
9930
10174
|
}
|
|
9931
10175
|
/**
|
|
@@ -10070,7 +10314,7 @@ var MockCalmLensApi = class {
|
|
|
10070
10314
|
this.lenses.set(lens.identifier, lens);
|
|
10071
10315
|
return lens;
|
|
10072
10316
|
}
|
|
10073
|
-
if (existing.name === options.name && (existing.description ?? null) === (options.description ?? null) && existing.type === options.type && existing.active === options.active && require_CalmLensServerClient.stringifyJsonCanonical(existing.
|
|
10317
|
+
if (existing.name === options.name && (existing.description ?? null) === (options.description ?? null) && existing.type === options.type && existing.active === options.active && require_CalmLensServerClient.stringifyJsonCanonical(existing.transform ?? null) === require_CalmLensServerClient.stringifyJsonCanonical(options.transform ?? null) && existing.version === options.version) return existing;
|
|
10074
10318
|
if (options.version > existing.version) {
|
|
10075
10319
|
const lens = {
|
|
10076
10320
|
...existing,
|
|
@@ -10099,6 +10343,17 @@ var MockCalmLensApi = class {
|
|
|
10099
10343
|
code: "asset/not-found",
|
|
10100
10344
|
message: "Asset not found"
|
|
10101
10345
|
}, url);
|
|
10346
|
+
const invalidTransform = () => this.jsonResponse(400, {
|
|
10347
|
+
code: "asset/invalid-transform",
|
|
10348
|
+
message: "Invalid transform selector"
|
|
10349
|
+
}, url);
|
|
10350
|
+
let selector;
|
|
10351
|
+
try {
|
|
10352
|
+
selector = require_ModerationContextLimits.parseTransformSelector(request.rawSegments.slice(4).join("/"));
|
|
10353
|
+
} catch {
|
|
10354
|
+
return invalidTransform();
|
|
10355
|
+
}
|
|
10356
|
+
if (resource === "original" && (selector.lens || selector.options)) return invalidTransform();
|
|
10102
10357
|
if (root !== "assets" || projectId !== this.projectId || !assetIdentifier) return notFound();
|
|
10103
10358
|
const asset = (await this.databaseStorage.listAssets(this.projectId)).find((asset) => asset.id === assetIdentifier || asset.externalId === assetIdentifier);
|
|
10104
10359
|
if (!asset) return notFound();
|
|
@@ -10136,6 +10391,13 @@ var MockCalmLensApi = class {
|
|
|
10136
10391
|
code: "asset/api-key-missing-permission",
|
|
10137
10392
|
message: "This API key needs assets:download permission for this asset’s folder."
|
|
10138
10393
|
}, url);
|
|
10394
|
+
if (selector.options) {
|
|
10395
|
+
const { unknownKeys, invalidKeys } = require_ModerationContextLimits.checkTransformOptions(selector.options);
|
|
10396
|
+
if (unknownKeys.length || invalidKeys.length) return this.jsonResponse(400, {
|
|
10397
|
+
code: "asset/invalid-transform-options",
|
|
10398
|
+
message: `Invalid transform options: ${[...unknownKeys, ...invalidKeys].join(", ")}`
|
|
10399
|
+
}, url);
|
|
10400
|
+
}
|
|
10139
10401
|
const parts = [...storedContent.parts.entries()].sort(([left], [right]) => left - right).map(([, value]) => value);
|
|
10140
10402
|
const bytes = new Uint8Array(parts.reduce((sum, value) => sum + value.byteLength, 0));
|
|
10141
10403
|
let offset = 0;
|
|
@@ -10172,9 +10434,9 @@ var InMemoryMockImageStorage = class {
|
|
|
10172
10434
|
this.content = /* @__PURE__ */ new Map();
|
|
10173
10435
|
}
|
|
10174
10436
|
async putContent(assetId, content) {
|
|
10175
|
-
const validation =
|
|
10437
|
+
const validation = require_CalmLensOptionKeys.validateAssetPayload(content);
|
|
10176
10438
|
if (!validation.ok) throw new Error(validation.error);
|
|
10177
|
-
const bytes = await
|
|
10439
|
+
const bytes = await require_CalmLensOptionKeys.assetDataToUint8Array(require_CalmLensOptionKeys.assetToData(content));
|
|
10178
10440
|
this.content.set(assetId, {
|
|
10179
10441
|
assetId,
|
|
10180
10442
|
parts: /* @__PURE__ */ new Map([[1, bytes]]),
|
|
@@ -10182,12 +10444,12 @@ var InMemoryMockImageStorage = class {
|
|
|
10182
10444
|
});
|
|
10183
10445
|
}
|
|
10184
10446
|
async putPart(assetId, part) {
|
|
10185
|
-
const validation =
|
|
10447
|
+
const validation = require_CalmLensOptionKeys.validateAssetPayload(part, {
|
|
10186
10448
|
multipart: true,
|
|
10187
10449
|
isFinal: part.isFinal
|
|
10188
10450
|
});
|
|
10189
10451
|
if (!validation.ok) throw new Error(validation.error);
|
|
10190
|
-
const bytes = await
|
|
10452
|
+
const bytes = await require_CalmLensOptionKeys.assetDataToUint8Array(require_CalmLensOptionKeys.assetToData(part));
|
|
10191
10453
|
const existing = this.content.get(assetId) ?? {
|
|
10192
10454
|
assetId,
|
|
10193
10455
|
parts: /* @__PURE__ */ new Map(),
|
|
@@ -10244,7 +10506,6 @@ var InMemoryMockDatabaseStorage = class {
|
|
|
10244
10506
|
this.folders.delete(folderId);
|
|
10245
10507
|
}
|
|
10246
10508
|
};
|
|
10247
|
-
// src/testing/MockCalmLensServerClient.ts
|
|
10248
10509
|
const apis = /* @__PURE__ */ new WeakMap();
|
|
10249
10510
|
/** The in-memory API a mock server client runs against, for `MockCalmLensAppClient`. */
|
|
10250
10511
|
const getMockApi = (client) => {
|
|
@@ -10260,7 +10521,7 @@ const mockClientOptions = (api, endpoints, session) => {
|
|
|
10260
10521
|
const fetch = api.createFetch(endpoints, session);
|
|
10261
10522
|
const hooks = {
|
|
10262
10523
|
sleep: async (ms, signal) => {
|
|
10263
|
-
await
|
|
10524
|
+
await require_CalmLensOptionKeys.sleep(0, signal);
|
|
10264
10525
|
api.waitedMs += ms;
|
|
10265
10526
|
},
|
|
10266
10527
|
now: () => api.waitedMs,
|
|
@@ -10275,7 +10536,7 @@ const mockClientOptions = (api, endpoints, session) => {
|
|
|
10275
10536
|
fetch,
|
|
10276
10537
|
uploadFetch: fetch,
|
|
10277
10538
|
cdnFetch: fetch,
|
|
10278
|
-
[
|
|
10539
|
+
[require_CalmLensOptionKeys.MOCK_HOOKS]: hooks
|
|
10279
10540
|
};
|
|
10280
10541
|
};
|
|
10281
10542
|
/**
|
|
@@ -10292,7 +10553,11 @@ var MockCalmLensServerClient = class extends require_CalmLensServerClient.CalmLe
|
|
|
10292
10553
|
* `mockOptions`. `maxRetries` defaults to 0, so a failed request fails once; retry backoff and
|
|
10293
10554
|
* `assets.waitForDecision` take no real time.
|
|
10294
10555
|
*/
|
|
10295
|
-
constructor(
|
|
10556
|
+
constructor(input) {
|
|
10557
|
+
const options = {
|
|
10558
|
+
...input,
|
|
10559
|
+
projectId: input.projectId ?? "project-1"
|
|
10560
|
+
};
|
|
10296
10561
|
require_ModerationContextLimits.validateServerClientOptions(options);
|
|
10297
10562
|
const { mockOptions = {}, ...clientOptions } = options;
|
|
10298
10563
|
const api = new MockCalmLensApi({
|
|
@@ -10394,7 +10659,6 @@ var MockCalmLensServerClient = class extends require_CalmLensServerClient.CalmLe
|
|
|
10394
10659
|
}
|
|
10395
10660
|
};
|
|
10396
10661
|
// src/testing/MockCalmLensAppClient.ts
|
|
10397
|
-
const MOCK_PROJECT_ID = "proj_0000000000000000c1a5";
|
|
10398
10662
|
/**
|
|
10399
10663
|
* The real `CalmLensAppClient`, answered by the in-memory API of a `MockCalmLensServerClient`.
|
|
10400
10664
|
* The API applies `mockOptions.preset` to this client's uploads like CalmLens applies an upload
|
|
@@ -10417,7 +10681,6 @@ var MockCalmLensAppClient = class extends require_CalmLensAppClient.CalmLensAppC
|
|
|
10417
10681
|
folderId: null,
|
|
10418
10682
|
includeSubfolders: true
|
|
10419
10683
|
}]),
|
|
10420
|
-
projectId: MOCK_PROJECT_ID,
|
|
10421
10684
|
mockOptions: { moderate: mockOptions.moderate }
|
|
10422
10685
|
});
|
|
10423
10686
|
let endpoints;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as CalmLensAppClient } from "./CalmLensAppClient-
|
|
1
|
+
import { E as CalmLensAppClientOptions, Mt as ViewerClaims, h as AssetModerationStatus, j as CdnTransform } from "./CalmLensTypes-COJbOuiv.js";
|
|
2
|
+
import { t as CalmLensAppClient } from "./CalmLensAppClient-DDLojj0P.js";
|
|
3
3
|
/**
|
|
4
4
|
* The parts of an asset, as the API or a webhook returns it, that the media component reads.
|
|
5
5
|
* Assets from `CalmLensServerClient` fit as they are.
|
|
@@ -469,13 +469,26 @@ declare const ICON_ATTRIBUTES: {
|
|
|
469
469
|
readonly "stroke-linejoin": "round";
|
|
470
470
|
readonly "aria-hidden": "true";
|
|
471
471
|
};
|
|
472
|
+
interface ProgressFetchOptions {
|
|
473
|
+
/**
|
|
474
|
+
* The size of everything this fetch will send, such as the file's size. An upload larger than
|
|
475
|
+
* the client's `partSizeBytes` goes in several requests, and only this total keeps the
|
|
476
|
+
* reported share of the file from restarting with each part.
|
|
477
|
+
*/
|
|
478
|
+
totalBytes?: number;
|
|
479
|
+
}
|
|
472
480
|
/**
|
|
473
481
|
* A `fetch` that reports how many bytes of the request body have been sent, which `fetch` itself
|
|
474
482
|
* can't do. It sends through `XMLHttpRequest`, so the upload components pass it to
|
|
475
483
|
* `CalmLensAppClient` as `uploadFetch`. Without `XMLHttpRequest` it falls back to `fetch` and
|
|
476
484
|
* reports nothing.
|
|
485
|
+
*
|
|
486
|
+
* The count runs across the requests sent through it: `sentBytes` adds the bodies of earlier
|
|
487
|
+
* requests that succeeded, so a file uploaded in parts keeps counting up. `totalBytes` is
|
|
488
|
+
* `options.totalBytes` when given, otherwise those earlier bodies plus the current one. Create
|
|
489
|
+
* one for each file.
|
|
477
490
|
*/
|
|
478
|
-
declare const createProgressFetch: (onProgress: (sentBytes: number, totalBytes: number) => void) => ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>);
|
|
491
|
+
declare const createProgressFetch: (onProgress: (sentBytes: number, totalBytes: number) => void, { totalBytes }?: ProgressFetchOptions) => ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>);
|
|
479
492
|
/**
|
|
480
493
|
* The components' stylesheet, also shipped as `calmlens/styles.css`. The React components
|
|
481
494
|
* render it themselves (React hoists it into the head, on the server too); with Vue, Svelte or
|
|
@@ -523,4 +536,4 @@ declare const CALMLENS_THEME: {
|
|
|
523
536
|
* as the stylesheet mixes them from the page's text colour.
|
|
524
537
|
*/
|
|
525
538
|
declare const resolveTheme: (overrides?: Partial<CalmLensTheme>) => CalmLensTheme;
|
|
526
|
-
export {
|
|
539
|
+
export { CustomUploadContext as A, isFileAccepted as B, formatMessage as C, getUploadItemOutcome as D, getUploadItemMessage as E, UploadFile as F, MediaSource as G, MediaImageSource as H, UploadItem as I, pickMediaSource as J, MediaState as K, UploadSnapshot as L, UploadClient as M, UploadController as N, resolveMessages as O, UploadControllerOptions as P, UploadStage as R, formatBytes as S, getMediaUnavailableMessage as T, MediaOptions as U, MediaAsset as V, MediaSettings as W, resolveMediaProps as Y, DEFAULT_MESSAGES as _, ProgressFetchOptions as a, describeUploadItem as b, ICON_ATTRIBUTES as c, MediaProps as d, UploaderDisplayOptions as f, CalmLensMessages as g, getMediaLoadKey as h, CALMLENS_STYLES as i, CustomUploadResult as j, CalmLensUpload as k, IconName as l, getMediaAspectRatio as m, CalmLensTheme as n, createProgressFetch as o, UploaderProps as p, getMediaState as q, resolveTheme as r, ICONS as s, CALMLENS_THEME as t, MediaDisplayOptions as u, UploadItemView as v, getDropzoneHint as w, describeUploader as x, UploaderView as y, createUploadController as z };
|