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

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 (182) hide show
  1. package/client.d.ts +2 -2
  2. package/client.js.map +1 -1
  3. package/export/combine/blocksHandler.d.ts +6 -0
  4. package/export/combine/blocksHandler.js +99 -0
  5. package/export/combine/blocksHandler.js.map +1 -0
  6. package/export/combine/formsHandler.d.ts +6 -0
  7. package/export/combine/formsHandler.js +99 -0
  8. package/export/combine/formsHandler.js.map +1 -0
  9. package/{exportPages → export}/combine/index.d.ts +3 -2
  10. package/export/combine/index.js +42 -0
  11. package/export/combine/index.js.map +1 -0
  12. package/export/combine/pagesHandler.d.ts +6 -0
  13. package/export/combine/pagesHandler.js +99 -0
  14. package/export/combine/pagesHandler.js.map +1 -0
  15. package/export/combine/templatesHandler.d.ts +6 -0
  16. package/export/combine/templatesHandler.js +99 -0
  17. package/export/combine/templatesHandler.js.map +1 -0
  18. package/export/process/blocksHandler.d.ts +6 -0
  19. package/export/process/blocksHandler.js +162 -0
  20. package/export/process/blocksHandler.js.map +1 -0
  21. package/export/process/formsHandler.d.ts +6 -0
  22. package/export/process/formsHandler.js +187 -0
  23. package/export/process/formsHandler.js.map +1 -0
  24. package/{exportPages → export}/process/index.d.ts +4 -6
  25. package/export/process/index.js +39 -0
  26. package/export/process/index.js.map +1 -0
  27. package/export/process/pagesHandler.d.ts +6 -0
  28. package/export/process/pagesHandler.js +189 -0
  29. package/export/process/pagesHandler.js.map +1 -0
  30. package/export/process/templatesHandler.d.ts +6 -0
  31. package/export/process/templatesHandler.js +166 -0
  32. package/export/process/templatesHandler.js.map +1 -0
  33. package/{exportPages → export}/s3Stream.d.ts +5 -2
  34. package/export/s3Stream.js.map +1 -0
  35. package/export/utils.d.ts +29 -0
  36. package/export/utils.js +194 -0
  37. package/export/utils.js.map +1 -0
  38. package/{exportPages → export}/zipper.d.ts +6 -5
  39. package/{exportPages → export}/zipper.js +9 -8
  40. package/export/zipper.js.map +1 -0
  41. package/graphql/crud/blocks.crud.d.ts +4 -0
  42. package/graphql/crud/blocks.crud.js +140 -0
  43. package/graphql/crud/blocks.crud.js.map +1 -0
  44. package/graphql/crud/forms.crud.d.ts +4 -0
  45. package/graphql/crud/forms.crud.js +134 -0
  46. package/graphql/crud/forms.crud.js.map +1 -0
  47. package/graphql/crud/importExportTasks.crud.d.ts +5 -0
  48. package/graphql/crud/{pageImportExportTasks.crud.js → importExportTasks.crud.js} +83 -79
  49. package/graphql/crud/importExportTasks.crud.js.map +1 -0
  50. package/graphql/crud/pages.crud.d.ts +2 -2
  51. package/graphql/crud/pages.crud.js +26 -18
  52. package/graphql/crud/pages.crud.js.map +1 -1
  53. package/graphql/crud/templates.crud.d.ts +4 -0
  54. package/graphql/crud/templates.crud.js +128 -0
  55. package/graphql/crud/templates.crud.js.map +1 -0
  56. package/graphql/crud.d.ts +2 -2
  57. package/graphql/crud.js +5 -2
  58. package/graphql/crud.js.map +1 -1
  59. package/graphql/graphql/blocks.gql.d.ts +4 -0
  60. package/graphql/graphql/blocks.gql.js +52 -0
  61. package/graphql/graphql/blocks.gql.js.map +1 -0
  62. package/graphql/graphql/forms.gql.d.ts +4 -0
  63. package/graphql/graphql/forms.gql.js +60 -0
  64. package/graphql/graphql/forms.gql.js.map +1 -0
  65. package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
  66. package/graphql/graphql/{pageImportExportTasks.gql.js → importExportTasks.gql.js} +17 -17
  67. package/graphql/graphql/importExportTasks.gql.js.map +1 -0
  68. package/graphql/graphql/pages.gql.d.ts +2 -2
  69. package/graphql/graphql/pages.gql.js +3 -9
  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.js +5 -2
  76. package/graphql/graphql.js.map +1 -1
  77. package/graphql/index.d.ts +2 -2
  78. package/graphql/index.js.map +1 -1
  79. package/graphql/types.d.ts +83 -23
  80. package/graphql/types.js.map +1 -1
  81. package/import/constants.d.ts +3 -0
  82. package/import/constants.js +14 -0
  83. package/import/constants.js.map +1 -0
  84. package/import/create/blocksHandler.d.ts +3 -0
  85. package/import/create/blocksHandler.js +101 -0
  86. package/import/create/blocksHandler.js.map +1 -0
  87. package/import/create/formsHandler.d.ts +3 -0
  88. package/import/create/formsHandler.js +103 -0
  89. package/import/create/formsHandler.js.map +1 -0
  90. package/{importPages → import}/create/index.d.ts +7 -5
  91. package/import/create/index.js +42 -0
  92. package/import/create/index.js.map +1 -0
  93. package/import/create/pagesHandler.d.ts +3 -0
  94. package/import/create/pagesHandler.js +103 -0
  95. package/import/create/pagesHandler.js.map +1 -0
  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/blocks/blocksHandler.d.ts +3 -0
  100. package/import/process/blocks/blocksHandler.js +169 -0
  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 +92 -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/{importPages → import}/process/index.d.ts +5 -3
  112. package/import/process/index.js +39 -0
  113. package/import/process/index.js.map +1 -0
  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/pages/pagesHandler.js +183 -0
  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 +48 -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 +49 -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 -1
  157. package/mockSecurity.js.map +1 -1
  158. package/package.json +34 -37
  159. package/types.d.ts +83 -65
  160. package/types.js +17 -17
  161. package/types.js.map +1 -1
  162. package/exportPages/combine/index.js +0 -106
  163. package/exportPages/combine/index.js.map +0 -1
  164. package/exportPages/process/index.js +0 -192
  165. package/exportPages/process/index.js.map +0 -1
  166. package/exportPages/s3Stream.js.map +0 -1
  167. package/exportPages/utils.d.ts +0 -13
  168. package/exportPages/utils.js +0 -100
  169. package/exportPages/utils.js.map +0 -1
  170. package/exportPages/zipper.js.map +0 -1
  171. package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
  172. package/graphql/crud/pageImportExportTasks.crud.js.map +0 -1
  173. package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
  174. package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
  175. package/importPages/create/index.js +0 -107
  176. package/importPages/create/index.js.map +0 -1
  177. package/importPages/process/index.js +0 -180
  178. package/importPages/process/index.js.map +0 -1
  179. package/importPages/utils.d.ts +0 -50
  180. package/importPages/utils.js +0 -488
  181. package/importPages/utils.js.map +0 -1
  182. /package/{exportPages → export}/s3Stream.js +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"names":["EXPORT_PAGES_FOLDER_KEY","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","exportBlocksDataKey","preview","getFile","blockData","blockDataBuffer","exportTemplate","template","exportTemplatesDataKey","templateData","slug","tags","description","layout","pageCategory","templateDataBuffer","data","Array","isArray","i","element","tuple","Object","entries","key","value","exportForm","form","exportFormsDataKey","formData","fields","triggers","formDataBuffer"],"sources":["utils.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { Page, PageBlock, PageTemplate } from \"@webiny/api-page-builder/types\";\nimport { FbForm } from \"@webiny/api-form-builder/types\";\nimport { 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<S3.ManagedUpload.SendData> {\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\" | \"preview\">;\n files: File[];\n}\n\nexport async function exportBlock(\n block: PageBlock,\n exportBlocksDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<S3.ManagedUpload.SendData> {\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 // Add block preview image file data\n if (block.preview.id) {\n imageFilesData.push(await fileManager.getFile(block.preview.id));\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 preview: block.preview\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\" | \"slug\" | \"tags\" | \"description\" | \"content\" | \"layout\" | \"pageCategory\"\n >;\n files: File[];\n}\n\nexport async function exportTemplate(\n template: PageTemplate,\n exportTemplatesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<S3.ManagedUpload.SendData> {\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 = {\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 },\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: any[] = []): File[] {\n // Base case: termination\n if (!data || typeof data !== \"object\") {\n return files;\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 // TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.\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\nexport interface ExportedFormData {\n form: Pick<\n FbForm,\n \"name\" | \"status\" | \"version\" | \"fields\" | \"layout\" | \"settings\" | \"triggers\"\n >;\n files: File[];\n}\n\nexport async function exportForm(\n form: FbForm,\n exportFormsDataKey: string\n): Promise<S3.ManagedUpload.SendData> {\n // Extract the form data in a json file and upload it to S3\n const formData = {\n form: {\n name: form.name,\n status: form.status,\n version: form.version,\n fields: form.fields,\n layout: form.layout,\n settings: form.settings,\n triggers: form.triggers\n }\n };\n const formDataBuffer = Buffer.from(JSON.stringify(formData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: [],\n name: form.name,\n dataBuffer: formDataBuffer\n },\n archiveFileKey: exportFormsDataKey\n });\n\n return zipper.process();\n}\n"],"mappings":";;;;;;;;;;;;AAIA;AACA;AAEO,MAAMA,uBAAuB,GAAG,wBAAwB;AAAC;AACzD,MAAMC,wBAAwB,GAAG,wBAAwB;AAAC;AAC1D,MAAMC,2BAA2B,GAAG,2BAA2B;AAAC;AAChE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CAACkB,IAAI,CAAC,GAAG6C,KAAK,CAAC;IACxB,CAAC,MAAM;MACH9D,oBAAoB,CAAC8D,KAAK,EAAE/D,KAAK,CAAC;IACtC;EACJ;EACA,OAAOA,KAAK;AAChB;AAUO,eAAegE,UAAU,CAC5BC,IAAY,EACZC,kBAA0B,EACQ;EAClC;EACA,MAAMC,QAAQ,GAAG;IACbF,IAAI,EAAE;MACFhC,IAAI,EAAEgC,IAAI,CAAChC,IAAI;MACfV,MAAM,EAAE0C,IAAI,CAAC1C,MAAM;MACnBD,OAAO,EAAE2C,IAAI,CAAC3C,OAAO;MACrB8C,MAAM,EAAEH,IAAI,CAACG,MAAM;MACnBjB,MAAM,EAAEc,IAAI,CAACd,MAAM;MACnB3B,QAAQ,EAAEyC,IAAI,CAACzC,QAAQ;MACvB6C,QAAQ,EAAEJ,IAAI,CAACI;IACnB;EACJ,CAAC;EACD,MAAMC,cAAc,GAAG5C,MAAM,CAACC,IAAI,CAACC,IAAI,CAACC,SAAS,CAACsC,QAAQ,CAAC,CAAC;EAE5D,MAAMrC,MAAM,GAAG,IAAIC,eAAM,CAAC;IACtBC,UAAU,EAAE;MACRhC,KAAK,EAAE,EAAE;MACTiC,IAAI,EAAEgC,IAAI,CAAChC,IAAI;MACfC,UAAU,EAAEoC;IAChB,CAAC;IACDnC,cAAc,EAAE+B;EACpB,CAAC,CAAC;EAEF,OAAOpC,MAAM,CAACM,OAAO,EAAE;AAC3B"}
@@ -2,15 +2,15 @@
2
2
  /// <reference types="node" />
3
3
  import S3 from "aws-sdk/clients/s3";
4
4
  import { Readable } from "stream";
5
- import { ImageFile } from "./utils";
5
+ import { File } from "@webiny/api-file-manager/types";
6
6
  interface FileStreamDetails {
7
7
  stream: Readable;
8
8
  filename: string;
9
9
  }
10
10
  interface ExportInfo {
11
- files: ImageFile[];
12
- pageTitle: string;
13
- pageDataBuffer: Buffer;
11
+ files: File[];
12
+ name: string;
13
+ dataBuffer: Buffer;
14
14
  }
15
15
  export interface ZipperConfig {
16
16
  exportInfo: ExportInfo;
@@ -29,7 +29,8 @@ export declare class ZipOfZip {
29
29
  private readonly archiveFormat;
30
30
  private readonly archiveFileName;
31
31
  keys: string[];
32
- constructor(keys: string[]);
32
+ filename: string;
33
+ constructor(keys: string[], filename: string);
33
34
  getFileStreams(): FileStreamDetails[];
34
35
  process(): Promise<S3.ManagedUpload.SendData>;
35
36
  }
@@ -22,22 +22,22 @@ class Zipper {
22
22
  (0, _defineProperty2.default)(this, "archiveFileName", void 0);
23
23
  (0, _defineProperty2.default)(this, "config", void 0);
24
24
  this.config = config;
25
- this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.pageTitle)}.zip`);
25
+ this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.name)}.zip`);
26
26
  }
27
27
  s3DownloadStreams() {
28
28
  const exportInfo = this.config.exportInfo;
29
- const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.pageTitle)}`);
29
+ const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.name)}`);
30
30
  const files = exportInfo.files.map(({
31
31
  key
32
32
  }) => {
33
33
  return {
34
34
  stream: _s3Stream.s3Stream.readStream(key),
35
- filename: `${prefix}\\${this.filesDirName}\\${path.basename(key)}`
35
+ filename: `${prefix}\\${this.filesDirName}\\${key}`
36
36
  };
37
37
  });
38
38
  return [...files, {
39
- stream: _stream.Readable.from(exportInfo.pageDataBuffer),
40
- filename: `${prefix}\\${exportInfo.pageTitle}.json`
39
+ stream: _stream.Readable.from(exportInfo.dataBuffer),
40
+ filename: `${prefix}\\${exportInfo.name}.json`
41
41
  }];
42
42
  }
43
43
  process() {
@@ -72,14 +72,15 @@ class Zipper {
72
72
  }
73
73
  }
74
74
  exports.default = Zipper;
75
- const PAGE_EXPORT_BASENAME = `WEBINY_PAGE_EXPORT.zip`;
76
75
  class ZipOfZip {
77
- constructor(keys) {
76
+ constructor(keys, filename) {
78
77
  (0, _defineProperty2.default)(this, "archiveFormat", "zip");
79
78
  (0, _defineProperty2.default)(this, "archiveFileName", void 0);
80
79
  (0, _defineProperty2.default)(this, "keys", void 0);
80
+ (0, _defineProperty2.default)(this, "filename", void 0);
81
81
  this.keys = keys;
82
- this.archiveFileName = (0, _uniqid.default)("", `-${PAGE_EXPORT_BASENAME}`);
82
+ this.filename = filename;
83
+ this.archiveFileName = (0, _uniqid.default)("EXPORTS/", `-${filename}`);
83
84
  }
84
85
  getFileStreams() {
85
86
  return this.keys.map(key => {
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Zipper","constructor","config","archiveFileName","uniqueId","archiveFileKey","kebabCase","exportInfo","name","s3DownloadStreams","prefix","files","map","key","stream","s3Stream","readStream","filename","filesDirName","Readable","from","dataBuffer","process","streamPassThrough","streamPassThroughUploadPromise","writeStream","s3FilesStreams","archive","vending","create","archiveFormat","on","error","Error","code","message","path","stack","forEach","streamDetails","append","pipe","finalize","ZipOfZip","keys","getFileStreams","basename","fileStreamDetails"],"sources":["zipper.ts"],"sourcesContent":["// TODO: Move \"archive\" in layer\nimport vending, { ArchiverError } from \"archiver\";\nimport S3 from \"aws-sdk/clients/s3\";\nimport { Readable } from \"stream\";\nimport * as path from \"path\";\nimport kebabCase from \"lodash/kebabCase\";\nimport uniqueId from \"uniqid\";\nimport { s3Stream } from \"./s3Stream\";\nimport { File } from \"@webiny/api-file-manager/types\";\n\ninterface FileStreamDetails {\n stream: Readable;\n filename: string;\n}\n\ninterface ExportInfo {\n files: File[];\n name: string;\n dataBuffer: Buffer;\n}\n\nexport interface ZipperConfig {\n exportInfo: ExportInfo;\n archiveFileKey: string;\n}\n\nexport default class Zipper {\n private readonly archiveFormat = \"zip\";\n private readonly filesDirName = \"assets\";\n private readonly archiveFileName: string;\n config: ZipperConfig;\n\n constructor(config: ZipperConfig) {\n this.config = config;\n this.archiveFileName = uniqueId(\n `${this.config.archiveFileKey}/`,\n `-${kebabCase(this.config.exportInfo.name)}.zip`\n );\n }\n\n s3DownloadStreams(): FileStreamDetails[] {\n const exportInfo = this.config.exportInfo;\n const prefix = uniqueId(\"\", `-${kebabCase(exportInfo.name)}`);\n const files = exportInfo.files.map(({ key }) => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${prefix}\\\\${this.filesDirName}\\\\${key}`\n };\n });\n\n return [\n ...files,\n {\n stream: Readable.from(exportInfo.dataBuffer),\n filename: `${prefix}\\\\${exportInfo.name}.json`\n }\n ];\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const s3FilesStreams = this.s3DownloadStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n s3FilesStreams.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n\nexport class ZipOfZip {\n private readonly archiveFormat = \"zip\";\n private readonly archiveFileName: string;\n keys: string[];\n filename: string;\n\n constructor(keys: string[], filename: string) {\n this.keys = keys;\n this.filename = filename;\n this.archiveFileName = uniqueId(\"EXPORTS/\", `-${filename}`);\n }\n\n getFileStreams(): FileStreamDetails[] {\n return this.keys.map(key => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${path.basename(key)}`\n };\n });\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const fileStreamDetails = this.getFileStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n fileStreamDetails.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n"],"mappings":";;;;;;;;;AACA;AAEA;AACA;AACA;AACA;AACA;AAPA;;AA0Be,MAAMA,MAAM,CAAC;EAMxBC,WAAW,CAACC,MAAoB,EAAE;IAAA,qDALD,KAAK;IAAA,oDACN,QAAQ;IAAA;IAAA;IAKpC,IAAI,CAACA,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,eAAe,GAAG,IAAAC,eAAQ,EAC1B,GAAE,IAAI,CAACF,MAAM,CAACG,cAAe,GAAE,EAC/B,IAAG,IAAAC,kBAAS,EAAC,IAAI,CAACJ,MAAM,CAACK,UAAU,CAACC,IAAI,CAAE,MAAK,CACnD;EACL;EAEAC,iBAAiB,GAAwB;IACrC,MAAMF,UAAU,GAAG,IAAI,CAACL,MAAM,CAACK,UAAU;IACzC,MAAMG,MAAM,GAAG,IAAAN,eAAQ,EAAC,EAAE,EAAG,IAAG,IAAAE,kBAAS,EAACC,UAAU,CAACC,IAAI,CAAE,EAAC,CAAC;IAC7D,MAAMG,KAAK,GAAGJ,UAAU,CAACI,KAAK,CAACC,GAAG,CAAC,CAAC;MAA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,OAAO,CAACc,IAAI,CAAClB,iBAAiB,CAAC;IAC/B;IACA;IACAI,OAAO,CAACe,QAAQ,EAAE;;IAElB;IACA,OAAOlB,8BAA8B;EACzC;AACJ;AAAC"}
@@ -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,140 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _handlerGraphql = require("@webiny/handler-graphql");
10
+ var _api = require("@webiny/api");
11
+ var _types = require("../../types");
12
+ var _client = require("../../client");
13
+ var _utils = require("../../import/utils");
14
+ var _utils2 = require("../../export/utils");
15
+ var _utils3 = require("@webiny/utils");
16
+ var _PageBlocksPermissions = require("@webiny/api-page-builder/graphql/crud/permissions/PageBlocksPermissions");
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 = 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
+ const importExportCrud = {
26
+ async importBlocks({
27
+ category: categorySlug,
28
+ zipFileUrl
29
+ }) {
30
+ await pageBlocksPermissions.ensure({
31
+ rwd: "w"
32
+ });
33
+
34
+ // Bail out early if category not found
35
+ const category = await context.pageBuilder.getBlockCategory(categorySlug);
36
+ if (!category) {
37
+ throw new _handlerGraphql.NotFoundError(`Category with slug "${categorySlug}" not found.`);
38
+ }
39
+
40
+ // Create a task for import block
41
+ const task = await context.pageBuilder.importExportTask.createTask({
42
+ status: _types.ImportExportTaskStatus.PENDING,
43
+ input: {
44
+ category: categorySlug,
45
+ zipFileUrl
46
+ }
47
+ });
48
+ /**
49
+ * Import Blocks
50
+ * ImportBlocks
51
+ * importBlocks
52
+ */
53
+ await (0, _client.invokeHandlerClient)({
54
+ context,
55
+ name: IMPORT_BLOCKS_CREATE_HANDLER,
56
+ payload: {
57
+ category: categorySlug,
58
+ zipFileUrl,
59
+ task,
60
+ type: "block",
61
+ identity: context.security.getIdentity()
62
+ },
63
+ description: "Import Blocks - create"
64
+ });
65
+ return {
66
+ task
67
+ };
68
+ },
69
+ async exportBlocks({
70
+ ids: initialBlockIds,
71
+ where
72
+ }) {
73
+ await pageBlocksPermissions.ensure({
74
+ rwd: "w"
75
+ });
76
+ let blockIds = initialBlockIds || [];
77
+ // If no ids are provided then it means we want to export all blocks
78
+ if (!initialBlockIds || Array.isArray(initialBlockIds) && initialBlockIds.length === 0) {
79
+ const blocks = await context.pageBuilder.listPageBlocks({
80
+ where
81
+ });
82
+ // Save block ids
83
+ blockIds = blocks.map(block => block.id);
84
+ }
85
+ if (blockIds.length === 0) {
86
+ throw new _error.default("Cannot export blocks - no blocks found for provided inputs.", "EMPTY_EXPORT_NO_BLOCKS_FOUND");
87
+ }
88
+
89
+ // Create the main task for blocks export.
90
+ const task = await context.pageBuilder.importExportTask.createTask({
91
+ status: _types.ImportExportTaskStatus.PENDING
92
+ });
93
+ const exportBlocksDataKey = `${_utils2.EXPORT_BLOCKS_FOLDER_KEY}/${task.id}`;
94
+ // For each block create a sub task and invoke the process handler.
95
+ for (let i = 0; i < blockIds.length; i++) {
96
+ const blockId = blockIds[i];
97
+ // Create sub task.
98
+ await context.pageBuilder.importExportTask.createSubTask(task.id, (0, _utils3.zeroPad)(i + 1, 5), {
99
+ status: _types.ImportExportTaskStatus.PENDING,
100
+ input: {
101
+ blockId,
102
+ exportBlocksDataKey
103
+ }
104
+ });
105
+ }
106
+ // Update main task status.
107
+ await context.pageBuilder.importExportTask.updateTask(task.id, {
108
+ status: _types.ImportExportTaskStatus.PROCESSING,
109
+ stats: (0, _utils.initialStats)(blockIds.length),
110
+ input: {
111
+ exportBlocksDataKey
112
+ }
113
+ });
114
+
115
+ /**
116
+ * Export Blocks
117
+ * ExportBlocks
118
+ * exportBlocks
119
+ */
120
+ // Invoke handler.
121
+ await (0, _client.invokeHandlerClient)({
122
+ context,
123
+ name: EXPORT_BLOCKS_PROCESS_HANDLER,
124
+ payload: {
125
+ taskId: task.id,
126
+ subTaskIndex: 1,
127
+ type: "block",
128
+ identity: context.security.getIdentity()
129
+ },
130
+ description: "Export blocks - process"
131
+ });
132
+ return {
133
+ task
134
+ };
135
+ }
136
+ };
137
+ // Modify context
138
+ context.pageBuilder.blocks = importExportCrud;
139
+ });
140
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["EXPORT_BLOCKS_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_BLOCKS_CREATE_HANDLER","IMPORT_CREATE_HANDLER","ContextPlugin","context","pageBlocksPermissions","PageBlocksPermissions","getPermissions","security","getIdentity","fullAccessPermissionName","importExportCrud","importBlocks","category","categorySlug","zipFileUrl","ensure","rwd","pageBuilder","getBlockCategory","NotFoundError","task","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","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 { 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\";\nimport { PageBlocksPermissions } from \"@webiny/api-page-builder/graphql/crud/permissions/PageBlocksPermissions\";\n\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({ category: categorySlug, zipFileUrl }) {\n await pageBlocksPermissions.ensure({ rwd: \"w\" });\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 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;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AAEA,MAAMA,6BAA6B,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAgC;AAClF,MAAMC,4BAA4B,GAAGH,OAAO,CAACC,GAAG,CAACG,qBAA+B;AAAC,eAElE,IAAIC,kBAAa,CAAwBC,OAAO,IAAI;EAC/D,MAAMC,qBAAqB,GAAG,IAAIC,4CAAqB,CAAC;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EAAE;QAC3DtB,MAAM,EAAEC,6BAAsB,CAAC8B,UAAU;QACzCC,KAAK,EAAE,IAAAC,mBAAY,EAACnB,QAAQ,CAACG,MAAM,CAAC;QACpCd,KAAK,EAAE;UACHqB;QACJ;MACJ,CAAC,CAAC;;MAEF;AACZ;AACA;AACA;AACA;MACY;MACA,MAAM,IAAApB,2BAAmB,EAAoC;QACzDxB,OAAO;QACPyB,IAAI,EAAEhC,6BAA6B;QACnCiC,OAAO,EAAE;UACL4B,MAAM,EAAErC,IAAI,CAACyB,EAAE;UACfa,YAAY,EAAE,CAAC;UACf5B,IAAI,EAAE,OAAO;UACbC,QAAQ,EAAE5B,OAAO,CAACI,QAAQ,CAACC,WAAW;QAC1C,CAAC;QACDwB,WAAW,EAAE;MACjB,CAAC,CAAC;MAEF,OAAO;QAAEZ;MAAK,CAAC;IACnB;EACJ,CAAC;EACD;EACAjB,OAAO,CAACc,WAAW,CAACwB,MAAM,GAAG/B,gBAAgB;AACjD,CAAC,CAAC;AAAA"}
@@ -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("../../export/utils");
14
+ var _utils3 = require("@webiny/utils");
15
+ var _FormsPermissions = require("@webiny/api-form-builder/plugins/crud/permissions/FormsPermissions");
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 = `${_utils2.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, _utils3.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":["EXPORT_FORMS_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_FORMS_CREATE_HANDLER","IMPORT_CREATE_HANDLER","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","EXPORT_FORMS_FOLDER_KEY","i","formId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex"],"sources":["forms.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { ImportExportTaskStatus, FormsImportExportCrud, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { Payload as CreateHandlerPayload } from \"~/import/create\";\nimport { initialStats } from \"~/import/utils\";\nimport { Payload as ExportFormsProcessHandlerPayload } from \"~/export/process\";\nimport { EXPORT_FORMS_FOLDER_KEY } from \"~/export/utils\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { FormsPermissions } from \"@webiny/api-form-builder/plugins/crud/permissions/FormsPermissions\";\n\nconst EXPORT_FORMS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER as string;\nconst IMPORT_FORMS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER as string;\n\nexport default new ContextPlugin<PbImportExportContext>(context => {\n 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;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AAEA,MAAMA,4BAA4B,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAgC;AACjF,MAAMC,2BAA2B,GAAGH,OAAO,CAACC,GAAG,CAACG,qBAA+B;AAAC,eAEjE,IAAIC,kBAAa,CAAwBC,OAAO,IAAI;EAC/D,MAAMC,gBAAgB,GAAG,IAAIC,kCAAgB,CAAC;IAC1C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;AACA;AACA;QACgB;QACA,MAAM,IAAAT,2BAAmB,EAAmC;UACxDrB,OAAO;UACPsB,IAAI,EAAE7B,4BAA4B;UAClC8B,OAAO,EAAE;YACL8B,MAAM,EAAExC,IAAI,CAAC4B,EAAE;YACfa,YAAY,EAAE,CAAC;YACf9B,IAAI,EAAE,MAAM;YACZC,QAAQ,EAAEzB,OAAO,CAACI,QAAQ,CAACC,WAAW;UAC1C,CAAC;UACDqB,WAAW,EAAE;QACjB,CAAC,CAAC;QAEF,OAAO;UAAEb;QAAK,CAAC;MACnB;IACJ,CAAC;IACD;IACAb,OAAO,CAACoC,WAAW,CAACD,KAAK,GAAG3B,gBAAgB;EAChD,CAAC,CAAC;AACN,CAAC,CAAC;AAAA"}
@@ -0,0 +1,5 @@
1
+ import { ContextPlugin } from "@webiny/api";
2
+ import { ImportExportPluginsParams } from "../../types";
3
+ import { PbImportExportContext } from "../types";
4
+ declare const _default: ({ storageOperations }: ImportExportPluginsParams) => ContextPlugin<PbImportExportContext>;
5
+ export default _default;