@webiny/api-page-builder-import-export 0.0.0-unstable.2696f9d9e8 → 0.0.0-unstable.2aaa1916d9
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 +1 -1
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.d.ts +2 -2
- package/export/combine/blocksHandler.js.map +1 -1
- package/export/combine/formsHandler.d.ts +2 -2
- package/export/combine/formsHandler.js.map +1 -1
- package/export/combine/index.d.ts +2 -2
- package/export/combine/index.js +2 -2
- package/export/combine/index.js.map +1 -1
- package/export/combine/templatesHandler.d.ts +2 -2
- package/export/combine/templatesHandler.js.map +1 -1
- package/export/pages/ExportPagesCleanup.d.ts +5 -0
- package/export/pages/ExportPagesCleanup.js +82 -0
- package/export/pages/ExportPagesCleanup.js.map +1 -0
- package/export/pages/ExportPagesController.d.ts +5 -0
- package/export/pages/ExportPagesController.js +31 -0
- package/export/pages/ExportPagesController.js.map +1 -0
- package/export/pages/ExportPagesZipPages.d.ts +5 -0
- package/export/pages/ExportPagesZipPages.js +23 -0
- package/export/pages/ExportPagesZipPages.js.map +1 -0
- package/export/pages/controller/CombineZippedPages.d.ts +5 -0
- package/export/pages/controller/CombineZippedPages.js +75 -0
- package/export/pages/controller/CombineZippedPages.js.map +1 -0
- package/export/pages/controller/CreateZipPagesTasks.d.ts +8 -0
- package/export/pages/controller/CreateZipPagesTasks.js +103 -0
- package/export/pages/controller/CreateZipPagesTasks.js.map +1 -0
- package/export/pages/controller/ProcessZipPagesTasks.d.ts +6 -0
- package/export/pages/controller/ProcessZipPagesTasks.js +61 -0
- package/export/pages/controller/ProcessZipPagesTasks.js.map +1 -0
- package/export/pages/types.d.ts +53 -0
- package/export/pages/types.js +26 -0
- package/export/pages/types.js.map +1 -0
- package/export/pages/utils.d.ts +2 -0
- package/export/pages/utils.js +13 -0
- package/export/pages/utils.js.map +1 -0
- package/export/pages/zipPages/ZipPages.d.ts +5 -0
- package/export/pages/zipPages/ZipPages.js +100 -0
- package/export/pages/zipPages/ZipPages.js.map +1 -0
- package/export/pages/zipPages/ZipPagesDataManager.d.ts +14 -0
- package/export/pages/zipPages/ZipPagesDataManager.js +46 -0
- package/export/pages/zipPages/ZipPagesDataManager.js.map +1 -0
- package/export/pages/zipPages/getPageFactory.d.ts +4 -0
- package/export/pages/zipPages/getPageFactory.js +38 -0
- package/export/pages/zipPages/getPageFactory.js.map +1 -0
- package/export/process/blocksHandler.d.ts +2 -2
- package/export/process/blocksHandler.js.map +1 -1
- package/export/process/exporters/BlockExporter.d.ts +2 -2
- package/export/process/exporters/BlockExporter.js.map +1 -1
- package/export/process/exporters/FormExporter.d.ts +2 -2
- package/export/process/exporters/FormExporter.js.map +1 -1
- package/export/process/exporters/PageExporter.d.ts +10 -3
- package/export/process/exporters/PageExporter.js +2 -1
- package/export/process/exporters/PageExporter.js.map +1 -1
- package/export/process/exporters/PageTemplateExporter.d.ts +3 -3
- package/export/process/exporters/PageTemplateExporter.js +3 -1
- package/export/process/exporters/PageTemplateExporter.js.map +1 -1
- package/export/process/formsHandler.d.ts +2 -2
- package/export/process/formsHandler.js.map +1 -1
- package/export/process/index.d.ts +2 -2
- package/export/process/index.js +2 -2
- package/export/process/index.js.map +1 -1
- package/export/process/templatesHandler.d.ts +2 -2
- package/export/process/templatesHandler.js.map +1 -1
- package/export/s3Stream.d.ts +6 -4
- package/export/s3Stream.js +1 -2
- package/export/s3Stream.js.map +1 -1
- package/export/utils.d.ts +4 -4
- package/export/utils.js +7 -9
- package/export/utils.js.map +1 -1
- package/export/zipper.d.ts +3 -2
- package/export/zipper.js.map +1 -1
- package/graphql/crud/blocks.crud.d.ts +1 -1
- package/graphql/crud/blocks.crud.js +1 -2
- package/graphql/crud/blocks.crud.js.map +1 -1
- package/graphql/crud/forms.crud.d.ts +1 -1
- package/graphql/crud/forms.crud.js +1 -2
- package/graphql/crud/forms.crud.js.map +1 -1
- package/graphql/crud/importExportTasks.crud.d.ts +2 -2
- package/graphql/crud/importExportTasks.crud.js +73 -58
- package/graphql/crud/importExportTasks.crud.js.map +1 -1
- package/graphql/crud/pages.crud.d.ts +1 -2
- package/graphql/crud/pages.crud.js +208 -125
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.d.ts +1 -1
- package/graphql/crud/templates.crud.js +1 -2
- package/graphql/crud/templates.crud.js.map +1 -1
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.d.ts +2 -2
- package/graphql/graphql/blocks.gql.js +4 -6
- package/graphql/graphql/blocks.gql.js.map +1 -1
- package/graphql/graphql/forms.gql.d.ts +2 -2
- package/graphql/graphql/forms.gql.js +4 -6
- package/graphql/graphql/forms.gql.js.map +1 -1
- package/graphql/graphql/importExportTasks.gql.d.ts +2 -2
- package/graphql/graphql/importExportTasks.gql.js +5 -7
- package/graphql/graphql/importExportTasks.gql.js.map +1 -1
- package/graphql/graphql/pages.gql.d.ts +2 -2
- package/graphql/graphql/pages.gql.js +101 -14
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.d.ts +2 -2
- package/graphql/graphql/templates.gql.js +4 -6
- package/graphql/graphql/templates.gql.js.map +1 -1
- package/graphql/graphql/utils/resolve.d.ts +3 -3
- package/graphql/graphql/utils/resolve.js +14 -5
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/graphql.d.ts +1 -1
- package/graphql/graphql.js +1 -2
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +2 -1
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +61 -33
- package/graphql/types.js.map +1 -1
- package/import/constants.js +3 -6
- package/import/constants.js.map +1 -1
- package/import/create/blocksHandler.d.ts +2 -2
- package/import/create/blocksHandler.js.map +1 -1
- package/import/create/formsHandler.d.ts +2 -2
- package/import/create/formsHandler.js.map +1 -1
- package/import/create/index.d.ts +2 -2
- package/import/create/index.js +2 -2
- package/import/create/index.js.map +1 -1
- package/import/create/pagesHandler.d.ts +2 -2
- package/import/create/pagesHandler.js.map +1 -1
- package/import/create/templatesHandler.d.ts +2 -2
- package/import/create/templatesHandler.js.map +1 -1
- package/import/pages/ImportPagesController.d.ts +5 -0
- package/import/pages/ImportPagesController.js +29 -0
- package/import/pages/ImportPagesController.js.map +1 -0
- package/import/pages/ImportPagesProcessPages.d.ts +6 -0
- package/import/pages/ImportPagesProcessPages.js +112 -0
- package/import/pages/ImportPagesProcessPages.js.map +1 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.d.ts +6 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.js +40 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.js.map +1 -0
- package/import/pages/controller/ImportPagesProcessZipFile.d.ts +5 -0
- package/import/pages/controller/ImportPagesProcessZipFile.js +71 -0
- package/import/pages/controller/ImportPagesProcessZipFile.js.map +1 -0
- package/import/{process/pages → pages/process}/importPage.d.ts +3 -4
- package/import/pages/process/importPage.js.map +1 -0
- package/import/pages/types.d.ts +48 -0
- package/import/pages/types.js +20 -0
- package/import/pages/types.js.map +1 -0
- package/import/process/blocks/ElementIdsProcessor.d.ts +5 -0
- package/import/process/blocks/ElementIdsProcessor.js +26 -0
- package/import/process/blocks/ElementIdsProcessor.js.map +1 -0
- package/import/process/blocks/blocksHandler.d.ts +2 -2
- package/import/process/blocks/blocksHandler.js.map +1 -1
- package/import/process/blocks/importBlock.d.ts +3 -3
- package/import/process/blocks/importBlock.js +5 -2
- package/import/process/blocks/importBlock.js.map +1 -1
- package/import/process/forms/formsHandler.d.ts +2 -2
- package/import/process/forms/formsHandler.js.map +1 -1
- package/import/process/forms/importForm.d.ts +2 -2
- package/import/process/forms/importForm.js.map +1 -1
- package/import/process/index.d.ts +2 -2
- package/import/process/index.js +2 -2
- package/import/process/index.js.map +1 -1
- package/import/process/templates/importTemplate.d.ts +3 -3
- package/import/process/templates/importTemplate.js.map +1 -1
- package/import/process/templates/templatesHandler.d.ts +2 -2
- package/import/process/templates/templatesHandler.js +3 -1
- package/import/process/templates/templatesHandler.js.map +1 -1
- package/import/utils/deleteS3Folder.js.map +1 -1
- package/import/utils/extractAndUploadZipFileContents.d.ts +1 -1
- package/import/utils/extractAndUploadZipFileContents.js +6 -3
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -1
- package/import/utils/extractZipAndUploadToS3.d.ts +1 -1
- package/import/utils/extractZipAndUploadToS3.js.map +1 -1
- package/import/utils/getFileNameWithoutExt.js.map +1 -1
- package/import/utils/index.js.map +1 -1
- package/import/utils/initialStats.js.map +1 -1
- package/import/utils/prepareDataDirMap.d.ts +1 -1
- package/import/utils/prepareDataDirMap.js.map +1 -1
- package/import/utils/updateFilesInData.d.ts +1 -1
- package/import/utils/updateFilesInData.js.map +1 -1
- package/import/utils/uploadAssets.d.ts +3 -3
- package/import/utils/uploadAssets.js.map +1 -1
- package/import/utils/uploadFilesFromS3.d.ts +3 -3
- package/import/utils/uploadFilesFromS3.js.map +1 -1
- package/mockSecurity.d.ts +1 -1
- package/mockSecurity.js.map +1 -1
- package/package.json +33 -41
- package/tasks/common/ChildTasksCleanup.d.ts +12 -0
- package/tasks/common/ChildTasksCleanup.js +64 -0
- package/tasks/common/ChildTasksCleanup.js.map +1 -0
- package/tasks/index.d.ts +1 -0
- package/tasks/index.js +13 -0
- package/tasks/index.js.map +1 -0
- package/tasks/pages/exportPagesCleanupTask.d.ts +3 -0
- package/tasks/pages/exportPagesCleanupTask.js +36 -0
- package/tasks/pages/exportPagesCleanupTask.js.map +1 -0
- package/tasks/pages/exportPagesControllerTask.d.ts +3 -0
- package/tasks/pages/exportPagesControllerTask.js +83 -0
- package/tasks/pages/exportPagesControllerTask.js.map +1 -0
- package/tasks/pages/exportPagesZipPagesTask.d.ts +3 -0
- package/tasks/pages/exportPagesZipPagesTask.js +39 -0
- package/tasks/pages/exportPagesZipPagesTask.js.map +1 -0
- package/tasks/pages/importPagesControllerTask.d.ts +3 -0
- package/tasks/pages/importPagesControllerTask.js +39 -0
- package/tasks/pages/importPagesControllerTask.js.map +1 -0
- package/tasks/pages/importPagesProcessPageTask.d.ts +3 -0
- package/tasks/pages/importPagesProcessPageTask.js +39 -0
- package/tasks/pages/importPagesProcessPageTask.js.map +1 -0
- package/tasks/pages/index.d.ts +1 -0
- package/tasks/pages/index.js +17 -0
- package/tasks/pages/index.js.map +1 -0
- package/types.d.ts +2 -2
- package/types.js +2 -4
- package/types.js.map +1 -1
- package/utils/ZipFiles.d.ts +11 -0
- package/utils/ZipFiles.js +124 -0
- package/utils/ZipFiles.js.map +1 -0
- package/export/combine/pagesHandler.d.ts +0 -6
- package/export/combine/pagesHandler.js +0 -101
- package/export/combine/pagesHandler.js.map +0 -1
- package/export/process/pagesHandler.d.ts +0 -6
- package/export/process/pagesHandler.js +0 -191
- package/export/process/pagesHandler.js.map +0 -1
- package/import/process/pages/importPage.js.map +0 -1
- package/import/process/pages/pagesHandler.d.ts +0 -3
- package/import/process/pages/pagesHandler.js +0 -185
- package/import/process/pages/pagesHandler.js.map +0 -1
- /package/import/{process/pages → pages/process}/importPage.js +0 -0
|
@@ -4,21 +4,15 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.default =
|
|
7
|
+
exports.default = void 0;
|
|
8
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
9
|
var _pubsub = require("@webiny/pubsub");
|
|
10
10
|
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
11
11
|
var _api = require("@webiny/api");
|
|
12
|
-
var _types = require("../../types");
|
|
13
|
-
var _client = require("../../client");
|
|
14
|
-
var _utils = require("../../import/utils");
|
|
15
|
-
var _utils2 = require("@webiny/utils");
|
|
16
12
|
var _PagesPermissions = require("@webiny/api-page-builder/graphql/crud/permissions/PagesPermissions");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const IMPORT_PAGES_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER;
|
|
21
|
-
var _default = new _api.ContextPlugin(context => {
|
|
13
|
+
var _types = require("../../export/pages/types");
|
|
14
|
+
var _types2 = require("../../import/pages/types");
|
|
15
|
+
var _default = exports.default = new _api.ContextPlugin(context => {
|
|
22
16
|
const pagesPermissions = new _PagesPermissions.PagesPermissions({
|
|
23
17
|
getPermissions: () => context.security.getPermissions("pb.page"),
|
|
24
18
|
getIdentity: context.security.getIdentity,
|
|
@@ -32,11 +26,95 @@ var _default = new _api.ContextPlugin(context => {
|
|
|
32
26
|
// Import
|
|
33
27
|
const onPagesBeforeImport = (0, _pubsub.createTopic)("PageBuilder.onPagesBeforeImport");
|
|
34
28
|
const onPagesAfterImport = (0, _pubsub.createTopic)("PageBuilder.onPagesAfterImport");
|
|
35
|
-
|
|
29
|
+
context.pageBuilder.pages = {
|
|
36
30
|
onPagesBeforeExport,
|
|
37
31
|
onPagesAfterExport,
|
|
38
32
|
onPagesBeforeImport,
|
|
39
33
|
onPagesAfterImport,
|
|
34
|
+
/**
|
|
35
|
+
* Background task implementation.
|
|
36
|
+
*/
|
|
37
|
+
getExportPagesTask: async id => {
|
|
38
|
+
const task = await context.tasks.getTask(id);
|
|
39
|
+
if (!task || task.definitionId !== _types.PageExportTask.Controller) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const totalPages = task.input.totalPages || 0;
|
|
43
|
+
const data = {
|
|
44
|
+
url: task.output?.url,
|
|
45
|
+
error: task.output?.error
|
|
46
|
+
};
|
|
47
|
+
const {
|
|
48
|
+
items: subTasks
|
|
49
|
+
} = await context.tasks.listTasks({
|
|
50
|
+
where: {
|
|
51
|
+
parentId: task.id,
|
|
52
|
+
definitionId: _types.PageExportTask.ZipPages
|
|
53
|
+
},
|
|
54
|
+
limit: 10000
|
|
55
|
+
});
|
|
56
|
+
const stats = {
|
|
57
|
+
completed: [],
|
|
58
|
+
failed: []
|
|
59
|
+
};
|
|
60
|
+
for (const subTask of subTasks) {
|
|
61
|
+
if (!subTask.output) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const completed = Object.keys(subTask.output.done || []);
|
|
65
|
+
const failed = subTask.output.failed || [];
|
|
66
|
+
stats.completed.push(...completed);
|
|
67
|
+
stats.failed.push(...failed);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
...task,
|
|
71
|
+
status: task.taskStatus,
|
|
72
|
+
data,
|
|
73
|
+
stats: {
|
|
74
|
+
total: totalPages,
|
|
75
|
+
completed: stats.completed.length,
|
|
76
|
+
failed: stats.failed.length
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
async getImportPagesTask(id) {
|
|
81
|
+
const task = await context.tasks.getTask(id);
|
|
82
|
+
if (!task || task.definitionId !== _types2.PageImportTask.Controller) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const data = {
|
|
86
|
+
error: task.output?.error
|
|
87
|
+
};
|
|
88
|
+
const {
|
|
89
|
+
items: subTasks
|
|
90
|
+
} = await context.tasks.listTasks({
|
|
91
|
+
where: {
|
|
92
|
+
parentId: task.id,
|
|
93
|
+
definitionId: _types2.PageImportTask.Process
|
|
94
|
+
},
|
|
95
|
+
limit: 10000
|
|
96
|
+
});
|
|
97
|
+
const stats = subTasks.reduce((result, item) => {
|
|
98
|
+
if (!item.output) {
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
...result,
|
|
103
|
+
completed: result.completed + (item.output.done || []).length,
|
|
104
|
+
failed: result.failed + (item.output.failed || []).length
|
|
105
|
+
};
|
|
106
|
+
}, {
|
|
107
|
+
total: task.output?.total || 0,
|
|
108
|
+
completed: 0,
|
|
109
|
+
failed: 0
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
...task,
|
|
113
|
+
status: task.taskStatus,
|
|
114
|
+
data,
|
|
115
|
+
stats
|
|
116
|
+
};
|
|
117
|
+
},
|
|
40
118
|
async importPages(params) {
|
|
41
119
|
const {
|
|
42
120
|
category: categorySlug,
|
|
@@ -52,139 +130,144 @@ var _default = new _api.ContextPlugin(context => {
|
|
|
52
130
|
if (!category) {
|
|
53
131
|
throw new _handlerGraphql.NotFoundError(`Category with slug "${categorySlug}" not found.`);
|
|
54
132
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
133
|
+
const identity = context.security.getIdentity();
|
|
134
|
+
try {
|
|
135
|
+
await onPagesBeforeImport.publish({
|
|
136
|
+
params
|
|
137
|
+
});
|
|
138
|
+
const task = await context.tasks.trigger({
|
|
139
|
+
definition: _types2.PageImportTask.Controller,
|
|
140
|
+
input: {
|
|
141
|
+
category: categorySlug,
|
|
142
|
+
zipFileUrl,
|
|
143
|
+
meta,
|
|
144
|
+
identity: {
|
|
145
|
+
id: identity.id,
|
|
146
|
+
displayName: identity.displayName || "unknown",
|
|
147
|
+
type: identity.type
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
await onPagesAfterImport.publish({
|
|
152
|
+
params
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
task: {
|
|
156
|
+
id: task.id,
|
|
157
|
+
status: task.taskStatus,
|
|
158
|
+
data: {},
|
|
159
|
+
createdOn: task.createdOn,
|
|
160
|
+
createdBy: task.createdBy,
|
|
161
|
+
stats: {
|
|
162
|
+
total: 0,
|
|
163
|
+
completed: 0,
|
|
164
|
+
failed: 0
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
} catch (ex) {
|
|
169
|
+
console.error(ex);
|
|
170
|
+
throw ex;
|
|
171
|
+
}
|
|
91
172
|
},
|
|
92
173
|
async exportPages(params) {
|
|
93
|
-
const {
|
|
94
|
-
ids: initialPageIds,
|
|
95
|
-
revisionType,
|
|
96
|
-
where,
|
|
97
|
-
sort,
|
|
98
|
-
search
|
|
99
|
-
} = params;
|
|
100
174
|
await pagesPermissions.ensure({
|
|
101
175
|
rwd: "w"
|
|
102
176
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
cursor: null,
|
|
111
|
-
totalCount: 0
|
|
112
|
-
};
|
|
113
|
-
// Paginate pages
|
|
114
|
-
while (meta.hasMoreItems) {
|
|
115
|
-
[pages, meta] = await context.pageBuilder.listLatestPages({
|
|
116
|
-
after: meta.cursor,
|
|
117
|
-
where: where,
|
|
118
|
-
sort: sort,
|
|
119
|
-
search: search
|
|
120
|
-
});
|
|
121
|
-
// Save page ids
|
|
122
|
-
pages.forEach(page => pageIds.push(page.id));
|
|
177
|
+
const listPages = input => {
|
|
178
|
+
const {
|
|
179
|
+
revisionType,
|
|
180
|
+
...conditions
|
|
181
|
+
} = input;
|
|
182
|
+
if (revisionType === "published") {
|
|
183
|
+
return context.pageBuilder.listPublishedPages(conditions);
|
|
123
184
|
}
|
|
124
|
-
|
|
125
|
-
|
|
185
|
+
return context.pageBuilder.listLatestPages(conditions);
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* We just need to check if even a single page exists for the provided params.
|
|
189
|
+
* If not, no point in starting a background task.
|
|
190
|
+
*/
|
|
191
|
+
const [pages, meta] = await listPages({
|
|
192
|
+
...params,
|
|
193
|
+
limit: 1
|
|
194
|
+
});
|
|
195
|
+
if (!pages.length || meta.totalCount === 0) {
|
|
126
196
|
throw new _error.default("Cannot export pages - no pages found for provided inputs.", "EMPTY_EXPORT_NO_PAGES_FOUND");
|
|
127
197
|
}
|
|
128
198
|
|
|
129
199
|
// Create the main task for page export.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
for (let i = 0; i < pageIds.length; i++) {
|
|
136
|
-
const pageId = pageIds[i];
|
|
137
|
-
// Create sub-task.
|
|
138
|
-
await context.pageBuilder.importExportTask.createSubTask(task.id, (0, _utils2.zeroPad)(i + 1, 5), {
|
|
139
|
-
status: _types.ImportExportTaskStatus.PENDING,
|
|
200
|
+
try {
|
|
201
|
+
await onPagesBeforeExport.publish({
|
|
202
|
+
params
|
|
203
|
+
});
|
|
204
|
+
const task = await context.tasks.trigger({
|
|
140
205
|
input: {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
206
|
+
...params,
|
|
207
|
+
type: params.revisionType,
|
|
208
|
+
totalPages: meta.totalCount
|
|
209
|
+
},
|
|
210
|
+
definition: _types.PageExportTask.Controller
|
|
211
|
+
});
|
|
212
|
+
await onPagesAfterExport.publish({
|
|
213
|
+
params
|
|
145
214
|
});
|
|
215
|
+
return {
|
|
216
|
+
task: {
|
|
217
|
+
id: task.id,
|
|
218
|
+
status: task.taskStatus,
|
|
219
|
+
data: {},
|
|
220
|
+
createdOn: task.createdOn,
|
|
221
|
+
createdBy: task.createdBy,
|
|
222
|
+
stats: {
|
|
223
|
+
total: meta.totalCount,
|
|
224
|
+
completed: 0,
|
|
225
|
+
failed: 0
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
} catch (ex) {
|
|
230
|
+
console.error(ex);
|
|
231
|
+
throw ex;
|
|
146
232
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
*/
|
|
162
|
-
await onPagesBeforeExport.publish({
|
|
163
|
-
params
|
|
233
|
+
},
|
|
234
|
+
listImportedPages: async taskId => {
|
|
235
|
+
const task = await context.tasks.getTask(taskId);
|
|
236
|
+
if (!task || task.definitionId !== _types2.PageImportTask.Controller) {
|
|
237
|
+
throw new _handlerGraphql.NotFoundError(`Task with id "${taskId}" not found.`);
|
|
238
|
+
}
|
|
239
|
+
const {
|
|
240
|
+
items: subTasks
|
|
241
|
+
} = await context.tasks.listTasks({
|
|
242
|
+
where: {
|
|
243
|
+
parentId: task.id,
|
|
244
|
+
definitionId: _types2.PageImportTask.Process
|
|
245
|
+
},
|
|
246
|
+
limit: 10000
|
|
164
247
|
});
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
248
|
+
const pageIdList = subTasks.reduce((collection, subTask) => {
|
|
249
|
+
if (!subTask.output?.pageIdList) {
|
|
250
|
+
return collection;
|
|
251
|
+
}
|
|
252
|
+
collection.push(...subTask.output.pageIdList);
|
|
253
|
+
return collection;
|
|
254
|
+
}, []);
|
|
255
|
+
const result = await context.pageBuilder.listLatestPages({
|
|
256
|
+
where: {
|
|
257
|
+
pid_in: pageIdList
|
|
174
258
|
},
|
|
175
|
-
|
|
259
|
+
limit: 10000
|
|
176
260
|
});
|
|
177
|
-
|
|
178
|
-
|
|
261
|
+
const [pages] = result;
|
|
262
|
+
return pages.map(page => {
|
|
263
|
+
return {
|
|
264
|
+
id: page.id,
|
|
265
|
+
title: page.title,
|
|
266
|
+
version: page.version
|
|
267
|
+
};
|
|
179
268
|
});
|
|
180
|
-
return {
|
|
181
|
-
task
|
|
182
|
-
};
|
|
183
269
|
}
|
|
184
270
|
};
|
|
185
|
-
// Modify context
|
|
186
|
-
context.pageBuilder.pages = importExportCrud;
|
|
187
271
|
});
|
|
188
|
-
exports.default = _default;
|
|
189
272
|
|
|
190
273
|
//# sourceMappingURL=pages.crud.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_error","_interopRequireDefault","require","_pubsub","_handlerGraphql","_api","_types","_client","_utils","_utils2","_PagesPermissions","EXPORT_PAGES_FOLDER_KEY","exports","EXPORT_PAGES_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_PAGES_CREATE_HANDLER","IMPORT_CREATE_HANDLER","_default","ContextPlugin","context","pagesPermissions","PagesPermissions","getPermissions","security","getIdentity","fullAccessPermissionName","onPagesBeforeExport","createTopic","onPagesAfterExport","onPagesBeforeImport","onPagesAfterImport","importExportCrud","importPages","params","category","categorySlug","zipFileUrl","meta","ensure","rwd","pageBuilder","getCategory","NotFoundError","task","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","publish","invokeHandlerClient","name","payload","type","identity","description","exportPages","ids","initialPageIds","revisionType","where","sort","search","pageIds","Array","isArray","length","pages","hasMoreItems","cursor","totalCount","listLatestPages","after","forEach","page","push","id","WebinyError","exportPagesDataKey","i","pageId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex","default"],"sources":["pages.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport {\n ImportExportTaskStatus,\n PagesImportExportCrud,\n PbImportExportContext,\n OnPagesBeforeExportTopicParams,\n OnPagesAfterExportTopicParams,\n OnPagesBeforeImportTopicParams,\n OnPagesAfterImportTopicParams\n} from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { Payload as CreateHandlerPayload } from \"~/import/create\";\nimport { initialStats } from \"~/import/utils\";\nimport { Payload as ExportPagesProcessHandlerPayload } from \"~/export/process\";\nimport { MetaResponse } from \"@webiny/api-page-builder/types\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { PagesPermissions } from \"@webiny/api-page-builder/graphql/crud/permissions/PagesPermissions\";\n\nexport const EXPORT_PAGES_FOLDER_KEY = \"WEBINY_PB_EXPORT_PAGES\";\nconst EXPORT_PAGES_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER as string;\nconst IMPORT_PAGES_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER as string;\n\nexport default new ContextPlugin<PbImportExportContext>(context => {\n const pagesPermissions = new PagesPermissions({\n getPermissions: () => context.security.getPermissions(\"pb.page\"),\n getIdentity: context.security.getIdentity,\n fullAccessPermissionName: \"pb.*\"\n });\n\n // Export\n const onPagesBeforeExport = createTopic<OnPagesBeforeExportTopicParams>(\n \"PageBuilder.onPagesBeforeExport\"\n );\n const onPagesAfterExport = createTopic<OnPagesAfterExportTopicParams>(\n \"PageBuilder.onPagesAfterExport\"\n );\n\n // Import\n const onPagesBeforeImport = createTopic<OnPagesBeforeImportTopicParams>(\n \"PageBuilder.onPagesBeforeImport\"\n );\n const onPagesAfterImport = createTopic<OnPagesAfterImportTopicParams>(\n \"PageBuilder.onPagesAfterImport\"\n );\n\n const importExportCrud: PagesImportExportCrud = {\n onPagesBeforeExport,\n onPagesAfterExport,\n onPagesBeforeImport,\n onPagesAfterImport,\n async importPages(params) {\n const { category: categorySlug, zipFileUrl, meta } = params;\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n // Bail out early if category not found\n const category = await context.pageBuilder.getCategory(categorySlug);\n if (!category) {\n throw new NotFoundError(`Category with slug \"${categorySlug}\" not found.`);\n }\n\n // Create a task for import page\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING,\n input: {\n category: categorySlug,\n zipFileUrl\n }\n });\n /**\n * Import Pages\n * ImportPages\n * importPages\n */\n await onPagesBeforeImport.publish({ params });\n await invokeHandlerClient<CreateHandlerPayload>({\n context,\n name: IMPORT_PAGES_CREATE_HANDLER,\n payload: {\n category: categorySlug,\n zipFileUrl,\n task,\n type: \"page\",\n identity: context.security.getIdentity(),\n meta\n },\n description: \"Import Pages - create\"\n });\n await onPagesAfterImport.publish({ params });\n\n return {\n task\n };\n },\n\n async exportPages(params) {\n const { ids: initialPageIds, revisionType, where, sort, search } = params;\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n let pageIds: string[] = initialPageIds || [];\n // If no ids are provided then it means we want to export all pages\n if (!initialPageIds || (Array.isArray(initialPageIds) && initialPageIds.length === 0)) {\n pageIds = [];\n let pages = [];\n let meta: MetaResponse = {\n hasMoreItems: true,\n cursor: null,\n totalCount: 0\n };\n // Paginate pages\n while (meta.hasMoreItems) {\n [pages, meta] = await context.pageBuilder.listLatestPages({\n after: meta.cursor,\n where: where,\n sort: sort,\n search: search\n });\n // Save page ids\n pages.forEach(page => pageIds.push(page.id));\n }\n }\n\n if (pageIds.length === 0) {\n throw new WebinyError(\n \"Cannot export pages - no pages found for provided inputs.\",\n \"EMPTY_EXPORT_NO_PAGES_FOUND\"\n );\n }\n\n // Create the main task for page export.\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING\n });\n const exportPagesDataKey = `${EXPORT_PAGES_FOLDER_KEY}/${task.id}`;\n // For each page create a sub-task and invoke the process handler.\n for (let i = 0; i < pageIds.length; i++) {\n const pageId = pageIds[i];\n // Create sub-task.\n await context.pageBuilder.importExportTask.createSubTask(\n task.id,\n zeroPad(i + 1, 5),\n {\n status: ImportExportTaskStatus.PENDING,\n input: {\n pageId,\n exportPagesDataKey,\n revisionType\n }\n }\n );\n }\n // Update main task status.\n await context.pageBuilder.importExportTask.updateTask(task.id, {\n status: ImportExportTaskStatus.PROCESSING,\n stats: initialStats(pageIds.length),\n input: {\n exportPagesDataKey,\n revisionType\n }\n });\n\n /**\n * Export Pages\n * ExportPages\n * exportPages\n */\n await onPagesBeforeExport.publish({ params });\n // Invoke handler.\n await invokeHandlerClient<ExportPagesProcessHandlerPayload>({\n context,\n name: EXPORT_PAGES_PROCESS_HANDLER,\n payload: {\n taskId: task.id,\n subTaskIndex: 1,\n type: \"page\",\n identity: context.security.getIdentity()\n },\n description: \"Export pages - process\"\n });\n await onPagesAfterExport.publish({ params });\n\n return { task };\n }\n };\n // Modify context\n context.pageBuilder.pages = importExportCrud;\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AASA,IAAAK,OAAA,GAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AAGA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,iBAAA,GAAAR,OAAA;AAEO,MAAMS,uBAAuB,GAAG,wBAAwB;AAACC,OAAA,CAAAD,uBAAA,GAAAA,uBAAA;AAChE,MAAME,4BAA4B,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAgC;AACjF,MAAMC,2BAA2B,GAAGH,OAAO,CAACC,GAAG,CAACG,qBAA+B;AAAC,IAAAC,QAAA,GAEjE,IAAIC,kBAAa,CAAwBC,OAAO,IAAI;EAC/D,MAAMC,gBAAgB,GAAG,IAAIC,kCAAgB,CAAC;IAC1CC,cAAc,EAAEA,CAAA,KAAMH,OAAO,CAACI,QAAQ,CAACD,cAAc,CAAC,SAAS,CAAC;IAChEE,WAAW,EAAEL,OAAO,CAACI,QAAQ,CAACC,WAAW;IACzCC,wBAAwB,EAAE;EAC9B,CAAC,CAAC;;EAEF;EACA,MAAMC,mBAAmB,GAAG,IAAAC,mBAAW,EACnC,iCACJ,CAAC;EACD,MAAMC,kBAAkB,GAAG,IAAAD,mBAAW,EAClC,gCACJ,CAAC;;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AE;MACjB,CAAC,CAAC;MACF,MAAM5B,kBAAkB,CAACsB,OAAO,CAAC;QAAEjB;MAAO,CAAC,CAAC;MAE5C,OAAO;QAAEU;MAAK,CAAC;IACnB;EACJ,CAAC;EACD;EACAxB,OAAO,CAACqB,WAAW,CAAC4B,KAAK,GAAGrC,gBAAgB;AAChD,CAAC,CAAC;AAAArB,OAAA,CAAAgF,OAAA,GAAAzE,QAAA"}
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_pubsub","_handlerGraphql","_api","_PagesPermissions","_types","_types2","_default","exports","default","ContextPlugin","context","pagesPermissions","PagesPermissions","getPermissions","security","getIdentity","fullAccessPermissionName","onPagesBeforeExport","createTopic","onPagesAfterExport","onPagesBeforeImport","onPagesAfterImport","pageBuilder","pages","getExportPagesTask","id","task","tasks","getTask","definitionId","PageExportTask","Controller","totalPages","input","data","url","output","error","items","subTasks","listTasks","where","parentId","ZipPages","limit","stats","completed","failed","subTask","Object","keys","done","push","status","taskStatus","total","length","getImportPagesTask","PageImportTask","Process","reduce","result","item","importPages","params","category","categorySlug","zipFileUrl","meta","ensure","rwd","getCategory","NotFoundError","identity","publish","trigger","definition","displayName","type","createdOn","createdBy","ex","console","exportPages","listPages","revisionType","conditions","listPublishedPages","listLatestPages","totalCount","WebinyError","listImportedPages","taskId","pageIdList","collection","pid_in","map","page","title","version"],"sources":["pages.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport type {\n ExportPagesParams,\n OnPagesAfterExportTopicParams,\n OnPagesAfterImportTopicParams,\n OnPagesBeforeExportTopicParams,\n OnPagesBeforeImportTopicParams,\n PbExportPagesTaskData,\n PbImportExportContext,\n PbImportPagesTaskData,\n PbImportPagesTaskStats\n} from \"~/types\";\nimport { PagesPermissions } from \"@webiny/api-page-builder/graphql/crud/permissions/PagesPermissions\";\nimport type {\n IExportPagesControllerInput,\n IExportPagesControllerOutput,\n IExportPagesZipPagesInput,\n IExportPagesZipPagesOutput\n} from \"~/export/pages/types\";\nimport { PageExportTask } from \"~/export/pages/types\";\nimport type {\n IImportPagesControllerInput,\n IImportPagesControllerOutput,\n IImportPagesProcessPagesInput,\n IImportPagesProcessPagesOutput\n} from \"~/import/pages/types\";\nimport { PageImportTask } from \"~/import/pages/types\";\n\nexport default new ContextPlugin<PbImportExportContext>(context => {\n const pagesPermissions = new PagesPermissions({\n getPermissions: () => context.security.getPermissions(\"pb.page\"),\n getIdentity: context.security.getIdentity,\n fullAccessPermissionName: \"pb.*\"\n });\n\n // Export\n const onPagesBeforeExport = createTopic<OnPagesBeforeExportTopicParams>(\n \"PageBuilder.onPagesBeforeExport\"\n );\n const onPagesAfterExport = createTopic<OnPagesAfterExportTopicParams>(\n \"PageBuilder.onPagesAfterExport\"\n );\n\n // Import\n const onPagesBeforeImport = createTopic<OnPagesBeforeImportTopicParams>(\n \"PageBuilder.onPagesBeforeImport\"\n );\n const onPagesAfterImport = createTopic<OnPagesAfterImportTopicParams>(\n \"PageBuilder.onPagesAfterImport\"\n );\n\n context.pageBuilder.pages = {\n onPagesBeforeExport,\n onPagesAfterExport,\n onPagesBeforeImport,\n onPagesAfterImport,\n /**\n * Background task implementation.\n */\n getExportPagesTask: async id => {\n const task = await context.tasks.getTask<\n IExportPagesControllerInput,\n IExportPagesControllerOutput\n >(id);\n\n if (!task || task.definitionId !== PageExportTask.Controller) {\n return null;\n }\n\n const totalPages = task.input.totalPages || 0;\n\n const data: PbExportPagesTaskData = {\n url: task.output?.url,\n error: task.output?.error\n };\n\n const { items: subTasks } = await context.tasks.listTasks<\n IExportPagesZipPagesInput,\n IExportPagesZipPagesOutput\n >({\n where: {\n parentId: task.id,\n definitionId: PageExportTask.ZipPages\n },\n limit: 10000\n });\n\n const stats = {\n completed: [] as string[],\n failed: [] as string[]\n };\n\n for (const subTask of subTasks) {\n if (!subTask.output) {\n continue;\n }\n const completed = Object.keys(subTask.output.done || []);\n const failed = subTask.output.failed || [];\n\n stats.completed.push(...completed);\n stats.failed.push(...failed);\n }\n\n return {\n ...task,\n status: task.taskStatus,\n data,\n stats: {\n total: totalPages,\n completed: stats.completed.length,\n failed: stats.failed.length\n }\n };\n },\n async getImportPagesTask(id) {\n const task = await context.tasks.getTask<\n IImportPagesControllerInput,\n IImportPagesControllerOutput\n >(id);\n\n if (!task || task.definitionId !== PageImportTask.Controller) {\n return null;\n }\n\n const data: PbImportPagesTaskData = {\n error: task.output?.error\n };\n\n const { items: subTasks } = await context.tasks.listTasks<\n IImportPagesProcessPagesInput,\n IImportPagesProcessPagesOutput\n >({\n where: {\n parentId: task.id,\n definitionId: PageImportTask.Process\n },\n limit: 10000\n });\n\n const stats = subTasks.reduce<PbImportPagesTaskStats>(\n (result, item) => {\n if (!item.output) {\n return result;\n }\n return {\n ...result,\n completed: result.completed + (item.output.done || []).length,\n failed: result.failed + (item.output.failed || []).length\n };\n },\n {\n total: task.output?.total || 0,\n completed: 0,\n failed: 0\n }\n );\n\n return {\n ...task,\n status: task.taskStatus,\n data,\n stats\n };\n },\n async importPages(params) {\n const { category: categorySlug, zipFileUrl, meta } = params;\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n // Bail out early if category not found\n const category = await context.pageBuilder.getCategory(categorySlug);\n if (!category) {\n throw new NotFoundError(`Category with slug \"${categorySlug}\" not found.`);\n }\n\n const identity = context.security.getIdentity();\n\n try {\n await onPagesBeforeImport.publish({ params });\n const task = await context.tasks.trigger<IImportPagesControllerInput>({\n definition: PageImportTask.Controller,\n input: {\n category: categorySlug,\n zipFileUrl,\n meta,\n identity: {\n id: identity.id,\n displayName: identity.displayName || \"unknown\",\n type: identity.type\n }\n }\n });\n await onPagesAfterImport.publish({ params });\n return {\n task: {\n id: task.id,\n status: task.taskStatus,\n data: {},\n createdOn: task.createdOn,\n createdBy: task.createdBy,\n stats: {\n total: 0,\n completed: 0,\n failed: 0\n }\n }\n };\n } catch (ex) {\n console.error(ex);\n throw ex;\n }\n },\n\n async exportPages(params) {\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n const listPages = (input: ExportPagesParams) => {\n const { revisionType, ...conditions } = input;\n if (revisionType === \"published\") {\n return context.pageBuilder.listPublishedPages(conditions);\n }\n return context.pageBuilder.listLatestPages(conditions);\n };\n /**\n * We just need to check if even a single page exists for the provided params.\n * If not, no point in starting a background task.\n */\n const [pages, meta] = await listPages({\n ...params,\n limit: 1\n });\n if (!pages.length || meta.totalCount === 0) {\n throw new WebinyError(\n \"Cannot export pages - no pages found for provided inputs.\",\n \"EMPTY_EXPORT_NO_PAGES_FOUND\"\n );\n }\n\n // Create the main task for page export.\n try {\n await onPagesBeforeExport.publish({ params });\n const task = await context.tasks.trigger<IExportPagesControllerInput>({\n input: {\n ...params,\n type: params.revisionType,\n totalPages: meta.totalCount\n },\n definition: PageExportTask.Controller\n });\n await onPagesAfterExport.publish({ params });\n return {\n task: {\n id: task.id,\n status: task.taskStatus,\n data: {},\n createdOn: task.createdOn,\n createdBy: task.createdBy,\n stats: {\n total: meta.totalCount,\n completed: 0,\n failed: 0\n }\n }\n };\n } catch (ex) {\n console.error(ex);\n throw ex;\n }\n },\n listImportedPages: async taskId => {\n const task = await context.tasks.getTask<\n IImportPagesControllerInput,\n IImportPagesControllerOutput\n >(taskId);\n\n if (!task || task.definitionId !== PageImportTask.Controller) {\n throw new NotFoundError(`Task with id \"${taskId}\" not found.`);\n }\n const { items: subTasks } = await context.tasks.listTasks<\n IImportPagesProcessPagesInput,\n IImportPagesProcessPagesOutput\n >({\n where: {\n parentId: task.id,\n definitionId: PageImportTask.Process\n },\n limit: 10000\n });\n const pageIdList = subTasks.reduce<string[]>((collection, subTask) => {\n if (!subTask.output?.pageIdList) {\n return collection;\n }\n collection.push(...subTask.output.pageIdList);\n return collection;\n }, []);\n\n const result = await context.pageBuilder.listLatestPages({\n where: {\n pid_in: pageIdList\n },\n limit: 10000\n });\n\n const [pages] = result;\n return pages.map(page => {\n return {\n id: page.id,\n title: page.title,\n version: page.version\n };\n });\n }\n };\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AAYA,IAAAI,iBAAA,GAAAJ,OAAA;AAOA,IAAAK,MAAA,GAAAL,OAAA;AAOA,IAAAM,OAAA,GAAAN,OAAA;AAAsD,IAAAO,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEvC,IAAIC,kBAAa,CAAwBC,OAAO,IAAI;EAC/D,MAAMC,gBAAgB,GAAG,IAAIC,kCAAgB,CAAC;IAC1CC,cAAc,EAAEA,CAAA,KAAMH,OAAO,CAACI,QAAQ,CAACD,cAAc,CAAC,SAAS,CAAC;IAChEE,WAAW,EAAEL,OAAO,CAACI,QAAQ,CAACC,WAAW;IACzCC,wBAAwB,EAAE;EAC9B,CAAC,CAAC;;EAEF;EACA,MAAMC,mBAAmB,GAAG,IAAAC,mBAAW,EACnC,iCACJ,CAAC;EACD,MAAMC,kBAAkB,GAAG,IAAAD,mBAAW,EAClC,gCACJ,CAAC;;EAED;EACA,MAAME,mBAAmB,GAAG,IAAAF,mBAAW,EACnC,iCACJ,CAAC;EACD,MAAMG,kBAAkB,GAAG,IAAAH,mBAAW,EAClC,gCACJ,CAAC;EAEDR,OAAO,CAACY,WAAW,CAACC,KAAK,GAAG;IACxBN,mBAAmB;IACnBE,kBAAkB;IAClBC,mBAAmB;IACnBC,kBAAkB;IAClB;AACR;AACA;IACQG,kBAAkB,EAAE,MAAMC,EAAE,IAAI;MAC5B,MAAMC,IAAI,GAAG,MAAMhB,OAAO,CAACiB,KAAK,CAACC,OAAO,CAGtCH,EAAE,CAAC;MAEL,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACG,YAAY,KAAKC,qBAAc,CAACC,UAAU,EAAE;QAC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I,CAAC,GAAGJ,OAAO,CAACZ,MAAM,CAACyD,UAAU,CAAC;QAC7C,OAAOC,UAAU;MACrB,CAAC,EAAE,EAAE,CAAC;MAEN,MAAMjC,MAAM,GAAG,MAAMnD,OAAO,CAACY,WAAW,CAACkE,eAAe,CAAC;QACrD/C,KAAK,EAAE;UACHsD,MAAM,EAAEF;QACZ,CAAC;QACDjD,KAAK,EAAE;MACX,CAAC,CAAC;MAEF,MAAM,CAACrB,KAAK,CAAC,GAAGsC,MAAM;MACtB,OAAOtC,KAAK,CAACyE,GAAG,CAACC,IAAI,IAAI;QACrB,OAAO;UACHxE,EAAE,EAAEwE,IAAI,CAACxE,EAAE;UACXyE,KAAK,EAAED,IAAI,CAACC,KAAK;UACjBC,OAAO,EAAEF,IAAI,CAACE;QAClB,CAAC;MACL,CAAC,CAAC;IACN;EACJ,CAAC;AACL,CAAC,CAAC","ignoreList":[]}
|
|
@@ -16,7 +16,7 @@ var _PageTemplatesPermissions = require("@webiny/api-page-builder/graphql/crud/p
|
|
|
16
16
|
const EXPORT_TEMPLATES_FOLDER_KEY = "WEBINY_PB_EXPORT_TEMPLATE";
|
|
17
17
|
const EXPORT_TEMPLATES_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER;
|
|
18
18
|
const IMPORT_TEMPLATES_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER;
|
|
19
|
-
var _default = new _api.ContextPlugin(context => {
|
|
19
|
+
var _default = exports.default = new _api.ContextPlugin(context => {
|
|
20
20
|
const pagesPermissions = new _PageTemplatesPermissions.PageTemplatesPermissions({
|
|
21
21
|
getPermissions: () => context.security.getPermissions("pb.template"),
|
|
22
22
|
getIdentity: context.security.getIdentity,
|
|
@@ -152,6 +152,5 @@ var _default = new _api.ContextPlugin(context => {
|
|
|
152
152
|
// Modify context
|
|
153
153
|
context.pageBuilder.templates = importExportCrud;
|
|
154
154
|
});
|
|
155
|
-
exports.default = _default;
|
|
156
155
|
|
|
157
156
|
//# sourceMappingURL=templates.crud.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_error","_interopRequireDefault","require","_pubsub","_api","_types","_client","_utils","_utils2","_PageTemplatesPermissions","EXPORT_TEMPLATES_FOLDER_KEY","EXPORT_TEMPLATES_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_TEMPLATES_CREATE_HANDLER","IMPORT_CREATE_HANDLER","_default","ContextPlugin","context","pagesPermissions","PageTemplatesPermissions","getPermissions","security","getIdentity","fullAccessPermissionName","onTemplatesBeforeExport","createTopic","onTemplatesAfterExport","onTemplatesBeforeImport","onTemplatesAfterImport","importExportCrud","importTemplates","params","zipFileUrl","ensure","rwd","task","pageBuilder","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","publish","invokeHandlerClient","name","payload","type","identity","description","exportTemplates","ids","initialTemplateIds","templateIds","Array","isArray","length","templates","listPageTemplates","forEach","template","push","id","WebinyError","exportTemplatesDataKey","i","templateId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex","exports","default"],"sources":["templates.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport {\n ImportExportTaskStatus,\n TemplatesImportExportCrud,\n PbImportExportContext,\n OnTemplatesBeforeExportTopicParams,\n OnTemplatesAfterExportTopicParams,\n OnTemplatesBeforeImportTopicParams,\n OnTemplatesAfterImportTopicParams\n} from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { Payload as CreateHandlerPayload } from \"~/import/create\";\nimport { initialStats } from \"~/import/utils\";\nimport { Payload as ExportTemplatesProcessHandlerPayload } from \"~/export/process\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { PageTemplatesPermissions } from \"@webiny/api-page-builder/graphql/crud/permissions/PageTemplatesPermissions\";\n\nconst EXPORT_TEMPLATES_FOLDER_KEY = \"WEBINY_PB_EXPORT_TEMPLATE\";\nconst EXPORT_TEMPLATES_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER as string;\nconst IMPORT_TEMPLATES_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER as string;\n\nexport default new ContextPlugin<PbImportExportContext>(context => {\n const pagesPermissions = new PageTemplatesPermissions({\n getPermissions: () => context.security.getPermissions(\"pb.template\"),\n getIdentity: context.security.getIdentity,\n fullAccessPermissionName: \"pb.*\"\n });\n\n // Export\n const onTemplatesBeforeExport = createTopic<OnTemplatesBeforeExportTopicParams>(\n \"PageBuilder.onTemplatesBeforeExport\"\n );\n const onTemplatesAfterExport = createTopic<OnTemplatesAfterExportTopicParams>(\n \"PageBuilder.onTemplatesAfterExport\"\n );\n\n // Import\n const onTemplatesBeforeImport = createTopic<OnTemplatesBeforeImportTopicParams>(\n \"PageBuilder.onTemplatesBeforeImport\"\n );\n const onTemplatesAfterImport = createTopic<OnTemplatesAfterImportTopicParams>(\n \"PageBuilder.onTemplatesAfterImport\"\n );\n\n const importExportCrud: TemplatesImportExportCrud = {\n onTemplatesBeforeExport,\n onTemplatesAfterExport,\n onTemplatesBeforeImport,\n onTemplatesAfterImport,\n async importTemplates(params) {\n const { zipFileUrl } = params;\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n // Create a task for import template\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING,\n input: {\n zipFileUrl\n }\n });\n /**\n * Import Templates\n * ImportTemplates\n * importTemplates\n */\n await onTemplatesBeforeImport.publish({ params });\n await invokeHandlerClient<CreateHandlerPayload>({\n context,\n name: IMPORT_TEMPLATES_CREATE_HANDLER,\n payload: {\n zipFileUrl,\n task,\n type: \"template\",\n identity: context.security.getIdentity()\n },\n description: \"Import Templates - create\"\n });\n await onTemplatesAfterImport.publish({ params });\n\n return {\n task\n };\n },\n\n async exportTemplates(params) {\n const { ids: initialTemplateIds } = params;\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n let templateIds: string[] = initialTemplateIds || [];\n // If no ids are provided then it means we want to export all templates\n if (\n !initialTemplateIds ||\n (Array.isArray(initialTemplateIds) && initialTemplateIds.length === 0)\n ) {\n templateIds = [];\n const templates = await context.pageBuilder.listPageTemplates();\n // Save template ids\n templates.forEach(template => templateIds.push(template.id));\n }\n\n if (templateIds.length === 0) {\n throw new WebinyError(\n \"Cannot export templates - no templates found for provided inputs.\",\n \"EMPTY_EXPORT_NO_TEMPLATES_FOUND\"\n );\n }\n\n // Create the main task for templates export.\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING\n });\n const exportTemplatesDataKey = `${EXPORT_TEMPLATES_FOLDER_KEY}/${task.id}`;\n // For each template create a sub task and invoke the process handler.\n for (let i = 0; i < templateIds.length; i++) {\n const templateId = templateIds[i];\n // Create sub task.\n await context.pageBuilder.importExportTask.createSubTask(\n task.id,\n zeroPad(i + 1, 5),\n {\n status: ImportExportTaskStatus.PENDING,\n input: {\n templateId,\n exportTemplatesDataKey\n }\n }\n );\n }\n // Update main task status.\n await context.pageBuilder.importExportTask.updateTask(task.id, {\n status: ImportExportTaskStatus.PROCESSING,\n stats: initialStats(templateIds.length),\n input: {\n exportTemplatesDataKey\n }\n });\n\n /**\n * Export Templates\n * ExportTemplates\n * exportTemplates\n */\n await onTemplatesBeforeExport.publish({ params });\n // Invoke handler.\n await invokeHandlerClient<ExportTemplatesProcessHandlerPayload>({\n context,\n name: EXPORT_TEMPLATES_PROCESS_HANDLER,\n payload: {\n taskId: task.id,\n subTaskIndex: 1,\n type: \"template\",\n identity: context.security.getIdentity()\n },\n description: \"Export templates - process\"\n });\n await onTemplatesAfterExport.publish({ params });\n\n return { task };\n }\n };\n // Modify context\n context.pageBuilder.templates = importExportCrud;\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GA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QACD2B,WAAW,EAAE;MACjB,CAAC,CAAC;MACF,MAAMvB,sBAAsB,CAACiB,OAAO,CAAC;QAAEZ;MAAO,CAAC,CAAC;MAEhD,OAAO;QAAEI;MAAK,CAAC;IACnB;EACJ,CAAC;EACD;EACAlB,OAAO,CAACmB,WAAW,CAACqB,SAAS,GAAG5B,gBAAgB;AACpD,CAAC,CAAC;AAAA8C,OAAA,CAAAC,OAAA,GAAA7D,QAAA"}
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_pubsub","_api","_types","_client","_utils","_utils2","_PageTemplatesPermissions","EXPORT_TEMPLATES_FOLDER_KEY","EXPORT_TEMPLATES_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_TEMPLATES_CREATE_HANDLER","IMPORT_CREATE_HANDLER","_default","exports","default","ContextPlugin","context","pagesPermissions","PageTemplatesPermissions","getPermissions","security","getIdentity","fullAccessPermissionName","onTemplatesBeforeExport","createTopic","onTemplatesAfterExport","onTemplatesBeforeImport","onTemplatesAfterImport","importExportCrud","importTemplates","params","zipFileUrl","ensure","rwd","task","pageBuilder","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","publish","invokeHandlerClient","name","payload","type","identity","description","exportTemplates","ids","initialTemplateIds","templateIds","Array","isArray","length","templates","listPageTemplates","forEach","template","push","id","WebinyError","exportTemplatesDataKey","i","templateId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex"],"sources":["templates.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport type {\n TemplatesImportExportCrud,\n PbImportExportContext,\n OnTemplatesBeforeExportTopicParams,\n OnTemplatesAfterExportTopicParams,\n OnTemplatesBeforeImportTopicParams,\n OnTemplatesAfterImportTopicParams\n} from \"~/types\";\nimport { ImportExportTaskStatus } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport type { Payload as CreateHandlerPayload } from \"~/import/create\";\nimport { initialStats } from \"~/import/utils\";\nimport type { Payload as ExportTemplatesProcessHandlerPayload } from \"~/export/process\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { PageTemplatesPermissions } from \"@webiny/api-page-builder/graphql/crud/permissions/PageTemplatesPermissions\";\n\nconst EXPORT_TEMPLATES_FOLDER_KEY = \"WEBINY_PB_EXPORT_TEMPLATE\";\nconst EXPORT_TEMPLATES_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER as string;\nconst IMPORT_TEMPLATES_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER as string;\n\nexport default new ContextPlugin<PbImportExportContext>(context => {\n const pagesPermissions = new PageTemplatesPermissions({\n getPermissions: () => context.security.getPermissions(\"pb.template\"),\n getIdentity: context.security.getIdentity,\n fullAccessPermissionName: \"pb.*\"\n });\n\n // Export\n const onTemplatesBeforeExport = createTopic<OnTemplatesBeforeExportTopicParams>(\n \"PageBuilder.onTemplatesBeforeExport\"\n );\n const onTemplatesAfterExport = createTopic<OnTemplatesAfterExportTopicParams>(\n \"PageBuilder.onTemplatesAfterExport\"\n );\n\n // Import\n const onTemplatesBeforeImport = createTopic<OnTemplatesBeforeImportTopicParams>(\n \"PageBuilder.onTemplatesBeforeImport\"\n );\n const onTemplatesAfterImport = createTopic<OnTemplatesAfterImportTopicParams>(\n \"PageBuilder.onTemplatesAfterImport\"\n );\n\n const importExportCrud: TemplatesImportExportCrud = {\n onTemplatesBeforeExport,\n onTemplatesAfterExport,\n onTemplatesBeforeImport,\n onTemplatesAfterImport,\n async importTemplates(params) {\n const { zipFileUrl } = params;\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n // Create a task for import template\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING,\n input: {\n zipFileUrl\n }\n });\n /**\n * Import Templates\n * ImportTemplates\n * importTemplates\n */\n await onTemplatesBeforeImport.publish({ params });\n await invokeHandlerClient<CreateHandlerPayload>({\n context,\n name: IMPORT_TEMPLATES_CREATE_HANDLER,\n payload: {\n zipFileUrl,\n task,\n type: \"template\",\n identity: context.security.getIdentity()\n },\n description: \"Import Templates - create\"\n });\n await onTemplatesAfterImport.publish({ params });\n\n return {\n task\n };\n },\n\n async exportTemplates(params) {\n const { ids: initialTemplateIds } = params;\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n let templateIds: string[] = initialTemplateIds || [];\n // If no ids are provided then it means we want to export all templates\n if (\n !initialTemplateIds ||\n (Array.isArray(initialTemplateIds) && initialTemplateIds.length === 0)\n ) {\n templateIds = [];\n const templates = await context.pageBuilder.listPageTemplates();\n // Save template ids\n templates.forEach(template => templateIds.push(template.id));\n }\n\n if (templateIds.length === 0) {\n throw new WebinyError(\n \"Cannot export templates - no templates found for provided inputs.\",\n \"EMPTY_EXPORT_NO_TEMPLATES_FOUND\"\n );\n }\n\n // Create the main task for templates export.\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING\n });\n const exportTemplatesDataKey = `${EXPORT_TEMPLATES_FOLDER_KEY}/${task.id}`;\n // For each template create a sub task and invoke the process handler.\n for (let i = 0; i < templateIds.length; i++) {\n const templateId = templateIds[i];\n // Create sub task.\n await context.pageBuilder.importExportTask.createSubTask(\n task.id,\n zeroPad(i + 1, 5),\n {\n status: ImportExportTaskStatus.PENDING,\n input: {\n templateId,\n exportTemplatesDataKey\n }\n }\n );\n }\n // Update main task status.\n await context.pageBuilder.importExportTask.updateTask(task.id, {\n status: ImportExportTaskStatus.PROCESSING,\n stats: initialStats(templateIds.length),\n input: {\n exportTemplatesDataKey\n }\n });\n\n /**\n * Export Templates\n * ExportTemplates\n * exportTemplates\n */\n await onTemplatesBeforeExport.publish({ params });\n // Invoke handler.\n await invokeHandlerClient<ExportTemplatesProcessHandlerPayload>({\n context,\n name: EXPORT_TEMPLATES_PROCESS_HANDLER,\n payload: {\n taskId: task.id,\n subTaskIndex: 1,\n type: \"template\",\n identity: context.security.getIdentity()\n },\n description: \"Export templates - process\"\n });\n await onTemplatesAfterExport.publish({ params });\n\n return { task };\n }\n };\n // Modify context\n context.pageBuilder.templates = importExportCrud;\n});\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AASA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AAEA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,yBAAA,GAAAP,OAAA;AAEA,MAAMQ,2BAA2B,GAAG,2BAA2B;AAC/D,MAAMC,gCAAgC,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAgC;AACrF,MAAMC,+BAA+B,GAAGH,OAAO,CAACC,GAAG,CAACG,qBAA+B;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAErE,IAAIC,kBAAa,CAAwBC,OAAO,IAAI;EAC/D,MAAMC,gBAAgB,GAAG,IAAIC,kDAAwB,CAAC;IAClDC,cAAc,EAAEA,CAAA,KAAMH,OAAO,CAACI,QAAQ,CAACD,cAAc,CAAC,aAAa,CAAC;IACpEE,WAAW,EAAEL,OAAO,CAACI,QAAQ,CAACC,WAAW;IACzCC,wBAAwB,EAAE;EAC9B,CAAC,CAAC;;EAEF;EACA,MAAMC,uBAAuB,GAAG,IAAAC,mBAAW,EACvC,qCACJ,CAAC;EACD,MAAMC,sBAAsB,GAAG,IAAAD,mBAAW,EACtC,oCACJ,CAAC;;EAED;EACA,MAAME,uBAAuB,GAAG,IAAAF,mBAAW,EACvC,qCACJ,CAAC;EACD,MAAMG,sBAAsB,GAAG,IAAAH,mBAAW,EACtC,oCACJ,CAAC;EAED,MAAMI,gBAA2C,GAAG;IAChDL,uBAAuB;IACvBE,sBAAsB;IACtBC,uBAAuB;IACvBC,sBAAsB;IACtB,MAAME,eAAe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O,CAAC,CAAC;MACjD;MACA,MAAM,IAAAa,2BAAmB,EAAuC;QAC5D3B,OAAO;QACP4B,IAAI,EAAEtC,gCAAgC;QACtCuC,OAAO,EAAE;UACL2B,MAAM,EAAEtC,IAAI,CAAC2B,EAAE;UACfY,YAAY,EAAE,CAAC;UACf3B,IAAI,EAAE,UAAU;UAChBC,QAAQ,EAAE/B,OAAO,CAACI,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACD2B,WAAW,EAAE;MACjB,CAAC,CAAC;MACF,MAAMvB,sBAAsB,CAACiB,OAAO,CAAC;QAAEZ;MAAO,CAAC,CAAC;MAEhD,OAAO;QAAEI;MAAK,CAAC;IACnB;EACJ,CAAC;EACD;EACAlB,OAAO,CAACmB,WAAW,CAACqB,SAAS,GAAG5B,gBAAgB;AACpD,CAAC,CAAC","ignoreList":[]}
|
package/graphql/crud.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ImportExportPluginsParams } from "./types";
|
|
2
|
-
declare const _default: (params: ImportExportPluginsParams) => import("@webiny/api").ContextPlugin<import("
|
|
1
|
+
import type { ImportExportPluginsParams } from "./types";
|
|
2
|
+
declare const _default: (params: ImportExportPluginsParams) => import("@webiny/api").ContextPlugin<import("./types").PbImportExportContext>[];
|
|
3
3
|
export default _default;
|
package/graphql/crud.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blocks","_interopRequireDefault","require","_forms","_pages","_templates","_importExportTasks","_default","params","blocks","forms","pages","templates","importExportTask","exports","default"],"sources":["crud.ts"],"sourcesContent":["import blocks from \"./crud/blocks.crud\";\nimport forms from \"./crud/forms.crud\";\nimport pages from \"./crud/pages.crud\";\nimport templates from \"./crud/templates.crud\";\nimport importExportTask from \"./crud/importExportTasks.crud\";\nimport { ImportExportPluginsParams } from \"~/graphql/types\";\n\nexport default (params: ImportExportPluginsParams) => [\n blocks,\n forms,\n pages,\n templates,\n importExportTask(params
|
|
1
|
+
{"version":3,"names":["_blocks","_interopRequireDefault","require","_forms","_pages","_templates","_importExportTasks","_default","params","blocks","forms","pages","templates","importExportTask","exports","default"],"sources":["crud.ts"],"sourcesContent":["import blocks from \"./crud/blocks.crud\";\nimport forms from \"./crud/forms.crud\";\nimport pages from \"./crud/pages.crud\";\nimport templates from \"./crud/templates.crud\";\nimport importExportTask from \"./crud/importExportTasks.crud\";\nimport type { ImportExportPluginsParams } from \"~/graphql/types\";\n\nexport default (params: ImportExportPluginsParams) => [\n blocks,\n forms,\n pages,\n templates,\n importExportTask(params)\n];\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,UAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,kBAAA,GAAAL,sBAAA,CAAAC,OAAA;AAA6D,IAAAK,QAAA,GAG7CC,MAAiC,IAAK,CAClDC,eAAM,EACNC,cAAK,EACLC,cAAK,EACLC,kBAAS,EACT,IAAAC,0BAAgB,EAACL,MAAM,CAAC,CAC3B;AAAAM,OAAA,CAAAC,OAAA,GAAAR,QAAA","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql/types";
|
|
2
|
-
import { PbImportExportContext } from "../types";
|
|
1
|
+
import type { GraphQLSchemaPlugin } from "@webiny/handler-graphql/types";
|
|
2
|
+
import type { PbImportExportContext } from "../types";
|
|
3
3
|
declare const plugin: GraphQLSchemaPlugin<PbImportExportContext>;
|
|
4
4
|
export default plugin;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
|
-
var _resolve =
|
|
7
|
+
var _resolve = require("./utils/resolve");
|
|
9
8
|
const plugin = {
|
|
10
9
|
type: "graphql-schema",
|
|
11
10
|
schema: {
|
|
@@ -39,16 +38,15 @@ const plugin = {
|
|
|
39
38
|
resolvers: {
|
|
40
39
|
PbMutation: {
|
|
41
40
|
exportBlocks: async (_, args, context) => {
|
|
42
|
-
return (0, _resolve.
|
|
41
|
+
return (0, _resolve.resolve)(() => context.pageBuilder.blocks.exportBlocks(args));
|
|
43
42
|
},
|
|
44
43
|
importBlocks: async (_, args, context) => {
|
|
45
|
-
return (0, _resolve.
|
|
44
|
+
return (0, _resolve.resolve)(() => context.pageBuilder.blocks.importBlocks(args));
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
};
|
|
51
|
-
var _default = plugin;
|
|
52
|
-
exports.default = _default;
|
|
50
|
+
var _default = exports.default = plugin;
|
|
53
51
|
|
|
54
52
|
//# sourceMappingURL=blocks.gql.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_resolve","
|
|
1
|
+
{"version":3,"names":["_resolve","require","plugin","type","schema","typeDefs","resolvers","PbMutation","exportBlocks","_","args","context","resolve","pageBuilder","blocks","importBlocks","_default","exports","default"],"sources":["blocks.gql.ts"],"sourcesContent":["import type { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\nimport type { PbImportExportContext } from \"../types\";\nimport { resolve } from \"./utils/resolve\";\n\nconst plugin: GraphQLSchemaPlugin<PbImportExportContext> = {\n type: \"graphql-schema\",\n schema: {\n typeDefs: /* GraphQL */ `\n type PbExportBlockData {\n task: PbImportExportTask\n }\n\n type PbExportBlockResponse {\n data: PbExportBlockData\n error: PbError\n }\n\n type PbImportBlockData {\n task: PbImportExportTask\n }\n\n type PbImportBlockResponse {\n data: PbImportBlockData\n error: PbError\n }\n\n extend type PbMutation {\n # Export blocks\n exportBlocks(ids: [ID!], where: PbListPageBlocksWhereInput): PbExportBlockResponse\n\n # Import blocks\n importBlocks(zipFileUrl: String): PbImportBlockResponse\n }\n `,\n resolvers: {\n PbMutation: {\n exportBlocks: async (_, args: any, context) => {\n return resolve(() => context.pageBuilder.blocks.exportBlocks(args));\n },\n\n importBlocks: async (_, args: any, context) => {\n return resolve(() => context.pageBuilder.blocks.importBlocks(args));\n }\n }\n }\n }\n};\n\nexport default plugin;\n"],"mappings":";;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AAEA,MAAMC,MAAkD,GAAG;EACvDC,IAAI,EAAE,gBAAgB;EACtBC,MAAM,EAAE;IACJC,QAAQ,EAAE,aAAc;AAChC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;IACDC,SAAS,EAAE;MACPC,UAAU,EAAE;QACRC,YAAY,EAAE,MAAAA,CAAOC,CAAC,EAAEC,IAAS,EAAEC,OAAO,KAAK;UAC3C,OAAO,IAAAC,gBAAO,EAAC,MAAMD,OAAO,CAACE,WAAW,CAACC,MAAM,CAACN,YAAY,CAACE,IAAI,CAAC,CAAC;QACvE,CAAC;QAEDK,YAAY,EAAE,MAAAA,CAAON,CAAC,EAAEC,IAAS,EAAEC,OAAO,KAAK;UAC3C,OAAO,IAAAC,gBAAO,EAAC,MAAMD,OAAO,CAACE,WAAW,CAACC,MAAM,CAACC,YAAY,CAACL,IAAI,CAAC,CAAC;QACvE;MACJ;IACJ;EACJ;AACJ,CAAC;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEahB,MAAM","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql/types";
|
|
2
|
-
import { PbImportExportContext } from "../types";
|
|
1
|
+
import type { GraphQLSchemaPlugin } from "@webiny/handler-graphql/types";
|
|
2
|
+
import type { PbImportExportContext } from "../types";
|
|
3
3
|
declare const plugin: GraphQLSchemaPlugin<PbImportExportContext>;
|
|
4
4
|
export default plugin;
|