@webiny/api-page-builder-import-export 5.33.5 → 5.34.0-beta.1
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
@@ -0,0 +1,110 @@
|
|
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 _utils = require("../utils");
|
11
|
+
|
12
|
+
var _client = require("../../client");
|
13
|
+
|
14
|
+
var _mockSecurity = require("../../mockSecurity");
|
15
|
+
|
16
|
+
var _utils2 = require("@webiny/utils");
|
17
|
+
|
18
|
+
const blocksHandler = async (configuration, payload, context) => {
|
19
|
+
const log = console.log;
|
20
|
+
const {
|
21
|
+
pageBuilder
|
22
|
+
} = context;
|
23
|
+
const {
|
24
|
+
task,
|
25
|
+
type,
|
26
|
+
category,
|
27
|
+
zipFileUrl,
|
28
|
+
identity
|
29
|
+
} = payload;
|
30
|
+
|
31
|
+
try {
|
32
|
+
log("RUNNING Import Blocks Create");
|
33
|
+
|
34
|
+
if (!zipFileUrl) {
|
35
|
+
return {
|
36
|
+
data: null,
|
37
|
+
error: {
|
38
|
+
message: `Missing "zipFileUrl"!`
|
39
|
+
}
|
40
|
+
};
|
41
|
+
}
|
42
|
+
|
43
|
+
(0, _mockSecurity.mockSecurity)(identity, context); // Step 1: Read the zip file
|
44
|
+
|
45
|
+
const blockImportDataList = await (0, _utils.readExtractAndUploadZipFileContents)(zipFileUrl); // For each block create a subtask and invoke the process handler
|
46
|
+
|
47
|
+
for (let i = 0; i < blockImportDataList.length; i++) {
|
48
|
+
const blocksDirMap = blockImportDataList[i]; // Create sub task
|
49
|
+
|
50
|
+
const subtask = await pageBuilder.importExportTask.createSubTask(task.id, (0, _utils2.zeroPad)(i + 1, 5), {
|
51
|
+
status: _types.ImportExportTaskStatus.PENDING,
|
52
|
+
data: {
|
53
|
+
blockKey: blocksDirMap.key,
|
54
|
+
category,
|
55
|
+
zipFileUrl,
|
56
|
+
input: {
|
57
|
+
fileUploadsData: blocksDirMap
|
58
|
+
}
|
59
|
+
}
|
60
|
+
});
|
61
|
+
log(`Added SUB_TASK "${subtask.id}" to queue.`);
|
62
|
+
} // Update main task status
|
63
|
+
|
64
|
+
|
65
|
+
await pageBuilder.importExportTask.updateTask(task.id, {
|
66
|
+
status: _types.ImportExportTaskStatus.PROCESSING,
|
67
|
+
stats: (0, _utils.initialStats)(blockImportDataList.length)
|
68
|
+
});
|
69
|
+
await (0, _client.invokeHandlerClient)({
|
70
|
+
context,
|
71
|
+
name: configuration.handlers.process,
|
72
|
+
payload: {
|
73
|
+
taskId: task.id,
|
74
|
+
// Execute "Process" for the first sub task.
|
75
|
+
subTaskIndex: 1,
|
76
|
+
type,
|
77
|
+
identity: context.security.getIdentity()
|
78
|
+
},
|
79
|
+
description: "Import blocks - process - first"
|
80
|
+
});
|
81
|
+
} catch (e) {
|
82
|
+
log("[IMPORT_BLOCKS_CREATE] Error => ", e);
|
83
|
+
/**
|
84
|
+
* In case of error, we'll update the task status to "failed",
|
85
|
+
* so that, client can show notify the user appropriately.
|
86
|
+
*/
|
87
|
+
|
88
|
+
await pageBuilder.importExportTask.updateTask(task.id, {
|
89
|
+
status: _types.ImportExportTaskStatus.FAILED,
|
90
|
+
error: {
|
91
|
+
name: e.name,
|
92
|
+
message: e.message,
|
93
|
+
code: e.code || "EXPORT_FAILED"
|
94
|
+
}
|
95
|
+
});
|
96
|
+
return {
|
97
|
+
data: null,
|
98
|
+
error: {
|
99
|
+
message: e.message
|
100
|
+
}
|
101
|
+
};
|
102
|
+
}
|
103
|
+
|
104
|
+
return {
|
105
|
+
data: "",
|
106
|
+
error: null
|
107
|
+
};
|
108
|
+
};
|
109
|
+
|
110
|
+
exports.blocksHandler = blocksHandler;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["blocksHandler","configuration","payload","context","log","console","pageBuilder","task","type","category","zipFileUrl","identity","data","error","message","mockSecurity","blockImportDataList","readExtractAndUploadZipFileContents","i","length","blocksDirMap","subtask","importExportTask","createSubTask","id","zeroPad","status","ImportExportTaskStatus","PENDING","blockKey","key","input","fileUploadsData","updateTask","PROCESSING","stats","initialStats","invokeHandlerClient","name","handlers","process","taskId","subTaskIndex","security","getIdentity","description","e","FAILED","code"],"sources":["blocksHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { initialStats, readExtractAndUploadZipFileContents } from \"~/import/utils\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { Payload as ProcessPayload } from \"../process\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { Configuration, Payload, Response } from \"~/import/create\";\n\nexport const blocksHandler = async (\n configuration: Configuration,\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n\n const { pageBuilder } = context;\n const { task, type, category, zipFileUrl, identity } = payload;\n try {\n log(\"RUNNING Import Blocks Create\");\n if (!zipFileUrl) {\n return {\n data: null,\n error: {\n message: `Missing \"zipFileUrl\"!`\n }\n };\n }\n mockSecurity(identity, context);\n // Step 1: Read the zip file\n const blockImportDataList = await readExtractAndUploadZipFileContents(zipFileUrl);\n\n // For each block create a subtask and invoke the process handler\n for (let i = 0; i < blockImportDataList.length; i++) {\n const blocksDirMap = blockImportDataList[i];\n // Create sub task\n const subtask = await pageBuilder.importExportTask.createSubTask(\n task.id,\n zeroPad(i + 1, 5),\n {\n status: ImportExportTaskStatus.PENDING,\n data: {\n blockKey: blocksDirMap.key,\n category,\n zipFileUrl,\n input: {\n fileUploadsData: blocksDirMap\n }\n }\n }\n );\n log(`Added SUB_TASK \"${subtask.id}\" to queue.`);\n }\n // Update main task status\n await pageBuilder.importExportTask.updateTask(task.id, {\n status: ImportExportTaskStatus.PROCESSING,\n stats: initialStats(blockImportDataList.length)\n });\n\n await invokeHandlerClient<ProcessPayload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId: task.id,\n // Execute \"Process\" for the first sub task.\n subTaskIndex: 1,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Import blocks - process - first\"\n });\n } catch (e) {\n log(\"[IMPORT_BLOCKS_CREATE] Error => \", e);\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\n await pageBuilder.importExportTask.updateTask(task.id, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n code: e.code || \"EXPORT_FAILED\"\n }\n });\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n }\n\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AAGO,MAAMA,aAAa,GAAG,OACzBC,aADyB,EAEzBC,OAFyB,EAGzBC,OAHyB,KAIL;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAApB;EAEA,MAAM;IAAEE;EAAF,IAAkBH,OAAxB;EACA,MAAM;IAAEI,IAAF;IAAQC,IAAR;IAAcC,QAAd;IAAwBC,UAAxB;IAAoCC;EAApC,IAAiDT,OAAvD;;EACA,IAAI;IACAE,GAAG,CAAC,8BAAD,CAAH;;IACA,IAAI,CAACM,UAAL,EAAiB;MACb,OAAO;QACHE,IAAI,EAAE,IADH;QAEHC,KAAK,EAAE;UACHC,OAAO,EAAG;QADP;MAFJ,CAAP;IAMH;;IACD,IAAAC,0BAAA,EAAaJ,QAAb,EAAuBR,OA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AW,EAAE;IAVyB,CAApC,CAAN;EAYH,CArDD,CAqDE,OAAOC,CAAP,EAAU;IACR1C,GAAG,CAAC,kCAAD,EAAqC0C,CAArC,CAAH;IAEA;AACR;AACA;AACA;;IAEQ,MAAMxC,WAAW,CAACgB,gBAAZ,CAA6BW,UAA7B,CAAwC1B,IAAI,CAACiB,EAA7C,EAAiD;MACnDE,MAAM,EAAEC,6BAAA,CAAuBoB,MADoB;MAEnDlC,KAAK,EAAE;QACHyB,IAAI,EAAEQ,CAAC,CAACR,IADL;QAEHxB,OAAO,EAAEgC,CAAC,CAAChC,OAFR;QAGHkC,IAAI,EAAEF,CAAC,CAACE,IAAF,IAAU;MAHb;IAF4C,CAAjD,CAAN;IASA,OAAO;MACHpC,IAAI,EAAE,IADH;MAEHC,KAAK,EAAE;QACHC,OAAO,EAAEgC,CAAC,CAAChC;MADR;IAFJ,CAAP;EAMH;;EAED,OAAO;IACHF,IAAI,EAAE,EADH;IAEHC,KAAK,EAAE;EAFJ,CAAP;AAIH,CA3FM"}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { ImportExportTask, 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
|
};
|
@@ -8,7 +8,8 @@ interface Configuration {
|
|
8
8
|
export interface Payload {
|
9
9
|
category: string;
|
10
10
|
zipFileUrl: string;
|
11
|
-
task:
|
11
|
+
task: ImportExportTask;
|
12
|
+
type: string;
|
12
13
|
identity: SecurityIdentity;
|
13
14
|
}
|
14
15
|
export interface Response {
|
@@ -18,5 +19,5 @@ export interface Response {
|
|
18
19
|
/**
|
19
20
|
* Handles the import page workflow.
|
20
21
|
*/
|
21
|
-
declare const _default: (configuration: Configuration) => import("@webiny/handler-aws").RawEventHandler<Payload,
|
22
|
+
declare const _default: (configuration: Configuration) => import("@webiny/handler-aws").RawEventHandler<Payload, PbImportExportContext, Response>;
|
22
23
|
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 import page workflow.
|
16
|
+
*/
|
17
|
+
var _default = configuration => {
|
18
|
+
return (0, _handlerAws.createRawEventHandler)(async ({
|
19
|
+
payload,
|
20
|
+
context
|
21
|
+
}) => {
|
22
|
+
if (payload.type === "block") {
|
23
|
+
return await (0, _blocksHandler.blocksHandler)(configuration, payload, context);
|
24
|
+
} else {
|
25
|
+
return await (0, _pagesHandler.pagesHandler)(configuration, payload, context);
|
26
|
+
}
|
27
|
+
});
|
28
|
+
};
|
29
|
+
|
30
|
+
exports.default = _default;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["configuration","createRawEventHandler","payload","context","type","blocksHandler","pagesHandler"],"sources":["index.ts"],"sourcesContent":["import { ImportExportTask, PbImportExportContext } from \"~/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { blocksHandler } from \"~/import/create/blocksHandler\";\nimport { pagesHandler } from \"~/import/create/pagesHandler\";\n\nexport interface Configuration {\n handlers: {\n process: string;\n };\n}\n\nexport interface Payload {\n category: string;\n zipFileUrl: string;\n task: ImportExportTask;\n type: string;\n identity: SecurityIdentity;\n}\nexport interface Response {\n data: string | null;\n error: Partial<Error> | null;\n}\n\n/**\n * Handles the import page workflow.\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;;AAoBA;AACA;AACA;eACgBA,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,110 @@
|
|
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 _utils = require("../utils");
|
11
|
+
|
12
|
+
var _client = require("../../client");
|
13
|
+
|
14
|
+
var _mockSecurity = require("../../mockSecurity");
|
15
|
+
|
16
|
+
var _utils2 = require("@webiny/utils");
|
17
|
+
|
18
|
+
const pagesHandler = async (configuration, payload, context) => {
|
19
|
+
const log = console.log;
|
20
|
+
const {
|
21
|
+
pageBuilder
|
22
|
+
} = context;
|
23
|
+
const {
|
24
|
+
task,
|
25
|
+
type,
|
26
|
+
category,
|
27
|
+
zipFileUrl,
|
28
|
+
identity
|
29
|
+
} = payload;
|
30
|
+
|
31
|
+
try {
|
32
|
+
log("RUNNING Import Pages Create");
|
33
|
+
|
34
|
+
if (!zipFileUrl) {
|
35
|
+
return {
|
36
|
+
data: null,
|
37
|
+
error: {
|
38
|
+
message: `Missing "zipFileUrl"!`
|
39
|
+
}
|
40
|
+
};
|
41
|
+
}
|
42
|
+
|
43
|
+
(0, _mockSecurity.mockSecurity)(identity, context); // Step 1: Read the zip file
|
44
|
+
|
45
|
+
const pageImportDataList = await (0, _utils.readExtractAndUploadZipFileContents)(zipFileUrl); // For each page create a subtask and invoke the process handler
|
46
|
+
|
47
|
+
for (let i = 0; i < pageImportDataList.length; i++) {
|
48
|
+
const pagesDirMap = pageImportDataList[i]; // Create sub task
|
49
|
+
|
50
|
+
const subtask = await pageBuilder.importExportTask.createSubTask(task.id, (0, _utils2.zeroPad)(i + 1, 5), {
|
51
|
+
status: _types.ImportExportTaskStatus.PENDING,
|
52
|
+
data: {
|
53
|
+
pageKey: pagesDirMap.key,
|
54
|
+
category,
|
55
|
+
zipFileUrl,
|
56
|
+
input: {
|
57
|
+
fileUploadsData: pagesDirMap
|
58
|
+
}
|
59
|
+
}
|
60
|
+
});
|
61
|
+
log(`Added SUB_TASK "${subtask.id}" to queue.`);
|
62
|
+
} // Update main task status
|
63
|
+
|
64
|
+
|
65
|
+
await pageBuilder.importExportTask.updateTask(task.id, {
|
66
|
+
status: _types.ImportExportTaskStatus.PROCESSING,
|
67
|
+
stats: (0, _utils.initialStats)(pageImportDataList.length)
|
68
|
+
});
|
69
|
+
await (0, _client.invokeHandlerClient)({
|
70
|
+
context,
|
71
|
+
name: configuration.handlers.process,
|
72
|
+
payload: {
|
73
|
+
taskId: task.id,
|
74
|
+
// Execute "Process" for the first sub task.
|
75
|
+
subTaskIndex: 1,
|
76
|
+
type,
|
77
|
+
identity: context.security.getIdentity()
|
78
|
+
},
|
79
|
+
description: "Import pages - process - first"
|
80
|
+
});
|
81
|
+
} catch (e) {
|
82
|
+
log("[IMPORT_PAGES_CREATE] Error => ", e);
|
83
|
+
/**
|
84
|
+
* In case of error, we'll update the task status to "failed",
|
85
|
+
* so that, client can show notify the user appropriately.
|
86
|
+
*/
|
87
|
+
|
88
|
+
await pageBuilder.importExportTask.updateTask(task.id, {
|
89
|
+
status: _types.ImportExportTaskStatus.FAILED,
|
90
|
+
error: {
|
91
|
+
name: e.name,
|
92
|
+
message: e.message,
|
93
|
+
code: e.code || "EXPORT_FAILED"
|
94
|
+
}
|
95
|
+
});
|
96
|
+
return {
|
97
|
+
data: null,
|
98
|
+
error: {
|
99
|
+
message: e.message
|
100
|
+
}
|
101
|
+
};
|
102
|
+
}
|
103
|
+
|
104
|
+
return {
|
105
|
+
data: "",
|
106
|
+
error: null
|
107
|
+
};
|
108
|
+
};
|
109
|
+
|
110
|
+
exports.pagesHandler = pagesHandler;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["pagesHandler","configuration","payload","context","log","console","pageBuilder","task","type","category","zipFileUrl","identity","data","error","message","mockSecurity","pageImportDataList","readExtractAndUploadZipFileContents","i","length","pagesDirMap","subtask","importExportTask","createSubTask","id","zeroPad","status","ImportExportTaskStatus","PENDING","pageKey","key","input","fileUploadsData","updateTask","PROCESSING","stats","initialStats","invokeHandlerClient","name","handlers","process","taskId","subTaskIndex","security","getIdentity","description","e","FAILED","code"],"sources":["pagesHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { initialStats, readExtractAndUploadZipFileContents } from \"~/import/utils\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { Payload as ProcessPayload } from \"../process\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { Configuration, Payload, Response } from \"~/import/create\";\n\nexport const pagesHandler = async (\n configuration: Configuration,\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n\n const { pageBuilder } = context;\n const { task, type, category, zipFileUrl, identity } = payload;\n try {\n log(\"RUNNING Import Pages Create\");\n if (!zipFileUrl) {\n return {\n data: null,\n error: {\n message: `Missing \"zipFileUrl\"!`\n }\n };\n }\n mockSecurity(identity, context);\n // Step 1: Read the zip file\n const pageImportDataList = await readExtractAndUploadZipFileContents(zipFileUrl);\n\n // For each page create a subtask and invoke the process handler\n for (let i = 0; i < pageImportDataList.length; i++) {\n const pagesDirMap = pageImportDataList[i];\n // Create sub task\n const subtask = await pageBuilder.importExportTask.createSubTask(\n task.id,\n zeroPad(i + 1, 5),\n {\n status: ImportExportTaskStatus.PENDING,\n data: {\n pageKey: pagesDirMap.key,\n category,\n zipFileUrl,\n input: {\n fileUploadsData: pagesDirMap\n }\n }\n }\n );\n log(`Added SUB_TASK \"${subtask.id}\" to queue.`);\n }\n // Update main task status\n await pageBuilder.importExportTask.updateTask(task.id, {\n status: ImportExportTaskStatus.PROCESSING,\n stats: initialStats(pageImportDataList.length)\n });\n\n await invokeHandlerClient<ProcessPayload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId: task.id,\n // Execute \"Process\" for the first sub task.\n subTaskIndex: 1,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Import pages - process - first\"\n });\n } catch (e) {\n log(\"[IMPORT_PAGES_CREATE] Error => \", e);\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\n await pageBuilder.importExportTask.updateTask(task.id, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n code: e.code || \"EXPORT_FAILED\"\n }\n });\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n }\n\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AAGO,MAAMA,YAAY,GAAG,OACxBC,aADwB,EAExBC,OAFwB,EAGxBC,OAHwB,KAIJ;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAApB;EAEA,MAAM;IAAEE;EAAF,IAAkBH,OAAxB;EACA,MAAM;IAAEI,IAAF;IAAQC,IAAR;IAAcC,QAAd;IAAwBC,UAAxB;IAAoCC;EAApC,IAAiDT,OAAvD;;EACA,IAAI;IACAE,GAAG,CAAC,6BAAD,CAAH;;IACA,IAAI,CAACM,UAAL,EAAiB;MACb,OAAO;QACHE,IAAI,EAAE,IADH;QAEHC,KAA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HT;QAILlC,IAJK;QAKLG,QAAQ,EAAER,OAAO,CAACwC,QAAR,CAAiBC,WAAjB;MALL,CAH6B;MAUtCC,WAAW,EAAE;IAVyB,CAApC,CAAN;EAYH,CArDD,CAqDE,OAAOC,CAAP,EAAU;IACR1C,GAAG,CAAC,iCAAD,EAAoC0C,CAApC,CAAH;IAEA;AACR;AACA;AACA;;IAEQ,MAAMxC,WAAW,CAACgB,gBAAZ,CAA6BW,UAA7B,CAAwC1B,IAAI,CAACiB,EAA7C,EAAiD;MACnDE,MAAM,EAAEC,6BAAA,CAAuBoB,MADoB;MAEnDlC,KAAK,EAAE;QACHyB,IAAI,EAAEQ,CAAC,CAACR,IADL;QAEHxB,OAAO,EAAEgC,CAAC,CAAChC,OAFR;QAGHkC,IAAI,EAAEF,CAAC,CAACE,IAAF,IAAU;MAHb;IAF4C,CAAjD,CAAN;IASA,OAAO;MACHpC,IAAI,EAAE,IADH;MAEHC,KAAK,EAAE;QACHC,OAAO,EAAEgC,CAAC,CAAChC;MADR;IAFJ,CAAP;EAMH;;EAED,OAAO;IACHF,IAAI,EAAE,EADH;IAEHC,KAAK,EAAE;EAFJ,CAAP;AAIH,CA3FM"}
|
@@ -0,0 +1,175 @@
|
|
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 _utils = require("../utils");
|
11
|
+
|
12
|
+
var _client = require("../../client");
|
13
|
+
|
14
|
+
var _mockSecurity = require("../../mockSecurity");
|
15
|
+
|
16
|
+
var _utils2 = require("@webiny/utils");
|
17
|
+
|
18
|
+
const blocksHandler = async (configuration, payload, context) => {
|
19
|
+
const log = console.log;
|
20
|
+
let subTask;
|
21
|
+
let noPendingTask = true;
|
22
|
+
let prevStatusOfSubTask = _types.ImportExportTaskStatus.PENDING;
|
23
|
+
log("RUNNING Import Block Queue Process");
|
24
|
+
const {
|
25
|
+
pageBuilder
|
26
|
+
} = context;
|
27
|
+
const {
|
28
|
+
taskId,
|
29
|
+
subTaskIndex,
|
30
|
+
type,
|
31
|
+
identity
|
32
|
+
} = payload; // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks
|
33
|
+
// and this Lambda is invoked internally, without credentials.
|
34
|
+
|
35
|
+
(0, _mockSecurity.mockSecurity)(identity, context);
|
36
|
+
|
37
|
+
try {
|
38
|
+
/*
|
39
|
+
* Note: We're not going to DB for getting next sub-task to process,
|
40
|
+
* because the data might be out of sync due to GSI eventual consistency.
|
41
|
+
*/
|
42
|
+
subTask = await pageBuilder.importExportTask.getSubTask(taskId, (0, _utils2.zeroPad)(subTaskIndex, 5));
|
43
|
+
/**
|
44
|
+
* Base condition!!
|
45
|
+
* Bail out early, if task not found or task's status is not "pending".
|
46
|
+
*/
|
47
|
+
|
48
|
+
if (!subTask || subTask.status !== _types.ImportExportTaskStatus.PENDING) {
|
49
|
+
noPendingTask = true;
|
50
|
+
return {
|
51
|
+
data: "",
|
52
|
+
error: null
|
53
|
+
};
|
54
|
+
} else {
|
55
|
+
noPendingTask = false;
|
56
|
+
}
|
57
|
+
|
58
|
+
prevStatusOfSubTask = subTask.status;
|
59
|
+
log(`Fetched sub task => ${subTask.id}`);
|
60
|
+
console.log("subTask", subTask);
|
61
|
+
const {
|
62
|
+
blockKey,
|
63
|
+
category,
|
64
|
+
zipFileKey,
|
65
|
+
input
|
66
|
+
} = subTask.data;
|
67
|
+
const {
|
68
|
+
fileUploadsData
|
69
|
+
} = input;
|
70
|
+
log(`Processing block key "${blockKey}"`); // Mark task status as PROCESSING
|
71
|
+
|
72
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
73
|
+
status: _types.ImportExportTaskStatus.PROCESSING
|
74
|
+
}); // Update stats in main task
|
75
|
+
|
76
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
77
|
+
prevStatus: prevStatusOfSubTask,
|
78
|
+
nextStatus: _types.ImportExportTaskStatus.PROCESSING
|
79
|
+
});
|
80
|
+
prevStatusOfSubTask = subTask.status; // Real job
|
81
|
+
|
82
|
+
const block = await (0, _utils.importBlock)({
|
83
|
+
context,
|
84
|
+
blockKey,
|
85
|
+
key: zipFileKey,
|
86
|
+
fileUploadsData
|
87
|
+
}); // Create a block
|
88
|
+
|
89
|
+
const pbBlock = await context.pageBuilder.createPageBlock({
|
90
|
+
name: block.name,
|
91
|
+
blockCategory: category,
|
92
|
+
content: block.content,
|
93
|
+
preview: block.preview
|
94
|
+
}); // Update task record in DB
|
95
|
+
|
96
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
97
|
+
status: _types.ImportExportTaskStatus.COMPLETED,
|
98
|
+
data: {
|
99
|
+
message: "Done",
|
100
|
+
block: {
|
101
|
+
id: pbBlock.id,
|
102
|
+
name: pbBlock.name
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}); // Update stats in main task
|
106
|
+
|
107
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
108
|
+
prevStatus: prevStatusOfSubTask,
|
109
|
+
nextStatus: _types.ImportExportTaskStatus.COMPLETED
|
110
|
+
});
|
111
|
+
prevStatusOfSubTask = subTask.status;
|
112
|
+
} catch (e) {
|
113
|
+
log("[IMPORT_BLOCKS_PROCESS] Error => ", e.message);
|
114
|
+
|
115
|
+
if (subTask && subTask.id) {
|
116
|
+
/**
|
117
|
+
* In case of error, we'll update the task status to "failed",
|
118
|
+
* so that, client can show notify the user appropriately.
|
119
|
+
*/
|
120
|
+
subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
|
121
|
+
status: _types.ImportExportTaskStatus.FAILED,
|
122
|
+
error: {
|
123
|
+
name: e.name,
|
124
|
+
message: e.message,
|
125
|
+
code: "IMPORT_FAILED"
|
126
|
+
}
|
127
|
+
}); // Update stats in main task
|
128
|
+
|
129
|
+
await pageBuilder.importExportTask.updateStats(taskId, {
|
130
|
+
prevStatus: prevStatusOfSubTask,
|
131
|
+
nextStatus: _types.ImportExportTaskStatus.FAILED
|
132
|
+
});
|
133
|
+
prevStatusOfSubTask = subTask.status;
|
134
|
+
}
|
135
|
+
|
136
|
+
return {
|
137
|
+
data: null,
|
138
|
+
error: {
|
139
|
+
message: e.message
|
140
|
+
}
|
141
|
+
};
|
142
|
+
} finally {
|
143
|
+
// Base condition!
|
144
|
+
if (noPendingTask) {
|
145
|
+
log(`No pending sub-task for task ${taskId}`);
|
146
|
+
await pageBuilder.importExportTask.updateTask(taskId, {
|
147
|
+
status: _types.ImportExportTaskStatus.COMPLETED,
|
148
|
+
data: {
|
149
|
+
message: `Finish importing blocks.`
|
150
|
+
}
|
151
|
+
});
|
152
|
+
} else {
|
153
|
+
log(`Invoking PROCESS for task "${subTaskIndex + 1}"`); // We want to continue with Self invocation no matter if current block error out.
|
154
|
+
|
155
|
+
await (0, _client.invokeHandlerClient)({
|
156
|
+
context,
|
157
|
+
name: configuration.handlers.process,
|
158
|
+
payload: {
|
159
|
+
taskId,
|
160
|
+
subTaskIndex: subTaskIndex + 1,
|
161
|
+
type,
|
162
|
+
identity: context.security.getIdentity()
|
163
|
+
},
|
164
|
+
description: "Import blocks - process - subtask"
|
165
|
+
});
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
return {
|
170
|
+
data: "",
|
171
|
+
error: null
|
172
|
+
};
|
173
|
+
};
|
174
|
+
|
175
|
+
exports.blocksHandler = blocksHandler;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["blocksHandler","configuration","payload","context","log","console","subTask","noPendingTask","prevStatusOfSubTask","ImportExportTaskStatus","PENDING","pageBuilder","taskId","subTaskIndex","type","identity","mockSecurity","importExportTask","getSubTask","zeroPad","status","data","error","id","blockKey","category","zipFileKey","input","fileUploadsData","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","block","importBlock","key","pbBlock","createPageBlock","name","blockCategory","content","preview","COMPLETED","message","e","FAILED","code","updateTask","invokeHandlerClient","handlers","process","security","getIdentity","description"],"sources":["blocksHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { importBlock } from \"~/import/utils\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { Configuration, Payload, Response } from \"~/import/process\";\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 Import Block Queue Process\");\n const { pageBuilder } = 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, context);\n\n try {\n /*\n * Note: We're not going to DB for getting next sub-task to process,\n * because the data might be out of sync due to GSI eventual consistency.\n */\n\n subTask = await pageBuilder.importExportTask.getSubTask(taskId, zeroPad(subTaskIndex, 5));\n\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 prevStatusOfSubTask = subTask.status;\n\n log(`Fetched sub task => ${subTask.id}`);\n console.log(\"subTask\", subTask);\n\n const { blockKey, category, zipFileKey, input } = subTask.data;\n const { fileUploadsData } = input;\n\n log(`Processing block key \"${blockKey}\"`);\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 // Real job\n const block = await importBlock({\n context,\n blockKey,\n key: zipFileKey,\n fileUploadsData\n });\n\n // Create a block\n const pbBlock = await context.pageBuilder.createPageBlock({\n name: block.name,\n blockCategory: category,\n content: block.content,\n preview: block.preview\n });\n\n // Update task record in DB\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: \"Done\",\n block: {\n id: pbBlock.id,\n name: pbBlock.name\n }\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(\"[IMPORT_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: \"IMPORT_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\n await pageBuilder.importExportTask.updateTask(taskId, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish importing blocks.`\n }\n });\n } else {\n 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: \"Import blocks - process - subtask\"\n });\n }\n }\n return {\n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AAA,CAAuBkC,SADmB;QAElDtB,IAAI,EAAE;UACFuB,OAAO,EAAG;QADR;MAF4C,CAAhD,CAAN;IAMH,CATD,MASO;MACHxC,GAAG,CAAE,8BAA6BS,YAAY,GAAG,CAAE,GAAhD,CAAH,CADG,CAEH;;MACA,MAAM,IAAAoC,2BAAA,EAA6B;QAC/B9C,OAD+B;QAE/BoC,IAAI,EAAEtC,aAAa,CAACiD,QAAd,CAAuBC,OAFE;QAG/BjD,OAAO,EAAE;UACLU,MADK;UAELC,YAAY,EAAEA,YAAY,GAAG,CAFxB;UAGLC,IAHK;UAILC,QAAQ,EAAEZ,OAAO,CAACiD,QAAR,CAAiBC,WAAjB;QAJL,CAHsB;QAS/BC,WAAW,EAAE;MATkB,CAA7B,CAAN;IAWH;EACJ;;EACD,OAAO;IACHjC,IAAI,EAAE,EADH;IAEHC,KAAK,EAAE;EAFJ,CAAP;AAIH,CA1JM"}
|
@@ -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
|
};
|
@@ -8,11 +8,12 @@ interface Configuration {
|
|
8
8
|
export interface Payload {
|
9
9
|
taskId: string;
|
10
10
|
subTaskIndex: number;
|
11
|
+
type: string;
|
11
12
|
identity: SecurityIdentity;
|
12
13
|
}
|
13
14
|
export interface Response {
|
14
15
|
data: string | null;
|
15
16
|
error: Partial<Error> | null;
|
16
17
|
}
|
17
|
-
declare const _default: (configuration: Configuration) => import("@webiny/handler-aws").RawEventHandler<Payload,
|
18
|
+
declare const _default: (configuration: Configuration) => import("@webiny/handler-aws").RawEventHandler<Payload, PbImportExportContext, Response>;
|
18
19
|
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 \"~/import/process/blocksHandler\";\nimport { pagesHandler } from \"~/import/process/pagesHandler\";\n\nexport interface Configuration {\n handlers: {\n process: 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;;eAoBgBA,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"}
|