rolegate 0.1.0 → 0.1.1
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 +23 -10
- package/dist/core/createRbac.d.ts +3 -0
- package/dist/core/createRbac.d.ts.map +1 -0
- package/dist/core/createRbac.js +14 -34
- package/dist/core/createRbac.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/rules.d.ts +17 -0
- package/dist/core/rules.d.ts.map +1 -0
- package/dist/core/rules.js +62 -0
- package/dist/core/rules.js.map +1 -0
- package/dist/core/types.d.ts +1 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/express/guardRoutes.d.ts +6 -0
- package/dist/express/guardRoutes.d.ts.map +1 -0
- package/dist/express/guardRoutes.js +6 -1
- package/dist/express/guardRoutes.js.map +1 -1
- package/dist/express/index.d.ts +1 -0
- package/dist/express/index.d.ts.map +1 -0
- package/dist/express/requirePermission.d.ts +1 -0
- package/dist/express/requirePermission.d.ts.map +1 -0
- package/dist/express/types.d.ts +2 -0
- package/dist/express/types.d.ts.map +1 -0
- package/dist/express/types.js +3 -1
- package/dist/express/types.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/rbac.d.ts +1 -0
- package/dist/react/rbac.d.ts.map +1 -0
- package/dist/react/routes.d.ts +1 -0
- package/dist/react/routes.d.ts.map +1 -0
- package/dist/routes/createRouteAccess.d.ts +3 -0
- package/dist/routes/createRouteAccess.d.ts.map +1 -0
- package/dist/routes/createRouteAccess.js +15 -33
- package/dist/routes/createRouteAccess.js.map +1 -1
- package/dist/routes/fromRows.d.ts +1 -0
- package/dist/routes/fromRows.d.ts.map +1 -0
- package/dist/routes/fromRows.js +21 -7
- package/dist/routes/fromRows.js.map +1 -1
- package/dist/routes/index.d.ts +2 -1
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +1 -1
- package/dist/routes/index.js.map +1 -1
- package/dist/routes/matching/path.d.ts +14 -0
- package/dist/routes/matching/path.d.ts.map +1 -0
- package/dist/routes/matching/path.js +49 -0
- package/dist/routes/matching/path.js.map +1 -0
- package/dist/routes/{pattern.d.ts → matching/pattern.d.ts} +5 -10
- package/dist/routes/matching/pattern.d.ts.map +1 -0
- package/dist/routes/{pattern.js → matching/pattern.js} +21 -27
- package/dist/routes/matching/pattern.js.map +1 -0
- package/dist/routes/rules.d.ts +14 -0
- package/dist/routes/rules.d.ts.map +1 -0
- package/dist/routes/rules.js +53 -0
- package/dist/routes/rules.js.map +1 -0
- package/dist/routes/types.d.ts +1 -0
- package/dist/routes/types.d.ts.map +1 -0
- package/dist/shared/errors.d.ts +1 -0
- package/dist/shared/errors.d.ts.map +1 -0
- package/dist/shared/roles.d.ts +4 -1
- package/dist/shared/roles.d.ts.map +1 -0
- package/dist/shared/roles.js +7 -3
- package/dist/shared/roles.js.map +1 -1
- package/dist/shared/validate.d.ts +14 -0
- package/dist/shared/validate.d.ts.map +1 -0
- package/dist/shared/validate.js +35 -0
- package/dist/shared/validate.js.map +1 -0
- package/docs/actions.md +3 -1
- package/docs/api-routes.md +21 -1
- package/docs/database.md +4 -0
- package/docs/pages.md +6 -0
- package/package.json +4 -3
- package/src/core/createRbac.ts +58 -0
- package/src/core/index.ts +2 -0
- package/src/core/rules.ts +69 -0
- package/src/core/types.ts +36 -0
- package/src/express/guardRoutes.ts +64 -0
- package/src/express/index.ts +12 -0
- package/src/express/requirePermission.ts +43 -0
- package/src/express/types.ts +45 -0
- package/src/index.ts +11 -0
- package/src/react/index.ts +10 -0
- package/src/react/rbac.tsx +49 -0
- package/src/react/routes.tsx +49 -0
- package/src/routes/createRouteAccess.ts +57 -0
- package/src/routes/fromRows.ts +61 -0
- package/src/routes/index.ts +5 -0
- package/src/routes/matching/path.ts +48 -0
- package/src/routes/matching/pattern.ts +67 -0
- package/src/routes/rules.ts +62 -0
- package/src/routes/types.ts +35 -0
- package/src/shared/errors.ts +17 -0
- package/src/shared/roles.ts +92 -0
- package/src/shared/validate.ts +37 -0
- package/dist/routes/pattern.js.map +0 -1
package/README.md
CHANGED
|
@@ -10,7 +10,8 @@ It answers two kinds of questions, and you can use either one on its own or both
|
|
|
10
10
|
What you get either way:
|
|
11
11
|
|
|
12
12
|
- **Deny always wins**, including over rules a role inherits from another one.
|
|
13
|
-
- **Mistakes fail early.** Unknown roles, circular `extends
|
|
13
|
+
- **Mistakes fail early.** Unknown roles, circular `extends`, broken route patterns and rules of the wrong shape throw when the config is created, not halfway through a request.
|
|
14
|
+
- **Paths are read like a server reads them.** `/public/../admin`, `/public/%2e%2e/admin` and `/ADMIN` can't sneak past your rules.
|
|
14
15
|
- **No runtime dependencies.** React is an optional peer dependency, and Express isn't needed at all.
|
|
15
16
|
|
|
16
17
|
```bash
|
|
@@ -70,8 +71,8 @@ Pick the page that matches what you're building:
|
|
|
70
71
|
|
|
71
72
|
| Import from | What's there |
|
|
72
73
|
| --- | --- |
|
|
73
|
-
| `rolegate` | `createRbac`, `createRouteAccess`, `routeConfigFromRows`, `ForbiddenError` |
|
|
74
|
-
| `rolegate/express` | `requirePermission` (one action), `guardRoutes` (many routes at once) |
|
|
74
|
+
| `rolegate` | `createRbac`, `createRouteAccess`, `routeConfigFromRows`, `normalizePath`, `ForbiddenError` |
|
|
75
|
+
| `rolegate/express` | `requirePermission` (one action), `guardRoutes` (many routes at once, can skip `OPTIONS` for CORS) |
|
|
75
76
|
| `rolegate/react` | `RbacProvider`, `useCan`, `<Can>`, `RouteAccessProvider`, `useCanVisit`, `<CanVisit>` |
|
|
76
77
|
|
|
77
78
|
## How a decision is made
|
|
@@ -84,6 +85,7 @@ The same rules apply to both kinds of checks:
|
|
|
84
85
|
| Any role denies it | denied, even if another role allows it |
|
|
85
86
|
| A role `extends` another one | it gets all of that role's allows **and** denies |
|
|
86
87
|
| A role that isn't in the config, or no role at all | denied |
|
|
88
|
+
| A path with broken encoding, like `/posts/%zz` | denied |
|
|
87
89
|
|
|
88
90
|
## Development
|
|
89
91
|
|
|
@@ -98,13 +100,24 @@ Project layout:
|
|
|
98
100
|
|
|
99
101
|
```
|
|
100
102
|
src/
|
|
101
|
-
shared/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
shared/ used by both engines
|
|
104
|
+
roles.ts role inheritance and the "deny wins" rule
|
|
105
|
+
validate.ts config shape checks, the "__proto__" guard
|
|
106
|
+
errors.ts ForbiddenError
|
|
107
|
+
core/ createRbac: actions on resources
|
|
108
|
+
createRbac.ts the checker itself
|
|
109
|
+
rules.ts how resource rules are checked, indexed and matched
|
|
110
|
+
routes/ createRouteAccess: pages and API routes
|
|
111
|
+
matching/
|
|
112
|
+
path.ts how a request path is read: decoding, "..", case
|
|
113
|
+
pattern.ts "/posts/:id", "/admin/*" and friends
|
|
114
|
+
rules.ts compiling route rules, methods, HEAD as GET
|
|
115
|
+
createRouteAccess.ts
|
|
116
|
+
fromRows.ts rows from a database -> config
|
|
117
|
+
express/ requirePermission and guardRoutes
|
|
118
|
+
react/ providers, hooks and components
|
|
119
|
+
docs/ usage guides
|
|
120
|
+
test/ same folders as src/, plus helpers/ for shared test utilities
|
|
108
121
|
```
|
|
109
122
|
|
|
110
123
|
## Status
|
|
@@ -4,5 +4,8 @@ import type { Context, Rbac, RbacConfig } from './types.js';
|
|
|
4
4
|
*
|
|
5
5
|
* const rbac = createRbac({ roles: { editor: { allow: { posts: ['read', 'write'] } } } });
|
|
6
6
|
* rbac.can('editor', 'posts', 'write'); // true
|
|
7
|
+
*
|
|
8
|
+
* The config is checked here, so a typo throws on startup.
|
|
7
9
|
*/
|
|
8
10
|
export declare function createRbac<C extends Context = Context>(config: RbacConfig<C>): Rbac<C>;
|
|
11
|
+
//# sourceMappingURL=createRbac.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRbac.d.ts","sourceRoot":"","sources":["../../src/core/createRbac.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAO5D;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAoCtF"}
|
package/dist/core/createRbac.js
CHANGED
|
@@ -1,53 +1,33 @@
|
|
|
1
1
|
import { ForbiddenError } from '../shared/errors.js';
|
|
2
2
|
import { decide, pickRoles, resolveRoles } from '../shared/roles.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return Object.entries(rules).flatMap(([resource, list]) => list.map((rule) => ({ resource, rule })));
|
|
6
|
-
}
|
|
7
|
-
function toIndex(entries) {
|
|
8
|
-
const index = new Map();
|
|
9
|
-
for (const { resource, rule } of entries) {
|
|
10
|
-
const list = index.get(resource);
|
|
11
|
-
if (list)
|
|
12
|
-
list.push(rule);
|
|
13
|
-
else
|
|
14
|
-
index.set(resource, [rule]);
|
|
15
|
-
}
|
|
16
|
-
return index;
|
|
17
|
-
}
|
|
18
|
-
function matches(index, resource, action, ctx) {
|
|
19
|
-
// Look at rules for this exact resource and at the "any resource" ones.
|
|
20
|
-
const keys = resource === ANY ? [ANY] : [resource, ANY];
|
|
21
|
-
for (const key of keys) {
|
|
22
|
-
for (const rule of index.get(key) ?? []) {
|
|
23
|
-
const name = typeof rule === 'string' ? rule : rule.action;
|
|
24
|
-
if (name !== ANY && name !== action)
|
|
25
|
-
continue;
|
|
26
|
-
const when = typeof rule === 'string' ? undefined : rule.when;
|
|
27
|
-
if (!when || when(ctx))
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
3
|
+
import { checkRolesObject, dictionary } from '../shared/validate.js';
|
|
4
|
+
import { matches, toEntries, toIndex } from './rules.js';
|
|
33
5
|
/**
|
|
34
6
|
* Builds the resource/action checker:
|
|
35
7
|
*
|
|
36
8
|
* const rbac = createRbac({ roles: { editor: { allow: { posts: ['read', 'write'] } } } });
|
|
37
9
|
* rbac.can('editor', 'posts', 'write'); // true
|
|
10
|
+
*
|
|
11
|
+
* The config is checked here, so a typo throws on startup.
|
|
38
12
|
*/
|
|
39
13
|
export function createRbac(config) {
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
const definitions =
|
|
14
|
+
checkRolesObject(config?.roles);
|
|
15
|
+
// flat lists for the shared role code (extends, deny wins)
|
|
16
|
+
const definitions = dictionary();
|
|
43
17
|
for (const [name, role] of Object.entries(config.roles)) {
|
|
44
|
-
definitions[name] = {
|
|
18
|
+
definitions[name] = {
|
|
19
|
+
extends: role.extends,
|
|
20
|
+
allow: toEntries(role.allow, `allow of role "${name}"`),
|
|
21
|
+
deny: toEntries(role.deny, `deny of role "${name}"`),
|
|
22
|
+
};
|
|
45
23
|
}
|
|
24
|
+
// and back to "by resource" for fast checks
|
|
46
25
|
const known = new Map();
|
|
47
26
|
for (const [name, role] of resolveRoles(definitions)) {
|
|
48
27
|
known.set(name, { allow: toIndex(role.allow), deny: toIndex(role.deny) });
|
|
49
28
|
}
|
|
50
29
|
const can = (roles, resource, action, ctx) => {
|
|
30
|
+
// so `when` never gets undefined
|
|
51
31
|
const context = (ctx ?? {});
|
|
52
32
|
return decide(pickRoles(known, roles), (role) => matches(role.deny, resource, action, context), (role) => matches(role.allow, resource, action, context));
|
|
53
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRbac.js","sourceRoot":"","sources":["../../src/core/createRbac.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
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,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;QAC3D,iCAAiC;QACjC,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,EAAE,CAAM,CAAC;QACjC,OAAO,MAAM,CACX,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,EACvB,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EACvD,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CACzD,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,GAAG;QACH,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG;YACjC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC;gBAAE,MAAM,IAAI,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACrF,CAAC;QACD,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;KACjC,CAAC;AACJ,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Context, ResourceRules, Rule } from './types.js';
|
|
2
|
+
/** '*' means "any resource" in the resource slot and "any action" in the action slot. */
|
|
3
|
+
export declare const ANY = "*";
|
|
4
|
+
/** One rule together with the resource it was written for. */
|
|
5
|
+
export interface Entry<C extends Context> {
|
|
6
|
+
resource: string;
|
|
7
|
+
rule: Rule<C>;
|
|
8
|
+
}
|
|
9
|
+
/** Rules grouped by resource name. */
|
|
10
|
+
export type RuleIndex<C extends Context> = Map<string, Rule<C>[]>;
|
|
11
|
+
/** `{ posts: ['read'] }` -> `[{ resource: 'posts', rule: 'read' }]`, checking the shape on the way. */
|
|
12
|
+
export declare function toEntries<C extends Context>(rules: ResourceRules<C> | undefined, where: string): Entry<C>[];
|
|
13
|
+
/** Groups the flat entries back by resource. */
|
|
14
|
+
export declare function toIndex<C extends Context>(entries: Entry<C>[]): RuleIndex<C>;
|
|
15
|
+
/** Is there a rule for this resource and action whose condition (if any) holds? */
|
|
16
|
+
export declare function matches<C extends Context>(index: RuleIndex<C>, resource: string, action: string, ctx: C): boolean;
|
|
17
|
+
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/core/rules.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAE/D,yFAAyF;AACzF,eAAO,MAAM,GAAG,MAAM,CAAC;AAEvB,8DAA8D;AAC9D,MAAM,WAAW,KAAK,CAAC,CAAC,SAAS,OAAO;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;CACf;AAED,sCAAsC;AACtC,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,OAAO,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAElE,uGAAuG;AACvG,wBAAgB,SAAS,CAAC,CAAC,SAAS,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAS3G;AAED,gDAAgD;AAChD,wBAAgB,OAAO,CAAC,CAAC,SAAS,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAQ5E;AAED,mFAAmF;AACnF,wBAAgB,OAAO,CAAC,CAAC,SAAS,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAejH"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Rules are grouped by resource in the config: { posts: ['read'] }.
|
|
2
|
+
// The shared role code wants a flat list, so we flatten them, apply
|
|
3
|
+
// inheritance, then group them back by resource for fast lookups.
|
|
4
|
+
import { configError, isObject } from '../shared/validate.js';
|
|
5
|
+
/** '*' means "any resource" in the resource slot and "any action" in the action slot. */
|
|
6
|
+
export const ANY = '*';
|
|
7
|
+
/** `{ posts: ['read'] }` -> `[{ resource: 'posts', rule: 'read' }]`, checking the shape on the way. */
|
|
8
|
+
export function toEntries(rules, where) {
|
|
9
|
+
if (rules === undefined)
|
|
10
|
+
return [];
|
|
11
|
+
if (!isObject(rules))
|
|
12
|
+
configError(`${where} should be an object like { posts: ['read'] }`);
|
|
13
|
+
return Object.entries(rules).flatMap(([resource, list]) => {
|
|
14
|
+
if (!Array.isArray(list))
|
|
15
|
+
configError(`rules for "${resource}" should be a list (${where})`);
|
|
16
|
+
for (const rule of list)
|
|
17
|
+
checkRule(rule, `${where}, resource "${resource}"`);
|
|
18
|
+
return list.map((rule) => ({ resource, rule }));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** Groups the flat entries back by resource. */
|
|
22
|
+
export function toIndex(entries) {
|
|
23
|
+
const index = new Map();
|
|
24
|
+
for (const { resource, rule } of entries) {
|
|
25
|
+
const list = index.get(resource);
|
|
26
|
+
if (list)
|
|
27
|
+
list.push(rule);
|
|
28
|
+
else
|
|
29
|
+
index.set(resource, [rule]);
|
|
30
|
+
}
|
|
31
|
+
return index;
|
|
32
|
+
}
|
|
33
|
+
/** Is there a rule for this resource and action whose condition (if any) holds? */
|
|
34
|
+
export function matches(index, resource, action, ctx) {
|
|
35
|
+
// this resource plus the '*' ones
|
|
36
|
+
const keys = resource === ANY ? [ANY] : [resource, ANY];
|
|
37
|
+
for (const key of keys) {
|
|
38
|
+
for (const rule of index.get(key) ?? []) {
|
|
39
|
+
if (typeof rule === 'string') {
|
|
40
|
+
if (rule === ANY || rule === action)
|
|
41
|
+
return true;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (rule.action !== ANY && rule.action !== action)
|
|
45
|
+
continue;
|
|
46
|
+
if (!rule.when || rule.when(ctx))
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
function checkRule(rule, where) {
|
|
53
|
+
if (typeof rule === 'string')
|
|
54
|
+
return;
|
|
55
|
+
if (!isObject(rule) || typeof rule.action !== 'string') {
|
|
56
|
+
configError(`a rule should be an action name or { action, when? } (${where})`);
|
|
57
|
+
}
|
|
58
|
+
if (rule.when !== undefined && typeof rule.when !== 'function') {
|
|
59
|
+
configError(`"when" for action "${rule.action}" should be a function (${where})`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/core/rules.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,oEAAoE;AACpE,kEAAkE;AAElE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAG9D,yFAAyF;AACzF,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAC;AAWvB,uGAAuG;AACvG,MAAM,UAAU,SAAS,CAAoB,K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C,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IACtE,uCAAuC;IACvC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC"}
|
|
@@ -10,6 +10,11 @@ export interface GuardRoutesOptions<Req = RequestLike> {
|
|
|
10
10
|
* The query string isn't part of it.
|
|
11
11
|
*/
|
|
12
12
|
getPath?: (req: Req) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Methods to let through without a check, e.g. `['OPTIONS']` for CORS preflights
|
|
15
|
+
* (they come without a token). Empty by default. Putting `cors()` above the guard works too.
|
|
16
|
+
*/
|
|
17
|
+
skipMethods?: readonly string[];
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
20
|
* One middleware for many routes. It looks at the method and path of each
|
|
@@ -24,3 +29,4 @@ export interface GuardRoutesOptions<Req = RequestLike> {
|
|
|
24
29
|
* like login go above it, or get allowed for a "guest" role (see the docs).
|
|
25
30
|
*/
|
|
26
31
|
export declare function guardRoutes<Req = RequestLike>(access: Source<RouteAccess>, options?: GuardRoutesOptions<Req>): (req: Req, res: ResponseLike, next: NextLike) => void;
|
|
32
|
+
//# sourceMappingURL=guardRoutes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardRoutes.d.ts","sourceRoot":"","sources":["../../src/express/guardRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAE9E,MAAM,WAAW,kBAAkB,CAAC,GAAG,GAAG,WAAW;IACnD,kFAAkF;IAClF,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,KAAK,CAAC;IAC/B;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC;IAC/B;;;OAGG;IACH,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACjC;AAOD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,GAAG,GAAG,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,OAAO,GAAE,kBAAkB,CAAC,GAAG,CAAM,IAKvG,KAAK,GAAG,EAAE,KAAK,YAAY,EAAE,MAAM,QAAQ,KAAG,IAAI,CAoB3D"}
|
|
@@ -18,14 +18,19 @@ function defaultGetPath(req) {
|
|
|
18
18
|
export function guardRoutes(access, options = {}) {
|
|
19
19
|
const getRoles = options.getRoles ?? defaultGetRoles;
|
|
20
20
|
const getPath = options.getPath ?? defaultGetPath;
|
|
21
|
+
const skip = new Set((options.skipMethods ?? []).map((m) => m.toUpperCase()));
|
|
21
22
|
return (req, res, next) => {
|
|
23
|
+
const method = req.method ?? 'GET';
|
|
24
|
+
if (skip.has(method.toUpperCase())) {
|
|
25
|
+
next();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
22
28
|
const roles = getRoles(req);
|
|
23
29
|
if (hasNoRoles(roles)) {
|
|
24
30
|
res.status(401).json({ error: 'Unauthorized' });
|
|
25
31
|
return;
|
|
26
32
|
}
|
|
27
33
|
const path = getPath(req);
|
|
28
|
-
const method = req.method ?? 'GET';
|
|
29
34
|
if (!read(access).can(roles, path, method)) {
|
|
30
35
|
res.status(403).json({ error: 'Forbidden', path, method });
|
|
31
36
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guardRoutes.js","sourceRoot":"","sources":["../../src/express/guardRoutes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"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CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;YAC3C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YAC3D,OAAO;QACT,CAAC;QACD,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/express/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export type { RequirePermissionOptions } from './requirePermission.js';
|
|
|
3
3
|
export { guardRoutes } from './guardRoutes.js';
|
|
4
4
|
export type { GuardRoutesOptions } from './guardRoutes.js';
|
|
5
5
|
export type { RequestLike, ResponseLike, NextLike, Source } from './types.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/express/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGvE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -18,3 +18,4 @@ export interface RequirePermissionOptions<C extends Context = Context, Req = Req
|
|
|
18
18
|
* e.g. `getContext: (req: express.Request) => ({ ... })`.
|
|
19
19
|
*/
|
|
20
20
|
export declare function requirePermission<C extends Context = Context, Req = RequestLike>(rbac: Source<Rbac<C>>, resource: string, action: string, options?: RequirePermissionOptions<C, Req>): (req: Req, res: ResponseLike, next: NextLike) => void;
|
|
21
|
+
//# sourceMappingURL=requirePermission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requirePermission.d.ts","sourceRoot":"","sources":["../../src/express/requirePermission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAE9E,MAAM,WAAW,wBAAwB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,GAAG,GAAG,WAAW;IACtF,kFAAkF;IAClF,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,KAAK,CAAC;IAC/B,0DAA0D;IAC1D,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC;CAC1C;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,GAAG,GAAG,WAAW,EAC9E,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EACrB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,wBAAwB,CAAC,CAAC,EAAE,GAAG,CAAM,IAItC,KAAK,GAAG,EAAE,KAAK,YAAY,EAAE,MAAM,QAAQ,KAAG,IAAI,CAY3D"}
|
package/dist/express/types.d.ts
CHANGED
|
@@ -29,4 +29,6 @@ export type Source<T> = T | (() => T);
|
|
|
29
29
|
export declare function read<T extends object>(source: Source<T>): T;
|
|
30
30
|
/** By default we expect your auth middleware to put roles on req.user. */
|
|
31
31
|
export declare function defaultGetRoles(req: unknown): Roles;
|
|
32
|
+
/** No usable role name means not signed in, so `['']` or `[null]` is a 401 too. */
|
|
32
33
|
export declare function hasNoRoles(roles: Roles): boolean;
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/express/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,IAAI,CAAC;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;IACnC,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;CAC9B;AAED,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAEtC,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAE3D;AAED,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAGnD;AAED,mFAAmF;AACnF,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEhD"}
|
package/dist/express/types.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { roleNames } from '../shared/roles.js';
|
|
1
2
|
export function read(source) {
|
|
2
3
|
return typeof source === 'function' ? source() : source;
|
|
3
4
|
}
|
|
@@ -6,7 +7,8 @@ export function defaultGetRoles(req) {
|
|
|
6
7
|
const user = req.user;
|
|
7
8
|
return user?.roles ?? user?.role;
|
|
8
9
|
}
|
|
10
|
+
/** No usable role name means not signed in, so `['']` or `[null]` is a 401 too. */
|
|
9
11
|
export function hasNoRoles(roles) {
|
|
10
|
-
return
|
|
12
|
+
return roleNames(roles).length === 0;
|
|
11
13
|
}
|
|
12
14
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/express/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/express/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AA+B/C,MAAM,UAAU,IAAI,CAAmB,MAAiB;IACtD,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAE,MAAkB,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AACvE,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,MAAM,IAAI,GAAI,GAAmB,CAAC,IAAI,CAAC;IACvC,OAAO,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,IAAI,CAAC;AACnC,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,UAAU,CAAC,KAAY;IACrC,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,iBAAiB,CAAC;AAGhC,cAAc,mBAAmB,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { RbacProvider, useCan, Can } from './rbac.js';
|
|
|
2
2
|
export type { RbacProviderProps, CanProps } from './rbac.js';
|
|
3
3
|
export { RouteAccessProvider, useCanVisit, CanVisit } from './routes.js';
|
|
4
4
|
export type { RouteAccessProviderProps, CanVisitProps } from './routes.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACtD,YAAY,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAG7D,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACzE,YAAY,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/react/rbac.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rbac.d.ts","sourceRoot":"","sources":["../../src/react/rbac.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAShD,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IAC5D,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACd,yEAAyE;IACzE,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,6DAA6D;AAC7D,wBAAgB,YAAY,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC,+BAGxG;AAED,oEAAoE;AACpE,wBAAgB,MAAM,eAIP,MAAM,UAAU,MAAM,QAAQ,OAAO,aAGnD;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,qEAAqE;AACrE,wBAAgB,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,QAAe,EAAE,QAAQ,EAAE,EAAE,QAAQ,+BAGjF"}
|
package/dist/react/routes.d.ts
CHANGED
|
@@ -24,3 +24,4 @@ export interface CanVisitProps {
|
|
|
24
24
|
}
|
|
25
25
|
/** Shows its children only if the current user can open `path`. Good for links and menu items. */
|
|
26
26
|
export declare function CanVisit({ path, fallback, children }: CanVisitProps): import("react").JSX.Element;
|
|
27
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/react/routes.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAShD,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,WAAW,CAAC;IACpB,2EAA2E;IAC3E,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,+BAGxF;AAED,kFAAkF;AAClF,wBAAgB,WAAW,WAGC,MAAM,aACjC;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,kGAAkG;AAClG,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAe,EAAE,QAAQ,EAAE,EAAE,aAAa,+BAG1E"}
|
|
@@ -10,5 +10,8 @@ import type { RouteAccess, RouteAccessConfig } from './types.js';
|
|
|
10
10
|
* });
|
|
11
11
|
* pages.can('user', '/posts/42'); // true
|
|
12
12
|
* pages.can('user', '/admin/users'); // false
|
|
13
|
+
*
|
|
14
|
+
* Rules are compiled here, so a broken one throws on startup.
|
|
13
15
|
*/
|
|
14
16
|
export declare function createRouteAccess(config: RouteAccessConfig): RouteAccess;
|
|
17
|
+
//# sourceMappingURL=createRouteAccess.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRouteAccess.d.ts","sourceRoot":"","sources":["../../src/routes/createRouteAccess.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEjE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW,CAiCxE"}
|
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
import { ForbiddenError } from '../shared/errors.js';
|
|
2
2
|
import { decide, pickRoles, resolveRoles } from '../shared/roles.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// Express runs GET handlers for HEAD requests, so HEAD has to obey GET rules,
|
|
7
|
-
// otherwise a HEAD request would get around a GET deny.
|
|
8
|
-
return upper === 'HEAD' ? 'GET' : upper;
|
|
9
|
-
}
|
|
10
|
-
function compileRule(rule, role) {
|
|
11
|
-
try {
|
|
12
|
-
if (typeof rule === 'string')
|
|
13
|
-
return { pattern: compilePattern(rule), methods: null };
|
|
14
|
-
const pattern = compilePattern(rule.path);
|
|
15
|
-
if (!rule.methods || rule.methods.includes('*'))
|
|
16
|
-
return { pattern, methods: null };
|
|
17
|
-
if (rule.methods.length === 0)
|
|
18
|
-
throw new Error(`rolegate: "methods" for "${rule.path}" is empty`);
|
|
19
|
-
return { pattern, methods: new Set(rule.methods.map(normalizeMethod)) };
|
|
20
|
-
}
|
|
21
|
-
catch (err) {
|
|
22
|
-
// Say which role the bad rule belongs to. With rules from a database,
|
|
23
|
-
// that's the first thing you'll want to know.
|
|
24
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
25
|
-
throw new Error(`${message} (in role "${role}")`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function hits(rules, path, method) {
|
|
29
|
-
return rules.some((r) => (r.methods === null || r.methods.has(method)) && r.pattern.test(path));
|
|
30
|
-
}
|
|
3
|
+
import { checkRolesObject, dictionary } from '../shared/validate.js';
|
|
4
|
+
import { splitPath } from './matching/path.js';
|
|
5
|
+
import { compileRules, hits, normalizeMethod } from './rules.js';
|
|
31
6
|
/**
|
|
32
7
|
* Builds the route checker:
|
|
33
8
|
*
|
|
@@ -39,26 +14,33 @@ function hits(rules, path, method) {
|
|
|
39
14
|
* });
|
|
40
15
|
* pages.can('user', '/posts/42'); // true
|
|
41
16
|
* pages.can('user', '/admin/users'); // false
|
|
17
|
+
*
|
|
18
|
+
* Rules are compiled here, so a broken one throws on startup.
|
|
42
19
|
*/
|
|
43
20
|
export function createRouteAccess(config) {
|
|
44
|
-
|
|
21
|
+
checkRolesObject(config?.roles);
|
|
22
|
+
const definitions = dictionary();
|
|
45
23
|
for (const [name, role] of Object.entries(config.roles)) {
|
|
46
24
|
definitions[name] = {
|
|
47
25
|
extends: role.extends,
|
|
48
|
-
allow: (role.allow
|
|
49
|
-
deny: (role.deny
|
|
26
|
+
allow: compileRules(role.allow, name, 'allow'),
|
|
27
|
+
deny: compileRules(role.deny, name, 'deny'),
|
|
50
28
|
};
|
|
51
29
|
}
|
|
52
30
|
const known = resolveRoles(definitions);
|
|
53
31
|
const can = (roles, path, method = 'GET') => {
|
|
32
|
+
// can't decode the path - can't know where it goes, so no
|
|
33
|
+
const segments = splitPath(path);
|
|
34
|
+
if (segments === null || typeof method !== 'string')
|
|
35
|
+
return false;
|
|
54
36
|
const m = normalizeMethod(method);
|
|
55
|
-
return decide(pickRoles(known, roles), (role) => hits(role.deny,
|
|
37
|
+
return decide(pickRoles(known, roles), (role) => hits(role.deny, segments, m), (role) => hits(role.allow, segments, m));
|
|
56
38
|
};
|
|
57
39
|
return {
|
|
58
40
|
can,
|
|
59
41
|
assert(roles, path, method = 'GET') {
|
|
60
42
|
if (!can(roles, path, method))
|
|
61
|
-
throw new ForbiddenError(path, method.toUpperCase());
|
|
43
|
+
throw new ForbiddenError(path, String(method).toUpperCase());
|
|
62
44
|
},
|
|
63
45
|
roles: Object.keys(config.roles),
|
|
64
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRouteAccess.js","sourceRoot":"","sources":["../../src/routes/createRouteAccess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"createRouteAccess.js","sourceRoot":"","sources":["../../src/routes/createRouteAccess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;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C,CAAC;IAEF,OAAO;QACL,GAAG;QACH,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK;YAChC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC;gBAAE,MAAM,IAAI,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;QAC9F,CAAC;QACD,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;KACjC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromRows.d.ts","sourceRoot":"","sources":["../../src/routes/fromRows.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,YAAY,CAAC;AAErE;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,2BAA2B;IAC3B,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,+EAA+E;IAC/E,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACpC;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAE,eAAoB,GAAG,iBAAiB,CA8B9G"}
|
package/dist/routes/fromRows.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkRoleName, configError, dictionary, isObject } from '../shared/validate.js';
|
|
1
2
|
/**
|
|
2
3
|
* Turns flat table rows into a config for `createRouteAccess`.
|
|
3
4
|
*
|
|
@@ -8,19 +9,32 @@
|
|
|
8
9
|
* tells you which role has the broken one.
|
|
9
10
|
*/
|
|
10
11
|
export function routeConfigFromRows(rows, options = {}) {
|
|
11
|
-
|
|
12
|
-
const
|
|
12
|
+
// no prototype: with a plain {} a "__proto__" row would write into Object.prototype
|
|
13
|
+
const roles = dictionary();
|
|
14
|
+
const roleFor = (name, where) => {
|
|
15
|
+
checkRoleName(name, where);
|
|
16
|
+
return (roles[name] ?? (roles[name] = {}));
|
|
17
|
+
};
|
|
13
18
|
for (const row of rows) {
|
|
19
|
+
if (!isObject(row))
|
|
20
|
+
configError('every row should be an object like { role, path }');
|
|
21
|
+
// rows come from a DB, so TypeScript can't check them for us
|
|
22
|
+
const where = `row for role "${row.role}" on "${row.path}"`;
|
|
23
|
+
if (typeof row.path !== 'string')
|
|
24
|
+
configError(`"path" should be a string (${where})`);
|
|
25
|
+
if (row.method != null && typeof row.method !== 'string')
|
|
26
|
+
configError(`"method" should be a string (${where})`);
|
|
14
27
|
const effect = row.effect ?? 'allow';
|
|
15
|
-
if (effect !== 'allow' && effect !== 'deny')
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const role = roleFor(row.role);
|
|
28
|
+
if (effect !== 'allow' && effect !== 'deny')
|
|
29
|
+
configError(`unknown effect "${effect}" (${where})`);
|
|
30
|
+
const role = roleFor(row.role, where);
|
|
19
31
|
const list = (role[effect] ?? (role[effect] = []));
|
|
20
32
|
list.push(row.method ? { path: row.path, methods: [row.method] } : row.path);
|
|
21
33
|
}
|
|
22
34
|
for (const [name, parents] of Object.entries(options.extends ?? {})) {
|
|
23
|
-
|
|
35
|
+
if (!Array.isArray(parents))
|
|
36
|
+
configError(`parents of role "${name}" should be a list`);
|
|
37
|
+
roleFor(name, 'in options.extends').extends = [...parents];
|
|
24
38
|
}
|
|
25
39
|
return { roles };
|
|
26
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromRows.js","sourceRoot":"","sources":["../../src/routes/fromRows.ts"],"names":[],"mappings":"
|
|
1
|
+
{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C;QACtC,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,MAAX,IAAI,CAAC,MAAM,IAAM,EAAE,EAAC,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/E,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;QACpE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;YAAE,WAAW,CAAC,oBAAoB,IAAI,oBAAoB,CAAC,CAAC;QACvF,OAAO,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC,OAAO,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC"}
|
package/dist/routes/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createRouteAccess } from './createRouteAccess.js';
|
|
2
2
|
export { routeConfigFromRows } from './fromRows.js';
|
|
3
|
-
export { normalizePath } from './
|
|
3
|
+
export { normalizePath } from './matching/path.js';
|
|
4
4
|
export type { RouteAccess, RouteAccessConfig, RouteRoleConfig, RouteRule } from './types.js';
|
|
5
5
|
export type { RouteRow, FromRowsOptions } from './fromRows.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|