@webiny/api-file-manager-s3 6.0.0-beta.0 → 6.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/README.md +11 -1
  2. package/assetDelivery/assetDeliveryConfig.d.ts +2 -6
  3. package/assetDelivery/assetDeliveryConfig.js +24 -23
  4. package/assetDelivery/assetDeliveryConfig.js.map +1 -1
  5. package/assetDelivery/createAssetDelivery.d.ts +3 -3
  6. package/assetDelivery/createAssetDelivery.js +15 -12
  7. package/assetDelivery/createAssetDelivery.js.map +1 -1
  8. package/assetDelivery/index.d.ts +8 -9
  9. package/assetDelivery/index.js +8 -68
  10. package/assetDelivery/index.js.map +1 -1
  11. package/assetDelivery/s3/S3AssetResolver.d.ts +8 -5
  12. package/assetDelivery/s3/S3AssetResolver.js +19 -27
  13. package/assetDelivery/s3/S3AssetResolver.js.map +1 -1
  14. package/assetDelivery/s3/S3ContentsReader.d.ts +2 -3
  15. package/assetDelivery/s3/S3ContentsReader.js +1 -8
  16. package/assetDelivery/s3/S3ContentsReader.js.map +1 -1
  17. package/assetDelivery/s3/S3ErrorAssetReply.js +2 -9
  18. package/assetDelivery/s3/S3ErrorAssetReply.js.map +1 -1
  19. package/assetDelivery/s3/S3OutputStrategy.d.ts +4 -3
  20. package/assetDelivery/s3/S3OutputStrategy.js +12 -17
  21. package/assetDelivery/s3/S3OutputStrategy.js.map +1 -1
  22. package/assetDelivery/s3/S3RedirectAssetReply.js +4 -11
  23. package/assetDelivery/s3/S3RedirectAssetReply.js.map +1 -1
  24. package/assetDelivery/s3/S3StreamAssetReply.d.ts +2 -1
  25. package/assetDelivery/s3/S3StreamAssetReply.js +4 -11
  26. package/assetDelivery/s3/S3StreamAssetReply.js.map +1 -1
  27. package/assetDelivery/s3/SharpTransform.d.ts +2 -2
  28. package/assetDelivery/s3/SharpTransform.js +63 -37
  29. package/assetDelivery/s3/SharpTransform.js.map +1 -1
  30. package/assetDelivery/s3/transformation/AssetKeyGenerator.d.ts +1 -1
  31. package/assetDelivery/s3/transformation/AssetKeyGenerator.js +3 -12
  32. package/assetDelivery/s3/transformation/AssetKeyGenerator.js.map +1 -1
  33. package/assetDelivery/s3/transformation/CallableContentsReader.d.ts +1 -2
  34. package/assetDelivery/s3/transformation/CallableContentsReader.js +1 -8
  35. package/assetDelivery/s3/transformation/CallableContentsReader.js.map +1 -1
  36. package/assetDelivery/s3/transformation/WidthCollection.js +1 -8
  37. package/assetDelivery/s3/transformation/WidthCollection.js.map +1 -1
  38. package/assetDelivery/s3/transformation/utils.d.ts +1 -3
  39. package/assetDelivery/s3/transformation/utils.js +23 -19
  40. package/assetDelivery/s3/transformation/utils.js.map +1 -1
  41. package/assetDelivery/threatDetection/ObjectKey.d.ts +7 -0
  42. package/assetDelivery/threatDetection/ObjectKey.js +17 -0
  43. package/assetDelivery/threatDetection/ObjectKey.js.map +1 -0
  44. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.d.ts +2 -0
  45. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js +51 -0
  46. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js.map +1 -0
  47. package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.d.ts +2 -0
  48. package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js +6 -0
  49. package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js.map +1 -0
  50. package/assetDelivery/threatDetection/index.d.ts +2 -0
  51. package/assetDelivery/threatDetection/index.js +4 -0
  52. package/assetDelivery/threatDetection/index.js.map +1 -0
  53. package/assetDelivery/threatDetection/processThreatScanResult.d.ts +3 -0
  54. package/assetDelivery/threatDetection/processThreatScanResult.js +65 -0
  55. package/assetDelivery/threatDetection/processThreatScanResult.js.map +1 -0
  56. package/assetDelivery/threatDetection/types.d.ts +9 -0
  57. package/assetDelivery/threatDetection/types.js +3 -0
  58. package/assetDelivery/threatDetection/types.js.map +1 -0
  59. package/assetDelivery/types.d.ts +10 -0
  60. package/assetDelivery/types.js +3 -0
  61. package/assetDelivery/types.js.map +1 -0
  62. package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.d.ts +11 -0
  63. package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js +19 -0
  64. package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js.map +1 -0
  65. package/enterprise/ApplyThreatScanning/feature.d.ts +1 -0
  66. package/enterprise/ApplyThreatScanning/feature.js +10 -0
  67. package/enterprise/ApplyThreatScanning/feature.js.map +1 -0
  68. package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.d.ts +15 -0
  69. package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js +36 -0
  70. package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js.map +1 -0
  71. package/features/DeleteFileFromBucket/DeleteS3FolderTask.d.ts +31 -0
  72. package/features/DeleteFileFromBucket/DeleteS3FolderTask.js +60 -0
  73. package/features/DeleteFileFromBucket/DeleteS3FolderTask.js.map +1 -0
  74. package/features/DeleteFileFromBucket/feature.d.ts +1 -0
  75. package/features/DeleteFileFromBucket/feature.js +12 -0
  76. package/features/DeleteFileFromBucket/feature.js.map +1 -0
  77. package/features/ExtractMetadata/ExtractMetadataHandler.d.ts +11 -0
  78. package/features/ExtractMetadata/ExtractMetadataHandler.js +26 -0
  79. package/features/ExtractMetadata/ExtractMetadataHandler.js.map +1 -0
  80. package/features/ExtractMetadata/ExtractMetadataTask.d.ts +23 -0
  81. package/features/ExtractMetadata/ExtractMetadataTask.js +128 -0
  82. package/features/ExtractMetadata/ExtractMetadataTask.js.map +1 -0
  83. package/features/ExtractMetadata/feature.d.ts +1 -0
  84. package/features/ExtractMetadata/feature.js +12 -0
  85. package/features/ExtractMetadata/feature.js.map +1 -0
  86. package/features/FlushCache/FlushCacheOnFileDeleteHandler.d.ts +12 -0
  87. package/features/FlushCache/FlushCacheOnFileDeleteHandler.js +27 -0
  88. package/features/FlushCache/FlushCacheOnFileDeleteHandler.js.map +1 -0
  89. package/features/FlushCache/FlushCacheOnFileUpdateHandler.d.ts +12 -0
  90. package/features/FlushCache/FlushCacheOnFileUpdateHandler.js +35 -0
  91. package/features/FlushCache/FlushCacheOnFileUpdateHandler.js.map +1 -0
  92. package/features/FlushCache/InvalidateCacheTask.d.ts +25 -0
  93. package/features/FlushCache/InvalidateCacheTask.js +86 -0
  94. package/features/FlushCache/InvalidateCacheTask.js.map +1 -0
  95. package/features/FlushCache/feature.d.ts +1 -0
  96. package/features/FlushCache/feature.js +14 -0
  97. package/features/FlushCache/feature.js.map +1 -0
  98. package/features/WriteFileMetadata/MetadataReader.d.ts +14 -0
  99. package/features/WriteFileMetadata/MetadataReader.js +14 -0
  100. package/features/WriteFileMetadata/MetadataReader.js.map +1 -0
  101. package/features/WriteFileMetadata/MetadataWriter.d.ts +10 -0
  102. package/features/WriteFileMetadata/MetadataWriter.js +28 -0
  103. package/features/WriteFileMetadata/MetadataWriter.js.map +1 -0
  104. package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.d.ts +12 -0
  105. package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js +21 -0
  106. package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js.map +1 -0
  107. package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.d.ts +12 -0
  108. package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js +21 -0
  109. package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js.map +1 -0
  110. package/features/WriteFileMetadata/feature.d.ts +1 -0
  111. package/features/WriteFileMetadata/feature.js +12 -0
  112. package/features/WriteFileMetadata/feature.js.map +1 -0
  113. package/graphql/checkPermissions.d.ts +5 -0
  114. package/{plugins → graphql}/checkPermissions.js +4 -11
  115. package/graphql/checkPermissions.js.map +1 -0
  116. package/graphql/schema.d.ts +1 -0
  117. package/{plugins/graphqlFileStorageS3.js → graphql/schema.js} +49 -57
  118. package/graphql/schema.js.map +1 -0
  119. package/index.d.ts +4 -5
  120. package/index.js +21 -32
  121. package/index.js.map +1 -1
  122. package/multiPartUpload/CompleteMultiPartUploadUseCase.d.ts +1 -1
  123. package/multiPartUpload/CompleteMultiPartUploadUseCase.js +4 -11
  124. package/multiPartUpload/CompleteMultiPartUploadUseCase.js.map +1 -1
  125. package/multiPartUpload/CreateMultiPartUploadUseCase.d.ts +2 -2
  126. package/multiPartUpload/CreateMultiPartUploadUseCase.js +3 -10
  127. package/multiPartUpload/CreateMultiPartUploadUseCase.js.map +1 -1
  128. package/package.json +23 -29
  129. package/types.d.ts +1 -1
  130. package/types.js +1 -5
  131. package/types.js.map +1 -1
  132. package/utils/CdnPathsGenerator.d.ts +3 -0
  133. package/utils/CdnPathsGenerator.js +7 -0
  134. package/utils/CdnPathsGenerator.js.map +1 -0
  135. package/utils/FileExtension.d.ts +1 -1
  136. package/utils/FileExtension.js +3 -10
  137. package/utils/FileExtension.js.map +1 -1
  138. package/utils/FileKey.d.ts +1 -1
  139. package/utils/FileKey.js +5 -13
  140. package/utils/FileKey.js.map +1 -1
  141. package/utils/FileKey.test.js +8 -9
  142. package/utils/FileKey.test.js.map +1 -1
  143. package/utils/FileNormalizer.d.ts +2 -2
  144. package/utils/FileNormalizer.js +5 -12
  145. package/utils/FileNormalizer.js.map +1 -1
  146. package/utils/FileUploadModifier.d.ts +1 -1
  147. package/utils/FileUploadModifier.js +6 -16
  148. package/utils/FileUploadModifier.js.map +1 -1
  149. package/utils/createFileNormalizerFromContext.d.ts +2 -2
  150. package/utils/createFileNormalizerFromContext.js +5 -12
  151. package/utils/createFileNormalizerFromContext.js.map +1 -1
  152. package/utils/getPresignedPostPayload.d.ts +4 -3
  153. package/utils/getPresignedPostPayload.js +10 -15
  154. package/utils/getPresignedPostPayload.js.map +1 -1
  155. package/utils/mimeTypes.js +5 -13
  156. package/utils/mimeTypes.js.map +1 -1
  157. package/utils/uploadFileToS3.d.ts +1 -3
  158. package/utils/uploadFileToS3.js +7 -20
  159. package/utils/uploadFileToS3.js.map +1 -1
  160. package/assetDelivery/createCustomAssetDelivery.d.ts +0 -12
  161. package/assetDelivery/createCustomAssetDelivery.js +0 -28
  162. package/assetDelivery/createCustomAssetDelivery.js.map +0 -1
  163. package/assetDelivery/customAssets/CustomAsset.d.ts +0 -6
  164. package/assetDelivery/customAssets/CustomAsset.js +0 -14
  165. package/assetDelivery/customAssets/CustomAsset.js.map +0 -1
  166. package/assetDelivery/customAssets/CustomAssetProcessor.d.ts +0 -10
  167. package/assetDelivery/customAssets/CustomAssetProcessor.js +0 -25
  168. package/assetDelivery/customAssets/CustomAssetProcessor.js.map +0 -1
  169. package/assetDelivery/customAssets/S3CustomAssetResolver.d.ts +0 -15
  170. package/assetDelivery/customAssets/S3CustomAssetResolver.js +0 -90
  171. package/assetDelivery/customAssets/S3CustomAssetResolver.js.map +0 -1
  172. package/assetDelivery/customAssets/customAssetDeliveryConfig.d.ts +0 -1
  173. package/assetDelivery/customAssets/customAssetDeliveryConfig.js +0 -30
  174. package/assetDelivery/customAssets/customAssetDeliveryConfig.js.map +0 -1
  175. package/assetDelivery/s3/S3AssetMetadataReader.d.ts +0 -15
  176. package/assetDelivery/s3/S3AssetMetadataReader.js +0 -36
  177. package/assetDelivery/s3/S3AssetMetadataReader.js.map +0 -1
  178. package/assetDelivery/s3/transformation/legacyUtils.d.ts +0 -12
  179. package/assetDelivery/s3/transformation/legacyUtils.js +0 -34
  180. package/assetDelivery/s3/transformation/legacyUtils.js.map +0 -1
  181. package/flushCdnCache/CdnPathsGenerator.d.ts +0 -4
  182. package/flushCdnCache/CdnPathsGenerator.js +0 -14
  183. package/flushCdnCache/CdnPathsGenerator.js.map +0 -1
  184. package/flushCdnCache/InvalidateCacheTask.d.ts +0 -18
  185. package/flushCdnCache/InvalidateCacheTask.js +0 -78
  186. package/flushCdnCache/InvalidateCacheTask.js.map +0 -1
  187. package/flushCdnCache/flushCacheOnFileDelete.d.ts +0 -3
  188. package/flushCdnCache/flushCacheOnFileDelete.js +0 -34
  189. package/flushCdnCache/flushCacheOnFileDelete.js.map +0 -1
  190. package/flushCdnCache/flushCacheOnFileUpdate.d.ts +0 -3
  191. package/flushCdnCache/flushCacheOnFileUpdate.js +0 -40
  192. package/flushCdnCache/flushCacheOnFileUpdate.js.map +0 -1
  193. package/flushCdnCache/index.d.ts +0 -1
  194. package/flushCdnCache/index.js +0 -15
  195. package/flushCdnCache/index.js.map +0 -1
  196. package/flushCdnCache/invalidateCacheTaskDefinition.d.ts +0 -2
  197. package/flushCdnCache/invalidateCacheTaskDefinition.js +0 -22
  198. package/flushCdnCache/invalidateCacheTaskDefinition.js.map +0 -1
  199. package/plugins/addFileMetadata.d.ts +0 -10
  200. package/plugins/addFileMetadata.js +0 -67
  201. package/plugins/addFileMetadata.js.map +0 -1
  202. package/plugins/checkPermissions.d.ts +0 -4
  203. package/plugins/checkPermissions.js.map +0 -1
  204. package/plugins/fileStorageS3.d.ts +0 -3
  205. package/plugins/fileStorageS3.js +0 -60
  206. package/plugins/fileStorageS3.js.map +0 -1
  207. package/plugins/graphqlFileStorageS3.d.ts +0 -4
  208. package/plugins/graphqlFileStorageS3.js.map +0 -1
package/utils/FileKey.js CHANGED
@@ -1,16 +1,9 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.FileKey = void 0;
8
- var _sanitizeFilename = _interopRequireDefault(require("sanitize-filename"));
9
- var _FileExtension = require("./FileExtension");
10
- class FileKey {
1
+ import sanitizeFilename from "sanitize-filename";
2
+ import { FileExtension } from "./FileExtension.js";
3
+ export class FileKey {
11
4
  constructor(data) {
12
5
  this.data = data;
13
- this.extension = new _FileExtension.FileExtension(data);
6
+ this.extension = new FileExtension(data);
14
7
  this.key = this.getSanitizedKey();
15
8
  }
16
9
  getExtension() {
@@ -24,10 +17,9 @@ class FileKey {
24
17
  return [this.data.keyPrefix, this.data.id, this.key].filter(Boolean).join("/");
25
18
  }
26
19
  getSanitizedKey() {
27
- const key = (0, _sanitizeFilename.default)(this.data.key || this.data.name).replace(/\s/g, "");
20
+ const key = sanitizeFilename(this.data.key || this.data.name).replace(/\s/g, "");
28
21
  return [key, this.getExtension()].filter(Boolean).join(".");
29
22
  }
30
23
  }
31
- exports.FileKey = FileKey;
32
24
 
33
25
  //# sourceMappingURL=FileKey.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_sanitizeFilename","_interopRequireDefault","require","_FileExtension","FileKey","constructor","data","extension","FileExtension","key","getSanitizedKey","getExtension","getValue","setKey","toString","keyPrefix","id","filter","Boolean","join","sanitizeFilename","name","replace","exports"],"sources":["FileKey.ts"],"sourcesContent":["import sanitizeFilename from \"sanitize-filename\";\nimport { PresignedPostPayloadData } from \"~/types\";\nimport { FileExtension } from \"~/utils/FileExtension\";\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"],"mappings":";;;;;;;AAAA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AAEO,MAAME,OAAO,CAAC;EAKjBC,WAAWA,CAACC,IAA8B,EAAE;IACxC,IAAI,CAACA,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,SAAS,GAAG,IAAIC,4BAAa,CAACF,IAAI,CAAC;IACxC,IAAI,CAACG,GAAG,GAAG,IAAI,CAACC,eAAe,CAAC,CAAC;EACrC;EAEAC,YAAYA,CAAA,EAAG;IACX,OAAO,IAAI,CAACJ,SAAS,CAACK,QAAQ,CAAC,CAAC;EACpC;EAEAC,MAAMA,CAACJ,GAAW,EAAE;IAChB,IAAI,CAACA,GAAG,GAAGA,GAAG;IACd,OAAO,IAAI;EACf;EAEAK,QAAQA,CAAA,EAAG;IACP,OAAO,CAAC,IAAI,CAACR,IAAI,CAACS,SAAS,EAAE,IAAI,CAACT,IAAI,CAACU,EAAE,EAAE,IAAI,CAACP,GAAG,CAAC,CAACQ,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EAClF;EAEQT,eAAeA,CAAA,EAAG;IACtB,MAAMD,GAAG,GAAG,IAAAW,yBAAgB,EAAC,IAAI,CAACd,IAAI,CAACG,GAAG,IAAI,IAAI,CAACH,IAAI,CAACe,IAAI,CAAC,CAACC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IAEhF,OAAO,CAACb,GAAG,EAAE,IAAI,CAACE,YAAY,CAAC,CAAC,CAAC,CAACM,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EAC/D;AACJ;AAACI,OAAA,CAAAnB,OAAA,GAAAA,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["sanitizeFilename","FileExtension","FileKey","constructor","data","extension","key","getSanitizedKey","getExtension","getValue","setKey","toString","keyPrefix","id","filter","Boolean","join","name","replace"],"sources":["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"],"mappings":"AAAA,OAAOA,gBAAgB,MAAM,mBAAmB;AAEhD,SAASC,aAAa;AAEtB,OAAO,MAAMC,OAAO,CAAC;EAKjBC,WAAWA,CAACC,IAA8B,EAAE;IACxC,IAAI,CAACA,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,SAAS,GAAG,IAAIJ,aAAa,CAACG,IAAI,CAAC;IACxC,IAAI,CAACE,GAAG,GAAG,IAAI,CAACC,eAAe,CAAC,CAAC;EACrC;EAEAC,YAAYA,CAAA,EAAG;IACX,OAAO,IAAI,CAACH,SAAS,CAACI,QAAQ,CAAC,CAAC;EACpC;EAEAC,MAAMA,CAACJ,GAAW,EAAE;IAChB,IAAI,CAACA,GAAG,GAAGA,GAAG;IACd,OAAO,IAAI;EACf;EAEAK,QAAQA,CAAA,EAAG;IACP,OAAO,CAAC,IAAI,CAACP,IAAI,CAACQ,SAAS,EAAE,IAAI,CAACR,IAAI,CAACS,EAAE,EAAE,IAAI,CAACP,GAAG,CAAC,CAACQ,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EAClF;EAEQT,eAAeA,CAAA,EAAG;IACtB,MAAMD,GAAG,GAAGN,gBAAgB,CAAC,IAAI,CAACI,IAAI,CAACE,GAAG,IAAI,IAAI,CAACF,IAAI,CAACa,IAAI,CAAC,CAACC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IAEhF,OAAO,CAACZ,GAAG,EAAE,IAAI,CAACE,YAAY,CAAC,CAAC,CAAC,CAACM,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EAC/D;AACJ","ignoreList":[]}
@@ -1,9 +1,8 @@
1
- "use strict";
2
-
3
- var _FileKey = require("./FileKey");
1
+ import { describe, it, expect } from "vitest";
2
+ import { FileKey } from "./FileKey.js";
4
3
  describe("FileKey", () => {
5
4
  it("should generate a file key (extension is included in the name)", () => {
6
- const fileKey = new _FileKey.FileKey({
5
+ const fileKey = new FileKey({
7
6
  size: 1071690,
8
7
  name: "image-14.jpg",
9
8
  type: "image/jpeg"
@@ -11,7 +10,7 @@ describe("FileKey", () => {
11
10
  expect(fileKey.toString()).toEqual("image-14.jpg");
12
11
  });
13
12
  it("should generate a file key (extension derived from file type)", () => {
14
- const fileKey = new _FileKey.FileKey({
13
+ const fileKey = new FileKey({
15
14
  size: 1071690,
16
15
  name: "image-14",
17
16
  type: "image/jpeg"
@@ -19,7 +18,7 @@ describe("FileKey", () => {
19
18
  expect(fileKey.toString()).toEqual("image-14.jpeg");
20
19
  });
21
20
  it("should generate a file key containing id", () => {
22
- const fileKey = new _FileKey.FileKey({
21
+ const fileKey = new FileKey({
23
22
  size: 1071690,
24
23
  name: "image-14.jpeg",
25
24
  type: "image/jpeg",
@@ -28,7 +27,7 @@ describe("FileKey", () => {
28
27
  expect(fileKey.toString()).toEqual("12345678/image-14.jpeg");
29
28
  });
30
29
  it("should generate a file key containing prefix", () => {
31
- const fileKey = new _FileKey.FileKey({
30
+ const fileKey = new FileKey({
32
31
  size: 1071690,
33
32
  name: "image-14.jpeg",
34
33
  type: "image/jpeg",
@@ -37,7 +36,7 @@ describe("FileKey", () => {
37
36
  expect(fileKey.toString()).toEqual("prefix/image-14.jpeg");
38
37
  });
39
38
  it("should generate a file key containing id and prefix", () => {
40
- const fileKey = new _FileKey.FileKey({
39
+ const fileKey = new FileKey({
41
40
  size: 1071690,
42
41
  name: "image-14.jpeg",
43
42
  type: "image/jpeg",
@@ -47,7 +46,7 @@ describe("FileKey", () => {
47
46
  expect(fileKey.toString()).toEqual("prefix/12345678/image-14.jpeg");
48
47
  });
49
48
  it("should use the key defined in the input", () => {
50
- const fileKey = new _FileKey.FileKey({
49
+ const fileKey = new FileKey({
51
50
  size: 1071690,
52
51
  name: "image",
53
52
  type: "image/jpeg",
@@ -1 +1 @@
1
- {"version":3,"names":["_FileKey","require","describe","it","fileKey","FileKey","size","name","type","expect","toString","toEqual","id","keyPrefix","key"],"sources":["FileKey.test.ts"],"sourcesContent":["import { FileKey } from \"./FileKey\";\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.jpeg\");\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"],"mappings":";;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEAC,QAAQ,CAAC,SAAS,EAAE,MAAM;EACtBC,EAAE,CAAC,gEAAgE,EAAE,MAAM;IACvE,MAAMC,OAAO,GAAG,IAAIC,gBAAO,CAAC;MACxBC,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,cAAc;MACpBC,IAAI,EAAE;IACV,CAAC,CAAC;IAEFC,MAAM,CAACL,OAAO,CAACM,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,cAAc,CAAC;EACtD,CAAC,CAAC;EAEFR,EAAE,CAAC,+DAA+D,EAAE,MAAM;IACtE,MAAMC,OAAO,GAAG,IAAIC,gBAAO,CAAC;MACxBC,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,UAAU;MAChBC,IAAI,EAAE;IACV,CAAC,CAAC;IAEFC,MAAM,CAACL,OAAO,CAACM,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,eAAe,CAAC;EACvD,CAAC,CAAC;EAEFR,EAAE,CAAC,0CAA0C,EAAE,MAAM;IACjD,MAAMC,OAAO,GAAG,IAAIC,gBAAO,CAAC;MACxBC,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,eAAe;MACrBC,IAAI,EAAE,YAAY;MAClBI,EAAE,EAAE;IACR,CAAC,CAAC;IAEFH,MAAM,CAACL,OAAO,CAACM,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,wBAAwB,CAAC;EAChE,CAAC,CAAC;EAEFR,EAAE,CAAC,8CAA8C,EAAE,MAAM;IACrD,MAAMC,OAAO,GAAG,IAAIC,gBAAO,CAAC;MACxBC,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,eAAe;MACrBC,IAAI,EAAE,YAAY;MAClBK,SAAS,EAAE;IACf,CAAC,CAAC;IAEFJ,MAAM,CAACL,OAAO,CAACM,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,sBAAsB,CAAC;EAC9D,CAAC,CAAC;EAEFR,EAAE,CAAC,qDAAqD,EAAE,MAAM;IAC5D,MAAMC,OAAO,GAAG,IAAIC,gBAAO,CAAC;MACxBC,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,eAAe;MACrBC,IAAI,EAAE,YAAY;MAClBI,EAAE,EAAE,UAAU;MACdC,SAAS,EAAE;IACf,CAAC,CAAC;IAEFJ,MAAM,CAACL,OAAO,CAACM,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,+BAA+B,CAAC;EACvE,CAAC,CAAC;EAEFR,EAAE,CAAC,yCAAyC,EAAE,MAAM;IAChD,MAAMC,OAAO,GAAG,IAAIC,gBAAO,CAAC;MACxBC,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,YAAY;MAClBM,GAAG,EAAE;IACT,CAAC,CAAC;IAEFL,MAAM,CAACL,OAAO,CAACM,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,cAAc,CAAC;EACtD,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["describe","it","expect","FileKey","fileKey","size","name","type","toString","toEqual","id","keyPrefix","key"],"sources":["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.jpeg\");\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"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,EAAEC,MAAM,QAAQ,QAAQ;AAC7C,SAASC,OAAO;AAEhBH,QAAQ,CAAC,SAAS,EAAE,MAAM;EACtBC,EAAE,CAAC,gEAAgE,EAAE,MAAM;IACvE,MAAMG,OAAO,GAAG,IAAID,OAAO,CAAC;MACxBE,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,cAAc;MACpBC,IAAI,EAAE;IACV,CAAC,CAAC;IAEFL,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,cAAc,CAAC;EACtD,CAAC,CAAC;EAEFR,EAAE,CAAC,+DAA+D,EAAE,MAAM;IACtE,MAAMG,OAAO,GAAG,IAAID,OAAO,CAAC;MACxBE,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,UAAU;MAChBC,IAAI,EAAE;IACV,CAAC,CAAC;IAEFL,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,eAAe,CAAC;EACvD,CAAC,CAAC;EAEFR,EAAE,CAAC,0CAA0C,EAAE,MAAM;IACjD,MAAMG,OAAO,GAAG,IAAID,OAAO,CAAC;MACxBE,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,eAAe;MACrBC,IAAI,EAAE,YAAY;MAClBG,EAAE,EAAE;IACR,CAAC,CAAC;IAEFR,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,wBAAwB,CAAC;EAChE,CAAC,CAAC;EAEFR,EAAE,CAAC,8CAA8C,EAAE,MAAM;IACrD,MAAMG,OAAO,GAAG,IAAID,OAAO,CAAC;MACxBE,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,eAAe;MACrBC,IAAI,EAAE,YAAY;MAClBI,SAAS,EAAE;IACf,CAAC,CAAC;IAEFT,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,sBAAsB,CAAC;EAC9D,CAAC,CAAC;EAEFR,EAAE,CAAC,qDAAqD,EAAE,MAAM;IAC5D,MAAMG,OAAO,GAAG,IAAID,OAAO,CAAC;MACxBE,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,eAAe;MACrBC,IAAI,EAAE,YAAY;MAClBG,EAAE,EAAE,UAAU;MACdC,SAAS,EAAE;IACf,CAAC,CAAC;IAEFT,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,+BAA+B,CAAC;EACvE,CAAC,CAAC;EAEFR,EAAE,CAAC,yCAAyC,EAAE,MAAM;IAChD,MAAMG,OAAO,GAAG,IAAID,OAAO,CAAC;MACxBE,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,OAAO;MACbC,IAAI,EAAE,YAAY;MAClBK,GAAG,EAAE;IACT,CAAC,CAAC;IAEFV,MAAM,CAACE,OAAO,CAACI,QAAQ,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,cAAc,CAAC;EACtD,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import { FileData, PresignedPostPayloadData } from "../types";
2
- import { FileModifier } from "./FileUploadModifier";
1
+ import type { FileData, PresignedPostPayloadData } from "../types.js";
2
+ import type { FileModifier } from "./FileUploadModifier.js";
3
3
  export interface FileToSign {
4
4
  name: string;
5
5
  key: string;
@@ -1,27 +1,21 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.FileNormalizer = void 0;
7
- var _utils = require("@webiny/utils");
8
- var _FileKey = require("./FileKey");
1
+ import { mdbid } from "@webiny/utils";
2
+ import { FileKey } from "./FileKey.js";
9
3
  /**
10
4
  * FileNormalizer normalizes file data, before it's signed for upload to S3.
11
5
  * It generates a unique file id, and makes sure that the file key includes the unique id.
12
6
  *
13
7
  */
14
- class FileNormalizer {
8
+ export class FileNormalizer {
15
9
  constructor(modifier) {
16
10
  this.modifier = modifier;
17
11
  }
18
12
  async normalizeFile(payload) {
19
13
  const data = {
20
14
  ...payload,
21
- id: payload.id || (0, _utils.mdbid)(),
15
+ id: payload.id || mdbid(),
22
16
  type: payload.type || "application/octet-stream"
23
17
  };
24
- const key = new _FileKey.FileKey(data);
18
+ const key = new FileKey(data);
25
19
  const defaultKey = key.toString();
26
20
  const file = {
27
21
  name: data.name,
@@ -44,6 +38,5 @@ class FileNormalizer {
44
38
  };
45
39
  }
46
40
  }
47
- exports.FileNormalizer = FileNormalizer;
48
41
 
49
42
  //# sourceMappingURL=FileNormalizer.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_utils","require","_FileKey","FileNormalizer","constructor","modifier","normalizeFile","payload","data","id","mdbid","type","key","FileKey","defaultKey","toString","file","name","size","Object","assign","setKey","exports"],"sources":["FileNormalizer.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { FileData, PresignedPostPayloadData } from \"~/types\";\nimport { FileKey } from \"~/utils/FileKey\";\nimport { FileModifier } from \"./FileUploadModifier\";\n\nexport interface FileToSign {\n name: string;\n key: string;\n type: string;\n size: number;\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 || \"application/octet-stream\"\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"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AAUA;AACA;AACA;AACA;AACA;AACO,MAAME,cAAc,CAAC;EAGxBC,WAAWA,CAACC,QAAuB,EAAE;IACjC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,aAAaA,CAACC,OAAiC,EAAqB;IACtE,MAAMC,IAAI,GAAG;MACT,GAAGD,OAAO;MACVE,EAAE,EAAEF,OAAO,CAACE,EAAE,IAAI,IAAAC,YAAK,EAAC,CAAC;MACzBC,IAAI,EAAEJ,OAAO,CAACI,IAAI,IAAI;IAC1B,CAAC;IAED,MAAMC,GAAG,GAAG,IAAIC,gBAAO,CAACL,IAAI,CAAC;IAC7B,MAAMM,UAAU,GAAGF,GAAG,CAACG,QAAQ,CAAC,CAAC;IAEjC,MAAMC,IAAgB,GAAG;MACrBC,IAAI,EAAET,IAAI,CAACS,IAAI;MACfN,IAAI,EAAEH,IAAI,CAACG,IAAI;MACfC,GAAG,EAAEE,UAAU;MACfI,IAAI,EAAEV,IAAI,CAACU;IACf,CAAC;IAED,IAAI,IAAI,CAACb,QAAQ,EAAE;MACfc,MAAM,CAACC,MAAM,CAACJ,IAAI,EAAE,MAAM,IAAI,CAACX,QAAQ,CAACW,IAAI,CAAC,CAAC;IAClD;IAEA,IAAIF,UAAU,KAAKE,IAAI,CAACJ,GAAG,EAAE;MACzBA,GAAG,CAACS,MAAM,CAACL,IAAI,CAACJ,GAAG,CAAC;IACxB;IAEA,OAAO;MACHH,EAAE,EAAED,IAAI,CAACC,EAAE;MACXG,GAAG,EAAEA,GAAG,CAACG,QAAQ,CAAC,CAAC;MACnBE,IAAI,EAAED,IAAI,CAACC,IAAI;MACfC,IAAI,EAAEF,IAAI,CAACE,IAAI;MACfP,IAAI,EAAEK,IAAI,CAACL;IACf,CAAC;EACL;AACJ;AAACW,OAAA,CAAAnB,cAAA,GAAAA,cAAA","ignoreList":[]}
1
+ {"version":3,"names":["mdbid","FileKey","FileNormalizer","constructor","modifier","normalizeFile","payload","data","id","type","key","defaultKey","toString","file","name","size","Object","assign","setKey"],"sources":["FileNormalizer.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport type { FileData, PresignedPostPayloadData } from \"~/types.js\";\nimport { FileKey } from \"~/utils/FileKey.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\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 || \"application/octet-stream\"\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"],"mappings":"AAAA,SAASA,KAAK,QAAQ,eAAe;AAErC,SAASC,OAAO;AAUhB;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAAc,CAAC;EAGxBC,WAAWA,CAACC,QAAuB,EAAE;IACjC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,aAAaA,CAACC,OAAiC,EAAqB;IACtE,MAAMC,IAAI,GAAG;MACT,GAAGD,OAAO;MACVE,EAAE,EAAEF,OAAO,CAACE,EAAE,IAAIR,KAAK,CAAC,CAAC;MACzBS,IAAI,EAAEH,OAAO,CAACG,IAAI,IAAI;IAC1B,CAAC;IAED,MAAMC,GAAG,GAAG,IAAIT,OAAO,CAACM,IAAI,CAAC;IAC7B,MAAMI,UAAU,GAAGD,GAAG,CAACE,QAAQ,CAAC,CAAC;IAEjC,MAAMC,IAAgB,GAAG;MACrBC,IAAI,EAAEP,IAAI,CAACO,IAAI;MACfL,IAAI,EAAEF,IAAI,CAACE,IAAI;MACfC,GAAG,EAAEC,UAAU;MACfI,IAAI,EAAER,IAAI,CAACQ;IACf,CAAC;IAED,IAAI,IAAI,CAACX,QAAQ,EAAE;MACfY,MAAM,CAACC,MAAM,CAACJ,IAAI,EAAE,MAAM,IAAI,CAACT,QAAQ,CAACS,IAAI,CAAC,CAAC;IAClD;IAEA,IAAIF,UAAU,KAAKE,IAAI,CAACH,GAAG,EAAE;MACzBA,GAAG,CAACQ,MAAM,CAACL,IAAI,CAACH,GAAG,CAAC;IACxB;IAEA,OAAO;MACHF,EAAE,EAAED,IAAI,CAACC,EAAE;MACXE,GAAG,EAAEA,GAAG,CAACE,QAAQ,CAAC,CAAC;MACnBE,IAAI,EAAED,IAAI,CAACC,IAAI;MACfC,IAAI,EAAEF,IAAI,CAACE,IAAI;MACfN,IAAI,EAAEI,IAAI,CAACJ;IACf,CAAC;EACL;AACJ","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from "@webiny/plugins";
2
- import { FileToSign } from "./FileNormalizer";
2
+ import type { FileToSign } from "../utils/FileNormalizer.js";
3
3
  interface Setter<T> {
4
4
  (param: T): T;
5
5
  }
@@ -1,19 +1,12 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createModifierFromPlugins = exports.createFileUploadModifier = exports.FileUploadModifierPlugin = void 0;
8
- var _pReduce = _interopRequireDefault(require("p-reduce"));
9
- var _plugins = require("@webiny/plugins");
1
+ import pReduce from "p-reduce";
2
+ import { Plugin } from "@webiny/plugins";
10
3
  class FileUploadModifier {
11
4
  fileSetters = [];
12
5
  setFile(setter) {
13
6
  this.fileSetters.push(setter);
14
7
  }
15
8
  execute(file) {
16
- return (0, _pReduce.default)(this.fileSetters, async (file, setter) => {
9
+ return pReduce(this.fileSetters, async (file, setter) => {
17
10
  // We need to spread the original file, then add (potentially) partial changes.
18
11
  return {
19
12
  ...file,
@@ -22,7 +15,7 @@ class FileUploadModifier {
22
15
  }, file);
23
16
  }
24
17
  }
25
- class FileUploadModifierPlugin extends _plugins.Plugin {
18
+ export class FileUploadModifierPlugin extends Plugin {
26
19
  static type = "fm.s3.uploadModifier";
27
20
  constructor(cb) {
28
21
  super();
@@ -32,18 +25,15 @@ class FileUploadModifierPlugin extends _plugins.Plugin {
32
25
  return this.cb(params);
33
26
  }
34
27
  }
35
- exports.FileUploadModifierPlugin = FileUploadModifierPlugin;
36
- const createFileUploadModifier = cb => {
28
+ export const createFileUploadModifier = cb => {
37
29
  return new FileUploadModifierPlugin(cb);
38
30
  };
39
- exports.createFileUploadModifier = createFileUploadModifier;
40
- const createModifierFromPlugins = (plugins = []) => {
31
+ export const createModifierFromPlugins = (plugins = []) => {
41
32
  const modifier = new FileUploadModifier();
42
33
  plugins.forEach(pl => pl.execute({
43
34
  modifier
44
35
  }));
45
36
  return file => modifier.execute(file);
46
37
  };
47
- exports.createModifierFromPlugins = createModifierFromPlugins;
48
38
 
49
39
  //# sourceMappingURL=FileUploadModifier.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_pReduce","_interopRequireDefault","require","_plugins","FileUploadModifier","fileSetters","setFile","setter","push","execute","file","pReduce","FileUploadModifierPlugin","Plugin","type","constructor","cb","params","exports","createFileUploadModifier","createModifierFromPlugins","plugins","modifier","forEach","pl"],"sources":["FileUploadModifier.ts"],"sourcesContent":["import pReduce from \"p-reduce\";\nimport { Plugin } from \"@webiny/plugins\";\nimport { FileToSign } from \"~/utils/FileNormalizer\";\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"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAOA,MAAME,kBAAkB,CAAC;EACbC,WAAW,GAAyB,EAAE;EAE9CC,OAAOA,CAACC,MAA0B,EAAQ;IACtC,IAAI,CAACF,WAAW,CAACG,IAAI,CAACD,MAAM,CAAC;EACjC;EAEAE,OAAOA,CAACC,IAAgB,EAAE;IACtB,OAAO,IAAAC,gBAAO,EACV,IAAI,CAACN,WAAW,EAChB,OAAOK,IAAI,EAAEH,MAAM,KAAK;MACpB;MACA,OAAO;QAAE,GAAGG,IAAI;QAAE,IAAI,MAAMH,MAAM,CAACG,IAAI,CAAC;MAAE,CAAC;IAC/C,CAAC,EACDA,IACJ,CAAC;EACL;AACJ;AAQO,MAAME,wBAAwB,SAASC,eAAM,CAAC;EACjD,OAAuBC,IAAI,GAAG,sBAAsB;EAGpDC,WAAWA,CAACC,EAA8B,EAAE;IACxC,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EAEAP,OAAOA,CAACQ,MAAwC,EAAE;IAC9C,OAAO,IAAI,CAACD,EAAE,CAACC,MAAM,CAAC;EAC1B;AACJ;AAACC,OAAA,CAAAN,wBAAA,GAAAA,wBAAA;AAMM,MAAMO,wBAAwB,GAAIH,EAA8B,IAAK;EACxE,OAAO,IAAIJ,wBAAwB,CAACI,EAAE,CAAC;AAC3C,CAAC;AAACE,OAAA,CAAAC,wBAAA,GAAAA,wBAAA;AAMK,MAAMC,yBAAyB,GAAGA,CACrCC,OAAmC,GAAG,EAAE,KACzB;EACf,MAAMC,QAAQ,GAAG,IAAIlB,kBAAkB,CAAC,CAAC;EACzCiB,OAAO,CAACE,OAAO,CAACC,EAAE,IAAIA,EAAE,CAACf,OAAO,CAAC;IAAEa;EAAS,CAAC,CAAC,CAAC;EAE/C,OAAQZ,IAAgB,IAAKY,QAAQ,CAACb,OAAO,CAACC,IAAI,CAAC;AACvD,CAAC;AAACQ,OAAA,CAAAE,yBAAA,GAAAA,yBAAA","ignoreList":[]}
1
+ {"version":3,"names":["pReduce","Plugin","FileUploadModifier","fileSetters","setFile","setter","push","execute","file","FileUploadModifierPlugin","type","constructor","cb","params","createFileUploadModifier","createModifierFromPlugins","plugins","modifier","forEach","pl"],"sources":["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"],"mappings":"AAAA,OAAOA,OAAO,MAAM,UAAU;AAC9B,SAASC,MAAM,QAAQ,iBAAiB;AAOxC,MAAMC,kBAAkB,CAAC;EACbC,WAAW,GAAyB,EAAE;EAE9CC,OAAOA,CAACC,MAA0B,EAAQ;IACtC,IAAI,CAACF,WAAW,CAACG,IAAI,CAACD,MAAM,CAAC;EACjC;EAEAE,OAAOA,CAACC,IAAgB,EAAE;IACtB,OAAOR,OAAO,CACV,IAAI,CAACG,WAAW,EAChB,OAAOK,IAAI,EAAEH,MAAM,KAAK;MACpB;MACA,OAAO;QAAE,GAAGG,IAAI;QAAE,IAAI,MAAMH,MAAM,CAACG,IAAI,CAAC;MAAE,CAAC;IAC/C,CAAC,EACDA,IACJ,CAAC;EACL;AACJ;AAQA,OAAO,MAAMC,wBAAwB,SAASR,MAAM,CAAC;EACjD,OAAuBS,IAAI,GAAG,sBAAsB;EAGpDC,WAAWA,CAACC,EAA8B,EAAE;IACxC,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EAEAL,OAAOA,CAACM,MAAwC,EAAE;IAC9C,OAAO,IAAI,CAACD,EAAE,CAACC,MAAM,CAAC;EAC1B;AACJ;AAMA,OAAO,MAAMC,wBAAwB,GAAIF,EAA8B,IAAK;EACxE,OAAO,IAAIH,wBAAwB,CAACG,EAAE,CAAC;AAC3C,CAAC;AAMD,OAAO,MAAMG,yBAAyB,GAAGA,CACrCC,OAAmC,GAAG,EAAE,KACzB;EACf,MAAMC,QAAQ,GAAG,IAAIf,kBAAkB,CAAC,CAAC;EACzCc,OAAO,CAACE,OAAO,CAACC,EAAE,IAAIA,EAAE,CAACZ,OAAO,CAAC;IAAEU;EAAS,CAAC,CAAC,CAAC;EAE/C,OAAQT,IAAgB,IAAKS,QAAQ,CAACV,OAAO,CAACC,IAAI,CAAC;AACvD,CAAC","ignoreList":[]}
@@ -1,3 +1,3 @@
1
- import { Context } from "@webiny/api/types";
2
- import { FileNormalizer } from "./FileNormalizer";
1
+ import type { Context } from "@webiny/api/types.js";
2
+ import { FileNormalizer } from "../utils/FileNormalizer.js";
3
3
  export declare const createFileNormalizerFromContext: (context: Context) => FileNormalizer;
@@ -1,15 +1,8 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createFileNormalizerFromContext = void 0;
7
- var _FileNormalizer = require("./FileNormalizer");
8
- var _FileUploadModifier = require("./FileUploadModifier");
9
- const createFileNormalizerFromContext = context => {
10
- const modifierPlugins = context.plugins.byType(_FileUploadModifier.FileUploadModifierPlugin.type);
11
- return new _FileNormalizer.FileNormalizer((0, _FileUploadModifier.createModifierFromPlugins)(modifierPlugins));
1
+ import { FileNormalizer } from "./FileNormalizer.js";
2
+ import { createModifierFromPlugins, FileUploadModifierPlugin } from "./FileUploadModifier.js";
3
+ export const createFileNormalizerFromContext = context => {
4
+ const modifierPlugins = context.plugins.byType(FileUploadModifierPlugin.type);
5
+ return new FileNormalizer(createModifierFromPlugins(modifierPlugins));
12
6
  };
13
- exports.createFileNormalizerFromContext = createFileNormalizerFromContext;
14
7
 
15
8
  //# sourceMappingURL=createFileNormalizerFromContext.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_FileNormalizer","require","_FileUploadModifier","createFileNormalizerFromContext","context","modifierPlugins","plugins","byType","FileUploadModifierPlugin","type","FileNormalizer","createModifierFromPlugins","exports"],"sources":["createFileNormalizerFromContext.ts"],"sourcesContent":["import { Context } from \"@webiny/api/types\";\nimport { FileNormalizer } from \"~/utils/FileNormalizer\";\nimport { createModifierFromPlugins, FileUploadModifierPlugin } from \"~/utils/FileUploadModifier\";\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"],"mappings":";;;;;;AACA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AAEO,MAAME,+BAA+B,GAAIC,OAAgB,IAAK;EACjE,MAAMC,eAAe,GAAGD,OAAO,CAACE,OAAO,CAACC,MAAM,CAC1CC,4CAAwB,CAACC,IAC7B,CAAC;EAED,OAAO,IAAIC,8BAAc,CAAC,IAAAC,6CAAyB,EAACN,eAAe,CAAC,CAAC;AACzE,CAAC;AAACO,OAAA,CAAAT,+BAAA,GAAAA,+BAAA","ignoreList":[]}
1
+ {"version":3,"names":["FileNormalizer","createModifierFromPlugins","FileUploadModifierPlugin","createFileNormalizerFromContext","context","modifierPlugins","plugins","byType","type"],"sources":["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"],"mappings":"AACA,SAASA,cAAc;AACvB,SAASC,yBAAyB,EAAEC,wBAAwB;AAE5D,OAAO,MAAMC,+BAA+B,GAAIC,OAAgB,IAAK;EACjE,MAAMC,eAAe,GAAGD,OAAO,CAACE,OAAO,CAACC,MAAM,CAC1CL,wBAAwB,CAACM,IAC7B,CAAC;EAED,OAAO,IAAIR,cAAc,CAACC,yBAAyB,CAACI,eAAe,CAAC,CAAC;AACzE,CAAC","ignoreList":[]}
@@ -1,3 +1,4 @@
1
- import { FileManagerSettings } from "@webiny/api-file-manager/types";
2
- import { FileData, PresignedPostPayloadDataResponse } from "../types";
3
- export declare const getPresignedPostPayload: (file: FileData, settings: FileManagerSettings) => Promise<PresignedPostPayloadDataResponse>;
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>;
@@ -1,28 +1,24 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getPresignedPostPayload = void 0;
7
- var _clientS = require("@webiny/aws-sdk/client-s3");
8
- var _validation = require("@webiny/validation");
1
+ import { S3Client, createPresignedPost } from "@webiny/aws-sdk/client-s3/index.js";
2
+ import { validation } from "@webiny/validation";
9
3
  const S3_BUCKET = process.env.S3_BUCKET;
10
4
  const UPLOAD_MAX_FILE_SIZE_DEFAULT = 1099511627776; // 1TB
11
5
 
12
6
  const sanitizeFileSizeValue = (value, defaultValue) => {
13
7
  try {
14
- _validation.validation.validateSync(value, "required,numeric,gte:0");
8
+ validation.validateSync(value, "required,numeric,gte:0");
15
9
  return value;
16
- } catch (e) {
10
+ } catch {
17
11
  // TODO @ts-refactor No need to log the error?
18
12
  return defaultValue;
19
13
  }
20
14
  };
21
- const getPresignedPostPayload = async (file, settings) => {
15
+ export const getPresignedPostPayload = async (file, settings, tenantContext) => {
22
16
  const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);
23
17
  const uploadMaxFileSize = sanitizeFileSizeValue(settings.uploadMaxFileSize, UPLOAD_MAX_FILE_SIZE_DEFAULT);
18
+ const tenant = tenantContext.getTenant();
19
+ const storageKey = `tenants/${tenant.id}/files/${file.key}`;
24
20
  const params = {
25
- Key: file.key,
21
+ Key: storageKey,
26
22
  Expires: 60,
27
23
  Bucket: S3_BUCKET,
28
24
  Conditions: [["content-length-range", uploadMinFileSize, uploadMaxFileSize]],
@@ -33,13 +29,12 @@ const getPresignedPostPayload = async (file, settings) => {
33
29
  if (params.Key.startsWith("/")) {
34
30
  params.Key = params.Key.slice(1);
35
31
  }
36
- const s3 = new _clientS.S3Client();
37
- const payload = await (0, _clientS.createPresignedPost)(s3, params);
32
+ const s3 = new S3Client();
33
+ const payload = await createPresignedPost(s3, params);
38
34
  return {
39
35
  data: payload,
40
36
  file
41
37
  };
42
38
  };
43
- exports.getPresignedPostPayload = getPresignedPostPayload;
44
39
 
45
40
  //# sourceMappingURL=getPresignedPostPayload.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_clientS","require","_validation","S3_BUCKET","process","env","UPLOAD_MAX_FILE_SIZE_DEFAULT","sanitizeFileSizeValue","value","defaultValue","validation","validateSync","e","getPresignedPostPayload","file","settings","uploadMinFileSize","uploadMaxFileSize","params","Key","key","Expires","Bucket","Conditions","Fields","type","startsWith","slice","s3","S3Client","payload","createPresignedPost","data","exports"],"sources":["getPresignedPostPayload.ts"],"sourcesContent":["import { S3Client, createPresignedPost, PresignedPostOptions } from \"@webiny/aws-sdk/client-s3\";\nimport { validation } from \"@webiny/validation\";\nimport { FileManagerSettings } from \"@webiny/api-file-manager/types\";\nimport { FileData, PresignedPostPayloadDataResponse } from \"~/types\";\n\nconst S3_BUCKET = process.env.S3_BUCKET;\nconst UPLOAD_MAX_FILE_SIZE_DEFAULT = 1099511627776; // 1TB\n\nconst sanitizeFileSizeValue = (value: number, defaultValue: number): number => {\n try {\n validation.validateSync(value, \"required,numeric,gte:0\");\n return value;\n } catch (e) {\n // TODO @ts-refactor No need to log the error?\n return defaultValue;\n }\n};\n\nexport const getPresignedPostPayload = async (\n file: FileData,\n settings: FileManagerSettings\n): Promise<PresignedPostPayloadDataResponse> => {\n const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);\n const uploadMaxFileSize = sanitizeFileSizeValue(\n settings.uploadMaxFileSize,\n UPLOAD_MAX_FILE_SIZE_DEFAULT\n );\n\n const params = {\n Key: file.key,\n Expires: 60,\n Bucket: S3_BUCKET as string,\n Conditions: [\n [\"content-length-range\", uploadMinFileSize, uploadMaxFileSize]\n ] as PresignedPostOptions[\"Conditions\"],\n Fields: {\n \"Content-Type\": file.type\n }\n };\n\n if (params.Key.startsWith(\"/\")) {\n params.Key = params.Key.slice(1);\n }\n\n const s3 = new S3Client();\n const payload = await createPresignedPost(s3, params);\n\n return {\n data: payload,\n file\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAIA,MAAME,SAAS,GAAGC,OAAO,CAACC,GAAG,CAACF,SAAS;AACvC,MAAMG,4BAA4B,GAAG,aAAa,CAAC,CAAC;;AAEpD,MAAMC,qBAAqB,GAAGA,CAACC,KAAa,EAAEC,YAAoB,KAAa;EAC3E,IAAI;IACAC,sBAAU,CAACC,YAAY,CAACH,KAAK,EAAE,wBAAwB,CAAC;IACxD,OAAOA,KAAK;EAChB,CAAC,CAAC,OAAOI,CAAC,EAAE;IACR;IACA,OAAOH,YAAY;EACvB;AACJ,CAAC;AAEM,MAAMI,uBAAuB,GAAG,MAAAA,CACnCC,IAAc,EACdC,QAA6B,KACe;EAC5C,MAAMC,iBAAiB,GAAGT,qBAAqB,CAACQ,QAAQ,CAACC,iBAAiB,EAAE,CAAC,CAAC;EAC9E,MAAMC,iBAAiB,GAAGV,qBAAqB,CAC3CQ,QAAQ,CAACE,iBAAiB,EAC1BX,4BACJ,CAAC;EAED,MAAMY,MAAM,GAAG;IACXC,GAAG,EAAEL,IAAI,CAACM,GAAG;IACbC,OAAO,EAAE,EAAE;IACXC,MAAM,EAAEnB,SAAmB;IAC3BoB,UAAU,EAAE,CACR,CAAC,sBAAsB,EAAEP,iBAAiB,EAAEC,iBAAiB,CAAC,CAC3B;IACvCO,MAAM,EAAE;MACJ,cAAc,EAAEV,IAAI,CAACW;IACzB;EACJ,CAAC;EAED,IAAIP,MAAM,CAACC,GAAG,CAACO,UAAU,CAAC,GAAG,CAAC,EAAE;IAC5BR,MAAM,CAACC,GAAG,GAAGD,MAAM,CAACC,GAAG,CAACQ,KAAK,CAAC,CAAC,CAAC;EACpC;EAEA,MAAMC,EAAE,GAAG,IAAIC,iBAAQ,CAAC,CAAC;EACzB,MAAMC,OAAO,GAAG,MAAM,IAAAC,4BAAmB,EAACH,EAAE,EAAEV,MAAM,CAAC;EAErD,OAAO;IACHc,IAAI,EAAEF,OAAO;IACbhB;EACJ,CAAC;AACL,CAAC;AAACmB,OAAA,CAAApB,uBAAA,GAAAA,uBAAA","ignoreList":[]}
1
+ {"version":3,"names":["S3Client","createPresignedPost","validation","S3_BUCKET","process","env","UPLOAD_MAX_FILE_SIZE_DEFAULT","sanitizeFileSizeValue","value","defaultValue","validateSync","getPresignedPostPayload","file","settings","tenantContext","uploadMinFileSize","uploadMaxFileSize","tenant","getTenant","storageKey","id","key","params","Key","Expires","Bucket","Conditions","Fields","type","startsWith","slice","s3","payload","data"],"sources":["getPresignedPostPayload.ts"],"sourcesContent":["import type { PresignedPostOptions } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { S3Client, createPresignedPost } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { validation } from \"@webiny/validation\";\nimport type { FileData, PresignedPostPayloadDataResponse } from \"~/types.js\";\nimport type { FileManagerSettings } from \"@webiny/api-file-manager/domain/settings/types.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\n\nconst S3_BUCKET = process.env.S3_BUCKET;\nconst UPLOAD_MAX_FILE_SIZE_DEFAULT = 1099511627776; // 1TB\n\nconst sanitizeFileSizeValue = (value: number, defaultValue: number): number => {\n try {\n validation.validateSync(value, \"required,numeric,gte:0\");\n return value;\n } catch {\n // TODO @ts-refactor No need to log the error?\n return defaultValue;\n }\n};\n\nexport const getPresignedPostPayload = async (\n file: FileData,\n settings: FileManagerSettings,\n tenantContext: TenantContext.Interface\n): Promise<PresignedPostPayloadDataResponse> => {\n const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);\n const uploadMaxFileSize = sanitizeFileSizeValue(\n settings.uploadMaxFileSize,\n UPLOAD_MAX_FILE_SIZE_DEFAULT\n );\n\n const tenant = tenantContext.getTenant();\n const storageKey = `tenants/${tenant.id}/files/${file.key}`;\n\n const params = {\n Key: storageKey,\n Expires: 60,\n Bucket: S3_BUCKET as string,\n Conditions: [\n [\"content-length-range\", uploadMinFileSize, uploadMaxFileSize]\n ] as PresignedPostOptions[\"Conditions\"],\n Fields: {\n \"Content-Type\": file.type\n }\n };\n\n if (params.Key.startsWith(\"/\")) {\n params.Key = params.Key.slice(1);\n }\n\n const s3 = new S3Client();\n const payload = await createPresignedPost(s3, params);\n\n return {\n data: payload,\n file\n };\n};\n"],"mappings":"AACA,SAASA,QAAQ,EAAEC,mBAAmB,QAAQ,oCAAoC;AAClF,SAASC,UAAU,QAAQ,oBAAoB;AAK/C,MAAMC,SAAS,GAAGC,OAAO,CAACC,GAAG,CAACF,SAAS;AACvC,MAAMG,4BAA4B,GAAG,aAAa,CAAC,CAAC;;AAEpD,MAAMC,qBAAqB,GAAGA,CAACC,KAAa,EAAEC,YAAoB,KAAa;EAC3E,IAAI;IACAP,UAAU,CAACQ,YAAY,CAACF,KAAK,EAAE,wBAAwB,CAAC;IACxD,OAAOA,KAAK;EAChB,CAAC,CAAC,MAAM;IACJ;IACA,OAAOC,YAAY;EACvB;AACJ,CAAC;AAED,OAAO,MAAME,uBAAuB,GAAG,MAAAA,CACnCC,IAAc,EACdC,QAA6B,EAC7BC,aAAsC,KACM;EAC5C,MAAMC,iBAAiB,GAAGR,qBAAqB,CAACM,QAAQ,CAACE,iBAAiB,EAAE,CAAC,CAAC;EAC9E,MAAMC,iBAAiB,GAAGT,qBAAqB,CAC3CM,QAAQ,CAACG,iBAAiB,EAC1BV,4BACJ,CAAC;EAED,MAAMW,MAAM,GAAGH,aAAa,CAACI,SAAS,CAAC,CAAC;EACxC,MAAMC,UAAU,GAAG,WAAWF,MAAM,CAACG,EAAE,UAAUR,IAAI,CAACS,GAAG,EAAE;EAE3D,MAAMC,MAAM,GAAG;IACXC,GAAG,EAAEJ,UAAU;IACfK,OAAO,EAAE,EAAE;IACXC,MAAM,EAAEtB,SAAmB;IAC3BuB,UAAU,EAAE,CACR,CAAC,sBAAsB,EAAEX,iBAAiB,EAAEC,iBAAiB,CAAC,CAC3B;IACvCW,MAAM,EAAE;MACJ,cAAc,EAAEf,IAAI,CAACgB;IACzB;EACJ,CAAC;EAED,IAAIN,MAAM,CAACC,GAAG,CAACM,UAAU,CAAC,GAAG,CAAC,EAAE;IAC5BP,MAAM,CAACC,GAAG,GAAGD,MAAM,CAACC,GAAG,CAACO,KAAK,CAAC,CAAC,CAAC;EACpC;EAEA,MAAMC,EAAE,GAAG,IAAI/B,QAAQ,CAAC,CAAC;EACzB,MAAMgC,OAAO,GAAG,MAAM/B,mBAAmB,CAAC8B,EAAE,EAAET,MAAM,CAAC;EAErD,OAAO;IACHW,IAAI,EAAED,OAAO;IACbpB;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
@@ -1,23 +1,15 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.mimeTypes = void 0;
8
- var _other = _interopRequireDefault(require("mime/types/other"));
9
- var _standard = _interopRequireDefault(require("mime/types/standard"));
10
1
  // @ts-expect-error
11
-
2
+ import vendorTypes from "mime/types/other.js";
12
3
  // @ts-expect-error
4
+ import standardTypes from "mime/types/standard.js";
13
5
 
14
6
  /**
15
7
  * We need to get all extensions that are defined for a specific content type.
16
8
  * This operation is not available via the `mime` package, so we create such an object ourselves.
17
9
  */
18
- const mimeTypes = exports.mimeTypes = {
19
- ..._other.default,
20
- ..._standard.default
10
+ export const mimeTypes = {
11
+ ...vendorTypes,
12
+ ...standardTypes
21
13
  };
22
14
 
23
15
  //# sourceMappingURL=mimeTypes.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_other","_interopRequireDefault","require","_standard","mimeTypes","exports","vendorTypes","standardTypes"],"sources":["mimeTypes.ts"],"sourcesContent":["// @ts-expect-error\nimport vendorTypes from \"mime/types/other\";\n// @ts-expect-error\nimport standardTypes from \"mime/types/standard\";\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"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AAHA;;AAEA;;AAGA;AACA;AACA;AACA;AACO,MAAME,SAAmC,GAAAC,OAAA,CAAAD,SAAA,GAAG;EAC/C,GAAGE,cAAW;EACd,GAAGC;AACP,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["vendorTypes","standardTypes","mimeTypes"],"sources":["mimeTypes.ts"],"sourcesContent":["// @ts-expect-error\nimport vendorTypes from \"mime/types/other.js\";\n// @ts-expect-error\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"],"mappings":"AAAA;AACA,OAAOA,WAAW,MAAM,qBAAqB;AAC7C;AACA,OAAOC,aAAa,MAAM,wBAAwB;;AAElD;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAmC,GAAG;EAC/C,GAAGF,WAAW;EACd,GAAGC;AACP,CAAC","ignoreList":[]}
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- import { Response } from "node-fetch";
3
- import { PresignedPost } from "@webiny/aws-sdk/client-s3";
1
+ import type { PresignedPost } from "@webiny/aws-sdk/client-s3/index.js";
4
2
  declare const _default: (buffer: Buffer, preSignedPostPayload: PresignedPost) => Promise<Response>;
5
3
  export default _default;
@@ -1,26 +1,13 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _formData = _interopRequireDefault(require("form-data"));
9
- var _nodeFetch = _interopRequireDefault(require("node-fetch"));
10
- var _default = async (buffer, preSignedPostPayload) => {
11
- const formData = new _formData.default();
12
- // Add all pre signed payload field to "FormData".
13
- Object.keys(preSignedPostPayload.fields).forEach(key => {
14
- formData.append(key, preSignedPostPayload.fields[key]);
15
- });
16
- // Add file content to "FormData".
17
- formData.append("file", buffer);
18
- // Finally make the upload request to S3.
19
- return (0, _nodeFetch.default)(preSignedPostPayload.url, {
1
+ export default async (buffer, preSignedPostPayload) => {
2
+ const formData = new FormData();
3
+ for (const [key, value] of Object.entries(preSignedPostPayload.fields)) {
4
+ formData.append(key, value);
5
+ }
6
+ formData.append("file", new Blob([Buffer.from(buffer)]));
7
+ return fetch(preSignedPostPayload.url, {
20
8
  method: "POST",
21
9
  body: formData
22
10
  });
23
11
  };
24
- exports.default = _default;
25
12
 
26
13
  //# sourceMappingURL=uploadFileToS3.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_formData","_interopRequireDefault","require","_nodeFetch","_default","buffer","preSignedPostPayload","formData","FormData","Object","keys","fields","forEach","key","append","fetch","url","method","body","exports","default"],"sources":["uploadFileToS3.ts"],"sourcesContent":["import FormData from \"form-data\";\nimport fetch, { Response } from \"node-fetch\";\nimport { PresignedPost } from \"@webiny/aws-sdk/client-s3\";\n\nexport default async (buffer: Buffer, preSignedPostPayload: PresignedPost): Promise<Response> => {\n const formData = new FormData();\n // Add all pre signed payload field to \"FormData\".\n Object.keys(preSignedPostPayload.fields).forEach(key => {\n formData.append(key, preSignedPostPayload.fields[key]);\n });\n // Add file content to \"FormData\".\n formData.append(\"file\", buffer);\n // Finally make the upload request to S3.\n return fetch(preSignedPostPayload.url, {\n method: \"POST\",\n body: formData\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AAA6C,IAAAE,QAAA,GAG9B,MAAAA,CAAOC,MAAc,EAAEC,oBAAmC,KAAwB;EAC7F,MAAMC,QAAQ,GAAG,IAAIC,iBAAQ,CAAC,CAAC;EAC/B;EACAC,MAAM,CAACC,IAAI,CAACJ,oBAAoB,CAACK,MAAM,CAAC,CAACC,OAAO,CAACC,GAAG,IAAI;IACpDN,QAAQ,CAACO,MAAM,CAACD,GAAG,EAAEP,oBAAoB,CAACK,MAAM,CAACE,GAAG,CAAC,CAAC;EAC1D,CAAC,CAAC;EACF;EACAN,QAAQ,CAACO,MAAM,CAAC,MAAM,EAAET,MAAM,CAAC;EAC/B;EACA,OAAO,IAAAU,kBAAK,EAACT,oBAAoB,CAACU,GAAG,EAAE;IACnCC,MAAM,EAAE,MAAM;IACdC,IAAI,EAAEX;EACV,CAAC,CAAC;AACN,CAAC;AAAAY,OAAA,CAAAC,OAAA,GAAAhB,QAAA","ignoreList":[]}
1
+ {"version":3,"names":["buffer","preSignedPostPayload","formData","FormData","key","value","Object","entries","fields","append","Blob","Buffer","from","fetch","url","method","body"],"sources":["uploadFileToS3.ts"],"sourcesContent":["import type { PresignedPost } from \"@webiny/aws-sdk/client-s3/index.js\";\n\nexport default async (buffer: Buffer, preSignedPostPayload: PresignedPost): Promise<Response> => {\n const formData = new FormData();\n\n for (const [key, value] of Object.entries(preSignedPostPayload.fields)) {\n formData.append(key, value);\n }\n\n formData.append(\"file\", new Blob([Buffer.from(buffer)]));\n\n return fetch(preSignedPostPayload.url, {\n method: \"POST\",\n body: formData\n });\n};\n"],"mappings":"AAEA,eAAe,OAAOA,MAAc,EAAEC,oBAAmC,KAAwB;EAC7F,MAAMC,QAAQ,GAAG,IAAIC,QAAQ,CAAC,CAAC;EAE/B,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACN,oBAAoB,CAACO,MAAM,CAAC,EAAE;IACpEN,QAAQ,CAACO,MAAM,CAACL,GAAG,EAAEC,KAAK,CAAC;EAC/B;EAEAH,QAAQ,CAACO,MAAM,CAAC,MAAM,EAAE,IAAIC,IAAI,CAAC,CAACC,MAAM,CAACC,IAAI,CAACZ,MAAM,CAAC,CAAC,CAAC,CAAC;EAExD,OAAOa,KAAK,CAACZ,oBAAoB,CAACa,GAAG,EAAE;IACnCC,MAAM,EAAE,MAAM;IACdC,IAAI,EAAEd;EACV,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
@@ -1,12 +0,0 @@
1
- /**
2
- * !! EXPERIMENTAL !!
3
- *
4
- * This plugin is used to enable delivery of assets derived from the original asset uploaded via the FM.
5
- * These are usually files that go through background processing, video transcoding, image optimization, etc.
6
- * Since these derived files are not managed through the File Manager, the default delivery mechanism will not be able
7
- * to resolve them.
8
- *
9
- * With this plugin, we add a custom asset resolver, which tries to resolve the requested asset within the folder
10
- * it's located in, and if found, it will simply be delivered back to the client, without any transformations applied.
11
- */
12
- export declare const createCustomAssetDelivery: () => import("@webiny/plugins/types").PluginFactory;
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createCustomAssetDelivery = void 0;
7
- var _apiFileManager = require("@webiny/api-file-manager");
8
- /**
9
- * !! EXPERIMENTAL !!
10
- *
11
- * This plugin is used to enable delivery of assets derived from the original asset uploaded via the FM.
12
- * These are usually files that go through background processing, video transcoding, image optimization, etc.
13
- * Since these derived files are not managed through the File Manager, the default delivery mechanism will not be able
14
- * to resolve them.
15
- *
16
- * With this plugin, we add a custom asset resolver, which tries to resolve the requested asset within the folder
17
- * it's located in, and if found, it will simply be delivered back to the client, without any transformations applied.
18
- */
19
- const createCustomAssetDelivery = () => {
20
- return (0, _apiFileManager.createAssetDeliveryPluginLoader)(async () => {
21
- return import( /* webpackChunkName: "customAssetDelivery" */"./customAssets/customAssetDeliveryConfig").then(({
22
- customAssetDeliveryConfig
23
- }) => customAssetDeliveryConfig());
24
- });
25
- };
26
- exports.createCustomAssetDelivery = createCustomAssetDelivery;
27
-
28
- //# sourceMappingURL=createCustomAssetDelivery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_apiFileManager","require","createCustomAssetDelivery","createAssetDeliveryPluginLoader","then","customAssetDeliveryConfig","exports"],"sources":["createCustomAssetDelivery.ts"],"sourcesContent":["import { createAssetDeliveryPluginLoader } from \"@webiny/api-file-manager\";\n\n/**\n * !! EXPERIMENTAL !!\n *\n * This plugin is used to enable delivery of assets derived from the original asset uploaded via the FM.\n * These are usually files that go through background processing, video transcoding, image optimization, etc.\n * Since these derived files are not managed through the File Manager, the default delivery mechanism will not be able\n * to resolve them.\n *\n * With this plugin, we add a custom asset resolver, which tries to resolve the requested asset within the folder\n * it's located in, and if found, it will simply be delivered back to the client, without any transformations applied.\n */\nexport const createCustomAssetDelivery = () => {\n return createAssetDeliveryPluginLoader(async () => {\n return import(\n /* webpackChunkName: \"customAssetDelivery\" */ \"./customAssets/customAssetDeliveryConfig\"\n ).then(({ customAssetDeliveryConfig }) => customAssetDeliveryConfig());\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,OAAO,IAAAC,+CAA+B,EAAC,YAAY;IAC/C,OAAO,MAAM,EACT,uFACJ,CAAC,CAACC,IAAI,CAAC,CAAC;MAAEC;IAA0B,CAAC,KAAKA,yBAAyB,CAAC,CAAC,CAAC;EAC1E,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAJ,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -1,6 +0,0 @@
1
- import { Asset } from "@webiny/api-file-manager";
2
- /**
3
- * This class is used to differentiate between regular and custom assets.
4
- */
5
- export declare class CustomAsset extends Asset {
6
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CustomAsset = void 0;
7
- var _apiFileManager = require("@webiny/api-file-manager");
8
- /**
9
- * This class is used to differentiate between regular and custom assets.
10
- */
11
- class CustomAsset extends _apiFileManager.Asset {}
12
- exports.CustomAsset = CustomAsset;
13
-
14
- //# sourceMappingURL=CustomAsset.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_apiFileManager","require","CustomAsset","Asset","exports"],"sources":["CustomAsset.ts"],"sourcesContent":["import { Asset } from \"@webiny/api-file-manager\";\n\n/**\n * This class is used to differentiate between regular and custom assets.\n */\nexport class CustomAsset extends Asset {}\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACO,MAAMC,WAAW,SAASC,qBAAK,CAAC;AAAEC,OAAA,CAAAF,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -1,10 +0,0 @@
1
- import { Asset, AssetProcessor, AssetRequest } from "@webiny/api-file-manager";
2
- /**
3
- * We don't want to run any kind of transformations on custom assets.
4
- * Custom assets are usually pre-processed and ready to be delivered to the client.
5
- */
6
- export declare class CustomAssetProcessor implements AssetProcessor {
7
- private assetProcessor;
8
- constructor(assetProcessor: AssetProcessor);
9
- process(assetRequest: AssetRequest, asset: Asset): Promise<Asset>;
10
- }
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CustomAssetProcessor = void 0;
7
- var _CustomAsset = require("./CustomAsset");
8
- /**
9
- * We don't want to run any kind of transformations on custom assets.
10
- * Custom assets are usually pre-processed and ready to be delivered to the client.
11
- */
12
- class CustomAssetProcessor {
13
- constructor(assetProcessor) {
14
- this.assetProcessor = assetProcessor;
15
- }
16
- async process(assetRequest, asset) {
17
- if (asset instanceof _CustomAsset.CustomAsset) {
18
- return asset;
19
- }
20
- return this.assetProcessor.process(assetRequest, asset);
21
- }
22
- }
23
- exports.CustomAssetProcessor = CustomAssetProcessor;
24
-
25
- //# sourceMappingURL=CustomAssetProcessor.js.map