@webiny/api-page-builder-import-export 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.99666aeb00
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +2 -2
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.d.ts +6 -0
- package/export/combine/blocksHandler.js +99 -0
- package/export/combine/blocksHandler.js.map +1 -0
- package/export/combine/formsHandler.d.ts +6 -0
- package/export/combine/formsHandler.js +99 -0
- package/export/combine/formsHandler.js.map +1 -0
- package/{exportPages → export}/combine/index.d.ts +3 -2
- package/export/combine/index.js +42 -0
- package/export/combine/index.js.map +1 -0
- package/export/combine/pagesHandler.d.ts +6 -0
- package/export/combine/pagesHandler.js +99 -0
- package/export/combine/pagesHandler.js.map +1 -0
- package/export/combine/templatesHandler.d.ts +6 -0
- package/export/combine/templatesHandler.js +99 -0
- package/export/combine/templatesHandler.js.map +1 -0
- package/export/process/blocksHandler.d.ts +6 -0
- package/export/process/blocksHandler.js +162 -0
- package/export/process/blocksHandler.js.map +1 -0
- package/export/process/formsHandler.d.ts +6 -0
- package/export/process/formsHandler.js +187 -0
- package/export/process/formsHandler.js.map +1 -0
- package/{exportPages → export}/process/index.d.ts +4 -6
- package/export/process/index.js +39 -0
- package/export/process/index.js.map +1 -0
- package/export/process/pagesHandler.d.ts +6 -0
- package/export/process/pagesHandler.js +189 -0
- package/export/process/pagesHandler.js.map +1 -0
- package/export/process/templatesHandler.d.ts +6 -0
- package/export/process/templatesHandler.js +166 -0
- package/export/process/templatesHandler.js.map +1 -0
- package/{exportPages → export}/s3Stream.d.ts +5 -2
- package/export/s3Stream.js.map +1 -0
- package/export/utils.d.ts +29 -0
- package/export/utils.js +194 -0
- package/export/utils.js.map +1 -0
- package/{exportPages → export}/zipper.d.ts +6 -5
- package/{exportPages → export}/zipper.js +9 -8
- package/export/zipper.js.map +1 -0
- package/graphql/crud/blocks.crud.d.ts +4 -0
- package/graphql/crud/blocks.crud.js +140 -0
- package/graphql/crud/blocks.crud.js.map +1 -0
- package/graphql/crud/forms.crud.d.ts +4 -0
- package/graphql/crud/forms.crud.js +134 -0
- package/graphql/crud/forms.crud.js.map +1 -0
- package/graphql/crud/importExportTasks.crud.d.ts +5 -0
- package/graphql/crud/{pageImportExportTasks.crud.js → importExportTasks.crud.js} +83 -79
- package/graphql/crud/importExportTasks.crud.js.map +1 -0
- package/graphql/crud/pages.crud.d.ts +2 -2
- package/graphql/crud/pages.crud.js +26 -18
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.d.ts +4 -0
- package/graphql/crud/templates.crud.js +128 -0
- package/graphql/crud/templates.crud.js.map +1 -0
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js +5 -2
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.d.ts +4 -0
- package/graphql/graphql/blocks.gql.js +52 -0
- package/graphql/graphql/blocks.gql.js.map +1 -0
- package/graphql/graphql/forms.gql.d.ts +4 -0
- package/graphql/graphql/forms.gql.js +60 -0
- package/graphql/graphql/forms.gql.js.map +1 -0
- package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
- package/graphql/graphql/{pageImportExportTasks.gql.js → importExportTasks.gql.js} +17 -17
- package/graphql/graphql/importExportTasks.gql.js.map +1 -0
- package/graphql/graphql/pages.gql.d.ts +2 -2
- package/graphql/graphql/pages.gql.js +3 -9
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.d.ts +4 -0
- package/graphql/graphql/templates.gql.js +52 -0
- package/graphql/graphql/templates.gql.js.map +1 -0
- package/graphql/graphql/utils/resolve.d.ts +1 -1
- package/graphql/graphql.js +5 -2
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +83 -23
- package/graphql/types.js.map +1 -1
- package/import/constants.d.ts +3 -0
- package/import/constants.js +14 -0
- package/import/constants.js.map +1 -0
- package/import/create/blocksHandler.d.ts +3 -0
- package/import/create/blocksHandler.js +101 -0
- package/import/create/blocksHandler.js.map +1 -0
- package/import/create/formsHandler.d.ts +3 -0
- package/import/create/formsHandler.js +103 -0
- package/import/create/formsHandler.js.map +1 -0
- package/{importPages → import}/create/index.d.ts +7 -5
- package/import/create/index.js +42 -0
- package/import/create/index.js.map +1 -0
- package/import/create/pagesHandler.d.ts +3 -0
- package/import/create/pagesHandler.js +103 -0
- package/import/create/pagesHandler.js.map +1 -0
- package/import/create/templatesHandler.d.ts +3 -0
- package/import/create/templatesHandler.js +99 -0
- package/import/create/templatesHandler.js.map +1 -0
- package/import/process/blocks/blocksHandler.d.ts +3 -0
- package/import/process/blocks/blocksHandler.js +169 -0
- package/import/process/blocks/blocksHandler.js.map +1 -0
- package/import/process/blocks/importBlock.d.ts +11 -0
- package/import/process/blocks/importBlock.js +92 -0
- package/import/process/blocks/importBlock.js.map +1 -0
- package/import/process/forms/formsHandler.d.ts +3 -0
- package/import/process/forms/formsHandler.js +176 -0
- package/import/process/forms/formsHandler.js.map +1 -0
- package/import/process/forms/importForm.d.ts +9 -0
- package/import/process/forms/importForm.js +43 -0
- package/import/process/forms/importForm.js.map +1 -0
- package/{importPages → import}/process/index.d.ts +5 -3
- package/import/process/index.js +39 -0
- package/import/process/index.js.map +1 -0
- package/import/process/pages/importPage.d.ts +11 -0
- package/import/process/pages/importPage.js +92 -0
- package/import/process/pages/importPage.js.map +1 -0
- package/import/process/pages/pagesHandler.d.ts +3 -0
- package/import/process/pages/pagesHandler.js +183 -0
- package/import/process/pages/pagesHandler.js.map +1 -0
- package/import/process/templates/importTemplate.d.ts +11 -0
- package/import/process/templates/importTemplate.js +66 -0
- package/import/process/templates/importTemplate.js.map +1 -0
- package/import/process/templates/templatesHandler.d.ts +3 -0
- package/import/process/templates/templatesHandler.js +170 -0
- package/import/process/templates/templatesHandler.js.map +1 -0
- package/import/utils/deleteS3Folder.d.ts +1 -0
- package/import/utils/deleteS3Folder.js +19 -0
- package/import/utils/deleteS3Folder.js.map +1 -0
- package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
- package/import/utils/extractAndUploadZipFileContents.js +122 -0
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
- package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
- package/import/utils/extractZipAndUploadToS3.js +98 -0
- package/import/utils/extractZipAndUploadToS3.js.map +1 -0
- package/import/utils/getFileNameWithoutExt.d.ts +1 -0
- package/import/utils/getFileNameWithoutExt.js +11 -0
- package/import/utils/getFileNameWithoutExt.js.map +1 -0
- package/import/utils/index.d.ts +9 -0
- package/import/utils/index.js +104 -0
- package/import/utils/index.js.map +1 -0
- package/import/utils/initialStats.d.ts +7 -0
- package/import/utils/initialStats.js +16 -0
- package/import/utils/initialStats.js.map +1 -0
- package/import/utils/prepareDataDirMap.d.ts +6 -0
- package/import/utils/prepareDataDirMap.js +29 -0
- package/import/utils/prepareDataDirMap.js.map +1 -0
- package/import/utils/updateFilesInData.d.ts +8 -0
- package/import/utils/updateFilesInData.js +48 -0
- package/import/utils/updateFilesInData.js.map +1 -0
- package/import/utils/uploadAssets.d.ts +10 -0
- package/import/utils/uploadAssets.js +49 -0
- package/import/utils/uploadAssets.js.map +1 -0
- package/import/utils/uploadFilesFromS3.d.ts +3 -0
- package/import/utils/uploadFilesFromS3.js +19 -0
- package/import/utils/uploadFilesFromS3.js.map +1 -0
- package/mockSecurity.js +0 -1
- package/mockSecurity.js.map +1 -1
- package/package.json +34 -37
- package/types.d.ts +83 -65
- package/types.js +17 -17
- package/types.js.map +1 -1
- package/exportPages/combine/index.js +0 -106
- package/exportPages/combine/index.js.map +0 -1
- package/exportPages/process/index.js +0 -192
- package/exportPages/process/index.js.map +0 -1
- package/exportPages/s3Stream.js.map +0 -1
- package/exportPages/utils.d.ts +0 -13
- package/exportPages/utils.js +0 -100
- package/exportPages/utils.js.map +0 -1
- package/exportPages/zipper.js.map +0 -1
- package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
- package/graphql/crud/pageImportExportTasks.crud.js.map +0 -1
- package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
- package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
- package/importPages/create/index.js +0 -107
- package/importPages/create/index.js.map +0 -1
- package/importPages/process/index.js +0 -180
- package/importPages/process/index.js.map +0 -1
- package/importPages/utils.d.ts +0 -50
- package/importPages/utils.js +0 -488
- package/importPages/utils.js.map +0 -1
- /package/{exportPages → export}/s3Stream.js +0 -0
@@ -6,21 +6,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
});
|
7
7
|
exports.default = void 0;
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
9
|
-
var
|
9
|
+
var _utils = require("@webiny/utils");
|
10
10
|
var _fields = require("@commodo/fields");
|
11
11
|
var _commodoFieldsObject = require("commodo-fields-object");
|
12
12
|
var _validation = require("@webiny/validation");
|
13
13
|
var _api = require("@webiny/api");
|
14
|
-
var _checkBasePermissions = _interopRequireDefault(require("@webiny/api-page-builder/graphql/crud/utils/checkBasePermissions"));
|
15
|
-
var _checkOwnPermissions = _interopRequireDefault(require("@webiny/api-page-builder/graphql/crud/utils/checkOwnPermissions"));
|
16
14
|
var _handlerGraphql = require("@webiny/handler-graphql");
|
17
15
|
var _types = require("../../types");
|
18
16
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
19
|
-
|
20
|
-
* Package mdbid does not have types.
|
21
|
-
*/
|
22
|
-
// @ts-ignore
|
23
|
-
|
17
|
+
var _PagesPermissions = require("@webiny/api-page-builder/graphql/crud/permissions/PagesPermissions");
|
24
18
|
/**
|
25
19
|
* Package @commodo/fields does not have types.
|
26
20
|
*/
|
@@ -31,7 +25,7 @@ var _error = _interopRequireDefault(require("@webiny/error"));
|
|
31
25
|
*/
|
32
26
|
// @ts-ignore
|
33
27
|
|
34
|
-
const validStatus = `${_types.
|
28
|
+
const validStatus = `${_types.ImportExportTaskStatus.PENDING}:${_types.ImportExportTaskStatus.PROCESSING}:${_types.ImportExportTaskStatus.COMPLETED}:${_types.ImportExportTaskStatus.FAILED}`;
|
35
29
|
const CreateDataModel = (0, _fields.withFields)({
|
36
30
|
status: (0, _fields.string)({
|
37
31
|
validation: _validation.validation.create(`required,in:${validStatus}`)
|
@@ -50,7 +44,6 @@ const UpdateDataModel = (0, _fields.withFields)({
|
|
50
44
|
stats: (0, _commodoFieldsObject.object)(),
|
51
45
|
error: (0, _commodoFieldsObject.object)()
|
52
46
|
})();
|
53
|
-
const PERMISSION_NAME = "pb.page";
|
54
47
|
var _default = ({
|
55
48
|
storageOperations
|
56
49
|
}) => new _api.ContextPlugin(async context => {
|
@@ -58,22 +51,27 @@ var _default = ({
|
|
58
51
|
* If pageBuilder is not defined on the context, do not continue, but log it.
|
59
52
|
*/
|
60
53
|
if (!context.pageBuilder) {
|
61
|
-
console.log("Missing pageBuilder on context. Skipping
|
54
|
+
console.log("Missing pageBuilder on context. Skipping ImportExportTasks crud.");
|
62
55
|
return;
|
63
56
|
}
|
57
|
+
const pagesPermissions = new _PagesPermissions.PagesPermissions({
|
58
|
+
getPermissions: () => context.security.getPermissions("pb.page"),
|
59
|
+
getIdentity: context.security.getIdentity,
|
60
|
+
fullAccessPermissionName: "pb.*"
|
61
|
+
});
|
64
62
|
const getLocale = () => {
|
65
63
|
const locale = context.i18n.getContentLocale();
|
66
64
|
if (!locale) {
|
67
|
-
throw new _error.default("Missing content locale in
|
65
|
+
throw new _error.default("Missing content locale in importExportTasks.crud.ts", "LOCALE_ERROR");
|
68
66
|
}
|
69
67
|
return locale;
|
70
68
|
};
|
71
69
|
|
72
70
|
// Modify context
|
73
|
-
context.pageBuilder.
|
71
|
+
context.pageBuilder.importExportTask = {
|
74
72
|
storageOperations,
|
75
73
|
async getTask(id) {
|
76
|
-
|
74
|
+
await pagesPermissions.ensure({
|
77
75
|
rwd: "r"
|
78
76
|
});
|
79
77
|
const tenant = context.tenancy.getCurrentTenant();
|
@@ -85,23 +83,24 @@ var _default = ({
|
|
85
83
|
id
|
86
84
|
}
|
87
85
|
};
|
88
|
-
let
|
86
|
+
let importExportTask = null;
|
89
87
|
try {
|
90
|
-
|
91
|
-
if (!
|
88
|
+
importExportTask = await storageOperations.getTask(params);
|
89
|
+
if (!importExportTask) {
|
92
90
|
return null;
|
93
91
|
}
|
94
92
|
} catch (ex) {
|
95
|
-
throw new _error.default(ex.message || "Could not get
|
93
|
+
throw new _error.default(ex.message || "Could not get importExportTask by id.", ex.code || "GET_IMPORT_EXPORT_TASK_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
96
94
|
params
|
97
95
|
}));
|
98
96
|
}
|
99
|
-
|
100
|
-
|
101
|
-
|
97
|
+
await pagesPermissions.ensure({
|
98
|
+
owns: importExportTask.createdBy
|
99
|
+
});
|
100
|
+
return importExportTask;
|
102
101
|
},
|
103
102
|
async listTasks(params) {
|
104
|
-
|
103
|
+
await pagesPermissions.ensure({
|
105
104
|
rwd: "r"
|
106
105
|
});
|
107
106
|
const tenant = context.tenancy.getCurrentTenant();
|
@@ -120,7 +119,7 @@ var _default = ({
|
|
120
119
|
};
|
121
120
|
|
122
121
|
// If user can only manage own records, let's add that to the listing.
|
123
|
-
if (
|
122
|
+
if (await pagesPermissions.canAccessOnlyOwnRecords) {
|
124
123
|
const identity = context.security.getIdentity();
|
125
124
|
listParams.where.createdBy = identity.id;
|
126
125
|
}
|
@@ -128,21 +127,21 @@ var _default = ({
|
|
128
127
|
const [items] = await storageOperations.listTasks(listParams);
|
129
128
|
return items;
|
130
129
|
} catch (ex) {
|
131
|
-
throw new _error.default(ex.message || "Could not list all
|
130
|
+
throw new _error.default(ex.message || "Could not list all importExportTask.", ex.code || "LIST_ELEMENTS_ERROR", {
|
132
131
|
params
|
133
132
|
});
|
134
133
|
}
|
135
134
|
},
|
136
135
|
async createTask(input) {
|
137
|
-
await
|
136
|
+
await pagesPermissions.ensure({
|
138
137
|
rwd: "w"
|
139
138
|
});
|
140
139
|
const createDataModel = new CreateDataModel().populate(input);
|
141
140
|
await createDataModel.validate();
|
142
|
-
const id = (0,
|
141
|
+
const id = (0, _utils.mdbid)();
|
143
142
|
const identity = context.security.getIdentity();
|
144
143
|
const data = await createDataModel.toJSON();
|
145
|
-
const
|
144
|
+
const importExportTask = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
|
146
145
|
tenant: context.tenancy.getCurrentTenant().id,
|
147
146
|
locale: getLocale().code,
|
148
147
|
id,
|
@@ -156,93 +155,96 @@ var _default = ({
|
|
156
155
|
try {
|
157
156
|
return await storageOperations.createTask({
|
158
157
|
input: data,
|
159
|
-
task:
|
158
|
+
task: importExportTask
|
160
159
|
});
|
161
160
|
} catch (ex) {
|
162
|
-
throw new _error.default(ex.message || "Could not create
|
163
|
-
|
161
|
+
throw new _error.default(ex.message || "Could not create importExportTask.", ex.code || "CREATE_IMPORT_EXPORT_TASK_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
162
|
+
importExportTask
|
164
163
|
}));
|
165
164
|
}
|
166
165
|
},
|
167
166
|
async updateTask(id, input) {
|
168
|
-
|
167
|
+
await pagesPermissions.ensure({
|
169
168
|
rwd: "w"
|
170
169
|
});
|
171
|
-
const original = await context.pageBuilder.
|
170
|
+
const original = await context.pageBuilder.importExportTask.getTask(id);
|
172
171
|
if (!original) {
|
173
|
-
throw new _handlerGraphql.NotFoundError(`
|
172
|
+
throw new _handlerGraphql.NotFoundError(`ImportExportTask "${id}" not found.`);
|
174
173
|
}
|
175
|
-
|
176
|
-
|
174
|
+
await pagesPermissions.ensure({
|
175
|
+
owns: original.createdBy
|
176
|
+
});
|
177
177
|
const updateDataModel = new UpdateDataModel().populate(input);
|
178
178
|
await updateDataModel.validate();
|
179
179
|
const data = await updateDataModel.toJSON({
|
180
180
|
onlyDirty: true
|
181
181
|
});
|
182
|
-
const
|
182
|
+
const importExportTask = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), data);
|
183
183
|
try {
|
184
184
|
return await storageOperations.updateTask({
|
185
185
|
input: data,
|
186
186
|
original,
|
187
|
-
task:
|
187
|
+
task: importExportTask
|
188
188
|
});
|
189
189
|
} catch (ex) {
|
190
|
-
throw new _error.default(ex.message || "Could not update
|
190
|
+
throw new _error.default(ex.message || "Could not update importExportTask.", ex.code || "UPDATE_IMPORT_EXPORT_TASK_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
191
191
|
original,
|
192
|
-
|
192
|
+
importExportTask
|
193
193
|
}));
|
194
194
|
}
|
195
195
|
},
|
196
196
|
async deleteTask(id) {
|
197
|
-
|
197
|
+
await pagesPermissions.ensure({
|
198
198
|
rwd: "d"
|
199
199
|
});
|
200
|
-
const
|
201
|
-
if (!
|
202
|
-
throw new _handlerGraphql.NotFoundError(`
|
200
|
+
const importExportTask = await context.pageBuilder.importExportTask.getTask(id);
|
201
|
+
if (!importExportTask) {
|
202
|
+
throw new _handlerGraphql.NotFoundError(`ImportExportTask "${id}" not found.`);
|
203
203
|
}
|
204
|
-
|
205
|
-
|
204
|
+
await pagesPermissions.ensure({
|
205
|
+
owns: importExportTask.createdBy
|
206
|
+
});
|
206
207
|
try {
|
207
208
|
return await storageOperations.deleteTask({
|
208
|
-
task:
|
209
|
+
task: importExportTask
|
209
210
|
});
|
210
211
|
} catch (ex) {
|
211
|
-
throw new _error.default(ex.message || "Could not delete
|
212
|
-
|
212
|
+
throw new _error.default(ex.message || "Could not delete importExportTask.", ex.code || "DELETE_IMPORT_EXPORT_TASK_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
213
|
+
importExportTask
|
213
214
|
}));
|
214
215
|
}
|
215
216
|
},
|
216
217
|
async updateStats(id, input) {
|
217
|
-
|
218
|
+
await pagesPermissions.ensure({
|
218
219
|
rwd: "w"
|
219
220
|
});
|
220
|
-
const original = await context.pageBuilder.
|
221
|
+
const original = await context.pageBuilder.importExportTask.getTask(id);
|
221
222
|
if (!original) {
|
222
|
-
throw new _handlerGraphql.NotFoundError(`
|
223
|
+
throw new _handlerGraphql.NotFoundError(`ImportExportTask "${id}" not found.`);
|
223
224
|
}
|
224
|
-
|
225
|
-
|
225
|
+
await pagesPermissions.ensure({
|
226
|
+
owns: original.createdBy
|
227
|
+
});
|
226
228
|
try {
|
227
229
|
return await storageOperations.updateTaskStats({
|
228
230
|
input,
|
229
231
|
original
|
230
232
|
});
|
231
233
|
} catch (ex) {
|
232
|
-
throw new _error.default(ex.message || "Could not update
|
234
|
+
throw new _error.default(ex.message || "Could not update importExportTask.", ex.code || "UPDATE_IMPORT_EXPORT_TASK_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
233
235
|
original
|
234
236
|
}));
|
235
237
|
}
|
236
238
|
},
|
237
239
|
async createSubTask(parent, id, input) {
|
238
|
-
await
|
240
|
+
await pagesPermissions.ensure({
|
239
241
|
rwd: "w"
|
240
242
|
});
|
241
243
|
const createDataModel = new CreateDataModel().populate(input);
|
242
244
|
await createDataModel.validate();
|
243
245
|
const identity = context.security.getIdentity();
|
244
246
|
const data = await createDataModel.toJSON();
|
245
|
-
const
|
247
|
+
const importExportSubTask = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
|
246
248
|
tenant: context.tenancy.getCurrentTenant().id,
|
247
249
|
locale: getLocale().code,
|
248
250
|
id: id,
|
@@ -257,46 +259,47 @@ var _default = ({
|
|
257
259
|
try {
|
258
260
|
return await storageOperations.createSubTask({
|
259
261
|
input: data,
|
260
|
-
subTask:
|
262
|
+
subTask: importExportSubTask
|
261
263
|
});
|
262
264
|
} catch (ex) {
|
263
|
-
throw new _error.default(ex.message || "Could not create
|
264
|
-
|
265
|
+
throw new _error.default(ex.message || "Could not create importExportSubTask.", ex.code || "CREATE_IMPORT_EXPORT_TASK_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
266
|
+
importExportSubTask
|
265
267
|
}));
|
266
268
|
}
|
267
269
|
},
|
268
270
|
async updateSubTask(parent, subTaskId, input) {
|
269
|
-
|
271
|
+
await pagesPermissions.ensure({
|
270
272
|
rwd: "w"
|
271
273
|
});
|
272
|
-
const original = await context.pageBuilder.
|
274
|
+
const original = await context.pageBuilder.importExportTask.getSubTask(parent, subTaskId);
|
273
275
|
if (!original) {
|
274
|
-
throw new _handlerGraphql.NotFoundError(`
|
276
|
+
throw new _handlerGraphql.NotFoundError(`ImportExportTask parent: "${parent}" and id: "${subTaskId}" not found.`);
|
275
277
|
}
|
276
|
-
|
277
|
-
|
278
|
+
await pagesPermissions.ensure({
|
279
|
+
owns: original.createdBy
|
280
|
+
});
|
278
281
|
const updateDataModel = new UpdateDataModel().populate(input);
|
279
282
|
await updateDataModel.validate();
|
280
283
|
const data = await updateDataModel.toJSON({
|
281
284
|
onlyDirty: true
|
282
285
|
});
|
283
286
|
// TODO: Merge recursively
|
284
|
-
const
|
287
|
+
const importExportSubTask = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), data);
|
285
288
|
try {
|
286
289
|
return await storageOperations.updateSubTask({
|
287
290
|
input: data,
|
288
291
|
original,
|
289
|
-
subTask:
|
292
|
+
subTask: importExportSubTask
|
290
293
|
});
|
291
294
|
} catch (ex) {
|
292
|
-
throw new _error.default(ex.message || "Could not update
|
293
|
-
|
295
|
+
throw new _error.default(ex.message || "Could not update importExportSubTask.", ex.code || "UPDATE_IMPORT_EXPORT_TASK_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
296
|
+
importExportSubTask,
|
294
297
|
original
|
295
298
|
}));
|
296
299
|
}
|
297
300
|
},
|
298
301
|
async getSubTask(parent, subTaskId) {
|
299
|
-
|
302
|
+
await pagesPermissions.ensure({
|
300
303
|
rwd: "r"
|
301
304
|
});
|
302
305
|
const tenant = context.tenancy.getCurrentTenant();
|
@@ -309,23 +312,24 @@ var _default = ({
|
|
309
312
|
parent: parent
|
310
313
|
}
|
311
314
|
};
|
312
|
-
let
|
315
|
+
let importExportSubTask = null;
|
313
316
|
try {
|
314
|
-
|
315
|
-
if (!
|
317
|
+
importExportSubTask = await storageOperations.getSubTask(params);
|
318
|
+
if (!importExportSubTask) {
|
316
319
|
return null;
|
317
320
|
}
|
318
321
|
} catch (ex) {
|
319
|
-
throw new _error.default(ex.message || "Could not get
|
322
|
+
throw new _error.default(ex.message || "Could not get importExportSubTask by id.", ex.code || "GET_IMPORT_EXPORT_TASK_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
320
323
|
params
|
321
324
|
}));
|
322
325
|
}
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
+
await pagesPermissions.ensure({
|
327
|
+
owns: importExportSubTask.createdBy
|
328
|
+
});
|
329
|
+
return importExportSubTask;
|
326
330
|
},
|
327
331
|
async listSubTasks(parent, status, limit) {
|
328
|
-
|
332
|
+
await pagesPermissions.ensure({
|
329
333
|
rwd: "r"
|
330
334
|
});
|
331
335
|
const tenant = context.tenancy.getCurrentTenant();
|
@@ -341,7 +345,7 @@ var _default = ({
|
|
341
345
|
};
|
342
346
|
|
343
347
|
// If user can only manage own records, let's add that to the listing.
|
344
|
-
if (
|
348
|
+
if (await pagesPermissions.canAccessOnlyOwnRecords()) {
|
345
349
|
const identity = context.security.getIdentity();
|
346
350
|
listParams.where.createdBy = identity.id;
|
347
351
|
}
|
@@ -349,7 +353,7 @@ var _default = ({
|
|
349
353
|
const [items] = await storageOperations.listSubTasks(listParams);
|
350
354
|
return items;
|
351
355
|
} catch (ex) {
|
352
|
-
throw new _error.default(ex.message || "Could not list all
|
356
|
+
throw new _error.default(ex.message || "Could not list all importExportSubTask.", ex.code || "LIST_IMPORT_EXPORT_TASK_ERROR", {
|
353
357
|
params: {
|
354
358
|
parent,
|
355
359
|
status,
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["validStatus","ImportExportTaskStatus","PENDING","PROCESSING","COMPLETED","FAILED","CreateDataModel","withFields","status","string","validation","create","data","object","input","stats","error","UpdateDataModel","storageOperations","ContextPlugin","context","pageBuilder","console","log","pagesPermissions","PagesPermissions","getPermissions","security","getIdentity","fullAccessPermissionName","getLocale","locale","i18n","getContentLocale","WebinyError","importExportTask","getTask","id","ensure","rwd","tenant","tenancy","getCurrentTenant","params","where","code","ex","message","owns","createdBy","listTasks","sort","limit","listParams","Array","isArray","length","canAccessOnlyOwnRecords","identity","items","createTask","createDataModel","populate","validate","mdbid","toJSON","createdOn","Date","toISOString","type","displayName","task","updateTask","original","NotFoundError","updateDataModel","onlyDirty","deleteTask","updateStats","updateTaskStats","createSubTask","parent","importExportSubTask","subTask","updateSubTask","subTaskId","getSubTask","listSubTasks"],"sources":["importExportTasks.crud.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\n/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { string, withFields } from \"@commodo/fields\";\n/**\n * Package commodo-fields-object does not have types.\n */\n// @ts-ignore\nimport { object } from \"commodo-fields-object\";\nimport { validation } from \"@webiny/validation\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport {\n ImportExportPluginsParams,\n ImportExportTask,\n ImportExportTaskStatus,\n ImportExportTaskStorageOperationsListSubTaskParams\n} from \"~/types\";\nimport { PbImportExportContext } from \"~/graphql/types\";\nimport WebinyError from \"@webiny/error\";\nimport { PageElementStorageOperationsListParams } from \"@webiny/api-page-builder/types\";\nimport { PagesPermissions } from \"@webiny/api-page-builder/graphql/crud/permissions/PagesPermissions\";\n\nconst validStatus = `${ImportExportTaskStatus.PENDING}:${ImportExportTaskStatus.PROCESSING}:${ImportExportTaskStatus.COMPLETED}:${ImportExportTaskStatus.FAILED}`;\n\nconst CreateDataModel = withFields({\n status: string({\n validation: validation.create(`required,in:${validStatus}`)\n }),\n data: object(),\n input: object(),\n stats: object(),\n error: object()\n})();\n\nconst UpdateDataModel = withFields({\n status: string({\n validation: validation.create(`in:${validStatus}`)\n }),\n data: object(),\n input: object(),\n stats: object(),\n error: object()\n})();\n\nexport default ({ storageOperations }: ImportExportPluginsParams) =>\n new ContextPlugin<PbImportExportContext>(async context => {\n /**\n * If pageBuilder is not defined on the context, do not continue, but log it.\n */\n if (!context.pageBuilder) {\n console.log(\"Missing pageBuilder on context. Skipping ImportExportTasks crud.\");\n return;\n }\n\n const pagesPermissions = new PagesPermissions({\n getPermissions: () => context.security.getPermissions(\"pb.page\"),\n getIdentity: context.security.getIdentity,\n fullAccessPermissionName: \"pb.*\"\n });\n\n const getLocale = () => {\n const locale = context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale in importExportTasks.crud.ts\",\n \"LOCALE_ERROR\"\n );\n }\n return locale;\n };\n\n // Modify context\n context.pageBuilder.importExportTask = {\n storageOperations,\n async getTask(id) {\n await pagesPermissions.ensure({ rwd: \"r\" });\n\n const tenant = context.tenancy.getCurrentTenant();\n const locale = getLocale();\n\n const params = {\n where: {\n tenant: tenant.id,\n locale: locale.code,\n id\n }\n };\n\n let importExportTask: ImportExportTask | null = null;\n\n try {\n importExportTask = await storageOperations.getTask(params);\n\n if (!importExportTask) {\n return null;\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get importExportTask by id.\",\n ex.code || \"GET_IMPORT_EXPORT_TASK_ERROR\",\n {\n ...(ex.data || {}),\n params\n }\n );\n }\n\n await pagesPermissions.ensure({ owns: importExportTask.createdBy });\n\n return importExportTask;\n },\n\n async listTasks(params) {\n await pagesPermissions.ensure({ rwd: \"r\" });\n\n const tenant = context.tenancy.getCurrentTenant();\n const locale = getLocale();\n\n const { sort, limit } = params || {};\n\n const listParams: PageElementStorageOperationsListParams = {\n where: {\n tenant: tenant.id,\n locale: locale.code\n },\n sort: Array.isArray(sort) && sort.length > 0 ? sort : [\"createdOn_ASC\"],\n limit: limit\n };\n\n // If user can only manage own records, let's add that to the listing.\n if (await pagesPermissions.canAccessOnlyOwnRecords) {\n const identity = context.security.getIdentity();\n listParams.where.createdBy = identity.id;\n }\n\n try {\n const [items] = await storageOperations.listTasks(listParams);\n return items;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list all importExportTask.\",\n ex.code || \"LIST_ELEMENTS_ERROR\",\n {\n params\n }\n );\n }\n },\n\n async createTask(input) {\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n const createDataModel = new CreateDataModel().populate(input);\n await createDataModel.validate();\n\n const id: string = mdbid();\n const identity = context.security.getIdentity();\n\n const data: ImportExportTask = await createDataModel.toJSON();\n\n const importExportTask: ImportExportTask = {\n ...data,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocale().code,\n id,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n }\n };\n\n try {\n return await storageOperations.createTask({\n input: data,\n task: importExportTask\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create importExportTask.\",\n ex.code || \"CREATE_IMPORT_EXPORT_TASK_ERROR\",\n {\n ...(ex.data || {}),\n importExportTask\n }\n );\n }\n },\n\n async updateTask(id, input) {\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n const original = await context.pageBuilder.importExportTask.getTask(id);\n if (!original) {\n throw new NotFoundError(`ImportExportTask \"${id}\" not found.`);\n }\n\n await pagesPermissions.ensure({ owns: original.createdBy });\n\n const updateDataModel = new UpdateDataModel().populate(input);\n await updateDataModel.validate();\n\n const data = await updateDataModel.toJSON({ onlyDirty: true });\n\n const importExportTask: ImportExportTask = {\n ...original,\n ...data\n };\n\n try {\n return await storageOperations.updateTask({\n input: data,\n original,\n task: importExportTask\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update importExportTask.\",\n ex.code || \"UPDATE_IMPORT_EXPORT_TASK_ERROR\",\n {\n ...(ex.data || {}),\n original,\n importExportTask\n }\n );\n }\n },\n\n async deleteTask(id) {\n await pagesPermissions.ensure({ rwd: \"d\" });\n\n const importExportTask = await context.pageBuilder.importExportTask.getTask(id);\n if (!importExportTask) {\n throw new NotFoundError(`ImportExportTask \"${id}\" not found.`);\n }\n\n await pagesPermissions.ensure({ owns: importExportTask.createdBy });\n\n try {\n return await storageOperations.deleteTask({\n task: importExportTask\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete importExportTask.\",\n ex.code || \"DELETE_IMPORT_EXPORT_TASK_ERROR\",\n {\n ...(ex.data || {}),\n importExportTask\n }\n );\n }\n },\n\n async updateStats(id, input) {\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n const original = await context.pageBuilder.importExportTask.getTask(id);\n if (!original) {\n throw new NotFoundError(`ImportExportTask \"${id}\" not found.`);\n }\n\n await pagesPermissions.ensure({ owns: original.createdBy });\n\n try {\n return await storageOperations.updateTaskStats({\n input,\n original\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update importExportTask.\",\n ex.code || \"UPDATE_IMPORT_EXPORT_TASK_ERROR\",\n {\n ...(ex.data || {}),\n original\n }\n );\n }\n },\n\n async createSubTask(parent, id, input) {\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n const createDataModel = new CreateDataModel().populate(input);\n await createDataModel.validate();\n\n const identity = context.security.getIdentity();\n\n const data = await createDataModel.toJSON();\n\n const importExportSubTask: ImportExportTask = {\n ...data,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocale().code,\n id: id,\n parent: parent,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n }\n };\n\n try {\n return await storageOperations.createSubTask({\n input: data,\n subTask: importExportSubTask\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create importExportSubTask.\",\n ex.code || \"CREATE_IMPORT_EXPORT_TASK_ERROR\",\n {\n ...(ex.data || {}),\n importExportSubTask\n }\n );\n }\n },\n\n async updateSubTask(parent, subTaskId, input) {\n await pagesPermissions.ensure({ rwd: \"w\" });\n\n const original = await context.pageBuilder.importExportTask.getSubTask(\n parent,\n subTaskId\n );\n if (!original) {\n throw new NotFoundError(\n `ImportExportTask parent: \"${parent}\" and id: \"${subTaskId}\" not found.`\n );\n }\n\n await pagesPermissions.ensure({ owns: original.createdBy });\n\n const updateDataModel = new UpdateDataModel().populate(input);\n await updateDataModel.validate();\n\n const data = await updateDataModel.toJSON({ onlyDirty: true });\n // TODO: Merge recursively\n const importExportSubTask: ImportExportTask = {\n ...original,\n ...data\n };\n\n try {\n return await storageOperations.updateSubTask({\n input: data,\n original,\n subTask: importExportSubTask\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update importExportSubTask.\",\n ex.code || \"UPDATE_IMPORT_EXPORT_TASK_ERROR\",\n {\n ...(ex.data || {}),\n importExportSubTask,\n original\n }\n );\n }\n },\n\n async getSubTask(parent, subTaskId) {\n await pagesPermissions.ensure({ rwd: \"r\" });\n\n const tenant = context.tenancy.getCurrentTenant();\n const locale = getLocale();\n\n const params = {\n where: {\n tenant: tenant.id,\n locale: locale.code,\n id: subTaskId,\n parent: parent\n }\n };\n\n let importExportSubTask: ImportExportTask | null = null;\n\n try {\n importExportSubTask = await storageOperations.getSubTask(params);\n if (!importExportSubTask) {\n return null;\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get importExportSubTask by id.\",\n ex.code || \"GET_IMPORT_EXPORT_TASK_ERROR\",\n {\n ...(ex.data || {}),\n params\n }\n );\n }\n\n await pagesPermissions.ensure({ owns: importExportSubTask.createdBy });\n\n return importExportSubTask;\n },\n\n async listSubTasks(parent, status, limit) {\n await pagesPermissions.ensure({ rwd: \"r\" });\n\n const tenant = context.tenancy.getCurrentTenant();\n const locale = getLocale();\n\n const listParams: ImportExportTaskStorageOperationsListSubTaskParams = {\n where: {\n tenant: tenant.id,\n locale: locale.code,\n parent: parent,\n status\n },\n limit\n };\n\n // If user can only manage own records, let's add that to the listing.\n if (await pagesPermissions.canAccessOnlyOwnRecords()) {\n const identity = context.security.getIdentity();\n listParams.where.createdBy = identity.id;\n }\n\n try {\n const [items] = await storageOperations.listSubTasks(listParams);\n return items;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list all importExportSubTask.\",\n ex.code || \"LIST_IMPORT_EXPORT_TASK_ERROR\",\n {\n params: {\n parent,\n status,\n limit\n }\n }\n );\n }\n }\n };\n });\n"],"mappings":";;;;;;;;AAAA;AAKA;AAKA;AACA;AACA;AACA;AACA;AAOA;AAEA;AAtBA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAgBA,MAAMA,WAAW,GAAI,GAAEC,6BAAsB,CAACC,OAAQ,IAAGD,6BAAsB,CAACE,UAAW,IAAGF,6BAAsB,CAACG,SAAU,IAAGH,6BAAsB,CAACI,MAAO,EAAC;AAEjK,MAAMC,eAAe,GAAG,IAAAC,kBAAU,EAAC;EAC/BC,MAAM,EAAE,IAAAC,cAAM,EAAC;IACXC,UAAU,EAAEA,sBAAU,CAACC,MAAM,CAAE,eAAcX,WAAY,EAAC;EAC9D,CAAC,CAAC;EACFY,IAAI,EAAE,IAAAC,2BAAM,GAAE;EACdC,KAAK,EAAE,IAAAD,2BAAM,GAAE;EACfE,KAAK,EAAE,IAAAF,2BAAM,GAAE;EACfG,KAAK,EAAE,IAAAH,2BAAM;AACjB,CAAC,CAAC,EAAE;AAEJ,MAAMI,eAAe,GAAG,IAAAV,kBAAU,EAAC;EAC/BC,MAAM,EAAE,IAAAC,cAAM,EAAC;IACXC,UAAU,EAAEA,sBAAU,CAACC,MAAM,CAAE,MAAKX,WAAY,EAAC;EACrD,CAAC,CAAC;EACFY,IAAI,EAAE,IAAAC,2BAAM,GAAE;EACdC,KAAK,EAAE,IAAAD,2BAAM,GAAE;EACfE,KAAK,EAAE,IAAAF,2BAAM,GAAE;EACfG,KAAK,EAAE,IAAAH,2BAAM;AACjB,CAAC,CAAC,EAAE;AAAC,eAEU,CA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D,SAAS,EAAE;MAE1B,MAAMuB,UAA8D,GAAG;QACnET,KAAK,EAAE;UACHJ,MAAM,EAAEA,MAAM,CAACH,EAAE;UACjBN,MAAM,EAAEA,MAAM,CAACc,IAAI;UACnBoC,MAAM,EAAEA,MAAM;UACdzE;QACJ,CAAC;QACD4C;MACJ,CAAC;;MAED;MACA,IAAI,MAAM5B,gBAAgB,CAACiC,uBAAuB,EAAE,EAAE;QAClD,MAAMC,QAAQ,GAAGtC,OAAO,CAACO,QAAQ,CAACC,WAAW,EAAE;QAC/CyB,UAAU,CAACT,KAAK,CAACK,SAAS,GAAGS,QAAQ,CAACrB,EAAE;MAC5C;MAEA,IAAI;QACA,MAAM,CAACsB,KAAK,CAAC,GAAG,MAAMzC,iBAAiB,CAACqE,YAAY,CAAClC,UAAU,CAAC;QAChE,OAAOM,KAAK;MAChB,CAAC,CAAC,OAAOb,EAAE,EAAE;QACT,MAAM,IAAIZ,cAAW,CACjBY,EAAE,CAACC,OAAO,IAAI,yCAAyC,EACvDD,EAAE,CAACD,IAAI,IAAI,+BAA+B,EAC1C;UACIF,MAAM,EAAE;YACJsC,MAAM;YACNzE,MAAM;YACN4C;UACJ;QACJ,CAAC,CACJ;MACL;IACJ;EACJ,CAAC;AACL,CAAC,CAAC;AAAA"}
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { ContextPlugin } from "@webiny/api";
|
2
|
-
import {
|
3
|
-
declare const _default: ContextPlugin<
|
2
|
+
import { PbImportExportContext } from "../../types";
|
3
|
+
declare const _default: ContextPlugin<PbImportExportContext>;
|
4
4
|
export default _default;
|
@@ -8,22 +8,27 @@ exports.default = void 0;
|
|
8
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
9
9
|
var _handlerGraphql = require("@webiny/handler-graphql");
|
10
10
|
var _api = require("@webiny/api");
|
11
|
-
var _checkBasePermissions = _interopRequireDefault(require("@webiny/api-page-builder/graphql/crud/utils/checkBasePermissions"));
|
12
11
|
var _types = require("../../types");
|
13
12
|
var _client = require("../../client");
|
14
|
-
var _utils = require("../../
|
15
|
-
var _utils2 = require("../../
|
13
|
+
var _utils = require("../../import/utils");
|
14
|
+
var _utils2 = require("../../export/utils");
|
16
15
|
var _utils3 = require("@webiny/utils");
|
17
|
-
|
18
|
-
const EXPORT_PAGES_PROCESS_HANDLER = process.env.
|
19
|
-
const IMPORT_PAGES_CREATE_HANDLER = process.env.
|
16
|
+
var _PagesPermissions = require("@webiny/api-page-builder/graphql/crud/permissions/PagesPermissions");
|
17
|
+
const EXPORT_PAGES_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER;
|
18
|
+
const IMPORT_PAGES_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER;
|
20
19
|
var _default = new _api.ContextPlugin(context => {
|
20
|
+
const pagesPermissions = new _PagesPermissions.PagesPermissions({
|
21
|
+
getPermissions: () => context.security.getPermissions("pb.page"),
|
22
|
+
getIdentity: context.security.getIdentity,
|
23
|
+
fullAccessPermissionName: "pb.*"
|
24
|
+
});
|
21
25
|
const importExportCrud = {
|
22
26
|
async importPages({
|
23
27
|
category: categorySlug,
|
24
|
-
zipFileUrl
|
28
|
+
zipFileUrl,
|
29
|
+
meta
|
25
30
|
}) {
|
26
|
-
await
|
31
|
+
await pagesPermissions.ensure({
|
27
32
|
rwd: "w"
|
28
33
|
});
|
29
34
|
|
@@ -34,8 +39,8 @@ var _default = new _api.ContextPlugin(context => {
|
|
34
39
|
}
|
35
40
|
|
36
41
|
// Create a task for import page
|
37
|
-
const task = await context.pageBuilder.
|
38
|
-
status: _types.
|
42
|
+
const task = await context.pageBuilder.importExportTask.createTask({
|
43
|
+
status: _types.ImportExportTaskStatus.PENDING,
|
39
44
|
input: {
|
40
45
|
category: categorySlug,
|
41
46
|
zipFileUrl
|
@@ -53,7 +58,9 @@ var _default = new _api.ContextPlugin(context => {
|
|
53
58
|
category: categorySlug,
|
54
59
|
zipFileUrl,
|
55
60
|
task,
|
56
|
-
|
61
|
+
type: "page",
|
62
|
+
identity: context.security.getIdentity(),
|
63
|
+
meta
|
57
64
|
},
|
58
65
|
description: "Import Pages - create"
|
59
66
|
});
|
@@ -68,7 +75,7 @@ var _default = new _api.ContextPlugin(context => {
|
|
68
75
|
sort,
|
69
76
|
search
|
70
77
|
}) {
|
71
|
-
await
|
78
|
+
await pagesPermissions.ensure({
|
72
79
|
rwd: "w"
|
73
80
|
});
|
74
81
|
let pageIds = initialPageIds || [];
|
@@ -98,16 +105,16 @@ var _default = new _api.ContextPlugin(context => {
|
|
98
105
|
}
|
99
106
|
|
100
107
|
// Create the main task for page export.
|
101
|
-
const task = await context.pageBuilder.
|
102
|
-
status: _types.
|
108
|
+
const task = await context.pageBuilder.importExportTask.createTask({
|
109
|
+
status: _types.ImportExportTaskStatus.PENDING
|
103
110
|
});
|
104
111
|
const exportPagesDataKey = `${_utils2.EXPORT_PAGES_FOLDER_KEY}/${task.id}`;
|
105
112
|
// For each page create a sub task and invoke the process handler.
|
106
113
|
for (let i = 0; i < pageIds.length; i++) {
|
107
114
|
const pageId = pageIds[i];
|
108
115
|
// Create sub task.
|
109
|
-
await context.pageBuilder.
|
110
|
-
status: _types.
|
116
|
+
await context.pageBuilder.importExportTask.createSubTask(task.id, (0, _utils3.zeroPad)(i + 1, 5), {
|
117
|
+
status: _types.ImportExportTaskStatus.PENDING,
|
111
118
|
input: {
|
112
119
|
pageId,
|
113
120
|
exportPagesDataKey,
|
@@ -116,8 +123,8 @@ var _default = new _api.ContextPlugin(context => {
|
|
116
123
|
});
|
117
124
|
}
|
118
125
|
// Update main task status.
|
119
|
-
await context.pageBuilder.
|
120
|
-
status: _types.
|
126
|
+
await context.pageBuilder.importExportTask.updateTask(task.id, {
|
127
|
+
status: _types.ImportExportTaskStatus.PROCESSING,
|
121
128
|
stats: (0, _utils.initialStats)(pageIds.length),
|
122
129
|
input: {
|
123
130
|
exportPagesDataKey,
|
@@ -137,6 +144,7 @@ var _default = new _api.ContextPlugin(context => {
|
|
137
144
|
payload: {
|
138
145
|
taskId: task.id,
|
139
146
|
subTaskIndex: 1,
|
147
|
+
type: "page",
|
140
148
|
identity: context.security.getIdentity()
|
141
149
|
},
|
142
150
|
description: "Export pages - process"
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["PERMISSION_NAME","EXPORT_PAGES_PROCESS_HANDLER","process","env","IMPORT_PAGES_CREATE_HANDLER","ContextPlugin","context","importExportCrud","importPages","category","categorySlug","zipFileUrl","checkBasePermissions","rwd","pageBuilder","getCategory","NotFoundError","task","pageImportExportTask","createTask","status","PageImportExportTaskStatus","PENDING","input","invokeHandlerClient","name","payload","identity","security","getIdentity","description","exportPages","ids","initialPageIds","revisionType","where","sort","search","pageIds","Array","isArray","length","pages","meta","hasMoreItems","cursor","totalCount","listLatestPages","after","forEach","page","push","id","WebinyError","exportPagesDataKey","EXPORT_PAGES_FOLDER_KEY","i","pageId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex"],"sources":["pages.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport checkBasePermissions from \"@webiny/api-page-builder/graphql/crud/utils/checkBasePermissions\";\nimport {\n PageImportExportTaskStatus,\n PagesImportExportCrud,\n PbPageImportExportContext\n} from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { Payload as CreateHandlerPayload } from \"~/importPages/create\";\nimport { initialStats } from \"~/importPages/utils\";\nimport { Payload as ExportPagesProcessHandlerPayload } from \"~/exportPages/process\";\nimport { EXPORT_PAGES_FOLDER_KEY } from \"~/exportPages/utils\";\nimport { MetaResponse } from \"@webiny/api-page-builder/types\";\nimport { zeroPad } from \"@webiny/utils\";\n\nconst PERMISSION_NAME = \"pb.page\";\nconst EXPORT_PAGES_PROCESS_HANDLER = process.env.EXPORT_PAGES_PROCESS_HANDLER as string;\nconst IMPORT_PAGES_CREATE_HANDLER = process.env.IMPORT_PAGES_CREATE_HANDLER as string;\n\nexport default new ContextPlugin<PbPageImportExportContext>(context => {\n const importExportCrud: PagesImportExportCrud = {\n async importPages({ category: categorySlug, zipFileUrl }) {\n await checkBasePermissions(context, PERMISSION_NAME, {\n rwd: \"w\"\n });\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.pageImportExportTask.createTask({\n status: PageImportExportTaskStatus.PENDING,\n input: {\n category: categorySlug,\n zipFileUrl\n }\n });\n /**\n * Import Pages\n * ImportPages\n * importPages\n */\n await invokeHandlerClient<CreateHandlerPayload>({\n context,\n name: IMPORT_PAGES_CREATE_HANDLER,\n payload: {\n category: categorySlug,\n zipFileUrl,\n task,\n identity: context.security.getIdentity()\n },\n description: \"Import Pages - create\"\n });\n\n return {\n task\n };\n },\n\n async exportPages({ ids: initialPageIds, revisionType, where, sort, search }) {\n await checkBasePermissions(context, PERMISSION_NAME, {\n 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.pageImportExportTask.createTask({\n status: PageImportExportTaskStatus.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.pageImportExportTask.createSubTask(\n task.id,\n zeroPad(i + 1, 5),\n {\n status: PageImportExportTaskStatus.PENDING,\n input: {\n pageId,\n exportPagesDataKey,\n revisionType\n }\n }\n );\n }\n // Update main task status.\n await context.pageBuilder.pageImportExportTask.updateTask(task.id, {\n status: PageImportExportTaskStatus.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 // Invoke handler.\n await invokeHandlerClient<ExportPagesProcessHandlerPayload>({\n context,\n name: EXPORT_PAGES_PROCESS_HANDLER,\n payload: {\n taskId: task.id,\n subTaskIndex: 1,\n identity: context.security.getIdentity()\n },\n description: \"Export pages - process\"\n });\n\n return { task };\n }\n };\n // Modify context\n context.pageBuilder.pages = importExportCrud;\n});\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AAKA;AAEA;AAEA;AAEA;AAEA,MAAMA,eAAe,GAAG,SAAS;AACjC,MAAMC,4BAA4B,GAAGC,OAAO,CAACC,GAAG,CAACF,4BAAsC;AACvF,MAAMG,2BAA2B,GAAGF,OAAO,CAACC,GAAG,CAACC,2BAAqC;AAAC,eAEvE,IAAIC,kBAAa,CAA4BC,OAAO,IAAI;EACnE,MAAMC,gBAAuC,GAAG;IAC5C,MAAMC,WAAW,CAAC;MAAEC,QAAQ,EAAEC,YAAY;MAAEC;IAAW,CAAC,EAAE;MACtD,MAAM,IAAAC,6BAAoB,EAACN,OAAO,EAAEN,eAAe,EAAE;QACjDa,GAAG,EAAE;MACT,CAAC,CAAC;;MAEF;MACA,MAAMJ,QAAQ,GAAG,MAAMH,OAAO,CAACQ,WAAW,CAACC,WAAW,CAACL,YAAY,CAAC;MACpE,IAAI,CAACD,QAAQ,EAAE;QACX,MAAM,IAAIO,6BAAa,CAAE,uBAAsB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ClB,KAAK,EAAE;UACH+B,kBAAkB;UAClBpB;QACJ;MACJ,CAAC,CAAC;;MAEF;AACZ;AACA;AACA;AACA;MACY;MACA,MAAM,IAAAV,2BAAmB,EAAmC;QACxDlB,OAAO;QACPmB,IAAI,EAAExB,4BAA4B;QAClCyB,OAAO,EAAE;UACLsC,MAAM,EAAE/C,IAAI,CAACmC,EAAE;UACfa,YAAY,EAAE,CAAC;UACftC,QAAQ,EAAErB,OAAO,CAACsB,QAAQ,CAACC,WAAW;QAC1C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;MAEF,OAAO;QAAEb;MAAK,CAAC;IACnB;EACJ,CAAC;EACD;EACAX,OAAO,CAACQ,WAAW,CAAC4B,KAAK,GAAGnC,gBAAgB;AAChD,CAAC,CAAC;AAAA"}
|
1
|
+
{"version":3,"names":["EXPORT_PAGES_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_PAGES_CREATE_HANDLER","IMPORT_CREATE_HANDLER","ContextPlugin","context","pagesPermissions","PagesPermissions","getPermissions","security","getIdentity","fullAccessPermissionName","importExportCrud","importPages","category","categorySlug","zipFileUrl","meta","ensure","rwd","pageBuilder","getCategory","NotFoundError","task","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","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","EXPORT_PAGES_FOLDER_KEY","i","pageId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex"],"sources":["pages.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { ImportExportTaskStatus, PagesImportExportCrud, PbImportExportContext } 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 { EXPORT_PAGES_FOLDER_KEY } from \"~/export/utils\";\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\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 const importExportCrud: PagesImportExportCrud = {\n async importPages({ category: categorySlug, zipFileUrl, meta }) {\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 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\n return {\n task\n };\n },\n\n async exportPages({ ids: initialPageIds, revisionType, where, sort, search }) {\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 // 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\n return { task };\n }\n };\n // Modify context\n context.pageBuilder.pages = importExportCrud;\n});\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA;AAEA;AAEA;AACA;AAEA,MAAMA,4BAA4B,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAgC;AACjF,MAAMC,2BAA2B,GAAGH,OAAO,CAACC,GAAG,CAACG,qBAA+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