@aeriajs/common 0.0.45 → 0.0.46

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/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export * from './getMissingProperties.js';
13
13
  export * from './getReferenceProperty.js';
14
14
  export * from './getValueFromPath.js';
15
15
  export * from './http.js';
16
+ export * from './isGranted.js';
16
17
  export * from './isObjectId.js';
17
18
  export * from './isReference.js';
18
19
  export * from './isRequired.js';
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ __exportStar(require("./getMissingProperties.js"), exports);
29
29
  __exportStar(require("./getReferenceProperty.js"), exports);
30
30
  __exportStar(require("./getValueFromPath.js"), exports);
31
31
  __exportStar(require("./http.js"), exports);
32
+ __exportStar(require("./isGranted.js"), exports);
32
33
  __exportStar(require("./isObjectId.js"), exports);
33
34
  __exportStar(require("./isReference.js"), exports);
34
35
  __exportStar(require("./isRequired.js"), exports);
package/dist/index.mjs CHANGED
@@ -14,6 +14,7 @@ export * from "./getMissingProperties.mjs";
14
14
  export * from "./getReferenceProperty.mjs";
15
15
  export * from "./getValueFromPath.mjs";
16
16
  export * from "./http.mjs";
17
+ export * from "./isGranted.mjs";
17
18
  export * from "./isObjectId.mjs";
18
19
  export * from "./isReference.mjs";
19
20
  export * from "./isRequired.mjs";
@@ -0,0 +1,2 @@
1
+ import type { AccessCondition, Token } from '@aeriajs/types';
2
+ export declare const isGranted: (condition: AccessCondition, token: Token) => boolean | undefined;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isGranted = void 0;
4
+ const arraysIntersects_js_1 = require("./arraysIntersects.js");
5
+ const isGranted = (condition, token) => {
6
+ if (Array.isArray(condition)) {
7
+ return token.authenticated
8
+ ? (0, arraysIntersects_js_1.arraysIntersects)(token.roles, condition)
9
+ : condition.includes('guest');
10
+ }
11
+ switch (condition) {
12
+ case false: return false;
13
+ case true: return token.authenticated;
14
+ case 'unauthenticated':
15
+ return true;
16
+ case 'unauthenticated-only':
17
+ return !token.authenticated;
18
+ }
19
+ };
20
+ exports.isGranted = isGranted;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ import { arraysIntersects } from "./arraysIntersects.mjs";
3
+ export const isGranted = (condition, token) => {
4
+ if (Array.isArray(condition)) {
5
+ return token.authenticated ? arraysIntersects(token.roles, condition) : condition.includes("guest");
6
+ }
7
+ switch (condition) {
8
+ case false:
9
+ return false;
10
+ case true:
11
+ return token.authenticated;
12
+ case "unauthenticated":
13
+ return true;
14
+ case "unauthenticated-only":
15
+ return !token.authenticated;
16
+ }
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/common",
3
- "version": "0.0.45",
3
+ "version": "0.0.46",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -31,7 +31,7 @@
31
31
  "bson": "^6.5.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "@aeriajs/types": "^0.0.42",
34
+ "@aeriajs/types": "^0.0.43",
35
35
  "bson": "^6.5.0"
36
36
  },
37
37
  "scripts": {