@webiny/api-page-builder-import-export 0.0.0-unstable.99666aeb00 → 0.0.0-unstable.a9593f74dd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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.js +4 -2
- package/export/combine/formsHandler.js.map +1 -1
- package/export/combine/index.js +3 -1
- 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.js +8 -6
- package/export/process/formsHandler.js.map +1 -1
- package/export/process/index.js +3 -1
- 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 +8 -8
- package/export/s3Stream.js +27 -22
- package/export/s3Stream.js.map +1 -1
- package/export/utils.d.ts +8 -13
- package/export/utils.js +11 -34
- package/export/utils.js.map +1 -1
- package/export/zipper.d.ts +5 -5
- package/export/zipper.js +18 -22
- package/export/zipper.js.map +1 -1
- package/graphql/crud/blocks.crud.js +41 -22
- package/graphql/crud/blocks.crud.js.map +1 -1
- package/graphql/crud/forms.crud.js +41 -12
- package/graphql/crud/forms.crud.js.map +1 -1
- package/graphql/crud/importExportTasks.crud.js +43 -29
- package/graphql/crud/importExportTasks.crud.js.map +1 -1
- package/graphql/crud/pages.crud.d.ts +1 -0
- package/graphql/crud/pages.crud.js +50 -20
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.js +40 -11
- package/graphql/crud/templates.crud.js.map +1 -1
- package/graphql/crud.js +3 -1
- 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.js +3 -1
- package/graphql/graphql/forms.gql.js.map +1 -1
- 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.js +3 -1
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/graphql.js +3 -1
- 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 +113 -1
- package/graphql/types.js +3 -1
- package/graphql/types.js.map +1 -1
- package/import/constants.js +3 -1
- package/import/constants.js.map +1 -1
- package/import/create/blocksHandler.js +3 -3
- package/import/create/blocksHandler.js.map +1 -1
- package/import/create/formsHandler.js +3 -1
- package/import/create/formsHandler.js.map +1 -1
- package/import/create/index.js +3 -1
- package/import/create/index.js.map +1 -1
- package/import/create/pagesHandler.js +3 -1
- package/import/create/pagesHandler.js.map +1 -1
- package/import/create/templatesHandler.js +3 -1
- package/import/create/templatesHandler.js.map +1 -1
- package/import/process/blocks/blocksHandler.js +6 -6
- package/import/process/blocks/blocksHandler.js.map +1 -1
- package/import/process/blocks/importBlock.d.ts +2 -2
- package/import/process/blocks/importBlock.js +33 -27
- package/import/process/blocks/importBlock.js.map +1 -1
- package/import/process/forms/formsHandler.js +4 -2
- package/import/process/forms/formsHandler.js.map +1 -1
- package/import/process/forms/importForm.d.ts +1 -1
- package/import/process/forms/importForm.js +6 -2
- package/import/process/forms/importForm.js.map +1 -1
- package/import/process/index.js +3 -1
- package/import/process/index.js.map +1 -1
- package/import/process/pages/importPage.d.ts +1 -1
- package/import/process/pages/importPage.js +8 -6
- package/import/process/pages/importPage.js.map +1 -1
- package/import/process/pages/pagesHandler.js +3 -1
- package/import/process/pages/pagesHandler.js.map +1 -1
- package/import/process/templates/importTemplate.d.ts +1 -1
- package/import/process/templates/importTemplate.js +6 -2
- package/import/process/templates/importTemplate.js.map +1 -1
- package/import/process/templates/templatesHandler.js +3 -1
- package/import/process/templates/templatesHandler.js.map +1 -1
- package/import/utils/deleteS3Folder.js +3 -1
- package/import/utils/deleteS3Folder.js.map +1 -1
- package/import/utils/extractAndUploadZipFileContents.js +3 -2
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -1
- package/import/utils/extractZipAndUploadToS3.js +3 -1
- package/import/utils/extractZipAndUploadToS3.js.map +1 -1
- package/import/utils/getFileNameWithoutExt.js +3 -1
- package/import/utils/getFileNameWithoutExt.js.map +1 -1
- package/import/utils/index.js +3 -1
- package/import/utils/index.js.map +1 -1
- package/import/utils/initialStats.js +3 -1
- package/import/utils/initialStats.js.map +1 -1
- package/import/utils/prepareDataDirMap.js +3 -1
- package/import/utils/prepareDataDirMap.js.map +1 -1
- package/import/utils/updateFilesInData.js +5 -2
- package/import/utils/updateFilesInData.js.map +1 -1
- package/import/utils/uploadAssets.js +54 -11
- package/import/utils/uploadAssets.js.map +1 -1
- package/import/utils/uploadFilesFromS3.d.ts +1 -1
- package/import/utils/uploadFilesFromS3.js +4 -2
- package/import/utils/uploadFilesFromS3.js.map +1 -1
- package/mockSecurity.js +3 -1
- package/mockSecurity.js.map +1 -1
- package/package.json +27 -32
- package/types.js +62 -8
- package/types.js.map +1 -1
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.PageExporter = void 0;
|
8
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
9
|
+
var _zipper = _interopRequireDefault(require("../../zipper"));
|
10
|
+
var _utils = require("../../utils");
|
11
|
+
class PageExporter {
|
12
|
+
constructor(fileManager) {
|
13
|
+
this.fileManager = fileManager;
|
14
|
+
}
|
15
|
+
async execute(page, exportPagesDataKey) {
|
16
|
+
// Extract all files
|
17
|
+
const files = (0, _utils.extractFilesFromData)(page.content || {});
|
18
|
+
// Extract images from page settings
|
19
|
+
const pageSettingsImages = [(0, _get.default)(page, "settings.general.image"), (0, _get.default)(page, "settings.social.image")].filter(image => image && image.src);
|
20
|
+
const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);
|
21
|
+
// Get file data for all images
|
22
|
+
const imageFilesData = [];
|
23
|
+
if (fileIds.length > 0) {
|
24
|
+
const [filesData] = await this.fileManager.listFiles({
|
25
|
+
where: {
|
26
|
+
id_in: fileIds
|
27
|
+
}
|
28
|
+
});
|
29
|
+
imageFilesData.push(...filesData);
|
30
|
+
}
|
31
|
+
|
32
|
+
// Extract the page data in a json file and upload it to S3
|
33
|
+
const pageData = {
|
34
|
+
page: {
|
35
|
+
content: page.content,
|
36
|
+
title: page.title,
|
37
|
+
path: page.path,
|
38
|
+
version: page.version,
|
39
|
+
status: page.status,
|
40
|
+
settings: page.settings
|
41
|
+
},
|
42
|
+
files: imageFilesData
|
43
|
+
};
|
44
|
+
const pageDataBuffer = Buffer.from(JSON.stringify(pageData));
|
45
|
+
const zipper = new _zipper.default({
|
46
|
+
exportInfo: {
|
47
|
+
files: imageFilesData,
|
48
|
+
name: page.title,
|
49
|
+
dataBuffer: pageDataBuffer
|
50
|
+
},
|
51
|
+
archiveFileKey: exportPagesDataKey
|
52
|
+
});
|
53
|
+
return zipper.process();
|
54
|
+
}
|
55
|
+
}
|
56
|
+
exports.PageExporter = PageExporter;
|
57
|
+
|
58
|
+
//# sourceMappingURL=PageExporter.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_get","_interopRequireDefault","require","_zipper","_utils","PageExporter","constructor","fileManager","execute","page","exportPagesDataKey","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","exports"],"sources":["PageExporter.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport { Page } from \"@webiny/api-page-builder/types\";\nimport { File, FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport Zipper from \"~/export/zipper\";\nimport { extractFilesFromData } from \"~/export/utils\";\n\nexport interface ExportedPageData {\n page: Pick<Page, \"content\" | \"title\" | \"version\" | \"status\" | \"settings\" | \"path\">;\n files: File[];\n}\n\nexport class PageExporter {\n private fileManager: FileManagerContext[\"fileManager\"];\n\n constructor(fileManager: FileManagerContext[\"fileManager\"]) {\n this.fileManager = fileManager;\n }\n\n async execute(page: Page, exportPagesDataKey: string) {\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 this.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}\n"],"mappings":";;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAOO,MAAMG,YAAY,CAAC;EAGtBC,WAAWA,CAACC,WAA8C,EAAE;IACxD,IAAI,CAACA,WAAW,GAAGA,WAAW;EAClC;EAEA,MAAMC,OAAOA,CAACC,IAAU,EAAEC,kBAA0B,EAAE;IAClD;IACA,MAAMC,KAAK,GAAG,IAAAC,2BAAoB,EAACH,IAAI,CAACI,OAAO,IAAI,CAAC,CAAC,CAAC;IACtD;IACA,MAAMC,kBAAkB,GAAG,CACvB,IAAAC,YAAG,EAACN,IAAI,EAAE,wBAAwB,CAAC,EACnC,IAAAM,YAAG,EAACN,IAAI,EAAE,uBAAuB,CAAC,CACrC,CAACO,MAAM,CAACC,KAAK,IAAIA,KAAK,IAAIA,KAAK,CAACC,GAAG,CAAC;IAErC,MAAMC,OAAO,GAAG,CAAC,GAAGR,KAAK,EAAE,GAAGG,kBAAkB,CAAC,CAACM,GAAG,CAACC,SAAS,IAAIA,SAAS,CAACC,EAAE,CAAC;IAChF;IACA,MAAMC,cAAc,GAAG,EAAE;IACzB,IAAIJ,OAAO,CAACK,MAAM,GAAG,CAAC,EAAE;MACpB,MAAM,CAACC,SAAS,CAAC,GAAG,MAAM,IAAI,CAAClB,WAAW,CAACmB,SAAS,CAAC;QAAEC,KAAK,EAAE;UAAEC,KAAK,EAAET;QAAQ;MAAE,CAAC,CAAC;MACnFI,cAAc,CAACM,IAAI,CAAC,GAAGJ,SAAS,CAAC;IACrC;;IAEA;IACA,MAAMK,QAAQ,GAAG;MACbrB,IAAI,EAAE;QACFI,OAAO,EAAEJ,IAAI,CAACI,OAAO;QACrBkB,KAAK,EAAEtB,IAAI,CAACsB,KAAK;QACjBC,IAAI,EAAEvB,IAAI,CAACuB,IAAI;QACfC,OAAO,EAAExB,IAAI,CAACwB,OAAO;QACrBC,MAAM,EAAEzB,IAAI,CAACyB,MAAM;QACnBC,QAAQ,EAAE1B,IAAI,CAAC0B;MACnB,CAAC;MACDxB,KAAK,EAAEY;IACX,CAAC;IACD,MAAMa,cAAc,GAAGC,MAAM,CAACC,IAAI,CAACC,IAAI,CAACC,SAAS,CAACV,QAAQ,CAAC,CAAC;IAE5D,MAAMW,MAAM,GAAG,IAAIC,eAAM,CAAC;MACtBC,UAAU,EAAE;QACRhC,KAAK,EAAEY,cAAc;QACrBqB,IAAI,EAAEnC,IAAI,CAACsB,KAAK;QAChBc,UAAU,EAAET;MAChB,CAAC;MACDU,cAAc,EAAEpC;IACpB,CAAC,CAAC;IAEF,OAAO+B,MAAM,CAACM,OAAO,CAAC,CAAC;EAC3B;AACJ;AAACC,OAAA,CAAA3C,YAAA,GAAAA,YAAA"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { PageTemplate } from "@webiny/api-page-builder/types";
|
2
|
+
import { File, FileManagerContext } from "@webiny/api-file-manager/types";
|
3
|
+
export interface ExportedTemplateData {
|
4
|
+
template: Pick<PageTemplate, "title" | "slug" | "tags" | "description" | "content" | "layout" | "pageCategory">;
|
5
|
+
files: File[];
|
6
|
+
}
|
7
|
+
export declare class PageTemplateExporter {
|
8
|
+
private fileManager;
|
9
|
+
constructor(fileManager: FileManagerContext["fileManager"]);
|
10
|
+
execute(template: PageTemplate, exportTemplatesDataKey: string): Promise<import("@aws-sdk/client-s3").CompleteMultipartUploadOutput>;
|
11
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.PageTemplateExporter = void 0;
|
8
|
+
var _zipper = _interopRequireDefault(require("../../zipper"));
|
9
|
+
var _utils = require("../../utils");
|
10
|
+
class PageTemplateExporter {
|
11
|
+
constructor(fileManager) {
|
12
|
+
this.fileManager = fileManager;
|
13
|
+
}
|
14
|
+
async execute(template, exportTemplatesDataKey) {
|
15
|
+
// Extract all files
|
16
|
+
const files = (0, _utils.extractFilesFromData)(template.content || {});
|
17
|
+
const fileIds = files.map(imageFile => imageFile.id);
|
18
|
+
// Get file data for all images
|
19
|
+
const imageFilesData = [];
|
20
|
+
if (fileIds.length > 0) {
|
21
|
+
const [filesData] = await this.fileManager.listFiles({
|
22
|
+
where: {
|
23
|
+
id_in: fileIds
|
24
|
+
}
|
25
|
+
});
|
26
|
+
imageFilesData.push(...filesData);
|
27
|
+
}
|
28
|
+
|
29
|
+
// Extract the template data in a json file and upload it to S3
|
30
|
+
const templateData = {
|
31
|
+
template: {
|
32
|
+
title: template.title,
|
33
|
+
slug: template.slug,
|
34
|
+
tags: template.tags,
|
35
|
+
description: template.description,
|
36
|
+
content: template.content,
|
37
|
+
layout: template.layout,
|
38
|
+
pageCategory: template.pageCategory
|
39
|
+
},
|
40
|
+
files: imageFilesData
|
41
|
+
};
|
42
|
+
const templateDataBuffer = Buffer.from(JSON.stringify(templateData));
|
43
|
+
const zipper = new _zipper.default({
|
44
|
+
exportInfo: {
|
45
|
+
files: imageFilesData,
|
46
|
+
name: template.title,
|
47
|
+
dataBuffer: templateDataBuffer
|
48
|
+
},
|
49
|
+
archiveFileKey: exportTemplatesDataKey
|
50
|
+
});
|
51
|
+
return zipper.process();
|
52
|
+
}
|
53
|
+
}
|
54
|
+
exports.PageTemplateExporter = PageTemplateExporter;
|
55
|
+
|
56
|
+
//# sourceMappingURL=PageTemplateExporter.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_zipper","_interopRequireDefault","require","_utils","PageTemplateExporter","constructor","fileManager","execute","template","exportTemplatesDataKey","files","extractFilesFromData","content","fileIds","map","imageFile","id","imageFilesData","length","filesData","listFiles","where","id_in","push","templateData","title","slug","tags","description","layout","pageCategory","templateDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","name","dataBuffer","archiveFileKey","process","exports"],"sources":["PageTemplateExporter.ts"],"sourcesContent":["import { PageTemplate } from \"@webiny/api-page-builder/types\";\nimport { File, FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport Zipper from \"~/export/zipper\";\nimport { extractFilesFromData } from \"~/export/utils\";\n\nexport interface ExportedTemplateData {\n template: Pick<\n PageTemplate,\n \"title\" | \"slug\" | \"tags\" | \"description\" | \"content\" | \"layout\" | \"pageCategory\"\n >;\n files: File[];\n}\n\nexport class PageTemplateExporter {\n private fileManager: FileManagerContext[\"fileManager\"];\n\n constructor(fileManager: FileManagerContext[\"fileManager\"]) {\n this.fileManager = fileManager;\n }\n\n async execute(template: PageTemplate, exportTemplatesDataKey: string) {\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 this.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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AAM,GAAG,IAAIC,eAAM,CAAC;MACtBC,UAAU,EAAE;QACR5B,KAAK,EAAEO,cAAc;QACrBsB,IAAI,EAAE/B,QAAQ,CAACiB,KAAK;QACpBe,UAAU,EAAET;MAChB,CAAC;MACDU,cAAc,EAAEhC;IACpB,CAAC,CAAC;IAEF,OAAO2B,MAAM,CAACM,OAAO,CAAC,CAAC;EAC3B;AACJ;AAACC,OAAA,CAAAvC,oBAAA,GAAAA,oBAAA"}
|
@@ -7,9 +7,9 @@ exports.formsHandler = 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 _FormExporter = require("./exporters/FormExporter");
|
13
13
|
/**
|
14
14
|
* Handles the export forms process workflow.
|
15
15
|
*/
|
@@ -37,7 +37,7 @@ const formsHandler = 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".
|
@@ -101,8 +101,8 @@ const formsHandler = async (configuration, payload, context) => {
|
|
101
101
|
});
|
102
102
|
prevStatusOfSubTask = subTask.status;
|
103
103
|
log(`Extracting form data and uploading to storage...`);
|
104
|
-
|
105
|
-
const formDataZip = await
|
104
|
+
const formExporter = new _FormExporter.FormExporter();
|
105
|
+
const formDataZip = await formExporter.execute(form, exportFormsDataKey);
|
106
106
|
log(`Finish uploading zip...`);
|
107
107
|
// Update task record in DB
|
108
108
|
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
@@ -184,4 +184,6 @@ const formsHandler = async (configuration, payload, context) => {
|
|
184
184
|
error: null
|
185
185
|
};
|
186
186
|
};
|
187
|
-
exports.formsHandler = formsHandler;
|
187
|
+
exports.formsHandler = formsHandler;
|
188
|
+
|
189
|
+
//# sourceMappingURL=formsHandler.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["formsHandler","configuration","payload","context","log","console","subTask","noPendingTask","prevStatusOfSubTask","ImportExportTaskStatus","PENDING","formBuilder","pageBuilder","taskId","subTaskIndex","type","identity","mockSecurity","importExportTask","getSubTask","zeroPad","status","data","error","id","input","formId","exportFormsDataKey","revisionType","form","ExportRevisionType","PUBLISHED","getLatestPublishedFormRevision","getForm","e","NotFoundError","version","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","formDataZip","exportForm","COMPLETED","message","key","Key","FAILED","name","stack","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process"],"sources":["formsHandler.ts"],"sourcesContent":["import { ExportRevisionType, ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { exportForm } 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 forms process workflow.\n */\nexport const formsHandler = async (\n configuration: Configuration,\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n let subTask;\n let noPendingTask = true;\n let prevStatusOfSubTask = ImportExportTaskStatus.PENDING;\n\n log(\"RUNNING Export Forms Process Handler\");\n const { formBuilder, pageBuilder } = context;\n const { taskId, subTaskIndex, type, identity } = payload;\n // Disable authorization; this is necessary because we call Form Builder CRUD methods which include authorization checks\n // and this Lambda is invoked internally, without credentials.\n mockSecurity(identity as SecurityIdentity, context);\n\n try {\n /*\n * Note: We're not going to DB for finding the next sub-task to process,\n * because the data might be out of sync due to GSI eventual consistency.\n */\n subTask = await pageBuilder.importExportTask.getSubTask(taskId, zeroPad(subTaskIndex, 5));\n /**\n * Base condition!!\n * Bail out early, if task not found or task's status is not \"pending\".\n */\n if (!subTask || subTask.status !== ImportExportTaskStatus.PENDING) {\n noPendingTask = true;\n return {\n data: \"\",\n error: null\n };\n } else {\n noPendingTask = false;\n }\n\n log(`Fetched sub task => ${subTask.id}`);\n\n const { input } = subTask;\n const { formId, exportFormsDataKey, revisionType } = input;\n\n /**\n * At the moment, we only export a single revision of the form.\n * It could be \"published\" or \"latest\" depending upon user input.\n *\n * Note: In case of no \"published\" revision available, we use the latest revision.\n */\n let form;\n try {\n if (revisionType === ExportRevisionType.PUBLISHED) {\n // Get \"published\" form.\n form = await formBuilder.getLatestPublishedFormRevision(formId);\n } else {\n // Get \"latest\" form.\n form = await formBuilder.getForm(formId);\n }\n } catch (e) {\n // If we're looking for \"published\" form and doesn't found it, get latest form.\n if (revisionType === ExportRevisionType.PUBLISHED && e instanceof NotFoundError) {\n form = await formBuilder.getForm(formId);\n } else {\n throw e;\n }\n }\n\n if (!form) {\n log(`Unable to load form \"${formId}\"`);\n throw new NotFoundError(`Unable to load form \"${formId}\"`);\n }\n\n log(`Processing form key \"${formId}\" | version ${form.version} | ${form.status}`);\n\n // Mark task status as PROCESSING\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.PROCESSING\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.PROCESSING\n });\n prevStatusOfSubTask = subTask.status;\n\n log(`Extracting form data and uploading to storage...`);\n // Extract Form\n const formDataZip = await exportForm(form, exportFormsDataKey);\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for form \"${form.id}\" v${form.version} (${form.status}).`,\n key: formDataZip.Key\n }\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.COMPLETED\n });\n prevStatusOfSubTask = subTask.status;\n } catch (e) {\n log(\"[EXPORT_PAGES_PROCESS] Error => \", e);\n\n if (subTask && subTask.id) {\n /**\n * In case of error, we'll update the task status to \"failed\",\n * so that, client can show notify the user appropriately.\n */\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n stack: e.stack,\n code: \"EXPORT_FAILED\"\n }\n });\n\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.FAILED\n });\n prevStatusOfSubTask = subTask.status;\n }\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n } finally {\n // Base condition!\n if (noPendingTask) {\n log(`No pending sub-task for task ${taskId}`);\n // Combine individual form zip files.\n await invokeHandlerClient<ExtractPayload>({\n context,\n name: configuration.handlers.combine,\n payload: {\n taskId,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export forms - combine\"\n });\n } else {\n console.log(`Invoking PROCESS for task \"${subTaskIndex + 1}\"`);\n // We want to continue with Self invocation no matter if current form error out.\n await invokeHandlerClient<Payload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId,\n type,\n subTaskIndex: subTaskIndex + 1,\n identity: context.security.getIdentity()\n },\n description: \"Export forms - process - subtask\"\n });\n }\n }\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAEA;AAEA;AAGA;AACA;AACA;AACO,MAAMA,YAAY,GAAG,OACxBC,aA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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"}
|
1
|
+
{"version":3,"names":["_types","require","_client","_handlerGraphql","_mockSecurity","_utils","_FormExporter","formsHandler","configuration","payload","context","log","console","subTask","noPendingTask","prevStatusOfSubTask","ImportExportTaskStatus","PENDING","formBuilder","pageBuilder","taskId","subTaskIndex","type","identity","mockSecurity","importExportTask","getSubTask","zeroPad","status","data","error","id","input","formId","exportFormsDataKey","revisionType","form","ExportRevisionType","PUBLISHED","getLatestPublishedFormRevision","getForm","e","NotFoundError","version","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","formExporter","FormExporter","formDataZip","execute","COMPLETED","message","key","Key","FAILED","name","stack","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process","exports"],"sources":["formsHandler.ts"],"sourcesContent":["import { ExportRevisionType, 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 { FormExporter } from \"./exporters/FormExporter\";\n\n/**\n * Handles the export forms process workflow.\n */\nexport const formsHandler = async (\n configuration: Configuration,\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n let subTask;\n let noPendingTask = true;\n let prevStatusOfSubTask = ImportExportTaskStatus.PENDING;\n\n log(\"RUNNING Export Forms Process Handler\");\n const { formBuilder, pageBuilder } = context;\n const { taskId, subTaskIndex, type, identity } = payload;\n // Disable authorization; this is necessary because we call Form Builder CRUD methods which include authorization checks\n // and this Lambda is invoked internally, without credentials.\n mockSecurity(identity as SecurityIdentity, context);\n\n try {\n /*\n * Note: We're not going to DB for finding the next sub-task to process,\n * because the data might be out of sync due to GSI eventual consistency.\n */\n subTask = await pageBuilder.importExportTask.getSubTask(taskId, zeroPad(subTaskIndex, 5));\n /**\n * Base condition!!\n * Bail out early, if task not found or task's status is not \"pending\".\n */\n if (!subTask || subTask.status !== ImportExportTaskStatus.PENDING) {\n noPendingTask = true;\n return {\n data: \"\",\n error: null\n };\n } else {\n noPendingTask = false;\n }\n\n log(`Fetched sub task => ${subTask.id}`);\n\n const { input } = subTask;\n const { formId, exportFormsDataKey, revisionType } = input;\n\n /**\n * At the moment, we only export a single revision of the form.\n * It could be \"published\" or \"latest\" depending upon user input.\n *\n * Note: In case of no \"published\" revision available, we use the latest revision.\n */\n let form;\n try {\n if (revisionType === ExportRevisionType.PUBLISHED) {\n // Get \"published\" form.\n form = await formBuilder.getLatestPublishedFormRevision(formId);\n } else {\n // Get \"latest\" form.\n form = await formBuilder.getForm(formId);\n }\n } catch (e) {\n // If we're looking for \"published\" form and doesn't found it, get latest form.\n if (revisionType === ExportRevisionType.PUBLISHED && e instanceof NotFoundError) {\n form = await formBuilder.getForm(formId);\n } else {\n throw e;\n }\n }\n\n if (!form) {\n log(`Unable to load form \"${formId}\"`);\n throw new NotFoundError(`Unable to load form \"${formId}\"`);\n }\n\n log(`Processing form key \"${formId}\" | version ${form.version} | ${form.status}`);\n\n // Mark task status as PROCESSING\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.PROCESSING\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.PROCESSING\n });\n prevStatusOfSubTask = subTask.status;\n\n log(`Extracting form data and uploading to storage...`);\n const formExporter = new FormExporter();\n const formDataZip = await formExporter.execute(form, exportFormsDataKey);\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for form \"${form.id}\" v${form.version} (${form.status}).`,\n key: formDataZip.Key\n }\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.COMPLETED\n });\n prevStatusOfSubTask = subTask.status;\n } catch (e) {\n log(\"[EXPORT_PAGES_PROCESS] Error => \", e);\n\n if (subTask && subTask.id) {\n /**\n * In case of error, we'll update the task status to \"failed\",\n * so that, client can show notify the user appropriately.\n */\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n stack: e.stack,\n code: \"EXPORT_FAILED\"\n }\n });\n\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.FAILED\n });\n prevStatusOfSubTask = subTask.status;\n }\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n } finally {\n // Base condition!\n if (noPendingTask) {\n log(`No pending sub-task for task ${taskId}`);\n // Combine individual form zip files.\n await invokeHandlerClient<ExtractPayload>({\n context,\n name: configuration.handlers.combine,\n payload: {\n taskId,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export forms - combine\"\n });\n } else {\n console.log(`Invoking PROCESS for task \"${subTaskIndex + 1}\"`);\n // We want to continue with Self invocation no matter if current form error out.\n await invokeHandlerClient<Payload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId,\n type,\n subTaskIndex: subTaskIndex + 1,\n identity: context.security.getIdentity()\n },\n description: \"Export forms - process - subtask\"\n });\n }\n }\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,aAAA,GAAAL,OAAA;AAEA;AACA;AACA;AACO,MAAMM,YAAY,GAAG,MAAAA,CACxBC,aAA4B,EAC5BC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EACvB,IAAIE,OAAO;EACX,IAAIC,aAAa,GAAG,IAAI;EACxB,IAAIC,mBAAmB,GAAGC,6BAAsB,CAACC,OAAO;EAExDN,GAAG,CAAC,sCAAsC,CAAC;EAC3C,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;EAEnD,IAAI;IACA;AACR;AACA;AACA;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MACA,MAAM,IAAAwC,2BAAmB,EAAU;QAC/BnD,OAAO;QACPgD,IAAI,EAAElD,aAAa,CAACsD,QAAQ,CAACK,OAAO;QACpC1D,OAAO,EAAE;UACLW,MAAM;UACNE,IAAI;UACJD,YAAY,EAAEA,YAAY,GAAG,CAAC;UAC9BE,QAAQ,EAAEb,OAAO,CAACsD,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN;EACJ;EACA,OAAO;IACHrC,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAACsC,OAAA,CAAA7D,YAAA,GAAAA,YAAA"}
|
package/export/process/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["configuration","createRawEventHandler","payload","context","security","withoutAuthorization","type","blocksHandler","formsHandler","templatesHandler","pagesHandler"],"sources":["index.ts"],"sourcesContent":["import { PbImportExportContext } from \"~/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { blocksHandler } from \"~/export/process/blocksHandler\";\nimport { formsHandler } from \"~/export/process/formsHandler\";\nimport { pagesHandler } from \"~/export/process/pagesHandler\";\nimport { templatesHandler } from \"~/export/process/templatesHandler\";\n\nexport interface Configuration {\n handlers: {\n process: string;\n combine: string;\n };\n}\n\nexport interface Payload {\n taskId: string;\n subTaskIndex: number;\n type: string;\n identity?: SecurityIdentity;\n}\n\nexport interface Response {\n data: string | null;\n error: Partial<Error> | null;\n}\n\nexport default (configuration: Configuration) => {\n return createRawEventHandler<Payload, PbImportExportContext, Response>(\n async ({ payload, context }) => {\n return context.security.withoutAuthorization(() => {\n switch (payload.type) {\n case \"block\": {\n return blocksHandler(configuration, payload, context);\n }\n case \"form\": {\n return formsHandler(configuration, payload, context);\n }\n case \"template\": {\n return templatesHandler(configuration, payload, context);\n }\n default: {\n return pagesHandler(configuration, payload, context);\n }\n }\n });\n }\n );\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AAAqE,
|
1
|
+
{"version":3,"names":["_handlerAws","require","_blocksHandler","_formsHandler","_pagesHandler","_templatesHandler","_default","configuration","createRawEventHandler","payload","context","security","withoutAuthorization","type","blocksHandler","formsHandler","templatesHandler","pagesHandler","exports","default"],"sources":["index.ts"],"sourcesContent":["import { PbImportExportContext } from \"~/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { blocksHandler } from \"~/export/process/blocksHandler\";\nimport { formsHandler } from \"~/export/process/formsHandler\";\nimport { pagesHandler } from \"~/export/process/pagesHandler\";\nimport { templatesHandler } from \"~/export/process/templatesHandler\";\n\nexport interface Configuration {\n handlers: {\n process: string;\n combine: string;\n };\n}\n\nexport interface Payload {\n taskId: string;\n subTaskIndex: number;\n type: string;\n identity?: SecurityIdentity;\n}\n\nexport interface Response {\n data: string | null;\n error: Partial<Error> | null;\n}\n\nexport default (configuration: Configuration) => {\n return createRawEventHandler<Payload, PbImportExportContext, Response>(\n async ({ payload, context }) => {\n return context.security.withoutAuthorization(() => {\n switch (payload.type) {\n case \"block\": {\n return blocksHandler(configuration, payload, context);\n }\n case \"form\": {\n return formsHandler(configuration, payload, context);\n }\n case \"template\": {\n return templatesHandler(configuration, payload, context);\n }\n default: {\n return pagesHandler(configuration, payload, context);\n }\n }\n });\n }\n );\n};\n"],"mappings":";;;;;;AAEA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAAqE,IAAAK,QAAA,GAqBrDC,aAA4B,IAAK;EAC7C,OAAO,IAAAC,iCAAqB,EACxB,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IAC5B,OAAOA,OAAO,CAACC,QAAQ,CAACC,oBAAoB,CAAC,MAAM;MAC/C,QAAQH,OAAO,CAACI,IAAI;QAChB,KAAK,OAAO;UAAE;YACV,OAAO,IAAAC,4BAAa,EAACP,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;UACzD;QACA,KAAK,MAAM;UAAE;YACT,OAAO,IAAAK,0BAAY,EAACR,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;UACxD;QACA,KAAK,UAAU;UAAE;YACb,OAAO,IAAAM,kCAAgB,EAACT,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;UAC5D;QACA;UAAS;YACL,OAAO,IAAAO,0BAAY,EAACV,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;UACxD;MACJ;IACJ,CAAC,CAAC;EACN,CACJ,CAAC;AACL,CAAC;AAAAQ,OAAA,CAAAC,OAAA,GAAAb,QAAA"}
|
@@ -7,9 +7,9 @@ exports.pagesHandler = 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 _PageExporter = require("./exporters/PageExporter");
|
13
13
|
/**
|
14
14
|
* Handles the export pages process workflow.
|
15
15
|
*/
|
@@ -37,7 +37,7 @@ const pagesHandler = 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".
|
@@ -103,8 +103,8 @@ const pagesHandler = async (configuration, payload, context) => {
|
|
103
103
|
});
|
104
104
|
prevStatusOfSubTask = subTask.status;
|
105
105
|
log(`Extracting page data and uploading to storage...`);
|
106
|
-
|
107
|
-
const pageDataZip = await
|
106
|
+
const pageExporter = new _PageExporter.PageExporter(fileManager);
|
107
|
+
const pageDataZip = await pageExporter.execute(page, exportPagesDataKey);
|
108
108
|
log(`Finish uploading zip...`);
|
109
109
|
// Update task record in DB
|
110
110
|
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
@@ -186,4 +186,6 @@ const pagesHandler = async (configuration, payload, context) => {
|
|
186
186
|
error: null
|
187
187
|
};
|
188
188
|
};
|
189
|
-
exports.pagesHandler = pagesHandler;
|
189
|
+
exports.pagesHandler = pagesHandler;
|
190
|
+
|
191
|
+
//# sourceMappingURL=pagesHandler.js.map
|
@@ -1 +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;AACA;AACO,MAAMA,YAAY,GAAG,OACxBC,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,sCAAsC,CAAC;EAC3C,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;EAEnD,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;IAExC,MAAM;MAAEC;IAAM,CAAC,GAAGnB,OAAO;IACzB,MAAM;MAAE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,CAACqB,WAAW,CAAC1B,MAAM,EAAE;QACnD2B,UAAU,EAAEhC,mBAAmB;QAC/BiC,UAAU,EAAEhC,6BAAsB,CAACuC;MACvC,CAAC,CAAC;MACFxC,mBAAmB,GAAGF,OAAO,CAACe,MAAM;IACxC;IAEA,OAAO;MACHC,IAAI,EAAE,IAAI;MACVC,KAAK,EAAE;QACHsB,OAAO,EAAEX,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"}
|
1
|
+
{"version":3,"names":["_types","require","_client","_handlerGraphql","_mockSecurity","_utils","_PageExporter","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","pageExporter","PageExporter","pageDataZip","execute","COMPLETED","message","key","Key","FAILED","name","stack","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process","exports"],"sources":["pagesHandler.ts"],"sourcesContent":["import { ExportRevisionType, 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 { PageExporter } from \"./exporters/PageExporter\";\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\n const pageExporter = new PageExporter(fileManager);\n const pageDataZip = await pageExporter.execute(page, exportPagesDataKey);\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 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,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,aAAA,GAAAL,OAAA;AAEA;AACA;AACA;AACO,MAAMM,YAAY,GAAG,MAAAA,CACxBC,aAA4B,EAC5BC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EACvB,IAAIE,OAAO;EACX,IAAI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+BS,MAAO,EAAC,CAAC;MAC7C;MACA,MAAM,IAAAyC,2BAAmB,EAAiB;QACtCnD,OAAO;QACPgD,IAAI,EAAElD,aAAa,CAACsD,QAAQ,CAACC,OAAO;QACpCtD,OAAO,EAAE;UACLW,MAAM;UACNE,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAACsD,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN,CAAC,MAAM;MACHtD,OAAO,CAACD,GAAG,CAAE,8BAA6BU,YAAY,GAAG,CAAE,GAAE,CAAC;MAC9D;MACA,MAAM,IAAAwC,2BAAmB,EAAU;QAC/BnD,OAAO;QACPgD,IAAI,EAAElD,aAAa,CAACsD,QAAQ,CAACK,OAAO;QACpC1D,OAAO,EAAE;UACLW,MAAM;UACNE,IAAI;UACJD,YAAY,EAAEA,YAAY,GAAG,CAAC;UAC9BE,QAAQ,EAAEb,OAAO,CAACsD,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN;EACJ;EACA,OAAO;IACHrC,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAACsC,OAAA,CAAA7D,YAAA,GAAAA,YAAA"}
|
@@ -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;IAExC,MAAM;MAAEC;IAAM,CAAC,GAAGnB,OAAO;IACzB,MAAM;MAAEoB,UAAU;MAAEC;IAAuB,CAAC,GAAGF,KAAK;IAEpD,MAAMG,QAAQ,GAAG,MAAMjB,WAAW,CAACkB,eAAe,CAAC;MAAEC,KAAK,EAAE;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AAY,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,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,qBAAA,GAAAL,OAAA;AAEA;AACA;A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BAAmB,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,34 +1,34 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
/// <reference types="node" />
|
3
3
|
import { Readable } from "stream";
|
4
|
-
import S3 from "aws-sdk/
|
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
19
|
streamPassThrough: import("stream").PassThrough;
|
20
20
|
/**
|
21
21
|
* We're not using the `FileManager` storage plugin here because it currently doesn't support streams.
|
22
22
|
*/
|
23
|
-
streamPassThroughUploadPromise: Promise<
|
23
|
+
streamPassThroughUploadPromise: Promise<import("@aws-sdk/client-s3").AbortMultipartUploadCommandOutput | import("@webiny/aws-sdk/client-s3").CompleteMultipartUploadCommandOutput>;
|
24
24
|
};
|
25
25
|
upload(params: {
|
26
26
|
Key: string;
|
27
27
|
ContentType: string;
|
28
28
|
Body: Buffer;
|
29
|
-
}): Promise<
|
30
|
-
listObject(prefix: string): Promise<
|
31
|
-
deleteObject(key: string): Promise<
|
29
|
+
}): Promise<void>;
|
30
|
+
listObject(prefix: string): Promise<ListObjectsOutput>;
|
31
|
+
deleteObject(key: string): Promise<DeleteObjectOutput>;
|
32
32
|
}
|
33
33
|
export declare const s3Stream: S3Stream;
|
34
34
|
export {};
|