@flusys/nestjs-auth 7.0.2 → 8.0.0-beta.1
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 +68 -1
- package/config/auth.constants.d.ts +2 -0
- package/config/event-actions.d.ts +2 -0
- package/config/index.d.ts +3 -3
- package/config/message-keys.d.ts +23 -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 -7
- package/controllers/social-auth-config.controller.d.ts +22 -0
- package/controllers/social-auth.controller.d.ts +11 -0
- package/controllers/user-permission.controller.d.ts +5 -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 -5
- package/dtos/social-auth.dto.d.ts +42 -0
- package/entities/company-branch.entity.d.ts +1 -1
- package/entities/company.entity.d.ts +1 -1
- package/entities/index.d.ts +15 -13
- package/entities/pending-registration.entity.d.ts +1 -1
- package/entities/social-auth-config.entity.d.ts +9 -0
- package/entities/user-company-permission.entity.d.ts +4 -4
- package/enums/index.d.ts +2 -1
- package/enums/social-provider-type.enum.d.ts +6 -0
- package/fesm/118.js +1230 -0
- package/fesm/120.js +2197 -0
- package/fesm/24.js +4389 -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 +244 -3
- package/fesm/controllers/index.js +27 -7
- package/fesm/docs/index.js +479 -1
- package/fesm/dtos/index.js +123 -5
- package/fesm/entities/index.js +68 -19
- package/fesm/enums/index.js +53 -1
- package/fesm/helpers/index.js +115 -2
- package/fesm/index.js +1437 -12
- package/fesm/interceptors/index.js +508 -2
- package/fesm/interfaces/index.js +75 -7
- package/fesm/modules/index.js +546 -1
- package/fesm/runtime.js +134 -0
- package/fesm/services/index.js +67 -9
- 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 -12
- 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 -7
- package/interfaces/social-auth.interface.d.ts +43 -0
- 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 +10 -0
- package/providers/google.social-provider.d.ts +10 -0
- package/providers/index.d.ts +1 -0
- package/providers/linkedin.social-provider.d.ts +10 -0
- package/providers/microsoft.social-provider.d.ts +10 -0
- package/providers/oauth-http.util.d.ts +10 -0
- package/providers/social-provider.registry.d.ts +3 -0
- package/services/auth-config.service.d.ts +4 -3
- package/services/auth-datasource.provider.d.ts +4 -3
- package/services/auth-email.service.d.ts +3 -3
- package/services/authentication.service.d.ts +15 -11
- package/services/branch.service.d.ts +7 -7
- package/services/company.service.d.ts +6 -6
- package/services/index.d.ts +11 -9
- package/services/social-auth-config.service.d.ts +21 -0
- package/services/social-auth.service.d.ts +24 -0
- package/services/user-permission.service.d.ts +8 -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 -41
- package/cjs/config/event-actions.js +0 -45
- package/cjs/config/index.js +0 -20
- package/cjs/config/message-keys.js +0 -108
- 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 -24
- 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 -453
- 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 -22
- 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 -65
- package/cjs/entities/index.spec.js +0 -73
- package/cjs/entities/pending-registration.entity.js +0 -135
- 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 -18
- 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 -29
- 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 -24
- package/cjs/interfaces/user-enricher.interface.js +0 -4
- package/cjs/interfaces/user.interface.js +0 -4
- package/cjs/modules/auth.module.js +0 -202
- package/cjs/modules/auth.module.spec.js +0 -243
- package/cjs/modules/index.js +0 -18
- package/cjs/services/auth-config.service.js +0 -110
- package/cjs/services/auth-config.service.spec.js +0 -97
- package/cjs/services/auth-datasource.provider.js +0 -134
- package/cjs/services/auth-datasource.provider.spec.js +0 -161
- 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 -1173
- package/cjs/services/authentication.service.spec.js +0 -962
- 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 -26
- 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 -11
- package/fesm/config/event-actions.js +0 -24
- package/fesm/config/message-keys.js +0 -78
- 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/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 -446
- 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/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 -69
- package/fesm/entities/pending-registration.entity.js +0 -125
- package/fesm/entities/user-company-permission.entity.js +0 -136
- package/fesm/entities/user-token.entity.js +0 -104
- 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/user-enricher.interface.js +0 -4
- package/fesm/interfaces/user.interface.js +0 -1
- package/fesm/modules/auth.module.js +0 -192
- package/fesm/modules/auth.module.spec.js +0 -239
- package/fesm/services/auth-config.service.js +0 -100
- package/fesm/services/auth-config.service.spec.js +0 -93
- package/fesm/services/auth-datasource.provider.js +0 -83
- package/fesm/services/auth-datasource.provider.spec.js +0 -157
- 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 -1122
- package/fesm/services/authentication.service.spec.js +0 -917
- 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/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,200 +0,0 @@
|
|
|
1
|
-
import { buildMockUser } from '@test-utils/mocks/logged-user.mock';
|
|
2
|
-
import { UserController } from './user.controller';
|
|
3
|
-
function buildUser(overrides = {}) {
|
|
4
|
-
return {
|
|
5
|
-
id: 'user-1',
|
|
6
|
-
name: 'Test User',
|
|
7
|
-
email: 'test@example.com',
|
|
8
|
-
phone: null,
|
|
9
|
-
isActive: true,
|
|
10
|
-
readOnly: false,
|
|
11
|
-
createdAt: new Date(),
|
|
12
|
-
updatedAt: new Date(),
|
|
13
|
-
...overrides
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
describe('UserController', ()=>{
|
|
17
|
-
let controller;
|
|
18
|
-
let mockUserService;
|
|
19
|
-
beforeEach(()=>{
|
|
20
|
-
mockUserService = {
|
|
21
|
-
insert: jest.fn(),
|
|
22
|
-
insertMany: jest.fn(),
|
|
23
|
-
findById: jest.fn(),
|
|
24
|
-
findByIds: jest.fn(),
|
|
25
|
-
update: jest.fn(),
|
|
26
|
-
updateMany: jest.fn(),
|
|
27
|
-
bulkUpsert: jest.fn(),
|
|
28
|
-
getAll: jest.fn(),
|
|
29
|
-
delete: jest.fn(),
|
|
30
|
-
getProfileWithExtras: jest.fn(),
|
|
31
|
-
verifyEmail: jest.fn(),
|
|
32
|
-
verifyPhone: jest.fn(),
|
|
33
|
-
updateStatus: jest.fn(),
|
|
34
|
-
profile: jest.fn(),
|
|
35
|
-
getProfileSections: jest.fn(),
|
|
36
|
-
getProfileSectionData: jest.fn(),
|
|
37
|
-
updateProfileSection: jest.fn(),
|
|
38
|
-
getProfileCompletion: jest.fn()
|
|
39
|
-
};
|
|
40
|
-
controller = new UserController(mockUserService);
|
|
41
|
-
});
|
|
42
|
-
describe('insert', ()=>{
|
|
43
|
-
it('creates a user and returns the mapped response', async ()=>{
|
|
44
|
-
const user = buildMockUser();
|
|
45
|
-
mockUserService.insert.mockResolvedValue(buildUser());
|
|
46
|
-
const result = await controller.insert({
|
|
47
|
-
name: 'Test User',
|
|
48
|
-
email: 'test@example.com',
|
|
49
|
-
password: 'Password1!'
|
|
50
|
-
}, user);
|
|
51
|
-
expect(mockUserService.insert).toHaveBeenCalledWith({
|
|
52
|
-
name: 'Test User',
|
|
53
|
-
email: 'test@example.com',
|
|
54
|
-
password: 'Password1!'
|
|
55
|
-
}, user);
|
|
56
|
-
expect(result.success).toBe(true);
|
|
57
|
-
expect(result.data).toEqual(expect.objectContaining({
|
|
58
|
-
id: 'user-1'
|
|
59
|
-
}));
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
describe('getAll', ()=>{
|
|
63
|
-
it('paginates users and maps the response list', async ()=>{
|
|
64
|
-
mockUserService.getAll.mockResolvedValue({
|
|
65
|
-
data: [
|
|
66
|
-
buildUser()
|
|
67
|
-
],
|
|
68
|
-
total: 1
|
|
69
|
-
});
|
|
70
|
-
const result = await controller.getAll({}, buildMockUser(), '');
|
|
71
|
-
expect(mockUserService.getAll).toHaveBeenCalledWith('', {}, buildMockUser());
|
|
72
|
-
expect(result.data).toHaveLength(1);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
describe('getProfileWithExtras', ()=>{
|
|
76
|
-
it('returns the enriched profile payload', async ()=>{
|
|
77
|
-
const user = buildMockUser();
|
|
78
|
-
mockUserService.getProfileWithExtras.mockResolvedValue({
|
|
79
|
-
...buildUser(),
|
|
80
|
-
completionPercentage: 80
|
|
81
|
-
});
|
|
82
|
-
const result = await controller.getProfileWithExtras('user-1', user);
|
|
83
|
-
expect(mockUserService.getProfileWithExtras).toHaveBeenCalledWith('user-1', user);
|
|
84
|
-
expect(result).toEqual({
|
|
85
|
-
success: true,
|
|
86
|
-
message: 'Profile extras retrieved successfully',
|
|
87
|
-
messageKey: expect.any(String),
|
|
88
|
-
data: expect.objectContaining({
|
|
89
|
-
completionPercentage: 80
|
|
90
|
-
})
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
describe('verifyEmail', ()=>{
|
|
95
|
-
it('verifies the email and returns a success message', async ()=>{
|
|
96
|
-
mockUserService.verifyEmail.mockResolvedValue(undefined);
|
|
97
|
-
const result = await controller.verifyEmail('user-1');
|
|
98
|
-
expect(mockUserService.verifyEmail).toHaveBeenCalledWith('user-1');
|
|
99
|
-
expect(result.success).toBe(true);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
describe('verifyPhone', ()=>{
|
|
103
|
-
it('verifies the phone and returns a success message', async ()=>{
|
|
104
|
-
mockUserService.verifyPhone.mockResolvedValue(undefined);
|
|
105
|
-
const result = await controller.verifyPhone('user-1');
|
|
106
|
-
expect(mockUserService.verifyPhone).toHaveBeenCalledWith('user-1');
|
|
107
|
-
expect(result.success).toBe(true);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
describe('updateStatus', ()=>{
|
|
111
|
-
it('updates the active status for the given user', async ()=>{
|
|
112
|
-
const user = buildMockUser();
|
|
113
|
-
mockUserService.updateStatus.mockResolvedValue(undefined);
|
|
114
|
-
const result = await controller.updateStatus('user-1', false, user);
|
|
115
|
-
expect(mockUserService.updateStatus).toHaveBeenCalledWith('user-1', false, user);
|
|
116
|
-
expect(result.success).toBe(true);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
describe('profile', ()=>{
|
|
120
|
-
it('updates the current user profile and returns the data', async ()=>{
|
|
121
|
-
const user = buildMockUser();
|
|
122
|
-
mockUserService.profile.mockResolvedValue('user-1');
|
|
123
|
-
const result = await controller.profile({
|
|
124
|
-
id: 'user-1',
|
|
125
|
-
name: 'New Name'
|
|
126
|
-
}, user);
|
|
127
|
-
expect(mockUserService.profile).toHaveBeenCalledWith({
|
|
128
|
-
id: 'user-1',
|
|
129
|
-
name: 'New Name'
|
|
130
|
-
}, user);
|
|
131
|
-
expect(result).toEqual({
|
|
132
|
-
success: true,
|
|
133
|
-
message: 'Profile updated successfully',
|
|
134
|
-
messageKey: expect.any(String),
|
|
135
|
-
data: 'user-1'
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
describe('getProfileSections', ()=>{
|
|
140
|
-
it('returns the profile section definitions', async ()=>{
|
|
141
|
-
mockUserService.getProfileSections.mockResolvedValue([
|
|
142
|
-
{
|
|
143
|
-
id: 's1',
|
|
144
|
-
name: 'Basic',
|
|
145
|
-
order: 1
|
|
146
|
-
}
|
|
147
|
-
]);
|
|
148
|
-
const result = await controller.getProfileSections();
|
|
149
|
-
expect(result.data).toEqual([
|
|
150
|
-
{
|
|
151
|
-
id: 's1',
|
|
152
|
-
name: 'Basic',
|
|
153
|
-
order: 1
|
|
154
|
-
}
|
|
155
|
-
]);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe('getProfileSectionData', ()=>{
|
|
159
|
-
it('returns data for the requested section', async ()=>{
|
|
160
|
-
const user = buildMockUser();
|
|
161
|
-
mockUserService.getProfileSectionData.mockResolvedValue({
|
|
162
|
-
sectionId: 's1',
|
|
163
|
-
data: {
|
|
164
|
-
foo: 'bar'
|
|
165
|
-
},
|
|
166
|
-
isComplete: true
|
|
167
|
-
});
|
|
168
|
-
const result = await controller.getProfileSectionData('user-1', 's1', user);
|
|
169
|
-
expect(mockUserService.getProfileSectionData).toHaveBeenCalledWith('user-1', 's1', user);
|
|
170
|
-
expect(result.data).toEqual(expect.objectContaining({
|
|
171
|
-
sectionId: 's1',
|
|
172
|
-
isComplete: true
|
|
173
|
-
}));
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
describe('updateProfileSection', ()=>{
|
|
177
|
-
it('updates the requested section', async ()=>{
|
|
178
|
-
const user = buildMockUser();
|
|
179
|
-
mockUserService.updateProfileSection.mockResolvedValue(undefined);
|
|
180
|
-
const result = await controller.updateProfileSection('user-1', 's1', {
|
|
181
|
-
foo: 'bar'
|
|
182
|
-
}, user);
|
|
183
|
-
expect(mockUserService.updateProfileSection).toHaveBeenCalledWith('user-1', 's1', {
|
|
184
|
-
foo: 'bar'
|
|
185
|
-
}, user);
|
|
186
|
-
expect(result.success).toBe(true);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
describe('getProfileCompletion', ()=>{
|
|
190
|
-
it('returns the completion percentage', async ()=>{
|
|
191
|
-
const user = buildMockUser();
|
|
192
|
-
mockUserService.getProfileCompletion.mockResolvedValue(42);
|
|
193
|
-
const result = await controller.getProfileCompletion('user-1', user);
|
|
194
|
-
expect(mockUserService.getProfileCompletion).toHaveBeenCalledWith('user-1', user);
|
|
195
|
-
expect(result.data).toEqual({
|
|
196
|
-
completionPercentage: 42
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
});
|
|
@@ -1,446 +0,0 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// Company feature exclusions
|
|
3
|
-
// ============================================================================
|
|
4
|
-
const COMPANY_RELATED_TAGS = [
|
|
5
|
-
'Companies',
|
|
6
|
-
'Branches',
|
|
7
|
-
'User Permissions',
|
|
8
|
-
'Company Selection'
|
|
9
|
-
];
|
|
10
|
-
const COMPANY_SCHEMA_EXCLUSIONS = [
|
|
11
|
-
// Request DTOs
|
|
12
|
-
{
|
|
13
|
-
schemaName: 'RegistrationDto',
|
|
14
|
-
properties: [
|
|
15
|
-
'companySlug',
|
|
16
|
-
'branchSlug',
|
|
17
|
-
'newCompanyName',
|
|
18
|
-
'newCompanyPhone',
|
|
19
|
-
'newCompanyAddress'
|
|
20
|
-
]
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
schemaName: 'SelectDto',
|
|
24
|
-
properties: [
|
|
25
|
-
'sessionId',
|
|
26
|
-
'companyId',
|
|
27
|
-
'branchId'
|
|
28
|
-
]
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
schemaName: 'SwitchCompanyDto',
|
|
32
|
-
properties: [
|
|
33
|
-
'companyId',
|
|
34
|
-
'branchId'
|
|
35
|
-
]
|
|
36
|
-
},
|
|
37
|
-
// Response DTOs
|
|
38
|
-
{
|
|
39
|
-
schemaName: 'RegistrationResponseDto',
|
|
40
|
-
properties: [
|
|
41
|
-
'company',
|
|
42
|
-
'branch'
|
|
43
|
-
]
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
schemaName: 'LoginResponseDto',
|
|
47
|
-
properties: [
|
|
48
|
-
'company',
|
|
49
|
-
'branch'
|
|
50
|
-
]
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
schemaName: 'MeResponseDto',
|
|
54
|
-
properties: [
|
|
55
|
-
'company',
|
|
56
|
-
'branch'
|
|
57
|
-
]
|
|
58
|
-
},
|
|
59
|
-
// Nested helper DTOs
|
|
60
|
-
{
|
|
61
|
-
schemaName: 'CompanyInfoDto',
|
|
62
|
-
properties: [
|
|
63
|
-
'id',
|
|
64
|
-
'name',
|
|
65
|
-
'slug',
|
|
66
|
-
'logoId'
|
|
67
|
-
]
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
schemaName: 'BranchInfoDto',
|
|
71
|
-
properties: [
|
|
72
|
-
'id',
|
|
73
|
-
'name',
|
|
74
|
-
'slug',
|
|
75
|
-
'logoId'
|
|
76
|
-
]
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
schemaName: 'BranchSelectionInfoDto',
|
|
80
|
-
properties: [
|
|
81
|
-
'id',
|
|
82
|
-
'name',
|
|
83
|
-
'slug',
|
|
84
|
-
'logoId'
|
|
85
|
-
]
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
schemaName: 'CompanyWithBranchesDto',
|
|
89
|
-
properties: [
|
|
90
|
-
'id',
|
|
91
|
-
'name',
|
|
92
|
-
'slug',
|
|
93
|
-
'logoId',
|
|
94
|
-
'branches'
|
|
95
|
-
]
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
schemaName: 'CompanySelectionResponseDto',
|
|
99
|
-
properties: [
|
|
100
|
-
'requiresSelection',
|
|
101
|
-
'sessionId',
|
|
102
|
-
'expiresAt',
|
|
103
|
-
'user',
|
|
104
|
-
'companies'
|
|
105
|
-
]
|
|
106
|
-
},
|
|
107
|
-
// Company management DTOs
|
|
108
|
-
{
|
|
109
|
-
schemaName: 'CreateCompanyDto',
|
|
110
|
-
properties: [
|
|
111
|
-
'name',
|
|
112
|
-
'slug',
|
|
113
|
-
'logoId',
|
|
114
|
-
'address',
|
|
115
|
-
'phone',
|
|
116
|
-
'email',
|
|
117
|
-
'website',
|
|
118
|
-
'serial',
|
|
119
|
-
'isActive',
|
|
120
|
-
'settings',
|
|
121
|
-
'additionalFields'
|
|
122
|
-
]
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
schemaName: 'UpdateCompanyDto',
|
|
126
|
-
properties: [
|
|
127
|
-
'id',
|
|
128
|
-
'name',
|
|
129
|
-
'slug',
|
|
130
|
-
'logoId',
|
|
131
|
-
'address',
|
|
132
|
-
'phone',
|
|
133
|
-
'email',
|
|
134
|
-
'website',
|
|
135
|
-
'serial',
|
|
136
|
-
'isActive',
|
|
137
|
-
'settings',
|
|
138
|
-
'additionalFields'
|
|
139
|
-
]
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
schemaName: 'CompanyResponseDto',
|
|
143
|
-
properties: [
|
|
144
|
-
'id',
|
|
145
|
-
'name',
|
|
146
|
-
'slug',
|
|
147
|
-
'logoId',
|
|
148
|
-
'address',
|
|
149
|
-
'phone',
|
|
150
|
-
'email',
|
|
151
|
-
'website',
|
|
152
|
-
'serial',
|
|
153
|
-
'isActive',
|
|
154
|
-
'settings',
|
|
155
|
-
'additionalFields',
|
|
156
|
-
'readOnly',
|
|
157
|
-
'createdAt',
|
|
158
|
-
'updatedAt'
|
|
159
|
-
]
|
|
160
|
-
},
|
|
161
|
-
// Branch management DTOs
|
|
162
|
-
{
|
|
163
|
-
schemaName: 'CreateCompanyBranchDto',
|
|
164
|
-
properties: [
|
|
165
|
-
'name',
|
|
166
|
-
'slug',
|
|
167
|
-
'companyId',
|
|
168
|
-
'parentId',
|
|
169
|
-
'logoId',
|
|
170
|
-
'address',
|
|
171
|
-
'phone',
|
|
172
|
-
'email',
|
|
173
|
-
'serial',
|
|
174
|
-
'isActive',
|
|
175
|
-
'additionalFields'
|
|
176
|
-
]
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
schemaName: 'UpdateCompanyBranchDto',
|
|
180
|
-
properties: [
|
|
181
|
-
'id',
|
|
182
|
-
'name',
|
|
183
|
-
'slug',
|
|
184
|
-
'companyId',
|
|
185
|
-
'parentId',
|
|
186
|
-
'logoId',
|
|
187
|
-
'address',
|
|
188
|
-
'phone',
|
|
189
|
-
'email',
|
|
190
|
-
'serial',
|
|
191
|
-
'isActive',
|
|
192
|
-
'additionalFields'
|
|
193
|
-
]
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
schemaName: 'CompanyBranchResponseDto',
|
|
197
|
-
properties: [
|
|
198
|
-
'id',
|
|
199
|
-
'name',
|
|
200
|
-
'slug',
|
|
201
|
-
'companyId',
|
|
202
|
-
'parentId',
|
|
203
|
-
'logoId',
|
|
204
|
-
'address',
|
|
205
|
-
'phone',
|
|
206
|
-
'email',
|
|
207
|
-
'serial',
|
|
208
|
-
'isActive',
|
|
209
|
-
'additionalFields',
|
|
210
|
-
'readOnly',
|
|
211
|
-
'createdAt',
|
|
212
|
-
'updatedAt'
|
|
213
|
-
]
|
|
214
|
-
},
|
|
215
|
-
// User permission DTOs
|
|
216
|
-
{
|
|
217
|
-
schemaName: 'UserCompanyPermissionDto',
|
|
218
|
-
properties: [
|
|
219
|
-
'id',
|
|
220
|
-
'userId',
|
|
221
|
-
'companyId',
|
|
222
|
-
'companyName',
|
|
223
|
-
'companySlug'
|
|
224
|
-
]
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
schemaName: 'UserBranchPermissionDto',
|
|
228
|
-
properties: [
|
|
229
|
-
'id',
|
|
230
|
-
'userId',
|
|
231
|
-
'branchId',
|
|
232
|
-
'branchName',
|
|
233
|
-
'branchSlug',
|
|
234
|
-
'companyId'
|
|
235
|
-
]
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
schemaName: 'AssignUserCompanyDto',
|
|
239
|
-
properties: [
|
|
240
|
-
'userId',
|
|
241
|
-
'items'
|
|
242
|
-
]
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
schemaName: 'AssignUserBranchDto',
|
|
246
|
-
properties: [
|
|
247
|
-
'userId',
|
|
248
|
-
'items'
|
|
249
|
-
]
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
schemaName: 'PermissionItemDto',
|
|
253
|
-
properties: [
|
|
254
|
-
'targetId',
|
|
255
|
-
'isAdd'
|
|
256
|
-
]
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
schemaName: 'UserCompaniesResponseDto',
|
|
260
|
-
properties: [
|
|
261
|
-
'data'
|
|
262
|
-
]
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
schemaName: 'UserBranchesResponseDto',
|
|
266
|
-
properties: [
|
|
267
|
-
'data'
|
|
268
|
-
]
|
|
269
|
-
}
|
|
270
|
-
];
|
|
271
|
-
const COMPANY_EXAMPLE_EXCLUSIONS = [
|
|
272
|
-
{
|
|
273
|
-
pathPattern: '/auth/login',
|
|
274
|
-
method: 'post',
|
|
275
|
-
examples: [
|
|
276
|
-
'loginSuccessWithCompany',
|
|
277
|
-
'companySelection'
|
|
278
|
-
]
|
|
279
|
-
}
|
|
280
|
-
];
|
|
281
|
-
// ============================================================================
|
|
282
|
-
// Email verification exclusions
|
|
283
|
-
// ============================================================================
|
|
284
|
-
const EMAIL_VERIFICATION_PATHS = [
|
|
285
|
-
'/auth/forgot-password',
|
|
286
|
-
'/auth/reset-password',
|
|
287
|
-
'/auth/resend-verification',
|
|
288
|
-
'/auth/verify-email'
|
|
289
|
-
];
|
|
290
|
-
const EMAIL_VERIFICATION_SCHEMA_EXCLUSIONS = [
|
|
291
|
-
{
|
|
292
|
-
schemaName: 'RegistrationResponseDto',
|
|
293
|
-
properties: [
|
|
294
|
-
'requiresEmailVerification'
|
|
295
|
-
]
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
schemaName: 'LoginResponseRequiresEmailVerificationDto',
|
|
299
|
-
properties: [
|
|
300
|
-
'requiresEmailVerification',
|
|
301
|
-
'email'
|
|
302
|
-
]
|
|
303
|
-
}
|
|
304
|
-
];
|
|
305
|
-
const EMAIL_VERIFICATION_EXAMPLE_EXCLUSIONS = [
|
|
306
|
-
{
|
|
307
|
-
pathPattern: '/auth/login',
|
|
308
|
-
method: 'post',
|
|
309
|
-
examples: [
|
|
310
|
-
'emailVerification'
|
|
311
|
-
]
|
|
312
|
-
}
|
|
313
|
-
];
|
|
314
|
-
// ============================================================================
|
|
315
|
-
// Description builder
|
|
316
|
-
// ============================================================================
|
|
317
|
-
function buildDescription(enableCompanyFeature, enableEmailVerification, isMultiTenant) {
|
|
318
|
-
const multiTenantNote = isMultiTenant ? `\n> **Multi-Tenant Mode**: Include \`x-tenant-id\` header to target a specific tenant database.\n` : '';
|
|
319
|
-
const features = [
|
|
320
|
-
'- User registration',
|
|
321
|
-
'- Login with email/password',
|
|
322
|
-
'- JWT token-based authentication',
|
|
323
|
-
...enableEmailVerification ? [
|
|
324
|
-
'- Email verification',
|
|
325
|
-
'- Forgot/reset password'
|
|
326
|
-
] : [],
|
|
327
|
-
...enableCompanyFeature ? [
|
|
328
|
-
'- Company/Branch selection flow (multi-company enabled)'
|
|
329
|
-
] : [],
|
|
330
|
-
'- Token refresh',
|
|
331
|
-
'- Password change'
|
|
332
|
-
].join('\n');
|
|
333
|
-
const loginFlowSection = enableCompanyFeature ? `
|
|
334
|
-
### Authentication Flow
|
|
335
|
-
|
|
336
|
-
#### Simple Login (single company/branch)
|
|
337
|
-
\`\`\`
|
|
338
|
-
POST /auth/login → { accessToken, refreshToken, user, company, branch }
|
|
339
|
-
\`\`\`
|
|
340
|
-
|
|
341
|
-
#### Multi-Company Login (multiple companies or branches)
|
|
342
|
-
\`\`\`
|
|
343
|
-
POST /auth/login → { requiresSelection: true, sessionId, companies }
|
|
344
|
-
POST /auth/select → { accessToken, refreshToken, user, company, branch }
|
|
345
|
-
\`\`\`
|
|
346
|
-
${enableEmailVerification ? `
|
|
347
|
-
#### Email Verification Required
|
|
348
|
-
\`\`\`
|
|
349
|
-
POST /auth/login → { requiresEmailVerification: true, email }
|
|
350
|
-
POST /auth/verify-email → { accessToken, refreshToken, user }
|
|
351
|
-
\`\`\`
|
|
352
|
-
` : ''}
|
|
353
|
-
### Company/Branch Selection Endpoints
|
|
354
|
-
- \`POST /auth/select\` - Complete login by selecting company and branch
|
|
355
|
-
- \`POST /auth/switch-company\` - Switch to different company/branch while logged in
|
|
356
|
-
` : `
|
|
357
|
-
### Authentication Flow
|
|
358
|
-
\`\`\`
|
|
359
|
-
POST /auth/login → { accessToken, refreshToken, user }
|
|
360
|
-
\`\`\`
|
|
361
|
-
${enableEmailVerification ? `
|
|
362
|
-
#### Email Verification Required
|
|
363
|
-
\`\`\`
|
|
364
|
-
POST /auth/login → { requiresEmailVerification: true, email }
|
|
365
|
-
POST /auth/verify-email → { accessToken, refreshToken, user }
|
|
366
|
-
\`\`\`
|
|
367
|
-
` : ''}`;
|
|
368
|
-
const emailVerificationSection = enableEmailVerification ? `
|
|
369
|
-
### Email Verification Endpoints
|
|
370
|
-
- \`POST /auth/forgot-password\` - Request password reset email
|
|
371
|
-
- \`POST /auth/reset-password\` - Reset password using token
|
|
372
|
-
- \`POST /auth/resend-verification\` - Resend verification email
|
|
373
|
-
- \`POST /auth/verify-email\` - Verify email using token
|
|
374
|
-
` : '';
|
|
375
|
-
const administrationSection = enableCompanyFeature ? `
|
|
376
|
-
### Administration Endpoints
|
|
377
|
-
- \`POST /administration/users/*\` - User management
|
|
378
|
-
- \`POST /administration/company/*\` - Company management
|
|
379
|
-
- \`POST /administration/branch/*\` - Branch management
|
|
380
|
-
- \`POST /administration/user-permissions/*\` - User permission management
|
|
381
|
-
` : `
|
|
382
|
-
### Administration Endpoints
|
|
383
|
-
- \`POST /administration/users/*\` - User management
|
|
384
|
-
`;
|
|
385
|
-
const registrationSection = enableCompanyFeature ? `
|
|
386
|
-
### Registration Flow
|
|
387
|
-
|
|
388
|
-
**Simple registration:**
|
|
389
|
-
\`\`\`json
|
|
390
|
-
{ "name": "John Doe", "email": "john@example.com", "password": "password123" }
|
|
391
|
-
\`\`\`
|
|
392
|
-
|
|
393
|
-
**Join existing company:**
|
|
394
|
-
\`\`\`json
|
|
395
|
-
{ "name": "John Doe", "email": "john@example.com", "password": "password123", "companySlug": "acme-corp", "branchSlug": "main-branch" }
|
|
396
|
-
\`\`\`
|
|
397
|
-
|
|
398
|
-
**Create new company:**
|
|
399
|
-
\`\`\`json
|
|
400
|
-
{ "name": "John Doe", "email": "john@example.com", "password": "password123", "newCompanyName": "My New Company" }
|
|
401
|
-
\`\`\`
|
|
402
|
-
` : `
|
|
403
|
-
### Registration Flow
|
|
404
|
-
\`\`\`json
|
|
405
|
-
{ "name": "John Doe", "email": "john@example.com", "password": "password123" }
|
|
406
|
-
\`\`\`
|
|
407
|
-
`;
|
|
408
|
-
return `
|
|
409
|
-
## Authentication API
|
|
410
|
-
${multiTenantNote}
|
|
411
|
-
Handles user authentication${enableCompanyFeature ? ', company/branch management' : ''}, and registration.
|
|
412
|
-
|
|
413
|
-
### Features
|
|
414
|
-
${features}
|
|
415
|
-
${loginFlowSection}${emailVerificationSection}${administrationSection}${registrationSection}`;
|
|
416
|
-
}
|
|
417
|
-
// ============================================================================
|
|
418
|
-
// Config factory
|
|
419
|
-
// ============================================================================
|
|
420
|
-
export function authSwaggerConfig(bootstrapConfig) {
|
|
421
|
-
const enableCompanyFeature = bootstrapConfig?.enableCompanyFeature ?? true;
|
|
422
|
-
const enableEmailVerification = bootstrapConfig?.enableEmailVerification ?? true;
|
|
423
|
-
const isMultiTenant = bootstrapConfig?.databaseMode === 'multi-tenant';
|
|
424
|
-
const excludeTags = enableCompanyFeature ? [] : COMPANY_RELATED_TAGS;
|
|
425
|
-
const excludeSchemaProperties = [
|
|
426
|
-
...enableCompanyFeature ? [] : COMPANY_SCHEMA_EXCLUSIONS,
|
|
427
|
-
...enableEmailVerification ? [] : EMAIL_VERIFICATION_SCHEMA_EXCLUSIONS
|
|
428
|
-
];
|
|
429
|
-
// Merge example exclusions — both may target /auth/login with different example names
|
|
430
|
-
const excludeExamples = [
|
|
431
|
-
...enableCompanyFeature ? [] : COMPANY_EXAMPLE_EXCLUSIONS,
|
|
432
|
-
...enableEmailVerification ? [] : EMAIL_VERIFICATION_EXAMPLE_EXCLUSIONS
|
|
433
|
-
];
|
|
434
|
-
const excludePaths = enableEmailVerification ? undefined : EMAIL_VERIFICATION_PATHS;
|
|
435
|
-
return {
|
|
436
|
-
title: 'Auth API',
|
|
437
|
-
description: buildDescription(enableCompanyFeature, enableEmailVerification, isMultiTenant),
|
|
438
|
-
version: '1.0',
|
|
439
|
-
path: 'api/docs/auth',
|
|
440
|
-
bearerAuth: true,
|
|
441
|
-
excludeTags,
|
|
442
|
-
excludeSchemaProperties: excludeSchemaProperties.length ? excludeSchemaProperties : undefined,
|
|
443
|
-
excludeExamples: excludeExamples.length ? excludeExamples : undefined,
|
|
444
|
-
excludePaths
|
|
445
|
-
};
|
|
446
|
-
}
|