@webiny/api-page-builder-import-export 0.0.0-unstable.d7f521b032 → 0.0.0-unstable.da99e0b846
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/export/combine/formsHandler.d.ts +6 -0
- package/export/combine/formsHandler.js +99 -0
- package/export/combine/formsHandler.js.map +1 -0
- package/export/combine/index.js +5 -0
- package/export/combine/index.js.map +1 -1
- package/export/process/formsHandler.d.ts +6 -0
- package/export/process/formsHandler.js +187 -0
- package/export/process/formsHandler.js.map +1 -0
- package/export/process/index.js +5 -0
- package/export/process/index.js.map +1 -1
- package/export/s3Stream.d.ts +5 -2
- package/export/s3Stream.js.map +1 -1
- package/export/utils.d.ts +8 -1
- package/export/utils.js +34 -6
- package/export/utils.js.map +1 -1
- package/export/zipper.js +2 -2
- package/export/zipper.js.map +1 -1
- package/graphql/crud/blocks.crud.js +1 -2
- package/graphql/crud/blocks.crud.js.map +1 -1
- package/graphql/crud/forms.crud.d.ts +4 -0
- package/graphql/crud/forms.crud.js +129 -0
- package/graphql/crud/forms.crud.js.map +1 -0
- package/graphql/crud.js +2 -1
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/forms.gql.d.ts +4 -0
- package/graphql/graphql/forms.gql.js +60 -0
- package/graphql/graphql/forms.gql.js.map +1 -0
- package/graphql/graphql.js +2 -1
- package/graphql/graphql.js.map +1 -1
- package/graphql/types.d.ts +23 -0
- package/graphql/types.js.map +1 -1
- package/import/constants.d.ts +3 -0
- package/import/constants.js +14 -0
- package/import/constants.js.map +1 -0
- package/import/create/blocksHandler.js +4 -3
- package/import/create/blocksHandler.js.map +1 -1
- package/import/create/formsHandler.d.ts +3 -0
- package/import/create/formsHandler.js +103 -0
- package/import/create/formsHandler.js.map +1 -0
- package/import/create/index.js +5 -0
- package/import/create/index.js.map +1 -1
- package/import/create/pagesHandler.js +3 -2
- package/import/create/pagesHandler.js.map +1 -1
- package/import/create/templatesHandler.js +2 -1
- package/import/create/templatesHandler.js.map +1 -1
- package/import/process/blocks/blocksHandler.d.ts +3 -0
- package/import/process/blocks/blocksHandler.js +169 -0
- package/import/process/blocks/blocksHandler.js.map +1 -0
- package/import/process/blocks/importBlock.d.ts +11 -0
- package/import/process/blocks/importBlock.js +92 -0
- package/import/process/blocks/importBlock.js.map +1 -0
- package/import/process/blocksHandler.js +26 -20
- package/import/process/blocksHandler.js.map +1 -1
- package/import/process/forms/formsHandler.d.ts +3 -0
- package/import/process/forms/formsHandler.js +176 -0
- package/import/process/forms/formsHandler.js.map +1 -0
- package/import/process/forms/importForm.d.ts +9 -0
- package/import/process/forms/importForm.js +43 -0
- package/import/process/forms/importForm.js.map +1 -0
- package/import/process/index.js +8 -3
- package/import/process/index.js.map +1 -1
- package/import/process/pages/importPage.d.ts +11 -0
- package/import/process/pages/importPage.js +92 -0
- package/import/process/pages/importPage.js.map +1 -0
- package/import/process/pages/pagesHandler.d.ts +3 -0
- package/import/process/pages/pagesHandler.js +183 -0
- package/import/process/pages/pagesHandler.js.map +1 -0
- package/import/process/pagesHandler.js +29 -26
- package/import/process/pagesHandler.js.map +1 -1
- package/import/process/templates/importTemplate.d.ts +11 -0
- package/import/process/templates/importTemplate.js +66 -0
- package/import/process/templates/importTemplate.js.map +1 -0
- package/import/process/{templatesHandler.d.ts → templates/templatesHandler.d.ts} +2 -2
- package/import/process/{templatesHandler.js → templates/templatesHandler.js} +8 -7
- package/import/process/templates/templatesHandler.js.map +1 -0
- package/import/utils/deleteS3Folder.d.ts +1 -0
- package/import/utils/deleteS3Folder.js +19 -0
- package/import/utils/deleteS3Folder.js.map +1 -0
- package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
- package/import/utils/extractAndUploadZipFileContents.js +122 -0
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
- package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
- package/import/utils/extractZipAndUploadToS3.js +98 -0
- package/import/utils/extractZipAndUploadToS3.js.map +1 -0
- package/import/utils/getFileNameWithoutExt.d.ts +1 -0
- package/import/utils/getFileNameWithoutExt.js +11 -0
- package/import/utils/getFileNameWithoutExt.js.map +1 -0
- package/import/utils/index.d.ts +9 -0
- package/import/utils/index.js +104 -0
- package/import/utils/index.js.map +1 -0
- package/import/utils/initialStats.d.ts +7 -0
- package/import/utils/initialStats.js +16 -0
- package/import/utils/initialStats.js.map +1 -0
- package/import/utils/prepareDataDirMap.d.ts +6 -0
- package/import/utils/prepareDataDirMap.js +29 -0
- package/import/utils/prepareDataDirMap.js.map +1 -0
- package/import/utils/updateFilesInData.d.ts +8 -0
- package/import/utils/updateFilesInData.js +48 -0
- package/import/utils/updateFilesInData.js.map +1 -0
- package/import/utils/uploadAssets.d.ts +10 -0
- package/import/utils/uploadAssets.js +51 -0
- package/import/utils/uploadAssets.js.map +1 -0
- package/import/utils/uploadFilesFromS3.d.ts +3 -0
- package/import/utils/uploadFilesFromS3.js +19 -0
- package/import/utils/uploadFilesFromS3.js.map +1 -0
- package/import/utils.d.ts +1 -8
- package/import/utils.js +137 -103
- package/import/utils.js.map +1 -1
- package/package.json +23 -22
- package/types.d.ts +21 -0
- package/types.js.map +1 -1
- package/import/process/templatesHandler.js.map +0 -1
package/export/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["EXPORT_PAGES_FOLDER_KEY","EXPORT_BLOCKS_FOLDER_KEY","EXPORT_TEMPLATES_FOLDER_KEY","exportPage","page","exportPagesDataKey","fileManager","files","extractFilesFromData","content","pageSettingsImages","get","filter","image","src","fileIds","map","imageFile","id","imageFilesData","length","filesData","listFiles","ids","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","templateDataBuffer","data","Array","isArray","i","element","tuple","Object","entries","key","value"],"sources":["utils.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { Page, PageBlock, PageTemplate } from \"@webiny/api-page-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\";\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.files.listFiles({ ids: 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.files.listFiles({ ids: fileIds });\n imageFilesData.push(...filesData);\n }\n // Add block preview image file data\n if (block.preview.id) {\n imageFilesData.push(await fileManager.files.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<PageTemplate, \"title\" | \"slug\" | \"tags\" | \"description\" | \"content\" | \"layout\">;\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.files.listFiles({ ids: 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 },\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"],"mappings":";;;;;;;;;;;AAGA;AACA;AAEO,MAAMA,uBAAuB,GAAG,wBAAwB;AAAC;AACzD,MAAMC,wBAAwB,GAAG,wBAAwB;AAAC;AAC1D,MAAMC,2BAA2B,GAAG,2BAA2B;AAAC;AAOhE,eAAeC,UAAU,CAC5BC,IAAU,EACVC,kBAA0B,EAC1BC,WAA8C,EACZ;EAClC;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,SAAS,IAAIA,SAAS,CAACC,EAAE,CAAC;EAChF;EACA,MAAMC,cAAc,GAAG,EAAE;EACzB,IAAIJ,OAAO,CAACK,MAAM,GAAG,CAAC,EAAE;IACpB,MAAM,CAACC,SAAS,CAAC,GAAG,MAAMf,WAAW,CAACC,KAAK,CAACe,SAAS,CAAC;MAAEC,GAAG,EAAER;IA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,CAACC,OAAO,CAACP,IAAI,CAAC;EAClC,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGE,KAAK,CAAC5C,MAAM,EAAE0C,CAAC,EAAE,EAAE;IACnC,MAAM,CAACK,GAAG,EAAEC,KAAK,CAAC,GAAGJ,KAAK,CAACF,CAAC,CAAC;IAC7B;IACA,IAAIK,GAAG,KAAK,MAAM,IAAIC,KAAK,EAAE;MACzB7D,KAAK,CAACiB,IAAI,CAAC4C,KAAK,CAAC;IACrB,CAAC,MAAM,IAAID,GAAG,KAAK,QAAQ,IAAIP,KAAK,CAACC,OAAO,CAACO,KAAK,CAAC,EAAE;MACjD;MACA7D,KAAK,CAACiB,IAAI,CAAC,GAAG4C,KAAK,CAAC;IACxB,CAAC,MAAM;MACH5D,oBAAoB,CAAC4D,KAAK,EAAE7D,KAAK,CAAC;IACtC;EACJ;EACA,OAAOA,KAAK;AAChB"}
|
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","ids","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({ ids: 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({ ids: 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({ ids: 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,MAAMC,uBAAuB,GAAG,uBAAuB;AAAC;AAOxD,eAAeC,UAAU,CAC5BC,IAAU,EACVC,kBAA0B,EAC1BC,WAA8C,EACZ;EAClC;EACA,MAAMC,KAAK,GAAGC,oBAAoB,CAACJ,IAAI,CAACK,OAAO,IAAI,CAAC,CAAC,CAAC;EACtD;EACA,MAAMC,kBAAkB,GAAG,CACvB,IAAA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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;MACR/B,KAAK,EAAE,EAAE;MACTgC,IAAI,EAAEgC,IAAI,CAAChC,IAAI;MACfC,UAAU,EAAEoC;IAChB,CAAC;IACDnC,cAAc,EAAE+B;EACpB,CAAC,CAAC;EAEF,OAAOpC,MAAM,CAACM,OAAO,EAAE;AAC3B"}
|
package/export/zipper.js
CHANGED
@@ -32,7 +32,7 @@ class Zipper {
|
|
32
32
|
}) => {
|
33
33
|
return {
|
34
34
|
stream: _s3Stream.s3Stream.readStream(key),
|
35
|
-
filename: `${prefix}\\${this.filesDirName}\\${
|
35
|
+
filename: `${prefix}\\${this.filesDirName}\\${key}`
|
36
36
|
};
|
37
37
|
});
|
38
38
|
return [...files, {
|
@@ -80,7 +80,7 @@ class ZipOfZip {
|
|
80
80
|
(0, _defineProperty2.default)(this, "filename", void 0);
|
81
81
|
this.keys = keys;
|
82
82
|
this.filename = filename;
|
83
|
-
this.archiveFileName = (0, _uniqid.default)("", `-${filename}`);
|
83
|
+
this.archiveFileName = (0, _uniqid.default)("EXPORTS/", `-${filename}`);
|
84
84
|
}
|
85
85
|
getFileStreams() {
|
86
86
|
return this.keys.map(key => {
|
package/export/zipper.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Zipper","constructor","config","archiveFileName","uniqueId","archiveFileKey","kebabCase","exportInfo","name","s3DownloadStreams","prefix","files","map","key","stream","s3Stream","readStream","filename","filesDirName","
|
1
|
+
{"version":3,"names":["Zipper","constructor","config","archiveFileName","uniqueId","archiveFileKey","kebabCase","exportInfo","name","s3DownloadStreams","prefix","files","map","key","stream","s3Stream","readStream","filename","filesDirName","Readable","from","dataBuffer","process","streamPassThrough","streamPassThroughUploadPromise","writeStream","s3FilesStreams","archive","vending","create","archiveFormat","on","error","Error","code","message","path","stack","forEach","streamDetails","append","pipe","finalize","ZipOfZip","keys","getFileStreams","basename","fileStreamDetails"],"sources":["zipper.ts"],"sourcesContent":["// TODO: Move \"archive\" in layer\nimport vending, { ArchiverError } from \"archiver\";\nimport S3 from \"aws-sdk/clients/s3\";\nimport { Readable } from \"stream\";\nimport * as path from \"path\";\nimport kebabCase from \"lodash/kebabCase\";\nimport uniqueId from \"uniqid\";\nimport { s3Stream } from \"./s3Stream\";\nimport { File } from \"@webiny/api-file-manager/types\";\n\ninterface FileStreamDetails {\n stream: Readable;\n filename: string;\n}\n\ninterface ExportInfo {\n files: File[];\n name: string;\n dataBuffer: Buffer;\n}\n\nexport interface ZipperConfig {\n exportInfo: ExportInfo;\n archiveFileKey: string;\n}\n\nexport default class Zipper {\n private readonly archiveFormat = \"zip\";\n private readonly filesDirName = \"assets\";\n private readonly archiveFileName: string;\n config: ZipperConfig;\n\n constructor(config: ZipperConfig) {\n this.config = config;\n this.archiveFileName = uniqueId(\n `${this.config.archiveFileKey}/`,\n `-${kebabCase(this.config.exportInfo.name)}.zip`\n );\n }\n\n s3DownloadStreams(): FileStreamDetails[] {\n const exportInfo = this.config.exportInfo;\n const prefix = uniqueId(\"\", `-${kebabCase(exportInfo.name)}`);\n const files = exportInfo.files.map(({ key }) => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${prefix}\\\\${this.filesDirName}\\\\${key}`\n };\n });\n\n return [\n ...files,\n {\n stream: Readable.from(exportInfo.dataBuffer),\n filename: `${prefix}\\\\${exportInfo.name}.json`\n }\n ];\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const s3FilesStreams = this.s3DownloadStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n s3FilesStreams.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n\nexport class ZipOfZip {\n private readonly archiveFormat = \"zip\";\n private readonly archiveFileName: string;\n keys: string[];\n filename: string;\n\n constructor(keys: string[], filename: string) {\n this.keys = keys;\n this.filename = filename;\n this.archiveFileName = uniqueId(\"EXPORTS/\", `-${filename}`);\n }\n\n getFileStreams(): FileStreamDetails[] {\n return this.keys.map(key => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${path.basename(key)}`\n };\n });\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const fileStreamDetails = this.getFileStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n fileStreamDetails.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n"],"mappings":";;;;;;;;;AACA;AAEA;AACA;AACA;AACA;AACA;AAPA;;AA0Be,MAAMA,MAAM,CAAC;EAMxBC,WAAW,CAACC,MAAoB,EAAE;IAAA,qDALD,KAAK;IAAA,oDACN,QAAQ;IAAA;IAAA;IAKpC,IAAI,CAACA,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,eAAe,GAAG,IAAAC,eAAQ,EAC1B,GAAE,IAAI,CAACF,MAAM,CAACG,cAAe,GAAE,EAC/B,IAAG,IAAAC,kBAAS,EAAC,IAAI,CAACJ,MAAM,CAACK,UAAU,CAACC,IAAI,CAAE,MAAK,CACnD;EACL;EAEAC,iBAAiB,GAAwB;IACrC,MAAMF,UAAU,GAAG,IAAI,CAACL,MAAM,CAACK,UAAU;IACzC,MAAMG,MAAM,GAAG,IAAAN,eAAQ,EAAC,EAAE,EAAG,IAAG,IAAAE,kBAAS,EAACC,UAAU,CAACC,IAAI,CAAE,EAAC,CAAC;IAC7D,MAAMG,KAAK,GAAGJ,UAAU,CAACI,KAAK,CAACC,GAAG,CAAC,CAAC;MAAEC;IAAI,CAAC,KAAK;MAC5C,OAAO;QACHC,MAAM,EAAEC,kBAAQ,CAACC,UAAU,CAACH,GAAG,CAAC;QAChCI,QAAQ,EAAG,GAAEP,MAAO,KAAI,IAAI,CAACQ,YAAa,KAAIL,GAAI;MACtD,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,CACH,GAAGF,KAAK,EACR;MACIG,MAAM,EAAEK,gBAAQ,CAACC,IAAI,CAACb,UAAU,CAACc,UAAU,CAAC;MAC5CJ,QAAQ,EAAG,GAAEP,MAAO,KAAIH,UAAU,CAACC,IAAK;IAC5C,C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AO;QACHC,MAAM,EAAEC,kBAAQ,CAACC,UAAU,CAACH,GAAG,CAAC;QAChCI,QAAQ,EAAG,GAAEmB,IAAI,CAACU,QAAQ,CAACjC,GAAG,CAAE;MACpC,CAAC;IACL,CAAC,CAAC;EACN;EAEAS,OAAO,GAAuC;IAC1C,MAAM;MAAEC,iBAAiB;MAAEC;IAA+B,CAAC,GAAGT,kBAAQ,CAACU,WAAW,CAC9E,IAAI,CAACtB,eAAe,CACvB;;IAED;IACA,MAAM4C,iBAAiB,GAAG,IAAI,CAACF,cAAc,EAAE;;IAE/C;IACA,MAAMlB,OAAO,GAAGC,iBAAO,CAACC,MAAM,CAAC,IAAI,CAACC,aAAa,CAAC;IAClD;IACAH,OAAO,CAACI,EAAE,CAAC,OAAO,EAAGC,KAAoB,IAAK;MAC1C,MAAM,IAAIC,KAAK,CACV,GAAED,KAAK,CAACxB,IAAK,IAAGwB,KAAK,CAACE,IAAK,IAAGF,KAAK,CAACG,OAAQ,IAAGH,KAAK,CAACI,IAAK,IAAGJ,KAAK,CAACK,KAAM,EAAC,CAC9E;IACL,CAAC,CAAC;;IAEF;IACAU,iBAAiB,CAACT,OAAO,CAAEC,aAAgC,IACvDZ,OAAO,CAACa,MAAM,CAACD,aAAa,CAACzB,MAAM,EAAE;MAAEN,IAAI,EAAE+B,aAAa,CAACtB;IAAS,CAAC,CAAC,CACzE;;IAED;IACAU,OAAO,CAACc,IAAI,CAAClB,iBAAiB,CAAC;IAC/B;IACA;IACAI,OAAO,CAACe,QAAQ,EAAE;;IAElB;IACA,OAAOlB,8BAA8B;EACzC;AACJ;AAAC"}
|
@@ -72,12 +72,11 @@ var _default = new _api.ContextPlugin(context => {
|
|
72
72
|
let blockIds = initialBlockIds || [];
|
73
73
|
// If no ids are provided then it means we want to export all blocks
|
74
74
|
if (!initialBlockIds || Array.isArray(initialBlockIds) && initialBlockIds.length === 0) {
|
75
|
-
blockIds = [];
|
76
75
|
const blocks = await context.pageBuilder.listPageBlocks({
|
77
76
|
where
|
78
77
|
});
|
79
78
|
// Save block ids
|
80
|
-
blocks.
|
79
|
+
blockIds = blocks.map(block => block.id);
|
81
80
|
}
|
82
81
|
if (blockIds.length === 0) {
|
83
82
|
throw new _error.default("Cannot export blocks - no blocks found for provided inputs.", "EMPTY_EXPORT_NO_BLOCKS_FOUND");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["PERMISSION_NAME","EXPORT_BLOCKS_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_BLOCKS_CREATE_HANDLER","IMPORT_CREATE_HANDLER","ContextPlugin","context","importExportCrud","importBlocks","category","categorySlug","zipFileUrl","checkBasePermissions","rwd","pageBuilder","getBlockCategory","NotFoundError","task","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","invokeHandlerClient","name","payload","type","identity","security","getIdentity","description","exportBlocks","ids","initialBlockIds","where","blockIds","Array","isArray","length","blocks","listPageBlocks","
|
1
|
+
{"version":3,"names":["PERMISSION_NAME","EXPORT_BLOCKS_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_BLOCKS_CREATE_HANDLER","IMPORT_CREATE_HANDLER","ContextPlugin","context","importExportCrud","importBlocks","category","categorySlug","zipFileUrl","checkBasePermissions","rwd","pageBuilder","getBlockCategory","NotFoundError","task","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","invokeHandlerClient","name","payload","type","identity","security","getIdentity","description","exportBlocks","ids","initialBlockIds","where","blockIds","Array","isArray","length","blocks","listPageBlocks","map","block","id","WebinyError","exportBlocksDataKey","EXPORT_BLOCKS_FOLDER_KEY","i","blockId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex"],"sources":["blocks.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport checkBasePermissions from \"@webiny/api-page-builder/graphql/crud/utils/checkBasePermissions\";\nimport { ImportExportTaskStatus, BlocksImportExportCrud, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { Payload as CreateHandlerPayload } from \"~/import/create\";\nimport { initialStats } from \"~/import/utils\";\nimport { Payload as ExportBlocksProcessHandlerPayload } from \"~/export/process\";\nimport { EXPORT_BLOCKS_FOLDER_KEY } from \"~/export/utils\";\nimport { zeroPad } from \"@webiny/utils\";\n\nconst PERMISSION_NAME = \"pb.block\";\nconst EXPORT_BLOCKS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER as string;\nconst IMPORT_BLOCKS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER as string;\n\nexport default new ContextPlugin<PbImportExportContext>(context => {\n const importExportCrud: BlocksImportExportCrud = {\n async importBlocks({ category: categorySlug, zipFileUrl }) {\n await checkBasePermissions(context, PERMISSION_NAME, {\n rwd: \"w\"\n });\n\n // Bail out early if category not found\n const category = await context.pageBuilder.getBlockCategory(categorySlug);\n if (!category) {\n throw new NotFoundError(`Category with slug \"${categorySlug}\" not found.`);\n }\n\n // Create a task for import block\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING,\n input: {\n category: categorySlug,\n zipFileUrl\n }\n });\n /**\n * Import Blocks\n * ImportBlocks\n * importBlocks\n */\n await invokeHandlerClient<CreateHandlerPayload>({\n context,\n name: IMPORT_BLOCKS_CREATE_HANDLER,\n payload: {\n category: categorySlug,\n zipFileUrl,\n task,\n type: \"block\",\n identity: context.security.getIdentity()\n },\n description: \"Import Blocks - create\"\n });\n\n return {\n task\n };\n },\n\n async exportBlocks({ ids: initialBlockIds, where }) {\n await checkBasePermissions(context, PERMISSION_NAME, {\n rwd: \"w\"\n });\n let blockIds: string[] = initialBlockIds || [];\n // If no ids are provided then it means we want to export all blocks\n if (\n !initialBlockIds ||\n (Array.isArray(initialBlockIds) && initialBlockIds.length === 0)\n ) {\n const blocks = await context.pageBuilder.listPageBlocks({ where });\n // Save block ids\n blockIds = blocks.map(block => block.id);\n }\n\n if (blockIds.length === 0) {\n throw new WebinyError(\n \"Cannot export blocks - no blocks found for provided inputs.\",\n \"EMPTY_EXPORT_NO_BLOCKS_FOUND\"\n );\n }\n\n // Create the main task for blocks export.\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING\n });\n const exportBlocksDataKey = `${EXPORT_BLOCKS_FOLDER_KEY}/${task.id}`;\n // For each block create a sub task and invoke the process handler.\n for (let i = 0; i < blockIds.length; i++) {\n const blockId = blockIds[i];\n // Create sub task.\n await context.pageBuilder.importExportTask.createSubTask(\n task.id,\n zeroPad(i + 1, 5),\n {\n status: ImportExportTaskStatus.PENDING,\n input: {\n blockId,\n exportBlocksDataKey\n }\n }\n );\n }\n // Update main task status.\n await context.pageBuilder.importExportTask.updateTask(task.id, {\n status: ImportExportTaskStatus.PROCESSING,\n stats: initialStats(blockIds.length),\n input: {\n exportBlocksDataKey\n }\n });\n\n /**\n * Export Blocks\n * ExportBlocks\n * exportBlocks\n */\n // Invoke handler.\n await invokeHandlerClient<ExportBlocksProcessHandlerPayload>({\n context,\n name: EXPORT_BLOCKS_PROCESS_HANDLER,\n payload: {\n taskId: task.id,\n subTaskIndex: 1,\n type: \"block\",\n identity: context.security.getIdentity()\n },\n description: \"Export blocks - process\"\n });\n\n return { task };\n }\n };\n // Modify context\n context.pageBuilder.blocks = importExportCrud;\n});\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AAEA,MAAMA,eAAe,GAAG,UAAU;AAClC,MAAMC,6BAA6B,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAgC;AAClF,MAAMC,4BAA4B,GAAGH,OAAO,CAACC,GAAG,CAACG,qBAA+B;AAAC,eAElE,IAAIC,kBAAa,CAAwBC,OAAO,IAAI;EAC/D,MAAMC,gBAAwC,GAAG;IAC7C,MAAMC,YAAY,CAAC;MAAEC,QAAQ,EAAEC,YAAY;MA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tB,2BAAmB,EAAoC;QACzDlB,OAAO;QACPmB,IAAI,EAAE1B,6BAA6B;QACnC2B,OAAO,EAAE;UACL8B,MAAM,EAAEvC,IAAI,CAAC2B,EAAE;UACfa,YAAY,EAAE,CAAC;UACf9B,IAAI,EAAE,OAAO;UACbC,QAAQ,EAAEtB,OAAO,CAACuB,QAAQ,CAACC,WAAW;QAC1C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;MAEF,OAAO;QAAEd;MAAK,CAAC;IACnB;EACJ,CAAC;EACD;EACAX,OAAO,CAACQ,WAAW,CAAC0B,MAAM,GAAGjC,gBAAgB;AACjD,CAAC,CAAC;AAAA"}
|
@@ -0,0 +1,129 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.default = void 0;
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
9
|
+
var _api = require("@webiny/api");
|
10
|
+
var _utils = require("@webiny/api-form-builder/plugins/crud/utils");
|
11
|
+
var _types = require("../../types");
|
12
|
+
var _client = require("../../client");
|
13
|
+
var _utils2 = require("../../import/utils");
|
14
|
+
var _utils3 = require("../../export/utils");
|
15
|
+
var _utils4 = require("@webiny/utils");
|
16
|
+
const EXPORT_FORMS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER;
|
17
|
+
const IMPORT_FORMS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER;
|
18
|
+
var _default = new _api.ContextPlugin(context => {
|
19
|
+
context.waitFor("formBuilder", () => {
|
20
|
+
const importExportCrud = {
|
21
|
+
async importForms({
|
22
|
+
zipFileUrl
|
23
|
+
}) {
|
24
|
+
await (0, _utils.checkBaseFormPermissions)(context, {
|
25
|
+
rwd: "w"
|
26
|
+
});
|
27
|
+
|
28
|
+
// Create a task for import form
|
29
|
+
const task = await context.pageBuilder.importExportTask.createTask({
|
30
|
+
status: _types.ImportExportTaskStatus.PENDING,
|
31
|
+
input: {
|
32
|
+
zipFileUrl
|
33
|
+
}
|
34
|
+
});
|
35
|
+
/**
|
36
|
+
* Import Forms
|
37
|
+
* ImportForms
|
38
|
+
* importForms
|
39
|
+
*/
|
40
|
+
await (0, _client.invokeHandlerClient)({
|
41
|
+
context,
|
42
|
+
name: IMPORT_FORMS_CREATE_HANDLER,
|
43
|
+
payload: {
|
44
|
+
zipFileUrl,
|
45
|
+
task,
|
46
|
+
type: "form",
|
47
|
+
identity: context.security.getIdentity()
|
48
|
+
},
|
49
|
+
description: "Import Forms - create"
|
50
|
+
});
|
51
|
+
return {
|
52
|
+
task
|
53
|
+
};
|
54
|
+
},
|
55
|
+
async exportForms({
|
56
|
+
ids: initialFormIds,
|
57
|
+
revisionType
|
58
|
+
}) {
|
59
|
+
await (0, _utils.checkBaseFormPermissions)(context, {
|
60
|
+
rwd: "w"
|
61
|
+
});
|
62
|
+
let formIds = initialFormIds || [];
|
63
|
+
// If no ids are provided then it means we want to export all forms
|
64
|
+
if (!initialFormIds || Array.isArray(initialFormIds) && initialFormIds.length === 0) {
|
65
|
+
formIds = [];
|
66
|
+
const forms = await context.formBuilder.listForms();
|
67
|
+
|
68
|
+
// Save form ids
|
69
|
+
forms.forEach(form => formIds.push(form.id));
|
70
|
+
}
|
71
|
+
if (formIds.length === 0) {
|
72
|
+
throw new _error.default("Cannot export forms - no forms found for provided inputs.", "EMPTY_EXPORT_NO_FORMS_FOUND");
|
73
|
+
}
|
74
|
+
|
75
|
+
// Create the main task for form export.
|
76
|
+
const task = await context.pageBuilder.importExportTask.createTask({
|
77
|
+
status: _types.ImportExportTaskStatus.PENDING
|
78
|
+
});
|
79
|
+
const exportFormsDataKey = `${_utils3.EXPORT_FORMS_FOLDER_KEY}/${task.id}`;
|
80
|
+
// For each form create a sub task and invoke the process handler.
|
81
|
+
for (let i = 0; i < formIds.length; i++) {
|
82
|
+
const formId = formIds[i];
|
83
|
+
// Create sub task.
|
84
|
+
await context.pageBuilder.importExportTask.createSubTask(task.id, (0, _utils4.zeroPad)(i + 1, 5), {
|
85
|
+
status: _types.ImportExportTaskStatus.PENDING,
|
86
|
+
input: {
|
87
|
+
formId,
|
88
|
+
exportFormsDataKey,
|
89
|
+
revisionType
|
90
|
+
}
|
91
|
+
});
|
92
|
+
}
|
93
|
+
// Update main task status.
|
94
|
+
await context.pageBuilder.importExportTask.updateTask(task.id, {
|
95
|
+
status: _types.ImportExportTaskStatus.PROCESSING,
|
96
|
+
stats: (0, _utils2.initialStats)(formIds.length),
|
97
|
+
input: {
|
98
|
+
exportFormsDataKey,
|
99
|
+
revisionType
|
100
|
+
}
|
101
|
+
});
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Export Forms
|
105
|
+
* ExportForms
|
106
|
+
* exportForms
|
107
|
+
*/
|
108
|
+
// Invoke handler.
|
109
|
+
await (0, _client.invokeHandlerClient)({
|
110
|
+
context,
|
111
|
+
name: EXPORT_FORMS_PROCESS_HANDLER,
|
112
|
+
payload: {
|
113
|
+
taskId: task.id,
|
114
|
+
subTaskIndex: 1,
|
115
|
+
type: "form",
|
116
|
+
identity: context.security.getIdentity()
|
117
|
+
},
|
118
|
+
description: "Export forms - process"
|
119
|
+
});
|
120
|
+
return {
|
121
|
+
task
|
122
|
+
};
|
123
|
+
}
|
124
|
+
};
|
125
|
+
// Modify context
|
126
|
+
context.formBuilder.forms = importExportCrud;
|
127
|
+
});
|
128
|
+
});
|
129
|
+
exports.default = _default;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["EXPORT_FORMS_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_FORMS_CREATE_HANDLER","IMPORT_CREATE_HANDLER","ContextPlugin","context","waitFor","importExportCrud","importForms","zipFileUrl","checkBaseFormPermissions","rwd","task","pageBuilder","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","invokeHandlerClient","name","payload","type","identity","security","getIdentity","description","exportForms","ids","initialFormIds","revisionType","formIds","Array","isArray","length","forms","formBuilder","listForms","forEach","form","push","id","WebinyError","exportFormsDataKey","EXPORT_FORMS_FOLDER_KEY","i","formId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex"],"sources":["forms.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { checkBaseFormPermissions } from \"@webiny/api-form-builder/plugins/crud/utils\";\nimport { ImportExportTaskStatus, FormsImportExportCrud, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { Payload as CreateHandlerPayload } from \"~/import/create\";\nimport { initialStats } from \"~/import/utils\";\nimport { Payload as ExportFormsProcessHandlerPayload } from \"~/export/process\";\nimport { EXPORT_FORMS_FOLDER_KEY } from \"~/export/utils\";\nimport { zeroPad } from \"@webiny/utils\";\n\nconst EXPORT_FORMS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER as string;\nconst IMPORT_FORMS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER as string;\n\nexport default new ContextPlugin<PbImportExportContext>(context => {\n context.waitFor(\"formBuilder\", () => {\n const importExportCrud: FormsImportExportCrud = {\n async importForms({ zipFileUrl }) {\n await checkBaseFormPermissions(context, {\n rwd: \"w\"\n });\n\n // Create a task for import form\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING,\n input: {\n zipFileUrl\n }\n });\n /**\n * Import Forms\n * ImportForms\n * importForms\n */\n await invokeHandlerClient<CreateHandlerPayload>({\n context,\n name: IMPORT_FORMS_CREATE_HANDLER,\n payload: {\n zipFileUrl,\n task,\n type: \"form\",\n identity: context.security.getIdentity()\n },\n description: \"Import Forms - create\"\n });\n\n return {\n task\n };\n },\n\n async exportForms({ ids: initialFormIds, revisionType }) {\n await checkBaseFormPermissions(context, {\n rwd: \"w\"\n });\n let formIds: string[] = initialFormIds || [];\n // If no ids are provided then it means we want to export all forms\n if (\n !initialFormIds ||\n (Array.isArray(initialFormIds) && initialFormIds.length === 0)\n ) {\n formIds = [];\n\n const forms = await context.formBuilder.listForms();\n\n // Save form ids\n forms.forEach(form => formIds.push(form.id));\n }\n\n if (formIds.length === 0) {\n throw new WebinyError(\n \"Cannot export forms - no forms found for provided inputs.\",\n \"EMPTY_EXPORT_NO_FORMS_FOUND\"\n );\n }\n\n // Create the main task for form export.\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING\n });\n const exportFormsDataKey = `${EXPORT_FORMS_FOLDER_KEY}/${task.id}`;\n // For each form create a sub task and invoke the process handler.\n for (let i = 0; i < formIds.length; i++) {\n const formId = formIds[i];\n // Create sub task.\n await context.pageBuilder.importExportTask.createSubTask(\n task.id,\n zeroPad(i + 1, 5),\n {\n status: ImportExportTaskStatus.PENDING,\n input: {\n formId,\n exportFormsDataKey,\n revisionType\n }\n }\n );\n }\n // Update main task status.\n await context.pageBuilder.importExportTask.updateTask(task.id, {\n status: ImportExportTaskStatus.PROCESSING,\n stats: initialStats(formIds.length),\n input: {\n exportFormsDataKey,\n revisionType\n }\n });\n\n /**\n * Export Forms\n * ExportForms\n * exportForms\n */\n // Invoke handler.\n await invokeHandlerClient<ExportFormsProcessHandlerPayload>({\n context,\n name: EXPORT_FORMS_PROCESS_HANDLER,\n payload: {\n taskId: task.id,\n subTaskIndex: 1,\n type: \"form\",\n identity: context.security.getIdentity()\n },\n description: \"Export forms - process\"\n });\n\n return { task };\n }\n };\n // Modify context\n context.formBuilder.forms = importExportCrud;\n });\n});\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AAEA,MAAMA,4BAA4B,GAAGC,OAAO,CAACC,GAAG,CAACC,sBAAgC;AACjF,MAAMC,2BAA2B,GAAGH,OAAO,CAACC,GAAG,CAACG,qBAA+B;AAAC,eAEjE,IAAIC,kBAAa,CAAwBC,OAAO,IAA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B,EAAE;YACfa,YAAY,EAAE,CAAC;YACfhC,IAAI,EAAE,MAAM;YACZC,QAAQ,EAAEnB,OAAO,CAACoB,QAAQ,CAACC,WAAW;UAC1C,CAAC;UACDC,WAAW,EAAE;QACjB,CAAC,CAAC;QAEF,OAAO;UAAEf;QAAK,CAAC;MACnB;IACJ,CAAC;IACD;IACAP,OAAO,CAACgC,WAAW,CAACD,KAAK,GAAG7B,gBAAgB;EAChD,CAAC,CAAC;AACN,CAAC,CAAC;AAAA"}
|
package/graphql/crud.js
CHANGED
@@ -6,8 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
});
|
7
7
|
exports.default = void 0;
|
8
8
|
var _blocks = _interopRequireDefault(require("./crud/blocks.crud"));
|
9
|
+
var _forms = _interopRequireDefault(require("./crud/forms.crud"));
|
9
10
|
var _pages = _interopRequireDefault(require("./crud/pages.crud"));
|
10
11
|
var _templates = _interopRequireDefault(require("./crud/templates.crud"));
|
11
12
|
var _importExportTasks = _interopRequireDefault(require("./crud/importExportTasks.crud"));
|
12
|
-
var _default = params => [_blocks.default, _pages.default, _templates.default, (0, _importExportTasks.default)(params)];
|
13
|
+
var _default = params => [_blocks.default, _forms.default, _pages.default, _templates.default, (0, _importExportTasks.default)(params)];
|
13
14
|
exports.default = _default;
|
package/graphql/crud.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["params","blocks","pages","templates","importExportTask"],"sources":["crud.ts"],"sourcesContent":["import blocks from \"./crud/blocks.crud\";\nimport pages from \"./crud/pages.crud\";\nimport templates from \"./crud/templates.crud\";\nimport importExportTask from \"./crud/importExportTasks.crud\";\nimport { ImportExportPluginsParams } from \"~/graphql/types\";\n\nexport default (params: ImportExportPluginsParams) => [\n blocks,\n pages,\n templates,\n importExportTask(params as ImportExportPluginsParams)\n];\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AAA6D,eAG7CA,MAAiC,IAAK,CAClDC,eAAM,EACNC,cAAK,EACLC,kBAAS,EACT,IAAAC,0BAAgB,
|
1
|
+
{"version":3,"names":["params","blocks","forms","pages","templates","importExportTask"],"sources":["crud.ts"],"sourcesContent":["import blocks from \"./crud/blocks.crud\";\nimport forms from \"./crud/forms.crud\";\nimport pages from \"./crud/pages.crud\";\nimport templates from \"./crud/templates.crud\";\nimport importExportTask from \"./crud/importExportTasks.crud\";\nimport { ImportExportPluginsParams } from \"~/graphql/types\";\n\nexport default (params: ImportExportPluginsParams) => [\n blocks,\n forms,\n pages,\n templates,\n importExportTask(params as ImportExportPluginsParams)\n];\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AAA6D,eAG7CA,MAAiC,IAAK,CAClDC,eAAM,EACNC,cAAK,EACLC,cAAK,EACLC,kBAAS,EACT,IAAAC,0BAAgB,EAACL,MAAM,CAA8B,CACxD;AAAA"}
|
@@ -0,0 +1,60 @@
|
|
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 _resolve = _interopRequireDefault(require("./utils/resolve"));
|
9
|
+
const plugin = {
|
10
|
+
type: "graphql-schema",
|
11
|
+
schema: {
|
12
|
+
typeDefs: /* GraphQL */`
|
13
|
+
type FbExportFormData {
|
14
|
+
task: PbImportExportTask
|
15
|
+
}
|
16
|
+
|
17
|
+
type FbExportFormResponse {
|
18
|
+
data: FbExportFormData
|
19
|
+
error: FbError
|
20
|
+
}
|
21
|
+
|
22
|
+
type FbImportFormData {
|
23
|
+
task: PbImportExportTask
|
24
|
+
}
|
25
|
+
|
26
|
+
type FbImportFormResponse {
|
27
|
+
data: FbImportFormData
|
28
|
+
error: FbError
|
29
|
+
}
|
30
|
+
|
31
|
+
enum FbExportFormRevisionType {
|
32
|
+
published
|
33
|
+
latest
|
34
|
+
}
|
35
|
+
|
36
|
+
extend type FbMutation {
|
37
|
+
# Export forms
|
38
|
+
exportForms(
|
39
|
+
ids: [ID!]
|
40
|
+
revisionType: FbExportFormRevisionType!
|
41
|
+
): FbExportFormResponse
|
42
|
+
|
43
|
+
# Import forms
|
44
|
+
importForms(zipFileUrl: String, meta: JSON): FbImportFormResponse
|
45
|
+
}
|
46
|
+
`,
|
47
|
+
resolvers: {
|
48
|
+
FbMutation: {
|
49
|
+
exportForms: async (_, args, context) => {
|
50
|
+
return (0, _resolve.default)(() => context.formBuilder.forms.exportForms(args));
|
51
|
+
},
|
52
|
+
importForms: async (_, args, context) => {
|
53
|
+
return (0, _resolve.default)(() => context.formBuilder.forms.importForms(args));
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
};
|
59
|
+
var _default = plugin;
|
60
|
+
exports.default = _default;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["plugin","type","schema","typeDefs","resolvers","FbMutation","exportForms","_","args","context","resolve","formBuilder","forms","importForms"],"sources":["forms.gql.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\nimport { PbImportExportContext } from \"../types\";\nimport resolve from \"./utils/resolve\";\n\nconst plugin: GraphQLSchemaPlugin<PbImportExportContext> = {\n type: \"graphql-schema\",\n schema: {\n typeDefs: /* GraphQL */ `\n type FbExportFormData {\n task: PbImportExportTask\n }\n\n type FbExportFormResponse {\n data: FbExportFormData\n error: FbError\n }\n\n type FbImportFormData {\n task: PbImportExportTask\n }\n\n type FbImportFormResponse {\n data: FbImportFormData\n error: FbError\n }\n\n enum FbExportFormRevisionType {\n published\n latest\n }\n\n extend type FbMutation {\n # Export forms\n exportForms(\n ids: [ID!]\n revisionType: FbExportFormRevisionType!\n ): FbExportFormResponse\n\n # Import forms\n importForms(zipFileUrl: String, meta: JSON): FbImportFormResponse\n }\n `,\n resolvers: {\n FbMutation: {\n exportForms: async (_, args: any, context) => {\n return resolve(() => context.formBuilder.forms.exportForms(args));\n },\n\n importForms: async (_, args: any, context) => {\n return resolve(() => context.formBuilder.forms.importForms(args));\n }\n }\n }\n }\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;AAEA;AAEA,MAAMA,MAAkD,GAAG;EACvDC,IAAI,EAAE,gBAAgB;EACtBC,MAAM,EAAE;IACJC,QAAQ,EAAE,aAAe;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;IACDC,SAAS,EAAE;MACPC,UAAU,EAAE;QACRC,WAAW,EAAE,OAAOC,CAAC,EAAEC,IAAS,EAAEC,OAAO,KAAK;UAC1C,OAAO,IAAAC,gBAAO,EAAC,MAAMD,OAAO,CAACE,WAAW,CAACC,KAAK,CAACN,WAAW,CAACE,IAAI,CAAC,CAAC;QACrE,CAAC;QAEDK,WAAW,EAAE,OAAON,CAAC,EAAEC,IAAS,EAAEC,OAAO,KAAK;UAC1C,OAAO,IAAAC,gBAAO,EAAC,MAAMD,OAAO,CAACE,WAAW,CAACC,KAAK,CAACC,WAAW,CAACL,IAAI,CAAC,CAAC;QACrE;MACJ;IACJ;EACJ;AACJ,CAAC;AAAC,eAEaR,MAAM;AAAA"}
|
package/graphql/graphql.js
CHANGED
@@ -6,8 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
});
|
7
7
|
exports.default = void 0;
|
8
8
|
var _blocks = _interopRequireDefault(require("./graphql/blocks.gql"));
|
9
|
+
var _forms = _interopRequireDefault(require("./graphql/forms.gql"));
|
9
10
|
var _pages = _interopRequireDefault(require("./graphql/pages.gql"));
|
10
11
|
var _templates = _interopRequireDefault(require("./graphql/templates.gql"));
|
11
12
|
var _importExportTasks = _interopRequireDefault(require("./graphql/importExportTasks.gql"));
|
12
|
-
var _default = [_blocks.default, _pages.default, _templates.default, _importExportTasks.default];
|
13
|
+
var _default = [_blocks.default, _forms.default, _pages.default, _templates.default, _importExportTasks.default];
|
13
14
|
exports.default = _default;
|
package/graphql/graphql.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["blocks","pages","templates","importExportTask"],"sources":["graphql.ts"],"sourcesContent":["import blocks from \"./graphql/blocks.gql\";\nimport pages from \"./graphql/pages.gql\";\nimport templates from \"./graphql/templates.gql\";\nimport importExportTask from \"./graphql/importExportTasks.gql\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\n\nexport default [blocks, pages, templates, importExportTask] as GraphQLSchemaPlugin[];\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AAA+D,eAGhD,CAACA,eAAM,EAAEC,cAAK,EAAEC,kBAAS,EAAEC,0BAAgB,CAAC;AAAA"}
|
1
|
+
{"version":3,"names":["blocks","forms","pages","templates","importExportTask"],"sources":["graphql.ts"],"sourcesContent":["import blocks from \"./graphql/blocks.gql\";\nimport forms from \"./graphql/forms.gql\";\nimport pages from \"./graphql/pages.gql\";\nimport templates from \"./graphql/templates.gql\";\nimport importExportTask from \"./graphql/importExportTasks.gql\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\n\nexport default [blocks, forms, pages, templates, importExportTask] as GraphQLSchemaPlugin[];\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AAA+D,eAGhD,CAACA,eAAM,EAAEC,cAAK,EAAEC,cAAK,EAAEC,kBAAS,EAAEC,0BAAgB,CAAC;AAAA"}
|
package/graphql/types.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { PbContext } from "@webiny/api-page-builder/types";
|
2
|
+
import { FormBuilderContext } from "@webiny/api-form-builder/types";
|
2
3
|
import { ExportRevisionType, ImportExportTask, ImportExportTaskStatus, ImportExportTaskStorageOperations, ImportExportTaskStorageOperationsListParams } from "../types";
|
3
4
|
export interface ExportPagesParams {
|
4
5
|
ids?: string[];
|
@@ -64,6 +65,25 @@ export declare type TemplatesImportExportCrud = {
|
|
64
65
|
task: ImportExportTask;
|
65
66
|
}>;
|
66
67
|
};
|
68
|
+
export interface ExportFormsParams {
|
69
|
+
ids?: string[];
|
70
|
+
revisionType: ExportRevisionType;
|
71
|
+
search?: {
|
72
|
+
query?: string;
|
73
|
+
};
|
74
|
+
sort?: string[];
|
75
|
+
}
|
76
|
+
export interface ImportFormsParams {
|
77
|
+
zipFileUrl: string;
|
78
|
+
}
|
79
|
+
export declare type FormsImportExportCrud = {
|
80
|
+
exportForms(params: ExportFormsParams): Promise<{
|
81
|
+
task: ImportExportTask;
|
82
|
+
}>;
|
83
|
+
importForms(params: ImportFormsParams): Promise<{
|
84
|
+
task: ImportExportTask;
|
85
|
+
}>;
|
86
|
+
};
|
67
87
|
declare type ImportExportTaskCreateData = Omit<ImportExportTask, "id" | "createdOn" | "createdBy">;
|
68
88
|
export declare type ImportExportTaskCrud = {
|
69
89
|
/**
|
@@ -92,6 +112,9 @@ export interface PbImportExportContext extends PbContext {
|
|
92
112
|
templates: TemplatesImportExportCrud;
|
93
113
|
importExportTask: ImportExportTaskCrud;
|
94
114
|
};
|
115
|
+
formBuilder: FormBuilderContext["formBuilder"] & {
|
116
|
+
forms: FormsImportExportCrud;
|
117
|
+
};
|
95
118
|
}
|
96
119
|
export interface ImportExportPluginsParams {
|
97
120
|
storageOperations: ImportExportTaskStorageOperations;
|
package/graphql/types.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { PbContext } from \"@webiny/api-page-builder/types\";\nimport {\n ExportRevisionType,\n ImportExportTask,\n ImportExportTaskStatus,\n ImportExportTaskStorageOperations,\n ImportExportTaskStorageOperationsListParams\n} from \"~/types\";\n\nexport interface ExportPagesParams {\n ids?: string[];\n revisionType: ExportRevisionType;\n where?: {\n category?: string;\n status?: string;\n tags?: { query: string[]; rule?: \"any\" | \"all\" };\n [key: string]: any;\n };\n search?: { query?: string };\n sort?: string[];\n}\n\nexport interface ImportPagesParams {\n category: string;\n zipFileUrl: string;\n meta?: Record<string, any>;\n}\n\nexport type PagesImportExportCrud = {\n exportPages(params: ExportPagesParams): Promise<{ task: ImportExportTask }>;\n importPages(params: ImportPagesParams): Promise<{ task: ImportExportTask }>;\n};\n\nexport interface ExportBlocksParams {\n ids?: string[];\n sort?: string[];\n where?: {\n blockCategory?: string;\n };\n}\n\nexport interface ImportBlocksParams {\n category: string;\n zipFileUrl: string;\n}\n\nexport type BlocksImportExportCrud = {\n exportBlocks(params: ExportBlocksParams): Promise<{ task: ImportExportTask }>;\n importBlocks(params: ImportBlocksParams): Promise<{ task: ImportExportTask }>;\n};\n\nexport interface ExportTemplatesParams {\n ids?: string[];\n sort?: string[];\n}\n\nexport interface ImportTemplatesParams {\n zipFileUrl: string;\n}\n\nexport type TemplatesImportExportCrud = {\n exportTemplates(params: ExportTemplatesParams): Promise<{ task: ImportExportTask }>;\n importTemplates(params: ImportTemplatesParams): Promise<{ task: ImportExportTask }>;\n};\n\ntype ImportExportTaskCreateData = Omit<ImportExportTask, \"id\" | \"createdOn\" | \"createdBy\">;\n\nexport type ImportExportTaskCrud = {\n /**\n * To be used internally in our code.\n * @internal\n */\n storageOperations: ImportExportTaskStorageOperations;\n\n getTask(id: string): Promise<ImportExportTask | null>;\n listTasks(params?: ImportExportTaskStorageOperationsListParams): Promise<ImportExportTask[]>;\n createTask(data: Partial<ImportExportTaskCreateData>): Promise<ImportExportTask>;\n updateTask(id: string, data: Partial<ImportExportTaskCreateData>): Promise<ImportExportTask>;\n updateStats(\n id: string,\n data: {\n prevStatus: ImportExportTaskStatus;\n nextStatus: ImportExportTaskStatus;\n }\n ): Promise<ImportExportTask>;\n deleteTask(id: string): Promise<ImportExportTask>;\n getSubTask(id: string, subtaskId: string): Promise<ImportExportTask | null>;\n listSubTasks(\n id: string,\n status: ImportExportTaskStatus,\n limit: number\n ): Promise<ImportExportTask[]>;\n createSubTask(\n id: string,\n subTaskId: string,\n data: Partial<ImportExportTaskCreateData>\n ): Promise<ImportExportTask>;\n updateSubTask(\n id: string,\n subTaskId: string,\n data: Partial<ImportExportTaskCreateData>\n ): Promise<ImportExportTask>;\n};\n\nexport interface PbImportExportContext extends PbContext {\n pageBuilder: PbContext[\"pageBuilder\"] & {\n pages: PagesImportExportCrud;\n blocks: BlocksImportExportCrud;\n templates: TemplatesImportExportCrud;\n importExportTask: ImportExportTaskCrud;\n };\n}\n\nexport interface ImportExportPluginsParams {\n storageOperations: ImportExportTaskStorageOperations;\n}\n"],"mappings":""}
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { PbContext } from \"@webiny/api-page-builder/types\";\nimport { FormBuilderContext } from \"@webiny/api-form-builder/types\";\nimport {\n ExportRevisionType,\n ImportExportTask,\n ImportExportTaskStatus,\n ImportExportTaskStorageOperations,\n ImportExportTaskStorageOperationsListParams\n} from \"~/types\";\n\nexport interface ExportPagesParams {\n ids?: string[];\n revisionType: ExportRevisionType;\n where?: {\n category?: string;\n status?: string;\n tags?: { query: string[]; rule?: \"any\" | \"all\" };\n [key: string]: any;\n };\n search?: { query?: string };\n sort?: string[];\n}\n\nexport interface ImportPagesParams {\n category: string;\n zipFileUrl: string;\n meta?: Record<string, any>;\n}\n\nexport type PagesImportExportCrud = {\n exportPages(params: ExportPagesParams): Promise<{ task: ImportExportTask }>;\n importPages(params: ImportPagesParams): Promise<{ task: ImportExportTask }>;\n};\n\nexport interface ExportBlocksParams {\n ids?: string[];\n sort?: string[];\n where?: {\n blockCategory?: string;\n };\n}\n\nexport interface ImportBlocksParams {\n category: string;\n zipFileUrl: string;\n}\n\nexport type BlocksImportExportCrud = {\n exportBlocks(params: ExportBlocksParams): Promise<{ task: ImportExportTask }>;\n importBlocks(params: ImportBlocksParams): Promise<{ task: ImportExportTask }>;\n};\n\nexport interface ExportTemplatesParams {\n ids?: string[];\n sort?: string[];\n}\n\nexport interface ImportTemplatesParams {\n zipFileUrl: string;\n}\n\nexport type TemplatesImportExportCrud = {\n exportTemplates(params: ExportTemplatesParams): Promise<{ task: ImportExportTask }>;\n importTemplates(params: ImportTemplatesParams): Promise<{ task: ImportExportTask }>;\n};\n\nexport interface ExportFormsParams {\n ids?: string[];\n revisionType: ExportRevisionType;\n search?: { query?: string };\n sort?: string[];\n}\n\nexport interface ImportFormsParams {\n zipFileUrl: string;\n}\n\nexport type FormsImportExportCrud = {\n exportForms(params: ExportFormsParams): Promise<{ task: ImportExportTask }>;\n importForms(params: ImportFormsParams): Promise<{ task: ImportExportTask }>;\n};\n\ntype ImportExportTaskCreateData = Omit<ImportExportTask, \"id\" | \"createdOn\" | \"createdBy\">;\n\nexport type ImportExportTaskCrud = {\n /**\n * To be used internally in our code.\n * @internal\n */\n storageOperations: ImportExportTaskStorageOperations;\n\n getTask(id: string): Promise<ImportExportTask | null>;\n listTasks(params?: ImportExportTaskStorageOperationsListParams): Promise<ImportExportTask[]>;\n createTask(data: Partial<ImportExportTaskCreateData>): Promise<ImportExportTask>;\n updateTask(id: string, data: Partial<ImportExportTaskCreateData>): Promise<ImportExportTask>;\n updateStats(\n id: string,\n data: {\n prevStatus: ImportExportTaskStatus;\n nextStatus: ImportExportTaskStatus;\n }\n ): Promise<ImportExportTask>;\n deleteTask(id: string): Promise<ImportExportTask>;\n getSubTask(id: string, subtaskId: string): Promise<ImportExportTask | null>;\n listSubTasks(\n id: string,\n status: ImportExportTaskStatus,\n limit: number\n ): Promise<ImportExportTask[]>;\n createSubTask(\n id: string,\n subTaskId: string,\n data: Partial<ImportExportTaskCreateData>\n ): Promise<ImportExportTask>;\n updateSubTask(\n id: string,\n subTaskId: string,\n data: Partial<ImportExportTaskCreateData>\n ): Promise<ImportExportTask>;\n};\n\nexport interface PbImportExportContext extends PbContext {\n pageBuilder: PbContext[\"pageBuilder\"] & {\n pages: PagesImportExportCrud;\n blocks: BlocksImportExportCrud;\n templates: TemplatesImportExportCrud;\n importExportTask: ImportExportTaskCrud;\n };\n formBuilder: FormBuilderContext[\"formBuilder\"] & {\n forms: FormsImportExportCrud;\n };\n}\n\nexport interface ImportExportPluginsParams {\n storageOperations: ImportExportTaskStorageOperations;\n}\n"],"mappings":""}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.INSTALL_EXTRACT_DIR = exports.INSTALL_DIR = exports.ASSETS_DIR_NAME = void 0;
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
const INSTALL_DIR = "/tmp";
|
10
|
+
exports.INSTALL_DIR = INSTALL_DIR;
|
11
|
+
const INSTALL_EXTRACT_DIR = _path.default.join(INSTALL_DIR, "apiPageBuilderImport");
|
12
|
+
exports.INSTALL_EXTRACT_DIR = INSTALL_EXTRACT_DIR;
|
13
|
+
const ASSETS_DIR_NAME = "/assets";
|
14
|
+
exports.ASSETS_DIR_NAME = ASSETS_DIR_NAME;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["INSTALL_DIR","INSTALL_EXTRACT_DIR","path","join","ASSETS_DIR_NAME"],"sources":["constants.ts"],"sourcesContent":["import path from \"path\";\n\nexport const INSTALL_DIR = \"/tmp\";\nexport const INSTALL_EXTRACT_DIR = path.join(INSTALL_DIR, \"apiPageBuilderImport\");\nexport const ASSETS_DIR_NAME = \"/assets\";\n"],"mappings":";;;;;;;AAAA;AAEO,MAAMA,WAAW,GAAG,MAAM;AAAC;AAC3B,MAAMC,mBAAmB,GAAGC,aAAI,CAACC,IAAI,CAACH,WAAW,EAAE,sBAAsB,CAAC;AAAC;AAC3E,MAAMI,eAAe,GAAG,SAAS;AAAC"}
|
@@ -9,6 +9,7 @@ var _utils = require("../utils");
|
|
9
9
|
var _client = require("../../client");
|
10
10
|
var _mockSecurity = require("../../mockSecurity");
|
11
11
|
var _utils2 = require("@webiny/utils");
|
12
|
+
var _extractAndUploadZipFileContents = require("../utils/extractAndUploadZipFileContents");
|
12
13
|
const blocksHandler = async (configuration, payload, context) => {
|
13
14
|
const log = console.log;
|
14
15
|
const {
|
@@ -33,12 +34,12 @@ const blocksHandler = async (configuration, payload, context) => {
|
|
33
34
|
}
|
34
35
|
(0, _mockSecurity.mockSecurity)(identity, context);
|
35
36
|
// Step 1: Read the zip file
|
36
|
-
const blockImportDataList = await (0,
|
37
|
+
const blockImportDataList = await (0, _extractAndUploadZipFileContents.extractAndUploadZipFileContents)(zipFileUrl);
|
37
38
|
|
38
39
|
// For each block create a subtask and invoke the process handler
|
39
40
|
for (let i = 0; i < blockImportDataList.length; i++) {
|
40
41
|
const blocksDirMap = blockImportDataList[i];
|
41
|
-
// Create sub
|
42
|
+
// Create sub-task
|
42
43
|
const subtask = await pageBuilder.importExportTask.createSubTask(task.id, (0, _utils2.zeroPad)(i + 1, 5), {
|
43
44
|
status: _types.ImportExportTaskStatus.PENDING,
|
44
45
|
data: {
|
@@ -62,7 +63,7 @@ const blocksHandler = async (configuration, payload, context) => {
|
|
62
63
|
name: configuration.handlers.process,
|
63
64
|
payload: {
|
64
65
|
taskId: task.id,
|
65
|
-
// Execute "Process" for the first sub
|
66
|
+
// Execute "Process" for the first sub-task.
|
66
67
|
subTaskIndex: 1,
|
67
68
|
type,
|
68
69
|
identity: context.security.getIdentity()
|