@webiny/api-core 6.6.0-alpha.1 → 6.6.0-alpha.11

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 (344) hide show
  1. package/ApiCoreFeature.js +10 -2
  2. package/ApiCoreFeature.js.map +1 -1
  3. package/exports/api/tasks.d.ts +1 -0
  4. package/exports/api/tasks.js +1 -1
  5. package/exports/api.d.ts +2 -1
  6. package/exports/api.js +2 -1
  7. package/features/ai/Ai.d.ts +3 -1
  8. package/features/ai/Ai.js +36 -28
  9. package/features/ai/Ai.js.map +1 -1
  10. package/features/ai/AiModelRegistry.d.ts +14 -0
  11. package/features/ai/AiModelRegistry.js +39 -0
  12. package/features/ai/AiModelRegistry.js.map +1 -0
  13. package/features/ai/AiSdkToolHandlerResolver.d.ts +11 -0
  14. package/features/ai/AiSdkToolHandlerResolver.js +19 -0
  15. package/features/ai/AiSdkToolHandlerResolver.js.map +1 -0
  16. package/features/ai/AiSdkTools.d.ts +4 -3
  17. package/features/ai/AiSdkTools.js +11 -9
  18. package/features/ai/AiSdkTools.js.map +1 -1
  19. package/features/ai/AnthropicSdkFactory.js +12 -4
  20. package/features/ai/AnthropicSdkFactory.js.map +1 -1
  21. package/features/ai/DEVELOPERS.md +183 -0
  22. package/features/ai/GoogleSdkFactory.d.ts +10 -0
  23. package/features/ai/GoogleSdkFactory.js +65 -0
  24. package/features/ai/GoogleSdkFactory.js.map +1 -0
  25. package/features/ai/OpenAiSdkFactory.js +51 -11
  26. package/features/ai/OpenAiSdkFactory.js.map +1 -1
  27. package/features/ai/OpenRouterSdkFactory.d.ts +10 -0
  28. package/features/ai/OpenRouterSdkFactory.js +112 -0
  29. package/features/ai/OpenRouterSdkFactory.js.map +1 -0
  30. package/features/ai/RemoteAiModelCatalog.d.ts +13 -0
  31. package/features/ai/RemoteAiModelCatalog.js +74 -0
  32. package/features/ai/RemoteAiModelCatalog.js.map +1 -0
  33. package/features/ai/abstractions.d.ts +82 -6
  34. package/features/ai/abstractions.js +6 -2
  35. package/features/ai/abstractions.js.map +1 -1
  36. package/features/ai/feature.js +10 -0
  37. package/features/ai/feature.js.map +1 -1
  38. package/features/ai/index.d.ts +2 -4
  39. package/features/ai/index.js +1 -1
  40. package/features/cdnCache/NullCdnCache.d.ts +8 -0
  41. package/features/cdnCache/NullCdnCache.js +11 -0
  42. package/features/cdnCache/NullCdnCache.js.map +1 -0
  43. package/features/cdnCache/abstractions.d.ts +20 -0
  44. package/features/cdnCache/abstractions.js +5 -0
  45. package/features/cdnCache/abstractions.js.map +1 -0
  46. package/features/cdnCache/feature.d.ts +8 -0
  47. package/features/cdnCache/feature.js +11 -0
  48. package/features/cdnCache/feature.js.map +1 -0
  49. package/features/cdnCache/index.d.ts +2 -0
  50. package/features/cdnCache/index.js +2 -0
  51. package/features/debugger/Debugger.d.ts +30 -0
  52. package/features/debugger/Debugger.js +142 -0
  53. package/features/debugger/Debugger.js.map +1 -0
  54. package/features/debugger/DebuggerRouteDecorator.d.ts +45 -0
  55. package/features/debugger/DebuggerRouteDecorator.js +102 -0
  56. package/features/debugger/DebuggerRouteDecorator.js.map +1 -0
  57. package/features/debugger/GraphQLDebuggerTransport.d.ts +28 -0
  58. package/features/debugger/GraphQLDebuggerTransport.js +45 -0
  59. package/features/debugger/GraphQLDebuggerTransport.js.map +1 -0
  60. package/features/debugger/__tests__/matchNamespace.test.d.ts +1 -0
  61. package/features/debugger/__tests__/matchNamespace.test.js +68 -0
  62. package/features/debugger/__tests__/matchNamespace.test.js.map +1 -0
  63. package/features/debugger/__tests__/serialize.test.d.ts +1 -0
  64. package/features/debugger/__tests__/serialize.test.js +220 -0
  65. package/features/debugger/__tests__/serialize.test.js.map +1 -0
  66. package/features/debugger/abstractions.d.ts +100 -0
  67. package/features/debugger/abstractions.js +6 -0
  68. package/features/debugger/abstractions.js.map +1 -0
  69. package/features/debugger/feature.d.ts +5 -0
  70. package/features/debugger/feature.js +15 -0
  71. package/features/debugger/feature.js.map +1 -0
  72. package/features/debugger/index.d.ts +12 -0
  73. package/features/debugger/index.js +7 -0
  74. package/features/debugger/limits.d.ts +18 -0
  75. package/features/debugger/limits.js +11 -0
  76. package/features/debugger/limits.js.map +1 -0
  77. package/features/debugger/matchNamespace.d.ts +14 -0
  78. package/features/debugger/matchNamespace.js +35 -0
  79. package/features/debugger/matchNamespace.js.map +1 -0
  80. package/features/debugger/parseNamespaceHeader.d.ts +7 -0
  81. package/features/debugger/parseNamespaceHeader.js +16 -0
  82. package/features/debugger/parseNamespaceHeader.js.map +1 -0
  83. package/features/debugger/permissions.d.ts +14 -0
  84. package/features/debugger/permissions.js +8 -0
  85. package/features/debugger/permissions.js.map +1 -0
  86. package/features/debugger/permissionsSchema.d.ts +17 -0
  87. package/features/debugger/permissionsSchema.js +18 -0
  88. package/features/debugger/permissionsSchema.js.map +1 -0
  89. package/features/debugger/serialize.d.ts +11 -0
  90. package/features/debugger/serialize.js +121 -0
  91. package/features/debugger/serialize.js.map +1 -0
  92. package/features/encryption/BuildParamsEncryptionConfig.d.ts +13 -0
  93. package/features/encryption/BuildParamsEncryptionConfig.js +19 -0
  94. package/features/encryption/BuildParamsEncryptionConfig.js.map +1 -0
  95. package/features/encryption/EncryptionKeyCacheFeature.d.ts +8 -0
  96. package/features/encryption/EncryptionKeyCacheFeature.js +11 -0
  97. package/features/encryption/EncryptionKeyCacheFeature.js.map +1 -0
  98. package/features/encryption/EncryptionService.d.ts +3 -2
  99. package/features/encryption/EncryptionService.js +15 -13
  100. package/features/encryption/EncryptionService.js.map +1 -1
  101. package/features/encryption/MemoryEncryptionKeyCache.d.ts +13 -0
  102. package/features/encryption/MemoryEncryptionKeyCache.js +26 -0
  103. package/features/encryption/MemoryEncryptionKeyCache.js.map +1 -0
  104. package/features/encryption/abstractions.d.ts +26 -0
  105. package/features/encryption/abstractions.js +3 -1
  106. package/features/encryption/abstractions.js.map +1 -1
  107. package/features/encryption/feature.js +2 -0
  108. package/features/encryption/feature.js.map +1 -1
  109. package/features/encryption/index.d.ts +3 -0
  110. package/features/encryption/index.js +3 -1
  111. package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js +13 -1
  112. package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js.map +1 -1
  113. package/features/hashing/BuildParamsHashingConfig.d.ts +11 -0
  114. package/features/hashing/BuildParamsHashingConfig.js +18 -0
  115. package/features/hashing/BuildParamsHashingConfig.js.map +1 -0
  116. package/features/hashing/ScryptHasher.d.ts +2 -2
  117. package/features/hashing/ScryptHasher.js +6 -8
  118. package/features/hashing/ScryptHasher.js.map +1 -1
  119. package/features/hashing/abstractions.d.ts +15 -0
  120. package/features/hashing/abstractions.js +2 -1
  121. package/features/hashing/abstractions.js.map +1 -1
  122. package/features/hashing/feature.js +2 -0
  123. package/features/hashing/feature.js.map +1 -1
  124. package/features/hashing/index.d.ts +1 -0
  125. package/features/hashing/index.js +1 -1
  126. package/features/httpClient/HttpClient.d.ts +7 -0
  127. package/features/httpClient/HttpClient.js +72 -0
  128. package/features/httpClient/HttpClient.js.map +1 -0
  129. package/features/httpClient/HttpRequestError.d.ts +10 -0
  130. package/features/httpClient/HttpRequestError.js +13 -0
  131. package/features/httpClient/HttpRequestError.js.map +1 -0
  132. package/features/httpClient/HttpStatusError.d.ts +12 -0
  133. package/features/httpClient/HttpStatusError.js +12 -0
  134. package/features/httpClient/HttpStatusError.js.map +1 -0
  135. package/features/httpClient/abstractions.d.ts +32 -0
  136. package/features/httpClient/abstractions.js +5 -0
  137. package/features/httpClient/abstractions.js.map +1 -0
  138. package/features/{logger → httpClient}/feature.d.ts +1 -1
  139. package/features/httpClient/feature.js +11 -0
  140. package/features/httpClient/feature.js.map +1 -0
  141. package/features/httpClient/index.d.ts +3 -0
  142. package/features/httpClient/index.js +3 -0
  143. package/features/keyValueStore/GlobalKeyValueStore.d.ts +9 -3
  144. package/features/keyValueStore/GlobalKeyValueStore.js +12 -2
  145. package/features/keyValueStore/GlobalKeyValueStore.js.map +1 -1
  146. package/features/keyValueStore/KeyValueStore.d.ts +6 -2
  147. package/features/keyValueStore/KeyValueStore.js +13 -3
  148. package/features/keyValueStore/KeyValueStore.js.map +1 -1
  149. package/features/keyValueStore/KeyValueStoreRepository.d.ts +8 -2
  150. package/features/keyValueStore/KeyValueStoreRepository.js +82 -4
  151. package/features/keyValueStore/KeyValueStoreRepository.js.map +1 -1
  152. package/features/keyValueStore/abstractions.d.ts +132 -14
  153. package/features/keyValueStore/abstractions.js.map +1 -1
  154. package/features/keyValueStore/errors.d.ts +29 -0
  155. package/features/keyValueStore/errors.js +49 -1
  156. package/features/keyValueStore/errors.js.map +1 -1
  157. package/features/keyValueStore/index.d.ts +4 -1
  158. package/features/keyValueStore/index.js +1 -1
  159. package/features/logger/NullLogger.d.ts +10 -0
  160. package/features/logger/NullLogger.js +12 -0
  161. package/features/logger/NullLogger.js.map +1 -0
  162. package/features/logger/index.d.ts +1 -0
  163. package/features/logger/index.js +1 -0
  164. package/features/publicUrls/NullPublicUrls.d.ts +11 -0
  165. package/features/publicUrls/NullPublicUrls.js +17 -0
  166. package/features/publicUrls/NullPublicUrls.js.map +1 -0
  167. package/features/publicUrls/PublicUrl.d.ts +24 -0
  168. package/features/publicUrls/PublicUrl.js +43 -0
  169. package/features/publicUrls/PublicUrl.js.map +1 -0
  170. package/features/publicUrls/__tests__/PublicUrl.test.d.ts +1 -0
  171. package/features/publicUrls/__tests__/PublicUrl.test.js +38 -0
  172. package/features/publicUrls/__tests__/PublicUrl.test.js.map +1 -0
  173. package/features/publicUrls/__tests__/PublicUrls.test.d.ts +1 -0
  174. package/features/publicUrls/__tests__/PublicUrls.test.js +14 -0
  175. package/features/publicUrls/__tests__/PublicUrls.test.js.map +1 -0
  176. package/features/publicUrls/abstractions.d.ts +27 -0
  177. package/features/publicUrls/abstractions.js +5 -0
  178. package/features/publicUrls/abstractions.js.map +1 -0
  179. package/features/publicUrls/feature.d.ts +8 -0
  180. package/features/publicUrls/feature.js +11 -0
  181. package/features/publicUrls/feature.js.map +1 -0
  182. package/features/publicUrls/index.d.ts +3 -0
  183. package/features/publicUrls/index.js +3 -0
  184. package/features/requestContext/RawAssumePermissions.d.ts +14 -0
  185. package/features/requestContext/RawAssumePermissions.js +19 -0
  186. package/features/requestContext/RawAssumePermissions.js.map +1 -0
  187. package/features/requestContext/abstractions.d.ts +22 -0
  188. package/features/requestContext/abstractions.js +2 -1
  189. package/features/requestContext/abstractions.js.map +1 -1
  190. package/features/requestContext/extractAssumePermissions.d.ts +14 -0
  191. package/features/requestContext/extractAssumePermissions.js +32 -0
  192. package/features/requestContext/extractAssumePermissions.js.map +1 -0
  193. package/features/requestContext/feature.d.ts +2 -1
  194. package/features/requestContext/feature.js +2 -0
  195. package/features/requestContext/feature.js.map +1 -1
  196. package/features/requestContext/index.d.ts +3 -1
  197. package/features/requestContext/index.js +2 -1
  198. package/features/requestStorage/abstractions.d.ts +23 -0
  199. package/features/requestStorage/abstractions.js +5 -0
  200. package/features/requestStorage/abstractions.js.map +1 -0
  201. package/features/requestStorage/index.d.ts +1 -0
  202. package/features/requestStorage/index.js +1 -0
  203. package/features/security/IdentityContext/IdentityContext.d.ts +6 -2
  204. package/features/security/IdentityContext/IdentityContext.js +24 -7
  205. package/features/security/IdentityContext/IdentityContext.js.map +1 -1
  206. package/features/security/IdentityContext/abstractions.d.ts +6 -1
  207. package/features/security/IdentityContext/abstractions.js.map +1 -1
  208. package/features/security/authorization/AuthorizationContext/AuthorizationContext.d.ts +13 -3
  209. package/features/security/authorization/AuthorizationContext/AuthorizationContext.js +35 -22
  210. package/features/security/authorization/AuthorizationContext/AuthorizationContext.js.map +1 -1
  211. package/features/security/authorization/AuthorizationContext/abstractions.d.ts +2 -0
  212. package/features/security/authorization/AuthorizationContext/abstractions.js.map +1 -1
  213. package/features/security/authorization/AuthorizationContext/feature.js +6 -1
  214. package/features/security/authorization/AuthorizationContext/feature.js.map +1 -1
  215. package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.d.ts +30 -0
  216. package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.js +60 -0
  217. package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.js.map +1 -0
  218. package/features/security/authorization/GroupsTeamsAuthorizer/feature.js +2 -0
  219. package/features/security/authorization/GroupsTeamsAuthorizer/feature.js.map +1 -1
  220. package/features/security/roles/Installer/RolesInstaller.js +1 -0
  221. package/features/security/roles/Installer/RolesInstaller.js.map +1 -1
  222. package/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.d.ts +11 -0
  223. package/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.js +22 -0
  224. package/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.js.map +1 -0
  225. package/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.d.ts +11 -0
  226. package/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.js +22 -0
  227. package/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.js.map +1 -0
  228. package/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.d.ts +11 -0
  229. package/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.js +22 -0
  230. package/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.js.map +1 -0
  231. package/features/security/roles/NotifyRoleChange/NotifyRoleChangeUseCase.d.ts +11 -0
  232. package/features/security/roles/NotifyRoleChange/NotifyRoleChangeUseCase.js +40 -0
  233. package/features/security/roles/NotifyRoleChange/NotifyRoleChangeUseCase.js.map +1 -0
  234. package/features/security/roles/NotifyRoleChange/abstractions.d.ts +21 -0
  235. package/features/security/roles/NotifyRoleChange/abstractions.js +8 -0
  236. package/features/security/roles/NotifyRoleChange/abstractions.js.map +1 -0
  237. package/features/security/roles/NotifyRoleChange/feature.d.ts +5 -0
  238. package/features/security/roles/NotifyRoleChange/feature.js +17 -0
  239. package/features/security/roles/NotifyRoleChange/feature.js.map +1 -0
  240. package/features/security/roles/NotifyRoleChange/index.d.ts +2 -0
  241. package/features/security/roles/NotifyRoleChange/index.js +2 -0
  242. package/features/security/roles/UpdateRole/UpdateRoleUseCase.js +2 -1
  243. package/features/security/roles/UpdateRole/UpdateRoleUseCase.js.map +1 -1
  244. package/features/security/roles/feature.js +2 -0
  245. package/features/security/roles/feature.js.map +1 -1
  246. package/features/security/shared/definedOnly.d.ts +1 -0
  247. package/features/security/shared/definedOnly.js +8 -0
  248. package/features/security/shared/definedOnly.js.map +1 -0
  249. package/features/security/shared/index.d.ts +1 -0
  250. package/features/security/shared/index.js +1 -0
  251. package/features/security/teams/NotifyTeamChange/NotifyOnTeamChangeHandlers.d.ts +29 -0
  252. package/features/security/teams/NotifyTeamChange/NotifyOnTeamChangeHandlers.js +58 -0
  253. package/features/security/teams/NotifyTeamChange/NotifyOnTeamChangeHandlers.js.map +1 -0
  254. package/features/security/teams/NotifyTeamChange/NotifyTeamChangeUseCase.d.ts +11 -0
  255. package/features/security/teams/NotifyTeamChange/NotifyTeamChangeUseCase.js +40 -0
  256. package/features/security/teams/NotifyTeamChange/NotifyTeamChangeUseCase.js.map +1 -0
  257. package/features/security/teams/NotifyTeamChange/abstractions.d.ts +21 -0
  258. package/features/security/teams/NotifyTeamChange/abstractions.js +8 -0
  259. package/features/security/teams/NotifyTeamChange/abstractions.js.map +1 -0
  260. package/features/security/teams/NotifyTeamChange/feature.d.ts +5 -0
  261. package/features/security/teams/NotifyTeamChange/feature.js +15 -0
  262. package/features/security/teams/NotifyTeamChange/feature.js.map +1 -0
  263. package/features/security/teams/NotifyTeamChange/index.d.ts +2 -0
  264. package/features/security/teams/NotifyTeamChange/index.js +2 -0
  265. package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js +2 -1
  266. package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js.map +1 -1
  267. package/features/security/teams/feature.js +2 -0
  268. package/features/security/teams/feature.js.map +1 -1
  269. package/features/task/TaskDefinition/abstractions.d.ts +13 -20
  270. package/features/task/TaskDefinition/abstractions.js.map +1 -1
  271. package/features/task/TaskService/abstractions.d.ts +7 -0
  272. package/features/task/TaskService/abstractions.js.map +1 -1
  273. package/features/tenancy/TenantContext/TenantContext.d.ts +5 -1
  274. package/features/tenancy/TenantContext/TenantContext.js +31 -23
  275. package/features/tenancy/TenantContext/TenantContext.js.map +1 -1
  276. package/features/users/shared/loaders.js.map +1 -1
  277. package/features/users/shared/types.d.ts +9 -7
  278. package/features/wcp/WcpContext/WcpContext.d.ts +6 -1
  279. package/features/wcp/WcpContext/WcpContext.js +17 -2
  280. package/features/wcp/WcpContext/WcpContext.js.map +1 -1
  281. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +9 -73
  282. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +25 -5
  283. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
  284. package/features/wcp/WcpLicenseLoader.js.map +1 -1
  285. package/features/wcp/resolveWcpProjectEnvironment.d.ts +1 -1
  286. package/features/wcp/resolveWcpProjectEnvironment.js.map +1 -1
  287. package/features/websockets/SendToIdentity/NullSendToIdentityUseCase.d.ts +20 -0
  288. package/features/websockets/SendToIdentity/NullSendToIdentityUseCase.js +24 -0
  289. package/features/websockets/SendToIdentity/NullSendToIdentityUseCase.js.map +1 -0
  290. package/features/websockets/SendToIdentity/abstractions.d.ts +19 -0
  291. package/features/websockets/SendToIdentity/abstractions.js +5 -0
  292. package/features/websockets/SendToIdentity/abstractions.js.map +1 -0
  293. package/features/websockets/WebsocketServiceError.d.ts +7 -0
  294. package/features/websockets/WebsocketServiceError.js +14 -0
  295. package/features/websockets/WebsocketServiceError.js.map +1 -0
  296. package/features/websockets/index.d.ts +6 -0
  297. package/features/websockets/index.js +3 -0
  298. package/features/websockets/types.d.ts +15 -0
  299. package/features/websockets/types.js +0 -0
  300. package/graphql/ApiCoreSchemaFactory.d.ts +1 -0
  301. package/graphql/ApiCoreSchemaFactory.js +7 -1
  302. package/graphql/ApiCoreSchemaFactory.js.map +1 -1
  303. package/graphql/featureFlags/FeatureFlagsSchemaFactory.d.ts +1 -0
  304. package/graphql/featureFlags/FeatureFlagsSchemaFactory.js +4 -0
  305. package/graphql/featureFlags/FeatureFlagsSchemaFactory.js.map +1 -1
  306. package/graphql/security/SecuritySchemaFactory.d.ts +1 -0
  307. package/graphql/security/SecuritySchemaFactory.js +4 -0
  308. package/graphql/security/SecuritySchemaFactory.js.map +1 -1
  309. package/graphql/system/SystemSchemaFactory.d.ts +1 -0
  310. package/graphql/system/SystemSchemaFactory.js +4 -0
  311. package/graphql/system/SystemSchemaFactory.js.map +1 -1
  312. package/graphql/users/UsersSchemaFactory.d.ts +1 -0
  313. package/graphql/users/UsersSchemaFactory.js +4 -0
  314. package/graphql/users/UsersSchemaFactory.js.map +1 -1
  315. package/graphql/wcp/WcpSchemaFactory.d.ts +1 -0
  316. package/graphql/wcp/WcpSchemaFactory.js +5 -1
  317. package/graphql/wcp/WcpSchemaFactory.js.map +1 -1
  318. package/idp/JwksCache.d.ts +14 -3
  319. package/idp/JwksCache.js +97 -17
  320. package/idp/JwksCache.js.map +1 -1
  321. package/idp/JwksStoreFeature.d.ts +8 -0
  322. package/idp/JwksStoreFeature.js +11 -0
  323. package/idp/JwksStoreFeature.js.map +1 -0
  324. package/idp/MemoryJwksStore.d.ts +14 -0
  325. package/idp/MemoryJwksStore.js +21 -0
  326. package/idp/MemoryJwksStore.js.map +1 -0
  327. package/idp/OidcJwtIdentityProvider.js +5 -1
  328. package/idp/OidcJwtIdentityProvider.js.map +1 -1
  329. package/idp/abstractions.d.ts +24 -0
  330. package/idp/abstractions.js +2 -1
  331. package/idp/abstractions.js.map +1 -1
  332. package/idp/feature.js +1 -2
  333. package/idp/feature.js.map +1 -1
  334. package/idp/index.d.ts +1 -0
  335. package/idp/index.js +1 -0
  336. package/index.d.ts +1 -0
  337. package/index.js +1 -0
  338. package/package.json +21 -21
  339. package/types/users.d.ts +2 -3
  340. package/features/logger/LoggerService.d.ts +0 -14
  341. package/features/logger/LoggerService.js +0 -48
  342. package/features/logger/LoggerService.js.map +0 -1
  343. package/features/logger/feature.js +0 -11
  344. package/features/logger/feature.js.map +0 -1
@@ -1,33 +1,44 @@
1
- import { AsyncLocalStorage } from "async_hooks";
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
2
  import { minimatch } from "minimatch";
3
3
  import { createImplementation } from "@webiny/di";
4
+ import { HandlerExecution } from "@webiny/event-handler-core";
4
5
  import { IdentityContext } from "./abstractions.js";
5
6
  import { AnonymousIdentity } from "./AnonymousIdentity.js";
6
7
  import { AuthorizationContext } from "../authorization/AuthorizationContext/index.js";
7
8
  import { filterOutCustomWbyAppsPermissions } from "../utils/filterOutCustomWbyAppsPermissions.js";
8
9
  import { FeatureFlags } from "../../featureFlags/abstractions.js";
9
- const identityStorage = new AsyncLocalStorage();
10
10
  class IdentityContextImpl {
11
- constructor(authorizationContext, featureFlags){
11
+ constructor(authorizationContext, featureFlags, handlerExecution){
12
12
  this.authorizationContext = authorizationContext;
13
13
  this.featureFlags = featureFlags;
14
+ this.handlerExecution = handlerExecution;
14
15
  this.identity = new AnonymousIdentity();
16
+ this.overrides = new AsyncLocalStorage();
15
17
  }
16
18
  getIdentity() {
17
- const override = identityStorage.getStore();
18
- if (void 0 !== override) return override;
19
+ this.handlerExecution?.assertCurrent("IdentityContext");
20
+ const override = this.overrides.getStore();
21
+ if (override) return override;
19
22
  return this.identity;
20
23
  }
21
24
  setIdentity(identity) {
25
+ this.handlerExecution?.assertCurrent("IdentityContext");
26
+ if (this.overrides.getStore()) throw new Error("IdentityContext.setIdentity() was called inside a withIdentity() callback. Call withIdentity() instead, so the switch stays inside its own callback.");
22
27
  this.identity = identity ?? new AnonymousIdentity();
23
28
  this.authorizationContext.clearPermissionsCache();
24
29
  }
25
30
  withIdentity(identity, cb) {
26
- return identityStorage.run(identity, cb);
31
+ this.handlerExecution?.assertCurrent("IdentityContext");
32
+ return this.overrides.run(identity, cb);
27
33
  }
28
34
  withoutAuthorization(cb) {
35
+ this.handlerExecution?.assertCurrent("IdentityContext");
29
36
  return this.authorizationContext.withoutAuthorization(cb);
30
37
  }
38
+ withAuthorization(cb) {
39
+ this.handlerExecution?.assertCurrent("IdentityContext");
40
+ return this.authorizationContext.withAuthorization(cb);
41
+ }
31
42
  isAuthorizationEnabled() {
32
43
  return this.authorizationContext.isAuthorizationEnabled();
33
44
  }
@@ -80,7 +91,13 @@ const IdentityContext_IdentityContext = createImplementation({
80
91
  implementation: IdentityContextImpl,
81
92
  dependencies: [
82
93
  AuthorizationContext,
83
- FeatureFlags
94
+ FeatureFlags,
95
+ [
96
+ HandlerExecution,
97
+ {
98
+ optional: true
99
+ }
100
+ ]
84
101
  ]
85
102
  });
86
103
  export { IdentityContext_IdentityContext as IdentityContext };
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/IdentityContext/IdentityContext.js","sources":["../../../../src/features/security/IdentityContext/IdentityContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\nimport { minimatch } from \"minimatch\";\nimport { createImplementation } from \"@webiny/di\";\nimport { IdentityContext as Abstraction } from \"./abstractions.js\";\nimport { Identity } from \"./Identity.js\";\nimport { AnonymousIdentity } from \"./AnonymousIdentity.js\";\nimport { AuthorizationContext } from \"../authorization/AuthorizationContext/index.js\";\nimport { filterOutCustomWbyAppsPermissions } from \"../utils/filterOutCustomWbyAppsPermissions.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport type { AaclPermission } from \"../../wcp/WcpContext/types.js\";\nimport { FeatureFlags } from \"../../featureFlags/abstractions.js\";\n\nconst identityStorage = new AsyncLocalStorage<Identity | undefined>();\n\nclass IdentityContextImpl implements Abstraction.Interface {\n private identity: Identity = new AnonymousIdentity();\n\n constructor(\n private authorizationContext: AuthorizationContext.Interface,\n private featureFlags: FeatureFlags.Interface\n ) {}\n\n // ========================================================================\n // Identity Methods\n // ========================================================================\n\n getIdentity(): Identity {\n // Check for identity override first (from withIdentity())\n const override = identityStorage.getStore();\n if (override !== undefined) {\n return override;\n }\n return this.identity;\n }\n\n setIdentity(identity: Identity | undefined): void {\n // If undefined, set to anonymous identity\n this.identity = identity ?? new AnonymousIdentity();\n\n // Clear permissions cache when identity changes\n this.authorizationContext.clearPermissionsCache();\n }\n\n withIdentity<T>(identity: Identity | undefined, cb: () => Promise<T>): Promise<T> {\n return identityStorage.run(identity, cb);\n }\n\n // ========================================================================\n // Authorization State Methods\n // ========================================================================\n\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n return this.authorizationContext.withoutAuthorization(cb);\n }\n\n isAuthorizationEnabled(): boolean {\n return this.authorizationContext.isAuthorizationEnabled();\n }\n\n // ========================================================================\n // Permission Methods\n // ========================================================================\n\n async getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission | null> {\n if (!this.isAuthorizationEnabled()) {\n return { name: \"*\" } as TPermission;\n }\n\n const permissions = await this.listPermissions();\n\n // Try exact match first\n const exactMatch = permissions.find(p => p.name === name);\n if (exactMatch) {\n return exactMatch as TPermission;\n }\n\n // Try pattern matching\n const patternMatch = permissions.find(p => minimatch(name, p.name));\n if (patternMatch) {\n return patternMatch as TPermission;\n }\n\n return null;\n }\n\n async getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission[]> {\n if (!this.isAuthorizationEnabled()) {\n return [{ name: \"*\" }] as TPermission[];\n }\n\n const permissions = await this.listPermissions();\n\n return permissions.filter(p => {\n if (p.name === name) {\n return true;\n }\n return minimatch(name, p.name);\n }) as TPermission[];\n }\n\n async listPermissions(): Promise<SecurityPermission[]> {\n const permissions = await this.authorizationContext.loadPermissions(this.getIdentity());\n // TODO: extract this into a decorator\n return this.applyAaclLogic(permissions);\n }\n\n async hasFullAccess(): Promise<boolean> {\n const permissions = await this.listPermissions();\n return permissions.some(p => p.name === \"*\");\n }\n\n // ========================================================================\n // Private Helper Methods\n // ========================================================================\n\n private applyAaclLogic(permissions: SecurityPermission[]): SecurityPermission[] {\n const aaclEnabled = this.featureFlags.get().isEnabled(\"advancedAccessControlLayer\");\n const teamsEnabled = this.featureFlags.get().isEnabled(\"advancedAccessControlLayer.teams\");\n\n if (aaclEnabled) {\n // Add AACL metadata permission\n return [\n ...permissions,\n {\n name: \"aacl\",\n teams: teamsEnabled\n } as AaclPermission\n ];\n }\n\n // If AACL is not enabled, filter out custom Webiny apps permissions\n return filterOutCustomWbyAppsPermissions(permissions);\n }\n}\n\nexport const IdentityContext = createImplementation({\n abstraction: Abstraction,\n implementation: IdentityContextImpl,\n dependencies: [AuthorizationContext, FeatureFlags]\n});\n"],"names":["identityStorage","AsyncLocalStorage","IdentityContextImpl","authorizationContext","featureFlags","AnonymousIdentity","override","undefined","identity","cb","name","permissions","exactMatch","p","patternMatch","minimatch","aaclEnabled","teamsEnabled","filterOutCustomWbyAppsPermissions","IdentityContext","createImplementation","Abstraction","AuthorizationContext","FeatureFlags"],"mappings":";;;;;;;;AAYA,MAAMA,kBAAkB,IAAIC;AAE5B,MAAMC;IAGF,YACYC,oBAAoD,EACpDC,YAAoC,CAC9C;aAFUD,oBAAoB,GAApBA;aACAC,YAAY,GAAZA;aAJJ,QAAQ,GAAa,IAAIC;IAK9B;IAMH,cAAwB;QAEpB,MAAMC,WAAWN,gBAAgB,QAAQ;QACzC,IAAIM,AAAaC,WAAbD,UACA,OAAOA;QAEX,OAAO,IAAI,CAAC,QAAQ;IACxB;IAEA,YAAYE,QAA8B,EAAQ;QAE9C,IAAI,CAAC,QAAQ,GAAGA,YAAY,IAAIH;QAGhC,IAAI,CAAC,oBAAoB,CAAC,qBAAqB;IACnD;IAEA,aAAgBG,QAA8B,EAAEC,EAAoB,EAAc;QAC9E,OAAOT,gBAAgB,GAAG,CAACQ,UAAUC;IACzC;IAMA,qBAAwBA,EAAoB,EAAc;QACtD,OAAO,IAAI,CAAC,oBAAoB,CAAC,oBAAoB,CAACA;IAC1D;IAEA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OM;YACX;SACH;QAIL,OAAOC,kCAAkCP;IAC7C;AACJ;AAEO,MAAMQ,kCAAkBC,qBAAqB;IAChD,aAAaC;IACb,gBAAgBnB;IAChB,cAAc;QAACoB;QAAsBC;KAAa;AACtD"}
1
+ {"version":3,"file":"features/security/IdentityContext/IdentityContext.js","sources":["../../../../src/features/security/IdentityContext/IdentityContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { minimatch } from \"minimatch\";\nimport { createImplementation } from \"@webiny/di\";\nimport { HandlerExecution } from \"@webiny/event-handler-core\";\nimport { IdentityContext as Abstraction } from \"./abstractions.js\";\nimport { Identity } from \"./Identity.js\";\nimport { AnonymousIdentity } from \"./AnonymousIdentity.js\";\nimport { AuthorizationContext } from \"../authorization/AuthorizationContext/index.js\";\nimport { filterOutCustomWbyAppsPermissions } from \"../utils/filterOutCustomWbyAppsPermissions.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport type { AaclPermission } from \"../../wcp/WcpContext/types.js\";\nimport { FeatureFlags } from \"../../featureFlags/abstractions.js\";\n\nclass IdentityContextImpl implements Abstraction.Interface {\n private identity: Identity = new AnonymousIdentity();\n /*\n * `withIdentity()` switches the identity for its callback's async call chain only, the same way\n * `TenantContext.withTenant()` switches the tenant.\n */\n private readonly overrides = new AsyncLocalStorage<Identity>();\n\n constructor(\n private authorizationContext: AuthorizationContext.Interface,\n private featureFlags: FeatureFlags.Interface,\n private handlerExecution: HandlerExecution.Interface | undefined\n ) {}\n\n // ========================================================================\n // Identity Methods\n // ========================================================================\n\n getIdentity(): Identity {\n this.handlerExecution?.assertCurrent(\"IdentityContext\");\n\n const override = this.overrides.getStore();\n if (override) {\n return override;\n }\n return this.identity;\n }\n\n /*\n * Sets the request's identity. Inside a `withIdentity()` callback it throws: the callback would\n * keep reading its own identity, and the change would only show once the callback ended, in the\n * rest of the request.\n */\n setIdentity(identity: Identity | undefined): void {\n this.handlerExecution?.assertCurrent(\"IdentityContext\");\n\n if (this.overrides.getStore()) {\n throw new Error(\n \"IdentityContext.setIdentity() was called inside a withIdentity() callback. Call withIdentity() instead, so the switch stays inside its own callback.\"\n );\n }\n\n // If undefined, set to anonymous identity\n this.identity = identity ?? new AnonymousIdentity();\n\n // Clear permissions cache when identity changes\n this.authorizationContext.clearPermissionsCache();\n }\n\n withIdentity<T>(identity: Identity, cb: () => Promise<T>): Promise<T> {\n this.handlerExecution?.assertCurrent(\"IdentityContext\");\n return this.overrides.run(identity, cb);\n }\n\n // ========================================================================\n // Authorization State Methods\n // ========================================================================\n\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n this.handlerExecution?.assertCurrent(\"IdentityContext\");\n return this.authorizationContext.withoutAuthorization(cb);\n }\n\n withAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n this.handlerExecution?.assertCurrent(\"IdentityContext\");\n return this.authorizationContext.withAuthorization(cb);\n }\n\n isAuthorizationEnabled(): boolean {\n return this.authorizationContext.isAuthorizationEnabled();\n }\n\n // ========================================================================\n // Permission Methods\n // ========================================================================\n\n async getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission | null> {\n if (!this.isAuthorizationEnabled()) {\n return { name: \"*\" } as TPermission;\n }\n\n const permissions = await this.listPermissions();\n\n // Try exact match first\n const exactMatch = permissions.find(p => p.name === name);\n if (exactMatch) {\n return exactMatch as TPermission;\n }\n\n // Try pattern matching\n const patternMatch = permissions.find(p => minimatch(name, p.name));\n if (patternMatch) {\n return patternMatch as TPermission;\n }\n\n return null;\n }\n\n async getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission[]> {\n if (!this.isAuthorizationEnabled()) {\n return [{ name: \"*\" }] as TPermission[];\n }\n\n const permissions = await this.listPermissions();\n\n return permissions.filter(p => {\n if (p.name === name) {\n return true;\n }\n return minimatch(name, p.name);\n }) as TPermission[];\n }\n\n async listPermissions(): Promise<SecurityPermission[]> {\n const permissions = await this.authorizationContext.loadPermissions(this.getIdentity());\n // TODO: extract this into a decorator\n return this.applyAaclLogic(permissions);\n }\n\n async hasFullAccess(): Promise<boolean> {\n const permissions = await this.listPermissions();\n return permissions.some(p => p.name === \"*\");\n }\n\n // ========================================================================\n // Private Helper Methods\n // ========================================================================\n\n private applyAaclLogic(permissions: SecurityPermission[]): SecurityPermission[] {\n const aaclEnabled = this.featureFlags.get().isEnabled(\"advancedAccessControlLayer\");\n const teamsEnabled = this.featureFlags.get().isEnabled(\"advancedAccessControlLayer.teams\");\n\n if (aaclEnabled) {\n // Add AACL metadata permission\n return [\n ...permissions,\n {\n name: \"aacl\",\n teams: teamsEnabled\n } as AaclPermission\n ];\n }\n\n // If AACL is not enabled, filter out custom Webiny apps permissions\n return filterOutCustomWbyAppsPermissions(permissions);\n }\n}\n\nexport const IdentityContext = createImplementation({\n abstraction: Abstraction,\n implementation: IdentityContextImpl,\n dependencies: [AuthorizationContext, FeatureFlags, [HandlerExecution, { optional: true }]]\n});\n"],"names":["IdentityContextImpl","authorizationContext","featureFlags","handlerExecution","AnonymousIdentity","AsyncLocalStorage","override","identity","Error","cb","name","permissions","exactMatch","p","patternMatch","minimatch","aaclEnabled","teamsEnabled","filterOutCustomWbyAppsPermissions","IdentityContext","createImplementation","Abstraction","AuthorizationContext","FeatureFlags","HandlerExecution"],"mappings":";;;;;;;;;AAaA,MAAMA;IAQF,YACYC,oBAAoD,EACpDC,YAAoC,EACpCC,gBAAwD,CAClE;aAHUF,oBAAoB,GAApBA;aACAC,YAAY,GAAZA;aACAC,gBAAgB,GAAhBA;aAVJ,QAAQ,GAAa,IAAIC;QAIhC,KACgB,SAAS,GAAG,IAAIC;IAM9B;IAMH,cAAwB;QACpB,IAAI,CAAC,gBAAgB,EAAE,cAAc;QAErC,MAAMC,WAAW,IAAI,CAAC,SAAS,CAAC,QAAQ;QACxC,IAAIA,UACA,OAAOA;QAEX,OAAO,IAAI,CAAC,QAAQ;IACxB;IAOA,YAAYC,QAA8B,EAAQ;QAC9C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A,EAAE,IAAI,KAAKH,MACX,OAAO;YAEX,OAAOK,UAAUL,MAAMG,EAAE,IAAI;QACjC;IACJ;IAEA,MAAM,kBAAiD;QACnD,MAAMF,cAAc,MAAM,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW;QAEpF,OAAO,IAAI,CAAC,cAAc,CAACA;IAC/B;IAEA,MAAM,gBAAkC;QACpC,MAAMA,cAAc,MAAM,IAAI,CAAC,eAAe;QAC9C,OAAOA,YAAY,IAAI,CAACE,CAAAA,IAAKA,AAAW,QAAXA,EAAE,IAAI;IACvC;IAMQ,eAAeF,WAAiC,EAAwB;QAC5E,MAAMK,cAAc,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC;QACtD,MAAMC,eAAe,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC;QAEvD,IAAID,aAEA,OAAO;eACAL;YACH;gBACI,MAAM;gBACN,OAAOM;YACX;SACH;QAIL,OAAOC,kCAAkCP;IAC7C;AACJ;AAEO,MAAMQ,kCAAkBC,qBAAqB;IAChD,aAAaC;IACb,gBAAgBrB;IAChB,cAAc;QAACsB;QAAsBC;QAAc;YAACC;YAAkB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAC9F"}
@@ -3,12 +3,17 @@ import type { SecurityPermission } from "../../../types/security.js";
3
3
  export interface IIdentityContext {
4
4
  getIdentity(): Identity;
5
5
  setIdentity(identity: Identity | undefined): void;
6
- withIdentity<T>(identity: Identity | undefined, cb: () => Promise<T>): Promise<T>;
6
+ withIdentity<T>(identity: Identity, cb: () => Promise<T>): Promise<T>;
7
7
  getPermission<TPermission extends SecurityPermission = SecurityPermission>(name: string): Promise<TPermission | null>;
8
8
  getPermissions<TPermission extends SecurityPermission = SecurityPermission>(name: string): Promise<TPermission[]>;
9
9
  listPermissions(): Promise<SecurityPermission[]>;
10
10
  hasFullAccess(): Promise<boolean>;
11
11
  withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;
12
+ /**
13
+ * Runs `cb` with authorization enabled, also inside `withoutAuthorization`. Combine with
14
+ * `withIdentity` to evaluate another user's real permissions from a background task.
15
+ */
16
+ withAuthorization<T>(cb: () => Promise<T>): Promise<T>;
12
17
  isAuthorizationEnabled(): boolean;
13
18
  }
14
19
  /** Provides access to the current identity and its permissions. */
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/IdentityContext/abstractions.js","sources":["../../../../src/features/security/IdentityContext/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Identity } from \"./Identity.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\n\nexport interface IIdentityContext {\n // Identity methods\n getIdentity(): Identity;\n setIdentity(identity: Identity | undefined): void;\n withIdentity<T>(identity: Identity | undefined, cb: () => Promise<T>): Promise<T>;\n\n // Permission methods\n getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission | null>;\n\n getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission[]>;\n\n listPermissions(): Promise<SecurityPermission[]>;\n\n hasFullAccess(): Promise<boolean>;\n\n // Authorization context methods\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;\n isAuthorizationEnabled(): boolean;\n}\n\n/** Provides access to the current identity and its permissions. */\nexport const IdentityContext = createAbstraction<IIdentityContext>(\"IdentityContext\");\n\nexport namespace IdentityContext {\n export type Interface = IIdentityContext;\n}\n"],"names":["IdentityContext","createAbstraction"],"mappings":";AA6BO,MAAMA,kBAAkBC,kBAAoC"}
1
+ {"version":3,"file":"features/security/IdentityContext/abstractions.js","sources":["../../../../src/features/security/IdentityContext/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Identity } from \"./Identity.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\n\nexport interface IIdentityContext {\n // Identity methods\n getIdentity(): Identity;\n setIdentity(identity: Identity | undefined): void;\n withIdentity<T>(identity: Identity, cb: () => Promise<T>): Promise<T>;\n\n // Permission methods\n getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission | null>;\n\n getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<TPermission[]>;\n\n listPermissions(): Promise<SecurityPermission[]>;\n\n hasFullAccess(): Promise<boolean>;\n\n // Authorization context methods\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;\n /**\n * Runs `cb` with authorization enabled, also inside `withoutAuthorization`. Combine with\n * `withIdentity` to evaluate another user's real permissions from a background task.\n */\n withAuthorization<T>(cb: () => Promise<T>): Promise<T>;\n isAuthorizationEnabled(): boolean;\n}\n\n/** Provides access to the current identity and its permissions. */\nexport const IdentityContext = createAbstraction<IIdentityContext>(\"IdentityContext\");\n\nexport namespace IdentityContext {\n export type Interface = IIdentityContext;\n}\n"],"names":["IdentityContext","createAbstraction"],"mappings":";AAkCO,MAAMA,kBAAkBC,kBAAoC"}
@@ -2,16 +2,26 @@ import { AuthorizationContext as Abstraction, PermissionTransformer } from "./ab
2
2
  import { Authorizer } from "../Authorizer/index.js";
3
3
  import type { SecurityPermission } from "../../../../types/security.js";
4
4
  import { Identity } from "../../../../features/security/IdentityContext/index.js";
5
+ /**
6
+ * Loads and caches permissions per identity object and tenant for the lifetime of the request.
7
+ * `IdentityContext.withIdentity` can switch the identity mid-request and `TenantContext` the
8
+ * tenant, so permissions loaded for one identity or tenant never answer for another. Keying by the
9
+ * object (not by id or a fingerprint) means two identities with the same id but a different
10
+ * context never share an entry (R69). A failed load is evicted, so the next check retries.
11
+ */
5
12
  export declare class AuthorizationContext implements Abstraction.Interface {
6
13
  private getAuthorizers;
7
14
  private getTransformers;
8
- private permissions?;
9
- private permissionsLoader?;
10
- constructor(getAuthorizers: () => Authorizer.Interface[], getTransformers: () => PermissionTransformer.Interface[]);
15
+ private getTenantId;
16
+ private permissionsByIdentity;
17
+ private readonly authorizationEnabledOverrides;
18
+ constructor(getAuthorizers: () => Authorizer.Interface[], getTransformers: () => PermissionTransformer.Interface[], getTenantId: () => string | null);
11
19
  loadPermissions(identity: Identity): Promise<SecurityPermission[]>;
12
20
  isAuthorizationEnabled(): boolean;
13
21
  withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;
22
+ withAuthorization<T>(cb: () => Promise<T>): Promise<T>;
14
23
  clearPermissionsCache(): void;
24
+ private authorize;
15
25
  private transformPermissions;
16
26
  private deduplicatePermissions;
17
27
  }
@@ -1,37 +1,50 @@
1
- import { AsyncLocalStorage } from "async_hooks";
2
- const authorizationEnabledStorage = new AsyncLocalStorage();
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ const NO_TENANT = "";
3
3
  class AuthorizationContext {
4
- constructor(getAuthorizers, getTransformers){
4
+ constructor(getAuthorizers, getTransformers, getTenantId){
5
5
  this.getAuthorizers = getAuthorizers;
6
6
  this.getTransformers = getTransformers;
7
+ this.getTenantId = getTenantId;
8
+ this.permissionsByIdentity = new WeakMap();
9
+ this.authorizationEnabledOverrides = new AsyncLocalStorage();
7
10
  }
8
- async loadPermissions(identity) {
9
- if (this.permissions) return this.permissions;
10
- if (this.permissionsLoader) return this.permissionsLoader;
11
- this.permissionsLoader = new Promise(async (resolve)=>{
12
- const authorizers = this.getAuthorizers();
13
- for (const authorizer of authorizers){
14
- const permissions = await authorizer.authorize(identity);
15
- if (Array.isArray(permissions)) {
16
- this.permissions = this.transformPermissions(permissions);
17
- return resolve(this.permissions);
18
- }
19
- }
20
- this.permissions = [];
21
- resolve(this.permissions);
11
+ loadPermissions(identity) {
12
+ let byTenant = this.permissionsByIdentity.get(identity);
13
+ if (!byTenant) {
14
+ byTenant = new Map();
15
+ this.permissionsByIdentity.set(identity, byTenant);
16
+ }
17
+ const tenantKey = this.getTenantId() ?? NO_TENANT;
18
+ const cached = byTenant.get(tenantKey);
19
+ if (cached) return cached;
20
+ const loader = this.authorize(identity);
21
+ byTenant.set(tenantKey, loader);
22
+ const cache = byTenant;
23
+ loader.catch(()=>{
24
+ if (cache.get(tenantKey) === loader) cache.delete(tenantKey);
22
25
  });
23
- return this.permissionsLoader;
26
+ return loader;
24
27
  }
25
28
  isAuthorizationEnabled() {
26
- const override = authorizationEnabledStorage.getStore();
29
+ const override = this.authorizationEnabledOverrides.getStore();
27
30
  return override ?? true;
28
31
  }
29
32
  withoutAuthorization(cb) {
30
- return authorizationEnabledStorage.run(false, cb);
33
+ return this.authorizationEnabledOverrides.run(false, cb);
34
+ }
35
+ withAuthorization(cb) {
36
+ return this.authorizationEnabledOverrides.run(true, cb);
31
37
  }
32
38
  clearPermissionsCache() {
33
- this.permissions = void 0;
34
- this.permissionsLoader = void 0;
39
+ this.permissionsByIdentity = new WeakMap();
40
+ }
41
+ async authorize(identity) {
42
+ const authorizers = this.getAuthorizers();
43
+ for (const authorizer of authorizers){
44
+ const permissions = await authorizer.authorize(identity);
45
+ if (Array.isArray(permissions)) return this.transformPermissions(permissions);
46
+ }
47
+ return [];
35
48
  }
36
49
  transformPermissions(permissions) {
37
50
  const transformers = this.getTransformers();
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/authorization/AuthorizationContext/AuthorizationContext.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/AuthorizationContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\nimport { AuthorizationContext as Abstraction, PermissionTransformer } from \"./abstractions.js\";\nimport { Authorizer } from \"../Authorizer/index.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\n\nconst authorizationEnabledStorage = new AsyncLocalStorage<boolean>();\n\nexport class AuthorizationContext implements Abstraction.Interface {\n private permissions?: SecurityPermission[];\n private permissionsLoader?: Promise<SecurityPermission[]>;\n\n constructor(\n private getAuthorizers: () => Authorizer.Interface[],\n private getTransformers: () => PermissionTransformer.Interface[]\n ) {}\n\n async loadPermissions(identity: Identity): Promise<SecurityPermission[]> {\n if (this.permissions) {\n return this.permissions;\n }\n\n if (this.permissionsLoader) {\n return this.permissionsLoader;\n }\n\n this.permissionsLoader = new Promise<SecurityPermission[]>(async resolve => {\n // Execute authorizers in sequence until one returns permissions\n const authorizers = this.getAuthorizers();\n for (const authorizer of authorizers) {\n const permissions = await authorizer.authorize(identity);\n if (Array.isArray(permissions)) {\n this.permissions = this.transformPermissions(permissions);\n return resolve(this.permissions);\n }\n }\n\n // No authorizer returned permissions\n this.permissions = [];\n resolve(this.permissions);\n });\n\n return this.permissionsLoader;\n }\n\n isAuthorizationEnabled(): boolean {\n const override = authorizationEnabledStorage.getStore();\n return override ?? true;\n }\n\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n return authorizationEnabledStorage.run(false, cb);\n }\n\n clearPermissionsCache(): void {\n this.permissions = undefined;\n this.permissionsLoader = undefined;\n }\n\n private transformPermissions(permissions: SecurityPermission[]) {\n const transformers = this.getTransformers();\n if (transformers.length === 0) {\n return this.deduplicatePermissions(permissions);\n }\n\n const transformed = permissions\n .map(permission => {\n // A transformer can return one or multiple permissions, so we flatten the result.\n return transformers.map(t => t.execute(permission)).flat();\n })\n .flat();\n\n return this.deduplicatePermissions(transformed);\n }\n\n private deduplicatePermissions(permissions: SecurityPermission[]) {\n const seen = new Set<string>();\n\n return permissions.filter(permission => {\n const key = JSON.stringify(permission);\n if (seen.has(key)) {\n return false;\n }\n seen.add(key);\n return true;\n });\n }\n}\n"],"names":["authorizationEnabledStorage","AsyncLocalStorage","AuthorizationContext","getAuthorizers","getTransformers","identity","Promise","resolve","authorizers","authorizer","permissions","Array","override","cb","undefined","transformers","transformed","permission","t","seen","Set","key","JSON"],"mappings":";AAMA,MAAMA,8BAA8B,IAAIC;AAEjC,MAAMC;IAIT,YACYC,cAA4C,EAC5CC,eAAwD,CAClE;aAFUD,cAAc,GAAdA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,gBAAgBC,QAAkB,EAAiC;QACrE,IAAI,IAAI,CAAC,WAAW,EAChB,OAAO,IAAI,CAAC,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AAG,CAACE,MACT,OAAO;YAEXF,KAAK,GAAG,CAACE;YACT,OAAO;QACX;IACJ;AACJ"}
1
+ {"version":3,"file":"features/security/authorization/AuthorizationContext/AuthorizationContext.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/AuthorizationContext.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { AuthorizationContext as Abstraction, PermissionTransformer } from \"./abstractions.js\";\nimport { Authorizer } from \"../Authorizer/index.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\n\n/** Tenant key used when no tenant is set yet (before the tenant is resolved). */\nconst NO_TENANT = \"\";\n\ntype PermissionsByTenant = Map<string, Promise<SecurityPermission[]>>;\n\n/**\n * Loads and caches permissions per identity object and tenant for the lifetime of the request.\n * `IdentityContext.withIdentity` can switch the identity mid-request and `TenantContext` the\n * tenant, so permissions loaded for one identity or tenant never answer for another. Keying by the\n * object (not by id or a fingerprint) means two identities with the same id but a different\n * context never share an entry (R69). A failed load is evicted, so the next check retries.\n */\nexport class AuthorizationContext implements Abstraction.Interface {\n private permissionsByIdentity = new WeakMap<Identity, PermissionsByTenant>();\n /*\n * `withoutAuthorization()` and `withAuthorization()` switch authorization on or off for their\n * callback's async call chain only.\n */\n private readonly authorizationEnabledOverrides = new AsyncLocalStorage<boolean>();\n\n constructor(\n private getAuthorizers: () => Authorizer.Interface[],\n private getTransformers: () => PermissionTransformer.Interface[],\n private getTenantId: () => string | null\n ) {}\n\n loadPermissions(identity: Identity): Promise<SecurityPermission[]> {\n let byTenant = this.permissionsByIdentity.get(identity);\n if (!byTenant) {\n byTenant = new Map();\n this.permissionsByIdentity.set(identity, byTenant);\n }\n\n const tenantKey = this.getTenantId() ?? NO_TENANT;\n const cached = byTenant.get(tenantKey);\n if (cached) {\n return cached;\n }\n\n const loader = this.authorize(identity);\n byTenant.set(tenantKey, loader);\n const cache = byTenant;\n loader.catch(() => {\n if (cache.get(tenantKey) === loader) {\n cache.delete(tenantKey);\n }\n });\n return loader;\n }\n\n isAuthorizationEnabled(): boolean {\n const override = this.authorizationEnabledOverrides.getStore();\n return override ?? true;\n }\n\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n return this.authorizationEnabledOverrides.run(false, cb);\n }\n\n withAuthorization<T>(cb: () => Promise<T>): Promise<T> {\n return this.authorizationEnabledOverrides.run(true, cb);\n }\n\n clearPermissionsCache(): void {\n this.permissionsByIdentity = new WeakMap();\n }\n\n private async authorize(identity: Identity): Promise<SecurityPermission[]> {\n // Execute authorizers in sequence until one returns permissions\n const authorizers = this.getAuthorizers();\n for (const authorizer of authorizers) {\n const permissions = await authorizer.authorize(identity);\n if (Array.isArray(permissions)) {\n return this.transformPermissions(permissions);\n }\n }\n\n // No authorizer returned permissions\n return [];\n }\n\n private transformPermissions(permissions: SecurityPermission[]) {\n const transformers = this.getTransformers();\n if (transformers.length === 0) {\n return this.deduplicatePermissions(permissions);\n }\n\n const transformed = permissions\n .map(permission => {\n // A transformer can return one or multiple permissions, so we flatten the result.\n return transformers.map(t => t.execute(permission)).flat();\n })\n .flat();\n\n return this.deduplicatePermissions(transformed);\n }\n\n private deduplicatePermissions(permissions: SecurityPermission[]) {\n const seen = new Set<string>();\n\n return permissions.filter(permission => {\n const key = JSON.stringify(permission);\n if (seen.has(key)) {\n return false;\n }\n seen.add(key);\n return true;\n });\n }\n}\n"],"names":["NO_TENANT","AuthorizationContext","getAuthorizers","getTransformers","getTenantId","WeakMap","AsyncLocalStorage","identity","byTenant","Map","tenantKey","cached","loader","cache","override","cb","authorizers","authorizer","permissions","Array","transformers","transformed","permission","t","seen","Set","key","JSON"],"mappings":";AAOA,MAAMA,YAAY;AAWX,MAAMC;IAQT,YACYC,cAA4C,EAC5CC,eAAwD,EACxDC,WAAgC,CAC1C;aAHUF,cAAc,GAAdA;aACAC,eAAe,GAAfA;aACAC,WAAW,GAAXA;aAVJ,qBAAqB,GAAG,IAAIC;QAInC,KACgB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EACnB,OAAO,IAAI,CAAC,sBAAsB,CAACF;QAGvC,MAAMG,cAAcH,YACf,GAAG,CAACI,CAAAA,aAEMF,aAAa,GAAG,CAACG,CAAAA,IAAKA,EAAE,OAAO,CAACD,aAAa,IAAI,IAE3D,IAAI;QAET,OAAO,IAAI,CAAC,sBAAsB,CAACD;IACvC;IAEQ,uBAAuBH,WAAiC,EAAE;QAC9D,MAAMM,OAAO,IAAIC;QAEjB,OAAOP,YAAY,MAAM,CAACI,CAAAA;YACtB,MAAMI,MAAMC,KAAK,SAAS,CAACL;YAC3B,IAAIE,KAAK,GAAG,CAACE,MACT,OAAO;YAEXF,KAAK,GAAG,CAACE;YACT,OAAO;QACX;IACJ;AACJ"}
@@ -4,6 +4,8 @@ export interface IAuthorizationContext {
4
4
  loadPermissions(identity: Identity): Promise<SecurityPermission[]>;
5
5
  isAuthorizationEnabled(): boolean;
6
6
  withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;
7
+ /** Runs `cb` with authorization enabled, also inside `withoutAuthorization`. */
8
+ withAuthorization<T>(cb: () => Promise<T>): Promise<T>;
7
9
  clearPermissionsCache(): void;
8
10
  }
9
11
  /** Load and cache security permissions for the current identity. */
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/authorization/AuthorizationContext/abstractions.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\n\nexport interface IAuthorizationContext {\n loadPermissions(identity: Identity): Promise<SecurityPermission[]>;\n isAuthorizationEnabled(): boolean;\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;\n clearPermissionsCache(): void;\n}\n\n/** Load and cache security permissions for the current identity. */\nexport const AuthorizationContext =\n createAbstraction<IAuthorizationContext>(\"AuthorizationContext\");\n\nexport namespace AuthorizationContext {\n export type Interface = IAuthorizationContext;\n}\n\nexport interface IPermissionTransformer {\n execute(permission: SecurityPermission): SecurityPermission | SecurityPermission[];\n}\n\n/** Transform security permissions before they are applied. */\nexport const PermissionTransformer =\n createAbstraction<IPermissionTransformer>(\"PermissionTransformer\");\n\nexport namespace PermissionTransformer {\n export type Interface = IPermissionTransformer;\n export type Permission = SecurityPermission;\n export type Return = SecurityPermission | SecurityPermission[];\n}\n"],"names":["AuthorizationContext","createAbstraction","PermissionTransformer"],"mappings":";AAYO,MAAMA,uBACTC,kBAAyC;AAWtC,MAAMC,wBACTD,kBAA0C"}
1
+ {"version":3,"file":"features/security/authorization/AuthorizationContext/abstractions.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\n\nexport interface IAuthorizationContext {\n loadPermissions(identity: Identity): Promise<SecurityPermission[]>;\n isAuthorizationEnabled(): boolean;\n withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;\n /** Runs `cb` with authorization enabled, also inside `withoutAuthorization`. */\n withAuthorization<T>(cb: () => Promise<T>): Promise<T>;\n clearPermissionsCache(): void;\n}\n\n/** Load and cache security permissions for the current identity. */\nexport const AuthorizationContext =\n createAbstraction<IAuthorizationContext>(\"AuthorizationContext\");\n\nexport namespace AuthorizationContext {\n export type Interface = IAuthorizationContext;\n}\n\nexport interface IPermissionTransformer {\n execute(permission: SecurityPermission): SecurityPermission | SecurityPermission[];\n}\n\n/** Transform security permissions before they are applied. */\nexport const PermissionTransformer =\n createAbstraction<IPermissionTransformer>(\"PermissionTransformer\");\n\nexport namespace PermissionTransformer {\n export type Interface = IPermissionTransformer;\n export type Permission = SecurityPermission;\n export type Return = SecurityPermission | SecurityPermission[];\n}\n"],"names":["AuthorizationContext","createAbstraction","PermissionTransformer"],"mappings":";AAcO,MAAMA,uBACTC,kBAAyC;AAWtC,MAAMC,wBACTD,kBAA0C"}
@@ -2,12 +2,17 @@ import { createFeature } from "@webiny/feature/api";
2
2
  import { AuthorizationContext } from "./AuthorizationContext.js";
3
3
  import { AuthorizationContext as external_abstractions_js_AuthorizationContext, PermissionTransformer } from "./abstractions.js";
4
4
  import { Authorizer } from "../Authorizer/index.js";
5
+ import { TenantContext } from "../../../tenancy/TenantContext/index.js";
5
6
  const AuthorizationContextFeature = createFeature({
6
7
  name: "AuthorizationContext",
7
8
  register (container) {
8
9
  const getAuthorizers = ()=>container.resolveAll(Authorizer);
9
10
  const getTransformers = ()=>container.resolveAll(PermissionTransformer);
10
- const authorizationContext = new AuthorizationContext(getAuthorizers, getTransformers);
11
+ const getTenantId = ()=>{
12
+ const tenantContext = container.resolveAll(TenantContext).at(-1);
13
+ return tenantContext?.getTenant()?.id ?? null;
14
+ };
15
+ const authorizationContext = new AuthorizationContext(getAuthorizers, getTransformers, getTenantId);
11
16
  container.registerInstance(external_abstractions_js_AuthorizationContext, authorizationContext);
12
17
  }
13
18
  });
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/authorization/AuthorizationContext/feature.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AuthorizationContext } from \"./AuthorizationContext.js\";\nimport { AuthorizationContext as Abstraction, PermissionTransformer } from \"./abstractions.js\";\nimport { Authorizer } from \"~/features/security/authorization/Authorizer/index.js\";\n\nexport const AuthorizationContextFeature = createFeature({\n name: \"AuthorizationContext\",\n register(container) {\n const getAuthorizers = () => container.resolveAll(Authorizer);\n const getTransformers = () => container.resolveAll(PermissionTransformer);\n\n const authorizationContext = new AuthorizationContext(getAuthorizers, getTransformers);\n\n container.registerInstance(Abstraction, authorizationContext);\n }\n});\n"],"names":["AuthorizationContextFeature","createFeature","container","getAuthorizers","Authorizer","getTransformers","PermissionTransformer","authorizationContext","AuthorizationContext","Abstraction"],"mappings":";;;;AAKO,MAAMA,8BAA8BC,cAAc;IACrD,MAAM;IACN,UAASC,SAAS;QACd,MAAMC,iBAAiB,IAAMD,UAAU,UAAU,CAACE;QAClD,MAAMC,kBAAkB,IAAMH,UAAU,UAAU,CAACI;QAEnD,MAAMC,uBAAuB,IAAIC,qBAAqBL,gBAAgBE;QAEtEH,UAAU,gBAAgB,CAACO,+CAAaF;IAC5C;AACJ"}
1
+ {"version":3,"file":"features/security/authorization/AuthorizationContext/feature.js","sources":["../../../../../src/features/security/authorization/AuthorizationContext/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AuthorizationContext } from \"./AuthorizationContext.js\";\nimport { AuthorizationContext as Abstraction, PermissionTransformer } from \"./abstractions.js\";\nimport { Authorizer } from \"~/features/security/authorization/Authorizer/index.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\n\nexport const AuthorizationContextFeature = createFeature({\n name: \"AuthorizationContext\",\n register(container) {\n const getAuthorizers = () => container.resolveAll(Authorizer);\n const getTransformers = () => container.resolveAll(PermissionTransformer);\n // Read lazily: the tenant is set after registration, and slim test containers have none\n // (`resolve` would throw there). The last registration is the one `resolve` returns, so a\n // project override wins over the platform's.\n const getTenantId = (): string | null => {\n const tenantContext = container.resolveAll(TenantContext).at(-1);\n return tenantContext?.getTenant()?.id ?? null;\n };\n\n const authorizationContext = new AuthorizationContext(\n getAuthorizers,\n getTransformers,\n getTenantId\n );\n\n container.registerInstance(Abstraction, authorizationContext);\n }\n});\n"],"names":["AuthorizationContextFeature","createFeature","container","getAuthorizers","Authorizer","getTransformers","PermissionTransformer","getTenantId","tenantContext","TenantContext","authorizationContext","AuthorizationContext","Abstraction"],"mappings":";;;;;AAMO,MAAMA,8BAA8BC,cAAc;IACrD,MAAM;IACN,UAASC,SAAS;QACd,MAAMC,iBAAiB,IAAMD,UAAU,UAAU,CAACE;QAClD,MAAMC,kBAAkB,IAAMH,UAAU,UAAU,CAACI;QAInD,MAAMC,cAAc;YAChB,MAAMC,gBAAgBN,UAAU,UAAU,CAACO,eAAe,EAAE,CAAC;YAC7D,OAAOD,eAAe,aAAa,MAAM;QAC7C;QAEA,MAAME,uBAAuB,IAAIC,qBAC7BR,gBACAE,iBACAE;QAGJL,UAAU,gBAAgB,CAACU,+CAAaF;IAC5C;AACJ"}
@@ -0,0 +1,30 @@
1
+ import { FeatureFlags } from "../../../../features/featureFlags/abstractions.js";
2
+ import { RawAssumePermissions } from "../../../../features/requestContext/abstractions.js";
3
+ import { Identity } from "../../../../features/security/IdentityContext/index.js";
4
+ import { RolesRepository } from "../../../../features/security/roles/shared/abstractions.js";
5
+ import { TeamsRepository } from "../../../../features/security/teams/shared/abstractions.js";
6
+ import { PermissionsProcessor } from "./abstractions.js";
7
+ /**
8
+ * Evaluates the request against a role or team the caller asked to preview, instead of against the
9
+ * caller's own roles. This is what makes "view the Admin as an Editor" honest: lists shrink and
10
+ * writes fail server-side, rather than the Admin merely hiding buttons over unrestricted data.
11
+ *
12
+ * Previewing is available only to callers who already have full access, and it can only ever take
13
+ * permissions away. See the guard in `getPermissions` for why the check cannot go through
14
+ * IdentityContext.
15
+ */
16
+ declare class AssumedPermissionsImpl implements PermissionsProcessor.Interface {
17
+ private rawAssumePermissions;
18
+ private featureFlags;
19
+ private rolesRepository;
20
+ private teamsRepository;
21
+ private decoratee;
22
+ constructor(rawAssumePermissions: RawAssumePermissions.Interface, featureFlags: FeatureFlags.Interface, rolesRepository: RolesRepository.Interface, teamsRepository: TeamsRepository.Interface, decoratee: PermissionsProcessor.Interface);
23
+ getPermissions(identity: Identity): Promise<PermissionsProcessor.Permissions | null>;
24
+ private loadAssumedRoles;
25
+ private loadRoles;
26
+ }
27
+ export declare const AssumedPermissions: typeof AssumedPermissionsImpl & {
28
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IPermissionsProcessor>;
29
+ };
30
+ export {};
@@ -0,0 +1,60 @@
1
+ import { FeatureFlags } from "../../../featureFlags/abstractions.js";
2
+ import { RawAssumePermissions } from "../../../requestContext/abstractions.js";
3
+ import { RolesRepository } from "../../roles/shared/abstractions.js";
4
+ import { TeamsRepository } from "../../teams/shared/abstractions.js";
5
+ import { getPermissionsFromRoles } from "../../utils/getPermissionsFromRoles.js";
6
+ import { PermissionsProcessor } from "./abstractions.js";
7
+ function grantsFullAccess(permissions) {
8
+ return permissions.some((permission)=>"*" === permission.name);
9
+ }
10
+ class AssumedPermissionsImpl {
11
+ constructor(rawAssumePermissions, featureFlags, rolesRepository, teamsRepository, decoratee){
12
+ this.rawAssumePermissions = rawAssumePermissions;
13
+ this.featureFlags = featureFlags;
14
+ this.rolesRepository = rolesRepository;
15
+ this.teamsRepository = teamsRepository;
16
+ this.decoratee = decoratee;
17
+ }
18
+ async getPermissions(identity) {
19
+ const target = this.rawAssumePermissions.get();
20
+ const own = await this.decoratee.getPermissions(identity);
21
+ if (!target) return own;
22
+ if (!own || !grantsFullAccess(own)) return own;
23
+ const roles = await this.loadAssumedRoles(target);
24
+ return getPermissionsFromRoles(roles);
25
+ }
26
+ async loadAssumedRoles(target) {
27
+ if ("role" === target.type) return this.loadRoles([
28
+ target.id
29
+ ]);
30
+ const teamsEnabled = this.featureFlags.get().isEnabled("advancedAccessControlLayer.teams");
31
+ if (!teamsEnabled) return [];
32
+ const teamResult = await this.teamsRepository.get({
33
+ id: target.id
34
+ });
35
+ if (teamResult.isFail()) return [];
36
+ return this.loadRoles(teamResult.value.roles);
37
+ }
38
+ async loadRoles(roleIds) {
39
+ if (0 === roleIds.length) return [];
40
+ const result = await this.rolesRepository.list({
41
+ where: {
42
+ id_in: roleIds
43
+ }
44
+ });
45
+ if (result.isFail()) return [];
46
+ return result.value;
47
+ }
48
+ }
49
+ const AssumedPermissions = PermissionsProcessor.createDecorator({
50
+ decorator: AssumedPermissionsImpl,
51
+ dependencies: [
52
+ RawAssumePermissions,
53
+ FeatureFlags,
54
+ RolesRepository,
55
+ TeamsRepository
56
+ ]
57
+ });
58
+ export { AssumedPermissions };
59
+
60
+ //# sourceMappingURL=AssumedPermissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.js","sources":["../../../../../src/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.ts"],"sourcesContent":["import { FeatureFlags } from \"~/features/featureFlags/abstractions.js\";\nimport { RawAssumePermissions } from \"~/features/requestContext/abstractions.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\nimport { RolesRepository } from \"~/features/security/roles/shared/abstractions.js\";\nimport { TeamsRepository } from \"~/features/security/teams/shared/abstractions.js\";\nimport { getPermissionsFromRoles } from \"~/features/security/utils/getPermissionsFromRoles.js\";\nimport type { SecurityRole } from \"~/types/security.js\";\nimport { PermissionsProcessor } from \"./abstractions.js\";\n\nfunction grantsFullAccess(permissions: PermissionsProcessor.Permissions): boolean {\n return permissions.some(permission => permission.name === \"*\");\n}\n\n/**\n * Evaluates the request against a role or team the caller asked to preview, instead of against the\n * caller's own roles. This is what makes \"view the Admin as an Editor\" honest: lists shrink and\n * writes fail server-side, rather than the Admin merely hiding buttons over unrestricted data.\n *\n * Previewing is available only to callers who already have full access, and it can only ever take\n * permissions away. See the guard in `getPermissions` for why the check cannot go through\n * IdentityContext.\n */\nclass AssumedPermissionsImpl implements PermissionsProcessor.Interface {\n constructor(\n private rawAssumePermissions: RawAssumePermissions.Interface,\n private featureFlags: FeatureFlags.Interface,\n private rolesRepository: RolesRepository.Interface,\n private teamsRepository: TeamsRepository.Interface,\n private decoratee: PermissionsProcessor.Interface\n ) {}\n\n async getPermissions(identity: Identity): Promise<PermissionsProcessor.Permissions | null> {\n const target = this.rawAssumePermissions.get();\n const own = await this.decoratee.getPermissions(identity);\n\n if (!target) {\n return own;\n }\n\n /*\n * The guard runs against the caller's OWN permissions, and they have to come from the\n * decoratee. IdentityContext.hasFullAccess() would resolve them through the Authorizer,\n * which lands back in this decorator, so the check would be re-entrant. Order matters too:\n * read the real permissions, verify them, and only then substitute.\n */\n if (!own || !grantsFullAccess(own)) {\n return own;\n }\n\n const roles = await this.loadAssumedRoles(target);\n\n /*\n * A preview request that resolves to no roles grants nothing. Falling back to `own` would\n * hand the caller their real full access while the Admin still claims they are previewing\n * a restricted role, which is the one outcome this feature must never produce.\n */\n return getPermissionsFromRoles(roles);\n }\n\n private async loadAssumedRoles(target: RawAssumePermissions.Target): Promise<SecurityRole[]> {\n if (target.type === \"role\") {\n return this.loadRoles([target.id]);\n }\n\n const teamsEnabled = this.featureFlags.get().isEnabled(\"advancedAccessControlLayer.teams\");\n if (!teamsEnabled) {\n return [];\n }\n\n const teamResult = await this.teamsRepository.get({ id: target.id });\n if (teamResult.isFail()) {\n return [];\n }\n\n return this.loadRoles(teamResult.value.roles);\n }\n\n private async loadRoles(roleIds: string[]): Promise<SecurityRole[]> {\n if (roleIds.length === 0) {\n return [];\n }\n\n const result = await this.rolesRepository.list({ where: { id_in: roleIds } });\n if (result.isFail()) {\n return [];\n }\n\n return result.value;\n }\n}\n\nexport const AssumedPermissions = PermissionsProcessor.createDecorator({\n decorator: AssumedPermissionsImpl,\n dependencies: [RawAssumePermissions, FeatureFlags, RolesRepository, TeamsRepository]\n});\n"],"names":["grantsFullAccess","permissions","permission","AssumedPermissionsImpl","rawAssumePermissions","featureFlags","rolesRepository","teamsRepository","decoratee","identity","target","own","roles","getPermissionsFromRoles","teamsEnabled","teamResult","roleIds","result","AssumedPermissions","PermissionsProcessor","RawAssumePermissions","FeatureFlags","RolesRepository","TeamsRepository"],"mappings":";;;;;;AASA,SAASA,iBAAiBC,WAA6C;IACnE,OAAOA,YAAY,IAAI,CAACC,CAAAA,aAAcA,AAAoB,QAApBA,WAAW,IAAI;AACzD;AAWA,MAAMC;IACF,YACYC,oBAAoD,EACpDC,YAAoC,EACpCC,eAA0C,EAC1CC,eAA0C,EAC1CC,SAAyC,CACnD;aALUJ,oBAAoB,GAApBA;aACAC,YAAY,GAAZA;aACAC,eAAe,GAAfA;aACAC,eAAe,GAAfA;aACAC,SAAS,GAATA;IACT;IAEH,MA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.js";
3
3
  import { GetPermissionsFromIdentity } from "./GetPermissionsFromIdentity.js";
4
+ import { AssumedPermissions } from "./AssumedPermissions.js";
4
5
  const GroupsTeamsAuthorizerFeature = createFeature({
5
6
  name: "GroupsTeamsAuthorizer",
6
7
  register (container) {
7
8
  container.register(RolesTeamsAuthorizer).inSingletonScope();
8
9
  container.register(GetPermissionsFromIdentity);
10
+ container.registerDecorator(AssumedPermissions);
9
11
  }
10
12
  });
11
13
  export { GroupsTeamsAuthorizerFeature };
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/authorization/GroupsTeamsAuthorizer/feature.js","sources":["../../../../../src/features/security/authorization/GroupsTeamsAuthorizer/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { RolesTeamsAuthorizer } from \"./RolesTeamsAuthorizer.js\";\nimport { GetPermissionsFromIdentity } from \"./GetPermissionsFromIdentity.js\";\n\nexport const GroupsTeamsAuthorizerFeature = createFeature({\n name: \"GroupsTeamsAuthorizer\",\n register(container) {\n container.register(RolesTeamsAuthorizer).inSingletonScope();\n container.register(GetPermissionsFromIdentity);\n }\n});\n"],"names":["GroupsTeamsAuthorizerFeature","createFeature","container","RolesTeamsAuthorizer","GetPermissionsFromIdentity"],"mappings":";;;AAIO,MAAMA,+BAA+BC,cAAc;IACtD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,sBAAsB,gBAAgB;QACzDD,UAAU,QAAQ,CAACE;IACvB;AACJ"}
1
+ {"version":3,"file":"features/security/authorization/GroupsTeamsAuthorizer/feature.js","sources":["../../../../../src/features/security/authorization/GroupsTeamsAuthorizer/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { RolesTeamsAuthorizer } from \"./RolesTeamsAuthorizer.js\";\nimport { GetPermissionsFromIdentity } from \"./GetPermissionsFromIdentity.js\";\nimport { AssumedPermissions } from \"./AssumedPermissions.js\";\n\nexport const GroupsTeamsAuthorizerFeature = createFeature({\n name: \"GroupsTeamsAuthorizer\",\n register(container) {\n container.register(RolesTeamsAuthorizer).inSingletonScope();\n container.register(GetPermissionsFromIdentity);\n container.registerDecorator(AssumedPermissions);\n }\n});\n"],"names":["GroupsTeamsAuthorizerFeature","createFeature","container","RolesTeamsAuthorizer","GetPermissionsFromIdentity","AssumedPermissions"],"mappings":";;;;AAKO,MAAMA,+BAA+BC,cAAc;IACtD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,sBAAsB,gBAAgB;QACzDD,UAAU,QAAQ,CAACE;QACnBF,UAAU,iBAAiB,CAACG;IAChC;AACJ"}
@@ -15,6 +15,7 @@ class RolesInstallerImpl {
15
15
  }
16
16
  async install() {
17
17
  const rolesResult = await this.listRolesUseCase.execute();
18
+ if (rolesResult.isFail()) throw rolesResult.error;
18
19
  const roles = rolesResult.value;
19
20
  if (!roles.find((g)=>"full-access" === g.slug)) {
20
21
  const result = await this.createRoleUseCase.execute({
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/roles/Installer/RolesInstaller.js","sources":["../../../../../src/features/security/roles/Installer/RolesInstaller.ts"],"sourcesContent":["import { AppInstaller } from \"~/features/tenancy/InstallTenant/index.js\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Role } from \"../shared/types.js\";\nimport { ListRolesUseCase } from \"~/features/security/roles/ListRoles/index.js\";\nimport { CreateRoleUseCase } from \"~/features/security/roles/CreateRole/index.js\";\nimport { DeleteRoleUseCase } from \"~/features/security/roles/DeleteRole/index.js\";\n\nclass RolesInstallerImpl implements AppInstaller.Interface {\n readonly alwaysRun = true;\n readonly appName = \"Security\";\n readonly dependsOn = [];\n private createdRoles: Role[] = [];\n\n constructor(\n private listRolesUseCase: ListRolesUseCase.Interface,\n private createRoleUseCase: CreateRoleUseCase.Interface,\n private deleteRoleUseCase: DeleteRoleUseCase.Interface\n ) {}\n\n async install(): Promise<void> {\n const rolesResult = await this.listRolesUseCase.execute();\n const roles = rolesResult.value;\n\n if (!roles.find(g => g.slug === \"full-access\")) {\n const result = await this.createRoleUseCase.execute({\n name: \"Full Access\",\n description: \"Grants full access to all apps.\",\n system: true,\n slug: \"full-access\",\n permissions: [{ name: \"*\" }]\n });\n\n if (result.isFail()) {\n throw result.error;\n }\n\n this.createdRoles.push(result.value);\n }\n }\n\n async uninstall(): Promise<void> {\n for (const role of this.createdRoles) {\n await this.deleteRoleUseCase.execute(role.id);\n }\n }\n}\n\nexport const RoleInstaller = createImplementation({\n abstraction: AppInstaller,\n implementation: RolesInstallerImpl,\n dependencies: [ListRolesUseCase, CreateRoleUseCase, DeleteRoleUseCase]\n});\n"],"names":["RolesInstallerImpl","listRolesUseCase","createRoleUseCase","deleteRoleUseCase","rolesResult","roles","g","result","role","RoleInstaller","createImplementation","AppInstaller","ListRolesUseCase","CreateRoleUseCase","DeleteRoleUseCase"],"mappings":";;;;;AAOA,MAAMA;IAMF,YACYC,gBAA4C,EAC5CC,iBAA8C,EAC9CC,iBAA8C,CACxD;aAHUF,gBAAgB,GAAhBA;aACAC,iBAAiB,GAAjBA;aACAC,iBAAiB,GAAjBA;aARH,SAAS,GAAG;aACZ,OAAO,GAAG;aACV,SAAS,GAAG,EAAE;aACf,YAAY,GAAW,EAAE;IAM9B;IAEH,MAAM,UAAyB;QAC3B,MAAMC,cAAc,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO;QACvD,MAAMC,QAAQD,YAAY,KAAK;QAE/B,IAAI,CAACC,MAAM,IAAI,CAACC,CAAAA,IAAKA,AAAW,kBAAXA,EAAE,IAAI,GAAqB;YAC5C,MAAMC,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC;gBAChD,MAAM;gBACN,aAAa;gBACb,QAAQ;gBACR,MAAM;gBACN,aAAa;oBAAC;wBAAE,MAAM;oBAAI;iBAAE;YAChC;YAEA,IAAIA,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;YAGtB,IAAI,CAAC,YAAY,CAAC,IAAI,CAACA,OAAO,KAAK;QACvC;IACJ;IAEA,MAAM,YAA2B;QAC7B,KAAK,MAAMC,QAAQ,IAAI,CAAC,YAAY,CAChC,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACA,KAAK,EAAE;IAEpD;AACJ;AAEO,MAAMC,gBAAgBC,qBAAqB;IAC9C,aAAaC;IACb,gBAAgBX;IAChB,cAAc;QAACY;QAAkBC;QAAmBC;KAAkB;AAC1E"}
1
+ {"version":3,"file":"features/security/roles/Installer/RolesInstaller.js","sources":["../../../../../src/features/security/roles/Installer/RolesInstaller.ts"],"sourcesContent":["import { AppInstaller } from \"~/features/tenancy/InstallTenant/index.js\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Role } from \"../shared/types.js\";\nimport { ListRolesUseCase } from \"~/features/security/roles/ListRoles/index.js\";\nimport { CreateRoleUseCase } from \"~/features/security/roles/CreateRole/index.js\";\nimport { DeleteRoleUseCase } from \"~/features/security/roles/DeleteRole/index.js\";\n\nclass RolesInstallerImpl implements AppInstaller.Interface {\n readonly alwaysRun = true;\n readonly appName = \"Security\";\n readonly dependsOn = [];\n private createdRoles: Role[] = [];\n\n constructor(\n private listRolesUseCase: ListRolesUseCase.Interface,\n private createRoleUseCase: CreateRoleUseCase.Interface,\n private deleteRoleUseCase: DeleteRoleUseCase.Interface\n ) {}\n\n async install(): Promise<void> {\n const rolesResult = await this.listRolesUseCase.execute();\n if (rolesResult.isFail()) {\n throw rolesResult.error;\n }\n const roles = rolesResult.value;\n\n if (!roles.find(g => g.slug === \"full-access\")) {\n const result = await this.createRoleUseCase.execute({\n name: \"Full Access\",\n description: \"Grants full access to all apps.\",\n system: true,\n slug: \"full-access\",\n permissions: [{ name: \"*\" }]\n });\n\n if (result.isFail()) {\n throw result.error;\n }\n\n this.createdRoles.push(result.value);\n }\n }\n\n async uninstall(): Promise<void> {\n for (const role of this.createdRoles) {\n await this.deleteRoleUseCase.execute(role.id);\n }\n }\n}\n\nexport const RoleInstaller = createImplementation({\n abstraction: AppInstaller,\n implementation: RolesInstallerImpl,\n dependencies: [ListRolesUseCase, CreateRoleUseCase, DeleteRoleUseCase]\n});\n"],"names":["RolesInstallerImpl","listRolesUseCase","createRoleUseCase","deleteRoleUseCase","rolesResult","roles","g","result","role","RoleInstaller","createImplementation","AppInstaller","ListRolesUseCase","CreateRoleUseCase","DeleteRoleUseCase"],"mappings":";;;;;AAOA,MAAMA;IAMF,YACYC,gBAA4C,EAC5CC,iBAA8C,EAC9CC,iBAA8C,CACxD;aAHUF,gBAAgB,GAAhBA;aACAC,iBAAiB,GAAjBA;aACAC,iBAAiB,GAAjBA;aARH,SAAS,GAAG;aACZ,OAAO,GAAG;aACV,SAAS,GAAG,EAAE;aACf,YAAY,GAAW,EAAE;IAM9B;IAEH,MAAM,UAAyB;QAC3B,MAAMC,cAAc,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO;QACvD,IAAIA,YAAY,MAAM,IAClB,MAAMA,YAAY,KAAK;QAE3B,MAAMC,QAAQD,YAAY,KAAK;QAE/B,IAAI,CAACC,MAAM,IAAI,CAACC,CAAAA,IAAKA,AAAW,kBAAXA,EAAE,IAAI,GAAqB;YAC5C,MAAMC,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC;gBAChD,MAAM;gBACN,aAAa;gBACb,QAAQ;gBACR,MAAM;gBACN,aAAa;oBAAC;wBAAE,MAAM;oBAAI;iBAAE;YAChC;YAEA,IAAIA,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;YAGtB,IAAI,CAAC,YAAY,CAAC,IAAI,CAACA,OAAO,KAAK;QACvC;IACJ;IAEA,MAAM,YAA2B;QAC7B,KAAK,MAAMC,QAAQ,IAAI,CAAC,YAAY,CAChC,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACA,KAAK,EAAE;IAEpD;AACJ;AAEO,MAAMC,gBAAgBC,qBAAqB;IAC9C,aAAaC;IACb,gBAAgBX;IAChB,cAAc;QAACY;QAAkBC;QAAmBC;KAAkB;AAC1E"}
@@ -0,0 +1,11 @@
1
+ import { RoleAfterCreateEventHandler } from "../../../../features/security/roles/CreateRole/index.js";
2
+ import { NotifyRoleChangeUseCase } from "./abstractions.js";
3
+ declare class NotifyOnRoleCreatedHandlerImpl implements RoleAfterCreateEventHandler.Interface {
4
+ private notifyRoleChange;
5
+ constructor(notifyRoleChange: NotifyRoleChangeUseCase.Interface);
6
+ handle(event: RoleAfterCreateEventHandler.Event): Promise<void>;
7
+ }
8
+ export declare const NotifyOnRoleCreatedHandler: typeof NotifyOnRoleCreatedHandlerImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("../../../eventPublisher/abstractions.js").IEventHandler<import("~/features/security/roles/CreateRole/index.js").RoleAfterCreateEvent>>;
10
+ };
11
+ export {};
@@ -0,0 +1,22 @@
1
+ import { RoleAfterCreateEventHandler } from "../CreateRole/index.js";
2
+ import { NotifyRoleChangeUseCase } from "./abstractions.js";
3
+ class NotifyOnRoleCreatedHandlerImpl {
4
+ constructor(notifyRoleChange){
5
+ this.notifyRoleChange = notifyRoleChange;
6
+ }
7
+ async handle(event) {
8
+ await this.notifyRoleChange.execute({
9
+ id: event.payload.role.id,
10
+ change: "created"
11
+ });
12
+ }
13
+ }
14
+ const NotifyOnRoleCreatedHandler = RoleAfterCreateEventHandler.createImplementation({
15
+ implementation: NotifyOnRoleCreatedHandlerImpl,
16
+ dependencies: [
17
+ NotifyRoleChangeUseCase
18
+ ]
19
+ });
20
+ export { NotifyOnRoleCreatedHandler };
21
+
22
+ //# sourceMappingURL=NotifyOnRoleCreatedHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.js","sources":["../../../../../src/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.ts"],"sourcesContent":["import { RoleAfterCreateEventHandler } from \"~/features/security/roles/CreateRole/index.js\";\nimport { NotifyRoleChangeUseCase } from \"./abstractions.js\";\n\nclass NotifyOnRoleCreatedHandlerImpl implements RoleAfterCreateEventHandler.Interface {\n constructor(private notifyRoleChange: NotifyRoleChangeUseCase.Interface) {}\n\n async handle(event: RoleAfterCreateEventHandler.Event): Promise<void> {\n await this.notifyRoleChange.execute({ id: event.payload.role.id, change: \"created\" });\n }\n}\n\nexport const NotifyOnRoleCreatedHandler = RoleAfterCreateEventHandler.createImplementation({\n implementation: NotifyOnRoleCreatedHandlerImpl,\n dependencies: [NotifyRoleChangeUseCase]\n});\n"],"names":["NotifyOnRoleCreatedHandlerImpl","notifyRoleChange","event","NotifyOnRoleCreatedHandler","RoleAfterCreateEventHandler","NotifyRoleChangeUseCase"],"mappings":";;AAGA,MAAMA;IACF,YAAoBC,gBAAmD,CAAE;aAArDA,gBAAgB,GAAhBA;IAAsD;IAE1E,MAAM,OAAOC,KAAwC,EAAiB;QAClE,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;YAAE,IAAIA,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE;YAAE,QAAQ;QAAU;IACvF;AACJ;AAEO,MAAMC,6BAA6BC,4BAA4B,oBAAoB,CAAC;IACvF,gBAAgBJ;IAChB,cAAc;QAACK;KAAwB;AAC3C"}
@@ -0,0 +1,11 @@
1
+ import { RoleAfterDeleteEventHandler } from "../../../../features/security/roles/DeleteRole/index.js";
2
+ import { NotifyRoleChangeUseCase } from "./abstractions.js";
3
+ declare class NotifyOnRoleDeletedHandlerImpl implements RoleAfterDeleteEventHandler.Interface {
4
+ private notifyRoleChange;
5
+ constructor(notifyRoleChange: NotifyRoleChangeUseCase.Interface);
6
+ handle(event: RoleAfterDeleteEventHandler.Event): Promise<void>;
7
+ }
8
+ export declare const NotifyOnRoleDeletedHandler: typeof NotifyOnRoleDeletedHandlerImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("../../../eventPublisher/abstractions.js").IEventHandler<import("~/features/security/roles/DeleteRole/index.js").RoleAfterDeleteEvent>>;
10
+ };
11
+ export {};
@@ -0,0 +1,22 @@
1
+ import { RoleAfterDeleteEventHandler } from "../DeleteRole/index.js";
2
+ import { NotifyRoleChangeUseCase } from "./abstractions.js";
3
+ class NotifyOnRoleDeletedHandlerImpl {
4
+ constructor(notifyRoleChange){
5
+ this.notifyRoleChange = notifyRoleChange;
6
+ }
7
+ async handle(event) {
8
+ await this.notifyRoleChange.execute({
9
+ id: event.payload.role.id,
10
+ change: "deleted"
11
+ });
12
+ }
13
+ }
14
+ const NotifyOnRoleDeletedHandler = RoleAfterDeleteEventHandler.createImplementation({
15
+ implementation: NotifyOnRoleDeletedHandlerImpl,
16
+ dependencies: [
17
+ NotifyRoleChangeUseCase
18
+ ]
19
+ });
20
+ export { NotifyOnRoleDeletedHandler };
21
+
22
+ //# sourceMappingURL=NotifyOnRoleDeletedHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.js","sources":["../../../../../src/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.ts"],"sourcesContent":["import { RoleAfterDeleteEventHandler } from \"~/features/security/roles/DeleteRole/index.js\";\nimport { NotifyRoleChangeUseCase } from \"./abstractions.js\";\n\nclass NotifyOnRoleDeletedHandlerImpl implements RoleAfterDeleteEventHandler.Interface {\n constructor(private notifyRoleChange: NotifyRoleChangeUseCase.Interface) {}\n\n async handle(event: RoleAfterDeleteEventHandler.Event): Promise<void> {\n await this.notifyRoleChange.execute({ id: event.payload.role.id, change: \"deleted\" });\n }\n}\n\nexport const NotifyOnRoleDeletedHandler = RoleAfterDeleteEventHandler.createImplementation({\n implementation: NotifyOnRoleDeletedHandlerImpl,\n dependencies: [NotifyRoleChangeUseCase]\n});\n"],"names":["NotifyOnRoleDeletedHandlerImpl","notifyRoleChange","event","NotifyOnRoleDeletedHandler","RoleAfterDeleteEventHandler","NotifyRoleChangeUseCase"],"mappings":";;AAGA,MAAMA;IACF,YAAoBC,gBAAmD,CAAE;aAArDA,gBAAgB,GAAhBA;IAAsD;IAE1E,MAAM,OAAOC,KAAwC,EAAiB;QAClE,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;YAAE,IAAIA,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE;YAAE,QAAQ;QAAU;IACvF;AACJ;AAEO,MAAMC,6BAA6BC,4BAA4B,oBAAoB,CAAC;IACvF,gBAAgBJ;IAChB,cAAc;QAACK;KAAwB;AAC3C"}
@@ -0,0 +1,11 @@
1
+ import { RoleAfterUpdateEventHandler } from "../../../../features/security/roles/UpdateRole/index.js";
2
+ import { NotifyRoleChangeUseCase } from "./abstractions.js";
3
+ declare class NotifyOnRoleUpdatedHandlerImpl implements RoleAfterUpdateEventHandler.Interface {
4
+ private notifyRoleChange;
5
+ constructor(notifyRoleChange: NotifyRoleChangeUseCase.Interface);
6
+ handle(event: RoleAfterUpdateEventHandler.Event): Promise<void>;
7
+ }
8
+ export declare const NotifyOnRoleUpdatedHandler: typeof NotifyOnRoleUpdatedHandlerImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("../../../eventPublisher/abstractions.js").IEventHandler<import("~/features/security/roles/UpdateRole/index.js").RoleAfterUpdateEvent>>;
10
+ };
11
+ export {};