@webiny/api-file-manager 0.0.0-mt-2 → 0.0.0-unstable.1145e7667f

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 (156) hide show
  1. package/createFileManager/checkBasePermissions.d.ts +5 -0
  2. package/createFileManager/checkBasePermissions.js +24 -0
  3. package/createFileManager/checkBasePermissions.js.map +1 -0
  4. package/createFileManager/files.crud.d.ts +3 -0
  5. package/createFileManager/files.crud.js +318 -0
  6. package/createFileManager/files.crud.js.map +1 -0
  7. package/createFileManager/filevalidation.disabled.d.ts +0 -0
  8. package/createFileManager/filevalidation.disabled.js +55 -0
  9. package/createFileManager/filevalidation.disabled.js.map +1 -0
  10. package/createFileManager/index.d.ts +13 -0
  11. package/createFileManager/index.js +20 -0
  12. package/createFileManager/index.js.map +1 -0
  13. package/createFileManager/settings.crud.d.ts +3 -0
  14. package/createFileManager/settings.crud.js +91 -0
  15. package/createFileManager/settings.crud.js.map +1 -0
  16. package/createFileManager/system.crud.d.ts +3 -0
  17. package/createFileManager/system.crud.js +86 -0
  18. package/createFileManager/system.crud.js.map +1 -0
  19. package/graphql/index.d.ts +3 -0
  20. package/graphql/index.js +288 -0
  21. package/graphql/index.js.map +1 -0
  22. package/handlers/download/byAlias.d.ts +6 -0
  23. package/handlers/download/byAlias.js +89 -0
  24. package/handlers/download/byAlias.js.map +1 -0
  25. package/handlers/download/byExactKey.d.ts +2 -0
  26. package/handlers/download/byExactKey.js +57 -0
  27. package/handlers/download/byExactKey.js.map +1 -0
  28. package/handlers/download/extractFileInformation.d.ts +9 -0
  29. package/handlers/download/extractFileInformation.js +20 -0
  30. package/handlers/download/extractFileInformation.js.map +1 -0
  31. package/handlers/download/getS3Object.d.ts +10 -0
  32. package/handlers/download/getS3Object.js +57 -0
  33. package/handlers/download/getS3Object.js.map +1 -0
  34. package/handlers/download/index.d.ts +2 -3
  35. package/handlers/download/index.js +20 -118
  36. package/handlers/download/index.js.map +1 -0
  37. package/handlers/manage/index.d.ts +5 -3
  38. package/handlers/manage/index.js +43 -58
  39. package/handlers/manage/index.js.map +1 -0
  40. package/handlers/transform/index.d.ts +2 -3
  41. package/handlers/transform/index.js +71 -78
  42. package/handlers/transform/index.js.map +1 -0
  43. package/handlers/transform/legacyUtils.d.ts +17 -0
  44. package/handlers/transform/legacyUtils.js +42 -0
  45. package/handlers/transform/legacyUtils.js.map +1 -0
  46. package/handlers/transform/loaders/imageLoader.d.ts +26 -9
  47. package/handlers/transform/loaders/imageLoader.js +13 -25
  48. package/handlers/transform/loaders/imageLoader.js.map +1 -0
  49. package/handlers/transform/loaders/index.d.ts +4 -9
  50. package/handlers/transform/loaders/index.js +1 -4
  51. package/handlers/transform/loaders/index.js.map +1 -0
  52. package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +7 -3
  53. package/handlers/transform/loaders/sanitizeImageTransformations.js +24 -30
  54. package/handlers/transform/loaders/sanitizeImageTransformations.js.map +1 -0
  55. package/handlers/transform/managers/imageManager.d.ts +12 -6
  56. package/handlers/transform/managers/imageManager.js +46 -27
  57. package/handlers/transform/managers/imageManager.js.map +1 -0
  58. package/handlers/transform/managers/index.d.ts +2 -6
  59. package/handlers/transform/managers/index.js +1 -4
  60. package/handlers/transform/managers/index.js.map +1 -0
  61. package/handlers/transform/optimizeImage.d.ts +2 -1
  62. package/handlers/transform/optimizeImage.js +4 -7
  63. package/handlers/transform/optimizeImage.js.map +1 -0
  64. package/handlers/transform/transformImage.d.ts +5 -4
  65. package/handlers/transform/transformImage.js +4 -9
  66. package/handlers/transform/transformImage.js.map +1 -0
  67. package/handlers/transform/utils.d.ts +2 -2
  68. package/handlers/transform/utils.js +8 -18
  69. package/handlers/transform/utils.js.map +1 -0
  70. package/handlers/types.d.ts +8 -0
  71. package/handlers/types.js +5 -0
  72. package/handlers/types.js.map +1 -0
  73. package/handlers/utils/getEnvironment.js +0 -2
  74. package/handlers/utils/getEnvironment.js.map +1 -0
  75. package/handlers/utils/getObjectParams.d.ts +3 -4
  76. package/handlers/utils/getObjectParams.js +1 -7
  77. package/handlers/utils/getObjectParams.js.map +1 -0
  78. package/handlers/utils/index.d.ts +0 -1
  79. package/handlers/utils/index.js +1 -12
  80. package/handlers/utils/index.js.map +1 -0
  81. package/index.d.ts +6 -0
  82. package/index.js +68 -0
  83. package/index.js.map +1 -0
  84. package/package.json +29 -30
  85. package/plugins/FilePhysicalStoragePlugin.d.ts +21 -0
  86. package/plugins/FilePhysicalStoragePlugin.js +31 -0
  87. package/plugins/FilePhysicalStoragePlugin.js.map +1 -0
  88. package/plugins/FileStorageTransformPlugin.d.ts +34 -0
  89. package/plugins/FileStorageTransformPlugin.js +40 -0
  90. package/plugins/FileStorageTransformPlugin.js.map +1 -0
  91. package/plugins/crud/files/validation.js +1 -1
  92. package/plugins/crud/files/validation.js.map +1 -0
  93. package/plugins/crud/files.crud.d.ts +1 -1
  94. package/plugins/crud/files.crud.js +48 -44
  95. package/plugins/crud/files.crud.js.map +1 -0
  96. package/plugins/crud/settings.crud.d.ts +1 -1
  97. package/plugins/crud/settings.crud.js +10 -9
  98. package/plugins/crud/settings.crud.js.map +1 -0
  99. package/plugins/crud/system.crud.d.ts +1 -1
  100. package/plugins/crud/system.crud.js +18 -10
  101. package/plugins/crud/system.crud.js.map +1 -0
  102. package/plugins/crud/utils/checkBasePermissions.js +1 -1
  103. package/plugins/crud/utils/checkBasePermissions.js.map +1 -0
  104. package/plugins/crud/utils/createFileModel.d.ts +3 -0
  105. package/plugins/crud/utils/createFileModel.js +13 -0
  106. package/plugins/crud/utils/createFileModel.js.map +1 -0
  107. package/plugins/crud/utils/lifecycleEvents.d.ts +2 -2
  108. package/plugins/crud/utils/lifecycleEvents.js +6 -1
  109. package/plugins/crud/utils/lifecycleEvents.js.map +1 -0
  110. package/plugins/definitions/FilePhysicalStoragePlugin.d.ts +10 -11
  111. package/plugins/definitions/FilePhysicalStoragePlugin.js +1 -1
  112. package/plugins/definitions/FilePhysicalStoragePlugin.js.map +1 -0
  113. package/plugins/definitions/FilePlugin.d.ts +6 -3
  114. package/plugins/definitions/FilePlugin.js +9 -3
  115. package/plugins/definitions/FilePlugin.js.map +1 -0
  116. package/plugins/definitions/FileStorageTransformPlugin.d.ts +9 -9
  117. package/plugins/definitions/FileStorageTransformPlugin.js +1 -1
  118. package/plugins/definitions/FileStorageTransformPlugin.js.map +1 -0
  119. package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +4 -4
  120. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +1 -1
  121. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +1 -0
  122. package/plugins/definitions/InstallationPlugin.d.ts +9 -9
  123. package/plugins/definitions/InstallationPlugin.js +5 -3
  124. package/plugins/definitions/InstallationPlugin.js.map +1 -0
  125. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +4 -4
  126. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +1 -1
  127. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +1 -0
  128. package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +4 -4
  129. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +1 -1
  130. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +1 -0
  131. package/plugins/graphql.js +20 -4
  132. package/plugins/graphql.js.map +1 -0
  133. package/plugins/index.d.ts +2 -2
  134. package/plugins/index.js +22 -19
  135. package/plugins/index.js.map +1 -0
  136. package/plugins/storage/FileStorage.d.ts +23 -24
  137. package/plugins/storage/FileStorage.js +28 -20
  138. package/plugins/storage/FileStorage.js.map +1 -0
  139. package/plugins/storage/index.d.ts +1 -1
  140. package/plugins/storage/index.js +6 -2
  141. package/plugins/storage/index.js.map +1 -0
  142. package/storage/FileStorage.d.ts +32 -0
  143. package/storage/FileStorage.js +86 -0
  144. package/storage/FileStorage.js.map +1 -0
  145. package/types/file.d.ts +33 -0
  146. package/types/file.js +5 -0
  147. package/types/file.js.map +1 -0
  148. package/types/file.lifecycle.d.ts +40 -0
  149. package/types/file.lifecycle.js +5 -0
  150. package/types/file.lifecycle.js.map +1 -0
  151. package/types.d.ts +59 -56
  152. package/types.js +22 -0
  153. package/types.js.map +1 -0
  154. package/utils.js.map +1 -0
  155. package/handlers/utils/createHandler.d.ts +0 -24
  156. package/handlers/utils/createHandler.js +0 -68
@@ -0,0 +1 @@
1
+ {"version":3,"names":["storagePluginType","FileStorage","constructor","context","storagePlugin","plugins","byType","pop","WebinyError","upload","params","settings","fileManager","getSettings","file","fileData","files","createFile","meta","private","Boolean","hideInFileManager","tags","Array","isArray","uploadFiles","promises","item","push","uploadFileResponses","Promise","all","filesData","map","response","createFilesInBatch","delete","id","key","deleteFile"],"sources":["FileStorage.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { FilePhysicalStoragePlugin } from \"~/plugins/definitions/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 tags?: string[];\n size: number;\n name: string;\n keyPrefix: string;\n type: 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 storagePlugin: FilePhysicalStoragePlugin;\n private readonly context: FileManagerContext;\n\n constructor({ context }: FileStorageParams) {\n const storagePlugin = context.plugins\n .byType<FilePhysicalStoragePlugin>(storagePluginType)\n .pop();\n if (!storagePlugin) {\n throw new WebinyError(\n `Missing plugin of type \"${storagePluginType}\".`,\n \"STORAGE_PLUGIN_ERROR\"\n );\n }\n this.storagePlugin = storagePlugin;\n this.context = context;\n }\n\n async upload(params: FileStorageUploadParams): Promise<Result> {\n const settings = await this.context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n // Add file to cloud storage.\n const { file: fileData } = await this.storagePlugin.upload({\n ...params,\n settings\n });\n\n const { fileManager } = this.context;\n\n // Save file in DB.\n return await fileManager.files.createFile({\n ...(fileData as any),\n meta: {\n private: Boolean(params.hideInFileManager)\n },\n tags: Array.isArray(params.tags) ? params.tags : []\n });\n }\n\n async uploadFiles(params: FileStorageUploadMultipleParams) {\n const settings = await this.context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n // Upload files to cloud storage.\n const promises = [];\n for (const item of params.files) {\n promises.push(\n this.storagePlugin.upload({\n ...item,\n settings\n })\n );\n }\n // Wait for all to resolve.\n const uploadFileResponses = await Promise.all(promises);\n\n const filesData = uploadFileResponses.map(response => response.file);\n\n const { fileManager } = this.context;\n // Save files in DB.\n return fileManager.files.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 // Delete file from the DB.\n return await fileManager.files.deleteFile(id);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AACA;;AAKA,MAAMA,iBAAiB,GAAG,0BAA1B;;AAuBO,MAAMC,WAAN,CAAkB;EAIrBC,WAAW,CAAC;IAAEC;EAAF,CAAD,EAAiC;IAAA;IAAA;IACxC,MAAMC,aAAa,GAAGD,OAAO,CAACE,OAAR,CACjBC,MADiB,CACiBN,iBADjB,EAEjBO,GAFiB,EAAtB;;IAGA,IAAI,CAACH,aAAL,EAAoB;MAChB,MAAM,IAAII,cAAJ,CACD,2BAA0BR,iBAAkB,IAD3C,EAEF,sBAFE,CAAN;IAIH;;IACD,KAAKI,aAAL,GAAqBA,aAArB;IACA,KAAKD,OAAL,GAAeA,OAAf;EACH;;EAEW,MAANM,MAAM,CAACC,MAAD,EAAmD;IAC3D,MAAMC,QAAQ,GAAG,MAAM,KAAKR,OAAL,CAAaS,WAAb,CAAyBD,QAAzB,CAAkCE,WAAlC,EAAvB;;IACA,IAAI,CAACF,QAAL,EAAe;MACX,MAAM,IAAIH,cAAJ,CAAgB,gCAAhB,EAAkD,oBAAlD,CAAN;IACH,CAJ0D,CAK3D;;;IACA,MAAM;MAAEM,IAAI,EAAEC;IAAR,IAAqB,MAAM,KAAKX,aAAL,CAAmBK,MAAnB,6DAC1BC,MAD0B;MAE7BC;IAF6B,GAAjC;IAKA,MAAM;MAAEC;IAAF,IAAkB,KAAKT,OAA7B,CAX2D,CAa3D;;IACA,OAAO,MAAMS,WAAW,CAACI,KAAZ,CAAkBC,UAAlB,6DACLF,QADK;MAETG,IAAI,EAAE;QACFC,OAAO,EAAEC,OAAO,CAACV,MAAM,CAACW,iBAAR;MADd,CAFG;MAKTC,IAAI,EAAEC,KAAK,CAACC,OAAN,CAAcd,MAAM,CAACY,IAArB,IAA6BZ,MAAM,CAACY,IAApC,GAA2C;IALxC,GAAb;EAOH;;EAEgB,MAAXG,WAAW,CAACf,MAAD,EAA0C;IACvD,MAAMC,QAAQ,GAAG,MAAM,KAAKR,OAAL,CAAaS,WAAb,CAAyBD,QAAzB,CAAkCE,WAAlC,EAAvB;;IACA,IAAI,CAACF,QAAL,EAAe;MACX,MAAM,IAAIH,cAAJ,CAAgB,gCAAhB,EAAkD,oBAAlD,CAAN;IACH,CAJsD,CAKvD;;;IACA,MAAMkB,QAAQ,GAAG,EAAjB;;IACA,KAAK,MAAMC,IAAX,IAAmBjB,MAAM,CAACM,KAA1B,EAAiC;MAC7BU,QAAQ,CAACE,IAAT,CACI,KAAKxB,aAAL,CAAmBK,MAAnB,6DACOkB,IADP;QAEIhB;MAFJ,GADJ;IAMH,CAdsD,CAevD;;;IACA,MAAMkB,mBAAmB,GAAG,MAAMC,OAAO,CAACC,GAAR,CAAYL,QAAZ,CAAlC;IAEA,MAAMM,SAAS,GAAGH,mBAAmB,CAACI,GAApB,CAAwBC,QAAQ,IAAIA,QAAQ,CAACpB,IAA7C,CAAlB;IAEA,MAAM;MAAEF;IAAF,IAAkB,KAAKT,OAA7B,CApBuD,CAqBvD;;IACA,OAAOS,WAAW,CAACI,KAAZ,CAAkBmB,kBAAlB,CAAqCH,SAArC,CAAP;EACH;;EAEW,MAANI,MAAM,CAAC1B,MAAD,EAAkC;IAC1C,MAAM;MAAE2B,EAAF;MAAMC;IAAN,IAAc5B,MAApB;IACA,MAAM;MAAEE;IAAF,IAAkB,KAAKT,OAA7B,CAF0C,CAG1C;;IACA,MAAM,KAAKC,aAAL,CAAmBgC,MAAnB,CAA0B;MAC5BE;IAD4B,CAA1B,CAAN,CAJ0C,CAO1C;;IACA,OAAO,MAAM1B,WAAW,CAACI,KAAZ,CAAkBuB,UAAlB,CAA6BF,EAA7B,CAAb;EACH;;AA3EoB"}
@@ -1,4 +1,4 @@
1
1
  import { FileManagerContext } from "../../types";
2
- import { ContextPlugin } from "@webiny/handler/plugins/ContextPlugin";
2
+ import { ContextPlugin } from "@webiny/api";
3
3
  declare const fileStorageContextPlugin: ContextPlugin<FileManagerContext>;
4
4
  export default fileStorageContextPlugin;
@@ -5,12 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _ContextPlugin = require("@webiny/handler/plugins/ContextPlugin");
8
+ var _api = require("@webiny/api");
9
9
 
10
10
  var _FileStorage = require("./FileStorage");
11
11
 
12
- const fileStorageContextPlugin = new _ContextPlugin.ContextPlugin(async context => {
12
+ const fileStorageContextPlugin = new _api.ContextPlugin(async context => {
13
13
  if (!context.fileManager) {
14
+ /**
15
+ * We need to define the fileManager initial property as empty object.
16
+ * When casting as FileManagerContext, typescript is complaining.
17
+ */
14
18
  context.fileManager = {};
15
19
  }
16
20
 
@@ -0,0 +1 @@
1
+ {"version":3,"names":["fileStorageContextPlugin","ContextPlugin","context","fileManager","storage","FileStorage"],"sources":["index.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { FileStorage } from \"./FileStorage\";\n\nconst fileStorageContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n if (!context.fileManager) {\n /**\n * We need to define the fileManager initial property as empty object.\n * When casting as FileManagerContext, typescript is complaining.\n */\n context.fileManager = {} as any;\n }\n context.fileManager.storage = new FileStorage({\n context\n });\n});\n\nexport default fileStorageContextPlugin;\n"],"mappings":";;;;;;;AACA;;AACA;;AAEA,MAAMA,wBAAwB,GAAG,IAAIC,kBAAJ,CAAsC,MAAMC,OAAN,IAAiB;EACpF,IAAI,CAACA,OAAO,CAACC,WAAb,EAA0B;IACtB;AACR;AACA;AACA;IACQD,OAAO,CAACC,WAAR,GAAsB,EAAtB;EACH;;EACDD,OAAO,CAACC,WAAR,CAAoBC,OAApB,GAA8B,IAAIC,wBAAJ,CAAgB;IAC1CH;EAD0C,CAAhB,CAA9B;AAGH,CAXgC,CAAjC;eAaeF,wB"}
@@ -0,0 +1,32 @@
1
+ /// <reference types="node" />
2
+ import { FileManagerContext } from "../types";
3
+ export declare type Result = Record<string, any>;
4
+ export interface FileStorageUploadParams {
5
+ buffer: Buffer;
6
+ hideInFileManager: boolean | string;
7
+ size: number;
8
+ name: string;
9
+ type: string;
10
+ id?: string;
11
+ key?: string;
12
+ tags?: string[];
13
+ keyPrefix?: string;
14
+ }
15
+ export interface FileStorageDeleteParams {
16
+ id: string;
17
+ key: string;
18
+ }
19
+ export interface FileStorageUploadMultipleParams {
20
+ files: FileStorageUploadParams[];
21
+ }
22
+ export interface FileStorageParams {
23
+ context: FileManagerContext;
24
+ }
25
+ export declare class FileStorage {
26
+ private readonly storagePlugin;
27
+ private readonly context;
28
+ constructor({ context }: FileStorageParams);
29
+ upload(params: FileStorageUploadParams): Promise<Result>;
30
+ uploadFiles({ files }: FileStorageUploadMultipleParams): Promise<import("../types").File[]>;
31
+ delete(params: FileStorageDeleteParams): Promise<boolean>;
32
+ }
@@ -0,0 +1,86 @@
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 _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+ const storagePluginType = "api-file-manager-storage";
12
+ class FileStorage {
13
+ constructor({
14
+ context
15
+ }) {
16
+ (0, _defineProperty2.default)(this, "storagePlugin", void 0);
17
+ (0, _defineProperty2.default)(this, "context", void 0);
18
+ const storagePlugin = context.plugins.byType(storagePluginType).pop();
19
+ if (!storagePlugin) {
20
+ throw new _error.default(`Missing plugin of type "${storagePluginType}".`, "STORAGE_PLUGIN_ERROR");
21
+ }
22
+ this.storagePlugin = storagePlugin;
23
+ this.context = context;
24
+ }
25
+ async upload(params) {
26
+ const settings = await this.context.fileManager.getSettings();
27
+ if (!settings) {
28
+ throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_ERROR");
29
+ }
30
+
31
+ // Add file to cloud storage.
32
+ const {
33
+ file: fileData
34
+ } = await this.storagePlugin.upload((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
35
+ settings
36
+ }));
37
+
38
+ // Save file in DB.
39
+ return this.context.fileManager.createFile((0, _objectSpread2.default)((0, _objectSpread2.default)({}, 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((0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
58
+ settings
59
+ }));
60
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, file), {}, {
61
+ meta: {
62
+ private: Boolean(item.hideInFileManager)
63
+ },
64
+ tags: Array.isArray(item.tags) ? item.tags : []
65
+ });
66
+ }));
67
+ return this.context.fileManager.createFilesInBatch(filesData);
68
+ }
69
+ async delete(params) {
70
+ const {
71
+ id,
72
+ key
73
+ } = params;
74
+ const {
75
+ fileManager
76
+ } = this.context;
77
+ // Delete file from cloud storage.
78
+ await this.storagePlugin.delete({
79
+ key
80
+ });
81
+
82
+ // Delete file from the DB.
83
+ return await fileManager.deleteFile(id);
84
+ }
85
+ }
86
+ exports.FileStorage = FileStorage;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["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"],"sources":["FileStorage.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { 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 storagePlugin: FilePhysicalStoragePlugin;\n private readonly context: FileManagerContext;\n\n constructor({ context }: FileStorageParams) {\n const storagePlugin = 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 this.storagePlugin = storagePlugin;\n this.context = context;\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 as any),\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;AAKA,MAAMA,iBAAiB,GAAG,0BAA0B;AAyB7C,MAAMC,WAAW,CAAC;EAIrBC,WAAW,CAAC;IAAEC;EAA2B,CAAC,EAAE;IAAA;IAAA;IACxC,MAAMC,aAAa,GAAGD,OAAO,CAACE,OAAO,CAChCC,MAAM,CAA4BN,iBAAiB,CAAC,CACpDO,GAAG,EAAE;IAEV,IAAI,CAACH,aAAa,EAAE;MAChB,MAAM,IAAII,cAAW,CAChB,2BAA0BR,iBAAkB,IAAG,EAChD,sBAAsB,CACzB;IACL;IACA,IAAI,CAACI,aAAa,GAAGA,aAAa;IAClC,IAAI,CAACD,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMM,MAAM,CAACC,MAA+B,EAAmB;IAC3D,MAAMC,QAAQ,GAAG,MAAM,IAAI,CAACR,OAAO,CAACS,WAAW,CAACC,WAAW,EAAE;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,6DACnDC,MAAM;MACTC;IAAQ,GACV;;IAEF;IACA,OAAO,IAAI,CAACR,OAAO,CAACS,WAAW,CAACI,UAAU,6DAClCD,QAAQ;MACZE,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;IAAE,GACrD;EACN;EAEA,MAAMG,WAAW,CAAC;IAAEC;EAAuC,CAAC,EAAE;IAC1D,MAAMd,QAAQ,GAAG,MAAM,IAAI,CAACR,OAAO,CAACS,WAAW,CAACC,WAAW,EAAE;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,6DACzCqB,IAAI;QACPnB;MAAQ,GACV;MAEF,mEACOG,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;MAAE;IAEvD,CAAC,CAAC,CACL;IAED,OAAO,IAAI,CAAClB,OAAO,CAACS,WAAW,CAACmB,kBAAkB,CAACL,SAAS,CAAC;EACjE;EAEA,MAAMM,MAAM,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;AAAC"}
@@ -0,0 +1,33 @@
1
+ export interface File {
2
+ id: string;
3
+ key: string;
4
+ size: number;
5
+ type: string;
6
+ name: string;
7
+ meta: Record<string, any>;
8
+ tags: string[];
9
+ aliases: string[];
10
+ createdOn: string;
11
+ createdBy: CreatedBy;
12
+ /**
13
+ * Added with new storage operations refactoring.
14
+ */
15
+ tenant: string;
16
+ locale: string;
17
+ webinyVersion: string;
18
+ /**
19
+ * User can add new fields to the File object so we must allow it in the types.
20
+ */
21
+ [key: string]: any;
22
+ }
23
+ export interface FileAlias {
24
+ tenant: string;
25
+ locale: string;
26
+ fileId: string;
27
+ alias: string;
28
+ }
29
+ export interface CreatedBy {
30
+ id: string;
31
+ displayName: string | null;
32
+ type: string;
33
+ }
package/types/file.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["file.ts"],"sourcesContent":["export 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 aliases: 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 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":""}
@@ -0,0 +1,40 @@
1
+ import { Topic } from "@webiny/pubsub/types";
2
+ import { File } from "./file";
3
+ export interface OnFileBeforeCreateTopicParams<TFile extends File = File> {
4
+ file: TFile;
5
+ }
6
+ export interface OnFileAfterCreateTopicParams<TFile extends File = File> {
7
+ file: TFile;
8
+ }
9
+ export interface OnFileBeforeBatchCreateTopicParams<TFile extends File = File> {
10
+ files: TFile[];
11
+ }
12
+ export interface OnFileAfterBatchCreateTopicParams<TFile extends File = File> {
13
+ files: TFile[];
14
+ }
15
+ export interface OnFileBeforeUpdateTopicParams<TFile extends File = File> {
16
+ original: TFile;
17
+ file: TFile;
18
+ input: Record<string, any>;
19
+ }
20
+ export interface OnFileAfterUpdateTopicParams<TFile extends File = File> {
21
+ original: TFile;
22
+ file: TFile;
23
+ input: Record<string, any>;
24
+ }
25
+ export interface OnFileBeforeDeleteTopicParams<TFile extends File = File> {
26
+ file: TFile;
27
+ }
28
+ export interface OnFileAfterDeleteTopicParams<TFile extends File = File> {
29
+ file: TFile;
30
+ }
31
+ export interface FileLifecycleEvents {
32
+ onFileBeforeCreate: Topic<OnFileBeforeCreateTopicParams>;
33
+ onFileAfterCreate: Topic<OnFileAfterCreateTopicParams>;
34
+ onFileBeforeBatchCreate: Topic<OnFileBeforeBatchCreateTopicParams>;
35
+ onFileAfterBatchCreate: Topic<OnFileAfterBatchCreateTopicParams>;
36
+ onFileBeforeUpdate: Topic<OnFileBeforeUpdateTopicParams>;
37
+ onFileAfterUpdate: Topic<OnFileAfterUpdateTopicParams>;
38
+ onFileBeforeDelete: Topic<OnFileBeforeDeleteTopicParams>;
39
+ onFileAfterDelete: Topic<OnFileAfterDeleteTopicParams>;
40
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["file.lifecycle.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { File } from \"./file\";\n\nexport interface OnFileBeforeCreateTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface OnFileAfterCreateTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface OnFileBeforeBatchCreateTopicParams<TFile extends File = File> {\n files: TFile[];\n}\n\nexport interface OnFileAfterBatchCreateTopicParams<TFile extends File = File> {\n files: TFile[];\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":""}
package/types.d.ts CHANGED
@@ -1,54 +1,33 @@
1
- import { BaseI18NContentContext } from "@webiny/api-i18n-content/types";
2
- import { FileStorage } from "./plugins/storage/FileStorage";
1
+ import { I18NContext } from "@webiny/api-i18n/types";
2
+ import { FileStorage } from "./storage/FileStorage";
3
3
  import { TenancyContext } from "@webiny/api-tenancy/types";
4
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
- };
5
+ import { Context } from "@webiny/api/types";
6
+ import { FileLifecycleEvents } from "./types/file.lifecycle";
7
+ import { File } from "./types/file";
8
+ import { Topic } from "@webiny/pubsub/types";
9
+ export * from "./types/file.lifecycle";
10
+ export * from "./types/file";
11
+ export interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {
12
+ storage: FileStorage;
13
+ }
14
+ export interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {
15
+ fileManager: FileManagerContextObject;
13
16
  }
14
17
  export interface FilePermission extends SecurityPermission {
15
18
  name: "fm.file";
16
19
  rwd?: string;
17
20
  own?: boolean;
18
21
  }
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;
44
- }
45
22
  export interface FileInput {
23
+ id: string;
46
24
  key: string;
47
25
  name: string;
48
26
  size: number;
49
27
  type: string;
50
28
  meta: Record<string, any>;
51
- tags: [string];
29
+ tags: string[];
30
+ aliases: string[];
52
31
  }
53
32
  export interface FileListWhereParams {
54
33
  search?: string;
@@ -71,37 +50,46 @@ export interface FilesListOpts {
71
50
  sort?: string[];
72
51
  }
73
52
  export interface FileListMeta {
74
- cursor: string;
53
+ cursor: string | null;
75
54
  totalCount: number;
55
+ hasMoreItems: boolean;
76
56
  }
77
57
  interface FilesCrudListTagsWhere {
78
58
  tag?: string;
79
59
  tag_contains?: string;
80
60
  tag_in?: string[];
61
+ tag_not_startsWith?: string;
62
+ tag_startsWith?: string;
81
63
  }
82
64
  interface FilesCrudListTagsParams {
83
65
  where?: FilesCrudListTagsWhere;
84
66
  limit?: number;
85
67
  after?: string;
86
68
  }
87
- export interface FilesCRUD {
69
+ export interface ListTagsResponse {
70
+ tag: string;
71
+ count: number;
72
+ }
73
+ export interface FilesCRUD extends FileLifecycleEvents {
88
74
  getFile(id: string): Promise<File>;
89
75
  listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;
90
- listTags(params: FilesCrudListTagsParams): Promise<string[]>;
76
+ listTags(params: FilesCrudListTagsParams): Promise<ListTagsResponse[]>;
91
77
  createFile(data: FileInput): Promise<File>;
92
78
  updateFile(id: string, data: Partial<FileInput>): Promise<File>;
93
79
  deleteFile(id: string): Promise<boolean>;
94
80
  createFilesInBatch(data: FileInput[]): Promise<File[]>;
95
81
  }
96
82
  export interface SystemCRUD {
97
- getVersion(): Promise<string>;
83
+ onSystemBeforeInstall: Topic;
84
+ onSystemAfterInstall: Topic;
85
+ getVersion(): Promise<string | null>;
98
86
  setVersion(version: string): Promise<void>;
99
87
  install(args: {
100
88
  srcPrefix: string;
101
89
  }): Promise<boolean>;
102
- upgrade(version: string, data?: Record<string, any>): Promise<boolean>;
103
90
  }
104
91
  export interface FileManagerSettings {
92
+ tenant: string;
105
93
  key: string;
106
94
  uploadMinFileSize: number;
107
95
  uploadMaxFileSize: number;
@@ -109,9 +97,10 @@ export interface FileManagerSettings {
109
97
  }
110
98
  export interface FileManagerSystem {
111
99
  version: string;
100
+ tenant: string;
112
101
  }
113
102
  export declare type SettingsCRUD = {
114
- getSettings(): Promise<FileManagerSettings>;
103
+ getSettings(): Promise<FileManagerSettings | null>;
115
104
  createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
116
105
  updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
117
106
  deleteSettings(): Promise<boolean>;
@@ -145,6 +134,9 @@ export interface FileManagerSystemStorageOperationsCreateParams {
145
134
  */
146
135
  data: FileManagerSystem;
147
136
  }
137
+ export interface FileManagerSystemStorageOperationsGetParams {
138
+ tenant: string;
139
+ }
148
140
  /**
149
141
  * @category StorageOperations
150
142
  * @category SystemStorageOperations
@@ -153,7 +145,7 @@ export interface FileManagerSystemStorageOperations {
153
145
  /**
154
146
  * Get the FileManager system data.
155
147
  */
156
- get: () => Promise<FileManagerSystem | null>;
148
+ get: (params: FileManagerSystemStorageOperationsGetParams) => Promise<FileManagerSystem | null>;
157
149
  /**
158
150
  * Update the FileManager system data..
159
151
  */
@@ -189,6 +181,12 @@ export interface FileManagerSettingsStorageOperationsCreateParams {
189
181
  */
190
182
  data: FileManagerSettings;
191
183
  }
184
+ export interface FileManagerStorageOperationsGetSettingsParams {
185
+ tenant: string;
186
+ }
187
+ export interface FileManagerStorageOperationsDeleteSettings {
188
+ tenant: string;
189
+ }
192
190
  /**
193
191
  * @category StorageOperations
194
192
  * @category SettingsStorageOperations
@@ -197,7 +195,7 @@ export interface FileManagerSettingsStorageOperations {
197
195
  /**
198
196
  * Get the FileManager system data.
199
197
  */
200
- get: () => Promise<FileManagerSettings | null>;
198
+ get: (params: FileManagerStorageOperationsGetSettingsParams) => Promise<FileManagerSettings | null>;
201
199
  /**
202
200
  * Create the FileManagerSettingsData
203
201
  */
@@ -209,7 +207,7 @@ export interface FileManagerSettingsStorageOperations {
209
207
  /**
210
208
  * Delete the existing settings.
211
209
  */
212
- delete: () => Promise<void>;
210
+ delete: (params: FileManagerStorageOperationsDeleteSettings) => Promise<void>;
213
211
  }
214
212
  /**
215
213
  * @category StorageOperations
@@ -293,19 +291,19 @@ export interface FileManagerFilesStorageOperationsListParams {
293
291
  * @category FilesStorageOperations
294
292
  * @category FilesStorageOperationsParams
295
293
  */
296
- interface FileManagerFilesStorageOperationsListResponseMeta {
294
+ export interface FileManagerFilesStorageOperationsListResponseMeta {
297
295
  hasMoreItems: boolean;
298
296
  totalCount: number;
299
- cursor: string;
297
+ cursor: string | null;
300
298
  }
301
299
  export declare type FileManagerFilesStorageOperationsListResponse = [
302
300
  File[],
303
301
  FileManagerFilesStorageOperationsListResponseMeta
304
302
  ];
305
- export declare type FileManagerFilesStorageOperationsTagsResponse = [
306
- string[],
307
- FileManagerFilesStorageOperationsListResponseMeta
308
- ];
303
+ export interface FileManagerFilesStorageOperationsTagsResponse {
304
+ tag: string;
305
+ count: number;
306
+ }
309
307
  export interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {
310
308
  locale: string;
311
309
  tenant: string;
@@ -332,11 +330,11 @@ export interface FileManagerFilesStorageOperations {
332
330
  /**
333
331
  * Insert the file data into the database.
334
332
  */
335
- create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File | null>;
333
+ create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;
336
334
  /**
337
335
  * Update the file data in the database.
338
336
  */
339
- update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File | null>;
337
+ update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;
340
338
  /**
341
339
  * Delete the file from the database.
342
340
  */
@@ -352,6 +350,11 @@ export interface FileManagerFilesStorageOperations {
352
350
  /**
353
351
  * Get a list of all file tags filtered by given parameters.
354
352
  */
355
- tags: (params: FileManagerFilesStorageOperationsTagsParams) => Promise<FileManagerFilesStorageOperationsTagsResponse>;
353
+ tags: (params: FileManagerFilesStorageOperationsTagsParams) => Promise<FileManagerFilesStorageOperationsTagsResponse[]>;
354
+ }
355
+ export interface FileManagerStorageOperations<TContext = FileManagerContext> {
356
+ beforeInit?: (context: TContext) => Promise<void>;
357
+ files: FileManagerFilesStorageOperations;
358
+ settings: FileManagerSettingsStorageOperations;
359
+ system: FileManagerSystemStorageOperations;
356
360
  }
357
- export {};
package/types.js CHANGED
@@ -2,4 +2,26 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
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
+ });
5
27
  });
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { I18NContext } from \"@webiny/api-i18n/types\";\nimport { FileStorage } from \"./storage/FileStorage\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { SecurityContext, SecurityPermission } from \"@webiny/api-security/types\";\nimport { Context } from \"@webiny/api/types\";\nimport { FileLifecycleEvents } from \"./types/file.lifecycle\";\nimport { File } from \"./types/file\";\nimport { Topic } from \"@webiny/pubsub/types\";\nexport * from \"./types/file.lifecycle\";\nexport * from \"./types/file\";\n\nexport interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {\n storage: FileStorage;\n}\n\nexport interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {\n fileManager: FileManagerContextObject;\n}\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n\nexport interface FileInput {\n id: string;\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n tags: string[];\n aliases: 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 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): 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 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 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\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 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 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 FileManagerStorageOperations<TContext = FileManagerContext> {\n beforeInit?: (context: TContext) => Promise<void>;\n files: FileManagerFilesStorageOperations;\n settings: FileManagerSettingsStorageOperations;\n system: FileManagerSystemStorageOperations;\n}\n"],"mappings":";;;;;AAQA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
package/utils.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["executeCallbacks","plugins","hook","args","plugin"],"sources":["utils.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/types\";\n\ntype CallbackFallback = (args: any) => void | Promise<void>;\n\nexport const executeCallbacks = async <\n TCallbackFunction extends CallbackFallback = CallbackFallback\n>(\n plugins: Plugin[],\n hook: string,\n args: Parameters<TCallbackFunction>[0]\n) => {\n for (const plugin of plugins) {\n if (typeof plugin[hook] === \"function\") {\n await plugin[hook](args);\n }\n }\n};\n"],"mappings":";;;;;;;AAIO,MAAMA,gBAAgB,GAAG,OAG5BC,OAH4B,EAI5BC,IAJ4B,EAK5BC,IAL4B,KAM3B;EACD,KAAK,MAAMC,MAAX,IAAqBH,OAArB,EAA8B;IAC1B,IAAI,OAAOG,MAAM,CAACF,IAAD,CAAb,KAAwB,UAA5B,EAAwC;MACpC,MAAME,MAAM,CAACF,IAAD,CAAN,CAAaC,IAAb,CAAN;IACH;EACJ;AACJ,CAZM"}
@@ -1,24 +0,0 @@
1
- declare const _default: (handler: any) => (event: any) => Promise<{
2
- body: string;
3
- statusCode: number;
4
- headers: {
5
- "Cache-Control": string;
6
- "Access-Control-Allow-Origin": string;
7
- "Access-Control-Allow-Credentials": boolean;
8
- };
9
- isBase64Encoded?: undefined;
10
- } | {
11
- isBase64Encoded: boolean;
12
- statusCode: any;
13
- headers: any;
14
- body: any;
15
- } | {
16
- statusCode: number;
17
- headers: {
18
- "Access-Control-Allow-Origin": string;
19
- "Access-Control-Allow-Credentials": boolean;
20
- };
21
- body: string;
22
- isBase64Encoded?: undefined;
23
- }>;
24
- export default _default;