@webiny/api-file-manager 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.aa00eecd97

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 (117) hide show
  1. package/createFileManager/checkBasePermissions.d.ts +5 -0
  2. package/{plugins/crud/utils → createFileManager}/checkBasePermissions.js +4 -5
  3. package/createFileManager/checkBasePermissions.js.map +1 -0
  4. package/createFileManager/files.crud.d.ts +3 -0
  5. package/{plugins/crud → createFileManager}/files.crud.js +95 -145
  6. package/createFileManager/files.crud.js.map +1 -0
  7. package/createFileManager/filevalidation.disabled.d.ts +0 -0
  8. package/createFileManager/filevalidation.disabled.js +55 -0
  9. package/createFileManager/filevalidation.disabled.js.map +1 -0
  10. package/createFileManager/index.d.ts +13 -0
  11. package/createFileManager/index.js +20 -0
  12. package/createFileManager/index.js.map +1 -0
  13. package/createFileManager/settings.crud.d.ts +3 -0
  14. package/{plugins/crud → createFileManager}/settings.crud.js +25 -33
  15. package/createFileManager/settings.crud.js.map +1 -0
  16. package/createFileManager/system.crud.d.ts +3 -0
  17. package/createFileManager/system.crud.js +86 -0
  18. package/createFileManager/system.crud.js.map +1 -0
  19. package/graphql/index.d.ts +3 -0
  20. package/{plugins/graphql.js → graphql/index.js} +64 -46
  21. package/graphql/index.js.map +1 -0
  22. package/handlers/download/byAlias.d.ts +6 -0
  23. package/handlers/download/byAlias.js +89 -0
  24. package/handlers/download/byAlias.js.map +1 -0
  25. package/handlers/download/byExactKey.d.ts +2 -0
  26. package/handlers/download/byExactKey.js +57 -0
  27. package/handlers/download/byExactKey.js.map +1 -0
  28. package/handlers/download/extractFileInformation.d.ts +9 -0
  29. package/handlers/download/extractFileInformation.js +20 -0
  30. package/handlers/download/extractFileInformation.js.map +1 -0
  31. package/handlers/download/getS3Object.d.ts +10 -0
  32. package/handlers/download/getS3Object.js +57 -0
  33. package/handlers/download/getS3Object.js.map +1 -0
  34. package/handlers/download/index.d.ts +2 -3
  35. package/handlers/download/index.js +21 -107
  36. package/handlers/download/index.js.map +1 -1
  37. package/handlers/transform/index.js +13 -5
  38. package/handlers/transform/index.js.map +1 -1
  39. package/handlers/transform/legacyUtils.d.ts +17 -0
  40. package/handlers/transform/legacyUtils.js +42 -0
  41. package/handlers/transform/legacyUtils.js.map +1 -0
  42. package/handlers/transform/loaders/imageLoader.d.ts +1 -1
  43. package/handlers/transform/loaders/imageLoader.js +12 -6
  44. package/handlers/transform/loaders/imageLoader.js.map +1 -1
  45. package/handlers/transform/loaders/index.d.ts +1 -1
  46. package/handlers/transform/managers/imageManager.js +28 -9
  47. package/handlers/transform/managers/imageManager.js.map +1 -1
  48. package/handlers/transform/utils.d.ts +1 -1
  49. package/handlers/transform/utils.js +7 -7
  50. package/handlers/transform/utils.js.map +1 -1
  51. package/index.d.ts +6 -0
  52. package/index.js +68 -0
  53. package/index.js.map +1 -0
  54. package/package.json +30 -32
  55. package/plugins/{definitions/FilePhysicalStoragePlugin.d.ts → FilePhysicalStoragePlugin.d.ts} +1 -1
  56. package/plugins/{definitions/FileStorageTransformPlugin.d.ts → FileStorageTransformPlugin.d.ts} +1 -1
  57. package/plugins/index.d.ts +2 -2
  58. package/plugins/index.js +22 -10
  59. package/plugins/index.js.map +1 -1
  60. package/{plugins/storage → storage}/FileStorage.d.ts +6 -4
  61. package/{plugins/storage → storage}/FileStorage.js +23 -22
  62. package/storage/FileStorage.js.map +1 -0
  63. package/types/file.d.ts +33 -0
  64. package/types/file.js +5 -0
  65. package/types/file.js.map +1 -0
  66. package/types/file.lifecycle.d.ts +44 -0
  67. package/types/file.lifecycle.js +5 -0
  68. package/types/file.lifecycle.js.map +1 -0
  69. package/types.d.ts +46 -47
  70. package/types.js +22 -0
  71. package/types.js.map +1 -1
  72. package/plugins/crud/files/validation.d.ts +0 -3
  73. package/plugins/crud/files/validation.js +0 -35
  74. package/plugins/crud/files/validation.js.map +0 -1
  75. package/plugins/crud/files.crud.d.ts +0 -4
  76. package/plugins/crud/files.crud.js.map +0 -1
  77. package/plugins/crud/settings.crud.d.ts +0 -5
  78. package/plugins/crud/settings.crud.js.map +0 -1
  79. package/plugins/crud/system.crud.d.ts +0 -4
  80. package/plugins/crud/system.crud.js +0 -123
  81. package/plugins/crud/system.crud.js.map +0 -1
  82. package/plugins/crud/utils/checkBasePermissions.d.ts +0 -5
  83. package/plugins/crud/utils/checkBasePermissions.js.map +0 -1
  84. package/plugins/crud/utils/createFileModel.d.ts +0 -5
  85. package/plugins/crud/utils/createFileModel.js +0 -65
  86. package/plugins/crud/utils/createFileModel.js.map +0 -1
  87. package/plugins/crud/utils/lifecycleEvents.d.ts +0 -6
  88. package/plugins/crud/utils/lifecycleEvents.js +0 -30
  89. package/plugins/crud/utils/lifecycleEvents.js.map +0 -1
  90. package/plugins/definitions/FilePlugin.d.ts +0 -136
  91. package/plugins/definitions/FilePlugin.js +0 -52
  92. package/plugins/definitions/FilePlugin.js.map +0 -1
  93. package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +0 -9
  94. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +0 -12
  95. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +0 -1
  96. package/plugins/definitions/InstallationPlugin.d.ts +0 -19
  97. package/plugins/definitions/InstallationPlugin.js +0 -31
  98. package/plugins/definitions/InstallationPlugin.js.map +0 -1
  99. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +0 -9
  100. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +0 -12
  101. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +0 -1
  102. package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +0 -9
  103. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +0 -12
  104. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +0 -1
  105. package/plugins/graphql.d.ts +0 -4
  106. package/plugins/graphql.js.map +0 -1
  107. package/plugins/storage/FileStorage.js.map +0 -1
  108. package/plugins/storage/index.d.ts +0 -4
  109. package/plugins/storage/index.js +0 -22
  110. package/plugins/storage/index.js.map +0 -1
  111. package/utils.d.ts +0 -4
  112. package/utils.js +0 -14
  113. package/utils.js.map +0 -1
  114. /package/plugins/{definitions/FilePhysicalStoragePlugin.js → FilePhysicalStoragePlugin.js} +0 -0
  115. /package/plugins/{definitions/FilePhysicalStoragePlugin.js.map → FilePhysicalStoragePlugin.js.map} +0 -0
  116. /package/plugins/{definitions/FileStorageTransformPlugin.js → FileStorageTransformPlugin.js} +0 -0
  117. /package/plugins/{definitions/FileStorageTransformPlugin.js.map → FileStorageTransformPlugin.js.map} +0 -0
@@ -0,0 +1,5 @@
1
+ import { GetPermission } from "@webiny/api-security/types";
2
+ import { FilePermission } from "../types";
3
+ export declare const checkBasePermissions: (getPermission: GetPermission, check?: {
4
+ rwd?: string;
5
+ }) => Promise<FilePermission>;
@@ -3,11 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.checkBasePermissions = void 0;
7
7
  var _apiSecurity = require("@webiny/api-security");
8
- var _default = async (context, check = {}) => {
9
- await context.i18n.checkI18NContentPermission();
10
- const filePermission = await context.security.getPermission("fm.file");
8
+ const checkBasePermissions = async (getPermission, check = {}) => {
9
+ const filePermission = await getPermission("fm.file");
11
10
  if (!filePermission) {
12
11
  throw new _apiSecurity.NotAuthorizedError();
13
12
  }
@@ -16,7 +15,7 @@ var _default = async (context, check = {}) => {
16
15
  }
17
16
  return filePermission;
18
17
  };
19
- exports.default = _default;
18
+ exports.checkBasePermissions = checkBasePermissions;
20
19
  const hasRwd = (filesFilePermission, rwd) => {
21
20
  if (typeof filesFilePermission.rwd !== "string") {
22
21
  return true;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["checkBasePermissions","getPermission","check","filePermission","NotAuthorizedError","rwd","hasRwd","filesFilePermission","includes"],"sources":["checkBasePermissions.ts"],"sourcesContent":["import { NotAuthorizedError } from \"@webiny/api-security\";\nimport { GetPermission } from \"@webiny/api-security/types\";\nimport { FilePermission } from \"~/types\";\n\nexport const checkBasePermissions = async (\n getPermission: GetPermission,\n check: { rwd?: string } = {}\n): Promise<FilePermission> => {\n const filePermission = await getPermission<FilePermission>(\"fm.file\");\n\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":";;;;;;AAAA;AAIO,MAAMA,oBAAoB,GAAG,OAChCC,aAA4B,EAC5BC,KAAuB,GAAG,CAAC,CAAC,KACF;EAC1B,MAAMC,cAAc,GAAG,MAAMF,aAAa,CAAiB,SAAS,CAAC;EAErE,IAAI,CAACE,cAAc,EAAE;IACjB,MAAM,IAAIC,+BAAkB,EAAE;EAClC;EACA,IAAIF,KAAK,CAACG,GAAG,IAAI,CAACC,MAAM,CAACH,cAAc,EAAED,KAAK,CAACG,GAAG,CAAC,EAAE;IACjD,MAAM,IAAID,+BAAkB,EAAE;EAClC;EAEA,OAAOD,cAAc;AACzB,CAAC;AAAC;AAEF,MAAMG,MAAM,GAAG,CAACC,mBAAmC,EAAEF,GAAW,KAAc;EAC1E,IAAI,OAAOE,mBAAmB,CAACF,GAAG,KAAK,QAAQ,EAAE;IAC7C,OAAO,IAAI;EACf;EAEA,OAAOE,mBAAmB,CAACF,GAAG,CAACG,QAAQ,CAACH,GAAG,CAAC;AAChD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { FilesCRUD } from "../types";
2
+ import { FileManagerConfig } from "./index";
3
+ export declare const createFilesCrud: (config: FileManagerConfig) => FilesCRUD;
@@ -4,118 +4,94 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.default = void 0;
7
+ exports.createFilesCrud = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _mdbid = _interopRequireDefault(require("mdbid"));
10
9
  var _handlerGraphql = require("@webiny/handler-graphql");
11
10
  var _apiSecurity = require("@webiny/api-security");
12
- var _checkBasePermissions = _interopRequireDefault(require("./utils/checkBasePermissions"));
13
- var _api = require("@webiny/api");
14
- var _FilePlugin = require("../definitions/FilePlugin");
15
- var _FilesStorageOperationsProviderPlugin = require("../definitions/FilesStorageOperationsProviderPlugin");
11
+ var _pubsub = require("@webiny/pubsub");
16
12
  var _error = _interopRequireDefault(require("@webiny/error"));
17
- var _lifecycleEvents = require("./utils/lifecycleEvents");
18
- /**
19
- * Package mdbid does not have types.
20
- */
21
- // @ts-ignore
22
-
23
- const BATCH_CREATE_MAX_FILES = 20;
24
-
13
+ var _checkBasePermissions = require("./checkBasePermissions");
25
14
  /**
26
15
  * If permission is limited to "own" files only, check that current identity owns the file.
27
16
  */
28
- const checkOwnership = (file, permission, context) => {
17
+ const checkOwnership = (file, permission, identity) => {
29
18
  if ((permission === null || permission === void 0 ? void 0 : permission.own) === true) {
30
- const identity = context.security.getIdentity();
31
19
  if (file.createdBy.id !== identity.id) {
32
20
  throw new _apiSecurity.NotAuthorizedError();
33
21
  }
34
22
  }
35
23
  };
36
- const getLocaleCode = context => {
37
- if (!context.i18n) {
38
- throw new _error.default("Missing i18n on the FileManagerContext.", "MISSING_I18N");
39
- }
40
- const locale = context.i18n.getContentLocale();
41
- if (!locale) {
42
- throw new _error.default("Missing content locale on the FileManagerContext.", "MISSING_I18N_CONTENT_LOCALE");
43
- }
44
- if (!locale.code) {
45
- throw new _error.default("Missing content locale code on the FileManagerContext.", "MISSING_I18N_CONTENT_LOCALE_CODE");
46
- }
47
- return locale.code;
48
- };
49
- const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
50
- const pluginType = _FilesStorageOperationsProviderPlugin.FilesStorageOperationsProviderPlugin.type;
51
- const providerPlugin = context.plugins.byType(pluginType).find(() => true);
52
- if (!providerPlugin) {
53
- throw new _error.default(`Missing "${pluginType}" plugin.`, "PLUGIN_NOT_FOUND", {
54
- type: pluginType
55
- });
56
- }
57
- const storageOperations = await providerPlugin.provide({
58
- context
59
- });
60
- if (!context.fileManager) {
61
- context.fileManager = {};
62
- }
63
- const filePlugins = context.plugins.byType(_FilePlugin.FilePlugin.type);
64
- context.fileManager.files = {
24
+ const createFilesCrud = config => {
25
+ const {
26
+ storageOperations,
27
+ getLocaleCode,
28
+ getTenantId,
29
+ getIdentity,
30
+ getPermission,
31
+ WEBINY_VERSION
32
+ } = config;
33
+ return {
34
+ onFileBeforeCreate: (0, _pubsub.createTopic)("fileManager.onFileBeforeCreate"),
35
+ onFileAfterCreate: (0, _pubsub.createTopic)("fileManager.onFileAfterCreate"),
36
+ onFileBeforeBatchCreate: (0, _pubsub.createTopic)("fileManager.onFileBeforeBatchCreate"),
37
+ onFileAfterBatchCreate: (0, _pubsub.createTopic)("fileManager.onFileAfterBatchCreate"),
38
+ onFileBeforeUpdate: (0, _pubsub.createTopic)("fileManager.onFileBeforeUpdate"),
39
+ onFileAfterUpdate: (0, _pubsub.createTopic)("fileManager.onFileAfterUpdate"),
40
+ onFileBeforeDelete: (0, _pubsub.createTopic)("fileManager.onFileBeforeDelete"),
41
+ onFileAfterDelete: (0, _pubsub.createTopic)("fileManager.onFileAfterDelete"),
65
42
  async getFile(id) {
66
- const permission = await (0, _checkBasePermissions.default)(context, {
43
+ const permission = await (0, _checkBasePermissions.checkBasePermissions)(getPermission, {
67
44
  rwd: "r"
68
45
  });
69
- const file = await storageOperations.get({
46
+ const file = await storageOperations.files.get({
70
47
  where: {
71
48
  id,
72
- tenant: context.tenancy.getCurrentTenant().id,
73
- locale: getLocaleCode(context)
49
+ tenant: getTenantId(),
50
+ locale: getLocaleCode()
74
51
  }
75
52
  });
76
53
  if (!file) {
77
54
  throw new _handlerGraphql.NotFoundError(`File with id "${id}" does not exists.`);
78
55
  }
79
- checkOwnership(file, permission, context);
56
+ checkOwnership(file, permission, getIdentity());
80
57
  return file;
81
58
  },
82
- async createFile(input) {
83
- await (0, _checkBasePermissions.default)(context, {
59
+ async createFile(input, meta) {
60
+ await (0, _checkBasePermissions.checkBasePermissions)(getPermission, {
84
61
  rwd: "w"
85
62
  });
86
- const identity = context.security.getIdentity();
87
- const tenant = context.tenancy.getCurrentTenant();
88
- const id = (0, _mdbid.default)();
63
+ const identity = getIdentity();
64
+
65
+ // Extract ID from file key
66
+ const [id] = input.key.split("/");
89
67
  const file = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, input), {}, {
90
68
  tags: Array.isArray(input.tags) ? input.tags : [],
91
- id,
69
+ aliases: Array.isArray(input.aliases) ? input.aliases : [],
70
+ id: input.id || id,
92
71
  meta: (0, _objectSpread2.default)({
93
72
  private: false
94
73
  }, input.meta || {}),
95
- tenant: tenant.id,
74
+ tenant: getTenantId(),
96
75
  createdOn: new Date().toISOString(),
97
76
  createdBy: {
98
77
  id: identity.id,
99
78
  displayName: identity.displayName,
100
79
  type: identity.type
101
80
  },
102
- locale: getLocaleCode(context),
103
- webinyVersion: context.WEBINY_VERSION
81
+ locale: getLocaleCode(),
82
+ webinyVersion: WEBINY_VERSION
104
83
  });
105
84
  try {
106
- await (0, _lifecycleEvents.runLifecycleEvent)("beforeCreate", {
107
- context,
108
- plugins: filePlugins,
109
- data: file
85
+ await this.onFileBeforeCreate.publish({
86
+ file,
87
+ meta
110
88
  });
111
- const result = await storageOperations.create({
89
+ const result = await storageOperations.files.create({
112
90
  file
113
91
  });
114
- await (0, _lifecycleEvents.runLifecycleEvent)("afterCreate", {
115
- context,
116
- plugins: filePlugins,
117
- data: file,
118
- file: result
92
+ await this.onFileAfterCreate.publish({
93
+ file,
94
+ meta
119
95
  });
120
96
  return result;
121
97
  } catch (ex) {
@@ -125,42 +101,40 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
125
101
  }
126
102
  },
127
103
  async updateFile(id, input) {
128
- const permission = await (0, _checkBasePermissions.default)(context, {
104
+ const permission = await (0, _checkBasePermissions.checkBasePermissions)(getPermission, {
129
105
  rwd: "w"
130
106
  });
131
- const original = await storageOperations.get({
107
+ const original = await storageOperations.files.get({
132
108
  where: {
133
109
  id,
134
- tenant: context.tenancy.getCurrentTenant().id,
135
- locale: getLocaleCode(context)
110
+ tenant: getTenantId(),
111
+ locale: getLocaleCode()
136
112
  }
137
113
  });
138
114
  if (!original) {
139
115
  throw new _handlerGraphql.NotFoundError(`File with id "${id}" does not exists.`);
140
116
  }
141
- checkOwnership(original, permission, context);
117
+ checkOwnership(original, permission, getIdentity());
142
118
  const file = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), input), {}, {
143
119
  tags: Array.isArray(input.tags) ? input.tags : Array.isArray(original.tags) ? original.tags : [],
120
+ aliases: Array.isArray(input.aliases) ? input.aliases : Array.isArray(original.aliases) ? original.aliases : [],
144
121
  id: original.id,
145
- webinyVersion: context.WEBINY_VERSION
122
+ webinyVersion: WEBINY_VERSION
146
123
  });
147
124
  try {
148
- await (0, _lifecycleEvents.runLifecycleEvent)("beforeUpdate", {
149
- context,
150
- plugins: filePlugins,
125
+ await this.onFileBeforeUpdate.publish({
151
126
  original,
152
- data: file
127
+ file,
128
+ input
153
129
  });
154
- const result = await storageOperations.update({
130
+ const result = await storageOperations.files.update({
155
131
  original,
156
132
  file
157
133
  });
158
- await (0, _lifecycleEvents.runLifecycleEvent)("afterUpdate", {
159
- context,
160
- plugins: filePlugins,
134
+ await this.onFileAfterUpdate.publish({
161
135
  original,
162
- data: file,
163
- file: result
136
+ file,
137
+ input
164
138
  });
165
139
  return result;
166
140
  } catch (ex) {
@@ -171,32 +145,28 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
171
145
  }
172
146
  },
173
147
  async deleteFile(id) {
174
- const permission = await (0, _checkBasePermissions.default)(context, {
148
+ const permission = await (0, _checkBasePermissions.checkBasePermissions)(getPermission, {
175
149
  rwd: "d"
176
150
  });
177
- const file = await storageOperations.get({
151
+ const file = await storageOperations.files.get({
178
152
  where: {
179
153
  id,
180
- tenant: context.tenancy.getCurrentTenant().id,
181
- locale: getLocaleCode(context)
154
+ tenant: getTenantId(),
155
+ locale: getLocaleCode()
182
156
  }
183
157
  });
184
158
  if (!file) {
185
159
  throw new _handlerGraphql.NotFoundError(`File with id "${id}" does not exists.`);
186
160
  }
187
- checkOwnership(file, permission, context);
161
+ checkOwnership(file, permission, getIdentity());
188
162
  try {
189
- await (0, _lifecycleEvents.runLifecycleEvent)("beforeDelete", {
190
- context,
191
- plugins: filePlugins,
163
+ await this.onFileBeforeDelete.publish({
192
164
  file
193
165
  });
194
- await storageOperations.delete({
166
+ await storageOperations.files.delete({
195
167
  file
196
168
  });
197
- await (0, _lifecycleEvents.runLifecycleEvent)("afterDelete", {
198
- context,
199
- plugins: filePlugins,
169
+ await this.onFileAfterDelete.publish({
200
170
  file
201
171
  });
202
172
  } catch (ex) {
@@ -207,21 +177,13 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
207
177
  }
208
178
  return true;
209
179
  },
210
- async createFilesInBatch(inputs) {
211
- if (!Array.isArray(inputs)) {
212
- throw new _error.default(`"data" must be an array.`, "CREATE_FILES_NON_ARRAY");
213
- }
214
- if (inputs.length === 0) {
215
- throw new _error.default(`"data" argument must contain at least one file.`, "CREATE_FILES_MIN_FILES");
216
- }
217
- if (inputs.length > BATCH_CREATE_MAX_FILES) {
218
- throw new _error.default(`"data" argument must not contain more than ${BATCH_CREATE_MAX_FILES} files.`, "CREATE_FILES_MAX_FILES");
219
- }
220
- await (0, _checkBasePermissions.default)(context, {
180
+ async createFilesInBatch(inputs, meta) {
181
+ await (0, _checkBasePermissions.checkBasePermissions)(getPermission, {
221
182
  rwd: "w"
222
183
  });
223
- const identity = context.security.getIdentity();
224
- const tenant = context.tenancy.getCurrentTenant();
184
+ const identity = getIdentity();
185
+ const tenant = getTenantId();
186
+ const locale = getLocaleCode();
225
187
  const createdBy = {
226
188
  id: identity.id,
227
189
  displayName: identity.displayName,
@@ -230,31 +192,28 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
230
192
  const files = inputs.map(input => {
231
193
  return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, input), {}, {
232
194
  tags: Array.isArray(input.tags) ? input.tags : [],
195
+ aliases: Array.isArray(input.aliases) ? input.aliases : [],
233
196
  meta: (0, _objectSpread2.default)({
234
197
  private: false
235
198
  }, input.meta || {}),
236
- id: (0, _mdbid.default)(),
237
- tenant: tenant.id,
199
+ tenant,
238
200
  createdOn: new Date().toISOString(),
239
201
  createdBy,
240
- locale: getLocaleCode(context),
241
- webinyVersion: context.WEBINY_VERSION
202
+ locale,
203
+ webinyVersion: WEBINY_VERSION
242
204
  });
243
205
  });
244
206
  try {
245
- await (0, _lifecycleEvents.runLifecycleEvent)("beforeBatchCreate", {
246
- context,
247
- plugins: filePlugins,
248
- data: files
207
+ await this.onFileBeforeBatchCreate.publish({
208
+ files,
209
+ meta
249
210
  });
250
- const results = await storageOperations.createBatch({
211
+ const results = await storageOperations.files.createBatch({
251
212
  files
252
213
  });
253
- await (0, _lifecycleEvents.runLifecycleEvent)("afterBatchCreate", {
254
- context,
255
- plugins: filePlugins,
256
- data: files,
257
- files: results
214
+ await this.onFileAfterBatchCreate.publish({
215
+ files,
216
+ meta
258
217
  });
259
218
  return results;
260
219
  } catch (ex) {
@@ -264,7 +223,7 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
264
223
  }
265
224
  },
266
225
  async listFiles(params = {}) {
267
- const permission = await (0, _checkBasePermissions.default)(context, {
226
+ const permission = await (0, _checkBasePermissions.checkBasePermissions)(getPermission, {
268
227
  rwd: "r"
269
228
  });
270
229
  const {
@@ -279,14 +238,14 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
279
238
  } = params;
280
239
  const where = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, initialWhere), {}, {
281
240
  private: false,
282
- locale: getLocaleCode(context),
283
- tenant: context.tenancy.getCurrentTenant().id
241
+ locale: getLocaleCode(),
242
+ tenant: getTenantId()
284
243
  });
285
244
  /**
286
245
  * Always override the createdBy received from the user, if any.
287
246
  */
288
247
  if (permission.own === true) {
289
- const identity = context.security.getIdentity();
248
+ const identity = getIdentity();
290
249
  where.createdBy = identity.id;
291
250
  }
292
251
  /**
@@ -320,7 +279,7 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
320
279
  }
321
280
  const sort = Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : ["id_DESC"];
322
281
  try {
323
- return await storageOperations.list({
282
+ return await storageOperations.files.list({
324
283
  where,
325
284
  after,
326
285
  limit,
@@ -340,25 +299,18 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
340
299
  after,
341
300
  limit
342
301
  }) {
343
- await (0, _checkBasePermissions.default)(context);
302
+ await (0, _checkBasePermissions.checkBasePermissions)(getPermission);
344
303
  const where = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, initialWhere), {}, {
345
- tenant: context.tenancy.getCurrentTenant().id,
346
- locale: getLocaleCode(context)
304
+ tenant: getTenantId(),
305
+ locale: getLocaleCode()
347
306
  });
348
307
  const params = {
349
308
  where,
350
- limit: limit || 100000,
309
+ limit: limit || 1000000,
351
310
  after
352
311
  };
353
312
  try {
354
- const [tags] = await storageOperations.tags(params);
355
- if (Array.isArray(tags) === false) {
356
- return [];
357
- }
358
- /**
359
- * just to keep it standardized, sort by the tag ASC
360
- */
361
- return tags.sort();
313
+ return await storageOperations.files.tags(params);
362
314
  } catch (ex) {
363
315
  throw new _error.default(ex.message || "Could not search for tags.", ex.code || "FILE_TAG_SEARCH_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
364
316
  params
@@ -366,7 +318,5 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
366
318
  }
367
319
  }
368
320
  };
369
- });
370
- filesContextCrudPlugin.name = "FileManagerFilesCrud";
371
- var _default = filesContextCrudPlugin;
372
- exports.default = _default;
321
+ };
322
+ exports.createFilesCrud = createFilesCrud;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["checkOwnership","file","permission","identity","own","createdBy","id","NotAuthorizedError","createFilesCrud","config","storageOperations","getLocaleCode","getTenantId","getIdentity","getPermission","WEBINY_VERSION","onFileBeforeCreate","createTopic","onFileAfterCreate","onFileBeforeBatchCreate","onFileAfterBatchCreate","onFileBeforeUpdate","onFileAfterUpdate","onFileBeforeDelete","onFileAfterDelete","getFile","checkBasePermissions","rwd","files","get","where","tenant","locale","NotFoundError","createFile","input","meta","key","split","tags","Array","isArray","aliases","private","createdOn","Date","toISOString","displayName","type","webinyVersion","publish","result","create","ex","WebinyError","message","code","data","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","map","results","createBatch","listFiles","params","limit","search","types","ids","after","initialWhere","sort","initialSort","length","type_in","tag_in","tag","toLowerCase","id_in","list","listTags"],"sources":["files.crud.ts"],"sourcesContent":["import { NotFoundError } from \"@webiny/handler-graphql\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport WebinyError from \"@webiny/error\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport {\n CreatedBy,\n File,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilePermission,\n FilesCRUD,\n FilesListOpts\n} from \"~/types\";\nimport { checkBasePermissions } from \"./checkBasePermissions\";\nimport { FileManagerConfig } from \"~/createFileManager/index\";\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, identity: SecurityIdentity) => {\n if (permission?.own === true) {\n if (file.createdBy.id !== identity.id) {\n throw new NotAuthorizedError();\n }\n }\n};\n\nexport const createFilesCrud = (config: FileManagerConfig): FilesCRUD => {\n const {\n storageOperations,\n getLocaleCode,\n getTenantId,\n getIdentity,\n getPermission,\n WEBINY_VERSION\n } = config;\n\n return {\n onFileBeforeCreate: createTopic(\"fileManager.onFileBeforeCreate\"),\n onFileAfterCreate: createTopic(\"fileManager.onFileAfterCreate\"),\n onFileBeforeBatchCreate: createTopic(\"fileManager.onFileBeforeBatchCreate\"),\n onFileAfterBatchCreate: createTopic(\"fileManager.onFileAfterBatchCreate\"),\n onFileBeforeUpdate: createTopic(\"fileManager.onFileBeforeUpdate\"),\n onFileAfterUpdate: createTopic(\"fileManager.onFileAfterUpdate\"),\n onFileBeforeDelete: createTopic(\"fileManager.onFileBeforeDelete\"),\n onFileAfterDelete: createTopic(\"fileManager.onFileAfterDelete\"),\n async getFile(id: string) {\n const permission = await checkBasePermissions(getPermission, { rwd: \"r\" });\n\n const file = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, getIdentity());\n\n return file;\n },\n async createFile(input, meta) {\n await checkBasePermissions(getPermission, { rwd: \"w\" });\n const identity = getIdentity();\n\n // Extract ID from file key\n const [id] = input.key.split(\"/\");\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n aliases: Array.isArray(input.aliases) ? input.aliases : [],\n id: input.id || id,\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant: getTenantId(),\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n locale: getLocaleCode(),\n webinyVersion: WEBINY_VERSION\n };\n\n try {\n await this.onFileBeforeCreate.publish({ file, meta });\n\n const result = await storageOperations.files.create({ file });\n\n await this.onFileAfterCreate.publish({ file, meta });\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(getPermission, { rwd: \"w\" });\n\n const original = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(original, permission, getIdentity());\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 aliases: Array.isArray(input.aliases)\n ? input.aliases\n : Array.isArray(original.aliases)\n ? original.aliases\n : [],\n id: original.id,\n webinyVersion: WEBINY_VERSION\n };\n\n try {\n await this.onFileBeforeUpdate.publish({\n original,\n file,\n input\n });\n\n const result = await storageOperations.files.update({\n original,\n file\n });\n\n await this.onFileAfterUpdate.publish({\n original,\n file,\n input\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(getPermission, { rwd: \"d\" });\n\n const file = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, getIdentity());\n\n try {\n await this.onFileBeforeDelete.publish({ file });\n\n await storageOperations.files.delete({\n file\n });\n\n await this.onFileAfterDelete.publish({ file });\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, meta) {\n await checkBasePermissions(getPermission, { rwd: \"w\" });\n\n const identity = getIdentity();\n const tenant = getTenantId();\n const locale = getLocaleCode();\n\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 aliases: Array.isArray(input.aliases) ? input.aliases : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant,\n createdOn: new Date().toISOString(),\n createdBy,\n locale,\n webinyVersion: WEBINY_VERSION\n };\n });\n\n try {\n await this.onFileBeforeBatchCreate.publish({ files, meta });\n const results = await storageOperations.files.createBatch({\n files\n });\n await this.onFileAfterBatchCreate.publish({ files, meta });\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(getPermission, { 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(),\n tenant: getTenantId()\n };\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (permission.own === true) {\n const identity = 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.files.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(getPermission);\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n ...initialWhere,\n tenant: getTenantId(),\n locale: getLocaleCode()\n };\n\n const params = {\n where,\n limit: limit || 1000000,\n after\n };\n\n try {\n return await storageOperations.files.tags(params);\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"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AAWA;AAGA;AACA;AACA;AACA,MAAMA,cAAc,GAAG,CAACC,IAAU,EAAEC,UAA0B,EAAEC,QAA0B,KAAK;EAC3F,IAAI,CAAAD,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEE,GAAG,MAAK,IAAI,EAAE;IAC1B,IAAIH,IAAI,CAACI,SAAS,CAACC,EAAE,KAAKH,QAAQ,CAACG,EAAE,EAAE;MACnC,MAAM,IAAIC,+BAAkB,EAAE;IAClC;EACJ;AACJ,CAAC;AAEM,MAAMC,eAAe,GAAIC,MAAyB,IAAgB;EACrE,MAAM;IACFC,iBAAiB;IACjBC,aAAa;IACbC,WAAW;IACXC,WAAW;IACXC,aAAa;IACbC;EACJ,CAAC,GAAGN,MAAM;EAEV,OAAO;IACHO,kBAAkB,EAAE,IAAAC,mBAAW,EAAC,gCAAgC,CAAC;IACjEC,iBAAiB,EAAE,IAAAD,mBAAW,EAAC,+BAA+B,CAAC;IAC/DE,uBAAuB,EAAE,IAAAF,mBAAW,EAAC,qCAAqC,CAAC;IAC3EG,sBAAsB,E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AAuD,+DACtD6C,YAAY;QACf5C,MAAM,EAAEnB,WAAW,EAAE;QACrBoB,MAAM,EAAErB,aAAa;MAAE,EAC1B;MAED,MAAM0D,MAAM,GAAG;QACXvC,KAAK;QACLwC,KAAK,EAAEA,KAAK,IAAI,OAAO;QACvBI;MACJ,CAAC;MAED,IAAI;QACA,OAAO,MAAMhE,iBAAiB,CAACkB,KAAK,CAACW,IAAI,CAAC8B,MAAM,CAAC;MACrD,CAAC,CAAC,OAAOhB,EAAE,EAAE;QACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,4BAA4B,EAC1CF,EAAE,CAACG,IAAI,IAAI,uBAAuB,8DAE1BH,EAAE,CAACI,IAAI,IAAI,CAAC,CAAC;UACjBY;QAAM,GAEb;MACL;IACJ;EACJ,CAAC;AACL,CAAC;AAAC"}
File without changes
@@ -0,0 +1,55 @@
1
+ // /**
2
+ // * Package @commodo/fields does not have types
3
+ // */
4
+ // // @ts-ignore
5
+ // import { withFields, string, number, onSet } from "@commodo/fields";
6
+ // /**
7
+ // * Package commodo-fields-object does not have types
8
+ // */
9
+ // // @ts-ignore
10
+ // import { object } from "commodo-fields-object";
11
+ // import { validation } from "@webiny/validation";
12
+ //
13
+ // export default (create = true) => {
14
+ // return withFields({
15
+ // key: string({
16
+ // validation: validation.create(`${create ? "required," : ""}maxLength:1000`)
17
+ // }),
18
+ // name: string({ validation: validation.create("maxLength:1000") }),
19
+ // size: number(),
20
+ // type: string({ validation: validation.create("maxLength:255") }),
21
+ // meta: object({ value: { private: false } }),
22
+ // tags: onSet((value: string[]) => {
23
+ // if (!Array.isArray(value)) {
24
+ // return null;
25
+ // }
26
+ //
27
+ // return value.map(item => item.toLowerCase());
28
+ // })(
29
+ // string({
30
+ // list: true,
31
+ // validation: (tags: string[]) => {
32
+ // if (!Array.isArray(tags)) {
33
+ // return;
34
+ // }
35
+ //
36
+ // if (tags.length > 15) {
37
+ // throw Error("You cannot set more than 15 tags.");
38
+ // }
39
+ //
40
+ // for (let i = 0; i < tags.length; i++) {
41
+ // const tag = tags[i];
42
+ // if (typeof tag !== "string") {
43
+ // throw Error("Tag must be typeof string.");
44
+ // }
45
+ //
46
+ // if (tag.length > 50) {
47
+ // throw Error(`Tag ${tag} is more than 50 characters long.`);
48
+ // }
49
+ // }
50
+ // }
51
+ // })
52
+ // )
53
+ // })();
54
+ // };
55
+ "use strict";
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["filevalidation.disabled.ts"],"sourcesContent":["// /**\n// * Package @commodo/fields does not have types\n// */\n// // @ts-ignore\n// import { withFields, string, number, onSet } from \"@commodo/fields\";\n// /**\n// * Package commodo-fields-object does not have types\n// */\n// // @ts-ignore\n// import { object } from \"commodo-fields-object\";\n// import { validation } from \"@webiny/validation\";\n//\n// export 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":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA"}
@@ -0,0 +1,13 @@
1
+ import { FileManagerContextObject, FileManagerStorageOperations } from "../types";
2
+ import { GetPermission, SecurityIdentity } from "@webiny/api-security/types";
3
+ import { FileStorage } from "../storage/FileStorage";
4
+ export interface FileManagerConfig {
5
+ storageOperations: FileManagerStorageOperations;
6
+ getTenantId: () => string;
7
+ getLocaleCode: () => string;
8
+ getIdentity: () => SecurityIdentity;
9
+ getPermission: GetPermission;
10
+ storage: FileStorage;
11
+ WEBINY_VERSION: string;
12
+ }
13
+ export declare const createFileManager: (config: FileManagerConfig) => FileManagerContextObject;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createFileManager = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _files = require("./files.crud");
10
+ var _settings = require("./settings.crud");
11
+ var _system = require("./system.crud");
12
+ const createFileManager = config => {
13
+ const filesCrud = (0, _files.createFilesCrud)(config);
14
+ const settingsCrud = (0, _settings.createSettingsCrud)(config);
15
+ const systemCrud = (0, _system.createSystemCrud)(config);
16
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, filesCrud), settingsCrud), systemCrud), {}, {
17
+ storage: config.storage
18
+ });
19
+ };
20
+ exports.createFileManager = createFileManager;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFileManager","config","filesCrud","createFilesCrud","settingsCrud","createSettingsCrud","systemCrud","createSystemCrud","storage"],"sources":["index.ts"],"sourcesContent":["import { FileManagerContextObject, FileManagerStorageOperations } from \"~/types\";\nimport { GetPermission, SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createFilesCrud } from \"~/createFileManager/files.crud\";\nimport { FileStorage } from \"~/storage/FileStorage\";\nimport { createSettingsCrud } from \"~/createFileManager/settings.crud\";\nimport { createSystemCrud } from \"~/createFileManager/system.crud\";\n\nexport interface FileManagerConfig {\n storageOperations: FileManagerStorageOperations;\n getTenantId: () => string;\n getLocaleCode: () => string;\n getIdentity: () => SecurityIdentity;\n getPermission: GetPermission;\n storage: FileStorage;\n WEBINY_VERSION: string;\n}\n\nexport const createFileManager = (config: FileManagerConfig): FileManagerContextObject => {\n const filesCrud = createFilesCrud(config);\n const settingsCrud = createSettingsCrud(config);\n const systemCrud = createSystemCrud(config);\n\n return {\n ...filesCrud,\n ...settingsCrud,\n ...systemCrud,\n storage: config.storage\n };\n};\n"],"mappings":";;;;;;;;AAEA;AAEA;AACA;AAYO,MAAMA,iBAAiB,GAAIC,MAAyB,IAA+B;EACtF,MAAMC,SAAS,GAAG,IAAAC,sBAAe,EAACF,MAAM,CAAC;EACzC,MAAMG,YAAY,GAAG,IAAAC,4BAAkB,EAACJ,MAAM,CAAC;EAC/C,MAAMK,UAAU,GAAG,IAAAC,wBAAgB,EAACN,MAAM,CAAC;EAE3C,2HACOC,SAAS,GACTE,YAAY,GACZE,UAAU;IACbE,OAAO,EAAEP,MAAM,CAACO;EAAO;AAE/B,CAAC;AAAC"}
@@ -0,0 +1,3 @@
1
+ import { SettingsCRUD } from "../types";
2
+ import { FileManagerConfig } from "./index";
3
+ export declare const createSettingsCrud: ({ storageOperations, getTenantId }: FileManagerConfig) => SettingsCRUD;