@webiny/api-page-builder-import-export 0.0.0-mt-3 → 0.0.0-unstable.13771d80a8
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 +40 -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 +37 -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 +188 -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 +136 -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 +129 -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} +87 -118
- package/graphql/crud/importExportTasks.crud.js.map +1 -0
- package/graphql/crud/pages.crud.d.ts +3 -3
- package/graphql/crud/pages.crud.js +64 -70
- package/graphql/crud/pages.crud.js.map +1 -0
- package/graphql/crud/templates.crud.d.ts +4 -0
- package/graphql/crud/templates.crud.js +124 -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 +40 -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 +89 -0
- package/import/process/blocks/importBlock.js.map +1 -0
- package/import/process/blocksHandler.d.ts +3 -0
- package/import/process/blocksHandler.js +175 -0
- package/import/process/blocksHandler.js.map +1 -0
- package/import/process/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 +37 -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/pagesHandler.d.ts +3 -0
- package/import/process/pagesHandler.js +180 -0
- package/import/process/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 +58 -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/import/utils.d.ts +49 -0
- package/{importPages → import}/utils.js +191 -89
- package/import/utils.js.map +1 -0
- package/mockSecurity.js +0 -2
- package/mockSecurity.js.map +1 -0
- package/package.json +37 -34
- 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/graphql/pageImportExportTasks.gql.d.ts +0 -4
- package/importPages/client.d.ts +0 -7
- package/importPages/client.js +0 -40
- package/importPages/create/index.d.ts +0 -27
- package/importPages/create/index.js +0 -109
- package/importPages/process/index.d.ts +0 -25
- package/importPages/process/index.js +0 -183
- package/importPages/utils.d.ts +0 -43
@@ -1,15 +1,16 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
2
3
|
import S3 from "aws-sdk/clients/s3";
|
3
4
|
import { Readable } from "stream";
|
4
|
-
import {
|
5
|
+
import { File } from "@webiny/api-file-manager/types";
|
5
6
|
interface FileStreamDetails {
|
6
7
|
stream: Readable;
|
7
8
|
filename: string;
|
8
9
|
}
|
9
10
|
interface ExportInfo {
|
10
|
-
files:
|
11
|
-
|
12
|
-
|
11
|
+
files: File[];
|
12
|
+
name: string;
|
13
|
+
dataBuffer: Buffer;
|
13
14
|
}
|
14
15
|
export interface ZipperConfig {
|
15
16
|
exportInfo: ExportInfo;
|
@@ -28,7 +29,8 @@ export declare class ZipOfZip {
|
|
28
29
|
private readonly archiveFormat;
|
29
30
|
private readonly archiveFileName;
|
30
31
|
keys: string[];
|
31
|
-
|
32
|
+
filename: string;
|
33
|
+
constructor(keys: string[], filename: string);
|
32
34
|
getFileStreams(): FileStreamDetails[];
|
33
35
|
process(): Promise<S3.ManagedUpload.SendData>;
|
34
36
|
}
|
@@ -1,31 +1,20 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var
|
4
|
-
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
6
6
|
value: true
|
7
7
|
});
|
8
8
|
exports.default = exports.ZipOfZip = void 0;
|
9
|
-
|
10
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
-
|
12
10
|
var _archiver = _interopRequireDefault(require("archiver"));
|
13
|
-
|
14
11
|
var _stream = require("stream");
|
15
|
-
|
16
12
|
var path = _interopRequireWildcard(require("path"));
|
17
|
-
|
18
13
|
var _kebabCase = _interopRequireDefault(require("lodash/kebabCase"));
|
19
|
-
|
20
14
|
var _uniqid = _interopRequireDefault(require("uniqid"));
|
21
|
-
|
22
15
|
var _s3Stream = require("./s3Stream");
|
23
|
-
|
24
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
25
|
-
|
26
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
27
|
-
|
28
16
|
// TODO: Move "archive" in layer
|
17
|
+
|
29
18
|
class Zipper {
|
30
19
|
constructor(config) {
|
31
20
|
(0, _defineProperty2.default)(this, "archiveFormat", "zip");
|
@@ -33,68 +22,66 @@ class Zipper {
|
|
33
22
|
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
34
23
|
(0, _defineProperty2.default)(this, "config", void 0);
|
35
24
|
this.config = config;
|
36
|
-
this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.
|
25
|
+
this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.name)}.zip`);
|
37
26
|
}
|
38
|
-
|
39
27
|
s3DownloadStreams() {
|
40
28
|
const exportInfo = this.config.exportInfo;
|
41
|
-
const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.
|
29
|
+
const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.name)}`);
|
42
30
|
const files = exportInfo.files.map(({
|
43
31
|
key
|
44
32
|
}) => {
|
45
33
|
return {
|
46
34
|
stream: _s3Stream.s3Stream.readStream(key),
|
47
|
-
filename: `${prefix}\\${this.filesDirName}\\${
|
35
|
+
filename: `${prefix}\\${this.filesDirName}\\${key}`
|
48
36
|
};
|
49
37
|
});
|
50
38
|
return [...files, {
|
51
|
-
stream: _stream.Readable.from(exportInfo.
|
52
|
-
filename: `${prefix}\\${exportInfo.
|
39
|
+
stream: _stream.Readable.from(exportInfo.dataBuffer),
|
40
|
+
filename: `${prefix}\\${exportInfo.name}.json`
|
53
41
|
}];
|
54
42
|
}
|
55
|
-
|
56
43
|
process() {
|
57
44
|
const {
|
58
45
|
streamPassThrough,
|
59
46
|
streamPassThroughUploadPromise
|
60
|
-
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
61
|
-
|
62
|
-
|
63
|
-
const s3FilesStreams = this.s3DownloadStreams(); // 2. Prepare zip from the file stream.
|
64
|
-
|
65
|
-
const archive = _archiver.default.create(this.archiveFormat); // Handle archive events.
|
47
|
+
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
66
48
|
|
49
|
+
// 1. Read all files from S3 using stream.
|
50
|
+
const s3FilesStreams = this.s3DownloadStreams();
|
67
51
|
|
52
|
+
// 2. Prepare zip from the file stream.
|
53
|
+
const archive = _archiver.default.create(this.archiveFormat);
|
54
|
+
// Handle archive events.
|
68
55
|
archive.on("error", error => {
|
69
56
|
throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
|
70
|
-
});
|
57
|
+
});
|
71
58
|
|
59
|
+
// Append all file streams to archive.
|
72
60
|
s3FilesStreams.forEach(streamDetails => archive.append(streamDetails.stream, {
|
73
61
|
name: streamDetails.filename
|
74
|
-
}));
|
62
|
+
}));
|
75
63
|
|
76
|
-
|
64
|
+
// Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
|
65
|
+
archive.pipe(streamPassThrough);
|
66
|
+
// Finalize the archive (ie we are done appending files but streams have to finish yet)
|
77
67
|
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
|
68
|
+
archive.finalize();
|
78
69
|
|
79
|
-
|
80
|
-
|
70
|
+
// 3. Return upload stream promise.
|
81
71
|
return streamPassThroughUploadPromise;
|
82
72
|
}
|
83
|
-
|
84
73
|
}
|
85
|
-
|
86
74
|
exports.default = Zipper;
|
87
|
-
const PAGE_EXPORT_BASENAME = `WEBINY_PAGE_EXPORT.zip`;
|
88
|
-
|
89
75
|
class ZipOfZip {
|
90
|
-
constructor(keys) {
|
76
|
+
constructor(keys, filename) {
|
91
77
|
(0, _defineProperty2.default)(this, "archiveFormat", "zip");
|
92
78
|
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
93
79
|
(0, _defineProperty2.default)(this, "keys", void 0);
|
80
|
+
(0, _defineProperty2.default)(this, "filename", void 0);
|
94
81
|
this.keys = keys;
|
95
|
-
this.
|
82
|
+
this.filename = filename;
|
83
|
+
this.archiveFileName = (0, _uniqid.default)("EXPORTS/", `-${filename}`);
|
96
84
|
}
|
97
|
-
|
98
85
|
getFileStreams() {
|
99
86
|
return this.keys.map(key => {
|
100
87
|
return {
|
@@ -103,35 +90,35 @@ class ZipOfZip {
|
|
103
90
|
};
|
104
91
|
});
|
105
92
|
}
|
106
|
-
|
107
93
|
process() {
|
108
94
|
const {
|
109
95
|
streamPassThrough,
|
110
96
|
streamPassThroughUploadPromise
|
111
|
-
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
112
|
-
|
113
|
-
|
114
|
-
const fileStreamDetails = this.getFileStreams(); // 2. Prepare zip from the file stream.
|
115
|
-
|
116
|
-
const archive = _archiver.default.create(this.archiveFormat); // Handle archive events.
|
97
|
+
} = _s3Stream.s3Stream.writeStream(this.archiveFileName);
|
117
98
|
|
99
|
+
// 1. Read all files from S3 using stream.
|
100
|
+
const fileStreamDetails = this.getFileStreams();
|
118
101
|
|
102
|
+
// 2. Prepare zip from the file stream.
|
103
|
+
const archive = _archiver.default.create(this.archiveFormat);
|
104
|
+
// Handle archive events.
|
119
105
|
archive.on("error", error => {
|
120
106
|
throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
|
121
|
-
});
|
107
|
+
});
|
122
108
|
|
109
|
+
// Append all file streams to archive.
|
123
110
|
fileStreamDetails.forEach(streamDetails => archive.append(streamDetails.stream, {
|
124
111
|
name: streamDetails.filename
|
125
|
-
}));
|
112
|
+
}));
|
126
113
|
|
127
|
-
|
114
|
+
// Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
|
115
|
+
archive.pipe(streamPassThrough);
|
116
|
+
// Finalize the archive (ie we are done appending files but streams have to finish yet)
|
128
117
|
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
|
118
|
+
archive.finalize();
|
129
119
|
|
130
|
-
|
131
|
-
|
120
|
+
// 3. Return upload stream promise.
|
132
121
|
return streamPassThroughUploadPromise;
|
133
122
|
}
|
134
|
-
|
135
123
|
}
|
136
|
-
|
137
124
|
exports.ZipOfZip = ZipOfZip;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["Zipper","constructor","config","archiveFileName","uniqueId","archiveFileKey","kebabCase","exportInfo","name","s3DownloadStreams","prefix","files","map","key","stream","s3Stream","readStream","filename","filesDirName","Readable","from","dataBuffer","process","streamPassThrough","streamPassThroughUploadPromise","writeStream","s3FilesStreams","archive","vending","create","archiveFormat","on","error","Error","code","message","path","stack","forEach","streamDetails","append","pipe","finalize","ZipOfZip","keys","getFileStreams","basename","fileStreamDetails"],"sources":["zipper.ts"],"sourcesContent":["// TODO: Move \"archive\" in layer\nimport vending, { ArchiverError } from \"archiver\";\nimport S3 from \"aws-sdk/clients/s3\";\nimport { Readable } from \"stream\";\nimport * as path from \"path\";\nimport kebabCase from \"lodash/kebabCase\";\nimport uniqueId from \"uniqid\";\nimport { s3Stream } from \"./s3Stream\";\nimport { File } from \"@webiny/api-file-manager/types\";\n\ninterface FileStreamDetails {\n stream: Readable;\n filename: string;\n}\n\ninterface ExportInfo {\n files: File[];\n name: string;\n dataBuffer: Buffer;\n}\n\nexport interface ZipperConfig {\n exportInfo: ExportInfo;\n archiveFileKey: string;\n}\n\nexport default class Zipper {\n private readonly archiveFormat = \"zip\";\n private readonly filesDirName = \"assets\";\n private readonly archiveFileName: string;\n config: ZipperConfig;\n\n constructor(config: ZipperConfig) {\n this.config = config;\n this.archiveFileName = uniqueId(\n `${this.config.archiveFileKey}/`,\n `-${kebabCase(this.config.exportInfo.name)}.zip`\n );\n }\n\n s3DownloadStreams(): FileStreamDetails[] {\n const exportInfo = this.config.exportInfo;\n const prefix = uniqueId(\"\", `-${kebabCase(exportInfo.name)}`);\n const files = exportInfo.files.map(({ key }) => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${prefix}\\\\${this.filesDirName}\\\\${key}`\n };\n });\n\n return [\n ...files,\n {\n stream: Readable.from(exportInfo.dataBuffer),\n filename: `${prefix}\\\\${exportInfo.name}.json`\n }\n ];\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const s3FilesStreams = this.s3DownloadStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n s3FilesStreams.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n\nexport class ZipOfZip {\n private readonly archiveFormat = \"zip\";\n private readonly archiveFileName: string;\n keys: string[];\n filename: string;\n\n constructor(keys: string[], filename: string) {\n this.keys = keys;\n this.filename = filename;\n this.archiveFileName = uniqueId(\"EXPORTS/\", `-${filename}`);\n }\n\n getFileStreams(): FileStreamDetails[] {\n return this.keys.map(key => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${path.basename(key)}`\n };\n });\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const fileStreamDetails = this.getFileStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n fileStreamDetails.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n"],"mappings":";;;;;;;;;AACA;AAEA;AACA;AACA;AACA;AACA;AAPA;;AA0Be,MAAMA,MAAM,CAAC;EAMxBC,WAAW,CAACC,MAAoB,EAAE;IAAA,qDALD,KAAK;IAAA,oDACN,QAAQ;IAAA;IAAA;IAKpC,IAAI,CAACA,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,eAAe,GAAG,IAAAC,eAAQ,EAC1B,GAAE,IAAI,CAACF,MAAM,CAACG,cAAe,GAAE,EAC/B,IAAG,IAAAC,kBAAS,EAAC,IAAI,CAACJ,MAAM,CAACK,UAAU,CAACC,IAAI,CAAE,MAAK,CACnD;EACL;EAEAC,iBAAiB,GAAwB;IACrC,MAAMF,UAAU,GAAG,IAAI,CAACL,MAAM,CAACK,UAAU;IACzC,MAAMG,MAAM,GAAG,IAAAN,eAAQ,EAAC,EAAE,EAAG,IAAG,IAAAE,kBAAS,EAACC,UAAU,CAACC,IAAI,CAAE,EAAC,CAAC;IAC7D,MAAMG,KAAK,GAAGJ,UAAU,CAACI,KAAK,CAACC,GAAG,CAAC,CAAC;MAAEC;IAAI,CAAC,KAAK;MAC5C,OAAO;QACHC,MAAM,EAAEC,kBAAQ,CAACC,UAAU,CAACH,GAAG,CAAC;QAChCI,QAAQ,EAAG,GAAEP,MAAO,KAAI,IAAI,CAACQ,YAAa,KAAIL,GAAI;MACtD,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,CACH,GAAGF,KAAK,EACR;MACIG,MAAM,EAAEK,gBAAQ,CAACC,IAAI,CAACb,UAAU,CAACc,UAAU,CAAC;MAC5CJ,QAAQ,EAAG,GAAEP,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CAAChC,GAAG,CAACC,GAAG,IAAI;MACxB,OAAO;QACHC,MAAM,EAAEC,kBAAQ,CAACC,UAAU,CAACH,GAAG,CAAC;QAChCI,QAAQ,EAAG,GAAEmB,IAAI,CAACU,QAAQ,CAACjC,GAAG,CAAE;MACpC,CAAC;IACL,CAAC,CAAC;EACN;EAEAS,OAAO,GAAuC;IAC1C,MAAM;MAAEC,iBAAiB;MAAEC;IAA+B,CAAC,GAAGT,kBAAQ,CAACU,WAAW,CAC9E,IAAI,CAACtB,eAAe,CACvB;;IAED;IACA,MAAM4C,iBAAiB,GAAG,IAAI,CAACF,cAAc,EAAE;;IAE/C;IACA,MAAMlB,OAAO,GAAGC,iBAAO,CAACC,MAAM,CAAC,IAAI,CAACC,aAAa,CAAC;IAClD;IACAH,OAAO,CAACI,EAAE,CAAC,OAAO,EAAGC,KAAoB,IAAK;MAC1C,MAAM,IAAIC,KAAK,CACV,GAAED,KAAK,CAACxB,IAAK,IAAGwB,KAAK,CAACE,IAAK,IAAGF,KAAK,CAACG,OAAQ,IAAGH,KAAK,CAACI,IAAK,IAAGJ,KAAK,CAACK,KAAM,EAAC,CAC9E;IACL,CAAC,CAAC;;IAEF;IACAU,iBAAiB,CAACT,OAAO,CAAEC,aAAgC,IACvDZ,OAAO,CAACa,MAAM,CAACD,aAAa,CAACzB,MAAM,EAAE;MAAEN,IAAI,EAAE+B,aAAa,CAACtB;IAAS,CAAC,CAAC,CACzE;;IAED;IACAU,OAAO,CAACc,IAAI,CAAClB,iBAAiB,CAAC;IAC/B;IACA;IACAI,OAAO,CAACe,QAAQ,EAAE;;IAElB;IACA,OAAOlB,8BAA8B;EACzC;AACJ;AAAC"}
|
@@ -0,0 +1,136 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.default = void 0;
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
9
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
10
|
+
var _api = require("@webiny/api");
|
11
|
+
var _checkBasePermissions = _interopRequireDefault(require("@webiny/api-page-builder/graphql/crud/utils/checkBasePermissions"));
|
12
|
+
var _types = require("../../types");
|
13
|
+
var _client = require("../../client");
|
14
|
+
var _utils = require("../../import/utils");
|
15
|
+
var _utils2 = require("../../export/utils");
|
16
|
+
var _utils3 = require("@webiny/utils");
|
17
|
+
const PERMISSION_NAME = "pb.block";
|
18
|
+
const EXPORT_BLOCKS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER;
|
19
|
+
const IMPORT_BLOCKS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER;
|
20
|
+
var _default = new _api.ContextPlugin(context => {
|
21
|
+
const importExportCrud = {
|
22
|
+
async importBlocks({
|
23
|
+
category: categorySlug,
|
24
|
+
zipFileUrl
|
25
|
+
}) {
|
26
|
+
await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
27
|
+
rwd: "w"
|
28
|
+
});
|
29
|
+
|
30
|
+
// Bail out early if category not found
|
31
|
+
const category = await context.pageBuilder.getBlockCategory(categorySlug);
|
32
|
+
if (!category) {
|
33
|
+
throw new _handlerGraphql.NotFoundError(`Category with slug "${categorySlug}" not found.`);
|
34
|
+
}
|
35
|
+
|
36
|
+
// Create a task for import block
|
37
|
+
const task = await context.pageBuilder.importExportTask.createTask({
|
38
|
+
status: _types.ImportExportTaskStatus.PENDING,
|
39
|
+
input: {
|
40
|
+
category: categorySlug,
|
41
|
+
zipFileUrl
|
42
|
+
}
|
43
|
+
});
|
44
|
+
/**
|
45
|
+
* Import Blocks
|
46
|
+
* ImportBlocks
|
47
|
+
* importBlocks
|
48
|
+
*/
|
49
|
+
await (0, _client.invokeHandlerClient)({
|
50
|
+
context,
|
51
|
+
name: IMPORT_BLOCKS_CREATE_HANDLER,
|
52
|
+
payload: {
|
53
|
+
category: categorySlug,
|
54
|
+
zipFileUrl,
|
55
|
+
task,
|
56
|
+
type: "block",
|
57
|
+
identity: context.security.getIdentity()
|
58
|
+
},
|
59
|
+
description: "Import Blocks - create"
|
60
|
+
});
|
61
|
+
return {
|
62
|
+
task
|
63
|
+
};
|
64
|
+
},
|
65
|
+
async exportBlocks({
|
66
|
+
ids: initialBlockIds,
|
67
|
+
where
|
68
|
+
}) {
|
69
|
+
await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
|
70
|
+
rwd: "w"
|
71
|
+
});
|
72
|
+
let blockIds = initialBlockIds || [];
|
73
|
+
// If no ids are provided then it means we want to export all blocks
|
74
|
+
if (!initialBlockIds || Array.isArray(initialBlockIds) && initialBlockIds.length === 0) {
|
75
|
+
const blocks = await context.pageBuilder.listPageBlocks({
|
76
|
+
where
|
77
|
+
});
|
78
|
+
// Save block ids
|
79
|
+
blockIds = blocks.map(block => block.id);
|
80
|
+
}
|
81
|
+
if (blockIds.length === 0) {
|
82
|
+
throw new _error.default("Cannot export blocks - no blocks found for provided inputs.", "EMPTY_EXPORT_NO_BLOCKS_FOUND");
|
83
|
+
}
|
84
|
+
|
85
|
+
// Create the main task for blocks export.
|
86
|
+
const task = await context.pageBuilder.importExportTask.createTask({
|
87
|
+
status: _types.ImportExportTaskStatus.PENDING
|
88
|
+
});
|
89
|
+
const exportBlocksDataKey = `${_utils2.EXPORT_BLOCKS_FOLDER_KEY}/${task.id}`;
|
90
|
+
// For each block create a sub task and invoke the process handler.
|
91
|
+
for (let i = 0; i < blockIds.length; i++) {
|
92
|
+
const blockId = blockIds[i];
|
93
|
+
// Create sub task.
|
94
|
+
await context.pageBuilder.importExportTask.createSubTask(task.id, (0, _utils3.zeroPad)(i + 1, 5), {
|
95
|
+
status: _types.ImportExportTaskStatus.PENDING,
|
96
|
+
input: {
|
97
|
+
blockId,
|
98
|
+
exportBlocksDataKey
|
99
|
+
}
|
100
|
+
});
|
101
|
+
}
|
102
|
+
// Update main task status.
|
103
|
+
await context.pageBuilder.importExportTask.updateTask(task.id, {
|
104
|
+
status: _types.ImportExportTaskStatus.PROCESSING,
|
105
|
+
stats: (0, _utils.initialStats)(blockIds.length),
|
106
|
+
input: {
|
107
|
+
exportBlocksDataKey
|
108
|
+
}
|
109
|
+
});
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Export Blocks
|
113
|
+
* ExportBlocks
|
114
|
+
* exportBlocks
|
115
|
+
*/
|
116
|
+
// Invoke handler.
|
117
|
+
await (0, _client.invokeHandlerClient)({
|
118
|
+
context,
|
119
|
+
name: EXPORT_BLOCKS_PROCESS_HANDLER,
|
120
|
+
payload: {
|
121
|
+
taskId: task.id,
|
122
|
+
subTaskIndex: 1,
|
123
|
+
type: "block",
|
124
|
+
identity: context.security.getIdentity()
|
125
|
+
},
|
126
|
+
description: "Export blocks - process"
|
127
|
+
});
|
128
|
+
return {
|
129
|
+
task
|
130
|
+
};
|
131
|
+
}
|
132
|
+
};
|
133
|
+
// Modify context
|
134
|
+
context.pageBuilder.blocks = importExportCrud;
|
135
|
+
});
|
136
|
+
exports.default = _default;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["PERMISSION_NAME","EXPORT_BLOCKS_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_BLOCKS_CREATE_HANDLER","IMPORT_CREATE_HANDLER","ContextPlugin","context","importExportCrud","importBlocks","category","categorySlug","zipFileUrl","checkBasePermissions","rwd","pageBuilder","getBlockCategory","NotFoundError","task","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","invokeHandlerClient","name","payload","type","identity","security","getIdentity","description","exportBlocks","ids","initialBlockIds","where","blockIds","Array","isArray","length","blocks","listPageBlocks","map","block","id","WebinyError","exportBlocksDataKey","EXPORT_BLOCKS_FOLDER_KEY","i","blockId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex"],"sources":["blocks.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 { ImportExportTaskStatus, BlocksImportExportCrud, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { Payload as CreateHandlerPayload } from \"~/import/create\";\nimport { initialStats } from \"~/import/utils\";\nimport { Payload as ExportBlocksProcessHandlerPayload } from \"~/export/process\";\nimport { EXPORT_BLOCKS_FOLDER_KEY } from \"~/export/utils\";\nimport { zeroPad } from \"@webiny/utils\";\n\nconst PERMISSION_NAME = \"pb.block\";\nconst EXPORT_BLOCKS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER as string;\nconst IMPORT_BLOCKS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER as string;\n\nexport default new ContextPlugin<PbImportExportContext>(context => {\n const importExportCrud: BlocksImportExportCrud = {\n async importBlocks({ 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.getBlockCategory(categorySlug);\n if (!category) {\n throw new NotFoundError(`Category with slug \"${categorySlug}\" not found.`);\n }\n\n // Create a task for import block\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING,\n input: {\n category: categorySlug,\n zipFileUrl\n }\n });\n /**\n * Import Blocks\n * ImportBlocks\n * importBlocks\n */\n await invokeHandlerClient<CreateHandlerPayload>({\n context,\n name: IMPORT_BLOCKS_CREATE_HANDLER,\n payload: {\n category: categorySlug,\n zipFileUrl,\n task,\n type: \"block\",\n identity: context.security.getIdentity()\n },\n description: \"Import Blocks - create\"\n });\n\n return {\n task\n };\n },\n\n async exportBlocks({ ids: initialBlockIds, where }) {\n await checkBasePermissions(context, PERMISSION_NAME, {\n rwd: \"w\"\n });\n let blockIds: string[] = initialBlockIds || [];\n // If no ids are provided then it means we want to export all blocks\n if (\n !initialBlockIds ||\n (Array.isArray(initialBlockIds) && initialBlockIds.length === 0)\n ) {\n const blocks = await context.pageBuilder.listPageBlocks({ where });\n // Save block ids\n blockIds = blocks.map(block => block.id);\n }\n\n if (blockIds.length === 0) {\n throw new WebinyError(\n \"Cannot export blocks - no blocks found for provided inputs.\",\n \"EMPTY_EXPORT_NO_BLOCKS_FOUND\"\n );\n }\n\n // Create the main task for blocks export.\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING\n });\n const exportBlocksDataKey = `${EXPORT_BLOCKS_FOLDER_KEY}/${task.id}`;\n // For each block create a sub task and invoke the process handler.\n for (let i = 0; i < blockIds.length; i++) {\n const blockId = blockIds[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 blockId,\n exportBlocksDataKey\n }\n }\n );\n }\n // Update main task status.\n await context.pageBuilder.importExportTask.updateTask(task.id, {\n status: ImportExportTaskStatus.PROCESSING,\n stats: initialStats(blockIds.length),\n input: {\n exportBlocksDataKey\n }\n });\n\n /**\n * Export Blocks\n * ExportBlocks\n * exportBlocks\n */\n // Invoke handler.\n await invokeHandlerClient<ExportBlocksProcessHandlerPayload>({\n context,\n name: EXPORT_BLOCKS_PROCESS_HANDLER,\n payload: {\n taskId: task.id,\n subTaskIndex: 1,\n type: \"block\",\n identity: context.security.getIdentity()\n },\n description: \"Export blocks - process\"\n });\n\n return { task };\n }\n };\n // Modify context\n context.pageBuilder.blocks = importExportCrud;\n});\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AAEA,MAAMA,eAAe,GAAG,UAAU;AAClC,MAAMC,6BAA6B,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAgC;AAClF,MAAMC,4BAA4B,GAAGH,OAAO,CAACC,GAAG,CAACG,qBAA+B;AAAC,eAElE,IAAIC,k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,MAAM,CAAC;QACpChB,KAAK,EAAE;UACHuB;QACJ;MACJ,CAAC,CAAC;;MAEF;AACZ;AACA;AACA;AACA;MACY;MACA,MAAM,IAAAtB,2BAAmB,EAAoC;QACzDlB,OAAO;QACPmB,IAAI,EAAE1B,6BAA6B;QACnC2B,OAAO,EAAE;UACL8B,MAAM,EAAEvC,IAAI,CAAC2B,EAAE;UACfa,YAAY,EAAE,CAAC;UACf9B,IAAI,EAAE,OAAO;UACbC,QAAQ,EAAEtB,OAAO,CAACuB,QAAQ,CAACC,WAAW;QAC1C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;MAEF,OAAO;QAAEd;MAAK,CAAC;IACnB;EACJ,CAAC;EACD;EACAX,OAAO,CAACQ,WAAW,CAAC0B,MAAM,GAAGjC,gBAAgB;AACjD,CAAC,CAAC;AAAA"}
|
@@ -0,0 +1,129 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.default = void 0;
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
9
|
+
var _api = require("@webiny/api");
|
10
|
+
var _utils = require("@webiny/api-form-builder/plugins/crud/utils");
|
11
|
+
var _types = require("../../types");
|
12
|
+
var _client = require("../../client");
|
13
|
+
var _utils2 = require("../../import/utils");
|
14
|
+
var _utils3 = require("../../export/utils");
|
15
|
+
var _utils4 = require("@webiny/utils");
|
16
|
+
const EXPORT_FORMS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER;
|
17
|
+
const IMPORT_FORMS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER;
|
18
|
+
var _default = new _api.ContextPlugin(context => {
|
19
|
+
context.waitFor("formBuilder", () => {
|
20
|
+
const importExportCrud = {
|
21
|
+
async importForms({
|
22
|
+
zipFileUrl
|
23
|
+
}) {
|
24
|
+
await (0, _utils.checkBaseFormPermissions)(context, {
|
25
|
+
rwd: "w"
|
26
|
+
});
|
27
|
+
|
28
|
+
// Create a task for import form
|
29
|
+
const task = await context.pageBuilder.importExportTask.createTask({
|
30
|
+
status: _types.ImportExportTaskStatus.PENDING,
|
31
|
+
input: {
|
32
|
+
zipFileUrl
|
33
|
+
}
|
34
|
+
});
|
35
|
+
/**
|
36
|
+
* Import Forms
|
37
|
+
* ImportForms
|
38
|
+
* importForms
|
39
|
+
*/
|
40
|
+
await (0, _client.invokeHandlerClient)({
|
41
|
+
context,
|
42
|
+
name: IMPORT_FORMS_CREATE_HANDLER,
|
43
|
+
payload: {
|
44
|
+
zipFileUrl,
|
45
|
+
task,
|
46
|
+
type: "form",
|
47
|
+
identity: context.security.getIdentity()
|
48
|
+
},
|
49
|
+
description: "Import Forms - create"
|
50
|
+
});
|
51
|
+
return {
|
52
|
+
task
|
53
|
+
};
|
54
|
+
},
|
55
|
+
async exportForms({
|
56
|
+
ids: initialFormIds,
|
57
|
+
revisionType
|
58
|
+
}) {
|
59
|
+
await (0, _utils.checkBaseFormPermissions)(context, {
|
60
|
+
rwd: "w"
|
61
|
+
});
|
62
|
+
let formIds = initialFormIds || [];
|
63
|
+
// If no ids are provided then it means we want to export all forms
|
64
|
+
if (!initialFormIds || Array.isArray(initialFormIds) && initialFormIds.length === 0) {
|
65
|
+
formIds = [];
|
66
|
+
const forms = await context.formBuilder.listForms();
|
67
|
+
|
68
|
+
// Save form ids
|
69
|
+
forms.forEach(form => formIds.push(form.id));
|
70
|
+
}
|
71
|
+
if (formIds.length === 0) {
|
72
|
+
throw new _error.default("Cannot export forms - no forms found for provided inputs.", "EMPTY_EXPORT_NO_FORMS_FOUND");
|
73
|
+
}
|
74
|
+
|
75
|
+
// Create the main task for form export.
|
76
|
+
const task = await context.pageBuilder.importExportTask.createTask({
|
77
|
+
status: _types.ImportExportTaskStatus.PENDING
|
78
|
+
});
|
79
|
+
const exportFormsDataKey = `${_utils3.EXPORT_FORMS_FOLDER_KEY}/${task.id}`;
|
80
|
+
// For each form create a sub task and invoke the process handler.
|
81
|
+
for (let i = 0; i < formIds.length; i++) {
|
82
|
+
const formId = formIds[i];
|
83
|
+
// Create sub task.
|
84
|
+
await context.pageBuilder.importExportTask.createSubTask(task.id, (0, _utils4.zeroPad)(i + 1, 5), {
|
85
|
+
status: _types.ImportExportTaskStatus.PENDING,
|
86
|
+
input: {
|
87
|
+
formId,
|
88
|
+
exportFormsDataKey,
|
89
|
+
revisionType
|
90
|
+
}
|
91
|
+
});
|
92
|
+
}
|
93
|
+
// Update main task status.
|
94
|
+
await context.pageBuilder.importExportTask.updateTask(task.id, {
|
95
|
+
status: _types.ImportExportTaskStatus.PROCESSING,
|
96
|
+
stats: (0, _utils2.initialStats)(formIds.length),
|
97
|
+
input: {
|
98
|
+
exportFormsDataKey,
|
99
|
+
revisionType
|
100
|
+
}
|
101
|
+
});
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Export Forms
|
105
|
+
* ExportForms
|
106
|
+
* exportForms
|
107
|
+
*/
|
108
|
+
// Invoke handler.
|
109
|
+
await (0, _client.invokeHandlerClient)({
|
110
|
+
context,
|
111
|
+
name: EXPORT_FORMS_PROCESS_HANDLER,
|
112
|
+
payload: {
|
113
|
+
taskId: task.id,
|
114
|
+
subTaskIndex: 1,
|
115
|
+
type: "form",
|
116
|
+
identity: context.security.getIdentity()
|
117
|
+
},
|
118
|
+
description: "Export forms - process"
|
119
|
+
});
|
120
|
+
return {
|
121
|
+
task
|
122
|
+
};
|
123
|
+
}
|
124
|
+
};
|
125
|
+
// Modify context
|
126
|
+
context.formBuilder.forms = importExportCrud;
|
127
|
+
});
|
128
|
+
});
|
129
|
+
exports.default = _default;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["EXPORT_FORMS_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_FORMS_CREATE_HANDLER","IMPORT_CREATE_HANDLER","ContextPlugin","context","waitFor","importExportCrud","importForms","zipFileUrl","checkBaseFormPermissions","rwd","task","pageBuilder","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","invokeHandlerClient","name","payload","type","identity","security","getIdentity","description","exportForms","ids","initialFormIds","revisionType","formIds","Array","isArray","length","forms","formBuilder","listForms","forEach","form","push","id","WebinyError","exportFormsDataKey","EXPORT_FORMS_FOLDER_KEY","i","formId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex"],"sources":["forms.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { checkBaseFormPermissions } from \"@webiny/api-form-builder/plugins/crud/utils\";\nimport { ImportExportTaskStatus, FormsImportExportCrud, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { Payload as CreateHandlerPayload } from \"~/import/create\";\nimport { initialStats } from \"~/import/utils\";\nimport { Payload as ExportFormsProcessHandlerPayload } from \"~/export/process\";\nimport { EXPORT_FORMS_FOLDER_KEY } from \"~/export/utils\";\nimport { zeroPad } from \"@webiny/utils\";\n\nconst EXPORT_FORMS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER as string;\nconst IMPORT_FORMS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER as string;\n\nexport default new ContextPlugin<PbImportExportContext>(context => {\n context.waitFor(\"formBuilder\", () => {\n const importExportCrud: FormsImportExportCrud = {\n async importForms({ zipFileUrl }) {\n await checkBaseFormPermissions(context, {\n rwd: \"w\"\n });\n\n // Create a task for import form\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING,\n input: {\n zipFileUrl\n }\n });\n /**\n * Import Forms\n * ImportForms\n * importForms\n */\n await invokeHandlerClient<CreateHandlerPayload>({\n context,\n name: IMPORT_FORMS_CREATE_HANDLER,\n payload: {\n zipFileUrl,\n task,\n type: \"form\",\n identity: context.security.getIdentity()\n },\n description: \"Import Forms - create\"\n });\n\n return {\n task\n };\n },\n\n async exportForms({ ids: initialFormIds, revisionType }) {\n await checkBaseFormPermissions(context, {\n rwd: \"w\"\n });\n let formIds: string[] = initialFormIds || [];\n // If no ids are provided then it means we want to export all forms\n if (\n !initialFormIds ||\n (Array.isArray(initialFormIds) && initialFormIds.length === 0)\n ) {\n formIds = [];\n\n const forms = await context.formBuilder.listForms();\n\n // Save form ids\n forms.forEach(form => formIds.push(form.id));\n }\n\n if (formIds.length === 0) {\n throw new WebinyError(\n \"Cannot export forms - no forms found for provided inputs.\",\n \"EMPTY_EXPORT_NO_FORMS_FOUND\"\n );\n }\n\n // Create the main task for form export.\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING\n });\n const exportFormsDataKey = `${EXPORT_FORMS_FOLDER_KEY}/${task.id}`;\n // For each form create a sub task and invoke the process handler.\n for (let i = 0; i < formIds.length; i++) {\n const formId = formIds[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 formId,\n exportFormsDataKey,\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(formIds.length),\n input: {\n exportFormsDataKey,\n revisionType\n }\n });\n\n /**\n * Export Forms\n * ExportForms\n * exportForms\n */\n // Invoke handler.\n await invokeHandlerClient<ExportFormsProcessHandlerPayload>({\n context,\n name: EXPORT_FORMS_PROCESS_HANDLER,\n payload: {\n taskId: task.id,\n subTaskIndex: 1,\n type: \"form\",\n identity: context.security.getIdentity()\n },\n description: \"Export forms - process\"\n });\n\n return { task };\n }\n };\n // Modify context\n context.formBuilder.forms = importExportCrud;\n });\n});\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AAEA,MAAMA,4BAA4B,GAAGC,OAAO,CAACC,GAAG,CAACC,sBA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BAAmB,EAAmC;UACxDf,OAAO;UACPgB,IAAI,EAAEvB,4BAA4B;UAClCwB,OAAO,EAAE;YACLgC,MAAM,EAAE1C,IAAI,CAAC8B,EAAE;YACfa,YAAY,EAAE,CAAC;YACfhC,IAAI,EAAE,MAAM;YACZC,QAAQ,EAAEnB,OAAO,CAACoB,QAAQ,CAACC,WAAW;UAC1C,CAAC;UACDC,WAAW,EAAE;QACjB,CAAC,CAAC;QAEF,OAAO;UAAEf;QAAK,CAAC;MACnB;IACJ,CAAC;IACD;IACAP,OAAO,CAACgC,WAAW,CAACD,KAAK,GAAG7B,gBAAgB;EAChD,CAAC,CAAC;AACN,CAAC,CAAC;AAAA"}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { ContextPlugin } from "@webiny/api";
|
2
|
+
import { ImportExportPluginsParams } from "../../types";
|
3
|
+
import { PbImportExportContext } from "../types";
|
4
|
+
declare const _default: ({ storageOperations }: ImportExportPluginsParams) => ContextPlugin<PbImportExportContext>;
|
5
|
+
export default _default;
|