@webiny/api-file-manager 0.0.0-unstable.97a151f74d → 0.0.0-unstable.99666aeb00

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 (181) hide show
  1. package/FileManagerContextSetup.d.ts +13 -0
  2. package/FileManagerContextSetup.js +113 -0
  3. package/FileManagerContextSetup.js.map +1 -0
  4. package/cmsFileStorage/CmsFilesStorage.d.ts +27 -0
  5. package/cmsFileStorage/CmsFilesStorage.js +173 -0
  6. package/cmsFileStorage/CmsFilesStorage.js.map +1 -0
  7. package/cmsFileStorage/ListFilesWhereProcessor.d.ts +7 -0
  8. package/cmsFileStorage/ListFilesWhereProcessor.js +35 -0
  9. package/cmsFileStorage/ListFilesWhereProcessor.js.map +1 -0
  10. package/cmsFileStorage/ListTagsWhereProcessor.d.ts +7 -0
  11. package/cmsFileStorage/ListTagsWhereProcessor.js +35 -0
  12. package/cmsFileStorage/ListTagsWhereProcessor.js.map +1 -0
  13. package/cmsFileStorage/createFileManagerPlugins.d.ts +5 -0
  14. package/cmsFileStorage/createFileManagerPlugins.js +34 -0
  15. package/cmsFileStorage/createFileManagerPlugins.js.map +1 -0
  16. package/cmsFileStorage/createModelField.d.ts +5 -0
  17. package/cmsFileStorage/createModelField.js +37 -0
  18. package/cmsFileStorage/createModelField.js.map +1 -0
  19. package/cmsFileStorage/file.model.d.ts +4 -0
  20. package/cmsFileStorage/file.model.js +118 -0
  21. package/cmsFileStorage/file.model.js.map +1 -0
  22. package/cmsFileStorage/isInstallationPending.d.ts +4 -0
  23. package/cmsFileStorage/isInstallationPending.js +21 -0
  24. package/cmsFileStorage/isInstallationPending.js.map +1 -0
  25. package/contants.d.ts +1 -0
  26. package/contants.js +8 -0
  27. package/contants.js.map +1 -0
  28. package/createFileManager/files.crud.d.ts +3 -0
  29. package/createFileManager/files.crud.js +300 -0
  30. package/createFileManager/files.crud.js.map +1 -0
  31. package/createFileManager/filevalidation.disabled.d.ts +0 -0
  32. package/createFileManager/filevalidation.disabled.js +55 -0
  33. package/createFileManager/filevalidation.disabled.js.map +1 -0
  34. package/createFileManager/index.d.ts +15 -0
  35. package/createFileManager/index.js +20 -0
  36. package/createFileManager/index.js.map +1 -0
  37. package/createFileManager/permissions/FilesPermissions.d.ts +4 -0
  38. package/createFileManager/permissions/FilesPermissions.js +9 -0
  39. package/createFileManager/permissions/FilesPermissions.js.map +1 -0
  40. package/createFileManager/settings.crud.d.ts +3 -0
  41. package/{plugins/crud → createFileManager}/settings.crud.js +27 -52
  42. package/createFileManager/settings.crud.js.map +1 -0
  43. package/createFileManager/system.crud.d.ts +3 -0
  44. package/createFileManager/system.crud.js +86 -0
  45. package/createFileManager/system.crud.js.map +1 -0
  46. package/graphql/baseSchema.d.ts +3 -0
  47. package/graphql/baseSchema.js +117 -0
  48. package/graphql/baseSchema.js.map +1 -0
  49. package/graphql/createFilesTypeDefs.d.ts +7 -0
  50. package/graphql/createFilesTypeDefs.js +162 -0
  51. package/graphql/createFilesTypeDefs.js.map +1 -0
  52. package/graphql/filesSchema.d.ts +4 -0
  53. package/graphql/filesSchema.js +83 -0
  54. package/graphql/filesSchema.js.map +1 -0
  55. package/graphql/index.d.ts +3 -0
  56. package/graphql/index.js +33 -0
  57. package/graphql/index.js.map +1 -0
  58. package/graphql/utils.d.ts +11 -0
  59. package/graphql/utils.js +22 -0
  60. package/graphql/utils.js.map +1 -0
  61. package/handlers/download/byAlias.d.ts +6 -0
  62. package/handlers/download/byAlias.js +89 -0
  63. package/handlers/download/byAlias.js.map +1 -0
  64. package/handlers/download/byExactKey.d.ts +2 -0
  65. package/handlers/download/byExactKey.js +57 -0
  66. package/handlers/download/byExactKey.js.map +1 -0
  67. package/handlers/download/extractFileInformation.d.ts +9 -0
  68. package/handlers/download/extractFileInformation.js +20 -0
  69. package/handlers/download/extractFileInformation.js.map +1 -0
  70. package/handlers/download/getS3Object.d.ts +12 -0
  71. package/handlers/download/getS3Object.js +72 -0
  72. package/handlers/download/getS3Object.js.map +1 -0
  73. package/handlers/download/index.d.ts +2 -3
  74. package/handlers/download/index.js +21 -126
  75. package/handlers/download/index.js.map +1 -1
  76. package/handlers/manage/index.js +0 -16
  77. package/handlers/manage/index.js.map +1 -1
  78. package/handlers/transform/index.js +24 -23
  79. package/handlers/transform/index.js.map +1 -1
  80. package/handlers/transform/legacyUtils.d.ts +17 -0
  81. package/handlers/transform/legacyUtils.js +42 -0
  82. package/handlers/transform/legacyUtils.js.map +1 -0
  83. package/handlers/transform/loaders/imageLoader.d.ts +1 -1
  84. package/handlers/transform/loaders/imageLoader.js +12 -23
  85. package/handlers/transform/loaders/imageLoader.js.map +1 -1
  86. package/handlers/transform/loaders/index.d.ts +1 -1
  87. package/handlers/transform/loaders/index.js +0 -3
  88. package/handlers/transform/loaders/index.js.map +1 -1
  89. package/handlers/transform/loaders/sanitizeImageTransformations.js +0 -13
  90. package/handlers/transform/loaders/sanitizeImageTransformations.js.map +1 -1
  91. package/handlers/transform/managers/imageManager.js +32 -21
  92. package/handlers/transform/managers/imageManager.js.map +1 -1
  93. package/handlers/transform/managers/index.js +0 -3
  94. package/handlers/transform/managers/index.js.map +1 -1
  95. package/handlers/transform/optimizeImage.js +0 -6
  96. package/handlers/transform/optimizeImage.js.map +1 -1
  97. package/handlers/transform/transformImage.d.ts +5 -2
  98. package/handlers/transform/transformImage.js +6 -8
  99. package/handlers/transform/transformImage.js.map +1 -1
  100. package/handlers/transform/utils.d.ts +1 -1
  101. package/handlers/transform/utils.js +9 -19
  102. package/handlers/transform/utils.js.map +1 -1
  103. package/handlers/utils/getEnvironment.js +0 -2
  104. package/handlers/utils/getEnvironment.js.map +1 -1
  105. package/handlers/utils/getObjectParams.js +0 -4
  106. package/handlers/utils/getObjectParams.js.map +1 -1
  107. package/handlers/utils/index.js +0 -3
  108. package/handlers/utils/index.js.map +1 -1
  109. package/index.d.ts +7 -0
  110. package/index.js +52 -0
  111. package/index.js.map +1 -0
  112. package/modelModifier/CmsModelModifier.d.ts +24 -0
  113. package/modelModifier/CmsModelModifier.js +59 -0
  114. package/modelModifier/CmsModelModifier.js.map +1 -0
  115. package/package.json +31 -32
  116. package/plugins/{definitions/FilePhysicalStoragePlugin.d.ts → FilePhysicalStoragePlugin.d.ts} +1 -1
  117. package/plugins/{definitions/FilePhysicalStoragePlugin.js → FilePhysicalStoragePlugin.js} +0 -11
  118. package/plugins/{definitions/FilePhysicalStoragePlugin.js.map → FilePhysicalStoragePlugin.js.map} +1 -1
  119. package/plugins/{definitions/FileStorageTransformPlugin.d.ts → FileStorageTransformPlugin.d.ts} +1 -1
  120. package/plugins/{definitions/FileStorageTransformPlugin.js → FileStorageTransformPlugin.js} +1 -12
  121. package/plugins/{definitions/FileStorageTransformPlugin.js.map → FileStorageTransformPlugin.js.map} +1 -1
  122. package/plugins/index.d.ts +2 -2
  123. package/plugins/index.js +22 -19
  124. package/plugins/index.js.map +1 -1
  125. package/{plugins/storage → storage}/FileStorage.d.ts +6 -4
  126. package/{plugins/storage → storage}/FileStorage.js +29 -46
  127. package/storage/FileStorage.js.map +1 -0
  128. package/types/file.d.ts +37 -0
  129. package/types/file.js +5 -0
  130. package/types/file.js.map +1 -0
  131. package/types/file.lifecycle.d.ts +44 -0
  132. package/types/file.lifecycle.js +5 -0
  133. package/types/file.lifecycle.js.map +1 -0
  134. package/types.d.ts +62 -73
  135. package/types.js +22 -0
  136. package/types.js.map +1 -1
  137. package/plugins/crud/files/validation.d.ts +0 -3
  138. package/plugins/crud/files/validation.js +0 -41
  139. package/plugins/crud/files/validation.js.map +0 -1
  140. package/plugins/crud/files.crud.d.ts +0 -4
  141. package/plugins/crud/files.crud.js +0 -431
  142. package/plugins/crud/files.crud.js.map +0 -1
  143. package/plugins/crud/settings.crud.d.ts +0 -5
  144. package/plugins/crud/settings.crud.js.map +0 -1
  145. package/plugins/crud/system.crud.d.ts +0 -4
  146. package/plugins/crud/system.crud.js +0 -153
  147. package/plugins/crud/system.crud.js.map +0 -1
  148. package/plugins/crud/utils/checkBasePermissions.d.ts +0 -5
  149. package/plugins/crud/utils/checkBasePermissions.js +0 -33
  150. package/plugins/crud/utils/checkBasePermissions.js.map +0 -1
  151. package/plugins/crud/utils/createFileModel.d.ts +0 -5
  152. package/plugins/crud/utils/createFileModel.js +0 -77
  153. package/plugins/crud/utils/createFileModel.js.map +0 -1
  154. package/plugins/crud/utils/lifecycleEvents.d.ts +0 -6
  155. package/plugins/crud/utils/lifecycleEvents.js +0 -38
  156. package/plugins/crud/utils/lifecycleEvents.js.map +0 -1
  157. package/plugins/definitions/FilePlugin.d.ts +0 -136
  158. package/plugins/definitions/FilePlugin.js +0 -70
  159. package/plugins/definitions/FilePlugin.js.map +0 -1
  160. package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +0 -9
  161. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +0 -17
  162. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +0 -1
  163. package/plugins/definitions/InstallationPlugin.d.ts +0 -19
  164. package/plugins/definitions/InstallationPlugin.js +0 -42
  165. package/plugins/definitions/InstallationPlugin.js.map +0 -1
  166. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +0 -9
  167. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +0 -17
  168. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +0 -1
  169. package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +0 -9
  170. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +0 -17
  171. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +0 -1
  172. package/plugins/graphql.d.ts +0 -4
  173. package/plugins/graphql.js +0 -290
  174. package/plugins/graphql.js.map +0 -1
  175. package/plugins/storage/FileStorage.js.map +0 -1
  176. package/plugins/storage/index.d.ts +0 -4
  177. package/plugins/storage/index.js +0 -26
  178. package/plugins/storage/index.js.map +0 -1
  179. package/utils.d.ts +0 -4
  180. package/utils.js +0 -16
  181. package/utils.js.map +0 -1
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createFileModelModifier = exports.CmsModelModifierPlugin = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _plugins = require("@webiny/plugins");
11
+ var _file = require("../cmsFileStorage/file.model");
12
+ var _createModelField = require("../cmsFileStorage/createModelField");
13
+ class CmsModelFieldsModifier {
14
+ constructor(fields) {
15
+ (0, _defineProperty2.default)(this, "fields", void 0);
16
+ this.fields = fields;
17
+ }
18
+ addField(field) {
19
+ this.fields.push((0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
20
+ storageId: `${field.type}@${field.id}`
21
+ }));
22
+ }
23
+ }
24
+ class CmsModelModifierPlugin extends _plugins.Plugin {
25
+ constructor(modelId, cb) {
26
+ super();
27
+ (0, _defineProperty2.default)(this, "modelId", void 0);
28
+ (0, _defineProperty2.default)(this, "cb", void 0);
29
+ this.modelId = modelId;
30
+ this.cb = cb;
31
+ }
32
+ async modifyModel(model) {
33
+ if (model.modelId !== this.modelId) {
34
+ return;
35
+ }
36
+ let extensionsField = model.fields.find(field => field.fieldId === "extensions");
37
+ if (!extensionsField) {
38
+ extensionsField = (0, _createModelField.createModelField)({
39
+ label: "Extensions",
40
+ type: "object",
41
+ settings: {
42
+ layout: [],
43
+ fields: []
44
+ }
45
+ });
46
+ model.fields.push(extensionsField);
47
+ }
48
+ const modifier = new CmsModelFieldsModifier(extensionsField.settings.fields);
49
+ await this.cb({
50
+ modifier
51
+ });
52
+ }
53
+ }
54
+ exports.CmsModelModifierPlugin = CmsModelModifierPlugin;
55
+ (0, _defineProperty2.default)(CmsModelModifierPlugin, "type", "fm.cms-model-modifier");
56
+ const createFileModelModifier = cb => {
57
+ return new CmsModelModifierPlugin(_file.FILE_MODEL_ID, cb);
58
+ };
59
+ exports.createFileModelModifier = createFileModelModifier;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CmsModelFieldsModifier","constructor","fields","addField","field","push","storageId","type","id","CmsModelModifierPlugin","Plugin","modelId","cb","modifyModel","model","extensionsField","find","fieldId","createModelField","label","settings","layout","modifier","createFileModelModifier","FILE_MODEL_ID"],"sources":["CmsModelModifier.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { CmsModelField as BaseModelField } from \"@webiny/api-headless-cms/types\";\nimport { FILE_MODEL_ID } from \"~/cmsFileStorage/file.model\";\nimport { createModelField } from \"~/cmsFileStorage/createModelField\";\nimport { CmsPrivateModelFull } from \"@webiny/api-headless-cms\";\n\ntype CmsModelField = Omit<BaseModelField, \"storageId\">;\n\nclass CmsModelFieldsModifier {\n private fields: BaseModelField[];\n\n constructor(fields: BaseModelField[]) {\n this.fields = fields;\n }\n\n addField(field: CmsModelField) {\n this.fields.push({\n ...field,\n storageId: `${field.type}@${field.id}`\n });\n }\n}\n\ninterface CmsModelModifierCallableParams {\n modifier: CmsModelFieldsModifier;\n}\n\ninterface CmsModelModifierCallable {\n (params: CmsModelModifierCallableParams): Promise<void> | void;\n}\n\nexport class CmsModelModifierPlugin extends Plugin {\n public static override type = \"fm.cms-model-modifier\";\n private readonly modelId: string;\n private readonly cb: CmsModelModifierCallable;\n\n constructor(modelId: string, cb: CmsModelModifierCallable) {\n super();\n this.modelId = modelId;\n this.cb = cb;\n }\n\n async modifyModel(model: CmsPrivateModelFull): Promise<void> {\n if (model.modelId !== this.modelId) {\n return;\n }\n\n let extensionsField = model.fields.find(field => field.fieldId === \"extensions\");\n if (!extensionsField) {\n extensionsField = createModelField({\n label: \"Extensions\",\n type: \"object\",\n settings: {\n layout: [],\n fields: []\n }\n });\n model.fields.push(extensionsField);\n }\n\n const modifier = new CmsModelFieldsModifier(extensionsField.settings!.fields!);\n await this.cb({ modifier });\n }\n}\n\nexport const createFileModelModifier = (cb: CmsModelModifierCallable) => {\n return new CmsModelModifierPlugin(FILE_MODEL_ID, cb);\n};\n"],"mappings":";;;;;;;;;AAAA;AAEA;AACA;AAKA,MAAMA,sBAAsB,CAAC;EAGzBC,WAAW,CAACC,MAAwB,EAAE;IAAA;IAClC,IAAI,CAACA,MAAM,GAAGA,MAAM;EACxB;EAEAC,QAAQ,CAACC,KAAoB,EAAE;IAC3B,IAAI,CAACF,MAAM,CAACG,IAAI,6DACTD,KAAK;MACRE,SAAS,EAAG,GAAEF,KAAK,CAACG,IAAK,IAAGH,KAAK,CAACI,EAAG;IAAC,GACxC;EACN;AACJ;AAUO,MAAMC,sBAAsB,SAASC,eAAM,CAAC;EAK/CT,WAAW,CAACU,OAAe,EAAEC,EAA4B,EAAE;IACvD,KAAK,EAAE;IAAC;IAAA;IACR,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,EAAE,GAAGA,EAAE;EAChB;EAEA,MAAMC,WAAW,CAACC,KAA0B,EAAiB;IACzD,IAAIA,KAAK,CAACH,OAAO,KAAK,IAAI,CAACA,OAAO,EAAE;MAChC;IACJ;IAEA,IAAII,eAAe,GAAGD,KAAK,CAACZ,MAAM,CAACc,IAAI,CAACZ,KAAK,IAAIA,KAAK,CAACa,OAAO,KAAK,YAAY,CAAC;IAChF,IAAI,CAACF,eAAe,EAAE;MAClBA,eAAe,GAAG,IAAAG,kCAAgB,EAAC;QAC/BC,KAAK,EAAE,YAAY;QACnBZ,IAAI,EAAE,QAAQ;QACda,QAAQ,EAAE;UACNC,MAAM,EAAE,EAAE;UACVnB,MAAM,EAAE;QACZ;MACJ,CAAC,CAAC;MACFY,KAAK,CAACZ,MAAM,CAACG,IAAI,CAACU,eAAe,CAAC;IACtC;IAEA,MAAMO,QAAQ,GAAG,IAAItB,sBAAsB,CAACe,eAAe,CAACK,QAAQ,CAAElB,MAAM,CAAE;IAC9E,MAAM,IAAI,CAACU,EAAE,CAAC;MAAEU;IAAS,CAAC,CAAC;EAC/B;AACJ;AAAC;AAAA,8BAhCYb,sBAAsB,UACD,uBAAuB;AAiClD,MAAMc,uBAAuB,GAAIX,EAA4B,IAAK;EACrE,OAAO,IAAIH,sBAAsB,CAACe,mBAAa,EAAEZ,EAAE,CAAC;AACxD,CAAC;AAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-file-manager",
3
- "version": "0.0.0-unstable.97a151f74d",
3
+ "version": "0.0.0-unstable.99666aeb00",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "fm:base"
@@ -18,39 +18,38 @@
18
18
  ],
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@babel/runtime": "7.19.0",
21
+ "@babel/runtime": "7.20.13",
22
22
  "@commodo/fields": "1.1.2-beta.20",
23
- "@webiny/api": "0.0.0-unstable.97a151f74d",
24
- "@webiny/api-security": "0.0.0-unstable.97a151f74d",
25
- "@webiny/api-tenancy": "0.0.0-unstable.97a151f74d",
26
- "@webiny/api-upgrade": "0.0.0-unstable.97a151f74d",
27
- "@webiny/error": "0.0.0-unstable.97a151f74d",
28
- "@webiny/handler": "0.0.0-unstable.97a151f74d",
29
- "@webiny/handler-aws": "0.0.0-unstable.97a151f74d",
30
- "@webiny/handler-client": "0.0.0-unstable.97a151f74d",
31
- "@webiny/handler-graphql": "0.0.0-unstable.97a151f74d",
32
- "@webiny/plugins": "0.0.0-unstable.97a151f74d",
33
- "@webiny/project-utils": "0.0.0-unstable.97a151f74d",
34
- "@webiny/validation": "0.0.0-unstable.97a151f74d",
35
- "aws-sdk": "2.1230.0",
36
- "commodo-fields-object": "1.0.6",
37
- "mdbid": "1.0.0",
38
- "object-hash": "2.2.0",
39
- "sanitize-filename": "1.6.3"
23
+ "@webiny/api": "0.0.0-unstable.99666aeb00",
24
+ "@webiny/api-headless-cms": "0.0.0-unstable.99666aeb00",
25
+ "@webiny/api-security": "0.0.0-unstable.99666aeb00",
26
+ "@webiny/api-tenancy": "0.0.0-unstable.99666aeb00",
27
+ "@webiny/error": "0.0.0-unstable.99666aeb00",
28
+ "@webiny/handler": "0.0.0-unstable.99666aeb00",
29
+ "@webiny/handler-aws": "0.0.0-unstable.99666aeb00",
30
+ "@webiny/handler-client": "0.0.0-unstable.99666aeb00",
31
+ "@webiny/handler-graphql": "0.0.0-unstable.99666aeb00",
32
+ "@webiny/plugins": "0.0.0-unstable.99666aeb00",
33
+ "@webiny/project-utils": "0.0.0-unstable.99666aeb00",
34
+ "@webiny/pubsub": "0.0.0-unstable.99666aeb00",
35
+ "@webiny/validation": "0.0.0-unstable.99666aeb00",
36
+ "aws-sdk": "2.1310.0",
37
+ "lodash": "4.17.21",
38
+ "object-hash": "2.2.0"
40
39
  },
41
40
  "devDependencies": {
42
- "@babel/cli": "^7.19.3",
43
- "@babel/core": "^7.19.3",
44
- "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
45
- "@babel/plugin-transform-runtime": "^7.16.4",
46
- "@babel/preset-env": "^7.19.4",
47
- "@babel/preset-typescript": "^7.18.6",
48
- "@webiny/api-i18n": "^0.0.0-unstable.97a151f74d",
49
- "@webiny/api-i18n-ddb": "^0.0.0-unstable.97a151f74d",
50
- "@webiny/cli": "^0.0.0-unstable.97a151f74d",
51
- "jest": "^28.1.0",
52
- "rimraf": "^3.0.2",
53
- "ttypescript": "^1.5.12",
41
+ "@babel/cli": "7.20.7",
42
+ "@babel/core": "7.20.12",
43
+ "@babel/plugin-proposal-object-rest-spread": "7.20.7",
44
+ "@babel/plugin-transform-runtime": "7.19.6",
45
+ "@babel/preset-env": "7.20.2",
46
+ "@babel/preset-typescript": "7.18.6",
47
+ "@webiny/api-i18n": "0.0.0-unstable.99666aeb00",
48
+ "@webiny/cli": "0.0.0-unstable.99666aeb00",
49
+ "@webiny/utils": "0.0.0-unstable.99666aeb00",
50
+ "jest": "29.5.0",
51
+ "rimraf": "3.0.2",
52
+ "ttypescript": "1.5.15",
54
53
  "typescript": "4.7.4"
55
54
  },
56
55
  "publishConfig": {
@@ -72,5 +71,5 @@
72
71
  ]
73
72
  }
74
73
  },
75
- "gitHead": "97a151f74d8c5679323989fcc8cc7036be0f150e"
74
+ "gitHead": "99666aeb00056c56292eeb5dbb6aba7fda2439e2"
76
75
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Plugin } from "@webiny/plugins";
3
- import { FileManagerSettings } from "../../types";
3
+ import { FileManagerSettings } from "../types";
4
4
  export interface FilePhysicalStoragePluginParams<U extends FilePhysicalStoragePluginUploadParams, D extends FilePhysicalStoragePluginDeleteParams> {
5
5
  upload: (args: U) => Promise<any>;
6
6
  delete: (args: D) => Promise<void>;
@@ -1,42 +1,31 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.FilePhysicalStoragePlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _plugins = require("@webiny/plugins");
13
-
14
10
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
11
  class FilePhysicalStoragePlugin extends _plugins.Plugin {
17
12
  constructor(params) {
18
13
  super();
19
14
  (0, _defineProperty2.default)(this, "_params", void 0);
20
15
  this._params = params;
21
16
  }
22
-
23
17
  async upload(params) {
24
18
  if (!this._params.upload) {
25
19
  throw new _error.default(`You must define the "upload" method of this plugin.`, "UPLOAD_METHOD_ERROR");
26
20
  }
27
-
28
21
  return this._params.upload(params);
29
22
  }
30
-
31
23
  async delete(params) {
32
24
  if (!this._params.delete) {
33
25
  throw new _error.default(`You must define the "delete" method of this plugin.`, "DELETE_METHOD_ERROR");
34
26
  }
35
-
36
27
  return this._params.delete(params);
37
28
  }
38
-
39
29
  }
40
-
41
30
  exports.FilePhysicalStoragePlugin = FilePhysicalStoragePlugin;
42
31
  (0, _defineProperty2.default)(FilePhysicalStoragePlugin, "type", "api-file-manager-storage");
@@ -1 +1 @@
1
- {"version":3,"names":["FilePhysicalStoragePlugin","Plugin","constructor","params","_params","upload","WebinyError","delete"],"sources":["FilePhysicalStoragePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { FileManagerSettings } from \"~/types\";\n\nexport interface FilePhysicalStoragePluginParams<\n U extends FilePhysicalStoragePluginUploadParams,\n D extends FilePhysicalStoragePluginDeleteParams\n> {\n upload: (args: U) => Promise<any>;\n delete: (args: D) => Promise<void>;\n}\n\nexport interface FilePhysicalStoragePluginUploadParams {\n settings: FileManagerSettings;\n buffer: Buffer;\n}\n\nexport interface FilePhysicalStoragePluginDeleteParams {\n key: string;\n}\n\nexport class FilePhysicalStoragePlugin<\n U extends FilePhysicalStoragePluginUploadParams = FilePhysicalStoragePluginUploadParams,\n D extends FilePhysicalStoragePluginDeleteParams = FilePhysicalStoragePluginDeleteParams\n> extends Plugin {\n public static override readonly type: string = \"api-file-manager-storage\";\n private readonly _params: FilePhysicalStoragePluginParams<U, D>;\n\n public constructor(params: FilePhysicalStoragePluginParams<U, D>) {\n super();\n this._params = params;\n }\n\n public async upload(params: U): Promise<any> {\n if (!this._params.upload) {\n throw new WebinyError(\n `You must define the \"upload\" method of this plugin.`,\n \"UPLOAD_METHOD_ERROR\"\n );\n }\n return this._params.upload(params);\n }\n\n public async delete(params: D): Promise<any> {\n if (!this._params.delete) {\n throw new WebinyError(\n `You must define the \"delete\" method of this plugin.`,\n \"DELETE_METHOD_ERROR\"\n );\n }\n return this._params.delete(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAoBO,MAAMA,yBAAN,SAGGC,eAHH,CAGU;EAINC,WAAW,CAACC,MAAD,EAAgD;IAC9D;IAD8D;IAE9D,KAAKC,OAAL,GAAeD,MAAf;EACH;;EAEkB,MAANE,MAAM,CAACF,MAAD,EAA0B;IACzC,IAAI,CAAC,KAAKC,OAAL,CAAaC,MAAlB,EAA0B;MACtB,MAAM,IAAIC,cAAJ,CACD,qDADC,EAEF,qBAFE,CAAN;IAIH;;IACD,OAAO,KAAKF,OAAL,CAAaC,MAAb,CAAoBF,MAApB,CAAP;EACH;;EAEkB,MAANI,MAAM,CAACJ,MAAD,EAA0B;IACzC,IAAI,CAAC,KAAKC,OAAL,CAAaG,MAAlB,EAA0B;MACtB,MAAM,IAAID,cAAJ,CACD,qDADC,EAEF,qBAFE,CAAN;IAIH;;IACD,OAAO,KAAKF,OAAL,CAAaG,MAAb,CAAoBJ,MAApB,CAAP;EACH;;AA3BY;;;8BAHJH,yB,UAIsC,0B"}
1
+ {"version":3,"names":["FilePhysicalStoragePlugin","Plugin","constructor","params","_params","upload","WebinyError","delete"],"sources":["FilePhysicalStoragePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { FileManagerSettings } from \"~/types\";\n\nexport interface FilePhysicalStoragePluginParams<\n U extends FilePhysicalStoragePluginUploadParams,\n D extends FilePhysicalStoragePluginDeleteParams\n> {\n upload: (args: U) => Promise<any>;\n delete: (args: D) => Promise<void>;\n}\n\nexport interface FilePhysicalStoragePluginUploadParams {\n settings: FileManagerSettings;\n buffer: Buffer;\n}\n\nexport interface FilePhysicalStoragePluginDeleteParams {\n key: string;\n}\n\nexport class FilePhysicalStoragePlugin<\n U extends FilePhysicalStoragePluginUploadParams = FilePhysicalStoragePluginUploadParams,\n D extends FilePhysicalStoragePluginDeleteParams = FilePhysicalStoragePluginDeleteParams\n> extends Plugin {\n public static override readonly type: string = \"api-file-manager-storage\";\n private readonly _params: FilePhysicalStoragePluginParams<U, D>;\n\n public constructor(params: FilePhysicalStoragePluginParams<U, D>) {\n super();\n this._params = params;\n }\n\n public async upload(params: U): Promise<any> {\n if (!this._params.upload) {\n throw new WebinyError(\n `You must define the \"upload\" method of this plugin.`,\n \"UPLOAD_METHOD_ERROR\"\n );\n }\n return this._params.upload(params);\n }\n\n public async delete(params: D): Promise<any> {\n if (!this._params.delete) {\n throw new WebinyError(\n `You must define the \"delete\" method of this plugin.`,\n \"DELETE_METHOD_ERROR\"\n );\n }\n return this._params.delete(params);\n }\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AAoBO,MAAMA,yBAAyB,SAG5BC,eAAM,CAAC;EAINC,WAAW,CAACC,MAA6C,EAAE;IAC9D,KAAK,EAAE;IAAC;IACR,IAAI,CAACC,OAAO,GAAGD,MAAM;EACzB;EAEA,MAAaE,MAAM,CAACF,MAAS,EAAgB;IACzC,IAAI,CAAC,IAAI,CAACC,OAAO,CAACC,MAAM,EAAE;MACtB,MAAM,IAAIC,cAAW,CAChB,qDAAoD,EACrD,qBAAqB,CACxB;IACL;IACA,OAAO,IAAI,CAACF,OAAO,CAACC,MAAM,CAACF,MAAM,CAAC;EACtC;EAEA,MAAaI,MAAM,CAACJ,MAAS,EAAgB;IACzC,IAAI,CAAC,IAAI,CAACC,OAAO,CAACG,MAAM,EAAE;MACtB,MAAM,IAAID,cAAW,CAChB,qDAAoD,EACrD,qBAAqB,CACxB;IACL;IACA,OAAO,IAAI,CAACF,OAAO,CAACG,MAAM,CAACJ,MAAM,CAAC;EACtC;AACJ;AAAC;AAAA,8BA/BYH,yBAAyB,UAIa,0BAA0B"}
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from "@webiny/plugins";
2
- import { File } from "../../types";
2
+ import { File } from "../types";
3
3
  export interface FileStorageTransformPluginToParams {
4
4
  /**
5
5
  * File that is being sent to the storage operations method.
@@ -1,33 +1,27 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.FileStorageTransformPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _plugins = require("@webiny/plugins");
13
-
14
10
  class FileStorageTransformPlugin extends _plugins.Plugin {
15
11
  constructor(params) {
16
12
  super();
17
13
  (0, _defineProperty2.default)(this, "_params", void 0);
18
14
  this._params = params;
19
15
  }
16
+
20
17
  /**
21
18
  * Transform the file value into something that can be stored.
22
19
  * Be aware that you must return the whole file object.
23
20
  */
24
-
25
-
26
21
  async toStorage(params) {
27
22
  if (!this._params.toStorage) {
28
23
  return params.file;
29
24
  }
30
-
31
25
  return this._params.toStorage(params);
32
26
  }
33
27
  /**
@@ -35,17 +29,12 @@ class FileStorageTransformPlugin extends _plugins.Plugin {
35
29
  * Be aware that you must return the whole file object.
36
30
  * This method MUST reverse what ever toStorage method changed on the file object.
37
31
  */
38
-
39
-
40
32
  async fromStorage(params) {
41
33
  if (!this._params.fromStorage) {
42
34
  return params.file;
43
35
  }
44
-
45
36
  return this._params.fromStorage(params);
46
37
  }
47
-
48
38
  }
49
-
50
39
  exports.FileStorageTransformPlugin = FileStorageTransformPlugin;
51
40
  (0, _defineProperty2.default)(FileStorageTransformPlugin, "type", "fm.files.storage.transform");
@@ -1 +1 @@
1
- {"version":3,"names":["FileStorageTransformPlugin","Plugin","constructor","params","_params","toStorage","file","fromStorage"],"sources":["FileStorageTransformPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { File } from \"~/types\";\n\nexport interface FileStorageTransformPluginToParams {\n /**\n * File that is being sent to the storage operations method.\n */\n file: File & Record<string, any>;\n}\n\nexport interface FileStorageTransformPluginFromParams {\n /**\n * File that was fetched from the storage operations method.\n */\n file: File & Record<string, any>;\n}\n\nexport interface FileStorageTransformPluginParams {\n toStorage?: (params: FileStorageTransformPluginToParams) => Promise<File & Record<string, any>>;\n fromStorage?: (\n params: FileStorageTransformPluginFromParams\n ) => Promise<File & Record<string, any>>;\n}\n\nexport class FileStorageTransformPlugin extends Plugin {\n public static override readonly type: string = \"fm.files.storage.transform\";\n private readonly _params: FileStorageTransformPluginParams;\n\n public constructor(params: FileStorageTransformPluginParams) {\n super();\n\n this._params = params;\n }\n\n /**\n * Transform the file value into something that can be stored.\n * Be aware that you must return the whole file object.\n */\n public async toStorage(\n params: FileStorageTransformPluginToParams\n ): Promise<File & Record<string, any>> {\n if (!this._params.toStorage) {\n return params.file;\n }\n return this._params.toStorage(params);\n }\n /**\n * Transform the file value from the storage type to one required by our system.\n * Be aware that you must return the whole file object.\n * This method MUST reverse what ever toStorage method changed on the file object.\n */\n public async fromStorage(\n params: FileStorageTransformPluginFromParams\n ): Promise<File & Record<string, any>> {\n if (!this._params.fromStorage) {\n return params.file;\n }\n return this._params.fromStorage(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAwBO,MAAMA,0BAAN,SAAyCC,eAAzC,CAAgD;EAI5CC,WAAW,CAACC,MAAD,EAA2C;IACzD;IADyD;IAGzD,KAAKC,OAAL,GAAeD,MAAf;EACH;EAED;AACJ;AACA;AACA;;;EAC0B,MAATE,SAAS,CAClBF,MADkB,EAEiB;IACnC,IAAI,CAAC,KAAKC,OAAL,CAAaC,SAAlB,EAA6B;MACzB,OAAOF,MAAM,CAACG,IAAd;IACH;;IACD,OAAO,KAAKF,OAAL,CAAaC,SAAb,CAAuBF,MAAvB,CAAP;EACH;EACD;AACJ;AACA;AACA;AACA;;;EAC4B,MAAXI,WAAW,CACpBJ,MADoB,EAEe;IACnC,IAAI,CAAC,KAAKC,OAAL,CAAaG,WAAlB,EAA+B;MAC3B,OAAOJ,MAAM,CAACG,IAAd;IACH;;IACD,OAAO,KAAKF,OAAL,CAAaG,WAAb,CAAyBJ,MAAzB,CAAP;EACH;;AAlCkD;;;8BAA1CH,0B,UACsC,4B"}
1
+ {"version":3,"names":["FileStorageTransformPlugin","Plugin","constructor","params","_params","toStorage","file","fromStorage"],"sources":["FileStorageTransformPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { File } from \"~/types\";\n\nexport interface FileStorageTransformPluginToParams {\n /**\n * File that is being sent to the storage operations method.\n */\n file: File & Record<string, any>;\n}\n\nexport interface FileStorageTransformPluginFromParams {\n /**\n * File that was fetched from the storage operations method.\n */\n file: File & Record<string, any>;\n}\n\nexport interface FileStorageTransformPluginParams {\n toStorage?: (params: FileStorageTransformPluginToParams) => Promise<File & Record<string, any>>;\n fromStorage?: (\n params: FileStorageTransformPluginFromParams\n ) => Promise<File & Record<string, any>>;\n}\n\nexport class FileStorageTransformPlugin extends Plugin {\n public static override readonly type: string = \"fm.files.storage.transform\";\n private readonly _params: FileStorageTransformPluginParams;\n\n public constructor(params: FileStorageTransformPluginParams) {\n super();\n\n this._params = params;\n }\n\n /**\n * Transform the file value into something that can be stored.\n * Be aware that you must return the whole file object.\n */\n public async toStorage(\n params: FileStorageTransformPluginToParams\n ): Promise<File & Record<string, any>> {\n if (!this._params.toStorage) {\n return params.file;\n }\n return this._params.toStorage(params);\n }\n /**\n * Transform the file value from the storage type to one required by our system.\n * Be aware that you must return the whole file object.\n * This method MUST reverse what ever toStorage method changed on the file object.\n */\n public async fromStorage(\n params: FileStorageTransformPluginFromParams\n ): Promise<File & Record<string, any>> {\n if (!this._params.fromStorage) {\n return params.file;\n }\n return this._params.fromStorage(params);\n }\n}\n"],"mappings":";;;;;;;;AAAA;AAwBO,MAAMA,0BAA0B,SAASC,eAAM,CAAC;EAI5CC,WAAW,CAACC,MAAwC,EAAE;IACzD,KAAK,EAAE;IAAC;IAER,IAAI,CAACC,OAAO,GAAGD,MAAM;EACzB;;EAEA;AACJ;AACA;AACA;EACI,MAAaE,SAAS,CAClBF,MAA0C,EACP;IACnC,IAAI,CAAC,IAAI,CAACC,OAAO,CAACC,SAAS,EAAE;MACzB,OAAOF,MAAM,CAACG,IAAI;IACtB;IACA,OAAO,IAAI,CAACF,OAAO,CAACC,SAAS,CAACF,MAAM,CAAC;EACzC;EACA;AACJ;AACA;AACA;AACA;EACI,MAAaI,WAAW,CACpBJ,MAA4C,EACT;IACnC,IAAI,CAAC,IAAI,CAACC,OAAO,CAACG,WAAW,EAAE;MAC3B,OAAOJ,MAAM,CAACG,IAAI;IACtB;IACA,OAAO,IAAI,CAACF,OAAO,CAACG,WAAW,CAACJ,MAAM,CAAC;EAC3C;AACJ;AAAC;AAAA,8BAnCYH,0BAA0B,UACY,4BAA4B"}
@@ -1,2 +1,2 @@
1
- declare const _default: () => (import("@webiny/handler-graphql/types").GraphQLSchemaPlugin<import("../types").FileManagerContext> | import("./definitions/FilePlugin").FilePlugin[] | import("@webiny/api").ContextPlugin<import("../types").FileManagerContext>)[];
2
- export default _default;
1
+ export * from "./FilePhysicalStoragePlugin";
2
+ export * from "./FileStorageTransformPlugin";
package/plugins/index.js CHANGED
@@ -1,24 +1,27 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
- exports.default = void 0;
9
-
10
- var _graphql = _interopRequireDefault(require("./graphql"));
11
-
12
- var _files = _interopRequireDefault(require("./crud/files.crud"));
13
-
14
- var _validation = _interopRequireDefault(require("./crud/files/validation"));
15
-
16
- var _settings = _interopRequireDefault(require("./crud/settings.crud"));
17
-
18
- var _system = _interopRequireDefault(require("./crud/system.crud"));
19
-
20
- var _storage = _interopRequireDefault(require("./storage"));
21
-
22
- var _default = () => [_system.default, _settings.default, _files.default, _storage.default, _graphql.default, (0, _validation.default)()];
23
-
24
- exports.default = _default;
6
+ var _FilePhysicalStoragePlugin = require("./FilePhysicalStoragePlugin");
7
+ Object.keys(_FilePhysicalStoragePlugin).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _FilePhysicalStoragePlugin[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _FilePhysicalStoragePlugin[key];
14
+ }
15
+ });
16
+ });
17
+ var _FileStorageTransformPlugin = require("./FileStorageTransformPlugin");
18
+ Object.keys(_FileStorageTransformPlugin).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _FileStorageTransformPlugin[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _FileStorageTransformPlugin[key];
25
+ }
26
+ });
27
+ });
@@ -1 +1 @@
1
- {"version":3,"names":["systemCRUD","settingsCRUD","filesCRUD","storage","graphql","fileValidationPlugin"],"sources":["index.ts"],"sourcesContent":["import graphql from \"./graphql\";\nimport filesCRUD from \"./crud/files.crud\";\nimport fileValidationPlugin from \"./crud/files/validation\";\nimport settingsCRUD from \"./crud/settings.crud\";\nimport systemCRUD from \"./crud/system.crud\";\nimport storage from \"./storage\";\n\nexport default () => [\n systemCRUD,\n settingsCRUD,\n filesCRUD,\n storage,\n graphql,\n fileValidationPlugin()\n];\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;eAEe,MAAM,CACjBA,eADiB,EAEjBC,iBAFiB,EAGjBC,cAHiB,EAIjBC,gBAJiB,EAKjBC,gBALiB,EAMjB,IAAAC,mBAAA,GANiB,C"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./FilePhysicalStoragePlugin\";\nexport * from \"./FileStorageTransformPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -1,14 +1,16 @@
1
1
  /// <reference types="node" />
2
- import { FileManagerContext } from "../../types";
2
+ import { FileManagerContext } from "../types";
3
3
  export declare type Result = Record<string, any>;
4
4
  export interface FileStorageUploadParams {
5
5
  buffer: Buffer;
6
6
  hideInFileManager: boolean | string;
7
- tags?: string[];
8
7
  size: number;
9
8
  name: string;
10
- keyPrefix: string;
11
9
  type: string;
10
+ id?: string;
11
+ key?: string;
12
+ tags?: string[];
13
+ keyPrefix?: string;
12
14
  }
13
15
  export interface FileStorageDeleteParams {
14
16
  id: string;
@@ -25,6 +27,6 @@ export declare class FileStorage {
25
27
  private readonly context;
26
28
  constructor({ context }: FileStorageParams);
27
29
  upload(params: FileStorageUploadParams): Promise<Result>;
28
- uploadFiles(params: FileStorageUploadMultipleParams): Promise<import("../../types").File[]>;
30
+ uploadFiles({ files }: FileStorageUploadMultipleParams): Promise<import("../types").File[]>;
29
31
  delete(params: FileStorageDeleteParams): Promise<boolean>;
30
32
  }
@@ -1,20 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.FileStorage = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
10
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
11
  const storagePluginType = "api-file-manager-storage";
17
-
18
12
  class FileStorage {
19
13
  constructor({
20
14
  context
@@ -22,66 +16,56 @@ class FileStorage {
22
16
  (0, _defineProperty2.default)(this, "storagePlugin", void 0);
23
17
  (0, _defineProperty2.default)(this, "context", void 0);
24
18
  const storagePlugin = context.plugins.byType(storagePluginType).pop();
25
-
26
19
  if (!storagePlugin) {
27
20
  throw new _error.default(`Missing plugin of type "${storagePluginType}".`, "STORAGE_PLUGIN_ERROR");
28
21
  }
29
-
30
22
  this.storagePlugin = storagePlugin;
31
23
  this.context = context;
32
24
  }
33
-
34
25
  async upload(params) {
35
- const settings = await this.context.fileManager.settings.getSettings();
36
-
26
+ const settings = await this.context.fileManager.getSettings();
37
27
  if (!settings) {
38
28
  throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_ERROR");
39
- } // Add file to cloud storage.
40
-
29
+ }
41
30
 
31
+ // Add file to cloud storage.
42
32
  const {
43
33
  file: fileData
44
34
  } = await this.storagePlugin.upload((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
45
35
  settings
46
36
  }));
47
- const {
48
- fileManager
49
- } = this.context; // Save file in DB.
50
37
 
51
- return await fileManager.files.createFile((0, _objectSpread2.default)((0, _objectSpread2.default)({}, fileData), {}, {
38
+ // Save file in DB.
39
+ return this.context.fileManager.createFile((0, _objectSpread2.default)((0, _objectSpread2.default)({}, fileData), {}, {
52
40
  meta: {
53
41
  private: Boolean(params.hideInFileManager)
54
42
  },
55
43
  tags: Array.isArray(params.tags) ? params.tags : []
56
44
  }));
57
45
  }
58
-
59
- async uploadFiles(params) {
60
- const settings = await this.context.fileManager.settings.getSettings();
61
-
46
+ async uploadFiles({
47
+ files
48
+ }) {
49
+ const settings = await this.context.fileManager.getSettings();
62
50
  if (!settings) {
63
51
  throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_ERROR");
64
- } // Upload files to cloud storage.
65
-
66
-
67
- const promises = [];
68
-
69
- for (const item of params.files) {
70
- promises.push(this.storagePlugin.upload((0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
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), {}, {
71
58
  settings
72
- })));
73
- } // Wait for all to resolve.
74
-
75
-
76
- const uploadFileResponses = await Promise.all(promises);
77
- const filesData = uploadFileResponses.map(response => response.file);
78
- const {
79
- fileManager
80
- } = this.context; // Save files in DB.
81
-
82
- return fileManager.files.createFilesInBatch(filesData);
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);
83
68
  }
84
-
85
69
  async delete(params) {
86
70
  const {
87
71
  id,
@@ -89,15 +73,14 @@ class FileStorage {
89
73
  } = params;
90
74
  const {
91
75
  fileManager
92
- } = this.context; // Delete file from cloud storage.
93
-
76
+ } = this.context;
77
+ // Delete file from cloud storage.
94
78
  await this.storagePlugin.delete({
95
79
  key
96
- }); // Delete file from the DB.
80
+ });
97
81
 
98
- return await fileManager.files.deleteFile(id);
82
+ // Delete file from the DB.
83
+ return await fileManager.deleteFile(id);
99
84
  }
100
-
101
85
  }
102
-
103
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,37 @@
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
+ location: {
9
+ folderId: string;
10
+ };
11
+ tags: string[];
12
+ aliases: string[];
13
+ createdOn: string;
14
+ savedOn: string;
15
+ createdBy: CreatedBy;
16
+ /**
17
+ * Added with new storage operations refactoring.
18
+ */
19
+ tenant: string;
20
+ locale: string;
21
+ webinyVersion: string;
22
+ /**
23
+ * User can add new fields to the File object, so we must allow it in the types.
24
+ */
25
+ [key: string]: any;
26
+ }
27
+ export interface FileAlias {
28
+ tenant: string;
29
+ locale: string;
30
+ fileId: string;
31
+ alias: string;
32
+ }
33
+ export interface CreatedBy {
34
+ id: string;
35
+ displayName: string | null;
36
+ type: string;
37
+ }
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 location: {\n folderId: string;\n };\n tags: string[];\n aliases: string[];\n createdOn: string;\n savedOn: 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,44 @@
1
+ import { Topic } from "@webiny/pubsub/types";
2
+ import { 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,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });