@webiny/api-page-builder-import-export 0.0.0-mt-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/LICENSE +21 -0
- package/README.md +17 -0
- package/exportPages/combine/index.d.ts +19 -0
- package/exportPages/combine/index.js +88 -0
- package/exportPages/process/index.d.ts +26 -0
- package/exportPages/process/index.js +204 -0
- package/exportPages/s3Stream.d.ts +29 -0
- package/exportPages/s3Stream.js +106 -0
- package/exportPages/utils.d.ts +13 -0
- package/exportPages/utils.js +113 -0
- package/exportPages/zipper.d.ts +35 -0
- package/exportPages/zipper.js +137 -0
- package/graphql/crud/pageImportExportTasks.crud.d.ts +5 -0
- package/graphql/crud/pageImportExportTasks.crud.js +394 -0
- package/graphql/crud/pages.crud.d.ts +4 -0
- package/graphql/crud/pages.crud.js +162 -0
- package/graphql/crud.d.ts +3 -0
- package/graphql/crud.js +16 -0
- package/graphql/graphql/pageImportExportTasks.gql.d.ts +4 -0
- package/graphql/graphql/pageImportExportTasks.gql.js +80 -0
- package/graphql/graphql/pages.gql.d.ts +4 -0
- package/graphql/graphql/pages.gql.js +72 -0
- package/graphql/graphql/utils/resolve.d.ts +3 -0
- package/graphql/graphql/utils/resolve.js +18 -0
- package/graphql/graphql.d.ts +3 -0
- package/graphql/graphql.js +15 -0
- package/graphql/index.d.ts +3 -0
- package/graphql/index.js +16 -0
- package/graphql/types.d.ts +63 -0
- package/graphql/types.js +5 -0
- package/importPages/client.d.ts +7 -0
- package/importPages/client.js +40 -0
- package/importPages/create/index.d.ts +27 -0
- package/importPages/create/index.js +109 -0
- package/importPages/process/index.d.ts +25 -0
- package/importPages/process/index.js +183 -0
- package/importPages/utils.d.ts +43 -0
- package/importPages/utils.js +539 -0
- package/mockSecurity.d.ts +2 -0
- package/mockSecurity.js +13 -0
- package/package.json +80 -0
- package/types.d.ts +192 -0
- package/types.js +42 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
import { HandlerPlugin } from "@webiny/handler/types";
|
2
|
+
import { ArgsContext } from "@webiny/handler-args/types";
|
3
|
+
import { PbPageImportExportContext } from "../../types";
|
4
|
+
import { SecurityIdentity } from "@webiny/api-security/types";
|
5
|
+
export declare type HandlerArgs = {
|
6
|
+
taskId: string;
|
7
|
+
subTaskIndex: number;
|
8
|
+
identity: SecurityIdentity;
|
9
|
+
};
|
10
|
+
export declare type HandlerResponse = {
|
11
|
+
data: string;
|
12
|
+
error: {
|
13
|
+
message: string;
|
14
|
+
};
|
15
|
+
};
|
16
|
+
interface Configuration {
|
17
|
+
handlers: {
|
18
|
+
process: string;
|
19
|
+
};
|
20
|
+
}
|
21
|
+
declare const _default: (configuration: Configuration) => HandlerPlugin<PbPageImportExportContext, ArgsContext<HandlerArgs>>;
|
22
|
+
/**
|
23
|
+
* Handles the import page workflow.
|
24
|
+
*/
|
25
|
+
export default _default;
|
@@ -0,0 +1,183 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = 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
|
+
/**
|
17
|
+
* Handles the import page workflow.
|
18
|
+
*/
|
19
|
+
var _default = configuration => ({
|
20
|
+
type: "handler",
|
21
|
+
|
22
|
+
async handle(context) {
|
23
|
+
const log = console.log;
|
24
|
+
let subTask;
|
25
|
+
let noPendingTask = true;
|
26
|
+
let prevStatusOfSubTask = _types.PageImportExportTaskStatus.PENDING;
|
27
|
+
log("RUNNING Import Page Queue Process");
|
28
|
+
const {
|
29
|
+
invocationArgs: args,
|
30
|
+
pageBuilder
|
31
|
+
} = context;
|
32
|
+
const {
|
33
|
+
taskId,
|
34
|
+
subTaskIndex,
|
35
|
+
identity
|
36
|
+
} = args; // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks
|
37
|
+
// and this Lambda is invoked internally, without credentials.
|
38
|
+
|
39
|
+
(0, _mockSecurity.mockSecurity)(identity, context);
|
40
|
+
|
41
|
+
try {
|
42
|
+
/*
|
43
|
+
* Note: We're not going to DB for getting next sub-task to process,
|
44
|
+
* because the data might be out of sync due to GSI eventual consistency.
|
45
|
+
*/
|
46
|
+
subTask = await pageBuilder.pageImportExportTask.getSubTask(taskId, (0, _utils.zeroPad)(subTaskIndex));
|
47
|
+
/**
|
48
|
+
* Base condition!!
|
49
|
+
* Bail out early, if task not found or task's status is not "pending".
|
50
|
+
*/
|
51
|
+
|
52
|
+
if (!subTask || subTask.status !== _types.PageImportExportTaskStatus.PENDING) {
|
53
|
+
noPendingTask = true;
|
54
|
+
return;
|
55
|
+
} else {
|
56
|
+
noPendingTask = false;
|
57
|
+
}
|
58
|
+
|
59
|
+
prevStatusOfSubTask = subTask.status;
|
60
|
+
log(`Fetched sub task => ${subTask.id}`);
|
61
|
+
const {
|
62
|
+
pageKey,
|
63
|
+
category,
|
64
|
+
zipFileKey,
|
65
|
+
input
|
66
|
+
} = subTask.data;
|
67
|
+
const {
|
68
|
+
fileUploadsData
|
69
|
+
} = input;
|
70
|
+
log(`Processing page key "${pageKey}"`); // Mark task status as PROCESSING
|
71
|
+
|
72
|
+
subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
|
73
|
+
status: _types.PageImportExportTaskStatus.PROCESSING
|
74
|
+
}); // Update stats in main task
|
75
|
+
|
76
|
+
await pageBuilder.pageImportExportTask.updateStats(taskId, {
|
77
|
+
prevStatus: prevStatusOfSubTask,
|
78
|
+
nextStatus: _types.PageImportExportTaskStatus.PROCESSING
|
79
|
+
});
|
80
|
+
prevStatusOfSubTask = subTask.status; // Real job
|
81
|
+
|
82
|
+
const page = await (0, _utils.importPage)({
|
83
|
+
context,
|
84
|
+
pageKey,
|
85
|
+
key: zipFileKey,
|
86
|
+
fileUploadsData
|
87
|
+
}); // Create a page
|
88
|
+
|
89
|
+
let pbPage = await context.pageBuilder.pages.create(category); // Update page with data
|
90
|
+
|
91
|
+
pbPage = await context.pageBuilder.pages.update(pbPage.id, {
|
92
|
+
content: page.content,
|
93
|
+
title: page.title,
|
94
|
+
path: page.path,
|
95
|
+
settings: page.settings
|
96
|
+
}); // TODO: Publish page
|
97
|
+
// Update task record in DB
|
98
|
+
|
99
|
+
subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
|
100
|
+
status: _types.PageImportExportTaskStatus.COMPLETED,
|
101
|
+
data: {
|
102
|
+
message: "Done",
|
103
|
+
page: {
|
104
|
+
id: pbPage.id,
|
105
|
+
title: pbPage.title,
|
106
|
+
version: pbPage.version,
|
107
|
+
status: pbPage.status
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}); // Update stats in main task
|
111
|
+
|
112
|
+
await pageBuilder.pageImportExportTask.updateStats(taskId, {
|
113
|
+
prevStatus: prevStatusOfSubTask,
|
114
|
+
nextStatus: _types.PageImportExportTaskStatus.COMPLETED
|
115
|
+
});
|
116
|
+
prevStatusOfSubTask = subTask.status;
|
117
|
+
} catch (e) {
|
118
|
+
log("[IMPORT_PAGES_PROCESS] Error => ", e);
|
119
|
+
|
120
|
+
if (subTask && subTask.id) {
|
121
|
+
/**
|
122
|
+
* In case of error, we'll update the task status to "failed",
|
123
|
+
* so that, client can show notify the user appropriately.
|
124
|
+
*/
|
125
|
+
const {
|
126
|
+
invocationArgs: args,
|
127
|
+
pageBuilder
|
128
|
+
} = context;
|
129
|
+
const {
|
130
|
+
taskId
|
131
|
+
} = args;
|
132
|
+
subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
|
133
|
+
status: _types.PageImportExportTaskStatus.FAILED,
|
134
|
+
error: {
|
135
|
+
name: e.name,
|
136
|
+
message: e.message,
|
137
|
+
stack: e.stack,
|
138
|
+
code: "IMPORT_FAILED"
|
139
|
+
}
|
140
|
+
}); // Update stats in main task
|
141
|
+
|
142
|
+
await pageBuilder.pageImportExportTask.updateStats(taskId, {
|
143
|
+
prevStatus: prevStatusOfSubTask,
|
144
|
+
nextStatus: _types.PageImportExportTaskStatus.FAILED
|
145
|
+
});
|
146
|
+
prevStatusOfSubTask = subTask.status;
|
147
|
+
}
|
148
|
+
|
149
|
+
return {
|
150
|
+
data: null,
|
151
|
+
error: {
|
152
|
+
message: e.message
|
153
|
+
}
|
154
|
+
};
|
155
|
+
} finally {
|
156
|
+
// Base condition!
|
157
|
+
if (noPendingTask) {
|
158
|
+
log(`No pending sub-task for task ${taskId}`);
|
159
|
+
await pageBuilder.pageImportExportTask.updateTask(taskId, {
|
160
|
+
status: _types.PageImportExportTaskStatus.COMPLETED,
|
161
|
+
data: {
|
162
|
+
message: `Finish importing pages.`
|
163
|
+
}
|
164
|
+
});
|
165
|
+
} else {
|
166
|
+
log(`Invoking PROCESS for task "${subTaskIndex + 1}"`); // We want to continue with Self invocation no matter if current page error out.
|
167
|
+
|
168
|
+
await (0, _client.invokeHandlerClient)({
|
169
|
+
context,
|
170
|
+
name: configuration.handlers.process,
|
171
|
+
payload: {
|
172
|
+
taskId,
|
173
|
+
subTaskIndex: subTaskIndex + 1,
|
174
|
+
identity: context.security.getIdentity()
|
175
|
+
}
|
176
|
+
});
|
177
|
+
}
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
});
|
182
|
+
|
183
|
+
exports.default = _default;
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { PageImportExportTaskStatus } from "../types";
|
2
|
+
import { PbPageImportExportContext } from "../graphql/types";
|
3
|
+
import { ExportedPageData } from "../exportPages/utils";
|
4
|
+
interface UploadPageAssetsParams {
|
5
|
+
context: PbPageImportExportContext;
|
6
|
+
filesData: Record<string, any>[];
|
7
|
+
fileUploadsData: FileUploadsData;
|
8
|
+
}
|
9
|
+
interface UploadPageAssetsReturnType {
|
10
|
+
fileIdToKeyMap?: Map<string, string>;
|
11
|
+
}
|
12
|
+
export declare const uploadPageAssets: ({ context, filesData, fileUploadsData }: UploadPageAssetsParams) => Promise<UploadPageAssetsReturnType>;
|
13
|
+
interface FileUploadsData {
|
14
|
+
data: string;
|
15
|
+
assets: Record<string, string>;
|
16
|
+
}
|
17
|
+
interface ImportPageParams {
|
18
|
+
key: string;
|
19
|
+
pageKey: string;
|
20
|
+
context: PbPageImportExportContext;
|
21
|
+
fileUploadsData: FileUploadsData;
|
22
|
+
}
|
23
|
+
export declare function importPage({ pageKey, context, fileUploadsData }: ImportPageParams): Promise<ExportedPageData["page"]>;
|
24
|
+
interface PageImportData {
|
25
|
+
assets: Record<string, string>;
|
26
|
+
data: string;
|
27
|
+
key: string;
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* Function will read the given zip file from S3 via stream, extract its content and upload it to S3 bucket.
|
31
|
+
* @param zipFileKey
|
32
|
+
* @return PageImportData S3 file keys for all uploaded assets group by page.
|
33
|
+
*/
|
34
|
+
export declare function readExtractAndUploadZipFileContents(zipFileKey: string): Promise<PageImportData[]>;
|
35
|
+
export declare const zeroPad: (version: any) => string;
|
36
|
+
export declare function initialStats(total: any): {
|
37
|
+
pending: any;
|
38
|
+
processing: number;
|
39
|
+
completed: number;
|
40
|
+
failed: number;
|
41
|
+
total: any;
|
42
|
+
};
|
43
|
+
export {};
|