@webiny/api-file-manager 0.0.0-mt-3 → 0.0.0-unstable.2af142b57e

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 (102) hide show
  1. package/handlers/download/index.d.ts +3 -3
  2. package/handlers/download/index.js +64 -76
  3. package/handlers/download/index.js.map +1 -0
  4. package/handlers/manage/index.d.ts +5 -3
  5. package/handlers/manage/index.js +43 -58
  6. package/handlers/manage/index.js.map +1 -0
  7. package/handlers/transform/index.d.ts +2 -3
  8. package/handlers/transform/index.js +62 -77
  9. package/handlers/transform/index.js.map +1 -0
  10. package/handlers/transform/loaders/imageLoader.d.ts +26 -9
  11. package/handlers/transform/loaders/imageLoader.js +3 -21
  12. package/handlers/transform/loaders/imageLoader.js.map +1 -0
  13. package/handlers/transform/loaders/index.d.ts +4 -9
  14. package/handlers/transform/loaders/index.js +1 -4
  15. package/handlers/transform/loaders/index.js.map +1 -0
  16. package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +7 -3
  17. package/handlers/transform/loaders/sanitizeImageTransformations.js +24 -30
  18. package/handlers/transform/loaders/sanitizeImageTransformations.js.map +1 -0
  19. package/handlers/transform/managers/imageManager.d.ts +12 -6
  20. package/handlers/transform/managers/imageManager.js +25 -25
  21. package/handlers/transform/managers/imageManager.js.map +1 -0
  22. package/handlers/transform/managers/index.d.ts +2 -6
  23. package/handlers/transform/managers/index.js +1 -4
  24. package/handlers/transform/managers/index.js.map +1 -0
  25. package/handlers/transform/optimizeImage.d.ts +2 -1
  26. package/handlers/transform/optimizeImage.js +4 -7
  27. package/handlers/transform/optimizeImage.js.map +1 -0
  28. package/handlers/transform/transformImage.d.ts +5 -4
  29. package/handlers/transform/transformImage.js +4 -9
  30. package/handlers/transform/transformImage.js.map +1 -0
  31. package/handlers/transform/utils.d.ts +2 -2
  32. package/handlers/transform/utils.js +1 -11
  33. package/handlers/transform/utils.js.map +1 -0
  34. package/handlers/types.d.ts +8 -0
  35. package/handlers/types.js +5 -0
  36. package/handlers/types.js.map +1 -0
  37. package/handlers/utils/getEnvironment.js +0 -2
  38. package/handlers/utils/getEnvironment.js.map +1 -0
  39. package/handlers/utils/getObjectParams.d.ts +3 -4
  40. package/handlers/utils/getObjectParams.js +1 -7
  41. package/handlers/utils/getObjectParams.js.map +1 -0
  42. package/handlers/utils/index.d.ts +0 -1
  43. package/handlers/utils/index.js +1 -12
  44. package/handlers/utils/index.js.map +1 -0
  45. package/package.json +28 -27
  46. package/plugins/crud/files/validation.js +1 -7
  47. package/plugins/crud/files/validation.js.map +1 -0
  48. package/plugins/crud/files.crud.d.ts +1 -1
  49. package/plugins/crud/files.crud.js +43 -98
  50. package/plugins/crud/files.crud.js.map +1 -0
  51. package/plugins/crud/settings.crud.d.ts +1 -1
  52. package/plugins/crud/settings.crud.js +10 -26
  53. package/plugins/crud/settings.crud.js.map +1 -0
  54. package/plugins/crud/system.crud.d.ts +1 -1
  55. package/plugins/crud/system.crud.js +17 -39
  56. package/plugins/crud/system.crud.js.map +1 -0
  57. package/plugins/crud/utils/checkBasePermissions.js +1 -9
  58. package/plugins/crud/utils/checkBasePermissions.js.map +1 -0
  59. package/plugins/crud/utils/createFileModel.d.ts +3 -0
  60. package/plugins/crud/utils/createFileModel.js +11 -10
  61. package/plugins/crud/utils/createFileModel.js.map +1 -0
  62. package/plugins/crud/utils/lifecycleEvents.d.ts +2 -2
  63. package/plugins/crud/utils/lifecycleEvents.js +8 -11
  64. package/plugins/crud/utils/lifecycleEvents.js.map +1 -0
  65. package/plugins/definitions/FilePhysicalStoragePlugin.d.ts +10 -11
  66. package/plugins/definitions/FilePhysicalStoragePlugin.js +1 -12
  67. package/plugins/definitions/FilePhysicalStoragePlugin.js.map +1 -0
  68. package/plugins/definitions/FilePlugin.d.ts +6 -3
  69. package/plugins/definitions/FilePlugin.js +7 -19
  70. package/plugins/definitions/FilePlugin.js.map +1 -0
  71. package/plugins/definitions/FileStorageTransformPlugin.d.ts +9 -9
  72. package/plugins/definitions/FileStorageTransformPlugin.js +2 -13
  73. package/plugins/definitions/FileStorageTransformPlugin.js.map +1 -0
  74. package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +4 -4
  75. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +1 -6
  76. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +1 -0
  77. package/plugins/definitions/InstallationPlugin.d.ts +9 -9
  78. package/plugins/definitions/InstallationPlugin.js +4 -13
  79. package/plugins/definitions/InstallationPlugin.js.map +1 -0
  80. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +4 -4
  81. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +1 -6
  82. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +1 -0
  83. package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +4 -4
  84. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +1 -6
  85. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +1 -0
  86. package/plugins/graphql.js +21 -25
  87. package/plugins/graphql.js.map +1 -0
  88. package/plugins/index.d.ts +1 -1
  89. package/plugins/index.js +1 -10
  90. package/plugins/index.js.map +1 -0
  91. package/plugins/storage/FileStorage.d.ts +23 -24
  92. package/plugins/storage/FileStorage.js +35 -45
  93. package/plugins/storage/FileStorage.js.map +1 -0
  94. package/plugins/storage/index.d.ts +1 -1
  95. package/plugins/storage/index.js +6 -6
  96. package/plugins/storage/index.js.map +1 -0
  97. package/types.d.ts +16 -12
  98. package/types.js.map +1 -0
  99. package/utils.js +0 -2
  100. package/utils.js.map +1 -0
  101. package/handlers/utils/createHandler.d.ts +0 -24
  102. package/handlers/utils/createHandler.js +0 -68
@@ -1,28 +1,22 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = exports.SETTINGS_KEY = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _fields = require("@commodo/fields");
13
-
14
10
  var _validation = require("@webiny/validation");
15
-
16
11
  var _SettingsStorageOperationsProviderPlugin = require("../definitions/SettingsStorageOperationsProviderPlugin");
17
-
18
12
  var _error = _interopRequireDefault(require("@webiny/error"));
13
+ var _api = require("@webiny/api");
14
+ /**
15
+ * Package @commodo/fields does not have types.
16
+ */
17
+ // @ts-ignore
19
18
 
20
- var _ContextPlugin = require("@webiny/handler/plugins/ContextPlugin");
21
-
22
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
23
-
24
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
25
-
19
+ // TODO @ts-refactor verify that this is not used and remove it
26
20
  const SETTINGS_KEY = "file-manager";
27
21
  exports.SETTINGS_KEY = SETTINGS_KEY;
28
22
  const CreateDataModel = (0, _fields.withFields)({
@@ -38,7 +32,6 @@ const CreateDataModel = (0, _fields.withFields)({
38
32
  if (typeof value === "string") {
39
33
  return value.endsWith("/") ? value : value + "/";
40
34
  }
41
-
42
35
  return value;
43
36
  })((0, _fields.string)({
44
37
  value: "/files/"
@@ -54,33 +47,27 @@ const UpdateDataModel = (0, _fields.withFields)({
54
47
  if (typeof value === "string") {
55
48
  return value.endsWith("/") ? value : value + "/";
56
49
  }
57
-
58
50
  return value;
59
51
  })((0, _fields.string)())
60
52
  })();
61
- const settingsCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context => {
53
+ const settingsCrudContextPlugin = new _api.ContextPlugin(async context => {
62
54
  const pluginType = _SettingsStorageOperationsProviderPlugin.SettingsStorageOperationsProviderPlugin.type;
63
55
  const providerPlugin = context.plugins.byType(pluginType).find(() => true);
64
-
65
56
  if (!providerPlugin) {
66
57
  throw new _error.default(`Missing "${pluginType}" plugin.`, "PLUGIN_NOT_FOUND", {
67
58
  type: pluginType
68
59
  });
69
60
  }
70
-
71
61
  const storageOperations = await providerPlugin.provide({
72
62
  context
73
63
  });
74
-
75
64
  if (!context.fileManager) {
76
65
  context.fileManager = {};
77
66
  }
78
-
79
67
  context.fileManager.settings = {
80
68
  async getSettings() {
81
69
  return storageOperations.get();
82
70
  },
83
-
84
71
  async createSettings(data) {
85
72
  const settings = new CreateDataModel().populate(data);
86
73
  await settings.validate();
@@ -89,7 +76,6 @@ const settingsCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context
89
76
  data: settingsData
90
77
  });
91
78
  },
92
-
93
79
  async updateSettings(data) {
94
80
  const updatedValue = new UpdateDataModel().populate(data);
95
81
  await updatedValue.validate();
@@ -99,15 +85,13 @@ const settingsCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context
99
85
  });
100
86
  return storageOperations.update({
101
87
  original: existingSettings,
102
- data: _objectSpread(_objectSpread({}, existingSettings), updatedSettings)
88
+ data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingSettings), updatedSettings)
103
89
  });
104
90
  },
105
-
106
91
  async deleteSettings() {
107
92
  await storageOperations.delete();
108
93
  return true;
109
94
  }
110
-
111
95
  };
112
96
  });
113
97
  settingsCrudContextPlugin.name = "FileMangerSettingsCrud";
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SETTINGS_KEY","CreateDataModel","withFields","uploadMinFileSize","number","value","validation","create","uploadMaxFileSize","srcPrefix","onSet","endsWith","string","UpdateDataModel","settingsCrudContextPlugin","ContextPlugin","context","pluginType","SettingsStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","settings","getSettings","get","createSettings","data","populate","validate","settingsData","toJSON","updateSettings","updatedValue","existingSettings","updatedSettings","onlyDirty","update","original","deleteSettings","delete","name"],"sources":["settings.crud.ts"],"sourcesContent":["/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { withFields, string, number, onSet } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport { FileManagerContext, FileManagerSettings } from \"~/types\";\nimport { SettingsStorageOperationsProviderPlugin } from \"~/plugins/definitions/SettingsStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\n\n// TODO @ts-refactor verify that this is not used and remove it\nexport const SETTINGS_KEY = \"file-manager\";\n\nconst CreateDataModel = withFields({\n uploadMinFileSize: number({ value: 0, validation: validation.create(\"gte:0\") }),\n uploadMaxFileSize: number({ value: 26214401 }),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string({ value: \"/files/\" }))\n})();\n\nconst UpdateDataModel = withFields({\n uploadMinFileSize: number({\n validation: validation.create(\"gte:0\")\n }),\n uploadMaxFileSize: number(),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string())\n})();\n\nconst settingsCrudContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = SettingsStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<SettingsStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n context.fileManager.settings = {\n async getSettings() {\n return storageOperations.get();\n },\n async createSettings(data) {\n const settings = new CreateDataModel().populate(data);\n await settings.validate();\n\n const settingsData: FileManagerSettings = await settings.toJSON();\n\n return storageOperations.create({\n data: settingsData\n });\n },\n async updateSettings(data) {\n const updatedValue = new UpdateDataModel().populate(data);\n await updatedValue.validate();\n\n const existingSettings = (await storageOperations.get()) as FileManagerSettings;\n\n const updatedSettings: Partial<FileManagerSettings> = await updatedValue.toJSON({\n onlyDirty: true\n });\n\n return storageOperations.update({\n original: existingSettings,\n data: {\n ...existingSettings,\n ...updatedSettings\n }\n });\n },\n async deleteSettings() {\n await storageOperations.delete();\n\n return true;\n }\n };\n});\n\nsettingsCrudContextPlugin.name = \"FileMangerSettingsCrud\";\n\nexport default settingsCrudContextPlugin;\n"],"mappings":";;;;;;;;AAIA;AACA;AAEA;AACA;AACA;AATA;AACA;AACA;AACA;;AAQA;AACO,MAAMA,YAAY,GAAG,cAAc;AAAC;AAE3C,MAAMC,eAAe,GAAG,IAAAC,kBAAU,EAAC;EAC/BC,iBAAiB,EAAE,IAAAC,cAAM,EAAC;IAAEC,KAAK,EAAE,CAAC;IAAEC,UAAU,EAAEA,sBAAU,CAACC,MAAM,CAAC,OAAO;EAAE,CAAC,CAAC;EAC/EC,iBAAiB,EAAE,IAAAJ,cAAM,EAAC;IAAEC,KAAK,EAAE;EAAS,CAAC,CAAC;EAC9CI,SAAS,EAAE,IAAAC,aAAK,EAAEL,KAAc,IAAK;IACjC;IACA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC3B,OAAOA,KAAK,CAACM,QAAQ,CAAC,GAAG,CAAC,GAAGN,KAAK,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AG;IAC3B,MAAMC,WAAW,GAAG;MAChB,OAAOJ,iBAAiB,CAACK,GAAG,EAAE;IAClC,CAAC;IACD,MAAMC,cAAc,CAACC,IAAI,EAAE;MACvB,MAAMJ,QAAQ,GAAG,IAAI3B,eAAe,EAAE,CAACgC,QAAQ,CAACD,IAAI,CAAC;MACrD,MAAMJ,QAAQ,CAACM,QAAQ,EAAE;MAEzB,MAAMC,YAAiC,GAAG,MAAMP,QAAQ,CAACQ,MAAM,EAAE;MAEjE,OAAOX,iBAAiB,CAAClB,MAAM,CAAC;QAC5ByB,IAAI,EAAEG;MACV,CAAC,CAAC;IACN,CAAC;IACD,MAAME,cAAc,CAACL,IAAI,EAAE;MACvB,MAAMM,YAAY,GAAG,IAAIzB,eAAe,EAAE,CAACoB,QAAQ,CAACD,IAAI,CAAC;MACzD,MAAMM,YAAY,CAACJ,QAAQ,EAAE;MAE7B,MAAMK,gBAAgB,GAAI,MAAMd,iBAAiB,CAACK,GAAG,EAA0B;MAE/E,MAAMU,eAA6C,GAAG,MAAMF,YAAY,CAACF,MAAM,CAAC;QAC5EK,SAAS,EAAE;MACf,CAAC,CAAC;MAEF,OAAOhB,iBAAiB,CAACiB,MAAM,CAAC;QAC5BC,QAAQ,EAAEJ,gBAAgB;QAC1BP,IAAI,8DACGO,gBAAgB,GAChBC,eAAe;MAE1B,CAAC,CAAC;IACN,CAAC;IACD,MAAMI,cAAc,GAAG;MACnB,MAAMnB,iBAAiB,CAACoB,MAAM,EAAE;MAEhC,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC,CAAC;AAEF/B,yBAAyB,CAACgC,IAAI,GAAG,wBAAwB;AAAC,eAE3ChC,yBAAyB;AAAA"}
@@ -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 systemCrudContextPlugin: ContextPlugin<FileManagerContext>;
4
4
  export default systemCrudContextPlugin;
@@ -1,64 +1,47 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _apiSecurity = require("@webiny/api-security");
13
-
14
10
  var _apiUpgrade = require("@webiny/api-upgrade");
15
-
16
11
  var _error = _interopRequireDefault(require("@webiny/error"));
17
-
18
- var _ContextPlugin = require("@webiny/handler/plugins/ContextPlugin");
19
-
12
+ var _api = require("@webiny/api");
20
13
  var _utils = require("../../utils");
21
-
22
14
  var _InstallationPlugin = require("../definitions/InstallationPlugin");
23
-
24
15
  var _SystemStorageOperationsProviderPlugin = require("../definitions/SystemStorageOperationsProviderPlugin");
25
-
26
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
27
-
28
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
29
-
30
- const systemCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context => {
16
+ const systemCrudContextPlugin = new _api.ContextPlugin(async context => {
31
17
  const pluginType = _SystemStorageOperationsProviderPlugin.SystemStorageOperationsProviderPlugin.type;
32
18
  const providerPlugin = context.plugins.byType(pluginType).find(() => true);
33
-
34
19
  if (!providerPlugin) {
35
20
  throw new _error.default(`Missing "${pluginType}" plugin.`, "PLUGIN_NOT_FOUND", {
36
21
  type: pluginType
37
22
  });
38
23
  }
39
-
40
24
  const storageOperations = await providerPlugin.provide({
41
25
  context
42
26
  });
43
-
44
27
  if (!context.fileManager) {
45
28
  context.fileManager = {};
46
29
  }
47
-
30
+ const getTenantId = () => {
31
+ return context.tenancy.getCurrentTenant().id;
32
+ };
48
33
  context.fileManager.system = {
49
34
  async getVersion() {
50
35
  const system = await storageOperations.get();
51
36
  return system ? system.version : null;
52
37
  },
53
-
54
38
  async setVersion(version) {
55
39
  const system = await storageOperations.get();
56
-
57
40
  if (system) {
58
- const data = _objectSpread(_objectSpread({}, system), {}, {
41
+ const data = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), {}, {
42
+ tenant: system.tenant || getTenantId(),
59
43
  version
60
44
  });
61
-
62
45
  try {
63
46
  await storageOperations.update({
64
47
  original: system,
@@ -71,11 +54,10 @@ const systemCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context =
71
54
  });
72
55
  }
73
56
  }
74
-
75
57
  const data = {
76
- version
58
+ version,
59
+ tenant: getTenantId()
77
60
  };
78
-
79
61
  try {
80
62
  await storageOperations.create({
81
63
  data
@@ -87,25 +69,24 @@ const systemCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context =
87
69
  });
88
70
  }
89
71
  },
90
-
91
72
  async install({
92
73
  srcPrefix
93
74
  }) {
75
+ const identity = context.security.getIdentity();
76
+ if (!identity) {
77
+ throw new _apiSecurity.NotAuthorizedError();
78
+ }
94
79
  const {
95
80
  fileManager
96
81
  } = context;
97
82
  const version = await fileManager.system.getVersion();
98
-
99
83
  if (version) {
100
84
  throw new _error.default("File Manager is already installed.", "FILES_INSTALL_ABORTED");
101
85
  }
102
-
103
86
  const data = {};
104
-
105
87
  if (srcPrefix) {
106
88
  data.srcPrefix = srcPrefix;
107
89
  }
108
-
109
90
  const installationPlugins = context.plugins.byType(_InstallationPlugin.InstallationPlugin.type);
110
91
  await (0, _utils.executeCallbacks)(installationPlugins, "beforeInstall", {
111
92
  context
@@ -117,14 +98,11 @@ const systemCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context =
117
98
  });
118
99
  return true;
119
100
  },
120
-
121
101
  async upgrade(version) {
122
102
  const identity = context.security.getIdentity();
123
-
124
103
  if (!identity) {
125
104
  throw new _apiSecurity.NotAuthorizedError();
126
105
  }
127
-
128
106
  const upgradePlugins = context.plugins.byType("api-upgrade").filter(pl => pl.app === "file-manager");
129
107
  const plugin = (0, _apiUpgrade.getApplicablePlugin)({
130
108
  deployedVersion: context.WEBINY_VERSION,
@@ -132,12 +110,12 @@ const systemCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context =
132
110
  upgradePlugins,
133
111
  upgradeToVersion: version
134
112
  });
135
- await plugin.apply(context); // Store new app version
113
+ await plugin.apply(context);
136
114
 
115
+ // Store new app version
137
116
  await context.fileManager.system.setVersion(version);
138
117
  return true;
139
118
  }
140
-
141
119
  };
142
120
  });
143
121
  systemCrudContextPlugin.name = "FileManagerSystemCrud";
@@ -0,0 +1 @@
1
+ {"version":3,"names":["systemCrudContextPlugin","ContextPlugin","context","pluginType","SystemStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","getTenantId","tenancy","getCurrentTenant","id","system","getVersion","get","version","setVersion","data","tenant","update","original","ex","create","install","srcPrefix","identity","security","getIdentity","NotAuthorizedError","installationPlugins","InstallationPlugin","executeCallbacks","settings","createSettings","WEBINY_VERSION","upgrade","upgradePlugins","filter","pl","app","plugin","getApplicablePlugin","deployedVersion","installedAppVersion","upgradeToVersion","apply","name"],"sources":["system.crud.ts"],"sourcesContent":["import { NotAuthorizedError } from \"@webiny/api-security\";\nimport { getApplicablePlugin } from \"@webiny/api-upgrade\";\nimport { FileManagerContext, FileManagerSettings, FileManagerSystem } from \"~/types\";\nimport { UpgradePlugin } from \"@webiny/api-upgrade/types\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { executeCallbacks } from \"~/utils\";\nimport { InstallationPlugin } from \"~/plugins/definitions/InstallationPlugin\";\nimport { SystemStorageOperationsProviderPlugin } from \"~/plugins/definitions/SystemStorageOperationsProviderPlugin\";\n\nconst systemCrudContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = SystemStorageOperationsProviderPlugin.type;\n const providerPlugin = context.plugins\n .byType<SystemStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const getTenantId = (): string => {\n return context.tenancy.getCurrentTenant().id;\n };\n\n context.fileManager.system = {\n async getVersion() {\n const system = await storageOperations.get();\n\n return system ? system.version : null;\n },\n async setVersion(version: string) {\n const system = await storageOperations.get();\n\n if (system) {\n const data: FileManagerSystem = {\n ...system,\n tenant: system.tenant || getTenantId(),\n version\n };\n try {\n await storageOperations.update({\n original: system,\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\n \"Could not update the system data.\",\n \"SYSTEM_UPDATE_ERROR\",\n {\n data\n }\n );\n }\n }\n\n const data: FileManagerSystem = {\n version,\n tenant: getTenantId()\n };\n try {\n await storageOperations.create({\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\"Could not create the system data.\", \"SYSTEM_CREATE_ERROR\", {\n data\n });\n }\n },\n async install({ srcPrefix }) {\n const identity = context.security.getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n const { fileManager } = context;\n const version = await fileManager.system.getVersion();\n\n if (version) {\n throw new WebinyError(\n \"File Manager is already installed.\",\n \"FILES_INSTALL_ABORTED\"\n );\n }\n\n const data: Partial<FileManagerSettings> = {};\n\n if (srcPrefix) {\n data.srcPrefix = srcPrefix;\n }\n\n const installationPlugins = context.plugins.byType<InstallationPlugin>(\n InstallationPlugin.type\n );\n\n await executeCallbacks<InstallationPlugin[\"beforeInstall\"]>(\n installationPlugins,\n \"beforeInstall\",\n {\n context\n }\n );\n\n await fileManager.settings.createSettings(data);\n\n await fileManager.system.setVersion(context.WEBINY_VERSION);\n\n await executeCallbacks<InstallationPlugin[\"afterInstall\"]>(\n installationPlugins,\n \"afterInstall\",\n {\n context\n }\n );\n\n return true;\n },\n async upgrade(version) {\n const identity = context.security.getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const upgradePlugins = context.plugins\n .byType<UpgradePlugin>(\"api-upgrade\")\n .filter(pl => pl.app === \"file-manager\");\n\n const plugin = getApplicablePlugin({\n deployedVersion: context.WEBINY_VERSION,\n installedAppVersion: await this.getVersion(),\n upgradePlugins,\n upgradeToVersion: version\n });\n\n await plugin.apply(context);\n\n // Store new app version\n await context.fileManager.system.setVersion(version);\n\n return true;\n }\n };\n});\n\nsystemCrudContextPlugin.name = \"FileManagerSystemCrud\";\n\nexport default systemCrudContextPlugin;\n"],"mappings":";;;;;;;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AAEA,MAAMA,uBAAuB,GAAG,IAAIC,kBAAa,CAAqB,MAAMC,OAAO,IAAI;EACnF,MAAMC,UAAU,GAAGC,4EAAqC,CAACC,IAAI;EAC7D,MAAMC,cAAc,GAAGJ,OAAO,CAACK,OAAO,CACjCC,MAAM,CAAwCL,UAAU,CAAC,CACzDM,IAAI,CAAC,MAAM,IAAI,CAAC;EAErB,IAAI,CAACH,cAAc,EAAE;IACjB,MAAM,IAAII,cAAW,CAAE,YAAWP,UAAW,WAAU,EAAE,kBAAkB,EAAE;MACzEE,IAAI,EAAEF;IACV,CAAC,CAAC;EACN;EAEA,MAAMQ,iBA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IAAIA,EAAE,CAACC,GAAG,KAAK,cAAc,CAAC;MAE5C,MAAMC,MAAM,GAAG,IAAAC,+BAAmB,EAAC;QAC/BC,eAAe,EAAE9C,OAAO,CAACsC,cAAc;QACvCS,mBAAmB,EAAE,MAAM,IAAI,CAAC9B,UAAU,EAAE;QAC5CuB,cAAc;QACdQ,gBAAgB,EAAE7B;MACtB,CAAC,CAAC;MAEF,MAAMyB,MAAM,CAACK,KAAK,CAACjD,OAAO,CAAC;;MAE3B;MACA,MAAMA,OAAO,CAACW,WAAW,CAACK,MAAM,CAACI,UAAU,CAACD,OAAO,CAAC;MAEpD,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC,CAAC;AAEFrB,uBAAuB,CAACoD,IAAI,GAAG,uBAAuB;AAAC,eAExCpD,uBAAuB;AAAA"}
@@ -4,30 +4,22 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _apiSecurity = require("@webiny/api-security");
9
-
10
8
  var _default = async (context, check = {}) => {
11
- await context.i18nContent.checkI18NContentPermission();
9
+ await context.i18n.checkI18NContentPermission();
12
10
  const filePermission = await context.security.getPermission("fm.file");
13
-
14
11
  if (!filePermission) {
15
12
  throw new _apiSecurity.NotAuthorizedError();
16
13
  }
17
-
18
14
  if (check.rwd && !hasRwd(filePermission, check.rwd)) {
19
15
  throw new _apiSecurity.NotAuthorizedError();
20
16
  }
21
-
22
17
  return filePermission;
23
18
  };
24
-
25
19
  exports.default = _default;
26
-
27
20
  const hasRwd = (filesFilePermission, rwd) => {
28
21
  if (typeof filesFilePermission.rwd !== "string") {
29
22
  return true;
30
23
  }
31
-
32
24
  return filesFilePermission.rwd.includes(rwd);
33
25
  };
@@ -0,0 +1 @@
1
+ {"version":3,"names":["context","check","i18n","checkI18NContentPermission","filePermission","security","getPermission","NotAuthorizedError","rwd","hasRwd","filesFilePermission","includes"],"sources":["checkBasePermissions.ts"],"sourcesContent":["import { FileManagerContext, FilePermission } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\nexport default async (\n context: FileManagerContext,\n check: { rwd?: string } = {}\n): Promise<FilePermission> => {\n await context.i18n.checkI18NContentPermission();\n const filePermission = await context.security.getPermission<FilePermission>(\"fm.file\");\n if (!filePermission) {\n throw new NotAuthorizedError();\n }\n if (check.rwd && !hasRwd(filePermission, check.rwd)) {\n throw new NotAuthorizedError();\n }\n\n return filePermission;\n};\n\nconst hasRwd = (filesFilePermission: FilePermission, rwd: string): boolean => {\n if (typeof filesFilePermission.rwd !== \"string\") {\n return true;\n }\n\n return filesFilePermission.rwd.includes(rwd);\n};\n"],"mappings":";;;;;;AACA;AAA0D,eAE3C,OACXA,OAA2B,EAC3BC,KAAuB,GAAG,CAAC,CAAC,KACF;EAC1B,MAAMD,OAAO,CAACE,IAAI,CAACC,0BAA0B,EAAE;EAC/C,MAAMC,cAAc,GAAG,MAAMJ,OAAO,CAACK,QAAQ,CAACC,aAAa,CAAiB,SAAS,CAAC;EACtF,IAAI,CAACF,cAAc,EAAE;IACjB,MAAM,IAAIG,+BAAkB,EAAE;EAClC;EACA,IAAIN,KAAK,CAACO,GAAG,IAAI,CAACC,MAAM,CAACL,cAAc,EAAEH,KAAK,CAACO,GAAG,CAAC,EAAE;IACjD,MAAM,IAAID,+BAAkB,EAAE;EAClC;EAEA,OAAOH,cAAc;AACzB,CAAC;AAAA;AAED,MAAMK,MAAM,GAAG,CAACC,mBAAmC,EAAEF,GAAW,KAAc;EAC1E,IAAI,OAAOE,mBAAmB,CAACF,GAAG,KAAK,QAAQ,EAAE;IAC7C,OAAO,IAAI;EACf;EAEA,OAAOE,mBAAmB,CAACF,GAAG,CAACG,QAAQ,CAACH,GAAG,CAAC;AAChD,CAAC"}
@@ -1,2 +1,5 @@
1
+ /**
2
+ * TODO @ts-refactor change for JOI or some other validation library
3
+ */
1
4
  declare const _default: (create?: boolean) => any;
2
5
  export default _default;
@@ -4,13 +4,20 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _fields = require("@commodo/fields");
9
-
10
8
  var _commodoFieldsObject = require("commodo-fields-object");
11
-
12
9
  var _validation = require("@webiny/validation");
13
-
10
+ /**
11
+ * Package @commodo/fields does not have types
12
+ */
13
+ // @ts-ignore
14
+ /**
15
+ * Package commodo-fields-object does not have types
16
+ */
17
+ // @ts-ignore
18
+ /**
19
+ * TODO @ts-refactor change for JOI or some other validation library
20
+ */
14
21
  var _default = (create = true) => {
15
22
  return (0, _fields.withFields)({
16
23
  key: (0, _fields.string)({
@@ -32,7 +39,6 @@ var _default = (create = true) => {
32
39
  if (!Array.isArray(value)) {
33
40
  return null;
34
41
  }
35
-
36
42
  return value.map(item => item.toLowerCase());
37
43
  })((0, _fields.string)({
38
44
  list: true,
@@ -40,18 +46,14 @@ var _default = (create = true) => {
40
46
  if (!Array.isArray(tags)) {
41
47
  return;
42
48
  }
43
-
44
49
  if (tags.length > 15) {
45
50
  throw Error("You cannot set more than 15 tags.");
46
51
  }
47
-
48
52
  for (let i = 0; i < tags.length; i++) {
49
53
  const tag = tags[i];
50
-
51
54
  if (typeof tag !== "string") {
52
55
  throw Error("Tag must be typeof string.");
53
56
  }
54
-
55
57
  if (tag.length > 50) {
56
58
  throw Error(`Tag ${tag} is more than 50 characters long.`);
57
59
  }
@@ -60,5 +62,4 @@ var _default = (create = true) => {
60
62
  }))
61
63
  })();
62
64
  };
63
-
64
65
  exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["create","withFields","key","string","validation","name","size","number","type","meta","object","value","private","tags","onSet","Array","isArray","map","item","toLowerCase","list","length","Error","i","tag"],"sources":["createFileModel.ts"],"sourcesContent":["/**\n * Package @commodo/fields does not have types\n */\n// @ts-ignore\nimport { withFields, string, number, onSet } from \"@commodo/fields\";\n/**\n * Package commodo-fields-object does not have types\n */\n// @ts-ignore\nimport { object } from \"commodo-fields-object\";\nimport { validation } from \"@webiny/validation\";\n\n/**\n * TODO @ts-refactor change for JOI or some other validation library\n */\nexport default (create = true) => {\n return withFields({\n key: string({\n validation: validation.create(`${create ? \"required,\" : \"\"}maxLength:1000`)\n }),\n name: string({ validation: validation.create(\"maxLength:1000\") }),\n size: number(),\n type: string({ validation: validation.create(\"maxLength:255\") }),\n meta: object({ value: { private: false } }),\n tags: onSet((value: string[]) => {\n if (!Array.isArray(value)) {\n return null;\n }\n\n return value.map(item => item.toLowerCase());\n })(\n string({\n list: true,\n validation: (tags: string[]) => {\n if (!Array.isArray(tags)) {\n return;\n }\n\n if (tags.length > 15) {\n throw Error(\"You cannot set more than 15 tags.\");\n }\n\n for (let i = 0; i < tags.length; i++) {\n const tag = tags[i];\n if (typeof tag !== \"string\") {\n throw Error(\"Tag must be typeof string.\");\n }\n\n if (tag.length > 50) {\n throw Error(`Tag ${tag} is more than 50 characters long.`);\n }\n }\n }\n })\n )\n })();\n};\n"],"mappings":";;;;;;AAIA;AAKA;AACA;AAVA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAIA;AACA;AACA;AAFA,eAGe,CAACA,MAAM,GAAG,IAAI,KAAK;EAC9B,OAAO,IAAAC,kBAAU,EAAC;IACdC,GAAG,EAAE,IAAAC,cAAM,EAAC;MACRC,UAAU,EAAEA,sBAAU,CAACJ,MAAM,CAAE,GAAEA,MAAM,GAAG,WAAW,GAAG,EAAG,gBAAe;IAC9E,CAAC,CAAC;IACFK,IAAI,EAAE,IAAAF,cAAM,EAAC;MAAEC,UAAU,EAAEA,sBAAU,CAACJ,MAAM,CAAC,gBAAgB;IAAE,CAAC,CAAC;IACjEM,IAAI,EAAE,IAAAC,cAAM,GAAE;IACdC,IAAI,EAAE,IAAAL,cAAM,EAAC;MAAEC,UAAU,EAAEA,sBAAU,CAACJ,MAAM,CAAC,eAAe;IAAE,CAAC,CAAC;IAChES,IAAI,EAAE,IAAAC,2BAAM,EAAC;MAAEC,KAAK,EAAE;QAAEC,OAAO,EAAE;MAAM;IAAE,CAAC,CAAC;IAC3CC,IAAI,EAAE,IAAAC,aAAK,EAAEH,KAAe,IAAK;MAC7B,IAAI,CAACI,KAAK,CAACC,OAAO,CAACL,KAAK,CAAC,EAAE;QACvB,OAAO,IAAI;MACf;MAEA,OAAOA,KAAK,CAACM,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACC,WAAW,EAAE,CAAC;IAChD,CAAC,CAAC,CACE,IAAAhB,cAAM,EAAC;MACHiB,IAAI,EAAE,IAAI;MACVhB,UAAU,EAAGS,IAAc,IAAK;QAC5B,IAAI,CAACE,KAAK,CAACC,OAAO,CAACH,IAAI,CAAC,EAAE;UACtB;QACJ;QAEA,IAAIA,IAAI,CAACQ,MAAM,GAAG,EAAE,EAAE;UAClB,MAAMC,KAAK,CAAC,mCAAmC,CAAC;QACpD;QAEA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGV,IAAI,CAACQ,MAAM,EAAEE,CAAC,EAAE,EAAE;UAClC,MAAMC,GAAG,GAAGX,IAAI,CAACU,CAAC,CAAC;UACnB,IAAI,OAAOC,GAAG,KAAK,QAAQ,EAAE;YACzB,MAAMF,KAAK,CAAC,4BAA4B,CAAC;UAC7C;UAEA,IAAIE,GAAG,CAACH,MAAM,GAAG,EAAE,EAAE;YACjB,MAAMC,KAAK,CAAE,OAAME,GAAI,mCAAkC,CAAC;UAC9D;QACJ;MACJ;IACJ,CAAC,CAAC;EAEV,CAAC,CAAC,EAAE;AACR,CAAC;AAAA"}
@@ -1,6 +1,6 @@
1
- import { FilePlugin } from "../../definitions/FilePlugin";
1
+ import { FilePlugin, FilePluginParams } from "../../definitions/FilePlugin";
2
2
  import { FileManagerContext } from "../../../types";
3
- export declare const runLifecycleEvent: (hook: string, params: {
3
+ export declare const runLifecycleEvent: (hook: keyof FilePluginParams, params: {
4
4
  context: FileManagerContext;
5
5
  plugins: FilePlugin[];
6
6
  } & Record<string, any>) => Promise<void>;
@@ -1,33 +1,30 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.runLifecycleEvent = void 0;
9
-
10
8
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
-
12
9
  const _excluded = ["plugins"];
10
+ // TODO @ts-refactor introduce pubsub methods
13
11
 
14
12
  const runLifecycleEvent = async (hook, params) => {
15
13
  const {
16
- plugins
17
- } = params,
18
- rest = (0, _objectWithoutProperties2.default)(params, _excluded);
19
-
14
+ plugins
15
+ } = params,
16
+ rest = (0, _objectWithoutProperties2.default)(params, _excluded);
20
17
  if (plugins.length === 0) {
21
18
  return;
22
19
  }
23
-
24
20
  for (const plugin of plugins) {
25
21
  if (!plugin[hook]) {
26
22
  continue;
27
23
  }
28
-
24
+ /**
25
+ * Keep any because we do not know which hook needs to be executed. This will be removed, so it does not matter.
26
+ */
29
27
  await plugin[hook](rest);
30
28
  }
31
29
  };
32
-
33
30
  exports.runLifecycleEvent = runLifecycleEvent;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["runLifecycleEvent","hook","params","plugins","rest","length","plugin"],"sources":["lifecycleEvents.ts"],"sourcesContent":["// TODO @ts-refactor introduce pubsub methods\nimport { FilePlugin, FilePluginParams } from \"~/plugins/definitions/FilePlugin\";\nimport { FileManagerContext } from \"~/types\";\n\nexport const runLifecycleEvent = async (\n hook: keyof FilePluginParams,\n params: { context: FileManagerContext; plugins: FilePlugin[] } & Record<string, any>\n): Promise<void> => {\n const { plugins, ...rest } = params;\n if (plugins.length === 0) {\n return;\n }\n for (const plugin of plugins) {\n if (!plugin[hook]) {\n continue;\n }\n /**\n * Keep any because we do not know which hook needs to be executed. This will be removed, so it does not matter.\n */\n await plugin[hook](rest as any);\n }\n};\n"],"mappings":";;;;;;;;;AAAA;;AAIO,MAAMA,iBAAiB,GAAG,OAC7BC,IAA4B,EAC5BC,MAAoF,KACpE;EAChB,MAAM;MAAEC;IAAiB,CAAC,GAAGD,MAAM;IAAfE,IAAI,0CAAKF,MAAM;EACnC,IAAIC,OAAO,CAACE,MAAM,KAAK,CAAC,EAAE;IACtB;EACJ;EACA,KAAK,MAAMC,MAAM,IAAIH,OAAO,EAAE;IAC1B,IAAI,CAACG,MAAM,CAACL,IAAI,CAAC,EAAE;MACf;IACJ;IACA;AACR;AACA;IACQ,MAAMK,MAAM,CAACL,IAAI,CAAC,CAACG,IAAI,CAAQ;EACnC;AACJ,CAAC;AAAC"}
@@ -1,22 +1,21 @@
1
1
  /// <reference types="node" />
2
2
  import { Plugin } from "@webiny/plugins";
3
3
  import { FileManagerSettings } from "../../types";
4
- export interface Params {
5
- upload: (args: UploadParams) => Promise<any>;
6
- delete: (args: DeleteParams) => Promise<void>;
4
+ export interface FilePhysicalStoragePluginParams<U extends FilePhysicalStoragePluginUploadParams, D extends FilePhysicalStoragePluginDeleteParams> {
5
+ upload: (args: U) => Promise<any>;
6
+ delete: (args: D) => Promise<void>;
7
7
  }
8
- export interface UploadParams {
8
+ export interface FilePhysicalStoragePluginUploadParams {
9
9
  settings: FileManagerSettings;
10
10
  buffer: Buffer;
11
- [key: string]: any;
12
11
  }
13
- export interface DeleteParams {
12
+ export interface FilePhysicalStoragePluginDeleteParams {
14
13
  key: string;
15
14
  }
16
- export declare class FilePhysicalStoragePlugin extends Plugin {
17
- static readonly type = "api-file-manager-storage";
15
+ export declare class FilePhysicalStoragePlugin<U extends FilePhysicalStoragePluginUploadParams = FilePhysicalStoragePluginUploadParams, D extends FilePhysicalStoragePluginDeleteParams = FilePhysicalStoragePluginDeleteParams> extends Plugin {
16
+ static readonly type: string;
18
17
  private readonly _params;
19
- constructor(params: Params);
20
- upload(params: UploadParams): Promise<any>;
21
- delete(params: DeleteParams): Promise<any>;
18
+ constructor(params: FilePhysicalStoragePluginParams<U, D>);
19
+ upload(params: U): Promise<any>;
20
+ delete(params: D): Promise<any>;
22
21
  }
@@ -1,42 +1,31 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
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");
@@ -0,0 +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,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"}
@@ -107,7 +107,7 @@ export interface AfterDeleteParams {
107
107
  *
108
108
  * @category FilePlugin
109
109
  */
110
- export interface Params {
110
+ export interface FilePluginParams {
111
111
  beforeCreate?: (params: BeforeCreateParams) => Promise<void>;
112
112
  afterCreate?: (params: AfterCreateParams) => Promise<void>;
113
113
  beforeUpdate?: (params: BeforeUpdateParams) => Promise<void>;
@@ -118,9 +118,9 @@ export interface Params {
118
118
  afterDelete?: (params: AfterDeleteParams) => Promise<void>;
119
119
  }
120
120
  export declare class FilePlugin extends Plugin {
121
- static readonly type = "fm.file";
121
+ static readonly type: string;
122
122
  private readonly _params;
123
- constructor(params?: Params);
123
+ constructor(params?: FilePluginParams);
124
124
  beforeCreate(params: BeforeCreateParams): Promise<void>;
125
125
  afterCreate(params: AfterCreateParams): Promise<void>;
126
126
  beforeUpdate(params: BeforeUpdateParams): Promise<void>;
@@ -129,5 +129,8 @@ export declare class FilePlugin extends Plugin {
129
129
  afterBatchCreate(params: AfterBatchCreateParams): Promise<void>;
130
130
  beforeDelete(params: BeforeDeleteParams): Promise<void>;
131
131
  afterDelete(params: AfterDeleteParams): Promise<void>;
132
+ /**
133
+ * Keep any here because it can be a number of params. Method is internal so no need to complicate the code.
134
+ */
132
135
  private _execute;
133
136
  }