@webiny/api-page-builder-import-export 0.0.0-unstable.99666aeb00 → 0.0.0-unstable.a9593f74dd

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 (135) hide show
  1. package/client.js +12 -21
  2. package/client.js.map +1 -1
  3. package/export/combine/blocksHandler.js +4 -2
  4. package/export/combine/blocksHandler.js.map +1 -1
  5. package/export/combine/formsHandler.js +4 -2
  6. package/export/combine/formsHandler.js.map +1 -1
  7. package/export/combine/index.js +3 -1
  8. package/export/combine/index.js.map +1 -1
  9. package/export/combine/pagesHandler.js +4 -2
  10. package/export/combine/pagesHandler.js.map +1 -1
  11. package/export/combine/templatesHandler.js +4 -2
  12. package/export/combine/templatesHandler.js.map +1 -1
  13. package/export/process/blocksHandler.js +13 -6
  14. package/export/process/blocksHandler.js.map +1 -1
  15. package/export/process/exporters/BlockExporter.d.ts +12 -0
  16. package/export/process/exporters/BlockExporter.js +57 -0
  17. package/export/process/exporters/BlockExporter.js.map +1 -0
  18. package/export/process/exporters/FormExporter.d.ts +9 -0
  19. package/export/process/exporters/FormExporter.js +36 -0
  20. package/export/process/exporters/FormExporter.js.map +1 -0
  21. package/export/process/exporters/PageExporter.d.ts +11 -0
  22. package/export/process/exporters/PageExporter.js +58 -0
  23. package/export/process/exporters/PageExporter.js.map +1 -0
  24. package/export/process/exporters/PageTemplateExporter.d.ts +11 -0
  25. package/export/process/exporters/PageTemplateExporter.js +56 -0
  26. package/export/process/exporters/PageTemplateExporter.js.map +1 -0
  27. package/export/process/formsHandler.js +8 -6
  28. package/export/process/formsHandler.js.map +1 -1
  29. package/export/process/index.js +3 -1
  30. package/export/process/index.js.map +1 -1
  31. package/export/process/pagesHandler.js +8 -6
  32. package/export/process/pagesHandler.js.map +1 -1
  33. package/export/process/templatesHandler.js +8 -6
  34. package/export/process/templatesHandler.js.map +1 -1
  35. package/export/s3Stream.d.ts +8 -8
  36. package/export/s3Stream.js +27 -22
  37. package/export/s3Stream.js.map +1 -1
  38. package/export/utils.d.ts +8 -13
  39. package/export/utils.js +11 -34
  40. package/export/utils.js.map +1 -1
  41. package/export/zipper.d.ts +5 -5
  42. package/export/zipper.js +18 -22
  43. package/export/zipper.js.map +1 -1
  44. package/graphql/crud/blocks.crud.js +41 -22
  45. package/graphql/crud/blocks.crud.js.map +1 -1
  46. package/graphql/crud/forms.crud.js +41 -12
  47. package/graphql/crud/forms.crud.js.map +1 -1
  48. package/graphql/crud/importExportTasks.crud.js +43 -29
  49. package/graphql/crud/importExportTasks.crud.js.map +1 -1
  50. package/graphql/crud/pages.crud.d.ts +1 -0
  51. package/graphql/crud/pages.crud.js +50 -20
  52. package/graphql/crud/pages.crud.js.map +1 -1
  53. package/graphql/crud/templates.crud.js +40 -11
  54. package/graphql/crud/templates.crud.js.map +1 -1
  55. package/graphql/crud.js +3 -1
  56. package/graphql/crud.js.map +1 -1
  57. package/graphql/graphql/blocks.gql.js +4 -2
  58. package/graphql/graphql/blocks.gql.js.map +1 -1
  59. package/graphql/graphql/forms.gql.js +3 -1
  60. package/graphql/graphql/forms.gql.js.map +1 -1
  61. package/graphql/graphql/importExportTasks.gql.js +3 -1
  62. package/graphql/graphql/importExportTasks.gql.js.map +1 -1
  63. package/graphql/graphql/pages.gql.js +3 -1
  64. package/graphql/graphql/pages.gql.js.map +1 -1
  65. package/graphql/graphql/templates.gql.js +3 -1
  66. package/graphql/graphql/templates.gql.js.map +1 -1
  67. package/graphql/graphql/utils/resolve.js +3 -1
  68. package/graphql/graphql/utils/resolve.js.map +1 -1
  69. package/graphql/graphql.js +3 -1
  70. package/graphql/graphql.js.map +1 -1
  71. package/graphql/index.js +3 -1
  72. package/graphql/index.js.map +1 -1
  73. package/graphql/types.d.ts +113 -1
  74. package/graphql/types.js +3 -1
  75. package/graphql/types.js.map +1 -1
  76. package/import/constants.js +3 -1
  77. package/import/constants.js.map +1 -1
  78. package/import/create/blocksHandler.js +3 -3
  79. package/import/create/blocksHandler.js.map +1 -1
  80. package/import/create/formsHandler.js +3 -1
  81. package/import/create/formsHandler.js.map +1 -1
  82. package/import/create/index.js +3 -1
  83. package/import/create/index.js.map +1 -1
  84. package/import/create/pagesHandler.js +3 -1
  85. package/import/create/pagesHandler.js.map +1 -1
  86. package/import/create/templatesHandler.js +3 -1
  87. package/import/create/templatesHandler.js.map +1 -1
  88. package/import/process/blocks/blocksHandler.js +6 -6
  89. package/import/process/blocks/blocksHandler.js.map +1 -1
  90. package/import/process/blocks/importBlock.d.ts +2 -2
  91. package/import/process/blocks/importBlock.js +33 -27
  92. package/import/process/blocks/importBlock.js.map +1 -1
  93. package/import/process/forms/formsHandler.js +4 -2
  94. package/import/process/forms/formsHandler.js.map +1 -1
  95. package/import/process/forms/importForm.d.ts +1 -1
  96. package/import/process/forms/importForm.js +6 -2
  97. package/import/process/forms/importForm.js.map +1 -1
  98. package/import/process/index.js +3 -1
  99. package/import/process/index.js.map +1 -1
  100. package/import/process/pages/importPage.d.ts +1 -1
  101. package/import/process/pages/importPage.js +8 -6
  102. package/import/process/pages/importPage.js.map +1 -1
  103. package/import/process/pages/pagesHandler.js +3 -1
  104. package/import/process/pages/pagesHandler.js.map +1 -1
  105. package/import/process/templates/importTemplate.d.ts +1 -1
  106. package/import/process/templates/importTemplate.js +6 -2
  107. package/import/process/templates/importTemplate.js.map +1 -1
  108. package/import/process/templates/templatesHandler.js +3 -1
  109. package/import/process/templates/templatesHandler.js.map +1 -1
  110. package/import/utils/deleteS3Folder.js +3 -1
  111. package/import/utils/deleteS3Folder.js.map +1 -1
  112. package/import/utils/extractAndUploadZipFileContents.js +3 -2
  113. package/import/utils/extractAndUploadZipFileContents.js.map +1 -1
  114. package/import/utils/extractZipAndUploadToS3.js +3 -1
  115. package/import/utils/extractZipAndUploadToS3.js.map +1 -1
  116. package/import/utils/getFileNameWithoutExt.js +3 -1
  117. package/import/utils/getFileNameWithoutExt.js.map +1 -1
  118. package/import/utils/index.js +3 -1
  119. package/import/utils/index.js.map +1 -1
  120. package/import/utils/initialStats.js +3 -1
  121. package/import/utils/initialStats.js.map +1 -1
  122. package/import/utils/prepareDataDirMap.js +3 -1
  123. package/import/utils/prepareDataDirMap.js.map +1 -1
  124. package/import/utils/updateFilesInData.js +5 -2
  125. package/import/utils/updateFilesInData.js.map +1 -1
  126. package/import/utils/uploadAssets.js +54 -11
  127. package/import/utils/uploadAssets.js.map +1 -1
  128. package/import/utils/uploadFilesFromS3.d.ts +1 -1
  129. package/import/utils/uploadFilesFromS3.js +4 -2
  130. package/import/utils/uploadFilesFromS3.js.map +1 -1
  131. package/mockSecurity.js +3 -1
  132. package/mockSecurity.js.map +1 -1
  133. package/package.json +27 -32
  134. package/types.js +62 -8
  135. package/types.js.map +1 -1
package/client.js CHANGED
@@ -1,43 +1,34 @@
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.invokeHandlerClient = invokeHandlerClient;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
7
  async function invokeHandlerClient({
10
8
  context,
11
9
  name,
12
10
  payload,
13
11
  description
14
12
  }) {
15
- /*
16
- * Prepare "invocationArgs", we're hacking our wat here.
17
- * They are necessary to setup the "context.pageBuilder" object among other things in IMPORT_PAGE_FUNCTION
18
- */
19
13
  const {
20
14
  request
21
15
  } = context;
22
16
  const tenantId = context.tenancy.getCurrentTenant().id;
23
- const headers = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, request.headers), {}, {
24
- ["x-tenant"]: request.headers["x-tenant"] || tenantId
25
- });
26
- delete headers["content-length"];
27
- const invocationArgs = {
28
- httpMethod: request.method,
29
- body: request.body,
30
- headers,
31
- /**
32
- * Required until type augmentation works correctly.
33
- */
34
- cookies: request.cookies
35
- };
17
+
36
18
  // Invoke handler
37
19
  await context.handlerClient.invoke({
38
20
  name: name,
39
- payload: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, payload), invocationArgs),
21
+ payload: {
22
+ ...payload,
23
+ httpMethod: request.method,
24
+ headers: {
25
+ ["x-i18n-locale"]: request.headers["x-i18n-locale"],
26
+ ["x-tenant"]: request.headers["x-tenant"] || tenantId
27
+ }
28
+ },
40
29
  await: false,
41
30
  description
42
31
  });
43
- }
32
+ }
33
+
34
+ //# sourceMappingURL=client.js.map
package/client.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["invokeHandlerClient","context","name","payload","description","request","tenantId","tenancy","getCurrentTenant","id","headers","invocationArgs","httpMethod","method","body","cookies","handlerClient","invoke","await"],"sources":["client.ts"],"sourcesContent":["import { PbImportExportContext } from \"~/graphql/types\";\n\nexport interface InvokeHandlerClientParams<TParams> {\n context: PbImportExportContext;\n name: string;\n payload: TParams;\n description: string;\n}\n\nexport async function invokeHandlerClient<TParams>({\n context,\n name,\n payload,\n description\n}: InvokeHandlerClientParams<TParams>) {\n /*\n * Prepare \"invocationArgs\", we're hacking our wat here.\n * They are necessary to setup the \"context.pageBuilder\" object among other things in IMPORT_PAGE_FUNCTION\n */\n const { request } = context;\n\n const tenantId = context.tenancy.getCurrentTenant().id;\n\n const headers = {\n ...request.headers,\n [\"x-tenant\"]: request.headers[\"x-tenant\"] || tenantId\n };\n delete headers[\"content-length\"];\n const invocationArgs = {\n httpMethod: request.method,\n body: request.body,\n headers,\n /**\n * Required until type augmentation works correctly.\n */\n cookies: (request as any).cookies\n };\n // Invoke handler\n await context.handlerClient.invoke<TParams & any>({\n name: name,\n payload: {\n ...payload,\n ...invocationArgs\n },\n await: false,\n description\n });\n}\n"],"mappings":";;;;;;;;AASO,eAAeA,mBAAmB,CAAU;EAC/CC,OAAO;EACPC,IAAI;EACJC,OAAO;EACPC;AACgC,CAAC,EAAE;EACnC;AACJ;AACA;AACA;EACI,MAAM;IAAEC;EAAQ,CAAC,GAAGJ,OAAO;EAE3B,MAAMK,QAAQ,GAAGL,OAAO,CAACM,OAAO,CAACC,gBAAgB,EAAE,CAACC,EAAE;EAEtD,MAAMC,OAAO,+DACNL,OAAO,CAACK,OAAO;IAClB,CAAC,UAAU,GAAGL,OAAO,CAACK,OAAO,CAAC,UAAU,CAAC,IAAIJ;EAAQ,EACxD;EACD,OAAOI,OAAO,CAAC,gBAAgB,CAAC;EAChC,MAAMC,cAAc,GAAG;IACnBC,UAAU,EAAEP,OAAO,CAACQ,MAAM;IAC1BC,IAAI,EAAET,OAAO,CAACS,IAAI;IAClBJ,OAAO;IACP;AACR;AACA;IACQK,OAAO,EAAGV,OAAO,CAASU;EAC9B,CAAC;EACD;EACA,MAAMd,OAAO,CAACe,aAAa,CAACC,MAAM,CAAgB;IAC9Cf,IAAI,EAAEA,IAAI;IACVC,OAAO,8DACAA,OAAO,GACPQ,cAAc,CACpB;IACDO,KAAK,EAAE,KAAK;IACZd;EACJ,CAAC,CAAC;AACN"}
1
+ {"version":3,"names":["invokeHandlerClient","context","name","payload","description","request","tenantId","tenancy","getCurrentTenant","id","handlerClient","invoke","httpMethod","method","headers","await"],"sources":["client.ts"],"sourcesContent":["import { PbImportExportContext } from \"~/graphql/types\";\n\nexport interface InvokeHandlerClientParams<TParams> {\n context: PbImportExportContext;\n name: string;\n payload: TParams;\n description: string;\n}\n\nexport async function invokeHandlerClient<TParams>({\n context,\n name,\n payload,\n description\n}: InvokeHandlerClientParams<TParams>) {\n const { request } = context;\n const tenantId = context.tenancy.getCurrentTenant().id;\n\n // Invoke handler\n await context.handlerClient.invoke<TParams & any>({\n name: name,\n payload: {\n ...payload,\n httpMethod: request.method,\n headers: {\n [\"x-i18n-locale\"]: request.headers[\"x-i18n-locale\"],\n [\"x-tenant\"]: request.headers[\"x-tenant\"] || tenantId\n }\n },\n await: false,\n description\n });\n}\n"],"mappings":";;;;;;AASO,eAAeA,mBAAmBA,CAAU;EAC/CC,OAAO;EACPC,IAAI;EACJC,OAAO;EACPC;AACgC,CAAC,EAAE;EACnC,MAAM;IAAEC;EAAQ,CAAC,GAAGJ,OAAO;EAC3B,MAAMK,QAAQ,GAAGL,OAAO,CAACM,OAAO,CAACC,gBAAgB,CAAC,CAAC,CAACC,EAAE;;EAEtD;EACA,MAAMR,OAAO,CAACS,aAAa,CAACC,MAAM,CAAgB;IAC9CT,IAAI,EAAEA,IAAI;IACVC,OAAO,EAAE;MACL,GAAGA,OAAO;MACVS,UAAU,EAAEP,OAAO,CAACQ,MAAM;MAC1BC,OAAO,EAAE;QACL,CAAC,eAAe,GAAGT,OAAO,CAACS,OAAO,CAAC,eAAe,CAAC;QACnD,CAAC,UAAU,GAAGT,OAAO,CAACS,OAAO,CAAC,UAAU,CAAC,IAAIR;MACjD;IACJ,CAAC;IACDS,KAAK,EAAE,KAAK;IACZX;EACJ,CAAC,CAAC;AACN"}
@@ -61,7 +61,7 @@ const blocksHandler = async (payload, context) => {
61
61
  data: {
62
62
  message: `Finish uploading block export.`,
63
63
  key: blockExportUpload.Key,
64
- url: _s3Stream.s3Stream.getPresignedUrl(blockExportUpload.Key)
64
+ url: await _s3Stream.s3Stream.getPresignedUrl(blockExportUpload.Key)
65
65
  }
66
66
  });
67
67
 
@@ -96,4 +96,6 @@ const blocksHandler = async (payload, context) => {
96
96
  error: null
97
97
  };
98
98
  };
99
- exports.blocksHandler = blocksHandler;
99
+ exports.blocksHandler = blocksHandler;
100
+
101
+ //# sourceMappingURL=blocksHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["blocksHandler","payload","context","log","console","pageBuilder","taskId","identity","mockSecurity","task","importExportTask","getTask","data","error","message","exportBlocksDataKey","input","listObjectResponse","s3Stream","listObject","Contents","zipFileKeys","filter","file","Key","map","Boolean","zipOfZip","ZipOfZip","blockExportUpload","process","Location","updateTask","status","ImportExportTaskStatus","COMPLETED","key","url","getPresignedUrl","deleteFilePromises","deleteObject","Promise","all","length","e","FAILED","name","code"],"sources":["blocksHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { s3Stream } from \"../s3Stream\";\nimport { ZipOfZip } from \"../zipper\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { Payload, Response } from \"~/export/combine\";\n\n/**\n * Handles the export blocks combine workflow.\n */\nexport const blocksHandler = async (\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n\n log(\"RUNNING Export Blocks Combine Handler\");\n const { pageBuilder } = context;\n const { taskId, identity } = payload;\n\n mockSecurity(identity, context);\n\n try {\n const task = await pageBuilder.importExportTask.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 { exportBlocksDataKey } = task.input;\n\n // Get all files (zip) from given key\n const listObjectResponse = await s3Stream.listObject(exportBlocksDataKey);\n if (!listObjectResponse.Contents) {\n return {\n data: null,\n error: {\n message: \"There is no Contents defined on S3 Stream while combining blocks.\"\n }\n };\n }\n\n const zipFileKeys = listObjectResponse.Contents.filter(\n file => file.Key !== exportBlocksDataKey\n )\n .map(file => file.Key)\n .filter(Boolean) as string[];\n\n // Prepare zip of all zips\n const zipOfZip = new ZipOfZip(zipFileKeys, \"WEBINY_BLOCK_EXPORT.zip\");\n\n // Upload\n const blockExportUpload = await zipOfZip.process();\n log(`Done uploading... File is located at ${blockExportUpload.Location} `);\n\n // Update task status and save export blocks data key\n await pageBuilder.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading block export.`,\n key: blockExportUpload.Key,\n url: s3Stream.getPresignedUrl(blockExportUpload.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_BLOCKS_COMBINE] Error => \", e.message);\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.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\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"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAGA;AACA;AACA;AACO,MAAMA,aAAa,GAAG,OACzBC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EAEvBA,GAAG,CAAC,uCAAuC,CAAC;EAC5C,MAAM;IAAEE;EAAY,CAAC,GAAGH,OAAO;EAC/B,MAAM;IAAEI,MAAM;IAAEC;EAAS,CAAC,GAAGN,OAAO;EAEpC,IAAAO,0BAAY,EAACD,QAAQ,EAAEL,OAAO,CAAC;EAE/B,IAAI;IACA,MAAMO,IAAI,GAAG,MAAMJ,WAAW,CAACK,gBAAgB,CAACC,OAAO,CAACL,MAAM,CAAC;IAC/D,IAAI,CAACG,IAAI,EAAE;MACP,OAAO;QACHG,IAAI,EAAE,IAAI;QACVC,KAAK,EAAE;UACHC,OAAO,EAAG,6BAA4BR,MAAO;QACjD;MACJ,CAAC;IACL;IAEA,MAAM;MAAES;IAAoB,CAAC,GAAGN,IAAI,CAACO,KAAK;;IAE1C;IACA,MAAMC,kBAAkB,GAAG,MAAMC,kBAAQ,CAACC,UAAU,CAACJ,mBAAmB,CAAC;IACzE,IAAI,CAACE,kBAAkB,CAACG,QAAQ,EAAE;MAC9B,OAAO;QACHR,IAAI,EAAE,IAAI;QACVC,KAAK,EAAE;UACHC,OAAO,EAAE;QACb;MACJ,CAAC;IACL;IAEA,MAAMO,WAAW,GAAGJ,kBAAkB,CAACG,QAAQ,CAACE,MAAM,CAClDC,IAAI,IAAIA,IAAI,CAACC,GAAG,KAAKT,mBAAmB,CAC3C,CACIU,GAAG,CAACF,IAAI,IAAIA,IAAI,CAACC,GAAG,CAAC,CACrBF,MAAM,CAACI,OAAO,CAAa;;IAE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EACL;EACA,OAAO;IACHF,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_types","require","_s3Stream","_zipper","_mockSecurity","blocksHandler","payload","context","log","console","pageBuilder","taskId","identity","mockSecurity","task","importExportTask","getTask","data","error","message","exportBlocksDataKey","input","listObjectResponse","s3Stream","listObject","Contents","zipFileKeys","filter","file","Key","map","Boolean","zipOfZip","ZipOfZip","blockExportUpload","process","Location","updateTask","status","ImportExportTaskStatus","COMPLETED","key","url","getPresignedUrl","deleteFilePromises","deleteObject","Promise","all","length","e","FAILED","name","code","exports"],"sources":["blocksHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { s3Stream } from \"../s3Stream\";\nimport { ZipOfZip } from \"../zipper\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { Payload, Response } from \"~/export/combine\";\n\n/**\n * Handles the export blocks combine workflow.\n */\nexport const blocksHandler = async (\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n\n log(\"RUNNING Export Blocks Combine Handler\");\n const { pageBuilder } = context;\n const { taskId, identity } = payload;\n\n mockSecurity(identity, context);\n\n try {\n const task = await pageBuilder.importExportTask.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 { exportBlocksDataKey } = task.input;\n\n // Get all files (zip) from given key\n const listObjectResponse = await s3Stream.listObject(exportBlocksDataKey);\n if (!listObjectResponse.Contents) {\n return {\n data: null,\n error: {\n message: \"There is no Contents defined on S3 Stream while combining blocks.\"\n }\n };\n }\n\n const zipFileKeys = listObjectResponse.Contents.filter(\n file => file.Key !== exportBlocksDataKey\n )\n .map(file => file.Key)\n .filter(Boolean) as string[];\n\n // Prepare zip of all zips\n const zipOfZip = new ZipOfZip(zipFileKeys, \"WEBINY_BLOCK_EXPORT.zip\");\n\n // Upload\n const blockExportUpload = await zipOfZip.process();\n log(`Done uploading... File is located at ${blockExportUpload.Location} `);\n\n // Update task status and save export blocks data key\n await pageBuilder.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading block export.`,\n key: blockExportUpload.Key,\n url: await s3Stream.getPresignedUrl(blockExportUpload.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_BLOCKS_COMBINE] Error => \", e.message);\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.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\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"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AAGA;AACA;AACA;AACO,MAAMI,aAAa,GAAG,MAAAA,CACzBC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EAEvBA,GAAG,CAAC,uCAAuC,CAAC;EAC5C,MAAM;IAAEE;EAAY,CAAC,GAAGH,OAAO;EAC/B,MAAM;IAAEI,MAAM;IAAEC;EAAS,CAAC,GAAGN,OAAO;EAEpC,IAAAO,0BAAY,EAACD,QAAQ,EAAEL,OAAO,CAAC;EAE/B,IAAI;IACA,MAAMO,IAAI,GAAG,MAAMJ,WAAW,CAACK,gBAAgB,CAACC,OAAO,CAACL,MAAM,CAAC;IAC/D,IAAI,CAACG,IAAI,EAAE;MACP,OAAO;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CAAC;IAC7E,MAAMK,OAAO,CAACC,GAAG,CAACH,kBAAkB,CAAC;IACrCpC,GAAG,CAAE,wBAAuBoC,kBAAkB,CAACI,MAAO,aAAY,CAAC;EACvE,CAAC,CAAC,OAAOC,CAAC,EAAE;IACRzC,GAAG,CAAC,mCAAmC,EAAEyC,CAAC,CAAC9B,OAAO,CAAC;;IAEnD;AACR;AACA;AACA;IACQ,MAAMT,WAAW,CAACK,gBAAgB,CAACsB,UAAU,CAAC1B,MAAM,EAAE;MAClD2B,MAAM,EAAEC,6BAAsB,CAACW,MAAM;MACrChC,KAAK,EAAE;QACHiC,IAAI,EAAEF,CAAC,CAACE,IAAI;QACZhC,OAAO,EAAE8B,CAAC,CAAC9B,OAAO;QAClBiC,IAAI,EAAE;MACV;IACJ,CAAC,CAAC;IAEF,OAAO;MACHnC,IAAI,EAAE,IAAI;MACVC,KAAK,EAAE;QACHC,OAAO,EAAE8B,CAAC,CAAC9B;MACf;IACJ,CAAC;EACL;EACA,OAAO;IACHF,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAACmC,OAAA,CAAAhD,aAAA,GAAAA,aAAA"}
@@ -61,7 +61,7 @@ const formsHandler = async (payload, context) => {
61
61
  data: {
62
62
  message: `Finish uploading form export.`,
63
63
  key: formExportUpload.Key,
64
- url: _s3Stream.s3Stream.getPresignedUrl(formExportUpload.Key)
64
+ url: await _s3Stream.s3Stream.getPresignedUrl(formExportUpload.Key)
65
65
  }
66
66
  });
67
67
 
@@ -96,4 +96,6 @@ const formsHandler = async (payload, context) => {
96
96
  error: null
97
97
  };
98
98
  };
99
- exports.formsHandler = formsHandler;
99
+ exports.formsHandler = formsHandler;
100
+
101
+ //# sourceMappingURL=formsHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["formsHandler","payload","context","log","console","pageBuilder","taskId","identity","mockSecurity","task","importExportTask","getTask","data","error","message","exportFormsDataKey","input","listObjectResponse","s3Stream","listObject","Contents","zipFileKeys","filter","file","Key","map","Boolean","zipOfZip","ZipOfZip","formExportUpload","process","Location","updateTask","status","ImportExportTaskStatus","COMPLETED","key","url","getPresignedUrl","deleteFilePromises","deleteObject","Promise","all","length","e","FAILED","name","code"],"sources":["formsHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { s3Stream } from \"../s3Stream\";\nimport { ZipOfZip } from \"../zipper\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { Payload, Response } from \"~/export/combine\";\n\n/**\n * Handles the export forms combine workflow.\n */\nexport const formsHandler = async (\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n\n log(\"RUNNING Export Forms Combine Handler\");\n const { pageBuilder } = context;\n const { taskId, identity } = payload;\n\n mockSecurity(identity, context);\n\n try {\n const task = await pageBuilder.importExportTask.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 { exportFormsDataKey } = task.input;\n\n // Get all files (zip) from given key\n const listObjectResponse = await s3Stream.listObject(exportFormsDataKey);\n if (!listObjectResponse.Contents) {\n return {\n data: null,\n error: {\n message: \"There is no Contents defined on S3 Stream while combining forms.\"\n }\n };\n }\n\n const zipFileKeys = listObjectResponse.Contents.filter(\n file => file.Key !== exportFormsDataKey\n )\n .map(file => file.Key)\n .filter(Boolean) as string[];\n\n // Prepare zip of all zips\n const zipOfZip = new ZipOfZip(zipFileKeys, \"WEBINY_FORM_EXPORT.zip\");\n\n // Upload\n const formExportUpload = await zipOfZip.process();\n log(`Done uploading... File is located at ${formExportUpload.Location} `);\n\n // Update task status and save export form data key\n await pageBuilder.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading form export.`,\n key: formExportUpload.Key,\n url: s3Stream.getPresignedUrl(formExportUpload.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_FORMS_COMBINE] Error => \", e.message);\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.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\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"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAGA;AACA;AACA;AACO,MAAMA,YAAY,GAAG,OACxBC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EAEvBA,GAAG,CAAC,sCAAsC,CAAC;EAC3C,MAAM;IAAEE;EAAY,CAAC,GAAGH,OAAO;EAC/B,MAAM;IAAEI,MAAM;IAAEC;EAAS,CAAC,GAAGN,OAAO;EAEpC,IAAAO,0BAAY,EAACD,QAAQ,EAAEL,OAAO,CAAC;EAE/B,IAAI;IACA,MAAMO,IAAI,GAAG,MAAMJ,WAAW,CAACK,gBAAgB,CAACC,OAAO,CAACL,MAAM,CAAC;IAC/D,IAAI,CAACG,IAAI,EAAE;MACP,OAAO;QACHG,IAAI,EAAE,IAAI;QACVC,KAAK,EAAE;UACHC,OAAO,EAAG,6BAA4BR,MAAO;QACjD;MACJ,CAAC;IACL;IAEA,MAAM;MAAES;IAAmB,CAAC,GAAGN,IAAI,CAACO,KAAK;;IAEzC;IACA,MAAMC,kBAAkB,GAAG,MAAMC,kBAAQ,CAACC,UAAU,CAACJ,kBAAkB,CAAC;IACxE,IAAI,CAACE,kBAAkB,CAACG,QAAQ,EAAE;MAC9B,OAAO;QACHR,IAAI,EAAE,IAAI;QACVC,KAAK,EAAE;UACHC,OAAO,EAAE;QACb;MACJ,CAAC;IACL;IAEA,MA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AACE,IAAI;QACZhC,OAAO,EAAE8B,CAAC,CAAC9B,OAAO;QAClBiC,IAAI,EAAE;MACV;IACJ,CAAC,CAAC;IAEF,OAAO;MACHnC,IAAI,EAAE,IAAI;MACVC,KAAK,EAAE;QACHC,OAAO,EAAE8B,CAAC,CAAC9B;MACf;IACJ,CAAC;EACL;EACA,OAAO;IACHF,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_types","require","_s3Stream","_zipper","_mockSecurity","formsHandler","payload","context","log","console","pageBuilder","taskId","identity","mockSecurity","task","importExportTask","getTask","data","error","message","exportFormsDataKey","input","listObjectResponse","s3Stream","listObject","Contents","zipFileKeys","filter","file","Key","map","Boolean","zipOfZip","ZipOfZip","formExportUpload","process","Location","updateTask","status","ImportExportTaskStatus","COMPLETED","key","url","getPresignedUrl","deleteFilePromises","deleteObject","Promise","all","length","e","FAILED","name","code","exports"],"sources":["formsHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { s3Stream } from \"../s3Stream\";\nimport { ZipOfZip } from \"../zipper\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { Payload, Response } from \"~/export/combine\";\n\n/**\n * Handles the export forms combine workflow.\n */\nexport const formsHandler = async (\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n\n log(\"RUNNING Export Forms Combine Handler\");\n const { pageBuilder } = context;\n const { taskId, identity } = payload;\n\n mockSecurity(identity, context);\n\n try {\n const task = await pageBuilder.importExportTask.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 { exportFormsDataKey } = task.input;\n\n // Get all files (zip) from given key\n const listObjectResponse = await s3Stream.listObject(exportFormsDataKey);\n if (!listObjectResponse.Contents) {\n return {\n data: null,\n error: {\n message: \"There is no Contents defined on S3 Stream while combining forms.\"\n }\n };\n }\n\n const zipFileKeys = listObjectResponse.Contents.filter(\n file => file.Key !== exportFormsDataKey\n )\n .map(file => file.Key)\n .filter(Boolean) as string[];\n\n // Prepare zip of all zips\n const zipOfZip = new ZipOfZip(zipFileKeys, \"WEBINY_FORM_EXPORT.zip\");\n\n // Upload\n const formExportUpload = await zipOfZip.process();\n log(`Done uploading... File is located at ${formExportUpload.Location} `);\n\n // Update task status and save export form data key\n await pageBuilder.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading form export.`,\n key: formExportUpload.Key,\n url: await s3Stream.getPresignedUrl(formExportUpload.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_FORMS_COMBINE] Error => \", e.message);\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.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\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"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AAGA;AACA;AACA;AACO,MAAMI,YAAY,GAAG,MAAAA,CACxBC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EAEvBA,GAAG,CAAC,sCAAsC,CAAC;EAC3C,MAAM;IAAEE;EAAY,CAAC,GAAGH,OAAO;EAC/B,MAAM;IAAEI,MAAM;IAAEC;EAAS,CAAC,GAAGN,OAAO;EAEpC,IAAAO,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oB,eAAe,CAACT,gBAAgB,CAACL,GAAG;MAC5D;IACJ,CAAC,CAAC;;IAEF;IACA,MAAMe,kBAAkB,GAAGlB,WAAW,CAACI,GAAG,CAACW,GAAG,IAAIlB,kBAAQ,CAACsB,YAAY,CAACJ,GAAG,CAAC,CAAC;IAC7E,MAAMK,OAAO,CAACC,GAAG,CAACH,kBAAkB,CAAC;IACrCpC,GAAG,CAAE,wBAAuBoC,kBAAkB,CAACI,MAAO,aAAY,CAAC;EACvE,CAAC,CAAC,OAAOC,CAAC,EAAE;IACRzC,GAAG,CAAC,kCAAkC,EAAEyC,CAAC,CAAC9B,OAAO,CAAC;;IAElD;AACR;AACA;AACA;IACQ,MAAMT,WAAW,CAACK,gBAAgB,CAACsB,UAAU,CAAC1B,MAAM,EAAE;MAClD2B,MAAM,EAAEC,6BAAsB,CAACW,MAAM;MACrChC,KAAK,EAAE;QACHiC,IAAI,EAAEF,CAAC,CAACE,IAAI;QACZhC,OAAO,EAAE8B,CAAC,CAAC9B,OAAO;QAClBiC,IAAI,EAAE;MACV;IACJ,CAAC,CAAC;IAEF,OAAO;MACHnC,IAAI,EAAE,IAAI;MACVC,KAAK,EAAE;QACHC,OAAO,EAAE8B,CAAC,CAAC9B;MACf;IACJ,CAAC;EACL;EACA,OAAO;IACHF,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAACmC,OAAA,CAAAhD,YAAA,GAAAA,YAAA"}
@@ -39,4 +39,6 @@ var _default = () => {
39
39
  });
40
40
  });
41
41
  };
42
- exports.default = _default;
42
+ exports.default = _default;
43
+
44
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createRawEventHandler","payload","context","security","withoutAuthorization","type","blocksHandler","formsHandler","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/combine/blocksHandler\";\nimport { formsHandler } from \"~/export/combine/formsHandler\";\nimport { pagesHandler } from \"~/export/combine/pagesHandler\";\nimport { templatesHandler } from \"~/export/combine/templatesHandler\";\n\nexport interface Payload {\n taskId: string;\n type: 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, PbImportExportContext, Response>(\n async ({ payload, context }) => {\n return context.security.withoutAuthorization(() => {\n switch (payload.type) {\n case \"block\": {\n return blocksHandler(payload, context);\n }\n case \"form\": {\n return formsHandler(payload, context);\n }\n case \"template\": {\n return templatesHandler(payload, context);\n }\n default: {\n return pagesHandler(payload, context);\n }\n }\n });\n }\n );\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AAaA;AACA;AACA;AAFA,eAGe,MAAM;EACjB,OAAO,IAAAA,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,EAACL,OAAO,EAAEC,OAAO,CAAC;UAC1C;QACA,KAAK,MAAM;UAAE;YACT,OAAO,IAAAK,0BAAY,EAACN,OAAO,EAAEC,OAAO,CAAC;UACzC;QACA,KAAK,UAAU;UAAE;YACb,OAAO,IAAAM,kCAAgB,EAACP,OAAO,EAAEC,OAAO,CAAC;UAC7C;QACA;UAAS;YACL,OAAO,IAAAO,0BAAY,EAACR,OAAO,EAAEC,OAAO,CAAC;UACzC;MAAC;IAET,CAAC,CAAC;EACN,CAAC,CACJ;AACL,CAAC;AAAA"}
1
+ {"version":3,"names":["_handlerAws","require","_blocksHandler","_formsHandler","_pagesHandler","_templatesHandler","_default","createRawEventHandler","payload","context","security","withoutAuthorization","type","blocksHandler","formsHandler","templatesHandler","pagesHandler","exports","default"],"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/combine/blocksHandler\";\nimport { formsHandler } from \"~/export/combine/formsHandler\";\nimport { pagesHandler } from \"~/export/combine/pagesHandler\";\nimport { templatesHandler } from \"~/export/combine/templatesHandler\";\n\nexport interface Payload {\n taskId: string;\n type: 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, PbImportExportContext, Response>(\n async ({ payload, context }) => {\n return context.security.withoutAuthorization(() => {\n switch (payload.type) {\n case \"block\": {\n return blocksHandler(payload, context);\n }\n case \"form\": {\n return formsHandler(payload, context);\n }\n case \"template\": {\n return templatesHandler(payload, context);\n }\n default: {\n return pagesHandler(payload, context);\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,aAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAaA;AACA;AACA;AAFA,IAAAK,QAAA,GAGeA,CAAA,KAAM;EACjB,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,EAACL,OAAO,EAAEC,OAAO,CAAC;UAC1C;QACA,KAAK,MAAM;UAAE;YACT,OAAO,IAAAK,0BAAY,EAACN,OAAO,EAAEC,OAAO,CAAC;UACzC;QACA,KAAK,UAAU;UAAE;YACb,OAAO,IAAAM,kCAAgB,EAACP,OAAO,EAAEC,OAAO,CAAC;UAC7C;QACA;UAAS;YACL,OAAO,IAAAO,0BAAY,EAACR,OAAO,EAAEC,OAAO,CAAC;UACzC;MACJ;IACJ,CAAC,CAAC;EACN,CACJ,CAAC;AACL,CAAC;AAAAQ,OAAA,CAAAC,OAAA,GAAAZ,QAAA"}
@@ -61,7 +61,7 @@ const pagesHandler = async (payload, context) => {
61
61
  data: {
62
62
  message: `Finish uploading page export.`,
63
63
  key: pageExportUpload.Key,
64
- url: _s3Stream.s3Stream.getPresignedUrl(pageExportUpload.Key)
64
+ url: await _s3Stream.s3Stream.getPresignedUrl(pageExportUpload.Key)
65
65
  }
66
66
  });
67
67
 
@@ -96,4 +96,6 @@ const pagesHandler = async (payload, context) => {
96
96
  error: null
97
97
  };
98
98
  };
99
- exports.pagesHandler = pagesHandler;
99
+ exports.pagesHandler = pagesHandler;
100
+
101
+ //# sourceMappingURL=pagesHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["pagesHandler","payload","context","log","console","pageBuilder","taskId","identity","mockSecurity","task","importExportTask","getTask","data","error","message","exportPagesDataKey","input","listObjectResponse","s3Stream","listObject","Contents","zipFileKeys","filter","file","Key","map","Boolean","zipOfZip","ZipOfZip","pageExportUpload","process","Location","updateTask","status","ImportExportTaskStatus","COMPLETED","key","url","getPresignedUrl","deleteFilePromises","deleteObject","Promise","all","length","e","FAILED","name","code"],"sources":["pagesHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { s3Stream } from \"../s3Stream\";\nimport { ZipOfZip } from \"../zipper\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { Payload, Response } from \"~/export/combine\";\n\n/**\n * Handles the export pages combine workflow.\n */\nexport const pagesHandler = async (\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\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.importExportTask.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: \"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, \"WEBINY_PAGE_EXPORT.zip\");\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.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.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.message);\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.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\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"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAGA;AACA;AACA;AACO,MAAMA,Y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;IACA,MAAM1B,WAAW,CAACK,gBAAgB,CAACsB,UAAU,CAAC1B,MAAM,EAAE;MAClD2B,MAAM,EAAEC,6BAAsB,CAACC,SAAS;MACxCvB,IAAI,EAAE;QACFE,OAAO,EAAG,+BAA8B;QACxCsB,GAAG,EAAEP,gBAAgB,CAACL,GAAG;QACzBa,GAAG,EAAEnB,kBAAQ,CAACoB,eAAe,CAACT,gBAAgB,CAACL,GAAG;MACtD;IACJ,CAAC,CAAC;;IAEF;IACA,MAAMe,kBAAkB,GAAGlB,WAAW,CAACI,GAAG,CAACW,GAAG,IAAIlB,kBAAQ,CAACsB,YAAY,CAACJ,GAAG,CAAC,CAAC;IAC7E,MAAMK,OAAO,CAACC,GAAG,CAACH,kBAAkB,CAAC;IACrCpC,GAAG,CAAE,wBAAuBoC,kBAAkB,CAACI,MAAO,aAAY,CAAC;EACvE,CAAC,CAAC,OAAOC,CAAC,EAAE;IACRzC,GAAG,CAAC,kCAAkC,EAAEyC,CAAC,CAAC9B,OAAO,CAAC;;IAElD;AACR;AACA;AACA;IACQ,MAAMT,WAAW,CAACK,gBAAgB,CAACsB,UAAU,CAAC1B,MAAM,EAAE;MAClD2B,MAAM,EAAEC,6BAAsB,CAACW,MAAM;MACrChC,KAAK,EAAE;QACHiC,IAAI,EAAEF,CAAC,CAACE,IAAI;QACZhC,OAAO,EAAE8B,CAAC,CAAC9B,OAAO;QAClBiC,IAAI,EAAE;MACV;IACJ,CAAC,CAAC;IAEF,OAAO;MACHnC,IAAI,EAAE,IAAI;MACVC,KAAK,EAAE;QACHC,OAAO,EAAE8B,CAAC,CAAC9B;MACf;IACJ,CAAC;EACL;EACA,OAAO;IACHF,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_types","require","_s3Stream","_zipper","_mockSecurity","pagesHandler","payload","context","log","console","pageBuilder","taskId","identity","mockSecurity","task","importExportTask","getTask","data","error","message","exportPagesDataKey","input","listObjectResponse","s3Stream","listObject","Contents","zipFileKeys","filter","file","Key","map","Boolean","zipOfZip","ZipOfZip","pageExportUpload","process","Location","updateTask","status","ImportExportTaskStatus","COMPLETED","key","url","getPresignedUrl","deleteFilePromises","deleteObject","Promise","all","length","e","FAILED","name","code","exports"],"sources":["pagesHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { s3Stream } from \"../s3Stream\";\nimport { ZipOfZip } from \"../zipper\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { Payload, Response } from \"~/export/combine\";\n\n/**\n * Handles the export pages combine workflow.\n */\nexport const pagesHandler = async (\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\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.importExportTask.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: \"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, \"WEBINY_PAGE_EXPORT.zip\");\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.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading page export.`,\n key: pageExportUpload.Key,\n url: await 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.message);\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.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\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"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AAGA;AACA;AACA;AACO,MAAMI,YAAY,GAAG,MAAAA,CACxBC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EAEvBA,GAAG,CAAC,sCAAsC,CAAC;EAC3C,MAAM;IAAEE;EAAY,CAAC,GAAGH,OAAO;EAC/B,MAAM;IAAEI,MAAM;IAAEC;EAAS,CAAC,GAAGN,OAAO;EAEpC,IAAAO,0BAAY,EAACD,QAAQ,EAAEL,OAAO,CAAC;EAE/B,IAAI;IACA,MAAMO,IAAI,GAAG,MAAMJ,WAAW,CAACK,gBAAgB,CAACC,OAAO,CAACL,MAAM,CAAC;IAC/D,IAAI,CAACG,IAAI,EAAE;MACP,OAAO;QACHG,IAAI,EAAE,IAAI;QACVC,KAAK,EAAE;UACHC,OAAO,EAAG,6BAA4BR,MAAO;QACjD;MACJ,CAAC;IACL;IAEA,MAAM;MAAES;IAAmB,CAAC,GAAGN,IAAI,CAACO,KAAK;;IAEzC;IACA,MAAMC,kBAAkB,GAAG,MAAMC,kBAAQ,CAACC,UAAU,CAACJ,kBAAkB,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AACA;AACA;IACQ,MAAMT,WAAW,CAACK,gBAAgB,CAACsB,UAAU,CAAC1B,MAAM,EAAE;MAClD2B,MAAM,EAAEC,6BAAsB,CAACW,MAAM;MACrChC,KAAK,EAAE;QACHiC,IAAI,EAAEF,CAAC,CAACE,IAAI;QACZhC,OAAO,EAAE8B,CAAC,CAAC9B,OAAO;QAClBiC,IAAI,EAAE;MACV;IACJ,CAAC,CAAC;IAEF,OAAO;MACHnC,IAAI,EAAE,IAAI;MACVC,KAAK,EAAE;QACHC,OAAO,EAAE8B,CAAC,CAAC9B;MACf;IACJ,CAAC;EACL;EACA,OAAO;IACHF,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAACmC,OAAA,CAAAhD,YAAA,GAAAA,YAAA"}
@@ -61,7 +61,7 @@ const templatesHandler = async (payload, context) => {
61
61
  data: {
62
62
  message: `Finish uploading template export.`,
63
63
  key: templateExportUpload.Key,
64
- url: _s3Stream.s3Stream.getPresignedUrl(templateExportUpload.Key)
64
+ url: await _s3Stream.s3Stream.getPresignedUrl(templateExportUpload.Key)
65
65
  }
66
66
  });
67
67
 
@@ -96,4 +96,6 @@ const templatesHandler = async (payload, context) => {
96
96
  error: null
97
97
  };
98
98
  };
99
- exports.templatesHandler = templatesHandler;
99
+ exports.templatesHandler = templatesHandler;
100
+
101
+ //# sourceMappingURL=templatesHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["templatesHandler","payload","context","log","console","pageBuilder","taskId","identity","mockSecurity","task","importExportTask","getTask","data","error","message","exportTemplatesDataKey","input","listObjectResponse","s3Stream","listObject","Contents","zipFileKeys","filter","file","Key","map","Boolean","zipOfZip","ZipOfZip","templateExportUpload","process","Location","updateTask","status","ImportExportTaskStatus","COMPLETED","key","url","getPresignedUrl","deleteFilePromises","deleteObject","Promise","all","length","e","FAILED","name","code"],"sources":["templatesHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { s3Stream } from \"../s3Stream\";\nimport { ZipOfZip } from \"../zipper\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { Payload, Response } from \"~/export/combine\";\n\n/**\n * Handles the export templates combine workflow.\n */\nexport const templatesHandler = async (\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n\n log(\"RUNNING Export Templates Combine Handler\");\n const { pageBuilder } = context;\n const { taskId, identity } = payload;\n\n mockSecurity(identity, context);\n\n try {\n const task = await pageBuilder.importExportTask.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 { exportTemplatesDataKey } = task.input;\n\n // Get all files (zip) from given key\n const listObjectResponse = await s3Stream.listObject(exportTemplatesDataKey);\n if (!listObjectResponse.Contents) {\n return {\n data: null,\n error: {\n message: \"There is no Contents defined on S3 Stream while combining templates.\"\n }\n };\n }\n\n const zipFileKeys = listObjectResponse.Contents.filter(\n file => file.Key !== exportTemplatesDataKey\n )\n .map(file => file.Key)\n .filter(Boolean) as string[];\n\n // Prepare zip of all zips\n const zipOfZip = new ZipOfZip(zipFileKeys, \"WEBINY_TEMPLATE_EXPORT.zip\");\n\n // Upload\n const templateExportUpload = await zipOfZip.process();\n log(`Done uploading... File is located at ${templateExportUpload.Location} `);\n\n // Update task status and save export templates data key\n await pageBuilder.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading template export.`,\n key: templateExportUpload.Key,\n url: s3Stream.getPresignedUrl(templateExportUpload.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_TEMPLATES_COMBINE] Error => \", e.message);\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.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\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"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAGA;AACA;AACA;AACO,MAAMA,gBAAgB,GAAG,OAC5BC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EAEvBA,GAAG,CAAC,0CAA0C,CAAC;EAC/C,MAAM;IAAEE;EAAY,CAAC,GAAGH,OAAO;EAC/B,MAAM;IAAEI,MAAM;IAAEC;EAAS,CAAC,GAAGN,OAAO;EAEpC,IAAAO,0BAAY,EAACD,QAAQ,EAAEL,OAAO,CAAC;EAE/B,IAAI;IACA,MAAMO,IAAI,GAAG,MAAMJ,WAAW,CAACK,gBAAgB,CAACC,OAAO,CAACL,MAAM,CAAC;IAC/D,IAAI,CAACG,IAAI,EAAE;MACP,OAAO;QACHG,IAAI,EAAE,IAAI;QACVC,KAAK,EAAE;UACHC,OAAO,EAAG,6BAA4BR,MAAO;QACjD;MACJ,CAAC;IACL;IAEA,MAAM;MAAES;IAAuB,CAAC,GAAGN,IAAI,CAACO,KAAK;;IAE7C;IACA,MAAMC,kBAAkB,GAAG,MAAMC,kBAAQ,CAACC,UAAU,CAACJ,sBAAsB,CAAC;IAC5E,IAAI,CAACE,kBAAkB,CAACG,QAAQ,EAAE;MAC9B,OAAO;QACHR,IAAI,EAAE,IAAI;QACVC,KAAK,EAAE;UACHC,OAAO,EAAE;QACb;MACJ,CAAC;IACL;IAEA,MAAMO,WAAW,GAAGJ,kBAAkB,CAACG,QAAQ,CAACE,MAAM,CAClDC,IAAI,IAAIA,IAAI,CAACC,GAAG,KAAKT,sBAAsB,CAC9C,CACIU,GAAG,CAACF,IAAI,IAAIA,IAAI,CAACC,GAAG,CAAC,CACrBF,MAAM,CAACI,O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;MACf;IACJ,CAAC;EACL;EACA,OAAO;IACHF,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_types","require","_s3Stream","_zipper","_mockSecurity","templatesHandler","payload","context","log","console","pageBuilder","taskId","identity","mockSecurity","task","importExportTask","getTask","data","error","message","exportTemplatesDataKey","input","listObjectResponse","s3Stream","listObject","Contents","zipFileKeys","filter","file","Key","map","Boolean","zipOfZip","ZipOfZip","templateExportUpload","process","Location","updateTask","status","ImportExportTaskStatus","COMPLETED","key","url","getPresignedUrl","deleteFilePromises","deleteObject","Promise","all","length","e","FAILED","name","code","exports"],"sources":["templatesHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { s3Stream } from \"../s3Stream\";\nimport { ZipOfZip } from \"../zipper\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { Payload, Response } from \"~/export/combine\";\n\n/**\n * Handles the export templates combine workflow.\n */\nexport const templatesHandler = async (\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n\n log(\"RUNNING Export Templates Combine Handler\");\n const { pageBuilder } = context;\n const { taskId, identity } = payload;\n\n mockSecurity(identity, context);\n\n try {\n const task = await pageBuilder.importExportTask.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 { exportTemplatesDataKey } = task.input;\n\n // Get all files (zip) from given key\n const listObjectResponse = await s3Stream.listObject(exportTemplatesDataKey);\n if (!listObjectResponse.Contents) {\n return {\n data: null,\n error: {\n message: \"There is no Contents defined on S3 Stream while combining templates.\"\n }\n };\n }\n\n const zipFileKeys = listObjectResponse.Contents.filter(\n file => file.Key !== exportTemplatesDataKey\n )\n .map(file => file.Key)\n .filter(Boolean) as string[];\n\n // Prepare zip of all zips\n const zipOfZip = new ZipOfZip(zipFileKeys, \"WEBINY_TEMPLATE_EXPORT.zip\");\n\n // Upload\n const templateExportUpload = await zipOfZip.process();\n log(`Done uploading... File is located at ${templateExportUpload.Location} `);\n\n // Update task status and save export templates data key\n await pageBuilder.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading template export.`,\n key: templateExportUpload.Key,\n url: await s3Stream.getPresignedUrl(templateExportUpload.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_TEMPLATES_COMBINE] Error => \", e.message);\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.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\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"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AAGA;AACA;AACA;AACO,MAAMI,gBAAgB,GAAG,MAAAA,CAC5BC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EAEvBA,GAAG,CAAC,0CAA0C,CAAC;EAC/C,MAAM;IAAEE;EAAY,CAAC,GAAGH,OAAO;EAC/B,MAAM;IAAEI,MAAM;IAAEC;EAAS,CAAC,GAAGN,OAAO;EAEpC,IAAAO,0BAAY,EAACD,QAAQ,EAAEL,OAAO,CAAC;EAE/B,IAAI;IACA,MAAMO,IAAI,GAAG,MAAMJ,WAAW,CAACK,gBAAgB,CAACC,OAAO,CAACL,MAAM,CAAC;IAC/D,IAAI,CAAC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,YAAY,CAACJ,GAAG,CAAC,CAAC;IAC7E,MAAMK,OAAO,CAACC,GAAG,CAACH,kBAAkB,CAAC;IACrCpC,GAAG,CAAE,wBAAuBoC,kBAAkB,CAACI,MAAO,aAAY,CAAC;EACvE,CAAC,CAAC,OAAOC,CAAC,EAAE;IACRzC,GAAG,CAAC,sCAAsC,EAAEyC,CAAC,CAAC9B,OAAO,CAAC;;IAEtD;AACR;AACA;AACA;IACQ,MAAMT,WAAW,CAACK,gBAAgB,CAACsB,UAAU,CAAC1B,MAAM,EAAE;MAClD2B,MAAM,EAAEC,6BAAsB,CAACW,MAAM;MACrChC,KAAK,EAAE;QACHiC,IAAI,EAAEF,CAAC,CAACE,IAAI;QACZhC,OAAO,EAAE8B,CAAC,CAAC9B,OAAO;QAClBiC,IAAI,EAAE;MACV;IACJ,CAAC,CAAC;IAEF,OAAO;MACHnC,IAAI,EAAE,IAAI;MACVC,KAAK,EAAE;QACHC,OAAO,EAAE8B,CAAC,CAAC9B;MACf;IACJ,CAAC;EACL;EACA,OAAO;IACHF,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAACmC,OAAA,CAAAhD,gBAAA,GAAAA,gBAAA"}
@@ -7,9 +7,9 @@ exports.blocksHandler = 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 _BlockExporter = require("./exporters/BlockExporter");
13
13
  /**
14
14
  * Handles the export blocks process workflow.
15
15
  */
@@ -37,7 +37,7 @@ const blocksHandler = 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".
@@ -65,6 +65,11 @@ const blocksHandler = async (configuration, payload, context) => {
65
65
  throw new _handlerGraphql.NotFoundError(`Unable to load block "${blockId}"`);
66
66
  }
67
67
  log(`Processing block key "${blockId}"`);
68
+ const blockCategory = await pageBuilder.getBlockCategory(block.blockCategory);
69
+ if (!blockCategory) {
70
+ log(`Unable to load block category "${block.blockCategory}"`);
71
+ throw new _handlerGraphql.NotFoundError(`Unable to load block category "${block.blockCategory}"`);
72
+ }
68
73
 
69
74
  // Mark task status as PROCESSING
70
75
  subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
@@ -77,8 +82,8 @@ const blocksHandler = async (configuration, payload, context) => {
77
82
  });
78
83
  prevStatusOfSubTask = subTask.status;
79
84
  log(`Extracting block data and uploading to storage...`);
80
- // Extract Block
81
- const blockDataZip = await (0, _utils.exportBlock)(block, exportBlocksDataKey, fileManager);
85
+ const blockExporter = new _BlockExporter.BlockExporter(fileManager);
86
+ const blockDataZip = await blockExporter.execute(block, blockCategory, exportBlocksDataKey);
82
87
  log(`Finish uploading zip...`);
83
88
  // Update task record in DB
84
89
  subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
@@ -159,4 +164,6 @@ const blocksHandler = async (configuration, payload, context) => {
159
164
  error: null
160
165
  };
161
166
  };
162
- exports.blocksHandler = blocksHandler;
167
+ exports.blocksHandler = blocksHandler;
168
+
169
+ //# sourceMappingURL=blocksHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["blocksHandler","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","blockId","exportBlocksDataKey","block","getPageBlock","NotFoundError","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","blockDataZip","exportBlock","COMPLETED","message","key","Key","e","FAILED","name","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process"],"sources":["blocksHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { exportBlock } 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 blocks process workflow.\n */\nexport const blocksHandler = 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 Blocks 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 { blockId, exportBlocksDataKey } = input;\n\n const block = await pageBuilder.getPageBlock(blockId);\n\n if (!block) {\n log(`Unable to load block \"${blockId}\"`);\n throw new NotFoundError(`Unable to load block \"${blockId}\"`);\n }\n\n log(`Processing block key \"${blockId}\"`);\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 block data and uploading to storage...`);\n // Extract Block\n const blockDataZip = await exportBlock(block, exportBlocksDataKey, 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 block \"${block.id}\"`,\n key: blockDataZip.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_BLOCKS_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 block 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 blocks - 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 block 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 blocks - 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,aAAa,GAAG,OACzBC,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,uCAAuC,CAAC;EAC5C,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,IAAAO,eAAO,EAACN,YAAY,EAAE,CAAC,CAAC,CAAC;IACzF;AACR;AACA;AACA;IACQ,IAAI,CAACR,OAAO,IAAIA,OAAO,CAACe,MAAM,KAAKZ,6BAAsB,CAACC,OAAO,EAAE;MAC/DH,aAAa,GAAG,IAAI;MACpB,OAAO;QACHe,IAAI,EAAE,EAAE;QACRC,KAAK,EAAE;MACX,CAAC;IACL,CAAC,MAAM;MACHhB,aAAa,GAAG,KAAK;IACzB;IAEAH,GAAG,CAAE,uBAAsBE,OAAO,CAACkB,EAAG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AAC8C,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","_BlockExporter","blocksHandler","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","blockId","exportBlocksDataKey","block","getPageBlock","NotFoundError","blockCategory","getBlockCategory","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","blockExporter","BlockExporter","blockDataZip","execute","COMPLETED","message","key","Key","e","FAILED","name","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process","exports"],"sources":["blocksHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\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\";\nimport { BlockExporter } from \"./exporters/BlockExporter\";\n\n/**\n * Handles the export blocks process workflow.\n */\nexport const blocksHandler = 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 Blocks 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 { blockId, exportBlocksDataKey } = input;\n\n const block = await pageBuilder.getPageBlock(blockId);\n\n if (!block) {\n log(`Unable to load block \"${blockId}\"`);\n throw new NotFoundError(`Unable to load block \"${blockId}\"`);\n }\n\n log(`Processing block key \"${blockId}\"`);\n\n const blockCategory = await pageBuilder.getBlockCategory(block.blockCategory);\n\n if (!blockCategory) {\n log(`Unable to load block category \"${block.blockCategory}\"`);\n throw new NotFoundError(`Unable to load block category \"${block.blockCategory}\"`);\n }\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 block data and uploading to storage...`);\n const blockExporter = new BlockExporter(fileManager);\n const blockDataZip = await blockExporter.execute(block, blockCategory, exportBlocksDataKey);\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 block \"${block.id}\"`,\n key: blockDataZip.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_BLOCKS_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 block 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 blocks - 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 block 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 blocks - process - subtask\"\n });\n }\n }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S;IACN;IACA,IAAIpC,aAAa,EAAE;MACfH,GAAG,CAAE,gCAA+BS,MAAO,EAAC,CAAC;MAC7C;MACA,MAAM,IAAAqC,2BAAmB,EAAiB;QACtC/C,OAAO;QACP6C,IAAI,EAAE/C,aAAa,CAACkD,QAAQ,CAACC,OAAO;QACpClD,OAAO,EAAE;UACLW,MAAM;UACNE,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAACkD,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN,CAAC,MAAM;MACHlD,OAAO,CAACD,GAAG,CAAE,8BAA6BU,YAAY,GAAG,CAAE,GAAE,CAAC;MAC9D;MACA,MAAM,IAAAoC,2BAAmB,EAAU;QAC/B/C,OAAO;QACP6C,IAAI,EAAE/C,aAAa,CAACkD,QAAQ,CAACK,OAAO;QACpCtD,OAAO,EAAE;UACLW,MAAM;UACNC,YAAY,EAAEA,YAAY,GAAG,CAAC;UAC9BC,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAACkD,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN;EACJ;EACA,OAAO;IACHjC,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAACkC,OAAA,CAAAzD,aAAA,GAAAA,aAAA"}
@@ -0,0 +1,12 @@
1
+ import { BlockCategory, PageBlock } from "@webiny/api-page-builder/types";
2
+ import { File, FileManagerContext } from "@webiny/api-file-manager/types";
3
+ export interface ExportedBlockData {
4
+ block: Pick<PageBlock, "name" | "content">;
5
+ category: BlockCategory;
6
+ files: File[];
7
+ }
8
+ export declare class BlockExporter {
9
+ private fileManager;
10
+ constructor(fileManager: FileManagerContext["fileManager"]);
11
+ execute(block: PageBlock, blockCategory: BlockCategory, exportBlocksDataKey: string): Promise<import("@aws-sdk/client-s3").CompleteMultipartUploadOutput>;
12
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.BlockExporter = void 0;
8
+ var _zipper = _interopRequireDefault(require("../../zipper"));
9
+ var _utils = require("../../utils");
10
+ class BlockExporter {
11
+ constructor(fileManager) {
12
+ this.fileManager = fileManager;
13
+ }
14
+ async execute(block, blockCategory, exportBlocksDataKey) {
15
+ // Extract all files
16
+ const files = (0, _utils.extractFilesFromData)(block.content || {});
17
+ const fileIds = files.map(imageFile => imageFile.id);
18
+ // Get file data for all images
19
+ const imageFilesData = [];
20
+ if (fileIds.length > 0) {
21
+ const [filesData] = await this.fileManager.listFiles({
22
+ where: {
23
+ id_in: fileIds
24
+ }
25
+ });
26
+ imageFilesData.push(...filesData);
27
+ }
28
+
29
+ // Extract the block data in a json file and upload it to S3
30
+ const blockData = {
31
+ block: {
32
+ name: block.name,
33
+ content: block.content
34
+ },
35
+ category: {
36
+ name: blockCategory.name,
37
+ slug: blockCategory.slug,
38
+ icon: blockCategory.icon,
39
+ description: blockCategory.description
40
+ },
41
+ files: imageFilesData
42
+ };
43
+ const blockDataBuffer = Buffer.from(JSON.stringify(blockData));
44
+ const zipper = new _zipper.default({
45
+ exportInfo: {
46
+ files: imageFilesData,
47
+ name: block.name,
48
+ dataBuffer: blockDataBuffer
49
+ },
50
+ archiveFileKey: exportBlocksDataKey
51
+ });
52
+ return zipper.process();
53
+ }
54
+ }
55
+ exports.BlockExporter = BlockExporter;
56
+
57
+ //# sourceMappingURL=BlockExporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_zipper","_interopRequireDefault","require","_utils","BlockExporter","constructor","fileManager","execute","block","blockCategory","exportBlocksDataKey","files","extractFilesFromData","content","fileIds","map","imageFile","id","imageFilesData","length","filesData","listFiles","where","id_in","push","blockData","name","category","slug","icon","description","blockDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","dataBuffer","archiveFileKey","process","exports"],"sources":["BlockExporter.ts"],"sourcesContent":["import { BlockCategory, PageBlock } from \"@webiny/api-page-builder/types\";\nimport { File, FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport Zipper from \"~/export/zipper\";\nimport { extractFilesFromData } from \"~/export/utils\";\n\nexport interface ExportedBlockData {\n block: Pick<PageBlock, \"name\" | \"content\">;\n category: BlockCategory;\n files: File[];\n}\n\nexport class BlockExporter {\n private fileManager: FileManagerContext[\"fileManager\"];\n\n constructor(fileManager: FileManagerContext[\"fileManager\"]) {\n this.fileManager = fileManager;\n }\n\n async execute(block: PageBlock, blockCategory: BlockCategory, exportBlocksDataKey: string) {\n // Extract all files\n const files = extractFilesFromData(block.content || {});\n const fileIds = files.map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await this.fileManager.listFiles({ where: { id_in: fileIds } });\n imageFilesData.push(...filesData);\n }\n\n // Extract the block data in a json file and upload it to S3\n const blockData = {\n block: {\n name: block.name,\n content: block.content\n },\n category: {\n name: blockCategory.name,\n slug: blockCategory.slug,\n icon: blockCategory.icon,\n description: blockCategory.description\n },\n files: imageFilesData\n };\n const blockDataBuffer = Buffer.from(JSON.stringify(blockData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: block.name,\n dataBuffer: blockDataBuffer\n },\n archiveFileKey: exportBlocksDataKey\n });\n\n return zipper.process();\n }\n}\n"],"mappings":";;;;;;;AAEA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAQO,MAAME,aAAa,CAAC;EAGvBC,WAAWA,CAACC,WAA8C,EAAE;IACxD,IAAI,CAACA,WAAW,GAAGA,WAAW;EAClC;EAEA,MAAMC,OAAOA,CAACC,KAAgB,EAAEC,aAA4B,EAAEC,mBAA2B,EAAE;IACvF;IACA,MAAMC,KAAK,GAAG,IAAAC,2BAAoB,EAACJ,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/api-file-manager/types";
3
+ export interface ExportedFormData {
4
+ form: Pick<FbForm, "name" | "status" | "version" | "fields" | "steps" | "settings" | "triggers">;
5
+ files: File[];
6
+ }
7
+ export declare class FormExporter {
8
+ execute(form: FbForm, exportFormsDataKey: string): Promise<import("@aws-sdk/client-s3").CompleteMultipartUploadOutput>;
9
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.FormExporter = void 0;
8
+ var _zipper = _interopRequireDefault(require("../../zipper"));
9
+ class FormExporter {
10
+ async execute(form, exportFormsDataKey) {
11
+ const formData = {
12
+ form: {
13
+ name: form.name,
14
+ status: form.status,
15
+ version: form.version,
16
+ fields: form.fields,
17
+ steps: form.steps,
18
+ settings: form.settings,
19
+ triggers: form.triggers
20
+ }
21
+ };
22
+ const formDataBuffer = Buffer.from(JSON.stringify(formData));
23
+ const zipper = new _zipper.default({
24
+ exportInfo: {
25
+ files: [],
26
+ name: form.name,
27
+ dataBuffer: formDataBuffer
28
+ },
29
+ archiveFileKey: exportFormsDataKey
30
+ });
31
+ return zipper.process();
32
+ }
33
+ }
34
+ exports.FormExporter = FormExporter;
35
+
36
+ //# sourceMappingURL=FormExporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_zipper","_interopRequireDefault","require","FormExporter","execute","form","exportFormsDataKey","formData","name","status","version","fields","steps","settings","triggers","formDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","files","dataBuffer","archiveFileKey","process","exports"],"sources":["FormExporter.ts"],"sourcesContent":["import Zipper from \"~/export/zipper\";\nimport { FbForm } from \"@webiny/api-form-builder/types\";\nimport { File } from \"@webiny/api-file-manager/types\";\n\nexport interface ExportedFormData {\n form: Pick<\n FbForm,\n \"name\" | \"status\" | \"version\" | \"fields\" | \"steps\" | \"settings\" | \"triggers\"\n >;\n files: File[];\n}\n\nexport class FormExporter {\n async execute(form: FbForm, exportFormsDataKey: string) {\n const formData = {\n form: {\n name: form.name,\n status: form.status,\n version: form.version,\n fields: form.fields,\n steps: form.steps,\n settings: form.settings,\n triggers: form.triggers\n }\n };\n const formDataBuffer = Buffer.from(JSON.stringify(formData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: [],\n name: form.name,\n dataBuffer: formDataBuffer\n },\n archiveFileKey: exportFormsDataKey\n });\n\n return zipper.process();\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAYO,MAAMC,YAAY,CAAC;EACtB,MAAMC,OAAOA,CAACC,IAAY,EAAEC,kBAA0B,EAAE;IACpD,MAAMC,QAAQ,GAAG;MACbF,IAAI,EAAE;QACFG,IAAI,EAAEH,IAAI,CAACG,IAAI;QACfC,MAAM,EAAEJ,IAAI,CAACI,MAAM;QACnBC,OAAO,EAAEL,IAAI,CAACK,OAAO;QACrBC,MAAM,EAAEN,IAAI,CAACM,MAAM;QACnBC,KAAK,EAAEP,IAAI,CAACO,KAAK;QACjBC,QAAQ,EAAER,IAAI,CAACQ,QAAQ;QACvBC,QAAQ,EAAET,IAAI,CAACS;MACnB;IACJ,CAAC;IACD,MAAMC,cAAc,GAAGC,MAAM,CAACC,IAAI,CAACC,IAAI,CAACC,SAAS,CAACZ,QAAQ,CAAC,CAAC;IAE5D,MAAMa,MAAM,GAAG,IAAIC,eAAM,CAAC;MACtBC,UAAU,EAAE;QACRC,KAAK,EAAE,EAAE;QACTf,IAAI,EAAEH,IAAI,CAACG,IAAI;QACfgB,UAAU,EAAET;MAChB,CAAC;MACDU,cAAc,EAAEnB;IACpB,CAAC,CAAC;IAEF,OAAOc,MAAM,CAACM,OAAO,CAAC,CAAC;EAC3B;AACJ;AAACC,OAAA,CAAAxB,YAAA,GAAAA,YAAA"}
@@ -0,0 +1,11 @@
1
+ import { Page } from "@webiny/api-page-builder/types";
2
+ import { File, FileManagerContext } from "@webiny/api-file-manager/types";
3
+ export interface ExportedPageData {
4
+ page: Pick<Page, "content" | "title" | "version" | "status" | "settings" | "path">;
5
+ files: File[];
6
+ }
7
+ export declare class PageExporter {
8
+ private fileManager;
9
+ constructor(fileManager: FileManagerContext["fileManager"]);
10
+ execute(page: Page, exportPagesDataKey: string): Promise<import("@aws-sdk/client-s3").CompleteMultipartUploadOutput>;
11
+ }