@webiny/api-core 6.6.0-alpha.0 → 6.6.0-alpha.10

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 (391) hide show
  1. package/ApiCoreFeature.js +12 -2
  2. package/ApiCoreFeature.js.map +1 -1
  3. package/exports/api/security/api-key.d.ts +1 -0
  4. package/exports/api/security/api-key.js +1 -0
  5. package/exports/api/tasks.d.ts +1 -0
  6. package/exports/api/tasks.js +1 -1
  7. package/exports/api.d.ts +1 -1
  8. package/exports/api.js +1 -1
  9. package/features/ai/Ai.d.ts +5 -1
  10. package/features/ai/Ai.js +72 -29
  11. package/features/ai/Ai.js.map +1 -1
  12. package/features/ai/AiModelRegistry.d.ts +14 -0
  13. package/features/ai/AiModelRegistry.js +39 -0
  14. package/features/ai/AiModelRegistry.js.map +1 -0
  15. package/features/ai/AiSdkToolHandlerResolver.d.ts +11 -0
  16. package/features/ai/AiSdkToolHandlerResolver.js +19 -0
  17. package/features/ai/AiSdkToolHandlerResolver.js.map +1 -0
  18. package/features/ai/AiSdkTools.d.ts +4 -3
  19. package/features/ai/AiSdkTools.js +11 -9
  20. package/features/ai/AiSdkTools.js.map +1 -1
  21. package/features/ai/AnthropicSdkFactory.js +24 -4
  22. package/features/ai/AnthropicSdkFactory.js.map +1 -1
  23. package/features/ai/DEVELOPERS.md +183 -0
  24. package/features/ai/GoogleSdkFactory.d.ts +10 -0
  25. package/features/ai/GoogleSdkFactory.js +65 -0
  26. package/features/ai/GoogleSdkFactory.js.map +1 -0
  27. package/features/ai/OpenAiSdkFactory.js +67 -11
  28. package/features/ai/OpenAiSdkFactory.js.map +1 -1
  29. package/features/ai/OpenRouterSdkFactory.d.ts +10 -0
  30. package/features/ai/OpenRouterSdkFactory.js +112 -0
  31. package/features/ai/OpenRouterSdkFactory.js.map +1 -0
  32. package/features/ai/RemoteAiModelCatalog.d.ts +13 -0
  33. package/features/ai/RemoteAiModelCatalog.js +74 -0
  34. package/features/ai/RemoteAiModelCatalog.js.map +1 -0
  35. package/features/ai/TextExtractor/DefaultTextExtractor.d.ts +9 -0
  36. package/features/ai/TextExtractor/DefaultTextExtractor.js +28 -0
  37. package/features/ai/TextExtractor/DefaultTextExtractor.js.map +1 -0
  38. package/features/ai/TextExtractor/abstractions.d.ts +12 -0
  39. package/features/ai/TextExtractor/abstractions.js +5 -0
  40. package/features/ai/TextExtractor/abstractions.js.map +1 -0
  41. package/features/ai/TextExtractor/index.d.ts +3 -0
  42. package/features/ai/TextExtractor/index.js +2 -0
  43. package/features/ai/TextExtractor/parsers/docxParser.d.ts +1 -0
  44. package/features/ai/TextExtractor/parsers/docxParser.js +111 -0
  45. package/features/ai/TextExtractor/parsers/docxParser.js.map +1 -0
  46. package/features/ai/abstractions.d.ts +102 -7
  47. package/features/ai/abstractions.js +6 -2
  48. package/features/ai/abstractions.js.map +1 -1
  49. package/features/ai/events.d.ts +59 -0
  50. package/features/ai/events.js +41 -0
  51. package/features/ai/events.js.map +1 -0
  52. package/features/ai/feature.js +12 -0
  53. package/features/ai/feature.js.map +1 -1
  54. package/features/ai/index.d.ts +5 -3
  55. package/features/ai/index.js +3 -1
  56. package/features/dateFormatter/DefaultDateFormatter.d.ts +15 -0
  57. package/features/dateFormatter/DefaultDateFormatter.js +20 -0
  58. package/features/dateFormatter/DefaultDateFormatter.js.map +1 -0
  59. package/features/dateFormatter/abstractions.d.ts +13 -0
  60. package/features/dateFormatter/abstractions.js +5 -0
  61. package/features/dateFormatter/abstractions.js.map +1 -0
  62. package/features/dateFormatter/feature.d.ts +4 -0
  63. package/features/dateFormatter/feature.js +11 -0
  64. package/features/dateFormatter/feature.js.map +1 -0
  65. package/features/dateFormatter/index.d.ts +3 -0
  66. package/features/dateFormatter/index.js +2 -0
  67. package/features/debugger/Debugger.d.ts +30 -0
  68. package/features/debugger/Debugger.js +142 -0
  69. package/features/debugger/Debugger.js.map +1 -0
  70. package/features/debugger/DebuggerRouteDecorator.d.ts +45 -0
  71. package/features/debugger/DebuggerRouteDecorator.js +102 -0
  72. package/features/debugger/DebuggerRouteDecorator.js.map +1 -0
  73. package/features/debugger/GraphQLDebuggerTransport.d.ts +28 -0
  74. package/features/debugger/GraphQLDebuggerTransport.js +45 -0
  75. package/features/debugger/GraphQLDebuggerTransport.js.map +1 -0
  76. package/features/debugger/__tests__/matchNamespace.test.d.ts +1 -0
  77. package/features/debugger/__tests__/matchNamespace.test.js +68 -0
  78. package/features/debugger/__tests__/matchNamespace.test.js.map +1 -0
  79. package/features/debugger/__tests__/serialize.test.d.ts +1 -0
  80. package/features/debugger/__tests__/serialize.test.js +220 -0
  81. package/features/debugger/__tests__/serialize.test.js.map +1 -0
  82. package/features/debugger/abstractions.d.ts +100 -0
  83. package/features/debugger/abstractions.js +6 -0
  84. package/features/debugger/abstractions.js.map +1 -0
  85. package/features/debugger/feature.d.ts +5 -0
  86. package/features/debugger/feature.js +15 -0
  87. package/features/debugger/feature.js.map +1 -0
  88. package/features/debugger/index.d.ts +12 -0
  89. package/features/debugger/index.js +7 -0
  90. package/features/debugger/limits.d.ts +18 -0
  91. package/features/debugger/limits.js +11 -0
  92. package/features/debugger/limits.js.map +1 -0
  93. package/features/debugger/matchNamespace.d.ts +14 -0
  94. package/features/debugger/matchNamespace.js +35 -0
  95. package/features/debugger/matchNamespace.js.map +1 -0
  96. package/features/debugger/parseNamespaceHeader.d.ts +7 -0
  97. package/features/debugger/parseNamespaceHeader.js +16 -0
  98. package/features/debugger/parseNamespaceHeader.js.map +1 -0
  99. package/features/debugger/permissions.d.ts +14 -0
  100. package/features/debugger/permissions.js +8 -0
  101. package/features/debugger/permissions.js.map +1 -0
  102. package/features/debugger/permissionsSchema.d.ts +17 -0
  103. package/features/debugger/permissionsSchema.js +18 -0
  104. package/features/debugger/permissionsSchema.js.map +1 -0
  105. package/features/debugger/serialize.d.ts +11 -0
  106. package/features/debugger/serialize.js +121 -0
  107. package/features/debugger/serialize.js.map +1 -0
  108. package/features/encryption/BuildParamsEncryptionConfig.d.ts +13 -0
  109. package/features/encryption/BuildParamsEncryptionConfig.js +19 -0
  110. package/features/encryption/BuildParamsEncryptionConfig.js.map +1 -0
  111. package/features/encryption/EncryptionKeyCacheFeature.d.ts +8 -0
  112. package/features/encryption/EncryptionKeyCacheFeature.js +11 -0
  113. package/features/encryption/EncryptionKeyCacheFeature.js.map +1 -0
  114. package/features/encryption/EncryptionService.d.ts +3 -2
  115. package/features/encryption/EncryptionService.js +15 -13
  116. package/features/encryption/EncryptionService.js.map +1 -1
  117. package/features/encryption/MemoryEncryptionKeyCache.d.ts +13 -0
  118. package/features/encryption/MemoryEncryptionKeyCache.js +26 -0
  119. package/features/encryption/MemoryEncryptionKeyCache.js.map +1 -0
  120. package/features/encryption/abstractions.d.ts +26 -0
  121. package/features/encryption/abstractions.js +3 -1
  122. package/features/encryption/abstractions.js.map +1 -1
  123. package/features/encryption/feature.js +2 -0
  124. package/features/encryption/feature.js.map +1 -1
  125. package/features/encryption/index.d.ts +3 -0
  126. package/features/encryption/index.js +3 -1
  127. package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.d.ts +13 -0
  128. package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js +61 -0
  129. package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js.map +1 -0
  130. package/features/hashing/BuildParamsHashingConfig.d.ts +11 -0
  131. package/features/hashing/BuildParamsHashingConfig.js +18 -0
  132. package/features/hashing/BuildParamsHashingConfig.js.map +1 -0
  133. package/features/hashing/ScryptHasher.d.ts +2 -2
  134. package/features/hashing/ScryptHasher.js +6 -8
  135. package/features/hashing/ScryptHasher.js.map +1 -1
  136. package/features/hashing/abstractions.d.ts +15 -0
  137. package/features/hashing/abstractions.js +2 -1
  138. package/features/hashing/abstractions.js.map +1 -1
  139. package/features/hashing/feature.js +2 -0
  140. package/features/hashing/feature.js.map +1 -1
  141. package/features/hashing/index.d.ts +1 -0
  142. package/features/hashing/index.js +1 -1
  143. package/features/httpClient/HttpClient.d.ts +7 -0
  144. package/features/httpClient/HttpClient.js +72 -0
  145. package/features/httpClient/HttpClient.js.map +1 -0
  146. package/features/httpClient/HttpRequestError.d.ts +10 -0
  147. package/features/httpClient/HttpRequestError.js +13 -0
  148. package/features/httpClient/HttpRequestError.js.map +1 -0
  149. package/features/httpClient/HttpStatusError.d.ts +12 -0
  150. package/features/httpClient/HttpStatusError.js +12 -0
  151. package/features/httpClient/HttpStatusError.js.map +1 -0
  152. package/features/httpClient/abstractions.d.ts +32 -0
  153. package/features/httpClient/abstractions.js +5 -0
  154. package/features/httpClient/abstractions.js.map +1 -0
  155. package/features/httpClient/feature.d.ts +4 -0
  156. package/features/httpClient/feature.js +11 -0
  157. package/features/httpClient/feature.js.map +1 -0
  158. package/features/httpClient/index.d.ts +3 -0
  159. package/features/httpClient/index.js +3 -0
  160. package/features/keyValueStore/GlobalKeyValueStore.d.ts +9 -3
  161. package/features/keyValueStore/GlobalKeyValueStore.js +12 -2
  162. package/features/keyValueStore/GlobalKeyValueStore.js.map +1 -1
  163. package/features/keyValueStore/KeyValueStore.d.ts +6 -2
  164. package/features/keyValueStore/KeyValueStore.js +13 -3
  165. package/features/keyValueStore/KeyValueStore.js.map +1 -1
  166. package/features/keyValueStore/KeyValueStoreRepository.d.ts +8 -2
  167. package/features/keyValueStore/KeyValueStoreRepository.js +82 -4
  168. package/features/keyValueStore/KeyValueStoreRepository.js.map +1 -1
  169. package/features/keyValueStore/abstractions.d.ts +132 -14
  170. package/features/keyValueStore/abstractions.js.map +1 -1
  171. package/features/keyValueStore/errors.d.ts +29 -0
  172. package/features/keyValueStore/errors.js +49 -1
  173. package/features/keyValueStore/errors.js.map +1 -1
  174. package/features/keyValueStore/index.d.ts +4 -1
  175. package/features/keyValueStore/index.js +1 -1
  176. package/features/logger/NullLogger.d.ts +10 -0
  177. package/features/logger/NullLogger.js +12 -0
  178. package/features/logger/NullLogger.js.map +1 -0
  179. package/features/logger/index.d.ts +1 -0
  180. package/features/logger/index.js +1 -0
  181. package/features/publicUrls/NullPublicUrls.d.ts +11 -0
  182. package/features/publicUrls/NullPublicUrls.js +17 -0
  183. package/features/publicUrls/NullPublicUrls.js.map +1 -0
  184. package/features/publicUrls/PublicUrl.d.ts +24 -0
  185. package/features/publicUrls/PublicUrl.js +43 -0
  186. package/features/publicUrls/PublicUrl.js.map +1 -0
  187. package/features/publicUrls/__tests__/PublicUrl.test.d.ts +1 -0
  188. package/features/publicUrls/__tests__/PublicUrl.test.js +38 -0
  189. package/features/publicUrls/__tests__/PublicUrl.test.js.map +1 -0
  190. package/features/publicUrls/__tests__/PublicUrls.test.d.ts +1 -0
  191. package/features/publicUrls/__tests__/PublicUrls.test.js +14 -0
  192. package/features/publicUrls/__tests__/PublicUrls.test.js.map +1 -0
  193. package/features/publicUrls/abstractions.d.ts +27 -0
  194. package/features/publicUrls/abstractions.js +5 -0
  195. package/features/publicUrls/abstractions.js.map +1 -0
  196. package/features/publicUrls/feature.d.ts +8 -0
  197. package/features/publicUrls/feature.js +11 -0
  198. package/features/publicUrls/feature.js.map +1 -0
  199. package/features/publicUrls/index.d.ts +3 -0
  200. package/features/publicUrls/index.js +3 -0
  201. package/features/requestContext/RawAssumePermissions.d.ts +14 -0
  202. package/features/requestContext/RawAssumePermissions.js +19 -0
  203. package/features/requestContext/RawAssumePermissions.js.map +1 -0
  204. package/features/requestContext/abstractions.d.ts +22 -0
  205. package/features/requestContext/abstractions.js +2 -1
  206. package/features/requestContext/abstractions.js.map +1 -1
  207. package/features/requestContext/extractAssumePermissions.d.ts +14 -0
  208. package/features/requestContext/extractAssumePermissions.js +32 -0
  209. package/features/requestContext/extractAssumePermissions.js.map +1 -0
  210. package/features/requestContext/feature.d.ts +2 -1
  211. package/features/requestContext/feature.js +2 -0
  212. package/features/requestContext/feature.js.map +1 -1
  213. package/features/requestContext/index.d.ts +3 -1
  214. package/features/requestContext/index.js +2 -1
  215. package/features/security/IdentityContext/IdentityContext.d.ts +8 -4
  216. package/features/security/IdentityContext/IdentityContext.js +28 -11
  217. package/features/security/IdentityContext/IdentityContext.js.map +1 -1
  218. package/features/security/IdentityContext/abstractions.d.ts +6 -1
  219. package/features/security/IdentityContext/abstractions.js.map +1 -1
  220. package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js +11 -6
  221. package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js.map +1 -1
  222. package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.d.ts +1 -1
  223. package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js.map +1 -1
  224. package/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.d.ts +1 -3
  225. package/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.js.map +1 -1
  226. package/features/security/apiKeys/GetApiKeyBySlug/abstractions.d.ts +1 -1
  227. package/features/security/apiKeys/GetApiKeyBySlug/abstractions.js.map +1 -1
  228. package/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.d.ts +1 -3
  229. package/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.js.map +1 -1
  230. package/features/security/apiKeys/GetApiKeyByToken/abstractions.d.ts +1 -1
  231. package/features/security/apiKeys/GetApiKeyByToken/abstractions.js.map +1 -1
  232. package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js +9 -3
  233. package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js.map +1 -1
  234. package/features/security/apiKeys/feature.js +7 -2
  235. package/features/security/apiKeys/feature.js.map +1 -1
  236. package/features/security/apiKeys/shared/ApiKeyProvider.d.ts +3 -5
  237. package/features/security/apiKeys/shared/ApiKeyProvider.js +6 -21
  238. package/features/security/apiKeys/shared/ApiKeyProvider.js.map +1 -1
  239. package/features/security/apiKeys/shared/ApiKeysRepository.d.ts +1 -0
  240. package/features/security/apiKeys/shared/ApiKeysRepository.js +19 -4
  241. package/features/security/apiKeys/shared/ApiKeysRepository.js.map +1 -1
  242. package/features/security/apiKeys/shared/generateToken.d.ts +1 -1
  243. package/features/security/apiKeys/shared/generateToken.js.map +1 -1
  244. package/features/security/apiKeys/shared/schemas.d.ts +2 -2
  245. package/features/security/apiKeys/shared/schemas.js +2 -2
  246. package/features/security/apiKeys/shared/schemas.js.map +1 -1
  247. package/features/security/apiKeys/shared/types.d.ts +1 -1
  248. package/features/security/authorization/AuthorizationContext/AuthorizationContext.d.ts +13 -3
  249. package/features/security/authorization/AuthorizationContext/AuthorizationContext.js +35 -22
  250. package/features/security/authorization/AuthorizationContext/AuthorizationContext.js.map +1 -1
  251. package/features/security/authorization/AuthorizationContext/abstractions.d.ts +2 -0
  252. package/features/security/authorization/AuthorizationContext/abstractions.js.map +1 -1
  253. package/features/security/authorization/AuthorizationContext/feature.js +6 -1
  254. package/features/security/authorization/AuthorizationContext/feature.js.map +1 -1
  255. package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.d.ts +30 -0
  256. package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.js +60 -0
  257. package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.js.map +1 -0
  258. package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.d.ts +3 -3
  259. package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js +5 -5
  260. package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js.map +1 -1
  261. package/features/security/authorization/GroupsTeamsAuthorizer/feature.js +2 -0
  262. package/features/security/authorization/GroupsTeamsAuthorizer/feature.js.map +1 -1
  263. package/features/security/roles/CreateRole/CreateRoleUseCase.js +11 -6
  264. package/features/security/roles/CreateRole/CreateRoleUseCase.js.map +1 -1
  265. package/features/security/roles/CreateRole/schema.d.ts +1 -1
  266. package/features/security/roles/CreateRole/schema.js +1 -1
  267. package/features/security/roles/CreateRole/schema.js.map +1 -1
  268. package/features/security/roles/Installer/RolesInstaller.js +1 -0
  269. package/features/security/roles/Installer/RolesInstaller.js.map +1 -1
  270. package/features/security/roles/UpdateRole/UpdateRoleUseCase.js +9 -3
  271. package/features/security/roles/UpdateRole/UpdateRoleUseCase.js.map +1 -1
  272. package/features/security/roles/UpdateRole/schema.d.ts +1 -1
  273. package/features/security/roles/UpdateRole/schema.js +1 -1
  274. package/features/security/roles/UpdateRole/schema.js.map +1 -1
  275. package/features/security/shared/description.d.ts +4 -0
  276. package/features/security/shared/description.js +7 -0
  277. package/features/security/shared/description.js.map +1 -0
  278. package/features/security/shared/index.d.ts +1 -0
  279. package/features/security/shared/index.js +1 -0
  280. package/features/security/teams/CreateTeam/CreateTeamUseCase.d.ts +3 -1
  281. package/features/security/teams/CreateTeam/CreateTeamUseCase.js +20 -8
  282. package/features/security/teams/CreateTeam/CreateTeamUseCase.js.map +1 -1
  283. package/features/security/teams/CreateTeam/schema.d.ts +1 -1
  284. package/features/security/teams/CreateTeam/schema.js +1 -1
  285. package/features/security/teams/CreateTeam/schema.js.map +1 -1
  286. package/features/security/teams/UpdateTeam/UpdateTeamUseCase.d.ts +3 -1
  287. package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js +20 -5
  288. package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js.map +1 -1
  289. package/features/security/teams/UpdateTeam/schema.d.ts +1 -1
  290. package/features/security/teams/UpdateTeam/schema.js +1 -1
  291. package/features/security/teams/UpdateTeam/schema.js.map +1 -1
  292. package/features/security/teams/shared/resolveRoleIdentifiers.d.ts +17 -0
  293. package/features/security/teams/shared/resolveRoleIdentifiers.js +32 -0
  294. package/features/security/teams/shared/resolveRoleIdentifiers.js.map +1 -0
  295. package/features/slugify/DefaultSlugify.d.ts +8 -0
  296. package/features/slugify/DefaultSlugify.js +20 -0
  297. package/features/slugify/DefaultSlugify.js.map +1 -0
  298. package/features/slugify/abstractions.d.ts +12 -0
  299. package/features/slugify/abstractions.js +5 -0
  300. package/features/slugify/abstractions.js.map +1 -0
  301. package/features/{logger → slugify}/feature.d.ts +1 -1
  302. package/features/slugify/feature.js +11 -0
  303. package/features/slugify/feature.js.map +1 -0
  304. package/features/slugify/index.d.ts +3 -0
  305. package/features/slugify/index.js +2 -0
  306. package/features/stringFormatter/DefaultStringFormatter.d.ts +17 -0
  307. package/features/stringFormatter/DefaultStringFormatter.js +19 -0
  308. package/features/stringFormatter/DefaultStringFormatter.js.map +1 -0
  309. package/features/stringFormatter/abstractions.d.ts +11 -0
  310. package/features/stringFormatter/abstractions.js +5 -0
  311. package/features/stringFormatter/abstractions.js.map +1 -0
  312. package/features/stringFormatter/feature.d.ts +4 -0
  313. package/features/stringFormatter/feature.js +13 -0
  314. package/features/stringFormatter/feature.js.map +1 -0
  315. package/features/stringFormatter/index.d.ts +3 -0
  316. package/features/stringFormatter/index.js +2 -0
  317. package/features/task/TaskDefinition/abstractions.d.ts +69 -4
  318. package/features/task/TaskDefinition/abstractions.js +2 -1
  319. package/features/task/TaskDefinition/abstractions.js.map +1 -1
  320. package/features/tenancy/TenantContext/TenantContext.d.ts +5 -1
  321. package/features/tenancy/TenantContext/TenantContext.js +31 -23
  322. package/features/tenancy/TenantContext/TenantContext.js.map +1 -1
  323. package/features/users/shared/loaders.js.map +1 -1
  324. package/features/users/shared/types.d.ts +9 -7
  325. package/features/wcp/WcpContext/WcpContext.d.ts +11 -0
  326. package/features/wcp/WcpContext/WcpContext.js +33 -0
  327. package/features/wcp/WcpContext/WcpContext.js.map +1 -1
  328. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +14 -60
  329. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +77 -25
  330. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
  331. package/features/wcp/WcpFeature.js +2 -0
  332. package/features/wcp/WcpFeature.js.map +1 -1
  333. package/features/wcp/WcpLicenseLoader.d.ts +25 -0
  334. package/features/wcp/WcpLicenseLoader.js +58 -0
  335. package/features/wcp/WcpLicenseLoader.js.map +1 -0
  336. package/features/wcp/WcpLicenseProvider.d.ts +6 -14
  337. package/features/wcp/WcpLicenseProvider.js +3 -7
  338. package/features/wcp/WcpLicenseProvider.js.map +1 -1
  339. package/features/wcp/resolveWcpProjectEnvironment.d.ts +9 -0
  340. package/features/wcp/resolveWcpProjectEnvironment.js +23 -0
  341. package/features/wcp/resolveWcpProjectEnvironment.js.map +1 -0
  342. package/graphql/ApiCoreSchemaFactory.d.ts +1 -0
  343. package/graphql/ApiCoreSchemaFactory.js +7 -1
  344. package/graphql/ApiCoreSchemaFactory.js.map +1 -1
  345. package/graphql/featureFlags/FeatureFlagsSchemaFactory.d.ts +10 -0
  346. package/graphql/featureFlags/FeatureFlagsSchemaFactory.js +53 -0
  347. package/graphql/featureFlags/FeatureFlagsSchemaFactory.js.map +1 -0
  348. package/graphql/security/SecuritySchemaFactory.d.ts +1 -0
  349. package/graphql/security/SecuritySchemaFactory.js +4 -0
  350. package/graphql/security/SecuritySchemaFactory.js.map +1 -1
  351. package/graphql/system/SystemSchemaFactory.d.ts +1 -0
  352. package/graphql/system/SystemSchemaFactory.js +4 -0
  353. package/graphql/system/SystemSchemaFactory.js.map +1 -1
  354. package/graphql/users/UsersSchemaFactory.d.ts +1 -0
  355. package/graphql/users/UsersSchemaFactory.js +4 -0
  356. package/graphql/users/UsersSchemaFactory.js.map +1 -1
  357. package/graphql/wcp/WcpSchemaFactory.d.ts +1 -0
  358. package/graphql/wcp/WcpSchemaFactory.js +6 -0
  359. package/graphql/wcp/WcpSchemaFactory.js.map +1 -1
  360. package/idp/JwksCache.d.ts +14 -3
  361. package/idp/JwksCache.js +97 -17
  362. package/idp/JwksCache.js.map +1 -1
  363. package/idp/JwksStoreFeature.d.ts +8 -0
  364. package/idp/JwksStoreFeature.js +11 -0
  365. package/idp/JwksStoreFeature.js.map +1 -0
  366. package/idp/MemoryJwksStore.d.ts +14 -0
  367. package/idp/MemoryJwksStore.js +21 -0
  368. package/idp/MemoryJwksStore.js.map +1 -0
  369. package/idp/OidcJwtIdentityProvider.js +5 -1
  370. package/idp/OidcJwtIdentityProvider.js.map +1 -1
  371. package/idp/abstractions.d.ts +24 -0
  372. package/idp/abstractions.js +2 -1
  373. package/idp/abstractions.js.map +1 -1
  374. package/idp/feature.js +1 -2
  375. package/idp/feature.js.map +1 -1
  376. package/idp/index.d.ts +1 -0
  377. package/idp/index.js +1 -0
  378. package/package.json +22 -22
  379. package/testing/environment.d.ts +14 -0
  380. package/testing/environment.js +18 -0
  381. package/testing/environment.js.map +1 -0
  382. package/types/security.d.ts +1 -1
  383. package/types/users.d.ts +2 -3
  384. package/features/logger/LoggerService.d.ts +0 -14
  385. package/features/logger/LoggerService.js +0 -48
  386. package/features/logger/LoggerService.js.map +0 -1
  387. package/features/logger/feature.js +0 -11
  388. package/features/logger/feature.js.map +0 -1
  389. package/features/wcp/loadWcpLicense.d.ts +0 -2
  390. package/features/wcp/loadWcpLicense.js +0 -51
  391. package/features/wcp/loadWcpLicense.js.map +0 -1
@@ -0,0 +1,27 @@
1
+ import type { PublicUrl } from "./PublicUrl.js";
2
+ export interface IPublicUrls {
3
+ /**
4
+ * Public URL of the API for the current tenant, e.g. https://api.example.com. Uses the custom
5
+ * domain when one is configured. Unknown (see `PublicUrl.isKnown()`) when the deployment doesn't
6
+ * know it.
7
+ */
8
+ getApiUrl(): Promise<PublicUrl>;
9
+ /**
10
+ * Public URL of the Admin app for the current tenant, e.g. https://admin.example.com. Uses the
11
+ * custom domain when one is configured. Unknown when the deployment doesn't know it (e.g. the
12
+ * API is deployed but the Admin app isn't yet).
13
+ */
14
+ getAdminUrl(): Promise<PublicUrl>;
15
+ }
16
+ /**
17
+ * Public URLs of this deployment's API and Admin app. Each hosting type supplies its own
18
+ * implementation: AWS reads the service manifest written at deploy time
19
+ * (`@webiny/api-event-handler-aws`), standalone reads the `WEBINY_API_URL` / `WEBINY_ADMIN_URL`
20
+ * build params (`@webiny/api-event-handler-standalone`).
21
+ *
22
+ * Resolve per request and don't cache the result globally: values are "for the current tenant".
23
+ */
24
+ export declare const PublicUrls: import("@webiny/di").Abstraction<IPublicUrls>;
25
+ export declare namespace PublicUrls {
26
+ type Interface = IPublicUrls;
27
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const PublicUrls = createAbstraction("Core/PublicUrls");
3
+ export { PublicUrls };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/publicUrls/abstractions.js","sources":["../../../src/features/publicUrls/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { PublicUrl } from \"./PublicUrl.js\";\n\nexport interface IPublicUrls {\n /**\n * Public URL of the API for the current tenant, e.g. https://api.example.com. Uses the custom\n * domain when one is configured. Unknown (see `PublicUrl.isKnown()`) when the deployment doesn't\n * know it.\n */\n getApiUrl(): Promise<PublicUrl>;\n /**\n * Public URL of the Admin app for the current tenant, e.g. https://admin.example.com. Uses the\n * custom domain when one is configured. Unknown when the deployment doesn't know it (e.g. the\n * API is deployed but the Admin app isn't yet).\n */\n getAdminUrl(): Promise<PublicUrl>;\n}\n\n/**\n * Public URLs of this deployment's API and Admin app. Each hosting type supplies its own\n * implementation: AWS reads the service manifest written at deploy time\n * (`@webiny/api-event-handler-aws`), standalone reads the `WEBINY_API_URL` / `WEBINY_ADMIN_URL`\n * build params (`@webiny/api-event-handler-standalone`).\n *\n * Resolve per request and don't cache the result globally: values are \"for the current tenant\".\n */\nexport const PublicUrls = createAbstraction<IPublicUrls>(\"Core/PublicUrls\");\n\nexport namespace PublicUrls {\n export type Interface = IPublicUrls;\n}\n"],"names":["PublicUrls","createAbstraction"],"mappings":";AA0BO,MAAMA,aAAaC,kBAA+B"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Registers the default, which knows no URLs. Each hosting type overrides it through the
3
+ * `publicUrls` hook of `registerApiRequestStack`.
4
+ */
5
+ export declare const PublicUrlsFeature: {
6
+ name: string;
7
+ register(container: import("@webiny/di").Container): void;
8
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { NullPublicUrls } from "./NullPublicUrls.js";
3
+ const PublicUrlsFeature = createFeature({
4
+ name: "PublicUrlsFeature",
5
+ register (container) {
6
+ container.register(NullPublicUrls);
7
+ }
8
+ });
9
+ export { PublicUrlsFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/publicUrls/feature.js","sources":["../../../src/features/publicUrls/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { NullPublicUrls } from \"./NullPublicUrls.js\";\n\n/**\n * Registers the default, which knows no URLs. Each hosting type overrides it through the\n * `publicUrls` hook of `registerApiRequestStack`.\n */\nexport const PublicUrlsFeature = createFeature({\n name: \"PublicUrlsFeature\",\n register(container) {\n container.register(NullPublicUrls);\n }\n});\n"],"names":["PublicUrlsFeature","createFeature","container","NullPublicUrls"],"mappings":";;AAOO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1,3 @@
1
+ export { PublicUrls } from "./abstractions.js";
2
+ export { PublicUrl } from "./PublicUrl.js";
3
+ export { PublicUrlsFeature } from "./feature.js";
@@ -0,0 +1,3 @@
1
+ export { PublicUrls } from "./abstractions.js";
2
+ export { PublicUrl } from "./PublicUrl.js";
3
+ export { PublicUrlsFeature } from "./feature.js";
@@ -0,0 +1,14 @@
1
+ import { RawAssumePermissions as Abstraction } from "./abstractions.js";
2
+ /**
3
+ * Per-request holder for the transport-extracted preview target. Registered per request, so a
4
+ * fresh instance holds the value for the current request only.
5
+ */
6
+ declare class RawAssumePermissionsImpl implements Abstraction.Interface {
7
+ private value;
8
+ get(): Abstraction.Target | null;
9
+ set(value: Abstraction.Target | null): void;
10
+ }
11
+ export declare const RawAssumePermissions: typeof RawAssumePermissionsImpl & {
12
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IRawAssumePermissions>;
13
+ };
14
+ export {};
@@ -0,0 +1,19 @@
1
+ import { RawAssumePermissions } from "./abstractions.js";
2
+ class RawAssumePermissionsImpl {
3
+ get() {
4
+ return this.value;
5
+ }
6
+ set(value) {
7
+ this.value = value;
8
+ }
9
+ constructor(){
10
+ this.value = null;
11
+ }
12
+ }
13
+ const RawAssumePermissions_RawAssumePermissions = RawAssumePermissions.createImplementation({
14
+ implementation: RawAssumePermissionsImpl,
15
+ dependencies: []
16
+ });
17
+ export { RawAssumePermissions_RawAssumePermissions as RawAssumePermissions };
18
+
19
+ //# sourceMappingURL=RawAssumePermissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/requestContext/RawAssumePermissions.js","sources":["../../../src/features/requestContext/RawAssumePermissions.ts"],"sourcesContent":["import { RawAssumePermissions as Abstraction } from \"./abstractions.js\";\n\n/**\n * Per-request holder for the transport-extracted preview target. Registered per request, so a\n * fresh instance holds the value for the current request only.\n */\nclass RawAssumePermissionsImpl implements Abstraction.Interface {\n private value: Abstraction.Target | null = null;\n\n get(): Abstraction.Target | null {\n return this.value;\n }\n\n set(value: Abstraction.Target | null): void {\n this.value = value;\n }\n}\n\nexport const RawAssumePermissions = Abstraction.createImplementation({\n implementation: RawAssumePermissionsImpl,\n dependencies: []\n});\n"],"names":["RawAssumePermissionsImpl","value","RawAssumePermissions","Abstraction"],"mappings":";AAMA,MAAMA;IAGF,MAAiC;QAC7B,OAAO,IAAI,CAAC,KAAK;IACrB;IAEA,IAAIC,KAAgC,EAAQ;QACxC,IAAI,CAAC,KAAK,GAAGA;IACjB;;aARQ,KAAK,GAA8B;;AAS/C;AAEO,MAAMC,4CAAuBC,qBAAAA,oBAAgC,CAAC;IACjE,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
@@ -29,6 +29,28 @@ export declare const RawAuthToken: import("@webiny/di").Abstraction<IRawAuthToke
29
29
  export declare namespace RawAuthToken {
30
30
  type Interface = IRawAuthToken;
31
31
  }
32
+ /**
33
+ * Per-request holder for the role or team the caller asked to be evaluated as, EXTRACTED by the
34
+ * transport from the `x-webiny-assume-permissions` header. This is a preview mechanism: it can
35
+ * only ever narrow what a caller may do, never widen it. AssumedPermissions reads this holder and
36
+ * substitutes the permission set, but only after confirming the caller's own permissions grant
37
+ * full access.
38
+ *
39
+ * Note: only the HTTP transports set this. S3 and background tasks have no caller to preview as.
40
+ */
41
+ export interface IAssumePermissionsTarget {
42
+ type: "role" | "team";
43
+ id: string;
44
+ }
45
+ export interface IRawAssumePermissions {
46
+ get(): IAssumePermissionsTarget | null;
47
+ set(value: IAssumePermissionsTarget | null): void;
48
+ }
49
+ export declare const RawAssumePermissions: import("@webiny/di").Abstraction<IRawAssumePermissions>;
50
+ export declare namespace RawAssumePermissions {
51
+ type Interface = IRawAssumePermissions;
52
+ type Target = IAssumePermissionsTarget;
53
+ }
32
54
  /**
33
55
  * LOAD step: authenticates the token held by RawAuthToken and sets IdentityContext. Fully
34
56
  * transport-agnostic — transports only EXTRACT the token into RawAuthToken.
@@ -1,8 +1,9 @@
1
1
  import { createAbstraction } from "@webiny/feature/api";
2
2
  const RawTenantId = createAbstraction("RequestContext/RawTenantId");
3
3
  const RawAuthToken = createAbstraction("RequestContext/RawAuthToken");
4
+ const RawAssumePermissions = createAbstraction("RequestContext/RawAssumePermissions");
4
5
  const RequestIdentityLoader = createAbstraction("RequestContext/RequestIdentityLoader");
5
6
  const RequestTenantLoader = createAbstraction("RequestContext/RequestTenantLoader");
6
- export { RawAuthToken, RawTenantId, RequestIdentityLoader, RequestTenantLoader };
7
+ export { RawAssumePermissions, RawAuthToken, RawTenantId, RequestIdentityLoader, RequestTenantLoader };
7
8
 
8
9
  //# sourceMappingURL=abstractions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"features/requestContext/abstractions.js","sources":["../../../src/features/requestContext/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\n/**\n * Per-request holder for the raw tenant id EXTRACTED by the transport (e.g. the `x-tenant` header\n * of an API Gateway event, the bucket name of an S3 event, or `payload.tenant` of a background\n * task). The transport-specific EXTRACT step sets this; the transport-agnostic LOAD step\n * (RequestTenantLoader) reads it, resolves the Tenant, and sets TenantContext.\n */\nexport interface IRawTenantId {\n get(): string | null;\n set(id: string | null): void;\n}\n\nexport const RawTenantId = createAbstraction<IRawTenantId>(\"RequestContext/RawTenantId\");\n\nexport namespace RawTenantId {\n export type Interface = IRawTenantId;\n}\n\n/**\n * Per-request holder for the raw auth token EXTRACTED by the transport (e.g. the `Authorization`\n * bearer header or an auth cookie of an API Gateway event). Only token-based transports set this;\n * the transport-agnostic LOAD step (RequestIdentityLoader) reads it, authenticates it, and\n * sets IdentityContext. A null/absent value authenticates as anonymous.\n *\n * Note: non-token transports (S3, background tasks) never set this — S3 has no user identity, and\n * background-task identity is derived from `task.createdBy` after the task is fetched.\n */\nexport interface IRawAuthToken {\n get(): string | null;\n set(token: string | null): void;\n}\n\nexport const RawAuthToken = createAbstraction<IRawAuthToken>(\"RequestContext/RawAuthToken\");\n\nexport namespace RawAuthToken {\n export type Interface = IRawAuthToken;\n}\n\n/**\n * LOAD step: authenticates the token held by RawAuthToken and sets IdentityContext. Fully\n * transport-agnostic — transports only EXTRACT the token into RawAuthToken.\n */\nexport interface IRequestIdentityLoader {\n establish(): Promise<void>;\n}\n\nexport const RequestIdentityLoader = createAbstraction<IRequestIdentityLoader>(\n \"RequestContext/RequestIdentityLoader\"\n);\n\nexport namespace RequestIdentityLoader {\n export type Interface = IRequestIdentityLoader;\n}\n\n/**\n * LOAD step: resolves the Tenant for the id held by RawTenantId and sets TenantContext. Fully\n * transport-agnostic — transports only EXTRACT the id into RawTenantId.\n */\nexport interface IRequestTenantLoader {\n establish(): Promise<void>;\n}\n\nexport const RequestTenantLoader = createAbstraction<IRequestTenantLoader>(\n \"RequestContext/RequestTenantLoader\"\n);\n\nexport namespace RequestTenantLoader {\n export type Interface = IRequestTenantLoader;\n}\n"],"names":["RawTenantId","createAbstraction","RawAuthToken","RequestIdentityLoader","RequestTenantLoader"],"mappings":";AAaO,MAAMA,cAAcC,kBAAgC;AAoBpD,MAAMC,eAAeD,kBAAiC;AActD,MAAME,wBAAwBF,kBACjC;AAeG,MAAMG,sBAAsBH,kBAC/B"}
1
+ {"version":3,"file":"features/requestContext/abstractions.js","sources":["../../../src/features/requestContext/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\n/**\n * Per-request holder for the raw tenant id EXTRACTED by the transport (e.g. the `x-tenant` header\n * of an API Gateway event, the bucket name of an S3 event, or `payload.tenant` of a background\n * task). The transport-specific EXTRACT step sets this; the transport-agnostic LOAD step\n * (RequestTenantLoader) reads it, resolves the Tenant, and sets TenantContext.\n */\nexport interface IRawTenantId {\n get(): string | null;\n set(id: string | null): void;\n}\n\nexport const RawTenantId = createAbstraction<IRawTenantId>(\"RequestContext/RawTenantId\");\n\nexport namespace RawTenantId {\n export type Interface = IRawTenantId;\n}\n\n/**\n * Per-request holder for the raw auth token EXTRACTED by the transport (e.g. the `Authorization`\n * bearer header or an auth cookie of an API Gateway event). Only token-based transports set this;\n * the transport-agnostic LOAD step (RequestIdentityLoader) reads it, authenticates it, and\n * sets IdentityContext. A null/absent value authenticates as anonymous.\n *\n * Note: non-token transports (S3, background tasks) never set this — S3 has no user identity, and\n * background-task identity is derived from `task.createdBy` after the task is fetched.\n */\nexport interface IRawAuthToken {\n get(): string | null;\n set(token: string | null): void;\n}\n\nexport const RawAuthToken = createAbstraction<IRawAuthToken>(\"RequestContext/RawAuthToken\");\n\nexport namespace RawAuthToken {\n export type Interface = IRawAuthToken;\n}\n\n/**\n * Per-request holder for the role or team the caller asked to be evaluated as, EXTRACTED by the\n * transport from the `x-webiny-assume-permissions` header. This is a preview mechanism: it can\n * only ever narrow what a caller may do, never widen it. AssumedPermissions reads this holder and\n * substitutes the permission set, but only after confirming the caller's own permissions grant\n * full access.\n *\n * Note: only the HTTP transports set this. S3 and background tasks have no caller to preview as.\n */\nexport interface IAssumePermissionsTarget {\n /*\n * Whose permissions to assume. A team is a set of roles, so assuming one means the union of its\n * roles' permissions. Assuming a user's permissions would be another type here, resolved to\n * that user's roles and teams the same way.\n */\n type: \"role\" | \"team\";\n id: string;\n}\n\nexport interface IRawAssumePermissions {\n get(): IAssumePermissionsTarget | null;\n set(value: IAssumePermissionsTarget | null): void;\n}\n\nexport const RawAssumePermissions = createAbstraction<IRawAssumePermissions>(\n \"RequestContext/RawAssumePermissions\"\n);\n\nexport namespace RawAssumePermissions {\n export type Interface = IRawAssumePermissions;\n export type Target = IAssumePermissionsTarget;\n}\n\n/**\n * LOAD step: authenticates the token held by RawAuthToken and sets IdentityContext. Fully\n * transport-agnostic — transports only EXTRACT the token into RawAuthToken.\n */\nexport interface IRequestIdentityLoader {\n establish(): Promise<void>;\n}\n\nexport const RequestIdentityLoader = createAbstraction<IRequestIdentityLoader>(\n \"RequestContext/RequestIdentityLoader\"\n);\n\nexport namespace RequestIdentityLoader {\n export type Interface = IRequestIdentityLoader;\n}\n\n/**\n * LOAD step: resolves the Tenant for the id held by RawTenantId and sets TenantContext. Fully\n * transport-agnostic — transports only EXTRACT the id into RawTenantId.\n */\nexport interface IRequestTenantLoader {\n establish(): Promise<void>;\n}\n\nexport const RequestTenantLoader = createAbstraction<IRequestTenantLoader>(\n \"RequestContext/RequestTenantLoader\"\n);\n\nexport namespace RequestTenantLoader {\n export type Interface = IRequestTenantLoader;\n}\n"],"names":["RawTenantId","createAbstraction","RawAuthToken","RawAssumePermissions","RequestIdentityLoader","RequestTenantLoader"],"mappings":";AAaO,MAAMA,cAAcC,kBAAgC;AAoBpD,MAAMC,eAAeD,kBAAiC;AA8BtD,MAAME,uBAAuBF,kBAChC;AAgBG,MAAMG,wBAAwBH,kBACjC;AAeG,MAAMI,sBAAsBJ,kBAC/B"}
@@ -0,0 +1,14 @@
1
+ import { RawAssumePermissions } from "./abstractions.js";
2
+ export declare const ASSUME_PERMISSIONS_HEADER = "x-webiny-assume-permissions";
3
+ type HeaderValue = string | string[] | undefined;
4
+ type Headers = Record<string, HeaderValue> | undefined;
5
+ /**
6
+ * Reads the `x-webiny-assume-permissions` header and parses it into the role or team whose
7
+ * permissions should be previewed. The value is `role:<id>` or `team:<id>`.
8
+ *
9
+ * Anything else parses to null, which leaves the caller's own permissions untouched. Lives in
10
+ * api-core rather than in a transport package so the HTTP transports cannot drift on the format or
11
+ * on header casing.
12
+ */
13
+ export declare function extractAssumePermissions(headers: Headers): RawAssumePermissions.Target | null;
14
+ export {};
@@ -0,0 +1,32 @@
1
+ const ASSUME_PERMISSIONS_HEADER = "x-webiny-assume-permissions";
2
+ function readHeader(headers, name) {
3
+ if (!headers) return null;
4
+ for (const key of Object.keys(headers)){
5
+ if (key.toLowerCase() !== name) continue;
6
+ const value = headers[key];
7
+ if (Array.isArray(value)) return value[0] ?? null;
8
+ return value ?? null;
9
+ }
10
+ return null;
11
+ }
12
+ function extractAssumePermissions(headers) {
13
+ const value = readHeader(headers, ASSUME_PERMISSIONS_HEADER);
14
+ if (!value) return null;
15
+ const separatorIndex = value.indexOf(":");
16
+ if (separatorIndex < 1) return null;
17
+ const type = value.slice(0, separatorIndex).trim();
18
+ const id = value.slice(separatorIndex + 1).trim();
19
+ if ("" === id) return null;
20
+ if ("role" === type) return {
21
+ type: "role",
22
+ id
23
+ };
24
+ if ("team" === type) return {
25
+ type: "team",
26
+ id
27
+ };
28
+ return null;
29
+ }
30
+ export { ASSUME_PERMISSIONS_HEADER, extractAssumePermissions };
31
+
32
+ //# sourceMappingURL=extractAssumePermissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/requestContext/extractAssumePermissions.js","sources":["../../../src/features/requestContext/extractAssumePermissions.ts"],"sourcesContent":["import { RawAssumePermissions } from \"./abstractions.js\";\n\nexport const ASSUME_PERMISSIONS_HEADER = \"x-webiny-assume-permissions\";\n\ntype HeaderValue = string | string[] | undefined;\ntype Headers = Record<string, HeaderValue> | undefined;\n\nfunction readHeader(headers: Headers, name: string): string | null {\n if (!headers) {\n return null;\n }\n\n /*\n * Header names are case-insensitive, and the casing that reaches us depends on the transport\n * and on the client, so match on the lowercased key rather than guessing a spelling. Node's\n * IncomingMessage also hands back an array when a header repeats.\n */\n for (const key of Object.keys(headers)) {\n if (key.toLowerCase() !== name) {\n continue;\n }\n\n const value = headers[key];\n if (Array.isArray(value)) {\n return value[0] ?? null;\n }\n\n return value ?? null;\n }\n\n return null;\n}\n\n/**\n * Reads the `x-webiny-assume-permissions` header and parses it into the role or team whose\n * permissions should be previewed. The value is `role:<id>` or `team:<id>`.\n *\n * Anything else parses to null, which leaves the caller's own permissions untouched. Lives in\n * api-core rather than in a transport package so the HTTP transports cannot drift on the format or\n * on header casing.\n */\nexport function extractAssumePermissions(headers: Headers): RawAssumePermissions.Target | null {\n const value = readHeader(headers, ASSUME_PERMISSIONS_HEADER);\n if (!value) {\n return null;\n }\n\n const separatorIndex = value.indexOf(\":\");\n if (separatorIndex < 1) {\n return null;\n }\n\n const type = value.slice(0, separatorIndex).trim();\n const id = value.slice(separatorIndex + 1).trim();\n\n if (id === \"\") {\n return null;\n }\n\n if (type === \"role\") {\n return { type: \"role\", id };\n }\n\n if (type === \"team\") {\n return { type: \"team\", id };\n }\n\n return null;\n}\n"],"names":["ASSUME_PERMISSIONS_HEADER","readHeader","headers","name","key","Object","value","Array","extractAssumePermissions","separatorIndex","type","id"],"mappings":"AAEO,MAAMA,4BAA4B;AAKzC,SAASC,WAAWC,OAAgB,EAAEC,IAAY;IAC9C,IAAI,CAACD,SACD,OAAO;IAQX,KAAK,MAAME,OAAOC,OAAO,IAAI,CAACH,SAAU;QACpC,IAAIE,IAAI,WAAW,OAAOD,MACtB;QAGJ,MAAMG,QAAQJ,OAAO,CAACE,IAAI;QAC1B,IAAIG,MAAM,OAAO,CAACD,QACd,OAAOA,KAAK,CAAC,EAAE,IAAI;QAGvB,OAAOA,SAAS;IACpB;IAEA,OAAO;AACX;AAUO,SAASE,yBAAyBN,OAAgB;IACrD,MAAMI,QAAQL,WAAWC,SAASF;IAClC,IAAI,CAACM,OACD,OAAO;IAGX,MAAMG,iBAAiBH,MAAM,OAAO,CAAC;IACrC,IAAIG,iBAAiB,GACjB,OAAO;IAGX,MAAMC,OAAOJ,MAAM,KAAK,CAAC,GAAGG,gBAAgB,IAAI;IAChD,MAAME,KAAKL,MAAM,KAAK,CAACG,iBAAiB,GAAG,IAAI;IAE/C,IAAIE,AAAO,OAAPA,IACA,OAAO;IAGX,IAAID,AAAS,WAATA,MACA,OAAO;QAAE,MAAM;QAAQC;IAAG;IAG9B,IAAID,AAAS,WAATA,MACA,OAAO;QAAE,MAAM;QAAQC;IAAG;IAG9B,OAAO;AACX"}
@@ -1,7 +1,8 @@
1
1
  import type { Container } from "@webiny/di";
2
2
  /**
3
3
  * Registers the request-context pieces:
4
- * - RawTenantId / RawAuthToken: per-request holders that the transport's EXTRACT step writes to.
4
+ * - RawTenantId / RawAuthToken / RawAssumePermissions: per-request holders that the transport's
5
+ * EXTRACT step writes to.
5
6
  * - RequestIdentityLoader / RequestTenantLoader: transport-agnostic LOAD steps that read
6
7
  * the holders and set IdentityContext / TenantContext.
7
8
  */
@@ -1,6 +1,7 @@
1
1
  import { createFeature } from "@webiny/feature/api";
2
2
  import { RawTenantId } from "./RawTenantId.js";
3
3
  import { RawAuthToken } from "./RawAuthToken.js";
4
+ import { RawAssumePermissions } from "./RawAssumePermissions.js";
4
5
  import { RequestIdentityLoader } from "./RequestIdentityLoader.js";
5
6
  import { RequestTenantLoader } from "./RequestTenantLoader.js";
6
7
  const RequestContextFeature = createFeature({
@@ -8,6 +9,7 @@ const RequestContextFeature = createFeature({
8
9
  register (container) {
9
10
  container.register(RawTenantId).inSingletonScope();
10
11
  container.register(RawAuthToken).inSingletonScope();
12
+ container.register(RawAssumePermissions).inSingletonScope();
11
13
  container.register(RequestIdentityLoader);
12
14
  container.register(RequestTenantLoader);
13
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"features/requestContext/feature.js","sources":["../../../src/features/requestContext/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport { RawTenantId } from \"./RawTenantId.js\";\nimport { RawAuthToken } from \"./RawAuthToken.js\";\nimport { RequestIdentityLoader } from \"./RequestIdentityLoader.js\";\nimport { RequestTenantLoader } from \"./RequestTenantLoader.js\";\n\n/**\n * Registers the request-context pieces:\n * - RawTenantId / RawAuthToken: per-request holders that the transport's EXTRACT step writes to.\n * - RequestIdentityLoader / RequestTenantLoader: transport-agnostic LOAD steps that read\n * the holders and set IdentityContext / TenantContext.\n */\nexport const RequestContextFeature = createFeature({\n name: \"RequestContext\",\n register(container: Container) {\n // Singleton so the value the transport's EXTRACT step sets is the same instance the LOAD\n // establisher reads. Registered per request (RequestContextFeature runs per-request), so it's\n // singleton *within the request container* — a fresh holder per request.\n container.register(RawTenantId).inSingletonScope();\n container.register(RawAuthToken).inSingletonScope();\n container.register(RequestIdentityLoader);\n container.register(RequestTenantLoader);\n }\n});\n"],"names":["RequestContextFeature","createFeature","container","RawTenantId","RawAuthToken","RequestIdentityLoader","RequestTenantLoader"],"mappings":";;;;;AAaO,MAAMA,wBAAwBC,cAAc;IAC/C,MAAM;IACN,UAASC,SAAoB;QAIzBA,UAAU,QAAQ,CAACC,aAAa,gBAAgB;QAChDD,UAAU,QAAQ,CAACE,cAAc,gBAAgB;QACjDF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;IACvB;AACJ"}
1
+ {"version":3,"file":"features/requestContext/feature.js","sources":["../../../src/features/requestContext/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport { RawTenantId } from \"./RawTenantId.js\";\nimport { RawAuthToken } from \"./RawAuthToken.js\";\nimport { RawAssumePermissions } from \"./RawAssumePermissions.js\";\nimport { RequestIdentityLoader } from \"./RequestIdentityLoader.js\";\nimport { RequestTenantLoader } from \"./RequestTenantLoader.js\";\n\n/**\n * Registers the request-context pieces:\n * - RawTenantId / RawAuthToken / RawAssumePermissions: per-request holders that the transport's\n * EXTRACT step writes to.\n * - RequestIdentityLoader / RequestTenantLoader: transport-agnostic LOAD steps that read\n * the holders and set IdentityContext / TenantContext.\n */\nexport const RequestContextFeature = createFeature({\n name: \"RequestContext\",\n register(container: Container) {\n // Singleton so the value the transport's EXTRACT step sets is the same instance the LOAD\n // establisher reads. Registered per request (RequestContextFeature runs per-request), so it's\n // singleton *within the request container* — a fresh holder per request.\n container.register(RawTenantId).inSingletonScope();\n container.register(RawAuthToken).inSingletonScope();\n container.register(RawAssumePermissions).inSingletonScope();\n container.register(RequestIdentityLoader);\n container.register(RequestTenantLoader);\n }\n});\n"],"names":["RequestContextFeature","createFeature","container","RawTenantId","RawAuthToken","RawAssumePermissions","RequestIdentityLoader","RequestTenantLoader"],"mappings":";;;;;;AAeO,MAAMA,wBAAwBC,cAAc;IAC/C,MAAM;IACN,UAASC,SAAoB;QAIzBA,UAAU,QAAQ,CAACC,aAAa,gBAAgB;QAChDD,UAAU,QAAQ,CAACE,cAAc,gBAAgB;QACjDF,UAAU,QAAQ,CAACG,sBAAsB,gBAAgB;QACzDH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;IACvB;AACJ"}
@@ -1,2 +1,4 @@
1
- export { RawTenantId, RawAuthToken, RequestIdentityLoader, RequestTenantLoader } from "./abstractions.js";
1
+ export { RawTenantId, RawAuthToken, RawAssumePermissions, RequestIdentityLoader, RequestTenantLoader } from "./abstractions.js";
2
2
  export { RequestContextFeature } from "./feature.js";
3
+ export { ASSUME_PERMISSIONS_HEADER } from "./extractAssumePermissions.js";
4
+ export { extractAssumePermissions } from "./extractAssumePermissions.js";
@@ -1,2 +1,3 @@
1
- export { RawAuthToken, RawTenantId, RequestIdentityLoader, RequestTenantLoader } from "./abstractions.js";
1
+ export { RawAssumePermissions, RawAuthToken, RawTenantId, RequestIdentityLoader, RequestTenantLoader } from "./abstractions.js";
2
2
  export { RequestContextFeature } from "./feature.js";
3
+ export { ASSUME_PERMISSIONS_HEADER, extractAssumePermissions } from "./extractAssumePermissions.js";
@@ -1,17 +1,21 @@
1
+ import { HandlerExecution } from "@webiny/event-handler-core";
1
2
  import { IdentityContext as Abstraction } from "./abstractions.js";
2
3
  import { Identity } from "./Identity.js";
3
4
  import { AuthorizationContext } from "../authorization/AuthorizationContext/index.js";
4
5
  import type { SecurityPermission } from "../../../types/security.js";
5
- import { WcpContext } from "../../wcp/WcpContext/index.js";
6
+ import { FeatureFlags } from "../../featureFlags/abstractions.js";
6
7
  declare class IdentityContextImpl implements Abstraction.Interface {
7
8
  private authorizationContext;
8
- private wcpContext;
9
+ private featureFlags;
10
+ private handlerExecution;
9
11
  private identity;
10
- constructor(authorizationContext: AuthorizationContext.Interface, wcpContext: WcpContext.Interface);
12
+ private readonly overrides;
13
+ constructor(authorizationContext: AuthorizationContext.Interface, featureFlags: FeatureFlags.Interface, handlerExecution: HandlerExecution.Interface | undefined);
11
14
  getIdentity(): Identity;
12
15
  setIdentity(identity: Identity | undefined): void;
13
- withIdentity<T>(identity: Identity | undefined, cb: () => Promise<T>): Promise<T>;
16
+ withIdentity<T>(identity: Identity, cb: () => Promise<T>): Promise<T>;
14
17
  withoutAuthorization<T>(cb: () => Promise<T>): Promise<T>;
18
+ withAuthorization<T>(cb: () => Promise<T>): Promise<T>;
15
19
  isAuthorizationEnabled(): boolean;
16
20
  getPermission<TPermission extends SecurityPermission = SecurityPermission>(name: string): Promise<TPermission | null>;
17
21
  getPermissions<TPermission extends SecurityPermission = SecurityPermission>(name: string): Promise<TPermission[]>;
@@ -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
- import { WcpContext } from "../../wcp/WcpContext/index.js";
9
- const identityStorage = new AsyncLocalStorage();
9
+ import { FeatureFlags } from "../../featureFlags/abstractions.js";
10
10
  class IdentityContextImpl {
11
- constructor(authorizationContext, wcpContext){
11
+ constructor(authorizationContext, featureFlags, handlerExecution){
12
12
  this.authorizationContext = authorizationContext;
13
- this.wcpContext = wcpContext;
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
  }
@@ -63,8 +74,8 @@ class IdentityContextImpl {
63
74
  return permissions.some((p)=>"*" === p.name);
64
75
  }
65
76
  applyAaclLogic(permissions) {
66
- const aaclEnabled = this.wcpContext.canUseAacl();
67
- const teamsEnabled = this.wcpContext.canUseTeams();
77
+ const aaclEnabled = this.featureFlags.get().isEnabled("advancedAccessControlLayer");
78
+ const teamsEnabled = this.featureFlags.get().isEnabled("advancedAccessControlLayer.teams");
68
79
  if (aaclEnabled) return [
69
80
  ...permissions,
70
81
  {
@@ -80,7 +91,13 @@ const IdentityContext_IdentityContext = createImplementation({
80
91
  implementation: IdentityContextImpl,
81
92
  dependencies: [
82
93
  AuthorizationContext,
83
- WcpContext
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 { WcpContext } from \"../../wcp/WcpContext/index.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 wcpContext: WcpContext.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.wcpContext.canUseAacl();\n const teamsEnabled = this.wcpContext.canUseTeams();\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, WcpContext]\n});\n"],"names":["identityStorage","AsyncLocalStorage","IdentityContextImpl","authorizationContext","wcpContext","AnonymousIdentity","override","undefined","identity","cb","name","permissions","exactMatch","p","patternMatch","minimatch","aaclEnabled","teamsEnabled","filterOutCustomWbyAppsPermissions","IdentityContext","createImplementation","Abstraction","AuthorizationContext","WcpContext"],"mappings":";;;;;;;;AAYA,MAAMA,kBAAkB,IAAIC;AAE5B,MAAMC;IAGF,YACYC,oBAAoD,EACpDC,UAAgC,CAC1C;aAFUD,oBAAoB,GAApBA;aACAC,UAAU,GAAVA;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,yBAAkC;QAC9B,OAAO,IAAI,CAAC,oBAAoB,CAAC,sBAAsB;IAC3D;IAMA,MAAM,cACFC,IAAY,EACe;QAC3B,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAC5B,OAAO;YAAE,MAAM;QAAI;QAGvB,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe;QAG9C,MAAMC,aAAaD,YAAY,IAAI,CAACE,CAAAA,IAAKA,EAAE,IAAI,KAAKH;QACpD,IAAIE,YACA,OAAOA;QAIX,MAAME,eAAeH,YAAY,IAAI,CAACE,CAAAA,IAAKE,UAAUL,MAAMG,EAAE,IAAI;QACjE,IAAIC,cACA,OAAOA;QAGX,OAAO;IACX;IAEA,MAAM,eACFJ,IAAY,EACU;QACtB,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAC5B,OAAO;YAAC;gBAAE,MAAM;YAAI;SAAE;QAG1B,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe;QAE9C,OAAOA,YAAY,MAAM,CAACE,CAAAA;YACtB,IAAIA,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,UAAU,CAAC,UAAU;QAC9C,MAAMC,eAAe,IAAI,CAAC,UAAU,CAAC,WAAW;QAEhD,IAAID,aAEA,OAAO;eACAL;YACH;gBACI,MAAM;gBACN,OAAOM;YACX;SACH;QAIL,OAAOC,kCAAkCP;IAC7C;AACJ;AAEO,MAAMQ,kCAAkBC,qBAAqB;IAChD,aAAaC;IACb,gBAAgBnB;IAChB,cAAc;QAACoB;QAAsBC;KAAW;AACpD"}
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,IAAI,CAAC,gBAAgB,EAAE,cAAc;QAErC,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,IACvB,MAAM,IAAIC,MACN;QAKR,IAAI,CAAC,QAAQ,GAAGD,YAAY,IAAIH;QAGhC,IAAI,CAAC,oBAAoB,CAAC,qBAAqB;IACnD;IAEA,aAAgBG,QAAkB,EAAEE,EAAoB,EAAc;QAClE,IAAI,CAAC,gBAAgB,EAAE,cAAc;QACrC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAACF,UAAUE;IACxC;IAMA,qBAAwBA,EAAoB,EAAc;QACtD,IAAI,CAAC,gBAAgB,EAAE,cAAc;QACrC,OAAO,IAAI,CAAC,oBAAoB,CAAC,oBAAoB,CAACA;IAC1D;IAEA,kBAAqBA,EAAoB,EAAc;QACnD,IAAI,CAAC,gBAAgB,EAAE,cAAc;QACrC,OAAO,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAACA;IACvD;IAEA,yBAAkC;QAC9B,OAAO,IAAI,CAAC,oBAAoB,CAAC,sBAAsB;IAC3D;IAMA,MAAM,cACFC,IAAY,EACe;QAC3B,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAC5B,OAAO;YAAE,MAAM;QAAI;QAGvB,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe;QAG9C,MAAMC,aAAaD,YAAY,IAAI,CAACE,CAAAA,IAAKA,EAAE,IAAI,KAAKH;QACpD,IAAIE,YACA,OAAOA;QAIX,MAAME,eAAeH,YAAY,IAAI,CAACE,CAAAA,IAAKE,UAAUL,MAAMG,EAAE,IAAI;QACjE,IAAIC,cACA,OAAOA;QAGX,OAAO;IACX;IAEA,MAAM,eACFJ,IAAY,EACU;QACtB,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAC5B,OAAO;YAAC;gBAAE,MAAM;YAAI;SAAE;QAG1B,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe;QAE9C,OAAOA,YAAY,MAAM,CAACE,CAAAA;YACtB,IAAIA,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"}
@@ -8,6 +8,7 @@ import { createApiKeyInputSchema } from "../shared/schemas.js";
8
8
  import { ApiKeyAfterCreateEvent, ApiKeyBeforeCreateEvent } from "./events.js";
9
9
  import { generateToken } from "../shared/generateToken.js";
10
10
  import { ApiKeyNotAuthorizedError, ApiKeyValidationError } from "../shared/errors.js";
11
+ import { descriptionOnCreate } from "../../shared/description.js";
11
12
  class CreateApiKeyUseCaseImpl {
12
13
  constructor(identityContext, eventPublisher, repository){
13
14
  this.identityContext = identityContext;
@@ -22,13 +23,17 @@ class CreateApiKeyUseCaseImpl {
22
23
  const token = generateToken();
23
24
  const identity = this.identityContext.getIdentity();
24
25
  const data = validation.data;
26
+ const createInput = {
27
+ ...data,
28
+ description: descriptionOnCreate(data.description)
29
+ };
25
30
  const apiKey = {
26
31
  id: mdbid(),
27
- name: data.name,
28
- slug: data.slug,
29
- description: data.description,
32
+ name: createInput.name,
33
+ slug: createInput.slug,
34
+ description: descriptionOnCreate(createInput.description),
30
35
  token,
31
- permissions: data.permissions,
36
+ permissions: createInput.permissions,
32
37
  createdOn: new Date().toISOString(),
33
38
  createdBy: {
34
39
  id: identity.id,
@@ -38,13 +43,13 @@ class CreateApiKeyUseCaseImpl {
38
43
  };
39
44
  await this.eventPublisher.publish(new ApiKeyBeforeCreateEvent({
40
45
  apiKey,
41
- input: validation.data
46
+ input: createInput
42
47
  }));
43
48
  const result = await this.repository.create(apiKey);
44
49
  if (result.isFail()) return Result.fail(result.error);
45
50
  await this.eventPublisher.publish(new ApiKeyAfterCreateEvent({
46
51
  apiKey,
47
- input: validation.data
52
+ input: createInput
48
53
  }));
49
54
  return Result.ok(apiKey);
50
55
  }
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js","sources":["../../../../../src/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { CreateApiKeyUseCase as CreateApiKeyUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { createApiKeyInputSchema } from \"../shared/schemas.js\";\nimport { ApiKeyBeforeCreateEvent, ApiKeyAfterCreateEvent } from \"./events.js\";\nimport type { ApiKey, CreateApiKeyInput } from \"../shared/types.js\";\nimport type { ApiKeyPermission } from \"~/types/security.js\";\nimport { generateToken } from \"../shared/generateToken.js\";\nimport { ApiKeyValidationError, ApiKeyNotAuthorizedError } from \"../shared/errors.js\";\n\nclass CreateApiKeyUseCaseImpl implements CreateApiKeyUseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: ApiKeysRepository.Interface\n ) {}\n\n async execute(\n input: CreateApiKeyInput\n ): Promise<Result<ApiKey, CreateApiKeyUseCaseAbstraction.Error>> {\n const hasPermission =\n await this.identityContext.getPermission<ApiKeyPermission>(\"security.apiKey\");\n\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n const validation = createApiKeyInputSchema.safeParse(input);\n if (!validation.success) {\n return Result.fail(new ApiKeyValidationError(validation.error.issues[0].message));\n }\n\n const token = generateToken();\n const identity = this.identityContext.getIdentity();\n const data = validation.data;\n\n const apiKey: ApiKey = {\n id: mdbid(),\n name: data.name,\n slug: data.slug,\n description: data.description,\n token,\n permissions: data.permissions,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n }\n };\n\n await this.eventPublisher.publish(\n new ApiKeyBeforeCreateEvent({ apiKey, input: validation.data })\n );\n\n const result = await this.repository.create(apiKey);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new ApiKeyAfterCreateEvent({ apiKey, input: validation.data })\n );\n\n return Result.ok(apiKey);\n }\n}\n\nexport const CreateApiKeyUseCase = CreateApiKeyUseCaseAbstraction.createImplementation({\n implementation: CreateApiKeyUseCaseImpl,\n dependencies: [IdentityContext, EventPublisher, ApiKeysRepository]\n});\n"],"names":["CreateApiKeyUseCaseImpl","identityContext","eventPublisher","repository","input","hasPermission","Result","ApiKeyNotAuthorizedError","validation","createApiKeyInputSchema","ApiKeyValidationError","token","generateToken","identity","data","apiKey","mdbid","Date","ApiKeyBeforeCreateEvent","result","ApiKeyAfterCreateEvent","CreateApiKeyUseCase","CreateApiKeyUseCaseAbstraction","IdentityContext","EventPublisher","ApiKeysRepository"],"mappings":";;;;;;;;;;AAaA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAAuC,CACjD;aAHUF,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QACFC,KAAwB,EACqC;QAC7D,MAAMC,gBACF,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAmB;QAE/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,aAAaC,wBAAwB,SAAS,CAACL;QACrD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,sBAAsBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGnF,MAAMG,QAAQC;QACd,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QACjD,MAAMC,OAAON,WAAW,IAAI;QAE5B,MAAMO,SAAiB;YACnB,IAAIC;YACJ,MAAMF,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,aAAaA,KAAK,WAAW;YAC7BH;YACA,aAAaG,KAAK,WAAW;YAC7B,WAAW,IAAIG,OAAO,WAAW;YACjC,WAAW;gBACP,IAAIJ,SAAS,EAAE;gBACf,aAAaA,SAAS,WAAW;gBACjC,MAAMA,SAAS,IAAI;YACvB;QACJ;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIK,wBAAwB;YAAEH;YAAQ,OAAOP,WAAW,IAAI;QAAC;QAGjE,MAAMW,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACJ;QAE5C,IAAII,OAAO,MAAM,IACb,OAAOb,OAAO,IAAI,CAACa,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,uBAAuB;YAAEL;YAAQ,OAAOP,WAAW,IAAI;QAAC;QAGhE,OAAOF,OAAO,EAAE,CAACS;IACrB;AACJ;AAEO,MAAMM,0CAAsBC,oBAAAA,oBAAmD,CAAC;IACnF,gBAAgBtB;IAChB,cAAc;QAACuB;QAAiBC;QAAgBC;KAAkB;AACtE"}
1
+ {"version":3,"file":"features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js","sources":["../../../../../src/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { CreateApiKeyUseCase as CreateApiKeyUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { createApiKeyInputSchema } from \"../shared/schemas.js\";\nimport { ApiKeyBeforeCreateEvent, ApiKeyAfterCreateEvent } from \"./events.js\";\nimport type { ApiKey, CreateApiKeyInput } from \"../shared/types.js\";\nimport type { ApiKeyPermission } from \"~/types/security.js\";\nimport { generateToken } from \"../shared/generateToken.js\";\nimport { ApiKeyValidationError, ApiKeyNotAuthorizedError } from \"../shared/errors.js\";\nimport { descriptionOnCreate } from \"../../shared/description.js\";\n\nclass CreateApiKeyUseCaseImpl implements CreateApiKeyUseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: ApiKeysRepository.Interface\n ) {}\n\n async execute(\n input: CreateApiKeyInput\n ): Promise<Result<ApiKey, CreateApiKeyUseCaseAbstraction.Error>> {\n const hasPermission =\n await this.identityContext.getPermission<ApiKeyPermission>(\"security.apiKey\");\n\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n const validation = createApiKeyInputSchema.safeParse(input);\n if (!validation.success) {\n return Result.fail(new ApiKeyValidationError(validation.error.issues[0].message));\n }\n\n const token = generateToken();\n const identity = this.identityContext.getIdentity();\n const data = validation.data;\n\n // Normalised up front so that null reaches neither the entity nor the published events.\n const createInput: CreateApiKeyInput = {\n ...data,\n description: descriptionOnCreate(data.description)\n };\n\n const apiKey: ApiKey = {\n id: mdbid(),\n name: createInput.name,\n slug: createInput.slug,\n description: descriptionOnCreate(createInput.description),\n token,\n permissions: createInput.permissions,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n }\n };\n\n await this.eventPublisher.publish(\n new ApiKeyBeforeCreateEvent({ apiKey, input: createInput })\n );\n\n const result = await this.repository.create(apiKey);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new ApiKeyAfterCreateEvent({ apiKey, input: createInput })\n );\n\n return Result.ok(apiKey);\n }\n}\n\nexport const CreateApiKeyUseCase = CreateApiKeyUseCaseAbstraction.createImplementation({\n implementation: CreateApiKeyUseCaseImpl,\n dependencies: [IdentityContext, EventPublisher, ApiKeysRepository]\n});\n"],"names":["CreateApiKeyUseCaseImpl","identityContext","eventPublisher","repository","input","hasPermission","Result","ApiKeyNotAuthorizedError","validation","createApiKeyInputSchema","ApiKeyValidationError","token","generateToken","identity","data","createInput","descriptionOnCreate","apiKey","mdbid","Date","ApiKeyBeforeCreateEvent","result","ApiKeyAfterCreateEvent","CreateApiKeyUseCase","CreateApiKeyUseCaseAbstraction","IdentityContext","EventPublisher","ApiKeysRepository"],"mappings":";;;;;;;;;;;AAcA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAAuC,CACjD;aAHUF,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QACFC,KAAwB,EACqC;QAC7D,MAAMC,gBACF,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAmB;QAE/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,aAAaC,wBAAwB,SAAS,CAACL;QACrD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,sBAAsBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGnF,MAAMG,QAAQC;QACd,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QACjD,MAAMC,OAAON,WAAW,IAAI;QAG5B,MAAMO,cAAiC;YACnC,GAAGD,IAAI;YACP,aAAaE,oBAAoBF,KAAK,WAAW;QACrD;QAEA,MAAMG,SAAiB;YACnB,IAAIC;YACJ,MAAMH,YAAY,IAAI;YACtB,MAAMA,YAAY,IAAI;YACtB,aAAaC,oBAAoBD,YAAY,WAAW;YACxDJ;YACA,aAAaI,YAAY,WAAW;YACpC,WAAW,IAAII,OAAO,WAAW;YACjC,WAAW;gBACP,IAAIN,SAAS,EAAE;gBACf,aAAaA,SAAS,WAAW;gBACjC,MAAMA,SAAS,IAAI;YACvB;QACJ;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIO,wBAAwB;YAAEH;YAAQ,OAAOF;QAAY;QAG7D,MAAMM,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACJ;QAE5C,IAAII,OAAO,MAAM,IACb,OAAOf,OAAO,IAAI,CAACe,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,uBAAuB;YAAEL;YAAQ,OAAOF;QAAY;QAG5D,OAAOT,OAAO,EAAE,CAACW;IACrB;AACJ;AAEO,MAAMM,0CAAsBC,oBAAAA,oBAAmD,CAAC;IACnF,gBAAgBxB;IAChB,cAAc;QAACyB;QAAiBC;QAAgBC;KAAkB;AACtE"}
@@ -7,7 +7,7 @@ declare class GetApiKeyUseCaseImpl implements GetApiKeyUseCaseAbstraction.Interf
7
7
  private repository;
8
8
  private identityContext;
9
9
  constructor(repository: ApiKeysRepository.Interface, identityContext: IdentityContext.Interface);
10
- execute(id: string): Promise<Result<ApiKey | null, GetApiKeyUseCaseAbstraction.Error>>;
10
+ execute(id: string): Promise<Result<ApiKey, GetApiKeyUseCaseAbstraction.Error>>;
11
11
  }
12
12
  export declare const GetApiKeyUseCase: typeof GetApiKeyUseCaseImpl & {
13
13
  __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetApiKey>;
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetApiKeyUseCase as GetApiKeyUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport type { ApiKey } from \"../shared/types.js\";\nimport { ApiKeyNotAuthorizedError } from \"~/features/security/apiKeys/shared/errors.js\";\n\nclass GetApiKeyUseCaseImpl implements GetApiKeyUseCaseAbstraction.Interface {\n private repository: ApiKeysRepository.Interface;\n private identityContext: IdentityContext.Interface;\n\n constructor(\n repository: ApiKeysRepository.Interface,\n identityContext: IdentityContext.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n }\n\n async execute(id: string): Promise<Result<ApiKey | null, GetApiKeyUseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.apiKey\");\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n return this.repository.get(id);\n }\n}\n\nexport const GetApiKeyUseCase = GetApiKeyUseCaseAbstraction.createImplementation({\n implementation: GetApiKeyUseCaseImpl,\n dependencies: [ApiKeysRepository, IdentityContext]\n});\n"],"names":["GetApiKeyUseCaseImpl","repository","identityContext","id","hasPermission","Result","ApiKeyNotAuthorizedError","GetApiKeyUseCase","GetApiKeyUseCaseAbstraction","ApiKeysRepository","IdentityContext"],"mappings":";;;;;AAOA,MAAMA;IAIF,YACIC,UAAuC,EACvCC,eAA0C,CAC5C;QACE,IAAI,CAAC,UAAU,GAAGD;QAClB,IAAI,CAAC,eAAe,GAAGC;IAC3B;IAEA,MAAM,QAAQC,EAAU,EAAqE;QACzF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAACH;IAC/B;AACJ;AAEO,MAAMI,oCAAmBC,iBAAAA,oBAAgD,CAAC;IAC7E,gBAAgBR;IAChB,cAAc;QAACS;QAAmBC;KAAgB;AACtD"}
1
+ {"version":3,"file":"features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetApiKeyUseCase as GetApiKeyUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport type { ApiKey } from \"../shared/types.js\";\nimport { ApiKeyNotAuthorizedError } from \"~/features/security/apiKeys/shared/errors.js\";\n\nclass GetApiKeyUseCaseImpl implements GetApiKeyUseCaseAbstraction.Interface {\n private repository: ApiKeysRepository.Interface;\n private identityContext: IdentityContext.Interface;\n\n constructor(\n repository: ApiKeysRepository.Interface,\n identityContext: IdentityContext.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n }\n\n async execute(id: string): Promise<Result<ApiKey, GetApiKeyUseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.apiKey\");\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n return this.repository.get(id);\n }\n}\n\nexport const GetApiKeyUseCase = GetApiKeyUseCaseAbstraction.createImplementation({\n implementation: GetApiKeyUseCaseImpl,\n dependencies: [ApiKeysRepository, IdentityContext]\n});\n"],"names":["GetApiKeyUseCaseImpl","repository","identityContext","id","hasPermission","Result","ApiKeyNotAuthorizedError","GetApiKeyUseCase","GetApiKeyUseCaseAbstraction","ApiKeysRepository","IdentityContext"],"mappings":";;;;;AAOA,MAAMA;IAIF,YACIC,UAAuC,EACvCC,eAA0C,CAC5C;QACE,IAAI,CAAC,UAAU,GAAGD;QAClB,IAAI,CAAC,eAAe,GAAGC;IAC3B;IAEA,MAAM,QAAQC,EAAU,EAA8D;QAClF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAACH;IAC/B;AACJ;AAEO,MAAMI,oCAAmBC,iBAAAA,oBAAgD,CAAC;IAC7E,gBAAgBR;IAChB,cAAc;QAACS;QAAmBC;KAAgB;AACtD"}
@@ -1,11 +1,9 @@
1
- import { Result } from "@webiny/feature/api";
2
1
  import { GetApiKeyBySlugUseCase as GetApiKeyBySlugUseCaseAbstraction } from "./abstractions.js";
3
2
  import { ApiKeysRepository } from "../shared/abstractions.js";
4
- import type { ApiKey } from "../shared/types.js";
5
3
  declare class GetApiKeyBySlugUseCaseImpl implements GetApiKeyBySlugUseCaseAbstraction.Interface {
6
4
  private repository;
7
5
  constructor(repository: ApiKeysRepository.Interface);
8
- execute(slug: string): Promise<Result<ApiKey | null, GetApiKeyBySlugUseCaseAbstraction.Error>>;
6
+ execute(slug: string): Promise<import("@webiny/feature/api/Result.js").Result<import("../shared/types.js").ApiKey, import("../shared/errors.js").ApiKeyNotFoundError | import("../shared/errors.js").ApiKeyPersistenceError | import("../shared/errors.js").ApiKeyValidationError>>;
9
7
  }
10
8
  export declare const GetApiKeyBySlugUseCase: typeof GetApiKeyBySlugUseCaseImpl & {
11
9
  __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetApiKeyBySlug>;