@webiny/api-page-builder-import-export 0.0.0-unstable.990c3ab1b6 → 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 (274) hide show
  1. package/client.d.ts +2 -2
  2. package/client.js +12 -21
  3. package/client.js.map +1 -1
  4. package/export/combine/blocksHandler.d.ts +6 -0
  5. package/export/combine/blocksHandler.js +101 -0
  6. package/export/combine/blocksHandler.js.map +1 -0
  7. package/export/combine/formsHandler.d.ts +6 -0
  8. package/export/combine/formsHandler.js +101 -0
  9. package/export/combine/formsHandler.js.map +1 -0
  10. package/{exportPages → export}/combine/index.d.ts +4 -3
  11. package/export/combine/index.js +44 -0
  12. package/export/combine/index.js.map +1 -0
  13. package/export/combine/templatesHandler.d.ts +6 -0
  14. package/export/combine/templatesHandler.js +101 -0
  15. package/export/combine/templatesHandler.js.map +1 -0
  16. package/export/pages/ExportPagesCleanup.d.ts +5 -0
  17. package/export/pages/ExportPagesCleanup.js +82 -0
  18. package/export/pages/ExportPagesCleanup.js.map +1 -0
  19. package/export/pages/ExportPagesController.d.ts +5 -0
  20. package/export/pages/ExportPagesController.js +31 -0
  21. package/export/pages/ExportPagesController.js.map +1 -0
  22. package/export/pages/ExportPagesZipPages.d.ts +5 -0
  23. package/export/pages/ExportPagesZipPages.js +23 -0
  24. package/export/pages/ExportPagesZipPages.js.map +1 -0
  25. package/export/pages/controller/CombineZippedPages.d.ts +5 -0
  26. package/export/pages/controller/CombineZippedPages.js +75 -0
  27. package/export/pages/controller/CombineZippedPages.js.map +1 -0
  28. package/export/pages/controller/CreateZipPagesTasks.d.ts +8 -0
  29. package/export/pages/controller/CreateZipPagesTasks.js +103 -0
  30. package/export/pages/controller/CreateZipPagesTasks.js.map +1 -0
  31. package/export/pages/controller/ProcessZipPagesTasks.d.ts +6 -0
  32. package/export/pages/controller/ProcessZipPagesTasks.js +61 -0
  33. package/export/pages/controller/ProcessZipPagesTasks.js.map +1 -0
  34. package/export/pages/types.d.ts +53 -0
  35. package/export/pages/types.js +26 -0
  36. package/export/pages/types.js.map +1 -0
  37. package/export/pages/utils.d.ts +2 -0
  38. package/export/pages/utils.js +13 -0
  39. package/export/pages/utils.js.map +1 -0
  40. package/export/pages/zipPages/ZipPages.d.ts +5 -0
  41. package/export/pages/zipPages/ZipPages.js +100 -0
  42. package/export/pages/zipPages/ZipPages.js.map +1 -0
  43. package/export/pages/zipPages/ZipPagesDataManager.d.ts +14 -0
  44. package/export/pages/zipPages/ZipPagesDataManager.js +46 -0
  45. package/export/pages/zipPages/ZipPagesDataManager.js.map +1 -0
  46. package/export/pages/zipPages/getPageFactory.d.ts +4 -0
  47. package/export/pages/zipPages/getPageFactory.js +38 -0
  48. package/export/pages/zipPages/getPageFactory.js.map +1 -0
  49. package/export/process/blocksHandler.d.ts +6 -0
  50. package/export/process/blocksHandler.js +169 -0
  51. package/export/process/blocksHandler.js.map +1 -0
  52. package/export/process/exporters/BlockExporter.d.ts +12 -0
  53. package/export/process/exporters/BlockExporter.js +57 -0
  54. package/export/process/exporters/BlockExporter.js.map +1 -0
  55. package/export/process/exporters/FormExporter.d.ts +9 -0
  56. package/export/process/exporters/FormExporter.js +36 -0
  57. package/export/process/exporters/FormExporter.js.map +1 -0
  58. package/export/process/exporters/PageExporter.d.ts +18 -0
  59. package/export/process/exporters/PageExporter.js +59 -0
  60. package/export/process/exporters/PageExporter.js.map +1 -0
  61. package/export/process/exporters/PageTemplateExporter.d.ts +11 -0
  62. package/export/process/exporters/PageTemplateExporter.js +58 -0
  63. package/export/process/exporters/PageTemplateExporter.js.map +1 -0
  64. package/export/process/formsHandler.d.ts +6 -0
  65. package/export/process/formsHandler.js +189 -0
  66. package/export/process/formsHandler.js.map +1 -0
  67. package/{exportPages → export}/process/index.d.ts +5 -7
  68. package/export/process/index.js +41 -0
  69. package/export/process/index.js.map +1 -0
  70. package/export/process/templatesHandler.d.ts +6 -0
  71. package/export/process/templatesHandler.js +168 -0
  72. package/export/process/templatesHandler.js.map +1 -0
  73. package/export/s3Stream.d.ts +36 -0
  74. package/{exportPages → export}/s3Stream.js +27 -23
  75. package/export/s3Stream.js.map +1 -0
  76. package/export/utils.d.ts +24 -0
  77. package/export/utils.js +169 -0
  78. package/export/utils.js.map +1 -0
  79. package/{exportPages → export}/zipper.d.ts +12 -10
  80. package/{exportPages → export}/zipper.js +26 -29
  81. package/export/zipper.js.map +1 -0
  82. package/graphql/crud/blocks.crud.d.ts +4 -0
  83. package/graphql/crud/blocks.crud.js +158 -0
  84. package/graphql/crud/blocks.crud.js.map +1 -0
  85. package/graphql/crud/forms.crud.d.ts +4 -0
  86. package/graphql/crud/forms.crud.js +162 -0
  87. package/graphql/crud/forms.crud.js.map +1 -0
  88. package/graphql/crud/importExportTasks.crud.d.ts +5 -0
  89. package/graphql/crud/importExportTasks.crud.js +396 -0
  90. package/graphql/crud/importExportTasks.crud.js.map +1 -0
  91. package/graphql/crud/pages.crud.d.ts +2 -2
  92. package/graphql/crud/pages.crud.js +238 -117
  93. package/graphql/crud/pages.crud.js.map +1 -1
  94. package/graphql/crud/templates.crud.d.ts +4 -0
  95. package/graphql/crud/templates.crud.js +156 -0
  96. package/graphql/crud/templates.crud.js.map +1 -0
  97. package/graphql/crud.d.ts +2 -2
  98. package/graphql/crud.js +8 -3
  99. package/graphql/crud.js.map +1 -1
  100. package/graphql/graphql/blocks.gql.d.ts +4 -0
  101. package/graphql/graphql/blocks.gql.js +52 -0
  102. package/graphql/graphql/blocks.gql.js.map +1 -0
  103. package/graphql/graphql/forms.gql.d.ts +4 -0
  104. package/graphql/graphql/forms.gql.js +60 -0
  105. package/graphql/graphql/forms.gql.js.map +1 -0
  106. package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
  107. package/graphql/graphql/importExportTasks.gql.js +75 -0
  108. package/graphql/graphql/importExportTasks.gql.js.map +1 -0
  109. package/graphql/graphql/pages.gql.d.ts +3 -3
  110. package/graphql/graphql/pages.gql.js +103 -20
  111. package/graphql/graphql/pages.gql.js.map +1 -1
  112. package/graphql/graphql/templates.gql.d.ts +4 -0
  113. package/graphql/graphql/templates.gql.js +52 -0
  114. package/graphql/graphql/templates.gql.js.map +1 -0
  115. package/graphql/graphql/utils/resolve.d.ts +3 -3
  116. package/graphql/graphql/utils/resolve.js +16 -5
  117. package/graphql/graphql/utils/resolve.js.map +1 -1
  118. package/graphql/graphql.d.ts +1 -1
  119. package/graphql/graphql.js +7 -3
  120. package/graphql/graphql.js.map +1 -1
  121. package/graphql/index.d.ts +2 -2
  122. package/graphql/index.js +5 -2
  123. package/graphql/index.js.map +1 -1
  124. package/graphql/types.d.ts +237 -37
  125. package/graphql/types.js +3 -1
  126. package/graphql/types.js.map +1 -1
  127. package/import/constants.d.ts +3 -0
  128. package/import/constants.js +13 -0
  129. package/import/constants.js.map +1 -0
  130. package/import/create/blocksHandler.d.ts +3 -0
  131. package/import/create/blocksHandler.js +101 -0
  132. package/import/create/blocksHandler.js.map +1 -0
  133. package/import/create/formsHandler.d.ts +3 -0
  134. package/import/create/formsHandler.js +105 -0
  135. package/import/create/formsHandler.js.map +1 -0
  136. package/import/create/index.d.ts +24 -0
  137. package/import/create/index.js +44 -0
  138. package/import/create/index.js.map +1 -0
  139. package/import/create/pagesHandler.d.ts +3 -0
  140. package/import/create/pagesHandler.js +105 -0
  141. package/import/create/pagesHandler.js.map +1 -0
  142. package/import/create/templatesHandler.d.ts +3 -0
  143. package/import/create/templatesHandler.js +101 -0
  144. package/import/create/templatesHandler.js.map +1 -0
  145. package/import/pages/ImportPagesController.d.ts +5 -0
  146. package/import/pages/ImportPagesController.js +29 -0
  147. package/import/pages/ImportPagesController.js.map +1 -0
  148. package/import/pages/ImportPagesProcessPages.d.ts +6 -0
  149. package/import/pages/ImportPagesProcessPages.js +112 -0
  150. package/import/pages/ImportPagesProcessPages.js.map +1 -0
  151. package/import/pages/controller/ImportPagesProcessPagesChecker.d.ts +6 -0
  152. package/import/pages/controller/ImportPagesProcessPagesChecker.js +40 -0
  153. package/import/pages/controller/ImportPagesProcessPagesChecker.js.map +1 -0
  154. package/import/pages/controller/ImportPagesProcessZipFile.d.ts +5 -0
  155. package/import/pages/controller/ImportPagesProcessZipFile.js +71 -0
  156. package/import/pages/controller/ImportPagesProcessZipFile.js.map +1 -0
  157. package/import/pages/process/importPage.d.ts +10 -0
  158. package/import/pages/process/importPage.js +94 -0
  159. package/import/pages/process/importPage.js.map +1 -0
  160. package/import/pages/types.d.ts +48 -0
  161. package/import/pages/types.js +20 -0
  162. package/import/pages/types.js.map +1 -0
  163. package/import/process/blocks/ElementIdsProcessor.d.ts +5 -0
  164. package/import/process/blocks/ElementIdsProcessor.js +26 -0
  165. package/import/process/blocks/ElementIdsProcessor.js.map +1 -0
  166. package/import/process/blocks/blocksHandler.d.ts +3 -0
  167. package/import/process/blocks/blocksHandler.js +169 -0
  168. package/import/process/blocks/blocksHandler.js.map +1 -0
  169. package/import/process/blocks/importBlock.d.ts +11 -0
  170. package/import/process/blocks/importBlock.js +101 -0
  171. package/import/process/blocks/importBlock.js.map +1 -0
  172. package/import/process/forms/formsHandler.d.ts +3 -0
  173. package/import/process/forms/formsHandler.js +178 -0
  174. package/import/process/forms/formsHandler.js.map +1 -0
  175. package/import/process/forms/importForm.d.ts +9 -0
  176. package/import/process/forms/importForm.js +47 -0
  177. package/import/process/forms/importForm.js.map +1 -0
  178. package/{importPages → import}/process/index.d.ts +6 -4
  179. package/import/process/index.js +41 -0
  180. package/import/process/index.js.map +1 -0
  181. package/import/process/templates/importTemplate.d.ts +11 -0
  182. package/import/process/templates/importTemplate.js +70 -0
  183. package/import/process/templates/importTemplate.js.map +1 -0
  184. package/import/process/templates/templatesHandler.d.ts +3 -0
  185. package/import/process/templates/templatesHandler.js +174 -0
  186. package/import/process/templates/templatesHandler.js.map +1 -0
  187. package/import/utils/deleteS3Folder.d.ts +1 -0
  188. package/import/utils/deleteS3Folder.js +21 -0
  189. package/import/utils/deleteS3Folder.js.map +1 -0
  190. package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
  191. package/import/utils/extractAndUploadZipFileContents.js +126 -0
  192. package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
  193. package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
  194. package/import/utils/extractZipAndUploadToS3.js +100 -0
  195. package/import/utils/extractZipAndUploadToS3.js.map +1 -0
  196. package/import/utils/getFileNameWithoutExt.d.ts +1 -0
  197. package/import/utils/getFileNameWithoutExt.js +13 -0
  198. package/import/utils/getFileNameWithoutExt.js.map +1 -0
  199. package/import/utils/index.d.ts +9 -0
  200. package/import/utils/index.js +106 -0
  201. package/import/utils/index.js.map +1 -0
  202. package/import/utils/initialStats.d.ts +7 -0
  203. package/import/utils/initialStats.js +18 -0
  204. package/import/utils/initialStats.js.map +1 -0
  205. package/import/utils/prepareDataDirMap.d.ts +6 -0
  206. package/import/utils/prepareDataDirMap.js +31 -0
  207. package/import/utils/prepareDataDirMap.js.map +1 -0
  208. package/import/utils/updateFilesInData.d.ts +8 -0
  209. package/import/utils/updateFilesInData.js +51 -0
  210. package/import/utils/updateFilesInData.js.map +1 -0
  211. package/import/utils/uploadAssets.d.ts +10 -0
  212. package/import/utils/uploadAssets.js +92 -0
  213. package/import/utils/uploadAssets.js.map +1 -0
  214. package/import/utils/uploadFilesFromS3.d.ts +3 -0
  215. package/import/utils/uploadFilesFromS3.js +21 -0
  216. package/import/utils/uploadFilesFromS3.js.map +1 -0
  217. package/mockSecurity.d.ts +1 -1
  218. package/mockSecurity.js +3 -2
  219. package/mockSecurity.js.map +1 -1
  220. package/package.json +36 -52
  221. package/tasks/common/ChildTasksCleanup.d.ts +12 -0
  222. package/tasks/common/ChildTasksCleanup.js +64 -0
  223. package/tasks/common/ChildTasksCleanup.js.map +1 -0
  224. package/tasks/index.d.ts +1 -0
  225. package/tasks/index.js +13 -0
  226. package/tasks/index.js.map +1 -0
  227. package/tasks/pages/exportPagesCleanupTask.d.ts +3 -0
  228. package/tasks/pages/exportPagesCleanupTask.js +36 -0
  229. package/tasks/pages/exportPagesCleanupTask.js.map +1 -0
  230. package/tasks/pages/exportPagesControllerTask.d.ts +3 -0
  231. package/tasks/pages/exportPagesControllerTask.js +83 -0
  232. package/tasks/pages/exportPagesControllerTask.js.map +1 -0
  233. package/tasks/pages/exportPagesZipPagesTask.d.ts +3 -0
  234. package/tasks/pages/exportPagesZipPagesTask.js +39 -0
  235. package/tasks/pages/exportPagesZipPagesTask.js.map +1 -0
  236. package/tasks/pages/importPagesControllerTask.d.ts +3 -0
  237. package/tasks/pages/importPagesControllerTask.js +39 -0
  238. package/tasks/pages/importPagesControllerTask.js.map +1 -0
  239. package/tasks/pages/importPagesProcessPageTask.d.ts +3 -0
  240. package/tasks/pages/importPagesProcessPageTask.js +39 -0
  241. package/tasks/pages/importPagesProcessPageTask.js.map +1 -0
  242. package/tasks/pages/index.d.ts +1 -0
  243. package/tasks/pages/index.js +17 -0
  244. package/tasks/pages/index.js.map +1 -0
  245. package/types.d.ts +83 -65
  246. package/types.js +69 -17
  247. package/types.js.map +1 -1
  248. package/utils/ZipFiles.d.ts +11 -0
  249. package/utils/ZipFiles.js +124 -0
  250. package/utils/ZipFiles.js.map +1 -0
  251. package/exportPages/combine/index.js +0 -106
  252. package/exportPages/combine/index.js.map +0 -1
  253. package/exportPages/process/index.js +0 -192
  254. package/exportPages/process/index.js.map +0 -1
  255. package/exportPages/s3Stream.d.ts +0 -31
  256. package/exportPages/s3Stream.js.map +0 -1
  257. package/exportPages/utils.d.ts +0 -13
  258. package/exportPages/utils.js +0 -100
  259. package/exportPages/utils.js.map +0 -1
  260. package/exportPages/zipper.js.map +0 -1
  261. package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
  262. package/graphql/crud/pageImportExportTasks.crud.js +0 -363
  263. package/graphql/crud/pageImportExportTasks.crud.js.map +0 -1
  264. package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
  265. package/graphql/graphql/pageImportExportTasks.gql.js +0 -75
  266. package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
  267. package/importPages/create/index.d.ts +0 -22
  268. package/importPages/create/index.js +0 -107
  269. package/importPages/create/index.js.map +0 -1
  270. package/importPages/process/index.js +0 -180
  271. package/importPages/process/index.js.map +0 -1
  272. package/importPages/utils.d.ts +0 -50
  273. package/importPages/utils.js +0 -488
  274. package/importPages/utils.js.map +0 -1
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ZipFiles = void 0;
8
+ var _archiver = require("archiver");
9
+ var _clientS = require("@webiny/aws-sdk/client-s3");
10
+ var _path = _interopRequireDefault(require("path"));
11
+ var _stream = require("stream");
12
+ var _libStorage = require("@webiny/aws-sdk/lib-storage");
13
+ var _nodeHttpHandler = require("@smithy/node-http-handler");
14
+ var _https = require("https");
15
+ var _http = require("http");
16
+ class ZipFiles {
17
+ bucket = process.env.S3_BUCKET;
18
+ debug = process.env.DEBUG === "true";
19
+ constructor(options) {
20
+ this.setDebug(options?.debug);
21
+ }
22
+ async process(targetFileName, files) {
23
+ const fileNames = Array.from(files);
24
+ const s3Client = (0, _clientS.createS3)({
25
+ requestHandler: new _nodeHttpHandler.NodeHttpHandler({
26
+ connectionTimeout: 0,
27
+ httpAgent: new _http.Agent({
28
+ maxSockets: 10000,
29
+ keepAlive: true,
30
+ maxFreeSockets: 10000,
31
+ maxTotalSockets: 10000,
32
+ keepAliveMsecs: 900000 // milliseconds / 15 minutes
33
+ }),
34
+ httpsAgent: new _https.Agent({
35
+ maxSockets: 10000,
36
+ keepAlive: true,
37
+ sessionTimeout: 900,
38
+ // seconds / 15 minutes
39
+ maxCachedSessions: 100000,
40
+ maxFreeSockets: 10000,
41
+ maxTotalSockets: 10000,
42
+ keepAliveMsecs: 900000 // milliseconds / 15 minutes
43
+ }),
44
+ requestTimeout: 900000 // milliseconds / 15 minutes
45
+ })
46
+ });
47
+ const streamPassThrough = new _stream.Stream.PassThrough({
48
+ autoDestroy: true
49
+ });
50
+ const upload = new _libStorage.Upload({
51
+ client: s3Client,
52
+ params: {
53
+ ACL: "private",
54
+ Body: streamPassThrough,
55
+ Bucket: this.bucket,
56
+ ContentType: "application/zip",
57
+ Key: targetFileName
58
+ },
59
+ queueSize: 1,
60
+ partSize: 1024 * 1024 * 5,
61
+ leavePartsOnError: false
62
+ });
63
+ const archive = (0, _archiver.create)("zip", {});
64
+ archive.on("error", error => {
65
+ console.error(error);
66
+ throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
67
+ });
68
+ archive.pipe(streamPassThrough);
69
+
70
+ /**
71
+ * To combine all the files into a single zip file, we need to add files one by one.
72
+ *
73
+ * addFileToArchive() method is called every time an entry event is triggered on the archive - it means that file was added into the archive.
74
+ * The method is called manually, first time, to start the process.
75
+ */
76
+
77
+ archive.on("entry", data => {
78
+ this.debug && console.log(`Archived file: ${data.name}`);
79
+ addFileToArchive();
80
+ });
81
+ const addFileToArchive = async () => {
82
+ const file = fileNames.shift();
83
+ if (!file) {
84
+ this.debug && console.log("No more files to add to the archive.");
85
+ /**
86
+ * Must call finalize() with a timeout, otherwise the lambda crashes.
87
+ */
88
+ setTimeout(() => {
89
+ archive.finalize();
90
+ }, 200);
91
+ return;
92
+ }
93
+ this.debug && console.log(`Adding file "${file}" to the archive.`);
94
+ const cmd = new _clientS.GetObjectCommand({
95
+ Bucket: this.bucket,
96
+ Key: file
97
+ });
98
+ const response = await s3Client.send(cmd);
99
+ // Possible to get a null response.Body?
100
+ // Typescript says yes, so let's check it.
101
+ if (!response.Body) {
102
+ this.debug && console.log(`No response.Body for file "${file}", moving to next file.`);
103
+ return addFileToArchive();
104
+ }
105
+ const name = `${_path.default.basename(file)}`;
106
+ archive.append(response.Body, {
107
+ name
108
+ });
109
+ };
110
+ addFileToArchive();
111
+ const result = await upload.done();
112
+ s3Client.destroy();
113
+ return result;
114
+ }
115
+ setDebug(debug) {
116
+ if (debug === undefined) {
117
+ return;
118
+ }
119
+ this.debug = debug;
120
+ }
121
+ }
122
+ exports.ZipFiles = ZipFiles;
123
+
124
+ //# sourceMappingURL=ZipFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_archiver","require","_clientS","_path","_interopRequireDefault","_stream","_libStorage","_nodeHttpHandler","_https","_http","ZipFiles","bucket","process","env","S3_BUCKET","debug","DEBUG","constructor","options","setDebug","targetFileName","files","fileNames","Array","from","s3Client","createS3","requestHandler","NodeHttpHandler","connectionTimeout","httpAgent","HttpAgent","maxSockets","keepAlive","maxFreeSockets","maxTotalSockets","keepAliveMsecs","httpsAgent","HttpsAgent","sessionTimeout","maxCachedSessions","requestTimeout","streamPassThrough","Stream","PassThrough","autoDestroy","upload","Upload","client","params","ACL","Body","Bucket","ContentType","Key","queueSize","partSize","leavePartsOnError","archive","createArchiver","on","error","console","Error","name","code","message","path","stack","pipe","data","log","addFileToArchive","file","shift","setTimeout","finalize","cmd","GetObjectCommand","response","send","basename","append","result","done","destroy","undefined","exports"],"sources":["ZipFiles.ts"],"sourcesContent":["import type { ArchiverError } from \"archiver\";\nimport { create as createArchiver } from \"archiver\";\nimport type { CompleteMultipartUploadOutput } from \"@webiny/aws-sdk/client-s3\";\nimport { createS3, GetObjectCommand } from \"@webiny/aws-sdk/client-s3\";\nimport path from \"path\";\nimport { type Readable, Stream } from \"stream\";\nimport { Upload } from \"@webiny/aws-sdk/lib-storage\";\nimport { NodeHttpHandler } from \"@smithy/node-http-handler\";\nimport { Agent as HttpsAgent } from \"https\";\nimport { Agent as HttpAgent } from \"http\";\n\nexport interface ZipFilesOptions {\n debug?: boolean;\n}\n\nexport class ZipFiles {\n private readonly bucket: string = process.env.S3_BUCKET as string;\n private debug: boolean = process.env.DEBUG === \"true\";\n\n public constructor(options?: ZipFilesOptions) {\n this.setDebug(options?.debug);\n }\n\n public async process(\n targetFileName: string,\n files: string[]\n ): Promise<CompleteMultipartUploadOutput> {\n const fileNames = Array.from(files);\n const s3Client = createS3({\n requestHandler: new NodeHttpHandler({\n connectionTimeout: 0,\n httpAgent: new HttpAgent({\n maxSockets: 10000,\n keepAlive: true,\n maxFreeSockets: 10000,\n maxTotalSockets: 10000,\n keepAliveMsecs: 900000 // milliseconds / 15 minutes\n }),\n httpsAgent: new HttpsAgent({\n maxSockets: 10000,\n keepAlive: true,\n sessionTimeout: 900, // seconds / 15 minutes\n maxCachedSessions: 100000,\n maxFreeSockets: 10000,\n maxTotalSockets: 10000,\n keepAliveMsecs: 900000 // milliseconds / 15 minutes\n }),\n requestTimeout: 900000 // milliseconds / 15 minutes\n })\n });\n\n const streamPassThrough = new Stream.PassThrough({\n autoDestroy: true\n });\n\n const upload = new Upload({\n client: s3Client,\n params: {\n ACL: \"private\",\n Body: streamPassThrough,\n Bucket: this.bucket,\n ContentType: \"application/zip\",\n Key: targetFileName\n },\n queueSize: 1,\n partSize: 1024 * 1024 * 5,\n leavePartsOnError: false\n });\n\n const archive = createArchiver(\"zip\", {});\n\n archive.on(\"error\", (error: ArchiverError) => {\n console.error(error);\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n archive.pipe(streamPassThrough);\n\n /**\n * To combine all the files into a single zip file, we need to add files one by one.\n *\n * addFileToArchive() method is called every time an entry event is triggered on the archive - it means that file was added into the archive.\n * The method is called manually, first time, to start the process.\n */\n\n archive.on(\"entry\", data => {\n this.debug && console.log(`Archived file: ${data.name}`);\n addFileToArchive();\n });\n\n const addFileToArchive = async (): Promise<void> => {\n const file = fileNames.shift();\n if (!file) {\n this.debug && console.log(\"No more files to add to the archive.\");\n /**\n * Must call finalize() with a timeout, otherwise the lambda crashes.\n */\n setTimeout(() => {\n archive.finalize();\n }, 200);\n return;\n }\n this.debug && console.log(`Adding file \"${file}\" to the archive.`);\n const cmd = new GetObjectCommand({\n Bucket: this.bucket,\n Key: file\n });\n\n const response = await s3Client.send(cmd);\n // Possible to get a null response.Body?\n // Typescript says yes, so let's check it.\n if (!response.Body) {\n this.debug &&\n console.log(`No response.Body for file \"${file}\", moving to next file.`);\n return addFileToArchive();\n }\n const name = `${path.basename(file)}`;\n\n archive.append(response.Body as Readable, {\n name\n });\n };\n\n addFileToArchive();\n\n const result = await upload.done();\n\n s3Client.destroy();\n return result;\n }\n\n private setDebug(debug?: boolean): void {\n if (debug === undefined) {\n return;\n }\n this.debug = debug;\n }\n}\n"],"mappings":";;;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,KAAA,GAAAR,OAAA;AAMO,MAAMS,QAAQ,CAAC;EACDC,MAAM,GAAWC,OAAO,CAACC,GAAG,CAACC,SAAS;EAC/CC,KAAK,GAAYH,OAAO,CAACC,GAAG,CAACG,KAAK,KAAK,MAAM;EAE9CC,WAAWA,CAACC,OAAyB,EAAE;IAC1C,IAAI,CAACC,QAAQ,CAACD,OAAO,EAAEH,KAAK,CAAC;EACjC;EAEA,MAAaH,OAAOA,CAChBQ,cAAsB,EACtBC,KAAe,EACuB;IACtC,MAAMC,SAAS,GAAGC,KAAK,CAACC,IAAI,CAACH,KAAK,CAAC;IACnC,MAAMI,QAAQ,GAAG,IAAAC,iBAAQ,EAAC;MACtBC,cAAc,EAAE,IAAIC,gCAAe,CAAC;QAChCC,iBAAiB,EAAE,CAAC;QACpBC,SAAS,EAAE,IAAIC,WAAS,CAAC;UACrBC,UAAU,EAAE,KAAK;UACjBC,SAAS,EAAE,IAAI;UACfC,cAAc,EAAE,KAAK;UACrBC,eAAe,EAAE,KAAK;UACtBC,cAAc,EAAE,MAAM,CAAC;QAC3B,CAAC,CA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CAACsC,IAAI,CAAC,CAAC;IAElC3D,QAAQ,CAAC4D,OAAO,CAAC,CAAC;IAClB,OAAOF,MAAM;EACjB;EAEQhE,QAAQA,CAACJ,KAAe,EAAQ;IACpC,IAAIA,KAAK,KAAKuE,SAAS,EAAE;MACrB;IACJ;IACA,IAAI,CAACvE,KAAK,GAAGA,KAAK;EACtB;AACJ;AAACwE,OAAA,CAAA7E,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -1,106 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _types = require("../../types");
8
- var _s3Stream = require("../s3Stream");
9
- var _zipper = require("../zipper");
10
- var _mockSecurity = require("../../mockSecurity");
11
- var _handlerAws = require("@webiny/handler-aws");
12
- /**
13
- * Handles the export pages combine workflow.
14
- */
15
- var _default = () => {
16
- return (0, _handlerAws.createRawEventHandler)(async ({
17
- payload,
18
- context
19
- }) => {
20
- const log = console.log;
21
- log("RUNNING Export Pages Combine Handler");
22
- const {
23
- pageBuilder
24
- } = context;
25
- const {
26
- taskId,
27
- identity
28
- } = payload;
29
- (0, _mockSecurity.mockSecurity)(identity, context);
30
- try {
31
- const task = await pageBuilder.pageImportExportTask.getTask(taskId);
32
- if (!task) {
33
- return {
34
- data: null,
35
- error: {
36
- message: `There is no task with ID "${taskId}".`
37
- }
38
- };
39
- }
40
- const {
41
- exportPagesDataKey
42
- } = task.input;
43
-
44
- // Get all files (zip) from given key
45
- const listObjectResponse = await _s3Stream.s3Stream.listObject(exportPagesDataKey);
46
- if (!listObjectResponse.Contents) {
47
- return {
48
- data: null,
49
- error: {
50
- message: "There is no Contents defined on S3 Stream while combining pages."
51
- }
52
- };
53
- }
54
- const zipFileKeys = listObjectResponse.Contents.filter(file => file.Key !== exportPagesDataKey).map(file => file.Key).filter(Boolean);
55
-
56
- // Prepare zip of all zips
57
- const zipOfZip = new _zipper.ZipOfZip(zipFileKeys);
58
-
59
- // Upload
60
- const pageExportUpload = await zipOfZip.process();
61
- log(`Done uploading... File is located at ${pageExportUpload.Location} `);
62
-
63
- // Update task status and save export page data key
64
- await pageBuilder.pageImportExportTask.updateTask(taskId, {
65
- status: _types.PageImportExportTaskStatus.COMPLETED,
66
- data: {
67
- message: `Finish uploading page export.`,
68
- key: pageExportUpload.Key,
69
- url: _s3Stream.s3Stream.getPresignedUrl(pageExportUpload.Key)
70
- }
71
- });
72
-
73
- // Remove individual zip files from storage
74
- const deleteFilePromises = zipFileKeys.map(key => _s3Stream.s3Stream.deleteObject(key));
75
- await Promise.all(deleteFilePromises);
76
- log(`Successfully deleted ${deleteFilePromises.length} zip files.`);
77
- } catch (e) {
78
- log("[EXPORT_PAGES_COMBINE] Error => ", e);
79
-
80
- /**
81
- * In case of error, we'll update the task status to "failed",
82
- * so that, client can show notify the user appropriately.
83
- */
84
- await pageBuilder.pageImportExportTask.updateTask(taskId, {
85
- status: _types.PageImportExportTaskStatus.FAILED,
86
- error: {
87
- name: e.name,
88
- message: e.message,
89
- stack: e.stack,
90
- code: "EXPORT_FAILED"
91
- }
92
- });
93
- return {
94
- data: null,
95
- error: {
96
- message: e.message
97
- }
98
- };
99
- }
100
- return {
101
- data: "",
102
- error: null
103
- };
104
- });
105
- };
106
- exports.default = _default;
@@ -1 +0,0 @@
1
- {"version":3,"names":["createRawEventHandler","payload","context","log","console","pageBuilder","taskId","identity","mockSecurity","task","pageImportExportTask","getTask","data","error","message","exportPagesDataKey","input","listObjectResponse","s3Stream","listObject","Contents","zipFileKeys","filter","file","Key","map","Boolean","zipOfZip","ZipOfZip","pageExportUpload","process","Location","updateTask","status","PageImportExportTaskStatus","COMPLETED","key","url","getPresignedUrl","deleteFilePromises","deleteObject","Promise","all","length","e","FAILED","name","stack","code"],"sources":["index.ts"],"sourcesContent":["import { PageImportExportTaskStatus, PbPageImportExportContext } from \"~/types\";\nimport { s3Stream } from \"../s3Stream\";\nimport { ZipOfZip } from \"../zipper\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\n\nexport interface Payload {\n taskId: string;\n identity: SecurityIdentity;\n}\n\nexport interface Response {\n data: string | null;\n error: Partial<Error> | null;\n}\n\n/**\n * Handles the export pages combine workflow.\n */\nexport default () => {\n return createRawEventHandler<Payload, PbPageImportExportContext, Response>(\n async ({ payload, context }) => {\n const log = console.log;\n\n log(\"RUNNING Export Pages Combine Handler\");\n const { pageBuilder } = context;\n const { taskId, identity } = payload;\n\n mockSecurity(identity, context);\n\n try {\n const task = await pageBuilder.pageImportExportTask.getTask(taskId);\n if (!task) {\n return {\n data: null,\n error: {\n message: `There is no task with ID \"${taskId}\".`\n }\n };\n }\n\n const { exportPagesDataKey } = task.input;\n\n // Get all files (zip) from given key\n const listObjectResponse = await s3Stream.listObject(exportPagesDataKey);\n if (!listObjectResponse.Contents) {\n return {\n data: null,\n error: {\n message:\n \"There is no Contents defined on S3 Stream while combining pages.\"\n }\n };\n }\n\n const zipFileKeys = listObjectResponse.Contents.filter(\n file => file.Key !== exportPagesDataKey\n )\n .map(file => file.Key)\n .filter(Boolean) as string[];\n\n // Prepare zip of all zips\n const zipOfZip = new ZipOfZip(zipFileKeys);\n\n // Upload\n const pageExportUpload = await zipOfZip.process();\n log(`Done uploading... File is located at ${pageExportUpload.Location} `);\n\n // Update task status and save export page data key\n await pageBuilder.pageImportExportTask.updateTask(taskId, {\n status: PageImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading page export.`,\n key: pageExportUpload.Key,\n url: s3Stream.getPresignedUrl(pageExportUpload.Key)\n }\n });\n\n // Remove individual zip files from storage\n const deleteFilePromises = zipFileKeys.map(key => s3Stream.deleteObject(key));\n await Promise.all(deleteFilePromises);\n log(`Successfully deleted ${deleteFilePromises.length} zip files.`);\n } catch (e) {\n log(\"[EXPORT_PAGES_COMBINE] Error => \", e);\n\n /**\n * In case of error, we'll update the task status to \"failed\",\n * so that, client can show notify the user appropriately.\n */\n await pageBuilder.pageImportExportTask.updateTask(taskId, {\n status: PageImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n stack: e.stack,\n code: \"EXPORT_FAILED\"\n }\n });\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n }\n return {\n data: \"\",\n error: null\n };\n }\n );\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAEA;AAYA;AACA;AACA;AAFA,eAGe,MAAM;EACjB,OAAO,IAAAA,iCAAqB,EACxB,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IAC5B,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;IAEvBA,GAAG,CAAC,sCAAsC,CAAC;IAC3C,MAAM;MAAEE;IAAY,CAAC,GAAGH,OAAO;IAC/B,MAAM;MAAEI,MAAM;MAAEC;IAAS,CAAC,GAAGN,OAAO;IAEpC,IAAAO,0BAAY,EAACD,QAAQ,EAAEL,OAAO,CAAC;IAE/B,IAAI;MACA,MAAMO,IAAI,GAAG,MAAMJ,WAAW,CAACK,oBAAoB,CAACC,OAAO,CAACL,MAAM,CAAC;MACnE,IAAI,CAACG,IAAI,EAAE;QACP,OAAO;UACHG,IAAI,EAAE,IAAI;UACVC,KAAK,EAAE;YACHC,OAAO,EAAG,6BAA4BR,MAAO;UACjD;QACJ,CAAC;MACL;MAEA,MAAM;QAAES;MAAmB,CAAC,GAAGN,IAAI,CAACO,KAAK;;MAEzC;MACA,MAAMC,kBAAkB,GAAG,MAAMC,kBAAQ,CAACC,UAAU,CAACJ,kBAAkB,CAAC;MACxE,IAAI,CAACE,kBAAkB,CAACG,QAAQ,EAAE;QAC9B,OAAO;UACHR,IAAI,EAAE,IAAI;UACVC,KAAK,EAAE;YACHC,OAAO,EACH;UACR;QACJ,CAAC;MACL;MAEA,MAAMO,WAAW,GAAGJ,kBAAkB,CAACG,QAAQ,CAACE,MAAM,CAClDC,IAAI,IAAIA,IAAI,CAACC,G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QACV;MACJ,CAAC,CAAC;MAEF,OAAO;QACHpC,IAAI,EAAE,IAAI;QACVC,KAAK,EAAE;UACHC,OAAO,EAAE8B,CAAC,CAAC9B;QACf;MACJ,CAAC;IACL;IACA,OAAO;MACHF,IAAI,EAAE,EAAE;MACRC,KAAK,EAAE;IACX,CAAC;EACL,CAAC,CACJ;AACL,CAAC;AAAA"}
@@ -1,192 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _types = require("../../types");
8
- var _client = require("../../client");
9
- var _handlerGraphql = require("@webiny/handler-graphql");
10
- var _utils = require("../utils");
11
- var _mockSecurity = require("../../mockSecurity");
12
- var _utils2 = require("@webiny/utils");
13
- var _handlerAws = require("@webiny/handler-aws");
14
- /**
15
- * Handles the export pages process workflow.
16
- */
17
- var _default = configuration => {
18
- return (0, _handlerAws.createRawEventHandler)(async ({
19
- payload,
20
- context
21
- }) => {
22
- const log = console.log;
23
- let subTask;
24
- let noPendingTask = true;
25
- let prevStatusOfSubTask = _types.PageImportExportTaskStatus.PENDING;
26
- log("RUNNING Export Pages Process Handler");
27
- const {
28
- pageBuilder,
29
- fileManager
30
- } = context;
31
- const {
32
- taskId,
33
- subTaskIndex,
34
- identity
35
- } = payload;
36
- // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks
37
- // and this Lambda is invoked internally, without credentials.
38
- (0, _mockSecurity.mockSecurity)(identity, context);
39
- try {
40
- /*
41
- * Note: We're not going to DB for finding the next sub-task to process,
42
- * because the data might be out of sync due to GSI eventual consistency.
43
- */
44
- subTask = await pageBuilder.pageImportExportTask.getSubTask(taskId, (0, _utils2.zeroPad)(subTaskIndex, 5));
45
- /**
46
- * Base condition!!
47
- * Bail out early, if task not found or task's status is not "pending".
48
- */
49
- if (!subTask || subTask.status !== _types.PageImportExportTaskStatus.PENDING) {
50
- noPendingTask = true;
51
- return {
52
- data: "",
53
- error: null
54
- };
55
- } else {
56
- noPendingTask = false;
57
- }
58
- log(`Fetched sub task => ${subTask.id}`);
59
- const {
60
- input
61
- } = subTask;
62
- const {
63
- pageId,
64
- exportPagesDataKey,
65
- revisionType
66
- } = input;
67
-
68
- /**
69
- * At the moment, we only export a single revision of the page.
70
- * It could be "published" or "latest" depending upon user input.
71
- *
72
- * Note: In case of no "published" revision available, we use the latest revision.
73
- */
74
- let page;
75
- try {
76
- if (revisionType === _types.PageExportRevisionType.PUBLISHED) {
77
- // Get "published" page.
78
- page = await pageBuilder.getPublishedPageById({
79
- id: pageId
80
- });
81
- } else {
82
- // Get "latest" page.
83
- page = await pageBuilder.getPage(pageId);
84
- }
85
- } catch (e) {
86
- // If we're looking for "published" page and doesn't found it, get latest page.
87
- if (revisionType === _types.PageExportRevisionType.PUBLISHED && e instanceof _handlerGraphql.NotFoundError) {
88
- page = await pageBuilder.getPage(pageId);
89
- } else {
90
- throw e;
91
- }
92
- }
93
- if (!page) {
94
- log(`Unable to load page "${pageId}"`);
95
- throw new _handlerGraphql.NotFoundError(`Unable to load page "${pageId}"`);
96
- }
97
- log(`Processing page key "${pageId}" | version ${page.version} | ${page.status}`);
98
-
99
- // Mark task status as PROCESSING
100
- subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
101
- status: _types.PageImportExportTaskStatus.PROCESSING
102
- });
103
- // Update stats in main task
104
- await pageBuilder.pageImportExportTask.updateStats(taskId, {
105
- prevStatus: prevStatusOfSubTask,
106
- nextStatus: _types.PageImportExportTaskStatus.PROCESSING
107
- });
108
- prevStatusOfSubTask = subTask.status;
109
- log(`Extracting page data and uploading to storage...`);
110
- // Extract Page
111
- const pageDataZip = await (0, _utils.exportPage)(page, exportPagesDataKey, fileManager);
112
- log(`Finish uploading zip...`);
113
- // Update task record in DB
114
- subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
115
- status: _types.PageImportExportTaskStatus.COMPLETED,
116
- data: {
117
- message: `Finish uploading data for page "${page.id}" v${page.version} (${page.status}).`,
118
- key: pageDataZip.Key
119
- }
120
- });
121
- // Update stats in main task
122
- await pageBuilder.pageImportExportTask.updateStats(taskId, {
123
- prevStatus: prevStatusOfSubTask,
124
- nextStatus: _types.PageImportExportTaskStatus.COMPLETED
125
- });
126
- prevStatusOfSubTask = subTask.status;
127
- } catch (e) {
128
- log("[EXPORT_PAGES_PROCESS] Error => ", e);
129
- if (subTask && subTask.id) {
130
- /**
131
- * In case of error, we'll update the task status to "failed",
132
- * so that, client can show notify the user appropriately.
133
- */
134
- subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
135
- status: _types.PageImportExportTaskStatus.FAILED,
136
- error: {
137
- name: e.name,
138
- message: e.message,
139
- stack: e.stack,
140
- code: "EXPORT_FAILED"
141
- }
142
- });
143
-
144
- // Update stats in main task
145
- await pageBuilder.pageImportExportTask.updateStats(taskId, {
146
- prevStatus: prevStatusOfSubTask,
147
- nextStatus: _types.PageImportExportTaskStatus.FAILED
148
- });
149
- prevStatusOfSubTask = subTask.status;
150
- }
151
- return {
152
- data: null,
153
- error: {
154
- message: e.message
155
- }
156
- };
157
- } finally {
158
- // Base condition!
159
- if (noPendingTask) {
160
- log(`No pending sub-task for task ${taskId}`);
161
- // Combine individual page zip files.
162
- await (0, _client.invokeHandlerClient)({
163
- context,
164
- name: configuration.handlers.combine,
165
- payload: {
166
- taskId,
167
- identity: context.security.getIdentity()
168
- },
169
- description: "Export pages - combine"
170
- });
171
- } else {
172
- console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`);
173
- // We want to continue with Self invocation no matter if current page error out.
174
- await (0, _client.invokeHandlerClient)({
175
- context,
176
- name: configuration.handlers.process,
177
- payload: {
178
- taskId,
179
- subTaskIndex: subTaskIndex + 1,
180
- identity: context.security.getIdentity()
181
- },
182
- description: "Export pages - process - subtask"
183
- });
184
- }
185
- }
186
- return {
187
- data: "",
188
- error: null
189
- };
190
- });
191
- };
192
- exports.default = _default;
@@ -1 +0,0 @@
1
- {"version":3,"names":["configuration","createRawEventHandler","payload","context","log","console","subTask","noPendingTask","prevStatusOfSubTask","PageImportExportTaskStatus","PENDING","pageBuilder","fileManager","taskId","subTaskIndex","identity","mockSecurity","pageImportExportTask","getSubTask","zeroPad","status","data","error","id","input","pageId","exportPagesDataKey","revisionType","page","PageExportRevisionType","PUBLISHED","getPublishedPageById","getPage","e","NotFoundError","version","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","pageDataZip","exportPage","COMPLETED","message","key","Key","FAILED","name","stack","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process"],"sources":["index.ts"],"sourcesContent":["import {\n PageExportRevisionType,\n PageImportExportTaskStatus,\n PbPageImportExportContext\n} from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { exportPage } from \"~/exportPages/utils\";\nimport { Payload as ExtractPayload } from \"../combine\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\n\ninterface Configuration {\n handlers: {\n process: string;\n combine: string;\n };\n}\n\nexport interface Payload {\n taskId: string;\n subTaskIndex: number;\n identity?: SecurityIdentity;\n}\n\nexport interface Response {\n data: string | null;\n error: Partial<Error> | null;\n}\n\n/**\n * Handles the export pages process workflow.\n */\nexport default (configuration: Configuration) => {\n return createRawEventHandler<Payload, PbPageImportExportContext, Response>(\n async ({ payload, context }) => {\n const log = console.log;\n let subTask;\n let noPendingTask = true;\n let prevStatusOfSubTask = PageImportExportTaskStatus.PENDING;\n\n log(\"RUNNING Export Pages Process Handler\");\n const { pageBuilder, fileManager } = context;\n const { taskId, subTaskIndex, identity } = payload;\n // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks\n // and this Lambda is invoked internally, without credentials.\n mockSecurity(identity as SecurityIdentity, context);\n\n try {\n /*\n * Note: We're not going to DB for finding the next sub-task to process,\n * because the data might be out of sync due to GSI eventual consistency.\n */\n subTask = await pageBuilder.pageImportExportTask.getSubTask(\n taskId,\n zeroPad(subTaskIndex, 5)\n );\n /**\n * Base condition!!\n * Bail out early, if task not found or task's status is not \"pending\".\n */\n if (!subTask || subTask.status !== PageImportExportTaskStatus.PENDING) {\n noPendingTask = true;\n return {\n data: \"\",\n error: null\n };\n } else {\n noPendingTask = false;\n }\n\n log(`Fetched sub task => ${subTask.id}`);\n\n const { input } = subTask;\n const { pageId, exportPagesDataKey, revisionType } = input;\n\n /**\n * At the moment, we only export a single revision of the page.\n * It could be \"published\" or \"latest\" depending upon user input.\n *\n * Note: In case of no \"published\" revision available, we use the latest revision.\n */\n let page;\n try {\n if (revisionType === PageExportRevisionType.PUBLISHED) {\n // Get \"published\" page.\n page = await pageBuilder.getPublishedPageById({ id: pageId });\n } else {\n // Get \"latest\" page.\n page = await pageBuilder.getPage(pageId);\n }\n } catch (e) {\n // If we're looking for \"published\" page and doesn't found it, get latest page.\n if (\n revisionType === PageExportRevisionType.PUBLISHED &&\n e instanceof NotFoundError\n ) {\n page = await pageBuilder.getPage(pageId);\n } else {\n throw e;\n }\n }\n\n if (!page) {\n log(`Unable to load page \"${pageId}\"`);\n throw new NotFoundError(`Unable to load page \"${pageId}\"`);\n }\n\n log(`Processing page key \"${pageId}\" | version ${page.version} | ${page.status}`);\n\n // Mark task status as PROCESSING\n subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {\n status: PageImportExportTaskStatus.PROCESSING\n });\n // Update stats in main task\n await pageBuilder.pageImportExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: PageImportExportTaskStatus.PROCESSING\n });\n prevStatusOfSubTask = subTask.status;\n\n log(`Extracting page data and uploading to storage...`);\n // Extract Page\n const pageDataZip = await exportPage(page, exportPagesDataKey, fileManager);\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {\n status: PageImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for page \"${page.id}\" v${page.version} (${page.status}).`,\n key: pageDataZip.Key\n }\n });\n // Update stats in main task\n await pageBuilder.pageImportExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: PageImportExportTaskStatus.COMPLETED\n });\n prevStatusOfSubTask = subTask.status;\n } catch (e) {\n log(\"[EXPORT_PAGES_PROCESS] Error => \", e);\n\n if (subTask && subTask.id) {\n /**\n * In case of error, we'll update the task status to \"failed\",\n * so that, client can show notify the user appropriately.\n */\n subTask = await pageBuilder.pageImportExportTask.updateSubTask(\n taskId,\n subTask.id,\n {\n status: PageImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n stack: e.stack,\n code: \"EXPORT_FAILED\"\n }\n }\n );\n\n // Update stats in main task\n await pageBuilder.pageImportExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: PageImportExportTaskStatus.FAILED\n });\n prevStatusOfSubTask = subTask.status;\n }\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n } finally {\n // Base condition!\n if (noPendingTask) {\n log(`No pending sub-task for task ${taskId}`);\n // Combine individual page zip files.\n await invokeHandlerClient<ExtractPayload>({\n context,\n name: configuration.handlers.combine,\n payload: {\n taskId,\n identity: context.security.getIdentity()\n },\n description: \"Export pages - combine\"\n });\n } else {\n console.log(`Invoking PROCESS for task \"${subTaskIndex + 1}\"`);\n // We want to continue with Self invocation no matter if current page error out.\n await invokeHandlerClient<Payload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId,\n subTaskIndex: subTaskIndex + 1,\n identity: context.security.getIdentity()\n },\n description: \"Export pages - process - subtask\"\n });\n }\n }\n return {\n data: \"\",\n error: null\n };\n }\n );\n};\n"],"mappings":";;;;;;AAAA;AAKA;AACA;AACA;AAEA;AAEA;AACA;AAoBA;AACA;AACA;AAFA,eAGgBA,aAA4B,IAAK;EAC7C,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CAAC;IACL,CAAC,SAAS;MACN;MACA,IAAIrC,aAAa,EAAE;QACfH,GAAG,CAAE,gCAA+BS,MAAO,EAAC,CAAC;QAC7C;QACA,MAAM,IAAAsC,2BAAmB,EAAiB;UACtChD,OAAO;UACP6C,IAAI,EAAEhD,aAAa,CAACoD,QAAQ,CAACC,OAAO;UACpCnD,OAAO,EAAE;YACLW,MAAM;YACNE,QAAQ,EAAEZ,OAAO,CAACmD,QAAQ,CAACC,WAAW;UAC1C,CAAC;UACDC,WAAW,EAAE;QACjB,CAAC,CAAC;MACN,CAAC,MAAM;QACHnD,OAAO,CAACD,GAAG,CAAE,8BAA6BU,YAAY,GAAG,CAAE,GAAE,CAAC;QAC9D;QACA,MAAM,IAAAqC,2BAAmB,EAAU;UAC/BhD,OAAO;UACP6C,IAAI,EAAEhD,aAAa,CAACoD,QAAQ,CAACK,OAAO;UACpCvD,OAAO,EAAE;YACLW,MAAM;YACNC,YAAY,EAAEA,YAAY,GAAG,CAAC;YAC9BC,QAAQ,EAAEZ,OAAO,CAACmD,QAAQ,CAACC,WAAW;UAC1C,CAAC;UACDC,WAAW,EAAE;QACjB,CAAC,CAAC;MACN;IACJ;IACA,OAAO;MACHnC,IAAI,EAAE,EAAE;MACRC,KAAK,EAAE;IACX,CAAC;EACL,CAAC,CACJ;AACL,CAAC;AAAA"}
@@ -1,31 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { PassThrough, Readable } from "stream";
4
- import S3 from "aws-sdk/clients/s3";
5
- declare class S3Stream {
6
- s3: S3;
7
- bucket: string;
8
- constructor();
9
- getPresignedUrl(key: string): string;
10
- /**
11
- * We're checking if the file is accessible on S3 by getting object meta data.
12
- * It help us to filter files that we need to download as part of export data.
13
- * @param Key {string}
14
- */
15
- isFileAccessible(Key: string): Promise<boolean>;
16
- getObjectHead(Key: string): Promise<S3.HeadObjectOutput>;
17
- readStream(Key: string): Readable;
18
- writeStream(Key: string, contentType?: string): {
19
- streamPassThrough: PassThrough;
20
- streamPassThroughUploadPromise: Promise<S3.ManagedUpload.SendData>;
21
- };
22
- upload(params: {
23
- Key: string;
24
- ContentType: string;
25
- Body: Buffer;
26
- }): Promise<S3.ManagedUpload.SendData>;
27
- listObject(prefix: string): Promise<S3.ListObjectsOutput>;
28
- deleteObject(key: string): Promise<S3.DeleteObjectOutput>;
29
- }
30
- export declare const s3Stream: S3Stream;
31
- export {};
@@ -1 +0,0 @@
1
- {"version":3,"names":["ARCHIVE_CONTENT_TYPE","S3Stream","constructor","s3","S3","region","process","env","AWS_REGION","bucket","S3_BUCKET","getPresignedUrl","key","getSignedUrl","Bucket","Key","Expires","isFileAccessible","getObjectHead","error","console","warn","log","headObject","promise","readStream","getObject","createReadStream","writeStream","contentType","streamPassThrough","Stream","PassThrough","params","ACL","Body","ContentType","streamPassThroughUploadPromise","upload","listObject","prefix","listObjects","Prefix","deleteObject","s3Stream"],"sources":["s3Stream.ts"],"sourcesContent":["import { Stream, PassThrough, Readable } from \"stream\";\nimport S3 from \"aws-sdk/clients/s3\";\n\nconst ARCHIVE_CONTENT_TYPE = \"application/zip\";\n\nclass S3Stream {\n s3: S3;\n bucket: string;\n\n constructor() {\n this.s3 = new S3({\n region: process.env.AWS_REGION as string\n });\n this.bucket = process.env.S3_BUCKET as string;\n }\n\n getPresignedUrl(key: string) {\n return this.s3.getSignedUrl(\"getObject\", {\n Bucket: this.bucket,\n Key: key,\n Expires: 604800 // 1 week\n });\n }\n\n /**\n * We're checking if the file is accessible on S3 by getting object meta data.\n * It help us to filter files that we need to download as part of export data.\n * @param Key {string}\n */\n async isFileAccessible(Key: string): Promise<boolean> {\n try {\n await this.getObjectHead(Key);\n return true;\n } catch (error) {\n console.warn(`Error while fetching meta data for file \"${Key}\"`);\n console.log(error);\n return false;\n }\n }\n\n getObjectHead(Key: string): Promise<S3.HeadObjectOutput> {\n return this.s3.headObject({ Bucket: this.bucket, Key }).promise();\n }\n\n readStream(Key: string): Readable {\n return this.s3.getObject({ Bucket: this.bucket, Key }).createReadStream();\n }\n\n writeStream(\n Key: string,\n contentType: string = ARCHIVE_CONTENT_TYPE\n ): {\n streamPassThrough: PassThrough;\n streamPassThroughUploadPromise: Promise<S3.ManagedUpload.SendData>;\n } {\n const streamPassThrough = new Stream.PassThrough();\n\n const params: S3.PutObjectRequest = {\n ACL: \"private\",\n Body: streamPassThrough,\n Bucket: this.bucket,\n ContentType: contentType,\n Key\n };\n\n return {\n streamPassThrough: streamPassThrough,\n /**\n * We're not using the `FileManager` storage plugin here because it currently doesn't support streams.\n */\n streamPassThroughUploadPromise: this.s3.upload(params).promise()\n };\n }\n\n upload(params: {\n Key: string;\n ContentType: string;\n Body: Buffer;\n }): Promise<S3.ManagedUpload.SendData> {\n return this.s3\n .upload({\n ACL: \"private\",\n Bucket: this.bucket,\n ...params\n })\n .promise();\n }\n\n listObject(prefix: string): Promise<S3.ListObjectsOutput> {\n return this.s3\n .listObjects({\n Bucket: this.bucket,\n Prefix: prefix\n })\n .promise();\n }\n\n deleteObject(key: string): Promise<S3.DeleteObjectOutput> {\n return this.s3.deleteObject({ Key: key, Bucket: this.bucket }).promise();\n }\n}\n\nexport const s3Stream = new S3Stream();\n"],"mappings":";;;;;;;;;AAAA;AACA;AAEA,MAAMA,oBAAoB,GAAG,iBAAiB;AAE9C,MAAMC,QAAQ,CAAC;EAIXC,WAAW,GAAG;IAAA;IAAA;IACV,IAAI,CAACC,EAAE,GAAG,IAAIC,UAAE,CAAC;MACbC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAACC;IACxB,CAAC,CAAC;IACF,IAAI,CAACC,MAAM,GAAGH,OAAO,CAACC,GAAG,CAACG,SAAmB;EACjD;EAEAC,eAAe,CAACC,GAAW,EAAE;IACzB,OAAO,IAAI,CAACT,EAAE,CAACU,YAAY,CAAC,WAAW,EAAE;MACrCC,MAAM,EAAE,IAAI,CAACL,MAAM;MACnBM,GAAG,EAAEH,GAAG;MACRI,OAAO,EAAE,MAAM,CAAC;IACpB,CAAC,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,IAAI,CAACL;IAAM,GAChBwB,MAAM,EACX,CACDT,OAAO,EAAE;EAClB;EAEAe,UAAU,CAACC,MAAc,EAAiC;IACtD,OAAO,IAAI,CAACrC,EAAE,CACTsC,WAAW,CAAC;MACT3B,MAAM,EAAE,IAAI,CAACL,MAAM;MACnBiC,MAAM,EAAEF;IACZ,CAAC,CAAC,CACDhB,OAAO,EAAE;EAClB;EAEAmB,YAAY,CAAC/B,GAAW,EAAkC;IACtD,OAAO,IAAI,CAACT,EAAE,CAACwC,YAAY,CAAC;MAAE5B,GAAG,EAAEH,GAAG;MAAEE,MAAM,EAAE,IAAI,CAACL;IAAO,CAAC,CAAC,CAACe,OAAO,EAAE;EAC5E;AACJ;AAEO,MAAMoB,QAAQ,GAAG,IAAI3C,QAAQ,EAAE;AAAC"}
@@ -1,13 +0,0 @@
1
- import S3 from "aws-sdk/clients/s3";
2
- import { Page, File } from "@webiny/api-page-builder/types";
3
- import { FileManagerContext } from "@webiny/api-file-manager/types";
4
- export declare const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
5
- export interface ExportedPageData {
6
- page: Pick<Page, "content" | "title" | "version" | "status" | "settings" | "path">;
7
- files: ImageFile[];
8
- }
9
- export declare function exportPage(page: Page, exportPagesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<S3.ManagedUpload.SendData>;
10
- export interface ImageFile extends Omit<File, "src"> {
11
- key: string;
12
- }
13
- export declare function extractFilesFromPageData(data: Record<string, any>, files?: any[]): ImageFile[];
@@ -1,100 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.EXPORT_PAGES_FOLDER_KEY = void 0;
8
- exports.exportPage = exportPage;
9
- exports.extractFilesFromPageData = extractFilesFromPageData;
10
- var _get = _interopRequireDefault(require("lodash/get"));
11
- var _s3Stream = require("./s3Stream");
12
- var _zipper = _interopRequireDefault(require("./zipper"));
13
- const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
14
- exports.EXPORT_PAGES_FOLDER_KEY = EXPORT_PAGES_FOLDER_KEY;
15
- async function getFilteredFiles(files) {
16
- const uniqueFileKeys = new Map();
17
- const promises = files.map(file => _s3Stream.s3Stream.isFileAccessible(file.key));
18
- const isFileAvailableResults = await Promise.all(promises);
19
- const filesAvailableForDownload = [];
20
- // Filter files
21
- for (let i = 0; i < files.length; i++) {
22
- const file = files[i];
23
- // Check file accessibility
24
- if (isFileAvailableResults[i] && !uniqueFileKeys.has(file.key)) {
25
- filesAvailableForDownload.push(file);
26
- uniqueFileKeys.set(file.key, true);
27
- }
28
- }
29
- return filesAvailableForDownload;
30
- }
31
- async function exportPage(page, exportPagesDataKey, fileManager) {
32
- // Extract all files
33
- const files = extractFilesFromPageData(page.content || {});
34
- // Filter files
35
- const filesAvailableForDownload = await getFilteredFiles(files);
36
- // Extract images from page settings
37
- const pageSettingsImages = [(0, _get.default)(page, "settings.general.image"), (0, _get.default)(page, "settings.social.image")].filter(image => image && image.src);
38
- const pageSettingsImagesData = [];
39
- // Get file data for all images inside "page.settings"
40
- for (let i = 0; i < pageSettingsImages.length; i++) {
41
- const {
42
- id
43
- } = pageSettingsImages[i];
44
- const file = await fileManager.files.getFile(id);
45
- pageSettingsImagesData.push(file);
46
- }
47
-
48
- // Extract the page data in a json file and upload it to S3
49
- const pageData = {
50
- page: {
51
- content: page.content,
52
- title: page.title,
53
- path: page.path,
54
- version: page.version,
55
- status: page.status,
56
- settings: page.settings
57
- },
58
- files: [...filesAvailableForDownload, ...pageSettingsImagesData]
59
- };
60
- const pageDataBuffer = Buffer.from(JSON.stringify(pageData));
61
- const zipper = new _zipper.default({
62
- exportInfo: {
63
- files: [...filesAvailableForDownload, ...pageSettingsImagesData],
64
- pageTitle: page.title,
65
- pageDataBuffer
66
- },
67
- archiveFileKey: exportPagesDataKey
68
- });
69
- return zipper.process();
70
- }
71
- function extractFilesFromPageData(data, files = []) {
72
- // Base case: termination
73
- if (!data || typeof data !== "object") {
74
- return files;
75
- }
76
- // Recursively call function for each element
77
- if (Array.isArray(data)) {
78
- for (let i = 0; i < data.length; i++) {
79
- const element = data[i];
80
- extractFilesFromPageData(element, files);
81
- }
82
- return files;
83
- }
84
-
85
- // Main
86
- const tuple = Object.entries(data);
87
- for (let i = 0; i < tuple.length; i++) {
88
- const [key, value] = tuple[i];
89
- // TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.
90
- if (key === "file" && value) {
91
- files.push(value);
92
- } else if (key === "images" && Array.isArray(value)) {
93
- // Handle case for "images-list" component
94
- files.push(...value);
95
- } else {
96
- extractFilesFromPageData(value, files);
97
- }
98
- }
99
- return files;
100
- }