@web-ts-toolkit/access-router 0.70.0 → 0.72.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,9 +1192,9 @@ 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)) {
1195
+ if (import_node_util6.types.isProxy(input)) {
1119
1196
  const error2 = new ServiceAuthorizationError("proxy snapshot input");
1120
- console.error("[access-router] Authorization snapshot rejected a Proxy", error2);
1197
+ logProxySnapshotRejection(`$${pathFrames.join("")}`, error2);
1121
1198
  throw error2;
1122
1199
  }
1123
1200
  const ownedCatalog = configuration === true ? readOwnedAuthorizationCatalogWork(input) : void 0;
@@ -1160,13 +1237,24 @@ function copyAuthorizationValue(value, configuration = false) {
1160
1237
  }
1161
1238
  if (configuration && input instanceof Map) {
1162
1239
  const result3 = /* @__PURE__ */ new Map();
1163
- for (const [key, entry] of Map.prototype.entries.call(input))
1164
- 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
+ }
1165
1249
  return result3;
1166
1250
  }
1167
1251
  if (configuration && input instanceof Set) {
1168
1252
  const result3 = /* @__PURE__ */ new Set();
1169
- 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
+ }
1170
1258
  return result3;
1171
1259
  }
1172
1260
  const array = Array.isArray(input);
@@ -1182,7 +1270,9 @@ function copyAuthorizationValue(value, configuration = false) {
1182
1270
  const descriptor = Object.getOwnPropertyDescriptor(input, key);
1183
1271
  if (!("value" in descriptor) || !descriptor.enumerable && configuration !== "document")
1184
1272
  authorizationError("accessor/non-enumerable input");
1273
+ pathFrames.push(array ? `[${key}]` : `.${key}`);
1185
1274
  const value2 = copy(descriptor.value, depth + 1);
1275
+ pathFrames.pop();
1186
1276
  if (array || definedProperty && Object.getPrototypeOf(result2) !== Object.prototype || key in result2) {
1187
1277
  definedProperty = true;
1188
1278
  Object.defineProperty(result2, key, {
@@ -1201,15 +1291,18 @@ function copyAuthorizationValue(value, configuration = false) {
1201
1291
  }
1202
1292
  return copy(value, 0);
1203
1293
  }
1204
- 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;
1205
1295
  var init_authorization_snapshot = __esm({
1206
1296
  "src/acl/authorization-snapshot.ts"() {
1207
- import_node_util5 = require("util");
1297
+ import_node_util6 = require("util");
1208
1298
  import_mongoose2 = require("mongoose");
1209
1299
  import_express_json_router = __toESM(require("@web-ts-toolkit/express-json-router"));
1210
1300
  init_field_catalog();
1211
1301
  init_trusted_output_materialization();
1212
1302
  init_output_work_ledger();
1303
+ init_logger_default();
1304
+ init_runtime_context();
1305
+ init_proxy_diagnostics();
1213
1306
  ServiceAuthorizationError = class extends import_express_json_router.default.clientErrors.BadRequestError {
1214
1307
  constructor(detail) {
1215
1308
  const errors = [{ detail: `Service authorization: ${detail}` }];
@@ -1272,12 +1365,12 @@ function prepareOutputWorkString(parts, separator = ".", ledger = currentOutputW
1272
1365
  }
1273
1366
  return parts.join(separator);
1274
1367
  }
1275
- var import_node_async_hooks, preparation;
1368
+ var import_node_async_hooks2, preparation;
1276
1369
  var init_output_work_ledger = __esm({
1277
1370
  "src/acl/output-work-ledger.ts"() {
1278
- import_node_async_hooks = require("async_hooks");
1371
+ import_node_async_hooks2 = require("async_hooks");
1279
1372
  init_authorization_snapshot();
1280
- preparation = new import_node_async_hooks.AsyncLocalStorage();
1373
+ preparation = new import_node_async_hooks2.AsyncLocalStorage();
1281
1374
  }
1282
1375
  });
1283
1376
 
@@ -1329,7 +1422,7 @@ function walkControlAdmission(input, kind, check, reject) {
1329
1422
  const { value, kind: slot, path, depth } = pending.pop();
1330
1423
  if (!value || typeof value !== "object" && typeof value !== "function") continue;
1331
1424
  if (typeof value === "function" && (slot === "policy" || slot === "data")) continue;
1332
- 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}`);
1333
1426
  const owners = admitControlPrototypes(value, reject);
1334
1427
  const kinds = seen.get(value) ?? /* @__PURE__ */ new Set();
1335
1428
  if (kinds.has(slot)) continue;
@@ -1468,11 +1561,11 @@ function requestOnlyServiceOptions(options) {
1468
1561
  authorization: requestAuthorization
1469
1562
  };
1470
1563
  }
1471
- 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;
1472
1565
  var init_public_admission = __esm({
1473
1566
  "src/validation/public-admission.ts"() {
1474
1567
  import_express_json_router2 = __toESM(require("@web-ts-toolkit/express-json-router"));
1475
- import_node_util6 = require("util");
1568
+ import_node_util7 = require("util");
1476
1569
  import_utils2 = require("@web-ts-toolkit/utils");
1477
1570
  init_output_work_ledger();
1478
1571
  init_authorization_modes();
@@ -1622,10 +1715,10 @@ var init_collection = __esm({
1622
1715
  });
1623
1716
 
1624
1717
  // src/helpers/concurrency.ts
1625
- 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;
1626
1719
  var init_concurrency = __esm({
1627
1720
  "src/helpers/concurrency.ts"() {
1628
- import_node_async_hooks2 = require("async_hooks");
1721
+ import_node_async_hooks3 = require("async_hooks");
1629
1722
  mapWithConcurrencyLimit = async (items, limit, iteratee, onError) => {
1630
1723
  const results = new Array(items.length);
1631
1724
  let cursor = 0;
@@ -1699,7 +1792,7 @@ var init_concurrency = __esm({
1699
1792
  return this.persistence.run(operation);
1700
1793
  }
1701
1794
  };
1702
- hookFrames = new import_node_async_hooks2.AsyncLocalStorage();
1795
+ hookFrames = new import_node_async_hooks3.AsyncLocalStorage();
1703
1796
  MAX_HOOK_DEPTH = 64;
1704
1797
  SharedHookGate = class {
1705
1798
  constructor(limit) {
@@ -2654,37 +2747,6 @@ var init_registry = __esm({
2654
2747
  }
2655
2748
  });
2656
2749
 
2657
- // src/logger-default.ts
2658
- var import_node_util7, import_winston, colorizer, defaultLogLevel, inspectValue, defaultLogger;
2659
- var init_logger_default = __esm({
2660
- "src/logger-default.ts"() {
2661
- import_node_util7 = __toESM(require("util"));
2662
- import_winston = require("winston");
2663
- colorizer = import_winston.format.colorize();
2664
- defaultLogLevel = process.env.WTT_LOG_LEVEL || "silent";
2665
- inspectValue = (value) => {
2666
- return typeof value === "string" ? value : import_node_util7.default.inspect(value, { depth: 5, colors: false });
2667
- };
2668
- defaultLogger = (0, import_winston.createLogger)({
2669
- level: defaultLogLevel,
2670
- format: import_winston.format.combine(
2671
- import_winston.format.errors({ stack: true }),
2672
- import_winston.format.splat(),
2673
- import_winston.format.label({ label: "[WTT]" }),
2674
- import_winston.format.timestamp(),
2675
- import_winston.format.printf(({ level, label, message, timestamp, stack, ...meta }) => {
2676
- const formattedLabel = colorizer.colorize(level, String(label));
2677
- const formattedLevel = colorizer.colorize(level, `[${String(level).toUpperCase()}]`);
2678
- const formattedMessage = colorizer.colorize(level, inspectValue(stack ?? message));
2679
- const formattedMeta = Object.keys(meta).length > 0 ? ` ${inspectValue(meta)}` : "";
2680
- return `${formattedLabel} ${timestamp} ${formattedLevel} ${formattedMessage}${formattedMeta}`;
2681
- })
2682
- ),
2683
- transports: [new import_winston.transports.Console()]
2684
- });
2685
- }
2686
- });
2687
-
2688
2750
  // src/options/manager.ts
2689
2751
  var import_utils11, toPath, cloneConfigValue, cloneForRead, freezeConfigValue, cloneAndFreezeForStore, cloneOptionsSnapshot, getNestedOption, resolveNestedOption, OptionsManager;
2690
2752
  var init_manager = __esm({
@@ -3410,21 +3472,6 @@ var init_virtual_descriptor = __esm({
3410
3472
  }
3411
3473
  });
3412
3474
 
3413
- // src/runtime-context.ts
3414
- function runWithRuntime(runtime, callback) {
3415
- return runtimeStorage.run(runtime, callback);
3416
- }
3417
- function getActiveRuntime() {
3418
- return runtimeStorage.getStore() ?? null;
3419
- }
3420
- var import_node_async_hooks3, runtimeStorage;
3421
- var init_runtime_context = __esm({
3422
- "src/runtime-context.ts"() {
3423
- import_node_async_hooks3 = require("async_hooks");
3424
- runtimeStorage = new import_node_async_hooks3.AsyncLocalStorage();
3425
- }
3426
- });
3427
-
3428
3475
  // src/meta.ts
3429
3476
  var getRuntime, getModelReference;
3430
3477
  var init_meta = __esm({
@@ -3932,6 +3979,7 @@ var init_runtime = __esm({
3932
3979
  init_document_permissions_definition();
3933
3980
  init_persisted_dependencies();
3934
3981
  init_authorization_modes();
3982
+ init_proxy_diagnostics();
3935
3983
  mongooseJsonSchemaInitialized = false;
3936
3984
  ensureMongooseJsonSchemaInitialized = () => {
3937
3985
  if (mongooseJsonSchemaInitialized) return;
@@ -4286,6 +4334,13 @@ var init_runtime = __esm({
4286
4334
  this.allowGlobalModelLookup = options.allowGlobalModelLookup ?? false;
4287
4335
  ensureMongooseJsonSchemaInitialized();
4288
4336
  }
4337
+ syncProxySnapshotDiagnosticsState() {
4338
+ if (this !== defaultRuntime) return;
4339
+ syncProxySnapshotDiagnostics(
4340
+ this.globalOptions.get("authorizationSnapshotProxyLog"),
4341
+ this.globalOptions.get("logger")
4342
+ );
4343
+ }
4289
4344
  registerModelInstance(modelName, model) {
4290
4345
  if (!modelName || typeof modelName !== "string") {
4291
4346
  throw new TypeError(`registerModelInstance: modelName must be a non-empty string, received ${typeof modelName}`);
@@ -4422,6 +4477,7 @@ var init_runtime = __esm({
4422
4477
  assertNoServerModelControls(options, reject, "data-options");
4423
4478
  }
4424
4479
  this.globalOptions.restore(snapshot.globalOptions);
4480
+ this.syncProxySnapshotDiagnosticsState();
4425
4481
  this.defaultModelOptions.restore(snapshot.defaultModelOptions);
4426
4482
  for (const name of Object.keys(this.modelOptionOverrides)) delete this.modelOptionOverrides[name];
4427
4483
  for (const [name, options] of Object.entries(snapshot.modelOptionOverrides)) {
@@ -4486,6 +4542,7 @@ var init_runtime = __esm({
4486
4542
  });
4487
4543
  for (const key of populatePolicyKeys) if (key in options) assertNoGlobalPopulatePolicy(key);
4488
4544
  this.globalOptions.assign({ ...options });
4545
+ this.syncProxySnapshotDiagnosticsState();
4489
4546
  }
4490
4547
  setGlobalOption(key, value) {
4491
4548
  assertAuthorizationModeKey(key, false);
@@ -4496,6 +4553,7 @@ var init_runtime = __esm({
4496
4553
  throw new TypeError(detail);
4497
4554
  });
4498
4555
  this.globalOptions.set(key, value);
4556
+ this.syncProxySnapshotDiagnosticsState();
4499
4557
  }
4500
4558
  getGlobalOptions() {
4501
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") {
@@ -1099,7 +1176,7 @@ function copyAuthorizationValue(value, configuration = false) {
1099
1176
  }
1100
1177
  if (types5.isProxy(input)) {
1101
1178
  const error2 = new ServiceAuthorizationError("proxy snapshot input");
1102
- console.error("[access-router] Authorization snapshot rejected a Proxy", error2);
1179
+ logProxySnapshotRejection(`$${pathFrames.join("")}`, error2);
1103
1180
  throw error2;
1104
1181
  }
1105
1182
  const ownedCatalog = configuration === true ? readOwnedAuthorizationCatalogWork(input) : void 0;
@@ -1142,13 +1219,24 @@ function copyAuthorizationValue(value, configuration = false) {
1142
1219
  }
1143
1220
  if (configuration && input instanceof Map) {
1144
1221
  const result3 = /* @__PURE__ */ new Map();
1145
- for (const [key, entry] of Map.prototype.entries.call(input))
1146
- 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
+ }
1147
1231
  return result3;
1148
1232
  }
1149
1233
  if (configuration && input instanceof Set) {
1150
1234
  const result3 = /* @__PURE__ */ new Set();
1151
- 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
+ }
1152
1240
  return result3;
1153
1241
  }
1154
1242
  const array = Array.isArray(input);
@@ -1164,7 +1252,9 @@ function copyAuthorizationValue(value, configuration = false) {
1164
1252
  const descriptor = Object.getOwnPropertyDescriptor(input, key);
1165
1253
  if (!("value" in descriptor) || !descriptor.enumerable && configuration !== "document")
1166
1254
  authorizationError("accessor/non-enumerable input");
1255
+ pathFrames.push(array ? `[${key}]` : `.${key}`);
1167
1256
  const value2 = copy(descriptor.value, depth + 1);
1257
+ pathFrames.pop();
1168
1258
  if (array || definedProperty && Object.getPrototypeOf(result2) !== Object.prototype || key in result2) {
1169
1259
  definedProperty = true;
1170
1260
  Object.defineProperty(result2, key, {
@@ -1189,6 +1279,9 @@ var init_authorization_snapshot = __esm({
1189
1279
  init_field_catalog();
1190
1280
  init_trusted_output_materialization();
1191
1281
  init_output_work_ledger();
1282
+ init_logger_default();
1283
+ init_runtime_context();
1284
+ init_proxy_diagnostics();
1192
1285
  ServiceAuthorizationError = class extends JsonRouter.clientErrors.BadRequestError {
1193
1286
  constructor(detail) {
1194
1287
  const errors = [{ detail: `Service authorization: ${detail}` }];
@@ -1210,7 +1303,7 @@ var init_authorization_snapshot = __esm({
1210
1303
  });
1211
1304
 
1212
1305
  // src/acl/output-work-ledger.ts
1213
- import { AsyncLocalStorage } from "async_hooks";
1306
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
1214
1307
  function currentOutputWorkLedger() {
1215
1308
  return preparation.getStore();
1216
1309
  }
@@ -1256,7 +1349,7 @@ var preparation;
1256
1349
  var init_output_work_ledger = __esm({
1257
1350
  "src/acl/output-work-ledger.ts"() {
1258
1351
  init_authorization_snapshot();
1259
- preparation = new AsyncLocalStorage();
1352
+ preparation = new AsyncLocalStorage2();
1260
1353
  }
1261
1354
  });
1262
1355
 
@@ -1601,7 +1694,7 @@ var init_collection = __esm({
1601
1694
  });
1602
1695
 
1603
1696
  // src/helpers/concurrency.ts
1604
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
1697
+ import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
1605
1698
  var mapWithConcurrencyLimit, FifoAdmission, RequestConcurrencyScheduler, hookFrames, MAX_HOOK_DEPTH, SharedHookGate, normalizeHookConcurrencyLimit;
1606
1699
  var init_concurrency = __esm({
1607
1700
  "src/helpers/concurrency.ts"() {
@@ -1678,7 +1771,7 @@ var init_concurrency = __esm({
1678
1771
  return this.persistence.run(operation);
1679
1772
  }
1680
1773
  };
1681
- hookFrames = new AsyncLocalStorage2();
1774
+ hookFrames = new AsyncLocalStorage3();
1682
1775
  MAX_HOOK_DEPTH = 64;
1683
1776
  SharedHookGate = class {
1684
1777
  constructor(limit) {
@@ -2633,37 +2726,6 @@ var init_registry = __esm({
2633
2726
  }
2634
2727
  });
2635
2728
 
2636
- // src/logger-default.ts
2637
- import util from "util";
2638
- import { createLogger, format, transports } from "winston";
2639
- var colorizer, defaultLogLevel, inspectValue, defaultLogger;
2640
- var init_logger_default = __esm({
2641
- "src/logger-default.ts"() {
2642
- colorizer = format.colorize();
2643
- defaultLogLevel = process.env.WTT_LOG_LEVEL || "silent";
2644
- inspectValue = (value) => {
2645
- return typeof value === "string" ? value : util.inspect(value, { depth: 5, colors: false });
2646
- };
2647
- defaultLogger = createLogger({
2648
- level: defaultLogLevel,
2649
- format: format.combine(
2650
- format.errors({ stack: true }),
2651
- format.splat(),
2652
- format.label({ label: "[WTT]" }),
2653
- format.timestamp(),
2654
- format.printf(({ level, label, message, timestamp, stack, ...meta }) => {
2655
- const formattedLabel = colorizer.colorize(level, String(label));
2656
- const formattedLevel = colorizer.colorize(level, `[${String(level).toUpperCase()}]`);
2657
- const formattedMessage = colorizer.colorize(level, inspectValue(stack ?? message));
2658
- const formattedMeta = Object.keys(meta).length > 0 ? ` ${inspectValue(meta)}` : "";
2659
- return `${formattedLabel} ${timestamp} ${formattedLevel} ${formattedMessage}${formattedMeta}`;
2660
- })
2661
- ),
2662
- transports: [new transports.Console()]
2663
- });
2664
- }
2665
- });
2666
-
2667
2729
  // src/options/manager.ts
2668
2730
  import { assign, get as get3, isPlainObject as isPlainObject9, set as set2 } from "@web-ts-toolkit/utils";
2669
2731
  var toPath, cloneConfigValue, cloneForRead, freezeConfigValue, cloneAndFreezeForStore, cloneOptionsSnapshot, getNestedOption, resolveNestedOption, OptionsManager;
@@ -3389,21 +3451,6 @@ var init_virtual_descriptor = __esm({
3389
3451
  }
3390
3452
  });
3391
3453
 
3392
- // src/runtime-context.ts
3393
- import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
3394
- function runWithRuntime(runtime, callback) {
3395
- return runtimeStorage.run(runtime, callback);
3396
- }
3397
- function getActiveRuntime() {
3398
- return runtimeStorage.getStore() ?? null;
3399
- }
3400
- var runtimeStorage;
3401
- var init_runtime_context = __esm({
3402
- "src/runtime-context.ts"() {
3403
- runtimeStorage = new AsyncLocalStorage3();
3404
- }
3405
- });
3406
-
3407
3454
  // src/meta.ts
3408
3455
  var getRuntime, getModelReference;
3409
3456
  var init_meta = __esm({
@@ -3921,6 +3968,7 @@ var init_runtime = __esm({
3921
3968
  init_document_permissions_definition();
3922
3969
  init_persisted_dependencies();
3923
3970
  init_authorization_modes();
3971
+ init_proxy_diagnostics();
3924
3972
  mongooseJsonSchemaInitialized = false;
3925
3973
  ensureMongooseJsonSchemaInitialized = () => {
3926
3974
  if (mongooseJsonSchemaInitialized) return;
@@ -4275,6 +4323,13 @@ var init_runtime = __esm({
4275
4323
  this.allowGlobalModelLookup = options.allowGlobalModelLookup ?? false;
4276
4324
  ensureMongooseJsonSchemaInitialized();
4277
4325
  }
4326
+ syncProxySnapshotDiagnosticsState() {
4327
+ if (this !== defaultRuntime) return;
4328
+ syncProxySnapshotDiagnostics(
4329
+ this.globalOptions.get("authorizationSnapshotProxyLog"),
4330
+ this.globalOptions.get("logger")
4331
+ );
4332
+ }
4278
4333
  registerModelInstance(modelName, model) {
4279
4334
  if (!modelName || typeof modelName !== "string") {
4280
4335
  throw new TypeError(`registerModelInstance: modelName must be a non-empty string, received ${typeof modelName}`);
@@ -4411,6 +4466,7 @@ var init_runtime = __esm({
4411
4466
  assertNoServerModelControls(options, reject, "data-options");
4412
4467
  }
4413
4468
  this.globalOptions.restore(snapshot.globalOptions);
4469
+ this.syncProxySnapshotDiagnosticsState();
4414
4470
  this.defaultModelOptions.restore(snapshot.defaultModelOptions);
4415
4471
  for (const name of Object.keys(this.modelOptionOverrides)) delete this.modelOptionOverrides[name];
4416
4472
  for (const [name, options] of Object.entries(snapshot.modelOptionOverrides)) {
@@ -4475,6 +4531,7 @@ var init_runtime = __esm({
4475
4531
  });
4476
4532
  for (const key of populatePolicyKeys) if (key in options) assertNoGlobalPopulatePolicy(key);
4477
4533
  this.globalOptions.assign({ ...options });
4534
+ this.syncProxySnapshotDiagnosticsState();
4478
4535
  }
4479
4536
  setGlobalOption(key, value) {
4480
4537
  assertAuthorizationModeKey(key, false);
@@ -4485,6 +4542,7 @@ var init_runtime = __esm({
4485
4542
  throw new TypeError(detail);
4486
4543
  });
4487
4544
  this.globalOptions.set(key, value);
4545
+ this.syncProxySnapshotDiagnosticsState();
4488
4546
  }
4489
4547
  getGlobalOptions() {
4490
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.70.0",
5
+ "version": "0.72.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.70.0",
61
- "@web-ts-toolkit/utils": "0.70.0",
60
+ "@web-ts-toolkit/express-json-router": "0.72.0",
61
+ "@web-ts-toolkit/utils": "0.72.0",
62
62
  "just-diff": "^6.0.2",
63
63
  "mongoose-schema-jsonschema": "^4.0.1",
64
64
  "sift": "^17.1.3",