@web-ts-toolkit/access-router 0.30.0 → 0.31.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
@@ -163,7 +163,8 @@ function setDocValue(doc, path, value) {
163
163
  }
164
164
  function getDocPermissions(modelName, doc) {
165
165
  const docPermissionField = getModelOption(modelName, "documentPermissionField");
166
- return getDocValue(doc, docPermissionField, {});
166
+ const permissions = getDocValue(doc, docPermissionField, {});
167
+ return (0, import_utils3.isPlainObject)(permissions) ? permissions : {};
167
168
  }
168
169
  function toObject(doc) {
169
170
  return isDocument(doc) ? doc.toObject() : doc;
@@ -921,7 +922,8 @@ var AccessRuntime = class {
921
922
  }
922
923
  getModelRef(modelName, refPath) {
923
924
  this.ensureModelMeta(modelName);
924
- return (0, import_utils10.get)(this.modelRefs, `${modelName}.${refPath}`, null);
925
+ const value = (0, import_utils10.get)(this.modelRefs, `${modelName}.${refPath}`, null);
926
+ return (0, import_utils10.isString)(value) ? value : null;
925
927
  }
926
928
  getModelSub(modelName) {
927
929
  this.ensureModelMeta(modelName);
@@ -2986,7 +2988,7 @@ var Core = class {
2986
2988
  permissionSchema,
2987
2989
  access,
2988
2990
  baseFields,
2989
- hasPermission: (key) => permissions.has(key) || docPermissions[this.removePrefix(key, modelPermissionPrefix)],
2991
+ hasPermission: (key) => permissions.has(key) || Boolean(docPermissions[this.removePrefix(key, modelPermissionPrefix)]),
2990
2992
  functionArgs: [permissions, docPermissions]
2991
2993
  });
2992
2994
  }
@@ -3001,7 +3003,7 @@ var Core = class {
3001
3003
  permissionSchema,
3002
3004
  access,
3003
3005
  baseFields,
3004
- hasPermission: (key) => permissions.has(key) || docPermissions[this.removePrefix(key, modelPermissionPrefix)],
3006
+ hasPermission: (key) => permissions.has(key) || Boolean(docPermissions[this.removePrefix(key, modelPermissionPrefix)]),
3005
3007
  functionArgs: [permissions, docPermissions]
3006
3008
  });
3007
3009
  }
@@ -3291,7 +3293,7 @@ function guard(condition) {
3291
3293
  return next(new import_express_json_router2.default.clientErrors.UnauthorizedError());
3292
3294
  }
3293
3295
  const docPermissions = getDocPermissions(modelName, result.data);
3294
- phas = (key) => permissions.has(key) || docPermissions[key];
3296
+ phas = (key) => permissions.has(key) || Boolean(docPermissions[key]);
3295
3297
  cond = _cond;
3296
3298
  }
3297
3299
  const { stringHandler, arrayHandler } = createValidator(phas);
package/index.mjs CHANGED
@@ -116,7 +116,8 @@ function setDocValue(doc, path, value) {
116
116
  }
117
117
  function getDocPermissions(modelName, doc) {
118
118
  const docPermissionField = getModelOption(modelName, "documentPermissionField");
119
- return getDocValue(doc, docPermissionField, {});
119
+ const permissions = getDocValue(doc, docPermissionField, {});
120
+ return isPlainObject2(permissions) ? permissions : {};
120
121
  }
121
122
  function toObject(doc) {
122
123
  return isDocument(doc) ? doc.toObject() : doc;
@@ -874,7 +875,8 @@ var AccessRuntime = class {
874
875
  }
875
876
  getModelRef(modelName, refPath) {
876
877
  this.ensureModelMeta(modelName);
877
- return get3(this.modelRefs, `${modelName}.${refPath}`, null);
878
+ const value = get3(this.modelRefs, `${modelName}.${refPath}`, null);
879
+ return isString4(value) ? value : null;
878
880
  }
879
881
  getModelSub(modelName) {
880
882
  this.ensureModelMeta(modelName);
@@ -2970,7 +2972,7 @@ var Core = class {
2970
2972
  permissionSchema,
2971
2973
  access,
2972
2974
  baseFields,
2973
- hasPermission: (key) => permissions.has(key) || docPermissions[this.removePrefix(key, modelPermissionPrefix)],
2975
+ hasPermission: (key) => permissions.has(key) || Boolean(docPermissions[this.removePrefix(key, modelPermissionPrefix)]),
2974
2976
  functionArgs: [permissions, docPermissions]
2975
2977
  });
2976
2978
  }
@@ -2985,7 +2987,7 @@ var Core = class {
2985
2987
  permissionSchema,
2986
2988
  access,
2987
2989
  baseFields,
2988
- hasPermission: (key) => permissions.has(key) || docPermissions[this.removePrefix(key, modelPermissionPrefix)],
2990
+ hasPermission: (key) => permissions.has(key) || Boolean(docPermissions[this.removePrefix(key, modelPermissionPrefix)]),
2989
2991
  functionArgs: [permissions, docPermissions]
2990
2992
  });
2991
2993
  }
@@ -3275,7 +3277,7 @@ function guard(condition) {
3275
3277
  return next(new JsonRouter2.clientErrors.UnauthorizedError());
3276
3278
  }
3277
3279
  const docPermissions = getDocPermissions(modelName, result.data);
3278
- phas = (key) => permissions.has(key) || docPermissions[key];
3280
+ phas = (key) => permissions.has(key) || Boolean(docPermissions[key]);
3279
3281
  cond = _cond;
3280
3282
  }
3281
3283
  const { stringHandler, arrayHandler } = createValidator(phas);
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.30.0",
5
+ "version": "0.31.0",
6
6
  "sideEffects": false,
7
7
  "keywords": [
8
8
  "express",
@@ -40,8 +40,8 @@
40
40
  "node": ">=20"
41
41
  },
42
42
  "dependencies": {
43
- "@web-ts-toolkit/express-json-router": "0.30.0",
44
- "@web-ts-toolkit/utils": "0.30.0",
43
+ "@web-ts-toolkit/express-json-router": "0.31.0",
44
+ "@web-ts-toolkit/utils": "0.31.0",
45
45
  "just-diff": "^6.0.2",
46
46
  "mongoose-schema-jsonschema": "^4.0.1",
47
47
  "sift": "^17.1.3",