@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,31 +1,30 @@
1
1
  /// <reference types="node" />
2
2
  import { FileManagerContext } from "../../types";
3
- export declare type Args = {
4
- name: string;
5
- type: string;
6
- size: number;
3
+ export declare type Result = Record<string, any>;
4
+ export interface FileStorageUploadParams {
7
5
  buffer: Buffer;
8
- keyPrefix?: string;
9
- hideInFileManager?: boolean;
6
+ hideInFileManager: boolean | string;
10
7
  tags?: string[];
11
- };
12
- export declare type Result = Record<string, any>;
13
- export interface FileStoragePlugin {
14
- upload: (args: Args) => Promise<Result>;
15
- delete: (args: {
16
- key: string;
17
- }) => Promise<void>;
8
+ size: number;
9
+ name: string;
10
+ keyPrefix: string;
11
+ type: string;
18
12
  }
19
- export declare class FileStorage {
20
- storagePlugin: FileStoragePlugin;
13
+ export interface FileStorageDeleteParams {
14
+ id: string;
15
+ key: string;
16
+ }
17
+ export interface FileStorageUploadMultipleParams {
18
+ files: FileStorageUploadParams[];
19
+ }
20
+ export interface FileStorageParams {
21
21
  context: FileManagerContext;
22
- constructor({ context }: {
23
- context: any;
24
- });
25
- upload(args: any): Promise<Result>;
26
- uploadFiles(args: any): Promise<import("../../types").File[]>;
27
- delete(args: {
28
- id: string;
29
- key: string;
30
- }): Promise<boolean>;
22
+ }
23
+ export declare class FileStorage {
24
+ private readonly storagePlugin;
25
+ private readonly context;
26
+ constructor({ context }: FileStorageParams);
27
+ upload(params: FileStorageUploadParams): Promise<Result>;
28
+ uploadFiles(params: FileStorageUploadMultipleParams): Promise<import("../../types").File[]>;
29
+ delete(params: FileStorageDeleteParams): Promise<boolean>;
31
30
  }
@@ -1,95 +1,85 @@
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.FileStorage = void 0;
9
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
10
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- 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; }
15
-
16
- 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; }
17
-
18
11
  const storagePluginType = "api-file-manager-storage";
19
-
20
12
  class FileStorage {
21
13
  constructor({
22
14
  context
23
15
  }) {
24
16
  (0, _defineProperty2.default)(this, "storagePlugin", void 0);
25
17
  (0, _defineProperty2.default)(this, "context", void 0);
26
- this.storagePlugin = context.plugins.byType(storagePluginType).pop();
27
-
28
- if (!this.storagePlugin) {
18
+ const storagePlugin = context.plugins.byType(storagePluginType).pop();
19
+ if (!storagePlugin) {
29
20
  throw new _error.default(`Missing plugin of type "${storagePluginType}".`, "STORAGE_PLUGIN_ERROR");
30
21
  }
31
-
22
+ this.storagePlugin = storagePlugin;
32
23
  this.context = context;
33
24
  }
34
-
35
- async upload(args) {
36
- const settings = await this.context.fileManager.settings.getSettings(); // Add file to cloud storage.
37
-
25
+ async upload(params) {
26
+ const settings = await this.context.fileManager.settings.getSettings();
27
+ if (!settings) {
28
+ throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_ERROR");
29
+ }
30
+ // Add file to cloud storage.
38
31
  const {
39
32
  file: fileData
40
- } = await this.storagePlugin.upload(_objectSpread(_objectSpread({}, args), {}, {
33
+ } = await this.storagePlugin.upload((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
41
34
  settings
42
35
  }));
43
36
  const {
44
37
  fileManager
45
- } = this.context; // Save file in DB.
38
+ } = this.context;
46
39
 
47
- return await fileManager.files.createFile(_objectSpread(_objectSpread({}, fileData), {}, {
40
+ // Save file in DB.
41
+ return await fileManager.files.createFile((0, _objectSpread2.default)((0, _objectSpread2.default)({}, fileData), {}, {
48
42
  meta: {
49
- private: Boolean(args.hideInFileManager)
43
+ private: Boolean(params.hideInFileManager)
50
44
  },
51
- tags: Array.isArray(args.tags) ? args.tags : []
45
+ tags: Array.isArray(params.tags) ? params.tags : []
52
46
  }));
53
47
  }
54
-
55
- async uploadFiles(args) {
56
- const settings = await this.context.fileManager.settings.getSettings(); // Upload files to cloud storage.
57
-
48
+ async uploadFiles(params) {
49
+ const settings = await this.context.fileManager.settings.getSettings();
50
+ if (!settings) {
51
+ throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_ERROR");
52
+ }
53
+ // Upload files to cloud storage.
58
54
  const promises = [];
59
-
60
- for (let i = 0; i < args.files.length; i++) {
61
- const item = args.files[i];
62
- promises.push(this.storagePlugin.upload(_objectSpread(_objectSpread({}, item), {}, {
55
+ for (const item of params.files) {
56
+ promises.push(this.storagePlugin.upload((0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
63
57
  settings
64
58
  })));
65
- } // Wait for all to resolve.
66
-
67
-
59
+ }
60
+ // Wait for all to resolve.
68
61
  const uploadFileResponses = await Promise.all(promises);
69
62
  const filesData = uploadFileResponses.map(response => response.file);
70
63
  const {
71
64
  fileManager
72
- } = this.context; // Save files in DB.
73
-
65
+ } = this.context;
66
+ // Save files in DB.
74
67
  return fileManager.files.createFilesInBatch(filesData);
75
68
  }
76
-
77
- async delete(args) {
69
+ async delete(params) {
78
70
  const {
79
71
  id,
80
72
  key
81
- } = args;
73
+ } = params;
82
74
  const {
83
75
  fileManager
84
- } = this.context; // Delete file from cloud storage.
85
-
76
+ } = this.context;
77
+ // Delete file from cloud storage.
86
78
  await this.storagePlugin.delete({
87
79
  key
88
- }); // Delete file from the DB.
89
-
80
+ });
81
+ // Delete file from the DB.
90
82
  return await fileManager.files.deleteFile(id);
91
83
  }
92
-
93
84
  }
94
-
95
85
  exports.FileStorage = FileStorage;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["storagePluginType","FileStorage","constructor","context","storagePlugin","plugins","byType","pop","WebinyError","upload","params","settings","fileManager","getSettings","file","fileData","files","createFile","meta","private","Boolean","hideInFileManager","tags","Array","isArray","uploadFiles","promises","item","push","uploadFileResponses","Promise","all","filesData","map","response","createFilesInBatch","delete","id","key","deleteFile"],"sources":["FileStorage.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { FilePhysicalStoragePlugin } from \"~/plugins/definitions/FilePhysicalStoragePlugin\";\n\nexport type Result = Record<string, any>;\n\nconst storagePluginType = \"api-file-manager-storage\";\n\nexport interface FileStorageUploadParams {\n buffer: Buffer;\n hideInFileManager: boolean | string;\n tags?: string[];\n size: number;\n name: string;\n keyPrefix: string;\n type: string;\n}\nexport interface FileStorageDeleteParams {\n id: string;\n key: string;\n}\n\nexport interface FileStorageUploadMultipleParams {\n files: FileStorageUploadParams[];\n}\n\nexport interface FileStorageParams {\n context: FileManagerContext;\n}\nexport class FileStorage {\n private readonly storagePlugin: FilePhysicalStoragePlugin;\n private readonly context: FileManagerContext;\n\n constructor({ context }: FileStorageParams) {\n const storagePlugin = context.plugins\n .byType<FilePhysicalStoragePlugin>(storagePluginType)\n .pop();\n if (!storagePlugin) {\n throw new WebinyError(\n `Missing plugin of type \"${storagePluginType}\".`,\n \"STORAGE_PLUGIN_ERROR\"\n );\n }\n this.storagePlugin = storagePlugin;\n this.context = context;\n }\n\n async upload(params: FileStorageUploadParams): Promise<Result> {\n const settings = await this.context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n // Add file to cloud storage.\n const { file: fileData } = await this.storagePlugin.upload({\n ...params,\n settings\n });\n\n const { fileManager } = this.context;\n\n // Save file in DB.\n return await fileManager.files.createFile({\n ...(fileData as any),\n meta: {\n private: Boolean(params.hideInFileManager)\n },\n tags: Array.isArray(params.tags) ? params.tags : []\n });\n }\n\n async uploadFiles(params: FileStorageUploadMultipleParams) {\n const settings = await this.context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n // Upload files to cloud storage.\n const promises = [];\n for (const item of params.files) {\n promises.push(\n this.storagePlugin.upload({\n ...item,\n settings\n })\n );\n }\n // Wait for all to resolve.\n const uploadFileResponses = await Promise.all(promises);\n\n const filesData = uploadFileResponses.map(response => response.file);\n\n const { fileManager } = this.context;\n // Save files in DB.\n return fileManager.files.createFilesInBatch(filesData);\n }\n\n async delete(params: FileStorageDeleteParams) {\n const { id, key } = params;\n const { fileManager } = this.context;\n // Delete file from cloud storage.\n await this.storagePlugin.delete({\n key\n });\n // Delete file from the DB.\n return await fileManager.files.deleteFile(id);\n }\n}\n"],"mappings":";;;;;;;;;AACA;AAKA,MAAMA,iBAAiB,GAAG,0BAA0B;AAuB7C,MAAMC,WAAW,CAAC;EAIrBC,WAAW,CAAC;IAAEC;EAA2B,CAAC,EAAE;IAAA;IAAA;IACxC,MAAMC,aAAa,GAAGD,OAAO,CAACE,OAAO,CAChCC,MAAM,CAA4BN,iBAAiB,CAAC,CACpDO,GAAG,EAAE;IACV,IAAI,CAACH,aAAa,EAAE;MAChB,MAAM,IAAII,cAAW,CAChB,2BAA0BR,iBAAkB,IAAG,EAChD,sBAAsB,CACzB;IACL;IACA,IAAI,CAACI,aAAa,GAAGA,aAAa;IAClC,IAAI,CAACD,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMM,MAAM,CAACC,MAA+B,EAAmB;IAC3D,MAAMC,QAAQ,GAAG,MAAM,IAAI,CAACR,OAAO,CAACS,WAAW,CAACD,QAAQ,CAACE,WAAW,EAAE;IACtE,IAAI,CAACF,QAAQ,EAAE;MACX,MAAM,IAAIH,cAAW,CAAC,gCAAgC,EAAE,oBAAoB,CAAC;IACjF;IACA;IACA,MAAM;MAAEM,IAAI,EAAEC;IAAS,CAAC,GAAG,MAAM,IAAI,CAACX,aAAa,CAACK,MAAM,6DACnDC,MAAM;MACTC;IAAQ,GACV;IAEF,MAAM;MAAEC;IAAY,CAAC,GAAG,IAAI,CAACT,OAAO;;IAEpC;IACA,OAAO,MAAMS,WAAW,CAACI,KAAK,CAACC,UAAU,6DACjCF,QAAQ;MACZG,IAAI,EAAE;QACFC,OAAO,EAAEC,OAAO,CAACV,MAAM,CAACW,iBAAiB;MAC7C,CAAC;MACDC,IAAI,EAAEC,KAAK,CAACC,OAAO,CAACd,MAAM,CAACY,IAAI,CAAC,GAAGZ,MAAM,CAACY,IAAI,GAAG;IAAE,GACrD;EACN;EAEA,MAAMG,WAAW,CAACf,MAAuC,EAAE;IACvD,MAAMC,QAAQ,GAAG,MAAM,IAAI,CAACR,OAAO,CAACS,WAAW,CAACD,QAAQ,CAACE,WAAW,EAAE;IACtE,IAAI,CAACF,QAAQ,EAAE;MACX,MAAM,IAAIH,cAAW,CAAC,gCAAgC,EAAE,oBAAoB,CAAC;IACjF;IACA;IACA,MAAMkB,QAAQ,GAAG,EAAE;IACnB,KAAK,MAAMC,IAAI,IAAIjB,MAAM,CAACM,KAAK,EAAE;MAC7BU,QAAQ,CAACE,IAAI,CACT,IAAI,CAACxB,aAAa,CAACK,MAAM,6DAClBkB,IAAI;QACPhB;MAAQ,GACV,CACL;IACL;IACA;IACA,MAAMkB,mBAAmB,GAAG,MAAMC,OAAO,CAACC,GAAG,CAACL,QAAQ,CAAC;IAEvD,MAAMM,SAAS,GAAGH,mBAAmB,CAACI,GAAG,CAACC,QAAQ,IAAIA,QAAQ,CAACpB,IAAI,CAAC;IAEpE,MAAM;MAAEF;IAAY,CAAC,GAAG,IAAI,CAACT,OAAO;IACpC;IACA,OAAOS,WAAW,CAACI,KAAK,CAACmB,kBAAkB,CAACH,SAAS,CAAC;EAC1D;EAEA,MAAMI,MAAM,CAAC1B,MAA+B,EAAE;IAC1C,MAAM;MAAE2B,EAAE;MAAEC;IAAI,CAAC,GAAG5B,MAAM;IAC1B,MAAM;MAAEE;IAAY,CAAC,GAAG,IAAI,CAACT,OAAO;IACpC;IACA,MAAM,IAAI,CAACC,aAAa,CAACgC,MAAM,CAAC;MAC5BE;IACJ,CAAC,CAAC;IACF;IACA,OAAO,MAAM1B,WAAW,CAACI,KAAK,CAACuB,UAAU,CAACF,EAAE,CAAC;EACjD;AACJ;AAAC"}
@@ -1,4 +1,4 @@
1
1
  import { FileManagerContext } from "../../types";
2
- import { ContextPlugin } from "@webiny/handler/plugins/ContextPlugin";
2
+ import { ContextPlugin } from "@webiny/api";
3
3
  declare const fileStorageContextPlugin: ContextPlugin<FileManagerContext>;
4
4
  export default fileStorageContextPlugin;
@@ -4,16 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
- var _ContextPlugin = require("@webiny/handler/plugins/ContextPlugin");
9
-
7
+ var _api = require("@webiny/api");
10
8
  var _FileStorage = require("./FileStorage");
11
-
12
- const fileStorageContextPlugin = new _ContextPlugin.ContextPlugin(async context => {
9
+ const fileStorageContextPlugin = new _api.ContextPlugin(async context => {
13
10
  if (!context.fileManager) {
11
+ /**
12
+ * We need to define the fileManager initial property as empty object.
13
+ * When casting as FileManagerContext, typescript is complaining.
14
+ */
14
15
  context.fileManager = {};
15
16
  }
16
-
17
17
  context.fileManager.storage = new _FileStorage.FileStorage({
18
18
  context
19
19
  });
@@ -0,0 +1 @@
1
+ {"version":3,"names":["fileStorageContextPlugin","ContextPlugin","context","fileManager","storage","FileStorage"],"sources":["index.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { FileStorage } from \"./FileStorage\";\n\nconst fileStorageContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n if (!context.fileManager) {\n /**\n * We need to define the fileManager initial property as empty object.\n * When casting as FileManagerContext, typescript is complaining.\n */\n context.fileManager = {} as any;\n }\n context.fileManager.storage = new FileStorage({\n context\n });\n});\n\nexport default fileStorageContextPlugin;\n"],"mappings":";;;;;;AACA;AACA;AAEA,MAAMA,wBAAwB,GAAG,IAAIC,kBAAa,CAAqB,MAAMC,OAAO,IAAI;EACpF,IAAI,CAACA,OAAO,CAACC,WAAW,EAAE;IACtB;AACR;AACA;AACA;IACQD,OAAO,CAACC,WAAW,GAAG,CAAC,CAAQ;EACnC;EACAD,OAAO,CAACC,WAAW,CAACC,OAAO,GAAG,IAAIC,wBAAW,CAAC;IAC1CH;EACJ,CAAC,CAAC;AACN,CAAC,CAAC;AAAC,eAEYF,wBAAwB;AAAA"}
package/types.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { BaseI18NContentContext } from "@webiny/api-i18n-content/types";
1
+ import { I18NContext } from "@webiny/api-i18n/types";
2
2
  import { FileStorage } from "./plugins/storage/FileStorage";
3
3
  import { TenancyContext } from "@webiny/api-tenancy/types";
4
4
  import { SecurityContext, SecurityPermission } from "@webiny/api-security/types";
5
- import { ContextInterface } from "@webiny/handler/types";
6
- export interface FileManagerContext extends ContextInterface, SecurityContext, TenancyContext, BaseI18NContentContext {
5
+ import { Context } from "@webiny/api/types";
6
+ export interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {
7
7
  fileManager: {
8
8
  files: FilesCRUD;
9
9
  settings: SettingsCRUD;
@@ -39,7 +39,7 @@ export interface File {
39
39
  }
40
40
  export interface CreatedBy {
41
41
  id: string;
42
- displayName: string;
42
+ displayName: string | null;
43
43
  type: string;
44
44
  }
45
45
  export interface FileInput {
@@ -48,7 +48,7 @@ export interface FileInput {
48
48
  size: number;
49
49
  type: string;
50
50
  meta: Record<string, any>;
51
- tags: [string];
51
+ tags: string[];
52
52
  }
53
53
  export interface FileListWhereParams {
54
54
  search?: string;
@@ -71,13 +71,16 @@ export interface FilesListOpts {
71
71
  sort?: string[];
72
72
  }
73
73
  export interface FileListMeta {
74
- cursor: string;
74
+ cursor: string | null;
75
75
  totalCount: number;
76
+ hasMoreItems: boolean;
76
77
  }
77
78
  interface FilesCrudListTagsWhere {
78
79
  tag?: string;
79
80
  tag_contains?: string;
80
81
  tag_in?: string[];
82
+ tag_not_startsWith?: string;
83
+ tag_startsWith?: string;
81
84
  }
82
85
  interface FilesCrudListTagsParams {
83
86
  where?: FilesCrudListTagsWhere;
@@ -94,7 +97,7 @@ export interface FilesCRUD {
94
97
  createFilesInBatch(data: FileInput[]): Promise<File[]>;
95
98
  }
96
99
  export interface SystemCRUD {
97
- getVersion(): Promise<string>;
100
+ getVersion(): Promise<string | null>;
98
101
  setVersion(version: string): Promise<void>;
99
102
  install(args: {
100
103
  srcPrefix: string;
@@ -109,9 +112,10 @@ export interface FileManagerSettings {
109
112
  }
110
113
  export interface FileManagerSystem {
111
114
  version: string;
115
+ tenant: string;
112
116
  }
113
117
  export declare type SettingsCRUD = {
114
- getSettings(): Promise<FileManagerSettings>;
118
+ getSettings(): Promise<FileManagerSettings | null>;
115
119
  createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
116
120
  updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
117
121
  deleteSettings(): Promise<boolean>;
@@ -293,10 +297,10 @@ export interface FileManagerFilesStorageOperationsListParams {
293
297
  * @category FilesStorageOperations
294
298
  * @category FilesStorageOperationsParams
295
299
  */
296
- interface FileManagerFilesStorageOperationsListResponseMeta {
300
+ export interface FileManagerFilesStorageOperationsListResponseMeta {
297
301
  hasMoreItems: boolean;
298
302
  totalCount: number;
299
- cursor: string;
303
+ cursor: string | null;
300
304
  }
301
305
  export declare type FileManagerFilesStorageOperationsListResponse = [
302
306
  File[],
@@ -332,11 +336,11 @@ export interface FileManagerFilesStorageOperations {
332
336
  /**
333
337
  * Insert the file data into the database.
334
338
  */
335
- create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File | null>;
339
+ create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;
336
340
  /**
337
341
  * Update the file data in the database.
338
342
  */
339
- update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File | null>;
343
+ update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;
340
344
  /**
341
345
  * Delete the file from the database.
342
346
  */
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { I18NContext } from \"@webiny/api-i18n/types\";\nimport { FileStorage } from \"./plugins/storage/FileStorage\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { SecurityContext, SecurityPermission } from \"@webiny/api-security/types\";\nimport { Context } from \"@webiny/api/types\";\n\nexport interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {\n fileManager: {\n files: FilesCRUD;\n settings: SettingsCRUD;\n storage: FileStorage;\n system: SystemCRUD;\n };\n}\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n\nexport interface File {\n id: string;\n key: string;\n size: number;\n type: string;\n name: string;\n meta: Record<string, any>;\n tags: string[];\n createdOn: string;\n createdBy: CreatedBy;\n /**\n * Added with new storage operations refactoring.\n */\n tenant: string;\n locale: string;\n webinyVersion: string;\n /**\n * User can add new fields to the File object so we must allow it in the types.\n */\n [key: string]: any;\n}\n\nexport interface CreatedBy {\n id: string;\n displayName: string | null;\n type: string;\n}\n\nexport interface FileInput {\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n tags: string[];\n}\n\nexport interface FileListWhereParams {\n search?: string;\n type?: string;\n type_in?: string[];\n tag?: string;\n tag_in?: string[];\n tag_and_in?: string[];\n id_in?: string[];\n id?: string;\n}\nexport interface FilesListOpts {\n search?: string;\n types?: string[];\n tags?: string[];\n ids?: string[];\n limit?: number;\n after?: string;\n where?: FileListWhereParams;\n sort?: string[];\n}\n\nexport interface FileListMeta {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\ninterface FilesCrudListTagsWhere {\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n tag_not_startsWith?: string;\n tag_startsWith?: string;\n}\ninterface FilesCrudListTagsParams {\n where?: FilesCrudListTagsWhere;\n limit?: number;\n after?: string;\n}\n\nexport interface FilesCRUD {\n getFile(id: string): Promise<File>;\n listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;\n listTags(params: FilesCrudListTagsParams): Promise<string[]>;\n createFile(data: FileInput): Promise<File>;\n updateFile(id: string, data: Partial<FileInput>): Promise<File>;\n deleteFile(id: string): Promise<boolean>;\n createFilesInBatch(data: FileInput[]): Promise<File[]>;\n}\n\nexport interface SystemCRUD {\n getVersion(): Promise<string | null>;\n setVersion(version: string): Promise<void>;\n install(args: { srcPrefix: string }): Promise<boolean>;\n upgrade(version: string, data?: Record<string, any>): Promise<boolean>;\n}\n\nexport interface FileManagerSettings {\n key: string;\n uploadMinFileSize: number;\n uploadMaxFileSize: number;\n srcPrefix: string;\n}\n\nexport interface FileManagerSystem {\n version: string;\n tenant: string;\n}\n\nexport type SettingsCRUD = {\n getSettings(): Promise<FileManagerSettings | null>;\n createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n deleteSettings(): Promise<boolean>;\n};\n/********\n * Storage operations\n *******/\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsUpdateParams {\n /**\n * The system data to be updated.\n */\n original: FileManagerSystem;\n /**\n * The system data with the updated fields.\n */\n data: FileManagerSystem;\n}\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsCreateParams {\n /**\n * The system fields.\n */\n data: FileManagerSystem;\n}\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n */\nexport interface FileManagerSystemStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: () => Promise<FileManagerSystem | null>;\n /**\n * Update the FileManager system data..\n */\n update: (params: FileManagerSystemStorageOperationsUpdateParams) => Promise<FileManagerSystem>;\n /**\n * Create the FileManagerSystemData\n */\n create: (params: FileManagerSystemStorageOperationsCreateParams) => Promise<FileManagerSystem>;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsUpdateParams {\n /**\n * Original settings to be updated.\n */\n original: FileManagerSettings;\n /**\n * The settings with the updated fields.\n */\n data: FileManagerSettings;\n}\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsCreateParams {\n /**\n * The settings fields.\n */\n data: FileManagerSettings;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n */\nexport interface FileManagerSettingsStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: () => Promise<FileManagerSettings | null>;\n /**\n * Create the FileManagerSettingsData\n */\n create: (\n params: FileManagerSettingsStorageOperationsCreateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Update the FileManager system data..\n */\n update: (\n params: FileManagerSettingsStorageOperationsUpdateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Delete the existing settings.\n */\n delete: () => Promise<void>;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsUpdateParams {\n original: File;\n file: File;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsDeleteParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateBatchParams {\n files: File[];\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParamsWhere {\n id?: string;\n id_in?: string[];\n name?: string;\n name_contains?: string;\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n createdBy?: string;\n locale: string;\n tenant: string;\n private?: boolean;\n type?: string;\n type_in?: string[];\n search?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n sort: string[];\n limit: number;\n after: string | null;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListResponseMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor: string | null;\n}\nexport type FileManagerFilesStorageOperationsListResponse = [\n File[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport type FileManagerFilesStorageOperationsTagsResponse = [\n string[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {\n locale: string;\n tenant: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsTagsParams {\n where: FileManagerFilesStorageOperationsTagsParamsWhere;\n limit: number;\n after?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n */\nexport interface FileManagerFilesStorageOperations {\n /**\n * Get a single file with given ID from the storage.\n */\n get: (params: FileManagerFilesStorageOperationsGetParams) => Promise<File | null>;\n /**\n * Insert the file data into the database.\n */\n create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;\n /**\n * Update the file data in the database.\n */\n update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;\n /**\n * Delete the file from the database.\n */\n delete: (params: FileManagerFilesStorageOperationsDeleteParams) => Promise<void>;\n /**\n * Store multiple files at once to the database.\n */\n createBatch: (params: FileManagerFilesStorageOperationsCreateBatchParams) => Promise<File[]>;\n /**\n * Get a list of files filtered by given parameters.\n */\n list: (\n params: FileManagerFilesStorageOperationsListParams\n ) => Promise<FileManagerFilesStorageOperationsListResponse>;\n /**\n * Get a list of all file tags filtered by given parameters.\n */\n tags: (\n params: FileManagerFilesStorageOperationsTagsParams\n ) => Promise<FileManagerFilesStorageOperationsTagsResponse>;\n}\n"],"mappings":""}
package/utils.js CHANGED
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.executeCallbacks = void 0;
7
-
8
7
  const executeCallbacks = async (plugins, hook, args) => {
9
8
  for (const plugin of plugins) {
10
9
  if (typeof plugin[hook] === "function") {
@@ -12,5 +11,4 @@ const executeCallbacks = async (plugins, hook, args) => {
12
11
  }
13
12
  }
14
13
  };
15
-
16
14
  exports.executeCallbacks = executeCallbacks;
package/utils.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["executeCallbacks","plugins","hook","args","plugin"],"sources":["utils.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/types\";\n\ntype CallbackFallback = (args: any) => void | Promise<void>;\n\nexport const executeCallbacks = async <\n TCallbackFunction extends CallbackFallback = CallbackFallback\n>(\n plugins: Plugin[],\n hook: string,\n args: Parameters<TCallbackFunction>[0]\n) => {\n for (const plugin of plugins) {\n if (typeof plugin[hook] === \"function\") {\n await plugin[hook](args);\n }\n }\n};\n"],"mappings":";;;;;;AAIO,MAAMA,gBAAgB,GAAG,OAG5BC,OAAiB,EACjBC,IAAY,EACZC,IAAsC,KACrC;EACD,KAAK,MAAMC,MAAM,IAAIH,OAAO,EAAE;IAC1B,IAAI,OAAOG,MAAM,CAACF,IAAI,CAAC,KAAK,UAAU,EAAE;MACpC,MAAME,MAAM,CAACF,IAAI,CAAC,CAACC,IAAI,CAAC;IAC5B;EACJ;AACJ,CAAC;AAAC"}
@@ -1,24 +0,0 @@
1
- declare const _default: (handler: any) => (event: any) => Promise<{
2
- body: string;
3
- statusCode: number;
4
- headers: {
5
- "Cache-Control": string;
6
- "Access-Control-Allow-Origin": string;
7
- "Access-Control-Allow-Credentials": boolean;
8
- };
9
- isBase64Encoded?: undefined;
10
- } | {
11
- isBase64Encoded: boolean;
12
- statusCode: any;
13
- headers: any;
14
- body: any;
15
- } | {
16
- statusCode: number;
17
- headers: {
18
- "Access-Control-Allow-Origin": string;
19
- "Access-Control-Allow-Credentials": boolean;
20
- };
21
- body: string;
22
- isBase64Encoded?: undefined;
23
- }>;
24
- export default _default;
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- 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; }
13
-
14
- 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; }
15
-
16
- /**
17
- * We need to respond with adequate CORS headers.
18
- * @type {{"Access-Control-Allow-Origin": string, "Access-Control-Allow-Credentials": boolean}}
19
- */
20
- const baseHeaders = {
21
- "Access-Control-Allow-Origin": "*",
22
- "Access-Control-Allow-Credentials": true
23
- };
24
- const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
25
-
26
- var _default = handler => async event => {
27
- if (event.httpMethod === "OPTIONS") {
28
- return {
29
- body: "",
30
- statusCode: 204,
31
- headers: _objectSpread(_objectSpread({}, baseHeaders), {}, {
32
- "Cache-Control": "public, max-age=" + DEFAULT_CACHE_MAX_AGE
33
- })
34
- };
35
- }
36
-
37
- try {
38
- const {
39
- data,
40
- statusCode,
41
- headers = {}
42
- } = await handler(event);
43
- const isBuffer = Buffer.isBuffer(data);
44
- const body = isBuffer ? data.toString("base64") : JSON.stringify({
45
- error: false,
46
- data,
47
- message: null
48
- });
49
- return {
50
- isBase64Encoded: isBuffer,
51
- statusCode: statusCode || 200,
52
- headers: _objectSpread(_objectSpread({}, baseHeaders), headers),
53
- body
54
- };
55
- } catch (e) {
56
- return {
57
- statusCode: 500,
58
- headers: baseHeaders,
59
- body: JSON.stringify({
60
- error: true,
61
- data: null,
62
- message: e.message
63
- })
64
- };
65
- }
66
- };
67
-
68
- exports.default = _default;