@flusys/nestjs-shared 7.0.2 → 8.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) 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/constants/permissions.d.ts +12 -0
  15. package/decorators/api-response.decorator.d.ts +1 -1
  16. package/decorators/current-user.decorator.d.ts +1 -1
  17. package/decorators/index.d.ts +6 -6
  18. package/decorators/require-permission.decorator.d.ts +1 -1
  19. package/dtos/filter-and-pagination.dto.d.ts +1 -1
  20. package/dtos/index.d.ts +6 -6
  21. package/entities/index.d.ts +3 -3
  22. package/enums/index.d.ts +3 -3
  23. package/exceptions/index.d.ts +2 -2
  24. package/fesm/470.js +2713 -0
  25. package/fesm/509.js +793 -0
  26. package/fesm/667.js +606 -0
  27. package/fesm/67.js +808 -0
  28. package/fesm/720.js +914 -0
  29. package/{cjs/classes/event-transports/rabbitmq-transport.optional.js → fesm/chunks/123.js} +78 -55
  30. package/fesm/{classes/event-transports/kafka-transport.optional.js → chunks/37.js} +74 -41
  31. package/fesm/classes/index.js +62 -12
  32. package/fesm/constants/index.js +445 -17
  33. package/fesm/decorators/index.js +341 -6
  34. package/fesm/dtos/index.js +23 -6
  35. package/fesm/entities/index.js +336 -3
  36. package/fesm/enums/index.js +57 -3
  37. package/fesm/exceptions/index.js +280 -2
  38. package/fesm/guards/index.js +1003 -3
  39. package/fesm/index.js +1524 -14
  40. package/fesm/interceptors/index.js +924 -5
  41. package/fesm/interfaces/index.js +57 -11
  42. package/fesm/middlewares/index.js +33 -1
  43. package/fesm/modules/index.js +432 -9
  44. package/fesm/runtime.js +134 -0
  45. package/fesm/utils/index.js +1045 -8
  46. package/filters/global-exception.filter.d.ts +1 -1
  47. package/filters/index.d.ts +1 -1
  48. package/guards/index.d.ts +3 -3
  49. package/guards/jwt-auth.guard.d.ts +1 -1
  50. package/guards/optional-jwt-auth.guard.d.ts +1 -1
  51. package/guards/permission.guard.d.ts +2 -2
  52. package/index.d.ts +14 -14
  53. package/interceptors/delete-empty-id-from-body.interceptor.d.ts +1 -1
  54. package/interceptors/idempotency.interceptor.d.ts +2 -2
  55. package/interceptors/index.d.ts +5 -5
  56. package/interceptors/response-meta.interceptor.d.ts +1 -1
  57. package/interceptors/set-user-field-on-body.interceptor.d.ts +1 -1
  58. package/interceptors/slug.interceptor.d.ts +2 -2
  59. package/interfaces/ai-assistant-adapter.interface.d.ts +1 -1
  60. package/interfaces/api.interface.d.ts +2 -2
  61. package/interfaces/datasource.interface.d.ts +1 -1
  62. package/interfaces/event-manager-adapter.interface.d.ts +2 -2
  63. package/interfaces/index.d.ts +11 -11
  64. package/interfaces/module-config.interface.d.ts +1 -1
  65. package/interfaces/notification-adapter.interface.d.ts +1 -1
  66. package/middlewares/index.d.ts +1 -1
  67. package/middlewares/logger.middleware.d.ts +2 -2
  68. package/modules/cache/cache.module.d.ts +1 -1
  69. package/modules/datasource/index.d.ts +1 -1
  70. package/modules/datasource/multi-tenant-datasource.service.d.ts +4 -4
  71. package/modules/event-bus/event-bus.explorer.d.ts +2 -2
  72. package/modules/event-bus/event-bus.module.d.ts +2 -2
  73. package/modules/event-bus/module-events.provider.d.ts +1 -1
  74. package/modules/index.d.ts +9 -9
  75. package/modules/shared-permission-cache/shared-permission-cache.service.d.ts +3 -3
  76. package/modules/utils/utils.service.d.ts +1 -1
  77. package/package.json +30 -44
  78. package/utils/index.d.ts +8 -8
  79. package/utils/permission-cache-key.util.d.ts +1 -1
  80. package/utils/query-helpers.util.d.ts +2 -2
  81. package/utils/request.util.d.ts +1 -1
  82. package/cjs/classes/api-controller.class.js +0 -728
  83. package/cjs/classes/api-controller.class.spec.js +0 -684
  84. package/cjs/classes/api-service.class.js +0 -631
  85. package/cjs/classes/api-service.class.spec.js +0 -1137
  86. package/cjs/classes/disabled-event-bus.class.js +0 -15
  87. package/cjs/classes/disabled-event-bus.class.spec.js +0 -40
  88. package/cjs/classes/domain-event.publisher.js +0 -76
  89. package/cjs/classes/domain-event.publisher.spec.js +0 -234
  90. package/cjs/classes/event-bus.registry.js +0 -68
  91. package/cjs/classes/event-bus.registry.spec.js +0 -141
  92. package/cjs/classes/event-transports/event-transport.registry.js +0 -41
  93. package/cjs/classes/event-transports/event-transport.registry.spec.js +0 -31
  94. package/cjs/classes/event-transports/index.js +0 -23
  95. package/cjs/classes/event-transports/kafka-transport.optional.js +0 -151
  96. package/cjs/classes/event-transports/kafka-transport.optional.spec.js +0 -198
  97. package/cjs/classes/event-transports/memory-transport.js +0 -53
  98. package/cjs/classes/event-transports/memory-transport.spec.js +0 -57
  99. package/cjs/classes/event-transports/rabbitmq-transport.optional.spec.js +0 -255
  100. package/cjs/classes/handle-custome-db.js +0 -37
  101. package/cjs/classes/handle-custome-db.spec.js +0 -82
  102. package/cjs/classes/hybrid-cache.class.js +0 -96
  103. package/cjs/classes/hybrid-cache.class.spec.js +0 -168
  104. package/cjs/classes/hybrid-event-bus.class.js +0 -281
  105. package/cjs/classes/hybrid-event-bus.class.spec.js +0 -218
  106. package/cjs/classes/index.js +0 -28
  107. package/cjs/classes/winston.logger.class.js +0 -274
  108. package/cjs/classes/winston.logger.class.spec.js +0 -330
  109. package/cjs/constants/index.js +0 -88
  110. package/cjs/constants/message-keys.js +0 -68
  111. package/cjs/constants/permissions.js +0 -297
  112. package/cjs/decorators/api-response.decorator.js +0 -52
  113. package/cjs/decorators/api-response.decorator.spec.js +0 -126
  114. package/cjs/decorators/current-user.decorator.js +0 -16
  115. package/cjs/decorators/current-user.decorator.spec.js +0 -74
  116. package/cjs/decorators/index.js +0 -23
  117. package/cjs/decorators/log-action.decorator.js +0 -149
  118. package/cjs/decorators/log-action.decorator.spec.js +0 -353
  119. package/cjs/decorators/on-domain-event.decorator.js +0 -13
  120. package/cjs/decorators/on-domain-event.decorator.spec.js +0 -50
  121. package/cjs/decorators/public.decorator.js +0 -13
  122. package/cjs/decorators/public.decorator.spec.js +0 -50
  123. package/cjs/decorators/require-permission.decorator.js +0 -32
  124. package/cjs/decorators/require-permission.decorator.spec.js +0 -147
  125. package/cjs/dtos/delete.dto.js +0 -92
  126. package/cjs/dtos/filter-and-pagination.dto.js +0 -164
  127. package/cjs/dtos/get-by-ids.dto.js +0 -65
  128. package/cjs/dtos/identity-response.dto.js +0 -108
  129. package/cjs/dtos/index.js +0 -23
  130. package/cjs/dtos/pagination.dto.js +0 -67
  131. package/cjs/dtos/response-payload.dto.js +0 -369
  132. package/cjs/entities/identity.js +0 -100
  133. package/cjs/entities/index.js +0 -20
  134. package/cjs/entities/raw-type.js +0 -4
  135. package/cjs/entities/user-root.js +0 -189
  136. package/cjs/enums/index.js +0 -20
  137. package/cjs/enums/notification-type.enum.js +0 -17
  138. package/cjs/enums/participant-status.enum.js +0 -17
  139. package/cjs/enums/recurrence-type.enum.js +0 -18
  140. package/cjs/exceptions/base-app.exception.js +0 -151
  141. package/cjs/exceptions/base-app.exception.spec.js +0 -157
  142. package/cjs/exceptions/index.js +0 -19
  143. package/cjs/exceptions/permission.exception.js +0 -56
  144. package/cjs/exceptions/permission.exception.spec.js +0 -82
  145. package/cjs/filters/global-exception.filter.js +0 -279
  146. package/cjs/filters/global-exception.filter.spec.js +0 -440
  147. package/cjs/filters/index.js +0 -18
  148. package/cjs/guards/index.js +0 -20
  149. package/cjs/guards/jwt-auth.guard.js +0 -75
  150. package/cjs/guards/jwt-auth.guard.spec.js +0 -75
  151. package/cjs/guards/optional-jwt-auth.guard.js +0 -67
  152. package/cjs/guards/optional-jwt-auth.guard.spec.js +0 -55
  153. package/cjs/guards/permission.guard.js +0 -179
  154. package/cjs/guards/permission.guard.spec.js +0 -373
  155. package/cjs/index.js +0 -31
  156. package/cjs/interceptors/delete-empty-id-from-body.interceptor.js +0 -40
  157. package/cjs/interceptors/delete-empty-id-from-body.interceptor.spec.js +0 -107
  158. package/cjs/interceptors/idempotency.interceptor.js +0 -96
  159. package/cjs/interceptors/idempotency.interceptor.spec.js +0 -116
  160. package/cjs/interceptors/index.js +0 -22
  161. package/cjs/interceptors/response-meta.interceptor.js +0 -47
  162. package/cjs/interceptors/response-meta.interceptor.spec.js +0 -89
  163. package/cjs/interceptors/set-user-field-on-body.interceptor.js +0 -60
  164. package/cjs/interceptors/set-user-field-on-body.interceptor.spec.js +0 -128
  165. package/cjs/interceptors/slug.interceptor.js +0 -75
  166. package/cjs/interceptors/slug.interceptor.spec.js +0 -110
  167. package/cjs/interfaces/ai-assistant-adapter.interface.js +0 -24
  168. package/cjs/interfaces/api.interface.js +0 -4
  169. package/cjs/interfaces/datasource.interface.js +0 -4
  170. package/cjs/interfaces/event-bus.interface.js +0 -4
  171. package/cjs/interfaces/event-manager-adapter.interface.js +0 -11
  172. package/cjs/interfaces/identity.interface.js +0 -4
  173. package/cjs/interfaces/index.js +0 -28
  174. package/cjs/interfaces/logged-user-info.interface.js +0 -6
  175. package/cjs/interfaces/module-config.interface.js +0 -4
  176. package/cjs/interfaces/notification-adapter.interface.js +0 -11
  177. package/cjs/interfaces/permission-sync-adapter.interface.js +0 -11
  178. package/cjs/interfaces/permission.interface.js +0 -4
  179. package/cjs/middlewares/index.js +0 -18
  180. package/cjs/middlewares/logger.middleware.js +0 -264
  181. package/cjs/middlewares/logger.middleware.spec.js +0 -462
  182. package/cjs/modules/cache/cache.module.js +0 -39
  183. package/cjs/modules/cache/cache.module.spec.js +0 -48
  184. package/cjs/modules/datasource/index.js +0 -18
  185. package/cjs/modules/datasource/multi-tenant-datasource.service.js +0 -222
  186. package/cjs/modules/datasource/multi-tenant-datasource.service.spec.js +0 -381
  187. package/cjs/modules/event-bus/event-bus.explorer.js +0 -124
  188. package/cjs/modules/event-bus/event-bus.explorer.spec.js +0 -189
  189. package/cjs/modules/event-bus/event-bus.integration.spec.js +0 -253
  190. package/cjs/modules/event-bus/event-bus.module.js +0 -94
  191. package/cjs/modules/event-bus/event-bus.module.spec.js +0 -149
  192. package/cjs/modules/event-bus/module-events.provider.js +0 -39
  193. package/cjs/modules/event-bus/module-events.provider.spec.js +0 -56
  194. package/cjs/modules/index.js +0 -26
  195. package/cjs/modules/shared-permission-cache/shared-permission-cache.module.js +0 -32
  196. package/cjs/modules/shared-permission-cache/shared-permission-cache.service.js +0 -101
  197. package/cjs/modules/shared-permission-cache/shared-permission-cache.service.spec.js +0 -165
  198. package/cjs/modules/utils/utils.module.js +0 -32
  199. package/cjs/modules/utils/utils.service.js +0 -76
  200. package/cjs/modules/utils/utils.service.spec.js +0 -169
  201. package/cjs/utils/date-time.util.js +0 -94
  202. package/cjs/utils/date-time.util.spec.js +0 -84
  203. package/cjs/utils/event-pattern.util.js +0 -103
  204. package/cjs/utils/event-pattern.util.spec.js +0 -251
  205. package/cjs/utils/html-sanitizer.util.js +0 -64
  206. package/cjs/utils/html-sanitizer.util.spec.js +0 -76
  207. package/cjs/utils/index.js +0 -25
  208. package/cjs/utils/optional-module.util.js +0 -35
  209. package/cjs/utils/optional-module.util.spec.js +0 -14
  210. package/cjs/utils/permission-cache-key.util.js +0 -31
  211. package/cjs/utils/permission-cache-key.util.spec.js +0 -88
  212. package/cjs/utils/query-helpers.util.js +0 -60
  213. package/cjs/utils/query-helpers.util.spec.js +0 -209
  214. package/cjs/utils/request.util.js +0 -96
  215. package/cjs/utils/request.util.spec.js +0 -249
  216. package/cjs/utils/string.util.js +0 -63
  217. package/cjs/utils/string.util.spec.js +0 -63
  218. package/fesm/classes/api-controller.class.js +0 -718
  219. package/fesm/classes/api-controller.class.spec.js +0 -680
  220. package/fesm/classes/api-service.class.js +0 -621
  221. package/fesm/classes/api-service.class.spec.js +0 -1133
  222. package/fesm/classes/disabled-event-bus.class.js +0 -11
  223. package/fesm/classes/disabled-event-bus.class.spec.js +0 -36
  224. package/fesm/classes/domain-event.publisher.js +0 -63
  225. package/fesm/classes/domain-event.publisher.spec.js +0 -230
  226. package/fesm/classes/event-bus.registry.js +0 -64
  227. package/fesm/classes/event-bus.registry.spec.js +0 -137
  228. package/fesm/classes/event-transports/event-transport.registry.js +0 -35
  229. package/fesm/classes/event-transports/event-transport.registry.spec.js +0 -27
  230. package/fesm/classes/event-transports/index.js +0 -6
  231. package/fesm/classes/event-transports/kafka-transport.optional.spec.js +0 -194
  232. package/fesm/classes/event-transports/memory-transport.js +0 -49
  233. package/fesm/classes/event-transports/memory-transport.spec.js +0 -53
  234. package/fesm/classes/event-transports/rabbitmq-transport.optional.js +0 -174
  235. package/fesm/classes/event-transports/rabbitmq-transport.optional.spec.js +0 -251
  236. package/fesm/classes/handle-custome-db.js +0 -19
  237. package/fesm/classes/handle-custome-db.spec.js +0 -78
  238. package/fesm/classes/hybrid-cache.class.js +0 -81
  239. package/fesm/classes/hybrid-cache.class.spec.js +0 -164
  240. package/fesm/classes/hybrid-event-bus.class.js +0 -237
  241. package/fesm/classes/hybrid-event-bus.class.spec.js +0 -214
  242. package/fesm/classes/winston.logger.class.js +0 -228
  243. package/fesm/classes/winston.logger.class.spec.js +0 -327
  244. package/fesm/constants/message-keys.js +0 -49
  245. package/fesm/constants/permissions.js +0 -208
  246. package/fesm/decorators/api-response.decorator.js +0 -42
  247. package/fesm/decorators/api-response.decorator.spec.js +0 -122
  248. package/fesm/decorators/current-user.decorator.js +0 -18
  249. package/fesm/decorators/current-user.decorator.spec.js +0 -73
  250. package/fesm/decorators/log-action.decorator.js +0 -139
  251. package/fesm/decorators/log-action.decorator.spec.js +0 -349
  252. package/fesm/decorators/on-domain-event.decorator.js +0 -10
  253. package/fesm/decorators/on-domain-event.decorator.spec.js +0 -46
  254. package/fesm/decorators/public.decorator.js +0 -20
  255. package/fesm/decorators/public.decorator.spec.js +0 -46
  256. package/fesm/decorators/require-permission.decorator.js +0 -27
  257. package/fesm/decorators/require-permission.decorator.spec.js +0 -143
  258. package/fesm/dtos/delete.dto.js +0 -82
  259. package/fesm/dtos/filter-and-pagination.dto.js +0 -148
  260. package/fesm/dtos/get-by-ids.dto.js +0 -55
  261. package/fesm/dtos/identity-response.dto.js +0 -98
  262. package/fesm/dtos/pagination.dto.js +0 -57
  263. package/fesm/dtos/response-payload.dto.js +0 -336
  264. package/fesm/entities/identity.js +0 -90
  265. package/fesm/entities/raw-type.js +0 -1
  266. package/fesm/entities/user-root.js +0 -179
  267. package/fesm/enums/notification-type.enum.js +0 -7
  268. package/fesm/enums/participant-status.enum.js +0 -7
  269. package/fesm/enums/recurrence-type.enum.js +0 -8
  270. package/fesm/exceptions/base-app.exception.js +0 -115
  271. package/fesm/exceptions/base-app.exception.spec.js +0 -153
  272. package/fesm/exceptions/permission.exception.js +0 -35
  273. package/fesm/exceptions/permission.exception.spec.js +0 -78
  274. package/fesm/filters/global-exception.filter.js +0 -269
  275. package/fesm/filters/global-exception.filter.spec.js +0 -436
  276. package/fesm/filters/index.js +0 -1
  277. package/fesm/guards/jwt-auth.guard.js +0 -65
  278. package/fesm/guards/jwt-auth.guard.spec.js +0 -71
  279. package/fesm/guards/optional-jwt-auth.guard.js +0 -57
  280. package/fesm/guards/optional-jwt-auth.guard.spec.js +0 -51
  281. package/fesm/guards/permission.guard.js +0 -169
  282. package/fesm/guards/permission.guard.spec.js +0 -369
  283. package/fesm/interceptors/delete-empty-id-from-body.interceptor.js +0 -30
  284. package/fesm/interceptors/delete-empty-id-from-body.interceptor.spec.js +0 -103
  285. package/fesm/interceptors/idempotency.interceptor.js +0 -86
  286. package/fesm/interceptors/idempotency.interceptor.spec.js +0 -112
  287. package/fesm/interceptors/response-meta.interceptor.js +0 -37
  288. package/fesm/interceptors/response-meta.interceptor.spec.js +0 -85
  289. package/fesm/interceptors/set-user-field-on-body.interceptor.js +0 -39
  290. package/fesm/interceptors/set-user-field-on-body.interceptor.spec.js +0 -124
  291. package/fesm/interceptors/slug.interceptor.js +0 -65
  292. package/fesm/interceptors/slug.interceptor.spec.js +0 -106
  293. package/fesm/interfaces/ai-assistant-adapter.interface.js +0 -3
  294. package/fesm/interfaces/api.interface.js +0 -1
  295. package/fesm/interfaces/datasource.interface.js +0 -1
  296. package/fesm/interfaces/event-bus.interface.js +0 -1
  297. package/fesm/interfaces/event-manager-adapter.interface.js +0 -1
  298. package/fesm/interfaces/identity.interface.js +0 -1
  299. package/fesm/interfaces/logged-user-info.interface.js +0 -3
  300. package/fesm/interfaces/module-config.interface.js +0 -5
  301. package/fesm/interfaces/notification-adapter.interface.js +0 -1
  302. package/fesm/interfaces/permission-sync-adapter.interface.js +0 -1
  303. package/fesm/interfaces/permission.interface.js +0 -1
  304. package/fesm/middlewares/logger.middleware.js +0 -235
  305. package/fesm/middlewares/logger.middleware.spec.js +0 -459
  306. package/fesm/modules/cache/cache.module.js +0 -29
  307. package/fesm/modules/cache/cache.module.spec.js +0 -44
  308. package/fesm/modules/datasource/index.js +0 -1
  309. package/fesm/modules/datasource/multi-tenant-datasource.service.js +0 -212
  310. package/fesm/modules/datasource/multi-tenant-datasource.service.spec.js +0 -377
  311. package/fesm/modules/event-bus/event-bus.explorer.js +0 -114
  312. package/fesm/modules/event-bus/event-bus.explorer.spec.js +0 -185
  313. package/fesm/modules/event-bus/event-bus.integration.spec.js +0 -249
  314. package/fesm/modules/event-bus/event-bus.module.js +0 -84
  315. package/fesm/modules/event-bus/event-bus.module.spec.js +0 -145
  316. package/fesm/modules/event-bus/module-events.provider.js +0 -26
  317. package/fesm/modules/event-bus/module-events.provider.spec.js +0 -52
  318. package/fesm/modules/shared-permission-cache/shared-permission-cache.module.js +0 -22
  319. package/fesm/modules/shared-permission-cache/shared-permission-cache.service.js +0 -91
  320. package/fesm/modules/shared-permission-cache/shared-permission-cache.service.spec.js +0 -161
  321. package/fesm/modules/utils/utils.module.js +0 -22
  322. package/fesm/modules/utils/utils.service.js +0 -66
  323. package/fesm/modules/utils/utils.service.spec.js +0 -165
  324. package/fesm/utils/date-time.util.js +0 -70
  325. package/fesm/utils/date-time.util.spec.js +0 -80
  326. package/fesm/utils/event-pattern.util.js +0 -91
  327. package/fesm/utils/event-pattern.util.spec.js +0 -247
  328. package/fesm/utils/html-sanitizer.util.js +0 -69
  329. package/fesm/utils/html-sanitizer.util.spec.js +0 -72
  330. package/fesm/utils/optional-module.util.js +0 -25
  331. package/fesm/utils/optional-module.util.spec.js +0 -10
  332. package/fesm/utils/permission-cache-key.util.js +0 -10
  333. package/fesm/utils/permission-cache-key.util.spec.js +0 -84
  334. package/fesm/utils/query-helpers.util.js +0 -85
  335. package/fesm/utils/query-helpers.util.spec.js +0 -205
  336. package/fesm/utils/request.util.js +0 -81
  337. package/fesm/utils/request.util.spec.js +0 -245
  338. package/fesm/utils/string.util.js +0 -71
  339. package/fesm/utils/string.util.spec.js +0 -59
@@ -1,11 +0,0 @@
1
- /**
2
- * Stands in for HybridEventBus when the subsystem is switched off.
3
- *
4
- * Injecting `EVENT_BUS_INSTANCE` keeps working, so turning events off cannot
5
- * break a provider's dependencies, but nothing here can ever open a broker
6
- * connection or run a handler.
7
- */ export class DisabledEventBus {
8
- async publish(_event) {}
9
- async subscribe(_pattern, _handler) {}
10
- async close() {}
11
- }
@@ -1,36 +0,0 @@
1
- import { DisabledEventBus } from './disabled-event-bus.class';
2
- describe('DisabledEventBus', ()=>{
3
- const event = {
4
- id: 'e1',
5
- name: 'auth.session.logged-in',
6
- module: 'auth',
7
- entity: 'session',
8
- action: 'logged-in',
9
- payload: {
10
- ids: [
11
- 'u1'
12
- ]
13
- },
14
- actor: {
15
- userId: 'u1',
16
- companyId: null,
17
- tenantId: null,
18
- requestId: null
19
- },
20
- occurredAt: new Date().toISOString(),
21
- version: 1
22
- };
23
- it('should never deliver an event to a subscriber', async ()=>{
24
- const bus = new DisabledEventBus();
25
- const handler = jest.fn();
26
- await bus.subscribe('**', handler);
27
- await bus.publish(event);
28
- expect(handler).not.toHaveBeenCalled();
29
- });
30
- it('should resolve without throwing so callers need no special case', async ()=>{
31
- const bus = new DisabledEventBus();
32
- await expect(bus.publish(event)).resolves.toBeUndefined();
33
- await expect(bus.subscribe('**', jest.fn())).resolves.toBeUndefined();
34
- await expect(bus.close()).resolves.toBeUndefined();
35
- });
36
- });
@@ -1,63 +0,0 @@
1
- import { randomUUID } from 'crypto';
2
- import { getCompanyId, getRequestId, getTenantId } from '../middlewares/logger.middleware';
3
- import { sanitizeEventPayload } from '../utils/event-pattern.util';
4
- import { EventBusRegistry } from './event-bus.registry';
5
- export const DOMAIN_EVENT_VERSION = 1;
6
- export function buildDomainEvent(input) {
7
- const rows = input.data === undefined ? [] : toArray(input.data);
8
- const ids = input.ids ?? collectIds(rows);
9
- return {
10
- id: randomUUID(),
11
- name: `${input.module}.${input.entity}.${input.action}`,
12
- module: input.module,
13
- entity: input.entity,
14
- action: input.action,
15
- payload: {
16
- ids,
17
- ...rows.length && EventBusRegistry.shouldIncludePayload(input.module) ? {
18
- data: sanitizeEventPayload(rows)
19
- } : {},
20
- ...input.metadata ? {
21
- metadata: sanitizeEventPayload(input.metadata)
22
- } : {}
23
- },
24
- actor: {
25
- userId: input.user?.id ?? null,
26
- companyId: input.user?.companyId ?? getCompanyId() ?? null,
27
- tenantId: getTenantId() ?? null,
28
- requestId: getRequestId() ?? null
29
- },
30
- occurredAt: new Date().toISOString(),
31
- version: DOMAIN_EVENT_VERSION
32
- };
33
- }
34
- /**
35
- * Publishes a domain event for an operation that is not plain CRUD - a form
36
- * submission, a login, a file upload. Honours the publishing module's own
37
- * `events` config and never throws, so a broker outage cannot break the caller.
38
- *
39
- * Supplying `eventBus` chooses which bus to publish on; it never overrides the
40
- * module's on/off switch, otherwise turning a module's events off would leave
41
- * every service holding its own bus still publishing.
42
- */ export async function publishDomainEvent(input) {
43
- const bus = input.eventBus ?? EventBusRegistry.getBus();
44
- if (!bus) return;
45
- if (!EventBusRegistry.isEnabled(input.module, input.entity, input.action)) return;
46
- try {
47
- await bus.publish(buildDomainEvent(input));
48
- } catch {
49
- // Events must never break the operation that produced them
50
- }
51
- }
52
- function toArray(value) {
53
- return Array.isArray(value) ? value : [
54
- value
55
- ];
56
- }
57
- function collectIds(rows) {
58
- return rows.reduce((ids, row)=>{
59
- const id = row?.id;
60
- if (id) ids.push(id);
61
- return ids;
62
- }, []);
63
- }
@@ -1,230 +0,0 @@
1
- import { buildDomainEvent, publishDomainEvent } from './domain-event.publisher';
2
- import { EventBusRegistry } from './event-bus.registry';
3
- const user = {
4
- id: 'user-1',
5
- email: 'ada@example.com',
6
- companyId: 'company-1'
7
- };
8
- describe('buildDomainEvent', ()=>{
9
- beforeEach(()=>{
10
- EventBusRegistry.reset();
11
- EventBusRegistry.configureModule('form-builder', {
12
- enabled: true
13
- });
14
- });
15
- afterEach(()=>{
16
- EventBusRegistry.reset();
17
- });
18
- it('should name the event <module>.<entity>.<action>', ()=>{
19
- const event = buildDomainEvent({
20
- module: 'form-builder',
21
- entity: 'form_result',
22
- action: 'submitted'
23
- });
24
- expect(event.name).toBe('form-builder.form_result.submitted');
25
- expect(event.version).toBe(1);
26
- expect(event.id).toEqual(expect.any(String));
27
- });
28
- it('should derive ids from the supplied rows when none are given', ()=>{
29
- const event = buildDomainEvent({
30
- module: 'form-builder',
31
- entity: 'form_result',
32
- action: 'submitted',
33
- data: [
34
- {
35
- id: 'a'
36
- },
37
- {
38
- id: 'b'
39
- }
40
- ]
41
- });
42
- expect(event.payload.ids).toEqual([
43
- 'a',
44
- 'b'
45
- ]);
46
- });
47
- it('should prefer explicitly supplied ids', ()=>{
48
- const event = buildDomainEvent({
49
- module: 'form-builder',
50
- entity: 'form_result',
51
- action: 'submitted',
52
- ids: [
53
- 'explicit'
54
- ],
55
- data: {
56
- id: 'ignored'
57
- }
58
- });
59
- expect(event.payload.ids).toEqual([
60
- 'explicit'
61
- ]);
62
- });
63
- it('should attach metadata regardless of the includePayload setting', ()=>{
64
- EventBusRegistry.configureModule('form-builder', {
65
- enabled: true,
66
- includePayload: false
67
- });
68
- const event = buildDomainEvent({
69
- module: 'form-builder',
70
- entity: 'form_result',
71
- action: 'submitted',
72
- data: {
73
- id: 'a',
74
- answer: 'secret-ish'
75
- },
76
- metadata: {
77
- formId: 'form-1',
78
- isDraft: false
79
- }
80
- });
81
- expect(event.payload.data).toBeUndefined();
82
- expect(event.payload.metadata).toEqual({
83
- formId: 'form-1',
84
- isDraft: false
85
- });
86
- });
87
- it('should redact credential-like fields from data and metadata', ()=>{
88
- const event = buildDomainEvent({
89
- module: 'form-builder',
90
- entity: 'form_result',
91
- action: 'submitted',
92
- data: {
93
- id: 'a',
94
- password: 'hunter2'
95
- },
96
- metadata: {
97
- token: 'abc'
98
- }
99
- });
100
- expect(event.payload.data).toEqual([
101
- {
102
- id: 'a',
103
- password: '[REDACTED]'
104
- }
105
- ]);
106
- expect(event.payload.metadata).toEqual({
107
- token: '[REDACTED]'
108
- });
109
- });
110
- it('should record the acting user', ()=>{
111
- const event = buildDomainEvent({
112
- module: 'form-builder',
113
- entity: 'form_result',
114
- action: 'submitted',
115
- user
116
- });
117
- expect(event.actor).toEqual(expect.objectContaining({
118
- userId: 'user-1',
119
- companyId: 'company-1'
120
- }));
121
- });
122
- });
123
- describe('publishDomainEvent', ()=>{
124
- let publish;
125
- beforeEach(()=>{
126
- publish = jest.fn().mockResolvedValue(undefined);
127
- EventBusRegistry.reset();
128
- EventBusRegistry.setBus({
129
- publish,
130
- subscribe: jest.fn(),
131
- close: jest.fn()
132
- });
133
- });
134
- afterEach(()=>{
135
- EventBusRegistry.reset();
136
- });
137
- it('should publish when the module has events enabled', async ()=>{
138
- EventBusRegistry.configureModule('auth', {
139
- enabled: true
140
- });
141
- await publishDomainEvent({
142
- module: 'auth',
143
- entity: 'session',
144
- action: 'logged-in'
145
- });
146
- expect(publish).toHaveBeenCalledWith(expect.objectContaining({
147
- name: 'auth.session.logged-in'
148
- }));
149
- });
150
- it('should stay silent when the module has events disabled', async ()=>{
151
- EventBusRegistry.configureModule('auth', {
152
- enabled: false
153
- });
154
- await publishDomainEvent({
155
- module: 'auth',
156
- entity: 'session',
157
- action: 'logged-in'
158
- });
159
- expect(publish).not.toHaveBeenCalled();
160
- });
161
- it('should honour an action allowlist that names a domain action', async ()=>{
162
- EventBusRegistry.configureModule('auth', {
163
- enabled: true,
164
- actions: [
165
- 'logged-in'
166
- ]
167
- });
168
- await publishDomainEvent({
169
- module: 'auth',
170
- entity: 'session',
171
- action: 'logged-in'
172
- });
173
- await publishDomainEvent({
174
- module: 'auth',
175
- entity: 'session',
176
- action: 'logged-out'
177
- });
178
- expect(publish).toHaveBeenCalledTimes(1);
179
- });
180
- it('should publish through an explicitly supplied bus instead of the registered one', async ()=>{
181
- const directPublish = jest.fn().mockResolvedValue(undefined);
182
- EventBusRegistry.configureModule('auth', {
183
- enabled: true
184
- });
185
- await publishDomainEvent({
186
- module: 'auth',
187
- entity: 'session',
188
- action: 'logged-in',
189
- eventBus: {
190
- publish: directPublish
191
- }
192
- });
193
- expect(directPublish).toHaveBeenCalled();
194
- expect(publish).not.toHaveBeenCalled();
195
- });
196
- it('should still respect the module switch when a bus is supplied explicitly', async ()=>{
197
- const directPublish = jest.fn().mockResolvedValue(undefined);
198
- EventBusRegistry.configureModule('auth', {
199
- enabled: false
200
- });
201
- await publishDomainEvent({
202
- module: 'auth',
203
- entity: 'session',
204
- action: 'logged-in',
205
- eventBus: {
206
- publish: directPublish
207
- }
208
- });
209
- expect(directPublish).not.toHaveBeenCalled();
210
- });
211
- it('should do nothing when no bus is registered', async ()=>{
212
- EventBusRegistry.reset();
213
- await expect(publishDomainEvent({
214
- module: 'auth',
215
- entity: 'session',
216
- action: 'logged-in'
217
- })).resolves.toBeUndefined();
218
- });
219
- it('should swallow a broker failure', async ()=>{
220
- EventBusRegistry.configureModule('auth', {
221
- enabled: true
222
- });
223
- publish.mockRejectedValue(new Error('broker down'));
224
- await expect(publishDomainEvent({
225
- module: 'auth',
226
- entity: 'session',
227
- action: 'logged-in'
228
- })).resolves.toBeUndefined();
229
- });
230
- });
@@ -1,64 +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
- import { matchEventPattern } from '../utils/event-pattern.util';
15
- const DISABLED = {
16
- enabled: false
17
- };
18
- /**
19
- * Ambient access point for the event bus.
20
- *
21
- * ApiService is request scoped and is extended by every feature package, so the
22
- * bus is resolved from here instead of being threaded through 20+ constructors.
23
- * Services may still receive a bus explicitly - that instance wins.
24
- */ export class EventBusRegistry {
25
- static setBus(bus) {
26
- this.bus = bus;
27
- }
28
- static getBus() {
29
- return this.bus;
30
- }
31
- static setDefaultModuleEvents(config) {
32
- this.defaultConfig = config ?? DISABLED;
33
- }
34
- /** Called by each feature module with the `events` block from its own config */ static configureModule(moduleName, config) {
35
- this.moduleConfigs.set(moduleName, config ?? DISABLED);
36
- }
37
- static getModuleConfig(moduleName) {
38
- if (!moduleName) return this.defaultConfig;
39
- return this.moduleConfigs.get(moduleName) ?? this.defaultConfig;
40
- }
41
- /**
42
- * Answers only "is this module configured to publish this" - whether a bus
43
- * exists is the publisher's concern, so an explicitly supplied bus is still
44
- * held to the module's own on/off switch.
45
- */ static isEnabled(moduleName, entity, action) {
46
- const config = this.getModuleConfig(moduleName);
47
- if (!config.enabled) return false;
48
- // Without an explicit allowlist, CRUD lifecycle actions and every domain
49
- // action a package defines are all published.
50
- if (!config.actions?.length) return true;
51
- return config.actions.some((entry)=>entry.includes('.') ? matchEventPattern(entry, `${entity}.${action}`) : matchEventPattern(entry, action));
52
- }
53
- static shouldIncludePayload(moduleName) {
54
- return this.getModuleConfig(moduleName).includePayload ?? true;
55
- }
56
- static reset() {
57
- this.bus = undefined;
58
- this.moduleConfigs.clear();
59
- this.defaultConfig = DISABLED;
60
- }
61
- }
62
- _define_property(EventBusRegistry, "bus", void 0);
63
- _define_property(EventBusRegistry, "moduleConfigs", new Map());
64
- _define_property(EventBusRegistry, "defaultConfig", DISABLED);
@@ -1,137 +0,0 @@
1
- import { EventBusRegistry } from './event-bus.registry';
2
- const bus = {
3
- publish: jest.fn(),
4
- subscribe: jest.fn(),
5
- close: jest.fn()
6
- };
7
- describe('EventBusRegistry', ()=>{
8
- beforeEach(()=>{
9
- EventBusRegistry.reset();
10
- EventBusRegistry.setBus(bus);
11
- });
12
- afterEach(()=>{
13
- EventBusRegistry.reset();
14
- });
15
- it('should expose the registered bus', ()=>{
16
- expect(EventBusRegistry.getBus()).toBe(bus);
17
- });
18
- it('should answer from the module config alone, independent of any registered bus', ()=>{
19
- EventBusRegistry.reset();
20
- EventBusRegistry.configureModule('storage', {
21
- enabled: true
22
- });
23
- expect(EventBusRegistry.getBus()).toBeUndefined();
24
- expect(EventBusRegistry.isEnabled('storage', 'folder', 'created')).toBe(true);
25
- });
26
- it('should report disabled for a module that never registered a config', ()=>{
27
- expect(EventBusRegistry.isEnabled('storage', 'folder', 'created')).toBe(false);
28
- });
29
- it('should enable every action of an enabled module by default', ()=>{
30
- EventBusRegistry.configureModule('storage', {
31
- enabled: true
32
- });
33
- expect(EventBusRegistry.isEnabled('storage', 'folder', 'created')).toBe(true);
34
- expect(EventBusRegistry.isEnabled('storage', 'folder', 'deleted')).toBe(true);
35
- });
36
- it('should honour an action allowlist', ()=>{
37
- EventBusRegistry.configureModule('storage', {
38
- enabled: true,
39
- actions: [
40
- 'created'
41
- ]
42
- });
43
- expect(EventBusRegistry.isEnabled('storage', 'folder', 'created')).toBe(true);
44
- expect(EventBusRegistry.isEnabled('storage', 'folder', 'updated')).toBe(false);
45
- });
46
- it('should honour an allowlist that mixes CRUD lifecycle and domain actions', ()=>{
47
- EventBusRegistry.configureModule('auth', {
48
- enabled: true,
49
- actions: [
50
- 'created',
51
- 'logged-in'
52
- ]
53
- });
54
- expect(EventBusRegistry.isEnabled('auth', 'appuser', 'created')).toBe(true);
55
- expect(EventBusRegistry.isEnabled('auth', 'session', 'logged-in')).toBe(true);
56
- expect(EventBusRegistry.isEnabled('auth', 'appuser', 'updated')).toBe(false);
57
- expect(EventBusRegistry.isEnabled('auth', 'session', 'logged-out')).toBe(false);
58
- });
59
- it('should silence CRUD when the allowlist names only domain actions', ()=>{
60
- EventBusRegistry.configureModule('auth', {
61
- enabled: true,
62
- actions: [
63
- 'logged-in'
64
- ]
65
- });
66
- expect(EventBusRegistry.isEnabled('auth', 'session', 'logged-in')).toBe(true);
67
- expect(EventBusRegistry.isEnabled('auth', 'appuser', 'created')).toBe(false);
68
- });
69
- it('should scope an action to one entity when the entry names it', ()=>{
70
- EventBusRegistry.configureModule('iam', {
71
- enabled: true,
72
- actions: [
73
- 'created',
74
- 'role.updated'
75
- ]
76
- });
77
- expect(EventBusRegistry.isEnabled('iam', 'role', 'updated')).toBe(true);
78
- expect(EventBusRegistry.isEnabled('iam', 'action', 'updated')).toBe(false);
79
- expect(EventBusRegistry.isEnabled('iam', 'action', 'created')).toBe(true);
80
- });
81
- it('should treat a scoped entry as a routing pattern', ()=>{
82
- EventBusRegistry.configureModule('iam', {
83
- enabled: true,
84
- actions: [
85
- 'role.*',
86
- '*.purged'
87
- ]
88
- });
89
- expect(EventBusRegistry.isEnabled('iam', 'role', 'updated')).toBe(true);
90
- expect(EventBusRegistry.isEnabled('iam', 'role', 'permissions-assigned')).toBe(true);
91
- expect(EventBusRegistry.isEnabled('iam', 'action', 'purged')).toBe(true);
92
- expect(EventBusRegistry.isEnabled('iam', 'action', 'updated')).toBe(false);
93
- });
94
- it('should publish only the entity and action pairs an app lists', ()=>{
95
- EventBusRegistry.configureModule('auth', {
96
- enabled: true,
97
- actions: [
98
- 'company.created',
99
- 'company.updated',
100
- 'session.logged-in'
101
- ]
102
- });
103
- expect(EventBusRegistry.isEnabled('auth', 'company', 'created')).toBe(true);
104
- expect(EventBusRegistry.isEnabled('auth', 'company', 'updated')).toBe(true);
105
- expect(EventBusRegistry.isEnabled('auth', 'company', 'purged')).toBe(false);
106
- expect(EventBusRegistry.isEnabled('auth', 'appuser', 'created')).toBe(false);
107
- expect(EventBusRegistry.isEnabled('auth', 'session', 'logged-in')).toBe(true);
108
- expect(EventBusRegistry.isEnabled('auth', 'session', 'logged-out')).toBe(false);
109
- });
110
- it('should fall back to the default config for unregistered modules', ()=>{
111
- EventBusRegistry.setDefaultModuleEvents({
112
- enabled: true
113
- });
114
- expect(EventBusRegistry.isEnabled('unknown-module', 'thing', 'created')).toBe(true);
115
- });
116
- it('should include the payload unless a module opts out', ()=>{
117
- EventBusRegistry.configureModule('storage', {
118
- enabled: true
119
- });
120
- EventBusRegistry.configureModule('auth', {
121
- enabled: true,
122
- includePayload: false
123
- });
124
- expect(EventBusRegistry.shouldIncludePayload('storage')).toBe(true);
125
- expect(EventBusRegistry.shouldIncludePayload('auth')).toBe(false);
126
- });
127
- it('should clear everything on reset', ()=>{
128
- EventBusRegistry.configureModule('storage', {
129
- enabled: true
130
- });
131
- EventBusRegistry.reset();
132
- expect(EventBusRegistry.getBus()).toBeUndefined();
133
- expect(EventBusRegistry.getModuleConfig('storage')).toEqual({
134
- enabled: false
135
- });
136
- });
137
- });
@@ -1,35 +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
- /**
15
- * Static registry for event transports.
16
- * Broker transports register themselves on import so nestjs-shared never has to
17
- * depend on `amqplib` or `kafkajs` at build time.
18
- */ export class EventTransportRegistry {
19
- static register(name, factory) {
20
- this.transports.set(name.toLowerCase(), factory);
21
- }
22
- static get(name) {
23
- return this.transports.get(name.toLowerCase());
24
- }
25
- static has(name) {
26
- return this.transports.has(name.toLowerCase());
27
- }
28
- static getAll() {
29
- return Array.from(this.transports.keys());
30
- }
31
- static clear() {
32
- this.transports.clear();
33
- }
34
- }
35
- _define_property(EventTransportRegistry, "transports", new Map());
@@ -1,27 +0,0 @@
1
- import { EventTransportRegistry } from './event-transport.registry';
2
- const stubTransport = {};
3
- describe('EventTransportRegistry', ()=>{
4
- afterEach(()=>{
5
- EventTransportRegistry.clear();
6
- });
7
- it('should register and resolve a transport factory', ()=>{
8
- EventTransportRegistry.register('rabbitmq', ()=>stubTransport);
9
- expect(EventTransportRegistry.get('rabbitmq')({})).toBe(stubTransport);
10
- });
11
- it('should resolve case insensitively', ()=>{
12
- EventTransportRegistry.register('Kafka', ()=>stubTransport);
13
- expect(EventTransportRegistry.has('kafka')).toBe(true);
14
- });
15
- it('should return undefined for an unknown transport', ()=>{
16
- expect(EventTransportRegistry.get('nats')).toBeUndefined();
17
- expect(EventTransportRegistry.has('nats')).toBe(false);
18
- });
19
- it('should list every registered transport', ()=>{
20
- EventTransportRegistry.register('memory', ()=>stubTransport);
21
- EventTransportRegistry.register('kafka', ()=>stubTransport);
22
- expect(EventTransportRegistry.getAll().sort()).toEqual([
23
- 'kafka',
24
- 'memory'
25
- ]);
26
- });
27
- });
@@ -1,6 +0,0 @@
1
- export * from './event-transport.registry';
2
- // Built-in transport (no external dependencies)
3
- export * from './memory-transport'; // Note: Broker transports are loaded dynamically by HybridEventBus.
4
- // Import them directly when registering manually:
5
- // - import { RabbitMqTransport } from '@flusys/nestjs-shared/classes/event-transports/rabbitmq-transport.optional';
6
- // - import { KafkaTransport } from '@flusys/nestjs-shared/classes/event-transports/kafka-transport.optional';