@webiny/api-page-builder-import-export 0.0.0-mt-3 → 0.0.0-unstable.3386f66516
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 +8 -0
- package/client.js +47 -0
- package/client.js.map +1 -0
- package/export/combine/blocksHandler.d.ts +6 -0
- package/export/combine/blocksHandler.js +106 -0
- package/export/combine/blocksHandler.js.map +1 -0
- package/export/combine/index.d.ts +16 -0
- package/export/combine/index.js +43 -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/combine/templatesHandler.d.ts +6 -0
- package/export/combine/templatesHandler.js +106 -0
- package/export/combine/templatesHandler.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/export/process/index.d.ts +20 -0
- package/export/process/index.js +40 -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/export/process/templatesHandler.d.ts +6 -0
- package/export/process/templatesHandler.js +176 -0
- package/export/process/templatesHandler.js.map +1 -0
- package/{exportPages → export}/s3Stream.d.ts +2 -0
- package/{exportPages → export}/s3Stream.js +14 -7
- package/export/s3Stream.js.map +1 -0
- package/export/utils.d.ts +22 -0
- package/export/utils.js +173 -0
- package/export/utils.js.map +1 -0
- package/{exportPages → export}/zipper.d.ts +7 -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} +82 -65
- package/graphql/crud/importExportTasks.crud.js.map +1 -0
- package/graphql/crud/pages.crud.d.ts +3 -3
- package/graphql/crud/pages.crud.js +46 -34
- package/graphql/crud/pages.crud.js.map +1 -0
- package/graphql/crud/templates.crud.d.ts +4 -0
- package/graphql/crud/templates.crud.js +140 -0
- package/graphql/crud/templates.crud.js.map +1 -0
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js +7 -3
- package/graphql/crud.js.map +1 -0
- 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 +4 -8
- package/graphql/graphql/pages.gql.js.map +1 -0
- package/graphql/graphql/templates.gql.d.ts +4 -0
- package/graphql/graphql/templates.gql.js +57 -0
- package/graphql/graphql/templates.gql.js.map +1 -0
- package/graphql/graphql/utils/resolve.d.ts +1 -1
- package/graphql/graphql/utils/resolve.js.map +1 -0
- package/graphql/graphql.d.ts +1 -1
- package/graphql/graphql.js +7 -3
- package/graphql/graphql.js.map +1 -0
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +1 -1
- package/graphql/index.js.map +1 -0
- package/graphql/types.d.ts +63 -27
- package/graphql/types.js.map +1 -0
- package/import/create/blocksHandler.d.ts +3 -0
- package/import/create/blocksHandler.js +110 -0
- package/import/create/blocksHandler.js.map +1 -0
- package/import/create/index.d.ts +24 -0
- package/import/create/index.js +43 -0
- package/import/create/index.js.map +1 -0
- package/import/create/pagesHandler.d.ts +3 -0
- package/import/create/pagesHandler.js +112 -0
- package/import/create/pagesHandler.js.map +1 -0
- package/import/create/templatesHandler.d.ts +3 -0
- package/import/create/templatesHandler.js +108 -0
- package/import/create/templatesHandler.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/import/process/index.d.ts +20 -0
- package/import/process/index.js +40 -0
- package/import/process/index.js.map +1 -0
- package/import/process/pagesHandler.d.ts +3 -0
- package/import/process/pagesHandler.js +181 -0
- package/import/process/pagesHandler.js.map +1 -0
- package/import/process/templatesHandler.d.ts +3 -0
- package/import/process/templatesHandler.js +172 -0
- package/import/process/templatesHandler.js.map +1 -0
- package/import/utils.d.ts +56 -0
- package/{importPages → import}/utils.js +246 -89
- package/import/utils.js.map +1 -0
- package/mockSecurity.js.map +1 -0
- package/package.json +36 -34
- package/types.d.ts +70 -72
- package/types.js +17 -17
- package/types.js.map +1 -0
- package/exportPages/combine/index.d.ts +0 -19
- package/exportPages/combine/index.js +0 -88
- package/exportPages/process/index.d.ts +0 -26
- package/exportPages/process/index.js +0 -204
- package/exportPages/utils.d.ts +0 -13
- package/exportPages/utils.js +0 -113
- package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
- package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
- package/importPages/client.d.ts +0 -7
- package/importPages/client.js +0 -40
- package/importPages/create/index.d.ts +0 -27
- package/importPages/create/index.js +0 -109
- package/importPages/process/index.d.ts +0 -25
- package/importPages/process/index.js +0 -183
- package/importPages/utils.d.ts +0 -43
@@ -1,88 +0,0 @@
|
|
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 _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
|
-
var _default = () => ({
|
20
|
-
type: "handler",
|
21
|
-
|
22
|
-
async handle(context) {
|
23
|
-
const log = console.log;
|
24
|
-
log("RUNNING Export Pages Combine Handler");
|
25
|
-
const {
|
26
|
-
invocationArgs: args,
|
27
|
-
pageBuilder
|
28
|
-
} = context;
|
29
|
-
const {
|
30
|
-
taskId,
|
31
|
-
identity
|
32
|
-
} = args;
|
33
|
-
(0, _mockSecurity.mockSecurity)(identity, context);
|
34
|
-
|
35
|
-
try {
|
36
|
-
const task = await pageBuilder.pageImportExportTask.getTask(taskId);
|
37
|
-
const {
|
38
|
-
exportPagesDataKey
|
39
|
-
} = task.input; // Get all files (zip) from given key
|
40
|
-
|
41
|
-
const listObjectResponse = await _s3Stream.s3Stream.listObject(exportPagesDataKey);
|
42
|
-
const zipFileKeys = listObjectResponse.Contents.filter(file => file.Key !== exportPagesDataKey).map(file => file.Key); // Prepare zip of all zips
|
43
|
-
|
44
|
-
const zipOfZip = new _zipper.ZipOfZip(zipFileKeys); // Upload
|
45
|
-
|
46
|
-
const pageExportUpload = await zipOfZip.process();
|
47
|
-
log(`Done uploading... File is located at ${pageExportUpload.Location} `); // Update task status and save export page data key
|
48
|
-
|
49
|
-
await pageBuilder.pageImportExportTask.updateTask(taskId, {
|
50
|
-
status: _types.PageImportExportTaskStatus.COMPLETED,
|
51
|
-
data: {
|
52
|
-
message: `Finish uploading page export.`,
|
53
|
-
key: pageExportUpload.Key,
|
54
|
-
url: pageExportUpload.Location
|
55
|
-
}
|
56
|
-
}); // Remove individual zip files from storage
|
57
|
-
|
58
|
-
const deleteFilePromises = zipFileKeys.map(key => _s3Stream.s3Stream.deleteObject(key));
|
59
|
-
await Promise.all(deleteFilePromises);
|
60
|
-
log(`Successfully deleted ${deleteFilePromises.length} zip files.`);
|
61
|
-
} catch (e) {
|
62
|
-
log("[EXPORT_PAGES_COMBINE] Error => ", e);
|
63
|
-
/**
|
64
|
-
* In case of error, we'll update the task status to "failed",
|
65
|
-
* so that, client can show notify the user appropriately.
|
66
|
-
*/
|
67
|
-
|
68
|
-
await pageBuilder.pageImportExportTask.updateTask(taskId, {
|
69
|
-
status: _types.PageImportExportTaskStatus.FAILED,
|
70
|
-
error: {
|
71
|
-
name: e.name,
|
72
|
-
message: e.message,
|
73
|
-
stack: e.stack,
|
74
|
-
code: "IMPORT_FAILED"
|
75
|
-
}
|
76
|
-
});
|
77
|
-
return {
|
78
|
-
data: null,
|
79
|
-
error: {
|
80
|
-
message: e.message
|
81
|
-
}
|
82
|
-
};
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
});
|
87
|
-
|
88
|
-
exports.default = _default;
|
@@ -1,26 +0,0 @@
|
|
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
|
-
combine: string;
|
20
|
-
};
|
21
|
-
}
|
22
|
-
declare const _default: (configuration: Configuration) => HandlerPlugin<PbPageImportExportContext, ArgsContext<HandlerArgs>>;
|
23
|
-
/**
|
24
|
-
* Handles the export pages process workflow.
|
25
|
-
*/
|
26
|
-
export default _default;
|
@@ -1,204 +0,0 @@
|
|
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("../../importPages/utils");
|
11
|
-
|
12
|
-
var _client = require("../../importPages/client");
|
13
|
-
|
14
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
15
|
-
|
16
|
-
var _utils2 = require("../utils");
|
17
|
-
|
18
|
-
var _mockSecurity = require("../../mockSecurity");
|
19
|
-
|
20
|
-
/**
|
21
|
-
* Handles the export pages process workflow.
|
22
|
-
*/
|
23
|
-
var _default = configuration => ({
|
24
|
-
type: "handler",
|
25
|
-
|
26
|
-
async handle(context) {
|
27
|
-
const log = console.log;
|
28
|
-
let subTask;
|
29
|
-
let noPendingTask = true;
|
30
|
-
let prevStatusOfSubTask = _types.PageImportExportTaskStatus.PENDING;
|
31
|
-
log("RUNNING Export Pages Process Handler");
|
32
|
-
const {
|
33
|
-
invocationArgs: args,
|
34
|
-
pageBuilder,
|
35
|
-
fileManager
|
36
|
-
} = context;
|
37
|
-
const {
|
38
|
-
taskId,
|
39
|
-
subTaskIndex,
|
40
|
-
identity
|
41
|
-
} = args; // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks
|
42
|
-
// and this Lambda is invoked internally, without credentials.
|
43
|
-
|
44
|
-
(0, _mockSecurity.mockSecurity)(identity, context);
|
45
|
-
|
46
|
-
try {
|
47
|
-
/*
|
48
|
-
* Note: We're not going to DB for finding the next sub-task to process,
|
49
|
-
* because the data might be out of sync due to GSI eventual consistency.
|
50
|
-
*/
|
51
|
-
subTask = await pageBuilder.pageImportExportTask.getSubTask(taskId, (0, _utils.zeroPad)(subTaskIndex));
|
52
|
-
/**
|
53
|
-
* Base condition!!
|
54
|
-
* Bail out early, if task not found or task's status is not "pending".
|
55
|
-
*/
|
56
|
-
|
57
|
-
if (!subTask || subTask.status !== _types.PageImportExportTaskStatus.PENDING) {
|
58
|
-
noPendingTask = true;
|
59
|
-
return;
|
60
|
-
} else {
|
61
|
-
noPendingTask = false;
|
62
|
-
}
|
63
|
-
|
64
|
-
log(`Fetched sub task => ${subTask.id}`);
|
65
|
-
const {
|
66
|
-
input
|
67
|
-
} = subTask;
|
68
|
-
const {
|
69
|
-
pageId,
|
70
|
-
exportPagesDataKey,
|
71
|
-
revisionType
|
72
|
-
} = input;
|
73
|
-
/**
|
74
|
-
* At the moment, we only export a single revision of the page.
|
75
|
-
* It could be "published" or "latest" depending upon user input.
|
76
|
-
*
|
77
|
-
* Note: In case of no "published" revision available, we use the latest revision.
|
78
|
-
*/
|
79
|
-
|
80
|
-
let page;
|
81
|
-
|
82
|
-
try {
|
83
|
-
if (revisionType === _types.PageExportRevisionType.PUBLISHED) {
|
84
|
-
// Get "published" page.
|
85
|
-
page = await pageBuilder.pages.getPublishedById({
|
86
|
-
id: pageId
|
87
|
-
});
|
88
|
-
} else {
|
89
|
-
// Get "latest" page.
|
90
|
-
page = await pageBuilder.pages.get(pageId);
|
91
|
-
}
|
92
|
-
} catch (e) {
|
93
|
-
// If we're looking for "published" page and doesn't found it, get latest page.
|
94
|
-
if (revisionType === _types.PageExportRevisionType.PUBLISHED && e instanceof _handlerGraphql.NotFoundError) {
|
95
|
-
page = await pageBuilder.pages.get(pageId);
|
96
|
-
} else {
|
97
|
-
throw e;
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
if (!page) {
|
102
|
-
log(`Unable to load page "${pageId}"`);
|
103
|
-
throw new _handlerGraphql.NotFoundError(`Unable to load page "${pageId}"`);
|
104
|
-
}
|
105
|
-
|
106
|
-
log(`Processing page key "${pageId}" | version ${page.version} | ${page.status}`); // Mark task status as PROCESSING
|
107
|
-
|
108
|
-
subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
|
109
|
-
status: _types.PageImportExportTaskStatus.PROCESSING
|
110
|
-
}); // Update stats in main task
|
111
|
-
|
112
|
-
await pageBuilder.pageImportExportTask.updateStats(taskId, {
|
113
|
-
prevStatus: prevStatusOfSubTask,
|
114
|
-
nextStatus: _types.PageImportExportTaskStatus.PROCESSING
|
115
|
-
});
|
116
|
-
prevStatusOfSubTask = subTask.status;
|
117
|
-
log(`Extracting page data and uploading to storage...`); // Extract Page
|
118
|
-
|
119
|
-
const pageDataZip = await (0, _utils2.exportPage)(page, exportPagesDataKey, fileManager);
|
120
|
-
log(`Finish uploading zip...`); // Update task record in DB
|
121
|
-
|
122
|
-
subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
|
123
|
-
status: _types.PageImportExportTaskStatus.COMPLETED,
|
124
|
-
data: {
|
125
|
-
message: `Finish uploading data for page "${page.id}" v${page.version} (${page.status}).`,
|
126
|
-
key: pageDataZip.Key
|
127
|
-
}
|
128
|
-
}); // Update stats in main task
|
129
|
-
|
130
|
-
await pageBuilder.pageImportExportTask.updateStats(taskId, {
|
131
|
-
prevStatus: prevStatusOfSubTask,
|
132
|
-
nextStatus: _types.PageImportExportTaskStatus.COMPLETED
|
133
|
-
});
|
134
|
-
prevStatusOfSubTask = subTask.status;
|
135
|
-
} catch (e) {
|
136
|
-
log("[EXPORT_PAGES_PROCESS] Error => ", e);
|
137
|
-
|
138
|
-
if (subTask && subTask.id) {
|
139
|
-
/**
|
140
|
-
* In case of error, we'll update the task status to "failed",
|
141
|
-
* so that, client can show notify the user appropriately.
|
142
|
-
*/
|
143
|
-
const {
|
144
|
-
invocationArgs: args,
|
145
|
-
pageBuilder
|
146
|
-
} = context;
|
147
|
-
const {
|
148
|
-
taskId
|
149
|
-
} = args;
|
150
|
-
subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
|
151
|
-
status: _types.PageImportExportTaskStatus.FAILED,
|
152
|
-
error: {
|
153
|
-
name: e.name,
|
154
|
-
message: e.message,
|
155
|
-
stack: e.stack,
|
156
|
-
code: "IMPORT_FAILED"
|
157
|
-
}
|
158
|
-
}); // Update stats in main task
|
159
|
-
|
160
|
-
await pageBuilder.pageImportExportTask.updateStats(taskId, {
|
161
|
-
prevStatus: prevStatusOfSubTask,
|
162
|
-
nextStatus: _types.PageImportExportTaskStatus.FAILED
|
163
|
-
});
|
164
|
-
prevStatusOfSubTask = subTask.status;
|
165
|
-
}
|
166
|
-
|
167
|
-
return {
|
168
|
-
data: null,
|
169
|
-
error: {
|
170
|
-
message: e.message
|
171
|
-
}
|
172
|
-
};
|
173
|
-
} finally {
|
174
|
-
// Base condition!
|
175
|
-
if (noPendingTask) {
|
176
|
-
log(`No pending sub-task for task ${taskId}`); // Combine individual page zip files.
|
177
|
-
|
178
|
-
await (0, _client.invokeHandlerClient)({
|
179
|
-
context,
|
180
|
-
name: configuration.handlers.combine,
|
181
|
-
payload: {
|
182
|
-
taskId,
|
183
|
-
identity: context.security.getIdentity()
|
184
|
-
}
|
185
|
-
});
|
186
|
-
} else {
|
187
|
-
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`); // We want to continue with Self invocation no matter if current page error out.
|
188
|
-
|
189
|
-
await (0, _client.invokeHandlerClient)({
|
190
|
-
context,
|
191
|
-
name: configuration.handlers.process,
|
192
|
-
payload: {
|
193
|
-
taskId,
|
194
|
-
subTaskIndex: subTaskIndex + 1,
|
195
|
-
identity: context.security.getIdentity()
|
196
|
-
}
|
197
|
-
});
|
198
|
-
}
|
199
|
-
}
|
200
|
-
}
|
201
|
-
|
202
|
-
});
|
203
|
-
|
204
|
-
exports.default = _default;
|
package/exportPages/utils.d.ts
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
import S3 from "aws-sdk/clients/s3";
|
2
|
-
import { Page, File } from "@webiny/api-page-builder/types";
|
3
|
-
import { FileManagerContext } from "@webiny/api-file-manager/types";
|
4
|
-
export declare const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
5
|
-
export interface ExportedPageData {
|
6
|
-
page: Pick<Page, "content" | "title" | "version" | "status" | "settings" | "path">;
|
7
|
-
files: ImageFile[];
|
8
|
-
}
|
9
|
-
export declare function exportPage(page: Page, exportPagesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<S3.ManagedUpload.SendData>;
|
10
|
-
export interface ImageFile extends File {
|
11
|
-
key: string;
|
12
|
-
}
|
13
|
-
export declare function extractFilesFromPageData(data: Record<string, any>, files?: any[]): ImageFile[];
|
package/exportPages/utils.js
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
6
|
-
value: true
|
7
|
-
});
|
8
|
-
exports.EXPORT_PAGES_FOLDER_KEY = void 0;
|
9
|
-
exports.exportPage = exportPage;
|
10
|
-
exports.extractFilesFromPageData = extractFilesFromPageData;
|
11
|
-
|
12
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
13
|
-
|
14
|
-
var _s3Stream = require("./s3Stream");
|
15
|
-
|
16
|
-
var _zipper = _interopRequireDefault(require("./zipper"));
|
17
|
-
|
18
|
-
const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
19
|
-
exports.EXPORT_PAGES_FOLDER_KEY = EXPORT_PAGES_FOLDER_KEY;
|
20
|
-
|
21
|
-
async function getFilteredFiles(files) {
|
22
|
-
const uniqueFileKeys = new Map();
|
23
|
-
const promises = files.map(file => _s3Stream.s3Stream.isFileAccessible(file.key));
|
24
|
-
const isFileAvailableResults = await Promise.all(promises);
|
25
|
-
const filesAvailableForDownload = []; // Filter files
|
26
|
-
|
27
|
-
for (let i = 0; i < files.length; i++) {
|
28
|
-
const file = files[i]; // Check file accessibility
|
29
|
-
|
30
|
-
if (isFileAvailableResults[i] && !uniqueFileKeys.has(file.key)) {
|
31
|
-
filesAvailableForDownload.push(file);
|
32
|
-
uniqueFileKeys.set(file.key, true);
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
return filesAvailableForDownload;
|
37
|
-
}
|
38
|
-
|
39
|
-
async function exportPage(page, exportPagesDataKey, fileManager) {
|
40
|
-
// Extract all files
|
41
|
-
const files = extractFilesFromPageData(page.content); // Filter files
|
42
|
-
|
43
|
-
const filesAvailableForDownload = await getFilteredFiles(files); // Extract images from page settings
|
44
|
-
|
45
|
-
const pageSettingsImages = [(0, _get.default)(page, "settings.general.image"), (0, _get.default)(page, "settings.social.image")].filter(image => image && image.src);
|
46
|
-
const pageSettingsImagesData = []; // Get file data for all images inside "page.settings"
|
47
|
-
|
48
|
-
for (let i = 0; i < pageSettingsImages.length; i++) {
|
49
|
-
const {
|
50
|
-
id
|
51
|
-
} = pageSettingsImages[i];
|
52
|
-
const file = await fileManager.files.getFile(id);
|
53
|
-
pageSettingsImagesData.push(file);
|
54
|
-
} // Extract the page data in a json file and upload it to S3
|
55
|
-
|
56
|
-
|
57
|
-
const pageData = {
|
58
|
-
page: {
|
59
|
-
content: page.content,
|
60
|
-
title: page.title,
|
61
|
-
path: page.path,
|
62
|
-
version: page.version,
|
63
|
-
status: page.status,
|
64
|
-
settings: page.settings
|
65
|
-
},
|
66
|
-
files: [...filesAvailableForDownload, ...pageSettingsImagesData]
|
67
|
-
};
|
68
|
-
const pageDataBuffer = Buffer.from(JSON.stringify(pageData));
|
69
|
-
const zipper = new _zipper.default({
|
70
|
-
exportInfo: {
|
71
|
-
files: [...filesAvailableForDownload, ...pageSettingsImagesData],
|
72
|
-
pageTitle: page.title,
|
73
|
-
pageDataBuffer
|
74
|
-
},
|
75
|
-
archiveFileKey: exportPagesDataKey
|
76
|
-
});
|
77
|
-
return zipper.process();
|
78
|
-
}
|
79
|
-
|
80
|
-
function extractFilesFromPageData(data, files = []) {
|
81
|
-
// Base case: termination
|
82
|
-
if (!data || typeof data !== "object") {
|
83
|
-
return files;
|
84
|
-
} // Recursively call function for each element
|
85
|
-
|
86
|
-
|
87
|
-
if (Array.isArray(data)) {
|
88
|
-
for (let i = 0; i < data.length; i++) {
|
89
|
-
const element = data[i];
|
90
|
-
extractFilesFromPageData(element, files);
|
91
|
-
}
|
92
|
-
|
93
|
-
return files;
|
94
|
-
} // Main
|
95
|
-
|
96
|
-
|
97
|
-
const tuple = Object.entries(data);
|
98
|
-
|
99
|
-
for (let i = 0; i < tuple.length; i++) {
|
100
|
-
const [key, value] = tuple[i]; // TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.
|
101
|
-
|
102
|
-
if (key === "file" && value) {
|
103
|
-
files.push(value);
|
104
|
-
} else if (key === "images" && Array.isArray(value)) {
|
105
|
-
// Handle case for "images-list" component
|
106
|
-
files.push(...value);
|
107
|
-
} else {
|
108
|
-
extractFilesFromPageData(value, files);
|
109
|
-
}
|
110
|
-
}
|
111
|
-
|
112
|
-
return files;
|
113
|
-
}
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import { ContextPlugin } from "@webiny/handler/plugins/ContextPlugin";
|
2
|
-
import { PageImportExportPluginsParams } from "../../types";
|
3
|
-
import { PbPageImportExportContext } from "../types";
|
4
|
-
declare const _default: ({ storageOperations }: PageImportExportPluginsParams) => ContextPlugin<PbPageImportExportContext>;
|
5
|
-
export default _default;
|
package/importPages/client.d.ts
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
import { PbPageImportExportContext } from "../graphql/types";
|
2
|
-
export interface InvokeHandlerClientParams<TParams> {
|
3
|
-
context: PbPageImportExportContext;
|
4
|
-
name: string;
|
5
|
-
payload: TParams;
|
6
|
-
}
|
7
|
-
export declare function invokeHandlerClient<TParams>({ context, name, payload }: InvokeHandlerClientParams<TParams>): Promise<void>;
|
package/importPages/client.js
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
6
|
-
value: true
|
7
|
-
});
|
8
|
-
exports.invokeHandlerClient = invokeHandlerClient;
|
9
|
-
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
-
|
12
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
15
|
-
|
16
|
-
async function invokeHandlerClient({
|
17
|
-
context,
|
18
|
-
name,
|
19
|
-
payload
|
20
|
-
}) {
|
21
|
-
/*
|
22
|
-
* Prepare "invocationArgs", we're hacking our wat here.
|
23
|
-
* They are necessary to setup the "context.pageBuilder" object among other things in IMPORT_PAGE_FUNCTION
|
24
|
-
*/
|
25
|
-
const {
|
26
|
-
request
|
27
|
-
} = context.http;
|
28
|
-
const invocationArgs = {
|
29
|
-
httpMethod: request.method,
|
30
|
-
body: request.body,
|
31
|
-
headers: request.headers,
|
32
|
-
cookies: request.cookies
|
33
|
-
}; // Invoke handler
|
34
|
-
|
35
|
-
await context.handlerClient.invoke({
|
36
|
-
name: name,
|
37
|
-
payload: _objectSpread(_objectSpread({}, payload), invocationArgs),
|
38
|
-
await: false
|
39
|
-
});
|
40
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import { HandlerPlugin } from "@webiny/handler/types";
|
2
|
-
import { ArgsContext } from "@webiny/handler-args/types";
|
3
|
-
import { PageImportExportTask, PbPageImportExportContext } from "../../types";
|
4
|
-
import { SecurityIdentity } from "@webiny/api-security/types";
|
5
|
-
export declare type HandlerArgs = {
|
6
|
-
category: string;
|
7
|
-
zipFileKey?: string;
|
8
|
-
zipFileUrl?: string;
|
9
|
-
task: PageImportExportTask;
|
10
|
-
identity: SecurityIdentity;
|
11
|
-
};
|
12
|
-
export declare type HandlerResponse = {
|
13
|
-
data: string;
|
14
|
-
error: {
|
15
|
-
message: string;
|
16
|
-
};
|
17
|
-
};
|
18
|
-
interface Configuration {
|
19
|
-
handlers: {
|
20
|
-
process: string;
|
21
|
-
};
|
22
|
-
}
|
23
|
-
declare const _default: (configuration: Configuration) => HandlerPlugin<PbPageImportExportContext, ArgsContext<HandlerArgs>>;
|
24
|
-
/**
|
25
|
-
* Handles the import page workflow.
|
26
|
-
*/
|
27
|
-
export default _default;
|
@@ -1,109 +0,0 @@
|
|
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
|
-
|
25
|
-
try {
|
26
|
-
log("RUNNING Import Pages Create");
|
27
|
-
const {
|
28
|
-
invocationArgs: args,
|
29
|
-
pageBuilder
|
30
|
-
} = context;
|
31
|
-
const {
|
32
|
-
task,
|
33
|
-
category,
|
34
|
-
zipFileKey,
|
35
|
-
zipFileUrl,
|
36
|
-
identity
|
37
|
-
} = args;
|
38
|
-
(0, _mockSecurity.mockSecurity)(identity, context); // Step 1: Read the zip file
|
39
|
-
|
40
|
-
const pageImportDataList = await (0, _utils.readExtractAndUploadZipFileContents)(zipFileKey || zipFileUrl); // Once we have map we can start processing each page
|
41
|
-
// For each page create a sub task and invoke the process handler
|
42
|
-
|
43
|
-
for (let i = 0; i < pageImportDataList.length; i++) {
|
44
|
-
const pagesDirMap = pageImportDataList[i]; // Create sub task
|
45
|
-
|
46
|
-
const subtask = await pageBuilder.pageImportExportTask.createSubTask(task.id, (0, _utils.zeroPad)(i + 1), {
|
47
|
-
status: _types.PageImportExportTaskStatus.PENDING,
|
48
|
-
data: {
|
49
|
-
pageKey: pagesDirMap.key,
|
50
|
-
category,
|
51
|
-
zipFileKey,
|
52
|
-
zipFileUrl,
|
53
|
-
input: {
|
54
|
-
fileUploadsData: pagesDirMap
|
55
|
-
}
|
56
|
-
}
|
57
|
-
});
|
58
|
-
log(`Added SUB_TASK "${subtask.id}" to queue.`);
|
59
|
-
} // Update main task status
|
60
|
-
|
61
|
-
|
62
|
-
await pageBuilder.pageImportExportTask.updateTask(task.id, {
|
63
|
-
status: _types.PageImportExportTaskStatus.PROCESSING,
|
64
|
-
stats: (0, _utils.initialStats)(pageImportDataList.length)
|
65
|
-
});
|
66
|
-
await (0, _client.invokeHandlerClient)({
|
67
|
-
context,
|
68
|
-
name: configuration.handlers.process,
|
69
|
-
payload: {
|
70
|
-
taskId: task.id,
|
71
|
-
// Execute "Process" for the first sub task.
|
72
|
-
subTaskIndex: 1,
|
73
|
-
identity: context.security.getIdentity()
|
74
|
-
}
|
75
|
-
});
|
76
|
-
} catch (e) {
|
77
|
-
log("[IMPORT_PAGES_CREATE] Error => ", e);
|
78
|
-
/**
|
79
|
-
* In case of error, we'll update the task status to "failed",
|
80
|
-
* so that, client can show notify the user appropriately.
|
81
|
-
*/
|
82
|
-
|
83
|
-
const {
|
84
|
-
invocationArgs: args,
|
85
|
-
pageBuilder
|
86
|
-
} = context;
|
87
|
-
const {
|
88
|
-
task
|
89
|
-
} = args;
|
90
|
-
await pageBuilder.pageImportExportTask.updateTask(task.id, {
|
91
|
-
status: _types.PageImportExportTaskStatus.FAILED,
|
92
|
-
error: {
|
93
|
-
name: e.name,
|
94
|
-
message: e.message,
|
95
|
-
code: e.code || "EXPORT_FAILED"
|
96
|
-
}
|
97
|
-
});
|
98
|
-
return {
|
99
|
-
data: null,
|
100
|
-
error: {
|
101
|
-
message: e.message
|
102
|
-
}
|
103
|
-
};
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
});
|
108
|
-
|
109
|
-
exports.default = _default;
|
@@ -1,25 +0,0 @@
|
|
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;
|