@anarchitects/auth-nest 0.4.1 → 0.5.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/README.md +164 -29
- package/package.json +25 -12
- package/src/application/application.module-definition.d.ts +4 -21
- package/src/application/application.module-definition.js.map +1 -1
- package/src/application/application.module.d.ts +5 -25
- package/src/application/application.module.js +65 -18
- package/src/application/application.module.js.map +1 -1
- package/src/application/factories/ability.factory.js +3 -3
- package/src/application/factories/ability.factory.js.map +1 -1
- package/src/application/index.d.ts +8 -4
- package/src/application/index.js +7 -4
- package/src/application/index.js.map +1 -1
- package/src/application/resource-authorization.tokens.d.ts +1 -0
- package/src/application/resource-authorization.tokens.js +5 -0
- package/src/application/resource-authorization.tokens.js.map +1 -0
- package/src/application/resource-authorization.types.d.ts +16 -0
- package/src/application/resource-authorization.types.js +3 -0
- package/src/application/resource-authorization.types.js.map +1 -0
- package/src/application/services/auth-engine.port.d.ts +42 -0
- package/src/application/services/auth-engine.port.js +12 -0
- package/src/application/services/auth-engine.port.js.map +1 -0
- package/src/application/services/auth-orchestration.service.d.ts +41 -0
- package/src/application/services/auth-orchestration.service.js +161 -0
- package/src/application/services/auth-orchestration.service.js.map +1 -0
- package/src/application/services/jwt-auth.service.d.ts +6 -36
- package/src/application/services/jwt-auth.service.js +8 -201
- package/src/application/services/jwt-auth.service.js.map +1 -1
- package/src/application/services/persisted-policy-rule.d.ts +2 -0
- package/src/application/services/persisted-policy-rule.js +20 -0
- package/src/application/services/persisted-policy-rule.js.map +1 -0
- package/src/application/services/policies.service.js +7 -10
- package/src/application/services/policies.service.js.map +1 -1
- package/src/application/services/resource-authorization.d.ts +5 -0
- package/src/application/services/resource-authorization.js +18 -0
- package/src/application/services/resource-authorization.js.map +1 -0
- package/src/application/strategies/{jwt/strategy.d.ts → jwt-strategy.d.ts} +2 -1
- package/src/application/strategies/{jwt/strategy.js → jwt-strategy.js} +6 -4
- package/src/application/strategies/jwt-strategy.js.map +1 -0
- package/src/auth.module.d.ts +7 -0
- package/src/auth.module.js +60 -0
- package/src/auth.module.js.map +1 -0
- package/src/config/auth.config.d.ts +64 -0
- package/src/config/auth.config.js +115 -7
- package/src/config/auth.config.js.map +1 -1
- package/src/config/index.d.ts +1 -0
- package/src/config/index.js +1 -0
- package/src/config/index.js.map +1 -1
- package/src/config/module-options.d.ts +108 -0
- package/src/config/module-options.js +111 -0
- package/src/config/module-options.js.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/infrastructure-engine/better-auth/better-auth-auth-engine.adapter.d.ts +21 -0
- package/src/infrastructure-engine/better-auth/better-auth-auth-engine.adapter.js +180 -0
- package/src/infrastructure-engine/better-auth/better-auth-auth-engine.adapter.js.map +1 -0
- package/src/infrastructure-engine/better-auth/better-auth-spike.harness.d.ts +17 -0
- package/src/infrastructure-engine/better-auth/better-auth-spike.harness.js +32 -0
- package/src/infrastructure-engine/better-auth/better-auth-spike.harness.js.map +1 -0
- package/src/infrastructure-engine/better-auth/better-auth.module-loader.d.ts +7 -0
- package/src/infrastructure-engine/better-auth/better-auth.module-loader.js +15 -0
- package/src/infrastructure-engine/better-auth/better-auth.module-loader.js.map +1 -0
- package/src/infrastructure-engine/better-auth/dynamic-import.d.ts +1 -0
- package/src/infrastructure-engine/better-auth/dynamic-import.js +9 -0
- package/src/infrastructure-engine/better-auth/dynamic-import.js.map +1 -0
- package/src/infrastructure-engine/legacy-jwt-auth-engine.adapter.d.ts +22 -0
- package/src/infrastructure-engine/legacy-jwt-auth-engine.adapter.js +131 -0
- package/src/infrastructure-engine/legacy-jwt-auth-engine.adapter.js.map +1 -0
- package/src/infrastructure-mailer/adapters/node-mailer.adapter.d.ts +1 -8
- package/src/infrastructure-mailer/adapters/node-mailer.adapter.js +2 -19
- package/src/infrastructure-mailer/adapters/node-mailer.adapter.js.map +1 -1
- package/src/infrastructure-mailer/index.d.ts +1 -1
- package/src/infrastructure-mailer/index.js +0 -1
- package/src/infrastructure-mailer/index.js.map +1 -1
- package/src/infrastructure-mailer/mailer.module.d.ts +4 -0
- package/src/infrastructure-mailer/mailer.module.js +33 -14
- package/src/infrastructure-mailer/mailer.module.js.map +1 -1
- package/src/infrastructure-persistence/index.d.ts +1 -0
- package/src/infrastructure-persistence/persistence.module-definition.d.ts +4 -9
- package/src/infrastructure-persistence/persistence.module-definition.js.map +1 -1
- package/src/infrastructure-persistence/persistence.module.d.ts +4 -4
- package/src/infrastructure-persistence/persistence.module.js +22 -11
- package/src/infrastructure-persistence/persistence.module.js.map +1 -1
- package/src/presentation/authorized-resource.request.d.ts +7 -0
- package/src/presentation/authorized-resource.request.js +16 -0
- package/src/presentation/authorized-resource.request.js.map +1 -0
- package/src/presentation/decorators/authorize-resource.decorator.d.ts +3 -0
- package/src/presentation/decorators/authorize-resource.decorator.js +9 -0
- package/src/presentation/decorators/authorize-resource.decorator.js.map +1 -0
- package/src/presentation/decorators/authorized-resource.decorator.d.ts +2 -0
- package/src/presentation/decorators/authorized-resource.decorator.js +32 -0
- package/src/presentation/decorators/authorized-resource.decorator.js.map +1 -0
- package/src/presentation/decorators/policies.decorator.d.ts +2 -2
- package/src/presentation/decorators/policies.decorator.js.map +1 -1
- package/src/presentation/guards/policies.guard.js +6 -5
- package/src/presentation/guards/policies.guard.js.map +1 -1
- package/src/presentation/guards/resource-authorization.guard.d.ts +11 -0
- package/src/presentation/guards/resource-authorization.guard.js +55 -0
- package/src/presentation/guards/resource-authorization.guard.js.map +1 -0
- package/src/presentation/guards/route-policy-matcher.d.ts +1 -0
- package/src/presentation/guards/route-policy-matcher.js +6 -0
- package/src/presentation/guards/route-policy-matcher.js.map +1 -0
- package/src/presentation/index.d.ts +5 -0
- package/src/presentation/index.js +4 -0
- package/src/presentation/index.js.map +1 -1
- package/src/presentation/presentation.module.d.ts +4 -0
- package/src/presentation/presentation.module.js +43 -2
- package/src/presentation/presentation.module.js.map +1 -1
- package/src/presentation/route-policy.d.ts +1 -0
- package/src/presentation/route-policy.js +3 -0
- package/src/presentation/route-policy.js.map +1 -0
- package/src/application/strategies/jwt/strategy.js.map +0 -1
- package/src/infrastructure-mailer/adapters/mailer.adapter.d.ts +0 -4
- package/src/infrastructure-mailer/adapters/mailer.adapter.js +0 -7
- package/src/infrastructure-mailer/adapters/mailer.adapter.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,37 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
NestJS services, controllers, and infrastructure for the Anarchitecture authentication domain. This package wires contract-driven DTOs from `@anarchitects/auth-ts`, orchestrates user lifecycle flows (registration, activation, login/logout, password management, email verification), and persists auth state through pluggable repositories.
|
|
4
4
|
|
|
5
|
+
## Developer + AI Agent Start Here
|
|
6
|
+
|
|
7
|
+
- Read this README before generating integration code for `@anarchitects/auth-nest`.
|
|
8
|
+
- Start with `AuthModule.forRoot(...)` or `AuthModule.forRootFromConfig(...)` from the root entry point unless you need explicit layered composition.
|
|
9
|
+
- Keep shared mail transport setup at app root via `@anarchitects/common-nest-mailer`; keep auth mailer infrastructure adapter-only.
|
|
10
|
+
- Use DTO contracts from `@anarchitects/auth-ts` and preserve `presentation -> application <- infrastructure` boundaries.
|
|
11
|
+
|
|
5
12
|
## Features
|
|
6
13
|
|
|
7
14
|
- **Application layer** – `JwtAuthService`, `BcryptHashService`, JWT Passport strategy, CASL-based `PoliciesService` and `AbilityFactory` encapsulating business rules for tokens, passwords, and fine-grained access control.
|
|
8
15
|
- **Presentation layer** – `AuthController` exposing REST handlers for the full auth lifecycle, `PoliciesGuard` and `@Policies()` decorator for route-level authorization.
|
|
9
16
|
- **Infrastructure persistence** – `PersistenceModule` with TypeORM entities and repositories (users, roles, permissions, invalidated tokens). Configurable adapters to swap implementations while preserving the application contract.
|
|
10
|
-
- **Infrastructure mailer** – `
|
|
17
|
+
- **Infrastructure mailer** – `AuthMailerModule` wrapper over shared `CommonMailerModule.forRoot(...)` provider wiring; `NodeMailerAdapter` is re-exported for compatibility.
|
|
11
18
|
- **Config** – Typed `authConfig` namespace using `@nestjs/config` with an `InjectAuthConfig()` helper decorator.
|
|
12
19
|
|
|
13
20
|
## Installation
|
|
14
21
|
|
|
15
22
|
```bash
|
|
16
|
-
npm install @anarchitects/auth-nest
|
|
23
|
+
npm install @anarchitects/auth-nest @nestjs/common @nestjs/config @nestjs/core @nestjs/jwt @nestjs/passport @nestjs/platform-fastify @nestjs/typeorm typeorm
|
|
17
24
|
# or
|
|
18
|
-
yarn add @anarchitects/auth-nest
|
|
25
|
+
yarn add @anarchitects/auth-nest @nestjs/common @nestjs/config @nestjs/core @nestjs/jwt @nestjs/passport @nestjs/platform-fastify @nestjs/typeorm typeorm
|
|
19
26
|
```
|
|
20
27
|
|
|
21
28
|
Peer requirements:
|
|
22
29
|
|
|
23
30
|
- `@nestjs/common`, `@nestjs/core`, `@nestjs/jwt`, `@nestjs/typeorm`, `@nestjs/config`, `@nestjs/passport`
|
|
24
|
-
- `@
|
|
25
|
-
|
|
26
|
-
- `@nestjs-modules/mailer`
|
|
31
|
+
- `@nestjs/platform-fastify`, `typeorm`
|
|
32
|
+
|
|
33
|
+
The internal `@anarchitects/auth-ts` and `@anarchitects/common-nest-mailer` packages are installed transitively. Runtime utilities such as `@casl/ability`, `bcrypt`, and `passport-jwt` are direct dependencies of this package. Add `@nestjs-modules/mailer` only when your host app enables the shared/common mailer integration.
|
|
27
34
|
|
|
28
|
-
##
|
|
35
|
+
## Exports
|
|
29
36
|
|
|
30
37
|
| Import path | Contents |
|
|
31
38
|
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
32
|
-
| `@anarchitects/auth-nest
|
|
33
|
-
| `@anarchitects/auth-nest/
|
|
39
|
+
| `@anarchitects/auth-nest` | `AuthModule.forRoot(...)`, `AuthModule.forRootFromConfig(...)`, plus re-exports of layered entry points for convenience |
|
|
40
|
+
| `@anarchitects/auth-nest/application` | `AuthApplicationModule`, `AuthService`, `JwtAuthService`, `HashService`, `BcryptHashService`, `PoliciesService`, `AbilityFactory`, `JwtStrategy`, resource-authorization helpers/types |
|
|
41
|
+
| `@anarchitects/auth-nest/presentation` | `AuthPresentationModule`, `AuthController`, `PoliciesGuard`, `ResourceAuthorizationGuard`, `@Policies()`, `@AuthorizeResource()`, `@AuthorizedResource()`, `RoutePolicy` |
|
|
34
42
|
| `@anarchitects/auth-nest/infrastructure-persistence` | `AuthPersistenceModule`, `AuthUserRepository`, `TypeormAuthUserRepository`, migration |
|
|
35
|
-
| `@anarchitects/auth-nest/infrastructure-mailer` | `AuthMailerModule`, `
|
|
43
|
+
| `@anarchitects/auth-nest/infrastructure-mailer` | `AuthMailerModule`, `NodeMailerAdapter` |
|
|
36
44
|
| `@anarchitects/auth-nest/config` | `authConfig`, `AuthConfig` type, `InjectAuthConfig()` |
|
|
37
45
|
|
|
38
46
|
## Configuration
|
|
@@ -47,6 +55,9 @@ The library reads configuration through `@nestjs/config` using a namespaced `aut
|
|
|
47
55
|
| `AUTH_JWT_ISSUER` | Expected `iss` claim in the JWT. | `your_issuer` |
|
|
48
56
|
| `AUTH_ENCRYPTION_ALGORITHM` | Password hashing algorithm (`bcrypt`). | `bcrypt` |
|
|
49
57
|
| `AUTH_ENCRYPTION_KEY` | Symmetric key for additional encryption needs. **Must** be overridden in production. | `default_encryption_key` |
|
|
58
|
+
| `AUTH_PERSISTENCE` | Persistence adapter key used by `forRootFromConfig(...)`. | `typeorm` |
|
|
59
|
+
| `AUTH_MAILER_PROVIDER` | Domain mailer provider for `forRootFromConfig(...)` (`node` or `noop`). | `node` |
|
|
60
|
+
| `AUTH_STRATEGIES` | Comma-separated auth strategies for config-driven module composition. | `jwt` |
|
|
50
61
|
|
|
51
62
|
> **Security note:** The defaults for `AUTH_JWT_SECRET` and `AUTH_ENCRYPTION_KEY` are intentionally insecure placeholders. Always provide strong, unique values in any deployed environment.
|
|
52
63
|
|
|
@@ -79,35 +90,114 @@ export class AppModule {}
|
|
|
79
90
|
|
|
80
91
|
## Usage
|
|
81
92
|
|
|
82
|
-
###
|
|
93
|
+
### Easy mode (single facade import)
|
|
83
94
|
|
|
84
95
|
```ts
|
|
85
96
|
import { Module } from '@nestjs/common';
|
|
86
97
|
import { ConfigModule } from '@nestjs/config';
|
|
98
|
+
import { CommonMailerModule, mailerConfig } from '@anarchitects/common-nest-mailer';
|
|
99
|
+
import { AuthModule } from '@anarchitects/auth-nest';
|
|
100
|
+
import { authConfig } from '@anarchitects/auth-nest/config';
|
|
101
|
+
|
|
102
|
+
@Module({
|
|
103
|
+
imports: [
|
|
104
|
+
ConfigModule.forRoot({
|
|
105
|
+
isGlobal: true,
|
|
106
|
+
load: [authConfig, mailerConfig],
|
|
107
|
+
}),
|
|
108
|
+
CommonMailerModule.forRootFromConfig(),
|
|
109
|
+
AuthModule.forRoot({
|
|
110
|
+
presentation: {
|
|
111
|
+
application: {
|
|
112
|
+
authStrategies: ['jwt'],
|
|
113
|
+
encryption: {
|
|
114
|
+
algorithm: 'bcrypt',
|
|
115
|
+
key: process.env.AUTH_ENCRYPTION_KEY!,
|
|
116
|
+
},
|
|
117
|
+
persistence: {
|
|
118
|
+
persistence: 'typeorm',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
mailer: {
|
|
123
|
+
provider: 'node',
|
|
124
|
+
},
|
|
125
|
+
}),
|
|
126
|
+
],
|
|
127
|
+
})
|
|
128
|
+
export class AuthApiModule {}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
`AuthModule.forRoot(...)` is the preferred integration path when you want a full auth stack with minimal host-module wiring.
|
|
132
|
+
|
|
133
|
+
Use `AuthModule.forRootFromConfig()` when you want module composition fully driven by `AUTH_*`
|
|
134
|
+
variables exposed via `authConfig`.
|
|
135
|
+
|
|
136
|
+
Disable domain mailer wiring when not needed:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
AuthModule.forRoot({
|
|
140
|
+
presentation: { application: { ... } },
|
|
141
|
+
mailer: { provider: 'noop' },
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Layered composition (advanced)
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
import { Module } from '@nestjs/common';
|
|
149
|
+
import { ConfigModule } from '@nestjs/config';
|
|
150
|
+
import { CommonMailerModule, mailerConfig } from '@anarchitects/common-nest-mailer';
|
|
87
151
|
import { authConfig } from '@anarchitects/auth-nest/config';
|
|
88
152
|
import { AuthApplicationModule } from '@anarchitects/auth-nest/application';
|
|
89
|
-
import { AuthPersistenceModule } from '@anarchitects/auth-nest/infrastructure-persistence';
|
|
90
153
|
import { AuthPresentationModule } from '@anarchitects/auth-nest/presentation';
|
|
91
154
|
import { AuthMailerModule } from '@anarchitects/auth-nest/infrastructure-mailer';
|
|
92
155
|
|
|
93
156
|
@Module({
|
|
94
157
|
imports: [
|
|
95
|
-
ConfigModule.forRoot({
|
|
96
|
-
|
|
158
|
+
ConfigModule.forRoot({
|
|
159
|
+
isGlobal: true,
|
|
160
|
+
load: [authConfig, mailerConfig],
|
|
161
|
+
}),
|
|
162
|
+
CommonMailerModule.forRootFromConfig(),
|
|
163
|
+
AuthApplicationModule.forRoot({
|
|
97
164
|
authStrategies: ['jwt'],
|
|
98
165
|
encryption: {
|
|
99
166
|
algorithm: 'bcrypt',
|
|
100
167
|
key: process.env.AUTH_ENCRYPTION_KEY!,
|
|
101
168
|
},
|
|
169
|
+
persistence: { persistence: 'typeorm' },
|
|
170
|
+
}),
|
|
171
|
+
AuthPresentationModule.forRoot({
|
|
172
|
+
application: {
|
|
173
|
+
authStrategies: ['jwt'],
|
|
174
|
+
encryption: {
|
|
175
|
+
algorithm: 'bcrypt',
|
|
176
|
+
key: process.env.AUTH_ENCRYPTION_KEY!,
|
|
177
|
+
},
|
|
178
|
+
persistence: { persistence: 'typeorm' },
|
|
179
|
+
},
|
|
180
|
+
}),
|
|
181
|
+
AuthMailerModule.forRoot({
|
|
182
|
+
provider: 'node',
|
|
102
183
|
}),
|
|
103
|
-
AuthPersistenceModule.register({ persistence: 'typeorm' }),
|
|
104
|
-
AuthPresentationModule,
|
|
105
|
-
AuthMailerModule,
|
|
106
184
|
],
|
|
107
185
|
})
|
|
108
186
|
export class AuthApiModule {}
|
|
109
187
|
```
|
|
110
188
|
|
|
189
|
+
Use layered composition when you need to replace or selectively compose infrastructure/application concerns.
|
|
190
|
+
|
|
191
|
+
## Mailer Migration Note
|
|
192
|
+
|
|
193
|
+
`AuthMailerModule` is now adapter-only. It wraps shared `CommonMailerModule.forRoot(...)`
|
|
194
|
+
provider wiring from `@anarchitects/common-nest-mailer` and no longer configures transport with
|
|
195
|
+
`MailerModule.forRootAsync(...)`.
|
|
196
|
+
Configure transport once at app root with `CommonMailerModule`.
|
|
197
|
+
Set `mailer.provider: 'noop'` to disable active delivery behavior per domain.
|
|
198
|
+
The shared mailer DI contract (`MailerPort`) and concrete `NodeMailerAdapter` now live in
|
|
199
|
+
`@anarchitects/common-nest-mailer`.
|
|
200
|
+
|
|
111
201
|
### Injecting services
|
|
112
202
|
|
|
113
203
|
```ts
|
|
@@ -131,29 +221,73 @@ export class AuthController {
|
|
|
131
221
|
```ts
|
|
132
222
|
import { TypeormAuthUserRepository } from '@anarchitects/auth-nest/infrastructure-persistence';
|
|
133
223
|
|
|
134
|
-
await authUserRepository.invalidateTokens(
|
|
135
|
-
[hashedAccessToken, hashedRefreshToken],
|
|
136
|
-
userId,
|
|
137
|
-
);
|
|
224
|
+
await authUserRepository.invalidateTokens([hashedAccessToken, hashedRefreshToken], userId);
|
|
138
225
|
```
|
|
139
226
|
|
|
140
227
|
### Route-level authorization with policies
|
|
141
228
|
|
|
142
229
|
```ts
|
|
143
|
-
import { Controller,
|
|
144
|
-
import {
|
|
230
|
+
import { Controller, Patch, UseGuards } from '@nestjs/common';
|
|
231
|
+
import { AuthorizedResource, AuthorizeResource, Policies, PoliciesGuard } from '@anarchitects/auth-nest/presentation';
|
|
145
232
|
|
|
146
|
-
@Controller('
|
|
233
|
+
@Controller('posts')
|
|
147
234
|
@UseGuards(PoliciesGuard)
|
|
148
|
-
export class
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
235
|
+
export class PostsController {
|
|
236
|
+
constructor(private readonly postsService: PostsService) {}
|
|
237
|
+
|
|
238
|
+
@Patch(':postId')
|
|
239
|
+
@Policies({ action: 'update', subject: 'Post' })
|
|
240
|
+
@AuthorizeResource({ action: 'update', subject: 'Post', idParam: 'postId' })
|
|
241
|
+
async updatePost(@AuthorizedResource() post: Post) {
|
|
242
|
+
return this.postsService.update(post);
|
|
153
243
|
}
|
|
154
244
|
}
|
|
155
245
|
```
|
|
156
246
|
|
|
247
|
+
```ts
|
|
248
|
+
import { AuthModule } from '@anarchitects/auth-nest';
|
|
249
|
+
|
|
250
|
+
AuthModule.forRoot({
|
|
251
|
+
presentation: {
|
|
252
|
+
application: {
|
|
253
|
+
resourceAuthorization: {
|
|
254
|
+
loaders: {
|
|
255
|
+
Post: async ({ resourceId }) => postsRepository.findById(resourceId),
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
`@Policies()` remains the coarse route-level pre-check. `@AuthorizeResource(...)` uses the app-registered loader to fetch the concrete entity, evaluates the instance-level CASL rule behind the scenes, and attaches the authorized resource to the request so `@AuthorizedResource()` can read it in the handler.
|
|
264
|
+
|
|
265
|
+
## Authorization Model
|
|
266
|
+
|
|
267
|
+
CASL integration in `@anarchitects/auth-nest` is intentionally split into two layers:
|
|
268
|
+
|
|
269
|
+
- `@Policies()` uses `RoutePolicy` and performs a coarse route-level pre-check
|
|
270
|
+
- `@AuthorizeResource(...)` performs the concrete instance-level check after loading the resource
|
|
271
|
+
- `@AuthorizedResource()` gives the handler access to the already loaded and authorized entity
|
|
272
|
+
|
|
273
|
+
Use this split to avoid overstating what route metadata can prove. Ownership-sensitive rules such as "writers may only update their own posts" need the concrete resource instance before CASL can decide correctly.
|
|
274
|
+
|
|
275
|
+
### What the library enforces
|
|
276
|
+
|
|
277
|
+
- persisted permission payloads are validated before they become `PolicyRule[]`
|
|
278
|
+
- malformed persisted permission payloads fail closed with a server-side error
|
|
279
|
+
- missing registered resource loader is treated as configuration error
|
|
280
|
+
- missing route param yields `400`
|
|
281
|
+
- missing resource yields `404`
|
|
282
|
+
|
|
283
|
+
### What the host app must provide
|
|
284
|
+
|
|
285
|
+
- subject-specific resource loaders for `@AuthorizeResource(...)`
|
|
286
|
+
- domain resource retrieval logic and repository access
|
|
287
|
+
- route resolver/handler composition that fits the app's domain model
|
|
288
|
+
|
|
289
|
+
The library owns authorization orchestration. The host app still owns how domain resources are found.
|
|
290
|
+
|
|
157
291
|
## REST endpoints
|
|
158
292
|
|
|
159
293
|
The `AuthController` exposes the following routes (all prefixed with `/auth`):
|
|
@@ -184,6 +318,7 @@ The `AuthController` exposes the following routes (all prefixed with `/auth`):
|
|
|
184
318
|
- Default persistence is TypeORM with schema-qualified tables (see `libs/auth/nest/src/infrastructure-persistence`).
|
|
185
319
|
- Invalidated tokens use an unlogged cache table for quick revocation lookups.
|
|
186
320
|
- Route schemas are defined in `@anarchitects/auth-ts/dtos` and imported into controller `@RouteSchema` decorators — do not define inline schemas.
|
|
321
|
+
- Keep `@Policies()` guidance coarse in docs and examples; use `@AuthorizeResource(...)` for instance-sensitive authorization.
|
|
187
322
|
- OpenAPI metadata (`operationId`, `tags`) is assigned in `tools/api-specs/route-metadata.ts`, not in controllers.
|
|
188
323
|
|
|
189
324
|
## License
|
package/package.json
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anarchitects/auth-nest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"@better-auth/passkey": "^1.5.6",
|
|
9
|
+
"@anarchitects/auth-ts": "^0.5.0",
|
|
10
|
+
"@anarchitects/common-nest-mailer": "^0.3.0",
|
|
11
|
+
"@casl/ability": "^6.7.3",
|
|
12
|
+
"bcrypt": "^6.0.0",
|
|
13
|
+
"better-auth": "^1.5.6",
|
|
14
|
+
"passport-jwt": "^4.0.1",
|
|
8
15
|
"tslib": "^2.3.0",
|
|
16
|
+
"uuidv7": "^1.0.2"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
9
19
|
"@nestjs/common": "^11.0.0",
|
|
20
|
+
"@nestjs/config": "^4.0.2",
|
|
21
|
+
"@nestjs/core": "^11.0.0",
|
|
10
22
|
"@nestjs/jwt": "^11.0.1",
|
|
11
|
-
"@anarchitects/auth-ts": "0.1.3",
|
|
12
|
-
"bcrypt": "^6.0.0",
|
|
13
23
|
"@nestjs/passport": "^11.0.5",
|
|
14
|
-
"passport-jwt": "^4.0.1",
|
|
15
|
-
"@nestjs/config": "^4.0.2",
|
|
16
|
-
"@nestjs-modules/mailer": "^2.0.2",
|
|
17
|
-
"typeorm": "^0.3.27",
|
|
18
|
-
"uuidv7": "^1.0.2",
|
|
19
|
-
"@nestjs/typeorm": "^11.0.0",
|
|
20
24
|
"@nestjs/platform-fastify": "^11.1.6",
|
|
21
|
-
"@
|
|
22
|
-
"
|
|
25
|
+
"@nestjs/typeorm": "^11.0.0",
|
|
26
|
+
"typeorm": "^0.3.27"
|
|
23
27
|
},
|
|
24
28
|
"publishConfig": {
|
|
25
29
|
"access": "public"
|
|
@@ -43,6 +47,15 @@
|
|
|
43
47
|
]
|
|
44
48
|
}
|
|
45
49
|
},
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/anarchitects/anarchitecture-bricks-3tier.git",
|
|
53
|
+
"directory": "libs/auth/nest"
|
|
54
|
+
},
|
|
55
|
+
"homepage": "https://github.com/anarchitects/anarchitecture-bricks-3tier/tree/main/libs/auth/nest",
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/anarchitects/anarchitecture-bricks-3tier/issues"
|
|
58
|
+
},
|
|
46
59
|
"exports": {
|
|
47
60
|
"./package.json": "./package.json",
|
|
48
61
|
".": {
|
|
@@ -60,4 +73,4 @@
|
|
|
60
73
|
"./config": "./src/config/index.js",
|
|
61
74
|
"./config/index": "./src/config/index.js"
|
|
62
75
|
}
|
|
63
|
-
}
|
|
76
|
+
}
|
|
@@ -1,25 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
encryption: {
|
|
4
|
-
algorithm: "bcrypt" | "argon2";
|
|
5
|
-
key: string;
|
|
6
|
-
};
|
|
7
|
-
}, "forRoot", "create", {
|
|
1
|
+
import type { ResolvedAuthApplicationModuleOptions } from '../config';
|
|
2
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<ResolvedAuthApplicationModuleOptions, "forRoot", "create", {
|
|
8
3
|
isGlobal?: boolean;
|
|
9
|
-
}>, AUTH_APPLICATION_MODULE_OPTIONS: string | symbol, OPTIONS_TYPE: {
|
|
10
|
-
authStrategies: string[];
|
|
11
|
-
encryption: {
|
|
12
|
-
algorithm: "bcrypt" | "argon2";
|
|
13
|
-
key: string;
|
|
14
|
-
};
|
|
15
|
-
} & Partial<{
|
|
4
|
+
}>, AUTH_APPLICATION_MODULE_OPTIONS: string | symbol, OPTIONS_TYPE: ResolvedAuthApplicationModuleOptions & Partial<{
|
|
16
5
|
isGlobal?: boolean;
|
|
17
|
-
}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<{
|
|
18
|
-
authStrategies: string[];
|
|
19
|
-
encryption: {
|
|
20
|
-
algorithm: "bcrypt" | "argon2";
|
|
21
|
-
key: string;
|
|
22
|
-
};
|
|
23
|
-
}, "create"> & Partial<{
|
|
6
|
+
}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<ResolvedAuthApplicationModuleOptions, "create"> & Partial<{
|
|
24
7
|
isGlobal?: boolean;
|
|
25
8
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.module-definition.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/application.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;
|
|
1
|
+
{"version":3,"file":"application.module-definition.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/application.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAG9C,KAKT,IAAI,kCAAyB,EAAwC;KACtE,kBAAkB,CAAC,SAAS,CAAC;KAC7B,SAAS,CACR,EAAE,QAAQ,EAAE,IAAI,EAAE,EAClB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACvB,GAAG,UAAU;IACb,MAAM,EAAE,MAAM,CAAC,QAAQ,IAAI,KAAK;CACjC,CAAC,CACH;KACA,KAAK,EAAE,EAbR,+BAAuB,+BACD,uCAA+B,4BACrD,oBAAY,oBACZ,0BAAkB,yBAUT"}
|
|
@@ -1,27 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { BcryptHashService } from './services/bcrypt-hash.service';
|
|
5
|
-
import { HashService } from './services/hash.service';
|
|
6
|
-
import { JwtAuthService } from './services/jwt-auth.service';
|
|
7
|
-
import { PoliciesService } from './services/policies.service';
|
|
8
|
-
import { JwtStrategy } from './strategies/jwt/strategy';
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import type { AuthApplicationModuleOptions } from '../config';
|
|
3
|
+
import { ConfigurableModuleClass } from './application.module-definition';
|
|
9
4
|
export declare class AuthApplicationModule extends ConfigurableModuleClass {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
constructor(options: string | symbol, authConfig: AuthConfig);
|
|
13
|
-
static forRoot(options: typeof OPTIONS_TYPE): {
|
|
14
|
-
imports: import("@nestjs/common").DynamicModule[];
|
|
15
|
-
providers: (typeof BcryptHashService | typeof JwtAuthService | typeof PoliciesService | typeof JwtStrategy | {
|
|
16
|
-
provide: typeof HashService;
|
|
17
|
-
useExisting: typeof BcryptHashService;
|
|
18
|
-
} | {
|
|
19
|
-
provide: typeof AuthService;
|
|
20
|
-
useExisting: typeof JwtAuthService;
|
|
21
|
-
})[];
|
|
22
|
-
exports: (typeof AuthService | typeof HashService)[];
|
|
23
|
-
module: import("@nestjs/common").Type<any>;
|
|
24
|
-
global?: boolean;
|
|
25
|
-
controllers?: import("@nestjs/common").Type<any>[];
|
|
26
|
-
};
|
|
5
|
+
static forRoot(options?: AuthApplicationModuleOptions): DynamicModule;
|
|
6
|
+
static forRootFromConfig(overrides?: AuthApplicationModuleOptions): DynamicModule;
|
|
27
7
|
}
|
|
@@ -3,27 +3,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AuthApplicationModule = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
|
+
const config_1 = require("@nestjs/config");
|
|
6
7
|
const jwt_1 = require("@nestjs/jwt");
|
|
7
|
-
const
|
|
8
|
+
const config_2 = require("../config");
|
|
9
|
+
const better_auth_auth_engine_adapter_1 = require("../infrastructure-engine/better-auth/better-auth-auth-engine.adapter");
|
|
10
|
+
const legacy_jwt_auth_engine_adapter_1 = require("../infrastructure-engine/legacy-jwt-auth-engine.adapter");
|
|
11
|
+
const infrastructure_persistence_1 = require("../infrastructure-persistence");
|
|
8
12
|
const application_module_definition_1 = require("./application.module-definition");
|
|
13
|
+
const ability_factory_1 = require("./factories/ability.factory");
|
|
14
|
+
const resource_authorization_tokens_1 = require("./resource-authorization.tokens");
|
|
15
|
+
const auth_engine_port_1 = require("./services/auth-engine.port");
|
|
16
|
+
const auth_orchestration_service_1 = require("./services/auth-orchestration.service");
|
|
9
17
|
const auth_service_1 = require("./services/auth.service");
|
|
10
18
|
const bcrypt_hash_service_1 = require("./services/bcrypt-hash.service");
|
|
11
19
|
const hash_service_1 = require("./services/hash.service");
|
|
12
20
|
const jwt_auth_service_1 = require("./services/jwt-auth.service");
|
|
13
21
|
const policies_service_1 = require("./services/policies.service");
|
|
14
|
-
const
|
|
22
|
+
const jwt_strategy_1 = require("./strategies/jwt-strategy");
|
|
15
23
|
let AuthApplicationModule = class AuthApplicationModule extends application_module_definition_1.ConfigurableModuleClass {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const imports = [];
|
|
24
|
+
static forRoot(options = {}) {
|
|
25
|
+
const resolvedOptions = (0, config_2.resolveAuthApplicationModuleOptions)(options);
|
|
26
|
+
const { authStrategies, engine, encryption, persistence, resourceAuthorization, } = resolvedOptions;
|
|
27
|
+
const imports = [
|
|
28
|
+
config_1.ConfigModule.forFeature(config_2.authConfig),
|
|
29
|
+
infrastructure_persistence_1.AuthPersistenceModule.forRoot(persistence),
|
|
30
|
+
];
|
|
24
31
|
const providers = [];
|
|
25
32
|
const exports = [];
|
|
26
|
-
providers.push(policies_service_1.PoliciesService
|
|
33
|
+
providers.push(ability_factory_1.AbilityFactory, policies_service_1.PoliciesService, {
|
|
34
|
+
provide: resource_authorization_tokens_1.AUTH_RESOURCE_AUTHORIZATION_LOADERS,
|
|
35
|
+
useValue: resourceAuthorization.loaders,
|
|
36
|
+
});
|
|
37
|
+
exports.push(resource_authorization_tokens_1.AUTH_RESOURCE_AUTHORIZATION_LOADERS, policies_service_1.PoliciesService);
|
|
27
38
|
switch (encryption.algorithm) {
|
|
28
39
|
case 'bcrypt':
|
|
29
40
|
providers.push(bcrypt_hash_service_1.BcryptHashService, {
|
|
@@ -40,6 +51,8 @@ let AuthApplicationModule = class AuthApplicationModule extends application_modu
|
|
|
40
51
|
}
|
|
41
52
|
if (authStrategies.includes('jwt')) {
|
|
42
53
|
imports.push(jwt_1.JwtModule.registerAsync({
|
|
54
|
+
imports: [config_1.ConfigModule.forFeature(config_2.authConfig)],
|
|
55
|
+
inject: [config_2.authConfig.KEY],
|
|
43
56
|
useFactory: (authConfig) => ({
|
|
44
57
|
secret: authConfig.jwtSecret,
|
|
45
58
|
signOptions: {
|
|
@@ -49,25 +62,59 @@ let AuthApplicationModule = class AuthApplicationModule extends application_modu
|
|
|
49
62
|
},
|
|
50
63
|
}),
|
|
51
64
|
}));
|
|
52
|
-
providers.push(
|
|
65
|
+
providers.push(auth_orchestration_service_1.AuthOrchestrationService, jwt_strategy_1.JwtStrategy, {
|
|
53
66
|
provide: auth_service_1.AuthService,
|
|
54
|
-
useExisting:
|
|
67
|
+
useExisting: auth_orchestration_service_1.AuthOrchestrationService,
|
|
68
|
+
}, {
|
|
69
|
+
provide: jwt_auth_service_1.JwtAuthService,
|
|
70
|
+
useExisting: auth_orchestration_service_1.AuthOrchestrationService,
|
|
55
71
|
});
|
|
56
72
|
exports.push(auth_service_1.AuthService);
|
|
57
73
|
}
|
|
74
|
+
if (engine === 'better-auth') {
|
|
75
|
+
providers.push(better_auth_auth_engine_adapter_1.BetterAuthAuthEngineAdapter, {
|
|
76
|
+
provide: auth_engine_port_1.AuthEnginePort,
|
|
77
|
+
useExisting: better_auth_auth_engine_adapter_1.BetterAuthAuthEngineAdapter,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
providers.push(legacy_jwt_auth_engine_adapter_1.LegacyJwtAuthEngineAdapter, {
|
|
82
|
+
provide: auth_engine_port_1.AuthEnginePort,
|
|
83
|
+
useExisting: legacy_jwt_auth_engine_adapter_1.LegacyJwtAuthEngineAdapter,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
58
86
|
return {
|
|
59
|
-
...super.forRoot(
|
|
87
|
+
...super.forRoot(resolvedOptions),
|
|
60
88
|
imports,
|
|
61
89
|
providers,
|
|
62
90
|
exports,
|
|
63
91
|
};
|
|
64
92
|
}
|
|
93
|
+
static forRootFromConfig(overrides = {}) {
|
|
94
|
+
const configOptions = (0, config_2.mapAuthConfigToApplicationModuleOptions)((0, config_2.authConfig)());
|
|
95
|
+
const moduleDefinition = this.forRoot({
|
|
96
|
+
...configOptions,
|
|
97
|
+
...overrides,
|
|
98
|
+
encryption: {
|
|
99
|
+
...configOptions.encryption,
|
|
100
|
+
...overrides.encryption,
|
|
101
|
+
},
|
|
102
|
+
persistence: {
|
|
103
|
+
...configOptions.persistence,
|
|
104
|
+
...overrides.persistence,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
...moduleDefinition,
|
|
109
|
+
imports: [
|
|
110
|
+
config_1.ConfigModule.forFeature(config_2.authConfig),
|
|
111
|
+
...(moduleDefinition.imports ?? []),
|
|
112
|
+
],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
65
115
|
};
|
|
66
116
|
exports.AuthApplicationModule = AuthApplicationModule;
|
|
67
117
|
exports.AuthApplicationModule = AuthApplicationModule = tslib_1.__decorate([
|
|
68
|
-
(0, common_1.Module)({})
|
|
69
|
-
tslib_1.__param(0, (0, common_1.Inject)(application_module_definition_1.AUTH_APPLICATION_MODULE_OPTIONS)),
|
|
70
|
-
tslib_1.__param(1, (0, config_1.InjectAuthConfig)()),
|
|
71
|
-
tslib_1.__metadata("design:paramtypes", [Object, Object])
|
|
118
|
+
(0, common_1.Module)({})
|
|
72
119
|
], AuthApplicationModule);
|
|
73
120
|
//# sourceMappingURL=application.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.module.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/application.module.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"application.module.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/application.module.ts"],"names":[],"mappings":"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"}
|
|
@@ -9,12 +9,12 @@ let AbilityFactory = class AbilityFactory {
|
|
|
9
9
|
const { can, cannot, build } = new ability_1.AbilityBuilder(ability_1.createMongoAbility);
|
|
10
10
|
for (const rule of rules) {
|
|
11
11
|
const args = [rule.action, rule.subject];
|
|
12
|
+
if (rule.fields?.length) {
|
|
13
|
+
args.push(rule.fields);
|
|
14
|
+
}
|
|
12
15
|
if (rule.conditions) {
|
|
13
16
|
args.push(rule.conditions);
|
|
14
17
|
}
|
|
15
|
-
if (rule.fields?.length) {
|
|
16
|
-
args.push({ fields: rule.fields });
|
|
17
|
-
}
|
|
18
18
|
if (rule.inverted) {
|
|
19
19
|
cannot(...args);
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ability.factory.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/application/factories/ability.factory.ts"],"names":[],"mappings":";;;;AAEA,2CAIuB;AACvB,2CAA4C;AAIrC,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YAAY,CAAC,KAAmB;QAC9B,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,wBAAc,CAC/C,4BAAkB,CACnB,CAAC;
|
|
1
|
+
{"version":3,"file":"ability.factory.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/application/factories/ability.factory.ts"],"names":[],"mappings":";;;;AAEA,2CAIuB;AACvB,2CAA4C;AAIrC,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YAAY,CAAC,KAAmB;QAC9B,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,wBAAc,CAC/C,4BAAkB,CACnB,CAAC;QAEF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,GAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAChD,IAAI,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;gBACxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC;YACD,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACpB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC7B,CAAC;YACD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACjB,MAAc,CAAC,GAAG,IAAI,CAAC,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACL,GAAW,CAAC,GAAG,IAAI,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;YACX,iBAAiB,EAAE,CAAC,GAAG,EAAE,EAAE,CACxB,GAAW,CAAC,mBAAmB,IAAI,GAAG,EAAE,WAAW,EAAE,IAAI,IAAI,KAAK;SACtE,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAzBY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;GACA,cAAc,CAyB1B"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
export type { AuthApplicationModuleOptions } from '../config';
|
|
1
2
|
export * from './application.module';
|
|
3
|
+
export * from './factories/ability.factory';
|
|
4
|
+
export * from './resource-authorization.tokens';
|
|
5
|
+
export * from './resource-authorization.types';
|
|
2
6
|
export * from './services/auth.service';
|
|
3
|
-
export * from './services/jwt-auth.service';
|
|
4
|
-
export * from './services/hash.service';
|
|
5
7
|
export * from './services/bcrypt-hash.service';
|
|
8
|
+
export * from './services/hash.service';
|
|
9
|
+
export * from './services/jwt-auth.service';
|
|
6
10
|
export * from './services/policies.service';
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
11
|
+
export * from './services/resource-authorization';
|
|
12
|
+
export * from './strategies/jwt-strategy';
|
package/src/application/index.js
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./application.module"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./factories/ability.factory"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./resource-authorization.tokens"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./resource-authorization.types"), exports);
|
|
5
8
|
tslib_1.__exportStar(require("./services/auth.service"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./services/jwt-auth.service"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./services/hash.service"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./services/bcrypt-hash.service"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./services/hash.service"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./services/jwt-auth.service"), exports);
|
|
9
12
|
tslib_1.__exportStar(require("./services/policies.service"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./
|
|
11
|
-
tslib_1.__exportStar(require("./
|
|
13
|
+
tslib_1.__exportStar(require("./services/resource-authorization"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./strategies/jwt-strategy"), exports);
|
|
12
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/index.ts"],"names":[],"mappings":";;;AACA,+DAAqC;AACrC,sEAA4C;AAC5C,0EAAgD;AAChD,yEAA+C;AAC/C,kEAAwC;AACxC,yEAA+C;AAC/C,kEAAwC;AACxC,sEAA4C;AAC5C,sEAA4C;AAC5C,4EAAkD;AAClD,oEAA0C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AUTH_RESOURCE_AUTHORIZATION_LOADERS: unique symbol;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AUTH_RESOURCE_AUTHORIZATION_LOADERS = void 0;
|
|
4
|
+
exports.AUTH_RESOURCE_AUTHORIZATION_LOADERS = Symbol('AUTH_RESOURCE_AUTHORIZATION_LOADERS');
|
|
5
|
+
//# sourceMappingURL=resource-authorization.tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-authorization.tokens.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/resource-authorization.tokens.ts"],"names":[],"mappings":";;;AAAa,QAAA,mCAAmC,GAAG,MAAM,CACvD,qCAAqC,CACtC,CAAC"}
|