@flusys/nestjs-shared 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 (338) hide show
  1. package/classes/api-controller.class.d.ts +4 -4
  2. package/classes/api-service.class.d.ts +7 -7
  3. package/classes/disabled-event-bus.class.d.ts +1 -1
  4. package/classes/domain-event.publisher.d.ts +1 -1
  5. package/classes/event-bus.registry.d.ts +1 -1
  6. package/classes/event-transports/event-transport.registry.d.ts +1 -1
  7. package/classes/event-transports/index.d.ts +2 -2
  8. package/classes/event-transports/kafka-transport.optional.d.ts +1 -1
  9. package/classes/event-transports/memory-transport.d.ts +1 -1
  10. package/classes/event-transports/rabbitmq-transport.optional.d.ts +1 -1
  11. package/classes/hybrid-event-bus.class.d.ts +1 -1
  12. package/classes/index.d.ts +11 -11
  13. package/constants/index.d.ts +2 -2
  14. package/decorators/api-response.decorator.d.ts +1 -1
  15. package/decorators/current-user.decorator.d.ts +1 -1
  16. package/decorators/index.d.ts +6 -6
  17. package/decorators/require-permission.decorator.d.ts +1 -1
  18. package/dtos/filter-and-pagination.dto.d.ts +1 -1
  19. package/dtos/index.d.ts +6 -6
  20. package/entities/index.d.ts +3 -3
  21. package/enums/index.d.ts +3 -3
  22. package/exceptions/index.d.ts +2 -2
  23. package/fesm/470.js +2713 -0
  24. package/fesm/509.js +793 -0
  25. package/fesm/667.js +606 -0
  26. package/fesm/67.js +808 -0
  27. package/fesm/720.js +914 -0
  28. package/{cjs/classes/event-transports/rabbitmq-transport.optional.js → fesm/chunks/123.js} +78 -55
  29. package/fesm/{classes/event-transports/kafka-transport.optional.js → chunks/37.js} +74 -41
  30. package/fesm/classes/index.js +62 -12
  31. package/fesm/constants/index.js +445 -17
  32. package/fesm/decorators/index.js +341 -6
  33. package/fesm/dtos/index.js +23 -6
  34. package/fesm/entities/index.js +336 -3
  35. package/fesm/enums/index.js +57 -3
  36. package/fesm/exceptions/index.js +280 -2
  37. package/fesm/guards/index.js +1003 -3
  38. package/fesm/index.js +1524 -14
  39. package/fesm/interceptors/index.js +924 -5
  40. package/fesm/interfaces/index.js +57 -11
  41. package/fesm/middlewares/index.js +33 -1
  42. package/fesm/modules/index.js +432 -9
  43. package/fesm/runtime.js +134 -0
  44. package/fesm/utils/index.js +1045 -8
  45. package/filters/global-exception.filter.d.ts +1 -1
  46. package/filters/index.d.ts +1 -1
  47. package/guards/index.d.ts +3 -3
  48. package/guards/jwt-auth.guard.d.ts +1 -1
  49. package/guards/optional-jwt-auth.guard.d.ts +1 -1
  50. package/guards/permission.guard.d.ts +2 -2
  51. package/index.d.ts +14 -14
  52. package/interceptors/delete-empty-id-from-body.interceptor.d.ts +1 -1
  53. package/interceptors/idempotency.interceptor.d.ts +2 -2
  54. package/interceptors/index.d.ts +5 -5
  55. package/interceptors/response-meta.interceptor.d.ts +1 -1
  56. package/interceptors/set-user-field-on-body.interceptor.d.ts +1 -1
  57. package/interceptors/slug.interceptor.d.ts +2 -2
  58. package/interfaces/ai-assistant-adapter.interface.d.ts +1 -1
  59. package/interfaces/api.interface.d.ts +2 -2
  60. package/interfaces/datasource.interface.d.ts +1 -1
  61. package/interfaces/event-manager-adapter.interface.d.ts +2 -2
  62. package/interfaces/index.d.ts +11 -11
  63. package/interfaces/module-config.interface.d.ts +1 -1
  64. package/interfaces/notification-adapter.interface.d.ts +1 -1
  65. package/middlewares/index.d.ts +1 -1
  66. package/middlewares/logger.middleware.d.ts +2 -2
  67. package/modules/cache/cache.module.d.ts +1 -1
  68. package/modules/datasource/index.d.ts +1 -1
  69. package/modules/datasource/multi-tenant-datasource.service.d.ts +4 -4
  70. package/modules/event-bus/event-bus.explorer.d.ts +2 -2
  71. package/modules/event-bus/event-bus.module.d.ts +2 -2
  72. package/modules/event-bus/module-events.provider.d.ts +1 -1
  73. package/modules/index.d.ts +9 -9
  74. package/modules/shared-permission-cache/shared-permission-cache.service.d.ts +3 -3
  75. package/modules/utils/utils.service.d.ts +1 -1
  76. package/package.json +30 -44
  77. package/utils/index.d.ts +8 -8
  78. package/utils/permission-cache-key.util.d.ts +1 -1
  79. package/utils/query-helpers.util.d.ts +2 -2
  80. package/utils/request.util.d.ts +1 -1
  81. package/cjs/classes/api-controller.class.js +0 -728
  82. package/cjs/classes/api-controller.class.spec.js +0 -684
  83. package/cjs/classes/api-service.class.js +0 -631
  84. package/cjs/classes/api-service.class.spec.js +0 -1137
  85. package/cjs/classes/disabled-event-bus.class.js +0 -15
  86. package/cjs/classes/disabled-event-bus.class.spec.js +0 -40
  87. package/cjs/classes/domain-event.publisher.js +0 -76
  88. package/cjs/classes/domain-event.publisher.spec.js +0 -234
  89. package/cjs/classes/event-bus.registry.js +0 -68
  90. package/cjs/classes/event-bus.registry.spec.js +0 -141
  91. package/cjs/classes/event-transports/event-transport.registry.js +0 -41
  92. package/cjs/classes/event-transports/event-transport.registry.spec.js +0 -31
  93. package/cjs/classes/event-transports/index.js +0 -23
  94. package/cjs/classes/event-transports/kafka-transport.optional.js +0 -151
  95. package/cjs/classes/event-transports/kafka-transport.optional.spec.js +0 -198
  96. package/cjs/classes/event-transports/memory-transport.js +0 -53
  97. package/cjs/classes/event-transports/memory-transport.spec.js +0 -57
  98. package/cjs/classes/event-transports/rabbitmq-transport.optional.spec.js +0 -255
  99. package/cjs/classes/handle-custome-db.js +0 -37
  100. package/cjs/classes/handle-custome-db.spec.js +0 -82
  101. package/cjs/classes/hybrid-cache.class.js +0 -96
  102. package/cjs/classes/hybrid-cache.class.spec.js +0 -168
  103. package/cjs/classes/hybrid-event-bus.class.js +0 -281
  104. package/cjs/classes/hybrid-event-bus.class.spec.js +0 -218
  105. package/cjs/classes/index.js +0 -28
  106. package/cjs/classes/winston.logger.class.js +0 -274
  107. package/cjs/classes/winston.logger.class.spec.js +0 -330
  108. package/cjs/constants/index.js +0 -88
  109. package/cjs/constants/message-keys.js +0 -68
  110. package/cjs/constants/permissions.js +0 -307
  111. package/cjs/decorators/api-response.decorator.js +0 -52
  112. package/cjs/decorators/api-response.decorator.spec.js +0 -126
  113. package/cjs/decorators/current-user.decorator.js +0 -16
  114. package/cjs/decorators/current-user.decorator.spec.js +0 -74
  115. package/cjs/decorators/index.js +0 -23
  116. package/cjs/decorators/log-action.decorator.js +0 -149
  117. package/cjs/decorators/log-action.decorator.spec.js +0 -353
  118. package/cjs/decorators/on-domain-event.decorator.js +0 -13
  119. package/cjs/decorators/on-domain-event.decorator.spec.js +0 -50
  120. package/cjs/decorators/public.decorator.js +0 -13
  121. package/cjs/decorators/public.decorator.spec.js +0 -50
  122. package/cjs/decorators/require-permission.decorator.js +0 -32
  123. package/cjs/decorators/require-permission.decorator.spec.js +0 -147
  124. package/cjs/dtos/delete.dto.js +0 -92
  125. package/cjs/dtos/filter-and-pagination.dto.js +0 -164
  126. package/cjs/dtos/get-by-ids.dto.js +0 -65
  127. package/cjs/dtos/identity-response.dto.js +0 -108
  128. package/cjs/dtos/index.js +0 -23
  129. package/cjs/dtos/pagination.dto.js +0 -67
  130. package/cjs/dtos/response-payload.dto.js +0 -369
  131. package/cjs/entities/identity.js +0 -100
  132. package/cjs/entities/index.js +0 -20
  133. package/cjs/entities/raw-type.js +0 -4
  134. package/cjs/entities/user-root.js +0 -189
  135. package/cjs/enums/index.js +0 -20
  136. package/cjs/enums/notification-type.enum.js +0 -17
  137. package/cjs/enums/participant-status.enum.js +0 -17
  138. package/cjs/enums/recurrence-type.enum.js +0 -18
  139. package/cjs/exceptions/base-app.exception.js +0 -151
  140. package/cjs/exceptions/base-app.exception.spec.js +0 -157
  141. package/cjs/exceptions/index.js +0 -19
  142. package/cjs/exceptions/permission.exception.js +0 -56
  143. package/cjs/exceptions/permission.exception.spec.js +0 -82
  144. package/cjs/filters/global-exception.filter.js +0 -279
  145. package/cjs/filters/global-exception.filter.spec.js +0 -440
  146. package/cjs/filters/index.js +0 -18
  147. package/cjs/guards/index.js +0 -20
  148. package/cjs/guards/jwt-auth.guard.js +0 -75
  149. package/cjs/guards/jwt-auth.guard.spec.js +0 -75
  150. package/cjs/guards/optional-jwt-auth.guard.js +0 -67
  151. package/cjs/guards/optional-jwt-auth.guard.spec.js +0 -55
  152. package/cjs/guards/permission.guard.js +0 -179
  153. package/cjs/guards/permission.guard.spec.js +0 -373
  154. package/cjs/index.js +0 -31
  155. package/cjs/interceptors/delete-empty-id-from-body.interceptor.js +0 -40
  156. package/cjs/interceptors/delete-empty-id-from-body.interceptor.spec.js +0 -107
  157. package/cjs/interceptors/idempotency.interceptor.js +0 -96
  158. package/cjs/interceptors/idempotency.interceptor.spec.js +0 -116
  159. package/cjs/interceptors/index.js +0 -22
  160. package/cjs/interceptors/response-meta.interceptor.js +0 -47
  161. package/cjs/interceptors/response-meta.interceptor.spec.js +0 -89
  162. package/cjs/interceptors/set-user-field-on-body.interceptor.js +0 -60
  163. package/cjs/interceptors/set-user-field-on-body.interceptor.spec.js +0 -128
  164. package/cjs/interceptors/slug.interceptor.js +0 -75
  165. package/cjs/interceptors/slug.interceptor.spec.js +0 -110
  166. package/cjs/interfaces/ai-assistant-adapter.interface.js +0 -24
  167. package/cjs/interfaces/api.interface.js +0 -4
  168. package/cjs/interfaces/datasource.interface.js +0 -4
  169. package/cjs/interfaces/event-bus.interface.js +0 -4
  170. package/cjs/interfaces/event-manager-adapter.interface.js +0 -11
  171. package/cjs/interfaces/identity.interface.js +0 -4
  172. package/cjs/interfaces/index.js +0 -28
  173. package/cjs/interfaces/logged-user-info.interface.js +0 -6
  174. package/cjs/interfaces/module-config.interface.js +0 -4
  175. package/cjs/interfaces/notification-adapter.interface.js +0 -11
  176. package/cjs/interfaces/permission-sync-adapter.interface.js +0 -11
  177. package/cjs/interfaces/permission.interface.js +0 -4
  178. package/cjs/middlewares/index.js +0 -18
  179. package/cjs/middlewares/logger.middleware.js +0 -264
  180. package/cjs/middlewares/logger.middleware.spec.js +0 -462
  181. package/cjs/modules/cache/cache.module.js +0 -39
  182. package/cjs/modules/cache/cache.module.spec.js +0 -48
  183. package/cjs/modules/datasource/index.js +0 -18
  184. package/cjs/modules/datasource/multi-tenant-datasource.service.js +0 -222
  185. package/cjs/modules/datasource/multi-tenant-datasource.service.spec.js +0 -381
  186. package/cjs/modules/event-bus/event-bus.explorer.js +0 -124
  187. package/cjs/modules/event-bus/event-bus.explorer.spec.js +0 -189
  188. package/cjs/modules/event-bus/event-bus.integration.spec.js +0 -253
  189. package/cjs/modules/event-bus/event-bus.module.js +0 -94
  190. package/cjs/modules/event-bus/event-bus.module.spec.js +0 -149
  191. package/cjs/modules/event-bus/module-events.provider.js +0 -39
  192. package/cjs/modules/event-bus/module-events.provider.spec.js +0 -56
  193. package/cjs/modules/index.js +0 -26
  194. package/cjs/modules/shared-permission-cache/shared-permission-cache.module.js +0 -32
  195. package/cjs/modules/shared-permission-cache/shared-permission-cache.service.js +0 -101
  196. package/cjs/modules/shared-permission-cache/shared-permission-cache.service.spec.js +0 -165
  197. package/cjs/modules/utils/utils.module.js +0 -32
  198. package/cjs/modules/utils/utils.service.js +0 -76
  199. package/cjs/modules/utils/utils.service.spec.js +0 -169
  200. package/cjs/utils/date-time.util.js +0 -94
  201. package/cjs/utils/date-time.util.spec.js +0 -84
  202. package/cjs/utils/event-pattern.util.js +0 -103
  203. package/cjs/utils/event-pattern.util.spec.js +0 -251
  204. package/cjs/utils/html-sanitizer.util.js +0 -64
  205. package/cjs/utils/html-sanitizer.util.spec.js +0 -76
  206. package/cjs/utils/index.js +0 -25
  207. package/cjs/utils/optional-module.util.js +0 -35
  208. package/cjs/utils/optional-module.util.spec.js +0 -14
  209. package/cjs/utils/permission-cache-key.util.js +0 -31
  210. package/cjs/utils/permission-cache-key.util.spec.js +0 -88
  211. package/cjs/utils/query-helpers.util.js +0 -60
  212. package/cjs/utils/query-helpers.util.spec.js +0 -209
  213. package/cjs/utils/request.util.js +0 -96
  214. package/cjs/utils/request.util.spec.js +0 -249
  215. package/cjs/utils/string.util.js +0 -63
  216. package/cjs/utils/string.util.spec.js +0 -63
  217. package/fesm/classes/api-controller.class.js +0 -718
  218. package/fesm/classes/api-controller.class.spec.js +0 -680
  219. package/fesm/classes/api-service.class.js +0 -621
  220. package/fesm/classes/api-service.class.spec.js +0 -1133
  221. package/fesm/classes/disabled-event-bus.class.js +0 -11
  222. package/fesm/classes/disabled-event-bus.class.spec.js +0 -36
  223. package/fesm/classes/domain-event.publisher.js +0 -63
  224. package/fesm/classes/domain-event.publisher.spec.js +0 -230
  225. package/fesm/classes/event-bus.registry.js +0 -64
  226. package/fesm/classes/event-bus.registry.spec.js +0 -137
  227. package/fesm/classes/event-transports/event-transport.registry.js +0 -35
  228. package/fesm/classes/event-transports/event-transport.registry.spec.js +0 -27
  229. package/fesm/classes/event-transports/index.js +0 -6
  230. package/fesm/classes/event-transports/kafka-transport.optional.spec.js +0 -194
  231. package/fesm/classes/event-transports/memory-transport.js +0 -49
  232. package/fesm/classes/event-transports/memory-transport.spec.js +0 -53
  233. package/fesm/classes/event-transports/rabbitmq-transport.optional.js +0 -174
  234. package/fesm/classes/event-transports/rabbitmq-transport.optional.spec.js +0 -251
  235. package/fesm/classes/handle-custome-db.js +0 -19
  236. package/fesm/classes/handle-custome-db.spec.js +0 -78
  237. package/fesm/classes/hybrid-cache.class.js +0 -81
  238. package/fesm/classes/hybrid-cache.class.spec.js +0 -164
  239. package/fesm/classes/hybrid-event-bus.class.js +0 -237
  240. package/fesm/classes/hybrid-event-bus.class.spec.js +0 -214
  241. package/fesm/classes/winston.logger.class.js +0 -228
  242. package/fesm/classes/winston.logger.class.spec.js +0 -327
  243. package/fesm/constants/message-keys.js +0 -49
  244. package/fesm/constants/permissions.js +0 -215
  245. package/fesm/decorators/api-response.decorator.js +0 -42
  246. package/fesm/decorators/api-response.decorator.spec.js +0 -122
  247. package/fesm/decorators/current-user.decorator.js +0 -18
  248. package/fesm/decorators/current-user.decorator.spec.js +0 -73
  249. package/fesm/decorators/log-action.decorator.js +0 -139
  250. package/fesm/decorators/log-action.decorator.spec.js +0 -349
  251. package/fesm/decorators/on-domain-event.decorator.js +0 -10
  252. package/fesm/decorators/on-domain-event.decorator.spec.js +0 -46
  253. package/fesm/decorators/public.decorator.js +0 -20
  254. package/fesm/decorators/public.decorator.spec.js +0 -46
  255. package/fesm/decorators/require-permission.decorator.js +0 -27
  256. package/fesm/decorators/require-permission.decorator.spec.js +0 -143
  257. package/fesm/dtos/delete.dto.js +0 -82
  258. package/fesm/dtos/filter-and-pagination.dto.js +0 -148
  259. package/fesm/dtos/get-by-ids.dto.js +0 -55
  260. package/fesm/dtos/identity-response.dto.js +0 -98
  261. package/fesm/dtos/pagination.dto.js +0 -57
  262. package/fesm/dtos/response-payload.dto.js +0 -336
  263. package/fesm/entities/identity.js +0 -90
  264. package/fesm/entities/raw-type.js +0 -1
  265. package/fesm/entities/user-root.js +0 -179
  266. package/fesm/enums/notification-type.enum.js +0 -7
  267. package/fesm/enums/participant-status.enum.js +0 -7
  268. package/fesm/enums/recurrence-type.enum.js +0 -8
  269. package/fesm/exceptions/base-app.exception.js +0 -115
  270. package/fesm/exceptions/base-app.exception.spec.js +0 -153
  271. package/fesm/exceptions/permission.exception.js +0 -35
  272. package/fesm/exceptions/permission.exception.spec.js +0 -78
  273. package/fesm/filters/global-exception.filter.js +0 -269
  274. package/fesm/filters/global-exception.filter.spec.js +0 -436
  275. package/fesm/filters/index.js +0 -1
  276. package/fesm/guards/jwt-auth.guard.js +0 -65
  277. package/fesm/guards/jwt-auth.guard.spec.js +0 -71
  278. package/fesm/guards/optional-jwt-auth.guard.js +0 -57
  279. package/fesm/guards/optional-jwt-auth.guard.spec.js +0 -51
  280. package/fesm/guards/permission.guard.js +0 -169
  281. package/fesm/guards/permission.guard.spec.js +0 -369
  282. package/fesm/interceptors/delete-empty-id-from-body.interceptor.js +0 -30
  283. package/fesm/interceptors/delete-empty-id-from-body.interceptor.spec.js +0 -103
  284. package/fesm/interceptors/idempotency.interceptor.js +0 -86
  285. package/fesm/interceptors/idempotency.interceptor.spec.js +0 -112
  286. package/fesm/interceptors/response-meta.interceptor.js +0 -37
  287. package/fesm/interceptors/response-meta.interceptor.spec.js +0 -85
  288. package/fesm/interceptors/set-user-field-on-body.interceptor.js +0 -39
  289. package/fesm/interceptors/set-user-field-on-body.interceptor.spec.js +0 -124
  290. package/fesm/interceptors/slug.interceptor.js +0 -65
  291. package/fesm/interceptors/slug.interceptor.spec.js +0 -106
  292. package/fesm/interfaces/ai-assistant-adapter.interface.js +0 -3
  293. package/fesm/interfaces/api.interface.js +0 -1
  294. package/fesm/interfaces/datasource.interface.js +0 -1
  295. package/fesm/interfaces/event-bus.interface.js +0 -1
  296. package/fesm/interfaces/event-manager-adapter.interface.js +0 -1
  297. package/fesm/interfaces/identity.interface.js +0 -1
  298. package/fesm/interfaces/logged-user-info.interface.js +0 -3
  299. package/fesm/interfaces/module-config.interface.js +0 -5
  300. package/fesm/interfaces/notification-adapter.interface.js +0 -1
  301. package/fesm/interfaces/permission-sync-adapter.interface.js +0 -1
  302. package/fesm/interfaces/permission.interface.js +0 -1
  303. package/fesm/middlewares/logger.middleware.js +0 -235
  304. package/fesm/middlewares/logger.middleware.spec.js +0 -459
  305. package/fesm/modules/cache/cache.module.js +0 -29
  306. package/fesm/modules/cache/cache.module.spec.js +0 -44
  307. package/fesm/modules/datasource/index.js +0 -1
  308. package/fesm/modules/datasource/multi-tenant-datasource.service.js +0 -212
  309. package/fesm/modules/datasource/multi-tenant-datasource.service.spec.js +0 -377
  310. package/fesm/modules/event-bus/event-bus.explorer.js +0 -114
  311. package/fesm/modules/event-bus/event-bus.explorer.spec.js +0 -185
  312. package/fesm/modules/event-bus/event-bus.integration.spec.js +0 -249
  313. package/fesm/modules/event-bus/event-bus.module.js +0 -84
  314. package/fesm/modules/event-bus/event-bus.module.spec.js +0 -145
  315. package/fesm/modules/event-bus/module-events.provider.js +0 -26
  316. package/fesm/modules/event-bus/module-events.provider.spec.js +0 -52
  317. package/fesm/modules/shared-permission-cache/shared-permission-cache.module.js +0 -22
  318. package/fesm/modules/shared-permission-cache/shared-permission-cache.service.js +0 -91
  319. package/fesm/modules/shared-permission-cache/shared-permission-cache.service.spec.js +0 -161
  320. package/fesm/modules/utils/utils.module.js +0 -22
  321. package/fesm/modules/utils/utils.service.js +0 -66
  322. package/fesm/modules/utils/utils.service.spec.js +0 -165
  323. package/fesm/utils/date-time.util.js +0 -70
  324. package/fesm/utils/date-time.util.spec.js +0 -80
  325. package/fesm/utils/event-pattern.util.js +0 -91
  326. package/fesm/utils/event-pattern.util.spec.js +0 -247
  327. package/fesm/utils/html-sanitizer.util.js +0 -69
  328. package/fesm/utils/html-sanitizer.util.spec.js +0 -72
  329. package/fesm/utils/optional-module.util.js +0 -25
  330. package/fesm/utils/optional-module.util.spec.js +0 -10
  331. package/fesm/utils/permission-cache-key.util.js +0 -10
  332. package/fesm/utils/permission-cache-key.util.spec.js +0 -84
  333. package/fesm/utils/query-helpers.util.js +0 -85
  334. package/fesm/utils/query-helpers.util.spec.js +0 -205
  335. package/fesm/utils/request.util.js +0 -81
  336. package/fesm/utils/request.util.spec.js +0 -245
  337. package/fesm/utils/string.util.js +0 -71
  338. package/fesm/utils/string.util.spec.js +0 -59
@@ -1,327 +0,0 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
14
- const mockExistsSync = jest.fn();
15
- const mockMkdirSync = jest.fn();
16
- jest.mock('fs', ()=>({
17
- existsSync: (...args)=>mockExistsSync(...args),
18
- mkdirSync: (...args)=>mockMkdirSync(...args)
19
- }));
20
- const mockGetLogConfig = jest.fn();
21
- const mockUseTenantMode = jest.fn();
22
- const mockIsProduction = jest.fn();
23
- jest.mock('@flusys/nestjs-core/config', ()=>({
24
- envConfig: {
25
- getLogConfig: (...args)=>mockGetLogConfig(...args),
26
- useTenantMode: (...args)=>mockUseTenantMode(...args),
27
- isProduction: (...args)=>mockIsProduction(...args)
28
- }
29
- }));
30
- const { EventEmitter } = require('events');
31
- let FakeDailyRotateFile = class FakeDailyRotateFile extends EventEmitter {
32
- constructor(options){
33
- super(), _define_property(this, "options", void 0), _define_property(this, "log", jest.fn((_info, callback)=>callback?.()));
34
- this.options = options;
35
- }
36
- };
37
- jest.mock('winston-daily-rotate-file', ()=>({
38
- __esModule: true,
39
- default: FakeDailyRotateFile
40
- }));
41
- let capturedPrintf;
42
- jest.mock('winston', ()=>{
43
- const actual = jest.requireActual('winston');
44
- // winston's `format` export exposes its sub-formatters (colorize, combine, printf, ...)
45
- // as non-enumerable getters, so a plain object spread silently drops them. Delegate through
46
- // the prototype chain instead and only shadow `printf` to capture the formatter callback.
47
- const realPrintf = actual.format.printf;
48
- const mockFormat = Object.create(actual.format);
49
- Object.defineProperty(mockFormat, 'printf', {
50
- value: (fn)=>{
51
- capturedPrintf = fn;
52
- return realPrintf(fn);
53
- }
54
- });
55
- return {
56
- ...actual,
57
- format: mockFormat
58
- };
59
- });
60
- describe('winston.logger.class', ()=>{
61
- let consoleErrorSpy;
62
- beforeEach(()=>{
63
- jest.resetModules();
64
- jest.clearAllMocks();
65
- // FakeDailyRotateFile isn't a real winston-transport instance, so winston logs a
66
- // harmless "legacy transport" deprecation warning via console.error on each createLogger call.
67
- consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(()=>undefined);
68
- mockExistsSync.mockReturnValue(true);
69
- mockGetLogConfig.mockReturnValue({
70
- dir: 'logs',
71
- level: 'debug',
72
- maxSize: '20m',
73
- maxFiles: '14d',
74
- disableHttpLogging: false
75
- });
76
- mockUseTenantMode.mockReturnValue(false);
77
- });
78
- afterEach(()=>{
79
- consoleErrorSpy.mockRestore();
80
- });
81
- it('should create the log directory when it does not exist', ()=>{
82
- mockExistsSync.mockReturnValue(false);
83
- mockIsProduction.mockReturnValue(false);
84
- require('./winston.logger.class');
85
- expect(mockMkdirSync).toHaveBeenCalledWith('logs', {
86
- recursive: true
87
- });
88
- });
89
- it('should not attempt to create the log directory when it already exists', ()=>{
90
- mockExistsSync.mockReturnValue(true);
91
- mockIsProduction.mockReturnValue(false);
92
- require('./winston.logger.class');
93
- expect(mockMkdirSync).not.toHaveBeenCalledWith('logs', {
94
- recursive: true
95
- });
96
- });
97
- it('should export a dev (console-based) instance when not in production', ()=>{
98
- mockIsProduction.mockReturnValue(false);
99
- const { instance } = require('./winston.logger.class');
100
- expect(instance).toBeDefined();
101
- expect(typeof instance.log).toBe('function');
102
- });
103
- it('should export a prod (file-rotation-based) instance when in production', ()=>{
104
- mockIsProduction.mockReturnValue(true);
105
- const { instance } = require('./winston.logger.class');
106
- expect(instance).toBeDefined();
107
- expect(typeof instance.log).toBe('function');
108
- });
109
- describe('createModuleLogger', ()=>{
110
- it('should return the shared dev logger instance in non-production mode', ()=>{
111
- mockIsProduction.mockReturnValue(false);
112
- const { createModuleLogger, instance } = require('./winston.logger.class');
113
- expect(createModuleLogger('auth')).toBe(instance);
114
- expect(createModuleLogger('iam')).toBe(instance);
115
- });
116
- it('should create a distinct, cached logger per module in production mode', ()=>{
117
- mockIsProduction.mockReturnValue(true);
118
- const { createModuleLogger } = require('./winston.logger.class');
119
- const authLogger1 = createModuleLogger('auth');
120
- const authLogger2 = createModuleLogger('auth');
121
- const iamLogger = createModuleLogger('iam');
122
- expect(authLogger1).toBe(authLogger2);
123
- expect(authLogger1).not.toBe(iamLogger);
124
- });
125
- it('should create the module-specific log directory on first use in production mode', ()=>{
126
- mockIsProduction.mockReturnValue(true);
127
- mockExistsSync.mockImplementation((p)=>p === 'logs');
128
- const { createModuleLogger } = require('./winston.logger.class');
129
- createModuleLogger('storage');
130
- expect(mockMkdirSync).toHaveBeenCalledWith(expect.stringContaining('storage'), {
131
- recursive: true
132
- });
133
- });
134
- it('should not recreate the module directory or transport on subsequent calls', ()=>{
135
- mockIsProduction.mockReturnValue(true);
136
- mockExistsSync.mockReturnValue(true);
137
- const { createModuleLogger } = require('./winston.logger.class');
138
- createModuleLogger('storage');
139
- const mkdirCallsAfterFirst = mockMkdirSync.mock.calls.length;
140
- createModuleLogger('storage');
141
- expect(mockMkdirSync.mock.calls.length).toBe(mkdirCallsAfterFirst);
142
- });
143
- });
144
- describe('structuredFormat (captured printf callback)', ()=>{
145
- beforeEach(()=>{
146
- mockIsProduction.mockReturnValue(true);
147
- capturedPrintf = undefined;
148
- require('./winston.logger.class');
149
- });
150
- it('should capture the printf formatter', ()=>{
151
- expect(capturedPrintf).toBeInstanceOf(Function);
152
- });
153
- it('should default the request id when absent and map known levels', ()=>{
154
- const out = capturedPrintf({
155
- timestamp: 'T',
156
- level: 'error',
157
- message: 'boom'
158
- });
159
- expect(out).toContain('[no-request-id]');
160
- expect(out).toContain('Error');
161
- });
162
- it('should use the provided requestId and title-case unknown levels', ()=>{
163
- const out = capturedPrintf({
164
- timestamp: 'T',
165
- level: 'silly',
166
- message: 'x',
167
- requestId: 'req-1'
168
- });
169
- expect(out).toContain('[req-1]');
170
- expect(out).toContain('Silly');
171
- });
172
- it('should render context, endpoint, status, duration and user/tenant/company parts', ()=>{
173
- const out = capturedPrintf({
174
- timestamp: 'T',
175
- level: 'info',
176
- message: 'handled',
177
- context: 'AuthService',
178
- method: 'POST',
179
- path: '/login',
180
- statusCode: 200,
181
- duration: '12ms',
182
- userId: 'u1',
183
- tenantId: 't1',
184
- companyId: 'c1'
185
- });
186
- expect(out).toContain('Context: AuthService');
187
- expect(out).toContain('Endpoint: POST /login');
188
- expect(out).toContain('Status: 200');
189
- expect(out).toContain('Duration: 12ms');
190
- expect(out).toContain('UserId: u1');
191
- expect(out).toContain('TenantId: t1');
192
- expect(out).toContain('CompanyId: c1');
193
- expect(out).toContain('handled');
194
- });
195
- it('should fall back to `url` for the endpoint line when `path` is absent', ()=>{
196
- const out = capturedPrintf({
197
- timestamp: 'T',
198
- level: 'info',
199
- message: 'm',
200
- method: 'GET',
201
- url: '/legacy'
202
- });
203
- expect(out).toContain('Endpoint: GET /legacy');
204
- });
205
- it('should omit the endpoint line entirely when method has no path or url', ()=>{
206
- const out = capturedPrintf({
207
- timestamp: 'T',
208
- level: 'info',
209
- message: 'm',
210
- method: 'GET'
211
- });
212
- expect(out).not.toContain('Endpoint:');
213
- });
214
- it('should append remaining metadata as JSON, excluding the `splat` key', ()=>{
215
- const out = capturedPrintf({
216
- timestamp: 'T',
217
- level: 'info',
218
- message: 'm',
219
- splat: [
220
- 'ignored'
221
- ],
222
- orderId: 'o1',
223
- amount: 50
224
- });
225
- expect(out).toContain('Metadata: {"orderId":"o1","amount":50}');
226
- expect(out).not.toContain('ignored');
227
- });
228
- it('should omit the Metadata line when no extra metadata remains', ()=>{
229
- const out = capturedPrintf({
230
- timestamp: 'T',
231
- level: 'info',
232
- message: 'm',
233
- splat: []
234
- });
235
- expect(out).not.toContain('Metadata:');
236
- });
237
- it('should append the stack trace when present', ()=>{
238
- const out = capturedPrintf({
239
- timestamp: 'T',
240
- level: 'error',
241
- message: 'crashed',
242
- stack: 'Error: crashed\n at foo.ts:1:1'
243
- });
244
- expect(out).toContain('Stack: Error: crashed');
245
- });
246
- });
247
- describe('TenantAwareTransport routing', ()=>{
248
- it('should route to the default transport when tenant mode is disabled', ()=>{
249
- mockIsProduction.mockReturnValue(true);
250
- mockUseTenantMode.mockReturnValue(false);
251
- const { instance } = require('./winston.logger.class');
252
- const tenantAwareTransport = instance.transports[0];
253
- const defaultTransport = tenantAwareTransport.defaultTransport;
254
- const logSpy = jest.spyOn(defaultTransport, 'log');
255
- const cb = jest.fn();
256
- tenantAwareTransport.log({
257
- level: 'info',
258
- message: 'x',
259
- tenantId: 't1'
260
- }, cb);
261
- expect(logSpy).toHaveBeenCalled();
262
- });
263
- it('should route to the default transport when tenant mode is enabled but no tenantId is present', ()=>{
264
- mockIsProduction.mockReturnValue(true);
265
- mockUseTenantMode.mockReturnValue(true);
266
- const { instance } = require('./winston.logger.class');
267
- const tenantAwareTransport = instance.transports[0];
268
- const defaultTransport = tenantAwareTransport.defaultTransport;
269
- const logSpy = jest.spyOn(defaultTransport, 'log');
270
- const cb = jest.fn();
271
- tenantAwareTransport.log({
272
- level: 'info',
273
- message: 'x'
274
- }, cb);
275
- expect(logSpy).toHaveBeenCalled();
276
- });
277
- it('should route to a tenant-specific transport when tenant mode is enabled and tenantId is present', ()=>{
278
- mockIsProduction.mockReturnValue(true);
279
- mockUseTenantMode.mockReturnValue(true);
280
- mockExistsSync.mockReturnValue(true);
281
- const { instance } = require('./winston.logger.class');
282
- const tenantAwareTransport = instance.transports[0];
283
- const defaultTransport = tenantAwareTransport.defaultTransport;
284
- const defaultLogSpy = jest.spyOn(defaultTransport, 'log');
285
- const cb = jest.fn();
286
- tenantAwareTransport.log({
287
- level: 'info',
288
- message: 'x',
289
- tenantId: 'tenant-a'
290
- }, cb);
291
- expect(defaultLogSpy).not.toHaveBeenCalled();
292
- });
293
- it('should read tenantId from nested `metadata.tenantId` when top-level tenantId is absent', ()=>{
294
- mockIsProduction.mockReturnValue(true);
295
- mockUseTenantMode.mockReturnValue(true);
296
- mockExistsSync.mockReturnValue(true);
297
- const { instance } = require('./winston.logger.class');
298
- const tenantAwareTransport = instance.transports[0];
299
- const defaultTransport = tenantAwareTransport.defaultTransport;
300
- const defaultLogSpy = jest.spyOn(defaultTransport, 'log');
301
- const cb = jest.fn();
302
- tenantAwareTransport.log({
303
- level: 'info',
304
- message: 'x',
305
- metadata: {
306
- tenantId: 'tenant-b'
307
- }
308
- }, cb);
309
- expect(defaultLogSpy).not.toHaveBeenCalled();
310
- });
311
- it('should re-emit "logged" so winston can track transport completion', (done)=>{
312
- mockIsProduction.mockReturnValue(true);
313
- mockUseTenantMode.mockReturnValue(false);
314
- const { instance } = require('./winston.logger.class');
315
- const tenantAwareTransport = instance.transports[0];
316
- tenantAwareTransport.once('logged', (info)=>{
317
- expect(info.message).toBe('done-check');
318
- done();
319
- });
320
- tenantAwareTransport.log({
321
- level: 'info',
322
- message: 'done-check'
323
- }, jest.fn());
324
- });
325
- });
326
- });
327
- export { };
@@ -1,49 +0,0 @@
1
- // ==================== AUTH (Shared across guards/interceptors) ====================
2
- // These are duplicated in nestjs-auth but needed here to avoid circular dependencies
3
- export const AUTH_MESSAGES = {
4
- TOKEN_REQUIRED: 'auth.token.required',
5
- TOKEN_INVALID: 'auth.token.invalid',
6
- ENTITY_BELOG_ANOTHER_COMPANY: 'entity.belongs.another.company',
7
- COMPANY_NO_ACCESS: 'auth.company.no.access'
8
- };
9
- // ==================== ERROR (HTTP Exceptions) ====================
10
- export const ERROR_MESSAGES = {
11
- NOT_FOUND: 'error.not.found',
12
- VALIDATION: 'error.validation',
13
- UNAUTHORIZED: 'error.unauthorized',
14
- FORBIDDEN: 'error.forbidden',
15
- CONFLICT: 'error.conflict',
16
- DB_FOREIGN_KEY: 'error.db.foreign.key',
17
- DB_NOT_NULL: 'error.db.not.null',
18
- DB_INVALID_INPUT: 'error.db.invalid.input',
19
- DB_VALUE_TOO_LONG: 'error.db.value.too.long',
20
- DB_CHECK_CONSTRAINT: 'error.db.check.constraint',
21
- DB_DEADLOCK: 'error.db.deadlock',
22
- INTERNAL: 'error.internal',
23
- SERVICE_UNAVAILABLE: 'error.service.unavailable',
24
- UNKNOWN: 'error.unknown',
25
- HTTP: 'error.http',
26
- GENERIC: 'error.generic',
27
- PERMISSION_SYSTEM_UNAVAILABLE: 'error.permission.system.unavailable',
28
- INSUFFICIENT_PERMISSIONS: 'error.insufficient.permissions',
29
- INSUFFICIENT_PERMISSIONS_OR: 'error.insufficient.permissions.or',
30
- NO_PERMISSIONS_FOUND: 'error.no.permissions.found',
31
- ENDPOINT_DISABLED: 'error.endpoint.disabled'
32
- };
33
- // ==================== SYSTEM (Infrastructure) ====================
34
- export const SYSTEM_MESSAGES = {
35
- REPOSITORY_NOT_AVAILABLE: 'system.repository.not.available',
36
- DATASOURCE_NOT_AVAILABLE: 'system.datasource.not.available',
37
- DATABASE_CONFIG_NOT_AVAILABLE: 'system.database.config.not.available',
38
- SERVICE_NOT_AVAILABLE: 'system.service.not.available',
39
- CONFIG_REQUIRED: 'system.config.required',
40
- INTERNAL_ERROR: 'system.internal.error',
41
- DUPLICATE_REQUEST: 'system.duplicate.request',
42
- INVALID_TENANT_ID: 'system.invalid.tenant.id',
43
- TENANT_NOT_FOUND: 'system.tenant.not.found',
44
- TENANT_HEADER_REQUIRED: 'system.tenant.header.required',
45
- MISSING_PARAMETER: 'system.missing.parameter',
46
- SDK_NOT_INSTALLED: 'system.sdk.not.installed',
47
- PATH_TRAVERSAL_DETECTED: 'system.path.traversal.detected',
48
- INVALID_FILE_KEY: 'system.invalid.file.key'
49
- };
@@ -1,215 +0,0 @@
1
- // ==================== AUTH MODULE ====================
2
- export const USER_PERMISSIONS = {
3
- CREATE: 'user.create',
4
- READ: 'user.read',
5
- UPDATE: 'user.update',
6
- DELETE: 'user.delete',
7
- LOOKUP: 'user.lookup'
8
- };
9
- export const COMPANY_PERMISSIONS = {
10
- CREATE: 'company.create',
11
- READ: 'company.read',
12
- UPDATE: 'company.update',
13
- DELETE: 'company.delete'
14
- };
15
- export const BRANCH_PERMISSIONS = {
16
- CREATE: 'branch.create',
17
- READ: 'branch.read',
18
- UPDATE: 'branch.update',
19
- DELETE: 'branch.delete'
20
- };
21
- export const SOCIAL_AUTH_CONFIG_PERMISSIONS = {
22
- CREATE: 'social-config.create',
23
- READ: 'social-config.read',
24
- UPDATE: 'social-config.update',
25
- DELETE: 'social-config.delete'
26
- };
27
- // ==================== IAM MODULE ====================
28
- export const ACTION_PERMISSIONS = {
29
- CREATE: 'action.create',
30
- READ: 'action.read',
31
- UPDATE: 'action.update',
32
- DELETE: 'action.delete'
33
- };
34
- export const ROLE_PERMISSIONS = {
35
- CREATE: 'role.create',
36
- READ: 'role.read',
37
- UPDATE: 'role.update',
38
- DELETE: 'role.delete'
39
- };
40
- export const ROLE_ACTION_PERMISSIONS = {
41
- READ: 'role-action.read',
42
- ASSIGN: 'role-action.assign'
43
- };
44
- export const USER_ROLE_PERMISSIONS = {
45
- READ: 'user-role.read',
46
- ASSIGN: 'user-role.assign'
47
- };
48
- export const USER_ACTION_PERMISSIONS = {
49
- READ: 'user-action.read',
50
- ASSIGN: 'user-action.assign'
51
- };
52
- export const COMPANY_ACTION_PERMISSIONS = {
53
- READ: 'company-action.read',
54
- ASSIGN: 'company-action.assign'
55
- };
56
- // ==================== STORAGE MODULE ====================
57
- export const FILE_PERMISSIONS = {
58
- CREATE: 'file.create',
59
- READ: 'file.read',
60
- UPDATE: 'file.update',
61
- DELETE: 'file.delete',
62
- VIEW_PRIVATE_ACTION: 'file.view.private'
63
- };
64
- export const FOLDER_PERMISSIONS = {
65
- CREATE: 'folder.create',
66
- READ: 'folder.read',
67
- UPDATE: 'folder.update',
68
- DELETE: 'folder.delete'
69
- };
70
- export const STORAGE_CONFIG_PERMISSIONS = {
71
- CREATE: 'storage-config.create',
72
- READ: 'storage-config.read',
73
- UPDATE: 'storage-config.update',
74
- DELETE: 'storage-config.delete'
75
- };
76
- export const UPLOAD_CONFIG_PERMISSIONS = {
77
- DELETE: 'upload-config.delete'
78
- };
79
- // ==================== EMAIL MODULE ====================
80
- export const EMAIL_CONFIG_PERMISSIONS = {
81
- CREATE: 'email-config.create',
82
- READ: 'email-config.read',
83
- UPDATE: 'email-config.update',
84
- DELETE: 'email-config.delete'
85
- };
86
- export const EMAIL_TEMPLATE_PERMISSIONS = {
87
- CREATE: 'email-template.create',
88
- READ: 'email-template.read',
89
- UPDATE: 'email-template.update',
90
- DELETE: 'email-template.delete'
91
- };
92
- // ==================== FORM BUILDER MODULE ====================
93
- export const FORM_PERMISSIONS = {
94
- CREATE: 'form.create',
95
- READ: 'form.read',
96
- UPDATE: 'form.update',
97
- DELETE: 'form.delete'
98
- };
99
- export const FORM_RESULT_PERMISSIONS = {
100
- CREATE: 'form-result.create',
101
- READ: 'form-result.read',
102
- UPDATE: 'form-result.update',
103
- DELETE: 'form-result.delete'
104
- };
105
- // ==================== EVENT MANAGER MODULE ====================
106
- export const EVENT_PERMISSIONS = {
107
- CREATE: 'event.create',
108
- READ: 'event.read',
109
- UPDATE: 'event.update',
110
- DELETE: 'event.delete'
111
- };
112
- // ==================== NOTIFICATION MODULE ====================
113
- export const NOTIFICATION_PERMISSIONS = {
114
- CREATE: 'notification.create',
115
- READ: 'notification.read',
116
- UPDATE: 'notification.update',
117
- DELETE: 'notification.delete'
118
- };
119
- // ==================== LOCALIZATION MODULE ====================
120
- export const LANGUAGE_PERMISSIONS = {
121
- CREATE: 'language.create',
122
- READ: 'language.read',
123
- UPDATE: 'language.update',
124
- DELETE: 'language.delete'
125
- };
126
- export const TRANSLATION_KEY_PERMISSIONS = {
127
- CREATE: 'translation-key.create',
128
- READ: 'translation-key.read',
129
- UPDATE: 'translation-key.update',
130
- DELETE: 'translation-key.delete'
131
- };
132
- export const TRANSLATION_PERMISSIONS = {
133
- CREATE: 'translation.create',
134
- READ: 'translation.read',
135
- UPDATE: 'translation.update',
136
- DELETE: 'translation.delete'
137
- };
138
- // ==================== TASK MANAGER MODULE ====================
139
- export const TASK_BOARD_PERMISSIONS = {
140
- CREATE: 'task-board.create',
141
- READ: 'task-board.read',
142
- UPDATE: 'task-board.update',
143
- DELETE: 'task-board.delete',
144
- MANAGE_MEMBERS: 'task-board.manage-members'
145
- };
146
- export const TASK_LIST_PERMISSIONS = {
147
- CREATE: 'task-list.create',
148
- READ: 'task-list.read',
149
- UPDATE: 'task-list.update',
150
- DELETE: 'task-list.delete'
151
- };
152
- export const TASK_PERMISSIONS = {
153
- CREATE: 'task.create',
154
- READ: 'task.read',
155
- UPDATE: 'task.update',
156
- DELETE: 'task.delete',
157
- MOVE: 'task.move',
158
- ASSIGN: 'task.assign'
159
- };
160
- export const TASK_LABEL_PERMISSIONS = {
161
- CREATE: 'task-label.create',
162
- READ: 'task-label.read',
163
- UPDATE: 'task-label.update',
164
- DELETE: 'task-label.delete'
165
- };
166
- export const TASK_COMMENT_PERMISSIONS = {
167
- CREATE: 'task-comment.create',
168
- READ: 'task-comment.read',
169
- DELETE: 'task-comment.delete'
170
- };
171
- // ==================== AI ASSISTANT MODULE ====================
172
- export const AI_ASSISTANT_PERMISSIONS = {
173
- VIEW_ALL_HISTORY: 'ai-assistant.view-all-history'
174
- };
175
- // ==================== AGGREGATED EXPORTS ====================
176
- export const PERMISSIONS = {
177
- // Auth
178
- USER: USER_PERMISSIONS,
179
- COMPANY: COMPANY_PERMISSIONS,
180
- BRANCH: BRANCH_PERMISSIONS,
181
- SOCIAL_AUTH_CONFIG: SOCIAL_AUTH_CONFIG_PERMISSIONS,
182
- // IAM
183
- ACTION: ACTION_PERMISSIONS,
184
- ROLE: ROLE_PERMISSIONS,
185
- ROLE_ACTION: ROLE_ACTION_PERMISSIONS,
186
- USER_ROLE: USER_ROLE_PERMISSIONS,
187
- USER_ACTION: USER_ACTION_PERMISSIONS,
188
- COMPANY_ACTION: COMPANY_ACTION_PERMISSIONS,
189
- // Storage
190
- FILE: FILE_PERMISSIONS,
191
- FOLDER: FOLDER_PERMISSIONS,
192
- STORAGE_CONFIG: STORAGE_CONFIG_PERMISSIONS,
193
- // Email
194
- EMAIL_CONFIG: EMAIL_CONFIG_PERMISSIONS,
195
- EMAIL_TEMPLATE: EMAIL_TEMPLATE_PERMISSIONS,
196
- // Form Builder
197
- FORM: FORM_PERMISSIONS,
198
- FORM_RESULT: FORM_RESULT_PERMISSIONS,
199
- // Event Manager
200
- EVENT: EVENT_PERMISSIONS,
201
- // Notification
202
- NOTIFICATION: NOTIFICATION_PERMISSIONS,
203
- // Localization
204
- LANGUAGE: LANGUAGE_PERMISSIONS,
205
- TRANSLATION_KEY: TRANSLATION_KEY_PERMISSIONS,
206
- TRANSLATION: TRANSLATION_PERMISSIONS,
207
- // Task Manager
208
- TASK_BOARD: TASK_BOARD_PERMISSIONS,
209
- TASK_LIST: TASK_LIST_PERMISSIONS,
210
- TASK: TASK_PERMISSIONS,
211
- TASK_LABEL: TASK_LABEL_PERMISSIONS,
212
- TASK_COMMENT: TASK_COMMENT_PERMISSIONS,
213
- // AI Assistant
214
- AI_ASSISTANT: AI_ASSISTANT_PERMISSIONS
215
- };
@@ -1,42 +0,0 @@
1
- import { BulkMetaDto, BulkResponseDto, ListResponseDto, PaginationMetaDto, SingleResponseDto } from '../dtos';
2
- import { applyDecorators } from '@nestjs/common';
3
- import { ApiExtraModels, ApiOkResponse, getSchemaPath } from '@nestjs/swagger';
4
- export const ApiResponseDto = (dto, isArray = false, arrayType = 'list')=>{
5
- let wrapperDto;
6
- let metaDto = null;
7
- if (!isArray || arrayType === 'single') {
8
- wrapperDto = SingleResponseDto;
9
- } else if (arrayType === 'bulk') {
10
- wrapperDto = BulkResponseDto;
11
- metaDto = BulkMetaDto;
12
- } else {
13
- wrapperDto = ListResponseDto;
14
- metaDto = PaginationMetaDto;
15
- }
16
- return applyDecorators(ApiExtraModels(SingleResponseDto, ListResponseDto, BulkResponseDto, PaginationMetaDto, BulkMetaDto, dto), ApiOkResponse({
17
- schema: {
18
- allOf: [
19
- {
20
- $ref: getSchemaPath(wrapperDto)
21
- },
22
- {
23
- properties: {
24
- data: isArray ? {
25
- type: 'array',
26
- items: {
27
- $ref: getSchemaPath(dto)
28
- }
29
- } : {
30
- $ref: getSchemaPath(dto)
31
- },
32
- ...metaDto ? {
33
- meta: {
34
- $ref: getSchemaPath(metaDto)
35
- }
36
- } : {}
37
- }
38
- }
39
- ]
40
- }
41
- }));
42
- };