@webiny/api-page-builder-import-export 0.0.0-unstable.3386f66516 → 0.0.0-unstable.39223eb3c1
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 +1 -1
- package/client.js +12 -25
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.d.ts +2 -2
- package/export/combine/blocksHandler.js +14 -19
- package/export/combine/blocksHandler.js.map +1 -1
- package/export/combine/formsHandler.d.ts +6 -0
- package/export/combine/{pagesHandler.js → formsHandler.js} +25 -30
- package/export/combine/formsHandler.js.map +1 -0
- package/export/combine/index.d.ts +2 -2
- package/export/combine/index.js +24 -23
- package/export/combine/index.js.map +1 -1
- package/export/combine/templatesHandler.d.ts +2 -2
- package/export/combine/templatesHandler.js +14 -19
- package/export/combine/templatesHandler.js.map +1 -1
- package/export/pages/ExportPagesCleanup.d.ts +5 -0
- package/export/pages/ExportPagesCleanup.js +82 -0
- package/export/pages/ExportPagesCleanup.js.map +1 -0
- package/export/pages/ExportPagesController.d.ts +5 -0
- package/export/pages/ExportPagesController.js +31 -0
- package/export/pages/ExportPagesController.js.map +1 -0
- package/export/pages/ExportPagesZipPages.d.ts +5 -0
- package/export/pages/ExportPagesZipPages.js +23 -0
- package/export/pages/ExportPagesZipPages.js.map +1 -0
- package/export/pages/controller/CombineZippedPages.d.ts +5 -0
- package/export/pages/controller/CombineZippedPages.js +75 -0
- package/export/pages/controller/CombineZippedPages.js.map +1 -0
- package/export/pages/controller/CreateZipPagesTasks.d.ts +8 -0
- package/export/pages/controller/CreateZipPagesTasks.js +103 -0
- package/export/pages/controller/CreateZipPagesTasks.js.map +1 -0
- package/export/pages/controller/ProcessZipPagesTasks.d.ts +6 -0
- package/export/pages/controller/ProcessZipPagesTasks.js +61 -0
- package/export/pages/controller/ProcessZipPagesTasks.js.map +1 -0
- package/export/pages/types.d.ts +53 -0
- package/export/pages/types.js +26 -0
- package/export/pages/types.js.map +1 -0
- package/export/pages/utils.d.ts +2 -0
- package/export/pages/utils.js +13 -0
- package/export/pages/utils.js.map +1 -0
- package/export/pages/zipPages/ZipPages.d.ts +5 -0
- package/export/pages/zipPages/ZipPages.js +100 -0
- package/export/pages/zipPages/ZipPages.js.map +1 -0
- package/export/pages/zipPages/ZipPagesDataManager.d.ts +14 -0
- package/export/pages/zipPages/ZipPagesDataManager.js +46 -0
- package/export/pages/zipPages/ZipPagesDataManager.js.map +1 -0
- package/export/pages/zipPages/getPageFactory.d.ts +4 -0
- package/export/pages/zipPages/getPageFactory.js +38 -0
- package/export/pages/zipPages/getPageFactory.js.map +1 -0
- package/export/process/blocksHandler.d.ts +2 -2
- package/export/process/blocksHandler.js +29 -36
- 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 +18 -0
- package/export/process/exporters/PageExporter.js +59 -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 +58 -0
- package/export/process/exporters/PageTemplateExporter.js.map +1 -0
- package/export/process/formsHandler.d.ts +6 -0
- package/export/process/{pagesHandler.js → formsHandler.js} +48 -63
- package/export/process/formsHandler.js.map +1 -0
- package/export/process/index.d.ts +2 -2
- package/export/process/index.js +24 -23
- package/export/process/index.js.map +1 -1
- package/export/process/templatesHandler.d.ts +2 -2
- package/export/process/templatesHandler.js +29 -37
- package/export/process/templatesHandler.js.map +1 -1
- package/export/s3Stream.d.ts +16 -11
- package/export/s3Stream.js +27 -42
- package/export/s3Stream.js.map +1 -1
- package/export/utils.d.ts +11 -9
- package/export/utils.js +54 -58
- package/export/utils.js.map +1 -1
- package/export/zipper.d.ts +7 -6
- package/export/zipper.js +46 -62
- package/export/zipper.js.map +1 -1
- package/graphql/crud/blocks.crud.d.ts +1 -1
- package/graphql/crud/blocks.crud.js +65 -62
- package/graphql/crud/blocks.crud.js.map +1 -1
- package/graphql/crud/forms.crud.d.ts +4 -0
- package/graphql/crud/forms.crud.js +162 -0
- package/graphql/crud/forms.crud.js.map +1 -0
- package/graphql/crud/importExportTasks.crud.d.ts +2 -2
- package/graphql/crud/importExportTasks.crud.js +150 -165
- package/graphql/crud/importExportTasks.crud.js.map +1 -1
- package/graphql/crud/pages.crud.d.ts +1 -1
- package/graphql/crud/pages.crud.js +241 -142
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.d.ts +1 -1
- package/graphql/crud/templates.crud.js +63 -47
- package/graphql/crud/templates.crud.js.map +1 -1
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js +4 -8
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.d.ts +2 -2
- package/graphql/graphql/blocks.gql.js +8 -13
- package/graphql/graphql/blocks.gql.js.map +1 -1
- 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 +2 -2
- package/graphql/graphql/importExportTasks.gql.js +8 -13
- package/graphql/graphql/importExportTasks.gql.js.map +1 -1
- package/graphql/graphql/pages.gql.d.ts +2 -2
- package/graphql/graphql/pages.gql.js +104 -20
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.d.ts +2 -2
- package/graphql/graphql/templates.gql.js +7 -12
- package/graphql/graphql/templates.gql.js.map +1 -1
- package/graphql/graphql/utils/resolve.d.ts +3 -3
- package/graphql/graphql/utils/resolve.js +15 -7
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/graphql.d.ts +1 -1
- package/graphql/graphql.js +3 -7
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +4 -6
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +194 -31
- package/graphql/types.js +3 -1
- package/graphql/types.js.map +1 -1
- package/import/constants.d.ts +3 -0
- package/import/constants.js +13 -0
- package/import/constants.js.map +1 -0
- package/import/create/blocksHandler.d.ts +2 -2
- package/import/create/blocksHandler.js +13 -22
- package/import/create/blocksHandler.js.map +1 -1
- package/import/create/formsHandler.d.ts +3 -0
- package/import/create/formsHandler.js +105 -0
- package/import/create/formsHandler.js.map +1 -0
- package/import/create/index.d.ts +2 -2
- package/import/create/index.js +24 -23
- package/import/create/index.js.map +1 -1
- package/import/create/pagesHandler.d.ts +2 -2
- package/import/create/pagesHandler.js +12 -19
- package/import/create/pagesHandler.js.map +1 -1
- package/import/create/templatesHandler.d.ts +2 -2
- package/import/create/templatesHandler.js +12 -19
- package/import/create/templatesHandler.js.map +1 -1
- package/import/pages/ImportPagesController.d.ts +5 -0
- package/import/pages/ImportPagesController.js +29 -0
- package/import/pages/ImportPagesController.js.map +1 -0
- package/import/pages/ImportPagesProcessPages.d.ts +6 -0
- package/import/pages/ImportPagesProcessPages.js +112 -0
- package/import/pages/ImportPagesProcessPages.js.map +1 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.d.ts +6 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.js +40 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.js.map +1 -0
- package/import/pages/controller/ImportPagesProcessZipFile.d.ts +5 -0
- package/import/pages/controller/ImportPagesProcessZipFile.js +71 -0
- package/import/pages/controller/ImportPagesProcessZipFile.js.map +1 -0
- package/import/pages/process/importPage.d.ts +10 -0
- package/import/pages/process/importPage.js +94 -0
- package/import/pages/process/importPage.js.map +1 -0
- package/import/pages/types.d.ts +48 -0
- package/import/pages/types.js +20 -0
- package/import/pages/types.js.map +1 -0
- package/import/process/blocks/ElementIdsProcessor.d.ts +5 -0
- package/import/process/blocks/ElementIdsProcessor.js +26 -0
- package/import/process/blocks/ElementIdsProcessor.js.map +1 -0
- package/import/process/{blocksHandler.d.ts → blocks/blocksHandler.d.ts} +2 -2
- package/import/process/{blocksHandler.js → blocks/blocksHandler.js} +32 -38
- package/import/process/blocks/blocksHandler.js.map +1 -0
- package/import/process/blocks/importBlock.d.ts +11 -0
- package/import/process/blocks/importBlock.js +101 -0
- package/import/process/blocks/importBlock.js.map +1 -0
- package/import/process/forms/formsHandler.d.ts +3 -0
- package/import/process/{pagesHandler.js → forms/formsHandler.js} +54 -57
- package/import/process/forms/formsHandler.js.map +1 -0
- package/import/process/forms/importForm.d.ts +9 -0
- package/import/process/forms/importForm.js +47 -0
- package/import/process/forms/importForm.js.map +1 -0
- package/import/process/index.d.ts +2 -2
- package/import/process/index.js +26 -25
- package/import/process/index.js.map +1 -1
- package/import/process/templates/importTemplate.d.ts +11 -0
- package/import/process/templates/importTemplate.js +70 -0
- package/import/process/templates/importTemplate.js.map +1 -0
- package/import/process/{templatesHandler.d.ts → templates/templatesHandler.d.ts} +2 -2
- package/import/process/{templatesHandler.js → templates/templatesHandler.js} +36 -34
- package/import/process/templates/templatesHandler.js.map +1 -0
- package/import/utils/deleteS3Folder.d.ts +1 -0
- package/import/utils/deleteS3Folder.js +21 -0
- package/import/utils/deleteS3Folder.js.map +1 -0
- package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
- package/import/utils/extractAndUploadZipFileContents.js +126 -0
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
- package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
- package/import/utils/extractZipAndUploadToS3.js +100 -0
- package/import/utils/extractZipAndUploadToS3.js.map +1 -0
- package/import/utils/getFileNameWithoutExt.d.ts +1 -0
- package/import/utils/getFileNameWithoutExt.js +13 -0
- package/import/utils/getFileNameWithoutExt.js.map +1 -0
- package/import/utils/index.d.ts +9 -0
- package/import/utils/index.js +106 -0
- package/import/utils/index.js.map +1 -0
- package/import/utils/initialStats.d.ts +7 -0
- package/import/utils/initialStats.js +18 -0
- package/import/utils/initialStats.js.map +1 -0
- package/import/utils/prepareDataDirMap.d.ts +6 -0
- package/import/utils/prepareDataDirMap.js +31 -0
- package/import/utils/prepareDataDirMap.js.map +1 -0
- package/import/utils/updateFilesInData.d.ts +8 -0
- package/import/utils/updateFilesInData.js +51 -0
- package/import/utils/updateFilesInData.js.map +1 -0
- package/import/utils/uploadAssets.d.ts +10 -0
- package/import/utils/uploadAssets.js +92 -0
- package/import/utils/uploadAssets.js.map +1 -0
- package/import/utils/uploadFilesFromS3.d.ts +3 -0
- package/import/utils/uploadFilesFromS3.js +21 -0
- package/import/utils/uploadFilesFromS3.js.map +1 -0
- package/mockSecurity.d.ts +1 -1
- package/mockSecurity.js +2 -3
- package/mockSecurity.js.map +1 -1
- package/package.json +36 -52
- package/tasks/common/ChildTasksCleanup.d.ts +12 -0
- package/tasks/common/ChildTasksCleanup.js +64 -0
- package/tasks/common/ChildTasksCleanup.js.map +1 -0
- package/tasks/index.d.ts +1 -0
- package/tasks/index.js +13 -0
- package/tasks/index.js.map +1 -0
- package/tasks/pages/exportPagesCleanupTask.d.ts +3 -0
- package/tasks/pages/exportPagesCleanupTask.js +36 -0
- package/tasks/pages/exportPagesCleanupTask.js.map +1 -0
- package/tasks/pages/exportPagesControllerTask.d.ts +3 -0
- package/tasks/pages/exportPagesControllerTask.js +83 -0
- package/tasks/pages/exportPagesControllerTask.js.map +1 -0
- package/tasks/pages/exportPagesZipPagesTask.d.ts +3 -0
- package/tasks/pages/exportPagesZipPagesTask.js +39 -0
- package/tasks/pages/exportPagesZipPagesTask.js.map +1 -0
- package/tasks/pages/importPagesControllerTask.d.ts +3 -0
- package/tasks/pages/importPagesControllerTask.js +39 -0
- package/tasks/pages/importPagesControllerTask.js.map +1 -0
- package/tasks/pages/importPagesProcessPageTask.d.ts +3 -0
- package/tasks/pages/importPagesProcessPageTask.js +39 -0
- package/tasks/pages/importPagesProcessPageTask.js.map +1 -0
- package/tasks/pages/index.d.ts +1 -0
- package/tasks/pages/index.js +17 -0
- package/tasks/pages/index.js.map +1 -0
- package/types.d.ts +23 -2
- package/types.js +60 -13
- package/types.js.map +1 -1
- package/utils/ZipFiles.d.ts +11 -0
- package/utils/ZipFiles.js +124 -0
- package/utils/ZipFiles.js.map +1 -0
- package/export/combine/pagesHandler.d.ts +0 -6
- package/export/combine/pagesHandler.js.map +0 -1
- package/export/process/pagesHandler.d.ts +0 -6
- package/export/process/pagesHandler.js.map +0 -1
- package/import/process/blocksHandler.js.map +0 -1
- package/import/process/pagesHandler.d.ts +0 -3
- package/import/process/pagesHandler.js.map +0 -1
- package/import/process/templatesHandler.js.map +0 -1
- package/import/utils.d.ts +0 -56
- package/import/utils.js +0 -696
- package/import/utils.js.map +0 -1
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
limit: 10000
|
|
29
|
+
});
|
|
30
|
+
imageFilesData.push(...filesData);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Extract the page data in a json file and upload it to S3
|
|
34
|
+
const pageData = {
|
|
35
|
+
page: {
|
|
36
|
+
content: page.content,
|
|
37
|
+
title: page.title,
|
|
38
|
+
path: page.path,
|
|
39
|
+
version: page.version,
|
|
40
|
+
status: page.status,
|
|
41
|
+
settings: page.settings
|
|
42
|
+
},
|
|
43
|
+
files: imageFilesData
|
|
44
|
+
};
|
|
45
|
+
const pageDataBuffer = Buffer.from(JSON.stringify(pageData));
|
|
46
|
+
const zipper = new _zipper.default({
|
|
47
|
+
exportInfo: {
|
|
48
|
+
files: imageFilesData,
|
|
49
|
+
name: page.title,
|
|
50
|
+
dataBuffer: pageDataBuffer
|
|
51
|
+
},
|
|
52
|
+
archiveFileKey: exportPagesDataKey
|
|
53
|
+
});
|
|
54
|
+
return zipper.process();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.PageExporter = PageExporter;
|
|
58
|
+
|
|
59
|
+
//# 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","limit","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 type { Page } from \"@webiny/api-page-builder/types\";\nimport type { File, FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport Zipper from \"~/export/zipper\";\nimport { extractFilesFromData } from \"~/export/utils\";\n\nexport interface ExportedPageData {\n /**\n * TODO: is it really ok not to export whole page object?\n * What if we add some new properties in the future?\n *\n * Type of the exported page data is now created by removing unnecessary properties from the Page type.\n * This way TS will break if we add new property and forget to handle it in the export/import process.\n */\n page: Omit<\n Page,\n | \"id\"\n | \"pid\"\n | \"tenant\"\n | \"locale\"\n | \"editor\"\n | \"category\"\n | \"createdFrom\"\n | \"createdBy\"\n | \"createdOn\"\n | \"savedOn\"\n | \"publishedOn\"\n | \"locked\"\n | \"ownedBy\"\n | \"webinyVersion\"\n >;\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: File[] = [];\n if (fileIds.length > 0) {\n const [filesData] = await this.fileManager.listFiles({\n where: {\n id_in: fileIds\n },\n limit: 10000\n });\n imageFilesData.push(...filesData);\n }\n\n // Extract the page data in a json file and upload it to S3\n const pageData: ExportedPageData = {\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,IA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B,KAAK,EAAEY;IACX,CAAC;IACD,MAAMc,cAAc,GAAGC,MAAM,CAACC,IAAI,CAACC,IAAI,CAACC,SAAS,CAACV,QAAQ,CAAC,CAAC;IAE5D,MAAMW,MAAM,GAAG,IAAIC,eAAM,CAAC;MACtBC,UAAU,EAAE;QACRjC,KAAK,EAAEY,cAAc;QACrBsB,IAAI,EAAEpC,IAAI,CAACuB,KAAK;QAChBc,UAAU,EAAET;MAChB,CAAC;MACDU,cAAc,EAAErC;IACpB,CAAC,CAAC;IAEF,OAAOgC,MAAM,CAACM,OAAO,CAAC,CAAC;EAC3B;AACJ;AAACC,OAAA,CAAA5C,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PageTemplate } from "@webiny/api-page-builder/types";
|
|
2
|
+
import type { File, FileManagerContext } from "@webiny/api-file-manager/types";
|
|
3
|
+
export interface ExportedTemplateData {
|
|
4
|
+
template: Pick<PageTemplate, "title" | "slug" | "tags" | "description" | "content" | "layout" | "pageCategory" | "dataBindings" | "dataSources">;
|
|
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,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.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
|
+
dataBindings: template.dataBindings,
|
|
40
|
+
dataSources: template.dataSources
|
|
41
|
+
},
|
|
42
|
+
files: imageFilesData
|
|
43
|
+
};
|
|
44
|
+
const templateDataBuffer = Buffer.from(JSON.stringify(templateData));
|
|
45
|
+
const zipper = new _zipper.default({
|
|
46
|
+
exportInfo: {
|
|
47
|
+
files: imageFilesData,
|
|
48
|
+
name: template.title,
|
|
49
|
+
dataBuffer: templateDataBuffer
|
|
50
|
+
},
|
|
51
|
+
archiveFileKey: exportTemplatesDataKey
|
|
52
|
+
});
|
|
53
|
+
return zipper.process();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.PageTemplateExporter = PageTemplateExporter;
|
|
57
|
+
|
|
58
|
+
//# 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","dataBindings","dataSources","templateDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","name","dataBuffer","archiveFileKey","process","exports"],"sources":["PageTemplateExporter.ts"],"sourcesContent":["import type { PageTemplate } from \"@webiny/api-page-builder/types\";\nimport type { 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\"\n | \"slug\"\n | \"tags\"\n | \"description\"\n | \"content\"\n | \"layout\"\n | \"pageCategory\"\n | \"dataBindings\"\n | \"dataSources\"\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 dataBindings: template.dataBindings,\n dataSources: template.dataSources\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}\n"],"mappings":";;;;;;;AAEA,IAAA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AAS,CAACb,YAAY,CAAC,CAAC;IAEpE,MAAMc,MAAM,GAAG,IAAIC,eAAM,CAAC;MACtBC,UAAU,EAAE;QACR9B,KAAK,EAAEO,cAAc;QACrBwB,IAAI,EAAEjC,QAAQ,CAACiB,KAAK;QACpBiB,UAAU,EAAET;MAChB,CAAC;MACDU,cAAc,EAAElC;IACpB,CAAC,CAAC;IAEF,OAAO6B,MAAM,CAACM,OAAO,CAAC,CAAC;EAC3B;AACJ;AAACC,OAAA,CAAAzC,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PbImportExportContext } from "../../types";
|
|
2
|
+
import type { Configuration, Payload, Response } from "./";
|
|
3
|
+
/**
|
|
4
|
+
* Handles the export forms process workflow.
|
|
5
|
+
*/
|
|
6
|
+
export declare const formsHandler: (configuration: Configuration, payload: Payload, context: PbImportExportContext) => Promise<Response>;
|
|
@@ -3,54 +3,45 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.formsHandler = void 0;
|
|
8
7
|
var _types = require("../../types");
|
|
9
|
-
|
|
10
8
|
var _client = require("../../client");
|
|
11
|
-
|
|
12
9
|
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
13
|
-
|
|
14
|
-
var _utils = require("../utils");
|
|
15
|
-
|
|
16
10
|
var _mockSecurity = require("../../mockSecurity");
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
|
|
11
|
+
var _utils = require("@webiny/utils");
|
|
12
|
+
var _FormExporter = require("./exporters/FormExporter");
|
|
20
13
|
/**
|
|
21
|
-
* Handles the export
|
|
14
|
+
* Handles the export forms process workflow.
|
|
22
15
|
*/
|
|
23
|
-
const
|
|
16
|
+
const formsHandler = async (configuration, payload, context) => {
|
|
24
17
|
const log = console.log;
|
|
25
18
|
let subTask;
|
|
26
19
|
let noPendingTask = true;
|
|
27
20
|
let prevStatusOfSubTask = _types.ImportExportTaskStatus.PENDING;
|
|
28
|
-
log("RUNNING Export
|
|
21
|
+
log("RUNNING Export Forms Process Handler");
|
|
29
22
|
const {
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
formBuilder,
|
|
24
|
+
pageBuilder
|
|
32
25
|
} = context;
|
|
33
26
|
const {
|
|
34
27
|
taskId,
|
|
35
28
|
subTaskIndex,
|
|
36
29
|
type,
|
|
37
30
|
identity
|
|
38
|
-
} = payload;
|
|
31
|
+
} = payload;
|
|
32
|
+
// Disable authorization; this is necessary because we call Form Builder CRUD methods which include authorization checks
|
|
39
33
|
// and this Lambda is invoked internally, without credentials.
|
|
40
|
-
|
|
41
34
|
(0, _mockSecurity.mockSecurity)(identity, context);
|
|
42
|
-
|
|
43
35
|
try {
|
|
44
36
|
/*
|
|
45
37
|
* Note: We're not going to DB for finding the next sub-task to process,
|
|
46
38
|
* because the data might be out of sync due to GSI eventual consistency.
|
|
47
39
|
*/
|
|
48
|
-
subTask = await pageBuilder.importExportTask.getSubTask(taskId, (0,
|
|
40
|
+
subTask = await pageBuilder.importExportTask.getSubTask(taskId, (0, _utils.zeroPad)(subTaskIndex, 5));
|
|
49
41
|
/**
|
|
50
42
|
* Base condition!!
|
|
51
43
|
* Bail out early, if task not found or task's status is not "pending".
|
|
52
44
|
*/
|
|
53
|
-
|
|
54
45
|
if (!subTask || subTask.status !== _types.ImportExportTaskStatus.PENDING) {
|
|
55
46
|
noPendingTask = true;
|
|
56
47
|
return {
|
|
@@ -60,73 +51,68 @@ const pagesHandler = async (configuration, payload, context) => {
|
|
|
60
51
|
} else {
|
|
61
52
|
noPendingTask = false;
|
|
62
53
|
}
|
|
63
|
-
|
|
64
54
|
log(`Fetched sub task => ${subTask.id}`);
|
|
65
55
|
const {
|
|
66
56
|
input
|
|
67
57
|
} = subTask;
|
|
68
58
|
const {
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
formId,
|
|
60
|
+
exportFormsDataKey,
|
|
71
61
|
revisionType
|
|
72
62
|
} = input;
|
|
63
|
+
|
|
73
64
|
/**
|
|
74
|
-
* At the moment, we only export a single revision of the
|
|
65
|
+
* At the moment, we only export a single revision of the form.
|
|
75
66
|
* It could be "published" or "latest" depending upon user input.
|
|
76
67
|
*
|
|
77
68
|
* Note: In case of no "published" revision available, we use the latest revision.
|
|
78
69
|
*/
|
|
79
|
-
|
|
80
|
-
let page;
|
|
81
|
-
|
|
70
|
+
let form;
|
|
82
71
|
try {
|
|
83
72
|
if (revisionType === _types.ExportRevisionType.PUBLISHED) {
|
|
84
|
-
// Get "published"
|
|
85
|
-
|
|
86
|
-
id: pageId
|
|
87
|
-
});
|
|
73
|
+
// Get "published" form.
|
|
74
|
+
form = await formBuilder.getLatestPublishedFormRevision(formId);
|
|
88
75
|
} else {
|
|
89
|
-
// Get "latest"
|
|
90
|
-
|
|
76
|
+
// Get "latest" form.
|
|
77
|
+
form = await formBuilder.getForm(formId);
|
|
91
78
|
}
|
|
92
79
|
} catch (e) {
|
|
93
|
-
// If we're looking for "published"
|
|
80
|
+
// If we're looking for "published" form and doesn't found it, get latest form.
|
|
94
81
|
if (revisionType === _types.ExportRevisionType.PUBLISHED && e instanceof _handlerGraphql.NotFoundError) {
|
|
95
|
-
|
|
82
|
+
form = await formBuilder.getForm(formId);
|
|
96
83
|
} else {
|
|
97
84
|
throw e;
|
|
98
85
|
}
|
|
99
86
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
throw new _handlerGraphql.NotFoundError(`Unable to load page "${pageId}"`);
|
|
87
|
+
if (!form) {
|
|
88
|
+
log(`Unable to load form "${formId}"`);
|
|
89
|
+
throw new _handlerGraphql.NotFoundError(`Unable to load form "${formId}"`);
|
|
104
90
|
}
|
|
91
|
+
log(`Processing form key "${formId}" | version ${form.version} | ${form.status}`);
|
|
105
92
|
|
|
106
|
-
|
|
107
|
-
|
|
93
|
+
// Mark task status as PROCESSING
|
|
108
94
|
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
|
109
95
|
status: _types.ImportExportTaskStatus.PROCESSING
|
|
110
|
-
});
|
|
111
|
-
|
|
96
|
+
});
|
|
97
|
+
// Update stats in main task
|
|
112
98
|
await pageBuilder.importExportTask.updateStats(taskId, {
|
|
113
99
|
prevStatus: prevStatusOfSubTask,
|
|
114
100
|
nextStatus: _types.ImportExportTaskStatus.PROCESSING
|
|
115
101
|
});
|
|
116
102
|
prevStatusOfSubTask = subTask.status;
|
|
117
|
-
log(`Extracting
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
log(`Finish uploading zip...`);
|
|
121
|
-
|
|
103
|
+
log(`Extracting form data and uploading to storage...`);
|
|
104
|
+
const formExporter = new _FormExporter.FormExporter();
|
|
105
|
+
const formDataZip = await formExporter.execute(form, exportFormsDataKey);
|
|
106
|
+
log(`Finish uploading zip...`);
|
|
107
|
+
// Update task record in DB
|
|
122
108
|
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
|
123
109
|
status: _types.ImportExportTaskStatus.COMPLETED,
|
|
124
110
|
data: {
|
|
125
|
-
message: `Finish uploading data for
|
|
126
|
-
key:
|
|
111
|
+
message: `Finish uploading data for form "${form.id}" v${form.version} (${form.status}).`,
|
|
112
|
+
key: formDataZip.Key
|
|
127
113
|
}
|
|
128
|
-
});
|
|
129
|
-
|
|
114
|
+
});
|
|
115
|
+
// Update stats in main task
|
|
130
116
|
await pageBuilder.importExportTask.updateStats(taskId, {
|
|
131
117
|
prevStatus: prevStatusOfSubTask,
|
|
132
118
|
nextStatus: _types.ImportExportTaskStatus.COMPLETED
|
|
@@ -134,7 +120,6 @@ const pagesHandler = async (configuration, payload, context) => {
|
|
|
134
120
|
prevStatusOfSubTask = subTask.status;
|
|
135
121
|
} catch (e) {
|
|
136
122
|
log("[EXPORT_PAGES_PROCESS] Error => ", e);
|
|
137
|
-
|
|
138
123
|
if (subTask && subTask.id) {
|
|
139
124
|
/**
|
|
140
125
|
* In case of error, we'll update the task status to "failed",
|
|
@@ -148,15 +133,15 @@ const pagesHandler = async (configuration, payload, context) => {
|
|
|
148
133
|
stack: e.stack,
|
|
149
134
|
code: "EXPORT_FAILED"
|
|
150
135
|
}
|
|
151
|
-
});
|
|
136
|
+
});
|
|
152
137
|
|
|
138
|
+
// Update stats in main task
|
|
153
139
|
await pageBuilder.importExportTask.updateStats(taskId, {
|
|
154
140
|
prevStatus: prevStatusOfSubTask,
|
|
155
141
|
nextStatus: _types.ImportExportTaskStatus.FAILED
|
|
156
142
|
});
|
|
157
143
|
prevStatusOfSubTask = subTask.status;
|
|
158
144
|
}
|
|
159
|
-
|
|
160
145
|
return {
|
|
161
146
|
data: null,
|
|
162
147
|
error: {
|
|
@@ -166,8 +151,8 @@ const pagesHandler = async (configuration, payload, context) => {
|
|
|
166
151
|
} finally {
|
|
167
152
|
// Base condition!
|
|
168
153
|
if (noPendingTask) {
|
|
169
|
-
log(`No pending sub-task for task ${taskId}`);
|
|
170
|
-
|
|
154
|
+
log(`No pending sub-task for task ${taskId}`);
|
|
155
|
+
// Combine individual form zip files.
|
|
171
156
|
await (0, _client.invokeHandlerClient)({
|
|
172
157
|
context,
|
|
173
158
|
name: configuration.handlers.combine,
|
|
@@ -176,11 +161,11 @@ const pagesHandler = async (configuration, payload, context) => {
|
|
|
176
161
|
type,
|
|
177
162
|
identity: context.security.getIdentity()
|
|
178
163
|
},
|
|
179
|
-
description: "Export
|
|
164
|
+
description: "Export forms - combine"
|
|
180
165
|
});
|
|
181
166
|
} else {
|
|
182
|
-
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`);
|
|
183
|
-
|
|
167
|
+
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`);
|
|
168
|
+
// We want to continue with Self invocation no matter if current form error out.
|
|
184
169
|
await (0, _client.invokeHandlerClient)({
|
|
185
170
|
context,
|
|
186
171
|
name: configuration.handlers.process,
|
|
@@ -190,15 +175,15 @@ const pagesHandler = async (configuration, payload, context) => {
|
|
|
190
175
|
subTaskIndex: subTaskIndex + 1,
|
|
191
176
|
identity: context.security.getIdentity()
|
|
192
177
|
},
|
|
193
|
-
description: "Export
|
|
178
|
+
description: "Export forms - process - subtask"
|
|
194
179
|
});
|
|
195
180
|
}
|
|
196
181
|
}
|
|
197
|
-
|
|
198
182
|
return {
|
|
199
183
|
data: "",
|
|
200
184
|
error: null
|
|
201
185
|
};
|
|
202
186
|
};
|
|
187
|
+
exports.formsHandler = formsHandler;
|
|
203
188
|
|
|
204
|
-
|
|
189
|
+
//# sourceMappingURL=formsHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_types","require","_client","_handlerGraphql","_mockSecurity","_utils","_FormExporter","formsHandler","configuration","payload","context","log","console","subTask","noPendingTask","prevStatusOfSubTask","ImportExportTaskStatus","PENDING","formBuilder","pageBuilder","taskId","subTaskIndex","type","identity","mockSecurity","importExportTask","getSubTask","zeroPad","status","data","error","id","input","formId","exportFormsDataKey","revisionType","form","ExportRevisionType","PUBLISHED","getLatestPublishedFormRevision","getForm","e","NotFoundError","version","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","formExporter","FormExporter","formDataZip","execute","COMPLETED","message","key","Key","FAILED","name","stack","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process","exports"],"sources":["formsHandler.ts"],"sourcesContent":["import type { PbImportExportContext } from \"~/types\";\nimport { ExportRevisionType, ImportExportTaskStatus } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport type { Payload as ExtractPayload } from \"../combine\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport type { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { zeroPad } from \"@webiny/utils\";\nimport type { Configuration, Payload, Response } from \"~/export/process\";\nimport { FormExporter } from \"./exporters/FormExporter\";\n\n/**\n * Handles the export forms process workflow.\n */\nexport const formsHandler = async (\n configuration: Configuration,\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n let subTask;\n let noPendingTask = true;\n let prevStatusOfSubTask = ImportExportTaskStatus.PENDING;\n\n log(\"RUNNING Export Forms Process Handler\");\n const { formBuilder, pageBuilder } = context;\n const { taskId, subTaskIndex, type, identity } = payload;\n // Disable authorization; this is necessary because we call Form Builder CRUD methods which include authorization checks\n // and this Lambda is invoked internally, without credentials.\n mockSecurity(identity as SecurityIdentity, context);\n\n try {\n /*\n * Note: We're not going to DB for finding the next sub-task to process,\n * because the data might be out of sync due to GSI eventual consistency.\n */\n subTask = await pageBuilder.importExportTask.getSubTask(taskId, zeroPad(subTaskIndex, 5));\n /**\n * Base condition!!\n * Bail out early, if task not found or task's status is not \"pending\".\n */\n if (!subTask || subTask.status !== ImportExportTaskStatus.PENDING) {\n noPendingTask = true;\n return {\n data: \"\",\n error: null\n };\n } else {\n noPendingTask = false;\n }\n\n log(`Fetched sub task => ${subTask.id}`);\n\n const { input } = subTask;\n const { formId, exportFormsDataKey, revisionType } = input;\n\n /**\n * At the moment, we only export a single revision of the form.\n * It could be \"published\" or \"latest\" depending upon user input.\n *\n * Note: In case of no \"published\" revision available, we use the latest revision.\n */\n let form;\n try {\n if (revisionType === ExportRevisionType.PUBLISHED) {\n // Get \"published\" form.\n form = await formBuilder.getLatestPublishedFormRevision(formId);\n } else {\n // Get \"latest\" form.\n form = await formBuilder.getForm(formId);\n }\n } catch (e) {\n // If we're looking for \"published\" form and doesn't found it, get latest form.\n if (revisionType === ExportRevisionType.PUBLISHED && e instanceof NotFoundError) {\n form = await formBuilder.getForm(formId);\n } else {\n throw e;\n }\n }\n\n if (!form) {\n log(`Unable to load form \"${formId}\"`);\n throw new NotFoundError(`Unable to load form \"${formId}\"`);\n }\n\n log(`Processing form key \"${formId}\" | version ${form.version} | ${form.status}`);\n\n // Mark task status as PROCESSING\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.PROCESSING\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.PROCESSING\n });\n prevStatusOfSubTask = subTask.status;\n\n log(`Extracting form data and uploading to storage...`);\n const formExporter = new FormExporter();\n const formDataZip = await formExporter.execute(form, exportFormsDataKey);\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for form \"${form.id}\" v${form.version} (${form.status}).`,\n key: formDataZip.Key\n }\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.COMPLETED\n });\n prevStatusOfSubTask = subTask.status;\n } catch (e) {\n log(\"[EXPORT_PAGES_PROCESS] Error => \", e);\n\n if (subTask && subTask.id) {\n /**\n * In case of error, we'll update the task status to \"failed\",\n * so that, client can show notify the user appropriately.\n */\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n stack: e.stack,\n code: \"EXPORT_FAILED\"\n }\n });\n\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.FAILED\n });\n prevStatusOfSubTask = subTask.status;\n }\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n } finally {\n // Base condition!\n if (noPendingTask) {\n log(`No pending sub-task for task ${taskId}`);\n // Combine individual form zip files.\n await invokeHandlerClient<ExtractPayload>({\n context,\n name: configuration.handlers.combine,\n payload: {\n taskId,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export forms - combine\"\n });\n } else {\n console.log(`Invoking PROCESS for task \"${subTaskIndex + 1}\"`);\n // We want to continue with Self invocation no matter if current form error out.\n await invokeHandlerClient<Payload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId,\n type,\n subTaskIndex: subTaskIndex + 1,\n identity: context.security.getIdentity()\n },\n description: \"Export forms - process - subtask\"\n });\n }\n }\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,aAAA,GAAAL,OAAA;AAEA;AACA;AACA;AACO,MAAMM,YAAY,GAAG,MAAAA,CACxBC,aAA4B,EAC5BC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EACvB,IAAIE,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,MAAMM,WAAW,CAACM,gBAAgB,CAACC,UAAU,CAACN,MAAM,EAAE,IAAAO,cAAO,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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CAAC;AACL,CAAC;AAACsC,OAAA,CAAA7D,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PbImportExportContext } from "../../types";
|
|
2
|
-
import { SecurityIdentity } from "@webiny/api-security/types";
|
|
1
|
+
import type { PbImportExportContext } from "../../types";
|
|
2
|
+
import type { SecurityIdentity } from "@webiny/api-security/types";
|
|
3
3
|
export interface Configuration {
|
|
4
4
|
handlers: {
|
|
5
5
|
process: string;
|
package/export/process/index.js
CHANGED
|
@@ -4,37 +4,38 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _handlerAws = require("@webiny/handler-aws");
|
|
9
|
-
|
|
10
8
|
var _blocksHandler = require("./blocksHandler");
|
|
11
|
-
|
|
12
|
-
var _pagesHandler = require("./pagesHandler");
|
|
13
|
-
|
|
9
|
+
var _formsHandler = require("./formsHandler");
|
|
14
10
|
var _templatesHandler = require("./templatesHandler");
|
|
15
|
-
|
|
16
11
|
var _default = configuration => {
|
|
17
12
|
return (0, _handlerAws.createRawEventHandler)(async ({
|
|
18
13
|
payload,
|
|
19
14
|
context
|
|
20
15
|
}) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
return context.security.withoutAuthorization(() => {
|
|
17
|
+
switch (payload.type) {
|
|
18
|
+
case "block":
|
|
19
|
+
{
|
|
20
|
+
return (0, _blocksHandler.blocksHandler)(configuration, payload, context);
|
|
21
|
+
}
|
|
22
|
+
case "form":
|
|
23
|
+
{
|
|
24
|
+
return (0, _formsHandler.formsHandler)(configuration, payload, context);
|
|
25
|
+
}
|
|
26
|
+
case "template":
|
|
27
|
+
{
|
|
28
|
+
return (0, _templatesHandler.templatesHandler)(configuration, payload, context);
|
|
29
|
+
}
|
|
30
|
+
default:
|
|
31
|
+
{
|
|
32
|
+
console.log("Export PB process", JSON.stringify(payload));
|
|
33
|
+
throw new Error("Invalid type provided: pb process.");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
|
+
exports.default = _default;
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["configuration","createRawEventHandler","payload","context","type","blocksHandler","templatesHandler","
|
|
1
|
+
{"version":3,"names":["_handlerAws","require","_blocksHandler","_formsHandler","_templatesHandler","_default","configuration","createRawEventHandler","payload","context","security","withoutAuthorization","type","blocksHandler","formsHandler","templatesHandler","console","log","JSON","stringify","Error","exports","default"],"sources":["index.ts"],"sourcesContent":["import type { PbImportExportContext } from \"~/types\";\nimport type { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { blocksHandler } from \"~/export/process/blocksHandler\";\nimport { formsHandler } from \"~/export/process/formsHandler\";\nimport { templatesHandler } from \"~/export/process/templatesHandler\";\n\nexport interface Configuration {\n handlers: {\n process: string;\n combine: string;\n };\n}\n\nexport interface Payload {\n taskId: string;\n subTaskIndex: number;\n type: string;\n identity?: SecurityIdentity;\n}\n\nexport interface Response {\n data: string | null;\n error: Partial<Error> | null;\n}\n\nexport default (configuration: Configuration) => {\n return createRawEventHandler<Payload, PbImportExportContext, Response>(\n async ({ payload, context }) => {\n return context.security.withoutAuthorization(() => {\n switch (payload.type) {\n case \"block\": {\n return blocksHandler(configuration, payload, context);\n }\n case \"form\": {\n return formsHandler(configuration, payload, context);\n }\n case \"template\": {\n return templatesHandler(configuration, payload, context);\n }\n default: {\n console.log(\"Export PB process\", JSON.stringify(payload));\n throw new Error(\"Invalid type provided: pb process.\");\n }\n }\n });\n }\n );\n};\n"],"mappings":";;;;;;AAEA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AAAqE,IAAAI,QAAA,GAqBrDC,aAA4B,IAAK;EAC7C,OAAO,IAAAC,iCAAqB,EACxB,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IAC5B,OAAOA,OAAO,CAACC,QAAQ,CAACC,oBAAoB,CAAC,MAAM;MAC/C,QAAQH,OAAO,CAACI,IAAI;QAChB,KAAK,OAAO;UAAE;YACV,OAAO,IAAAC,4BAAa,EAACP,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;UACzD;QACA,KAAK,MAAM;UAAE;YACT,OAAO,IAAAK,0BAAY,EAACR,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;UACxD;QACA,KAAK,UAAU;UAAE;YACb,OAAO,IAAAM,kCAAgB,EAACT,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;UAC5D;QACA;UAAS;YACLO,OAAO,CAACC,GAAG,CAAC,mBAAmB,EAAEC,IAAI,CAACC,SAAS,CAACX,OAAO,CAAC,CAAC;YACzD,MAAM,IAAIY,KAAK,CAAC,oCAAoC,CAAC;UACzD;MACJ;IACJ,CAAC,CAAC;EACN,CACJ,CAAC;AACL,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAjB,QAAA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PbImportExportContext } from "../../types";
|
|
2
|
-
import { Configuration, Payload, Response } from "
|
|
1
|
+
import type { PbImportExportContext } from "../../types";
|
|
2
|
+
import type { Configuration, Payload, Response } from "./";
|
|
3
3
|
/**
|
|
4
4
|
* Handles the export templates process workflow.
|
|
5
5
|
*/
|