@webiny/api-file-manager-s3 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9

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 (184) hide show
  1. package/README.md +11 -1
  2. package/assetDelivery/abstractions.d.ts +9 -0
  3. package/assetDelivery/abstractions.js +7 -0
  4. package/assetDelivery/abstractions.js.map +1 -0
  5. package/assetDelivery/assetDeliveryConfig.d.ts +2 -0
  6. package/assetDelivery/assetDeliveryConfig.js +15 -0
  7. package/assetDelivery/assetDeliveryConfig.js.map +1 -0
  8. package/assetDelivery/createAssetDelivery.d.ts +3 -0
  9. package/assetDelivery/createAssetDelivery.js +9 -0
  10. package/assetDelivery/createAssetDelivery.js.map +1 -0
  11. package/assetDelivery/feature.d.ts +5 -0
  12. package/assetDelivery/feature.js +37 -0
  13. package/assetDelivery/feature.js.map +1 -0
  14. package/assetDelivery/index.d.ts +8 -0
  15. package/assetDelivery/index.js +8 -0
  16. package/assetDelivery/s3/S3AssetResolver.d.ts +14 -0
  17. package/assetDelivery/s3/S3AssetResolver.js +39 -0
  18. package/assetDelivery/s3/S3AssetResolver.js.map +1 -0
  19. package/assetDelivery/s3/S3ContentsReader.d.ts +8 -0
  20. package/assetDelivery/s3/S3ContentsReader.js +17 -0
  21. package/assetDelivery/s3/S3ContentsReader.js.map +1 -0
  22. package/assetDelivery/s3/S3ErrorAssetReply.d.ts +4 -0
  23. package/assetDelivery/s3/S3ErrorAssetReply.js +14 -0
  24. package/assetDelivery/s3/S3ErrorAssetReply.js.map +1 -0
  25. package/assetDelivery/s3/S3OutputStrategy.d.ts +15 -0
  26. package/assetDelivery/s3/S3OutputStrategy.js +40 -0
  27. package/assetDelivery/s3/S3OutputStrategy.js.map +1 -0
  28. package/assetDelivery/s3/S3RedirectAssetReply.d.ts +4 -0
  29. package/assetDelivery/s3/S3RedirectAssetReply.js +17 -0
  30. package/assetDelivery/s3/S3RedirectAssetReply.js.map +1 -0
  31. package/assetDelivery/s3/S3StreamAssetReply.d.ts +5 -0
  32. package/assetDelivery/s3/S3StreamAssetReply.js +17 -0
  33. package/assetDelivery/s3/S3StreamAssetReply.js.map +1 -0
  34. package/assetDelivery/s3/SharpTransform.d.ts +18 -0
  35. package/assetDelivery/s3/SharpTransform.js +162 -0
  36. package/assetDelivery/s3/SharpTransform.js.map +1 -0
  37. package/assetDelivery/s3/transformation/AssetKeyGenerator.d.ts +8 -0
  38. package/assetDelivery/s3/transformation/AssetKeyGenerator.js +21 -0
  39. package/assetDelivery/s3/transformation/AssetKeyGenerator.js.map +1 -0
  40. package/assetDelivery/s3/transformation/CallableContentsReader.d.ts +10 -0
  41. package/assetDelivery/s3/transformation/CallableContentsReader.js +11 -0
  42. package/assetDelivery/s3/transformation/CallableContentsReader.js.map +1 -0
  43. package/assetDelivery/s3/transformation/WidthCollection.d.ts +7 -0
  44. package/assetDelivery/s3/transformation/WidthCollection.js +19 -0
  45. package/assetDelivery/s3/transformation/WidthCollection.js.map +1 -0
  46. package/assetDelivery/s3/transformation/utils.d.ts +9 -0
  47. package/assetDelivery/s3/transformation/utils.js +31 -0
  48. package/assetDelivery/s3/transformation/utils.js.map +1 -0
  49. package/assetDelivery/threatDetection/ObjectKey.d.ts +7 -0
  50. package/assetDelivery/threatDetection/ObjectKey.js +18 -0
  51. package/assetDelivery/threatDetection/ObjectKey.js.map +1 -0
  52. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.d.ts +2 -0
  53. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js +37 -0
  54. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js.map +1 -0
  55. package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.d.ts +2 -0
  56. package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js +5 -0
  57. package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js.map +1 -0
  58. package/assetDelivery/threatDetection/index.d.ts +2 -0
  59. package/assetDelivery/threatDetection/index.js +2 -0
  60. package/assetDelivery/threatDetection/processThreatScanResult.d.ts +3 -0
  61. package/assetDelivery/threatDetection/processThreatScanResult.js +59 -0
  62. package/assetDelivery/threatDetection/processThreatScanResult.js.map +1 -0
  63. package/assetDelivery/threatDetection/types.d.ts +9 -0
  64. package/assetDelivery/threatDetection/types.js +0 -0
  65. package/assetDelivery/types.d.ts +10 -0
  66. package/assetDelivery/types.js +0 -0
  67. package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.d.ts +11 -0
  68. package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js +23 -0
  69. package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js.map +1 -0
  70. package/enterprise/ApplyThreatScanning/feature.d.ts +4 -0
  71. package/enterprise/ApplyThreatScanning/feature.js +11 -0
  72. package/enterprise/ApplyThreatScanning/feature.js.map +1 -0
  73. package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.d.ts +15 -0
  74. package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js +35 -0
  75. package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js.map +1 -0
  76. package/features/DeleteFileFromBucket/DeleteS3FolderTask.d.ts +32 -0
  77. package/features/DeleteFileFromBucket/DeleteS3FolderTask.js +50 -0
  78. package/features/DeleteFileFromBucket/DeleteS3FolderTask.js.map +1 -0
  79. package/features/DeleteFileFromBucket/feature.d.ts +4 -0
  80. package/features/DeleteFileFromBucket/feature.js +13 -0
  81. package/features/DeleteFileFromBucket/feature.js.map +1 -0
  82. package/features/ExtractMetadata/ExtractMetadataHandler.d.ts +11 -0
  83. package/features/ExtractMetadata/ExtractMetadataHandler.js +25 -0
  84. package/features/ExtractMetadata/ExtractMetadataHandler.js.map +1 -0
  85. package/features/ExtractMetadata/ExtractMetadataTask.d.ts +24 -0
  86. package/features/ExtractMetadata/ExtractMetadataTask.js +90 -0
  87. package/features/ExtractMetadata/ExtractMetadataTask.js.map +1 -0
  88. package/features/ExtractMetadata/feature.d.ts +4 -0
  89. package/features/ExtractMetadata/feature.js +13 -0
  90. package/features/ExtractMetadata/feature.js.map +1 -0
  91. package/features/FlushCache/FlushCacheOnFileDeleteHandler.d.ts +12 -0
  92. package/features/FlushCache/FlushCacheOnFileDeleteHandler.js +28 -0
  93. package/features/FlushCache/FlushCacheOnFileDeleteHandler.js.map +1 -0
  94. package/features/FlushCache/FlushCacheOnFileUpdateHandler.d.ts +12 -0
  95. package/features/FlushCache/FlushCacheOnFileUpdateHandler.js +31 -0
  96. package/features/FlushCache/FlushCacheOnFileUpdateHandler.js.map +1 -0
  97. package/features/FlushCache/InvalidateCacheTask.d.ts +26 -0
  98. package/features/FlushCache/InvalidateCacheTask.js +75 -0
  99. package/features/FlushCache/InvalidateCacheTask.js.map +1 -0
  100. package/features/FlushCache/feature.d.ts +4 -0
  101. package/features/FlushCache/feature.js +15 -0
  102. package/features/FlushCache/feature.js.map +1 -0
  103. package/features/GetFileContentsById/GetFileContentsByIdUseCase.d.ts +13 -0
  104. package/features/GetFileContentsById/GetFileContentsByIdUseCase.js +40 -0
  105. package/features/GetFileContentsById/GetFileContentsByIdUseCase.js.map +1 -0
  106. package/features/GetFileContentsById/feature.d.ts +4 -0
  107. package/features/GetFileContentsById/feature.js +11 -0
  108. package/features/GetFileContentsById/feature.js.map +1 -0
  109. package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.d.ts +13 -0
  110. package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js +40 -0
  111. package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js.map +1 -0
  112. package/features/GetFileContentsByKey/feature.d.ts +4 -0
  113. package/features/GetFileContentsByKey/feature.js +11 -0
  114. package/features/GetFileContentsByKey/feature.js.map +1 -0
  115. package/features/WriteFileMetadata/MetadataReader.d.ts +14 -0
  116. package/features/WriteFileMetadata/MetadataReader.js +13 -0
  117. package/features/WriteFileMetadata/MetadataReader.js.map +1 -0
  118. package/features/WriteFileMetadata/MetadataWriter.d.ts +10 -0
  119. package/features/WriteFileMetadata/MetadataWriter.js +26 -0
  120. package/features/WriteFileMetadata/MetadataWriter.js.map +1 -0
  121. package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.d.ts +12 -0
  122. package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js +23 -0
  123. package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js.map +1 -0
  124. package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.d.ts +12 -0
  125. package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js +25 -0
  126. package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js.map +1 -0
  127. package/features/WriteFileMetadata/feature.d.ts +4 -0
  128. package/features/WriteFileMetadata/feature.js +13 -0
  129. package/features/WriteFileMetadata/feature.js.map +1 -0
  130. package/graphql/checkPermissions.d.ts +5 -0
  131. package/graphql/checkPermissions.js +22 -0
  132. package/graphql/checkPermissions.js.map +1 -0
  133. package/graphql/schema.d.ts +1 -0
  134. package/graphql/schema.js +201 -0
  135. package/graphql/schema.js.map +1 -0
  136. package/index.d.ts +4 -2
  137. package/index.js +29 -14
  138. package/index.js.map +1 -1
  139. package/multiPartUpload/CompleteMultiPartUploadUseCase.d.ts +15 -0
  140. package/multiPartUpload/CompleteMultiPartUploadUseCase.js +55 -0
  141. package/multiPartUpload/CompleteMultiPartUploadUseCase.js.map +1 -0
  142. package/multiPartUpload/CreateMultiPartUploadUseCase.d.ts +20 -0
  143. package/multiPartUpload/CreateMultiPartUploadUseCase.js +34 -0
  144. package/multiPartUpload/CreateMultiPartUploadUseCase.js.map +1 -0
  145. package/package.json +35 -24
  146. package/types.d.ts +14 -9
  147. package/types.js +1 -5
  148. package/utils/CdnPathsGenerator.d.ts +3 -0
  149. package/utils/CdnPathsGenerator.js +11 -0
  150. package/utils/CdnPathsGenerator.js.map +1 -0
  151. package/utils/FileExtension.d.ts +6 -0
  152. package/utils/FileExtension.js +16 -0
  153. package/utils/FileExtension.js.map +1 -0
  154. package/utils/FileKey.d.ts +11 -0
  155. package/utils/FileKey.js +33 -0
  156. package/utils/FileKey.js.map +1 -0
  157. package/utils/FileKey.test.d.ts +1 -0
  158. package/utils/FileKey.test.js +59 -0
  159. package/utils/FileKey.test.js.map +1 -0
  160. package/utils/FileNormalizer.d.ts +18 -0
  161. package/utils/FileNormalizer.js +41 -0
  162. package/utils/FileNormalizer.js.map +1 -0
  163. package/utils/FileUploadModifier.d.ts +30 -0
  164. package/utils/FileUploadModifier.js +39 -0
  165. package/utils/FileUploadModifier.js.map +1 -0
  166. package/utils/createFileNormalizerFromContext.d.ts +3 -0
  167. package/utils/createFileNormalizerFromContext.js +9 -0
  168. package/utils/createFileNormalizerFromContext.js.map +1 -0
  169. package/utils/getPresignedPostPayload.d.ts +4 -4
  170. package/utils/getPresignedPostPayload.js +39 -83
  171. package/utils/getPresignedPostPayload.js.map +1 -1
  172. package/utils/mimeTypes.d.ts +5 -0
  173. package/utils/mimeTypes.js +9 -0
  174. package/utils/mimeTypes.js.map +1 -0
  175. package/utils/uploadFileToS3.d.ts +2 -4
  176. package/utils/uploadFileToS3.js +12 -27
  177. package/utils/uploadFileToS3.js.map +1 -1
  178. package/plugins/fileStorageS3.d.ts +0 -6
  179. package/plugins/fileStorageS3.js +0 -68
  180. package/plugins/fileStorageS3.js.map +0 -1
  181. package/plugins/graphqlFileStorageS3.d.ts +0 -4
  182. package/plugins/graphqlFileStorageS3.js +0 -150
  183. package/plugins/graphqlFileStorageS3.js.map +0 -1
  184. package/types.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multiPartUpload/CompleteMultiPartUploadUseCase.js","sources":["../../src/multiPartUpload/CompleteMultiPartUploadUseCase.ts"],"sourcesContent":["import type { S3, Part, ListPartsOutput } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport {\n ListPartsCommand,\n CompleteMultipartUploadCommand\n} from \"@webiny/aws-sdk/client-s3/index.js\";\n\ninterface CompleteMultiPartUploadParams {\n fileKey: string;\n uploadId: string;\n}\n\ninterface GetAllUploadPartsParams {\n Bucket: string;\n Key: string;\n UploadId: string;\n}\n\nexport class CompleteMultiPartUploadUseCase {\n private readonly s3: S3;\n private readonly bucket: string;\n private readonly emptyMarkerValues = [undefined, \"0\"];\n\n constructor(bucket: string, s3Client: S3) {\n this.bucket = bucket;\n this.s3 = s3Client;\n }\n\n async execute(params: CompleteMultiPartUploadParams) {\n const uploadParams = {\n Bucket: this.bucket,\n Key: params.fileKey,\n UploadId: params.uploadId\n };\n\n const allParts = await this.getAllUploadParts(uploadParams);\n\n const s3Params = {\n ...uploadParams,\n MultipartUpload: {\n Parts: allParts\n }\n };\n\n try {\n const command = new CompleteMultipartUploadCommand(s3Params);\n await this.s3.send(command);\n } catch (err) {\n console.error(err);\n throw err;\n }\n }\n\n private async getAllUploadParts(params: GetAllUploadPartsParams) {\n const parts: Part[] = [];\n\n let marker: string | undefined = undefined;\n while (true) {\n const { Parts, PartNumberMarker }: ListPartsOutput = await this.s3.send(\n new ListPartsCommand({\n ...params,\n PartNumberMarker: marker\n })\n );\n\n if (Parts) {\n Parts.forEach(part => parts.push(part));\n }\n\n marker = PartNumberMarker || undefined;\n if (this.isMarkerEmpty(marker)) {\n break;\n }\n }\n\n return parts.map(part => ({\n ETag: part.ETag as string,\n PartNumber: part.PartNumber as number\n }));\n }\n\n private isMarkerEmpty(marker: string | undefined) {\n return this.emptyMarkerValues.includes(marker);\n }\n}\n"],"names":["CompleteMultiPartUploadUseCase","bucket","s3Client","undefined","params","uploadParams","allParts","s3Params","command","CompleteMultipartUploadCommand","err","console","parts","marker","Parts","PartNumberMarker","ListPartsCommand","part"],"mappings":";AAiBO,MAAMA;IAKT,YAAYC,MAAc,EAAEC,QAAY,CAAE;aAFzB,iBAAiB,GAAG;YAACC;YAAW;SAAI;QAGjD,IAAI,CAAC,MAAM,GAAGF;QACd,IAAI,CAAC,EAAE,GAAGC;IACd;IAEA,MAAM,QAAQE,MAAqC,EAAE;QACjD,MAAMC,eAAe;YACjB,QAAQ,IAAI,CAAC,MAAM;YACnB,KAAKD,OAAO,OAAO;YACnB,UAAUA,OAAO,QAAQ;QAC7B;QAEA,MAAME,WAAW,MAAM,IAAI,CAAC,iBAAiB,CAACD;QAE9C,MAAME,WAAW;YACb,GAAGF,YAAY;YACf,iBAAiB;gBACb,OAAOC;YACX;QACJ;QAEA,IAAI;YACA,MAAME,UAAU,IAAIC,+BAA+BF;YACnD,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAACC;QACvB,EAAE,OAAOE,KAAK;YACVC,QAAQ,KAAK,CAACD;YACd,MAAMA;QACV;IACJ;IAEA,MAAc,kBAAkBN,MAA+B,EAAE;QAC7D,MAAMQ,QAAgB,EAAE;QAExB,IAAIC;QACJ,MAAO,KAAM;YACT,MAAM,EAAEC,KAAK,EAAEC,gBAAgB,EAAE,GAAoB,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CACnE,IAAIC,iBAAiB;gBACjB,GAAGZ,MAAM;gBACT,kBAAkBS;YACtB;YAGJ,IAAIC,OACAA,MAAM,OAAO,CAACG,CAAAA,OAAQL,MAAM,IAAI,CAACK;YAGrCJ,SAASE,oBAAoBZ;YAC7B,IAAI,IAAI,CAAC,aAAa,CAACU,SACnB;QAER;QAEA,OAAOD,MAAM,GAAG,CAACK,CAAAA,OAAS;gBACtB,MAAMA,KAAK,IAAI;gBACf,YAAYA,KAAK,UAAU;YAC/B;IACJ;IAEQ,cAAcJ,MAA0B,EAAE;QAC9C,OAAO,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAACA;IAC3C;AACJ"}
@@ -0,0 +1,20 @@
1
+ import type { S3 } from "@webiny/aws-sdk/client-s3/index.js";
2
+ import type { FileData } from "../types.js";
3
+ interface CreateMultiPartUploadParams {
4
+ file: FileData;
5
+ numberOfParts: number;
6
+ }
7
+ export declare class CreateMultiPartUploadUseCase {
8
+ private readonly s3;
9
+ private readonly bucket;
10
+ constructor(bucket: string, s3Client: S3);
11
+ execute({ file, numberOfParts }: CreateMultiPartUploadParams): Promise<{
12
+ file: FileData;
13
+ uploadId: string | undefined;
14
+ parts: {
15
+ url: string;
16
+ partNumber: number;
17
+ }[];
18
+ }>;
19
+ }
20
+ export {};
@@ -0,0 +1,34 @@
1
+ import { UploadPartCommand, getSignedUrl } from "@webiny/aws-sdk/client-s3/index.js";
2
+ class CreateMultiPartUploadUseCase {
3
+ constructor(bucket, s3Client){
4
+ this.bucket = bucket;
5
+ this.s3 = s3Client;
6
+ }
7
+ async execute({ file, numberOfParts }) {
8
+ const s3Params = {
9
+ Bucket: this.bucket,
10
+ Key: file.key
11
+ };
12
+ const { UploadId } = await this.s3.createMultipartUpload(s3Params);
13
+ const parts = await Promise.all(Array.from({
14
+ length: numberOfParts
15
+ }).map((_, index)=>getSignedUrl(this.s3, new UploadPartCommand({
16
+ ...s3Params,
17
+ UploadId,
18
+ PartNumber: index + 1
19
+ }), {
20
+ expiresIn: 86400
21
+ }).then((url)=>({
22
+ url,
23
+ partNumber: index + 1
24
+ }))));
25
+ return {
26
+ file,
27
+ uploadId: UploadId,
28
+ parts
29
+ };
30
+ }
31
+ }
32
+ export { CreateMultiPartUploadUseCase };
33
+
34
+ //# sourceMappingURL=CreateMultiPartUploadUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multiPartUpload/CreateMultiPartUploadUseCase.js","sources":["../../src/multiPartUpload/CreateMultiPartUploadUseCase.ts"],"sourcesContent":["import type { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { getSignedUrl, UploadPartCommand } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport type { FileData } from \"~/types.js\";\n\ninterface CreateMultiPartUploadParams {\n file: FileData;\n numberOfParts: number;\n}\n\nexport class CreateMultiPartUploadUseCase {\n private readonly s3: S3;\n private readonly bucket: string;\n\n constructor(bucket: string, s3Client: S3) {\n this.bucket = bucket;\n this.s3 = s3Client;\n }\n\n async execute({ file, numberOfParts }: CreateMultiPartUploadParams) {\n const s3Params = { Bucket: this.bucket, Key: file.key };\n\n const { UploadId } = await this.s3.createMultipartUpload(s3Params);\n\n const parts = await Promise.all(\n Array.from({ length: numberOfParts }).map((_, index) => {\n return getSignedUrl(\n this.s3,\n new UploadPartCommand({ ...s3Params, UploadId, PartNumber: index + 1 }),\n {\n // URL expires after 24 hours.\n expiresIn: 86400\n }\n ).then(url => ({\n url,\n partNumber: index + 1\n }));\n })\n );\n\n return {\n file,\n uploadId: UploadId,\n parts\n };\n }\n}\n"],"names":["CreateMultiPartUploadUseCase","bucket","s3Client","file","numberOfParts","s3Params","UploadId","parts","Promise","Array","_","index","getSignedUrl","UploadPartCommand","url"],"mappings":";AASO,MAAMA;IAIT,YAAYC,MAAc,EAAEC,QAAY,CAAE;QACtC,IAAI,CAAC,MAAM,GAAGD;QACd,IAAI,CAAC,EAAE,GAAGC;IACd;IAEA,MAAM,QAAQ,EAAEC,IAAI,EAAEC,aAAa,EAA+B,EAAE;QAChE,MAAMC,WAAW;YAAE,QAAQ,IAAI,CAAC,MAAM;YAAE,KAAKF,KAAK,GAAG;QAAC;QAEtD,MAAM,EAAEG,QAAQ,EAAE,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,qBAAqB,CAACD;QAEzD,MAAME,QAAQ,MAAMC,QAAQ,GAAG,CAC3BC,MAAM,IAAI,CAAC;YAAE,QAAQL;QAAc,GAAG,GAAG,CAAC,CAACM,GAAGC,QACnCC,aACH,IAAI,CAAC,EAAE,EACP,IAAIC,kBAAkB;gBAAE,GAAGR,QAAQ;gBAAEC;gBAAU,YAAYK,QAAQ;YAAE,IACrE;gBAEI,WAAW;YACf,GACF,IAAI,CAACG,CAAAA,MAAQ;oBACXA;oBACA,YAAYH,QAAQ;gBACxB;QAIR,OAAO;YACHR;YACA,UAAUG;YACVC;QACJ;IACJ;AACJ"}
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@webiny/api-file-manager-s3",
3
- "version": "0.0.0-unstable.78f581c1d2",
4
- "main": "index.js",
3
+ "version": "0.0.0-unstable.7be00a75a9",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./index.js",
7
+ "./*": "./*"
8
+ },
5
9
  "repository": {
6
10
  "type": "git",
7
11
  "url": "https://github.com/webiny/webiny-js.git"
@@ -10,31 +14,38 @@
10
14
  "author": "Webiny Ltd",
11
15
  "license": "MIT",
12
16
  "dependencies": {
13
- "@webiny/api-file-manager": "0.0.0-unstable.78f581c1d2",
14
- "@webiny/error": "0.0.0-unstable.78f581c1d2",
15
- "@webiny/handler-graphql": "0.0.0-unstable.78f581c1d2",
16
- "@webiny/validation": "0.0.0-unstable.78f581c1d2",
17
- "form-data": "4.0.0",
18
- "node-fetch": "2.6.7",
19
- "sanitize-filename": "1.6.3",
20
- "uniqid": "5.4.0"
17
+ "@webiny/api": "0.0.0-unstable.7be00a75a9",
18
+ "@webiny/api-core": "0.0.0-unstable.7be00a75a9",
19
+ "@webiny/api-file-manager": "0.0.0-unstable.7be00a75a9",
20
+ "@webiny/api-websockets": "0.0.0-unstable.7be00a75a9",
21
+ "@webiny/aws-sdk": "0.0.0-unstable.7be00a75a9",
22
+ "@webiny/feature": "0.0.0-unstable.7be00a75a9",
23
+ "@webiny/handler": "0.0.0-unstable.7be00a75a9",
24
+ "@webiny/handler-aws": "0.0.0-unstable.7be00a75a9",
25
+ "@webiny/handler-graphql": "0.0.0-unstable.7be00a75a9",
26
+ "@webiny/plugins": "0.0.0-unstable.7be00a75a9",
27
+ "@webiny/tasks": "0.0.0-unstable.7be00a75a9",
28
+ "@webiny/utils": "0.0.0-unstable.7be00a75a9",
29
+ "@webiny/validation": "0.0.0-unstable.7be00a75a9",
30
+ "exifreader": "4.39.1",
31
+ "mime": "4.1.0",
32
+ "object-hash": "3.0.0",
33
+ "p-map": "7.0.4",
34
+ "p-reduce": "3.0.0",
35
+ "sanitize-filename": "1.6.4",
36
+ "sharp": "0.34.5"
21
37
  },
22
38
  "devDependencies": {
23
- "@babel/cli": "^7.19.3",
24
- "@babel/core": "^7.19.3",
25
- "@types/node-fetch": "^2.6.1",
26
- "@webiny/cli": "^0.0.0-unstable.78f581c1d2",
27
- "@webiny/project-utils": "^0.0.0-unstable.78f581c1d2",
28
- "rimraf": "^3.0.2",
29
- "typescript": "4.7.4"
39
+ "@webiny/build-tools": "0.0.0-unstable.7be00a75a9",
40
+ "rimraf": "6.1.3",
41
+ "typescript": "6.0.3",
42
+ "vitest": "4.1.7"
30
43
  },
31
44
  "publishConfig": {
32
- "access": "public",
33
- "directory": "dist"
34
- },
35
- "scripts": {
36
- "build": "yarn webiny run build",
37
- "watch": "yarn webiny run watch"
45
+ "access": "public"
38
46
  },
39
- "gitHead": "78f581c1d2e5e6936aa11b9452a66d2a3652a1b2"
47
+ "gitHead": "8476da73b653c89cc1474d968baf55c1b0ae0e5f",
48
+ "webiny": {
49
+ "publishFrom": "dist"
50
+ }
40
51
  }
package/types.d.ts CHANGED
@@ -1,16 +1,21 @@
1
- import S3 from "aws-sdk/clients/s3";
1
+ import type { PresignedPost } from "@webiny/aws-sdk/client-s3/index.js";
2
+ import "@webiny/tasks/features/TaskController/augmentation.js";
2
3
  export interface PresignedPostPayloadData {
3
4
  name: string;
4
5
  type: string;
5
6
  size: number;
6
- keyPrefix: string;
7
+ id?: string;
8
+ key?: string;
9
+ keyPrefix?: string;
10
+ }
11
+ export interface FileData {
12
+ id: string;
13
+ key: string;
14
+ name: string;
15
+ size: number;
16
+ type: string;
7
17
  }
8
18
  export interface PresignedPostPayloadDataResponse {
9
- data: S3.PresignedPost;
10
- file: {
11
- name: string;
12
- key: string;
13
- type: string;
14
- size: number;
15
- };
19
+ data: PresignedPost;
20
+ file: FileData;
16
21
  }
package/types.js CHANGED
@@ -1,5 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
1
+ import "@webiny/tasks/features/TaskController/augmentation.js";
@@ -0,0 +1,3 @@
1
+ export declare class CdnPathsGenerator {
2
+ generate(fileId: string): string[];
3
+ }
@@ -0,0 +1,11 @@
1
+ class CdnPathsGenerator {
2
+ generate(fileId) {
3
+ return [
4
+ `/files/${fileId}/*`,
5
+ `/private/${fileId}/*`
6
+ ];
7
+ }
8
+ }
9
+ export { CdnPathsGenerator };
10
+
11
+ //# sourceMappingURL=CdnPathsGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/CdnPathsGenerator.js","sources":["../../src/utils/CdnPathsGenerator.ts"],"sourcesContent":["export class CdnPathsGenerator {\n generate(fileId: string): string[] {\n return [`/files/${fileId}/*`, `/private/${fileId}/*`];\n }\n}\n"],"names":["CdnPathsGenerator","fileId"],"mappings":"AAAO,MAAMA;IACT,SAASC,MAAc,EAAY;QAC/B,OAAO;YAAC,CAAC,OAAO,EAAEA,OAAO,EAAE,CAAC;YAAE,CAAC,SAAS,EAAEA,OAAO,EAAE,CAAC;SAAC;IACzD;AACJ"}
@@ -0,0 +1,6 @@
1
+ import type { PresignedPostPayloadData } from "../types.js";
2
+ export declare class FileExtension {
3
+ private data;
4
+ constructor(data: PresignedPostPayloadData);
5
+ getValue(): string;
6
+ }
@@ -0,0 +1,16 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,33 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,41 @@
1
+ import { mdbid } from "@webiny/utils";
2
+ import { FileKey } from "./FileKey.js";
3
+ import { mimeTypes as external_mimeTypes_js_mimeTypes } from "./mimeTypes.js";
4
+ const extensionToMime = new Map();
5
+ for (const [mime, extensions] of Object.entries(external_mimeTypes_js_mimeTypes))for (const ext of extensions)if (!extensionToMime.has(ext)) extensionToMime.set(ext, mime);
6
+ function resolveTypeFromName(name) {
7
+ const ext = name.slice(name.lastIndexOf(".") + 1).toLowerCase();
8
+ return extensionToMime.get(ext) || "application/octet-stream";
9
+ }
10
+ class FileNormalizer {
11
+ constructor(modifier){
12
+ this.modifier = modifier;
13
+ }
14
+ async normalizeFile(payload) {
15
+ const data = {
16
+ ...payload,
17
+ id: payload.id || mdbid(),
18
+ type: payload.type || resolveTypeFromName(payload.name)
19
+ };
20
+ const key = new FileKey(data);
21
+ const defaultKey = key.toString();
22
+ const file = {
23
+ name: data.name,
24
+ type: data.type,
25
+ key: defaultKey,
26
+ size: data.size
27
+ };
28
+ if (this.modifier) Object.assign(file, await this.modifier(file));
29
+ if (defaultKey !== file.key) key.setKey(file.key);
30
+ return {
31
+ id: data.id,
32
+ key: key.toString(),
33
+ name: file.name,
34
+ size: file.size,
35
+ type: file.type
36
+ };
37
+ }
38
+ }
39
+ export { FileNormalizer };
40
+
41
+ //# sourceMappingURL=FileNormalizer.js.map
@@ -0,0 +1 @@
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 { 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 return {\n id: data.id,\n key: key.toString(),\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"],"mappings":";;;AAaA,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;QAGvB,OAAO;YACH,IAAIL,KAAK,EAAE;YACX,KAAKE,IAAI,QAAQ;YACjB,MAAMG,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;QACnB;IACJ;AACJ"}
@@ -0,0 +1,30 @@
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 FileUploadModifier {
7
+ private fileSetters;
8
+ setFile(setter: Setter<FileToSign>): void;
9
+ execute(file: FileToSign): Promise<FileToSign>;
10
+ }
11
+ interface FileUploadModifierCallbackParams {
12
+ modifier: {
13
+ setFile: FileUploadModifier["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
+ export interface FileModifier {
27
+ (file: FileToSign): Promise<Partial<FileToSign>> | Partial<FileToSign>;
28
+ }
29
+ export declare const createModifierFromPlugins: (plugins?: FileUploadModifierPlugin[]) => FileModifier;
30
+ export {};
@@ -0,0 +1,39 @@
1
+ import p_reduce from "p-reduce";
2
+ import { Plugin } from "@webiny/plugins";
3
+ class FileUploadModifier {
4
+ setFile(setter) {
5
+ this.fileSetters.push(setter);
6
+ }
7
+ execute(file) {
8
+ return p_reduce(this.fileSetters, async (file, setter)=>({
9
+ ...file,
10
+ ...await setter(file)
11
+ }), file);
12
+ }
13
+ constructor(){
14
+ this.fileSetters = [];
15
+ }
16
+ }
17
+ class FileUploadModifierPlugin extends Plugin {
18
+ static{
19
+ this.type = "fm.s3.uploadModifier";
20
+ }
21
+ constructor(cb){
22
+ super();
23
+ this.cb = cb;
24
+ }
25
+ execute(params) {
26
+ return this.cb(params);
27
+ }
28
+ }
29
+ const createFileUploadModifier = (cb)=>new FileUploadModifierPlugin(cb);
30
+ const createModifierFromPlugins = (plugins = [])=>{
31
+ const modifier = new FileUploadModifier();
32
+ plugins.forEach((pl)=>pl.execute({
33
+ modifier
34
+ }));
35
+ return (file)=>modifier.execute(file);
36
+ };
37
+ export { FileUploadModifierPlugin, createFileUploadModifier, createModifierFromPlugins };
38
+
39
+ //# sourceMappingURL=FileUploadModifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/FileUploadModifier.js","sources":["../../src/utils/FileUploadModifier.ts"],"sourcesContent":["import pReduce from \"p-reduce\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { FileToSign } from \"~/utils/FileNormalizer.js\";\n\ninterface Setter<T> {\n (param: T): T;\n}\n\nclass FileUploadModifier {\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: FileUploadModifier[\"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\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 FileUploadModifier();\n plugins.forEach(pl => pl.execute({ modifier }));\n\n return (file: FileToSign) => modifier.execute(file);\n};\n"],"names":["FileUploadModifier","setter","file","pReduce","FileUploadModifierPlugin","Plugin","cb","params","createFileUploadModifier","createModifierFromPlugins","plugins","modifier","pl"],"mappings":";;AAQA,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;AAOjC,MAAMG,4BAA4B,CACrCC,UAAsC,EAAE;IAExC,MAAMC,WAAW,IAAIX;IACrBU,QAAQ,OAAO,CAACE,CAAAA,KAAMA,GAAG,OAAO,CAAC;YAAED;QAAS;IAE5C,OAAO,CAACT,OAAqBS,SAAS,OAAO,CAACT;AAClD"}
@@ -0,0 +1,3 @@
1
+ import type { Context } from "@webiny/api/types.js";
2
+ import { FileNormalizer } from "../utils/FileNormalizer.js";
3
+ export declare const createFileNormalizerFromContext: (context: Context) => FileNormalizer;
@@ -0,0 +1,9 @@
1
+ import { FileNormalizer } from "./FileNormalizer.js";
2
+ import { FileUploadModifierPlugin, createModifierFromPlugins } from "./FileUploadModifier.js";
3
+ const createFileNormalizerFromContext = (context)=>{
4
+ const modifierPlugins = context.plugins.byType(FileUploadModifierPlugin.type);
5
+ return new FileNormalizer(createModifierFromPlugins(modifierPlugins));
6
+ };
7
+ export { createFileNormalizerFromContext };
8
+
9
+ //# sourceMappingURL=createFileNormalizerFromContext.js.map
@@ -0,0 +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, FileUploadModifierPlugin } from \"~/utils/FileUploadModifier.js\";\n\nexport const createFileNormalizerFromContext = (context: Context) => {\n const modifierPlugins = context.plugins.byType<FileUploadModifierPlugin>(\n FileUploadModifierPlugin.type\n );\n\n return new FileNormalizer(createModifierFromPlugins(modifierPlugins));\n};\n"],"names":["createFileNormalizerFromContext","context","modifierPlugins","FileUploadModifierPlugin","FileNormalizer","createModifierFromPlugins"],"mappings":";;AAIO,MAAMA,kCAAkC,CAACC;IAC5C,MAAMC,kBAAkBD,QAAQ,OAAO,CAAC,MAAM,CAC1CE,yBAAyB,IAAI;IAGjC,OAAO,IAAIC,eAAeC,0BAA0BH;AACxD"}
@@ -1,4 +1,4 @@
1
- import { PresignedPostPayloadData, PresignedPostPayloadDataResponse } from "../types";
2
- import { FileManagerSettings } from "@webiny/api-file-manager/types";
3
- declare const _default: (data: PresignedPostPayloadData, settings: FileManagerSettings) => Promise<PresignedPostPayloadDataResponse>;
4
- export default _default;
1
+ import type { FileData, PresignedPostPayloadDataResponse } from "../types.js";
2
+ import type { FileManagerSettings } from "@webiny/api-file-manager/domain/settings/types.js";
3
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
4
+ export declare const getPresignedPostPayload: (file: FileData, settings: FileManagerSettings, tenantContext: TenantContext.Interface) => Promise<PresignedPostPayloadDataResponse>;