@webiny/api-page-builder-import-export 0.0.0-unstable.1e66d121db → 0.0.0-unstable.2696f9d9e8
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 +3 -2
- package/export/combine/index.js +44 -0
- package/export/combine/index.js.map +1 -0
- package/export/combine/pagesHandler.d.ts +6 -0
- package/export/combine/pagesHandler.js +101 -0
- package/export/combine/pagesHandler.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/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 +11 -0
- package/export/process/exporters/PageExporter.js +58 -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 +56 -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 +4 -6
- package/export/process/index.js +41 -0
- package/export/process/index.js.map +1 -0
- package/export/process/pagesHandler.d.ts +6 -0
- package/export/process/pagesHandler.js +191 -0
- package/export/process/pagesHandler.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 +34 -0
- package/{exportPages → export}/s3Stream.js +28 -42
- package/export/s3Stream.js.map +1 -0
- package/export/utils.d.ts +24 -0
- package/export/utils.js +171 -0
- package/export/utils.js.map +1 -0
- package/{exportPages → export}/zipper.d.ts +11 -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 +159 -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 +163 -0
- package/graphql/crud/forms.crud.js.map +1 -0
- package/graphql/crud/importExportTasks.crud.d.ts +5 -0
- package/graphql/crud/{pageImportExportTasks.crud.js → importExportTasks.crud.js} +121 -151
- package/graphql/crud/importExportTasks.crud.js.map +1 -0
- package/graphql/crud/pages.crud.d.ts +3 -2
- package/graphql/crud/pages.crud.js +89 -69
- package/graphql/crud/pages.crud.js.map +1 -1
- package/graphql/crud/templates.crud.d.ts +4 -0
- package/graphql/crud/templates.crud.js +157 -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 +54 -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 +62 -0
- package/graphql/graphql/forms.gql.js.map +1 -0
- package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
- package/graphql/graphql/{pageImportExportTasks.gql.js → importExportTasks.gql.js} +21 -24
- package/graphql/graphql/importExportTasks.gql.js.map +1 -0
- package/graphql/graphql/pages.gql.d.ts +2 -2
- package/graphql/graphql/pages.gql.js +7 -16
- package/graphql/graphql/pages.gql.js.map +1 -1
- package/graphql/graphql/templates.gql.d.ts +4 -0
- package/graphql/graphql/templates.gql.js +54 -0
- package/graphql/graphql/templates.gql.js.map +1 -0
- package/graphql/graphql/utils/resolve.d.ts +1 -1
- package/graphql/graphql/utils/resolve.js +2 -3
- package/graphql/graphql/utils/resolve.js.map +1 -1
- package/graphql/graphql.js +7 -6
- package/graphql/graphql.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +2 -5
- package/graphql/index.js.map +1 -1
- package/graphql/types.d.ts +195 -23
- package/graphql/types.js +3 -1
- package/graphql/types.js.map +1 -1
- package/import/constants.d.ts +3 -0
- package/import/constants.js +16 -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/{importPages → import}/create/index.d.ts +7 -5
- 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/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 +98 -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 +5 -3
- package/import/process/index.js +41 -0
- package/import/process/index.js.map +1 -0
- package/import/process/pages/importPage.d.ts +11 -0
- package/import/process/pages/importPage.js +94 -0
- package/import/process/pages/importPage.js.map +1 -0
- package/import/process/pages/pagesHandler.d.ts +3 -0
- package/import/process/pages/pagesHandler.js +185 -0
- package/import/process/pages/pagesHandler.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 +172 -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 +123 -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.js +2 -3
- package/mockSecurity.js.map +1 -1
- package/package.json +36 -44
- package/types.d.ts +83 -65
- package/types.js +70 -21
- package/types.js.map +1 -1
- 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.map +0 -1
- package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
- package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
- 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
@@ -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;;IACA,IAAAc,0BAAA,EAAaD,QAAb,EAA2CZ,OAA3C;;IAEA,IAAI;MACA;AAChB;AACA;AACA;MACgBG,OAAO,GAAG,MAAMK,WAAW,CAACM,oB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H,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;MAErCM,GAAG,EAAEH,GAFgC;MAGrCI,OAAO,EAAE,MAH4B,CAGrB;;IAHqB,CAAlC,CAAP;EAKH;EAED;AACJ;AACA;AACA;AACA;;;EAC0B,MAAhBC,gBAAgB,CAACF,GAAD,EAAgC;IAClD,IAAI;MACA,MAAM,KAAKG,aAAL,CAAmBH,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AKL,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[];
|
package/exportPages/utils.js
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
-
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
6
|
-
value: true
|
7
|
-
});
|
8
|
-
exports.EXPORT_PAGES_FOLDER_KEY = void 0;
|
9
|
-
exports.exportPage = exportPage;
|
10
|
-
exports.extractFilesFromPageData = extractFilesFromPageData;
|
11
|
-
|
12
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
13
|
-
|
14
|
-
var _s3Stream = require("./s3Stream");
|
15
|
-
|
16
|
-
var _zipper = _interopRequireDefault(require("./zipper"));
|
17
|
-
|
18
|
-
const EXPORT_PAGES_FOLDER_KEY = "WEBINY_PB_EXPORT_PAGES";
|
19
|
-
exports.EXPORT_PAGES_FOLDER_KEY = EXPORT_PAGES_FOLDER_KEY;
|
20
|
-
|
21
|
-
async function getFilteredFiles(files) {
|
22
|
-
const uniqueFileKeys = new Map();
|
23
|
-
const promises = files.map(file => _s3Stream.s3Stream.isFileAccessible(file.key));
|
24
|
-
const isFileAvailableResults = await Promise.all(promises);
|
25
|
-
const filesAvailableForDownload = []; // Filter files
|
26
|
-
|
27
|
-
for (let i = 0; i < files.length; i++) {
|
28
|
-
const file = files[i]; // Check file accessibility
|
29
|
-
|
30
|
-
if (isFileAvailableResults[i] && !uniqueFileKeys.has(file.key)) {
|
31
|
-
filesAvailableForDownload.push(file);
|
32
|
-
uniqueFileKeys.set(file.key, true);
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
return filesAvailableForDownload;
|
37
|
-
}
|
38
|
-
|
39
|
-
async function exportPage(page, exportPagesDataKey, fileManager) {
|
40
|
-
// Extract all files
|
41
|
-
const files = extractFilesFromPageData(page.content || {}); // Filter files
|
42
|
-
|
43
|
-
const filesAvailableForDownload = await getFilteredFiles(files); // Extract images from page settings
|
44
|
-
|
45
|
-
const pageSettingsImages = [(0, _get.default)(page, "settings.general.image"), (0, _get.default)(page, "settings.social.image")].filter(image => image && image.src);
|
46
|
-
const pageSettingsImagesData = []; // Get file data for all images inside "page.settings"
|
47
|
-
|
48
|
-
for (let i = 0; i < pageSettingsImages.length; i++) {
|
49
|
-
const {
|
50
|
-
id
|
51
|
-
} = pageSettingsImages[i];
|
52
|
-
const file = await fileManager.files.getFile(id);
|
53
|
-
pageSettingsImagesData.push(file);
|
54
|
-
} // Extract the page data in a json file and upload it to S3
|
55
|
-
|
56
|
-
|
57
|
-
const pageData = {
|
58
|
-
page: {
|
59
|
-
content: page.content,
|
60
|
-
title: page.title,
|
61
|
-
path: page.path,
|
62
|
-
version: page.version,
|
63
|
-
status: page.status,
|
64
|
-
settings: page.settings
|
65
|
-
},
|
66
|
-
files: [...filesAvailableForDownload, ...pageSettingsImagesData]
|
67
|
-
};
|
68
|
-
const pageDataBuffer = Buffer.from(JSON.stringify(pageData));
|
69
|
-
const zipper = new _zipper.default({
|
70
|
-
exportInfo: {
|
71
|
-
files: [...filesAvailableForDownload, ...pageSettingsImagesData],
|
72
|
-
pageTitle: page.title,
|
73
|
-
pageDataBuffer
|
74
|
-
},
|
75
|
-
archiveFileKey: exportPagesDataKey
|
76
|
-
});
|
77
|
-
return zipper.process();
|
78
|
-
}
|
79
|
-
|
80
|
-
function extractFilesFromPageData(data, files = []) {
|
81
|
-
// Base case: termination
|
82
|
-
if (!data || typeof data !== "object") {
|
83
|
-
return files;
|
84
|
-
} // Recursively call function for each element
|
85
|
-
|
86
|
-
|
87
|
-
if (Array.isArray(data)) {
|
88
|
-
for (let i = 0; i < data.length; i++) {
|
89
|
-
const element = data[i];
|
90
|
-
extractFilesFromPageData(element, files);
|
91
|
-
}
|
92
|
-
|
93
|
-
return files;
|
94
|
-
} // Main
|
95
|
-
|
96
|
-
|
97
|
-
const tuple = Object.entries(data);
|
98
|
-
|
99
|
-
for (let i = 0; i < tuple.length; i++) {
|
100
|
-
const [key, value] = tuple[i]; // TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.
|
101
|
-
|
102
|
-
if (key === "file" && value) {
|
103
|
-
files.push(value);
|
104
|
-
} else if (key === "images" && Array.isArray(value)) {
|
105
|
-
// Handle case for "images-list" component
|
106
|
-
files.push(...value);
|
107
|
-
} else {
|
108
|
-
extractFilesFromPageData(value, files);
|
109
|
-
}
|
110
|
-
}
|
111
|
-
|
112
|
-
return files;
|
113
|
-
}
|
package/exportPages/utils.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["EXPORT_PAGES_FOLDER_KEY","getFilteredFiles","files","uniqueFileKeys","Map","promises","map","file","s3Stream","isFileAccessible","key","isFileAvailableResults","Promise","all","filesAvailableForDownload","i","length","has","push","set","exportPage","page","exportPagesDataKey","fileManager","extractFilesFromPageData","content","pageSettingsImages","get","filter","image","src","pageSettingsImagesData","id","getFile","pageData","title","path","version","status","settings","pageDataBuffer","Buffer","from","JSON","stringify","zipper","Zipper","exportInfo","pageTitle","archiveFileKey","process","data","Array","isArray","element","tuple","Object","entries","value"],"sources":["utils.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { Page, File } from \"@webiny/api-page-builder/types\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport get from \"lodash/get\";\nimport { s3Stream } from \"./s3Stream\";\nimport Zipper from \"./zipper\";\n\nexport const EXPORT_PAGES_FOLDER_KEY = \"WEBINY_PB_EXPORT_PAGES\";\n\nasync function getFilteredFiles(files: ImageFile[]) {\n const uniqueFileKeys = new Map<string, boolean>();\n const promises = files.map(file => s3Stream.isFileAccessible(file.key));\n const isFileAvailableResults = await Promise.all(promises);\n\n const filesAvailableForDownload = [];\n // Filter files\n for (let i = 0; i < files.length; i++) {\n const file = files[i];\n // Check file accessibility\n if (isFileAvailableResults[i] && !uniqueFileKeys.has(file.key)) {\n filesAvailableForDownload.push(file);\n uniqueFileKeys.set(file.key, true);\n }\n }\n return filesAvailableForDownload;\n}\n\nexport interface ExportedPageData {\n page: Pick<Page, \"content\" | \"title\" | \"version\" | \"status\" | \"settings\" | \"path\">;\n files: ImageFile[];\n}\n\nexport async function exportPage(\n page: Page,\n exportPagesDataKey: string,\n fileManager: FileManagerContext[\"fileManager\"]\n): Promise<S3.ManagedUpload.SendData> {\n // Extract all files\n const files = extractFilesFromPageData(page.content || {});\n // Filter files\n const filesAvailableForDownload = await getFilteredFiles(files);\n // Extract images from page settings\n const pageSettingsImages = [\n get(page, \"settings.general.image\"),\n get(page, \"settings.social.image\")\n ].filter(image => image && image.src);\n const pageSettingsImagesData = [];\n // Get file data for all images inside \"page.settings\"\n for (let i = 0; i < pageSettingsImages.length; i++) {\n const { id } = pageSettingsImages[i];\n const file = await fileManager.files.getFile(id);\n pageSettingsImagesData.push(file);\n }\n\n // Extract the page data in a json file and upload it to S3\n const pageData = {\n page: {\n content: page.content,\n title: page.title,\n path: page.path,\n version: page.version,\n status: page.status,\n settings: page.settings\n },\n files: [...filesAvailableForDownload, ...pageSettingsImagesData]\n };\n const pageDataBuffer = Buffer.from(JSON.stringify(pageData));\n\n const zipper = new Zipper({\n exportInfo: {\n files: [...filesAvailableForDownload, ...pageSettingsImagesData],\n pageTitle: page.title,\n pageDataBuffer\n },\n archiveFileKey: exportPagesDataKey\n });\n\n return zipper.process();\n}\n\nexport interface ImageFile extends Omit<File, \"src\"> {\n key: string;\n}\n\nexport function extractFilesFromPageData(\n data: Record<string, any>,\n files: any[] = []\n): ImageFile[] {\n // Base case: termination\n if (!data || typeof data !== \"object\") {\n return files;\n }\n // Recursively call function for each element\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const element = data[i];\n extractFilesFromPageData(element, files);\n }\n return files;\n }\n\n // Main\n const tuple = Object.entries(data);\n for (let i = 0; i < tuple.length; i++) {\n const [key, value] = tuple[i];\n // TODO: @ashutosh extract it to plugins, so that, we can handle cases for other components too.\n if (key === \"file\" && value) {\n files.push(value);\n } else if (key === \"images\" && Array.isArray(value)) {\n // Handle case for \"images-list\" component\n files.push(...value);\n } else {\n extractFilesFromPageData(value, files);\n }\n }\n return files;\n}\n"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAEO,MAAMA,uBAAuB,GAAG,wBAAhC;;;AAEP,eAAeC,gBAAf,CAAgCC,KAAhC,EAAoD;EAChD,MAAMC,cAAc,GAAG,IAAIC,GAAJ,EAAvB;EACA,MAAMC,QAAQ,GAAGH,KAAK,CAACI,GAAN,CAAUC,IAAI,IAAIC,kBAAA,CAASC,gBAAT,CAA0BF,IAAI,CAACG,GAA/B,CAAlB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EAAiCD,CAAC,EAAlC,EAAsC;MAClC,MAAMuC,OAAO,GAAGH,IAAI,CAACpC,CAAD,CAApB;MACAS,wBAAwB,CAAC8B,OAAD,EAAUpD,KAAV,CAAxB;IACH;;IACD,OAAOA,KAAP;EACH,CAZU,CAcX;;;EACA,MAAMqD,KAAK,GAAGC,MAAM,CAACC,OAAP,CAAeN,IAAf,CAAd;;EACA,KAAK,IAAIpC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGwC,KAAK,CAACvC,MAA1B,EAAkCD,CAAC,EAAnC,EAAuC;IACnC,MAAM,CAACL,GAAD,EAAMgD,KAAN,IAAeH,KAAK,CAACxC,CAAD,CAA1B,CADmC,CAEnC;;IACA,IAAIL,GAAG,KAAK,MAAR,IAAkBgD,KAAtB,EAA6B;MACzBxD,KAAK,CAACgB,IAAN,CAAWwC,KAAX;IACH,CAFD,MAEO,IAAIhD,GAAG,KAAK,QAAR,IAAoB0C,KAAK,CAACC,OAAN,CAAcK,KAAd,CAAxB,EAA8C;MACjD;MACAxD,KAAK,CAACgB,IAAN,CAAW,GAAGwC,KAAd;IACH,CAHM,MAGA;MACHlC,wBAAwB,CAACkC,KAAD,EAAQxD,KAAR,CAAxB;IACH;EACJ;;EACD,OAAOA,KAAP;AACH"}
|
package/exportPages/zipper.js
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
4
|
-
|
5
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
6
|
-
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
8
|
-
value: true
|
9
|
-
});
|
10
|
-
exports.default = exports.ZipOfZip = void 0;
|
11
|
-
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
13
|
-
|
14
|
-
var _archiver = _interopRequireDefault(require("archiver"));
|
15
|
-
|
16
|
-
var _stream = require("stream");
|
17
|
-
|
18
|
-
var path = _interopRequireWildcard(require("path"));
|
19
|
-
|
20
|
-
var _kebabCase = _interopRequireDefault(require("lodash/kebabCase"));
|
21
|
-
|
22
|
-
var _uniqid = _interopRequireDefault(require("uniqid"));
|
23
|
-
|
24
|
-
var _s3Stream = require("./s3Stream");
|
25
|
-
|
26
|
-
// TODO: Move "archive" in layer
|
27
|
-
class Zipper {
|
28
|
-
constructor(config) {
|
29
|
-
(0, _defineProperty2.default)(this, "archiveFormat", "zip");
|
30
|
-
(0, _defineProperty2.default)(this, "filesDirName", "assets");
|
31
|
-
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
32
|
-
(0, _defineProperty2.default)(this, "config", void 0);
|
33
|
-
this.config = config;
|
34
|
-
this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.pageTitle)}.zip`);
|
35
|
-
}
|
36
|
-
|
37
|
-
s3DownloadStreams() {
|
38
|
-
const exportInfo = this.config.exportInfo;
|
39
|
-
const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.pageTitle)}`);
|
40
|
-
const files = exportInfo.files.map(({
|
41
|
-
key
|
42
|
-
}) => {
|
43
|
-
return {
|
44
|
-
stream: _s3Stream.s3Stream.readStream(key),
|
45
|
-
filename: `${prefix}\\${this.filesDirName}\\${path.basename(key)}`
|
46
|
-
};
|
47
|
-
});
|
48
|
-
return [...files, {
|
49
|
-
stream: _stream.Readable.from(exportInfo.pageDataBuffer),
|
50
|
-
filename: `${prefix}\\${exportInfo.pageTitle}.json`
|
51
|
-
}];
|
52
|
-
}
|
53
|
-
|
54
|
-
process() {
|
55
|
-
const {
|
56
|
-
streamPassThrough,
|
57
|
-
streamPassThroughUploadPromise
|
58
|
-
} = _s3Stream.s3Stream.writeStream(this.archiveFileName); // 1. Read all files from S3 using stream.
|
59
|
-
|
60
|
-
|
61
|
-
const s3FilesStreams = this.s3DownloadStreams(); // 2. Prepare zip from the file stream.
|
62
|
-
|
63
|
-
const archive = _archiver.default.create(this.archiveFormat); // Handle archive events.
|
64
|
-
|
65
|
-
|
66
|
-
archive.on("error", error => {
|
67
|
-
throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
|
68
|
-
}); // Append all file streams to archive.
|
69
|
-
|
70
|
-
s3FilesStreams.forEach(streamDetails => archive.append(streamDetails.stream, {
|
71
|
-
name: streamDetails.filename
|
72
|
-
})); // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
|
73
|
-
|
74
|
-
archive.pipe(streamPassThrough); // Finalize the archive (ie we are done appending files but streams have to finish yet)
|
75
|
-
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
|
76
|
-
|
77
|
-
archive.finalize(); // 3. Return upload stream promise.
|
78
|
-
|
79
|
-
return streamPassThroughUploadPromise;
|
80
|
-
}
|
81
|
-
|
82
|
-
}
|
83
|
-
|
84
|
-
exports.default = Zipper;
|
85
|
-
const PAGE_EXPORT_BASENAME = `WEBINY_PAGE_EXPORT.zip`;
|
86
|
-
|
87
|
-
class ZipOfZip {
|
88
|
-
constructor(keys) {
|
89
|
-
(0, _defineProperty2.default)(this, "archiveFormat", "zip");
|
90
|
-
(0, _defineProperty2.default)(this, "archiveFileName", void 0);
|
91
|
-
(0, _defineProperty2.default)(this, "keys", void 0);
|
92
|
-
this.keys = keys;
|
93
|
-
this.archiveFileName = (0, _uniqid.default)("", `-${PAGE_EXPORT_BASENAME}`);
|
94
|
-
}
|
95
|
-
|
96
|
-
getFileStreams() {
|
97
|
-
return this.keys.map(key => {
|
98
|
-
return {
|
99
|
-
stream: _s3Stream.s3Stream.readStream(key),
|
100
|
-
filename: `${path.basename(key)}`
|
101
|
-
};
|
102
|
-
});
|
103
|
-
}
|
104
|
-
|
105
|
-
process() {
|
106
|
-
const {
|
107
|
-
streamPassThrough,
|
108
|
-
streamPassThroughUploadPromise
|
109
|
-
} = _s3Stream.s3Stream.writeStream(this.archiveFileName); // 1. Read all files from S3 using stream.
|
110
|
-
|
111
|
-
|
112
|
-
const fileStreamDetails = this.getFileStreams(); // 2. Prepare zip from the file stream.
|
113
|
-
|
114
|
-
const archive = _archiver.default.create(this.archiveFormat); // Handle archive events.
|
115
|
-
|
116
|
-
|
117
|
-
archive.on("error", error => {
|
118
|
-
throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
|
119
|
-
}); // Append all file streams to archive.
|
120
|
-
|
121
|
-
fileStreamDetails.forEach(streamDetails => archive.append(streamDetails.stream, {
|
122
|
-
name: streamDetails.filename
|
123
|
-
})); // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
|
124
|
-
|
125
|
-
archive.pipe(streamPassThrough); // Finalize the archive (ie we are done appending files but streams have to finish yet)
|
126
|
-
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
|
127
|
-
|
128
|
-
archive.finalize(); // 3. Return upload stream promise.
|
129
|
-
|
130
|
-
return streamPassThroughUploadPromise;
|
131
|
-
}
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
exports.ZipOfZip = ZipOfZip;
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["Zipper","constructor","config","archiveFileName","uniqueId","archiveFileKey","kebabCase","exportInfo","pageTitle","s3DownloadStreams","prefix","files","map","key","stream","s3Stream","readStream","filename","filesDirName","path","basename","Readable","from","pageDataBuffer","process","streamPassThrough","streamPassThroughUploadPromise","writeStream","s3FilesStreams","archive","vending","create","archiveFormat","on","error","Error","name","code","message","stack","forEach","streamDetails","append","pipe","finalize","PAGE_EXPORT_BASENAME","ZipOfZip","keys","getFileStreams","fileStreamDetails"],"sources":["zipper.ts"],"sourcesContent":["// TODO: Move \"archive\" in layer\nimport vending, { ArchiverError } from \"archiver\";\nimport S3 from \"aws-sdk/clients/s3\";\nimport { Readable } from \"stream\";\nimport * as path from \"path\";\nimport kebabCase from \"lodash/kebabCase\";\nimport uniqueId from \"uniqid\";\nimport { s3Stream } from \"./s3Stream\";\nimport { ImageFile } from \"./utils\";\n\ninterface FileStreamDetails {\n stream: Readable;\n filename: string;\n}\n\ninterface ExportInfo {\n files: ImageFile[];\n pageTitle: string;\n pageDataBuffer: Buffer;\n}\n\nexport interface ZipperConfig {\n exportInfo: ExportInfo;\n archiveFileKey: string;\n}\n\nexport default class Zipper {\n private readonly archiveFormat = \"zip\";\n private readonly filesDirName = \"assets\";\n private readonly archiveFileName: string;\n config: ZipperConfig;\n\n constructor(config: ZipperConfig) {\n this.config = config;\n this.archiveFileName = uniqueId(\n `${this.config.archiveFileKey}/`,\n `-${kebabCase(this.config.exportInfo.pageTitle)}.zip`\n );\n }\n\n s3DownloadStreams(): FileStreamDetails[] {\n const exportInfo = this.config.exportInfo;\n const prefix = uniqueId(\"\", `-${kebabCase(exportInfo.pageTitle)}`);\n const files = exportInfo.files.map(({ key }) => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${prefix}\\\\${this.filesDirName}\\\\${path.basename(key)}`\n };\n });\n\n return [\n ...files,\n {\n stream: Readable.from(exportInfo.pageDataBuffer),\n filename: `${prefix}\\\\${exportInfo.pageTitle}.json`\n }\n ];\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const s3FilesStreams = this.s3DownloadStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n s3FilesStreams.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n\nconst PAGE_EXPORT_BASENAME = `WEBINY_PAGE_EXPORT.zip`;\n\nexport class ZipOfZip {\n private readonly archiveFormat = \"zip\";\n private readonly archiveFileName: string;\n keys: string[];\n\n constructor(keys: string[]) {\n this.keys = keys;\n this.archiveFileName = uniqueId(\"\", `-${PAGE_EXPORT_BASENAME}`);\n }\n\n getFileStreams(): FileStreamDetails[] {\n return this.keys.map(key => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${path.basename(key)}`\n };\n });\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const fileStreamDetails = this.getFileStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n fileStreamDetails.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAPA;AA0Be,MAAMA,MAAN,CAAa;EAMxBC,WAAW,CAACC,MAAD,EAAuB;IAAA,qDALD,KAKC;IAAA,oDAJF,QAIE;IAAA;IAAA;IAC9B,KAAKA,MAAL,GAAcA,MAAd;IACA,KAAKC,eAAL,GAAuB,IAAA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AAQC,MAAR,CAAe,KAAKC,aAApB,CAAhB,CAT0C,CAU1C;;;IACAH,OAAO,CAACI,EAAR,CAAW,OAAX,EAAqBC,KAAD,IAA0B;MAC1C,MAAM,IAAIC,KAAJ,CACD,GAAED,KAAK,CAACE,IAAK,IAAGF,KAAK,CAACG,IAAK,IAAGH,KAAK,CAACI,OAAQ,IAAGJ,KAAK,CAACf,IAAK,IAAGe,KAAK,CAACK,KAAM,EADxE,CAAN;IAGH,CAJD,EAX0C,CAiB1C;;IACAU,iBAAiB,CAACT,OAAlB,CAA2BC,aAAD,IACtBZ,OAAO,CAACa,MAAR,CAAeD,aAAa,CAAC3B,MAA7B,EAAqC;MAAEsB,IAAI,EAAEK,aAAa,CAACxB;IAAtB,CAArC,CADJ,EAlB0C,CAsB1C;;IACAY,OAAO,CAACc,IAAR,CAAalB,iBAAb,EAvB0C,CAwB1C;IACA;;IACAI,OAAO,CAACe,QAAR,GA1B0C,CA4B1C;;IACA,OAAOlB,8BAAP;EACH;;AAjDiB"}
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import { ContextPlugin } from "@webiny/api";
|
2
|
-
import { PageImportExportPluginsParams } from "../../types";
|
3
|
-
import { PbPageImportExportContext } from "../types";
|
4
|
-
declare const _default: ({ storageOperations }: PageImportExportPluginsParams) => ContextPlugin<PbPageImportExportContext>;
|
5
|
-
export default _default;
|