@web-ts-toolkit/access-router 0.62.0 → 0.63.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/advanced.js +12 -6
- package/advanced.mjs +12 -6
- package/index.js +78 -35
- package/index.mjs +68 -25
- package/package.json +3 -3
package/advanced.js
CHANGED
|
@@ -1346,6 +1346,7 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
1346
1346
|
if (array && input.length > 2e4) authorizationError("snapshot array exceeds structural limits");
|
|
1347
1347
|
if (!array) authorizationRecord(input, "snapshot");
|
|
1348
1348
|
const result = array ? [] : {};
|
|
1349
|
+
let definedProperty = false;
|
|
1349
1350
|
for (const key of Reflect.ownKeys(input)) {
|
|
1350
1351
|
if (array && key === "length") continue;
|
|
1351
1352
|
if (typeof key !== "string" || unsafeKeys.has(key)) authorizationError("unsafe snapshot key");
|
|
@@ -1353,12 +1354,16 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
1353
1354
|
const descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
1354
1355
|
if (!("value" in descriptor) || !descriptor.enumerable && configuration !== "document")
|
|
1355
1356
|
authorizationError("accessor/non-enumerable input");
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1357
|
+
const value2 = copy(descriptor.value, depth + 1);
|
|
1358
|
+
if (array || definedProperty && Object.getPrototypeOf(result) !== Object.prototype || key in result) {
|
|
1359
|
+
definedProperty = true;
|
|
1360
|
+
Object.defineProperty(result, key, {
|
|
1361
|
+
value: value2,
|
|
1362
|
+
enumerable: true,
|
|
1363
|
+
writable: true,
|
|
1364
|
+
configurable: true
|
|
1365
|
+
});
|
|
1366
|
+
} else result[key] = value2;
|
|
1362
1367
|
}
|
|
1363
1368
|
if (array) result.length = input.length;
|
|
1364
1369
|
return Object.freeze(result);
|
|
@@ -1370,6 +1375,7 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
1370
1375
|
}
|
|
1371
1376
|
|
|
1372
1377
|
// src/acl/field-catalog.ts
|
|
1378
|
+
var import_node_util4 = require("util");
|
|
1373
1379
|
var safeSegment = (part) => !!part && part !== "sub" && !["__proto__", "constructor", "prototype", "_doc", "__v"].includes(part) && !/^[+$-]|[\s*]/.test(part) && !part.includes("[") && !part.includes("]") && !/^\d+$/.test(part) && ![...part].some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127);
|
|
1374
1380
|
var isSafeOutputPath = (path) => path.split(".").every(safeSegment);
|
|
1375
1381
|
var inputControlSegments = /* @__PURE__ */ new Set([
|
package/advanced.mjs
CHANGED
|
@@ -1277,6 +1277,7 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
1277
1277
|
if (array && input.length > 2e4) authorizationError("snapshot array exceeds structural limits");
|
|
1278
1278
|
if (!array) authorizationRecord(input, "snapshot");
|
|
1279
1279
|
const result = array ? [] : {};
|
|
1280
|
+
let definedProperty = false;
|
|
1280
1281
|
for (const key of Reflect.ownKeys(input)) {
|
|
1281
1282
|
if (array && key === "length") continue;
|
|
1282
1283
|
if (typeof key !== "string" || unsafeKeys.has(key)) authorizationError("unsafe snapshot key");
|
|
@@ -1284,12 +1285,16 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
1284
1285
|
const descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
1285
1286
|
if (!("value" in descriptor) || !descriptor.enumerable && configuration !== "document")
|
|
1286
1287
|
authorizationError("accessor/non-enumerable input");
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1288
|
+
const value2 = copy(descriptor.value, depth + 1);
|
|
1289
|
+
if (array || definedProperty && Object.getPrototypeOf(result) !== Object.prototype || key in result) {
|
|
1290
|
+
definedProperty = true;
|
|
1291
|
+
Object.defineProperty(result, key, {
|
|
1292
|
+
value: value2,
|
|
1293
|
+
enumerable: true,
|
|
1294
|
+
writable: true,
|
|
1295
|
+
configurable: true
|
|
1296
|
+
});
|
|
1297
|
+
} else result[key] = value2;
|
|
1293
1298
|
}
|
|
1294
1299
|
if (array) result.length = input.length;
|
|
1295
1300
|
return Object.freeze(result);
|
|
@@ -1301,6 +1306,7 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
1301
1306
|
}
|
|
1302
1307
|
|
|
1303
1308
|
// src/acl/field-catalog.ts
|
|
1309
|
+
import { types as types3 } from "util";
|
|
1304
1310
|
var safeSegment = (part) => !!part && part !== "sub" && !["__proto__", "constructor", "prototype", "_doc", "__v"].includes(part) && !/^[+$-]|[\s*]/.test(part) && !part.includes("[") && !part.includes("]") && !/^\d+$/.test(part) && ![...part].some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127);
|
|
1305
1311
|
var isSafeOutputPath = (path) => path.split(".").every(safeSegment);
|
|
1306
1312
|
var inputControlSegments = /* @__PURE__ */ new Set([
|
package/index.js
CHANGED
|
@@ -634,12 +634,9 @@ var init_document = __esm({
|
|
|
634
634
|
const out = {};
|
|
635
635
|
seen.set(value, out);
|
|
636
636
|
for (const [key, entry] of Object.entries(value)) {
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
writable: true,
|
|
641
|
-
configurable: true
|
|
642
|
-
});
|
|
637
|
+
const copied = deepIsolateValue(entry, seen, flattenMaps);
|
|
638
|
+
if (Object.getPrototypeOf(out) === Object.prototype && !(key in out)) out[key] = copied;
|
|
639
|
+
else Object.defineProperty(out, key, { value: copied, enumerable: true, writable: true, configurable: true });
|
|
643
640
|
}
|
|
644
641
|
copyPermissionsAlias(value, out);
|
|
645
642
|
return out;
|
|
@@ -1992,6 +1989,7 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
1992
1989
|
if (array && input.length > 2e4) authorizationError("snapshot array exceeds structural limits");
|
|
1993
1990
|
if (!array) authorizationRecord(input, "snapshot");
|
|
1994
1991
|
const result2 = array ? [] : {};
|
|
1992
|
+
let definedProperty = false;
|
|
1995
1993
|
for (const key of Reflect.ownKeys(input)) {
|
|
1996
1994
|
if (array && key === "length") continue;
|
|
1997
1995
|
if (typeof key !== "string" || unsafeKeys.has(key)) authorizationError("unsafe snapshot key");
|
|
@@ -1999,12 +1997,16 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
1999
1997
|
const descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
2000
1998
|
if (!("value" in descriptor) || !descriptor.enumerable && configuration !== "document")
|
|
2001
1999
|
authorizationError("accessor/non-enumerable input");
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2000
|
+
const value2 = copy(descriptor.value, depth + 1);
|
|
2001
|
+
if (array || definedProperty && Object.getPrototypeOf(result2) !== Object.prototype || key in result2) {
|
|
2002
|
+
definedProperty = true;
|
|
2003
|
+
Object.defineProperty(result2, key, {
|
|
2004
|
+
value: value2,
|
|
2005
|
+
enumerable: true,
|
|
2006
|
+
writable: true,
|
|
2007
|
+
configurable: true
|
|
2008
|
+
});
|
|
2009
|
+
} else result2[key] = value2;
|
|
2008
2010
|
}
|
|
2009
2011
|
if (array) result2.length = input.length;
|
|
2010
2012
|
return Object.freeze(result2);
|
|
@@ -2128,6 +2130,29 @@ var init_authorization_snapshot = __esm({
|
|
|
2128
2130
|
});
|
|
2129
2131
|
|
|
2130
2132
|
// src/acl/field-catalog.ts
|
|
2133
|
+
function prepareCapturedOutputCatalog(catalog) {
|
|
2134
|
+
preparedOutputCatalogs.set(catalog, 0);
|
|
2135
|
+
}
|
|
2136
|
+
function prepareOutputCatalog(catalog) {
|
|
2137
|
+
if (import_node_util4.types.isProxy(catalog) || Object.getPrototypeOf(catalog) !== Object.prototype || !Object.isFrozen(catalog))
|
|
2138
|
+
return false;
|
|
2139
|
+
const paths = /* @__PURE__ */ new Set();
|
|
2140
|
+
for (const key of ["paths", "protectedPaths", "referencePaths", "virtualPaths", "dynamicPaths", "opaquePaths"]) {
|
|
2141
|
+
const slot = Object.getOwnPropertyDescriptor(catalog, key);
|
|
2142
|
+
if (!slot || !("value" in slot)) return false;
|
|
2143
|
+
const entries = slot.value;
|
|
2144
|
+
if (!Array.isArray(entries) || import_node_util4.types.isProxy(entries) || Object.getPrototypeOf(entries) !== Array.prototype || !Object.isFrozen(entries))
|
|
2145
|
+
return false;
|
|
2146
|
+
const length = Object.getOwnPropertyDescriptor(entries, "length").value;
|
|
2147
|
+
if (length > 2e4 || Reflect.ownKeys(entries).length !== length + 1) return false;
|
|
2148
|
+
for (let index = 0; index < length; index++) {
|
|
2149
|
+
const entry = Object.getOwnPropertyDescriptor(entries, String(index));
|
|
2150
|
+
if (!entry || !("value" in entry) || typeof entry.value !== "string") return false;
|
|
2151
|
+
if (key === "paths") paths.add(entry.value);
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
return { paths, results: /* @__PURE__ */ new Map() };
|
|
2155
|
+
}
|
|
2131
2156
|
function isSafeInputPath(path, requestIdentity = false) {
|
|
2132
2157
|
return isSafeOutputPath(path) && path.split(".").every((part) => !inputControlSegments.has(part) && (requestIdentity || part !== "_id"));
|
|
2133
2158
|
}
|
|
@@ -2158,13 +2183,27 @@ function matchesCatalogPattern(pattern, path, descendants = false) {
|
|
|
2158
2183
|
return (descendants ? actual.length >= expected.length : actual.length === expected.length) && expected.every((part, index) => part === "$*" || part === actual[index]);
|
|
2159
2184
|
}
|
|
2160
2185
|
function isCatalogOutputPath(catalog, path) {
|
|
2186
|
+
let prepared = typeof path === "string" ? preparedOutputCatalogs.get(catalog) : void 0;
|
|
2187
|
+
if (typeof prepared === "number") {
|
|
2188
|
+
const lookups = prepared + 1;
|
|
2189
|
+
prepared = lookups < 32 ? lookups : prepareOutputCatalog(catalog);
|
|
2190
|
+
preparedOutputCatalogs.set(catalog, prepared);
|
|
2191
|
+
if (typeof prepared === "number") return catalogOutputPath(catalog, path);
|
|
2192
|
+
}
|
|
2193
|
+
const cached = prepared ? prepared.results.get(path) : void 0;
|
|
2194
|
+
if (cached !== void 0) return cached;
|
|
2195
|
+
const allowed = catalogOutputPath(catalog, path, prepared ? prepared.paths : void 0);
|
|
2196
|
+
if (prepared && prepared.results.size < 2e4) prepared.results.set(path, allowed);
|
|
2197
|
+
return allowed;
|
|
2198
|
+
}
|
|
2199
|
+
function catalogOutputPath(catalog, path, paths) {
|
|
2161
2200
|
if (!isSafeOutputPath(path)) return false;
|
|
2162
2201
|
if (catalog.protectedPaths?.some((p) => matchesCatalogPattern(p, path, true))) return false;
|
|
2163
2202
|
if (catalog.referencePaths?.some((p) => matchesCatalogPattern(p, path, true) && !matchesCatalogPattern(p, path)))
|
|
2164
2203
|
return false;
|
|
2165
2204
|
if (catalog.virtualPaths?.some((p) => matchesCatalogPattern(p, path, true) && !matchesCatalogPattern(p, path)))
|
|
2166
2205
|
return false;
|
|
2167
|
-
return catalog.paths.includes(path) || !!catalog.dynamicPaths?.some((p) => matchesCatalogPattern(p, path)) || !!catalog.opaquePaths?.some((p) => matchesCatalogPattern(p, path, true));
|
|
2206
|
+
return (paths ? paths.has(path) : catalog.paths.includes(path)) || !!catalog.dynamicPaths?.some((p) => matchesCatalogPattern(p, path)) || !!catalog.opaquePaths?.some((p) => matchesCatalogPattern(p, path, true));
|
|
2168
2207
|
}
|
|
2169
2208
|
function captureAuthorizationFieldCatalog(schema, virtuals, documentPermissionField = "_permissions") {
|
|
2170
2209
|
const paths = /* @__PURE__ */ new Set();
|
|
@@ -2259,9 +2298,11 @@ function captureAuthorizationFieldCatalog(schema, virtuals, documentPermissionFi
|
|
|
2259
2298
|
protectedPaths: Object.freeze([...protectedPaths])
|
|
2260
2299
|
});
|
|
2261
2300
|
}
|
|
2262
|
-
var safeSegment, isSafeOutputPath, inputControlSegments;
|
|
2301
|
+
var import_node_util4, preparedOutputCatalogs, safeSegment, isSafeOutputPath, inputControlSegments;
|
|
2263
2302
|
var init_field_catalog = __esm({
|
|
2264
2303
|
"src/acl/field-catalog.ts"() {
|
|
2304
|
+
import_node_util4 = require("util");
|
|
2305
|
+
preparedOutputCatalogs = /* @__PURE__ */ new WeakMap();
|
|
2265
2306
|
safeSegment = (part) => !!part && part !== "sub" && !["__proto__", "constructor", "prototype", "_doc", "__v"].includes(part) && !/^[+$-]|[\s*]/.test(part) && !part.includes("[") && !part.includes("]") && !/^\d+$/.test(part) && ![...part].some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127);
|
|
2266
2307
|
isSafeOutputPath = (path) => path.split(".").every(safeSegment);
|
|
2267
2308
|
inputControlSegments = /* @__PURE__ */ new Set([
|
|
@@ -3871,7 +3912,9 @@ function captureAuthorizationCatalog(value) {
|
|
|
3871
3912
|
}
|
|
3872
3913
|
catalog[key] = paths;
|
|
3873
3914
|
}
|
|
3874
|
-
|
|
3915
|
+
const captured = Object.freeze(catalog);
|
|
3916
|
+
prepareCapturedOutputCatalog(captured);
|
|
3917
|
+
return captured;
|
|
3875
3918
|
}
|
|
3876
3919
|
function assertAuthorizationPath(path) {
|
|
3877
3920
|
if (typeof path !== "string" || !isSafeOutputPath(path)) {
|
|
@@ -4565,7 +4608,7 @@ var init_virtual_projection = __esm({
|
|
|
4565
4608
|
|
|
4566
4609
|
// src/acl/output-projection.ts
|
|
4567
4610
|
function copyOutputDecisionFields(value) {
|
|
4568
|
-
if (!Array.isArray(value) ||
|
|
4611
|
+
if (!Array.isArray(value) || import_node_util5.types.isProxy(value) || Object.getPrototypeOf(value) !== Array.prototype) return;
|
|
4569
4612
|
const length = Object.getOwnPropertyDescriptor(value, "length").value;
|
|
4570
4613
|
if (length > 2e4) return;
|
|
4571
4614
|
const fields = [];
|
|
@@ -4578,14 +4621,14 @@ function copyOutputDecisionFields(value) {
|
|
|
4578
4621
|
}
|
|
4579
4622
|
function readStaticOutputPlanFields(plan, authorization) {
|
|
4580
4623
|
const record3 = staticPlanFields.get(plan);
|
|
4581
|
-
if (!record3 || record3.authorization !== authorization ||
|
|
4624
|
+
if (!record3 || record3.authorization !== authorization || import_node_util5.types.isProxy(plan)) return;
|
|
4582
4625
|
const ownValue2 = (key) => {
|
|
4583
4626
|
const slot = Object.getOwnPropertyDescriptor(plan, key);
|
|
4584
4627
|
return slot && "value" in slot ? slot.value : void 0;
|
|
4585
4628
|
};
|
|
4586
4629
|
if (ownValue2("authorization") !== authorization || ownValue2("authorizationBinding") !== record3.binding) return;
|
|
4587
4630
|
const children = ownValue2("childPlans");
|
|
4588
|
-
if (children !== record3.children ||
|
|
4631
|
+
if (children !== record3.children || import_node_util5.types.isProxy(children) || Reflect.ownKeys(children).length) return;
|
|
4589
4632
|
const persisted = copyOutputDecisionFields(ownValue2("outputPersistedFields"));
|
|
4590
4633
|
const virtuals = copyOutputDecisionFields(ownValue2("outputVirtualNames"));
|
|
4591
4634
|
const same = (a, b) => a?.length === b.length && a.every((field, index) => field === b[index]);
|
|
@@ -4825,10 +4868,10 @@ function planCatalogProjection(args, outputFields = { mode: "request" }) {
|
|
|
4825
4868
|
)
|
|
4826
4869
|
};
|
|
4827
4870
|
}
|
|
4828
|
-
var
|
|
4871
|
+
var import_node_util5, staticPlanFields;
|
|
4829
4872
|
var init_output_projection = __esm({
|
|
4830
4873
|
"src/acl/output-projection.ts"() {
|
|
4831
|
-
|
|
4874
|
+
import_node_util5 = require("util");
|
|
4832
4875
|
init_query();
|
|
4833
4876
|
init_authorization_snapshot();
|
|
4834
4877
|
init_field_catalog();
|
|
@@ -4911,7 +4954,7 @@ function prepareOutputPath(policy, authorization, binding, path, access) {
|
|
|
4911
4954
|
return prepared;
|
|
4912
4955
|
}
|
|
4913
4956
|
function ordinaryContainer(value) {
|
|
4914
|
-
return value !== null && typeof value === "object" && !
|
|
4957
|
+
return value !== null && typeof value === "object" && !import_node_util6.types.isProxy(value) && Object.getPrototypeOf(value) === Object.prototype && Object.isFrozen(value);
|
|
4915
4958
|
}
|
|
4916
4959
|
function booleanRuleLookup(schema, path, access) {
|
|
4917
4960
|
if (schema == null) return true;
|
|
@@ -4959,10 +5002,10 @@ function prepareStaticOutputPaths(authorization, binding, paths, access, request
|
|
|
4959
5002
|
};
|
|
4960
5003
|
});
|
|
4961
5004
|
}
|
|
4962
|
-
var
|
|
5005
|
+
var import_node_util6, import_utils20, fieldPolicies;
|
|
4963
5006
|
var init_output_field_policy = __esm({
|
|
4964
5007
|
"src/acl/output-field-policy.ts"() {
|
|
4965
|
-
|
|
5008
|
+
import_node_util6 = require("util");
|
|
4966
5009
|
import_utils20 = require("@web-ts-toolkit/utils");
|
|
4967
5010
|
init_service_authorization();
|
|
4968
5011
|
init_field_authorization();
|
|
@@ -5152,7 +5195,7 @@ function memoizeDocumentFieldDecision(handle, binding, field, evaluate) {
|
|
|
5152
5195
|
return decision.promise;
|
|
5153
5196
|
}
|
|
5154
5197
|
function ordinaryDecisionBinding(binding) {
|
|
5155
|
-
if (
|
|
5198
|
+
if (import_node_util7.types.isProxy(binding) || Object.getPrototypeOf(binding) !== Object.prototype) return false;
|
|
5156
5199
|
for (const key of ["request", "runtime", "model", "modelName", "scopePath"]) {
|
|
5157
5200
|
const slot = Object.getOwnPropertyDescriptor(binding, key);
|
|
5158
5201
|
if (slot && !("value" in slot)) return false;
|
|
@@ -5402,10 +5445,10 @@ function createServiceOutputContext(diagnostic, handle, use) {
|
|
|
5402
5445
|
});
|
|
5403
5446
|
return context;
|
|
5404
5447
|
}
|
|
5405
|
-
var
|
|
5448
|
+
var import_node_util7, import_mongoose5, stages, documents, outputs, unresolvedDocuments, owningDocuments;
|
|
5406
5449
|
var init_document_authorization = __esm({
|
|
5407
5450
|
"src/acl/document-authorization.ts"() {
|
|
5408
|
-
|
|
5451
|
+
import_node_util7 = require("util");
|
|
5409
5452
|
import_mongoose5 = require("mongoose");
|
|
5410
5453
|
init_service_authorization();
|
|
5411
5454
|
init_authorization_snapshot();
|
|
@@ -5635,7 +5678,7 @@ function optimizeAndFilter(clausesInput) {
|
|
|
5635
5678
|
}
|
|
5636
5679
|
let canMerge = true;
|
|
5637
5680
|
for (const [key, value] of Object.entries(clause)) {
|
|
5638
|
-
if ((0, import_utils25.hasOwn)(mergedClause, key) && !(0,
|
|
5681
|
+
if ((0, import_utils25.hasOwn)(mergedClause, key) && !(0, import_node_util8.isDeepStrictEqual)(mergedClause[key], value)) {
|
|
5639
5682
|
canMerge = false;
|
|
5640
5683
|
break;
|
|
5641
5684
|
}
|
|
@@ -5789,11 +5832,11 @@ async function collectSchemaFields({
|
|
|
5789
5832
|
}
|
|
5790
5833
|
return fields;
|
|
5791
5834
|
}
|
|
5792
|
-
var import_utils25,
|
|
5835
|
+
var import_utils25, import_node_util8, permissionFieldOwners;
|
|
5793
5836
|
var init_core_shared = __esm({
|
|
5794
5837
|
"src/core-shared.ts"() {
|
|
5795
5838
|
import_utils25 = require("@web-ts-toolkit/utils");
|
|
5796
|
-
|
|
5839
|
+
import_node_util8 = require("util");
|
|
5797
5840
|
init_helpers();
|
|
5798
5841
|
init_options();
|
|
5799
5842
|
init_runtime_context();
|
|
@@ -6178,7 +6221,7 @@ function equivalentVirtualPopulatePredicate(left, right) {
|
|
|
6178
6221
|
)
|
|
6179
6222
|
);
|
|
6180
6223
|
}
|
|
6181
|
-
return (0,
|
|
6224
|
+
return (0, import_node_util9.isDeepStrictEqual)(left, right);
|
|
6182
6225
|
}
|
|
6183
6226
|
function createVirtualPopulateBatch(owner) {
|
|
6184
6227
|
const batch = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
@@ -6553,11 +6596,11 @@ async function loadVirtualPopulateOutputRows(owner, inputs, plan, publicPopulate
|
|
|
6553
6596
|
}
|
|
6554
6597
|
return output;
|
|
6555
6598
|
}
|
|
6556
|
-
var import_mongoose7,
|
|
6599
|
+
var import_mongoose7, import_node_util9, import_utils28, batches, rows, outputRows, fetchedPublicIdentities, publicViewIdentities, familyRawFetches, addressKey, storage, originalRef, copyOriginalValue, readPolicy, compatible, idKey, logUnavailable;
|
|
6557
6600
|
var init_virtual_populate_execution = __esm({
|
|
6558
6601
|
"src/acl/virtual-populate-execution.ts"() {
|
|
6559
6602
|
import_mongoose7 = require("mongoose");
|
|
6560
|
-
|
|
6603
|
+
import_node_util9 = require("util");
|
|
6561
6604
|
import_utils28 = require("@web-ts-toolkit/utils");
|
|
6562
6605
|
init_cache();
|
|
6563
6606
|
init_core_shared();
|
|
@@ -6829,7 +6872,7 @@ function helperPlan(authorization, binding) {
|
|
|
6829
6872
|
return planAuthorizedModelProjection({ authorization, binding, effectiveSelect: [] });
|
|
6830
6873
|
}
|
|
6831
6874
|
function primitiveHelperFields(source, plan) {
|
|
6832
|
-
if (
|
|
6875
|
+
if (import_node_util10.types.isProxy(source)) return;
|
|
6833
6876
|
const canonical = readStaticOutputPlanFields(plan, plan.authorization);
|
|
6834
6877
|
if (!canonical) return;
|
|
6835
6878
|
const fields = [];
|
|
@@ -6960,10 +7003,10 @@ async function filterModelOutputForHelper(args) {
|
|
|
6960
7003
|
});
|
|
6961
7004
|
return filterExistingOutput(source, plan, handle, false);
|
|
6962
7005
|
}
|
|
6963
|
-
var
|
|
7006
|
+
var import_node_util10, import_utils29;
|
|
6964
7007
|
var init_output_field_filter = __esm({
|
|
6965
7008
|
"src/acl/output-field-filter.ts"() {
|
|
6966
|
-
|
|
7009
|
+
import_node_util10 = require("util");
|
|
6967
7010
|
import_utils29 = require("@web-ts-toolkit/utils");
|
|
6968
7011
|
init_permissions_alias();
|
|
6969
7012
|
init_document();
|
package/index.mjs
CHANGED
|
@@ -613,12 +613,9 @@ var init_document = __esm({
|
|
|
613
613
|
const out = {};
|
|
614
614
|
seen.set(value, out);
|
|
615
615
|
for (const [key, entry] of Object.entries(value)) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
writable: true,
|
|
620
|
-
configurable: true
|
|
621
|
-
});
|
|
616
|
+
const copied = deepIsolateValue(entry, seen, flattenMaps);
|
|
617
|
+
if (Object.getPrototypeOf(out) === Object.prototype && !(key in out)) out[key] = copied;
|
|
618
|
+
else Object.defineProperty(out, key, { value: copied, enumerable: true, writable: true, configurable: true });
|
|
622
619
|
}
|
|
623
620
|
copyPermissionsAlias(value, out);
|
|
624
621
|
return out;
|
|
@@ -1975,6 +1972,7 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
1975
1972
|
if (array && input.length > 2e4) authorizationError("snapshot array exceeds structural limits");
|
|
1976
1973
|
if (!array) authorizationRecord(input, "snapshot");
|
|
1977
1974
|
const result2 = array ? [] : {};
|
|
1975
|
+
let definedProperty = false;
|
|
1978
1976
|
for (const key of Reflect.ownKeys(input)) {
|
|
1979
1977
|
if (array && key === "length") continue;
|
|
1980
1978
|
if (typeof key !== "string" || unsafeKeys.has(key)) authorizationError("unsafe snapshot key");
|
|
@@ -1982,12 +1980,16 @@ function copyAuthorizationValue(value, configuration = false) {
|
|
|
1982
1980
|
const descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
1983
1981
|
if (!("value" in descriptor) || !descriptor.enumerable && configuration !== "document")
|
|
1984
1982
|
authorizationError("accessor/non-enumerable input");
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1983
|
+
const value2 = copy(descriptor.value, depth + 1);
|
|
1984
|
+
if (array || definedProperty && Object.getPrototypeOf(result2) !== Object.prototype || key in result2) {
|
|
1985
|
+
definedProperty = true;
|
|
1986
|
+
Object.defineProperty(result2, key, {
|
|
1987
|
+
value: value2,
|
|
1988
|
+
enumerable: true,
|
|
1989
|
+
writable: true,
|
|
1990
|
+
configurable: true
|
|
1991
|
+
});
|
|
1992
|
+
} else result2[key] = value2;
|
|
1991
1993
|
}
|
|
1992
1994
|
if (array) result2.length = input.length;
|
|
1993
1995
|
return Object.freeze(result2);
|
|
@@ -2107,6 +2109,30 @@ var init_authorization_snapshot = __esm({
|
|
|
2107
2109
|
});
|
|
2108
2110
|
|
|
2109
2111
|
// src/acl/field-catalog.ts
|
|
2112
|
+
import { types as types3 } from "util";
|
|
2113
|
+
function prepareCapturedOutputCatalog(catalog) {
|
|
2114
|
+
preparedOutputCatalogs.set(catalog, 0);
|
|
2115
|
+
}
|
|
2116
|
+
function prepareOutputCatalog(catalog) {
|
|
2117
|
+
if (types3.isProxy(catalog) || Object.getPrototypeOf(catalog) !== Object.prototype || !Object.isFrozen(catalog))
|
|
2118
|
+
return false;
|
|
2119
|
+
const paths = /* @__PURE__ */ new Set();
|
|
2120
|
+
for (const key of ["paths", "protectedPaths", "referencePaths", "virtualPaths", "dynamicPaths", "opaquePaths"]) {
|
|
2121
|
+
const slot = Object.getOwnPropertyDescriptor(catalog, key);
|
|
2122
|
+
if (!slot || !("value" in slot)) return false;
|
|
2123
|
+
const entries = slot.value;
|
|
2124
|
+
if (!Array.isArray(entries) || types3.isProxy(entries) || Object.getPrototypeOf(entries) !== Array.prototype || !Object.isFrozen(entries))
|
|
2125
|
+
return false;
|
|
2126
|
+
const length = Object.getOwnPropertyDescriptor(entries, "length").value;
|
|
2127
|
+
if (length > 2e4 || Reflect.ownKeys(entries).length !== length + 1) return false;
|
|
2128
|
+
for (let index = 0; index < length; index++) {
|
|
2129
|
+
const entry = Object.getOwnPropertyDescriptor(entries, String(index));
|
|
2130
|
+
if (!entry || !("value" in entry) || typeof entry.value !== "string") return false;
|
|
2131
|
+
if (key === "paths") paths.add(entry.value);
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
return { paths, results: /* @__PURE__ */ new Map() };
|
|
2135
|
+
}
|
|
2110
2136
|
function isSafeInputPath(path, requestIdentity = false) {
|
|
2111
2137
|
return isSafeOutputPath(path) && path.split(".").every((part) => !inputControlSegments.has(part) && (requestIdentity || part !== "_id"));
|
|
2112
2138
|
}
|
|
@@ -2137,13 +2163,27 @@ function matchesCatalogPattern(pattern, path, descendants = false) {
|
|
|
2137
2163
|
return (descendants ? actual.length >= expected.length : actual.length === expected.length) && expected.every((part, index) => part === "$*" || part === actual[index]);
|
|
2138
2164
|
}
|
|
2139
2165
|
function isCatalogOutputPath(catalog, path) {
|
|
2166
|
+
let prepared = typeof path === "string" ? preparedOutputCatalogs.get(catalog) : void 0;
|
|
2167
|
+
if (typeof prepared === "number") {
|
|
2168
|
+
const lookups = prepared + 1;
|
|
2169
|
+
prepared = lookups < 32 ? lookups : prepareOutputCatalog(catalog);
|
|
2170
|
+
preparedOutputCatalogs.set(catalog, prepared);
|
|
2171
|
+
if (typeof prepared === "number") return catalogOutputPath(catalog, path);
|
|
2172
|
+
}
|
|
2173
|
+
const cached = prepared ? prepared.results.get(path) : void 0;
|
|
2174
|
+
if (cached !== void 0) return cached;
|
|
2175
|
+
const allowed = catalogOutputPath(catalog, path, prepared ? prepared.paths : void 0);
|
|
2176
|
+
if (prepared && prepared.results.size < 2e4) prepared.results.set(path, allowed);
|
|
2177
|
+
return allowed;
|
|
2178
|
+
}
|
|
2179
|
+
function catalogOutputPath(catalog, path, paths) {
|
|
2140
2180
|
if (!isSafeOutputPath(path)) return false;
|
|
2141
2181
|
if (catalog.protectedPaths?.some((p) => matchesCatalogPattern(p, path, true))) return false;
|
|
2142
2182
|
if (catalog.referencePaths?.some((p) => matchesCatalogPattern(p, path, true) && !matchesCatalogPattern(p, path)))
|
|
2143
2183
|
return false;
|
|
2144
2184
|
if (catalog.virtualPaths?.some((p) => matchesCatalogPattern(p, path, true) && !matchesCatalogPattern(p, path)))
|
|
2145
2185
|
return false;
|
|
2146
|
-
return catalog.paths.includes(path) || !!catalog.dynamicPaths?.some((p) => matchesCatalogPattern(p, path)) || !!catalog.opaquePaths?.some((p) => matchesCatalogPattern(p, path, true));
|
|
2186
|
+
return (paths ? paths.has(path) : catalog.paths.includes(path)) || !!catalog.dynamicPaths?.some((p) => matchesCatalogPattern(p, path)) || !!catalog.opaquePaths?.some((p) => matchesCatalogPattern(p, path, true));
|
|
2147
2187
|
}
|
|
2148
2188
|
function captureAuthorizationFieldCatalog(schema, virtuals, documentPermissionField = "_permissions") {
|
|
2149
2189
|
const paths = /* @__PURE__ */ new Set();
|
|
@@ -2238,9 +2278,10 @@ function captureAuthorizationFieldCatalog(schema, virtuals, documentPermissionFi
|
|
|
2238
2278
|
protectedPaths: Object.freeze([...protectedPaths])
|
|
2239
2279
|
});
|
|
2240
2280
|
}
|
|
2241
|
-
var safeSegment, isSafeOutputPath, inputControlSegments;
|
|
2281
|
+
var preparedOutputCatalogs, safeSegment, isSafeOutputPath, inputControlSegments;
|
|
2242
2282
|
var init_field_catalog = __esm({
|
|
2243
2283
|
"src/acl/field-catalog.ts"() {
|
|
2284
|
+
preparedOutputCatalogs = /* @__PURE__ */ new WeakMap();
|
|
2244
2285
|
safeSegment = (part) => !!part && part !== "sub" && !["__proto__", "constructor", "prototype", "_doc", "__v"].includes(part) && !/^[+$-]|[\s*]/.test(part) && !part.includes("[") && !part.includes("]") && !/^\d+$/.test(part) && ![...part].some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127);
|
|
2245
2286
|
isSafeOutputPath = (path) => path.split(".").every(safeSegment);
|
|
2246
2287
|
inputControlSegments = /* @__PURE__ */ new Set([
|
|
@@ -3862,7 +3903,9 @@ function captureAuthorizationCatalog(value) {
|
|
|
3862
3903
|
}
|
|
3863
3904
|
catalog[key] = paths;
|
|
3864
3905
|
}
|
|
3865
|
-
|
|
3906
|
+
const captured = Object.freeze(catalog);
|
|
3907
|
+
prepareCapturedOutputCatalog(captured);
|
|
3908
|
+
return captured;
|
|
3866
3909
|
}
|
|
3867
3910
|
function assertAuthorizationPath(path) {
|
|
3868
3911
|
if (typeof path !== "string" || !isSafeOutputPath(path)) {
|
|
@@ -4555,9 +4598,9 @@ var init_virtual_projection = __esm({
|
|
|
4555
4598
|
});
|
|
4556
4599
|
|
|
4557
4600
|
// src/acl/output-projection.ts
|
|
4558
|
-
import { types as
|
|
4601
|
+
import { types as types4 } from "util";
|
|
4559
4602
|
function copyOutputDecisionFields(value) {
|
|
4560
|
-
if (!Array.isArray(value) ||
|
|
4603
|
+
if (!Array.isArray(value) || types4.isProxy(value) || Object.getPrototypeOf(value) !== Array.prototype) return;
|
|
4561
4604
|
const length = Object.getOwnPropertyDescriptor(value, "length").value;
|
|
4562
4605
|
if (length > 2e4) return;
|
|
4563
4606
|
const fields = [];
|
|
@@ -4570,14 +4613,14 @@ function copyOutputDecisionFields(value) {
|
|
|
4570
4613
|
}
|
|
4571
4614
|
function readStaticOutputPlanFields(plan, authorization) {
|
|
4572
4615
|
const record3 = staticPlanFields.get(plan);
|
|
4573
|
-
if (!record3 || record3.authorization !== authorization ||
|
|
4616
|
+
if (!record3 || record3.authorization !== authorization || types4.isProxy(plan)) return;
|
|
4574
4617
|
const ownValue2 = (key) => {
|
|
4575
4618
|
const slot = Object.getOwnPropertyDescriptor(plan, key);
|
|
4576
4619
|
return slot && "value" in slot ? slot.value : void 0;
|
|
4577
4620
|
};
|
|
4578
4621
|
if (ownValue2("authorization") !== authorization || ownValue2("authorizationBinding") !== record3.binding) return;
|
|
4579
4622
|
const children = ownValue2("childPlans");
|
|
4580
|
-
if (children !== record3.children ||
|
|
4623
|
+
if (children !== record3.children || types4.isProxy(children) || Reflect.ownKeys(children).length) return;
|
|
4581
4624
|
const persisted = copyOutputDecisionFields(ownValue2("outputPersistedFields"));
|
|
4582
4625
|
const virtuals = copyOutputDecisionFields(ownValue2("outputVirtualNames"));
|
|
4583
4626
|
const same = (a, b) => a?.length === b.length && a.every((field, index) => field === b[index]);
|
|
@@ -4832,7 +4875,7 @@ var init_output_projection = __esm({
|
|
|
4832
4875
|
});
|
|
4833
4876
|
|
|
4834
4877
|
// src/acl/output-field-policy.ts
|
|
4835
|
-
import { types as
|
|
4878
|
+
import { types as types5 } from "util";
|
|
4836
4879
|
import { isPlainObject as isPlainObject16 } from "@web-ts-toolkit/utils";
|
|
4837
4880
|
function callFieldPolicy(authorization, binding) {
|
|
4838
4881
|
assertAuthorizationBinding(authorization, binding);
|
|
@@ -4904,7 +4947,7 @@ function prepareOutputPath(policy, authorization, binding, path, access) {
|
|
|
4904
4947
|
return prepared;
|
|
4905
4948
|
}
|
|
4906
4949
|
function ordinaryContainer(value) {
|
|
4907
|
-
return value !== null && typeof value === "object" && !
|
|
4950
|
+
return value !== null && typeof value === "object" && !types5.isProxy(value) && Object.getPrototypeOf(value) === Object.prototype && Object.isFrozen(value);
|
|
4908
4951
|
}
|
|
4909
4952
|
function booleanRuleLookup(schema, path, access) {
|
|
4910
4953
|
if (schema == null) return true;
|
|
@@ -4963,7 +5006,7 @@ var init_output_field_policy = __esm({
|
|
|
4963
5006
|
});
|
|
4964
5007
|
|
|
4965
5008
|
// src/acl/document-authorization.ts
|
|
4966
|
-
import { types as
|
|
5009
|
+
import { types as types6 } from "util";
|
|
4967
5010
|
import { Document as Document3 } from "mongoose";
|
|
4968
5011
|
function bindOutputDocumentOwner(handle, knownOutput, owner, binding) {
|
|
4969
5012
|
lookupDocumentOwner(handle);
|
|
@@ -5145,7 +5188,7 @@ function memoizeDocumentFieldDecision(handle, binding, field, evaluate) {
|
|
|
5145
5188
|
return decision.promise;
|
|
5146
5189
|
}
|
|
5147
5190
|
function ordinaryDecisionBinding(binding) {
|
|
5148
|
-
if (
|
|
5191
|
+
if (types6.isProxy(binding) || Object.getPrototypeOf(binding) !== Object.prototype) return false;
|
|
5149
5192
|
for (const key of ["request", "runtime", "model", "modelName", "scopePath"]) {
|
|
5150
5193
|
const slot = Object.getOwnPropertyDescriptor(binding, key);
|
|
5151
5194
|
if (slot && !("value" in slot)) return false;
|
|
@@ -6602,7 +6645,7 @@ var init_virtual_populate_execution = __esm({
|
|
|
6602
6645
|
});
|
|
6603
6646
|
|
|
6604
6647
|
// src/acl/output-field-filter.ts
|
|
6605
|
-
import { types as
|
|
6648
|
+
import { types as types7 } from "util";
|
|
6606
6649
|
import { isPlainObject as isPlainObject22 } from "@web-ts-toolkit/utils";
|
|
6607
6650
|
function assertOwningOutputDocuments(handle) {
|
|
6608
6651
|
const owner = readOutputDocumentOwner(handle);
|
|
@@ -6831,7 +6874,7 @@ function helperPlan(authorization, binding) {
|
|
|
6831
6874
|
return planAuthorizedModelProjection({ authorization, binding, effectiveSelect: [] });
|
|
6832
6875
|
}
|
|
6833
6876
|
function primitiveHelperFields(source, plan) {
|
|
6834
|
-
if (
|
|
6877
|
+
if (types7.isProxy(source)) return;
|
|
6835
6878
|
const canonical = readStaticOutputPlanFields(plan, plan.authorization);
|
|
6836
6879
|
if (!canonical) return;
|
|
6837
6880
|
const fields = [];
|
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.
|
|
5
|
+
"version": "0.63.0",
|
|
6
6
|
"sideEffects": [
|
|
7
7
|
"./**/index.js",
|
|
8
8
|
"./**/index.mjs",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"node": ">=22"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@web-ts-toolkit/express-json-router": "0.
|
|
61
|
-
"@web-ts-toolkit/utils": "0.
|
|
60
|
+
"@web-ts-toolkit/express-json-router": "0.63.0",
|
|
61
|
+
"@web-ts-toolkit/utils": "0.63.0",
|
|
62
62
|
"just-diff": "^6.0.2",
|
|
63
63
|
"mongoose-schema-jsonschema": "^4.0.1",
|
|
64
64
|
"sift": "^17.1.3",
|