@webiny/api-page-builder-import-export 0.0.0-mt-2 → 0.0.0-unstable.085ff6572f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +8 -0
- package/client.js +43 -0
- package/client.js.map +1 -0
- 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/export/combine/index.d.ts +16 -0
- 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/export/process/index.d.ts +20 -0
- 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 +7 -2
- package/{exportPages → export}/s3Stream.js +12 -24
- 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 +7 -5
- package/{exportPages → export}/zipper.js +40 -53
- 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/importExportTasks.crud.js +367 -0
- package/graphql/crud/importExportTasks.crud.js.map +1 -0
- package/graphql/crud/pages.crud.d.ts +3 -3
- package/graphql/crud/pages.crud.js +72 -74
- package/graphql/crud/pages.crud.js.map +1 -0
- 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 +6 -8
- package/graphql/crud.js.map +1 -0
- 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} +19 -24
- package/graphql/graphql/importExportTasks.gql.js.map +1 -0
- package/graphql/graphql/pages.gql.d.ts +2 -2
- package/graphql/graphql/pages.gql.js +5 -14
- package/graphql/graphql/pages.gql.js.map +1 -0
- 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/utils/resolve.js +0 -3
- package/graphql/graphql/utils/resolve.js.map +1 -0
- package/graphql/graphql.d.ts +1 -1
- package/graphql/graphql.js +6 -7
- package/graphql/graphql.js.map +1 -0
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +1 -6
- package/graphql/index.js.map +1 -0
- package/graphql/types.d.ts +86 -27
- package/graphql/types.js.map +1 -0
- 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/import/create/index.d.ts +24 -0
- 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/import/process/index.d.ts +20 -0
- 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 -3
- package/mockSecurity.js.map +1 -0
- package/package.json +37 -38
- package/types.d.ts +91 -72
- package/types.js +17 -22
- package/types.js.map +1 -0
- package/exportPages/combine/index.d.ts +0 -19
- package/exportPages/combine/index.js +0 -88
- package/exportPages/process/index.d.ts +0 -26
- package/exportPages/process/index.js +0 -204
- package/exportPages/utils.d.ts +0 -13
- package/exportPages/utils.js +0 -113
- package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
- package/graphql/crud/pageImportExportTasks.crud.js +0 -394
- package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
- package/importPages/client.d.ts +0 -7
- package/importPages/client.js +0 -40
- package/importPages/create/index.d.ts +0 -27
- package/importPages/create/index.js +0 -109
- package/importPages/process/index.d.ts +0 -25
- package/importPages/process/index.js +0 -183
- package/importPages/utils.d.ts +0 -43
- package/importPages/utils.js +0 -539
@@ -1,394 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
6
|
-
value: true
|
7
|
-
});
|
8
|
-
exports.default = void 0;
|
9
|
-
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
-
|
12
|
-
var _mdbid = _interopRequireDefault(require("mdbid"));
|
13
|
-
|
14
|
-
var _fields = require("@commodo/fields");
|
15
|
-
|
16
|
-
var _commodoFieldsObject = require("commodo-fields-object");
|
17
|
-
|
18
|
-
var _validation = require("@webiny/validation");
|
19
|
-
|
20
|
-
var _ContextPlugin = require("@webiny/handler/plugins/ContextPlugin");
|
21
|
-
|
22
|
-
var _checkBasePermissions = _interopRequireDefault(require("@webiny/api-page-builder/graphql/crud/utils/checkBasePermissions"));
|
23
|
-
|
24
|
-
var _checkOwnPermissions = _interopRequireDefault(require("@webiny/api-page-builder/graphql/crud/utils/checkOwnPermissions"));
|
25
|
-
|
26
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
27
|
-
|
28
|
-
var _types = require("../../types");
|
29
|
-
|
30
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
31
|
-
|
32
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
33
|
-
|
34
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
35
|
-
|
36
|
-
const validStatus = `${_types.PageImportExportTaskStatus.PENDING}:${_types.PageImportExportTaskStatus.PROCESSING}:${_types.PageImportExportTaskStatus.COMPLETED}:${_types.PageImportExportTaskStatus.FAILED}`;
|
37
|
-
const CreateDataModel = (0, _fields.withFields)({
|
38
|
-
status: (0, _fields.string)({
|
39
|
-
validation: _validation.validation.create(`required,in:${validStatus}`)
|
40
|
-
}),
|
41
|
-
data: (0, _commodoFieldsObject.object)(),
|
42
|
-
input: (0, _commodoFieldsObject.object)(),
|
43
|
-
stats: (0, _commodoFieldsObject.object)(),
|
44
|
-
error: (0, _commodoFieldsObject.object)()
|
45
|
-
})();
|
46
|
-
const UpdateDataModel = (0, _fields.withFields)({
|
47
|
-
status: (0, _fields.string)({
|
48
|
-
validation: _validation.validation.create(`in:${validStatus}`)
|
49
|
-
}),
|
50
|
-
data: (0, _commodoFieldsObject.object)(),
|
51
|
-
input: (0, _commodoFieldsObject.object)(),
|
52
|
-
stats: (0, _commodoFieldsObject.object)(),
|
53
|
-
error: (0, _commodoFieldsObject.object)()
|
54
|
-
})();
|
55
|
-
const PERMISSION_NAME = "pb.page";
|
56
|
-
|
57
|
-
var _default = ({
|
58
|
-
storageOperations
|
59
|
-
}) => new _ContextPlugin.ContextPlugin(async context => {
|
60
|
-
/**
|
61
|
-
* If pageBuilder is not defined on the context, do not continue, but log it.
|
62
|
-
*/
|
63
|
-
if (!context.pageBuilder) {
|
64
|
-
console.log("Missing pageBuilder on context. Skipping Page ImportExportTasks crud.");
|
65
|
-
return;
|
66
|
-
} // Modify context
|
67
|
-
|
68
|
-
|
69
|
-
context.pageBuilder.pageImportExportTask = {
|
70
|
-
storageOperations,
|
71
|
-
|
72
|
-
async getTask(id) {
|
73
|
-
const permission = await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
74
|
-
rwd: "r"
|
75
|
-
});
|
76
|
-
const tenant = context.tenancy.getCurrentTenant();
|
77
|
-
const locale = context.i18nContent.getLocale();
|
78
|
-
const params = {
|
79
|
-
where: {
|
80
|
-
tenant: tenant.id,
|
81
|
-
locale: locale.code,
|
82
|
-
id
|
83
|
-
}
|
84
|
-
};
|
85
|
-
let pageImportExportTask;
|
86
|
-
|
87
|
-
try {
|
88
|
-
pageImportExportTask = await storageOperations.getTask(params);
|
89
|
-
|
90
|
-
if (!pageImportExportTask) {
|
91
|
-
return null;
|
92
|
-
}
|
93
|
-
} catch (ex) {
|
94
|
-
throw new _error.default(ex.message || "Could not get pageImportExportTask by id.", ex.code || "GET_PAGE_IMPORT_EXPORT_TASK_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
|
95
|
-
params
|
96
|
-
}));
|
97
|
-
}
|
98
|
-
|
99
|
-
const identity = context.security.getIdentity();
|
100
|
-
(0, _checkOwnPermissions.default)(identity, permission, pageImportExportTask);
|
101
|
-
return pageImportExportTask;
|
102
|
-
},
|
103
|
-
|
104
|
-
async listTasks(params) {
|
105
|
-
const permission = await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
106
|
-
rwd: "r"
|
107
|
-
});
|
108
|
-
const tenant = context.tenancy.getCurrentTenant();
|
109
|
-
const locale = context.i18nContent.getLocale();
|
110
|
-
const {
|
111
|
-
sort,
|
112
|
-
limit
|
113
|
-
} = params || {};
|
114
|
-
const listParams = {
|
115
|
-
where: {
|
116
|
-
tenant: tenant.id,
|
117
|
-
locale: locale.code
|
118
|
-
},
|
119
|
-
sort: Array.isArray(sort) && sort.length > 0 ? sort : ["createdOn_ASC"],
|
120
|
-
limit: limit
|
121
|
-
}; // If user can only manage own records, let's add that to the listing.
|
122
|
-
|
123
|
-
if (permission.own) {
|
124
|
-
const identity = context.security.getIdentity();
|
125
|
-
listParams.where.createdBy = identity.id;
|
126
|
-
}
|
127
|
-
|
128
|
-
try {
|
129
|
-
const [items] = await storageOperations.listTasks(listParams);
|
130
|
-
return items;
|
131
|
-
} catch (ex) {
|
132
|
-
throw new _error.default(ex.message || "Could not list all page elements.", ex.code || "LIST_PAGE_ELEMENTS_ERROR", {
|
133
|
-
params
|
134
|
-
});
|
135
|
-
}
|
136
|
-
},
|
137
|
-
|
138
|
-
async createTask(input) {
|
139
|
-
await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
140
|
-
rwd: "w"
|
141
|
-
});
|
142
|
-
const createDataModel = new CreateDataModel().populate(input);
|
143
|
-
await createDataModel.validate();
|
144
|
-
const id = (0, _mdbid.default)();
|
145
|
-
const identity = context.security.getIdentity();
|
146
|
-
const data = await createDataModel.toJSON();
|
147
|
-
|
148
|
-
const pageImportExportTask = _objectSpread(_objectSpread({}, data), {}, {
|
149
|
-
tenant: context.tenancy.getCurrentTenant().id,
|
150
|
-
locale: context.i18nContent.getLocale().code,
|
151
|
-
id,
|
152
|
-
createdOn: new Date().toISOString(),
|
153
|
-
createdBy: {
|
154
|
-
id: identity.id,
|
155
|
-
type: identity.type,
|
156
|
-
displayName: identity.displayName
|
157
|
-
}
|
158
|
-
});
|
159
|
-
|
160
|
-
try {
|
161
|
-
return await storageOperations.createTask({
|
162
|
-
input: data,
|
163
|
-
task: pageImportExportTask
|
164
|
-
});
|
165
|
-
} catch (ex) {
|
166
|
-
throw new _error.default(ex.message || "Could not create pageImportExportTask.", ex.code || "CREATE_PAGE_IMPORT_EXPORT_TASK_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
|
167
|
-
pageImportExportTask
|
168
|
-
}));
|
169
|
-
}
|
170
|
-
},
|
171
|
-
|
172
|
-
async updateTask(id, input) {
|
173
|
-
const permission = await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
174
|
-
rwd: "w"
|
175
|
-
});
|
176
|
-
const original = await context.pageBuilder.pageImportExportTask.getTask(id);
|
177
|
-
|
178
|
-
if (!original) {
|
179
|
-
throw new _handlerGraphql.NotFoundError(`PageImportExportTask "${id}" not found.`);
|
180
|
-
}
|
181
|
-
|
182
|
-
const identity = context.security.getIdentity();
|
183
|
-
(0, _checkOwnPermissions.default)(identity, permission, original);
|
184
|
-
const updateDataModel = new UpdateDataModel().populate(input);
|
185
|
-
await updateDataModel.validate();
|
186
|
-
const data = await updateDataModel.toJSON({
|
187
|
-
onlyDirty: true
|
188
|
-
});
|
189
|
-
|
190
|
-
const pageImportExportTask = _objectSpread(_objectSpread({}, original), data);
|
191
|
-
|
192
|
-
try {
|
193
|
-
return await storageOperations.updateTask({
|
194
|
-
input: data,
|
195
|
-
original,
|
196
|
-
task: pageImportExportTask
|
197
|
-
});
|
198
|
-
} catch (ex) {
|
199
|
-
throw new _error.default(ex.message || "Could not update pageImportExportTask.", ex.code || "UPDATE_PAGE_IMPORT_EXPORT_TASK_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
|
200
|
-
original,
|
201
|
-
pageImportExportTask
|
202
|
-
}));
|
203
|
-
}
|
204
|
-
},
|
205
|
-
|
206
|
-
async deleteTask(id) {
|
207
|
-
const permission = await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
208
|
-
rwd: "d"
|
209
|
-
});
|
210
|
-
const pageImportExportTask = await context.pageBuilder.pageImportExportTask.getTask(id);
|
211
|
-
|
212
|
-
if (!pageImportExportTask) {
|
213
|
-
throw new _handlerGraphql.NotFoundError(`PageImportExportTask "${id}" not found.`);
|
214
|
-
}
|
215
|
-
|
216
|
-
const identity = context.security.getIdentity();
|
217
|
-
(0, _checkOwnPermissions.default)(identity, permission, pageImportExportTask);
|
218
|
-
|
219
|
-
try {
|
220
|
-
return await storageOperations.deleteTask({
|
221
|
-
task: pageImportExportTask
|
222
|
-
});
|
223
|
-
} catch (ex) {
|
224
|
-
throw new _error.default(ex.message || "Could not delete pageImportExportTask.", ex.code || "DELETE_PAGE_IMPORT_EXPORT_TASK_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
|
225
|
-
pageImportExportTask
|
226
|
-
}));
|
227
|
-
}
|
228
|
-
},
|
229
|
-
|
230
|
-
async updateStats(id, input) {
|
231
|
-
const permission = await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
232
|
-
rwd: "w"
|
233
|
-
});
|
234
|
-
const original = await context.pageBuilder.pageImportExportTask.getTask(id);
|
235
|
-
|
236
|
-
if (!original) {
|
237
|
-
throw new _handlerGraphql.NotFoundError(`PageImportExportTask "${id}" not found.`);
|
238
|
-
}
|
239
|
-
|
240
|
-
const identity = context.security.getIdentity();
|
241
|
-
(0, _checkOwnPermissions.default)(identity, permission, original);
|
242
|
-
|
243
|
-
try {
|
244
|
-
return await storageOperations.updateTaskStats({
|
245
|
-
input,
|
246
|
-
original
|
247
|
-
});
|
248
|
-
} catch (ex) {
|
249
|
-
throw new _error.default(ex.message || "Could not update pageImportExportTask.", ex.code || "UPDATE_PAGE_IMPORT_EXPORT_TASK_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
|
250
|
-
original
|
251
|
-
}));
|
252
|
-
}
|
253
|
-
},
|
254
|
-
|
255
|
-
async createSubTask(parent, id, input) {
|
256
|
-
await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
257
|
-
rwd: "w"
|
258
|
-
});
|
259
|
-
const createDataModel = new CreateDataModel().populate(input);
|
260
|
-
await createDataModel.validate();
|
261
|
-
const identity = context.security.getIdentity();
|
262
|
-
const data = await createDataModel.toJSON();
|
263
|
-
|
264
|
-
const pageImportExportSubTask = _objectSpread(_objectSpread({}, data), {}, {
|
265
|
-
tenant: context.tenancy.getCurrentTenant().id,
|
266
|
-
locale: context.i18nContent.getLocale().code,
|
267
|
-
id: id,
|
268
|
-
parent: parent,
|
269
|
-
createdOn: new Date().toISOString(),
|
270
|
-
createdBy: {
|
271
|
-
id: identity.id,
|
272
|
-
type: identity.type,
|
273
|
-
displayName: identity.displayName
|
274
|
-
}
|
275
|
-
});
|
276
|
-
|
277
|
-
try {
|
278
|
-
return await storageOperations.createSubTask({
|
279
|
-
input: data,
|
280
|
-
subTask: pageImportExportSubTask
|
281
|
-
});
|
282
|
-
} catch (ex) {
|
283
|
-
throw new _error.default(ex.message || "Could not create pageImportExportSubTask.", ex.code || "CREATE_PAGE_IMPORT_EXPORT_TASK_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
|
284
|
-
pageImportExportSubTask
|
285
|
-
}));
|
286
|
-
}
|
287
|
-
},
|
288
|
-
|
289
|
-
async updateSubTask(parent, subTaskId, input) {
|
290
|
-
const permission = await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
291
|
-
rwd: "w"
|
292
|
-
});
|
293
|
-
const original = await context.pageBuilder.pageImportExportTask.getSubTask(parent, subTaskId);
|
294
|
-
|
295
|
-
if (!original) {
|
296
|
-
throw new _handlerGraphql.NotFoundError(`PageImportExportTask parent: "${parent}" and id: "${subTaskId}" not found.`);
|
297
|
-
}
|
298
|
-
|
299
|
-
const identity = context.security.getIdentity();
|
300
|
-
(0, _checkOwnPermissions.default)(identity, permission, original);
|
301
|
-
const updateDataModel = new UpdateDataModel().populate(input);
|
302
|
-
await updateDataModel.validate();
|
303
|
-
const data = await updateDataModel.toJSON({
|
304
|
-
onlyDirty: true
|
305
|
-
}); // TODO: Merge recursively
|
306
|
-
|
307
|
-
const pageImportExportSubTask = _objectSpread(_objectSpread({}, original), data);
|
308
|
-
|
309
|
-
try {
|
310
|
-
return await storageOperations.updateSubTask({
|
311
|
-
input: data,
|
312
|
-
original,
|
313
|
-
subTask: pageImportExportSubTask
|
314
|
-
});
|
315
|
-
} catch (ex) {
|
316
|
-
throw new _error.default(ex.message || "Could not update pageImportExportSubTask.", ex.code || "UPDATE_PAGE_IMPORT_EXPORT_TASK_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
|
317
|
-
pageImportExportSubTask,
|
318
|
-
original
|
319
|
-
}));
|
320
|
-
}
|
321
|
-
},
|
322
|
-
|
323
|
-
async getSubTask(parent, subTaskId) {
|
324
|
-
const permission = await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
325
|
-
rwd: "r"
|
326
|
-
});
|
327
|
-
const tenant = context.tenancy.getCurrentTenant();
|
328
|
-
const locale = context.i18nContent.getLocale();
|
329
|
-
const params = {
|
330
|
-
where: {
|
331
|
-
tenant: tenant.id,
|
332
|
-
locale: locale.code,
|
333
|
-
id: subTaskId,
|
334
|
-
parent: parent
|
335
|
-
}
|
336
|
-
};
|
337
|
-
let pageImportExportSubTask;
|
338
|
-
|
339
|
-
try {
|
340
|
-
pageImportExportSubTask = await storageOperations.getSubTask(params);
|
341
|
-
|
342
|
-
if (!pageImportExportSubTask) {
|
343
|
-
return null;
|
344
|
-
}
|
345
|
-
} catch (ex) {
|
346
|
-
throw new _error.default(ex.message || "Could not get pageImportExportSubTask by id.", ex.code || "GET_PAGE_IMPORT_EXPORT_TASK_ERROR", _objectSpread(_objectSpread({}, ex.data || {}), {}, {
|
347
|
-
params
|
348
|
-
}));
|
349
|
-
}
|
350
|
-
|
351
|
-
const identity = context.security.getIdentity();
|
352
|
-
(0, _checkOwnPermissions.default)(identity, permission, pageImportExportSubTask);
|
353
|
-
return pageImportExportSubTask;
|
354
|
-
},
|
355
|
-
|
356
|
-
async listSubTasks(parent, status, limit) {
|
357
|
-
const permission = await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
358
|
-
rwd: "r"
|
359
|
-
});
|
360
|
-
const tenant = context.tenancy.getCurrentTenant();
|
361
|
-
const locale = context.i18nContent.getLocale();
|
362
|
-
const listParams = {
|
363
|
-
where: {
|
364
|
-
tenant: tenant.id,
|
365
|
-
locale: locale.code,
|
366
|
-
parent: parent,
|
367
|
-
status
|
368
|
-
},
|
369
|
-
limit
|
370
|
-
}; // If user can only manage own records, let's add that to the listing.
|
371
|
-
|
372
|
-
if (permission.own) {
|
373
|
-
const identity = context.security.getIdentity();
|
374
|
-
listParams.where.createdBy = identity.id;
|
375
|
-
}
|
376
|
-
|
377
|
-
try {
|
378
|
-
const [items] = await storageOperations.listSubTasks(listParams);
|
379
|
-
return items;
|
380
|
-
} catch (ex) {
|
381
|
-
throw new _error.default(ex.message || "Could not list all pageImportExportSubTask.", ex.code || "LIST_PAGE_IMPORT_EXPORT_TASK_ERROR", {
|
382
|
-
params: {
|
383
|
-
parent,
|
384
|
-
status,
|
385
|
-
limit
|
386
|
-
}
|
387
|
-
});
|
388
|
-
}
|
389
|
-
}
|
390
|
-
|
391
|
-
};
|
392
|
-
});
|
393
|
-
|
394
|
-
exports.default = _default;
|
package/importPages/client.d.ts
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
import { PbPageImportExportContext } from "../graphql/types";
|
2
|
-
export interface InvokeHandlerClientParams<TParams> {
|
3
|
-
context: PbPageImportExportContext;
|
4
|
-
name: string;
|
5
|
-
payload: TParams;
|
6
|
-
}
|
7
|
-
export declare function invokeHandlerClient<TParams>({ context, name, payload }: InvokeHandlerClientParams<TParams>): Promise<void>;
|
package/importPages/client.js
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
6
|
-
value: true
|
7
|
-
});
|
8
|
-
exports.invokeHandlerClient = invokeHandlerClient;
|
9
|
-
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
-
|
12
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
13
|
-
|
14
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
15
|
-
|
16
|
-
async function invokeHandlerClient({
|
17
|
-
context,
|
18
|
-
name,
|
19
|
-
payload
|
20
|
-
}) {
|
21
|
-
/*
|
22
|
-
* Prepare "invocationArgs", we're hacking our wat here.
|
23
|
-
* They are necessary to setup the "context.pageBuilder" object among other things in IMPORT_PAGE_FUNCTION
|
24
|
-
*/
|
25
|
-
const {
|
26
|
-
request
|
27
|
-
} = context.http;
|
28
|
-
const invocationArgs = {
|
29
|
-
httpMethod: request.method,
|
30
|
-
body: request.body,
|
31
|
-
headers: request.headers,
|
32
|
-
cookies: request.cookies
|
33
|
-
}; // Invoke handler
|
34
|
-
|
35
|
-
await context.handlerClient.invoke({
|
36
|
-
name: name,
|
37
|
-
payload: _objectSpread(_objectSpread({}, payload), invocationArgs),
|
38
|
-
await: false
|
39
|
-
});
|
40
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import { HandlerPlugin } from "@webiny/handler/types";
|
2
|
-
import { ArgsContext } from "@webiny/handler-args/types";
|
3
|
-
import { PageImportExportTask, PbPageImportExportContext } from "../../types";
|
4
|
-
import { SecurityIdentity } from "@webiny/api-security/types";
|
5
|
-
export declare type HandlerArgs = {
|
6
|
-
category: string;
|
7
|
-
zipFileKey?: string;
|
8
|
-
zipFileUrl?: string;
|
9
|
-
task: PageImportExportTask;
|
10
|
-
identity: SecurityIdentity;
|
11
|
-
};
|
12
|
-
export declare type HandlerResponse = {
|
13
|
-
data: string;
|
14
|
-
error: {
|
15
|
-
message: string;
|
16
|
-
};
|
17
|
-
};
|
18
|
-
interface Configuration {
|
19
|
-
handlers: {
|
20
|
-
process: string;
|
21
|
-
};
|
22
|
-
}
|
23
|
-
declare const _default: (configuration: Configuration) => HandlerPlugin<PbPageImportExportContext, ArgsContext<HandlerArgs>>;
|
24
|
-
/**
|
25
|
-
* Handles the import page workflow.
|
26
|
-
*/
|
27
|
-
export default _default;
|
@@ -1,109 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
|
8
|
-
var _types = require("../../types");
|
9
|
-
|
10
|
-
var _utils = require("../utils");
|
11
|
-
|
12
|
-
var _client = require("../client");
|
13
|
-
|
14
|
-
var _mockSecurity = require("../../mockSecurity");
|
15
|
-
|
16
|
-
/**
|
17
|
-
* Handles the import page workflow.
|
18
|
-
*/
|
19
|
-
var _default = configuration => ({
|
20
|
-
type: "handler",
|
21
|
-
|
22
|
-
async handle(context) {
|
23
|
-
const log = console.log;
|
24
|
-
|
25
|
-
try {
|
26
|
-
log("RUNNING Import Pages Create");
|
27
|
-
const {
|
28
|
-
invocationArgs: args,
|
29
|
-
pageBuilder
|
30
|
-
} = context;
|
31
|
-
const {
|
32
|
-
task,
|
33
|
-
category,
|
34
|
-
zipFileKey,
|
35
|
-
zipFileUrl,
|
36
|
-
identity
|
37
|
-
} = args;
|
38
|
-
(0, _mockSecurity.mockSecurity)(identity, context); // Step 1: Read the zip file
|
39
|
-
|
40
|
-
const pageImportDataList = await (0, _utils.readExtractAndUploadZipFileContents)(zipFileKey || zipFileUrl); // Once we have map we can start processing each page
|
41
|
-
// For each page create a sub task and invoke the process handler
|
42
|
-
|
43
|
-
for (let i = 0; i < pageImportDataList.length; i++) {
|
44
|
-
const pagesDirMap = pageImportDataList[i]; // Create sub task
|
45
|
-
|
46
|
-
const subtask = await pageBuilder.pageImportExportTask.createSubTask(task.id, (0, _utils.zeroPad)(i + 1), {
|
47
|
-
status: _types.PageImportExportTaskStatus.PENDING,
|
48
|
-
data: {
|
49
|
-
pageKey: pagesDirMap.key,
|
50
|
-
category,
|
51
|
-
zipFileKey,
|
52
|
-
zipFileUrl,
|
53
|
-
input: {
|
54
|
-
fileUploadsData: pagesDirMap
|
55
|
-
}
|
56
|
-
}
|
57
|
-
});
|
58
|
-
log(`Added SUB_TASK "${subtask.id}" to queue.`);
|
59
|
-
} // Update main task status
|
60
|
-
|
61
|
-
|
62
|
-
await pageBuilder.pageImportExportTask.updateTask(task.id, {
|
63
|
-
status: _types.PageImportExportTaskStatus.PROCESSING,
|
64
|
-
stats: (0, _utils.initialStats)(pageImportDataList.length)
|
65
|
-
});
|
66
|
-
await (0, _client.invokeHandlerClient)({
|
67
|
-
context,
|
68
|
-
name: configuration.handlers.process,
|
69
|
-
payload: {
|
70
|
-
taskId: task.id,
|
71
|
-
// Execute "Process" for the first sub task.
|
72
|
-
subTaskIndex: 1,
|
73
|
-
identity: context.security.getIdentity()
|
74
|
-
}
|
75
|
-
});
|
76
|
-
} catch (e) {
|
77
|
-
log("[IMPORT_PAGES_CREATE] Error => ", e);
|
78
|
-
/**
|
79
|
-
* In case of error, we'll update the task status to "failed",
|
80
|
-
* so that, client can show notify the user appropriately.
|
81
|
-
*/
|
82
|
-
|
83
|
-
const {
|
84
|
-
invocationArgs: args,
|
85
|
-
pageBuilder
|
86
|
-
} = context;
|
87
|
-
const {
|
88
|
-
task
|
89
|
-
} = args;
|
90
|
-
await pageBuilder.pageImportExportTask.updateTask(task.id, {
|
91
|
-
status: _types.PageImportExportTaskStatus.FAILED,
|
92
|
-
error: {
|
93
|
-
name: e.name,
|
94
|
-
message: e.message,
|
95
|
-
code: e.code || "EXPORT_FAILED"
|
96
|
-
}
|
97
|
-
});
|
98
|
-
return {
|
99
|
-
data: null,
|
100
|
-
error: {
|
101
|
-
message: e.message
|
102
|
-
}
|
103
|
-
};
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
});
|
108
|
-
|
109
|
-
exports.default = _default;
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import { HandlerPlugin } from "@webiny/handler/types";
|
2
|
-
import { ArgsContext } from "@webiny/handler-args/types";
|
3
|
-
import { PbPageImportExportContext } from "../../types";
|
4
|
-
import { SecurityIdentity } from "@webiny/api-security/types";
|
5
|
-
export declare type HandlerArgs = {
|
6
|
-
taskId: string;
|
7
|
-
subTaskIndex: number;
|
8
|
-
identity: SecurityIdentity;
|
9
|
-
};
|
10
|
-
export declare type HandlerResponse = {
|
11
|
-
data: string;
|
12
|
-
error: {
|
13
|
-
message: string;
|
14
|
-
};
|
15
|
-
};
|
16
|
-
interface Configuration {
|
17
|
-
handlers: {
|
18
|
-
process: string;
|
19
|
-
};
|
20
|
-
}
|
21
|
-
declare const _default: (configuration: Configuration) => HandlerPlugin<PbPageImportExportContext, ArgsContext<HandlerArgs>>;
|
22
|
-
/**
|
23
|
-
* Handles the import page workflow.
|
24
|
-
*/
|
25
|
-
export default _default;
|