@anarchitects/auth-nest 0.4.2 → 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 +110 -37
- 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 -22
- package/src/application/application.module.js +59 -8
- 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 +4 -11
- package/src/auth.module.js +40 -24
- package/src/auth.module.js.map +1 -1
- 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/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/index.d.ts +1 -0
- package/src/infrastructure-mailer/mailer.module.d.ts +4 -0
- package/src/infrastructure-mailer/mailer.module.js +31 -6
- 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 -2
- package/src/infrastructure-persistence/persistence.module.js +21 -4
- 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/README.md
CHANGED
|
@@ -2,36 +2,43 @@
|
|
|
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** – `AuthMailerModule` wrapper over shared `
|
|
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` | `AuthModule.forRoot(...)`, plus re-exports of layered entry points for convenience
|
|
33
|
-
| `@anarchitects/auth-nest/application` | `AuthApplicationModule`, `AuthService`, `JwtAuthService`, `HashService`, `BcryptHashService`, `PoliciesService`, `AbilityFactory`, `JwtStrategy
|
|
34
|
-
| `@anarchitects/auth-nest/presentation` | `AuthPresentationModule`, `AuthController`, `PoliciesGuard`, `@Policies()`
|
|
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` |
|
|
35
42
|
| `@anarchitects/auth-nest/infrastructure-persistence` | `AuthPersistenceModule`, `AuthUserRepository`, `TypeormAuthUserRepository`, migration |
|
|
36
43
|
| `@anarchitects/auth-nest/infrastructure-mailer` | `AuthMailerModule`, `NodeMailerAdapter` |
|
|
37
44
|
| `@anarchitects/auth-nest/config` | `authConfig`, `AuthConfig` type, `InjectAuthConfig()` |
|
|
@@ -48,6 +55,9 @@ The library reads configuration through `@nestjs/config` using a namespaced `aut
|
|
|
48
55
|
| `AUTH_JWT_ISSUER` | Expected `iss` claim in the JWT. | `your_issuer` |
|
|
49
56
|
| `AUTH_ENCRYPTION_ALGORITHM` | Password hashing algorithm (`bcrypt`). | `bcrypt` |
|
|
50
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` |
|
|
51
61
|
|
|
52
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.
|
|
53
63
|
|
|
@@ -97,18 +107,20 @@ import { authConfig } from '@anarchitects/auth-nest/config';
|
|
|
97
107
|
}),
|
|
98
108
|
CommonMailerModule.forRootFromConfig(),
|
|
99
109
|
AuthModule.forRoot({
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
},
|
|
105
120
|
},
|
|
106
121
|
},
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
},
|
|
110
|
-
features: {
|
|
111
|
-
mailer: true,
|
|
122
|
+
mailer: {
|
|
123
|
+
provider: 'node',
|
|
112
124
|
},
|
|
113
125
|
}),
|
|
114
126
|
],
|
|
@@ -118,13 +130,15 @@ export class AuthApiModule {}
|
|
|
118
130
|
|
|
119
131
|
`AuthModule.forRoot(...)` is the preferred integration path when you want a full auth stack with minimal host-module wiring.
|
|
120
132
|
|
|
133
|
+
Use `AuthModule.forRootFromConfig()` when you want module composition fully driven by `AUTH_*`
|
|
134
|
+
variables exposed via `authConfig`.
|
|
135
|
+
|
|
121
136
|
Disable domain mailer wiring when not needed:
|
|
122
137
|
|
|
123
138
|
```ts
|
|
124
139
|
AuthModule.forRoot({
|
|
125
|
-
application: { ... },
|
|
126
|
-
|
|
127
|
-
features: { mailer: false },
|
|
140
|
+
presentation: { application: { ... } },
|
|
141
|
+
mailer: { provider: 'noop' },
|
|
128
142
|
});
|
|
129
143
|
```
|
|
130
144
|
|
|
@@ -136,7 +150,6 @@ import { ConfigModule } from '@nestjs/config';
|
|
|
136
150
|
import { CommonMailerModule, mailerConfig } from '@anarchitects/common-nest-mailer';
|
|
137
151
|
import { authConfig } from '@anarchitects/auth-nest/config';
|
|
138
152
|
import { AuthApplicationModule } from '@anarchitects/auth-nest/application';
|
|
139
|
-
import { AuthPersistenceModule } from '@anarchitects/auth-nest/infrastructure-persistence';
|
|
140
153
|
import { AuthPresentationModule } from '@anarchitects/auth-nest/presentation';
|
|
141
154
|
import { AuthMailerModule } from '@anarchitects/auth-nest/infrastructure-mailer';
|
|
142
155
|
|
|
@@ -153,10 +166,21 @@ import { AuthMailerModule } from '@anarchitects/auth-nest/infrastructure-mailer'
|
|
|
153
166
|
algorithm: 'bcrypt',
|
|
154
167
|
key: process.env.AUTH_ENCRYPTION_KEY!,
|
|
155
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',
|
|
156
183
|
}),
|
|
157
|
-
AuthPersistenceModule.forRoot({ persistence: 'typeorm' }),
|
|
158
|
-
AuthPresentationModule,
|
|
159
|
-
AuthMailerModule,
|
|
160
184
|
],
|
|
161
185
|
})
|
|
162
186
|
export class AuthApiModule {}
|
|
@@ -166,10 +190,11 @@ Use layered composition when you need to replace or selectively compose infrastr
|
|
|
166
190
|
|
|
167
191
|
## Mailer Migration Note
|
|
168
192
|
|
|
169
|
-
`AuthMailerModule` is now adapter-only. It wraps
|
|
170
|
-
`@anarchitects/common-nest-mailer` and no longer configures transport with
|
|
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
|
|
171
195
|
`MailerModule.forRootAsync(...)`.
|
|
172
|
-
Configure transport once at app root with `CommonMailerModule
|
|
196
|
+
Configure transport once at app root with `CommonMailerModule`.
|
|
197
|
+
Set `mailer.provider: 'noop'` to disable active delivery behavior per domain.
|
|
173
198
|
The shared mailer DI contract (`MailerPort`) and concrete `NodeMailerAdapter` now live in
|
|
174
199
|
`@anarchitects/common-nest-mailer`.
|
|
175
200
|
|
|
@@ -202,20 +227,67 @@ await authUserRepository.invalidateTokens([hashedAccessToken, hashedRefreshToken
|
|
|
202
227
|
### Route-level authorization with policies
|
|
203
228
|
|
|
204
229
|
```ts
|
|
205
|
-
import { Controller,
|
|
206
|
-
import {
|
|
230
|
+
import { Controller, Patch, UseGuards } from '@nestjs/common';
|
|
231
|
+
import { AuthorizedResource, AuthorizeResource, Policies, PoliciesGuard } from '@anarchitects/auth-nest/presentation';
|
|
207
232
|
|
|
208
|
-
@Controller('
|
|
233
|
+
@Controller('posts')
|
|
209
234
|
@UseGuards(PoliciesGuard)
|
|
210
|
-
export class
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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);
|
|
215
243
|
}
|
|
216
244
|
}
|
|
217
245
|
```
|
|
218
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
|
+
|
|
219
291
|
## REST endpoints
|
|
220
292
|
|
|
221
293
|
The `AuthController` exposes the following routes (all prefixed with `/auth`):
|
|
@@ -246,6 +318,7 @@ The `AuthController` exposes the following routes (all prefixed with `/auth`):
|
|
|
246
318
|
- Default persistence is TypeORM with schema-qualified tables (see `libs/auth/nest/src/infrastructure-persistence`).
|
|
247
319
|
- Invalidated tokens use an unlogged cache table for quick revocation lookups.
|
|
248
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.
|
|
249
322
|
- OpenAPI metadata (`operationId`, `tags`) is assigned in `tools/api-specs/route-metadata.ts`, not in controllers.
|
|
250
323
|
|
|
251
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.4",
|
|
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
|
-
"typeorm": "^0.3.27",
|
|
17
|
-
"uuidv7": "^1.0.2",
|
|
18
|
-
"@nestjs/typeorm": "^11.0.0",
|
|
19
24
|
"@nestjs/platform-fastify": "^11.1.6",
|
|
20
|
-
"@
|
|
21
|
-
"
|
|
22
|
-
"@anarchitects/common-nest-mailer": "0.0.10"
|
|
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,24 +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
|
-
static forRoot(options
|
|
11
|
-
|
|
12
|
-
providers: (typeof AbilityFactory | typeof BcryptHashService | typeof JwtAuthService | typeof PoliciesService | typeof JwtStrategy | {
|
|
13
|
-
provide: typeof HashService;
|
|
14
|
-
useExisting: typeof BcryptHashService;
|
|
15
|
-
} | {
|
|
16
|
-
provide: typeof AuthService;
|
|
17
|
-
useExisting: typeof JwtAuthService;
|
|
18
|
-
})[];
|
|
19
|
-
exports: (typeof AuthService | typeof HashService)[];
|
|
20
|
-
module: import("@nestjs/common").Type<any>;
|
|
21
|
-
global?: boolean;
|
|
22
|
-
controllers?: import("@nestjs/common").Type<any>[];
|
|
23
|
-
};
|
|
5
|
+
static forRoot(options?: AuthApplicationModuleOptions): DynamicModule;
|
|
6
|
+
static forRootFromConfig(overrides?: AuthApplicationModuleOptions): DynamicModule;
|
|
24
7
|
}
|
|
@@ -6,21 +6,35 @@ const common_1 = require("@nestjs/common");
|
|
|
6
6
|
const config_1 = require("@nestjs/config");
|
|
7
7
|
const jwt_1 = require("@nestjs/jwt");
|
|
8
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");
|
|
9
12
|
const application_module_definition_1 = require("./application.module-definition");
|
|
10
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");
|
|
11
17
|
const auth_service_1 = require("./services/auth.service");
|
|
12
18
|
const bcrypt_hash_service_1 = require("./services/bcrypt-hash.service");
|
|
13
19
|
const hash_service_1 = require("./services/hash.service");
|
|
14
20
|
const jwt_auth_service_1 = require("./services/jwt-auth.service");
|
|
15
21
|
const policies_service_1 = require("./services/policies.service");
|
|
16
|
-
const
|
|
22
|
+
const jwt_strategy_1 = require("./strategies/jwt-strategy");
|
|
17
23
|
let AuthApplicationModule = class AuthApplicationModule extends application_module_definition_1.ConfigurableModuleClass {
|
|
18
|
-
static forRoot(options) {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
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
|
+
];
|
|
21
31
|
const providers = [];
|
|
22
32
|
const exports = [];
|
|
23
|
-
providers.push(ability_factory_1.AbilityFactory, 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);
|
|
24
38
|
switch (encryption.algorithm) {
|
|
25
39
|
case 'bcrypt':
|
|
26
40
|
providers.push(bcrypt_hash_service_1.BcryptHashService, {
|
|
@@ -48,19 +62,56 @@ let AuthApplicationModule = class AuthApplicationModule extends application_modu
|
|
|
48
62
|
},
|
|
49
63
|
}),
|
|
50
64
|
}));
|
|
51
|
-
providers.push(
|
|
65
|
+
providers.push(auth_orchestration_service_1.AuthOrchestrationService, jwt_strategy_1.JwtStrategy, {
|
|
52
66
|
provide: auth_service_1.AuthService,
|
|
53
|
-
useExisting:
|
|
67
|
+
useExisting: auth_orchestration_service_1.AuthOrchestrationService,
|
|
68
|
+
}, {
|
|
69
|
+
provide: jwt_auth_service_1.JwtAuthService,
|
|
70
|
+
useExisting: auth_orchestration_service_1.AuthOrchestrationService,
|
|
54
71
|
});
|
|
55
72
|
exports.push(auth_service_1.AuthService);
|
|
56
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
|
+
}
|
|
57
86
|
return {
|
|
58
|
-
...super.forRoot(
|
|
87
|
+
...super.forRoot(resolvedOptions),
|
|
59
88
|
imports,
|
|
60
89
|
providers,
|
|
61
90
|
exports,
|
|
62
91
|
};
|
|
63
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
|
+
}
|
|
64
115
|
};
|
|
65
116
|
exports.AuthApplicationModule = AuthApplicationModule;
|
|
66
117
|
exports.AuthApplicationModule = AuthApplicationModule = tslib_1.__decorate([
|
|
@@ -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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Action, Subject, User } from '@anarchitects/auth-ts/models';
|
|
2
|
+
export type AuthorizableResource = Record<string, unknown>;
|
|
3
|
+
export type ResourceAuthorizationLoaderInput = {
|
|
4
|
+
user: User;
|
|
5
|
+
resourceId: string;
|
|
6
|
+
};
|
|
7
|
+
export type ResourceAuthorizationLoader<TResource extends AuthorizableResource = AuthorizableResource> = (input: ResourceAuthorizationLoaderInput) => Promise<TResource | null> | TResource | null;
|
|
8
|
+
export type ResourceAuthorizationLoaders = Record<string, ResourceAuthorizationLoader>;
|
|
9
|
+
export type ResourceAuthorizationOptions = {
|
|
10
|
+
loaders?: ResourceAuthorizationLoaders;
|
|
11
|
+
};
|
|
12
|
+
export type ResourceAuthorizationRoute = {
|
|
13
|
+
action: Action;
|
|
14
|
+
subject: Subject;
|
|
15
|
+
idParam: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-authorization.types.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/resource-authorization.types.ts"],"names":[],"mappings":""}
|