@webiny/api-file-manager 0.0.0-mt-2 → 0.0.0-unstable.13771d80a8

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 (156) hide show
  1. package/createFileManager/checkBasePermissions.d.ts +5 -0
  2. package/createFileManager/checkBasePermissions.js +24 -0
  3. package/createFileManager/checkBasePermissions.js.map +1 -0
  4. package/createFileManager/files.crud.d.ts +3 -0
  5. package/createFileManager/files.crud.js +336 -0
  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/createFileManager/settings.crud.js +91 -0
  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/graphql/index.js +277 -0
  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 +20 -118
  36. package/handlers/download/index.js.map +1 -0
  37. package/handlers/manage/index.d.ts +5 -3
  38. package/handlers/manage/index.js +43 -58
  39. package/handlers/manage/index.js.map +1 -0
  40. package/handlers/transform/index.d.ts +2 -3
  41. package/handlers/transform/index.js +66 -78
  42. package/handlers/transform/index.js.map +1 -0
  43. package/handlers/transform/legacyUtils.d.ts +17 -0
  44. package/handlers/transform/legacyUtils.js +42 -0
  45. package/handlers/transform/legacyUtils.js.map +1 -0
  46. package/handlers/transform/loaders/imageLoader.d.ts +26 -9
  47. package/handlers/transform/loaders/imageLoader.js +13 -25
  48. package/handlers/transform/loaders/imageLoader.js.map +1 -0
  49. package/handlers/transform/loaders/index.d.ts +4 -9
  50. package/handlers/transform/loaders/index.js +1 -4
  51. package/handlers/transform/loaders/index.js.map +1 -0
  52. package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +7 -3
  53. package/handlers/transform/loaders/sanitizeImageTransformations.js +24 -30
  54. package/handlers/transform/loaders/sanitizeImageTransformations.js.map +1 -0
  55. package/handlers/transform/managers/imageManager.d.ts +12 -6
  56. package/handlers/transform/managers/imageManager.js +37 -28
  57. package/handlers/transform/managers/imageManager.js.map +1 -0
  58. package/handlers/transform/managers/index.d.ts +2 -6
  59. package/handlers/transform/managers/index.js +1 -4
  60. package/handlers/transform/managers/index.js.map +1 -0
  61. package/handlers/transform/optimizeImage.d.ts +2 -1
  62. package/handlers/transform/optimizeImage.js +4 -7
  63. package/handlers/transform/optimizeImage.js.map +1 -0
  64. package/handlers/transform/transformImage.d.ts +5 -4
  65. package/handlers/transform/transformImage.js +4 -9
  66. package/handlers/transform/transformImage.js.map +1 -0
  67. package/handlers/transform/utils.d.ts +2 -2
  68. package/handlers/transform/utils.js +8 -18
  69. package/handlers/transform/utils.js.map +1 -0
  70. package/handlers/types.d.ts +8 -0
  71. package/handlers/types.js +5 -0
  72. package/handlers/types.js.map +1 -0
  73. package/handlers/utils/getEnvironment.js +0 -2
  74. package/handlers/utils/getEnvironment.js.map +1 -0
  75. package/handlers/utils/getObjectParams.d.ts +3 -4
  76. package/handlers/utils/getObjectParams.js +1 -7
  77. package/handlers/utils/getObjectParams.js.map +1 -0
  78. package/handlers/utils/index.d.ts +0 -1
  79. package/handlers/utils/index.js +1 -12
  80. package/handlers/utils/index.js.map +1 -0
  81. package/index.d.ts +6 -0
  82. package/index.js +68 -0
  83. package/index.js.map +1 -0
  84. package/package.json +29 -30
  85. package/plugins/FilePhysicalStoragePlugin.d.ts +21 -0
  86. package/plugins/FilePhysicalStoragePlugin.js +31 -0
  87. package/plugins/FilePhysicalStoragePlugin.js.map +1 -0
  88. package/plugins/FileStorageTransformPlugin.d.ts +34 -0
  89. package/plugins/FileStorageTransformPlugin.js +40 -0
  90. package/plugins/FileStorageTransformPlugin.js.map +1 -0
  91. package/plugins/crud/files/validation.js +1 -1
  92. package/plugins/crud/files/validation.js.map +1 -0
  93. package/plugins/crud/files.crud.d.ts +1 -1
  94. package/plugins/crud/files.crud.js +48 -44
  95. package/plugins/crud/files.crud.js.map +1 -0
  96. package/plugins/crud/settings.crud.d.ts +1 -1
  97. package/plugins/crud/settings.crud.js +10 -9
  98. package/plugins/crud/settings.crud.js.map +1 -0
  99. package/plugins/crud/system.crud.d.ts +1 -1
  100. package/plugins/crud/system.crud.js +18 -10
  101. package/plugins/crud/system.crud.js.map +1 -0
  102. package/plugins/crud/utils/checkBasePermissions.js +1 -1
  103. package/plugins/crud/utils/checkBasePermissions.js.map +1 -0
  104. package/plugins/crud/utils/createFileModel.d.ts +3 -0
  105. package/plugins/crud/utils/createFileModel.js +13 -0
  106. package/plugins/crud/utils/createFileModel.js.map +1 -0
  107. package/plugins/crud/utils/lifecycleEvents.d.ts +2 -2
  108. package/plugins/crud/utils/lifecycleEvents.js +6 -1
  109. package/plugins/crud/utils/lifecycleEvents.js.map +1 -0
  110. package/plugins/definitions/FilePhysicalStoragePlugin.d.ts +10 -11
  111. package/plugins/definitions/FilePhysicalStoragePlugin.js +1 -1
  112. package/plugins/definitions/FilePhysicalStoragePlugin.js.map +1 -0
  113. package/plugins/definitions/FilePlugin.d.ts +6 -3
  114. package/plugins/definitions/FilePlugin.js +9 -3
  115. package/plugins/definitions/FilePlugin.js.map +1 -0
  116. package/plugins/definitions/FileStorageTransformPlugin.d.ts +9 -9
  117. package/plugins/definitions/FileStorageTransformPlugin.js +1 -1
  118. package/plugins/definitions/FileStorageTransformPlugin.js.map +1 -0
  119. package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +4 -4
  120. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +1 -1
  121. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +1 -0
  122. package/plugins/definitions/InstallationPlugin.d.ts +9 -9
  123. package/plugins/definitions/InstallationPlugin.js +5 -3
  124. package/plugins/definitions/InstallationPlugin.js.map +1 -0
  125. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +4 -4
  126. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +1 -1
  127. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +1 -0
  128. package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +4 -4
  129. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +1 -1
  130. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +1 -0
  131. package/plugins/graphql.js +20 -4
  132. package/plugins/graphql.js.map +1 -0
  133. package/plugins/index.d.ts +2 -2
  134. package/plugins/index.js +22 -19
  135. package/plugins/index.js.map +1 -0
  136. package/plugins/storage/FileStorage.d.ts +23 -24
  137. package/plugins/storage/FileStorage.js +28 -20
  138. package/plugins/storage/FileStorage.js.map +1 -0
  139. package/plugins/storage/index.d.ts +1 -1
  140. package/plugins/storage/index.js +6 -2
  141. package/plugins/storage/index.js.map +1 -0
  142. package/storage/FileStorage.d.ts +30 -0
  143. package/storage/FileStorage.js +86 -0
  144. package/storage/FileStorage.js.map +1 -0
  145. package/types/file.d.ts +33 -0
  146. package/types/file.js +5 -0
  147. package/types/file.js.map +1 -0
  148. package/types/file.lifecycle.d.ts +40 -0
  149. package/types/file.lifecycle.js +5 -0
  150. package/types/file.lifecycle.js.map +1 -0
  151. package/types.d.ts +49 -50
  152. package/types.js +22 -0
  153. package/types.js.map +1 -0
  154. package/utils.js.map +1 -0
  155. package/handlers/utils/createHandler.d.ts +0 -24
  156. package/handlers/utils/createHandler.js +0 -68
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -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
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -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
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -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"}
@@ -8,6 +8,11 @@ exports.default = void 0;
8
8
  var _handlerGraphql = require("@webiny/handler-graphql");
9
9
 
10
10
  const emptyResolver = () => ({});
11
+ /**
12
+ * Use any because it really can be any.
13
+ * TODO @ts-refactor maybe use generics at some point?
14
+ */
15
+
11
16
 
12
17
  const resolve = async fn => {
13
18
  try {
@@ -60,6 +65,7 @@ const plugin = {
60
65
  code: String
61
66
  message: String
62
67
  data: JSON
68
+ stack: String
63
69
  }
64
70
 
65
71
  type FileListResponse {
@@ -99,11 +105,13 @@ const plugin = {
99
105
  type FileManagerSettings {
100
106
  uploadMinFileSize: Number
101
107
  uploadMaxFileSize: Number
108
+ srcPrefix: String
102
109
  }
103
110
 
104
111
  input FileManagerSettingsInput {
105
112
  uploadMinFileSize: Number
106
113
  uploadMaxFileSize: Number
114
+ srcPrefix: String
107
115
  }
108
116
 
109
117
  type FileManagerSettingsResponse {
@@ -118,8 +126,16 @@ const plugin = {
118
126
  tag: String
119
127
  tag_in: [String!]
120
128
  tag_and_in: [String!]
129
+ tag_startsWith: String
130
+ tag_not_startsWith: String
121
131
  id_in: [ID!]
122
132
  id: ID
133
+ createdBy: ID
134
+ }
135
+
136
+ input TagWhereInput {
137
+ tag_startsWith: String
138
+ tag_not_startsWith: String
123
139
  }
124
140
 
125
141
  type FmQuery {
@@ -135,7 +151,7 @@ const plugin = {
135
151
  where: FileWhereInput
136
152
  ): FileListResponse
137
153
 
138
- listTags: [String]
154
+ listTags(where: TagWhereInput): [String]
139
155
 
140
156
  # Get installed version
141
157
  version: String
@@ -178,7 +194,7 @@ const plugin = {
178
194
  File: {
179
195
  async src(file, _, context) {
180
196
  const settings = await context.fileManager.settings.getSettings();
181
- return settings.srcPrefix + file.key;
197
+ return ((settings === null || settings === void 0 ? void 0 : settings.srcPrefix) || "") + file.key;
182
198
  }
183
199
 
184
200
  },
@@ -212,12 +228,12 @@ const plugin = {
212
228
 
213
229
  async version(_, __, context) {
214
230
  const {
215
- i18nContent,
231
+ i18n,
216
232
  tenancy,
217
233
  fileManager
218
234
  } = context;
219
235
 
220
- if (!tenancy.getCurrentTenant() || !i18nContent.getLocale()) {
236
+ if (!tenancy.getCurrentTenant() || !i18n.getContentLocale()) {
221
237
  return null;
222
238
  }
223
239
 
@@ -0,0 +1 @@
1
+ {"version":3,"names":["emptyResolver","resolve","fn","Response","e","ErrorResponse","plugin","type","schema","typeDefs","resolvers","File","src","file","_","context","settings","fileManager","getSettings","srcPrefix","key","Query","Mutation","FmQuery","getFile","args","files","id","listFiles","data","meta","ListResponse","listTags","error","version","__","i18n","tenancy","getCurrentTenant","getContentLocale","system","getVersion","FmMutation","createFile","updateFile","createFiles","createFilesInBatch","deleteFile","storage","delete","install","upgrade","updateSettings"],"sources":["graphql.ts"],"sourcesContent":["import { Response, ErrorResponse, ListResponse } from \"@webiny/handler-graphql\";\nimport { FileManagerContext, FilesListOpts } from \"~/types\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\n\nconst emptyResolver = () => ({});\n\n/**\n * Use any because it really can be any.\n * TODO @ts-refactor maybe use generics at some point?\n */\ninterface ResolveCallable {\n (): Promise<any>;\n}\n\nconst resolve = async (fn: ResolveCallable) => {\n try {\n return new Response(await fn());\n } catch (e) {\n return new ErrorResponse(e);\n }\n};\n\nconst plugin: GraphQLSchemaPlugin<FileManagerContext> = {\n type: \"graphql-schema\",\n schema: {\n typeDefs: /* GraphQL */ `\n type FmCreatedBy {\n id: ID\n displayName: String\n }\n\n input FileInput {\n key: String\n name: String\n size: Int\n type: String\n tags: [String]\n meta: JSON\n }\n\n type UploadFileResponseDataFile {\n name: String\n type: String\n size: Int\n key: String\n }\n\n type UploadFileResponseData {\n # Contains data that is necessary for initiating a file upload.\n data: JSON\n file: UploadFileResponseDataFile\n }\n\n type FileListMeta {\n cursor: String\n totalCount: Int\n hasMoreItems: Boolean\n }\n\n type FileError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type FileListResponse {\n data: [File]\n meta: FileListMeta\n error: FileError\n }\n\n type FileResponse {\n data: File\n error: FileError\n }\n\n type CreateFilesResponse {\n data: [File]!\n error: FileError\n }\n\n type File {\n id: ID\n key: String\n name: String\n size: Int\n type: String\n src: String\n tags: [String]\n meta: JSON\n createdOn: DateTime\n createdBy: FmCreatedBy\n }\n\n type FileManagerBooleanResponse {\n data: Boolean\n error: FileError\n }\n\n type FileManagerSettings {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n input FileManagerSettingsInput {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n type FileManagerSettingsResponse {\n data: FileManagerSettings\n error: FileError\n }\n\n input FileWhereInput {\n search: String\n type: String\n type_in: [String!]\n tag: String\n tag_in: [String!]\n tag_and_in: [String!]\n tag_startsWith: String\n tag_not_startsWith: String\n id_in: [ID!]\n id: ID\n createdBy: ID\n }\n\n input TagWhereInput {\n tag_startsWith: String\n tag_not_startsWith: String\n }\n\n type FmQuery {\n getFile(id: ID, where: JSON, sort: String): FileResponse\n\n listFiles(\n limit: Int\n after: String\n types: [String]\n tags: [String]\n ids: [ID]\n search: String\n where: FileWhereInput\n ): FileListResponse\n\n listTags(where: TagWhereInput): [String]\n\n # Get installed version\n version: String\n\n getSettings: FileManagerSettingsResponse\n }\n\n type FilesDeleteResponse {\n data: Boolean\n error: FileError\n }\n\n type FmMutation {\n createFile(data: FileInput!): FileResponse\n createFiles(data: [FileInput]!): CreateFilesResponse\n updateFile(id: ID!, data: FileInput!): FileResponse\n deleteFile(id: ID!): FilesDeleteResponse\n\n # Install File manager\n install(srcPrefix: String): FileManagerBooleanResponse\n\n upgrade(version: String!): FileManagerBooleanResponse\n\n updateSettings(data: FileManagerSettingsInput): FileManagerSettingsResponse\n }\n\n input FilesInstallInput {\n srcPrefix: String!\n }\n\n extend type Query {\n fileManager: FmQuery\n }\n\n extend type Mutation {\n fileManager: FmMutation\n }\n `,\n resolvers: {\n File: {\n async src(file, _, context: FileManagerContext) {\n const settings = await context.fileManager.settings.getSettings();\n return (settings?.srcPrefix || \"\") + file.key;\n }\n },\n Query: {\n fileManager: emptyResolver\n },\n Mutation: {\n fileManager: emptyResolver\n },\n FmQuery: {\n getFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.getFile(args.id));\n },\n async listFiles(_, args: FilesListOpts, context) {\n try {\n const [data, meta] = await context.fileManager.files.listFiles(args);\n return new ListResponse(data, meta);\n } catch (e) {\n return new ErrorResponse(e);\n }\n },\n async listTags(_, args: any, context) {\n try {\n return await context.fileManager.files.listTags(args || {});\n } catch (error) {\n return new ErrorResponse(error);\n }\n },\n async version(_, __, context) {\n const { i18n, tenancy, fileManager } = context;\n if (!tenancy.getCurrentTenant() || !i18n.getContentLocale()) {\n return null;\n }\n\n return await fileManager.system.getVersion();\n },\n async getSettings(_, __, context) {\n return resolve(() => context.fileManager.settings.getSettings());\n }\n },\n FmMutation: {\n async createFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.createFile(args.data));\n },\n async updateFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.updateFile(args.id, args.data));\n },\n async createFiles(_, args: any, context) {\n return resolve(() => context.fileManager.files.createFilesInBatch(args.data));\n },\n async deleteFile(_, args: any, context) {\n return resolve(async () => {\n const file = await context.fileManager.files.getFile(args.id);\n return await context.fileManager.storage.delete({\n id: file.id,\n key: file.key\n });\n });\n },\n async install(_, args: any, context) {\n return resolve(() =>\n context.fileManager.system.install({ srcPrefix: args.srcPrefix })\n );\n },\n async upgrade(_, args: any, context) {\n return resolve(() => context.fileManager.system.upgrade(args.version));\n },\n async updateSettings(_, args: any, context) {\n return resolve(() => context.fileManager.settings.updateSettings(args.data));\n }\n }\n }\n }\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;AAAA;;AAIA,MAAMA,aAAa,GAAG,OAAO,EAAP,CAAtB;AAEA;AACA;AACA;AACA;;;AAKA,MAAMC,OAAO,GAAG,MAAOC,EAAP,IAA+B;EAC3C,IAAI;IACA,OAAO,IAAIC,wBAAJ,CAAa,MAAMD,EAAE,EAArB,CAAP;EACH,CAFD,CAEE,OAAOE,CAAP,EAAU;IACR,OAAO,IAAIC,6BAAJ,CAAkBD,CAAlB,CAAP;EACH;AACJ,CAND;;AAQA,MAAME,MAA+C,GAAG;EACpDC,IAAI,EAAE,gBAD8C;EAEpDC,MAAM,EAAE;IACJC,QAAQ;IAAE;IAAe;AACjC;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;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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AC,MAAMc,OAAO,CAACE,WAAR,CAAoBD,QAApB,CAA6BoC,cAA7B,CAA4C3B,IAAI,CAACI,IAAjD,CAAP,CAAd;QACH;;MA7BO;IA5CL;EApKP;AAF4C,CAAxD;eAqPevB,M"}
@@ -1,2 +1,2 @@
1
- declare const _default: () => (import("@webiny/handler-graphql/types").GraphQLSchemaPlugin<import("../types").FileManagerContext> | import("./definitions/FilePlugin").FilePlugin[] | import("@webiny/handler/plugins/ContextPlugin").ContextPlugin<import("../types").FileManagerContext>)[];
2
- export default _default;
1
+ export * from "./FilePhysicalStoragePlugin";
2
+ export * from "./FileStorageTransformPlugin";
package/plugins/index.js CHANGED
@@ -1,24 +1,27 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
- exports.default = void 0;
9
-
10
- var _graphql = _interopRequireDefault(require("./graphql"));
11
-
12
- var _files = _interopRequireDefault(require("./crud/files.crud"));
13
-
14
- var _validation = _interopRequireDefault(require("./crud/files/validation"));
15
-
16
- var _settings = _interopRequireDefault(require("./crud/settings.crud"));
17
-
18
- var _system = _interopRequireDefault(require("./crud/system.crud"));
19
-
20
- var _storage = _interopRequireDefault(require("./storage"));
21
-
22
- var _default = () => [_system.default, _settings.default, _files.default, _storage.default, _graphql.default, (0, _validation.default)()];
23
-
24
- exports.default = _default;
6
+ var _FilePhysicalStoragePlugin = require("./FilePhysicalStoragePlugin");
7
+ Object.keys(_FilePhysicalStoragePlugin).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _FilePhysicalStoragePlugin[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _FilePhysicalStoragePlugin[key];
14
+ }
15
+ });
16
+ });
17
+ var _FileStorageTransformPlugin = require("./FileStorageTransformPlugin");
18
+ Object.keys(_FileStorageTransformPlugin).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _FileStorageTransformPlugin[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _FileStorageTransformPlugin[key];
25
+ }
26
+ });
27
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./FilePhysicalStoragePlugin\";\nexport * from \"./FileStorageTransformPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -1,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,20 +1,18 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.FileStorage = void 0;
9
9
 
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
10
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
13
 
12
14
  var _error = _interopRequireDefault(require("@webiny/error"));
13
15
 
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
16
  const storagePluginType = "api-file-manager-storage";
19
17
 
20
18
  class FileStorage {
@@ -23,43 +21,53 @@ class FileStorage {
23
21
  }) {
24
22
  (0, _defineProperty2.default)(this, "storagePlugin", void 0);
25
23
  (0, _defineProperty2.default)(this, "context", void 0);
26
- this.storagePlugin = context.plugins.byType(storagePluginType).pop();
24
+ const storagePlugin = context.plugins.byType(storagePluginType).pop();
27
25
 
28
- if (!this.storagePlugin) {
26
+ if (!storagePlugin) {
29
27
  throw new _error.default(`Missing plugin of type "${storagePluginType}".`, "STORAGE_PLUGIN_ERROR");
30
28
  }
31
29
 
30
+ this.storagePlugin = storagePlugin;
32
31
  this.context = context;
33
32
  }
34
33
 
35
- async upload(args) {
36
- const settings = await this.context.fileManager.settings.getSettings(); // Add file to cloud storage.
34
+ async upload(params) {
35
+ const settings = await this.context.fileManager.settings.getSettings();
36
+
37
+ if (!settings) {
38
+ throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_ERROR");
39
+ } // Add file to cloud storage.
40
+
37
41
 
38
42
  const {
39
43
  file: fileData
40
- } = await this.storagePlugin.upload(_objectSpread(_objectSpread({}, args), {}, {
44
+ } = await this.storagePlugin.upload((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
41
45
  settings
42
46
  }));
43
47
  const {
44
48
  fileManager
45
49
  } = this.context; // Save file in DB.
46
50
 
47
- return await fileManager.files.createFile(_objectSpread(_objectSpread({}, fileData), {}, {
51
+ return await fileManager.files.createFile((0, _objectSpread2.default)((0, _objectSpread2.default)({}, fileData), {}, {
48
52
  meta: {
49
- private: Boolean(args.hideInFileManager)
53
+ private: Boolean(params.hideInFileManager)
50
54
  },
51
- tags: Array.isArray(args.tags) ? args.tags : []
55
+ tags: Array.isArray(params.tags) ? params.tags : []
52
56
  }));
53
57
  }
54
58
 
55
- async uploadFiles(args) {
56
- const settings = await this.context.fileManager.settings.getSettings(); // Upload files to cloud storage.
59
+ async uploadFiles(params) {
60
+ const settings = await this.context.fileManager.settings.getSettings();
61
+
62
+ if (!settings) {
63
+ throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_ERROR");
64
+ } // Upload files to cloud storage.
65
+
57
66
 
58
67
  const promises = [];
59
68
 
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), {}, {
69
+ for (const item of params.files) {
70
+ promises.push(this.storagePlugin.upload((0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
63
71
  settings
64
72
  })));
65
73
  } // Wait for all to resolve.
@@ -74,11 +82,11 @@ class FileStorage {
74
82
  return fileManager.files.createFilesInBatch(filesData);
75
83
  }
76
84
 
77
- async delete(args) {
85
+ async delete(params) {
78
86
  const {
79
87
  id,
80
88
  key
81
- } = args;
89
+ } = params;
82
90
  const {
83
91
  fileManager
84
92
  } = this.context; // Delete file from cloud storage.
@@ -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,0BAA1B;;AAuBO,MAAMC,WAAN,CAAkB;EAIrBC,WAAW,CAAC;IAAEC;EAAF,CAAD,EAAiC;IAAA;IAAA;IACxC,MAAMC,aAAa,GAAGD,OAAO,CAACE,OAAR,CACjBC,MADiB,CACiBN,iBADjB,EAEjBO,GAFiB,EAAtB;;IAGA,IAAI,CAACH,aAAL,EAAoB;MAChB,MAAM,IAAII,cAAJ,CACD,2BAA0BR,iBAAkB,I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J,GADJ;IAMH,CAdsD,CAevD;;;IACA,MAAMkB,mBAAmB,GAAG,MAAMC,OAAO,CAACC,GAAR,CAAYL,QAAZ,CAAlC;IAEA,MAAMM,SAAS,GAAGH,mBAAmB,CAACI,GAApB,CAAwBC,QAAQ,IAAIA,QAAQ,CAACpB,IAA7C,CAAlB;IAEA,MAAM;MAAEF;IAAF,IAAkB,KAAKT,OAA7B,CApBuD,CAqBvD;;IACA,OAAOS,WAAW,CAACI,KAAZ,CAAkBmB,kBAAlB,CAAqCH,SAArC,CAAP;EACH;;EAEW,MAANI,MAAM,CAAC1B,MAAD,EAAkC;IAC1C,MAAM;MAAE2B,EAAF;MAAMC;IAAN,IAAc5B,MAApB;IACA,MAAM;MAAEE;IAAF,IAAkB,KAAKT,OAA7B,CAF0C,CAG1C;;IACA,MAAM,KAAKC,aAAL,CAAmBgC,MAAnB,CAA0B;MAC5BE;IAD4B,CAA1B,CAAN,CAJ0C,CAO1C;;IACA,OAAO,MAAM1B,WAAW,CAACI,KAAZ,CAAkBuB,UAAlB,CAA6BF,EAA7B,CAAb;EACH;;AA3EoB"}
@@ -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;
@@ -5,12 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _ContextPlugin = require("@webiny/handler/plugins/ContextPlugin");
8
+ var _api = require("@webiny/api");
9
9
 
10
10
  var _FileStorage = require("./FileStorage");
11
11
 
12
- const fileStorageContextPlugin = new _ContextPlugin.ContextPlugin(async context => {
12
+ const fileStorageContextPlugin = new _api.ContextPlugin(async context => {
13
13
  if (!context.fileManager) {
14
+ /**
15
+ * We need to define the fileManager initial property as empty object.
16
+ * When casting as FileManagerContext, typescript is complaining.
17
+ */
14
18
  context.fileManager = {};
15
19
  }
16
20
 
@@ -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,kBAAJ,CAAsC,MAAMC,OAAN,IAAiB;EACpF,IAAI,CAACA,OAAO,CAACC,WAAb,EAA0B;IACtB;AACR;AACA;AACA;IACQD,OAAO,CAACC,WAAR,GAAsB,EAAtB;EACH;;EACDD,OAAO,CAACC,WAAR,CAAoBC,OAApB,GAA8B,IAAIC,wBAAJ,CAAgB;IAC1CH;EAD0C,CAAhB,CAA9B;AAGH,CAXgC,CAAjC;eAaeF,wB"}
@@ -0,0 +1,30 @@
1
+ /// <reference types="node" />
2
+ import { FileManagerContext } from "../types";
3
+ export declare type Result = Record<string, any>;
4
+ export interface FileStorageUploadParams {
5
+ buffer: Buffer;
6
+ hideInFileManager: boolean | string;
7
+ tags?: string[];
8
+ size: number;
9
+ name: string;
10
+ keyPrefix: string;
11
+ type: string;
12
+ }
13
+ export interface FileStorageDeleteParams {
14
+ id: string;
15
+ key: string;
16
+ }
17
+ export interface FileStorageUploadMultipleParams {
18
+ files: FileStorageUploadParams[];
19
+ }
20
+ export interface FileStorageParams {
21
+ context: FileManagerContext;
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>;
30
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.FileStorage = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+ const storagePluginType = "api-file-manager-storage";
12
+ class FileStorage {
13
+ constructor({
14
+ context
15
+ }) {
16
+ (0, _defineProperty2.default)(this, "storagePlugin", void 0);
17
+ (0, _defineProperty2.default)(this, "context", void 0);
18
+ const storagePlugin = context.plugins.byType(storagePluginType).pop();
19
+ if (!storagePlugin) {
20
+ throw new _error.default(`Missing plugin of type "${storagePluginType}".`, "STORAGE_PLUGIN_ERROR");
21
+ }
22
+ this.storagePlugin = storagePlugin;
23
+ this.context = context;
24
+ }
25
+ async upload(params) {
26
+ const settings = await this.context.fileManager.getSettings();
27
+ if (!settings) {
28
+ throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_ERROR");
29
+ }
30
+ // Add file to cloud storage.
31
+ const {
32
+ file: fileData
33
+ } = await this.storagePlugin.upload((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
34
+ settings
35
+ }));
36
+ const {
37
+ fileManager
38
+ } = this.context;
39
+
40
+ // Save file in DB.
41
+ return await fileManager.createFile((0, _objectSpread2.default)((0, _objectSpread2.default)({}, fileData), {}, {
42
+ meta: {
43
+ private: Boolean(params.hideInFileManager)
44
+ },
45
+ tags: Array.isArray(params.tags) ? params.tags : []
46
+ }));
47
+ }
48
+ async uploadFiles(params) {
49
+ const settings = await this.context.fileManager.getSettings();
50
+ if (!settings) {
51
+ throw new _error.default("Missing File Manager Settings.", "FILE_MANAGER_ERROR");
52
+ }
53
+ // Upload files to cloud storage.
54
+ const promises = [];
55
+ for (const item of params.files) {
56
+ promises.push(this.storagePlugin.upload((0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
57
+ settings
58
+ })));
59
+ }
60
+ // Wait for all to resolve.
61
+ const uploadFileResponses = await Promise.all(promises);
62
+ const filesData = uploadFileResponses.map(response => response.file);
63
+ const {
64
+ fileManager
65
+ } = this.context;
66
+ // Save files in DB.
67
+ return fileManager.createFilesInBatch(filesData);
68
+ }
69
+ async delete(params) {
70
+ const {
71
+ id,
72
+ key
73
+ } = params;
74
+ const {
75
+ fileManager
76
+ } = this.context;
77
+ // Delete file from cloud storage.
78
+ await this.storagePlugin.delete({
79
+ key
80
+ });
81
+
82
+ // Delete file from the DB.
83
+ return await fileManager.deleteFile(id);
84
+ }
85
+ }
86
+ exports.FileStorage = FileStorage;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["storagePluginType","FileStorage","constructor","context","storagePlugin","plugins","byType","pop","WebinyError","upload","params","settings","fileManager","getSettings","file","fileData","createFile","meta","private","Boolean","hideInFileManager","tags","Array","isArray","uploadFiles","promises","item","files","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/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\n if (!storagePlugin) {\n throw new WebinyError(\n `Missing plugin of type \"${storagePluginType}\".`,\n \"STORAGE_PLUGIN_ERROR\"\n );\n }\n this.storagePlugin = storagePlugin;\n this.context = context;\n }\n\n async upload(params: FileStorageUploadParams): Promise<Result> {\n const settings = await this.context.fileManager.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n // 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.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.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.createFilesInBatch(filesData);\n }\n\n async delete(params: FileStorageDeleteParams) {\n const { id, key } = params;\n const { fileManager } = this.context;\n // Delete file from cloud storage.\n await this.storagePlugin.delete({\n key\n });\n\n // Delete file from the DB.\n return await fileManager.deleteFile(id);\n }\n}\n"],"mappings":";;;;;;;;;AACA;AAKA,MAAMA,iBAAiB,GAAG,0BAA0B;AAuB7C,MAAMC,WAAW,CAAC;EAIrBC,WAAW,CAAC;IAAEC;EAA2B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KAAK,MAAMC,IAAI,IAAIhB,MAAM,CAACiB,KAAK,EAAE;MAC7BF,QAAQ,CAACG,IAAI,CACT,IAAI,CAACxB,aAAa,CAACK,MAAM,6DAClBiB,IAAI;QACPf;MAAQ,GACV,CACL;IACL;IACA;IACA,MAAMkB,mBAAmB,GAAG,MAAMC,OAAO,CAACC,GAAG,CAACN,QAAQ,CAAC;IAEvD,MAAMO,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,CAACuB,kBAAkB,CAACH,SAAS,CAAC;EACpD;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;;IAEF;IACA,OAAO,MAAM1B,WAAW,CAAC2B,UAAU,CAACF,EAAE,CAAC;EAC3C;AACJ;AAAC"}
@@ -0,0 +1,33 @@
1
+ export interface File {
2
+ id: string;
3
+ key: string;
4
+ size: number;
5
+ type: string;
6
+ name: string;
7
+ meta: Record<string, any>;
8
+ tags: string[];
9
+ aliases: string[];
10
+ createdOn: string;
11
+ createdBy: CreatedBy;
12
+ /**
13
+ * Added with new storage operations refactoring.
14
+ */
15
+ tenant: string;
16
+ locale: string;
17
+ webinyVersion: string;
18
+ /**
19
+ * User can add new fields to the File object so we must allow it in the types.
20
+ */
21
+ [key: string]: any;
22
+ }
23
+ export interface FileAlias {
24
+ tenant: string;
25
+ locale: string;
26
+ fileId: string;
27
+ alias: string;
28
+ }
29
+ export interface CreatedBy {
30
+ id: string;
31
+ displayName: string | null;
32
+ type: string;
33
+ }