@web-ts-toolkit/access-router 0.69.0 → 0.71.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/index.js CHANGED
@@ -1091,7 +1091,83 @@ var init_trusted_output_materialization = __esm({
1091
1091
  }
1092
1092
  });
1093
1093
 
1094
+ // src/logger-default.ts
1095
+ var import_node_util5, import_winston, colorizer, defaultLogLevel, inspectValue, defaultLogger;
1096
+ var init_logger_default = __esm({
1097
+ "src/logger-default.ts"() {
1098
+ import_node_util5 = __toESM(require("util"));
1099
+ import_winston = require("winston");
1100
+ colorizer = import_winston.format.colorize();
1101
+ defaultLogLevel = process.env.WTT_LOG_LEVEL || "silent";
1102
+ inspectValue = (value) => {
1103
+ return typeof value === "string" ? value : import_node_util5.default.inspect(value, { depth: 5, colors: false });
1104
+ };
1105
+ defaultLogger = (0, import_winston.createLogger)({
1106
+ level: defaultLogLevel,
1107
+ format: import_winston.format.combine(
1108
+ import_winston.format.errors({ stack: true }),
1109
+ import_winston.format.splat(),
1110
+ import_winston.format.label({ label: "[WTT]" }),
1111
+ import_winston.format.timestamp(),
1112
+ import_winston.format.printf(({ level, label, message, timestamp, stack, ...meta }) => {
1113
+ const formattedLabel = colorizer.colorize(level, String(label));
1114
+ const formattedLevel = colorizer.colorize(level, `[${String(level).toUpperCase()}]`);
1115
+ const formattedMessage = colorizer.colorize(level, inspectValue(stack ?? message));
1116
+ const formattedMeta = Object.keys(meta).length > 0 ? ` ${inspectValue(meta)}` : "";
1117
+ return `${formattedLabel} ${timestamp} ${formattedLevel} ${formattedMessage}${formattedMeta}`;
1118
+ })
1119
+ ),
1120
+ transports: [new import_winston.transports.Console()]
1121
+ });
1122
+ }
1123
+ });
1124
+
1125
+ // src/runtime-context.ts
1126
+ function runWithRuntime(runtime, callback) {
1127
+ return runtimeStorage.run(runtime, callback);
1128
+ }
1129
+ function getActiveRuntime() {
1130
+ return runtimeStorage.getStore() ?? null;
1131
+ }
1132
+ var import_node_async_hooks, runtimeStorage;
1133
+ var init_runtime_context = __esm({
1134
+ "src/runtime-context.ts"() {
1135
+ import_node_async_hooks = require("async_hooks");
1136
+ runtimeStorage = new import_node_async_hooks.AsyncLocalStorage();
1137
+ }
1138
+ });
1139
+
1140
+ // src/acl/proxy-diagnostics.ts
1141
+ var fallbackMode, fallbackLogger, syncProxySnapshotDiagnostics, normalizeMode, readProxySnapshotDiagnostics;
1142
+ var init_proxy_diagnostics = __esm({
1143
+ "src/acl/proxy-diagnostics.ts"() {
1144
+ syncProxySnapshotDiagnostics = (mode, logger) => {
1145
+ fallbackMode = mode;
1146
+ fallbackLogger = logger;
1147
+ };
1148
+ normalizeMode = (mode) => mode === "warn" || mode === "silent" ? mode : "error";
1149
+ readProxySnapshotDiagnostics = (runtime) => {
1150
+ if (runtime)
1151
+ return {
1152
+ mode: normalizeMode(runtime.getGlobalOption("authorizationSnapshotProxyLog")),
1153
+ logger: runtime.getGlobalOption("logger")
1154
+ };
1155
+ return { mode: normalizeMode(fallbackMode), logger: fallbackLogger };
1156
+ };
1157
+ }
1158
+ });
1159
+
1094
1160
  // src/acl/authorization-snapshot.ts
1161
+ function logProxySnapshotRejection(path, error2) {
1162
+ try {
1163
+ const { mode, logger } = readProxySnapshotDiagnostics(getActiveRuntime());
1164
+ if (mode === "silent") return;
1165
+ const message = `[access-router] Authorization snapshot rejected a Proxy at ${path}`;
1166
+ const target = logger?.[mode] ?? defaultLogger[mode];
1167
+ target.call(logger ?? defaultLogger, message, error2);
1168
+ } catch {
1169
+ }
1170
+ }
1095
1171
  function authorizationError(detail) {
1096
1172
  throw new ServiceAuthorizationError(detail);
1097
1173
  }
@@ -1104,6 +1180,7 @@ function authorizationRecord(value, label) {
1104
1180
  function copyAuthorizationValue(value, configuration = false) {
1105
1181
  const active = /* @__PURE__ */ new WeakSet();
1106
1182
  const budget = createTrustedOutputBudget();
1183
+ const pathFrames = [];
1107
1184
  function copy(input, depth) {
1108
1185
  visitTrustedOutput(budget, depth);
1109
1186
  if (typeof input === "function") {
@@ -1115,7 +1192,11 @@ function copyAuthorizationValue(value, configuration = false) {
1115
1192
  if (typeof input === "string") prepareTrustedOutputPayload(budget, input);
1116
1193
  return input;
1117
1194
  }
1118
- if (import_node_util5.types.isProxy(input)) authorizationError("proxy snapshot input");
1195
+ if (import_node_util6.types.isProxy(input)) {
1196
+ const error2 = new ServiceAuthorizationError("proxy snapshot input");
1197
+ logProxySnapshotRejection(`$${pathFrames.join("")}`, error2);
1198
+ throw error2;
1199
+ }
1119
1200
  const ownedCatalog = configuration === true ? readOwnedAuthorizationCatalogWork(input) : void 0;
1120
1201
  if (ownedCatalog) {
1121
1202
  preloadTrustedOutputBudget(budget, depth + ownedCatalog.depth, ownedCatalog.slots - 1);
@@ -1156,13 +1237,24 @@ function copyAuthorizationValue(value, configuration = false) {
1156
1237
  }
1157
1238
  if (configuration && input instanceof Map) {
1158
1239
  const result3 = /* @__PURE__ */ new Map();
1159
- for (const [key, entry] of Map.prototype.entries.call(input))
1160
- result3.set(copy(key, depth + 1), copy(entry, depth + 1));
1240
+ for (const [key, entry] of Map.prototype.entries.call(input)) {
1241
+ pathFrames.push(".<map-key>");
1242
+ const mappedKey = copy(key, depth + 1);
1243
+ pathFrames.pop();
1244
+ pathFrames.push(".<map-value>");
1245
+ const mappedEntry = copy(entry, depth + 1);
1246
+ pathFrames.pop();
1247
+ result3.set(mappedKey, mappedEntry);
1248
+ }
1161
1249
  return result3;
1162
1250
  }
1163
1251
  if (configuration && input instanceof Set) {
1164
1252
  const result3 = /* @__PURE__ */ new Set();
1165
- for (const entry of Set.prototype.values.call(input)) result3.add(copy(entry, depth + 1));
1253
+ for (const entry of Set.prototype.values.call(input)) {
1254
+ pathFrames.push(".<set-entry>");
1255
+ result3.add(copy(entry, depth + 1));
1256
+ pathFrames.pop();
1257
+ }
1166
1258
  return result3;
1167
1259
  }
1168
1260
  const array = Array.isArray(input);
@@ -1178,7 +1270,9 @@ function copyAuthorizationValue(value, configuration = false) {
1178
1270
  const descriptor = Object.getOwnPropertyDescriptor(input, key);
1179
1271
  if (!("value" in descriptor) || !descriptor.enumerable && configuration !== "document")
1180
1272
  authorizationError("accessor/non-enumerable input");
1273
+ pathFrames.push(array ? `[${key}]` : `.${key}`);
1181
1274
  const value2 = copy(descriptor.value, depth + 1);
1275
+ pathFrames.pop();
1182
1276
  if (array || definedProperty && Object.getPrototypeOf(result2) !== Object.prototype || key in result2) {
1183
1277
  definedProperty = true;
1184
1278
  Object.defineProperty(result2, key, {
@@ -1197,15 +1291,18 @@ function copyAuthorizationValue(value, configuration = false) {
1197
1291
  }
1198
1292
  return copy(value, 0);
1199
1293
  }
1200
- var import_node_util5, import_mongoose2, import_express_json_router, ServiceAuthorizationError, unsafeKeys2;
1294
+ var import_node_util6, import_mongoose2, import_express_json_router, ServiceAuthorizationError, unsafeKeys2;
1201
1295
  var init_authorization_snapshot = __esm({
1202
1296
  "src/acl/authorization-snapshot.ts"() {
1203
- import_node_util5 = require("util");
1297
+ import_node_util6 = require("util");
1204
1298
  import_mongoose2 = require("mongoose");
1205
1299
  import_express_json_router = __toESM(require("@web-ts-toolkit/express-json-router"));
1206
1300
  init_field_catalog();
1207
1301
  init_trusted_output_materialization();
1208
1302
  init_output_work_ledger();
1303
+ init_logger_default();
1304
+ init_runtime_context();
1305
+ init_proxy_diagnostics();
1209
1306
  ServiceAuthorizationError = class extends import_express_json_router.default.clientErrors.BadRequestError {
1210
1307
  constructor(detail) {
1211
1308
  const errors = [{ detail: `Service authorization: ${detail}` }];
@@ -1268,12 +1365,12 @@ function prepareOutputWorkString(parts, separator = ".", ledger = currentOutputW
1268
1365
  }
1269
1366
  return parts.join(separator);
1270
1367
  }
1271
- var import_node_async_hooks, preparation;
1368
+ var import_node_async_hooks2, preparation;
1272
1369
  var init_output_work_ledger = __esm({
1273
1370
  "src/acl/output-work-ledger.ts"() {
1274
- import_node_async_hooks = require("async_hooks");
1371
+ import_node_async_hooks2 = require("async_hooks");
1275
1372
  init_authorization_snapshot();
1276
- preparation = new import_node_async_hooks.AsyncLocalStorage();
1373
+ preparation = new import_node_async_hooks2.AsyncLocalStorage();
1277
1374
  }
1278
1375
  });
1279
1376
 
@@ -1325,7 +1422,7 @@ function walkControlAdmission(input, kind, check, reject) {
1325
1422
  const { value, kind: slot, path, depth } = pending.pop();
1326
1423
  if (!value || typeof value !== "object" && typeof value !== "function") continue;
1327
1424
  if (typeof value === "function" && (slot === "policy" || slot === "data")) continue;
1328
- if (import_node_util6.types.isProxy(value)) reject(`unsupported proxy in control admission: ${path}`);
1425
+ if (import_node_util7.types.isProxy(value)) reject(`unsupported proxy in control admission: ${path}`);
1329
1426
  const owners = admitControlPrototypes(value, reject);
1330
1427
  const kinds = seen.get(value) ?? /* @__PURE__ */ new Set();
1331
1428
  if (kinds.has(slot)) continue;
@@ -1464,11 +1561,11 @@ function requestOnlyServiceOptions(options) {
1464
1561
  authorization: requestAuthorization
1465
1562
  };
1466
1563
  }
1467
- var import_express_json_router2, import_node_util6, import_utils2, privateControls, PublicAdmissionError, defaultControlBuckets, listArgs, readArgs, listOptions, readOptions, requestAuthorization;
1564
+ var import_express_json_router2, import_node_util7, import_utils2, privateControls, PublicAdmissionError, defaultControlBuckets, listArgs, readArgs, listOptions, readOptions, requestAuthorization;
1468
1565
  var init_public_admission = __esm({
1469
1566
  "src/validation/public-admission.ts"() {
1470
1567
  import_express_json_router2 = __toESM(require("@web-ts-toolkit/express-json-router"));
1471
- import_node_util6 = require("util");
1568
+ import_node_util7 = require("util");
1472
1569
  import_utils2 = require("@web-ts-toolkit/utils");
1473
1570
  init_output_work_ledger();
1474
1571
  init_authorization_modes();
@@ -1618,10 +1715,10 @@ var init_collection = __esm({
1618
1715
  });
1619
1716
 
1620
1717
  // src/helpers/concurrency.ts
1621
- var import_node_async_hooks2, mapWithConcurrencyLimit, FifoAdmission, RequestConcurrencyScheduler, hookFrames, MAX_HOOK_DEPTH, SharedHookGate, normalizeHookConcurrencyLimit;
1718
+ var import_node_async_hooks3, mapWithConcurrencyLimit, FifoAdmission, RequestConcurrencyScheduler, hookFrames, MAX_HOOK_DEPTH, SharedHookGate, normalizeHookConcurrencyLimit;
1622
1719
  var init_concurrency = __esm({
1623
1720
  "src/helpers/concurrency.ts"() {
1624
- import_node_async_hooks2 = require("async_hooks");
1721
+ import_node_async_hooks3 = require("async_hooks");
1625
1722
  mapWithConcurrencyLimit = async (items, limit, iteratee, onError) => {
1626
1723
  const results = new Array(items.length);
1627
1724
  let cursor = 0;
@@ -1695,7 +1792,7 @@ var init_concurrency = __esm({
1695
1792
  return this.persistence.run(operation);
1696
1793
  }
1697
1794
  };
1698
- hookFrames = new import_node_async_hooks2.AsyncLocalStorage();
1795
+ hookFrames = new import_node_async_hooks3.AsyncLocalStorage();
1699
1796
  MAX_HOOK_DEPTH = 64;
1700
1797
  SharedHookGate = class {
1701
1798
  constructor(limit) {
@@ -2650,37 +2747,6 @@ var init_registry = __esm({
2650
2747
  }
2651
2748
  });
2652
2749
 
2653
- // src/logger-default.ts
2654
- var import_node_util7, import_winston, colorizer, defaultLogLevel, inspectValue, defaultLogger;
2655
- var init_logger_default = __esm({
2656
- "src/logger-default.ts"() {
2657
- import_node_util7 = __toESM(require("util"));
2658
- import_winston = require("winston");
2659
- colorizer = import_winston.format.colorize();
2660
- defaultLogLevel = process.env.WTT_LOG_LEVEL || "silent";
2661
- inspectValue = (value) => {
2662
- return typeof value === "string" ? value : import_node_util7.default.inspect(value, { depth: 5, colors: false });
2663
- };
2664
- defaultLogger = (0, import_winston.createLogger)({
2665
- level: defaultLogLevel,
2666
- format: import_winston.format.combine(
2667
- import_winston.format.errors({ stack: true }),
2668
- import_winston.format.splat(),
2669
- import_winston.format.label({ label: "[WTT]" }),
2670
- import_winston.format.timestamp(),
2671
- import_winston.format.printf(({ level, label, message, timestamp, stack, ...meta }) => {
2672
- const formattedLabel = colorizer.colorize(level, String(label));
2673
- const formattedLevel = colorizer.colorize(level, `[${String(level).toUpperCase()}]`);
2674
- const formattedMessage = colorizer.colorize(level, inspectValue(stack ?? message));
2675
- const formattedMeta = Object.keys(meta).length > 0 ? ` ${inspectValue(meta)}` : "";
2676
- return `${formattedLabel} ${timestamp} ${formattedLevel} ${formattedMessage}${formattedMeta}`;
2677
- })
2678
- ),
2679
- transports: [new import_winston.transports.Console()]
2680
- });
2681
- }
2682
- });
2683
-
2684
2750
  // src/options/manager.ts
2685
2751
  var import_utils11, toPath, cloneConfigValue, cloneForRead, freezeConfigValue, cloneAndFreezeForStore, cloneOptionsSnapshot, getNestedOption, resolveNestedOption, OptionsManager;
2686
2752
  var init_manager = __esm({
@@ -3406,21 +3472,6 @@ var init_virtual_descriptor = __esm({
3406
3472
  }
3407
3473
  });
3408
3474
 
3409
- // src/runtime-context.ts
3410
- function runWithRuntime(runtime, callback) {
3411
- return runtimeStorage.run(runtime, callback);
3412
- }
3413
- function getActiveRuntime() {
3414
- return runtimeStorage.getStore() ?? null;
3415
- }
3416
- var import_node_async_hooks3, runtimeStorage;
3417
- var init_runtime_context = __esm({
3418
- "src/runtime-context.ts"() {
3419
- import_node_async_hooks3 = require("async_hooks");
3420
- runtimeStorage = new import_node_async_hooks3.AsyncLocalStorage();
3421
- }
3422
- });
3423
-
3424
3475
  // src/meta.ts
3425
3476
  var getRuntime, getModelReference;
3426
3477
  var init_meta = __esm({
@@ -3928,6 +3979,7 @@ var init_runtime = __esm({
3928
3979
  init_document_permissions_definition();
3929
3980
  init_persisted_dependencies();
3930
3981
  init_authorization_modes();
3982
+ init_proxy_diagnostics();
3931
3983
  mongooseJsonSchemaInitialized = false;
3932
3984
  ensureMongooseJsonSchemaInitialized = () => {
3933
3985
  if (mongooseJsonSchemaInitialized) return;
@@ -4282,6 +4334,13 @@ var init_runtime = __esm({
4282
4334
  this.allowGlobalModelLookup = options.allowGlobalModelLookup ?? false;
4283
4335
  ensureMongooseJsonSchemaInitialized();
4284
4336
  }
4337
+ syncProxySnapshotDiagnosticsState() {
4338
+ if (this !== defaultRuntime) return;
4339
+ syncProxySnapshotDiagnostics(
4340
+ this.globalOptions.get("authorizationSnapshotProxyLog"),
4341
+ this.globalOptions.get("logger")
4342
+ );
4343
+ }
4285
4344
  registerModelInstance(modelName, model) {
4286
4345
  if (!modelName || typeof modelName !== "string") {
4287
4346
  throw new TypeError(`registerModelInstance: modelName must be a non-empty string, received ${typeof modelName}`);
@@ -4418,6 +4477,7 @@ var init_runtime = __esm({
4418
4477
  assertNoServerModelControls(options, reject, "data-options");
4419
4478
  }
4420
4479
  this.globalOptions.restore(snapshot.globalOptions);
4480
+ this.syncProxySnapshotDiagnosticsState();
4421
4481
  this.defaultModelOptions.restore(snapshot.defaultModelOptions);
4422
4482
  for (const name of Object.keys(this.modelOptionOverrides)) delete this.modelOptionOverrides[name];
4423
4483
  for (const [name, options] of Object.entries(snapshot.modelOptionOverrides)) {
@@ -4482,6 +4542,7 @@ var init_runtime = __esm({
4482
4542
  });
4483
4543
  for (const key of populatePolicyKeys) if (key in options) assertNoGlobalPopulatePolicy(key);
4484
4544
  this.globalOptions.assign({ ...options });
4545
+ this.syncProxySnapshotDiagnosticsState();
4485
4546
  }
4486
4547
  setGlobalOption(key, value) {
4487
4548
  assertAuthorizationModeKey(key, false);
@@ -4492,6 +4553,7 @@ var init_runtime = __esm({
4492
4553
  throw new TypeError(detail);
4493
4554
  });
4494
4555
  this.globalOptions.set(key, value);
4556
+ this.syncProxySnapshotDiagnosticsState();
4495
4557
  }
4496
4558
  getGlobalOptions() {
4497
4559
  return this.globalOptions.fetch();
package/index.mjs CHANGED
@@ -1070,10 +1070,86 @@ var init_trusted_output_materialization = __esm({
1070
1070
  }
1071
1071
  });
1072
1072
 
1073
+ // src/logger-default.ts
1074
+ import util from "util";
1075
+ import { createLogger, format, transports } from "winston";
1076
+ var colorizer, defaultLogLevel, inspectValue, defaultLogger;
1077
+ var init_logger_default = __esm({
1078
+ "src/logger-default.ts"() {
1079
+ colorizer = format.colorize();
1080
+ defaultLogLevel = process.env.WTT_LOG_LEVEL || "silent";
1081
+ inspectValue = (value) => {
1082
+ return typeof value === "string" ? value : util.inspect(value, { depth: 5, colors: false });
1083
+ };
1084
+ defaultLogger = createLogger({
1085
+ level: defaultLogLevel,
1086
+ format: format.combine(
1087
+ format.errors({ stack: true }),
1088
+ format.splat(),
1089
+ format.label({ label: "[WTT]" }),
1090
+ format.timestamp(),
1091
+ format.printf(({ level, label, message, timestamp, stack, ...meta }) => {
1092
+ const formattedLabel = colorizer.colorize(level, String(label));
1093
+ const formattedLevel = colorizer.colorize(level, `[${String(level).toUpperCase()}]`);
1094
+ const formattedMessage = colorizer.colorize(level, inspectValue(stack ?? message));
1095
+ const formattedMeta = Object.keys(meta).length > 0 ? ` ${inspectValue(meta)}` : "";
1096
+ return `${formattedLabel} ${timestamp} ${formattedLevel} ${formattedMessage}${formattedMeta}`;
1097
+ })
1098
+ ),
1099
+ transports: [new transports.Console()]
1100
+ });
1101
+ }
1102
+ });
1103
+
1104
+ // src/runtime-context.ts
1105
+ import { AsyncLocalStorage } from "async_hooks";
1106
+ function runWithRuntime(runtime, callback) {
1107
+ return runtimeStorage.run(runtime, callback);
1108
+ }
1109
+ function getActiveRuntime() {
1110
+ return runtimeStorage.getStore() ?? null;
1111
+ }
1112
+ var runtimeStorage;
1113
+ var init_runtime_context = __esm({
1114
+ "src/runtime-context.ts"() {
1115
+ runtimeStorage = new AsyncLocalStorage();
1116
+ }
1117
+ });
1118
+
1119
+ // src/acl/proxy-diagnostics.ts
1120
+ var fallbackMode, fallbackLogger, syncProxySnapshotDiagnostics, normalizeMode, readProxySnapshotDiagnostics;
1121
+ var init_proxy_diagnostics = __esm({
1122
+ "src/acl/proxy-diagnostics.ts"() {
1123
+ syncProxySnapshotDiagnostics = (mode, logger) => {
1124
+ fallbackMode = mode;
1125
+ fallbackLogger = logger;
1126
+ };
1127
+ normalizeMode = (mode) => mode === "warn" || mode === "silent" ? mode : "error";
1128
+ readProxySnapshotDiagnostics = (runtime) => {
1129
+ if (runtime)
1130
+ return {
1131
+ mode: normalizeMode(runtime.getGlobalOption("authorizationSnapshotProxyLog")),
1132
+ logger: runtime.getGlobalOption("logger")
1133
+ };
1134
+ return { mode: normalizeMode(fallbackMode), logger: fallbackLogger };
1135
+ };
1136
+ }
1137
+ });
1138
+
1073
1139
  // src/acl/authorization-snapshot.ts
1074
1140
  import { types as types5 } from "util";
1075
1141
  import { mongo as mongo2 } from "mongoose";
1076
1142
  import JsonRouter from "@web-ts-toolkit/express-json-router";
1143
+ function logProxySnapshotRejection(path, error2) {
1144
+ try {
1145
+ const { mode, logger } = readProxySnapshotDiagnostics(getActiveRuntime());
1146
+ if (mode === "silent") return;
1147
+ const message = `[access-router] Authorization snapshot rejected a Proxy at ${path}`;
1148
+ const target = logger?.[mode] ?? defaultLogger[mode];
1149
+ target.call(logger ?? defaultLogger, message, error2);
1150
+ } catch {
1151
+ }
1152
+ }
1077
1153
  function authorizationError(detail) {
1078
1154
  throw new ServiceAuthorizationError(detail);
1079
1155
  }
@@ -1086,6 +1162,7 @@ function authorizationRecord(value, label) {
1086
1162
  function copyAuthorizationValue(value, configuration = false) {
1087
1163
  const active = /* @__PURE__ */ new WeakSet();
1088
1164
  const budget = createTrustedOutputBudget();
1165
+ const pathFrames = [];
1089
1166
  function copy(input, depth) {
1090
1167
  visitTrustedOutput(budget, depth);
1091
1168
  if (typeof input === "function") {
@@ -1097,7 +1174,11 @@ function copyAuthorizationValue(value, configuration = false) {
1097
1174
  if (typeof input === "string") prepareTrustedOutputPayload(budget, input);
1098
1175
  return input;
1099
1176
  }
1100
- if (types5.isProxy(input)) authorizationError("proxy snapshot input");
1177
+ if (types5.isProxy(input)) {
1178
+ const error2 = new ServiceAuthorizationError("proxy snapshot input");
1179
+ logProxySnapshotRejection(`$${pathFrames.join("")}`, error2);
1180
+ throw error2;
1181
+ }
1101
1182
  const ownedCatalog = configuration === true ? readOwnedAuthorizationCatalogWork(input) : void 0;
1102
1183
  if (ownedCatalog) {
1103
1184
  preloadTrustedOutputBudget(budget, depth + ownedCatalog.depth, ownedCatalog.slots - 1);
@@ -1138,13 +1219,24 @@ function copyAuthorizationValue(value, configuration = false) {
1138
1219
  }
1139
1220
  if (configuration && input instanceof Map) {
1140
1221
  const result3 = /* @__PURE__ */ new Map();
1141
- for (const [key, entry] of Map.prototype.entries.call(input))
1142
- result3.set(copy(key, depth + 1), copy(entry, depth + 1));
1222
+ for (const [key, entry] of Map.prototype.entries.call(input)) {
1223
+ pathFrames.push(".<map-key>");
1224
+ const mappedKey = copy(key, depth + 1);
1225
+ pathFrames.pop();
1226
+ pathFrames.push(".<map-value>");
1227
+ const mappedEntry = copy(entry, depth + 1);
1228
+ pathFrames.pop();
1229
+ result3.set(mappedKey, mappedEntry);
1230
+ }
1143
1231
  return result3;
1144
1232
  }
1145
1233
  if (configuration && input instanceof Set) {
1146
1234
  const result3 = /* @__PURE__ */ new Set();
1147
- for (const entry of Set.prototype.values.call(input)) result3.add(copy(entry, depth + 1));
1235
+ for (const entry of Set.prototype.values.call(input)) {
1236
+ pathFrames.push(".<set-entry>");
1237
+ result3.add(copy(entry, depth + 1));
1238
+ pathFrames.pop();
1239
+ }
1148
1240
  return result3;
1149
1241
  }
1150
1242
  const array = Array.isArray(input);
@@ -1160,7 +1252,9 @@ function copyAuthorizationValue(value, configuration = false) {
1160
1252
  const descriptor = Object.getOwnPropertyDescriptor(input, key);
1161
1253
  if (!("value" in descriptor) || !descriptor.enumerable && configuration !== "document")
1162
1254
  authorizationError("accessor/non-enumerable input");
1255
+ pathFrames.push(array ? `[${key}]` : `.${key}`);
1163
1256
  const value2 = copy(descriptor.value, depth + 1);
1257
+ pathFrames.pop();
1164
1258
  if (array || definedProperty && Object.getPrototypeOf(result2) !== Object.prototype || key in result2) {
1165
1259
  definedProperty = true;
1166
1260
  Object.defineProperty(result2, key, {
@@ -1185,6 +1279,9 @@ var init_authorization_snapshot = __esm({
1185
1279
  init_field_catalog();
1186
1280
  init_trusted_output_materialization();
1187
1281
  init_output_work_ledger();
1282
+ init_logger_default();
1283
+ init_runtime_context();
1284
+ init_proxy_diagnostics();
1188
1285
  ServiceAuthorizationError = class extends JsonRouter.clientErrors.BadRequestError {
1189
1286
  constructor(detail) {
1190
1287
  const errors = [{ detail: `Service authorization: ${detail}` }];
@@ -1206,7 +1303,7 @@ var init_authorization_snapshot = __esm({
1206
1303
  });
1207
1304
 
1208
1305
  // src/acl/output-work-ledger.ts
1209
- import { AsyncLocalStorage } from "async_hooks";
1306
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
1210
1307
  function currentOutputWorkLedger() {
1211
1308
  return preparation.getStore();
1212
1309
  }
@@ -1252,7 +1349,7 @@ var preparation;
1252
1349
  var init_output_work_ledger = __esm({
1253
1350
  "src/acl/output-work-ledger.ts"() {
1254
1351
  init_authorization_snapshot();
1255
- preparation = new AsyncLocalStorage();
1352
+ preparation = new AsyncLocalStorage2();
1256
1353
  }
1257
1354
  });
1258
1355
 
@@ -1597,7 +1694,7 @@ var init_collection = __esm({
1597
1694
  });
1598
1695
 
1599
1696
  // src/helpers/concurrency.ts
1600
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
1697
+ import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
1601
1698
  var mapWithConcurrencyLimit, FifoAdmission, RequestConcurrencyScheduler, hookFrames, MAX_HOOK_DEPTH, SharedHookGate, normalizeHookConcurrencyLimit;
1602
1699
  var init_concurrency = __esm({
1603
1700
  "src/helpers/concurrency.ts"() {
@@ -1674,7 +1771,7 @@ var init_concurrency = __esm({
1674
1771
  return this.persistence.run(operation);
1675
1772
  }
1676
1773
  };
1677
- hookFrames = new AsyncLocalStorage2();
1774
+ hookFrames = new AsyncLocalStorage3();
1678
1775
  MAX_HOOK_DEPTH = 64;
1679
1776
  SharedHookGate = class {
1680
1777
  constructor(limit) {
@@ -2629,37 +2726,6 @@ var init_registry = __esm({
2629
2726
  }
2630
2727
  });
2631
2728
 
2632
- // src/logger-default.ts
2633
- import util from "util";
2634
- import { createLogger, format, transports } from "winston";
2635
- var colorizer, defaultLogLevel, inspectValue, defaultLogger;
2636
- var init_logger_default = __esm({
2637
- "src/logger-default.ts"() {
2638
- colorizer = format.colorize();
2639
- defaultLogLevel = process.env.WTT_LOG_LEVEL || "silent";
2640
- inspectValue = (value) => {
2641
- return typeof value === "string" ? value : util.inspect(value, { depth: 5, colors: false });
2642
- };
2643
- defaultLogger = createLogger({
2644
- level: defaultLogLevel,
2645
- format: format.combine(
2646
- format.errors({ stack: true }),
2647
- format.splat(),
2648
- format.label({ label: "[WTT]" }),
2649
- format.timestamp(),
2650
- format.printf(({ level, label, message, timestamp, stack, ...meta }) => {
2651
- const formattedLabel = colorizer.colorize(level, String(label));
2652
- const formattedLevel = colorizer.colorize(level, `[${String(level).toUpperCase()}]`);
2653
- const formattedMessage = colorizer.colorize(level, inspectValue(stack ?? message));
2654
- const formattedMeta = Object.keys(meta).length > 0 ? ` ${inspectValue(meta)}` : "";
2655
- return `${formattedLabel} ${timestamp} ${formattedLevel} ${formattedMessage}${formattedMeta}`;
2656
- })
2657
- ),
2658
- transports: [new transports.Console()]
2659
- });
2660
- }
2661
- });
2662
-
2663
2729
  // src/options/manager.ts
2664
2730
  import { assign, get as get3, isPlainObject as isPlainObject9, set as set2 } from "@web-ts-toolkit/utils";
2665
2731
  var toPath, cloneConfigValue, cloneForRead, freezeConfigValue, cloneAndFreezeForStore, cloneOptionsSnapshot, getNestedOption, resolveNestedOption, OptionsManager;
@@ -3385,21 +3451,6 @@ var init_virtual_descriptor = __esm({
3385
3451
  }
3386
3452
  });
3387
3453
 
3388
- // src/runtime-context.ts
3389
- import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
3390
- function runWithRuntime(runtime, callback) {
3391
- return runtimeStorage.run(runtime, callback);
3392
- }
3393
- function getActiveRuntime() {
3394
- return runtimeStorage.getStore() ?? null;
3395
- }
3396
- var runtimeStorage;
3397
- var init_runtime_context = __esm({
3398
- "src/runtime-context.ts"() {
3399
- runtimeStorage = new AsyncLocalStorage3();
3400
- }
3401
- });
3402
-
3403
3454
  // src/meta.ts
3404
3455
  var getRuntime, getModelReference;
3405
3456
  var init_meta = __esm({
@@ -3917,6 +3968,7 @@ var init_runtime = __esm({
3917
3968
  init_document_permissions_definition();
3918
3969
  init_persisted_dependencies();
3919
3970
  init_authorization_modes();
3971
+ init_proxy_diagnostics();
3920
3972
  mongooseJsonSchemaInitialized = false;
3921
3973
  ensureMongooseJsonSchemaInitialized = () => {
3922
3974
  if (mongooseJsonSchemaInitialized) return;
@@ -4271,6 +4323,13 @@ var init_runtime = __esm({
4271
4323
  this.allowGlobalModelLookup = options.allowGlobalModelLookup ?? false;
4272
4324
  ensureMongooseJsonSchemaInitialized();
4273
4325
  }
4326
+ syncProxySnapshotDiagnosticsState() {
4327
+ if (this !== defaultRuntime) return;
4328
+ syncProxySnapshotDiagnostics(
4329
+ this.globalOptions.get("authorizationSnapshotProxyLog"),
4330
+ this.globalOptions.get("logger")
4331
+ );
4332
+ }
4274
4333
  registerModelInstance(modelName, model) {
4275
4334
  if (!modelName || typeof modelName !== "string") {
4276
4335
  throw new TypeError(`registerModelInstance: modelName must be a non-empty string, received ${typeof modelName}`);
@@ -4407,6 +4466,7 @@ var init_runtime = __esm({
4407
4466
  assertNoServerModelControls(options, reject, "data-options");
4408
4467
  }
4409
4468
  this.globalOptions.restore(snapshot.globalOptions);
4469
+ this.syncProxySnapshotDiagnosticsState();
4410
4470
  this.defaultModelOptions.restore(snapshot.defaultModelOptions);
4411
4471
  for (const name of Object.keys(this.modelOptionOverrides)) delete this.modelOptionOverrides[name];
4412
4472
  for (const [name, options] of Object.entries(snapshot.modelOptionOverrides)) {
@@ -4471,6 +4531,7 @@ var init_runtime = __esm({
4471
4531
  });
4472
4532
  for (const key of populatePolicyKeys) if (key in options) assertNoGlobalPopulatePolicy(key);
4473
4533
  this.globalOptions.assign({ ...options });
4534
+ this.syncProxySnapshotDiagnosticsState();
4474
4535
  }
4475
4536
  setGlobalOption(key, value) {
4476
4537
  assertAuthorizationModeKey(key, false);
@@ -4481,6 +4542,7 @@ var init_runtime = __esm({
4481
4542
  throw new TypeError(detail);
4482
4543
  });
4483
4544
  this.globalOptions.set(key, value);
4545
+ this.syncProxySnapshotDiagnosticsState();
4484
4546
  }
4485
4547
  getGlobalOptions() {
4486
4548
  return this.globalOptions.fetch();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@web-ts-toolkit/access-router",
3
3
  "description": "ACL-aware Express routers and in-memory data services for Mongoose-backed APIs",
4
4
  "homepage": "https://web-ts-toolkit.pages.dev/docs/packages/access-router",
5
- "version": "0.69.0",
5
+ "version": "0.71.0",
6
6
  "sideEffects": [
7
7
  "./**/index.js",
8
8
  "./**/index.mjs",
@@ -57,8 +57,8 @@
57
57
  "node": ">=24"
58
58
  },
59
59
  "dependencies": {
60
- "@web-ts-toolkit/express-json-router": "0.69.0",
61
- "@web-ts-toolkit/utils": "0.69.0",
60
+ "@web-ts-toolkit/express-json-router": "0.71.0",
61
+ "@web-ts-toolkit/utils": "0.71.0",
62
62
  "just-diff": "^6.0.2",
63
63
  "mongoose-schema-jsonschema": "^4.0.1",
64
64
  "sift": "^17.1.3",