calmlens 0.37.1 → 0.38.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.
Files changed (84) hide show
  1. package/bin/calmlens.js +9 -3
  2. package/cjs/{BrowserUpload-84KQWr1Q.js → BrowserUpload-BO_ZukUM.js} +1 -1
  3. package/{esm/BrowserUpload-CuG3tWSo.d.ts → cjs/BrowserUpload-BuTS7yTy.d.ts} +2 -2
  4. package/cjs/{CalmLensAppClient-D4tRb_P2.js → CalmLensAppClient-DoNMg8Dh.js} +3 -3
  5. package/{esm/CalmLensAppClient-QqtovWE-.d.ts → cjs/CalmLensAppClient-L5x_sMOI.d.ts} +1 -1
  6. package/cjs/{CalmLensCdn-CdYY_XtK.js → CalmLensCdn-B_Tbwq10.js} +2 -2
  7. package/cjs/{CalmLensConnection-GkR2cKn5.js → CalmLensConnection-Dhg1amnb.js} +2 -2
  8. package/cjs/{CalmLensError-ifj5rLmk.js → CalmLensError-C9g7GXfU.js} +7 -2
  9. package/{esm/CalmLensServerClient-csSQqHBt.d.ts → cjs/CalmLensServerClient-2H0ZpJlr.d.ts} +5 -5
  10. package/cjs/{CalmLensServerClient-cgPOG4Sv.js → CalmLensServerClient-D0wCcQNn.js} +15 -6
  11. package/cjs/{CalmLensTypes-_f7QVRtO.d.ts → CalmLensTypes-CCsoVr39.d.ts} +4 -4
  12. package/{esm/Core-4iFxKJnY.d.ts → cjs/Core-B110Ug8_.d.ts} +2 -2
  13. package/cjs/{Core-BlnBBJKb.js → Core-iNgZ8Cij.js} +3 -3
  14. package/cjs/{ReactUpload-D3AYIZBh.js → ReactUpload-BS8bYIhv.js} +1 -1
  15. package/cjs/{ReactUpload-4qd2xACg.d.ts → ReactUpload-CbtQtN6v.d.ts} +1 -1
  16. package/cjs/{UploadController-BYuHuZ7K.js → UploadController-CVKtUCK0.js} +2 -2
  17. package/{esm/WebhookPayload-BJtggTLd.d.ts → cjs/WebhookPayload-_fvY2eu8.d.ts} +5 -3
  18. package/cjs/app.d.ts +4 -4
  19. package/cjs/app.js +3 -3
  20. package/cjs/elements.d.ts +4 -4
  21. package/cjs/elements.js +4 -4
  22. package/cjs/{index-IEA75nev.d.ts → index-Dk3I5YXf.d.ts} +2 -2
  23. package/cjs/index.d.ts +3 -3
  24. package/cjs/index.js +2 -2
  25. package/cjs/react-native.d.ts +2 -2
  26. package/cjs/react-native.js +4 -4
  27. package/cjs/react.d.ts +4 -4
  28. package/cjs/react.js +5 -5
  29. package/cjs/server.d.ts +4 -4
  30. package/cjs/server.js +3 -3
  31. package/cjs/{CalmLensTestInputArguments-C6S09FVQ.js → test-inputs-BVJZjtFd.js} +156 -16
  32. package/{esm/TestTriggers-CjDhhz78.d.ts → cjs/test-inputs-JaZaV9Up.d.ts} +20 -1
  33. package/cjs/test-inputs.d.ts +2 -18
  34. package/cjs/test-inputs.js +15 -126
  35. package/cjs/testing.d.ts +11 -14
  36. package/cjs/testing.js +35 -66
  37. package/cjs/{ui-BMQW3Hse.d.ts → ui--E_s-cDd.d.ts} +2 -2
  38. package/cjs/{ui-Cy8MWXOw.js → ui-CuO37F4u.js} +2 -2
  39. package/cjs/ui.d.ts +2 -2
  40. package/cjs/ui.js +3 -3
  41. package/cjs/vue.d.ts +5 -5
  42. package/cjs/vue.js +4 -4
  43. package/{cjs/BrowserUpload-CuG3tWSo.d.ts → esm/BrowserUpload-BuTS7yTy.d.ts} +2 -2
  44. package/esm/{BrowserUpload-C429CcUi.js → BrowserUpload-DxgiUXC2.js} +1 -1
  45. package/esm/{CalmLensAppClient-Brvc-GXt.js → CalmLensAppClient-C7ScAfRx.js} +3 -3
  46. package/{cjs/CalmLensAppClient-QqtovWE-.d.ts → esm/CalmLensAppClient-L5x_sMOI.d.ts} +1 -1
  47. package/esm/{CalmLensCdn-cmxtF_dw.js → CalmLensCdn-CW5Fn3ph.js} +2 -2
  48. package/esm/{CalmLensConnection-DEfpIugc.js → CalmLensConnection-Blv8JyLF.js} +2 -2
  49. package/esm/{CalmLensError-C15tWu8W.js → CalmLensError-DjkibkdI.js} +7 -2
  50. package/{cjs/CalmLensServerClient-csSQqHBt.d.ts → esm/CalmLensServerClient-2H0ZpJlr.d.ts} +5 -5
  51. package/esm/{CalmLensServerClient-BpsCXVeO.js → CalmLensServerClient-C7n6EzVd.js} +15 -6
  52. package/esm/{CalmLensTypes-_f7QVRtO.d.ts → CalmLensTypes-CCsoVr39.d.ts} +4 -4
  53. package/{cjs/Core-4iFxKJnY.d.ts → esm/Core-B110Ug8_.d.ts} +2 -2
  54. package/esm/{Core-C_f1o9RQ.js → Core-BRrPxS4i.js} +3 -3
  55. package/esm/{ReactUpload-Ch5qY7PS.js → ReactUpload-BGPktblV.js} +1 -1
  56. package/esm/{ReactUpload-4qd2xACg.d.ts → ReactUpload-CbtQtN6v.d.ts} +1 -1
  57. package/esm/{UploadController-9fkYFVZM.js → UploadController-CQ4NouIU.js} +2 -2
  58. package/{cjs/WebhookPayload-BJtggTLd.d.ts → esm/WebhookPayload-_fvY2eu8.d.ts} +5 -3
  59. package/esm/app.d.ts +4 -4
  60. package/esm/app.js +3 -3
  61. package/esm/elements.d.ts +4 -4
  62. package/esm/elements.js +4 -4
  63. package/esm/{index-IEA75nev.d.ts → index-Dk3I5YXf.d.ts} +2 -2
  64. package/esm/index.d.ts +3 -3
  65. package/esm/index.js +2 -2
  66. package/esm/react-native.d.ts +2 -2
  67. package/esm/react-native.js +4 -4
  68. package/esm/react.d.ts +4 -4
  69. package/esm/react.js +5 -5
  70. package/esm/server.d.ts +4 -4
  71. package/esm/server.js +3 -3
  72. package/esm/{CalmLensTestInputArguments-DS_3mt1C.js → test-inputs-DizPp8_w.js} +145 -5
  73. package/{cjs/TestTriggers-CjDhhz78.d.ts → esm/test-inputs-JaZaV9Up.d.ts} +20 -1
  74. package/esm/test-inputs.d.ts +2 -18
  75. package/esm/test-inputs.js +1 -115
  76. package/esm/testing.d.ts +11 -14
  77. package/esm/testing.js +24 -55
  78. package/esm/{ui-BMQW3Hse.d.ts → ui--E_s-cDd.d.ts} +2 -2
  79. package/esm/{ui-HK74e42L.js → ui-B-QOHuVI.js} +2 -2
  80. package/esm/ui.d.ts +2 -2
  81. package/esm/ui.js +3 -3
  82. package/esm/vue.d.ts +5 -5
  83. package/esm/vue.js +4 -4
  84. package/package.json +1 -1
@@ -19,7 +19,7 @@ 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-ifj5rLmk.js");
22
+ const require_CalmLensError = require("./CalmLensError-C9g7GXfU.js");
23
23
  const require_CryptoUtils_BLCa_oZe = require("./CryptoUtils-BLCa-oZe-leCkr1ko.js");
24
24
  let zod = require("zod");
25
25
  let zod$1 = __toESM(zod, 1);
@@ -1872,7 +1872,7 @@ const toBase64Url = (bytes) => btoa(String.fromCharCode(...bytes)).replaceAll("+
1872
1872
  const fromBase64Url = (text) => Uint8Array.from(atob(text.replaceAll("-", "+").replaceAll("_", "/")), (char) => char.charCodeAt(0));
1873
1873
  /** The signed bytes: the scenario's canonical JSON (ASCII). */
1874
1874
  const envelope = (scenario) => new TextEncoder().encode(JSON.stringify(TEST_INPUT_SCHEMA.parse(scenario)));
1875
- async function generateTestTextCode(scenario, key) {
1875
+ async function generateTestTextCode$1(scenario, key) {
1876
1876
  if (!/^[a-f0-9]{32}$/.test(key)) throw new TypeError("Invalid test input key");
1877
1877
  const payload = toBase64Url(envelope(typeof scenario === "string" ? testInputForSignal(scenario) : scenario));
1878
1878
  if (payload.length > 8e3) throw new RangeError("Test scenario is too large");
@@ -1948,9 +1948,9 @@ const TEST_INPUT_CATEGORY_COLORS = {
1948
1948
  * bytes, big-endian), the 16-byte tag, then the payload (the scenario JSON). The reader rebuilds
1949
1949
  * the text code, so images and text share one verification.
1950
1950
  */
1951
- async function paintTestImage(scenario, key) {
1951
+ async function paintTestImage$1(scenario, key) {
1952
1952
  const input = TEST_INPUT_SCHEMA.parse(typeof scenario === "string" ? testInputForSignal(scenario, "image") : scenario);
1953
- const [, signature, payload] = (await generateTestTextCode(input, key)).slice(0, -1).split(" ");
1953
+ const [, signature, payload] = (await generateTestTextCode$1(input, key)).slice(0, -1).split(" ");
1954
1954
  const signed = fromBase64Url(payload);
1955
1955
  const data = new Uint8Array(18 + signed.length);
1956
1956
  data.set([signed.length >> 8, signed.length & 255]);
@@ -2000,6 +2000,146 @@ async function withValidTestInputArguments(key, generate) {
2000
2000
  throw error;
2001
2001
  }
2002
2002
  }
2003
+ // src/client/TestImagePng.ts
2004
+ /**
2005
+ * Encodes a painted test image as a PNG: 8-bit RGBA rows without filtering in stored deflate
2006
+ * blocks, as every SDK writes it, so the bytes match across SDKs. Runs anywhere, with no
2007
+ * compression library.
2008
+ */
2009
+ function encodeTestImagePng(width, height, rgba) {
2010
+ const stride = width * 4;
2011
+ const raw = new Uint8Array((stride + 1) * height);
2012
+ for (let row = 0; row < height; row++) raw.set(rgba.subarray(row * stride, (row + 1) * stride), row * (stride + 1) + 1);
2013
+ const blocks = Math.max(1, Math.ceil(raw.length / 65535));
2014
+ const stream = new Uint8Array(2 + raw.length + blocks * 5 + 4);
2015
+ stream.set([120, 1]);
2016
+ let position = 2;
2017
+ for (let offset = 0; offset < raw.length || position === 2; offset += 65535) {
2018
+ const block = raw.subarray(offset, offset + 65535);
2019
+ const length = block.length;
2020
+ stream.set([
2021
+ offset + length >= raw.length ? 1 : 0,
2022
+ length & 255,
2023
+ length >> 8,
2024
+ ~length & 255,
2025
+ ~length >> 8 & 255
2026
+ ], position);
2027
+ stream.set(block, position + 5);
2028
+ position += 5 + length;
2029
+ }
2030
+ writeUint32(stream, position, adler32(raw));
2031
+ const header = /* @__PURE__ */ new Uint8Array(13);
2032
+ writeUint32(header, 0, width);
2033
+ writeUint32(header, 4, height);
2034
+ header.set([
2035
+ 8,
2036
+ 6,
2037
+ 0,
2038
+ 0,
2039
+ 0
2040
+ ], 8);
2041
+ return concat([
2042
+ Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10),
2043
+ chunk("IHDR", header),
2044
+ chunk("IDAT", stream),
2045
+ chunk("IEND", /* @__PURE__ */ new Uint8Array(0))
2046
+ ]);
2047
+ }
2048
+ function chunk(kind, body) {
2049
+ const typed = new Uint8Array(4 + body.length);
2050
+ for (let i = 0; i < 4; i++) typed[i] = kind.charCodeAt(i);
2051
+ typed.set(body, 4);
2052
+ const out = new Uint8Array(12 + body.length);
2053
+ writeUint32(out, 0, body.length);
2054
+ out.set(typed, 4);
2055
+ writeUint32(out, 8 + body.length, crc32(typed));
2056
+ return out;
2057
+ }
2058
+ function writeUint32(target, offset, value) {
2059
+ target[offset] = value >>> 24;
2060
+ target[offset + 1] = value >>> 16 & 255;
2061
+ target[offset + 2] = value >>> 8 & 255;
2062
+ target[offset + 3] = value & 255;
2063
+ }
2064
+ function concat(parts) {
2065
+ const out = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
2066
+ let offset = 0;
2067
+ for (const part of parts) {
2068
+ out.set(part, offset);
2069
+ offset += part.length;
2070
+ }
2071
+ return out;
2072
+ }
2073
+ let crcTable;
2074
+ function crc32(bytes) {
2075
+ if (!crcTable) {
2076
+ crcTable = /* @__PURE__ */ new Uint32Array(256);
2077
+ for (let n = 0; n < 256; n++) {
2078
+ let c = n;
2079
+ for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
2080
+ crcTable[n] = c >>> 0;
2081
+ }
2082
+ }
2083
+ let crc = 4294967295;
2084
+ for (const byte of bytes) crc = crcTable[(crc ^ byte) & 255] ^ crc >>> 8;
2085
+ return (crc ^ 4294967295) >>> 0;
2086
+ }
2087
+ function adler32(bytes) {
2088
+ let a = 1;
2089
+ let b = 0;
2090
+ for (const byte of bytes) {
2091
+ a = (a + byte) % 65521;
2092
+ b = (b + a) % 65521;
2093
+ }
2094
+ return (b << 16 | a) >>> 0;
2095
+ }
2096
+ // src/contract/MediaTestTriggers.js
2097
+ const MEDIA_TEST_SIGNALS = [...CLASSIFICATION_CATEGORIES, "violence.graphic"];
2098
+ const HEX_WORDS = [
2099
+ "zero",
2100
+ "one",
2101
+ "two",
2102
+ "three",
2103
+ "four",
2104
+ "five",
2105
+ "six",
2106
+ "seven",
2107
+ "eight",
2108
+ "nine",
2109
+ "alpha",
2110
+ "bravo",
2111
+ "charlie",
2112
+ "delta",
2113
+ "echo",
2114
+ "foxtrot"
2115
+ ];
2116
+ /** Read this aloud, or render it as large, high-contrast text in a video frame. */
2117
+ async function generateMediaTestCode$1(signal, testInputKey) {
2118
+ if (!MEDIA_TEST_SIGNALS.includes(signal)) throw new RangeError("Unsupported media test signal");
2119
+ return `Calm Lens test ${[...await getTestInputTag("media", signal, testInputKey)].map((character) => HEX_WORDS[Number.parseInt(character, 16)]).join(" ")} ${signal.replace(/[.-]/g, " ")} end test`;
2120
+ }
2121
+ // src/test-inputs.ts
2122
+ /**
2123
+ * Portable test inputs: presets and custom instances share one authenticated format. CalmLens
2124
+ * recognises a code only as the whole text and a test image only as the whole
2125
+ * upload, signed with the project's own key.
2126
+ */
2127
+ /** A spoken media test phrase for `signal`, signed with the project's test input key. */
2128
+ const generateMediaTestCode = (signal, key) => withValidTestInputArguments(key, () => generateMediaTestCode$1(signal, key));
2129
+ /** A text code for `scenario`, signed with the project's test input key. */
2130
+ const generateTestTextCode = (scenario, key) => withValidTestInputArguments(key, () => generateTestTextCode$1(scenario, key));
2131
+ /**
2132
+ * The test image for `scenario`, signed with the project's test input key. Upload its `png` bytes
2133
+ * (or encode `rgba` in another format: the image survives lossy formats and resizing) as the whole
2134
+ * image, optionally on a plain single-colour border.
2135
+ */
2136
+ const paintTestImage = async (scenario, key) => {
2137
+ const image = await withValidTestInputArguments(key, () => paintTestImage$1(scenario, key));
2138
+ return {
2139
+ ...image,
2140
+ png: encodeTestImagePng(image.width, image.height, image.rgba)
2141
+ };
2142
+ };
2003
2143
  Object.defineProperty(exports, "CLASSIFICATION_CATEGORIES", {
2004
2144
  enumerable: true,
2005
2145
  get: function() {
@@ -2012,6 +2152,12 @@ Object.defineProperty(exports, "EU_COUNTRIES", {
2012
2152
  return EU_COUNTRIES;
2013
2153
  }
2014
2154
  });
2155
+ Object.defineProperty(exports, "MEDIA_TEST_SIGNALS", {
2156
+ enumerable: true,
2157
+ get: function() {
2158
+ return MEDIA_TEST_SIGNALS;
2159
+ }
2160
+ });
2015
2161
  Object.defineProperty(exports, "TEST_DETECTIONS_MAX", {
2016
2162
  enumerable: true,
2017
2163
  get: function() {
@@ -2066,22 +2212,22 @@ Object.defineProperty(exports, "detectTestTrigger", {
2066
2212
  return detectTestTrigger;
2067
2213
  }
2068
2214
  });
2069
- Object.defineProperty(exports, "generateTestTextCode", {
2215
+ Object.defineProperty(exports, "generateMediaTestCode", {
2070
2216
  enumerable: true,
2071
2217
  get: function() {
2072
- return generateTestTextCode;
2218
+ return generateMediaTestCode;
2073
2219
  }
2074
2220
  });
2075
- Object.defineProperty(exports, "getImageTestCategories", {
2221
+ Object.defineProperty(exports, "generateTestTextCode", {
2076
2222
  enumerable: true,
2077
2223
  get: function() {
2078
- return getImageTestCategories;
2224
+ return generateTestTextCode;
2079
2225
  }
2080
2226
  });
2081
- Object.defineProperty(exports, "getTestInputTag", {
2227
+ Object.defineProperty(exports, "getImageTestCategories", {
2082
2228
  enumerable: true,
2083
2229
  get: function() {
2084
- return getTestInputTag;
2230
+ return getImageTestCategories;
2085
2231
  }
2086
2232
  });
2087
2233
  Object.defineProperty(exports, "lazySchema", {
@@ -2102,9 +2248,3 @@ Object.defineProperty(exports, "testInputForSignal", {
2102
2248
  return testInputForSignal;
2103
2249
  }
2104
2250
  });
2105
- Object.defineProperty(exports, "withValidTestInputArguments", {
2106
- enumerable: true,
2107
- get: function() {
2108
- return withValidTestInputArguments;
2109
- }
2110
- });
@@ -402,4 +402,23 @@ declare function detectTestImage(image: RgbaImage, key: string,
402
402
  }[] | undefined;
403
403
  } | undefined;
404
404
  } | undefined>;
405
- export { TEST_FACE_AGE_PRESETS as a, TestDetections as c, detectTestTrigger as d, getImageTestCategories as f, TEST_FACE_AGE_MAX as i, TestInput as l, TEST_DETECTIONS_MAX as n, TEST_INPUT_KEY_PATTERN as o, testInputForSignal as p, TEST_DETECTION_BOX_MAX as r, TEST_INPUT_PRESETS as s, ClassificationTestSignal as t, detectTestImage as u };
405
+ declare const MEDIA_TEST_SIGNALS: readonly ["sexual", "violence", "self-harm", "harassment", "hate", "criminal-activity", "personal-information", "profanity", "violence.graphic"];
406
+ /** A spoken media test phrase for `signal`, signed with the project's test input key. */
407
+ declare const generateMediaTestCode: (signal: ClassificationTestSignal, key: string) => Promise<string>;
408
+ /** A text code for `scenario`, signed with the project's test input key. */
409
+ declare const generateTestTextCode: (scenario: TestInput | ClassificationTestSignal, key: string) => Promise<string>;
410
+ /** A painted test image: its RGBA pixels, row by row, and the same image as PNG bytes. */
411
+ interface TestImage {
412
+ width: number;
413
+ height: number;
414
+ rgba: Uint8Array;
415
+ /** The image as a PNG, to upload as it is. */
416
+ png: Uint8Array;
417
+ }
418
+ /**
419
+ * The test image for `scenario`, signed with the project's test input key. Upload its `png` bytes
420
+ * (or encode `rgba` in another format: the image survives lossy formats and resizing) as the whole
421
+ * image, optionally on a plain single-colour border.
422
+ */
423
+ declare const paintTestImage: (scenario: TestInput | ClassificationTestSignal, key: string) => Promise<TestImage>;
424
+ export { getImageTestCategories as _, MEDIA_TEST_SIGNALS as a, TEST_DETECTION_BOX_MAX as c, TEST_INPUT_KEY_PATTERN as d, TEST_INPUT_PRESETS as f, detectTestTrigger as g, detectTestImage as h, paintTestImage as i, TEST_FACE_AGE_MAX as l, TestInput as m, generateMediaTestCode as n, ClassificationTestSignal as o, TestDetections as p, generateTestTextCode as r, TEST_DETECTIONS_MAX as s, TestImage as t, TEST_FACE_AGE_PRESETS as u, testInputForSignal as v };
@@ -1,18 +1,2 @@
1
- import { a as TEST_FACE_AGE_PRESETS, c as TestDetections, d as detectTestTrigger, f as getImageTestCategories, i as TEST_FACE_AGE_MAX, l as TestInput, n as TEST_DETECTIONS_MAX, o as TEST_INPUT_KEY_PATTERN, p as testInputForSignal, r as TEST_DETECTION_BOX_MAX, s as TEST_INPUT_PRESETS, t as ClassificationTestSignal, u as detectTestImage } from "./TestTriggers-CjDhhz78.js";
2
- /** A text code for `scenario`, signed with the project's test input key. */
3
- export declare const generateTestTextCode: (scenario: TestInput | ClassificationTestSignal, key: string) => Promise<string>;
4
- /** A painted test image: its RGBA pixels, row by row, and the same image as PNG bytes. */
5
- export interface TestImage {
6
- width: number;
7
- height: number;
8
- rgba: Uint8Array;
9
- /** The image as a PNG, to upload as it is. */
10
- png: Uint8Array;
11
- }
12
- /**
13
- * The test image for `scenario`, signed with the project's test input key. Upload its `png` bytes
14
- * (or encode `rgba` in another format: the image survives lossy formats and resizing) as the whole
15
- * image, optionally on a plain single-colour border.
16
- */
17
- export declare const paintTestImage: (scenario: TestInput | ClassificationTestSignal, key: string) => Promise<TestImage>;
18
- export { type ClassificationTestSignal, TEST_DETECTIONS_MAX, TEST_DETECTION_BOX_MAX, TEST_FACE_AGE_MAX, TEST_FACE_AGE_PRESETS, TEST_INPUT_KEY_PATTERN, TEST_INPUT_PRESETS, type TestDetections, type TestInput, detectTestImage, detectTestTrigger, getImageTestCategories, testInputForSignal };
1
+ import { _ as getImageTestCategories, a as MEDIA_TEST_SIGNALS, c as TEST_DETECTION_BOX_MAX, d as TEST_INPUT_KEY_PATTERN, f as TEST_INPUT_PRESETS, g as detectTestTrigger, h as detectTestImage, i as paintTestImage, l as TEST_FACE_AGE_MAX, m as TestInput, n as generateMediaTestCode, o as ClassificationTestSignal, p as TestDetections, r as generateTestTextCode, s as TEST_DETECTIONS_MAX, t as TestImage, u as TEST_FACE_AGE_PRESETS, v as testInputForSignal } from "./test-inputs-JaZaV9Up.js";
2
+ export { type ClassificationTestSignal, MEDIA_TEST_SIGNALS, TEST_DETECTIONS_MAX, TEST_DETECTION_BOX_MAX, TEST_FACE_AGE_MAX, TEST_FACE_AGE_PRESETS, TEST_INPUT_KEY_PATTERN, TEST_INPUT_PRESETS, type TestDetections, TestImage, type TestInput, detectTestImage, detectTestTrigger, generateMediaTestCode, generateTestTextCode, getImageTestCategories, paintTestImage, testInputForSignal };
@@ -1,127 +1,16 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_CalmLensTestInputArguments = require("./CalmLensTestInputArguments-C6S09FVQ.js");
3
- // src/client/TestImagePng.ts
4
- /**
5
- * Encodes a painted test image as a PNG: 8-bit RGBA rows without filtering in stored deflate
6
- * blocks, as every SDK writes it, so the bytes match across SDKs. Runs anywhere, with no
7
- * compression library.
8
- */
9
- function encodeTestImagePng(width, height, rgba) {
10
- const stride = width * 4;
11
- const raw = new Uint8Array((stride + 1) * height);
12
- for (let row = 0; row < height; row++) raw.set(rgba.subarray(row * stride, (row + 1) * stride), row * (stride + 1) + 1);
13
- const blocks = Math.max(1, Math.ceil(raw.length / 65535));
14
- const stream = new Uint8Array(2 + raw.length + blocks * 5 + 4);
15
- stream.set([120, 1]);
16
- let position = 2;
17
- for (let offset = 0; offset < raw.length || position === 2; offset += 65535) {
18
- const block = raw.subarray(offset, offset + 65535);
19
- const length = block.length;
20
- stream.set([
21
- offset + length >= raw.length ? 1 : 0,
22
- length & 255,
23
- length >> 8,
24
- ~length & 255,
25
- ~length >> 8 & 255
26
- ], position);
27
- stream.set(block, position + 5);
28
- position += 5 + length;
29
- }
30
- writeUint32(stream, position, adler32(raw));
31
- const header = /* @__PURE__ */ new Uint8Array(13);
32
- writeUint32(header, 0, width);
33
- writeUint32(header, 4, height);
34
- header.set([
35
- 8,
36
- 6,
37
- 0,
38
- 0,
39
- 0
40
- ], 8);
41
- return concat([
42
- Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10),
43
- chunk("IHDR", header),
44
- chunk("IDAT", stream),
45
- chunk("IEND", /* @__PURE__ */ new Uint8Array(0))
46
- ]);
47
- }
48
- function chunk(kind, body) {
49
- const typed = new Uint8Array(4 + body.length);
50
- for (let i = 0; i < 4; i++) typed[i] = kind.charCodeAt(i);
51
- typed.set(body, 4);
52
- const out = new Uint8Array(12 + body.length);
53
- writeUint32(out, 0, body.length);
54
- out.set(typed, 4);
55
- writeUint32(out, 8 + body.length, crc32(typed));
56
- return out;
57
- }
58
- function writeUint32(target, offset, value) {
59
- target[offset] = value >>> 24;
60
- target[offset + 1] = value >>> 16 & 255;
61
- target[offset + 2] = value >>> 8 & 255;
62
- target[offset + 3] = value & 255;
63
- }
64
- function concat(parts) {
65
- const out = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
66
- let offset = 0;
67
- for (const part of parts) {
68
- out.set(part, offset);
69
- offset += part.length;
70
- }
71
- return out;
72
- }
73
- let crcTable;
74
- function crc32(bytes) {
75
- if (!crcTable) {
76
- crcTable = /* @__PURE__ */ new Uint32Array(256);
77
- for (let n = 0; n < 256; n++) {
78
- let c = n;
79
- for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
80
- crcTable[n] = c >>> 0;
81
- }
82
- }
83
- let crc = 4294967295;
84
- for (const byte of bytes) crc = crcTable[(crc ^ byte) & 255] ^ crc >>> 8;
85
- return (crc ^ 4294967295) >>> 0;
86
- }
87
- function adler32(bytes) {
88
- let a = 1;
89
- let b = 0;
90
- for (const byte of bytes) {
91
- a = (a + byte) % 65521;
92
- b = (b + a) % 65521;
93
- }
94
- return (b << 16 | a) >>> 0;
95
- }
96
- // src/test-inputs.ts
97
- /**
98
- * Portable test inputs: presets and custom instances share one authenticated format. CalmLens
99
- * recognises a code only as the whole text and a test image only as the whole
100
- * upload, signed with the project's own key.
101
- */
102
- /** A text code for `scenario`, signed with the project's test input key. */
103
- const generateTestTextCode = (scenario, key) => require_CalmLensTestInputArguments.withValidTestInputArguments(key, () => require_CalmLensTestInputArguments.generateTestTextCode(scenario, key));
104
- /**
105
- * The test image for `scenario`, signed with the project's test input key. Upload its `png` bytes
106
- * (or encode `rgba` in another format: the image survives lossy formats and resizing) as the whole
107
- * image, optionally on a plain single-colour border.
108
- */
109
- const paintTestImage = async (scenario, key) => {
110
- const image = await require_CalmLensTestInputArguments.withValidTestInputArguments(key, () => require_CalmLensTestInputArguments.paintTestImage(scenario, key));
111
- return {
112
- ...image,
113
- png: encodeTestImagePng(image.width, image.height, image.rgba)
114
- };
115
- };
116
- exports.TEST_DETECTIONS_MAX = require_CalmLensTestInputArguments.TEST_DETECTIONS_MAX;
117
- exports.TEST_DETECTION_BOX_MAX = require_CalmLensTestInputArguments.TEST_DETECTION_BOX_MAX;
118
- exports.TEST_FACE_AGE_MAX = require_CalmLensTestInputArguments.TEST_FACE_AGE_MAX;
119
- exports.TEST_FACE_AGE_PRESETS = require_CalmLensTestInputArguments.TEST_FACE_AGE_PRESETS;
120
- exports.TEST_INPUT_KEY_PATTERN = require_CalmLensTestInputArguments.TEST_INPUT_KEY_PATTERN;
121
- exports.TEST_INPUT_PRESETS = require_CalmLensTestInputArguments.TEST_INPUT_PRESETS;
122
- exports.detectTestImage = require_CalmLensTestInputArguments.detectTestImage;
123
- exports.detectTestTrigger = require_CalmLensTestInputArguments.detectTestTrigger;
124
- exports.generateTestTextCode = generateTestTextCode;
125
- exports.getImageTestCategories = require_CalmLensTestInputArguments.getImageTestCategories;
126
- exports.paintTestImage = paintTestImage;
127
- exports.testInputForSignal = require_CalmLensTestInputArguments.testInputForSignal;
2
+ const require_test_inputs = require("./test-inputs-BVJZjtFd.js");
3
+ exports.MEDIA_TEST_SIGNALS = require_test_inputs.MEDIA_TEST_SIGNALS;
4
+ exports.TEST_DETECTIONS_MAX = require_test_inputs.TEST_DETECTIONS_MAX;
5
+ exports.TEST_DETECTION_BOX_MAX = require_test_inputs.TEST_DETECTION_BOX_MAX;
6
+ exports.TEST_FACE_AGE_MAX = require_test_inputs.TEST_FACE_AGE_MAX;
7
+ exports.TEST_FACE_AGE_PRESETS = require_test_inputs.TEST_FACE_AGE_PRESETS;
8
+ exports.TEST_INPUT_KEY_PATTERN = require_test_inputs.TEST_INPUT_KEY_PATTERN;
9
+ exports.TEST_INPUT_PRESETS = require_test_inputs.TEST_INPUT_PRESETS;
10
+ exports.detectTestImage = require_test_inputs.detectTestImage;
11
+ exports.detectTestTrigger = require_test_inputs.detectTestTrigger;
12
+ exports.generateMediaTestCode = require_test_inputs.generateMediaTestCode;
13
+ exports.generateTestTextCode = require_test_inputs.generateTestTextCode;
14
+ exports.getImageTestCategories = require_test_inputs.getImageTestCategories;
15
+ exports.paintTestImage = require_test_inputs.paintTestImage;
16
+ exports.testInputForSignal = require_test_inputs.testInputForSignal;
package/cjs/testing.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Jt as SignedUploadToken, Kt as SignUploadTokenOptions, Ln as PermissionGrant, Nn as TypedEvent, O as CalmLensAppClientOptions, Rn as Folder, Vn as AssetBinaryPayloadInput, k as CalmLensServerClientOptions, m as AssetModeration, on as UploadPresetDefinition, r as Asset } from "./CalmLensTypes-_f7QVRtO.js";
2
- import { t as CalmLensAppClient } from "./CalmLensAppClient-QqtovWE-.js";
3
- import { I as ApiErrorCode, n as WebhookEventPayload } from "./WebhookPayload-BJtggTLd.js";
4
- import { t as CalmLensServerClient } from "./CalmLensServerClient-csSQqHBt.js";
5
- import { t as ClassificationTestSignal } from "./TestTriggers-CjDhhz78.js";
1
+ import { Jt as SignedUploadToken, Kt as SignUploadTokenOptions, Ln as PermissionGrant, Nn as TypedEvent, O as CalmLensAppClientOptions, Rn as Folder, Vn as AssetBinaryPayloadInput, k as CalmLensServerClientOptions, m as AssetModeration, on as UploadPresetDefinition, r as Asset } from "./CalmLensTypes-CCsoVr39.js";
2
+ import { t as CalmLensAppClient } from "./CalmLensAppClient-L5x_sMOI.js";
3
+ import { I as ApiErrorCode, n as WebhookEventPayload } from "./WebhookPayload-_fvY2eu8.js";
4
+ import { t as CalmLensServerClient } from "./CalmLensServerClient-2H0ZpJlr.js";
5
+ import { a as MEDIA_TEST_SIGNALS, n as generateMediaTestCode } from "./test-inputs-JaZaV9Up.js";
6
6
  import "zod";
7
7
  /**
8
8
  * Signs a single-use upload token with `apiKey`, locally. `CalmLensServerClient` and
@@ -14,7 +14,6 @@ declare const signUploadTokenWithApiKey: (apiKey: string, options: SignUploadTok
14
14
  now?: number;
15
15
  nonce?: string;
16
16
  }) => Promise<SignedUploadToken>;
17
- export declare const MEDIA_TEST_SIGNALS: readonly ["sexual", "violence", "self-harm", "harassment", "hate", "criminal-activity", "personal-information", "profanity", "violence.graphic"];
18
17
  export declare const MOCK_API_KEY_PREFIX = "sk_test_";
19
18
  /**
20
19
  * Creates a mock API key holding `grants`. Throws `sdk/invalid-argument`, naming the grant, for
@@ -234,11 +233,11 @@ interface MockDatabaseStorage {
234
233
  getAsset(assetId: string): Promise<Asset | undefined>;
235
234
  listAssets(projectId: string): Promise<Asset[]>;
236
235
  deleteAsset(assetId: string): Promise<void>;
237
- createFolder?(folder: Folder): Promise<Folder>;
238
- updateFolder?(folder: Folder): Promise<Folder>;
239
- getFolder?(folderId: string): Promise<Folder | undefined>;
240
- listFolders?(projectId: string): Promise<Folder[]>;
241
- deleteFolder?(folderId: string): Promise<void>;
236
+ createFolder(folder: Folder): Promise<Folder>;
237
+ updateFolder(folder: Folder): Promise<Folder>;
238
+ getFolder(folderId: string): Promise<Folder | undefined>;
239
+ listFolders(projectId: string): Promise<Folder[]>;
240
+ deleteFolder(folderId: string): Promise<void>;
242
241
  }
243
242
  export declare class InMemoryMockDatabaseStorage implements MockDatabaseStorage {
244
243
  private readonly assets;
@@ -505,6 +504,4 @@ export declare const createWebhookHeaders: (options: {
505
504
  deliveryId: string;
506
505
  timestampSeconds?: number;
507
506
  }) => Promise<Record<string, string>>;
508
- /** A spoken media test phrase for `signal`, signed with the project's test input key. */
509
- export declare const generateMediaTestCode: (signal: ClassificationTestSignal, key: string) => Promise<string>;
510
- export { type MockAssetOutcome, type MockCalmLensAppClientOptions, type MockCalmLensCall, type MockCalmLensOperation, type MockCalmLensServerClientOptions, type MockDatabaseStorage, type MockDetectedFace, type MockDetectedLink, type MockDetectedPerson, type MockEventInput, type MockFailureOptions, type MockImageStorage, type MockModerate, type MockModerationInput, type MockModerationTrigger, type MockQrCode, type MockRegionalDecision, type MockRequestFailure, type MockReviewDecision, type MockServedUrl, type MockStoredContent, type MockTextRegion, type MockUploadPreset, signUploadTokenWithApiKey as signUploadToken };
507
+ export { MEDIA_TEST_SIGNALS, type MockAssetOutcome, type MockCalmLensAppClientOptions, type MockCalmLensCall, type MockCalmLensOperation, type MockCalmLensServerClientOptions, type MockDatabaseStorage, type MockDetectedFace, type MockDetectedLink, type MockDetectedPerson, type MockEventInput, type MockFailureOptions, type MockImageStorage, type MockModerate, type MockModerationInput, type MockModerationTrigger, type MockQrCode, type MockRegionalDecision, type MockRequestFailure, type MockReviewDecision, type MockServedUrl, type MockStoredContent, type MockTextRegion, type MockUploadPreset, generateMediaTestCode, signUploadTokenWithApiKey as signUploadToken };