@webiny/api-file-manager 0.0.0-mt-3 → 0.0.0-unstable.8c4d9f045a

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 (90) hide show
  1. package/handlers/download/index.d.ts +3 -3
  2. package/handlers/download/index.js +66 -59
  3. package/handlers/download/index.js.map +1 -0
  4. package/handlers/manage/index.d.ts +5 -3
  5. package/handlers/manage/index.js +47 -46
  6. package/handlers/manage/index.js.map +1 -0
  7. package/handlers/transform/index.d.ts +2 -3
  8. package/handlers/transform/index.js +67 -68
  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 +2 -3
  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.map +1 -0
  15. package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +7 -3
  16. package/handlers/transform/loaders/sanitizeImageTransformations.js +27 -20
  17. package/handlers/transform/loaders/sanitizeImageTransformations.js.map +1 -0
  18. package/handlers/transform/managers/imageManager.d.ts +12 -6
  19. package/handlers/transform/managers/imageManager.js +25 -17
  20. package/handlers/transform/managers/imageManager.js.map +1 -0
  21. package/handlers/transform/managers/index.d.ts +2 -6
  22. package/handlers/transform/managers/index.js.map +1 -0
  23. package/handlers/transform/optimizeImage.d.ts +2 -1
  24. package/handlers/transform/optimizeImage.js +3 -0
  25. package/handlers/transform/optimizeImage.js.map +1 -0
  26. package/handlers/transform/transformImage.d.ts +5 -4
  27. package/handlers/transform/transformImage.js +3 -3
  28. package/handlers/transform/transformImage.js.map +1 -0
  29. package/handlers/transform/utils.d.ts +2 -2
  30. package/handlers/transform/utils.js.map +1 -0
  31. package/handlers/types.d.ts +8 -0
  32. package/handlers/types.js +5 -0
  33. package/handlers/types.js.map +1 -0
  34. package/handlers/utils/getEnvironment.js.map +1 -0
  35. package/handlers/utils/getObjectParams.d.ts +3 -4
  36. package/handlers/utils/getObjectParams.js +0 -2
  37. package/handlers/utils/getObjectParams.js.map +1 -0
  38. package/handlers/utils/index.d.ts +0 -1
  39. package/handlers/utils/index.js +0 -8
  40. package/handlers/utils/index.js.map +1 -0
  41. package/package.json +28 -27
  42. package/plugins/crud/files/validation.js.map +1 -0
  43. package/plugins/crud/files.crud.d.ts +1 -1
  44. package/plugins/crud/files.crud.js +34 -24
  45. package/plugins/crud/files.crud.js.map +1 -0
  46. package/plugins/crud/settings.crud.d.ts +1 -1
  47. package/plugins/crud/settings.crud.js +5 -4
  48. package/plugins/crud/settings.crud.js.map +1 -0
  49. package/plugins/crud/system.crud.d.ts +1 -1
  50. package/plugins/crud/system.crud.js +17 -5
  51. package/plugins/crud/system.crud.js.map +1 -0
  52. package/plugins/crud/utils/checkBasePermissions.js +1 -1
  53. package/plugins/crud/utils/checkBasePermissions.js.map +1 -0
  54. package/plugins/crud/utils/createFileModel.d.ts +3 -0
  55. package/plugins/crud/utils/createFileModel.js +13 -0
  56. package/plugins/crud/utils/createFileModel.js.map +1 -0
  57. package/plugins/crud/utils/lifecycleEvents.d.ts +2 -2
  58. package/plugins/crud/utils/lifecycleEvents.js +5 -0
  59. package/plugins/crud/utils/lifecycleEvents.js.map +1 -0
  60. package/plugins/definitions/FilePhysicalStoragePlugin.d.ts +10 -11
  61. package/plugins/definitions/FilePhysicalStoragePlugin.js.map +1 -0
  62. package/plugins/definitions/FilePlugin.d.ts +6 -3
  63. package/plugins/definitions/FilePlugin.js +8 -2
  64. package/plugins/definitions/FilePlugin.js.map +1 -0
  65. package/plugins/definitions/FileStorageTransformPlugin.d.ts +9 -9
  66. package/plugins/definitions/FileStorageTransformPlugin.js.map +1 -0
  67. package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +4 -4
  68. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +1 -0
  69. package/plugins/definitions/InstallationPlugin.d.ts +9 -9
  70. package/plugins/definitions/InstallationPlugin.js +4 -2
  71. package/plugins/definitions/InstallationPlugin.js.map +1 -0
  72. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +4 -4
  73. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +1 -0
  74. package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +4 -4
  75. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +1 -0
  76. package/plugins/graphql.js +20 -4
  77. package/plugins/graphql.js.map +1 -0
  78. package/plugins/index.d.ts +1 -1
  79. package/plugins/index.js.map +1 -0
  80. package/plugins/storage/FileStorage.d.ts +23 -24
  81. package/plugins/storage/FileStorage.js +25 -15
  82. package/plugins/storage/FileStorage.js.map +1 -0
  83. package/plugins/storage/index.d.ts +1 -1
  84. package/plugins/storage/index.js +6 -2
  85. package/plugins/storage/index.js.map +1 -0
  86. package/types.d.ts +16 -12
  87. package/types.js.map +1 -0
  88. package/utils.js.map +1 -0
  89. package/handlers/utils/createHandler.d.ts +0 -24
  90. package/handlers/utils/createHandler.js +0 -68
@@ -0,0 +1 @@
1
+ {"version":3,"names":["BATCH_CREATE_MAX_FILES","checkOwnership","file","permission","context","own","identity","security","getIdentity","createdBy","id","NotAuthorizedError","getLocaleCode","i18n","WebinyError","locale","getContentLocale","code","filesContextCrudPlugin","ContextPlugin","pluginType","FilesStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","storageOperations","provide","fileManager","filePlugins","FilePlugin","files","getFile","checkBasePermissions","rwd","get","where","tenant","tenancy","getCurrentTenant","NotFoundError","createFile","input","mdbid","tags","Array","isArray","meta","private","createdOn","Date","toISOString","displayName","webinyVersion","WEBINY_VERSION","runLifecycleEvent","data","result","create","ex","message","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","length","map","results","createBatch","listFiles","params","limit","search","types","ids","after","initialWhere","sort","initialSort","type_in","tag_in","tag","toLowerCase","id_in","list","listTags","name"],"sources":["files.crud.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport {\n CreatedBy,\n File,\n FileManagerContext,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilePermission,\n FilesListOpts\n} from \"~/types\";\nimport checkBasePermissions from \"./utils/checkBasePermissions\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { FilePlugin } from \"~/plugins/definitions/FilePlugin\";\nimport { FilesStorageOperationsProviderPlugin } from \"~/plugins/definitions/FilesStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { runLifecycleEvent } from \"~/plugins/crud/utils/lifecycleEvents\";\n\nconst BATCH_CREATE_MAX_FILES = 20;\n\n/**\n * If permission is limited to \"own\" files only, check that current identity owns the file.\n */\nconst checkOwnership = (file: File, permission: FilePermission, context: FileManagerContext) => {\n if (permission?.own === true) {\n const identity = context.security.getIdentity();\n if (file.createdBy.id !== identity.id) {\n throw new NotAuthorizedError();\n }\n }\n};\n\nconst getLocaleCode = (context: FileManagerContext): string => {\n if (!context.i18n) {\n throw new WebinyError(\"Missing i18n on the FileManagerContext.\", \"MISSING_I18N\");\n }\n\n const locale = context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE\"\n );\n }\n\n if (!locale.code) {\n throw new WebinyError(\n \"Missing content locale code on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE_CODE\"\n );\n }\n return locale.code;\n};\n\nconst filesContextCrudPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = FilesStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<FilesStorageOperationsProviderPlugin>(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 filePlugins = context.plugins.byType<FilePlugin>(FilePlugin.type);\n\n context.fileManager.files = {\n async getFile(id: string) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n return file;\n },\n async createFile(input) {\n await checkBasePermissions(context, { rwd: \"w\" });\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n\n const id = mdbid();\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n id,\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeCreate\", {\n context,\n plugins: filePlugins,\n data: file\n });\n const result = await storageOperations.create({\n file\n });\n await runLifecycleEvent(\"afterCreate\", {\n context,\n plugins: filePlugins,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a file.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n file\n }\n );\n }\n },\n async updateFile(id, input) {\n const permission = await checkBasePermissions(context, { rwd: \"w\" });\n\n const original = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(original, permission, context);\n\n const file: File = {\n ...original,\n ...input,\n tags: Array.isArray(input.tags)\n ? input.tags\n : Array.isArray(original.tags)\n ? original.tags\n : [],\n id: original.id,\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file\n });\n const result = await storageOperations.update({\n original,\n file\n });\n await runLifecycleEvent(\"afterUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n original,\n file\n }\n );\n }\n },\n async deleteFile(id) {\n const permission = await checkBasePermissions(context, { rwd: \"d\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n try {\n await runLifecycleEvent(\"beforeDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n await storageOperations.delete({\n file\n });\n await runLifecycleEvent(\"afterDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete a file.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n id,\n file\n }\n );\n }\n\n return true;\n },\n async createFilesInBatch(inputs) {\n if (!Array.isArray(inputs)) {\n throw new WebinyError(`\"data\" must be an array.`, \"CREATE_FILES_NON_ARRAY\");\n }\n\n if (inputs.length === 0) {\n throw new WebinyError(\n `\"data\" argument must contain at least one file.`,\n \"CREATE_FILES_MIN_FILES\"\n );\n }\n\n if (inputs.length > BATCH_CREATE_MAX_FILES) {\n throw new WebinyError(\n `\"data\" argument must not contain more than ${BATCH_CREATE_MAX_FILES} files.`,\n \"CREATE_FILES_MAX_FILES\"\n );\n }\n\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n const createdBy: CreatedBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n\n const files: File[] = inputs.map(input => {\n return {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n id: mdbid(),\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy,\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n });\n\n try {\n await runLifecycleEvent(\"beforeBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files\n });\n const results = await storageOperations.createBatch({\n files\n });\n await runLifecycleEvent(\"afterBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files,\n files: results\n });\n return results;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a batch of files.\",\n ex.code || \"CREATE_FILES_ERROR\",\n {\n ...(ex.data || {}),\n files\n }\n );\n }\n },\n async listFiles(params: FilesListOpts = {}) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const {\n limit = 40,\n search = \"\",\n types = [],\n tags = [],\n ids = [],\n after = null,\n where: initialWhere,\n sort: initialSort\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...initialWhere,\n private: false,\n locale: getLocaleCode(context),\n tenant: context.tenancy.getCurrentTenant().id\n };\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (permission.own === true) {\n const identity = context.security.getIdentity();\n where.createdBy = identity.id;\n }\n /**\n * We need to map the old GraphQL definition to the new one.\n * That GQL definition is marked as deprecated.\n */\n /**\n * To have standardized where objects across the applications, we transform the types into type_in.\n */\n if (Array.isArray(types) && types.length > 0 && !where.type_in) {\n where.type_in = types;\n }\n /**\n * We are assigning search to tag and name search.\n * This should be treated as OR condition in the storage operations.\n */\n if (search && !where.search) {\n where.search = search;\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(tags) && tags.length > 0 && !where.tag_in) {\n where.tag_in = tags.map(tag => tag.toLowerCase());\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(ids) && ids.length > 0 && !where.id_in) {\n where.id_in = ids;\n }\n\n const sort =\n Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : [\"id_DESC\"];\n try {\n return await storageOperations.list({\n where,\n after,\n limit,\n sort\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list files by given parameters.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n where,\n after,\n limit,\n sort\n }\n );\n }\n },\n async listTags({ where: initialWhere, after, limit }) {\n await checkBasePermissions(context);\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n ...initialWhere,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n };\n\n const params = {\n where,\n limit: limit || 100000,\n after\n };\n\n try {\n const [tags] = await storageOperations.tags(params);\n if (Array.isArray(tags) === false) {\n return [];\n }\n /**\n * just to keep it standardized, sort by the tag ASC\n */\n return tags.sort();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not search for tags.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n params\n }\n );\n }\n }\n };\n});\n\nfilesContextCrudPlugin.name = \"FileManagerFilesCrud\";\n\nexport default filesContextCrudPlugin;\n"],"mappings":";;;;;;;;;;;AAIA;;AACA;;AACA;;AAUA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,sBAAsB,GAAG,EAA/B;AAEA;AACA;AACA;;AACA,MAAMC,cAAc,GAAG,CAACC,IAAD,EAAaC,UAAb,EAAyCC,OAAzC,KAAyE;EAC5F,IAAI,CAAAD,UAAU,SAAV,IAAAA,UAAU,WAAV,YAAAA,UAAU,CAAEE,GAAZ,MAAoB,IAAxB,EAA8B;IAC1B,MAAMC,QAAQ,GAAGF,OAAO,CAACG,QAAR,CAAiBC,WAAjB,EAAjB;;IACA,IAAIN,IAAI,CAACO,SAAL,CAA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C,OAAH,IAAc,4BADZ,EAEFD,EAAE,CAAC3C,IAAH,IAAW,uBAFT,kCAIM2C,EAAE,CAACH,IAAH,IAAW,EAJjB;UAKEiB;QALF,GAAN;MAQH;IACJ;;EA5WuB,CAA5B;AA8WH,CArY8B,CAA/B;AAuYAxD,sBAAsB,CAACwE,IAAvB,GAA8B,sBAA9B;eAEexE,sB"}
@@ -1,5 +1,5 @@
1
1
  import { FileManagerContext } from "../../types";
2
- import { ContextPlugin } from "@webiny/handler/plugins/ContextPlugin";
2
+ import { ContextPlugin } from "@webiny/api";
3
3
  export declare const SETTINGS_KEY = "file-manager";
4
4
  declare const settingsCrudContextPlugin: ContextPlugin<FileManagerContext>;
5
5
  export default settingsCrudContextPlugin;
@@ -17,12 +17,13 @@ var _SettingsStorageOperationsProviderPlugin = require("../definitions/SettingsS
17
17
 
18
18
  var _error = _interopRequireDefault(require("@webiny/error"));
19
19
 
20
- var _ContextPlugin = require("@webiny/handler/plugins/ContextPlugin");
20
+ var _api = require("@webiny/api");
21
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; }
22
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
23
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; }
24
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
25
 
26
+ // TODO @ts-refactor verify that this is not used and remove it
26
27
  const SETTINGS_KEY = "file-manager";
27
28
  exports.SETTINGS_KEY = SETTINGS_KEY;
28
29
  const CreateDataModel = (0, _fields.withFields)({
@@ -58,7 +59,7 @@ const UpdateDataModel = (0, _fields.withFields)({
58
59
  return value;
59
60
  })((0, _fields.string)())
60
61
  })();
61
- const settingsCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context => {
62
+ const settingsCrudContextPlugin = new _api.ContextPlugin(async context => {
62
63
  const pluginType = _SettingsStorageOperationsProviderPlugin.SettingsStorageOperationsProviderPlugin.type;
63
64
  const providerPlugin = context.plugins.byType(pluginType).find(() => true);
64
65
 
@@ -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;;;;;;AAEA;AACO,MAAMA,YAAY,GAAG,cAArB;;AAEP,MAAMC,eAAe,GAAG,IAAAC,kBAAA,EAAW;EAC/BC,iBAAiB,EAAE,IAAAC,cAAA,EAAO;IAAEC,KAAK,EAAE,CAAT;IAAYC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAkB,OAAlB;EAAxB,CAAP,CADY;EAE/BC,iBAAiB,EAAE,IAAAJ,cAAA,EAAO;IAAEC,KAAK,EAAE;EAAT,CAAP,CAFY;EAG/BI,SAAS,EAAE,IAAAC,aAAA,EAAOL,KAAD,IAAoB;IACjC;IACA,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC3B,OAAOA,KAAK,CAACM,QAAN,CAAe,GAAf,IAAsBN,KAAtB,GAA8BA,KAAK,GAAG,GAA7C;IACH;;IACD,OAAOA,KAAP;EACH,CANU,EAMR,IAAAO,cAAA,EAAO;IAAEP,KAAK,EAAE;EAAT,CAAP,CANQ;AAHoB,CAAX,GAAxB;AAYA,MAAMQ,eAAe,GAAG,IAAAX,kBAAA,EAAW;EAC/BC,iBAAiB,EAAE,IAAAC,cAAA,EAAO;IACtBE,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAkB,OAAlB;EADU,CAAP,CADY;EAI/BC,iBAAiB,EAAE,IAAAJ,cAAA,GAJY;EAK/BK,SAAS,EAAE,IAAAC,aAAA,EAAOL,KAAD,IAAoB;IACjC;IACA,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC3B,OA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AAY,GAAG,IAAIzB,eAAJ,GAAsBoB,QAAtB,CAA+BD,IAA/B,CAArB;MACA,MAAMM,YAAY,CAACJ,QAAb,EAAN;MAEA,MAAMK,gBAAgB,GAAI,MAAMd,iBAAiB,CAACK,GAAlB,EAAhC;MAEA,MAAMU,eAA6C,GAAG,MAAMF,YAAY,CAACF,MAAb,CAAoB;QAC5EK,SAAS,EAAE;MADiE,CAApB,CAA5D;MAIA,OAAOhB,iBAAiB,CAACiB,MAAlB,CAAyB;QAC5BC,QAAQ,EAAEJ,gBADkB;QAE5BP,IAAI,kCACGO,gBADH,GAEGC,eAFH;MAFwB,CAAzB,CAAP;IAOH,CA/B0B;;IAgC3B,MAAMI,cAAN,GAAuB;MACnB,MAAMnB,iBAAiB,CAACoB,MAAlB,EAAN;MAEA,OAAO,IAAP;IACH;;EApC0B,CAA/B;AAsCH,CA3DiC,CAAlC;AA6DA/B,yBAAyB,CAACgC,IAA1B,GAAiC,wBAAjC;eAEehC,yB"}
@@ -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;
@@ -15,7 +15,7 @@ var _apiUpgrade = require("@webiny/api-upgrade");
15
15
 
16
16
  var _error = _interopRequireDefault(require("@webiny/error"));
17
17
 
18
- var _ContextPlugin = require("@webiny/handler/plugins/ContextPlugin");
18
+ var _api = require("@webiny/api");
19
19
 
20
20
  var _utils = require("../../utils");
21
21
 
@@ -23,11 +23,11 @@ var _InstallationPlugin = require("../definitions/InstallationPlugin");
23
23
 
24
24
  var _SystemStorageOperationsProviderPlugin = require("../definitions/SystemStorageOperationsProviderPlugin");
25
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; }
26
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
27
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; }
28
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
29
29
 
30
- const systemCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context => {
30
+ const systemCrudContextPlugin = new _api.ContextPlugin(async context => {
31
31
  const pluginType = _SystemStorageOperationsProviderPlugin.SystemStorageOperationsProviderPlugin.type;
32
32
  const providerPlugin = context.plugins.byType(pluginType).find(() => true);
33
33
 
@@ -45,6 +45,10 @@ const systemCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context =
45
45
  context.fileManager = {};
46
46
  }
47
47
 
48
+ const getTenantId = () => {
49
+ return context.tenancy.getCurrentTenant().id;
50
+ };
51
+
48
52
  context.fileManager.system = {
49
53
  async getVersion() {
50
54
  const system = await storageOperations.get();
@@ -56,6 +60,7 @@ const systemCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context =
56
60
 
57
61
  if (system) {
58
62
  const data = _objectSpread(_objectSpread({}, system), {}, {
63
+ tenant: system.tenant || getTenantId(),
59
64
  version
60
65
  });
61
66
 
@@ -73,7 +78,8 @@ const systemCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context =
73
78
  }
74
79
 
75
80
  const data = {
76
- version
81
+ version,
82
+ tenant: getTenantId()
77
83
  };
78
84
 
79
85
  try {
@@ -91,6 +97,12 @@ const systemCrudContextPlugin = new _ContextPlugin.ContextPlugin(async context =
91
97
  async install({
92
98
  srcPrefix
93
99
  }) {
100
+ const identity = context.security.getIdentity();
101
+
102
+ if (!identity) {
103
+ throw new _apiSecurity.NotAuthorizedError();
104
+ }
105
+
94
106
  const {
95
107
  fileManager
96
108
  } = context;
@@ -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,kBAAJ,CAAsC,MAAMC,OAAN,IAAiB;EACnF,MAAMC,UAAU,GAAGC,4EAAA,CAAsCC,IAAzD;EACA,MAAMC,cAAc,GAAGJ,OAAO,CAACK,OAAR,CAClBC,MADkB,CAC4BL,UAD5B,EAElBM,IAFkB,CAEb,MAAM,IAFO,CAAvB;;EAIA,IAAI,CAACH,cAAL,EAAqB;IACjB,MAAM,IAAII,cAAJ,CAAiB,YAAWP,UAAW,WAAvC,EAAmD,kBAAnD,EAAuE;MACzEE,IAAI,EAAEF;IADmE,CAAvE,CAAN;EAGH;;EAED,MAAMQ,iBAAiB,GAAG,MAAML,cAAc,CAACM,OAAf,CAAuB;IACnDV;EADmD,CAAvB,CAAhC;;EAIA,IAAI,CAACA,OAAO,CAACW,WAAb,EAA0B;IACtBX,OAAO,CAACW,WAAR,GAAsB,EAAtB;EACH;;EAED,MAAMC,WAAW,GAAG,MAAc;IAC9B,OAAOZ,OAAO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,EAAE,MAAM,KAAK9B,UAAL,EAFI;QAG/BuB,cAH+B;QAI/BQ,gBAAgB,EAAE7B;MAJa,CAApB,CAAf;MAOA,MAAMyB,MAAM,CAACK,KAAP,CAAajD,OAAb,CAAN,CAjBmB,CAmBnB;;MACA,MAAMA,OAAO,CAACW,WAAR,CAAoBK,MAApB,CAA2BI,UAA3B,CAAsCD,OAAtC,CAAN;MAEA,OAAO,IAAP;IACH;;EArHwB,CAA7B;AAuHH,CA/I+B,CAAhC;AAiJArB,uBAAuB,CAACoD,IAAxB,GAA+B,uBAA/B;eAEepD,uB"}
@@ -8,7 +8,7 @@ exports.default = void 0;
8
8
  var _apiSecurity = require("@webiny/api-security");
9
9
 
10
10
  var _default = async (context, check = {}) => {
11
- await context.i18nContent.checkI18NContentPermission();
11
+ await context.i18n.checkI18NContentPermission();
12
12
  const filePermission = await context.security.getPermission("fm.file");
13
13
 
14
14
  if (!filePermission) {
@@ -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;;eAEe,OACXA,OADW,EAEXC,KAAuB,GAAG,EAFf,KAGe;EAC1B,MAAMD,OAAO,CAACE,IAAR,CAAaC,0BAAb,EAAN;EACA,MAAMC,cAAc,GAAG,MAAMJ,OAAO,CAACK,QAAR,CAAiBC,aAAjB,CAA+C,SAA/C,CAA7B;;EACA,IAAI,CAACF,cAAL,EAAqB;IACjB,MAAM,IAAIG,+BAAJ,EAAN;EACH;;EACD,IAAIN,KAAK,CAACO,GAAN,IAAa,CAACC,MAAM,CAACL,cAAD,EAAiBH,KAAK,CAACO,GAAvB,CAAxB,EAAqD;IACjD,MAAM,IAAID,+BAAJ,EAAN;EACH;;EAED,OAAOH,cAAP;AACH,C;;;;AAED,MAAMK,MAAM,GAAG,CAACC,mBAAD,EAAsCF,GAAtC,KAA+D;EAC1E,IAAI,OAAOE,mBAAmB,CAACF,GAA3B,KAAmC,QAAvC,EAAiD;IAC7C,OAAO,IAAP;EACH;;EAED,OAAOE,mBAAmB,CAACF,GAApB,CAAwBG,QAAxB,CAAiCH,GAAjC,CAAP;AACH,CAND"}
@@ -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;
@@ -11,6 +11,19 @@ var _commodoFieldsObject = require("commodo-fields-object");
11
11
 
12
12
  var _validation = require("@webiny/validation");
13
13
 
14
+ /**
15
+ * Package @commodo/fields does not have types
16
+ */
17
+ // @ts-ignore
18
+
19
+ /**
20
+ * Package commodo-fields-object does not have types
21
+ */
22
+ // @ts-ignore
23
+
24
+ /**
25
+ * TODO @ts-refactor change for JOI or some other validation library
26
+ */
14
27
  var _default = (create = true) => {
15
28
  return (0, _fields.withFields)({
16
29
  key: (0, _fields.string)({
@@ -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;eACe,CAACA,MAAM,GAAG,IAAV,KAAmB;EAC9B,OAAO,IAAAC,kBAAA,EAAW;IACdC,GAAG,EAAE,IAAAC,cAAA,EAAO;MACRC,UAAU,EAAEA,sBAAA,CAAWJ,MAAX,CAAmB,GAAEA,MAAM,GAAG,WAAH,GAAiB,EAAG,gBAA/C;IADJ,CAAP,CADS;IAIdK,IAAI,EAAE,IAAAF,cAAA,EAAO;MAAEC,UAAU,EAAEA,sBAAA,CAAWJ,MAAX,CAAkB,gBAAlB;IAAd,CAAP,CAJQ;IAKdM,IAAI,EAAE,IAAAC,cAAA,GALQ;IAMdC,IAAI,EAAE,IAAAL,cAAA,EAAO;MAAEC,UAAU,EAAEA,sBAAA,CAAWJ,MAAX,CAAkB,eAAlB;IAAd,CAAP,CANQ;IAOdS,IAAI,EAAE,IAAAC,2BAAA,EAAO;MAAEC,KAAK,EAAE;QAAEC,OAAO,EAAE;MAAX;IAAT,CAAP,CAPQ;IAQdC,IAAI,EAAE,IAAAC,aAAA,EAAOH,KAAD,IAAqB;MAC7B,IAAI,CAACI,KAAK,CAACC,OAAN,CAAcL,KAAd,CAAL,EAA2B;QACvB,OAAO,IAAP;MACH;;MAED,OAAOA,KAAK,CAACM,GAAN,CAAUC,IAAI,IAAIA,IAAI,CAACC,WAAL,EAAlB,CAAP;IACH,CANK,EAOF,IAAAhB,cAAA,EAAO;MACHiB,IAAI,EAAE,IADH;MAEHhB,UAAU,EAAGS,IAAD,IAAoB;QAC5B,IAAI,CAACE,KAAK,CAACC,OAAN,CAAcH,IAAd,CAAL,EAA0B;UACtB;QACH;;QAED,IAAIA,IAAI,CAACQ,MAAL,GAAc,EAAlB,EAAsB;UAClB,MAAMC,KAAK,CAAC,mCAAD,CAAX;QACH;;QAED,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGV,IAAI,CAACQ,MAAzB,EAAiCE,CAAC,EAAlC,EAAsC;UAClC,MAAMC,GAAG,GAAGX,IAAI,CAACU,CAAD,CAAhB;;UACA,IAAI,OAAOC,GAAP,KAAe,QAAnB,EAA6B;YACzB,MAAMF,KAAK,CAAC,4BAAD,CAAX;UACH;;UAED,IAAIE,GAAG,CAACH,MAAJ,GAAa,EAAjB,EAAqB;YACjB,MAAMC,KAAK,CAAE,OAAME,GAAI,mCAAZ,CAAX;UACH;QACJ;MACJ;IArBE,CAAP,CAPE;EARQ,CAAX,GAAP;AAwCH,C"}
@@ -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>;
@@ -11,6 +11,7 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
11
11
 
12
12
  const _excluded = ["plugins"];
13
13
 
14
+ // TODO @ts-refactor introduce pubsub methods
14
15
  const runLifecycleEvent = async (hook, params) => {
15
16
  const {
16
17
  plugins
@@ -25,6 +26,10 @@ const runLifecycleEvent = async (hook, params) => {
25
26
  if (!plugin[hook]) {
26
27
  continue;
27
28
  }
29
+ /**
30
+ * Keep any because we do not know which hook needs to be executed. This will be removed, so it does not matter.
31
+ */
32
+
28
33
 
29
34
  await plugin[hook](rest);
30
35
  }
@@ -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,IAD6B,EAE7BC,MAF6B,KAGb;EAChB,MAAM;IAAEC;EAAF,IAAuBD,MAA7B;EAAA,MAAoBE,IAApB,0CAA6BF,MAA7B;;EACA,IAAIC,OAAO,CAACE,MAAR,KAAmB,CAAvB,EAA0B;IACtB;EACH;;EACD,KAAK,MAAMC,MAAX,IAAqBH,OAArB,EAA8B;IAC1B,IAAI,CAACG,MAAM,CAACL,IAAD,CAAX,EAAmB;MACf;IACH;IACD;AACR;AACA;;;IACQ,MAAMK,MAAM,CAACL,IAAD,CAAN,CAAaG,IAAb,CAAN;EACH;AACJ,CAjBM"}
@@ -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
  }
@@ -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,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"}
@@ -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
  }
@@ -49,13 +49,19 @@ class FilePlugin extends _plugins.Plugin {
49
49
  async afterDelete(params) {
50
50
  await this._execute("afterDelete", params);
51
51
  }
52
+ /**
53
+ * Keep any here because it can be a number of params. Method is internal so no need to complicate the code.
54
+ */
55
+
52
56
 
53
57
  async _execute(callback, params) {
54
- if (typeof this._params[callback] !== "function") {
58
+ const cb = this._params[callback];
59
+
60
+ if (typeof cb !== "function") {
55
61
  return;
56
62
  }
57
63
 
58
- await this._params[callback](params);
64
+ await cb(params);
59
65
  }
60
66
 
61
67
  }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FilePlugin","Plugin","constructor","params","_params","beforeCreate","_execute","afterCreate","beforeUpdate","afterUpdate","beforeBatchCreate","afterBatchCreate","beforeDelete","afterDelete","callback","cb"],"sources":["FilePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { File, FileManagerContext } from \"~/types\";\n\n/**\n * Parameters for beforeCreate lifecycle.\n */\nexport interface BeforeCreateParams {\n context: FileManagerContext;\n /**\n * Data to be inserted into the storage.\n */\n data: File;\n}\n/**\n * Parameters for afterCreate lifecycle.\n */\nexport interface AfterCreateParams {\n context: FileManagerContext;\n /**\n * Data that was inserted into the storage.\n */\n data: File;\n /**\n * Result of the storage operations create method.\n * Possibly changed something on the \"data\".\n */\n file: File;\n}\n/**\n * Parameters for beforeUpdate lifecycle.\n */\nexport interface BeforeUpdateParams {\n context: FileManagerContext;\n /**\n * Original file from the storage.\n */\n original: File;\n /**\n * Data to be updated to the storage.\n */\n data: File;\n}\n/**\n * Parameters for afterUpdate lifecycle.\n */\nexport interface AfterUpdateParams {\n context: FileManagerContext;\n /**\n * Original file from the storage.\n */\n original: File;\n /**\n * Data that was updated in the storage.\n */\n data: File;\n /**\n * Result of the storage operations update method.\n * Possibly changed something on the \"data\".\n */\n file: File;\n}\n/**\n * Parameters for beforeBatchCreate lifecycle.\n */\nexport interface BeforeBatchCreateParams {\n context: FileManagerContext;\n /**\n * Files to be inserted into the storage.\n */\n data: File[];\n}\n\n/**\n * Parameters for afterBatchCreate lifecycle.\n */\nexport interface AfterBatchCreateParams {\n context: FileManagerContext;\n /**\n * Files that were inserted into the storage.\n */\n data: File[];\n /**\n * Results of the insert.\n */\n files: File[];\n}\n/**\n * Parameters for beforeDelete lifecycle.\n */\nexport interface BeforeDeleteParams {\n context: FileManagerContext;\n /**\n * File to be deleted from the storage.\n */\n file: File;\n}\n/**\n * Parameters for afterDelete lifecycle.\n */\nexport interface AfterDeleteParams {\n context: FileManagerContext;\n /**\n * File that was deleted from the storage.\n */\n file: File;\n}\n\n/**\n * Definition for the constructor parameters of the FilePlugin.\n *\n * @category FilePlugin\n */\nexport interface FilePluginParams {\n beforeCreate?: (params: BeforeCreateParams) => Promise<void>;\n afterCreate?: (params: AfterCreateParams) => Promise<void>;\n beforeUpdate?: (params: BeforeUpdateParams) => Promise<void>;\n afterUpdate?: (params: AfterUpdateParams) => Promise<void>;\n beforeBatchCreate?: (params: BeforeBatchCreateParams) => Promise<void>;\n afterBatchCreate?: (params: AfterBatchCreateParams) => Promise<void>;\n beforeDelete?: (params: BeforeDeleteParams) => Promise<void>;\n afterDelete?: (params: AfterDeleteParams) => Promise<void>;\n}\n\nexport class FilePlugin extends Plugin {\n public static override readonly type: string = \"fm.file\";\n private readonly _params: FilePluginParams;\n\n public constructor(params?: FilePluginParams) {\n super();\n this._params = params || ({} as any);\n }\n\n public async beforeCreate(params: BeforeCreateParams): Promise<void> {\n await this._execute(\"beforeCreate\", params);\n }\n\n public async afterCreate(params: AfterCreateParams): Promise<void> {\n await this._execute(\"afterCreate\", params);\n }\n\n public async beforeUpdate(params: BeforeUpdateParams): Promise<void> {\n await this._execute(\"beforeUpdate\", params);\n }\n\n public async afterUpdate(params: AfterUpdateParams): Promise<void> {\n await this._execute(\"afterUpdate\", params);\n }\n\n public async beforeBatchCreate(params: BeforeBatchCreateParams): Promise<void> {\n await this._execute(\"beforeBatchCreate\", params);\n }\n\n public async afterBatchCreate(params: AfterBatchCreateParams): Promise<void> {\n await this._execute(\"afterBatchCreate\", params);\n }\n\n public async beforeDelete(params: BeforeDeleteParams): Promise<void> {\n await this._execute(\"beforeDelete\", params);\n }\n\n public async afterDelete(params: AfterDeleteParams): Promise<void> {\n await this._execute(\"afterDelete\", params);\n }\n /**\n * Keep any here because it can be a number of params. Method is internal so no need to complicate the code.\n */\n private async _execute(callback: keyof FilePluginParams, params: any): Promise<void> {\n const cb = this._params[callback];\n if (typeof cb !== \"function\") {\n return;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B;IACH;;IACD,MAAMA,EAAE,CAACZ,MAAD,CAAR;EACH;;AAjDkC;;;8BAA1BH,U,UACsC,S"}
@@ -1,34 +1,34 @@
1
1
  import { Plugin } from "@webiny/plugins";
2
2
  import { File } from "../../types";
3
- export interface ToParams {
3
+ export interface FileStorageTransformPluginToParams {
4
4
  /**
5
5
  * File that is being sent to the storage operations method.
6
6
  */
7
7
  file: File & Record<string, any>;
8
8
  }
9
- export interface FromParams {
9
+ export interface FileStorageTransformPluginFromParams {
10
10
  /**
11
11
  * File that was fetched from the storage operations method.
12
12
  */
13
13
  file: File & Record<string, any>;
14
14
  }
15
- export interface Params {
16
- toStorage?: (params: ToParams) => Promise<File & Record<string, any>>;
17
- fromStorage?: (params: FromParams) => Promise<File & Record<string, any>>;
15
+ export interface FileStorageTransformPluginParams {
16
+ toStorage?: (params: FileStorageTransformPluginToParams) => Promise<File & Record<string, any>>;
17
+ fromStorage?: (params: FileStorageTransformPluginFromParams) => Promise<File & Record<string, any>>;
18
18
  }
19
19
  export declare class FileStorageTransformPlugin extends Plugin {
20
- static readonly type = "fm.files.storage.transform";
20
+ static readonly type: string;
21
21
  private readonly _params;
22
- constructor(params: Params);
22
+ constructor(params: FileStorageTransformPluginParams);
23
23
  /**
24
24
  * Transform the file value into something that can be stored.
25
25
  * Be aware that you must return the whole file object.
26
26
  */
27
- toStorage(params: ToParams): Promise<File & Record<string, any>>;
27
+ toStorage(params: FileStorageTransformPluginToParams): Promise<File & Record<string, any>>;
28
28
  /**
29
29
  * Transform the file value from the storage type to one required by our system.
30
30
  * Be aware that you must return the whole file object.
31
31
  * This method MUST reverse what ever toStorage method changed on the file object.
32
32
  */
33
- fromStorage(params: FromParams): Promise<File & Record<string, any>>;
33
+ fromStorage(params: FileStorageTransformPluginFromParams): Promise<File & Record<string, any>>;
34
34
  }
@@ -0,0 +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,9 +1,9 @@
1
1
  import { Plugin } from "@webiny/plugins";
2
2
  import { FileManagerContext, FileManagerFilesStorageOperations } from "../../types";
3
- export interface Params {
4
- context: FileManagerContext;
3
+ export interface FilesStorageOperationsProviderPluginParams<T = FileManagerContext> {
4
+ context: T;
5
5
  }
6
6
  export declare abstract class FilesStorageOperationsProviderPlugin extends Plugin {
7
- static readonly type = "fm.storageOperationsProvider.files";
8
- abstract provide(params: Params): Promise<FileManagerFilesStorageOperations>;
7
+ static readonly type: string;
8
+ abstract provide(params: FilesStorageOperationsProviderPluginParams): Promise<FileManagerFilesStorageOperations>;
9
9
  }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FilesStorageOperationsProviderPlugin","Plugin"],"sources":["FilesStorageOperationsProviderPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FileManagerContext, FileManagerFilesStorageOperations } from \"~/types\";\n\nexport interface FilesStorageOperationsProviderPluginParams<T = FileManagerContext> {\n context: T;\n}\n\nexport abstract class FilesStorageOperationsProviderPlugin extends Plugin {\n public static override readonly type: string = \"fm.storageOperationsProvider.files\";\n\n public abstract provide(\n params: FilesStorageOperationsProviderPluginParams\n ): Promise<FileManagerFilesStorageOperations>;\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAeA,oCAAf,SAA4DC,eAA5D,CAAmE;;;8BAApDD,oC,UAC6B,oC"}
@@ -1,19 +1,19 @@
1
1
  import { FileManagerContext } from "../../types";
2
2
  import { Plugin } from "@webiny/plugins";
3
- export declare type CallbackFunction<TParams> = (params: TParams) => Promise<void>;
4
- export interface Params {
3
+ export interface InstallationPluginParams {
5
4
  context: FileManagerContext;
6
5
  }
7
- interface Config {
8
- beforeInstall?: CallbackFunction<Params>;
9
- afterInstall?: CallbackFunction<Params>;
6
+ export declare type CallbackFunction<TParams> = (params: TParams) => Promise<void>;
7
+ interface InstallationPluginConfig {
8
+ beforeInstall?: CallbackFunction<InstallationPluginParams>;
9
+ afterInstall?: CallbackFunction<InstallationPluginParams>;
10
10
  }
11
11
  export declare abstract class InstallationPlugin extends Plugin {
12
- static readonly type = "fm.install";
12
+ static readonly type: string;
13
13
  private readonly _config;
14
- constructor(config?: Partial<Config>);
15
- beforeInstall(params: Params): Promise<void>;
16
- afterInstall(params: Params): Promise<void>;
14
+ constructor(config?: Partial<InstallationPluginConfig>);
15
+ beforeInstall(params: InstallationPluginParams): Promise<void>;
16
+ afterInstall(params: InstallationPluginParams): Promise<void>;
17
17
  private _execute;
18
18
  }
19
19
  export {};
@@ -27,11 +27,13 @@ class InstallationPlugin extends _plugins.Plugin {
27
27
  }
28
28
 
29
29
  async _execute(callback, params) {
30
- if (typeof this._config[callback] !== "function") {
30
+ const cb = this._config[callback];
31
+
32
+ if (!cb) {
31
33
  return;
32
34
  }
33
35
 
34
- return this._config[callback](params);
36
+ return cb(params);
35
37
  }
36
38
 
37
39
  }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["InstallationPlugin","Plugin","constructor","config","_config","beforeInstall","params","_execute","afterInstall","callback","cb"],"sources":["InstallationPlugin.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport { Plugin } from \"@webiny/plugins\";\n\nexport interface InstallationPluginParams {\n context: FileManagerContext;\n}\nexport type CallbackFunction<TParams> = (params: TParams) => Promise<void>;\n\ninterface InstallationPluginConfig {\n beforeInstall?: CallbackFunction<InstallationPluginParams>;\n afterInstall?: CallbackFunction<InstallationPluginParams>;\n}\n\nexport abstract class InstallationPlugin extends Plugin {\n public static override readonly type: string = \"fm.install\";\n private readonly _config: Partial<InstallationPluginConfig>;\n\n constructor(config?: Partial<InstallationPluginConfig>) {\n super();\n this._config = config || {};\n }\n\n public async beforeInstall(params: InstallationPluginParams): Promise<void> {\n return this._execute(\"beforeInstall\", params);\n }\n\n public async afterInstall(params: InstallationPluginParams): Promise<void> {\n return this._execute(\"afterInstall\", params);\n }\n\n private async _execute(\n callback: keyof InstallationPluginConfig,\n params: InstallationPluginParams\n ): Promise<void> {\n const cb = this._config[callback];\n if (!cb) {\n return;\n }\n return cb(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AACA;;AAYO,MAAeA,kBAAf,SAA0CC,eAA1C,CAAiD;EAIpDC,WAAW,CAACC,MAAD,EAA6C;IACpD;IADoD;IAEpD,KAAKC,OAAL,GAAeD,MAAM,IAAI,EAAzB;EACH;;EAEyB,MAAbE,aAAa,CAACC,MAAD,EAAkD;IACxE,OAAO,KAAKC,QAAL,CAAc,eAAd,EAA+BD,MAA/B,CAAP;EACH;;EAEwB,MAAZE,YAAY,CAACF,MAAD,EAAkD;IACvE,OAAO,KAAKC,QAAL,CAAc,cAAd,EAA8BD,MAA9B,CAAP;EACH;;EAEqB,MAARC,QAAQ,CAClBE,QADkB,EAElBH,MAFkB,EAGL;IACb,MAAMI,EAAE,GAAG,KAAKN,OAAL,CAAaK,QAAb,CAAX;;IACA,IAAI,CAACC,EAAL,EAAS;MACL;IACH;;IACD,OAAOA,EAAE,CAACJ,MAAD,CAAT;EACH;;AA1BmD;;;8BAAlCN,kB,UAC6B,Y"}
@@ -1,9 +1,9 @@
1
1
  import { Plugin } from "@webiny/plugins";
2
2
  import { FileManagerContext, FileManagerSettingsStorageOperations } from "../../types";
3
- export interface Params {
4
- context: FileManagerContext;
3
+ export interface SettingsStorageOperationsProviderPluginParams<T = FileManagerContext> {
4
+ context: T;
5
5
  }
6
6
  export declare abstract class SettingsStorageOperationsProviderPlugin extends Plugin {
7
- static readonly type = "fm.storageOperationsProvider.settings";
8
- abstract provide(params: Params): Promise<FileManagerSettingsStorageOperations>;
7
+ static readonly type: string;
8
+ abstract provide(params: SettingsStorageOperationsProviderPluginParams): Promise<FileManagerSettingsStorageOperations>;
9
9
  }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SettingsStorageOperationsProviderPlugin","Plugin"],"sources":["SettingsStorageOperationsProviderPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FileManagerContext, FileManagerSettingsStorageOperations } from \"~/types\";\n\nexport interface SettingsStorageOperationsProviderPluginParams<T = FileManagerContext> {\n context: T;\n}\n\nexport abstract class SettingsStorageOperationsProviderPlugin extends Plugin {\n public static override readonly type: string = \"fm.storageOperationsProvider.settings\";\n\n public abstract provide(\n params: SettingsStorageOperationsProviderPluginParams\n ): Promise<FileManagerSettingsStorageOperations>;\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAeA,uCAAf,SAA+DC,eAA/D,CAAsE;;;8BAAvDD,uC,UAC6B,uC"}
@@ -1,9 +1,9 @@
1
1
  import { Plugin } from "@webiny/plugins";
2
2
  import { FileManagerContext, FileManagerSystemStorageOperations } from "../../types";
3
- export interface Params {
4
- context: FileManagerContext;
3
+ export interface SystemStorageOperationsProviderPluginParams<T = FileManagerContext> {
4
+ context: T;
5
5
  }
6
6
  export declare abstract class SystemStorageOperationsProviderPlugin extends Plugin {
7
- static readonly type = "fm.storageOperationsProvider.system";
8
- abstract provide(params: Params): Promise<FileManagerSystemStorageOperations>;
7
+ static readonly type: string;
8
+ abstract provide(params: SystemStorageOperationsProviderPluginParams): Promise<FileManagerSystemStorageOperations>;
9
9
  }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SystemStorageOperationsProviderPlugin","Plugin"],"sources":["SystemStorageOperationsProviderPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FileManagerContext, FileManagerSystemStorageOperations } from \"~/types\";\n\nexport interface SystemStorageOperationsProviderPluginParams<T = FileManagerContext> {\n context: T;\n}\n\nexport abstract class SystemStorageOperationsProviderPlugin extends Plugin {\n public static override readonly type: string = \"fm.storageOperationsProvider.system\";\n\n public abstract provide(\n params: SystemStorageOperationsProviderPluginParams\n ): Promise<FileManagerSystemStorageOperations>;\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAeA,qCAAf,SAA6DC,eAA7D,CAAoE;;;8BAArDD,qC,UAC6B,qC"}