@webiny/api-page-builder-import-export 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.d16f688daf

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.
Files changed (105) hide show
  1. package/client.d.ts +2 -2
  2. package/client.js +6 -2
  3. package/client.js.map +1 -1
  4. package/export/combine/blocksHandler.d.ts +6 -0
  5. package/export/combine/blocksHandler.js +106 -0
  6. package/export/combine/blocksHandler.js.map +1 -0
  7. package/{exportPages → export}/combine/index.d.ts +3 -2
  8. package/export/combine/index.js +30 -0
  9. package/export/combine/index.js.map +1 -0
  10. package/export/combine/pagesHandler.d.ts +6 -0
  11. package/export/combine/pagesHandler.js +106 -0
  12. package/export/combine/pagesHandler.js.map +1 -0
  13. package/export/process/blocksHandler.d.ts +6 -0
  14. package/export/process/blocksHandler.js +176 -0
  15. package/export/process/blocksHandler.js.map +1 -0
  16. package/{exportPages → export}/process/index.d.ts +4 -6
  17. package/export/process/index.js +27 -0
  18. package/export/process/index.js.map +1 -0
  19. package/export/process/pagesHandler.d.ts +6 -0
  20. package/export/process/pagesHandler.js +204 -0
  21. package/export/process/pagesHandler.js.map +1 -0
  22. package/{exportPages → export}/s3Stream.d.ts +0 -0
  23. package/{exportPages → export}/s3Stream.js +20 -1
  24. package/{exportPages → export}/s3Stream.js.map +1 -1
  25. package/export/utils.d.ts +16 -0
  26. package/export/utils.js +135 -0
  27. package/export/utils.js.map +1 -0
  28. package/{exportPages → export}/zipper.d.ts +6 -5
  29. package/{exportPages → export}/zipper.js +49 -36
  30. package/export/zipper.js.map +1 -0
  31. package/graphql/crud/blocks.crud.d.ts +4 -0
  32. package/graphql/crud/blocks.crud.js +155 -0
  33. package/graphql/crud/blocks.crud.js.map +1 -0
  34. package/graphql/crud/importExportTasks.crud.d.ts +5 -0
  35. package/graphql/crud/{pageImportExportTasks.crud.js → importExportTasks.crud.js} +105 -57
  36. package/graphql/crud/importExportTasks.crud.js.map +1 -0
  37. package/graphql/crud/pages.crud.d.ts +2 -2
  38. package/graphql/crud/pages.crud.js +53 -33
  39. package/graphql/crud/pages.crud.js.map +1 -1
  40. package/graphql/crud.d.ts +2 -2
  41. package/graphql/crud.js +9 -2
  42. package/graphql/crud.js.map +1 -1
  43. package/graphql/graphql/blocks.gql.d.ts +4 -0
  44. package/graphql/graphql/blocks.gql.js +57 -0
  45. package/graphql/graphql/blocks.gql.js.map +1 -0
  46. package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
  47. package/graphql/graphql/{pageImportExportTasks.gql.js → importExportTasks.gql.js} +23 -18
  48. package/graphql/graphql/importExportTasks.gql.js.map +1 -0
  49. package/graphql/graphql/pages.gql.d.ts +2 -2
  50. package/graphql/graphql/pages.gql.js +8 -9
  51. package/graphql/graphql/pages.gql.js.map +1 -1
  52. package/graphql/graphql/utils/resolve.d.ts +1 -1
  53. package/graphql/graphql/utils/resolve.js +3 -0
  54. package/graphql/graphql/utils/resolve.js.map +1 -1
  55. package/graphql/graphql.js +8 -2
  56. package/graphql/graphql.js.map +1 -1
  57. package/graphql/index.d.ts +2 -2
  58. package/graphql/index.js +5 -0
  59. package/graphql/index.js.map +1 -1
  60. package/graphql/types.d.ts +43 -23
  61. package/graphql/types.js.map +1 -1
  62. package/import/create/blocksHandler.d.ts +3 -0
  63. package/import/create/blocksHandler.js +110 -0
  64. package/import/create/blocksHandler.js.map +1 -0
  65. package/{importPages → import}/create/index.d.ts +5 -4
  66. package/import/create/index.js +30 -0
  67. package/import/create/index.js.map +1 -0
  68. package/import/create/pagesHandler.d.ts +3 -0
  69. package/import/create/pagesHandler.js +110 -0
  70. package/import/create/pagesHandler.js.map +1 -0
  71. package/import/process/blocksHandler.d.ts +3 -0
  72. package/import/process/blocksHandler.js +175 -0
  73. package/import/process/blocksHandler.js.map +1 -0
  74. package/{importPages → import}/process/index.d.ts +4 -3
  75. package/import/process/index.js +27 -0
  76. package/import/process/index.js.map +1 -0
  77. package/import/process/pagesHandler.d.ts +3 -0
  78. package/import/process/pagesHandler.js +180 -0
  79. package/import/process/pagesHandler.js.map +1 -0
  80. package/{importPages → import}/utils.d.ts +19 -20
  81. package/{importPages → import}/utils.js +229 -76
  82. package/import/utils.js.map +1 -0
  83. package/mockSecurity.js +2 -0
  84. package/mockSecurity.js.map +1 -1
  85. package/package.json +23 -23
  86. package/types.d.ts +62 -65
  87. package/types.js +22 -17
  88. package/types.js.map +1 -1
  89. package/exportPages/combine/index.js +0 -106
  90. package/exportPages/combine/index.js.map +0 -1
  91. package/exportPages/process/index.js +0 -192
  92. package/exportPages/process/index.js.map +0 -1
  93. package/exportPages/utils.d.ts +0 -13
  94. package/exportPages/utils.js +0 -100
  95. package/exportPages/utils.js.map +0 -1
  96. package/exportPages/zipper.js.map +0 -1
  97. package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
  98. package/graphql/crud/pageImportExportTasks.crud.js.map +0 -1
  99. package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
  100. package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
  101. package/importPages/create/index.js +0 -107
  102. package/importPages/create/index.js.map +0 -1
  103. package/importPages/process/index.js +0 -180
  104. package/importPages/process/index.js.map +0 -1
  105. package/importPages/utils.js.map +0 -1
@@ -1,20 +1,29 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
4
5
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
8
10
  exports.default = exports.ZipOfZip = void 0;
11
+
9
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
10
14
  var _archiver = _interopRequireDefault(require("archiver"));
15
+
11
16
  var _stream = require("stream");
17
+
12
18
  var path = _interopRequireWildcard(require("path"));
19
+
13
20
  var _kebabCase = _interopRequireDefault(require("lodash/kebabCase"));
21
+
14
22
  var _uniqid = _interopRequireDefault(require("uniqid"));
23
+
15
24
  var _s3Stream = require("./s3Stream");
16
- // TODO: Move "archive" in layer
17
25
 
26
+ // TODO: Move "archive" in layer
18
27
  class Zipper {
19
28
  constructor(config) {
20
29
  (0, _defineProperty2.default)(this, "archiveFormat", "zip");
@@ -22,11 +31,12 @@ class Zipper {
22
31
  (0, _defineProperty2.default)(this, "archiveFileName", void 0);
23
32
  (0, _defineProperty2.default)(this, "config", void 0);
24
33
  this.config = config;
25
- this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.pageTitle)}.zip`);
34
+ this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.name)}.zip`);
26
35
  }
36
+
27
37
  s3DownloadStreams() {
28
38
  const exportInfo = this.config.exportInfo;
29
- const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.pageTitle)}`);
39
+ const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.name)}`);
30
40
  const files = exportInfo.files.map(({
31
41
  key
32
42
  }) => {
@@ -36,51 +46,54 @@ class Zipper {
36
46
  };
37
47
  });
38
48
  return [...files, {
39
- stream: _stream.Readable.from(exportInfo.pageDataBuffer),
40
- filename: `${prefix}\\${exportInfo.pageTitle}.json`
49
+ stream: _stream.Readable.from(exportInfo.dataBuffer),
50
+ filename: `${prefix}\\${exportInfo.name}.json`
41
51
  }];
42
52
  }
53
+
43
54
  process() {
44
55
  const {
45
56
  streamPassThrough,
46
57
  streamPassThroughUploadPromise
47
- } = _s3Stream.s3Stream.writeStream(this.archiveFileName);
58
+ } = _s3Stream.s3Stream.writeStream(this.archiveFileName); // 1. Read all files from S3 using stream.
59
+
60
+
61
+ const s3FilesStreams = this.s3DownloadStreams(); // 2. Prepare zip from the file stream.
62
+
63
+ const archive = _archiver.default.create(this.archiveFormat); // Handle archive events.
48
64
 
49
- // 1. Read all files from S3 using stream.
50
- const s3FilesStreams = this.s3DownloadStreams();
51
65
 
52
- // 2. Prepare zip from the file stream.
53
- const archive = _archiver.default.create(this.archiveFormat);
54
- // Handle archive events.
55
66
  archive.on("error", error => {
56
67
  throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
57
- });
68
+ }); // Append all file streams to archive.
58
69
 
59
- // Append all file streams to archive.
60
70
  s3FilesStreams.forEach(streamDetails => archive.append(streamDetails.stream, {
61
71
  name: streamDetails.filename
62
- }));
72
+ })); // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
63
73
 
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)
74
+ archive.pipe(streamPassThrough); // Finalize the archive (ie we are done appending files but streams have to finish yet)
67
75
  // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
68
- archive.finalize();
69
76
 
70
- // 3. Return upload stream promise.
77
+ archive.finalize(); // 3. Return upload stream promise.
78
+
71
79
  return streamPassThroughUploadPromise;
72
80
  }
81
+
73
82
  }
83
+
74
84
  exports.default = Zipper;
75
- const PAGE_EXPORT_BASENAME = `WEBINY_PAGE_EXPORT.zip`;
85
+
76
86
  class ZipOfZip {
77
- constructor(keys) {
87
+ constructor(keys, filename) {
78
88
  (0, _defineProperty2.default)(this, "archiveFormat", "zip");
79
89
  (0, _defineProperty2.default)(this, "archiveFileName", void 0);
80
90
  (0, _defineProperty2.default)(this, "keys", void 0);
91
+ (0, _defineProperty2.default)(this, "filename", void 0);
81
92
  this.keys = keys;
82
- this.archiveFileName = (0, _uniqid.default)("", `-${PAGE_EXPORT_BASENAME}`);
93
+ this.filename = filename;
94
+ this.archiveFileName = (0, _uniqid.default)("", `-${filename}`);
83
95
  }
96
+
84
97
  getFileStreams() {
85
98
  return this.keys.map(key => {
86
99
  return {
@@ -89,35 +102,35 @@ class ZipOfZip {
89
102
  };
90
103
  });
91
104
  }
105
+
92
106
  process() {
93
107
  const {
94
108
  streamPassThrough,
95
109
  streamPassThroughUploadPromise
96
- } = _s3Stream.s3Stream.writeStream(this.archiveFileName);
110
+ } = _s3Stream.s3Stream.writeStream(this.archiveFileName); // 1. Read all files from S3 using stream.
111
+
112
+
113
+ const fileStreamDetails = this.getFileStreams(); // 2. Prepare zip from the file stream.
114
+
115
+ const archive = _archiver.default.create(this.archiveFormat); // Handle archive events.
97
116
 
98
- // 1. Read all files from S3 using stream.
99
- const fileStreamDetails = this.getFileStreams();
100
117
 
101
- // 2. Prepare zip from the file stream.
102
- const archive = _archiver.default.create(this.archiveFormat);
103
- // Handle archive events.
104
118
  archive.on("error", error => {
105
119
  throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
106
- });
120
+ }); // Append all file streams to archive.
107
121
 
108
- // Append all file streams to archive.
109
122
  fileStreamDetails.forEach(streamDetails => archive.append(streamDetails.stream, {
110
123
  name: streamDetails.filename
111
- }));
124
+ })); // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
112
125
 
113
- // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
114
- archive.pipe(streamPassThrough);
115
- // Finalize the archive (ie we are done appending files but streams have to finish yet)
126
+ archive.pipe(streamPassThrough); // Finalize the archive (ie we are done appending files but streams have to finish yet)
116
127
  // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
117
- archive.finalize();
118
128
 
119
- // 3. Return upload stream promise.
129
+ archive.finalize(); // 3. Return upload stream promise.
130
+
120
131
  return streamPassThroughUploadPromise;
121
132
  }
133
+
122
134
  }
135
+
123
136
  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","path","basename","Readable","from","dataBuffer","process","streamPassThrough","streamPassThroughUploadPromise","writeStream","s3FilesStreams","archive","vending","create","archiveFormat","on","error","Error","code","message","stack","forEach","streamDetails","append","pipe","finalize","ZipOfZip","keys","getFileStreams","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}\\\\${path.basename(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(\"\", `-${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}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;IAIH,CALM,CAAP;EAMH;;EAEDW,OAAO,GAAuC;IAC1C,MAAM;MAAEC,iBAAF;MAAqBC;IAArB,IAAwDX,kBAAA,CAASY,WAAT,CAC1D,KAAKxB,eADqD,CAA9D,CAD0C,CAK1C;;;IACA,MAAM4C,iBAAiB,GAAG,KAAKD,cAAL,EAA1B,CAN0C,CAQ1C;;IACA,MAAMjB,OAAO,GAAGC,iBAAA,CAAQC,MAAR,CAAe,KAAKC,aAApB,CAAhB,CAT0C,CAU1C;;;IACAH,OAAO,CAACI,EAAR,CAAW,OAAX,EAAqBC,KAAD,IAA0B;MAC1C,MAAM,IAAIC,KAAJ,CACD,GAAED,KAAK,CAAC1B,IAAK,IAAG0B,KAAK,CAACE,IAAK,IAAGF,KAAK,CAACG,OAAQ,IAAGH,KAAK,CAACf,IAAK,IAAGe,KAAK,CAACI,KAAM,EADxE,CAAN;IAGH,CAJD,EAX0C,CAiB1C;;IACAS,iBAAiB,CAACR,OAAlB,CAA2BC,aAAD,IACtBX,OAAO,CAACY,MAAR,CAAeD,aAAa,CAAC1B,MAA7B,EAAqC;MAAEN,IAAI,EAAEgC,aAAa,CAACvB;IAAtB,CAArC,CADJ,EAlB0C,CAsB1C;;IACAY,OAAO,CAACa,IAAR,CAAajB,iBAAb,EAvB0C,CAwB1C;IACA;;IACAI,OAAO,CAACc,QAAR,GA1B0C,CA4B1C;;IACA,OAAOjB,8BAAP;EACH;;AAnDiB"}
@@ -0,0 +1,4 @@
1
+ import { ContextPlugin } from "@webiny/api";
2
+ import { PbImportExportContext } from "../../types";
3
+ declare const _default: ContextPlugin<PbImportExportContext>;
4
+ export default _default;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ var _handlerGraphql = require("@webiny/handler-graphql");
13
+
14
+ var _api = require("@webiny/api");
15
+
16
+ var _checkBasePermissions = _interopRequireDefault(require("@webiny/api-page-builder/graphql/crud/utils/checkBasePermissions"));
17
+
18
+ var _types = require("../../types");
19
+
20
+ var _client = require("../../client");
21
+
22
+ var _utils = require("../../import/utils");
23
+
24
+ var _utils2 = require("../../export/utils");
25
+
26
+ var _utils3 = require("@webiny/utils");
27
+
28
+ const PERMISSION_NAME = "pb.block";
29
+ const EXPORT_BLOCKS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER;
30
+ const IMPORT_BLOCKS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER;
31
+
32
+ var _default = new _api.ContextPlugin(context => {
33
+ const importExportCrud = {
34
+ async importBlocks({
35
+ category: categorySlug,
36
+ zipFileUrl
37
+ }) {
38
+ await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
39
+ rwd: "w"
40
+ }); // Bail out early if category not found
41
+
42
+ const category = await context.pageBuilder.getBlockCategory(categorySlug);
43
+
44
+ if (!category) {
45
+ throw new _handlerGraphql.NotFoundError(`Category with slug "${categorySlug}" not found.`);
46
+ } // Create a task for import block
47
+
48
+
49
+ const task = await context.pageBuilder.importExportTask.createTask({
50
+ status: _types.ImportExportTaskStatus.PENDING,
51
+ input: {
52
+ category: categorySlug,
53
+ zipFileUrl
54
+ }
55
+ });
56
+ /**
57
+ * Import Blocks
58
+ * ImportBlocks
59
+ * importBlocks
60
+ */
61
+
62
+ await (0, _client.invokeHandlerClient)({
63
+ context,
64
+ name: IMPORT_BLOCKS_CREATE_HANDLER,
65
+ payload: {
66
+ category: categorySlug,
67
+ zipFileUrl,
68
+ task,
69
+ type: "block",
70
+ identity: context.security.getIdentity()
71
+ },
72
+ description: "Import Blocks - create"
73
+ });
74
+ return {
75
+ task
76
+ };
77
+ },
78
+
79
+ async exportBlocks({
80
+ ids: initialBlockIds,
81
+ where
82
+ }) {
83
+ await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
84
+ rwd: "w"
85
+ });
86
+ let blockIds = initialBlockIds || []; // If no ids are provided then it means we want to export all blocks
87
+
88
+ if (!initialBlockIds || Array.isArray(initialBlockIds) && initialBlockIds.length === 0) {
89
+ blockIds = [];
90
+ const blocks = await context.pageBuilder.listPageBlocks({
91
+ where
92
+ }); // Save block ids
93
+
94
+ blocks.forEach(block => blockIds.push(block.id));
95
+ }
96
+
97
+ if (blockIds.length === 0) {
98
+ throw new _error.default("Cannot export blocks - no blocks found for provided inputs.", "EMPTY_EXPORT_NO_BLOCKS_FOUND");
99
+ } // Create the main task for blocks export.
100
+
101
+
102
+ const task = await context.pageBuilder.importExportTask.createTask({
103
+ status: _types.ImportExportTaskStatus.PENDING
104
+ });
105
+ const exportBlocksDataKey = `${_utils2.EXPORT_BLOCKS_FOLDER_KEY}/${task.id}`; // For each block create a sub task and invoke the process handler.
106
+
107
+ for (let i = 0; i < blockIds.length; i++) {
108
+ const blockId = blockIds[i]; // Create sub task.
109
+
110
+ await context.pageBuilder.importExportTask.createSubTask(task.id, (0, _utils3.zeroPad)(i + 1, 5), {
111
+ status: _types.ImportExportTaskStatus.PENDING,
112
+ input: {
113
+ blockId,
114
+ exportBlocksDataKey
115
+ }
116
+ });
117
+ } // Update main task status.
118
+
119
+
120
+ await context.pageBuilder.importExportTask.updateTask(task.id, {
121
+ status: _types.ImportExportTaskStatus.PROCESSING,
122
+ stats: (0, _utils.initialStats)(blockIds.length),
123
+ input: {
124
+ exportBlocksDataKey
125
+ }
126
+ });
127
+ /**
128
+ * Export Blocks
129
+ * ExportBlocks
130
+ * exportBlocks
131
+ */
132
+ // Invoke handler.
133
+
134
+ await (0, _client.invokeHandlerClient)({
135
+ context,
136
+ name: EXPORT_BLOCKS_PROCESS_HANDLER,
137
+ payload: {
138
+ taskId: task.id,
139
+ subTaskIndex: 1,
140
+ type: "block",
141
+ identity: context.security.getIdentity()
142
+ },
143
+ description: "Export blocks - process"
144
+ });
145
+ return {
146
+ task
147
+ };
148
+ }
149
+
150
+ }; // Modify context
151
+
152
+ context.pageBuilder.blocks = importExportCrud;
153
+ });
154
+
155
+ 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","forEach","block","push","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 blockIds = [];\n const blocks = await context.pageBuilder.listPageBlocks({ where });\n // Save block ids\n blocks.forEach(block => blockIds.push(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,UAAxB;AACA,MAAMC,6BAA6B,GAAGC,OAAO,CAACC,GAAR,CAAYC,sBAAlD;AACA,MAAMC,4BAA4B,GAAGH,OAAO,CAACC,GAAR,CAAYG,qBAAjD;;eAEe,IAAIC,kBAAJ,CAAyCC,OAAO,IAAI;EAC/D,MAAMC,gBAAwC,GAAG;IAC7C,MAAMC,YAAN,CAAmB;MAAEC,QAAQ,EAAEC,YAAZ;MAA0BC;IAA1B,CAAnB,EAA2D;MACvD,MAAM,IAAAC,6BAAA,EAAqBN,OAArB,EAA8BR,eAA9B,EAA+C;QACjDe,GAAG,EAAE;MAD4C,CAA/C,CAAN,CADuD,CAKvD;;MACA,MAAMJ,QAAQ,GAAG,MAAMH,OAAO,CAACQ,WAAR,CAAoBC,gBAApB,CAAqCL,YAArC,CAAvB;;MACA,IAAI,CAACD,QAAL,EAAe;QACX,MAAM,IAAIO,6BAAJ,CAAmB,uBAAsBN,YAAa,cAAtD,CAAN;MACH,CATsD,CAWvD;;;MACA,MAAMO,IAAI,GAAG,MAAMX,OAAO,CAACQ,WAAR,CAAoBI,gBAApB,CAAqCC,UAArC,CAAgD;QAC/DC,MA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iBC,WAAjB;QAJL,CAHgD;QASzDC,WAAW,EAAE;MAT4C,CAAvD,CAAN;MAYA,OAAO;QAAEd;MAAF,CAAP;IACH;;EAnH4C,CAAjD,CAD+D,CAsH/D;;EACAX,OAAO,CAACQ,WAAR,CAAoB0B,MAApB,GAA6BjC,gBAA7B;AACH,CAxHc,C"}
@@ -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;