@webiny/api-file-manager 0.0.0-unstable.99666aeb00 → 0.0.0-unstable.9bd236cf5e

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 (263) hide show
  1. package/FileManagerContextSetup.d.ts +2 -2
  2. package/FileManagerContextSetup.js +16 -14
  3. package/FileManagerContextSetup.js.map +1 -1
  4. package/README.md +1 -1
  5. package/cmsFileStorage/CmsFilesStorage.d.ts +3 -3
  6. package/cmsFileStorage/CmsFilesStorage.js +52 -61
  7. package/cmsFileStorage/CmsFilesStorage.js.map +1 -1
  8. package/cmsFileStorage/ListFilesWhereProcessor.d.ts +2 -2
  9. package/cmsFileStorage/ListFilesWhereProcessor.js +8 -10
  10. package/cmsFileStorage/ListFilesWhereProcessor.js.map +1 -1
  11. package/cmsFileStorage/ListTagsWhereProcessor.d.ts +2 -2
  12. package/cmsFileStorage/ListTagsWhereProcessor.js +8 -10
  13. package/cmsFileStorage/ListTagsWhereProcessor.js.map +1 -1
  14. package/cmsFileStorage/file.model.d.ts +5 -3
  15. package/cmsFileStorage/file.model.js +83 -43
  16. package/cmsFileStorage/file.model.js.map +1 -1
  17. package/contants.js +3 -2
  18. package/contants.js.map +1 -1
  19. package/createFileManager/files.crud.d.ts +3 -3
  20. package/createFileManager/files.crud.js +83 -55
  21. package/createFileManager/files.crud.js.map +1 -1
  22. package/createFileManager/index.d.ts +2 -14
  23. package/createFileManager/index.js +8 -5
  24. package/createFileManager/index.js.map +1 -1
  25. package/createFileManager/permissions/FilesPermissions.d.ts +1 -1
  26. package/createFileManager/permissions/FilesPermissions.js +3 -1
  27. package/createFileManager/permissions/FilesPermissions.js.map +1 -1
  28. package/createFileManager/permissions/SettingsPermissions.d.ts +4 -0
  29. package/createFileManager/permissions/SettingsPermissions.js +11 -0
  30. package/createFileManager/permissions/SettingsPermissions.js.map +1 -0
  31. package/createFileManager/settings.crud.d.ts +3 -3
  32. package/createFileManager/settings.crud.js +74 -48
  33. package/createFileManager/settings.crud.js.map +1 -1
  34. package/createFileManager/system.crud.d.ts +3 -3
  35. package/createFileManager/system.crud.js +6 -4
  36. package/createFileManager/system.crud.js.map +1 -1
  37. package/createFileManager/types.d.ts +16 -0
  38. package/createFileManager/types.js +7 -0
  39. package/createFileManager/types.js.map +1 -0
  40. package/delivery/AssetDelivery/AliasAssetRequestResolver.d.ts +11 -0
  41. package/delivery/AssetDelivery/AliasAssetRequestResolver.js +74 -0
  42. package/delivery/AssetDelivery/AliasAssetRequestResolver.js.map +1 -0
  43. package/delivery/AssetDelivery/Asset.d.ts +32 -0
  44. package/delivery/AssetDelivery/Asset.js +69 -0
  45. package/delivery/AssetDelivery/Asset.js.map +1 -0
  46. package/delivery/AssetDelivery/AssetDeliveryConfig.d.ts +63 -0
  47. package/delivery/AssetDelivery/AssetDeliveryConfig.js +102 -0
  48. package/delivery/AssetDelivery/AssetDeliveryConfig.js.map +1 -0
  49. package/delivery/AssetDelivery/AssetRequest.d.ts +25 -0
  50. package/delivery/AssetDelivery/AssetRequest.js +29 -0
  51. package/delivery/AssetDelivery/AssetRequest.js.map +1 -0
  52. package/delivery/AssetDelivery/FilesAssetRequestResolver.d.ts +6 -0
  53. package/delivery/AssetDelivery/FilesAssetRequestResolver.js +37 -0
  54. package/delivery/AssetDelivery/FilesAssetRequestResolver.js.map +1 -0
  55. package/delivery/AssetDelivery/NullAssetOutputStrategy.d.ts +4 -0
  56. package/delivery/AssetDelivery/NullAssetOutputStrategy.js +15 -0
  57. package/delivery/AssetDelivery/NullAssetOutputStrategy.js.map +1 -0
  58. package/delivery/AssetDelivery/NullAssetReply.d.ts +4 -0
  59. package/delivery/AssetDelivery/NullAssetReply.js +20 -0
  60. package/delivery/AssetDelivery/NullAssetReply.js.map +1 -0
  61. package/delivery/AssetDelivery/NullAssetResolver.d.ts +5 -0
  62. package/delivery/AssetDelivery/NullAssetResolver.js +14 -0
  63. package/delivery/AssetDelivery/NullAssetResolver.js.map +1 -0
  64. package/delivery/AssetDelivery/NullRequestResolver.d.ts +4 -0
  65. package/delivery/AssetDelivery/NullRequestResolver.js +14 -0
  66. package/delivery/AssetDelivery/NullRequestResolver.js.map +1 -0
  67. package/delivery/AssetDelivery/SetCacheControlHeaders.d.ts +8 -0
  68. package/delivery/AssetDelivery/SetCacheControlHeaders.js +25 -0
  69. package/delivery/AssetDelivery/SetCacheControlHeaders.js.map +1 -0
  70. package/delivery/AssetDelivery/SetResponseHeaders.d.ts +18 -0
  71. package/delivery/AssetDelivery/SetResponseHeaders.js +25 -0
  72. package/delivery/AssetDelivery/SetResponseHeaders.js.map +1 -0
  73. package/delivery/AssetDelivery/abstractions/AssetContentsReader.d.ts +6 -0
  74. package/delivery/AssetDelivery/abstractions/AssetContentsReader.js +7 -0
  75. package/delivery/AssetDelivery/abstractions/AssetContentsReader.js.map +1 -0
  76. package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.d.ts +4 -0
  77. package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.js +7 -0
  78. package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.js.map +1 -0
  79. package/delivery/AssetDelivery/abstractions/AssetProcessor.d.ts +4 -0
  80. package/delivery/AssetDelivery/abstractions/AssetProcessor.js +7 -0
  81. package/delivery/AssetDelivery/abstractions/AssetProcessor.js.map +1 -0
  82. package/delivery/AssetDelivery/abstractions/AssetReply.d.ts +25 -0
  83. package/delivery/AssetDelivery/abstractions/AssetReply.js +38 -0
  84. package/delivery/AssetDelivery/abstractions/AssetReply.js.map +1 -0
  85. package/delivery/AssetDelivery/abstractions/AssetRequestResolver.d.ts +5 -0
  86. package/delivery/AssetDelivery/abstractions/AssetRequestResolver.js +7 -0
  87. package/delivery/AssetDelivery/abstractions/AssetRequestResolver.js.map +1 -0
  88. package/delivery/AssetDelivery/abstractions/AssetResolver.d.ts +4 -0
  89. package/delivery/AssetDelivery/abstractions/AssetResolver.js +7 -0
  90. package/delivery/AssetDelivery/abstractions/AssetResolver.js.map +1 -0
  91. package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.d.ts +4 -0
  92. package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.js +7 -0
  93. package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.js.map +1 -0
  94. package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.d.ts +2 -0
  95. package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.js +15 -0
  96. package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.js.map +1 -0
  97. package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.d.ts +4 -0
  98. package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.js +7 -0
  99. package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.js.map +1 -0
  100. package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.d.ts +4 -0
  101. package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js +26 -0
  102. package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js.map +1 -0
  103. package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.d.ts +4 -0
  104. package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js +15 -0
  105. package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js.map +1 -0
  106. package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.d.ts +7 -0
  107. package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js +28 -0
  108. package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js.map +1 -0
  109. package/delivery/AssetDelivery/privateFiles/PrivateCache.d.ts +6 -0
  110. package/delivery/AssetDelivery/privateFiles/PrivateCache.js +28 -0
  111. package/delivery/AssetDelivery/privateFiles/PrivateCache.js.map +1 -0
  112. package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.d.ts +8 -0
  113. package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js +37 -0
  114. package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js.map +1 -0
  115. package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.d.ts +13 -0
  116. package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js +63 -0
  117. package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js.map +1 -0
  118. package/delivery/AssetDelivery/privateFiles/PublicCache.d.ts +6 -0
  119. package/delivery/AssetDelivery/privateFiles/PublicCache.js +28 -0
  120. package/delivery/AssetDelivery/privateFiles/PublicCache.js.map +1 -0
  121. package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.d.ts +7 -0
  122. package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js +27 -0
  123. package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js.map +1 -0
  124. package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.d.ts +7 -0
  125. package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js +27 -0
  126. package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js.map +1 -0
  127. package/delivery/AssetDelivery/privateFiles/internalIdentity.d.ts +7 -0
  128. package/delivery/AssetDelivery/privateFiles/internalIdentity.js +18 -0
  129. package/delivery/AssetDelivery/privateFiles/internalIdentity.js.map +1 -0
  130. package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.d.ts +4 -0
  131. package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js +14 -0
  132. package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js.map +1 -0
  133. package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.d.ts +4 -0
  134. package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js +14 -0
  135. package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js.map +1 -0
  136. package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.d.ts +6 -0
  137. package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js +26 -0
  138. package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js.map +1 -0
  139. package/delivery/index.d.ts +17 -0
  140. package/delivery/index.js +194 -0
  141. package/delivery/index.js.map +1 -0
  142. package/delivery/setupAssetDelivery.d.ts +6 -0
  143. package/delivery/setupAssetDelivery.js +128 -0
  144. package/delivery/setupAssetDelivery.js.map +1 -0
  145. package/enterprise/applyThreatScanning.d.ts +2 -0
  146. package/enterprise/applyThreatScanning.js +20 -0
  147. package/enterprise/applyThreatScanning.js.map +1 -0
  148. package/graphql/baseSchema.d.ts +1 -1
  149. package/graphql/baseSchema.js +6 -2
  150. package/graphql/baseSchema.js.map +1 -1
  151. package/graphql/createFilesTypeDefs.d.ts +1 -1
  152. package/graphql/createFilesTypeDefs.js +31 -9
  153. package/graphql/createFilesTypeDefs.js.map +1 -1
  154. package/graphql/filesSchema.d.ts +2 -2
  155. package/graphql/filesSchema.js +14 -8
  156. package/graphql/filesSchema.js.map +1 -1
  157. package/graphql/getFileByUrl.d.ts +3 -0
  158. package/graphql/getFileByUrl.js +78 -0
  159. package/graphql/getFileByUrl.js.map +1 -0
  160. package/graphql/index.d.ts +3 -2
  161. package/graphql/index.js +27 -5
  162. package/graphql/index.js.map +1 -1
  163. package/graphql/utils.js +3 -1
  164. package/graphql/utils.js.map +1 -1
  165. package/handlers/{transform/managers → manage}/imageManager.d.ts +2 -3
  166. package/handlers/{transform/managers → manage}/imageManager.js +10 -9
  167. package/handlers/manage/imageManager.js.map +1 -0
  168. package/handlers/manage/index.d.ts +1 -1
  169. package/handlers/manage/index.js +9 -5
  170. package/handlers/manage/index.js.map +1 -1
  171. package/handlers/{transform → manage}/legacyUtils.d.ts +0 -5
  172. package/handlers/{transform → manage}/legacyUtils.js +7 -15
  173. package/handlers/manage/legacyUtils.js.map +1 -0
  174. package/handlers/{transform → manage}/utils.js +7 -9
  175. package/handlers/manage/utils.js.map +1 -0
  176. package/handlers/types.d.ts +1 -1
  177. package/handlers/types.js +3 -1
  178. package/handlers/types.js.map +1 -1
  179. package/handlers/utils/getEnvironment.js +3 -1
  180. package/handlers/utils/getEnvironment.js.map +1 -1
  181. package/handlers/utils/getObjectParams.js +3 -1
  182. package/handlers/utils/getObjectParams.js.map +1 -1
  183. package/handlers/utils/index.js +3 -1
  184. package/handlers/utils/index.js.map +1 -1
  185. package/index.d.ts +6 -3
  186. package/index.js +31 -7
  187. package/index.js.map +1 -1
  188. package/modelModifier/CmsModelModifier.d.ts +5 -3
  189. package/modelModifier/CmsModelModifier.js +15 -12
  190. package/modelModifier/CmsModelModifier.js.map +1 -1
  191. package/package.json +25 -35
  192. package/plugins/FilePhysicalStoragePlugin.d.ts +2 -1
  193. package/plugins/FilePhysicalStoragePlugin.js +3 -3
  194. package/plugins/FilePhysicalStoragePlugin.js.map +1 -1
  195. package/plugins/FileStorageTransformPlugin.d.ts +1 -1
  196. package/plugins/FileStorageTransformPlugin.js +3 -4
  197. package/plugins/FileStorageTransformPlugin.js.map +1 -1
  198. package/plugins/index.js +3 -1
  199. package/plugins/index.js.map +1 -1
  200. package/storage/FileStorage.d.ts +5 -3
  201. package/storage/FileStorage.js +20 -16
  202. package/storage/FileStorage.js.map +1 -1
  203. package/types/file.d.ts +12 -0
  204. package/types/file.js +3 -1
  205. package/types/file.js.map +1 -1
  206. package/types/file.lifecycle.d.ts +2 -2
  207. package/types/file.lifecycle.js +3 -1
  208. package/types/file.lifecycle.js.map +1 -1
  209. package/types.d.ts +37 -15
  210. package/types.js +3 -1
  211. package/types.js.map +1 -1
  212. package/cmsFileStorage/createFileManagerPlugins.d.ts +0 -5
  213. package/cmsFileStorage/createFileManagerPlugins.js +0 -34
  214. package/cmsFileStorage/createFileManagerPlugins.js.map +0 -1
  215. package/cmsFileStorage/createModelField.d.ts +0 -5
  216. package/cmsFileStorage/createModelField.js +0 -37
  217. package/cmsFileStorage/createModelField.js.map +0 -1
  218. package/cmsFileStorage/isInstallationPending.d.ts +0 -4
  219. package/cmsFileStorage/isInstallationPending.js +0 -21
  220. package/cmsFileStorage/isInstallationPending.js.map +0 -1
  221. package/createFileManager/filevalidation.disabled.d.ts +0 -0
  222. package/createFileManager/filevalidation.disabled.js +0 -55
  223. package/createFileManager/filevalidation.disabled.js.map +0 -1
  224. package/handlers/download/byAlias.d.ts +0 -6
  225. package/handlers/download/byAlias.js +0 -89
  226. package/handlers/download/byAlias.js.map +0 -1
  227. package/handlers/download/byExactKey.d.ts +0 -2
  228. package/handlers/download/byExactKey.js +0 -57
  229. package/handlers/download/byExactKey.js.map +0 -1
  230. package/handlers/download/extractFileInformation.d.ts +0 -9
  231. package/handlers/download/extractFileInformation.js +0 -20
  232. package/handlers/download/extractFileInformation.js.map +0 -1
  233. package/handlers/download/getS3Object.d.ts +0 -12
  234. package/handlers/download/getS3Object.js +0 -72
  235. package/handlers/download/getS3Object.js.map +0 -1
  236. package/handlers/download/index.d.ts +0 -2
  237. package/handlers/download/index.js +0 -27
  238. package/handlers/download/index.js.map +0 -1
  239. package/handlers/transform/index.d.ts +0 -2
  240. package/handlers/transform/index.js +0 -92
  241. package/handlers/transform/index.js.map +0 -1
  242. package/handlers/transform/legacyUtils.js.map +0 -1
  243. package/handlers/transform/loaders/imageLoader.d.ts +0 -30
  244. package/handlers/transform/loaders/imageLoader.js +0 -94
  245. package/handlers/transform/loaders/imageLoader.js.map +0 -1
  246. package/handlers/transform/loaders/index.d.ts +0 -8
  247. package/handlers/transform/loaders/index.js +0 -10
  248. package/handlers/transform/loaders/index.js.map +0 -1
  249. package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +0 -11
  250. package/handlers/transform/loaders/sanitizeImageTransformations.js +0 -45
  251. package/handlers/transform/loaders/sanitizeImageTransformations.js.map +0 -1
  252. package/handlers/transform/managers/imageManager.js.map +0 -1
  253. package/handlers/transform/managers/index.d.ts +0 -5
  254. package/handlers/transform/managers/index.js +0 -10
  255. package/handlers/transform/managers/index.js.map +0 -1
  256. package/handlers/transform/optimizeImage.d.ts +0 -3
  257. package/handlers/transform/optimizeImage.js +0 -42
  258. package/handlers/transform/optimizeImage.js.map +0 -1
  259. package/handlers/transform/transformImage.d.ts +0 -13
  260. package/handlers/transform/transformImage.js +0 -28
  261. package/handlers/transform/transformImage.js.map +0 -1
  262. package/handlers/transform/utils.js.map +0 -1
  263. /package/handlers/{transform → manage}/utils.d.ts +0 -0
@@ -1,15 +1,3 @@
1
- import { FileManagerContextObject, FileManagerStorageOperations } from "../types";
2
- import { GetPermissions, SecurityIdentity } from "@webiny/api-security/types";
3
- import { FileStorage } from "../storage/FileStorage";
4
- import { FilesPermissions } from "./permissions/FilesPermissions";
5
- export interface FileManagerConfig {
6
- storageOperations: FileManagerStorageOperations;
7
- filesPermissions: FilesPermissions;
8
- getTenantId: () => string;
9
- getLocaleCode: () => string;
10
- getIdentity: () => SecurityIdentity;
11
- getPermissions: GetPermissions;
12
- storage: FileStorage;
13
- WEBINY_VERSION: string;
14
- }
1
+ import type { FileManagerContextObject } from "../types";
2
+ import type { FileManagerConfig } from "./types";
15
3
  export declare const createFileManager: (config: FileManagerConfig) => FileManagerContextObject;
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.createFileManager = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
7
  var _files = require("./files.crud");
10
8
  var _settings = require("./settings.crud");
11
9
  var _system = require("./system.crud");
@@ -13,8 +11,13 @@ const createFileManager = config => {
13
11
  const filesCrud = (0, _files.createFilesCrud)(config);
14
12
  const settingsCrud = (0, _settings.createSettingsCrud)(config);
15
13
  const systemCrud = (0, _system.createSystemCrud)(config);
16
- return (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, filesCrud), settingsCrud), systemCrud), {}, {
14
+ return {
15
+ ...filesCrud,
16
+ ...settingsCrud,
17
+ ...systemCrud,
17
18
  storage: config.storage
18
- });
19
+ };
19
20
  };
20
- exports.createFileManager = createFileManager;
21
+ exports.createFileManager = createFileManager;
22
+
23
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createFileManager","config","filesCrud","createFilesCrud","settingsCrud","createSettingsCrud","systemCrud","createSystemCrud","storage"],"sources":["index.ts"],"sourcesContent":["import { FileManagerContextObject, FileManagerStorageOperations } from \"~/types\";\nimport { GetPermissions, SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createFilesCrud } from \"~/createFileManager/files.crud\";\nimport { FileStorage } from \"~/storage/FileStorage\";\nimport { createSettingsCrud } from \"~/createFileManager/settings.crud\";\nimport { createSystemCrud } from \"~/createFileManager/system.crud\";\nimport { FilesPermissions } from \"~/createFileManager/permissions/FilesPermissions\";\n\nexport interface FileManagerConfig {\n storageOperations: FileManagerStorageOperations;\n filesPermissions: FilesPermissions;\n getTenantId: () => string;\n getLocaleCode: () => string;\n getIdentity: () => SecurityIdentity;\n getPermissions: GetPermissions;\n storage: FileStorage;\n WEBINY_VERSION: string;\n}\n\nexport const createFileManager = (config: FileManagerConfig): FileManagerContextObject => {\n const filesCrud = createFilesCrud(config);\n const settingsCrud = createSettingsCrud(config);\n const systemCrud = createSystemCrud(config);\n\n return {\n ...filesCrud,\n ...settingsCrud,\n ...systemCrud,\n storage: config.storage\n };\n};\n"],"mappings":";;;;;;;;AAEA;AAEA;AACA;AAcO,MAAMA,iBAAiB,GAAIC,MAAyB,IAA+B;EACtF,MAAMC,SAAS,GAAG,IAAAC,sBAAe,EAACF,MAAM,CAAC;EACzC,MAAMG,YAAY,GAAG,IAAAC,4BAAkB,EAACJ,MAAM,CAAC;EAC/C,MAAMK,UAAU,GAAG,IAAAC,wBAAgB,EAACN,MAAM,CAAC;EAE3C,2HACOC,SAAS,GACTE,YAAY,GACZE,UAAU;IACbE,OAAO,EAAEP,MAAM,CAACO;EAAO;AAE/B,CAAC;AAAC"}
1
+ {"version":3,"names":["_files","require","_settings","_system","createFileManager","config","filesCrud","createFilesCrud","settingsCrud","createSettingsCrud","systemCrud","createSystemCrud","storage","exports"],"sources":["index.ts"],"sourcesContent":["import type { FileManagerContextObject } from \"~/types\";\nimport { createFilesCrud } from \"~/createFileManager/files.crud\";\nimport { createSettingsCrud } from \"~/createFileManager/settings.crud\";\nimport { createSystemCrud } from \"~/createFileManager/system.crud\";\nimport type { FileManagerConfig } from \"~/createFileManager/types\";\n\nexport const createFileManager = (config: FileManagerConfig): FileManagerContextObject => {\n const filesCrud = createFilesCrud(config);\n const settingsCrud = createSettingsCrud(config);\n const systemCrud = createSystemCrud(config);\n\n return {\n ...filesCrud,\n ...settingsCrud,\n ...systemCrud,\n storage: config.storage\n };\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAGO,MAAMG,iBAAiB,GAAIC,MAAyB,IAA+B;EACtF,MAAMC,SAAS,GAAG,IAAAC,sBAAe,EAACF,MAAM,CAAC;EACzC,MAAMG,YAAY,GAAG,IAAAC,4BAAkB,EAACJ,MAAM,CAAC;EAC/C,MAAMK,UAAU,GAAG,IAAAC,wBAAgB,EAACN,MAAM,CAAC;EAE3C,OAAO;IACH,GAAGC,SAAS;IACZ,GAAGE,YAAY;IACf,GAAGE,UAAU;IACbE,OAAO,EAAEP,MAAM,CAACO;EACpB,CAAC;AACL,CAAC;AAACC,OAAA,CAAAT,iBAAA,GAAAA,iBAAA","ignoreList":[]}
@@ -1,4 +1,4 @@
1
1
  import { AppPermissions } from "@webiny/api-security/utils/AppPermissions";
2
- import { FilePermission } from "../../types";
2
+ import type { FilePermission } from "../../types";
3
3
  export declare class FilesPermissions extends AppPermissions<FilePermission> {
4
4
  }
@@ -6,4 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.FilesPermissions = void 0;
7
7
  var _AppPermissions = require("@webiny/api-security/utils/AppPermissions");
8
8
  class FilesPermissions extends _AppPermissions.AppPermissions {}
9
- exports.FilesPermissions = FilesPermissions;
9
+ exports.FilesPermissions = FilesPermissions;
10
+
11
+ //# sourceMappingURL=FilesPermissions.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["FilesPermissions","AppPermissions"],"sources":["FilesPermissions.ts"],"sourcesContent":["import { AppPermissions } from \"@webiny/api-security/utils/AppPermissions\";\nimport { FilePermission } from \"~/types\";\n\nexport class FilesPermissions extends AppPermissions<FilePermission> {}\n"],"mappings":";;;;;;AAAA;AAGO,MAAMA,gBAAgB,SAASC,8BAAc,CAAiB;AAAE"}
1
+ {"version":3,"names":["_AppPermissions","require","FilesPermissions","AppPermissions","exports"],"sources":["FilesPermissions.ts"],"sourcesContent":["import { AppPermissions } from \"@webiny/api-security/utils/AppPermissions\";\nimport type { FilePermission } from \"~/types\";\n\nexport class FilesPermissions extends AppPermissions<FilePermission> {}\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAGO,MAAMC,gBAAgB,SAASC,8BAAc,CAAiB;AAAEC,OAAA,CAAAF,gBAAA,GAAAA,gBAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import { AppPermissions } from "@webiny/api-security/utils/AppPermissions";
2
+ import type { SettingsPermission } from "../../types";
3
+ export declare class SettingsPermissions extends AppPermissions<SettingsPermission> {
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SettingsPermissions = void 0;
7
+ var _AppPermissions = require("@webiny/api-security/utils/AppPermissions");
8
+ class SettingsPermissions extends _AppPermissions.AppPermissions {}
9
+ exports.SettingsPermissions = SettingsPermissions;
10
+
11
+ //# sourceMappingURL=SettingsPermissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_AppPermissions","require","SettingsPermissions","AppPermissions","exports"],"sources":["SettingsPermissions.ts"],"sourcesContent":["import { AppPermissions } from \"@webiny/api-security/utils/AppPermissions\";\nimport type { SettingsPermission } from \"~/types\";\n\nexport class SettingsPermissions extends AppPermissions<SettingsPermission> {}\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAGO,MAAMC,mBAAmB,SAASC,8BAAc,CAAqB;AAAEC,OAAA,CAAAF,mBAAA,GAAAA,mBAAA","ignoreList":[]}
@@ -1,3 +1,3 @@
1
- import { SettingsCRUD } from "../types";
2
- import { FileManagerConfig } from "./index";
3
- export declare const createSettingsCrud: ({ storageOperations, getTenantId }: FileManagerConfig) => SettingsCRUD;
1
+ import type { SettingsCRUD } from "../types";
2
+ import type { FileManagerConfig } from "./types";
3
+ export declare const createSettingsCrud: ({ storageOperations, getTenantId, settingsPermissions }: Pick<FileManagerConfig, "storageOperations" | "getTenantId" | "settingsPermissions">) => SettingsCRUD;
@@ -5,82 +5,106 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.createSettingsCrud = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _fields = require("@commodo/fields");
10
- var _validation = require("@webiny/validation");
11
- /**
12
- * Package @commodo/fields does not have types.
13
- */
14
- // @ts-ignore
15
-
16
- const CreateDataModel = (0, _fields.withFields)({
17
- uploadMinFileSize: (0, _fields.number)({
18
- value: 0,
19
- validation: _validation.validation.create("gte:0")
20
- }),
21
- uploadMaxFileSize: (0, _fields.number)({
22
- value: 10737418240
23
- }),
24
- srcPrefix: (0, _fields.onSet)(value => {
25
- // Make sure srcPrefix always ends with forward slash.
8
+ var _pubsub = require("@webiny/pubsub");
9
+ var _zod = _interopRequireDefault(require("zod"));
10
+ var _utils = require("@webiny/utils");
11
+ const MIN_FILE_SIZE = 0;
12
+ const MAX_FILE_SIZE = 10737418240;
13
+ const uploadMinFileSizeValidation = _zod.default.number().min(MIN_FILE_SIZE, {
14
+ message: `Value needs to be greater than or equal to ${MIN_FILE_SIZE}.`
15
+ }).optional();
16
+ const uploadMaxFileSizeValidation = _zod.default.number().max(MAX_FILE_SIZE, {
17
+ message: `Value needs to be lesser than or equal to ${MAX_FILE_SIZE}.`
18
+ }).optional();
19
+ const createDataModelValidation = _zod.default.object({
20
+ uploadMinFileSize: uploadMinFileSizeValidation.default(MIN_FILE_SIZE),
21
+ uploadMaxFileSize: uploadMaxFileSizeValidation.default(MAX_FILE_SIZE),
22
+ srcPrefix: _zod.default.string().optional().default("/files/").transform(value => {
26
23
  if (typeof value === "string") {
27
24
  return value.endsWith("/") ? value : value + "/";
28
25
  }
29
26
  return value;
30
- })((0, _fields.string)({
31
- value: "/files/"
32
- }))
33
- })();
34
- const UpdateDataModel = (0, _fields.withFields)({
35
- uploadMinFileSize: (0, _fields.number)({
36
- validation: _validation.validation.create("gte:0")
37
- }),
38
- uploadMaxFileSize: (0, _fields.number)(),
39
- srcPrefix: (0, _fields.onSet)(value => {
40
- // Make sure srcPrefix always ends with forward slash.
27
+ })
28
+ });
29
+ const updateDataModelValidation = _zod.default.object({
30
+ uploadMinFileSize: uploadMinFileSizeValidation,
31
+ uploadMaxFileSize: uploadMaxFileSizeValidation,
32
+ srcPrefix: _zod.default.string().optional().transform(value => {
41
33
  if (typeof value === "string") {
42
34
  return value.endsWith("/") ? value : value + "/";
43
35
  }
44
36
  return value;
45
- })((0, _fields.string)())
46
- })();
37
+ })
38
+ });
47
39
  const createSettingsCrud = ({
48
40
  storageOperations,
49
- getTenantId
41
+ getTenantId,
42
+ settingsPermissions
50
43
  }) => {
51
44
  return {
45
+ onSettingsBeforeUpdate: (0, _pubsub.createTopic)("fileManager.onSettingsBeforeUpdate"),
46
+ onSettingsAfterUpdate: (0, _pubsub.createTopic)("fileManager.onSettingsAfterUpdate"),
52
47
  async getSettings() {
53
48
  return storageOperations.settings.get({
54
49
  tenant: getTenantId()
55
50
  });
56
51
  },
57
52
  async createSettings(data) {
58
- const settings = new CreateDataModel().populate(data);
59
- await settings.validate();
60
- const settingsData = await settings.toJSON();
53
+ await settingsPermissions.ensure();
54
+ const results = createDataModelValidation.safeParse(data);
55
+ if (!results.success) {
56
+ throw (0, _utils.createZodError)(results.error);
57
+ }
61
58
  return storageOperations.settings.create({
62
- data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settingsData), {}, {
59
+ data: {
60
+ ...results.data,
63
61
  tenant: getTenantId()
64
- })
62
+ }
65
63
  });
66
64
  },
67
65
  async updateSettings(data) {
68
- const updatedValue = new UpdateDataModel().populate(data);
69
- await updatedValue.validate();
70
- const existingSettings = await storageOperations.settings.get({
66
+ await settingsPermissions.ensure();
67
+ const results = updateDataModelValidation.safeParse(data);
68
+ if (!results.success) {
69
+ throw (0, _utils.createZodError)(results.error);
70
+ }
71
+ const original = await storageOperations.settings.get({
71
72
  tenant: getTenantId()
72
73
  });
73
- const updatedSettings = await updatedValue.toJSON({
74
- onlyDirty: true
74
+ const newSettings = {
75
+ ...(original || {})
76
+ };
77
+ for (const key in results.data) {
78
+ // @ts-expect-error
79
+ const value = results.data[key];
80
+ if (value === undefined) {
81
+ continue;
82
+ }
83
+ // @ts-expect-error
84
+ newSettings[key] = value;
85
+ }
86
+ const settings = {
87
+ ...newSettings,
88
+ tenant: getTenantId()
89
+ };
90
+ await this.onSettingsBeforeUpdate.publish({
91
+ input: data,
92
+ original,
93
+ settings
75
94
  });
76
- return storageOperations.settings.update({
77
- original: existingSettings,
78
- data: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingSettings), updatedSettings), {}, {
79
- tenant: getTenantId()
80
- })
95
+ const result = await storageOperations.settings.update({
96
+ original,
97
+ data: settings
98
+ });
99
+ await this.onSettingsAfterUpdate.publish({
100
+ input: data,
101
+ original,
102
+ settings: result
81
103
  });
104
+ return result;
82
105
  },
83
106
  async deleteSettings() {
107
+ await settingsPermissions.ensure();
84
108
  await storageOperations.settings.delete({
85
109
  tenant: getTenantId()
86
110
  });
@@ -88,4 +112,6 @@ const createSettingsCrud = ({
88
112
  }
89
113
  };
90
114
  };
91
- exports.createSettingsCrud = createSettingsCrud;
115
+ exports.createSettingsCrud = createSettingsCrud;
116
+
117
+ //# sourceMappingURL=settings.crud.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["CreateDataModel","withFields","uploadMinFileSize","number","value","validation","create","uploadMaxFileSize","srcPrefix","onSet","endsWith","string","UpdateDataModel","createSettingsCrud","storageOperations","getTenantId","getSettings","settings","get","tenant","createSettings","data","populate","validate","settingsData","toJSON","updateSettings","updatedValue","existingSettings","updatedSettings","onlyDirty","update","original","deleteSettings","delete"],"sources":["settings.crud.ts"],"sourcesContent":["/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { withFields, string, number, onSet } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport { FileManagerSettings, SettingsCRUD } from \"~/types\";\nimport { FileManagerConfig } from \"~/createFileManager/index\";\n\nconst CreateDataModel = withFields({\n uploadMinFileSize: number({ value: 0, validation: validation.create(\"gte:0\") }),\n uploadMaxFileSize: number({ value: 10737418240 }),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string({ value: \"/files/\" }))\n})();\n\nconst UpdateDataModel = withFields({\n uploadMinFileSize: number({\n validation: validation.create(\"gte:0\")\n }),\n uploadMaxFileSize: number(),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string())\n})();\n\nexport const createSettingsCrud = ({\n storageOperations,\n getTenantId\n}: FileManagerConfig): SettingsCRUD => {\n return {\n async getSettings() {\n return storageOperations.settings.get({ tenant: getTenantId() });\n },\n async createSettings(data) {\n const settings = new CreateDataModel().populate(data);\n await settings.validate();\n\n const settingsData: FileManagerSettings = await settings.toJSON();\n\n return storageOperations.settings.create({\n data: { ...settingsData, tenant: getTenantId() }\n });\n },\n async updateSettings(data) {\n const updatedValue = new UpdateDataModel().populate(data);\n await updatedValue.validate();\n\n const existingSettings = (await storageOperations.settings.get({\n tenant: getTenantId()\n })) as FileManagerSettings;\n\n const updatedSettings: Partial<FileManagerSettings> = await updatedValue.toJSON({\n onlyDirty: true\n });\n\n return storageOperations.settings.update({\n original: existingSettings,\n data: {\n ...existingSettings,\n ...updatedSettings,\n tenant: getTenantId()\n }\n });\n },\n async deleteSettings() {\n await storageOperations.settings.delete({ tenant: getTenantId() });\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AAIA;AACA;AALA;AACA;AACA;AACA;;AAMA,MAAMA,eAAe,GAAG,IAAAC,kBAAU,EAAC;EAC/BC,iBAAiB,EAAE,IAAAC,cAAM,EAAC;IAAEC,KAAK,EAAE,CAAC;IAAEC,UAAU,EAAEA,sBAAU,CAACC,MAAM,CAAC,OAAO;EAAE,CAAC,CAAC;EAC/EC,iBAAiB,EAAE,IAAAJ,cAAM,EAAC;IAAEC,KAAK,EAAE;EAAY,CAAC,CAAC;EACjDI,SAAS,EAAE,IAAAC,aAAK,EAAEL,KAAc,IAAK;IACjC;IACA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC3B,OAAOA,KAAK,CAACM,QAAQ,CAAC,GAAG,CAAC,GAAGN,KAAK,GAAGA,KAAK,GAAG,GAAG;IACpD;IACA,OAAOA,KAAK;EAChB,CAAC,CAAC,CAAC,IAAAO,cAAM,EAAC;IAAEP,KAAK,EAAE;EAAU,CAAC,CAAC;AACnC,CAAC,CAAC,EAAE;AAEJ,MAAMQ,eAAe,GAAG,IAAAX,kBAAU,EAAC;EAC/BC,iBAAiB,EAAE,IAAAC,cAAM,EAAC;IACtBE,UAAU,EAAEA,sBAAU,CAACC,MAAM,CAAC,OAAO;EACzC,CAAC,CAAC;EACFC,iBAAiB,EAAE,IAAA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EAAE;MACf,CAAC,CAAC;MAEF,OAAOhB,iBAAiB,CAACG,QAAQ,CAACc,MAAM,CAAC;QACrCC,QAAQ,EAAEJ,gBAAgB;QAC1BP,IAAI,0FACGO,gBAAgB,GAChBC,eAAe;UAClBV,MAAM,EAAEJ,WAAW;QAAE;MAE7B,CAAC,CAAC;IACN,CAAC;IACD,MAAMkB,cAAc,GAAG;MACnB,MAAMnB,iBAAiB,CAACG,QAAQ,CAACiB,MAAM,CAAC;QAAEf,MAAM,EAAEJ,WAAW;MAAG,CAAC,CAAC;MAElE,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_pubsub","require","_zod","_interopRequireDefault","_utils","MIN_FILE_SIZE","MAX_FILE_SIZE","uploadMinFileSizeValidation","zod","number","min","message","optional","uploadMaxFileSizeValidation","max","createDataModelValidation","object","uploadMinFileSize","default","uploadMaxFileSize","srcPrefix","string","transform","value","endsWith","updateDataModelValidation","createSettingsCrud","storageOperations","getTenantId","settingsPermissions","onSettingsBeforeUpdate","createTopic","onSettingsAfterUpdate","getSettings","settings","get","tenant","createSettings","data","ensure","results","safeParse","success","createZodError","error","create","updateSettings","original","newSettings","key","undefined","publish","input","result","update","deleteSettings","delete","exports"],"sources":["settings.crud.ts"],"sourcesContent":["import { createTopic } from \"@webiny/pubsub\";\nimport type { FileManagerSettings, SettingsCRUD } from \"~/types\";\nimport type { FileManagerConfig } from \"./types\";\nimport zod from \"zod\";\nimport { createZodError } from \"@webiny/utils\";\n\nconst MIN_FILE_SIZE = 0;\nconst MAX_FILE_SIZE = 10737418240;\n\nconst uploadMinFileSizeValidation = zod\n .number()\n .min(MIN_FILE_SIZE, {\n message: `Value needs to be greater than or equal to ${MIN_FILE_SIZE}.`\n })\n .optional();\nconst uploadMaxFileSizeValidation = zod\n .number()\n .max(MAX_FILE_SIZE, {\n message: `Value needs to be lesser than or equal to ${MAX_FILE_SIZE}.`\n })\n .optional();\n\nconst createDataModelValidation = zod.object({\n uploadMinFileSize: uploadMinFileSizeValidation.default(MIN_FILE_SIZE),\n uploadMaxFileSize: uploadMaxFileSizeValidation.default(MAX_FILE_SIZE),\n srcPrefix: zod\n .string()\n .optional()\n .default(\"/files/\")\n .transform(value => {\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })\n});\n\nconst updateDataModelValidation = zod.object({\n uploadMinFileSize: uploadMinFileSizeValidation,\n uploadMaxFileSize: uploadMaxFileSizeValidation,\n srcPrefix: zod\n .string()\n .optional()\n .transform(value => {\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })\n});\n\nexport const createSettingsCrud = ({\n storageOperations,\n getTenantId,\n settingsPermissions\n}: Pick<\n FileManagerConfig,\n \"storageOperations\" | \"getTenantId\" | \"settingsPermissions\"\n>): SettingsCRUD => {\n return {\n onSettingsBeforeUpdate: createTopic(\"fileManager.onSettingsBeforeUpdate\"),\n onSettingsAfterUpdate: createTopic(\"fileManager.onSettingsAfterUpdate\"),\n async getSettings() {\n return storageOperations.settings.get({ tenant: getTenantId() });\n },\n async createSettings(data) {\n await settingsPermissions.ensure();\n\n const results = createDataModelValidation.safeParse(data);\n if (!results.success) {\n throw createZodError(results.error);\n }\n\n return storageOperations.settings.create({\n data: {\n ...results.data,\n tenant: getTenantId()\n }\n });\n },\n async updateSettings(data) {\n await settingsPermissions.ensure();\n const results = updateDataModelValidation.safeParse(data);\n if (!results.success) {\n throw createZodError(results.error);\n }\n\n const original = (await storageOperations.settings.get({\n tenant: getTenantId()\n })) as FileManagerSettings;\n const newSettings: FileManagerSettings = {\n ...(original || {})\n };\n\n for (const key in results.data) {\n // @ts-expect-error\n const value = results.data[key];\n if (value === undefined) {\n continue;\n }\n // @ts-expect-error\n newSettings[key] = value;\n }\n\n const settings: FileManagerSettings = {\n ...newSettings,\n tenant: getTenantId()\n };\n\n await this.onSettingsBeforeUpdate.publish({\n input: data,\n original,\n settings\n });\n const result = await storageOperations.settings.update({\n original,\n data: settings\n });\n await this.onSettingsAfterUpdate.publish({\n input: data,\n original,\n settings: result\n });\n\n return result;\n },\n async deleteSettings() {\n await settingsPermissions.ensure();\n await storageOperations.settings.delete({ tenant: getTenantId() });\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAGA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEA,MAAMI,aAAa,GAAG,CAAC;AACvB,MAAMC,aAAa,GAAG,WAAW;AAEjC,MAAMC,2BAA2B,GAAGC,YAAG,CAClCC,MAAM,CAAC,CAAC,CACRC,GAAG,CAACL,aAAa,EAAE;EAChBM,OAAO,EAAE,8CAA8CN,aAAa;AACxE,CAAC,CAAC,CACDO,QAAQ,CAAC,CAAC;AACf,MAAMC,2BAA2B,GAAGL,YAAG,CAClCC,MAAM,CAAC,CAAC,CACRK,GAAG,CAACR,aAAa,EAAE;EAChBK,OAAO,EAAE,6CAA6CL,aAAa;AACvE,CAAC,CAAC,CACDM,QAAQ,CAAC,CAAC;AAEf,MAAMG,yBAAyB,GAAGP,YAAG,CAACQ,MAAM,CAAC;EACzCC,iBAAiB,EAAEV,2BAA2B,CAACW,OAAO,CAACb,aAAa,CAAC;EACrEc,iBAAiB,EAAEN,2BAA2B,CAACK,OAAO,CAACZ,aAAa,CAAC;EACrEc,SAAS,EAAEZ,YAAG,CACTa,MAAM,CAAC,CAAC,CACRT,QAAQ,CAAC,CAAC,CACVM,OAAO,CAAC,SAAS,CAAC,CAClBI,SAAS,CAACC,KAAK,IAAI;IAChB,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC3B,OAAOA,KAAK,CAACC,QAAQ,CAAC,GAAG,CAAC,GAAGD,KAAK,GAAGA,KAAK,GAAG,GAAG;IACpD;IACA,OAAOA,KAAK;EAChB,CAAC;AACT,CAAC,CAAC;AAEF,MAAME,yBAAyB,G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,QAAQ,CAACsB,MAAM,CAAC;QAAEpB,MAAM,EAAER,WAAW,CAAC;MAAE,CAAC,CAAC;MAElE,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC6B,OAAA,CAAA/B,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -1,3 +1,3 @@
1
- import { SystemCRUD } from "../types";
2
- import { FileManagerConfig } from "./index";
3
- export declare const createSystemCrud: ({ storageOperations, getTenantId, getIdentity, WEBINY_VERSION }: FileManagerConfig) => SystemCRUD;
1
+ import type { SystemCRUD } from "../types";
2
+ import type { FileManagerConfig } from "./types";
3
+ export declare const createSystemCrud: ({ storageOperations, getTenantId, getIdentity, WEBINY_VERSION }: Pick<FileManagerConfig, "storageOperations" | "getTenantId" | "getIdentity" | "WEBINY_VERSION">) => SystemCRUD;
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.createSystemCrud = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
8
  var _pubsub = require("@webiny/pubsub");
10
9
  var _apiSecurity = require("@webiny/api-security");
11
10
  var _error = _interopRequireDefault(require("@webiny/error"));
@@ -29,10 +28,11 @@ const createSystemCrud = ({
29
28
  tenant: getTenantId()
30
29
  });
31
30
  if (system) {
32
- const data = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), {}, {
31
+ const data = {
32
+ ...system,
33
33
  tenant: system.tenant || getTenantId(),
34
34
  version
35
- });
35
+ };
36
36
  try {
37
37
  await storageOperations.system.update({
38
38
  original: system,
@@ -83,4 +83,6 @@ const createSystemCrud = ({
83
83
  }
84
84
  };
85
85
  };
86
- exports.createSystemCrud = createSystemCrud;
86
+ exports.createSystemCrud = createSystemCrud;
87
+
88
+ //# sourceMappingURL=system.crud.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createSystemCrud","storageOperations","getTenantId","getIdentity","WEBINY_VERSION","onSystemBeforeInstall","createTopic","onSystemAfterInstall","getVersion","system","get","tenant","version","setVersion","data","update","original","ex","WebinyError","create","install","srcPrefix","identity","NotAuthorizedError","publish","createSettings"],"sources":["system.crud.ts"],"sourcesContent":["import { createTopic } from \"@webiny/pubsub\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport {\n FileManagerContextObject,\n FileManagerSettings,\n FileManagerSystem,\n SystemCRUD\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { FileManagerConfig } from \"~/createFileManager/index\";\n\nexport const createSystemCrud = ({\n storageOperations,\n getTenantId,\n getIdentity,\n WEBINY_VERSION\n}: FileManagerConfig): SystemCRUD => {\n return {\n onSystemBeforeInstall: createTopic(\"fileManager.onSystemBeforeInstall\"),\n onSystemAfterInstall: createTopic(\"fileManager.onSystemAfterInstall\"),\n async getVersion() {\n const system = await storageOperations.system.get({ tenant: getTenantId() });\n\n return system ? system.version : null;\n },\n async setVersion(version: string) {\n const system = await storageOperations.system.get({ tenant: getTenantId() });\n\n if (system) {\n const data: FileManagerSystem = {\n ...system,\n tenant: system.tenant || getTenantId(),\n version\n };\n try {\n await storageOperations.system.update({\n original: system,\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\n \"Could not update the system data.\",\n \"SYSTEM_UPDATE_ERROR\",\n {\n data\n }\n );\n }\n }\n\n const data: FileManagerSystem = {\n version,\n tenant: getTenantId()\n };\n try {\n await storageOperations.system.create({\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\"Could not create the system data.\", \"SYSTEM_CREATE_ERROR\", {\n data\n });\n }\n },\n async install(this: FileManagerContextObject, { srcPrefix }) {\n const identity = getIdentity();\n\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const version = await this.getVersion();\n\n if (version) {\n throw new WebinyError(\n \"File Manager is already installed.\",\n \"FILES_INSTALL_ABORTED\"\n );\n }\n\n const data: Partial<FileManagerSettings> = {};\n\n if (srcPrefix) {\n data.srcPrefix = srcPrefix;\n }\n\n await this.onSystemBeforeInstall.publish({});\n\n await this.createSettings(data);\n await this.setVersion(WEBINY_VERSION);\n\n await this.onSystemAfterInstall.publish({});\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAOA;AAGO,MAAMA,gBAAgB,GAAG,CAAC;EAC7BC,iBAAiB;EACjBC,WAAW;EACXC,WAAW;EACXC;AACe,CAAC,KAAiB;EACjC,OAAO;IACHC,qBAAqB,EAAE,IAAAC,mBAAW,EAAC,mCAAmC,CAAC;IACvEC,oBAAoB,EAAE,IAAAD,mBAAW,EAAC,kCAAkC,CAAC;IACrE,MAAME,UAAU,GAAG;MACf,MAAMC,MAAM,GAAG,MAAMR,iBAAiB,CAACQ,MAAM,CAACC,GAAG,CAAC;QAAEC,MAAM,EAAET,WAAW;MAAG,CAAC,CAAC;MAE5E,OAAOO,MAAM,GAAGA,MAAM,CAACG,OAAO,GAAG,IAAI;IACzC,CAAC;IACD,MAAMC,UAAU,CAACD,OAAe,EAAE;MAC9B,MAAMH,MAAM,GAAG,MAAMR,iBAAiB,CAACQ,MAAM,CAACC,GAAG,CAAC;QAAEC,MAAM,EAAET,WAAW;MAAG,CAAC,CAAC;MAE5E,IAAIO,MAAM,EAAE;QACR,MAAMK,IAAuB,+DACtBL,MAAM;UACTE,MAAM,EAAEF,MAAM,CAACE,MAAM,IAAIT,WAAW,EAAE;UACtCU;QAAO,EACV;QACD,IAAI;UACA,MAAMX,iBAAiB,CAACQ,MAAM,CAACM,MAAM,CAAC;YAClCC,QAAQ,EAAEP,MAAM;YAChBK;UACJ,CAAC,CAAC;UACF;QACJ,CAAC,CAAC,OAAOG,EAAE,EAAE;UACT,MAAM,IAAIC,cAAW,CACjB,mCAAmC,EACnC,qBAAqB,EACrB;YACIJ;UACJ,CAAC,CACJ;QACL;MACJ;MAEA,MAAMA,IAAuB,GAAG;QAC5BF,OAAO;QACPD,MAAM,EAAET,WAAW;MACvB,CAAC;MACD,IAAI;QACA,MAAMD,iBAAiB,CAACQ,MAAM,CAACU,MAAM,CAAC;UAClCL;QACJ,CAAC,CAAC;QACF;MACJ,CAAC,CAAC,OAAOG,EAAE,EAAE;QACT,MAAM,IAAIC,cAAW,CAAC,mCAAmC,EAAE,qBAAqB,EAAE;UAC9EJ;QACJ,CAAC,CAAC;MACN;IACJ,CAAC;IACD,MAAMM,OAAO,CAAiC;MAAEC;IAAU,CAAC,EAAE;MACzD,MAAMC,QAAQ,GAAGnB,WAAW,EAAE;MAE9B,IAAI,CAACmB,QAAQ,EAAE;QACX,MAAM,IAAIC,+BAAkB,EAAE;MAClC;MAEA,MAAMX,OAAO,GAAG,MAAM,IAAI,CAACJ,UAAU,EAAE;MAEvC,IAAII,OAAO,EAAE;QACT,MAAM,IAAIM,cAAW,CACjB,oCAAoC,EACpC,uBAAuB,CAC1B;MACL;MAEA,MAAMJ,IAAkC,GAAG,CAAC,CAAC;MAE7C,IAAIO,SAAS,EAAE;QACXP,IAAI,CAACO,SAAS,GAAGA,SAAS;MAC9B;MAEA,MAAM,IAAI,CAAChB,qBAAqB,CAACmB,OAAO,CAAC,CAAC,CAAC,CAAC;MAE5C,MAAM,IAAI,CAACC,cAAc,CAACX,IAAI,CAAC;MAC/B,MAAM,IAAI,CAACD,UAAU,CAACT,cAAc,CAAC;MAErC,MAAM,IAAI,CAACG,oBAAoB,CAACiB,OAAO,CAAC,CAAC,CAAC,CAAC;MAE3C,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_pubsub","require","_apiSecurity","_error","_interopRequireDefault","createSystemCrud","storageOperations","getTenantId","getIdentity","WEBINY_VERSION","onSystemBeforeInstall","createTopic","onSystemAfterInstall","getVersion","system","get","tenant","version","setVersion","data","update","original","ex","WebinyError","create","install","srcPrefix","identity","NotAuthorizedError","publish","createSettings","exports"],"sources":["system.crud.ts"],"sourcesContent":["import { createTopic } from \"@webiny/pubsub\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport type {\n FileManagerContextObject,\n FileManagerSettings,\n FileManagerSystem,\n SystemCRUD\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport type { FileManagerConfig } from \"~/createFileManager/types\";\n\nexport const createSystemCrud = ({\n storageOperations,\n getTenantId,\n getIdentity,\n WEBINY_VERSION\n}: Pick<\n FileManagerConfig,\n \"storageOperations\" | \"getTenantId\" | \"getIdentity\" | \"WEBINY_VERSION\"\n>): SystemCRUD => {\n return {\n onSystemBeforeInstall: createTopic(\"fileManager.onSystemBeforeInstall\"),\n onSystemAfterInstall: createTopic(\"fileManager.onSystemAfterInstall\"),\n async getVersion() {\n const system = await storageOperations.system.get({ tenant: getTenantId() });\n\n return system ? system.version : null;\n },\n async setVersion(version: string) {\n const system = await storageOperations.system.get({ tenant: getTenantId() });\n\n if (system) {\n const data: FileManagerSystem = {\n ...system,\n tenant: system.tenant || getTenantId(),\n version\n };\n try {\n await storageOperations.system.update({\n original: system,\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\n \"Could not update the system data.\",\n \"SYSTEM_UPDATE_ERROR\",\n {\n data\n }\n );\n }\n }\n\n const data: FileManagerSystem = {\n version,\n tenant: getTenantId()\n };\n try {\n await storageOperations.system.create({\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\"Could not create the system data.\", \"SYSTEM_CREATE_ERROR\", {\n data\n });\n }\n },\n async install(this: FileManagerContextObject, { srcPrefix }) {\n const identity = getIdentity();\n\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const version = await this.getVersion();\n\n if (version) {\n throw new WebinyError(\n \"File Manager is already installed.\",\n \"FILES_INSTALL_ABORTED\"\n );\n }\n\n const data: Partial<FileManagerSettings> = {};\n\n if (srcPrefix) {\n data.srcPrefix = srcPrefix;\n }\n\n await this.onSystemBeforeInstall.publish({});\n\n await this.createSettings(data);\n await this.setVersion(WEBINY_VERSION);\n\n await this.onSystemAfterInstall.publish({});\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAA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M,CAAC;UAClCL;QACJ,CAAC,CAAC;QACF;MACJ,CAAC,CAAC,OAAOG,EAAE,EAAE;QACT,MAAM,IAAIC,cAAW,CAAC,mCAAmC,EAAE,qBAAqB,EAAE;UAC9EJ;QACJ,CAAC,CAAC;MACN;IACJ,CAAC;IACD,MAAMM,OAAOA,CAAiC;MAAEC;IAAU,CAAC,EAAE;MACzD,MAAMC,QAAQ,GAAGnB,WAAW,CAAC,CAAC;MAE9B,IAAI,CAACmB,QAAQ,EAAE;QACX,MAAM,IAAIC,+BAAkB,CAAC,CAAC;MAClC;MAEA,MAAMX,OAAO,GAAG,MAAM,IAAI,CAACJ,UAAU,CAAC,CAAC;MAEvC,IAAII,OAAO,EAAE;QACT,MAAM,IAAIM,cAAW,CACjB,oCAAoC,EACpC,uBACJ,CAAC;MACL;MAEA,MAAMJ,IAAkC,GAAG,CAAC,CAAC;MAE7C,IAAIO,SAAS,EAAE;QACXP,IAAI,CAACO,SAAS,GAAGA,SAAS;MAC9B;MAEA,MAAM,IAAI,CAAChB,qBAAqB,CAACmB,OAAO,CAAC,CAAC,CAAC,CAAC;MAE5C,MAAM,IAAI,CAACC,cAAc,CAACX,IAAI,CAAC;MAC/B,MAAM,IAAI,CAACD,UAAU,CAACT,cAAc,CAAC;MAErC,MAAM,IAAI,CAACG,oBAAoB,CAACiB,OAAO,CAAC,CAAC,CAAC,CAAC;MAE3C,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAACE,OAAA,CAAA1B,gBAAA,GAAAA,gBAAA","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ import type { FileManagerStorageOperations } from "../types";
2
+ import type { FilesPermissions } from "./permissions/FilesPermissions";
3
+ import type { GetPermissions, SecurityIdentity } from "@webiny/api-security/types";
4
+ import type { FileStorage } from "../storage/FileStorage";
5
+ import type { SettingsPermissions } from "./permissions/SettingsPermissions";
6
+ export interface FileManagerConfig {
7
+ storageOperations: FileManagerStorageOperations;
8
+ filesPermissions: FilesPermissions;
9
+ settingsPermissions: SettingsPermissions;
10
+ getTenantId: () => string;
11
+ getLocaleCode: () => string;
12
+ getIdentity: () => SecurityIdentity;
13
+ getPermissions: GetPermissions;
14
+ storage: FileStorage;
15
+ WEBINY_VERSION: string;
16
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { FileManagerStorageOperations } from \"~/types\";\nimport type { FilesPermissions } from \"./permissions/FilesPermissions\";\nimport type { GetPermissions, SecurityIdentity } from \"@webiny/api-security/types\";\nimport type { FileStorage } from \"~/storage/FileStorage\";\nimport type { SettingsPermissions } from \"./permissions/SettingsPermissions\";\n\nexport interface FileManagerConfig {\n storageOperations: FileManagerStorageOperations;\n filesPermissions: FilesPermissions;\n settingsPermissions: SettingsPermissions;\n getTenantId: () => string;\n getLocaleCode: () => string;\n getIdentity: () => SecurityIdentity;\n getPermissions: GetPermissions;\n storage: FileStorage;\n WEBINY_VERSION: string;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ import type { Request } from "@webiny/handler/types";
2
+ import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
3
+ import type { AssetRequestResolver } from "..";
4
+ import { AssetRequest } from "..";
5
+ export declare class AliasAssetRequestResolver implements AssetRequestResolver {
6
+ private documentClient;
7
+ private resolver;
8
+ constructor(documentClient: DynamoDBDocument, resolver: AssetRequestResolver);
9
+ resolve(request: Request): Promise<AssetRequest | undefined>;
10
+ private getFileByAlias;
11
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AliasAssetRequestResolver = void 0;
7
+ var _clientDynamodb = require("@webiny/aws-sdk/client-dynamodb");
8
+ var _ = require("./..");
9
+ class AliasAssetRequestResolver {
10
+ constructor(documentClient, resolver) {
11
+ this.documentClient = documentClient;
12
+ this.resolver = resolver;
13
+ }
14
+ async resolve(request) {
15
+ const resolvedAsset = await this.resolver.resolve(request);
16
+ if (resolvedAsset) {
17
+ return resolvedAsset;
18
+ }
19
+ const params = request.params ?? {};
20
+ const query = request.query ?? {};
21
+ const path = decodeURI(params["*"]);
22
+ const tenant = query.tenant || "root";
23
+ const fileKey = await this.getFileByAlias(tenant, path);
24
+ if (!fileKey) {
25
+ return undefined;
26
+ }
27
+ const {
28
+ original,
29
+ ...options
30
+ } = query;
31
+ return new _.AssetRequest({
32
+ key: fileKey,
33
+ context: {
34
+ url: request.url
35
+ },
36
+ options: {
37
+ original: original !== undefined,
38
+ ...options
39
+ }
40
+ });
41
+ }
42
+ async getFileByAlias(tenant, alias) {
43
+ const {
44
+ Items
45
+ } = await this.documentClient.send(new _clientDynamodb.QueryCommand({
46
+ TableName: String(process.env.DB_TABLE),
47
+ IndexName: "GSI1",
48
+ Limit: 1,
49
+ KeyConditionExpression: "GSI1_PK = :GSI1_PK AND GSI1_SK = :GSI1_SK",
50
+ ExpressionAttributeValues: {
51
+ ":GSI1_PK": {
52
+ S: `T#${tenant}#FM#FILE_ALIASES`
53
+ },
54
+ ":GSI1_SK": {
55
+ S: alias
56
+ }
57
+ }
58
+ }));
59
+ if (!Array.isArray(Items)) {
60
+ return null;
61
+ }
62
+ const [item] = Items;
63
+ if (!item) {
64
+ return null;
65
+ }
66
+ const {
67
+ data
68
+ } = (0, _clientDynamodb.unmarshall)(item);
69
+ return data?.key ?? null;
70
+ }
71
+ }
72
+ exports.AliasAssetRequestResolver = AliasAssetRequestResolver;
73
+
74
+ //# sourceMappingURL=AliasAssetRequestResolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_clientDynamodb","require","_","AliasAssetRequestResolver","constructor","documentClient","resolver","resolve","request","resolvedAsset","params","query","path","decodeURI","tenant","fileKey","getFileByAlias","undefined","original","options","AssetRequest","key","context","url","alias","Items","send","QueryCommand","TableName","String","process","env","DB_TABLE","IndexName","Limit","KeyConditionExpression","ExpressionAttributeValues","S","Array","isArray","item","data","unmarshall","exports"],"sources":["AliasAssetRequestResolver.ts"],"sourcesContent":["import type { Request } from \"@webiny/handler/types\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { QueryCommand, unmarshall } from \"@webiny/aws-sdk/client-dynamodb\";\nimport type { AssetRequestResolver } from \"~/delivery\";\nimport { AssetRequest } from \"~/delivery\";\n\nexport class AliasAssetRequestResolver implements AssetRequestResolver {\n private documentClient: DynamoDBDocument;\n private resolver: AssetRequestResolver;\n\n constructor(documentClient: DynamoDBDocument, resolver: AssetRequestResolver) {\n this.documentClient = documentClient;\n this.resolver = resolver;\n }\n\n async resolve(request: Request): Promise<AssetRequest | undefined> {\n const resolvedAsset = await this.resolver.resolve(request);\n\n if (resolvedAsset) {\n return resolvedAsset;\n }\n\n const params = (request.params as Record<string, any>) ?? {};\n const query = (request.query as Record<string, any>) ?? {};\n const path = decodeURI(params[\"*\"]);\n\n const tenant = query.tenant || \"root\";\n const fileKey = await this.getFileByAlias(tenant, path);\n\n if (!fileKey) {\n return undefined;\n }\n\n const { original, ...options } = query;\n\n return new AssetRequest({\n key: fileKey,\n context: {\n url: request.url\n },\n options: {\n original: original !== undefined,\n ...options\n }\n });\n }\n\n private async getFileByAlias(tenant: string, alias: string): Promise<string | null> {\n const { Items } = await this.documentClient.send(\n new QueryCommand({\n TableName: String(process.env.DB_TABLE),\n IndexName: \"GSI1\",\n Limit: 1,\n KeyConditionExpression: \"GSI1_PK = :GSI1_PK AND GSI1_SK = :GSI1_SK\",\n ExpressionAttributeValues: {\n \":GSI1_PK\": { S: `T#${tenant}#FM#FILE_ALIASES` },\n \":GSI1_SK\": { S: alias }\n }\n })\n );\n\n if (!Array.isArray(Items)) {\n return null;\n }\n const [item] = Items;\n if (!item) {\n return null;\n }\n const { data } = unmarshall(item);\n\n return data?.key ?? null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I,CAC5C,IAAIC,4BAAY,CAAC;MACbC,SAAS,EAAEC,MAAM,CAACC,OAAO,CAACC,GAAG,CAACC,QAAQ,CAAC;MACvCC,SAAS,EAAE,MAAM;MACjBC,KAAK,EAAE,CAAC;MACRC,sBAAsB,EAAE,2CAA2C;MACnEC,yBAAyB,EAAE;QACvB,UAAU,EAAE;UAAEC,CAAC,EAAE,KAAKvB,MAAM;QAAmB,CAAC;QAChD,UAAU,EAAE;UAAEuB,CAAC,EAAEb;QAAM;MAC3B;IACJ,CAAC,CACL,CAAC;IAED,IAAI,CAACc,KAAK,CAACC,OAAO,CAACd,KAAK,CAAC,EAAE;MACvB,OAAO,IAAI;IACf;IACA,MAAM,CAACe,IAAI,CAAC,GAAGf,KAAK;IACpB,IAAI,CAACe,IAAI,EAAE;MACP,OAAO,IAAI;IACf;IACA,MAAM;MAAEC;IAAK,CAAC,GAAG,IAAAC,0BAAU,EAACF,IAAI,CAAC;IAEjC,OAAOC,IAAI,EAAEpB,GAAG,IAAI,IAAI;EAC5B;AACJ;AAACsB,OAAA,CAAAxC,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -0,0 +1,32 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type { AssetContentsReader, AssetOutputStrategy } from "..";
4
+ type Setter<T> = (arg: T | undefined) => T;
5
+ export interface AssetData {
6
+ id: string;
7
+ tenant: string;
8
+ locale: string;
9
+ key: string;
10
+ size: number;
11
+ contentType: string;
12
+ }
13
+ export declare class Asset {
14
+ protected readonly props: AssetData;
15
+ private outputStrategy;
16
+ private contentsReader;
17
+ constructor(props: AssetData);
18
+ clone(): Asset;
19
+ withProps(props: Partial<AssetData>): Asset;
20
+ getId(): string;
21
+ getTenant(): string;
22
+ getLocale(): string;
23
+ getKey(): string;
24
+ getSize(): number;
25
+ getContentType(): string;
26
+ getExtension(): string;
27
+ getContents(): Promise<Buffer>;
28
+ setContentsReader(reader: AssetContentsReader): void;
29
+ output(): Promise<import("..").AssetReply>;
30
+ setOutputStrategy(setter: Setter<AssetOutputStrategy> | AssetOutputStrategy): void;
31
+ }
32
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Asset = void 0;
7
+ class Asset {
8
+ constructor(props) {
9
+ this.props = props;
10
+ }
11
+ clone() {
12
+ return this.withProps(structuredClone(this.props));
13
+ }
14
+ withProps(props) {
15
+ const newAsset = new Asset({
16
+ ...this.props,
17
+ ...props
18
+ });
19
+ newAsset.contentsReader = this.contentsReader;
20
+ newAsset.outputStrategy = this.outputStrategy;
21
+ return newAsset;
22
+ }
23
+ getId() {
24
+ return this.props.id;
25
+ }
26
+ getTenant() {
27
+ return this.props.tenant;
28
+ }
29
+ getLocale() {
30
+ return this.props.locale;
31
+ }
32
+ getKey() {
33
+ return this.props.key;
34
+ }
35
+ getSize() {
36
+ return this.props.size;
37
+ }
38
+ getContentType() {
39
+ return this.props.contentType;
40
+ }
41
+ getExtension() {
42
+ return this.getKey().split(".").pop() ?? "";
43
+ }
44
+ getContents() {
45
+ if (!this.contentsReader) {
46
+ throw Error(`Asset contents reader was not configured!`);
47
+ }
48
+ return this.contentsReader.read(this);
49
+ }
50
+ setContentsReader(reader) {
51
+ this.contentsReader = reader;
52
+ }
53
+ output() {
54
+ if (!this.outputStrategy) {
55
+ throw Error(`Asset output strategy was not configured!`);
56
+ }
57
+ return this.outputStrategy.output(this);
58
+ }
59
+ setOutputStrategy(setter) {
60
+ if (typeof setter === "function") {
61
+ this.outputStrategy = setter(this.outputStrategy);
62
+ } else {
63
+ this.outputStrategy = setter;
64
+ }
65
+ }
66
+ }
67
+ exports.Asset = Asset;
68
+
69
+ //# sourceMappingURL=Asset.js.map