@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.
Files changed (271) hide show
  1. package/README.md +1 -1
  2. package/config/index.d.ts +3 -3
  3. package/config/message-keys.d.ts +4 -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 +7 -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/dtos/user-permission.dto.d.ts +30 -0
  19. package/entities/company-branch.entity.d.ts +1 -1
  20. package/entities/company.entity.d.ts +1 -1
  21. package/entities/index.d.ts +14 -14
  22. package/entities/pending-registration.entity.d.ts +1 -1
  23. package/entities/user-company-permission.entity.d.ts +4 -4
  24. package/enums/index.d.ts +2 -2
  25. package/fesm/118.js +1404 -0
  26. package/fesm/120.js +2265 -0
  27. package/fesm/24.js +4422 -0
  28. package/fesm/370.js +1163 -0
  29. package/fesm/446.js +877 -0
  30. package/fesm/chunks/117.js +69 -0
  31. package/fesm/config/index.js +246 -3
  32. package/fesm/controllers/index.js +27 -9
  33. package/fesm/docs/index.js +479 -1
  34. package/fesm/dtos/index.js +135 -6
  35. package/fesm/entities/index.js +68 -22
  36. package/fesm/enums/index.js +53 -2
  37. package/fesm/helpers/index.js +115 -2
  38. package/fesm/index.js +1455 -13
  39. package/fesm/interceptors/index.js +510 -2
  40. package/fesm/interfaces/index.js +75 -8
  41. package/fesm/modules/index.js +546 -1
  42. package/fesm/runtime.js +134 -0
  43. package/fesm/services/index.js +67 -11
  44. package/helpers/auth-response.mapper.d.ts +3 -3
  45. package/helpers/index.d.ts +2 -2
  46. package/helpers/token.helper.d.ts +2 -2
  47. package/index.d.ts +13 -13
  48. package/interceptors/clear-token.interceptor.d.ts +2 -2
  49. package/interceptors/index.d.ts +2 -2
  50. package/interceptors/set-token.interceptor.d.ts +2 -2
  51. package/interfaces/auth-module-options.interface.d.ts +3 -3
  52. package/interfaces/authentication.interface.d.ts +3 -3
  53. package/interfaces/company-branch.interface.d.ts +2 -2
  54. package/interfaces/company.interface.d.ts +1 -1
  55. package/interfaces/index.d.ts +8 -8
  56. package/interfaces/social-auth.interface.d.ts +2 -2
  57. package/interfaces/user-enricher.interface.d.ts +3 -3
  58. package/modules/auth.module.d.ts +4 -4
  59. package/modules/index.d.ts +1 -1
  60. package/package.json +32 -39
  61. package/providers/facebook.social-provider.d.ts +2 -2
  62. package/providers/google.social-provider.d.ts +2 -2
  63. package/providers/index.d.ts +1 -1
  64. package/providers/linkedin.social-provider.d.ts +2 -2
  65. package/providers/microsoft.social-provider.d.ts +2 -2
  66. package/providers/social-provider.registry.d.ts +2 -2
  67. package/services/auth-config.service.d.ts +3 -3
  68. package/services/auth-datasource.provider.d.ts +3 -3
  69. package/services/auth-email.service.d.ts +3 -3
  70. package/services/authentication.service.d.ts +12 -12
  71. package/services/branch.service.d.ts +7 -7
  72. package/services/company.service.d.ts +6 -6
  73. package/services/index.d.ts +11 -11
  74. package/services/social-auth-config.service.d.ts +6 -6
  75. package/services/social-auth.service.d.ts +5 -5
  76. package/services/user-permission.service.d.ts +10 -4
  77. package/services/user.service.d.ts +7 -7
  78. package/strategies/jwt.strategy.d.ts +4 -4
  79. package/validators/password.validator.d.ts +1 -1
  80. package/cjs/config/auth.constants.js +0 -49
  81. package/cjs/config/event-actions.js +0 -47
  82. package/cjs/config/index.js +0 -20
  83. package/cjs/config/message-keys.js +0 -135
  84. package/cjs/controllers/authentication.controller.js +0 -427
  85. package/cjs/controllers/authentication.controller.spec.js +0 -219
  86. package/cjs/controllers/branch.controller.js +0 -102
  87. package/cjs/controllers/branch.controller.spec.js +0 -134
  88. package/cjs/controllers/company-selection.controller.js +0 -198
  89. package/cjs/controllers/company-selection.controller.spec.js +0 -84
  90. package/cjs/controllers/company.controller.js +0 -102
  91. package/cjs/controllers/company.controller.spec.js +0 -131
  92. package/cjs/controllers/email-verification.controller.js +0 -224
  93. package/cjs/controllers/email-verification.controller.spec.js +0 -142
  94. package/cjs/controllers/index.js +0 -26
  95. package/cjs/controllers/social-auth-config.controller.js +0 -107
  96. package/cjs/controllers/social-auth.controller.js +0 -175
  97. package/cjs/controllers/social-auth.controller.spec.js +0 -79
  98. package/cjs/controllers/user-permission.controller.js +0 -223
  99. package/cjs/controllers/user-permission.controller.spec.js +0 -138
  100. package/cjs/controllers/user.controller.js +0 -438
  101. package/cjs/controllers/user.controller.spec.js +0 -204
  102. package/cjs/docs/auth-swagger.config.js +0 -461
  103. package/cjs/docs/auth-swagger.config.spec.js +0 -130
  104. package/cjs/docs/index.js +0 -18
  105. package/cjs/dtos/authentication.dto.js +0 -755
  106. package/cjs/dtos/company-branch.dto.js +0 -294
  107. package/cjs/dtos/company.dto.js +0 -298
  108. package/cjs/dtos/index.js +0 -23
  109. package/cjs/dtos/social-auth.dto.js +0 -318
  110. package/cjs/dtos/user-permission.dto.js +0 -358
  111. package/cjs/dtos/user.dto.js +0 -413
  112. package/cjs/entities/app-user.entity.js +0 -25
  113. package/cjs/entities/company-branch.entity.js +0 -163
  114. package/cjs/entities/company.entity.js +0 -146
  115. package/cjs/entities/index.js +0 -67
  116. package/cjs/entities/index.spec.js +0 -84
  117. package/cjs/entities/pending-registration.entity.js +0 -135
  118. package/cjs/entities/social-auth-config.entity.js +0 -102
  119. package/cjs/entities/user-company-permission.entity.js +0 -153
  120. package/cjs/entities/user-token.entity.js +0 -120
  121. package/cjs/enums/index.js +0 -19
  122. package/cjs/enums/social-provider-type.enum.js +0 -17
  123. package/cjs/enums/user-org-permission-type.enum.js +0 -15
  124. package/cjs/helpers/auth-response.mapper.js +0 -46
  125. package/cjs/helpers/auth-response.mapper.spec.js +0 -139
  126. package/cjs/helpers/index.js +0 -19
  127. package/cjs/helpers/token.helper.js +0 -58
  128. package/cjs/helpers/token.helper.spec.js +0 -86
  129. package/cjs/index.js +0 -30
  130. package/cjs/interceptors/clear-token.interceptor.js +0 -73
  131. package/cjs/interceptors/clear-token.interceptor.spec.js +0 -107
  132. package/cjs/interceptors/index.js +0 -19
  133. package/cjs/interceptors/set-token.interceptor.js +0 -107
  134. package/cjs/interceptors/set-token.interceptor.spec.js +0 -165
  135. package/cjs/interfaces/auth-email-provider.interface.js +0 -45
  136. package/cjs/interfaces/auth-module-options.interface.js +0 -4
  137. package/cjs/interfaces/authentication.interface.js +0 -4
  138. package/cjs/interfaces/company-branch.interface.js +0 -4
  139. package/cjs/interfaces/company.interface.js +0 -4
  140. package/cjs/interfaces/index.js +0 -25
  141. package/cjs/interfaces/social-auth.interface.js +0 -4
  142. package/cjs/interfaces/user-enricher.interface.js +0 -4
  143. package/cjs/interfaces/user.interface.js +0 -4
  144. package/cjs/modules/auth.module.js +0 -208
  145. package/cjs/modules/auth.module.spec.js +0 -258
  146. package/cjs/modules/index.js +0 -18
  147. package/cjs/providers/facebook.social-provider.js +0 -73
  148. package/cjs/providers/google.social-provider.js +0 -68
  149. package/cjs/providers/index.js +0 -18
  150. package/cjs/providers/linkedin.social-provider.js +0 -66
  151. package/cjs/providers/microsoft.social-provider.js +0 -78
  152. package/cjs/providers/oauth-http.util.js +0 -107
  153. package/cjs/providers/social-provider.registry.js +0 -24
  154. package/cjs/providers/social-provider.registry.spec.js +0 -135
  155. package/cjs/services/auth-config.service.js +0 -113
  156. package/cjs/services/auth-config.service.spec.js +0 -100
  157. package/cjs/services/auth-datasource.provider.js +0 -138
  158. package/cjs/services/auth-datasource.provider.spec.js +0 -191
  159. package/cjs/services/auth-email.service.js +0 -539
  160. package/cjs/services/auth-email.service.spec.js +0 -456
  161. package/cjs/services/authentication.service.js +0 -1203
  162. package/cjs/services/authentication.service.spec.js +0 -1020
  163. package/cjs/services/branch.service.js +0 -153
  164. package/cjs/services/branch.service.spec.js +0 -169
  165. package/cjs/services/company-selection-session.service.js +0 -121
  166. package/cjs/services/company-selection-session.service.spec.js +0 -90
  167. package/cjs/services/company.service.js +0 -140
  168. package/cjs/services/company.service.spec.js +0 -127
  169. package/cjs/services/index.js +0 -28
  170. package/cjs/services/social-auth-config.service.js +0 -103
  171. package/cjs/services/social-auth-config.service.spec.js +0 -71
  172. package/cjs/services/social-auth.service.js +0 -310
  173. package/cjs/services/social-auth.service.spec.js +0 -310
  174. package/cjs/services/user-permission.service.js +0 -236
  175. package/cjs/services/user-permission.service.spec.js +0 -254
  176. package/cjs/services/user.service.js +0 -671
  177. package/cjs/services/user.service.spec.js +0 -718
  178. package/cjs/strategies/jwt.strategy.js +0 -140
  179. package/cjs/strategies/jwt.strategy.spec.js +0 -166
  180. package/cjs/validators/password.validator.js +0 -45
  181. package/cjs/validators/password.validator.spec.js +0 -161
  182. package/fesm/config/auth.constants.js +0 -14
  183. package/fesm/config/event-actions.js +0 -26
  184. package/fesm/config/message-keys.js +0 -99
  185. package/fesm/controllers/authentication.controller.js +0 -417
  186. package/fesm/controllers/authentication.controller.spec.js +0 -215
  187. package/fesm/controllers/branch.controller.js +0 -92
  188. package/fesm/controllers/branch.controller.spec.js +0 -130
  189. package/fesm/controllers/company-selection.controller.js +0 -188
  190. package/fesm/controllers/company-selection.controller.spec.js +0 -80
  191. package/fesm/controllers/company.controller.js +0 -92
  192. package/fesm/controllers/company.controller.spec.js +0 -127
  193. package/fesm/controllers/email-verification.controller.js +0 -214
  194. package/fesm/controllers/email-verification.controller.spec.js +0 -138
  195. package/fesm/controllers/social-auth-config.controller.js +0 -97
  196. package/fesm/controllers/social-auth.controller.js +0 -165
  197. package/fesm/controllers/social-auth.controller.spec.js +0 -75
  198. package/fesm/controllers/user-permission.controller.js +0 -213
  199. package/fesm/controllers/user-permission.controller.spec.js +0 -134
  200. package/fesm/controllers/user.controller.js +0 -428
  201. package/fesm/controllers/user.controller.spec.js +0 -200
  202. package/fesm/docs/auth-swagger.config.js +0 -454
  203. package/fesm/docs/auth-swagger.config.spec.js +0 -126
  204. package/fesm/dtos/authentication.dto.js +0 -683
  205. package/fesm/dtos/company-branch.dto.js +0 -279
  206. package/fesm/dtos/company.dto.js +0 -283
  207. package/fesm/dtos/social-auth.dto.js +0 -282
  208. package/fesm/dtos/user-permission.dto.js +0 -339
  209. package/fesm/dtos/user.dto.js +0 -391
  210. package/fesm/entities/app-user.entity.js +0 -15
  211. package/fesm/entities/company-branch.entity.js +0 -153
  212. package/fesm/entities/company.entity.js +0 -136
  213. package/fesm/entities/index.spec.js +0 -80
  214. package/fesm/entities/pending-registration.entity.js +0 -125
  215. package/fesm/entities/social-auth-config.entity.js +0 -92
  216. package/fesm/entities/user-company-permission.entity.js +0 -136
  217. package/fesm/entities/user-token.entity.js +0 -104
  218. package/fesm/enums/social-provider-type.enum.js +0 -7
  219. package/fesm/enums/user-org-permission-type.enum.js +0 -5
  220. package/fesm/helpers/auth-response.mapper.js +0 -25
  221. package/fesm/helpers/auth-response.mapper.spec.js +0 -135
  222. package/fesm/helpers/token.helper.js +0 -40
  223. package/fesm/helpers/token.helper.spec.js +0 -82
  224. package/fesm/interceptors/clear-token.interceptor.js +0 -63
  225. package/fesm/interceptors/clear-token.interceptor.spec.js +0 -103
  226. package/fesm/interceptors/set-token.interceptor.js +0 -98
  227. package/fesm/interceptors/set-token.interceptor.spec.js +0 -161
  228. package/fesm/interfaces/auth-email-provider.interface.js +0 -38
  229. package/fesm/interfaces/auth-module-options.interface.js +0 -3
  230. package/fesm/interfaces/authentication.interface.js +0 -1
  231. package/fesm/interfaces/company-branch.interface.js +0 -1
  232. package/fesm/interfaces/company.interface.js +0 -1
  233. package/fesm/interfaces/social-auth.interface.js +0 -1
  234. package/fesm/interfaces/user-enricher.interface.js +0 -4
  235. package/fesm/interfaces/user.interface.js +0 -1
  236. package/fesm/modules/auth.module.js +0 -198
  237. package/fesm/modules/auth.module.spec.js +0 -254
  238. package/fesm/providers/facebook.social-provider.js +0 -63
  239. package/fesm/providers/google.social-provider.js +0 -58
  240. package/fesm/providers/index.js +0 -1
  241. package/fesm/providers/linkedin.social-provider.js +0 -56
  242. package/fesm/providers/microsoft.social-provider.js +0 -68
  243. package/fesm/providers/oauth-http.util.js +0 -77
  244. package/fesm/providers/social-provider.registry.js +0 -14
  245. package/fesm/providers/social-provider.registry.spec.js +0 -131
  246. package/fesm/services/auth-config.service.js +0 -103
  247. package/fesm/services/auth-config.service.spec.js +0 -96
  248. package/fesm/services/auth-datasource.provider.js +0 -87
  249. package/fesm/services/auth-datasource.provider.spec.js +0 -187
  250. package/fesm/services/auth-email.service.js +0 -488
  251. package/fesm/services/auth-email.service.spec.js +0 -411
  252. package/fesm/services/authentication.service.js +0 -1152
  253. package/fesm/services/authentication.service.spec.js +0 -975
  254. package/fesm/services/branch.service.js +0 -143
  255. package/fesm/services/branch.service.spec.js +0 -165
  256. package/fesm/services/company-selection-session.service.js +0 -111
  257. package/fesm/services/company-selection-session.service.spec.js +0 -86
  258. package/fesm/services/company.service.js +0 -130
  259. package/fesm/services/company.service.spec.js +0 -123
  260. package/fesm/services/social-auth-config.service.js +0 -93
  261. package/fesm/services/social-auth-config.service.spec.js +0 -67
  262. package/fesm/services/social-auth.service.js +0 -300
  263. package/fesm/services/social-auth.service.spec.js +0 -265
  264. package/fesm/services/user-permission.service.js +0 -226
  265. package/fesm/services/user-permission.service.spec.js +0 -250
  266. package/fesm/services/user.service.js +0 -620
  267. package/fesm/services/user.service.spec.js +0 -673
  268. package/fesm/strategies/jwt.strategy.js +0 -130
  269. package/fesm/strategies/jwt.strategy.spec.js +0 -162
  270. package/fesm/validators/password.validator.js +0 -48
  271. 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
- });