@webiny/api-page-builder-import-export 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7c9e8fbfd6
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 +2 -2
- package/client.js +12 -25
- package/client.js.map +1 -1
- package/export/combine/blocksHandler.d.ts +6 -0
- package/export/combine/blocksHandler.js +101 -0
- package/export/combine/blocksHandler.js.map +1 -0
- package/export/combine/formsHandler.d.ts +6 -0
- package/export/combine/formsHandler.js +101 -0
- package/export/combine/formsHandler.js.map +1 -0
- package/{exportPages → export}/combine/index.d.ts +4 -3
- package/export/combine/index.js +44 -0
- package/export/combine/index.js.map +1 -0
- package/export/combine/templatesHandler.d.ts +6 -0
- package/export/combine/templatesHandler.js +101 -0
- package/export/combine/templatesHandler.js.map +1 -0
- 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 +6 -0
- package/export/process/blocksHandler.js +169 -0
- package/export/process/blocksHandler.js.map +1 -0
- package/export/process/exporters/BlockExporter.d.ts +12 -0
- package/export/process/exporters/BlockExporter.js +57 -0
- package/export/process/exporters/BlockExporter.js.map +1 -0
- package/export/process/exporters/FormExporter.d.ts +9 -0
- package/export/process/exporters/FormExporter.js +36 -0
- package/export/process/exporters/FormExporter.js.map +1 -0
- package/export/process/exporters/PageExporter.d.ts +18 -0
- package/export/process/exporters/PageExporter.js +59 -0
- package/export/process/exporters/PageExporter.js.map +1 -0
- package/export/process/exporters/PageTemplateExporter.d.ts +11 -0
- package/export/process/exporters/PageTemplateExporter.js +58 -0
- package/export/process/exporters/PageTemplateExporter.js.map +1 -0
- package/export/process/formsHandler.d.ts +6 -0
- package/export/process/formsHandler.js +189 -0
- package/export/process/formsHandler.js.map +1 -0
- package/{exportPages → export}/process/index.d.ts +5 -7
- package/export/process/index.js +41 -0
- package/export/process/index.js.map +1 -0
- package/export/process/templatesHandler.d.ts +6 -0
- package/export/process/templatesHandler.js +168 -0
- package/export/process/templatesHandler.js.map +1 -0
- package/export/s3Stream.d.ts +36 -0
- package/{exportPages → export}/s3Stream.js +27 -42
- package/export/s3Stream.js.map +1 -0
- package/export/utils.d.ts +24 -0
- package/export/utils.js +169 -0
- package/export/utils.js.map +1 -0
- package/{exportPages → export}/zipper.d.ts +12 -10
- package/export/zipper.js +120 -0
- package/export/zipper.js.map +1 -0
- package/graphql/crud/blocks.crud.d.ts +4 -0
- package/graphql/crud/blocks.crud.js +158 -0
- package/graphql/crud/blocks.crud.js.map +1 -0
- package/graphql/crud/forms.crud.d.ts +4 -0
- package/graphql/crud/forms.crud.js +162 -0
- package/graphql/crud/forms.crud.js.map +1 -0
- package/graphql/crud/importExportTasks.crud.d.ts +5 -0
- package/graphql/crud/importExportTasks.crud.js +396 -0
- package/graphql/crud/importExportTasks.crud.js.map +1 -0
- package/graphql/crud/pages.crud.d.ts +2 -2
- package/graphql/crud/pages.crud.js +241 -138
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.d.ts +4 -0
- package/graphql/crud/templates.crud.js +156 -0
- package/graphql/crud/templates.crud.js.map +1 -0
- package/graphql/crud.d.ts +2 -2
- package/graphql/crud.js +7 -7
- package/graphql/crud.js.map +1 -1
- package/graphql/graphql/blocks.gql.d.ts +4 -0
- package/graphql/graphql/blocks.gql.js +52 -0
- package/graphql/graphql/blocks.gql.js.map +1 -0
- 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/importExportTasks.gql.d.ts +4 -0
- package/graphql/graphql/importExportTasks.gql.js +75 -0
- package/graphql/graphql/importExportTasks.gql.js.map +1 -0
- package/graphql/graphql/pages.gql.d.ts +3 -3
- package/graphql/graphql/pages.gql.js +104 -26
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.d.ts +4 -0
- package/graphql/graphql/templates.gql.js +52 -0
- package/graphql/graphql/templates.gql.js.map +1 -0
- package/graphql/graphql/utils/resolve.d.ts +3 -3
- package/graphql/graphql/utils/resolve.js +15 -7
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/graphql.d.ts +1 -1
- package/graphql/graphql.js +6 -6
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +4 -6
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +237 -37
- package/graphql/types.js +3 -1
- package/graphql/types.js.map +1 -1
- package/import/constants.d.ts +3 -0
- package/import/constants.js +13 -0
- package/import/constants.js.map +1 -0
- package/import/create/blocksHandler.d.ts +3 -0
- package/import/create/blocksHandler.js +101 -0
- package/import/create/blocksHandler.js.map +1 -0
- package/import/create/formsHandler.d.ts +3 -0
- package/import/create/formsHandler.js +105 -0
- package/import/create/formsHandler.js.map +1 -0
- package/import/create/index.d.ts +24 -0
- package/import/create/index.js +44 -0
- package/import/create/index.js.map +1 -0
- package/import/create/pagesHandler.d.ts +3 -0
- package/import/create/pagesHandler.js +105 -0
- package/import/create/pagesHandler.js.map +1 -0
- package/import/create/templatesHandler.d.ts +3 -0
- package/import/create/templatesHandler.js +101 -0
- package/import/create/templatesHandler.js.map +1 -0
- 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/pages/process/importPage.d.ts +10 -0
- package/import/pages/process/importPage.js +94 -0
- 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 +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 +101 -0
- package/import/process/blocks/importBlock.js.map +1 -0
- package/import/process/forms/formsHandler.d.ts +3 -0
- package/import/process/forms/formsHandler.js +178 -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 +47 -0
- package/import/process/forms/importForm.js.map +1 -0
- package/{importPages → import}/process/index.d.ts +6 -4
- package/import/process/index.js +41 -0
- package/import/process/index.js.map +1 -0
- package/import/process/templates/importTemplate.d.ts +11 -0
- package/import/process/templates/importTemplate.js +70 -0
- package/import/process/templates/importTemplate.js.map +1 -0
- package/import/process/templates/templatesHandler.d.ts +3 -0
- package/import/process/templates/templatesHandler.js +174 -0
- package/import/process/templates/templatesHandler.js.map +1 -0
- package/import/utils/deleteS3Folder.d.ts +1 -0
- package/import/utils/deleteS3Folder.js +21 -0
- package/import/utils/deleteS3Folder.js.map +1 -0
- package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
- package/import/utils/extractAndUploadZipFileContents.js +126 -0
- package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
- package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
- package/import/utils/extractZipAndUploadToS3.js +100 -0
- package/import/utils/extractZipAndUploadToS3.js.map +1 -0
- package/import/utils/getFileNameWithoutExt.d.ts +1 -0
- package/import/utils/getFileNameWithoutExt.js +13 -0
- package/import/utils/getFileNameWithoutExt.js.map +1 -0
- package/import/utils/index.d.ts +9 -0
- package/import/utils/index.js +106 -0
- package/import/utils/index.js.map +1 -0
- package/import/utils/initialStats.d.ts +7 -0
- package/import/utils/initialStats.js +18 -0
- package/import/utils/initialStats.js.map +1 -0
- package/import/utils/prepareDataDirMap.d.ts +6 -0
- package/import/utils/prepareDataDirMap.js +31 -0
- package/import/utils/prepareDataDirMap.js.map +1 -0
- package/import/utils/updateFilesInData.d.ts +8 -0
- package/import/utils/updateFilesInData.js +51 -0
- package/import/utils/updateFilesInData.js.map +1 -0
- package/import/utils/uploadAssets.d.ts +10 -0
- package/import/utils/uploadAssets.js +92 -0
- package/import/utils/uploadAssets.js.map +1 -0
- package/import/utils/uploadFilesFromS3.d.ts +3 -0
- package/import/utils/uploadFilesFromS3.js +21 -0
- package/import/utils/uploadFilesFromS3.js.map +1 -0
- package/mockSecurity.d.ts +1 -1
- package/mockSecurity.js +2 -3
- package/mockSecurity.js.map +1 -1
- package/package.json +36 -52
- 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 +83 -65
- package/types.js +68 -21
- 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/exportPages/combine/index.js +0 -114
- package/exportPages/combine/index.js.map +0 -1
- package/exportPages/process/index.js +0 -208
- package/exportPages/process/index.js.map +0 -1
- package/exportPages/s3Stream.d.ts +0 -31
- package/exportPages/s3Stream.js.map +0 -1
- package/exportPages/utils.d.ts +0 -13
- package/exportPages/utils.js +0 -113
- package/exportPages/utils.js.map +0 -1
- package/exportPages/zipper.js +0 -135
- package/exportPages/zipper.js.map +0 -1
- package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
- package/graphql/crud/pageImportExportTasks.crud.js +0 -411
- package/graphql/crud/pageImportExportTasks.crud.js.map +0 -1
- package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
- package/graphql/graphql/pageImportExportTasks.gql.js +0 -80
- package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
- package/importPages/create/index.d.ts +0 -22
- package/importPages/create/index.js +0 -118
- package/importPages/create/index.js.map +0 -1
- package/importPages/process/index.js +0 -185
- package/importPages/process/index.js.map +0 -1
- package/importPages/utils.d.ts +0 -50
- package/importPages/utils.js +0 -570
- package/importPages/utils.js.map +0 -1
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_types","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","ExportRevisionType","ImportExportTaskStatus"],"sources":["types.ts"],"sourcesContent":["export * from \"./graphql/types\";\n\n// Entities.\nexport enum ExportRevisionType {\n PUBLISHED = \"published\",\n LATEST = \"latest\"\n}\n\nexport enum ImportExportTaskStatus {\n PENDING = \"pending\",\n PROCESSING = \"processing\",\n COMPLETED = \"completed\",\n FAILED = \"failed\"\n}\n\nexport interface ImportExportTaskStats {\n [ImportExportTaskStatus.PENDING]: number;\n [ImportExportTaskStatus.PROCESSING]: number;\n [ImportExportTaskStatus.COMPLETED]: number;\n [ImportExportTaskStatus.FAILED]: number;\n total: number;\n}\n\ninterface CreatedBy {\n id: string;\n type: string;\n displayName: string | null;\n}\n\nexport interface ImportExportTask {\n id: string;\n parent: string;\n status: ImportExportTaskStatus;\n data: Record<string, any>;\n stats: ImportExportTaskStats;\n error: Record<string, any>;\n input: Record<string, any>;\n createdOn: string;\n createdBy: CreatedBy;\n tenant: string;\n locale: string;\n}\n\nexport interface File {\n id: string;\n src: string;\n}\n\nexport interface MetaResponse {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport interface ImportExportTaskStorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport interface ImportExportTaskStorageOperationsListParams {\n where: {\n tenant: string;\n locale: string;\n };\n sort?: string[];\n limit?: number;\n after?: string | null;\n}\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport type ImportExportTaskStorageOperationsListResponse = [ImportExportTask[], MetaResponse];\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport interface ImportExportTaskStorageOperationsCreateParams {\n input: Record<string, any>;\n task: ImportExportTask;\n}\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport interface ImportExportTaskStorageOperationsUpdateParams {\n input: Record<string, any>;\n original: ImportExportTask;\n task: ImportExportTask;\n}\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport interface ImportExportTaskStorageOperationsDeleteParams {\n task: ImportExportTask;\n}\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport interface ImportExportTaskStorageOperationsGetSubTaskParams {\n where: {\n id: string;\n parent: string;\n tenant: string;\n locale: string;\n };\n}\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport interface ImportExportTaskStorageOperationsListSubTaskParams {\n where: {\n tenant: string;\n locale: string;\n parent: string;\n status: ImportExportTaskStatus;\n createdBy?: string;\n };\n sort?: string[];\n limit?: number;\n after?: string | null;\n}\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport type ImportExportTaskStorageOperationsListSubTaskResponse = [\n ImportExportTask[],\n MetaResponse\n];\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport interface ImportExportTaskStorageOperationsCreateSubTaskParams {\n input: Record<string, any>;\n subTask: ImportExportTask;\n}\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport interface ImportExportTaskStorageOperationsUpdateSubTaskParams {\n input: Record<string, any>;\n original: ImportExportTask;\n subTask: ImportExportTask;\n}\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport interface ImportExportTaskStorageOperationsUpdateTaskStatsParams {\n input: {\n prevStatus: ImportExportTaskStatus;\n nextStatus: ImportExportTaskStatus;\n };\n original: ImportExportTask;\n}\n\n/**\n * @category StorageOperations\n * @category ImportExportTaskStorageOperations\n */\nexport interface ImportExportTaskStorageOperations {\n /**\n * Get a single import export task item by given params.\n */\n getTask(params: ImportExportTaskStorageOperationsGetParams): Promise<ImportExportTask | null>;\n\n /**\n * Get all import export tasks by given params.\n */\n listTasks(\n params: ImportExportTaskStorageOperationsListParams\n ): Promise<ImportExportTaskStorageOperationsListResponse>;\n\n createTask(params: ImportExportTaskStorageOperationsCreateParams): Promise<ImportExportTask>;\n\n updateTask(params: ImportExportTaskStorageOperationsUpdateParams): Promise<ImportExportTask>;\n\n deleteTask(params: ImportExportTaskStorageOperationsDeleteParams): Promise<ImportExportTask>;\n\n updateTaskStats(\n params: ImportExportTaskStorageOperationsUpdateTaskStatsParams\n ): Promise<ImportExportTask>;\n\n /**\n * Get a single import export sub-task item by given params.\n */\n getSubTask(\n params: ImportExportTaskStorageOperationsGetSubTaskParams\n ): Promise<ImportExportTask | null>;\n\n /**\n * Get all import export sub-tasks by given params.\n */\n listSubTasks(\n params: ImportExportTaskStorageOperationsListSubTaskParams\n ): Promise<ImportExportTaskStorageOperationsListSubTaskResponse>;\n\n createSubTask(\n params: ImportExportTaskStorageOperationsCreateSubTaskParams\n ): Promise<ImportExportTask>;\n\n updateSubTask(\n params: ImportExportTaskStorageOperationsUpdateSubTaskParams\n ): Promise<ImportExportTask>;\n}\n\nexport interface FileUploadsData {\n /**\n * Location of export data file. Export data contains the relevant entity data (block, page, template), and an\n * array of file objects, exported from the DB, that need to be imported.\n *\n * Example:\n * 'IMPORTS/8lf6y7xp5/8lf6x9v68-header-1/8lf6x9v69-header-1/Header #1.json'\n */\n data: string;\n /**\n * Example:\n * '8ldspraka-9l9iaffak-1.jpeg': 'IMPORTS/8lf6y7xp5/8lf6x9v68-header-1/assets/8ldspraka-9l9iaffak-1.jpeg',\n * '8ldwyq8ao-pb-editor-page-element-rzfKWtdTWN.png': 'IMPORTS/8lf6y7xp5/8lf6x9v69-header-1/assets/8ldwyq8ao-pb-editor-page-element-rzfKWtdTWN.png'\n */\n assets: Record<string, string>;\n}\n\nexport interface ImportData {\n assets: Record<string, string>;\n data: string;\n key: string;\n}\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AAEA;AAAA,IACYS,kBAAkB,GAAAJ,OAAA,CAAAI,kBAAA,0BAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA;AAAA,IAKlBC,sBAAsB,GAAAL,OAAA,CAAAK,sBAAA,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AA8ClC;AACA;AACA;AACA;AASA;AACA;AACA;AACA;AAWA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AAMA;AACA;AACA;AACA;AAOA;AACA;AACA;AACA;AAKA;AACA;AACA;AACA;AAUA;AACA;AACA;AACA;AAcA;AACA;AACA;AACA;AAMA;AACA;AACA;AACA;AAMA;AACA;AACA;AACA;AAOA;AACA;AACA;AACA;AASA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CompleteMultipartUploadOutput } from "@webiny/aws-sdk/client-s3";
|
|
2
|
+
export interface ZipFilesOptions {
|
|
3
|
+
debug?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare class ZipFiles {
|
|
6
|
+
private readonly bucket;
|
|
7
|
+
private debug;
|
|
8
|
+
constructor(options?: ZipFilesOptions);
|
|
9
|
+
process(targetFileName: string, files: string[]): Promise<CompleteMultipartUploadOutput>;
|
|
10
|
+
private setDebug;
|
|
11
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ZipFiles = void 0;
|
|
8
|
+
var _archiver = require("archiver");
|
|
9
|
+
var _clientS = require("@webiny/aws-sdk/client-s3");
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _stream = require("stream");
|
|
12
|
+
var _libStorage = require("@webiny/aws-sdk/lib-storage");
|
|
13
|
+
var _nodeHttpHandler = require("@smithy/node-http-handler");
|
|
14
|
+
var _https = require("https");
|
|
15
|
+
var _http = require("http");
|
|
16
|
+
class ZipFiles {
|
|
17
|
+
bucket = process.env.S3_BUCKET;
|
|
18
|
+
debug = process.env.DEBUG === "true";
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.setDebug(options?.debug);
|
|
21
|
+
}
|
|
22
|
+
async process(targetFileName, files) {
|
|
23
|
+
const fileNames = Array.from(files);
|
|
24
|
+
const s3Client = (0, _clientS.createS3)({
|
|
25
|
+
requestHandler: new _nodeHttpHandler.NodeHttpHandler({
|
|
26
|
+
connectionTimeout: 0,
|
|
27
|
+
httpAgent: new _http.Agent({
|
|
28
|
+
maxSockets: 10000,
|
|
29
|
+
keepAlive: true,
|
|
30
|
+
maxFreeSockets: 10000,
|
|
31
|
+
maxTotalSockets: 10000,
|
|
32
|
+
keepAliveMsecs: 900000 // milliseconds / 15 minutes
|
|
33
|
+
}),
|
|
34
|
+
httpsAgent: new _https.Agent({
|
|
35
|
+
maxSockets: 10000,
|
|
36
|
+
keepAlive: true,
|
|
37
|
+
sessionTimeout: 900,
|
|
38
|
+
// seconds / 15 minutes
|
|
39
|
+
maxCachedSessions: 100000,
|
|
40
|
+
maxFreeSockets: 10000,
|
|
41
|
+
maxTotalSockets: 10000,
|
|
42
|
+
keepAliveMsecs: 900000 // milliseconds / 15 minutes
|
|
43
|
+
}),
|
|
44
|
+
requestTimeout: 900000 // milliseconds / 15 minutes
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
const streamPassThrough = new _stream.Stream.PassThrough({
|
|
48
|
+
autoDestroy: true
|
|
49
|
+
});
|
|
50
|
+
const upload = new _libStorage.Upload({
|
|
51
|
+
client: s3Client,
|
|
52
|
+
params: {
|
|
53
|
+
ACL: "private",
|
|
54
|
+
Body: streamPassThrough,
|
|
55
|
+
Bucket: this.bucket,
|
|
56
|
+
ContentType: "application/zip",
|
|
57
|
+
Key: targetFileName
|
|
58
|
+
},
|
|
59
|
+
queueSize: 1,
|
|
60
|
+
partSize: 1024 * 1024 * 5,
|
|
61
|
+
leavePartsOnError: false
|
|
62
|
+
});
|
|
63
|
+
const archive = (0, _archiver.create)("zip", {});
|
|
64
|
+
archive.on("error", error => {
|
|
65
|
+
console.error(error);
|
|
66
|
+
throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
|
|
67
|
+
});
|
|
68
|
+
archive.pipe(streamPassThrough);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* To combine all the files into a single zip file, we need to add files one by one.
|
|
72
|
+
*
|
|
73
|
+
* addFileToArchive() method is called every time an entry event is triggered on the archive - it means that file was added into the archive.
|
|
74
|
+
* The method is called manually, first time, to start the process.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
archive.on("entry", data => {
|
|
78
|
+
this.debug && console.log(`Archived file: ${data.name}`);
|
|
79
|
+
addFileToArchive();
|
|
80
|
+
});
|
|
81
|
+
const addFileToArchive = async () => {
|
|
82
|
+
const file = fileNames.shift();
|
|
83
|
+
if (!file) {
|
|
84
|
+
this.debug && console.log("No more files to add to the archive.");
|
|
85
|
+
/**
|
|
86
|
+
* Must call finalize() with a timeout, otherwise the lambda crashes.
|
|
87
|
+
*/
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
archive.finalize();
|
|
90
|
+
}, 200);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.debug && console.log(`Adding file "${file}" to the archive.`);
|
|
94
|
+
const cmd = new _clientS.GetObjectCommand({
|
|
95
|
+
Bucket: this.bucket,
|
|
96
|
+
Key: file
|
|
97
|
+
});
|
|
98
|
+
const response = await s3Client.send(cmd);
|
|
99
|
+
// Possible to get a null response.Body?
|
|
100
|
+
// Typescript says yes, so let's check it.
|
|
101
|
+
if (!response.Body) {
|
|
102
|
+
this.debug && console.log(`No response.Body for file "${file}", moving to next file.`);
|
|
103
|
+
return addFileToArchive();
|
|
104
|
+
}
|
|
105
|
+
const name = `${_path.default.basename(file)}`;
|
|
106
|
+
archive.append(response.Body, {
|
|
107
|
+
name
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
addFileToArchive();
|
|
111
|
+
const result = await upload.done();
|
|
112
|
+
s3Client.destroy();
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
setDebug(debug) {
|
|
116
|
+
if (debug === undefined) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.debug = debug;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.ZipFiles = ZipFiles;
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=ZipFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_archiver","require","_clientS","_path","_interopRequireDefault","_stream","_libStorage","_nodeHttpHandler","_https","_http","ZipFiles","bucket","process","env","S3_BUCKET","debug","DEBUG","constructor","options","setDebug","targetFileName","files","fileNames","Array","from","s3Client","createS3","requestHandler","NodeHttpHandler","connectionTimeout","httpAgent","HttpAgent","maxSockets","keepAlive","maxFreeSockets","maxTotalSockets","keepAliveMsecs","httpsAgent","HttpsAgent","sessionTimeout","maxCachedSessions","requestTimeout","streamPassThrough","Stream","PassThrough","autoDestroy","upload","Upload","client","params","ACL","Body","Bucket","ContentType","Key","queueSize","partSize","leavePartsOnError","archive","createArchiver","on","error","console","Error","name","code","message","path","stack","pipe","data","log","addFileToArchive","file","shift","setTimeout","finalize","cmd","GetObjectCommand","response","send","basename","append","result","done","destroy","undefined","exports"],"sources":["ZipFiles.ts"],"sourcesContent":["import type { ArchiverError } from \"archiver\";\nimport { create as createArchiver } from \"archiver\";\nimport type { CompleteMultipartUploadOutput } from \"@webiny/aws-sdk/client-s3\";\nimport { createS3, GetObjectCommand } from \"@webiny/aws-sdk/client-s3\";\nimport path from \"path\";\nimport { type Readable, Stream } from \"stream\";\nimport { Upload } from \"@webiny/aws-sdk/lib-storage\";\nimport { NodeHttpHandler } from \"@smithy/node-http-handler\";\nimport { Agent as HttpsAgent } from \"https\";\nimport { Agent as HttpAgent } from \"http\";\n\nexport interface ZipFilesOptions {\n debug?: boolean;\n}\n\nexport class ZipFiles {\n private readonly bucket: string = process.env.S3_BUCKET as string;\n private debug: boolean = process.env.DEBUG === \"true\";\n\n public constructor(options?: ZipFilesOptions) {\n this.setDebug(options?.debug);\n }\n\n public async process(\n targetFileName: string,\n files: string[]\n ): Promise<CompleteMultipartUploadOutput> {\n const fileNames = Array.from(files);\n const s3Client = createS3({\n requestHandler: new NodeHttpHandler({\n connectionTimeout: 0,\n httpAgent: new HttpAgent({\n maxSockets: 10000,\n keepAlive: true,\n maxFreeSockets: 10000,\n maxTotalSockets: 10000,\n keepAliveMsecs: 900000 // milliseconds / 15 minutes\n }),\n httpsAgent: new HttpsAgent({\n maxSockets: 10000,\n keepAlive: true,\n sessionTimeout: 900, // seconds / 15 minutes\n maxCachedSessions: 100000,\n maxFreeSockets: 10000,\n maxTotalSockets: 10000,\n keepAliveMsecs: 900000 // milliseconds / 15 minutes\n }),\n requestTimeout: 900000 // milliseconds / 15 minutes\n })\n });\n\n const streamPassThrough = new Stream.PassThrough({\n autoDestroy: true\n });\n\n const upload = new Upload({\n client: s3Client,\n params: {\n ACL: \"private\",\n Body: streamPassThrough,\n Bucket: this.bucket,\n ContentType: \"application/zip\",\n Key: targetFileName\n },\n queueSize: 1,\n partSize: 1024 * 1024 * 5,\n leavePartsOnError: false\n });\n\n const archive = createArchiver(\"zip\", {});\n\n archive.on(\"error\", (error: ArchiverError) => {\n console.error(error);\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n archive.pipe(streamPassThrough);\n\n /**\n * To combine all the files into a single zip file, we need to add files one by one.\n *\n * addFileToArchive() method is called every time an entry event is triggered on the archive - it means that file was added into the archive.\n * The method is called manually, first time, to start the process.\n */\n\n archive.on(\"entry\", data => {\n this.debug && console.log(`Archived file: ${data.name}`);\n addFileToArchive();\n });\n\n const addFileToArchive = async (): Promise<void> => {\n const file = fileNames.shift();\n if (!file) {\n this.debug && console.log(\"No more files to add to the archive.\");\n /**\n * Must call finalize() with a timeout, otherwise the lambda crashes.\n */\n setTimeout(() => {\n archive.finalize();\n }, 200);\n return;\n }\n this.debug && console.log(`Adding file \"${file}\" to the archive.`);\n const cmd = new GetObjectCommand({\n Bucket: this.bucket,\n Key: file\n });\n\n const response = await s3Client.send(cmd);\n // Possible to get a null response.Body?\n // Typescript says yes, so let's check it.\n if (!response.Body) {\n this.debug &&\n console.log(`No response.Body for file \"${file}\", moving to next file.`);\n return addFileToArchive();\n }\n const name = `${path.basename(file)}`;\n\n archive.append(response.Body as Readable, {\n name\n });\n };\n\n addFileToArchive();\n\n const result = await upload.done();\n\n s3Client.destroy();\n return result;\n }\n\n private setDebug(debug?: boolean): void {\n if (debug === undefined) {\n return;\n }\n this.debug = debug;\n }\n}\n"],"mappings":";;;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,KAAA,GAAAR,OAAA;AAMO,MAAMS,QAAQ,CAAC;EACDC,MAAM,GAAWC,OAAO,CAACC,GAAG,CAACC,SAAS;EAC/CC,KAAK,GAAYH,OAAO,CAACC,GAAG,CAACG,KAAK,KAAK,MAAM;EAE9CC,WAAWA,CAACC,OAAyB,EAAE;IAC1C,IAAI,CAACC,QAAQ,CAACD,OAAO,EAAEH,KAAK,CAAC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C;MACzC;MACA;MACA,IAAI,CAACE,QAAQ,CAAC5B,IAAI,EAAE;QAChB,IAAI,CAACpC,KAAK,IACN+C,OAAO,CAACS,GAAG,CAAC,8BAA8BE,IAAI,yBAAyB,CAAC;QAC5E,OAAOD,gBAAgB,CAAC,CAAC;MAC7B;MACA,MAAMR,IAAI,GAAG,GAAGG,aAAI,CAACc,QAAQ,CAACR,IAAI,CAAC,EAAE;MAErCf,OAAO,CAACwB,MAAM,CAACH,QAAQ,CAAC5B,IAAI,EAAc;QACtCa;MACJ,CAAC,CAAC;IACN,CAAC;IAEDQ,gBAAgB,CAAC,CAAC;IAElB,MAAMW,MAAM,GAAG,MAAMrC,MAAM,CAACsC,IAAI,CAAC,CAAC;IAElC3D,QAAQ,CAAC4D,OAAO,CAAC,CAAC;IAClB,OAAOF,MAAM;EACjB;EAEQhE,QAAQA,CAACJ,KAAe,EAAQ;IACpC,IAAIA,KAAK,KAAKuE,SAAS,EAAE;MACrB;IACJ;IACA,IAAI,CAACvE,KAAK,GAAGA,KAAK;EACtB;AACJ;AAACwE,OAAA,CAAA7E,QAAA,GAAAA,QAAA","ignoreList":[]}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _types = require("../../types");
|
|
9
|
-
|
|
10
|
-
var _s3Stream = require("../s3Stream");
|
|
11
|
-
|
|
12
|
-
var _zipper = require("../zipper");
|
|
13
|
-
|
|
14
|
-
var _mockSecurity = require("../../mockSecurity");
|
|
15
|
-
|
|
16
|
-
var _handlerAws = require("@webiny/handler-aws");
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Handles the export pages combine workflow.
|
|
20
|
-
*/
|
|
21
|
-
var _default = () => {
|
|
22
|
-
return (0, _handlerAws.createRawEventHandler)(async ({
|
|
23
|
-
payload,
|
|
24
|
-
context
|
|
25
|
-
}) => {
|
|
26
|
-
const log = console.log;
|
|
27
|
-
log("RUNNING Export Pages Combine Handler");
|
|
28
|
-
const {
|
|
29
|
-
pageBuilder
|
|
30
|
-
} = context;
|
|
31
|
-
const {
|
|
32
|
-
taskId,
|
|
33
|
-
identity
|
|
34
|
-
} = payload;
|
|
35
|
-
(0, _mockSecurity.mockSecurity)(identity, context);
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
const task = await pageBuilder.pageImportExportTask.getTask(taskId);
|
|
39
|
-
|
|
40
|
-
if (!task) {
|
|
41
|
-
return {
|
|
42
|
-
data: null,
|
|
43
|
-
error: {
|
|
44
|
-
message: `There is no task with ID "${taskId}".`
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const {
|
|
50
|
-
exportPagesDataKey
|
|
51
|
-
} = task.input; // Get all files (zip) from given key
|
|
52
|
-
|
|
53
|
-
const listObjectResponse = await _s3Stream.s3Stream.listObject(exportPagesDataKey);
|
|
54
|
-
|
|
55
|
-
if (!listObjectResponse.Contents) {
|
|
56
|
-
return {
|
|
57
|
-
data: null,
|
|
58
|
-
error: {
|
|
59
|
-
message: "There is no Contents defined on S3 Stream while combining pages."
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const zipFileKeys = listObjectResponse.Contents.filter(file => file.Key !== exportPagesDataKey).map(file => file.Key).filter(Boolean); // Prepare zip of all zips
|
|
65
|
-
|
|
66
|
-
const zipOfZip = new _zipper.ZipOfZip(zipFileKeys); // Upload
|
|
67
|
-
|
|
68
|
-
const pageExportUpload = await zipOfZip.process();
|
|
69
|
-
log(`Done uploading... File is located at ${pageExportUpload.Location} `); // Update task status and save export page data key
|
|
70
|
-
|
|
71
|
-
await pageBuilder.pageImportExportTask.updateTask(taskId, {
|
|
72
|
-
status: _types.PageImportExportTaskStatus.COMPLETED,
|
|
73
|
-
data: {
|
|
74
|
-
message: `Finish uploading page export.`,
|
|
75
|
-
key: pageExportUpload.Key,
|
|
76
|
-
url: _s3Stream.s3Stream.getPresignedUrl(pageExportUpload.Key)
|
|
77
|
-
}
|
|
78
|
-
}); // Remove individual zip files from storage
|
|
79
|
-
|
|
80
|
-
const deleteFilePromises = zipFileKeys.map(key => _s3Stream.s3Stream.deleteObject(key));
|
|
81
|
-
await Promise.all(deleteFilePromises);
|
|
82
|
-
log(`Successfully deleted ${deleteFilePromises.length} zip files.`);
|
|
83
|
-
} catch (e) {
|
|
84
|
-
log("[EXPORT_PAGES_COMBINE] Error => ", e);
|
|
85
|
-
/**
|
|
86
|
-
* In case of error, we'll update the task status to "failed",
|
|
87
|
-
* so that, client can show notify the user appropriately.
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
await pageBuilder.pageImportExportTask.updateTask(taskId, {
|
|
91
|
-
status: _types.PageImportExportTaskStatus.FAILED,
|
|
92
|
-
error: {
|
|
93
|
-
name: e.name,
|
|
94
|
-
message: e.message,
|
|
95
|
-
stack: e.stack,
|
|
96
|
-
code: "EXPORT_FAILED"
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
data: null,
|
|
101
|
-
error: {
|
|
102
|
-
message: e.message
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
data: "",
|
|
109
|
-
error: null
|
|
110
|
-
};
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
exports.default = _default;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createRawEventHandler","payload","context","log","console","pageBuilder","taskId","identity","mockSecurity","task","pageImportExportTask","getTask","data","error","message","exportPagesDataKey","input","listObjectResponse","s3Stream","listObject","Contents","zipFileKeys","filter","file","Key","map","Boolean","zipOfZip","ZipOfZip","pageExportUpload","process","Location","updateTask","status","PageImportExportTaskStatus","COMPLETED","key","url","getPresignedUrl","deleteFilePromises","deleteObject","Promise","all","length","e","FAILED","name","stack","code"],"sources":["index.ts"],"sourcesContent":["import { PageImportExportTaskStatus, PbPageImportExportContext } from \"~/types\";\nimport { s3Stream } from \"../s3Stream\";\nimport { ZipOfZip } from \"../zipper\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\n\nexport interface Payload {\n taskId: string;\n identity: SecurityIdentity;\n}\n\nexport interface Response {\n data: string | null;\n error: Partial<Error> | null;\n}\n\n/**\n * Handles the export pages combine workflow.\n */\nexport default () => {\n return createRawEventHandler<Payload, PbPageImportExportContext, Response>(\n async ({ payload, context }) => {\n const log = console.log;\n\n log(\"RUNNING Export Pages Combine Handler\");\n const { pageBuilder } = context;\n const { taskId, identity } = payload;\n\n mockSecurity(identity, context);\n\n try {\n const task = await pageBuilder.pageImportExportTask.getTask(taskId);\n if (!task) {\n return {\n data: null,\n error: {\n message: `There is no task with ID \"${taskId}\".`\n }\n };\n }\n\n const { exportPagesDataKey } = task.input;\n\n // Get all files (zip) from given key\n const listObjectResponse = await s3Stream.listObject(exportPagesDataKey);\n if (!listObjectResponse.Contents) {\n return {\n data: null,\n error: {\n message:\n \"There is no Contents defined on S3 Stream while combining pages.\"\n }\n };\n }\n\n const zipFileKeys = listObjectResponse.Contents.filter(\n file => file.Key !== exportPagesDataKey\n )\n .map(file => file.Key)\n .filter(Boolean) as string[];\n\n // Prepare zip of all zips\n const zipOfZip = new ZipOfZip(zipFileKeys);\n\n // Upload\n const pageExportUpload = await zipOfZip.process();\n log(`Done uploading... File is located at ${pageExportUpload.Location} `);\n\n // Update task status and save export page data key\n await pageBuilder.pageImportExportTask.updateTask(taskId, {\n status: PageImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading page export.`,\n key: pageExportUpload.Key,\n url: s3Stream.getPresignedUrl(pageExportUpload.Key)\n }\n });\n\n // Remove individual zip files from storage\n const deleteFilePromises = zipFileKeys.map(key => s3Stream.deleteObject(key));\n await Promise.all(deleteFilePromises);\n log(`Successfully deleted ${deleteFilePromises.length} zip files.`);\n } catch (e) {\n log(\"[EXPORT_PAGES_COMBINE] Error => \", e);\n\n /**\n * In case of error, we'll update the task status to \"failed\",\n * so that, client can show notify the user appropriately.\n */\n await pageBuilder.pageImportExportTask.updateTask(taskId, {\n status: PageImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n stack: e.stack,\n code: \"EXPORT_FAILED\"\n }\n });\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n }\n return {\n data: \"\",\n error: null\n };\n }\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AAYA;AACA;AACA;eACe,MAAM;EACjB,OAAO,IAAAA,iCAAA,EACH,OAAO;IAAEC,OAAF;IAAWC;EAAX,CAAP,KAAgC;IAC5B,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAApB;IAEAA,GAAG,CAAC,sCAAD,CAAH;IACA,MAAM;MAAEE;IAAF,IAAkBH,OAAxB;IACA,MAAM;MAAEI,MAAF;MAAUC;IAAV,IAAuBN,OAA7B;IAEA,IAAAO,0BAAA,EAAaD,QAAb,EAAuBL,OAAvB;;IAEA,IAAI;MACA,MAAMO,IAAI,GAAG,MAAMJ,WAAW,CAACK,oBAAZ,CAAiCC,OAAjC,CAAyCL,MAAzC,CAAnB;;MACA,IAAI,CAACG,IAAL,EAAW;QACP,OAAO;UACHG,IAAI,EAAE,IADH;UAEHC,KAAK,EAAE;YACHC,OAAO,EAAG,6BAA4BR,MAAO;UAD1C;QAFJ,CAAP;MAMH;;MAED,MAAM;QAAES;MAAF,IAAyBN,IAAI,CAACO,KAApC,CAXA,CAaA;;MACA,MAAMC,kBAAkB,GAAG,MAAMC,kBAAA,CAASC,UAAT,CAAoBJ,kBAApB,CAAjC;;MACA,IAAI,CAACE,kBAAkB,CAACG,QAAxB,EAAkC;QA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AiCsB,UAAjC,CAA4C1B,MAA5C,EAAoD;QACtD2B,MAAM,EAAEC,iCAAA,CAA2BW,MADmB;QAEtDhC,KAAK,EAAE;UACHiC,IAAI,EAAEF,CAAC,CAACE,IADL;UAEHhC,OAAO,EAAE8B,CAAC,CAAC9B,OAFR;UAGHiC,KAAK,EAAEH,CAAC,CAACG,KAHN;UAIHC,IAAI,EAAE;QAJH;MAF+C,CAApD,CAAN;MAUA,OAAO;QACHpC,IAAI,EAAE,IADH;QAEHC,KAAK,EAAE;UACHC,OAAO,EAAE8B,CAAC,CAAC9B;QADR;MAFJ,CAAP;IAMH;;IACD,OAAO;MACHF,IAAI,EAAE,EADH;MAEHC,KAAK,EAAE;IAFJ,CAAP;EAIH,CA1FE,CAAP;AA4FH,C"}
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _types = require("../../types");
|
|
9
|
-
|
|
10
|
-
var _client = require("../../client");
|
|
11
|
-
|
|
12
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
13
|
-
|
|
14
|
-
var _utils = require("../utils");
|
|
15
|
-
|
|
16
|
-
var _mockSecurity = require("../../mockSecurity");
|
|
17
|
-
|
|
18
|
-
var _utils2 = require("@webiny/utils");
|
|
19
|
-
|
|
20
|
-
var _handlerAws = require("@webiny/handler-aws");
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Handles the export pages process workflow.
|
|
24
|
-
*/
|
|
25
|
-
var _default = configuration => {
|
|
26
|
-
return (0, _handlerAws.createRawEventHandler)(async ({
|
|
27
|
-
payload,
|
|
28
|
-
context
|
|
29
|
-
}) => {
|
|
30
|
-
const log = console.log;
|
|
31
|
-
let subTask;
|
|
32
|
-
let noPendingTask = true;
|
|
33
|
-
let prevStatusOfSubTask = _types.PageImportExportTaskStatus.PENDING;
|
|
34
|
-
log("RUNNING Export Pages Process Handler");
|
|
35
|
-
const {
|
|
36
|
-
pageBuilder,
|
|
37
|
-
fileManager
|
|
38
|
-
} = context;
|
|
39
|
-
const {
|
|
40
|
-
taskId,
|
|
41
|
-
subTaskIndex,
|
|
42
|
-
identity
|
|
43
|
-
} = payload; // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks
|
|
44
|
-
// and this Lambda is invoked internally, without credentials.
|
|
45
|
-
|
|
46
|
-
(0, _mockSecurity.mockSecurity)(identity, context);
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
/*
|
|
50
|
-
* Note: We're not going to DB for finding the next sub-task to process,
|
|
51
|
-
* because the data might be out of sync due to GSI eventual consistency.
|
|
52
|
-
*/
|
|
53
|
-
subTask = await pageBuilder.pageImportExportTask.getSubTask(taskId, (0, _utils2.zeroPad)(subTaskIndex, 5));
|
|
54
|
-
/**
|
|
55
|
-
* Base condition!!
|
|
56
|
-
* Bail out early, if task not found or task's status is not "pending".
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
if (!subTask || subTask.status !== _types.PageImportExportTaskStatus.PENDING) {
|
|
60
|
-
noPendingTask = true;
|
|
61
|
-
return {
|
|
62
|
-
data: "",
|
|
63
|
-
error: null
|
|
64
|
-
};
|
|
65
|
-
} else {
|
|
66
|
-
noPendingTask = false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
log(`Fetched sub task => ${subTask.id}`);
|
|
70
|
-
const {
|
|
71
|
-
input
|
|
72
|
-
} = subTask;
|
|
73
|
-
const {
|
|
74
|
-
pageId,
|
|
75
|
-
exportPagesDataKey,
|
|
76
|
-
revisionType
|
|
77
|
-
} = input;
|
|
78
|
-
/**
|
|
79
|
-
* At the moment, we only export a single revision of the page.
|
|
80
|
-
* It could be "published" or "latest" depending upon user input.
|
|
81
|
-
*
|
|
82
|
-
* Note: In case of no "published" revision available, we use the latest revision.
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
let page;
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
if (revisionType === _types.PageExportRevisionType.PUBLISHED) {
|
|
89
|
-
// Get "published" page.
|
|
90
|
-
page = await pageBuilder.getPublishedPageById({
|
|
91
|
-
id: pageId
|
|
92
|
-
});
|
|
93
|
-
} else {
|
|
94
|
-
// Get "latest" page.
|
|
95
|
-
page = await pageBuilder.getPage(pageId);
|
|
96
|
-
}
|
|
97
|
-
} catch (e) {
|
|
98
|
-
// If we're looking for "published" page and doesn't found it, get latest page.
|
|
99
|
-
if (revisionType === _types.PageExportRevisionType.PUBLISHED && e instanceof _handlerGraphql.NotFoundError) {
|
|
100
|
-
page = await pageBuilder.getPage(pageId);
|
|
101
|
-
} else {
|
|
102
|
-
throw e;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (!page) {
|
|
107
|
-
log(`Unable to load page "${pageId}"`);
|
|
108
|
-
throw new _handlerGraphql.NotFoundError(`Unable to load page "${pageId}"`);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
log(`Processing page key "${pageId}" | version ${page.version} | ${page.status}`); // Mark task status as PROCESSING
|
|
112
|
-
|
|
113
|
-
subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
|
|
114
|
-
status: _types.PageImportExportTaskStatus.PROCESSING
|
|
115
|
-
}); // Update stats in main task
|
|
116
|
-
|
|
117
|
-
await pageBuilder.pageImportExportTask.updateStats(taskId, {
|
|
118
|
-
prevStatus: prevStatusOfSubTask,
|
|
119
|
-
nextStatus: _types.PageImportExportTaskStatus.PROCESSING
|
|
120
|
-
});
|
|
121
|
-
prevStatusOfSubTask = subTask.status;
|
|
122
|
-
log(`Extracting page data and uploading to storage...`); // Extract Page
|
|
123
|
-
|
|
124
|
-
const pageDataZip = await (0, _utils.exportPage)(page, exportPagesDataKey, fileManager);
|
|
125
|
-
log(`Finish uploading zip...`); // Update task record in DB
|
|
126
|
-
|
|
127
|
-
subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
|
|
128
|
-
status: _types.PageImportExportTaskStatus.COMPLETED,
|
|
129
|
-
data: {
|
|
130
|
-
message: `Finish uploading data for page "${page.id}" v${page.version} (${page.status}).`,
|
|
131
|
-
key: pageDataZip.Key
|
|
132
|
-
}
|
|
133
|
-
}); // Update stats in main task
|
|
134
|
-
|
|
135
|
-
await pageBuilder.pageImportExportTask.updateStats(taskId, {
|
|
136
|
-
prevStatus: prevStatusOfSubTask,
|
|
137
|
-
nextStatus: _types.PageImportExportTaskStatus.COMPLETED
|
|
138
|
-
});
|
|
139
|
-
prevStatusOfSubTask = subTask.status;
|
|
140
|
-
} catch (e) {
|
|
141
|
-
log("[EXPORT_PAGES_PROCESS] Error => ", e);
|
|
142
|
-
|
|
143
|
-
if (subTask && subTask.id) {
|
|
144
|
-
/**
|
|
145
|
-
* In case of error, we'll update the task status to "failed",
|
|
146
|
-
* so that, client can show notify the user appropriately.
|
|
147
|
-
*/
|
|
148
|
-
subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {
|
|
149
|
-
status: _types.PageImportExportTaskStatus.FAILED,
|
|
150
|
-
error: {
|
|
151
|
-
name: e.name,
|
|
152
|
-
message: e.message,
|
|
153
|
-
stack: e.stack,
|
|
154
|
-
code: "EXPORT_FAILED"
|
|
155
|
-
}
|
|
156
|
-
}); // Update stats in main task
|
|
157
|
-
|
|
158
|
-
await pageBuilder.pageImportExportTask.updateStats(taskId, {
|
|
159
|
-
prevStatus: prevStatusOfSubTask,
|
|
160
|
-
nextStatus: _types.PageImportExportTaskStatus.FAILED
|
|
161
|
-
});
|
|
162
|
-
prevStatusOfSubTask = subTask.status;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return {
|
|
166
|
-
data: null,
|
|
167
|
-
error: {
|
|
168
|
-
message: e.message
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
} finally {
|
|
172
|
-
// Base condition!
|
|
173
|
-
if (noPendingTask) {
|
|
174
|
-
log(`No pending sub-task for task ${taskId}`); // Combine individual page zip files.
|
|
175
|
-
|
|
176
|
-
await (0, _client.invokeHandlerClient)({
|
|
177
|
-
context,
|
|
178
|
-
name: configuration.handlers.combine,
|
|
179
|
-
payload: {
|
|
180
|
-
taskId,
|
|
181
|
-
identity: context.security.getIdentity()
|
|
182
|
-
},
|
|
183
|
-
description: "Export pages - combine"
|
|
184
|
-
});
|
|
185
|
-
} else {
|
|
186
|
-
console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`); // We want to continue with Self invocation no matter if current page error out.
|
|
187
|
-
|
|
188
|
-
await (0, _client.invokeHandlerClient)({
|
|
189
|
-
context,
|
|
190
|
-
name: configuration.handlers.process,
|
|
191
|
-
payload: {
|
|
192
|
-
taskId,
|
|
193
|
-
subTaskIndex: subTaskIndex + 1,
|
|
194
|
-
identity: context.security.getIdentity()
|
|
195
|
-
},
|
|
196
|
-
description: "Export pages - process - subtask"
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return {
|
|
202
|
-
data: "",
|
|
203
|
-
error: null
|
|
204
|
-
};
|
|
205
|
-
});
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
exports.default = _default;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["configuration","createRawEventHandler","payload","context","log","console","subTask","noPendingTask","prevStatusOfSubTask","PageImportExportTaskStatus","PENDING","pageBuilder","fileManager","taskId","subTaskIndex","identity","mockSecurity","pageImportExportTask","getSubTask","zeroPad","status","data","error","id","input","pageId","exportPagesDataKey","revisionType","page","PageExportRevisionType","PUBLISHED","getPublishedPageById","getPage","e","NotFoundError","version","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","pageDataZip","exportPage","COMPLETED","message","key","Key","FAILED","name","stack","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process"],"sources":["index.ts"],"sourcesContent":["import {\n PageExportRevisionType,\n PageImportExportTaskStatus,\n PbPageImportExportContext\n} from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { exportPage } from \"~/exportPages/utils\";\nimport { Payload as ExtractPayload } from \"../combine\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\n\ninterface Configuration {\n handlers: {\n process: string;\n combine: string;\n };\n}\n\nexport interface Payload {\n taskId: string;\n subTaskIndex: number;\n identity?: SecurityIdentity;\n}\n\nexport interface Response {\n data: string | null;\n error: Partial<Error> | null;\n}\n\n/**\n * Handles the export pages process workflow.\n */\nexport default (configuration: Configuration) => {\n return createRawEventHandler<Payload, PbPageImportExportContext, Response>(\n async ({ payload, context }) => {\n const log = console.log;\n let subTask;\n let noPendingTask = true;\n let prevStatusOfSubTask = PageImportExportTaskStatus.PENDING;\n\n log(\"RUNNING Export Pages Process Handler\");\n const { pageBuilder, fileManager } = context;\n const { taskId, subTaskIndex, identity } = payload;\n // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks\n // and this Lambda is invoked internally, without credentials.\n mockSecurity(identity as SecurityIdentity, context);\n\n try {\n /*\n * Note: We're not going to DB for finding the next sub-task to process,\n * because the data might be out of sync due to GSI eventual consistency.\n */\n subTask = await pageBuilder.pageImportExportTask.getSubTask(\n taskId,\n zeroPad(subTaskIndex, 5)\n );\n /**\n * Base condition!!\n * Bail out early, if task not found or task's status is not \"pending\".\n */\n if (!subTask || subTask.status !== PageImportExportTaskStatus.PENDING) {\n noPendingTask = true;\n return {\n data: \"\",\n error: null\n };\n } else {\n noPendingTask = false;\n }\n\n log(`Fetched sub task => ${subTask.id}`);\n\n const { input } = subTask;\n const { pageId, exportPagesDataKey, revisionType } = input;\n\n /**\n * At the moment, we only export a single revision of the page.\n * It could be \"published\" or \"latest\" depending upon user input.\n *\n * Note: In case of no \"published\" revision available, we use the latest revision.\n */\n let page;\n try {\n if (revisionType === PageExportRevisionType.PUBLISHED) {\n // Get \"published\" page.\n page = await pageBuilder.getPublishedPageById({ id: pageId });\n } else {\n // Get \"latest\" page.\n page = await pageBuilder.getPage(pageId);\n }\n } catch (e) {\n // If we're looking for \"published\" page and doesn't found it, get latest page.\n if (\n revisionType === PageExportRevisionType.PUBLISHED &&\n e instanceof NotFoundError\n ) {\n page = await pageBuilder.getPage(pageId);\n } else {\n throw e;\n }\n }\n\n if (!page) {\n log(`Unable to load page \"${pageId}\"`);\n throw new NotFoundError(`Unable to load page \"${pageId}\"`);\n }\n\n log(`Processing page key \"${pageId}\" | version ${page.version} | ${page.status}`);\n\n // Mark task status as PROCESSING\n subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {\n status: PageImportExportTaskStatus.PROCESSING\n });\n // Update stats in main task\n await pageBuilder.pageImportExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: PageImportExportTaskStatus.PROCESSING\n });\n prevStatusOfSubTask = subTask.status;\n\n log(`Extracting page data and uploading to storage...`);\n // Extract Page\n const pageDataZip = await exportPage(page, exportPagesDataKey, fileManager);\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.pageImportExportTask.updateSubTask(taskId, subTask.id, {\n status: PageImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for page \"${page.id}\" v${page.version} (${page.status}).`,\n key: pageDataZip.Key\n }\n });\n // Update stats in main task\n await pageBuilder.pageImportExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: PageImportExportTaskStatus.COMPLETED\n });\n prevStatusOfSubTask = subTask.status;\n } catch (e) {\n log(\"[EXPORT_PAGES_PROCESS] Error => \", e);\n\n if (subTask && subTask.id) {\n /**\n * In case of error, we'll update the task status to \"failed\",\n * so that, client can show notify the user appropriately.\n */\n subTask = await pageBuilder.pageImportExportTask.updateSubTask(\n taskId,\n subTask.id,\n {\n status: PageImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n stack: e.stack,\n code: \"EXPORT_FAILED\"\n }\n }\n );\n\n // Update stats in main task\n await pageBuilder.pageImportExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: PageImportExportTaskStatus.FAILED\n });\n prevStatusOfSubTask = subTask.status;\n }\n\n return {\n data: null,\n error: {\n message: e.message\n }\n };\n } finally {\n // Base condition!\n if (noPendingTask) {\n log(`No pending sub-task for task ${taskId}`);\n // Combine individual page zip files.\n await invokeHandlerClient<ExtractPayload>({\n context,\n name: configuration.handlers.combine,\n payload: {\n taskId,\n identity: context.security.getIdentity()\n },\n description: \"Export pages - combine\"\n });\n } else {\n console.log(`Invoking PROCESS for task \"${subTaskIndex + 1}\"`);\n // We want to continue with Self invocation no matter if current page error out.\n await invokeHandlerClient<Payload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId,\n subTaskIndex: subTaskIndex + 1,\n identity: context.security.getIdentity()\n },\n description: \"Export pages - process - subtask\"\n });\n }\n }\n return {\n data: \"\",\n error: null\n };\n }\n );\n};\n"],"mappings":";;;;;;;AAAA;;AAKA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AAoBA;AACA;AACA;eACgBA,aAAD,IAAkC;EAC7C,OAAO,IAAAC,iCAAA,EACH,OAAO;IAAEC,OAAF;IAAWC;EAAX,CAAP,KAAgC;IAC5B,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAApB;IACA,IAAIE,OAAJ;IACA,IAAIC,aAAa,GAAG,IAApB;IACA,IAAIC,mBAAmB,GAAGC,iCAAA,CAA2BC,OAArD;IAEAN,GAAG,CAAC,sCAAD,CAAH;IACA,MAAM;MAAEO,WAAF;MAAeC;IAAf,IAA+BT,OAArC;IACA,MAAM;MAAEU,MAAF;MAAUC,YAAV;MAAwBC;IAAxB,IAAqCb,OAA3C,CAR4B,CAS5B;IACA;;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;YACLW,MADK;YAELE,QAAQ,EAAEZ,OAAO,CAACmD,QAAR,CAAiBC,WAAjB;UAFL,CAH6B;UAOtCC,WAAW,EAAE;QAPyB,CAApC,CAAN;MASH,CAZD,MAYO;QACHnD,OAAO,CAACD,GAAR,CAAa,8BAA6BU,YAAY,GAAG,CAAE,GAA3D,EADG,CAEH;;QACA,MAAM,IAAAqC,2BAAA,EAA6B;UAC/BhD,OAD+B;UAE/B6C,IAAI,EAAEhD,aAAa,CAACoD,QAAd,CAAuBK,OAFE;UAG/BvD,OAAO,EAAE;YACLW,MADK;YAELC,YAAY,EAAEA,YAAY,GAAG,CAFxB;YAGLC,QAAQ,EAAEZ,OAAO,CAACmD,QAAR,CAAiBC,WAAjB;UAHL,CAHsB;UAQ/BC,WAAW,EAAE;QARkB,CAA7B,CAAN;MAUH;IACJ;;IACD,OAAO;MACHnC,IAAI,EAAE,EADH;MAEHC,KAAK,EAAE;IAFJ,CAAP;EAIH,CA9KE,CAAP;AAgLH,C"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { PassThrough, Readable } from "stream";
|
|
4
|
-
import S3 from "aws-sdk/clients/s3";
|
|
5
|
-
declare class S3Stream {
|
|
6
|
-
s3: S3;
|
|
7
|
-
bucket: string;
|
|
8
|
-
constructor();
|
|
9
|
-
getPresignedUrl(key: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* We're checking if the file is accessible on S3 by getting object meta data.
|
|
12
|
-
* It help us to filter files that we need to download as part of export data.
|
|
13
|
-
* @param Key {string}
|
|
14
|
-
*/
|
|
15
|
-
isFileAccessible(Key: string): Promise<boolean>;
|
|
16
|
-
getObjectHead(Key: string): Promise<S3.HeadObjectOutput>;
|
|
17
|
-
readStream(Key: string): Readable;
|
|
18
|
-
writeStream(Key: string, contentType?: string): {
|
|
19
|
-
streamPassThrough: PassThrough;
|
|
20
|
-
streamPassThroughUploadPromise: Promise<S3.ManagedUpload.SendData>;
|
|
21
|
-
};
|
|
22
|
-
upload(params: {
|
|
23
|
-
Key: string;
|
|
24
|
-
ContentType: string;
|
|
25
|
-
Body: Buffer;
|
|
26
|
-
}): Promise<S3.ManagedUpload.SendData>;
|
|
27
|
-
listObject(prefix: string): Promise<S3.ListObjectsOutput>;
|
|
28
|
-
deleteObject(key: string): Promise<S3.DeleteObjectOutput>;
|
|
29
|
-
}
|
|
30
|
-
export declare const s3Stream: S3Stream;
|
|
31
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["ARCHIVE_CONTENT_TYPE","S3Stream","constructor","s3","S3","region","process","env","AWS_REGION","bucket","S3_BUCKET","getPresignedUrl","key","getSignedUrl","Bucket","Key","Expires","isFileAccessible","getObjectHead","error","console","warn","log","headObject","promise","readStream","getObject","createReadStream","writeStream","contentType","streamPassThrough","Stream","PassThrough","params","ACL","Body","ContentType","streamPassThroughUploadPromise","upload","listObject","prefix","listObjects","Prefix","deleteObject","s3Stream"],"sources":["s3Stream.ts"],"sourcesContent":["import { Stream, PassThrough, Readable } from \"stream\";\nimport S3 from \"aws-sdk/clients/s3\";\n\nconst ARCHIVE_CONTENT_TYPE = \"application/zip\";\n\nclass S3Stream {\n s3: S3;\n bucket: string;\n\n constructor() {\n this.s3 = new S3({\n region: process.env.AWS_REGION as string\n });\n this.bucket = process.env.S3_BUCKET as string;\n }\n\n getPresignedUrl(key: string) {\n return this.s3.getSignedUrl(\"getObject\", {\n Bucket: this.bucket,\n Key: key,\n Expires: 604800 // 1 week\n });\n }\n\n /**\n * We're checking if the file is accessible on S3 by getting object meta data.\n * It help us to filter files that we need to download as part of export data.\n * @param Key {string}\n */\n async isFileAccessible(Key: string): Promise<boolean> {\n try {\n await this.getObjectHead(Key);\n return true;\n } catch (error) {\n console.warn(`Error while fetching meta data for file \"${Key}\"`);\n console.log(error);\n return false;\n }\n }\n\n getObjectHead(Key: string): Promise<S3.HeadObjectOutput> {\n return this.s3.headObject({ Bucket: this.bucket, Key }).promise();\n }\n\n readStream(Key: string): Readable {\n return this.s3.getObject({ Bucket: this.bucket, Key }).createReadStream();\n }\n\n writeStream(\n Key: string,\n contentType: string = ARCHIVE_CONTENT_TYPE\n ): {\n streamPassThrough: PassThrough;\n streamPassThroughUploadPromise: Promise<S3.ManagedUpload.SendData>;\n } {\n const streamPassThrough = new Stream.PassThrough();\n\n const params: S3.PutObjectRequest = {\n ACL: \"private\",\n Body: streamPassThrough,\n Bucket: this.bucket,\n ContentType: contentType,\n Key\n };\n\n return {\n streamPassThrough: streamPassThrough,\n /**\n * We're not using the `FileManager` storage plugin here because it currently doesn't support streams.\n */\n streamPassThroughUploadPromise: this.s3.upload(params).promise()\n };\n }\n\n upload(params: {\n Key: string;\n ContentType: string;\n Body: Buffer;\n }): Promise<S3.ManagedUpload.SendData> {\n return this.s3\n .upload({\n ACL: \"private\",\n Bucket: this.bucket,\n ...params\n })\n .promise();\n }\n\n listObject(prefix: string): Promise<S3.ListObjectsOutput> {\n return this.s3\n .listObjects({\n Bucket: this.bucket,\n Prefix: prefix\n })\n .promise();\n }\n\n deleteObject(key: string): Promise<S3.DeleteObjectOutput> {\n return this.s3.deleteObject({ Key: key, Bucket: this.bucket }).promise();\n }\n}\n\nexport const s3Stream = new S3Stream();\n"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAEA,MAAMA,oBAAoB,GAAG,iBAA7B;;AAEA,MAAMC,QAAN,CAAe;EAIXC,WAAW,GAAG;IAAA;IAAA;IACV,KAAKC,EAAL,GAAU,IAAIC,UAAJ,CAAO;MACbC,MAAM,EAAEC,OAAO,CAACC,GAAR,CAAYC;IADP,CAAP,CAAV;IAGA,KAAKC,MAAL,GAAcH,OAAO,CAACC,GAAR,CAAYG,SAA1B;EACH;;EAEDC,eAAe,CAACC,GAAD,EAAc;IACzB,OAAO,KAAKT,EAAL,CAAQU,YAAR,CAAqB,WAArB,EAAkC;MACrCC,MAAM,EAAE,KAAKL,MADwB;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mC,MADE;MAECJ,GAAG,EAAE,SAFN;MAGCpB,MAAM,EAAE,KAAKL;IAHd,GAIIwB,MAJJ,GAMFT,OANE,EAAP;EAOH;;EAEDe,UAAU,CAACC,MAAD,EAAgD;IACtD,OAAO,KAAKrC,EAAL,CACFsC,WADE,CACU;MACT3B,MAAM,EAAE,KAAKL,MADJ;MAETiC,MAAM,EAAEF;IAFC,CADV,EAKFhB,OALE,EAAP;EAMH;;EAEDmB,YAAY,CAAC/B,GAAD,EAA8C;IACtD,OAAO,KAAKT,EAAL,CAAQwC,YAAR,CAAqB;MAAE5B,GAAG,EAAEH,GAAP;MAAYE,MAAM,EAAE,KAAKL;IAAzB,CAArB,EAAwDe,OAAxD,EAAP;EACH;;AA9FU;;AAiGR,MAAMoB,QAAQ,GAAG,IAAI3C,QAAJ,EAAjB"}
|
package/exportPages/utils.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import S3 from "aws-sdk/clients/s3";
|
|
2
|
-
import { Page, File } from "@webiny/api-page-builder/types";
|
|
3
|
-
import { FileManagerContext } from "@webiny/api-file-manager/types";
|
|
4
|
-
export declare const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
|
5
|
-
export interface ExportedPageData {
|
|
6
|
-
page: Pick<Page, "content" | "title" | "version" | "status" | "settings" | "path">;
|
|
7
|
-
files: ImageFile[];
|
|
8
|
-
}
|
|
9
|
-
export declare function exportPage(page: Page, exportPagesDataKey: string, fileManager: FileManagerContext["fileManager"]): Promise<S3.ManagedUpload.SendData>;
|
|
10
|
-
export interface ImageFile extends Omit<File, "src"> {
|
|
11
|
-
key: string;
|
|
12
|
-
}
|
|
13
|
-
export declare function extractFilesFromPageData(data: Record<string, any>, files?: any[]): ImageFile[];
|