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

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 (37) hide show
  1. package/FileManagerS3Feature.js +2 -0
  2. package/FileManagerS3Feature.js.map +1 -1
  3. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js +6 -2
  4. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js.map +1 -1
  5. package/assetDelivery/threatDetection/processThreatScanResult.d.ts +1 -1
  6. package/assetDelivery/threatDetection/processThreatScanResult.js +9 -3
  7. package/assetDelivery/threatDetection/processThreatScanResult.js.map +1 -1
  8. package/features/FileContentsStorage/S3FileContentsStorage.d.ts +17 -0
  9. package/features/FileContentsStorage/S3FileContentsStorage.js +60 -0
  10. package/features/FileContentsStorage/S3FileContentsStorage.js.map +1 -0
  11. package/features/FileContentsStorage/feature.d.ts +5 -0
  12. package/features/FileContentsStorage/feature.js +11 -0
  13. package/features/FileContentsStorage/feature.js.map +1 -0
  14. package/index.d.ts +2 -1
  15. package/index.js +1 -1
  16. package/package.json +15 -19
  17. package/utils/createFileNormalizerFromContext.d.ts +1 -1
  18. package/utils/createFileNormalizerFromContext.js +2 -2
  19. package/utils/createFileNormalizerFromContext.js.map +1 -1
  20. package/utils/FileExtension.d.ts +0 -6
  21. package/utils/FileExtension.js +0 -16
  22. package/utils/FileExtension.js.map +0 -1
  23. package/utils/FileKey.d.ts +0 -11
  24. package/utils/FileKey.js +0 -33
  25. package/utils/FileKey.js.map +0 -1
  26. package/utils/FileKey.test.d.ts +0 -1
  27. package/utils/FileKey.test.js +0 -59
  28. package/utils/FileKey.test.js.map +0 -1
  29. package/utils/FileNormalizer.d.ts +0 -18
  30. package/utils/FileNormalizer.js +0 -48
  31. package/utils/FileNormalizer.js.map +0 -1
  32. package/utils/FileUploadModifier.d.ts +0 -36
  33. package/utils/FileUploadModifier.js +0 -41
  34. package/utils/FileUploadModifier.js.map +0 -1
  35. package/utils/mimeTypes.d.ts +0 -5
  36. package/utils/mimeTypes.js +0 -9
  37. package/utils/mimeTypes.js.map +0 -1
@@ -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"}
@@ -23,17 +23,21 @@ 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()) {
33
+ this.tenantCtx.setTenant(tenantResult.value);
34
+ tenant = tenantResult.value.id;
35
+ }
32
36
  }
33
37
  } catch {}
34
38
  await processThreatScanResult({
35
39
  container: this.container
36
- }, payload.detail);
40
+ }, payload.detail, tenant);
37
41
  return {
38
42
  success: true
39
43
  };
@@ -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 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 let tenant: string | 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 this.tenantCtx.setTenant(tenantResult.value);\n tenant = tenantResult.value.id;\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 tenant\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","tenant","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;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,IAAI;oBACrB,IAAI,CAAC,SAAS,CAAC,SAAS,CAACA,aAAa,KAAK;oBAC3CJ,SAASI,aAAa,KAAK,CAAC,EAAE;gBAClC;YACJ;QACJ,EAAE,OAAM,CAER;QAEA,MAAMC,wBACF;YAAE,WAAW,IAAI,CAAC,SAAS;QAAC,GAC5BV,QAAQ,MAAM,EACdK;QAEJ,OAAO;YAAE,SAAS;QAAK;IAC3B;AACJ;AAEO,MAAMM,0CAA0CC,wBAAwB,oBAAoB,CAC/F;IACI,gBAAgBlB;IAChB,cAAc;QAACmB;QAAkBC;QAAeC;KAAqB;AACzE;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,14 @@ 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
+ where: {
24
+ tenant
25
+ }
26
+ });
27
+ if (connectionsResult.isOk()) allConnections = connectionsResult.value;
28
+ }
23
29
  if ("NO_THREATS_FOUND" === scanStatus) {
24
30
  const newTags = file.tags.filter((tag)=>"threatScanInProgress" !== tag);
25
31
  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 {\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 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. Without a tenant, nobody does.\n let allConnections: ConnectionRegistry.Data[] = [];\n if (tenant) {\n const connectionsResult = await listConnections.execute({ where: { tenant } });\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":";;;;;;AAaO,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;QAG7B,IAAIE,iBAA4C,EAAE;QAClD,IAAIlB,QAAQ;YACR,MAAMmB,oBAAoB,MAAMlB,gBAAgB,OAAO,CAAC;gBAAE,OAAO;oBAAED;gBAAO;YAAE;YAC5E,IAAImB,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"}
@@ -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"}
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { createFileUploadModifier } from "./utils/FileUploadModifier.js";
1
+ export { createFileUploadModifier } from "@webiny/api-file-manager/features/upload/utils/FileUploadModifier.js";
2
+ export { FileUploadModifier } from "@webiny/api-file-manager/features/upload/utils/FileUploadModifier.js";
2
3
  export { createAssetDelivery } from "./assetDelivery/createAssetDelivery.js";
3
4
  export { FileManagerS3Feature } from "./FileManagerS3Feature.js";
4
5
  export type { FileManagerS3FeatureConfig } from "./FileManagerS3Feature.js";
package/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { createFileUploadModifier } from "./utils/FileUploadModifier.js";
1
+ export { FileUploadModifier, createFileUploadModifier } from "@webiny/api-file-manager/features/upload/utils/FileUploadModifier.js";
2
2
  export { createAssetDelivery } from "./assetDelivery/createAssetDelivery.js";
3
3
  export { FileManagerS3Feature } from "./FileManagerS3Feature.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-file-manager-s3",
3
- "version": "6.6.0-alpha.11",
3
+ "version": "6.6.0-alpha.12",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -14,31 +14,27 @@
14
14
  "author": "Webiny Ltd",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@webiny/api": "6.6.0-alpha.11",
18
- "@webiny/api-core": "6.6.0-alpha.11",
19
- "@webiny/api-file-manager": "6.6.0-alpha.11",
20
- "@webiny/api-graphql": "6.6.0-alpha.11",
21
- "@webiny/api-websockets": "6.6.0-alpha.11",
22
- "@webiny/aws-sdk": "6.6.0-alpha.11",
23
- "@webiny/background-tasks": "6.6.0-alpha.11",
17
+ "@webiny/api": "6.6.0-alpha.12",
18
+ "@webiny/api-core": "6.6.0-alpha.12",
19
+ "@webiny/api-file-manager": "6.6.0-alpha.12",
20
+ "@webiny/api-graphql": "6.6.0-alpha.12",
21
+ "@webiny/api-websockets": "6.6.0-alpha.12",
22
+ "@webiny/aws-sdk": "6.6.0-alpha.12",
23
+ "@webiny/background-tasks": "6.6.0-alpha.12",
24
24
  "@webiny/di": "2.0.0",
25
- "@webiny/event-handler-aws": "6.6.0-alpha.11",
26
- "@webiny/event-handler-core": "6.6.0-alpha.11",
27
- "@webiny/feature": "6.6.0-alpha.11",
28
- "@webiny/handler": "6.6.0-alpha.11",
29
- "@webiny/plugins": "6.6.0-alpha.11",
30
- "@webiny/utils": "6.6.0-alpha.11",
31
- "@webiny/validation": "6.6.0-alpha.11",
25
+ "@webiny/event-handler-aws": "6.6.0-alpha.12",
26
+ "@webiny/event-handler-core": "6.6.0-alpha.12",
27
+ "@webiny/feature": "6.6.0-alpha.12",
28
+ "@webiny/handler": "6.6.0-alpha.12",
29
+ "@webiny/plugins": "6.6.0-alpha.12",
30
+ "@webiny/validation": "6.6.0-alpha.12",
32
31
  "exifreader": "4.52.0",
33
- "mime": "4.1.2",
34
32
  "object-hash": "3.0.0",
35
33
  "p-map": "7.1.1",
36
- "p-reduce": "3.0.0",
37
- "sanitize-filename": "1.6.4",
38
34
  "sharp": "0.35.5"
39
35
  },
40
36
  "devDependencies": {
41
- "@webiny/build-tools": "6.6.0-alpha.11",
37
+ "@webiny/build-tools": "6.6.0-alpha.12",
42
38
  "rimraf": "6.1.3",
43
39
  "typescript": "7.0.2",
44
40
  "vitest": "5.0.5"
@@ -1,3 +1,3 @@
1
1
  import type { Context } from "@webiny/api/types.js";
2
- import { FileNormalizer } from "../utils/FileNormalizer.js";
2
+ import { FileNormalizer } from "@webiny/api-file-manager/features/upload/utils/FileNormalizer.js";
3
3
  export declare const createFileNormalizerFromContext: (context: Context) => FileNormalizer;
@@ -1,5 +1,5 @@
1
- import { FileNormalizer } from "./FileNormalizer.js";
2
- import { FileUploadModifier, createModifierFromPlugins } from "./FileUploadModifier.js";
1
+ import { FileNormalizer } from "@webiny/api-file-manager/features/upload/utils/FileNormalizer.js";
2
+ import { FileUploadModifier, createModifierFromPlugins } from "@webiny/api-file-manager/features/upload/utils/FileUploadModifier.js";
3
3
  const createFileNormalizerFromContext = (context)=>{
4
4
  const modifierPlugins = context.container.resolveAll(FileUploadModifier);
5
5
  return new FileNormalizer(createModifierFromPlugins(modifierPlugins));
@@ -1 +1 @@
1
- {"version":3,"file":"utils/createFileNormalizerFromContext.js","sources":["../../src/utils/createFileNormalizerFromContext.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types.js\";\nimport { FileNormalizer } from \"~/utils/FileNormalizer.js\";\nimport { createModifierFromPlugins, FileUploadModifier } from \"~/utils/FileUploadModifier.js\";\n\nexport const createFileNormalizerFromContext = (context: Context) => {\n // Modifiers are registered as DI instances (FileUploadModifier) — was\n // context.plugins.byType(FileUploadModifierPlugin.type).\n const modifierPlugins = context.container.resolveAll(FileUploadModifier);\n\n return new FileNormalizer(createModifierFromPlugins(modifierPlugins));\n};\n"],"names":["createFileNormalizerFromContext","context","modifierPlugins","FileUploadModifier","FileNormalizer","createModifierFromPlugins"],"mappings":";;AAIO,MAAMA,kCAAkC,CAACC;IAG5C,MAAMC,kBAAkBD,QAAQ,SAAS,CAAC,UAAU,CAACE;IAErD,OAAO,IAAIC,eAAeC,0BAA0BH;AACxD"}
1
+ {"version":3,"file":"utils/createFileNormalizerFromContext.js","sources":["../../src/utils/createFileNormalizerFromContext.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types.js\";\nimport { FileNormalizer } from \"@webiny/api-file-manager/features/upload/utils/FileNormalizer.js\";\nimport {\n createModifierFromPlugins,\n FileUploadModifier\n} from \"@webiny/api-file-manager/features/upload/utils/FileUploadModifier.js\";\n\nexport const createFileNormalizerFromContext = (context: Context) => {\n // Modifiers are registered as DI instances (FileUploadModifier) — was\n // context.plugins.byType(FileUploadModifierPlugin.type).\n const modifierPlugins = context.container.resolveAll(FileUploadModifier);\n\n return new FileNormalizer(createModifierFromPlugins(modifierPlugins));\n};\n"],"names":["createFileNormalizerFromContext","context","modifierPlugins","FileUploadModifier","FileNormalizer","createModifierFromPlugins"],"mappings":";;AAOO,MAAMA,kCAAkC,CAACC;IAG5C,MAAMC,kBAAkBD,QAAQ,SAAS,CAAC,UAAU,CAACE;IAErD,OAAO,IAAIC,eAAeC,0BAA0BH;AACxD"}
@@ -1,6 +0,0 @@
1
- import type { PresignedPostPayloadData } from "../types.js";
2
- export declare class FileExtension {
3
- private data;
4
- constructor(data: PresignedPostPayloadData);
5
- getValue(): string;
6
- }
@@ -1,16 +0,0 @@
1
- import { mimeTypes as external_mimeTypes_js_mimeTypes } from "./mimeTypes.js";
2
- class FileExtension {
3
- constructor(data){
4
- this.data = data;
5
- }
6
- getValue() {
7
- const name = (this.data.key || this.data.name).toLowerCase();
8
- const maybeExt = name.split(".").pop();
9
- const extensions = external_mimeTypes_js_mimeTypes[this.data.type];
10
- if (extensions && !extensions.includes(maybeExt)) return extensions[0];
11
- return "";
12
- }
13
- }
14
- export { FileExtension };
15
-
16
- //# sourceMappingURL=FileExtension.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils/FileExtension.js","sources":["../../src/utils/FileExtension.ts"],"sourcesContent":["import { mimeTypes } from \"~/utils/mimeTypes.js\";\nimport type { PresignedPostPayloadData } from \"~/types.js\";\n\nexport class FileExtension {\n private data: PresignedPostPayloadData;\n\n constructor(data: PresignedPostPayloadData) {\n this.data = data;\n }\n\n getValue() {\n const name = (this.data.key || this.data.name).toLowerCase();\n\n const maybeExt = name.split(\".\").pop() as string;\n const extensions = mimeTypes[this.data.type];\n if (extensions && !extensions.includes(maybeExt)) {\n return extensions[0];\n }\n\n return \"\";\n }\n}\n"],"names":["FileExtension","data","name","maybeExt","extensions","mimeTypes"],"mappings":";AAGO,MAAMA;IAGT,YAAYC,IAA8B,CAAE;QACxC,IAAI,CAAC,IAAI,GAAGA;IAChB;IAEA,WAAW;QACP,MAAMC,OAAQ,KAAI,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAG,EAAG,WAAW;QAE1D,MAAMC,WAAWD,KAAK,KAAK,CAAC,KAAK,GAAG;QACpC,MAAME,aAAaC,+BAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5C,IAAID,cAAc,CAACA,WAAW,QAAQ,CAACD,WACnC,OAAOC,UAAU,CAAC,EAAE;QAGxB,OAAO;IACX;AACJ"}
@@ -1,11 +0,0 @@
1
- import type { PresignedPostPayloadData } from "../types.js";
2
- export declare class FileKey {
3
- private data;
4
- private extension;
5
- private key;
6
- constructor(data: PresignedPostPayloadData);
7
- getExtension(): string;
8
- setKey(key: string): this;
9
- toString(): string;
10
- private getSanitizedKey;
11
- }
package/utils/FileKey.js DELETED
@@ -1,33 +0,0 @@
1
- import sanitize_filename from "sanitize-filename";
2
- import { FileExtension } from "./FileExtension.js";
3
- class FileKey {
4
- constructor(data){
5
- this.data = data;
6
- this.extension = new FileExtension(data);
7
- this.key = this.getSanitizedKey();
8
- }
9
- getExtension() {
10
- return this.extension.getValue();
11
- }
12
- setKey(key) {
13
- this.key = key;
14
- return this;
15
- }
16
- toString() {
17
- return [
18
- this.data.keyPrefix,
19
- this.data.id,
20
- this.key
21
- ].filter(Boolean).join("/");
22
- }
23
- getSanitizedKey() {
24
- const key = sanitize_filename(this.data.key || this.data.name).replace(/\s/g, "");
25
- return [
26
- key,
27
- this.getExtension()
28
- ].filter(Boolean).join(".");
29
- }
30
- }
31
- export { FileKey };
32
-
33
- //# sourceMappingURL=FileKey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils/FileKey.js","sources":["../../src/utils/FileKey.ts"],"sourcesContent":["import sanitizeFilename from \"sanitize-filename\";\nimport type { PresignedPostPayloadData } from \"~/types.js\";\nimport { FileExtension } from \"~/utils/FileExtension.js\";\n\nexport class FileKey {\n private data: PresignedPostPayloadData;\n private extension: FileExtension;\n private key: string;\n\n constructor(data: PresignedPostPayloadData) {\n this.data = data;\n this.extension = new FileExtension(data);\n this.key = this.getSanitizedKey();\n }\n\n getExtension() {\n return this.extension.getValue();\n }\n\n setKey(key: string) {\n this.key = key;\n return this;\n }\n\n toString() {\n return [this.data.keyPrefix, this.data.id, this.key].filter(Boolean).join(\"/\");\n }\n\n private getSanitizedKey() {\n const key = sanitizeFilename(this.data.key || this.data.name).replace(/\\s/g, \"\");\n\n return [key, this.getExtension()].filter(Boolean).join(\".\");\n }\n}\n"],"names":["FileKey","data","FileExtension","key","Boolean","sanitizeFilename"],"mappings":";;AAIO,MAAMA;IAKT,YAAYC,IAA8B,CAAE;QACxC,IAAI,CAAC,IAAI,GAAGA;QACZ,IAAI,CAAC,SAAS,GAAG,IAAIC,cAAcD;QACnC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,eAAe;IACnC;IAEA,eAAe;QACX,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ;IAClC;IAEA,OAAOE,GAAW,EAAE;QAChB,IAAI,CAAC,GAAG,GAAGA;QACX,OAAO,IAAI;IACf;IAEA,WAAW;QACP,OAAO;YAAC,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,IAAI,CAAC,IAAI,CAAC,EAAE;YAAE,IAAI,CAAC,GAAG;SAAC,CAAC,MAAM,CAACC,SAAS,IAAI,CAAC;IAC9E;IAEQ,kBAAkB;QACtB,MAAMD,MAAME,kBAAiB,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO;QAE7E,OAAO;YAACF;YAAK,IAAI,CAAC,YAAY;SAAG,CAAC,MAAM,CAACC,SAAS,IAAI,CAAC;IAC3D;AACJ"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,59 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { FileKey } from "./FileKey.js";
3
- describe("FileKey", ()=>{
4
- it("should generate a file key (extension is included in the name)", ()=>{
5
- const fileKey = new FileKey({
6
- size: 1071690,
7
- name: "image-14.jpg",
8
- type: "image/jpeg"
9
- });
10
- expect(fileKey.toString()).toEqual("image-14.jpg");
11
- });
12
- it("should generate a file key (extension derived from file type)", ()=>{
13
- const fileKey = new FileKey({
14
- size: 1071690,
15
- name: "image-14",
16
- type: "image/jpeg"
17
- });
18
- expect(fileKey.toString()).toEqual("image-14.jpg");
19
- });
20
- it("should generate a file key containing id", ()=>{
21
- const fileKey = new FileKey({
22
- size: 1071690,
23
- name: "image-14.jpeg",
24
- type: "image/jpeg",
25
- id: "12345678"
26
- });
27
- expect(fileKey.toString()).toEqual("12345678/image-14.jpeg");
28
- });
29
- it("should generate a file key containing prefix", ()=>{
30
- const fileKey = new FileKey({
31
- size: 1071690,
32
- name: "image-14.jpeg",
33
- type: "image/jpeg",
34
- keyPrefix: "prefix"
35
- });
36
- expect(fileKey.toString()).toEqual("prefix/image-14.jpeg");
37
- });
38
- it("should generate a file key containing id and prefix", ()=>{
39
- const fileKey = new FileKey({
40
- size: 1071690,
41
- name: "image-14.jpeg",
42
- type: "image/jpeg",
43
- id: "12345678",
44
- keyPrefix: "prefix"
45
- });
46
- expect(fileKey.toString()).toEqual("prefix/12345678/image-14.jpeg");
47
- });
48
- it("should use the key defined in the input", ()=>{
49
- const fileKey = new FileKey({
50
- size: 1071690,
51
- name: "image",
52
- type: "image/jpeg",
53
- key: "image-14.jpg"
54
- });
55
- expect(fileKey.toString()).toEqual("image-14.jpg");
56
- });
57
- });
58
-
59
- //# sourceMappingURL=FileKey.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils/FileKey.test.js","sources":["../../src/utils/FileKey.test.ts"],"sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport { FileKey } from \"./FileKey.js\";\n\ndescribe(\"FileKey\", () => {\n it(\"should generate a file key (extension is included in the name)\", () => {\n const fileKey = new FileKey({\n size: 1071690,\n name: \"image-14.jpg\",\n type: \"image/jpeg\"\n });\n\n expect(fileKey.toString()).toEqual(\"image-14.jpg\");\n });\n\n it(\"should generate a file key (extension derived from file type)\", () => {\n const fileKey = new FileKey({\n size: 1071690,\n name: \"image-14\",\n type: \"image/jpeg\"\n });\n\n expect(fileKey.toString()).toEqual(\"image-14.jpg\");\n });\n\n it(\"should generate a file key containing id\", () => {\n const fileKey = new FileKey({\n size: 1071690,\n name: \"image-14.jpeg\",\n type: \"image/jpeg\",\n id: \"12345678\"\n });\n\n expect(fileKey.toString()).toEqual(\"12345678/image-14.jpeg\");\n });\n\n it(\"should generate a file key containing prefix\", () => {\n const fileKey = new FileKey({\n size: 1071690,\n name: \"image-14.jpeg\",\n type: \"image/jpeg\",\n keyPrefix: \"prefix\"\n });\n\n expect(fileKey.toString()).toEqual(\"prefix/image-14.jpeg\");\n });\n\n it(\"should generate a file key containing id and prefix\", () => {\n const fileKey = new FileKey({\n size: 1071690,\n name: \"image-14.jpeg\",\n type: \"image/jpeg\",\n id: \"12345678\",\n keyPrefix: \"prefix\"\n });\n\n expect(fileKey.toString()).toEqual(\"prefix/12345678/image-14.jpeg\");\n });\n\n it(\"should use the key defined in the input\", () => {\n const fileKey = new FileKey({\n size: 1071690,\n name: \"image\",\n type: \"image/jpeg\",\n key: \"image-14.jpg\"\n });\n\n expect(fileKey.toString()).toEqual(\"image-14.jpg\");\n });\n});\n"],"names":["describe","it","fileKey","FileKey","expect"],"mappings":";;AAGAA,SAAS,WAAW;IAChBC,GAAG,kEAAkE;QACjE,MAAMC,UAAU,IAAIC,QAAQ;YACxB,MAAM;YACN,MAAM;YACN,MAAM;QACV;QAEAC,OAAOF,QAAQ,QAAQ,IAAI,OAAO,CAAC;IACvC;IAEAD,GAAG,iEAAiE;QAChE,MAAMC,UAAU,IAAIC,QAAQ;YACxB,MAAM;YACN,MAAM;YACN,MAAM;QACV;QAEAC,OAAOF,QAAQ,QAAQ,IAAI,OAAO,CAAC;IACvC;IAEAD,GAAG,4CAA4C;QAC3C,MAAMC,UAAU,IAAIC,QAAQ;YACxB,MAAM;YACN,MAAM;YACN,MAAM;YACN,IAAI;QACR;QAEAC,OAAOF,QAAQ,QAAQ,IAAI,OAAO,CAAC;IACvC;IAEAD,GAAG,gDAAgD;QAC/C,MAAMC,UAAU,IAAIC,QAAQ;YACxB,MAAM;YACN,MAAM;YACN,MAAM;YACN,WAAW;QACf;QAEAC,OAAOF,QAAQ,QAAQ,IAAI,OAAO,CAAC;IACvC;IAEAD,GAAG,uDAAuD;QACtD,MAAMC,UAAU,IAAIC,QAAQ;YACxB,MAAM;YACN,MAAM;YACN,MAAM;YACN,IAAI;YACJ,WAAW;QACf;QAEAC,OAAOF,QAAQ,QAAQ,IAAI,OAAO,CAAC;IACvC;IAEAD,GAAG,2CAA2C;QAC1C,MAAMC,UAAU,IAAIC,QAAQ;YACxB,MAAM;YACN,MAAM;YACN,MAAM;YACN,KAAK;QACT;QAEAC,OAAOF,QAAQ,QAAQ,IAAI,OAAO,CAAC;IACvC;AACJ"}
@@ -1,18 +0,0 @@
1
- import type { FileData, PresignedPostPayloadData } from "../types.js";
2
- import type { FileModifier } from "./FileUploadModifier.js";
3
- export interface FileToSign {
4
- name: string;
5
- key: string;
6
- type: string;
7
- size: number;
8
- }
9
- /**
10
- * FileNormalizer normalizes file data, before it's signed for upload to S3.
11
- * It generates a unique file id, and makes sure that the file key includes the unique id.
12
- *
13
- */
14
- export declare class FileNormalizer {
15
- private readonly modifier;
16
- constructor(modifier?: FileModifier);
17
- normalizeFile(payload: PresignedPostPayloadData): Promise<FileData>;
18
- }
@@ -1,48 +0,0 @@
1
- import { mdbid } from "@webiny/utils";
2
- import { FileKey } from "./FileKey.js";
3
- import { validateFileKey } from "@webiny/api-file-manager/domain/file/validateFileKey.js";
4
- import { mimeTypes as external_mimeTypes_js_mimeTypes } from "./mimeTypes.js";
5
- const extensionToMime = new Map();
6
- for (const [mime, extensions] of Object.entries(external_mimeTypes_js_mimeTypes))for (const ext of extensions)if (!extensionToMime.has(ext)) extensionToMime.set(ext, mime);
7
- function resolveTypeFromName(name) {
8
- const ext = name.slice(name.lastIndexOf(".") + 1).toLowerCase();
9
- return extensionToMime.get(ext) || "application/octet-stream";
10
- }
11
- class FileNormalizer {
12
- constructor(modifier){
13
- this.modifier = modifier;
14
- }
15
- async normalizeFile(payload) {
16
- const data = {
17
- ...payload,
18
- id: payload.id || mdbid(),
19
- type: payload.type || resolveTypeFromName(payload.name)
20
- };
21
- const key = new FileKey(data);
22
- const defaultKey = key.toString();
23
- const file = {
24
- name: data.name,
25
- type: data.type,
26
- key: defaultKey,
27
- size: data.size
28
- };
29
- if (this.modifier) Object.assign(file, await this.modifier(file));
30
- if (defaultKey !== file.key) key.setKey(file.key);
31
- const fileKey = key.toString();
32
- const keyResult = validateFileKey({
33
- key: fileKey,
34
- id: data.id
35
- });
36
- if (keyResult.isFail()) throw keyResult.error;
37
- return {
38
- id: data.id,
39
- key: fileKey,
40
- name: file.name,
41
- size: file.size,
42
- type: file.type
43
- };
44
- }
45
- }
46
- export { FileNormalizer };
47
-
48
- //# sourceMappingURL=FileNormalizer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils/FileNormalizer.js","sources":["../../src/utils/FileNormalizer.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport type { FileData, PresignedPostPayloadData } from \"~/types.js\";\nimport { FileKey } from \"~/utils/FileKey.js\";\nimport { validateFileKey } from \"@webiny/api-file-manager/domain/file/validateFileKey.js\";\nimport { mimeTypes } from \"~/utils/mimeTypes.js\";\nimport type { FileModifier } from \"./FileUploadModifier.js\";\n\nexport interface FileToSign {\n name: string;\n key: string;\n type: string;\n size: number;\n}\n\nconst extensionToMime = new Map<string, string>();\nfor (const [mime, extensions] of Object.entries(mimeTypes)) {\n for (const ext of extensions) {\n if (!extensionToMime.has(ext)) {\n extensionToMime.set(ext, mime);\n }\n }\n}\n\nfunction resolveTypeFromName(name: string): string {\n const ext = name.slice(name.lastIndexOf(\".\") + 1).toLowerCase();\n return extensionToMime.get(ext) || \"application/octet-stream\";\n}\n\n/**\n * FileNormalizer normalizes file data, before it's signed for upload to S3.\n * It generates a unique file id, and makes sure that the file key includes the unique id.\n *\n */\nexport class FileNormalizer {\n private readonly modifier: FileModifier | undefined;\n\n constructor(modifier?: FileModifier) {\n this.modifier = modifier;\n }\n\n async normalizeFile(payload: PresignedPostPayloadData): Promise<FileData> {\n const data = {\n ...payload,\n id: payload.id || mdbid(),\n type: payload.type || resolveTypeFromName(payload.name)\n };\n\n const key = new FileKey(data);\n const defaultKey = key.toString();\n\n const file: FileToSign = {\n name: data.name,\n type: data.type,\n key: defaultKey,\n size: data.size\n };\n\n if (this.modifier) {\n Object.assign(file, await this.modifier(file));\n }\n\n if (defaultKey !== file.key) {\n key.setKey(file.key);\n }\n\n // The ID and key prefix come from the client and end up in a storage path.\n const fileKey = key.toString();\n const keyResult = validateFileKey({ key: fileKey, id: data.id });\n if (keyResult.isFail()) {\n throw keyResult.error;\n }\n\n return {\n id: data.id,\n key: fileKey,\n name: file.name,\n size: file.size,\n type: file.type\n };\n }\n}\n"],"names":["extensionToMime","Map","mime","extensions","Object","mimeTypes","ext","resolveTypeFromName","name","FileNormalizer","modifier","payload","data","mdbid","key","FileKey","defaultKey","file","fileKey","keyResult","validateFileKey"],"mappings":";;;;AAcA,MAAMA,kBAAkB,IAAIC;AAC5B,KAAK,MAAM,CAACC,MAAMC,WAAW,IAAIC,OAAO,OAAO,CAACC,iCAC5C,KAAK,MAAMC,OAAOH,WACd,IAAI,CAACH,gBAAgB,GAAG,CAACM,MACrBN,gBAAgB,GAAG,CAACM,KAAKJ;AAKrC,SAASK,oBAAoBC,IAAY;IACrC,MAAMF,MAAME,KAAK,KAAK,CAACA,KAAK,WAAW,CAAC,OAAO,GAAG,WAAW;IAC7D,OAAOR,gBAAgB,GAAG,CAACM,QAAQ;AACvC;AAOO,MAAMG;IAGT,YAAYC,QAAuB,CAAE;QACjC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,cAAcC,OAAiC,EAAqB;QACtE,MAAMC,OAAO;YACT,GAAGD,OAAO;YACV,IAAIA,QAAQ,EAAE,IAAIE;YAClB,MAAMF,QAAQ,IAAI,IAAIJ,oBAAoBI,QAAQ,IAAI;QAC1D;QAEA,MAAMG,MAAM,IAAIC,QAAQH;QACxB,MAAMI,aAAaF,IAAI,QAAQ;QAE/B,MAAMG,OAAmB;YACrB,MAAML,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,KAAKI;YACL,MAAMJ,KAAK,IAAI;QACnB;QAEA,IAAI,IAAI,CAAC,QAAQ,EACbR,OAAO,MAAM,CAACa,MAAM,MAAM,IAAI,CAAC,QAAQ,CAACA;QAG5C,IAAID,eAAeC,KAAK,GAAG,EACvBH,IAAI,MAAM,CAACG,KAAK,GAAG;QAIvB,MAAMC,UAAUJ,IAAI,QAAQ;QAC5B,MAAMK,YAAYC,gBAAgB;YAAE,KAAKF;YAAS,IAAIN,KAAK,EAAE;QAAC;QAC9D,IAAIO,UAAU,MAAM,IAChB,MAAMA,UAAU,KAAK;QAGzB,OAAO;YACH,IAAIP,KAAK,EAAE;YACX,KAAKM;YACL,MAAMD,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;QACnB;IACJ;AACJ"}
@@ -1,36 +0,0 @@
1
- import { Plugin } from "@webiny/plugins";
2
- import type { FileToSign } from "../utils/FileNormalizer.js";
3
- interface Setter<T> {
4
- (param: T): T;
5
- }
6
- declare class FileUploadModifierBuilder {
7
- private fileSetters;
8
- setFile(setter: Setter<FileToSign>): void;
9
- execute(file: FileToSign): Promise<FileToSign>;
10
- }
11
- interface FileUploadModifierCallbackParams {
12
- modifier: {
13
- setFile: FileUploadModifierBuilder["setFile"];
14
- };
15
- }
16
- export declare class FileUploadModifierPlugin extends Plugin {
17
- static type: string;
18
- private readonly cb;
19
- constructor(cb: FileUploadModifierCallable);
20
- execute(params: FileUploadModifierCallbackParams): void;
21
- }
22
- interface FileUploadModifierCallable {
23
- (params: FileUploadModifierCallbackParams): void;
24
- }
25
- export declare const createFileUploadModifier: (cb: FileUploadModifierCallable) => FileUploadModifierPlugin;
26
- /**
27
- * DI multiple-abstraction for file-upload modifiers. Replaces the old
28
- * `context.plugins.byType(FileUploadModifierPlugin.type)` lookup in createFileNormalizerFromContext.
29
- * Extensions register modifiers via `container.registerInstance(FileUploadModifier, createFileUploadModifier(cb))`.
30
- */
31
- export declare const FileUploadModifier: import("@webiny/di").Abstraction<FileUploadModifierPlugin>;
32
- export interface FileModifier {
33
- (file: FileToSign): Promise<Partial<FileToSign>> | Partial<FileToSign>;
34
- }
35
- export declare const createModifierFromPlugins: (plugins?: FileUploadModifierPlugin[]) => FileModifier;
36
- export {};
@@ -1,41 +0,0 @@
1
- import p_reduce from "p-reduce";
2
- import { Plugin } from "@webiny/plugins";
3
- import { createAbstraction } from "@webiny/feature/api";
4
- class FileUploadModifierBuilder {
5
- setFile(setter) {
6
- this.fileSetters.push(setter);
7
- }
8
- execute(file) {
9
- return p_reduce(this.fileSetters, async (file, setter)=>({
10
- ...file,
11
- ...await setter(file)
12
- }), file);
13
- }
14
- constructor(){
15
- this.fileSetters = [];
16
- }
17
- }
18
- class FileUploadModifierPlugin extends Plugin {
19
- static{
20
- this.type = "fm.s3.uploadModifier";
21
- }
22
- constructor(cb){
23
- super();
24
- this.cb = cb;
25
- }
26
- execute(params) {
27
- return this.cb(params);
28
- }
29
- }
30
- const createFileUploadModifier = (cb)=>new FileUploadModifierPlugin(cb);
31
- const FileUploadModifier = createAbstraction("FileUploadModifier");
32
- const createModifierFromPlugins = (plugins = [])=>{
33
- const modifier = new FileUploadModifierBuilder();
34
- plugins.forEach((pl)=>pl.execute({
35
- modifier
36
- }));
37
- return (file)=>modifier.execute(file);
38
- };
39
- export { FileUploadModifier, FileUploadModifierPlugin, createFileUploadModifier, createModifierFromPlugins };
40
-
41
- //# sourceMappingURL=FileUploadModifier.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils/FileUploadModifier.js","sources":["../../src/utils/FileUploadModifier.ts"],"sourcesContent":["import pReduce from \"p-reduce\";\nimport { Plugin } from \"@webiny/plugins\";\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { FileToSign } from \"~/utils/FileNormalizer.js\";\n\ninterface Setter<T> {\n (param: T): T;\n}\n\nclass FileUploadModifierBuilder {\n private fileSetters: Setter<FileToSign>[] = [];\n\n setFile(setter: Setter<FileToSign>): void {\n this.fileSetters.push(setter);\n }\n\n execute(file: FileToSign) {\n return pReduce(\n this.fileSetters,\n async (file, setter) => {\n // We need to spread the original file, then add (potentially) partial changes.\n return { ...file, ...(await setter(file)) };\n },\n file\n );\n }\n}\n\ninterface FileUploadModifierCallbackParams {\n modifier: {\n setFile: FileUploadModifierBuilder[\"setFile\"];\n };\n}\n\nexport class FileUploadModifierPlugin extends Plugin {\n public static override type = \"fm.s3.uploadModifier\";\n private readonly cb: FileUploadModifierCallable;\n\n constructor(cb: FileUploadModifierCallable) {\n super();\n this.cb = cb;\n }\n\n execute(params: FileUploadModifierCallbackParams) {\n return this.cb(params);\n }\n}\n\ninterface FileUploadModifierCallable {\n (params: FileUploadModifierCallbackParams): void;\n}\n\nexport const createFileUploadModifier = (cb: FileUploadModifierCallable) => {\n return new FileUploadModifierPlugin(cb);\n};\n\n/**\n * DI multiple-abstraction for file-upload modifiers. Replaces the old\n * `context.plugins.byType(FileUploadModifierPlugin.type)` lookup in createFileNormalizerFromContext.\n * Extensions register modifiers via `container.registerInstance(FileUploadModifier, createFileUploadModifier(cb))`.\n */\nexport const FileUploadModifier = createAbstraction<FileUploadModifierPlugin>(\"FileUploadModifier\");\n\nexport interface FileModifier {\n (file: FileToSign): Promise<Partial<FileToSign>> | Partial<FileToSign>;\n}\n\nexport const createModifierFromPlugins = (\n plugins: FileUploadModifierPlugin[] = []\n): FileModifier => {\n const modifier = new FileUploadModifierBuilder();\n plugins.forEach(pl => pl.execute({ modifier }));\n\n return (file: FileToSign) => modifier.execute(file);\n};\n"],"names":["FileUploadModifierBuilder","setter","file","pReduce","FileUploadModifierPlugin","Plugin","cb","params","createFileUploadModifier","FileUploadModifier","createAbstraction","createModifierFromPlugins","plugins","modifier","pl"],"mappings":";;;AASA,MAAMA;IAGF,QAAQC,MAA0B,EAAQ;QACtC,IAAI,CAAC,WAAW,CAAC,IAAI,CAACA;IAC1B;IAEA,QAAQC,IAAgB,EAAE;QACtB,OAAOC,SACH,IAAI,CAAC,WAAW,EAChB,OAAOD,MAAMD,SAEF;gBAAE,GAAGC,IAAI;gBAAE,GAAI,MAAMD,OAAOC,KAAK;YAAE,IAE9CA;IAER;;aAfQ,WAAW,GAAyB,EAAE;;AAgBlD;AAQO,MAAME,iCAAiCC;;aACnB,IAAI,GAAG;;IAG9B,YAAYC,EAA8B,CAAE;QACxC,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEA,QAAQC,MAAwC,EAAE;QAC9C,OAAO,IAAI,CAAC,EAAE,CAACA;IACnB;AACJ;AAMO,MAAMC,2BAA2B,CAACF,KAC9B,IAAIF,yBAAyBE;AAQjC,MAAMG,qBAAqBC,kBAA4C;AAMvE,MAAMC,4BAA4B,CACrCC,UAAsC,EAAE;IAExC,MAAMC,WAAW,IAAIb;IACrBY,QAAQ,OAAO,CAACE,CAAAA,KAAMA,GAAG,OAAO,CAAC;YAAED;QAAS;IAE5C,OAAO,CAACX,OAAqBW,SAAS,OAAO,CAACX;AAClD"}
@@ -1,5 +0,0 @@
1
- /**
2
- * We need to get all extensions that are defined for a specific content type.
3
- * This operation is not available via the `mime` package, so we create such an object ourselves.
4
- */
5
- export declare const mimeTypes: Record<string, string[]>;
@@ -1,9 +0,0 @@
1
- import other from "mime/types/other.js";
2
- import standard from "mime/types/standard.js";
3
- const mimeTypes_mimeTypes = {
4
- ...other,
5
- ...standard
6
- };
7
- export { mimeTypes_mimeTypes as mimeTypes };
8
-
9
- //# sourceMappingURL=mimeTypes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils/mimeTypes.js","sources":["../../src/utils/mimeTypes.ts"],"sourcesContent":["import vendorTypes from \"mime/types/other.js\";\nimport standardTypes from \"mime/types/standard.js\";\n\n/**\n * We need to get all extensions that are defined for a specific content type.\n * This operation is not available via the `mime` package, so we create such an object ourselves.\n */\nexport const mimeTypes: Record<string, string[]> = {\n ...vendorTypes,\n ...standardTypes\n};\n"],"names":["mimeTypes","vendorTypes","standardTypes"],"mappings":";;AAOO,MAAMA,sBAAsC;IAC/C,GAAGC,KAAW;IACd,GAAGC,QAAa;AACpB"}