@dudousxd/nestjs-authz-codegen 0.2.0 → 0.3.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/CHANGELOG.md +19 -0
- package/README.md +16 -5
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +106 -53
- package/dist/index.js.map +1 -1
- package/package.json +23 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @dudousxd/nestjs-authz-codegen
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#67](https://github.com/DavideCarvalho/nestjs-authz/pull/67) [`32e967f`](https://github.com/DavideCarvalho/nestjs-authz/commit/32e967ffbcd68a97e8effc77af9c16bbbafdc918) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Abilities of a policy without a `@PolicyFor(Resource)` link are now emitted model-less instead of
|
|
8
|
+
under a resource guessed from the class name (`InvoicePolicy` → `Invoice`). The `Gate` (and the
|
|
9
|
+
`can()` endpoint) resolves a string ability on a resource only through that link, so the guessed
|
|
10
|
+
keys could never resolve. Add `@PolicyFor(Invoice)` to keep the resource key.
|
|
11
|
+
|
|
12
|
+
- [#67](https://github.com/DavideCarvalho/nestjs-authz/pull/67) [`32e967f`](https://github.com/DavideCarvalho/nestjs-authz/commit/32e967ffbcd68a97e8effc77af9c16bbbafdc918) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Type client abilities from the official `@Can(Policy, 'ability', byId(Resource))`,
|
|
13
|
+
`@Permission` / `PermissionPolicy` permission names, `GatePolicy` abilities and
|
|
14
|
+
`@Policy()` / `@PolicyFor()` classes (skipping `before` and `scope`). The 0.8 string
|
|
15
|
+
`@Can('update', Post)` and `@Policy(Post)` are no longer read; a policy's resource comes from
|
|
16
|
+
`@PolicyFor(Resource)` (else its name). Peers on `@dudousxd/nestjs-authz` `>=0.9.0 <0.10.0`.
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- [#67](https://github.com/DavideCarvalho/nestjs-authz/pull/67) [`32e967f`](https://github.com/DavideCarvalho/nestjs-authz/commit/32e967ffbcd68a97e8effc77af9c16bbbafdc918) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Fix packages that could be published without files their `exports` point to. `tsc` builds no longer use a `.tsbuildinfo` that can outlive `dist/` and skip emitting files. A new `check:exports` step (also `prepack`) fails the release if any `exports`/`main`/`types` path is missing.
|
|
21
|
+
|
|
3
22
|
## 0.2.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
A [`@dudousxd/nestjs-codegen`](https://www.npmjs.com/package/@dudousxd/nestjs-codegen) **extension**
|
|
4
4
|
that discovers the authorization abilities declared with
|
|
5
5
|
[`@dudousxd/nestjs-authz`](https://github.com/DavideCarvalho/nestjs-authz)'s
|
|
6
|
-
`@Can(ability,
|
|
6
|
+
official `@Can(Policy, 'ability', ...)` decorators (from `@nestjs/authorization`), the
|
|
7
|
+
`@Permission(...)` sugar and, optionally, the abilities of `@Policy()` / `@PolicyFor(Resource)`
|
|
8
|
+
classes, and emits a typed `can()`
|
|
7
9
|
helper into your generated `api.ts` — so checking a permission on the frontend is a compile-time
|
|
8
10
|
type, not a magic string.
|
|
9
11
|
|
|
@@ -30,21 +32,30 @@ export default defineConfig({
|
|
|
30
32
|
|
|
31
33
|
## What it emits
|
|
32
34
|
|
|
33
|
-
Given controllers decorated with `@Can(...)`:
|
|
35
|
+
Given controllers decorated with the official `@Can(...)`:
|
|
34
36
|
|
|
35
37
|
```ts
|
|
36
38
|
@Controller('posts')
|
|
37
39
|
export class PostsController {
|
|
38
40
|
@Patch(':id')
|
|
39
|
-
@Can('update', Post)
|
|
41
|
+
@Can(PostPolicy, 'update', byId(Post)) // → 'update' on Post
|
|
40
42
|
update() {}
|
|
41
43
|
|
|
42
44
|
@Post(':id/publish')
|
|
43
|
-
@Can('access-admin')
|
|
45
|
+
@Can(GatePolicy, 'allows', ability('access-admin')) // → 'access-admin'
|
|
44
46
|
publish() {}
|
|
45
47
|
}
|
|
46
48
|
```
|
|
47
49
|
|
|
50
|
+
How each form maps to a client ability:
|
|
51
|
+
|
|
52
|
+
| Decorator | Client ability |
|
|
53
|
+
| --- | --- |
|
|
54
|
+
| `@Can(PostPolicy, 'update', byId(Post))` | `update` on `Post` (from `byId`, else the policy's `@PolicyFor` link, else `PostPolicy` → `Post`) |
|
|
55
|
+
| `@Can(PermissionPolicy, 'has', permission('posts.publish'))`, `@Permission('posts.publish')` | `posts.publish` |
|
|
56
|
+
| `@Can(GatePolicy, 'allows', ability('access-admin'))` | `access-admin` |
|
|
57
|
+
| `@Roles(...)`, `@Can(RolePolicy, ...)` | none (roles are not client abilities) |
|
|
58
|
+
|
|
48
59
|
the generated `api.ts` gains:
|
|
49
60
|
|
|
50
61
|
```ts
|
|
@@ -105,7 +116,7 @@ async can(@Body() body: { ability: string; resource?: { type: string; id?: strin
|
|
|
105
116
|
| Option | Default | Description |
|
|
106
117
|
| --- | --- | --- |
|
|
107
118
|
| `endpoint` | `'/authz/can'` | Server endpoint the generated `can()` POSTs to (expects `{ allowed }`). |
|
|
108
|
-
| `discoverPolicies` | `true` | Also
|
|
119
|
+
| `discoverPolicies` | `true` | Also list the methods of `@Policy()` / `@PolicyFor(Resource)` classes (but `before` and `scope`) as abilities. |
|
|
109
120
|
|
|
110
121
|
## Caveats
|
|
111
122
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { CodegenExtension } from '@dudousxd/nestjs-codegen/extension';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* `@
|
|
6
|
-
*
|
|
3
|
+
* A client ability discovered on a controller route (the official `@Can(Policy, 'ability', ...)`,
|
|
4
|
+
* or `@Permission`), or on a policy class (`@Policy()`,
|
|
5
|
+
* `@PolicyFor(Resource)`). Read statically from the AST: reflect-metadata is not available at
|
|
6
|
+
* codegen time.
|
|
7
7
|
*/
|
|
8
8
|
export interface AuthzAbilityInfo {
|
|
9
9
|
/** The ability string, e.g. `'update'` or `'access-admin'`. */
|
|
10
10
|
ability: string;
|
|
11
|
-
/** The resource class name the ability targets
|
|
11
|
+
/** The resource class name the ability targets (from `byId(Resource)` or the policy's link). */
|
|
12
12
|
resource?: string;
|
|
13
13
|
}
|
|
14
14
|
/** Options for {@link nestjsAuthzCodegen}. */
|
|
@@ -21,15 +21,15 @@ export interface AuthzCodegenOptions {
|
|
|
21
21
|
*/
|
|
22
22
|
endpoint?: string;
|
|
23
23
|
/**
|
|
24
|
-
* Also discover `@Policy(Resource)` classes and treat their public method names as class-level
|
|
24
|
+
* Also discover `@Policy()` / `@PolicyFor(Resource)` classes and treat their public method names as class-level
|
|
25
25
|
* abilities (so e.g. `PostPolicy.publish` contributes `'publish'` to the union even when no
|
|
26
26
|
* route is decorated with it yet). Default `true`.
|
|
27
27
|
*/
|
|
28
28
|
discoverPolicies?: boolean;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* `@dudousxd/nestjs-authz` codegen extension. Discovers every `@Can(ability,
|
|
32
|
-
* on your controllers (and, optionally, `@Policy`
|
|
31
|
+
* `@dudousxd/nestjs-authz` codegen extension. Discovers every official `@Can(Policy, 'ability', ...)`
|
|
32
|
+
* (and `@Permission`) on your controllers (and, optionally, the methods of `@Policy()` classes) and emits a typed `can()` helper
|
|
33
33
|
* into your generated `api.ts`: `ability` is a string-literal union of the discovered abilities, so a
|
|
34
34
|
* wrong ability is a compile error. The runtime `can()` delegates to `@dudousxd/nestjs-authz-client`
|
|
35
35
|
* (a shared `AbilityStore` + `createCan`) — so a hydrated decision answers with no request, and a
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAGjB,MAAM,oCAAoC,CAAC;AAG5C;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAGjB,MAAM,oCAAoC,CAAC;AAG5C;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,gGAAgG;IAChG,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAQD,8CAA8C;AAC9C,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAqPD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,gBAAgB,CAmEtF;AAED,eAAe,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,87 @@
|
|
|
1
|
-
import { Node } from 'ts-morph';
|
|
1
|
+
import { Node, SyntaxKind } from 'ts-morph';
|
|
2
2
|
const DEFAULT_ENDPOINT = '/authz/can';
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
/** Built-in policies whose abilities are not client abilities themselves. */
|
|
4
|
+
const ROLE_POLICY = 'RolePolicy';
|
|
5
|
+
const PERMISSION_POLICY = 'PermissionPolicy';
|
|
6
|
+
const GATE_POLICY = 'GatePolicy';
|
|
7
|
+
/** The string literals among `args`, e.g. `permission('a', 'b')` → `['a', 'b']`. */
|
|
8
|
+
function stringArgs(args) {
|
|
9
|
+
return args.flatMap((a) => (Node.isStringLiteral(a) ? [a.getLiteralValue()] : []));
|
|
10
|
+
}
|
|
11
|
+
/** `byId(Post)` / `staticCanArgs('x')` → its callee name and arguments. */
|
|
12
|
+
function callOf(node) {
|
|
13
|
+
if (!node || !Node.isCallExpression(node))
|
|
14
|
+
return undefined;
|
|
15
|
+
return { name: node.getExpression().getText(), args: node.getArguments() };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The resource a policy class is linked to with `@PolicyFor(Post)`, if any. No guess from the
|
|
19
|
+
* class name: the runtime `Gate` (and so the `can()` endpoint) resolves a string ability on a
|
|
20
|
+
* resource only through that link, so an unlinked policy's abilities are model-less.
|
|
21
|
+
*/
|
|
22
|
+
function resourceOfPolicy(policyName, project) {
|
|
23
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
24
|
+
const classDecl = sourceFile.getClass(policyName);
|
|
25
|
+
if (!classDecl)
|
|
26
|
+
continue;
|
|
27
|
+
const linked = resourceNameFromPolicy(classDecl);
|
|
28
|
+
if (linked)
|
|
29
|
+
return linked;
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Read the client abilities one `@Can(...)` (or sugar) decorator declares:
|
|
35
|
+
*
|
|
36
|
+
* - official `@Can(PostPolicy, 'update', byId(Post))` → `update` on `Post` (from `byId`, else
|
|
37
|
+
* the policy's `@PolicyFor` link, else model-less)
|
|
38
|
+
* - `@Can(PermissionPolicy, 'has', permission('posts.publish'))` / `@Permission('posts.publish')`
|
|
39
|
+
* → the named permissions, model-less
|
|
40
|
+
* - `@Can(GatePolicy, 'allows', ability('access-admin'))` → `access-admin`
|
|
41
|
+
*
|
|
42
|
+
* Roles (`@Roles`, `RolePolicy`) are not client abilities.
|
|
43
|
+
*/
|
|
44
|
+
function readCanDecorator(name, args, project) {
|
|
45
|
+
if (name === 'Permission')
|
|
46
|
+
return stringArgs(args).map((ability) => ({ ability }));
|
|
47
|
+
if (name !== 'Can')
|
|
48
|
+
return [];
|
|
49
|
+
const [first, second, third] = args;
|
|
50
|
+
if (!first)
|
|
51
|
+
return [];
|
|
52
|
+
if (!Node.isIdentifier(first) || !second || !Node.isStringLiteral(second))
|
|
53
|
+
return [];
|
|
54
|
+
const policy = first.getText();
|
|
55
|
+
const ability = second.getLiteralValue();
|
|
56
|
+
const resolver = callOf(third);
|
|
57
|
+
if (policy === ROLE_POLICY)
|
|
58
|
+
return [];
|
|
59
|
+
if (policy === PERMISSION_POLICY || policy === GATE_POLICY) {
|
|
60
|
+
return resolver ? stringArgs(resolver.args).map((a) => ({ ability: a })) : [];
|
|
13
61
|
}
|
|
14
|
-
|
|
62
|
+
const info = { ability };
|
|
63
|
+
const fromById = resolver?.name === 'byId' ? resolver.args[0] : undefined;
|
|
64
|
+
const resource = fromById && Node.isIdentifier(fromById)
|
|
65
|
+
? fromById.getText()
|
|
66
|
+
: resourceOfPolicy(policy, project);
|
|
67
|
+
if (resource)
|
|
68
|
+
info.resource = resource;
|
|
69
|
+
return [info];
|
|
70
|
+
}
|
|
71
|
+
/** Every client ability declared on a method or class, top-down. */
|
|
72
|
+
function abilitiesOn(decorated, project) {
|
|
73
|
+
return decorated
|
|
74
|
+
.getDecorators()
|
|
75
|
+
.flatMap((d) => readCanDecorator(d.getName(), d.getArguments(), project));
|
|
15
76
|
}
|
|
16
77
|
/**
|
|
17
|
-
* Discover the
|
|
18
|
-
*
|
|
19
|
-
* class's) `@Can` decorator. Class-level `@Can` applies when the method has none.
|
|
78
|
+
* Discover the abilities on the controller method backing a route, then on its class
|
|
79
|
+
* (the official guard applies both). The first one is the route's own ability.
|
|
20
80
|
*/
|
|
21
|
-
function
|
|
81
|
+
function discoverRouteAbilities(route, project) {
|
|
22
82
|
const ref = route.controllerRef;
|
|
23
83
|
if (!ref)
|
|
24
|
-
return
|
|
84
|
+
return [];
|
|
25
85
|
let sourceFile;
|
|
26
86
|
try {
|
|
27
87
|
sourceFile = project.addSourceFileAtPathIfExists(ref.filePath) ?? undefined;
|
|
@@ -32,44 +92,34 @@ function discoverRouteAbility(route, project) {
|
|
|
32
92
|
if (!sourceFile)
|
|
33
93
|
sourceFile = project.getSourceFile(ref.filePath);
|
|
34
94
|
if (!sourceFile)
|
|
35
|
-
return
|
|
95
|
+
return [];
|
|
36
96
|
const classDecl = sourceFile.getClass(ref.className);
|
|
37
97
|
if (!classDecl)
|
|
38
|
-
return
|
|
98
|
+
return [];
|
|
39
99
|
const method = classDecl.getMethod(ref.methodName);
|
|
40
|
-
|
|
41
|
-
const dec = method.getDecorators().find((d) => d.getName() === 'Can');
|
|
42
|
-
if (dec) {
|
|
43
|
-
const info = readCanDecorator(dec.getArguments());
|
|
44
|
-
if (info)
|
|
45
|
-
return info;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// Fall back to a class-level `@Can(...)` guarding the whole controller.
|
|
49
|
-
const classDec = classDecl.getDecorators().find((d) => d.getName() === 'Can');
|
|
50
|
-
if (classDec)
|
|
51
|
-
return readCanDecorator(classDec.getArguments());
|
|
52
|
-
return null;
|
|
100
|
+
return [...(method ? abilitiesOn(method, project) : []), ...abilitiesOn(classDecl, project)];
|
|
53
101
|
}
|
|
102
|
+
/** Names that make a class a policy: the official `@Policy()` and `@PolicyFor(X)`. */
|
|
103
|
+
const POLICY_DECORATORS = new Set(['Policy', 'PolicyFor']);
|
|
104
|
+
/** Members of a policy that are not abilities. */
|
|
105
|
+
const NOT_ABILITIES = new Set(['before', 'scope', 'constructor']);
|
|
54
106
|
/**
|
|
55
|
-
* Discover
|
|
56
|
-
* method
|
|
57
|
-
*
|
|
107
|
+
* Discover the abilities of every policy class (`@Policy()`, `@PolicyFor(X)`): each public
|
|
108
|
+
* instance method but `before` and `scope`, keyed to the policy's `@PolicyFor` resource
|
|
109
|
+
* (model-less without one).
|
|
58
110
|
*/
|
|
59
111
|
function discoverPolicyAbilities(project) {
|
|
60
112
|
const found = [];
|
|
61
113
|
for (const sourceFile of project.getSourceFiles()) {
|
|
62
114
|
for (const classDecl of sourceFile.getClasses()) {
|
|
63
|
-
|
|
64
|
-
if (!policyDec)
|
|
115
|
+
if (!classDecl.getDecorators().some((d) => POLICY_DECORATORS.has(d.getName())))
|
|
65
116
|
continue;
|
|
66
|
-
const resource = resourceNameFromPolicy(
|
|
117
|
+
const resource = resourceNameFromPolicy(classDecl);
|
|
67
118
|
for (const method of classDecl.getMethods()) {
|
|
68
|
-
if (method.isStatic())
|
|
119
|
+
if (method.isStatic() || method.hasModifier(SyntaxKind.PrivateKeyword))
|
|
69
120
|
continue;
|
|
70
121
|
const name = method.getName();
|
|
71
|
-
|
|
72
|
-
if (name === 'before')
|
|
122
|
+
if (NOT_ABILITIES.has(name))
|
|
73
123
|
continue;
|
|
74
124
|
const ability = { ability: name };
|
|
75
125
|
if (resource)
|
|
@@ -80,14 +130,15 @@ function discoverPolicyAbilities(project) {
|
|
|
80
130
|
}
|
|
81
131
|
return found;
|
|
82
132
|
}
|
|
83
|
-
/** `@
|
|
84
|
-
function resourceNameFromPolicy(
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
133
|
+
/** `@PolicyFor(Post)` → `'Post'`; `undefined` without the link (the official `@Policy()` alone). */
|
|
134
|
+
function resourceNameFromPolicy(classDecl) {
|
|
135
|
+
for (const decorator of classDecl.getDecorators()) {
|
|
136
|
+
if (decorator.getName() !== 'PolicyFor')
|
|
137
|
+
continue;
|
|
138
|
+
const arg = decorator.getArguments()[0];
|
|
139
|
+
if (arg && Node.isIdentifier(arg))
|
|
140
|
+
return arg.getText();
|
|
141
|
+
}
|
|
91
142
|
return undefined;
|
|
92
143
|
}
|
|
93
144
|
/** The string-literal union of all discovered abilities, e.g. `"update" | "create"` (or `never`). */
|
|
@@ -189,8 +240,8 @@ function markerOf(route) {
|
|
|
189
240
|
return route.contract?.contractSource?.authz;
|
|
190
241
|
}
|
|
191
242
|
/**
|
|
192
|
-
* `@dudousxd/nestjs-authz` codegen extension. Discovers every `@Can(ability,
|
|
193
|
-
* on your controllers (and, optionally, `@Policy`
|
|
243
|
+
* `@dudousxd/nestjs-authz` codegen extension. Discovers every official `@Can(Policy, 'ability', ...)`
|
|
244
|
+
* (and `@Permission`) on your controllers (and, optionally, the methods of `@Policy()` classes) and emits a typed `can()` helper
|
|
194
245
|
* into your generated `api.ts`: `ability` is a string-literal union of the discovered abilities, so a
|
|
195
246
|
* wrong ability is a compile error. The runtime `can()` delegates to `@dudousxd/nestjs-authz-client`
|
|
196
247
|
* (a shared `AbilityStore` + `createCan`) — so a hydrated decision answers with no request, and a
|
|
@@ -224,10 +275,12 @@ export function nestjsAuthzCodegen(options = {}) {
|
|
|
224
275
|
transformRoutes(routes, ctx) {
|
|
225
276
|
const project = ctx.project();
|
|
226
277
|
const out = routes.map((route) => {
|
|
227
|
-
const
|
|
278
|
+
const found = discoverRouteAbilities(route, project);
|
|
279
|
+
for (const each of found)
|
|
280
|
+
record(each);
|
|
281
|
+
const info = found[0];
|
|
228
282
|
if (!info)
|
|
229
283
|
return route;
|
|
230
|
-
record(info);
|
|
231
284
|
const marker = { ability: info.ability };
|
|
232
285
|
if (info.resource)
|
|
233
286
|
marker.resource = info.resource;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAyB,IAAI,EAAiC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAyB,IAAI,EAAiC,UAAU,EAAE,MAAM,UAAU,CAAC;AAsClG,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAEtC,6EAA6E;AAC7E,MAAM,WAAW,GAAG,YAAY,CAAC;AACjC,MAAM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,GAAG,EAAE,IAAI,WAAW,YAAY,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,YAAY,GAAG;gBAChF,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC;aACxC,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC;AAED,eAAe,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-authz-codegen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "nestjs-codegen extension for @dudousxd/nestjs-authz — discovers @Can abilities and emits a typed can() into your generated client.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -8,6 +8,19 @@
|
|
|
8
8
|
"url": "git+https://github.com/DavideCarvalho/nestjs-authz.git",
|
|
9
9
|
"directory": "packages/codegen"
|
|
10
10
|
},
|
|
11
|
+
"homepage": "https://davidecarvalho.github.io/aviary/docs/authz",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/DavideCarvalho/nestjs-authz/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"nestjs",
|
|
17
|
+
"authorization",
|
|
18
|
+
"authz",
|
|
19
|
+
"codegen",
|
|
20
|
+
"extension",
|
|
21
|
+
"can",
|
|
22
|
+
"policy"
|
|
23
|
+
],
|
|
11
24
|
"author": "Davi Carvalho <davi@goflip.ai>",
|
|
12
25
|
"type": "module",
|
|
13
26
|
"main": "./dist/index.js",
|
|
@@ -25,7 +38,7 @@
|
|
|
25
38
|
"CHANGELOG.md"
|
|
26
39
|
],
|
|
27
40
|
"peerDependencies": {
|
|
28
|
-
"@dudousxd/nestjs-authz": ">=0.
|
|
41
|
+
"@dudousxd/nestjs-authz": ">=0.9.0 <0.10.0",
|
|
29
42
|
"@dudousxd/nestjs-authz-client": ">=0.0.0",
|
|
30
43
|
"@dudousxd/nestjs-codegen": ">=0.4.0"
|
|
31
44
|
},
|
|
@@ -35,27 +48,18 @@
|
|
|
35
48
|
}
|
|
36
49
|
},
|
|
37
50
|
"devDependencies": {
|
|
38
|
-
"@dudousxd/nestjs-codegen": "0.
|
|
39
|
-
"ts-morph": "
|
|
40
|
-
"typescript": "
|
|
41
|
-
"vitest": "
|
|
42
|
-
"@dudousxd/nestjs-authz-client": "^0.2.
|
|
43
|
-
"@dudousxd/nestjs-authz": "^0.
|
|
51
|
+
"@dudousxd/nestjs-codegen": "0.25.1",
|
|
52
|
+
"ts-morph": "28.0.0",
|
|
53
|
+
"typescript": "5.9.3",
|
|
54
|
+
"vitest": "3.2.7",
|
|
55
|
+
"@dudousxd/nestjs-authz-client": "^0.2.2",
|
|
56
|
+
"@dudousxd/nestjs-authz": "^0.9.1"
|
|
44
57
|
},
|
|
45
58
|
"engines": {
|
|
46
|
-
"node": ">=
|
|
59
|
+
"node": ">=22"
|
|
47
60
|
},
|
|
48
|
-
"keywords": [
|
|
49
|
-
"nestjs",
|
|
50
|
-
"authorization",
|
|
51
|
-
"authz",
|
|
52
|
-
"codegen",
|
|
53
|
-
"extension",
|
|
54
|
-
"can",
|
|
55
|
-
"policy"
|
|
56
|
-
],
|
|
57
61
|
"scripts": {
|
|
58
|
-
"build": "tsc -p tsconfig.json",
|
|
62
|
+
"build": "tsc -p tsconfig.json --incremental false",
|
|
59
63
|
"test": "vitest run --passWithNoTests",
|
|
60
64
|
"test:watch": "vitest",
|
|
61
65
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|