@webiny/api-file-manager-s3 0.0.0-unstable.eb196ccd2f → 0.0.0-unstable.eb81deee7e

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 (232) hide show
  1. package/FileManagerS3Feature.d.ts +9 -0
  2. package/FileManagerS3Feature.js +27 -0
  3. package/FileManagerS3Feature.js.map +1 -0
  4. package/README.md +11 -1
  5. package/assetDelivery/abstractions.d.ts +11 -0
  6. package/assetDelivery/abstractions.js +7 -0
  7. package/assetDelivery/abstractions.js.map +1 -0
  8. package/assetDelivery/assetDeliveryConfig.d.ts +2 -2
  9. package/assetDelivery/assetDeliveryConfig.js +10 -49
  10. package/assetDelivery/assetDeliveryConfig.js.map +1 -1
  11. package/assetDelivery/createAssetDelivery.d.ts +3 -3
  12. package/assetDelivery/createAssetDelivery.js +7 -28
  13. package/assetDelivery/createAssetDelivery.js.map +1 -1
  14. package/assetDelivery/feature.d.ts +5 -0
  15. package/assetDelivery/feature.js +36 -0
  16. package/assetDelivery/feature.js.map +1 -0
  17. package/assetDelivery/index.d.ts +8 -9
  18. package/assetDelivery/index.js +8 -70
  19. package/assetDelivery/s3/LazySharpTransform.d.ts +34 -0
  20. package/assetDelivery/s3/LazySharpTransform.js +34 -0
  21. package/assetDelivery/s3/LazySharpTransform.js.map +1 -0
  22. package/assetDelivery/s3/S3AssetResolver.d.ts +9 -4
  23. package/assetDelivery/s3/S3AssetResolver.js +34 -32
  24. package/assetDelivery/s3/S3AssetResolver.js.map +1 -1
  25. package/assetDelivery/s3/S3ContentsReader.d.ts +1 -3
  26. package/assetDelivery/s3/S3ContentsReader.js +12 -22
  27. package/assetDelivery/s3/S3ContentsReader.js.map +1 -1
  28. package/assetDelivery/s3/S3ErrorAssetReply.js +11 -17
  29. package/assetDelivery/s3/S3ErrorAssetReply.js.map +1 -1
  30. package/assetDelivery/s3/S3OutputStrategy.d.ts +6 -6
  31. package/assetDelivery/s3/S3OutputStrategy.js +35 -35
  32. package/assetDelivery/s3/S3OutputStrategy.js.map +1 -1
  33. package/assetDelivery/s3/S3RedirectAssetReply.js +14 -20
  34. package/assetDelivery/s3/S3RedirectAssetReply.js.map +1 -1
  35. package/assetDelivery/s3/S3StreamAssetReply.js +14 -20
  36. package/assetDelivery/s3/S3StreamAssetReply.js.map +1 -1
  37. package/assetDelivery/s3/SharpTransform.d.ts +22 -14
  38. package/assetDelivery/s3/SharpTransform.js +163 -182
  39. package/assetDelivery/s3/SharpTransform.js.map +1 -1
  40. package/assetDelivery/s3/transformation/AssetKeyGenerator.js +17 -25
  41. package/assetDelivery/s3/transformation/AssetKeyGenerator.js.map +1 -1
  42. package/assetDelivery/s3/transformation/CallableContentsReader.d.ts +0 -2
  43. package/assetDelivery/s3/transformation/CallableContentsReader.js +7 -13
  44. package/assetDelivery/s3/transformation/CallableContentsReader.js.map +1 -1
  45. package/assetDelivery/s3/transformation/WidthCollection.js +14 -22
  46. package/assetDelivery/s3/transformation/WidthCollection.js.map +1 -1
  47. package/assetDelivery/s3/transformation/utils.d.ts +1 -3
  48. package/assetDelivery/s3/transformation/utils.js +26 -28
  49. package/assetDelivery/s3/transformation/utils.js.map +1 -1
  50. package/assetDelivery/threatDetection/ObjectKey.d.ts +7 -0
  51. package/assetDelivery/threatDetection/ObjectKey.js +18 -0
  52. package/assetDelivery/threatDetection/ObjectKey.js.map +1 -0
  53. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.d.ts +22 -2
  54. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js +49 -58
  55. package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js.map +1 -1
  56. package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.d.ts +1 -1
  57. package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js +3 -11
  58. package/assetDelivery/threatDetection/createThreatDetectionPluginLoader.js.map +1 -1
  59. package/assetDelivery/threatDetection/index.d.ts +2 -2
  60. package/assetDelivery/threatDetection/index.js +2 -29
  61. package/assetDelivery/threatDetection/processThreatScanResult.d.ts +3 -2
  62. package/assetDelivery/threatDetection/processThreatScanResult.js +56 -61
  63. package/assetDelivery/threatDetection/processThreatScanResult.js.map +1 -1
  64. package/assetDelivery/threatDetection/types.d.ts +0 -4
  65. package/assetDelivery/threatDetection/types.js +0 -7
  66. package/assetDelivery/types.d.ts +4 -2
  67. package/assetDelivery/types.js +0 -7
  68. package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.d.ts +13 -0
  69. package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js +28 -0
  70. package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js.map +1 -0
  71. package/enterprise/ApplyThreatScanning/feature.d.ts +4 -0
  72. package/enterprise/ApplyThreatScanning/feature.js +11 -0
  73. package/enterprise/ApplyThreatScanning/feature.js.map +1 -0
  74. package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.d.ts +15 -0
  75. package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js +35 -0
  76. package/features/DeleteFileFromBucket/DeleteFileFromBucketHandler.js.map +1 -0
  77. package/features/DeleteFileFromBucket/DeleteS3FolderTask.d.ts +37 -0
  78. package/features/DeleteFileFromBucket/DeleteS3FolderTask.js +57 -0
  79. package/features/DeleteFileFromBucket/DeleteS3FolderTask.js.map +1 -0
  80. package/features/DeleteFileFromBucket/feature.d.ts +4 -0
  81. package/features/DeleteFileFromBucket/feature.js +13 -0
  82. package/features/DeleteFileFromBucket/feature.js.map +1 -0
  83. package/features/ExtractMetadata/ExtractMetadataHandler.d.ts +11 -0
  84. package/features/ExtractMetadata/ExtractMetadataHandler.js +25 -0
  85. package/features/ExtractMetadata/ExtractMetadataHandler.js.map +1 -0
  86. package/features/ExtractMetadata/ExtractMetadataTask.d.ts +29 -0
  87. package/features/ExtractMetadata/ExtractMetadataTask.js +99 -0
  88. package/features/ExtractMetadata/ExtractMetadataTask.js.map +1 -0
  89. package/features/ExtractMetadata/feature.d.ts +4 -0
  90. package/features/ExtractMetadata/feature.js +13 -0
  91. package/features/ExtractMetadata/feature.js.map +1 -0
  92. package/features/FlushCache/FlushCacheOnFileDeleteHandler.d.ts +12 -0
  93. package/features/FlushCache/FlushCacheOnFileDeleteHandler.js +28 -0
  94. package/features/FlushCache/FlushCacheOnFileDeleteHandler.js.map +1 -0
  95. package/features/FlushCache/FlushCacheOnFileUpdateHandler.d.ts +12 -0
  96. package/features/FlushCache/FlushCacheOnFileUpdateHandler.js +31 -0
  97. package/features/FlushCache/FlushCacheOnFileUpdateHandler.js.map +1 -0
  98. package/features/FlushCache/InvalidateCacheTask.d.ts +31 -0
  99. package/features/FlushCache/InvalidateCacheTask.js +84 -0
  100. package/features/FlushCache/InvalidateCacheTask.js.map +1 -0
  101. package/features/FlushCache/feature.d.ts +4 -0
  102. package/features/FlushCache/feature.js +15 -0
  103. package/features/FlushCache/feature.js.map +1 -0
  104. package/features/GetFileContentsById/GetFileContentsByIdUseCase.d.ts +13 -0
  105. package/features/GetFileContentsById/GetFileContentsByIdUseCase.js +40 -0
  106. package/features/GetFileContentsById/GetFileContentsByIdUseCase.js.map +1 -0
  107. package/features/GetFileContentsById/feature.d.ts +4 -0
  108. package/features/GetFileContentsById/feature.js +11 -0
  109. package/features/GetFileContentsById/feature.js.map +1 -0
  110. package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.d.ts +13 -0
  111. package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js +40 -0
  112. package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js.map +1 -0
  113. package/features/GetFileContentsByKey/feature.d.ts +4 -0
  114. package/features/GetFileContentsByKey/feature.js +11 -0
  115. package/features/GetFileContentsByKey/feature.js.map +1 -0
  116. package/features/WriteFileMetadata/MetadataReader.d.ts +14 -0
  117. package/features/WriteFileMetadata/MetadataReader.js +13 -0
  118. package/features/WriteFileMetadata/MetadataReader.js.map +1 -0
  119. package/features/WriteFileMetadata/MetadataWriter.d.ts +10 -0
  120. package/features/WriteFileMetadata/MetadataWriter.js +28 -0
  121. package/features/WriteFileMetadata/MetadataWriter.js.map +1 -0
  122. package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.d.ts +12 -0
  123. package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js +23 -0
  124. package/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js.map +1 -0
  125. package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.d.ts +12 -0
  126. package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js +25 -0
  127. package/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js.map +1 -0
  128. package/features/WriteFileMetadata/feature.d.ts +4 -0
  129. package/features/WriteFileMetadata/feature.js +13 -0
  130. package/features/WriteFileMetadata/feature.js.map +1 -0
  131. package/graphql/S3GraphQLSchema.d.ts +10 -0
  132. package/graphql/S3GraphQLSchema.js +233 -0
  133. package/graphql/S3GraphQLSchema.js.map +1 -0
  134. package/graphql/checkPermissions.d.ts +5 -0
  135. package/graphql/checkPermissions.js +22 -0
  136. package/graphql/checkPermissions.js.map +1 -0
  137. package/index.d.ts +4 -5
  138. package/index.js +3 -36
  139. package/multiPartUpload/CompleteMultiPartUploadUseCase.d.ts +1 -1
  140. package/multiPartUpload/CompleteMultiPartUploadUseCase.js +49 -59
  141. package/multiPartUpload/CompleteMultiPartUploadUseCase.js.map +1 -1
  142. package/multiPartUpload/CreateMultiPartUploadUseCase.d.ts +2 -2
  143. package/multiPartUpload/CreateMultiPartUploadUseCase.js +30 -44
  144. package/multiPartUpload/CreateMultiPartUploadUseCase.js.map +1 -1
  145. package/package.json +36 -34
  146. package/types.d.ts +2 -1
  147. package/types.js +1 -7
  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 +1 -1
  152. package/utils/FileExtension.js +11 -19
  153. package/utils/FileExtension.js.map +1 -1
  154. package/utils/FileKey.d.ts +1 -1
  155. package/utils/FileKey.js +29 -29
  156. package/utils/FileKey.js.map +1 -1
  157. package/utils/FileKey.test.js +50 -51
  158. package/utils/FileKey.test.js.map +1 -1
  159. package/utils/FileNormalizer.d.ts +2 -2
  160. package/utils/FileNormalizer.js +35 -43
  161. package/utils/FileNormalizer.js.map +1 -1
  162. package/utils/FileUploadModifier.d.ts +9 -3
  163. package/utils/FileUploadModifier.js +36 -44
  164. package/utils/FileUploadModifier.js.map +1 -1
  165. package/utils/createFileNormalizerFromContext.d.ts +2 -2
  166. package/utils/createFileNormalizerFromContext.js +6 -12
  167. package/utils/createFileNormalizerFromContext.js.map +1 -1
  168. package/utils/getPresignedPostPayload.d.ts +4 -3
  169. package/utils/getPresignedPostPayload.js +38 -40
  170. package/utils/getPresignedPostPayload.js.map +1 -1
  171. package/utils/mimeTypes.js +6 -20
  172. package/utils/mimeTypes.js.map +1 -1
  173. package/utils/uploadFileToS3.d.ts +2 -5
  174. package/utils/uploadFileToS3.js +11 -23
  175. package/utils/uploadFileToS3.js.map +1 -1
  176. package/assetDelivery/createCustomAssetDelivery.d.ts +0 -12
  177. package/assetDelivery/createCustomAssetDelivery.js +0 -28
  178. package/assetDelivery/createCustomAssetDelivery.js.map +0 -1
  179. package/assetDelivery/customAssets/CustomAsset.d.ts +0 -6
  180. package/assetDelivery/customAssets/CustomAsset.js +0 -14
  181. package/assetDelivery/customAssets/CustomAsset.js.map +0 -1
  182. package/assetDelivery/customAssets/CustomAssetProcessor.d.ts +0 -10
  183. package/assetDelivery/customAssets/CustomAssetProcessor.js +0 -25
  184. package/assetDelivery/customAssets/CustomAssetProcessor.js.map +0 -1
  185. package/assetDelivery/customAssets/S3CustomAssetResolver.d.ts +0 -15
  186. package/assetDelivery/customAssets/S3CustomAssetResolver.js +0 -90
  187. package/assetDelivery/customAssets/S3CustomAssetResolver.js.map +0 -1
  188. package/assetDelivery/customAssets/customAssetDeliveryConfig.d.ts +0 -1
  189. package/assetDelivery/customAssets/customAssetDeliveryConfig.js +0 -30
  190. package/assetDelivery/customAssets/customAssetDeliveryConfig.js.map +0 -1
  191. package/assetDelivery/index.js.map +0 -1
  192. package/assetDelivery/s3/S3AssetMetadataReader.d.ts +0 -15
  193. package/assetDelivery/s3/S3AssetMetadataReader.js +0 -36
  194. package/assetDelivery/s3/S3AssetMetadataReader.js.map +0 -1
  195. package/assetDelivery/s3/transformation/legacyUtils.d.ts +0 -12
  196. package/assetDelivery/s3/transformation/legacyUtils.js +0 -34
  197. package/assetDelivery/s3/transformation/legacyUtils.js.map +0 -1
  198. package/assetDelivery/threatDetection/index.js.map +0 -1
  199. package/assetDelivery/threatDetection/types.js.map +0 -1
  200. package/assetDelivery/types.js.map +0 -1
  201. package/flushCdnCache/CdnPathsGenerator.d.ts +0 -4
  202. package/flushCdnCache/CdnPathsGenerator.js +0 -14
  203. package/flushCdnCache/CdnPathsGenerator.js.map +0 -1
  204. package/flushCdnCache/InvalidateCacheTask.d.ts +0 -18
  205. package/flushCdnCache/InvalidateCacheTask.js +0 -78
  206. package/flushCdnCache/InvalidateCacheTask.js.map +0 -1
  207. package/flushCdnCache/flushCacheOnFileDelete.d.ts +0 -3
  208. package/flushCdnCache/flushCacheOnFileDelete.js +0 -34
  209. package/flushCdnCache/flushCacheOnFileDelete.js.map +0 -1
  210. package/flushCdnCache/flushCacheOnFileUpdate.d.ts +0 -3
  211. package/flushCdnCache/flushCacheOnFileUpdate.js +0 -40
  212. package/flushCdnCache/flushCacheOnFileUpdate.js.map +0 -1
  213. package/flushCdnCache/index.d.ts +0 -1
  214. package/flushCdnCache/index.js +0 -15
  215. package/flushCdnCache/index.js.map +0 -1
  216. package/flushCdnCache/invalidateCacheTaskDefinition.d.ts +0 -2
  217. package/flushCdnCache/invalidateCacheTaskDefinition.js +0 -22
  218. package/flushCdnCache/invalidateCacheTaskDefinition.js.map +0 -1
  219. package/index.js.map +0 -1
  220. package/plugins/addFileMetadata.d.ts +0 -10
  221. package/plugins/addFileMetadata.js +0 -67
  222. package/plugins/addFileMetadata.js.map +0 -1
  223. package/plugins/checkPermissions.d.ts +0 -4
  224. package/plugins/checkPermissions.js +0 -44
  225. package/plugins/checkPermissions.js.map +0 -1
  226. package/plugins/fileStorageS3.d.ts +0 -3
  227. package/plugins/fileStorageS3.js +0 -60
  228. package/plugins/fileStorageS3.js.map +0 -1
  229. package/plugins/graphqlFileStorageS3.d.ts +0 -4
  230. package/plugins/graphqlFileStorageS3.js +0 -213
  231. package/plugins/graphqlFileStorageS3.js.map +0 -1
  232. package/types.js.map +0 -1
@@ -0,0 +1,84 @@
1
+ import { ServiceDiscovery } from "@webiny/api-core/features/serviceDiscovery/index.js";
2
+ import { CloudFront } from "@webiny/aws-sdk/client-cloudfront/index.js";
3
+ import { TaskDefinition, TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
4
+ import { executeWithRetry } from "@webiny/utils";
5
+ class ReturnContinue extends Error {
6
+ }
7
+ class InvalidateCloudfrontCacheTaskHandlerImpl {
8
+ async run({ input, controller }) {
9
+ if (controller.runtime.isAborted()) return controller.response.aborted();
10
+ const manifest = await ServiceDiscovery.load();
11
+ if (!manifest) return controller.response.error({
12
+ message: "Unable to invalidate cache due to a missing service manifest.",
13
+ code: "MISSING_SERVICE_MANIFEST",
14
+ data: {
15
+ manifest: "api"
16
+ }
17
+ });
18
+ const { distributionId } = manifest.api.cloudfront;
19
+ const invalidateCache = ()=>this.invalidateCache(input.caller, distributionId, input.paths);
20
+ try {
21
+ await executeWithRetry(invalidateCache, {
22
+ minTimeout: 2000,
23
+ retries: 10000,
24
+ onFailedAttempt: ({ error })=>{
25
+ if (this.continueIfCode.includes(error.name)) throw new ReturnContinue();
26
+ if (error.message.includes("not authorized to perform")) throw error;
27
+ if (controller.runtime.isCloseToTimeout()) throw new ReturnContinue();
28
+ }
29
+ });
30
+ } catch (error) {
31
+ if (error instanceof ReturnContinue) return controller.response.continue(input);
32
+ return controller.response.error({
33
+ message: error.message,
34
+ code: "EXECUTE_WITH_RETRY_FAILED",
35
+ data: input.paths
36
+ });
37
+ }
38
+ return controller.response.done();
39
+ }
40
+ async invalidateCache(caller, distributionId, paths) {
41
+ const cloudfront = new CloudFront();
42
+ await cloudfront.createInvalidation({
43
+ DistributionId: distributionId,
44
+ InvalidationBatch: {
45
+ CallerReference: `${new Date().getTime()}-${caller}`,
46
+ Paths: {
47
+ Quantity: paths.length,
48
+ Items: paths
49
+ }
50
+ }
51
+ });
52
+ }
53
+ constructor(){
54
+ this.continueIfCode = [
55
+ "TooManyInvalidationsInProgress",
56
+ "Throttling"
57
+ ];
58
+ }
59
+ }
60
+ const InvalidateCloudfrontCacheTaskHandler = TaskHandler.createImplementation({
61
+ implementation: InvalidateCloudfrontCacheTaskHandlerImpl,
62
+ dependencies: []
63
+ });
64
+ class InvalidateCloudfrontCacheTask {
65
+ constructor(){
66
+ this.id = "invalidateAssetCache";
67
+ this.title = "Invalidate CloudFront Cache";
68
+ this.description = "A task to invalidate Cloudfront cache by given paths.";
69
+ this.maxIterations = 100;
70
+ this.isPrivate = true;
71
+ this.selfCleanup = [
72
+ "onSuccess",
73
+ "onAbort"
74
+ ];
75
+ this.handler = InvalidateCloudfrontCacheTaskHandler;
76
+ }
77
+ }
78
+ const InvalidateCloudfrontCacheTaskDefinition = TaskDefinition.createImplementation({
79
+ implementation: InvalidateCloudfrontCacheTask,
80
+ dependencies: []
81
+ });
82
+ export { InvalidateCloudfrontCacheTaskDefinition };
83
+
84
+ //# sourceMappingURL=InvalidateCacheTask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/FlushCache/InvalidateCacheTask.js","sources":["../../../src/features/FlushCache/InvalidateCacheTask.ts"],"sourcesContent":["import { ServiceDiscovery } from \"@webiny/api-core/features/serviceDiscovery/index.js\";\nimport { CloudFront } from \"@webiny/aws-sdk/client-cloudfront/index.js\";\nimport {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { executeWithRetry } from \"@webiny/utils\";\n\nclass ReturnContinue extends Error {}\n\nexport interface InvalidateCacheInput {\n /**\n * Caller of the task (e.g., `fm-before-update`, `fm-after-delete`).\n */\n caller: string;\n /**\n * Cache paths to invalidate.\n */\n paths: string[];\n}\n\nclass InvalidateCloudfrontCacheTaskHandlerImpl implements TaskHandler.Interface<InvalidateCacheInput> {\n private continueIfCode = [\"TooManyInvalidationsInProgress\", \"Throttling\"];\n\n public async run({ input, controller }: TaskHandler.RunParams<InvalidateCacheInput>) {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n const manifest = await ServiceDiscovery.load();\n\n if (!manifest) {\n return controller.response.error({\n message: `Unable to invalidate cache due to a missing service manifest.`,\n code: \"MISSING_SERVICE_MANIFEST\",\n data: {\n manifest: \"api\"\n }\n });\n }\n\n const { distributionId } = manifest.api.cloudfront;\n\n const invalidateCache = () => {\n return this.invalidateCache(input.caller, distributionId as string, input.paths);\n };\n\n try {\n await executeWithRetry(invalidateCache, {\n minTimeout: 2000,\n // instead of forever: true\n retries: 10000,\n onFailedAttempt: ({ error }) => {\n if (this.continueIfCode.includes(error.name)) {\n throw new ReturnContinue();\n }\n\n if (error.message.includes(\"not authorized to perform\")) {\n throw error;\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n throw new ReturnContinue();\n }\n }\n });\n } catch (error) {\n if (error instanceof ReturnContinue) {\n return controller.response.continue(input);\n }\n\n return controller.response.error({\n message: error.message,\n code: \"EXECUTE_WITH_RETRY_FAILED\",\n data: input.paths\n });\n }\n\n return controller.response.done();\n }\n\n private async invalidateCache(\n caller: string,\n distributionId: string,\n paths: string[]\n ): Promise<void> {\n const cloudfront = new CloudFront();\n await cloudfront.createInvalidation({\n DistributionId: distributionId,\n InvalidationBatch: {\n CallerReference: `${new Date().getTime()}-${caller}`,\n Paths: {\n Quantity: paths.length,\n Items: paths\n }\n }\n });\n }\n}\n\nconst InvalidateCloudfrontCacheTaskHandler = TaskHandler.createImplementation({\n implementation: InvalidateCloudfrontCacheTaskHandlerImpl,\n dependencies: []\n});\n\nclass InvalidateCloudfrontCacheTask implements TaskDefinition.Interface {\n id = \"invalidateAssetCache\";\n title = \"Invalidate CloudFront Cache\";\n description = \"A task to invalidate Cloudfront cache by given paths.\";\n maxIterations = 100;\n isPrivate = true;\n selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = InvalidateCloudfrontCacheTaskHandler;\n}\n\nexport const InvalidateCloudfrontCacheTaskDefinition = TaskDefinition.createImplementation({\n implementation: InvalidateCloudfrontCacheTask,\n dependencies: []\n});\n"],"names":["ReturnContinue","Error","InvalidateCloudfrontCacheTaskHandlerImpl","input","controller","manifest","ServiceDiscovery","distributionId","invalidateCache","executeWithRetry","error","caller","paths","cloudfront","CloudFront","Date","InvalidateCloudfrontCacheTaskHandler","TaskHandler","InvalidateCloudfrontCacheTask","InvalidateCloudfrontCacheTaskDefinition","TaskDefinition"],"mappings":";;;;AAQA,MAAMA,uBAAuBC;AAAO;AAapC,MAAMC;IAGF,MAAa,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAA+C,EAAE;QACjF,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;QAGtC,MAAMC,WAAW,MAAMC,iBAAiB,IAAI;QAE5C,IAAI,CAACD,UACD,OAAOD,WAAW,QAAQ,CAAC,KAAK,CAAC;YAC7B,SAAS;YACT,MAAM;YACN,MAAM;gBACF,UAAU;YACd;QACJ;QAGJ,MAAM,EAAEG,cAAc,EAAE,GAAGF,SAAS,GAAG,CAAC,UAAU;QAElD,MAAMG,kBAAkB,IACb,IAAI,CAAC,eAAe,CAACL,MAAM,MAAM,EAAEI,gBAA0BJ,MAAM,KAAK;QAGnF,IAAI;YACA,MAAMM,iBAAiBD,iBAAiB;gBACpC,YAAY;gBAEZ,SAAS;gBACT,iBAAiB,CAAC,EAAEE,KAAK,EAAE;oBACvB,IAAI,IAAI,CAAC,cAAc,CAAC,QAAQ,CAACA,MAAM,IAAI,GACvC,MAAM,IAAIV;oBAGd,IAAIU,MAAM,OAAO,CAAC,QAAQ,CAAC,8BACvB,MAAMA;oBAGV,IAAIN,WAAW,OAAO,CAAC,gBAAgB,IACnC,MAAM,IAAIJ;gBAElB;YACJ;QACJ,EAAE,OAAOU,OAAO;YACZ,IAAIA,iBAAiBV,gBACjB,OAAOI,WAAW,QAAQ,CAAC,QAAQ,CAACD;YAGxC,OAAOC,WAAW,QAAQ,CAAC,KAAK,CAAC;gBAC7B,SAASM,MAAM,OAAO;gBACtB,MAAM;gBACN,MAAMP,MAAM,KAAK;YACrB;QACJ;QAEA,OAAOC,WAAW,QAAQ,CAAC,IAAI;IACnC;IAEA,MAAc,gBACVO,MAAc,EACdJ,cAAsB,EACtBK,KAAe,EACF;QACb,MAAMC,aAAa,IAAIC;QACvB,MAAMD,WAAW,kBAAkB,CAAC;YAChC,gBAAgBN;YAChB,mBAAmB;gBACf,iBAAiB,GAAG,IAAIQ,OAAO,OAAO,GAAG,CAAC,EAAEJ,QAAQ;gBACpD,OAAO;oBACH,UAAUC,MAAM,MAAM;oBACtB,OAAOA;gBACX;YACJ;QACJ;IACJ;;aA3EQ,cAAc,GAAG;YAAC;YAAkC;SAAa;;AA4E7E;AAEA,MAAMI,uCAAuCC,YAAY,oBAAoB,CAAC;IAC1E,gBAAgBf;IAChB,cAAc,EAAE;AACpB;AAEA,MAAMgB;;aACF,EAAE,GAAG;aACL,KAAK,GAAG;aACR,WAAW,GAAG;aACd,aAAa,GAAG;aAChB,SAAS,GAAG;aACZ,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAExD,OAAO,GAAGF;;AACd;AAEO,MAAMG,0CAA0CC,eAAe,oBAAoB,CAAC;IACvF,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,4 @@
1
+ export declare const FlushCacheFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,15 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { FlushCacheOnFileDeleteHandler } from "./FlushCacheOnFileDeleteHandler.js";
3
+ import { FlushCacheOnFileUpdateHandler } from "./FlushCacheOnFileUpdateHandler.js";
4
+ import { InvalidateCloudfrontCacheTaskDefinition } from "./InvalidateCacheTask.js";
5
+ const FlushCacheFeature = createFeature({
6
+ name: "FileManagerS3/FlushCache",
7
+ register (container) {
8
+ container.register(FlushCacheOnFileDeleteHandler);
9
+ container.register(FlushCacheOnFileUpdateHandler);
10
+ container.register(InvalidateCloudfrontCacheTaskDefinition);
11
+ }
12
+ });
13
+ export { FlushCacheFeature };
14
+
15
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/FlushCache/feature.js","sources":["../../../src/features/FlushCache/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { FlushCacheOnFileDeleteHandler } from \"./FlushCacheOnFileDeleteHandler.js\";\nimport { FlushCacheOnFileUpdateHandler } from \"./FlushCacheOnFileUpdateHandler.js\";\nimport { InvalidateCloudfrontCacheTaskDefinition } from \"./InvalidateCacheTask.js\";\n\nexport const FlushCacheFeature = createFeature({\n name: \"FileManagerS3/FlushCache\",\n register(container) {\n container.register(FlushCacheOnFileDeleteHandler);\n container.register(FlushCacheOnFileUpdateHandler);\n container.register(InvalidateCloudfrontCacheTaskDefinition);\n }\n});\n"],"names":["FlushCacheFeature","createFeature","container","FlushCacheOnFileDeleteHandler","FlushCacheOnFileUpdateHandler","InvalidateCloudfrontCacheTaskDefinition"],"mappings":";;;;AAKO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;IACvB;AACJ"}
@@ -0,0 +1,13 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
3
+ import { GetFileContentsByIdUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
4
+ import type { FileContents } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
5
+ declare class GetFileContentsByIdUseCaseImpl implements GetFileContentsByIdUseCase.Interface {
6
+ private metadataReader;
7
+ constructor(keyValueStore: GlobalKeyValueStore.Interface);
8
+ execute(fileId: string): Promise<Result<FileContents, GetFileContentsByIdUseCase.Error>>;
9
+ }
10
+ export declare const GetFileContentsByIdUseCaseImplementation: typeof GetFileContentsByIdUseCaseImpl & {
11
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-file-manager/features/file/GetFileContentsById/abstractions").IGetFileContentsByIdUseCase>;
12
+ };
13
+ export {};
@@ -0,0 +1,40 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { S3 } from "@webiny/aws-sdk/client-s3/index.js";
3
+ import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
4
+ import { GetFileContentsByIdUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
5
+ import { FileNotFoundError, FilePersistenceError } from "@webiny/api-file-manager/domain/file/errors.js";
6
+ import { MetadataReader } from "../WriteFileMetadata/MetadataReader.js";
7
+ class GetFileContentsByIdUseCaseImpl {
8
+ constructor(keyValueStore){
9
+ this.metadataReader = new MetadataReader(keyValueStore);
10
+ }
11
+ async execute(fileId) {
12
+ const metadata = await this.metadataReader.read(fileId);
13
+ if (!metadata) return Result.fail(new FileNotFoundError(fileId));
14
+ try {
15
+ const s3 = new S3();
16
+ const bucket = String(process.env.S3_BUCKET);
17
+ const response = await s3.getObject({
18
+ Bucket: bucket,
19
+ Key: metadata.bucketKey
20
+ });
21
+ if (!response.Body) return Result.fail(new FileNotFoundError(fileId));
22
+ const buffer = Buffer.from(await response.Body.transformToByteArray());
23
+ return Result.ok({
24
+ buffer,
25
+ contentType: metadata.contentType
26
+ });
27
+ } catch (error) {
28
+ return Result.fail(new FilePersistenceError(error instanceof Error ? error : new Error(String(error))));
29
+ }
30
+ }
31
+ }
32
+ const GetFileContentsByIdUseCaseImplementation = GetFileContentsByIdUseCase.createImplementation({
33
+ implementation: GetFileContentsByIdUseCaseImpl,
34
+ dependencies: [
35
+ GlobalKeyValueStore
36
+ ]
37
+ });
38
+ export { GetFileContentsByIdUseCaseImplementation };
39
+
40
+ //# sourceMappingURL=GetFileContentsByIdUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/GetFileContentsById/GetFileContentsByIdUseCase.js","sources":["../../../src/features/GetFileContentsById/GetFileContentsByIdUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { GetFileContentsByIdUseCase } from \"@webiny/api-file-manager/features/file/GetFileContentsById/index.js\";\nimport type { FileContents } from \"@webiny/api-file-manager/features/file/GetFileContentsById/index.js\";\nimport {\n FileNotFoundError,\n FilePersistenceError\n} from \"@webiny/api-file-manager/domain/file/errors.js\";\nimport { MetadataReader } from \"~/features/WriteFileMetadata/MetadataReader.js\";\n\nclass GetFileContentsByIdUseCaseImpl implements GetFileContentsByIdUseCase.Interface {\n private metadataReader: MetadataReader;\n\n constructor(keyValueStore: GlobalKeyValueStore.Interface) {\n this.metadataReader = new MetadataReader(keyValueStore);\n }\n\n async execute(fileId: string): Promise<Result<FileContents, GetFileContentsByIdUseCase.Error>> {\n const metadata = await this.metadataReader.read(fileId);\n if (!metadata) {\n return Result.fail(new FileNotFoundError(fileId));\n }\n\n try {\n const s3 = new S3();\n const bucket = String(process.env.S3_BUCKET);\n const response = await s3.getObject({ Bucket: bucket, Key: metadata.bucketKey });\n\n if (!response.Body) {\n return Result.fail(new FileNotFoundError(fileId));\n }\n\n const buffer = Buffer.from(await response.Body.transformToByteArray());\n return Result.ok({ buffer, contentType: metadata.contentType });\n } catch (error) {\n return Result.fail(\n new FilePersistenceError(error instanceof Error ? error : new Error(String(error)))\n );\n }\n }\n}\n\nexport const GetFileContentsByIdUseCaseImplementation =\n GetFileContentsByIdUseCase.createImplementation({\n implementation: GetFileContentsByIdUseCaseImpl,\n dependencies: [GlobalKeyValueStore]\n });\n"],"names":["GetFileContentsByIdUseCaseImpl","keyValueStore","MetadataReader","fileId","metadata","Result","FileNotFoundError","s3","S3","bucket","String","process","response","buffer","Buffer","error","FilePersistenceError","Error","GetFileContentsByIdUseCaseImplementation","GetFileContentsByIdUseCase","GlobalKeyValueStore"],"mappings":";;;;;;AAWA,MAAMA;IAGF,YAAYC,aAA4C,CAAE;QACtD,IAAI,CAAC,cAAc,GAAG,IAAIC,eAAeD;IAC7C;IAEA,MAAM,QAAQE,MAAc,EAAmE;QAC3F,MAAMC,WAAW,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAACD;QAChD,IAAI,CAACC,UACD,OAAOC,OAAO,IAAI,CAAC,IAAIC,kBAAkBH;QAG7C,IAAI;YACA,MAAMI,KAAK,IAAIC;YACf,MAAMC,SAASC,OAAOC,QAAQ,GAAG,CAAC,SAAS;YAC3C,MAAMC,WAAW,MAAML,GAAG,SAAS,CAAC;gBAAE,QAAQE;gBAAQ,KAAKL,SAAS,SAAS;YAAC;YAE9E,IAAI,CAACQ,SAAS,IAAI,EACd,OAAOP,OAAO,IAAI,CAAC,IAAIC,kBAAkBH;YAG7C,MAAMU,SAASC,OAAO,IAAI,CAAC,MAAMF,SAAS,IAAI,CAAC,oBAAoB;YACnE,OAAOP,OAAO,EAAE,CAAC;gBAAEQ;gBAAQ,aAAaT,SAAS,WAAW;YAAC;QACjE,EAAE,OAAOW,OAAO;YACZ,OAAOV,OAAO,IAAI,CACd,IAAIW,qBAAqBD,iBAAiBE,QAAQF,QAAQ,IAAIE,MAAMP,OAAOK;QAEnF;IACJ;AACJ;AAEO,MAAMG,2CACTC,2BAA2B,oBAAoB,CAAC;IAC5C,gBAAgBnB;IAChB,cAAc;QAACoB;KAAoB;AACvC"}
@@ -0,0 +1,4 @@
1
+ export declare const GetFileContentsByIdFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { GetFileContentsByIdUseCaseImplementation } from "./GetFileContentsByIdUseCase.js";
3
+ const GetFileContentsByIdFeature = createFeature({
4
+ name: "FileManagerS3/GetFileContentsById",
5
+ register (container) {
6
+ container.register(GetFileContentsByIdUseCaseImplementation);
7
+ }
8
+ });
9
+ export { GetFileContentsByIdFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/GetFileContentsById/feature.js","sources":["../../../src/features/GetFileContentsById/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetFileContentsByIdUseCaseImplementation } from \"./GetFileContentsByIdUseCase.js\";\n\nexport const GetFileContentsByIdFeature = createFeature({\n name: \"FileManagerS3/GetFileContentsById\",\n register(container) {\n container.register(GetFileContentsByIdUseCaseImplementation);\n }\n});\n"],"names":["GetFileContentsByIdFeature","createFeature","container","GetFileContentsByIdUseCaseImplementation"],"mappings":";;AAGO,MAAMA,6BAA6BC,cAAc;IACpD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1,13 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
3
+ import { GetFileContentsByKeyUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsByKey/index.js";
4
+ import type { FileContents } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
5
+ declare class GetFileContentsByKeyUseCaseImpl implements GetFileContentsByKeyUseCase.Interface {
6
+ private tenantContext;
7
+ constructor(tenantContext: TenantContext.Interface);
8
+ execute(key: string): Promise<Result<FileContents, GetFileContentsByKeyUseCase.Error>>;
9
+ }
10
+ export declare const GetFileContentsByKeyUseCaseImplementation: typeof GetFileContentsByKeyUseCaseImpl & {
11
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-file-manager/features/file/GetFileContentsByKey/abstractions").IGetFileContentsByKeyUseCase>;
12
+ };
13
+ export {};
@@ -0,0 +1,40 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { S3 } from "@webiny/aws-sdk/client-s3/index.js";
3
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
4
+ import { GetFileContentsByKeyUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsByKey/index.js";
5
+ import { FileNotFoundError, FilePersistenceError } from "@webiny/api-file-manager/domain/file/errors.js";
6
+ class GetFileContentsByKeyUseCaseImpl {
7
+ constructor(tenantContext){
8
+ this.tenantContext = tenantContext;
9
+ }
10
+ async execute(key) {
11
+ const tenant = this.tenantContext.getTenant();
12
+ const bucketKey = `tenants/${tenant.id}/files/${key}`;
13
+ try {
14
+ const s3 = new S3();
15
+ const bucket = String(process.env.S3_BUCKET);
16
+ const response = await s3.getObject({
17
+ Bucket: bucket,
18
+ Key: bucketKey
19
+ });
20
+ if (!response.Body) return Result.fail(new FileNotFoundError(key));
21
+ const buffer = Buffer.from(await response.Body.transformToByteArray());
22
+ const contentType = response.ContentType || "application/octet-stream";
23
+ return Result.ok({
24
+ buffer,
25
+ contentType
26
+ });
27
+ } catch (error) {
28
+ return Result.fail(new FilePersistenceError(error instanceof Error ? error : new Error(String(error))));
29
+ }
30
+ }
31
+ }
32
+ const GetFileContentsByKeyUseCaseImplementation = GetFileContentsByKeyUseCase.createImplementation({
33
+ implementation: GetFileContentsByKeyUseCaseImpl,
34
+ dependencies: [
35
+ TenantContext
36
+ ]
37
+ });
38
+ export { GetFileContentsByKeyUseCaseImplementation };
39
+
40
+ //# sourceMappingURL=GetFileContentsByKeyUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js","sources":["../../../src/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetFileContentsByKeyUseCase } from \"@webiny/api-file-manager/features/file/GetFileContentsByKey/index.js\";\nimport type { FileContents } from \"@webiny/api-file-manager/features/file/GetFileContentsById/index.js\";\nimport {\n FileNotFoundError,\n FilePersistenceError\n} from \"@webiny/api-file-manager/domain/file/errors.js\";\n\nclass GetFileContentsByKeyUseCaseImpl implements GetFileContentsByKeyUseCase.Interface {\n constructor(private tenantContext: TenantContext.Interface) {}\n\n async execute(key: string): Promise<Result<FileContents, GetFileContentsByKeyUseCase.Error>> {\n const tenant = this.tenantContext.getTenant();\n const bucketKey = `tenants/${tenant.id}/files/${key}`;\n\n try {\n const s3 = new S3();\n const bucket = String(process.env.S3_BUCKET);\n const response = await s3.getObject({ Bucket: bucket, Key: bucketKey });\n\n if (!response.Body) {\n return Result.fail(new FileNotFoundError(key));\n }\n\n const buffer = Buffer.from(await response.Body.transformToByteArray());\n const contentType = response.ContentType || \"application/octet-stream\";\n return Result.ok({ buffer, contentType });\n } catch (error) {\n return Result.fail(\n new FilePersistenceError(error instanceof Error ? error : new Error(String(error)))\n );\n }\n }\n}\n\nexport const GetFileContentsByKeyUseCaseImplementation =\n GetFileContentsByKeyUseCase.createImplementation({\n implementation: GetFileContentsByKeyUseCaseImpl,\n dependencies: [TenantContext]\n });\n"],"names":["GetFileContentsByKeyUseCaseImpl","tenantContext","key","tenant","bucketKey","s3","S3","bucket","String","process","response","Result","FileNotFoundError","buffer","Buffer","contentType","error","FilePersistenceError","Error","GetFileContentsByKeyUseCaseImplementation","GetFileContentsByKeyUseCase","TenantContext"],"mappings":";;;;;AAUA,MAAMA;IACF,YAAoBC,aAAsC,CAAE;aAAxCA,aAAa,GAAbA;IAAyC;IAE7D,MAAM,QAAQC,GAAW,EAAoE;QACzF,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,MAAMC,YAAY,CAAC,QAAQ,EAAED,OAAO,EAAE,CAAC,OAAO,EAAED,KAAK;QAErD,IAAI;YACA,MAAMG,KAAK,IAAIC;YACf,MAAMC,SAASC,OAAOC,QAAQ,GAAG,CAAC,SAAS;YAC3C,MAAMC,WAAW,MAAML,GAAG,SAAS,CAAC;gBAAE,QAAQE;gBAAQ,KAAKH;YAAU;YAErE,IAAI,CAACM,SAAS,IAAI,EACd,OAAOC,OAAO,IAAI,CAAC,IAAIC,kBAAkBV;YAG7C,MAAMW,SAASC,OAAO,IAAI,CAAC,MAAMJ,SAAS,IAAI,CAAC,oBAAoB;YACnE,MAAMK,cAAcL,SAAS,WAAW,IAAI;YAC5C,OAAOC,OAAO,EAAE,CAAC;gBAAEE;gBAAQE;YAAY;QAC3C,EAAE,OAAOC,OAAO;YACZ,OAAOL,OAAO,IAAI,CACd,IAAIM,qBAAqBD,iBAAiBE,QAAQF,QAAQ,IAAIE,MAAMV,OAAOQ;QAEnF;IACJ;AACJ;AAEO,MAAMG,4CACTC,4BAA4B,oBAAoB,CAAC;IAC7C,gBAAgBpB;IAChB,cAAc;QAACqB;KAAc;AACjC"}
@@ -0,0 +1,4 @@
1
+ export declare const GetFileContentsByKeyFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { GetFileContentsByKeyUseCaseImplementation } from "./GetFileContentsByKeyUseCase.js";
3
+ const GetFileContentsByKeyFeature = createFeature({
4
+ name: "FileManagerS3/GetFileContentsByKey",
5
+ register (container) {
6
+ container.register(GetFileContentsByKeyUseCaseImplementation);
7
+ }
8
+ });
9
+ export { GetFileContentsByKeyFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/GetFileContentsByKey/feature.js","sources":["../../../src/features/GetFileContentsByKey/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetFileContentsByKeyUseCaseImplementation } from \"./GetFileContentsByKeyUseCase.js\";\n\nexport const GetFileContentsByKeyFeature = createFeature({\n name: \"FileManagerS3/GetFileContentsByKey\",\n register(container) {\n container.register(GetFileContentsByKeyUseCaseImplementation);\n }\n});\n"],"names":["GetFileContentsByKeyFeature","createFeature","container","GetFileContentsByKeyUseCaseImplementation"],"mappings":";;AAGO,MAAMA,8BAA8BC,cAAc;IACrD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1,14 @@
1
+ import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
2
+ interface AssetMetadata {
3
+ id: string;
4
+ tenant: string;
5
+ size: number;
6
+ contentType: string;
7
+ bucketKey: string;
8
+ }
9
+ export declare class MetadataReader {
10
+ private keyValueStore;
11
+ constructor(keyValueStore: GlobalKeyValueStore.Interface);
12
+ read(fileId: string): Promise<AssetMetadata | undefined>;
13
+ }
14
+ export {};
@@ -0,0 +1,13 @@
1
+ class MetadataReader {
2
+ constructor(keyValueStore){
3
+ this.keyValueStore = keyValueStore;
4
+ }
5
+ async read(fileId) {
6
+ const result = await this.keyValueStore.get(`FileManager/File/${fileId}/Metadata`);
7
+ if (result.isFail()) return;
8
+ return result.value;
9
+ }
10
+ }
11
+ export { MetadataReader };
12
+
13
+ //# sourceMappingURL=MetadataReader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/WriteFileMetadata/MetadataReader.js","sources":["../../../src/features/WriteFileMetadata/MetadataReader.ts"],"sourcesContent":["import { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\n\ninterface AssetMetadata {\n id: string;\n tenant: string;\n size: number;\n contentType: string;\n bucketKey: string;\n}\n\nexport class MetadataReader {\n constructor(private keyValueStore: GlobalKeyValueStore.Interface) {}\n\n async read(fileId: string): Promise<AssetMetadata | undefined> {\n const result = await this.keyValueStore.get<AssetMetadata>(\n `FileManager/File/${fileId}/Metadata`\n );\n\n if (result.isFail()) {\n return undefined;\n }\n\n return result.value;\n }\n}\n"],"names":["MetadataReader","keyValueStore","fileId","result"],"mappings":"AAUO,MAAMA;IACT,YAAoBC,aAA4C,CAAE;aAA9CA,aAAa,GAAbA;IAA+C;IAEnE,MAAM,KAAKC,MAAc,EAAsC;QAC3D,MAAMC,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CACvC,CAAC,iBAAiB,EAAED,OAAO,SAAS,CAAC;QAGzC,IAAIC,OAAO,MAAM,IACb;QAGJ,OAAOA,OAAO,KAAK;IACvB;AACJ"}
@@ -0,0 +1,10 @@
1
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
2
+ import type { File } from "@webiny/api-file-manager/domain/file/types.js";
3
+ import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
4
+ export declare class MetadataWriter {
5
+ private tenantContext;
6
+ private keyValueStore;
7
+ constructor(tenantContext: TenantContext.Interface, keyValueStore: GlobalKeyValueStore.Interface);
8
+ write(files: File[]): Promise<void>;
9
+ private getMetadata;
10
+ }
@@ -0,0 +1,28 @@
1
+ class MetadataWriter {
2
+ constructor(tenantContext, keyValueStore){
3
+ this.tenantContext = tenantContext;
4
+ this.keyValueStore = keyValueStore;
5
+ }
6
+ async write(files) {
7
+ const writers = files.map(async (file)=>{
8
+ const metadata = this.getMetadata(file);
9
+ const key = `FileManager/File/${file.id}/Metadata`;
10
+ const result = await this.keyValueStore.set(key, metadata);
11
+ if (result.isFail()) console.error(`[FileManagerS3] Failed to write delivery metadata "${key}":`, result.error);
12
+ });
13
+ await Promise.all(writers);
14
+ }
15
+ getMetadata(file) {
16
+ const tenant = this.tenantContext.getTenant();
17
+ return {
18
+ id: file.id,
19
+ bucketKey: `tenants/${tenant.id}/files/${file.key}`,
20
+ tenant: tenant.id,
21
+ size: file.size,
22
+ contentType: file.type
23
+ };
24
+ }
25
+ }
26
+ export { MetadataWriter };
27
+
28
+ //# sourceMappingURL=MetadataWriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/WriteFileMetadata/MetadataWriter.js","sources":["../../../src/features/WriteFileMetadata/MetadataWriter.ts"],"sourcesContent":["import { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport type { File } from \"@webiny/api-file-manager/domain/file/types.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\n\nexport class MetadataWriter {\n constructor(\n private tenantContext: TenantContext.Interface,\n private keyValueStore: GlobalKeyValueStore.Interface\n ) {}\n\n async write(files: File[]) {\n /**\n * We need to write each file with retry.\n */\n const writers = files.map(async file => {\n const metadata = this.getMetadata(file);\n const key = `FileManager/File/${file.id}/Metadata`;\n // Check the result: the KV store returns a failed Result (it does not throw), so an\n // ignored failure here would silently break asset delivery (missing metadata → 404).\n const result = await this.keyValueStore.set(key, metadata);\n if (result.isFail()) {\n console.error(\n `[FileManagerS3] Failed to write delivery metadata \"${key}\":`,\n result.error\n );\n }\n });\n\n await Promise.all(writers);\n }\n\n private getMetadata(file: File) {\n const tenant = this.tenantContext.getTenant();\n return {\n id: file.id,\n bucketKey: `tenants/${tenant.id}/files/${file.key}`,\n tenant: tenant.id,\n size: file.size,\n contentType: file.type\n };\n }\n}\n"],"names":["MetadataWriter","tenantContext","keyValueStore","files","writers","file","metadata","key","result","console","Promise","tenant"],"mappings":"AAIO,MAAMA;IACT,YACYC,aAAsC,EACtCC,aAA4C,CACtD;aAFUD,aAAa,GAAbA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,MAAMC,KAAa,EAAE;QAIvB,MAAMC,UAAUD,MAAM,GAAG,CAAC,OAAME;YAC5B,MAAMC,WAAW,IAAI,CAAC,WAAW,CAACD;YAClC,MAAME,MAAM,CAAC,iBAAiB,EAAEF,KAAK,EAAE,CAAC,SAAS,CAAC;YAGlD,MAAMG,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAACD,KAAKD;YACjD,IAAIE,OAAO,MAAM,IACbC,QAAQ,KAAK,CACT,CAAC,mDAAmD,EAAEF,IAAI,EAAE,CAAC,EAC7DC,OAAO,KAAK;QAGxB;QAEA,MAAME,QAAQ,GAAG,CAACN;IACtB;IAEQ,YAAYC,IAAU,EAAE;QAC5B,MAAMM,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO;YACH,IAAIN,KAAK,EAAE;YACX,WAAW,CAAC,QAAQ,EAAEM,OAAO,EAAE,CAAC,OAAO,EAAEN,KAAK,GAAG,EAAE;YACnD,QAAQM,OAAO,EAAE;YACjB,MAAMN,KAAK,IAAI;YACf,aAAaA,KAAK,IAAI;QAC1B;IACJ;AACJ"}
@@ -0,0 +1,12 @@
1
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
2
+ import { FileAfterBatchCreateEventHandler } from "@webiny/api-file-manager/features/file/CreateFilesInBatch/events.js";
3
+ import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
4
+ declare class WriteMetadataAfterBatchCreateHandlerImpl implements FileAfterBatchCreateEventHandler.Interface {
5
+ private readonly metadataWriter;
6
+ constructor(tenantContext: TenantContext.Interface, keyValueStore: GlobalKeyValueStore.Interface);
7
+ handle(event: FileAfterBatchCreateEventHandler.Event): Promise<void>;
8
+ }
9
+ export declare const WriteMetadataAfterBatchCreateHandler: typeof WriteMetadataAfterBatchCreateHandlerImpl & {
10
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/api-file-manager/features/file/CreateFilesInBatch/events.js").FileAfterBatchCreateEvent>>;
11
+ };
12
+ export {};
@@ -0,0 +1,23 @@
1
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
2
+ import { FileAfterBatchCreateEventHandler } from "@webiny/api-file-manager/features/file/CreateFilesInBatch/events.js";
3
+ import { MetadataWriter } from "./MetadataWriter.js";
4
+ import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
5
+ class WriteMetadataAfterBatchCreateHandlerImpl {
6
+ constructor(tenantContext, keyValueStore){
7
+ this.metadataWriter = new MetadataWriter(tenantContext, keyValueStore);
8
+ }
9
+ async handle(event) {
10
+ const { files } = event.payload;
11
+ await this.metadataWriter.write(files);
12
+ }
13
+ }
14
+ const WriteMetadataAfterBatchCreateHandler = FileAfterBatchCreateEventHandler.createImplementation({
15
+ implementation: WriteMetadataAfterBatchCreateHandlerImpl,
16
+ dependencies: [
17
+ TenantContext,
18
+ GlobalKeyValueStore
19
+ ]
20
+ });
21
+ export { WriteMetadataAfterBatchCreateHandler };
22
+
23
+ //# sourceMappingURL=WriteMetadataAfterBatchCreateHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js","sources":["../../../src/features/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.ts"],"sourcesContent":["import { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { FileAfterBatchCreateEventHandler } from \"@webiny/api-file-manager/features/file/CreateFilesInBatch/events.js\";\nimport { MetadataWriter } from \"./MetadataWriter.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\n\nclass WriteMetadataAfterBatchCreateHandlerImpl\n implements FileAfterBatchCreateEventHandler.Interface\n{\n private readonly metadataWriter: MetadataWriter;\n\n constructor(\n tenantContext: TenantContext.Interface,\n keyValueStore: GlobalKeyValueStore.Interface\n ) {\n this.metadataWriter = new MetadataWriter(tenantContext, keyValueStore);\n }\n\n async handle(event: FileAfterBatchCreateEventHandler.Event): Promise<void> {\n const { files } = event.payload;\n await this.metadataWriter.write(files);\n }\n}\n\nexport const WriteMetadataAfterBatchCreateHandler =\n FileAfterBatchCreateEventHandler.createImplementation({\n implementation: WriteMetadataAfterBatchCreateHandlerImpl,\n dependencies: [TenantContext, GlobalKeyValueStore]\n });\n"],"names":["WriteMetadataAfterBatchCreateHandlerImpl","tenantContext","keyValueStore","MetadataWriter","event","files","WriteMetadataAfterBatchCreateHandler","FileAfterBatchCreateEventHandler","TenantContext","GlobalKeyValueStore"],"mappings":";;;;AAKA,MAAMA;IAKF,YACIC,aAAsC,EACtCC,aAA4C,CAC9C;QACE,IAAI,CAAC,cAAc,GAAG,IAAIC,eAAeF,eAAeC;IAC5D;IAEA,MAAM,OAAOE,KAA6C,EAAiB;QACvE,MAAM,EAAEC,KAAK,EAAE,GAAGD,MAAM,OAAO;QAC/B,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,CAACC;IACpC;AACJ;AAEO,MAAMC,uCACTC,iCAAiC,oBAAoB,CAAC;IAClD,gBAAgBP;IAChB,cAAc;QAACQ;QAAeC;KAAoB;AACtD"}
@@ -0,0 +1,12 @@
1
+ import { FileAfterCreateEventHandler } from "@webiny/api-file-manager/features/file/CreateFile/events.js";
2
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
3
+ import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
4
+ declare class WriteMetadataAfterCreateHandlerImpl implements FileAfterCreateEventHandler.Interface {
5
+ private readonly metadataWriter;
6
+ constructor(tenantContext: TenantContext.Interface, keyValueStore: GlobalKeyValueStore.Interface);
7
+ handle(event: FileAfterCreateEventHandler.Event): Promise<void>;
8
+ }
9
+ export declare const WriteMetadataAfterCreateHandler: typeof WriteMetadataAfterCreateHandlerImpl & {
10
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/api-file-manager/features/file/CreateFile/events.js").FileAfterCreateEvent>>;
11
+ };
12
+ export {};
@@ -0,0 +1,25 @@
1
+ import { FileAfterCreateEventHandler } from "@webiny/api-file-manager/features/file/CreateFile/events.js";
2
+ import { MetadataWriter } from "./MetadataWriter.js";
3
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
4
+ import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
5
+ class WriteMetadataAfterCreateHandlerImpl {
6
+ constructor(tenantContext, keyValueStore){
7
+ this.metadataWriter = new MetadataWriter(tenantContext, keyValueStore);
8
+ }
9
+ async handle(event) {
10
+ const { file } = event.payload;
11
+ await this.metadataWriter.write([
12
+ file
13
+ ]);
14
+ }
15
+ }
16
+ const WriteMetadataAfterCreateHandler = FileAfterCreateEventHandler.createImplementation({
17
+ implementation: WriteMetadataAfterCreateHandlerImpl,
18
+ dependencies: [
19
+ TenantContext,
20
+ GlobalKeyValueStore
21
+ ]
22
+ });
23
+ export { WriteMetadataAfterCreateHandler };
24
+
25
+ //# sourceMappingURL=WriteMetadataAfterCreateHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/WriteFileMetadata/WriteMetadataAfterCreateHandler.js","sources":["../../../src/features/WriteFileMetadata/WriteMetadataAfterCreateHandler.ts"],"sourcesContent":["import { FileAfterCreateEventHandler } from \"@webiny/api-file-manager/features/file/CreateFile/events.js\";\nimport { MetadataWriter } from \"./MetadataWriter.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\n\nclass WriteMetadataAfterCreateHandlerImpl implements FileAfterCreateEventHandler.Interface {\n private readonly metadataWriter: MetadataWriter;\n\n constructor(\n tenantContext: TenantContext.Interface,\n keyValueStore: GlobalKeyValueStore.Interface\n ) {\n this.metadataWriter = new MetadataWriter(tenantContext, keyValueStore);\n }\n\n async handle(event: FileAfterCreateEventHandler.Event): Promise<void> {\n const { file } = event.payload;\n await this.metadataWriter.write([file]);\n }\n}\n\nexport const WriteMetadataAfterCreateHandler = FileAfterCreateEventHandler.createImplementation({\n implementation: WriteMetadataAfterCreateHandlerImpl,\n dependencies: [TenantContext, GlobalKeyValueStore]\n});\n"],"names":["WriteMetadataAfterCreateHandlerImpl","tenantContext","keyValueStore","MetadataWriter","event","file","WriteMetadataAfterCreateHandler","FileAfterCreateEventHandler","TenantContext","GlobalKeyValueStore"],"mappings":";;;;AAKA,MAAMA;IAGF,YACIC,aAAsC,EACtCC,aAA4C,CAC9C;QACE,IAAI,CAAC,cAAc,GAAG,IAAIC,eAAeF,eAAeC;IAC5D;IAEA,MAAM,OAAOE,KAAwC,EAAiB;QAClE,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAM,OAAO;QAC9B,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC;YAACC;SAAK;IAC1C;AACJ;AAEO,MAAMC,kCAAkCC,4BAA4B,oBAAoB,CAAC;IAC5F,gBAAgBP;IAChB,cAAc;QAACQ;QAAeC;KAAoB;AACtD"}
@@ -0,0 +1,4 @@
1
+ export declare const WriteFileMetadataFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,13 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { WriteMetadataAfterCreateHandler } from "./WriteMetadataAfterCreateHandler.js";
3
+ import { WriteMetadataAfterBatchCreateHandler } from "./WriteMetadataAfterBatchCreateHandler.js";
4
+ const WriteFileMetadataFeature = createFeature({
5
+ name: "FileManagerS3/WriteFileMetadata",
6
+ register (container) {
7
+ container.register(WriteMetadataAfterCreateHandler);
8
+ container.register(WriteMetadataAfterBatchCreateHandler);
9
+ }
10
+ });
11
+ export { WriteFileMetadataFeature };
12
+
13
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/WriteFileMetadata/feature.js","sources":["../../../src/features/WriteFileMetadata/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { WriteMetadataAfterCreateHandler } from \"./WriteMetadataAfterCreateHandler.js\";\nimport { WriteMetadataAfterBatchCreateHandler } from \"./WriteMetadataAfterBatchCreateHandler.js\";\n\nexport const WriteFileMetadataFeature = createFeature({\n name: \"FileManagerS3/WriteFileMetadata\",\n register(container) {\n container.register(WriteMetadataAfterCreateHandler);\n container.register(WriteMetadataAfterBatchCreateHandler);\n }\n});\n"],"names":["WriteFileMetadataFeature","createFeature","container","WriteMetadataAfterCreateHandler","WriteMetadataAfterBatchCreateHandler"],"mappings":";;;AAIO,MAAMA,2BAA2BC,cAAc;IAClD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;IACvB;AACJ"}
@@ -0,0 +1,10 @@
1
+ import { CoreGraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
2
+ import { GraphQLSchemaBuilder } from "@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js";
3
+ declare class S3GraphQLSchemaImpl implements CoreGraphQLSchemaFactory.Interface {
4
+ getSchemaKey: () => string;
5
+ execute(builder: GraphQLSchemaBuilder.Interface): CoreGraphQLSchemaFactory.Return;
6
+ }
7
+ export declare const S3GraphQLSchema: typeof S3GraphQLSchemaImpl & {
8
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-graphql/graphql/abstractions.core.js").ICoreGraphQLSchemaFactory>;
9
+ };
10
+ export {};