@webiny/api-page-builder-import-export 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.aa00eecd97
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.d.ts +2 -2
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.d.ts +6 -0
- package/export/combine/blocksHandler.js +99 -0
- package/export/combine/blocksHandler.js.map +1 -0
- package/export/combine/formsHandler.d.ts +6 -0
- package/export/combine/formsHandler.js +99 -0
- package/export/combine/formsHandler.js.map +1 -0
- package/{exportPages → export}/combine/index.d.ts +3 -2
- package/export/combine/index.js +40 -0
- package/export/combine/index.js.map +1 -0
- package/export/combine/pagesHandler.d.ts +6 -0
- package/export/combine/pagesHandler.js +99 -0
- package/export/combine/pagesHandler.js.map +1 -0
- package/export/combine/templatesHandler.d.ts +6 -0
- package/export/combine/templatesHandler.js +99 -0
- package/export/combine/templatesHandler.js.map +1 -0
- package/export/process/blocksHandler.d.ts +6 -0
- package/export/process/blocksHandler.js +162 -0
- package/export/process/blocksHandler.js.map +1 -0
- package/export/process/formsHandler.d.ts +6 -0
- package/export/process/formsHandler.js +187 -0
- package/export/process/formsHandler.js.map +1 -0
- package/{exportPages → export}/process/index.d.ts +4 -6
- package/export/process/index.js +37 -0
- package/export/process/index.js.map +1 -0
- package/export/process/pagesHandler.d.ts +6 -0
- package/export/process/pagesHandler.js +189 -0
- package/export/process/pagesHandler.js.map +1 -0
- package/export/process/templatesHandler.d.ts +6 -0
- package/export/process/templatesHandler.js +166 -0
- package/export/process/templatesHandler.js.map +1 -0
- package/{exportPages → export}/s3Stream.d.ts +5 -2
- package/export/s3Stream.js.map +1 -0
- package/export/utils.d.ts +29 -0
- package/export/utils.js +188 -0
- package/export/utils.js.map +1 -0
- package/{exportPages → export}/zipper.d.ts +6 -5
- package/{exportPages → export}/zipper.js +9 -8
- package/export/zipper.js.map +1 -0
- package/graphql/crud/blocks.crud.d.ts +4 -0
- package/graphql/crud/blocks.crud.js +136 -0
- package/graphql/crud/blocks.crud.js.map +1 -0
- package/graphql/crud/forms.crud.d.ts +4 -0
- package/graphql/crud/forms.crud.js +129 -0
- package/graphql/crud/forms.crud.js.map +1 -0
- package/graphql/crud/importExportTasks.crud.d.ts +5 -0
- package/graphql/crud/{pageImportExportTasks.crud.js → importExportTasks.crud.js} +50 -55
- package/graphql/crud/importExportTasks.crud.js.map +1 -0
- package/graphql/crud/pages.crud.d.ts +2 -2
- package/graphql/crud/pages.crud.js +18 -14
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.d.ts +4 -0
- package/graphql/crud/templates.crud.js +124 -0
- package/graphql/crud/templates.crud.js.map +1 -0
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js +5 -2
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.d.ts +4 -0
- package/graphql/graphql/blocks.gql.js +52 -0
- package/graphql/graphql/blocks.gql.js.map +1 -0
- package/graphql/graphql/forms.gql.d.ts +4 -0
- package/graphql/graphql/forms.gql.js +60 -0
- package/graphql/graphql/forms.gql.js.map +1 -0
- package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
- package/graphql/graphql/{pageImportExportTasks.gql.js → importExportTasks.gql.js} +17 -17
- package/graphql/graphql/importExportTasks.gql.js.map +1 -0
- package/graphql/graphql/pages.gql.d.ts +2 -2
- package/graphql/graphql/pages.gql.js +3 -9
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.d.ts +4 -0
- package/graphql/graphql/templates.gql.js +52 -0
- package/graphql/graphql/templates.gql.js.map +1 -0
- package/graphql/graphql.js +5 -2
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +83 -23
- package/graphql/types.js.map +1 -1
- package/import/constants.d.ts +3 -0
- package/import/constants.js +14 -0
- package/import/constants.js.map +1 -0
- package/import/create/blocksHandler.d.ts +3 -0
- package/import/create/blocksHandler.js +101 -0
- package/import/create/blocksHandler.js.map +1 -0
- package/import/create/formsHandler.d.ts +3 -0
- package/import/create/formsHandler.js +103 -0
- package/import/create/formsHandler.js.map +1 -0
- package/{importPages → import}/create/index.d.ts +7 -5
- package/import/create/index.js +40 -0
- package/import/create/index.js.map +1 -0
- package/import/create/pagesHandler.d.ts +3 -0
- package/import/create/pagesHandler.js +103 -0
- package/import/create/pagesHandler.js.map +1 -0
- package/import/create/templatesHandler.d.ts +3 -0
- package/import/create/templatesHandler.js +99 -0
- package/import/create/templatesHandler.js.map +1 -0
- package/import/process/blocks/blocksHandler.d.ts +3 -0
- package/import/process/blocks/blocksHandler.js +169 -0
- package/import/process/blocks/blocksHandler.js.map +1 -0
- package/import/process/blocks/importBlock.d.ts +11 -0
- package/import/process/blocks/importBlock.js +92 -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 +176 -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 +43 -0
- package/import/process/forms/importForm.js.map +1 -0
- package/{importPages → import}/process/index.d.ts +5 -3
- package/import/process/index.js +37 -0
- package/import/process/index.js.map +1 -0
- package/import/process/pages/importPage.d.ts +11 -0
- package/import/process/pages/importPage.js +92 -0
- package/import/process/pages/importPage.js.map +1 -0
- package/import/process/pages/pagesHandler.d.ts +3 -0
- package/import/process/pages/pagesHandler.js +183 -0
- package/import/process/pages/pagesHandler.js.map +1 -0
- package/import/process/templates/importTemplate.d.ts +11 -0
- package/import/process/templates/importTemplate.js +66 -0
- package/import/process/templates/importTemplate.js.map +1 -0
- package/import/process/templates/templatesHandler.d.ts +3 -0
- package/import/process/templates/templatesHandler.js +170 -0
- package/import/process/templates/templatesHandler.js.map +1 -0
- package/import/utils/deleteS3Folder.d.ts +1 -0
- package/import/utils/deleteS3Folder.js +19 -0
- package/import/utils/deleteS3Folder.js.map +1 -0
- package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
- package/import/utils/extractAndUploadZipFileContents.js +122 -0
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
- package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
- package/import/utils/extractZipAndUploadToS3.js +98 -0
- package/import/utils/extractZipAndUploadToS3.js.map +1 -0
- package/import/utils/getFileNameWithoutExt.d.ts +1 -0
- package/import/utils/getFileNameWithoutExt.js +11 -0
- package/import/utils/getFileNameWithoutExt.js.map +1 -0
- package/import/utils/index.d.ts +9 -0
- package/import/utils/index.js +104 -0
- package/import/utils/index.js.map +1 -0
- package/import/utils/initialStats.d.ts +7 -0
- package/import/utils/initialStats.js +16 -0
- package/import/utils/initialStats.js.map +1 -0
- package/import/utils/prepareDataDirMap.d.ts +6 -0
- package/import/utils/prepareDataDirMap.js +29 -0
- package/import/utils/prepareDataDirMap.js.map +1 -0
- package/import/utils/updateFilesInData.d.ts +8 -0
- package/import/utils/updateFilesInData.js +48 -0
- package/import/utils/updateFilesInData.js.map +1 -0
- package/import/utils/uploadAssets.d.ts +10 -0
- package/import/utils/uploadAssets.js +49 -0
- package/import/utils/uploadAssets.js.map +1 -0
- package/import/utils/uploadFilesFromS3.d.ts +3 -0
- package/import/utils/uploadFilesFromS3.js +19 -0
- package/import/utils/uploadFilesFromS3.js.map +1 -0
- package/package.json +37 -37
- package/types.d.ts +83 -65
- package/types.js +17 -17
- package/types.js.map +1 -1
- package/exportPages/combine/index.js +0 -106
- package/exportPages/combine/index.js.map +0 -1
- package/exportPages/process/index.js +0 -192
- package/exportPages/process/index.js.map +0 -1
- package/exportPages/s3Stream.js.map +0 -1
- package/exportPages/utils.d.ts +0 -13
- package/exportPages/utils.js +0 -100
- package/exportPages/utils.js.map +0 -1
- package/exportPages/zipper.js.map +0 -1
- package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
- package/graphql/crud/pageImportExportTasks.crud.js.map +0 -1
- package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
- package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
- package/importPages/create/index.js +0 -107
- package/importPages/create/index.js.map +0 -1
- package/importPages/process/index.js +0 -180
- package/importPages/process/index.js.map +0 -1
- package/importPages/utils.d.ts +0 -50
- package/importPages/utils.js +0 -488
- package/importPages/utils.js.map +0 -1
- /package/{exportPages → export}/s3Stream.js +0 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["pagesHandler","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","pageId","exportPagesDataKey","revisionType","page","ExportRevisionType","PUBLISHED","getPublishedPageById","getPage","e","NotFoundError","version","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","pageDataZip","exportPage","COMPLETED","message","key","Key","FAILED","name","stack","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process"],"sources":["pagesHandler.ts"],"sourcesContent":["import { ExportRevisionType, ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { exportPage } 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 pages process workflow.\n */\nexport const pagesHandler = 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 Pages 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\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 { pageId, exportPagesDataKey, revisionType } = input;\n\n /**\n * At the moment, we only export a single revision of the page.\n * It could be \"published\" or \"latest\" depending upon user input.\n *\n * Note: In case of no \"published\" revision available, we use the latest revision.\n */\n let page;\n try {\n if (revisionType === ExportRevisionType.PUBLISHED) {\n // Get \"published\" page.\n page = await pageBuilder.getPublishedPageById({ id: pageId });\n } else {\n // Get \"latest\" page.\n page = await pageBuilder.getPage(pageId);\n }\n } catch (e) {\n // If we're looking for \"published\" page and doesn't found it, get latest page.\n if (revisionType === ExportRevisionType.PUBLISHED && e instanceof NotFoundError) {\n page = await pageBuilder.getPage(pageId);\n } else {\n throw e;\n }\n }\n\n if (!page) {\n log(`Unable to load page \"${pageId}\"`);\n throw new NotFoundError(`Unable to load page \"${pageId}\"`);\n }\n\n log(`Processing page key \"${pageId}\" | version ${page.version} | ${page.status}`);\n\n // Mark task status as PROCESSING\n subTask = await pageBuilder.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 page data and uploading to storage...`);\n // Extract Page\n const pageDataZip = await exportPage(page, exportPagesDataKey, fileManager);\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for page \"${page.id}\" v${page.version} (${page.status}).`,\n key: pageDataZip.Key\n }\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.COMPLETED\n });\n prevStatusOfSubTask = subTask.status;\n } catch (e) {\n log(\"[EXPORT_PAGES_PROCESS] Error => \", e);\n\n if (subTask && subTask.id) {\n /**\n * In case of error, we'll update the task status to \"failed\",\n * so that, client can show notify the user appropriately.\n */\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n stack: e.stack,\n code: \"EXPORT_FAILED\"\n }\n });\n\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.FAILED\n });\n prevStatusOfSubTask = subTask.status;\n }\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n } finally {\n // Base condition!\n if (noPendingTask) {\n log(`No pending sub-task for task ${taskId}`);\n // Combine individual page 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 pages - combine\"\n });\n } else {\n console.log(`Invoking PROCESS for task \"${subTaskIndex + 1}\"`);\n // We want to continue with Self invocation no matter if current page error out.\n await invokeHandlerClient<Payload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId,\n type,\n subTaskIndex: subTaskIndex + 1,\n identity: context.security.getIdentity()\n },\n description: \"Export pages - process - subtask\"\n });\n }\n }\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAEA;AAEA;AAGA;AACA;A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CAAC,CAACW;MACf;IACJ,CAAC;EACL,CAAC,SAAS;IACN;IACA,IAAItC,aAAa,EAAE;MACfH,GAAG,CAAE,gCAA+BS,MAAO,EAAC,CAAC;MAC7C;MACA,MAAM,IAAAuC,2BAAmB,EAAiB;QACtCjD,OAAO;QACP8C,IAAI,EAAEhD,aAAa,CAACoD,QAAQ,CAACC,OAAO;QACpCpD,OAAO,EAAE;UACLW,MAAM;UACNE,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAACoD,QAAQ,CAACC,WAAW;QAC1C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN,CAAC,MAAM;MACHpD,OAAO,CAACD,GAAG,CAAE,8BAA6BU,YAAY,GAAG,CAAE,GAAE,CAAC;MAC9D;MACA,MAAM,IAAAsC,2BAAmB,EAAU;QAC/BjD,OAAO;QACP8C,IAAI,EAAEhD,aAAa,CAACoD,QAAQ,CAACK,OAAO;QACpCxD,OAAO,EAAE;UACLW,MAAM;UACNE,IAAI;UACJD,YAAY,EAAEA,YAAY,GAAG,CAAC;UAC9BE,QAAQ,EAAEb,OAAO,CAACoD,QAAQ,CAACC,WAAW;QAC1C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN;EACJ;EACA,OAAO;IACHnC,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAAC"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { PbImportExportContext } from "../../types";
|
2
|
+
import { Configuration, Payload, Response } from ".";
|
3
|
+
/**
|
4
|
+
* Handles the export templates process workflow.
|
5
|
+
*/
|
6
|
+
export declare const templatesHandler: (configuration: Configuration, payload: Payload, context: PbImportExportContext) => Promise<Response>;
|
@@ -0,0 +1,166 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.templatesHandler = void 0;
|
7
|
+
var _types = require("../../types");
|
8
|
+
var _client = require("../../client");
|
9
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
10
|
+
var _utils = require("../utils");
|
11
|
+
var _mockSecurity = require("../../mockSecurity");
|
12
|
+
var _utils2 = require("@webiny/utils");
|
13
|
+
/**
|
14
|
+
* Handles the export templates process workflow.
|
15
|
+
*/
|
16
|
+
const templatesHandler = async (configuration, payload, context) => {
|
17
|
+
const log = console.log;
|
18
|
+
let subTask;
|
19
|
+
let noPendingTask = true;
|
20
|
+
let prevStatusOfSubTask = _types.ImportExportTaskStatus.PENDING;
|
21
|
+
log("RUNNING Export Templates Process Handler");
|
22
|
+
const {
|
23
|
+
pageBuilder,
|
24
|
+
fileManager
|
25
|
+
} = context;
|
26
|
+
const {
|
27
|
+
taskId,
|
28
|
+
subTaskIndex,
|
29
|
+
type,
|
30
|
+
identity
|
31
|
+
} = payload;
|
32
|
+
// Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks
|
33
|
+
// and this Lambda is invoked internally, without credentials.
|
34
|
+
(0, _mockSecurity.mockSecurity)(identity, context);
|
35
|
+
try {
|
36
|
+
/*
|
37
|
+
* Note: We're not going to DB for finding the next sub-task to process,
|
38
|
+
* because the data might be out of sync due to GSI eventual consistency.
|
39
|
+
*/
|
40
|
+
subTask = await pageBuilder.importExportTask.getSubTask(taskId, (0, _utils2.zeroPad)(subTaskIndex, 5));
|
41
|
+
/**
|
42
|
+
* Base condition!!
|
43
|
+
* Bail out early, if task not found or task's status is not "pending".
|
44
|
+
*/
|
45
|
+
if (!subTask || subTask.status !== _types.ImportExportTaskStatus.PENDING) {
|
46
|
+
noPendingTask = true;
|
47
|
+
return {
|
48
|
+
data: "",
|
49
|
+
error: null
|
50
|
+
};
|
51
|
+
} else {
|
52
|
+
noPendingTask = false;
|
53
|
+
}
|
54
|
+
log(`Fetched sub task => ${subTask.id}`);
|
55
|
+
const {
|
56
|
+
input
|
57
|
+
} = subTask;
|
58
|
+
const {
|
59
|
+
templateId,
|
60
|
+
exportTemplatesDataKey
|
61
|
+
} = input;
|
62
|
+
const template = await pageBuilder.getPageTemplate({
|
63
|
+
where: {
|
64
|
+
id: templateId
|
65
|
+
}
|
66
|
+
});
|
67
|
+
if (!template) {
|
68
|
+
log(`Unable to load template "${templateId}"`);
|
69
|
+
throw new _handlerGraphql.NotFoundError(`Unable to load template "${templateId}"`);
|
70
|
+
}
|
71
|
+
log(`Processing template key "${templateId}"`);
|
72
|
+
|
73
|
+
// Mark task status as PROCESSING
|
74
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
75
|
+
status: _types.ImportExportTaskStatus.PROCESSING
|
76
|
+
});
|
77
|
+
// Update stats in main task
|
78
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
79
|
+
prevStatus: prevStatusOfSubTask,
|
80
|
+
nextStatus: _types.ImportExportTaskStatus.PROCESSING
|
81
|
+
});
|
82
|
+
prevStatusOfSubTask = subTask.status;
|
83
|
+
log(`Extracting template data and uploading to storage...`);
|
84
|
+
// Extract Template
|
85
|
+
const templateDataZip = await (0, _utils.exportTemplate)(template, exportTemplatesDataKey, fileManager);
|
86
|
+
log(`Finish uploading zip...`);
|
87
|
+
// Update task record in DB
|
88
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
89
|
+
status: _types.ImportExportTaskStatus.COMPLETED,
|
90
|
+
data: {
|
91
|
+
message: `Finish uploading data for template "${template.id}"`,
|
92
|
+
key: templateDataZip.Key
|
93
|
+
}
|
94
|
+
});
|
95
|
+
// Update stats in main task
|
96
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
97
|
+
prevStatus: prevStatusOfSubTask,
|
98
|
+
nextStatus: _types.ImportExportTaskStatus.COMPLETED
|
99
|
+
});
|
100
|
+
prevStatusOfSubTask = subTask.status;
|
101
|
+
} catch (e) {
|
102
|
+
log("[EXPORT_TEMPLATES_PROCESS] Error => ", e.message);
|
103
|
+
if (subTask && subTask.id) {
|
104
|
+
/**
|
105
|
+
* In case of error, we'll update the task status to "failed",
|
106
|
+
* so that, client can show notify the user appropriately.
|
107
|
+
*/
|
108
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
109
|
+
status: _types.ImportExportTaskStatus.FAILED,
|
110
|
+
error: {
|
111
|
+
name: e.name,
|
112
|
+
message: e.message,
|
113
|
+
code: "EXPORT_FAILED"
|
114
|
+
}
|
115
|
+
});
|
116
|
+
|
117
|
+
// Update stats in main task
|
118
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
119
|
+
prevStatus: prevStatusOfSubTask,
|
120
|
+
nextStatus: _types.ImportExportTaskStatus.FAILED
|
121
|
+
});
|
122
|
+
prevStatusOfSubTask = subTask.status;
|
123
|
+
}
|
124
|
+
return {
|
125
|
+
data: null,
|
126
|
+
error: {
|
127
|
+
message: e.message
|
128
|
+
}
|
129
|
+
};
|
130
|
+
} finally {
|
131
|
+
// Base condition!
|
132
|
+
if (noPendingTask) {
|
133
|
+
log(`No pending sub-task for task ${taskId}`);
|
134
|
+
// Combine individual template zip files.
|
135
|
+
await (0, _client.invokeHandlerClient)({
|
136
|
+
context,
|
137
|
+
name: configuration.handlers.combine,
|
138
|
+
payload: {
|
139
|
+
taskId,
|
140
|
+
type,
|
141
|
+
identity: context.security.getIdentity()
|
142
|
+
},
|
143
|
+
description: "Export templates - combine"
|
144
|
+
});
|
145
|
+
} else {
|
146
|
+
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`);
|
147
|
+
// We want to continue with Self invocation no matter if current template error out.
|
148
|
+
await (0, _client.invokeHandlerClient)({
|
149
|
+
context,
|
150
|
+
name: configuration.handlers.process,
|
151
|
+
payload: {
|
152
|
+
taskId,
|
153
|
+
subTaskIndex: subTaskIndex + 1,
|
154
|
+
type,
|
155
|
+
identity: context.security.getIdentity()
|
156
|
+
},
|
157
|
+
description: "Export templates - process - subtask"
|
158
|
+
});
|
159
|
+
}
|
160
|
+
}
|
161
|
+
return {
|
162
|
+
data: "",
|
163
|
+
error: null
|
164
|
+
};
|
165
|
+
};
|
166
|
+
exports.templatesHandler = templatesHandler;
|
@@ -0,0 +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,Y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ACxC;IAEA,OAAO;MACHC,IAAI,EAAE,IAAI;MACVC,KAAK,EAAE;QACHiB,OAAO,EAAEG,CAAC,CAACH;MACf;IACJ,CAAC;EACL,CAAC,SAAS;IACN;IACA,IAAIjC,aAAa,EAAE;MACfH,GAAG,CAAE,gCAA+BS,MAAO,EAAC,CAAC;MAC7C;MACA,MAAM,IAAAkC,2BAAmB,EAAiB;QACtC5C,OAAO;QACP0C,IAAI,EAAE5C,aAAa,CAAC+C,QAAQ,CAACC,OAAO;QACpC/C,OAAO,EAAE;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,6 +1,6 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
/// <reference types="node" />
|
3
|
-
import {
|
3
|
+
import { Readable } from "stream";
|
4
4
|
import S3 from "aws-sdk/clients/s3";
|
5
5
|
declare class S3Stream {
|
6
6
|
s3: S3;
|
@@ -16,7 +16,10 @@ declare class S3Stream {
|
|
16
16
|
getObjectHead(Key: string): Promise<S3.HeadObjectOutput>;
|
17
17
|
readStream(Key: string): Readable;
|
18
18
|
writeStream(Key: string, contentType?: string): {
|
19
|
-
streamPassThrough: PassThrough;
|
19
|
+
streamPassThrough: import("stream").PassThrough;
|
20
|
+
/**
|
21
|
+
* We're not using the `FileManager` storage plugin here because it currently doesn't support streams.
|
22
|
+
*/
|
20
23
|
streamPassThroughUploadPromise: Promise<S3.ManagedUpload.SendData>;
|
21
24
|
};
|
22
25
|
upload(params: {
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["ARCHIVE_CONTENT_TYPE","S3Stream","constructor","s3","S3","region","process","env","AWS_REGION","bucket","S3_BUCKET","getPresignedUrl","key","getSignedUrl","Bucket","Key","Expires","isFileAccessible","getObjectHead","error","console","warn","log","headObject","promise","readStream","getObject","createReadStream","writeStream","contentType","streamPassThrough","Stream","PassThrough","params","ACL","Body","ContentType","streamPassThroughUploadPromise","upload","listObject","prefix","listObjects","Prefix","deleteObject","s3Stream"],"sources":["s3Stream.ts"],"sourcesContent":["import { Stream, Readable } from \"stream\";\nimport S3 from \"aws-sdk/clients/s3\";\n\nconst ARCHIVE_CONTENT_TYPE = \"application/zip\";\n\nclass S3Stream {\n s3: S3;\n bucket: string;\n\n constructor() {\n this.s3 = new S3({\n region: process.env.AWS_REGION as string\n });\n this.bucket = process.env.S3_BUCKET as string;\n }\n\n getPresignedUrl(key: string) {\n return this.s3.getSignedUrl(\"getObject\", {\n Bucket: this.bucket,\n Key: key,\n Expires: 604800 // 1 week\n });\n }\n\n /**\n * We're checking if the file is accessible on S3 by getting object meta data.\n * It help us to filter files that we need to download as part of export data.\n * @param Key {string}\n */\n async isFileAccessible(Key: string): Promise<boolean> {\n try {\n await this.getObjectHead(Key);\n return true;\n } catch (error) {\n console.warn(`Error while fetching meta data for file \"${Key}\"`);\n console.log(error);\n return false;\n }\n }\n\n getObjectHead(Key: string): Promise<S3.HeadObjectOutput> {\n return this.s3.headObject({ Bucket: this.bucket, Key }).promise();\n }\n\n readStream(Key: string): Readable {\n return this.s3.getObject({ Bucket: this.bucket, Key }).createReadStream();\n }\n\n writeStream(Key: string, contentType: string = ARCHIVE_CONTENT_TYPE) {\n const streamPassThrough = new Stream.PassThrough();\n\n const params: S3.PutObjectRequest = {\n ACL: \"private\",\n Body: streamPassThrough,\n Bucket: this.bucket,\n ContentType: contentType,\n Key\n };\n\n return {\n streamPassThrough: streamPassThrough,\n /**\n * We're not using the `FileManager` storage plugin here because it currently doesn't support streams.\n */\n streamPassThroughUploadPromise: this.s3.upload(params).promise()\n };\n }\n\n upload(params: {\n Key: string;\n ContentType: string;\n Body: Buffer;\n }): Promise<S3.ManagedUpload.SendData> {\n return this.s3\n .upload({\n ACL: \"private\",\n Bucket: this.bucket,\n ...params\n })\n .promise();\n }\n\n listObject(prefix: string): Promise<S3.ListObjectsOutput> {\n return this.s3\n .listObjects({\n Bucket: this.bucket,\n Prefix: prefix\n })\n .promise();\n }\n\n deleteObject(key: string): Promise<S3.DeleteObjectOutput> {\n return this.s3.deleteObject({ Key: key, Bucket: this.bucket }).promise();\n }\n}\n\nexport const s3Stream = new S3Stream();\n"],"mappings":";;;;;;;;;AAAA;AACA;AAEA,MAAMA,oBAAoB,GAAG,iBAAiB;AAE9C,MAAMC,QAAQ,CAAC;EAIXC,WAAW,GAAG;IAAA;IAAA;IACV,IAAI,CAACC,EAAE,GAAG,IAAIC,UAAE,CAAC;MACbC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAACC;IACxB,CAAC,CAAC;IACF,IAAI,CAACC,MAAM,GAAGH,OAAO,CAACC,GAAG,CAACG,SAAmB;EACjD;EAEAC,eAAe,CAACC,GAAW,EAAE;IACzB,OAAO,IAAI,CAACT,EAAE,CAACU,YAAY,CAAC,WAAW,EAAE;MACrCC,MAAM,EAAE,IAAI,CAACL,MAAM;MACnBM,GAAG,EAAEH,GAAG;MACRI,OAAO,EAAE,MAAM,CAAC;IACpB,CAAC,CAAC;EACN;;EAEA;AACJ;AACA;AACA;AACA;EACI,MAAMC,gBAAgB,CAACF,GAAW,EAAoB;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AACC,MAAc,EAAiC;IACtD,OAAO,IAAI,CAACrC,EAAE,CACTsC,WAAW,CAAC;MACT3B,MAAM,EAAE,IAAI,CAACL,MAAM;MACnBiC,MAAM,EAAEF;IACZ,CAAC,CAAC,CACDhB,OAAO,EAAE;EAClB;EAEAmB,YAAY,CAAC/B,GAAW,EAAkC;IACtD,OAAO,IAAI,CAACT,EAAE,CAACwC,YAAY,CAAC;MAAE5B,GAAG,EAAEH,GAAG;MAAEE,MAAM,EAAE,IAAI,CAACL;IAAO,CAAC,CAAC,CAACe,OAAO,EAAE;EAC5E;AACJ;AAEO,MAAMoB,QAAQ,GAAG,IAAI3C,QAAQ,EAAE;AAAC"}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import S3 from "aws-sdk/clients/s3";
|
2
|
+
import { Page, PageBlock, PageTemplate } from "@webiny/api-page-builder/types";
|
3
|
+
import { FbForm } from "@webiny/api-form-builder/types";
|
4
|
+
import { FileManagerContext, File } from "@webiny/api-file-manager/types";
|
5
|
+
export declare const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
6
|
+
export declare const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
|
7
|
+
export declare const EXPORT_TEMPLATES_FOLDER_KEY = "WEBINY_PB_EXPORT_TEMPLATE";
|
8
|
+
export declare const EXPORT_FORMS_FOLDER_KEY = "WEBINY_FB_EXPORT_FORM";
|
9
|
+
export interface ExportedPageData {
|
10
|
+
page: Pick<Page, "content" | "title" | "version" | "status" | "settings" | "path">;
|
11
|
+
files: File[];
|
12
|
+
}
|
13
|
+
export declare function exportPage(page: Page, exportPagesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<S3.ManagedUpload.SendData>;
|
14
|
+
export interface ExportedBlockData {
|
15
|
+
block: Pick<PageBlock, "name" | "content" | "preview">;
|
16
|
+
files: File[];
|
17
|
+
}
|
18
|
+
export declare function exportBlock(block: PageBlock, exportBlocksDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<S3.ManagedUpload.SendData>;
|
19
|
+
export interface ExportedTemplateData {
|
20
|
+
template: Pick<PageTemplate, "title" | "slug" | "tags" | "description" | "content" | "layout" | "pageCategory">;
|
21
|
+
files: File[];
|
22
|
+
}
|
23
|
+
export declare function exportTemplate(template: PageTemplate, exportTemplatesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<S3.ManagedUpload.SendData>;
|
24
|
+
export declare function extractFilesFromData(data: Record<string, any>, files?: any[]): File[];
|
25
|
+
export interface ExportedFormData {
|
26
|
+
form: Pick<FbForm, "name" | "status" | "version" | "fields" | "layout" | "settings" | "triggers">;
|
27
|
+
files: File[];
|
28
|
+
}
|
29
|
+
export declare function exportForm(form: FbForm, exportFormsDataKey: string): Promise<S3.ManagedUpload.SendData>;
|
package/export/utils.js
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.EXPORT_TEMPLATES_FOLDER_KEY = exports.EXPORT_PAGES_FOLDER_KEY = exports.EXPORT_FORMS_FOLDER_KEY = exports.EXPORT_BLOCKS_FOLDER_KEY = void 0;
|
8
|
+
exports.exportBlock = exportBlock;
|
9
|
+
exports.exportForm = exportForm;
|
10
|
+
exports.exportPage = exportPage;
|
11
|
+
exports.exportTemplate = exportTemplate;
|
12
|
+
exports.extractFilesFromData = extractFilesFromData;
|
13
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
14
|
+
var _zipper = _interopRequireDefault(require("./zipper"));
|
15
|
+
const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
16
|
+
exports.EXPORT_PAGES_FOLDER_KEY = EXPORT_PAGES_FOLDER_KEY;
|
17
|
+
const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
|
18
|
+
exports.EXPORT_BLOCKS_FOLDER_KEY = EXPORT_BLOCKS_FOLDER_KEY;
|
19
|
+
const EXPORT_TEMPLATES_FOLDER_KEY = "WEBINY_PB_EXPORT_TEMPLATE";
|
20
|
+
exports.EXPORT_TEMPLATES_FOLDER_KEY = EXPORT_TEMPLATES_FOLDER_KEY;
|
21
|
+
const EXPORT_FORMS_FOLDER_KEY = "WEBINY_FB_EXPORT_FORM";
|
22
|
+
exports.EXPORT_FORMS_FOLDER_KEY = EXPORT_FORMS_FOLDER_KEY;
|
23
|
+
async function exportPage(page, exportPagesDataKey, fileManager) {
|
24
|
+
// Extract all files
|
25
|
+
const files = extractFilesFromData(page.content || {});
|
26
|
+
// Extract images from page settings
|
27
|
+
const pageSettingsImages = [(0, _get.default)(page, "settings.general.image"), (0, _get.default)(page, "settings.social.image")].filter(image => image && image.src);
|
28
|
+
const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);
|
29
|
+
// Get file data for all images
|
30
|
+
const imageFilesData = [];
|
31
|
+
if (fileIds.length > 0) {
|
32
|
+
const [filesData] = await fileManager.listFiles({
|
33
|
+
ids: fileIds
|
34
|
+
});
|
35
|
+
imageFilesData.push(...filesData);
|
36
|
+
}
|
37
|
+
|
38
|
+
// Extract the page data in a json file and upload it to S3
|
39
|
+
const pageData = {
|
40
|
+
page: {
|
41
|
+
content: page.content,
|
42
|
+
title: page.title,
|
43
|
+
path: page.path,
|
44
|
+
version: page.version,
|
45
|
+
status: page.status,
|
46
|
+
settings: page.settings
|
47
|
+
},
|
48
|
+
files: imageFilesData
|
49
|
+
};
|
50
|
+
const pageDataBuffer = Buffer.from(JSON.stringify(pageData));
|
51
|
+
const zipper = new _zipper.default({
|
52
|
+
exportInfo: {
|
53
|
+
files: imageFilesData,
|
54
|
+
name: page.title,
|
55
|
+
dataBuffer: pageDataBuffer
|
56
|
+
},
|
57
|
+
archiveFileKey: exportPagesDataKey
|
58
|
+
});
|
59
|
+
return zipper.process();
|
60
|
+
}
|
61
|
+
async function exportBlock(block, exportBlocksDataKey, fileManager) {
|
62
|
+
// Extract all files
|
63
|
+
const files = extractFilesFromData(block.content || {});
|
64
|
+
const fileIds = files.map(imageFile => imageFile.id);
|
65
|
+
// Get file data for all images
|
66
|
+
const imageFilesData = [];
|
67
|
+
if (fileIds.length > 0) {
|
68
|
+
const [filesData] = await fileManager.listFiles({
|
69
|
+
ids: fileIds
|
70
|
+
});
|
71
|
+
imageFilesData.push(...filesData);
|
72
|
+
}
|
73
|
+
// Add block preview image file data
|
74
|
+
if (block.preview.id) {
|
75
|
+
imageFilesData.push(await fileManager.getFile(block.preview.id));
|
76
|
+
}
|
77
|
+
|
78
|
+
// Extract the block data in a json file and upload it to S3
|
79
|
+
const blockData = {
|
80
|
+
block: {
|
81
|
+
name: block.name,
|
82
|
+
content: block.content,
|
83
|
+
preview: block.preview
|
84
|
+
},
|
85
|
+
files: imageFilesData
|
86
|
+
};
|
87
|
+
const blockDataBuffer = Buffer.from(JSON.stringify(blockData));
|
88
|
+
const zipper = new _zipper.default({
|
89
|
+
exportInfo: {
|
90
|
+
files: imageFilesData,
|
91
|
+
name: block.name,
|
92
|
+
dataBuffer: blockDataBuffer
|
93
|
+
},
|
94
|
+
archiveFileKey: exportBlocksDataKey
|
95
|
+
});
|
96
|
+
return zipper.process();
|
97
|
+
}
|
98
|
+
async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
|
99
|
+
// Extract all files
|
100
|
+
const files = extractFilesFromData(template.content || {});
|
101
|
+
const fileIds = files.map(imageFile => imageFile.id);
|
102
|
+
// Get file data for all images
|
103
|
+
const imageFilesData = [];
|
104
|
+
if (fileIds.length > 0) {
|
105
|
+
const [filesData] = await fileManager.listFiles({
|
106
|
+
ids: fileIds
|
107
|
+
});
|
108
|
+
imageFilesData.push(...filesData);
|
109
|
+
}
|
110
|
+
|
111
|
+
// Extract the template data in a json file and upload it to S3
|
112
|
+
const templateData = {
|
113
|
+
template: {
|
114
|
+
title: template.title,
|
115
|
+
slug: template.slug,
|
116
|
+
tags: template.tags,
|
117
|
+
description: template.description,
|
118
|
+
content: template.content,
|
119
|
+
layout: template.layout,
|
120
|
+
pageCategory: template.pageCategory
|
121
|
+
},
|
122
|
+
files: imageFilesData
|
123
|
+
};
|
124
|
+
const templateDataBuffer = Buffer.from(JSON.stringify(templateData));
|
125
|
+
const zipper = new _zipper.default({
|
126
|
+
exportInfo: {
|
127
|
+
files: imageFilesData,
|
128
|
+
name: template.title,
|
129
|
+
dataBuffer: templateDataBuffer
|
130
|
+
},
|
131
|
+
archiveFileKey: exportTemplatesDataKey
|
132
|
+
});
|
133
|
+
return zipper.process();
|
134
|
+
}
|
135
|
+
function extractFilesFromData(data, files = []) {
|
136
|
+
// Base case: termination
|
137
|
+
if (!data || typeof data !== "object") {
|
138
|
+
return files;
|
139
|
+
}
|
140
|
+
// Recursively call function for each element
|
141
|
+
if (Array.isArray(data)) {
|
142
|
+
for (let i = 0; i < data.length; i++) {
|
143
|
+
const element = data[i];
|
144
|
+
extractFilesFromData(element, files);
|
145
|
+
}
|
146
|
+
return files;
|
147
|
+
}
|
148
|
+
|
149
|
+
// Main
|
150
|
+
const tuple = Object.entries(data);
|
151
|
+
for (let i = 0; i < tuple.length; i++) {
|
152
|
+
const [key, value] = tuple[i];
|
153
|
+
// TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.
|
154
|
+
if (key === "file" && value) {
|
155
|
+
files.push(value);
|
156
|
+
} else if (key === "images" && Array.isArray(value)) {
|
157
|
+
// Handle case for "images-list" component
|
158
|
+
files.push(...value);
|
159
|
+
} else {
|
160
|
+
extractFilesFromData(value, files);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
return files;
|
164
|
+
}
|
165
|
+
async function exportForm(form, exportFormsDataKey) {
|
166
|
+
// Extract the form data in a json file and upload it to S3
|
167
|
+
const formData = {
|
168
|
+
form: {
|
169
|
+
name: form.name,
|
170
|
+
status: form.status,
|
171
|
+
version: form.version,
|
172
|
+
fields: form.fields,
|
173
|
+
layout: form.layout,
|
174
|
+
settings: form.settings,
|
175
|
+
triggers: form.triggers
|
176
|
+
}
|
177
|
+
};
|
178
|
+
const formDataBuffer = Buffer.from(JSON.stringify(formData));
|
179
|
+
const zipper = new _zipper.default({
|
180
|
+
exportInfo: {
|
181
|
+
files: [],
|
182
|
+
name: form.name,
|
183
|
+
dataBuffer: formDataBuffer
|
184
|
+
},
|
185
|
+
archiveFileKey: exportFormsDataKey
|
186
|
+
});
|
187
|
+
return zipper.process();
|
188
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["EXPORT_PAGES_FOLDER_KEY","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","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","pageCategory","templateDataBuffer","data","Array","isArray","i","element","tuple","Object","entries","key","value","exportForm","form","exportFormsDataKey","formData","fields","triggers","formDataBuffer"],"sources":["utils.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { Page, PageBlock, PageTemplate } from \"@webiny/api-page-builder/types\";\nimport { FbForm } from \"@webiny/api-form-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<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.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.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.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<\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<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.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 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: 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\nexport interface ExportedFormData {\n form: Pick<\n FbForm,\n \"name\" | \"status\" | \"version\" | \"fields\" | \"layout\" | \"settings\" | \"triggers\"\n >;\n files: File[];\n}\n\nexport async function exportForm(\n form: FbForm,\n exportFormsDataKey: string\n): Promise<S3.ManagedUpload.SendData> {\n // Extract the form data in a json file and upload it to S3\n const formData = {\n form: {\n name: form.name,\n status: form.status,\n version: form.version,\n fields: form.fields,\n layout: form.layout,\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"],"mappings":";;;;;;;;;;;;AAIA;AACA;AAEO,MAAMA,uBAAuB,GAAG,wBAAwB;AAAC;AACzD,MAAMC,wBAAwB,GAAG,wBAAwB;AAAC;AAC1D,MAAMC,2BAA2B,GAAG,2BAA2B;AAAC;AAChE,MAAMC,uBAAuB,GAAG,uBAAuB;AAAC;AAOxD,eAAeC,UAAU,CAC5BC,IAAU,EACVC,kBAA0B,EAC1BC,WAA8C,EACZ;EAClC;EACA,MAAMC,KAAK,GAAGC,oBAAoB,CAACJ,IAAI,CAACK,OAAO,IAAI,CAAC,CAAC,CAAC;EACtD;EACA,MAAMC,kBAAkB,GAAG,CACvB,IAAAC,YAAG,EAACP,IAAI,EAAE,wBAAwB,CAAC,EACnC,IAAAO,YAAG,EAACP,IAAI,EAAE,uBAAuB,CAAC,CACrC,CAACQ,MAAM,CAACC,KAAK,IAAIA,KAAK,IAAIA,KAAK,CAACC,GAAG,CAAC;EAErC,MAAMC,OAAO,GAAG,CAAC,GAAGR,KAAK,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;EACJ,CAAC;EACD,MAAMC,cAAc,GAAG5C,MAAM,CAACC,IAAI,CAACC,IAAI,CAACC,SAAS,CAACsC,QAAQ,CAAC,CAAC;EAE5D,MAAMrC,MAAM,GAAG,IAAIC,eAAM,CAAC;IACtBC,UAAU,EAAE;MACR/B,KAAK,EAAE,EAAE;MACTgC,IAAI,EAAEgC,IAAI,CAAChC,IAAI;MACfC,UAAU,EAAEoC;IAChB,CAAC;IACDnC,cAAc,EAAE+B;EACpB,CAAC,CAAC;EAEF,OAAOpC,MAAM,CAACM,OAAO,EAAE;AAC3B"}
|
@@ -2,15 +2,15 @@
|
|
2
2
|
/// <reference types="node" />
|
3
3
|
import S3 from "aws-sdk/clients/s3";
|
4
4
|
import { Readable } from "stream";
|
5
|
-
import {
|
5
|
+
import { File } from "@webiny/api-file-manager/types";
|
6
6
|
interface FileStreamDetails {
|
7
7
|
stream: Readable;
|
8
8
|
filename: string;
|
9
9
|
}
|
10
10
|
interface ExportInfo {
|
11
|
-
files:
|
12
|
-
|
13
|
-
|
11
|
+
files: File[];
|
12
|
+
name: string;
|
13
|
+
dataBuffer: Buffer;
|
14
14
|
}
|
15
15
|
export interface ZipperConfig {
|
16
16
|
exportInfo: ExportInfo;
|
@@ -29,7 +29,8 @@ export declare class ZipOfZip {
|
|
29
29
|
private readonly archiveFormat;
|
30
30
|
private readonly archiveFileName;
|
31
31
|
keys: string[];
|
32
|
-
|
32
|
+
filename: string;
|
33
|
+
constructor(keys: string[], filename: string);
|
33
34
|
getFileStreams(): FileStreamDetails[];
|
34
35
|
process(): Promise<S3.ManagedUpload.SendData>;
|
35
36
|
}
|
@@ -22,22 +22,22 @@ class Zipper {
|
|
22
22
|
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
23
23
|
(0, _defineProperty2.default)(this, "config", void 0);
|
24
24
|
this.config = config;
|
25
|
-
this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.
|
25
|
+
this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.name)}.zip`);
|
26
26
|
}
|
27
27
|
s3DownloadStreams() {
|
28
28
|
const exportInfo = this.config.exportInfo;
|
29
|
-
const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.
|
29
|
+
const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.name)}`);
|
30
30
|
const files = exportInfo.files.map(({
|
31
31
|
key
|
32
32
|
}) => {
|
33
33
|
return {
|
34
34
|
stream: _s3Stream.s3Stream.readStream(key),
|
35
|
-
filename: `${prefix}\\${this.filesDirName}\\${
|
35
|
+
filename: `${prefix}\\${this.filesDirName}\\${key}`
|
36
36
|
};
|
37
37
|
});
|
38
38
|
return [...files, {
|
39
|
-
stream: _stream.Readable.from(exportInfo.
|
40
|
-
filename: `${prefix}\\${exportInfo.
|
39
|
+
stream: _stream.Readable.from(exportInfo.dataBuffer),
|
40
|
+
filename: `${prefix}\\${exportInfo.name}.json`
|
41
41
|
}];
|
42
42
|
}
|
43
43
|
process() {
|
@@ -72,14 +72,15 @@ class Zipper {
|
|
72
72
|
}
|
73
73
|
}
|
74
74
|
exports.default = Zipper;
|
75
|
-
const PAGE_EXPORT_BASENAME = `WEBINY_PAGE_EXPORT.zip`;
|
76
75
|
class ZipOfZip {
|
77
|
-
constructor(keys) {
|
76
|
+
constructor(keys, filename) {
|
78
77
|
(0, _defineProperty2.default)(this, "archiveFormat", "zip");
|
79
78
|
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
80
79
|
(0, _defineProperty2.default)(this, "keys", void 0);
|
80
|
+
(0, _defineProperty2.default)(this, "filename", void 0);
|
81
81
|
this.keys = keys;
|
82
|
-
this.
|
82
|
+
this.filename = filename;
|
83
|
+
this.archiveFileName = (0, _uniqid.default)("EXPORTS/", `-${filename}`);
|
83
84
|
}
|
84
85
|
getFileStreams() {
|
85
86
|
return this.keys.map(key => {
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["Zipper","constructor","config","archiveFileName","uniqueId","archiveFileKey","kebabCase","exportInfo","name","s3DownloadStreams","prefix","files","map","key","stream","s3Stream","readStream","filename","filesDirName","Readable","from","dataBuffer","process","streamPassThrough","streamPassThroughUploadPromise","writeStream","s3FilesStreams","archive","vending","create","archiveFormat","on","error","Error","code","message","path","stack","forEach","streamDetails","append","pipe","finalize","ZipOfZip","keys","getFileStreams","basename","fileStreamDetails"],"sources":["zipper.ts"],"sourcesContent":["// TODO: Move \"archive\" in layer\nimport vending, { ArchiverError } from \"archiver\";\nimport S3 from \"aws-sdk/clients/s3\";\nimport { Readable } from \"stream\";\nimport * as path from \"path\";\nimport kebabCase from \"lodash/kebabCase\";\nimport uniqueId from \"uniqid\";\nimport { s3Stream } from \"./s3Stream\";\nimport { File } from \"@webiny/api-file-manager/types\";\n\ninterface FileStreamDetails {\n stream: Readable;\n filename: string;\n}\n\ninterface ExportInfo {\n files: File[];\n name: string;\n dataBuffer: Buffer;\n}\n\nexport interface ZipperConfig {\n exportInfo: ExportInfo;\n archiveFileKey: string;\n}\n\nexport default class Zipper {\n private readonly archiveFormat = \"zip\";\n private readonly filesDirName = \"assets\";\n private readonly archiveFileName: string;\n config: ZipperConfig;\n\n constructor(config: ZipperConfig) {\n this.config = config;\n this.archiveFileName = uniqueId(\n `${this.config.archiveFileKey}/`,\n `-${kebabCase(this.config.exportInfo.name)}.zip`\n );\n }\n\n s3DownloadStreams(): FileStreamDetails[] {\n const exportInfo = this.config.exportInfo;\n const prefix = uniqueId(\"\", `-${kebabCase(exportInfo.name)}`);\n const files = exportInfo.files.map(({ key }) => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${prefix}\\\\${this.filesDirName}\\\\${key}`\n };\n });\n\n return [\n ...files,\n {\n stream: Readable.from(exportInfo.dataBuffer),\n filename: `${prefix}\\\\${exportInfo.name}.json`\n }\n ];\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const s3FilesStreams = this.s3DownloadStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n s3FilesStreams.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n\nexport class ZipOfZip {\n private readonly archiveFormat = \"zip\";\n private readonly archiveFileName: string;\n keys: string[];\n filename: string;\n\n constructor(keys: string[], filename: string) {\n this.keys = keys;\n this.filename = filename;\n this.archiveFileName = uniqueId(\"EXPORTS/\", `-${filename}`);\n }\n\n getFileStreams(): FileStreamDetails[] {\n return this.keys.map(key => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${path.basename(key)}`\n };\n });\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const fileStreamDetails = this.getFileStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n fileStreamDetails.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n"],"mappings":";;;;;;;;;AACA;AAEA;AACA;AACA;AACA;AACA;AAPA;;AA0Be,MAAMA,MAAM,CAAC;EAMxBC,WAAW,CAACC,MAAoB,EAAE;IAAA,qDALD,KAAK;IAAA,oDACN,QAAQ;IAAA;IAAA;IAKpC,IAAI,CAACA,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,eAAe,GAAG,IAAAC,eAAQ,EAC1B,GAAE,IAAI,CAACF,MAAM,CAACG,cAAe,GAAE,EAC/B,IAAG,IAAAC,kBAAS,EAAC,IAAI,CAACJ,MAAM,CAACK,UAAU,CAACC,IAAI,CAAE,MAAK,CACnD;EACL;EAEAC,iBAAiB,GAAwB;IACrC,MAAMF,UAAU,GAAG,IAAI,CAACL,MAAM,CAACK,UAAU;IACzC,MAAMG,MAAM,GAAG,IAAAN,eAAQ,EAAC,EAAE,EAAG,IAAG,IAAAE,kBAAS,EAACC,UAAU,CAACC,IAAI,CAAE,EAAC,CAAC;IAC7D,MAAMG,KAAK,GAAGJ,UAAU,CAACI,KAAK,CAACC,GAAG,CAAC,CAAC;MAAEC;IAAI,CAAC,KAAK;MAC5C,OAAO;QACHC,MAAM,EAAEC,kBAAQ,CAACC,UAAU,CAACH,GAAG,CAAC;QAChCI,QAAQ,EAAG,GAAEP,MAAO,KAAI,IAAI,CAACQ,YAAa,KAAIL,GAAI;MACtD,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,CACH,GAAGF,KAAK,EACR;MACIG,MAAM,EAAEK,gBAAQ,CAACC,IAAI,CAACb,UAAU,CAACc,UAAU,CAAC;MAC5CJ,QAAQ,EAAG,GAAEP,MAAO,KAAIH,UAAU,CAACC,IAAK;IAC5C,CA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