@webiny/api-file-manager 6.3.0-beta.4 → 6.4.0-beta.0

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 (250) hide show
  1. package/contants.js +2 -1
  2. package/contants.js.map +1 -1
  3. package/delivery/AssetDelivery/Asset.js +50 -56
  4. package/delivery/AssetDelivery/Asset.js.map +1 -1
  5. package/delivery/AssetDelivery/AssetDeliveryConfig.js +70 -83
  6. package/delivery/AssetDelivery/AssetDeliveryConfig.js.map +1 -1
  7. package/delivery/AssetDelivery/AssetRequest.js +20 -19
  8. package/delivery/AssetDelivery/AssetRequest.js.map +1 -1
  9. package/delivery/AssetDelivery/FilesAssetRequestResolver.js +19 -25
  10. package/delivery/AssetDelivery/FilesAssetRequestResolver.js.map +1 -1
  11. package/delivery/AssetDelivery/NullAssetOutputStrategy.js +5 -4
  12. package/delivery/AssetDelivery/NullAssetOutputStrategy.js.map +1 -1
  13. package/delivery/AssetDelivery/NullAssetReply.js +10 -9
  14. package/delivery/AssetDelivery/NullAssetReply.js.map +1 -1
  15. package/delivery/AssetDelivery/NullAssetResolver.js +5 -4
  16. package/delivery/AssetDelivery/NullAssetResolver.js.map +1 -1
  17. package/delivery/AssetDelivery/NullRequestResolver.js +5 -4
  18. package/delivery/AssetDelivery/NullRequestResolver.js.map +1 -1
  19. package/delivery/AssetDelivery/SetCacheControlHeaders.js +11 -14
  20. package/delivery/AssetDelivery/SetCacheControlHeaders.js.map +1 -1
  21. package/delivery/AssetDelivery/SetResponseHeaders.js +16 -15
  22. package/delivery/AssetDelivery/SetResponseHeaders.js.map +1 -1
  23. package/delivery/AssetDelivery/abstractions/AssetContentsReader.js +0 -3
  24. package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.js +0 -3
  25. package/delivery/AssetDelivery/abstractions/AssetProcessor.js +0 -3
  26. package/delivery/AssetDelivery/abstractions/AssetReply.js +28 -27
  27. package/delivery/AssetDelivery/abstractions/AssetReply.js.map +1 -1
  28. package/delivery/AssetDelivery/abstractions/AssetRequestResolver.js +0 -3
  29. package/delivery/AssetDelivery/abstractions/AssetResolver.js +0 -3
  30. package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.js +0 -3
  31. package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.js +4 -5
  32. package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.js.map +1 -1
  33. package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.js +0 -3
  34. package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js +15 -14
  35. package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js.map +1 -1
  36. package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js +5 -4
  37. package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js.map +1 -1
  38. package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js +14 -16
  39. package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js.map +1 -1
  40. package/delivery/AssetDelivery/privateFiles/PrivateCache.js +18 -17
  41. package/delivery/AssetDelivery/privateFiles/PrivateCache.js.map +1 -1
  42. package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js +21 -25
  43. package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js.map +1 -1
  44. package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js +44 -51
  45. package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js.map +1 -1
  46. package/delivery/AssetDelivery/privateFiles/PublicCache.js +18 -17
  47. package/delivery/AssetDelivery/privateFiles/PublicCache.js.map +1 -1
  48. package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js +16 -15
  49. package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js.map +1 -1
  50. package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js +16 -15
  51. package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js.map +1 -1
  52. package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js +5 -4
  53. package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js.map +1 -1
  54. package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js +5 -4
  55. package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js.map +1 -1
  56. package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js +12 -15
  57. package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js.map +1 -1
  58. package/delivery/index.js +0 -2
  59. package/delivery/setupAssetDelivery.js +70 -101
  60. package/delivery/setupAssetDelivery.js.map +1 -1
  61. package/domain/file/abstractions.js +2 -5
  62. package/domain/file/abstractions.js.map +1 -1
  63. package/domain/file/errors.js +67 -76
  64. package/domain/file/errors.js.map +1 -1
  65. package/domain/file/file.model.js +57 -49
  66. package/domain/file/file.model.js.map +1 -1
  67. package/domain/file/types.js +0 -3
  68. package/domain/identity/Identity.js +9 -8
  69. package/domain/identity/Identity.js.map +1 -1
  70. package/domain/permissionsSchema.js +26 -15
  71. package/domain/permissionsSchema.js.map +1 -1
  72. package/domain/settings/constants.js +2 -1
  73. package/domain/settings/constants.js.map +1 -1
  74. package/domain/settings/errors.js +22 -24
  75. package/domain/settings/errors.js.map +1 -1
  76. package/domain/settings/types.js +0 -3
  77. package/domain/settings/validation.js +18 -27
  78. package/domain/settings/validation.js.map +1 -1
  79. package/exports/api/file-manager/file.js +0 -2
  80. package/exports/api/file-manager/permissions.js +0 -2
  81. package/exports/api/file-manager/settings.js +0 -2
  82. package/features/FileManagerFeature.js +16 -15
  83. package/features/FileManagerFeature.js.map +1 -1
  84. package/features/file/CreateFile/CreateFileRepository.js +20 -18
  85. package/features/file/CreateFile/CreateFileRepository.js.map +1 -1
  86. package/features/file/CreateFile/CreateFileUseCase.js +68 -75
  87. package/features/file/CreateFile/CreateFileUseCase.js.map +1 -1
  88. package/features/file/CreateFile/abstractions.js +3 -14
  89. package/features/file/CreateFile/abstractions.js.map +1 -1
  90. package/features/file/CreateFile/events.js +17 -26
  91. package/features/file/CreateFile/events.js.map +1 -1
  92. package/features/file/CreateFile/feature.js +7 -6
  93. package/features/file/CreateFile/feature.js.map +1 -1
  94. package/features/file/CreateFile/index.js +0 -2
  95. package/features/file/CreateFilesInBatch/CreateFilesInBatchRepository.js +15 -17
  96. package/features/file/CreateFilesInBatch/CreateFilesInBatchRepository.js.map +1 -1
  97. package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js +59 -70
  98. package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js.map +1 -1
  99. package/features/file/CreateFilesInBatch/abstractions.js +3 -14
  100. package/features/file/CreateFilesInBatch/abstractions.js.map +1 -1
  101. package/features/file/CreateFilesInBatch/events.js +17 -26
  102. package/features/file/CreateFilesInBatch/events.js.map +1 -1
  103. package/features/file/CreateFilesInBatch/feature.js +7 -6
  104. package/features/file/CreateFilesInBatch/feature.js.map +1 -1
  105. package/features/file/CreateFilesInBatch/index.js +0 -2
  106. package/features/file/DeleteFile/DeleteFileRepository.js +21 -20
  107. package/features/file/DeleteFile/DeleteFileRepository.js.map +1 -1
  108. package/features/file/DeleteFile/DeleteFileUseCase.js +31 -33
  109. package/features/file/DeleteFile/DeleteFileUseCase.js.map +1 -1
  110. package/features/file/DeleteFile/abstractions.js +3 -14
  111. package/features/file/DeleteFile/abstractions.js.map +1 -1
  112. package/features/file/DeleteFile/events.js +17 -26
  113. package/features/file/DeleteFile/events.js.map +1 -1
  114. package/features/file/DeleteFile/feature.js +7 -6
  115. package/features/file/DeleteFile/feature.js.map +1 -1
  116. package/features/file/DeleteFile/index.js +1 -3
  117. package/features/file/FileUrlGenerator/abstractions.js +2 -2
  118. package/features/file/FileUrlGenerator/abstractions.js.map +1 -1
  119. package/features/file/GetFile/GetFileRepository.js +22 -22
  120. package/features/file/GetFile/GetFileRepository.js.map +1 -1
  121. package/features/file/GetFile/GetFileUseCase.js +19 -21
  122. package/features/file/GetFile/GetFileUseCase.js.map +1 -1
  123. package/features/file/GetFile/abstractions.js +3 -14
  124. package/features/file/GetFile/abstractions.js.map +1 -1
  125. package/features/file/GetFile/feature.js +7 -6
  126. package/features/file/GetFile/feature.js.map +1 -1
  127. package/features/file/GetFile/index.js +0 -2
  128. package/features/file/GetFileContentsById/abstractions.d.ts +20 -0
  129. package/features/file/GetFileContentsById/abstractions.js +5 -0
  130. package/features/file/GetFileContentsById/abstractions.js.map +1 -0
  131. package/features/file/GetFileContentsById/index.d.ts +1 -0
  132. package/features/file/GetFileContentsById/index.js +1 -0
  133. package/features/file/GetFileContentsByKey/abstractions.d.ts +17 -0
  134. package/features/file/GetFileContentsByKey/abstractions.js +5 -0
  135. package/features/file/GetFileContentsByKey/abstractions.js.map +1 -0
  136. package/features/file/GetFileContentsByKey/index.d.ts +1 -0
  137. package/features/file/GetFileContentsByKey/index.js +1 -0
  138. package/features/file/ListFiles/ListFilesRepository.js +42 -40
  139. package/features/file/ListFiles/ListFilesRepository.js.map +1 -1
  140. package/features/file/ListFiles/ListFilesUseCase.js +33 -34
  141. package/features/file/ListFiles/ListFilesUseCase.js.map +1 -1
  142. package/features/file/ListFiles/abstractions.js +3 -14
  143. package/features/file/ListFiles/abstractions.js.map +1 -1
  144. package/features/file/ListFiles/feature.js +7 -6
  145. package/features/file/ListFiles/feature.js.map +1 -1
  146. package/features/file/ListFiles/index.js +0 -2
  147. package/features/file/ListImagesByTagTool/ListImagesByTagTool.js +31 -28
  148. package/features/file/ListImagesByTagTool/ListImagesByTagTool.js.map +1 -1
  149. package/features/file/ListImagesByTagTool/feature.js +6 -5
  150. package/features/file/ListImagesByTagTool/feature.js.map +1 -1
  151. package/features/file/ListTags/ListTagsRepository.js +31 -36
  152. package/features/file/ListTags/ListTagsRepository.js.map +1 -1
  153. package/features/file/ListTags/ListTagsUseCase.js +21 -21
  154. package/features/file/ListTags/ListTagsUseCase.js.map +1 -1
  155. package/features/file/ListTags/abstractions.js +3 -14
  156. package/features/file/ListTags/abstractions.js.map +1 -1
  157. package/features/file/ListTags/feature.js +7 -6
  158. package/features/file/ListTags/feature.js.map +1 -1
  159. package/features/file/ListTags/index.js +0 -2
  160. package/features/file/UpdateFile/UpdateFileRepository.js +26 -28
  161. package/features/file/UpdateFile/UpdateFileRepository.js.map +1 -1
  162. package/features/file/UpdateFile/UpdateFileUseCase.js +57 -65
  163. package/features/file/UpdateFile/UpdateFileUseCase.js.map +1 -1
  164. package/features/file/UpdateFile/abstractions.js +3 -14
  165. package/features/file/UpdateFile/abstractions.js.map +1 -1
  166. package/features/file/UpdateFile/events.js +17 -26
  167. package/features/file/UpdateFile/events.js.map +1 -1
  168. package/features/file/UpdateFile/feature.js +7 -6
  169. package/features/file/UpdateFile/feature.js.map +1 -1
  170. package/features/file/UpdateFile/index.js +1 -3
  171. package/features/file/shared/EntryToFileMapper.js +25 -24
  172. package/features/file/shared/EntryToFileMapper.js.map +1 -1
  173. package/features/file/shared/FileInputToEntryInputMapper.js +29 -28
  174. package/features/file/shared/FileInputToEntryInputMapper.js.map +1 -1
  175. package/features/file/shared/FileToEntryMapper.js +28 -27
  176. package/features/file/shared/FileToEntryMapper.js.map +1 -1
  177. package/features/permissions/abstractions.js +2 -1
  178. package/features/permissions/abstractions.js.map +1 -1
  179. package/features/permissions/feature.js +2 -1
  180. package/features/permissions/feature.js.map +1 -1
  181. package/features/settings/GetSettings/GetSettingsUseCase.js +19 -19
  182. package/features/settings/GetSettings/GetSettingsUseCase.js.map +1 -1
  183. package/features/settings/GetSettings/abstractions.js +2 -7
  184. package/features/settings/GetSettings/abstractions.js.map +1 -1
  185. package/features/settings/GetSettings/feature.js +6 -5
  186. package/features/settings/GetSettings/feature.js.map +1 -1
  187. package/features/settings/SettingsInstaller/SettingsInstaller.js +25 -24
  188. package/features/settings/SettingsInstaller/SettingsInstaller.js.map +1 -1
  189. package/features/settings/SettingsInstaller/feature.js +6 -5
  190. package/features/settings/SettingsInstaller/feature.js.map +1 -1
  191. package/features/settings/UpdateSettings/UpdateSettingsUseCase.js +41 -48
  192. package/features/settings/UpdateSettings/UpdateSettingsUseCase.js.map +1 -1
  193. package/features/settings/UpdateSettings/abstractions.js +2 -7
  194. package/features/settings/UpdateSettings/abstractions.js.map +1 -1
  195. package/features/settings/UpdateSettings/events.js +17 -26
  196. package/features/settings/UpdateSettings/events.js.map +1 -1
  197. package/features/settings/UpdateSettings/feature.js +6 -5
  198. package/features/settings/UpdateSettings/feature.js.map +1 -1
  199. package/features/settings/UpdateSettings/index.js +0 -2
  200. package/features/shared/abstractions.js +0 -2
  201. package/graphql/baseSchema.js +30 -33
  202. package/graphql/baseSchema.js.map +1 -1
  203. package/graphql/createFilesTypeDefs.js +49 -57
  204. package/graphql/createFilesTypeDefs.js.map +1 -1
  205. package/graphql/filesSchema.js +79 -99
  206. package/graphql/filesSchema.js.map +1 -1
  207. package/graphql/getFileByUrl.js +45 -53
  208. package/graphql/getFileByUrl.js.map +1 -1
  209. package/graphql/index.js +35 -42
  210. package/graphql/index.js.map +1 -1
  211. package/graphql/utils.js +9 -14
  212. package/graphql/utils.js.map +1 -1
  213. package/index.js +19 -30
  214. package/index.js.map +1 -1
  215. package/modelModifier/CmsModelModifier.js +40 -43
  216. package/modelModifier/CmsModelModifier.js.map +1 -1
  217. package/package.json +17 -20
  218. package/types.js +0 -2
  219. package/delivery/AssetDelivery/abstractions/AssetContentsReader.js.map +0 -1
  220. package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.js.map +0 -1
  221. package/delivery/AssetDelivery/abstractions/AssetProcessor.js.map +0 -1
  222. package/delivery/AssetDelivery/abstractions/AssetRequestResolver.js.map +0 -1
  223. package/delivery/AssetDelivery/abstractions/AssetResolver.js.map +0 -1
  224. package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.js.map +0 -1
  225. package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.js.map +0 -1
  226. package/delivery/index.js.map +0 -1
  227. package/domain/file/types.js.map +0 -1
  228. package/domain/settings/types.js.map +0 -1
  229. package/exports/api/file-manager/file.js.map +0 -1
  230. package/exports/api/file-manager/permissions.js.map +0 -1
  231. package/exports/api/file-manager/settings.js.map +0 -1
  232. package/features/ai/AiImageEnrichmentAfterCreateHandler.d.ts +0 -11
  233. package/features/ai/AiImageEnrichmentAfterCreateHandler.js +0 -28
  234. package/features/ai/AiImageEnrichmentAfterCreateHandler.js.map +0 -1
  235. package/features/ai/AiImageEnrichmentFeature.d.ts +0 -4
  236. package/features/ai/AiImageEnrichmentFeature.js +0 -12
  237. package/features/ai/AiImageEnrichmentFeature.js.map +0 -1
  238. package/features/file/CreateFile/index.js.map +0 -1
  239. package/features/file/CreateFilesInBatch/index.js.map +0 -1
  240. package/features/file/DeleteFile/index.js.map +0 -1
  241. package/features/file/GetFile/index.js.map +0 -1
  242. package/features/file/ListFiles/index.js.map +0 -1
  243. package/features/file/ListTags/index.js.map +0 -1
  244. package/features/file/UpdateFile/index.js.map +0 -1
  245. package/features/settings/UpdateSettings/index.js.map +0 -1
  246. package/features/shared/abstractions.js.map +0 -1
  247. package/tasks/AiImageEnrichmentTask.d.ts +0 -35
  248. package/tasks/AiImageEnrichmentTask.js +0 -136
  249. package/tasks/AiImageEnrichmentTask.js.map +0 -1
  250. package/types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["SetCacheControlHeaders","constructor","headers","strategy","output","asset","Error","reply","setHeaders","merge"],"sources":["SetCacheControlHeaders.ts"],"sourcesContent":["import type { ResponseHeaders } from \"@webiny/handler\";\nimport type { Asset, AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\n\nexport class SetCacheControlHeaders implements AssetOutputStrategy {\n private readonly strategy: AssetOutputStrategy | undefined;\n private readonly headers: ResponseHeaders;\n\n constructor(headers: ResponseHeaders, strategy: AssetOutputStrategy | undefined) {\n this.headers = headers;\n this.strategy = strategy;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n if (!this.strategy) {\n throw Error(`No asset output strategy is configured!`);\n }\n\n const reply = await this.strategy.output(asset);\n\n reply.setHeaders(headers => {\n return headers.merge(this.headers);\n });\n\n return reply;\n }\n}\n"],"mappings":"AAGA,OAAO,MAAMA,sBAAsB,CAAgC;EAI/DC,WAAWA,CAACC,OAAwB,EAAEC,QAAyC,EAAE;IAC7E,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,MAAMA,CAACC,KAAY,EAAuB;IAC5C,IAAI,CAAC,IAAI,CAACF,QAAQ,EAAE;MAChB,MAAMG,KAAK,CAAC,yCAAyC,CAAC;IAC1D;IAEA,MAAMC,KAAK,GAAG,MAAM,IAAI,CAACJ,QAAQ,CAACC,MAAM,CAACC,KAAK,CAAC;IAE/CE,KAAK,CAACC,UAAU,CAACN,OAAO,IAAI;MACxB,OAAOA,OAAO,CAACO,KAAK,CAAC,IAAI,CAACP,OAAO,CAAC;IACtC,CAAC,CAAC;IAEF,OAAOK,KAAK;EAChB;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"delivery/AssetDelivery/SetCacheControlHeaders.js","sources":["../../../src/delivery/AssetDelivery/SetCacheControlHeaders.ts"],"sourcesContent":["import type { ResponseHeaders } from \"@webiny/handler\";\nimport type { Asset, AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\n\nexport class SetCacheControlHeaders implements AssetOutputStrategy {\n private readonly strategy: AssetOutputStrategy | undefined;\n private readonly headers: ResponseHeaders;\n\n constructor(headers: ResponseHeaders, strategy: AssetOutputStrategy | undefined) {\n this.headers = headers;\n this.strategy = strategy;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n if (!this.strategy) {\n throw Error(`No asset output strategy is configured!`);\n }\n\n const reply = await this.strategy.output(asset);\n\n reply.setHeaders(headers => {\n return headers.merge(this.headers);\n });\n\n return reply;\n }\n}\n"],"names":["SetCacheControlHeaders","headers","strategy","asset","Error","reply"],"mappings":"AAGO,MAAMA;IAIT,YAAYC,OAAwB,EAAEC,QAAyC,CAAE;QAC7E,IAAI,CAAC,OAAO,GAAGD;QACf,IAAI,CAAC,QAAQ,GAAGC;IACpB;IAEA,MAAM,OAAOC,KAAY,EAAuB;QAC5C,IAAI,CAAC,IAAI,CAAC,QAAQ,EACd,MAAMC,MAAM;QAGhB,MAAMC,QAAQ,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAACF;QAEzCE,MAAM,UAAU,CAACJ,CAAAA,UACNA,QAAQ,KAAK,CAAC,IAAI,CAAC,OAAO;QAGrC,OAAOI;IACX;AACJ"}
@@ -1,18 +1,19 @@
1
- export class SetResponseHeaders {
2
- constructor(setter, strategyDecoratorParams) {
3
- this.strategyDecoratorParams = strategyDecoratorParams;
4
- this.setter = setter;
5
- }
6
- async output(asset) {
7
- const reply = await this.strategyDecoratorParams.assetOutputStrategy.output(asset);
8
- await this.setter({
9
- asset: this.strategyDecoratorParams.asset,
10
- assetRequest: this.strategyDecoratorParams.assetRequest,
11
- context: this.strategyDecoratorParams.context,
12
- headers: reply.getHeaders()
13
- });
14
- return reply;
15
- }
1
+ class SetResponseHeaders {
2
+ constructor(setter, strategyDecoratorParams){
3
+ this.strategyDecoratorParams = strategyDecoratorParams;
4
+ this.setter = setter;
5
+ }
6
+ async output(asset) {
7
+ const reply = await this.strategyDecoratorParams.assetOutputStrategy.output(asset);
8
+ await this.setter({
9
+ asset: this.strategyDecoratorParams.asset,
10
+ assetRequest: this.strategyDecoratorParams.assetRequest,
11
+ context: this.strategyDecoratorParams.context,
12
+ headers: reply.getHeaders()
13
+ });
14
+ return reply;
15
+ }
16
16
  }
17
+ export { SetResponseHeaders };
17
18
 
18
19
  //# sourceMappingURL=SetResponseHeaders.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["SetResponseHeaders","constructor","setter","strategyDecoratorParams","output","asset","reply","assetOutputStrategy","assetRequest","context","headers","getHeaders"],"sources":["SetResponseHeaders.ts"],"sourcesContent":["import type {\n AssetOutputStrategy,\n Asset,\n AssetReply,\n AssetRequest,\n AssetOutputStrategyDecoratorParams\n} from \"~/delivery/index.js\";\nimport type { ResponseHeaders } from \"@webiny/handler\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\n\nexport interface ResponseHeadersParams {\n headers: ResponseHeaders;\n context: ApiCoreContext;\n assetRequest: AssetRequest;\n asset: Asset;\n}\n\nexport interface ResponseHeadersSetter {\n (params: ResponseHeadersParams): Promise<void> | void;\n}\n\nexport class SetResponseHeaders implements AssetOutputStrategy {\n private readonly setter: ResponseHeadersSetter;\n private strategyDecoratorParams: AssetOutputStrategyDecoratorParams;\n\n constructor(\n setter: ResponseHeadersSetter,\n strategyDecoratorParams: AssetOutputStrategyDecoratorParams\n ) {\n this.strategyDecoratorParams = strategyDecoratorParams;\n this.setter = setter;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n const reply = await this.strategyDecoratorParams.assetOutputStrategy.output(asset);\n\n await this.setter({\n asset: this.strategyDecoratorParams.asset,\n assetRequest: this.strategyDecoratorParams.assetRequest,\n context: this.strategyDecoratorParams.context,\n headers: reply.getHeaders()\n });\n\n return reply;\n }\n}\n"],"mappings":"AAqBA,OAAO,MAAMA,kBAAkB,CAAgC;EAI3DC,WAAWA,CACPC,MAA6B,EAC7BC,uBAA2D,EAC7D;IACE,IAAI,CAACA,uBAAuB,GAAGA,uBAAuB;IACtD,IAAI,CAACD,MAAM,GAAGA,MAAM;EACxB;EAEA,MAAME,MAAMA,CAACC,KAAY,EAAuB;IAC5C,MAAMC,KAAK,GAAG,MAAM,IAAI,CAACH,uBAAuB,CAACI,mBAAmB,CAACH,MAAM,CAACC,KAAK,CAAC;IAElF,MAAM,IAAI,CAACH,MAAM,CAAC;MACdG,KAAK,EAAE,IAAI,CAACF,uBAAuB,CAACE,KAAK;MACzCG,YAAY,EAAE,IAAI,CAACL,uBAAuB,CAACK,YAAY;MACvDC,OAAO,EAAE,IAAI,CAACN,uBAAuB,CAACM,OAAO;MAC7CC,OAAO,EAAEJ,KAAK,CAACK,UAAU,CAAC;IAC9B,CAAC,CAAC;IAEF,OAAOL,KAAK;EAChB;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"delivery/AssetDelivery/SetResponseHeaders.js","sources":["../../../src/delivery/AssetDelivery/SetResponseHeaders.ts"],"sourcesContent":["import type {\n AssetOutputStrategy,\n Asset,\n AssetReply,\n AssetRequest,\n AssetOutputStrategyDecoratorParams\n} from \"~/delivery/index.js\";\nimport type { ResponseHeaders } from \"@webiny/handler\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\n\nexport interface ResponseHeadersParams {\n headers: ResponseHeaders;\n context: ApiCoreContext;\n assetRequest: AssetRequest;\n asset: Asset;\n}\n\nexport interface ResponseHeadersSetter {\n (params: ResponseHeadersParams): Promise<void> | void;\n}\n\nexport class SetResponseHeaders implements AssetOutputStrategy {\n private readonly setter: ResponseHeadersSetter;\n private strategyDecoratorParams: AssetOutputStrategyDecoratorParams;\n\n constructor(\n setter: ResponseHeadersSetter,\n strategyDecoratorParams: AssetOutputStrategyDecoratorParams\n ) {\n this.strategyDecoratorParams = strategyDecoratorParams;\n this.setter = setter;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n const reply = await this.strategyDecoratorParams.assetOutputStrategy.output(asset);\n\n await this.setter({\n asset: this.strategyDecoratorParams.asset,\n assetRequest: this.strategyDecoratorParams.assetRequest,\n context: this.strategyDecoratorParams.context,\n headers: reply.getHeaders()\n });\n\n return reply;\n }\n}\n"],"names":["SetResponseHeaders","setter","strategyDecoratorParams","asset","reply"],"mappings":"AAqBO,MAAMA;IAIT,YACIC,MAA6B,EAC7BC,uBAA2D,CAC7D;QACE,IAAI,CAAC,uBAAuB,GAAGA;QAC/B,IAAI,CAAC,MAAM,GAAGD;IAClB;IAEA,MAAM,OAAOE,KAAY,EAAuB;QAC5C,MAAMC,QAAQ,MAAM,IAAI,CAAC,uBAAuB,CAAC,mBAAmB,CAAC,MAAM,CAACD;QAE5E,MAAM,IAAI,CAAC,MAAM,CAAC;YACd,OAAO,IAAI,CAAC,uBAAuB,CAAC,KAAK;YACzC,cAAc,IAAI,CAAC,uBAAuB,CAAC,YAAY;YACvD,SAAS,IAAI,CAAC,uBAAuB,CAAC,OAAO;YAC7C,SAASC,MAAM,UAAU;QAC7B;QAEA,OAAOA;IACX;AACJ"}
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=AssetContentsReader.js.map
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=AssetOutputStrategy.js.map
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=AssetProcessor.js.map
@@ -1,31 +1,32 @@
1
1
  import { ResponseHeaders } from "@webiny/handler";
2
- const defaultBody = () => "";
3
- export class AssetReply {
4
- constructor(params = {
5
- code: 200
6
- }) {
7
- this.code = params.code;
8
- this.headers = params.headers || ResponseHeaders.create();
9
- this.body = params.body || defaultBody;
10
- }
11
- setHeaders(cb) {
12
- this.headers = cb(this.headers);
13
- }
14
- getHeaders() {
15
- return this.headers;
16
- }
17
- setCode(code) {
18
- this.code = code;
19
- }
20
- getCode() {
21
- return this.code;
22
- }
23
- setBody(body) {
24
- this.body = body;
25
- }
26
- getBody() {
27
- return this.body();
28
- }
2
+ const defaultBody = ()=>"";
3
+ class AssetReply {
4
+ constructor(params = {
5
+ code: 200
6
+ }){
7
+ this.code = params.code;
8
+ this.headers = params.headers || ResponseHeaders.create();
9
+ this.body = params.body || defaultBody;
10
+ }
11
+ setHeaders(cb) {
12
+ this.headers = cb(this.headers);
13
+ }
14
+ getHeaders() {
15
+ return this.headers;
16
+ }
17
+ setCode(code) {
18
+ this.code = code;
19
+ }
20
+ getCode() {
21
+ return this.code;
22
+ }
23
+ setBody(body) {
24
+ this.body = body;
25
+ }
26
+ getBody() {
27
+ return this.body();
28
+ }
29
29
  }
30
+ export { AssetReply };
30
31
 
31
32
  //# sourceMappingURL=AssetReply.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ResponseHeaders","defaultBody","AssetReply","constructor","params","code","headers","create","body","setHeaders","cb","getHeaders","setCode","getCode","setBody","getBody"],"sources":["AssetReply.ts"],"sourcesContent":["import { ResponseHeaders } from \"@webiny/handler\";\n\ninterface HeadersSetter {\n (headers: ResponseHeaders): ResponseHeaders;\n}\n\ninterface AssetReplyParams {\n code: number;\n headers?: ResponseHeaders;\n body?: AssetReplyBody;\n}\n\ninterface AssetReplyBody {\n (): Promise<unknown> | unknown;\n}\n\nconst defaultBody = () => \"\";\n\nexport class AssetReply {\n private headers: ResponseHeaders;\n private code: number;\n private body: AssetReplyBody;\n\n constructor(params: AssetReplyParams = { code: 200 }) {\n this.code = params.code;\n this.headers = params.headers || ResponseHeaders.create();\n this.body = params.body || defaultBody;\n }\n\n setHeaders(cb: HeadersSetter) {\n this.headers = cb(this.headers);\n }\n\n getHeaders() {\n return this.headers;\n }\n\n setCode(code: number) {\n this.code = code;\n }\n\n getCode() {\n return this.code;\n }\n\n setBody(body: AssetReplyBody) {\n this.body = body;\n }\n\n getBody() {\n return this.body();\n }\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,iBAAiB;AAgBjD,MAAMC,WAAW,GAAGA,CAAA,KAAM,EAAE;AAE5B,OAAO,MAAMC,UAAU,CAAC;EAKpBC,WAAWA,CAACC,MAAwB,GAAG;IAAEC,IAAI,EAAE;EAAI,CAAC,EAAE;IAClD,IAAI,CAACA,IAAI,GAAGD,MAAM,CAACC,IAAI;IACvB,IAAI,CAACC,OAAO,GAAGF,MAAM,CAACE,OAAO,IAAIN,eAAe,CAACO,MAAM,CAAC,CAAC;IACzD,IAAI,CAACC,IAAI,GAAGJ,MAAM,CAACI,IAAI,IAAIP,WAAW;EAC1C;EAEAQ,UAAUA,CAACC,EAAiB,EAAE;IAC1B,IAAI,CAACJ,OAAO,GAAGI,EAAE,CAAC,IAAI,CAACJ,OAAO,CAAC;EACnC;EAEAK,UAAUA,CAAA,EAAG;IACT,OAAO,IAAI,CAACL,OAAO;EACvB;EAEAM,OAAOA,CAACP,IAAY,EAAE;IAClB,IAAI,CAACA,IAAI,GAAGA,IAAI;EACpB;EAEAQ,OAAOA,CAAA,EAAG;IACN,OAAO,IAAI,CAACR,IAAI;EACpB;EAEAS,OAAOA,CAACN,IAAoB,EAAE;IAC1B,IAAI,CAACA,IAAI,GAAGA,IAAI;EACpB;EAEAO,OAAOA,CAAA,EAAG;IACN,OAAO,IAAI,CAACP,IAAI,CAAC,CAAC;EACtB;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"delivery/AssetDelivery/abstractions/AssetReply.js","sources":["../../../../src/delivery/AssetDelivery/abstractions/AssetReply.ts"],"sourcesContent":["import { ResponseHeaders } from \"@webiny/handler\";\n\ninterface HeadersSetter {\n (headers: ResponseHeaders): ResponseHeaders;\n}\n\ninterface AssetReplyParams {\n code: number;\n headers?: ResponseHeaders;\n body?: AssetReplyBody;\n}\n\ninterface AssetReplyBody {\n (): Promise<unknown> | unknown;\n}\n\nconst defaultBody = () => \"\";\n\nexport class AssetReply {\n private headers: ResponseHeaders;\n private code: number;\n private body: AssetReplyBody;\n\n constructor(params: AssetReplyParams = { code: 200 }) {\n this.code = params.code;\n this.headers = params.headers || ResponseHeaders.create();\n this.body = params.body || defaultBody;\n }\n\n setHeaders(cb: HeadersSetter) {\n this.headers = cb(this.headers);\n }\n\n getHeaders() {\n return this.headers;\n }\n\n setCode(code: number) {\n this.code = code;\n }\n\n getCode() {\n return this.code;\n }\n\n setBody(body: AssetReplyBody) {\n this.body = body;\n }\n\n getBody() {\n return this.body();\n }\n}\n"],"names":["defaultBody","AssetReply","params","ResponseHeaders","cb","code","body"],"mappings":";AAgBA,MAAMA,cAAc,IAAM;AAEnB,MAAMC;IAKT,YAAYC,SAA2B;QAAE,MAAM;IAAI,CAAC,CAAE;QAClD,IAAI,CAAC,IAAI,GAAGA,OAAO,IAAI;QACvB,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO,IAAIC,gBAAgB,MAAM;QACvD,IAAI,CAAC,IAAI,GAAGD,OAAO,IAAI,IAAIF;IAC/B;IAEA,WAAWI,EAAiB,EAAE;QAC1B,IAAI,CAAC,OAAO,GAAGA,GAAG,IAAI,CAAC,OAAO;IAClC;IAEA,aAAa;QACT,OAAO,IAAI,CAAC,OAAO;IACvB;IAEA,QAAQC,IAAY,EAAE;QAClB,IAAI,CAAC,IAAI,GAAGA;IAChB;IAEA,UAAU;QACN,OAAO,IAAI,CAAC,IAAI;IACpB;IAEA,QAAQC,IAAoB,EAAE;QAC1B,IAAI,CAAC,IAAI,GAAGA;IAChB;IAEA,UAAU;QACN,OAAO,IAAI,CAAC,IAAI;IACpB;AACJ"}
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=AssetRequestResolver.js.map
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=AssetResolver.js.map
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=AssetTransformationStrategy.js.map
@@ -1,8 +1,7 @@
1
- export const createAssetDeliveryPluginLoader = cb => {
2
- if (process.env.WEBINY_FUNCTION_TYPE === "asset-delivery") {
3
- return () => cb();
4
- }
5
- return () => Promise.resolve([]);
1
+ const createAssetDeliveryPluginLoader = (cb)=>{
2
+ if ("asset-delivery" === process.env.WEBINY_FUNCTION_TYPE) return ()=>cb();
3
+ return ()=>Promise.resolve([]);
6
4
  };
5
+ export { createAssetDeliveryPluginLoader };
7
6
 
8
7
  //# sourceMappingURL=createAssetDeliveryPluginLoader.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createAssetDeliveryPluginLoader","cb","process","env","WEBINY_FUNCTION_TYPE","Promise","resolve"],"sources":["createAssetDeliveryPluginLoader.ts"],"sourcesContent":["import type { PluginFactory } from \"@webiny/plugins/types.js\";\n\nexport const createAssetDeliveryPluginLoader = (cb: PluginFactory): PluginFactory => {\n if (process.env.WEBINY_FUNCTION_TYPE === \"asset-delivery\") {\n return () => cb();\n }\n\n return () => Promise.resolve([]);\n};\n"],"mappings":"AAEA,OAAO,MAAMA,+BAA+B,GAAIC,EAAiB,IAAoB;EACjF,IAAIC,OAAO,CAACC,GAAG,CAACC,oBAAoB,KAAK,gBAAgB,EAAE;IACvD,OAAO,MAAMH,EAAE,CAAC,CAAC;EACrB;EAEA,OAAO,MAAMI,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC;AACpC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"delivery/AssetDelivery/createAssetDeliveryPluginLoader.js","sources":["../../../src/delivery/AssetDelivery/createAssetDeliveryPluginLoader.ts"],"sourcesContent":["import type { PluginFactory } from \"@webiny/plugins/types.js\";\n\nexport const createAssetDeliveryPluginLoader = (cb: PluginFactory): PluginFactory => {\n if (process.env.WEBINY_FUNCTION_TYPE === \"asset-delivery\") {\n return () => cb();\n }\n\n return () => Promise.resolve([]);\n};\n"],"names":["createAssetDeliveryPluginLoader","cb","process","Promise"],"mappings":"AAEO,MAAMA,kCAAkC,CAACC;IAC5C,IAAIC,AAAqC,qBAArCA,QAAQ,GAAG,CAAC,oBAAoB,EAChC,OAAO,IAAMD;IAGjB,OAAO,IAAME,QAAQ,OAAO,CAAC,EAAE;AACnC"}
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=AssetAuthorizer.js.map
@@ -1,19 +1,20 @@
1
1
  import { ResponseHeaders } from "@webiny/handler";
2
2
  import { AssetReply } from "../../index.js";
3
- export class NotAuthorizedAssetReply extends AssetReply {
4
- constructor() {
5
- super({
6
- code: 403,
7
- headers: ResponseHeaders.create({
8
- "cache-control": "no-store",
9
- "content-type": "application/json; charset=utf-8"
10
- }),
11
- body: () => ({
12
- error: "Not authorized!",
13
- code: "NOT_AUTHORIZED"
14
- })
15
- });
16
- }
3
+ class NotAuthorizedAssetReply extends AssetReply {
4
+ constructor(){
5
+ super({
6
+ code: 403,
7
+ headers: ResponseHeaders.create({
8
+ "cache-control": "no-store",
9
+ "content-type": "application/json; charset=utf-8"
10
+ }),
11
+ body: ()=>({
12
+ error: "Not authorized!",
13
+ code: "NOT_AUTHORIZED"
14
+ })
15
+ });
16
+ }
17
17
  }
18
+ export { NotAuthorizedAssetReply };
18
19
 
19
20
  //# sourceMappingURL=NotAuthorizedAssetReply.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ResponseHeaders","AssetReply","NotAuthorizedAssetReply","constructor","code","headers","create","body","error"],"sources":["NotAuthorizedAssetReply.ts"],"sourcesContent":["import { ResponseHeaders } from \"@webiny/handler\";\nimport { AssetReply } from \"~/delivery/index.js\";\n\nexport class NotAuthorizedAssetReply extends AssetReply {\n constructor() {\n super({\n code: 403,\n headers: ResponseHeaders.create({\n \"cache-control\": \"no-store\",\n \"content-type\": \"application/json; charset=utf-8\"\n }),\n body: () => ({ error: \"Not authorized!\", code: \"NOT_AUTHORIZED\" })\n });\n }\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,iBAAiB;AACjD,SAASC,UAAU;AAEnB,OAAO,MAAMC,uBAAuB,SAASD,UAAU,CAAC;EACpDE,WAAWA,CAAA,EAAG;IACV,KAAK,CAAC;MACFC,IAAI,EAAE,GAAG;MACTC,OAAO,EAAEL,eAAe,CAACM,MAAM,CAAC;QAC5B,eAAe,EAAE,UAAU;QAC3B,cAAc,EAAE;MACpB,CAAC,CAAC;MACFC,IAAI,EAAEA,CAAA,MAAO;QAAEC,KAAK,EAAE,iBAAiB;QAAEJ,IAAI,EAAE;MAAiB,CAAC;IACrE,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.ts"],"sourcesContent":["import { ResponseHeaders } from \"@webiny/handler\";\nimport { AssetReply } from \"~/delivery/index.js\";\n\nexport class NotAuthorizedAssetReply extends AssetReply {\n constructor() {\n super({\n code: 403,\n headers: ResponseHeaders.create({\n \"cache-control\": \"no-store\",\n \"content-type\": \"application/json; charset=utf-8\"\n }),\n body: () => ({ error: \"Not authorized!\", code: \"NOT_AUTHORIZED\" })\n });\n }\n}\n"],"names":["NotAuthorizedAssetReply","AssetReply","ResponseHeaders"],"mappings":";;AAGO,MAAMA,gCAAgCC;IACzC,aAAc;QACV,KAAK,CAAC;YACF,MAAM;YACN,SAASC,gBAAgB,MAAM,CAAC;gBAC5B,iBAAiB;gBACjB,gBAAgB;YACpB;YACA,MAAM,IAAO;oBAAE,OAAO;oBAAmB,MAAM;gBAAiB;QACpE;IACJ;AACJ"}
@@ -1,8 +1,9 @@
1
1
  import { NotAuthorizedAssetReply } from "./NotAuthorizedAssetReply.js";
2
- export class NotAuthorizedOutputStrategy {
3
- async output() {
4
- return new NotAuthorizedAssetReply();
5
- }
2
+ class NotAuthorizedOutputStrategy {
3
+ async output() {
4
+ return new NotAuthorizedAssetReply();
5
+ }
6
6
  }
7
+ export { NotAuthorizedOutputStrategy };
7
8
 
8
9
  //# sourceMappingURL=NotAuthorizedOutputStrategy.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NotAuthorizedAssetReply","NotAuthorizedOutputStrategy","output"],"sources":["NotAuthorizedOutputStrategy.ts"],"sourcesContent":["import type { AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\nimport { NotAuthorizedAssetReply } from \"./NotAuthorizedAssetReply.js\";\n\nexport class NotAuthorizedOutputStrategy implements AssetOutputStrategy {\n async output(): Promise<AssetReply> {\n return new NotAuthorizedAssetReply();\n }\n}\n"],"mappings":"AACA,SAASA,uBAAuB;AAEhC,OAAO,MAAMC,2BAA2B,CAAgC;EACpE,MAAMC,MAAMA,CAAA,EAAwB;IAChC,OAAO,IAAIF,uBAAuB,CAAC,CAAC;EACxC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.ts"],"sourcesContent":["import type { AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\nimport { NotAuthorizedAssetReply } from \"./NotAuthorizedAssetReply.js\";\n\nexport class NotAuthorizedOutputStrategy implements AssetOutputStrategy {\n async output(): Promise<AssetReply> {\n return new NotAuthorizedAssetReply();\n }\n}\n"],"names":["NotAuthorizedOutputStrategy","NotAuthorizedAssetReply"],"mappings":";AAGO,MAAMA;IACT,MAAM,SAA8B;QAChC,OAAO,IAAIC;IACf;AACJ"}
@@ -1,20 +1,18 @@
1
- import Error from "@webiny/error";
2
- export class PrivateAuthenticatedAuthorizer {
3
- constructor(context) {
4
- this.context = context;
5
- }
6
- async authorize(file) {
7
- if (file.accessControl && file.accessControl.type === "private-authenticated") {
8
- // Make sure there's a valid identity!
9
- const identity = this.context.security.getIdentity();
10
- if (!identity) {
11
- throw new Error({
12
- code: "NOT_AUTHORIZED",
13
- message: "You're not authorized to access this asset!"
14
- });
15
- }
1
+ import error from "@webiny/error";
2
+ class PrivateAuthenticatedAuthorizer {
3
+ constructor(context){
4
+ this.context = context;
5
+ }
6
+ async authorize(file) {
7
+ if (file.accessControl && "private-authenticated" === file.accessControl.type) {
8
+ const identity = this.context.security.getIdentity();
9
+ if (!identity) throw new error({
10
+ code: "NOT_AUTHORIZED",
11
+ message: "You're not authorized to access this asset!"
12
+ });
13
+ }
16
14
  }
17
- }
18
15
  }
16
+ export { PrivateAuthenticatedAuthorizer };
19
17
 
20
18
  //# sourceMappingURL=PrivateAuthenticatedAuthorizer.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Error","PrivateAuthenticatedAuthorizer","constructor","context","authorize","file","accessControl","type","identity","security","getIdentity","code","message"],"sources":["PrivateAuthenticatedAuthorizer.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport type { File } from \"~/domain/file/types.js\";\nimport type { AssetAuthorizer } from \"./AssetAuthorizer.js\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\n\nexport class PrivateAuthenticatedAuthorizer implements AssetAuthorizer {\n private context: ApiCoreContext;\n\n constructor(context: ApiCoreContext) {\n this.context = context;\n }\n\n async authorize(file: File) {\n if (file.accessControl && file.accessControl.type === \"private-authenticated\") {\n // Make sure there's a valid identity!\n const identity = this.context.security.getIdentity();\n\n if (!identity) {\n throw new Error({\n code: \"NOT_AUTHORIZED\",\n message: \"You're not authorized to access this asset!\"\n });\n }\n }\n }\n}\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,eAAe;AAKjC,OAAO,MAAMC,8BAA8B,CAA4B;EAGnEC,WAAWA,CAACC,OAAuB,EAAE;IACjC,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMC,SAASA,CAACC,IAAU,EAAE;IACxB,IAAIA,IAAI,CAACC,aAAa,IAAID,IAAI,CAACC,aAAa,CAACC,IAAI,KAAK,uBAAuB,EAAE;MAC3E;MACA,MAAMC,QAAQ,GAAG,IAAI,CAACL,OAAO,CAACM,QAAQ,CAACC,WAAW,CAAC,CAAC;MAEpD,IAAI,CAACF,QAAQ,EAAE;QACX,MAAM,IAAIR,KAAK,CAAC;UACZW,IAAI,EAAE,gBAAgB;UACtBC,OAAO,EAAE;QACb,CAAC,CAAC;MACN;IACJ;EACJ;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport type { File } from \"~/domain/file/types.js\";\nimport type { AssetAuthorizer } from \"./AssetAuthorizer.js\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\n\nexport class PrivateAuthenticatedAuthorizer implements AssetAuthorizer {\n private context: ApiCoreContext;\n\n constructor(context: ApiCoreContext) {\n this.context = context;\n }\n\n async authorize(file: File) {\n if (file.accessControl && file.accessControl.type === \"private-authenticated\") {\n // Make sure there's a valid identity!\n const identity = this.context.security.getIdentity();\n\n if (!identity) {\n throw new Error({\n code: \"NOT_AUTHORIZED\",\n message: \"You're not authorized to access this asset!\"\n });\n }\n }\n }\n}\n"],"names":["PrivateAuthenticatedAuthorizer","context","file","identity","Error"],"mappings":";AAKO,MAAMA;IAGT,YAAYC,OAAuB,CAAE;QACjC,IAAI,CAAC,OAAO,GAAGA;IACnB;IAEA,MAAM,UAAUC,IAAU,EAAE;QACxB,IAAIA,KAAK,aAAa,IAAIA,AAA4B,4BAA5BA,KAAK,aAAa,CAAC,IAAI,EAA8B;YAE3E,MAAMC,WAAW,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW;YAElD,IAAI,CAACA,UACD,MAAM,IAAIC,MAAM;gBACZ,MAAM;gBACN,SAAS;YACb;QAER;IACJ;AACJ"}
@@ -1,21 +1,22 @@
1
1
  import { parse, stringify } from "cache-control-parser";
2
- export class PrivateCache {
3
- constructor(strategy) {
4
- this.strategy = strategy;
5
- }
6
- async output(asset) {
7
- const reply = await this.strategy.output(asset);
8
- reply.setHeaders(headers => {
9
- headers.set("cache-control", (value = "") => {
10
- const cacheControl = parse(value);
11
- cacheControl["private"] = true;
12
- cacheControl["public"] = false;
13
- return stringify(cacheControl);
14
- });
15
- return headers;
16
- });
17
- return reply;
18
- }
2
+ class PrivateCache {
3
+ constructor(strategy){
4
+ this.strategy = strategy;
5
+ }
6
+ async output(asset) {
7
+ const reply = await this.strategy.output(asset);
8
+ reply.setHeaders((headers)=>{
9
+ headers.set("cache-control", (value = "")=>{
10
+ const cacheControl = parse(value);
11
+ cacheControl["private"] = true;
12
+ cacheControl["public"] = false;
13
+ return stringify(cacheControl);
14
+ });
15
+ return headers;
16
+ });
17
+ return reply;
18
+ }
19
19
  }
20
+ export { PrivateCache };
20
21
 
21
22
  //# sourceMappingURL=PrivateCache.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["parse","stringify","PrivateCache","constructor","strategy","output","asset","reply","setHeaders","headers","set","value","cacheControl"],"sources":["PrivateCache.ts"],"sourcesContent":["import { parse, stringify } from \"cache-control-parser\";\nimport type { Asset, AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\n\nexport class PrivateCache implements AssetOutputStrategy {\n private strategy: AssetOutputStrategy;\n\n constructor(strategy: AssetOutputStrategy) {\n this.strategy = strategy;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n const reply = await this.strategy.output(asset);\n\n reply.setHeaders(headers => {\n headers.set(\"cache-control\", (value = \"\") => {\n const cacheControl = parse(value);\n cacheControl[\"private\"] = true;\n cacheControl[\"public\"] = false;\n return stringify(cacheControl);\n });\n return headers;\n });\n\n return reply;\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,SAAS,QAAQ,sBAAsB;AAGvD,OAAO,MAAMC,YAAY,CAAgC;EAGrDC,WAAWA,CAACC,QAA6B,EAAE;IACvC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,MAAMA,CAACC,KAAY,EAAuB;IAC5C,MAAMC,KAAK,GAAG,MAAM,IAAI,CAACH,QAAQ,CAACC,MAAM,CAACC,KAAK,CAAC;IAE/CC,KAAK,CAACC,UAAU,CAACC,OAAO,IAAI;MACxBA,OAAO,CAACC,GAAG,CAAC,eAAe,EAAE,CAACC,KAAK,GAAG,EAAE,KAAK;QACzC,MAAMC,YAAY,GAAGZ,KAAK,CAACW,KAAK,CAAC;QACjCC,YAAY,CAAC,SAAS,CAAC,GAAG,IAAI;QAC9BA,YAAY,CAAC,QAAQ,CAAC,GAAG,KAAK;QAC9B,OAAOX,SAAS,CAACW,YAAY,CAAC;MAClC,CAAC,CAAC;MACF,OAAOH,OAAO;IAClB,CAAC,CAAC;IAEF,OAAOF,KAAK;EAChB;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"delivery/AssetDelivery/privateFiles/PrivateCache.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PrivateCache.ts"],"sourcesContent":["import { parse, stringify } from \"cache-control-parser\";\nimport type { Asset, AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\n\nexport class PrivateCache implements AssetOutputStrategy {\n private strategy: AssetOutputStrategy;\n\n constructor(strategy: AssetOutputStrategy) {\n this.strategy = strategy;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n const reply = await this.strategy.output(asset);\n\n reply.setHeaders(headers => {\n headers.set(\"cache-control\", (value = \"\") => {\n const cacheControl = parse(value);\n cacheControl[\"private\"] = true;\n cacheControl[\"public\"] = false;\n return stringify(cacheControl);\n });\n return headers;\n });\n\n return reply;\n }\n}\n"],"names":["PrivateCache","strategy","asset","reply","headers","value","cacheControl","parse","stringify"],"mappings":";AAGO,MAAMA;IAGT,YAAYC,QAA6B,CAAE;QACvC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,OAAOC,KAAY,EAAuB;QAC5C,MAAMC,QAAQ,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAACD;QAEzCC,MAAM,UAAU,CAACC,CAAAA;YACbA,QAAQ,GAAG,CAAC,iBAAiB,CAACC,QAAQ,EAAE;gBACpC,MAAMC,eAAeC,MAAMF;gBAC3BC,YAAY,CAAC,UAAU,GAAG;gBAC1BA,YAAY,CAAC,SAAS,GAAG;gBACzB,OAAOE,UAAUF;YACrB;YACA,OAAOF;QACX;QAEA,OAAOD;IACX;AACJ"}
@@ -1,30 +1,26 @@
1
1
  import { AssetRequest } from "../../index.js";
2
- export class PrivateFileAssetRequestResolver {
3
- constructor(resolver) {
4
- this.resolver = resolver;
5
- }
6
- async resolve(request) {
7
- // Example: /private/65722cb5c7824a0008d05963/image-48.jpg?width=300
8
- if (!request.url.startsWith("/private/")) {
9
- return this.resolver.resolve(request);
2
+ class PrivateFileAssetRequestResolver {
3
+ constructor(resolver){
4
+ this.resolver = resolver;
5
+ }
6
+ async resolve(request) {
7
+ if (!request.url.startsWith("/private/")) return this.resolver.resolve(request);
8
+ const params = request.params ?? {};
9
+ const query = request.query ?? {};
10
+ const path = params["*"];
11
+ return new AssetRequest({
12
+ key: decodeURI(path).replace("/private/", ""),
13
+ context: {
14
+ url: request.url,
15
+ private: true
16
+ },
17
+ options: {
18
+ ...query,
19
+ width: query.width ? parseInt(query.width) : void 0
20
+ }
21
+ });
10
22
  }
11
- const params = request.params ?? {};
12
- const query = request.query ?? {};
13
-
14
- // Example: { '*': '/private/65722cb5c7824a0008d05963/image-48.jpg' },
15
- const path = params["*"];
16
- return new AssetRequest({
17
- key: decodeURI(path).replace("/private/", ""),
18
- context: {
19
- url: request.url,
20
- private: true
21
- },
22
- options: {
23
- ...query,
24
- width: query.width ? parseInt(query.width) : undefined
25
- }
26
- });
27
- }
28
23
  }
24
+ export { PrivateFileAssetRequestResolver };
29
25
 
30
26
  //# sourceMappingURL=PrivateFileAssetRequestResolver.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["AssetRequest","PrivateFileAssetRequestResolver","constructor","resolver","resolve","request","url","startsWith","params","query","path","key","decodeURI","replace","context","private","options","width","parseInt","undefined"],"sources":["PrivateFileAssetRequestResolver.ts"],"sourcesContent":["import type { AssetRequestResolver } from \"~/delivery/index.js\";\nimport { AssetRequest } from \"~/delivery/index.js\";\nimport type { Request } from \"@webiny/handler/types.js\";\n\nexport class PrivateFileAssetRequestResolver implements AssetRequestResolver {\n private readonly resolver: AssetRequestResolver;\n\n constructor(resolver: AssetRequestResolver) {\n this.resolver = resolver;\n }\n\n async resolve(request: Request): Promise<AssetRequest | undefined> {\n // Example: /private/65722cb5c7824a0008d05963/image-48.jpg?width=300\n if (!request.url.startsWith(\"/private/\")) {\n return this.resolver.resolve(request);\n }\n\n const params = (request.params ?? {}) as Record<string, any>;\n const query = (request.query ?? {}) as Record<string, any>;\n\n // Example: { '*': '/private/65722cb5c7824a0008d05963/image-48.jpg' },\n const path = params[\"*\"];\n\n return new AssetRequest({\n key: decodeURI(path).replace(\"/private/\", \"\"),\n context: {\n url: request.url,\n private: true\n },\n options: {\n ...query,\n width: query.width ? parseInt(query.width) : undefined\n }\n });\n }\n}\n"],"mappings":"AACA,SAASA,YAAY;AAGrB,OAAO,MAAMC,+BAA+B,CAAiC;EAGzEC,WAAWA,CAACC,QAA8B,EAAE;IACxC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,OAAgB,EAAqC;IAC/D;IACA,IAAI,CAACA,OAAO,CAACC,GAAG,CAACC,UAAU,CAAC,WAAW,CAAC,EAAE;MACtC,OAAO,IAAI,CAACJ,QAAQ,CAACC,OAAO,CAACC,OAAO,CAAC;IACzC;IAEA,MAAMG,MAAM,GAAIH,OAAO,CAACG,MAAM,IAAI,CAAC,CAAyB;IAC5D,MAAMC,KAAK,GAAIJ,OAAO,CAACI,KAAK,IAAI,CAAC,CAAyB;;IAE1D;IACA,MAAMC,IAAI,GAAGF,MAAM,CAAC,GAAG,CAAC;IAExB,OAAO,IAAIR,YAAY,CAAC;MACpBW,GAAG,EAAEC,SAAS,CAACF,IAAI,CAAC,CAACG,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;MAC7CC,OAAO,EAAE;QACLR,GAAG,EAAED,OAAO,CAACC,GAAG;QAChBS,OAAO,EAAE;MACb,CAAC;MACDC,OAAO,EAAE;QACL,GAAGP,KAAK;QACRQ,KAAK,EAAER,KAAK,CAACQ,KAAK,GAAGC,QAAQ,CAACT,KAAK,CAACQ,KAAK,CAAC,GAAGE;MACjD;IACJ,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.ts"],"sourcesContent":["import type { AssetRequestResolver } from \"~/delivery/index.js\";\nimport { AssetRequest } from \"~/delivery/index.js\";\nimport type { Request } from \"@webiny/handler/types.js\";\n\nexport class PrivateFileAssetRequestResolver implements AssetRequestResolver {\n private readonly resolver: AssetRequestResolver;\n\n constructor(resolver: AssetRequestResolver) {\n this.resolver = resolver;\n }\n\n async resolve(request: Request): Promise<AssetRequest | undefined> {\n // Example: /private/65722cb5c7824a0008d05963/image-48.jpg?width=300\n if (!request.url.startsWith(\"/private/\")) {\n return this.resolver.resolve(request);\n }\n\n const params = (request.params ?? {}) as Record<string, any>;\n const query = (request.query ?? {}) as Record<string, any>;\n\n // Example: { '*': '/private/65722cb5c7824a0008d05963/image-48.jpg' },\n const path = params[\"*\"];\n\n return new AssetRequest({\n key: decodeURI(path).replace(\"/private/\", \"\"),\n context: {\n url: request.url,\n private: true\n },\n options: {\n ...query,\n width: query.width ? parseInt(query.width) : undefined\n }\n });\n }\n}\n"],"names":["PrivateFileAssetRequestResolver","resolver","request","params","query","path","AssetRequest","decodeURI","parseInt","undefined"],"mappings":";AAIO,MAAMA;IAGT,YAAYC,QAA8B,CAAE;QACxC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,QAAQC,OAAgB,EAAqC;QAE/D,IAAI,CAACA,QAAQ,GAAG,CAAC,UAAU,CAAC,cACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAACA;QAGjC,MAAMC,SAAUD,QAAQ,MAAM,IAAI,CAAC;QACnC,MAAME,QAASF,QAAQ,KAAK,IAAI,CAAC;QAGjC,MAAMG,OAAOF,MAAM,CAAC,IAAI;QAExB,OAAO,IAAIG,aAAa;YACpB,KAAKC,UAAUF,MAAM,OAAO,CAAC,aAAa;YAC1C,SAAS;gBACL,KAAKH,QAAQ,GAAG;gBAChB,SAAS;YACb;YACA,SAAS;gBACL,GAAGE,KAAK;gBACR,OAAOA,MAAM,KAAK,GAAGI,SAASJ,MAAM,KAAK,IAAIK;YACjD;QACJ;IACJ;AACJ"}
@@ -4,60 +4,53 @@ import { RedirectToPrivateUrlOutputStrategy } from "./RedirectToPrivateUrlOutput
4
4
  import { PrivateCache } from "./PrivateCache.js";
5
5
  import { PublicCache } from "./PublicCache.js";
6
6
  import { GetFileUseCase } from "../../../features/file/GetFile/index.js";
7
- export class PrivateFilesAssetProcessor {
8
- constructor(context, assetAuthorizer, assetProcessor) {
9
- this.assetAuthorizer = assetAuthorizer;
10
- this.context = context;
11
- this.assetProcessor = assetProcessor;
12
- }
13
- async process(assetRequest, asset) {
14
- const id = asset.getId();
15
- const {
16
- security
17
- } = this.context;
18
- const getFile = this.context.container.resolve(GetFileUseCase);
19
-
20
- // Get file from File Manager by `id`.
21
- const file = await security.withoutAuthorization(async () => {
22
- const fileResult = await getFile.execute(id);
23
- if (fileResult.isFail()) {
24
- throw fileResult.error;
25
- }
26
- return fileResult.value;
27
- });
28
- const isPrivateFile = this.isPrivate(file);
29
- if (!isPrivateFile && this.requestedViaPrivateEndpoint(assetRequest)) {
30
- asset.setOutputStrategy(new RedirectToPublicUrlOutputStrategy(assetRequest));
31
- return asset;
7
+ class PrivateFilesAssetProcessor {
8
+ constructor(context, assetAuthorizer, assetProcessor){
9
+ this.assetAuthorizer = assetAuthorizer;
10
+ this.context = context;
11
+ this.assetProcessor = assetProcessor;
12
+ }
13
+ async process(assetRequest, asset) {
14
+ const id = asset.getId();
15
+ const { security } = this.context;
16
+ const getFile = this.context.container.resolve(GetFileUseCase);
17
+ const file = await security.withoutAuthorization(async ()=>{
18
+ const fileResult = await getFile.execute(id);
19
+ if (fileResult.isFail()) throw fileResult.error;
20
+ return fileResult.value;
21
+ });
22
+ const isPrivateFile = this.isPrivate(file);
23
+ if (!isPrivateFile && this.requestedViaPrivateEndpoint(assetRequest)) {
24
+ asset.setOutputStrategy(new RedirectToPublicUrlOutputStrategy(assetRequest));
25
+ return asset;
26
+ }
27
+ if (isPrivateFile && this.requestedViaPublicEndpoint(assetRequest)) {
28
+ asset.setOutputStrategy(new RedirectToPrivateUrlOutputStrategy(assetRequest));
29
+ return asset;
30
+ }
31
+ try {
32
+ await this.assetAuthorizer.authorize(file);
33
+ } catch {
34
+ asset.setOutputStrategy(new NotAuthorizedOutputStrategy());
35
+ return asset;
36
+ }
37
+ const processedAsset = await this.assetProcessor.process(assetRequest, asset);
38
+ processedAsset.setOutputStrategy((strategy)=>{
39
+ if (!strategy) throw Error("No asset output strategy is configured!");
40
+ return isPrivateFile ? new PrivateCache(strategy) : new PublicCache(strategy);
41
+ });
42
+ return processedAsset;
43
+ }
44
+ isPrivate(file) {
45
+ return file.accessControl && file.accessControl.type.startsWith("private-");
32
46
  }
33
- if (isPrivateFile && this.requestedViaPublicEndpoint(assetRequest)) {
34
- asset.setOutputStrategy(new RedirectToPrivateUrlOutputStrategy(assetRequest));
35
- return asset;
47
+ requestedViaPrivateEndpoint(assetRequest) {
48
+ return assetRequest.getContext().private;
36
49
  }
37
- try {
38
- await this.assetAuthorizer.authorize(file);
39
- } catch {
40
- asset.setOutputStrategy(new NotAuthorizedOutputStrategy());
41
- return asset;
50
+ requestedViaPublicEndpoint(assetRequest) {
51
+ return !this.requestedViaPrivateEndpoint(assetRequest);
42
52
  }
43
- const processedAsset = await this.assetProcessor.process(assetRequest, asset);
44
- processedAsset.setOutputStrategy(strategy => {
45
- if (!strategy) {
46
- throw Error(`No asset output strategy is configured!`);
47
- }
48
- return isPrivateFile ? new PrivateCache(strategy) : new PublicCache(strategy);
49
- });
50
- return processedAsset;
51
- }
52
- isPrivate(file) {
53
- return file.accessControl && file.accessControl.type.startsWith("private-");
54
- }
55
- requestedViaPrivateEndpoint(assetRequest) {
56
- return assetRequest.getContext().private;
57
- }
58
- requestedViaPublicEndpoint(assetRequest) {
59
- return !this.requestedViaPrivateEndpoint(assetRequest);
60
- }
61
53
  }
54
+ export { PrivateFilesAssetProcessor };
62
55
 
63
56
  //# sourceMappingURL=PrivateFilesAssetProcessor.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NotAuthorizedOutputStrategy","RedirectToPublicUrlOutputStrategy","RedirectToPrivateUrlOutputStrategy","PrivateCache","PublicCache","GetFileUseCase","PrivateFilesAssetProcessor","constructor","context","assetAuthorizer","assetProcessor","process","assetRequest","asset","id","getId","security","getFile","container","resolve","file","withoutAuthorization","fileResult","execute","isFail","error","value","isPrivateFile","isPrivate","requestedViaPrivateEndpoint","setOutputStrategy","requestedViaPublicEndpoint","authorize","processedAsset","strategy","Error","accessControl","type","startsWith","getContext","private"],"sources":["PrivateFilesAssetProcessor.ts"],"sourcesContent":["import type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport type { File } from \"~/domain/file/types.js\";\nimport type { Asset, AssetProcessor, AssetRequest } from \"~/delivery/index.js\";\nimport type { AssetAuthorizer } from \"./AssetAuthorizer.js\";\nimport { NotAuthorizedOutputStrategy } from \"./NotAuthorizedOutputStrategy.js\";\nimport { RedirectToPublicUrlOutputStrategy } from \"./RedirectToPublicUrlOutputStrategy.js\";\nimport { RedirectToPrivateUrlOutputStrategy } from \"./RedirectToPrivateUrlOutputStrategy.js\";\nimport { PrivateCache } from \"./PrivateCache.js\";\nimport { PublicCache } from \"./PublicCache.js\";\nimport { GetFileUseCase } from \"~/features/file/GetFile/index.js\";\n\ninterface MaybePrivate {\n private?: boolean;\n}\n\nexport class PrivateFilesAssetProcessor implements AssetProcessor {\n private readonly context: ApiCoreContext;\n private assetProcessor: AssetProcessor;\n private assetAuthorizer: AssetAuthorizer;\n\n constructor(\n context: ApiCoreContext,\n assetAuthorizer: AssetAuthorizer,\n assetProcessor: AssetProcessor\n ) {\n this.assetAuthorizer = assetAuthorizer;\n this.context = context;\n this.assetProcessor = assetProcessor;\n }\n\n async process(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n const id = asset.getId();\n const { security } = this.context;\n const getFile = this.context.container.resolve(GetFileUseCase);\n\n // Get file from File Manager by `id`.\n const file = await security.withoutAuthorization(async () => {\n const fileResult = await getFile.execute(id);\n if (fileResult.isFail()) {\n throw fileResult.error;\n }\n return fileResult.value;\n });\n\n const isPrivateFile = this.isPrivate(file);\n\n if (!isPrivateFile && this.requestedViaPrivateEndpoint(assetRequest)) {\n asset.setOutputStrategy(new RedirectToPublicUrlOutputStrategy(assetRequest));\n return asset;\n }\n\n if (isPrivateFile && this.requestedViaPublicEndpoint(assetRequest)) {\n asset.setOutputStrategy(new RedirectToPrivateUrlOutputStrategy(assetRequest));\n return asset;\n }\n\n try {\n await this.assetAuthorizer.authorize(file);\n } catch {\n asset.setOutputStrategy(new NotAuthorizedOutputStrategy());\n\n return asset;\n }\n\n const processedAsset = await this.assetProcessor.process(assetRequest, asset);\n\n processedAsset.setOutputStrategy(strategy => {\n if (!strategy) {\n throw Error(`No asset output strategy is configured!`);\n }\n return isPrivateFile ? new PrivateCache(strategy) : new PublicCache(strategy);\n });\n\n return processedAsset;\n }\n\n private isPrivate(file: File) {\n return file.accessControl && file.accessControl.type.startsWith(\"private-\");\n }\n\n private requestedViaPrivateEndpoint(assetRequest: AssetRequest) {\n return assetRequest.getContext<MaybePrivate>().private;\n }\n\n private requestedViaPublicEndpoint(assetRequest: AssetRequest) {\n return !this.requestedViaPrivateEndpoint(assetRequest);\n }\n}\n"],"mappings":"AAIA,SAASA,2BAA2B;AACpC,SAASC,iCAAiC;AAC1C,SAASC,kCAAkC;AAC3C,SAASC,YAAY;AACrB,SAASC,WAAW;AACpB,SAASC,cAAc;AAMvB,OAAO,MAAMC,0BAA0B,CAA2B;EAK9DC,WAAWA,CACPC,OAAuB,EACvBC,eAAgC,EAChCC,cAA8B,EAChC;IACE,IAAI,CAACD,eAAe,GAAGA,eAAe;IACtC,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACE,cAAc,GAAGA,cAAc;EACxC;EAEA,MAAMC,OAAOA,CAACC,YAA0B,EAAEC,KAAY,EAAkB;IACpE,MAAMC,EAAE,GAAGD,KAAK,CAACE,KAAK,CAAC,CAAC;IACxB,MAAM;MAAEC;IAAS,CAAC,GAAG,IAAI,CAACR,OAAO;IACjC,MAAMS,OAAO,GAAG,IAAI,CAACT,OAAO,CAACU,SAAS,CAACC,OAAO,CAACd,cAAc,CAAC;;IAE9D;IACA,MAAMe,IAAI,GAAG,MAAMJ,QAAQ,CAACK,oBAAoB,CAAC,YAAY;MACzD,MAAMC,UAAU,GAAG,MAAML,OAAO,CAACM,OAAO,CAACT,EAAE,CAAC;MAC5C,IAAIQ,UAAU,CAACE,MAAM,CAAC,CAAC,EAAE;QACrB,MAAMF,UAAU,CAACG,KAAK;MAC1B;MACA,OAAOH,UAAU,CAACI,KAAK;IAC3B,CAAC,CAAC;IAEF,MAAMC,aAAa,GAAG,IAAI,CAACC,SAAS,CAACR,IAAI,CAAC;IAE1C,IAAI,CAACO,aAAa,IAAI,IAAI,CAACE,2BAA2B,CAACjB,YAAY,CAAC,EAAE;MAClEC,KAAK,CAACiB,iBAAiB,CAAC,IAAI7B,iCAAiC,CAACW,YAAY,CAAC,CAAC;MAC5E,OAAOC,KAAK;IAChB;IAEA,IAAIc,aAAa,IAAI,IAAI,CAACI,0BAA0B,CAACnB,YAAY,CAAC,EAAE;MAChEC,KAAK,CAACiB,iBAAiB,CAAC,IAAI5B,kCAAkC,CAACU,YAAY,CAAC,CAAC;MAC7E,OAAOC,KAAK;IAChB;IAEA,IAAI;MACA,MAAM,IAAI,CAACJ,eAAe,CAACuB,SAAS,CAACZ,IAAI,CAAC;IAC9C,CAAC,CAAC,MAAM;MACJP,KAAK,CAACiB,iBAAiB,CAAC,IAAI9B,2BAA2B,CAAC,CAAC,CAAC;MAE1D,OAAOa,KAAK;IAChB;IAEA,MAAMoB,cAAc,GAAG,MAAM,IAAI,CAACvB,cAAc,CAACC,OAAO,CAACC,YAAY,EAAEC,KAAK,CAAC;IAE7EoB,cAAc,CAACH,iBAAiB,CAACI,QAAQ,IAAI;MACzC,IAAI,CAACA,QAAQ,EAAE;QACX,MAAMC,KAAK,CAAC,yCAAyC,CAAC;MAC1D;MACA,OAAOR,aAAa,GAAG,IAAIxB,YAAY,CAAC+B,QAAQ,CAAC,GAAG,IAAI9B,WAAW,CAAC8B,QAAQ,CAAC;IACjF,CAAC,CAAC;IAEF,OAAOD,cAAc;EACzB;EAEQL,SAASA,CAACR,IAAU,EAAE;IAC1B,OAAOA,IAAI,CAACgB,aAAa,IAAIhB,IAAI,CAACgB,aAAa,CAACC,IAAI,CAACC,UAAU,CAAC,UAAU,CAAC;EAC/E;EAEQT,2BAA2BA,CAACjB,YAA0B,EAAE;IAC5D,OAAOA,YAAY,CAAC2B,UAAU,CAAe,CAAC,CAACC,OAAO;EAC1D;EAEQT,0BAA0BA,CAACnB,YAA0B,EAAE;IAC3D,OAAO,CAAC,IAAI,CAACiB,2BAA2B,CAACjB,YAAY,CAAC;EAC1D;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.ts"],"sourcesContent":["import type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport type { File } from \"~/domain/file/types.js\";\nimport type { Asset, AssetProcessor, AssetRequest } from \"~/delivery/index.js\";\nimport type { AssetAuthorizer } from \"./AssetAuthorizer.js\";\nimport { NotAuthorizedOutputStrategy } from \"./NotAuthorizedOutputStrategy.js\";\nimport { RedirectToPublicUrlOutputStrategy } from \"./RedirectToPublicUrlOutputStrategy.js\";\nimport { RedirectToPrivateUrlOutputStrategy } from \"./RedirectToPrivateUrlOutputStrategy.js\";\nimport { PrivateCache } from \"./PrivateCache.js\";\nimport { PublicCache } from \"./PublicCache.js\";\nimport { GetFileUseCase } from \"~/features/file/GetFile/index.js\";\n\ninterface MaybePrivate {\n private?: boolean;\n}\n\nexport class PrivateFilesAssetProcessor implements AssetProcessor {\n private readonly context: ApiCoreContext;\n private assetProcessor: AssetProcessor;\n private assetAuthorizer: AssetAuthorizer;\n\n constructor(\n context: ApiCoreContext,\n assetAuthorizer: AssetAuthorizer,\n assetProcessor: AssetProcessor\n ) {\n this.assetAuthorizer = assetAuthorizer;\n this.context = context;\n this.assetProcessor = assetProcessor;\n }\n\n async process(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n const id = asset.getId();\n const { security } = this.context;\n const getFile = this.context.container.resolve(GetFileUseCase);\n\n // Get file from File Manager by `id`.\n const file = await security.withoutAuthorization(async () => {\n const fileResult = await getFile.execute(id);\n if (fileResult.isFail()) {\n throw fileResult.error;\n }\n return fileResult.value;\n });\n\n const isPrivateFile = this.isPrivate(file);\n\n if (!isPrivateFile && this.requestedViaPrivateEndpoint(assetRequest)) {\n asset.setOutputStrategy(new RedirectToPublicUrlOutputStrategy(assetRequest));\n return asset;\n }\n\n if (isPrivateFile && this.requestedViaPublicEndpoint(assetRequest)) {\n asset.setOutputStrategy(new RedirectToPrivateUrlOutputStrategy(assetRequest));\n return asset;\n }\n\n try {\n await this.assetAuthorizer.authorize(file);\n } catch {\n asset.setOutputStrategy(new NotAuthorizedOutputStrategy());\n\n return asset;\n }\n\n const processedAsset = await this.assetProcessor.process(assetRequest, asset);\n\n processedAsset.setOutputStrategy(strategy => {\n if (!strategy) {\n throw Error(`No asset output strategy is configured!`);\n }\n return isPrivateFile ? new PrivateCache(strategy) : new PublicCache(strategy);\n });\n\n return processedAsset;\n }\n\n private isPrivate(file: File) {\n return file.accessControl && file.accessControl.type.startsWith(\"private-\");\n }\n\n private requestedViaPrivateEndpoint(assetRequest: AssetRequest) {\n return assetRequest.getContext<MaybePrivate>().private;\n }\n\n private requestedViaPublicEndpoint(assetRequest: AssetRequest) {\n return !this.requestedViaPrivateEndpoint(assetRequest);\n }\n}\n"],"names":["PrivateFilesAssetProcessor","context","assetAuthorizer","assetProcessor","assetRequest","asset","id","security","getFile","GetFileUseCase","file","fileResult","isPrivateFile","RedirectToPublicUrlOutputStrategy","RedirectToPrivateUrlOutputStrategy","NotAuthorizedOutputStrategy","processedAsset","strategy","Error","PrivateCache","PublicCache"],"mappings":";;;;;;AAeO,MAAMA;IAKT,YACIC,OAAuB,EACvBC,eAAgC,EAChCC,cAA8B,CAChC;QACE,IAAI,CAAC,eAAe,GAAGD;QACvB,IAAI,CAAC,OAAO,GAAGD;QACf,IAAI,CAAC,cAAc,GAAGE;IAC1B;IAEA,MAAM,QAAQC,YAA0B,EAAEC,KAAY,EAAkB;QACpE,MAAMC,KAAKD,MAAM,KAAK;QACtB,MAAM,EAAEE,QAAQ,EAAE,GAAG,IAAI,CAAC,OAAO;QACjC,MAAMC,UAAU,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAACC;QAG/C,MAAMC,OAAO,MAAMH,SAAS,oBAAoB,CAAC;YAC7C,MAAMI,aAAa,MAAMH,QAAQ,OAAO,CAACF;YACzC,IAAIK,WAAW,MAAM,IACjB,MAAMA,WAAW,KAAK;YAE1B,OAAOA,WAAW,KAAK;QAC3B;QAEA,MAAMC,gBAAgB,IAAI,CAAC,SAAS,CAACF;QAErC,IAAI,CAACE,iBAAiB,IAAI,CAAC,2BAA2B,CAACR,eAAe;YAClEC,MAAM,iBAAiB,CAAC,IAAIQ,kCAAkCT;YAC9D,OAAOC;QACX;QAEA,IAAIO,iBAAiB,IAAI,CAAC,0BAA0B,CAACR,eAAe;YAChEC,MAAM,iBAAiB,CAAC,IAAIS,mCAAmCV;YAC/D,OAAOC;QACX;QAEA,IAAI;YACA,MAAM,IAAI,CAAC,eAAe,CAAC,SAAS,CAACK;QACzC,EAAE,OAAM;YACJL,MAAM,iBAAiB,CAAC,IAAIU;YAE5B,OAAOV;QACX;QAEA,MAAMW,iBAAiB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACZ,cAAcC;QAEvEW,eAAe,iBAAiB,CAACC,CAAAA;YAC7B,IAAI,CAACA,UACD,MAAMC,MAAM;YAEhB,OAAON,gBAAgB,IAAIO,aAAaF,YAAY,IAAIG,YAAYH;QACxE;QAEA,OAAOD;IACX;IAEQ,UAAUN,IAAU,EAAE;QAC1B,OAAOA,KAAK,aAAa,IAAIA,KAAK,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC;IACpE;IAEQ,4BAA4BN,YAA0B,EAAE;QAC5D,OAAOA,aAAa,UAAU,GAAiB,OAAO;IAC1D;IAEQ,2BAA2BA,YAA0B,EAAE;QAC3D,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAACA;IAC7C;AACJ"}