@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/README.md +28 -1
- package/advanced.d.mts +37 -37
- package/advanced.d.ts +37 -37
- package/advanced.js +99 -46
- package/advanced.mjs +94 -41
- package/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/index.js +123 -61
- package/index.mjs +116 -54
- package/package.json +3 -3
- package/{parsers-DcYjda98.d.mts → parsers-BXwV3svU.d.mts} +10 -1
- package/{parsers-DcYjda98.d.ts → parsers-BXwV3svU.d.ts} +10 -1
package/advanced.js
CHANGED
|
@@ -130,14 +130,14 @@ var import_mongoose4 = __toESM(require("mongoose"));
|
|
|
130
130
|
|
|
131
131
|
// src/validation/public-admission.ts
|
|
132
132
|
var import_express_json_router2 = __toESM(require("@web-ts-toolkit/express-json-router"));
|
|
133
|
-
var
|
|
133
|
+
var import_node_util7 = require("util");
|
|
134
134
|
var import_utils2 = require("@web-ts-toolkit/utils");
|
|
135
135
|
|
|
136
136
|
// src/acl/output-work-ledger.ts
|
|
137
|
-
var
|
|
137
|
+
var import_node_async_hooks2 = require("async_hooks");
|
|
138
138
|
|
|
139
139
|
// src/acl/authorization-snapshot.ts
|
|
140
|
-
var
|
|
140
|
+
var import_node_util5 = require("util");
|
|
141
141
|
var import_mongoose2 = require("mongoose");
|
|
142
142
|
var import_express_json_router = __toESM(require("@web-ts-toolkit/express-json-router"));
|
|
143
143
|
|
|
@@ -873,7 +873,67 @@ function materializeTrustedOutputValue(value, path, budget, policy, depth = 0, p
|
|
|
873
873
|
}
|
|
874
874
|
}
|
|
875
875
|
|
|
876
|
+
// src/logger-default.ts
|
|
877
|
+
var import_node_util4 = __toESM(require("util"));
|
|
878
|
+
var import_winston = require("winston");
|
|
879
|
+
var colorizer = import_winston.format.colorize();
|
|
880
|
+
var defaultLogLevel = process.env.WTT_LOG_LEVEL || "silent";
|
|
881
|
+
var inspectValue = (value) => {
|
|
882
|
+
return typeof value === "string" ? value : import_node_util4.default.inspect(value, { depth: 5, colors: false });
|
|
883
|
+
};
|
|
884
|
+
var defaultLogger = (0, import_winston.createLogger)({
|
|
885
|
+
level: defaultLogLevel,
|
|
886
|
+
format: import_winston.format.combine(
|
|
887
|
+
import_winston.format.errors({ stack: true }),
|
|
888
|
+
import_winston.format.splat(),
|
|
889
|
+
import_winston.format.label({ label: "[WTT]" }),
|
|
890
|
+
import_winston.format.timestamp(),
|
|
891
|
+
import_winston.format.printf(({ level, label, message, timestamp, stack, ...meta }) => {
|
|
892
|
+
const formattedLabel = colorizer.colorize(level, String(label));
|
|
893
|
+
const formattedLevel = colorizer.colorize(level, `[${String(level).toUpperCase()}]`);
|
|
894
|
+
const formattedMessage = colorizer.colorize(level, inspectValue(stack ?? message));
|
|
895
|
+
const formattedMeta = Object.keys(meta).length > 0 ? ` ${inspectValue(meta)}` : "";
|
|
896
|
+
return `${formattedLabel} ${timestamp} ${formattedLevel} ${formattedMessage}${formattedMeta}`;
|
|
897
|
+
})
|
|
898
|
+
),
|
|
899
|
+
transports: [new import_winston.transports.Console()]
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
// src/runtime-context.ts
|
|
903
|
+
var import_node_async_hooks = require("async_hooks");
|
|
904
|
+
var runtimeStorage = new import_node_async_hooks.AsyncLocalStorage();
|
|
905
|
+
function getActiveRuntime() {
|
|
906
|
+
return runtimeStorage.getStore() ?? null;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// src/acl/proxy-diagnostics.ts
|
|
910
|
+
var fallbackMode;
|
|
911
|
+
var fallbackLogger;
|
|
912
|
+
var syncProxySnapshotDiagnostics = (mode, logger) => {
|
|
913
|
+
fallbackMode = mode;
|
|
914
|
+
fallbackLogger = logger;
|
|
915
|
+
};
|
|
916
|
+
var normalizeMode = (mode) => mode === "warn" || mode === "silent" ? mode : "error";
|
|
917
|
+
var readProxySnapshotDiagnostics = (runtime) => {
|
|
918
|
+
if (runtime)
|
|
919
|
+
return {
|
|
920
|
+
mode: normalizeMode(runtime.getGlobalOption("authorizationSnapshotProxyLog")),
|
|
921
|
+
logger: runtime.getGlobalOption("logger")
|
|
922
|
+
};
|
|
923
|
+
return { mode: normalizeMode(fallbackMode), logger: fallbackLogger };
|
|
924
|
+
};
|
|
925
|
+
|
|
876
926
|
// src/acl/authorization-snapshot.ts
|
|
927
|
+
function logProxySnapshotRejection(path, error) {
|
|
928
|
+
try {
|
|
929
|
+
const { mode, logger } = readProxySnapshotDiagnostics(getActiveRuntime());
|
|
930
|
+
if (mode === "silent") return;
|
|
931
|
+
const message = `[access-router] Authorization snapshot rejected a Proxy at ${path}`;
|
|
932
|
+
const target = logger?.[mode] ?? defaultLogger[mode];
|
|
933
|
+
target.call(logger ?? defaultLogger, message, error);
|
|
934
|
+
} catch {
|
|
935
|
+
}
|
|
936
|
+
}
|
|
877
937
|
var ServiceAuthorizationError = class extends import_express_json_router.default.clientErrors.BadRequestError {
|
|
878
938
|
constructor(detail) {
|
|
879
939
|
const errors = [{ detail: `Service authorization: ${detail}` }];
|
|
@@ -903,6 +963,7 @@ function authorizationRecord(value, label) {
|
|
|
903
963
|
function copyAuthorizationValue(value, configuration = false) {
|
|
904
964
|
const active = /* @__PURE__ */ new WeakSet();
|
|
905
965
|
const budget = createTrustedOutputBudget();
|
|
966
|
+
const pathFrames = [];
|
|
906
967
|
function copy(input, depth) {
|
|
907
968
|
visitTrustedOutput(budget, depth);
|
|
908
969
|
if (typeof input === "function") {
|
|
@@ -914,7 +975,11 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
914
975
|
if (typeof input === "string") prepareTrustedOutputPayload(budget, input);
|
|
915
976
|
return input;
|
|
916
977
|
}
|
|
917
|
-
if (
|
|
978
|
+
if (import_node_util5.types.isProxy(input)) {
|
|
979
|
+
const error = new ServiceAuthorizationError("proxy snapshot input");
|
|
980
|
+
logProxySnapshotRejection(`$${pathFrames.join("")}`, error);
|
|
981
|
+
throw error;
|
|
982
|
+
}
|
|
918
983
|
const ownedCatalog = configuration === true ? readOwnedAuthorizationCatalogWork(input) : void 0;
|
|
919
984
|
if (ownedCatalog) {
|
|
920
985
|
preloadTrustedOutputBudget(budget, depth + ownedCatalog.depth, ownedCatalog.slots - 1);
|
|
@@ -955,13 +1020,24 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
955
1020
|
}
|
|
956
1021
|
if (configuration && input instanceof Map) {
|
|
957
1022
|
const result2 = /* @__PURE__ */ new Map();
|
|
958
|
-
for (const [key, entry] of Map.prototype.entries.call(input))
|
|
959
|
-
|
|
1023
|
+
for (const [key, entry] of Map.prototype.entries.call(input)) {
|
|
1024
|
+
pathFrames.push(".<map-key>");
|
|
1025
|
+
const mappedKey = copy(key, depth + 1);
|
|
1026
|
+
pathFrames.pop();
|
|
1027
|
+
pathFrames.push(".<map-value>");
|
|
1028
|
+
const mappedEntry = copy(entry, depth + 1);
|
|
1029
|
+
pathFrames.pop();
|
|
1030
|
+
result2.set(mappedKey, mappedEntry);
|
|
1031
|
+
}
|
|
960
1032
|
return result2;
|
|
961
1033
|
}
|
|
962
1034
|
if (configuration && input instanceof Set) {
|
|
963
1035
|
const result2 = /* @__PURE__ */ new Set();
|
|
964
|
-
for (const entry of Set.prototype.values.call(input))
|
|
1036
|
+
for (const entry of Set.prototype.values.call(input)) {
|
|
1037
|
+
pathFrames.push(".<set-entry>");
|
|
1038
|
+
result2.add(copy(entry, depth + 1));
|
|
1039
|
+
pathFrames.pop();
|
|
1040
|
+
}
|
|
965
1041
|
return result2;
|
|
966
1042
|
}
|
|
967
1043
|
const array = Array.isArray(input);
|
|
@@ -977,7 +1053,9 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
977
1053
|
const descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
978
1054
|
if (!("value" in descriptor) || !descriptor.enumerable && configuration !== "document")
|
|
979
1055
|
authorizationError("accessor/non-enumerable input");
|
|
1056
|
+
pathFrames.push(array ? `[${key}]` : `.${key}`);
|
|
980
1057
|
const value2 = copy(descriptor.value, depth + 1);
|
|
1058
|
+
pathFrames.pop();
|
|
981
1059
|
if (array || definedProperty && Object.getPrototypeOf(result) !== Object.prototype || key in result) {
|
|
982
1060
|
definedProperty = true;
|
|
983
1061
|
Object.defineProperty(result, key, {
|
|
@@ -998,7 +1076,7 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
998
1076
|
}
|
|
999
1077
|
|
|
1000
1078
|
// src/acl/output-work-ledger.ts
|
|
1001
|
-
var preparation = new
|
|
1079
|
+
var preparation = new import_node_async_hooks2.AsyncLocalStorage();
|
|
1002
1080
|
function currentOutputWorkLedger() {
|
|
1003
1081
|
return preparation.getStore();
|
|
1004
1082
|
}
|
|
@@ -1042,7 +1120,7 @@ function prepareOutputWorkString(parts, separator = ".", ledger = currentOutputW
|
|
|
1042
1120
|
}
|
|
1043
1121
|
|
|
1044
1122
|
// src/acl/authorization-modes.ts
|
|
1045
|
-
var
|
|
1123
|
+
var import_node_util6 = require("util");
|
|
1046
1124
|
var retiredAuthorizationOptions = [
|
|
1047
1125
|
"unsafeSkipListDocumentSnapshotChecks",
|
|
1048
1126
|
"unsafeSkipReadDocumentSnapshotChecks",
|
|
@@ -1091,7 +1169,7 @@ function assertAuthorizationModeKey(key, model) {
|
|
|
1091
1169
|
function admitControlPrototypes(value, reject) {
|
|
1092
1170
|
const owners = [];
|
|
1093
1171
|
for (let owner = value; owner; owner = Object.getPrototypeOf(owner)) {
|
|
1094
|
-
if (
|
|
1172
|
+
if (import_node_util6.types.isProxy(owner)) reject("Proxy control/configuration prototype is unsupported");
|
|
1095
1173
|
if (owners.length > 100) reject("Control/configuration prototype depth exceeded");
|
|
1096
1174
|
owners.push(owner);
|
|
1097
1175
|
}
|
|
@@ -1224,7 +1302,7 @@ function walkControlAdmission(input, kind, check, reject) {
|
|
|
1224
1302
|
const { value, kind: slot, path, depth } = pending.pop();
|
|
1225
1303
|
if (!value || typeof value !== "object" && typeof value !== "function") continue;
|
|
1226
1304
|
if (typeof value === "function" && (slot === "policy" || slot === "data")) continue;
|
|
1227
|
-
if (
|
|
1305
|
+
if (import_node_util7.types.isProxy(value)) reject(`unsupported proxy in control admission: ${path}`);
|
|
1228
1306
|
const owners = admitControlPrototypes(value, reject);
|
|
1229
1307
|
const kinds = seen.get(value) ?? /* @__PURE__ */ new Set();
|
|
1230
1308
|
if (kinds.has(slot)) continue;
|
|
@@ -1798,32 +1876,6 @@ var OpenApiRegistry = class {
|
|
|
1798
1876
|
}
|
|
1799
1877
|
};
|
|
1800
1878
|
|
|
1801
|
-
// src/logger-default.ts
|
|
1802
|
-
var import_node_util7 = __toESM(require("util"));
|
|
1803
|
-
var import_winston = require("winston");
|
|
1804
|
-
var colorizer = import_winston.format.colorize();
|
|
1805
|
-
var defaultLogLevel = process.env.WTT_LOG_LEVEL || "silent";
|
|
1806
|
-
var inspectValue = (value) => {
|
|
1807
|
-
return typeof value === "string" ? value : import_node_util7.default.inspect(value, { depth: 5, colors: false });
|
|
1808
|
-
};
|
|
1809
|
-
var defaultLogger = (0, import_winston.createLogger)({
|
|
1810
|
-
level: defaultLogLevel,
|
|
1811
|
-
format: import_winston.format.combine(
|
|
1812
|
-
import_winston.format.errors({ stack: true }),
|
|
1813
|
-
import_winston.format.splat(),
|
|
1814
|
-
import_winston.format.label({ label: "[WTT]" }),
|
|
1815
|
-
import_winston.format.timestamp(),
|
|
1816
|
-
import_winston.format.printf(({ level, label, message, timestamp, stack, ...meta }) => {
|
|
1817
|
-
const formattedLabel = colorizer.colorize(level, String(label));
|
|
1818
|
-
const formattedLevel = colorizer.colorize(level, `[${String(level).toUpperCase()}]`);
|
|
1819
|
-
const formattedMessage = colorizer.colorize(level, inspectValue(stack ?? message));
|
|
1820
|
-
const formattedMeta = Object.keys(meta).length > 0 ? ` ${inspectValue(meta)}` : "";
|
|
1821
|
-
return `${formattedLabel} ${timestamp} ${formattedLevel} ${formattedMessage}${formattedMeta}`;
|
|
1822
|
-
})
|
|
1823
|
-
),
|
|
1824
|
-
transports: [new import_winston.transports.Console()]
|
|
1825
|
-
});
|
|
1826
|
-
|
|
1827
1879
|
// src/options/manager.ts
|
|
1828
1880
|
var import_utils8 = require("@web-ts-toolkit/utils");
|
|
1829
1881
|
var toPath = (key) => {
|
|
@@ -2517,15 +2569,6 @@ var import_utils13 = require("@web-ts-toolkit/utils");
|
|
|
2517
2569
|
|
|
2518
2570
|
// src/acl/populate-target-configuration.ts
|
|
2519
2571
|
var import_utils12 = require("@web-ts-toolkit/utils");
|
|
2520
|
-
|
|
2521
|
-
// src/runtime-context.ts
|
|
2522
|
-
var import_node_async_hooks2 = require("async_hooks");
|
|
2523
|
-
var runtimeStorage = new import_node_async_hooks2.AsyncLocalStorage();
|
|
2524
|
-
function getActiveRuntime() {
|
|
2525
|
-
return runtimeStorage.getStore() ?? null;
|
|
2526
|
-
}
|
|
2527
|
-
|
|
2528
|
-
// src/acl/populate-target-configuration.ts
|
|
2529
2572
|
function capturePopulateTargetConfiguration(runtime, modelName, source, proposedOptions, defaults2 = runtime.getDefaultModelOptions()) {
|
|
2530
2573
|
const label = `Populate target "${modelName}" for ${source}`;
|
|
2531
2574
|
if (!proposedOptions && !runtime.hasModel(modelName))
|
|
@@ -3245,6 +3288,13 @@ var AccessRuntime = class {
|
|
|
3245
3288
|
this.allowGlobalModelLookup = options.allowGlobalModelLookup ?? false;
|
|
3246
3289
|
ensureMongooseJsonSchemaInitialized();
|
|
3247
3290
|
}
|
|
3291
|
+
syncProxySnapshotDiagnosticsState() {
|
|
3292
|
+
if (this !== defaultRuntime) return;
|
|
3293
|
+
syncProxySnapshotDiagnostics(
|
|
3294
|
+
this.globalOptions.get("authorizationSnapshotProxyLog"),
|
|
3295
|
+
this.globalOptions.get("logger")
|
|
3296
|
+
);
|
|
3297
|
+
}
|
|
3248
3298
|
registerModelInstance(modelName, model) {
|
|
3249
3299
|
if (!modelName || typeof modelName !== "string") {
|
|
3250
3300
|
throw new TypeError(`registerModelInstance: modelName must be a non-empty string, received ${typeof modelName}`);
|
|
@@ -3381,6 +3431,7 @@ var AccessRuntime = class {
|
|
|
3381
3431
|
assertNoServerModelControls(options, reject, "data-options");
|
|
3382
3432
|
}
|
|
3383
3433
|
this.globalOptions.restore(snapshot.globalOptions);
|
|
3434
|
+
this.syncProxySnapshotDiagnosticsState();
|
|
3384
3435
|
this.defaultModelOptions.restore(snapshot.defaultModelOptions);
|
|
3385
3436
|
for (const name of Object.keys(this.modelOptionOverrides)) delete this.modelOptionOverrides[name];
|
|
3386
3437
|
for (const [name, options] of Object.entries(snapshot.modelOptionOverrides)) {
|
|
@@ -3445,6 +3496,7 @@ var AccessRuntime = class {
|
|
|
3445
3496
|
});
|
|
3446
3497
|
for (const key of populatePolicyKeys) if (key in options) assertNoGlobalPopulatePolicy(key);
|
|
3447
3498
|
this.globalOptions.assign({ ...options });
|
|
3499
|
+
this.syncProxySnapshotDiagnosticsState();
|
|
3448
3500
|
}
|
|
3449
3501
|
setGlobalOption(key, value) {
|
|
3450
3502
|
assertAuthorizationModeKey(key, false);
|
|
@@ -3455,6 +3507,7 @@ var AccessRuntime = class {
|
|
|
3455
3507
|
throw new TypeError(detail);
|
|
3456
3508
|
});
|
|
3457
3509
|
this.globalOptions.set(key, value);
|
|
3510
|
+
this.syncProxySnapshotDiagnosticsState();
|
|
3458
3511
|
}
|
|
3459
3512
|
getGlobalOptions() {
|
|
3460
3513
|
return this.globalOptions.fetch();
|
package/advanced.mjs
CHANGED
|
@@ -52,7 +52,7 @@ import { types as types6 } from "util";
|
|
|
52
52
|
import { isPlainObject } from "@web-ts-toolkit/utils";
|
|
53
53
|
|
|
54
54
|
// src/acl/output-work-ledger.ts
|
|
55
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
55
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
56
56
|
|
|
57
57
|
// src/acl/authorization-snapshot.ts
|
|
58
58
|
import { types as types4 } from "util";
|
|
@@ -791,7 +791,67 @@ function materializeTrustedOutputValue(value, path, budget, policy, depth = 0, p
|
|
|
791
791
|
}
|
|
792
792
|
}
|
|
793
793
|
|
|
794
|
+
// src/logger-default.ts
|
|
795
|
+
import util from "util";
|
|
796
|
+
import { createLogger, format, transports } from "winston";
|
|
797
|
+
var colorizer = format.colorize();
|
|
798
|
+
var defaultLogLevel = process.env.WTT_LOG_LEVEL || "silent";
|
|
799
|
+
var inspectValue = (value) => {
|
|
800
|
+
return typeof value === "string" ? value : util.inspect(value, { depth: 5, colors: false });
|
|
801
|
+
};
|
|
802
|
+
var defaultLogger = createLogger({
|
|
803
|
+
level: defaultLogLevel,
|
|
804
|
+
format: format.combine(
|
|
805
|
+
format.errors({ stack: true }),
|
|
806
|
+
format.splat(),
|
|
807
|
+
format.label({ label: "[WTT]" }),
|
|
808
|
+
format.timestamp(),
|
|
809
|
+
format.printf(({ level, label, message, timestamp, stack, ...meta }) => {
|
|
810
|
+
const formattedLabel = colorizer.colorize(level, String(label));
|
|
811
|
+
const formattedLevel = colorizer.colorize(level, `[${String(level).toUpperCase()}]`);
|
|
812
|
+
const formattedMessage = colorizer.colorize(level, inspectValue(stack ?? message));
|
|
813
|
+
const formattedMeta = Object.keys(meta).length > 0 ? ` ${inspectValue(meta)}` : "";
|
|
814
|
+
return `${formattedLabel} ${timestamp} ${formattedLevel} ${formattedMessage}${formattedMeta}`;
|
|
815
|
+
})
|
|
816
|
+
),
|
|
817
|
+
transports: [new transports.Console()]
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
// src/runtime-context.ts
|
|
821
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
822
|
+
var runtimeStorage = new AsyncLocalStorage();
|
|
823
|
+
function getActiveRuntime() {
|
|
824
|
+
return runtimeStorage.getStore() ?? null;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// src/acl/proxy-diagnostics.ts
|
|
828
|
+
var fallbackMode;
|
|
829
|
+
var fallbackLogger;
|
|
830
|
+
var syncProxySnapshotDiagnostics = (mode, logger) => {
|
|
831
|
+
fallbackMode = mode;
|
|
832
|
+
fallbackLogger = logger;
|
|
833
|
+
};
|
|
834
|
+
var normalizeMode = (mode) => mode === "warn" || mode === "silent" ? mode : "error";
|
|
835
|
+
var readProxySnapshotDiagnostics = (runtime) => {
|
|
836
|
+
if (runtime)
|
|
837
|
+
return {
|
|
838
|
+
mode: normalizeMode(runtime.getGlobalOption("authorizationSnapshotProxyLog")),
|
|
839
|
+
logger: runtime.getGlobalOption("logger")
|
|
840
|
+
};
|
|
841
|
+
return { mode: normalizeMode(fallbackMode), logger: fallbackLogger };
|
|
842
|
+
};
|
|
843
|
+
|
|
794
844
|
// src/acl/authorization-snapshot.ts
|
|
845
|
+
function logProxySnapshotRejection(path, error) {
|
|
846
|
+
try {
|
|
847
|
+
const { mode, logger } = readProxySnapshotDiagnostics(getActiveRuntime());
|
|
848
|
+
if (mode === "silent") return;
|
|
849
|
+
const message = `[access-router] Authorization snapshot rejected a Proxy at ${path}`;
|
|
850
|
+
const target = logger?.[mode] ?? defaultLogger[mode];
|
|
851
|
+
target.call(logger ?? defaultLogger, message, error);
|
|
852
|
+
} catch {
|
|
853
|
+
}
|
|
854
|
+
}
|
|
795
855
|
var ServiceAuthorizationError = class extends JsonRouter.clientErrors.BadRequestError {
|
|
796
856
|
constructor(detail) {
|
|
797
857
|
const errors = [{ detail: `Service authorization: ${detail}` }];
|
|
@@ -821,6 +881,7 @@ function authorizationRecord(value, label) {
|
|
|
821
881
|
function copyAuthorizationValue(value, configuration = false) {
|
|
822
882
|
const active = /* @__PURE__ */ new WeakSet();
|
|
823
883
|
const budget = createTrustedOutputBudget();
|
|
884
|
+
const pathFrames = [];
|
|
824
885
|
function copy(input, depth) {
|
|
825
886
|
visitTrustedOutput(budget, depth);
|
|
826
887
|
if (typeof input === "function") {
|
|
@@ -832,7 +893,11 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
832
893
|
if (typeof input === "string") prepareTrustedOutputPayload(budget, input);
|
|
833
894
|
return input;
|
|
834
895
|
}
|
|
835
|
-
if (types4.isProxy(input))
|
|
896
|
+
if (types4.isProxy(input)) {
|
|
897
|
+
const error = new ServiceAuthorizationError("proxy snapshot input");
|
|
898
|
+
logProxySnapshotRejection(`$${pathFrames.join("")}`, error);
|
|
899
|
+
throw error;
|
|
900
|
+
}
|
|
836
901
|
const ownedCatalog = configuration === true ? readOwnedAuthorizationCatalogWork(input) : void 0;
|
|
837
902
|
if (ownedCatalog) {
|
|
838
903
|
preloadTrustedOutputBudget(budget, depth + ownedCatalog.depth, ownedCatalog.slots - 1);
|
|
@@ -873,13 +938,24 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
873
938
|
}
|
|
874
939
|
if (configuration && input instanceof Map) {
|
|
875
940
|
const result2 = /* @__PURE__ */ new Map();
|
|
876
|
-
for (const [key, entry] of Map.prototype.entries.call(input))
|
|
877
|
-
|
|
941
|
+
for (const [key, entry] of Map.prototype.entries.call(input)) {
|
|
942
|
+
pathFrames.push(".<map-key>");
|
|
943
|
+
const mappedKey = copy(key, depth + 1);
|
|
944
|
+
pathFrames.pop();
|
|
945
|
+
pathFrames.push(".<map-value>");
|
|
946
|
+
const mappedEntry = copy(entry, depth + 1);
|
|
947
|
+
pathFrames.pop();
|
|
948
|
+
result2.set(mappedKey, mappedEntry);
|
|
949
|
+
}
|
|
878
950
|
return result2;
|
|
879
951
|
}
|
|
880
952
|
if (configuration && input instanceof Set) {
|
|
881
953
|
const result2 = /* @__PURE__ */ new Set();
|
|
882
|
-
for (const entry of Set.prototype.values.call(input))
|
|
954
|
+
for (const entry of Set.prototype.values.call(input)) {
|
|
955
|
+
pathFrames.push(".<set-entry>");
|
|
956
|
+
result2.add(copy(entry, depth + 1));
|
|
957
|
+
pathFrames.pop();
|
|
958
|
+
}
|
|
883
959
|
return result2;
|
|
884
960
|
}
|
|
885
961
|
const array = Array.isArray(input);
|
|
@@ -895,7 +971,9 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
895
971
|
const descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
896
972
|
if (!("value" in descriptor) || !descriptor.enumerable && configuration !== "document")
|
|
897
973
|
authorizationError("accessor/non-enumerable input");
|
|
974
|
+
pathFrames.push(array ? `[${key}]` : `.${key}`);
|
|
898
975
|
const value2 = copy(descriptor.value, depth + 1);
|
|
976
|
+
pathFrames.pop();
|
|
899
977
|
if (array || definedProperty && Object.getPrototypeOf(result) !== Object.prototype || key in result) {
|
|
900
978
|
definedProperty = true;
|
|
901
979
|
Object.defineProperty(result, key, {
|
|
@@ -916,7 +994,7 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
916
994
|
}
|
|
917
995
|
|
|
918
996
|
// src/acl/output-work-ledger.ts
|
|
919
|
-
var preparation = new
|
|
997
|
+
var preparation = new AsyncLocalStorage2();
|
|
920
998
|
function currentOutputWorkLedger() {
|
|
921
999
|
return preparation.getStore();
|
|
922
1000
|
}
|
|
@@ -1729,32 +1807,6 @@ var OpenApiRegistry = class {
|
|
|
1729
1807
|
}
|
|
1730
1808
|
};
|
|
1731
1809
|
|
|
1732
|
-
// src/logger-default.ts
|
|
1733
|
-
import util from "util";
|
|
1734
|
-
import { createLogger, format, transports } from "winston";
|
|
1735
|
-
var colorizer = format.colorize();
|
|
1736
|
-
var defaultLogLevel = process.env.WTT_LOG_LEVEL || "silent";
|
|
1737
|
-
var inspectValue = (value) => {
|
|
1738
|
-
return typeof value === "string" ? value : util.inspect(value, { depth: 5, colors: false });
|
|
1739
|
-
};
|
|
1740
|
-
var defaultLogger = createLogger({
|
|
1741
|
-
level: defaultLogLevel,
|
|
1742
|
-
format: format.combine(
|
|
1743
|
-
format.errors({ stack: true }),
|
|
1744
|
-
format.splat(),
|
|
1745
|
-
format.label({ label: "[WTT]" }),
|
|
1746
|
-
format.timestamp(),
|
|
1747
|
-
format.printf(({ level, label, message, timestamp, stack, ...meta }) => {
|
|
1748
|
-
const formattedLabel = colorizer.colorize(level, String(label));
|
|
1749
|
-
const formattedLevel = colorizer.colorize(level, `[${String(level).toUpperCase()}]`);
|
|
1750
|
-
const formattedMessage = colorizer.colorize(level, inspectValue(stack ?? message));
|
|
1751
|
-
const formattedMeta = Object.keys(meta).length > 0 ? ` ${inspectValue(meta)}` : "";
|
|
1752
|
-
return `${formattedLabel} ${timestamp} ${formattedLevel} ${formattedMessage}${formattedMeta}`;
|
|
1753
|
-
})
|
|
1754
|
-
),
|
|
1755
|
-
transports: [new transports.Console()]
|
|
1756
|
-
});
|
|
1757
|
-
|
|
1758
1810
|
// src/options/manager.ts
|
|
1759
1811
|
import { assign, get as get2, isPlainObject as isPlainObject8, set } from "@web-ts-toolkit/utils";
|
|
1760
1812
|
var toPath = (key) => {
|
|
@@ -2448,15 +2500,6 @@ import { get as get3, isPlainObject as isPlainObject12 } from "@web-ts-toolkit/u
|
|
|
2448
2500
|
|
|
2449
2501
|
// src/acl/populate-target-configuration.ts
|
|
2450
2502
|
import { isPlainObject as isPlainObject11 } from "@web-ts-toolkit/utils";
|
|
2451
|
-
|
|
2452
|
-
// src/runtime-context.ts
|
|
2453
|
-
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
2454
|
-
var runtimeStorage = new AsyncLocalStorage2();
|
|
2455
|
-
function getActiveRuntime() {
|
|
2456
|
-
return runtimeStorage.getStore() ?? null;
|
|
2457
|
-
}
|
|
2458
|
-
|
|
2459
|
-
// src/acl/populate-target-configuration.ts
|
|
2460
2503
|
function capturePopulateTargetConfiguration(runtime, modelName, source, proposedOptions, defaults2 = runtime.getDefaultModelOptions()) {
|
|
2461
2504
|
const label = `Populate target "${modelName}" for ${source}`;
|
|
2462
2505
|
if (!proposedOptions && !runtime.hasModel(modelName))
|
|
@@ -3176,6 +3219,13 @@ var AccessRuntime = class {
|
|
|
3176
3219
|
this.allowGlobalModelLookup = options.allowGlobalModelLookup ?? false;
|
|
3177
3220
|
ensureMongooseJsonSchemaInitialized();
|
|
3178
3221
|
}
|
|
3222
|
+
syncProxySnapshotDiagnosticsState() {
|
|
3223
|
+
if (this !== defaultRuntime) return;
|
|
3224
|
+
syncProxySnapshotDiagnostics(
|
|
3225
|
+
this.globalOptions.get("authorizationSnapshotProxyLog"),
|
|
3226
|
+
this.globalOptions.get("logger")
|
|
3227
|
+
);
|
|
3228
|
+
}
|
|
3179
3229
|
registerModelInstance(modelName, model) {
|
|
3180
3230
|
if (!modelName || typeof modelName !== "string") {
|
|
3181
3231
|
throw new TypeError(`registerModelInstance: modelName must be a non-empty string, received ${typeof modelName}`);
|
|
@@ -3312,6 +3362,7 @@ var AccessRuntime = class {
|
|
|
3312
3362
|
assertNoServerModelControls(options, reject, "data-options");
|
|
3313
3363
|
}
|
|
3314
3364
|
this.globalOptions.restore(snapshot.globalOptions);
|
|
3365
|
+
this.syncProxySnapshotDiagnosticsState();
|
|
3315
3366
|
this.defaultModelOptions.restore(snapshot.defaultModelOptions);
|
|
3316
3367
|
for (const name of Object.keys(this.modelOptionOverrides)) delete this.modelOptionOverrides[name];
|
|
3317
3368
|
for (const [name, options] of Object.entries(snapshot.modelOptionOverrides)) {
|
|
@@ -3376,6 +3427,7 @@ var AccessRuntime = class {
|
|
|
3376
3427
|
});
|
|
3377
3428
|
for (const key of populatePolicyKeys) if (key in options) assertNoGlobalPopulatePolicy(key);
|
|
3378
3429
|
this.globalOptions.assign({ ...options });
|
|
3430
|
+
this.syncProxySnapshotDiagnosticsState();
|
|
3379
3431
|
}
|
|
3380
3432
|
setGlobalOption(key, value) {
|
|
3381
3433
|
assertAuthorizationModeKey(key, false);
|
|
@@ -3386,6 +3438,7 @@ var AccessRuntime = class {
|
|
|
3386
3438
|
throw new TypeError(detail);
|
|
3387
3439
|
});
|
|
3388
3440
|
this.globalOptions.set(key, value);
|
|
3441
|
+
this.syncProxySnapshotDiagnosticsState();
|
|
3389
3442
|
}
|
|
3390
3443
|
getGlobalOptions() {
|
|
3391
3444
|
return this.globalOptions.fetch();
|
package/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose__default, { Schema } from 'mongoose';
|
|
2
2
|
import { Response, NextFunction, RequestHandler, Router } from 'express';
|
|
3
|
-
import { A as AccessRouterBaseRequest,
|
|
4
|
-
export {
|
|
3
|
+
import { A as AccessRouterBaseRequest, av as GuardHook, b2 as ModelRequest, e4 as AccessRuntime, a0 as DataRouterOptions, _ as DataRequest, e5 as DataService, ac as ExtendedDataRouterOptions, bn as OperationAccessSetter, aj as Filter, bE as Projection, cK as Sort, bA as Populate, b3 as ModelRouterOptions, e6 as Service, e7 as PublicService, be as ModelVirtualRecordAccess, b8 as ModelVirtualDescriptor, ba as ModelVirtualGetter, bb as ModelVirtualLeaf, ae as ExtendedModelRouterOptions, aQ as ModelDocPermissionsDefinition, dH as Validation, cv as RootRouterOptions, e8 as OpenApiRouterOptions, e9 as OpenApiRegistryOptions, ea as OpenApiRouteDescriptor, eb as OpenApiDocumentOptions, ec as OpenApiParameter, ed as OpenApiSchema, ee as OpenApiResponses, at as GlobalOptions, a4 as DefaultModelRouterOptions, ad as ExtendedDefaultModelRouterOptions } from './parsers-BXwV3svU.mjs';
|
|
4
|
+
export { ef as AccessRouterPermissionMap, eg as AccessRouterPermissions, c as AccessRouterRequest, d as AccessRouterRequestExtensions, l as AjvErrorObjectLike, n as AjvValidatorLike, o as AllowedOutputFieldOptions, p as ArkTypeErrorsLike, q as ArkTypeLike, s as AuthorizationMode, u as AuthorizedListResult, v as AuthorizedSingleResult, J as CreateAuthorization, P as DataFieldOptions, a9 as DocumentGrants, af as FieldAuthorization, ag as FieldOperationAccess, ah as FieldPermissionHook, ai as FieldValidation, al as FilteredOutput, au as GlobalPermissionValue, aw as HydrationMode, az as InputFieldAuthorization, aA as InputFieldPath, aB as IoTsContextEntryLike, aC as IoTsDecodeErrorLike, aD as IoTsDecoderLike, aE as JoiSchemaLike, aF as JoiValidationErrorDetailLike, aL as MaybePromise, aM as ModelBaseFilterHook, aO as ModelDeleteHook, aP as ModelDocPermissionsAccessRecord, aR as ModelDocPermissionsDescriptor, aS as ModelDocPermissionsHook, aU as ModelDocumentHook, aV as ModelHook, aX as ModelHydrationOptions, aY as ModelIdentifierHook, aZ as ModelListHook, a_ as ModelOutputContext, a$ as ModelOutputHook, b0 as ModelOutputListHook, b1 as ModelOverrideFilterHook, b4 as ModelValidateHook, b5 as ModelVirtualAccess, b6 as ModelVirtualAccessRecord, b7 as ModelVirtualContext, b9 as ModelVirtualDoc, bc as ModelVirtualPopulateDependency, bd as ModelVirtualPopulateInputs, bf as ModelVirtuals, bg as MutationAuthorization, bh as NewArgs, bi as NewOptions, eh as OpenApiMethod, bj as OperationAccess, bk as OperationAccessContext, bl as OperationAccessPaths, bm as OperationAccessRule, bo as OperationAccessVariants, bp as OperationAuthorization, bq as OutputAuthorization, br as OutputFieldOptions, bs as OutputFieldPath, bt as OutputPlanningOptions, bw as PairedRouteAccess, bz as PermissionSchema, ei as Permissions, bC as PopulatePlanningOptions, bQ as PublicSubdocumentCreateOptions, bR as PublicSubdocumentListOptions, bS as PublicSubdocumentMutationOptions, bT as PublicSubdocumentReadOptions, bZ as RelatedAuthorization, b$ as RequestSchemaAdapter, c0 as RequestSchemaFailure, c1 as RequestSchemaIssue, c2 as RequestSchemaLike, c3 as RequestSchemaOptions, c4 as RequestSchemaResult, c5 as RequestSchemaSuccess, c6 as RequestSchemaValidator, cy as RouteBaseAccess, cz as RouteGuardAccess, cA as RouteVariant, cB as RowAuthorization, cF as ServiceAuthorization, cG as ServiceOutputContext, cH as ServiceOutputDecorator, cM as StandardSchemaFailure, cN as StandardSchemaInferOutput, cO as StandardSchemaIssue, cP as StandardSchemaPathSegment, cQ as StandardSchemaResult, cR as StandardSchemaSuccess, cS as StandardSchemaV1, cV as SubOperationAccess, cZ as SubRouteGuardOptions, d0 as SubdocumentCreateAuthorization, d2 as SubdocumentCreateOptions, d3 as SubdocumentCreateVisibilityAuthorization, d4 as SubdocumentDeleteAuthorization, d5 as SubdocumentDeleteOptions, d6 as SubdocumentGateAuthorization, d8 as SubdocumentInputAuthorization, d9 as SubdocumentListOptions, da as SubdocumentModel, db as SubdocumentMutationAuthorization, dc as SubdocumentName, dd as SubdocumentOutputAuthorization, dg as SubdocumentReadAuthorization, dh as SubdocumentReadOptions, dj as SubdocumentUpdateOptions, dk as SubdocumentVirtuals, dl as SubdocumentVisibilityAuthorization, dm as SuperstructFailureLike, dn as SuperstructValidateLike, dB as ValibotIssueLike, dC as ValibotPathItemLike, dD as ValibotSafeParseLike, dE as ValibotSafeParseResult, dJ as VineValidationErrorLike, dK as VineValidationMessageLike, dL as VineValidatorLike, dM as VirtualSubModel, dN as WithVirtuals, dO as YupSchemaLike, dP as YupValidationErrorLike, ej as defaultRuntime, dQ as defineRequestSchema, dR as fromAjv, dS as fromArkType, dT as fromIoTs, dU as fromJoi, dV as fromStandardSchema, dW as fromSuperstruct, dX as fromValibot, dY as fromVine, dZ as fromYup, d_ as fromZod } from './parsers-BXwV3svU.mjs';
|
|
5
5
|
import JsonRouter from '@web-ts-toolkit/express-json-router';
|
|
6
6
|
import 'zod';
|
|
7
7
|
import 'node:buffer';
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose__default, { Schema } from 'mongoose';
|
|
2
2
|
import { Response, NextFunction, RequestHandler, Router } from 'express';
|
|
3
|
-
import { A as AccessRouterBaseRequest,
|
|
4
|
-
export {
|
|
3
|
+
import { A as AccessRouterBaseRequest, av as GuardHook, b2 as ModelRequest, e4 as AccessRuntime, a0 as DataRouterOptions, _ as DataRequest, e5 as DataService, ac as ExtendedDataRouterOptions, bn as OperationAccessSetter, aj as Filter, bE as Projection, cK as Sort, bA as Populate, b3 as ModelRouterOptions, e6 as Service, e7 as PublicService, be as ModelVirtualRecordAccess, b8 as ModelVirtualDescriptor, ba as ModelVirtualGetter, bb as ModelVirtualLeaf, ae as ExtendedModelRouterOptions, aQ as ModelDocPermissionsDefinition, dH as Validation, cv as RootRouterOptions, e8 as OpenApiRouterOptions, e9 as OpenApiRegistryOptions, ea as OpenApiRouteDescriptor, eb as OpenApiDocumentOptions, ec as OpenApiParameter, ed as OpenApiSchema, ee as OpenApiResponses, at as GlobalOptions, a4 as DefaultModelRouterOptions, ad as ExtendedDefaultModelRouterOptions } from './parsers-BXwV3svU.js';
|
|
4
|
+
export { ef as AccessRouterPermissionMap, eg as AccessRouterPermissions, c as AccessRouterRequest, d as AccessRouterRequestExtensions, l as AjvErrorObjectLike, n as AjvValidatorLike, o as AllowedOutputFieldOptions, p as ArkTypeErrorsLike, q as ArkTypeLike, s as AuthorizationMode, u as AuthorizedListResult, v as AuthorizedSingleResult, J as CreateAuthorization, P as DataFieldOptions, a9 as DocumentGrants, af as FieldAuthorization, ag as FieldOperationAccess, ah as FieldPermissionHook, ai as FieldValidation, al as FilteredOutput, au as GlobalPermissionValue, aw as HydrationMode, az as InputFieldAuthorization, aA as InputFieldPath, aB as IoTsContextEntryLike, aC as IoTsDecodeErrorLike, aD as IoTsDecoderLike, aE as JoiSchemaLike, aF as JoiValidationErrorDetailLike, aL as MaybePromise, aM as ModelBaseFilterHook, aO as ModelDeleteHook, aP as ModelDocPermissionsAccessRecord, aR as ModelDocPermissionsDescriptor, aS as ModelDocPermissionsHook, aU as ModelDocumentHook, aV as ModelHook, aX as ModelHydrationOptions, aY as ModelIdentifierHook, aZ as ModelListHook, a_ as ModelOutputContext, a$ as ModelOutputHook, b0 as ModelOutputListHook, b1 as ModelOverrideFilterHook, b4 as ModelValidateHook, b5 as ModelVirtualAccess, b6 as ModelVirtualAccessRecord, b7 as ModelVirtualContext, b9 as ModelVirtualDoc, bc as ModelVirtualPopulateDependency, bd as ModelVirtualPopulateInputs, bf as ModelVirtuals, bg as MutationAuthorization, bh as NewArgs, bi as NewOptions, eh as OpenApiMethod, bj as OperationAccess, bk as OperationAccessContext, bl as OperationAccessPaths, bm as OperationAccessRule, bo as OperationAccessVariants, bp as OperationAuthorization, bq as OutputAuthorization, br as OutputFieldOptions, bs as OutputFieldPath, bt as OutputPlanningOptions, bw as PairedRouteAccess, bz as PermissionSchema, ei as Permissions, bC as PopulatePlanningOptions, bQ as PublicSubdocumentCreateOptions, bR as PublicSubdocumentListOptions, bS as PublicSubdocumentMutationOptions, bT as PublicSubdocumentReadOptions, bZ as RelatedAuthorization, b$ as RequestSchemaAdapter, c0 as RequestSchemaFailure, c1 as RequestSchemaIssue, c2 as RequestSchemaLike, c3 as RequestSchemaOptions, c4 as RequestSchemaResult, c5 as RequestSchemaSuccess, c6 as RequestSchemaValidator, cy as RouteBaseAccess, cz as RouteGuardAccess, cA as RouteVariant, cB as RowAuthorization, cF as ServiceAuthorization, cG as ServiceOutputContext, cH as ServiceOutputDecorator, cM as StandardSchemaFailure, cN as StandardSchemaInferOutput, cO as StandardSchemaIssue, cP as StandardSchemaPathSegment, cQ as StandardSchemaResult, cR as StandardSchemaSuccess, cS as StandardSchemaV1, cV as SubOperationAccess, cZ as SubRouteGuardOptions, d0 as SubdocumentCreateAuthorization, d2 as SubdocumentCreateOptions, d3 as SubdocumentCreateVisibilityAuthorization, d4 as SubdocumentDeleteAuthorization, d5 as SubdocumentDeleteOptions, d6 as SubdocumentGateAuthorization, d8 as SubdocumentInputAuthorization, d9 as SubdocumentListOptions, da as SubdocumentModel, db as SubdocumentMutationAuthorization, dc as SubdocumentName, dd as SubdocumentOutputAuthorization, dg as SubdocumentReadAuthorization, dh as SubdocumentReadOptions, dj as SubdocumentUpdateOptions, dk as SubdocumentVirtuals, dl as SubdocumentVisibilityAuthorization, dm as SuperstructFailureLike, dn as SuperstructValidateLike, dB as ValibotIssueLike, dC as ValibotPathItemLike, dD as ValibotSafeParseLike, dE as ValibotSafeParseResult, dJ as VineValidationErrorLike, dK as VineValidationMessageLike, dL as VineValidatorLike, dM as VirtualSubModel, dN as WithVirtuals, dO as YupSchemaLike, dP as YupValidationErrorLike, ej as defaultRuntime, dQ as defineRequestSchema, dR as fromAjv, dS as fromArkType, dT as fromIoTs, dU as fromJoi, dV as fromStandardSchema, dW as fromSuperstruct, dX as fromValibot, dY as fromVine, dZ as fromYup, d_ as fromZod } from './parsers-BXwV3svU.js';
|
|
5
5
|
import JsonRouter from '@web-ts-toolkit/express-json-router';
|
|
6
6
|
import 'zod';
|
|
7
7
|
import 'node:buffer';
|