@nathapp/nestjs-auth 3.2.2 → 3.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/AGENTS.md +61 -0
- package/CLAUDE.md +18 -0
- package/GEMINI.md +59 -0
- package/codex.md +59 -0
- package/dist/permission/permission.provider.js +2 -24
- package/dist/permission/permission.provider.js.map +1 -1
- package/dist/strategy/base-jwt-strategy-provider.js +5 -2
- package/dist/strategy/base-jwt-strategy-provider.js.map +1 -1
- package/dist/utils/execution-context.utils.d.ts +3 -0
- package/dist/utils/execution-context.utils.js +17 -0
- package/dist/utils/execution-context.utils.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +5 -3
package/AGENTS.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Agent Instructions
|
|
2
|
+
|
|
3
|
+
This file is auto-generated from `.nax/context.md`.
|
|
4
|
+
DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
5
|
+
|
|
6
|
+
These instructions apply to all AI coding agents in this project.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Project Metadata
|
|
11
|
+
|
|
12
|
+
> Auto-injected by `nax generate`
|
|
13
|
+
|
|
14
|
+
**Project:** `@nathapp/nestjs-auth`
|
|
15
|
+
|
|
16
|
+
**Language:** TypeScript
|
|
17
|
+
|
|
18
|
+
**Key dependencies:** @nathapp/typescript-config, typescript
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
# @nathapp/nestjs-auth
|
|
22
|
+
|
|
23
|
+
JWT authentication + CASL authorization library for NestJS.
|
|
24
|
+
|
|
25
|
+
## Commands
|
|
26
|
+
- Test: `npx jest --config test/jest-test.json --no-coverage`
|
|
27
|
+
- Build: `npx tsc`
|
|
28
|
+
|
|
29
|
+
## Module Structure
|
|
30
|
+
- `AuthModule` — combined AuthN+AuthZ (one-stop import for consumers)
|
|
31
|
+
- `AuthenticationModule` — AuthN only (JWT guards, strategies)
|
|
32
|
+
- `AuthorizationModule` — AuthZ only (CASL permissions)
|
|
33
|
+
- `AuthModule.forRoot()` splits options internally to `AuthenticationModule` + `AuthorizationModule`
|
|
34
|
+
|
|
35
|
+
## Key Files
|
|
36
|
+
- `lib/auth.module.ts` — combined module, complex async option splitting logic
|
|
37
|
+
- `lib/authentication/auth.module.ts` — AuthN module with strategy/guard providers
|
|
38
|
+
- `lib/authorization/authorization.module.ts` — AuthZ module with CASL wiring
|
|
39
|
+
- `lib/permission/permission.provider.ts` — `DefaultPermissionProvider` with `@Inject()` + `@Optional()`
|
|
40
|
+
|
|
41
|
+
## Gotchas
|
|
42
|
+
- `createPermissionProvider()` uses `useFactory` with explicit `inject: [CASL_ABILITY_FACTORY]` — NOT `useClass`. Required because `emitDecoratorMetadata` is unreliable across ts-jest configs.
|
|
43
|
+
- `AuthModule.forRootAsync` with `useClass`: instantiates factory directly (`new FactoryClass()`) to avoid cross-module DI resolution issues.
|
|
44
|
+
- `@RefreshToken()` does NOT bypass guards. Use `@Public()` + `@UseGuards(JwtRefreshGuard)` for refresh endpoints.
|
|
45
|
+
- Guards (`JwtAuthGuard`, `PermissionAuthGuard`) are registered by `nestjs-app`, not self-registered.
|
|
46
|
+
|
|
47
|
+
## JWKS Mode
|
|
48
|
+
|
|
49
|
+
- Enabled by setting `JwtNestJsOptions.jwks.jwksUri`.
|
|
50
|
+
- Uses `jwks-rsa` (optional peer dep — install separately).
|
|
51
|
+
- `BaseJwtStrategyProvider` emits `secretOrKeyProvider` instead of `secretOrKey` when `jwks` is set.
|
|
52
|
+
- `JwksJwtStrategyProvider` is the verify-only convenience class.
|
|
53
|
+
- Security invariants enforced at construction by `validateJwksOptions`:
|
|
54
|
+
- `issuer` is required (prevents accepting any token from any key the URI serves)
|
|
55
|
+
- `algorithms` defaults to `['RS256']`; HMAC and `none` are rejected (key-confusion attack)
|
|
56
|
+
- `jwksUri` must be https unless `jwks.allowInsecure=true`
|
|
57
|
+
- `sign()` and `verify()` throw in JWKS mode — strategies are verify-only.
|
|
58
|
+
|
|
59
|
+
## IMPORTANT
|
|
60
|
+
- Security-critical package — extra scrutiny on all changes.
|
|
61
|
+
- `BaseJwtStrategyProvider` is the extension point for custom JWT strategies.
|
package/CLAUDE.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
# Project Context
|
|
2
|
+
|
|
3
|
+
This file is auto-generated from `.nax/context.md`.
|
|
4
|
+
DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Project Metadata
|
|
9
|
+
|
|
10
|
+
> Auto-injected by `nax generate`
|
|
11
|
+
|
|
12
|
+
**Project:** `@nathapp/nestjs-auth`
|
|
13
|
+
|
|
14
|
+
**Language:** TypeScript
|
|
15
|
+
|
|
16
|
+
**Key dependencies:** @nathapp/typescript-config, typescript
|
|
17
|
+
|
|
18
|
+
---
|
|
1
19
|
# @nathapp/nestjs-auth
|
|
2
20
|
|
|
3
21
|
JWT authentication + CASL authorization library for NestJS.
|
package/GEMINI.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Gemini CLI Context
|
|
2
|
+
|
|
3
|
+
This file is auto-generated from `.nax/context.md`.
|
|
4
|
+
DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Project Metadata
|
|
9
|
+
|
|
10
|
+
> Auto-injected by `nax generate`
|
|
11
|
+
|
|
12
|
+
**Project:** `@nathapp/nestjs-auth`
|
|
13
|
+
|
|
14
|
+
**Language:** TypeScript
|
|
15
|
+
|
|
16
|
+
**Key dependencies:** @nathapp/typescript-config, typescript
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
# @nathapp/nestjs-auth
|
|
20
|
+
|
|
21
|
+
JWT authentication + CASL authorization library for NestJS.
|
|
22
|
+
|
|
23
|
+
## Commands
|
|
24
|
+
- Test: `npx jest --config test/jest-test.json --no-coverage`
|
|
25
|
+
- Build: `npx tsc`
|
|
26
|
+
|
|
27
|
+
## Module Structure
|
|
28
|
+
- `AuthModule` — combined AuthN+AuthZ (one-stop import for consumers)
|
|
29
|
+
- `AuthenticationModule` — AuthN only (JWT guards, strategies)
|
|
30
|
+
- `AuthorizationModule` — AuthZ only (CASL permissions)
|
|
31
|
+
- `AuthModule.forRoot()` splits options internally to `AuthenticationModule` + `AuthorizationModule`
|
|
32
|
+
|
|
33
|
+
## Key Files
|
|
34
|
+
- `lib/auth.module.ts` — combined module, complex async option splitting logic
|
|
35
|
+
- `lib/authentication/auth.module.ts` — AuthN module with strategy/guard providers
|
|
36
|
+
- `lib/authorization/authorization.module.ts` — AuthZ module with CASL wiring
|
|
37
|
+
- `lib/permission/permission.provider.ts` — `DefaultPermissionProvider` with `@Inject()` + `@Optional()`
|
|
38
|
+
|
|
39
|
+
## Gotchas
|
|
40
|
+
- `createPermissionProvider()` uses `useFactory` with explicit `inject: [CASL_ABILITY_FACTORY]` — NOT `useClass`. Required because `emitDecoratorMetadata` is unreliable across ts-jest configs.
|
|
41
|
+
- `AuthModule.forRootAsync` with `useClass`: instantiates factory directly (`new FactoryClass()`) to avoid cross-module DI resolution issues.
|
|
42
|
+
- `@RefreshToken()` does NOT bypass guards. Use `@Public()` + `@UseGuards(JwtRefreshGuard)` for refresh endpoints.
|
|
43
|
+
- Guards (`JwtAuthGuard`, `PermissionAuthGuard`) are registered by `nestjs-app`, not self-registered.
|
|
44
|
+
|
|
45
|
+
## JWKS Mode
|
|
46
|
+
|
|
47
|
+
- Enabled by setting `JwtNestJsOptions.jwks.jwksUri`.
|
|
48
|
+
- Uses `jwks-rsa` (optional peer dep — install separately).
|
|
49
|
+
- `BaseJwtStrategyProvider` emits `secretOrKeyProvider` instead of `secretOrKey` when `jwks` is set.
|
|
50
|
+
- `JwksJwtStrategyProvider` is the verify-only convenience class.
|
|
51
|
+
- Security invariants enforced at construction by `validateJwksOptions`:
|
|
52
|
+
- `issuer` is required (prevents accepting any token from any key the URI serves)
|
|
53
|
+
- `algorithms` defaults to `['RS256']`; HMAC and `none` are rejected (key-confusion attack)
|
|
54
|
+
- `jwksUri` must be https unless `jwks.allowInsecure=true`
|
|
55
|
+
- `sign()` and `verify()` throw in JWKS mode — strategies are verify-only.
|
|
56
|
+
|
|
57
|
+
## IMPORTANT
|
|
58
|
+
- Security-critical package — extra scrutiny on all changes.
|
|
59
|
+
- `BaseJwtStrategyProvider` is the extension point for custom JWT strategies.
|
package/codex.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Codex Instructions
|
|
2
|
+
|
|
3
|
+
This file is auto-generated from `.nax/context.md`.
|
|
4
|
+
DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Project Metadata
|
|
9
|
+
|
|
10
|
+
> Auto-injected by `nax generate`
|
|
11
|
+
|
|
12
|
+
**Project:** `@nathapp/nestjs-auth`
|
|
13
|
+
|
|
14
|
+
**Language:** TypeScript
|
|
15
|
+
|
|
16
|
+
**Key dependencies:** @nathapp/typescript-config, typescript
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
# @nathapp/nestjs-auth
|
|
20
|
+
|
|
21
|
+
JWT authentication + CASL authorization library for NestJS.
|
|
22
|
+
|
|
23
|
+
## Commands
|
|
24
|
+
- Test: `npx jest --config test/jest-test.json --no-coverage`
|
|
25
|
+
- Build: `npx tsc`
|
|
26
|
+
|
|
27
|
+
## Module Structure
|
|
28
|
+
- `AuthModule` — combined AuthN+AuthZ (one-stop import for consumers)
|
|
29
|
+
- `AuthenticationModule` — AuthN only (JWT guards, strategies)
|
|
30
|
+
- `AuthorizationModule` — AuthZ only (CASL permissions)
|
|
31
|
+
- `AuthModule.forRoot()` splits options internally to `AuthenticationModule` + `AuthorizationModule`
|
|
32
|
+
|
|
33
|
+
## Key Files
|
|
34
|
+
- `lib/auth.module.ts` — combined module, complex async option splitting logic
|
|
35
|
+
- `lib/authentication/auth.module.ts` — AuthN module with strategy/guard providers
|
|
36
|
+
- `lib/authorization/authorization.module.ts` — AuthZ module with CASL wiring
|
|
37
|
+
- `lib/permission/permission.provider.ts` — `DefaultPermissionProvider` with `@Inject()` + `@Optional()`
|
|
38
|
+
|
|
39
|
+
## Gotchas
|
|
40
|
+
- `createPermissionProvider()` uses `useFactory` with explicit `inject: [CASL_ABILITY_FACTORY]` — NOT `useClass`. Required because `emitDecoratorMetadata` is unreliable across ts-jest configs.
|
|
41
|
+
- `AuthModule.forRootAsync` with `useClass`: instantiates factory directly (`new FactoryClass()`) to avoid cross-module DI resolution issues.
|
|
42
|
+
- `@RefreshToken()` does NOT bypass guards. Use `@Public()` + `@UseGuards(JwtRefreshGuard)` for refresh endpoints.
|
|
43
|
+
- Guards (`JwtAuthGuard`, `PermissionAuthGuard`) are registered by `nestjs-app`, not self-registered.
|
|
44
|
+
|
|
45
|
+
## JWKS Mode
|
|
46
|
+
|
|
47
|
+
- Enabled by setting `JwtNestJsOptions.jwks.jwksUri`.
|
|
48
|
+
- Uses `jwks-rsa` (optional peer dep — install separately).
|
|
49
|
+
- `BaseJwtStrategyProvider` emits `secretOrKeyProvider` instead of `secretOrKey` when `jwks` is set.
|
|
50
|
+
- `JwksJwtStrategyProvider` is the verify-only convenience class.
|
|
51
|
+
- Security invariants enforced at construction by `validateJwksOptions`:
|
|
52
|
+
- `issuer` is required (prevents accepting any token from any key the URI serves)
|
|
53
|
+
- `algorithms` defaults to `['RS256']`; HMAC and `none` are rejected (key-confusion attack)
|
|
54
|
+
- `jwksUri` must be https unless `jwks.allowInsecure=true`
|
|
55
|
+
- `sign()` and `verify()` throw in JWKS mode — strategies are verify-only.
|
|
56
|
+
|
|
57
|
+
## IMPORTANT
|
|
58
|
+
- Security-critical package — extra scrutiny on all changes.
|
|
59
|
+
- `BaseJwtStrategyProvider` is the extension point for custom JWT strategies.
|
|
@@ -35,18 +35,7 @@ let DefaultPermissionProvider = DefaultPermissionProvider_1 = class DefaultPermi
|
|
|
35
35
|
this.caslAbilityFactory = caslAbilityFactory || new casl_1.JwtCaslAbilityFactory();
|
|
36
36
|
}
|
|
37
37
|
checkPermission(context, permission) {
|
|
38
|
-
|
|
39
|
-
const hostType = context.getType();
|
|
40
|
-
let user = undefined;
|
|
41
|
-
if (hostType === "http") {
|
|
42
|
-
user = (_a = context.switchToHttp().getRequest()) === null || _a === void 0 ? void 0 : _a.user;
|
|
43
|
-
}
|
|
44
|
-
else if (hostType === "rpc") {
|
|
45
|
-
user = (_b = context.switchToRpc().getData()) === null || _b === void 0 ? void 0 : _b.user;
|
|
46
|
-
}
|
|
47
|
-
else if (hostType === "ws") {
|
|
48
|
-
user = (_c = context.switchToWs().getData()) === null || _c === void 0 ? void 0 : _c.user;
|
|
49
|
-
}
|
|
38
|
+
const user = (0, utils_1.getPrincipalFromContext)(context);
|
|
50
39
|
if (!user || !this.isPermissionable(user)) {
|
|
51
40
|
this.logger.debug("user not found or user has empty permission");
|
|
52
41
|
this.logger.debug(`user: ${JSON.stringify(user)}`);
|
|
@@ -104,18 +93,7 @@ exports.DefaultPermissionProvider = DefaultPermissionProvider = DefaultPermissio
|
|
|
104
93
|
], DefaultPermissionProvider);
|
|
105
94
|
class SimplePermissionProvider {
|
|
106
95
|
checkPermission(context, permission) {
|
|
107
|
-
|
|
108
|
-
const hostType = context.getType();
|
|
109
|
-
let user = undefined;
|
|
110
|
-
if (hostType === "http") {
|
|
111
|
-
user = (_a = context.switchToHttp().getRequest()) === null || _a === void 0 ? void 0 : _a.user;
|
|
112
|
-
}
|
|
113
|
-
else if (hostType === "rpc") {
|
|
114
|
-
user = (_b = context.switchToRpc().getData()) === null || _b === void 0 ? void 0 : _b.user;
|
|
115
|
-
}
|
|
116
|
-
else if (hostType === "ws") {
|
|
117
|
-
user = (_c = context.switchToWs().getData()) === null || _c === void 0 ? void 0 : _c.user;
|
|
118
|
-
}
|
|
96
|
+
const user = (0, utils_1.getPrincipalFromContext)(context);
|
|
119
97
|
return user ? true : false;
|
|
120
98
|
}
|
|
121
99
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission.provider.js","sourceRoot":"","sources":["../../lib/permission/permission.provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4E;AAI5E,
|
|
1
|
+
{"version":3,"file":"permission.provider.js","sourceRoot":"","sources":["../../lib/permission/permission.provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4E;AAI5E,oCAAkF;AAClF,kCAAoE;AAMpE,IAAY,oBAMX;AAND,WAAY,oBAAoB;IAC9B,yCAAiB,CAAA;IACjB,qCAAa,CAAA;IACb,yCAAiB,CAAA;IACjB,yCAAiB,CAAA;IACjB,yCAAiB,CAAA;AACnB,CAAC,EANW,oBAAoB,oCAApB,oBAAoB,QAM/B;AA0ED,MAAsB,kBAAkB;CAIvC;AAJD,gDAIC;AAOD,IAAa,yBAAyB,iCAAtC,MAAa,yBAA0B,SAAQ,kBAAkB;IAK/D,YAAoD,kBAAuC;QACzF,KAAK,EAAE,CAAC;QAJO,WAAM,GAAG,IAAI,eAAM,CAAC,2BAAyB,CAAC,IAAI,CAAC,CAAC;QAKnE,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,IAAI,IAAI,4BAAqB,EAAE,CAAC;IAC9E,CAAC;IASD,eAAe,CAAC,OAAyB,EAAE,UAA0B;QAInE,MAAM,IAAI,GAAG,IAAA,+BAAuB,EAAC,OAAO,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;YACjE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,IAAI,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K,CAAC;IAC7B,CAAC;CAEF;AAhBD,4DAgBC"}
|
|
@@ -29,12 +29,15 @@ class BaseJwtStrategyProvider {
|
|
|
29
29
|
this.passReqToCallback = this.jwtOptions.passReqToCallback;
|
|
30
30
|
}
|
|
31
31
|
getStrategyOptions() {
|
|
32
|
-
var _a;
|
|
32
|
+
var _a, _b, _c;
|
|
33
|
+
const algorithms = this.jwtOptions.jwks
|
|
34
|
+
? (_a = this.jwtOptions.jwks.algorithms) !== null && _a !== void 0 ? _a : ['RS256']
|
|
35
|
+
: [(_c = (_b = this.jwtOptions.signOption) === null || _b === void 0 ? void 0 : _b.algorithm) !== null && _c !== void 0 ? _c : 'HS512'];
|
|
33
36
|
const partialOptions = {
|
|
34
37
|
ignoreExpiration: this.ignoreExpiration,
|
|
38
|
+
algorithms,
|
|
35
39
|
...(this.jwtOptions.issuer && { issuer: this.jwtOptions.issuer }),
|
|
36
40
|
...(this.jwtOptions.audience && { audience: this.jwtOptions.audience }),
|
|
37
|
-
...(this.jwtOptions.jwks && { algorithms: (_a = this.jwtOptions.jwks.algorithms) !== null && _a !== void 0 ? _a : ['RS256'] }),
|
|
38
41
|
};
|
|
39
42
|
const keyConfig = this.secretOrKeyProviderFn
|
|
40
43
|
? { secretOrKeyProvider: this.secretOrKeyProviderFn }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-jwt-strategy-provider.js","sourceRoot":"","sources":["../../lib/strategy/base-jwt-strategy-provider.ts"],"names":[],"mappings":";;;AACA,+CAA8I;
|
|
1
|
+
{"version":3,"file":"base-jwt-strategy-provider.js","sourceRoot":"","sources":["../../lib/strategy/base-jwt-strategy-provider.ts"],"names":[],"mappings":";;;AACA,+CAA8I;AAI9I,0CAAmG;AAcnG,MAAsB,uBAAuB;IAW3C,YAAY,UAAsB,EAAE,cAAoC;QACtE,MAAM,YAAY,GAAwB;YACxC,MAAM,EAAE,KAAK;YACb,mBAAmB,EAAE,IAAI;YACzB,gBAAgB,EAAE,IA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CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IACtD,CAAC;CAMF;AA5GD,0DA4GC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPrincipalFromContext = getPrincipalFromContext;
|
|
4
|
+
function getPrincipalFromContext(context) {
|
|
5
|
+
var _a, _b, _c;
|
|
6
|
+
switch (context.getType()) {
|
|
7
|
+
case "http":
|
|
8
|
+
return (_a = context.switchToHttp().getRequest()) === null || _a === void 0 ? void 0 : _a.user;
|
|
9
|
+
case "rpc":
|
|
10
|
+
return (_b = context.switchToRpc().getContext()) === null || _b === void 0 ? void 0 : _b.user;
|
|
11
|
+
case "ws":
|
|
12
|
+
return (_c = context.switchToWs().getClient()) === null || _c === void 0 ? void 0 : _c.user;
|
|
13
|
+
default:
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=execution-context.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-context.utils.js","sourceRoot":"","sources":["../../lib/utils/execution-context.utils.ts"],"names":[],"mappings":";;AAcA,0DAWC;AAXD,SAAgB,uBAAuB,CAAC,OAAyB;;IAC/D,QAAQ,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QAC1B,KAAK,MAAM;YACT,OAAO,MAAA,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,0CAAE,IAAI,CAAC;QACnD,KAAK,KAAK;YACR,OAAO,MAAA,OAAO,CAAC,WAAW,EAAE,CAAC,UAAU,EAAE,0CAAE,IAAI,CAAC;QAClD,KAAK,IAAI;YACP,OAAO,MAAA,OAAO,CAAC,UAAU,EAAE,CAAC,SAAS,EAAE,0CAAE,IAAI,CAAC;QAChD;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isRequiredCaslPermission = exports.isCaslPermissionAction = exports.isAuthority = exports.isCaslPermission = void 0;
|
|
3
|
+
exports.getPrincipalFromContext = exports.isRequiredCaslPermission = exports.isCaslPermissionAction = exports.isAuthority = exports.isCaslPermission = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
5
|
Object.defineProperty(exports, "isAuthority", { enumerable: true, get: function () { return utils_1.isAuthority; } });
|
|
6
6
|
Object.defineProperty(exports, "isCaslPermission", { enumerable: true, get: function () { return utils_1.isCaslPermission; } });
|
|
7
7
|
Object.defineProperty(exports, "isCaslPermissionAction", { enumerable: true, get: function () { return utils_1.isCaslPermissionAction; } });
|
|
8
8
|
Object.defineProperty(exports, "isRequiredCaslPermission", { enumerable: true, get: function () { return utils_1.isRequiredCaslPermission; } });
|
|
9
|
+
var execution_context_utils_1 = require("./execution-context.utils");
|
|
10
|
+
Object.defineProperty(exports, "getPrincipalFromContext", { enumerable: true, get: function () { return execution_context_utils_1.getPrincipalFromContext; } });
|
|
9
11
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":";;;AAAA,mCAA0G;AAIxG,4FAJO,mBAAW,OAIP;AADX,iGAHoB,wBAAgB,OAGpB;AAEhB,uGALsC,8BAAsB,OAKtC;AACtB,yGAN8D,gCAAwB,OAM9D"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":";;;AAAA,mCAA0G;AAIxG,4FAJO,mBAAW,OAIP;AADX,iGAHoB,wBAAgB,OAGpB;AAEhB,uGALsC,8BAAsB,OAKtC;AACtB,yGAN8D,gCAAwB,OAM9D;AAG1B,qEAAoE;AAA3D,kIAAA,uBAAuB,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nestjs-auth",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "nestjs-auth",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist/ .turbo/",
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"test": "jest --config ./test/jest-test.json",
|
|
10
10
|
"test:cov": "jest --config ./test/jest-test.json --coverage",
|
|
11
11
|
"test:watch": "jest --config ./test/jest-test.json --watch",
|
|
12
|
-
"lint": "eslint -c .eslintrc.js"
|
|
12
|
+
"lint": "eslint -c .eslintrc.js",
|
|
13
|
+
"type-check": "tsc --noEmit -p tsconfig.json",
|
|
14
|
+
"lint:fix": "eslint -c .eslintrc.js --fix"
|
|
13
15
|
},
|
|
14
16
|
"author": "",
|
|
15
17
|
"license": "ISC",
|
|
@@ -27,7 +29,7 @@
|
|
|
27
29
|
"lib": "lib"
|
|
28
30
|
},
|
|
29
31
|
"dependencies": {
|
|
30
|
-
"@nathapp/nestjs-common": "^3.
|
|
32
|
+
"@nathapp/nestjs-common": "^3.3.0",
|
|
31
33
|
"passport-jwt": "^4.0.1"
|
|
32
34
|
},
|
|
33
35
|
"peerDependencies": {
|