@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,18 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _getEnvironment = _interopRequireDefault(require("./getEnvironment"));
11
-
12
9
  /**
13
10
  * Returns website's Bucket and file's Key values.
14
- * @param filename
15
- * @returns {{Bucket: string, Key: string}}
16
11
  */
17
12
  var _default = filename => {
18
13
  const {
@@ -23,5 +18,4 @@ var _default = filename => {
23
18
  Key: `${filename}`
24
19
  };
25
20
  };
26
-
27
21
  exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["filename","bucket","Bucket","getEnvironment","Key"],"sources":["getObjectParams.ts"],"sourcesContent":["import getEnvironment from \"./getEnvironment\";\n\nexport interface ObjectParamsResponse {\n Bucket: string;\n Key: string;\n}\n/**\n * Returns website's Bucket and file's Key values.\n */\nexport default (filename: string): ObjectParamsResponse => {\n const { bucket: Bucket } = getEnvironment();\n\n return {\n Bucket,\n Key: `${filename}`\n };\n};\n"],"mappings":";;;;;;;AAAA;AAMA;AACA;AACA;AAFA,eAGgBA,QAAgB,IAA2B;EACvD,MAAM;IAAEC,MAAM,EAAEC;EAAO,CAAC,GAAG,IAAAC,uBAAc,GAAE;EAE3C,OAAO;IACHD,MAAM;IACNE,GAAG,EAAG,GAAEJ,QAAS;EACrB,CAAC;AACL,CAAC;AAAA"}
@@ -1,3 +1,2 @@
1
1
  export { default as getEnvironment } from "./getEnvironment";
2
- export { default as createHandler } from "./createHandler";
3
2
  export { default as getObjectParams } from "./getObjectParams";
@@ -1,16 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- Object.defineProperty(exports, "createHandler", {
9
- enumerable: true,
10
- get: function () {
11
- return _createHandler.default;
12
- }
13
- });
14
7
  Object.defineProperty(exports, "getEnvironment", {
15
8
  enumerable: true,
16
9
  get: function () {
@@ -23,9 +16,5 @@ Object.defineProperty(exports, "getObjectParams", {
23
16
  return _getObjectParams.default;
24
17
  }
25
18
  });
26
-
27
19
  var _getEnvironment = _interopRequireDefault(require("./getEnvironment"));
28
-
29
- var _createHandler = _interopRequireDefault(require("./createHandler"));
30
-
31
20
  var _getObjectParams = _interopRequireDefault(require("./getObjectParams"));
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as getEnvironment } from \"./getEnvironment\";\nexport { default as getObjectParams } from \"./getObjectParams\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AACA"}
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { ContextPlugin } from "@webiny/api";
2
+ import { FileManagerConfig } from "./createFileManager";
3
+ import { FileManagerContext } from "./types";
4
+ export * from "./plugins";
5
+ export declare const createFileManagerContext: (config: Pick<FileManagerConfig, "storageOperations">) => ContextPlugin<FileManagerContext>;
6
+ export declare const createFileManagerGraphQL: () => import("@webiny/handler-graphql").GraphQLSchemaPlugin<FileManagerContext>;
package/index.js ADDED
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ var _exportNames = {
8
+ createFileManagerContext: true,
9
+ createFileManagerGraphQL: true
10
+ };
11
+ exports.createFileManagerGraphQL = exports.createFileManagerContext = void 0;
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+ var _api = require("@webiny/api");
14
+ var _createFileManager = require("./createFileManager");
15
+ var _graphql = require("./graphql");
16
+ var _FileStorage = require("./storage/FileStorage");
17
+ var _plugins = require("./plugins");
18
+ Object.keys(_plugins).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
21
+ if (key in exports && exports[key] === _plugins[key]) return;
22
+ Object.defineProperty(exports, key, {
23
+ enumerable: true,
24
+ get: function () {
25
+ return _plugins[key];
26
+ }
27
+ });
28
+ });
29
+ const createFileManagerContext = config => {
30
+ return new _api.ContextPlugin(async context => {
31
+ const getLocaleCode = () => {
32
+ const locale = context.i18n.getContentLocale();
33
+ if (!locale) {
34
+ throw new _error.default("Missing locale on context.i18n locale in File Manager API.", "LOCALE_ERROR");
35
+ }
36
+ return locale.code;
37
+ };
38
+ const getIdentity = () => {
39
+ return context.security.getIdentity();
40
+ };
41
+ const getTenantId = () => {
42
+ return context.tenancy.getCurrentTenant().id;
43
+ };
44
+ const getPermission = async name => {
45
+ await context.i18n.checkI18NContentPermission();
46
+ return context.security.getPermission(name);
47
+ };
48
+ if (config.storageOperations.beforeInit) {
49
+ await config.storageOperations.beforeInit(context);
50
+ }
51
+ context.fileManager = (0, _createFileManager.createFileManager)({
52
+ storageOperations: config.storageOperations,
53
+ getTenantId,
54
+ getLocaleCode,
55
+ getIdentity,
56
+ getPermission,
57
+ storage: new _FileStorage.FileStorage({
58
+ context
59
+ }),
60
+ WEBINY_VERSION: context.WEBINY_VERSION
61
+ });
62
+ });
63
+ };
64
+ exports.createFileManagerContext = createFileManagerContext;
65
+ const createFileManagerGraphQL = () => {
66
+ return (0, _graphql.createGraphQLSchemaPlugin)();
67
+ };
68
+ exports.createFileManagerGraphQL = createFileManagerGraphQL;
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFileManagerContext","config","ContextPlugin","context","getLocaleCode","locale","i18n","getContentLocale","WebinyError","code","getIdentity","security","getTenantId","tenancy","getCurrentTenant","id","getPermission","name","checkI18NContentPermission","storageOperations","beforeInit","fileManager","createFileManager","storage","FileStorage","WEBINY_VERSION","createFileManagerGraphQL","createGraphQLSchemaPlugin"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { SecurityPermission } from \"@webiny/api-security/types\";\nimport { FileManagerConfig, createFileManager } from \"~/createFileManager\";\nimport { FileManagerContext } from \"~/types\";\nimport { createGraphQLSchemaPlugin } from \"./graphql\";\nimport { FileStorage } from \"~/storage/FileStorage\";\n\nexport * from \"./plugins\";\n\nexport const createFileManagerContext = (config: Pick<FileManagerConfig, \"storageOperations\">) => {\n return new ContextPlugin<FileManagerContext>(async context => {\n const getLocaleCode = () => {\n const locale = context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing locale on context.i18n locale in File Manager API.\",\n \"LOCALE_ERROR\"\n );\n }\n return locale.code;\n };\n\n const getIdentity = () => {\n return context.security.getIdentity();\n };\n\n const getTenantId = () => {\n return context.tenancy.getCurrentTenant().id;\n };\n\n const getPermission = async <T extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<T | null> => {\n await context.i18n.checkI18NContentPermission();\n\n return context.security.getPermission(name);\n };\n\n if (config.storageOperations.beforeInit) {\n await config.storageOperations.beforeInit(context);\n }\n\n context.fileManager = createFileManager({\n storageOperations: config.storageOperations,\n getTenantId,\n getLocaleCode,\n getIdentity,\n getPermission,\n storage: new FileStorage({\n context\n }),\n WEBINY_VERSION: context.WEBINY_VERSION\n });\n });\n};\n\nexport const createFileManagerGraphQL = () => {\n return createGraphQLSchemaPlugin();\n};\n"],"mappings":";;;;;;;;;;;AAAA;AACA;AAEA;AAEA;AACA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAEO,MAAMA,wBAAwB,GAAIC,MAAoD,IAAK;EAC9F,OAAO,IAAIC,kBAAa,CAAqB,MAAMC,OAAO,IAAI;IAC1D,MAAMC,aAAa,GAAG,MAAM;MACxB,MAAMC,MAAM,GAAGF,OAAO,CAACG,IAAI,CAACC,gBAAgB,EAAE;MAC9C,IAAI,CAACF,MAAM,EAAE;QACT,MAAM,IAAIG,cAAW,CACjB,4DAA4D,EAC5D,cAAc,CACjB;MACL;MACA,OAAOH,MAAM,CAACI,IAAI;IACtB,CAAC;IAED,MAAMC,WAAW,GAAG,MAAM;MACtB,OAAOP,OAAO,CAACQ,QAAQ,CAACD,WAAW,EAAE;IACzC,CAAC;IAED,MAAME,WAAW,GAAG,MAAM;MACtB,OAAOT,OAAO,CAACU,OAAO,CAACC,gBAAgB,EAAE,CAACC,EAAE;IAChD,CAAC;IAED,MAAMC,aAAa,GAAG,MAClBC,IAAY,IACQ;MACpB,MAAMd,OAAO,CAACG,IAAI,CAACY,0BAA0B,EAAE;MAE/C,OAAOf,OAAO,CAACQ,QAAQ,CAACK,aAAa,CAACC,IAAI,CAAC;IAC/C,CAAC;IAED,IAAIhB,MAAM,CAACkB,iBAAiB,CAACC,UAAU,EAAE;MACrC,MAAMnB,MAAM,CAACkB,iBAAiB,CAACC,UAAU,CAACjB,OAAO,CAAC;IACtD;IAEAA,OAAO,CAACkB,WAAW,GAAG,IAAAC,oCAAiB,EAAC;MACpCH,iBAAiB,EAAElB,MAAM,CAACkB,iBAAiB;MAC3CP,WAAW;MACXR,aAAa;MACbM,WAAW;MACXM,aAAa;MACbO,OAAO,EAAE,IAAIC,wBAAW,CAAC;QACrBrB;MACJ,CAAC,CAAC;MACFsB,cAAc,EAAEtB,OAAO,CAACsB;IAC5B,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC;AAEK,MAAMC,wBAAwB,GAAG,MAAM;EAC1C,OAAO,IAAAC,kCAAyB,GAAE;AACtC,CAAC;AAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-file-manager",
3
- "version": "0.0.0-mt-2",
3
+ "version": "0.0.0-unstable.13771d80a8",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "fm:base"
@@ -18,39 +18,38 @@
18
18
  ],
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@babel/runtime": "7.15.4",
21
+ "@babel/runtime": "7.20.13",
22
22
  "@commodo/fields": "1.1.2-beta.20",
23
- "@webiny/api-i18n-content": "0.0.0-mt-2",
24
- "@webiny/api-security": "0.0.0-mt-2",
25
- "@webiny/api-tenancy": "0.0.0-mt-2",
26
- "@webiny/api-upgrade": "0.0.0-mt-2",
27
- "@webiny/error": "0.0.0-mt-2",
28
- "@webiny/handler": "0.0.0-mt-2",
29
- "@webiny/handler-client": "0.0.0-mt-2",
30
- "@webiny/handler-graphql": "0.0.0-mt-2",
31
- "@webiny/plugins": "0.0.0-mt-2",
32
- "@webiny/project-utils": "0.0.0-mt-2",
33
- "@webiny/validation": "0.0.0-mt-2",
34
- "aws-sdk": "2.1026.0",
35
- "commodo-fields-object": "1.0.6",
36
- "mdbid": "1.0.0",
37
- "object-hash": "1.3.1",
38
- "sanitize-filename": "1.6.3"
23
+ "@webiny/api": "0.0.0-unstable.13771d80a8",
24
+ "@webiny/api-security": "0.0.0-unstable.13771d80a8",
25
+ "@webiny/api-tenancy": "0.0.0-unstable.13771d80a8",
26
+ "@webiny/error": "0.0.0-unstable.13771d80a8",
27
+ "@webiny/handler": "0.0.0-unstable.13771d80a8",
28
+ "@webiny/handler-aws": "0.0.0-unstable.13771d80a8",
29
+ "@webiny/handler-client": "0.0.0-unstable.13771d80a8",
30
+ "@webiny/handler-graphql": "0.0.0-unstable.13771d80a8",
31
+ "@webiny/plugins": "0.0.0-unstable.13771d80a8",
32
+ "@webiny/project-utils": "0.0.0-unstable.13771d80a8",
33
+ "@webiny/pubsub": "0.0.0-unstable.13771d80a8",
34
+ "@webiny/validation": "0.0.0-unstable.13771d80a8",
35
+ "aws-sdk": "2.1310.0",
36
+ "object-hash": "2.2.0"
39
37
  },
40
38
  "devDependencies": {
41
- "@babel/cli": "^7.5.5",
42
- "@babel/core": "^7.5.5",
43
- "@babel/plugin-proposal-object-rest-spread": "^7.5.5",
44
- "@babel/plugin-transform-runtime": "^7.5.5",
45
- "@babel/preset-env": "^7.5.5",
46
- "@babel/preset-typescript": "^7.0.0",
47
- "@webiny/api-i18n": "^0.0.0-mt-2",
48
- "@webiny/api-i18n-ddb": "^0.0.0-mt-2",
49
- "@webiny/cli": "^0.0.0-mt-2",
50
- "jest": "^26.6.3",
39
+ "@babel/cli": "^7.19.3",
40
+ "@babel/core": "^7.19.3",
41
+ "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
42
+ "@babel/plugin-transform-runtime": "^7.16.4",
43
+ "@babel/preset-env": "^7.19.4",
44
+ "@babel/preset-typescript": "^7.18.6",
45
+ "@webiny/api-i18n": "^0.0.0-unstable.13771d80a8",
46
+ "@webiny/api-i18n-ddb": "^0.0.0-unstable.13771d80a8",
47
+ "@webiny/cli": "^0.0.0-unstable.13771d80a8",
48
+ "jest": "^28.1.0",
49
+ "mdbid": "^1.0.0",
51
50
  "rimraf": "^3.0.2",
52
51
  "ttypescript": "^1.5.12",
53
- "typescript": "^4.1.3"
52
+ "typescript": "4.7.4"
54
53
  },
55
54
  "publishConfig": {
56
55
  "access": "public",
@@ -71,5 +70,5 @@
71
70
  ]
72
71
  }
73
72
  },
74
- "gitHead": "3c0dcfb3c22c9f83107fdb97b25014cd03d9db7d"
73
+ "gitHead": "13771d80a8ae3195c9ea1485bf8c01f6667a129e"
75
74
  }
@@ -0,0 +1,21 @@
1
+ /// <reference types="node" />
2
+ import { Plugin } from "@webiny/plugins";
3
+ import { FileManagerSettings } from "../types";
4
+ export interface FilePhysicalStoragePluginParams<U extends FilePhysicalStoragePluginUploadParams, D extends FilePhysicalStoragePluginDeleteParams> {
5
+ upload: (args: U) => Promise<any>;
6
+ delete: (args: D) => Promise<void>;
7
+ }
8
+ export interface FilePhysicalStoragePluginUploadParams {
9
+ settings: FileManagerSettings;
10
+ buffer: Buffer;
11
+ }
12
+ export interface FilePhysicalStoragePluginDeleteParams {
13
+ key: string;
14
+ }
15
+ export declare class FilePhysicalStoragePlugin<U extends FilePhysicalStoragePluginUploadParams = FilePhysicalStoragePluginUploadParams, D extends FilePhysicalStoragePluginDeleteParams = FilePhysicalStoragePluginDeleteParams> extends Plugin {
16
+ static readonly type: string;
17
+ private readonly _params;
18
+ constructor(params: FilePhysicalStoragePluginParams<U, D>);
19
+ upload(params: U): Promise<any>;
20
+ delete(params: D): Promise<any>;
21
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.FilePhysicalStoragePlugin = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _plugins = require("@webiny/plugins");
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+ class FilePhysicalStoragePlugin extends _plugins.Plugin {
12
+ constructor(params) {
13
+ super();
14
+ (0, _defineProperty2.default)(this, "_params", void 0);
15
+ this._params = params;
16
+ }
17
+ async upload(params) {
18
+ if (!this._params.upload) {
19
+ throw new _error.default(`You must define the "upload" method of this plugin.`, "UPLOAD_METHOD_ERROR");
20
+ }
21
+ return this._params.upload(params);
22
+ }
23
+ async delete(params) {
24
+ if (!this._params.delete) {
25
+ throw new _error.default(`You must define the "delete" method of this plugin.`, "DELETE_METHOD_ERROR");
26
+ }
27
+ return this._params.delete(params);
28
+ }
29
+ }
30
+ exports.FilePhysicalStoragePlugin = FilePhysicalStoragePlugin;
31
+ (0, _defineProperty2.default)(FilePhysicalStoragePlugin, "type", "api-file-manager-storage");
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FilePhysicalStoragePlugin","Plugin","constructor","params","_params","upload","WebinyError","delete"],"sources":["FilePhysicalStoragePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { FileManagerSettings } from \"~/types\";\n\nexport interface FilePhysicalStoragePluginParams<\n U extends FilePhysicalStoragePluginUploadParams,\n D extends FilePhysicalStoragePluginDeleteParams\n> {\n upload: (args: U) => Promise<any>;\n delete: (args: D) => Promise<void>;\n}\n\nexport interface FilePhysicalStoragePluginUploadParams {\n settings: FileManagerSettings;\n buffer: Buffer;\n}\n\nexport interface FilePhysicalStoragePluginDeleteParams {\n key: string;\n}\n\nexport class FilePhysicalStoragePlugin<\n U extends FilePhysicalStoragePluginUploadParams = FilePhysicalStoragePluginUploadParams,\n D extends FilePhysicalStoragePluginDeleteParams = FilePhysicalStoragePluginDeleteParams\n> extends Plugin {\n public static override readonly type: string = \"api-file-manager-storage\";\n private readonly _params: FilePhysicalStoragePluginParams<U, D>;\n\n public constructor(params: FilePhysicalStoragePluginParams<U, D>) {\n super();\n this._params = params;\n }\n\n public async upload(params: U): Promise<any> {\n if (!this._params.upload) {\n throw new WebinyError(\n `You must define the \"upload\" method of this plugin.`,\n \"UPLOAD_METHOD_ERROR\"\n );\n }\n return this._params.upload(params);\n }\n\n public async delete(params: D): Promise<any> {\n if (!this._params.delete) {\n throw new WebinyError(\n `You must define the \"delete\" method of this plugin.`,\n \"DELETE_METHOD_ERROR\"\n );\n }\n return this._params.delete(params);\n }\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AAoBO,MAAMA,yBAAyB,SAG5BC,eAAM,CAAC;EAINC,WAAW,CAACC,MAA6C,EAAE;IAC9D,KAAK,EAAE;IAAC;IACR,IAAI,CAACC,OAAO,GAAGD,MAAM;EACzB;EAEA,MAAaE,MAAM,CAACF,MAAS,EAAgB;IACzC,IAAI,CAAC,IAAI,CAACC,OAAO,CAACC,MAAM,EAAE;MACtB,MAAM,IAAIC,cAAW,CAChB,qDAAoD,EACrD,qBAAqB,CACxB;IACL;IACA,OAAO,IAAI,CAACF,OAAO,CAACC,MAAM,CAACF,MAAM,CAAC;EACtC;EAEA,MAAaI,MAAM,CAACJ,MAAS,EAAgB;IACzC,IAAI,CAAC,IAAI,CAACC,OAAO,CAACG,MAAM,EAAE;MACtB,MAAM,IAAID,cAAW,CAChB,qDAAoD,EACrD,qBAAqB,CACxB;IACL;IACA,OAAO,IAAI,CAACF,OAAO,CAACG,MAAM,CAACJ,MAAM,CAAC;EACtC;AACJ;AAAC;AAAA,8BA/BYH,yBAAyB,UAIa,0BAA0B"}
@@ -0,0 +1,34 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ import { File } from "../types";
3
+ export interface FileStorageTransformPluginToParams {
4
+ /**
5
+ * File that is being sent to the storage operations method.
6
+ */
7
+ file: File & Record<string, any>;
8
+ }
9
+ export interface FileStorageTransformPluginFromParams {
10
+ /**
11
+ * File that was fetched from the storage operations method.
12
+ */
13
+ file: File & Record<string, any>;
14
+ }
15
+ export interface FileStorageTransformPluginParams {
16
+ toStorage?: (params: FileStorageTransformPluginToParams) => Promise<File & Record<string, any>>;
17
+ fromStorage?: (params: FileStorageTransformPluginFromParams) => Promise<File & Record<string, any>>;
18
+ }
19
+ export declare class FileStorageTransformPlugin extends Plugin {
20
+ static readonly type: string;
21
+ private readonly _params;
22
+ constructor(params: FileStorageTransformPluginParams);
23
+ /**
24
+ * Transform the file value into something that can be stored.
25
+ * Be aware that you must return the whole file object.
26
+ */
27
+ toStorage(params: FileStorageTransformPluginToParams): Promise<File & Record<string, any>>;
28
+ /**
29
+ * Transform the file value from the storage type to one required by our system.
30
+ * Be aware that you must return the whole file object.
31
+ * This method MUST reverse what ever toStorage method changed on the file object.
32
+ */
33
+ fromStorage(params: FileStorageTransformPluginFromParams): Promise<File & Record<string, any>>;
34
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.FileStorageTransformPlugin = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _plugins = require("@webiny/plugins");
10
+ class FileStorageTransformPlugin extends _plugins.Plugin {
11
+ constructor(params) {
12
+ super();
13
+ (0, _defineProperty2.default)(this, "_params", void 0);
14
+ this._params = params;
15
+ }
16
+
17
+ /**
18
+ * Transform the file value into something that can be stored.
19
+ * Be aware that you must return the whole file object.
20
+ */
21
+ async toStorage(params) {
22
+ if (!this._params.toStorage) {
23
+ return params.file;
24
+ }
25
+ return this._params.toStorage(params);
26
+ }
27
+ /**
28
+ * Transform the file value from the storage type to one required by our system.
29
+ * Be aware that you must return the whole file object.
30
+ * This method MUST reverse what ever toStorage method changed on the file object.
31
+ */
32
+ async fromStorage(params) {
33
+ if (!this._params.fromStorage) {
34
+ return params.file;
35
+ }
36
+ return this._params.fromStorage(params);
37
+ }
38
+ }
39
+ exports.FileStorageTransformPlugin = FileStorageTransformPlugin;
40
+ (0, _defineProperty2.default)(FileStorageTransformPlugin, "type", "fm.files.storage.transform");
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FileStorageTransformPlugin","Plugin","constructor","params","_params","toStorage","file","fromStorage"],"sources":["FileStorageTransformPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { File } from \"~/types\";\n\nexport interface FileStorageTransformPluginToParams {\n /**\n * File that is being sent to the storage operations method.\n */\n file: File & Record<string, any>;\n}\n\nexport interface FileStorageTransformPluginFromParams {\n /**\n * File that was fetched from the storage operations method.\n */\n file: File & Record<string, any>;\n}\n\nexport interface FileStorageTransformPluginParams {\n toStorage?: (params: FileStorageTransformPluginToParams) => Promise<File & Record<string, any>>;\n fromStorage?: (\n params: FileStorageTransformPluginFromParams\n ) => Promise<File & Record<string, any>>;\n}\n\nexport class FileStorageTransformPlugin extends Plugin {\n public static override readonly type: string = \"fm.files.storage.transform\";\n private readonly _params: FileStorageTransformPluginParams;\n\n public constructor(params: FileStorageTransformPluginParams) {\n super();\n\n this._params = params;\n }\n\n /**\n * Transform the file value into something that can be stored.\n * Be aware that you must return the whole file object.\n */\n public async toStorage(\n params: FileStorageTransformPluginToParams\n ): Promise<File & Record<string, any>> {\n if (!this._params.toStorage) {\n return params.file;\n }\n return this._params.toStorage(params);\n }\n /**\n * Transform the file value from the storage type to one required by our system.\n * Be aware that you must return the whole file object.\n * This method MUST reverse what ever toStorage method changed on the file object.\n */\n public async fromStorage(\n params: FileStorageTransformPluginFromParams\n ): Promise<File & Record<string, any>> {\n if (!this._params.fromStorage) {\n return params.file;\n }\n return this._params.fromStorage(params);\n }\n}\n"],"mappings":";;;;;;;;AAAA;AAwBO,MAAMA,0BAA0B,SAASC,eAAM,CAAC;EAI5CC,WAAW,CAACC,MAAwC,EAAE;IACzD,KAAK,EAAE;IAAC;IAER,IAAI,CAACC,OAAO,GAAGD,MAAM;EACzB;;EAEA;AACJ;AACA;AACA;EACI,MAAaE,SAAS,CAClBF,MAA0C,EACP;IACnC,IAAI,CAAC,IAAI,CAACC,OAAO,CAACC,SAAS,EAAE;MACzB,OAAOF,MAAM,CAACG,IAAI;IACtB;IACA,OAAO,IAAI,CAACF,OAAO,CAACC,SAAS,CAACF,MAAM,CAAC;EACzC;EACA;AACJ;AACA;AACA;AACA;EACI,MAAaI,WAAW,CACpBJ,MAA4C,EACT;IACnC,IAAI,CAAC,IAAI,CAACC,OAAO,CAACG,WAAW,EAAE;MAC3B,OAAOJ,MAAM,CAACG,IAAI;IACtB;IACA,OAAO,IAAI,CAACF,OAAO,CAACG,WAAW,CAACJ,MAAM,CAAC;EAC3C;AACJ;AAAC;AAAA,8BAnCYH,0BAA0B,UACY,4BAA4B"}
@@ -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":["FilePlugin","beforeCreate","data","FileModel","createFileModel","fileData","populate","validate","beforeUpdate","updatedFileData","beforeBatchCreate","input","fileInstance"],"sources":["validation.ts"],"sourcesContent":["import { FilePlugin } from \"~/plugins/definitions/FilePlugin\";\nimport createFileModel from \"~/plugins/crud/utils/createFileModel\";\n\nexport default (): FilePlugin[] => [\n new FilePlugin({\n beforeCreate: async ({ data }) => {\n const FileModel = createFileModel();\n const fileData = new FileModel().populate(data);\n await fileData.validate();\n },\n beforeUpdate: async ({ data }) => {\n const FileModel = createFileModel(false);\n const updatedFileData = new FileModel().populate(data);\n await updatedFileData.validate();\n },\n beforeBatchCreate: async ({ data }) => {\n const FileModel = createFileModel();\n for (const input of data) {\n const fileInstance = new FileModel().populate(input);\n await fileInstance.validate();\n }\n }\n })\n];\n"],"mappings":";;;;;;;;;AAAA;;AACA;;eAEe,MAAoB,CAC/B,IAAIA,sBAAJ,CAAe;EACXC,YAAY,EAAE,OAAO;IAAEC;EAAF,CAAP,KAAoB;IAC9B,MAAMC,SAAS,GAAG,IAAAC,wBAAA,GAAlB;IACA,MAAMC,QAAQ,GAAG,IAAIF,SAAJ,GAAgBG,QAAhB,CAAyBJ,IAAzB,CAAjB;IACA,MAAMG,QAAQ,CAACE,QAAT,EAAN;EACH,CALU;EAMXC,YAAY,EAAE,OAAO;IAAEN;EAAF,CAAP,KAAoB;IAC9B,MAAMC,SAAS,GAAG,IAAAC,wBAAA,EAAgB,KAAhB,CAAlB;IACA,MAAMK,eAAe,GAAG,IAAIN,SAAJ,GAAgBG,QAAhB,CAAyBJ,IAAzB,CAAxB;IACA,MAAMO,eAAe,CAACF,QAAhB,EAAN;EACH,CAVU;EAWXG,iBAAiB,EAAE,OAAO;IAAER;EAAF,CAAP,KAAoB;IACnC,MAAMC,SAAS,GAAG,IAAAC,wBAAA,GAAlB;;IACA,KAAK,MAAMO,KAAX,IAAoBT,IAApB,EAA0B;MACtB,MAAMU,YAAY,GAAG,IAAIT,SAAJ,GAAgBG,QAAhB,CAAyBK,KAAzB,CAArB;MACA,MAAMC,YAAY,CAACL,QAAb,EAAN;IACH;EACJ;AAjBU,CAAf,CAD+B,C"}
@@ -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 filesContextCrudPlugin: ContextPlugin<FileManagerContext>;
4
4
  export default filesContextCrudPlugin;
@@ -1,13 +1,13 @@
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.default = void 0;
9
9
 
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
11
 
12
12
  var _mdbid = _interopRequireDefault(require("mdbid"));
13
13
 
@@ -15,22 +15,22 @@ var _handlerGraphql = require("@webiny/handler-graphql");
15
15
 
16
16
  var _apiSecurity = require("@webiny/api-security");
17
17
 
18
- var _error = _interopRequireDefault(require("@webiny/error"));
19
-
20
18
  var _checkBasePermissions = _interopRequireDefault(require("./utils/checkBasePermissions"));
21
19
 
22
- var _ContextPlugin = require("@webiny/handler/plugins/ContextPlugin");
20
+ var _api = require("@webiny/api");
23
21
 
24
22
  var _FilePlugin = require("../definitions/FilePlugin");
25
23
 
26
24
  var _FilesStorageOperationsProviderPlugin = require("../definitions/FilesStorageOperationsProviderPlugin");
27
25
 
28
- var _lifecycleEvents = require("./utils/lifecycleEvents");
29
-
30
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
26
+ var _error = _interopRequireDefault(require("@webiny/error"));
31
27
 
32
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
28
+ var _lifecycleEvents = require("./utils/lifecycleEvents");
33
29
 
30
+ /**
31
+ * Package mdbid does not have types.
32
+ */
33
+ // @ts-ignore
34
34
  const BATCH_CREATE_MAX_FILES = 20;
35
35
  /**
36
36
  * If permission is limited to "own" files only, check that current identity owns the file.
@@ -47,18 +47,24 @@ const checkOwnership = (file, permission, context) => {
47
47
  };
48
48
 
49
49
  const getLocaleCode = context => {
50
- if (!context.i18nContent) {
51
- throw new _error.default("Missing i18nContent on the FileManagerContext.", "MISSING_I18N_CONTENT");
52
- } else if (!context.i18nContent.locale) {
53
- throw new _error.default("Missing i18nContent.locale on the FileManagerContext.", "MISSING_I18N_CONTENT_LOCALE");
54
- } else if (!context.i18nContent.locale.code) {
55
- throw new _error.default("Missing i18nContent.locale.code on the FileManagerContext.", "MISSING_I18N_CONTENT_LOCALE_CODE");
50
+ if (!context.i18n) {
51
+ throw new _error.default("Missing i18n on the FileManagerContext.", "MISSING_I18N");
52
+ }
53
+
54
+ const locale = context.i18n.getContentLocale();
55
+
56
+ if (!locale) {
57
+ throw new _error.default("Missing content locale on the FileManagerContext.", "MISSING_I18N_CONTENT_LOCALE");
58
+ }
59
+
60
+ if (!locale.code) {
61
+ throw new _error.default("Missing content locale code on the FileManagerContext.", "MISSING_I18N_CONTENT_LOCALE_CODE");
56
62
  }
57
63
 
58
- return context.i18nContent.locale.code;
64
+ return locale.code;
59
65
  };
60
66
 
61
- const filesContextCrudPlugin = new _ContextPlugin.ContextPlugin(async context => {
67
+ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
62
68
  const pluginType = _FilesStorageOperationsProviderPlugin.FilesStorageOperationsProviderPlugin.type;
63
69
  const providerPlugin = context.plugins.byType(pluginType).find(() => true);
64
70
 
@@ -105,10 +111,10 @@ const filesContextCrudPlugin = new _ContextPlugin.ContextPlugin(async context =>
105
111
  const identity = context.security.getIdentity();
106
112
  const tenant = context.tenancy.getCurrentTenant();
107
113
  const id = (0, _mdbid.default)();
108
-
109
- const file = _objectSpread(_objectSpread({}, input), {}, {
114
+ const file = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, input), {}, {
115
+ tags: Array.isArray(input.tags) ? input.tags : [],
110
116
  id,
111
- meta: _objectSpread({
117
+ meta: (0, _objectSpread2.default)({
112
118
  private: false
113
119
  }, input.meta || {}),
114
120
  tenant: tenant.id,
@@ -139,7 +145,7 @@ const filesContextCrudPlugin = new _ContextPlugin.ContextPlugin(async context =>
139
145
  });
140
146
  return result;
141
147
  } catch (ex) {
142
- throw new _error.default(ex.message || "Could not create a file.", ex.code || "CREATE_FILE_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
148
+ throw new _error.default(ex.message || "Could not create a file.", ex.code || "CREATE_FILE_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
143
149
  file
144
150
  }));
145
151
  }
@@ -162,8 +168,8 @@ const filesContextCrudPlugin = new _ContextPlugin.ContextPlugin(async context =>
162
168
  }
163
169
 
164
170
  checkOwnership(original, permission, context);
165
-
166
- const file = _objectSpread(_objectSpread(_objectSpread({}, original), input), {}, {
171
+ const file = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), input), {}, {
172
+ tags: Array.isArray(input.tags) ? input.tags : Array.isArray(original.tags) ? original.tags : [],
167
173
  id: original.id,
168
174
  webinyVersion: context.WEBINY_VERSION
169
175
  });
@@ -188,7 +194,7 @@ const filesContextCrudPlugin = new _ContextPlugin.ContextPlugin(async context =>
188
194
  });
189
195
  return result;
190
196
  } catch (ex) {
191
- throw new _error.default(ex.message || "Could not update a file.", ex.code || "UPDATE_FILE_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
197
+ throw new _error.default(ex.message || "Could not update a file.", ex.code || "UPDATE_FILE_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
192
198
  original,
193
199
  file
194
200
  }));
@@ -228,7 +234,7 @@ const filesContextCrudPlugin = new _ContextPlugin.ContextPlugin(async context =>
228
234
  file
229
235
  });
230
236
  } catch (ex) {
231
- throw new _error.default(ex.message || "Could not delete a file.", ex.code || "DELETE_FILE_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
237
+ throw new _error.default(ex.message || "Could not delete a file.", ex.code || "DELETE_FILE_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
232
238
  id,
233
239
  file
234
240
  }));
@@ -261,8 +267,9 @@ const filesContextCrudPlugin = new _ContextPlugin.ContextPlugin(async context =>
261
267
  type: identity.type
262
268
  };
263
269
  const files = inputs.map(input => {
264
- return _objectSpread(_objectSpread({}, input), {}, {
265
- meta: _objectSpread({
270
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, input), {}, {
271
+ tags: Array.isArray(input.tags) ? input.tags : [],
272
+ meta: (0, _objectSpread2.default)({
266
273
  private: false
267
274
  }, input.meta || {}),
268
275
  id: (0, _mdbid.default)(),
@@ -291,7 +298,7 @@ const filesContextCrudPlugin = new _ContextPlugin.ContextPlugin(async context =>
291
298
  });
292
299
  return results;
293
300
  } catch (ex) {
294
- throw new _error.default(ex.message || "Could not create a batch of files.", ex.code || "CREATE_FILES_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
301
+ throw new _error.default(ex.message || "Could not create a batch of files.", ex.code || "CREATE_FILES_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
295
302
  files
296
303
  }));
297
304
  }
@@ -311,17 +318,15 @@ const filesContextCrudPlugin = new _ContextPlugin.ContextPlugin(async context =>
311
318
  where: initialWhere,
312
319
  sort: initialSort
313
320
  } = params;
314
-
315
- const where = _objectSpread(_objectSpread({}, initialWhere), {}, {
321
+ const where = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, initialWhere), {}, {
316
322
  private: false,
317
- locale: context.i18nContent.getLocale().code,
323
+ locale: getLocaleCode(context),
318
324
  tenant: context.tenancy.getCurrentTenant().id
319
325
  });
320
326
  /**
321
327
  * Always override the createdBy received from the user, if any.
322
328
  */
323
329
 
324
-
325
330
  if (permission.own === true) {
326
331
  const identity = context.security.getIdentity();
327
332
  where.createdBy = identity.id;
@@ -375,7 +380,7 @@ const filesContextCrudPlugin = new _ContextPlugin.ContextPlugin(async context =>
375
380
  sort
376
381
  });
377
382
  } catch (ex) {
378
- throw new _error.default(ex.message || "Could not list files by given parameters.", ex.code || "FILE_TAG_SEARCH_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
383
+ throw new _error.default(ex.message || "Could not list files by given parameters.", ex.code || "FILE_TAG_SEARCH_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
379
384
  where,
380
385
  after,
381
386
  limit,
@@ -385,17 +390,15 @@ const filesContextCrudPlugin = new _ContextPlugin.ContextPlugin(async context =>
385
390
  },
386
391
 
387
392
  async listTags({
393
+ where: initialWhere,
388
394
  after,
389
395
  limit
390
396
  }) {
391
397
  await (0, _checkBasePermissions.default)(context);
392
- const {
393
- i18nContent
394
- } = context;
395
- const where = {
398
+ const where = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, initialWhere), {}, {
396
399
  tenant: context.tenancy.getCurrentTenant().id,
397
- locale: i18nContent.locale.code
398
- };
400
+ locale: getLocaleCode(context)
401
+ });
399
402
  const params = {
400
403
  where,
401
404
  limit: limit || 100000,
@@ -403,18 +406,19 @@ const filesContextCrudPlugin = new _ContextPlugin.ContextPlugin(async context =>
403
406
  };
404
407
 
405
408
  try {
406
- /**
407
- * There is a meta object on the second key.
408
- * TODO: use when changing GraphQL output of the tags.
409
- */
410
409
  const [tags] = await storageOperations.tags(params);
410
+
411
+ if (Array.isArray(tags) === false) {
412
+ return [];
413
+ }
411
414
  /**
412
415
  * just to keep it standardized, sort by the tag ASC
413
416
  */
414
417
 
418
+
415
419
  return tags.sort();
416
420
  } catch (ex) {
417
- throw new _error.default(ex.message || "Could not search for tags.", ex.code || "FILE_TAG_SEARCH_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
421
+ 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 || {}), {}, {
418
422
  params
419
423
  }));
420
424
  }