calmlens 0.29.0 → 0.29.2
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 +24 -2
- package/cjs/{BrowserUpload-CcSQI7Kf.js → BrowserUpload-CCXt4DAY.js} +1 -1
- package/cjs/{CalmLensAppClient-BPILD5mg.js → CalmLensAppClient-ea-qXkmD.js} +7 -6
- package/cjs/{CalmLensConnection-Wfxn25LT.js → CalmLensConnection-BrySN2M3.js} +29 -28
- package/cjs/CalmLensError-DPHJaVjX.js +1066 -0
- package/cjs/{CalmLensServerClient-C_42j_i4.js → CalmLensServerClient-FD7H7KvL.js} +21 -20
- package/cjs/{TestTriggers-uL2Ec8Vt-cPmmKvYd.js → CalmLensTestInputArguments-BXDBAOg_.js} +50 -22
- package/cjs/{Core-CfdovxKJ.js → Core-DMFa3EUp.js} +4 -3
- package/cjs/{ModerationContextLimits-DXlPrt4K.js → ModerationContextLimits-1XP4ZTQk.js} +67 -1126
- package/cjs/{ReactUpload-CzsQwVKM.js → ReactUpload-gaeiPSeH.js} +1 -1
- package/cjs/{TestTriggers-dognME9k-PWyIfHMI.d.ts → TestTriggers-CFnel6a9.d.ts} +1 -2
- package/cjs/{UploadController-D_Y5wktq.js → UploadController-CyPTBuZg.js} +6 -6
- package/cjs/app.js +22 -21
- package/cjs/elements.js +4 -4
- package/cjs/index.js +21 -20
- package/cjs/react-native.js +4 -4
- package/cjs/react.js +5 -5
- package/cjs/server.js +22 -21
- package/cjs/test-inputs.d.ts +6 -2
- package/cjs/test-inputs.js +23 -13
- package/cjs/testing.d.ts +3 -3
- package/cjs/testing.js +138 -133
- package/cjs/{ui-CkOexkAO.js → ui-DNP1uWQy.js} +2 -2
- package/cjs/ui.js +3 -3
- package/cjs/vue.js +4 -4
- package/esm/{BrowserUpload-DJ2euKyv.js → BrowserUpload-Bu6eWqQS.js} +1 -1
- package/esm/{CalmLensAppClient-CCT5Em2S.js → CalmLensAppClient-xp-fH6Lz.js} +3 -2
- package/esm/{CalmLensConnection-CfBXkam-.js → CalmLensConnection-DwG5yBk2.js} +2 -1
- package/esm/CalmLensError-BDWThPCr.js +917 -0
- package/esm/{CalmLensServerClient-e6gVcMxy.js → CalmLensServerClient-CKlNBBo3.js} +3 -2
- package/esm/{TestTriggers-uL2Ec8Vt-DYbTEJWm.js → CalmLensTestInputArguments-Xh4GIadS.js} +22 -1
- package/esm/{Core-CojlqrKH.js → Core-DnCeTmvS.js} +3 -2
- package/esm/{ModerationContextLimits-Abu_L1Df.js → ModerationContextLimits-CtAyz60h.js} +3 -918
- package/esm/{ReactUpload-CDrA7hRn.js → ReactUpload-D30YlRui.js} +1 -1
- package/esm/{TestTriggers-dognME9k-PWyIfHMI.d.ts → TestTriggers-CFnel6a9.d.ts} +1 -2
- package/esm/{UploadController-BubUXclM.js → UploadController-DENryQ8H.js} +2 -2
- package/esm/app.js +3 -2
- package/esm/elements.js +4 -4
- package/esm/index.js +3 -1
- package/esm/react-native.js +4 -4
- package/esm/react.js +5 -5
- package/esm/server.js +3 -2
- package/esm/test-inputs.d.ts +6 -2
- package/esm/test-inputs.js +12 -1
- package/esm/testing.d.ts +3 -3
- package/esm/testing.js +11 -7
- package/esm/{ui--AzgLLVf.js → ui-DUEBbRJ0.js} +2 -2
- package/esm/ui.js +3 -3
- package/esm/vue.js +4 -4
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const require_CalmLensError = require("./CalmLensError-DPHJaVjX.js");
|
|
2
|
+
const require_ModerationContextLimits = require("./ModerationContextLimits-1XP4ZTQk.js");
|
|
3
|
+
const require_CalmLensConnection = require("./CalmLensConnection-BrySN2M3.js");
|
|
3
4
|
const require_CryptoUtils_BLCa_oZe = require("./CryptoUtils-BLCa-oZe-leCkr1ko.js");
|
|
4
5
|
// src/contract/JsonUtils.js
|
|
5
6
|
const stringifyJsonCanonical = (value) => JSON.stringify(value, (_key, nestedValue) => {
|
|
@@ -56,11 +57,11 @@ const decodeUploadToken = (token) => {
|
|
|
56
57
|
* give the same token every time, for comparing with known tokens in tests.
|
|
57
58
|
*/
|
|
58
59
|
const signUploadTokenWithApiKey = async (apiKey, options, { now = Date.now(), nonce = crypto.randomUUID() } = {}) => {
|
|
59
|
-
if (!options || typeof options !== "object") throw
|
|
60
|
+
if (!options || typeof options !== "object") throw require_CalmLensError.invalidArgument("Options are required");
|
|
60
61
|
const { uploadPresetId, externalId, expiresIn = 600 } = options;
|
|
61
62
|
require_ModerationContextLimits.encodePathSegment(uploadPresetId, "Upload preset ID");
|
|
62
|
-
if (!Number.isInteger(expiresIn) || expiresIn < 1 || expiresIn > 3600) throw
|
|
63
|
-
if (externalId !== void 0 && (typeof externalId !== "string" || !externalId)) throw
|
|
63
|
+
if (!Number.isInteger(expiresIn) || expiresIn < 1 || expiresIn > 3600) throw require_CalmLensError.invalidArgument(`expiresIn must be a whole number from 1 to ${UPLOAD_TOKEN_MAX_TTL_SECONDS}`);
|
|
64
|
+
if (externalId !== void 0 && (typeof externalId !== "string" || !externalId)) throw require_CalmLensError.invalidArgument("externalId must be a non-empty string");
|
|
64
65
|
const expiresAt = now + expiresIn * 1e3;
|
|
65
66
|
return {
|
|
66
67
|
token: await signUploadToken({
|
|
@@ -95,7 +96,7 @@ const payloadToText = (payload) => {
|
|
|
95
96
|
const view = ArrayBuffer.isView(payload) ? new Uint8Array(payload.buffer, payload.byteOffset, payload.byteLength) : new Uint8Array(payload);
|
|
96
97
|
return new TextDecoder("utf-8", { fatal: false }).decode(view);
|
|
97
98
|
}
|
|
98
|
-
throw
|
|
99
|
+
throw require_CalmLensError.invalidArgument("Webhook payload must be the raw request body as a string, Uint8Array/Buffer or ArrayBuffer, not parsed JSON");
|
|
99
100
|
};
|
|
100
101
|
/**
|
|
101
102
|
* Verifies a webhook delivery: `x-calmlens-signature` must contain a `v1=` HMAC-SHA256 of
|
|
@@ -129,17 +130,17 @@ async function verifyWebhookSignature(options) {
|
|
|
129
130
|
* so keep a default branch when you switch on `type`.
|
|
130
131
|
*/
|
|
131
132
|
async function parseWebhookEvent(options) {
|
|
132
|
-
if (!await verifyWebhookSignature(options)) throw new
|
|
133
|
+
if (!await verifyWebhookSignature(options)) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_WEBHOOK_SIGNATURE, { message: "Webhook signature or timestamp did not verify" });
|
|
133
134
|
let event;
|
|
134
135
|
try {
|
|
135
136
|
event = JSON.parse(payloadToText(options.payload));
|
|
136
137
|
} catch (cause) {
|
|
137
|
-
throw new
|
|
138
|
+
throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_WEBHOOK_PAYLOAD, {
|
|
138
139
|
message: "Webhook body is not JSON",
|
|
139
140
|
cause
|
|
140
141
|
});
|
|
141
142
|
}
|
|
142
|
-
if (!isWebhookEvent(event)) throw new
|
|
143
|
+
if (!isWebhookEvent(event)) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_WEBHOOK_PAYLOAD, { message: "Webhook body is not a CalmLens event" });
|
|
143
144
|
return event;
|
|
144
145
|
}
|
|
145
146
|
const isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
@@ -308,7 +309,7 @@ var CalmLensServerClient = class {
|
|
|
308
309
|
constructor(clientOptions = {}, lenses) {
|
|
309
310
|
const options = withEnvironmentDefaults(clientOptions);
|
|
310
311
|
require_ModerationContextLimits.validateServerClientOptions(options);
|
|
311
|
-
if ((require_ModerationContextLimits.isBrowserRuntime() || require_ModerationContextLimits.isReactNativeRuntime()) && !options.dangerouslyAllowBrowser) throw
|
|
312
|
+
if ((require_ModerationContextLimits.isBrowserRuntime() || require_ModerationContextLimits.isReactNativeRuntime()) && !options.dangerouslyAllowBrowser) throw require_CalmLensError.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.");
|
|
312
313
|
const { apiKey, projectId, ...rest } = options;
|
|
313
314
|
this.#apiKey = apiKey;
|
|
314
315
|
this.#settings = {
|
|
@@ -358,8 +359,8 @@ var CalmLensServerClient = class {
|
|
|
358
359
|
"PATCH",
|
|
359
360
|
"DELETE"
|
|
360
361
|
];
|
|
361
|
-
if (typeof method !== "string" || !methods.includes(method)) throw
|
|
362
|
-
if (typeof path !== "string" || !path.startsWith("/") || path.startsWith("//")) throw
|
|
362
|
+
if (typeof method !== "string" || !methods.includes(method)) throw require_CalmLensError.invalidArgument(`method must be one of ${methods.join(", ")}`);
|
|
363
|
+
if (typeof path !== "string" || !path.startsWith("/") || path.startsWith("//")) throw require_CalmLensError.invalidArgument("path must start with \"/\", such as \"/assets/asset_123\"");
|
|
363
364
|
const { headers: callHeaders, ...rest } = requestOptions ?? {};
|
|
364
365
|
return this.#send(void 0, {
|
|
365
366
|
...rest,
|
|
@@ -438,7 +439,7 @@ var CalmLensServerClient = class {
|
|
|
438
439
|
expiresIn: expiresIn ?? 900,
|
|
439
440
|
...location.resource !== void 0 ? { resource: location.resource } : {}
|
|
440
441
|
} });
|
|
441
|
-
if (!signed || typeof signed.url !== "string" || !signed.url || typeof signed.expiresAt !== "number") throw new
|
|
442
|
+
if (!signed || typeof signed.url !== "string" || !signed.url || typeof signed.expiresAt !== "number") throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, { message: "The API returned no signed asset URL" });
|
|
442
443
|
return require_ModerationContextLimits.copyLastResponse({
|
|
443
444
|
url: require_ModerationContextLimits.appendSignedLocation(signed.url, location),
|
|
444
445
|
expiresAt: signed.expiresAt
|
|
@@ -462,7 +463,7 @@ var CalmLensServerClient = class {
|
|
|
462
463
|
serve: async (options, requestOptions) => {
|
|
463
464
|
const { init, resource = "rendered", ...urlOptions } = checked("cdn.serve", options);
|
|
464
465
|
const connection = this.#connection.forCall("cdn.serve", requestOptions);
|
|
465
|
-
if (requestOptions?.extraBody) throw
|
|
466
|
+
if (requestOptions?.extraBody) throw require_CalmLensError.invalidArgument("cdn.serve sends no body: extraBody can't apply");
|
|
466
467
|
const url = this.cdn.getAssetUrl({
|
|
467
468
|
...urlOptions,
|
|
468
469
|
resource
|
|
@@ -891,7 +892,7 @@ sign: async (options) => {
|
|
|
891
892
|
*/
|
|
892
893
|
async ensureLens(options, requestOptions) {
|
|
893
894
|
checked("ensureLens", options);
|
|
894
|
-
if (!options?.identifier) throw
|
|
895
|
+
if (!options?.identifier) throw require_CalmLensError.invalidArgument("Lens identifier is required");
|
|
895
896
|
const [lens] = await this.ensureLenses({ lenses: [options] }, requestOptions);
|
|
896
897
|
return lens;
|
|
897
898
|
}
|
|
@@ -903,8 +904,8 @@ sign: async (options) => {
|
|
|
903
904
|
async ensureLenses(options, requestOptions) {
|
|
904
905
|
require_CalmLensConnection.validateCallOptions(requestOptions);
|
|
905
906
|
const { lenses } = checked("ensureLenses", options);
|
|
906
|
-
if (!Array.isArray(lenses) || lenses.length === 0) throw
|
|
907
|
-
if (lenses.some((option) => !option?.identifier)) throw
|
|
907
|
+
if (!Array.isArray(lenses) || lenses.length === 0) throw require_CalmLensError.invalidArgument("At least one lens is required");
|
|
908
|
+
if (lenses.some((option) => !option?.identifier)) throw require_CalmLensError.invalidArgument("Lens identifier is required");
|
|
908
909
|
for (const lens of lenses) checked("ensureLens", lens);
|
|
909
910
|
const { ensuredLenses, pendingEnsureLenses } = this.#lenses;
|
|
910
911
|
const missingOptions = [];
|
|
@@ -928,7 +929,7 @@ sign: async (options) => {
|
|
|
928
929
|
}
|
|
929
930
|
return lenses.map((option) => {
|
|
930
931
|
const lens = ensuredLenses.get(getEnsureLensCacheKey(option));
|
|
931
|
-
if (!lens) throw new
|
|
932
|
+
if (!lens) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, { message: `CalmLens did not return lens "${option.identifier}"` });
|
|
932
933
|
return lens;
|
|
933
934
|
});
|
|
934
935
|
}
|
|
@@ -938,11 +939,11 @@ sign: async (options) => {
|
|
|
938
939
|
async #submitEnsureLensesChunk(options, requestOptions) {
|
|
939
940
|
const result = await this.#send("ensureLenses", requestOptions, "PUT", `${this.#projectPath}/lenses`, { body: { lenses: options } });
|
|
940
941
|
const returned = Array.isArray(result?.lenses) ? result.lenses : [];
|
|
941
|
-
if (returned.length !== options.length) throw new
|
|
942
|
+
if (returned.length !== options.length) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, { message: `Expected ${options.length} lenses but CalmLens returned ${returned.length}` });
|
|
942
943
|
const { ensuredLenses } = this.#lenses;
|
|
943
944
|
for (const [index, lens] of returned.entries()) {
|
|
944
945
|
const optionsForLens = options[index];
|
|
945
|
-
if (lens?.identifier !== optionsForLens.identifier) throw new
|
|
946
|
+
if (lens?.identifier !== optionsForLens.identifier) throw new require_CalmLensError.CalmLensError(require_CalmLensError.SDK_ERROR_CODES.INVALID_RESPONSE, { message: `Expected lens "${optionsForLens.identifier}" at position ${index}` });
|
|
946
947
|
for (const [cacheKey, cachedLens] of ensuredLenses) if (cachedLens.identifier === optionsForLens.identifier) ensuredLenses.delete(cacheKey);
|
|
947
948
|
ensuredLenses.set(getEnsureLensCacheKey(optionsForLens), lens);
|
|
948
949
|
}
|
|
@@ -19,9 +19,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
19
19
|
value: mod,
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
22
|
+
const require_CalmLensError = require("./CalmLensError-DPHJaVjX.js");
|
|
22
23
|
const require_CryptoUtils_BLCa_oZe = require("./CryptoUtils-BLCa-oZe-leCkr1ko.js");
|
|
23
24
|
let zod = require("zod");
|
|
24
|
-
zod = __toESM(zod, 1);
|
|
25
|
+
let zod$1 = __toESM(zod, 1);
|
|
26
|
+
zod = __toESM(zod);
|
|
25
27
|
// src/contract/ModerationCategories-CHFRoeWV.js
|
|
26
28
|
const CLASSIFICATION_CATEGORIES = [
|
|
27
29
|
"sexual",
|
|
@@ -34,7 +36,7 @@ const CLASSIFICATION_CATEGORIES = [
|
|
|
34
36
|
"profanity"
|
|
35
37
|
];
|
|
36
38
|
// src/contract/LazySchema-BKMpWIaF.js
|
|
37
|
-
const registryMap = zod.globalRegistry._map;
|
|
39
|
+
const registryMap = zod$1.globalRegistry._map;
|
|
38
40
|
/**
|
|
39
41
|
* A schema built the first time anything reads it, rather than when its module loads. Building
|
|
40
42
|
* Zod schemas costs a new isolate CPU before its first request, so a module whose schemas most
|
|
@@ -150,7 +152,7 @@ const JURISDICTIONS = {
|
|
|
150
152
|
optional: false
|
|
151
153
|
}
|
|
152
154
|
};
|
|
153
|
-
const JURISDICTION_SCHEMA = /* @__PURE__ */ lazySchema(() => zod.enum(Object.keys(JURISDICTIONS)));
|
|
155
|
+
const JURISDICTION_SCHEMA = /* @__PURE__ */ lazySchema(() => zod$1.enum(Object.keys(JURISDICTIONS)));
|
|
154
156
|
Object.keys(JURISDICTIONS).filter((code) => !JURISDICTIONS[code].optional);
|
|
155
157
|
Object.keys(JURISDICTIONS).filter((code) => JURISDICTIONS[code].optional);
|
|
156
158
|
new Set("AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW".split(" "));
|
|
@@ -1178,9 +1180,9 @@ function getModerationQualifierInfo(qualifier) {
|
|
|
1178
1180
|
return MODERATION_QUALIFIER_INFO[qualifier];
|
|
1179
1181
|
}
|
|
1180
1182
|
/** Authenticated test inputs can add regional delivery restrictions without inventing evidence. */
|
|
1181
|
-
const TEST_REGIONAL_ACTIONS_SCHEMA = /* @__PURE__ */ lazySchema(() => zod.array(zod.object({
|
|
1183
|
+
const TEST_REGIONAL_ACTIONS_SCHEMA = /* @__PURE__ */ lazySchema(() => zod$1.array(zod$1.object({
|
|
1182
1184
|
region: JURISDICTION_SCHEMA.exclude(["global"]),
|
|
1183
|
-
action: zod.enum([
|
|
1185
|
+
action: zod$1.enum([
|
|
1184
1186
|
"limit",
|
|
1185
1187
|
"age-restrict",
|
|
1186
1188
|
"block"
|
|
@@ -1646,45 +1648,45 @@ const TEST_FACE_AGE_PRESETS = {
|
|
|
1646
1648
|
}
|
|
1647
1649
|
};
|
|
1648
1650
|
const TEST_FACE_AGE_MAX = 120;
|
|
1649
|
-
const basisPoints = /* @__PURE__ */ lazySchema(() => zod.number().int().min(0).max(TEST_DETECTION_BOX_MAX));
|
|
1651
|
+
const basisPoints = /* @__PURE__ */ lazySchema(() => zod$1.number().int().min(0).max(TEST_DETECTION_BOX_MAX));
|
|
1650
1652
|
const detectionShape = {
|
|
1651
|
-
box: /* @__PURE__ */ lazySchema(() => zod.tuple([
|
|
1653
|
+
box: /* @__PURE__ */ lazySchema(() => zod$1.tuple([
|
|
1652
1654
|
basisPoints,
|
|
1653
1655
|
basisPoints,
|
|
1654
1656
|
basisPoints,
|
|
1655
1657
|
basisPoints
|
|
1656
1658
|
])),
|
|
1657
|
-
confidence: /* @__PURE__ */ lazySchema(() => zod.number().int().min(0).max(100).optional())
|
|
1659
|
+
confidence: /* @__PURE__ */ lazySchema(() => zod$1.number().int().min(0).max(100).optional())
|
|
1658
1660
|
};
|
|
1659
1661
|
const fitsImage = ({ box: [left, top, width, height] }) => left + width <= 1e4 && top + height <= 1e4;
|
|
1660
1662
|
const BOX_MESSAGE = msg("A box must lie inside the image: left + width and top + height are at most 10000.");
|
|
1661
|
-
const ageYears = /* @__PURE__ */ lazySchema(() => zod.number().int().min(0).max(120));
|
|
1662
|
-
const TEST_DETECTED_PERSON_SCHEMA = /* @__PURE__ */ lazySchema(() => zod.object(detectionShape).strict().refine(fitsImage, BOX_MESSAGE));
|
|
1663
|
-
const TEST_DETECTED_FACE_SCHEMA = /* @__PURE__ */ lazySchema(() => zod.object({
|
|
1663
|
+
const ageYears = /* @__PURE__ */ lazySchema(() => zod$1.number().int().min(0).max(120));
|
|
1664
|
+
const TEST_DETECTED_PERSON_SCHEMA = /* @__PURE__ */ lazySchema(() => zod$1.object(detectionShape).strict().refine(fitsImage, BOX_MESSAGE));
|
|
1665
|
+
const TEST_DETECTED_FACE_SCHEMA = /* @__PURE__ */ lazySchema(() => zod$1.object({
|
|
1664
1666
|
...detectionShape,
|
|
1665
|
-
age: zod.union([zod.enum(["adult", "minor"]), zod.object({
|
|
1667
|
+
age: zod$1.union([zod$1.enum(["adult", "minor"]), zod$1.object({
|
|
1666
1668
|
low: ageYears,
|
|
1667
1669
|
high: ageYears
|
|
1668
1670
|
}).strict().refine(({ low, high }) => low <= high, msg("An age range's low must not be above its high."))]).optional()
|
|
1669
1671
|
}).strict().refine(fitsImage, BOX_MESSAGE));
|
|
1670
1672
|
/** Person and face detection results a test image reports instead of running detection. */
|
|
1671
|
-
const TEST_DETECTIONS_SCHEMA = /* @__PURE__ */ lazySchema(() => zod.object({
|
|
1672
|
-
people: zod.union([zod.array(TEST_DETECTED_PERSON_SCHEMA).max(32), zod.literal("unavailable")]).optional(),
|
|
1673
|
-
faces: zod.union([zod.array(TEST_DETECTED_FACE_SCHEMA).max(32), zod.literal("unavailable")]).optional()
|
|
1673
|
+
const TEST_DETECTIONS_SCHEMA = /* @__PURE__ */ lazySchema(() => zod$1.object({
|
|
1674
|
+
people: zod$1.union([zod$1.array(TEST_DETECTED_PERSON_SCHEMA).max(32), zod$1.literal("unavailable")]).optional(),
|
|
1675
|
+
faces: zod$1.union([zod$1.array(TEST_DETECTED_FACE_SCHEMA).max(32), zod$1.literal("unavailable")]).optional()
|
|
1674
1676
|
}).strict());
|
|
1675
1677
|
/** Each row is one qualifying instance. Unselected qualifiers are explicitly absent. */
|
|
1676
|
-
const TEST_INPUT_SCHEMA = /* @__PURE__ */ lazySchema(() => zod.object({
|
|
1678
|
+
const TEST_INPUT_SCHEMA = /* @__PURE__ */ lazySchema(() => zod$1.object({
|
|
1677
1679
|
regionalActions: TEST_REGIONAL_ACTIONS_SCHEMA.optional(),
|
|
1678
|
-
unassessedCategories: zod.array(zod.enum(CLASSIFICATION_CATEGORIES)).max(CLASSIFICATION_CATEGORIES.length).optional(),
|
|
1679
|
-
instances: zod.array(zod.object({
|
|
1680
|
-
category: zod.enum(CLASSIFICATION_CATEGORIES),
|
|
1681
|
-
score: zod.number().min(0).max(1).optional(),
|
|
1682
|
-
action: zod.enum([
|
|
1680
|
+
unassessedCategories: zod$1.array(zod$1.enum(CLASSIFICATION_CATEGORIES)).max(CLASSIFICATION_CATEGORIES.length).optional(),
|
|
1681
|
+
instances: zod$1.array(zod$1.object({
|
|
1682
|
+
category: zod$1.enum(CLASSIFICATION_CATEGORIES),
|
|
1683
|
+
score: zod$1.number().min(0).max(1).optional(),
|
|
1684
|
+
action: zod$1.enum([
|
|
1683
1685
|
"limit",
|
|
1684
1686
|
"age-restrict",
|
|
1685
1687
|
"block"
|
|
1686
1688
|
]).optional(),
|
|
1687
|
-
qualifiers: zod.array(zod.enum(MODERATION_QUALIFIERS)).max(64)
|
|
1689
|
+
qualifiers: zod$1.array(zod$1.enum(MODERATION_QUALIFIERS)).max(64)
|
|
1688
1690
|
}).strict().superRefine((instance, context) => {
|
|
1689
1691
|
if (new Set(instance.qualifiers).size !== instance.qualifiers.length || instance.qualifiers.some((q) => getModerationQualifierInfo(q).category !== instance.category || "fromInput" in getModerationQualifierInfo(q))) context.addIssue({
|
|
1690
1692
|
code: "custom",
|
|
@@ -1978,6 +1980,26 @@ async function detectTestImage(image, key, { whole = true } = {}) {
|
|
|
1978
1980
|
if (!scenario || !whole) return scenario;
|
|
1979
1981
|
return matchesTestImageGrid(image, grid, paintTestImageGrid(data.subarray(0, 18 + length), testImagePalette(scenario))) ? scenario : void 0;
|
|
1980
1982
|
}
|
|
1983
|
+
// src/client/CalmLensTestInputArguments.ts
|
|
1984
|
+
/**
|
|
1985
|
+
* Runs a test input generator with the caller's scenario and key, reporting an invalid one as an
|
|
1986
|
+
* `sdk/invalid-argument` CalmLensError (naming the offending scenario field) instead of the
|
|
1987
|
+
* contract's raw validation error.
|
|
1988
|
+
*/
|
|
1989
|
+
async function withValidTestInputArguments(key, generate) {
|
|
1990
|
+
if (!TEST_INPUT_KEY_PATTERN.test(key)) throw require_CalmLensError.invalidArgument("key must be a test input key: 32 lowercase hexadecimal characters");
|
|
1991
|
+
try {
|
|
1992
|
+
return await generate();
|
|
1993
|
+
} catch (error) {
|
|
1994
|
+
if (error instanceof zod.ZodError) {
|
|
1995
|
+
const [issue] = error.issues;
|
|
1996
|
+
const path = (issue?.path ?? []).map((segment) => typeof segment === "number" ? segment : String(segment));
|
|
1997
|
+
throw require_CalmLensError.invalidArgument(`Invalid test scenario at ${path.length ? path.join(".") : "scenario"}: ${issue?.message ?? error.message}`, { path });
|
|
1998
|
+
}
|
|
1999
|
+
if (error instanceof RangeError) throw require_CalmLensError.invalidArgument(error.message);
|
|
2000
|
+
throw error;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
1981
2003
|
Object.defineProperty(exports, "CLASSIFICATION_CATEGORIES", {
|
|
1982
2004
|
enumerable: true,
|
|
1983
2005
|
get: function() {
|
|
@@ -2074,3 +2096,9 @@ Object.defineProperty(exports, "testInputForSignal", {
|
|
|
2074
2096
|
return testInputForSignal;
|
|
2075
2097
|
}
|
|
2076
2098
|
});
|
|
2099
|
+
Object.defineProperty(exports, "withValidTestInputArguments", {
|
|
2100
|
+
enumerable: true,
|
|
2101
|
+
get: function() {
|
|
2102
|
+
return withValidTestInputArguments;
|
|
2103
|
+
}
|
|
2104
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const require_CalmLensError = require("./CalmLensError-DPHJaVjX.js");
|
|
2
|
+
const require_ModerationContextLimits = require("./ModerationContextLimits-1XP4ZTQk.js");
|
|
3
|
+
const require_UploadController = require("./UploadController-CyPTBuZg.js");
|
|
3
4
|
const require_FileIcons = require("./FileIcons-Ob003MdS.js");
|
|
4
5
|
// src/ui/viewers/ViewerAsset.ts
|
|
5
6
|
/** Spreadsheet MIME types, as `content.format` reports them (compared lower-cased). */
|
|
@@ -388,7 +389,7 @@ const getPlayedPercent = (media) => Number.isFinite(media.duration) && media.dur
|
|
|
388
389
|
const INSTANT_LOAD_MS = 50;
|
|
389
390
|
/** True when an image element is already decoded in the browser's memory cache. */
|
|
390
391
|
const isImageReady = (image) => Boolean(image?.complete && image.naturalWidth > 0);
|
|
391
|
-
const codeOf = (error) =>
|
|
392
|
+
const codeOf = (error) => require_CalmLensError.CalmLensError.isCalmLensError(error) ? error.code : void 0;
|
|
392
393
|
/**
|
|
393
394
|
* One `CalmLensAsset`'s connection to the CDN. Each render calls `update` with the options and
|
|
394
395
|
* renders `getAssetView` of what it returns; once mounted, `load` fetches `{src}/info` when `info`
|