@webiny/api-core 6.4.12-beta.5 → 6.5.0-beta.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 (143) hide show
  1. package/ApiCoreFeature.js +0 -2
  2. package/ApiCoreFeature.js.map +1 -1
  3. package/createApiCore.d.ts +1 -1
  4. package/createApiCore.js +9 -7
  5. package/createApiCore.js.map +1 -1
  6. package/exports/api/security/api-key.d.ts +1 -0
  7. package/exports/api/security/api-key.js +1 -0
  8. package/exports/api.d.ts +2 -1
  9. package/exports/api.js +1 -1
  10. package/features/ai/Ai.d.ts +3 -1
  11. package/features/ai/Ai.js +38 -3
  12. package/features/ai/Ai.js.map +1 -1
  13. package/features/ai/AiModelRegistry.js +3 -1
  14. package/features/ai/AiModelRegistry.js.map +1 -1
  15. package/features/ai/AnthropicSdkFactory.js +24 -4
  16. package/features/ai/AnthropicSdkFactory.js.map +1 -1
  17. package/features/ai/DEVELOPERS.md +126 -0
  18. package/features/ai/GoogleSdkFactory.d.ts +10 -0
  19. package/features/ai/GoogleSdkFactory.js +65 -0
  20. package/features/ai/GoogleSdkFactory.js.map +1 -0
  21. package/features/ai/OpenAiSdkFactory.js +67 -11
  22. package/features/ai/OpenAiSdkFactory.js.map +1 -1
  23. package/features/ai/TextExtractor/DefaultTextExtractor.d.ts +9 -0
  24. package/features/ai/TextExtractor/DefaultTextExtractor.js +28 -0
  25. package/features/ai/TextExtractor/DefaultTextExtractor.js.map +1 -0
  26. package/features/ai/TextExtractor/abstractions.d.ts +12 -0
  27. package/features/ai/TextExtractor/abstractions.js +5 -0
  28. package/features/ai/TextExtractor/abstractions.js.map +1 -0
  29. package/features/ai/TextExtractor/index.d.ts +3 -0
  30. package/features/ai/TextExtractor/index.js +2 -0
  31. package/features/ai/TextExtractor/parsers/docxParser.d.ts +1 -0
  32. package/features/ai/TextExtractor/parsers/docxParser.js +111 -0
  33. package/features/ai/TextExtractor/parsers/docxParser.js.map +1 -0
  34. package/features/ai/abstractions.d.ts +4 -0
  35. package/features/ai/abstractions.js.map +1 -1
  36. package/features/ai/events.d.ts +59 -0
  37. package/features/ai/events.js +41 -0
  38. package/features/ai/events.js.map +1 -0
  39. package/features/ai/feature.js +9 -1
  40. package/features/ai/feature.js.map +1 -1
  41. package/features/ai/index.d.ts +7 -1
  42. package/features/ai/index.js +3 -0
  43. package/features/ai/toolPipeline/AiOutputToolRegistry.d.ts +11 -0
  44. package/features/ai/toolPipeline/AiOutputToolRegistry.js +31 -0
  45. package/features/ai/toolPipeline/AiOutputToolRegistry.js.map +1 -0
  46. package/features/ai/toolPipeline/AiToolPipelineRunner.d.ts +10 -0
  47. package/features/ai/toolPipeline/AiToolPipelineRunner.js +36 -0
  48. package/features/ai/toolPipeline/AiToolPipelineRunner.js.map +1 -0
  49. package/features/ai/toolPipeline/abstractions.d.ts +23 -0
  50. package/features/ai/toolPipeline/abstractions.js +7 -0
  51. package/features/ai/toolPipeline/abstractions.js.map +1 -0
  52. package/features/ai/toolPipeline/index.d.ts +2 -0
  53. package/features/ai/toolPipeline/index.js +1 -0
  54. package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.d.ts +1 -1
  55. package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js.map +1 -1
  56. package/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.d.ts +1 -3
  57. package/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.js.map +1 -1
  58. package/features/security/apiKeys/GetApiKeyBySlug/abstractions.d.ts +1 -1
  59. package/features/security/apiKeys/GetApiKeyBySlug/abstractions.js.map +1 -1
  60. package/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.d.ts +1 -3
  61. package/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.js.map +1 -1
  62. package/features/security/apiKeys/GetApiKeyByToken/abstractions.d.ts +1 -1
  63. package/features/security/apiKeys/GetApiKeyByToken/abstractions.js.map +1 -1
  64. package/features/security/apiKeys/feature.js +7 -2
  65. package/features/security/apiKeys/feature.js.map +1 -1
  66. package/features/security/apiKeys/shared/ApiKeyProvider.d.ts +3 -5
  67. package/features/security/apiKeys/shared/ApiKeyProvider.js +6 -21
  68. package/features/security/apiKeys/shared/ApiKeyProvider.js.map +1 -1
  69. package/features/security/apiKeys/shared/ApiKeysRepository.d.ts +1 -0
  70. package/features/security/apiKeys/shared/ApiKeysRepository.js +19 -4
  71. package/features/security/apiKeys/shared/ApiKeysRepository.js.map +1 -1
  72. package/features/security/apiKeys/shared/generateToken.d.ts +1 -1
  73. package/features/security/apiKeys/shared/generateToken.js.map +1 -1
  74. package/features/security/apiKeys/shared/types.d.ts +1 -1
  75. package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.d.ts +1 -1
  76. package/features/security/utils/getPermissionsFromRoles.d.ts +1 -1
  77. package/features/serviceDiscovery/ServiceDiscovery.d.ts +17 -0
  78. package/features/serviceDiscovery/ServiceDiscovery.js +22 -0
  79. package/features/serviceDiscovery/ServiceDiscovery.js.map +1 -0
  80. package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.js +111 -0
  81. package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.js.map +1 -0
  82. package/features/serviceDiscovery/index.d.ts +3 -0
  83. package/features/serviceDiscovery/index.js +1 -0
  84. package/features/tenancy/CreateTenant/CreateTenantUseCase.d.ts +1 -1
  85. package/features/tenancy/InstallTenant/InstallTenantUseCase.d.ts +1 -1
  86. package/features/tenancy/UpdateTenant/UpdateTenantUseCase.d.ts +2 -2
  87. package/features/users/CreateUser/decorators/CreateUserWithWcpIncrement.d.ts +1 -1
  88. package/features/users/shared/loaders.js.map +1 -1
  89. package/features/wcp/WcpContext/WcpContext.d.ts +9 -0
  90. package/features/wcp/WcpContext/WcpContext.js +27 -0
  91. package/features/wcp/WcpContext/WcpContext.js.map +1 -1
  92. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +31 -5
  93. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +48 -2
  94. package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
  95. package/legacy/security/plugins/apiKeyAuthentication.d.ts +1 -1
  96. package/legacy/security/plugins/apiKeyAuthorization.d.ts +1 -1
  97. package/legacy/security/plugins/authenticateUsingCookie.d.ts +1 -1
  98. package/legacy/security/plugins/authenticateUsingHttpHeader.d.ts +1 -1
  99. package/legacy/security/plugins/secureHeaders.js +0 -1
  100. package/legacy/security/plugins/secureHeaders.js.map +1 -1
  101. package/legacy/wcp/LegacyWcpContext.d.ts +9 -0
  102. package/legacy/wcp/LegacyWcpContext.js +27 -0
  103. package/legacy/wcp/LegacyWcpContext.js.map +1 -1
  104. package/package.json +24 -25
  105. package/types/security.d.ts +1 -1
  106. package/features/debugger/Debugger.d.ts +0 -23
  107. package/features/debugger/Debugger.js +0 -134
  108. package/features/debugger/Debugger.js.map +0 -1
  109. package/features/debugger/GraphQLDebuggerTransport.d.ts +0 -26
  110. package/features/debugger/GraphQLDebuggerTransport.js +0 -45
  111. package/features/debugger/GraphQLDebuggerTransport.js.map +0 -1
  112. package/features/debugger/__tests__/matchNamespace.test.js +0 -67
  113. package/features/debugger/__tests__/matchNamespace.test.js.map +0 -1
  114. package/features/debugger/__tests__/serialize.test.d.ts +0 -1
  115. package/features/debugger/__tests__/serialize.test.js +0 -220
  116. package/features/debugger/__tests__/serialize.test.js.map +0 -1
  117. package/features/debugger/abstractions.d.ts +0 -100
  118. package/features/debugger/abstractions.js +0 -6
  119. package/features/debugger/abstractions.js.map +0 -1
  120. package/features/debugger/feature.d.ts +0 -5
  121. package/features/debugger/feature.js +0 -15
  122. package/features/debugger/feature.js.map +0 -1
  123. package/features/debugger/index.d.ts +0 -7
  124. package/features/debugger/index.js +0 -7
  125. package/features/debugger/limits.d.ts +0 -18
  126. package/features/debugger/limits.js +0 -11
  127. package/features/debugger/limits.js.map +0 -1
  128. package/features/debugger/matchNamespace.d.ts +0 -21
  129. package/features/debugger/matchNamespace.js +0 -48
  130. package/features/debugger/matchNamespace.js.map +0 -1
  131. package/features/debugger/permissions.d.ts +0 -33
  132. package/features/debugger/permissions.js +0 -12
  133. package/features/debugger/permissions.js.map +0 -1
  134. package/features/debugger/permissionsSchema.d.ts +0 -17
  135. package/features/debugger/permissionsSchema.js +0 -18
  136. package/features/debugger/permissionsSchema.js.map +0 -1
  137. package/features/debugger/plugins.d.ts +0 -4
  138. package/features/debugger/plugins.js +0 -82
  139. package/features/debugger/plugins.js.map +0 -1
  140. package/features/debugger/serialize.d.ts +0 -11
  141. package/features/debugger/serialize.js +0 -121
  142. package/features/debugger/serialize.js.map +0 -1
  143. /package/features/{debugger/__tests__/matchNamespace.test.d.ts → serviceDiscovery/__tests__/ServiceDiscovery.test.d.ts} +0 -0
@@ -0,0 +1,10 @@
1
+ import { type IAiOutputToolRegistry, type IAiToolPipelineRunner } from "./abstractions.js";
2
+ declare class AiToolPipelineRunnerImpl implements IAiToolPipelineRunner {
3
+ private registry;
4
+ constructor(registry: IAiOutputToolRegistry);
5
+ resolve(data: unknown): Promise<unknown>;
6
+ }
7
+ export declare const AiToolPipelineRunner: typeof AiToolPipelineRunnerImpl & {
8
+ __abstraction: import("@webiny/di").Abstraction<IAiToolPipelineRunner>;
9
+ };
10
+ export {};
@@ -0,0 +1,36 @@
1
+ import { AiOutputToolRegistry, AiToolPipelineRunner } from "./abstractions.js";
2
+ function isToolEnvelope(value) {
3
+ return "object" == typeof value && null !== value && "tool" in value && "string" == typeof value.tool && "params" in value && "object" == typeof value.params;
4
+ }
5
+ class AiToolPipelineRunnerImpl {
6
+ constructor(registry){
7
+ this.registry = registry;
8
+ }
9
+ async resolve(data) {
10
+ if (null == data) return data;
11
+ if (isToolEnvelope(data)) {
12
+ if (!this.registry.has(data.tool)) return data;
13
+ const result = await this.registry.invoke(data.tool, data.params);
14
+ return this.resolve(result);
15
+ }
16
+ if (Array.isArray(data)) return Promise.all(data.map((item)=>this.resolve(item)));
17
+ if ("object" == typeof data) {
18
+ const entries = Object.entries(data);
19
+ const resolvedValues = await Promise.all(entries.map(([, value])=>this.resolve(value)));
20
+ return Object.fromEntries(entries.map(([key], i)=>[
21
+ key,
22
+ resolvedValues[i]
23
+ ]));
24
+ }
25
+ return data;
26
+ }
27
+ }
28
+ const AiToolPipelineRunner_AiToolPipelineRunner = AiToolPipelineRunner.createImplementation({
29
+ implementation: AiToolPipelineRunnerImpl,
30
+ dependencies: [
31
+ AiOutputToolRegistry
32
+ ]
33
+ });
34
+ export { AiToolPipelineRunner_AiToolPipelineRunner as AiToolPipelineRunner };
35
+
36
+ //# sourceMappingURL=AiToolPipelineRunner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/toolPipeline/AiToolPipelineRunner.js","sources":["../../../../src/features/ai/toolPipeline/AiToolPipelineRunner.ts"],"sourcesContent":["import {\n AiOutputToolRegistry,\n AiToolPipelineRunner as Abstraction,\n type IAiOutputToolRegistry,\n type IAiToolPipelineRunner\n} from \"./abstractions.js\";\n\nfunction isToolEnvelope(\n value: unknown\n): value is { tool: string; params: Record<string, unknown> } {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"tool\" in value &&\n typeof (value as Record<string, unknown>).tool === \"string\" &&\n \"params\" in value &&\n typeof (value as Record<string, unknown>).params === \"object\"\n );\n}\n\nclass AiToolPipelineRunnerImpl implements IAiToolPipelineRunner {\n constructor(private registry: IAiOutputToolRegistry) {}\n\n async resolve(data: unknown): Promise<unknown> {\n if (data === null || data === undefined) {\n return data;\n }\n\n if (isToolEnvelope(data)) {\n if (!this.registry.has(data.tool)) {\n return data;\n }\n const result = await this.registry.invoke(data.tool, data.params);\n return this.resolve(result);\n }\n\n if (Array.isArray(data)) {\n return Promise.all(data.map(item => this.resolve(item)));\n }\n\n if (typeof data === \"object\") {\n const entries = Object.entries(data as Record<string, unknown>);\n const resolvedValues = await Promise.all(\n entries.map(([, value]) => this.resolve(value))\n );\n return Object.fromEntries(entries.map(([key], i) => [key, resolvedValues[i]]));\n }\n\n return data;\n }\n}\n\nexport const AiToolPipelineRunner = Abstraction.createImplementation({\n implementation: AiToolPipelineRunnerImpl,\n dependencies: [AiOutputToolRegistry]\n});\n"],"names":["isToolEnvelope","value","AiToolPipelineRunnerImpl","registry","data","result","Array","Promise","item","entries","Object","resolvedValues","key","i","AiToolPipelineRunner","Abstraction","AiOutputToolRegistry"],"mappings":";AAOA,SAASA,eACLC,KAAc;IAEd,OACI,AAAiB,YAAjB,OAAOA,SACPA,AAAU,SAAVA,SACA,UAAUA,SACV,AAAmD,YAAnD,OAAQA,MAAkC,IAAI,IAC9C,YAAYA,SACZ,AAAqD,YAArD,OAAQA,MAAkC,MAAM;AAExD;AAEA,MAAMC;IACF,YAAoBC,QAA+B,CAAE;aAAjCA,QAAQ,GAARA;IAAkC;IAEtD,MAAM,QAAQC,IAAa,EAAoB;QAC3C,IAAIA,QAAAA,MACA,OAAOA;QAGX,IAAIJ,eAAeI,OAAO;YACtB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACA,KAAK,IAAI,GAC5B,OAAOA;YAEX,MAAMC,SAAS,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAACD,KAAK,IAAI,EAAEA,KAAK,MAAM;YAChE,OAAO,IAAI,CAAC,OAAO,CAACC;QACxB;QAEA,IAAIC,MAAM,OAAO,CAACF,OACd,OAAOG,QAAQ,GAAG,CAACH,KAAK,GAAG,CAACI,CAAAA,OAAQ,IAAI,CAAC,OAAO,CAACA;QAGrD,IAAI,AAAgB,YAAhB,OAAOJ,MAAmB;YAC1B,MAAMK,UAAUC,OAAO,OAAO,CAACN;YAC/B,MAAMO,iBAAiB,MAAMJ,QAAQ,GAAG,CACpCE,QAAQ,GAAG,CAAC,CAAC,GAAGR,MAAM,GAAK,IAAI,CAAC,OAAO,CAACA;YAE5C,OAAOS,OAAO,WAAW,CAACD,QAAQ,GAAG,CAAC,CAAC,CAACG,IAAI,EAAEC,IAAM;oBAACD;oBAAKD,cAAc,CAACE,EAAE;iBAAC;QAChF;QAEA,OAAOT;IACX;AACJ;AAEO,MAAMU,4CAAuBC,qBAAAA,oBAAgC,CAAC;IACjE,gBAAgBb;IAChB,cAAc;QAACc;KAAqB;AACxC"}
@@ -0,0 +1,23 @@
1
+ export interface IAiOutputTool {
2
+ readonly name: string;
3
+ execute(params: Record<string, unknown>): Promise<unknown>;
4
+ }
5
+ export declare const AiOutputTool: import("@webiny/di").Abstraction<IAiOutputTool>;
6
+ export declare namespace AiOutputTool {
7
+ type Interface = IAiOutputTool;
8
+ }
9
+ export interface IAiOutputToolRegistry {
10
+ has(name: string): boolean;
11
+ invoke(name: string, params: Record<string, unknown>): Promise<unknown>;
12
+ }
13
+ export declare const AiOutputToolRegistry: import("@webiny/di").Abstraction<IAiOutputToolRegistry>;
14
+ export declare namespace AiOutputToolRegistry {
15
+ type Interface = IAiOutputToolRegistry;
16
+ }
17
+ export interface IAiToolPipelineRunner {
18
+ resolve(data: unknown): Promise<unknown>;
19
+ }
20
+ export declare const AiToolPipelineRunner: import("@webiny/di").Abstraction<IAiToolPipelineRunner>;
21
+ export declare namespace AiToolPipelineRunner {
22
+ type Interface = IAiToolPipelineRunner;
23
+ }
@@ -0,0 +1,7 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const AiOutputTool = createAbstraction("AiOutputTool");
3
+ const AiOutputToolRegistry = createAbstraction("AiOutputToolRegistry");
4
+ const AiToolPipelineRunner = createAbstraction("AiToolPipelineRunner");
5
+ export { AiOutputTool, AiOutputToolRegistry, AiToolPipelineRunner };
6
+
7
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/toolPipeline/abstractions.js","sources":["../../../../src/features/ai/toolPipeline/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IAiOutputTool {\n readonly name: string;\n execute(params: Record<string, unknown>): Promise<unknown>;\n}\n\nexport const AiOutputTool = createAbstraction<IAiOutputTool>(\"AiOutputTool\");\n\nexport namespace AiOutputTool {\n export type Interface = IAiOutputTool;\n}\n\nexport interface IAiOutputToolRegistry {\n has(name: string): boolean;\n invoke(name: string, params: Record<string, unknown>): Promise<unknown>;\n}\n\nexport const AiOutputToolRegistry =\n createAbstraction<IAiOutputToolRegistry>(\"AiOutputToolRegistry\");\n\nexport namespace AiOutputToolRegistry {\n export type Interface = IAiOutputToolRegistry;\n}\n\nexport interface IAiToolPipelineRunner {\n resolve(data: unknown): Promise<unknown>;\n}\n\nexport const AiToolPipelineRunner =\n createAbstraction<IAiToolPipelineRunner>(\"AiToolPipelineRunner\");\n\nexport namespace AiToolPipelineRunner {\n export type Interface = IAiToolPipelineRunner;\n}\n"],"names":["AiOutputTool","createAbstraction","AiOutputToolRegistry","AiToolPipelineRunner"],"mappings":";AAOO,MAAMA,eAAeC,kBAAiC;AAWtD,MAAMC,uBACTD,kBAAyC;AAUtC,MAAME,uBACTF,kBAAyC"}
@@ -0,0 +1,2 @@
1
+ export { AiOutputTool, AiOutputToolRegistry, AiToolPipelineRunner } from "./abstractions.js";
2
+ export type { IAiOutputTool, IAiOutputToolRegistry, IAiToolPipelineRunner } from "./abstractions.js";
@@ -0,0 +1 @@
1
+ export { AiOutputTool, AiOutputToolRegistry, AiToolPipelineRunner } from "./abstractions.js";
@@ -7,7 +7,7 @@ declare class GetApiKeyUseCaseImpl implements GetApiKeyUseCaseAbstraction.Interf
7
7
  private repository;
8
8
  private identityContext;
9
9
  constructor(repository: ApiKeysRepository.Interface, identityContext: IdentityContext.Interface);
10
- execute(id: string): Promise<Result<ApiKey | null, GetApiKeyUseCaseAbstraction.Error>>;
10
+ execute(id: string): Promise<Result<ApiKey, GetApiKeyUseCaseAbstraction.Error>>;
11
11
  }
12
12
  export declare const GetApiKeyUseCase: typeof GetApiKeyUseCaseImpl & {
13
13
  __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetApiKey>;
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetApiKeyUseCase as GetApiKeyUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport type { ApiKey } from \"../shared/types.js\";\nimport { ApiKeyNotAuthorizedError } from \"~/features/security/apiKeys/shared/errors.js\";\n\nclass GetApiKeyUseCaseImpl implements GetApiKeyUseCaseAbstraction.Interface {\n private repository: ApiKeysRepository.Interface;\n private identityContext: IdentityContext.Interface;\n\n constructor(\n repository: ApiKeysRepository.Interface,\n identityContext: IdentityContext.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n }\n\n async execute(id: string): Promise<Result<ApiKey | null, GetApiKeyUseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.apiKey\");\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n return this.repository.get(id);\n }\n}\n\nexport const GetApiKeyUseCase = GetApiKeyUseCaseAbstraction.createImplementation({\n implementation: GetApiKeyUseCaseImpl,\n dependencies: [ApiKeysRepository, IdentityContext]\n});\n"],"names":["GetApiKeyUseCaseImpl","repository","identityContext","id","hasPermission","Result","ApiKeyNotAuthorizedError","GetApiKeyUseCase","GetApiKeyUseCaseAbstraction","ApiKeysRepository","IdentityContext"],"mappings":";;;;;AAOA,MAAMA;IAIF,YACIC,UAAuC,EACvCC,eAA0C,CAC5C;QACE,IAAI,CAAC,UAAU,GAAGD;QAClB,IAAI,CAAC,eAAe,GAAGC;IAC3B;IAEA,MAAM,QAAQC,EAAU,EAAqE;QACzF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAACH;IAC/B;AACJ;AAEO,MAAMI,oCAAmBC,iBAAAA,oBAAgD,CAAC;IAC7E,gBAAgBR;IAChB,cAAc;QAACS;QAAmBC;KAAgB;AACtD"}
1
+ {"version":3,"file":"features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetApiKeyUseCase as GetApiKeyUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport type { ApiKey } from \"../shared/types.js\";\nimport { ApiKeyNotAuthorizedError } from \"~/features/security/apiKeys/shared/errors.js\";\n\nclass GetApiKeyUseCaseImpl implements GetApiKeyUseCaseAbstraction.Interface {\n private repository: ApiKeysRepository.Interface;\n private identityContext: IdentityContext.Interface;\n\n constructor(\n repository: ApiKeysRepository.Interface,\n identityContext: IdentityContext.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n }\n\n async execute(id: string): Promise<Result<ApiKey, GetApiKeyUseCaseAbstraction.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.apiKey\");\n if (!hasPermission) {\n return Result.fail(new ApiKeyNotAuthorizedError());\n }\n\n return this.repository.get(id);\n }\n}\n\nexport const GetApiKeyUseCase = GetApiKeyUseCaseAbstraction.createImplementation({\n implementation: GetApiKeyUseCaseImpl,\n dependencies: [ApiKeysRepository, IdentityContext]\n});\n"],"names":["GetApiKeyUseCaseImpl","repository","identityContext","id","hasPermission","Result","ApiKeyNotAuthorizedError","GetApiKeyUseCase","GetApiKeyUseCaseAbstraction","ApiKeysRepository","IdentityContext"],"mappings":";;;;;AAOA,MAAMA;IAIF,YACIC,UAAuC,EACvCC,eAA0C,CAC5C;QACE,IAAI,CAAC,UAAU,GAAGD;QAClB,IAAI,CAAC,eAAe,GAAGC;IAC3B;IAEA,MAAM,QAAQC,EAAU,EAA8D;QAClF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAACH;IAC/B;AACJ;AAEO,MAAMI,oCAAmBC,iBAAAA,oBAAgD,CAAC;IAC7E,gBAAgBR;IAChB,cAAc;QAACS;QAAmBC;KAAgB;AACtD"}
@@ -1,11 +1,9 @@
1
- import { Result } from "@webiny/feature/api";
2
1
  import { GetApiKeyBySlugUseCase as GetApiKeyBySlugUseCaseAbstraction } from "./abstractions.js";
3
2
  import { ApiKeysRepository } from "../shared/abstractions.js";
4
- import type { ApiKey } from "../shared/types.js";
5
3
  declare class GetApiKeyBySlugUseCaseImpl implements GetApiKeyBySlugUseCaseAbstraction.Interface {
6
4
  private repository;
7
5
  constructor(repository: ApiKeysRepository.Interface);
8
- execute(slug: string): Promise<Result<ApiKey | null, GetApiKeyBySlugUseCaseAbstraction.Error>>;
6
+ execute(slug: string): Promise<import("@webiny/feature/api").Result<import("../shared/types.js").ApiKey, import("../shared/errors.js").ApiKeyNotFoundError | import("../shared/errors.js").ApiKeyPersistenceError | import("../shared/errors.js").ApiKeyValidationError>>;
9
7
  }
10
8
  export declare const GetApiKeyBySlugUseCase: typeof GetApiKeyBySlugUseCaseImpl & {
11
9
  __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetApiKeyBySlug>;
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetApiKeyBySlugUseCase as GetApiKeyBySlugUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport type { ApiKey } from \"../shared/types.js\";\n\nclass GetApiKeyBySlugUseCaseImpl implements GetApiKeyBySlugUseCaseAbstraction.Interface {\n private repository: ApiKeysRepository.Interface;\n\n constructor(repository: ApiKeysRepository.Interface) {\n this.repository = repository;\n }\n\n async execute(\n slug: string\n ): Promise<Result<ApiKey | null, GetApiKeyBySlugUseCaseAbstraction.Error>> {\n return this.repository.getBySlug(slug);\n }\n}\n\nexport const GetApiKeyBySlugUseCase = GetApiKeyBySlugUseCaseAbstraction.createImplementation({\n implementation: GetApiKeyBySlugUseCaseImpl,\n dependencies: [ApiKeysRepository]\n});\n"],"names":["GetApiKeyBySlugUseCaseImpl","repository","slug","GetApiKeyBySlugUseCase","GetApiKeyBySlugUseCaseAbstraction","ApiKeysRepository"],"mappings":";;AAKA,MAAMA;IAGF,YAAYC,UAAuC,CAAE;QACjD,IAAI,CAAC,UAAU,GAAGA;IACtB;IAEA,MAAM,QACFC,IAAY,EAC2D;QACvE,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAACA;IACrC;AACJ;AAEO,MAAMC,gDAAyBC,uBAAAA,oBAAsD,CAAC;IACzF,gBAAgBJ;IAChB,cAAc;QAACK;KAAkB;AACrC"}
1
+ {"version":3,"file":"features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.ts"],"sourcesContent":["import { GetApiKeyBySlugUseCase as GetApiKeyBySlugUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\n\nclass GetApiKeyBySlugUseCaseImpl implements GetApiKeyBySlugUseCaseAbstraction.Interface {\n constructor(private repository: ApiKeysRepository.Interface) {}\n\n async execute(slug: string) {\n return this.repository.getBySlug(slug);\n }\n}\n\nexport const GetApiKeyBySlugUseCase = GetApiKeyBySlugUseCaseAbstraction.createImplementation({\n implementation: GetApiKeyBySlugUseCaseImpl,\n dependencies: [ApiKeysRepository]\n});\n"],"names":["GetApiKeyBySlugUseCaseImpl","repository","slug","GetApiKeyBySlugUseCase","GetApiKeyBySlugUseCaseAbstraction","ApiKeysRepository"],"mappings":";;AAGA,MAAMA;IACF,YAAoBC,UAAuC,CAAE;aAAzCA,UAAU,GAAVA;IAA0C;IAE9D,MAAM,QAAQC,IAAY,EAAE;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAACA;IACrC;AACJ;AAEO,MAAMC,gDAAyBC,uBAAAA,oBAAsD,CAAC;IACzF,gBAAgBJ;IAChB,cAAc;QAACK;KAAkB;AACrC"}
@@ -5,7 +5,7 @@ export interface IGetApiKeyBySlugErrors {
5
5
  }
6
6
  type GetApiKeyBySlugError = IGetApiKeyBySlugErrors[keyof IGetApiKeyBySlugErrors] | ApiKeysRepository.Error;
7
7
  export interface IGetApiKeyBySlug {
8
- execute(slug: string): Promise<Result<ApiKey | null, GetApiKeyBySlugError>>;
8
+ execute(slug: string): Promise<Result<ApiKey, GetApiKeyBySlugError>>;
9
9
  }
10
10
  /** Retrieve an API key by its slug. */
11
11
  export declare const GetApiKeyBySlugUseCase: import("@webiny/di").Abstraction<IGetApiKeyBySlug>;
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/GetApiKeyBySlug/abstractions.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyBySlug/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ApiKey } from \"../shared/types.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\n\nexport interface IGetApiKeyBySlugErrors {\n // No use-case specific errors - only repository errors can occur\n}\n\ntype GetApiKeyBySlugError =\n | IGetApiKeyBySlugErrors[keyof IGetApiKeyBySlugErrors]\n | ApiKeysRepository.Error;\n\nexport interface IGetApiKeyBySlug {\n execute(slug: string): Promise<Result<ApiKey | null, GetApiKeyBySlugError>>;\n}\n\n/** Retrieve an API key by its slug. */\nexport const GetApiKeyBySlugUseCase = createAbstraction<IGetApiKeyBySlug>(\"GetApiKeyBySlugUseCase\");\n\nexport namespace GetApiKeyBySlugUseCase {\n export type Interface = IGetApiKeyBySlug;\n export type Error = GetApiKeyBySlugError;\n}\n"],"names":["GetApiKeyBySlugUseCase","createAbstraction"],"mappings":";AAkBO,MAAMA,yBAAyBC,kBAAoC"}
1
+ {"version":3,"file":"features/security/apiKeys/GetApiKeyBySlug/abstractions.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyBySlug/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ApiKey } from \"../shared/types.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\n\nexport interface IGetApiKeyBySlugErrors {\n // No use-case specific errors - only repository errors can occur\n}\n\ntype GetApiKeyBySlugError =\n | IGetApiKeyBySlugErrors[keyof IGetApiKeyBySlugErrors]\n | ApiKeysRepository.Error;\n\nexport interface IGetApiKeyBySlug {\n execute(slug: string): Promise<Result<ApiKey, GetApiKeyBySlugError>>;\n}\n\n/** Retrieve an API key by its slug. */\nexport const GetApiKeyBySlugUseCase = createAbstraction<IGetApiKeyBySlug>(\"GetApiKeyBySlugUseCase\");\n\nexport namespace GetApiKeyBySlugUseCase {\n export type Interface = IGetApiKeyBySlug;\n export type Error = GetApiKeyBySlugError;\n}\n"],"names":["GetApiKeyBySlugUseCase","createAbstraction"],"mappings":";AAkBO,MAAMA,yBAAyBC,kBAAoC"}
@@ -1,11 +1,9 @@
1
- import { Result } from "@webiny/feature/api";
2
1
  import { GetApiKeyByTokenUseCase as GetApiKeyByTokenUseCaseAbstraction } from "./abstractions.js";
3
2
  import { ApiKeysRepository } from "../shared/abstractions.js";
4
- import type { ApiKey } from "../shared/types.js";
5
3
  declare class GetApiKeyByTokenUseCaseImpl implements GetApiKeyByTokenUseCaseAbstraction.Interface {
6
4
  private repository;
7
5
  constructor(repository: ApiKeysRepository.Interface);
8
- execute(token: string): Promise<Result<ApiKey | null, GetApiKeyByTokenUseCaseAbstraction.Error>>;
6
+ execute(token: string): Promise<import("@webiny/feature/api").Result<import("../shared/types.js").ApiKey, import("../shared/errors.js").ApiKeyNotFoundError | import("../shared/errors.js").ApiKeyPersistenceError | import("../shared/errors.js").ApiKeyValidationError>>;
9
7
  }
10
8
  export declare const GetApiKeyByTokenUseCase: typeof GetApiKeyByTokenUseCaseImpl & {
11
9
  __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetApiKeyByToken>;
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetApiKeyByTokenUseCase as GetApiKeyByTokenUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\nimport type { ApiKey } from \"../shared/types.js\";\n\nclass GetApiKeyByTokenUseCaseImpl implements GetApiKeyByTokenUseCaseAbstraction.Interface {\n private repository: ApiKeysRepository.Interface;\n\n constructor(repository: ApiKeysRepository.Interface) {\n this.repository = repository;\n }\n\n async execute(\n token: string\n ): Promise<Result<ApiKey | null, GetApiKeyByTokenUseCaseAbstraction.Error>> {\n return this.repository.getByToken(token);\n }\n}\n\nexport const GetApiKeyByTokenUseCase = GetApiKeyByTokenUseCaseAbstraction.createImplementation({\n implementation: GetApiKeyByTokenUseCaseImpl,\n dependencies: [ApiKeysRepository]\n});\n"],"names":["GetApiKeyByTokenUseCaseImpl","repository","token","GetApiKeyByTokenUseCase","GetApiKeyByTokenUseCaseAbstraction","ApiKeysRepository"],"mappings":";;AAKA,MAAMA;IAGF,YAAYC,UAAuC,CAAE;QACjD,IAAI,CAAC,UAAU,GAAGA;IACtB;IAEA,MAAM,QACFC,KAAa,EAC2D;QACxE,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAACA;IACtC;AACJ;AAEO,MAAMC,kDAA0BC,wBAAAA,oBAAuD,CAAC;IAC3F,gBAAgBJ;IAChB,cAAc;QAACK;KAAkB;AACrC"}
1
+ {"version":3,"file":"features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.ts"],"sourcesContent":["import { GetApiKeyByTokenUseCase as GetApiKeyByTokenUseCaseAbstraction } from \"./abstractions.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\n\nclass GetApiKeyByTokenUseCaseImpl implements GetApiKeyByTokenUseCaseAbstraction.Interface {\n constructor(private repository: ApiKeysRepository.Interface) {}\n\n async execute(token: string) {\n return this.repository.getByToken(token);\n }\n}\n\nexport const GetApiKeyByTokenUseCase = GetApiKeyByTokenUseCaseAbstraction.createImplementation({\n implementation: GetApiKeyByTokenUseCaseImpl,\n dependencies: [ApiKeysRepository]\n});\n"],"names":["GetApiKeyByTokenUseCaseImpl","repository","token","GetApiKeyByTokenUseCase","GetApiKeyByTokenUseCaseAbstraction","ApiKeysRepository"],"mappings":";;AAGA,MAAMA;IACF,YAAoBC,UAAuC,CAAE;aAAzCA,UAAU,GAAVA;IAA0C;IAE9D,MAAM,QAAQC,KAAa,EAAE;QACzB,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAACA;IACtC;AACJ;AAEO,MAAMC,kDAA0BC,wBAAAA,oBAAuD,CAAC;IAC3F,gBAAgBJ;IAChB,cAAc;QAACK;KAAkB;AACrC"}
@@ -5,7 +5,7 @@ export interface IGetApiKeyByTokenErrors {
5
5
  }
6
6
  type GetApiKeyByTokenError = IGetApiKeyByTokenErrors[keyof IGetApiKeyByTokenErrors] | ApiKeysRepository.Error;
7
7
  export interface IGetApiKeyByToken {
8
- execute(token: string): Promise<Result<ApiKey | null, GetApiKeyByTokenError>>;
8
+ execute(token: string): Promise<Result<ApiKey, GetApiKeyByTokenError>>;
9
9
  }
10
10
  /** Retrieve an API key by its token value. */
11
11
  export declare const GetApiKeyByTokenUseCase: import("@webiny/di").Abstraction<IGetApiKeyByToken>;
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/GetApiKeyByToken/abstractions.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyByToken/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ApiKey } from \"../shared/types.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\n\nexport interface IGetApiKeyByTokenErrors {\n // No use-case specific errors - only repository errors can occur\n}\n\ntype GetApiKeyByTokenError =\n | IGetApiKeyByTokenErrors[keyof IGetApiKeyByTokenErrors]\n | ApiKeysRepository.Error;\n\nexport interface IGetApiKeyByToken {\n execute(token: string): Promise<Result<ApiKey | null, GetApiKeyByTokenError>>;\n}\n\n/** Retrieve an API key by its token value. */\nexport const GetApiKeyByTokenUseCase =\n createAbstraction<IGetApiKeyByToken>(\"GetApiKeyByTokenUseCase\");\n\nexport namespace GetApiKeyByTokenUseCase {\n export type Interface = IGetApiKeyByToken;\n export type Error = GetApiKeyByTokenError;\n}\n"],"names":["GetApiKeyByTokenUseCase","createAbstraction"],"mappings":";AAkBO,MAAMA,0BACTC,kBAAqC"}
1
+ {"version":3,"file":"features/security/apiKeys/GetApiKeyByToken/abstractions.js","sources":["../../../../../src/features/security/apiKeys/GetApiKeyByToken/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ApiKey } from \"../shared/types.js\";\nimport { ApiKeysRepository } from \"../shared/abstractions.js\";\n\nexport interface IGetApiKeyByTokenErrors {\n // No use-case specific errors - only repository errors can occur\n}\n\ntype GetApiKeyByTokenError =\n | IGetApiKeyByTokenErrors[keyof IGetApiKeyByTokenErrors]\n | ApiKeysRepository.Error;\n\nexport interface IGetApiKeyByToken {\n execute(token: string): Promise<Result<ApiKey, GetApiKeyByTokenError>>;\n}\n\n/** Retrieve an API key by its token value. */\nexport const GetApiKeyByTokenUseCase =\n createAbstraction<IGetApiKeyByToken>(\"GetApiKeyByTokenUseCase\");\n\nexport namespace GetApiKeyByTokenUseCase {\n export type Interface = IGetApiKeyByToken;\n export type Error = GetApiKeyByTokenError;\n}\n"],"names":["GetApiKeyByTokenUseCase","createAbstraction"],"mappings":";AAkBO,MAAMA,0BACTC,kBAAqC"}
@@ -7,12 +7,17 @@ import { ListApiKeysFeature } from "./ListApiKeys/feature.js";
7
7
  import { CreateApiKeyFeature } from "./CreateApiKey/feature.js";
8
8
  import { UpdateApiKeyFeature } from "./UpdateApiKey/feature.js";
9
9
  import { DeleteApiKeyFeature } from "./DeleteApiKey/feature.js";
10
- import { ApiKeyProvider } from "./shared/ApiKeyProvider.js";
10
+ import { ApiKeyFactory, ApiKeyProvider } from "./shared/abstractions.js";
11
+ import { ApiKeyProvider as ApiKeyProvider_js_ApiKeyProvider } from "./shared/ApiKeyProvider.js";
12
+ import { TenantContext } from "../../tenancy/TenantContext/index.js";
11
13
  const ApiKeysFeature = createFeature({
12
14
  name: "ApiKeys",
13
15
  register (container) {
14
16
  container.register(ApiKeysRepository).inSingletonScope();
15
- container.register(ApiKeyProvider).inSingletonScope();
17
+ container.registerFactory(ApiKeyProvider, ()=>{
18
+ const tenantContext = container.resolve(TenantContext);
19
+ return new ApiKeyProvider_js_ApiKeyProvider(tenantContext, ()=>container.resolveAll(ApiKeyFactory));
20
+ });
16
21
  GetApiKeyFeature.register(container);
17
22
  GetApiKeyByTokenFeature.register(container);
18
23
  GetApiKeyBySlugFeature.register(container);
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/feature.js","sources":["../../../../src/features/security/apiKeys/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ApiKeysRepository } from \"./shared/ApiKeysRepository.js\";\nimport { GetApiKeyFeature } from \"./GetApiKey/feature.js\";\nimport { GetApiKeyByTokenFeature } from \"./GetApiKeyByToken/feature.js\";\nimport { GetApiKeyBySlugFeature } from \"./GetApiKeyBySlug/feature.js\";\nimport { ListApiKeysFeature } from \"./ListApiKeys/feature.js\";\nimport { CreateApiKeyFeature } from \"./CreateApiKey/feature.js\";\nimport { UpdateApiKeyFeature } from \"./UpdateApiKey/feature.js\";\nimport { DeleteApiKeyFeature } from \"./DeleteApiKey/feature.js\";\nimport { ApiKeyProvider } from \"./shared/ApiKeyProvider.js\";\n\nexport const ApiKeysFeature = createFeature({\n name: \"ApiKeys\",\n register(container) {\n // Register repository in singleton scope\n container.register(ApiKeysRepository).inSingletonScope();\n container.register(ApiKeyProvider).inSingletonScope();\n\n // Register all use cases\n GetApiKeyFeature.register(container);\n GetApiKeyByTokenFeature.register(container);\n GetApiKeyBySlugFeature.register(container);\n ListApiKeysFeature.register(container);\n CreateApiKeyFeature.register(container);\n UpdateApiKeyFeature.register(container);\n DeleteApiKeyFeature.register(container);\n }\n});\n"],"names":["ApiKeysFeature","createFeature","container","ApiKeysRepository","ApiKeyProvider","GetApiKeyFeature","GetApiKeyByTokenFeature","GetApiKeyBySlugFeature","ListApiKeysFeature","CreateApiKeyFeature","UpdateApiKeyFeature","DeleteApiKeyFeature"],"mappings":";;;;;;;;;;AAWO,MAAMA,iBAAiBC,cAAc;IACxC,MAAM;IACN,UAASC,SAAS;QAEdA,UAAU,QAAQ,CAACC,mBAAmB,gBAAgB;QACtDD,UAAU,QAAQ,CAACE,gBAAgB,gBAAgB;QAGnDC,iBAAiB,QAAQ,CAACH;QAC1BI,wBAAwB,QAAQ,CAACJ;QACjCK,uBAAuB,QAAQ,CAACL;QAChCM,mBAAmB,QAAQ,CAACN;QAC5BO,oBAAoB,QAAQ,CAACP;QAC7BQ,oBAAoB,QAAQ,CAACR;QAC7BS,oBAAoB,QAAQ,CAACT;IACjC;AACJ"}
1
+ {"version":3,"file":"features/security/apiKeys/feature.js","sources":["../../../../src/features/security/apiKeys/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ApiKeysRepository } from \"./shared/ApiKeysRepository.js\";\nimport { GetApiKeyFeature } from \"./GetApiKey/feature.js\";\nimport { GetApiKeyByTokenFeature } from \"./GetApiKeyByToken/feature.js\";\nimport { GetApiKeyBySlugFeature } from \"./GetApiKeyBySlug/feature.js\";\nimport { ListApiKeysFeature } from \"./ListApiKeys/feature.js\";\nimport { CreateApiKeyFeature } from \"./CreateApiKey/feature.js\";\nimport { UpdateApiKeyFeature } from \"./UpdateApiKey/feature.js\";\nimport { DeleteApiKeyFeature } from \"./DeleteApiKey/feature.js\";\nimport {\n ApiKeyFactory,\n ApiKeyProvider as ApiKeyProviderAbstraction\n} from \"~/features/security/apiKeys/shared/abstractions.js\";\nimport { ApiKeyProvider } from \"./shared/ApiKeyProvider.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\n\nexport const ApiKeysFeature = createFeature({\n name: \"ApiKeys\",\n register(container) {\n // Register repository in singleton scope\n container.register(ApiKeysRepository).inSingletonScope();\n\n container.registerFactory(ApiKeyProviderAbstraction, () => {\n const tenantContext = container.resolve(TenantContext);\n return new ApiKeyProvider(tenantContext, () => {\n return container.resolveAll(ApiKeyFactory);\n });\n });\n\n // Register all use cases\n GetApiKeyFeature.register(container);\n GetApiKeyByTokenFeature.register(container);\n GetApiKeyBySlugFeature.register(container);\n ListApiKeysFeature.register(container);\n CreateApiKeyFeature.register(container);\n UpdateApiKeyFeature.register(container);\n DeleteApiKeyFeature.register(container);\n }\n});\n"],"names":["ApiKeysFeature","createFeature","container","ApiKeysRepository","ApiKeyProviderAbstraction","tenantContext","TenantContext","ApiKeyProvider","ApiKeyFactory","GetApiKeyFeature","GetApiKeyByTokenFeature","GetApiKeyBySlugFeature","ListApiKeysFeature","CreateApiKeyFeature","UpdateApiKeyFeature","DeleteApiKeyFeature"],"mappings":";;;;;;;;;;;;AAgBO,MAAMA,iBAAiBC,cAAc;IACxC,MAAM;IACN,UAASC,SAAS;QAEdA,UAAU,QAAQ,CAACC,mBAAmB,gBAAgB;QAEtDD,UAAU,eAAe,CAACE,gBAA2B;YACjD,MAAMC,gBAAgBH,UAAU,OAAO,CAACI;YACxC,OAAO,IAAIC,iCAAeF,eAAe,IAC9BH,UAAU,UAAU,CAACM;QAEpC;QAGAC,iBAAiB,QAAQ,CAACP;QAC1BQ,wBAAwB,QAAQ,CAACR;QACjCS,uBAAuB,QAAQ,CAACT;QAChCU,mBAAmB,QAAQ,CAACV;QAC5BW,oBAAoB,QAAQ,CAACX;QAC7BY,oBAAoB,QAAQ,CAACZ;QAC7Ba,oBAAoB,QAAQ,CAACb;IACjC;AACJ"}
@@ -2,14 +2,12 @@ import { TenantContext } from "../../../../features/tenancy/TenantContext/index.
2
2
  import { ApiKeyFactory } from "./abstractions.js";
3
3
  import { ApiKeyProvider as ProviderAbstraction } from "./abstractions.js";
4
4
  import type { ApiKey } from "./types.js";
5
- declare class ApiKeyProviderImpl implements ProviderAbstraction.Interface {
5
+ export declare class ApiKeyProvider implements ProviderAbstraction.Interface {
6
6
  private tenantContext;
7
- private apiKeyFactories;
7
+ private getApiKeyFactories;
8
8
  private cache;
9
- constructor(tenantContext: TenantContext.Interface, apiKeyFactories: ApiKeyFactory.Interface[]);
9
+ constructor(tenantContext: TenantContext.Interface, getApiKeyFactories: () => ApiKeyFactory.Interface[]);
10
10
  getByToken(token: string): Promise<ApiKey | null>;
11
11
  getBySlug(slug: string): Promise<ApiKey | null>;
12
12
  private getCache;
13
13
  }
14
- export declare const ApiKeyProvider: import("@webiny/di").Implementation<typeof ApiKeyProviderImpl>;
15
- export {};
@@ -1,11 +1,8 @@
1
- import { createImplementation } from "@webiny/feature/api";
2
- import { TenantContext } from "../../../tenancy/TenantContext/index.js";
3
- import { ApiKeyFactory, ApiKeyProvider } from "./abstractions.js";
4
1
  import { SystemIdentityValue } from "../../../../domain/identity/SystemIdentityValue.js";
5
- class ApiKeyProviderImpl {
6
- constructor(tenantContext, apiKeyFactories){
2
+ class ApiKeyProvider {
3
+ constructor(tenantContext, getApiKeyFactories){
7
4
  this.tenantContext = tenantContext;
8
- this.apiKeyFactories = apiKeyFactories;
5
+ this.getApiKeyFactories = getApiKeyFactories;
9
6
  }
10
7
  async getByToken(token) {
11
8
  const cache = await this.getCache();
@@ -19,7 +16,8 @@ class ApiKeyProviderImpl {
19
16
  }
20
17
  async getCache() {
21
18
  if (void 0 === this.cache) {
22
- const results = await Promise.all(this.apiKeyFactories.map((factory)=>factory.execute()));
19
+ const apiKeyFactories = this.getApiKeyFactories();
20
+ const results = await Promise.all(apiKeyFactories.map((factory)=>factory.execute()));
23
21
  this.cache = results.flat().map((codeKey)=>({
24
22
  ...codeKey,
25
23
  id: codeKey.slug,
@@ -33,19 +31,6 @@ class ApiKeyProviderImpl {
33
31
  return this.cache;
34
32
  }
35
33
  }
36
- const ApiKeyProvider_ApiKeyProvider = createImplementation({
37
- abstraction: ApiKeyProvider,
38
- implementation: ApiKeyProviderImpl,
39
- dependencies: [
40
- TenantContext,
41
- [
42
- ApiKeyFactory,
43
- {
44
- multiple: true
45
- }
46
- ]
47
- ]
48
- });
49
- export { ApiKeyProvider_ApiKeyProvider as ApiKeyProvider };
34
+ export { ApiKeyProvider };
50
35
 
51
36
  //# sourceMappingURL=ApiKeyProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/shared/ApiKeyProvider.js","sources":["../../../../../src/features/security/apiKeys/shared/ApiKeyProvider.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { ApiKeyFactory } from \"./abstractions.js\";\nimport { ApiKeyProvider as ProviderAbstraction } from \"./abstractions.js\";\nimport type { ApiKey } from \"./types.js\";\nimport { SystemIdentityValue } from \"~/domain/identity/SystemIdentityValue.js\";\n\nclass ApiKeyProviderImpl implements ProviderAbstraction.Interface {\n private cache: ApiKey[] | undefined;\n\n constructor(\n private tenantContext: TenantContext.Interface,\n private apiKeyFactories: ApiKeyFactory.Interface[]\n ) {}\n\n async getByToken(token: string): Promise<ApiKey | null> {\n const cache = await this.getCache();\n\n // Search for the API key by token in the cached array\n const apiKey = cache.find(key => key.token === token);\n return apiKey || null;\n }\n\n async getBySlug(slug: string): Promise<ApiKey | null> {\n const cache = await this.getCache();\n\n // Search for the API key by token in the cached array\n const apiKey = cache.find(key => key.slug === slug);\n return apiKey || null;\n }\n\n private async getCache(): Promise<ApiKey[]> {\n if (this.cache === undefined) {\n const results = await Promise.all(\n this.apiKeyFactories.map(factory => factory.execute())\n );\n this.cache = results.flat().map<ApiKey>(codeKey => {\n return {\n ...codeKey,\n id: codeKey.slug,\n slug: codeKey.slug,\n description: \"\",\n tenant: this.tenantContext.getTenant().id,\n createdOn: new Date().toISOString(),\n createdBy: SystemIdentityValue.create()\n };\n });\n }\n\n return this.cache;\n }\n}\n\nexport const ApiKeyProvider = createImplementation({\n abstraction: ProviderAbstraction,\n implementation: ApiKeyProviderImpl,\n dependencies: [TenantContext, [ApiKeyFactory, { multiple: true }]]\n});\n"],"names":["ApiKeyProviderImpl","tenantContext","apiKeyFactories","token","cache","apiKey","key","slug","undefined","results","Promise","factory","codeKey","Date","SystemIdentityValue","ApiKeyProvider","createImplementation","ProviderAbstraction","TenantContext","ApiKeyFactory"],"mappings":";;;;AAOA,MAAMA;IAGF,YACYC,aAAsC,EACtCC,eAA0C,CACpD;aAFUD,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,WAAWC,KAAa,EAA0B;QACpD,MAAMC,QAAQ,MAAM,IAAI,CAAC,QAAQ;QAGjC,MAAMC,SAASD,MAAM,IAAI,CAACE,CAAAA,MAAOA,IAAI,KAAK,KAAKH;QAC/C,OAAOE,UAAU;IACrB;IAEA,MAAM,UAAUE,IAAY,EAA0B;QAClD,MAAMH,QAAQ,MAAM,IAAI,CAAC,QAAQ;QAGjC,MAAMC,SAASD,MAAM,IAAI,CAACE,CAAAA,MAAOA,IAAI,IAAI,KAAKC;QAC9C,OAAOF,UAAU;IACrB;IAEA,MAAc,WAA8B;QACxC,IAAI,AAAeG,WAAf,IAAI,CAAC,KAAK,EAAgB;YAC1B,MAAMC,UAAU,MAAMC,QAAQ,GAAG,CAC7B,IAAI,CAAC,eAAe,CAAC,GAAG,CAACC,CAAAA,UAAWA,QAAQ,OAAO;YAEvD,IAAI,CAAC,KAAK,GAAGF,QAAQ,IAAI,GAAG,GAAG,CAASG,CAAAA,UAC7B;oBACH,GAAGA,OAAO;oBACV,IAAIA,QAAQ,IAAI;oBAChB,MAAMA,QAAQ,IAAI;oBAClB,aAAa;oBACb,QAAQ,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,EAAE;oBACzC,WAAW,IAAIC,OAAO,WAAW;oBACjC,WAAWC,oBAAoB,MAAM;gBACzC;QAER;QAEA,OAAO,IAAI,CAAC,KAAK;IACrB;AACJ;AAEO,MAAMC,gCAAiBC,qBAAqB;IAC/C,aAAaC;IACb,gBAAgBjB;IAChB,cAAc;QAACkB;QAAe;YAACC;YAAe;gBAAE,UAAU;YAAK;SAAE;KAAC;AACtE"}
1
+ {"version":3,"file":"features/security/apiKeys/shared/ApiKeyProvider.js","sources":["../../../../../src/features/security/apiKeys/shared/ApiKeyProvider.ts"],"sourcesContent":["import { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { ApiKeyFactory } from \"./abstractions.js\";\nimport { ApiKeyProvider as ProviderAbstraction } from \"./abstractions.js\";\nimport type { ApiKey } from \"./types.js\";\nimport { SystemIdentityValue } from \"~/domain/identity/SystemIdentityValue.js\";\n\nexport class ApiKeyProvider implements ProviderAbstraction.Interface {\n private cache: ApiKey[] | undefined;\n\n constructor(\n private tenantContext: TenantContext.Interface,\n private getApiKeyFactories: () => ApiKeyFactory.Interface[]\n ) {}\n\n async getByToken(token: string): Promise<ApiKey | null> {\n const cache = await this.getCache();\n\n // Search for the API key by token in the cached array\n const apiKey = cache.find(key => key.token === token);\n return apiKey || null;\n }\n\n async getBySlug(slug: string): Promise<ApiKey | null> {\n const cache = await this.getCache();\n\n // Search for the API key by token in the cached array\n const apiKey = cache.find(key => key.slug === slug);\n return apiKey || null;\n }\n\n private async getCache(): Promise<ApiKey[]> {\n if (this.cache === undefined) {\n const apiKeyFactories = this.getApiKeyFactories();\n const results = await Promise.all(apiKeyFactories.map(factory => factory.execute()));\n this.cache = results.flat().map<ApiKey>(codeKey => {\n return {\n ...codeKey,\n id: codeKey.slug,\n slug: codeKey.slug,\n description: \"\",\n tenant: this.tenantContext.getTenant().id,\n createdOn: new Date().toISOString(),\n createdBy: SystemIdentityValue.create()\n };\n });\n }\n\n return this.cache;\n }\n}\n"],"names":["ApiKeyProvider","tenantContext","getApiKeyFactories","token","cache","apiKey","key","slug","undefined","apiKeyFactories","results","Promise","factory","codeKey","Date","SystemIdentityValue"],"mappings":";AAMO,MAAMA;IAGT,YACYC,aAAsC,EACtCC,kBAAmD,CAC7D;aAFUD,aAAa,GAAbA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,WAAWC,KAAa,EAA0B;QACpD,MAAMC,QAAQ,MAAM,IAAI,CAAC,QAAQ;QAGjC,MAAMC,SAASD,MAAM,IAAI,CAACE,CAAAA,MAAOA,IAAI,KAAK,KAAKH;QAC/C,OAAOE,UAAU;IACrB;IAEA,MAAM,UAAUE,IAAY,EAA0B;QAClD,MAAMH,QAAQ,MAAM,IAAI,CAAC,QAAQ;QAGjC,MAAMC,SAASD,MAAM,IAAI,CAACE,CAAAA,MAAOA,IAAI,IAAI,KAAKC;QAC9C,OAAOF,UAAU;IACrB;IAEA,MAAc,WAA8B;QACxC,IAAI,AAAeG,WAAf,IAAI,CAAC,KAAK,EAAgB;YAC1B,MAAMC,kBAAkB,IAAI,CAAC,kBAAkB;YAC/C,MAAMC,UAAU,MAAMC,QAAQ,GAAG,CAACF,gBAAgB,GAAG,CAACG,CAAAA,UAAWA,QAAQ,OAAO;YAChF,IAAI,CAAC,KAAK,GAAGF,QAAQ,IAAI,GAAG,GAAG,CAASG,CAAAA,UAC7B;oBACH,GAAGA,OAAO;oBACV,IAAIA,QAAQ,IAAI;oBAChB,MAAMA,QAAQ,IAAI;oBAClB,aAAa;oBACb,QAAQ,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,EAAE;oBACzC,WAAW,IAAIC,OAAO,WAAW;oBACjC,WAAWC,oBAAoB,MAAM;gBACzC;QAER;QAEA,OAAO,IAAI,CAAC,KAAK;IACrB;AACJ"}
@@ -8,6 +8,7 @@ declare class ApiKeysRepositoryImpl implements RepositoryAbstraction.Interface {
8
8
  private tenantContext;
9
9
  private storageOperations;
10
10
  private apiKeyProvider;
11
+ private resolving;
11
12
  constructor(tenantContext: TenantContext.Interface, storageOperations: SecurityStorageOperations.Interface, apiKeyProvider: ApiKeyProvider.Interface);
12
13
  get(id: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>>;
13
14
  getByToken(token: string): Promise<Result<ApiKey, RepositoryAbstraction.Error>>;
@@ -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,MAAMC,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC;gBACzDI;gBACA,QAAQL,OAAO,EAAE;YACrB;YAEA,IAAIC,QACA,OAAOC,OAAO,EAAE,CAACD;YAIrB,MAAMK,gBAAgB,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAACD;YAC3D,IAAIC,eACA,OAAOJ,OAAO,EAAE,CAACI;YAGrB,OAAOJ,OAAO,IAAI,CAAC,IAAIC;QAC3B,EAAE,OAAOC,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIK,uBAAuBH;QAClD;IACJ;IAEA,MAAM,UAAUI,IAAY,EAAwD;QAChF,IAAI;YAEA,MAAMR,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C,MAAMC,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC;gBACxDO;gBACA,QAAQR,OAAO,EAAE;YACrB;YAEA,IAAIC,QACA,OAAOC,OAAO,EAAE,CAACD;YAIrB,MAAMK,gBAAgB,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAACE;YAC1D,IAAIF,eACA,OAAOJ,OAAO,EAAE,CAACI;YAGrB,OAAOJ,OAAO,IAAI,CAAC,IAAIC;QAC3B,EAAE,OAAOC,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIK,uBAAuBH;QAClD;IACJ;IAEA,MAAM,KAAKK,MAAwB,EAA0D;QACzF,IAAI;YACA,MAAMT,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAC3C,MAAMU,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC;gBACpD,OAAO;oBAAE,QAAQV,OAAO,EAAE;gBAAC;gBAC3B,GAAGS,MAAM;YACb;YACA,OAAOP,OAAO,EAAE,CAACQ;QACrB,EAAE,OAAON,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIK,uBAAuBH;QAClD;IACJ;IAEA,MAAM,OAAOH,MAAc,EAAsD;QAC7E,IAAI;YAEA,MAAMU,oBAAoB,MAAM,IAAI,CAAC,SAAS,CAACV,OAAO,IAAI;YAG1D,IAAIU,kBAAkB,IAAI,IACtB,OAAOT,OAAO,IAAI,CACd,IAAIU,sBAAsB,CAAC,mBAAmB,EAAEX,OAAO,IAAI,CAAC,iBAAiB,CAAC;YAKtF,IAAIU,AAAiC,sBAAjCA,kBAAkB,KAAK,CAAC,IAAI,EAC5B,OAAOT,OAAO,IAAI,CAACS,kBAAkB,KAAK;YAI9C,MAAMX,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;YACrF,OAAOE,OAAO,EAAE;QACpB,EAAE,OAAOE,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;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"}
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":"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"}
@@ -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"}
@@ -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;
@@ -13,8 +13,8 @@ declare class GetPermissionsFromGroupsAndTeamsImpl implements PermissionsProcess
13
13
  private teamsRepository;
14
14
  constructor(wcpContext: WcpContext.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 & {
@@ -3,6 +3,6 @@ export declare const getPermissionsFromRoles: (securityGroups: Array<{
3
3
  permissions: SecurityPermission[];
4
4
  id: string;
5
5
  }>) => {
6
- _src: string;
7
6
  name: string;
7
+ _src: string;
8
8
  }[];
@@ -0,0 +1,17 @@
1
+ import type { GenericRecord } from "@webiny/api/types.js";
2
+ export interface IServiceManifest {
3
+ name: string;
4
+ manifest: GenericRecord<string>;
5
+ }
6
+ export interface IServiceManifestLoader {
7
+ load(): Promise<IServiceManifest[] | undefined>;
8
+ }
9
+ type Manifest = GenericRecord<string>;
10
+ export declare class ServiceDiscovery {
11
+ private static loader;
12
+ private static manifest;
13
+ static setLoader(loader: IServiceManifestLoader): void;
14
+ static load(): Promise<Manifest | undefined>;
15
+ static clear(): void;
16
+ }
17
+ export {};
@@ -0,0 +1,22 @@
1
+ class ServiceDiscovery {
2
+ static setLoader(loader) {
3
+ this.loader = loader;
4
+ }
5
+ static async load() {
6
+ if (this.manifest) return this.manifest;
7
+ if (!this.loader) throw new Error("ServiceDiscovery loader not configured. Call ServiceDiscovery.setLoader() before loading manifests.");
8
+ const manifests = await this.loader.load();
9
+ if (!manifests) return;
10
+ this.manifest = manifests.reduce((acc, item)=>({
11
+ ...acc,
12
+ [item.name]: item.manifest
13
+ }), {});
14
+ return this.manifest;
15
+ }
16
+ static clear() {
17
+ this.manifest = void 0;
18
+ }
19
+ }
20
+ export { ServiceDiscovery };
21
+
22
+ //# sourceMappingURL=ServiceDiscovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/serviceDiscovery/ServiceDiscovery.js","sources":["../../../src/features/serviceDiscovery/ServiceDiscovery.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface IServiceManifest {\n name: string;\n manifest: GenericRecord<string>;\n}\n\nexport interface IServiceManifestLoader {\n load(): Promise<IServiceManifest[] | undefined>;\n}\n\ntype Manifest = GenericRecord<string>;\n\nexport class ServiceDiscovery {\n private static loader: IServiceManifestLoader | undefined;\n private static manifest: Manifest | undefined;\n\n static setLoader(loader: IServiceManifestLoader): void {\n this.loader = loader;\n }\n\n static async load(): Promise<Manifest | undefined> {\n if (this.manifest) {\n return this.manifest;\n }\n\n if (!this.loader) {\n throw new Error(\n \"ServiceDiscovery loader not configured. Call ServiceDiscovery.setLoader() before loading manifests.\"\n );\n }\n\n const manifests = await this.loader.load();\n\n if (!manifests) {\n return undefined;\n }\n\n this.manifest = manifests.reduce<Manifest>((acc, item) => {\n return { ...acc, [item.name]: item.manifest };\n }, {});\n\n return this.manifest;\n }\n\n static clear(): void {\n this.manifest = undefined;\n }\n}\n"],"names":["ServiceDiscovery","loader","Error","manifests","acc","item","undefined"],"mappings":"AAaO,MAAMA;IAIT,OAAO,UAAUC,MAA8B,EAAQ;QACnD,IAAI,CAAC,MAAM,GAAGA;IAClB;IAEA,aAAa,OAAsC;QAC/C,IAAI,IAAI,CAAC,QAAQ,EACb,OAAO,IAAI,CAAC,QAAQ;QAGxB,IAAI,CAAC,IAAI,CAAC,MAAM,EACZ,MAAM,IAAIC,MACN;QAIR,MAAMC,YAAY,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI;QAExC,IAAI,CAACA,WACD;QAGJ,IAAI,CAAC,QAAQ,GAAGA,UAAU,MAAM,CAAW,CAACC,KAAKC,OACtC;gBAAE,GAAGD,GAAG;gBAAE,CAACC,KAAK,IAAI,CAAC,EAAEA,KAAK,QAAQ;YAAC,IAC7C,CAAC;QAEJ,OAAO,IAAI,CAAC,QAAQ;IACxB;IAEA,OAAO,QAAc;QACjB,IAAI,CAAC,QAAQ,GAAGC;IACpB;AACJ"}