@webiny/api-page-builder-import-export 0.0.0-unstable.40876133bb → 0.0.0-unstable.461c047ab7

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 (275) hide show
  1. package/client.d.ts +2 -2
  2. package/client.js +12 -25
  3. package/client.js.map +1 -1
  4. package/export/combine/blocksHandler.d.ts +6 -0
  5. package/export/combine/blocksHandler.js +101 -0
  6. package/export/combine/blocksHandler.js.map +1 -0
  7. package/export/combine/formsHandler.d.ts +6 -0
  8. package/export/combine/formsHandler.js +101 -0
  9. package/export/combine/formsHandler.js.map +1 -0
  10. package/{exportPages → export}/combine/index.d.ts +4 -3
  11. package/export/combine/index.js +44 -0
  12. package/export/combine/index.js.map +1 -0
  13. package/export/combine/templatesHandler.d.ts +6 -0
  14. package/export/combine/templatesHandler.js +101 -0
  15. package/export/combine/templatesHandler.js.map +1 -0
  16. package/export/pages/ExportPagesCleanup.d.ts +5 -0
  17. package/export/pages/ExportPagesCleanup.js +82 -0
  18. package/export/pages/ExportPagesCleanup.js.map +1 -0
  19. package/export/pages/ExportPagesController.d.ts +5 -0
  20. package/export/pages/ExportPagesController.js +31 -0
  21. package/export/pages/ExportPagesController.js.map +1 -0
  22. package/export/pages/ExportPagesZipPages.d.ts +5 -0
  23. package/export/pages/ExportPagesZipPages.js +23 -0
  24. package/export/pages/ExportPagesZipPages.js.map +1 -0
  25. package/export/pages/controller/CombineZippedPages.d.ts +5 -0
  26. package/export/pages/controller/CombineZippedPages.js +75 -0
  27. package/export/pages/controller/CombineZippedPages.js.map +1 -0
  28. package/export/pages/controller/CreateZipPagesTasks.d.ts +8 -0
  29. package/export/pages/controller/CreateZipPagesTasks.js +103 -0
  30. package/export/pages/controller/CreateZipPagesTasks.js.map +1 -0
  31. package/export/pages/controller/ProcessZipPagesTasks.d.ts +6 -0
  32. package/export/pages/controller/ProcessZipPagesTasks.js +61 -0
  33. package/export/pages/controller/ProcessZipPagesTasks.js.map +1 -0
  34. package/export/pages/types.d.ts +53 -0
  35. package/export/pages/types.js +26 -0
  36. package/export/pages/types.js.map +1 -0
  37. package/export/pages/utils.d.ts +2 -0
  38. package/export/pages/utils.js +13 -0
  39. package/export/pages/utils.js.map +1 -0
  40. package/export/pages/zipPages/ZipPages.d.ts +5 -0
  41. package/export/pages/zipPages/ZipPages.js +100 -0
  42. package/export/pages/zipPages/ZipPages.js.map +1 -0
  43. package/export/pages/zipPages/ZipPagesDataManager.d.ts +14 -0
  44. package/export/pages/zipPages/ZipPagesDataManager.js +46 -0
  45. package/export/pages/zipPages/ZipPagesDataManager.js.map +1 -0
  46. package/export/pages/zipPages/getPageFactory.d.ts +4 -0
  47. package/export/pages/zipPages/getPageFactory.js +38 -0
  48. package/export/pages/zipPages/getPageFactory.js.map +1 -0
  49. package/export/process/blocksHandler.d.ts +6 -0
  50. package/export/process/blocksHandler.js +169 -0
  51. package/export/process/blocksHandler.js.map +1 -0
  52. package/export/process/exporters/BlockExporter.d.ts +12 -0
  53. package/export/process/exporters/BlockExporter.js +57 -0
  54. package/export/process/exporters/BlockExporter.js.map +1 -0
  55. package/export/process/exporters/FormExporter.d.ts +9 -0
  56. package/export/process/exporters/FormExporter.js +36 -0
  57. package/export/process/exporters/FormExporter.js.map +1 -0
  58. package/export/process/exporters/PageExporter.d.ts +18 -0
  59. package/export/process/exporters/PageExporter.js +59 -0
  60. package/export/process/exporters/PageExporter.js.map +1 -0
  61. package/export/process/exporters/PageTemplateExporter.d.ts +11 -0
  62. package/export/process/exporters/PageTemplateExporter.js +58 -0
  63. package/export/process/exporters/PageTemplateExporter.js.map +1 -0
  64. package/export/process/formsHandler.d.ts +6 -0
  65. package/export/process/formsHandler.js +189 -0
  66. package/export/process/formsHandler.js.map +1 -0
  67. package/{exportPages → export}/process/index.d.ts +5 -7
  68. package/export/process/index.js +41 -0
  69. package/export/process/index.js.map +1 -0
  70. package/export/process/templatesHandler.d.ts +6 -0
  71. package/export/process/templatesHandler.js +168 -0
  72. package/export/process/templatesHandler.js.map +1 -0
  73. package/export/s3Stream.d.ts +36 -0
  74. package/{exportPages → export}/s3Stream.js +27 -42
  75. package/export/s3Stream.js.map +1 -0
  76. package/export/utils.d.ts +24 -0
  77. package/export/utils.js +169 -0
  78. package/export/utils.js.map +1 -0
  79. package/{exportPages → export}/zipper.d.ts +12 -10
  80. package/export/zipper.js +120 -0
  81. package/export/zipper.js.map +1 -0
  82. package/graphql/crud/blocks.crud.d.ts +4 -0
  83. package/graphql/crud/blocks.crud.js +158 -0
  84. package/graphql/crud/blocks.crud.js.map +1 -0
  85. package/graphql/crud/forms.crud.d.ts +4 -0
  86. package/graphql/crud/forms.crud.js +162 -0
  87. package/graphql/crud/forms.crud.js.map +1 -0
  88. package/graphql/crud/importExportTasks.crud.d.ts +5 -0
  89. package/graphql/crud/importExportTasks.crud.js +396 -0
  90. package/graphql/crud/importExportTasks.crud.js.map +1 -0
  91. package/graphql/crud/pages.crud.d.ts +2 -2
  92. package/graphql/crud/pages.crud.js +241 -138
  93. package/graphql/crud/pages.crud.js.map +1 -1
  94. package/graphql/crud/templates.crud.d.ts +4 -0
  95. package/graphql/crud/templates.crud.js +156 -0
  96. package/graphql/crud/templates.crud.js.map +1 -0
  97. package/graphql/crud.d.ts +2 -2
  98. package/graphql/crud.js +7 -7
  99. package/graphql/crud.js.map +1 -1
  100. package/graphql/graphql/blocks.gql.d.ts +4 -0
  101. package/graphql/graphql/blocks.gql.js +52 -0
  102. package/graphql/graphql/blocks.gql.js.map +1 -0
  103. package/graphql/graphql/forms.gql.d.ts +4 -0
  104. package/graphql/graphql/forms.gql.js +60 -0
  105. package/graphql/graphql/forms.gql.js.map +1 -0
  106. package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
  107. package/graphql/graphql/importExportTasks.gql.js +75 -0
  108. package/graphql/graphql/importExportTasks.gql.js.map +1 -0
  109. package/graphql/graphql/pages.gql.d.ts +3 -3
  110. package/graphql/graphql/pages.gql.js +104 -26
  111. package/graphql/graphql/pages.gql.js.map +1 -1
  112. package/graphql/graphql/templates.gql.d.ts +4 -0
  113. package/graphql/graphql/templates.gql.js +52 -0
  114. package/graphql/graphql/templates.gql.js.map +1 -0
  115. package/graphql/graphql/utils/resolve.d.ts +3 -3
  116. package/graphql/graphql/utils/resolve.js +15 -7
  117. package/graphql/graphql/utils/resolve.js.map +1 -1
  118. package/graphql/graphql.d.ts +1 -1
  119. package/graphql/graphql.js +6 -6
  120. package/graphql/graphql.js.map +1 -1
  121. package/graphql/index.d.ts +2 -2
  122. package/graphql/index.js +4 -6
  123. package/graphql/index.js.map +1 -1
  124. package/graphql/types.d.ts +237 -37
  125. package/graphql/types.js +3 -1
  126. package/graphql/types.js.map +1 -1
  127. package/import/constants.d.ts +3 -0
  128. package/import/constants.js +13 -0
  129. package/import/constants.js.map +1 -0
  130. package/import/create/blocksHandler.d.ts +3 -0
  131. package/import/create/blocksHandler.js +101 -0
  132. package/import/create/blocksHandler.js.map +1 -0
  133. package/import/create/formsHandler.d.ts +3 -0
  134. package/import/create/formsHandler.js +105 -0
  135. package/import/create/formsHandler.js.map +1 -0
  136. package/import/create/index.d.ts +24 -0
  137. package/import/create/index.js +44 -0
  138. package/import/create/index.js.map +1 -0
  139. package/import/create/pagesHandler.d.ts +3 -0
  140. package/import/create/pagesHandler.js +105 -0
  141. package/import/create/pagesHandler.js.map +1 -0
  142. package/import/create/templatesHandler.d.ts +3 -0
  143. package/import/create/templatesHandler.js +101 -0
  144. package/import/create/templatesHandler.js.map +1 -0
  145. package/import/pages/ImportPagesController.d.ts +5 -0
  146. package/import/pages/ImportPagesController.js +29 -0
  147. package/import/pages/ImportPagesController.js.map +1 -0
  148. package/import/pages/ImportPagesProcessPages.d.ts +6 -0
  149. package/import/pages/ImportPagesProcessPages.js +112 -0
  150. package/import/pages/ImportPagesProcessPages.js.map +1 -0
  151. package/import/pages/controller/ImportPagesProcessPagesChecker.d.ts +6 -0
  152. package/import/pages/controller/ImportPagesProcessPagesChecker.js +40 -0
  153. package/import/pages/controller/ImportPagesProcessPagesChecker.js.map +1 -0
  154. package/import/pages/controller/ImportPagesProcessZipFile.d.ts +5 -0
  155. package/import/pages/controller/ImportPagesProcessZipFile.js +71 -0
  156. package/import/pages/controller/ImportPagesProcessZipFile.js.map +1 -0
  157. package/import/pages/process/importPage.d.ts +10 -0
  158. package/import/pages/process/importPage.js +94 -0
  159. package/import/pages/process/importPage.js.map +1 -0
  160. package/import/pages/types.d.ts +48 -0
  161. package/import/pages/types.js +20 -0
  162. package/import/pages/types.js.map +1 -0
  163. package/import/process/blocks/ElementIdsProcessor.d.ts +5 -0
  164. package/import/process/blocks/ElementIdsProcessor.js +26 -0
  165. package/import/process/blocks/ElementIdsProcessor.js.map +1 -0
  166. package/import/process/blocks/blocksHandler.d.ts +3 -0
  167. package/import/process/blocks/blocksHandler.js +169 -0
  168. package/import/process/blocks/blocksHandler.js.map +1 -0
  169. package/import/process/blocks/importBlock.d.ts +11 -0
  170. package/import/process/blocks/importBlock.js +101 -0
  171. package/import/process/blocks/importBlock.js.map +1 -0
  172. package/import/process/forms/formsHandler.d.ts +3 -0
  173. package/import/process/forms/formsHandler.js +178 -0
  174. package/import/process/forms/formsHandler.js.map +1 -0
  175. package/import/process/forms/importForm.d.ts +9 -0
  176. package/import/process/forms/importForm.js +47 -0
  177. package/import/process/forms/importForm.js.map +1 -0
  178. package/{importPages → import}/process/index.d.ts +6 -4
  179. package/import/process/index.js +41 -0
  180. package/import/process/index.js.map +1 -0
  181. package/import/process/templates/importTemplate.d.ts +11 -0
  182. package/import/process/templates/importTemplate.js +70 -0
  183. package/import/process/templates/importTemplate.js.map +1 -0
  184. package/import/process/templates/templatesHandler.d.ts +3 -0
  185. package/import/process/templates/templatesHandler.js +174 -0
  186. package/import/process/templates/templatesHandler.js.map +1 -0
  187. package/import/utils/deleteS3Folder.d.ts +1 -0
  188. package/import/utils/deleteS3Folder.js +21 -0
  189. package/import/utils/deleteS3Folder.js.map +1 -0
  190. package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
  191. package/import/utils/extractAndUploadZipFileContents.js +126 -0
  192. package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
  193. package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
  194. package/import/utils/extractZipAndUploadToS3.js +100 -0
  195. package/import/utils/extractZipAndUploadToS3.js.map +1 -0
  196. package/import/utils/getFileNameWithoutExt.d.ts +1 -0
  197. package/import/utils/getFileNameWithoutExt.js +13 -0
  198. package/import/utils/getFileNameWithoutExt.js.map +1 -0
  199. package/import/utils/index.d.ts +9 -0
  200. package/import/utils/index.js +106 -0
  201. package/import/utils/index.js.map +1 -0
  202. package/import/utils/initialStats.d.ts +7 -0
  203. package/import/utils/initialStats.js +18 -0
  204. package/import/utils/initialStats.js.map +1 -0
  205. package/import/utils/prepareDataDirMap.d.ts +6 -0
  206. package/import/utils/prepareDataDirMap.js +31 -0
  207. package/import/utils/prepareDataDirMap.js.map +1 -0
  208. package/import/utils/updateFilesInData.d.ts +8 -0
  209. package/import/utils/updateFilesInData.js +51 -0
  210. package/import/utils/updateFilesInData.js.map +1 -0
  211. package/import/utils/uploadAssets.d.ts +10 -0
  212. package/import/utils/uploadAssets.js +92 -0
  213. package/import/utils/uploadAssets.js.map +1 -0
  214. package/import/utils/uploadFilesFromS3.d.ts +3 -0
  215. package/import/utils/uploadFilesFromS3.js +21 -0
  216. package/import/utils/uploadFilesFromS3.js.map +1 -0
  217. package/mockSecurity.d.ts +1 -1
  218. package/mockSecurity.js +2 -3
  219. package/mockSecurity.js.map +1 -1
  220. package/package.json +36 -52
  221. package/tasks/common/ChildTasksCleanup.d.ts +12 -0
  222. package/tasks/common/ChildTasksCleanup.js +64 -0
  223. package/tasks/common/ChildTasksCleanup.js.map +1 -0
  224. package/tasks/index.d.ts +1 -0
  225. package/tasks/index.js +13 -0
  226. package/tasks/index.js.map +1 -0
  227. package/tasks/pages/exportPagesCleanupTask.d.ts +3 -0
  228. package/tasks/pages/exportPagesCleanupTask.js +36 -0
  229. package/tasks/pages/exportPagesCleanupTask.js.map +1 -0
  230. package/tasks/pages/exportPagesControllerTask.d.ts +3 -0
  231. package/tasks/pages/exportPagesControllerTask.js +83 -0
  232. package/tasks/pages/exportPagesControllerTask.js.map +1 -0
  233. package/tasks/pages/exportPagesZipPagesTask.d.ts +3 -0
  234. package/tasks/pages/exportPagesZipPagesTask.js +39 -0
  235. package/tasks/pages/exportPagesZipPagesTask.js.map +1 -0
  236. package/tasks/pages/importPagesControllerTask.d.ts +3 -0
  237. package/tasks/pages/importPagesControllerTask.js +39 -0
  238. package/tasks/pages/importPagesControllerTask.js.map +1 -0
  239. package/tasks/pages/importPagesProcessPageTask.d.ts +3 -0
  240. package/tasks/pages/importPagesProcessPageTask.js +39 -0
  241. package/tasks/pages/importPagesProcessPageTask.js.map +1 -0
  242. package/tasks/pages/index.d.ts +1 -0
  243. package/tasks/pages/index.js +17 -0
  244. package/tasks/pages/index.js.map +1 -0
  245. package/types.d.ts +83 -65
  246. package/types.js +68 -21
  247. package/types.js.map +1 -1
  248. package/utils/ZipFiles.d.ts +11 -0
  249. package/utils/ZipFiles.js +124 -0
  250. package/utils/ZipFiles.js.map +1 -0
  251. package/exportPages/combine/index.js +0 -114
  252. package/exportPages/combine/index.js.map +0 -1
  253. package/exportPages/process/index.js +0 -208
  254. package/exportPages/process/index.js.map +0 -1
  255. package/exportPages/s3Stream.d.ts +0 -31
  256. package/exportPages/s3Stream.js.map +0 -1
  257. package/exportPages/utils.d.ts +0 -13
  258. package/exportPages/utils.js +0 -113
  259. package/exportPages/utils.js.map +0 -1
  260. package/exportPages/zipper.js +0 -135
  261. package/exportPages/zipper.js.map +0 -1
  262. package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
  263. package/graphql/crud/pageImportExportTasks.crud.js +0 -411
  264. package/graphql/crud/pageImportExportTasks.crud.js.map +0 -1
  265. package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
  266. package/graphql/graphql/pageImportExportTasks.gql.js +0 -80
  267. package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
  268. package/importPages/create/index.d.ts +0 -22
  269. package/importPages/create/index.js +0 -118
  270. package/importPages/create/index.js.map +0 -1
  271. package/importPages/process/index.js +0 -185
  272. package/importPages/process/index.js.map +0 -1
  273. package/importPages/utils.d.ts +0 -50
  274. package/importPages/utils.js +0 -570
  275. package/importPages/utils.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_stream","require","_clientS","_libStorage","ARCHIVE_CONTENT_TYPE","S3Stream","constructor","s3","S3","region","process","env","AWS_REGION","bucket","S3_BUCKET","getPresignedUrl","key","getSignedUrl","GetObjectCommand","Bucket","Key","expiresIn","isFileAccessible","getObjectHead","error","console","warn","log","headObject","readStream","response","send","Body","writeStream","contentType","streamPassThrough","Stream","PassThrough","params","ACL","ContentType","upload","Upload","client","streamPassThroughUploadPromise","done","PutObjectCommand","listObject","prefix","listObjects","Prefix","deleteObject","s3Stream","exports"],"sources":["s3Stream.ts"],"sourcesContent":["import type { Readable } from \"stream\";\nimport { Stream } from \"stream\";\nimport type {\n ListObjectsOutput,\n DeleteObjectOutput,\n HeadObjectOutput,\n PutObjectCommandInput\n} from \"@webiny/aws-sdk/client-s3\";\nimport { S3, getSignedUrl, GetObjectCommand, PutObjectCommand } from \"@webiny/aws-sdk/client-s3\";\nimport { Upload } from \"@webiny/aws-sdk/lib-storage\";\n\nexport type { ListObjectsOutput };\n\nconst ARCHIVE_CONTENT_TYPE = \"application/zip\";\n\nclass S3Stream {\n s3: S3;\n bucket: string;\n\n constructor() {\n this.s3 = new S3({\n region: process.env.AWS_REGION as string\n });\n this.bucket = process.env.S3_BUCKET as string;\n }\n\n getPresignedUrl(key?: string) {\n return getSignedUrl(\n this.s3,\n new GetObjectCommand({\n Bucket: this.bucket,\n Key: key\n }),\n {\n expiresIn: 604800 // 1 week\n }\n );\n }\n\n /**\n * We're checking if the file is accessible on S3 by getting object meta data.\n * It help us to filter files that we need to download as part of export data.\n * @param Key {string}\n */\n async isFileAccessible(Key: string): Promise<boolean> {\n try {\n await this.getObjectHead(Key);\n return true;\n } catch (error) {\n console.warn(`Error while fetching meta data for file \"${Key}\"`);\n console.log(error);\n return false;\n }\n }\n\n getObjectHead(Key: string): Promise<HeadObjectOutput> {\n return this.s3.headObject({ Bucket: this.bucket, Key });\n }\n\n async readStream(Key: string): Promise<Readable> {\n const response = await this.s3.send(new GetObjectCommand({ Bucket: this.bucket, Key }));\n return response.Body as Readable;\n }\n\n writeStream(Key: string, contentType: string = ARCHIVE_CONTENT_TYPE) {\n const streamPassThrough = new Stream.PassThrough();\n\n const params: PutObjectCommandInput = {\n ACL: \"private\",\n Body: streamPassThrough,\n Bucket: this.bucket,\n ContentType: contentType,\n Key\n };\n\n const upload = new Upload({\n client: this.s3,\n params\n });\n\n return {\n streamPassThrough: streamPassThrough,\n /**\n * We're not using the `FileManager` storage plugin here because it currently doesn't support streams.\n */\n streamPassThroughUploadPromise: upload.done()\n };\n }\n\n async upload(params: { Key: string; ContentType: string; Body: Buffer }): Promise<void> {\n await this.s3.send(\n new PutObjectCommand({\n ACL: \"private\",\n Bucket: this.bucket,\n ...params\n })\n );\n }\n\n listObject(prefix: string): Promise<ListObjectsOutput> {\n return this.s3.listObjects({\n Bucket: this.bucket,\n Prefix: prefix\n });\n }\n\n deleteObject(key: string): Promise<DeleteObjectOutput> {\n return this.s3.deleteObject({ Key: key, Bucket: this.bucket });\n }\n}\n\nexport const s3Stream = new S3Stream();\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAOA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAIA,MAAMG,oBAAoB,GAAG,iBAAiB;AAE9C,MAAMC,QAAQ,CAAC;EAIXC,WAAWA,CAAA,EAAG;IACV,IAAI,CAACC,EAAE,GAAG,IAAIC,WAAE,CAAC;MACbC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAACC;IACxB,CAAC,C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ACvBhB,MAAM,EAAE,IAAI,CAACN,MAAM;MACnB2B,WAAW,EAAEN,WAAW;MACxBd;IACJ,CAAC;IAED,MAAMqB,MAAM,GAAG,IAAIC,kBAAM,CAAC;MACtBC,MAAM,EAAE,IAAI,CAACpC,EAAE;MACf+B;IACJ,CAAC,CAAC;IAEF,OAAO;MACHH,iBAAiB,EAAEA,iBAAiB;MACpC;AACZ;AACA;MACYS,8BAA8B,EAAEH,MAAM,CAACI,IAAI,CAAC;IAChD,CAAC;EACL;EAEA,MAAMJ,MAAMA,CAACH,MAA0D,EAAiB;IACpF,MAAM,IAAI,CAAC/B,EAAE,CAACwB,IAAI,CACd,IAAIe,yBAAgB,CAAC;MACjBP,GAAG,EAAE,SAAS;MACdpB,MAAM,EAAE,IAAI,CAACN,MAAM;MACnB,GAAGyB;IACP,CAAC,CACL,CAAC;EACL;EAEAS,UAAUA,CAACC,MAAc,EAA8B;IACnD,OAAO,IAAI,CAACzC,EAAE,CAAC0C,WAAW,CAAC;MACvB9B,MAAM,EAAE,IAAI,CAACN,MAAM;MACnBqC,MAAM,EAAEF;IACZ,CAAC,CAAC;EACN;EAEAG,YAAYA,CAACnC,GAAW,EAA+B;IACnD,OAAO,IAAI,CAACT,EAAE,CAAC4C,YAAY,CAAC;MAAE/B,GAAG,EAAEJ,GAAG;MAAEG,MAAM,EAAE,IAAI,CAACN;IAAO,CAAC,CAAC;EAClE;AACJ;AAEO,MAAMuC,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAG,IAAI/C,QAAQ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,24 @@
1
+ import type { CompleteMultipartUploadOutput } from "@webiny/aws-sdk/client-s3";
2
+ import type { BlockCategory, Page, PageBlock, PageTemplate } from "@webiny/api-page-builder/types";
3
+ import type { FileManagerContext, File } from "@webiny/api-file-manager/types";
4
+ export declare const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
5
+ export declare const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
6
+ export declare const EXPORT_TEMPLATES_FOLDER_KEY = "WEBINY_PB_EXPORT_TEMPLATE";
7
+ export declare const EXPORT_FORMS_FOLDER_KEY = "WEBINY_FB_EXPORT_FORM";
8
+ export interface ExportedPageData {
9
+ page: Pick<Page, "content" | "title" | "version" | "status" | "settings" | "path">;
10
+ files: File[];
11
+ }
12
+ export declare function exportPage(page: Page, exportPagesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<CompleteMultipartUploadOutput>;
13
+ export interface ExportedBlockData {
14
+ block: Pick<PageBlock, "name" | "content">;
15
+ category: BlockCategory;
16
+ files: File[];
17
+ }
18
+ export declare function exportBlock(block: PageBlock, blockCategory: BlockCategory, exportBlocksDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<CompleteMultipartUploadOutput>;
19
+ export interface ExportedTemplateData {
20
+ template: Pick<PageTemplate, "title" | "slug" | "tags" | "description" | "content" | "layout" | "pageCategory" | "dataSources" | "dataBindings">;
21
+ files: File[];
22
+ }
23
+ export declare function exportTemplate(template: PageTemplate, exportTemplatesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<CompleteMultipartUploadOutput>;
24
+ export declare function extractFilesFromData(data: Record<string, any>, files?: File[]): File[];
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.EXPORT_TEMPLATES_FOLDER_KEY = exports.EXPORT_PAGES_FOLDER_KEY = exports.EXPORT_FORMS_FOLDER_KEY = exports.EXPORT_BLOCKS_FOLDER_KEY = void 0;
8
+ exports.exportBlock = exportBlock;
9
+ exports.exportPage = exportPage;
10
+ exports.exportTemplate = exportTemplate;
11
+ exports.extractFilesFromData = extractFilesFromData;
12
+ var _get = _interopRequireDefault(require("lodash/get"));
13
+ var _zipper = _interopRequireDefault(require("./zipper"));
14
+ const EXPORT_PAGES_FOLDER_KEY = exports.EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
15
+ const EXPORT_BLOCKS_FOLDER_KEY = exports.EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
16
+ const EXPORT_TEMPLATES_FOLDER_KEY = exports.EXPORT_TEMPLATES_FOLDER_KEY = "WEBINY_PB_EXPORT_TEMPLATE";
17
+ const EXPORT_FORMS_FOLDER_KEY = exports.EXPORT_FORMS_FOLDER_KEY = "WEBINY_FB_EXPORT_FORM";
18
+ async function exportPage(page, exportPagesDataKey, fileManager) {
19
+ // Extract all files
20
+ const files = extractFilesFromData(page.content || {});
21
+ // Extract images from page settings
22
+ const pageSettingsImages = [(0, _get.default)(page, "settings.general.image"), (0, _get.default)(page, "settings.social.image")].filter(image => image && image.src);
23
+ const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);
24
+ // Get file data for all images
25
+ const imageFilesData = [];
26
+ if (fileIds.length > 0) {
27
+ const [filesData] = await fileManager.listFiles({
28
+ where: {
29
+ id_in: fileIds
30
+ }
31
+ });
32
+ imageFilesData.push(...filesData);
33
+ }
34
+
35
+ // Extract the page data in a json file and upload it to S3
36
+ const pageData = {
37
+ page: {
38
+ content: page.content,
39
+ title: page.title,
40
+ path: page.path,
41
+ version: page.version,
42
+ status: page.status,
43
+ settings: page.settings
44
+ },
45
+ files: imageFilesData
46
+ };
47
+ const pageDataBuffer = Buffer.from(JSON.stringify(pageData));
48
+ const zipper = new _zipper.default({
49
+ exportInfo: {
50
+ files: imageFilesData,
51
+ name: page.title,
52
+ dataBuffer: pageDataBuffer
53
+ },
54
+ archiveFileKey: exportPagesDataKey
55
+ });
56
+ return zipper.process();
57
+ }
58
+ async function exportBlock(block, blockCategory, exportBlocksDataKey, fileManager) {
59
+ // Extract all files
60
+ const files = extractFilesFromData(block.content || {});
61
+ const fileIds = files.map(imageFile => imageFile.id);
62
+ // Get file data for all images
63
+ const imageFilesData = [];
64
+ if (fileIds.length > 0) {
65
+ const [filesData] = await fileManager.listFiles({
66
+ where: {
67
+ id_in: fileIds
68
+ }
69
+ });
70
+ imageFilesData.push(...filesData);
71
+ }
72
+
73
+ // Extract the block data in a json file and upload it to S3
74
+ const blockData = {
75
+ block: {
76
+ name: block.name,
77
+ content: block.content
78
+ },
79
+ category: {
80
+ name: blockCategory.name,
81
+ slug: blockCategory.slug,
82
+ icon: blockCategory.icon,
83
+ description: blockCategory.description
84
+ },
85
+ files: imageFilesData
86
+ };
87
+ const blockDataBuffer = Buffer.from(JSON.stringify(blockData));
88
+ const zipper = new _zipper.default({
89
+ exportInfo: {
90
+ files: imageFilesData,
91
+ name: block.name,
92
+ dataBuffer: blockDataBuffer
93
+ },
94
+ archiveFileKey: exportBlocksDataKey
95
+ });
96
+ return zipper.process();
97
+ }
98
+ async function exportTemplate(template, exportTemplatesDataKey, fileManager) {
99
+ // Extract all files
100
+ const files = extractFilesFromData(template.content || {});
101
+ const fileIds = files.map(imageFile => imageFile.id);
102
+ // Get file data for all images
103
+ const imageFilesData = [];
104
+ if (fileIds.length > 0) {
105
+ const [filesData] = await fileManager.listFiles({
106
+ where: {
107
+ id_in: fileIds
108
+ }
109
+ });
110
+ imageFilesData.push(...filesData);
111
+ }
112
+
113
+ // Extract the template data in a json file and upload it to S3
114
+ const templateData = {
115
+ template: {
116
+ title: template.title,
117
+ slug: template.slug,
118
+ tags: template.tags,
119
+ description: template.description,
120
+ content: template.content,
121
+ layout: template.layout,
122
+ pageCategory: template.pageCategory,
123
+ dataSources: template.dataSources,
124
+ dataBindings: template.dataBindings
125
+ },
126
+ files: imageFilesData
127
+ };
128
+ const templateDataBuffer = Buffer.from(JSON.stringify(templateData));
129
+ const zipper = new _zipper.default({
130
+ exportInfo: {
131
+ files: imageFilesData,
132
+ name: template.title,
133
+ dataBuffer: templateDataBuffer
134
+ },
135
+ archiveFileKey: exportTemplatesDataKey
136
+ });
137
+ return zipper.process();
138
+ }
139
+ function extractFilesFromData(data, files = []) {
140
+ if (!data || typeof data !== "object") {
141
+ return files;
142
+ }
143
+
144
+ // Recursively call function for each element
145
+ if (Array.isArray(data)) {
146
+ for (let i = 0; i < data.length; i++) {
147
+ const element = data[i];
148
+ extractFilesFromData(element, files);
149
+ }
150
+ return files;
151
+ }
152
+
153
+ // Main
154
+ const tuple = Object.entries(data);
155
+ for (let i = 0; i < tuple.length; i++) {
156
+ const [key, value] = tuple[i];
157
+ if (key === "file" && value) {
158
+ files.push(value);
159
+ } else if (key === "images" && Array.isArray(value)) {
160
+ // Handle case for "images-list" component
161
+ files.push(...value);
162
+ } else {
163
+ extractFilesFromData(value, files);
164
+ }
165
+ }
166
+ return files;
167
+ }
168
+
169
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_get","_interopRequireDefault","require","_zipper","EXPORT_PAGES_FOLDER_KEY","exports","EXPORT_BLOCKS_FOLDER_KEY","EXPORT_TEMPLATES_FOLDER_KEY","EXPORT_FORMS_FOLDER_KEY","exportPage","page","exportPagesDataKey","fileManager","files","extractFilesFromData","content","pageSettingsImages","get","filter","image","src","fileIds","map","imageFile","id","imageFilesData","length","filesData","listFiles","where","id_in","push","pageData","title","path","version","status","settings","pageDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","name","dataBuffer","archiveFileKey","process","exportBlock","block","blockCategory","exportBlocksDataKey","blockData","category","slug","icon","description","blockDataBuffer","exportTemplate","template","exportTemplatesDataKey","templateData","tags","layout","pageCategory","dataSources","dataBindings","templateDataBuffer","data","Array","isArray","i","element","tuple","Object","entries","key","value"],"sources":["utils.ts"],"sourcesContent":["import type { CompleteMultipartUploadOutput } from \"@webiny/aws-sdk/client-s3\";\nimport type {\n BlockCategory,\n Page,\n PageBlock,\n PageTemplate,\n PageTemplateInput\n} from \"@webiny/api-page-builder/types\";\nimport type { FileManagerContext, File } from \"@webiny/api-file-manager/types\";\nimport get from \"lodash/get\";\nimport Zipper from \"./zipper\";\n\nexport const EXPORT_PAGES_FOLDER_KEY = \"WEBINY_PB_EXPORT_PAGES\";\nexport const EXPORT_BLOCKS_FOLDER_KEY = \"WEBINY_PB_EXPORT_BLOCK\";\nexport const EXPORT_TEMPLATES_FOLDER_KEY = \"WEBINY_PB_EXPORT_TEMPLATE\";\nexport const EXPORT_FORMS_FOLDER_KEY = \"WEBINY_FB_EXPORT_FORM\";\n\nexport interface ExportedPageData {\n page: Pick<Page, \"content\" | \"title\" | \"version\" | \"status\" | \"settings\" | \"path\">;\n files: File[];\n}\n\nexport async function exportPage(\n page: Page,\n exportPagesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<CompleteMultipartUploadOutput> {\n // Extract all files\n const files = extractFilesFromData(page.content || {});\n // Extract images from page settings\n const pageSettingsImages = [\n get(page, \"settings.general.image\") as unknown as File,\n get(page, \"settings.social.image\") as unknown as File\n ].filter(image => image && image.src);\n\n const fileIds = [...files, ...pageSettingsImages].map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.listFiles({ where: { id_in: fileIds } });\n imageFilesData.push(...filesData);\n }\n\n // Extract the page data in a json file and upload it to S3\n const pageData = {\n page: {\n content: page.content,\n title: page.title,\n path: page.path,\n version: page.version,\n status: page.status,\n settings: page.settings\n },\n files: imageFilesData\n };\n const pageDataBuffer = Buffer.from(JSON.stringify(pageData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: page.title,\n dataBuffer: pageDataBuffer\n },\n archiveFileKey: exportPagesDataKey\n });\n\n return zipper.process();\n}\n\nexport interface ExportedBlockData {\n block: Pick<PageBlock, \"name\" | \"content\">;\n category: BlockCategory;\n files: File[];\n}\n\nexport async function exportBlock(\n block: PageBlock,\n blockCategory: BlockCategory,\n exportBlocksDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<CompleteMultipartUploadOutput> {\n // Extract all files\n const files = extractFilesFromData(block.content || {});\n const fileIds = files.map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.listFiles({ where: { id_in: fileIds } });\n imageFilesData.push(...filesData);\n }\n\n // Extract the block data in a json file and upload it to S3\n const blockData = {\n block: {\n name: block.name,\n content: block.content\n },\n category: {\n name: blockCategory.name,\n slug: blockCategory.slug,\n icon: blockCategory.icon,\n description: blockCategory.description\n },\n files: imageFilesData\n };\n const blockDataBuffer = Buffer.from(JSON.stringify(blockData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: block.name,\n dataBuffer: blockDataBuffer\n },\n archiveFileKey: exportBlocksDataKey\n });\n\n return zipper.process();\n}\n\nexport interface ExportedTemplateData {\n template: Pick<\n PageTemplate,\n | \"title\"\n | \"slug\"\n | \"tags\"\n | \"description\"\n | \"content\"\n | \"layout\"\n | \"pageCategory\"\n | \"dataSources\"\n | \"dataBindings\"\n >;\n files: File[];\n}\n\nexport async function exportTemplate(\n template: PageTemplate,\n exportTemplatesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<CompleteMultipartUploadOutput> {\n // Extract all files\n const files = extractFilesFromData(template.content || {});\n const fileIds = files.map(imageFile => imageFile.id);\n // Get file data for all images\n const imageFilesData = [];\n if (fileIds.length > 0) {\n const [filesData] = await fileManager.listFiles({ where: { id_in: fileIds } });\n imageFilesData.push(...filesData);\n }\n\n // Extract the template data in a json file and upload it to S3\n const templateData: { template: PageTemplateInput; files: File[] } = {\n template: {\n title: template.title,\n slug: template.slug,\n tags: template.tags,\n description: template.description,\n content: template.content,\n layout: template.layout,\n pageCategory: template.pageCategory,\n dataSources: template.dataSources,\n dataBindings: template.dataBindings\n },\n files: imageFilesData\n };\n const templateDataBuffer = Buffer.from(JSON.stringify(templateData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: imageFilesData,\n name: template.title,\n dataBuffer: templateDataBuffer\n },\n archiveFileKey: exportTemplatesDataKey\n });\n\n return zipper.process();\n}\n\nexport function extractFilesFromData(data: Record<string, any>, files: File[] = []) {\n if (!data || typeof data !== \"object\") {\n return files;\n }\n\n // Recursively call function for each element\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const element = data[i];\n extractFilesFromData(element, files);\n }\n return files;\n }\n\n // Main\n const tuple = Object.entries(data);\n for (let i = 0; i < tuple.length; i++) {\n const [key, value] = tuple[i];\n if (key === \"file\" && value) {\n files.push(value);\n } else if (key === \"images\" && Array.isArray(value)) {\n // Handle case for \"images-list\" component\n files.push(...value);\n } else {\n extractFilesFromData(value, files);\n }\n }\n return files;\n}\n"],"mappings":";;;;;;;;;;;AASA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEO,MAAME,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG,wBAAwB;AACxD,MAAME,wBAAwB,GAAAD,OAAA,CAAAC,wBAAA,GAAG,wBAAwB;AACzD,MAAMC,2BAA2B,GAAAF,OAAA,CAAAE,2BAAA,GAAG,2BAA2B;AAC/D,MAAMC,uBAAuB,GAAAH,OAAA,CAAAG,uBAAA,GAAG,uBAAuB;AAOvD,eAAeC,UAAUA,CAC5BC,IAAU,EACVC,kBAA0B,EAC1BC,WAA8C,EACR;EACtC;EACA,MAAMC,KAAK,GAAGC,oBAAoB,CAACJ,IAAI,CAACK,OAAO,IAAI,CAAC,CAAC,CAAC;EACtD;EACA,MAAMC,kBAAkB,GAAG,CACvB,IAAAC,YAAG,EAACP,IAAI,EAAE,wBAAwB,CAAC,EACnC,IAAAO,YAAG,EAACP,IAAI,EAAE,uBAAuB,CAAC,CACrC,CAACQ,MAAM,CAACC,KAAK,IAAIA,KAAK,IAAIA,KAAK,CAACC,GAAG,CAAC;EAErC,MAAMC,OAAO,GAAG,CAAC,GAAGR,KAAK,EAAE,GAAGG,kBAAkB,CAAC,CAACM,GAAG,CAACC,SA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AAI,KAAK,QAAQ,EAAE;IACnC,OAAOzD,KAAK;EAChB;;EAEA;EACA,IAAI0D,KAAK,CAACC,OAAO,CAACF,IAAI,CAAC,EAAE;IACrB,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAAC5C,MAAM,EAAE+C,CAAC,EAAE,EAAE;MAClC,MAAMC,OAAO,GAAGJ,IAAI,CAACG,CAAC,CAAC;MACvB3D,oBAAoB,CAAC4D,OAAO,EAAE7D,KAAK,CAAC;IACxC;IACA,OAAOA,KAAK;EAChB;;EAEA;EACA,MAAM8D,KAAK,GAAGC,MAAM,CAACC,OAAO,CAACP,IAAI,CAAC;EAClC,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGE,KAAK,CAACjD,MAAM,EAAE+C,CAAC,EAAE,EAAE;IACnC,MAAM,CAACK,GAAG,EAAEC,KAAK,CAAC,GAAGJ,KAAK,CAACF,CAAC,CAAC;IAC7B,IAAIK,GAAG,KAAK,MAAM,IAAIC,KAAK,EAAE;MACzBlE,KAAK,CAACkB,IAAI,CAACgD,KAAK,CAAC;IACrB,CAAC,MAAM,IAAID,GAAG,KAAK,QAAQ,IAAIP,KAAK,CAACC,OAAO,CAACO,KAAK,CAAC,EAAE;MACjD;MACAlE,KAAK,CAACkB,IAAI,CAAC,GAAGgD,KAAK,CAAC;IACxB,CAAC,MAAM;MACHjE,oBAAoB,CAACiE,KAAK,EAAElE,KAAK,CAAC;IACtC;EACJ;EACA,OAAOA,KAAK;AAChB","ignoreList":[]}
@@ -1,16 +1,17 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import S3 from "aws-sdk/clients/s3";
3
+ /// <reference types="node" />
4
+ import type { CompleteMultipartUploadOutput } from "@webiny/aws-sdk/client-s3";
4
5
  import { Readable } from "stream";
5
- import { ImageFile } from "./utils";
6
+ import type { File } from "@webiny/api-file-manager/types";
6
7
  interface FileStreamDetails {
7
8
  stream: Readable;
8
9
  filename: string;
9
10
  }
10
11
  interface ExportInfo {
11
- files: ImageFile[];
12
- pageTitle: string;
13
- pageDataBuffer: Buffer;
12
+ files: File[];
13
+ name: string;
14
+ dataBuffer: Buffer;
14
15
  }
15
16
  export interface ZipperConfig {
16
17
  exportInfo: ExportInfo;
@@ -22,15 +23,16 @@ export default class Zipper {
22
23
  private readonly archiveFileName;
23
24
  config: ZipperConfig;
24
25
  constructor(config: ZipperConfig);
25
- s3DownloadStreams(): FileStreamDetails[];
26
- process(): Promise<S3.ManagedUpload.SendData>;
26
+ s3DownloadStreams(): Promise<FileStreamDetails[]>;
27
+ process(): Promise<CompleteMultipartUploadOutput>;
27
28
  }
28
29
  export declare class ZipOfZip {
29
30
  private readonly archiveFormat;
30
31
  private readonly archiveFileName;
31
32
  keys: string[];
32
- constructor(keys: string[]);
33
- getFileStreams(): FileStreamDetails[];
34
- process(): Promise<S3.ManagedUpload.SendData>;
33
+ filename: string;
34
+ constructor(keys: string[], filename: string);
35
+ getFileStreams(): Promise<FileStreamDetails[]>;
36
+ process(): Promise<CompleteMultipartUploadOutput>;
35
37
  }
36
38
  export {};
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = exports.ZipOfZip = void 0;
9
+ var _archiver = _interopRequireDefault(require("archiver"));
10
+ var _stream = require("stream");
11
+ var path = _interopRequireWildcard(require("path"));
12
+ var _kebabCase = _interopRequireDefault(require("lodash/kebabCase"));
13
+ var _uniqid = _interopRequireDefault(require("uniqid"));
14
+ var _s3Stream = require("./s3Stream");
15
+ // TODO: Move "archive" in layer
16
+
17
+ class Zipper {
18
+ archiveFormat = "zip";
19
+ filesDirName = "assets";
20
+ constructor(config) {
21
+ this.config = config;
22
+ this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.name)}.zip`);
23
+ }
24
+ async s3DownloadStreams() {
25
+ const exportInfo = this.config.exportInfo;
26
+ const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.name)}`);
27
+ const files = await Promise.all(exportInfo.files.map(async ({
28
+ key
29
+ }) => {
30
+ return {
31
+ stream: await _s3Stream.s3Stream.readStream(key),
32
+ filename: `${prefix}\\${this.filesDirName}\\${key}`
33
+ };
34
+ }));
35
+ return [...files, {
36
+ stream: _stream.Readable.from(exportInfo.dataBuffer),
37
+ filename: `${prefix}\\${exportInfo.name}.json`
38
+ }];
39
+ }
40
+ async process() {
41
+ const {
42
+ streamPassThrough,
43
+ streamPassThroughUploadPromise
44
+ } = _s3Stream.s3Stream.writeStream(this.archiveFileName);
45
+
46
+ // 1. Read all files from S3 using stream.
47
+ const s3FilesStreams = await this.s3DownloadStreams();
48
+
49
+ // 2. Prepare zip from the file stream.
50
+ const archive = _archiver.default.create(this.archiveFormat);
51
+ // Handle archive events.
52
+ archive.on("error", error => {
53
+ throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
54
+ });
55
+
56
+ // Append all file streams to archive.
57
+ s3FilesStreams.forEach(streamDetails => archive.append(streamDetails.stream, {
58
+ name: streamDetails.filename
59
+ }));
60
+
61
+ // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
62
+ archive.pipe(streamPassThrough);
63
+ // Finalize the archive (ie we are done appending files but streams have to finish yet)
64
+ // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
65
+ archive.finalize();
66
+
67
+ // 3. Return upload stream promise.
68
+ return streamPassThroughUploadPromise;
69
+ }
70
+ }
71
+ exports.default = Zipper;
72
+ class ZipOfZip {
73
+ archiveFormat = "zip";
74
+ constructor(keys, filename) {
75
+ this.keys = keys;
76
+ this.filename = filename;
77
+ this.archiveFileName = (0, _uniqid.default)("EXPORTS/", `-${filename}`);
78
+ }
79
+ async getFileStreams() {
80
+ return await Promise.all(this.keys.map(async key => {
81
+ return {
82
+ stream: await _s3Stream.s3Stream.readStream(key),
83
+ filename: `${path.basename(key)}`
84
+ };
85
+ }));
86
+ }
87
+ async process() {
88
+ const {
89
+ streamPassThrough,
90
+ streamPassThroughUploadPromise
91
+ } = _s3Stream.s3Stream.writeStream(this.archiveFileName);
92
+
93
+ // 1. Read all files from S3 using stream.
94
+ const fileStreamDetails = await this.getFileStreams();
95
+
96
+ // 2. Prepare zip from the file stream.
97
+ const archive = _archiver.default.create(this.archiveFormat);
98
+ // Handle archive events.
99
+ archive.on("error", error => {
100
+ throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
101
+ });
102
+
103
+ // Append all file streams to archive.
104
+ fileStreamDetails.forEach(streamDetails => archive.append(streamDetails.stream, {
105
+ name: streamDetails.filename
106
+ }));
107
+
108
+ // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
109
+ archive.pipe(streamPassThrough);
110
+ // Finalize the archive (ie we are done appending files but streams have to finish yet)
111
+ // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
112
+ archive.finalize();
113
+
114
+ // 3. Return upload stream promise.
115
+ return streamPassThroughUploadPromise;
116
+ }
117
+ }
118
+ exports.ZipOfZip = ZipOfZip;
119
+
120
+ //# sourceMappingURL=zipper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_archiver","_interopRequireDefault","require","_stream","path","_interopRequireWildcard","_kebabCase","_uniqid","_s3Stream","Zipper","archiveFormat","filesDirName","constructor","config","archiveFileName","uniqueId","archiveFileKey","kebabCase","exportInfo","name","s3DownloadStreams","prefix","files","Promise","all","map","key","stream","s3Stream","readStream","filename","Readable","from","dataBuffer","process","streamPassThrough","streamPassThroughUploadPromise","writeStream","s3FilesStreams","archive","vending","create","on","error","Error","code","message","stack","forEach","streamDetails","append","pipe","finalize","exports","default","ZipOfZip","keys","getFileStreams","basename","fileStreamDetails"],"sources":["zipper.ts"],"sourcesContent":["// TODO: Move \"archive\" in layer\nimport type { ArchiverError } from \"archiver\";\nimport vending from \"archiver\";\nimport type { CompleteMultipartUploadOutput } from \"@webiny/aws-sdk/client-s3\";\nimport { Readable } from \"stream\";\nimport * as path from \"path\";\nimport kebabCase from \"lodash/kebabCase\";\nimport uniqueId from \"uniqid\";\nimport { s3Stream } from \"./s3Stream\";\nimport type { 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 async s3DownloadStreams(): Promise<FileStreamDetails[]> {\n const exportInfo = this.config.exportInfo;\n const prefix = uniqueId(\"\", `-${kebabCase(exportInfo.name)}`);\n const files = await Promise.all(\n exportInfo.files.map(async ({ key }) => {\n return {\n stream: await s3Stream.readStream(key),\n filename: `${prefix}\\\\${this.filesDirName}\\\\${key}`\n };\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 async process(): Promise<CompleteMultipartUploadOutput> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const s3FilesStreams = await 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 async getFileStreams(): Promise<FileStreamDetails[]> {\n return await Promise.all(\n this.keys.map(async key => {\n return {\n stream: await s3Stream.readStream(key),\n filename: `${path.basename(key)}`\n };\n })\n );\n }\n\n async process(): Promise<CompleteMultipartUploadOutput> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const fileStreamDetails = await 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":";;;;;;;;AAEA,IAAAA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ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import { ContextPlugin } from "@webiny/api";
2
+ import type { PbImportExportContext } from "../../types";
3
+ declare const _default: ContextPlugin<PbImportExportContext>;
4
+ export default _default;
@@ -0,0 +1,158 @@
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 _pubsub = require("@webiny/pubsub");
10
+ var _api = require("@webiny/api");
11
+ var _types = require("../../types");
12
+ var _client = require("../../client");
13
+ var _utils = require("../../import/utils");
14
+ var _utils2 = require("@webiny/utils");
15
+ var _PageBlocksPermissions = require("@webiny/api-page-builder/graphql/crud/permissions/PageBlocksPermissions");
16
+ const EXPORT_BLOCKS_FOLDER_KEY = "WEBINY_PB_EXPORT_BLOCK";
17
+ const EXPORT_BLOCKS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER;
18
+ const IMPORT_BLOCKS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER;
19
+ var _default = exports.default = new _api.ContextPlugin(context => {
20
+ const pageBlocksPermissions = new _PageBlocksPermissions.PageBlocksPermissions({
21
+ getPermissions: () => context.security.getPermissions("pb.block"),
22
+ getIdentity: context.security.getIdentity,
23
+ fullAccessPermissionName: "pb.*"
24
+ });
25
+
26
+ // Export
27
+ const onBlocksBeforeExport = (0, _pubsub.createTopic)("PageBuilder.onBlocksBeforeExport");
28
+ const onBlocksAfterExport = (0, _pubsub.createTopic)("PageBuilder.onBlocksAfterExport");
29
+
30
+ // Import
31
+ const onBlocksBeforeImport = (0, _pubsub.createTopic)("PageBuilder.onBlocksBeforeImport");
32
+ const onBlocksAfterImport = (0, _pubsub.createTopic)("PageBuilder.onBlocksAfterImport");
33
+ const importExportCrud = {
34
+ onBlocksBeforeExport,
35
+ onBlocksAfterExport,
36
+ onBlocksBeforeImport,
37
+ onBlocksAfterImport,
38
+ async importBlocks(params) {
39
+ const {
40
+ zipFileUrl
41
+ } = params;
42
+ await pageBlocksPermissions.ensure({
43
+ rwd: "w"
44
+ });
45
+
46
+ // Create a task for import block
47
+ const task = await context.pageBuilder.importExportTask.createTask({
48
+ status: _types.ImportExportTaskStatus.PENDING,
49
+ input: {
50
+ zipFileUrl
51
+ }
52
+ });
53
+ /**
54
+ * Import Blocks
55
+ * ImportBlocks
56
+ * importBlocks
57
+ */
58
+ await onBlocksBeforeImport.publish({
59
+ params
60
+ });
61
+ await (0, _client.invokeHandlerClient)({
62
+ context,
63
+ name: IMPORT_BLOCKS_CREATE_HANDLER,
64
+ payload: {
65
+ zipFileUrl,
66
+ task,
67
+ type: "block",
68
+ identity: context.security.getIdentity()
69
+ },
70
+ description: "Import Blocks - create"
71
+ });
72
+ await onBlocksAfterImport.publish({
73
+ params
74
+ });
75
+ return {
76
+ task
77
+ };
78
+ },
79
+ async exportBlocks(params) {
80
+ const {
81
+ ids: initialBlockIds,
82
+ where
83
+ } = params;
84
+ await pageBlocksPermissions.ensure({
85
+ rwd: "w"
86
+ });
87
+ let blockIds = initialBlockIds || [];
88
+ // If no ids are provided then it means we want to export all blocks
89
+ if (!initialBlockIds || Array.isArray(initialBlockIds) && initialBlockIds.length === 0) {
90
+ const blocks = await context.pageBuilder.listPageBlocks({
91
+ where
92
+ });
93
+ // Save block ids
94
+ blockIds = blocks.map(block => block.id);
95
+ }
96
+ if (blockIds.length === 0) {
97
+ throw new _error.default("Cannot export blocks - no blocks found for provided inputs.", "EMPTY_EXPORT_NO_BLOCKS_FOUND");
98
+ }
99
+
100
+ // Create the main task for blocks export.
101
+ const task = await context.pageBuilder.importExportTask.createTask({
102
+ status: _types.ImportExportTaskStatus.PENDING
103
+ });
104
+ const exportBlocksDataKey = `${EXPORT_BLOCKS_FOLDER_KEY}/${task.id}`;
105
+ // For each block create a sub task and invoke the process handler.
106
+ for (let i = 0; i < blockIds.length; i++) {
107
+ const blockId = blockIds[i];
108
+ // Create sub task.
109
+ await context.pageBuilder.importExportTask.createSubTask(task.id, (0, _utils2.zeroPad)(i + 1, 5), {
110
+ status: _types.ImportExportTaskStatus.PENDING,
111
+ input: {
112
+ blockId,
113
+ exportBlocksDataKey
114
+ }
115
+ });
116
+ }
117
+ // Update main task status.
118
+ await context.pageBuilder.importExportTask.updateTask(task.id, {
119
+ status: _types.ImportExportTaskStatus.PROCESSING,
120
+ stats: (0, _utils.initialStats)(blockIds.length),
121
+ input: {
122
+ exportBlocksDataKey
123
+ }
124
+ });
125
+
126
+ /**
127
+ * Export Blocks
128
+ * ExportBlocks
129
+ * exportBlocks
130
+ */
131
+ await onBlocksBeforeExport.publish({
132
+ params
133
+ });
134
+ // Invoke handler.
135
+ await (0, _client.invokeHandlerClient)({
136
+ context,
137
+ name: EXPORT_BLOCKS_PROCESS_HANDLER,
138
+ payload: {
139
+ taskId: task.id,
140
+ subTaskIndex: 1,
141
+ type: "block",
142
+ identity: context.security.getIdentity()
143
+ },
144
+ description: "Export blocks - process"
145
+ });
146
+ await onBlocksAfterExport.publish({
147
+ params
148
+ });
149
+ return {
150
+ task
151
+ };
152
+ }
153
+ };
154
+ // Modify context
155
+ context.pageBuilder.blocks = importExportCrud;
156
+ });
157
+
158
+ //# sourceMappingURL=blocks.crud.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_pubsub","_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","exports","default","ContextPlugin","context","pageBlocksPermissions","PageBlocksPermissions","getPermissions","security","getIdentity","fullAccessPermissionName","onBlocksBeforeExport","createTopic","onBlocksAfterExport","onBlocksBeforeImport","onBlocksAfterImport","importExportCrud","importBlocks","params","zipFileUrl","ensure","rwd","task","pageBuilder","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","publish","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"],"sources":["blocks.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport type {\n BlocksImportExportCrud,\n PbImportExportContext,\n OnBlocksBeforeExportTopicParams,\n OnBlocksAfterExportTopicParams,\n OnBlocksBeforeImportTopicParams,\n OnBlocksAfterImportTopicParams\n} from \"~/types\";\nimport { ImportExportTaskStatus } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport type { Payload as CreateHandlerPayload } from \"~/import/create\";\nimport { initialStats } from \"~/import/utils\";\nimport type { 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 // Export\n const onBlocksBeforeExport = createTopic<OnBlocksBeforeExportTopicParams>(\n \"PageBuilder.onBlocksBeforeExport\"\n );\n const onBlocksAfterExport = createTopic<OnBlocksAfterExportTopicParams>(\n \"PageBuilder.onBlocksAfterExport\"\n );\n\n // Import\n const onBlocksBeforeImport = createTopic<OnBlocksBeforeImportTopicParams>(\n \"PageBuilder.onBlocksBeforeImport\"\n );\n const onBlocksAfterImport = createTopic<OnBlocksAfterImportTopicParams>(\n \"PageBuilder.onBlocksAfterImport\"\n );\n\n const importExportCrud: BlocksImportExportCrud = {\n onBlocksBeforeExport,\n onBlocksAfterExport,\n onBlocksBeforeImport,\n onBlocksAfterImport,\n async importBlocks(params) {\n const { zipFileUrl } = params;\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 onBlocksBeforeImport.publish({ params });\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 await onBlocksAfterImport.publish({ params });\n\n return {\n task\n };\n },\n\n async exportBlocks(params) {\n const { ids: initialBlockIds, where } = params;\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 await onBlocksBeforeExport.publish({ params });\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 await onBlocksAfterExport.publish({ params });\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,OAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AASA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AAEA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,sBAAA,GAAAP,OAAA;AAEA,MAAMQ,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,GAAAC,OAAA,CAAAC,OAAA,GAElE,IAAIC,kBAAa,CAAwBC,OAAO,IAAI;EAC/D,MAAMC,qBAAqB,GAAG,IAAIC,4CAAqB,CAAC;IACpDC,cAAc,EAAEA,CAAA,KAAMH,OAAO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AAC,EAAE,CAAC,CAAC,EACjB;UACI1B,MAAM,EAAEC,6BAAsB,CAACC,OAAO;UACtCC,KAAK,EAAE;YACHwB,OAAO;YACPF;UACJ;QACJ,CACJ,CAAC;MACL;MACA;MACA,MAAM/C,OAAO,CAACmB,WAAW,CAACC,gBAAgB,CAACgC,UAAU,CAAClC,IAAI,CAAC2B,EAAE,EAAE;QAC3DvB,MAAM,EAAEC,6BAAsB,CAAC8B,UAAU;QACzCC,KAAK,EAAE,IAAAC,mBAAY,EAAClB,QAAQ,CAACG,MAAM,CAAC;QACpCf,KAAK,EAAE;UACHsB;QACJ;MACJ,CAAC,CAAC;;MAEF;AACZ;AACA;AACA;AACA;MACY,MAAMxC,oBAAoB,CAACmB,OAAO,CAAC;QAAEZ;MAAO,CAAC,CAAC;MAC9C;MACA,MAAM,IAAAa,2BAAmB,EAAoC;QACzD3B,OAAO;QACP4B,IAAI,EAAEtC,6BAA6B;QACnCuC,OAAO,EAAE;UACL2B,MAAM,EAAEtC,IAAI,CAAC2B,EAAE;UACfY,YAAY,EAAE,CAAC;UACf3B,IAAI,EAAE,OAAO;UACbC,QAAQ,EAAE/B,OAAO,CAACI,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACD2B,WAAW,EAAE;MACjB,CAAC,CAAC;MACF,MAAMvB,mBAAmB,CAACiB,OAAO,CAAC;QAAEZ;MAAO,CAAC,CAAC;MAE7C,OAAO;QAAEI;MAAK,CAAC;IACnB;EACJ,CAAC;EACD;EACAlB,OAAO,CAACmB,WAAW,CAACsB,MAAM,GAAG7B,gBAAgB;AACjD,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import { ContextPlugin } from "@webiny/api";
2
+ import type { PbImportExportContext } from "../../types";
3
+ declare const _default: ContextPlugin<PbImportExportContext>;
4
+ export default _default;