@carlonicora/nestjs-neo4jsonapi 6.6.1 → 6.7.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 (289) hide show
  1. package/dist/agents/operator/controllers/operator.controller.d.ts.map +1 -1
  2. package/dist/agents/operator/controllers/operator.controller.js +3 -0
  3. package/dist/agents/operator/controllers/operator.controller.js.map +1 -1
  4. package/dist/bootstrap/app.module.factory.d.ts.map +1 -1
  5. package/dist/bootstrap/app.module.factory.js +9 -0
  6. package/dist/bootstrap/app.module.factory.js.map +1 -1
  7. package/dist/bootstrap/bootstrap.options.d.ts +19 -0
  8. package/dist/bootstrap/bootstrap.options.d.ts.map +1 -1
  9. package/dist/common/constants/core-module.ids.d.ts +39 -0
  10. package/dist/common/constants/core-module.ids.d.ts.map +1 -0
  11. package/dist/common/constants/core-module.ids.js +41 -0
  12. package/dist/common/constants/core-module.ids.js.map +1 -0
  13. package/dist/common/decorators/index.d.ts +1 -0
  14. package/dist/common/decorators/index.d.ts.map +1 -1
  15. package/dist/common/decorators/index.js +1 -0
  16. package/dist/common/decorators/index.js.map +1 -1
  17. package/dist/common/decorators/module.decorator.d.ts +19 -0
  18. package/dist/common/decorators/module.decorator.d.ts.map +1 -1
  19. package/dist/common/decorators/module.decorator.js +8 -2
  20. package/dist/common/decorators/module.decorator.js.map +1 -1
  21. package/dist/common/decorators/token-scopes.decorator.d.ts +14 -0
  22. package/dist/common/decorators/token-scopes.decorator.d.ts.map +1 -0
  23. package/dist/common/decorators/token-scopes.decorator.js +18 -0
  24. package/dist/common/decorators/token-scopes.decorator.js.map +1 -0
  25. package/dist/common/guards/index.d.ts +1 -0
  26. package/dist/common/guards/index.d.ts.map +1 -1
  27. package/dist/common/guards/index.js +1 -0
  28. package/dist/common/guards/index.js.map +1 -1
  29. package/dist/common/guards/jwt.auth.admin.guard.d.ts +3 -1
  30. package/dist/common/guards/jwt.auth.admin.guard.d.ts.map +1 -1
  31. package/dist/common/guards/jwt.auth.admin.guard.js +28 -7
  32. package/dist/common/guards/jwt.auth.admin.guard.js.map +1 -1
  33. package/dist/common/guards/jwt.auth.any-scope.guard.d.ts +10 -3
  34. package/dist/common/guards/jwt.auth.any-scope.guard.d.ts.map +1 -1
  35. package/dist/common/guards/jwt.auth.any-scope.guard.js +17 -4
  36. package/dist/common/guards/jwt.auth.any-scope.guard.js.map +1 -1
  37. package/dist/common/guards/jwt.auth.guard.d.ts +3 -1
  38. package/dist/common/guards/jwt.auth.guard.d.ts.map +1 -1
  39. package/dist/common/guards/jwt.auth.guard.js +30 -8
  40. package/dist/common/guards/jwt.auth.guard.js.map +1 -1
  41. package/dist/common/guards/jwt.auth.optional.guard.d.ts +3 -1
  42. package/dist/common/guards/jwt.auth.optional.guard.d.ts.map +1 -1
  43. package/dist/common/guards/jwt.auth.optional.guard.js +32 -8
  44. package/dist/common/guards/jwt.auth.optional.guard.js.map +1 -1
  45. package/dist/common/guards/session.token.d.ts +50 -0
  46. package/dist/common/guards/session.token.d.ts.map +1 -0
  47. package/dist/common/guards/session.token.js +71 -0
  48. package/dist/common/guards/session.token.js.map +1 -0
  49. package/dist/common/index.d.ts +1 -0
  50. package/dist/common/index.d.ts.map +1 -1
  51. package/dist/common/index.js +1 -0
  52. package/dist/common/index.js.map +1 -1
  53. package/dist/common/strategies/jwt.strategy.d.ts +8 -0
  54. package/dist/common/strategies/jwt.strategy.d.ts.map +1 -1
  55. package/dist/common/strategies/jwt.strategy.js +8 -0
  56. package/dist/common/strategies/jwt.strategy.js.map +1 -1
  57. package/dist/core/websocket/gateways/event.gateway.d.ts.map +1 -1
  58. package/dist/core/websocket/gateways/event.gateway.js +12 -1
  59. package/dist/core/websocket/gateways/event.gateway.js.map +1 -1
  60. package/dist/core/websocket/guards/ws.jwt.auth.guard.d.ts.map +1 -1
  61. package/dist/core/websocket/guards/ws.jwt.auth.guard.js +4 -0
  62. package/dist/core/websocket/guards/ws.jwt.auth.guard.js.map +1 -1
  63. package/dist/foundations/ai-connection/controllers/ai-connection.controller.d.ts.map +1 -1
  64. package/dist/foundations/ai-connection/controllers/ai-connection.controller.js +4 -0
  65. package/dist/foundations/ai-connection/controllers/ai-connection.controller.js.map +1 -1
  66. package/dist/foundations/analytics/controllers/analytics.admin.controller.d.ts.map +1 -1
  67. package/dist/foundations/analytics/controllers/analytics.admin.controller.js +3 -0
  68. package/dist/foundations/analytics/controllers/analytics.admin.controller.js.map +1 -1
  69. package/dist/foundations/analytics/controllers/analytics.controller.d.ts.map +1 -1
  70. package/dist/foundations/analytics/controllers/analytics.controller.js +3 -0
  71. package/dist/foundations/analytics/controllers/analytics.controller.js.map +1 -1
  72. package/dist/foundations/assistant/controllers/assistant.controller.d.ts.map +1 -1
  73. package/dist/foundations/assistant/controllers/assistant.controller.js +3 -0
  74. package/dist/foundations/assistant/controllers/assistant.controller.js.map +1 -1
  75. package/dist/foundations/assistant-action/controllers/assistant-action.controller.d.ts.map +1 -1
  76. package/dist/foundations/assistant-action/controllers/assistant-action.controller.js +3 -0
  77. package/dist/foundations/assistant-action/controllers/assistant-action.controller.js.map +1 -1
  78. package/dist/foundations/assistant-message/controllers/assistant-message.controller.d.ts.map +1 -1
  79. package/dist/foundations/assistant-message/controllers/assistant-message.controller.js +3 -0
  80. package/dist/foundations/assistant-message/controllers/assistant-message.controller.js.map +1 -1
  81. package/dist/foundations/audit/controllers/audit.controller.d.ts.map +1 -1
  82. package/dist/foundations/audit/controllers/audit.controller.js +3 -0
  83. package/dist/foundations/audit/controllers/audit.controller.js.map +1 -1
  84. package/dist/foundations/auth/controllers/auth.company.controller.d.ts.map +1 -1
  85. package/dist/foundations/auth/controllers/auth.company.controller.js +4 -0
  86. package/dist/foundations/auth/controllers/auth.company.controller.js.map +1 -1
  87. package/dist/foundations/auth/controllers/auth.controller.d.ts.map +1 -1
  88. package/dist/foundations/auth/controllers/auth.controller.js +3 -0
  89. package/dist/foundations/auth/controllers/auth.controller.js.map +1 -1
  90. package/dist/foundations/auth/repositories/auth.repository.d.ts.map +1 -1
  91. package/dist/foundations/auth/repositories/auth.repository.js +5 -0
  92. package/dist/foundations/auth/repositories/auth.repository.js.map +1 -1
  93. package/dist/foundations/chunk/controllers/chunk.controller.d.ts.map +1 -1
  94. package/dist/foundations/chunk/controllers/chunk.controller.js +10 -0
  95. package/dist/foundations/chunk/controllers/chunk.controller.js.map +1 -1
  96. package/dist/foundations/chunk/repositories/chunk.repository.d.ts +13 -0
  97. package/dist/foundations/chunk/repositories/chunk.repository.d.ts.map +1 -1
  98. package/dist/foundations/chunk/repositories/chunk.repository.js +27 -1
  99. package/dist/foundations/chunk/repositories/chunk.repository.js.map +1 -1
  100. package/dist/foundations/chunker/services/chunker.service.d.ts +48 -7
  101. package/dist/foundations/chunker/services/chunker.service.d.ts.map +1 -1
  102. package/dist/foundations/chunker/services/chunker.service.js +119 -61
  103. package/dist/foundations/chunker/services/chunker.service.js.map +1 -1
  104. package/dist/foundations/chunker/services/types/docx.service.d.ts +2 -0
  105. package/dist/foundations/chunker/services/types/docx.service.d.ts.map +1 -1
  106. package/dist/foundations/chunker/services/types/docx.service.js +10 -36
  107. package/dist/foundations/chunker/services/types/docx.service.js.map +1 -1
  108. package/dist/foundations/chunker/services/types/pptx.service.d.ts.map +1 -1
  109. package/dist/foundations/chunker/services/types/pptx.service.js +5 -0
  110. package/dist/foundations/chunker/services/types/pptx.service.js.map +1 -1
  111. package/dist/foundations/chunker/services/types/xlsx.service.d.ts.map +1 -1
  112. package/dist/foundations/chunker/services/types/xlsx.service.js +8 -1
  113. package/dist/foundations/chunker/services/types/xlsx.service.js.map +1 -1
  114. package/dist/foundations/chunker/utils/zip-limits.d.ts +37 -0
  115. package/dist/foundations/chunker/utils/zip-limits.d.ts.map +1 -0
  116. package/dist/foundations/chunker/utils/zip-limits.js +113 -0
  117. package/dist/foundations/chunker/utils/zip-limits.js.map +1 -0
  118. package/dist/foundations/company/controllers/company.controller.d.ts.map +1 -1
  119. package/dist/foundations/company/controllers/company.controller.js +3 -0
  120. package/dist/foundations/company/controllers/company.controller.js.map +1 -1
  121. package/dist/foundations/content/controllers/content.controller.d.ts.map +1 -1
  122. package/dist/foundations/content/controllers/content.controller.js +3 -0
  123. package/dist/foundations/content/controllers/content.controller.js.map +1 -1
  124. package/dist/foundations/email-automation/controllers/email-automation-step.controller.d.ts.map +1 -1
  125. package/dist/foundations/email-automation/controllers/email-automation-step.controller.js +3 -0
  126. package/dist/foundations/email-automation/controllers/email-automation-step.controller.js.map +1 -1
  127. package/dist/foundations/email-automation/controllers/email-automation.controller.d.ts.map +1 -1
  128. package/dist/foundations/email-automation/controllers/email-automation.controller.js +3 -0
  129. package/dist/foundations/email-automation/controllers/email-automation.controller.js.map +1 -1
  130. package/dist/foundations/feature/controllers/feature.controller.d.ts.map +1 -1
  131. package/dist/foundations/feature/controllers/feature.controller.js +3 -0
  132. package/dist/foundations/feature/controllers/feature.controller.js.map +1 -1
  133. package/dist/foundations/handbook/controllers/handbook-thread.controller.d.ts.map +1 -1
  134. package/dist/foundations/handbook/controllers/handbook-thread.controller.js +3 -0
  135. package/dist/foundations/handbook/controllers/handbook-thread.controller.js.map +1 -1
  136. package/dist/foundations/handbook/controllers/handbook.controller.d.ts.map +1 -1
  137. package/dist/foundations/handbook/controllers/handbook.controller.js +3 -0
  138. package/dist/foundations/handbook/controllers/handbook.controller.js.map +1 -1
  139. package/dist/foundations/how-to/controllers/how-to.controller.d.ts.map +1 -1
  140. package/dist/foundations/how-to/controllers/how-to.controller.js +3 -0
  141. package/dist/foundations/how-to/controllers/how-to.controller.js.map +1 -1
  142. package/dist/foundations/keyconcept/controllers/keyconcept.controller.d.ts.map +1 -1
  143. package/dist/foundations/keyconcept/controllers/keyconcept.controller.js +3 -0
  144. package/dist/foundations/keyconcept/controllers/keyconcept.controller.js.map +1 -1
  145. package/dist/foundations/notification/controllers/notification.controller.d.ts.map +1 -1
  146. package/dist/foundations/notification/controllers/notification.controller.js +4 -0
  147. package/dist/foundations/notification/controllers/notification.controller.js.map +1 -1
  148. package/dist/foundations/oauth/constants/oauth.errors.d.ts +5 -0
  149. package/dist/foundations/oauth/constants/oauth.errors.d.ts.map +1 -1
  150. package/dist/foundations/oauth/constants/oauth.errors.js +6 -0
  151. package/dist/foundations/oauth/constants/oauth.errors.js.map +1 -1
  152. package/dist/foundations/oauth/controllers/oauth.authorize.controller.d.ts.map +1 -1
  153. package/dist/foundations/oauth/controllers/oauth.authorize.controller.js +4 -0
  154. package/dist/foundations/oauth/controllers/oauth.authorize.controller.js.map +1 -1
  155. package/dist/foundations/oauth/controllers/oauth.management.controller.d.ts.map +1 -1
  156. package/dist/foundations/oauth/controllers/oauth.management.controller.js +3 -0
  157. package/dist/foundations/oauth/controllers/oauth.management.controller.js.map +1 -1
  158. package/dist/foundations/oauth/controllers/oauth.registration.controller.d.ts.map +1 -1
  159. package/dist/foundations/oauth/controllers/oauth.registration.controller.js +10 -1
  160. package/dist/foundations/oauth/controllers/oauth.registration.controller.js.map +1 -1
  161. package/dist/foundations/oauth/queries/revoke-user-oauth-tokens.query.d.ts +13 -0
  162. package/dist/foundations/oauth/queries/revoke-user-oauth-tokens.query.d.ts.map +1 -0
  163. package/dist/foundations/oauth/queries/revoke-user-oauth-tokens.query.js +29 -0
  164. package/dist/foundations/oauth/queries/revoke-user-oauth-tokens.query.js.map +1 -0
  165. package/dist/foundations/oauth/repositories/oauth.repository.d.ts +22 -0
  166. package/dist/foundations/oauth/repositories/oauth.repository.d.ts.map +1 -1
  167. package/dist/foundations/oauth/repositories/oauth.repository.js +43 -12
  168. package/dist/foundations/oauth/repositories/oauth.repository.js.map +1 -1
  169. package/dist/foundations/oauth/services/oauth.service.d.ts.map +1 -1
  170. package/dist/foundations/oauth/services/oauth.service.js +11 -2
  171. package/dist/foundations/oauth/services/oauth.service.js.map +1 -1
  172. package/dist/foundations/oauth/services/oauth.token.service.d.ts +9 -0
  173. package/dist/foundations/oauth/services/oauth.token.service.d.ts.map +1 -1
  174. package/dist/foundations/oauth/services/oauth.token.service.js +22 -0
  175. package/dist/foundations/oauth/services/oauth.token.service.js.map +1 -1
  176. package/dist/foundations/push/controllers/push.controller.d.ts.map +1 -1
  177. package/dist/foundations/push/controllers/push.controller.js +3 -0
  178. package/dist/foundations/push/controllers/push.controller.js.map +1 -1
  179. package/dist/foundations/rbac/controllers/rbac-dev.controller.d.ts.map +1 -1
  180. package/dist/foundations/rbac/controllers/rbac-dev.controller.js +3 -0
  181. package/dist/foundations/rbac/controllers/rbac-dev.controller.js.map +1 -1
  182. package/dist/foundations/rbac/controllers/rbac-module-paths.controller.d.ts.map +1 -1
  183. package/dist/foundations/rbac/controllers/rbac-module-paths.controller.js +3 -0
  184. package/dist/foundations/rbac/controllers/rbac-module-paths.controller.js.map +1 -1
  185. package/dist/foundations/rbac/controllers/rbac.controller.d.ts.map +1 -1
  186. package/dist/foundations/rbac/controllers/rbac.controller.js +3 -0
  187. package/dist/foundations/rbac/controllers/rbac.controller.js.map +1 -1
  188. package/dist/foundations/rbac/index.d.ts +5 -0
  189. package/dist/foundations/rbac/index.d.ts.map +1 -1
  190. package/dist/foundations/rbac/index.js +12 -1
  191. package/dist/foundations/rbac/index.js.map +1 -1
  192. package/dist/foundations/rbac/rbac-permission.module.d.ts +4 -0
  193. package/dist/foundations/rbac/rbac-permission.module.d.ts.map +1 -1
  194. package/dist/foundations/rbac/rbac-permission.module.js +18 -2
  195. package/dist/foundations/rbac/rbac-permission.module.js.map +1 -1
  196. package/dist/foundations/rbac/rbac.tokens.d.ts +8 -0
  197. package/dist/foundations/rbac/rbac.tokens.d.ts.map +1 -1
  198. package/dist/foundations/rbac/rbac.tokens.js +9 -1
  199. package/dist/foundations/rbac/rbac.tokens.js.map +1 -1
  200. package/dist/foundations/rbac/repositories/rbac-permission.repository.d.ts +29 -1
  201. package/dist/foundations/rbac/repositories/rbac-permission.repository.d.ts.map +1 -1
  202. package/dist/foundations/rbac/repositories/rbac-permission.repository.js +73 -1
  203. package/dist/foundations/rbac/repositories/rbac-permission.repository.js.map +1 -1
  204. package/dist/foundations/rbac/services/module-permission-audit.service.d.ts +34 -0
  205. package/dist/foundations/rbac/services/module-permission-audit.service.d.ts.map +1 -0
  206. package/dist/foundations/rbac/services/module-permission-audit.service.js +137 -0
  207. package/dist/foundations/rbac/services/module-permission-audit.service.js.map +1 -0
  208. package/dist/foundations/rbac/services/module-permission.gate.d.ts +51 -0
  209. package/dist/foundations/rbac/services/module-permission.gate.d.ts.map +1 -0
  210. package/dist/foundations/rbac/services/module-permission.gate.js +108 -0
  211. package/dist/foundations/rbac/services/module-permission.gate.js.map +1 -0
  212. package/dist/foundations/rbac/services/module-permission.service.d.ts +34 -0
  213. package/dist/foundations/rbac/services/module-permission.service.d.ts.map +1 -0
  214. package/dist/foundations/rbac/services/module-permission.service.js +64 -0
  215. package/dist/foundations/rbac/services/module-permission.service.js.map +1 -0
  216. package/dist/foundations/rbac/services/rbac-permission.service.d.ts +10 -1
  217. package/dist/foundations/rbac/services/rbac-permission.service.d.ts.map +1 -1
  218. package/dist/foundations/rbac/services/rbac-permission.service.js +32 -2
  219. package/dist/foundations/rbac/services/rbac-permission.service.js.map +1 -1
  220. package/dist/foundations/rbac/services/rbac-reconciler.service.d.ts +11 -2
  221. package/dist/foundations/rbac/services/rbac-reconciler.service.d.ts.map +1 -1
  222. package/dist/foundations/rbac/services/rbac-reconciler.service.js +19 -6
  223. package/dist/foundations/rbac/services/rbac-reconciler.service.js.map +1 -1
  224. package/dist/foundations/referral/controllers/referral.controller.d.ts.map +1 -1
  225. package/dist/foundations/referral/controllers/referral.controller.js +3 -0
  226. package/dist/foundations/referral/controllers/referral.controller.js.map +1 -1
  227. package/dist/foundations/role/controllers/role.controller.d.ts.map +1 -1
  228. package/dist/foundations/role/controllers/role.controller.js +3 -0
  229. package/dist/foundations/role/controllers/role.controller.js.map +1 -1
  230. package/dist/foundations/role/controllers/role.user.controller.d.ts.map +1 -1
  231. package/dist/foundations/role/controllers/role.user.controller.js +3 -0
  232. package/dist/foundations/role/controllers/role.user.controller.js.map +1 -1
  233. package/dist/foundations/s3/controllers/s3.controller.d.ts +13 -0
  234. package/dist/foundations/s3/controllers/s3.controller.d.ts.map +1 -1
  235. package/dist/foundations/s3/controllers/s3.controller.js +61 -7
  236. package/dist/foundations/s3/controllers/s3.controller.js.map +1 -1
  237. package/dist/foundations/stripe/controllers/billing.controller.d.ts.map +1 -1
  238. package/dist/foundations/stripe/controllers/billing.controller.js +4 -0
  239. package/dist/foundations/stripe/controllers/billing.controller.js.map +1 -1
  240. package/dist/foundations/stripe-customer/controllers/stripe-customer.controller.d.ts.map +1 -1
  241. package/dist/foundations/stripe-customer/controllers/stripe-customer.controller.js +3 -0
  242. package/dist/foundations/stripe-customer/controllers/stripe-customer.controller.js.map +1 -1
  243. package/dist/foundations/stripe-invoice/controllers/stripe-invoice.controller.d.ts.map +1 -1
  244. package/dist/foundations/stripe-invoice/controllers/stripe-invoice.controller.js +3 -0
  245. package/dist/foundations/stripe-invoice/controllers/stripe-invoice.controller.js.map +1 -1
  246. package/dist/foundations/stripe-price/controllers/stripe-price.controller.d.ts.map +1 -1
  247. package/dist/foundations/stripe-price/controllers/stripe-price.controller.js +3 -0
  248. package/dist/foundations/stripe-price/controllers/stripe-price.controller.js.map +1 -1
  249. package/dist/foundations/stripe-product/controllers/stripe-product.controller.d.ts.map +1 -1
  250. package/dist/foundations/stripe-product/controllers/stripe-product.controller.js +3 -0
  251. package/dist/foundations/stripe-product/controllers/stripe-product.controller.js.map +1 -1
  252. package/dist/foundations/stripe-promotion-code/controllers/stripe-promotion-code.controller.d.ts.map +1 -1
  253. package/dist/foundations/stripe-promotion-code/controllers/stripe-promotion-code.controller.js +4 -0
  254. package/dist/foundations/stripe-promotion-code/controllers/stripe-promotion-code.controller.js.map +1 -1
  255. package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.d.ts.map +1 -1
  256. package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.js +3 -0
  257. package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.js.map +1 -1
  258. package/dist/foundations/stripe-usage/controllers/stripe-usage.controller.d.ts.map +1 -1
  259. package/dist/foundations/stripe-usage/controllers/stripe-usage.controller.js +3 -0
  260. package/dist/foundations/stripe-usage/controllers/stripe-usage.controller.js.map +1 -1
  261. package/dist/foundations/tokenusage/controllers/tokenusage.admin.controller.d.ts.map +1 -1
  262. package/dist/foundations/tokenusage/controllers/tokenusage.admin.controller.js +3 -0
  263. package/dist/foundations/tokenusage/controllers/tokenusage.admin.controller.js.map +1 -1
  264. package/dist/foundations/tokenusage/controllers/tokenusage.report.controller.d.ts.map +1 -1
  265. package/dist/foundations/tokenusage/controllers/tokenusage.report.controller.js +3 -0
  266. package/dist/foundations/tokenusage/controllers/tokenusage.report.controller.js.map +1 -1
  267. package/dist/foundations/two-factor/controllers/passkey.controller.d.ts.map +1 -1
  268. package/dist/foundations/two-factor/controllers/passkey.controller.js +7 -0
  269. package/dist/foundations/two-factor/controllers/passkey.controller.js.map +1 -1
  270. package/dist/foundations/two-factor/controllers/totp.controller.d.ts.map +1 -1
  271. package/dist/foundations/two-factor/controllers/totp.controller.js +6 -0
  272. package/dist/foundations/two-factor/controllers/totp.controller.js.map +1 -1
  273. package/dist/foundations/two-factor/controllers/two-factor.controller.d.ts.map +1 -1
  274. package/dist/foundations/two-factor/controllers/two-factor.controller.js +7 -0
  275. package/dist/foundations/two-factor/controllers/two-factor.controller.js.map +1 -1
  276. package/dist/foundations/user/controllers/user.controller.d.ts.map +1 -1
  277. package/dist/foundations/user/controllers/user.controller.js +3 -0
  278. package/dist/foundations/user/controllers/user.controller.js.map +1 -1
  279. package/dist/foundations/user/repositories/user.repository.d.ts +18 -0
  280. package/dist/foundations/user/repositories/user.repository.d.ts.map +1 -1
  281. package/dist/foundations/user/repositories/user.repository.js +44 -1
  282. package/dist/foundations/user/repositories/user.repository.js.map +1 -1
  283. package/dist/foundations/waitlist/controllers/waitlist.controller.d.ts.map +1 -1
  284. package/dist/foundations/waitlist/controllers/waitlist.controller.js +3 -0
  285. package/dist/foundations/waitlist/controllers/waitlist.controller.js.map +1 -1
  286. package/dist/mcp/controllers/mcp.controller.d.ts.map +1 -1
  287. package/dist/mcp/controllers/mcp.controller.js +7 -1
  288. package/dist/mcp/controllers/mcp.controller.js.map +1 -1
  289. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"rbac.tokens.js","sourceRoot":"","sources":["../../../src/foundations/rbac/rbac.tokens.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACU,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
1
+ {"version":3,"file":"rbac.tokens.js","sourceRoot":"","sources":["../../../src/foundations/rbac/rbac.tokens.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACU,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAE7D;;;;;;GAMG;AACU,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC"}
@@ -1,5 +1,11 @@
1
1
  import { Neo4jService } from "../../../core/neo4j/services/neo4j.service";
2
2
  import type { RbacAction } from "../services/rbac-permission.service";
3
+ /**
4
+ * Effective permission values per module id. A value is `true`, `false` or a
5
+ * record path (a non-empty string such as `"id"`), exactly as resolved by
6
+ * `modulePermissionResolutionQuery`.
7
+ */
8
+ export type EffectivePermissions = Map<string, Record<RbacAction, boolean | string>>;
3
9
  /**
4
10
  * Resolves the effective per-module permission flags for a user. Mirrors the
5
11
  * permission model used by the rest of the app (see AuthRepository and
@@ -9,7 +15,7 @@ import type { RbacAction } from "../services/rbac-permission.service";
9
15
  * `permissions` JSON with any role-level `HAS_PERMISSIONS` overrides.
10
16
  *
11
17
  * Used by RbacPermissionService to answer `can(userId, moduleId, action)`
12
- * for the MCP layer.
18
+ * for the MCP layer, and by ModulePermissionService for the request gate.
13
19
  */
14
20
  export declare class RbacPermissionRepository {
15
21
  private readonly neo4j;
@@ -27,5 +33,27 @@ export declare class RbacPermissionRepository {
27
33
  * types (`read`, `create`, `update`, `delete`).
28
34
  */
29
35
  findEffectivePermissionsForUser(userId: string): Promise<Map<string, Record<RbacAction, boolean>>>;
36
+ /**
37
+ * Effective permissions of a user in ONE company: the module defaults plus
38
+ * the grants of the roles on the user's membership in that company and on
39
+ * the user's platform memberships (no `IN_COMPANY`). Never follows the
40
+ * legacy `(User)-[:BELONGS_TO]->(Company)` edge.
41
+ *
42
+ * With no `companyId` (a platform session) it resolves through the
43
+ * platform membership only (`adminModuleQuery`).
44
+ *
45
+ * Record-path values are kept as strings: the request gate allows them at
46
+ * the section level and leaves the record decision to the app.
47
+ *
48
+ * Intentional exception to "use buildDefaultMatch": this is the library's
49
+ * own permission resolution (the same `company` binding UserModulesRepository
50
+ * uses), not an entity read.
51
+ */
52
+ findEffectivePermissions(params: {
53
+ userId: string;
54
+ companyId: string | undefined;
55
+ }): Promise<EffectivePermissions>;
56
+ /** The subset of `ids` that exist as `(:Module)` nodes. */
57
+ findExistingModuleIds(ids: string[]): Promise<Set<string>>;
30
58
  }
31
59
  //# sourceMappingURL=rbac-permission.repository.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rbac-permission.repository.d.ts","sourceRoot":"","sources":["../../../../src/foundations/rbac/repositories/rbac-permission.repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAE1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAOtE;;;;;;;;;;GAUG;AACH,qBACa,wBAAwB;IAGvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFlC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6C;gBAEvC,KAAK,EAAE,YAAY;IAEhD;;;;;;;;;;OAUG;IACG,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;CA+BzG"}
1
+ {"version":3,"file":"rbac-permission.repository.d.ts","sourceRoot":"","sources":["../../../../src/foundations/rbac/repositories/rbac-permission.repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAI1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAOtE;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;AAErF;;;;;;;;;;GAUG;AACH,qBACa,wBAAwB;IAGvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFlC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6C;gBAEvC,KAAK,EAAE,YAAY;IAEhD;;;;;;;;;;OAUG;IACG,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IAgCxG;;;;;;;;;;;;;;;OAeG;IACG,wBAAwB,CAAC,MAAM,EAAE;QACrC,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;KAC/B,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAyCjC,2DAA2D;IACrD,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CAcjE"}
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.RbacPermissionRepository = void 0;
14
14
  const common_1 = require("@nestjs/common");
15
15
  const neo4j_service_1 = require("../../../core/neo4j/services/neo4j.service");
16
+ const module_model_1 = require("../../module/entities/module.model");
16
17
  const feature_module_query_1 = require("../../module/queries/feature.module.query");
17
18
  /**
18
19
  * Resolves the effective per-module permission flags for a user. Mirrors the
@@ -23,7 +24,7 @@ const feature_module_query_1 = require("../../module/queries/feature.module.quer
23
24
  * `permissions` JSON with any role-level `HAS_PERMISSIONS` overrides.
24
25
  *
25
26
  * Used by RbacPermissionService to answer `can(userId, moduleId, action)`
26
- * for the MCP layer.
27
+ * for the MCP layer, and by ModulePermissionService for the request gate.
27
28
  */
28
29
  let RbacPermissionRepository = RbacPermissionRepository_1 = class RbacPermissionRepository {
29
30
  constructor(neo4j) {
@@ -71,6 +72,77 @@ let RbacPermissionRepository = RbacPermissionRepository_1 = class RbacPermission
71
72
  }
72
73
  return map;
73
74
  }
75
+ /**
76
+ * Effective permissions of a user in ONE company: the module defaults plus
77
+ * the grants of the roles on the user's membership in that company and on
78
+ * the user's platform memberships (no `IN_COMPANY`). Never follows the
79
+ * legacy `(User)-[:BELONGS_TO]->(Company)` edge.
80
+ *
81
+ * With no `companyId` (a platform session) it resolves through the
82
+ * platform membership only (`adminModuleQuery`).
83
+ *
84
+ * Record-path values are kept as strings: the request gate allows them at
85
+ * the section level and leaves the record decision to the app.
86
+ *
87
+ * Intentional exception to "use buildDefaultMatch": this is the library's
88
+ * own permission resolution (the same `company` binding UserModulesRepository
89
+ * uses), not an entity read.
90
+ */
91
+ async findEffectivePermissions(params) {
92
+ const result = params.companyId
93
+ ? await this.neo4j.read(`
94
+ MATCH (user:User {id: $userId})
95
+ MATCH (company:Company {id: $companyId})
96
+ ${feature_module_query_1.featureModuleQuery}
97
+ `, { userId: params.userId, companyId: params.companyId })
98
+ : await this.neo4j.read(feature_module_query_1.adminModuleQuery, { searchValue: params.userId });
99
+ const map = new Map();
100
+ for (const record of result.records) {
101
+ const moduleNode = record.get("module");
102
+ const props = moduleNode?.properties;
103
+ if (!props)
104
+ continue;
105
+ const id = props.id;
106
+ const permsJson = props.permissions;
107
+ if (typeof id !== "string" || !id.length || typeof permsJson !== "string")
108
+ continue;
109
+ try {
110
+ const perms = JSON.parse(permsJson);
111
+ const value = (type) => {
112
+ const raw = perms.find((p) => p.type === type)?.value;
113
+ if (raw === true)
114
+ return true;
115
+ if (typeof raw === "string" && raw.length > 0)
116
+ return raw;
117
+ return false;
118
+ };
119
+ map.set(id, {
120
+ read: value("read"),
121
+ create: value("create"),
122
+ update: value("update"),
123
+ delete: value("delete"),
124
+ });
125
+ }
126
+ catch {
127
+ this.logger.warn(`findEffectivePermissions: malformed permissions JSON on module ${id}`);
128
+ }
129
+ }
130
+ return map;
131
+ }
132
+ /** The subset of `ids` that exist as `(:Module)` nodes. */
133
+ async findExistingModuleIds(ids) {
134
+ if (ids.length === 0)
135
+ return new Set();
136
+ const query = this.neo4j.initQuery({ serialiser: module_model_1.ModuleModel });
137
+ query.queryParams = { ...query.queryParams, ids };
138
+ query.query += `
139
+ MATCH (module:Module)
140
+ WHERE module.id IN $ids
141
+ RETURN module
142
+ `;
143
+ const modules = await this.neo4j.readMany(query);
144
+ return new Set(modules.map((module) => module.id));
145
+ }
74
146
  };
75
147
  exports.RbacPermissionRepository = RbacPermissionRepository;
76
148
  exports.RbacPermissionRepository = RbacPermissionRepository = RbacPermissionRepository_1 = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"rbac-permission.repository.js","sourceRoot":"","sources":["../../../../src/foundations/rbac/repositories/rbac-permission.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,8EAA0E;AAC1E,oFAA+E;AAQ/E;;;;;;;;;;GAUG;AAEI,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAGnC,YAA6B,KAAmB;QAAnB,UAAK,GAAL,KAAK,CAAc;QAF/B,WAAM,GAAG,IAAI,eAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAC;IAEjB,CAAC;IAEpD;;;;;;;;;;OAUG;IACH,KAAK,CAAC,+BAA+B,CAAC,MAAc;QAClD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAClC;;QAEE,yCAAkB;OACnB,EACD,EAAE,MAAM,EAAE,CACX,CAAC;QAE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EAAyE,EAAE,EAAE,CAAC,CAAC;YAClG,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAA;AA/CY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAIyB,4BAAY;GAHrC,wBAAwB,CA+CpC"}
1
+ {"version":3,"file":"rbac-permission.repository.js","sourceRoot":"","sources":["../../../../src/foundations/rbac/repositories/rbac-permission.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,8EAA0E;AAE1E,qEAAiE;AACjE,oFAAiG;AAejG;;;;;;;;;;GAUG;AAEI,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAGnC,YAA6B,KAAmB;QAAnB,UAAK,GAAL,KAAK,CAAc;QAF/B,WAAM,GAAG,IAAI,eAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAC;IAEjB,CAAC;IAEpD;;;;;;;;;;OAUG;IACH,KAAK,CAAC,+BAA+B,CAAC,MAAc;QAClD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAClC;;QAEE,yCAAkB;OACnB,EACD,EAAE,MAAM,EAAE,CACX,CAAC;QAEF,MAAM,GAAG,GAAG,IAAI,GAAG,EAAuC,CAAC;QAC3D,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACpC,MAAM,UAAU,GAAQ,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC7C,MAAM,KAAK,GAAG,UAAU,EAAE,UAAU,CAAC;YACrC,IAAI,CAAC,KAAK;gBAAE,SAAS;YACrB,MAAM,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;YACpB,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC;YACpC,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,EAAE,CAAC,MAAM,IAAI,OAAO,SAAS,KAAK,QAAQ;gBAAE,SAAS;YAC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AAC;gBACP,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kEAAkE,EAAE,EAAE,CAAC,CAAC;YAC3F,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,qBAAqB,CAAC,GAAa;QACvC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,GAAG,EAAE,CAAC;QAEvC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,0BAAW,EAAE,CAAC,CAAC;QAChE,KAAK,CAAC,WAAW,GAAG,EAAE,GAAG,KAAK,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC;QAClD,KAAK,CAAC,KAAK,IAAI;;;;KAId,CAAC;QAEF,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAS,KAAK,CAAC,CAAC;QACzD,OAAO,IAAI,GAAG,CAAS,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;CACF,CAAA;AA3HY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAIyB,4BAAY;GAHrC,wBAAwB,CA2HpC"}
@@ -0,0 +1,34 @@
1
+ import { OnApplicationBootstrap } from "@nestjs/common";
2
+ import { DiscoveryService, MetadataScanner, Reflector } from "@nestjs/core";
3
+ import { RbacPermissionRepository } from "../repositories/rbac-permission.repository";
4
+ interface AuditedRoute {
5
+ label: string;
6
+ module: string | undefined;
7
+ isWrite: boolean;
8
+ }
9
+ /**
10
+ * Boot audit for the permission gate. Runs only when the app bootstraps with
11
+ * `permissions: { enforce: true }` (API and worker).
12
+ *
13
+ * Refuses to start when:
14
+ * - a route guarded by a session guard is a write (POST/PUT/PATCH/DELETE, or a
15
+ * `@ModuleACL` action that is a write) and has no section;
16
+ * - a section id referenced by any session-guarded route has no `(:Module)` node.
17
+ *
18
+ * This is what makes the gate fail closed for writes at startup instead of at
19
+ * request time.
20
+ */
21
+ export declare class ModulePermissionAuditService implements OnApplicationBootstrap {
22
+ private readonly discovery;
23
+ private readonly metadataScanner;
24
+ private readonly reflector;
25
+ private readonly repository;
26
+ private readonly enforce?;
27
+ constructor(discovery: DiscoveryService, metadataScanner: MetadataScanner, reflector: Reflector, repository: RbacPermissionRepository, enforce?: boolean);
28
+ onApplicationBootstrap(): Promise<void>;
29
+ /** Every session-guarded route with its resolved section. Exposed for tests. */
30
+ collectRoutes(): AuditedRoute[];
31
+ audit(): Promise<void>;
32
+ }
33
+ export {};
34
+ //# sourceMappingURL=module-permission-audit.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-permission-audit.service.d.ts","sourceRoot":"","sources":["../../../../src/foundations/rbac/services/module-permission-audit.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,sBAAsB,EAA2B,MAAM,gBAAgB,CAAC;AAErG,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAM5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAatF,UAAU,YAAY;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;CAClB;AAcD;;;;;;;;;;;GAWG;AACH,qBACa,4BAA6B,YAAW,sBAAsB;IAEvE,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAG3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBANR,SAAS,EAAE,gBAAgB,EAC3B,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,wBAAwB,EAGpC,OAAO,CAAC,EAAE,OAAO;IAG9B,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAK7C,gFAAgF;IAChF,aAAa,IAAI,YAAY,EAAE;IAyCzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CA0B7B"}
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ModulePermissionAuditService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const constants_1 = require("@nestjs/common/constants");
18
+ const core_1 = require("@nestjs/core");
19
+ const module_decorator_1 = require("../../../common/decorators/module.decorator");
20
+ const jwt_auth_admin_guard_1 = require("../../../common/guards/jwt.auth.admin.guard");
21
+ const jwt_auth_guard_1 = require("../../../common/guards/jwt.auth.guard");
22
+ const jwt_auth_optional_guard_1 = require("../../../common/guards/jwt.auth.optional.guard");
23
+ const rbac_permission_repository_1 = require("../repositories/rbac-permission.repository");
24
+ const rbac_tokens_1 = require("../rbac.tokens");
25
+ const module_permission_gate_1 = require("./module-permission.gate");
26
+ /** The guards that run `ModulePermissionGate`. Subclasses count too. */
27
+ const SESSION_GUARDS = [
28
+ jwt_auth_guard_1.JwtAuthGuard,
29
+ jwt_auth_admin_guard_1.AdminJwtAuthGuard,
30
+ jwt_auth_optional_guard_1.OptionalJwtAuthGuard,
31
+ ];
32
+ const WRITE_ACTIONS = new Set(["create", "update", "delete"]);
33
+ function isSessionGuard(guard) {
34
+ const type = typeof guard === "function" ? guard : guard?.constructor;
35
+ if (typeof type !== "function")
36
+ return false;
37
+ return SESSION_GUARDS.some((g) => type === g || type.prototype instanceof g);
38
+ }
39
+ function joinPaths(prefix, path) {
40
+ const first = (value) => (Array.isArray(value) ? String(value[0] ?? "") : String(value ?? ""));
41
+ const parts = [first(prefix), first(path)].map((p) => p.replace(/^\/+|\/+$/g, "")).filter((p) => p.length);
42
+ return `/${parts.join("/")}`;
43
+ }
44
+ /**
45
+ * Boot audit for the permission gate. Runs only when the app bootstraps with
46
+ * `permissions: { enforce: true }` (API and worker).
47
+ *
48
+ * Refuses to start when:
49
+ * - a route guarded by a session guard is a write (POST/PUT/PATCH/DELETE, or a
50
+ * `@ModuleACL` action that is a write) and has no section;
51
+ * - a section id referenced by any session-guarded route has no `(:Module)` node.
52
+ *
53
+ * This is what makes the gate fail closed for writes at startup instead of at
54
+ * request time.
55
+ */
56
+ let ModulePermissionAuditService = class ModulePermissionAuditService {
57
+ constructor(discovery, metadataScanner, reflector, repository, enforce) {
58
+ this.discovery = discovery;
59
+ this.metadataScanner = metadataScanner;
60
+ this.reflector = reflector;
61
+ this.repository = repository;
62
+ this.enforce = enforce;
63
+ }
64
+ async onApplicationBootstrap() {
65
+ if (this.enforce !== true)
66
+ return;
67
+ await this.audit();
68
+ }
69
+ /** Every session-guarded route with its resolved section. Exposed for tests. */
70
+ collectRoutes() {
71
+ const routes = [];
72
+ for (const wrapper of this.discovery.getControllers()) {
73
+ const controller = wrapper.metatype;
74
+ if (typeof controller !== "function" || !controller.prototype)
75
+ continue;
76
+ const prototype = controller.prototype;
77
+ const classGuards = this.reflector.get(constants_1.GUARDS_METADATA, controller) ?? [];
78
+ const classDefinition = this.reflector.get(module_decorator_1.MODULE_ACL_METADATA, controller);
79
+ const controllerPath = this.reflector.get(constants_1.PATH_METADATA, controller);
80
+ for (const methodName of this.metadataScanner.getAllMethodNames(prototype)) {
81
+ const handler = prototype[methodName];
82
+ if (typeof handler !== "function")
83
+ continue;
84
+ const requestMethod = this.reflector.get(constants_1.METHOD_METADATA, handler);
85
+ const routePath = this.reflector.get(constants_1.PATH_METADATA, handler);
86
+ if (requestMethod === undefined || routePath === undefined)
87
+ continue;
88
+ const handlerGuards = this.reflector.get(constants_1.GUARDS_METADATA, handler) ?? [];
89
+ if (![...classGuards, ...handlerGuards].some(isSessionGuard))
90
+ continue;
91
+ const method = common_1.RequestMethod[requestMethod] ?? String(requestMethod);
92
+ const { module, action } = (0, module_permission_gate_1.resolveRouteAcl)({
93
+ classDefinition,
94
+ handlerDefinition: this.reflector.get(module_decorator_1.MODULE_ACL_METADATA, handler),
95
+ method,
96
+ });
97
+ routes.push({
98
+ label: `${method} ${joinPaths(controllerPath, routePath)} (${controller.name}.${methodName})`,
99
+ module,
100
+ isWrite: WRITE_ACTIONS.has(action),
101
+ });
102
+ }
103
+ }
104
+ return routes;
105
+ }
106
+ async audit() {
107
+ const routes = this.collectRoutes();
108
+ const unsectioned = routes.filter((r) => r.isWrite && !r.module).map((r) => r.label);
109
+ if (unsectioned.length > 0) {
110
+ throw new Error(`Permission audit failed: ${unsectioned.length} session-guarded write route(s) have no @ModuleACL section:\n` +
111
+ unsectioned.map((label) => ` - ${label}`).join("\n"));
112
+ }
113
+ const referenced = Array.from(new Set(routes.map((r) => r.module).filter((m) => !!m))).sort();
114
+ const existing = await this.repository.findExistingModuleIds(referenced);
115
+ const missing = referenced.filter((id) => !existing.has(id));
116
+ if (missing.length > 0) {
117
+ const byModule = missing.map((id) => {
118
+ const example = routes.find((r) => r.module === id)?.label ?? "";
119
+ return ` - ${id} (e.g. ${example})`;
120
+ });
121
+ throw new Error(`Permission audit failed: ${missing.length} section id(s) referenced by @ModuleACL have no (:Module) node. ` +
122
+ `Seed them in a migration before switching permissions.enforce on:\n` +
123
+ byModule.join("\n"));
124
+ }
125
+ }
126
+ };
127
+ exports.ModulePermissionAuditService = ModulePermissionAuditService;
128
+ exports.ModulePermissionAuditService = ModulePermissionAuditService = __decorate([
129
+ (0, common_1.Injectable)(),
130
+ __param(4, (0, common_1.Optional)()),
131
+ __param(4, (0, common_1.Inject)(rbac_tokens_1.PERMISSIONS_ENFORCE)),
132
+ __metadata("design:paramtypes", [core_1.DiscoveryService,
133
+ core_1.MetadataScanner,
134
+ core_1.Reflector,
135
+ rbac_permission_repository_1.RbacPermissionRepository, Boolean])
136
+ ], ModulePermissionAuditService);
137
+ //# sourceMappingURL=module-permission-audit.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-permission-audit.service.js","sourceRoot":"","sources":["../../../../src/foundations/rbac/services/module-permission-audit.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAqG;AACrG,wDAA2F;AAC3F,uCAA4E;AAC5E,kFAAkF;AAElF,sFAAgF;AAChF,0EAAqE;AACrE,4FAAsF;AACtF,2FAAsF;AACtF,gDAAqD;AACrD,qEAA2D;AAE3D,wEAAwE;AACxE,MAAM,cAAc,GAAoD;IACtE,6BAAY;IACZ,wCAAiB;IACjB,8CAAoB;CACrB,CAAC;AAEF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AAQ9D,SAAS,cAAc,CAAC,KAAc;IACpC,MAAM,IAAI,GAAQ,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,KAAa,EAAE,WAAW,CAAC;IACpF,IAAI,OAAO,IAAI,KAAK,UAAU;QAAE,OAAO,KAAK,CAAC;IAC7C,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,CA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CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC3G,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC;QACzE,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7D,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;gBAClC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;gBACjE,OAAO,OAAO,EAAE,UAAU,OAAO,GAAG,CAAC;YACvC,CAAC,CAAC,CAAC;YACH,MAAM,IAAI,KAAK,CACb,4BAA4B,OAAO,CAAC,MAAM,kEAAkE;gBAC1G,qEAAqE;gBACrE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CACtB,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAA;AApFY,oEAA4B;uCAA5B,4BAA4B;IADxC,IAAA,mBAAU,GAAE;IAOR,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,iCAAmB,CAAC,CAAA;qCALA,uBAAgB;QACV,sBAAe;QACrB,gBAAS;QACR,qDAAwB;GAL5C,4BAA4B,CAoFxC"}
@@ -0,0 +1,51 @@
1
+ import { ExecutionContext } from "@nestjs/common";
2
+ import { Reflector } from "@nestjs/core";
3
+ import { ClsService } from "nestjs-cls";
4
+ import type { ModuleDefinition } from "../../../common/decorators/module.decorator";
5
+ import { ModulePermissionService } from "./module-permission.service";
6
+ import type { RbacAction } from "./rbac-permission.service";
7
+ /**
8
+ * HTTP method → permission action. GET/HEAD/OPTIONS read, POST create, PUT/PATCH
9
+ * update, DELETE delete. Anything else is treated as a write (update), so an
10
+ * unexpected verb never slips through as a read.
11
+ */
12
+ export declare function rbacActionForHttpMethod(method: string | undefined): RbacAction;
13
+ /**
14
+ * Section and action of a route: the handler `@ModuleACL` wins over the class
15
+ * one, field by field; the action falls back to the HTTP-method mapping.
16
+ */
17
+ export declare function resolveRouteAcl(params: {
18
+ classDefinition: ModuleDefinition | undefined;
19
+ handlerDefinition: ModuleDefinition | undefined;
20
+ method: string | undefined;
21
+ }): {
22
+ module: string | undefined;
23
+ action: RbacAction;
24
+ };
25
+ /**
26
+ * Request-level permission check, run by the session guards (`JwtAuthGuard`,
27
+ * `AdminJwtAuthGuard`, `OptionalJwtAuthGuard`) right after authentication.
28
+ *
29
+ * Off unless the app bootstraps with `permissions: { enforce: true }`: with it
30
+ * off, `assert` returns before reading metadata or touching the database.
31
+ *
32
+ * Rules:
33
+ * - A read with no section is allowed (company scoping still applies).
34
+ * - A write with no section is refused (the boot audit makes this unreachable).
35
+ * - Otherwise the caller's effective permission in the token's company decides:
36
+ * `true` or a record path allows, `false` or absent refuses with 403.
37
+ * - No administrator bypass.
38
+ */
39
+ export declare class ModulePermissionGate {
40
+ private readonly reflector;
41
+ private readonly cls;
42
+ private readonly permissions;
43
+ private readonly enforce?;
44
+ constructor(reflector: Reflector, cls: ClsService, permissions: ModulePermissionService, enforce?: boolean);
45
+ get enabled(): boolean;
46
+ assert(params: {
47
+ request: any;
48
+ context: ExecutionContext;
49
+ }): Promise<void>;
50
+ }
51
+ //# sourceMappingURL=module-permission.gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-permission.gate.d.ts","sourceRoot":"","sources":["../../../../src/foundations/rbac/services/module-permission.gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAoD,MAAM,gBAAgB,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAEpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAa9E;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACtC,eAAe,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAC9C,iBAAiB,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAChD,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAKrD;AAED;;;;;;;;;;;;;GAaG;AACH,qBACa,oBAAoB;IAE7B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAG5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBALR,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,UAAU,EACf,WAAW,EAAE,uBAAuB,EAGpC,OAAO,CAAC,EAAE,OAAO;IAGpC,IAAI,OAAO,IAAI,OAAO,CAErB;IAEK,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,gBAAgB,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAuBjF"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ModulePermissionGate = void 0;
16
+ exports.rbacActionForHttpMethod = rbacActionForHttpMethod;
17
+ exports.resolveRouteAcl = resolveRouteAcl;
18
+ const common_1 = require("@nestjs/common");
19
+ const core_1 = require("@nestjs/core");
20
+ const nestjs_cls_1 = require("nestjs-cls");
21
+ const module_decorator_1 = require("../../../common/decorators/module.decorator");
22
+ const rbac_tokens_1 = require("../rbac.tokens");
23
+ const module_permission_service_1 = require("./module-permission.service");
24
+ /**
25
+ * HTTP method → permission action. GET/HEAD/OPTIONS read, POST create, PUT/PATCH
26
+ * update, DELETE delete. Anything else is treated as a write (update), so an
27
+ * unexpected verb never slips through as a read.
28
+ */
29
+ function rbacActionForHttpMethod(method) {
30
+ switch ((method ?? "").toUpperCase()) {
31
+ case "GET":
32
+ case "HEAD":
33
+ case "OPTIONS":
34
+ return "read";
35
+ case "POST":
36
+ return "create";
37
+ case "DELETE":
38
+ return "delete";
39
+ default:
40
+ return "update";
41
+ }
42
+ }
43
+ /**
44
+ * Section and action of a route: the handler `@ModuleACL` wins over the class
45
+ * one, field by field; the action falls back to the HTTP-method mapping.
46
+ */
47
+ function resolveRouteAcl(params) {
48
+ const module = params.handlerDefinition?.module ?? params.classDefinition?.module;
49
+ const action = params.handlerDefinition?.action ?? params.classDefinition?.action ?? rbacActionForHttpMethod(params.method);
50
+ return { module: module || undefined, action };
51
+ }
52
+ /**
53
+ * Request-level permission check, run by the session guards (`JwtAuthGuard`,
54
+ * `AdminJwtAuthGuard`, `OptionalJwtAuthGuard`) right after authentication.
55
+ *
56
+ * Off unless the app bootstraps with `permissions: { enforce: true }`: with it
57
+ * off, `assert` returns before reading metadata or touching the database.
58
+ *
59
+ * Rules:
60
+ * - A read with no section is allowed (company scoping still applies).
61
+ * - A write with no section is refused (the boot audit makes this unreachable).
62
+ * - Otherwise the caller's effective permission in the token's company decides:
63
+ * `true` or a record path allows, `false` or absent refuses with 403.
64
+ * - No administrator bypass.
65
+ */
66
+ let ModulePermissionGate = class ModulePermissionGate {
67
+ constructor(reflector, cls, permissions, enforce) {
68
+ this.reflector = reflector;
69
+ this.cls = cls;
70
+ this.permissions = permissions;
71
+ this.enforce = enforce;
72
+ }
73
+ get enabled() {
74
+ return this.enforce === true;
75
+ }
76
+ async assert(params) {
77
+ if (!this.enabled)
78
+ return;
79
+ const userId = params.request?.user?.userId;
80
+ // No authenticated session (optional guard, anonymous caller): nothing to evaluate.
81
+ if (!userId)
82
+ return;
83
+ const { module, action } = resolveRouteAcl({
84
+ classDefinition: this.reflector.get(module_decorator_1.MODULE_ACL_METADATA, params.context.getClass()),
85
+ handlerDefinition: this.reflector.get(module_decorator_1.MODULE_ACL_METADATA, params.context.getHandler()),
86
+ method: params.request?.method,
87
+ });
88
+ if (!module) {
89
+ if (action === "read")
90
+ return;
91
+ throw new common_1.ForbiddenException();
92
+ }
93
+ const companyId = (this.cls.isActive() ? this.cls.get("companyId") : undefined) ?? undefined;
94
+ const allowed = await this.permissions.allows({ userId, companyId, moduleId: module, action });
95
+ if (!allowed)
96
+ throw new common_1.ForbiddenException();
97
+ }
98
+ };
99
+ exports.ModulePermissionGate = ModulePermissionGate;
100
+ exports.ModulePermissionGate = ModulePermissionGate = __decorate([
101
+ (0, common_1.Injectable)(),
102
+ __param(3, (0, common_1.Optional)()),
103
+ __param(3, (0, common_1.Inject)(rbac_tokens_1.PERMISSIONS_ENFORCE)),
104
+ __metadata("design:paramtypes", [core_1.Reflector,
105
+ nestjs_cls_1.ClsService,
106
+ module_permission_service_1.ModulePermissionService, Boolean])
107
+ ], ModulePermissionGate);
108
+ //# sourceMappingURL=module-permission.gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-permission.gate.js","sourceRoot":"","sources":["../../../../src/foundations/rbac/services/module-permission.gate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAcA,0DAaC;AAMD,0CASC;AA1CD,2CAAoG;AACpG,uCAAyC;AACzC,2CAAwC;AACxC,kFAAkF;AAElF,gDAAqD;AACrD,2EAAsE;AAGtE;;;;GAIG;AACH,SAAgB,uBAAuB,CAAC,MAA0B;IAChE,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;QACrC,KAAK,KAAK,CAAC;QACX,KAAK,MAAM,CAAC;QACZ,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC;QAChB,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAAC,MAI/B;IACC,MAAM,MAAM,GAAG,MAAM,CAAC,iBAAiB,EAAE,MAAM,IAAI,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC;IAClF,MAAM,MAAM,GACV,MAAM,CAAC,iBAAiB,EAAE,MAAM,IAAI,MAAM,CAAC,eAAe,EAAE,MAAM,IAAI,uBAAuB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/G,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,EAAE,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;GAaG;AAEI,IAAM,oBAAoB,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AM,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAC/F,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,2BAAkB,EAAE,CAAC;IAC/C,CAAC;CACF,CAAA;AArCY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,iCAAmB,CAAC,CAAA;qCAJA,gBAAS;QACf,uBAAU;QACF,mDAAuB;GAJ5C,oBAAoB,CAqChC"}
@@ -0,0 +1,34 @@
1
+ import { ClsService } from "nestjs-cls";
2
+ import { RbacPermissionRepository } from "../repositories/rbac-permission.repository";
3
+ import type { EffectivePermissions } from "../repositories/rbac-permission.repository";
4
+ import type { RbacAction } from "./rbac-permission.service";
5
+ export type { EffectivePermissions } from "../repositories/rbac-permission.repository";
6
+ /**
7
+ * Resolves a caller's effective permissions in the token's company, for the
8
+ * request-level permission gate (`ModulePermissionGate`).
9
+ *
10
+ * Mirrors `RbacPermissionService` (same `featureModuleQuery` resolution) with
11
+ * three differences: it binds the token's company instead of the legacy
12
+ * `BELONGS_TO` edge, it keeps record-path values (a string allows at the
13
+ * section level), and it resolves once per request (cached in CLS).
14
+ *
15
+ * No administrator bypass: the platform Administrator is resolved like any
16
+ * role, so its grants must exist in the app's permission table.
17
+ */
18
+ export declare class ModulePermissionService {
19
+ private readonly repository;
20
+ private readonly cls;
21
+ constructor(repository: RbacPermissionRepository, cls: ClsService);
22
+ resolve(params: {
23
+ userId: string;
24
+ companyId: string | undefined;
25
+ }): Promise<EffectivePermissions>;
26
+ /** True when the effective value is `true` or a non-empty record path. */
27
+ allows(params: {
28
+ userId: string;
29
+ companyId: string | undefined;
30
+ moduleId: string;
31
+ action: RbacAction;
32
+ }): Promise<boolean>;
33
+ }
34
+ //# sourceMappingURL=module-permission.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-permission.service.d.ts","sourceRoot":"","sources":["../../../../src/foundations/rbac/services/module-permission.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,YAAY,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAUvF;;;;;;;;;;;GAWG;AACH,qBACa,uBAAuB;IAEhC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,GAAG;gBADH,UAAU,EAAE,wBAAwB,EACpC,GAAG,EAAE,UAAU;IAG5B,OAAO,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAmBvG,0EAA0E;IACpE,MAAM,CAAC,MAAM,EAAE;QACnB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;QAC9B,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,UAAU,CAAC;KACpB,GAAG,OAAO,CAAC,OAAO,CAAC;CAKrB"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ModulePermissionService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const nestjs_cls_1 = require("nestjs-cls");
15
+ const rbac_permission_repository_1 = require("../repositories/rbac-permission.repository");
16
+ /** CLS key holding the permissions resolved for the current request. */
17
+ const CLS_KEY = "effectivePermissions";
18
+ /**
19
+ * Resolves a caller's effective permissions in the token's company, for the
20
+ * request-level permission gate (`ModulePermissionGate`).
21
+ *
22
+ * Mirrors `RbacPermissionService` (same `featureModuleQuery` resolution) with
23
+ * three differences: it binds the token's company instead of the legacy
24
+ * `BELONGS_TO` edge, it keeps record-path values (a string allows at the
25
+ * section level), and it resolves once per request (cached in CLS).
26
+ *
27
+ * No administrator bypass: the platform Administrator is resolved like any
28
+ * role, so its grants must exist in the app's permission table.
29
+ */
30
+ let ModulePermissionService = class ModulePermissionService {
31
+ constructor(repository, cls) {
32
+ this.repository = repository;
33
+ this.cls = cls;
34
+ }
35
+ async resolve(params) {
36
+ const key = `${params.userId}|${params.companyId ?? ""}`;
37
+ const clsActive = this.cls.isActive();
38
+ if (clsActive) {
39
+ const cached = this.cls.get(CLS_KEY);
40
+ if (cached && cached.key === key)
41
+ return cached.permissions;
42
+ }
43
+ const permissions = await this.repository.findEffectivePermissions({
44
+ userId: params.userId,
45
+ companyId: params.companyId || undefined,
46
+ });
47
+ if (clsActive)
48
+ this.cls.set(CLS_KEY, { key, permissions });
49
+ return permissions;
50
+ }
51
+ /** True when the effective value is `true` or a non-empty record path. */
52
+ async allows(params) {
53
+ const permissions = await this.resolve({ userId: params.userId, companyId: params.companyId });
54
+ const value = permissions.get(params.moduleId)?.[params.action];
55
+ return value === true || (typeof value === "string" && value.length > 0);
56
+ }
57
+ };
58
+ exports.ModulePermissionService = ModulePermissionService;
59
+ exports.ModulePermissionService = ModulePermissionService = __decorate([
60
+ (0, common_1.Injectable)(),
61
+ __metadata("design:paramtypes", [rbac_permission_repository_1.RbacPermissionRepository,
62
+ nestjs_cls_1.ClsService])
63
+ ], ModulePermissionService);
64
+ //# sourceMappingURL=module-permission.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-permission.service.js","sourceRoot":"","sources":["../../../../src/foundations/rbac/services/module-permission.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAAwC;AACxC,2FAAsF;AAMtF,wEAAwE;AACxE,MAAM,OAAO,GAAG,sBAAsB,CAAC;AAOvC;;;;;;;;;;;GAWG;AAEI,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAClC,YACmB,UAAoC,EACpC,GAAe;QADf,eAAU,GAAV,UAAU,CAA0B;QACpC,QAAG,GAAH,GAAG,CAAY;IAC/B,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,MAAyD;QACrE,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC;QACzD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QAEtC,IAAI,SAAS,EAAE,CAAC;YACd,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAgC,OAAO,CAAC,CAAC;YACpE,IAAI,MAAM,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG;gBAAE,OAAO,MAAM,CAAC,WAAW,CAAC;QAC9D,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,wBAAwB,CAAC;YACjE,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,SAAS;SACzC,CAAC,CAAC;QAEH,IAAI,SAAS;YAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAoB,OA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