@webiny/api-page-builder-import-export 0.0.0-unstable.2696f9d9e8 → 0.0.0-unstable.2aaa1916d9
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/client.d.ts +1 -1
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.d.ts +2 -2
- package/export/combine/blocksHandler.js.map +1 -1
- package/export/combine/formsHandler.d.ts +2 -2
- package/export/combine/formsHandler.js.map +1 -1
- package/export/combine/index.d.ts +2 -2
- package/export/combine/index.js +2 -2
- package/export/combine/index.js.map +1 -1
- package/export/combine/templatesHandler.d.ts +2 -2
- package/export/combine/templatesHandler.js.map +1 -1
- package/export/pages/ExportPagesCleanup.d.ts +5 -0
- package/export/pages/ExportPagesCleanup.js +82 -0
- package/export/pages/ExportPagesCleanup.js.map +1 -0
- package/export/pages/ExportPagesController.d.ts +5 -0
- package/export/pages/ExportPagesController.js +31 -0
- package/export/pages/ExportPagesController.js.map +1 -0
- package/export/pages/ExportPagesZipPages.d.ts +5 -0
- package/export/pages/ExportPagesZipPages.js +23 -0
- package/export/pages/ExportPagesZipPages.js.map +1 -0
- package/export/pages/controller/CombineZippedPages.d.ts +5 -0
- package/export/pages/controller/CombineZippedPages.js +75 -0
- package/export/pages/controller/CombineZippedPages.js.map +1 -0
- package/export/pages/controller/CreateZipPagesTasks.d.ts +8 -0
- package/export/pages/controller/CreateZipPagesTasks.js +103 -0
- package/export/pages/controller/CreateZipPagesTasks.js.map +1 -0
- package/export/pages/controller/ProcessZipPagesTasks.d.ts +6 -0
- package/export/pages/controller/ProcessZipPagesTasks.js +61 -0
- package/export/pages/controller/ProcessZipPagesTasks.js.map +1 -0
- package/export/pages/types.d.ts +53 -0
- package/export/pages/types.js +26 -0
- package/export/pages/types.js.map +1 -0
- package/export/pages/utils.d.ts +2 -0
- package/export/pages/utils.js +13 -0
- package/export/pages/utils.js.map +1 -0
- package/export/pages/zipPages/ZipPages.d.ts +5 -0
- package/export/pages/zipPages/ZipPages.js +100 -0
- package/export/pages/zipPages/ZipPages.js.map +1 -0
- package/export/pages/zipPages/ZipPagesDataManager.d.ts +14 -0
- package/export/pages/zipPages/ZipPagesDataManager.js +46 -0
- package/export/pages/zipPages/ZipPagesDataManager.js.map +1 -0
- package/export/pages/zipPages/getPageFactory.d.ts +4 -0
- package/export/pages/zipPages/getPageFactory.js +38 -0
- package/export/pages/zipPages/getPageFactory.js.map +1 -0
- package/export/process/blocksHandler.d.ts +2 -2
- package/export/process/blocksHandler.js.map +1 -1
- package/export/process/exporters/BlockExporter.d.ts +2 -2
- package/export/process/exporters/BlockExporter.js.map +1 -1
- package/export/process/exporters/FormExporter.d.ts +2 -2
- package/export/process/exporters/FormExporter.js.map +1 -1
- package/export/process/exporters/PageExporter.d.ts +10 -3
- package/export/process/exporters/PageExporter.js +2 -1
- package/export/process/exporters/PageExporter.js.map +1 -1
- package/export/process/exporters/PageTemplateExporter.d.ts +3 -3
- package/export/process/exporters/PageTemplateExporter.js +3 -1
- package/export/process/exporters/PageTemplateExporter.js.map +1 -1
- package/export/process/formsHandler.d.ts +2 -2
- package/export/process/formsHandler.js.map +1 -1
- package/export/process/index.d.ts +2 -2
- package/export/process/index.js +2 -2
- package/export/process/index.js.map +1 -1
- package/export/process/templatesHandler.d.ts +2 -2
- package/export/process/templatesHandler.js.map +1 -1
- package/export/s3Stream.d.ts +6 -4
- package/export/s3Stream.js +1 -2
- package/export/s3Stream.js.map +1 -1
- package/export/utils.d.ts +4 -4
- package/export/utils.js +7 -9
- package/export/utils.js.map +1 -1
- package/export/zipper.d.ts +3 -2
- package/export/zipper.js.map +1 -1
- package/graphql/crud/blocks.crud.d.ts +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 +1 -1
- package/graphql/crud/forms.crud.js +1 -2
- package/graphql/crud/forms.crud.js.map +1 -1
- package/graphql/crud/importExportTasks.crud.d.ts +2 -2
- package/graphql/crud/importExportTasks.crud.js +73 -58
- package/graphql/crud/importExportTasks.crud.js.map +1 -1
- package/graphql/crud/pages.crud.d.ts +1 -2
- package/graphql/crud/pages.crud.js +208 -125
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.d.ts +1 -1
- package/graphql/crud/templates.crud.js +1 -2
- package/graphql/crud/templates.crud.js.map +1 -1
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.d.ts +2 -2
- package/graphql/graphql/blocks.gql.js +4 -6
- package/graphql/graphql/blocks.gql.js.map +1 -1
- package/graphql/graphql/forms.gql.d.ts +2 -2
- package/graphql/graphql/forms.gql.js +4 -6
- package/graphql/graphql/forms.gql.js.map +1 -1
- package/graphql/graphql/importExportTasks.gql.d.ts +2 -2
- package/graphql/graphql/importExportTasks.gql.js +5 -7
- package/graphql/graphql/importExportTasks.gql.js.map +1 -1
- package/graphql/graphql/pages.gql.d.ts +2 -2
- package/graphql/graphql/pages.gql.js +101 -14
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.d.ts +2 -2
- package/graphql/graphql/templates.gql.js +4 -6
- package/graphql/graphql/templates.gql.js.map +1 -1
- package/graphql/graphql/utils/resolve.d.ts +3 -3
- package/graphql/graphql/utils/resolve.js +14 -5
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/graphql.d.ts +1 -1
- package/graphql/graphql.js +1 -2
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +2 -1
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +61 -33
- package/graphql/types.js.map +1 -1
- package/import/constants.js +3 -6
- package/import/constants.js.map +1 -1
- package/import/create/blocksHandler.d.ts +2 -2
- package/import/create/blocksHandler.js.map +1 -1
- package/import/create/formsHandler.d.ts +2 -2
- package/import/create/formsHandler.js.map +1 -1
- package/import/create/index.d.ts +2 -2
- package/import/create/index.js +2 -2
- package/import/create/index.js.map +1 -1
- package/import/create/pagesHandler.d.ts +2 -2
- package/import/create/pagesHandler.js.map +1 -1
- package/import/create/templatesHandler.d.ts +2 -2
- package/import/create/templatesHandler.js.map +1 -1
- package/import/pages/ImportPagesController.d.ts +5 -0
- package/import/pages/ImportPagesController.js +29 -0
- package/import/pages/ImportPagesController.js.map +1 -0
- package/import/pages/ImportPagesProcessPages.d.ts +6 -0
- package/import/pages/ImportPagesProcessPages.js +112 -0
- package/import/pages/ImportPagesProcessPages.js.map +1 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.d.ts +6 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.js +40 -0
- package/import/pages/controller/ImportPagesProcessPagesChecker.js.map +1 -0
- package/import/pages/controller/ImportPagesProcessZipFile.d.ts +5 -0
- package/import/pages/controller/ImportPagesProcessZipFile.js +71 -0
- package/import/pages/controller/ImportPagesProcessZipFile.js.map +1 -0
- package/import/{process/pages → pages/process}/importPage.d.ts +3 -4
- package/import/pages/process/importPage.js.map +1 -0
- package/import/pages/types.d.ts +48 -0
- package/import/pages/types.js +20 -0
- package/import/pages/types.js.map +1 -0
- package/import/process/blocks/ElementIdsProcessor.d.ts +5 -0
- package/import/process/blocks/ElementIdsProcessor.js +26 -0
- package/import/process/blocks/ElementIdsProcessor.js.map +1 -0
- package/import/process/blocks/blocksHandler.d.ts +2 -2
- package/import/process/blocks/blocksHandler.js.map +1 -1
- package/import/process/blocks/importBlock.d.ts +3 -3
- package/import/process/blocks/importBlock.js +5 -2
- package/import/process/blocks/importBlock.js.map +1 -1
- package/import/process/forms/formsHandler.d.ts +2 -2
- package/import/process/forms/formsHandler.js.map +1 -1
- package/import/process/forms/importForm.d.ts +2 -2
- package/import/process/forms/importForm.js.map +1 -1
- package/import/process/index.d.ts +2 -2
- package/import/process/index.js +2 -2
- package/import/process/index.js.map +1 -1
- package/import/process/templates/importTemplate.d.ts +3 -3
- package/import/process/templates/importTemplate.js.map +1 -1
- package/import/process/templates/templatesHandler.d.ts +2 -2
- package/import/process/templates/templatesHandler.js +3 -1
- package/import/process/templates/templatesHandler.js.map +1 -1
- package/import/utils/deleteS3Folder.js.map +1 -1
- package/import/utils/extractAndUploadZipFileContents.d.ts +1 -1
- package/import/utils/extractAndUploadZipFileContents.js +6 -3
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -1
- package/import/utils/extractZipAndUploadToS3.d.ts +1 -1
- package/import/utils/extractZipAndUploadToS3.js.map +1 -1
- package/import/utils/getFileNameWithoutExt.js.map +1 -1
- package/import/utils/index.js.map +1 -1
- package/import/utils/initialStats.js.map +1 -1
- package/import/utils/prepareDataDirMap.d.ts +1 -1
- package/import/utils/prepareDataDirMap.js.map +1 -1
- package/import/utils/updateFilesInData.d.ts +1 -1
- package/import/utils/updateFilesInData.js.map +1 -1
- package/import/utils/uploadAssets.d.ts +3 -3
- package/import/utils/uploadAssets.js.map +1 -1
- package/import/utils/uploadFilesFromS3.d.ts +3 -3
- package/import/utils/uploadFilesFromS3.js.map +1 -1
- package/mockSecurity.d.ts +1 -1
- package/mockSecurity.js.map +1 -1
- package/package.json +33 -41
- package/tasks/common/ChildTasksCleanup.d.ts +12 -0
- package/tasks/common/ChildTasksCleanup.js +64 -0
- package/tasks/common/ChildTasksCleanup.js.map +1 -0
- package/tasks/index.d.ts +1 -0
- package/tasks/index.js +13 -0
- package/tasks/index.js.map +1 -0
- package/tasks/pages/exportPagesCleanupTask.d.ts +3 -0
- package/tasks/pages/exportPagesCleanupTask.js +36 -0
- package/tasks/pages/exportPagesCleanupTask.js.map +1 -0
- package/tasks/pages/exportPagesControllerTask.d.ts +3 -0
- package/tasks/pages/exportPagesControllerTask.js +83 -0
- package/tasks/pages/exportPagesControllerTask.js.map +1 -0
- package/tasks/pages/exportPagesZipPagesTask.d.ts +3 -0
- package/tasks/pages/exportPagesZipPagesTask.js +39 -0
- package/tasks/pages/exportPagesZipPagesTask.js.map +1 -0
- package/tasks/pages/importPagesControllerTask.d.ts +3 -0
- package/tasks/pages/importPagesControllerTask.js +39 -0
- package/tasks/pages/importPagesControllerTask.js.map +1 -0
- package/tasks/pages/importPagesProcessPageTask.d.ts +3 -0
- package/tasks/pages/importPagesProcessPageTask.js +39 -0
- package/tasks/pages/importPagesProcessPageTask.js.map +1 -0
- package/tasks/pages/index.d.ts +1 -0
- package/tasks/pages/index.js +17 -0
- package/tasks/pages/index.js.map +1 -0
- package/types.d.ts +2 -2
- package/types.js +2 -4
- package/types.js.map +1 -1
- package/utils/ZipFiles.d.ts +11 -0
- package/utils/ZipFiles.js +124 -0
- package/utils/ZipFiles.js.map +1 -0
- package/export/combine/pagesHandler.d.ts +0 -6
- package/export/combine/pagesHandler.js +0 -101
- package/export/combine/pagesHandler.js.map +0 -1
- package/export/process/pagesHandler.d.ts +0 -6
- package/export/process/pagesHandler.js +0 -191
- package/export/process/pagesHandler.js.map +0 -1
- package/import/process/pages/importPage.js.map +0 -1
- package/import/process/pages/pagesHandler.d.ts +0 -3
- package/import/process/pages/pagesHandler.js +0 -185
- package/import/process/pages/pagesHandler.js.map +0 -1
- /package/import/{process/pages → pages/process}/importPage.js +0 -0
|
@@ -32,7 +32,7 @@ async function extractAndUploadZipFileContents(zipFileUrl) {
|
|
|
32
32
|
const response = await (0, _nodeFetch.default)(zipFileUrl);
|
|
33
33
|
const readStream = response.body;
|
|
34
34
|
if (!response.ok || !readStream) {
|
|
35
|
-
throw new _error.default(`Unable to
|
|
35
|
+
throw new _error.default(`Unable to download file: "${zipFileUrl}"`, response.statusText);
|
|
36
36
|
}
|
|
37
37
|
const uniquePath = (0, _uniqid.default)("IMPORTS/");
|
|
38
38
|
// Read export file and download it in the disk
|
|
@@ -46,12 +46,15 @@ async function extractAndUploadZipFileContents(zipFileUrl) {
|
|
|
46
46
|
log(`Removing ZIP file "${zipFileUrl}" from ${ZIP_FILE_PATH}`);
|
|
47
47
|
await (0, _downloadInstallFiles.deleteFile)(ZIP_FILE_PATH);
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* TODO: Possibly do this in parallel?
|
|
51
|
+
*/
|
|
49
52
|
// Extract each page/block zip and upload their content's to S3
|
|
50
|
-
for (
|
|
51
|
-
const currentPath = zipFilePaths[i];
|
|
53
|
+
for (const currentPath of zipFilePaths) {
|
|
52
54
|
const dataMap = await (0, _extractZipAndUploadToS.extractZipAndUploadToS3)(currentPath, uniquePath);
|
|
53
55
|
importDataList.push(dataMap);
|
|
54
56
|
}
|
|
57
|
+
// TODO @pavel why?
|
|
55
58
|
log("Removing all ZIP files located at ", _path.default.dirname(zipFilePaths[0]));
|
|
56
59
|
await (0, _downloadInstallFiles.deleteFile)(_path.default.dirname(zipFilePaths[0]));
|
|
57
60
|
return importDataList;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_stream","require","_util","_nodeFetch","_interopRequireDefault","_path","_yauzl","_fs","_uniqid","_error","_downloadInstallFiles","_extractZipAndUploadToS","_getFileNameWithoutExt","_constants","_fsExtra","streamPipeline","promisify","pipeline","extractAndUploadZipFileContents","zipFileUrl","log","console","importDataList","zipFileName","path","basename","split","response","fetch","readStream","body","ok","WebinyError","statusText","uniquePath","uniqueId","ZIP_FILE_PATH","join","INSTALL_DIR","writeStream","createWriteStream","zipFilePaths","extractZipToDisk","deleteFile","i","length","currentPath","dataMap","extractZipAndUploadToS3","push","dirname","exportFileZipPath","Promise","resolve","reject","uniqueFolderNameForExport","getFileNameWithoutExt","EXPORT_FILE_EXTRACTION_PATH","ensureDirSync","yauzl","open","lazyEntries","err","zipFile","warn","info","entryCount","on","readEntry","entry","fileName","test","openReadStream","filePath","catch","error"],"sources":["extractAndUploadZipFileContents.ts"],"sourcesContent":["import { pipeline } from \"stream\";\nimport { promisify } from \"util\";\nimport fetch from \"node-fetch\";\nimport path from \"path\";\nimport yauzl from \"yauzl\";\nimport { createWriteStream } from \"fs\";\nimport uniqueId from \"uniqid\";\nimport WebinyError from \"@webiny/error\";\nimport { deleteFile } from \"@webiny/api-page-builder/graphql/crud/install/utils/downloadInstallFiles\";\nimport { extractZipAndUploadToS3 } from \"~/import/utils/extractZipAndUploadToS3\";\nimport { getFileNameWithoutExt } from \"~/import/utils/getFileNameWithoutExt\";\nimport { ImportData } from \"~/types\";\nimport { INSTALL_DIR } from \"~/import/constants\";\nimport { ensureDirSync } from \"fs-extra\";\n\nconst streamPipeline = promisify(pipeline);\n\n/**\n * Function will read the given zip file from S3 via stream, extract its content and upload it to S3 bucket.\n * @param zipFileUrl\n * @return ImportData S3 file keys for all uploaded assets group by page/block.\n */\nexport async function extractAndUploadZipFileContents(zipFileUrl: string): Promise<ImportData[]> {\n const log = console.log;\n const importDataList = [];\n\n const zipFileName = path.basename(zipFileUrl).split(\"?\")[0];\n\n const response = await fetch(zipFileUrl);\n const readStream = response.body;\n if (!response.ok || !readStream) {\n throw new WebinyError(`Unable to downloading file: \"${zipFileUrl}\"`, response.statusText);\n }\n\n const uniquePath = uniqueId(\"IMPORTS/\");\n // Read export file and download it in the disk\n const ZIP_FILE_PATH = path.join(INSTALL_DIR, zipFileName);\n\n const writeStream = createWriteStream(ZIP_FILE_PATH);\n\n await streamPipeline(readStream, writeStream);\n log(`Downloaded file \"${zipFileName}\" at ${ZIP_FILE_PATH}`);\n\n // Extract the downloaded zip file\n const zipFilePaths = await extractZipToDisk(ZIP_FILE_PATH);\n\n log(`Removing ZIP file \"${zipFileUrl}\" from ${ZIP_FILE_PATH}`);\n await deleteFile(ZIP_FILE_PATH);\n\n // Extract each page/block zip and upload their content's to S3\n for (let i = 0; i < zipFilePaths.length; i++) {\n const currentPath = zipFilePaths[i];\n const dataMap = await extractZipAndUploadToS3(currentPath, uniquePath);\n importDataList.push(dataMap);\n }\n log(\"Removing all ZIP files located at \", path.dirname(zipFilePaths[0]));\n await deleteFile(path.dirname(zipFilePaths[0]));\n\n return importDataList;\n}\n\nfunction extractZipToDisk(exportFileZipPath: string): Promise<string[]> {\n return new Promise((resolve, reject) => {\n const zipFilePaths: string[] = [];\n const uniqueFolderNameForExport = getFileNameWithoutExt(exportFileZipPath);\n const EXPORT_FILE_EXTRACTION_PATH = path.join(INSTALL_DIR, uniqueFolderNameForExport);\n // Make sure DIR exists\n ensureDirSync(EXPORT_FILE_EXTRACTION_PATH);\n\n yauzl.open(exportFileZipPath, { lazyEntries: true }, function (err, zipFile) {\n if (err) {\n console.warn(\"ERROR: Failed to extract zip: \", exportFileZipPath, err);\n reject(err);\n return;\n }\n if (!zipFile) {\n console.log(\"ERROR: Missing zip file resource for path: \" + exportFileZipPath);\n reject(\"Missing Zip File Resource.\");\n return;\n }\n\n console.info(`The ZIP file contains ${zipFile.entryCount} entries.`);\n\n zipFile.on(\"end\", function (err) {\n if (err) {\n console.warn(\"ERROR: Failed on END event for file: \", exportFileZipPath, err);\n reject(err);\n }\n resolve(zipFilePaths);\n });\n\n zipFile.readEntry();\n\n zipFile.on(\"entry\", function (entry) {\n console.info(`Processing entry: \"${entry.fileName}\"`);\n if (/\\/$/.test(entry.fileName)) {\n // Directory file names end with '/'.\n // Note that entries for directories themselves are optional.\n // An entry's fileName implicitly requires its parent directories to exist.\n zipFile.readEntry();\n } else {\n // file entry\n zipFile.openReadStream(entry, function (err, readStream) {\n if (err) {\n console.warn(\n \"ERROR: Failed to openReadStream for file: \",\n entry.fileName,\n err\n );\n reject(err);\n return;\n }\n if (!readStream) {\n console.log(\n \"ERROR: Missing Read Stream Resource when extracting to disk.\"\n );\n reject(\"Missing Read Stream Resource.\");\n return;\n }\n\n const filePath = path.join(EXPORT_FILE_EXTRACTION_PATH, entry.fileName);\n\n readStream.on(\"end\", function () {\n zipFilePaths.push(filePath);\n zipFile.readEntry();\n });\n\n streamPipeline(readStream, createWriteStream(filePath)).catch(error => {\n reject(error);\n });\n });\n }\n });\n });\n });\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,I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YAEA,MAAMmB,QAAQ,GAAGjD,aAAI,CAACa,IAAI,CAACoB,2BAA2B,EAAEY,KAAK,CAACC,QAAQ,CAAC;YAEvEzC,UAAU,CAACsC,EAAE,CAAC,KAAK,EAAE,YAAY;cAC7B1B,YAAY,CAACQ,IAAI,CAACwB,QAAQ,CAAC;cAC3BV,OAAO,CAACK,SAAS,CAAC,CAAC;YACvB,CAAC,CAAC;YAEFrD,cAAc,CAACc,UAAU,EAAE,IAAAW,qBAAiB,EAACiC,QAAQ,CAAC,CAAC,CAACC,KAAK,CAACC,KAAK,IAAI;cACnErB,MAAM,CAACqB,KAAK,CAAC;YACjB,CAAC,CAAC;UACN,CAAC,CAAC;QACN;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN"}
|
|
1
|
+
{"version":3,"names":["_stream","require","_util","_nodeFetch","_interopRequireDefault","_path","_yauzl","_fs","_uniqid","_error","_downloadInstallFiles","_extractZipAndUploadToS","_getFileNameWithoutExt","_constants","_fsExtra","streamPipeline","promisify","pipeline","extractAndUploadZipFileContents","zipFileUrl","log","console","importDataList","zipFileName","path","basename","split","response","fetch","readStream","body","ok","WebinyError","statusText","uniquePath","uniqueId","ZIP_FILE_PATH","join","INSTALL_DIR","writeStream","createWriteStream","zipFilePaths","extractZipToDisk","deleteFile","currentPath","dataMap","extractZipAndUploadToS3","push","dirname","exportFileZipPath","Promise","resolve","reject","uniqueFolderNameForExport","getFileNameWithoutExt","EXPORT_FILE_EXTRACTION_PATH","ensureDirSync","yauzl","open","lazyEntries","err","zipFile","warn","info","entryCount","on","readEntry","entry","fileName","test","openReadStream","filePath","catch","error"],"sources":["extractAndUploadZipFileContents.ts"],"sourcesContent":["import { pipeline } from \"stream\";\nimport { promisify } from \"util\";\nimport fetch from \"node-fetch\";\nimport path from \"path\";\nimport yauzl from \"yauzl\";\nimport { createWriteStream } from \"fs\";\nimport uniqueId from \"uniqid\";\nimport WebinyError from \"@webiny/error\";\nimport { deleteFile } from \"@webiny/api-page-builder/graphql/crud/install/utils/downloadInstallFiles\";\nimport { extractZipAndUploadToS3 } from \"~/import/utils/extractZipAndUploadToS3\";\nimport { getFileNameWithoutExt } from \"~/import/utils/getFileNameWithoutExt\";\nimport type { ImportData } from \"~/types\";\nimport { INSTALL_DIR } from \"~/import/constants\";\nimport { ensureDirSync } from \"fs-extra\";\n\nconst streamPipeline = promisify(pipeline);\n\n/**\n * Function will read the given zip file from S3 via stream, extract its content and upload it to S3 bucket.\n * @param zipFileUrl\n * @return ImportData S3 file keys for all uploaded assets group by page/block.\n */\nexport async function extractAndUploadZipFileContents(zipFileUrl: string): Promise<ImportData[]> {\n const log = console.log;\n const importDataList: ImportData[] = [];\n\n const zipFileName = path.basename(zipFileUrl).split(\"?\")[0];\n\n const response = await fetch(zipFileUrl);\n const readStream = response.body;\n if (!response.ok || !readStream) {\n throw new WebinyError(`Unable to download file: \"${zipFileUrl}\"`, response.statusText);\n }\n\n const uniquePath = uniqueId(\"IMPORTS/\");\n // Read export file and download it in the disk\n const ZIP_FILE_PATH = path.join(INSTALL_DIR, zipFileName);\n\n const writeStream = createWriteStream(ZIP_FILE_PATH);\n\n await streamPipeline(readStream, writeStream);\n log(`Downloaded file \"${zipFileName}\" at ${ZIP_FILE_PATH}`);\n\n // Extract the downloaded zip file\n const zipFilePaths = await extractZipToDisk(ZIP_FILE_PATH);\n\n log(`Removing ZIP file \"${zipFileUrl}\" from ${ZIP_FILE_PATH}`);\n await deleteFile(ZIP_FILE_PATH);\n\n /**\n * TODO: Possibly do this in parallel?\n */\n // Extract each page/block zip and upload their content's to S3\n for (const currentPath of zipFilePaths) {\n const dataMap = await extractZipAndUploadToS3(currentPath, uniquePath);\n importDataList.push(dataMap);\n }\n // TODO @pavel why?\n log(\"Removing all ZIP files located at \", path.dirname(zipFilePaths[0]));\n await deleteFile(path.dirname(zipFilePaths[0]));\n\n return importDataList;\n}\n\nfunction extractZipToDisk(exportFileZipPath: string): Promise<string[]> {\n return new Promise((resolve, reject) => {\n const zipFilePaths: string[] = [];\n const uniqueFolderNameForExport = getFileNameWithoutExt(exportFileZipPath);\n const EXPORT_FILE_EXTRACTION_PATH = path.join(INSTALL_DIR, uniqueFolderNameForExport);\n // Make sure DIR exists\n ensureDirSync(EXPORT_FILE_EXTRACTION_PATH);\n\n yauzl.open(exportFileZipPath, { lazyEntries: true }, function (err, zipFile) {\n if (err) {\n console.warn(\"ERROR: Failed to extract zip: \", exportFileZipPath, err);\n reject(err);\n return;\n }\n if (!zipFile) {\n console.log(\"ERROR: Missing zip file resource for path: \" + exportFileZipPath);\n reject(\"Missing Zip File Resource.\");\n return;\n }\n\n console.info(`The ZIP file contains ${zipFile.entryCount} entries.`);\n\n zipFile.on(\"end\", function (err) {\n if (err) {\n console.warn(\"ERROR: Failed on END event for file: \", exportFileZipPath, err);\n reject(err);\n }\n resolve(zipFilePaths);\n });\n\n zipFile.readEntry();\n\n zipFile.on(\"entry\", function (entry) {\n console.info(`Processing entry: \"${entry.fileName}\"`);\n if (/\\/$/.test(entry.fileName)) {\n // Directory file names end with '/'.\n // Note that entries for directories themselves are optional.\n // An entry's fileName implicitly requires its parent directories to exist.\n zipFile.readEntry();\n } else {\n // file entry\n zipFile.openReadStream(entry, function (err, readStream) {\n if (err) {\n console.warn(\n \"ERROR: Failed to openReadStream for file: \",\n entry.fileName,\n err\n );\n reject(err);\n return;\n }\n if (!readStream) {\n console.log(\n \"ERROR: Missing Read Stream Resource when extracting to disk.\"\n );\n reject(\"Missing Read Stream Resource.\");\n return;\n }\n\n const filePath = path.join(EXPORT_FILE_EXTRACTION_PATH, entry.fileName);\n\n readStream.on(\"end\", function () {\n zipFilePaths.push(filePath);\n zipFile.readEntry();\n });\n\n streamPipeline(readStream, createWriteStream(filePath)).catch(error => {\n reject(error);\n });\n });\n }\n });\n });\n });\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,UAAA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2BAA2B,EAAEY,KAAK,CAACC,QAAQ,CAAC;YAEvEvC,UAAU,CAACoC,EAAE,CAAC,KAAK,EAAE,YAAY;cAC7BxB,YAAY,CAACM,IAAI,CAACwB,QAAQ,CAAC;cAC3BV,OAAO,CAACK,SAAS,CAAC,CAAC;YACvB,CAAC,CAAC;YAEFnD,cAAc,CAACc,UAAU,EAAE,IAAAW,qBAAiB,EAAC+B,QAAQ,CAAC,CAAC,CAACC,KAAK,CAACC,KAAK,IAAI;cACnErB,MAAM,CAACqB,KAAK,CAAC;YACjB,CAAC,CAAC;UACN,CAAC,CAAC;QACN;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ImportData } from "../../types";
|
|
1
|
+
import type { ImportData } from "../../types";
|
|
2
2
|
export declare function extractZipAndUploadToS3(dataZipFilePath: string, uniquePath: string): Promise<ImportData>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_yauzl","_interopRequireDefault","require","_stream","_util","_s3Stream","_getFileNameWithoutExt","_prepareDataDirMap","FILE_CONTENT_TYPE","streamPipeline","promisify","pipeline","extractZipAndUploadToS3","dataZipFilePath","uniquePath","Promise","resolve","reject","filePaths","fileUploadPromises","uniqueKey","getFileNameWithoutExt","dataMap","key","assets","data","yauzl","open","lazyEntries","err","zipFile","console","warn","log","info","entryCount","on","all","then","res","forEach","r","readEntry","entry","fileName","test","openReadStream","readStream","push","newKey","prepareDataDirMap","map","filePath","streamPassThrough","streamPassThroughUploadPromise","promise","s3Stream","writeStream","catch","error"],"sources":["extractZipAndUploadToS3.ts"],"sourcesContent":["import yauzl from \"yauzl\";\nimport { pipeline } from \"stream\";\nimport { promisify } from \"util\";\nimport { CompleteMultipartUploadOutput } from \"@webiny/aws-sdk/client-s3\";\nimport { s3Stream } from \"~/export/s3Stream\";\nimport { getFileNameWithoutExt } from \"./getFileNameWithoutExt\";\nimport { ImportData } from \"~/types\";\nimport { prepareDataDirMap } from \"~/import/utils/prepareDataDirMap\";\n\nconst FILE_CONTENT_TYPE = \"application/octet-stream\";\nconst streamPipeline = promisify(pipeline);\n\nexport function extractZipAndUploadToS3(\n dataZipFilePath: string,\n uniquePath: string\n): Promise<ImportData> {\n return new Promise((resolve, reject) => {\n const filePaths = [];\n const fileUploadPromises: Promise<CompleteMultipartUploadOutput>[] = [];\n const uniqueKey = getFileNameWithoutExt(dataZipFilePath);\n let dataMap: ImportData = {\n key: uniqueKey,\n assets: {},\n data: \"\"\n };\n yauzl.open(dataZipFilePath, { lazyEntries: true }, function (err, zipFile) {\n if (err) {\n console.warn(\"ERROR: Failed to extract zip: \", dataZipFilePath, err);\n reject(err);\n return;\n }\n if (!zipFile) {\n console.log(\"ERROR: Probably failed to extract zip: \" + dataZipFilePath);\n reject(\"Missing Zip File Resource.\");\n return;\n }\n console.info(`The ZIP file contains ${zipFile.entryCount} entries.`);\n zipFile.on(\"end\", function (err) {\n if (err) {\n console.warn('ERROR: Failed on \"END\" for file: ', dataZipFilePath, err);\n reject(err);\n }\n\n Promise.all(fileUploadPromises).then(res => {\n res.forEach(r => {\n console.info(\"Done uploading... \", r);\n });\n resolve(dataMap);\n });\n });\n\n zipFile.readEntry();\n\n zipFile.on(\"entry\", function (entry) {\n console.info(`Processing entry: \"${entry.fileName}\"`);\n if (/\\/$/.test(entry.fileName)) {\n // Directory file names end with '/'.\n // Note that entries for directories themselves are optional.\n // An entry's fileName implicitly requires its parent directories to exist.\n zipFile.readEntry();\n } else {\n // file entry\n zipFile.openReadStream(entry, function (err, readStream) {\n if (err) {\n console.warn(\n \"ERROR: Failed while performing [openReadStream] for file: \",\n entry.fileName,\n err\n );\n reject(err);\n return;\n }\n if (!readStream) {\n console.log(\"ERROR: Missing Read Stream while importing.\");\n reject(\"Missing Read Strea Resource.\");\n return;\n }\n readStream.on(\"end\", function () {\n filePaths.push(entry.fileName);\n zipFile.readEntry();\n });\n\n const newKey = `${uniquePath}/${uniqueKey}/${entry.fileName}`;\n // Modify in place\n dataMap = prepareDataDirMap({\n map: dataMap,\n filePath: entry.fileName,\n newKey\n });\n\n const { streamPassThrough, streamPassThroughUploadPromise: promise } =\n s3Stream.writeStream(newKey, FILE_CONTENT_TYPE);\n\n streamPipeline(readStream, streamPassThrough)\n .then(() => {\n fileUploadPromises.push(promise);\n })\n .catch(error => {\n reject(error);\n });\n });\n }\n });\n });\n });\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,sBAAA,GAAAJ,OAAA;AAEA,IAAAK,kBAAA,GAAAL,OAAA;AAEA,MAAMM,iBAAiB,GAAG,0BAA0B;AACpD,MAAMC,cAAc,GAAG,IAAAC,eAAS,EAACC,gBAAQ,CAAC;AAEnC,SAASC,uBAAuBA,CACnCC,eAAuB,EACvBC,UAAkB,EACC;EACnB,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACpC,MAAMC,SAAS,GAAG,EAAE;IACpB,MAAMC,kBAA4D,GAAG,EAAE;IACvE,MAAMC,SAAS,GAAG,IAAAC,4CAAqB,EAACR,eAAe,CAAC;IACxD,IAAIS,OAAmB,GAAG;MACtBC,GAAG,EAAEH,SAAS;MACdI,MAAM,EAAE,CAAC,CAAC;MACVC,IAAI,EAAE;IACV,CAAC;IACDC,cAAK,CAACC,IAAI,CAACd,eAAe,EAAE;MAAEe,WAAW,EAAE;IAAK,CAAC,EAAE,UAAUC,GAAG,EAAEC,OAAO,EAAE;MACvE,IAAID,GAAG,EAAE;QACLE,OAAO,CAACC,IAAI,CAAC,gCAAgC,EAAEnB,eAAe,EAAEgB,GAAG,CAAC;QACpEZ,MAAM,CAACY,GAAG,CAAC;QACX;MACJ;MACA,IAAI,CAACC,OAAO,EAAE;QACVC,OAAO,CAACE,GAAG,CAAC,yCAAyC,GAAGpB,eAAe,CAAC;QACxEI,MAAM,CAAC,4BAA4B,CAAC;QACpC;MACJ;MACAc,OAAO,CAACG,IAAI,
|
|
1
|
+
{"version":3,"names":["_yauzl","_interopRequireDefault","require","_stream","_util","_s3Stream","_getFileNameWithoutExt","_prepareDataDirMap","FILE_CONTENT_TYPE","streamPipeline","promisify","pipeline","extractZipAndUploadToS3","dataZipFilePath","uniquePath","Promise","resolve","reject","filePaths","fileUploadPromises","uniqueKey","getFileNameWithoutExt","dataMap","key","assets","data","yauzl","open","lazyEntries","err","zipFile","console","warn","log","info","entryCount","on","all","then","res","forEach","r","readEntry","entry","fileName","test","openReadStream","readStream","push","newKey","prepareDataDirMap","map","filePath","streamPassThrough","streamPassThroughUploadPromise","promise","s3Stream","writeStream","catch","error"],"sources":["extractZipAndUploadToS3.ts"],"sourcesContent":["import yauzl from \"yauzl\";\nimport { pipeline } from \"stream\";\nimport { promisify } from \"util\";\nimport type { CompleteMultipartUploadOutput } from \"@webiny/aws-sdk/client-s3\";\nimport { s3Stream } from \"~/export/s3Stream\";\nimport { getFileNameWithoutExt } from \"./getFileNameWithoutExt\";\nimport type { ImportData } from \"~/types\";\nimport { prepareDataDirMap } from \"~/import/utils/prepareDataDirMap\";\n\nconst FILE_CONTENT_TYPE = \"application/octet-stream\";\nconst streamPipeline = promisify(pipeline);\n\nexport function extractZipAndUploadToS3(\n dataZipFilePath: string,\n uniquePath: string\n): Promise<ImportData> {\n return new Promise((resolve, reject) => {\n const filePaths = [];\n const fileUploadPromises: Promise<CompleteMultipartUploadOutput>[] = [];\n const uniqueKey = getFileNameWithoutExt(dataZipFilePath);\n let dataMap: ImportData = {\n key: uniqueKey,\n assets: {},\n data: \"\"\n };\n yauzl.open(dataZipFilePath, { lazyEntries: true }, function (err, zipFile) {\n if (err) {\n console.warn(\"ERROR: Failed to extract zip: \", dataZipFilePath, err);\n reject(err);\n return;\n }\n if (!zipFile) {\n console.log(\"ERROR: Probably failed to extract zip: \" + dataZipFilePath);\n reject(\"Missing Zip File Resource.\");\n return;\n }\n console.info(`The ZIP file contains ${zipFile.entryCount} entries.`);\n zipFile.on(\"end\", function (err) {\n if (err) {\n console.warn('ERROR: Failed on \"END\" for file: ', dataZipFilePath, err);\n reject(err);\n }\n\n Promise.all(fileUploadPromises).then(res => {\n res.forEach(r => {\n console.info(\"Done uploading... \", r);\n });\n resolve(dataMap);\n });\n });\n\n zipFile.readEntry();\n\n zipFile.on(\"entry\", function (entry) {\n console.info(`Processing entry: \"${entry.fileName}\"`);\n if (/\\/$/.test(entry.fileName)) {\n // Directory file names end with '/'.\n // Note that entries for directories themselves are optional.\n // An entry's fileName implicitly requires its parent directories to exist.\n zipFile.readEntry();\n } else {\n // file entry\n zipFile.openReadStream(entry, function (err, readStream) {\n if (err) {\n console.warn(\n \"ERROR: Failed while performing [openReadStream] for file: \",\n entry.fileName,\n err\n );\n reject(err);\n return;\n }\n if (!readStream) {\n console.log(\"ERROR: Missing Read Stream while importing.\");\n reject(\"Missing Read Strea Resource.\");\n return;\n }\n readStream.on(\"end\", function () {\n filePaths.push(entry.fileName);\n zipFile.readEntry();\n });\n\n const newKey = `${uniquePath}/${uniqueKey}/${entry.fileName}`;\n // Modify in place\n dataMap = prepareDataDirMap({\n map: dataMap,\n filePath: entry.fileName,\n newKey\n });\n\n const { streamPassThrough, streamPassThroughUploadPromise: promise } =\n s3Stream.writeStream(newKey, FILE_CONTENT_TYPE);\n\n streamPipeline(readStream, streamPassThrough)\n .then(() => {\n fileUploadPromises.push(promise);\n })\n .catch(error => {\n reject(error);\n });\n });\n }\n });\n });\n });\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,sBAAA,GAAAJ,OAAA;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,CAAC,CAAC;YAEF,MAAM;cAAEI,iBAAiB;cAAEC,8BAA8B,EAAEC;YAAQ,CAAC,GAChEC,kBAAQ,CAACC,WAAW,CAACR,MAAM,EAAEzC,iBAAiB,CAAC;YAEnDC,cAAc,CAACsC,UAAU,EAAEM,iBAAiB,CAAC,CACxCf,IAAI,CAAC,MAAM;cACRnB,kBAAkB,CAAC6B,IAAI,CAACO,OAAO,CAAC;YACpC,CAAC,CAAC,CACDG,KAAK,CAACC,KAAK,IAAI;cACZ1C,MAAM,CAAC0C,KAAK,CAAC;YACjB,CAAC,CAAC;UACV,CAAC,CAAC;QACN;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_path","_interopRequireDefault","require","getFileNameWithoutExt","fileName","path","basename","replace","extname"],"sources":["getFileNameWithoutExt.ts"],"sourcesContent":["import path from \"path\";\n\nexport function getFileNameWithoutExt(fileName: string): string {\n return path.basename(fileName).replace(path.extname(fileName), \"\");\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEO,SAASC,qBAAqBA,CAACC,QAAgB,EAAU;EAC5D,OAAOC,aAAI,CAACC,QAAQ,CAACF,QAAQ,CAAC,CAACG,OAAO,CAACF,aAAI,CAACG,OAAO,CAACJ,QAAQ,CAAC,EAAE,EAAE,CAAC;AACtE"}
|
|
1
|
+
{"version":3,"names":["_path","_interopRequireDefault","require","getFileNameWithoutExt","fileName","path","basename","replace","extname"],"sources":["getFileNameWithoutExt.ts"],"sourcesContent":["import path from \"path\";\n\nexport function getFileNameWithoutExt(fileName: string): string {\n return path.basename(fileName).replace(path.extname(fileName), \"\");\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEO,SAASC,qBAAqBA,CAACC,QAAgB,EAAU;EAC5D,OAAOC,aAAI,CAACC,QAAQ,CAACF,QAAQ,CAAC,CAACG,OAAO,CAACF,aAAI,CAACG,OAAO,CAACJ,QAAQ,CAAC,EAAE,EAAE,CAAC;AACtE","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_initialStats","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_uploadFilesFromS","_uploadAssets","_updateFilesInData","_prepareDataDirMap","_getFileNameWithoutExt","_extractZipAndUploadToS","_extractAndUploadZipFileContents","_deleteS3Folder"],"sources":["index.ts"],"sourcesContent":["export * from \"./initialStats\";\nexport * from \"./uploadFilesFromS3\";\nexport * from \"./uploadAssets\";\nexport * from \"./updateFilesInData\";\nexport * from \"./prepareDataDirMap\";\nexport * from \"./getFileNameWithoutExt\";\nexport * from \"./extractZipAndUploadToS3\";\nexport * from \"./extractAndUploadZipFileContents\";\nexport * from \"./deleteS3Folder\";\n"],"mappings":";;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,aAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,aAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,aAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,iBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,iBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,iBAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA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Z,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAQ,eAAA,CAAAZ,GAAA;IAAA;EAAA;AAAA"}
|
|
1
|
+
{"version":3,"names":["_initialStats","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_uploadFilesFromS","_uploadAssets","_updateFilesInData","_prepareDataDirMap","_getFileNameWithoutExt","_extractZipAndUploadToS","_extractAndUploadZipFileContents","_deleteS3Folder"],"sources":["index.ts"],"sourcesContent":["export * from \"./initialStats\";\nexport * from \"./uploadFilesFromS3\";\nexport * from \"./uploadAssets\";\nexport * from \"./updateFilesInData\";\nexport * from \"./prepareDataDirMap\";\nexport * from \"./getFileNameWithoutExt\";\nexport * from \"./extractZipAndUploadToS3\";\nexport * from \"./extractAndUploadZipFileContents\";\nexport * from \"./deleteS3Folder\";\n"],"mappings":";;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,aAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,aAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,aAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,iBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,iBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,iBAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAA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AY,eAAA,CAAAZ,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAQ,eAAA,CAAAZ,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_types","require","initialStats","total","ImportExportTaskStatus","PENDING","PROCESSING","COMPLETED","FAILED"],"sources":["initialStats.ts"],"sourcesContent":["import { ImportExportTaskStatus } from \"~/types\";\n\nexport function initialStats(total: number) {\n return {\n [ImportExportTaskStatus.PENDING]: total,\n [ImportExportTaskStatus.PROCESSING]: 0,\n [ImportExportTaskStatus.COMPLETED]: 0,\n [ImportExportTaskStatus.FAILED]: 0,\n total\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEO,SAASC,YAAYA,CAACC,KAAa,EAAE;EACxC,OAAO;IACH,CAACC,6BAAsB,CAACC,OAAO,GAAGF,KAAK;IACvC,CAACC,6BAAsB,CAACE,UAAU,GAAG,CAAC;IACtC,CAACF,6BAAsB,CAACG,SAAS,GAAG,CAAC;IACrC,CAACH,6BAAsB,CAACI,MAAM,GAAG,CAAC;IAClCL;EACJ,CAAC;AACL"}
|
|
1
|
+
{"version":3,"names":["_types","require","initialStats","total","ImportExportTaskStatus","PENDING","PROCESSING","COMPLETED","FAILED"],"sources":["initialStats.ts"],"sourcesContent":["import { ImportExportTaskStatus } from \"~/types\";\n\nexport function initialStats(total: number) {\n return {\n [ImportExportTaskStatus.PENDING]: total,\n [ImportExportTaskStatus.PROCESSING]: 0,\n [ImportExportTaskStatus.COMPLETED]: 0,\n [ImportExportTaskStatus.FAILED]: 0,\n total\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEO,SAASC,YAAYA,CAACC,KAAa,EAAE;EACxC,OAAO;IACH,CAACC,6BAAsB,CAACC,OAAO,GAAGF,KAAK;IACvC,CAACC,6BAAsB,CAACE,UAAU,GAAG,CAAC;IACtC,CAACF,6BAAsB,CAACG,SAAS,GAAG,CAAC;IACrC,CAACH,6BAAsB,CAACI,MAAM,GAAG,CAAC;IAClCL;EACJ,CAAC;AACL","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_dotPropImmutable","_interopRequireDefault","require","_constants","prepareDataDirMap","map","filePath","newKey","isAsset","includes","ASSETS_DIR_NAME","assetKey","split","pop","oldKey","replace","dotProp","set"],"sources":["prepareDataDirMap.ts"],"sourcesContent":["import dotProp from \"dot-prop-immutable\";\nimport { ImportData } from \"~/types\";\nimport { ASSETS_DIR_NAME } from \"~/import/constants\";\n\nexport function prepareDataDirMap({\n map,\n filePath,\n newKey\n}: {\n map: ImportData;\n filePath: string;\n newKey: string;\n}): ImportData {\n const isAsset = filePath.includes(ASSETS_DIR_NAME);\n\n if (isAsset) {\n /*\n * We want to use dot (.) as part of object key rather than creating nested object(s).\n * Also, the file name might contain dots in it beside the extension, so, we are escaping them all.\n */\n const assetKey = filePath.split(`${ASSETS_DIR_NAME}/`).pop() as string;\n const oldKey = assetKey.replace(/\\./g, \"\\\\.\");\n\n map = dotProp.set(map, `assets.${oldKey}`, newKey);\n } else {\n // We only need to know the newKey for data file.\n map = dotProp.set(map, `data`, newKey);\n }\n\n return map;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAEO,SAASE,iBAAiBA,CAAC;EAC9BC,GAAG;EACHC,QAAQ;EACRC;AAKJ,CAAC,EAAc;EACX,MAAMC,OAAO,GAAGF,QAAQ,CAACG,QAAQ,CAACC,0BAAe,CAAC;EAElD,IAAIF,OAAO,EAAE;IACT;AACR;AACA;AACA;IACQ,MAAMG,QAAQ,GAAGL,QAAQ,CAACM,KAAK,
|
|
1
|
+
{"version":3,"names":["_dotPropImmutable","_interopRequireDefault","require","_constants","prepareDataDirMap","map","filePath","newKey","isAsset","includes","ASSETS_DIR_NAME","assetKey","split","pop","oldKey","replace","dotProp","set"],"sources":["prepareDataDirMap.ts"],"sourcesContent":["import dotProp from \"dot-prop-immutable\";\nimport type { ImportData } from \"~/types\";\nimport { ASSETS_DIR_NAME } from \"~/import/constants\";\n\nexport function prepareDataDirMap({\n map,\n filePath,\n newKey\n}: {\n map: ImportData;\n filePath: string;\n newKey: string;\n}): ImportData {\n const isAsset = filePath.includes(ASSETS_DIR_NAME);\n\n if (isAsset) {\n /*\n * We want to use dot (.) as part of object key rather than creating nested object(s).\n * Also, the file name might contain dots in it beside the extension, so, we are escaping them all.\n */\n const assetKey = filePath.split(`${ASSETS_DIR_NAME}/`).pop() as string;\n const oldKey = assetKey.replace(/\\./g, \"\\\\.\");\n\n map = dotProp.set(map, `assets.${oldKey}`, newKey);\n } else {\n // We only need to know the newKey for data file.\n map = dotProp.set(map, `data`, newKey);\n }\n\n return map;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAEO,SAASE,iBAAiBA,CAAC;EAC9BC,GAAG;EACHC,QAAQ;EACRC;AAKJ,CAAC,EAAc;EACX,MAAMC,OAAO,GAAGF,QAAQ,CAACG,QAAQ,CAACC,0BAAe,CAAC;EAElD,IAAIF,OAAO,EAAE;IACT;AACR;AACA;AACA;IACQ,MAAMG,QAAQ,GAAGL,QAAQ,CAACM,KAAK,CAAC,GAAGF,0BAAe,GAAG,CAAC,CAACG,GAAG,CAAC,CAAW;IACtE,MAAMC,MAAM,GAAGH,QAAQ,CAACI,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;IAE7CV,GAAG,GAAGW,yBAAO,CAACC,GAAG,CAACZ,GAAG,EAAE,UAAUS,MAAM,EAAE,EAAEP,MAAM,CAAC;EACtD,CAAC,MAAM;IACH;IACAF,GAAG,GAAGW,yBAAO,CAACC,GAAG,CAACZ,GAAG,EAAE,MAAM,EAAEE,MAAM,CAAC;EAC1C;EAEA,OAAOF,GAAG;AACd","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["updateFilesInData","data","fileIdToNewFileMap","srcPrefix","Array","isArray","i","length","element","tuple","Object","entries","key","value","has","id","newFile","get","cleanSrcPrefix","endsWith","slice","name","src"],"sources":["updateFilesInData.ts"],"sourcesContent":["import { FileInput } from \"@webiny/api-file-manager/types\";\n\ninterface UpdateFilesInDataParams {\n data: Record<string, any>;\n fileIdToNewFileMap: Map<string, FileInput>;\n srcPrefix: string;\n}\n\nexport function updateFilesInData({\n data,\n fileIdToNewFileMap,\n srcPrefix\n}: UpdateFilesInDataParams) {\n if (!data || typeof data !== \"object\") {\n return;\n }\n // Recursively call function if data is an array.\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const element = data[i];\n updateFilesInData({ data: element, fileIdToNewFileMap, srcPrefix });\n }\n return;\n }\n // Main logic\n const tuple = Object.entries(data);\n for (let i = 0; i < tuple.length; i++) {\n const [key, value] = tuple[i];\n\n if (key === \"file\" && value && fileIdToNewFileMap.has(value.id)) {\n const newFile = fileIdToNewFileMap.get(value.id);\n if (!newFile) {\n continue;\n }\n\n const cleanSrcPrefix = srcPrefix.endsWith(\"/\") ? srcPrefix.slice(0, -1) : srcPrefix;\n\n value.id = newFile.id;\n value.key = newFile.key;\n value.name = newFile.name;\n value.src = `${cleanSrcPrefix}/${newFile.key}`;\n } else {\n updateFilesInData({ data: value, srcPrefix, fileIdToNewFileMap });\n }\n }\n}\n"],"mappings":";;;;;;AAQO,SAASA,iBAAiBA,CAAC;EAC9BC,IAAI;EACJC,kBAAkB;EAClBC;AACqB,CAAC,EAAE;EACxB,IAAI,CAACF,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IACnC;EACJ;EACA;EACA,IAAIG,KAAK,CAACC,OAAO,CAACJ,IAAI,CAAC,EAAE;IACrB,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGL,IAAI,CAACM,MAAM,EAAED,CAAC,EAAE,EAAE;MAClC,MAAME,OAAO,GAAGP,IAAI,CAACK,CAAC,CAAC;MACvBN,iBAAiB,CAAC;QAAEC,IAAI,EAAEO,OAAO;QAAEN,kBAAkB;QAAEC;MAAU,CAAC,CAAC;IACvE;IACA;EACJ;EACA;EACA,MAAMM,KAAK,GAAGC,MAAM,CAACC,OAAO,CAACV,IAAI,CAAC;EAClC,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGG,KAAK,CAACF,MAAM,EAAED,CAAC,EAAE,EAAE;IACnC,MAAM,CAACM,GAAG,EAAEC,KAAK,CAAC,GAAGJ,KAAK,CAACH,CAAC,CAAC;IAE7B,IAAIM,GAAG,KAAK,MAAM,IAAIC,KAAK,IAAIX,kBAAkB,CAACY,GAAG,CAACD,KAAK,CAACE,EAAE,CAAC,EAAE;MAC7D,MAAMC,OAAO,GAAGd,kBAAkB,CAACe,GAAG,CAACJ,KAAK,CAACE,EAAE,CAAC;MAChD,IAAI,CAACC,OAAO,EAAE;QACV;MACJ;MAEA,MAAME,cAAc,GAAGf,SAAS,CAACgB,QAAQ,CAAC,GAAG,CAAC,GAAGhB,SAAS,CAACiB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAGjB,SAAS;MAEnFU,KAAK,CAACE,EAAE,GAAGC,OAAO,CAACD,EAAE;MACrBF,KAAK,CAACD,GAAG,GAAGI,OAAO,CAACJ,GAAG;MACvBC,KAAK,CAACQ,IAAI,GAAGL,OAAO,CAACK,IAAI;MACzBR,KAAK,CAACS,GAAG,
|
|
1
|
+
{"version":3,"names":["updateFilesInData","data","fileIdToNewFileMap","srcPrefix","Array","isArray","i","length","element","tuple","Object","entries","key","value","has","id","newFile","get","cleanSrcPrefix","endsWith","slice","name","src"],"sources":["updateFilesInData.ts"],"sourcesContent":["import type { FileInput } from \"@webiny/api-file-manager/types\";\n\ninterface UpdateFilesInDataParams {\n data: Record<string, any>;\n fileIdToNewFileMap: Map<string, FileInput>;\n srcPrefix: string;\n}\n\nexport function updateFilesInData({\n data,\n fileIdToNewFileMap,\n srcPrefix\n}: UpdateFilesInDataParams) {\n if (!data || typeof data !== \"object\") {\n return;\n }\n // Recursively call function if data is an array.\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const element = data[i];\n updateFilesInData({ data: element, fileIdToNewFileMap, srcPrefix });\n }\n return;\n }\n // Main logic\n const tuple = Object.entries(data);\n for (let i = 0; i < tuple.length; i++) {\n const [key, value] = tuple[i];\n\n if (key === \"file\" && value && fileIdToNewFileMap.has(value.id)) {\n const newFile = fileIdToNewFileMap.get(value.id);\n if (!newFile) {\n continue;\n }\n\n const cleanSrcPrefix = srcPrefix.endsWith(\"/\") ? srcPrefix.slice(0, -1) : srcPrefix;\n\n value.id = newFile.id;\n value.key = newFile.key;\n value.name = newFile.name;\n value.src = `${cleanSrcPrefix}/${newFile.key}`;\n } else {\n updateFilesInData({ data: value, srcPrefix, fileIdToNewFileMap });\n }\n }\n}\n"],"mappings":";;;;;;AAQO,SAASA,iBAAiBA,CAAC;EAC9BC,IAAI;EACJC,kBAAkB;EAClBC;AACqB,CAAC,EAAE;EACxB,IAAI,CAACF,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IACnC;EACJ;EACA;EACA,IAAIG,KAAK,CAACC,OAAO,CAACJ,IAAI,CAAC,EAAE;IACrB,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGL,IAAI,CAACM,MAAM,EAAED,CAAC,EAAE,EAAE;MAClC,MAAME,OAAO,GAAGP,IAAI,CAACK,CAAC,CAAC;MACvBN,iBAAiB,CAAC;QAAEC,IAAI,EAAEO,OAAO;QAAEN,kBAAkB;QAAEC;MAAU,CAAC,CAAC;IACvE;IACA;EACJ;EACA;EACA,MAAMM,KAAK,GAAGC,MAAM,CAACC,OAAO,CAACV,IAAI,CAAC;EAClC,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGG,KAAK,CAACF,MAAM,EAAED,CAAC,EAAE,EAAE;IACnC,MAAM,CAACM,GAAG,EAAEC,KAAK,CAAC,GAAGJ,KAAK,CAACH,CAAC,CAAC;IAE7B,IAAIM,GAAG,KAAK,MAAM,IAAIC,KAAK,IAAIX,kBAAkB,CAACY,GAAG,CAACD,KAAK,CAACE,EAAE,CAAC,EAAE;MAC7D,MAAMC,OAAO,GAAGd,kBAAkB,CAACe,GAAG,CAACJ,KAAK,CAACE,EAAE,CAAC;MAChD,IAAI,CAACC,OAAO,EAAE;QACV;MACJ;MAEA,MAAME,cAAc,GAAGf,SAAS,CAACgB,QAAQ,CAAC,GAAG,CAAC,GAAGhB,SAAS,CAACiB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAGjB,SAAS;MAEnFU,KAAK,CAACE,EAAE,GAAGC,OAAO,CAACD,EAAE;MACrBF,KAAK,CAACD,GAAG,GAAGI,OAAO,CAACJ,GAAG;MACvBC,KAAK,CAACQ,IAAI,GAAGL,OAAO,CAACK,IAAI;MACzBR,KAAK,CAACS,GAAG,GAAG,GAAGJ,cAAc,IAAIF,OAAO,CAACJ,GAAG,EAAE;IAClD,CAAC,MAAM;MACHZ,iBAAiB,CAAC;QAAEC,IAAI,EAAEY,KAAK;QAAEV,SAAS;QAAED;MAAmB,CAAC,CAAC;IACrE;EACJ;AACJ","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PbImportExportContext } from "../../graphql/types";
|
|
2
|
-
import { File, FileInput } from "@webiny/api-file-manager/types";
|
|
3
|
-
import { FileUploadsData } from "../../types";
|
|
1
|
+
import type { PbImportExportContext } from "../../graphql/types";
|
|
2
|
+
import type { File, FileInput } from "@webiny/api-file-manager/types";
|
|
3
|
+
import type { FileUploadsData } from "../../types";
|
|
4
4
|
interface UploadAssetsParams {
|
|
5
5
|
context: PbImportExportContext;
|
|
6
6
|
files: File[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_utils","require","_uploadFilesFromS","notAPreviouslyImportedFile","importedImages","file","some","existingImportedImage","meta","originalKey","key","notAnExistingFile","existingFiles","existingFile","uploadAssets","params","context","files","fileUploadsData","oldIdToNewFileMap","Map","process","env","NODE_ENV","fileManager","listFiles","where","originalKey_in","map","importedImage","fileBeingImported","find","set","id","id_in","newFilesToImport","filter","uploadFileMap","createFilesInput","toImport","mdbid","newKey","replace","newFile","location","folderId","push","assets","uploadFilesFromS3","createFilesInBatch","exports"],"sources":["uploadAssets.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { PbImportExportContext } from \"~/graphql/types\";\nimport { File, FileInput } from \"@webiny/api-file-manager/types\";\nimport { UploadFileMap
|
|
1
|
+
{"version":3,"names":["_utils","require","_uploadFilesFromS","notAPreviouslyImportedFile","importedImages","file","some","existingImportedImage","meta","originalKey","key","notAnExistingFile","existingFiles","existingFile","uploadAssets","params","context","files","fileUploadsData","oldIdToNewFileMap","Map","process","env","NODE_ENV","fileManager","listFiles","where","originalKey_in","map","importedImage","fileBeingImported","find","set","id","id_in","newFilesToImport","filter","uploadFileMap","createFilesInput","toImport","mdbid","newKey","replace","newFile","location","folderId","push","assets","uploadFilesFromS3","createFilesInBatch","exports"],"sources":["uploadAssets.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport type { PbImportExportContext } from \"~/graphql/types\";\nimport type { File, FileInput } from \"@webiny/api-file-manager/types\";\nimport type { UploadFileMap } from \"~/import/utils/uploadFilesFromS3\";\nimport { uploadFilesFromS3 } from \"~/import/utils/uploadFilesFromS3\";\nimport type { FileUploadsData } from \"~/types\";\n\ninterface UploadAssetsParams {\n context: PbImportExportContext;\n files: File[];\n fileUploadsData: FileUploadsData;\n}\n\nfunction notAPreviouslyImportedFile(importedImages: File[]) {\n return (file: File) => {\n return !importedImages.some(\n existingImportedImage => existingImportedImage.meta.originalKey === file.key\n );\n };\n}\n\nfunction notAnExistingFile(existingFiles: File[]) {\n return (file: File) => {\n return !existingFiles.some(existingFile => existingFile.key === file.key);\n };\n}\n\nexport const uploadAssets = async (params: UploadAssetsParams) => {\n const { context, files, fileUploadsData } = params;\n\n const oldIdToNewFileMap = new Map<string, FileInput>();\n\n /**\n * This function contains logic of file download from S3.\n * Current we're not mocking zip file download from S3 in tests at the moment.\n * So, we're manually mocking it in case of test just by returning an empty object.\n */\n if (process.env.NODE_ENV === \"test\") {\n return oldIdToNewFileMap;\n }\n\n // Check if the requested files were already imported in the past.\n const [importedImages] = await context.fileManager.listFiles({\n where: { meta: { originalKey_in: files.map(file => file.key) } }\n });\n\n // Link files that were already imported.\n for (const importedImage of importedImages) {\n const fileBeingImported = files.find(file => file.key === importedImage.meta.originalKey);\n\n if (fileBeingImported) {\n oldIdToNewFileMap.set(fileBeingImported.id, importedImage);\n }\n }\n\n // Check if files with such IDs already exist.\n const [existingFiles] = await context.fileManager.listFiles({\n where: { id_in: files.map(file => file.id) }\n });\n\n const newFilesToImport = files\n .filter(notAnExistingFile(existingFiles))\n .filter(notAPreviouslyImportedFile(importedImages));\n\n // A map of temporary file keys (created during ZIP upload) to permanent file keys.\n const uploadFileMap: UploadFileMap = new Map();\n\n // Array of file inputs, to insert into the DB.\n const createFilesInput: FileInput[] = [];\n\n for (const toImport of newFilesToImport) {\n // We generate a new file id, key, and add `meta.originalKey` property to prevent duplicates on future imports.\n const id = mdbid();\n const newKey = `${id}/${toImport.key.replace(`${toImport.id}/`, \"\")}`;\n const newFile: FileInput = {\n ...toImport,\n id,\n location: {\n folderId: \"root\"\n },\n key: newKey,\n meta: { ...toImport.meta, originalKey: toImport.key }\n };\n\n createFilesInput.push(newFile);\n oldIdToNewFileMap.set(toImport.id, newFile);\n uploadFileMap.set(fileUploadsData.assets[toImport.key], newFile);\n }\n\n await uploadFilesFromS3(uploadFileMap);\n\n await context.fileManager.createFilesInBatch(createFilesIn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AAM,CAACR,QAAQ,CAAC7B,GAAG,CAAC,EAAEiC,OAAO,CAAC;EACpE;EAEA,MAAM,IAAAK,mCAAiB,EAACX,aAAa,CAAC;EAEtC,MAAMrB,OAAO,CAACQ,WAAW,CAACyB,kBAAkB,CAACX,gBAAgB,CAAC;EAE9D,OAAOnB,iBAAiB;AAC5B,CAAC;AAAC+B,OAAA,CAAApC,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { FileInput } from "@webiny/api-file-manager/types";
|
|
2
|
-
export
|
|
3
|
-
export declare function uploadFilesFromS3(fileMap: UploadFileMap): Promise<
|
|
1
|
+
import type { FileInput } from "@webiny/api-file-manager/types";
|
|
2
|
+
export type UploadFileMap = Map<string, FileInput>;
|
|
3
|
+
export declare function uploadFilesFromS3(fileMap: UploadFileMap): Promise<import("@aws-sdk/client-s3").CompleteMultipartUploadCommandOutput[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_s3Stream","require","uploadFilesFromS3","fileMap","promises","source","target","Array","from","entries","readStream","s3Stream","ws","writeStream","key","type","pipe","streamPassThrough","push","streamPassThroughUploadPromise","console","log","Promise","all"],"sources":["uploadFilesFromS3.ts"],"sourcesContent":["import { s3Stream } from \"~/export/s3Stream\";\nimport { FileInput } from \"@webiny/api-file-manager/types\";\n\nexport type UploadFileMap = Map<string, FileInput>;\n\nexport async function uploadFilesFromS3(fileMap: UploadFileMap) {\n const promises = [];\n for (const [source, target] of Array.from(fileMap.entries())) {\n // Read file.\n const readStream = await s3Stream.readStream(source);\n\n const ws = s3Stream.writeStream(target.key, target.type);\n readStream.pipe(ws.streamPassThrough);\n promises.push(ws.streamPassThroughUploadPromise);\n\n console.log(`Successfully queued file \"${target.key}\"`);\n }\n\n return Promise.all(promises);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAKO,eAAeC,iBAAiBA,CAACC,OAAsB,EAAE;EAC5D,MAAMC,QAAQ,GAAG,EAAE;EACnB,KAAK,MAAM,CAACC,MAAM,EAAEC,MAAM,CAAC,IAAIC,KAAK,CAACC,IAAI,CAACL,OAAO,CAACM,OAAO,CAAC,CAAC,CAAC,EAAE;IAC1D;IACA,MAAMC,UAAU,GAAG,MAAMC,kBAAQ,CAACD,UAAU,CAACL,MAAM,CAAC;IAEpD,MAAMO,EAAE,GAAGD,kBAAQ,CAACE,WAAW,CAACP,MAAM,CAACQ,GAAG,EAAER,MAAM,CAACS,IAAI,CAAC;IACxDL,UAAU,CAACM,IAAI,CAACJ,EAAE,CAACK,iBAAiB,CAAC;IACrCb,QAAQ,CAACc,IAAI,CAACN,EAAE,CAACO,8BAA8B,CAAC;IAEhDC,OAAO,CAACC,GAAG,
|
|
1
|
+
{"version":3,"names":["_s3Stream","require","uploadFilesFromS3","fileMap","promises","source","target","Array","from","entries","readStream","s3Stream","ws","writeStream","key","type","pipe","streamPassThrough","push","streamPassThroughUploadPromise","console","log","Promise","all"],"sources":["uploadFilesFromS3.ts"],"sourcesContent":["import { s3Stream } from \"~/export/s3Stream\";\nimport type { FileInput } from \"@webiny/api-file-manager/types\";\n\nexport type UploadFileMap = Map<string, FileInput>;\n\nexport async function uploadFilesFromS3(fileMap: UploadFileMap) {\n const promises = [];\n for (const [source, target] of Array.from(fileMap.entries())) {\n // Read file.\n const readStream = await s3Stream.readStream(source);\n\n const ws = s3Stream.writeStream(target.key, target.type);\n readStream.pipe(ws.streamPassThrough);\n promises.push(ws.streamPassThroughUploadPromise);\n\n console.log(`Successfully queued file \"${target.key}\"`);\n }\n\n return Promise.all(promises);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAKO,eAAeC,iBAAiBA,CAACC,OAAsB,EAAE;EAC5D,MAAMC,QAAQ,GAAG,EAAE;EACnB,KAAK,MAAM,CAACC,MAAM,EAAEC,MAAM,CAAC,IAAIC,KAAK,CAACC,IAAI,CAACL,OAAO,CAACM,OAAO,CAAC,CAAC,CAAC,EAAE;IAC1D;IACA,MAAMC,UAAU,GAAG,MAAMC,kBAAQ,CAACD,UAAU,CAACL,MAAM,CAAC;IAEpD,MAAMO,EAAE,GAAGD,kBAAQ,CAACE,WAAW,CAACP,MAAM,CAACQ,GAAG,EAAER,MAAM,CAACS,IAAI,CAAC;IACxDL,UAAU,CAACM,IAAI,CAACJ,EAAE,CAACK,iBAAiB,CAAC;IACrCb,QAAQ,CAACc,IAAI,CAACN,EAAE,CAACO,8BAA8B,CAAC;IAEhDC,OAAO,CAACC,GAAG,CAAC,6BAA6Bf,MAAM,CAACQ,GAAG,GAAG,CAAC;EAC3D;EAEA,OAAOQ,OAAO,CAACC,GAAG,CAACnB,QAAQ,CAAC;AAChC","ignoreList":[]}
|
package/mockSecurity.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SecurityContext, SecurityIdentity } from "@webiny/api-security/types";
|
|
1
|
+
import type { SecurityContext, SecurityIdentity } from "@webiny/api-security/types";
|
|
2
2
|
export declare const mockSecurity: (identity: SecurityIdentity, context: SecurityContext) => void;
|
package/mockSecurity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["mockSecurity","identity","context","security","setIdentity","exports"],"sources":["mockSecurity.ts"],"sourcesContent":["import { SecurityContext, SecurityIdentity } from \"@webiny/api-security/types\";\n\nexport const mockSecurity = (identity: SecurityIdentity, context: SecurityContext) => {\n context.security.setIdentity(identity);\n};\n"],"mappings":";;;;;;AAEO,MAAMA,YAAY,GAAGA,CAACC,QAA0B,EAAEC,OAAwB,KAAK;EAClFA,OAAO,CAACC,QAAQ,CAACC,WAAW,CAACH,QAAQ,CAAC;AAC1C,CAAC;AAACI,OAAA,CAAAL,YAAA,GAAAA,YAAA"}
|
|
1
|
+
{"version":3,"names":["mockSecurity","identity","context","security","setIdentity","exports"],"sources":["mockSecurity.ts"],"sourcesContent":["import type { SecurityContext, SecurityIdentity } from \"@webiny/api-security/types\";\n\nexport const mockSecurity = (identity: SecurityIdentity, context: SecurityContext) => {\n context.security.setIdentity(identity);\n};\n"],"mappings":";;;;;;AAEO,MAAMA,YAAY,GAAGA,CAACC,QAA0B,EAAEC,OAAwB,KAAK;EAClFA,OAAO,CAACC,QAAQ,CAACC,WAAW,CAACH,QAAQ,CAAC;AAC1C,CAAC;AAACI,OAAA,CAAAL,YAAA,GAAAA,YAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-page-builder-import-export",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.2aaa1916d9",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pbie:base"
|
|
@@ -14,61 +14,53 @@
|
|
|
14
14
|
"author": "Webiny Ltd",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"@
|
|
19
|
-
"@webiny/api": "0.0.0-unstable.
|
|
20
|
-
"@webiny/api-
|
|
21
|
-
"@webiny/api-
|
|
22
|
-
"@webiny/api-
|
|
23
|
-
"@webiny/
|
|
24
|
-
"@webiny/
|
|
25
|
-
"@webiny/
|
|
26
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
27
|
-
"@webiny/handler-
|
|
28
|
-
"@webiny/
|
|
29
|
-
"@webiny/
|
|
30
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
31
|
-
"
|
|
32
|
-
"archiver": "5.3.1",
|
|
33
|
-
"commodo-fields-object": "1.0.6",
|
|
17
|
+
"@smithy/node-http-handler": "2.1.6",
|
|
18
|
+
"@webiny/api": "0.0.0-unstable.2aaa1916d9",
|
|
19
|
+
"@webiny/api-file-manager": "0.0.0-unstable.2aaa1916d9",
|
|
20
|
+
"@webiny/api-form-builder": "0.0.0-unstable.2aaa1916d9",
|
|
21
|
+
"@webiny/api-page-builder": "0.0.0-unstable.2aaa1916d9",
|
|
22
|
+
"@webiny/api-security": "0.0.0-unstable.2aaa1916d9",
|
|
23
|
+
"@webiny/aws-sdk": "0.0.0-unstable.2aaa1916d9",
|
|
24
|
+
"@webiny/error": "0.0.0-unstable.2aaa1916d9",
|
|
25
|
+
"@webiny/handler": "0.0.0-unstable.2aaa1916d9",
|
|
26
|
+
"@webiny/handler-aws": "0.0.0-unstable.2aaa1916d9",
|
|
27
|
+
"@webiny/handler-graphql": "0.0.0-unstable.2aaa1916d9",
|
|
28
|
+
"@webiny/pubsub": "0.0.0-unstable.2aaa1916d9",
|
|
29
|
+
"@webiny/tasks": "0.0.0-unstable.2aaa1916d9",
|
|
30
|
+
"@webiny/utils": "0.0.0-unstable.2aaa1916d9",
|
|
31
|
+
"archiver": "7.0.1",
|
|
34
32
|
"dot-prop-immutable": "2.1.1",
|
|
35
|
-
"fs-extra": "
|
|
33
|
+
"fs-extra": "11.2.0",
|
|
36
34
|
"load-json-file": "6.2.0",
|
|
37
35
|
"lodash": "4.17.21",
|
|
38
|
-
"node-fetch": "2.6.
|
|
39
|
-
"stream": "0.0.
|
|
36
|
+
"node-fetch": "2.6.7",
|
|
37
|
+
"stream": "0.0.3",
|
|
40
38
|
"uniqid": "5.4.0",
|
|
41
|
-
"yauzl": "2.10.0"
|
|
39
|
+
"yauzl": "2.10.0",
|
|
40
|
+
"zod": "3.23.8"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
|
-
"@babel/cli": "7.22.6",
|
|
45
|
-
"@babel/core": "7.22.8",
|
|
46
|
-
"@babel/plugin-proposal-export-default-from": "7.18.10",
|
|
47
|
-
"@babel/preset-env": "7.22.7",
|
|
48
|
-
"@babel/preset-typescript": "7.22.5",
|
|
49
43
|
"@types/archiver": "5.3.1",
|
|
50
44
|
"@types/node-fetch": "2.6.2",
|
|
51
45
|
"@types/yauzl": "2.10.0",
|
|
52
|
-
"@webiny/api-authentication": "0.0.0-unstable.
|
|
53
|
-
"@webiny/api-dynamodb-to-elasticsearch": "0.0.0-unstable.
|
|
54
|
-
"@webiny/api-tenancy": "0.0.0-unstable.
|
|
55
|
-
"@webiny/api-wcp": "0.0.0-unstable.
|
|
56
|
-
"@webiny/
|
|
57
|
-
"@webiny/
|
|
58
|
-
"
|
|
59
|
-
"jest": "29.5.0",
|
|
46
|
+
"@webiny/api-authentication": "0.0.0-unstable.2aaa1916d9",
|
|
47
|
+
"@webiny/api-dynamodb-to-elasticsearch": "0.0.0-unstable.2aaa1916d9",
|
|
48
|
+
"@webiny/api-tenancy": "0.0.0-unstable.2aaa1916d9",
|
|
49
|
+
"@webiny/api-wcp": "0.0.0-unstable.2aaa1916d9",
|
|
50
|
+
"@webiny/db": "0.0.0-unstable.2aaa1916d9",
|
|
51
|
+
"@webiny/project-utils": "0.0.0-unstable.2aaa1916d9",
|
|
52
|
+
"jest": "29.7.0",
|
|
60
53
|
"jest-dynalite": "3.6.1",
|
|
61
|
-
"rimraf": "
|
|
62
|
-
"
|
|
63
|
-
"typescript": "4.7.4"
|
|
54
|
+
"rimraf": "6.0.1",
|
|
55
|
+
"typescript": "5.3.3"
|
|
64
56
|
},
|
|
65
57
|
"publishConfig": {
|
|
66
58
|
"access": "public",
|
|
67
59
|
"directory": "dist"
|
|
68
60
|
},
|
|
69
61
|
"scripts": {
|
|
70
|
-
"build": "
|
|
71
|
-
"watch": "
|
|
62
|
+
"build": "node ../cli/bin.js run build",
|
|
63
|
+
"watch": "node ../cli/bin.js run watch"
|
|
72
64
|
},
|
|
73
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "2aaa1916d95b4fb2aa0cc2543f60934c2f3d969c"
|
|
74
66
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cleanup of the child tasks.
|
|
3
|
+
* This code will remove all the child tasks and their logs, which have no errors in them.
|
|
4
|
+
*/
|
|
5
|
+
import type { ITask, Context } from "@webiny/tasks";
|
|
6
|
+
export interface IChildTasksCleanupExecuteParams {
|
|
7
|
+
context: Context;
|
|
8
|
+
task: ITask;
|
|
9
|
+
}
|
|
10
|
+
export declare class ChildTasksCleanup {
|
|
11
|
+
execute(params: IChildTasksCleanupExecuteParams): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ChildTasksCleanup = void 0;
|
|
7
|
+
var _tasks = require("@webiny/tasks");
|
|
8
|
+
/**
|
|
9
|
+
* Cleanup of the child tasks.
|
|
10
|
+
* This code will remove all the child tasks and their logs, which have no errors in them.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
class ChildTasksCleanup {
|
|
14
|
+
async execute(params) {
|
|
15
|
+
const {
|
|
16
|
+
context,
|
|
17
|
+
task
|
|
18
|
+
} = params;
|
|
19
|
+
const {
|
|
20
|
+
items: childTasks
|
|
21
|
+
} = await context.tasks.listTasks({
|
|
22
|
+
where: {
|
|
23
|
+
parentId: task.id
|
|
24
|
+
},
|
|
25
|
+
// Really doubtful there will be more than 10k of child tasks.
|
|
26
|
+
limit: 100000
|
|
27
|
+
});
|
|
28
|
+
if (childTasks.length === 0) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const childTaskIdList = childTasks.map(childTask => childTask.id);
|
|
32
|
+
const {
|
|
33
|
+
items: childLogs
|
|
34
|
+
} = await context.tasks.listLogs({
|
|
35
|
+
where: {
|
|
36
|
+
task_in: childTaskIdList
|
|
37
|
+
},
|
|
38
|
+
limit: 100000
|
|
39
|
+
});
|
|
40
|
+
const deletedChildTaskLogIdList = [];
|
|
41
|
+
/**
|
|
42
|
+
* First, we need to remove all the logs which have no errors.
|
|
43
|
+
*/
|
|
44
|
+
for (const log of childLogs) {
|
|
45
|
+
if (log.items.some(item => item.type === _tasks.TaskLogItemType.ERROR)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
await context.tasks.deleteLog(log.id);
|
|
49
|
+
if (deletedChildTaskLogIdList.includes(log.task)) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
deletedChildTaskLogIdList.push(log.task);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Now we can remove the tasks.
|
|
56
|
+
*/
|
|
57
|
+
for (const childTaskId of deletedChildTaskLogIdList) {
|
|
58
|
+
await context.tasks.deleteTask(childTaskId);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.ChildTasksCleanup = ChildTasksCleanup;
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=ChildTasksCleanup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_tasks","require","ChildTasksCleanup","execute","params","context","task","items","childTasks","tasks","listTasks","where","parentId","id","limit","length","childTaskIdList","map","childTask","childLogs","listLogs","task_in","deletedChildTaskLogIdList","log","some","item","type","TaskLogItemType","ERROR","deleteLog","includes","push","childTaskId","deleteTask","exports"],"sources":["ChildTasksCleanup.ts"],"sourcesContent":["/**\n * Cleanup of the child tasks.\n * This code will remove all the child tasks and their logs, which have no errors in them.\n */\nimport type { ITask, Context } from \"@webiny/tasks\";\nimport { TaskLogItemType } from \"@webiny/tasks\";\n\nexport interface IChildTasksCleanupExecuteParams {\n context: Context;\n task: ITask;\n}\nexport class ChildTasksCleanup {\n public async execute(params: IChildTasksCleanupExecuteParams): Promise<void> {\n const { context, task } = params;\n\n const { items: childTasks } = await context.tasks.listTasks({\n where: {\n parentId: task.id\n },\n // Really doubtful there will be more than 10k of child tasks.\n limit: 100000\n });\n if (childTasks.length === 0) {\n return;\n }\n\n const childTaskIdList = childTasks.map(childTask => childTask.id);\n\n const { items: childLogs } = await context.tasks.listLogs({\n where: {\n task_in: childTaskIdList\n },\n limit: 100000\n });\n\n const deletedChildTaskLogIdList: string[] = [];\n /**\n * First, we need to remove all the logs which have no errors.\n */\n for (const log of childLogs) {\n if (log.items.some(item => item.type === TaskLogItemType.ERROR)) {\n continue;\n }\n await context.tasks.deleteLog(log.id);\n if (deletedChildTaskLogIdList.includes(log.task)) {\n continue;\n }\n deletedChildTaskLogIdList.push(log.task);\n }\n /**\n * Now we can remove the tasks.\n */\n for (const childTaskId of deletedChildTaskLogIdList) {\n await context.tasks.deleteTask(childTaskId);\n }\n }\n}\n"],"mappings":";;;;;;AAKA,IAAAA,MAAA,GAAAC,OAAA;AALA;AACA;AACA;AACA;;AAQO,MAAMC,iBAAiB,CAAC;EAC3B,MAAaC,OAAOA,CAACC,MAAuC,EAAiB;IACzE,MAAM;MAAEC,OAAO;MAAEC;IAAK,CAAC,GAAGF,MAAM;IAEhC,MAAM;MAAEG,KAAK,EAAEC;IAAW,CAAC,GAAG,MAAMH,OAAO,CAACI,KAAK,CAACC,SAAS,CAAC;MACxDC,KAAK,EAAE;QACHC,QAAQ,EAAEN,IAAI,CAACO;MACnB,CAAC;MACD;MACAC,KAAK,EAAE;IACX,CAAC,CAAC;IACF,IAAIN,UAAU,CAACO,MAAM,KAAK,CAAC,EAAE;MACzB;IACJ;IAEA,MAAMC,eAAe,GAAGR,UAAU,CAACS,GAAG,CAACC,SAAS,IAAIA,SAAS,CAACL,EAAE,CAAC;IAEjE,MAAM;MAAEN,KAAK,EAAEY;IAAU,CAAC,GAAG,MAAMd,OAAO,CAACI,KAAK,CAACW,QAAQ,CAAC;MACtDT,KAAK,EAAE;QACHU,OAAO,EAAEL;MACb,CAAC;MACDF,KAAK,EAAE;IACX,CAAC,CAAC;IAEF,MAAMQ,yBAAmC,GAAG,EAAE;IAC9C;AACR;AACA;IACQ,KAAK,MAAMC,GAAG,IAAIJ,SAAS,EAAE;MACzB,IAAII,GAAG,CAAChB,KAAK,CAACiB,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACC,IAAI,KAAKC,sBAAe,CAACC,KAAK,CAAC,EAAE;QAC7D;MACJ;MACA,MAAMvB,OAAO,CAACI,KAAK,CAACoB,SAAS,CAACN,GAAG,CAACV,EAAE,CAAC;MACrC,IAAIS,yBAAyB,CAACQ,QAAQ,CAACP,GAAG,CAACjB,IAAI,CAAC,EAAE;QAC9C;MACJ;MACAgB,yBAAyB,CAACS,IAAI,CAACR,GAAG,CAACjB,IAAI,CAAC;IAC5C;IACA;AACR;AACA;IACQ,KAAK,MAAM0B,WAAW,IAAIV,yBAAyB,EAAE;MACjD,MAAMjB,OAAO,CAACI,KAAK,CAACwB,UAAU,CAACD,WAAW,CAAC;IAC/C;EACJ;AACJ;AAACE,OAAA,CAAAhC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
package/tasks/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createTasks: () => (import("@webiny/tasks").TaskDefinitionPlugin<import("../types").PbImportExportContext, import("../export/pages/types").IExportPagesControllerInput, import("../export/pages/types").IExportPagesControllerOutput> | import("@webiny/tasks").TaskDefinitionPlugin<import("../types").PbImportExportContext, import("../import/pages/types").IImportPagesControllerInput, import("../import/pages/types").IImportPagesControllerOutput> | import("@webiny/tasks").TaskDefinitionPlugin<import("../types").PbImportExportContext, import("../export/pages/types").IExportPagesZipPagesInput, import("../export/pages/types").IExportPagesZipPagesOutput> | import("@webiny/tasks").TaskDefinitionPlugin<import("../types").PbImportExportContext, import("../export/pages/types").IExportPagesCleanupInput, import("@webiny/tasks").ITaskResponseDoneResultOutput> | import("@webiny/tasks").TaskDefinitionPlugin<import("../types").PbImportExportContext, import("../import/pages/types").IImportPagesProcessPagesInput, import("../import/pages/types").IImportPagesProcessPagesOutput>)[][];
|
package/tasks/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createTasks = void 0;
|
|
7
|
+
var _pages = require("./pages");
|
|
8
|
+
const createTasks = () => {
|
|
9
|
+
return [(0, _pages.createPagesTasks)()];
|
|
10
|
+
};
|
|
11
|
+
exports.createTasks = createTasks;
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_pages","require","createTasks","createPagesTasks","exports"],"sources":["index.ts"],"sourcesContent":["import { createPagesTasks } from \"./pages\";\n\nexport const createTasks = () => {\n return [createPagesTasks()];\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEO,MAAMC,WAAW,GAAGA,CAAA,KAAM;EAC7B,OAAO,CAAC,IAAAC,uBAAgB,EAAC,CAAC,CAAC;AAC/B,CAAC;AAACC,OAAA,CAAAF,WAAA,GAAAA,WAAA","ignoreList":[]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { IExportPagesCleanupInput } from "../../export/pages/types";
|
|
2
|
+
import type { PbImportExportContext } from "../../graphql/types";
|
|
3
|
+
export declare const createExportPagesCleanupTask: () => import("@webiny/tasks").TaskDefinitionPlugin<PbImportExportContext, IExportPagesCleanupInput, import("@webiny/tasks").ITaskResponseDoneResultOutput>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createExportPagesCleanupTask = void 0;
|
|
7
|
+
var _tasks = require("@webiny/tasks");
|
|
8
|
+
var _types = require("../../export/pages/types");
|
|
9
|
+
const createExportPagesCleanupTask = () => {
|
|
10
|
+
return (0, _tasks.createPrivateTaskDefinition)({
|
|
11
|
+
id: _types.PageExportTask.Cleanup,
|
|
12
|
+
title: "Page Builder - Export Pages Cleanup",
|
|
13
|
+
description: "Export pages from the Page Builder - cleanup.",
|
|
14
|
+
maxIterations: 1,
|
|
15
|
+
run: async param => {
|
|
16
|
+
const {
|
|
17
|
+
response,
|
|
18
|
+
isAborted
|
|
19
|
+
} = param;
|
|
20
|
+
/**
|
|
21
|
+
* We always need to check task status.
|
|
22
|
+
*/
|
|
23
|
+
if (isAborted()) {
|
|
24
|
+
return response.aborted();
|
|
25
|
+
}
|
|
26
|
+
const {
|
|
27
|
+
ExportPagesCleanup
|
|
28
|
+
} = await import(/* webpackChunkName: "ExportPagesCleanup" */"../../export/pages/ExportPagesCleanup");
|
|
29
|
+
const exportPagesCleanup = new ExportPagesCleanup();
|
|
30
|
+
return await exportPagesCleanup.execute(param);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
exports.createExportPagesCleanupTask = createExportPagesCleanupTask;
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=exportPagesCleanupTask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_tasks","require","_types","createExportPagesCleanupTask","createPrivateTaskDefinition","id","PageExportTask","Cleanup","title","description","maxIterations","run","param","response","isAborted","aborted","ExportPagesCleanup","exportPagesCleanup","execute","exports"],"sources":["exportPagesCleanupTask.ts"],"sourcesContent":["import { createPrivateTaskDefinition } from \"@webiny/tasks\";\nimport type { IExportPagesCleanupInput } from \"~/export/pages/types\";\nimport { PageExportTask } from \"~/export/pages/types\";\nimport type { PbImportExportContext } from \"~/graphql/types\";\n\nexport const createExportPagesCleanupTask = () => {\n return createPrivateTaskDefinition<PbImportExportContext, IExportPagesCleanupInput>({\n id: PageExportTask.Cleanup,\n title: \"Page Builder - Export Pages Cleanup\",\n description: \"Export pages from the Page Builder - cleanup.\",\n maxIterations: 1,\n run: async param => {\n const { response, isAborted } = param;\n /**\n * We always need to check task status.\n */\n if (isAborted()) {\n return response.aborted();\n }\n\n const { ExportPagesCleanup } = await import(\n /* webpackChunkName: \"ExportPagesCleanup\" */ \"~/export/pages/ExportPagesCleanup\"\n );\n\n const exportPagesCleanup = new ExportPagesCleanup();\n return await exportPagesCleanup.execute(param);\n }\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAGO,MAAME,4BAA4B,GAAGA,CAAA,KAAM;EAC9C,OAAO,IAAAC,kCAA2B,EAAkD;IAChFC,EAAE,EAAEC,qBAAc,CAACC,OAAO;IAC1BC,KAAK,EAAE,qCAAqC;IAC5CC,WAAW,EAAE,+CAA+C;IAC5DC,aAAa,EAAE,CAAC;IAChBC,GAAG,EAAE,MAAMC,KAAK,IAAI;MAChB,MAAM;QAAEC,QAAQ;QAAEC;MAAU,CAAC,GAAGF,KAAK;MACrC;AACZ;AACA;MACY,IAAIE,SAAS,CAAC,CAAC,EAAE;QACb,OAAOD,QAAQ,CAACE,OAAO,CAAC,CAAC;MAC7B;MAEA,MAAM;QAAEC;MAAmB,CAAC,GAAG,MAAM,MAAM,CACvC,mFACJ,CAAC;MAED,MAAMC,kBAAkB,GAAG,IAAID,kBAAkB,CAAC,CAAC;MACnD,OAAO,MAAMC,kBAAkB,CAACC,OAAO,CAACN,KAAK,CAAC;IAClD;EACJ,CAAC,CAAC;AACN,CAAC;AAACO,OAAA,CAAAhB,4BAAA,GAAAA,4BAAA","ignoreList":[]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PbImportExportContext } from "../../graphql/types";
|
|
2
|
+
import type { IExportPagesControllerInput, IExportPagesControllerOutput } from "../../export/pages/types";
|
|
3
|
+
export declare const createExportPagesControllerTask: () => import("@webiny/tasks").TaskDefinitionPlugin<PbImportExportContext, IExportPagesControllerInput, IExportPagesControllerOutput>;
|