@webiny/api-page-builder-import-export 0.0.0-unstable.7f63ea0744 → 0.0.0-unstable.8b6c57b569

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 (261) hide show
  1. package/client.d.ts +1 -1
  2. package/client.js +12 -21
  3. package/client.js.map +1 -1
  4. package/export/combine/blocksHandler.d.ts +2 -2
  5. package/export/combine/blocksHandler.js +4 -2
  6. package/export/combine/blocksHandler.js.map +1 -1
  7. package/export/combine/formsHandler.d.ts +6 -0
  8. package/export/combine/{pagesHandler.js → formsHandler.js} +19 -17
  9. package/export/combine/formsHandler.js.map +1 -0
  10. package/export/combine/index.d.ts +2 -2
  11. package/export/combine/index.js +25 -16
  12. package/export/combine/index.js.map +1 -1
  13. package/export/combine/templatesHandler.d.ts +2 -2
  14. package/export/combine/templatesHandler.js +4 -2
  15. package/export/combine/templatesHandler.js.map +1 -1
  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 +2 -2
  50. package/export/process/blocksHandler.js +13 -6
  51. package/export/process/blocksHandler.js.map +1 -1
  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/{pagesHandler.js → formsHandler.js} +36 -36
  66. package/export/process/formsHandler.js.map +1 -0
  67. package/export/process/index.d.ts +2 -2
  68. package/export/process/index.js +25 -16
  69. package/export/process/index.js.map +1 -1
  70. package/export/process/templatesHandler.d.ts +2 -2
  71. package/export/process/templatesHandler.js +13 -7
  72. package/export/process/templatesHandler.js.map +1 -1
  73. package/export/s3Stream.d.ts +16 -11
  74. package/export/s3Stream.js +27 -23
  75. package/export/s3Stream.js.map +1 -1
  76. package/export/utils.d.ts +11 -9
  77. package/export/utils.js +36 -24
  78. package/export/utils.js.map +1 -1
  79. package/export/zipper.d.ts +7 -6
  80. package/export/zipper.js +20 -24
  81. package/export/zipper.js.map +1 -1
  82. package/graphql/crud/blocks.crud.d.ts +1 -1
  83. package/graphql/crud/blocks.crud.js +50 -29
  84. package/graphql/crud/blocks.crud.js.map +1 -1
  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 +2 -2
  89. package/graphql/crud/importExportTasks.crud.js +144 -111
  90. package/graphql/crud/importExportTasks.crud.js.map +1 -1
  91. package/graphql/crud/pages.crud.d.ts +1 -1
  92. package/graphql/crud/pages.crud.js +238 -121
  93. package/graphql/crud/pages.crud.js.map +1 -1
  94. package/graphql/crud/templates.crud.d.ts +1 -1
  95. package/graphql/crud/templates.crud.js +48 -16
  96. package/graphql/crud/templates.crud.js.map +1 -1
  97. package/graphql/crud.d.ts +2 -2
  98. package/graphql/crud.js +5 -2
  99. package/graphql/crud.js.map +1 -1
  100. package/graphql/graphql/blocks.gql.d.ts +2 -2
  101. package/graphql/graphql/blocks.gql.js +7 -7
  102. package/graphql/graphql/blocks.gql.js.map +1 -1
  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 +2 -2
  107. package/graphql/graphql/importExportTasks.gql.js +7 -7
  108. package/graphql/graphql/importExportTasks.gql.js.map +1 -1
  109. package/graphql/graphql/pages.gql.d.ts +2 -2
  110. package/graphql/graphql/pages.gql.js +103 -14
  111. package/graphql/graphql/pages.gql.js.map +1 -1
  112. package/graphql/graphql/templates.gql.d.ts +2 -2
  113. package/graphql/graphql/templates.gql.js +6 -6
  114. package/graphql/graphql/templates.gql.js.map +1 -1
  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 +4 -2
  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 +194 -31
  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 +2 -2
  131. package/import/create/blocksHandler.js +7 -6
  132. package/import/create/blocksHandler.js.map +1 -1
  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 +2 -2
  137. package/import/create/index.js +25 -16
  138. package/import/create/index.js.map +1 -1
  139. package/import/create/pagesHandler.d.ts +2 -2
  140. package/import/create/pagesHandler.js +6 -3
  141. package/import/create/pagesHandler.js.map +1 -1
  142. package/import/create/templatesHandler.d.ts +2 -2
  143. package/import/create/templatesHandler.js +5 -2
  144. package/import/create/templatesHandler.js.map +1 -1
  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/{blocksHandler.d.ts → blocks/blocksHandler.d.ts} +2 -2
  167. package/import/process/{blocksHandler.js → blocks/blocksHandler.js} +13 -13
  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/{pagesHandler.js → forms/formsHandler.js} +39 -38
  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/import/process/index.d.ts +2 -2
  179. package/import/process/index.js +27 -18
  180. package/import/process/index.js.map +1 -1
  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/{templatesHandler.d.ts → templates/templatesHandler.d.ts} +2 -2
  185. package/import/process/{templatesHandler.js → templates/templatesHandler.js} +17 -9
  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 +37 -53
  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 +23 -2
  246. package/types.js +60 -8
  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/export/combine/pagesHandler.d.ts +0 -6
  252. package/export/combine/pagesHandler.js.map +0 -1
  253. package/export/process/pagesHandler.d.ts +0 -6
  254. package/export/process/pagesHandler.js.map +0 -1
  255. package/import/process/blocksHandler.js.map +0 -1
  256. package/import/process/pagesHandler.d.ts +0 -3
  257. package/import/process/pagesHandler.js.map +0 -1
  258. package/import/process/templatesHandler.js.map +0 -1
  259. package/import/utils.d.ts +0 -56
  260. package/import/utils.js +0 -607
  261. package/import/utils.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_types","require","_client","_handlerGraphql","_mockSecurity","_utils","_FormExporter","formsHandler","configuration","payload","context","log","console","subTask","noPendingTask","prevStatusOfSubTask","ImportExportTaskStatus","PENDING","formBuilder","pageBuilder","taskId","subTaskIndex","type","identity","mockSecurity","importExportTask","getSubTask","zeroPad","status","data","error","id","input","formId","exportFormsDataKey","revisionType","form","ExportRevisionType","PUBLISHED","getLatestPublishedFormRevision","getForm","e","NotFoundError","version","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","formExporter","FormExporter","formDataZip","execute","COMPLETED","message","key","Key","FAILED","name","stack","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process","exports"],"sources":["formsHandler.ts"],"sourcesContent":["import type { PbImportExportContext } from \"~/types\";\nimport { ExportRevisionType, ImportExportTaskStatus } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport type { Payload as ExtractPayload } from \"../combine\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport type { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { zeroPad } from \"@webiny/utils\";\nimport type { Configuration, Payload, Response } from \"~/export/process\";\nimport { FormExporter } from \"./exporters/FormExporter\";\n\n/**\n * Handles the export forms process workflow.\n */\nexport const formsHandler = async (\n configuration: Configuration,\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n let subTask;\n let noPendingTask = true;\n let prevStatusOfSubTask = ImportExportTaskStatus.PENDING;\n\n log(\"RUNNING Export Forms Process Handler\");\n const { formBuilder, pageBuilder } = context;\n const { taskId, subTaskIndex, type, identity } = payload;\n // Disable authorization; this is necessary because we call Form 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.importExportTask.getSubTask(taskId, zeroPad(subTaskIndex, 5));\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 !== ImportExportTaskStatus.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 { formId, exportFormsDataKey, revisionType } = input;\n\n /**\n * At the moment, we only export a single revision of the form.\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 form;\n try {\n if (revisionType === ExportRevisionType.PUBLISHED) {\n // Get \"published\" form.\n form = await formBuilder.getLatestPublishedFormRevision(formId);\n } else {\n // Get \"latest\" form.\n form = await formBuilder.getForm(formId);\n }\n } catch (e) {\n // If we're looking for \"published\" form and doesn't found it, get latest form.\n if (revisionType === ExportRevisionType.PUBLISHED && e instanceof NotFoundError) {\n form = await formBuilder.getForm(formId);\n } else {\n throw e;\n }\n }\n\n if (!form) {\n log(`Unable to load form \"${formId}\"`);\n throw new NotFoundError(`Unable to load form \"${formId}\"`);\n }\n\n log(`Processing form key \"${formId}\" | version ${form.version} | ${form.status}`);\n\n // Mark task status as PROCESSING\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.PROCESSING\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.PROCESSING\n });\n prevStatusOfSubTask = subTask.status;\n\n log(`Extracting form data and uploading to storage...`);\n const formExporter = new FormExporter();\n const formDataZip = await formExporter.execute(form, exportFormsDataKey);\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for form \"${form.id}\" v${form.version} (${form.status}).`,\n key: formDataZip.Key\n }\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.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.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n stack: e.stack,\n code: \"EXPORT_FAILED\"\n }\n });\n\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.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 form zip files.\n await invokeHandlerClient<ExtractPayload>({\n context,\n name: configuration.handlers.combine,\n payload: {\n taskId,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export forms - 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 form error out.\n await invokeHandlerClient<Payload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId,\n type,\n subTaskIndex: subTaskIndex + 1,\n identity: context.security.getIdentity()\n },\n description: \"Export forms - process - subtask\"\n });\n }\n }\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,aAAA,GAAAL,OAAA;AAEA;AACA;AACA;AACO,MAAMM,YAAY,GAAG,MAAAA,CACxBC,aAA4B,EAC5BC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EACvB,IAAIE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;MAC7C;MACA,MAAM,IAAAyC,2BAAmB,EAAiB;QACtCnD,OAAO;QACPgD,IAAI,EAAElD,aAAa,CAACsD,QAAQ,CAACC,OAAO;QACpCtD,OAAO,EAAE;UACLW,MAAM;UACNE,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAACsD,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN,CAAC,MAAM;MACHtD,OAAO,CAACD,GAAG,CAAC,8BAA8BU,YAAY,GAAG,CAAC,GAAG,CAAC;MAC9D;MACA,MAAM,IAAAwC,2BAAmB,EAAU;QAC/BnD,OAAO;QACPgD,IAAI,EAAElD,aAAa,CAACsD,QAAQ,CAACK,OAAO;QACpC1D,OAAO,EAAE;UACLW,MAAM;UACNE,IAAI;UACJD,YAAY,EAAEA,YAAY,GAAG,CAAC;UAC9BE,QAAQ,EAAEb,OAAO,CAACsD,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN;EACJ;EACA,OAAO;IACHrC,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAACsC,OAAA,CAAA7D,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import { PbImportExportContext } from "../../types";
2
- import { SecurityIdentity } from "@webiny/api-security/types";
1
+ import type { PbImportExportContext } from "../../types";
2
+ import type { SecurityIdentity } from "@webiny/api-security/types";
3
3
  export interface Configuration {
4
4
  handlers: {
5
5
  process: string;
@@ -6,27 +6,36 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _handlerAws = require("@webiny/handler-aws");
8
8
  var _blocksHandler = require("./blocksHandler");
9
- var _pagesHandler = require("./pagesHandler");
9
+ var _formsHandler = require("./formsHandler");
10
10
  var _templatesHandler = require("./templatesHandler");
11
11
  var _default = configuration => {
12
12
  return (0, _handlerAws.createRawEventHandler)(async ({
13
13
  payload,
14
14
  context
15
15
  }) => {
16
- switch (payload.type) {
17
- case "block":
18
- {
19
- return await (0, _blocksHandler.blocksHandler)(configuration, payload, context);
20
- }
21
- case "template":
22
- {
23
- return await (0, _templatesHandler.templatesHandler)(configuration, payload, context);
24
- }
25
- default:
26
- {
27
- return await (0, _pagesHandler.pagesHandler)(configuration, payload, context);
28
- }
29
- }
16
+ return context.security.withoutAuthorization(() => {
17
+ switch (payload.type) {
18
+ case "block":
19
+ {
20
+ return (0, _blocksHandler.blocksHandler)(configuration, payload, context);
21
+ }
22
+ case "form":
23
+ {
24
+ return (0, _formsHandler.formsHandler)(configuration, payload, context);
25
+ }
26
+ case "template":
27
+ {
28
+ return (0, _templatesHandler.templatesHandler)(configuration, payload, context);
29
+ }
30
+ default:
31
+ {
32
+ console.log("Export PB process", JSON.stringify(payload));
33
+ throw new Error("Invalid type provided: pb process.");
34
+ }
35
+ }
36
+ });
30
37
  });
31
38
  };
32
- exports.default = _default;
39
+ exports.default = _default;
40
+
41
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["configuration","createRawEventHandler","payload","context","type","blocksHandler","templatesHandler","pagesHandler"],"sources":["index.ts"],"sourcesContent":["import { PbImportExportContext } from \"~/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { blocksHandler } from \"~/export/process/blocksHandler\";\nimport { pagesHandler } from \"~/export/process/pagesHandler\";\nimport { templatesHandler } from \"~/export/process/templatesHandler\";\n\nexport interface Configuration {\n handlers: {\n process: string;\n combine: string;\n };\n}\n\nexport interface Payload {\n taskId: string;\n subTaskIndex: number;\n type: string;\n identity?: SecurityIdentity;\n}\n\nexport interface Response {\n data: string | null;\n error: Partial<Error> | null;\n}\n\nexport default (configuration: Configuration) => {\n return createRawEventHandler<Payload, PbImportExportContext, Response>(\n async ({ payload, context }) => {\n switch (payload.type) {\n case \"block\": {\n return await blocksHandler(configuration, payload, context);\n }\n case \"template\": {\n return await templatesHandler(configuration, payload, context);\n }\n default: {\n return await pagesHandler(configuration, payload, context);\n }\n }\n }\n );\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AAAqE,eAqBrDA,aAA4B,IAAK;EAC7C,OAAO,IAAAC,iCAAqB,EACxB,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IAC5B,QAAQD,OAAO,CAACE,IAAI;MAChB,KAAK,OAAO;QAAE;UACV,OAAO,MAAM,IAAAC,4BAAa,EAACL,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;QAC/D;MACA,KAAK,UAAU;QAAE;UACb,OAAO,MAAM,IAAAG,kCAAgB,EAACN,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;QAClE;MACA;QAAS;UACL,OAAO,MAAM,IAAAI,0BAAY,EAACP,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;QAC9D;IAAC;EAET,CAAC,CACJ;AACL,CAAC;AAAA"}
1
+ {"version":3,"names":["_handlerAws","require","_blocksHandler","_formsHandler","_templatesHandler","_default","configuration","createRawEventHandler","payload","context","security","withoutAuthorization","type","blocksHandler","formsHandler","templatesHandler","console","log","JSON","stringify","Error","exports","default"],"sources":["index.ts"],"sourcesContent":["import type { PbImportExportContext } from \"~/types\";\nimport type { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { blocksHandler } from \"~/export/process/blocksHandler\";\nimport { formsHandler } from \"~/export/process/formsHandler\";\nimport { templatesHandler } from \"~/export/process/templatesHandler\";\n\nexport interface Configuration {\n handlers: {\n process: string;\n combine: string;\n };\n}\n\nexport interface Payload {\n taskId: string;\n subTaskIndex: number;\n type: string;\n identity?: SecurityIdentity;\n}\n\nexport interface Response {\n data: string | null;\n error: Partial<Error> | null;\n}\n\nexport default (configuration: Configuration) => {\n return createRawEventHandler<Payload, PbImportExportContext, Response>(\n async ({ payload, context }) => {\n return context.security.withoutAuthorization(() => {\n switch (payload.type) {\n case \"block\": {\n return blocksHandler(configuration, payload, context);\n }\n case \"form\": {\n return formsHandler(configuration, payload, context);\n }\n case \"template\": {\n return templatesHandler(configuration, payload, context);\n }\n default: {\n console.log(\"Export PB process\", JSON.stringify(payload));\n throw new Error(\"Invalid type provided: pb process.\");\n }\n }\n });\n }\n );\n};\n"],"mappings":";;;;;;AAEA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AAAqE,IAAAI,QAAA,GAqBrDC,aAA4B,IAAK;EAC7C,OAAO,IAAAC,iCAAqB,EACxB,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IAC5B,OAAOA,OAAO,CAACC,QAAQ,CAACC,oBAAoB,CAAC,MAAM;MAC/C,QAAQH,OAAO,CAACI,IAAI;QAChB,KAAK,OAAO;UAAE;YACV,OAAO,IAAAC,4BAAa,EAACP,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;UACzD;QACA,KAAK,MAAM;UAAE;YACT,OAAO,IAAAK,0BAAY,EAACR,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;UACxD;QACA,KAAK,UAAU;UAAE;YACb,OAAO,IAAAM,kCAAgB,EAACT,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;UAC5D;QACA;UAAS;YACLO,OAAO,CAACC,GAAG,CAAC,mBAAmB,EAAEC,IAAI,CAACC,SAAS,CAACX,OAAO,CAAC,CAAC;YACzD,MAAM,IAAIY,KAAK,CAAC,oCAAoC,CAAC;UACzD;MACJ;IACJ,CAAC,CAAC;EACN,CACJ,CAAC;AACL,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAjB,QAAA","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import { PbImportExportContext } from "../../types";
2
- import { Configuration, Payload, Response } from ".";
1
+ import type { PbImportExportContext } from "../../types";
2
+ import type { Configuration, Payload, Response } from "./";
3
3
  /**
4
4
  * Handles the export templates process workflow.
5
5
  */
@@ -7,9 +7,9 @@ exports.templatesHandler = void 0;
7
7
  var _types = require("../../types");
8
8
  var _client = require("../../client");
9
9
  var _handlerGraphql = require("@webiny/handler-graphql");
10
- var _utils = require("../utils");
11
10
  var _mockSecurity = require("../../mockSecurity");
12
- var _utils2 = require("@webiny/utils");
11
+ var _utils = require("@webiny/utils");
12
+ var _PageTemplateExporter = require("./exporters/PageTemplateExporter");
13
13
  /**
14
14
  * Handles the export templates process workflow.
15
15
  */
@@ -37,7 +37,7 @@ const templatesHandler = async (configuration, payload, context) => {
37
37
  * Note: We're not going to DB for finding the next sub-task to process,
38
38
  * because the data might be out of sync due to GSI eventual consistency.
39
39
  */
40
- subTask = await pageBuilder.importExportTask.getSubTask(taskId, (0, _utils2.zeroPad)(subTaskIndex, 5));
40
+ subTask = await pageBuilder.importExportTask.getSubTask(taskId, (0, _utils.zeroPad)(subTaskIndex, 5));
41
41
  /**
42
42
  * Base condition!!
43
43
  * Bail out early, if task not found or task's status is not "pending".
@@ -59,7 +59,11 @@ const templatesHandler = async (configuration, payload, context) => {
59
59
  templateId,
60
60
  exportTemplatesDataKey
61
61
  } = input;
62
- const template = await pageBuilder.getPageTemplate(templateId);
62
+ const template = await pageBuilder.getPageTemplate({
63
+ where: {
64
+ id: templateId
65
+ }
66
+ });
63
67
  if (!template) {
64
68
  log(`Unable to load template "${templateId}"`);
65
69
  throw new _handlerGraphql.NotFoundError(`Unable to load template "${templateId}"`);
@@ -77,8 +81,8 @@ const templatesHandler = async (configuration, payload, context) => {
77
81
  });
78
82
  prevStatusOfSubTask = subTask.status;
79
83
  log(`Extracting template data and uploading to storage...`);
80
- // Extract Template
81
- const templateDataZip = await (0, _utils.exportTemplate)(template, exportTemplatesDataKey, fileManager);
84
+ const templateExporter = new _PageTemplateExporter.PageTemplateExporter(fileManager);
85
+ const templateDataZip = await templateExporter.execute(template, exportTemplatesDataKey);
82
86
  log(`Finish uploading zip...`);
83
87
  // Update task record in DB
84
88
  subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
@@ -159,4 +163,6 @@ const templatesHandler = async (configuration, payload, context) => {
159
163
  error: null
160
164
  };
161
165
  };
162
- exports.templatesHandler = templatesHandler;
166
+ exports.templatesHandler = templatesHandler;
167
+
168
+ //# sourceMappingURL=templatesHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["templatesHandler","configuration","payload","context","log","console","subTask","noPendingTask","prevStatusOfSubTask","ImportExportTaskStatus","PENDING","pageBuilder","fileManager","taskId","subTaskIndex","type","identity","mockSecurity","importExportTask","getSubTask","zeroPad","status","data","error","id","input","templateId","exportTemplatesDataKey","template","getPageTemplate","NotFoundError","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","templateDataZip","exportTemplate","COMPLETED","message","key","Key","e","FAILED","name","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process"],"sources":["templatesHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { exportTemplate } from \"~/export/utils\";\nimport { Payload as ExtractPayload } from \"../combine\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { Configuration, Payload, Response } from \"~/export/process\";\n\n/**\n * Handles the export templates process workflow.\n */\nexport const templatesHandler = async (\n configuration: Configuration,\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n let subTask;\n let noPendingTask = true;\n let prevStatusOfSubTask = ImportExportTaskStatus.PENDING;\n\n log(\"RUNNING Export Templates Process Handler\");\n const { pageBuilder, fileManager } = context;\n const { taskId, subTaskIndex, type, 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 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.importExportTask.getSubTask(taskId, zeroPad(subTaskIndex, 5));\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 !== ImportExportTaskStatus.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 { templateId, exportTemplatesDataKey } = input;\n\n const template = await pageBuilder.getPageTemplate(templateId);\n\n if (!template) {\n log(`Unable to load template \"${templateId}\"`);\n throw new NotFoundError(`Unable to load template \"${templateId}\"`);\n }\n\n log(`Processing template key \"${templateId}\"`);\n\n // Mark task status as PROCESSING\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.PROCESSING\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.PROCESSING\n });\n prevStatusOfSubTask = subTask.status;\n\n log(`Extracting template data and uploading to storage...`);\n // Extract Template\n const templateDataZip = await exportTemplate(template, exportTemplatesDataKey, fileManager);\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for template \"${template.id}\"`,\n key: templateDataZip.Key\n }\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.COMPLETED\n });\n prevStatusOfSubTask = subTask.status;\n } catch (e) {\n log(\"[EXPORT_TEMPLATES_PROCESS] Error => \", e.message);\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.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n code: \"EXPORT_FAILED\"\n }\n });\n\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.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 template zip files.\n await invokeHandlerClient<ExtractPayload>({\n context,\n name: configuration.handlers.combine,\n payload: {\n taskId,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export templates - 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 template error out.\n await invokeHandlerClient<Payload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId,\n subTaskIndex: subTaskIndex + 1,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export templates - process - subtask\"\n });\n }\n }\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAEA;AAEA;AAGA;AACA;AACA;AACO,MAAMA,gBAAgB,GAAG,OAC5BC,aAA4B,EAC5BC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EACvB,IAAIE,OAAO;EACX,IAAIC,aAAa,GAAG,IAAI;EACxB,IAAIC,mBAAmB,GAAGC,6BAAsB,CAACC,OAAO;EAExDN,GAAG,CAAC,0CAA0C,CAAC;EAC/C,MAAM;IAAEO,WAAW;IAAEC;EAAY,CAAC,GAAGT,OAAO;EAC5C,MAAM;IAAEU,MAAM;IAAEC,YAAY;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAGd,OAAO;EACxD;EACA;EACA,IAA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AE1B,mBAAmB;QAC/B2B,UAAU,EAAE1B,6BAAsB,CAACkC;MACvC,CAAC,CAAC;MACFnC,mBAAmB,GAAGF,OAAO,CAACe,MAAM;IACxC;IAEA,OAAO;MACHC,IAAI,EAAE,IAAI;MACVC,KAAK,EAAE;QACHgB,OAAO,EAAEG,CAAC,CAACH;MACf;IACJ,CAAC;EACL,CAAC,SAAS;IACN;IACA,IAAIhC,aAAa,EAAE;MACfH,GAAG,CAAE,gCAA+BS,MAAO,EAAC,CAAC;MAC7C;MACA,MAAM,IAAAiC,2BAAmB,EAAiB;QACtC3C,OAAO;QACPyC,IAAI,EAAE3C,aAAa,CAAC8C,QAAQ,CAACC,OAAO;QACpC9C,OAAO,EAAE;UACLW,MAAM;UACNE,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAAC8C,QAAQ,CAACC,WAAW;QAC1C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN,CAAC,MAAM;MACH9C,OAAO,CAACD,GAAG,CAAE,8BAA6BU,YAAY,GAAG,CAAE,GAAE,CAAC;MAC9D;MACA,MAAM,IAAAgC,2BAAmB,EAAU;QAC/B3C,OAAO;QACPyC,IAAI,EAAE3C,aAAa,CAAC8C,QAAQ,CAACK,OAAO;QACpClD,OAAO,EAAE;UACLW,MAAM;UACNC,YAAY,EAAEA,YAAY,GAAG,CAAC;UAC9BC,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAAC8C,QAAQ,CAACC,WAAW;QAC1C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN;EACJ;EACA,OAAO;IACH7B,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_types","require","_client","_handlerGraphql","_mockSecurity","_utils","_PageTemplateExporter","templatesHandler","configuration","payload","context","log","console","subTask","noPendingTask","prevStatusOfSubTask","ImportExportTaskStatus","PENDING","pageBuilder","fileManager","taskId","subTaskIndex","type","identity","mockSecurity","importExportTask","getSubTask","zeroPad","status","data","error","id","input","templateId","exportTemplatesDataKey","template","getPageTemplate","where","NotFoundError","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","templateExporter","PageTemplateExporter","templateDataZip","execute","COMPLETED","message","key","Key","e","FAILED","name","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process","exports"],"sources":["templatesHandler.ts"],"sourcesContent":["import type { PbImportExportContext } from \"~/types\";\nimport { ImportExportTaskStatus } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport type { Payload as ExtractPayload } from \"../combine\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport type { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { zeroPad } from \"@webiny/utils\";\nimport type { Configuration, Payload, Response } from \"~/export/process\";\nimport { PageTemplateExporter } from \"~/export/process/exporters/PageTemplateExporter\";\n\n/**\n * Handles the export templates process workflow.\n */\nexport const templatesHandler = async (\n configuration: Configuration,\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n let subTask;\n let noPendingTask = true;\n let prevStatusOfSubTask = ImportExportTaskStatus.PENDING;\n\n log(\"RUNNING Export Templates Process Handler\");\n const { pageBuilder, fileManager } = context;\n const { taskId, subTaskIndex, type, 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 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.importExportTask.getSubTask(taskId, zeroPad(subTaskIndex, 5));\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 !== ImportExportTaskStatus.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 { templateId, exportTemplatesDataKey } = input;\n\n const template = await pageBuilder.getPageTemplate({ where: { id: templateId } });\n\n if (!template) {\n log(`Unable to load template \"${templateId}\"`);\n throw new NotFoundError(`Unable to load template \"${templateId}\"`);\n }\n\n log(`Processing template key \"${templateId}\"`);\n\n // Mark task status as PROCESSING\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.PROCESSING\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.PROCESSING\n });\n prevStatusOfSubTask = subTask.status;\n\n log(`Extracting template data and uploading to storage...`);\n const templateExporter = new PageTemplateExporter(fileManager);\n const templateDataZip = await templateExporter.execute(template, exportTemplatesDataKey);\n\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for template \"${template.id}\"`,\n key: templateDataZip.Key\n }\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.COMPLETED\n });\n prevStatusOfSubTask = subTask.status;\n } catch (e) {\n log(\"[EXPORT_TEMPLATES_PROCESS] Error => \", e.message);\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.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n code: \"EXPORT_FAILED\"\n }\n });\n\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.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 template zip files.\n await invokeHandlerClient<ExtractPayload>({\n context,\n name: configuration.handlers.combine,\n payload: {\n taskId,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export templates - 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 template error out.\n await invokeHandlerClient<Payload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId,\n subTaskIndex: subTaskIndex + 1,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export templates - process - subtask\"\n });\n }\n }\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,qBAAA,GAAAL,OAAA;AAEA;AACA;AACA;AACO,MAAMM,gBAAgB,GAAG,MAAAA,CAC5BC,aAA4B,EAC5BC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EACvB,IAAIE,OAAO;EACX,IAAIC,aAAa,GAAG,IAAI;EACxB,IAAIC,mBAAmB,GAAGC,6BAAsB,CAACC,OAAO;EAExDN,GAAG,CAAC,0CAA0C,CAAC;EAC/C,MAAM;IAAEO,WAAW;IAAEC;EAAY,CAAC,GAAGT,OAAO;EAC5C,MAAM;IAAEU,MAAM;IAAEC,YAAY;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAGd,OAAO;EACxD;EACA;EACA,IAAAe,0BAAY,EAACD,QAAQ,EAAsBb,OAAO,CAAC;EACnD,IAAI;IACA;AACR;AACA;AACA;IACQG,OAAO,GAAG,MAAMK,WAAW,CAACO,gBAAgB,CAACC,UAAU,CAACN,MAAM,EAAE,IAAA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,CAACqC;MACvC,CAAC,CAAC;MACFtC,mBAAmB,GAAGF,OAAO,CAACe,MAAM;IACxC;IAEA,OAAO;MACHC,IAAI,EAAE,IAAI;MACVC,KAAK,EAAE;QACHmB,OAAO,EAAEG,CAAC,CAACH;MACf;IACJ,CAAC;EACL,CAAC,SAAS;IACN;IACA,IAAInC,aAAa,EAAE;MACfH,GAAG,CAAC,gCAAgCS,MAAM,EAAE,CAAC;MAC7C;MACA,MAAM,IAAAoC,2BAAmB,EAAiB;QACtC9C,OAAO;QACP4C,IAAI,EAAE9C,aAAa,CAACiD,QAAQ,CAACC,OAAO;QACpCjD,OAAO,EAAE;UACLW,MAAM;UACNE,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAACiD,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN,CAAC,MAAM;MACHjD,OAAO,CAACD,GAAG,CAAC,8BAA8BU,YAAY,GAAG,CAAC,GAAG,CAAC;MAC9D;MACA,MAAM,IAAAmC,2BAAmB,EAAU;QAC/B9C,OAAO;QACP4C,IAAI,EAAE9C,aAAa,CAACiD,QAAQ,CAACK,OAAO;QACpCrD,OAAO,EAAE;UACLW,MAAM;UACNC,YAAY,EAAEA,YAAY,GAAG,CAAC;UAC9BC,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAACiD,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN;EACJ;EACA,OAAO;IACHhC,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAACiC,OAAA,CAAAxD,gBAAA,GAAAA,gBAAA","ignoreList":[]}
@@ -1,31 +1,36 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { PassThrough, Readable } from "stream";
4
- import S3 from "aws-sdk/clients/s3";
3
+ /// <reference types="node" />
4
+ import type { Readable } from "stream";
5
+ import type { ListObjectsOutput, DeleteObjectOutput, HeadObjectOutput } from "@webiny/aws-sdk/client-s3";
6
+ import { S3 } from "@webiny/aws-sdk/client-s3";
7
+ export type { ListObjectsOutput };
5
8
  declare class S3Stream {
6
9
  s3: S3;
7
10
  bucket: string;
8
11
  constructor();
9
- getPresignedUrl(key: string): string;
12
+ getPresignedUrl(key?: string): Promise<string>;
10
13
  /**
11
14
  * We're checking if the file is accessible on S3 by getting object meta data.
12
15
  * It help us to filter files that we need to download as part of export data.
13
16
  * @param Key {string}
14
17
  */
15
18
  isFileAccessible(Key: string): Promise<boolean>;
16
- getObjectHead(Key: string): Promise<S3.HeadObjectOutput>;
17
- readStream(Key: string): Readable;
19
+ getObjectHead(Key: string): Promise<HeadObjectOutput>;
20
+ readStream(Key: string): Promise<Readable>;
18
21
  writeStream(Key: string, contentType?: string): {
19
- streamPassThrough: PassThrough;
20
- streamPassThroughUploadPromise: Promise<S3.ManagedUpload.SendData>;
22
+ streamPassThrough: import("stream").PassThrough;
23
+ /**
24
+ * We're not using the `FileManager` storage plugin here because it currently doesn't support streams.
25
+ */
26
+ streamPassThroughUploadPromise: Promise<import("@webiny/aws-sdk/client-s3").CompleteMultipartUploadCommandOutput>;
21
27
  };
22
28
  upload(params: {
23
29
  Key: string;
24
30
  ContentType: string;
25
31
  Body: Buffer;
26
- }): Promise<S3.ManagedUpload.SendData>;
27
- listObject(prefix: string): Promise<S3.ListObjectsOutput>;
28
- deleteObject(key: string): Promise<S3.DeleteObjectOutput>;
32
+ }): Promise<void>;
33
+ listObject(prefix: string): Promise<ListObjectsOutput>;
34
+ deleteObject(key: string): Promise<DeleteObjectOutput>;
29
35
  }
30
36
  export declare const s3Stream: S3Stream;
31
- export {};
@@ -1,29 +1,26 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.s3Stream = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
7
  var _stream = require("stream");
11
- var _s = _interopRequireDefault(require("aws-sdk/clients/s3"));
8
+ var _clientS = require("@webiny/aws-sdk/client-s3");
9
+ var _libStorage = require("@webiny/aws-sdk/lib-storage");
12
10
  const ARCHIVE_CONTENT_TYPE = "application/zip";
13
11
  class S3Stream {
14
12
  constructor() {
15
- (0, _defineProperty2.default)(this, "s3", void 0);
16
- (0, _defineProperty2.default)(this, "bucket", void 0);
17
- this.s3 = new _s.default({
13
+ this.s3 = new _clientS.S3({
18
14
  region: process.env.AWS_REGION
19
15
  });
20
16
  this.bucket = process.env.S3_BUCKET;
21
17
  }
22
18
  getPresignedUrl(key) {
23
- return this.s3.getSignedUrl("getObject", {
19
+ return (0, _clientS.getSignedUrl)(this.s3, new _clientS.GetObjectCommand({
24
20
  Bucket: this.bucket,
25
- Key: key,
26
- Expires: 604800 // 1 week
21
+ Key: key
22
+ }), {
23
+ expiresIn: 604800 // 1 week
27
24
  });
28
25
  }
29
26
 
@@ -46,13 +43,14 @@ class S3Stream {
46
43
  return this.s3.headObject({
47
44
  Bucket: this.bucket,
48
45
  Key
49
- }).promise();
46
+ });
50
47
  }
51
- readStream(Key) {
52
- return this.s3.getObject({
48
+ async readStream(Key) {
49
+ const response = await this.s3.send(new _clientS.GetObjectCommand({
53
50
  Bucket: this.bucket,
54
51
  Key
55
- }).createReadStream();
52
+ }));
53
+ return response.Body;
56
54
  }
57
55
  writeStream(Key, contentType = ARCHIVE_CONTENT_TYPE) {
58
56
  const streamPassThrough = new _stream.Stream.PassThrough();
@@ -63,32 +61,38 @@ class S3Stream {
63
61
  ContentType: contentType,
64
62
  Key
65
63
  };
64
+ const upload = new _libStorage.Upload({
65
+ client: this.s3,
66
+ params
67
+ });
66
68
  return {
67
69
  streamPassThrough: streamPassThrough,
68
70
  /**
69
71
  * We're not using the `FileManager` storage plugin here because it currently doesn't support streams.
70
72
  */
71
- streamPassThroughUploadPromise: this.s3.upload(params).promise()
73
+ streamPassThroughUploadPromise: upload.done()
72
74
  };
73
75
  }
74
- upload(params) {
75
- return this.s3.upload((0, _objectSpread2.default)({
76
+ async upload(params) {
77
+ await this.s3.send(new _clientS.PutObjectCommand({
76
78
  ACL: "private",
77
- Bucket: this.bucket
78
- }, params)).promise();
79
+ Bucket: this.bucket,
80
+ ...params
81
+ }));
79
82
  }
80
83
  listObject(prefix) {
81
84
  return this.s3.listObjects({
82
85
  Bucket: this.bucket,
83
86
  Prefix: prefix
84
- }).promise();
87
+ });
85
88
  }
86
89
  deleteObject(key) {
87
90
  return this.s3.deleteObject({
88
91
  Key: key,
89
92
  Bucket: this.bucket
90
- }).promise();
93
+ });
91
94
  }
92
95
  }
93
- const s3Stream = new S3Stream();
94
- exports.s3Stream = s3Stream;
96
+ const s3Stream = exports.s3Stream = new S3Stream();
97
+
98
+ //# sourceMappingURL=s3Stream.js.map
@@ -1 +1 @@
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,E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MAAM,EAAE,IAAI,CAACL,MAAM;MACnB2B,WAAW,EAAEP,WAAW;MACxBd;IACJ,CAAC;IAED,OAAO;MACHe,iBAAiB,EAAEA,iBAAiB;MACpC;AACZ;AACA;MACYO,8BAA8B,EAAE,IAAI,CAAClC,EAAE,CAACmC,MAAM,CAACL,MAAM,CAAC,CAACT,OAAO;IAClE,CAAC;EACL;EAEAc,MAAM,CAACL,MAIN,EAAsC;IACnC,OAAO,IAAI,CAAC9B,EAAE,CACTmC,MAAM;MACHJ,GAAG,EAAE,SAAS;MACdpB,MAAM,EAAE,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
+ {"version":3,"names":["_stream","require","_clientS","_libStorage","ARCHIVE_CONTENT_TYPE","S3Stream","constructor","s3","S3","region","process","env","AWS_REGION","bucket","S3_BUCKET","getPresignedUrl","key","getSignedUrl","GetObjectCommand","Bucket","Key","expiresIn","isFileAccessible","getObjectHead","error","console","warn","log","headObject","readStream","response","send","Body","writeStream","contentType","streamPassThrough","Stream","PassThrough","params","ACL","ContentType","upload","Upload","client","streamPassThroughUploadPromise","done","PutObjectCommand","listObject","prefix","listObjects","Prefix","deleteObject","s3Stream","exports"],"sources":["s3Stream.ts"],"sourcesContent":["import type { Readable } from \"stream\";\nimport { Stream } from \"stream\";\nimport type {\n ListObjectsOutput,\n DeleteObjectOutput,\n HeadObjectOutput,\n PutObjectCommandInput\n} from \"@webiny/aws-sdk/client-s3\";\nimport { S3, getSignedUrl, GetObjectCommand, PutObjectCommand } from \"@webiny/aws-sdk/client-s3\";\nimport { Upload } from \"@webiny/aws-sdk/lib-storage\";\n\nexport type { ListObjectsOutput };\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 getSignedUrl(\n this.s3,\n new GetObjectCommand({\n Bucket: this.bucket,\n Key: key\n }),\n {\n expiresIn: 604800 // 1 week\n }\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<HeadObjectOutput> {\n return this.s3.headObject({ Bucket: this.bucket, Key });\n }\n\n async readStream(Key: string): Promise<Readable> {\n const response = await this.s3.send(new GetObjectCommand({ Bucket: this.bucket, Key }));\n return response.Body as Readable;\n }\n\n writeStream(Key: string, contentType: string = ARCHIVE_CONTENT_TYPE) {\n const streamPassThrough = new Stream.PassThrough();\n\n const params: PutObjectCommandInput = {\n ACL: \"private\",\n Body: streamPassThrough,\n Bucket: this.bucket,\n ContentType: contentType,\n Key\n };\n\n const upload = new Upload({\n client: this.s3,\n params\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: upload.done()\n };\n }\n\n async upload(params: { Key: string; ContentType: string; Body: Buffer }): Promise<void> {\n await this.s3.send(\n new PutObjectCommand({\n ACL: \"private\",\n Bucket: this.bucket,\n ...params\n })\n );\n }\n\n listObject(prefix: string): Promise<ListObjectsOutput> {\n return this.s3.listObjects({\n Bucket: this.bucket,\n Prefix: prefix\n });\n }\n\n deleteObject(key: string): Promise<DeleteObjectOutput> {\n return this.s3.deleteObject({ Key: key, Bucket: this.bucket });\n }\n}\n\nexport const s3Stream = new S3Stream();\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAOA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAIA,MAAMG,oBAAoB,GAAG,iBAAiB;AAE9C,MAAMC,QAAQ,CAAC;EAIXC,WAAWA,CAAA,EAAG;IACV,IAAI,CAACC,EAAE,GAAG,IAAIC,WAAE,CAAC;MACbC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAACC;IACxB,CAAC,CAAC;IACF,IAAI,CAACC,MAAM,GAAGH,OAAO,CAACC,GAAG,CAACG,SAAmB;EACjD;EAEAC,eAAeA,CAACC,GAAY,EAAE;IAC1B,OAAO,IAAAC,qBAAY,EACf,IAAI,CAACV,EAAE,EACP,IAAIW,yBAAgB,CAAC;MACjBC,MAAM,EAAE,IAAI,CAACN,MAAM;MACnBO,GAAG,EAAEJ;IACT,CAAC,CAAC,EACF;MACIK,SAAS,EAAE,MAAM,CAAC;IACtB,CACJ,CAAC;EACL;;EAEA;AACJ;AACA;AACA;AACA;EACI,MAAMC,gBAAgBA,CAACF,GAAW,EAAoB;IAClD,IAAI;MACA,MAAM,IAAI,CAACG,aAAa,CAACH,GAAG,CAAC;MAC7B,OAAO,IAAI;IACf,CAAC,CAAC,OAAOI,KAAK,EAAE;MACZC,OAAO,CAACC,IAAI,CAAC,4CAA4CN,GAAG,GAAG,CAAC;MAChEK,OAAO,CAACE,GAAG,CAACH,KAAK,CAAC;MAClB,OAAO,KAAK;IAChB;EACJ;EAEAD,aAAaA,CAAC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ACN,MAAM;MACnBqC,MAAM,EAAEF;IACZ,CAAC,CAAC;EACN;EAEAG,YAAYA,CAACnC,GAAW,EAA+B;IACnD,OAAO,IAAI,CAACT,EAAE,CAAC4C,YAAY,CAAC;MAAE/B,GAAG,EAAEJ,GAAG;MAAEG,MAAM,EAAE,IAAI,CAACN;IAAO,CAAC,CAAC;EAClE;AACJ;AAEO,MAAMuC,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAG,IAAI/C,QAAQ,CAAC,CAAC","ignoreList":[]}
package/export/utils.d.ts CHANGED
@@ -1,22 +1,24 @@
1
- import S3 from "aws-sdk/clients/s3";
2
- import { Page, PageBlock, PageTemplate } from "@webiny/api-page-builder/types";
3
- import { FileManagerContext, File } from "@webiny/api-file-manager/types";
1
+ import type { CompleteMultipartUploadOutput } from "@webiny/aws-sdk/client-s3";
2
+ import type { BlockCategory, Page, PageBlock, PageTemplate } from "@webiny/api-page-builder/types";
3
+ import type { FileManagerContext, File } from "@webiny/api-file-manager/types";
4
4
  export declare const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
5
5
  export declare const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
6
6
  export declare const EXPORT_TEMPLATES_FOLDER_KEY = "WEBINY_PB_EXPORT_TEMPLATE";
7
+ export declare const EXPORT_FORMS_FOLDER_KEY = "WEBINY_FB_EXPORT_FORM";
7
8
  export interface ExportedPageData {
8
9
  page: Pick<Page, "content" | "title" | "version" | "status" | "settings" | "path">;
9
10
  files: File[];
10
11
  }
11
- export declare function exportPage(page: Page, exportPagesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<S3.ManagedUpload.SendData>;
12
+ export declare function exportPage(page: Page, exportPagesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<CompleteMultipartUploadOutput>;
12
13
  export interface ExportedBlockData {
13
- block: Pick<PageBlock, "name" | "content" | "preview">;
14
+ block: Pick<PageBlock, "name" | "content">;
15
+ category: BlockCategory;
14
16
  files: File[];
15
17
  }
16
- export declare function exportBlock(block: PageBlock, exportBlocksDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<S3.ManagedUpload.SendData>;
18
+ export declare function exportBlock(block: PageBlock, blockCategory: BlockCategory, exportBlocksDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<CompleteMultipartUploadOutput>;
17
19
  export interface ExportedTemplateData {
18
- template: Pick<PageTemplate, "title" | "description" | "content">;
20
+ template: Pick<PageTemplate, "title" | "slug" | "tags" | "description" | "content" | "layout" | "pageCategory" | "dataSources" | "dataBindings">;
19
21
  files: File[];
20
22
  }
21
- export declare function exportTemplate(template: PageTemplate, exportTemplatesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<S3.ManagedUpload.SendData>;
22
- export declare function extractFilesFromData(data: Record<string, any>, files?: any[]): File[];
23
+ export declare function exportTemplate(template: PageTemplate, exportTemplatesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<CompleteMultipartUploadOutput>;
24
+ export declare function extractFilesFromData(data: Record<string, any>, files?: File[]): File[];
package/export/utils.js CHANGED
@@ -4,19 +4,17 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.EXPORT_TEMPLATES_FOLDER_KEY = exports.EXPORT_PAGES_FOLDER_KEY = exports.EXPORT_BLOCKS_FOLDER_KEY = void 0;
7
+ exports.EXPORT_TEMPLATES_FOLDER_KEY = exports.EXPORT_PAGES_FOLDER_KEY = exports.EXPORT_FORMS_FOLDER_KEY = exports.EXPORT_BLOCKS_FOLDER_KEY = void 0;
8
8
  exports.exportBlock = exportBlock;
9
9
  exports.exportPage = exportPage;
10
10
  exports.exportTemplate = exportTemplate;
11
11
  exports.extractFilesFromData = extractFilesFromData;
12
12
  var _get = _interopRequireDefault(require("lodash/get"));
13
13
  var _zipper = _interopRequireDefault(require("./zipper"));
14
- const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
15
- exports.EXPORT_PAGES_FOLDER_KEY = EXPORT_PAGES_FOLDER_KEY;
16
- const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
17
- exports.EXPORT_BLOCKS_FOLDER_KEY = EXPORT_BLOCKS_FOLDER_KEY;
18
- const EXPORT_TEMPLATES_FOLDER_KEY = "WEBINY_PB_EXPORT_TEMPLATE";
19
- exports.EXPORT_TEMPLATES_FOLDER_KEY = EXPORT_TEMPLATES_FOLDER_KEY;
14
+ const EXPORT_PAGES_FOLDER_KEY = exports.EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
15
+ const EXPORT_BLOCKS_FOLDER_KEY = exports.EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
16
+ const EXPORT_TEMPLATES_FOLDER_KEY = exports.EXPORT_TEMPLATES_FOLDER_KEY = "WEBINY_PB_EXPORT_TEMPLATE";
17
+ const EXPORT_FORMS_FOLDER_KEY = exports.EXPORT_FORMS_FOLDER_KEY = "WEBINY_FB_EXPORT_FORM";
20
18
  async function exportPage(page, exportPagesDataKey, fileManager) {
21
19
  // Extract all files
22
20
  const files = extractFilesFromData(page.content || {});
@@ -26,8 +24,10 @@ async function exportPage(page, exportPagesDataKey, fileManager) {
26
24
  // Get file data for all images
27
25
  const imageFilesData = [];
28
26
  if (fileIds.length > 0) {
29
- const [filesData] = await fileManager.files.listFiles({
30
- ids: fileIds
27
+ const [filesData] = await fileManager.listFiles({
28
+ where: {
29
+ id_in: fileIds
30
+ }
31
31
  });
32
32
  imageFilesData.push(...filesData);
33
33
  }
@@ -55,29 +55,32 @@ async function exportPage(page, exportPagesDataKey, fileManager) {
55
55
  });
56
56
  return zipper.process();
57
57
  }
58
- async function exportBlock(block, exportBlocksDataKey, fileManager) {
58
+ async function exportBlock(block, blockCategory, exportBlocksDataKey, fileManager) {
59
59
  // Extract all files
60
60
  const files = extractFilesFromData(block.content || {});
61
61
  const fileIds = files.map(imageFile => imageFile.id);
62
62
  // Get file data for all images
63
63
  const imageFilesData = [];
64
64
  if (fileIds.length > 0) {
65
- const [filesData] = await fileManager.files.listFiles({
66
- ids: fileIds
65
+ const [filesData] = await fileManager.listFiles({
66
+ where: {
67
+ id_in: fileIds
68
+ }
67
69
  });
68
70
  imageFilesData.push(...filesData);
69
71
  }
70
- // Add block preview image file data
71
- if (block.preview.id) {
72
- imageFilesData.push(await fileManager.files.getFile(block.preview.id));
73
- }
74
72
 
75
73
  // Extract the block data in a json file and upload it to S3
76
74
  const blockData = {
77
75
  block: {
78
76
  name: block.name,
79
- content: block.content,
80
- preview: block.preview
77
+ content: block.content
78
+ },
79
+ category: {
80
+ name: blockCategory.name,
81
+ slug: blockCategory.slug,
82
+ icon: blockCategory.icon,
83
+ description: blockCategory.description
81
84
  },
82
85
  files: imageFilesData
83
86
  };
@@ -99,8 +102,10 @@ async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
99
102
  // Get file data for all images
100
103
  const imageFilesData = [];
101
104
  if (fileIds.length > 0) {
102
- const [filesData] = await fileManager.files.listFiles({
103
- ids: fileIds
105
+ const [filesData] = await fileManager.listFiles({
106
+ where: {
107
+ id_in: fileIds
108
+ }
104
109
  });
105
110
  imageFilesData.push(...filesData);
106
111
  }
@@ -109,8 +114,14 @@ async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
109
114
  const templateData = {
110
115
  template: {
111
116
  title: template.title,
117
+ slug: template.slug,
118
+ tags: template.tags,
112
119
  description: template.description,
113
- content: template.content
120
+ content: template.content,
121
+ layout: template.layout,
122
+ pageCategory: template.pageCategory,
123
+ dataSources: template.dataSources,
124
+ dataBindings: template.dataBindings
114
125
  },
115
126
  files: imageFilesData
116
127
  };
@@ -126,10 +137,10 @@ async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
126
137
  return zipper.process();
127
138
  }
128
139
  function extractFilesFromData(data, files = []) {
129
- // Base case: termination
130
140
  if (!data || typeof data !== "object") {
131
141
  return files;
132
142
  }
143
+
133
144
  // Recursively call function for each element
134
145
  if (Array.isArray(data)) {
135
146
  for (let i = 0; i < data.length; i++) {
@@ -143,7 +154,6 @@ function extractFilesFromData(data, files = []) {
143
154
  const tuple = Object.entries(data);
144
155
  for (let i = 0; i < tuple.length; i++) {
145
156
  const [key, value] = tuple[i];
146
- // TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.
147
157
  if (key === "file" && value) {
148
158
  files.push(value);
149
159
  } else if (key === "images" && Array.isArray(value)) {
@@ -154,4 +164,6 @@ function extractFilesFromData(data, files = []) {
154
164
  }
155
165
  }
156
166
  return files;
157
- }
167
+ }
168
+
169
+ //# sourceMappingURL=utils.js.map