@webiny/api-page-builder-import-export 0.0.0-unstable.d7f521b032 → 0.0.0-unstable.de38392959
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.
- package/client.js +12 -21
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.js +4 -2
- package/export/combine/blocksHandler.js.map +1 -1
- package/export/combine/formsHandler.d.ts +6 -0
- package/export/combine/formsHandler.js +101 -0
- package/export/combine/formsHandler.js.map +1 -0
- package/export/combine/index.js +24 -15
- package/export/combine/index.js.map +1 -1
- package/export/combine/pagesHandler.js +4 -2
- package/export/combine/pagesHandler.js.map +1 -1
- package/export/combine/templatesHandler.js +4 -2
- package/export/combine/templatesHandler.js.map +1 -1
- package/export/process/blocksHandler.js +13 -6
- package/export/process/blocksHandler.js.map +1 -1
- package/export/process/exporters/BlockExporter.d.ts +12 -0
- package/export/process/exporters/BlockExporter.js +57 -0
- package/export/process/exporters/BlockExporter.js.map +1 -0
- package/export/process/exporters/FormExporter.d.ts +9 -0
- package/export/process/exporters/FormExporter.js +36 -0
- package/export/process/exporters/FormExporter.js.map +1 -0
- package/export/process/exporters/PageExporter.d.ts +11 -0
- package/export/process/exporters/PageExporter.js +58 -0
- package/export/process/exporters/PageExporter.js.map +1 -0
- package/export/process/exporters/PageTemplateExporter.d.ts +11 -0
- package/export/process/exporters/PageTemplateExporter.js +56 -0
- package/export/process/exporters/PageTemplateExporter.js.map +1 -0
- package/export/process/formsHandler.d.ts +6 -0
- package/export/process/formsHandler.js +189 -0
- package/export/process/formsHandler.js.map +1 -0
- package/export/process/index.js +24 -15
- package/export/process/index.js.map +1 -1
- package/export/process/pagesHandler.js +8 -6
- package/export/process/pagesHandler.js.map +1 -1
- package/export/process/templatesHandler.js +8 -6
- package/export/process/templatesHandler.js.map +1 -1
- package/export/s3Stream.d.ts +13 -10
- package/export/s3Stream.js +27 -22
- package/export/s3Stream.js.map +1 -1
- package/export/utils.d.ts +10 -8
- package/export/utils.js +29 -18
- package/export/utils.js.map +1 -1
- package/export/zipper.d.ts +5 -5
- package/export/zipper.js +20 -24
- package/export/zipper.js.map +1 -1
- package/graphql/crud/blocks.crud.js +50 -28
- package/graphql/crud/blocks.crud.js.map +1 -1
- package/graphql/crud/forms.crud.d.ts +4 -0
- package/graphql/crud/forms.crud.js +163 -0
- package/graphql/crud/forms.crud.js.map +1 -0
- package/graphql/crud/importExportTasks.crud.js +81 -63
- package/graphql/crud/importExportTasks.crud.js.map +1 -1
- package/graphql/crud/pages.crud.d.ts +1 -0
- package/graphql/crud/pages.crud.js +58 -24
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.js +48 -15
- package/graphql/crud/templates.crud.js.map +1 -1
- package/graphql/crud.js +5 -2
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.js +4 -2
- package/graphql/graphql/blocks.gql.js.map +1 -1
- package/graphql/graphql/forms.gql.d.ts +4 -0
- package/graphql/graphql/forms.gql.js +62 -0
- package/graphql/graphql/forms.gql.js.map +1 -0
- package/graphql/graphql/importExportTasks.gql.js +3 -1
- package/graphql/graphql/importExportTasks.gql.js.map +1 -1
- package/graphql/graphql/pages.gql.js +3 -1
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.js +3 -1
- package/graphql/graphql/templates.gql.js.map +1 -1
- package/graphql/graphql/utils/resolve.d.ts +1 -1
- package/graphql/graphql/utils/resolve.js +3 -1
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/graphql.js +5 -2
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.js +3 -1
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +136 -1
- package/graphql/types.js +3 -1
- package/graphql/types.js.map +1 -1
- package/import/constants.d.ts +3 -0
- package/import/constants.js +16 -0
- package/import/constants.js.map +1 -0
- package/import/create/blocksHandler.js +7 -6
- package/import/create/blocksHandler.js.map +1 -1
- package/import/{process/pagesHandler.d.ts → create/formsHandler.d.ts} +1 -1
- package/import/create/formsHandler.js +105 -0
- package/import/create/formsHandler.js.map +1 -0
- package/import/create/index.js +24 -15
- package/import/create/index.js.map +1 -1
- package/import/create/pagesHandler.js +6 -3
- package/import/create/pagesHandler.js.map +1 -1
- package/import/create/templatesHandler.js +5 -2
- package/import/create/templatesHandler.js.map +1 -1
- package/import/process/{blocksHandler.d.ts → blocks/blocksHandler.d.ts} +2 -2
- package/import/process/{blocksHandler.js → blocks/blocksHandler.js} +13 -13
- package/import/process/blocks/blocksHandler.js.map +1 -0
- package/import/process/blocks/importBlock.d.ts +11 -0
- package/import/process/blocks/importBlock.js +98 -0
- package/import/process/blocks/importBlock.js.map +1 -0
- package/import/process/forms/formsHandler.d.ts +3 -0
- package/import/process/forms/formsHandler.js +178 -0
- package/import/process/forms/formsHandler.js.map +1 -0
- package/import/process/forms/importForm.d.ts +9 -0
- package/import/process/forms/importForm.js +47 -0
- package/import/process/forms/importForm.js.map +1 -0
- package/import/process/index.js +27 -18
- package/import/process/index.js.map +1 -1
- package/import/process/pages/importPage.d.ts +11 -0
- package/import/process/pages/importPage.js +94 -0
- package/import/process/pages/importPage.js.map +1 -0
- package/import/process/pages/pagesHandler.d.ts +3 -0
- package/import/process/{pagesHandler.js → pages/pagesHandler.js} +16 -8
- package/import/process/pages/pagesHandler.js.map +1 -0
- package/import/process/templates/importTemplate.d.ts +11 -0
- package/import/process/templates/importTemplate.js +70 -0
- package/import/process/templates/importTemplate.js.map +1 -0
- package/import/process/{templatesHandler.d.ts → templates/templatesHandler.d.ts} +2 -2
- package/import/process/{templatesHandler.js → templates/templatesHandler.js} +11 -8
- package/import/process/templates/templatesHandler.js.map +1 -0
- package/import/utils/deleteS3Folder.d.ts +1 -0
- package/import/utils/deleteS3Folder.js +21 -0
- package/import/utils/deleteS3Folder.js.map +1 -0
- package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
- package/import/utils/extractAndUploadZipFileContents.js +123 -0
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
- package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
- package/import/utils/extractZipAndUploadToS3.js +100 -0
- package/import/utils/extractZipAndUploadToS3.js.map +1 -0
- package/import/utils/getFileNameWithoutExt.d.ts +1 -0
- package/import/utils/getFileNameWithoutExt.js +13 -0
- package/import/utils/getFileNameWithoutExt.js.map +1 -0
- package/import/utils/index.d.ts +9 -0
- package/import/utils/index.js +106 -0
- package/import/utils/index.js.map +1 -0
- package/import/utils/initialStats.d.ts +7 -0
- package/import/utils/initialStats.js +18 -0
- package/import/utils/initialStats.js.map +1 -0
- package/import/utils/prepareDataDirMap.d.ts +6 -0
- package/import/utils/prepareDataDirMap.js +31 -0
- package/import/utils/prepareDataDirMap.js.map +1 -0
- package/import/utils/updateFilesInData.d.ts +8 -0
- package/import/utils/updateFilesInData.js +51 -0
- package/import/utils/updateFilesInData.js.map +1 -0
- package/import/utils/uploadAssets.d.ts +10 -0
- package/import/utils/uploadAssets.js +92 -0
- package/import/utils/uploadAssets.js.map +1 -0
- package/import/utils/uploadFilesFromS3.d.ts +3 -0
- package/import/utils/uploadFilesFromS3.js +21 -0
- package/import/utils/uploadFilesFromS3.js.map +1 -0
- package/mockSecurity.js +3 -2
- package/mockSecurity.js.map +1 -1
- package/package.json +35 -43
- package/types.d.ts +21 -0
- package/types.js +62 -8
- package/types.js.map +1 -1
- package/import/process/blocksHandler.js.map +0 -1
- package/import/process/pagesHandler.js.map +0 -1
- package/import/process/templatesHandler.js.map +0 -1
- package/import/utils.d.ts +0 -56
- package/import/utils.js +0 -607
- package/import/utils.js.map +0 -1
@@ -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
|
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,
|
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".
|
@@ -81,8 +81,8 @@ const templatesHandler = async (configuration, payload, context) => {
|
|
81
81
|
});
|
82
82
|
prevStatusOfSubTask = subTask.status;
|
83
83
|
log(`Extracting template data and uploading to storage...`);
|
84
|
-
|
85
|
-
const templateDataZip = await
|
84
|
+
const templateExporter = new _PageTemplateExporter.PageTemplateExporter(fileManager);
|
85
|
+
const templateDataZip = await templateExporter.execute(template, exportTemplatesDataKey);
|
86
86
|
log(`Finish uploading zip...`);
|
87
87
|
// Update task record in DB
|
88
88
|
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
@@ -163,4 +163,6 @@ const templatesHandler = async (configuration, payload, context) => {
|
|
163
163
|
error: null
|
164
164
|
};
|
165
165
|
};
|
166
|
-
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","where","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({ 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 // 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,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,EAAC,CAAC;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UACLW,MAAM;UACNE,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAAC+C,QAAQ,CAACC,WAAW;QAC1C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN,CAAC,MAAM;MACH/C,OAAO,CAACD,GAAG,CAAE,8BAA6BU,YAAY,GAAG,CAAE,GAAE,CAAC;MAC9D;MACA,MAAM,IAAAiC,2BAAmB,EAAU;QAC/B5C,OAAO;QACP0C,IAAI,EAAE5C,aAAa,CAAC+C,QAAQ,CAACK,OAAO;QACpCnD,OAAO,EAAE;UACLW,MAAM;UACNC,YAAY,EAAEA,YAAY,GAAG,CAAC;UAC9BC,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAAC+C,QAAQ,CAACC,WAAW;QAC1C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN;EACJ;EACA,OAAO;IACH9B,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 { 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 { 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":";;;;;;AAAA,IAAAA,MAAA,G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Q,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN,CAAC,MAAM;MACHjD,OAAO,CAACD,GAAG,CAAE,8BAA6BU,YAAY,GAAG,CAAE,GAAE,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"}
|
package/export/s3Stream.d.ts
CHANGED
@@ -1,31 +1,34 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
/// <reference types="node" />
|
3
|
-
import {
|
4
|
-
import S3 from "aws-sdk/
|
3
|
+
import { Readable } from "stream";
|
4
|
+
import { S3, ListObjectsOutput, DeleteObjectOutput, HeadObjectOutput } from "@webiny/aws-sdk/client-s3";
|
5
5
|
declare class S3Stream {
|
6
6
|
s3: S3;
|
7
7
|
bucket: string;
|
8
8
|
constructor();
|
9
|
-
getPresignedUrl(key
|
9
|
+
getPresignedUrl(key?: string): Promise<string>;
|
10
10
|
/**
|
11
11
|
* We're checking if the file is accessible on S3 by getting object meta data.
|
12
12
|
* It help us to filter files that we need to download as part of export data.
|
13
13
|
* @param Key {string}
|
14
14
|
*/
|
15
15
|
isFileAccessible(Key: string): Promise<boolean>;
|
16
|
-
getObjectHead(Key: string): Promise<
|
17
|
-
readStream(Key: string): Readable
|
16
|
+
getObjectHead(Key: string): Promise<HeadObjectOutput>;
|
17
|
+
readStream(Key: string): Promise<Readable>;
|
18
18
|
writeStream(Key: string, contentType?: string): {
|
19
|
-
streamPassThrough: PassThrough;
|
20
|
-
|
19
|
+
streamPassThrough: import("stream").PassThrough;
|
20
|
+
/**
|
21
|
+
* We're not using the `FileManager` storage plugin here because it currently doesn't support streams.
|
22
|
+
*/
|
23
|
+
streamPassThroughUploadPromise: Promise<import("@aws-sdk/client-s3").AbortMultipartUploadCommandOutput | import("@webiny/aws-sdk/client-s3").CompleteMultipartUploadCommandOutput>;
|
21
24
|
};
|
22
25
|
upload(params: {
|
23
26
|
Key: string;
|
24
27
|
ContentType: string;
|
25
28
|
Body: Buffer;
|
26
|
-
}): Promise<
|
27
|
-
listObject(prefix: string): Promise<
|
28
|
-
deleteObject(key: string): Promise<
|
29
|
+
}): Promise<void>;
|
30
|
+
listObject(prefix: string): Promise<ListObjectsOutput>;
|
31
|
+
deleteObject(key: string): Promise<DeleteObjectOutput>;
|
29
32
|
}
|
30
33
|
export declare const s3Stream: S3Stream;
|
31
34
|
export {};
|
package/export/s3Stream.js
CHANGED
@@ -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
|
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
|
-
|
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.
|
19
|
+
return (0, _clientS.getSignedUrl)(this.s3, new _clientS.GetObjectCommand({
|
24
20
|
Bucket: this.bucket,
|
25
|
-
Key: key
|
26
|
-
|
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
|
-
})
|
46
|
+
});
|
50
47
|
}
|
51
|
-
readStream(Key) {
|
52
|
-
|
48
|
+
async readStream(Key) {
|
49
|
+
const response = await this.s3.send(new _clientS.GetObjectCommand({
|
53
50
|
Bucket: this.bucket,
|
54
51
|
Key
|
55
|
-
})
|
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,39 @@ 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:
|
73
|
+
streamPassThroughUploadPromise: upload.done()
|
72
74
|
};
|
73
75
|
}
|
74
|
-
upload(params) {
|
75
|
-
|
76
|
+
async upload(params) {
|
77
|
+
await this.s3.send(new _clientS.PutObjectCommand({
|
76
78
|
ACL: "private",
|
77
|
-
Bucket: this.bucket
|
78
|
-
|
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
|
-
})
|
87
|
+
});
|
85
88
|
}
|
86
89
|
deleteObject(key) {
|
87
90
|
return this.s3.deleteObject({
|
88
91
|
Key: key,
|
89
92
|
Bucket: this.bucket
|
90
|
-
})
|
93
|
+
});
|
91
94
|
}
|
92
95
|
}
|
93
96
|
const s3Stream = new S3Stream();
|
94
|
-
exports.s3Stream = s3Stream;
|
97
|
+
exports.s3Stream = s3Stream;
|
98
|
+
|
99
|
+
//# sourceMappingURL=s3Stream.js.map
|
package/export/s3Stream.js.map
CHANGED
@@ -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","
|
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 { Stream, Readable } from \"stream\";\nimport {\n S3,\n ListObjectsOutput,\n DeleteObjectOutput,\n HeadObjectOutput,\n getSignedUrl,\n GetObjectCommand,\n PutObjectCommand,\n PutObjectCommandInput\n} from \"@webiny/aws-sdk/client-s3\";\nimport { Upload } from \"@webiny/aws-sdk/lib-storage\";\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}\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AAG,IAAI/C,QAAQ,CAAC,CAAC;AAACgD,OAAA,CAAAD,QAAA,GAAAA,QAAA"}
|
package/export/utils.d.ts
CHANGED
@@ -1,22 +1,24 @@
|
|
1
|
-
import
|
2
|
-
import { Page, PageBlock, PageTemplate } from "@webiny/api-page-builder/types";
|
1
|
+
import { CompleteMultipartUploadOutput } from "@webiny/aws-sdk/client-s3";
|
2
|
+
import { BlockCategory, Page, PageBlock, PageTemplate } from "@webiny/api-page-builder/types";
|
3
3
|
import { 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<
|
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"
|
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<
|
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" | "slug" | "tags" | "description" | "content" | "layout">;
|
20
|
+
template: Pick<PageTemplate, "title" | "slug" | "tags" | "description" | "content" | "layout" | "pageCategory">;
|
19
21
|
files: File[];
|
20
22
|
}
|
21
|
-
export declare function exportTemplate(template: PageTemplate, exportTemplatesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<
|
22
|
-
export declare function extractFilesFromData(data: Record<string, any>, files?:
|
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,7 +4,7 @@ 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;
|
@@ -17,6 +17,8 @@ const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
|
|
17
17
|
exports.EXPORT_BLOCKS_FOLDER_KEY = EXPORT_BLOCKS_FOLDER_KEY;
|
18
18
|
const EXPORT_TEMPLATES_FOLDER_KEY = "WEBINY_PB_EXPORT_TEMPLATE";
|
19
19
|
exports.EXPORT_TEMPLATES_FOLDER_KEY = EXPORT_TEMPLATES_FOLDER_KEY;
|
20
|
+
const EXPORT_FORMS_FOLDER_KEY = "WEBINY_FB_EXPORT_FORM";
|
21
|
+
exports.EXPORT_FORMS_FOLDER_KEY = EXPORT_FORMS_FOLDER_KEY;
|
20
22
|
async function exportPage(page, exportPagesDataKey, fileManager) {
|
21
23
|
// Extract all files
|
22
24
|
const files = extractFilesFromData(page.content || {});
|
@@ -26,8 +28,10 @@ async function exportPage(page, exportPagesDataKey, fileManager) {
|
|
26
28
|
// Get file data for all images
|
27
29
|
const imageFilesData = [];
|
28
30
|
if (fileIds.length > 0) {
|
29
|
-
const [filesData] = await fileManager.
|
30
|
-
|
31
|
+
const [filesData] = await fileManager.listFiles({
|
32
|
+
where: {
|
33
|
+
id_in: fileIds
|
34
|
+
}
|
31
35
|
});
|
32
36
|
imageFilesData.push(...filesData);
|
33
37
|
}
|
@@ -55,29 +59,32 @@ async function exportPage(page, exportPagesDataKey, fileManager) {
|
|
55
59
|
});
|
56
60
|
return zipper.process();
|
57
61
|
}
|
58
|
-
async function exportBlock(block, exportBlocksDataKey, fileManager) {
|
62
|
+
async function exportBlock(block, blockCategory, exportBlocksDataKey, fileManager) {
|
59
63
|
// Extract all files
|
60
64
|
const files = extractFilesFromData(block.content || {});
|
61
65
|
const fileIds = files.map(imageFile => imageFile.id);
|
62
66
|
// Get file data for all images
|
63
67
|
const imageFilesData = [];
|
64
68
|
if (fileIds.length > 0) {
|
65
|
-
const [filesData] = await fileManager.
|
66
|
-
|
69
|
+
const [filesData] = await fileManager.listFiles({
|
70
|
+
where: {
|
71
|
+
id_in: fileIds
|
72
|
+
}
|
67
73
|
});
|
68
74
|
imageFilesData.push(...filesData);
|
69
75
|
}
|
70
|
-
// Add block preview image file data
|
71
|
-
if (block.preview.id) {
|
72
|
-
imageFilesData.push(await fileManager.files.getFile(block.preview.id));
|
73
|
-
}
|
74
76
|
|
75
77
|
// Extract the block data in a json file and upload it to S3
|
76
78
|
const blockData = {
|
77
79
|
block: {
|
78
80
|
name: block.name,
|
79
|
-
content: block.content
|
80
|
-
|
81
|
+
content: block.content
|
82
|
+
},
|
83
|
+
category: {
|
84
|
+
name: blockCategory.name,
|
85
|
+
slug: blockCategory.slug,
|
86
|
+
icon: blockCategory.icon,
|
87
|
+
description: blockCategory.description
|
81
88
|
},
|
82
89
|
files: imageFilesData
|
83
90
|
};
|
@@ -99,8 +106,10 @@ async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
|
|
99
106
|
// Get file data for all images
|
100
107
|
const imageFilesData = [];
|
101
108
|
if (fileIds.length > 0) {
|
102
|
-
const [filesData] = await fileManager.
|
103
|
-
|
109
|
+
const [filesData] = await fileManager.listFiles({
|
110
|
+
where: {
|
111
|
+
id_in: fileIds
|
112
|
+
}
|
104
113
|
});
|
105
114
|
imageFilesData.push(...filesData);
|
106
115
|
}
|
@@ -113,7 +122,8 @@ async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
|
|
113
122
|
tags: template.tags,
|
114
123
|
description: template.description,
|
115
124
|
content: template.content,
|
116
|
-
layout: template.layout
|
125
|
+
layout: template.layout,
|
126
|
+
pageCategory: template.pageCategory
|
117
127
|
},
|
118
128
|
files: imageFilesData
|
119
129
|
};
|
@@ -129,10 +139,10 @@ async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
|
|
129
139
|
return zipper.process();
|
130
140
|
}
|
131
141
|
function extractFilesFromData(data, files = []) {
|
132
|
-
// Base case: termination
|
133
142
|
if (!data || typeof data !== "object") {
|
134
143
|
return files;
|
135
144
|
}
|
145
|
+
|
136
146
|
// Recursively call function for each element
|
137
147
|
if (Array.isArray(data)) {
|
138
148
|
for (let i = 0; i < data.length; i++) {
|
@@ -146,7 +156,6 @@ function extractFilesFromData(data, files = []) {
|
|
146
156
|
const tuple = Object.entries(data);
|
147
157
|
for (let i = 0; i < tuple.length; i++) {
|
148
158
|
const [key, value] = tuple[i];
|
149
|
-
// TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.
|
150
159
|
if (key === "file" && value) {
|
151
160
|
files.push(value);
|
152
161
|
} else if (key === "images" && Array.isArray(value)) {
|
@@ -157,4 +166,6 @@ function extractFilesFromData(data, files = []) {
|
|
157
166
|
}
|
158
167
|
}
|
159
168
|
return files;
|
160
|
-
}
|
169
|
+
}
|
170
|
+
|
171
|
+
//# sourceMappingURL=utils.js.map
|
package/export/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["EXPORT_PAGES_FOLDER_KEY","EXPORT_BLOCKS_FOLDER_KEY","EXPORT_TEMPLATES_FOLDER_KEY","exportPage","page","exportPagesDataKey","fileManager","files","extractFilesFromData","content","pageSettingsImages","get","filter","image","src","fileIds","map","imageFile","id","imageFilesData","length","filesData","listFiles","ids","push","pageData","title","path","version","status","settings","pageDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","name","dataBuffer","archiveFileKey","process","exportBlock","block","exportBlocksDataKey","preview","getFile","blockData","blockDataBuffer","exportTemplate","template","exportTemplatesDataKey","templateData","slug","tags","description","layout","templateDataBuffer","data","Array","isArray","i","element","tuple","Object","entries","key","value"],"sources":["utils.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { Page, PageBlock, PageTemplate } from \"@webiny/api-page-builder/types\";\nimport { FileManagerContext, File } from \"@webiny/api-file-manager/types\";\nimport get from \"lodash/get\";\nimport Zipper from \"./zipper\";\n\nexport const EXPORT_PAGES_FOLDER_KEY = \"WEBINY_PB_EXPORT_PAGES\";\nexport const EXPORT_BLOCKS_FOLDER_KEY = \"WEBINY_PB_EXPORT_BLOCK\";\nexport const EXPORT_TEMPLATES_FOLDER_KEY = \"WEBINY_PB_EXPORT_TEMPLATE\";\n\nexport interface ExportedPageData {\n page: Pick<Page, \"content\" | \"title\" | \"version\" | \"status\" | \"settings\" | \"path\">;\n files: File[];\n}\n\nexport async function exportPage(\n page: Page,\n exportPagesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<S3.ManagedUpload.SendData> {\n // Extract all files\n const files = extractFilesFromData(page.content || {});\n // Extract images from page settings\n const pageSettingsImages = [\n get(page, \"settings.general.image\") as unknown as File,\n get(page, \"settings.social.image\") as unknown as File\n ].filter(image => image && image.src);\n\n const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.files.listFiles({ ids: fileIds });\n imageFilesData.push(...filesData);\n }\n\n // Extract the page data in a json file and upload it to S3\n const pageData = {\n page: {\n content: page.content,\n title: page.title,\n path: page.path,\n version: page.version,\n status: page.status,\n settings: page.settings\n },\n files: imageFilesData\n };\n const pageDataBuffer = Buffer.from(JSON.stringify(pageData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: page.title,\n dataBuffer: pageDataBuffer\n },\n archiveFileKey: exportPagesDataKey\n });\n\n return zipper.process();\n}\n\nexport interface ExportedBlockData {\n block: Pick<PageBlock, \"name\" | \"content\" | \"preview\">;\n files: File[];\n}\n\nexport async function exportBlock(\n block: PageBlock,\n exportBlocksDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<S3.ManagedUpload.SendData> {\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 fileManager.files.listFiles({ ids: fileIds });\n imageFilesData.push(...filesData);\n }\n // Add block preview image file data\n if (block.preview.id) {\n imageFilesData.push(await fileManager.files.getFile(block.preview.id));\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 preview: block.preview\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\nexport interface ExportedTemplateData {\n template: Pick<PageTemplate, \"title\" | \"slug\" | \"tags\" | \"description\" | \"content\" | \"layout\">;\n files: File[];\n}\n\nexport async function exportTemplate(\n template: PageTemplate,\n exportTemplatesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<S3.ManagedUpload.SendData> {\n // Extract all files\n const files = extractFilesFromData(template.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 fileManager.files.listFiles({ ids: fileIds });\n imageFilesData.push(...filesData);\n }\n\n // Extract the template data in a json file and upload it to S3\n const templateData = {\n template: {\n title: template.title,\n slug: template.slug,\n tags: template.tags,\n description: template.description,\n content: template.content,\n layout: template.layout\n },\n files: imageFilesData\n };\n const templateDataBuffer = Buffer.from(JSON.stringify(templateData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: template.title,\n dataBuffer: templateDataBuffer\n },\n archiveFileKey: exportTemplatesDataKey\n });\n\n return zipper.process();\n}\n\nexport function extractFilesFromData(data: Record<string, any>, files: any[] = []): File[] {\n // Base case: termination\n if (!data || typeof data !== \"object\") {\n return files;\n }\n // Recursively call function for each element\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const element = data[i];\n extractFilesFromData(element, files);\n }\n return files;\n }\n\n // Main\n const tuple = Object.entries(data);\n for (let i = 0; i < tuple.length; i++) {\n const [key, value] = tuple[i];\n // TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.\n if (key === \"file\" && value) {\n files.push(value);\n } else if (key === \"images\" && Array.isArray(value)) {\n // Handle case for \"images-list\" component\n files.push(...value);\n } else {\n extractFilesFromData(value, files);\n }\n }\n return files;\n}\n"],"mappings":";;;;;;;;;;;AAGA;AACA;AAEO,MAAMA,uBAAuB,GAAG,wBAAwB;AAAC;AACzD,MAAMC,wBAAwB,GAAG,wBAAwB;AAAC;AAC1D,MAAMC,2BAA2B,GAAG,2BAA2B;AAAC;AAOhE,eAAeC,UAAU,CAC5BC,IA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
1
|
+
{"version":3,"names":["_get","_interopRequireDefault","require","_zipper","EXPORT_PAGES_FOLDER_KEY","exports","EXPORT_BLOCKS_FOLDER_KEY","EXPORT_TEMPLATES_FOLDER_KEY","EXPORT_FORMS_FOLDER_KEY","exportPage","page","exportPagesDataKey","fileManager","files","extractFilesFromData","content","pageSettingsImages","get","filter","image","src","fileIds","map","imageFile","id","imageFilesData","length","filesData","listFiles","where","id_in","push","pageData","title","path","version","status","settings","pageDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","name","dataBuffer","archiveFileKey","process","exportBlock","block","blockCategory","exportBlocksDataKey","blockData","category","slug","icon","description","blockDataBuffer","exportTemplate","template","exportTemplatesDataKey","templateData","tags","layout","pageCategory","templateDataBuffer","data","Array","isArray","i","element","tuple","Object","entries","key","value"],"sources":["utils.ts"],"sourcesContent":["import { CompleteMultipartUploadOutput } from \"@webiny/aws-sdk/client-s3\";\nimport { BlockCategory, Page, PageBlock, PageTemplate } from \"@webiny/api-page-builder/types\";\nimport { FileManagerContext, File } from \"@webiny/api-file-manager/types\";\nimport get from \"lodash/get\";\nimport Zipper from \"./zipper\";\n\nexport const EXPORT_PAGES_FOLDER_KEY = \"WEBINY_PB_EXPORT_PAGES\";\nexport const EXPORT_BLOCKS_FOLDER_KEY = \"WEBINY_PB_EXPORT_BLOCK\";\nexport const EXPORT_TEMPLATES_FOLDER_KEY = \"WEBINY_PB_EXPORT_TEMPLATE\";\nexport const EXPORT_FORMS_FOLDER_KEY = \"WEBINY_FB_EXPORT_FORM\";\n\nexport interface ExportedPageData {\n page: Pick<Page, \"content\" | \"title\" | \"version\" | \"status\" | \"settings\" | \"path\">;\n files: File[];\n}\n\nexport async function exportPage(\n page: Page,\n exportPagesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<CompleteMultipartUploadOutput> {\n // Extract all files\n const files = extractFilesFromData(page.content || {});\n // Extract images from page settings\n const pageSettingsImages = [\n get(page, \"settings.general.image\") as unknown as File,\n get(page, \"settings.social.image\") as unknown as File\n ].filter(image => image && image.src);\n\n const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.listFiles({ where: { id_in: fileIds } });\n imageFilesData.push(...filesData);\n }\n\n // Extract the page data in a json file and upload it to S3\n const pageData = {\n page: {\n content: page.content,\n title: page.title,\n path: page.path,\n version: page.version,\n status: page.status,\n settings: page.settings\n },\n files: imageFilesData\n };\n const pageDataBuffer = Buffer.from(JSON.stringify(pageData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: page.title,\n dataBuffer: pageDataBuffer\n },\n archiveFileKey: exportPagesDataKey\n });\n\n return zipper.process();\n}\n\nexport interface ExportedBlockData {\n block: Pick<PageBlock, \"name\" | \"content\">;\n category: BlockCategory;\n files: File[];\n}\n\nexport async function exportBlock(\n block: PageBlock,\n blockCategory: BlockCategory,\n exportBlocksDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<CompleteMultipartUploadOutput> {\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 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\nexport interface ExportedTemplateData {\n template: Pick<\n PageTemplate,\n \"title\" | \"slug\" | \"tags\" | \"description\" | \"content\" | \"layout\" | \"pageCategory\"\n >;\n files: File[];\n}\n\nexport async function exportTemplate(\n template: PageTemplate,\n exportTemplatesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<CompleteMultipartUploadOutput> {\n // Extract all files\n const files = extractFilesFromData(template.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 fileManager.listFiles({ where: { id_in: fileIds } });\n imageFilesData.push(...filesData);\n }\n\n // Extract the template data in a json file and upload it to S3\n const templateData = {\n template: {\n title: template.title,\n slug: template.slug,\n tags: template.tags,\n description: template.description,\n content: template.content,\n layout: template.layout,\n pageCategory: template.pageCategory\n },\n files: imageFilesData\n };\n const templateDataBuffer = Buffer.from(JSON.stringify(templateData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: template.title,\n dataBuffer: templateDataBuffer\n },\n archiveFileKey: exportTemplatesDataKey\n });\n\n return zipper.process();\n}\n\nexport function extractFilesFromData(data: Record<string, any>, files: File[] = []) {\n if (!data || typeof data !== \"object\") {\n return files;\n }\n\n // Recursively call function for each element\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const element = data[i];\n extractFilesFromData(element, files);\n }\n return files;\n }\n\n // Main\n const tuple = Object.entries(data);\n for (let i = 0; i < tuple.length; i++) {\n const [key, value] = tuple[i];\n if (key === \"file\" && value) {\n files.push(value);\n } else if (key === \"images\" && Array.isArray(value)) {\n // Handle case for \"images-list\" component\n files.push(...value);\n } else {\n extractFilesFromData(value, files);\n }\n }\n return files;\n}\n"],"mappings":";;;;;;;;;;;AAGA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEO,MAAME,uBAAuB,GAAG,wBAAwB;AAACC,OAAA,CAAAD,uBAAA,GAAAA,uBAAA;AACzD,MAAME,wBAAwB,GAAG,wBAAwB;AAACD,OA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KAAK,CAACkB,IAAI,CAAC8C,KAAK,CAAC;IACrB,CAAC,MAAM,IAAID,GAAG,KAAK,QAAQ,IAAIP,KAAK,CAACC,OAAO,CAACO,KAAK,CAAC,EAAE;MACjD;MACAhE,KAAK,CAACkB,IAAI,CAAC,GAAG8C,KAAK,CAAC;IACxB,CAAC,MAAM;MACH/D,oBAAoB,CAAC+D,KAAK,EAAEhE,KAAK,CAAC;IACtC;EACJ;EACA,OAAOA,KAAK;AAChB"}
|
package/export/zipper.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
/// <reference types="node" />
|
3
|
-
import
|
3
|
+
import { CompleteMultipartUploadOutput } from "@webiny/aws-sdk/client-s3";
|
4
4
|
import { Readable } from "stream";
|
5
5
|
import { File } from "@webiny/api-file-manager/types";
|
6
6
|
interface FileStreamDetails {
|
@@ -22,8 +22,8 @@ export default class Zipper {
|
|
22
22
|
private readonly archiveFileName;
|
23
23
|
config: ZipperConfig;
|
24
24
|
constructor(config: ZipperConfig);
|
25
|
-
s3DownloadStreams(): FileStreamDetails[]
|
26
|
-
process(): Promise<
|
25
|
+
s3DownloadStreams(): Promise<FileStreamDetails[]>;
|
26
|
+
process(): Promise<CompleteMultipartUploadOutput>;
|
27
27
|
}
|
28
28
|
export declare class ZipOfZip {
|
29
29
|
private readonly archiveFormat;
|
@@ -31,7 +31,7 @@ export declare class ZipOfZip {
|
|
31
31
|
keys: string[];
|
32
32
|
filename: string;
|
33
33
|
constructor(keys: string[], filename: string);
|
34
|
-
getFileStreams(): FileStreamDetails[]
|
35
|
-
process(): Promise<
|
34
|
+
getFileStreams(): Promise<FileStreamDetails[]>;
|
35
|
+
process(): Promise<CompleteMultipartUploadOutput>;
|
36
36
|
}
|
37
37
|
export {};
|
package/export/zipper.js
CHANGED
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
7
7
|
});
|
8
8
|
exports.default = exports.ZipOfZip = void 0;
|
9
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
10
9
|
var _archiver = _interopRequireDefault(require("archiver"));
|
11
10
|
var _stream = require("stream");
|
12
11
|
var path = _interopRequireWildcard(require("path"));
|
@@ -16,38 +15,36 @@ var _s3Stream = require("./s3Stream");
|
|
16
15
|
// TODO: Move "archive" in layer
|
17
16
|
|
18
17
|
class Zipper {
|
18
|
+
archiveFormat = "zip";
|
19
|
+
filesDirName = "assets";
|
19
20
|
constructor(config) {
|
20
|
-
(0, _defineProperty2.default)(this, "archiveFormat", "zip");
|
21
|
-
(0, _defineProperty2.default)(this, "filesDirName", "assets");
|
22
|
-
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
23
|
-
(0, _defineProperty2.default)(this, "config", void 0);
|
24
21
|
this.config = config;
|
25
22
|
this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.name)}.zip`);
|
26
23
|
}
|
27
|
-
s3DownloadStreams() {
|
24
|
+
async s3DownloadStreams() {
|
28
25
|
const exportInfo = this.config.exportInfo;
|
29
26
|
const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.name)}`);
|
30
|
-
const files = exportInfo.files.map(({
|
27
|
+
const files = await Promise.all(exportInfo.files.map(async ({
|
31
28
|
key
|
32
29
|
}) => {
|
33
30
|
return {
|
34
|
-
stream: _s3Stream.s3Stream.readStream(key),
|
35
|
-
filename: `${prefix}\\${this.filesDirName}\\${
|
31
|
+
stream: await _s3Stream.s3Stream.readStream(key),
|
32
|
+
filename: `${prefix}\\${this.filesDirName}\\${key}`
|
36
33
|
};
|
37
|
-
});
|
34
|
+
}));
|
38
35
|
return [...files, {
|
39
36
|
stream: _stream.Readable.from(exportInfo.dataBuffer),
|
40
37
|
filename: `${prefix}\\${exportInfo.name}.json`
|
41
38
|
}];
|
42
39
|
}
|
43
|
-
process() {
|
40
|
+
async process() {
|
44
41
|
const {
|
45
42
|
streamPassThrough,
|
46
43
|
streamPassThroughUploadPromise
|
47
44
|
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
48
45
|
|
49
46
|
// 1. Read all files from S3 using stream.
|
50
|
-
const s3FilesStreams = this.s3DownloadStreams();
|
47
|
+
const s3FilesStreams = await this.s3DownloadStreams();
|
51
48
|
|
52
49
|
// 2. Prepare zip from the file stream.
|
53
50
|
const archive = _archiver.default.create(this.archiveFormat);
|
@@ -73,31 +70,28 @@ class Zipper {
|
|
73
70
|
}
|
74
71
|
exports.default = Zipper;
|
75
72
|
class ZipOfZip {
|
73
|
+
archiveFormat = "zip";
|
76
74
|
constructor(keys, filename) {
|
77
|
-
(0, _defineProperty2.default)(this, "archiveFormat", "zip");
|
78
|
-
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
79
|
-
(0, _defineProperty2.default)(this, "keys", void 0);
|
80
|
-
(0, _defineProperty2.default)(this, "filename", void 0);
|
81
75
|
this.keys = keys;
|
82
76
|
this.filename = filename;
|
83
|
-
this.archiveFileName = (0, _uniqid.default)("", `-${filename}`);
|
77
|
+
this.archiveFileName = (0, _uniqid.default)("EXPORTS/", `-${filename}`);
|
84
78
|
}
|
85
|
-
getFileStreams() {
|
86
|
-
return this.keys.map(key => {
|
79
|
+
async getFileStreams() {
|
80
|
+
return await Promise.all(this.keys.map(async key => {
|
87
81
|
return {
|
88
|
-
stream: _s3Stream.s3Stream.readStream(key),
|
82
|
+
stream: await _s3Stream.s3Stream.readStream(key),
|
89
83
|
filename: `${path.basename(key)}`
|
90
84
|
};
|
91
|
-
});
|
85
|
+
}));
|
92
86
|
}
|
93
|
-
process() {
|
87
|
+
async process() {
|
94
88
|
const {
|
95
89
|
streamPassThrough,
|
96
90
|
streamPassThroughUploadPromise
|
97
91
|
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
98
92
|
|
99
93
|
// 1. Read all files from S3 using stream.
|
100
|
-
const fileStreamDetails = this.getFileStreams();
|
94
|
+
const fileStreamDetails = await this.getFileStreams();
|
101
95
|
|
102
96
|
// 2. Prepare zip from the file stream.
|
103
97
|
const archive = _archiver.default.create(this.archiveFormat);
|
@@ -121,4 +115,6 @@ class ZipOfZip {
|
|
121
115
|
return streamPassThroughUploadPromise;
|
122
116
|
}
|
123
117
|
}
|
124
|
-
exports.ZipOfZip = ZipOfZip;
|
118
|
+
exports.ZipOfZip = ZipOfZip;
|
119
|
+
|
120
|
+
//# sourceMappingURL=zipper.js.map
|