@webiny/api-file-manager 0.0.0-unstable.fcdad0bc61 → 0.0.0-unstable.fdd9228b5d

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 (291) hide show
  1. package/FileManagerContextSetup.d.ts +13 -0
  2. package/FileManagerContextSetup.js +115 -0
  3. package/FileManagerContextSetup.js.map +1 -0
  4. package/README.md +1 -1
  5. package/cmsFileStorage/CmsFilesStorage.d.ts +27 -0
  6. package/cmsFileStorage/CmsFilesStorage.js +164 -0
  7. package/cmsFileStorage/CmsFilesStorage.js.map +1 -0
  8. package/cmsFileStorage/ListFilesWhereProcessor.d.ts +7 -0
  9. package/cmsFileStorage/ListFilesWhereProcessor.js +33 -0
  10. package/cmsFileStorage/ListFilesWhereProcessor.js.map +1 -0
  11. package/cmsFileStorage/ListTagsWhereProcessor.d.ts +7 -0
  12. package/cmsFileStorage/ListTagsWhereProcessor.js +33 -0
  13. package/cmsFileStorage/ListTagsWhereProcessor.js.map +1 -0
  14. package/cmsFileStorage/file.model.d.ts +6 -0
  15. package/cmsFileStorage/file.model.js +158 -0
  16. package/cmsFileStorage/file.model.js.map +1 -0
  17. package/contants.d.ts +1 -0
  18. package/contants.js +9 -0
  19. package/contants.js.map +1 -0
  20. package/createFileManager/files.crud.d.ts +3 -0
  21. package/createFileManager/files.crud.js +328 -0
  22. package/createFileManager/files.crud.js.map +1 -0
  23. package/createFileManager/index.d.ts +3 -0
  24. package/createFileManager/index.js +23 -0
  25. package/createFileManager/index.js.map +1 -0
  26. package/createFileManager/permissions/FilesPermissions.d.ts +4 -0
  27. package/createFileManager/permissions/FilesPermissions.js +11 -0
  28. package/createFileManager/permissions/FilesPermissions.js.map +1 -0
  29. package/createFileManager/permissions/SettingsPermissions.d.ts +4 -0
  30. package/createFileManager/permissions/SettingsPermissions.js +11 -0
  31. package/createFileManager/permissions/SettingsPermissions.js.map +1 -0
  32. package/createFileManager/settings.crud.d.ts +3 -0
  33. package/createFileManager/settings.crud.js +117 -0
  34. package/createFileManager/settings.crud.js.map +1 -0
  35. package/createFileManager/system.crud.d.ts +3 -0
  36. package/createFileManager/system.crud.js +88 -0
  37. package/createFileManager/system.crud.js.map +1 -0
  38. package/createFileManager/types.d.ts +16 -0
  39. package/createFileManager/types.js +7 -0
  40. package/createFileManager/types.js.map +1 -0
  41. package/delivery/AssetDelivery/AliasAssetRequestResolver.d.ts +11 -0
  42. package/delivery/AssetDelivery/AliasAssetRequestResolver.js +74 -0
  43. package/delivery/AssetDelivery/AliasAssetRequestResolver.js.map +1 -0
  44. package/delivery/AssetDelivery/Asset.d.ts +32 -0
  45. package/delivery/AssetDelivery/Asset.js +69 -0
  46. package/delivery/AssetDelivery/Asset.js.map +1 -0
  47. package/delivery/AssetDelivery/AssetDeliveryConfig.d.ts +63 -0
  48. package/delivery/AssetDelivery/AssetDeliveryConfig.js +102 -0
  49. package/delivery/AssetDelivery/AssetDeliveryConfig.js.map +1 -0
  50. package/delivery/AssetDelivery/AssetRequest.d.ts +25 -0
  51. package/delivery/AssetDelivery/AssetRequest.js +29 -0
  52. package/delivery/AssetDelivery/AssetRequest.js.map +1 -0
  53. package/delivery/AssetDelivery/FilesAssetRequestResolver.d.ts +6 -0
  54. package/delivery/AssetDelivery/FilesAssetRequestResolver.js +37 -0
  55. package/delivery/AssetDelivery/FilesAssetRequestResolver.js.map +1 -0
  56. package/delivery/AssetDelivery/NullAssetOutputStrategy.d.ts +4 -0
  57. package/delivery/AssetDelivery/NullAssetOutputStrategy.js +15 -0
  58. package/delivery/AssetDelivery/NullAssetOutputStrategy.js.map +1 -0
  59. package/delivery/AssetDelivery/NullAssetReply.d.ts +4 -0
  60. package/delivery/AssetDelivery/NullAssetReply.js +20 -0
  61. package/delivery/AssetDelivery/NullAssetReply.js.map +1 -0
  62. package/delivery/AssetDelivery/NullAssetResolver.d.ts +5 -0
  63. package/delivery/AssetDelivery/NullAssetResolver.js +14 -0
  64. package/delivery/AssetDelivery/NullAssetResolver.js.map +1 -0
  65. package/delivery/AssetDelivery/NullRequestResolver.d.ts +4 -0
  66. package/delivery/AssetDelivery/NullRequestResolver.js +14 -0
  67. package/delivery/AssetDelivery/NullRequestResolver.js.map +1 -0
  68. package/delivery/AssetDelivery/SetCacheControlHeaders.d.ts +8 -0
  69. package/delivery/AssetDelivery/SetCacheControlHeaders.js +25 -0
  70. package/delivery/AssetDelivery/SetCacheControlHeaders.js.map +1 -0
  71. package/delivery/AssetDelivery/SetResponseHeaders.d.ts +18 -0
  72. package/delivery/AssetDelivery/SetResponseHeaders.js +25 -0
  73. package/delivery/AssetDelivery/SetResponseHeaders.js.map +1 -0
  74. package/delivery/AssetDelivery/abstractions/AssetContentsReader.d.ts +6 -0
  75. package/delivery/AssetDelivery/abstractions/AssetContentsReader.js +7 -0
  76. package/delivery/AssetDelivery/abstractions/AssetContentsReader.js.map +1 -0
  77. package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.d.ts +4 -0
  78. package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.js +7 -0
  79. package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.js.map +1 -0
  80. package/delivery/AssetDelivery/abstractions/AssetProcessor.d.ts +4 -0
  81. package/delivery/AssetDelivery/abstractions/AssetProcessor.js +7 -0
  82. package/delivery/AssetDelivery/abstractions/AssetProcessor.js.map +1 -0
  83. package/delivery/AssetDelivery/abstractions/AssetReply.d.ts +25 -0
  84. package/delivery/AssetDelivery/abstractions/AssetReply.js +38 -0
  85. package/delivery/AssetDelivery/abstractions/AssetReply.js.map +1 -0
  86. package/delivery/AssetDelivery/abstractions/AssetRequestResolver.d.ts +5 -0
  87. package/delivery/AssetDelivery/abstractions/AssetRequestResolver.js +7 -0
  88. package/delivery/AssetDelivery/abstractions/AssetRequestResolver.js.map +1 -0
  89. package/delivery/AssetDelivery/abstractions/AssetResolver.d.ts +4 -0
  90. package/delivery/AssetDelivery/abstractions/AssetResolver.js +7 -0
  91. package/delivery/AssetDelivery/abstractions/AssetResolver.js.map +1 -0
  92. package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.d.ts +4 -0
  93. package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.js +7 -0
  94. package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.js.map +1 -0
  95. package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.d.ts +2 -0
  96. package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.js +15 -0
  97. package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.js.map +1 -0
  98. package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.d.ts +4 -0
  99. package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.js +7 -0
  100. package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.js.map +1 -0
  101. package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.d.ts +4 -0
  102. package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js +26 -0
  103. package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js.map +1 -0
  104. package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.d.ts +4 -0
  105. package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js +15 -0
  106. package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js.map +1 -0
  107. package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.d.ts +7 -0
  108. package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js +28 -0
  109. package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js.map +1 -0
  110. package/delivery/AssetDelivery/privateFiles/PrivateCache.d.ts +6 -0
  111. package/delivery/AssetDelivery/privateFiles/PrivateCache.js +28 -0
  112. package/delivery/AssetDelivery/privateFiles/PrivateCache.js.map +1 -0
  113. package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.d.ts +8 -0
  114. package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js +37 -0
  115. package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js.map +1 -0
  116. package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.d.ts +13 -0
  117. package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js +63 -0
  118. package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js.map +1 -0
  119. package/delivery/AssetDelivery/privateFiles/PublicCache.d.ts +6 -0
  120. package/delivery/AssetDelivery/privateFiles/PublicCache.js +28 -0
  121. package/delivery/AssetDelivery/privateFiles/PublicCache.js.map +1 -0
  122. package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.d.ts +7 -0
  123. package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js +27 -0
  124. package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js.map +1 -0
  125. package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.d.ts +7 -0
  126. package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js +27 -0
  127. package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js.map +1 -0
  128. package/delivery/AssetDelivery/privateFiles/internalIdentity.d.ts +7 -0
  129. package/delivery/AssetDelivery/privateFiles/internalIdentity.js +18 -0
  130. package/delivery/AssetDelivery/privateFiles/internalIdentity.js.map +1 -0
  131. package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.d.ts +4 -0
  132. package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js +14 -0
  133. package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js.map +1 -0
  134. package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.d.ts +4 -0
  135. package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js +14 -0
  136. package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js.map +1 -0
  137. package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.d.ts +6 -0
  138. package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js +26 -0
  139. package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js.map +1 -0
  140. package/delivery/index.d.ts +17 -0
  141. package/delivery/index.js +194 -0
  142. package/delivery/index.js.map +1 -0
  143. package/delivery/setupAssetDelivery.d.ts +6 -0
  144. package/delivery/setupAssetDelivery.js +128 -0
  145. package/delivery/setupAssetDelivery.js.map +1 -0
  146. package/enterprise/applyThreatScanning.d.ts +2 -0
  147. package/enterprise/applyThreatScanning.js +20 -0
  148. package/enterprise/applyThreatScanning.js.map +1 -0
  149. package/graphql/baseSchema.d.ts +3 -0
  150. package/graphql/baseSchema.js +121 -0
  151. package/graphql/baseSchema.js.map +1 -0
  152. package/graphql/createFilesTypeDefs.d.ts +7 -0
  153. package/graphql/createFilesTypeDefs.js +184 -0
  154. package/graphql/createFilesTypeDefs.js.map +1 -0
  155. package/graphql/filesSchema.d.ts +4 -0
  156. package/graphql/filesSchema.js +89 -0
  157. package/graphql/filesSchema.js.map +1 -0
  158. package/graphql/getFileByUrl.d.ts +3 -0
  159. package/graphql/getFileByUrl.js +78 -0
  160. package/graphql/getFileByUrl.js.map +1 -0
  161. package/graphql/index.d.ts +4 -0
  162. package/graphql/index.js +55 -0
  163. package/graphql/index.js.map +1 -0
  164. package/graphql/utils.d.ts +11 -0
  165. package/graphql/utils.js +24 -0
  166. package/graphql/utils.js.map +1 -0
  167. package/handlers/{transform/managers → manage}/imageManager.d.ts +2 -3
  168. package/handlers/manage/imageManager.js +75 -0
  169. package/handlers/manage/imageManager.js.map +1 -0
  170. package/handlers/manage/index.d.ts +1 -1
  171. package/handlers/manage/index.js +7 -19
  172. package/handlers/manage/index.js.map +1 -1
  173. package/handlers/{transform/utils.js → manage/legacyUtils.js} +6 -18
  174. package/handlers/manage/legacyUtils.js.map +1 -0
  175. package/handlers/manage/utils.d.ts +12 -0
  176. package/handlers/manage/utils.js +34 -0
  177. package/handlers/manage/utils.js.map +1 -0
  178. package/handlers/types.d.ts +1 -1
  179. package/handlers/types.js +3 -1
  180. package/handlers/types.js.map +1 -1
  181. package/handlers/utils/getEnvironment.js +2 -2
  182. package/handlers/utils/getEnvironment.js.map +1 -1
  183. package/handlers/utils/getObjectParams.js +2 -4
  184. package/handlers/utils/getObjectParams.js.map +1 -1
  185. package/handlers/utils/index.js +2 -3
  186. package/handlers/utils/index.js.map +1 -1
  187. package/index.d.ts +10 -0
  188. package/index.js +76 -0
  189. package/index.js.map +1 -0
  190. package/modelModifier/CmsModelModifier.d.ts +26 -0
  191. package/modelModifier/CmsModelModifier.js +62 -0
  192. package/modelModifier/CmsModelModifier.js.map +1 -0
  193. package/package.json +26 -37
  194. package/plugins/{definitions/FilePhysicalStoragePlugin.d.ts → FilePhysicalStoragePlugin.d.ts} +2 -1
  195. package/plugins/{definitions/FilePhysicalStoragePlugin.js → FilePhysicalStoragePlugin.js} +3 -14
  196. package/plugins/FilePhysicalStoragePlugin.js.map +1 -0
  197. package/plugins/{definitions/FileStorageTransformPlugin.d.ts → FileStorageTransformPlugin.d.ts} +1 -1
  198. package/plugins/{definitions/FileStorageTransformPlugin.js → FileStorageTransformPlugin.js} +4 -16
  199. package/plugins/FileStorageTransformPlugin.js.map +1 -0
  200. package/plugins/index.d.ts +2 -2
  201. package/plugins/index.js +23 -18
  202. package/plugins/index.js.map +1 -1
  203. package/{plugins/storage → storage}/FileStorage.d.ts +10 -6
  204. package/storage/FileStorage.js +90 -0
  205. package/storage/FileStorage.js.map +1 -0
  206. package/types/file.d.ts +49 -0
  207. package/types/file.js +7 -0
  208. package/types/file.js.map +1 -0
  209. package/types/file.lifecycle.d.ts +44 -0
  210. package/types/file.lifecycle.js +7 -0
  211. package/types/file.lifecycle.js.map +1 -0
  212. package/types.d.ts +92 -81
  213. package/types.js +25 -1
  214. package/types.js.map +1 -1
  215. package/handlers/download/index.d.ts +0 -3
  216. package/handlers/download/index.js +0 -132
  217. package/handlers/download/index.js.map +0 -1
  218. package/handlers/transform/index.d.ts +0 -2
  219. package/handlers/transform/index.js +0 -91
  220. package/handlers/transform/index.js.map +0 -1
  221. package/handlers/transform/loaders/imageLoader.d.ts +0 -30
  222. package/handlers/transform/loaders/imageLoader.js +0 -105
  223. package/handlers/transform/loaders/imageLoader.js.map +0 -1
  224. package/handlers/transform/loaders/index.d.ts +0 -8
  225. package/handlers/transform/loaders/index.js +0 -13
  226. package/handlers/transform/loaders/index.js.map +0 -1
  227. package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +0 -11
  228. package/handlers/transform/loaders/sanitizeImageTransformations.js +0 -58
  229. package/handlers/transform/loaders/sanitizeImageTransformations.js.map +0 -1
  230. package/handlers/transform/managers/imageManager.js +0 -63
  231. package/handlers/transform/managers/imageManager.js.map +0 -1
  232. package/handlers/transform/managers/index.d.ts +0 -5
  233. package/handlers/transform/managers/index.js +0 -13
  234. package/handlers/transform/managers/index.js.map +0 -1
  235. package/handlers/transform/optimizeImage.d.ts +0 -3
  236. package/handlers/transform/optimizeImage.js +0 -48
  237. package/handlers/transform/optimizeImage.js.map +0 -1
  238. package/handlers/transform/transformImage.d.ts +0 -10
  239. package/handlers/transform/transformImage.js +0 -30
  240. package/handlers/transform/transformImage.js.map +0 -1
  241. package/handlers/transform/utils.js.map +0 -1
  242. package/plugins/crud/files/validation.d.ts +0 -3
  243. package/plugins/crud/files/validation.js +0 -41
  244. package/plugins/crud/files/validation.js.map +0 -1
  245. package/plugins/crud/files.crud.d.ts +0 -4
  246. package/plugins/crud/files.crud.js +0 -431
  247. package/plugins/crud/files.crud.js.map +0 -1
  248. package/plugins/crud/settings.crud.d.ts +0 -5
  249. package/plugins/crud/settings.crud.js +0 -116
  250. package/plugins/crud/settings.crud.js.map +0 -1
  251. package/plugins/crud/system.crud.d.ts +0 -4
  252. package/plugins/crud/system.crud.js +0 -153
  253. package/plugins/crud/system.crud.js.map +0 -1
  254. package/plugins/crud/utils/checkBasePermissions.d.ts +0 -5
  255. package/plugins/crud/utils/checkBasePermissions.js +0 -33
  256. package/plugins/crud/utils/checkBasePermissions.js.map +0 -1
  257. package/plugins/crud/utils/createFileModel.d.ts +0 -5
  258. package/plugins/crud/utils/createFileModel.js +0 -77
  259. package/plugins/crud/utils/createFileModel.js.map +0 -1
  260. package/plugins/crud/utils/lifecycleEvents.d.ts +0 -6
  261. package/plugins/crud/utils/lifecycleEvents.js +0 -38
  262. package/plugins/crud/utils/lifecycleEvents.js.map +0 -1
  263. package/plugins/definitions/FilePhysicalStoragePlugin.js.map +0 -1
  264. package/plugins/definitions/FilePlugin.d.ts +0 -136
  265. package/plugins/definitions/FilePlugin.js +0 -70
  266. package/plugins/definitions/FilePlugin.js.map +0 -1
  267. package/plugins/definitions/FileStorageTransformPlugin.js.map +0 -1
  268. package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +0 -9
  269. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +0 -17
  270. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +0 -1
  271. package/plugins/definitions/InstallationPlugin.d.ts +0 -19
  272. package/plugins/definitions/InstallationPlugin.js +0 -42
  273. package/plugins/definitions/InstallationPlugin.js.map +0 -1
  274. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +0 -9
  275. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +0 -17
  276. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +0 -1
  277. package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +0 -9
  278. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +0 -17
  279. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +0 -1
  280. package/plugins/graphql.d.ts +0 -4
  281. package/plugins/graphql.js +0 -290
  282. package/plugins/graphql.js.map +0 -1
  283. package/plugins/storage/FileStorage.js +0 -103
  284. package/plugins/storage/FileStorage.js.map +0 -1
  285. package/plugins/storage/index.d.ts +0 -4
  286. package/plugins/storage/index.js +0 -26
  287. package/plugins/storage/index.js.map +0 -1
  288. package/utils.d.ts +0 -4
  289. package/utils.js +0 -16
  290. package/utils.js.map +0 -1
  291. /package/handlers/{transform/utils.d.ts → manage/legacyUtils.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","storagePluginType","FileStorage","constructor","context","storagePlugin","plugins","byType","pop","WebinyError","upload","params","settings","fileManager","getSettings","file","fileData","createFile","meta","private","Boolean","hideInFileManager","tags","Array","isArray","uploadFiles","files","filesData","Promise","all","map","item","createFilesInBatch","delete","id","key","deleteFile","exports"],"sources":["FileStorage.ts"],"sourcesContent":["import type { FileManagerContext } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport type { FilePhysicalStoragePlugin } from \"~/plugins/FilePhysicalStoragePlugin\";\n\nexport type Result = Record<string, any>;\n\nconst storagePluginType = \"api-file-manager-storage\";\n\nexport interface FileStorageUploadParams {\n buffer: Buffer;\n hideInFileManager: boolean | string;\n size: number;\n name: string;\n type: string;\n id?: string;\n key?: string;\n tags?: string[];\n keyPrefix?: string;\n}\nexport interface FileStorageDeleteParams {\n id: string;\n key: string;\n}\n\nexport interface FileStorageUploadMultipleParams {\n files: FileStorageUploadParams[];\n}\n\nexport interface FileStorageParams {\n context: FileManagerContext;\n}\nexport class FileStorage {\n private readonly context: FileManagerContext;\n\n constructor({ context }: FileStorageParams) {\n this.context = context;\n }\n\n get storagePlugin() {\n const storagePlugin = this.context.plugins\n .byType<FilePhysicalStoragePlugin>(storagePluginType)\n .pop();\n\n if (!storagePlugin) {\n throw new WebinyError(\n `Missing plugin of type \"${storagePluginType}\".`,\n \"STORAGE_PLUGIN_ERROR\"\n );\n }\n\n return storagePlugin;\n }\n\n async upload(params: FileStorageUploadParams): Promise<Result> {\n const settings = await this.context.fileManager.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n\n // Add file to cloud storage.\n const { file: fileData } = await this.storagePlugin.upload({\n ...params,\n settings\n });\n\n // Save file in DB.\n return this.context.fileManager.createFile({\n ...fileData,\n meta: {\n private: Boolean(params.hideInFileManager)\n },\n tags: Array.isArray(params.tags) ? params.tags : []\n });\n }\n\n async uploadFiles({ files }: FileStorageUploadMultipleParams) {\n const settings = await this.context.fileManager.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n\n const filesData = await Promise.all(\n files.map(async item => {\n // TODO: improve types of this.storagePlugin.\n const { file } = await this.storagePlugin.upload({\n ...item,\n settings\n });\n\n return {\n ...file,\n meta: {\n private: Boolean(item.hideInFileManager)\n },\n tags: Array.isArray(item.tags) ? item.tags : []\n };\n })\n );\n\n return this.context.fileManager.createFilesInBatch(filesData);\n }\n\n async delete(params: FileStorageDeleteParams) {\n const { id, key } = params;\n const { fileManager } = this.context;\n // Delete file from cloud storage.\n await this.storagePlugin.delete({\n key\n });\n\n // Delete file from the DB.\n return await fileManager.deleteFile(id);\n }\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,MAAMC,iBAAiB,GAAG,0BAA0B;AAyB7C,MAAMC,WAAW,CAAC;EAGrBC,WAAWA,CAAC;IAAEC;EAA2B,CAAC,EAAE;IACxC,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B;EAEA,IAAIC,aAAaA,CAAA,EAAG;IAChB,MAAMA,aAAa,GAAG,IAAI,CAACD,OAAO,CAACE,OAAO,CACrCC,MAAM,CAA4BN,iBAAiB,CAAC,CACpDO,GAAG,CAAC,CAAC;IAEV,IAAI,CAACH,aAAa,EAAE;MAChB,MAAM,IAAII,cAAW,CACjB,2BAA2BR,iBAAiB,IAAI,EAChD,sBACJ,CAAC;IACL;IAEA,OAAOI,aAAa;EACxB;EAEA,MAAMK,MAAMA,CAACC,MAA+B,EAAmB;IAC3D,MAAMC,QAAQ,GAAG,MAAM,IAAI,CAACR,OAAO,CAACS,WAAW,CAACC,WAAW,CAAC,CAAC;IAC7D,IAAI,CAACF,QAAQ,EAAE;MACX,MAAM,IAAIH,cAAW,CAAC,gCAAgC,EAAE,oBAAoB,CAAC;IACjF;;IAEA;IACA,MAAM;MAAEM,IAAI,EAAEC;IAAS,CAAC,GAAG,MAAM,IAAI,CAACX,aAAa,CAACK,MAAM,CAAC;MACvD,GAAGC,MAAM;MACTC;IACJ,CAAC,CAAC;;IAEF;IACA,OAAO,IAAI,CAACR,OAAO,CAACS,WAAW,CAACI,UAAU,CAAC;MACvC,GAAGD,QAAQ;MACXE,IAAI,EAAE;QACFC,OAAO,EAAEC,OAAO,CAACT,MAAM,CAACU,iBAAiB;MAC7C,CAAC;MACDC,IAAI,EAAEC,KAAK,CAACC,OAAO,CAACb,MAAM,CAACW,IAAI,CAAC,GAAGX,MAAM,CAACW,IAAI,GAAG;IACrD,CAAC,CAAC;EACN;EAEA,MAAMG,WAAWA,CAAC;IAAEC;EAAuC,CAAC,EAAE;IAC1D,MAAMd,QAAQ,GAAG,MAAM,IAAI,CAACR,OAAO,CAACS,WAAW,CAACC,WAAW,CAAC,CAAC;IAC7D,IAAI,CAACF,QAAQ,EAAE;MACX,MAAM,IAAIH,cAAW,CAAC,gCAAgC,EAAE,oBAAoB,CAAC;IACjF;IAEA,MAAMkB,SAAS,GAAG,MAAMC,OAAO,CAACC,GAAG,CAC/BH,KAAK,CAACI,GAAG,CAAC,MAAMC,IAAI,IAAI;MACpB;MACA,MAAM;QAAEhB;MAAK,CAAC,GAAG,MAAM,IAAI,CAACV,aAAa,CAACK,MAAM,CAAC;QAC7C,GAAGqB,IAAI;QACPnB;MACJ,CAAC,CAAC;MAEF,OAAO;QACH,GAAGG,IAAI;QACPG,IAAI,EAAE;UACFC,OAAO,EAAEC,OAAO,CAACW,IAAI,CAACV,iBAAiB;QAC3C,CAAC;QACDC,IAAI,EAAEC,KAAK,CAACC,OAAO,CAACO,IAAI,CAACT,IAAI,CAAC,GAAGS,IAAI,CAACT,IAAI,GAAG;MACjD,CAAC;IACL,CAAC,CACL,CAAC;IAED,OAAO,IAAI,CAAClB,OAAO,CAACS,WAAW,CAACmB,kBAAkB,CAACL,SAAS,CAAC;EACjE;EAEA,MAAMM,MAAMA,CAACtB,MAA+B,EAAE;IAC1C,MAAM;MAAEuB,EAAE;MAAEC;IAAI,CAAC,GAAGxB,MAAM;IAC1B,MAAM;MAAEE;IAAY,CAAC,GAAG,IAAI,CAACT,OAAO;IACpC;IACA,MAAM,IAAI,CAACC,aAAa,CAAC4B,MAAM,CAAC;MAC5BE;IACJ,CAAC,CAAC;;IAEF;IACA,OAAO,MAAMtB,WAAW,CAACuB,UAAU,CAACF,EAAE,CAAC;EAC3C;AACJ;AAACG,OAAA,CAAAnC,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -0,0 +1,49 @@
1
+ type PublicAccess = {
2
+ type: "public";
3
+ };
4
+ type PrivateAuthenticatedAccess = {
5
+ type: "private-authenticated";
6
+ };
7
+ export interface File {
8
+ id: string;
9
+ key: string;
10
+ size: number;
11
+ type: string;
12
+ name: string;
13
+ meta: Record<string, any>;
14
+ accessControl?: PublicAccess | PrivateAuthenticatedAccess;
15
+ location: {
16
+ folderId: string;
17
+ };
18
+ tags: string[];
19
+ aliases: string[];
20
+ createdOn: string;
21
+ modifiedOn: string | null;
22
+ savedOn: string;
23
+ createdBy: CreatedBy;
24
+ modifiedBy: CreatedBy | null;
25
+ savedBy: CreatedBy;
26
+ extensions?: Record<string, any>;
27
+ /**
28
+ * Added with new storage operations refactoring.
29
+ */
30
+ tenant: string;
31
+ locale: string;
32
+ webinyVersion: string;
33
+ /**
34
+ * User can add new fields to the File object, so we must allow it in the types.
35
+ */
36
+ [key: string]: any;
37
+ }
38
+ export interface FileAlias {
39
+ tenant: string;
40
+ locale: string;
41
+ fileId: string;
42
+ alias: string;
43
+ }
44
+ export interface CreatedBy {
45
+ id: string;
46
+ displayName: string | null;
47
+ type: string;
48
+ }
49
+ export {};
package/types/file.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["file.ts"],"sourcesContent":["type PublicAccess = {\n type: \"public\";\n};\n\ntype PrivateAuthenticatedAccess = {\n type: \"private-authenticated\";\n};\n\nexport interface File {\n id: string;\n key: string;\n size: number;\n type: string;\n name: string;\n meta: Record<string, any>;\n accessControl?: PublicAccess | PrivateAuthenticatedAccess;\n location: {\n folderId: string;\n };\n tags: string[];\n aliases: string[];\n\n createdOn: string;\n modifiedOn: string | null;\n savedOn: string;\n createdBy: CreatedBy;\n modifiedBy: CreatedBy | null;\n savedBy: CreatedBy;\n extensions?: Record<string, any>;\n\n /**\n * Added with new storage operations refactoring.\n */\n tenant: string;\n locale: string;\n webinyVersion: string;\n /**\n * User can add new fields to the File object, so we must allow it in the types.\n */\n\n [key: string]: any;\n}\n\nexport interface FileAlias {\n tenant: string;\n locale: string;\n fileId: string;\n alias: string;\n}\n\nexport interface CreatedBy {\n id: string;\n displayName: string | null;\n type: string;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,44 @@
1
+ import type { Topic } from "@webiny/pubsub/types";
2
+ import type { File } from "./file";
3
+ export interface OnFileBeforeCreateTopicParams<TFile extends File = File> {
4
+ file: TFile;
5
+ meta?: Record<string, any>;
6
+ }
7
+ export interface OnFileAfterCreateTopicParams<TFile extends File = File> {
8
+ file: TFile;
9
+ meta?: Record<string, any>;
10
+ }
11
+ export interface OnFileBeforeBatchCreateTopicParams<TFile extends File = File> {
12
+ files: TFile[];
13
+ meta?: Record<string, any>;
14
+ }
15
+ export interface OnFileAfterBatchCreateTopicParams<TFile extends File = File> {
16
+ files: TFile[];
17
+ meta?: Record<string, any>;
18
+ }
19
+ export interface OnFileBeforeUpdateTopicParams<TFile extends File = File> {
20
+ original: TFile;
21
+ file: TFile;
22
+ input: Record<string, any>;
23
+ }
24
+ export interface OnFileAfterUpdateTopicParams<TFile extends File = File> {
25
+ original: TFile;
26
+ file: TFile;
27
+ input: Record<string, any>;
28
+ }
29
+ export interface OnFileBeforeDeleteTopicParams<TFile extends File = File> {
30
+ file: TFile;
31
+ }
32
+ export interface OnFileAfterDeleteTopicParams<TFile extends File = File> {
33
+ file: TFile;
34
+ }
35
+ export interface FileLifecycleEvents {
36
+ onFileBeforeCreate: Topic<OnFileBeforeCreateTopicParams>;
37
+ onFileAfterCreate: Topic<OnFileAfterCreateTopicParams>;
38
+ onFileBeforeBatchCreate: Topic<OnFileBeforeBatchCreateTopicParams>;
39
+ onFileAfterBatchCreate: Topic<OnFileAfterBatchCreateTopicParams>;
40
+ onFileBeforeUpdate: Topic<OnFileBeforeUpdateTopicParams>;
41
+ onFileAfterUpdate: Topic<OnFileAfterUpdateTopicParams>;
42
+ onFileBeforeDelete: Topic<OnFileBeforeDeleteTopicParams>;
43
+ onFileAfterDelete: Topic<OnFileAfterDeleteTopicParams>;
44
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=file.lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["file.lifecycle.ts"],"sourcesContent":["import type { Topic } from \"@webiny/pubsub/types\";\nimport type { File } from \"./file\";\n\nexport interface OnFileBeforeCreateTopicParams<TFile extends File = File> {\n file: TFile;\n meta?: Record<string, any>;\n}\n\nexport interface OnFileAfterCreateTopicParams<TFile extends File = File> {\n file: TFile;\n meta?: Record<string, any>;\n}\n\nexport interface OnFileBeforeBatchCreateTopicParams<TFile extends File = File> {\n files: TFile[];\n meta?: Record<string, any>;\n}\n\nexport interface OnFileAfterBatchCreateTopicParams<TFile extends File = File> {\n files: TFile[];\n meta?: Record<string, any>;\n}\n\nexport interface OnFileBeforeUpdateTopicParams<TFile extends File = File> {\n original: TFile;\n file: TFile;\n input: Record<string, any>;\n}\n\nexport interface OnFileAfterUpdateTopicParams<TFile extends File = File> {\n original: TFile;\n file: TFile;\n input: Record<string, any>;\n}\n\nexport interface OnFileBeforeDeleteTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface OnFileAfterDeleteTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface FileLifecycleEvents {\n onFileBeforeCreate: Topic<OnFileBeforeCreateTopicParams>;\n onFileAfterCreate: Topic<OnFileAfterCreateTopicParams>;\n onFileBeforeBatchCreate: Topic<OnFileBeforeBatchCreateTopicParams>;\n onFileAfterBatchCreate: Topic<OnFileAfterBatchCreateTopicParams>;\n onFileBeforeUpdate: Topic<OnFileBeforeUpdateTopicParams>;\n onFileAfterUpdate: Topic<OnFileAfterUpdateTopicParams>;\n onFileBeforeDelete: Topic<OnFileBeforeDeleteTopicParams>;\n onFileAfterDelete: Topic<OnFileAfterDeleteTopicParams>;\n}\n"],"mappings":"","ignoreList":[]}
package/types.d.ts CHANGED
@@ -1,74 +1,61 @@
1
- import { I18NContext } from "@webiny/api-i18n/types";
2
- import { FileStorage } from "./plugins/storage/FileStorage";
3
- import { TenancyContext } from "@webiny/api-tenancy/types";
4
- import { SecurityContext, SecurityPermission } from "@webiny/api-security/types";
5
- import { Context } from "@webiny/api/types";
6
- export interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {
7
- fileManager: {
8
- files: FilesCRUD;
9
- settings: SettingsCRUD;
10
- storage: FileStorage;
11
- system: SystemCRUD;
12
- };
1
+ import type { I18NContext } from "@webiny/api-i18n/types";
2
+ import type { FileStorage } from "./storage/FileStorage";
3
+ import type { TenancyContext } from "@webiny/api-tenancy/types";
4
+ import type { SecurityContext, SecurityPermission } from "@webiny/api-security/types";
5
+ import type { Context } from "@webiny/api/types";
6
+ import type { FileLifecycleEvents } from "./types/file.lifecycle";
7
+ import type { CreatedBy, File } from "./types/file";
8
+ import type { Topic } from "@webiny/pubsub/types";
9
+ import type { CmsContext, CmsEntryListSort } from "@webiny/api-headless-cms/types";
10
+ import type { Context as TasksContext } from "@webiny/tasks/types";
11
+ export * from "./types/file.lifecycle";
12
+ export * from "./types/file";
13
+ export * from "./types/file";
14
+ export interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {
15
+ storage: FileStorage;
16
+ }
17
+ export interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext, CmsContext, TasksContext {
18
+ fileManager: FileManagerContextObject;
13
19
  }
14
20
  export interface FilePermission extends SecurityPermission {
15
21
  name: "fm.file";
16
22
  rwd?: string;
17
23
  own?: boolean;
18
24
  }
19
- export interface File {
20
- id: string;
21
- key: string;
22
- size: number;
23
- type: string;
24
- name: string;
25
- meta: Record<string, any>;
26
- tags: string[];
27
- createdOn: string;
28
- createdBy: CreatedBy;
29
- /**
30
- * Added with new storage operations refactoring.
31
- */
32
- tenant: string;
33
- locale: string;
34
- webinyVersion: string;
35
- /**
36
- * User can add new fields to the File object so we must allow it in the types.
37
- */
38
- [key: string]: any;
39
- }
40
- export interface CreatedBy {
41
- id: string;
42
- displayName: string | null;
43
- type: string;
25
+ export interface SettingsPermission extends SecurityPermission {
26
+ name: "fm.setting";
44
27
  }
45
28
  export interface FileInput {
29
+ id: string;
30
+ createdOn?: string | Date | null;
31
+ modifiedOn?: string | Date | null;
32
+ savedOn?: string | Date | null;
33
+ createdBy?: CreatedBy | null;
34
+ modifiedBy?: CreatedBy | null;
35
+ savedBy?: CreatedBy | null;
46
36
  key: string;
47
37
  name: string;
48
38
  size: number;
49
39
  type: string;
50
40
  meta: Record<string, any>;
41
+ location?: {
42
+ folderId: string;
43
+ };
51
44
  tags: string[];
45
+ aliases: string[];
46
+ extensions?: Record<string, any>;
52
47
  }
53
48
  export interface FileListWhereParams {
54
- search?: string;
55
- type?: string;
56
- type_in?: string[];
57
- tag?: string;
58
- tag_in?: string[];
59
- tag_and_in?: string[];
60
- id_in?: string[];
61
- id?: string;
49
+ AND?: FileListWhereParams[];
50
+ OR?: FileListWhereParams[];
51
+ [key: string]: any;
62
52
  }
63
53
  export interface FilesListOpts {
64
54
  search?: string;
65
- types?: string[];
66
- tags?: string[];
67
- ids?: string[];
68
55
  limit?: number;
69
56
  after?: string;
70
57
  where?: FileListWhereParams;
71
- sort?: string[];
58
+ sort?: CmsEntryListSort;
72
59
  }
73
60
  export interface FileListMeta {
74
61
  cursor: string | null;
@@ -87,25 +74,30 @@ interface FilesCrudListTagsParams {
87
74
  limit?: number;
88
75
  after?: string;
89
76
  }
90
- export interface FilesCRUD {
77
+ export interface ListTagsResponse {
78
+ tag: string;
79
+ count: number;
80
+ }
81
+ export interface FilesCRUD extends FileLifecycleEvents {
91
82
  getFile(id: string): Promise<File>;
92
83
  listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;
93
- listTags(params: FilesCrudListTagsParams): Promise<string[]>;
94
- createFile(data: FileInput): Promise<File>;
84
+ listTags(params: FilesCrudListTagsParams): Promise<ListTagsResponse[]>;
85
+ createFile(data: FileInput, meta?: Record<string, any>): Promise<File>;
95
86
  updateFile(id: string, data: Partial<FileInput>): Promise<File>;
96
87
  deleteFile(id: string): Promise<boolean>;
97
- createFilesInBatch(data: FileInput[]): Promise<File[]>;
88
+ createFilesInBatch(data: FileInput[], meta?: Record<string, any>): Promise<File[]>;
98
89
  }
99
90
  export interface SystemCRUD {
91
+ onSystemBeforeInstall: Topic;
92
+ onSystemAfterInstall: Topic;
100
93
  getVersion(): Promise<string | null>;
101
94
  setVersion(version: string): Promise<void>;
102
95
  install(args: {
103
96
  srcPrefix: string;
104
97
  }): Promise<boolean>;
105
- upgrade(version: string, data?: Record<string, any>): Promise<boolean>;
106
98
  }
107
99
  export interface FileManagerSettings {
108
- key: string;
100
+ tenant: string;
109
101
  uploadMinFileSize: number;
110
102
  uploadMaxFileSize: number;
111
103
  srcPrefix: string;
@@ -114,11 +106,23 @@ export interface FileManagerSystem {
114
106
  version: string;
115
107
  tenant: string;
116
108
  }
117
- export declare type SettingsCRUD = {
109
+ export interface OnSettingsBeforeUpdateTopicParams {
110
+ input: Partial<FileManagerSettings>;
111
+ original: FileManagerSettings;
112
+ settings: FileManagerSettings;
113
+ }
114
+ export interface OnSettingsAfterUpdateTopicParams {
115
+ input: Partial<FileManagerSettings>;
116
+ original: FileManagerSettings;
117
+ settings: FileManagerSettings;
118
+ }
119
+ export type SettingsCRUD = {
118
120
  getSettings(): Promise<FileManagerSettings | null>;
119
121
  createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
120
122
  updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
121
123
  deleteSettings(): Promise<boolean>;
124
+ onSettingsBeforeUpdate: Topic<OnSettingsBeforeUpdateTopicParams>;
125
+ onSettingsAfterUpdate: Topic<OnSettingsAfterUpdateTopicParams>;
122
126
  };
123
127
  /********
124
128
  * Storage operations
@@ -149,6 +153,9 @@ export interface FileManagerSystemStorageOperationsCreateParams {
149
153
  */
150
154
  data: FileManagerSystem;
151
155
  }
156
+ export interface FileManagerSystemStorageOperationsGetParams {
157
+ tenant: string;
158
+ }
152
159
  /**
153
160
  * @category StorageOperations
154
161
  * @category SystemStorageOperations
@@ -157,7 +164,7 @@ export interface FileManagerSystemStorageOperations {
157
164
  /**
158
165
  * Get the FileManager system data.
159
166
  */
160
- get: () => Promise<FileManagerSystem | null>;
167
+ get: (params: FileManagerSystemStorageOperationsGetParams) => Promise<FileManagerSystem | null>;
161
168
  /**
162
169
  * Update the FileManager system data..
163
170
  */
@@ -193,6 +200,12 @@ export interface FileManagerSettingsStorageOperationsCreateParams {
193
200
  */
194
201
  data: FileManagerSettings;
195
202
  }
203
+ export interface FileManagerStorageOperationsGetSettingsParams {
204
+ tenant: string;
205
+ }
206
+ export interface FileManagerStorageOperationsDeleteSettings {
207
+ tenant: string;
208
+ }
196
209
  /**
197
210
  * @category StorageOperations
198
211
  * @category SettingsStorageOperations
@@ -201,7 +214,7 @@ export interface FileManagerSettingsStorageOperations {
201
214
  /**
202
215
  * Get the FileManager system data.
203
216
  */
204
- get: () => Promise<FileManagerSettings | null>;
217
+ get: (params: FileManagerStorageOperationsGetSettingsParams) => Promise<FileManagerSettings | null>;
205
218
  /**
206
219
  * Create the FileManagerSettingsData
207
220
  */
@@ -213,7 +226,7 @@ export interface FileManagerSettingsStorageOperations {
213
226
  /**
214
227
  * Delete the existing settings.
215
228
  */
216
- delete: () => Promise<void>;
229
+ delete: (params: FileManagerStorageOperationsDeleteSettings) => Promise<void>;
217
230
  }
218
231
  /**
219
232
  * @category StorageOperations
@@ -266,20 +279,7 @@ export interface FileManagerFilesStorageOperationsCreateBatchParams {
266
279
  * @category FilesStorageOperationsParams
267
280
  */
268
281
  export interface FileManagerFilesStorageOperationsListParamsWhere {
269
- id?: string;
270
- id_in?: string[];
271
- name?: string;
272
- name_contains?: string;
273
- tag?: string;
274
- tag_contains?: string;
275
- tag_in?: string[];
276
- createdBy?: string;
277
- locale: string;
278
- tenant: string;
279
- private?: boolean;
280
- type?: string;
281
- type_in?: string[];
282
- search?: string;
282
+ [key: string]: any;
283
283
  }
284
284
  /**
285
285
  * @category StorageOperations
@@ -288,9 +288,10 @@ export interface FileManagerFilesStorageOperationsListParamsWhere {
288
288
  */
289
289
  export interface FileManagerFilesStorageOperationsListParams {
290
290
  where: FileManagerFilesStorageOperationsListParamsWhere;
291
- sort: string[];
291
+ sort: CmsEntryListSort;
292
292
  limit: number;
293
293
  after: string | null;
294
+ search?: string;
294
295
  }
295
296
  /**
296
297
  * @category StorageOperations
@@ -302,14 +303,14 @@ export interface FileManagerFilesStorageOperationsListResponseMeta {
302
303
  totalCount: number;
303
304
  cursor: string | null;
304
305
  }
305
- export declare type FileManagerFilesStorageOperationsListResponse = [
306
+ export type FileManagerFilesStorageOperationsListResponse = [
306
307
  File[],
307
308
  FileManagerFilesStorageOperationsListResponseMeta
308
309
  ];
309
- export declare type FileManagerFilesStorageOperationsTagsResponse = [
310
- string[],
311
- FileManagerFilesStorageOperationsListResponseMeta
312
- ];
310
+ export interface FileManagerFilesStorageOperationsTagsResponse {
311
+ tag: string;
312
+ count: number;
313
+ }
313
314
  export interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {
314
315
  locale: string;
315
316
  tenant: string;
@@ -356,6 +357,16 @@ export interface FileManagerFilesStorageOperations {
356
357
  /**
357
358
  * Get a list of all file tags filtered by given parameters.
358
359
  */
359
- tags: (params: FileManagerFilesStorageOperationsTagsParams) => Promise<FileManagerFilesStorageOperationsTagsResponse>;
360
+ tags: (params: FileManagerFilesStorageOperationsTagsParams) => Promise<FileManagerFilesStorageOperationsTagsResponse[]>;
361
+ }
362
+ export interface FileManagerAliasesStorageOperations {
363
+ storeAliases(file: File): Promise<void>;
364
+ deleteAliases(file: File): Promise<void>;
365
+ }
366
+ export interface FileManagerStorageOperations<TContext = FileManagerContext> {
367
+ beforeInit?: (context: TContext) => Promise<void>;
368
+ files: FileManagerFilesStorageOperations;
369
+ aliases: FileManagerAliasesStorageOperations;
370
+ settings: FileManagerSettingsStorageOperations;
371
+ system: FileManagerSystemStorageOperations;
360
372
  }
361
- export {};
package/types.js CHANGED
@@ -2,4 +2,28 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
5
+ });
6
+ var _file = require("./types/file.lifecycle");
7
+ Object.keys(_file).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _file[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _file[key];
14
+ }
15
+ });
16
+ });
17
+ var _file2 = require("./types/file");
18
+ Object.keys(_file2).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _file2[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _file2[key];
25
+ }
26
+ });
27
+ });
28
+
29
+ //# sourceMappingURL=types.js.map
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { I18NContext } from \"@webiny/api-i18n/types\";\nimport { FileStorage } from \"./plugins/storage/FileStorage\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { SecurityContext, SecurityPermission } from \"@webiny/api-security/types\";\nimport { Context } from \"@webiny/api/types\";\n\nexport interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {\n fileManager: {\n files: FilesCRUD;\n settings: SettingsCRUD;\n storage: FileStorage;\n system: SystemCRUD;\n };\n}\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n\nexport interface File {\n id: string;\n key: string;\n size: number;\n type: string;\n name: string;\n meta: Record<string, any>;\n tags: string[];\n createdOn: string;\n createdBy: CreatedBy;\n /**\n * Added with new storage operations refactoring.\n */\n tenant: string;\n locale: string;\n webinyVersion: string;\n /**\n * User can add new fields to the File object so we must allow it in the types.\n */\n [key: string]: any;\n}\n\nexport interface CreatedBy {\n id: string;\n displayName: string | null;\n type: string;\n}\n\nexport interface FileInput {\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n tags: string[];\n}\n\nexport interface FileListWhereParams {\n search?: string;\n type?: string;\n type_in?: string[];\n tag?: string;\n tag_in?: string[];\n tag_and_in?: string[];\n id_in?: string[];\n id?: string;\n}\nexport interface FilesListOpts {\n search?: string;\n types?: string[];\n tags?: string[];\n ids?: string[];\n limit?: number;\n after?: string;\n where?: FileListWhereParams;\n sort?: string[];\n}\n\nexport interface FileListMeta {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\ninterface FilesCrudListTagsWhere {\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n tag_not_startsWith?: string;\n tag_startsWith?: string;\n}\ninterface FilesCrudListTagsParams {\n where?: FilesCrudListTagsWhere;\n limit?: number;\n after?: string;\n}\n\nexport interface FilesCRUD {\n getFile(id: string): Promise<File>;\n listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;\n listTags(params: FilesCrudListTagsParams): Promise<string[]>;\n createFile(data: FileInput): Promise<File>;\n updateFile(id: string, data: Partial<FileInput>): Promise<File>;\n deleteFile(id: string): Promise<boolean>;\n createFilesInBatch(data: FileInput[]): Promise<File[]>;\n}\n\nexport interface SystemCRUD {\n getVersion(): Promise<string | null>;\n setVersion(version: string): Promise<void>;\n install(args: { srcPrefix: string }): Promise<boolean>;\n upgrade(version: string, data?: Record<string, any>): Promise<boolean>;\n}\n\nexport interface FileManagerSettings {\n key: string;\n uploadMinFileSize: number;\n uploadMaxFileSize: number;\n srcPrefix: string;\n}\n\nexport interface FileManagerSystem {\n version: string;\n tenant: string;\n}\n\nexport type SettingsCRUD = {\n getSettings(): Promise<FileManagerSettings | null>;\n createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n deleteSettings(): Promise<boolean>;\n};\n/********\n * Storage operations\n *******/\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsUpdateParams {\n /**\n * The system data to be updated.\n */\n original: FileManagerSystem;\n /**\n * The system data with the updated fields.\n */\n data: FileManagerSystem;\n}\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsCreateParams {\n /**\n * The system fields.\n */\n data: FileManagerSystem;\n}\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n */\nexport interface FileManagerSystemStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: () => Promise<FileManagerSystem | null>;\n /**\n * Update the FileManager system data..\n */\n update: (params: FileManagerSystemStorageOperationsUpdateParams) => Promise<FileManagerSystem>;\n /**\n * Create the FileManagerSystemData\n */\n create: (params: FileManagerSystemStorageOperationsCreateParams) => Promise<FileManagerSystem>;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsUpdateParams {\n /**\n * Original settings to be updated.\n */\n original: FileManagerSettings;\n /**\n * The settings with the updated fields.\n */\n data: FileManagerSettings;\n}\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsCreateParams {\n /**\n * The settings fields.\n */\n data: FileManagerSettings;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n */\nexport interface FileManagerSettingsStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: () => Promise<FileManagerSettings | null>;\n /**\n * Create the FileManagerSettingsData\n */\n create: (\n params: FileManagerSettingsStorageOperationsCreateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Update the FileManager system data..\n */\n update: (\n params: FileManagerSettingsStorageOperationsUpdateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Delete the existing settings.\n */\n delete: () => Promise<void>;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsUpdateParams {\n original: File;\n file: File;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsDeleteParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateBatchParams {\n files: File[];\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParamsWhere {\n id?: string;\n id_in?: string[];\n name?: string;\n name_contains?: string;\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n createdBy?: string;\n locale: string;\n tenant: string;\n private?: boolean;\n type?: string;\n type_in?: string[];\n search?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n sort: string[];\n limit: number;\n after: string | null;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListResponseMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor: string | null;\n}\nexport type FileManagerFilesStorageOperationsListResponse = [\n File[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport type FileManagerFilesStorageOperationsTagsResponse = [\n string[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {\n locale: string;\n tenant: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsTagsParams {\n where: FileManagerFilesStorageOperationsTagsParamsWhere;\n limit: number;\n after?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n */\nexport interface FileManagerFilesStorageOperations {\n /**\n * Get a single file with given ID from the storage.\n */\n get: (params: FileManagerFilesStorageOperationsGetParams) => Promise<File | null>;\n /**\n * Insert the file data into the database.\n */\n create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;\n /**\n * Update the file data in the database.\n */\n update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;\n /**\n * Delete the file from the database.\n */\n delete: (params: FileManagerFilesStorageOperationsDeleteParams) => Promise<void>;\n /**\n * Store multiple files at once to the database.\n */\n createBatch: (params: FileManagerFilesStorageOperationsCreateBatchParams) => Promise<File[]>;\n /**\n * Get a list of files filtered by given parameters.\n */\n list: (\n params: FileManagerFilesStorageOperationsListParams\n ) => Promise<FileManagerFilesStorageOperationsListResponse>;\n /**\n * Get a list of all file tags filtered by given parameters.\n */\n tags: (\n params: FileManagerFilesStorageOperationsTagsParams\n ) => Promise<FileManagerFilesStorageOperationsTagsResponse>;\n}\n"],"mappings":""}
1
+ {"version":3,"names":["_file","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_file2"],"sources":["types.ts"],"sourcesContent":["import type { I18NContext } from \"@webiny/api-i18n/types\";\nimport type { FileStorage } from \"./storage/FileStorage\";\nimport type { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport type { SecurityContext, SecurityPermission } from \"@webiny/api-security/types\";\nimport type { Context } from \"@webiny/api/types\";\nimport type { FileLifecycleEvents } from \"./types/file.lifecycle\";\nimport type { CreatedBy, File } from \"./types/file\";\nimport type { Topic } from \"@webiny/pubsub/types\";\nimport type { CmsContext, CmsEntryListSort } from \"@webiny/api-headless-cms/types\";\nimport type { Context as TasksContext } from \"@webiny/tasks/types\";\n\nexport * from \"./types/file.lifecycle\";\nexport * from \"./types/file\";\nexport * from \"./types/file\";\n\nexport interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {\n storage: FileStorage;\n}\n\nexport interface FileManagerContext\n extends Context,\n SecurityContext,\n TenancyContext,\n I18NContext,\n CmsContext,\n TasksContext {\n fileManager: FileManagerContextObject;\n}\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n\nexport interface SettingsPermission extends SecurityPermission {\n name: \"fm.setting\";\n}\n\nexport interface FileInput {\n id: string;\n\n // In the background, we're actually mapping these to entry-level fields.\n // This is fine since we don't use revisions for files.\n createdOn?: string | Date | null;\n modifiedOn?: string | Date | null;\n savedOn?: string | Date | null;\n createdBy?: CreatedBy | null;\n modifiedBy?: CreatedBy | null;\n savedBy?: CreatedBy | null;\n\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n location?: {\n folderId: string;\n };\n tags: string[];\n aliases: string[];\n extensions?: Record<string, any>;\n}\n\nexport interface FileListWhereParams {\n AND?: FileListWhereParams[];\n OR?: FileListWhereParams[];\n [key: string]: any;\n}\nexport interface FilesListOpts {\n search?: string;\n limit?: number;\n after?: string;\n where?: FileListWhereParams;\n sort?: CmsEntryListSort;\n}\n\nexport interface FileListMeta {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\ninterface FilesCrudListTagsWhere {\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n tag_not_startsWith?: string;\n tag_startsWith?: string;\n}\ninterface FilesCrudListTagsParams {\n where?: FilesCrudListTagsWhere;\n limit?: number;\n after?: string;\n}\n\nexport interface ListTagsResponse {\n tag: string;\n count: number;\n}\nexport interface FilesCRUD extends FileLifecycleEvents {\n getFile(id: string): Promise<File>;\n listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;\n listTags(params: FilesCrudListTagsParams): Promise<ListTagsResponse[]>;\n createFile(data: FileInput, meta?: Record<string, any>): Promise<File>;\n updateFile(id: string, data: Partial<FileInput>): Promise<File>;\n deleteFile(id: string): Promise<boolean>;\n createFilesInBatch(data: FileInput[], meta?: Record<string, any>): Promise<File[]>;\n}\n\nexport interface SystemCRUD {\n onSystemBeforeInstall: Topic;\n onSystemAfterInstall: Topic;\n getVersion(): Promise<string | null>;\n setVersion(version: string): Promise<void>;\n install(args: { srcPrefix: string }): Promise<boolean>;\n}\n\nexport interface FileManagerSettings {\n tenant: string;\n uploadMinFileSize: number;\n uploadMaxFileSize: number;\n srcPrefix: string;\n}\n\nexport interface FileManagerSystem {\n version: string;\n tenant: string;\n}\n\nexport interface OnSettingsBeforeUpdateTopicParams {\n input: Partial<FileManagerSettings>;\n original: FileManagerSettings;\n settings: FileManagerSettings;\n}\n\nexport interface OnSettingsAfterUpdateTopicParams {\n input: Partial<FileManagerSettings>;\n original: FileManagerSettings;\n settings: FileManagerSettings;\n}\n\nexport type SettingsCRUD = {\n getSettings(): Promise<FileManagerSettings | null>;\n createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n deleteSettings(): Promise<boolean>;\n\n onSettingsBeforeUpdate: Topic<OnSettingsBeforeUpdateTopicParams>;\n onSettingsAfterUpdate: Topic<OnSettingsAfterUpdateTopicParams>;\n};\n/********\n * Storage operations\n *******/\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsUpdateParams {\n /**\n * The system data to be updated.\n */\n original: FileManagerSystem;\n /**\n * The system data with the updated fields.\n */\n data: FileManagerSystem;\n}\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsCreateParams {\n /**\n * The system fields.\n */\n data: FileManagerSystem;\n}\n\nexport interface FileManagerSystemStorageOperationsGetParams {\n tenant: string;\n}\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n */\nexport interface FileManagerSystemStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: (params: FileManagerSystemStorageOperationsGetParams) => Promise<FileManagerSystem | null>;\n /**\n * Update the FileManager system data..\n */\n update: (params: FileManagerSystemStorageOperationsUpdateParams) => Promise<FileManagerSystem>;\n /**\n * Create the FileManagerSystemData\n */\n create: (params: FileManagerSystemStorageOperationsCreateParams) => Promise<FileManagerSystem>;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsUpdateParams {\n /**\n * Original settings to be updated.\n */\n original: FileManagerSettings;\n /**\n * The settings with the updated fields.\n */\n data: FileManagerSettings;\n}\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsCreateParams {\n /**\n * The settings fields.\n */\n data: FileManagerSettings;\n}\n\nexport interface FileManagerStorageOperationsGetSettingsParams {\n tenant: string;\n}\n\nexport interface FileManagerStorageOperationsDeleteSettings {\n tenant: string;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n */\nexport interface FileManagerSettingsStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: (\n params: FileManagerStorageOperationsGetSettingsParams\n ) => Promise<FileManagerSettings | null>;\n /**\n * Create the FileManagerSettingsData\n */\n create: (\n params: FileManagerSettingsStorageOperationsCreateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Update the FileManager system data..\n */\n update: (\n params: FileManagerSettingsStorageOperationsUpdateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Delete the existing settings.\n */\n delete: (params: FileManagerStorageOperationsDeleteSettings) => Promise<void>;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsUpdateParams {\n original: File;\n file: File;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsDeleteParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateBatchParams {\n files: File[];\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParamsWhere {\n [key: string]: any;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n sort: CmsEntryListSort;\n limit: number;\n after: string | null;\n search?: string;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListResponseMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor: string | null;\n}\nexport type FileManagerFilesStorageOperationsListResponse = [\n File[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport interface FileManagerFilesStorageOperationsTagsResponse {\n tag: string;\n count: number;\n}\n\nexport interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {\n locale: string;\n tenant: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsTagsParams {\n where: FileManagerFilesStorageOperationsTagsParamsWhere;\n limit: number;\n after?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n */\nexport interface FileManagerFilesStorageOperations {\n /**\n * Get a single file with given ID from the storage.\n */\n get: (params: FileManagerFilesStorageOperationsGetParams) => Promise<File | null>;\n /**\n * Insert the file data into the database.\n */\n create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;\n /**\n * Update the file data in the database.\n */\n update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;\n /**\n * Delete the file from the database.\n */\n delete: (params: FileManagerFilesStorageOperationsDeleteParams) => Promise<void>;\n /**\n * Store multiple files at once to the database.\n */\n createBatch: (params: FileManagerFilesStorageOperationsCreateBatchParams) => Promise<File[]>;\n /**\n * Get a list of files filtered by given parameters.\n */\n list: (\n params: FileManagerFilesStorageOperationsListParams\n ) => Promise<FileManagerFilesStorageOperationsListResponse>;\n /**\n * Get a list of all file tags filtered by given parameters.\n */\n tags: (\n params: FileManagerFilesStorageOperationsTagsParams\n ) => Promise<FileManagerFilesStorageOperationsTagsResponse[]>;\n}\n\nexport interface FileManagerAliasesStorageOperations {\n storeAliases(file: File): Promise<void>;\n deleteAliases(file: File): Promise<void>;\n}\n\nexport interface FileManagerStorageOperations<TContext = FileManagerContext> {\n beforeInit?: (context: TContext) => Promise<void>;\n files: FileManagerFilesStorageOperations;\n aliases: FileManagerAliasesStorageOperations;\n settings: FileManagerSettingsStorageOperations;\n system: FileManagerSystemStorageOperations;\n}\n"],"mappings":";;;;;AAWA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,MAAA,GAAAT,OAAA;AACAC,MAAA,CAAAC,IAAA,CAAAO,MAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,MAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,MAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -1,3 +0,0 @@
1
- import { RoutePlugin } from "@webiny/handler-aws/gateway";
2
- import { Context } from "@webiny/handler/types";
3
- export declare const createDownloadFilePlugins: () => RoutePlugin<Context>[];
@@ -1,132 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createDownloadFilePlugins = void 0;
9
-
10
- var _s = _interopRequireDefault(require("aws-sdk/clients/s3"));
11
-
12
- var _sanitizeFilename = _interopRequireDefault(require("sanitize-filename"));
13
-
14
- var _path = _interopRequireDefault(require("path"));
15
-
16
- var _utils = require("../utils");
17
-
18
- var _loaders = _interopRequireDefault(require("../transform/loaders"));
19
-
20
- var _gateway = require("@webiny/handler-aws/gateway");
21
-
22
- const MAX_RETURN_CONTENT_LENGTH = 5000000; // ~4.77MB
23
-
24
- const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
25
-
26
- const PRESIGNED_URL_EXPIRATION = 900; // 15 minutes
27
-
28
- /**
29
- * Based on given path, extracts file key and additional options sent via query params.
30
- */
31
-
32
- const extractFilenameOptions = request => {
33
- const path = (0, _sanitizeFilename.default)(request.params.path);
34
- return {
35
- filename: decodeURI(path),
36
- options: request.query,
37
- extension: _path.default.extname(path)
38
- };
39
- };
40
-
41
- const getS3Object = async (request, s3, context) => {
42
- const {
43
- options,
44
- filename,
45
- extension
46
- } = extractFilenameOptions(request);
47
- const params = (0, _utils.getObjectParams)(filename);
48
- const objectHead = await s3.headObject(params).promise();
49
- const contentLength = objectHead.ContentLength ? objectHead.ContentLength : 0;
50
-
51
- for (const loader of _loaders.default) {
52
- const canProcess = loader.canProcess({
53
- context,
54
- s3,
55
- options,
56
- file: {
57
- name: filename,
58
- extension,
59
- contentLength
60
- }
61
- });
62
-
63
- if (!canProcess) {
64
- continue;
65
- }
66
-
67
- return loader.process({
68
- context,
69
- s3,
70
- options,
71
- file: {
72
- name: filename,
73
- extension,
74
- contentLength
75
- }
76
- });
77
- } // If no processors handled the file request, just return the S3 object taking its size into consideration.
78
-
79
-
80
- let object;
81
-
82
- if (contentLength < MAX_RETURN_CONTENT_LENGTH) {
83
- object = await s3.getObject(params).promise();
84
- }
85
-
86
- return {
87
- object,
88
- params
89
- };
90
- };
91
-
92
- const createDownloadFilePlugins = () => {
93
- return [new _gateway.RoutePlugin(({
94
- onGet,
95
- context
96
- }) => {
97
- onGet("/files/:path", async (request, reply) => {
98
- const {
99
- region
100
- } = (0, _utils.getEnvironment)();
101
- const s3 = new _s.default({
102
- region
103
- });
104
- const {
105
- params,
106
- object
107
- } = await getS3Object(request, s3, context); // If there's an "object", it means we can return its body directly.
108
-
109
- if (object) {
110
- return reply.headers({
111
- "Content-Type": object.ContentType,
112
- "Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`,
113
- "x-webiny-base64-encoded": true
114
- }).send(object.Body || "");
115
- }
116
-
117
- const presignedUrl = s3.getSignedUrl("getObject", {
118
- Bucket: params.Bucket,
119
- Key: params.Key,
120
- Expires: PRESIGNED_URL_EXPIRATION
121
- }); // Lambda can return max 6MB of content, so if our object's size is larger, we are sending
122
- // a 301 Redirect, redirecting the user to the public URL of the object in S3.
123
-
124
- return reply.code(301).headers({
125
- Location: presignedUrl,
126
- "Cache-Control": "public, max-age=" + PRESIGNED_URL_EXPIRATION
127
- }).send("");
128
- });
129
- })];
130
- };
131
-
132
- exports.createDownloadFilePlugins = createDownloadFilePlugins;