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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/ApiCoreFeature.d.ts +2 -2
  2. package/ApiCoreFeature.js +29 -5
  3. package/ApiCoreFeature.js.map +1 -1
  4. package/exports/api/security/api-key.d.ts +1 -0
  5. package/exports/api/security/api-key.js +1 -0
  6. package/exports/api.d.ts +3 -1
  7. package/exports/api.js +2 -1
  8. package/features/ai/Ai.d.ts +3 -3
  9. package/features/ai/Ai.js +60 -23
  10. package/features/ai/Ai.js.map +1 -1
  11. package/features/ai/AnthropicSdkFactory.js +12 -0
  12. package/features/ai/AnthropicSdkFactory.js.map +1 -1
  13. package/features/ai/OpenAiSdkFactory.js +16 -0
  14. package/features/ai/OpenAiSdkFactory.js.map +1 -1
  15. package/features/ai/TextExtractor/DefaultTextExtractor.d.ts +9 -0
  16. package/features/ai/TextExtractor/DefaultTextExtractor.js +28 -0
  17. package/features/ai/TextExtractor/DefaultTextExtractor.js.map +1 -0
  18. package/features/ai/TextExtractor/abstractions.d.ts +12 -0
  19. package/features/ai/TextExtractor/abstractions.js +5 -0
  20. package/features/ai/TextExtractor/abstractions.js.map +1 -0
  21. package/features/ai/TextExtractor/index.d.ts +3 -0
  22. package/features/ai/TextExtractor/index.js +2 -0
  23. package/features/ai/TextExtractor/parsers/docxParser.d.ts +1 -0
  24. package/features/ai/TextExtractor/parsers/docxParser.js +111 -0
  25. package/features/ai/TextExtractor/parsers/docxParser.js.map +1 -0
  26. package/features/ai/abstractions.d.ts +18 -7
  27. package/features/ai/abstractions.js +1 -2
  28. package/features/ai/abstractions.js.map +1 -1
  29. package/features/ai/events.d.ts +59 -0
  30. package/features/ai/events.js +41 -0
  31. package/features/ai/events.js.map +1 -0
  32. package/features/ai/feature.js +6 -2
  33. package/features/ai/feature.js.map +1 -1
  34. package/features/ai/index.d.ts +8 -2
  35. package/features/ai/index.js +4 -1
  36. package/features/ai/toolPipeline/AiOutputToolRegistry.d.ts +11 -0
  37. package/features/ai/toolPipeline/AiOutputToolRegistry.js +31 -0
  38. package/features/ai/toolPipeline/AiOutputToolRegistry.js.map +1 -0
  39. package/features/ai/toolPipeline/AiToolPipelineRunner.d.ts +10 -0
  40. package/features/ai/toolPipeline/AiToolPipelineRunner.js +36 -0
  41. package/features/ai/toolPipeline/AiToolPipelineRunner.js.map +1 -0
  42. package/features/ai/toolPipeline/abstractions.d.ts +23 -0
  43. package/features/ai/toolPipeline/abstractions.js +7 -0
  44. package/features/ai/toolPipeline/abstractions.js.map +1 -0
  45. package/features/ai/toolPipeline/index.d.ts +2 -0
  46. package/features/ai/toolPipeline/index.js +1 -0
  47. package/features/dateFormatter/DefaultDateFormatter.d.ts +15 -0
  48. package/features/dateFormatter/DefaultDateFormatter.js +20 -0
  49. package/features/dateFormatter/DefaultDateFormatter.js.map +1 -0
  50. package/features/dateFormatter/abstractions.d.ts +13 -0
  51. package/features/dateFormatter/abstractions.js +5 -0
  52. package/features/dateFormatter/abstractions.js.map +1 -0
  53. package/features/dateFormatter/feature.d.ts +4 -0
  54. package/features/dateFormatter/feature.js +11 -0
  55. package/features/dateFormatter/feature.js.map +1 -0
  56. package/features/dateFormatter/index.d.ts +3 -0
  57. package/features/dateFormatter/index.js +2 -0
  58. package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.d.ts +13 -0
  59. package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js +49 -0
  60. package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js.map +1 -0
  61. package/features/hashing/ScryptHasher.d.ts +11 -0
  62. package/features/hashing/ScryptHasher.js +74 -0
  63. package/features/hashing/ScryptHasher.js.map +1 -0
  64. package/features/hashing/abstractions.d.ts +18 -0
  65. package/features/hashing/abstractions.js +5 -0
  66. package/features/hashing/abstractions.js.map +1 -0
  67. package/features/hashing/feature.d.ts +4 -0
  68. package/features/hashing/feature.js +11 -0
  69. package/features/hashing/feature.js.map +1 -0
  70. package/features/hashing/index.d.ts +2 -0
  71. package/features/hashing/index.js +1 -0
  72. package/features/requestContext/RawAuthToken.d.ts +14 -0
  73. package/features/requestContext/RawAuthToken.js +19 -0
  74. package/features/requestContext/RawAuthToken.js.map +1 -0
  75. package/features/requestContext/RawTenantId.d.ts +14 -0
  76. package/features/requestContext/RawTenantId.js +19 -0
  77. package/features/requestContext/RawTenantId.js.map +1 -0
  78. package/features/requestContext/RequestIdentityLoader.d.ts +19 -0
  79. package/features/requestContext/RequestIdentityLoader.js +26 -0
  80. package/features/requestContext/RequestIdentityLoader.js.map +1 -0
  81. package/features/requestContext/RequestTenantLoader.d.ts +18 -0
  82. package/features/requestContext/RequestTenantLoader.js +52 -0
  83. package/features/requestContext/RequestTenantLoader.js.map +1 -0
  84. package/features/requestContext/abstractions.d.ts +53 -0
  85. package/features/requestContext/abstractions.js +8 -0
  86. package/features/requestContext/abstractions.js.map +1 -0
  87. package/features/requestContext/feature.d.ts +11 -0
  88. package/features/requestContext/feature.js +17 -0
  89. package/features/requestContext/feature.js.map +1 -0
  90. package/features/requestContext/index.d.ts +2 -0
  91. package/features/requestContext/index.js +2 -0
  92. package/features/security/IdentityContext/IdentityContext.d.ts +3 -3
  93. package/features/security/IdentityContext/IdentityContext.js +6 -6
  94. package/features/security/IdentityContext/IdentityContext.js.map +1 -1
  95. package/features/security/apiKeys/ApiKeyAuthenticator.d.ts +14 -0
  96. package/features/security/apiKeys/ApiKeyAuthenticator.js +36 -0
  97. package/features/security/apiKeys/ApiKeyAuthenticator.js.map +1 -0
  98. package/features/security/apiKeys/ApiKeyAuthorizer.d.ts +10 -0
  99. package/features/security/apiKeys/ApiKeyAuthorizer.js +15 -0
  100. package/features/security/apiKeys/ApiKeyAuthorizer.js.map +1 -0
  101. package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js +11 -6
  102. package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js.map +1 -1
  103. package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.d.ts +1 -1
  104. package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js.map +1 -1
  105. package/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.d.ts +1 -3
  106. package/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.js.map +1 -1
  107. package/features/security/apiKeys/GetApiKeyBySlug/abstractions.d.ts +1 -1
  108. package/features/security/apiKeys/GetApiKeyBySlug/abstractions.js.map +1 -1
  109. package/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.d.ts +1 -3
  110. package/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.js.map +1 -1
  111. package/features/security/apiKeys/GetApiKeyByToken/abstractions.d.ts +1 -1
  112. package/features/security/apiKeys/GetApiKeyByToken/abstractions.js.map +1 -1
  113. package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js +9 -3
  114. package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js.map +1 -1
  115. package/features/security/apiKeys/feature.js +11 -2
  116. package/features/security/apiKeys/feature.js.map +1 -1
  117. package/features/security/apiKeys/shared/ApiKeyProvider.d.ts +3 -5
  118. package/features/security/apiKeys/shared/ApiKeyProvider.js +6 -21
  119. package/features/security/apiKeys/shared/ApiKeyProvider.js.map +1 -1
  120. package/features/security/apiKeys/shared/ApiKeysRepository.d.ts +1 -0
  121. package/features/security/apiKeys/shared/ApiKeysRepository.js +19 -4
  122. package/features/security/apiKeys/shared/ApiKeysRepository.js.map +1 -1
  123. package/features/security/apiKeys/shared/generateToken.d.ts +1 -1
  124. package/features/security/apiKeys/shared/generateToken.js.map +1 -1
  125. package/features/security/apiKeys/shared/schemas.d.ts +2 -2
  126. package/features/security/apiKeys/shared/schemas.js +2 -2
  127. package/features/security/apiKeys/shared/schemas.js.map +1 -1
  128. package/features/security/apiKeys/shared/types.d.ts +1 -1
  129. package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.d.ts +4 -4
  130. package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js +5 -5
  131. package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js.map +1 -1
  132. package/features/security/roles/CreateRole/CreateRoleUseCase.js +11 -6
  133. package/features/security/roles/CreateRole/CreateRoleUseCase.js.map +1 -1
  134. package/features/security/roles/CreateRole/schema.d.ts +1 -1
  135. package/features/security/roles/CreateRole/schema.js +1 -1
  136. package/features/security/roles/CreateRole/schema.js.map +1 -1
  137. package/features/security/roles/Installer/RolesInstaller.js +0 -1
  138. package/features/security/roles/Installer/RolesInstaller.js.map +1 -1
  139. package/features/security/roles/UpdateRole/UpdateRoleUseCase.js +9 -3
  140. package/features/security/roles/UpdateRole/UpdateRoleUseCase.js.map +1 -1
  141. package/features/security/roles/UpdateRole/schema.d.ts +1 -1
  142. package/features/security/roles/UpdateRole/schema.js +1 -1
  143. package/features/security/roles/UpdateRole/schema.js.map +1 -1
  144. package/features/security/shared/description.d.ts +4 -0
  145. package/features/security/shared/description.js +7 -0
  146. package/features/security/shared/description.js.map +1 -0
  147. package/features/security/shared/index.d.ts +1 -0
  148. package/features/security/shared/index.js +1 -0
  149. package/features/security/teams/CreateTeam/CreateTeamUseCase.d.ts +3 -1
  150. package/features/security/teams/CreateTeam/CreateTeamUseCase.js +20 -8
  151. package/features/security/teams/CreateTeam/CreateTeamUseCase.js.map +1 -1
  152. package/features/security/teams/CreateTeam/schema.d.ts +1 -1
  153. package/features/security/teams/CreateTeam/schema.js +1 -1
  154. package/features/security/teams/CreateTeam/schema.js.map +1 -1
  155. package/features/security/teams/UpdateTeam/UpdateTeamUseCase.d.ts +3 -1
  156. package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js +20 -5
  157. package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js.map +1 -1
  158. package/features/security/teams/UpdateTeam/schema.d.ts +1 -1
  159. package/features/security/teams/UpdateTeam/schema.js +1 -1
  160. package/features/security/teams/UpdateTeam/schema.js.map +1 -1
  161. package/features/security/teams/shared/resolveRoleIdentifiers.d.ts +17 -0
  162. package/features/security/teams/shared/resolveRoleIdentifiers.js +32 -0
  163. package/features/security/teams/shared/resolveRoleIdentifiers.js.map +1 -0
  164. package/features/security/utils/getPermissionsFromRoles.d.ts +1 -1
  165. package/features/serviceDiscovery/ServiceDiscovery.d.ts +17 -0
  166. package/features/serviceDiscovery/ServiceDiscovery.js +22 -0
  167. package/features/serviceDiscovery/ServiceDiscovery.js.map +1 -0
  168. package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.d.ts +1 -0
  169. package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.js +111 -0
  170. package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.js.map +1 -0
  171. package/features/serviceDiscovery/index.d.ts +3 -0
  172. package/features/serviceDiscovery/index.js +1 -0
  173. package/features/slugify/DefaultSlugify.d.ts +8 -0
  174. package/features/slugify/DefaultSlugify.js +20 -0
  175. package/features/slugify/DefaultSlugify.js.map +1 -0
  176. package/features/slugify/abstractions.d.ts +12 -0
  177. package/features/slugify/abstractions.js +5 -0
  178. package/features/slugify/abstractions.js.map +1 -0
  179. package/features/slugify/feature.d.ts +4 -0
  180. package/features/slugify/feature.js +11 -0
  181. package/features/slugify/feature.js.map +1 -0
  182. package/features/slugify/index.d.ts +3 -0
  183. package/features/slugify/index.js +2 -0
  184. package/features/storageOperations/abstractions.d.ts +21 -0
  185. package/features/storageOperations/abstractions.js +10 -0
  186. package/features/storageOperations/abstractions.js.map +1 -0
  187. package/features/stringFormatter/DefaultStringFormatter.d.ts +17 -0
  188. package/features/stringFormatter/DefaultStringFormatter.js +19 -0
  189. package/features/stringFormatter/DefaultStringFormatter.js.map +1 -0
  190. package/features/stringFormatter/abstractions.d.ts +11 -0
  191. package/features/stringFormatter/abstractions.js +5 -0
  192. package/features/stringFormatter/abstractions.js.map +1 -0
  193. package/features/stringFormatter/feature.d.ts +4 -0
  194. package/features/stringFormatter/feature.js +13 -0
  195. package/features/stringFormatter/feature.js.map +1 -0
  196. package/features/stringFormatter/index.d.ts +3 -0
  197. package/features/stringFormatter/index.js +2 -0
  198. package/features/task/TaskDefinition/abstractions.d.ts +76 -4
  199. package/features/task/TaskDefinition/abstractions.js +2 -1
  200. package/features/task/TaskDefinition/abstractions.js.map +1 -1
  201. package/features/tenancy/CreateTenant/CreateTenantUseCase.d.ts +1 -1
  202. package/features/tenancy/InstallTenant/InstallTenantUseCase.d.ts +1 -1
  203. package/features/tenancy/UpdateTenant/UpdateTenantUseCase.d.ts +2 -2
  204. package/features/users/CreateUser/decorators/CreateUserWithWcpIncrement.d.ts +1 -1
  205. package/features/wcp/WcpContext/WcpContext.d.ts +10 -5
  206. package/features/wcp/WcpContext/WcpContext.js +23 -2
  207. package/features/wcp/WcpContext/WcpContext.js.map +1 -1
  208. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +25 -7
  209. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +57 -25
  210. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
  211. package/features/wcp/WcpContext/feature.d.ts +1 -2
  212. package/features/wcp/WcpContext/feature.js +2 -2
  213. package/features/wcp/WcpContext/feature.js.map +1 -1
  214. package/features/wcp/WcpContext/index.d.ts +0 -1
  215. package/features/wcp/WcpContext/types.d.ts +0 -4
  216. package/features/wcp/WcpFeature.d.ts +1 -1
  217. package/features/wcp/WcpFeature.js +7 -2
  218. package/features/wcp/WcpFeature.js.map +1 -1
  219. package/features/wcp/WcpLicenseLoader.d.ts +25 -0
  220. package/features/wcp/WcpLicenseLoader.js +58 -0
  221. package/features/wcp/WcpLicenseLoader.js.map +1 -0
  222. package/features/wcp/WcpLicenseProvider.d.ts +21 -0
  223. package/features/wcp/WcpLicenseProvider.js +14 -0
  224. package/features/wcp/WcpLicenseProvider.js.map +1 -0
  225. package/features/wcp/resolveWcpProjectEnvironment.d.ts +9 -0
  226. package/features/wcp/resolveWcpProjectEnvironment.js +23 -0
  227. package/features/wcp/resolveWcpProjectEnvironment.js.map +1 -0
  228. package/graphql/ApiCoreSchemaFactory.d.ts +15 -0
  229. package/graphql/ApiCoreSchemaFactory.js +52 -0
  230. package/graphql/ApiCoreSchemaFactory.js.map +1 -0
  231. package/graphql/featureFlags/FeatureFlagsSchemaFactory.d.ts +9 -0
  232. package/graphql/featureFlags/FeatureFlagsSchemaFactory.js +49 -0
  233. package/graphql/featureFlags/FeatureFlagsSchemaFactory.js.map +1 -0
  234. package/graphql/security/NotAuthorizedResponse.d.ts +1 -1
  235. package/graphql/security/NotAuthorizedResponse.js +1 -1
  236. package/graphql/security/NotAuthorizedResponse.js.map +1 -1
  237. package/graphql/security/SecuritySchemaFactory.d.ts +14 -0
  238. package/graphql/security/SecuritySchemaFactory.js +23 -0
  239. package/graphql/security/SecuritySchemaFactory.js.map +1 -0
  240. package/graphql/security/addApiKeySchema.d.ts +2 -0
  241. package/graphql/security/{apiKey.gql.js → addApiKeySchema.js} +45 -27
  242. package/graphql/security/addApiKeySchema.js.map +1 -0
  243. package/graphql/security/addIdentitySchema.d.ts +2 -0
  244. package/graphql/security/{identity.gql.js → addIdentitySchema.js} +52 -35
  245. package/graphql/security/addIdentitySchema.js.map +1 -0
  246. package/graphql/security/addRoleSchema.d.ts +2 -0
  247. package/graphql/security/addRoleSchema.js +137 -0
  248. package/graphql/security/addRoleSchema.js.map +1 -0
  249. package/graphql/security/addSecurityBaseSchema.d.ts +2 -0
  250. package/graphql/security/{base.gql.js → addSecurityBaseSchema.js} +14 -16
  251. package/graphql/security/addSecurityBaseSchema.js.map +1 -0
  252. package/graphql/security/addTeamSchema.d.ts +2 -0
  253. package/graphql/security/addTeamSchema.js +157 -0
  254. package/graphql/security/addTeamSchema.js.map +1 -0
  255. package/graphql/system/SystemSchemaFactory.d.ts +9 -0
  256. package/graphql/system/SystemSchemaFactory.js +66 -0
  257. package/graphql/system/SystemSchemaFactory.js.map +1 -0
  258. package/graphql/users/UsersSchemaFactory.d.ts +9 -0
  259. package/graphql/users/UsersSchemaFactory.js +191 -0
  260. package/graphql/users/UsersSchemaFactory.js.map +1 -0
  261. package/graphql/wcp/WcpSchemaFactory.d.ts +9 -0
  262. package/graphql/wcp/{graphql.js → WcpSchemaFactory.js} +28 -18
  263. package/graphql/wcp/WcpSchemaFactory.js.map +1 -0
  264. package/index.d.ts +3 -1
  265. package/index.js +3 -1
  266. package/package.json +21 -24
  267. package/testing/environment.d.ts +14 -0
  268. package/testing/environment.js +18 -0
  269. package/testing/environment.js.map +1 -0
  270. package/types/core.d.ts +17 -5
  271. package/types/security.d.ts +1 -7
  272. package/types/tenancy.d.ts +0 -17
  273. package/types/users.d.ts +0 -13
  274. package/createApiCore.d.ts +0 -7
  275. package/createApiCore.js +0 -22
  276. package/createApiCore.js.map +0 -1
  277. package/features/ai/AiModelRegistry.d.ts +0 -12
  278. package/features/ai/AiModelRegistry.js +0 -28
  279. package/features/ai/AiModelRegistry.js.map +0 -1
  280. package/graphql/security/apiKey.gql.d.ts +0 -4
  281. package/graphql/security/apiKey.gql.js.map +0 -1
  282. package/graphql/security/base.gql.d.ts +0 -4
  283. package/graphql/security/base.gql.js.map +0 -1
  284. package/graphql/security/identity.gql.d.ts +0 -4
  285. package/graphql/security/identity.gql.js.map +0 -1
  286. package/graphql/security/index.d.ts +0 -1
  287. package/graphql/security/index.js +0 -15
  288. package/graphql/security/index.js.map +0 -1
  289. package/graphql/security/role.gql.d.ts +0 -4
  290. package/graphql/security/role.gql.js +0 -106
  291. package/graphql/security/role.gql.js.map +0 -1
  292. package/graphql/security/team.gql.d.ts +0 -4
  293. package/graphql/security/team.gql.js +0 -119
  294. package/graphql/security/team.gql.js.map +0 -1
  295. package/graphql/system/createSystemGraphQL.d.ts +0 -2
  296. package/graphql/system/createSystemGraphQL.js +0 -54
  297. package/graphql/system/createSystemGraphQL.js.map +0 -1
  298. package/graphql/users/user.gql.d.ts +0 -3
  299. package/graphql/users/user.gql.js +0 -167
  300. package/graphql/users/user.gql.js.map +0 -1
  301. package/graphql/wcp/graphql.d.ts +0 -2
  302. package/graphql/wcp/graphql.js.map +0 -1
  303. package/legacy/security/LegacyContext.d.ts +0 -36
  304. package/legacy/security/LegacyContext.js +0 -152
  305. package/legacy/security/LegacyContext.js.map +0 -1
  306. package/legacy/security/createSecurityContext.d.ts +0 -3
  307. package/legacy/security/createSecurityContext.js +0 -10
  308. package/legacy/security/createSecurityContext.js.map +0 -1
  309. package/legacy/security/plugins/apiKeyAuthentication.d.ts +0 -7
  310. package/legacy/security/plugins/apiKeyAuthentication.js +0 -20
  311. package/legacy/security/plugins/apiKeyAuthentication.js.map +0 -1
  312. package/legacy/security/plugins/apiKeyAuthorization.d.ts +0 -6
  313. package/legacy/security/plugins/apiKeyAuthorization.js +0 -13
  314. package/legacy/security/plugins/apiKeyAuthorization.js.map +0 -1
  315. package/legacy/security/plugins/authenticateUsingCookie.d.ts +0 -5
  316. package/legacy/security/plugins/authenticateUsingCookie.js +0 -23
  317. package/legacy/security/plugins/authenticateUsingCookie.js.map +0 -1
  318. package/legacy/security/plugins/authenticateUsingHttpHeader.d.ts +0 -5
  319. package/legacy/security/plugins/authenticateUsingHttpHeader.js +0 -20
  320. package/legacy/security/plugins/authenticateUsingHttpHeader.js.map +0 -1
  321. package/legacy/security/plugins/secureHeaders.d.ts +0 -1
  322. package/legacy/security/plugins/secureHeaders.js +0 -30
  323. package/legacy/security/plugins/secureHeaders.js.map +0 -1
  324. package/legacy/tenancy/LegacyContext.d.ts +0 -15
  325. package/legacy/tenancy/LegacyContext.js +0 -57
  326. package/legacy/tenancy/LegacyContext.js.map +0 -1
  327. package/legacy/tenancy/createTenancyContext.d.ts +0 -3
  328. package/legacy/tenancy/createTenancyContext.js +0 -31
  329. package/legacy/tenancy/createTenancyContext.js.map +0 -1
  330. package/legacy/users/LegacyContext.d.ts +0 -13
  331. package/legacy/users/LegacyContext.js +0 -55
  332. package/legacy/users/LegacyContext.js.map +0 -1
  333. package/legacy/users/createAdminUsersContext.d.ts +0 -3
  334. package/legacy/users/createAdminUsersContext.js +0 -12
  335. package/legacy/users/createAdminUsersContext.js.map +0 -1
  336. package/legacy/wcp/LegacyWcpContext.d.ts +0 -33
  337. package/legacy/wcp/LegacyWcpContext.js +0 -84
  338. package/legacy/wcp/LegacyWcpContext.js.map +0 -1
  339. package/legacy/wcp/context.d.ts +0 -5
  340. package/legacy/wcp/context.js +0 -46
  341. package/legacy/wcp/context.js.map +0 -1
@@ -8,6 +8,7 @@ class ApiKeysRepositoryImpl {
8
8
  this.tenantContext = tenantContext;
9
9
  this.storageOperations = storageOperations;
10
10
  this.apiKeyProvider = apiKeyProvider;
11
+ this.resolving = false;
11
12
  }
12
13
  async get(id) {
13
14
  try {
@@ -30,8 +31,15 @@ class ApiKeysRepositoryImpl {
30
31
  tenant: tenant.id
31
32
  });
32
33
  if (apiKey) return Result.ok(apiKey);
33
- const factoryApiKey = await this.apiKeyProvider.getByToken(token);
34
- if (factoryApiKey) return Result.ok(factoryApiKey);
34
+ if (!this.resolving) {
35
+ this.resolving = true;
36
+ try {
37
+ const factoryApiKey = await this.apiKeyProvider.getByToken(token);
38
+ if (factoryApiKey) return Result.ok(factoryApiKey);
39
+ } finally{
40
+ this.resolving = false;
41
+ }
42
+ }
35
43
  return Result.fail(new ApiKeyNotFoundError());
36
44
  } catch (error) {
37
45
  return Result.fail(new ApiKeyPersistenceError(error));
@@ -45,8 +53,15 @@ class ApiKeysRepositoryImpl {
45
53
  tenant: tenant.id
46
54
  });
47
55
  if (apiKey) return Result.ok(apiKey);
48
- const factoryApiKey = await this.apiKeyProvider.getBySlug(slug);
49
- if (factoryApiKey) return Result.ok(factoryApiKey);
56
+ if (!this.resolving) {
57
+ this.resolving = true;
58
+ try {
59
+ const factoryApiKey = await this.apiKeyProvider.getBySlug(slug);
60
+ if (factoryApiKey) return Result.ok(factoryApiKey);
61
+ } finally{
62
+ this.resolving = false;
63
+ }
64
+ }
50
65
  return Result.fail(new ApiKeyNotFoundError());
51
66
  } catch (error) {
52
67
  return Result.fail(new ApiKeyPersistenceError(error));
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/shared/ApiKeysRepository.js","sources":["../../../../../src/features/security/apiKeys/shared/ApiKeysRepository.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { ApiKeysRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { ApiKeyProvider } from \"./abstractions.js\";\nimport type { ApiKey, ListApiKeysInput } from \"./types.js\";\nimport { SecurityStorageOperations } from \"~/features/security/shared/abstractions.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { ApiKeyNotFoundError, ApiKeyPersistenceError, ApiKeyValidationError } from \"./errors.js\";\n\n// TODO: create an ApiKeyMapper\n\nclass ApiKeysRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private storageOperations: SecurityStorageOperations.Interface,\n private apiKeyProvider: ApiKeyProvider.Interface\n ) {}\n\n async get(id: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n const apiKey = await this.storageOperations.getApiKey({ id, tenant: tenant.id });\n if (apiKey) {\n return Result.ok(apiKey);\n }\n\n return Result.fail(new ApiKeyNotFoundError());\n } catch (error) {\n return Result.fail(error);\n }\n }\n\n async getByToken(token: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>> {\n try {\n // First, check the database (database keys have priority over factory keys)\n const tenant = this.tenantContext.getTenant();\n const apiKey = await this.storageOperations.getApiKeyByToken({\n token,\n tenant: tenant.id\n });\n\n if (apiKey) {\n return Result.ok(apiKey);\n }\n\n // If not found in database, check if the API key is provided by a factory\n const factoryApiKey = await this.apiKeyProvider.getByToken(token);\n if (factoryApiKey) {\n return Result.ok(factoryApiKey);\n }\n\n return Result.fail(new ApiKeyNotFoundError());\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async getBySlug(slug: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>> {\n try {\n // First, check the database (database keys have priority over factory keys)\n const tenant = this.tenantContext.getTenant();\n const apiKey = await this.storageOperations.getApiKeyBySlug({\n slug,\n tenant: tenant.id\n });\n\n if (apiKey) {\n return Result.ok(apiKey);\n }\n\n // If not found in database, check if the API key is provided by a factory\n const factoryApiKey = await this.apiKeyProvider.getBySlug(slug);\n if (factoryApiKey) {\n return Result.ok(factoryApiKey);\n }\n\n return Result.fail(new ApiKeyNotFoundError());\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async list(params: ListApiKeysInput): Promise<Result<ApiKey[], RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n const result = await this.storageOperations.listApiKeys({\n where: { tenant: tenant.id },\n ...params\n });\n return Result.ok(result);\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async create(apiKey: ApiKey): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n // Check if an API key with the same slug already exists\n const existingKeyResult = await this.getBySlug(apiKey.slug);\n\n // If we found a key, it's a duplicate slug - return validation error\n if (existingKeyResult.isOk()) {\n return Result.fail(\n new ApiKeyValidationError(`API key with slug \"${apiKey.slug}\" already exists.`)\n );\n }\n\n // \"NotFound\" error is ok. Everything else is not ok.\n if (existingKeyResult.error.code !== \"ApiKey/NotFound\") {\n return Result.fail(existingKeyResult.error);\n }\n\n // Slug is unique, proceed with creation\n const tenant = this.tenantContext.getTenant();\n await this.storageOperations.createApiKey({ apiKey: { ...apiKey, tenant: tenant.id } });\n return Result.ok();\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async update(apiKey: ApiKey): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n await this.storageOperations.updateApiKey({ apiKey: { ...apiKey, tenant: tenant.id } });\n\n return Result.ok();\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async delete(apiKey: ApiKey): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n await this.storageOperations.deleteApiKey({ apiKey: { ...apiKey, tenant: tenant.id } });\n\n return Result.ok();\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n}\n\nexport const ApiKeysRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: ApiKeysRepositoryImpl,\n dependencies: [TenantContext, SecurityStorageOperations, ApiKeyProvider]\n});\n"],"names":["ApiKeysRepositoryImpl","tenantContext","storageOperations","apiKeyProvider","id","tenant","apiKey","Result","ApiKeyNotFoundError","error","token","factoryApiKey","ApiKeyPersistenceError","slug","params","result","existingKeyResult","ApiKeyValidationError","ApiKeysRepository","createImplementation","RepositoryAbstraction","TenantContext","SecurityStorageOperations","ApiKeyProvider"],"mappings":";;;;;AAWA,MAAMA;IACF,YACYC,aAAsC,EACtCC,iBAAsD,EACtDC,cAAwC,CAClD;aAHUF,aAAa,GAAbA;aACAC,iBAAiB,GAAjBA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,IAAIC,EAAU,EAAwD;QACxE,IAAI;YACA,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C,MAAMC,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC;gBAAEF;gBAAI,QAAQC,OAAO,EAAE;YAAC;YAC9E,IAAIC,QACA,OAAOC,OAAO,EAAE,CAACD;YAGrB,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAC3B,EAAE,OAAOC,OAAO;YACZ,OAAOF,OAAO,IAAI,CAACE;QACvB;IACJ;IAEA,MAAM,WAAWC,KAAa,EAAwD;QAClF,IAAI;YAEA,MAAML,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C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AI,CAAC,IAAIK,uBAAuBH;QAClD;IACJ;AACJ;AAEO,MAAMS,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBpB;IAChB,cAAc;QAACqB;QAAeC;QAA2BC;KAAe;AAC5E"}
1
+ {"version":3,"file":"features/security/apiKeys/shared/ApiKeysRepository.js","sources":["../../../../../src/features/security/apiKeys/shared/ApiKeysRepository.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { ApiKeysRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { ApiKeyProvider } from \"./abstractions.js\";\nimport type { ApiKey, ListApiKeysInput } from \"./types.js\";\nimport { SecurityStorageOperations } from \"~/features/security/shared/abstractions.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { ApiKeyNotFoundError, ApiKeyPersistenceError, ApiKeyValidationError } from \"./errors.js\";\n\n// TODO: create an ApiKeyMapper\n\nclass ApiKeysRepositoryImpl implements RepositoryAbstraction.Interface {\n private resolving = false;\n\n constructor(\n private tenantContext: TenantContext.Interface,\n private storageOperations: SecurityStorageOperations.Interface,\n private apiKeyProvider: ApiKeyProvider.Interface\n ) {}\n\n async get(id: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n const apiKey = await this.storageOperations.getApiKey({ id, tenant: tenant.id });\n if (apiKey) {\n return Result.ok(apiKey);\n }\n\n return Result.fail(new ApiKeyNotFoundError());\n } catch (error) {\n return Result.fail(error);\n }\n }\n\n async getByToken(token: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n const apiKey = await this.storageOperations.getApiKeyByToken({\n token,\n tenant: tenant.id\n });\n\n if (apiKey) {\n return Result.ok(apiKey);\n }\n\n if (!this.resolving) {\n this.resolving = true;\n try {\n const factoryApiKey = await this.apiKeyProvider.getByToken(token);\n if (factoryApiKey) {\n return Result.ok(factoryApiKey);\n }\n } finally {\n this.resolving = false;\n }\n }\n\n return Result.fail(new ApiKeyNotFoundError());\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async getBySlug(slug: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n const apiKey = await this.storageOperations.getApiKeyBySlug({\n slug,\n tenant: tenant.id\n });\n\n if (apiKey) {\n return Result.ok(apiKey);\n }\n\n if (!this.resolving) {\n this.resolving = true;\n try {\n const factoryApiKey = await this.apiKeyProvider.getBySlug(slug);\n if (factoryApiKey) {\n return Result.ok(factoryApiKey);\n }\n } finally {\n this.resolving = false;\n }\n }\n\n return Result.fail(new ApiKeyNotFoundError());\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async list(params: ListApiKeysInput): Promise<Result<ApiKey[], RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n const result = await this.storageOperations.listApiKeys({\n where: { tenant: tenant.id },\n ...params\n });\n return Result.ok(result);\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async create(apiKey: ApiKey): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n // Check if an API key with the same slug already exists\n const existingKeyResult = await this.getBySlug(apiKey.slug);\n\n // If we found a key, it's a duplicate slug - return validation error\n if (existingKeyResult.isOk()) {\n return Result.fail(\n new ApiKeyValidationError(`API key with slug \"${apiKey.slug}\" already exists.`)\n );\n }\n\n // \"NotFound\" error is ok. Everything else is not ok.\n if (existingKeyResult.error.code !== \"ApiKey/NotFound\") {\n return Result.fail(existingKeyResult.error);\n }\n\n // Slug is unique, proceed with creation\n const tenant = this.tenantContext.getTenant();\n await this.storageOperations.createApiKey({ apiKey: { ...apiKey, tenant: tenant.id } });\n return Result.ok();\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async update(apiKey: ApiKey): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n await this.storageOperations.updateApiKey({ apiKey: { ...apiKey, tenant: tenant.id } });\n\n return Result.ok();\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n\n async delete(apiKey: ApiKey): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n await this.storageOperations.deleteApiKey({ apiKey: { ...apiKey, tenant: tenant.id } });\n\n return Result.ok();\n } catch (error) {\n return Result.fail(new ApiKeyPersistenceError(error));\n }\n }\n}\n\nexport const ApiKeysRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: ApiKeysRepositoryImpl,\n dependencies: [TenantContext, SecurityStorageOperations, ApiKeyProvider]\n});\n"],"names":["ApiKeysRepositoryImpl","tenantContext","storageOperations","apiKeyProvider","id","tenant","apiKey","Result","ApiKeyNotFoundError","error","token","factoryApiKey","ApiKeyPersistenceError","slug","params","result","existingKeyResult","ApiKeyValidationError","ApiKeysRepository","createImplementation","RepositoryAbstraction","TenantContext","SecurityStorageOperations","ApiKeyProvider"],"mappings":";;;;;AAWA,MAAMA;IAGF,YACYC,aAAsC,EACtCC,iBAAsD,EACtDC,cAAwC,CAClD;aAHUF,aAAa,GAAbA;aACAC,iBAAiB,GAAjBA;aACAC,cAAc,GAAdA;aALJ,SAAS,GAAG;IAMjB;IAEH,MAAM,IAAIC,EAAU,EAAwD;QACxE,IAAI;YACA,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C,MAAMC,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC;gBAAEF;gBAAI,QAAQC,OAAO,EAAE;YAAC;YAC9E,IAAIC,QACA,OAAOC,OAAO,EAAE,CAACD;YAGrB,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAC3B,EAAE,OAAOC,OAAO;YACZ,OAAOF,OAAO,IAAI,CAACE;QACvB;IACJ;IAEA,MAAM,WAAWC,KAAa,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,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIK,uBAAuBH;QAClD;IACJ;IAEA,MAAM,OAAOH,MAAc,EAAsD;QAC7E,IAAI;YACA,MAAMD,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C,MAAM,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC;gBAAE,QAAQ;oBAAE,GAAGC,MAAM;oBAAE,QAAQD,OAAO,EAAE;gBAAC;YAAE;YAErF,OAAOE,OAAO,EAAE;QACpB,EAAE,OAAOE,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIK,uBAAuBH;QAClD;IACJ;AACJ;AAEO,MAAMS,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBpB;IAChB,cAAc;QAACqB;QAAeC;QAA2BC;KAAe;AAC5E"}
@@ -4,4 +4,4 @@
4
4
  * When authentication plugins kick in, they will be able to tell if they should handle
5
5
  * the token by checking the first letter.
6
6
  */
7
- export declare const generateToken: (tokenLength?: number) => string;
7
+ export declare const generateToken: (tokenLength?: number) => `wat_${string}`;
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/shared/generateToken.js","sources":["../../../../../src/features/security/apiKeys/shared/generateToken.ts"],"sourcesContent":["import crypto from \"crypto\";\n\n/**\n * Generates a random token for API keys.\n * API Keys are prefixed with letter \"wat_\" to make token verification easier.\n * When authentication plugins kick in, they will be able to tell if they should handle\n * the token by checking the first letter.\n */\nexport const generateToken = (tokenLength = 40): string => {\n const token = crypto.randomBytes(Math.ceil(tokenLength / 2)).toString(\"hex\");\n\n // API Keys are prefixed with letters \"wat_\" to make token verification easier\n if (token.startsWith(\"wat_\")) {\n return token;\n }\n\n return `wat_${token.slice(0, tokenLength - 4)}`;\n};\n"],"names":["generateToken","tokenLength","token","crypto","Math"],"mappings":";AAQO,MAAMA,gBAAgB,CAACC,cAAc,EAAE;IAC1C,MAAMC,QAAQC,SAAAA,WAAkB,CAACC,KAAK,IAAI,CAACH,cAAc,IAAI,QAAQ,CAAC;IAGtE,IAAIC,MAAM,UAAU,CAAC,SACjB,OAAOA;IAGX,OAAO,CAAC,IAAI,EAAEA,MAAM,KAAK,CAAC,GAAGD,cAAc,IAAI;AACnD"}
1
+ {"version":3,"file":"features/security/apiKeys/shared/generateToken.js","sources":["../../../../../src/features/security/apiKeys/shared/generateToken.ts"],"sourcesContent":["import crypto from \"crypto\";\n\n/**\n * Generates a random token for API keys.\n * API Keys are prefixed with letter \"wat_\" to make token verification easier.\n * When authentication plugins kick in, they will be able to tell if they should handle\n * the token by checking the first letter.\n */\nexport const generateToken = (tokenLength = 40): `wat_${string}` => {\n const token = crypto.randomBytes(Math.ceil(tokenLength / 2)).toString(\"hex\");\n\n // API Keys are prefixed with letters \"wat_\" to make token verification easier\n if (token.startsWith(\"wat_\")) {\n return token as `wat_${string}`;\n }\n\n return `wat_${token.slice(0, tokenLength - 4)}`;\n};\n"],"names":["generateToken","tokenLength","token","crypto","Math"],"mappings":";AAQO,MAAMA,gBAAgB,CAACC,cAAc,EAAE;IAC1C,MAAMC,QAAQC,SAAAA,WAAkB,CAACC,KAAK,IAAI,CAACH,cAAc,IAAI,QAAQ,CAAC;IAGtE,IAAIC,MAAM,UAAU,CAAC,SACjB,OAAOA;IAGX,OAAO,CAAC,IAAI,EAAEA,MAAM,KAAK,CAAC,GAAGD,cAAc,IAAI;AACnD"}
@@ -2,14 +2,14 @@ import { z } from "zod";
2
2
  export declare const createApiKeyInputSchema: z.ZodObject<{
3
3
  name: z.ZodString;
4
4
  slug: z.ZodString;
5
- description: z.ZodString;
5
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
6
6
  permissions: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
7
7
  name: z.ZodString;
8
8
  }, z.core.$loose>>>>;
9
9
  }, z.core.$strip>;
10
10
  export declare const updateApiKeyInputSchema: z.ZodObject<{
11
11
  name: z.ZodOptional<z.ZodString>;
12
- description: z.ZodOptional<z.ZodString>;
12
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
13
13
  permissions: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
14
14
  name: z.ZodString;
15
15
  }, z.core.$loose>>>>;
@@ -2,14 +2,14 @@ import { z } from "zod";
2
2
  const createApiKeyInputSchema = z.object({
3
3
  name: z.string().min(1),
4
4
  slug: z.string().min(1),
5
- description: z.string(),
5
+ description: z.string().max(500).nullish(),
6
6
  permissions: z.array(z.looseObject({
7
7
  name: z.string()
8
8
  })).optional().default([])
9
9
  });
10
10
  const updateApiKeyInputSchema = z.object({
11
11
  name: z.string().min(1).optional(),
12
- description: z.string().optional(),
12
+ description: z.string().max(500).nullish(),
13
13
  permissions: z.array(z.looseObject({
14
14
  name: z.string()
15
15
  })).optional().default([])
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/shared/schemas.js","sources":["../../../../../src/features/security/apiKeys/shared/schemas.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const createApiKeyInputSchema = z.object({\n name: z.string().min(1),\n slug: z.string().min(1),\n description: z.string(),\n permissions: z\n .array(z.looseObject({ name: z.string() }))\n .optional()\n .default([])\n});\n\nexport const updateApiKeyInputSchema = z.object({\n name: z.string().min(1).optional(),\n description: z.string().optional(),\n permissions: z\n .array(z.looseObject({ name: z.string() }))\n .optional()\n .default([])\n});\n\nexport const listApiKeysInputSchema = z.object({\n where: z\n .object({\n name: z.string().optional(),\n name_contains: z.string().optional(),\n description: z.string().optional(),\n description_contains: z.string().optional()\n })\n .optional(),\n limit: z.number().int().positive().max(100).optional(),\n after: z.string().optional(),\n sort: z.array(z.enum([\"createdOn_ASC\", \"createdOn_DESC\"])).optional()\n});\n"],"names":["createApiKeyInputSchema","z","updateApiKeyInputSchema","listApiKeysInputSchema"],"mappings":";AAEO,MAAMA,0BAA0BC,EAAE,MAAM,CAAC;IAC5C,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,aAAaA,EAAE,MAAM;IACrB,aAAaA,EAAAA,KACH,CAACA,EAAE,WAAW,CAAC;QAAE,MAAMA,EAAE,MAAM;IAAG,IACvC,QAAQ,GACR,OAAO,CAAC,EAAE;AACnB;AAEO,MAAMC,0BAA0BD,EAAE,MAAM,CAAC;IAC5C,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,QAAQ;IAChC,aAAaA,EAAE,MAAM,GAAG,QAAQ;IAChC,aAAaA,EAAAA,KACH,CAACA,EAAE,WAAW,CAAC;QAAE,MAAMA,EAAE,MAAM;IAAG,IACvC,QAAQ,GACR,OAAO,CAAC,EAAE;AACnB;AAEO,MAAME,yBAAyBF,EAAE,MAAM,CAAC;IAC3C,OAAOA,EAAAA,MACI,CAAC;QACJ,MAAMA,EAAE,MAAM,GAAG,QAAQ;QACzB,eAAeA,EAAE,MAAM,GAAG,QAAQ;QAClC,aAAaA,EAAE,MAAM,GAAG,QAAQ;QAChC,sBAAsBA,EAAE,MAAM,GAAG,QAAQ;IAC7C,GACC,QAAQ;IACb,OAAOA,EAAE,MAAM,GAAG,GAAG,GAAG,QAAQ,GAAG,GAAG,CAAC,KAAK,QAAQ;IACpD,OAAOA,EAAE,MAAM,GAAG,QAAQ;IAC1B,MAAMA,EAAE,KAAK,CAACA,CAAC,CAADA,OAAM,CAAC;QAAC;QAAiB;KAAiB,GAAG,QAAQ;AACvE"}
1
+ {"version":3,"file":"features/security/apiKeys/shared/schemas.js","sources":["../../../../../src/features/security/apiKeys/shared/schemas.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const createApiKeyInputSchema = z.object({\n name: z.string().min(1),\n slug: z.string().min(1),\n // Nullable in the GraphQL schema - see `descriptionOnCreate` for why this is `.nullish()`.\n // This was a bare `z.string()`, so an API key created without a description was rejected\n // whether the client sent null or omitted the field entirely. `max` matches teams and roles.\n description: z.string().max(500).nullish(),\n permissions: z\n .array(z.looseObject({ name: z.string() }))\n .optional()\n .default([])\n});\n\nexport const updateApiKeyInputSchema = z.object({\n name: z.string().min(1).optional(),\n // Nullable in the GraphQL schema - see `descriptionOnUpdate` for why this is `.nullish()` and\n // must not carry a `.transform()`. `max` matches teams and roles.\n description: z.string().max(500).nullish(),\n permissions: z\n .array(z.looseObject({ name: z.string() }))\n .optional()\n .default([])\n});\n\nexport const listApiKeysInputSchema = z.object({\n where: z\n .object({\n name: z.string().optional(),\n name_contains: z.string().optional(),\n description: z.string().optional(),\n description_contains: z.string().optional()\n })\n .optional(),\n limit: z.number().int().positive().max(100).optional(),\n after: z.string().optional(),\n sort: z.array(z.enum([\"createdOn_ASC\", \"createdOn_DESC\"])).optional()\n});\n"],"names":["createApiKeyInputSchema","z","updateApiKeyInputSchema","listApiKeysInputSchema"],"mappings":";AAEO,MAAMA,0BAA0BC,EAAE,MAAM,CAAC;IAC5C,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC;IAIrB,aAAaA,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,OAAO;IACxC,aAAaA,EAAAA,KACH,CAACA,EAAE,WAAW,CAAC;QAAE,MAAMA,EAAE,MAAM;IAAG,IACvC,QAAQ,GACR,OAAO,CAAC,EAAE;AACnB;AAEO,MAAMC,0BAA0BD,EAAE,MAAM,CAAC;IAC5C,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,QAAQ;IAGhC,aAAaA,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,OAAO;IACxC,aAAaA,EAAAA,KACH,CAACA,EAAE,WAAW,CAAC;QAAE,MAAMA,EAAE,MAAM;IAAG,IACvC,QAAQ,GACR,OAAO,CAAC,EAAE;AACnB;AAEO,MAAME,yBAAyBF,EAAE,MAAM,CAAC;IAC3C,OAAOA,EAAAA,MACI,CAAC;QACJ,MAAMA,EAAE,MAAM,GAAG,QAAQ;QACzB,eAAeA,EAAE,MAAM,GAAG,QAAQ;QAClC,aAAaA,EAAE,MAAM,GAAG,QAAQ;QAChC,sBAAsBA,EAAE,MAAM,GAAG,QAAQ;IAC7C,GACC,QAAQ;IACb,OAAOA,EAAE,MAAM,GAAG,GAAG,GAAG,QAAQ,GAAG,GAAG,CAAC,KAAK,QAAQ;IACpD,OAAOA,EAAE,MAAM,GAAG,QAAQ;IAC1B,MAAMA,EAAE,KAAK,CAACA,CAAC,CAADA,OAAM,CAAC;QAAC;QAAiB;KAAiB,GAAG,QAAQ;AACvE"}
@@ -4,7 +4,7 @@ export interface ApiKey {
4
4
  name: string;
5
5
  slug: string;
6
6
  description: string;
7
- token: string;
7
+ token: `wat_${string}`;
8
8
  permissions: SecurityPermission[];
9
9
  createdBy: CreatedBy;
10
10
  createdOn: string;
@@ -1,4 +1,4 @@
1
- import { WcpContext } from "../../../../features/wcp/WcpContext/index.js";
1
+ import { FeatureFlags } from "../../../../features/featureFlags/abstractions.js";
2
2
  import { Identity } from "../../../../features/security/IdentityContext/index.js";
3
3
  import { PermissionsProcessor } from "./abstractions.js";
4
4
  import { RolesRepository } from "../../../../features/security/roles/shared/abstractions.js";
@@ -7,14 +7,14 @@ import { AdminUsersRepository } from "../../../../features/users/shared/abstract
7
7
  export type RoleId = string | undefined;
8
8
  export type TeamId = string | undefined;
9
9
  declare class GetPermissionsFromGroupsAndTeamsImpl implements PermissionsProcessor.Interface {
10
- private wcpContext;
10
+ private featureFlags;
11
11
  private usersRepository;
12
12
  private rolesRepository;
13
13
  private teamsRepository;
14
- constructor(wcpContext: WcpContext.Interface, usersRepository: AdminUsersRepository.Interface, rolesRepository: RolesRepository.Interface, teamsRepository: TeamsRepository.Interface);
14
+ constructor(featureFlags: FeatureFlags.Interface, usersRepository: AdminUsersRepository.Interface, rolesRepository: RolesRepository.Interface, teamsRepository: TeamsRepository.Interface);
15
15
  getPermissions(identity: Identity): Promise<{
16
- _src: string;
17
16
  name: string;
17
+ _src: string;
18
18
  }[] | null>;
19
19
  }
20
20
  export declare const GetPermissionsFromIdentity: typeof GetPermissionsFromGroupsAndTeamsImpl & {
@@ -1,12 +1,12 @@
1
- import { WcpContext } from "../../../wcp/WcpContext/index.js";
1
+ import { FeatureFlags } from "../../../featureFlags/abstractions.js";
2
2
  import { PermissionsProcessor } from "./abstractions.js";
3
3
  import { RolesRepository } from "../../roles/shared/abstractions.js";
4
4
  import { TeamsRepository } from "../../teams/shared/abstractions.js";
5
5
  import { getPermissionsFromRoles } from "../../utils/getPermissionsFromRoles.js";
6
6
  import { AdminUsersRepository } from "../../../users/shared/abstractions.js";
7
7
  class GetPermissionsFromGroupsAndTeamsImpl {
8
- constructor(wcpContext, usersRepository, rolesRepository, teamsRepository){
9
- this.wcpContext = wcpContext;
8
+ constructor(featureFlags, usersRepository, rolesRepository, teamsRepository){
9
+ this.featureFlags = featureFlags;
10
10
  this.usersRepository = usersRepository;
11
11
  this.rolesRepository = rolesRepository;
12
12
  this.teamsRepository = teamsRepository;
@@ -32,7 +32,7 @@ class GetPermissionsFromGroupsAndTeamsImpl {
32
32
  const loadedRolesByIds = rolesResult.isOk() ? rolesResult.value : [];
33
33
  loadedRoles.push(...loadedRolesByIds);
34
34
  }
35
- if (this.wcpContext.canUseTeams()) {
35
+ if (this.featureFlags.get().isEnabled("advancedAccessControlLayer.teams")) {
36
36
  teamIds.push(...user.teams ?? []);
37
37
  const filteredTeamIds = teamIds.filter(Boolean);
38
38
  const dedupedTeamIds = Array.from(new Set(filteredTeamIds));
@@ -65,7 +65,7 @@ class GetPermissionsFromGroupsAndTeamsImpl {
65
65
  const GetPermissionsFromIdentity = PermissionsProcessor.createImplementation({
66
66
  implementation: GetPermissionsFromGroupsAndTeamsImpl,
67
67
  dependencies: [
68
- WcpContext,
68
+ FeatureFlags,
69
69
  AdminUsersRepository,
70
70
  RolesRepository,
71
71
  TeamsRepository
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js","sources":["../../../../../src/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.ts"],"sourcesContent":["import { WcpContext } from \"~/features/wcp/WcpContext/index.js\";\nimport type { SecurityRole } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\nimport { PermissionsProcessor } from \"./abstractions.js\";\nimport { RolesRepository } from \"~/features/security/roles/shared/abstractions.js\";\nimport { TeamsRepository } from \"~/features/security/teams/shared/abstractions.js\";\nimport { getPermissionsFromRoles } from \"~/features/security/utils/getPermissionsFromRoles.js\";\nimport { AdminUsersRepository } from \"~/features/users/shared/abstractions.js\";\n\nexport type RoleId = string | undefined;\nexport type TeamId = string | undefined;\n\nclass GetPermissionsFromGroupsAndTeamsImpl implements PermissionsProcessor.Interface {\n constructor(\n private wcpContext: WcpContext.Interface,\n private usersRepository: AdminUsersRepository.Interface,\n private rolesRepository: RolesRepository.Interface,\n private teamsRepository: TeamsRepository.Interface\n ) {}\n\n async getPermissions(identity: Identity) {\n const userResult = await this.usersRepository.get({ id: identity.id });\n if (userResult.isFail()) {\n return null;\n }\n\n const user = userResult.value;\n\n // Load roles that are associated with the current identity. Also load roles\n // that are assigned via one or more teams (if the Teams feature is enabled).\n const roleIds: RoleId[] = [];\n const teamIds: TeamId[] = [];\n\n roleIds.push(...(user.roles ?? []));\n\n const filteredRoleIds = roleIds.filter(Boolean) as string[];\n const dedupedRoleIds = Array.from(new Set(filteredRoleIds));\n\n const loadedRoles: SecurityRole[] = [];\n\n if (dedupedRoleIds.length > 0) {\n const rolesResult = await this.rolesRepository.list({\n where: { id_in: dedupedRoleIds }\n });\n\n const loadedRolesByIds = rolesResult.isOk() ? rolesResult.value : [];\n loadedRoles.push(...loadedRolesByIds);\n }\n\n if (this.wcpContext.canUseTeams()) {\n teamIds.push(...(user.teams ?? []));\n\n const filteredTeamIds = teamIds.filter(Boolean) as string[];\n const dedupedTeamIds = Array.from(new Set(filteredTeamIds));\n\n if (dedupedTeamIds.length > 0) {\n const teamsResult = await this.teamsRepository.list({\n where: { id_in: dedupedTeamIds }\n });\n\n const loadedTeams = teamsResult.isOk() ? teamsResult.value : [];\n\n // Upon returning teams, we're filtering out team roles that were already loaded.\n // Also note that `team.roles` contains role IDs, not slugs.\n const roleIdsFromTeams = loadedTeams\n .flatMap(team => team.roles)\n .filter(roleId => {\n const alreadyLoaded = loadedRoles.find(role => role.id === roleId);\n return !alreadyLoaded;\n });\n\n if (roleIdsFromTeams.length > 0) {\n const moreRolesResult = await this.rolesRepository.list({\n where: { id_in: roleIdsFromTeams }\n });\n\n const rolesFromTeams = moreRolesResult.isOk() ? moreRolesResult.value : [];\n loadedRoles.push(...rolesFromTeams);\n }\n }\n }\n\n if (loadedRoles.length > 0) {\n return getPermissionsFromRoles(loadedRoles);\n }\n\n return null;\n }\n}\n\nexport const GetPermissionsFromIdentity = PermissionsProcessor.createImplementation({\n implementation: GetPermissionsFromGroupsAndTeamsImpl,\n dependencies: [WcpContext, AdminUsersRepository, RolesRepository, TeamsRepository]\n});\n"],"names":["GetPermissionsFromGroupsAndTeamsImpl","wcpContext","usersRepository","rolesRepository","teamsRepository","identity","userResult","user","roleIds","teamIds","filteredRoleIds","Boolean","dedupedRoleIds","Array","Set","loadedRoles","rolesResult","loadedRolesByIds","filteredTeamIds","dedupedTeamIds","teamsResult","loadedTeams","roleIdsFromTeams","team","roleId","alreadyLoaded","role","moreRolesResult","rolesFromTeams","getPermissionsFromRoles","GetPermissionsFromIdentity","PermissionsProcessor","WcpContext","AdminUsersRepository","RolesRepository","TeamsRepository"],"mappings":";;;;;;AAYA,MAAMA;IACF,YACYC,UAAgC,EAChCC,eAA+C,EAC/CC,eAA0C,EAC1CC,eAA0C,CACpD;aAJUH,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,eAAe,GAAfA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,eAAeC,QAAkB,EAAE;QACrC,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;YAAE,IAAID,SAAS,EAAE;QAAC;QACp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eAAe,CAAC,IAAI,CAAC;wBACpD,OAAO;4BAAE,OAAOL;wBAAiB;oBACrC;oBAEA,MAAMM,iBAAiBD,gBAAgB,IAAI,KAAKA,gBAAgB,KAAK,GAAG,EAAE;oBAC1EZ,YAAY,IAAI,IAAIa;gBACxB;YACJ;QACJ;QAEA,IAAIb,YAAY,MAAM,GAAG,GACrB,OAAOc,wBAAwBd;QAGnC,OAAO;IACX;AACJ;AAEO,MAAMe,6BAA6BC,qBAAqB,oBAAoB,CAAC;IAChF,gBAAgB/B;IAChB,cAAc;QAACgC;QAAYC;QAAsBC;QAAiBC;KAAgB;AACtF"}
1
+ {"version":3,"file":"features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js","sources":["../../../../../src/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.ts"],"sourcesContent":["import { FeatureFlags } from \"~/features/featureFlags/abstractions.js\";\nimport type { SecurityRole } from \"~/types/security.js\";\nimport { Identity } from \"~/features/security/IdentityContext/index.js\";\nimport { PermissionsProcessor } from \"./abstractions.js\";\nimport { RolesRepository } from \"~/features/security/roles/shared/abstractions.js\";\nimport { TeamsRepository } from \"~/features/security/teams/shared/abstractions.js\";\nimport { getPermissionsFromRoles } from \"~/features/security/utils/getPermissionsFromRoles.js\";\nimport { AdminUsersRepository } from \"~/features/users/shared/abstractions.js\";\n\nexport type RoleId = string | undefined;\nexport type TeamId = string | undefined;\n\nclass GetPermissionsFromGroupsAndTeamsImpl implements PermissionsProcessor.Interface {\n constructor(\n private featureFlags: FeatureFlags.Interface,\n private usersRepository: AdminUsersRepository.Interface,\n private rolesRepository: RolesRepository.Interface,\n private teamsRepository: TeamsRepository.Interface\n ) {}\n\n async getPermissions(identity: Identity) {\n const userResult = await this.usersRepository.get({ id: identity.id });\n if (userResult.isFail()) {\n return null;\n }\n\n const user = userResult.value;\n\n // Load roles that are associated with the current identity. Also load roles\n // that are assigned via one or more teams (if the Teams feature is enabled).\n const roleIds: RoleId[] = [];\n const teamIds: TeamId[] = [];\n\n roleIds.push(...(user.roles ?? []));\n\n const filteredRoleIds = roleIds.filter(Boolean) as string[];\n const dedupedRoleIds = Array.from(new Set(filteredRoleIds));\n\n const loadedRoles: SecurityRole[] = [];\n\n if (dedupedRoleIds.length > 0) {\n const rolesResult = await this.rolesRepository.list({\n where: { id_in: dedupedRoleIds }\n });\n\n const loadedRolesByIds = rolesResult.isOk() ? rolesResult.value : [];\n loadedRoles.push(...loadedRolesByIds);\n }\n\n if (this.featureFlags.get().isEnabled(\"advancedAccessControlLayer.teams\")) {\n teamIds.push(...(user.teams ?? []));\n\n const filteredTeamIds = teamIds.filter(Boolean) as string[];\n const dedupedTeamIds = Array.from(new Set(filteredTeamIds));\n\n if (dedupedTeamIds.length > 0) {\n const teamsResult = await this.teamsRepository.list({\n where: { id_in: dedupedTeamIds }\n });\n\n const loadedTeams = teamsResult.isOk() ? teamsResult.value : [];\n\n // Upon returning teams, we're filtering out team roles that were already loaded.\n // Also note that `team.roles` contains role IDs, not slugs.\n const roleIdsFromTeams = loadedTeams\n .flatMap(team => team.roles)\n .filter(roleId => {\n const alreadyLoaded = loadedRoles.find(role => role.id === roleId);\n return !alreadyLoaded;\n });\n\n if (roleIdsFromTeams.length > 0) {\n const moreRolesResult = await this.rolesRepository.list({\n where: { id_in: roleIdsFromTeams }\n });\n\n const rolesFromTeams = moreRolesResult.isOk() ? moreRolesResult.value : [];\n loadedRoles.push(...rolesFromTeams);\n }\n }\n }\n\n if (loadedRoles.length > 0) {\n return getPermissionsFromRoles(loadedRoles);\n }\n\n return null;\n }\n}\n\nexport const GetPermissionsFromIdentity = PermissionsProcessor.createImplementation({\n implementation: GetPermissionsFromGroupsAndTeamsImpl,\n dependencies: [FeatureFlags, AdminUsersRepository, RolesRepository, TeamsRepository]\n});\n"],"names":["GetPermissionsFromGroupsAndTeamsImpl","featureFlags","usersRepository","rolesRepository","teamsRepository","identity","userResult","user","roleIds","teamIds","filteredRoleIds","Boolean","dedupedRoleIds","Array","Set","loadedRoles","rolesResult","loadedRolesByIds","filteredTeamIds","dedupedTeamIds","teamsResult","loadedTeams","roleIdsFromTeams","team","roleId","alreadyLoaded","role","moreRolesResult","rolesFromTeams","getPermissionsFromRoles","GetPermissionsFromIdentity","PermissionsProcessor","FeatureFlags","AdminUsersRepository","RolesRepository","TeamsRepository"],"mappings":";;;;;;AAYA,MAAMA;IACF,YACYC,YAAoC,EACpCC,eAA+C,EAC/CC,eAA0C,EAC1CC,eAA0C,CACpD;aAJUH,YAAY,GAAZA;aACAC,eAAe,GAAfA;aACAC,eAAe,GAAfA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,eAAeC,QAAkB,EAAE;QACrC,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;YAAE,IAAID,SAAS,EAAE;QAAC;QACpE,IAAIC,WAAW,MAAM,IACjB,OAAO;QAGX,MAAMC,OAAOD,WAAW,KAAK;QAI7B,MAAME,UAAoB,EAAE;QAC5B,MAAMC,UAAoB,EAAE;QAE5BD,QAAQ,IAAI,IAAKD,KAAK,KAAK,IAAI,EAAE;QAEjC,MAAMG,kBAAkBF,QAAQ,MAAM,CAACG;QACvC,MAAMC,iBAAiBC,MAAM,IAAI,CAAC,IAAIC,IAAIJ;QAE1C,MAAMK,cAA8B,EAAE;QAEtC,IAAIH,eAAe,MAAM,GAAG,GAAG;YAC3B,MAAMI,cAAc,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;gBAChD,OAAO;oBAAE,OAAOJ;gBAAe;YACnC;YAEA,MAAMK,mBAAmBD,YAAY,IAAI,KAAKA,YAAY,KAAK,GAAG,EAAE;YACpED,YAAY,IAAI,IAAIE;QACxB;QAEA,IAAI,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC,qCAAqC;YACvER,QAAQ,IAAI,IAAKF,KAAK,KAAK,IAAI,EAAE;YAEjC,MAAMW,kBAAkBT,QAAQ,MAAM,CAACE;YACvC,MAAMQ,iBAAiBN,MAAM,IAAI,CAAC,IAAIC,IAAII;YAE1C,IAAIC,eAAe,MAAM,GAAG,GAAG;gBAC3B,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;oBAChD,OAAO;wBAAE,OAAOD;oBAAe;gBACnC;gBAEA,MAAME,cAAcD,YAAY,IAAI,KAAKA,YAAY,KAAK,GAAG,EAAE;gBAI/D,MAAME,mBAAmBD,YACpB,OAAO,CAACE,CAAAA,OAAQA,KAAK,KAAK,EAC1B,MAAM,CAACC,CAAAA;oBACJ,MAAMC,gBAAgBV,YAAY,IAAI,CAACW,CAAAA,OAAQA,KAAK,EAAE,KAAKF;oBAC3D,OAAO,CAACC;gBACZ;gBAEJ,IAAIH,iBAAiB,MAAM,GAAG,GAAG;oBAC7B,MAAMK,kBAAkB,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;wBACpD,OAAO;4BAAE,OAAOL;wBAAiB;oBACrC;oBAEA,MAAMM,iBAAiBD,gBAAgB,IAAI,KAAKA,gBAAgB,KAAK,GAAG,EAAE;oBAC1EZ,YAAY,IAAI,IAAIa;gBACxB;YACJ;QACJ;QAEA,IAAIb,YAAY,MAAM,GAAG,GACrB,OAAOc,wBAAwBd;QAGnC,OAAO;IACX;AACJ;AAEO,MAAMe,6BAA6BC,qBAAqB,oBAAoB,CAAC;IAChF,gBAAgB/B;IAChB,cAAc;QAACgC;QAAcC;QAAsBC;QAAiBC;KAAgB;AACxF"}
@@ -7,6 +7,7 @@ import { IdentityContext } from "../../IdentityContext/abstractions.js";
7
7
  import { createRoleValidation } from "./schema.js";
8
8
  import { RoleAfterCreateEvent, RoleBeforeCreateEvent } from "./events.js";
9
9
  import { NotAuthorizedError, RoleExistsError, RoleValidationError } from "../shared/errors.js";
10
+ import { descriptionOnCreate } from "../../shared/description.js";
10
11
  class CreateRoleUseCaseImpl {
11
12
  constructor(identityContext, eventPublisher, repository){
12
13
  this.identityContext = identityContext;
@@ -24,12 +25,16 @@ class CreateRoleUseCaseImpl {
24
25
  slug: data.slug
25
26
  });
26
27
  if (existingRoleResult.isOk()) return Result.fail(new RoleExistsError(data.slug));
28
+ const createInput = {
29
+ ...data,
30
+ description: descriptionOnCreate(data.description)
31
+ };
27
32
  const role = {
28
33
  id: mdbid(),
29
- name: data.name,
30
- slug: data.slug,
31
- description: data.description,
32
- permissions: data.permissions,
34
+ name: createInput.name,
35
+ slug: createInput.slug,
36
+ description: descriptionOnCreate(createInput.description),
37
+ permissions: createInput.permissions,
33
38
  system: input.system || false,
34
39
  createdOn: new Date().toISOString(),
35
40
  createdBy: {
@@ -41,13 +46,13 @@ class CreateRoleUseCaseImpl {
41
46
  };
42
47
  await this.eventPublisher.publish(new RoleBeforeCreateEvent({
43
48
  role,
44
- input: validation.data
49
+ input: createInput
45
50
  }));
46
51
  const result = await this.repository.create(role);
47
52
  if (result.isFail()) return Result.fail(result.error);
48
53
  await this.eventPublisher.publish(new RoleAfterCreateEvent({
49
54
  role,
50
- input: validation.data
55
+ input: createInput
51
56
  }));
52
57
  return Result.ok(role);
53
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/roles/CreateRole/CreateRoleUseCase.js","sources":["../../../../../src/features/security/roles/CreateRole/CreateRoleUseCase.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { CreateRoleUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { createRoleValidation } from \"./schema.js\";\nimport { RoleBeforeCreateEvent, RoleAfterCreateEvent } from \"./events.js\";\nimport type { Role, CreateRoleInput } from \"../shared/types.js\";\nimport { NotAuthorizedError, RoleExistsError, RoleValidationError } from \"../shared/errors.js\";\n\nclass CreateRoleUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: RolesRepository.Interface\n ) {}\n\n async execute(input: CreateRoleInput): Promise<Result<Role, UseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.role\");\n\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const validation = createRoleValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new RoleValidationError(validation.error.issues[0].message));\n }\n\n const identity = this.identityContext.getIdentity();\n const data = validation.data;\n\n // Check if role with same slug already exists\n const existingRoleResult = await this.repository.get({ slug: data.slug });\n if (existingRoleResult.isOk()) {\n return Result.fail(new RoleExistsError(data.slug));\n }\n\n const role: Role = {\n id: mdbid(),\n name: data.name,\n slug: data.slug,\n description: data.description,\n permissions: data.permissions,\n system: input.system || false,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n plugin: false\n };\n\n await this.eventPublisher.publish(\n new RoleBeforeCreateEvent({ role, input: validation.data })\n );\n\n const result = await this.repository.create(role);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new RoleAfterCreateEvent({ role, input: validation.data })\n );\n\n return Result.ok(role);\n }\n}\n\nexport const CreateRoleUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: CreateRoleUseCaseImpl,\n dependencies: [IdentityContext, EventPublisher, RolesRepository]\n});\n"],"names":["CreateRoleUseCaseImpl","identityContext","eventPublisher","repository","input","hasPermission","Result","NotAuthorizedError","validation","createRoleValidation","RoleValidationError","identity","data","existingRoleResult","RoleExistsError","role","mdbid","Date","RoleBeforeCreateEvent","result","RoleAfterCreateEvent","CreateRoleUseCase","createImplementation","UseCaseAbstraction","IdentityContext","EventPublisher","RolesRepository"],"mappings":";;;;;;;;;AAYA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAAqC,C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AAc,CAAC,OAAO,CAC7B,IAAIC,qBAAqB;YAAEL;YAAM,OAAOP,WAAW,IAAI;QAAC;QAG5D,OAAOF,OAAO,EAAE,CAACS;IACrB;AACJ;AAEO,MAAMM,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBvB;IAChB,cAAc;QAACwB;QAAiBC;QAAgBC;KAAgB;AACpE"}
1
+ {"version":3,"file":"features/security/roles/CreateRole/CreateRoleUseCase.js","sources":["../../../../../src/features/security/roles/CreateRole/CreateRoleUseCase.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { CreateRoleUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { createRoleValidation } from \"./schema.js\";\nimport { RoleBeforeCreateEvent, RoleAfterCreateEvent } from \"./events.js\";\nimport type { Role, CreateRoleInput } from \"../shared/types.js\";\nimport { NotAuthorizedError, RoleExistsError, RoleValidationError } from \"../shared/errors.js\";\nimport { descriptionOnCreate } from \"../../shared/description.js\";\n\nclass CreateRoleUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: RolesRepository.Interface\n ) {}\n\n async execute(input: CreateRoleInput): Promise<Result<Role, UseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.role\");\n\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const validation = createRoleValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new RoleValidationError(validation.error.issues[0].message));\n }\n\n const identity = this.identityContext.getIdentity();\n const data = validation.data;\n\n // Check if role with same slug already exists\n const existingRoleResult = await this.repository.get({ slug: data.slug });\n if (existingRoleResult.isOk()) {\n return Result.fail(new RoleExistsError(data.slug));\n }\n\n // Normalised up front so that null reaches neither the entity nor the published events.\n const createInput: CreateRoleInput = {\n ...data,\n description: descriptionOnCreate(data.description)\n };\n\n const role: Role = {\n id: mdbid(),\n name: createInput.name,\n slug: createInput.slug,\n description: descriptionOnCreate(createInput.description),\n permissions: createInput.permissions,\n system: input.system || false,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n plugin: false\n };\n\n await this.eventPublisher.publish(new RoleBeforeCreateEvent({ role, input: createInput }));\n\n const result = await this.repository.create(role);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(new RoleAfterCreateEvent({ role, input: createInput }));\n\n return Result.ok(role);\n }\n}\n\nexport const CreateRoleUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: CreateRoleUseCaseImpl,\n dependencies: [IdentityContext, EventPublisher, RolesRepository]\n});\n"],"names":["CreateRoleUseCaseImpl","identityContext","eventPublisher","repository","input","hasPermission","Result","NotAuthorizedError","validation","createRoleValidation","RoleValidationError","identity","data","existingRoleResult","RoleExistsError","createInput","descriptionOnCreate","role","mdbid","Date","RoleBeforeCreateEvent","result","RoleAfterCreateEvent","CreateRoleUseCase","createImplementation","UseCaseAbstraction","IdentityContext","EventPublisher","RolesRepository"],"mappings":";;;;;;;;;;AAaA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAAqC,CAC/C;aAHUF,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,KAAsB,EAAmD;QACnF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAE/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,aAAaC,qBAAqB,SAAS,CAACL;QAClD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,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@ import { z } from "zod";
2
2
  export declare const createRoleValidation: z.ZodObject<{
3
3
  name: z.ZodString;
4
4
  slug: z.ZodString;
5
- description: z.ZodDefault<z.ZodOptional<z.ZodString>>;
5
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
6
6
  permissions: z.ZodArray<z.ZodObject<{
7
7
  name: z.ZodString;
8
8
  }, z.core.$loose>>;
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  const createRoleValidation = z.object({
3
3
  name: z.string().min(3),
4
4
  slug: z.string().min(3),
5
- description: z.string().max(500).optional().default(""),
5
+ description: z.string().max(500).nullish(),
6
6
  permissions: z.array(z.looseObject({
7
7
  name: z.string()
8
8
  }))
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/roles/CreateRole/schema.js","sources":["../../../../../src/features/security/roles/CreateRole/schema.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const createRoleValidation = z.object({\n name: z.string().min(3),\n slug: z.string().min(3),\n description: z.string().max(500).optional().default(\"\"),\n permissions: z.array(z.looseObject({ name: z.string() }))\n});\n"],"names":["createRoleValidation","z"],"mappings":";AAEO,MAAMA,uBAAuBC,EAAE,MAAM,CAAC;IACzC,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,aAAaA,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,QAAQ,GAAG,OAAO,CAAC;IACpD,aAAaA,EAAE,KAAK,CAACA,EAAE,WAAW,CAAC;QAAE,MAAMA,EAAE,MAAM;IAAG;AAC1D"}
1
+ {"version":3,"file":"features/security/roles/CreateRole/schema.js","sources":["../../../../../src/features/security/roles/CreateRole/schema.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const createRoleValidation = z.object({\n name: z.string().min(3),\n slug: z.string().min(3),\n // Nullable in the GraphQL schema - see `descriptionOnCreate` for why this is `.nullish()`.\n // `.optional().default(\"\")` did NOT cover this: Zod applies a default to `undefined` only, so\n // an explicit null still failed validation.\n description: z.string().max(500).nullish(),\n permissions: z.array(z.looseObject({ name: z.string() }))\n});\n"],"names":["createRoleValidation","z"],"mappings":";AAEO,MAAMA,uBAAuBC,EAAE,MAAM,CAAC;IACzC,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC;IAIrB,aAAaA,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,OAAO;IACxC,aAAaA,EAAE,KAAK,CAACA,EAAE,WAAW,CAAC;QAAE,MAAMA,EAAE,MAAM;IAAG;AAC1D"}
@@ -15,7 +15,6 @@ class RolesInstallerImpl {
15
15
  }
16
16
  async install() {
17
17
  const rolesResult = await this.listRolesUseCase.execute();
18
- if (rolesResult.isFail()) throw rolesResult.error;
19
18
  const roles = rolesResult.value;
20
19
  if (!roles.find((g)=>"full-access" === g.slug)) {
21
20
  const result = await this.createRoleUseCase.execute({
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/roles/Installer/RolesInstaller.js","sources":["../../../../../src/features/security/roles/Installer/RolesInstaller.ts"],"sourcesContent":["import { AppInstaller } from \"~/features/tenancy/InstallTenant/index.js\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Role } from \"../shared/types.js\";\nimport { ListRolesUseCase } from \"~/features/security/roles/ListRoles/index.js\";\nimport { CreateRoleUseCase } from \"~/features/security/roles/CreateRole/index.js\";\nimport { DeleteRoleUseCase } from \"~/features/security/roles/DeleteRole/index.js\";\n\nclass RolesInstallerImpl implements AppInstaller.Interface {\n readonly alwaysRun = true;\n readonly appName = \"Security\";\n readonly dependsOn = [];\n private createdRoles: Role[] = [];\n\n constructor(\n private listRolesUseCase: ListRolesUseCase.Interface,\n private createRoleUseCase: CreateRoleUseCase.Interface,\n private deleteRoleUseCase: DeleteRoleUseCase.Interface\n ) {}\n\n async install(): Promise<void> {\n const rolesResult = await this.listRolesUseCase.execute();\n if (rolesResult.isFail()) {\n throw rolesResult.error;\n }\n const roles = rolesResult.value;\n\n if (!roles.find(g => g.slug === \"full-access\")) {\n const result = await this.createRoleUseCase.execute({\n name: \"Full Access\",\n description: \"Grants full access to all apps.\",\n system: true,\n slug: \"full-access\",\n permissions: [{ name: \"*\" }]\n });\n\n if (result.isFail()) {\n throw result.error;\n }\n\n this.createdRoles.push(result.value);\n }\n }\n\n async uninstall(): Promise<void> {\n for (const role of this.createdRoles) {\n await this.deleteRoleUseCase.execute(role.id);\n }\n }\n}\n\nexport const RoleInstaller = createImplementation({\n abstraction: AppInstaller,\n implementation: RolesInstallerImpl,\n dependencies: [ListRolesUseCase, CreateRoleUseCase, DeleteRoleUseCase]\n});\n"],"names":["RolesInstallerImpl","listRolesUseCase","createRoleUseCase","deleteRoleUseCase","rolesResult","roles","g","result","role","RoleInstaller","createImplementation","AppInstaller","ListRolesUseCase","CreateRoleUseCase","DeleteRoleUseCase"],"mappings":";;;;;AAOA,MAAMA;IAMF,YACYC,gBAA4C,EAC5CC,iBAA8C,EAC9CC,iBAA8C,CACxD;aAHUF,gBAAgB,GAAhBA;aACAC,iBAAiB,GAAjBA;aACAC,iBAAiB,GAAjBA;aARH,SAAS,GAAG;aACZ,OAAO,GAAG;aACV,SAAS,GAAG,EAAE;aACf,YAAY,GAAW,EAAE;IAM9B;IAEH,MAAM,UAAyB;QAC3B,MAAMC,cAAc,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO;QACvD,IAAIA,YAAY,MAAM,IAClB,MAAMA,YAAY,KAAK;QAE3B,MAAMC,QAAQD,YAAY,KAAK;QAE/B,IAAI,CAACC,MAAM,IAAI,CAACC,CAAAA,IAAKA,AAAW,kBAAXA,EAAE,IAAI,GAAqB;YAC5C,MAAMC,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC;gBAChD,MAAM;gBACN,aAAa;gBACb,QAAQ;gBACR,MAAM;gBACN,aAAa;oBAAC;wBAAE,MAAM;oBAAI;iBAAE;YAChC;YAEA,IAAIA,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;YAGtB,IAAI,CAAC,YAAY,CAAC,IAAI,CAACA,OAAO,KAAK;QACvC;IACJ;IAEA,MAAM,YAA2B;QAC7B,KAAK,MAAMC,QAAQ,IAAI,CAAC,YAAY,CAChC,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACA,KAAK,EAAE;IAEpD;AACJ;AAEO,MAAMC,gBAAgBC,qBAAqB;IAC9C,aAAaC;IACb,gBAAgBX;IAChB,cAAc;QAACY;QAAkBC;QAAmBC;KAAkB;AAC1E"}
1
+ {"version":3,"file":"features/security/roles/Installer/RolesInstaller.js","sources":["../../../../../src/features/security/roles/Installer/RolesInstaller.ts"],"sourcesContent":["import { AppInstaller } from \"~/features/tenancy/InstallTenant/index.js\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Role } from \"../shared/types.js\";\nimport { ListRolesUseCase } from \"~/features/security/roles/ListRoles/index.js\";\nimport { CreateRoleUseCase } from \"~/features/security/roles/CreateRole/index.js\";\nimport { DeleteRoleUseCase } from \"~/features/security/roles/DeleteRole/index.js\";\n\nclass RolesInstallerImpl implements AppInstaller.Interface {\n readonly alwaysRun = true;\n readonly appName = \"Security\";\n readonly dependsOn = [];\n private createdRoles: Role[] = [];\n\n constructor(\n private listRolesUseCase: ListRolesUseCase.Interface,\n private createRoleUseCase: CreateRoleUseCase.Interface,\n private deleteRoleUseCase: DeleteRoleUseCase.Interface\n ) {}\n\n async install(): Promise<void> {\n const rolesResult = await this.listRolesUseCase.execute();\n const roles = rolesResult.value;\n\n if (!roles.find(g => g.slug === \"full-access\")) {\n const result = await this.createRoleUseCase.execute({\n name: \"Full Access\",\n description: \"Grants full access to all apps.\",\n system: true,\n slug: \"full-access\",\n permissions: [{ name: \"*\" }]\n });\n\n if (result.isFail()) {\n throw result.error;\n }\n\n this.createdRoles.push(result.value);\n }\n }\n\n async uninstall(): Promise<void> {\n for (const role of this.createdRoles) {\n await this.deleteRoleUseCase.execute(role.id);\n }\n }\n}\n\nexport const RoleInstaller = createImplementation({\n abstraction: AppInstaller,\n implementation: RolesInstallerImpl,\n dependencies: [ListRolesUseCase, CreateRoleUseCase, DeleteRoleUseCase]\n});\n"],"names":["RolesInstallerImpl","listRolesUseCase","createRoleUseCase","deleteRoleUseCase","rolesResult","roles","g","result","role","RoleInstaller","createImplementation","AppInstaller","ListRolesUseCase","CreateRoleUseCase","DeleteRoleUseCase"],"mappings":";;;;;AAOA,MAAMA;IAMF,YACYC,gBAA4C,EAC5CC,iBAA8C,EAC9CC,iBAA8C,CACxD;aAHUF,gBAAgB,GAAhBA;aACAC,iBAAiB,GAAjBA;aACAC,iBAAiB,GAAjBA;aARH,SAAS,GAAG;aACZ,OAAO,GAAG;aACV,SAAS,GAAG,EAAE;aACf,YAAY,GAAW,EAAE;IAM9B;IAEH,MAAM,UAAyB;QAC3B,MAAMC,cAAc,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO;QACvD,MAAMC,QAAQD,YAAY,KAAK;QAE/B,IAAI,CAACC,MAAM,IAAI,CAACC,CAAAA,IAAKA,AAAW,kBAAXA,EAAE,IAAI,GAAqB;YAC5C,MAAMC,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC;gBAChD,MAAM;gBACN,aAAa;gBACb,QAAQ;gBACR,MAAM;gBACN,aAAa;oBAAC;wBAAE,MAAM;oBAAI;iBAAE;YAChC;YAEA,IAAIA,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;YAGtB,IAAI,CAAC,YAAY,CAAC,IAAI,CAACA,OAAO,KAAK;QACvC;IACJ;IAEA,MAAM,YAA2B;QAC7B,KAAK,MAAMC,QAAQ,IAAI,CAAC,YAAY,CAChC,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACA,KAAK,EAAE;IAEpD;AACJ;AAEO,MAAMC,gBAAgBC,qBAAqB;IAC9C,aAAaC;IACb,gBAAgBX;IAChB,cAAc;QAACY;QAAkBC;QAAmBC;KAAkB;AAC1E"}
@@ -5,6 +5,7 @@ import { IdentityContext } from "../../IdentityContext/abstractions.js";
5
5
  import { EventPublisher } from "../../../eventPublisher/index.js";
6
6
  import { updateRoleValidation } from "./schema.js";
7
7
  import { RoleAfterUpdateEvent, RoleBeforeUpdateEvent } from "./events.js";
8
+ import { descriptionOnUpdate } from "../../shared/description.js";
8
9
  import { CannotUpdatePluginRolesError, NotAuthorizedError, RoleValidationError } from "../shared/errors.js";
9
10
  class UpdateRoleUseCaseImpl {
10
11
  constructor(repository, identityContext, eventPublisher){
@@ -23,21 +24,26 @@ class UpdateRoleUseCaseImpl {
23
24
  if (existingResult.isFail()) return Result.fail(existingResult.error);
24
25
  const existingRole = existingResult.value;
25
26
  if (existingRole.plugin) return Result.fail(new CannotUpdatePluginRolesError());
27
+ const { description, ...rest } = validation.data;
28
+ const changes = {
29
+ ...rest,
30
+ ...descriptionOnUpdate(description)
31
+ };
26
32
  const updatedRole = {
27
33
  ...existingRole,
28
- ...validation.data
34
+ ...changes
29
35
  };
30
36
  await this.eventPublisher.publish(new RoleBeforeUpdateEvent({
31
37
  original: existingRole,
32
38
  updated: updatedRole,
33
- input: validation.data
39
+ input: changes
34
40
  }));
35
41
  const result = await this.repository.update(updatedRole);
36
42
  if (result.isFail()) return Result.fail(result.error);
37
43
  await this.eventPublisher.publish(new RoleAfterUpdateEvent({
38
44
  original: existingRole,
39
45
  updated: updatedRole,
40
- input: validation.data
46
+ input: changes
41
47
  }));
42
48
  return Result.ok(updatedRole);
43
49
  }
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/roles/UpdateRole/UpdateRoleUseCase.js","sources":["../../../../../src/features/security/roles/UpdateRole/UpdateRoleUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UpdateRoleUseCase as UseCase } from \"./abstractions.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { updateRoleValidation } from \"./schema.js\";\nimport { RoleBeforeUpdateEvent, RoleAfterUpdateEvent } from \"./events.js\";\nimport type { Role, UpdateRoleInput } from \"../shared/types.js\";\nimport {\n NotAuthorizedError,\n CannotUpdatePluginRolesError,\n RoleValidationError\n} from \"../shared/errors.js\";\n\nclass UpdateRoleUseCaseImpl implements UseCase.Interface {\n private repository: RolesRepository.Interface;\n private identityContext: IdentityContext.Interface;\n private eventPublisher: EventPublisher.Interface;\n\n constructor(\n repository: RolesRepository.Interface,\n identityContext: IdentityContext.Interface,\n eventPublisher: EventPublisher.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n this.eventPublisher = eventPublisher;\n }\n\n async execute(id: string, input: UpdateRoleInput): Promise<Result<Role, UseCase.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.role\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const validation = updateRoleValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new RoleValidationError(validation.error.issues[0].message));\n }\n\n const existingResult = await this.repository.get({ id });\n if (existingResult.isFail()) {\n return Result.fail(existingResult.error);\n }\n\n const existingRole = existingResult.value;\n\n // Check if role is created via plugin\n if (existingRole.plugin) {\n return Result.fail(new CannotUpdatePluginRolesError());\n }\n\n const updatedRole: Role = {\n ...existingRole,\n ...validation.data\n };\n\n await this.eventPublisher.publish(\n new RoleBeforeUpdateEvent({\n original: existingRole,\n updated: updatedRole,\n input: validation.data\n })\n );\n\n const result = await this.repository.update(updatedRole);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new RoleAfterUpdateEvent({\n original: existingRole,\n updated: updatedRole,\n input: validation.data\n })\n );\n\n return Result.ok(updatedRole);\n }\n}\n\nexport const UpdateRoleUseCase = UseCase.createImplementation({\n implementation: UpdateRoleUseCaseImpl,\n dependencies: [RolesRepository, IdentityContext, EventPublisher]\n});\n"],"names":["UpdateRoleUseCaseImpl","repository","identityContext","eventPublisher","id","input","hasPermission","Result","NotAuthorizedError","validation","updateRoleValidation","RoleValidationError","existingResult","existingRole","CannotUpdatePluginRolesError","updatedRole","RoleBeforeUpdateEvent","result","RoleAfterUpdateEvent","UpdateRoleUseCase","UseCase","RolesRepository","IdentityContext","EventPublisher"],"mappings":";;;;;;;;AAcA,MAAMA;IAKF,YACIC,UAAqC,EACrCC,eAA0C,EAC1CC,cAAwC,CAC1C;QACE,IAAI,CAAC,UAAU,GAAGF;QAClB,IAAI,CAAC,eAAe,GAAGC;QACvB,IAAI,CAAC,cAAc,GAAGC;IAC1B;IAEA,MAAM,QAAQC,EAAU,EAAEC,KAAsB,EAAwC;QACpF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,aAAaC,qBAAqB,SAAS,CAACL;QAClD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,oBAAoBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGjF,MAAMG,iBAAiB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAER;QAAG;QACtD,IAAIQ,eAAe,MAAM,IACrB,OAAOL,OAAO,IAAI,CAACK,eAAe,KAAK;QAG3C,MAAMC,eAAeD,eAAe,KAAK;QAGzC,IAAIC,aAAa,MAAM,EACnB,OAAON,OAAO,IAAI,CAAC,IAAIO;QAG3B,MAAMC,cAAoB;YACtB,GAAGF,YAAY;YACf,GAAGJ,WAAW,IAAI;QACtB;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIO,sBAAsB;YACtB,UAAUH;YACV,SAASE;YACT,OAAON,WAAW,IAAI;QAC1B;QAGJ,MAAMQ,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACF;QAE5C,IAAIE,OAAO,MAAM,IACb,OAAOV,OAAO,IAAI,CAACU,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,qBAAqB;YACrB,UAAUL;YACV,SAASE;YACT,OAAON,WAAW,IAAI;QAC1B;QAGJ,OAAOF,OAAO,EAAE,CAACQ;IACrB;AACJ;AAEO,MAAMI,sCAAoBC,kBAAAA,oBAA4B,CAAC;IAC1D,gBAAgBpB;IAChB,cAAc;QAACqB;QAAiBC;QAAiBC;KAAe;AACpE"}
1
+ {"version":3,"file":"features/security/roles/UpdateRole/UpdateRoleUseCase.js","sources":["../../../../../src/features/security/roles/UpdateRole/UpdateRoleUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UpdateRoleUseCase as UseCase } from \"./abstractions.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { updateRoleValidation } from \"./schema.js\";\nimport { RoleBeforeUpdateEvent, RoleAfterUpdateEvent } from \"./events.js\";\nimport type { Role, UpdateRoleInput } from \"../shared/types.js\";\nimport { descriptionOnUpdate } from \"../../shared/description.js\";\nimport {\n NotAuthorizedError,\n CannotUpdatePluginRolesError,\n RoleValidationError\n} from \"../shared/errors.js\";\n\nclass UpdateRoleUseCaseImpl implements UseCase.Interface {\n private repository: RolesRepository.Interface;\n private identityContext: IdentityContext.Interface;\n private eventPublisher: EventPublisher.Interface;\n\n constructor(\n repository: RolesRepository.Interface,\n identityContext: IdentityContext.Interface,\n eventPublisher: EventPublisher.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n this.eventPublisher = eventPublisher;\n }\n\n async execute(id: string, input: UpdateRoleInput): Promise<Result<Role, UseCase.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.role\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const validation = updateRoleValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new RoleValidationError(validation.error.issues[0].message));\n }\n\n const existingResult = await this.repository.get({ id });\n if (existingResult.isFail()) {\n return Result.fail(existingResult.error);\n }\n\n const existingRole = existingResult.value;\n\n // Check if role is created via plugin\n if (existingRole.plugin) {\n return Result.fail(new CannotUpdatePluginRolesError());\n }\n\n // `description` is pulled out of the spread because it is the one field that accepts null.\n // Normalising it here keeps null out of both the entity and the published events, whose\n // input type declares `description?: string`.\n const { description, ...rest } = validation.data;\n\n const changes: UpdateRoleInput = {\n ...rest,\n ...descriptionOnUpdate(description)\n };\n\n const updatedRole: Role = {\n ...existingRole,\n ...changes\n };\n\n await this.eventPublisher.publish(\n new RoleBeforeUpdateEvent({\n original: existingRole,\n updated: updatedRole,\n input: changes\n })\n );\n\n const result = await this.repository.update(updatedRole);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new RoleAfterUpdateEvent({\n original: existingRole,\n updated: updatedRole,\n input: changes\n })\n );\n\n return Result.ok(updatedRole);\n }\n}\n\nexport const UpdateRoleUseCase = UseCase.createImplementation({\n implementation: UpdateRoleUseCaseImpl,\n dependencies: [RolesRepository, IdentityContext, EventPublisher]\n});\n"],"names":["UpdateRoleUseCaseImpl","repository","identityContext","eventPublisher","id","input","hasPermission","Result","NotAuthorizedError","validation","updateRoleValidation","RoleValidationError","existingResult","existingRole","CannotUpdatePluginRolesError","description","rest","changes","descriptionOnUpdate","updatedRole","RoleBeforeUpdateEvent","result","RoleAfterUpdateEvent","UpdateRoleUseCase","UseCase","RolesRepository","IdentityContext","EventPublisher"],"mappings":";;;;;;;;;AAeA,MAAMA;IAKF,YACIC,UAAqC,EACrCC,eAA0C,EAC1CC,cAAwC,CAC1C;QACE,IAAI,CAAC,UAAU,GAAGF;QAClB,IAAI,CAAC,eAAe,GAAGC;QACvB,IAAI,CAAC,cAAc,GAAGC;IAC1B;IAEA,MAAM,QAAQC,EAAU,EAAEC,KAAsB,EAAwC;QACpF,M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@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  export declare const updateRoleValidation: z.ZodObject<{
3
3
  name: z.ZodOptional<z.ZodString>;
4
- description: z.ZodOptional<z.ZodString>;
4
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
5
5
  permissions: z.ZodOptional<z.ZodArray<z.ZodObject<{
6
6
  name: z.ZodString;
7
7
  }, z.core.$loose>>>;
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  const updateRoleValidation = z.object({
3
3
  name: z.string().min(3).optional(),
4
- description: z.string().max(500).optional(),
4
+ description: z.string().max(500).nullish(),
5
5
  permissions: z.array(z.looseObject({
6
6
  name: z.string()
7
7
  })).optional()
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/roles/UpdateRole/schema.js","sources":["../../../../../src/features/security/roles/UpdateRole/schema.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const updateRoleValidation = z.object({\n name: z.string().min(3).optional(),\n description: z.string().max(500).optional(),\n permissions: z.array(z.looseObject({ name: z.string() })).optional()\n});\n"],"names":["updateRoleValidation","z"],"mappings":";AAEO,MAAMA,uBAAuBC,EAAE,MAAM,CAAC;IACzC,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,QAAQ;IAChC,aAAaA,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,QAAQ;IACzC,aAAaA,EAAE,KAAK,CAACA,EAAE,WAAW,CAAC;QAAE,MAAMA,EAAE,MAAM;IAAG,IAAI,QAAQ;AACtE"}
1
+ {"version":3,"file":"features/security/roles/UpdateRole/schema.js","sources":["../../../../../src/features/security/roles/UpdateRole/schema.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const updateRoleValidation = z.object({\n name: z.string().min(3).optional(),\n // Nullable in the GraphQL schema - see `descriptionOnUpdate` for why this is `.nullish()` and\n // must not carry a `.transform()`.\n description: z.string().max(500).nullish(),\n permissions: z.array(z.looseObject({ name: z.string() })).optional()\n});\n"],"names":["updateRoleValidation","z"],"mappings":";AAEO,MAAMA,uBAAuBC,EAAE,MAAM,CAAC;IACzC,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,QAAQ;IAGhC,aAAaA,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,OAAO;IACxC,aAAaA,EAAE,KAAK,CAACA,EAAE,WAAW,CAAC;QAAE,MAAMA,EAAE,MAAM;IAAG,IAAI,QAAQ;AACtE"}
@@ -0,0 +1,4 @@
1
+ export declare const descriptionOnCreate: (value: string | null | undefined) => string;
2
+ export declare const descriptionOnUpdate: (value: string | null | undefined) => {
3
+ description?: string;
4
+ };
@@ -0,0 +1,7 @@
1
+ const descriptionOnCreate = (value)=>value ?? "";
2
+ const descriptionOnUpdate = (value)=>void 0 === value ? {} : {
3
+ description: value ?? ""
4
+ };
5
+ export { descriptionOnCreate, descriptionOnUpdate };
6
+
7
+ //# sourceMappingURL=description.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/security/shared/description.js","sources":["../../../../src/features/security/shared/description.ts"],"sourcesContent":["// Roles, teams and API keys all declare `description: String` in the GraphQL schema - nullable -\n// while their domain types store a plain string and use \"\" to mean \"no description\". Clients\n// therefore legitimately send null, and the admin app does exactly that: it reads an entity saved\n// without a description and submits the edit form again unchanged.\n//\n// Zod's `.optional()` accepts only `undefined`, so those requests used to fail with\n// \"Invalid input: expected string, received null\". The input schemas use `.nullish()` instead, and\n// these two helpers map what comes out of them onto the domain type.\n//\n// Note the schemas must NOT do this mapping via `.transform()`: a transform makes the key required\n// in the parsed output rather than optional, so spreading a parsed update onto a stored entity\n// would write `description: undefined` and wipe the stored value on every partial update.\n\nexport const descriptionOnCreate = (value: string | null | undefined): string => value ?? \"\";\n\n// Returns a patch rather than a value, because on a partial update an absent `description` has to\n// leave the stored one alone, while an explicit null clears it.\nexport const descriptionOnUpdate = (value: string | null | undefined): { description?: string } =>\n value === undefined ? {} : { description: value ?? \"\" };\n"],"names":["descriptionOnCreate","value","descriptionOnUpdate","undefined"],"mappings":"AAaO,MAAMA,sBAAsB,CAACC,QAA6CA,SAAS;AAInF,MAAMC,sBAAsB,CAACD,QAChCA,AAAUE,WAAVF,QAAsB,CAAC,IAAI;QAAE,aAAaA,SAAS;IAAG"}
@@ -1,2 +1,3 @@
1
1
  export * from "./abstractions.js";
2
+ export * from "./description.js";
2
3
  export * from "./errors.js";
@@ -1,2 +1,3 @@
1
1
  export * from "./abstractions.js";
2
+ export * from "./description.js";
2
3
  export * from "./errors.js";
@@ -2,13 +2,15 @@ import { Result } from "@webiny/feature/api";
2
2
  import { EventPublisher } from "../../../../features/eventPublisher/index.js";
3
3
  import { CreateTeam } from "./abstractions.js";
4
4
  import { TeamsRepository } from "../shared/abstractions.js";
5
+ import { RolesRepository } from "../../roles/shared/abstractions.js";
5
6
  import { IdentityContext } from "../../IdentityContext/abstractions.js";
6
7
  import type { Team, CreateTeamInput } from "../shared/types.js";
7
8
  export declare class CreateTeamUseCase implements CreateTeam.Interface {
8
9
  private identityContext;
9
10
  private eventPublisher;
10
11
  private repository;
11
- constructor(identityContext: IdentityContext.Interface, eventPublisher: EventPublisher.Interface, repository: TeamsRepository.Interface);
12
+ private rolesRepository;
13
+ constructor(identityContext: IdentityContext.Interface, eventPublisher: EventPublisher.Interface, repository: TeamsRepository.Interface, rolesRepository: RolesRepository.Interface);
12
14
  execute(input: CreateTeamInput): Promise<Result<Team, CreateTeam.Error>>;
13
15
  }
14
16
  export declare const CreateTeamUseCaseImpl: import("@webiny/di").Implementation<typeof CreateTeamUseCase>;