@flusys/nestjs-auth 7.1.0 → 8.0.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 +1 -1
- package/config/index.d.ts +3 -3
- package/config/message-keys.d.ts +4 -0
- package/controllers/authentication.controller.d.ts +5 -5
- package/controllers/branch.controller.d.ts +2 -2
- package/controllers/company-selection.controller.d.ts +4 -4
- package/controllers/company.controller.d.ts +2 -2
- package/controllers/email-verification.controller.d.ts +6 -6
- package/controllers/index.d.ts +9 -9
- package/controllers/social-auth-config.controller.d.ts +2 -2
- package/controllers/social-auth.controller.d.ts +3 -3
- package/controllers/user-permission.controller.d.ts +7 -4
- package/controllers/user.controller.d.ts +7 -7
- package/docs/auth-swagger.config.d.ts +2 -2
- package/docs/index.d.ts +1 -1
- package/dtos/index.d.ts +6 -6
- package/dtos/social-auth.dto.d.ts +1 -1
- package/dtos/user-permission.dto.d.ts +30 -0
- package/entities/company-branch.entity.d.ts +1 -1
- package/entities/company.entity.d.ts +1 -1
- package/entities/index.d.ts +14 -14
- package/entities/pending-registration.entity.d.ts +1 -1
- package/entities/user-company-permission.entity.d.ts +4 -4
- package/enums/index.d.ts +2 -2
- package/fesm/118.js +1404 -0
- package/fesm/120.js +2265 -0
- package/fesm/24.js +4422 -0
- package/fesm/370.js +1163 -0
- package/fesm/446.js +877 -0
- package/fesm/chunks/117.js +69 -0
- package/fesm/config/index.js +246 -3
- package/fesm/controllers/index.js +27 -9
- package/fesm/docs/index.js +479 -1
- package/fesm/dtos/index.js +135 -6
- package/fesm/entities/index.js +68 -22
- package/fesm/enums/index.js +53 -2
- package/fesm/helpers/index.js +115 -2
- package/fesm/index.js +1455 -13
- package/fesm/interceptors/index.js +510 -2
- package/fesm/interfaces/index.js +75 -8
- package/fesm/modules/index.js +546 -1
- package/fesm/runtime.js +134 -0
- package/fesm/services/index.js +67 -11
- package/helpers/auth-response.mapper.d.ts +3 -3
- package/helpers/index.d.ts +2 -2
- package/helpers/token.helper.d.ts +2 -2
- package/index.d.ts +13 -13
- package/interceptors/clear-token.interceptor.d.ts +2 -2
- package/interceptors/index.d.ts +2 -2
- package/interceptors/set-token.interceptor.d.ts +2 -2
- package/interfaces/auth-module-options.interface.d.ts +3 -3
- package/interfaces/authentication.interface.d.ts +3 -3
- package/interfaces/company-branch.interface.d.ts +2 -2
- package/interfaces/company.interface.d.ts +1 -1
- package/interfaces/index.d.ts +8 -8
- package/interfaces/social-auth.interface.d.ts +2 -2
- package/interfaces/user-enricher.interface.d.ts +3 -3
- package/modules/auth.module.d.ts +4 -4
- package/modules/index.d.ts +1 -1
- package/package.json +32 -39
- package/providers/facebook.social-provider.d.ts +2 -2
- package/providers/google.social-provider.d.ts +2 -2
- package/providers/index.d.ts +1 -1
- package/providers/linkedin.social-provider.d.ts +2 -2
- package/providers/microsoft.social-provider.d.ts +2 -2
- package/providers/social-provider.registry.d.ts +2 -2
- package/services/auth-config.service.d.ts +3 -3
- package/services/auth-datasource.provider.d.ts +3 -3
- package/services/auth-email.service.d.ts +3 -3
- package/services/authentication.service.d.ts +12 -12
- package/services/branch.service.d.ts +7 -7
- package/services/company.service.d.ts +6 -6
- package/services/index.d.ts +11 -11
- package/services/social-auth-config.service.d.ts +6 -6
- package/services/social-auth.service.d.ts +5 -5
- package/services/user-permission.service.d.ts +10 -4
- package/services/user.service.d.ts +7 -7
- package/strategies/jwt.strategy.d.ts +4 -4
- package/validators/password.validator.d.ts +1 -1
- package/cjs/config/auth.constants.js +0 -49
- package/cjs/config/event-actions.js +0 -47
- package/cjs/config/index.js +0 -20
- package/cjs/config/message-keys.js +0 -135
- package/cjs/controllers/authentication.controller.js +0 -427
- package/cjs/controllers/authentication.controller.spec.js +0 -219
- package/cjs/controllers/branch.controller.js +0 -102
- package/cjs/controllers/branch.controller.spec.js +0 -134
- package/cjs/controllers/company-selection.controller.js +0 -198
- package/cjs/controllers/company-selection.controller.spec.js +0 -84
- package/cjs/controllers/company.controller.js +0 -102
- package/cjs/controllers/company.controller.spec.js +0 -131
- package/cjs/controllers/email-verification.controller.js +0 -224
- package/cjs/controllers/email-verification.controller.spec.js +0 -142
- package/cjs/controllers/index.js +0 -26
- package/cjs/controllers/social-auth-config.controller.js +0 -107
- package/cjs/controllers/social-auth.controller.js +0 -175
- package/cjs/controllers/social-auth.controller.spec.js +0 -79
- package/cjs/controllers/user-permission.controller.js +0 -223
- package/cjs/controllers/user-permission.controller.spec.js +0 -138
- package/cjs/controllers/user.controller.js +0 -438
- package/cjs/controllers/user.controller.spec.js +0 -204
- package/cjs/docs/auth-swagger.config.js +0 -461
- package/cjs/docs/auth-swagger.config.spec.js +0 -130
- package/cjs/docs/index.js +0 -18
- package/cjs/dtos/authentication.dto.js +0 -755
- package/cjs/dtos/company-branch.dto.js +0 -294
- package/cjs/dtos/company.dto.js +0 -298
- package/cjs/dtos/index.js +0 -23
- package/cjs/dtos/social-auth.dto.js +0 -318
- package/cjs/dtos/user-permission.dto.js +0 -358
- package/cjs/dtos/user.dto.js +0 -413
- package/cjs/entities/app-user.entity.js +0 -25
- package/cjs/entities/company-branch.entity.js +0 -163
- package/cjs/entities/company.entity.js +0 -146
- package/cjs/entities/index.js +0 -67
- package/cjs/entities/index.spec.js +0 -84
- package/cjs/entities/pending-registration.entity.js +0 -135
- package/cjs/entities/social-auth-config.entity.js +0 -102
- package/cjs/entities/user-company-permission.entity.js +0 -153
- package/cjs/entities/user-token.entity.js +0 -120
- package/cjs/enums/index.js +0 -19
- package/cjs/enums/social-provider-type.enum.js +0 -17
- package/cjs/enums/user-org-permission-type.enum.js +0 -15
- package/cjs/helpers/auth-response.mapper.js +0 -46
- package/cjs/helpers/auth-response.mapper.spec.js +0 -139
- package/cjs/helpers/index.js +0 -19
- package/cjs/helpers/token.helper.js +0 -58
- package/cjs/helpers/token.helper.spec.js +0 -86
- package/cjs/index.js +0 -30
- package/cjs/interceptors/clear-token.interceptor.js +0 -73
- package/cjs/interceptors/clear-token.interceptor.spec.js +0 -107
- package/cjs/interceptors/index.js +0 -19
- package/cjs/interceptors/set-token.interceptor.js +0 -107
- package/cjs/interceptors/set-token.interceptor.spec.js +0 -165
- package/cjs/interfaces/auth-email-provider.interface.js +0 -45
- package/cjs/interfaces/auth-module-options.interface.js +0 -4
- package/cjs/interfaces/authentication.interface.js +0 -4
- package/cjs/interfaces/company-branch.interface.js +0 -4
- package/cjs/interfaces/company.interface.js +0 -4
- package/cjs/interfaces/index.js +0 -25
- package/cjs/interfaces/social-auth.interface.js +0 -4
- package/cjs/interfaces/user-enricher.interface.js +0 -4
- package/cjs/interfaces/user.interface.js +0 -4
- package/cjs/modules/auth.module.js +0 -208
- package/cjs/modules/auth.module.spec.js +0 -258
- package/cjs/modules/index.js +0 -18
- package/cjs/providers/facebook.social-provider.js +0 -73
- package/cjs/providers/google.social-provider.js +0 -68
- package/cjs/providers/index.js +0 -18
- package/cjs/providers/linkedin.social-provider.js +0 -66
- package/cjs/providers/microsoft.social-provider.js +0 -78
- package/cjs/providers/oauth-http.util.js +0 -107
- package/cjs/providers/social-provider.registry.js +0 -24
- package/cjs/providers/social-provider.registry.spec.js +0 -135
- package/cjs/services/auth-config.service.js +0 -113
- package/cjs/services/auth-config.service.spec.js +0 -100
- package/cjs/services/auth-datasource.provider.js +0 -138
- package/cjs/services/auth-datasource.provider.spec.js +0 -191
- package/cjs/services/auth-email.service.js +0 -539
- package/cjs/services/auth-email.service.spec.js +0 -456
- package/cjs/services/authentication.service.js +0 -1203
- package/cjs/services/authentication.service.spec.js +0 -1020
- package/cjs/services/branch.service.js +0 -153
- package/cjs/services/branch.service.spec.js +0 -169
- package/cjs/services/company-selection-session.service.js +0 -121
- package/cjs/services/company-selection-session.service.spec.js +0 -90
- package/cjs/services/company.service.js +0 -140
- package/cjs/services/company.service.spec.js +0 -127
- package/cjs/services/index.js +0 -28
- package/cjs/services/social-auth-config.service.js +0 -103
- package/cjs/services/social-auth-config.service.spec.js +0 -71
- package/cjs/services/social-auth.service.js +0 -310
- package/cjs/services/social-auth.service.spec.js +0 -310
- package/cjs/services/user-permission.service.js +0 -236
- package/cjs/services/user-permission.service.spec.js +0 -254
- package/cjs/services/user.service.js +0 -671
- package/cjs/services/user.service.spec.js +0 -718
- package/cjs/strategies/jwt.strategy.js +0 -140
- package/cjs/strategies/jwt.strategy.spec.js +0 -166
- package/cjs/validators/password.validator.js +0 -45
- package/cjs/validators/password.validator.spec.js +0 -161
- package/fesm/config/auth.constants.js +0 -14
- package/fesm/config/event-actions.js +0 -26
- package/fesm/config/message-keys.js +0 -99
- package/fesm/controllers/authentication.controller.js +0 -417
- package/fesm/controllers/authentication.controller.spec.js +0 -215
- package/fesm/controllers/branch.controller.js +0 -92
- package/fesm/controllers/branch.controller.spec.js +0 -130
- package/fesm/controllers/company-selection.controller.js +0 -188
- package/fesm/controllers/company-selection.controller.spec.js +0 -80
- package/fesm/controllers/company.controller.js +0 -92
- package/fesm/controllers/company.controller.spec.js +0 -127
- package/fesm/controllers/email-verification.controller.js +0 -214
- package/fesm/controllers/email-verification.controller.spec.js +0 -138
- package/fesm/controllers/social-auth-config.controller.js +0 -97
- package/fesm/controllers/social-auth.controller.js +0 -165
- package/fesm/controllers/social-auth.controller.spec.js +0 -75
- package/fesm/controllers/user-permission.controller.js +0 -213
- package/fesm/controllers/user-permission.controller.spec.js +0 -134
- package/fesm/controllers/user.controller.js +0 -428
- package/fesm/controllers/user.controller.spec.js +0 -200
- package/fesm/docs/auth-swagger.config.js +0 -454
- package/fesm/docs/auth-swagger.config.spec.js +0 -126
- package/fesm/dtos/authentication.dto.js +0 -683
- package/fesm/dtos/company-branch.dto.js +0 -279
- package/fesm/dtos/company.dto.js +0 -283
- package/fesm/dtos/social-auth.dto.js +0 -282
- package/fesm/dtos/user-permission.dto.js +0 -339
- package/fesm/dtos/user.dto.js +0 -391
- package/fesm/entities/app-user.entity.js +0 -15
- package/fesm/entities/company-branch.entity.js +0 -153
- package/fesm/entities/company.entity.js +0 -136
- package/fesm/entities/index.spec.js +0 -80
- package/fesm/entities/pending-registration.entity.js +0 -125
- package/fesm/entities/social-auth-config.entity.js +0 -92
- package/fesm/entities/user-company-permission.entity.js +0 -136
- package/fesm/entities/user-token.entity.js +0 -104
- package/fesm/enums/social-provider-type.enum.js +0 -7
- package/fesm/enums/user-org-permission-type.enum.js +0 -5
- package/fesm/helpers/auth-response.mapper.js +0 -25
- package/fesm/helpers/auth-response.mapper.spec.js +0 -135
- package/fesm/helpers/token.helper.js +0 -40
- package/fesm/helpers/token.helper.spec.js +0 -82
- package/fesm/interceptors/clear-token.interceptor.js +0 -63
- package/fesm/interceptors/clear-token.interceptor.spec.js +0 -103
- package/fesm/interceptors/set-token.interceptor.js +0 -98
- package/fesm/interceptors/set-token.interceptor.spec.js +0 -161
- package/fesm/interfaces/auth-email-provider.interface.js +0 -38
- package/fesm/interfaces/auth-module-options.interface.js +0 -3
- package/fesm/interfaces/authentication.interface.js +0 -1
- package/fesm/interfaces/company-branch.interface.js +0 -1
- package/fesm/interfaces/company.interface.js +0 -1
- package/fesm/interfaces/social-auth.interface.js +0 -1
- package/fesm/interfaces/user-enricher.interface.js +0 -4
- package/fesm/interfaces/user.interface.js +0 -1
- package/fesm/modules/auth.module.js +0 -198
- package/fesm/modules/auth.module.spec.js +0 -254
- package/fesm/providers/facebook.social-provider.js +0 -63
- package/fesm/providers/google.social-provider.js +0 -58
- package/fesm/providers/index.js +0 -1
- package/fesm/providers/linkedin.social-provider.js +0 -56
- package/fesm/providers/microsoft.social-provider.js +0 -68
- package/fesm/providers/oauth-http.util.js +0 -77
- package/fesm/providers/social-provider.registry.js +0 -14
- package/fesm/providers/social-provider.registry.spec.js +0 -131
- package/fesm/services/auth-config.service.js +0 -103
- package/fesm/services/auth-config.service.spec.js +0 -96
- package/fesm/services/auth-datasource.provider.js +0 -87
- package/fesm/services/auth-datasource.provider.spec.js +0 -187
- package/fesm/services/auth-email.service.js +0 -488
- package/fesm/services/auth-email.service.spec.js +0 -411
- package/fesm/services/authentication.service.js +0 -1152
- package/fesm/services/authentication.service.spec.js +0 -975
- package/fesm/services/branch.service.js +0 -143
- package/fesm/services/branch.service.spec.js +0 -165
- package/fesm/services/company-selection-session.service.js +0 -111
- package/fesm/services/company-selection-session.service.spec.js +0 -86
- package/fesm/services/company.service.js +0 -130
- package/fesm/services/company.service.spec.js +0 -123
- package/fesm/services/social-auth-config.service.js +0 -93
- package/fesm/services/social-auth-config.service.spec.js +0 -67
- package/fesm/services/social-auth.service.js +0 -300
- package/fesm/services/social-auth.service.spec.js +0 -265
- package/fesm/services/user-permission.service.js +0 -226
- package/fesm/services/user-permission.service.spec.js +0 -250
- package/fesm/services/user.service.js +0 -620
- package/fesm/services/user.service.spec.js +0 -673
- package/fesm/strategies/jwt.strategy.js +0 -130
- package/fesm/strategies/jwt.strategy.spec.js +0 -162
- package/fesm/validators/password.validator.js +0 -48
- package/fesm/validators/password.validator.spec.js +0 -157
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { MultiTenantDataSourceService } from '@flusys/nestjs-shared';
|
|
2
|
-
import { AuthDataSourceProvider } from './auth-datasource.provider';
|
|
3
|
-
function buildOptions(overrides = {}) {
|
|
4
|
-
return {
|
|
5
|
-
global: false,
|
|
6
|
-
includeController: true,
|
|
7
|
-
bootstrapAppConfig: {
|
|
8
|
-
databaseMode: 'single',
|
|
9
|
-
enableCompanyFeature: false,
|
|
10
|
-
enableEmailVerification: true
|
|
11
|
-
},
|
|
12
|
-
...overrides
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
describe('AuthDataSourceProvider', ()=>{
|
|
16
|
-
afterEach(()=>{
|
|
17
|
-
jest.restoreAllMocks();
|
|
18
|
-
});
|
|
19
|
-
describe('isCompanyFeatureEnabled', ()=>{
|
|
20
|
-
it('returns false by default when bootstrap config disables it', ()=>{
|
|
21
|
-
const provider = new AuthDataSourceProvider(buildOptions());
|
|
22
|
-
expect(provider.isCompanyFeatureEnabled()).toBe(false);
|
|
23
|
-
});
|
|
24
|
-
it('returns true when bootstrap config enables it', ()=>{
|
|
25
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
26
|
-
bootstrapAppConfig: {
|
|
27
|
-
databaseMode: 'single',
|
|
28
|
-
enableCompanyFeature: true
|
|
29
|
-
}
|
|
30
|
-
}));
|
|
31
|
-
expect(provider.isCompanyFeatureEnabled()).toBe(true);
|
|
32
|
-
});
|
|
33
|
-
it('prefers the tenant override over bootstrap config', ()=>{
|
|
34
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
35
|
-
bootstrapAppConfig: {
|
|
36
|
-
databaseMode: 'multi-tenant',
|
|
37
|
-
enableCompanyFeature: false
|
|
38
|
-
}
|
|
39
|
-
}));
|
|
40
|
-
expect(provider.isCompanyFeatureEnabled({
|
|
41
|
-
enableCompanyFeature: true
|
|
42
|
-
})).toBe(true);
|
|
43
|
-
});
|
|
44
|
-
it('defaults to false when no bootstrap config and no tenant override is present', ()=>{
|
|
45
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
46
|
-
bootstrapAppConfig: undefined
|
|
47
|
-
}));
|
|
48
|
-
expect(provider.isCompanyFeatureEnabled()).toBe(false);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
describe('isEmailVerificationEnabled', ()=>{
|
|
52
|
-
it('returns true by default (feature defaults to enabled)', ()=>{
|
|
53
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
54
|
-
bootstrapAppConfig: undefined
|
|
55
|
-
}));
|
|
56
|
-
expect(provider.isEmailVerificationEnabled()).toBe(true);
|
|
57
|
-
});
|
|
58
|
-
it('returns false when bootstrap config disables it', ()=>{
|
|
59
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
60
|
-
bootstrapAppConfig: {
|
|
61
|
-
databaseMode: 'single',
|
|
62
|
-
enableCompanyFeature: false,
|
|
63
|
-
enableEmailVerification: false
|
|
64
|
-
}
|
|
65
|
-
}));
|
|
66
|
-
expect(provider.isEmailVerificationEnabled()).toBe(false);
|
|
67
|
-
});
|
|
68
|
-
it('prefers the tenant override over bootstrap config', ()=>{
|
|
69
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
70
|
-
bootstrapAppConfig: {
|
|
71
|
-
databaseMode: 'multi-tenant',
|
|
72
|
-
enableCompanyFeature: true,
|
|
73
|
-
enableEmailVerification: true
|
|
74
|
-
}
|
|
75
|
-
}));
|
|
76
|
-
expect(provider.isEmailVerificationEnabled({
|
|
77
|
-
enableEmailVerification: false
|
|
78
|
-
})).toBe(false);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
describe('isSignUpEnabled', ()=>{
|
|
82
|
-
it('returns true by default (sign-up defaults to enabled)', ()=>{
|
|
83
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
84
|
-
bootstrapAppConfig: undefined
|
|
85
|
-
}));
|
|
86
|
-
expect(provider.isSignUpEnabled()).toBe(true);
|
|
87
|
-
});
|
|
88
|
-
it('returns false when bootstrap config disables it', ()=>{
|
|
89
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
90
|
-
bootstrapAppConfig: {
|
|
91
|
-
databaseMode: 'single',
|
|
92
|
-
enableCompanyFeature: false,
|
|
93
|
-
enableSignUp: false
|
|
94
|
-
}
|
|
95
|
-
}));
|
|
96
|
-
expect(provider.isSignUpEnabled()).toBe(false);
|
|
97
|
-
});
|
|
98
|
-
it('prefers the tenant override over bootstrap config', ()=>{
|
|
99
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
100
|
-
bootstrapAppConfig: {
|
|
101
|
-
databaseMode: 'multi-tenant',
|
|
102
|
-
enableCompanyFeature: true,
|
|
103
|
-
enableSignUp: true
|
|
104
|
-
}
|
|
105
|
-
}));
|
|
106
|
-
expect(provider.isSignUpEnabled({
|
|
107
|
-
enableSignUp: false
|
|
108
|
-
})).toBe(false);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
describe('getAuthEntities', ()=>{
|
|
112
|
-
it('returns only base entities when company feature and email verification are disabled', async ()=>{
|
|
113
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
114
|
-
bootstrapAppConfig: {
|
|
115
|
-
databaseMode: 'single',
|
|
116
|
-
enableCompanyFeature: false,
|
|
117
|
-
enableEmailVerification: false
|
|
118
|
-
}
|
|
119
|
-
}));
|
|
120
|
-
const entities = await provider.getAuthEntities();
|
|
121
|
-
const names = entities.map((e)=>e.name);
|
|
122
|
-
expect(names).toEqual(expect.arrayContaining([
|
|
123
|
-
'AppUser',
|
|
124
|
-
'UserToken'
|
|
125
|
-
]));
|
|
126
|
-
expect(names).not.toContain('Company');
|
|
127
|
-
expect(names).not.toContain('PendingRegistration');
|
|
128
|
-
});
|
|
129
|
-
it('includes company entities when company feature is enabled', async ()=>{
|
|
130
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
131
|
-
bootstrapAppConfig: {
|
|
132
|
-
databaseMode: 'single',
|
|
133
|
-
enableCompanyFeature: true,
|
|
134
|
-
enableEmailVerification: false
|
|
135
|
-
}
|
|
136
|
-
}));
|
|
137
|
-
const entities = await provider.getAuthEntities();
|
|
138
|
-
const names = entities.map((e)=>e.name);
|
|
139
|
-
expect(names).toEqual(expect.arrayContaining([
|
|
140
|
-
'AppUser',
|
|
141
|
-
'UserToken',
|
|
142
|
-
'Company',
|
|
143
|
-
'CompanyBranch',
|
|
144
|
-
'UserCompanyPermission'
|
|
145
|
-
]));
|
|
146
|
-
});
|
|
147
|
-
it('includes pending registration entity when email verification is enabled', async ()=>{
|
|
148
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
149
|
-
bootstrapAppConfig: {
|
|
150
|
-
databaseMode: 'single',
|
|
151
|
-
enableCompanyFeature: false,
|
|
152
|
-
enableEmailVerification: true
|
|
153
|
-
}
|
|
154
|
-
}));
|
|
155
|
-
const entities = await provider.getAuthEntities();
|
|
156
|
-
const names = entities.map((e)=>e.name);
|
|
157
|
-
expect(names).toContain('PendingRegistration');
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
describe('createDataSourceFromConfig', ()=>{
|
|
161
|
-
it('forwards the config and resolved auth entities to the parent implementation', async ()=>{
|
|
162
|
-
const fakeDataSource = {
|
|
163
|
-
isInitialized: true
|
|
164
|
-
};
|
|
165
|
-
const parentSpy = jest.spyOn(MultiTenantDataSourceService.prototype, 'createDataSourceFromConfig').mockResolvedValue(fakeDataSource);
|
|
166
|
-
const provider = new AuthDataSourceProvider(buildOptions({
|
|
167
|
-
bootstrapAppConfig: {
|
|
168
|
-
databaseMode: 'single',
|
|
169
|
-
enableCompanyFeature: true,
|
|
170
|
-
enableEmailVerification: true
|
|
171
|
-
}
|
|
172
|
-
}));
|
|
173
|
-
const config = {
|
|
174
|
-
type: 'postgres',
|
|
175
|
-
host: 'localhost'
|
|
176
|
-
};
|
|
177
|
-
const result = await provider.createDataSourceFromConfig(config);
|
|
178
|
-
expect(result).toBe(fakeDataSource);
|
|
179
|
-
expect(parentSpy).toHaveBeenCalledWith(config, expect.any(Array));
|
|
180
|
-
const forwardedEntityNames = parentSpy.mock.calls[0][1].map((e)=>e.name);
|
|
181
|
-
expect(forwardedEntityNames).toEqual(expect.arrayContaining([
|
|
182
|
-
'AppUser',
|
|
183
|
-
'Company'
|
|
184
|
-
]));
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
});
|
|
@@ -1,488 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
function _ts_param(paramIndex, decorator) {
|
|
24
|
-
return function(target, key) {
|
|
25
|
-
decorator(target, key, paramIndex);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
import { LogAction } from '@flusys/nestjs-shared';
|
|
29
|
-
import { publishDomainEvent } from '@flusys/nestjs-shared/classes';
|
|
30
|
-
import { SYSTEM_MESSAGES } from '@flusys/nestjs-shared/constants';
|
|
31
|
-
import { BadRequestException, Inject, Injectable, InternalServerErrorException, Optional, Scope } from '@nestjs/common';
|
|
32
|
-
import * as bcrypt from 'bcrypt';
|
|
33
|
-
import * as crypto from 'crypto';
|
|
34
|
-
import { AUTH_EVENT_ACTIONS, AUTH_EVENT_ENTITIES, AUTH_EVENT_MODULE, AUTH_MESSAGES, BCRYPT_SALT_ROUNDS, EMAIL_VERIFICATION_MESSAGES, USER_MESSAGES } from '../config';
|
|
35
|
-
import { AppUser } from '../entities/app-user.entity';
|
|
36
|
-
import { PendingRegistration } from '../entities/pending-registration.entity';
|
|
37
|
-
import { TokenType, UserToken } from '../entities/user-token.entity';
|
|
38
|
-
import { AUTH_EMAIL_PROVIDER, IAuthEmailProvider } from '../interfaces';
|
|
39
|
-
import { AuthDataSourceProvider } from './auth-datasource.provider';
|
|
40
|
-
export class AuthEmailService {
|
|
41
|
-
isEmailEnabled() {
|
|
42
|
-
return !!this.emailProvider;
|
|
43
|
-
}
|
|
44
|
-
async getRepository(entity) {
|
|
45
|
-
if (!this.dataSourceProvider) {
|
|
46
|
-
throw new InternalServerErrorException({
|
|
47
|
-
message: `${String(entity)} repository not available`,
|
|
48
|
-
messageKey: SYSTEM_MESSAGES.REPOSITORY_NOT_AVAILABLE,
|
|
49
|
-
messageVariables: {
|
|
50
|
-
entity: String(entity)
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return this.dataSourceProvider.getRepository(entity);
|
|
55
|
-
}
|
|
56
|
-
generateToken() {
|
|
57
|
-
return crypto.randomBytes(32).toString('hex');
|
|
58
|
-
}
|
|
59
|
-
hashToken(token) {
|
|
60
|
-
return crypto.createHash('sha256').update(token).digest('hex');
|
|
61
|
-
}
|
|
62
|
-
assertEmailEnabled() {
|
|
63
|
-
if (!this.emailProvider) {
|
|
64
|
-
throw new BadRequestException({
|
|
65
|
-
message: 'Email service is not configured',
|
|
66
|
-
messageKey: AUTH_MESSAGES.EMAIL_NOT_CONFIGURED
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async sendVerificationEmailSafe(email, token, verifyUrl) {
|
|
71
|
-
try {
|
|
72
|
-
await this.emailProvider.sendVerificationEmail(email, token, verifyUrl);
|
|
73
|
-
} catch {
|
|
74
|
-
throw new BadRequestException({
|
|
75
|
-
message: 'Failed to send verification email. Please try again.',
|
|
76
|
-
messageKey: AUTH_MESSAGES.EMAIL_SEND_FAILED
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
validateTokenNotExpiredOrUsed(token, expiredMessage, expiredMessageKey, usedMessage, usedMessageKey) {
|
|
81
|
-
if (token.expiresAt < new Date()) {
|
|
82
|
-
throw new BadRequestException({
|
|
83
|
-
message: expiredMessage,
|
|
84
|
-
messageKey: expiredMessageKey
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
if (usedMessage && usedMessageKey && token.usedAt) {
|
|
88
|
-
throw new BadRequestException({
|
|
89
|
-
message: usedMessage,
|
|
90
|
-
messageKey: usedMessageKey
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async hasPendingRegistration(email) {
|
|
95
|
-
if (!this.isEmailEnabled()) return false;
|
|
96
|
-
const pendingRepository = await this.getRepository(PendingRegistration);
|
|
97
|
-
const pending = await pendingRepository.findOne({
|
|
98
|
-
where: {
|
|
99
|
-
email
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
return !!pending && pending.expiresAt > new Date();
|
|
103
|
-
}
|
|
104
|
-
async createPendingRegistration(data) {
|
|
105
|
-
this.assertEmailEnabled();
|
|
106
|
-
const userRepository = await this.getRepository(AppUser);
|
|
107
|
-
const pendingRepository = await this.getRepository(PendingRegistration);
|
|
108
|
-
// Check if user already exists
|
|
109
|
-
const existingUser = await userRepository.findOne({
|
|
110
|
-
where: {
|
|
111
|
-
email: data.email
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
if (existingUser) {
|
|
115
|
-
throw new BadRequestException({
|
|
116
|
-
message: 'Registration failed. Please try again or contact support.',
|
|
117
|
-
messageKey: AUTH_MESSAGES.REGISTER_FAILED
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
// Delete any existing pending registration for this email
|
|
121
|
-
await pendingRepository.delete({
|
|
122
|
-
email: data.email
|
|
123
|
-
});
|
|
124
|
-
// Create pending registration with hashed token for secure storage
|
|
125
|
-
const token = this.generateToken();
|
|
126
|
-
const tokenHash = this.hashToken(token);
|
|
127
|
-
const passwordHash = await bcrypt.hash(data.password, BCRYPT_SALT_ROUNDS);
|
|
128
|
-
const expiresAt = new Date(Date.now() + this.EMAIL_VERIFICATION_EXPIRY);
|
|
129
|
-
const pending = pendingRepository.create({
|
|
130
|
-
email: data.email,
|
|
131
|
-
name: data.name ?? null,
|
|
132
|
-
phone: data.phone ?? null,
|
|
133
|
-
passwordHash,
|
|
134
|
-
token: tokenHash,
|
|
135
|
-
expiresAt,
|
|
136
|
-
companyData: data.companyData ?? null,
|
|
137
|
-
additionalFields: data.additionalFields ?? null
|
|
138
|
-
});
|
|
139
|
-
await pendingRepository.save(pending);
|
|
140
|
-
// Send verification email with raw token (user receives this)
|
|
141
|
-
const verifyUrl = `${data.verifyUrlBase}?token=${token}`;
|
|
142
|
-
await this.sendVerificationEmailSafe(data.email, token, verifyUrl);
|
|
143
|
-
return {
|
|
144
|
-
success: true,
|
|
145
|
-
message: 'Please check your email to verify your registration.',
|
|
146
|
-
messageKey: EMAIL_VERIFICATION_MESSAGES.VERIFICATION_SENT
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
async forgotPassword(email, resetUrlBase) {
|
|
150
|
-
this.assertEmailEnabled();
|
|
151
|
-
const userRepository = await this.getRepository(AppUser);
|
|
152
|
-
const tokenRepository = await this.getRepository(UserToken);
|
|
153
|
-
const user = await userRepository.findOne({
|
|
154
|
-
where: {
|
|
155
|
-
email
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
// Always return success to prevent email enumeration
|
|
159
|
-
if (!user || !user.isActive) {
|
|
160
|
-
return {
|
|
161
|
-
success: true,
|
|
162
|
-
message: 'If the email exists, a password reset link has been sent.',
|
|
163
|
-
messageKey: AUTH_MESSAGES.PASSWORD_RESET_EMAIL_SENT
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
// Invalidate existing password reset tokens for this user
|
|
167
|
-
await tokenRepository.delete({
|
|
168
|
-
userId: user.id,
|
|
169
|
-
type: TokenType.PASSWORD_RESET
|
|
170
|
-
});
|
|
171
|
-
// Create new token with hashed storage
|
|
172
|
-
const token = this.generateToken();
|
|
173
|
-
const tokenHash = this.hashToken(token);
|
|
174
|
-
const userToken = tokenRepository.create({
|
|
175
|
-
userId: user.id,
|
|
176
|
-
type: TokenType.PASSWORD_RESET,
|
|
177
|
-
token: tokenHash,
|
|
178
|
-
expiresAt: new Date(Date.now() + this.PASSWORD_RESET_EXPIRY)
|
|
179
|
-
});
|
|
180
|
-
await tokenRepository.save(userToken);
|
|
181
|
-
// Send email with raw token
|
|
182
|
-
const resetUrl = `${resetUrlBase}?token=${token}`;
|
|
183
|
-
try {
|
|
184
|
-
await this.emailProvider.sendPasswordResetEmail(email, token, resetUrl);
|
|
185
|
-
} catch {
|
|
186
|
-
throw new BadRequestException({
|
|
187
|
-
message: 'Failed to process request. Please try again later.',
|
|
188
|
-
messageKey: SYSTEM_MESSAGES.INTERNAL_ERROR,
|
|
189
|
-
messageVariables: {
|
|
190
|
-
provider: 'EmailProvider',
|
|
191
|
-
error: 'Send email failed'
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
await this.publishUserEvent(AUTH_EVENT_ACTIONS.PASSWORD_RESET_REQUESTED, user.id, {
|
|
196
|
-
email: user.email
|
|
197
|
-
});
|
|
198
|
-
return {
|
|
199
|
-
success: true,
|
|
200
|
-
message: 'If the email exists, a password reset link has been sent.',
|
|
201
|
-
messageKey: AUTH_MESSAGES.PASSWORD_RESET_EMAIL_SENT
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
async resetPassword(token, newPassword) {
|
|
205
|
-
const userRepository = await this.getRepository(AppUser);
|
|
206
|
-
const tokenRepository = await this.getRepository(UserToken);
|
|
207
|
-
// Hash the incoming token to compare with stored hash
|
|
208
|
-
const tokenHash = this.hashToken(token);
|
|
209
|
-
const userToken = await tokenRepository.findOne({
|
|
210
|
-
where: {
|
|
211
|
-
token: tokenHash,
|
|
212
|
-
type: TokenType.PASSWORD_RESET
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
if (!userToken) {
|
|
216
|
-
throw new BadRequestException({
|
|
217
|
-
message: 'Invalid or expired reset token',
|
|
218
|
-
messageKey: EMAIL_VERIFICATION_MESSAGES.VERIFICATION_TOKEN_INVALID
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
this.validateTokenNotExpiredOrUsed(userToken, 'Reset token has expired. Please request a new one.', AUTH_MESSAGES.PASSWORD_RESET_TOKEN_EXPIRED, 'This reset token has already been used.', AUTH_MESSAGES.PASSWORD_RESET_TOKEN_USED);
|
|
222
|
-
const user = await userRepository.findOne({
|
|
223
|
-
where: {
|
|
224
|
-
id: userToken.userId
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
if (!user) {
|
|
228
|
-
throw new BadRequestException({
|
|
229
|
-
message: 'User not found',
|
|
230
|
-
messageKey: USER_MESSAGES.NOT_FOUND
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
// Update password
|
|
234
|
-
user.password = await bcrypt.hash(newPassword, BCRYPT_SALT_ROUNDS);
|
|
235
|
-
await userRepository.save(user);
|
|
236
|
-
// Mark token as used
|
|
237
|
-
userToken.usedAt = new Date();
|
|
238
|
-
await tokenRepository.save(userToken);
|
|
239
|
-
await this.publishUserEvent(AUTH_EVENT_ACTIONS.PASSWORD_RESET, user.id, {
|
|
240
|
-
email: user.email
|
|
241
|
-
});
|
|
242
|
-
return {
|
|
243
|
-
success: true,
|
|
244
|
-
message: 'Password has been reset successfully.',
|
|
245
|
-
messageKey: AUTH_MESSAGES.PASSWORD_RESET_SUCCESS
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
async verifyEmail(token) {
|
|
249
|
-
const pendingRepository = await this.getRepository(PendingRegistration);
|
|
250
|
-
const userRepository = await this.getRepository(AppUser);
|
|
251
|
-
const tokenRepository = await this.getRepository(UserToken);
|
|
252
|
-
// Hash the incoming token to compare with stored hash
|
|
253
|
-
const tokenHash = this.hashToken(token);
|
|
254
|
-
// Check for pending registration first
|
|
255
|
-
const pending = await pendingRepository.findOne({
|
|
256
|
-
where: {
|
|
257
|
-
token: tokenHash
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
if (pending) {
|
|
261
|
-
if (pending.expiresAt < new Date()) {
|
|
262
|
-
await pendingRepository.delete({
|
|
263
|
-
id: pending.id
|
|
264
|
-
});
|
|
265
|
-
throw new BadRequestException({
|
|
266
|
-
message: 'Verification token has expired. Please register again.',
|
|
267
|
-
messageKey: EMAIL_VERIFICATION_MESSAGES.VERIFICATION_TOKEN_EXPIRED
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
// Delete pending registration (will be consumed by caller to create user)
|
|
271
|
-
await pendingRepository.delete({
|
|
272
|
-
id: pending.id
|
|
273
|
-
});
|
|
274
|
-
return {
|
|
275
|
-
type: 'pending',
|
|
276
|
-
pending
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
// Check for existing user email verification token
|
|
280
|
-
const userToken = await tokenRepository.findOne({
|
|
281
|
-
where: {
|
|
282
|
-
token: tokenHash,
|
|
283
|
-
type: TokenType.EMAIL_VERIFICATION
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
if (!userToken) {
|
|
287
|
-
throw new BadRequestException({
|
|
288
|
-
message: 'Invalid or expired verification token',
|
|
289
|
-
messageKey: EMAIL_VERIFICATION_MESSAGES.VERIFICATION_TOKEN_INVALID
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
if (userToken.expiresAt < new Date()) {
|
|
293
|
-
await tokenRepository.delete({
|
|
294
|
-
id: userToken.id
|
|
295
|
-
});
|
|
296
|
-
throw new BadRequestException({
|
|
297
|
-
message: 'Verification token has expired. Please request a new one.',
|
|
298
|
-
messageKey: EMAIL_VERIFICATION_MESSAGES.VERIFICATION_TOKEN_EXPIRED
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
if (userToken.usedAt) {
|
|
302
|
-
return {
|
|
303
|
-
type: 'verified',
|
|
304
|
-
message: 'Email has already been verified.',
|
|
305
|
-
messageKey: EMAIL_VERIFICATION_MESSAGES.VERIFICATION_SUCCESS
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
const user = await userRepository.findOne({
|
|
309
|
-
where: {
|
|
310
|
-
id: userToken.userId
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
if (!user) {
|
|
314
|
-
throw new BadRequestException({
|
|
315
|
-
message: 'User not found',
|
|
316
|
-
messageKey: USER_MESSAGES.NOT_FOUND
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
// Mark email as verified
|
|
320
|
-
user.emailVerified = true;
|
|
321
|
-
await userRepository.save(user);
|
|
322
|
-
// Mark token as used
|
|
323
|
-
userToken.usedAt = new Date();
|
|
324
|
-
await tokenRepository.save(userToken);
|
|
325
|
-
await this.publishUserEvent(AUTH_EVENT_ACTIONS.EMAIL_VERIFIED, user.id, {
|
|
326
|
-
email: user.email
|
|
327
|
-
});
|
|
328
|
-
return {
|
|
329
|
-
type: 'verified',
|
|
330
|
-
message: 'Email has been verified successfully.',
|
|
331
|
-
messageKey: EMAIL_VERIFICATION_MESSAGES.VERIFICATION_SUCCESS
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
async publishUserEvent(action, userId, metadata) {
|
|
335
|
-
await publishDomainEvent({
|
|
336
|
-
module: AUTH_EVENT_MODULE,
|
|
337
|
-
entity: AUTH_EVENT_ENTITIES.USER,
|
|
338
|
-
action,
|
|
339
|
-
ids: [
|
|
340
|
-
userId
|
|
341
|
-
],
|
|
342
|
-
metadata
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
async resendVerificationEmail(email, verifyUrlBase) {
|
|
346
|
-
this.assertEmailEnabled();
|
|
347
|
-
const pendingRepository = await this.getRepository(PendingRegistration);
|
|
348
|
-
const userRepository = await this.getRepository(AppUser);
|
|
349
|
-
const tokenRepository = await this.getRepository(UserToken);
|
|
350
|
-
// Check pending registration first
|
|
351
|
-
const pending = await pendingRepository.findOne({
|
|
352
|
-
where: {
|
|
353
|
-
email
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
if (pending) {
|
|
357
|
-
const token = this.generateToken();
|
|
358
|
-
pending.token = this.hashToken(token);
|
|
359
|
-
pending.expiresAt = new Date(Date.now() + this.EMAIL_VERIFICATION_EXPIRY);
|
|
360
|
-
await pendingRepository.save(pending);
|
|
361
|
-
const verifyUrl = `${verifyUrlBase}?token=${token}`;
|
|
362
|
-
await this.sendVerificationEmailSafe(email, token, verifyUrl);
|
|
363
|
-
return {
|
|
364
|
-
success: true,
|
|
365
|
-
message: 'If the email requires verification, a link has been sent.',
|
|
366
|
-
messageKey: EMAIL_VERIFICATION_MESSAGES.RESEND_SUCCESS
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
// Check existing user
|
|
370
|
-
const user = await userRepository.findOne({
|
|
371
|
-
where: {
|
|
372
|
-
email
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
if (!user || user.emailVerified) {
|
|
376
|
-
return {
|
|
377
|
-
success: true,
|
|
378
|
-
message: 'If the email requires verification, a link has been sent.',
|
|
379
|
-
messageKey: EMAIL_VERIFICATION_MESSAGES.RESEND_SUCCESS
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
// Invalidate existing tokens and create new one
|
|
383
|
-
await tokenRepository.delete({
|
|
384
|
-
userId: user.id,
|
|
385
|
-
type: TokenType.EMAIL_VERIFICATION
|
|
386
|
-
});
|
|
387
|
-
const token = this.generateToken();
|
|
388
|
-
const userToken = tokenRepository.create({
|
|
389
|
-
userId: user.id,
|
|
390
|
-
type: TokenType.EMAIL_VERIFICATION,
|
|
391
|
-
token: this.hashToken(token),
|
|
392
|
-
expiresAt: new Date(Date.now() + this.EMAIL_VERIFICATION_EXPIRY)
|
|
393
|
-
});
|
|
394
|
-
await tokenRepository.save(userToken);
|
|
395
|
-
const verifyUrl = `${verifyUrlBase}?token=${token}`;
|
|
396
|
-
await this.sendVerificationEmailSafe(user.email, token, verifyUrl);
|
|
397
|
-
return {
|
|
398
|
-
success: true,
|
|
399
|
-
message: 'If the email requires verification, a link has been sent.',
|
|
400
|
-
messageKey: EMAIL_VERIFICATION_MESSAGES.RESEND_SUCCESS
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
constructor(dataSourceProvider, emailProvider){
|
|
404
|
-
_define_property(this, "dataSourceProvider", void 0);
|
|
405
|
-
_define_property(this, "emailProvider", void 0);
|
|
406
|
-
_define_property(this, "PASSWORD_RESET_EXPIRY", void 0); // 1 hour
|
|
407
|
-
_define_property(this, "EMAIL_VERIFICATION_EXPIRY", void 0); // 24 hours
|
|
408
|
-
this.dataSourceProvider = dataSourceProvider;
|
|
409
|
-
this.emailProvider = emailProvider;
|
|
410
|
-
this.PASSWORD_RESET_EXPIRY = 60 * 60 * 1000;
|
|
411
|
-
this.EMAIL_VERIFICATION_EXPIRY = 24 * 60 * 60 * 1000;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
_ts_decorate([
|
|
415
|
-
LogAction({
|
|
416
|
-
action: 'auth.createPendingRegistration',
|
|
417
|
-
module: 'auth',
|
|
418
|
-
includeParams: false
|
|
419
|
-
}),
|
|
420
|
-
_ts_metadata("design:type", Function),
|
|
421
|
-
_ts_metadata("design:paramtypes", [
|
|
422
|
-
Object
|
|
423
|
-
]),
|
|
424
|
-
_ts_metadata("design:returntype", Promise)
|
|
425
|
-
], AuthEmailService.prototype, "createPendingRegistration", null);
|
|
426
|
-
_ts_decorate([
|
|
427
|
-
LogAction({
|
|
428
|
-
action: 'auth.forgotPassword',
|
|
429
|
-
module: 'auth',
|
|
430
|
-
includeParams: false
|
|
431
|
-
}),
|
|
432
|
-
_ts_metadata("design:type", Function),
|
|
433
|
-
_ts_metadata("design:paramtypes", [
|
|
434
|
-
String,
|
|
435
|
-
String
|
|
436
|
-
]),
|
|
437
|
-
_ts_metadata("design:returntype", Promise)
|
|
438
|
-
], AuthEmailService.prototype, "forgotPassword", null);
|
|
439
|
-
_ts_decorate([
|
|
440
|
-
LogAction({
|
|
441
|
-
action: 'auth.resetPassword',
|
|
442
|
-
module: 'auth',
|
|
443
|
-
includeParams: false
|
|
444
|
-
}),
|
|
445
|
-
_ts_metadata("design:type", Function),
|
|
446
|
-
_ts_metadata("design:paramtypes", [
|
|
447
|
-
String,
|
|
448
|
-
String
|
|
449
|
-
]),
|
|
450
|
-
_ts_metadata("design:returntype", Promise)
|
|
451
|
-
], AuthEmailService.prototype, "resetPassword", null);
|
|
452
|
-
_ts_decorate([
|
|
453
|
-
LogAction({
|
|
454
|
-
action: 'auth.verifyEmailToken',
|
|
455
|
-
module: 'auth'
|
|
456
|
-
}),
|
|
457
|
-
_ts_metadata("design:type", Function),
|
|
458
|
-
_ts_metadata("design:paramtypes", [
|
|
459
|
-
String
|
|
460
|
-
]),
|
|
461
|
-
_ts_metadata("design:returntype", Promise)
|
|
462
|
-
], AuthEmailService.prototype, "verifyEmail", null);
|
|
463
|
-
_ts_decorate([
|
|
464
|
-
LogAction({
|
|
465
|
-
action: 'auth.sendVerificationEmail',
|
|
466
|
-
module: 'auth'
|
|
467
|
-
}),
|
|
468
|
-
_ts_metadata("design:type", Function),
|
|
469
|
-
_ts_metadata("design:paramtypes", [
|
|
470
|
-
String,
|
|
471
|
-
String
|
|
472
|
-
]),
|
|
473
|
-
_ts_metadata("design:returntype", Promise)
|
|
474
|
-
], AuthEmailService.prototype, "resendVerificationEmail", null);
|
|
475
|
-
AuthEmailService = _ts_decorate([
|
|
476
|
-
Injectable({
|
|
477
|
-
scope: Scope.REQUEST
|
|
478
|
-
}),
|
|
479
|
-
_ts_param(0, Optional()),
|
|
480
|
-
_ts_param(0, Inject(AuthDataSourceProvider)),
|
|
481
|
-
_ts_param(1, Optional()),
|
|
482
|
-
_ts_param(1, Inject(AUTH_EMAIL_PROVIDER)),
|
|
483
|
-
_ts_metadata("design:type", Function),
|
|
484
|
-
_ts_metadata("design:paramtypes", [
|
|
485
|
-
typeof AuthDataSourceProvider === "undefined" ? Object : AuthDataSourceProvider,
|
|
486
|
-
typeof IAuthEmailProvider === "undefined" ? Object : IAuthEmailProvider
|
|
487
|
-
])
|
|
488
|
-
], AuthEmailService);
|