@webiny/api-page-builder-import-export 0.0.0-unstable.aad28a72ae → 0.0.0-unstable.acacc54f0e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +2 -6
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.js +11 -18
- package/export/combine/blocksHandler.js.map +1 -1
- package/export/combine/formsHandler.d.ts +6 -0
- package/export/combine/formsHandler.js +99 -0
- package/export/combine/formsHandler.js.map +1 -0
- package/export/combine/index.js +22 -10
- package/export/combine/index.js.map +1 -1
- package/export/combine/pagesHandler.js +11 -18
- package/export/combine/pagesHandler.js.map +1 -1
- 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.js +27 -36
- package/export/process/blocksHandler.js.map +1 -1
- package/export/process/exporters/BlockExporter.d.ts +13 -0
- package/export/process/exporters/BlockExporter.js +81 -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 +34 -0
- package/export/process/exporters/FormExporter.js.map +1 -0
- package/export/process/exporters/PageExporter.d.ts +11 -0
- package/export/process/exporters/PageExporter.js +58 -0
- package/export/process/exporters/PageExporter.js.map +1 -0
- package/export/process/exporters/PageTemplateExporter.d.ts +11 -0
- package/export/process/exporters/PageTemplateExporter.js +56 -0
- package/export/process/exporters/PageTemplateExporter.js.map +1 -0
- package/export/process/formsHandler.d.ts +6 -0
- package/export/process/formsHandler.js +187 -0
- package/export/process/formsHandler.js.map +1 -0
- package/export/process/index.js +22 -10
- package/export/process/index.js.map +1 -1
- package/export/process/pagesHandler.js +23 -38
- package/export/process/pagesHandler.js.map +1 -1
- package/export/process/templatesHandler.d.ts +6 -0
- package/export/process/templatesHandler.js +166 -0
- package/export/process/templatesHandler.js.map +1 -0
- package/export/s3Stream.d.ts +5 -2
- package/export/s3Stream.js +1 -20
- package/export/s3Stream.js.map +1 -1
- package/export/utils.d.ts +2 -16
- package/export/utils.js +5 -105
- package/export/utils.js.map +1 -1
- package/export/zipper.js +31 -43
- package/export/zipper.js.map +1 -1
- package/graphql/crud/blocks.crud.js +29 -54
- package/graphql/crud/blocks.crud.js.map +1 -1
- package/graphql/crud/forms.crud.d.ts +4 -0
- package/graphql/crud/forms.crud.js +134 -0
- package/graphql/crud/forms.crud.js.map +1 -0
- package/graphql/crud/importExportTasks.crud.js +47 -94
- package/graphql/crud/importExportTasks.crud.js.map +1 -1
- package/graphql/crud/pages.crud.d.ts +1 -0
- package/graphql/crud/pages.crud.js +38 -49
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.d.ts +4 -0
- package/graphql/crud/templates.crud.js +128 -0
- package/graphql/crud/templates.crud.js.map +1 -0
- package/graphql/crud.js +3 -7
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.js +2 -7
- 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.js +1 -6
- package/graphql/graphql/importExportTasks.gql.js.map +1 -1
- package/graphql/graphql/pages.gql.js +2 -7
- 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/utils/resolve.d.ts +1 -1
- package/graphql/graphql/utils/resolve.js +0 -3
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/graphql.js +3 -6
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.js +0 -5
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +40 -1
- 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.js +11 -22
- package/import/create/blocksHandler.js.map +1 -1
- package/import/{process/pagesHandler.d.ts → create/formsHandler.d.ts} +1 -1
- package/import/create/formsHandler.js +103 -0
- package/import/create/formsHandler.js.map +1 -0
- package/import/create/index.d.ts +2 -1
- package/import/create/index.js +22 -10
- package/import/create/index.js.map +1 -1
- package/import/create/pagesHandler.js +13 -20
- package/import/create/pagesHandler.js.map +1 -1
- 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/{blocksHandler.d.ts → blocks/blocksHandler.d.ts} +2 -2
- package/import/process/{blocksHandler.js → blocks/blocksHandler.js} +28 -35
- package/import/process/blocks/blocksHandler.js.map +1 -0
- package/import/process/blocks/importBlock.d.ts +11 -0
- package/import/process/blocks/importBlock.js +106 -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/import/process/index.d.ts +1 -0
- package/import/process/index.js +24 -12
- package/import/process/index.js.map +1 -1
- 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/{pagesHandler.js → pages/pagesHandler.js} +39 -36
- 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 +49 -0
- package/import/utils/updateFilesInData.js.map +1 -0
- package/import/utils/uploadAssets.d.ts +10 -0
- package/import/utils/uploadAssets.js +87 -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/mockSecurity.js +0 -3
- package/mockSecurity.js.map +1 -1
- package/package.json +34 -37
- package/types.d.ts +21 -0
- package/types.js +60 -13
- package/types.js.map +1 -1
- package/import/process/blocksHandler.js.map +0 -1
- package/import/process/pagesHandler.js.map +0 -1
- package/import/utils.d.ts +0 -49
- package/import/utils.js +0 -641
- package/import/utils.js.map +0 -1
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.blocksHandler = void 0;
|
7
|
-
|
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 _BlockExporter = require("./exporters/BlockExporter");
|
20
13
|
/**
|
21
14
|
* Handles the export blocks process workflow.
|
22
15
|
*/
|
@@ -35,22 +28,20 @@ const blocksHandler = async (configuration, payload, context) => {
|
|
35
28
|
subTaskIndex,
|
36
29
|
type,
|
37
30
|
identity
|
38
|
-
} = payload;
|
31
|
+
} = payload;
|
32
|
+
// Disable authorization; this is necessary because we call Page 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,7 +51,6 @@ const blocksHandler = 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
|
@@ -70,36 +60,40 @@ const blocksHandler = async (configuration, payload, context) => {
|
|
70
60
|
exportBlocksDataKey
|
71
61
|
} = input;
|
72
62
|
const block = await pageBuilder.getPageBlock(blockId);
|
73
|
-
|
74
63
|
if (!block) {
|
75
64
|
log(`Unable to load block "${blockId}"`);
|
76
65
|
throw new _handlerGraphql.NotFoundError(`Unable to load block "${blockId}"`);
|
77
66
|
}
|
67
|
+
log(`Processing block key "${blockId}"`);
|
68
|
+
const blockCategory = await pageBuilder.getBlockCategory(block.blockCategory);
|
69
|
+
if (!blockCategory) {
|
70
|
+
log(`Unable to load block category "${block.blockCategory}"`);
|
71
|
+
throw new _handlerGraphql.NotFoundError(`Unable to load block category "${block.blockCategory}"`);
|
72
|
+
}
|
78
73
|
|
79
|
-
|
80
|
-
|
74
|
+
// Mark task status as PROCESSING
|
81
75
|
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
82
76
|
status: _types.ImportExportTaskStatus.PROCESSING
|
83
|
-
});
|
84
|
-
|
77
|
+
});
|
78
|
+
// Update stats in main task
|
85
79
|
await pageBuilder.importExportTask.updateStats(taskId, {
|
86
80
|
prevStatus: prevStatusOfSubTask,
|
87
81
|
nextStatus: _types.ImportExportTaskStatus.PROCESSING
|
88
82
|
});
|
89
83
|
prevStatusOfSubTask = subTask.status;
|
90
|
-
log(`Extracting block data and uploading to storage...`);
|
91
|
-
|
92
|
-
const blockDataZip = await
|
93
|
-
log(`Finish uploading zip...`);
|
94
|
-
|
84
|
+
log(`Extracting block data and uploading to storage...`);
|
85
|
+
const blockExporter = new _BlockExporter.BlockExporter(fileManager);
|
86
|
+
const blockDataZip = await blockExporter.execute(block, blockCategory, exportBlocksDataKey);
|
87
|
+
log(`Finish uploading zip...`);
|
88
|
+
// Update task record in DB
|
95
89
|
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
96
90
|
status: _types.ImportExportTaskStatus.COMPLETED,
|
97
91
|
data: {
|
98
92
|
message: `Finish uploading data for block "${block.id}"`,
|
99
93
|
key: blockDataZip.Key
|
100
94
|
}
|
101
|
-
});
|
102
|
-
|
95
|
+
});
|
96
|
+
// Update stats in main task
|
103
97
|
await pageBuilder.importExportTask.updateStats(taskId, {
|
104
98
|
prevStatus: prevStatusOfSubTask,
|
105
99
|
nextStatus: _types.ImportExportTaskStatus.COMPLETED
|
@@ -107,7 +101,6 @@ const blocksHandler = async (configuration, payload, context) => {
|
|
107
101
|
prevStatusOfSubTask = subTask.status;
|
108
102
|
} catch (e) {
|
109
103
|
log("[EXPORT_BLOCKS_PROCESS] Error => ", e.message);
|
110
|
-
|
111
104
|
if (subTask && subTask.id) {
|
112
105
|
/**
|
113
106
|
* In case of error, we'll update the task status to "failed",
|
@@ -120,15 +113,15 @@ const blocksHandler = async (configuration, payload, context) => {
|
|
120
113
|
message: e.message,
|
121
114
|
code: "EXPORT_FAILED"
|
122
115
|
}
|
123
|
-
});
|
116
|
+
});
|
124
117
|
|
118
|
+
// Update stats in main task
|
125
119
|
await pageBuilder.importExportTask.updateStats(taskId, {
|
126
120
|
prevStatus: prevStatusOfSubTask,
|
127
121
|
nextStatus: _types.ImportExportTaskStatus.FAILED
|
128
122
|
});
|
129
123
|
prevStatusOfSubTask = subTask.status;
|
130
124
|
}
|
131
|
-
|
132
125
|
return {
|
133
126
|
data: null,
|
134
127
|
error: {
|
@@ -138,8 +131,8 @@ const blocksHandler = async (configuration, payload, context) => {
|
|
138
131
|
} finally {
|
139
132
|
// Base condition!
|
140
133
|
if (noPendingTask) {
|
141
|
-
log(`No pending sub-task for task ${taskId}`);
|
142
|
-
|
134
|
+
log(`No pending sub-task for task ${taskId}`);
|
135
|
+
// Combine individual block zip files.
|
143
136
|
await (0, _client.invokeHandlerClient)({
|
144
137
|
context,
|
145
138
|
name: configuration.handlers.combine,
|
@@ -151,8 +144,8 @@ const blocksHandler = async (configuration, payload, context) => {
|
|
151
144
|
description: "Export blocks - combine"
|
152
145
|
});
|
153
146
|
} else {
|
154
|
-
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`);
|
155
|
-
|
147
|
+
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`);
|
148
|
+
// We want to continue with Self invocation no matter if current block error out.
|
156
149
|
await (0, _client.invokeHandlerClient)({
|
157
150
|
context,
|
158
151
|
name: configuration.handlers.process,
|
@@ -166,11 +159,9 @@ const blocksHandler = async (configuration, payload, context) => {
|
|
166
159
|
});
|
167
160
|
}
|
168
161
|
}
|
169
|
-
|
170
162
|
return {
|
171
163
|
data: "",
|
172
164
|
error: null
|
173
165
|
};
|
174
166
|
};
|
175
|
-
|
176
167
|
exports.blocksHandler = blocksHandler;
|
@@ -1 +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,aADyB,EAEzBC,OAFyB,EAGzBC,OAHyB,KAIL;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAApB;EACA,IAAIE,OAAJ;EACA,IAAIC,aAAa,GAAG,IAApB;EACA,IAAIC,mBAAmB,GAAGC,6BAAA,CAAuBC,OAAjD;EAEAN,GAAG,CAAC,uCAAD,CAAH;EACA,MAAM;IAAEO,WAAF;IAAeC;EAAf,IAA+BT,OAArC;EACA,MAAM;IAAEU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AW,EAAE;MATkB,CAA7B,CAAN;IAWH;EACJ;;EACD,OAAO;IACH7B,IAAI,EAAE,EADH;IAEHC,KAAK,EAAE;EAFJ,CAAP;AAIH,CAjJM"}
|
1
|
+
{"version":3,"names":["_types","require","_client","_handlerGraphql","_mockSecurity","_utils","_BlockExporter","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","blockCategory","getBlockCategory","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","blockExporter","BlockExporter","blockDataZip","execute","COMPLETED","message","key","Key","e","FAILED","name","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process","exports"],"sources":["blocksHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { Payload as ExtractPayload } from \"../combine\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { Configuration, Payload, Response } from \"~/export/process\";\nimport { BlockExporter } from \"./exporters/BlockExporter\";\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 const blockCategory = await pageBuilder.getBlockCategory(block.blockCategory);\n\n if (!blockCategory) {\n log(`Unable to load block category \"${block.blockCategory}\"`);\n throw new NotFoundError(`Unable to load block category \"${block.blockCategory}\"`);\n }\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 const blockExporter = new BlockExporter(fileManager);\n const blockDataZip = await blockExporter.execute(block, blockCategory, exportBlocksDataKey);\n\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for 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,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,cAAA,GAAAL,OAAA;AAEA;AACA;AACA;AACO,MAAMM,aAAa,GAAG,MAAAA,CACzBC,aAA4B,EAC5BC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EACvB,IAAIE,OAAO;EACX,IAAIC,aAAa,GAAG,IAA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;MAC9D;MACA,MAAM,IAAAoC,2BAAmB,EAAU;QAC/B/C,OAAO;QACP6C,IAAI,EAAE/C,aAAa,CAACkD,QAAQ,CAACK,OAAO;QACpCtD,OAAO,EAAE;UACLW,MAAM;UACNC,YAAY,EAAEA,YAAY,GAAG,CAAC;UAC9BC,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAACkD,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN;EACJ;EACA,OAAO;IACHjC,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAACkC,OAAA,CAAAzD,aAAA,GAAAA,aAAA"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { BlockCategory, PageBlock } from "@webiny/api-page-builder/types";
|
2
|
+
import { File, FileManagerContext } from "@webiny/api-file-manager/types";
|
3
|
+
export interface ExportedBlockData {
|
4
|
+
block: Pick<PageBlock, "name" | "content" | "preview">;
|
5
|
+
category: BlockCategory;
|
6
|
+
files: File[];
|
7
|
+
}
|
8
|
+
export declare class BlockExporter {
|
9
|
+
private fileManager;
|
10
|
+
constructor(fileManager: FileManagerContext["fileManager"]);
|
11
|
+
execute(block: PageBlock, blockCategory: BlockCategory, exportBlocksDataKey: string): Promise<import("aws-sdk/clients/s3").ManagedUpload.SendData>;
|
12
|
+
private getPreviewImageFile;
|
13
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.BlockExporter = void 0;
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
9
|
+
var _zipper = _interopRequireDefault(require("../../zipper"));
|
10
|
+
var _utils = require("../../utils");
|
11
|
+
class BlockExporter {
|
12
|
+
constructor(fileManager) {
|
13
|
+
(0, _defineProperty2.default)(this, "fileManager", void 0);
|
14
|
+
this.fileManager = fileManager;
|
15
|
+
}
|
16
|
+
async execute(block, blockCategory, exportBlocksDataKey) {
|
17
|
+
// Extract all files
|
18
|
+
const files = (0, _utils.extractFilesFromData)(block.content || {});
|
19
|
+
const fileIds = files.map(imageFile => imageFile.id);
|
20
|
+
// Get file data for all images
|
21
|
+
const imageFilesData = [];
|
22
|
+
if (fileIds.length > 0) {
|
23
|
+
const [filesData] = await this.fileManager.listFiles({
|
24
|
+
where: {
|
25
|
+
id_in: fileIds
|
26
|
+
}
|
27
|
+
});
|
28
|
+
imageFilesData.push(...filesData);
|
29
|
+
}
|
30
|
+
// Add block preview image file data
|
31
|
+
if (block.preview.id) {
|
32
|
+
const previewImage = await this.getPreviewImageFile(block);
|
33
|
+
if (previewImage) {
|
34
|
+
imageFilesData.push(previewImage);
|
35
|
+
block.preview.id = previewImage.id;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
// Extract the block data in a json file and upload it to S3
|
40
|
+
const blockData = {
|
41
|
+
block: {
|
42
|
+
name: block.name,
|
43
|
+
content: block.content,
|
44
|
+
preview: block.preview
|
45
|
+
},
|
46
|
+
category: {
|
47
|
+
name: blockCategory.name,
|
48
|
+
slug: blockCategory.slug,
|
49
|
+
icon: blockCategory.icon,
|
50
|
+
description: blockCategory.description
|
51
|
+
},
|
52
|
+
files: imageFilesData
|
53
|
+
};
|
54
|
+
const blockDataBuffer = Buffer.from(JSON.stringify(blockData));
|
55
|
+
const zipper = new _zipper.default({
|
56
|
+
exportInfo: {
|
57
|
+
files: imageFilesData,
|
58
|
+
name: block.name,
|
59
|
+
dataBuffer: blockDataBuffer
|
60
|
+
},
|
61
|
+
archiveFileKey: exportBlocksDataKey
|
62
|
+
});
|
63
|
+
return zipper.process();
|
64
|
+
}
|
65
|
+
async getPreviewImageFile(block) {
|
66
|
+
var _block$preview$src;
|
67
|
+
// For BC, we need to check 2 IDs: the preview `id` and the `id` from the file URL.
|
68
|
+
const idFromSrc = (_block$preview$src = block.preview.src) === null || _block$preview$src === void 0 ? void 0 : _block$preview$src.split("/files/")[1].split("/")[0];
|
69
|
+
const possibleIds = [block.preview.id, idFromSrc].filter(Boolean);
|
70
|
+
const [files] = await this.fileManager.listFiles({
|
71
|
+
where: {
|
72
|
+
id_in: possibleIds,
|
73
|
+
meta: {
|
74
|
+
private: true
|
75
|
+
}
|
76
|
+
}
|
77
|
+
});
|
78
|
+
return files[0];
|
79
|
+
}
|
80
|
+
}
|
81
|
+
exports.BlockExporter = BlockExporter;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_zipper","_interopRequireDefault","require","_utils","BlockExporter","constructor","fileManager","_defineProperty2","default","execute","block","blockCategory","exportBlocksDataKey","files","extractFilesFromData","content","fileIds","map","imageFile","id","imageFilesData","length","filesData","listFiles","where","id_in","push","preview","previewImage","getPreviewImageFile","blockData","name","category","slug","icon","description","blockDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","dataBuffer","archiveFileKey","process","_block$preview$src","idFromSrc","src","split","possibleIds","filter","Boolean","meta","private","exports"],"sources":["BlockExporter.ts"],"sourcesContent":["import { BlockCategory, PageBlock } from \"@webiny/api-page-builder/types\";\nimport { File, FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport Zipper from \"~/export/zipper\";\nimport { extractFilesFromData } from \"~/export/utils\";\n\nexport interface ExportedBlockData {\n block: Pick<PageBlock, \"name\" | \"content\" | \"preview\">;\n category: BlockCategory;\n files: File[];\n}\n\nexport class BlockExporter {\n private fileManager: FileManagerContext[\"fileManager\"];\n\n constructor(fileManager: FileManagerContext[\"fileManager\"]) {\n this.fileManager = fileManager;\n }\n\n async execute(block: PageBlock, blockCategory: BlockCategory, exportBlocksDataKey: string) {\n // Extract all files\n const files = extractFilesFromData(block.content || {});\n const fileIds = files.map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await this.fileManager.listFiles({ where: { id_in: fileIds } });\n imageFilesData.push(...filesData);\n }\n // Add block preview image file data\n if (block.preview.id) {\n const previewImage = await this.getPreviewImageFile(block);\n if (previewImage) {\n imageFilesData.push(previewImage);\n block.preview.id = previewImage.id;\n }\n }\n\n // Extract the block data in a json file and upload it to S3\n const blockData = {\n block: {\n name: block.name,\n content: block.content,\n preview: block.preview\n },\n category: {\n name: blockCategory.name,\n slug: blockCategory.slug,\n icon: blockCategory.icon,\n description: blockCategory.description\n },\n files: imageFilesData\n };\n const blockDataBuffer = Buffer.from(JSON.stringify(blockData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: block.name,\n dataBuffer: blockDataBuffer\n },\n archiveFileKey: exportBlocksDataKey\n });\n\n return zipper.process();\n }\n\n private async getPreviewImageFile(block: PageBlock): Promise<File | undefined> {\n // For BC, we need to check 2 IDs: the preview `id` and the `id` from the file URL.\n const idFromSrc = block.preview.src?.split(\"/files/\")[1].split(\"/\")[0];\n const possibleIds = [block.preview.id, idFromSrc].filter(Boolean);\n\n const [files] = await this.fileManager.listFiles({\n where: { id_in: possibleIds, meta: { private: true } }\n });\n\n return files[0];\n }\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAQO,MAAME,aAAa,CAAC;EAGvBC,WAAWA,CAACC,WAA8C,EAAE;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IACxD,IAAI,CAACF,WAAW,GAAGA,WAAW;EAClC;EAEA,MAAMG,OAAOA,CAACC,KAAgB,EAAEC,aAA4B,EAAEC,mBAA2B,EAAE;IACvF;IACA,MAAMC,KAAK,GAAG,IAAAC,2BAAoB,EAACJ,KAAK,CAACK,OAAO,IAAI,CAAC,CAAC,CAAC;IACvD,MAAMC,OAAO,GAAGH,KAAK,CAACI,GAAG,CAACC,SAAS,IAAIA,SAAS,CAACC,EAAE,C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jC;IACpB,CAAC,CAAC;IAEF,OAAO6B,MAAM,CAACK,OAAO,CAAC,CAAC;EAC3B;EAEA,MAAcjB,mBAAmBA,CAACnB,KAAgB,EAA6B;IAAA,IAAAqC,kBAAA;IAC3E;IACA,MAAMC,SAAS,IAAAD,kBAAA,GAAGrC,KAAK,CAACiB,OAAO,CAACsB,GAAG,cAAAF,kBAAA,uBAAjBA,kBAAA,CAAmBG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAACA,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACtE,MAAMC,WAAW,GAAG,CAACzC,KAAK,CAACiB,OAAO,CAACR,EAAE,EAAE6B,SAAS,CAAC,CAACI,MAAM,CAACC,OAAO,CAAC;IAEjE,MAAM,CAACxC,KAAK,CAAC,GAAG,MAAM,IAAI,CAACP,WAAW,CAACiB,SAAS,CAAC;MAC7CC,KAAK,EAAE;QAAEC,KAAK,EAAE0B,WAAW;QAAEG,IAAI,EAAE;UAAEC,OAAO,EAAE;QAAK;MAAE;IACzD,CAAC,CAAC;IAEF,OAAO1C,KAAK,CAAC,CAAC,CAAC;EACnB;AACJ;AAAC2C,OAAA,CAAApD,aAAA,GAAAA,aAAA"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { FbForm } from "@webiny/api-form-builder/types";
|
2
|
+
import { File } from "@webiny/api-file-manager/types";
|
3
|
+
export interface ExportedFormData {
|
4
|
+
form: Pick<FbForm, "name" | "status" | "version" | "fields" | "layout" | "settings" | "triggers">;
|
5
|
+
files: File[];
|
6
|
+
}
|
7
|
+
export declare class FormExporter {
|
8
|
+
execute(form: FbForm, exportFormsDataKey: string): Promise<import("aws-sdk/clients/s3").ManagedUpload.SendData>;
|
9
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.FormExporter = void 0;
|
8
|
+
var _zipper = _interopRequireDefault(require("../../zipper"));
|
9
|
+
class FormExporter {
|
10
|
+
async execute(form, exportFormsDataKey) {
|
11
|
+
const formData = {
|
12
|
+
form: {
|
13
|
+
name: form.name,
|
14
|
+
status: form.status,
|
15
|
+
version: form.version,
|
16
|
+
fields: form.fields,
|
17
|
+
layout: form.layout,
|
18
|
+
settings: form.settings,
|
19
|
+
triggers: form.triggers
|
20
|
+
}
|
21
|
+
};
|
22
|
+
const formDataBuffer = Buffer.from(JSON.stringify(formData));
|
23
|
+
const zipper = new _zipper.default({
|
24
|
+
exportInfo: {
|
25
|
+
files: [],
|
26
|
+
name: form.name,
|
27
|
+
dataBuffer: formDataBuffer
|
28
|
+
},
|
29
|
+
archiveFileKey: exportFormsDataKey
|
30
|
+
});
|
31
|
+
return zipper.process();
|
32
|
+
}
|
33
|
+
}
|
34
|
+
exports.FormExporter = FormExporter;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_zipper","_interopRequireDefault","require","FormExporter","execute","form","exportFormsDataKey","formData","name","status","version","fields","layout","settings","triggers","formDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","files","dataBuffer","archiveFileKey","process","exports"],"sources":["FormExporter.ts"],"sourcesContent":["import Zipper from \"~/export/zipper\";\nimport { FbForm } from \"@webiny/api-form-builder/types\";\nimport { File } from \"@webiny/api-file-manager/types\";\n\nexport interface ExportedFormData {\n form: Pick<\n FbForm,\n \"name\" | \"status\" | \"version\" | \"fields\" | \"layout\" | \"settings\" | \"triggers\"\n >;\n files: File[];\n}\n\nexport class FormExporter {\n async execute(form: FbForm, exportFormsDataKey: string) {\n const formData = {\n form: {\n name: form.name,\n status: form.status,\n version: form.version,\n fields: form.fields,\n layout: form.layout,\n settings: form.settings,\n triggers: form.triggers\n }\n };\n const formDataBuffer = Buffer.from(JSON.stringify(formData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: [],\n name: form.name,\n dataBuffer: formDataBuffer\n },\n archiveFileKey: exportFormsDataKey\n });\n\n return zipper.process();\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAYO,MAAMC,YAAY,CAAC;EACtB,MAAMC,OAAOA,CAACC,IAAY,EAAEC,kBAA0B,EAAE;IACpD,MAAMC,QAAQ,GAAG;MACbF,IAAI,EAAE;QACFG,IAAI,EAAEH,IAAI,CAACG,IAAI;QACfC,MAAM,EAAEJ,IAAI,CAACI,MAAM;QACnBC,OAAO,EAAEL,IAAI,CAACK,OAAO;QACrBC,MAAM,EAAEN,IAAI,CAACM,MAAM;QACnBC,MAAM,EAAEP,IAAI,CAACO,MAAM;QACnBC,QAAQ,EAAER,IAAI,CAACQ,QAAQ;QACvBC,QAAQ,EAAET,IAAI,CAACS;MACnB;IACJ,CAAC;IACD,MAAMC,cAAc,GAAGC,MAAM,CAACC,IAAI,CAACC,IAAI,CAACC,SAAS,CAACZ,QAAQ,CAAC,CAAC;IAE5D,MAAMa,MAAM,GAAG,IAAIC,eAAM,CAAC;MACtBC,UAAU,EAAE;QACRC,KAAK,EAAE,EAAE;QACTf,IAAI,EAAEH,IAAI,CAACG,IAAI;QACfgB,UAAU,EAAET;MAChB,CAAC;MACDU,cAAc,EAAEnB;IACpB,CAAC,CAAC;IAEF,OAAOc,MAAM,CAACM,OAAO,CAAC,CAAC;EAC3B;AACJ;AAACC,OAAA,CAAAxB,YAAA,GAAAA,YAAA"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Page } from "@webiny/api-page-builder/types";
|
2
|
+
import { File, FileManagerContext } from "@webiny/api-file-manager/types";
|
3
|
+
export interface ExportedPageData {
|
4
|
+
page: Pick<Page, "content" | "title" | "version" | "status" | "settings" | "path">;
|
5
|
+
files: File[];
|
6
|
+
}
|
7
|
+
export declare class PageExporter {
|
8
|
+
private fileManager;
|
9
|
+
constructor(fileManager: FileManagerContext["fileManager"]);
|
10
|
+
execute(page: Page, exportPagesDataKey: string): Promise<import("aws-sdk/clients/s3").ManagedUpload.SendData>;
|
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.PageExporter = void 0;
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
9
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
10
|
+
var _zipper = _interopRequireDefault(require("../../zipper"));
|
11
|
+
var _utils = require("../../utils");
|
12
|
+
class PageExporter {
|
13
|
+
constructor(fileManager) {
|
14
|
+
(0, _defineProperty2.default)(this, "fileManager", void 0);
|
15
|
+
this.fileManager = fileManager;
|
16
|
+
}
|
17
|
+
async execute(page, exportPagesDataKey) {
|
18
|
+
// Extract all files
|
19
|
+
const files = (0, _utils.extractFilesFromData)(page.content || {});
|
20
|
+
// Extract images from page settings
|
21
|
+
const pageSettingsImages = [(0, _get.default)(page, "settings.general.image"), (0, _get.default)(page, "settings.social.image")].filter(image => image && image.src);
|
22
|
+
const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);
|
23
|
+
// Get file data for all images
|
24
|
+
const imageFilesData = [];
|
25
|
+
if (fileIds.length > 0) {
|
26
|
+
const [filesData] = await this.fileManager.listFiles({
|
27
|
+
where: {
|
28
|
+
id_in: fileIds
|
29
|
+
}
|
30
|
+
});
|
31
|
+
imageFilesData.push(...filesData);
|
32
|
+
}
|
33
|
+
|
34
|
+
// Extract the page data in a json file and upload it to S3
|
35
|
+
const pageData = {
|
36
|
+
page: {
|
37
|
+
content: page.content,
|
38
|
+
title: page.title,
|
39
|
+
path: page.path,
|
40
|
+
version: page.version,
|
41
|
+
status: page.status,
|
42
|
+
settings: page.settings
|
43
|
+
},
|
44
|
+
files: imageFilesData
|
45
|
+
};
|
46
|
+
const pageDataBuffer = Buffer.from(JSON.stringify(pageData));
|
47
|
+
const zipper = new _zipper.default({
|
48
|
+
exportInfo: {
|
49
|
+
files: imageFilesData,
|
50
|
+
name: page.title,
|
51
|
+
dataBuffer: pageDataBuffer
|
52
|
+
},
|
53
|
+
archiveFileKey: exportPagesDataKey
|
54
|
+
});
|
55
|
+
return zipper.process();
|
56
|
+
}
|
57
|
+
}
|
58
|
+
exports.PageExporter = PageExporter;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_get","_interopRequireDefault","require","_zipper","_utils","PageExporter","constructor","fileManager","_defineProperty2","default","execute","page","exportPagesDataKey","files","extractFilesFromData","content","pageSettingsImages","get","filter","image","src","fileIds","map","imageFile","id","imageFilesData","length","filesData","listFiles","where","id_in","push","pageData","title","path","version","status","settings","pageDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","name","dataBuffer","archiveFileKey","process","exports"],"sources":["PageExporter.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport { Page } from \"@webiny/api-page-builder/types\";\nimport { File, FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport Zipper from \"~/export/zipper\";\nimport { extractFilesFromData } from \"~/export/utils\";\n\nexport interface ExportedPageData {\n page: Pick<Page, \"content\" | \"title\" | \"version\" | \"status\" | \"settings\" | \"path\">;\n files: File[];\n}\n\nexport class PageExporter {\n private fileManager: FileManagerContext[\"fileManager\"];\n\n constructor(fileManager: FileManagerContext[\"fileManager\"]) {\n this.fileManager = fileManager;\n }\n\n async execute(page: Page, exportPagesDataKey: string) {\n // Extract all files\n const files = extractFilesFromData(page.content || {});\n // Extract images from page settings\n const pageSettingsImages = [\n get(page, \"settings.general.image\") as unknown as File,\n get(page, \"settings.social.image\") as unknown as File\n ].filter(image => image && image.src);\n\n const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await this.fileManager.listFiles({ where: { id_in: fileIds } });\n imageFilesData.push(...filesData);\n }\n\n // Extract the page data in a json file and upload it to S3\n const pageData = {\n page: {\n content: page.content,\n title: page.title,\n path: page.path,\n version: page.version,\n status: page.status,\n settings: page.settings\n },\n files: imageFilesData\n };\n const pageDataBuffer = Buffer.from(JSON.stringify(pageData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: page.title,\n dataBuffer: pageDataBuffer\n },\n archiveFileKey: exportPagesDataKey\n });\n\n return zipper.process();\n }\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAOO,MAAMG,YAAY,CAAC;EAGtBC,WAAWA,CAACC,WAA8C,EAAE;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IACxD,IAAI,CAACF,WAAW,GAAGA,WAAW;EAClC;EAEA,MAAMG,OAAOA,CAACC,IAAU,EAAEC,kBAA0B,EAAE;IAClD;IACA,MAAMC,KAAK,GAAG,IAAAC,2BAAoB,EAACH,IAAI,CAACI,OAAO,IAAI,CAAC,CAAC,CAAC;IACtD;IACA,MAAMC,kBAAkB,GAAG,CACvB,IAAAC,YAAG,EAACN,IAAI,EAAE,wBAAwB,CAAC,EACnC,IAAAM,YAAG,EAACN,IAAI,EAAE,uBAAuB,CAAC,CACrC,CAACO,MAAM,CAACC,KAAK,IAAIA,KAAK,IAAIA,KAAK,CAACC,GAAG,CAAC;IAErC,MAAMC,OAAO,GAAG,CAAC,GAAGR,KAAK,EAAE,GAAGG,kBAAkB,CAAC,CAACM,GAAG,CAACC,SAAS,IAAIA,SAAS,CAACC,EAAE,CAAC;IAChF;IACA,MAAMC,cAAc,GAAG,EAAE;IACzB,IAAIJ,OAAO,CAACK,MAAM,GAAG,CAAC,EAAE;MACpB,MAAM,CAACC,SAAS,CAAC,GAAG,MAAM,IAAI,CAACpB,WAAW,CAACqB,SAAS,CAAC;QAAEC,KAAK,EAAE;UAAEC,KAAK,EAAET;QAAQ;MAAE,CAAC,CAAC;MACnFI,cAAc,CAACM,IAAI,CAAC,GAAGJ,SAAS,CAAC;IACrC;;IAEA;IACA,MAAMK,QAAQ,GAAG;MACbrB,IAAI,EAAE;QACFI,OAAO,EAAEJ,IAAI,CAACI,OAAO;QACrBkB,KAAK,EAAEtB,IAAI,CAACsB,KAAK;QACjBC,IAAI,EAAEvB,IAAI,CAACuB,IAAI;QACfC,OAAO,EAAExB,IAAI,CAACwB,OAAO;QACrBC,MAAM,EAAEzB,IAAI,CAACyB,MAAM;QACnBC,QAAQ,EAAE1B,IAAI,CAAC0B;MACnB,CAAC;MACDxB,KAAK,EAAEY;IACX,CAAC;IACD,MAAMa,cAAc,GAAGC,MAAM,CAACC,IAAI,CAACC,IAAI,CAACC,SAAS,CAACV,QAAQ,CAAC,CAAC;IAE5D,MAAMW,MAAM,GAAG,IAAIC,eAAM,CAAC;MACtBC,UAAU,EAAE;QACRhC,KAAK,EAAEY,cAAc;QACrBqB,IAAI,EAAEnC,IAAI,CAACsB,KAAK;QAChBc,UAAU,EAAET;MAChB,CAAC;MACDU,cAAc,EAAEpC;IACpB,CAAC,CAAC;IAEF,OAAO+B,MAAM,CAACM,OAAO,CAAC,CAAC;EAC3B;AACJ;AAACC,OAAA,CAAA7C,YAAA,GAAAA,YAAA"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { PageTemplate } from "@webiny/api-page-builder/types";
|
2
|
+
import { File, FileManagerContext } from "@webiny/api-file-manager/types";
|
3
|
+
export interface ExportedTemplateData {
|
4
|
+
template: Pick<PageTemplate, "title" | "slug" | "tags" | "description" | "content" | "layout" | "pageCategory">;
|
5
|
+
files: File[];
|
6
|
+
}
|
7
|
+
export declare class PageTemplateExporter {
|
8
|
+
private fileManager;
|
9
|
+
constructor(fileManager: FileManagerContext["fileManager"]);
|
10
|
+
execute(template: PageTemplate, exportTemplatesDataKey: string): Promise<import("aws-sdk/clients/s3").ManagedUpload.SendData>;
|
11
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.PageTemplateExporter = void 0;
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
9
|
+
var _zipper = _interopRequireDefault(require("../../zipper"));
|
10
|
+
var _utils = require("../../utils");
|
11
|
+
class PageTemplateExporter {
|
12
|
+
constructor(fileManager) {
|
13
|
+
(0, _defineProperty2.default)(this, "fileManager", void 0);
|
14
|
+
this.fileManager = fileManager;
|
15
|
+
}
|
16
|
+
async execute(template, exportTemplatesDataKey) {
|
17
|
+
// Extract all files
|
18
|
+
const files = (0, _utils.extractFilesFromData)(template.content || {});
|
19
|
+
const fileIds = files.map(imageFile => imageFile.id);
|
20
|
+
// Get file data for all images
|
21
|
+
const imageFilesData = [];
|
22
|
+
if (fileIds.length > 0) {
|
23
|
+
const [filesData] = await this.fileManager.listFiles({
|
24
|
+
where: {
|
25
|
+
id_in: fileIds
|
26
|
+
}
|
27
|
+
});
|
28
|
+
imageFilesData.push(...filesData);
|
29
|
+
}
|
30
|
+
|
31
|
+
// Extract the template data in a json file and upload it to S3
|
32
|
+
const templateData = {
|
33
|
+
template: {
|
34
|
+
title: template.title,
|
35
|
+
slug: template.slug,
|
36
|
+
tags: template.tags,
|
37
|
+
description: template.description,
|
38
|
+
content: template.content,
|
39
|
+
layout: template.layout,
|
40
|
+
pageCategory: template.pageCategory
|
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;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_zipper","_interopRequireDefault","require","_utils","PageTemplateExporter","constructor","fileManager","_defineProperty2","default","execute","template","exportTemplatesDataKey","files","extractFilesFromData","content","fileIds","map","imageFile","id","imageFilesData","length","filesData","listFiles","where","id_in","push","templateData","title","slug","tags","description","layout","pageCategory","templateDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","name","dataBuffer","archiveFileKey","process","exports"],"sources":["PageTemplateExporter.ts"],"sourcesContent":["import { PageTemplate } from \"@webiny/api-page-builder/types\";\nimport { File, FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport Zipper from \"~/export/zipper\";\nimport { extractFilesFromData } from \"~/export/utils\";\n\nexport interface ExportedTemplateData {\n template: Pick<\n PageTemplate,\n \"title\" | \"slug\" | \"tags\" | \"description\" | \"content\" | \"layout\" | \"pageCategory\"\n >;\n files: File[];\n}\n\nexport class PageTemplateExporter {\n private fileManager: FileManagerContext[\"fileManager\"];\n\n constructor(fileManager: FileManagerContext[\"fileManager\"]) {\n this.fileManager = fileManager;\n }\n\n async execute(template: PageTemplate, exportTemplatesDataKey: string) {\n // Extract all files\n const files = extractFilesFromData(template.content || {});\n const fileIds = files.map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await this.fileManager.listFiles({ where: { id_in: fileIds } });\n imageFilesData.push(...filesData);\n }\n\n // Extract the template data in a json file and upload it to S3\n const templateData = {\n template: {\n title: template.title,\n slug: template.slug,\n tags: template.tags,\n description: template.description,\n content: template.content,\n layout: template.layout,\n pageCategory: template.pageCategory\n },\n files: imageFilesData\n };\n const templateDataBuffer = Buffer.from(JSON.stringify(templateData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: template.title,\n dataBuffer: templateDataBuffer\n },\n archiveFileKey: exportTemplatesDataKey\n });\n\n return zipper.process();\n }\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAUO,MAAME,oBAAoB,CAAC;EAG9BC,WAAWA,CAACC,WAA8C,EAAE;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IACxD,IAAI,CAACF,WAAW,GAAGA,WAAW;EAClC;EAEA,MAAMG,OAAOA,CAACC,QAAsB,EAAEC,sBAA8B,EAAE;IAClE;IACA,MAAMC,KAAK,GAAG,IAAAC,2BAAoB,EAACH,QAAQ,CAACI,OAAO,IAAI,CAAC,CAAC,CAAC;IAC1D,MAAMC,OAAO,GAAGH,KAAK,CAACI,GAAG,CAACC,SAAS,IAAIA,SAAS,CAACC,EAAE,CAAC;IACpD;IACA,MAAMC,cAAc,GAAG,EAAE;IACzB,IAAIJ,OAAO,CAACK,MAAM,GAAG,CAAC,EAAE;MACpB,MAAM,CAACC,SAAS,CAAC,GAAG,MAAM,IAAI,CAACf,WAAW,CAACgB,SAAS,CAAC;QAAEC,KAAK,EAAE;UAAEC,KAAK,EAAET;QAAQ;MAAE,CAAC,CAAC;MACnFI,cAAc,CAACM,IAAI,CAAC,GAAGJ,SAAS,CAAC;IACrC;;IAEA;IACA,MAAMK,YAAY,GAAG;MACjBhB,QAAQ,EAAE;QACNiB,KAAK,EAAEjB,QAAQ,CAACiB,KAAK;QACrBC,IAAI,EAAElB,QAAQ,CAACkB,IAAI;QACnBC,IAAI,EAAEnB,QAAQ,CAACmB,IAAI;QACnBC,WAAW,EAAEpB,QAAQ,CAACoB,WAAW;QACjChB,OAAO,EAAEJ,QAAQ,CAACI,OAAO;QACzBiB,MAAM,EAAErB,QAAQ,CAACqB,MAAM;QACvBC,YAAY,EAAEtB,QAAQ,CAACsB;MAC3B,CAAC;MACDpB,KAAK,EAAEO;IACX,CAAC;IACD,MAAMc,kBAAkB,GAAGC,MAAM,CAACC,IAAI,CAACC,IAAI,CAACC,SAAS,CAACX,YAAY,CAAC,CAAC;IAEpE,MAAMY,MAAM,GAAG,IAAIC,eAAM,CAAC;MACtBC,UAAU,EAAE;QACR5B,KAAK,EAAEO,cAAc;QACrBsB,IAAI,EAAE/B,QAAQ,CAACiB,KAAK;QACpBe,UAAU,EAAET;MAChB,CAAC;MACDU,cAAc,EAAEhC;IACpB,CAAC,CAAC;IAEF,OAAO2B,MAAM,CAACM,OAAO,CAAC,CAAC;EAC3B;AACJ;AAACC,OAAA,CAAAzC,oBAAA,GAAAA,oBAAA"}
|
@@ -0,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>;
|