@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,162 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.default = void 0;
|
9
|
+
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
13
|
+
|
14
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
15
|
+
|
16
|
+
var _ContextPlugin = require("@webiny/handler/plugins/ContextPlugin");
|
17
|
+
|
18
|
+
var _checkBasePermissions = _interopRequireDefault(require("@webiny/api-page-builder/graphql/crud/utils/checkBasePermissions"));
|
19
|
+
|
20
|
+
var _types = require("../../types");
|
21
|
+
|
22
|
+
var _client = require("../../importPages/client");
|
23
|
+
|
24
|
+
var _utils = require("../../importPages/utils");
|
25
|
+
|
26
|
+
var _utils2 = require("../../exportPages/utils");
|
27
|
+
|
28
|
+
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; }
|
29
|
+
|
30
|
+
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; }
|
31
|
+
|
32
|
+
const PERMISSION_NAME = "pb.page";
|
33
|
+
const EXPORT_PAGES_PROCESS_HANDLER = process.env.EXPORT_PAGES_PROCESS_HANDLER;
|
34
|
+
const IMPORT_PAGES_CREATE_HANDLER = process.env.IMPORT_PAGES_CREATE_HANDLER;
|
35
|
+
|
36
|
+
var _default = new _ContextPlugin.ContextPlugin(context => {
|
37
|
+
const importExportCrud = {
|
38
|
+
async importPages({
|
39
|
+
category: categorySlug,
|
40
|
+
zipFileKey,
|
41
|
+
zipFileUrl
|
42
|
+
}) {
|
43
|
+
await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
44
|
+
rwd: "w"
|
45
|
+
}); // Bail out early if category not found
|
46
|
+
|
47
|
+
const category = await context.pageBuilder.categories.get(categorySlug);
|
48
|
+
|
49
|
+
if (!category) {
|
50
|
+
throw new _handlerGraphql.NotFoundError(`Category with slug "${categorySlug}" not found.`);
|
51
|
+
} // Create a task for import page
|
52
|
+
|
53
|
+
|
54
|
+
const task = await context.pageBuilder.pageImportExportTask.createTask({
|
55
|
+
status: _types.PageImportExportTaskStatus.PENDING,
|
56
|
+
input: {
|
57
|
+
category: categorySlug,
|
58
|
+
zipFileKey,
|
59
|
+
zipFileUrl
|
60
|
+
}
|
61
|
+
});
|
62
|
+
await (0, _client.invokeHandlerClient)({
|
63
|
+
context,
|
64
|
+
name: IMPORT_PAGES_CREATE_HANDLER,
|
65
|
+
payload: {
|
66
|
+
category: categorySlug,
|
67
|
+
zipFileKey,
|
68
|
+
zipFileUrl,
|
69
|
+
task,
|
70
|
+
identity: context.security.getIdentity()
|
71
|
+
}
|
72
|
+
});
|
73
|
+
return {
|
74
|
+
task
|
75
|
+
};
|
76
|
+
},
|
77
|
+
|
78
|
+
async exportPages({
|
79
|
+
ids: initialPageIds,
|
80
|
+
revisionType,
|
81
|
+
where,
|
82
|
+
sort,
|
83
|
+
search
|
84
|
+
}) {
|
85
|
+
await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
86
|
+
rwd: "w"
|
87
|
+
});
|
88
|
+
let pageIds = initialPageIds; // If no ids are provided then it means we want to export all pages
|
89
|
+
|
90
|
+
if (!initialPageIds || Array.isArray(initialPageIds) && initialPageIds.length === 0) {
|
91
|
+
pageIds = [];
|
92
|
+
let pages = [];
|
93
|
+
let meta = {
|
94
|
+
hasMoreItems: true,
|
95
|
+
cursor: null
|
96
|
+
}; // Paginate pages
|
97
|
+
|
98
|
+
while (meta.hasMoreItems) {
|
99
|
+
[pages, meta] = await context.pageBuilder.pages.listLatest({
|
100
|
+
after: meta.cursor,
|
101
|
+
where: where,
|
102
|
+
sort: sort,
|
103
|
+
search: search
|
104
|
+
}); // Save page ids
|
105
|
+
|
106
|
+
pages.forEach(page => pageIds.push(page.id));
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
if (pageIds.length === 0) {
|
111
|
+
throw new _error.default("Cannot export pages - no pages found for provided inputs.", "EMPTY_EXPORT_NO_PAGES_FOUND");
|
112
|
+
} // Create the main task for page export.
|
113
|
+
|
114
|
+
|
115
|
+
const task = await context.pageBuilder.pageImportExportTask.createTask({
|
116
|
+
status: _types.PageImportExportTaskStatus.PENDING
|
117
|
+
});
|
118
|
+
const exportPagesDataKey = `${_utils2.EXPORT_PAGES_FOLDER_KEY}/${task.id}`; // For each page create a sub task and invoke the process handler.
|
119
|
+
|
120
|
+
for (let i = 0; i < pageIds.length; i++) {
|
121
|
+
const pageId = pageIds[i]; // Create sub task.
|
122
|
+
|
123
|
+
await context.pageBuilder.pageImportExportTask.createSubTask(task.id, (0, _utils.zeroPad)(i + 1), {
|
124
|
+
status: _types.PageImportExportTaskStatus.PENDING,
|
125
|
+
input: {
|
126
|
+
pageId,
|
127
|
+
exportPagesDataKey,
|
128
|
+
revisionType
|
129
|
+
}
|
130
|
+
});
|
131
|
+
} // Update main task status.
|
132
|
+
|
133
|
+
|
134
|
+
await context.pageBuilder.pageImportExportTask.updateTask(task.id, {
|
135
|
+
status: _types.PageImportExportTaskStatus.PROCESSING,
|
136
|
+
stats: (0, _utils.initialStats)(pageIds.length),
|
137
|
+
input: {
|
138
|
+
exportPagesDataKey,
|
139
|
+
revisionType
|
140
|
+
}
|
141
|
+
}); // Invoke handler.
|
142
|
+
|
143
|
+
await (0, _client.invokeHandlerClient)({
|
144
|
+
context,
|
145
|
+
name: EXPORT_PAGES_PROCESS_HANDLER,
|
146
|
+
payload: {
|
147
|
+
taskId: task.id,
|
148
|
+
subTaskIndex: 1,
|
149
|
+
identity: context.security.getIdentity()
|
150
|
+
}
|
151
|
+
});
|
152
|
+
return {
|
153
|
+
task
|
154
|
+
};
|
155
|
+
}
|
156
|
+
|
157
|
+
}; // Modify context
|
158
|
+
|
159
|
+
context.pageBuilder.pages = _objectSpread(_objectSpread({}, context.pageBuilder.pages), importExportCrud);
|
160
|
+
});
|
161
|
+
|
162
|
+
exports.default = _default;
|
package/graphql/crud.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.default = void 0;
|
9
|
+
|
10
|
+
var _pages = _interopRequireDefault(require("./crud/pages.crud"));
|
11
|
+
|
12
|
+
var _pageImportExportTasks = _interopRequireDefault(require("./crud/pageImportExportTasks.crud"));
|
13
|
+
|
14
|
+
var _default = params => [_pages.default, (0, _pageImportExportTasks.default)(params)];
|
15
|
+
|
16
|
+
exports.default = _default;
|
@@ -0,0 +1,80 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.default = void 0;
|
9
|
+
|
10
|
+
var _resolve = _interopRequireDefault(require("./utils/resolve"));
|
11
|
+
|
12
|
+
const plugin = {
|
13
|
+
type: "graphql-schema",
|
14
|
+
schema: {
|
15
|
+
typeDefs:
|
16
|
+
/* GraphQL */
|
17
|
+
`
|
18
|
+
enum PbPageImportExportTaskStatus {
|
19
|
+
pending
|
20
|
+
processing
|
21
|
+
completed
|
22
|
+
failed
|
23
|
+
}
|
24
|
+
|
25
|
+
type PbPageImportExportTaskStats {
|
26
|
+
pending: Int
|
27
|
+
processing: Int
|
28
|
+
completed: Int
|
29
|
+
failed: Int
|
30
|
+
total: Int
|
31
|
+
}
|
32
|
+
|
33
|
+
type PbPageImportExportTask {
|
34
|
+
id: ID
|
35
|
+
createdOn: DateTime
|
36
|
+
createdBy: PbCreatedBy
|
37
|
+
status: PbPageImportExportTaskStatus
|
38
|
+
data: JSON
|
39
|
+
stats: PbPageImportExportTaskStats
|
40
|
+
error: JSON
|
41
|
+
}
|
42
|
+
|
43
|
+
# Response types
|
44
|
+
type PbPageImportExportTaskResponse {
|
45
|
+
data: PbPageImportExportTask
|
46
|
+
error: PbError
|
47
|
+
}
|
48
|
+
|
49
|
+
type PbPageImportExportTaskListResponse {
|
50
|
+
data: [PbPageImportExportTask]
|
51
|
+
error: PbError
|
52
|
+
}
|
53
|
+
|
54
|
+
extend type PbQuery {
|
55
|
+
getPageImportExportTask(id: ID!): PbPageImportExportTaskResponse
|
56
|
+
listPageImportExportSubTask(
|
57
|
+
id: ID!
|
58
|
+
status: PbPageImportExportTaskStatus
|
59
|
+
limit: Int
|
60
|
+
): PbPageImportExportTaskListResponse
|
61
|
+
}
|
62
|
+
`,
|
63
|
+
resolvers: {
|
64
|
+
PbQuery: {
|
65
|
+
getPageImportExportTask: async (_, args, context) => {
|
66
|
+
return (0, _resolve.default)(() => {
|
67
|
+
return context.pageBuilder.pageImportExportTask.getTask(args.id);
|
68
|
+
});
|
69
|
+
},
|
70
|
+
listPageImportExportSubTask: async (_, args, context) => {
|
71
|
+
return (0, _resolve.default)(() => {
|
72
|
+
return context.pageBuilder.pageImportExportTask.listSubTasks(args.id, args.status, args.limit);
|
73
|
+
});
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
};
|
79
|
+
var _default = plugin;
|
80
|
+
exports.default = _default;
|
@@ -0,0 +1,72 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.default = void 0;
|
9
|
+
|
10
|
+
var _resolve = _interopRequireDefault(require("./utils/resolve"));
|
11
|
+
|
12
|
+
const plugin = {
|
13
|
+
type: "graphql-schema",
|
14
|
+
schema: {
|
15
|
+
typeDefs:
|
16
|
+
/* GraphQL */
|
17
|
+
`
|
18
|
+
type PbExportPageData {
|
19
|
+
task: PbPageImportExportTask
|
20
|
+
}
|
21
|
+
|
22
|
+
type PbExportPageResponse {
|
23
|
+
data: PbExportPageData
|
24
|
+
error: PbError
|
25
|
+
}
|
26
|
+
|
27
|
+
type PbImportPageData {
|
28
|
+
task: PbPageImportExportTask
|
29
|
+
}
|
30
|
+
|
31
|
+
type PbImportPageResponse {
|
32
|
+
data: PbImportPageData
|
33
|
+
error: PbError
|
34
|
+
}
|
35
|
+
|
36
|
+
enum PbExportPageRevisionType {
|
37
|
+
published
|
38
|
+
latest
|
39
|
+
}
|
40
|
+
|
41
|
+
extend type PbMutation {
|
42
|
+
# Export pages
|
43
|
+
exportPages(
|
44
|
+
ids: [ID!]
|
45
|
+
revisionType: PbExportPageRevisionType!
|
46
|
+
where: PbListPagesWhereInput
|
47
|
+
sort: [PbListPagesSort!]
|
48
|
+
search: PbListPagesSearchInput
|
49
|
+
): PbExportPageResponse
|
50
|
+
|
51
|
+
# Import pages
|
52
|
+
importPages(
|
53
|
+
category: String!
|
54
|
+
zipFileKey: String
|
55
|
+
zipFileUrl: String
|
56
|
+
): PbImportPageResponse
|
57
|
+
}
|
58
|
+
`,
|
59
|
+
resolvers: {
|
60
|
+
PbMutation: {
|
61
|
+
exportPages: async (_, args, context) => {
|
62
|
+
return (0, _resolve.default)(() => context.pageBuilder.pages.exportPages(args));
|
63
|
+
},
|
64
|
+
importPages: async (_, args, context) => {
|
65
|
+
return (0, _resolve.default)(() => context.pageBuilder.pages.importPages(args));
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
};
|
71
|
+
var _default = plugin;
|
72
|
+
exports.default = _default;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
9
|
+
|
10
|
+
var _default = async fn => {
|
11
|
+
try {
|
12
|
+
return new _handlerGraphql.Response(await fn());
|
13
|
+
} catch (e) {
|
14
|
+
return new _handlerGraphql.ErrorResponse(e);
|
15
|
+
}
|
16
|
+
};
|
17
|
+
|
18
|
+
exports.default = _default;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.default = void 0;
|
9
|
+
|
10
|
+
var _pages = _interopRequireDefault(require("./graphql/pages.gql"));
|
11
|
+
|
12
|
+
var _pageImportExportTasks = _interopRequireDefault(require("./graphql/pageImportExportTasks.gql"));
|
13
|
+
|
14
|
+
var _default = [_pages.default, _pageImportExportTasks.default];
|
15
|
+
exports.default = _default;
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { PageImportExportPluginsParams } from "./types";
|
2
|
+
declare const _default: (params: PageImportExportPluginsParams) => (import("@webiny/handler/plugins/ContextPlugin").ContextPlugin<import("./types").PbPageImportExportContext>[] | import("@webiny/handler-graphql/types").GraphQLSchemaPlugin<import("@webiny/handler/types").ContextInterface>[])[];
|
3
|
+
export default _default;
|
package/graphql/index.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.default = void 0;
|
9
|
+
|
10
|
+
var _crud = _interopRequireDefault(require("./crud"));
|
11
|
+
|
12
|
+
var _graphql = _interopRequireDefault(require("./graphql"));
|
13
|
+
|
14
|
+
var _default = params => [(0, _crud.default)(params), _graphql.default];
|
15
|
+
|
16
|
+
exports.default = _default;
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import { PagesCrud, PbContext } from "@webiny/api-page-builder/types";
|
2
|
+
import { PageExportRevisionType, PageImportExportTask, PageImportExportTaskStatus, PageImportExportTaskStorageOperations, PageImportExportTaskStorageOperationsListParams } from "../types";
|
3
|
+
export interface ExportPagesParams {
|
4
|
+
ids?: string[];
|
5
|
+
revisionType: PageExportRevisionType;
|
6
|
+
where?: {
|
7
|
+
category?: string;
|
8
|
+
status?: string;
|
9
|
+
tags?: {
|
10
|
+
query: string[];
|
11
|
+
rule?: "any" | "all";
|
12
|
+
};
|
13
|
+
[key: string]: any;
|
14
|
+
};
|
15
|
+
search?: {
|
16
|
+
query?: string;
|
17
|
+
};
|
18
|
+
sort?: string[];
|
19
|
+
}
|
20
|
+
export interface ImportPagesParams {
|
21
|
+
category: string;
|
22
|
+
zipFileKey?: string;
|
23
|
+
zipFileUrl?: string;
|
24
|
+
}
|
25
|
+
export declare type PagesImportExportCrud = {
|
26
|
+
exportPages(params: ExportPagesParams): Promise<{
|
27
|
+
task: PageImportExportTask;
|
28
|
+
}>;
|
29
|
+
importPages(params: ImportPagesParams): Promise<{
|
30
|
+
task: PageImportExportTask;
|
31
|
+
}>;
|
32
|
+
};
|
33
|
+
declare type PageImportExportTaskCreateData = Omit<PageImportExportTask, "id" | "createdOn" | "createdBy">;
|
34
|
+
export declare type PageImportExportTaskCrud = {
|
35
|
+
/**
|
36
|
+
* To be used internally in our code.
|
37
|
+
* @internal
|
38
|
+
*/
|
39
|
+
storageOperations: PageImportExportTaskStorageOperations;
|
40
|
+
getTask(id: string): Promise<PageImportExportTask>;
|
41
|
+
listTasks(params?: PageImportExportTaskStorageOperationsListParams): Promise<PageImportExportTask[]>;
|
42
|
+
createTask(data: Partial<PageImportExportTaskCreateData>): Promise<PageImportExportTask>;
|
43
|
+
updateTask(id: string, data: Partial<PageImportExportTaskCreateData>): Promise<PageImportExportTask>;
|
44
|
+
updateStats(id: string, data: {
|
45
|
+
prevStatus: PageImportExportTaskStatus;
|
46
|
+
nextStatus: PageImportExportTaskStatus;
|
47
|
+
}): Promise<PageImportExportTask>;
|
48
|
+
deleteTask(id: string): Promise<PageImportExportTask>;
|
49
|
+
getSubTask(id: string, subtaskId: string): Promise<PageImportExportTask>;
|
50
|
+
listSubTasks(id: string, status: PageImportExportTaskStatus, limit: number): Promise<PageImportExportTask[]>;
|
51
|
+
createSubTask(id: string, subTaskId: string, data: Partial<PageImportExportTaskCreateData>): Promise<PageImportExportTask>;
|
52
|
+
updateSubTask(id: string, subTaskId: string, data: Partial<PageImportExportTaskCreateData>): Promise<PageImportExportTask>;
|
53
|
+
};
|
54
|
+
export interface PbPageImportExportContext extends PbContext {
|
55
|
+
pageBuilder: PbContext["pageBuilder"] & {
|
56
|
+
pages: PagesCrud & PagesImportExportCrud;
|
57
|
+
pageImportExportTask: PageImportExportTaskCrud;
|
58
|
+
};
|
59
|
+
}
|
60
|
+
export interface PageImportExportPluginsParams {
|
61
|
+
storageOperations: PageImportExportTaskStorageOperations;
|
62
|
+
}
|
63
|
+
export {};
|
package/graphql/types.js
ADDED
@@ -0,0 +1,7 @@
|
|
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>;
|
@@ -0,0 +1,40 @@
|
|
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
|
+
}
|
@@ -0,0 +1,27 @@
|
|
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;
|
@@ -0,0 +1,109 @@
|
|
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;
|