@webiny/api-file-manager-s3 6.6.0-alpha.11 → 6.6.0-alpha.13

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 (76) hide show
  1. package/FileManagerS3Feature.js +2 -0
  2. package/FileManagerS3Feature.js.map +1 -1
  3. package/assetDelivery/s3/S3ContentsReader.d.ts +1 -0
  4. package/assetDelivery/s3/S3ContentsReader.js +5 -0
  5. package/assetDelivery/s3/S3ContentsReader.js.map +1 -1
  6. package/assetDelivery/s3/transformation/CallableContentsReader.d.ts +1 -0
  7. package/assetDelivery/s3/transformation/CallableContentsReader.js +5 -0
  8. package/assetDelivery/s3/transformation/CallableContentsReader.js.map +1 -1
  9. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.d.ts +8 -8
  10. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js +24 -13
  11. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js.map +1 -1
  12. package/assetDelivery/threatDetection/processThreatScanResult.d.ts +1 -1
  13. package/assetDelivery/threatDetection/processThreatScanResult.js +5 -3
  14. package/assetDelivery/threatDetection/processThreatScanResult.js.map +1 -1
  15. package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js +4 -1
  16. package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js.map +1 -1
  17. package/features/DeleteFileFromBucket/DeleteS3FolderTask.d.ts +3 -0
  18. package/features/DeleteFileFromBucket/DeleteS3FolderTask.js +8 -3
  19. package/features/DeleteFileFromBucket/DeleteS3FolderTask.js.map +1 -1
  20. package/features/FileContentsStorage/S3FileContentsStorage.d.ts +17 -0
  21. package/features/FileContentsStorage/S3FileContentsStorage.js +60 -0
  22. package/features/FileContentsStorage/S3FileContentsStorage.js.map +1 -0
  23. package/features/FileContentsStorage/feature.d.ts +5 -0
  24. package/features/FileContentsStorage/feature.js +11 -0
  25. package/features/FileContentsStorage/feature.js.map +1 -0
  26. package/features/GetFileContentsById/GetFileContentsByIdUseCase.d.ts +6 -1
  27. package/features/GetFileContentsById/GetFileContentsByIdUseCase.js +13 -8
  28. package/features/GetFileContentsById/GetFileContentsByIdUseCase.js.map +1 -1
  29. package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.d.ts +4 -1
  30. package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js +11 -8
  31. package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js.map +1 -1
  32. package/features/WriteFileMetadata/MetadataWriter.js +3 -0
  33. package/features/WriteFileMetadata/MetadataWriter.js.map +1 -1
  34. package/graphql/S3GraphQLSchema.js +17 -8
  35. package/graphql/S3GraphQLSchema.js.map +1 -1
  36. package/index.d.ts +2 -1
  37. package/index.js +1 -1
  38. package/multiPartUpload/CompleteMultiPartUploadUseCase.d.ts +1 -0
  39. package/multiPartUpload/CompleteMultiPartUploadUseCase.js +2 -1
  40. package/multiPartUpload/CompleteMultiPartUploadUseCase.js.map +1 -1
  41. package/multiPartUpload/CreateMultiPartUploadUseCase.d.ts +6 -1
  42. package/multiPartUpload/CreateMultiPartUploadUseCase.js +11 -2
  43. package/multiPartUpload/CreateMultiPartUploadUseCase.js.map +1 -1
  44. package/package.json +18 -22
  45. package/utils/FileNormalizer.test.js +86 -0
  46. package/utils/FileNormalizer.test.js.map +1 -0
  47. package/utils/createFileNormalizerFromContext.d.ts +1 -1
  48. package/utils/createFileNormalizerFromContext.js +2 -2
  49. package/utils/createFileNormalizerFromContext.js.map +1 -1
  50. package/utils/ensureNewFileId.d.ts +13 -0
  51. package/utils/ensureNewFileId.js +26 -0
  52. package/utils/ensureNewFileId.js.map +1 -0
  53. package/utils/getFileStorageKey.d.ts +5 -0
  54. package/utils/getFileStorageKey.js +4 -0
  55. package/utils/getFileStorageKey.js.map +1 -0
  56. package/utils/getPresignedPostPayload.d.ts +6 -1
  57. package/utils/getPresignedPostPayload.js +12 -4
  58. package/utils/getPresignedPostPayload.js.map +1 -1
  59. package/utils/FileExtension.d.ts +0 -6
  60. package/utils/FileExtension.js +0 -16
  61. package/utils/FileExtension.js.map +0 -1
  62. package/utils/FileKey.d.ts +0 -11
  63. package/utils/FileKey.js +0 -33
  64. package/utils/FileKey.js.map +0 -1
  65. package/utils/FileKey.test.js +0 -59
  66. package/utils/FileKey.test.js.map +0 -1
  67. package/utils/FileNormalizer.d.ts +0 -18
  68. package/utils/FileNormalizer.js +0 -48
  69. package/utils/FileNormalizer.js.map +0 -1
  70. package/utils/FileUploadModifier.d.ts +0 -36
  71. package/utils/FileUploadModifier.js +0 -41
  72. package/utils/FileUploadModifier.js.map +0 -1
  73. package/utils/mimeTypes.d.ts +0 -5
  74. package/utils/mimeTypes.js +0 -9
  75. package/utils/mimeTypes.js.map +0 -1
  76. /package/utils/{FileKey.test.d.ts → FileNormalizer.test.d.ts} +0 -0
@@ -7,6 +7,7 @@ import { FlushCacheFeature } from "./features/FlushCache/feature.js";
7
7
  import { ExtractMetadataFeature } from "./features/ExtractMetadata/feature.js";
8
8
  import { GetFileContentsByIdFeature } from "./features/GetFileContentsById/feature.js";
9
9
  import { GetFileContentsByKeyFeature } from "./features/GetFileContentsByKey/feature.js";
10
+ import { FileContentsStorageFeature } from "./features/FileContentsStorage/feature.js";
10
11
  import { createS3AssetDeliveryFeature } from "./assetDelivery/feature.js";
11
12
  const FileManagerS3Feature = createFeature({
12
13
  name: "FileManagerS3",
@@ -18,6 +19,7 @@ const FileManagerS3Feature = createFeature({
18
19
  WriteFileMetadataFeature.register(container);
19
20
  GetFileContentsByIdFeature.register(container);
20
21
  GetFileContentsByKeyFeature.register(container);
22
+ FileContentsStorageFeature.register(container);
21
23
  container.register(S3GraphQLSchema);
22
24
  ApplyThreatScanningFeature.register(container);
23
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FileManagerS3Feature.js","sources":["../src/FileManagerS3Feature.ts"],"sourcesContent":["import { type Container, createFeature } from \"@webiny/feature/api\";\nimport { S3GraphQLSchema } from \"./graphql/S3GraphQLSchema.js\";\nimport { DeleteFileFromBucketFeature } from \"~/features/DeleteFileFromBucket/feature.js\";\nimport { WriteFileMetadataFeature } from \"~/features/WriteFileMetadata/feature.js\";\nimport { ApplyThreatScanningFeature } from \"~/enterprise/ApplyThreatScanning/feature.js\";\nimport { FlushCacheFeature } from \"~/features/FlushCache/feature.js\";\nimport { ExtractMetadataFeature } from \"~/features/ExtractMetadata/feature.js\";\nimport { GetFileContentsByIdFeature } from \"~/features/GetFileContentsById/feature.js\";\nimport { GetFileContentsByKeyFeature } from \"~/features/GetFileContentsByKey/feature.js\";\nimport { createS3AssetDeliveryFeature } from \"./assetDelivery/feature.js\";\nimport type { AssetDeliveryParams } from \"./assetDelivery/types.js\";\n\nexport interface FileManagerS3FeatureConfig {\n assetDelivery?: AssetDeliveryParams;\n}\n\nexport const FileManagerS3Feature = createFeature({\n name: \"FileManagerS3\",\n register(container: Container, config: FileManagerS3FeatureConfig = {}) {\n // Register S3-specific asset delivery implementations (S3AssetResolver, S3OutputStrategy).\n // These replace the null implementations from AssetDeliveryFeature in FileManagerAppFeature.\n createS3AssetDeliveryFeature(config.assetDelivery).register(container);\n\n // S3 file-operation features.\n FlushCacheFeature.register(container);\n DeleteFileFromBucketFeature.register(container);\n ExtractMetadataFeature.register(container);\n WriteFileMetadataFeature.register(container);\n GetFileContentsByIdFeature.register(container);\n GetFileContentsByKeyFeature.register(container);\n\n // Static S3 GraphQL schema (extends FmQuery/FmMutation) — a DI-native\n // CoreGraphQLSchemaFactory contributor (declares its resolver dependencies).\n container.register(S3GraphQLSchema);\n\n // Threat scanning is WCP-gated, but the license is per-request (loaded post-register). Register\n // unconditionally; CreateFileWithThreatScanDecorator + the GuardDuty event handler both guard\n // on canUseFileManagerThreatDetection() at request time and no-op/pass-through when unlicensed.\n ApplyThreatScanningFeature.register(container);\n }\n});\n"],"names":["FileManagerS3Feature","createFeature","container","config","createS3AssetDeliveryFeature","FlushCacheFeature","DeleteFileFromBucketFeature","ExtractMetadataFeature","WriteFileMetadataFeature","GetFileContentsByIdFeature","GetFileContentsByKeyFeature","S3GraphQLSchema","ApplyThreatScanningFeature"],"mappings":";;;;;;;;;;AAgBO,MAAMA,uBAAuBC,cAAc;IAC9C,MAAM;IACN,UAASC,SAAoB,EAAEC,SAAqC,CAAC,CAAC;QAGlEC,6BAA6BD,OAAO,aAAa,EAAE,QAAQ,CAACD;QAG5DG,kBAAkB,QAAQ,CAACH;QAC3BI,4BAA4B,QAAQ,CAACJ;QACrCK,uBAAuB,QAAQ,CAACL;QAChCM,yBAAyB,QAAQ,CAACN;QAClCO,2BAA2B,QAAQ,CAACP;QACpCQ,4BAA4B,QAAQ,CAACR;QAIrCA,UAAU,QAAQ,CAACS;QAKnBC,2BAA2B,QAAQ,CAACV;IACxC;AACJ"}
1
+ {"version":3,"file":"FileManagerS3Feature.js","sources":["../src/FileManagerS3Feature.ts"],"sourcesContent":["import { type Container, createFeature } from \"@webiny/feature/api\";\nimport { S3GraphQLSchema } from \"./graphql/S3GraphQLSchema.js\";\nimport { DeleteFileFromBucketFeature } from \"~/features/DeleteFileFromBucket/feature.js\";\nimport { WriteFileMetadataFeature } from \"~/features/WriteFileMetadata/feature.js\";\nimport { ApplyThreatScanningFeature } from \"~/enterprise/ApplyThreatScanning/feature.js\";\nimport { FlushCacheFeature } from \"~/features/FlushCache/feature.js\";\nimport { ExtractMetadataFeature } from \"~/features/ExtractMetadata/feature.js\";\nimport { GetFileContentsByIdFeature } from \"~/features/GetFileContentsById/feature.js\";\nimport { GetFileContentsByKeyFeature } from \"~/features/GetFileContentsByKey/feature.js\";\nimport { FileContentsStorageFeature } from \"~/features/FileContentsStorage/feature.js\";\nimport { createS3AssetDeliveryFeature } from \"./assetDelivery/feature.js\";\nimport type { AssetDeliveryParams } from \"./assetDelivery/types.js\";\n\nexport interface FileManagerS3FeatureConfig {\n assetDelivery?: AssetDeliveryParams;\n}\n\nexport const FileManagerS3Feature = createFeature({\n name: \"FileManagerS3\",\n register(container: Container, config: FileManagerS3FeatureConfig = {}) {\n // Register S3-specific asset delivery implementations (S3AssetResolver, S3OutputStrategy).\n // These replace the null implementations from AssetDeliveryFeature in FileManagerAppFeature.\n createS3AssetDeliveryFeature(config.assetDelivery).register(container);\n\n // S3 file-operation features.\n FlushCacheFeature.register(container);\n DeleteFileFromBucketFeature.register(container);\n ExtractMetadataFeature.register(container);\n WriteFileMetadataFeature.register(container);\n GetFileContentsByIdFeature.register(container);\n GetFileContentsByKeyFeature.register(container);\n FileContentsStorageFeature.register(container);\n\n // Static S3 GraphQL schema (extends FmQuery/FmMutation) — a DI-native\n // CoreGraphQLSchemaFactory contributor (declares its resolver dependencies).\n container.register(S3GraphQLSchema);\n\n // Threat scanning is WCP-gated, but the license is per-request (loaded post-register). Register\n // unconditionally; CreateFileWithThreatScanDecorator + the GuardDuty event handler both guard\n // on canUseFileManagerThreatDetection() at request time and no-op/pass-through when unlicensed.\n ApplyThreatScanningFeature.register(container);\n }\n});\n"],"names":["FileManagerS3Feature","createFeature","container","config","createS3AssetDeliveryFeature","FlushCacheFeature","DeleteFileFromBucketFeature","ExtractMetadataFeature","WriteFileMetadataFeature","GetFileContentsByIdFeature","GetFileContentsByKeyFeature","FileContentsStorageFeature","S3GraphQLSchema","ApplyThreatScanningFeature"],"mappings":";;;;;;;;;;;AAiBO,MAAMA,uBAAuBC,cAAc;IAC9C,MAAM;IACN,UAASC,SAAoB,EAAEC,SAAqC,CAAC,CAAC;QAGlEC,6BAA6BD,OAAO,aAAa,EAAE,QAAQ,CAACD;QAG5DG,kBAAkB,QAAQ,CAACH;QAC3BI,4BAA4B,QAAQ,CAACJ;QACrCK,uBAAuB,QAAQ,CAACL;QAChCM,yBAAyB,QAAQ,CAACN;QAClCO,2BAA2B,QAAQ,CAACP;QACpCQ,4BAA4B,QAAQ,CAACR;QACrCS,2BAA2B,QAAQ,CAACT;QAIpCA,UAAU,QAAQ,CAACU;QAKnBC,2BAA2B,QAAQ,CAACX;IACxC;AACJ"}
@@ -5,4 +5,5 @@ export declare class S3ContentsReader implements AssetContentsReader {
5
5
  private readonly bucket;
6
6
  constructor(s3: S3, bucket: string);
7
7
  read(asset: Asset): Promise<Buffer>;
8
+ readStream(asset: Asset): Promise<AsyncIterable<Uint8Array>>;
8
9
  }
@@ -1,3 +1,4 @@
1
+ import { toSingleChunk } from "@webiny/api-file-manager";
1
2
  class S3ContentsReader {
2
3
  constructor(s3, bucket){
3
4
  this.s3 = s3;
@@ -11,6 +12,10 @@ class S3ContentsReader {
11
12
  if (!Body) throw Error(`Unable to read ${asset.getKey()}!`);
12
13
  return Buffer.from(await Body.transformToByteArray());
13
14
  }
15
+ async readStream(asset) {
16
+ const contents = await this.read(asset);
17
+ return toSingleChunk(contents);
18
+ }
14
19
  }
15
20
  export { S3ContentsReader };
16
21
 
@@ -1 +1 @@
1
- {"version":3,"file":"assetDelivery/s3/S3ContentsReader.js","sources":["../../../src/assetDelivery/s3/S3ContentsReader.ts"],"sourcesContent":["import type { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport type { Asset, AssetContentsReader } from \"@webiny/api-file-manager\";\n\nexport class S3ContentsReader implements AssetContentsReader {\n private s3: S3;\n private readonly bucket: string;\n\n constructor(s3: S3, bucket: string) {\n this.s3 = s3;\n this.bucket = bucket;\n }\n\n async read(asset: Asset): Promise<Buffer> {\n const { Body } = await this.s3.getObject({\n Bucket: this.bucket,\n Key: asset.getKey()\n });\n\n if (!Body) {\n throw Error(`Unable to read ${asset.getKey()}!`);\n }\n\n return Buffer.from(await Body.transformToByteArray());\n }\n}\n"],"names":["S3ContentsReader","s3","bucket","asset","Body","Error","Buffer"],"mappings":"AAGO,MAAMA;IAIT,YAAYC,EAAM,EAAEC,MAAc,CAAE;QAChC,IAAI,CAAC,EAAE,GAAGD;QACV,IAAI,CAAC,MAAM,GAAGC;IAClB;IAEA,MAAM,KAAKC,KAAY,EAAmB;QACtC,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC;YACrC,QAAQ,IAAI,CAAC,MAAM;YACnB,KAAKD,MAAM,MAAM;QACrB;QAEA,IAAI,CAACC,MACD,MAAMC,MAAM,CAAC,eAAe,EAAEF,MAAM,MAAM,GAAG,CAAC,CAAC;QAGnD,OAAOG,OAAO,IAAI,CAAC,MAAMF,KAAK,oBAAoB;IACtD;AACJ"}
1
+ {"version":3,"file":"assetDelivery/s3/S3ContentsReader.js","sources":["../../../src/assetDelivery/s3/S3ContentsReader.ts"],"sourcesContent":["import type { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport type { Asset, AssetContentsReader } from \"@webiny/api-file-manager\";\nimport { toSingleChunk } from \"@webiny/api-file-manager\";\n\nexport class S3ContentsReader implements AssetContentsReader {\n private s3: S3;\n private readonly bucket: string;\n\n constructor(s3: S3, bucket: string) {\n this.s3 = s3;\n this.bucket = bucket;\n }\n\n async read(asset: Asset): Promise<Buffer> {\n const { Body } = await this.s3.getObject({\n Bucket: this.bucket,\n Key: asset.getKey()\n });\n\n if (!Body) {\n throw Error(`Unable to read ${asset.getKey()}!`);\n }\n\n return Buffer.from(await Body.transformToByteArray());\n }\n\n /*\n * One chunk: on AWS, `S3OutputStrategy` redirects large files to a presigned URL and API\n * Gateway buffers the response anyway, so there is nothing to gain from streaming here.\n */\n async readStream(asset: Asset): Promise<AsyncIterable<Uint8Array>> {\n const contents = await this.read(asset);\n return toSingleChunk(contents);\n }\n}\n"],"names":["S3ContentsReader","s3","bucket","asset","Body","Error","Buffer","contents","toSingleChunk"],"mappings":";AAIO,MAAMA;IAIT,YAAYC,EAAM,EAAEC,MAAc,CAAE;QAChC,IAAI,CAAC,EAAE,GAAGD;QACV,IAAI,CAAC,MAAM,GAAGC;IAClB;IAEA,MAAM,KAAKC,KAAY,EAAmB;QACtC,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC;YACrC,QAAQ,IAAI,CAAC,MAAM;YACnB,KAAKD,MAAM,MAAM;QACrB;QAEA,IAAI,CAACC,MACD,MAAMC,MAAM,CAAC,eAAe,EAAEF,MAAM,MAAM,GAAG,CAAC,CAAC;QAGnD,OAAOG,OAAO,IAAI,CAAC,MAAMF,KAAK,oBAAoB;IACtD;IAMA,MAAM,WAAWD,KAAY,EAAsC;QAC/D,MAAMI,WAAW,MAAM,IAAI,CAAC,IAAI,CAACJ;QACjC,OAAOK,cAAcD;IACzB;AACJ"}
@@ -6,5 +6,6 @@ export declare class CallableContentsReader implements AssetContentsReader {
6
6
  private readonly callable;
7
7
  constructor(callable: ContentsCallable);
8
8
  read(): Promise<Buffer>;
9
+ readStream(): Promise<AsyncIterable<Uint8Array>>;
9
10
  }
10
11
  export {};
@@ -1,3 +1,4 @@
1
+ import { toSingleChunk } from "@webiny/api-file-manager";
1
2
  class CallableContentsReader {
2
3
  constructor(callable){
3
4
  this.callable = callable;
@@ -5,6 +6,10 @@ class CallableContentsReader {
5
6
  async read() {
6
7
  return this.callable();
7
8
  }
9
+ async readStream() {
10
+ const contents = await this.read();
11
+ return toSingleChunk(contents);
12
+ }
8
13
  }
9
14
  export { CallableContentsReader };
10
15
 
@@ -1 +1 @@
1
- {"version":3,"file":"assetDelivery/s3/transformation/CallableContentsReader.js","sources":["../../../../src/assetDelivery/s3/transformation/CallableContentsReader.ts"],"sourcesContent":["import type { AssetContentsReader } from \"@webiny/api-file-manager\";\n\ninterface ContentsCallable {\n (): Promise<Buffer> | Buffer;\n}\n\nexport class CallableContentsReader implements AssetContentsReader {\n private readonly callable: ContentsCallable;\n\n constructor(callable: ContentsCallable) {\n this.callable = callable;\n }\n\n async read(): Promise<Buffer> {\n return this.callable();\n }\n}\n"],"names":["CallableContentsReader","callable"],"mappings":"AAMO,MAAMA;IAGT,YAAYC,QAA0B,CAAE;QACpC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,OAAwB;QAC1B,OAAO,IAAI,CAAC,QAAQ;IACxB;AACJ"}
1
+ {"version":3,"file":"assetDelivery/s3/transformation/CallableContentsReader.js","sources":["../../../../src/assetDelivery/s3/transformation/CallableContentsReader.ts"],"sourcesContent":["import type { AssetContentsReader } from \"@webiny/api-file-manager\";\nimport { toSingleChunk } from \"@webiny/api-file-manager\";\n\ninterface ContentsCallable {\n (): Promise<Buffer> | Buffer;\n}\n\nexport class CallableContentsReader implements AssetContentsReader {\n private readonly callable: ContentsCallable;\n\n constructor(callable: ContentsCallable) {\n this.callable = callable;\n }\n\n async read(): Promise<Buffer> {\n return this.callable();\n }\n\n async readStream(): Promise<AsyncIterable<Uint8Array>> {\n const contents = await this.read();\n return toSingleChunk(contents);\n }\n}\n"],"names":["CallableContentsReader","callable","contents","toSingleChunk"],"mappings":";AAOO,MAAMA;IAGT,YAAYC,QAA0B,CAAE;QACpC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,OAAwB;QAC1B,OAAO,IAAI,CAAC,QAAQ;IACxB;IAEA,MAAM,aAAiD;QACnD,MAAMC,WAAW,MAAM,IAAI,CAAC,IAAI;QAChC,OAAOC,cAAcD;IACzB;AACJ"}
@@ -1,19 +1,19 @@
1
1
  import type { Container } from "@webiny/feature/api";
2
2
  import type { EventBridgeEvent } from "@webiny/aws-sdk/types/index.js";
3
- import { EventBridgeEventHandler, type EventBridgeResult } from "@webiny/event-handler-aws/abstractions/handlers/EventBridgeEventHandler.js";
4
- import type { ITenantContext } from "@webiny/api-core/features/tenancy/TenantContext/abstractions.js";
3
+ import { EventBridgeInputHandler, type EventBridgeResult } from "@webiny/api-kernel-aws/abstractions/handlers/EventBridgeInputHandler.js";
5
4
  import type { IGetTenantByIdUseCase } from "@webiny/api-core/features/tenancy/GetTenantById/abstractions.js";
6
- import type { EventContext, NextFunction } from "@webiny/event-handler-core";
5
+ import { TenantScopes } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
6
+ import type { InputContext, NextFunction } from "@webiny/api-kernel-core";
7
7
  import type { GuardDutyEvent } from "./types.js";
8
- declare class ThreatDetectionEventBridgeLambdaHandlerImpl implements EventBridgeEventHandler.Interface {
8
+ declare class ThreatDetectionEventBridgeLambdaHandlerImpl implements EventBridgeInputHandler.Interface {
9
9
  private container;
10
- private tenantCtx;
10
+ private tenantScopes;
11
11
  private getTenantById;
12
- constructor(container: Container, tenantCtx: ITenantContext, getTenantById: IGetTenantByIdUseCase);
13
- execute(eventCtx: EventContext<EventBridgeEvent<string, GuardDutyEvent>>, _next: NextFunction): Promise<EventBridgeResult>;
12
+ constructor(container: Container, tenantScopes: TenantScopes.Interface, getTenantById: IGetTenantByIdUseCase);
13
+ execute(inputCtx: InputContext<EventBridgeEvent<string, GuardDutyEvent>>, _next: NextFunction): Promise<EventBridgeResult>;
14
14
  }
15
15
  export declare const ThreatDetectionEventBridgeLambdaHandler: typeof ThreatDetectionEventBridgeLambdaHandlerImpl & {
16
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/event-handler-aws/abstractions/handlers/EventBridgeEventHandler.js").IEventBridgeEventHandler>;
16
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-kernel-aws/abstractions/handlers/EventBridgeInputHandler.js").IEventBridgeInputHandler>;
17
17
  };
18
18
  /**
19
19
  * @deprecated Use ThreatDetectionEventBridgeLambdaHandler instead.
@@ -1,20 +1,20 @@
1
- import { EventBridgeEventHandler } from "@webiny/event-handler-aws/abstractions/handlers/EventBridgeEventHandler.js";
2
- import { RequestContainer } from "@webiny/event-handler-core";
3
- import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
1
+ import { EventBridgeInputHandler } from "@webiny/api-kernel-aws/abstractions/handlers/EventBridgeInputHandler.js";
2
+ import { RequestContainer } from "@webiny/api-kernel-core";
4
3
  import { GetTenantByIdUseCase } from "@webiny/api-core/features/tenancy/GetTenantById/index.js";
4
+ import { TenantScopes } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
5
5
  import { FeatureFlags } from "@webiny/api-core/features/featureFlags/abstractions.js";
6
6
  import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
7
7
  import { processThreatScanResult } from "./processThreatScanResult.js";
8
8
  import { ObjectKey } from "./ObjectKey.js";
9
9
  const DETAIL_TYPE = "GuardDuty Malware Protection Object Scan Result";
10
10
  class ThreatDetectionEventBridgeLambdaHandlerImpl {
11
- constructor(container, tenantCtx, getTenantById){
11
+ constructor(container, tenantScopes, getTenantById){
12
12
  this.container = container;
13
- this.tenantCtx = tenantCtx;
13
+ this.tenantScopes = tenantScopes;
14
14
  this.getTenantById = getTenantById;
15
15
  }
16
- async execute(eventCtx, _next) {
17
- const payload = eventCtx.event;
16
+ async execute(inputCtx, _next) {
17
+ const payload = inputCtx.input;
18
18
  if (payload["detail-type"] !== DETAIL_TYPE) return {
19
19
  success: true
20
20
  };
@@ -23,27 +23,38 @@ class ThreatDetectionEventBridgeLambdaHandlerImpl {
23
23
  };
24
24
  const objectKey = payload.detail.s3ObjectDetails.objectKey;
25
25
  const keyValueStore = this.container.resolve(GlobalKeyValueStore);
26
+ let tenant = null;
26
27
  try {
27
28
  const fileId = ObjectKey.from(objectKey).id();
28
29
  const result = await keyValueStore.get(`FileManager/File/${fileId}/Metadata`);
29
30
  if (result.isOk()) {
30
31
  const tenantResult = await this.getTenantById.execute(result.value.tenant);
31
- if (tenantResult.isOk()) this.tenantCtx.setTenant(tenantResult.value);
32
+ if (tenantResult.isOk()) tenant = tenantResult.value;
32
33
  }
33
34
  } catch {}
34
- await processThreatScanResult({
35
- container: this.container
36
- }, payload.detail);
35
+ if (!tenant) {
36
+ await processThreatScanResult({
37
+ container: this.container
38
+ }, payload.detail, null);
39
+ return {
40
+ success: true
41
+ };
42
+ }
43
+ await this.tenantScopes.withTenant(tenant, async (scope)=>{
44
+ await processThreatScanResult({
45
+ container: scope.resolve(RequestContainer)
46
+ }, payload.detail, scope.tenant.id);
47
+ });
37
48
  return {
38
49
  success: true
39
50
  };
40
51
  }
41
52
  }
42
- const ThreatDetectionEventBridgeLambdaHandler = EventBridgeEventHandler.createImplementation({
53
+ const ThreatDetectionEventBridgeLambdaHandler = EventBridgeInputHandler.createImplementation({
43
54
  implementation: ThreatDetectionEventBridgeLambdaHandlerImpl,
44
55
  dependencies: [
45
56
  RequestContainer,
46
- TenantContext,
57
+ TenantScopes,
47
58
  GetTenantByIdUseCase
48
59
  ]
49
60
  });
@@ -1 +1 @@
1
- {"version":3,"file":"assetDelivery/threatDetection/createThreatDetectionEventHandler.js","sources":["../../../src/assetDelivery/threatDetection/createThreatDetectionEventHandler.ts"],"sourcesContent":["import type { Container } from \"@webiny/feature/api\";\nimport type { EventBridgeEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport {\n EventBridgeEventHandler,\n type EventBridgeResult\n} from \"@webiny/event-handler-aws/abstractions/handlers/EventBridgeEventHandler.js\";\nimport { RequestContainer } from \"@webiny/event-handler-core\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetTenantByIdUseCase } from \"@webiny/api-core/features/tenancy/GetTenantById/index.js\";\nimport type { ITenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/abstractions.js\";\nimport type { IGetTenantByIdUseCase } from \"@webiny/api-core/features/tenancy/GetTenantById/abstractions.js\";\nimport type { EventContext, NextFunction } from \"@webiny/event-handler-core\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport { FeatureFlags } from \"@webiny/api-core/features/featureFlags/abstractions.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { processThreatScanResult } from \"./processThreatScanResult.js\";\nimport { ObjectKey } from \"./ObjectKey.js\";\nimport type { GuardDutyEvent } from \"./types.js\";\n\nconst DETAIL_TYPE = \"GuardDuty Malware Protection Object Scan Result\";\n\nclass ThreatDetectionEventBridgeLambdaHandlerImpl implements EventBridgeEventHandler.Interface {\n constructor(\n private container: Container,\n private tenantCtx: ITenantContext,\n private getTenantById: IGetTenantByIdUseCase\n ) {}\n\n async execute(\n eventCtx: EventContext<EventBridgeEvent<string, GuardDutyEvent>>,\n _next: NextFunction\n ): Promise<EventBridgeResult> {\n const payload = eventCtx.event;\n if (payload[\"detail-type\"] !== DETAIL_TYPE) {\n return { success: true };\n }\n\n if (!this.container.resolve(FeatureFlags).get().isEnabled(\"fileManager.threatDetection\")) {\n return { success: true };\n }\n\n const objectKey = payload.detail.s3ObjectDetails.objectKey;\n const keyValueStore = this.container.resolve(GlobalKeyValueStore);\n\n try {\n const fileId = ObjectKey.from(objectKey).id();\n const result = await keyValueStore.get<{ tenant: string }>(\n `FileManager/File/${fileId}/Metadata`\n );\n\n if (result.isOk()) {\n const tenantResult = await this.getTenantById.execute(result.value.tenant);\n if (tenantResult.isOk()) {\n this.tenantCtx.setTenant(tenantResult.value);\n }\n }\n } catch {\n // If metadata can't be loaded, ignore — likely a rendition file.\n }\n\n await processThreatScanResult(\n { container: this.container } as unknown as ApiCoreContext,\n payload.detail\n );\n return { success: true };\n }\n}\n\nexport const ThreatDetectionEventBridgeLambdaHandler = EventBridgeEventHandler.createImplementation(\n {\n implementation: ThreatDetectionEventBridgeLambdaHandlerImpl,\n dependencies: [RequestContainer, TenantContext, GetTenantByIdUseCase]\n }\n);\n\n/**\n * @deprecated Use ThreatDetectionEventBridgeLambdaHandler instead.\n */\nexport const createThreatDetectionEventHandler = () => {\n return [];\n};\n"],"names":["DETAIL_TYPE","ThreatDetectionEventBridgeLambdaHandlerImpl","container","tenantCtx","getTenantById","eventCtx","_next","payload","FeatureFlags","objectKey","keyValueStore","GlobalKeyValueStore","fileId","ObjectKey","result","tenantResult","processThreatScanResult","ThreatDetectionEventBridgeLambdaHandler","EventBridgeEventHandler","RequestContainer","TenantContext","GetTenantByIdUseCase","createThreatDetectionEventHandler"],"mappings":";;;;;;;;AAmBA,MAAMA,cAAc;AAEpB,MAAMC;IACF,YACYC,SAAoB,EACpBC,SAAyB,EACzBC,aAAoC,CAC9C;aAHUF,SAAS,GAATA;aACAC,SAAS,GAATA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,QAAgE,EAChEC,KAAmB,EACO;QAC1B,MAAMC,UAAUF,SAAS,KAAK;QAC9B,IAAIE,OAAO,CAAC,cAAc,KAAKP,aAC3B,OAAO;YAAE,SAAS;QAAK;QAG3B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAACQ,cAAc,GAAG,GAAG,SAAS,CAAC,gCACtD,OAAO;YAAE,SAAS;QAAK;QAG3B,MAAMC,YAAYF,QAAQ,MAAM,CAAC,eAAe,CAAC,SAAS;QAC1D,MAAMG,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAE7C,IAAI;YACA,MAAMC,SAASC,UAAU,IAAI,CAACJ,WAAW,EAAE;YAC3C,MAAMK,SAAS,MAAMJ,cAAc,GAAG,CAClC,CAAC,iBAAiB,EAAEE,OAAO,SAAS,CAAC;YAGzC,IAAIE,OAAO,IAAI,IAAI;gBACf,MAAMC,eAAe,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACD,OAAO,KAAK,CAAC,MAAM;gBACzE,IAAIC,aAAa,IAAI,IACjB,IAAI,CAAC,SAAS,CAAC,SAAS,CAACA,aAAa,KAAK;YAEnD;QACJ,EAAE,OAAM,CAER;QAEA,MAAMC,wBACF;YAAE,WAAW,IAAI,CAAC,SAAS;QAAC,GAC5BT,QAAQ,MAAM;QAElB,OAAO;YAAE,SAAS;QAAK;IAC3B;AACJ;AAEO,MAAMU,0CAA0CC,wBAAwB,oBAAoB,CAC/F;IACI,gBAAgBjB;IAChB,cAAc;QAACkB;QAAkBC;QAAeC;KAAqB;AACzE;AAMG,MAAMC,oCAAoC,IACtC,EAAE"}
1
+ {"version":3,"file":"assetDelivery/threatDetection/createThreatDetectionEventHandler.js","sources":["../../../src/assetDelivery/threatDetection/createThreatDetectionEventHandler.ts"],"sourcesContent":["import type { Container } from \"@webiny/feature/api\";\nimport type { EventBridgeEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport {\n EventBridgeInputHandler,\n type EventBridgeResult\n} from \"@webiny/api-kernel-aws/abstractions/handlers/EventBridgeInputHandler.js\";\nimport { RequestContainer } from \"@webiny/api-kernel-core\";\nimport { GetTenantByIdUseCase } from \"@webiny/api-core/features/tenancy/GetTenantById/index.js\";\nimport type { IGetTenantByIdUseCase } from \"@webiny/api-core/features/tenancy/GetTenantById/abstractions.js\";\nimport { TenantScopes } from \"@webiny/api-core/features/tenancy/TenantScopes/index.js\";\nimport type { Tenant } from \"@webiny/api-core/types/tenancy.js\";\nimport type { InputContext, NextFunction } from \"@webiny/api-kernel-core\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport { FeatureFlags } from \"@webiny/api-core/features/featureFlags/abstractions.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { processThreatScanResult } from \"./processThreatScanResult.js\";\nimport { ObjectKey } from \"./ObjectKey.js\";\nimport type { GuardDutyEvent } from \"./types.js\";\n\nconst DETAIL_TYPE = \"GuardDuty Malware Protection Object Scan Result\";\n\nclass ThreatDetectionEventBridgeLambdaHandlerImpl implements EventBridgeInputHandler.Interface {\n constructor(\n private container: Container,\n private tenantScopes: TenantScopes.Interface,\n private getTenantById: IGetTenantByIdUseCase\n ) {}\n\n async execute(\n inputCtx: InputContext<EventBridgeEvent<string, GuardDutyEvent>>,\n _next: NextFunction\n ): Promise<EventBridgeResult> {\n const payload = inputCtx.input;\n if (payload[\"detail-type\"] !== DETAIL_TYPE) {\n return { success: true };\n }\n\n if (!this.container.resolve(FeatureFlags).get().isEnabled(\"fileManager.threatDetection\")) {\n return { success: true };\n }\n\n const objectKey = payload.detail.s3ObjectDetails.objectKey;\n const keyValueStore = this.container.resolve(GlobalKeyValueStore);\n let tenant: Tenant | null = null;\n\n try {\n const fileId = ObjectKey.from(objectKey).id();\n const result = await keyValueStore.get<{ tenant: string }>(\n `FileManager/File/${fileId}/Metadata`\n );\n\n if (result.isOk()) {\n const tenantResult = await this.getTenantById.execute(result.value.tenant);\n if (tenantResult.isOk()) {\n tenant = tenantResult.value;\n }\n }\n } catch {\n // If metadata can't be loaded, ignore — likely a rendition file.\n }\n\n if (!tenant) {\n await processThreatScanResult(\n { container: this.container } as unknown as ApiCoreContext,\n payload.detail,\n null\n );\n return { success: true };\n }\n\n // The file is the tenant's: handle it with that tenant's services.\n await this.tenantScopes.withTenant(tenant, async scope => {\n await processThreatScanResult(\n { container: scope.resolve(RequestContainer) } as unknown as ApiCoreContext,\n payload.detail,\n scope.tenant.id\n );\n });\n return { success: true };\n }\n}\n\nexport const ThreatDetectionEventBridgeLambdaHandler = EventBridgeInputHandler.createImplementation(\n {\n implementation: ThreatDetectionEventBridgeLambdaHandlerImpl,\n dependencies: [RequestContainer, TenantScopes, GetTenantByIdUseCase]\n }\n);\n\n/**\n * @deprecated Use ThreatDetectionEventBridgeLambdaHandler instead.\n */\nexport const createThreatDetectionEventHandler = () => {\n return [];\n};\n"],"names":["DETAIL_TYPE","ThreatDetectionEventBridgeLambdaHandlerImpl","container","tenantScopes","getTenantById","inputCtx","_next","payload","FeatureFlags","objectKey","keyValueStore","GlobalKeyValueStore","tenant","fileId","ObjectKey","result","tenantResult","processThreatScanResult","scope","RequestContainer","ThreatDetectionEventBridgeLambdaHandler","EventBridgeInputHandler","TenantScopes","GetTenantByIdUseCase","createThreatDetectionEventHandler"],"mappings":";;;;;;;;AAmBA,MAAMA,cAAc;AAEpB,MAAMC;IACF,YACYC,SAAoB,EACpBC,YAAoC,EACpCC,aAAoC,CAC9C;aAHUF,SAAS,GAATA;aACAC,YAAY,GAAZA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,QAAgE,EAChEC,KAAmB,EACO;QAC1B,MAAMC,UAAUF,SAAS,KAAK;QAC9B,IAAIE,OAAO,CAAC,cAAc,KAAKP,aAC3B,OAAO;YAAE,SAAS;QAAK;QAG3B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAACQ,cAAc,GAAG,GAAG,SAAS,CAAC,gCACtD,OAAO;YAAE,SAAS;QAAK;QAG3B,MAAMC,YAAYF,QAAQ,MAAM,CAAC,eAAe,CAAC,SAAS;QAC1D,MAAMG,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC7C,IAAIC,SAAwB;QAE5B,IAAI;YACA,MAAMC,SAASC,UAAU,IAAI,CAACL,WAAW,EAAE;YAC3C,MAAMM,SAAS,MAAML,cAAc,GAAG,CAClC,CAAC,iBAAiB,EAAEG,OAAO,SAAS,CAAC;YAGzC,IAAIE,OAAO,IAAI,IAAI;gBACf,MAAMC,eAAe,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACD,OAAO,KAAK,CAAC,MAAM;gBACzE,IAAIC,aAAa,IAAI,IACjBJ,SAASI,aAAa,KAAK;YAEnC;QACJ,EAAE,OAAM,CAER;QAEA,IAAI,CAACJ,QAAQ;YACT,MAAMK,wBACF;gBAAE,WAAW,IAAI,CAAC,SAAS;YAAC,GAC5BV,QAAQ,MAAM,EACd;YAEJ,OAAO;gBAAE,SAAS;YAAK;QAC3B;QAGA,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAACK,QAAQ,OAAMM;YAC7C,MAAMD,wBACF;gBAAE,WAAWC,MAAM,OAAO,CAACC;YAAkB,GAC7CZ,QAAQ,MAAM,EACdW,MAAM,MAAM,CAAC,EAAE;QAEvB;QACA,OAAO;YAAE,SAAS;QAAK;IAC3B;AACJ;AAEO,MAAME,0CAA0CC,wBAAwB,oBAAoB,CAC/F;IACI,gBAAgBpB;IAChB,cAAc;QAACkB;QAAkBG;QAAcC;KAAqB;AACxE;AAMG,MAAMC,oCAAoC,IACtC,EAAE"}
@@ -1,3 +1,3 @@
1
1
  import type { ApiCoreContext } from "@webiny/api-core/types/core.js";
2
2
  import type { GuardDutyEvent } from "./types.js";
3
- export declare const processThreatScanResult: (context: ApiCoreContext, eventDetail: GuardDutyEvent) => Promise<void>;
3
+ export declare const processThreatScanResult: (context: ApiCoreContext, eventDetail: GuardDutyEvent, tenant: string | null) => Promise<void>;
@@ -4,7 +4,7 @@ import { WebsocketsListConnectionsUseCase, WebsocketsSendToConnectionsUseCase }
4
4
  import { ObjectKey } from "./ObjectKey.js";
5
5
  import { GetFileUseCase } from "@webiny/api-file-manager/features/file/GetFile/index.js";
6
6
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
7
- const processThreatScanResult = async (context, eventDetail)=>{
7
+ const processThreatScanResult = async (context, eventDetail, tenant)=>{
8
8
  const listConnections = context.container.resolve(WebsocketsListConnectionsUseCase);
9
9
  const sendToConnections = context.container.resolve(WebsocketsSendToConnectionsUseCase);
10
10
  const getFile = context.container.resolve(GetFileUseCase);
@@ -18,8 +18,10 @@ const processThreatScanResult = async (context, eventDetail)=>{
18
18
  if (fileResult.isFail()) return;
19
19
  const file = fileResult.value;
20
20
  let allConnections = [];
21
- const connectionsResult = await listConnections.execute();
22
- if (connectionsResult.isOk()) allConnections = connectionsResult.value;
21
+ if (tenant) {
22
+ const connectionsResult = await listConnections.execute();
23
+ if (connectionsResult.isOk()) allConnections = connectionsResult.value;
24
+ }
23
25
  if ("NO_THREATS_FOUND" === scanStatus) {
24
26
  const newTags = file.tags.filter((tag)=>"threatScanInProgress" !== tag);
25
27
  await updateFile.execute({
@@ -1 +1 @@
1
- {"version":3,"file":"assetDelivery/threatDetection/processThreatScanResult.js","sources":["../../../src/assetDelivery/threatDetection/processThreatScanResult.ts"],"sourcesContent":["import type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport { UpdateFileUseCase } from \"@webiny/api-file-manager/features/file/UpdateFile/index.js\";\nimport { DeleteFileUseCase } from \"@webiny/api-file-manager/features/file/DeleteFile/index.js\";\nimport {\n WebsocketsListConnectionsUseCase,\n WebsocketsSendToConnectionsUseCase,\n ConnectionRegistry\n} from \"@webiny/api-websockets/exports/api.js\";\nimport type { GuardDutyEvent } from \"./types.js\";\nimport { ObjectKey } from \"./ObjectKey.js\";\nimport { GetFileUseCase } from \"@webiny/api-file-manager/features/file/GetFile/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\n\nexport const processThreatScanResult = async (\n context: ApiCoreContext,\n eventDetail: GuardDutyEvent\n) => {\n const listConnections = context.container.resolve(WebsocketsListConnectionsUseCase);\n const sendToConnections = context.container.resolve(WebsocketsSendToConnectionsUseCase);\n const getFile = context.container.resolve(GetFileUseCase);\n const updateFile = context.container.resolve(UpdateFileUseCase);\n const deleteFile = context.container.resolve(DeleteFileUseCase);\n\n await context.container.resolve(IdentityContext).withoutAuthorization(async () => {\n const scanStatus = eventDetail.scanResultDetails.scanResultStatus;\n const s3Object = eventDetail.s3ObjectDetails;\n\n const fileId = ObjectKey.from(s3Object.objectKey).id();\n const fileResult = await getFile.execute(fileId);\n\n if (fileResult.isFail()) {\n return;\n }\n\n const file = fileResult.value;\n\n let allConnections: ConnectionRegistry.Data[] = [];\n const connectionsResult = await listConnections.execute();\n if (connectionsResult.isOk()) {\n allConnections = connectionsResult.value;\n }\n\n if (scanStatus === \"NO_THREATS_FOUND\") {\n const newTags = file.tags.filter(tag => tag !== \"threatScanInProgress\");\n await updateFile.execute({\n id: file.id,\n tags: newTags\n });\n\n await sendToConnections.execute(allConnections, {\n action: \"fm.threatScan.noThreatFound\",\n data: {\n id: file.id,\n tags: newTags\n }\n });\n\n return;\n }\n\n if (scanStatus === \"THREATS_FOUND\") {\n // Delete the infected file.\n await deleteFile.execute(file.id);\n\n await sendToConnections.execute(allConnections, {\n action: \"fm.threatScan.threatDetected\",\n data: {\n id: file.id,\n name: file.name\n }\n });\n\n return;\n }\n\n // For all other outcomes, we delete the file, until better logic is implemented.\n await deleteFile.execute(file.id);\n\n await sendToConnections.execute(allConnections, {\n action: \"fm.threatScan.unsupported\",\n data: {\n id: file.id,\n name: file.name\n }\n });\n });\n};\n"],"names":["processThreatScanResult","context","eventDetail","listConnections","WebsocketsListConnectionsUseCase","sendToConnections","WebsocketsSendToConnectionsUseCase","getFile","GetFileUseCase","updateFile","UpdateFileUseCase","deleteFile","DeleteFileUseCase","IdentityContext","scanStatus","s3Object","fileId","ObjectKey","fileResult","file","allConnections","connectionsResult","newTags","tag"],"mappings":";;;;;;AAaO,MAAMA,0BAA0B,OACnCC,SACAC;IAEA,MAAMC,kBAAkBF,QAAQ,SAAS,CAAC,OAAO,CAACG;IAClD,MAAMC,oBAAoBJ,QAAQ,SAAS,CAAC,OAAO,CAACK;IACpD,MAAMC,UAAUN,QAAQ,SAAS,CAAC,OAAO,CAACO;IAC1C,MAAMC,aAAaR,QAAQ,SAAS,CAAC,OAAO,CAACS;IAC7C,MAAMC,aAAaV,QAAQ,SAAS,CAAC,OAAO,CAACW;IAE7C,MAAMX,QAAQ,SAAS,CAAC,OAAO,CAACY,iBAAiB,oBAAoB,CAAC;QAClE,MAAMC,aAAaZ,YAAY,iBAAiB,CAAC,gBAAgB;QACjE,MAAMa,WAAWb,YAAY,eAAe;QAE5C,MAAMc,SAASC,UAAU,IAAI,CAACF,SAAS,SAAS,EAAE,EAAE;QACpD,MAAMG,aAAa,MAAMX,QAAQ,OAAO,CAACS;QAEzC,IAAIE,WAAW,MAAM,IACjB;QAGJ,MAAMC,OAAOD,WAAW,KAAK;QAE7B,IAAIE,iBAA4C,EAAE;QAClD,MAAMC,oBAAoB,MAAMlB,gBAAgB,OAAO;QACvD,IAAIkB,kBAAkB,IAAI,IACtBD,iBAAiBC,kBAAkB,KAAK;QAG5C,IAAIP,AAAe,uBAAfA,YAAmC;YACnC,MAAMQ,UAAUH,KAAK,IAAI,CAAC,MAAM,CAACI,CAAAA,MAAOA,AAAQ,2BAARA;YACxC,MAAMd,WAAW,OAAO,CAAC;gBACrB,IAAIU,KAAK,EAAE;gBACX,MAAMG;YACV;YAEA,MAAMjB,kBAAkB,OAAO,CAACe,gBAAgB;gBAC5C,QAAQ;gBACR,MAAM;oBACF,IAAID,KAAK,EAAE;oBACX,MAAMG;gBACV;YACJ;YAEA;QACJ;QAEA,IAAIR,AAAe,oBAAfA,YAAgC;YAEhC,MAAMH,WAAW,OAAO,CAACQ,KAAK,EAAE;YAEhC,MAAMd,kBAAkB,OAAO,CAACe,gBAAgB;gBAC5C,QAAQ;gBACR,MAAM;oBACF,IAAID,KAAK,EAAE;oBACX,MAAMA,KAAK,IAAI;gBACnB;YACJ;YAEA;QACJ;QAGA,MAAMR,WAAW,OAAO,CAACQ,KAAK,EAAE;QAEhC,MAAMd,kBAAkB,OAAO,CAACe,gBAAgB;YAC5C,QAAQ;YACR,MAAM;gBACF,IAAID,KAAK,EAAE;gBACX,MAAMA,KAAK,IAAI;YACnB;QACJ;IACJ;AACJ"}
1
+ {"version":3,"file":"assetDelivery/threatDetection/processThreatScanResult.js","sources":["../../../src/assetDelivery/threatDetection/processThreatScanResult.ts"],"sourcesContent":["import type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport { UpdateFileUseCase } from \"@webiny/api-file-manager/features/file/UpdateFile/index.js\";\nimport { DeleteFileUseCase } from \"@webiny/api-file-manager/features/file/DeleteFile/index.js\";\nimport { WebsocketsListConnectionsUseCase } from \"@webiny/api-websockets/exports/api.js\";\nimport { WebsocketsSendToConnectionsUseCase } from \"@webiny/api-websockets/exports/api.js\";\nimport { ConnectionRegistry } from \"@webiny/api-websockets/features/ConnectionRegistry/abstractions.js\";\nimport type { GuardDutyEvent } from \"./types.js\";\nimport { ObjectKey } from \"./ObjectKey.js\";\nimport { GetFileUseCase } from \"@webiny/api-file-manager/features/file/GetFile/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\n\nexport const processThreatScanResult = async (\n context: ApiCoreContext,\n eventDetail: GuardDutyEvent,\n tenant: string | null\n) => {\n const listConnections = context.container.resolve(WebsocketsListConnectionsUseCase);\n const sendToConnections = context.container.resolve(WebsocketsSendToConnectionsUseCase);\n const getFile = context.container.resolve(GetFileUseCase);\n const updateFile = context.container.resolve(UpdateFileUseCase);\n const deleteFile = context.container.resolve(DeleteFileUseCase);\n\n await context.container.resolve(IdentityContext).withoutAuthorization(async () => {\n const scanStatus = eventDetail.scanResultDetails.scanResultStatus;\n const s3Object = eventDetail.s3ObjectDetails;\n\n const fileId = ObjectKey.from(s3Object.objectKey).id();\n const fileResult = await getFile.execute(fileId);\n\n if (fileResult.isFail()) {\n return;\n }\n\n const file = fileResult.value;\n\n // Only the file's own tenant hears about it: the handler made it the current tenant, and the\n // list is scoped to the current tenant. Without a tenant, nobody does.\n let allConnections: ConnectionRegistry.Data[] = [];\n if (tenant) {\n const connectionsResult = await listConnections.execute();\n if (connectionsResult.isOk()) {\n allConnections = connectionsResult.value;\n }\n }\n\n if (scanStatus === \"NO_THREATS_FOUND\") {\n const newTags = file.tags.filter(tag => tag !== \"threatScanInProgress\");\n await updateFile.execute({\n id: file.id,\n tags: newTags\n });\n\n await sendToConnections.execute(allConnections, {\n action: \"fm.threatScan.noThreatFound\",\n data: {\n id: file.id,\n tags: newTags\n }\n });\n\n return;\n }\n\n if (scanStatus === \"THREATS_FOUND\") {\n // Delete the infected file.\n await deleteFile.execute(file.id);\n\n await sendToConnections.execute(allConnections, {\n action: \"fm.threatScan.threatDetected\",\n data: {\n id: file.id,\n name: file.name\n }\n });\n\n return;\n }\n\n // For all other outcomes, we delete the file, until better logic is implemented.\n await deleteFile.execute(file.id);\n\n await sendToConnections.execute(allConnections, {\n action: \"fm.threatScan.unsupported\",\n data: {\n id: file.id,\n name: file.name\n }\n });\n });\n};\n"],"names":["processThreatScanResult","context","eventDetail","tenant","listConnections","WebsocketsListConnectionsUseCase","sendToConnections","WebsocketsSendToConnectionsUseCase","getFile","GetFileUseCase","updateFile","UpdateFileUseCase","deleteFile","DeleteFileUseCase","IdentityContext","scanStatus","s3Object","fileId","ObjectKey","fileResult","file","allConnections","connectionsResult","newTags","tag"],"mappings":";;;;;;AAWO,MAAMA,0BAA0B,OACnCC,SACAC,aACAC;IAEA,MAAMC,kBAAkBH,QAAQ,SAAS,CAAC,OAAO,CAACI;IAClD,MAAMC,oBAAoBL,QAAQ,SAAS,CAAC,OAAO,CAACM;IACpD,MAAMC,UAAUP,QAAQ,SAAS,CAAC,OAAO,CAACQ;IAC1C,MAAMC,aAAaT,QAAQ,SAAS,CAAC,OAAO,CAACU;IAC7C,MAAMC,aAAaX,QAAQ,SAAS,CAAC,OAAO,CAACY;IAE7C,MAAMZ,QAAQ,SAAS,CAAC,OAAO,CAACa,iBAAiB,oBAAoB,CAAC;QAClE,MAAMC,aAAab,YAAY,iBAAiB,CAAC,gBAAgB;QACjE,MAAMc,WAAWd,YAAY,eAAe;QAE5C,MAAMe,SAASC,UAAU,IAAI,CAACF,SAAS,SAAS,EAAE,EAAE;QACpD,MAAMG,aAAa,MAAMX,QAAQ,OAAO,CAACS;QAEzC,IAAIE,WAAW,MAAM,IACjB;QAGJ,MAAMC,OAAOD,WAAW,KAAK;QAI7B,IAAIE,iBAA4C,EAAE;QAClD,IAAIlB,QAAQ;YACR,MAAMmB,oBAAoB,MAAMlB,gBAAgB,OAAO;YACvD,IAAIkB,kBAAkB,IAAI,IACtBD,iBAAiBC,kBAAkB,KAAK;QAEhD;QAEA,IAAIP,AAAe,uBAAfA,YAAmC;YACnC,MAAMQ,UAAUH,KAAK,IAAI,CAAC,MAAM,CAACI,CAAAA,MAAOA,AAAQ,2BAARA;YACxC,MAAMd,WAAW,OAAO,CAAC;gBACrB,IAAIU,KAAK,EAAE;gBACX,MAAMG;YACV;YAEA,MAAMjB,kBAAkB,OAAO,CAACe,gBAAgB;gBAC5C,QAAQ;gBACR,MAAM;oBACF,IAAID,KAAK,EAAE;oBACX,MAAMG;gBACV;YACJ;YAEA;QACJ;QAEA,IAAIR,AAAe,oBAAfA,YAAgC;YAEhC,MAAMH,WAAW,OAAO,CAACQ,KAAK,EAAE;YAEhC,MAAMd,kBAAkB,OAAO,CAACe,gBAAgB;gBAC5C,QAAQ;gBACR,MAAM;oBACF,IAAID,KAAK,EAAE;oBACX,MAAMA,KAAK,IAAI;gBACnB;YACJ;YAEA;QACJ;QAGA,MAAMR,WAAW,OAAO,CAACQ,KAAK,EAAE;QAEhC,MAAMd,kBAAkB,OAAO,CAACe,gBAAgB;YAC5C,QAAQ;YACR,MAAM;gBACF,IAAID,KAAK,EAAE;gBACX,MAAMA,KAAK,IAAI;YACnB;QACJ;IACJ;AACJ"}
@@ -27,7 +27,10 @@ class DeleteFileFromBucketHandlerImpl {
27
27
  fileId: file.id,
28
28
  folderKey
29
29
  }, "Could not start deleting the file's folder from the bucket.");
30
- await this.keyValueStore.delete(`FileManager/File/${file.id}/Metadata`);
30
+ const metadataKey = `FileManager/File/${file.id}/Metadata`;
31
+ const existing = await this.keyValueStore.get(metadataKey);
32
+ if (existing.isOk() && existing.value?.tenant && existing.value.tenant !== tenant.id) return;
33
+ await this.keyValueStore.delete(metadataKey);
31
34
  }
32
35
  }
33
36
  const DeleteFileFromBucketHandler = FileAfterDeleteEventHandler.createImplementation({
@@ -1 +1 @@
1
- {"version":3,"file":"features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js","sources":["../../../src/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.ts"],"sourcesContent":["import { FileAfterDeleteEventHandler } from \"@webiny/api-file-manager/features/file/DeleteFile/events.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport type { DeleteS3FolderInput } from \"~/features/DeleteFileFromBucket/DeleteS3FolderTask.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\n\nclass DeleteFileFromBucketHandlerImpl implements FileAfterDeleteEventHandler.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private taskService: TaskService.Interface,\n private keyValueStore: GlobalKeyValueStore.Interface,\n private logger: Logger.Interface\n ) {}\n\n async handle(event: FileAfterDeleteEventHandler.Event): Promise<void> {\n const { file } = event.payload;\n const tenant = this.tenantContext.getTenant();\n\n // Delete S3 folder recursively. The file record is already gone, so a task that can't start\n // is logged and doesn't fail the delete.\n const folderKey = `tenants/${tenant.id}/files/${file.id}`;\n const result = await this.taskService.trigger<DeleteS3FolderInput>({\n definition: \"fileManagerFolderDelete\",\n input: {\n caller: \"fm-after-delete\",\n bucket: String(process.env.S3_BUCKET),\n folderKey\n }\n });\n if (result.isFail()) {\n this.logger.error(\n { error: result.error, fileId: file.id, folderKey },\n \"Could not start deleting the file's folder from the bucket.\"\n );\n }\n\n // Delete file metadata\n await this.keyValueStore.delete(`FileManager/File/${file.id}/Metadata`);\n }\n}\n\nexport const DeleteFileFromBucketHandler = FileAfterDeleteEventHandler.createImplementation({\n implementation: DeleteFileFromBucketHandlerImpl,\n dependencies: [TenantContext, TaskService, GlobalKeyValueStore, Logger]\n});\n"],"names":["DeleteFileFromBucketHandlerImpl","tenantContext","taskService","keyValueStore","logger","event","file","tenant","folderKey","result","String","process","DeleteFileFromBucketHandler","FileAfterDeleteEventHandler","TenantContext","TaskService","GlobalKeyValueStore","Logger"],"mappings":";;;;;AAOA,MAAMA;IACF,YACYC,aAAsC,EACtCC,WAAkC,EAClCC,aAA4C,EAC5CC,MAAwB,CAClC;aAJUH,aAAa,GAAbA;aACAC,WAAW,GAAXA;aACAC,aAAa,GAAbA;aACAC,MAAM,GAANA;IACT;IAEH,MAAM,OAAOC,KAAwC,EAAiB;QAClE,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAM,OAAO;QAC9B,MAAME,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAI3C,MAAMC,YAAY,CAAC,QAAQ,EAAED,OAAO,EAAE,CAAC,OAAO,EAAED,KAAK,EAAE,EAAE;QACzD,MAAMG,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAsB;YAC/D,YAAY;YACZ,OAAO;gBACH,QAAQ;gBACR,QAAQC,OAAOC,QAAQ,GAAG,CAAC,SAAS;gBACpCH;YACJ;QACJ;QACA,IAAIC,OAAO,MAAM,IACb,IAAI,CAAC,MAAM,CAAC,KAAK,CACb;YAAE,OAAOA,OAAO,KAAK;YAAE,QAAQH,KAAK,EAAE;YAAEE;QAAU,GAClD;QAKR,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,iBAAiB,EAAEF,KAAK,EAAE,CAAC,SAAS,CAAC;IAC1E;AACJ;AAEO,MAAMM,8BAA8BC,4BAA4B,oBAAoB,CAAC;IACxF,gBAAgBb;IAChB,cAAc;QAACc;QAAeC;QAAaC;QAAqBC;KAAO;AAC3E"}
1
+ {"version":3,"file":"features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js","sources":["../../../src/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.ts"],"sourcesContent":["import { FileAfterDeleteEventHandler } from \"@webiny/api-file-manager/features/file/DeleteFile/events.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport type { DeleteS3FolderInput } from \"~/features/DeleteFileFromBucket/DeleteS3FolderTask.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\n\nclass DeleteFileFromBucketHandlerImpl implements FileAfterDeleteEventHandler.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private taskService: TaskService.Interface,\n private keyValueStore: GlobalKeyValueStore.Interface,\n private logger: Logger.Interface\n ) {}\n\n async handle(event: FileAfterDeleteEventHandler.Event): Promise<void> {\n const { file } = event.payload;\n const tenant = this.tenantContext.getTenant();\n\n // Delete S3 folder recursively. The file record is already gone, so a task that can't start\n // is logged and doesn't fail the delete.\n const folderKey = `tenants/${tenant.id}/files/${file.id}`;\n const result = await this.taskService.trigger<DeleteS3FolderInput>({\n definition: \"fileManagerFolderDelete\",\n input: {\n caller: \"fm-after-delete\",\n bucket: String(process.env.S3_BUCKET),\n folderKey\n }\n });\n if (result.isFail()) {\n this.logger.error(\n { error: result.error, fileId: file.id, folderKey },\n \"Could not start deleting the file's folder from the bucket.\"\n );\n }\n\n // Delete file metadata\n // Security: metadata is global and keyed only by file id; never delete another tenant's.\n const metadataKey = `FileManager/File/${file.id}/Metadata`;\n const existing = await this.keyValueStore.get<{ tenant?: string }>(metadataKey);\n if (existing.isOk() && existing.value?.tenant && existing.value.tenant !== tenant.id) {\n return;\n }\n await this.keyValueStore.delete(metadataKey);\n }\n}\n\nexport const DeleteFileFromBucketHandler = FileAfterDeleteEventHandler.createImplementation({\n implementation: DeleteFileFromBucketHandlerImpl,\n dependencies: [TenantContext, TaskService, GlobalKeyValueStore, Logger]\n});\n"],"names":["DeleteFileFromBucketHandlerImpl","tenantContext","taskService","keyValueStore","logger","event","file","tenant","folderKey","result","String","process","metadataKey","existing","DeleteFileFromBucketHandler","FileAfterDeleteEventHandler","TenantContext","TaskService","GlobalKeyValueStore","Logger"],"mappings":";;;;;AAOA,MAAMA;IACF,YACYC,aAAsC,EACtCC,WAAkC,EAClCC,aAA4C,EAC5CC,MAAwB,CAClC;aAJUH,aAAa,GAAbA;aACAC,WAAW,GAAXA;aACAC,aAAa,GAAbA;aACAC,MAAM,GAANA;IACT;IAEH,MAAM,OAAOC,KAAwC,EAAiB;QAClE,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAM,OAAO;QAC9B,MAAME,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAI3C,MAAMC,YAAY,CAAC,QAAQ,EAAED,OAAO,EAAE,CAAC,OAAO,EAAED,KAAK,EAAE,EAAE;QACzD,MAAMG,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAsB;YAC/D,YAAY;YACZ,OAAO;gBACH,QAAQ;gBACR,QAAQC,OAAOC,QAAQ,GAAG,CAAC,SAAS;gBACpCH;YACJ;QACJ;QACA,IAAIC,OAAO,MAAM,IACb,IAAI,CAAC,MAAM,CAAC,KAAK,CACb;YAAE,OAAOA,OAAO,KAAK;YAAE,QAAQH,KAAK,EAAE;YAAEE;QAAU,GAClD;QAMR,MAAMI,cAAc,CAAC,iBAAiB,EAAEN,KAAK,EAAE,CAAC,SAAS,CAAC;QAC1D,MAAMO,WAAW,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAsBD;QACnE,IAAIC,SAAS,IAAI,MAAMA,SAAS,KAAK,EAAE,UAAUA,SAAS,KAAK,CAAC,MAAM,KAAKN,OAAO,EAAE,EAChF;QAEJ,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAACK;IACpC;AACJ;AAEO,MAAME,8BAA8BC,4BAA4B,oBAAoB,CAAC;IACxF,gBAAgBf;IAChB,cAAc;QAACgB;QAAeC;QAAaC;QAAqBC;KAAO;AAC3E"}
@@ -1,3 +1,4 @@
1
+ import type { S3 } from "@webiny/aws-sdk/client-s3/index.js";
1
2
  import { TaskDefinition, TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
2
3
  export interface DeleteS3FolderInput {
3
4
  /**
@@ -18,6 +19,8 @@ export interface DeleteS3FolderInput {
18
19
  continuationToken?: string;
19
20
  }
20
21
  declare class DeleteS3FolderTaskHandlerImpl implements TaskHandler.Interface<DeleteS3FolderInput> {
22
+ private s3;
23
+ constructor(s3: S3);
21
24
  run({ input, controller }: TaskHandler.RunParams<DeleteS3FolderInput>): Promise<TaskDefinition.Result<DeleteS3FolderInput>>;
22
25
  }
23
26
  declare class DeleteS3FolderTask implements TaskDefinition.Interface {
@@ -1,12 +1,15 @@
1
- import { S3 } from "@webiny/aws-sdk/client-s3/index.js";
1
+ import { S3Client } from "../../assetDelivery/abstractions.js";
2
2
  import { TaskDefinition, TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
3
3
  class DeleteS3FolderTaskHandlerImpl {
4
+ constructor(s3){
5
+ this.s3 = s3;
6
+ }
4
7
  async run({ input, controller }) {
5
8
  if (controller.runtime.isAborted()) return controller.response.aborted();
6
9
  if (!input.bucket) return controller.response.error({
7
10
  message: "Bucket is not defined."
8
11
  });
9
- const s3 = new S3();
12
+ const s3 = this.s3;
10
13
  const filesList = await s3.listObjectsV2({
11
14
  Bucket: input.bucket,
12
15
  Prefix: `${input.folderKey}/`,
@@ -32,7 +35,9 @@ class DeleteS3FolderTaskHandlerImpl {
32
35
  }
33
36
  const DeleteS3FolderTaskHandler = TaskHandler.createImplementation({
34
37
  implementation: DeleteS3FolderTaskHandlerImpl,
35
- dependencies: []
38
+ dependencies: [
39
+ S3Client
40
+ ]
36
41
  });
37
42
  class DeleteS3FolderTask {
38
43
  constructor(){
@@ -1 +1 @@
1
- {"version":3,"file":"features/DeleteFileFromBucket/DeleteS3FolderTask.js","sources":["../../../src/features/DeleteFileFromBucket/DeleteS3FolderTask.ts"],"sourcesContent":["import { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport interface DeleteS3FolderInput {\n /**\n * Caller of the task (e.g., `fm-after-delete`).\n */\n caller: string;\n /**\n * Cache paths to invalidate.\n */\n bucket: string;\n /**\n * FM file directory key to delete.\n */\n folderKey: string;\n /**\n * Continuation token for pagination.\n */\n continuationToken?: string;\n}\n\nclass DeleteS3FolderTaskHandlerImpl implements TaskHandler.Interface<DeleteS3FolderInput> {\n public async run({\n input,\n controller\n }: TaskHandler.RunParams<DeleteS3FolderInput>): Promise<\n TaskDefinition.Result<DeleteS3FolderInput>\n > {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n if (!input.bucket) {\n return controller.response.error({ message: `Bucket is not defined.` });\n }\n\n const s3 = new S3();\n\n // List objects in the folder with pagination support.\n const filesList = await s3.listObjectsV2({\n Bucket: input.bucket,\n Prefix: `${input.folderKey}/`,\n ContinuationToken: input.continuationToken\n });\n\n // Delete all files in the folder using batch delete.\n if (filesList.Contents && filesList.Contents.length > 0) {\n const objectsToDelete = filesList.Contents.filter(file => file.Key).map(file => ({\n Key: file.Key!\n }));\n\n if (objectsToDelete.length > 0) {\n await s3.deleteObjects({\n Bucket: input.bucket,\n Delete: {\n Objects: objectsToDelete\n }\n });\n }\n }\n\n // If there are more objects to delete, continue in the next iteration.\n if (filesList.IsTruncated && filesList.NextContinuationToken) {\n return controller.response.continue({\n ...input,\n continuationToken: filesList.NextContinuationToken\n });\n }\n\n return controller.response.done();\n }\n}\n\nconst DeleteS3FolderTaskHandler = TaskHandler.createImplementation({\n implementation: DeleteS3FolderTaskHandlerImpl,\n dependencies: []\n});\n\nclass DeleteS3FolderTask implements TaskDefinition.Interface {\n id = \"fileManagerFolderDelete\";\n title = \"Delete folder and all of its contents from the bucket.\";\n description = \"A task to delete all files from a given folder.\";\n maxIterations = 5;\n isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = DeleteS3FolderTaskHandler;\n}\n\nexport const DeleteS3FolderTaskDefinition = TaskDefinition.createImplementation({\n implementation: DeleteS3FolderTask,\n dependencies: []\n});\n"],"names":["DeleteS3FolderTaskHandlerImpl","input","controller","s3","S3","filesList","objectsToDelete","file","DeleteS3FolderTaskHandler","TaskHandler","DeleteS3FolderTask","DeleteS3FolderTaskDefinition","TaskDefinition"],"mappings":";;AAyBA,MAAMA;IACF,MAAa,IAAI,EACbC,KAAK,EACLC,UAAU,EAC+B,EAE3C;QACE,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;QAGtC,IAAI,CAACD,MAAM,MAAM,EACb,OAAOC,WAAW,QAAQ,CAAC,KAAK,CAAC;YAAE,SAAS;QAAyB;QAGzE,MAAMC,KAAK,IAAIC;QAGf,MAAMC,YAAY,MAAMF,GAAG,aAAa,CAAC;YACrC,QAAQF,MAAM,MAAM;YACpB,QAAQ,GAAGA,MAAM,SAAS,CAAC,CAAC,CAAC;YAC7B,mBAAmBA,MAAM,iBAAiB;QAC9C;QAGA,IAAII,UAAU,QAAQ,IAAIA,UAAU,QAAQ,CAAC,MAAM,GAAG,GAAG;YACrD,MAAMC,kBAAkBD,UAAU,QAAQ,CAAC,MAAM,CAACE,CAAAA,OAAQA,KAAK,GAAG,EAAE,GAAG,CAACA,CAAAA,OAAS;oBAC7E,KAAKA,KAAK,GAAG;gBACjB;YAEA,IAAID,gBAAgB,MAAM,GAAG,GACzB,MAAMH,GAAG,aAAa,CAAC;gBACnB,QAAQF,MAAM,MAAM;gBACpB,QAAQ;oBACJ,SAASK;gBACb;YACJ;QAER;QAGA,IAAID,UAAU,WAAW,IAAIA,UAAU,qBAAqB,EACxD,OAAOH,WAAW,QAAQ,CAAC,QAAQ,CAAC;YAChC,GAAGD,KAAK;YACR,mBAAmBI,UAAU,qBAAqB;QACtD;QAGJ,OAAOH,WAAW,QAAQ,CAAC,IAAI;IACnC;AACJ;AAEA,MAAMM,4BAA4BC,YAAY,oBAAoB,CAAC;IAC/D,gBAAgBT;IAChB,cAAc,EAAE;AACpB;AAEA,MAAMU;;aACF,EAAE,GAAG;aACL,KAAK,GAAG;aACR,WAAW,GAAG;aACd,aAAa,GAAG;aAChB,SAAS,GAAG;aACI,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAExE,OAAO,GAAGF;;AACd;AAEO,MAAMG,+BAA+BC,eAAe,oBAAoB,CAAC;IAC5E,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"features/DeleteFileFromBucket/DeleteS3FolderTask.js","sources":["../../../src/features/DeleteFileFromBucket/DeleteS3FolderTask.ts"],"sourcesContent":["import type { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { S3Client } from \"~/assetDelivery/abstractions.js\";\nimport {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport interface DeleteS3FolderInput {\n /**\n * Caller of the task (e.g., `fm-after-delete`).\n */\n caller: string;\n /**\n * Cache paths to invalidate.\n */\n bucket: string;\n /**\n * FM file directory key to delete.\n */\n folderKey: string;\n /**\n * Continuation token for pagination.\n */\n continuationToken?: string;\n}\n\nclass DeleteS3FolderTaskHandlerImpl implements TaskHandler.Interface<DeleteS3FolderInput> {\n constructor(private s3: S3) {}\n\n public async run({\n input,\n controller\n }: TaskHandler.RunParams<DeleteS3FolderInput>): Promise<\n TaskDefinition.Result<DeleteS3FolderInput>\n > {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n if (!input.bucket) {\n return controller.response.error({ message: `Bucket is not defined.` });\n }\n\n const s3 = this.s3;\n\n // List objects in the folder with pagination support.\n const filesList = await s3.listObjectsV2({\n Bucket: input.bucket,\n Prefix: `${input.folderKey}/`,\n ContinuationToken: input.continuationToken\n });\n\n // Delete all files in the folder using batch delete.\n if (filesList.Contents && filesList.Contents.length > 0) {\n const objectsToDelete = filesList.Contents.filter(file => file.Key).map(file => ({\n Key: file.Key!\n }));\n\n if (objectsToDelete.length > 0) {\n await s3.deleteObjects({\n Bucket: input.bucket,\n Delete: {\n Objects: objectsToDelete\n }\n });\n }\n }\n\n // If there are more objects to delete, continue in the next iteration.\n if (filesList.IsTruncated && filesList.NextContinuationToken) {\n return controller.response.continue({\n ...input,\n continuationToken: filesList.NextContinuationToken\n });\n }\n\n return controller.response.done();\n }\n}\n\nconst DeleteS3FolderTaskHandler = TaskHandler.createImplementation({\n implementation: DeleteS3FolderTaskHandlerImpl,\n dependencies: [S3Client]\n});\n\nclass DeleteS3FolderTask implements TaskDefinition.Interface {\n id = \"fileManagerFolderDelete\";\n title = \"Delete folder and all of its contents from the bucket.\";\n description = \"A task to delete all files from a given folder.\";\n maxIterations = 5;\n isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = DeleteS3FolderTaskHandler;\n}\n\nexport const DeleteS3FolderTaskDefinition = TaskDefinition.createImplementation({\n implementation: DeleteS3FolderTask,\n dependencies: []\n});\n"],"names":["DeleteS3FolderTaskHandlerImpl","s3","input","controller","filesList","objectsToDelete","file","DeleteS3FolderTaskHandler","TaskHandler","S3Client","DeleteS3FolderTask","DeleteS3FolderTaskDefinition","TaskDefinition"],"mappings":";;AA0BA,MAAMA;IACF,YAAoBC,EAAM,CAAE;aAARA,EAAE,GAAFA;IAAS;IAE7B,MAAa,IAAI,EACbC,KAAK,EACLC,UAAU,EAC+B,EAE3C;QACE,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;QAGtC,IAAI,CAACD,MAAM,MAAM,EACb,OAAOC,WAAW,QAAQ,CAAC,KAAK,CAAC;YAAE,SAAS;QAAyB;QAGzE,MAAMF,KAAK,IAAI,CAAC,EAAE;QAGlB,MAAMG,YAAY,MAAMH,GAAG,aAAa,CAAC;YACrC,QAAQC,MAAM,MAAM;YACpB,QAAQ,GAAGA,MAAM,SAAS,CAAC,CAAC,CAAC;YAC7B,mBAAmBA,MAAM,iBAAiB;QAC9C;QAGA,IAAIE,UAAU,QAAQ,IAAIA,UAAU,QAAQ,CAAC,MAAM,GAAG,GAAG;YACrD,MAAMC,kBAAkBD,UAAU,QAAQ,CAAC,MAAM,CAACE,CAAAA,OAAQA,KAAK,GAAG,EAAE,GAAG,CAACA,CAAAA,OAAS;oBAC7E,KAAKA,KAAK,GAAG;gBACjB;YAEA,IAAID,gBAAgB,MAAM,GAAG,GACzB,MAAMJ,GAAG,aAAa,CAAC;gBACnB,QAAQC,MAAM,MAAM;gBACpB,QAAQ;oBACJ,SAASG;gBACb;YACJ;QAER;QAGA,IAAID,UAAU,WAAW,IAAIA,UAAU,qBAAqB,EACxD,OAAOD,WAAW,QAAQ,CAAC,QAAQ,CAAC;YAChC,GAAGD,KAAK;YACR,mBAAmBE,UAAU,qBAAqB;QACtD;QAGJ,OAAOD,WAAW,QAAQ,CAAC,IAAI;IACnC;AACJ;AAEA,MAAMI,4BAA4BC,YAAY,oBAAoB,CAAC;IAC/D,gBAAgBR;IAChB,cAAc;QAACS;KAAS;AAC5B;AAEA,MAAMC;;aACF,EAAE,GAAG;aACL,KAAK,GAAG;aACR,WAAW,GAAG;aACd,aAAa,GAAG;aAChB,SAAS,GAAG;aACI,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAExE,OAAO,GAAGH;;AACd;AAEO,MAAMI,+BAA+BC,eAAe,oBAAoB,CAAC;IAC5E,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,17 @@
1
+ import type { S3 } from "@webiny/aws-sdk/client-s3/index.js";
2
+ import { Result } from "@webiny/feature/api";
3
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
4
+ import { FileContentsStorage } from "@webiny/api-file-manager/features/file/FileContentsStorage/index.js";
5
+ declare class S3FileContentsStorageImpl implements FileContentsStorage.Interface {
6
+ private tenantContext;
7
+ private s3;
8
+ private bucket;
9
+ constructor(tenantContext: TenantContext.Interface, s3: S3, bucket: string);
10
+ put(input: FileContentsStorage.PutInput): Promise<Result<void, FileContentsStorage.PutError>>;
11
+ delete(key: string): Promise<Result<void, FileContentsStorage.DeleteError>>;
12
+ private toObjectKey;
13
+ }
14
+ export declare const S3FileContentsStorage: typeof S3FileContentsStorageImpl & {
15
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-file-manager/features/file/FileContentsStorage/abstractions").IFileContentsStorage>;
16
+ };
17
+ export {};
@@ -0,0 +1,60 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
3
+ import { FileContentsStorage } from "@webiny/api-file-manager/features/file/FileContentsStorage/index.js";
4
+ import { FileAlreadyExistsError, FilePersistenceError } from "@webiny/api-file-manager/domain/file/errors.js";
5
+ import { S3Bucket, S3Client } from "../../assetDelivery/abstractions.js";
6
+ const isKeyTakenError = (error)=>{
7
+ const s3Error = error;
8
+ return s3Error?.$metadata?.httpStatusCode === 412 || s3Error?.name === "PreconditionFailed" || s3Error?.name === "ConditionalRequestConflict";
9
+ };
10
+ const toPersistenceError = (error)=>new FilePersistenceError(error instanceof Error ? error : new Error(String(error)));
11
+ class S3FileContentsStorageImpl {
12
+ constructor(tenantContext, s3, bucket){
13
+ this.tenantContext = tenantContext;
14
+ this.s3 = s3;
15
+ this.bucket = bucket;
16
+ }
17
+ async put(input) {
18
+ try {
19
+ await this.s3.putObject({
20
+ Bucket: this.bucket,
21
+ Key: this.toObjectKey(input.key),
22
+ Body: input.contents,
23
+ ContentType: input.contentType,
24
+ ContentLength: input.contents.byteLength,
25
+ IfNoneMatch: "*"
26
+ });
27
+ return Result.ok();
28
+ } catch (error) {
29
+ if (isKeyTakenError(error)) return Result.fail(new FileAlreadyExistsError({
30
+ key: input.key
31
+ }));
32
+ return Result.fail(toPersistenceError(error));
33
+ }
34
+ }
35
+ async delete(key) {
36
+ try {
37
+ await this.s3.deleteObject({
38
+ Bucket: this.bucket,
39
+ Key: this.toObjectKey(key)
40
+ });
41
+ return Result.ok();
42
+ } catch (error) {
43
+ return Result.fail(toPersistenceError(error));
44
+ }
45
+ }
46
+ toObjectKey(key) {
47
+ return `tenants/${this.tenantContext.getTenant().id}/files/${key}`;
48
+ }
49
+ }
50
+ const S3FileContentsStorage = FileContentsStorage.createImplementation({
51
+ implementation: S3FileContentsStorageImpl,
52
+ dependencies: [
53
+ TenantContext,
54
+ S3Client,
55
+ S3Bucket
56
+ ]
57
+ });
58
+ export { S3FileContentsStorage };
59
+
60
+ //# sourceMappingURL=S3FileContentsStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/FileContentsStorage/S3FileContentsStorage.js","sources":["../../../src/features/FileContentsStorage/S3FileContentsStorage.ts"],"sourcesContent":["import type { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { FileContentsStorage } from \"@webiny/api-file-manager/features/file/FileContentsStorage/index.js\";\nimport {\n FileAlreadyExistsError,\n FilePersistenceError\n} from \"@webiny/api-file-manager/domain/file/errors.js\";\nimport { S3Client, S3Bucket } from \"~/assetDelivery/abstractions.js\";\n\n/**\n * S3 refuses a conditional write (`IfNoneMatch: \"*\"`) with 412 when the key already exists, and\n * with 409 when another conditional write to the same key is still in progress.\n */\nconst isKeyTakenError = (error: unknown): boolean => {\n const s3Error = error as { name?: string; $metadata?: { httpStatusCode?: number } };\n return (\n s3Error?.$metadata?.httpStatusCode === 412 ||\n s3Error?.name === \"PreconditionFailed\" ||\n s3Error?.name === \"ConditionalRequestConflict\"\n );\n};\n\nconst toPersistenceError = (error: unknown) => {\n return new FilePersistenceError(error instanceof Error ? error : new Error(String(error)));\n};\n\nclass S3FileContentsStorageImpl implements FileContentsStorage.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private s3: S3,\n private bucket: string\n ) {}\n\n async put(\n input: FileContentsStorage.PutInput\n ): Promise<Result<void, FileContentsStorage.PutError>> {\n try {\n await this.s3.putObject({\n Bucket: this.bucket,\n Key: this.toObjectKey(input.key),\n Body: input.contents,\n ContentType: input.contentType,\n ContentLength: input.contents.byteLength,\n IfNoneMatch: \"*\"\n });\n return Result.ok();\n } catch (error) {\n if (isKeyTakenError(error)) {\n return Result.fail(new FileAlreadyExistsError({ key: input.key }));\n }\n return Result.fail(toPersistenceError(error));\n }\n }\n\n async delete(key: string): Promise<Result<void, FileContentsStorage.DeleteError>> {\n try {\n await this.s3.deleteObject({\n Bucket: this.bucket,\n Key: this.toObjectKey(key)\n });\n return Result.ok();\n } catch (error) {\n return Result.fail(toPersistenceError(error));\n }\n }\n\n private toObjectKey(key: string): string {\n return `tenants/${this.tenantContext.getTenant().id}/files/${key}`;\n }\n}\n\nexport const S3FileContentsStorage = FileContentsStorage.createImplementation({\n implementation: S3FileContentsStorageImpl,\n dependencies: [TenantContext, S3Client, S3Bucket]\n});\n"],"names":["isKeyTakenError","error","s3Error","toPersistenceError","FilePersistenceError","Error","String","S3FileContentsStorageImpl","tenantContext","s3","bucket","input","Result","FileAlreadyExistsError","key","S3FileContentsStorage","FileContentsStorage","TenantContext","S3Client","S3Bucket"],"mappings":";;;;;AAcA,MAAMA,kBAAkB,CAACC;IACrB,MAAMC,UAAUD;IAChB,OACIC,SAAS,WAAW,mBAAmB,OACvCA,SAAS,SAAS,wBAClBA,SAAS,SAAS;AAE1B;AAEA,MAAMC,qBAAqB,CAACF,QACjB,IAAIG,qBAAqBH,iBAAiBI,QAAQJ,QAAQ,IAAII,MAAMC,OAAOL;AAGtF,MAAMM;IACF,YACYC,aAAsC,EACtCC,EAAM,EACNC,MAAc,CACxB;aAHUF,aAAa,GAAbA;aACAC,EAAE,GAAFA;aACAC,MAAM,GAANA;IACT;IAEH,MAAM,IACFC,KAAmC,EACgB;QACnD,IAAI;YACA,MAAM,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC;gBACpB,QAAQ,IAAI,CAAC,MAAM;gBACnB,KAAK,IAAI,CAAC,WAAW,CAACA,MAAM,GAAG;gBAC/B,MAAMA,MAAM,QAAQ;gBACpB,aAAaA,MAAM,WAAW;gBAC9B,eAAeA,MAAM,QAAQ,CAAC,UAAU;gBACxC,aAAa;YACjB;YACA,OAAOC,OAAO,EAAE;QACpB,EAAE,OAAOX,OAAO;YACZ,IAAID,gBAAgBC,QAChB,OAAOW,OAAO,IAAI,CAAC,IAAIC,uBAAuB;gBAAE,KAAKF,MAAM,GAAG;YAAC;YAEnE,OAAOC,OAAO,IAAI,CAACT,mBAAmBF;QAC1C;IACJ;IAEA,MAAM,OAAOa,GAAW,EAA0D;QAC9E,IAAI;YACA,MAAM,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC;gBACvB,QAAQ,IAAI,CAAC,MAAM;gBACnB,KAAK,IAAI,CAAC,WAAW,CAACA;YAC1B;YACA,OAAOF,OAAO,EAAE;QACpB,EAAE,OAAOX,OAAO;YACZ,OAAOW,OAAO,IAAI,CAACT,mBAAmBF;QAC1C;IACJ;IAEQ,YAAYa,GAAW,EAAU;QACrC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,EAAE,CAAC,OAAO,EAAEA,KAAK;IACtE;AACJ;AAEO,MAAMC,wBAAwBC,oBAAoB,oBAAoB,CAAC;IAC1E,gBAAgBT;IAChB,cAAc;QAACU;QAAeC;QAAUC;KAAS;AACrD"}
@@ -0,0 +1,5 @@
1
+ /** Writes (and cleans up) file bytes in the bucket, for `StoreFileUseCase`. */
2
+ export declare const FileContentsStorageFeature: {
3
+ name: string;
4
+ register(container: import("@webiny/di").Container): void;
5
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { S3FileContentsStorage } from "./S3FileContentsStorage.js";
3
+ const FileContentsStorageFeature = createFeature({
4
+ name: "FileManagerS3/FileContentsStorage",
5
+ register (container) {
6
+ container.register(S3FileContentsStorage).inSingletonScope();
7
+ }
8
+ });
9
+ export { FileContentsStorageFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/FileContentsStorage/feature.js","sources":["../../../src/features/FileContentsStorage/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { S3FileContentsStorage } from \"./S3FileContentsStorage.js\";\n\n/** Writes (and cleans up) file bytes in the bucket, for `StoreFileUseCase`. */\nexport const FileContentsStorageFeature = createFeature({\n name: \"FileManagerS3/FileContentsStorage\",\n register(container) {\n container.register(S3FileContentsStorage).inSingletonScope();\n }\n});\n"],"names":["FileContentsStorageFeature","createFeature","container","S3FileContentsStorage"],"mappings":";;AAIO,MAAMA,6BAA6BC,cAAc;IACpD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,uBAAuB,gBAAgB;IAC9D;AACJ"}
@@ -1,10 +1,15 @@
1
1
  import { Result } from "@webiny/feature/api";
2
+ import type { S3 } from "@webiny/aws-sdk/client-s3/index.js";
2
3
  import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
3
4
  import { GetFileContentsByIdUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
4
5
  import type { FileContents } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
6
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
5
7
  declare class GetFileContentsByIdUseCaseImpl implements GetFileContentsByIdUseCase.Interface {
8
+ private readonly tenantContext;
9
+ private readonly s3;
10
+ private readonly bucket;
6
11
  private metadataReader;
7
- constructor(keyValueStore: GlobalKeyValueStore.Interface);
12
+ constructor(keyValueStore: GlobalKeyValueStore.Interface, tenantContext: TenantContext.Interface, s3: S3, bucket: string);
8
13
  execute(fileId: string): Promise<Result<FileContents, GetFileContentsByIdUseCase.Error>>;
9
14
  }
10
15
  export declare const GetFileContentsByIdUseCaseImplementation: typeof GetFileContentsByIdUseCaseImpl & {
@@ -1,21 +1,23 @@
1
1
  import { Result } from "@webiny/feature/api";
2
- import { S3 } from "@webiny/aws-sdk/client-s3/index.js";
2
+ import { S3Bucket, S3Client } from "../../assetDelivery/abstractions.js";
3
3
  import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
4
4
  import { GetFileContentsByIdUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
5
5
  import { FileNotFoundError, FilePersistenceError } from "@webiny/api-file-manager/domain/file/errors.js";
6
6
  import { MetadataReader } from "../WriteFileMetadata/MetadataReader.js";
7
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
7
8
  class GetFileContentsByIdUseCaseImpl {
8
- constructor(keyValueStore){
9
+ constructor(keyValueStore, tenantContext, s3, bucket){
10
+ this.tenantContext = tenantContext;
11
+ this.s3 = s3;
12
+ this.bucket = bucket;
9
13
  this.metadataReader = new MetadataReader(keyValueStore);
10
14
  }
11
15
  async execute(fileId) {
12
16
  const metadata = await this.metadataReader.read(fileId);
13
- if (!metadata) return Result.fail(new FileNotFoundError(fileId));
17
+ if (!metadata || metadata.tenant !== this.tenantContext.getTenant().id) return Result.fail(new FileNotFoundError(fileId));
14
18
  try {
15
- const s3 = new S3();
16
- const bucket = String(process.env.S3_BUCKET);
17
- const response = await s3.getObject({
18
- Bucket: bucket,
19
+ const response = await this.s3.getObject({
20
+ Bucket: this.bucket,
19
21
  Key: metadata.bucketKey
20
22
  });
21
23
  if (!response.Body) return Result.fail(new FileNotFoundError(fileId));
@@ -32,7 +34,10 @@ class GetFileContentsByIdUseCaseImpl {
32
34
  const GetFileContentsByIdUseCaseImplementation = GetFileContentsByIdUseCase.createImplementation({
33
35
  implementation: GetFileContentsByIdUseCaseImpl,
34
36
  dependencies: [
35
- GlobalKeyValueStore
37
+ GlobalKeyValueStore,
38
+ TenantContext,
39
+ S3Client,
40
+ S3Bucket
36
41
  ]
37
42
  });
38
43
  export { GetFileContentsByIdUseCaseImplementation };