@webiny/api-page-builder-import-export 0.0.0-unstable.aad28a72ae → 0.0.0-unstable.acacc54f0e

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 (166) hide show
  1. package/client.js +2 -6
  2. package/client.js.map +1 -1
  3. package/export/combine/blocksHandler.js +11 -18
  4. package/export/combine/blocksHandler.js.map +1 -1
  5. package/export/combine/formsHandler.d.ts +6 -0
  6. package/export/combine/formsHandler.js +99 -0
  7. package/export/combine/formsHandler.js.map +1 -0
  8. package/export/combine/index.js +22 -10
  9. package/export/combine/index.js.map +1 -1
  10. package/export/combine/pagesHandler.js +11 -18
  11. package/export/combine/pagesHandler.js.map +1 -1
  12. package/export/combine/templatesHandler.d.ts +6 -0
  13. package/export/combine/templatesHandler.js +99 -0
  14. package/export/combine/templatesHandler.js.map +1 -0
  15. package/export/process/blocksHandler.js +27 -36
  16. package/export/process/blocksHandler.js.map +1 -1
  17. package/export/process/exporters/BlockExporter.d.ts +13 -0
  18. package/export/process/exporters/BlockExporter.js +81 -0
  19. package/export/process/exporters/BlockExporter.js.map +1 -0
  20. package/export/process/exporters/FormExporter.d.ts +9 -0
  21. package/export/process/exporters/FormExporter.js +34 -0
  22. package/export/process/exporters/FormExporter.js.map +1 -0
  23. package/export/process/exporters/PageExporter.d.ts +11 -0
  24. package/export/process/exporters/PageExporter.js +58 -0
  25. package/export/process/exporters/PageExporter.js.map +1 -0
  26. package/export/process/exporters/PageTemplateExporter.d.ts +11 -0
  27. package/export/process/exporters/PageTemplateExporter.js +56 -0
  28. package/export/process/exporters/PageTemplateExporter.js.map +1 -0
  29. package/export/process/formsHandler.d.ts +6 -0
  30. package/export/process/formsHandler.js +187 -0
  31. package/export/process/formsHandler.js.map +1 -0
  32. package/export/process/index.js +22 -10
  33. package/export/process/index.js.map +1 -1
  34. package/export/process/pagesHandler.js +23 -38
  35. package/export/process/pagesHandler.js.map +1 -1
  36. package/export/process/templatesHandler.d.ts +6 -0
  37. package/export/process/templatesHandler.js +166 -0
  38. package/export/process/templatesHandler.js.map +1 -0
  39. package/export/s3Stream.d.ts +5 -2
  40. package/export/s3Stream.js +1 -20
  41. package/export/s3Stream.js.map +1 -1
  42. package/export/utils.d.ts +2 -16
  43. package/export/utils.js +5 -105
  44. package/export/utils.js.map +1 -1
  45. package/export/zipper.js +31 -43
  46. package/export/zipper.js.map +1 -1
  47. package/graphql/crud/blocks.crud.js +29 -54
  48. package/graphql/crud/blocks.crud.js.map +1 -1
  49. package/graphql/crud/forms.crud.d.ts +4 -0
  50. package/graphql/crud/forms.crud.js +134 -0
  51. package/graphql/crud/forms.crud.js.map +1 -0
  52. package/graphql/crud/importExportTasks.crud.js +47 -94
  53. package/graphql/crud/importExportTasks.crud.js.map +1 -1
  54. package/graphql/crud/pages.crud.d.ts +1 -0
  55. package/graphql/crud/pages.crud.js +38 -49
  56. package/graphql/crud/pages.crud.js.map +1 -1
  57. package/graphql/crud/templates.crud.d.ts +4 -0
  58. package/graphql/crud/templates.crud.js +128 -0
  59. package/graphql/crud/templates.crud.js.map +1 -0
  60. package/graphql/crud.js +3 -7
  61. package/graphql/crud.js.map +1 -1
  62. package/graphql/graphql/blocks.gql.js +2 -7
  63. package/graphql/graphql/blocks.gql.js.map +1 -1
  64. package/graphql/graphql/forms.gql.d.ts +4 -0
  65. package/graphql/graphql/forms.gql.js +60 -0
  66. package/graphql/graphql/forms.gql.js.map +1 -0
  67. package/graphql/graphql/importExportTasks.gql.js +1 -6
  68. package/graphql/graphql/importExportTasks.gql.js.map +1 -1
  69. package/graphql/graphql/pages.gql.js +2 -7
  70. package/graphql/graphql/pages.gql.js.map +1 -1
  71. package/graphql/graphql/templates.gql.d.ts +4 -0
  72. package/graphql/graphql/templates.gql.js +52 -0
  73. package/graphql/graphql/templates.gql.js.map +1 -0
  74. package/graphql/graphql/utils/resolve.d.ts +1 -1
  75. package/graphql/graphql/utils/resolve.js +0 -3
  76. package/graphql/graphql/utils/resolve.js.map +1 -1
  77. package/graphql/graphql.js +3 -6
  78. package/graphql/graphql.js.map +1 -1
  79. package/graphql/index.js +0 -5
  80. package/graphql/index.js.map +1 -1
  81. package/graphql/types.d.ts +40 -1
  82. package/graphql/types.js.map +1 -1
  83. package/import/constants.d.ts +3 -0
  84. package/import/constants.js +14 -0
  85. package/import/constants.js.map +1 -0
  86. package/import/create/blocksHandler.js +11 -22
  87. package/import/create/blocksHandler.js.map +1 -1
  88. package/import/{process/pagesHandler.d.ts → create/formsHandler.d.ts} +1 -1
  89. package/import/create/formsHandler.js +103 -0
  90. package/import/create/formsHandler.js.map +1 -0
  91. package/import/create/index.d.ts +2 -1
  92. package/import/create/index.js +22 -10
  93. package/import/create/index.js.map +1 -1
  94. package/import/create/pagesHandler.js +13 -20
  95. package/import/create/pagesHandler.js.map +1 -1
  96. package/import/create/templatesHandler.d.ts +3 -0
  97. package/import/create/templatesHandler.js +99 -0
  98. package/import/create/templatesHandler.js.map +1 -0
  99. package/import/process/{blocksHandler.d.ts → blocks/blocksHandler.d.ts} +2 -2
  100. package/import/process/{blocksHandler.js → blocks/blocksHandler.js} +28 -35
  101. package/import/process/blocks/blocksHandler.js.map +1 -0
  102. package/import/process/blocks/importBlock.d.ts +11 -0
  103. package/import/process/blocks/importBlock.js +106 -0
  104. package/import/process/blocks/importBlock.js.map +1 -0
  105. package/import/process/forms/formsHandler.d.ts +3 -0
  106. package/import/process/forms/formsHandler.js +176 -0
  107. package/import/process/forms/formsHandler.js.map +1 -0
  108. package/import/process/forms/importForm.d.ts +9 -0
  109. package/import/process/forms/importForm.js +43 -0
  110. package/import/process/forms/importForm.js.map +1 -0
  111. package/import/process/index.d.ts +1 -0
  112. package/import/process/index.js +24 -12
  113. package/import/process/index.js.map +1 -1
  114. package/import/process/pages/importPage.d.ts +11 -0
  115. package/import/process/pages/importPage.js +92 -0
  116. package/import/process/pages/importPage.js.map +1 -0
  117. package/import/process/pages/pagesHandler.d.ts +3 -0
  118. package/import/process/{pagesHandler.js → pages/pagesHandler.js} +39 -36
  119. package/import/process/pages/pagesHandler.js.map +1 -0
  120. package/import/process/templates/importTemplate.d.ts +11 -0
  121. package/import/process/templates/importTemplate.js +66 -0
  122. package/import/process/templates/importTemplate.js.map +1 -0
  123. package/import/process/templates/templatesHandler.d.ts +3 -0
  124. package/import/process/templates/templatesHandler.js +170 -0
  125. package/import/process/templates/templatesHandler.js.map +1 -0
  126. package/import/utils/deleteS3Folder.d.ts +1 -0
  127. package/import/utils/deleteS3Folder.js +19 -0
  128. package/import/utils/deleteS3Folder.js.map +1 -0
  129. package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
  130. package/import/utils/extractAndUploadZipFileContents.js +122 -0
  131. package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
  132. package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
  133. package/import/utils/extractZipAndUploadToS3.js +98 -0
  134. package/import/utils/extractZipAndUploadToS3.js.map +1 -0
  135. package/import/utils/getFileNameWithoutExt.d.ts +1 -0
  136. package/import/utils/getFileNameWithoutExt.js +11 -0
  137. package/import/utils/getFileNameWithoutExt.js.map +1 -0
  138. package/import/utils/index.d.ts +9 -0
  139. package/import/utils/index.js +104 -0
  140. package/import/utils/index.js.map +1 -0
  141. package/import/utils/initialStats.d.ts +7 -0
  142. package/import/utils/initialStats.js +16 -0
  143. package/import/utils/initialStats.js.map +1 -0
  144. package/import/utils/prepareDataDirMap.d.ts +6 -0
  145. package/import/utils/prepareDataDirMap.js +29 -0
  146. package/import/utils/prepareDataDirMap.js.map +1 -0
  147. package/import/utils/updateFilesInData.d.ts +8 -0
  148. package/import/utils/updateFilesInData.js +49 -0
  149. package/import/utils/updateFilesInData.js.map +1 -0
  150. package/import/utils/uploadAssets.d.ts +10 -0
  151. package/import/utils/uploadAssets.js +87 -0
  152. package/import/utils/uploadAssets.js.map +1 -0
  153. package/import/utils/uploadFilesFromS3.d.ts +3 -0
  154. package/import/utils/uploadFilesFromS3.js +19 -0
  155. package/import/utils/uploadFilesFromS3.js.map +1 -0
  156. package/mockSecurity.js +0 -3
  157. package/mockSecurity.js.map +1 -1
  158. package/package.json +34 -37
  159. package/types.d.ts +21 -0
  160. package/types.js +60 -13
  161. package/types.js.map +1 -1
  162. package/import/process/blocksHandler.js.map +0 -1
  163. package/import/process/pagesHandler.js.map +0 -1
  164. package/import/utils.d.ts +0 -49
  165. package/import/utils.js +0 -641
  166. package/import/utils.js.map +0 -1
package/export/zipper.js CHANGED
@@ -1,29 +1,20 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
-
5
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports.default = exports.ZipOfZip = void 0;
11
-
12
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
10
  var _archiver = _interopRequireDefault(require("archiver"));
15
-
16
11
  var _stream = require("stream");
17
-
18
12
  var path = _interopRequireWildcard(require("path"));
19
-
20
13
  var _kebabCase = _interopRequireDefault(require("lodash/kebabCase"));
21
-
22
14
  var _uniqid = _interopRequireDefault(require("uniqid"));
23
-
24
15
  var _s3Stream = require("./s3Stream");
25
-
26
16
  // TODO: Move "archive" in layer
17
+
27
18
  class Zipper {
28
19
  constructor(config) {
29
20
  (0, _defineProperty2.default)(this, "archiveFormat", "zip");
@@ -33,7 +24,6 @@ class Zipper {
33
24
  this.config = config;
34
25
  this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.name)}.zip`);
35
26
  }
36
-
37
27
  s3DownloadStreams() {
38
28
  const exportInfo = this.config.exportInfo;
39
29
  const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.name)}`);
@@ -42,7 +32,7 @@ class Zipper {
42
32
  }) => {
43
33
  return {
44
34
  stream: _s3Stream.s3Stream.readStream(key),
45
- filename: `${prefix}\\${this.filesDirName}\\${path.basename(key)}`
35
+ filename: `${prefix}\\${this.filesDirName}\\${key}`
46
36
  };
47
37
  });
48
38
  return [...files, {
@@ -50,39 +40,38 @@ class Zipper {
50
40
  filename: `${prefix}\\${exportInfo.name}.json`
51
41
  }];
52
42
  }
53
-
54
43
  process() {
55
44
  const {
56
45
  streamPassThrough,
57
46
  streamPassThroughUploadPromise
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.
47
+ } = _s3Stream.s3Stream.writeStream(this.archiveFileName);
64
48
 
49
+ // 1. Read all files from S3 using stream.
50
+ const s3FilesStreams = this.s3DownloadStreams();
65
51
 
52
+ // 2. Prepare zip from the file stream.
53
+ const archive = _archiver.default.create(this.archiveFormat);
54
+ // Handle archive events.
66
55
  archive.on("error", error => {
67
56
  throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
68
- }); // Append all file streams to archive.
57
+ });
69
58
 
59
+ // Append all file streams to archive.
70
60
  s3FilesStreams.forEach(streamDetails => archive.append(streamDetails.stream, {
71
61
  name: streamDetails.filename
72
- })); // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
62
+ }));
73
63
 
74
- archive.pipe(streamPassThrough); // Finalize the archive (ie we are done appending files but streams have to finish yet)
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)
75
67
  // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
68
+ archive.finalize();
76
69
 
77
- archive.finalize(); // 3. Return upload stream promise.
78
-
70
+ // 3. Return upload stream promise.
79
71
  return streamPassThroughUploadPromise;
80
72
  }
81
-
82
73
  }
83
-
84
74
  exports.default = Zipper;
85
-
86
75
  class ZipOfZip {
87
76
  constructor(keys, filename) {
88
77
  (0, _defineProperty2.default)(this, "archiveFormat", "zip");
@@ -91,9 +80,8 @@ class ZipOfZip {
91
80
  (0, _defineProperty2.default)(this, "filename", void 0);
92
81
  this.keys = keys;
93
82
  this.filename = filename;
94
- this.archiveFileName = (0, _uniqid.default)("", `-${filename}`);
83
+ this.archiveFileName = (0, _uniqid.default)("EXPORTS/", `-${filename}`);
95
84
  }
96
-
97
85
  getFileStreams() {
98
86
  return this.keys.map(key => {
99
87
  return {
@@ -102,35 +90,35 @@ class ZipOfZip {
102
90
  };
103
91
  });
104
92
  }
105
-
106
93
  process() {
107
94
  const {
108
95
  streamPassThrough,
109
96
  streamPassThroughUploadPromise
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
+ } = _s3Stream.s3Stream.writeStream(this.archiveFileName);
116
98
 
99
+ // 1. Read all files from S3 using stream.
100
+ const fileStreamDetails = this.getFileStreams();
117
101
 
102
+ // 2. Prepare zip from the file stream.
103
+ const archive = _archiver.default.create(this.archiveFormat);
104
+ // Handle archive events.
118
105
  archive.on("error", error => {
119
106
  throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
120
- }); // Append all file streams to archive.
107
+ });
121
108
 
109
+ // Append all file streams to archive.
122
110
  fileStreamDetails.forEach(streamDetails => archive.append(streamDetails.stream, {
123
111
  name: streamDetails.filename
124
- })); // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
112
+ }));
125
113
 
126
- archive.pipe(streamPassThrough); // Finalize the archive (ie we are done appending files but streams have to finish yet)
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)
127
117
  // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
118
+ archive.finalize();
128
119
 
129
- archive.finalize(); // 3. Return upload stream promise.
130
-
120
+ // 3. Return upload stream promise.
131
121
  return streamPassThroughUploadPromise;
132
122
  }
133
-
134
123
  }
135
-
136
124
  exports.ZipOfZip = ZipOfZip;
@@ -1 +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}\n"],"mappings":";;;;;;;;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAPA;AA0Be,MAAMA,MAAN,CAAa;EAMxBC,WAAW,CAACC,MAAD,EAAuB;IAAA,qDALD,KAKC;IAAA,oDAJF,QAIE;IAAA;IAAA;IAC9B,KAAKA,MAAL,GAAcA,MAAd;IACA,KAAKC,eAAL,GAAuB,IAAAC,eAAA,EAClB,GAAE,KAAKF,MAAL,CAAYG,cAAe,GADX,EAElB,IAAG,IAAAC,kBAAA,EAAU,KAAKJ,MAAL,CAAYK,UAAZ,CAAuBC,IAAjC,CAAuC,MAFxB,CAAvB;EAIH;;EAEDC,iBAAiB,GAAwB;IACrC,MAAMF,UAAU,GAAG,KAAKL,MAAL,CAAYK,UAA/B;IACA,MAAMG,MAAM,GAAG,IAAAN,eAAA,EAAS,EAAT,EAAc,IAAG,IAAAE,kBAAA,EAAUC,UAAU,CAACC,IAArB,CAA2B,EAA5C,CAAf;IACA,MAAMG,KAAK,GAAGJ,UAAU,CAACI,KAAX,CAAiBC,GAAjB,CAAqB,CAAC;MAAEC;IAAF,CAAD,KAAa;MAC5C,OAAO;QACHC,MAAM,EAAEC,kBAAA,CAASC,UAAT,CAAoBH,GAApB,CADL;QAEHI,QAAQ,EAAG,GAAEP,MAAO,KAAI,KAAKQ,YAAa,KAAIC,IAA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QAAR,GA1B0C,CA4B1C;;IACA,OAAOjB,8BAAP;EACH;;AAnDiB"}
1
+ {"version":3,"names":["_archiver","_interopRequireDefault","require","_stream","path","_interopRequireWildcard","_kebabCase","_uniqid","_s3Stream","Zipper","constructor","config","_defineProperty2","default","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","stack","forEach","streamDetails","append","pipe","finalize","exports","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,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAC,uBAAA,CAAAH,OAAA;AACA,IAAAI,UAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,OAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAPA;;AA0Be,MAAMO,MAAM,CAAC;EAMxBC,WAAWA,CAACC,MAAoB,EAAE;IAAA,IAAAC,gBAAA,CAAAC,OAAA,yBALD,KAAK;IAAA,IAAAD,gBAAA,CAAAC,OAAA,wBACN,QAAQ;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAKpC,IAAI,CAACF,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACG,eAAe,GAAG,IAAAC,eAAQ,EAC1B,GAAE,IAAI,CAACJ,MAAM,CAACK,cAAe,GAAE,EAC/B,IAAG,IAAAC,kBAAS,EAAC,IAAI,CAACN,MAAM,CAACO,UAAU,CAACC,IAAI,CAAE,MAC/C,CAAC;EACL;EAEAC,iBAAiBA,CAAA,EAAwB;IACrC,MAAMF,UAAU,GAAG,IAAI,CAACP,MAAM,CAACO,UAAU;IACzC,MAAMG,MAAM,GAAG,IAAAN,eAAQ,EAAC,EAAE,EAAG,IAAG,IAAAE,kBAAS,EAACC,UAAU,CAACC,IAAI,CAAE,EAAC,CAAC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AQ,IAAGH,KAAK,CAACvC,IAAK,IAAGuC,KAAK,CAACI,KAAM,EAC9E,CAAC;IACL,CAAC,CAAC;;IAEF;IACAW,iBAAiB,CAACV,OAAO,CAAEC,aAAgC,IACvDX,OAAO,CAACY,MAAM,CAACD,aAAa,CAACxB,MAAM,EAAE;MAAEN,IAAI,EAAE8B,aAAa,CAACrB;IAAS,CAAC,CACzE,CAAC;;IAED;IACAU,OAAO,CAACa,IAAI,CAACjB,iBAAiB,CAAC;IAC/B;IACA;IACAI,OAAO,CAACc,QAAQ,CAAC,CAAC;;IAElB;IACA,OAAOjB,8BAA8B;EACzC;AACJ;AAACkB,OAAA,CAAAC,QAAA,GAAAA,QAAA"}
@@ -1,55 +1,38 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
- var _handlerGraphql = require("@webiny/handler-graphql");
13
-
14
9
  var _api = require("@webiny/api");
15
-
16
- var _checkBasePermissions = _interopRequireDefault(require("@webiny/api-page-builder/graphql/crud/utils/checkBasePermissions"));
17
-
18
10
  var _types = require("../../types");
19
-
20
11
  var _client = require("../../client");
21
-
22
12
  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";
13
+ var _utils2 = require("@webiny/utils");
14
+ var _PageBlocksPermissions = require("@webiny/api-page-builder/graphql/crud/permissions/PageBlocksPermissions");
15
+ const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
29
16
  const EXPORT_BLOCKS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER;
30
17
  const IMPORT_BLOCKS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER;
31
-
32
18
  var _default = new _api.ContextPlugin(context => {
19
+ const pageBlocksPermissions = new _PageBlocksPermissions.PageBlocksPermissions({
20
+ getPermissions: () => context.security.getPermissions("pb.block"),
21
+ getIdentity: context.security.getIdentity,
22
+ fullAccessPermissionName: "pb.*"
23
+ });
33
24
  const importExportCrud = {
34
25
  async importBlocks({
35
- category: categorySlug,
36
26
  zipFileUrl
37
27
  }) {
38
- await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
28
+ await pageBlocksPermissions.ensure({
39
29
  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
-
30
+ });
48
31
 
32
+ // Create a task for import block
49
33
  const task = await context.pageBuilder.importExportTask.createTask({
50
34
  status: _types.ImportExportTaskStatus.PENDING,
51
35
  input: {
52
- category: categorySlug,
53
36
  zipFileUrl
54
37
  }
55
38
  });
@@ -58,12 +41,10 @@ var _default = new _api.ContextPlugin(context => {
58
41
  * ImportBlocks
59
42
  * importBlocks
60
43
  */
61
-
62
44
  await (0, _client.invokeHandlerClient)({
63
45
  context,
64
46
  name: IMPORT_BLOCKS_CREATE_HANDLER,
65
47
  payload: {
66
- category: categorySlug,
67
48
  zipFileUrl,
68
49
  task,
69
50
  type: "block",
@@ -75,48 +56,44 @@ var _default = new _api.ContextPlugin(context => {
75
56
  task
76
57
  };
77
58
  },
78
-
79
59
  async exportBlocks({
80
60
  ids: initialBlockIds,
81
61
  where
82
62
  }) {
83
- await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
63
+ await pageBlocksPermissions.ensure({
84
64
  rwd: "w"
85
65
  });
86
- let blockIds = initialBlockIds || []; // If no ids are provided then it means we want to export all blocks
87
-
66
+ let blockIds = initialBlockIds || [];
67
+ // If no ids are provided then it means we want to export all blocks
88
68
  if (!initialBlockIds || Array.isArray(initialBlockIds) && initialBlockIds.length === 0) {
89
- blockIds = [];
90
69
  const blocks = await context.pageBuilder.listPageBlocks({
91
70
  where
92
- }); // Save block ids
93
-
94
- blocks.forEach(block => blockIds.push(block.id));
71
+ });
72
+ // Save block ids
73
+ blockIds = blocks.map(block => block.id);
95
74
  }
96
-
97
75
  if (blockIds.length === 0) {
98
76
  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
-
77
+ }
101
78
 
79
+ // Create the main task for blocks export.
102
80
  const task = await context.pageBuilder.importExportTask.createTask({
103
81
  status: _types.ImportExportTaskStatus.PENDING
104
82
  });
105
- const exportBlocksDataKey = `${_utils2.EXPORT_BLOCKS_FOLDER_KEY}/${task.id}`; // For each block create a sub task and invoke the process handler.
106
-
83
+ const exportBlocksDataKey = `${EXPORT_BLOCKS_FOLDER_KEY}/${task.id}`;
84
+ // For each block create a sub task and invoke the process handler.
107
85
  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), {
86
+ const blockId = blockIds[i];
87
+ // Create sub task.
88
+ await context.pageBuilder.importExportTask.createSubTask(task.id, (0, _utils2.zeroPad)(i + 1, 5), {
111
89
  status: _types.ImportExportTaskStatus.PENDING,
112
90
  input: {
113
91
  blockId,
114
92
  exportBlocksDataKey
115
93
  }
116
94
  });
117
- } // Update main task status.
118
-
119
-
95
+ }
96
+ // Update main task status.
120
97
  await context.pageBuilder.importExportTask.updateTask(task.id, {
121
98
  status: _types.ImportExportTaskStatus.PROCESSING,
122
99
  stats: (0, _utils.initialStats)(blockIds.length),
@@ -124,13 +101,13 @@ var _default = new _api.ContextPlugin(context => {
124
101
  exportBlocksDataKey
125
102
  }
126
103
  });
104
+
127
105
  /**
128
106
  * Export Blocks
129
107
  * ExportBlocks
130
108
  * exportBlocks
131
109
  */
132
110
  // Invoke handler.
133
-
134
111
  await (0, _client.invokeHandlerClient)({
135
112
  context,
136
113
  name: EXPORT_BLOCKS_PROCESS_HANDLER,
@@ -146,10 +123,8 @@ var _default = new _api.ContextPlugin(context => {
146
123
  task
147
124
  };
148
125
  }
149
-
150
- }; // Modify context
151
-
126
+ };
127
+ // Modify context
152
128
  context.pageBuilder.blocks = importExportCrud;
153
129
  });
154
-
155
130
  exports.default = _default;
@@ -1 +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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AAI,EAAE1B,6BAFmD;QAGzD2B,OAAO,EAAE;UACL+B,MAAM,EAAExC,IAAI,CAAC4B,EADR;UAELa,YAAY,EAAE,CAFT;UAGL/B,IAAI,EAAE,OAHD;UAILC,QAAQ,EAAEtB,OAAO,CAACuB,QAAR,CAAiBC,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"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_api","_types","_client","_utils","_utils2","_PageBlocksPermissions","EXPORT_BLOCKS_FOLDER_KEY","EXPORT_BLOCKS_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_BLOCKS_CREATE_HANDLER","IMPORT_CREATE_HANDLER","_default","ContextPlugin","context","pageBlocksPermissions","PageBlocksPermissions","getPermissions","security","getIdentity","fullAccessPermissionName","importExportCrud","importBlocks","zipFileUrl","ensure","rwd","task","pageBuilder","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","invokeHandlerClient","name","payload","type","identity","description","exportBlocks","ids","initialBlockIds","where","blockIds","Array","isArray","length","blocks","listPageBlocks","map","block","id","WebinyError","exportBlocksDataKey","i","blockId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex","exports","default"],"sources":["blocks.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\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 { zeroPad } from \"@webiny/utils\";\nimport { PageBlocksPermissions } from \"@webiny/api-page-builder/graphql/crud/permissions/PageBlocksPermissions\";\n\nconst EXPORT_BLOCKS_FOLDER_KEY = \"WEBINY_PB_EXPORT_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 pageBlocksPermissions = new PageBlocksPermissions({\n getPermissions: () => context.security.getPermissions(\"pb.block\"),\n getIdentity: context.security.getIdentity,\n fullAccessPermissionName: \"pb.*\"\n });\n\n const importExportCrud: BlocksImportExportCrud = {\n async importBlocks({ zipFileUrl }) {\n await pageBlocksPermissions.ensure({ rwd: \"w\" });\n\n // Create a task for import block\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING,\n input: {\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 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 pageBlocksPermissions.ensure({ 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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,sBAAA,GAAAN,OAAA;AAEA,MAAMO,wBAAwB,GAAG,wBAAwB;AACzD,MAAMC,6BAA6B,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAgC;AAClF,MAAMC,4BAA4B,GAAGH,OAAO,CAACC,GAAG,CAACG,qBAA+B;AAAC,IAAAC,QAAA,GAElE,IAAIC,kBAAa,CAAwBC,OAAO,IAAI;EAC/D,MAAMC,qBAAqB,GAAG,IAAIC,4CAAqB,CAAC;IACpDC,cAAc,EAAEA,CAAA,KAAMH,OAAO,CAACI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AE;UACL2B,MAAM,EAAErC,IAAI,CAAC0B,EAAE;UACfY,YAAY,EAAE,CAAC;UACf3B,IAAI,EAAE,OAAO;UACbC,QAAQ,EAAExB,OAAO,CAACI,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDoB,WAAW,EAAE;MACjB,CAAC,CAAC;MAEF,OAAO;QAAEb;MAAK,CAAC;IACnB;EACJ,CAAC;EACD;EACAZ,OAAO,CAACa,WAAW,CAACqB,MAAM,GAAG3B,gBAAgB;AACjD,CAAC,CAAC;AAAA4C,OAAA,CAAAC,OAAA,GAAAtD,QAAA"}
@@ -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,134 @@
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 _types = require("../../types");
11
+ var _client = require("../../client");
12
+ var _utils = require("../../import/utils");
13
+ var _utils2 = require("@webiny/utils");
14
+ var _FormsPermissions = require("@webiny/api-form-builder/plugins/crud/permissions/FormsPermissions");
15
+ const EXPORT_FORMS_FOLDER_KEY = "WEBINY_FB_EXPORT_FORM";
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
+ const formsPermissions = new _FormsPermissions.FormsPermissions({
20
+ getPermissions: () => context.security.getPermissions("fb.form"),
21
+ getIdentity: context.security.getIdentity,
22
+ fullAccessPermissionName: "pb.*"
23
+ });
24
+ context.waitFor("formBuilder", () => {
25
+ const importExportCrud = {
26
+ async importForms({
27
+ zipFileUrl
28
+ }) {
29
+ await formsPermissions.ensure({
30
+ rwd: "w"
31
+ });
32
+
33
+ // Create a task for import form
34
+ const task = await context.pageBuilder.importExportTask.createTask({
35
+ status: _types.ImportExportTaskStatus.PENDING,
36
+ input: {
37
+ zipFileUrl
38
+ }
39
+ });
40
+ /**
41
+ * Import Forms
42
+ * ImportForms
43
+ * importForms
44
+ */
45
+ await (0, _client.invokeHandlerClient)({
46
+ context,
47
+ name: IMPORT_FORMS_CREATE_HANDLER,
48
+ payload: {
49
+ zipFileUrl,
50
+ task,
51
+ type: "form",
52
+ identity: context.security.getIdentity()
53
+ },
54
+ description: "Import Forms - create"
55
+ });
56
+ return {
57
+ task
58
+ };
59
+ },
60
+ async exportForms({
61
+ ids: initialFormIds,
62
+ revisionType
63
+ }) {
64
+ await formsPermissions.ensure({
65
+ rwd: "w"
66
+ });
67
+ let formIds = initialFormIds || [];
68
+ // If no ids are provided then it means we want to export all forms
69
+ if (!initialFormIds || Array.isArray(initialFormIds) && initialFormIds.length === 0) {
70
+ formIds = [];
71
+ const forms = await context.formBuilder.listForms();
72
+
73
+ // Save form ids
74
+ forms.forEach(form => formIds.push(form.id));
75
+ }
76
+ if (formIds.length === 0) {
77
+ throw new _error.default("Cannot export forms - no forms found for provided inputs.", "EMPTY_EXPORT_NO_FORMS_FOUND");
78
+ }
79
+
80
+ // Create the main task for form export.
81
+ const task = await context.pageBuilder.importExportTask.createTask({
82
+ status: _types.ImportExportTaskStatus.PENDING
83
+ });
84
+ const exportFormsDataKey = `${EXPORT_FORMS_FOLDER_KEY}/${task.id}`;
85
+ // For each form create a sub task and invoke the process handler.
86
+ for (let i = 0; i < formIds.length; i++) {
87
+ const formId = formIds[i];
88
+ // Create sub task.
89
+ await context.pageBuilder.importExportTask.createSubTask(task.id, (0, _utils2.zeroPad)(i + 1, 5), {
90
+ status: _types.ImportExportTaskStatus.PENDING,
91
+ input: {
92
+ formId,
93
+ exportFormsDataKey,
94
+ revisionType
95
+ }
96
+ });
97
+ }
98
+ // Update main task status.
99
+ await context.pageBuilder.importExportTask.updateTask(task.id, {
100
+ status: _types.ImportExportTaskStatus.PROCESSING,
101
+ stats: (0, _utils.initialStats)(formIds.length),
102
+ input: {
103
+ exportFormsDataKey,
104
+ revisionType
105
+ }
106
+ });
107
+
108
+ /**
109
+ * Export Forms
110
+ * ExportForms
111
+ * exportForms
112
+ */
113
+ // Invoke handler.
114
+ await (0, _client.invokeHandlerClient)({
115
+ context,
116
+ name: EXPORT_FORMS_PROCESS_HANDLER,
117
+ payload: {
118
+ taskId: task.id,
119
+ subTaskIndex: 1,
120
+ type: "form",
121
+ identity: context.security.getIdentity()
122
+ },
123
+ description: "Export forms - process"
124
+ });
125
+ return {
126
+ task
127
+ };
128
+ }
129
+ };
130
+ // Modify context
131
+ context.formBuilder.forms = importExportCrud;
132
+ });
133
+ });
134
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_api","_types","_client","_utils","_utils2","_FormsPermissions","EXPORT_FORMS_FOLDER_KEY","EXPORT_FORMS_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_FORMS_CREATE_HANDLER","IMPORT_CREATE_HANDLER","_default","ContextPlugin","context","formsPermissions","FormsPermissions","getPermissions","security","getIdentity","fullAccessPermissionName","waitFor","importExportCrud","importForms","zipFileUrl","ensure","rwd","task","pageBuilder","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","invokeHandlerClient","name","payload","type","identity","description","exportForms","ids","initialFormIds","revisionType","formIds","Array","isArray","length","forms","formBuilder","listForms","forEach","form","push","id","WebinyError","exportFormsDataKey","i","formId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex","exports","default"],"sources":["forms.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\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 { zeroPad } from \"@webiny/utils\";\nimport { FormsPermissions } from \"@webiny/api-form-builder/plugins/crud/permissions/FormsPermissions\";\n\nconst EXPORT_FORMS_FOLDER_KEY = \"WEBINY_FB_EXPORT_FORM\";\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 const formsPermissions = new FormsPermissions({\n getPermissions: () => context.security.getPermissions(\"fb.form\"),\n getIdentity: context.security.getIdentity,\n fullAccessPermissionName: \"pb.*\"\n });\n\n context.waitFor(\"formBuilder\", () => {\n const importExportCrud: FormsImportExportCrud = {\n async importForms({ zipFileUrl }) {\n await formsPermissions.ensure({ rwd: \"w\" });\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 formsPermissions.ensure({ rwd: \"w\" });\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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAEA,MAAMO,uBAAuB,GAAG,uBAAuB;AACvD,MAAMC,4BAA4B,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAgC;AACjF,MAAMC,2BAA2B,GAAGH,OAAO,CAACC,GAAG,CAACG,qBAA+B;AAAC,IAAAC,QAAA,GAEjE,IA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