@adcp/sdk 17.0.0-beta.31 → 17.0.0-beta.32

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 (36) hide show
  1. package/dist/lib/identity-3.3/trust.js +10 -4
  2. package/dist/lib/identity-3.3/trust.mjs +10 -4
  3. package/dist/lib/server/create-adcp-server.js +7 -8
  4. package/dist/lib/server/create-adcp-server.mjs +9 -10
  5. package/dist/lib/server/error-arm-tools.d.mts +23 -14
  6. package/dist/lib/server/error-arm-tools.d.ts +23 -14
  7. package/dist/lib/server/error-arm-tools.js +82 -34
  8. package/dist/lib/server/error-arm-tools.mjs +81 -34
  9. package/dist/lib/testing/storyboard/compliance.js +53 -24
  10. package/dist/lib/testing/storyboard/compliance.mjs +53 -24
  11. package/dist/lib/testing/storyboard/loader.js +2 -2
  12. package/dist/lib/testing/storyboard/loader.mjs +2 -2
  13. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  14. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  15. package/dist/lib/testing/storyboard/yaml-cache.d.mts +21 -0
  16. package/dist/lib/testing/storyboard/yaml-cache.d.ts +21 -0
  17. package/dist/lib/testing/storyboard/yaml-cache.js +168 -0
  18. package/dist/lib/testing/storyboard/yaml-cache.mjs +139 -0
  19. package/dist/lib/validation/schema-diagnostic-origins.js +55 -25
  20. package/dist/lib/validation/schema-diagnostic-origins.mjs +55 -25
  21. package/dist/lib/validation/schema-loader.js +499 -44
  22. package/dist/lib/validation/schema-loader.mjs +499 -46
  23. package/dist/lib/validation/schema-validator.js +4 -6
  24. package/dist/lib/validation/schema-validator.mjs +6 -7
  25. package/dist/lib/validation/validator-cache.d.mts +45 -0
  26. package/dist/lib/validation/validator-cache.d.ts +45 -0
  27. package/dist/lib/validation/validator-cache.js +249 -0
  28. package/dist/lib/validation/validator-cache.mjs +227 -0
  29. package/dist/lib/version.d.mts +3 -3
  30. package/dist/lib/version.d.ts +3 -3
  31. package/dist/lib/version.js +3 -3
  32. package/dist/lib/version.mjs +3 -3
  33. package/docs/TYPE-SUMMARY.md +2 -2
  34. package/docs/llms.txt +2 -2
  35. package/docs/migration-14.x-rc-worksheet.md +4 -4
  36. package/package.json +1 -1
@@ -377,12 +377,11 @@ function validateRequest(toolName, payload, version) {
377
377
  const validator = (0, import_schema_loader.getValidator)(toolName, "request", version);
378
378
  if (!validator) return OK;
379
379
  const valid = validator(payload);
380
- const rootSchema = validator.schema;
381
- const rootSchemaId = rootSchema && typeof rootSchema === "object" && typeof rootSchema.$id === "string" ? rootSchema.$id : void 0;
380
+ const rootSchemaId = (0, import_schema_loader.getValidatorRootSchemaId)(validator);
382
381
  if (valid) return { valid: true, issues: [], variant: "request", ...rootSchemaId && { schemaId: rootSchemaId } };
383
382
  const registeredIds = (0, import_schema_loader.getRegisteredSchemaIds)(version);
384
383
  const ctx = {
385
- rootSchema,
384
+ rootSchema: validator.schema,
386
385
  rootSchemaId,
387
386
  registeredIds,
388
387
  toolName,
@@ -410,13 +409,12 @@ function validateResponse(toolName, payload, version) {
410
409
  const validator = (0, import_schema_loader.getValidator)(toolName, variant, version);
411
410
  const effective = validator ?? (variant !== "sync" ? (0, import_schema_loader.getValidator)(toolName, "sync", version) : void 0);
412
411
  if (!effective) return OK;
413
- const rootSchema = effective.schema;
414
412
  const normalizedPayload = compatPayload;
415
413
  const valid = effective(normalizedPayload);
416
414
  const usedVariant = validator ? variant : "sync";
417
415
  const variantFallback = !validator && variant !== "sync";
418
416
  const fallbackFields = variantFallback ? { variant_fallback_applied: true, requested_variant: variant } : {};
419
- const rootSchemaId = rootSchema && typeof rootSchema === "object" && typeof rootSchema.$id === "string" ? rootSchema.$id : void 0;
417
+ const rootSchemaId = (0, import_schema_loader.getValidatorRootSchemaId)(effective);
420
418
  if (valid) {
421
419
  return {
422
420
  valid: true,
@@ -428,7 +426,7 @@ function validateResponse(toolName, payload, version) {
428
426
  }
429
427
  const registeredIds = (0, import_schema_loader.getRegisteredSchemaIds)(version);
430
428
  const ctx = {
431
- rootSchema,
429
+ rootSchema: effective.schema,
432
430
  rootSchemaId,
433
431
  registeredIds,
434
432
  toolName,
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  getValidator,
3
3
  getValidatorDiagnosticOrigin,
4
- getRegisteredSchemaIds
4
+ getRegisteredSchemaIds,
5
+ getValidatorRootSchemaId
5
6
  } from "./schema-loader.mjs";
6
7
  import { findHint } from "./hints.mjs";
7
8
  import { injectLegacyEnvelopeStatus } from "../utils/envelope-status-compat.mjs";
@@ -353,12 +354,11 @@ function validateRequest(toolName, payload, version) {
353
354
  const validator = getValidator(toolName, "request", version);
354
355
  if (!validator) return OK;
355
356
  const valid = validator(payload);
356
- const rootSchema = validator.schema;
357
- const rootSchemaId = rootSchema && typeof rootSchema === "object" && typeof rootSchema.$id === "string" ? rootSchema.$id : void 0;
357
+ const rootSchemaId = getValidatorRootSchemaId(validator);
358
358
  if (valid) return { valid: true, issues: [], variant: "request", ...rootSchemaId && { schemaId: rootSchemaId } };
359
359
  const registeredIds = getRegisteredSchemaIds(version);
360
360
  const ctx = {
361
- rootSchema,
361
+ rootSchema: validator.schema,
362
362
  rootSchemaId,
363
363
  registeredIds,
364
364
  toolName,
@@ -386,13 +386,12 @@ function validateResponse(toolName, payload, version) {
386
386
  const validator = getValidator(toolName, variant, version);
387
387
  const effective = validator ?? (variant !== "sync" ? getValidator(toolName, "sync", version) : void 0);
388
388
  if (!effective) return OK;
389
- const rootSchema = effective.schema;
390
389
  const normalizedPayload = compatPayload;
391
390
  const valid = effective(normalizedPayload);
392
391
  const usedVariant = validator ? variant : "sync";
393
392
  const variantFallback = !validator && variant !== "sync";
394
393
  const fallbackFields = variantFallback ? { variant_fallback_applied: true, requested_variant: variant } : {};
395
- const rootSchemaId = rootSchema && typeof rootSchema === "object" && typeof rootSchema.$id === "string" ? rootSchema.$id : void 0;
394
+ const rootSchemaId = getValidatorRootSchemaId(effective);
396
395
  if (valid) {
397
396
  return {
398
397
  valid: true,
@@ -404,7 +403,7 @@ function validateResponse(toolName, payload, version) {
404
403
  }
405
404
  const registeredIds = getRegisteredSchemaIds(version);
406
405
  const ctx = {
407
- rootSchema,
406
+ rootSchema: effective.schema,
408
407
  rootSchemaId,
409
408
  registeredIds,
410
409
  toolName,
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Opt-in on-disk cache of compiled bundled-schema validators.
3
+ *
4
+ * Enabled only when `ADCP_VALIDATOR_CACHE_DIR` names an absolute directory.
5
+ * schema-loader requires this module only in that case, so with the variable
6
+ * unset the SDK touches no cache files and loads no cache code.
7
+ *
8
+ * An entry is Ajv's standalone module for one compiled validator, stored under
9
+ * a key that digests every input of the compile (see schema-loader). Entries
10
+ * are executable code, so the directory and every entry must belong to the
11
+ * current user and be closed to group and other users, entries are written
12
+ * atomically, and each body is checked against the SHA-256 in its header
13
+ * before it is evaluated. Any doubt (wrong owner or mode, symlink, digest
14
+ * mismatch, truncation, evaluation error) means the caller compiles live.
15
+ *
16
+ * The same directory also holds JSON data entries under the same rules
17
+ * (schema-root document identities, see schema-loader's persistRootCheck).
18
+ */
19
+ export interface CachedValidatorEntry {
20
+ /** The validator function, as Ajv's standalone module exports it. */
21
+ validate: ((data: unknown) => boolean) & {
22
+ errors?: unknown;
23
+ };
24
+ /** The raw root `$id` of the schema the validator was compiled from, when it was a string. */
25
+ rootSchemaId: string | undefined;
26
+ }
27
+ export interface ValidatorCache {
28
+ read(key: string): CachedValidatorEntry | undefined;
29
+ write(key: string, moduleCode: string, rootSchemaId: string | undefined): void;
30
+ /** The JSON value stored under `key` by {@link ValidatorCache.writeData}, or `undefined`. */
31
+ readData(key: string): unknown;
32
+ /** Store a JSON value under `key`, with the same integrity and ownership rules as validators. */
33
+ writeData(key: string, value: unknown): void;
34
+ }
35
+ /**
36
+ * Open the cache at `dir`, or return `undefined` when it cannot be used
37
+ * safely. `requireFrom` anchors module resolution for the generated code
38
+ * (`ajv/dist/runtime/*`, `ajv-formats/dist/formats`), so cached code resolves
39
+ * the same packages as the loader that compiled it.
40
+ */
41
+ export declare function openValidatorCache(dir: string, requireFrom: string): ValidatorCache | undefined;
42
+ /** SHA-256 of the given files' bytes (missing files contribute their name only). */
43
+ export declare function filesDigest(files: readonly string[]): string;
44
+ /** Cache key over a JSON-serializable list of compile inputs. */
45
+ export declare function validatorCacheKey(parts: readonly unknown[]): string;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Opt-in on-disk cache of compiled bundled-schema validators.
3
+ *
4
+ * Enabled only when `ADCP_VALIDATOR_CACHE_DIR` names an absolute directory.
5
+ * schema-loader requires this module only in that case, so with the variable
6
+ * unset the SDK touches no cache files and loads no cache code.
7
+ *
8
+ * An entry is Ajv's standalone module for one compiled validator, stored under
9
+ * a key that digests every input of the compile (see schema-loader). Entries
10
+ * are executable code, so the directory and every entry must belong to the
11
+ * current user and be closed to group and other users, entries are written
12
+ * atomically, and each body is checked against the SHA-256 in its header
13
+ * before it is evaluated. Any doubt (wrong owner or mode, symlink, digest
14
+ * mismatch, truncation, evaluation error) means the caller compiles live.
15
+ *
16
+ * The same directory also holds JSON data entries under the same rules
17
+ * (schema-root document identities, see schema-loader's persistRootCheck).
18
+ */
19
+ export interface CachedValidatorEntry {
20
+ /** The validator function, as Ajv's standalone module exports it. */
21
+ validate: ((data: unknown) => boolean) & {
22
+ errors?: unknown;
23
+ };
24
+ /** The raw root `$id` of the schema the validator was compiled from, when it was a string. */
25
+ rootSchemaId: string | undefined;
26
+ }
27
+ export interface ValidatorCache {
28
+ read(key: string): CachedValidatorEntry | undefined;
29
+ write(key: string, moduleCode: string, rootSchemaId: string | undefined): void;
30
+ /** The JSON value stored under `key` by {@link ValidatorCache.writeData}, or `undefined`. */
31
+ readData(key: string): unknown;
32
+ /** Store a JSON value under `key`, with the same integrity and ownership rules as validators. */
33
+ writeData(key: string, value: unknown): void;
34
+ }
35
+ /**
36
+ * Open the cache at `dir`, or return `undefined` when it cannot be used
37
+ * safely. `requireFrom` anchors module resolution for the generated code
38
+ * (`ajv/dist/runtime/*`, `ajv-formats/dist/formats`), so cached code resolves
39
+ * the same packages as the loader that compiled it.
40
+ */
41
+ export declare function openValidatorCache(dir: string, requireFrom: string): ValidatorCache | undefined;
42
+ /** SHA-256 of the given files' bytes (missing files contribute their name only). */
43
+ export declare function filesDigest(files: readonly string[]): string;
44
+ /** Cache key over a JSON-serializable list of compile inputs. */
45
+ export declare function validatorCacheKey(parts: readonly unknown[]): string;
@@ -0,0 +1,249 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var validator_cache_exports = {};
30
+ __export(validator_cache_exports, {
31
+ filesDigest: () => filesDigest,
32
+ openValidatorCache: () => openValidatorCache,
33
+ validatorCacheKey: () => validatorCacheKey
34
+ });
35
+ module.exports = __toCommonJS(validator_cache_exports);
36
+ var import_node_crypto = require("node:crypto");
37
+ var import_node_fs = require("node:fs");
38
+ var import_node_module = require("node:module");
39
+ var import_node_path = __toESM(require("node:path"));
40
+ var import_node_vm = require("node:vm");
41
+ const FORMAT = 1;
42
+ const HEADER_PREFIX = "// adcp-validator-cache ";
43
+ const ENTRY_SUFFIX = ".js";
44
+ const DATA_SUFFIX = ".json";
45
+ const TMP_SUFFIX = ".tmp";
46
+ const ORPHAN_TMP_AGE_MS = 10 * 60 * 1e3;
47
+ const DEFAULT_MAX_BYTES = 512 * 1024 * 1024;
48
+ function sha256(value) {
49
+ return (0, import_node_crypto.createHash)("sha256").update(value).digest("hex");
50
+ }
51
+ function isPrivateDirectory(dir, uid, requireOwnerOnly) {
52
+ try {
53
+ const stat = (0, import_node_fs.lstatSync)(dir);
54
+ if (!stat.isDirectory() || stat.isSymbolicLink()) return false;
55
+ if (stat.uid !== uid) return false;
56
+ return requireOwnerOnly ? (stat.mode & 63) === 0 : (stat.mode & 18) === 0;
57
+ } catch {
58
+ return false;
59
+ }
60
+ }
61
+ function maxBytes() {
62
+ const raw = process.env.ADCP_VALIDATOR_CACHE_MAX_MB;
63
+ if (raw === void 0 || raw === "") return DEFAULT_MAX_BYTES;
64
+ const value = Number(raw);
65
+ return Number.isFinite(value) && value > 0 ? Math.floor(value * 1024 * 1024) : DEFAULT_MAX_BYTES;
66
+ }
67
+ function openValidatorCache(dir, requireFrom) {
68
+ if (!import_node_path.default.isAbsolute(dir) || typeof process.getuid !== "function") return void 0;
69
+ const uid = process.getuid();
70
+ const entries = import_node_path.default.join(dir, `v${FORMAT}`);
71
+ try {
72
+ (0, import_node_fs.mkdirSync)(dir, { recursive: true, mode: 448 });
73
+ } catch {
74
+ return void 0;
75
+ }
76
+ if (!isPrivateDirectory(dir, uid, false)) return void 0;
77
+ try {
78
+ (0, import_node_fs.mkdirSync)(entries, { mode: 448 });
79
+ } catch (error) {
80
+ if (error.code !== "EEXIST") return void 0;
81
+ }
82
+ if (!isPrivateDirectory(entries, uid, true)) return void 0;
83
+ const moduleRequire = (0, import_node_module.createRequire)(requireFrom);
84
+ const limit = maxBytes();
85
+ const entryPath = (key) => import_node_path.default.join(entries, `${key}${ENTRY_SUFFIX}`);
86
+ const discard = (file) => {
87
+ try {
88
+ (0, import_node_fs.unlinkSync)(file);
89
+ } catch {
90
+ }
91
+ };
92
+ const prune = () => {
93
+ let names;
94
+ try {
95
+ names = (0, import_node_fs.readdirSync)(entries);
96
+ } catch {
97
+ return;
98
+ }
99
+ const now = Date.now();
100
+ const files = [];
101
+ let total = 0;
102
+ for (const name of names) {
103
+ const file = import_node_path.default.join(entries, name);
104
+ let stat;
105
+ try {
106
+ stat = (0, import_node_fs.statSync)(file);
107
+ } catch {
108
+ continue;
109
+ }
110
+ if (!stat.isFile()) continue;
111
+ if (name.endsWith(TMP_SUFFIX)) {
112
+ if (now - stat.mtimeMs > ORPHAN_TMP_AGE_MS) discard(file);
113
+ continue;
114
+ }
115
+ files.push({ file, size: stat.size, mtimeMs: stat.mtimeMs });
116
+ total += stat.size;
117
+ }
118
+ if (total <= limit) return;
119
+ files.sort((a, b) => a.mtimeMs - b.mtimeMs);
120
+ for (const entry of files) {
121
+ if (total <= limit) break;
122
+ discard(entry.file);
123
+ total -= entry.size;
124
+ }
125
+ };
126
+ const readVerified = (file) => {
127
+ let fd;
128
+ try {
129
+ fd = (0, import_node_fs.openSync)(file, import_node_fs.constants.O_RDONLY | (import_node_fs.constants.O_NOFOLLOW ?? 0));
130
+ } catch {
131
+ return void 0;
132
+ }
133
+ let bytes;
134
+ try {
135
+ const stat = (0, import_node_fs.fstatSync)(fd);
136
+ if (!stat.isFile() || stat.uid !== uid || (stat.mode & 63) !== 0) return void 0;
137
+ bytes = (0, import_node_fs.readFileSync)(fd);
138
+ } catch {
139
+ return void 0;
140
+ } finally {
141
+ (0, import_node_fs.closeSync)(fd);
142
+ }
143
+ const text = bytes.toString("utf8");
144
+ const newline = text.indexOf("\n");
145
+ let header;
146
+ try {
147
+ if (newline > 0 && text.startsWith(HEADER_PREFIX)) {
148
+ header = JSON.parse(text.slice(HEADER_PREFIX.length, newline));
149
+ }
150
+ } catch {
151
+ header = void 0;
152
+ }
153
+ const body = newline > 0 ? text.slice(newline + 1) : "";
154
+ if (!header || header.format !== FORMAT || header.sha256 !== sha256(body)) {
155
+ discard(file);
156
+ return void 0;
157
+ }
158
+ return { header, body };
159
+ };
160
+ const writeAtomic = (key, file, header, body) => {
161
+ const tmp = import_node_path.default.join(entries, `.${key}.${process.pid}.${(0, import_node_crypto.randomBytes)(6).toString("hex")}${TMP_SUFFIX}`);
162
+ try {
163
+ (0, import_node_fs.writeFileSync)(tmp, `${HEADER_PREFIX}${JSON.stringify(header)}
164
+ ${body}`, { flag: "wx", mode: 384 });
165
+ (0, import_node_fs.renameSync)(tmp, file);
166
+ return true;
167
+ } catch {
168
+ discard(tmp);
169
+ return false;
170
+ }
171
+ };
172
+ const touch = (file) => {
173
+ try {
174
+ const now = /* @__PURE__ */ new Date();
175
+ (0, import_node_fs.utimesSync)(file, now, now);
176
+ } catch {
177
+ }
178
+ };
179
+ return {
180
+ read(key) {
181
+ const file = entryPath(key);
182
+ const entry = readVerified(file);
183
+ if (!entry) return void 0;
184
+ const { header, body } = entry;
185
+ let validate;
186
+ try {
187
+ const factory = (0, import_node_vm.runInThisContext)(`(function (require, module, exports) {${body}
188
+ })`, {
189
+ filename: file
190
+ });
191
+ const mod = { exports: {} };
192
+ factory(moduleRequire, mod, mod.exports);
193
+ validate = mod.exports;
194
+ if (typeof validate !== "function") throw new Error("not a validator");
195
+ } catch {
196
+ discard(file);
197
+ return void 0;
198
+ }
199
+ delete validate.default;
200
+ validate.errors = null;
201
+ touch(file);
202
+ return { validate, rootSchemaId: typeof header.rootSchemaId === "string" ? header.rootSchemaId : void 0 };
203
+ },
204
+ write(key, moduleCode, rootSchemaId) {
205
+ const header = { format: FORMAT, sha256: sha256(moduleCode), rootSchemaId: rootSchemaId ?? null };
206
+ if (writeAtomic(key, entryPath(key), header, moduleCode)) prune();
207
+ },
208
+ readData(key) {
209
+ const file = import_node_path.default.join(entries, `${key}${DATA_SUFFIX}`);
210
+ const entry = readVerified(file);
211
+ if (!entry) return void 0;
212
+ try {
213
+ const value = JSON.parse(entry.body);
214
+ touch(file);
215
+ return value;
216
+ } catch {
217
+ discard(file);
218
+ return void 0;
219
+ }
220
+ },
221
+ writeData(key, value) {
222
+ const body = JSON.stringify(value);
223
+ const header = { format: FORMAT, sha256: sha256(body), rootSchemaId: null };
224
+ if (writeAtomic(key, import_node_path.default.join(entries, `${key}${DATA_SUFFIX}`), header, body)) prune();
225
+ }
226
+ };
227
+ }
228
+ function filesDigest(files) {
229
+ const hash = (0, import_node_crypto.createHash)("sha256");
230
+ for (const file of files) {
231
+ hash.update(`${import_node_path.default.basename(file)}\0`);
232
+ try {
233
+ hash.update((0, import_node_fs.readFileSync)(file));
234
+ } catch {
235
+ hash.update("missing");
236
+ }
237
+ hash.update("\0");
238
+ }
239
+ return hash.digest("hex");
240
+ }
241
+ function validatorCacheKey(parts) {
242
+ return sha256(JSON.stringify([FORMAT, ...parts]));
243
+ }
244
+ // Annotate the CommonJS export names for ESM import in node:
245
+ 0 && (module.exports = {
246
+ filesDigest,
247
+ openValidatorCache,
248
+ validatorCacheKey
249
+ });
@@ -0,0 +1,227 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import {
3
+ closeSync,
4
+ constants,
5
+ fstatSync,
6
+ lstatSync,
7
+ mkdirSync,
8
+ openSync,
9
+ readFileSync,
10
+ readdirSync,
11
+ renameSync,
12
+ statSync,
13
+ unlinkSync,
14
+ utimesSync,
15
+ writeFileSync
16
+ } from "node:fs";
17
+ import { createRequire } from "node:module";
18
+ import path from "node:path";
19
+ import { runInThisContext } from "node:vm";
20
+ const FORMAT = 1;
21
+ const HEADER_PREFIX = "// adcp-validator-cache ";
22
+ const ENTRY_SUFFIX = ".js";
23
+ const DATA_SUFFIX = ".json";
24
+ const TMP_SUFFIX = ".tmp";
25
+ const ORPHAN_TMP_AGE_MS = 10 * 60 * 1e3;
26
+ const DEFAULT_MAX_BYTES = 512 * 1024 * 1024;
27
+ function sha256(value) {
28
+ return createHash("sha256").update(value).digest("hex");
29
+ }
30
+ function isPrivateDirectory(dir, uid, requireOwnerOnly) {
31
+ try {
32
+ const stat = lstatSync(dir);
33
+ if (!stat.isDirectory() || stat.isSymbolicLink()) return false;
34
+ if (stat.uid !== uid) return false;
35
+ return requireOwnerOnly ? (stat.mode & 63) === 0 : (stat.mode & 18) === 0;
36
+ } catch {
37
+ return false;
38
+ }
39
+ }
40
+ function maxBytes() {
41
+ const raw = process.env.ADCP_VALIDATOR_CACHE_MAX_MB;
42
+ if (raw === void 0 || raw === "") return DEFAULT_MAX_BYTES;
43
+ const value = Number(raw);
44
+ return Number.isFinite(value) && value > 0 ? Math.floor(value * 1024 * 1024) : DEFAULT_MAX_BYTES;
45
+ }
46
+ function openValidatorCache(dir, requireFrom) {
47
+ if (!path.isAbsolute(dir) || typeof process.getuid !== "function") return void 0;
48
+ const uid = process.getuid();
49
+ const entries = path.join(dir, `v${FORMAT}`);
50
+ try {
51
+ mkdirSync(dir, { recursive: true, mode: 448 });
52
+ } catch {
53
+ return void 0;
54
+ }
55
+ if (!isPrivateDirectory(dir, uid, false)) return void 0;
56
+ try {
57
+ mkdirSync(entries, { mode: 448 });
58
+ } catch (error) {
59
+ if (error.code !== "EEXIST") return void 0;
60
+ }
61
+ if (!isPrivateDirectory(entries, uid, true)) return void 0;
62
+ const moduleRequire = createRequire(requireFrom);
63
+ const limit = maxBytes();
64
+ const entryPath = (key) => path.join(entries, `${key}${ENTRY_SUFFIX}`);
65
+ const discard = (file) => {
66
+ try {
67
+ unlinkSync(file);
68
+ } catch {
69
+ }
70
+ };
71
+ const prune = () => {
72
+ let names;
73
+ try {
74
+ names = readdirSync(entries);
75
+ } catch {
76
+ return;
77
+ }
78
+ const now = Date.now();
79
+ const files = [];
80
+ let total = 0;
81
+ for (const name of names) {
82
+ const file = path.join(entries, name);
83
+ let stat;
84
+ try {
85
+ stat = statSync(file);
86
+ } catch {
87
+ continue;
88
+ }
89
+ if (!stat.isFile()) continue;
90
+ if (name.endsWith(TMP_SUFFIX)) {
91
+ if (now - stat.mtimeMs > ORPHAN_TMP_AGE_MS) discard(file);
92
+ continue;
93
+ }
94
+ files.push({ file, size: stat.size, mtimeMs: stat.mtimeMs });
95
+ total += stat.size;
96
+ }
97
+ if (total <= limit) return;
98
+ files.sort((a, b) => a.mtimeMs - b.mtimeMs);
99
+ for (const entry of files) {
100
+ if (total <= limit) break;
101
+ discard(entry.file);
102
+ total -= entry.size;
103
+ }
104
+ };
105
+ const readVerified = (file) => {
106
+ let fd;
107
+ try {
108
+ fd = openSync(file, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
109
+ } catch {
110
+ return void 0;
111
+ }
112
+ let bytes;
113
+ try {
114
+ const stat = fstatSync(fd);
115
+ if (!stat.isFile() || stat.uid !== uid || (stat.mode & 63) !== 0) return void 0;
116
+ bytes = readFileSync(fd);
117
+ } catch {
118
+ return void 0;
119
+ } finally {
120
+ closeSync(fd);
121
+ }
122
+ const text = bytes.toString("utf8");
123
+ const newline = text.indexOf("\n");
124
+ let header;
125
+ try {
126
+ if (newline > 0 && text.startsWith(HEADER_PREFIX)) {
127
+ header = JSON.parse(text.slice(HEADER_PREFIX.length, newline));
128
+ }
129
+ } catch {
130
+ header = void 0;
131
+ }
132
+ const body = newline > 0 ? text.slice(newline + 1) : "";
133
+ if (!header || header.format !== FORMAT || header.sha256 !== sha256(body)) {
134
+ discard(file);
135
+ return void 0;
136
+ }
137
+ return { header, body };
138
+ };
139
+ const writeAtomic = (key, file, header, body) => {
140
+ const tmp = path.join(entries, `.${key}.${process.pid}.${randomBytes(6).toString("hex")}${TMP_SUFFIX}`);
141
+ try {
142
+ writeFileSync(tmp, `${HEADER_PREFIX}${JSON.stringify(header)}
143
+ ${body}`, { flag: "wx", mode: 384 });
144
+ renameSync(tmp, file);
145
+ return true;
146
+ } catch {
147
+ discard(tmp);
148
+ return false;
149
+ }
150
+ };
151
+ const touch = (file) => {
152
+ try {
153
+ const now = /* @__PURE__ */ new Date();
154
+ utimesSync(file, now, now);
155
+ } catch {
156
+ }
157
+ };
158
+ return {
159
+ read(key) {
160
+ const file = entryPath(key);
161
+ const entry = readVerified(file);
162
+ if (!entry) return void 0;
163
+ const { header, body } = entry;
164
+ let validate;
165
+ try {
166
+ const factory = runInThisContext(`(function (require, module, exports) {${body}
167
+ })`, {
168
+ filename: file
169
+ });
170
+ const mod = { exports: {} };
171
+ factory(moduleRequire, mod, mod.exports);
172
+ validate = mod.exports;
173
+ if (typeof validate !== "function") throw new Error("not a validator");
174
+ } catch {
175
+ discard(file);
176
+ return void 0;
177
+ }
178
+ delete validate.default;
179
+ validate.errors = null;
180
+ touch(file);
181
+ return { validate, rootSchemaId: typeof header.rootSchemaId === "string" ? header.rootSchemaId : void 0 };
182
+ },
183
+ write(key, moduleCode, rootSchemaId) {
184
+ const header = { format: FORMAT, sha256: sha256(moduleCode), rootSchemaId: rootSchemaId ?? null };
185
+ if (writeAtomic(key, entryPath(key), header, moduleCode)) prune();
186
+ },
187
+ readData(key) {
188
+ const file = path.join(entries, `${key}${DATA_SUFFIX}`);
189
+ const entry = readVerified(file);
190
+ if (!entry) return void 0;
191
+ try {
192
+ const value = JSON.parse(entry.body);
193
+ touch(file);
194
+ return value;
195
+ } catch {
196
+ discard(file);
197
+ return void 0;
198
+ }
199
+ },
200
+ writeData(key, value) {
201
+ const body = JSON.stringify(value);
202
+ const header = { format: FORMAT, sha256: sha256(body), rootSchemaId: null };
203
+ if (writeAtomic(key, path.join(entries, `${key}${DATA_SUFFIX}`), header, body)) prune();
204
+ }
205
+ };
206
+ }
207
+ function filesDigest(files) {
208
+ const hash = createHash("sha256");
209
+ for (const file of files) {
210
+ hash.update(`${path.basename(file)}\0`);
211
+ try {
212
+ hash.update(readFileSync(file));
213
+ } catch {
214
+ hash.update("missing");
215
+ }
216
+ hash.update("\0");
217
+ }
218
+ return hash.digest("hex");
219
+ }
220
+ function validatorCacheKey(parts) {
221
+ return sha256(JSON.stringify([FORMAT, ...parts]));
222
+ }
223
+ export {
224
+ filesDigest,
225
+ openValidatorCache,
226
+ validatorCacheKey
227
+ };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * AdCP SDK library version
3
3
  */
4
- export declare const LIBRARY_VERSION = "17.0.0-beta.31";
4
+ export declare const LIBRARY_VERSION = "17.0.0-beta.32";
5
5
  /**
6
6
  * AdCP specification version this library is built for
7
7
  */
@@ -33,10 +33,10 @@ export type AdcpVersion = (typeof COMPATIBLE_ADCP_VERSIONS)[number];
33
33
  * Full version information
34
34
  */
35
35
  export declare const VERSION_INFO: {
36
- readonly library: "17.0.0-beta.31";
36
+ readonly library: "17.0.0-beta.32";
37
37
  readonly adcp: "3.3.0-rc.0";
38
38
  readonly compatibleVersions: readonly ["v3", "3.0.0", "3.0", "3.0.1", "3.0.2", "3.0.3", "3.0.4", "3.0.5", "3.0.6", "3.0.7", "3.0.8", "3.0.9", "3.0.10", "3.0.11", "3.0.12", "3.0.13", "3.0.14", "3.0.15", "3.0.16", "3.0.17", "3.0.18", "3.0.19", "3.0.20", "3.0.21", "3.0.22", "3.0.23", "3.0.24", "3.0.25", "3.1.0", "3.1", "3.1.1", "3.1.2", "3.1.3", "3.1.4", "3.1.5", "3.1.6", "3.1.7", "3.1.8", "3.1.9", "3.1.10", "3.1.11", "3.1.12", "3.1.13", "3.1.14", "3.1.15", "3.1.16", "3.1.17", "3.1.18", "3.1.19", "3.1.20", "3.1.21", "3.1.22", "3.1.23", "3.1.24", "3.1.25", "3.1.26", "3.1.27", "3.1.28", "3.1.29", "3.1.30", "3.1.31", "3.2.1", "3.2", "3.2.2", "3.2.3", "3.2.4", "3.2.5", "3.2.6", "3.2.7", "3.2.8", "3.3.0-rc.0", "3.3-rc.0"];
39
- readonly generatedAt: "2026-11-20T13:18:24.191Z";
39
+ readonly generatedAt: "2026-11-21T00:50:34.246Z";
40
40
  };
41
41
  /**
42
42
  * Get the AdCP specification version this library is built for