@flusys/nestjs-auth 7.1.0 → 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.
Files changed (270) hide show
  1. package/README.md +1 -1
  2. package/config/index.d.ts +3 -3
  3. package/config/message-keys.d.ts +2 -0
  4. package/controllers/authentication.controller.d.ts +5 -5
  5. package/controllers/branch.controller.d.ts +2 -2
  6. package/controllers/company-selection.controller.d.ts +4 -4
  7. package/controllers/company.controller.d.ts +2 -2
  8. package/controllers/email-verification.controller.d.ts +6 -6
  9. package/controllers/index.d.ts +9 -9
  10. package/controllers/social-auth-config.controller.d.ts +2 -2
  11. package/controllers/social-auth.controller.d.ts +3 -3
  12. package/controllers/user-permission.controller.d.ts +5 -4
  13. package/controllers/user.controller.d.ts +7 -7
  14. package/docs/auth-swagger.config.d.ts +2 -2
  15. package/docs/index.d.ts +1 -1
  16. package/dtos/index.d.ts +6 -6
  17. package/dtos/social-auth.dto.d.ts +1 -1
  18. package/entities/company-branch.entity.d.ts +1 -1
  19. package/entities/company.entity.d.ts +1 -1
  20. package/entities/index.d.ts +14 -14
  21. package/entities/pending-registration.entity.d.ts +1 -1
  22. package/entities/user-company-permission.entity.d.ts +4 -4
  23. package/enums/index.d.ts +2 -2
  24. package/fesm/118.js +1230 -0
  25. package/fesm/120.js +2197 -0
  26. package/fesm/24.js +4389 -0
  27. package/fesm/370.js +1163 -0
  28. package/fesm/446.js +877 -0
  29. package/fesm/chunks/117.js +69 -0
  30. package/fesm/config/index.js +244 -3
  31. package/fesm/controllers/index.js +27 -9
  32. package/fesm/docs/index.js +479 -1
  33. package/fesm/dtos/index.js +123 -6
  34. package/fesm/entities/index.js +68 -22
  35. package/fesm/enums/index.js +53 -2
  36. package/fesm/helpers/index.js +115 -2
  37. package/fesm/index.js +1437 -13
  38. package/fesm/interceptors/index.js +508 -2
  39. package/fesm/interfaces/index.js +75 -8
  40. package/fesm/modules/index.js +546 -1
  41. package/fesm/runtime.js +134 -0
  42. package/fesm/services/index.js +67 -11
  43. package/helpers/auth-response.mapper.d.ts +3 -3
  44. package/helpers/index.d.ts +2 -2
  45. package/helpers/token.helper.d.ts +2 -2
  46. package/index.d.ts +13 -13
  47. package/interceptors/clear-token.interceptor.d.ts +2 -2
  48. package/interceptors/index.d.ts +2 -2
  49. package/interceptors/set-token.interceptor.d.ts +2 -2
  50. package/interfaces/auth-module-options.interface.d.ts +3 -3
  51. package/interfaces/authentication.interface.d.ts +3 -3
  52. package/interfaces/company-branch.interface.d.ts +2 -2
  53. package/interfaces/company.interface.d.ts +1 -1
  54. package/interfaces/index.d.ts +8 -8
  55. package/interfaces/social-auth.interface.d.ts +2 -2
  56. package/interfaces/user-enricher.interface.d.ts +3 -3
  57. package/modules/auth.module.d.ts +4 -4
  58. package/modules/index.d.ts +1 -1
  59. package/package.json +32 -39
  60. package/providers/facebook.social-provider.d.ts +2 -2
  61. package/providers/google.social-provider.d.ts +2 -2
  62. package/providers/index.d.ts +1 -1
  63. package/providers/linkedin.social-provider.d.ts +2 -2
  64. package/providers/microsoft.social-provider.d.ts +2 -2
  65. package/providers/social-provider.registry.d.ts +2 -2
  66. package/services/auth-config.service.d.ts +3 -3
  67. package/services/auth-datasource.provider.d.ts +3 -3
  68. package/services/auth-email.service.d.ts +3 -3
  69. package/services/authentication.service.d.ts +12 -12
  70. package/services/branch.service.d.ts +7 -7
  71. package/services/company.service.d.ts +6 -6
  72. package/services/index.d.ts +11 -11
  73. package/services/social-auth-config.service.d.ts +6 -6
  74. package/services/social-auth.service.d.ts +5 -5
  75. package/services/user-permission.service.d.ts +8 -4
  76. package/services/user.service.d.ts +7 -7
  77. package/strategies/jwt.strategy.d.ts +4 -4
  78. package/validators/password.validator.d.ts +1 -1
  79. package/cjs/config/auth.constants.js +0 -49
  80. package/cjs/config/event-actions.js +0 -47
  81. package/cjs/config/index.js +0 -20
  82. package/cjs/config/message-keys.js +0 -135
  83. package/cjs/controllers/authentication.controller.js +0 -427
  84. package/cjs/controllers/authentication.controller.spec.js +0 -219
  85. package/cjs/controllers/branch.controller.js +0 -102
  86. package/cjs/controllers/branch.controller.spec.js +0 -134
  87. package/cjs/controllers/company-selection.controller.js +0 -198
  88. package/cjs/controllers/company-selection.controller.spec.js +0 -84
  89. package/cjs/controllers/company.controller.js +0 -102
  90. package/cjs/controllers/company.controller.spec.js +0 -131
  91. package/cjs/controllers/email-verification.controller.js +0 -224
  92. package/cjs/controllers/email-verification.controller.spec.js +0 -142
  93. package/cjs/controllers/index.js +0 -26
  94. package/cjs/controllers/social-auth-config.controller.js +0 -107
  95. package/cjs/controllers/social-auth.controller.js +0 -175
  96. package/cjs/controllers/social-auth.controller.spec.js +0 -79
  97. package/cjs/controllers/user-permission.controller.js +0 -223
  98. package/cjs/controllers/user-permission.controller.spec.js +0 -138
  99. package/cjs/controllers/user.controller.js +0 -438
  100. package/cjs/controllers/user.controller.spec.js +0 -204
  101. package/cjs/docs/auth-swagger.config.js +0 -461
  102. package/cjs/docs/auth-swagger.config.spec.js +0 -130
  103. package/cjs/docs/index.js +0 -18
  104. package/cjs/dtos/authentication.dto.js +0 -755
  105. package/cjs/dtos/company-branch.dto.js +0 -294
  106. package/cjs/dtos/company.dto.js +0 -298
  107. package/cjs/dtos/index.js +0 -23
  108. package/cjs/dtos/social-auth.dto.js +0 -318
  109. package/cjs/dtos/user-permission.dto.js +0 -358
  110. package/cjs/dtos/user.dto.js +0 -413
  111. package/cjs/entities/app-user.entity.js +0 -25
  112. package/cjs/entities/company-branch.entity.js +0 -163
  113. package/cjs/entities/company.entity.js +0 -146
  114. package/cjs/entities/index.js +0 -67
  115. package/cjs/entities/index.spec.js +0 -84
  116. package/cjs/entities/pending-registration.entity.js +0 -135
  117. package/cjs/entities/social-auth-config.entity.js +0 -102
  118. package/cjs/entities/user-company-permission.entity.js +0 -153
  119. package/cjs/entities/user-token.entity.js +0 -120
  120. package/cjs/enums/index.js +0 -19
  121. package/cjs/enums/social-provider-type.enum.js +0 -17
  122. package/cjs/enums/user-org-permission-type.enum.js +0 -15
  123. package/cjs/helpers/auth-response.mapper.js +0 -46
  124. package/cjs/helpers/auth-response.mapper.spec.js +0 -139
  125. package/cjs/helpers/index.js +0 -19
  126. package/cjs/helpers/token.helper.js +0 -58
  127. package/cjs/helpers/token.helper.spec.js +0 -86
  128. package/cjs/index.js +0 -30
  129. package/cjs/interceptors/clear-token.interceptor.js +0 -73
  130. package/cjs/interceptors/clear-token.interceptor.spec.js +0 -107
  131. package/cjs/interceptors/index.js +0 -19
  132. package/cjs/interceptors/set-token.interceptor.js +0 -107
  133. package/cjs/interceptors/set-token.interceptor.spec.js +0 -165
  134. package/cjs/interfaces/auth-email-provider.interface.js +0 -45
  135. package/cjs/interfaces/auth-module-options.interface.js +0 -4
  136. package/cjs/interfaces/authentication.interface.js +0 -4
  137. package/cjs/interfaces/company-branch.interface.js +0 -4
  138. package/cjs/interfaces/company.interface.js +0 -4
  139. package/cjs/interfaces/index.js +0 -25
  140. package/cjs/interfaces/social-auth.interface.js +0 -4
  141. package/cjs/interfaces/user-enricher.interface.js +0 -4
  142. package/cjs/interfaces/user.interface.js +0 -4
  143. package/cjs/modules/auth.module.js +0 -208
  144. package/cjs/modules/auth.module.spec.js +0 -258
  145. package/cjs/modules/index.js +0 -18
  146. package/cjs/providers/facebook.social-provider.js +0 -73
  147. package/cjs/providers/google.social-provider.js +0 -68
  148. package/cjs/providers/index.js +0 -18
  149. package/cjs/providers/linkedin.social-provider.js +0 -66
  150. package/cjs/providers/microsoft.social-provider.js +0 -78
  151. package/cjs/providers/oauth-http.util.js +0 -107
  152. package/cjs/providers/social-provider.registry.js +0 -24
  153. package/cjs/providers/social-provider.registry.spec.js +0 -135
  154. package/cjs/services/auth-config.service.js +0 -113
  155. package/cjs/services/auth-config.service.spec.js +0 -100
  156. package/cjs/services/auth-datasource.provider.js +0 -138
  157. package/cjs/services/auth-datasource.provider.spec.js +0 -191
  158. package/cjs/services/auth-email.service.js +0 -539
  159. package/cjs/services/auth-email.service.spec.js +0 -456
  160. package/cjs/services/authentication.service.js +0 -1203
  161. package/cjs/services/authentication.service.spec.js +0 -1020
  162. package/cjs/services/branch.service.js +0 -153
  163. package/cjs/services/branch.service.spec.js +0 -169
  164. package/cjs/services/company-selection-session.service.js +0 -121
  165. package/cjs/services/company-selection-session.service.spec.js +0 -90
  166. package/cjs/services/company.service.js +0 -140
  167. package/cjs/services/company.service.spec.js +0 -127
  168. package/cjs/services/index.js +0 -28
  169. package/cjs/services/social-auth-config.service.js +0 -103
  170. package/cjs/services/social-auth-config.service.spec.js +0 -71
  171. package/cjs/services/social-auth.service.js +0 -310
  172. package/cjs/services/social-auth.service.spec.js +0 -310
  173. package/cjs/services/user-permission.service.js +0 -236
  174. package/cjs/services/user-permission.service.spec.js +0 -254
  175. package/cjs/services/user.service.js +0 -671
  176. package/cjs/services/user.service.spec.js +0 -718
  177. package/cjs/strategies/jwt.strategy.js +0 -140
  178. package/cjs/strategies/jwt.strategy.spec.js +0 -166
  179. package/cjs/validators/password.validator.js +0 -45
  180. package/cjs/validators/password.validator.spec.js +0 -161
  181. package/fesm/config/auth.constants.js +0 -14
  182. package/fesm/config/event-actions.js +0 -26
  183. package/fesm/config/message-keys.js +0 -99
  184. package/fesm/controllers/authentication.controller.js +0 -417
  185. package/fesm/controllers/authentication.controller.spec.js +0 -215
  186. package/fesm/controllers/branch.controller.js +0 -92
  187. package/fesm/controllers/branch.controller.spec.js +0 -130
  188. package/fesm/controllers/company-selection.controller.js +0 -188
  189. package/fesm/controllers/company-selection.controller.spec.js +0 -80
  190. package/fesm/controllers/company.controller.js +0 -92
  191. package/fesm/controllers/company.controller.spec.js +0 -127
  192. package/fesm/controllers/email-verification.controller.js +0 -214
  193. package/fesm/controllers/email-verification.controller.spec.js +0 -138
  194. package/fesm/controllers/social-auth-config.controller.js +0 -97
  195. package/fesm/controllers/social-auth.controller.js +0 -165
  196. package/fesm/controllers/social-auth.controller.spec.js +0 -75
  197. package/fesm/controllers/user-permission.controller.js +0 -213
  198. package/fesm/controllers/user-permission.controller.spec.js +0 -134
  199. package/fesm/controllers/user.controller.js +0 -428
  200. package/fesm/controllers/user.controller.spec.js +0 -200
  201. package/fesm/docs/auth-swagger.config.js +0 -454
  202. package/fesm/docs/auth-swagger.config.spec.js +0 -126
  203. package/fesm/dtos/authentication.dto.js +0 -683
  204. package/fesm/dtos/company-branch.dto.js +0 -279
  205. package/fesm/dtos/company.dto.js +0 -283
  206. package/fesm/dtos/social-auth.dto.js +0 -282
  207. package/fesm/dtos/user-permission.dto.js +0 -339
  208. package/fesm/dtos/user.dto.js +0 -391
  209. package/fesm/entities/app-user.entity.js +0 -15
  210. package/fesm/entities/company-branch.entity.js +0 -153
  211. package/fesm/entities/company.entity.js +0 -136
  212. package/fesm/entities/index.spec.js +0 -80
  213. package/fesm/entities/pending-registration.entity.js +0 -125
  214. package/fesm/entities/social-auth-config.entity.js +0 -92
  215. package/fesm/entities/user-company-permission.entity.js +0 -136
  216. package/fesm/entities/user-token.entity.js +0 -104
  217. package/fesm/enums/social-provider-type.enum.js +0 -7
  218. package/fesm/enums/user-org-permission-type.enum.js +0 -5
  219. package/fesm/helpers/auth-response.mapper.js +0 -25
  220. package/fesm/helpers/auth-response.mapper.spec.js +0 -135
  221. package/fesm/helpers/token.helper.js +0 -40
  222. package/fesm/helpers/token.helper.spec.js +0 -82
  223. package/fesm/interceptors/clear-token.interceptor.js +0 -63
  224. package/fesm/interceptors/clear-token.interceptor.spec.js +0 -103
  225. package/fesm/interceptors/set-token.interceptor.js +0 -98
  226. package/fesm/interceptors/set-token.interceptor.spec.js +0 -161
  227. package/fesm/interfaces/auth-email-provider.interface.js +0 -38
  228. package/fesm/interfaces/auth-module-options.interface.js +0 -3
  229. package/fesm/interfaces/authentication.interface.js +0 -1
  230. package/fesm/interfaces/company-branch.interface.js +0 -1
  231. package/fesm/interfaces/company.interface.js +0 -1
  232. package/fesm/interfaces/social-auth.interface.js +0 -1
  233. package/fesm/interfaces/user-enricher.interface.js +0 -4
  234. package/fesm/interfaces/user.interface.js +0 -1
  235. package/fesm/modules/auth.module.js +0 -198
  236. package/fesm/modules/auth.module.spec.js +0 -254
  237. package/fesm/providers/facebook.social-provider.js +0 -63
  238. package/fesm/providers/google.social-provider.js +0 -58
  239. package/fesm/providers/index.js +0 -1
  240. package/fesm/providers/linkedin.social-provider.js +0 -56
  241. package/fesm/providers/microsoft.social-provider.js +0 -68
  242. package/fesm/providers/oauth-http.util.js +0 -77
  243. package/fesm/providers/social-provider.registry.js +0 -14
  244. package/fesm/providers/social-provider.registry.spec.js +0 -131
  245. package/fesm/services/auth-config.service.js +0 -103
  246. package/fesm/services/auth-config.service.spec.js +0 -96
  247. package/fesm/services/auth-datasource.provider.js +0 -87
  248. package/fesm/services/auth-datasource.provider.spec.js +0 -187
  249. package/fesm/services/auth-email.service.js +0 -488
  250. package/fesm/services/auth-email.service.spec.js +0 -411
  251. package/fesm/services/authentication.service.js +0 -1152
  252. package/fesm/services/authentication.service.spec.js +0 -975
  253. package/fesm/services/branch.service.js +0 -143
  254. package/fesm/services/branch.service.spec.js +0 -165
  255. package/fesm/services/company-selection-session.service.js +0 -111
  256. package/fesm/services/company-selection-session.service.spec.js +0 -86
  257. package/fesm/services/company.service.js +0 -130
  258. package/fesm/services/company.service.spec.js +0 -123
  259. package/fesm/services/social-auth-config.service.js +0 -93
  260. package/fesm/services/social-auth-config.service.spec.js +0 -67
  261. package/fesm/services/social-auth.service.js +0 -300
  262. package/fesm/services/social-auth.service.spec.js +0 -265
  263. package/fesm/services/user-permission.service.js +0 -226
  264. package/fesm/services/user-permission.service.spec.js +0 -250
  265. package/fesm/services/user.service.js +0 -620
  266. package/fesm/services/user.service.spec.js +0 -673
  267. package/fesm/strategies/jwt.strategy.js +0 -130
  268. package/fesm/strategies/jwt.strategy.spec.js +0 -162
  269. package/fesm/validators/password.validator.js +0 -48
  270. package/fesm/validators/password.validator.spec.js +0 -157
@@ -1,454 +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
- '- Social sign-in (Google, Facebook, LinkedIn, Microsoft)',
323
- '- JWT token-based authentication',
324
- ...enableEmailVerification ? [
325
- '- Email verification',
326
- '- Forgot/reset password'
327
- ] : [],
328
- ...enableCompanyFeature ? [
329
- '- Company/Branch selection flow (multi-company enabled)'
330
- ] : [],
331
- '- Token refresh',
332
- '- Password change'
333
- ].join('\n');
334
- const loginFlowSection = enableCompanyFeature ? `
335
- ### Authentication Flow
336
-
337
- #### Simple Login (single company/branch)
338
- \`\`\`
339
- POST /auth/login → { accessToken, refreshToken, user, company, branch }
340
- \`\`\`
341
-
342
- #### Multi-Company Login (multiple companies or branches)
343
- \`\`\`
344
- POST /auth/login → { requiresSelection: true, sessionId, companies }
345
- POST /auth/select → { accessToken, refreshToken, user, company, branch }
346
- \`\`\`
347
- ${enableEmailVerification ? `
348
- #### Email Verification Required
349
- \`\`\`
350
- POST /auth/login → { requiresEmailVerification: true, email }
351
- POST /auth/verify-email → { accessToken, refreshToken, user }
352
- \`\`\`
353
- ` : ''}
354
- ### Company/Branch Selection Endpoints
355
- - \`POST /auth/select\` - Complete login by selecting company and branch
356
- - \`POST /auth/switch-company\` - Switch to different company/branch while logged in
357
- ` : `
358
- ### Authentication Flow
359
- \`\`\`
360
- POST /auth/login → { accessToken, refreshToken, user }
361
- \`\`\`
362
- ${enableEmailVerification ? `
363
- #### Email Verification Required
364
- \`\`\`
365
- POST /auth/login → { requiresEmailVerification: true, email }
366
- POST /auth/verify-email → { accessToken, refreshToken, user }
367
- \`\`\`
368
- ` : ''}`;
369
- const emailVerificationSection = enableEmailVerification ? `
370
- ### Email Verification Endpoints
371
- - \`POST /auth/forgot-password\` - Request password reset email
372
- - \`POST /auth/reset-password\` - Reset password using token
373
- - \`POST /auth/resend-verification\` - Resend verification email
374
- - \`POST /auth/verify-email\` - Verify email using token
375
- ` : '';
376
- const socialSection = `
377
- ### Social Sign-In Endpoints
378
- - \`POST /auth/social/providers\` - List the providers an administrator enabled
379
- - \`POST /auth/social/authorize\` - Start a sign-in and get the provider's consent URL
380
- - \`POST /auth/social/callback\` - Exchange the provider's code for a session
381
- - \`POST /auth/social-config/*\` - Manage provider credentials
382
- `;
383
- const administrationSection = enableCompanyFeature ? `
384
- ### Administration Endpoints
385
- - \`POST /administration/users/*\` - User management
386
- - \`POST /administration/company/*\` - Company management
387
- - \`POST /administration/branch/*\` - Branch management
388
- - \`POST /administration/user-permissions/*\` - User permission management
389
- ` : `
390
- ### Administration Endpoints
391
- - \`POST /administration/users/*\` - User management
392
- `;
393
- const registrationSection = enableCompanyFeature ? `
394
- ### Registration Flow
395
-
396
- **Simple registration:**
397
- \`\`\`json
398
- { "name": "John Doe", "email": "john@example.com", "password": "password123" }
399
- \`\`\`
400
-
401
- **Join existing company:**
402
- \`\`\`json
403
- { "name": "John Doe", "email": "john@example.com", "password": "password123", "companySlug": "acme-corp", "branchSlug": "main-branch" }
404
- \`\`\`
405
-
406
- **Create new company:**
407
- \`\`\`json
408
- { "name": "John Doe", "email": "john@example.com", "password": "password123", "newCompanyName": "My New Company" }
409
- \`\`\`
410
- ` : `
411
- ### Registration Flow
412
- \`\`\`json
413
- { "name": "John Doe", "email": "john@example.com", "password": "password123" }
414
- \`\`\`
415
- `;
416
- return `
417
- ## Authentication API
418
- ${multiTenantNote}
419
- Handles user authentication${enableCompanyFeature ? ', company/branch management' : ''}, and registration.
420
-
421
- ### Features
422
- ${features}
423
- ${loginFlowSection}${emailVerificationSection}${socialSection}${administrationSection}${registrationSection}`;
424
- }
425
- // ============================================================================
426
- // Config factory
427
- // ============================================================================
428
- export function authSwaggerConfig(bootstrapConfig) {
429
- const enableCompanyFeature = bootstrapConfig?.enableCompanyFeature ?? true;
430
- const enableEmailVerification = bootstrapConfig?.enableEmailVerification ?? true;
431
- const isMultiTenant = bootstrapConfig?.databaseMode === 'multi-tenant';
432
- const excludeTags = enableCompanyFeature ? [] : COMPANY_RELATED_TAGS;
433
- const excludeSchemaProperties = [
434
- ...enableCompanyFeature ? [] : COMPANY_SCHEMA_EXCLUSIONS,
435
- ...enableEmailVerification ? [] : EMAIL_VERIFICATION_SCHEMA_EXCLUSIONS
436
- ];
437
- // Merge example exclusions — both may target /auth/login with different example names
438
- const excludeExamples = [
439
- ...enableCompanyFeature ? [] : COMPANY_EXAMPLE_EXCLUSIONS,
440
- ...enableEmailVerification ? [] : EMAIL_VERIFICATION_EXAMPLE_EXCLUSIONS
441
- ];
442
- const excludePaths = enableEmailVerification ? undefined : EMAIL_VERIFICATION_PATHS;
443
- return {
444
- title: 'Auth API',
445
- description: buildDescription(enableCompanyFeature, enableEmailVerification, isMultiTenant),
446
- version: '1.0',
447
- path: 'api/docs/auth',
448
- bearerAuth: true,
449
- excludeTags,
450
- excludeSchemaProperties: excludeSchemaProperties.length ? excludeSchemaProperties : undefined,
451
- excludeExamples: excludeExamples.length ? excludeExamples : undefined,
452
- excludePaths
453
- };
454
- }
@@ -1,126 +0,0 @@
1
- import { authSwaggerConfig } from './auth-swagger.config';
2
- describe('authSwaggerConfig', ()=>{
3
- it('should default to both features enabled and single-database mode when no config is given', ()=>{
4
- const config = authSwaggerConfig();
5
- expect(config.title).toBe('Auth API');
6
- expect(config.path).toBe('api/docs/auth');
7
- expect(config.bearerAuth).toBe(true);
8
- expect(config.excludeTags).toEqual([]);
9
- expect(config.excludeSchemaProperties).toBeUndefined();
10
- expect(config.excludeExamples).toBeUndefined();
11
- expect(config.excludePaths).toBeUndefined();
12
- expect(config.description).not.toContain('Multi-Tenant Mode');
13
- });
14
- it('should exclude company-related tags, schema properties, and examples when the company feature is off', ()=>{
15
- const config = authSwaggerConfig({
16
- enableCompanyFeature: false,
17
- databaseMode: 'single'
18
- });
19
- expect(config.excludeTags).toEqual(expect.arrayContaining([
20
- 'Companies',
21
- 'Branches',
22
- 'User Permissions',
23
- 'Company Selection'
24
- ]));
25
- expect(config.excludeSchemaProperties).toEqual(expect.arrayContaining([
26
- expect.objectContaining({
27
- schemaName: 'RegistrationDto'
28
- })
29
- ]));
30
- expect(config.excludeExamples).toEqual(expect.arrayContaining([
31
- expect.objectContaining({
32
- pathPattern: '/auth/login',
33
- examples: [
34
- 'loginSuccessWithCompany',
35
- 'companySelection'
36
- ]
37
- })
38
- ]));
39
- // Email verification is still enabled by default, so its paths must not be excluded
40
- expect(config.excludePaths).toBeUndefined();
41
- });
42
- it('should exclude email-verification paths, schema properties, and examples when disabled', ()=>{
43
- const config = authSwaggerConfig({
44
- enableEmailVerification: false
45
- });
46
- expect(config.excludePaths).toEqual([
47
- '/auth/forgot-password',
48
- '/auth/reset-password',
49
- '/auth/resend-verification',
50
- '/auth/verify-email'
51
- ]);
52
- expect(config.excludeSchemaProperties).toEqual(expect.arrayContaining([
53
- expect.objectContaining({
54
- schemaName: 'LoginResponseRequiresEmailVerificationDto'
55
- })
56
- ]));
57
- expect(config.excludeExamples).toEqual(expect.arrayContaining([
58
- expect.objectContaining({
59
- pathPattern: '/auth/login',
60
- examples: [
61
- 'emailVerification'
62
- ]
63
- })
64
- ]));
65
- // Company feature is still enabled by default, so its tags must not be excluded
66
- expect(config.excludeTags).toEqual([]);
67
- });
68
- it('should merge exclusions from both features when both are disabled', ()=>{
69
- const config = authSwaggerConfig({
70
- enableCompanyFeature: false,
71
- enableEmailVerification: false
72
- });
73
- expect(config.excludeTags?.length).toBeGreaterThan(0);
74
- expect(config.excludePaths?.length).toBeGreaterThan(0);
75
- // Both feature's schema exclusions should be present together
76
- const schemaNames = config.excludeSchemaProperties?.map((e)=>e.schemaName) ?? [];
77
- expect(schemaNames).toContain('RegistrationDto');
78
- expect(schemaNames).toContain('LoginResponseRequiresEmailVerificationDto');
79
- // Both feature's example exclusions merge onto the same /auth/login path
80
- const loginExclusions = config.excludeExamples?.filter((e)=>e.pathPattern === '/auth/login');
81
- expect(loginExclusions).toHaveLength(2);
82
- });
83
- it('should mention multi-tenant mode in the description only for multi-tenant database mode', ()=>{
84
- const multiTenant = authSwaggerConfig({
85
- databaseMode: 'multi-tenant'
86
- });
87
- const single = authSwaggerConfig({
88
- databaseMode: 'single'
89
- });
90
- expect(multiTenant.description).toContain('Multi-Tenant Mode');
91
- expect(single.description).not.toContain('Multi-Tenant Mode');
92
- });
93
- it('should describe the multi-company login flow only when the company feature is enabled', ()=>{
94
- const withCompany = authSwaggerConfig({
95
- enableCompanyFeature: true
96
- });
97
- const withoutCompany = authSwaggerConfig({
98
- enableCompanyFeature: false
99
- });
100
- expect(withCompany.description).toContain('Multi-Company Login');
101
- expect(withCompany.description).toContain('/auth/switch-company');
102
- expect(withoutCompany.description).not.toContain('Multi-Company Login');
103
- expect(withoutCompany.description).not.toContain('/auth/switch-company');
104
- });
105
- it('should describe email verification endpoints only when enabled', ()=>{
106
- const withVerification = authSwaggerConfig({
107
- enableEmailVerification: true
108
- });
109
- const withoutVerification = authSwaggerConfig({
110
- enableEmailVerification: false
111
- });
112
- expect(withVerification.description).toContain('/auth/forgot-password');
113
- expect(withoutVerification.description).not.toContain('### Email Verification Endpoints');
114
- });
115
- it('should list company administration endpoints only when the company feature is enabled', ()=>{
116
- const withCompany = authSwaggerConfig({
117
- enableCompanyFeature: true
118
- });
119
- const withoutCompany = authSwaggerConfig({
120
- enableCompanyFeature: false
121
- });
122
- expect(withCompany.description).toContain('/administration/company/*');
123
- expect(withoutCompany.description).not.toContain('/administration/company/*');
124
- expect(withoutCompany.description).toContain('/administration/users/*');
125
- });
126
- });