@webiny/api-page-builder-import-export 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.aa00eecd97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +2 -2
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.d.ts +6 -0
- package/export/combine/blocksHandler.js +99 -0
- package/export/combine/blocksHandler.js.map +1 -0
- package/export/combine/formsHandler.d.ts +6 -0
- package/export/combine/formsHandler.js +99 -0
- package/export/combine/formsHandler.js.map +1 -0
- package/{exportPages → export}/combine/index.d.ts +3 -2
- package/export/combine/index.js +40 -0
- package/export/combine/index.js.map +1 -0
- package/export/combine/pagesHandler.d.ts +6 -0
- package/export/combine/pagesHandler.js +99 -0
- package/export/combine/pagesHandler.js.map +1 -0
- package/export/combine/templatesHandler.d.ts +6 -0
- package/export/combine/templatesHandler.js +99 -0
- package/export/combine/templatesHandler.js.map +1 -0
- package/export/process/blocksHandler.d.ts +6 -0
- package/export/process/blocksHandler.js +162 -0
- package/export/process/blocksHandler.js.map +1 -0
- package/export/process/formsHandler.d.ts +6 -0
- package/export/process/formsHandler.js +187 -0
- package/export/process/formsHandler.js.map +1 -0
- package/{exportPages → export}/process/index.d.ts +4 -6
- package/export/process/index.js +37 -0
- package/export/process/index.js.map +1 -0
- package/export/process/pagesHandler.d.ts +6 -0
- package/export/process/pagesHandler.js +189 -0
- package/export/process/pagesHandler.js.map +1 -0
- package/export/process/templatesHandler.d.ts +6 -0
- package/export/process/templatesHandler.js +166 -0
- package/export/process/templatesHandler.js.map +1 -0
- package/{exportPages → export}/s3Stream.d.ts +5 -2
- package/export/s3Stream.js.map +1 -0
- package/export/utils.d.ts +29 -0
- package/export/utils.js +188 -0
- package/export/utils.js.map +1 -0
- package/{exportPages → export}/zipper.d.ts +6 -5
- package/{exportPages → export}/zipper.js +9 -8
- package/export/zipper.js.map +1 -0
- package/graphql/crud/blocks.crud.d.ts +4 -0
- package/graphql/crud/blocks.crud.js +136 -0
- package/graphql/crud/blocks.crud.js.map +1 -0
- package/graphql/crud/forms.crud.d.ts +4 -0
- package/graphql/crud/forms.crud.js +129 -0
- package/graphql/crud/forms.crud.js.map +1 -0
- package/graphql/crud/importExportTasks.crud.d.ts +5 -0
- package/graphql/crud/{pageImportExportTasks.crud.js → importExportTasks.crud.js} +50 -55
- package/graphql/crud/importExportTasks.crud.js.map +1 -0
- package/graphql/crud/pages.crud.d.ts +2 -2
- package/graphql/crud/pages.crud.js +18 -14
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.d.ts +4 -0
- package/graphql/crud/templates.crud.js +124 -0
- package/graphql/crud/templates.crud.js.map +1 -0
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js +5 -2
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.d.ts +4 -0
- package/graphql/graphql/blocks.gql.js +52 -0
- package/graphql/graphql/blocks.gql.js.map +1 -0
- package/graphql/graphql/forms.gql.d.ts +4 -0
- package/graphql/graphql/forms.gql.js +60 -0
- package/graphql/graphql/forms.gql.js.map +1 -0
- package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
- package/graphql/graphql/{pageImportExportTasks.gql.js → importExportTasks.gql.js} +17 -17
- package/graphql/graphql/importExportTasks.gql.js.map +1 -0
- package/graphql/graphql/pages.gql.d.ts +2 -2
- package/graphql/graphql/pages.gql.js +3 -9
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.d.ts +4 -0
- package/graphql/graphql/templates.gql.js +52 -0
- package/graphql/graphql/templates.gql.js.map +1 -0
- package/graphql/graphql.js +5 -2
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +83 -23
- package/graphql/types.js.map +1 -1
- package/import/constants.d.ts +3 -0
- package/import/constants.js +14 -0
- package/import/constants.js.map +1 -0
- package/import/create/blocksHandler.d.ts +3 -0
- package/import/create/blocksHandler.js +101 -0
- package/import/create/blocksHandler.js.map +1 -0
- package/import/create/formsHandler.d.ts +3 -0
- package/import/create/formsHandler.js +103 -0
- package/import/create/formsHandler.js.map +1 -0
- package/{importPages → import}/create/index.d.ts +7 -5
- package/import/create/index.js +40 -0
- package/import/create/index.js.map +1 -0
- package/import/create/pagesHandler.d.ts +3 -0
- package/import/create/pagesHandler.js +103 -0
- package/import/create/pagesHandler.js.map +1 -0
- package/import/create/templatesHandler.d.ts +3 -0
- package/import/create/templatesHandler.js +99 -0
- package/import/create/templatesHandler.js.map +1 -0
- package/import/process/blocks/blocksHandler.d.ts +3 -0
- package/import/process/blocks/blocksHandler.js +169 -0
- package/import/process/blocks/blocksHandler.js.map +1 -0
- package/import/process/blocks/importBlock.d.ts +11 -0
- package/import/process/blocks/importBlock.js +92 -0
- package/import/process/blocks/importBlock.js.map +1 -0
- package/import/process/forms/formsHandler.d.ts +3 -0
- package/import/process/forms/formsHandler.js +176 -0
- package/import/process/forms/formsHandler.js.map +1 -0
- package/import/process/forms/importForm.d.ts +9 -0
- package/import/process/forms/importForm.js +43 -0
- package/import/process/forms/importForm.js.map +1 -0
- package/{importPages → import}/process/index.d.ts +5 -3
- package/import/process/index.js +37 -0
- package/import/process/index.js.map +1 -0
- package/import/process/pages/importPage.d.ts +11 -0
- package/import/process/pages/importPage.js +92 -0
- package/import/process/pages/importPage.js.map +1 -0
- package/import/process/pages/pagesHandler.d.ts +3 -0
- package/import/process/pages/pagesHandler.js +183 -0
- package/import/process/pages/pagesHandler.js.map +1 -0
- package/import/process/templates/importTemplate.d.ts +11 -0
- package/import/process/templates/importTemplate.js +66 -0
- package/import/process/templates/importTemplate.js.map +1 -0
- package/import/process/templates/templatesHandler.d.ts +3 -0
- package/import/process/templates/templatesHandler.js +170 -0
- package/import/process/templates/templatesHandler.js.map +1 -0
- package/import/utils/deleteS3Folder.d.ts +1 -0
- package/import/utils/deleteS3Folder.js +19 -0
- package/import/utils/deleteS3Folder.js.map +1 -0
- package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
- package/import/utils/extractAndUploadZipFileContents.js +122 -0
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
- package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
- package/import/utils/extractZipAndUploadToS3.js +98 -0
- package/import/utils/extractZipAndUploadToS3.js.map +1 -0
- package/import/utils/getFileNameWithoutExt.d.ts +1 -0
- package/import/utils/getFileNameWithoutExt.js +11 -0
- package/import/utils/getFileNameWithoutExt.js.map +1 -0
- package/import/utils/index.d.ts +9 -0
- package/import/utils/index.js +104 -0
- package/import/utils/index.js.map +1 -0
- package/import/utils/initialStats.d.ts +7 -0
- package/import/utils/initialStats.js +16 -0
- package/import/utils/initialStats.js.map +1 -0
- package/import/utils/prepareDataDirMap.d.ts +6 -0
- package/import/utils/prepareDataDirMap.js +29 -0
- package/import/utils/prepareDataDirMap.js.map +1 -0
- package/import/utils/updateFilesInData.d.ts +8 -0
- package/import/utils/updateFilesInData.js +48 -0
- package/import/utils/updateFilesInData.js.map +1 -0
- package/import/utils/uploadAssets.d.ts +10 -0
- package/import/utils/uploadAssets.js +49 -0
- package/import/utils/uploadAssets.js.map +1 -0
- package/import/utils/uploadFilesFromS3.d.ts +3 -0
- package/import/utils/uploadFilesFromS3.js +19 -0
- package/import/utils/uploadFilesFromS3.js.map +1 -0
- package/package.json +37 -37
- package/types.d.ts +83 -65
- package/types.js +17 -17
- package/types.js.map +1 -1
- package/exportPages/combine/index.js +0 -106
- package/exportPages/combine/index.js.map +0 -1
- package/exportPages/process/index.js +0 -192
- package/exportPages/process/index.js.map +0 -1
- package/exportPages/s3Stream.js.map +0 -1
- package/exportPages/utils.d.ts +0 -13
- package/exportPages/utils.js +0 -100
- package/exportPages/utils.js.map +0 -1
- package/exportPages/zipper.js.map +0 -1
- package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
- package/graphql/crud/pageImportExportTasks.crud.js.map +0 -1
- package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
- package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
- package/importPages/create/index.js +0 -107
- package/importPages/create/index.js.map +0 -1
- package/importPages/process/index.js +0 -180
- package/importPages/process/index.js.map +0 -1
- package/importPages/utils.d.ts +0 -50
- package/importPages/utils.js +0 -488
- package/importPages/utils.js.map +0 -1
- /package/{exportPages → export}/s3Stream.js +0 -0
@@ -0,0 +1,162 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.blocksHandler = void 0;
|
7
|
+
var _types = require("../../types");
|
8
|
+
var _client = require("../../client");
|
9
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
10
|
+
var _utils = require("../utils");
|
11
|
+
var _mockSecurity = require("../../mockSecurity");
|
12
|
+
var _utils2 = require("@webiny/utils");
|
13
|
+
/**
|
14
|
+
* Handles the export blocks process workflow.
|
15
|
+
*/
|
16
|
+
const blocksHandler = async (configuration, payload, context) => {
|
17
|
+
const log = console.log;
|
18
|
+
let subTask;
|
19
|
+
let noPendingTask = true;
|
20
|
+
let prevStatusOfSubTask = _types.ImportExportTaskStatus.PENDING;
|
21
|
+
log("RUNNING Export Blocks Process Handler");
|
22
|
+
const {
|
23
|
+
pageBuilder,
|
24
|
+
fileManager
|
25
|
+
} = context;
|
26
|
+
const {
|
27
|
+
taskId,
|
28
|
+
subTaskIndex,
|
29
|
+
type,
|
30
|
+
identity
|
31
|
+
} = payload;
|
32
|
+
// Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks
|
33
|
+
// and this Lambda is invoked internally, without credentials.
|
34
|
+
(0, _mockSecurity.mockSecurity)(identity, context);
|
35
|
+
try {
|
36
|
+
/*
|
37
|
+
* Note: We're not going to DB for finding the next sub-task to process,
|
38
|
+
* because the data might be out of sync due to GSI eventual consistency.
|
39
|
+
*/
|
40
|
+
subTask = await pageBuilder.importExportTask.getSubTask(taskId, (0, _utils2.zeroPad)(subTaskIndex, 5));
|
41
|
+
/**
|
42
|
+
* Base condition!!
|
43
|
+
* Bail out early, if task not found or task's status is not "pending".
|
44
|
+
*/
|
45
|
+
if (!subTask || subTask.status !== _types.ImportExportTaskStatus.PENDING) {
|
46
|
+
noPendingTask = true;
|
47
|
+
return {
|
48
|
+
data: "",
|
49
|
+
error: null
|
50
|
+
};
|
51
|
+
} else {
|
52
|
+
noPendingTask = false;
|
53
|
+
}
|
54
|
+
log(`Fetched sub task => ${subTask.id}`);
|
55
|
+
const {
|
56
|
+
input
|
57
|
+
} = subTask;
|
58
|
+
const {
|
59
|
+
blockId,
|
60
|
+
exportBlocksDataKey
|
61
|
+
} = input;
|
62
|
+
const block = await pageBuilder.getPageBlock(blockId);
|
63
|
+
if (!block) {
|
64
|
+
log(`Unable to load block "${blockId}"`);
|
65
|
+
throw new _handlerGraphql.NotFoundError(`Unable to load block "${blockId}"`);
|
66
|
+
}
|
67
|
+
log(`Processing block key "${blockId}"`);
|
68
|
+
|
69
|
+
// Mark task status as PROCESSING
|
70
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
71
|
+
status: _types.ImportExportTaskStatus.PROCESSING
|
72
|
+
});
|
73
|
+
// Update stats in main task
|
74
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
75
|
+
prevStatus: prevStatusOfSubTask,
|
76
|
+
nextStatus: _types.ImportExportTaskStatus.PROCESSING
|
77
|
+
});
|
78
|
+
prevStatusOfSubTask = subTask.status;
|
79
|
+
log(`Extracting block data and uploading to storage...`);
|
80
|
+
// Extract Block
|
81
|
+
const blockDataZip = await (0, _utils.exportBlock)(block, exportBlocksDataKey, fileManager);
|
82
|
+
log(`Finish uploading zip...`);
|
83
|
+
// Update task record in DB
|
84
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
85
|
+
status: _types.ImportExportTaskStatus.COMPLETED,
|
86
|
+
data: {
|
87
|
+
message: `Finish uploading data for block "${block.id}"`,
|
88
|
+
key: blockDataZip.Key
|
89
|
+
}
|
90
|
+
});
|
91
|
+
// Update stats in main task
|
92
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
93
|
+
prevStatus: prevStatusOfSubTask,
|
94
|
+
nextStatus: _types.ImportExportTaskStatus.COMPLETED
|
95
|
+
});
|
96
|
+
prevStatusOfSubTask = subTask.status;
|
97
|
+
} catch (e) {
|
98
|
+
log("[EXPORT_BLOCKS_PROCESS] Error => ", e.message);
|
99
|
+
if (subTask && subTask.id) {
|
100
|
+
/**
|
101
|
+
* In case of error, we'll update the task status to "failed",
|
102
|
+
* so that, client can show notify the user appropriately.
|
103
|
+
*/
|
104
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
105
|
+
status: _types.ImportExportTaskStatus.FAILED,
|
106
|
+
error: {
|
107
|
+
name: e.name,
|
108
|
+
message: e.message,
|
109
|
+
code: "EXPORT_FAILED"
|
110
|
+
}
|
111
|
+
});
|
112
|
+
|
113
|
+
// Update stats in main task
|
114
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
115
|
+
prevStatus: prevStatusOfSubTask,
|
116
|
+
nextStatus: _types.ImportExportTaskStatus.FAILED
|
117
|
+
});
|
118
|
+
prevStatusOfSubTask = subTask.status;
|
119
|
+
}
|
120
|
+
return {
|
121
|
+
data: null,
|
122
|
+
error: {
|
123
|
+
message: e.message
|
124
|
+
}
|
125
|
+
};
|
126
|
+
} finally {
|
127
|
+
// Base condition!
|
128
|
+
if (noPendingTask) {
|
129
|
+
log(`No pending sub-task for task ${taskId}`);
|
130
|
+
// Combine individual block zip files.
|
131
|
+
await (0, _client.invokeHandlerClient)({
|
132
|
+
context,
|
133
|
+
name: configuration.handlers.combine,
|
134
|
+
payload: {
|
135
|
+
taskId,
|
136
|
+
type,
|
137
|
+
identity: context.security.getIdentity()
|
138
|
+
},
|
139
|
+
description: "Export blocks - combine"
|
140
|
+
});
|
141
|
+
} else {
|
142
|
+
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`);
|
143
|
+
// We want to continue with Self invocation no matter if current block error out.
|
144
|
+
await (0, _client.invokeHandlerClient)({
|
145
|
+
context,
|
146
|
+
name: configuration.handlers.process,
|
147
|
+
payload: {
|
148
|
+
taskId,
|
149
|
+
subTaskIndex: subTaskIndex + 1,
|
150
|
+
type,
|
151
|
+
identity: context.security.getIdentity()
|
152
|
+
},
|
153
|
+
description: "Export blocks - process - subtask"
|
154
|
+
});
|
155
|
+
}
|
156
|
+
}
|
157
|
+
return {
|
158
|
+
data: "",
|
159
|
+
error: null
|
160
|
+
};
|
161
|
+
};
|
162
|
+
exports.blocksHandler = blocksHandler;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["blocksHandler","configuration","payload","context","log","console","subTask","noPendingTask","prevStatusOfSubTask","ImportExportTaskStatus","PENDING","pageBuilder","fileManager","taskId","subTaskIndex","type","identity","mockSecurity","importExportTask","getSubTask","zeroPad","status","data","error","id","input","blockId","exportBlocksDataKey","block","getPageBlock","NotFoundError","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","blockDataZip","exportBlock","COMPLETED","message","key","Key","e","FAILED","name","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process"],"sources":["blocksHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { exportBlock } from \"~/export/utils\";\nimport { Payload as ExtractPayload } from \"../combine\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { Configuration, Payload, Response } from \"~/export/process\";\n\n/**\n * Handles the export blocks process workflow.\n */\nexport const blocksHandler = async (\n configuration: Configuration,\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n let subTask;\n let noPendingTask = true;\n let prevStatusOfSubTask = ImportExportTaskStatus.PENDING;\n\n log(\"RUNNING Export Blocks Process Handler\");\n const { pageBuilder, fileManager } = context;\n const { taskId, subTaskIndex, type, identity } = payload;\n // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks\n // and this Lambda is invoked internally, without credentials.\n mockSecurity(identity as SecurityIdentity, context);\n try {\n /*\n * Note: We're not going to DB for finding the next sub-task to process,\n * because the data might be out of sync due to GSI eventual consistency.\n */\n subTask = await pageBuilder.importExportTask.getSubTask(taskId, zeroPad(subTaskIndex, 5));\n /**\n * Base condition!!\n * Bail out early, if task not found or task's status is not \"pending\".\n */\n if (!subTask || subTask.status !== ImportExportTaskStatus.PENDING) {\n noPendingTask = true;\n return {\n data: \"\",\n error: null\n };\n } else {\n noPendingTask = false;\n }\n\n log(`Fetched sub task => ${subTask.id}`);\n\n const { input } = subTask;\n const { blockId, exportBlocksDataKey } = input;\n\n const block = await pageBuilder.getPageBlock(blockId);\n\n if (!block) {\n log(`Unable to load block \"${blockId}\"`);\n throw new NotFoundError(`Unable to load block \"${blockId}\"`);\n }\n\n log(`Processing block key \"${blockId}\"`);\n\n // Mark task status as PROCESSING\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.PROCESSING\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.PROCESSING\n });\n prevStatusOfSubTask = subTask.status;\n\n log(`Extracting block data and uploading to storage...`);\n // Extract Block\n const blockDataZip = await exportBlock(block, exportBlocksDataKey, fileManager);\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for block \"${block.id}\"`,\n key: blockDataZip.Key\n }\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.COMPLETED\n });\n prevStatusOfSubTask = subTask.status;\n } catch (e) {\n log(\"[EXPORT_BLOCKS_PROCESS] Error => \", e.message);\n\n if (subTask && subTask.id) {\n /**\n * In case of error, we'll update the task status to \"failed\",\n * so that, client can show notify the user appropriately.\n */\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n code: \"EXPORT_FAILED\"\n }\n });\n\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.FAILED\n });\n prevStatusOfSubTask = subTask.status;\n }\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n } finally {\n // Base condition!\n if (noPendingTask) {\n log(`No pending sub-task for task ${taskId}`);\n // Combine individual block zip files.\n await invokeHandlerClient<ExtractPayload>({\n context,\n name: configuration.handlers.combine,\n payload: {\n taskId,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export blocks - combine\"\n });\n } else {\n console.log(`Invoking PROCESS for task \"${subTaskIndex + 1}\"`);\n // We want to continue with Self invocation no matter if current block error out.\n await invokeHandlerClient<Payload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId,\n subTaskIndex: subTaskIndex + 1,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export blocks - process - subtask\"\n });\n }\n }\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAEA;AAEA;AAGA;AACA;AACA;AACO,MAAMA,aAAa,GAAG,OACzBC,aAA4B,EAC5BC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EACvB,IAAIE,OAAO;EACX,IAAIC,aAAa,GAAG,IAAI;EACxB,IAAIC,mBAAmB,GAAGC,6BAAsB,CAACC,OAAO;EAExDN,GAAG,CAAC,uCAA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0 +1,6 @@
|
|
1
|
+
import { PbImportExportContext } from "../../types";
|
2
|
+
import { 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>;
|
@@ -0,0 +1,187 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.formsHandler = void 0;
|
7
|
+
var _types = require("../../types");
|
8
|
+
var _client = require("../../client");
|
9
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
10
|
+
var _utils = require("../utils");
|
11
|
+
var _mockSecurity = require("../../mockSecurity");
|
12
|
+
var _utils2 = require("@webiny/utils");
|
13
|
+
/**
|
14
|
+
* Handles the export forms process workflow.
|
15
|
+
*/
|
16
|
+
const formsHandler = async (configuration, payload, context) => {
|
17
|
+
const log = console.log;
|
18
|
+
let subTask;
|
19
|
+
let noPendingTask = true;
|
20
|
+
let prevStatusOfSubTask = _types.ImportExportTaskStatus.PENDING;
|
21
|
+
log("RUNNING Export Forms Process Handler");
|
22
|
+
const {
|
23
|
+
formBuilder,
|
24
|
+
pageBuilder
|
25
|
+
} = context;
|
26
|
+
const {
|
27
|
+
taskId,
|
28
|
+
subTaskIndex,
|
29
|
+
type,
|
30
|
+
identity
|
31
|
+
} = payload;
|
32
|
+
// Disable authorization; this is necessary because we call Form Builder CRUD methods which include authorization checks
|
33
|
+
// and this Lambda is invoked internally, without credentials.
|
34
|
+
(0, _mockSecurity.mockSecurity)(identity, context);
|
35
|
+
try {
|
36
|
+
/*
|
37
|
+
* Note: We're not going to DB for finding the next sub-task to process,
|
38
|
+
* because the data might be out of sync due to GSI eventual consistency.
|
39
|
+
*/
|
40
|
+
subTask = await pageBuilder.importExportTask.getSubTask(taskId, (0, _utils2.zeroPad)(subTaskIndex, 5));
|
41
|
+
/**
|
42
|
+
* Base condition!!
|
43
|
+
* Bail out early, if task not found or task's status is not "pending".
|
44
|
+
*/
|
45
|
+
if (!subTask || subTask.status !== _types.ImportExportTaskStatus.PENDING) {
|
46
|
+
noPendingTask = true;
|
47
|
+
return {
|
48
|
+
data: "",
|
49
|
+
error: null
|
50
|
+
};
|
51
|
+
} else {
|
52
|
+
noPendingTask = false;
|
53
|
+
}
|
54
|
+
log(`Fetched sub task => ${subTask.id}`);
|
55
|
+
const {
|
56
|
+
input
|
57
|
+
} = subTask;
|
58
|
+
const {
|
59
|
+
formId,
|
60
|
+
exportFormsDataKey,
|
61
|
+
revisionType
|
62
|
+
} = input;
|
63
|
+
|
64
|
+
/**
|
65
|
+
* At the moment, we only export a single revision of the form.
|
66
|
+
* It could be "published" or "latest" depending upon user input.
|
67
|
+
*
|
68
|
+
* Note: In case of no "published" revision available, we use the latest revision.
|
69
|
+
*/
|
70
|
+
let form;
|
71
|
+
try {
|
72
|
+
if (revisionType === _types.ExportRevisionType.PUBLISHED) {
|
73
|
+
// Get "published" form.
|
74
|
+
form = await formBuilder.getLatestPublishedFormRevision(formId);
|
75
|
+
} else {
|
76
|
+
// Get "latest" form.
|
77
|
+
form = await formBuilder.getForm(formId);
|
78
|
+
}
|
79
|
+
} catch (e) {
|
80
|
+
// If we're looking for "published" form and doesn't found it, get latest form.
|
81
|
+
if (revisionType === _types.ExportRevisionType.PUBLISHED && e instanceof _handlerGraphql.NotFoundError) {
|
82
|
+
form = await formBuilder.getForm(formId);
|
83
|
+
} else {
|
84
|
+
throw e;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
if (!form) {
|
88
|
+
log(`Unable to load form "${formId}"`);
|
89
|
+
throw new _handlerGraphql.NotFoundError(`Unable to load form "${formId}"`);
|
90
|
+
}
|
91
|
+
log(`Processing form key "${formId}" | version ${form.version} | ${form.status}`);
|
92
|
+
|
93
|
+
// Mark task status as PROCESSING
|
94
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
95
|
+
status: _types.ImportExportTaskStatus.PROCESSING
|
96
|
+
});
|
97
|
+
// Update stats in main task
|
98
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
99
|
+
prevStatus: prevStatusOfSubTask,
|
100
|
+
nextStatus: _types.ImportExportTaskStatus.PROCESSING
|
101
|
+
});
|
102
|
+
prevStatusOfSubTask = subTask.status;
|
103
|
+
log(`Extracting form data and uploading to storage...`);
|
104
|
+
// Extract Form
|
105
|
+
const formDataZip = await (0, _utils.exportForm)(form, exportFormsDataKey);
|
106
|
+
log(`Finish uploading zip...`);
|
107
|
+
// Update task record in DB
|
108
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
109
|
+
status: _types.ImportExportTaskStatus.COMPLETED,
|
110
|
+
data: {
|
111
|
+
message: `Finish uploading data for form "${form.id}" v${form.version} (${form.status}).`,
|
112
|
+
key: formDataZip.Key
|
113
|
+
}
|
114
|
+
});
|
115
|
+
// Update stats in main task
|
116
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
117
|
+
prevStatus: prevStatusOfSubTask,
|
118
|
+
nextStatus: _types.ImportExportTaskStatus.COMPLETED
|
119
|
+
});
|
120
|
+
prevStatusOfSubTask = subTask.status;
|
121
|
+
} catch (e) {
|
122
|
+
log("[EXPORT_PAGES_PROCESS] Error => ", e);
|
123
|
+
if (subTask && subTask.id) {
|
124
|
+
/**
|
125
|
+
* In case of error, we'll update the task status to "failed",
|
126
|
+
* so that, client can show notify the user appropriately.
|
127
|
+
*/
|
128
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
129
|
+
status: _types.ImportExportTaskStatus.FAILED,
|
130
|
+
error: {
|
131
|
+
name: e.name,
|
132
|
+
message: e.message,
|
133
|
+
stack: e.stack,
|
134
|
+
code: "EXPORT_FAILED"
|
135
|
+
}
|
136
|
+
});
|
137
|
+
|
138
|
+
// Update stats in main task
|
139
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
140
|
+
prevStatus: prevStatusOfSubTask,
|
141
|
+
nextStatus: _types.ImportExportTaskStatus.FAILED
|
142
|
+
});
|
143
|
+
prevStatusOfSubTask = subTask.status;
|
144
|
+
}
|
145
|
+
return {
|
146
|
+
data: null,
|
147
|
+
error: {
|
148
|
+
message: e.message
|
149
|
+
}
|
150
|
+
};
|
151
|
+
} finally {
|
152
|
+
// Base condition!
|
153
|
+
if (noPendingTask) {
|
154
|
+
log(`No pending sub-task for task ${taskId}`);
|
155
|
+
// Combine individual form zip files.
|
156
|
+
await (0, _client.invokeHandlerClient)({
|
157
|
+
context,
|
158
|
+
name: configuration.handlers.combine,
|
159
|
+
payload: {
|
160
|
+
taskId,
|
161
|
+
type,
|
162
|
+
identity: context.security.getIdentity()
|
163
|
+
},
|
164
|
+
description: "Export forms - combine"
|
165
|
+
});
|
166
|
+
} else {
|
167
|
+
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`);
|
168
|
+
// We want to continue with Self invocation no matter if current form error out.
|
169
|
+
await (0, _client.invokeHandlerClient)({
|
170
|
+
context,
|
171
|
+
name: configuration.handlers.process,
|
172
|
+
payload: {
|
173
|
+
taskId,
|
174
|
+
type,
|
175
|
+
subTaskIndex: subTaskIndex + 1,
|
176
|
+
identity: context.security.getIdentity()
|
177
|
+
},
|
178
|
+
description: "Export forms - process - subtask"
|
179
|
+
});
|
180
|
+
}
|
181
|
+
}
|
182
|
+
return {
|
183
|
+
data: "",
|
184
|
+
error: null
|
185
|
+
};
|
186
|
+
};
|
187
|
+
exports.formsHandler = formsHandler;
|
@@ -0,0 +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,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,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,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,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { PbImportExportContext } from "../../types";
|
2
2
|
import { SecurityIdentity } from "@webiny/api-security/types";
|
3
|
-
interface Configuration {
|
3
|
+
export interface Configuration {
|
4
4
|
handlers: {
|
5
5
|
process: string;
|
6
6
|
combine: string;
|
@@ -9,14 +9,12 @@ interface Configuration {
|
|
9
9
|
export interface Payload {
|
10
10
|
taskId: string;
|
11
11
|
subTaskIndex: number;
|
12
|
+
type: string;
|
12
13
|
identity?: SecurityIdentity;
|
13
14
|
}
|
14
15
|
export interface Response {
|
15
16
|
data: string | null;
|
16
17
|
error: Partial<Error> | null;
|
17
18
|
}
|
18
|
-
|
19
|
-
* Handles the export pages process workflow.
|
20
|
-
*/
|
21
|
-
declare const _default: (configuration: Configuration) => import("@webiny/handler-aws").RawEventHandler<Payload, PbPageImportExportContext, Response>;
|
19
|
+
declare const _default: (configuration: Configuration) => import("@webiny/handler-aws").RawEventHandler<Payload, PbImportExportContext, Response>;
|
22
20
|
export default _default;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
var _handlerAws = require("@webiny/handler-aws");
|
8
|
+
var _blocksHandler = require("./blocksHandler");
|
9
|
+
var _formsHandler = require("./formsHandler");
|
10
|
+
var _pagesHandler = require("./pagesHandler");
|
11
|
+
var _templatesHandler = require("./templatesHandler");
|
12
|
+
var _default = configuration => {
|
13
|
+
return (0, _handlerAws.createRawEventHandler)(async ({
|
14
|
+
payload,
|
15
|
+
context
|
16
|
+
}) => {
|
17
|
+
switch (payload.type) {
|
18
|
+
case "block":
|
19
|
+
{
|
20
|
+
return await (0, _blocksHandler.blocksHandler)(configuration, payload, context);
|
21
|
+
}
|
22
|
+
case "form":
|
23
|
+
{
|
24
|
+
return await (0, _formsHandler.formsHandler)(configuration, payload, context);
|
25
|
+
}
|
26
|
+
case "template":
|
27
|
+
{
|
28
|
+
return await (0, _templatesHandler.templatesHandler)(configuration, payload, context);
|
29
|
+
}
|
30
|
+
default:
|
31
|
+
{
|
32
|
+
return await (0, _pagesHandler.pagesHandler)(configuration, payload, context);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
});
|
36
|
+
};
|
37
|
+
exports.default = _default;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["configuration","createRawEventHandler","payload","context","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 switch (payload.type) {\n case \"block\": {\n return await blocksHandler(configuration, payload, context);\n }\n case \"form\": {\n return await formsHandler(configuration, payload, context);\n }\n case \"template\": {\n return await templatesHandler(configuration, payload, context);\n }\n default: {\n return await pagesHandler(configuration, payload, context);\n }\n }\n }\n );\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AAAqE,eAqBrDA,aAA4B,IAAK;EAC7C,OAAO,IAAAC,iCAAqB,EACxB,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IAC5B,QAAQD,OAAO,CAACE,IAAI;MAChB,KAAK,OAAO;QAAE;UACV,OAAO,MAAM,IAAAC,4BAAa,EAACL,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;QAC/D;MACA,KAAK,MAAM;QAAE;UACT,OAAO,MAAM,IAAAG,0BAAY,EAACN,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;QAC9D;MACA,KAAK,UAAU;QAAE;UACb,OAAO,MAAM,IAAAI,kCAAgB,EAACP,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;QAClE;MACA;QAAS;UACL,OAAO,MAAM,IAAAK,0BAAY,EAACR,aAAa,EAAEE,OAAO,EAAEC,OAAO,CAAC;QAC9D;IAAC;EAET,CAAC,CACJ;AACL,CAAC;AAAA"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { PbImportExportContext } from "../../types";
|
2
|
+
import { Configuration, Payload, Response } from ".";
|
3
|
+
/**
|
4
|
+
* Handles the export pages process workflow.
|
5
|
+
*/
|
6
|
+
export declare const pagesHandler: (configuration: Configuration, payload: Payload, context: PbImportExportContext) => Promise<Response>;
|
@@ -0,0 +1,189 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.pagesHandler = void 0;
|
7
|
+
var _types = require("../../types");
|
8
|
+
var _client = require("../../client");
|
9
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
10
|
+
var _utils = require("../utils");
|
11
|
+
var _mockSecurity = require("../../mockSecurity");
|
12
|
+
var _utils2 = require("@webiny/utils");
|
13
|
+
/**
|
14
|
+
* Handles the export pages process workflow.
|
15
|
+
*/
|
16
|
+
const pagesHandler = async (configuration, payload, context) => {
|
17
|
+
const log = console.log;
|
18
|
+
let subTask;
|
19
|
+
let noPendingTask = true;
|
20
|
+
let prevStatusOfSubTask = _types.ImportExportTaskStatus.PENDING;
|
21
|
+
log("RUNNING Export Pages Process Handler");
|
22
|
+
const {
|
23
|
+
pageBuilder,
|
24
|
+
fileManager
|
25
|
+
} = context;
|
26
|
+
const {
|
27
|
+
taskId,
|
28
|
+
subTaskIndex,
|
29
|
+
type,
|
30
|
+
identity
|
31
|
+
} = payload;
|
32
|
+
// Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks
|
33
|
+
// and this Lambda is invoked internally, without credentials.
|
34
|
+
(0, _mockSecurity.mockSecurity)(identity, context);
|
35
|
+
try {
|
36
|
+
/*
|
37
|
+
* Note: We're not going to DB for finding the next sub-task to process,
|
38
|
+
* because the data might be out of sync due to GSI eventual consistency.
|
39
|
+
*/
|
40
|
+
subTask = await pageBuilder.importExportTask.getSubTask(taskId, (0, _utils2.zeroPad)(subTaskIndex, 5));
|
41
|
+
/**
|
42
|
+
* Base condition!!
|
43
|
+
* Bail out early, if task not found or task's status is not "pending".
|
44
|
+
*/
|
45
|
+
if (!subTask || subTask.status !== _types.ImportExportTaskStatus.PENDING) {
|
46
|
+
noPendingTask = true;
|
47
|
+
return {
|
48
|
+
data: "",
|
49
|
+
error: null
|
50
|
+
};
|
51
|
+
} else {
|
52
|
+
noPendingTask = false;
|
53
|
+
}
|
54
|
+
log(`Fetched sub task => ${subTask.id}`);
|
55
|
+
const {
|
56
|
+
input
|
57
|
+
} = subTask;
|
58
|
+
const {
|
59
|
+
pageId,
|
60
|
+
exportPagesDataKey,
|
61
|
+
revisionType
|
62
|
+
} = input;
|
63
|
+
|
64
|
+
/**
|
65
|
+
* At the moment, we only export a single revision of the page.
|
66
|
+
* It could be "published" or "latest" depending upon user input.
|
67
|
+
*
|
68
|
+
* Note: In case of no "published" revision available, we use the latest revision.
|
69
|
+
*/
|
70
|
+
let page;
|
71
|
+
try {
|
72
|
+
if (revisionType === _types.ExportRevisionType.PUBLISHED) {
|
73
|
+
// Get "published" page.
|
74
|
+
page = await pageBuilder.getPublishedPageById({
|
75
|
+
id: pageId
|
76
|
+
});
|
77
|
+
} else {
|
78
|
+
// Get "latest" page.
|
79
|
+
page = await pageBuilder.getPage(pageId);
|
80
|
+
}
|
81
|
+
} catch (e) {
|
82
|
+
// If we're looking for "published" page and doesn't found it, get latest page.
|
83
|
+
if (revisionType === _types.ExportRevisionType.PUBLISHED && e instanceof _handlerGraphql.NotFoundError) {
|
84
|
+
page = await pageBuilder.getPage(pageId);
|
85
|
+
} else {
|
86
|
+
throw e;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
if (!page) {
|
90
|
+
log(`Unable to load page "${pageId}"`);
|
91
|
+
throw new _handlerGraphql.NotFoundError(`Unable to load page "${pageId}"`);
|
92
|
+
}
|
93
|
+
log(`Processing page key "${pageId}" | version ${page.version} | ${page.status}`);
|
94
|
+
|
95
|
+
// Mark task status as PROCESSING
|
96
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
97
|
+
status: _types.ImportExportTaskStatus.PROCESSING
|
98
|
+
});
|
99
|
+
// Update stats in main task
|
100
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
101
|
+
prevStatus: prevStatusOfSubTask,
|
102
|
+
nextStatus: _types.ImportExportTaskStatus.PROCESSING
|
103
|
+
});
|
104
|
+
prevStatusOfSubTask = subTask.status;
|
105
|
+
log(`Extracting page data and uploading to storage...`);
|
106
|
+
// Extract Page
|
107
|
+
const pageDataZip = await (0, _utils.exportPage)(page, exportPagesDataKey, fileManager);
|
108
|
+
log(`Finish uploading zip...`);
|
109
|
+
// Update task record in DB
|
110
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
111
|
+
status: _types.ImportExportTaskStatus.COMPLETED,
|
112
|
+
data: {
|
113
|
+
message: `Finish uploading data for page "${page.id}" v${page.version} (${page.status}).`,
|
114
|
+
key: pageDataZip.Key
|
115
|
+
}
|
116
|
+
});
|
117
|
+
// Update stats in main task
|
118
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
119
|
+
prevStatus: prevStatusOfSubTask,
|
120
|
+
nextStatus: _types.ImportExportTaskStatus.COMPLETED
|
121
|
+
});
|
122
|
+
prevStatusOfSubTask = subTask.status;
|
123
|
+
} catch (e) {
|
124
|
+
log("[EXPORT_PAGES_PROCESS] Error => ", e);
|
125
|
+
if (subTask && subTask.id) {
|
126
|
+
/**
|
127
|
+
* In case of error, we'll update the task status to "failed",
|
128
|
+
* so that, client can show notify the user appropriately.
|
129
|
+
*/
|
130
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
131
|
+
status: _types.ImportExportTaskStatus.FAILED,
|
132
|
+
error: {
|
133
|
+
name: e.name,
|
134
|
+
message: e.message,
|
135
|
+
stack: e.stack,
|
136
|
+
code: "EXPORT_FAILED"
|
137
|
+
}
|
138
|
+
});
|
139
|
+
|
140
|
+
// Update stats in main task
|
141
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
142
|
+
prevStatus: prevStatusOfSubTask,
|
143
|
+
nextStatus: _types.ImportExportTaskStatus.FAILED
|
144
|
+
});
|
145
|
+
prevStatusOfSubTask = subTask.status;
|
146
|
+
}
|
147
|
+
return {
|
148
|
+
data: null,
|
149
|
+
error: {
|
150
|
+
message: e.message
|
151
|
+
}
|
152
|
+
};
|
153
|
+
} finally {
|
154
|
+
// Base condition!
|
155
|
+
if (noPendingTask) {
|
156
|
+
log(`No pending sub-task for task ${taskId}`);
|
157
|
+
// Combine individual page zip files.
|
158
|
+
await (0, _client.invokeHandlerClient)({
|
159
|
+
context,
|
160
|
+
name: configuration.handlers.combine,
|
161
|
+
payload: {
|
162
|
+
taskId,
|
163
|
+
type,
|
164
|
+
identity: context.security.getIdentity()
|
165
|
+
},
|
166
|
+
description: "Export pages - combine"
|
167
|
+
});
|
168
|
+
} else {
|
169
|
+
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`);
|
170
|
+
// We want to continue with Self invocation no matter if current page error out.
|
171
|
+
await (0, _client.invokeHandlerClient)({
|
172
|
+
context,
|
173
|
+
name: configuration.handlers.process,
|
174
|
+
payload: {
|
175
|
+
taskId,
|
176
|
+
type,
|
177
|
+
subTaskIndex: subTaskIndex + 1,
|
178
|
+
identity: context.security.getIdentity()
|
179
|
+
},
|
180
|
+
description: "Export pages - process - subtask"
|
181
|
+
});
|
182
|
+
}
|
183
|
+
}
|
184
|
+
return {
|
185
|
+
data: "",
|
186
|
+
error: null
|
187
|
+
};
|
188
|
+
};
|
189
|
+
exports.pagesHandler = pagesHandler;
|