@webiny/api-file-manager 0.0.0-mt-2 → 0.0.0-unstable.06b2ede40f

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 (270) 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/manage/imageManager.d.ts +14 -0
  168. package/handlers/manage/imageManager.js +75 -0
  169. package/handlers/manage/imageManager.js.map +1 -0
  170. package/handlers/manage/index.d.ts +5 -3
  171. package/handlers/manage/index.js +48 -59
  172. package/handlers/manage/index.js.map +1 -0
  173. package/handlers/{transform/utils.d.ts → manage/legacyUtils.d.ts} +2 -2
  174. package/handlers/{transform/utils.js → manage/legacyUtils.js} +7 -19
  175. package/handlers/manage/legacyUtils.js.map +1 -0
  176. package/handlers/manage/utils.d.ts +12 -0
  177. package/handlers/manage/utils.js +34 -0
  178. package/handlers/manage/utils.js.map +1 -0
  179. package/handlers/types.d.ts +8 -0
  180. package/handlers/types.js +7 -0
  181. package/handlers/types.js.map +1 -0
  182. package/handlers/utils/getEnvironment.js +2 -2
  183. package/handlers/utils/getEnvironment.js.map +1 -0
  184. package/handlers/utils/getObjectParams.d.ts +3 -4
  185. package/handlers/utils/getObjectParams.js +3 -7
  186. package/handlers/utils/getObjectParams.js.map +1 -0
  187. package/handlers/utils/index.d.ts +0 -1
  188. package/handlers/utils/index.js +3 -12
  189. package/handlers/utils/index.js.map +1 -0
  190. package/index.d.ts +10 -0
  191. package/index.js +76 -0
  192. package/index.js.map +1 -0
  193. package/modelModifier/CmsModelModifier.d.ts +26 -0
  194. package/modelModifier/CmsModelModifier.js +62 -0
  195. package/modelModifier/CmsModelModifier.js.map +1 -0
  196. package/package.json +26 -36
  197. package/plugins/FilePhysicalStoragePlugin.d.ts +22 -0
  198. package/plugins/{definitions/FilePhysicalStoragePlugin.js → FilePhysicalStoragePlugin.js} +4 -15
  199. package/plugins/FilePhysicalStoragePlugin.js.map +1 -0
  200. package/plugins/{definitions/FileStorageTransformPlugin.d.ts → FileStorageTransformPlugin.d.ts} +10 -10
  201. package/plugins/{definitions/FileStorageTransformPlugin.js → FileStorageTransformPlugin.js} +4 -16
  202. package/plugins/FileStorageTransformPlugin.js.map +1 -0
  203. package/plugins/index.d.ts +2 -2
  204. package/plugins/index.js +23 -18
  205. package/plugins/index.js.map +1 -0
  206. package/storage/FileStorage.d.ts +34 -0
  207. package/storage/FileStorage.js +90 -0
  208. package/storage/FileStorage.js.map +1 -0
  209. package/types/file.d.ts +49 -0
  210. package/types/file.js +7 -0
  211. package/types/file.js.map +1 -0
  212. package/types/file.lifecycle.d.ts +44 -0
  213. package/types/file.lifecycle.js +7 -0
  214. package/types/file.lifecycle.js.map +1 -0
  215. package/types.d.ts +104 -89
  216. package/types.js +25 -1
  217. package/types.js.map +1 -0
  218. package/handlers/download/index.d.ts +0 -3
  219. package/handlers/download/index.js +0 -125
  220. package/handlers/transform/index.d.ts +0 -3
  221. package/handlers/transform/index.js +0 -96
  222. package/handlers/transform/loaders/imageLoader.d.ts +0 -13
  223. package/handlers/transform/loaders/imageLoader.js +0 -106
  224. package/handlers/transform/loaders/index.d.ts +0 -13
  225. package/handlers/transform/loaders/index.js +0 -13
  226. package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +0 -7
  227. package/handlers/transform/loaders/sanitizeImageTransformations.js +0 -51
  228. package/handlers/transform/managers/imageManager.d.ts +0 -9
  229. package/handlers/transform/managers/imageManager.js +0 -55
  230. package/handlers/transform/managers/index.d.ts +0 -9
  231. package/handlers/transform/managers/index.js +0 -13
  232. package/handlers/transform/optimizeImage.d.ts +0 -2
  233. package/handlers/transform/optimizeImage.js +0 -45
  234. package/handlers/transform/transformImage.d.ts +0 -9
  235. package/handlers/transform/transformImage.js +0 -30
  236. package/handlers/utils/createHandler.d.ts +0 -24
  237. package/handlers/utils/createHandler.js +0 -68
  238. package/plugins/crud/files/validation.d.ts +0 -3
  239. package/plugins/crud/files/validation.js +0 -41
  240. package/plugins/crud/files.crud.d.ts +0 -4
  241. package/plugins/crud/files.crud.js +0 -427
  242. package/plugins/crud/settings.crud.d.ts +0 -5
  243. package/plugins/crud/settings.crud.js +0 -115
  244. package/plugins/crud/system.crud.d.ts +0 -4
  245. package/plugins/crud/system.crud.js +0 -145
  246. package/plugins/crud/utils/checkBasePermissions.d.ts +0 -5
  247. package/plugins/crud/utils/checkBasePermissions.js +0 -33
  248. package/plugins/crud/utils/createFileModel.d.ts +0 -2
  249. package/plugins/crud/utils/createFileModel.js +0 -64
  250. package/plugins/crud/utils/lifecycleEvents.d.ts +0 -6
  251. package/plugins/crud/utils/lifecycleEvents.js +0 -33
  252. package/plugins/definitions/FilePhysicalStoragePlugin.d.ts +0 -22
  253. package/plugins/definitions/FilePlugin.d.ts +0 -133
  254. package/plugins/definitions/FilePlugin.js +0 -64
  255. package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +0 -9
  256. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +0 -17
  257. package/plugins/definitions/InstallationPlugin.d.ts +0 -19
  258. package/plugins/definitions/InstallationPlugin.js +0 -40
  259. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +0 -9
  260. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +0 -17
  261. package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +0 -9
  262. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +0 -17
  263. package/plugins/graphql.d.ts +0 -4
  264. package/plugins/graphql.js +0 -274
  265. package/plugins/storage/FileStorage.d.ts +0 -31
  266. package/plugins/storage/FileStorage.js +0 -95
  267. package/plugins/storage/index.d.ts +0 -4
  268. package/plugins/storage/index.js +0 -22
  269. package/utils.d.ts +0 -4
  270. package/utils.js +0 -16
@@ -0,0 +1,34 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type { FileManagerContext } from "../types";
4
+ import type { FilePhysicalStoragePlugin } from "../plugins/FilePhysicalStoragePlugin";
5
+ export type Result = Record<string, any>;
6
+ export interface FileStorageUploadParams {
7
+ buffer: Buffer;
8
+ hideInFileManager: boolean | string;
9
+ size: number;
10
+ name: string;
11
+ type: string;
12
+ id?: string;
13
+ key?: string;
14
+ tags?: string[];
15
+ keyPrefix?: string;
16
+ }
17
+ export interface FileStorageDeleteParams {
18
+ id: string;
19
+ key: string;
20
+ }
21
+ export interface FileStorageUploadMultipleParams {
22
+ files: FileStorageUploadParams[];
23
+ }
24
+ export interface FileStorageParams {
25
+ context: FileManagerContext;
26
+ }
27
+ export declare class FileStorage {
28
+ private readonly context;
29
+ constructor({ context }: FileStorageParams);
30
+ get storagePlugin(): import("@webiny/plugins/PluginsContainer").WithName<FilePhysicalStoragePlugin<import("../plugins/FilePhysicalStoragePlugin").FilePhysicalStoragePluginUploadParams, import("../plugins/FilePhysicalStoragePlugin").FilePhysicalStoragePluginDeleteParams>>;
31
+ upload(params: FileStorageUploadParams): Promise<Result>;
32
+ uploadFiles({ files }: FileStorageUploadMultipleParams): Promise<import("../types").File[]>;
33
+ delete(params: FileStorageDeleteParams): Promise<boolean>;
34
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.FileStorage = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ const storagePluginType = "api-file-manager-storage";
10
+ class FileStorage {
11
+ constructor({
12
+ context
13
+ }) {
14
+ this.context = context;
15
+ }
16
+ get storagePlugin() {
17
+ const storagePlugin = this.context.plugins.byType(storagePluginType).pop();
18
+ if (!storagePlugin) {
19
+ throw new _error.default(`Missing plugin of type "${storagePluginType}".`, "STORAGE_PLUGIN_ERROR");
20
+ }
21
+ return storagePlugin;
22
+ }
23
+ async upload(params) {
24
+ const settings = await this.context.fileManager.getSettings();
25
+ if (!settings) {
26
+ throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_ERROR");
27
+ }
28
+
29
+ // Add file to cloud storage.
30
+ const {
31
+ file: fileData
32
+ } = await this.storagePlugin.upload({
33
+ ...params,
34
+ settings
35
+ });
36
+
37
+ // Save file in DB.
38
+ return this.context.fileManager.createFile({
39
+ ...fileData,
40
+ meta: {
41
+ private: Boolean(params.hideInFileManager)
42
+ },
43
+ tags: Array.isArray(params.tags) ? params.tags : []
44
+ });
45
+ }
46
+ async uploadFiles({
47
+ files
48
+ }) {
49
+ const settings = await this.context.fileManager.getSettings();
50
+ if (!settings) {
51
+ throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_ERROR");
52
+ }
53
+ const filesData = await Promise.all(files.map(async item => {
54
+ // TODO: improve types of this.storagePlugin.
55
+ const {
56
+ file
57
+ } = await this.storagePlugin.upload({
58
+ ...item,
59
+ settings
60
+ });
61
+ return {
62
+ ...file,
63
+ meta: {
64
+ private: Boolean(item.hideInFileManager)
65
+ },
66
+ tags: Array.isArray(item.tags) ? item.tags : []
67
+ };
68
+ }));
69
+ return this.context.fileManager.createFilesInBatch(filesData);
70
+ }
71
+ async delete(params) {
72
+ const {
73
+ id,
74
+ key
75
+ } = params;
76
+ const {
77
+ fileManager
78
+ } = this.context;
79
+ // Delete file from cloud storage.
80
+ await this.storagePlugin.delete({
81
+ key
82
+ });
83
+
84
+ // Delete file from the DB.
85
+ return await fileManager.deleteFile(id);
86
+ }
87
+ }
88
+ exports.FileStorage = FileStorage;
89
+
90
+ //# sourceMappingURL=FileStorage.js.map
@@ -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,120 +1,128 @@
1
- import { BaseI18NContentContext } from "@webiny/api-i18n-content/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 { ContextInterface } from "@webiny/handler/types";
6
- export interface FileManagerContext extends ContextInterface, SecurityContext, TenancyContext, BaseI18NContentContext {
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;
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>;
51
- tags: [string];
41
+ location?: {
42
+ folderId: string;
43
+ };
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
- cursor: string;
61
+ cursor: string | null;
75
62
  totalCount: number;
63
+ hasMoreItems: boolean;
76
64
  }
77
65
  interface FilesCrudListTagsWhere {
78
66
  tag?: string;
79
67
  tag_contains?: string;
80
68
  tag_in?: string[];
69
+ tag_not_startsWith?: string;
70
+ tag_startsWith?: string;
81
71
  }
82
72
  interface FilesCrudListTagsParams {
83
73
  where?: FilesCrudListTagsWhere;
84
74
  limit?: number;
85
75
  after?: string;
86
76
  }
87
- export interface FilesCRUD {
77
+ export interface ListTagsResponse {
78
+ tag: string;
79
+ count: number;
80
+ }
81
+ export interface FilesCRUD extends FileLifecycleEvents {
88
82
  getFile(id: string): Promise<File>;
89
83
  listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;
90
- listTags(params: FilesCrudListTagsParams): Promise<string[]>;
91
- createFile(data: FileInput): Promise<File>;
84
+ listTags(params: FilesCrudListTagsParams): Promise<ListTagsResponse[]>;
85
+ createFile(data: FileInput, meta?: Record<string, any>): Promise<File>;
92
86
  updateFile(id: string, data: Partial<FileInput>): Promise<File>;
93
87
  deleteFile(id: string): Promise<boolean>;
94
- createFilesInBatch(data: FileInput[]): Promise<File[]>;
88
+ createFilesInBatch(data: FileInput[], meta?: Record<string, any>): Promise<File[]>;
95
89
  }
96
90
  export interface SystemCRUD {
97
- getVersion(): Promise<string>;
91
+ onSystemBeforeInstall: Topic;
92
+ onSystemAfterInstall: Topic;
93
+ getVersion(): Promise<string | null>;
98
94
  setVersion(version: string): Promise<void>;
99
95
  install(args: {
100
96
  srcPrefix: string;
101
97
  }): Promise<boolean>;
102
- upgrade(version: string, data?: Record<string, any>): Promise<boolean>;
103
98
  }
104
99
  export interface FileManagerSettings {
105
- key: string;
100
+ tenant: string;
106
101
  uploadMinFileSize: number;
107
102
  uploadMaxFileSize: number;
108
103
  srcPrefix: string;
109
104
  }
110
105
  export interface FileManagerSystem {
111
106
  version: string;
107
+ tenant: string;
108
+ }
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;
112
118
  }
113
- export declare type SettingsCRUD = {
114
- getSettings(): Promise<FileManagerSettings>;
119
+ export type SettingsCRUD = {
120
+ getSettings(): Promise<FileManagerSettings | null>;
115
121
  createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
116
122
  updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
117
123
  deleteSettings(): Promise<boolean>;
124
+ onSettingsBeforeUpdate: Topic<OnSettingsBeforeUpdateTopicParams>;
125
+ onSettingsAfterUpdate: Topic<OnSettingsAfterUpdateTopicParams>;
118
126
  };
119
127
  /********
120
128
  * Storage operations
@@ -145,6 +153,9 @@ export interface FileManagerSystemStorageOperationsCreateParams {
145
153
  */
146
154
  data: FileManagerSystem;
147
155
  }
156
+ export interface FileManagerSystemStorageOperationsGetParams {
157
+ tenant: string;
158
+ }
148
159
  /**
149
160
  * @category StorageOperations
150
161
  * @category SystemStorageOperations
@@ -153,7 +164,7 @@ export interface FileManagerSystemStorageOperations {
153
164
  /**
154
165
  * Get the FileManager system data.
155
166
  */
156
- get: () => Promise<FileManagerSystem | null>;
167
+ get: (params: FileManagerSystemStorageOperationsGetParams) => Promise<FileManagerSystem | null>;
157
168
  /**
158
169
  * Update the FileManager system data..
159
170
  */
@@ -189,6 +200,12 @@ export interface FileManagerSettingsStorageOperationsCreateParams {
189
200
  */
190
201
  data: FileManagerSettings;
191
202
  }
203
+ export interface FileManagerStorageOperationsGetSettingsParams {
204
+ tenant: string;
205
+ }
206
+ export interface FileManagerStorageOperationsDeleteSettings {
207
+ tenant: string;
208
+ }
192
209
  /**
193
210
  * @category StorageOperations
194
211
  * @category SettingsStorageOperations
@@ -197,7 +214,7 @@ export interface FileManagerSettingsStorageOperations {
197
214
  /**
198
215
  * Get the FileManager system data.
199
216
  */
200
- get: () => Promise<FileManagerSettings | null>;
217
+ get: (params: FileManagerStorageOperationsGetSettingsParams) => Promise<FileManagerSettings | null>;
201
218
  /**
202
219
  * Create the FileManagerSettingsData
203
220
  */
@@ -209,7 +226,7 @@ export interface FileManagerSettingsStorageOperations {
209
226
  /**
210
227
  * Delete the existing settings.
211
228
  */
212
- delete: () => Promise<void>;
229
+ delete: (params: FileManagerStorageOperationsDeleteSettings) => Promise<void>;
213
230
  }
214
231
  /**
215
232
  * @category StorageOperations
@@ -262,20 +279,7 @@ export interface FileManagerFilesStorageOperationsCreateBatchParams {
262
279
  * @category FilesStorageOperationsParams
263
280
  */
264
281
  export interface FileManagerFilesStorageOperationsListParamsWhere {
265
- id?: string;
266
- id_in?: string[];
267
- name?: string;
268
- name_contains?: string;
269
- tag?: string;
270
- tag_contains?: string;
271
- tag_in?: string[];
272
- createdBy?: string;
273
- locale: string;
274
- tenant: string;
275
- private?: boolean;
276
- type?: string;
277
- type_in?: string[];
278
- search?: string;
282
+ [key: string]: any;
279
283
  }
280
284
  /**
281
285
  * @category StorageOperations
@@ -284,28 +288,29 @@ export interface FileManagerFilesStorageOperationsListParamsWhere {
284
288
  */
285
289
  export interface FileManagerFilesStorageOperationsListParams {
286
290
  where: FileManagerFilesStorageOperationsListParamsWhere;
287
- sort: string[];
291
+ sort: CmsEntryListSort;
288
292
  limit: number;
289
293
  after: string | null;
294
+ search?: string;
290
295
  }
291
296
  /**
292
297
  * @category StorageOperations
293
298
  * @category FilesStorageOperations
294
299
  * @category FilesStorageOperationsParams
295
300
  */
296
- interface FileManagerFilesStorageOperationsListResponseMeta {
301
+ export interface FileManagerFilesStorageOperationsListResponseMeta {
297
302
  hasMoreItems: boolean;
298
303
  totalCount: number;
299
- cursor: string;
304
+ cursor: string | null;
300
305
  }
301
- export declare type FileManagerFilesStorageOperationsListResponse = [
306
+ export type FileManagerFilesStorageOperationsListResponse = [
302
307
  File[],
303
308
  FileManagerFilesStorageOperationsListResponseMeta
304
309
  ];
305
- export declare type FileManagerFilesStorageOperationsTagsResponse = [
306
- string[],
307
- FileManagerFilesStorageOperationsListResponseMeta
308
- ];
310
+ export interface FileManagerFilesStorageOperationsTagsResponse {
311
+ tag: string;
312
+ count: number;
313
+ }
309
314
  export interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {
310
315
  locale: string;
311
316
  tenant: string;
@@ -332,11 +337,11 @@ export interface FileManagerFilesStorageOperations {
332
337
  /**
333
338
  * Insert the file data into the database.
334
339
  */
335
- create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File | null>;
340
+ create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;
336
341
  /**
337
342
  * Update the file data in the database.
338
343
  */
339
- update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File | null>;
344
+ update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;
340
345
  /**
341
346
  * Delete the file from the database.
342
347
  */
@@ -352,6 +357,16 @@ export interface FileManagerFilesStorageOperations {
352
357
  /**
353
358
  * Get a list of all file tags filtered by given parameters.
354
359
  */
355
- 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;
356
372
  }
357
- 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 ADDED
@@ -0,0 +1 @@
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 { HandlerPlugin } from "@webiny/handler/types";
2
- declare const _default: () => HandlerPlugin;
3
- export default _default;