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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/ApiCoreFeature.d.ts +2 -2
  2. package/ApiCoreFeature.js +23 -5
  3. package/ApiCoreFeature.js.map +1 -1
  4. package/exports/api.d.ts +2 -1
  5. package/exports/api.js +2 -1
  6. package/features/ai/feature.js +4 -0
  7. package/features/ai/feature.js.map +1 -1
  8. package/features/ai/index.d.ts +2 -0
  9. package/features/ai/index.js +1 -0
  10. package/features/ai/toolPipeline/AiOutputToolRegistry.d.ts +11 -0
  11. package/features/ai/toolPipeline/AiOutputToolRegistry.js +31 -0
  12. package/features/ai/toolPipeline/AiOutputToolRegistry.js.map +1 -0
  13. package/features/ai/toolPipeline/AiToolPipelineRunner.d.ts +10 -0
  14. package/features/ai/toolPipeline/AiToolPipelineRunner.js +36 -0
  15. package/features/ai/toolPipeline/AiToolPipelineRunner.js.map +1 -0
  16. package/features/ai/toolPipeline/abstractions.d.ts +23 -0
  17. package/features/ai/toolPipeline/abstractions.js +7 -0
  18. package/features/ai/toolPipeline/abstractions.js.map +1 -0
  19. package/features/ai/toolPipeline/index.d.ts +2 -0
  20. package/features/ai/toolPipeline/index.js +1 -0
  21. package/features/hashing/ScryptHasher.d.ts +11 -0
  22. package/features/hashing/ScryptHasher.js +74 -0
  23. package/features/hashing/ScryptHasher.js.map +1 -0
  24. package/features/hashing/abstractions.d.ts +18 -0
  25. package/features/hashing/abstractions.js +5 -0
  26. package/features/hashing/abstractions.js.map +1 -0
  27. package/features/hashing/feature.d.ts +4 -0
  28. package/features/hashing/feature.js +11 -0
  29. package/features/hashing/feature.js.map +1 -0
  30. package/features/hashing/index.d.ts +2 -0
  31. package/features/hashing/index.js +1 -0
  32. package/features/requestContext/RawAuthToken.d.ts +14 -0
  33. package/features/requestContext/RawAuthToken.js +19 -0
  34. package/features/requestContext/RawAuthToken.js.map +1 -0
  35. package/features/requestContext/RawTenantId.d.ts +14 -0
  36. package/features/requestContext/RawTenantId.js +19 -0
  37. package/features/requestContext/RawTenantId.js.map +1 -0
  38. package/features/requestContext/RequestIdentityLoader.d.ts +19 -0
  39. package/features/requestContext/RequestIdentityLoader.js +26 -0
  40. package/features/requestContext/RequestIdentityLoader.js.map +1 -0
  41. package/features/requestContext/RequestTenantLoader.d.ts +18 -0
  42. package/features/requestContext/RequestTenantLoader.js +52 -0
  43. package/features/requestContext/RequestTenantLoader.js.map +1 -0
  44. package/features/requestContext/abstractions.d.ts +53 -0
  45. package/features/requestContext/abstractions.js +8 -0
  46. package/features/requestContext/abstractions.js.map +1 -0
  47. package/features/requestContext/feature.d.ts +11 -0
  48. package/features/requestContext/feature.js +17 -0
  49. package/features/requestContext/feature.js.map +1 -0
  50. package/features/requestContext/index.d.ts +2 -0
  51. package/features/requestContext/index.js +2 -0
  52. package/features/security/apiKeys/ApiKeyAuthenticator.d.ts +14 -0
  53. package/features/security/apiKeys/ApiKeyAuthenticator.js +36 -0
  54. package/features/security/apiKeys/ApiKeyAuthenticator.js.map +1 -0
  55. package/features/security/apiKeys/ApiKeyAuthorizer.d.ts +10 -0
  56. package/features/security/apiKeys/ApiKeyAuthorizer.js +15 -0
  57. package/features/security/apiKeys/ApiKeyAuthorizer.js.map +1 -0
  58. package/features/security/apiKeys/feature.js +4 -0
  59. package/features/security/apiKeys/feature.js.map +1 -1
  60. package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.d.ts +1 -1
  61. package/features/security/utils/getPermissionsFromRoles.d.ts +1 -1
  62. package/features/serviceDiscovery/ServiceDiscovery.d.ts +17 -0
  63. package/features/serviceDiscovery/ServiceDiscovery.js +22 -0
  64. package/features/serviceDiscovery/ServiceDiscovery.js.map +1 -0
  65. package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.d.ts +1 -0
  66. package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.js +111 -0
  67. package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.js.map +1 -0
  68. package/features/serviceDiscovery/index.d.ts +3 -0
  69. package/features/serviceDiscovery/index.js +1 -0
  70. package/features/storageOperations/abstractions.d.ts +21 -0
  71. package/features/storageOperations/abstractions.js +10 -0
  72. package/features/storageOperations/abstractions.js.map +1 -0
  73. package/features/tenancy/CreateTenant/CreateTenantUseCase.d.ts +1 -1
  74. package/features/tenancy/InstallTenant/InstallTenantUseCase.d.ts +1 -1
  75. package/features/tenancy/UpdateTenant/UpdateTenantUseCase.d.ts +2 -2
  76. package/features/users/CreateUser/decorators/CreateUserWithWcpIncrement.d.ts +1 -1
  77. package/features/wcp/WcpContext/WcpContext.d.ts +4 -5
  78. package/features/wcp/WcpContext/WcpContext.js +5 -2
  79. package/features/wcp/WcpContext/WcpContext.js.map +1 -1
  80. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +8 -8
  81. package/features/wcp/WcpContext/feature.d.ts +1 -2
  82. package/features/wcp/WcpContext/feature.js +2 -2
  83. package/features/wcp/WcpContext/feature.js.map +1 -1
  84. package/features/wcp/WcpContext/index.d.ts +0 -1
  85. package/features/wcp/WcpContext/types.d.ts +0 -4
  86. package/features/wcp/WcpFeature.d.ts +1 -1
  87. package/features/wcp/WcpFeature.js +5 -2
  88. package/features/wcp/WcpFeature.js.map +1 -1
  89. package/features/wcp/WcpLicenseProvider.d.ts +29 -0
  90. package/features/wcp/WcpLicenseProvider.js +18 -0
  91. package/features/wcp/WcpLicenseProvider.js.map +1 -0
  92. package/features/wcp/loadWcpLicense.d.ts +2 -0
  93. package/{legacy/wcp/context.js → features/wcp/loadWcpLicense.js} +24 -19
  94. package/features/wcp/loadWcpLicense.js.map +1 -0
  95. package/graphql/ApiCoreSchemaFactory.d.ts +15 -0
  96. package/graphql/ApiCoreSchemaFactory.js +52 -0
  97. package/graphql/ApiCoreSchemaFactory.js.map +1 -0
  98. package/graphql/security/NotAuthorizedResponse.d.ts +1 -1
  99. package/graphql/security/NotAuthorizedResponse.js +1 -1
  100. package/graphql/security/NotAuthorizedResponse.js.map +1 -1
  101. package/graphql/security/SecuritySchemaFactory.d.ts +14 -0
  102. package/graphql/security/SecuritySchemaFactory.js +23 -0
  103. package/graphql/security/SecuritySchemaFactory.js.map +1 -0
  104. package/graphql/security/addApiKeySchema.d.ts +2 -0
  105. package/graphql/security/{apiKey.gql.js → addApiKeySchema.js} +45 -27
  106. package/graphql/security/addApiKeySchema.js.map +1 -0
  107. package/graphql/security/addIdentitySchema.d.ts +2 -0
  108. package/graphql/security/{identity.gql.js → addIdentitySchema.js} +52 -35
  109. package/graphql/security/addIdentitySchema.js.map +1 -0
  110. package/graphql/security/addRoleSchema.d.ts +2 -0
  111. package/graphql/security/addRoleSchema.js +137 -0
  112. package/graphql/security/addRoleSchema.js.map +1 -0
  113. package/graphql/security/addSecurityBaseSchema.d.ts +2 -0
  114. package/graphql/security/{base.gql.js → addSecurityBaseSchema.js} +14 -16
  115. package/graphql/security/addSecurityBaseSchema.js.map +1 -0
  116. package/graphql/security/addTeamSchema.d.ts +2 -0
  117. package/graphql/security/addTeamSchema.js +157 -0
  118. package/graphql/security/addTeamSchema.js.map +1 -0
  119. package/graphql/system/SystemSchemaFactory.d.ts +9 -0
  120. package/graphql/system/SystemSchemaFactory.js +66 -0
  121. package/graphql/system/SystemSchemaFactory.js.map +1 -0
  122. package/graphql/users/UsersSchemaFactory.d.ts +9 -0
  123. package/graphql/users/UsersSchemaFactory.js +191 -0
  124. package/graphql/users/UsersSchemaFactory.js.map +1 -0
  125. package/graphql/wcp/WcpSchemaFactory.d.ts +9 -0
  126. package/graphql/wcp/{graphql.js → WcpSchemaFactory.js} +26 -18
  127. package/graphql/wcp/WcpSchemaFactory.js.map +1 -0
  128. package/index.d.ts +3 -1
  129. package/index.js +3 -1
  130. package/package.json +19 -22
  131. package/types/core.d.ts +17 -5
  132. package/types/security.d.ts +0 -6
  133. package/types/tenancy.d.ts +0 -17
  134. package/types/users.d.ts +0 -13
  135. package/createApiCore.d.ts +0 -7
  136. package/createApiCore.js +0 -22
  137. package/createApiCore.js.map +0 -1
  138. package/graphql/security/apiKey.gql.d.ts +0 -4
  139. package/graphql/security/apiKey.gql.js.map +0 -1
  140. package/graphql/security/base.gql.d.ts +0 -4
  141. package/graphql/security/base.gql.js.map +0 -1
  142. package/graphql/security/identity.gql.d.ts +0 -4
  143. package/graphql/security/identity.gql.js.map +0 -1
  144. package/graphql/security/index.d.ts +0 -1
  145. package/graphql/security/index.js +0 -15
  146. package/graphql/security/index.js.map +0 -1
  147. package/graphql/security/role.gql.d.ts +0 -4
  148. package/graphql/security/role.gql.js +0 -106
  149. package/graphql/security/role.gql.js.map +0 -1
  150. package/graphql/security/team.gql.d.ts +0 -4
  151. package/graphql/security/team.gql.js +0 -119
  152. package/graphql/security/team.gql.js.map +0 -1
  153. package/graphql/system/createSystemGraphQL.d.ts +0 -2
  154. package/graphql/system/createSystemGraphQL.js +0 -54
  155. package/graphql/system/createSystemGraphQL.js.map +0 -1
  156. package/graphql/users/user.gql.d.ts +0 -3
  157. package/graphql/users/user.gql.js +0 -167
  158. package/graphql/users/user.gql.js.map +0 -1
  159. package/graphql/wcp/graphql.d.ts +0 -2
  160. package/graphql/wcp/graphql.js.map +0 -1
  161. package/legacy/security/LegacyContext.d.ts +0 -36
  162. package/legacy/security/LegacyContext.js +0 -152
  163. package/legacy/security/LegacyContext.js.map +0 -1
  164. package/legacy/security/createSecurityContext.d.ts +0 -3
  165. package/legacy/security/createSecurityContext.js +0 -10
  166. package/legacy/security/createSecurityContext.js.map +0 -1
  167. package/legacy/security/plugins/apiKeyAuthentication.d.ts +0 -7
  168. package/legacy/security/plugins/apiKeyAuthentication.js +0 -20
  169. package/legacy/security/plugins/apiKeyAuthentication.js.map +0 -1
  170. package/legacy/security/plugins/apiKeyAuthorization.d.ts +0 -6
  171. package/legacy/security/plugins/apiKeyAuthorization.js +0 -13
  172. package/legacy/security/plugins/apiKeyAuthorization.js.map +0 -1
  173. package/legacy/security/plugins/authenticateUsingCookie.d.ts +0 -5
  174. package/legacy/security/plugins/authenticateUsingCookie.js +0 -23
  175. package/legacy/security/plugins/authenticateUsingCookie.js.map +0 -1
  176. package/legacy/security/plugins/authenticateUsingHttpHeader.d.ts +0 -5
  177. package/legacy/security/plugins/authenticateUsingHttpHeader.js +0 -20
  178. package/legacy/security/plugins/authenticateUsingHttpHeader.js.map +0 -1
  179. package/legacy/security/plugins/secureHeaders.d.ts +0 -1
  180. package/legacy/security/plugins/secureHeaders.js +0 -30
  181. package/legacy/security/plugins/secureHeaders.js.map +0 -1
  182. package/legacy/tenancy/LegacyContext.d.ts +0 -15
  183. package/legacy/tenancy/LegacyContext.js +0 -57
  184. package/legacy/tenancy/LegacyContext.js.map +0 -1
  185. package/legacy/tenancy/createTenancyContext.d.ts +0 -3
  186. package/legacy/tenancy/createTenancyContext.js +0 -31
  187. package/legacy/tenancy/createTenancyContext.js.map +0 -1
  188. package/legacy/users/LegacyContext.d.ts +0 -13
  189. package/legacy/users/LegacyContext.js +0 -55
  190. package/legacy/users/LegacyContext.js.map +0 -1
  191. package/legacy/users/createAdminUsersContext.d.ts +0 -3
  192. package/legacy/users/createAdminUsersContext.js +0 -12
  193. package/legacy/users/createAdminUsersContext.js.map +0 -1
  194. package/legacy/wcp/LegacyWcpContext.d.ts +0 -33
  195. package/legacy/wcp/LegacyWcpContext.js +0 -84
  196. package/legacy/wcp/LegacyWcpContext.js.map +0 -1
  197. package/legacy/wcp/context.d.ts +0 -5
  198. package/legacy/wcp/context.js.map +0 -1
@@ -1,152 +0,0 @@
1
- import { AuthenticationContext } from "../../features/security/authentication/AuthenticationContext/index.js";
2
- import { Authenticator } from "../../features/security/authentication/Authenticator/index.js";
3
- import { Authorizer } from "../../features/security/authorization/Authorizer/abstractions.js";
4
- import { AuthenticatedIdentity, IdentityContext } from "../../features/security/IdentityContext/index.js";
5
- import { GetRoleUseCase } from "../../features/security/roles/GetRole/index.js";
6
- import { ListRolesUseCase } from "../../features/security/roles/ListRoles/index.js";
7
- import { CreateRoleUseCase } from "../../features/security/roles/CreateRole/index.js";
8
- import { UpdateRoleUseCase } from "../../features/security/roles/UpdateRole/index.js";
9
- import { DeleteRoleUseCase } from "../../features/security/roles/DeleteRole/index.js";
10
- import { GetTeamUseCase } from "../../features/security/teams/GetTeam/index.js";
11
- import { ListTeamsUseCase } from "../../features/security/teams/ListTeams/index.js";
12
- import { CreateTeam } from "../../features/security/teams/CreateTeam/index.js";
13
- import { UpdateTeam } from "../../features/security/teams/UpdateTeam/index.js";
14
- import { DeleteTeam } from "../../features/security/teams/DeleteTeam/index.js";
15
- class LegacyContext {
16
- constructor(container){
17
- this.container = container;
18
- }
19
- get identityContext() {
20
- return this.container.resolve(IdentityContext);
21
- }
22
- get authenticationContext() {
23
- return this.container.resolve(AuthenticationContext);
24
- }
25
- addAuthenticator(authenticator) {
26
- this.container.registerFactory(Authenticator, ()=>({
27
- authenticate (token) {
28
- return authenticator(token);
29
- }
30
- }));
31
- }
32
- async authenticate(token) {
33
- const identity = await this.authenticationContext.authenticate(token);
34
- this.identityContext.setIdentity(identity);
35
- }
36
- getIdentity() {
37
- const identity = this.identityContext.getIdentity();
38
- if (identity.isAnonymous()) return;
39
- return identity;
40
- }
41
- setIdentity(identity) {
42
- if (!identity) return void this.identityContext.setIdentity(void 0);
43
- const { id, displayName, type, ...rest } = identity;
44
- const authenticatedIdentity = new AuthenticatedIdentity({
45
- id,
46
- displayName,
47
- type,
48
- ...rest
49
- });
50
- this.identityContext.setIdentity(authenticatedIdentity);
51
- }
52
- getToken() {
53
- return this.authenticationContext.getAuthToken();
54
- }
55
- isAuthorizationEnabled() {
56
- return this.identityContext.isAuthorizationEnabled();
57
- }
58
- withoutAuthorization(cb) {
59
- return this.identityContext.withoutAuthorization(cb);
60
- }
61
- withIdentity(identity, cb) {
62
- if (!identity) return this.identityContext.withIdentity(void 0, cb);
63
- const { id, displayName, type, ...rest } = identity;
64
- const authenticatedIdentity = new AuthenticatedIdentity({
65
- id,
66
- displayName,
67
- type,
68
- ...rest
69
- });
70
- return this.identityContext.withIdentity(authenticatedIdentity, cb);
71
- }
72
- async getPermission(permission) {
73
- return this.identityContext.getPermission(permission);
74
- }
75
- async getPermissions(permission) {
76
- return this.identityContext.getPermissions(permission);
77
- }
78
- async listPermissions() {
79
- return this.identityContext.listPermissions();
80
- }
81
- async hasFullAccess() {
82
- return this.identityContext.hasFullAccess();
83
- }
84
- async getRole(params) {
85
- const useCase = this.container.resolve(GetRoleUseCase);
86
- const result = await useCase.execute(params.where);
87
- if (result.isFail()) throw result.error;
88
- return result.value;
89
- }
90
- async listRoles(params) {
91
- const useCase = this.container.resolve(ListRolesUseCase);
92
- const result = await useCase.execute(params);
93
- if (result.isFail()) throw result.error;
94
- return result.value;
95
- }
96
- async createRole(input) {
97
- const useCase = this.container.resolve(CreateRoleUseCase);
98
- const result = await useCase.execute(input);
99
- if (result.isFail()) throw result.error;
100
- return result.value;
101
- }
102
- async updateRole(id, input) {
103
- const useCase = this.container.resolve(UpdateRoleUseCase);
104
- const result = await useCase.execute(id, input);
105
- if (result.isFail()) throw result.error;
106
- return result.value;
107
- }
108
- async deleteRole(id) {
109
- const useCase = this.container.resolve(DeleteRoleUseCase);
110
- const result = await useCase.execute(id);
111
- if (result.isFail()) throw result.error;
112
- }
113
- addAuthorizer(authorizer) {
114
- this.container.registerFactory(Authorizer, ()=>({
115
- authorize () {
116
- return authorizer();
117
- }
118
- }));
119
- }
120
- async getTeam(params) {
121
- const useCase = this.container.resolve(GetTeamUseCase);
122
- const result = await useCase.execute(params.where);
123
- if (result.isFail()) throw result.error;
124
- return result.value;
125
- }
126
- async listTeams(params) {
127
- const useCase = this.container.resolve(ListTeamsUseCase);
128
- const result = await useCase.execute(params);
129
- if (result.isFail()) throw result.error;
130
- return result.value;
131
- }
132
- async createTeam(input) {
133
- const useCase = this.container.resolve(CreateTeam);
134
- const result = await useCase.execute(input);
135
- if (result.isFail()) throw result.error;
136
- return result.value;
137
- }
138
- async updateTeam(id, input) {
139
- const useCase = this.container.resolve(UpdateTeam);
140
- const result = await useCase.execute(id, input);
141
- if (result.isFail()) throw result.error;
142
- return result.value;
143
- }
144
- async deleteTeam(id) {
145
- const useCase = this.container.resolve(DeleteTeam);
146
- const result = await useCase.execute(id);
147
- if (result.isFail()) throw result.error;
148
- }
149
- }
150
- export { LegacyContext };
151
-
152
- //# sourceMappingURL=LegacyContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy/security/LegacyContext.js","sources":["../../../src/legacy/security/LegacyContext.ts"],"sourcesContent":["import { type Container } from \"@webiny/di\";\nimport type { SecurityIdentity, SecurityPermission } from \"~/types/security.js\";\nimport { AuthenticationContext } from \"~/features/security/authentication/AuthenticationContext/index.js\";\nimport { Authenticator } from \"~/features/security/authentication/Authenticator/index.js\";\nimport { Authorizer } from \"~/features/security/authorization/Authorizer/abstractions.js\";\nimport {\n AuthenticatedIdentity,\n IdentityContext,\n IdentityData\n} from \"~/features/security/IdentityContext/index.js\";\nimport { GetRoleUseCase } from \"~/features/security/roles/GetRole/index.js\";\nimport { ListRolesUseCase } from \"~/features/security/roles/ListRoles/index.js\";\nimport { CreateRoleUseCase } from \"~/features/security/roles/CreateRole/index.js\";\nimport { UpdateRoleUseCase } from \"~/features/security/roles/UpdateRole/index.js\";\nimport { DeleteRoleUseCase } from \"~/features/security/roles/DeleteRole/index.js\";\nimport { GetTeamUseCase } from \"~/features/security/teams/GetTeam/index.js\";\nimport { ListTeamsUseCase } from \"~/features/security/teams/ListTeams/index.js\";\nimport { CreateTeam } from \"~/features/security/teams/CreateTeam/index.js\";\nimport { UpdateTeam } from \"~/features/security/teams/UpdateTeam/index.js\";\nimport { DeleteTeam } from \"~/features/security/teams/DeleteTeam/index.js\";\n\n/**\n * Legacy bridge that implements the old Security interface.\n * As we implement each phase, we'll replace forwarding with delegation.\n */\nexport class LegacyContext {\n constructor(private container: Container) {}\n\n private get identityContext() {\n return this.container.resolve(IdentityContext);\n }\n\n private get authenticationContext() {\n return this.container.resolve(AuthenticationContext);\n }\n\n addAuthenticator(authenticator: Authenticator.Interface[\"authenticate\"]): void {\n this.container.registerFactory(Authenticator, () => {\n return {\n authenticate(token: string): Promise<IdentityData | null> {\n return authenticator(token);\n }\n };\n });\n }\n\n async authenticate(token: string): Promise<void> {\n // Authenticate using new context\n const identity = await this.authenticationContext.authenticate(token);\n\n // Set identity in IdentityContext\n this.identityContext.setIdentity(identity);\n }\n\n getIdentity(): SecurityIdentity {\n const identity = this.identityContext.getIdentity();\n\n // Convert our Identity class to old SecurityIdentity format\n if (identity.isAnonymous()) {\n return undefined as any;\n }\n\n return identity;\n }\n\n setIdentity(identity: SecurityIdentity): void {\n if (!identity) {\n this.identityContext.setIdentity(undefined);\n return;\n }\n\n // Wrap old identity format in AuthenticatedIdentity\n const { id, displayName, type, ...rest } = identity;\n const authenticatedIdentity = new AuthenticatedIdentity({\n id,\n displayName,\n type,\n ...rest\n });\n\n this.identityContext.setIdentity(authenticatedIdentity);\n }\n\n getToken() {\n return this.authenticationContext.getAuthToken();\n }\n\n isAuthorizationEnabled(): boolean {\n return this.identityContext.isAuthorizationEnabled();\n }\n\n withoutAuthorization<T = any>(cb: () => Promise<T>): Promise<T> {\n return this.identityContext.withoutAuthorization(cb);\n }\n\n withIdentity<T = any>(\n identity: SecurityIdentity | undefined,\n cb: () => Promise<T>\n ): Promise<T> {\n if (!identity) {\n return this.identityContext.withIdentity(undefined, cb);\n }\n\n const { id, displayName, type, ...rest } = identity;\n const authenticatedIdentity = new AuthenticatedIdentity({\n id,\n displayName,\n type,\n ...rest\n });\n\n return this.identityContext.withIdentity(authenticatedIdentity, cb);\n }\n\n async getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n permission: string\n ) {\n return this.identityContext.getPermission<TPermission>(permission);\n }\n\n async getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n permission: string\n ) {\n return this.identityContext.getPermissions<TPermission>(permission);\n }\n\n async listPermissions() {\n return this.identityContext.listPermissions();\n }\n\n async hasFullAccess(): Promise<boolean> {\n return this.identityContext.hasFullAccess();\n }\n\n async getRole(params: any) {\n const useCase = this.container.resolve(GetRoleUseCase);\n const result = await useCase.execute(params.where);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async listRoles(params?: any) {\n const useCase = this.container.resolve(ListRolesUseCase);\n const result = await useCase.execute(params);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async createRole(input: any) {\n const useCase = this.container.resolve(CreateRoleUseCase);\n const result = await useCase.execute(input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async updateRole(id: string, input: any) {\n const useCase = this.container.resolve(UpdateRoleUseCase);\n const result = await useCase.execute(id, input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async deleteRole(id: string) {\n const useCase = this.container.resolve(DeleteRoleUseCase);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw result.error;\n }\n }\n\n addAuthorizer(authorizer: any) {\n // @ts-expect-error\n this.container.registerFactory(Authorizer, () => {\n return {\n authorize(): Promise<Permissions[]> {\n return authorizer();\n }\n };\n });\n }\n\n async getTeam(params: any) {\n const useCase = this.container.resolve(GetTeamUseCase);\n const result = await useCase.execute(params.where);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async listTeams(params?: any) {\n const useCase = this.container.resolve(ListTeamsUseCase);\n const result = await useCase.execute(params);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async createTeam(input: any) {\n const useCase = this.container.resolve(CreateTeam);\n const result = await useCase.execute(input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async updateTeam(id: string, input: any) {\n const useCase = this.container.resolve(UpdateTeam);\n const result = await useCase.execute(id, input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async deleteTeam(id: string) {\n const useCase = this.container.resolve(DeleteTeam);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw result.error;\n }\n }\n}\n"],"names":["LegacyContext","container","IdentityContext","AuthenticationContext","authenticator","Authenticator","token","identity","undefined","id","displayName","type","rest","authenticatedIdentity","AuthenticatedIdentity","cb","permission","params","useCase","GetRoleUseCase","result","ListRolesUseCase","input","CreateRoleUseCase","UpdateRoleUseCase","DeleteRoleUseCase","authorizer","Authorizer","GetTeamUseCase","ListTeamsUseCase","CreateTeam","UpdateTeam","DeleteTeam"],"mappings":"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"}
@@ -1,3 +0,0 @@
1
- import { ContextPlugin } from "@webiny/api";
2
- import type { ApiCoreContext } from "../../types/core.js";
3
- export declare const createSecurityContext: () => ContextPlugin<ApiCoreContext>;
@@ -1,10 +0,0 @@
1
- import { ContextPlugin } from "@webiny/api";
2
- import { LegacyContext } from "./LegacyContext.js";
3
- import { createSecurityGraphQL } from "../../graphql/security/index.js";
4
- const createSecurityContext = ()=>new ContextPlugin(async (context)=>{
5
- context.security = new LegacyContext(context.container);
6
- context.plugins.register(createSecurityGraphQL());
7
- });
8
- export { createSecurityContext };
9
-
10
- //# sourceMappingURL=createSecurityContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy/security/createSecurityContext.js","sources":["../../../src/legacy/security/createSecurityContext.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { LegacyContext } from \"~/legacy/security/LegacyContext.js\";\nimport { createSecurityGraphQL } from \"~/graphql/security/index.js\";\n\nexport const createSecurityContext = () => {\n return new ContextPlugin<ApiCoreContext>(async context => {\n // Create a legacy context that delegates to new features\n context.security = new LegacyContext(context.container);\n\n // Register GraphQL plugins\n context.plugins.register(createSecurityGraphQL());\n });\n};\n"],"names":["createSecurityContext","ContextPlugin","context","LegacyContext","createSecurityGraphQL"],"mappings":";;;AAKO,MAAMA,wBAAwB,IAC1B,IAAIC,cAA8B,OAAMC;QAE3CA,QAAQ,QAAQ,GAAG,IAAIC,cAAcD,QAAQ,SAAS;QAGtDA,QAAQ,OAAO,CAAC,QAAQ,CAACE;IAC7B"}
@@ -1,7 +0,0 @@
1
- import { ContextPlugin } from "@webiny/api";
2
- import type { ApiCoreContext } from "../../../types/core.js";
3
- export interface Config {
4
- identityType?: string;
5
- }
6
- declare const _default: ({ identityType }: Config) => ContextPlugin<ApiCoreContext>;
7
- export default _default;
@@ -1,20 +0,0 @@
1
- import { ContextPlugin } from "@webiny/api";
2
- import { ApiKeysRepository } from "../../../features/security/apiKeys/shared/abstractions.js";
3
- const apiKeyAuthentication = ({ identityType })=>new ContextPlugin((context)=>{
4
- context.security.addAuthenticator(async (token)=>{
5
- if ("string" != typeof token || !token.startsWith("wat_")) return null;
6
- const repository = context.container.resolve(ApiKeysRepository);
7
- const result = await repository.getByToken(token);
8
- if (!result.isOk()) return null;
9
- const apiKey = result.value;
10
- return {
11
- id: apiKey.id,
12
- displayName: apiKey.name,
13
- type: identityType || "api-key",
14
- permissions: apiKey.permissions
15
- };
16
- });
17
- });
18
- export default apiKeyAuthentication;
19
-
20
- //# sourceMappingURL=apiKeyAuthentication.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy/security/plugins/apiKeyAuthentication.js","sources":["../../../../src/legacy/security/plugins/apiKeyAuthentication.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { ApiKeysRepository } from \"~/features/security/apiKeys/shared/abstractions.js\";\n\nexport interface Config {\n identityType?: string;\n}\n\nexport default ({ identityType }: Config) => {\n return new ContextPlugin<ApiCoreContext>(context => {\n context.security.addAuthenticator(async token => {\n if (typeof token !== \"string\" || !token.startsWith(\"wat_\")) {\n return null;\n }\n\n const repository = context.container.resolve(ApiKeysRepository);\n const result = await repository.getByToken(token);\n\n if (!result.isOk()) {\n return null;\n }\n\n const apiKey = result.value;\n\n return {\n id: apiKey.id,\n displayName: apiKey.name,\n type: identityType || \"api-key\",\n // Add permissions directly to the identity so we don't have to load them\n // again when authorization kicks in.\n permissions: apiKey.permissions\n };\n });\n });\n};\n"],"names":["identityType","ContextPlugin","context","token","repository","ApiKeysRepository","result","apiKey"],"mappings":";;AAQA,6BAAgB,GAAEA,YAAY,EAAU,GAC7B,IAAIC,cAA8BC,CAAAA;QACrCA,QAAQ,QAAQ,CAAC,gBAAgB,CAAC,OAAMC;YACpC,IAAI,AAAiB,YAAjB,OAAOA,SAAsB,CAACA,MAAM,UAAU,CAAC,SAC/C,OAAO;YAGX,MAAMC,aAAaF,QAAQ,SAAS,CAAC,OAAO,CAACG;YAC7C,MAAMC,SAAS,MAAMF,WAAW,UAAU,CAACD;YAE3C,IAAI,CAACG,OAAO,IAAI,IACZ,OAAO;YAGX,MAAMC,SAASD,OAAO,KAAK;YAE3B,OAAO;gBACH,IAAIC,OAAO,EAAE;gBACb,aAAaA,OAAO,IAAI;gBACxB,MAAMP,gBAAgB;gBAGtB,aAAaO,OAAO,WAAW;YACnC;QACJ;IACJ"}
@@ -1,6 +0,0 @@
1
- import type { ApiCoreContext } from "../../../types/core.js";
2
- export interface Config {
3
- identityType?: string;
4
- }
5
- declare const _default: (config: Config) => import("@webiny/api").ContextPlugin<ApiCoreContext>;
6
- export default _default;
@@ -1,13 +0,0 @@
1
- import { createContextPlugin } from "@webiny/api";
2
- const apiKeyAuthorization = (config)=>createContextPlugin(({ security })=>{
3
- security.addAuthorizer(async ()=>{
4
- const identityType = config.identityType || "api-key";
5
- const identity = security.getIdentity();
6
- if (!identity || identity.type !== identityType) return null;
7
- if (false === Array.isArray(identity.permissions)) return [];
8
- return identity.permissions;
9
- });
10
- });
11
- export default apiKeyAuthorization;
12
-
13
- //# sourceMappingURL=apiKeyAuthorization.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy/security/plugins/apiKeyAuthorization.js","sources":["../../../../src/legacy/security/plugins/apiKeyAuthorization.ts"],"sourcesContent":["import { createContextPlugin } from \"@webiny/api\";\nimport type { SecurityPermission } from \"~/types/security.js\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\n\nexport interface Config {\n identityType?: string;\n}\n\nexport default (config: Config) => {\n return createContextPlugin<ApiCoreContext>(({ security }) => {\n security.addAuthorizer(async () => {\n const identityType = config.identityType || \"api-key\";\n\n const identity = security.getIdentity();\n\n if (!identity || identity.type !== identityType) {\n return null;\n }\n // We can expect `permissions` to exist on the identity, because api-key authentication\n // plugin sets them on the identity instance to avoid loading them from DB here.\n if (Array.isArray(identity.permissions) === false) {\n return [];\n }\n return identity.permissions as SecurityPermission[];\n });\n });\n};\n"],"names":["config","createContextPlugin","security","identityType","identity","Array"],"mappings":";AAQA,4BAAgB,CAAAA,SACLC,oBAAoC,CAAC,EAAEC,QAAQ,EAAE;QACpDA,SAAS,aAAa,CAAC;YACnB,MAAMC,eAAeH,OAAO,YAAY,IAAI;YAE5C,MAAMI,WAAWF,SAAS,WAAW;YAErC,IAAI,CAACE,YAAYA,SAAS,IAAI,KAAKD,cAC/B,OAAO;YAIX,IAAIE,AAAwC,UAAxCA,MAAM,OAAO,CAACD,SAAS,WAAW,GAClC,OAAO,EAAE;YAEb,OAAOA,SAAS,WAAW;QAC/B;IACJ"}
@@ -1,5 +0,0 @@
1
- import type { ApiCoreContext } from "../../../types/core.js";
2
- /**
3
- * @internal
4
- */
5
- export declare function authenticateUsingCookie(): (import("@webiny/api").ContextPlugin<ApiCoreContext> | import("@webiny/handler").BeforeHandlerPlugin<ApiCoreContext>)[];
@@ -1,23 +0,0 @@
1
- import { createContextPlugin } from "@webiny/api";
2
- import { Request, createBeforeHandlerPlugin } from "@webiny/handler";
3
- import { SetIdTokenCookie } from "../../../features/security/authentication/AuthenticationContext/SetIdTokenCookie.js";
4
- function authenticateUsingCookie() {
5
- return [
6
- createBeforeHandlerPlugin(async (context)=>{
7
- const request = context.container.resolve(Request);
8
- const { cookies } = request;
9
- const token = cookies["wby-id-token"];
10
- if (!context.security.getIdentity() && token) try {
11
- await context.security.authenticate(token);
12
- } catch (err) {
13
- console.log(err);
14
- }
15
- }),
16
- createContextPlugin((context)=>{
17
- context.container.register(SetIdTokenCookie);
18
- })
19
- ];
20
- }
21
- export { authenticateUsingCookie };
22
-
23
- //# sourceMappingURL=authenticateUsingCookie.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy/security/plugins/authenticateUsingCookie.js","sources":["../../../../src/legacy/security/plugins/authenticateUsingCookie.ts"],"sourcesContent":["import { createContextPlugin } from \"@webiny/api\";\nimport { createBeforeHandlerPlugin, Request } from \"@webiny/handler\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { SetIdTokenCookie } from \"~/features/security/authentication/AuthenticationContext/SetIdTokenCookie.js\";\n\n/**\n * @internal\n */\nexport function authenticateUsingCookie() {\n return [\n createBeforeHandlerPlugin<ApiCoreContext>(async context => {\n const request = context.container.resolve(Request);\n const { cookies } = request;\n const token = cookies[\"wby-id-token\"];\n\n if (!context.security.getIdentity() && token) {\n try {\n await context.security.authenticate(token);\n } catch (err) {\n console.log(err);\n }\n }\n }),\n\n createContextPlugin<ApiCoreContext>(context => {\n context.container.register(SetIdTokenCookie);\n })\n ];\n}\n"],"names":["authenticateUsingCookie","createBeforeHandlerPlugin","context","request","Request","cookies","token","err","console","createContextPlugin","SetIdTokenCookie"],"mappings":";;;AAQO,SAASA;IACZ,OAAO;QACHC,0BAA0C,OAAMC;YAC5C,MAAMC,UAAUD,QAAQ,SAAS,CAAC,OAAO,CAACE;YAC1C,MAAM,EAAEC,OAAO,EAAE,GAAGF;YACpB,MAAMG,QAAQD,OAAO,CAAC,eAAe;YAErC,IAAI,CAACH,QAAQ,QAAQ,CAAC,WAAW,MAAMI,OACnC,IAAI;gBACA,MAAMJ,QAAQ,QAAQ,CAAC,YAAY,CAACI;YACxC,EAAE,OAAOC,KAAK;gBACVC,QAAQ,GAAG,CAACD;YAChB;QAER;QAEAE,oBAAoCP,CAAAA;YAChCA,QAAQ,SAAS,CAAC,QAAQ,CAACQ;QAC/B;KACH;AACL"}
@@ -1,5 +0,0 @@
1
- import type { ApiCoreContext } from "../../../types/core.js";
2
- export interface GetHeader {
3
- (context: ApiCoreContext): string | null | undefined;
4
- }
5
- export declare const authenticateUsingHttpHeader: () => (import("@webiny/handler").BeforeHandlerPlugin<ApiCoreContext> | (import("@webiny/api/index.js").ContextPlugin<ApiCoreContext> | import("@webiny/handler").BeforeHandlerPlugin<ApiCoreContext>)[] | import("@webiny/handler").HandlerOnRequestPlugin<import("@webiny/handler/types.js").Context>)[];
@@ -1,20 +0,0 @@
1
- import { Request, createBeforeHandlerPlugin } from "@webiny/handler";
2
- import { authenticateUsingCookie } from "./authenticateUsingCookie.js";
3
- import { setupSecureHeaders } from "./secureHeaders.js";
4
- const getHeader = (context)=>{
5
- const request = context.container.resolve(Request);
6
- const header = request.headers["authorization"];
7
- return header ? header.split(" ").pop() : null;
8
- };
9
- const authenticateUsingHttpHeader = ()=>[
10
- createBeforeHandlerPlugin(async (context)=>{
11
- const token = getHeader(context);
12
- if (!token) return;
13
- await context.security.authenticate(token);
14
- }),
15
- setupSecureHeaders(),
16
- authenticateUsingCookie()
17
- ];
18
- export { authenticateUsingHttpHeader };
19
-
20
- //# sourceMappingURL=authenticateUsingHttpHeader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy/security/plugins/authenticateUsingHttpHeader.js","sources":["../../../../src/legacy/security/plugins/authenticateUsingHttpHeader.ts"],"sourcesContent":["import { createBeforeHandlerPlugin, Request } from \"@webiny/handler\";\nimport { authenticateUsingCookie } from \"./authenticateUsingCookie.js\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { setupSecureHeaders } from \"./secureHeaders.js\";\n\nexport interface GetHeader {\n (context: ApiCoreContext): string | null | undefined;\n}\n\nconst getHeader: GetHeader = context => {\n const request = context.container.resolve(Request);\n const header = request.headers[\"authorization\"];\n\n return header ? header.split(\" \").pop() : null;\n};\n\nexport const authenticateUsingHttpHeader = () => {\n return [\n createBeforeHandlerPlugin<ApiCoreContext>(async context => {\n const token = getHeader(context);\n\n if (!token) {\n return;\n }\n\n await context.security.authenticate(token);\n }),\n // Configure strict headers (this is also a requirement to use cookies).\n setupSecureHeaders(),\n // Finally, we add cookie-based authentication.\n authenticateUsingCookie()\n ];\n};\n"],"names":["getHeader","context","request","Request","header","authenticateUsingHttpHeader","createBeforeHandlerPlugin","token","setupSecureHeaders","authenticateUsingCookie"],"mappings":";;;AASA,MAAMA,YAAuBC,CAAAA;IACzB,MAAMC,UAAUD,QAAQ,SAAS,CAAC,OAAO,CAACE;IAC1C,MAAMC,SAASF,QAAQ,OAAO,CAAC,gBAAgB;IAE/C,OAAOE,SAASA,OAAO,KAAK,CAAC,KAAK,GAAG,KAAK;AAC9C;AAEO,MAAMC,8BAA8B,IAChC;QACHC,0BAA0C,OAAML;YAC5C,MAAMM,QAAQP,UAAUC;YAExB,IAAI,CAACM,OACD;YAGJ,MAAMN,QAAQ,QAAQ,CAAC,YAAY,CAACM;QACxC;QAEAC;QAEAC;KACH"}
@@ -1 +0,0 @@
1
- export declare const setupSecureHeaders: () => import("@webiny/handler").HandlerOnRequestPlugin<import("@webiny/handler/types").Context>;
@@ -1,30 +0,0 @@
1
- import { ResponseHeaders, createHandlerOnRequest } from "@webiny/handler";
2
- const whitelistedHeaders = [
3
- "accept",
4
- "authorization",
5
- "cache-control",
6
- "content-type",
7
- "x-tenant",
8
- "x-apollo-tracing",
9
- "apollo-query-plan-experimental"
10
- ];
11
- const setupSecureHeaders = ()=>createHandlerOnRequest(async (request, reply)=>{
12
- const isOptions = "OPTIONS" === request.method;
13
- const headers = ResponseHeaders.create();
14
- headers.set("access-control-allow-origin", request.headers["origin"]);
15
- headers.set("access-control-allow-credentials", "true");
16
- if (isOptions) {
17
- headers.set("cache-control", "public, max-age=86400");
18
- headers.set("content-type", "application/json; charset=utf-8");
19
- headers.set("access-control-max-age", "86400");
20
- headers.set("access-control-allow-methods", "OPTIONS,POST,GET,DELETE,PUT,PATCH");
21
- headers.set("access-control-allow-headers", whitelistedHeaders.join(", "));
22
- } else {
23
- headers.set("x-tenant", request.headers["x-tenant"] || "root");
24
- headers.set("vary", "origin");
25
- }
26
- reply.headers(headers.getHeaders());
27
- });
28
- export { setupSecureHeaders };
29
-
30
- //# sourceMappingURL=secureHeaders.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy/security/plugins/secureHeaders.js","sources":["../../../../src/legacy/security/plugins/secureHeaders.ts"],"sourcesContent":["import { createHandlerOnRequest, ResponseHeaders } from \"@webiny/handler\";\n\nconst whitelistedHeaders = [\n \"accept\",\n \"authorization\",\n \"cache-control\",\n \"content-type\",\n \"x-tenant\",\n \"x-apollo-tracing\",\n \"apollo-query-plan-experimental\"\n];\n\nexport const setupSecureHeaders = () => {\n return createHandlerOnRequest(async (request, reply) => {\n const isOptions = request.method === \"OPTIONS\";\n\n const headers = ResponseHeaders.create();\n headers.set(\"access-control-allow-origin\", request.headers[\"origin\"]);\n headers.set(\"access-control-allow-credentials\", \"true\");\n\n if (isOptions) {\n headers.set(\"cache-control\", \"public, max-age=86400\");\n headers.set(\"content-type\", \"application/json; charset=utf-8\");\n headers.set(\"access-control-max-age\", \"86400\");\n headers.set(\"access-control-allow-methods\", \"OPTIONS,POST,GET,DELETE,PUT,PATCH\");\n headers.set(\"access-control-allow-headers\", whitelistedHeaders.join(\", \"));\n } else {\n headers.set(\"x-tenant\", request.headers[\"x-tenant\"] || \"root\");\n headers.set(\"vary\", \"origin\");\n }\n\n reply.headers(headers.getHeaders());\n });\n};\n"],"names":["whitelistedHeaders","setupSecureHeaders","createHandlerOnRequest","request","reply","isOptions","headers","ResponseHeaders"],"mappings":";AAEA,MAAMA,qBAAqB;IACvB;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAEM,MAAMC,qBAAqB,IACvBC,uBAAuB,OAAOC,SAASC;QAC1C,MAAMC,YAAYF,AAAmB,cAAnBA,QAAQ,MAAM;QAEhC,MAAMG,UAAUC,gBAAgB,MAAM;QACtCD,QAAQ,GAAG,CAAC,+BAA+BH,QAAQ,OAAO,CAAC,SAAS;QACpEG,QAAQ,GAAG,CAAC,oCAAoC;QAEhD,IAAID,WAAW;YACXC,QAAQ,GAAG,CAAC,iBAAiB;YAC7BA,QAAQ,GAAG,CAAC,gBAAgB;YAC5BA,QAAQ,GAAG,CAAC,0BAA0B;YACtCA,QAAQ,GAAG,CAAC,gCAAgC;YAC5CA,QAAQ,GAAG,CAAC,gCAAgCN,mBAAmB,IAAI,CAAC;QACxE,OAAO;YACHM,QAAQ,GAAG,CAAC,YAAYH,QAAQ,OAAO,CAAC,WAAW,IAAI;YACvDG,QAAQ,GAAG,CAAC,QAAQ;QACxB;QAEAF,MAAM,OAAO,CAACE,QAAQ,UAAU;IACpC"}
@@ -1,15 +0,0 @@
1
- import { Container } from "@webiny/di";
2
- import type { CreateTenantInput, ListTenantsParams, Tenancy, Tenant } from "../../types/tenancy.js";
3
- export declare class LegacyContext implements Tenancy {
4
- private container;
5
- constructor(container: Container);
6
- createTenant(data: CreateTenantInput): Promise<Tenant>;
7
- getCurrentTenant(): Tenant;
8
- getRootTenant(): Promise<Tenant>;
9
- getTenantById(id: string): Promise<Tenant>;
10
- listTenants(params?: ListTenantsParams): Promise<Tenant[]>;
11
- setCurrentTenant(tenant: Tenant): void;
12
- withEachTenant<TReturn>(tenants: Tenant[], cb: (tenant: Tenant) => Promise<TReturn>): Promise<TReturn[]>;
13
- withRootTenant<T>(cb: () => T): Promise<T>;
14
- withTenant<TReturn>(tenant: Tenant, cb: (tenant: Tenant) => Promise<TReturn>): Promise<TReturn>;
15
- }
@@ -1,57 +0,0 @@
1
- import { CreateTenantUseCase } from "../../features/tenancy/CreateTenant/abstractions.js";
2
- import { GetRootTenantUseCase } from "../../features/tenancy/GetRootTenant/abstractions.js";
3
- import { GetTenantByIdUseCase } from "../../features/tenancy/GetTenantById/abstractions.js";
4
- import { ListTenantsUseCase } from "../../features/tenancy/ListTenants/abstractions.js";
5
- import { TenantContext } from "../../features/tenancy/TenantContext/abstractions.js";
6
- class LegacyContext {
7
- constructor(container){
8
- this.container = container;
9
- }
10
- async createTenant(data) {
11
- const useCase = this.container.resolve(CreateTenantUseCase);
12
- const result = await useCase.execute(data);
13
- if (result.isFail()) throw result.error;
14
- return result.value;
15
- }
16
- getCurrentTenant() {
17
- const tenantContext = this.container.resolve(TenantContext);
18
- return tenantContext.getTenant();
19
- }
20
- async getRootTenant() {
21
- const useCase = this.container.resolve(GetRootTenantUseCase);
22
- const result = await useCase.execute();
23
- if (result.isFail()) throw result.error;
24
- return result.value;
25
- }
26
- async getTenantById(id) {
27
- const useCase = this.container.resolve(GetTenantByIdUseCase);
28
- const result = await useCase.execute(id);
29
- if (result.isFail()) throw result.error;
30
- return result.value;
31
- }
32
- async listTenants(params) {
33
- const useCase = this.container.resolve(ListTenantsUseCase);
34
- const result = await useCase.execute(params);
35
- if (result.isFail()) throw result.error;
36
- return result.value;
37
- }
38
- setCurrentTenant(tenant) {
39
- const tenantContext = this.container.resolve(TenantContext);
40
- tenantContext.setTenant(tenant);
41
- }
42
- async withEachTenant(tenants, cb) {
43
- const tenantContext = this.container.resolve(TenantContext);
44
- return tenantContext.withEachTenant(tenants, cb);
45
- }
46
- async withRootTenant(cb) {
47
- const tenantContext = this.container.resolve(TenantContext);
48
- return tenantContext.withRootTenant(cb);
49
- }
50
- async withTenant(tenant, cb) {
51
- const tenantContext = this.container.resolve(TenantContext);
52
- return tenantContext.withTenant(tenant, cb);
53
- }
54
- }
55
- export { LegacyContext };
56
-
57
- //# sourceMappingURL=LegacyContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy/tenancy/LegacyContext.js","sources":["../../../src/legacy/tenancy/LegacyContext.ts"],"sourcesContent":["import { Container } from \"@webiny/di\";\nimport type { CreateTenantInput, ListTenantsParams, Tenancy, Tenant } from \"~/types/tenancy.js\";\nimport { CreateTenantUseCase } from \"~/features/tenancy/CreateTenant/abstractions.js\";\nimport { GetRootTenantUseCase } from \"~/features/tenancy/GetRootTenant/abstractions.js\";\nimport { GetTenantByIdUseCase } from \"~/features/tenancy/GetTenantById/abstractions.js\";\nimport { ListTenantsUseCase } from \"~/features/tenancy/ListTenants/abstractions.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/abstractions.js\";\n\nexport class LegacyContext implements Tenancy {\n constructor(private container: Container) {}\n\n async createTenant(data: CreateTenantInput): Promise<Tenant> {\n const useCase = this.container.resolve(CreateTenantUseCase);\n const result = await useCase.execute(data);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n getCurrentTenant(): Tenant {\n const tenantContext = this.container.resolve(TenantContext);\n return tenantContext.getTenant();\n }\n\n async getRootTenant(): Promise<Tenant> {\n const useCase = this.container.resolve(GetRootTenantUseCase);\n const result = await useCase.execute();\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async getTenantById(id: string): Promise<Tenant> {\n const useCase = this.container.resolve(GetTenantByIdUseCase);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async listTenants(params?: ListTenantsParams): Promise<Tenant[]> {\n const useCase = this.container.resolve(ListTenantsUseCase);\n const result = await useCase.execute(params);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n setCurrentTenant(tenant: Tenant): void {\n const tenantContext = this.container.resolve(TenantContext);\n tenantContext.setTenant(tenant);\n }\n\n async withEachTenant<TReturn>(\n tenants: Tenant[],\n cb: (tenant: Tenant) => Promise<TReturn>\n ): Promise<TReturn[]> {\n const tenantContext = this.container.resolve(TenantContext);\n return tenantContext.withEachTenant(tenants, cb);\n }\n\n async withRootTenant<T>(cb: () => T): Promise<T> {\n const tenantContext = this.container.resolve(TenantContext);\n return tenantContext.withRootTenant(cb);\n }\n\n async withTenant<TReturn>(\n tenant: Tenant,\n cb: (tenant: Tenant) => Promise<TReturn>\n ): Promise<TReturn> {\n const tenantContext = this.container.resolve(TenantContext);\n return tenantContext.withTenant(tenant, cb);\n }\n}\n"],"names":["LegacyContext","container","data","useCase","CreateTenantUseCase","result","tenantContext","TenantContext","GetRootTenantUseCase","id","GetTenantByIdUseCase","params","ListTenantsUseCase","tenant","tenants","cb"],"mappings":";;;;;AAQO,MAAMA;IACT,YAAoBC,SAAoB,CAAE;aAAtBA,SAAS,GAATA;IAAuB;IAE3C,MAAM,aAAaC,IAAuB,EAAmB;QACzD,MAAMC,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QACvC,MAAMC,SAAS,MAAMF,QAAQ,OAAO,CAACD;QAErC,IAAIG,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,mBAA2B;QACvB,MAAMC,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC7C,OAAOD,cAAc,SAAS;IAClC;IAEA,MAAM,gBAAiC;QACnC,MAAMH,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACK;QACvC,MAAMH,SAAS,MAAMF,QAAQ,OAAO;QAEpC,IAAIE,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,cAAcI,EAAU,EAAmB;QAC7C,MAAMN,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACO;QACvC,MAAML,SAAS,MAAMF,QAAQ,OAAO,CAACM;QAErC,IAAIJ,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,YAAYM,MAA0B,EAAqB;QAC7D,MAAMR,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACS;QACvC,MAAMP,SAAS,MAAMF,QAAQ,OAAO,CAACQ;QAErC,IAAIN,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,iBAAiBQ,MAAc,EAAQ;QACnC,MAAMP,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC7CD,cAAc,SAAS,CAACO;IAC5B;IAEA,MAAM,eACFC,OAAiB,EACjBC,EAAwC,EACtB;QAClB,MAAMT,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC7C,OAAOD,cAAc,cAAc,CAACQ,SAASC;IACjD;IAEA,MAAM,eAAkBA,EAAW,EAAc;QAC7C,MAAMT,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC7C,OAAOD,cAAc,cAAc,CAACS;IACxC;IAEA,MAAM,WACFF,MAAc,EACdE,EAAwC,EACxB;QAChB,MAAMT,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC7C,OAAOD,cAAc,UAAU,CAACO,QAAQE;IAC5C;AACJ"}
@@ -1,3 +0,0 @@
1
- import { ContextPlugin } from "@webiny/api";
2
- import type { ApiCoreContext } from "../../types/core.js";
3
- export declare const createTenancyContext: () => ContextPlugin<ApiCoreContext>;
@@ -1,31 +0,0 @@
1
- import { ContextPlugin } from "@webiny/api";
2
- import { Request } from "@webiny/handler";
3
- import { GetTenantByIdUseCase } from "../../features/tenancy/GetTenantById/index.js";
4
- import { TenantContext } from "../../features/tenancy/TenantContext/index.js";
5
- import { LegacyContext } from "./LegacyContext.js";
6
- import { RootTenantValue } from "../../domain/tenancy/RootTenantValue.js";
7
- const createTenancyContext = ()=>new ContextPlugin(async (context)=>{
8
- let tenantId = "root";
9
- const request = context.container.resolve(Request);
10
- const multiTenancy = context.wcp.canUseFeature("multiTenancy");
11
- if (!request) throw new Error("MISSING CONTEXT REQUEST");
12
- if (multiTenancy) {
13
- const { headers = {} } = request;
14
- tenantId = headers["x-tenant"] ?? "root";
15
- }
16
- context.plugins.register({
17
- type: "wcp-telemetry-tracker"
18
- });
19
- const getTenantById = context.container.resolve(GetTenantByIdUseCase);
20
- const tenantContext = context.container.resolve(TenantContext);
21
- const tenantResult = await getTenantById.execute(tenantId);
22
- if (tenantResult.isOk()) tenantContext.setTenant(tenantResult.value);
23
- else {
24
- if ("root" !== tenantId) throw new Error("Unable to load tenant!");
25
- tenantContext.setTenant(RootTenantValue.create());
26
- }
27
- context.tenancy = new LegacyContext(context.container);
28
- });
29
- export { createTenancyContext };
30
-
31
- //# sourceMappingURL=createTenancyContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy/tenancy/createTenancyContext.js","sources":["../../../src/legacy/tenancy/createTenancyContext.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { Request } from \"@webiny/handler\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { GetTenantByIdUseCase } from \"~/features/tenancy/GetTenantById/index.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { LegacyContext } from \"~/legacy/tenancy/LegacyContext.js\";\nimport { RootTenantValue } from \"~/domain/tenancy/RootTenantValue.js\";\n\nexport const createTenancyContext = () => {\n return new ContextPlugin<ApiCoreContext>(async context => {\n let tenantId = \"root\";\n\n const request = context.container.resolve(Request);\n\n const multiTenancy = context.wcp.canUseFeature(\"multiTenancy\");\n if (!request) {\n throw new Error(\"MISSING CONTEXT REQUEST\");\n }\n\n if (multiTenancy) {\n const { headers = {} } = request;\n\n tenantId = (headers[\"x-tenant\"] as string) ?? \"root\";\n }\n\n // Add WCP telemetry identifier\n // This tenancy package is used by GraphQL, Headless CMS, and PB import/export functions\n context.plugins.register({ type: \"wcp-telemetry-tracker\" });\n\n // We need to load tenant, and set the current tenant context.\n const getTenantById = context.container.resolve(GetTenantByIdUseCase);\n const tenantContext = context.container.resolve(TenantContext);\n\n const tenantResult = await getTenantById.execute(tenantId);\n if (tenantResult.isOk()) {\n tenantContext.setTenant(tenantResult.value);\n } else {\n // If there's no `root` tenant, it means system installation wasn't finished yet.\n // But all other tenants should throw an error.\n if (tenantId !== \"root\") {\n throw new Error(\"Unable to load tenant!\");\n }\n\n // Mock root tenant so the system can bootstrap\n tenantContext.setTenant(RootTenantValue.create());\n }\n\n // Set up legacy context. We use this API in many places across our codebase, and this will provide\n // a working bridge until everything is migrated to use DI container.\n context.tenancy = new LegacyContext(context.container);\n });\n};\n"],"names":["createTenancyContext","ContextPlugin","context","tenantId","request","Request","multiTenancy","Error","headers","getTenantById","GetTenantByIdUseCase","tenantContext","TenantContext","tenantResult","RootTenantValue","LegacyContext"],"mappings":";;;;;;AAQO,MAAMA,uBAAuB,IACzB,IAAIC,cAA8B,OAAMC;QAC3C,IAAIC,WAAW;QAEf,MAAMC,UAAUF,QAAQ,SAAS,CAAC,OAAO,CAACG;QAE1C,MAAMC,eAAeJ,QAAQ,GAAG,CAAC,aAAa,CAAC;QAC/C,IAAI,CAACE,SACD,MAAM,IAAIG,MAAM;QAGpB,IAAID,cAAc;YACd,MAAM,EAAEE,UAAU,CAAC,CAAC,EAAE,GAAGJ;YAEzBD,WAAYK,OAAO,CAAC,WAAW,IAAe;QAClD;QAIAN,QAAQ,OAAO,CAAC,QAAQ,CAAC;YAAE,MAAM;QAAwB;QAGzD,MAAMO,gBAAgBP,QAAQ,SAAS,CAAC,OAAO,CAACQ;QAChD,MAAMC,gBAAgBT,QAAQ,SAAS,CAAC,OAAO,CAACU;QAEhD,MAAMC,eAAe,MAAMJ,cAAc,OAAO,CAACN;QACjD,IAAIU,aAAa,IAAI,IACjBF,cAAc,SAAS,CAACE,aAAa,KAAK;aACvC;YAGH,IAAIV,AAAa,WAAbA,UACA,MAAM,IAAII,MAAM;YAIpBI,cAAc,SAAS,CAACG,gBAAgB,MAAM;QAClD;QAIAZ,QAAQ,OAAO,GAAG,IAAIa,cAAcb,QAAQ,SAAS;IACzD"}
@@ -1,13 +0,0 @@
1
- import type { Container } from "@webiny/di";
2
- import type { Team } from "../../types/security.js";
3
- import type { AdminUsers, AdminUser, CreateUserInput, UpdateUserInput, GetUserParams, ListUsersParams } from "../../types/users.js";
4
- export declare class LegacyContext implements AdminUsers {
5
- private container;
6
- constructor(container: Container);
7
- getUser<TUser extends AdminUser = AdminUser>(params: GetUserParams): Promise<TUser>;
8
- listUsers<TUser extends AdminUser = AdminUser>(params?: ListUsersParams): Promise<TUser[]>;
9
- listUserTeams(id: string): Promise<Team[]>;
10
- createUser<TUser extends AdminUser = AdminUser>(data: CreateUserInput): Promise<TUser>;
11
- updateUser<TUser extends AdminUser = AdminUser>(id: string, data: UpdateUserInput): Promise<TUser>;
12
- deleteUser(id: string): Promise<void>;
13
- }
@@ -1,55 +0,0 @@
1
- import { GetUserUseCase } from "../../features/users/GetUser/index.js";
2
- import { ListUsersUseCase } from "../../features/users/ListUsers/index.js";
3
- import { ListUserTeamsUseCase } from "../../features/users/ListUserTeams/index.js";
4
- import { CreateUserUseCase } from "../../features/users/CreateUser/index.js";
5
- import { UpdateUserUseCase } from "../../features/users/UpdateUser/index.js";
6
- import { DeleteUserUseCase } from "../../features/users/DeleteUser/index.js";
7
- class LegacyContext {
8
- constructor(container){
9
- this.container = container;
10
- }
11
- async getUser(params) {
12
- const useCase = this.container.resolve(GetUserUseCase);
13
- let input;
14
- input = params.where.id ? {
15
- id: params.where.id
16
- } : {
17
- email: params.where.email
18
- };
19
- const result = await useCase.execute(input);
20
- if (result.isFail()) throw new Error(result.error.message);
21
- return result.value;
22
- }
23
- async listUsers(params) {
24
- const useCase = this.container.resolve(ListUsersUseCase);
25
- const result = await useCase.execute(params);
26
- if (result.isFail()) throw new Error(result.error.message);
27
- return result.value;
28
- }
29
- async listUserTeams(id) {
30
- const useCase = this.container.resolve(ListUserTeamsUseCase);
31
- const result = await useCase.execute(id);
32
- if (result.isFail()) throw new Error(result.error.message);
33
- return result.value;
34
- }
35
- async createUser(data) {
36
- const useCase = this.container.resolve(CreateUserUseCase);
37
- const result = await useCase.execute(data);
38
- if (result.isFail()) throw new Error(result.error.message);
39
- return result.value;
40
- }
41
- async updateUser(id, data) {
42
- const useCase = this.container.resolve(UpdateUserUseCase);
43
- const result = await useCase.execute(id, data);
44
- if (result.isFail()) throw new Error(result.error.message);
45
- return result.value;
46
- }
47
- async deleteUser(id) {
48
- const useCase = this.container.resolve(DeleteUserUseCase);
49
- const result = await useCase.execute(id);
50
- if (result.isFail()) throw new Error(result.error.message);
51
- }
52
- }
53
- export { LegacyContext };
54
-
55
- //# sourceMappingURL=LegacyContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"legacy/users/LegacyContext.js","sources":["../../../src/legacy/users/LegacyContext.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport type { Team } from \"~/types/security.js\";\nimport type {\n AdminUsers,\n AdminUser,\n CreateUserInput,\n UpdateUserInput,\n GetUserParams,\n ListUsersParams\n} from \"~/types/users.js\";\nimport { GetUserUseCase } from \"~/features/users/GetUser/index.js\";\nimport { ListUsersUseCase } from \"~/features/users/ListUsers/index.js\";\nimport { ListUserTeamsUseCase } from \"~/features/users/ListUserTeams/index.js\";\nimport { CreateUserUseCase } from \"~/features/users/CreateUser/index.js\";\nimport { UpdateUserUseCase } from \"~/features/users/UpdateUser/index.js\";\nimport { DeleteUserUseCase } from \"~/features/users/DeleteUser/index.js\";\nimport type { GetUserInput } from \"~/features/users/shared/types.js\";\n\nexport class LegacyContext implements AdminUsers {\n constructor(private container: Container) {}\n\n async getUser<TUser extends AdminUser = AdminUser>(params: GetUserParams): Promise<TUser> {\n const useCase = this.container.resolve(GetUserUseCase);\n let input: GetUserInput;\n if (params.where.id) {\n input = { id: params.where.id! };\n } else {\n input = { email: params.where.email! };\n }\n const result = await useCase.execute(input);\n\n if (result.isFail()) {\n throw new Error(result.error.message);\n }\n\n return result.value as TUser;\n }\n\n async listUsers<TUser extends AdminUser = AdminUser>(\n params?: ListUsersParams\n ): Promise<TUser[]> {\n const useCase = this.container.resolve(ListUsersUseCase);\n const result = await useCase.execute(params);\n\n if (result.isFail()) {\n throw new Error(result.error.message);\n }\n\n return result.value as TUser[];\n }\n\n async listUserTeams(id: string): Promise<Team[]> {\n const useCase = this.container.resolve(ListUserTeamsUseCase);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw new Error(result.error.message);\n }\n\n return result.value;\n }\n\n async createUser<TUser extends AdminUser = AdminUser>(data: CreateUserInput): Promise<TUser> {\n const useCase = this.container.resolve(CreateUserUseCase);\n const result = await useCase.execute(data);\n\n if (result.isFail()) {\n throw new Error(result.error.message);\n }\n\n return result.value as TUser;\n }\n\n async updateUser<TUser extends AdminUser = AdminUser>(\n id: string,\n data: UpdateUserInput\n ): Promise<TUser> {\n const useCase = this.container.resolve(UpdateUserUseCase);\n const result = await useCase.execute(id, data);\n\n if (result.isFail()) {\n throw new Error(result.error.message);\n }\n\n return result.value as TUser;\n }\n\n async deleteUser(id: string): Promise<void> {\n const useCase = this.container.resolve(DeleteUserUseCase);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw new Error(result.error.message);\n }\n }\n}\n"],"names":["LegacyContext","container","params","useCase","GetUserUseCase","input","result","Error","ListUsersUseCase","id","ListUserTeamsUseCase","data","CreateUserUseCase","UpdateUserUseCase","DeleteUserUseCase"],"mappings":";;;;;;AAkBO,MAAMA;IACT,YAAoBC,SAAoB,CAAE;aAAtBA,SAAS,GAATA;IAAuB;IAE3C,MAAM,QAA6CC,MAAqB,EAAkB;QACtF,MAAMC,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QACvC,IAAIC;QAEAA,QADAH,OAAO,KAAK,CAAC,EAAE,GACP;YAAE,IAAIA,OAAO,KAAK,CAAC,EAAE;QAAE,IAEvB;YAAE,OAAOA,OAAO,KAAK,CAAC,KAAK;QAAE;QAEzC,MAAMI,SAAS,MAAMH,QAAQ,OAAO,CAACE;QAErC,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIC,MAAMD,OAAO,KAAK,CAAC,OAAO;QAGxC,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,UACFJ,MAAwB,EACR;QAChB,MAAMC,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACK;QACvC,MAAMF,SAAS,MAAMH,QAAQ,OAAO,CAACD;QAErC,IAAII,OAAO,MAAM,IACb,MAAM,IAAIC,MAAMD,OAAO,KAAK,CAAC,OAAO;QAGxC,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,cAAcG,EAAU,EAAmB;QAC7C,MAAMN,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACO;QACvC,MAAMJ,SAAS,MAAMH,QAAQ,OAAO,CAACM;QAErC,IAAIH,OAAO,MAAM,IACb,MAAM,IAAIC,MAAMD,OAAO,KAAK,CAAC,OAAO;QAGxC,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WAAgDK,IAAqB,EAAkB;QACzF,MAAMR,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACS;QACvC,MAAMN,SAAS,MAAMH,QAAQ,OAAO,CAACQ;QAErC,IAAIL,OAAO,MAAM,IACb,MAAM,IAAIC,MAAMD,OAAO,KAAK,CAAC,OAAO;QAGxC,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WACFG,EAAU,EACVE,IAAqB,EACP;QACd,MAAMR,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACU;QACvC,MAAMP,SAAS,MAAMH,QAAQ,OAAO,CAACM,IAAIE;QAEzC,IAAIL,OAAO,MAAM,IACb,MAAM,IAAIC,MAAMD,OAAO,KAAK,CAAC,OAAO;QAGxC,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WAAWG,EAAU,EAAiB;QACxC,MAAMN,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACW;QACvC,MAAMR,SAAS,MAAMH,QAAQ,OAAO,CAACM;QAErC,IAAIH,OAAO,MAAM,IACb,MAAM,IAAIC,MAAMD,OAAO,KAAK,CAAC,OAAO;IAE5C;AACJ"}
@@ -1,3 +0,0 @@
1
- import { ContextPlugin } from "@webiny/api";
2
- import type { ApiCoreContext } from "../../types/core.js";
3
- export declare const createAdminUsersContext: () => ContextPlugin<ApiCoreContext>[];
@@ -1,12 +0,0 @@
1
- import { ContextPlugin } from "@webiny/api";
2
- import { LegacyContext } from "./LegacyContext.js";
3
- import { createUsersGraphQL } from "../../graphql/users/user.gql.js";
4
- const createAdminUsersContext = ()=>[
5
- new ContextPlugin(async (context)=>{
6
- context.adminUsers = new LegacyContext(context.container);
7
- context.plugins.register(createUsersGraphQL());
8
- })
9
- ];
10
- export { createAdminUsersContext };
11
-
12
- //# sourceMappingURL=createAdminUsersContext.js.map