@flusys/nestjs-auth 9.1.0 → 9.1.2
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 +18 -0
- package/config/message-keys.d.ts +2 -0
- package/controllers/company-selection.controller.d.ts +5 -3
- package/controllers/user-permission.controller.d.ts +3 -3
- package/dtos/authentication.dto.d.ts +5 -0
- package/dtos/user-permission.dto.d.ts +3 -0
- package/fesm/118.js +30 -0
- package/fesm/120.js +27 -23
- package/fesm/24.js +361 -134
- package/fesm/360.js +719 -0
- package/fesm/370.js +50 -0
- package/fesm/config/index.js +3 -1
- package/fesm/docs/index.js +8 -2
- package/fesm/helpers/index.js +139 -33
- package/fesm/index.js +26 -550
- package/fesm/interceptors/index.js +6 -2
- package/fesm/modules/index.js +4 -529
- package/fesm/services/index.js +209 -27
- package/helpers/branch-ancestry.helper.d.ts +4 -0
- package/helpers/index.d.ts +1 -0
- package/helpers/token.helper.d.ts +2 -0
- package/interfaces/authentication.interface.d.ts +3 -0
- package/package.json +5 -5
- package/services/authentication.service.d.ts +3 -1
- package/services/branch-hierarchy-resolver.adapter.d.ts +15 -0
- package/services/branch.service.d.ts +7 -0
- package/services/company-access-resolver.adapter.d.ts +8 -0
- package/services/index.d.ts +2 -0
- package/services/user-permission.service.d.ts +1 -0
package/fesm/360.js
ADDED
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
import { ExtractJwt, Strategy } from "passport-jwt";
|
|
2
|
+
import * as __rspack_external__nestjs_passport_18907953 from "@nestjs/passport";
|
|
3
|
+
export const __rspack_esm_id = 360;
|
|
4
|
+
export const __rspack_esm_ids = [360];
|
|
5
|
+
export const __webpack_modules__ = {
|
|
6
|
+
5180(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
7
|
+
/* import */ var _app_user_entity_js__rspack_import_0 = __webpack_require__(4758);
|
|
8
|
+
/* import */ var _company_branch_entity_js__rspack_import_1 = __webpack_require__(1923);
|
|
9
|
+
/* import */ var _company_entity_js__rspack_import_2 = __webpack_require__(8538);
|
|
10
|
+
/* import */ var _pending_registration_entity_js__rspack_import_3 = __webpack_require__(9388);
|
|
11
|
+
/* import */ var _social_auth_config_entity_js__rspack_import_4 = __webpack_require__(2020);
|
|
12
|
+
/* import */ var _user_company_permission_entity_js__rspack_import_5 = __webpack_require__(2377);
|
|
13
|
+
/* import */ var _user_token_entity_js__rspack_import_6 = __webpack_require__(9696);
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const BaseEntities = [
|
|
29
|
+
_app_user_entity_js__rspack_import_0/* .AppUser */.$,
|
|
30
|
+
_user_token_entity_js__rspack_import_6/* .UserToken */.L,
|
|
31
|
+
_social_auth_config_entity_js__rspack_import_4/* .SocialAuthConfig */.G
|
|
32
|
+
];
|
|
33
|
+
const EmailEntities = [
|
|
34
|
+
_pending_registration_entity_js__rspack_import_3/* .PendingRegistration */.N
|
|
35
|
+
];
|
|
36
|
+
const CompanyEntities = [
|
|
37
|
+
_company_entity_js__rspack_import_2/* .Company */.C,
|
|
38
|
+
_company_branch_entity_js__rspack_import_1/* .CompanyBranch */.A,
|
|
39
|
+
_user_company_permission_entity_js__rspack_import_5/* .UserCompanyPermission */.I
|
|
40
|
+
];
|
|
41
|
+
function getAuthEntitiesByConfig(config) {
|
|
42
|
+
const { enableCompanyFeature = false, enableEmailVerification = true } = config;
|
|
43
|
+
const entities = [
|
|
44
|
+
...BaseEntities
|
|
45
|
+
];
|
|
46
|
+
if (enableEmailVerification) {
|
|
47
|
+
entities.push(...EmailEntities);
|
|
48
|
+
}
|
|
49
|
+
if (enableCompanyFeature) {
|
|
50
|
+
entities.push(...CompanyEntities);
|
|
51
|
+
}
|
|
52
|
+
return entities;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
56
|
+
$u: () => (/* reexport safe */ _app_user_entity_js__rspack_import_0.$),
|
|
57
|
+
At: () => (/* reexport safe */ _company_branch_entity_js__rspack_import_1.A),
|
|
58
|
+
CC: () => (/* reexport safe */ _company_entity_js__rspack_import_2.C),
|
|
59
|
+
GB: () => (/* reexport safe */ _social_auth_config_entity_js__rspack_import_4.G),
|
|
60
|
+
Iq: () => (/* reexport safe */ _user_company_permission_entity_js__rspack_import_5.I),
|
|
61
|
+
Li: () => (/* reexport safe */ _user_token_entity_js__rspack_import_6.L),
|
|
62
|
+
Ni: () => (/* reexport safe */ _pending_registration_entity_js__rspack_import_3.N),
|
|
63
|
+
eZ: () => (/* reexport safe */ _user_company_permission_entity_js__rspack_import_5.e),
|
|
64
|
+
getAuthEntitiesByConfig: () => (getAuthEntitiesByConfig),
|
|
65
|
+
ks: () => (/* reexport safe */ _user_token_entity_js__rspack_import_6.k)
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
},
|
|
70
|
+
7579(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
71
|
+
|
|
72
|
+
// EXPORTS
|
|
73
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
74
|
+
r: () => (/* reexport */ AuthModule)
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/interfaces"
|
|
78
|
+
var interfaces_ = __webpack_require__(5103);
|
|
79
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/modules"
|
|
80
|
+
var modules_ = __webpack_require__(1236);
|
|
81
|
+
// EXTERNAL MODULE: external "@nestjs/common"
|
|
82
|
+
var common_ = __webpack_require__(6157);
|
|
83
|
+
// EXTERNAL MODULE: external "@nestjs/jwt"
|
|
84
|
+
var jwt_ = __webpack_require__(2125);
|
|
85
|
+
// EXTERNAL MODULE: external "@nestjs/passport"
|
|
86
|
+
var passport_ = __webpack_require__(3794);
|
|
87
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/guards"
|
|
88
|
+
var guards_ = __webpack_require__(3513);
|
|
89
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/config/auth.constants.ts
|
|
90
|
+
var auth_constants = __webpack_require__(5588);
|
|
91
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/controllers/index.ts + 11 modules
|
|
92
|
+
var src_controllers = __webpack_require__(1003);
|
|
93
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/entities/index.ts
|
|
94
|
+
var entities = __webpack_require__(5180);
|
|
95
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/interceptors/clear-token.interceptor.ts
|
|
96
|
+
var clear_token_interceptor = __webpack_require__(5207);
|
|
97
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/interceptors/set-token.interceptor.ts + 1 modules
|
|
98
|
+
var set_token_interceptor = __webpack_require__(8359);
|
|
99
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/index.ts + 2 modules
|
|
100
|
+
var services = __webpack_require__(8230);
|
|
101
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-config.service.ts + 1 modules
|
|
102
|
+
var auth_config_service = __webpack_require__(6514);
|
|
103
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-datasource.provider.ts
|
|
104
|
+
var auth_datasource_provider = __webpack_require__(2732);
|
|
105
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/strategies/jwt.strategy.ts + 1 modules
|
|
106
|
+
var jwt_strategy = __webpack_require__(5389);
|
|
107
|
+
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/modules/auth.module.ts
|
|
108
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
109
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
110
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
111
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
112
|
+
} else {
|
|
113
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
114
|
+
if (d = decorators[i]) {
|
|
115
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class AuthModule {
|
|
137
|
+
static forRoot(options) {
|
|
138
|
+
const optionsProvider = {
|
|
139
|
+
provide: auth_constants/* .AUTH_MODULE_OPTIONS */.xe,
|
|
140
|
+
useValue: options
|
|
141
|
+
};
|
|
142
|
+
return this.buildModule(options, [
|
|
143
|
+
optionsProvider,
|
|
144
|
+
...options.providers ?? []
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
147
|
+
static forRootAsync(options) {
|
|
148
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
149
|
+
return this.buildModule(options, [
|
|
150
|
+
...asyncProviders,
|
|
151
|
+
...options.providers ?? []
|
|
152
|
+
], options.imports);
|
|
153
|
+
}
|
|
154
|
+
static buildModule(options, providers, externalImports = []) {
|
|
155
|
+
const { global = false, includeController = true, bootstrapAppConfig } = options;
|
|
156
|
+
const featureFlags = this.getFeatureFlags(bootstrapAppConfig);
|
|
157
|
+
return {
|
|
158
|
+
module: AuthModule,
|
|
159
|
+
global,
|
|
160
|
+
imports: [
|
|
161
|
+
...externalImports,
|
|
162
|
+
...this.buildImports()
|
|
163
|
+
],
|
|
164
|
+
controllers: this.buildControllers(includeController, featureFlags),
|
|
165
|
+
providers: [
|
|
166
|
+
...providers,
|
|
167
|
+
...this.buildProviders(featureFlags)
|
|
168
|
+
],
|
|
169
|
+
exports: this.buildExports(featureFlags)
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
static getFeatureFlags(bootstrapAppConfig) {
|
|
173
|
+
return {
|
|
174
|
+
enableCompanyFeature: bootstrapAppConfig?.enableCompanyFeature ?? false,
|
|
175
|
+
enableEmailVerification: bootstrapAppConfig?.enableEmailVerification ?? true
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
static buildImports() {
|
|
179
|
+
return [
|
|
180
|
+
passport_.PassportModule.register({
|
|
181
|
+
defaultStrategy: 'jwt'
|
|
182
|
+
}),
|
|
183
|
+
jwt_.JwtModule.register({}),
|
|
184
|
+
modules_.CacheModule,
|
|
185
|
+
modules_.UtilsModule
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
static buildControllers(includeController, flags) {
|
|
189
|
+
if (!includeController) return [];
|
|
190
|
+
const controllers = [
|
|
191
|
+
src_controllers/* .AuthenticationController */.$3,
|
|
192
|
+
src_controllers/* .SocialAuthController */.eA,
|
|
193
|
+
src_controllers/* .SocialAuthConfigController */.O3,
|
|
194
|
+
src_controllers/* .UserController */.SZ
|
|
195
|
+
];
|
|
196
|
+
if (flags.enableEmailVerification) {
|
|
197
|
+
controllers.push(src_controllers/* .EmailVerificationController */.Q1);
|
|
198
|
+
}
|
|
199
|
+
if (flags.enableCompanyFeature) {
|
|
200
|
+
controllers.push(src_controllers/* .CompanySelectionController */.Qg, src_controllers/* .CompanyController */.wD, src_controllers/* .BranchController */.zF, src_controllers/* .UserPermissionController */.rl);
|
|
201
|
+
}
|
|
202
|
+
return controllers;
|
|
203
|
+
}
|
|
204
|
+
static buildProviders(flags) {
|
|
205
|
+
const providers = [
|
|
206
|
+
auth_config_service/* .AuthConfigService */.W,
|
|
207
|
+
auth_datasource_provider/* .AuthDataSourceProvider */.v,
|
|
208
|
+
jwt_strategy/* .JwtStrategy */.P,
|
|
209
|
+
guards_.JwtAuthGuard,
|
|
210
|
+
services/* .AuthenticationService */.kX,
|
|
211
|
+
services/* .SocialAuthService */.Jn,
|
|
212
|
+
services/* .SocialAuthConfigService */.t_,
|
|
213
|
+
set_token_interceptor/* .SetToken */.A,
|
|
214
|
+
clear_token_interceptor/* .ClearToken */.t,
|
|
215
|
+
services/* .UserService */.DL,
|
|
216
|
+
(0,modules_.createModuleEventsProvider)('auth', auth_constants/* .AUTH_MODULE_OPTIONS */.xe)
|
|
217
|
+
];
|
|
218
|
+
if (flags.enableEmailVerification) {
|
|
219
|
+
providers.push(services/* .AuthEmailService */.Gw);
|
|
220
|
+
}
|
|
221
|
+
if (flags.enableCompanyFeature) {
|
|
222
|
+
providers.push(services/* .CompanySelectionSessionService */.vB, services/* .CompanyService */.Bl, services/* .BranchService */.O_, services/* .UserPermissionService */.OE, {
|
|
223
|
+
provide: interfaces_.COMPANY_ACCESS_RESOLVER,
|
|
224
|
+
useClass: services/* .CompanyAccessResolverAdapter */.ht
|
|
225
|
+
}, {
|
|
226
|
+
provide: interfaces_.BRANCH_HIERARCHY_RESOLVER,
|
|
227
|
+
useClass: services/* .BranchHierarchyResolverAdapter */.XR
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return providers;
|
|
231
|
+
}
|
|
232
|
+
static buildExports(flags) {
|
|
233
|
+
const exports = [
|
|
234
|
+
passport_.PassportModule,
|
|
235
|
+
auth_constants/* .AUTH_MODULE_OPTIONS */.xe,
|
|
236
|
+
auth_config_service/* .AuthConfigService */.W,
|
|
237
|
+
auth_datasource_provider/* .AuthDataSourceProvider */.v,
|
|
238
|
+
jwt_strategy/* .JwtStrategy */.P,
|
|
239
|
+
guards_.JwtAuthGuard,
|
|
240
|
+
services/* .AuthenticationService */.kX,
|
|
241
|
+
services/* .SocialAuthService */.Jn,
|
|
242
|
+
services/* .SocialAuthConfigService */.t_,
|
|
243
|
+
services/* .UserService */.DL
|
|
244
|
+
];
|
|
245
|
+
if (flags.enableEmailVerification) {
|
|
246
|
+
exports.push(services/* .AuthEmailService */.Gw);
|
|
247
|
+
}
|
|
248
|
+
if (flags.enableCompanyFeature) {
|
|
249
|
+
exports.push(services/* .CompanySelectionSessionService */.vB, services/* .CompanyService */.Bl, services/* .BranchService */.O_, services/* .UserPermissionService */.OE, interfaces_.COMPANY_ACCESS_RESOLVER, interfaces_.BRANCH_HIERARCHY_RESOLVER);
|
|
250
|
+
}
|
|
251
|
+
return exports;
|
|
252
|
+
}
|
|
253
|
+
static createAsyncProviders(options) {
|
|
254
|
+
const staticOptions = {
|
|
255
|
+
global: options.global,
|
|
256
|
+
includeController: options.includeController,
|
|
257
|
+
bootstrapAppConfig: options.bootstrapAppConfig
|
|
258
|
+
};
|
|
259
|
+
if (options.useFactory) {
|
|
260
|
+
return [
|
|
261
|
+
{
|
|
262
|
+
provide: auth_constants/* .AUTH_MODULE_OPTIONS */.xe,
|
|
263
|
+
useFactory: async (...args)=>({
|
|
264
|
+
...staticOptions,
|
|
265
|
+
config: await options.useFactory(...args)
|
|
266
|
+
}),
|
|
267
|
+
inject: options.inject || []
|
|
268
|
+
}
|
|
269
|
+
];
|
|
270
|
+
}
|
|
271
|
+
if (options.useClass) {
|
|
272
|
+
return [
|
|
273
|
+
{
|
|
274
|
+
provide: options.useClass,
|
|
275
|
+
useClass: options.useClass
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
provide: auth_constants/* .AUTH_MODULE_OPTIONS */.xe,
|
|
279
|
+
useFactory: async (factory)=>({
|
|
280
|
+
...staticOptions,
|
|
281
|
+
config: await factory.createAuthOptions()
|
|
282
|
+
}),
|
|
283
|
+
inject: [
|
|
284
|
+
options.useClass
|
|
285
|
+
]
|
|
286
|
+
}
|
|
287
|
+
];
|
|
288
|
+
}
|
|
289
|
+
if (options.useExisting) {
|
|
290
|
+
return [
|
|
291
|
+
{
|
|
292
|
+
provide: auth_constants/* .AUTH_MODULE_OPTIONS */.xe,
|
|
293
|
+
useFactory: async (factory)=>({
|
|
294
|
+
...staticOptions,
|
|
295
|
+
config: await factory.createAuthOptions()
|
|
296
|
+
}),
|
|
297
|
+
inject: [
|
|
298
|
+
options.useExisting
|
|
299
|
+
]
|
|
300
|
+
}
|
|
301
|
+
];
|
|
302
|
+
}
|
|
303
|
+
return [
|
|
304
|
+
{
|
|
305
|
+
provide: auth_constants/* .AUTH_MODULE_OPTIONS */.xe,
|
|
306
|
+
useValue: staticOptions
|
|
307
|
+
}
|
|
308
|
+
];
|
|
309
|
+
}
|
|
310
|
+
static getEntities(config) {
|
|
311
|
+
return (0,entities.getAuthEntitiesByConfig)({
|
|
312
|
+
enableCompanyFeature: config.enableCompanyFeature ?? false,
|
|
313
|
+
enableEmailVerification: config.enableEmailVerification ?? true
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
AuthModule = _ts_decorate([
|
|
318
|
+
(0,common_.Module)({})
|
|
319
|
+
], AuthModule);
|
|
320
|
+
|
|
321
|
+
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/modules/index.ts
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
},
|
|
326
|
+
8230(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
327
|
+
|
|
328
|
+
// EXPORTS
|
|
329
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
330
|
+
WE: () => (/* reexport */ auth_config_service/* .AuthConfigService */.W),
|
|
331
|
+
vS: () => (/* reexport */ auth_datasource_provider/* .AuthDataSourceProvider */.v),
|
|
332
|
+
Gw: () => (/* reexport */ auth_email_service/* .AuthEmailService */.G),
|
|
333
|
+
kX: () => (/* reexport */ authentication_service/* .AuthenticationService */.k),
|
|
334
|
+
XR: () => (/* reexport */ BranchHierarchyResolverAdapter),
|
|
335
|
+
O_: () => (/* reexport */ branch_service/* .BranchService */.O),
|
|
336
|
+
ht: () => (/* reexport */ CompanyAccessResolverAdapter),
|
|
337
|
+
vB: () => (/* reexport */ company_selection_session_service/* .CompanySelectionSessionService */.v),
|
|
338
|
+
Bl: () => (/* reexport */ company_service/* .CompanyService */.B),
|
|
339
|
+
t_: () => (/* reexport */ social_auth_config_service/* .SocialAuthConfigService */.t),
|
|
340
|
+
Jn: () => (/* reexport */ social_auth_service/* .SocialAuthService */.J),
|
|
341
|
+
OE: () => (/* reexport */ user_permission_service/* .UserPermissionService */.O),
|
|
342
|
+
DL: () => (/* reexport */ user_service/* .UserService */.D)
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/authentication.service.ts + 1 modules
|
|
346
|
+
var authentication_service = __webpack_require__(4722);
|
|
347
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-email.service.ts
|
|
348
|
+
var auth_email_service = __webpack_require__(3221);
|
|
349
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/company-selection-session.service.ts
|
|
350
|
+
var company_selection_session_service = __webpack_require__(5811);
|
|
351
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/social-auth.service.ts
|
|
352
|
+
var social_auth_service = __webpack_require__(2786);
|
|
353
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/social-auth-config.service.ts
|
|
354
|
+
var social_auth_config_service = __webpack_require__(8275);
|
|
355
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/user.service.ts
|
|
356
|
+
var user_service = __webpack_require__(7229);
|
|
357
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/company.service.ts
|
|
358
|
+
var company_service = __webpack_require__(9201);
|
|
359
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/branch.service.ts
|
|
360
|
+
var branch_service = __webpack_require__(5402);
|
|
361
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/user-permission.service.ts
|
|
362
|
+
var user_permission_service = __webpack_require__(5291);
|
|
363
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-config.service.ts + 1 modules
|
|
364
|
+
var auth_config_service = __webpack_require__(6514);
|
|
365
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-datasource.provider.ts
|
|
366
|
+
var auth_datasource_provider = __webpack_require__(2732);
|
|
367
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/interfaces"
|
|
368
|
+
var interfaces_ = __webpack_require__(5103);
|
|
369
|
+
// EXTERNAL MODULE: external "@nestjs/common"
|
|
370
|
+
var common_ = __webpack_require__(6157);
|
|
371
|
+
// EXTERNAL MODULE: external "@nestjs/core"
|
|
372
|
+
var core_ = __webpack_require__(3075);
|
|
373
|
+
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/services/branch-hierarchy-resolver.adapter.ts
|
|
374
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
375
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
376
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
377
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
378
|
+
} else {
|
|
379
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
380
|
+
if (d = decorators[i]) {
|
|
381
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
386
|
+
}
|
|
387
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
388
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
389
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
function _ts_param(paramIndex, decorator) {
|
|
393
|
+
return function(target, key) {
|
|
394
|
+
decorator(target, key, paramIndex);
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
class BranchHierarchyResolverAdapter {
|
|
402
|
+
moduleRef;
|
|
403
|
+
companyAccess;
|
|
404
|
+
constructor(moduleRef, companyAccess){
|
|
405
|
+
this.moduleRef = moduleRef;
|
|
406
|
+
this.companyAccess = companyAccess;
|
|
407
|
+
}
|
|
408
|
+
async getDescendantIds(branchIds, options) {
|
|
409
|
+
return (await this.resolve(branch_service/* .BranchService */.O)).getDescendantIds(branchIds, options);
|
|
410
|
+
}
|
|
411
|
+
async getAncestorIds(branchId, options) {
|
|
412
|
+
return (await this.resolve(branch_service/* .BranchService */.O)).getAncestorIds(branchId, options);
|
|
413
|
+
}
|
|
414
|
+
async isWithinBranch(branchId, ancestorId) {
|
|
415
|
+
return (await this.resolve(branch_service/* .BranchService */.O)).isWithinBranch(branchId, ancestorId);
|
|
416
|
+
}
|
|
417
|
+
async getGrantedBranchIds(userId, companyId) {
|
|
418
|
+
if (!userId) return [];
|
|
419
|
+
const { branches } = await this.companyAccess.getUserAccess(userId);
|
|
420
|
+
return branches.filter((branch)=>!companyId || branch.companyId === companyId).map((branch)=>branch.id);
|
|
421
|
+
}
|
|
422
|
+
async getGrantedDescendantIds(userId, branchIds, options) {
|
|
423
|
+
const granted = new Set(await this.getGrantedBranchIds(userId));
|
|
424
|
+
if (!granted.size) return [];
|
|
425
|
+
return (await this.getDescendantIds(branchIds, options)).filter((id)=>granted.has(id));
|
|
426
|
+
}
|
|
427
|
+
async hasBranchAccess(userId, branchId) {
|
|
428
|
+
if (!branchId) return false;
|
|
429
|
+
return (await this.getGrantedBranchIds(userId)).includes(branchId);
|
|
430
|
+
}
|
|
431
|
+
resolve(type) {
|
|
432
|
+
return this.moduleRef.resolve(type, core_.ContextIdFactory.create(), {
|
|
433
|
+
strict: false
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
BranchHierarchyResolverAdapter = _ts_decorate([
|
|
438
|
+
(0,common_.Injectable)(),
|
|
439
|
+
_ts_param(0, (0,common_.Inject)(core_.ModuleRef)),
|
|
440
|
+
_ts_param(1, (0,common_.Inject)(interfaces_.COMPANY_ACCESS_RESOLVER)),
|
|
441
|
+
_ts_metadata("design:type", Function),
|
|
442
|
+
_ts_metadata("design:paramtypes", [
|
|
443
|
+
typeof core_.ModuleRef === "undefined" ? Object : core_.ModuleRef,
|
|
444
|
+
typeof ICompanyAccessResolver === "undefined" ? Object : ICompanyAccessResolver
|
|
445
|
+
])
|
|
446
|
+
], BranchHierarchyResolverAdapter);
|
|
447
|
+
|
|
448
|
+
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/services/company-access-resolver.adapter.ts
|
|
449
|
+
function company_access_resolver_adapter_ts_decorate(decorators, target, key, desc) {
|
|
450
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
451
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
452
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
453
|
+
} else {
|
|
454
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
455
|
+
if (d = decorators[i]) {
|
|
456
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
461
|
+
}
|
|
462
|
+
function company_access_resolver_adapter_ts_metadata(metadataKey, metadataValue) {
|
|
463
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
464
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
function company_access_resolver_adapter_ts_param(paramIndex, decorator) {
|
|
468
|
+
return function(target, key) {
|
|
469
|
+
decorator(target, key, paramIndex);
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
const byName = (a, b)=>a.name.localeCompare(b.name);
|
|
476
|
+
/** Users of grants that still count: the grant is active and its user is active and not deleted. */ const activeUserIds = (grants)=>grants.filter((grant)=>grant.isActive && grant.user?.isActive && !grant.user.deletedAt).map((grant)=>grant.userId);
|
|
477
|
+
class CompanyAccessResolverAdapter {
|
|
478
|
+
moduleRef;
|
|
479
|
+
constructor(moduleRef){
|
|
480
|
+
this.moduleRef = moduleRef;
|
|
481
|
+
}
|
|
482
|
+
async getUserAccess(userId) {
|
|
483
|
+
const permissions = await this.moduleRef.resolve(user_permission_service/* .UserPermissionService */.O, core_.ContextIdFactory.create(), {
|
|
484
|
+
strict: false
|
|
485
|
+
});
|
|
486
|
+
const [companyGrants, branchGrants] = await Promise.all([
|
|
487
|
+
permissions.findUserCompanies(userId),
|
|
488
|
+
permissions.findUserBranches(userId)
|
|
489
|
+
]);
|
|
490
|
+
const companies = companyGrants.filter((grant)=>grant.isActive).map((grant)=>grant.company).filter((company)=>!!company?.isActive).toSorted(byName);
|
|
491
|
+
const companyIds = new Set(companies.map((company)=>company.id));
|
|
492
|
+
const branches = branchGrants.map((grant)=>grant.branch).filter((branch)=>!!branch?.isActive && companyIds.has(branch.companyId)).toSorted((a, b)=>(a.serial ?? 0) - (b.serial ?? 0) || byName(a, b));
|
|
493
|
+
return {
|
|
494
|
+
companies: companies.map(({ id, name })=>({
|
|
495
|
+
id,
|
|
496
|
+
name
|
|
497
|
+
})),
|
|
498
|
+
branches: branches.map(({ id, companyId, parentId, name })=>({
|
|
499
|
+
id,
|
|
500
|
+
companyId,
|
|
501
|
+
parentId: parentId ?? null,
|
|
502
|
+
name
|
|
503
|
+
}))
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
async getCompanyMembers(companyId, branchIds = []) {
|
|
507
|
+
const permissions = await this.moduleRef.resolve(user_permission_service/* .UserPermissionService */.O, core_.ContextIdFactory.create(), {
|
|
508
|
+
strict: false
|
|
509
|
+
});
|
|
510
|
+
const members = activeUserIds(await permissions.findUsersForCompany(companyId));
|
|
511
|
+
if (!branchIds.length) return [
|
|
512
|
+
...new Set(members)
|
|
513
|
+
];
|
|
514
|
+
const inBranches = new Set(activeUserIds((await Promise.all(branchIds.map((branchId)=>permissions.findUsersForBranch(branchId)))).flat()));
|
|
515
|
+
return [
|
|
516
|
+
...new Set(members.filter((userId)=>inBranches.has(userId)))
|
|
517
|
+
];
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
CompanyAccessResolverAdapter = company_access_resolver_adapter_ts_decorate([
|
|
521
|
+
(0,common_.Injectable)(),
|
|
522
|
+
company_access_resolver_adapter_ts_param(0, (0,common_.Inject)(core_.ModuleRef)),
|
|
523
|
+
company_access_resolver_adapter_ts_metadata("design:type", Function),
|
|
524
|
+
company_access_resolver_adapter_ts_metadata("design:paramtypes", [
|
|
525
|
+
typeof core_.ModuleRef === "undefined" ? Object : core_.ModuleRef
|
|
526
|
+
])
|
|
527
|
+
], CompanyAccessResolverAdapter);
|
|
528
|
+
|
|
529
|
+
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/services/index.ts
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
},
|
|
546
|
+
5389(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
547
|
+
|
|
548
|
+
// EXPORTS
|
|
549
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
550
|
+
P: () => (/* binding */ JwtStrategy)
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/constants"
|
|
554
|
+
var constants_ = __webpack_require__(9140);
|
|
555
|
+
// EXTERNAL MODULE: external "@nestjs/common"
|
|
556
|
+
var common_ = __webpack_require__(6157);
|
|
557
|
+
// EXTERNAL MODULE: external "@nestjs/core"
|
|
558
|
+
var core_ = __webpack_require__(3075);
|
|
559
|
+
// EXTERNAL MODULE: external "@nestjs/passport"
|
|
560
|
+
var passport_ = __webpack_require__(3794);
|
|
561
|
+
;// CONCATENATED MODULE: external "passport-jwt"
|
|
562
|
+
|
|
563
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/config/message-keys.ts
|
|
564
|
+
var message_keys = __webpack_require__(5363);
|
|
565
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/entities/app-user.entity.ts
|
|
566
|
+
var app_user_entity = __webpack_require__(4758);
|
|
567
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-config.service.ts + 1 modules
|
|
568
|
+
var auth_config_service = __webpack_require__(6514);
|
|
569
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-datasource.provider.ts
|
|
570
|
+
var auth_datasource_provider = __webpack_require__(2732);
|
|
571
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/authentication.service.ts + 1 modules
|
|
572
|
+
var authentication_service = __webpack_require__(4722);
|
|
573
|
+
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/strategies/jwt.strategy.ts
|
|
574
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
575
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
576
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
577
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
578
|
+
} else {
|
|
579
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
580
|
+
if (d = decorators[i]) {
|
|
581
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
586
|
+
}
|
|
587
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
588
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
589
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function _ts_param(paramIndex, decorator) {
|
|
593
|
+
return function(target, key) {
|
|
594
|
+
decorator(target, key, paramIndex);
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
function hasCompanyContext(payload) {
|
|
608
|
+
return 'companyId' in payload && payload.companyId != null;
|
|
609
|
+
}
|
|
610
|
+
class JwtStrategy extends (0,passport_.PassportStrategy)(Strategy, 'jwt') {
|
|
611
|
+
authConfig;
|
|
612
|
+
moduleRef;
|
|
613
|
+
constructor(authConfig, moduleRef){
|
|
614
|
+
super({
|
|
615
|
+
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
616
|
+
ignoreExpiration: false,
|
|
617
|
+
secretOrKeyProvider: (_req, _token, done)=>{
|
|
618
|
+
done(null, this.authConfig.getJwtSecret());
|
|
619
|
+
},
|
|
620
|
+
passReqToCallback: true
|
|
621
|
+
}), this.authConfig = authConfig, this.moduleRef = moduleRef;
|
|
622
|
+
}
|
|
623
|
+
async validate(_req, payload) {
|
|
624
|
+
const userRepo = await this.resolveUserRepository();
|
|
625
|
+
await this.checkTokenRevocation(payload);
|
|
626
|
+
const user = await userRepo.findOne({
|
|
627
|
+
where: {
|
|
628
|
+
id: payload.id,
|
|
629
|
+
isActive: true
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
if (!user) {
|
|
633
|
+
throw new common_.UnauthorizedException({
|
|
634
|
+
message: 'User not found or inactive',
|
|
635
|
+
messageKey: message_keys/* .USER_MESSAGES.NOT_FOUND */.ny.NOT_FOUND
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
return this.buildUserInfo(payload);
|
|
639
|
+
}
|
|
640
|
+
async resolveUserRepository() {
|
|
641
|
+
try {
|
|
642
|
+
const provider = await this.moduleRef.resolve(auth_datasource_provider/* .AuthDataSourceProvider */.v, undefined, {
|
|
643
|
+
strict: false
|
|
644
|
+
});
|
|
645
|
+
if (provider) {
|
|
646
|
+
return provider.getRepository(app_user_entity/* .AppUser */.$);
|
|
647
|
+
}
|
|
648
|
+
} catch {
|
|
649
|
+
throw new common_.UnauthorizedException({
|
|
650
|
+
message: 'Unable to access user data',
|
|
651
|
+
messageKey: constants_.SYSTEM_MESSAGES.SERVICE_NOT_AVAILABLE,
|
|
652
|
+
messageVariables: {
|
|
653
|
+
provider: 'DataSourceProvider',
|
|
654
|
+
available: ''
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
throw new common_.UnauthorizedException({
|
|
659
|
+
message: 'User repository not available',
|
|
660
|
+
messageKey: constants_.SYSTEM_MESSAGES.REPOSITORY_NOT_AVAILABLE,
|
|
661
|
+
messageVariables: {
|
|
662
|
+
entity: 'User'
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
async checkTokenRevocation(payload) {
|
|
667
|
+
if (!payload.iat) return;
|
|
668
|
+
try {
|
|
669
|
+
const authService = await this.moduleRef.resolve(authentication_service/* .AuthenticationService */.k, undefined, {
|
|
670
|
+
strict: false
|
|
671
|
+
});
|
|
672
|
+
if (authService && await authService.isTokenRevoked(payload.id, payload.iat)) {
|
|
673
|
+
throw new common_.UnauthorizedException({
|
|
674
|
+
message: 'Token has been revoked',
|
|
675
|
+
messageKey: message_keys/* .AUTH_MESSAGES.TOKEN_REVOKED */.mK.TOKEN_REVOKED
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
} catch (err) {
|
|
679
|
+
if (err instanceof common_.UnauthorizedException) throw err;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
buildUserInfo(payload) {
|
|
683
|
+
const base = {
|
|
684
|
+
id: payload.id,
|
|
685
|
+
email: payload.email
|
|
686
|
+
};
|
|
687
|
+
if (!hasCompanyContext(payload)) {
|
|
688
|
+
return base;
|
|
689
|
+
}
|
|
690
|
+
return {
|
|
691
|
+
...base,
|
|
692
|
+
companyId: payload.companyId,
|
|
693
|
+
...payload.branchId && {
|
|
694
|
+
branchId: payload.branchId
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
JwtStrategy = _ts_decorate([
|
|
700
|
+
(0,common_.Injectable)(),
|
|
701
|
+
_ts_param(0, (0,common_.Inject)(auth_config_service/* .AuthConfigService */.W)),
|
|
702
|
+
_ts_param(1, (0,common_.Inject)(core_.ModuleRef)),
|
|
703
|
+
_ts_metadata("design:type", Function),
|
|
704
|
+
_ts_metadata("design:paramtypes", [
|
|
705
|
+
typeof auth_config_service/* .AuthConfigService */.W === "undefined" ? Object : auth_config_service/* .AuthConfigService */.W,
|
|
706
|
+
typeof core_.ModuleRef === "undefined" ? Object : core_.ModuleRef
|
|
707
|
+
])
|
|
708
|
+
], JwtStrategy);
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
},
|
|
712
|
+
3794(module) {
|
|
713
|
+
|
|
714
|
+
module.exports = __rspack_external__nestjs_passport_18907953;
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
},
|
|
718
|
+
|
|
719
|
+
};
|