@webiny/api-page-builder-import-export 5.33.5 → 5.34.0-beta.0
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 +4 -10
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.d.ts +6 -0
- package/export/combine/blocksHandler.js +106 -0
- package/export/combine/blocksHandler.js.map +1 -0
- package/{exportPages → export}/combine/index.d.ts +3 -2
- package/export/combine/index.js +30 -0
- package/export/combine/index.js.map +1 -0
- package/export/combine/pagesHandler.d.ts +6 -0
- package/export/combine/pagesHandler.js +106 -0
- package/export/combine/pagesHandler.js.map +1 -0
- package/export/process/blocksHandler.d.ts +6 -0
- package/export/process/blocksHandler.js +176 -0
- package/export/process/blocksHandler.js.map +1 -0
- package/{exportPages → export}/process/index.d.ts +4 -6
- package/export/process/index.js +27 -0
- package/export/process/index.js.map +1 -0
- package/export/process/pagesHandler.d.ts +6 -0
- package/export/process/pagesHandler.js +204 -0
- package/export/process/pagesHandler.js.map +1 -0
- package/{exportPages → export}/s3Stream.d.ts +0 -0
- package/{exportPages → export}/s3Stream.js +4 -6
- package/{exportPages → export}/s3Stream.js.map +1 -1
- package/export/utils.d.ts +16 -0
- package/export/utils.js +135 -0
- package/export/utils.js.map +1 -0
- package/{exportPages → export}/zipper.d.ts +6 -5
- package/{exportPages → export}/zipper.js +11 -12
- package/export/zipper.js.map +1 -0
- package/graphql/crud/blocks.crud.d.ts +4 -0
- package/graphql/crud/blocks.crud.js +155 -0
- package/graphql/crud/blocks.crud.js.map +1 -0
- package/graphql/crud/importExportTasks.crud.d.ts +5 -0
- package/graphql/crud/{pageImportExportTasks.crud.js → importExportTasks.crud.js} +64 -57
- package/graphql/crud/importExportTasks.crud.js.map +1 -0
- package/graphql/crud/pages.crud.d.ts +2 -2
- package/graphql/crud/pages.crud.js +15 -13
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js +5 -3
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.d.ts +4 -0
- package/graphql/graphql/blocks.gql.js +57 -0
- package/graphql/graphql/blocks.gql.js.map +1 -0
- package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
- package/graphql/graphql/{pageImportExportTasks.gql.js → importExportTasks.gql.js} +18 -18
- 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/utils/resolve.d.ts +1 -1
- package/graphql/graphql.js +5 -3
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +1 -1
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +43 -23
- package/graphql/types.js.map +1 -1
- package/import/create/blocksHandler.d.ts +3 -0
- package/import/create/blocksHandler.js +110 -0
- package/import/create/blocksHandler.js.map +1 -0
- package/{importPages → import}/create/index.d.ts +5 -4
- package/import/create/index.js +30 -0
- package/import/create/index.js.map +1 -0
- package/import/create/pagesHandler.d.ts +3 -0
- package/import/create/pagesHandler.js +110 -0
- package/import/create/pagesHandler.js.map +1 -0
- package/import/process/blocksHandler.d.ts +3 -0
- package/import/process/blocksHandler.js +175 -0
- package/import/process/blocksHandler.js.map +1 -0
- package/{importPages → import}/process/index.d.ts +4 -3
- package/import/process/index.js +27 -0
- package/import/process/index.js.map +1 -0
- package/import/process/pagesHandler.d.ts +3 -0
- package/import/process/pagesHandler.js +180 -0
- package/import/process/pagesHandler.js.map +1 -0
- package/{importPages → import}/utils.d.ts +19 -20
- package/{importPages → import}/utils.js +108 -37
- package/import/utils.js.map +1 -0
- package/package.json +27 -27
- package/types.d.ts +62 -65
- package/types.js +17 -17
- package/types.js.map +1 -1
- package/exportPages/combine/index.js +0 -114
- package/exportPages/combine/index.js.map +0 -1
- package/exportPages/process/index.js +0 -208
- package/exportPages/process/index.js.map +0 -1
- package/exportPages/utils.d.ts +0 -13
- package/exportPages/utils.js +0 -113
- 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 -118
- package/importPages/create/index.js.map +0 -1
- package/importPages/process/index.js +0 -185
- package/importPages/process/index.js.map +0 -1
- package/importPages/utils.js.map +0 -1
package/client.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { PbImportExportContext } from "./graphql/types";
|
2
2
|
export interface InvokeHandlerClientParams<TParams> {
|
3
|
-
context:
|
3
|
+
context: PbImportExportContext;
|
4
4
|
name: string;
|
5
5
|
payload: TParams;
|
6
6
|
description: string;
|
package/client.js
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
4
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
6
6
|
value: true
|
7
7
|
});
|
8
8
|
exports.invokeHandlerClient = invokeHandlerClient;
|
9
9
|
|
10
|
-
var
|
11
|
-
|
12
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
13
|
-
|
14
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
15
11
|
|
16
12
|
async function invokeHandlerClient({
|
17
13
|
context,
|
@@ -27,11 +23,9 @@ async function invokeHandlerClient({
|
|
27
23
|
request
|
28
24
|
} = context;
|
29
25
|
const tenantId = context.tenancy.getCurrentTenant().id;
|
30
|
-
|
31
|
-
const headers = _objectSpread(_objectSpread({}, request.headers), {}, {
|
26
|
+
const headers = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, request.headers), {}, {
|
32
27
|
["x-tenant"]: request.headers["x-tenant"] || tenantId
|
33
28
|
});
|
34
|
-
|
35
29
|
delete headers["content-length"];
|
36
30
|
const invocationArgs = {
|
37
31
|
httpMethod: request.method,
|
@@ -46,7 +40,7 @@ async function invokeHandlerClient({
|
|
46
40
|
|
47
41
|
await context.handlerClient.invoke({
|
48
42
|
name: name,
|
49
|
-
payload:
|
43
|
+
payload: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, payload), invocationArgs),
|
50
44
|
await: false,
|
51
45
|
description
|
52
46
|
});
|
package/client.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["invokeHandlerClient","context","name","payload","description","request","tenantId","tenancy","getCurrentTenant","id","headers","invocationArgs","httpMethod","method","body","cookies","handlerClient","invoke","await"],"sources":["client.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"names":["invokeHandlerClient","context","name","payload","description","request","tenantId","tenancy","getCurrentTenant","id","headers","invocationArgs","httpMethod","method","body","cookies","handlerClient","invoke","await"],"sources":["client.ts"],"sourcesContent":["import { PbImportExportContext } from \"~/graphql/types\";\n\nexport interface InvokeHandlerClientParams<TParams> {\n context: PbImportExportContext;\n name: string;\n payload: TParams;\n description: string;\n}\n\nexport async function invokeHandlerClient<TParams>({\n context,\n name,\n payload,\n description\n}: InvokeHandlerClientParams<TParams>) {\n /*\n * Prepare \"invocationArgs\", we're hacking our wat here.\n * They are necessary to setup the \"context.pageBuilder\" object among other things in IMPORT_PAGE_FUNCTION\n */\n const { request } = context;\n\n const tenantId = context.tenancy.getCurrentTenant().id;\n\n const headers = {\n ...request.headers,\n [\"x-tenant\"]: request.headers[\"x-tenant\"] || tenantId\n };\n delete headers[\"content-length\"];\n const invocationArgs = {\n httpMethod: request.method,\n body: request.body,\n headers,\n /**\n * Required until type augmentation works correctly.\n */\n cookies: (request as any).cookies\n };\n // Invoke handler\n await context.handlerClient.invoke<TParams & any>({\n name: name,\n payload: {\n ...payload,\n ...invocationArgs\n },\n await: false,\n description\n });\n}\n"],"mappings":";;;;;;;;;;;AASO,eAAeA,mBAAf,CAA4C;EAC/CC,OAD+C;EAE/CC,IAF+C;EAG/CC,OAH+C;EAI/CC;AAJ+C,CAA5C,EAKgC;EACnC;AACJ;AACA;AACA;EACI,MAAM;IAAEC;EAAF,IAAcJ,OAApB;EAEA,MAAMK,QAAQ,GAAGL,OAAO,CAACM,OAAR,CAAgBC,gBAAhB,GAAmCC,EAApD;EAEA,MAAMC,OAAO,+DACNL,OAAO,CAACK,OADF;IAET,CAAC,UAAD,GAAcL,OAAO,CAACK,OAAR,CAAgB,UAAhB,KAA+BJ;EAFpC,EAAb;EAIA,OAAOI,OAAO,CAAC,gBAAD,CAAd;EACA,MAAMC,cAAc,GAAG;IACnBC,UAAU,EAAEP,OAAO,CAACQ,MADD;IAEnBC,IAAI,EAAET,OAAO,CAACS,IAFK;IAGnBJ,OAHmB;;IAInB;AACR;AACA;IACQK,OAAO,EAAGV,OAAD,CAAiBU;EAPP,CAAvB,CAdmC,CAuBnC;;EACA,MAAMd,OAAO,CAACe,aAAR,CAAsBC,MAAtB,CAA4C;IAC9Cf,IAAI,EAAEA,IADwC;IAE9CC,OAAO,8DACAA,OADA,GAEAQ,cAFA,CAFuC;IAM9CO,KAAK,EAAE,KANuC;IAO9Cd;EAP8C,CAA5C,CAAN;AASH"}
|
@@ -0,0 +1,106 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.blocksHandler = void 0;
|
7
|
+
|
8
|
+
var _types = require("../../types");
|
9
|
+
|
10
|
+
var _s3Stream = require("../s3Stream");
|
11
|
+
|
12
|
+
var _zipper = require("../zipper");
|
13
|
+
|
14
|
+
var _mockSecurity = require("../../mockSecurity");
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Handles the export blocks combine workflow.
|
18
|
+
*/
|
19
|
+
const blocksHandler = async (payload, context) => {
|
20
|
+
const log = console.log;
|
21
|
+
log("RUNNING Export Blocks Combine Handler");
|
22
|
+
const {
|
23
|
+
pageBuilder
|
24
|
+
} = context;
|
25
|
+
const {
|
26
|
+
taskId,
|
27
|
+
identity
|
28
|
+
} = payload;
|
29
|
+
(0, _mockSecurity.mockSecurity)(identity, context);
|
30
|
+
|
31
|
+
try {
|
32
|
+
const task = await pageBuilder.importExportTask.getTask(taskId);
|
33
|
+
|
34
|
+
if (!task) {
|
35
|
+
return {
|
36
|
+
data: null,
|
37
|
+
error: {
|
38
|
+
message: `There is no task with ID "${taskId}".`
|
39
|
+
}
|
40
|
+
};
|
41
|
+
}
|
42
|
+
|
43
|
+
const {
|
44
|
+
exportBlocksDataKey
|
45
|
+
} = task.input; // Get all files (zip) from given key
|
46
|
+
|
47
|
+
const listObjectResponse = await _s3Stream.s3Stream.listObject(exportBlocksDataKey);
|
48
|
+
|
49
|
+
if (!listObjectResponse.Contents) {
|
50
|
+
return {
|
51
|
+
data: null,
|
52
|
+
error: {
|
53
|
+
message: "There is no Contents defined on S3 Stream while combining blocks."
|
54
|
+
}
|
55
|
+
};
|
56
|
+
}
|
57
|
+
|
58
|
+
const zipFileKeys = listObjectResponse.Contents.filter(file => file.Key !== exportBlocksDataKey).map(file => file.Key).filter(Boolean); // Prepare zip of all zips
|
59
|
+
|
60
|
+
const zipOfZip = new _zipper.ZipOfZip(zipFileKeys, "WEBINY_BLOCK_EXPORT.zip"); // Upload
|
61
|
+
|
62
|
+
const blockExportUpload = await zipOfZip.process();
|
63
|
+
log(`Done uploading... File is located at ${blockExportUpload.Location} `); // Update task status and save export blocks data key
|
64
|
+
|
65
|
+
await pageBuilder.importExportTask.updateTask(taskId, {
|
66
|
+
status: _types.ImportExportTaskStatus.COMPLETED,
|
67
|
+
data: {
|
68
|
+
message: `Finish uploading block export.`,
|
69
|
+
key: blockExportUpload.Key,
|
70
|
+
url: _s3Stream.s3Stream.getPresignedUrl(blockExportUpload.Key)
|
71
|
+
}
|
72
|
+
}); // Remove individual zip files from storage
|
73
|
+
|
74
|
+
const deleteFilePromises = zipFileKeys.map(key => _s3Stream.s3Stream.deleteObject(key));
|
75
|
+
await Promise.all(deleteFilePromises);
|
76
|
+
log(`Successfully deleted ${deleteFilePromises.length} zip files.`);
|
77
|
+
} catch (e) {
|
78
|
+
log("[EXPORT_BLOCKS_COMBINE] Error => ", e.message);
|
79
|
+
/**
|
80
|
+
* In case of error, we'll update the task status to "failed",
|
81
|
+
* so that, client can show notify the user appropriately.
|
82
|
+
*/
|
83
|
+
|
84
|
+
await pageBuilder.importExportTask.updateTask(taskId, {
|
85
|
+
status: _types.ImportExportTaskStatus.FAILED,
|
86
|
+
error: {
|
87
|
+
name: e.name,
|
88
|
+
message: e.message,
|
89
|
+
code: "EXPORT_FAILED"
|
90
|
+
}
|
91
|
+
});
|
92
|
+
return {
|
93
|
+
data: null,
|
94
|
+
error: {
|
95
|
+
message: e.message
|
96
|
+
}
|
97
|
+
};
|
98
|
+
}
|
99
|
+
|
100
|
+
return {
|
101
|
+
data: "",
|
102
|
+
error: null
|
103
|
+
};
|
104
|
+
};
|
105
|
+
|
106
|
+
exports.blocksHandler = blocksHandler;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["blocksHandler","payload","context","log","console","pageBuilder","taskId","identity","mockSecurity","task","importExportTask","getTask","data","error","message","exportBlocksDataKey","input","listObjectResponse","s3Stream","listObject","Contents","zipFileKeys","filter","file","Key","map","Boolean","zipOfZip","ZipOfZip","blockExportUpload","process","Location","updateTask","status","ImportExportTaskStatus","COMPLETED","key","url","getPresignedUrl","deleteFilePromises","deleteObject","Promise","all","length","e","FAILED","name","code"],"sources":["blocksHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { s3Stream } from \"../s3Stream\";\nimport { ZipOfZip } from \"../zipper\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { Payload, Response } from \"~/export/combine\";\n\n/**\n * Handles the export blocks combine workflow.\n */\nexport const blocksHandler = async (\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n\n log(\"RUNNING Export Blocks Combine Handler\");\n const { pageBuilder } = context;\n const { taskId, identity } = payload;\n\n mockSecurity(identity, context);\n\n try {\n const task = await pageBuilder.importExportTask.getTask(taskId);\n if (!task) {\n return {\n data: null,\n error: {\n message: `There is no task with ID \"${taskId}\".`\n }\n };\n }\n\n const { exportBlocksDataKey } = task.input;\n\n // Get all files (zip) from given key\n const listObjectResponse = await s3Stream.listObject(exportBlocksDataKey);\n if (!listObjectResponse.Contents) {\n return {\n data: null,\n error: {\n message: \"There is no Contents defined on S3 Stream while combining blocks.\"\n }\n };\n }\n\n const zipFileKeys = listObjectResponse.Contents.filter(\n file => file.Key !== exportBlocksDataKey\n )\n .map(file => file.Key)\n .filter(Boolean) as string[];\n\n // Prepare zip of all zips\n const zipOfZip = new ZipOfZip(zipFileKeys, \"WEBINY_BLOCK_EXPORT.zip\");\n\n // Upload\n const blockExportUpload = await zipOfZip.process();\n log(`Done uploading... File is located at ${blockExportUpload.Location} `);\n\n // Update task status and save export blocks data key\n await pageBuilder.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading block export.`,\n key: blockExportUpload.Key,\n url: s3Stream.getPresignedUrl(blockExportUpload.Key)\n }\n });\n\n // Remove individual zip files from storage\n const deleteFilePromises = zipFileKeys.map(key => s3Stream.deleteObject(key));\n await Promise.all(deleteFilePromises);\n log(`Successfully deleted ${deleteFilePromises.length} zip files.`);\n } catch (e) {\n log(\"[EXPORT_BLOCKS_COMBINE] Error => \", e.message);\n\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 await pageBuilder.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n code: \"EXPORT_FAILED\"\n }\n });\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n }\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAGA;AACA;AACA;AACO,MAAMA,aAAa,GAAG,OACzBC,OADyB,EAEzBC,OAFyB,KAGL;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAApB;EAEAA,GAAG,CAAC,uCAAD,CAAH;EACA,MAAM;IAAEE;EAAF,IAAkBH,OAAxB;EACA,MAAM;IAAEI,MAAF;IAAUC;EAAV,IAAuBN,OAA7B;EAEA,IAAAO,0BAAA,EAAaD,QAAb,EAAuBL,OAAvB;;EAEA,IAAI;IACA,MAAMO,IAAI,GAAG,MAAMJ,WAAW,CAACK,gBAAZ,CAA6BC,OAA7B,CAAqCL,MAArC,CAAnB;;IACA,IAAI,CAACG,IAAL,EAAW;MACP,OAAO;QACHG,IAAI,EAAE,IADH;QAEHC,KAAK,EAAE;UACHC,OAAO,EAAG,6BAA4BR,MAAO;QAD1C;MAFJ,CAAP;IAMH;;IAED,MAAM;MAAES;IAAF,IAA0BN,IAAI,CAACO,KAArC,CAXA,CAaA;;IACA,MAAMC,kBAAkB,GAAG,MAAMC,kBAAA,CAASC,UAAT,CAAoBJ,mBAApB,CAAjC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,CAAC9B,OAAxC,CAAH;IAEA;AACR;AACA;AACA;;IACQ,MAAMT,WAAW,CAACK,gBAAZ,CAA6BsB,UAA7B,CAAwC1B,MAAxC,EAAgD;MAClD2B,MAAM,EAAEC,6BAAA,CAAuBW,MADmB;MAElDhC,KAAK,EAAE;QACHiC,IAAI,EAAEF,CAAC,CAACE,IADL;QAEHhC,OAAO,EAAE8B,CAAC,CAAC9B,OAFR;QAGHiC,IAAI,EAAE;MAHH;IAF2C,CAAhD,CAAN;IASA,OAAO;MACHnC,IAAI,EAAE,IADH;MAEHC,KAAK,EAAE;QACHC,OAAO,EAAE8B,CAAC,CAAC9B;MADR;IAFJ,CAAP;EAMH;;EACD,OAAO;IACHF,IAAI,EAAE,EADH;IAEHC,KAAK,EAAE;EAFJ,CAAP;AAIH,CA1FM"}
|
@@ -1,7 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { PbImportExportContext } from "../../types";
|
2
2
|
import { SecurityIdentity } from "@webiny/api-security/types";
|
3
3
|
export interface Payload {
|
4
4
|
taskId: string;
|
5
|
+
type: string;
|
5
6
|
identity: SecurityIdentity;
|
6
7
|
}
|
7
8
|
export interface Response {
|
@@ -11,5 +12,5 @@ export interface Response {
|
|
11
12
|
/**
|
12
13
|
* Handles the export pages combine workflow.
|
13
14
|
*/
|
14
|
-
declare const _default: () => import("@webiny/handler-aws").RawEventHandler<Payload,
|
15
|
+
declare const _default: () => import("@webiny/handler-aws").RawEventHandler<Payload, PbImportExportContext, Response>;
|
15
16
|
export default _default;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _handlerAws = require("@webiny/handler-aws");
|
9
|
+
|
10
|
+
var _blocksHandler = require("./blocksHandler");
|
11
|
+
|
12
|
+
var _pagesHandler = require("./pagesHandler");
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Handles the export pages combine workflow.
|
16
|
+
*/
|
17
|
+
var _default = () => {
|
18
|
+
return (0, _handlerAws.createRawEventHandler)(async ({
|
19
|
+
payload,
|
20
|
+
context
|
21
|
+
}) => {
|
22
|
+
if (payload.type === "block") {
|
23
|
+
return await (0, _blocksHandler.blocksHandler)(payload, context);
|
24
|
+
} else {
|
25
|
+
return await (0, _pagesHandler.pagesHandler)(payload, context);
|
26
|
+
}
|
27
|
+
});
|
28
|
+
};
|
29
|
+
|
30
|
+
exports.default = _default;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["createRawEventHandler","payload","context","type","blocksHandler","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/combine/blocksHandler\";\nimport { pagesHandler } from \"~/export/combine/pagesHandler\";\n\nexport interface Payload {\n taskId: string;\n type: string;\n identity: SecurityIdentity;\n}\n\nexport interface Response {\n data: string | null;\n error: Partial<Error> | null;\n}\n\n/**\n * Handles the export pages combine workflow.\n */\nexport default () => {\n return createRawEventHandler<Payload, PbImportExportContext, Response>(\n async ({ payload, context }) => {\n if (payload.type === \"block\") {\n return await blocksHandler(payload, context);\n } else {\n return await pagesHandler(payload, context);\n }\n }\n );\n};\n"],"mappings":";;;;;;;AAEA;;AACA;;AACA;;AAaA;AACA;AACA;eACe,MAAM;EACjB,OAAO,IAAAA,iCAAA,EACH,OAAO;IAAEC,OAAF;IAAWC;EAAX,CAAP,KAAgC;IAC5B,IAAID,OAAO,CAACE,IAAR,KAAiB,OAArB,EAA8B;MAC1B,OAAO,MAAM,IAAAC,4BAAA,EAAcH,OAAd,EAAuBC,OAAvB,CAAb;IACH,CAFD,MAEO;MACH,OAAO,MAAM,IAAAG,0BAAA,EAAaJ,OAAb,EAAsBC,OAAtB,CAAb;IACH;EACJ,CAPE,CAAP;AASH,C"}
|
@@ -0,0 +1,106 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.pagesHandler = void 0;
|
7
|
+
|
8
|
+
var _types = require("../../types");
|
9
|
+
|
10
|
+
var _s3Stream = require("../s3Stream");
|
11
|
+
|
12
|
+
var _zipper = require("../zipper");
|
13
|
+
|
14
|
+
var _mockSecurity = require("../../mockSecurity");
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Handles the export pages combine workflow.
|
18
|
+
*/
|
19
|
+
const pagesHandler = async (payload, context) => {
|
20
|
+
const log = console.log;
|
21
|
+
log("RUNNING Export Pages Combine Handler");
|
22
|
+
const {
|
23
|
+
pageBuilder
|
24
|
+
} = context;
|
25
|
+
const {
|
26
|
+
taskId,
|
27
|
+
identity
|
28
|
+
} = payload;
|
29
|
+
(0, _mockSecurity.mockSecurity)(identity, context);
|
30
|
+
|
31
|
+
try {
|
32
|
+
const task = await pageBuilder.importExportTask.getTask(taskId);
|
33
|
+
|
34
|
+
if (!task) {
|
35
|
+
return {
|
36
|
+
data: null,
|
37
|
+
error: {
|
38
|
+
message: `There is no task with ID "${taskId}".`
|
39
|
+
}
|
40
|
+
};
|
41
|
+
}
|
42
|
+
|
43
|
+
const {
|
44
|
+
exportPagesDataKey
|
45
|
+
} = task.input; // Get all files (zip) from given key
|
46
|
+
|
47
|
+
const listObjectResponse = await _s3Stream.s3Stream.listObject(exportPagesDataKey);
|
48
|
+
|
49
|
+
if (!listObjectResponse.Contents) {
|
50
|
+
return {
|
51
|
+
data: null,
|
52
|
+
error: {
|
53
|
+
message: "There is no Contents defined on S3 Stream while combining pages."
|
54
|
+
}
|
55
|
+
};
|
56
|
+
}
|
57
|
+
|
58
|
+
const zipFileKeys = listObjectResponse.Contents.filter(file => file.Key !== exportPagesDataKey).map(file => file.Key).filter(Boolean); // Prepare zip of all zips
|
59
|
+
|
60
|
+
const zipOfZip = new _zipper.ZipOfZip(zipFileKeys, "WEBINY_PAGE_EXPORT.zip"); // Upload
|
61
|
+
|
62
|
+
const pageExportUpload = await zipOfZip.process();
|
63
|
+
log(`Done uploading... File is located at ${pageExportUpload.Location} `); // Update task status and save export page data key
|
64
|
+
|
65
|
+
await pageBuilder.importExportTask.updateTask(taskId, {
|
66
|
+
status: _types.ImportExportTaskStatus.COMPLETED,
|
67
|
+
data: {
|
68
|
+
message: `Finish uploading page export.`,
|
69
|
+
key: pageExportUpload.Key,
|
70
|
+
url: _s3Stream.s3Stream.getPresignedUrl(pageExportUpload.Key)
|
71
|
+
}
|
72
|
+
}); // Remove individual zip files from storage
|
73
|
+
|
74
|
+
const deleteFilePromises = zipFileKeys.map(key => _s3Stream.s3Stream.deleteObject(key));
|
75
|
+
await Promise.all(deleteFilePromises);
|
76
|
+
log(`Successfully deleted ${deleteFilePromises.length} zip files.`);
|
77
|
+
} catch (e) {
|
78
|
+
log("[EXPORT_PAGES_COMBINE] Error => ", e.message);
|
79
|
+
/**
|
80
|
+
* In case of error, we'll update the task status to "failed",
|
81
|
+
* so that, client can show notify the user appropriately.
|
82
|
+
*/
|
83
|
+
|
84
|
+
await pageBuilder.importExportTask.updateTask(taskId, {
|
85
|
+
status: _types.ImportExportTaskStatus.FAILED,
|
86
|
+
error: {
|
87
|
+
name: e.name,
|
88
|
+
message: e.message,
|
89
|
+
code: "EXPORT_FAILED"
|
90
|
+
}
|
91
|
+
});
|
92
|
+
return {
|
93
|
+
data: null,
|
94
|
+
error: {
|
95
|
+
message: e.message
|
96
|
+
}
|
97
|
+
};
|
98
|
+
}
|
99
|
+
|
100
|
+
return {
|
101
|
+
data: "",
|
102
|
+
error: null
|
103
|
+
};
|
104
|
+
};
|
105
|
+
|
106
|
+
exports.pagesHandler = pagesHandler;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["pagesHandler","payload","context","log","console","pageBuilder","taskId","identity","mockSecurity","task","importExportTask","getTask","data","error","message","exportPagesDataKey","input","listObjectResponse","s3Stream","listObject","Contents","zipFileKeys","filter","file","Key","map","Boolean","zipOfZip","ZipOfZip","pageExportUpload","process","Location","updateTask","status","ImportExportTaskStatus","COMPLETED","key","url","getPresignedUrl","deleteFilePromises","deleteObject","Promise","all","length","e","FAILED","name","code"],"sources":["pagesHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { s3Stream } from \"../s3Stream\";\nimport { ZipOfZip } from \"../zipper\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { Payload, Response } from \"~/export/combine\";\n\n/**\n * Handles the export pages combine workflow.\n */\nexport const pagesHandler = async (\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n\n log(\"RUNNING Export Pages Combine Handler\");\n const { pageBuilder } = context;\n const { taskId, identity } = payload;\n\n mockSecurity(identity, context);\n\n try {\n const task = await pageBuilder.importExportTask.getTask(taskId);\n if (!task) {\n return {\n data: null,\n error: {\n message: `There is no task with ID \"${taskId}\".`\n }\n };\n }\n\n const { exportPagesDataKey } = task.input;\n\n // Get all files (zip) from given key\n const listObjectResponse = await s3Stream.listObject(exportPagesDataKey);\n if (!listObjectResponse.Contents) {\n return {\n data: null,\n error: {\n message: \"There is no Contents defined on S3 Stream while combining pages.\"\n }\n };\n }\n\n const zipFileKeys = listObjectResponse.Contents.filter(\n file => file.Key !== exportPagesDataKey\n )\n .map(file => file.Key)\n .filter(Boolean) as string[];\n\n // Prepare zip of all zips\n const zipOfZip = new ZipOfZip(zipFileKeys, \"WEBINY_PAGE_EXPORT.zip\");\n\n // Upload\n const pageExportUpload = await zipOfZip.process();\n log(`Done uploading... File is located at ${pageExportUpload.Location} `);\n\n // Update task status and save export page data key\n await pageBuilder.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading page export.`,\n key: pageExportUpload.Key,\n url: s3Stream.getPresignedUrl(pageExportUpload.Key)\n }\n });\n\n // Remove individual zip files from storage\n const deleteFilePromises = zipFileKeys.map(key => s3Stream.deleteObject(key));\n await Promise.all(deleteFilePromises);\n log(`Successfully deleted ${deleteFilePromises.length} zip files.`);\n } catch (e) {\n log(\"[EXPORT_PAGES_COMBINE] Error => \", e.message);\n\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 await pageBuilder.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n code: \"EXPORT_FAILED\"\n }\n });\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n }\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAGA;AACA;AACA;AACO,MAAMA,YAAY,GAAG,OACxBC,OADwB,EAExBC,OAFwB,KAGJ;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAApB;EAEAA,GAAG,CAAC,sCAAD,CAAH;EACA,MAAM;IAAEE;EAAF,IAAkBH,OAAxB;EACA,MAAM;IAAEI,MAAF;IAAUC;EAAV,IAAuBN,OAA7B;EAEA,IAAAO,0BAAA,EAAaD,QAAb,EAAuBL,OAAvB;;EAEA,IAAI;IACA,MAAMO,IAAI,GAAG,MAAMJ,WAAW,CAACK,gBAAZ,CAA6BC,OAA7B,CAAqCL,MAArC,CAAnB;;IACA,IAAI,CAACG,IAAL,EAAW;MACP,OAAO;QACHG,IAAI,EAAE,IADH;QAEHC,KAAK,EAAE;UACHC,OAAO,EAAG,6BAA4BR,MAAO;QAD1C;MAFJ,CAAP;IAMH;;IAED,MAAM;MAAES;IAAF,IAAyBN,IAAI,CAACO,KAApC,CAXA,CAaA;;IACA,MAAMC,kBAAkB,GAAG,MAAMC,kBAAA,CAASC,UAAT,CAAoBJ,kBAApB,CAAjC;;IACA,IAAI,CAACE,kBAAkB,CAACG,QAAxB,EAAkC;MAC9B,OAAO;QACHR,IAAI,EAAE,IADH;QAEHC,KAAK,EAAE;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B,MAAxC,EAAgD;MAClD2B,MAAM,EAAEC,6BAAA,CAAuBW,MADmB;MAElDhC,KAAK,EAAE;QACHiC,IAAI,EAAEF,CAAC,CAACE,IADL;QAEHhC,OAAO,EAAE8B,CAAC,CAAC9B,OAFR;QAGHiC,IAAI,EAAE;MAHH;IAF2C,CAAhD,CAAN;IASA,OAAO;MACHnC,IAAI,EAAE,IADH;MAEHC,KAAK,EAAE;QACHC,OAAO,EAAE8B,CAAC,CAAC9B;MADR;IAFJ,CAAP;EAMH;;EACD,OAAO;IACHF,IAAI,EAAE,EADH;IAEHC,KAAK,EAAE;EAFJ,CAAP;AAIH,CA1FM"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { PbImportExportContext } from "../../types";
|
2
|
+
import { Configuration, Payload, Response } from ".";
|
3
|
+
/**
|
4
|
+
* Handles the export blocks process workflow.
|
5
|
+
*/
|
6
|
+
export declare const blocksHandler: (configuration: Configuration, payload: Payload, context: PbImportExportContext) => Promise<Response>;
|
@@ -0,0 +1,176 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.blocksHandler = void 0;
|
7
|
+
|
8
|
+
var _types = require("../../types");
|
9
|
+
|
10
|
+
var _client = require("../../client");
|
11
|
+
|
12
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
13
|
+
|
14
|
+
var _utils = require("../utils");
|
15
|
+
|
16
|
+
var _mockSecurity = require("../../mockSecurity");
|
17
|
+
|
18
|
+
var _utils2 = require("@webiny/utils");
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Handles the export blocks process workflow.
|
22
|
+
*/
|
23
|
+
const blocksHandler = async (configuration, payload, context) => {
|
24
|
+
const log = console.log;
|
25
|
+
let subTask;
|
26
|
+
let noPendingTask = true;
|
27
|
+
let prevStatusOfSubTask = _types.ImportExportTaskStatus.PENDING;
|
28
|
+
log("RUNNING Export Blocks Process Handler");
|
29
|
+
const {
|
30
|
+
pageBuilder,
|
31
|
+
fileManager
|
32
|
+
} = context;
|
33
|
+
const {
|
34
|
+
taskId,
|
35
|
+
subTaskIndex,
|
36
|
+
type,
|
37
|
+
identity
|
38
|
+
} = payload; // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks
|
39
|
+
// and this Lambda is invoked internally, without credentials.
|
40
|
+
|
41
|
+
(0, _mockSecurity.mockSecurity)(identity, context);
|
42
|
+
|
43
|
+
try {
|
44
|
+
/*
|
45
|
+
* Note: We're not going to DB for finding the next sub-task to process,
|
46
|
+
* because the data might be out of sync due to GSI eventual consistency.
|
47
|
+
*/
|
48
|
+
subTask = await pageBuilder.importExportTask.getSubTask(taskId, (0, _utils2.zeroPad)(subTaskIndex, 5));
|
49
|
+
/**
|
50
|
+
* Base condition!!
|
51
|
+
* Bail out early, if task not found or task's status is not "pending".
|
52
|
+
*/
|
53
|
+
|
54
|
+
if (!subTask || subTask.status !== _types.ImportExportTaskStatus.PENDING) {
|
55
|
+
noPendingTask = true;
|
56
|
+
return {
|
57
|
+
data: "",
|
58
|
+
error: null
|
59
|
+
};
|
60
|
+
} else {
|
61
|
+
noPendingTask = false;
|
62
|
+
}
|
63
|
+
|
64
|
+
log(`Fetched sub task => ${subTask.id}`);
|
65
|
+
const {
|
66
|
+
input
|
67
|
+
} = subTask;
|
68
|
+
const {
|
69
|
+
blockId,
|
70
|
+
exportBlocksDataKey
|
71
|
+
} = input;
|
72
|
+
const block = await pageBuilder.getPageBlock(blockId);
|
73
|
+
|
74
|
+
if (!block) {
|
75
|
+
log(`Unable to load block "${blockId}"`);
|
76
|
+
throw new _handlerGraphql.NotFoundError(`Unable to load block "${blockId}"`);
|
77
|
+
}
|
78
|
+
|
79
|
+
log(`Processing block key "${blockId}"`); // Mark task status as PROCESSING
|
80
|
+
|
81
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
82
|
+
status: _types.ImportExportTaskStatus.PROCESSING
|
83
|
+
}); // Update stats in main task
|
84
|
+
|
85
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
86
|
+
prevStatus: prevStatusOfSubTask,
|
87
|
+
nextStatus: _types.ImportExportTaskStatus.PROCESSING
|
88
|
+
});
|
89
|
+
prevStatusOfSubTask = subTask.status;
|
90
|
+
log(`Extracting block data and uploading to storage...`); // Extract Block
|
91
|
+
|
92
|
+
const blockDataZip = await (0, _utils.exportBlock)(block, exportBlocksDataKey, fileManager);
|
93
|
+
log(`Finish uploading zip...`); // Update task record in DB
|
94
|
+
|
95
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
96
|
+
status: _types.ImportExportTaskStatus.COMPLETED,
|
97
|
+
data: {
|
98
|
+
message: `Finish uploading data for block "${block.id}"`,
|
99
|
+
key: blockDataZip.Key
|
100
|
+
}
|
101
|
+
}); // Update stats in main task
|
102
|
+
|
103
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
104
|
+
prevStatus: prevStatusOfSubTask,
|
105
|
+
nextStatus: _types.ImportExportTaskStatus.COMPLETED
|
106
|
+
});
|
107
|
+
prevStatusOfSubTask = subTask.status;
|
108
|
+
} catch (e) {
|
109
|
+
log("[EXPORT_BLOCKS_PROCESS] Error => ", e.message);
|
110
|
+
|
111
|
+
if (subTask && subTask.id) {
|
112
|
+
/**
|
113
|
+
* In case of error, we'll update the task status to "failed",
|
114
|
+
* so that, client can show notify the user appropriately.
|
115
|
+
*/
|
116
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
117
|
+
status: _types.ImportExportTaskStatus.FAILED,
|
118
|
+
error: {
|
119
|
+
name: e.name,
|
120
|
+
message: e.message,
|
121
|
+
code: "EXPORT_FAILED"
|
122
|
+
}
|
123
|
+
}); // Update stats in main task
|
124
|
+
|
125
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
126
|
+
prevStatus: prevStatusOfSubTask,
|
127
|
+
nextStatus: _types.ImportExportTaskStatus.FAILED
|
128
|
+
});
|
129
|
+
prevStatusOfSubTask = subTask.status;
|
130
|
+
}
|
131
|
+
|
132
|
+
return {
|
133
|
+
data: null,
|
134
|
+
error: {
|
135
|
+
message: e.message
|
136
|
+
}
|
137
|
+
};
|
138
|
+
} finally {
|
139
|
+
// Base condition!
|
140
|
+
if (noPendingTask) {
|
141
|
+
log(`No pending sub-task for task ${taskId}`); // Combine individual block zip files.
|
142
|
+
|
143
|
+
await (0, _client.invokeHandlerClient)({
|
144
|
+
context,
|
145
|
+
name: configuration.handlers.combine,
|
146
|
+
payload: {
|
147
|
+
taskId,
|
148
|
+
type,
|
149
|
+
identity: context.security.getIdentity()
|
150
|
+
},
|
151
|
+
description: "Export blocks - combine"
|
152
|
+
});
|
153
|
+
} else {
|
154
|
+
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`); // We want to continue with Self invocation no matter if current block error out.
|
155
|
+
|
156
|
+
await (0, _client.invokeHandlerClient)({
|
157
|
+
context,
|
158
|
+
name: configuration.handlers.process,
|
159
|
+
payload: {
|
160
|
+
taskId,
|
161
|
+
subTaskIndex: subTaskIndex + 1,
|
162
|
+
type,
|
163
|
+
identity: context.security.getIdentity()
|
164
|
+
},
|
165
|
+
description: "Export blocks - process - subtask"
|
166
|
+
});
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
return {
|
171
|
+
data: "",
|
172
|
+
error: null
|
173
|
+
};
|
174
|
+
};
|
175
|
+
|
176
|
+
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,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,MAAF;IAAUC,YAAV;IAAwBC,IAAxB;IAA8BC;EAA9B,IAA2Cd,OAAjD,CARoB,CASpB;EACA;;EACA,IAAAe,0BAAA,EAAaD,QAAb,EAA2Cb,OAA3C;;EACA,IAAI;IACA;AACR;AACA;AACA;IACQG,OAAO,GAAG,MAAMK,WAAW,CAACO,gBAAZ,CAA6BC,UAA7B,CAAwCN,MAAxC,EAAgD,IAAAO,eAAA,EAAQN,YAAR,EAAsB,CAAtB,CAAhD,CAAhB;IACA;AACR;AACA;AACA;;IACQ,IAAI,CAACR,OAAD,IAAYA,OAAO,CAACe,MAAR,KAAmBZ,6BAAA,CAAuBC,OAA1D,EAAmE;MAC/DH,aAAa,GAAG,IAAhB;MACA,OAAO;QACHe,IAAI,EAAE,EADH;QAEHC,KAAK,EAAE;MAFJ,CAAP;IAIH,CAND,MAMO;MACHhB,aAAa,GAAG,KAAhB;IACH;;IAEDH,GAAG,CAAE,uBAAsBE,OAAO,CAACkB,EAAG,EAAnC,CAAH;IAEA,MAAM;MAAEC;IAAF,IAAYnB,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yC,IAAI,EAAE3C,aAAa,CAAC8C,QAAd,CAAuBC,OAFS;QAGtC9C,OAAO,EAAE;UACLW,MADK;UAELE,IAFK;UAGLC,QAAQ,EAAEb,OAAO,CAAC8C,QAAR,CAAiBC,WAAjB;QAHL,CAH6B;QAQtCC,WAAW,EAAE;MARyB,CAApC,CAAN;IAUH,CAbD,MAaO;MACH9C,OAAO,CAACD,GAAR,CAAa,8BAA6BU,YAAY,GAAG,CAAE,GAA3D,EADG,CAEH;;MACA,MAAM,IAAAgC,2BAAA,EAA6B;QAC/B3C,OAD+B;QAE/ByC,IAAI,EAAE3C,aAAa,CAAC8C,QAAd,CAAuBK,OAFE;QAG/BlD,OAAO,EAAE;UACLW,MADK;UAELC,YAAY,EAAEA,YAAY,GAAG,CAFxB;UAGLC,IAHK;UAILC,QAAQ,EAAEb,OAAO,CAAC8C,QAAR,CAAiBC,WAAjB;QAJL,CAHsB;QAS/BC,WAAW,EAAE;MATkB,CAA7B,CAAN;IAWH;EACJ;;EACD,OAAO;IACH7B,IAAI,EAAE,EADH;IAEHC,KAAK,EAAE;EAFJ,CAAP;AAIH,CAjJM"}
|
@@ -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,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _handlerAws = require("@webiny/handler-aws");
|
9
|
+
|
10
|
+
var _blocksHandler = require("./blocksHandler");
|
11
|
+
|
12
|
+
var _pagesHandler = require("./pagesHandler");
|
13
|
+
|
14
|
+
var _default = configuration => {
|
15
|
+
return (0, _handlerAws.createRawEventHandler)(async ({
|
16
|
+
payload,
|
17
|
+
context
|
18
|
+
}) => {
|
19
|
+
if (payload.type === "block") {
|
20
|
+
return await (0, _blocksHandler.blocksHandler)(configuration, payload, context);
|
21
|
+
} else {
|
22
|
+
return await (0, _pagesHandler.pagesHandler)(configuration, payload, context);
|
23
|
+
}
|
24
|
+
});
|
25
|
+
};
|
26
|
+
|
27
|
+
exports.default = _default;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["configuration","createRawEventHandler","payload","context","type","blocksHandler","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 { pagesHandler } from \"~/export/process/pagesHandler\";\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 if (payload.type === \"block\") {\n return await blocksHandler(configuration, payload, context);\n } else {\n return await pagesHandler(configuration, payload, context);\n }\n }\n );\n};\n"],"mappings":";;;;;;;AAEA;;AACA;;AACA;;eAqBgBA,aAAD,IAAkC;EAC7C,OAAO,IAAAC,iCAAA,EACH,OAAO;IAAEC,OAAF;IAAWC;EAAX,CAAP,KAAgC;IAC5B,IAAID,OAAO,CAACE,IAAR,KAAiB,OAArB,EAA8B;MAC1B,OAAO,MAAM,IAAAC,4BAAA,EAAcL,aAAd,EAA6BE,OAA7B,EAAsCC,OAAtC,CAAb;IACH,CAFD,MAEO;MACH,OAAO,MAAM,IAAAG,0BAAA,EAAaN,aAAb,EAA4BE,OAA5B,EAAqCC,OAArC,CAAb;IACH;EACJ,CAPE,CAAP;AASH,C"}
|
@@ -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>;
|