@webiny/api-page-builder-import-export 0.0.0-unstable.97a151f74d → 0.0.0-unstable.98511f29f1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/client.d.ts +2 -2
  2. package/client.js +2 -6
  3. package/client.js.map +1 -1
  4. package/export/combine/blocksHandler.d.ts +6 -0
  5. package/export/combine/blocksHandler.js +99 -0
  6. package/export/combine/blocksHandler.js.map +1 -0
  7. package/export/combine/formsHandler.d.ts +6 -0
  8. package/export/combine/formsHandler.js +99 -0
  9. package/export/combine/formsHandler.js.map +1 -0
  10. package/{exportPages → export}/combine/index.d.ts +3 -2
  11. package/export/combine/index.js +42 -0
  12. package/export/combine/index.js.map +1 -0
  13. package/export/combine/pagesHandler.d.ts +6 -0
  14. package/export/combine/pagesHandler.js +99 -0
  15. package/export/combine/pagesHandler.js.map +1 -0
  16. package/export/combine/templatesHandler.d.ts +6 -0
  17. package/export/combine/templatesHandler.js +99 -0
  18. package/export/combine/templatesHandler.js.map +1 -0
  19. package/export/process/blocksHandler.d.ts +6 -0
  20. package/export/process/blocksHandler.js +167 -0
  21. package/export/process/blocksHandler.js.map +1 -0
  22. package/export/process/exporters/BlockExporter.d.ts +13 -0
  23. package/export/process/exporters/BlockExporter.js +81 -0
  24. package/export/process/exporters/BlockExporter.js.map +1 -0
  25. package/export/process/exporters/FormExporter.d.ts +9 -0
  26. package/export/process/exporters/FormExporter.js +34 -0
  27. package/export/process/exporters/FormExporter.js.map +1 -0
  28. package/export/process/exporters/PageExporter.d.ts +11 -0
  29. package/export/process/exporters/PageExporter.js +58 -0
  30. package/export/process/exporters/PageExporter.js.map +1 -0
  31. package/export/process/exporters/PageTemplateExporter.d.ts +11 -0
  32. package/export/process/exporters/PageTemplateExporter.js +56 -0
  33. package/export/process/exporters/PageTemplateExporter.js.map +1 -0
  34. package/export/process/formsHandler.d.ts +6 -0
  35. package/export/process/formsHandler.js +187 -0
  36. package/export/process/formsHandler.js.map +1 -0
  37. package/{exportPages → export}/process/index.d.ts +4 -6
  38. package/export/process/index.js +39 -0
  39. package/export/process/index.js.map +1 -0
  40. package/export/process/pagesHandler.d.ts +6 -0
  41. package/export/process/pagesHandler.js +189 -0
  42. package/export/process/pagesHandler.js.map +1 -0
  43. package/export/process/templatesHandler.d.ts +6 -0
  44. package/export/process/templatesHandler.js +166 -0
  45. package/export/process/templatesHandler.js.map +1 -0
  46. package/{exportPages → export}/s3Stream.d.ts +5 -2
  47. package/{exportPages → export}/s3Stream.js +1 -20
  48. package/export/s3Stream.js.map +1 -0
  49. package/export/utils.d.ts +2 -0
  50. package/export/utils.js +35 -0
  51. package/export/utils.js.map +1 -0
  52. package/{exportPages → export}/zipper.d.ts +6 -5
  53. package/{exportPages → export}/zipper.js +38 -49
  54. package/export/zipper.js.map +1 -0
  55. package/graphql/crud/blocks.crud.d.ts +4 -0
  56. package/graphql/crud/blocks.crud.js +130 -0
  57. package/graphql/crud/blocks.crud.js.map +1 -0
  58. package/graphql/crud/forms.crud.d.ts +4 -0
  59. package/graphql/crud/forms.crud.js +134 -0
  60. package/graphql/crud/forms.crud.js.map +1 -0
  61. package/graphql/crud/importExportTasks.crud.d.ts +5 -0
  62. package/graphql/crud/{pageImportExportTasks.crud.js → importExportTasks.crud.js} +92 -139
  63. package/graphql/crud/importExportTasks.crud.js.map +1 -0
  64. package/graphql/crud/pages.crud.d.ts +3 -2
  65. package/graphql/crud/pages.crud.js +50 -59
  66. package/graphql/crud/pages.crud.js.map +1 -1
  67. package/graphql/crud/templates.crud.d.ts +4 -0
  68. package/graphql/crud/templates.crud.js +128 -0
  69. package/graphql/crud/templates.crud.js.map +1 -0
  70. package/graphql/crud.d.ts +2 -2
  71. package/graphql/crud.js +5 -7
  72. package/graphql/crud.js.map +1 -1
  73. package/graphql/graphql/blocks.gql.d.ts +4 -0
  74. package/graphql/graphql/blocks.gql.js +52 -0
  75. package/graphql/graphql/blocks.gql.js.map +1 -0
  76. package/graphql/graphql/forms.gql.d.ts +4 -0
  77. package/graphql/graphql/forms.gql.js +60 -0
  78. package/graphql/graphql/forms.gql.js.map +1 -0
  79. package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
  80. package/graphql/graphql/{pageImportExportTasks.gql.js → importExportTasks.gql.js} +18 -23
  81. package/graphql/graphql/importExportTasks.gql.js.map +1 -0
  82. package/graphql/graphql/pages.gql.d.ts +2 -2
  83. package/graphql/graphql/pages.gql.js +4 -15
  84. package/graphql/graphql/pages.gql.js.map +1 -1
  85. package/graphql/graphql/templates.gql.d.ts +4 -0
  86. package/graphql/graphql/templates.gql.js +52 -0
  87. package/graphql/graphql/templates.gql.js.map +1 -0
  88. package/graphql/graphql/utils/resolve.d.ts +1 -1
  89. package/graphql/graphql/utils/resolve.js +0 -3
  90. package/graphql/graphql/utils/resolve.js.map +1 -1
  91. package/graphql/graphql.js +5 -6
  92. package/graphql/graphql.js.map +1 -1
  93. package/graphql/index.d.ts +2 -2
  94. package/graphql/index.js +0 -5
  95. package/graphql/index.js.map +1 -1
  96. package/graphql/types.d.ts +82 -23
  97. package/graphql/types.js.map +1 -1
  98. package/import/constants.d.ts +3 -0
  99. package/import/constants.js +14 -0
  100. package/import/constants.js.map +1 -0
  101. package/import/create/blocksHandler.d.ts +3 -0
  102. package/import/create/blocksHandler.js +99 -0
  103. package/import/create/blocksHandler.js.map +1 -0
  104. package/import/create/formsHandler.d.ts +3 -0
  105. package/import/create/formsHandler.js +103 -0
  106. package/import/create/formsHandler.js.map +1 -0
  107. package/{importPages → import}/create/index.d.ts +7 -5
  108. package/import/create/index.js +42 -0
  109. package/import/create/index.js.map +1 -0
  110. package/import/create/pagesHandler.d.ts +3 -0
  111. package/import/create/pagesHandler.js +103 -0
  112. package/import/create/pagesHandler.js.map +1 -0
  113. package/import/create/templatesHandler.d.ts +3 -0
  114. package/import/create/templatesHandler.js +99 -0
  115. package/import/create/templatesHandler.js.map +1 -0
  116. package/import/process/blocks/blocksHandler.d.ts +3 -0
  117. package/import/process/blocks/blocksHandler.js +168 -0
  118. package/import/process/blocks/blocksHandler.js.map +1 -0
  119. package/import/process/blocks/importBlock.d.ts +11 -0
  120. package/import/process/blocks/importBlock.js +106 -0
  121. package/import/process/blocks/importBlock.js.map +1 -0
  122. package/import/process/forms/formsHandler.d.ts +3 -0
  123. package/import/process/forms/formsHandler.js +176 -0
  124. package/import/process/forms/formsHandler.js.map +1 -0
  125. package/import/process/forms/importForm.d.ts +9 -0
  126. package/import/process/forms/importForm.js +43 -0
  127. package/import/process/forms/importForm.js.map +1 -0
  128. package/{importPages → import}/process/index.d.ts +5 -3
  129. package/import/process/index.js +39 -0
  130. package/import/process/index.js.map +1 -0
  131. package/import/process/pages/importPage.d.ts +11 -0
  132. package/import/process/pages/importPage.js +92 -0
  133. package/import/process/pages/importPage.js.map +1 -0
  134. package/import/process/pages/pagesHandler.d.ts +3 -0
  135. package/import/process/pages/pagesHandler.js +183 -0
  136. package/import/process/pages/pagesHandler.js.map +1 -0
  137. package/import/process/templates/importTemplate.d.ts +11 -0
  138. package/import/process/templates/importTemplate.js +66 -0
  139. package/import/process/templates/importTemplate.js.map +1 -0
  140. package/import/process/templates/templatesHandler.d.ts +3 -0
  141. package/import/process/templates/templatesHandler.js +170 -0
  142. package/import/process/templates/templatesHandler.js.map +1 -0
  143. package/import/utils/deleteS3Folder.d.ts +1 -0
  144. package/import/utils/deleteS3Folder.js +19 -0
  145. package/import/utils/deleteS3Folder.js.map +1 -0
  146. package/import/utils/extractAndUploadZipFileContents.d.ts +7 -0
  147. package/import/utils/extractAndUploadZipFileContents.js +122 -0
  148. package/import/utils/extractAndUploadZipFileContents.js.map +1 -0
  149. package/import/utils/extractZipAndUploadToS3.d.ts +2 -0
  150. package/import/utils/extractZipAndUploadToS3.js +98 -0
  151. package/import/utils/extractZipAndUploadToS3.js.map +1 -0
  152. package/import/utils/getFileNameWithoutExt.d.ts +1 -0
  153. package/import/utils/getFileNameWithoutExt.js +11 -0
  154. package/import/utils/getFileNameWithoutExt.js.map +1 -0
  155. package/import/utils/index.d.ts +9 -0
  156. package/import/utils/index.js +104 -0
  157. package/import/utils/index.js.map +1 -0
  158. package/import/utils/initialStats.d.ts +7 -0
  159. package/import/utils/initialStats.js +16 -0
  160. package/import/utils/initialStats.js.map +1 -0
  161. package/import/utils/prepareDataDirMap.d.ts +6 -0
  162. package/import/utils/prepareDataDirMap.js +29 -0
  163. package/import/utils/prepareDataDirMap.js.map +1 -0
  164. package/import/utils/updateFilesInData.d.ts +8 -0
  165. package/import/utils/updateFilesInData.js +49 -0
  166. package/import/utils/updateFilesInData.js.map +1 -0
  167. package/import/utils/uploadAssets.d.ts +10 -0
  168. package/import/utils/uploadAssets.js +87 -0
  169. package/import/utils/uploadAssets.js.map +1 -0
  170. package/import/utils/uploadFilesFromS3.d.ts +3 -0
  171. package/import/utils/uploadFilesFromS3.js +19 -0
  172. package/import/utils/uploadFilesFromS3.js.map +1 -0
  173. package/mockSecurity.js +0 -3
  174. package/mockSecurity.js.map +1 -1
  175. package/package.json +34 -37
  176. package/types.d.ts +83 -65
  177. package/types.js +69 -22
  178. package/types.js.map +1 -1
  179. package/exportPages/combine/index.js +0 -114
  180. package/exportPages/combine/index.js.map +0 -1
  181. package/exportPages/process/index.js +0 -208
  182. package/exportPages/process/index.js.map +0 -1
  183. package/exportPages/s3Stream.js.map +0 -1
  184. package/exportPages/utils.d.ts +0 -13
  185. package/exportPages/utils.js +0 -113
  186. package/exportPages/utils.js.map +0 -1
  187. package/exportPages/zipper.js.map +0 -1
  188. package/graphql/crud/pageImportExportTasks.crud.d.ts +0 -5
  189. package/graphql/crud/pageImportExportTasks.crud.js.map +0 -1
  190. package/graphql/graphql/pageImportExportTasks.gql.d.ts +0 -4
  191. package/graphql/graphql/pageImportExportTasks.gql.js.map +0 -1
  192. package/importPages/create/index.js +0 -118
  193. package/importPages/create/index.js.map +0 -1
  194. package/importPages/process/index.js +0 -185
  195. package/importPages/process/index.js.map +0 -1
  196. package/importPages/utils.d.ts +0 -50
  197. package/importPages/utils.js +0 -570
  198. package/importPages/utils.js.map +0 -1
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.templatesHandler = void 0;
7
+ var _types = require("../../types");
8
+ var _client = require("../../client");
9
+ var _handlerGraphql = require("@webiny/handler-graphql");
10
+ var _mockSecurity = require("../../mockSecurity");
11
+ var _utils = require("@webiny/utils");
12
+ var _PageTemplateExporter = require("./exporters/PageTemplateExporter");
13
+ /**
14
+ * Handles the export templates process workflow.
15
+ */
16
+ const templatesHandler = async (configuration, payload, context) => {
17
+ const log = console.log;
18
+ let subTask;
19
+ let noPendingTask = true;
20
+ let prevStatusOfSubTask = _types.ImportExportTaskStatus.PENDING;
21
+ log("RUNNING Export Templates Process Handler");
22
+ const {
23
+ pageBuilder,
24
+ fileManager
25
+ } = context;
26
+ const {
27
+ taskId,
28
+ subTaskIndex,
29
+ type,
30
+ identity
31
+ } = payload;
32
+ // Disable authorization; this is necessary because we call Page Builder CRUD methods which include authorization checks
33
+ // and this Lambda is invoked internally, without credentials.
34
+ (0, _mockSecurity.mockSecurity)(identity, context);
35
+ try {
36
+ /*
37
+ * Note: We're not going to DB for finding the next sub-task to process,
38
+ * because the data might be out of sync due to GSI eventual consistency.
39
+ */
40
+ subTask = await pageBuilder.importExportTask.getSubTask(taskId, (0, _utils.zeroPad)(subTaskIndex, 5));
41
+ /**
42
+ * Base condition!!
43
+ * Bail out early, if task not found or task's status is not "pending".
44
+ */
45
+ if (!subTask || subTask.status !== _types.ImportExportTaskStatus.PENDING) {
46
+ noPendingTask = true;
47
+ return {
48
+ data: "",
49
+ error: null
50
+ };
51
+ } else {
52
+ noPendingTask = false;
53
+ }
54
+ log(`Fetched sub task => ${subTask.id}`);
55
+ const {
56
+ input
57
+ } = subTask;
58
+ const {
59
+ templateId,
60
+ exportTemplatesDataKey
61
+ } = input;
62
+ const template = await pageBuilder.getPageTemplate({
63
+ where: {
64
+ id: templateId
65
+ }
66
+ });
67
+ if (!template) {
68
+ log(`Unable to load template "${templateId}"`);
69
+ throw new _handlerGraphql.NotFoundError(`Unable to load template "${templateId}"`);
70
+ }
71
+ log(`Processing template key "${templateId}"`);
72
+
73
+ // Mark task status as PROCESSING
74
+ subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
75
+ status: _types.ImportExportTaskStatus.PROCESSING
76
+ });
77
+ // Update stats in main task
78
+ await pageBuilder.importExportTask.updateStats(taskId, {
79
+ prevStatus: prevStatusOfSubTask,
80
+ nextStatus: _types.ImportExportTaskStatus.PROCESSING
81
+ });
82
+ prevStatusOfSubTask = subTask.status;
83
+ log(`Extracting template data and uploading to storage...`);
84
+ const templateExporter = new _PageTemplateExporter.PageTemplateExporter(fileManager);
85
+ const templateDataZip = await templateExporter.execute(template, exportTemplatesDataKey);
86
+ log(`Finish uploading zip...`);
87
+ // Update task record in DB
88
+ subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
89
+ status: _types.ImportExportTaskStatus.COMPLETED,
90
+ data: {
91
+ message: `Finish uploading data for template "${template.id}"`,
92
+ key: templateDataZip.Key
93
+ }
94
+ });
95
+ // Update stats in main task
96
+ await pageBuilder.importExportTask.updateStats(taskId, {
97
+ prevStatus: prevStatusOfSubTask,
98
+ nextStatus: _types.ImportExportTaskStatus.COMPLETED
99
+ });
100
+ prevStatusOfSubTask = subTask.status;
101
+ } catch (e) {
102
+ log("[EXPORT_TEMPLATES_PROCESS] Error => ", e.message);
103
+ if (subTask && subTask.id) {
104
+ /**
105
+ * In case of error, we'll update the task status to "failed",
106
+ * so that, client can show notify the user appropriately.
107
+ */
108
+ subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {
109
+ status: _types.ImportExportTaskStatus.FAILED,
110
+ error: {
111
+ name: e.name,
112
+ message: e.message,
113
+ code: "EXPORT_FAILED"
114
+ }
115
+ });
116
+
117
+ // Update stats in main task
118
+ await pageBuilder.importExportTask.updateStats(taskId, {
119
+ prevStatus: prevStatusOfSubTask,
120
+ nextStatus: _types.ImportExportTaskStatus.FAILED
121
+ });
122
+ prevStatusOfSubTask = subTask.status;
123
+ }
124
+ return {
125
+ data: null,
126
+ error: {
127
+ message: e.message
128
+ }
129
+ };
130
+ } finally {
131
+ // Base condition!
132
+ if (noPendingTask) {
133
+ log(`No pending sub-task for task ${taskId}`);
134
+ // Combine individual template zip files.
135
+ await (0, _client.invokeHandlerClient)({
136
+ context,
137
+ name: configuration.handlers.combine,
138
+ payload: {
139
+ taskId,
140
+ type,
141
+ identity: context.security.getIdentity()
142
+ },
143
+ description: "Export templates - combine"
144
+ });
145
+ } else {
146
+ console.log(`Invoking PROCESS for task "${subTaskIndex + 1}"`);
147
+ // We want to continue with Self invocation no matter if current template error out.
148
+ await (0, _client.invokeHandlerClient)({
149
+ context,
150
+ name: configuration.handlers.process,
151
+ payload: {
152
+ taskId,
153
+ subTaskIndex: subTaskIndex + 1,
154
+ type,
155
+ identity: context.security.getIdentity()
156
+ },
157
+ description: "Export templates - process - subtask"
158
+ });
159
+ }
160
+ }
161
+ return {
162
+ data: "",
163
+ error: null
164
+ };
165
+ };
166
+ exports.templatesHandler = templatesHandler;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_types","require","_client","_handlerGraphql","_mockSecurity","_utils","_PageTemplateExporter","templatesHandler","configuration","payload","context","log","console","subTask","noPendingTask","prevStatusOfSubTask","ImportExportTaskStatus","PENDING","pageBuilder","fileManager","taskId","subTaskIndex","type","identity","mockSecurity","importExportTask","getSubTask","zeroPad","status","data","error","id","input","templateId","exportTemplatesDataKey","template","getPageTemplate","where","NotFoundError","updateSubTask","PROCESSING","updateStats","prevStatus","nextStatus","templateExporter","PageTemplateExporter","templateDataZip","execute","COMPLETED","message","key","Key","e","FAILED","name","code","invokeHandlerClient","handlers","combine","security","getIdentity","description","process","exports"],"sources":["templatesHandler.ts"],"sourcesContent":["import { ImportExportTaskStatus, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { Payload as ExtractPayload } from \"../combine\";\nimport { mockSecurity } from \"~/mockSecurity\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { zeroPad } from \"@webiny/utils\";\nimport { Configuration, Payload, Response } from \"~/export/process\";\nimport { PageTemplateExporter } from \"~/export/process/exporters/PageTemplateExporter\";\n\n/**\n * Handles the export templates process workflow.\n */\nexport const templatesHandler = async (\n configuration: Configuration,\n payload: Payload,\n context: PbImportExportContext\n): Promise<Response> => {\n const log = console.log;\n let subTask;\n let noPendingTask = true;\n let prevStatusOfSubTask = ImportExportTaskStatus.PENDING;\n\n log(\"RUNNING Export Templates Process Handler\");\n const { pageBuilder, fileManager } = context;\n const { taskId, subTaskIndex, type, 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 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.importExportTask.getSubTask(taskId, zeroPad(subTaskIndex, 5));\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 !== ImportExportTaskStatus.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 { templateId, exportTemplatesDataKey } = input;\n\n const template = await pageBuilder.getPageTemplate({ where: { id: templateId } });\n\n if (!template) {\n log(`Unable to load template \"${templateId}\"`);\n throw new NotFoundError(`Unable to load template \"${templateId}\"`);\n }\n\n log(`Processing template key \"${templateId}\"`);\n\n // Mark task status as PROCESSING\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.PROCESSING\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.PROCESSING\n });\n prevStatusOfSubTask = subTask.status;\n\n log(`Extracting template data and uploading to storage...`);\n const templateExporter = new PageTemplateExporter(fileManager);\n const templateDataZip = await templateExporter.execute(template, exportTemplatesDataKey);\n\n log(`Finish uploading zip...`);\n // Update task record in DB\n subTask = await pageBuilder.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.COMPLETED,\n data: {\n message: `Finish uploading data for template \"${template.id}\"`,\n key: templateDataZip.Key\n }\n });\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.COMPLETED\n });\n prevStatusOfSubTask = subTask.status;\n } catch (e) {\n log(\"[EXPORT_TEMPLATES_PROCESS] Error => \", e.message);\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.importExportTask.updateSubTask(taskId, subTask.id, {\n status: ImportExportTaskStatus.FAILED,\n error: {\n name: e.name,\n message: e.message,\n code: \"EXPORT_FAILED\"\n }\n });\n\n // Update stats in main task\n await pageBuilder.importExportTask.updateStats(taskId, {\n prevStatus: prevStatusOfSubTask,\n nextStatus: ImportExportTaskStatus.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 template zip files.\n await invokeHandlerClient<ExtractPayload>({\n context,\n name: configuration.handlers.combine,\n payload: {\n taskId,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export templates - 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 template error out.\n await invokeHandlerClient<Payload>({\n context,\n name: configuration.handlers.process,\n payload: {\n taskId,\n subTaskIndex: subTaskIndex + 1,\n type,\n identity: context.security.getIdentity()\n },\n description: \"Export templates - process - subtask\"\n });\n }\n }\n return {\n data: \"\",\n error: null\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,qBAAA,GAAAL,OAAA;AAEA;AACA;AACA;AACO,MAAMM,gBAAgB,GAAG,MAAAA,CAC5BC,aAA4B,EAC5BC,OAAgB,EAChBC,OAA8B,KACV;EACpB,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;EACvB,IAAIE,OAAO;EACX,IAAIC,aAAa,GAAG,IAAI;EACxB,IAAIC,mBAAmB,GAAGC,6BAAsB,CAACC,OAAO;EAExDN,GAAG,CAAC,0CAA0C,CAAC;EAC/C,MAAM;IAAEO,WAAW;IAAEC;EAAY,CAAC,GAAGT,OAAO;EAC5C,MAAM;IAAEU,MAAM;IAAEC,YAAY;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAGd,OAAO;EACxD;EACA;EACA,IAAAe,0BAAY,EAACD,QAAQ,EAAsBb,OAAO,CAAC;EACnD,IAAI;IACA;AACR;AACA;AACA;IACQG,OAAO,GAAG,MAAMK,WAAW,CAACO,gBAAgB,CAACC,UAAU,CAACN,MAAM,EAAE,IAAAO,cAAO,EAACN,YAAY,EAAE,CAAC,CAAC,CAAC;IACzF;AACR;AACA;AACA;IACQ,IAAI,CAACR,OAAO,IAAIA,OAAO,CAACe,MAAM,KAAKZ,6BAAsB,CAACC,OAAO,EAAE;MAC/DH,aAAa,GAAG,IAAI;MACpB,OAAO;QACHe,IAAI,EAAE,EAAE;QACRC,KAAK,EAAE;MACX,CAAC;IACL,CAAC,MAAM;MACHhB,aAAa,GAAG,KAAK;IACzB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AAAoC,2BAAmB,EAAiB;QACtC9C,OAAO;QACP4C,IAAI,EAAE9C,aAAa,CAACiD,QAAQ,CAACC,OAAO;QACpCjD,OAAO,EAAE;UACLW,MAAM;UACNE,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAACiD,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN,CAAC,MAAM;MACHjD,OAAO,CAACD,GAAG,CAAE,8BAA6BU,YAAY,GAAG,CAAE,GAAE,CAAC;MAC9D;MACA,MAAM,IAAAmC,2BAAmB,EAAU;QAC/B9C,OAAO;QACP4C,IAAI,EAAE9C,aAAa,CAACiD,QAAQ,CAACK,OAAO;QACpCrD,OAAO,EAAE;UACLW,MAAM;UACNC,YAAY,EAAEA,YAAY,GAAG,CAAC;UAC9BC,IAAI;UACJC,QAAQ,EAAEb,OAAO,CAACiD,QAAQ,CAACC,WAAW,CAAC;QAC3C,CAAC;QACDC,WAAW,EAAE;MACjB,CAAC,CAAC;IACN;EACJ;EACA,OAAO;IACHhC,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACX,CAAC;AACL,CAAC;AAACiC,OAAA,CAAAxD,gBAAA,GAAAA,gBAAA"}
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { PassThrough, Readable } from "stream";
3
+ import { Readable } from "stream";
4
4
  import S3 from "aws-sdk/clients/s3";
5
5
  declare class S3Stream {
6
6
  s3: S3;
@@ -16,7 +16,10 @@ declare class S3Stream {
16
16
  getObjectHead(Key: string): Promise<S3.HeadObjectOutput>;
17
17
  readStream(Key: string): Readable;
18
18
  writeStream(Key: string, contentType?: string): {
19
- streamPassThrough: PassThrough;
19
+ streamPassThrough: import("stream").PassThrough;
20
+ /**
21
+ * We're not using the `FileManager` storage plugin here because it currently doesn't support streams.
22
+ */
20
23
  streamPassThroughUploadPromise: Promise<S3.ManagedUpload.SendData>;
21
24
  };
22
25
  upload(params: {
@@ -1,22 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.s3Stream = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
10
  var _stream = require("stream");
15
-
16
11
  var _s = _interopRequireDefault(require("aws-sdk/clients/s3"));
17
-
18
12
  const ARCHIVE_CONTENT_TYPE = "application/zip";
19
-
20
13
  class S3Stream {
21
14
  constructor() {
22
15
  (0, _defineProperty2.default)(this, "s3", void 0);
@@ -26,22 +19,19 @@ class S3Stream {
26
19
  });
27
20
  this.bucket = process.env.S3_BUCKET;
28
21
  }
29
-
30
22
  getPresignedUrl(key) {
31
23
  return this.s3.getSignedUrl("getObject", {
32
24
  Bucket: this.bucket,
33
25
  Key: key,
34
26
  Expires: 604800 // 1 week
35
-
36
27
  });
37
28
  }
29
+
38
30
  /**
39
31
  * We're checking if the file is accessible on S3 by getting object meta data.
40
32
  * It help us to filter files that we need to download as part of export data.
41
33
  * @param Key {string}
42
34
  */
43
-
44
-
45
35
  async isFileAccessible(Key) {
46
36
  try {
47
37
  await this.getObjectHead(Key);
@@ -52,21 +42,18 @@ class S3Stream {
52
42
  return false;
53
43
  }
54
44
  }
55
-
56
45
  getObjectHead(Key) {
57
46
  return this.s3.headObject({
58
47
  Bucket: this.bucket,
59
48
  Key
60
49
  }).promise();
61
50
  }
62
-
63
51
  readStream(Key) {
64
52
  return this.s3.getObject({
65
53
  Bucket: this.bucket,
66
54
  Key
67
55
  }).createReadStream();
68
56
  }
69
-
70
57
  writeStream(Key, contentType = ARCHIVE_CONTENT_TYPE) {
71
58
  const streamPassThrough = new _stream.Stream.PassThrough();
72
59
  const params = {
@@ -78,36 +65,30 @@ class S3Stream {
78
65
  };
79
66
  return {
80
67
  streamPassThrough: streamPassThrough,
81
-
82
68
  /**
83
69
  * We're not using the `FileManager` storage plugin here because it currently doesn't support streams.
84
70
  */
85
71
  streamPassThroughUploadPromise: this.s3.upload(params).promise()
86
72
  };
87
73
  }
88
-
89
74
  upload(params) {
90
75
  return this.s3.upload((0, _objectSpread2.default)({
91
76
  ACL: "private",
92
77
  Bucket: this.bucket
93
78
  }, params)).promise();
94
79
  }
95
-
96
80
  listObject(prefix) {
97
81
  return this.s3.listObjects({
98
82
  Bucket: this.bucket,
99
83
  Prefix: prefix
100
84
  }).promise();
101
85
  }
102
-
103
86
  deleteObject(key) {
104
87
  return this.s3.deleteObject({
105
88
  Key: key,
106
89
  Bucket: this.bucket
107
90
  }).promise();
108
91
  }
109
-
110
92
  }
111
-
112
93
  const s3Stream = new S3Stream();
113
94
  exports.s3Stream = s3Stream;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_stream","require","_s","_interopRequireDefault","ARCHIVE_CONTENT_TYPE","S3Stream","constructor","_defineProperty2","default","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","_objectSpread2","listObject","prefix","listObjects","Prefix","deleteObject","s3Stream","exports"],"sources":["s3Stream.ts"],"sourcesContent":["import { Stream, 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(Key: string, contentType: string = ARCHIVE_CONTENT_TYPE) {\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,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,EAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,MAAMG,oBAAoB,GAAG,iBAAiB;AAE9C,MAAMC,QAAQ,CAAC;EAIXC,WAAWA,CAAA,EAAG;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IAAA,IAAA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AAG;MAChCC,GAAG,EAAE,SAAS;MACdC,IAAI,EAAEL,iBAAiB;MACvBhB,MAAM,EAAE,IAAI,CAACL,MAAM;MACnB2B,WAAW,EAAEP,WAAW;MACxBd;IACJ,CAAC;IAED,OAAO;MACHe,iBAAiB,EAAEA,iBAAiB;MACpC;AACZ;AACA;MACYO,8BAA8B,EAAE,IAAI,CAAClC,EAAE,CAACmC,MAAM,CAACL,MAAM,CAAC,CAACT,OAAO,CAAC;IACnE,CAAC;EACL;EAEAc,MAAMA,CAACL,MAIN,EAAsC;IACnC,OAAO,IAAI,CAAC9B,EAAE,CACTmC,MAAM,KAAAC,cAAA,CAAArC,OAAA;MACHgC,GAAG,EAAE,SAAS;MACdpB,MAAM,EAAE,IAAI,CAACL;IAAM,GAChBwB,MAAM,CACZ,CAAC,CACDT,OAAO,CAAC,CAAC;EAClB;EAEAgB,UAAUA,CAACC,MAAc,EAAiC;IACtD,OAAO,IAAI,CAACtC,EAAE,CACTuC,WAAW,CAAC;MACT5B,MAAM,EAAE,IAAI,CAACL,MAAM;MACnBkC,MAAM,EAAEF;IACZ,CAAC,CAAC,CACDjB,OAAO,CAAC,CAAC;EAClB;EAEAoB,YAAYA,CAAChC,GAAW,EAAkC;IACtD,OAAO,IAAI,CAACT,EAAE,CAACyC,YAAY,CAAC;MAAE7B,GAAG,EAAEH,GAAG;MAAEE,MAAM,EAAE,IAAI,CAACL;IAAO,CAAC,CAAC,CAACe,OAAO,CAAC,CAAC;EAC5E;AACJ;AAEO,MAAMqB,QAAQ,GAAG,IAAI9C,QAAQ,CAAC,CAAC;AAAC+C,OAAA,CAAAD,QAAA,GAAAA,QAAA"}
@@ -0,0 +1,2 @@
1
+ import { File } from "@webiny/api-file-manager/types";
2
+ export declare function extractFilesFromData(data: Record<string, any>, files?: File[]): File[];
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.extractFilesFromData = extractFilesFromData;
7
+ function extractFilesFromData(data, files = []) {
8
+ if (!data || typeof data !== "object") {
9
+ return files;
10
+ }
11
+
12
+ // Recursively call function for each element
13
+ if (Array.isArray(data)) {
14
+ for (let i = 0; i < data.length; i++) {
15
+ const element = data[i];
16
+ extractFilesFromData(element, files);
17
+ }
18
+ return files;
19
+ }
20
+
21
+ // Main
22
+ const tuple = Object.entries(data);
23
+ for (let i = 0; i < tuple.length; i++) {
24
+ const [key, value] = tuple[i];
25
+ if (key === "file" && value) {
26
+ files.push(value);
27
+ } else if (key === "images" && Array.isArray(value)) {
28
+ // Handle case for "images-list" component
29
+ files.push(...value);
30
+ } else {
31
+ extractFilesFromData(value, files);
32
+ }
33
+ }
34
+ return files;
35
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["extractFilesFromData","data","files","Array","isArray","i","length","element","tuple","Object","entries","key","value","push"],"sources":["utils.ts"],"sourcesContent":["import { File } from \"@webiny/api-file-manager/types\";\n\nexport function extractFilesFromData(data: Record<string, any>, files: File[] = []) {\n if (!data || typeof data !== \"object\") {\n return files;\n }\n\n // Recursively call function for each element\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const element = data[i];\n extractFilesFromData(element, files);\n }\n return files;\n }\n\n // Main\n const tuple = Object.entries(data);\n for (let i = 0; i < tuple.length; i++) {\n const [key, value] = tuple[i];\n if (key === \"file\" && value) {\n files.push(value);\n } else if (key === \"images\" && Array.isArray(value)) {\n // Handle case for \"images-list\" component\n files.push(...value);\n } else {\n extractFilesFromData(value, files);\n }\n }\n return files;\n}\n"],"mappings":";;;;;;AAEO,SAASA,oBAAoBA,CAACC,IAAyB,EAAEC,KAAa,GAAG,EAAE,EAAE;EAChF,IAAI,CAACD,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IACnC,OAAOC,KAAK;EAChB;;EAEA;EACA,IAAIC,KAAK,CAACC,OAAO,CAACH,IAAI,CAAC,EAAE;IACrB,KAAK,IAAII,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGJ,IAAI,CAACK,MAAM,EAAED,CAAC,EAAE,EAAE;MAClC,MAAME,OAAO,GAAGN,IAAI,CAACI,CAAC,CAAC;MACvBL,oBAAoB,CAACO,OAAO,EAAEL,KAAK,CAAC;IACxC;IACA,OAAOA,KAAK;EAChB;;EAEA;EACA,MAAMM,KAAK,GAAGC,MAAM,CAACC,OAAO,CAACT,IAAI,CAAC;EAClC,KAAK,IAAII,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGG,KAAK,CAACF,MAAM,EAAED,CAAC,EAAE,EAAE;IACnC,MAAM,CAACM,GAAG,EAAEC,KAAK,CAAC,GAAGJ,KAAK,CAACH,CAAC,CAAC;IAC7B,IAAIM,GAAG,KAAK,MAAM,IAAIC,KAAK,EAAE;MACzBV,KAAK,CAACW,IAAI,CAACD,KAAK,CAAC;IACrB,CAAC,MAAM,IAAID,GAAG,KAAK,QAAQ,IAAIR,KAAK,CAACC,OAAO,CAACQ,KAAK,CAAC,EAAE;MACjD;MACAV,KAAK,CAACW,IAAI,CAAC,GAAGD,KAAK,CAAC;IACxB,CAAC,MAAM;MACHZ,oBAAoB,CAACY,KAAK,EAAEV,KAAK,CAAC;IACtC;EACJ;EACA,OAAOA,KAAK;AAChB"}
@@ -2,15 +2,15 @@
2
2
  /// <reference types="node" />
3
3
  import S3 from "aws-sdk/clients/s3";
4
4
  import { Readable } from "stream";
5
- import { ImageFile } from "./utils";
5
+ import { File } from "@webiny/api-file-manager/types";
6
6
  interface FileStreamDetails {
7
7
  stream: Readable;
8
8
  filename: string;
9
9
  }
10
10
  interface ExportInfo {
11
- files: ImageFile[];
12
- pageTitle: string;
13
- pageDataBuffer: Buffer;
11
+ files: File[];
12
+ name: string;
13
+ dataBuffer: Buffer;
14
14
  }
15
15
  export interface ZipperConfig {
16
16
  exportInfo: ExportInfo;
@@ -29,7 +29,8 @@ export declare class ZipOfZip {
29
29
  private readonly archiveFormat;
30
30
  private readonly archiveFileName;
31
31
  keys: string[];
32
- constructor(keys: string[]);
32
+ filename: string;
33
+ constructor(keys: string[], filename: string);
33
34
  getFileStreams(): FileStreamDetails[];
34
35
  process(): Promise<S3.ManagedUpload.SendData>;
35
36
  }
@@ -1,29 +1,20 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
-
5
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports.default = exports.ZipOfZip = void 0;
11
-
12
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
10
  var _archiver = _interopRequireDefault(require("archiver"));
15
-
16
11
  var _stream = require("stream");
17
-
18
12
  var path = _interopRequireWildcard(require("path"));
19
-
20
13
  var _kebabCase = _interopRequireDefault(require("lodash/kebabCase"));
21
-
22
14
  var _uniqid = _interopRequireDefault(require("uniqid"));
23
-
24
15
  var _s3Stream = require("./s3Stream");
25
-
26
16
  // TODO: Move "archive" in layer
17
+
27
18
  class Zipper {
28
19
  constructor(config) {
29
20
  (0, _defineProperty2.default)(this, "archiveFormat", "zip");
@@ -31,68 +22,66 @@ class Zipper {
31
22
  (0, _defineProperty2.default)(this, "archiveFileName", void 0);
32
23
  (0, _defineProperty2.default)(this, "config", void 0);
33
24
  this.config = config;
34
- this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.pageTitle)}.zip`);
25
+ this.archiveFileName = (0, _uniqid.default)(`${this.config.archiveFileKey}/`, `-${(0, _kebabCase.default)(this.config.exportInfo.name)}.zip`);
35
26
  }
36
-
37
27
  s3DownloadStreams() {
38
28
  const exportInfo = this.config.exportInfo;
39
- const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.pageTitle)}`);
29
+ const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.name)}`);
40
30
  const files = exportInfo.files.map(({
41
31
  key
42
32
  }) => {
43
33
  return {
44
34
  stream: _s3Stream.s3Stream.readStream(key),
45
- filename: `${prefix}\\${this.filesDirName}\\${path.basename(key)}`
35
+ filename: `${prefix}\\${this.filesDirName}\\${key}`
46
36
  };
47
37
  });
48
38
  return [...files, {
49
- stream: _stream.Readable.from(exportInfo.pageDataBuffer),
50
- filename: `${prefix}\\${exportInfo.pageTitle}.json`
39
+ stream: _stream.Readable.from(exportInfo.dataBuffer),
40
+ filename: `${prefix}\\${exportInfo.name}.json`
51
41
  }];
52
42
  }
53
-
54
43
  process() {
55
44
  const {
56
45
  streamPassThrough,
57
46
  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.
47
+ } = _s3Stream.s3Stream.writeStream(this.archiveFileName);
64
48
 
49
+ // 1. Read all files from S3 using stream.
50
+ const s3FilesStreams = this.s3DownloadStreams();
65
51
 
52
+ // 2. Prepare zip from the file stream.
53
+ const archive = _archiver.default.create(this.archiveFormat);
54
+ // Handle archive events.
66
55
  archive.on("error", error => {
67
56
  throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
68
- }); // Append all file streams to archive.
57
+ });
69
58
 
59
+ // Append all file streams to archive.
70
60
  s3FilesStreams.forEach(streamDetails => archive.append(streamDetails.stream, {
71
61
  name: streamDetails.filename
72
- })); // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
62
+ }));
73
63
 
74
- archive.pipe(streamPassThrough); // Finalize the archive (ie we are done appending files but streams have to finish yet)
64
+ // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
65
+ archive.pipe(streamPassThrough);
66
+ // Finalize the archive (ie we are done appending files but streams have to finish yet)
75
67
  // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
68
+ archive.finalize();
76
69
 
77
- archive.finalize(); // 3. Return upload stream promise.
78
-
70
+ // 3. Return upload stream promise.
79
71
  return streamPassThroughUploadPromise;
80
72
  }
81
-
82
73
  }
83
-
84
74
  exports.default = Zipper;
85
- const PAGE_EXPORT_BASENAME = `WEBINY_PAGE_EXPORT.zip`;
86
-
87
75
  class ZipOfZip {
88
- constructor(keys) {
76
+ constructor(keys, filename) {
89
77
  (0, _defineProperty2.default)(this, "archiveFormat", "zip");
90
78
  (0, _defineProperty2.default)(this, "archiveFileName", void 0);
91
79
  (0, _defineProperty2.default)(this, "keys", void 0);
80
+ (0, _defineProperty2.default)(this, "filename", void 0);
92
81
  this.keys = keys;
93
- this.archiveFileName = (0, _uniqid.default)("", `-${PAGE_EXPORT_BASENAME}`);
82
+ this.filename = filename;
83
+ this.archiveFileName = (0, _uniqid.default)("EXPORTS/", `-${filename}`);
94
84
  }
95
-
96
85
  getFileStreams() {
97
86
  return this.keys.map(key => {
98
87
  return {
@@ -101,35 +90,35 @@ class ZipOfZip {
101
90
  };
102
91
  });
103
92
  }
104
-
105
93
  process() {
106
94
  const {
107
95
  streamPassThrough,
108
96
  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.
97
+ } = _s3Stream.s3Stream.writeStream(this.archiveFileName);
115
98
 
99
+ // 1. Read all files from S3 using stream.
100
+ const fileStreamDetails = this.getFileStreams();
116
101
 
102
+ // 2. Prepare zip from the file stream.
103
+ const archive = _archiver.default.create(this.archiveFormat);
104
+ // Handle archive events.
117
105
  archive.on("error", error => {
118
106
  throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
119
- }); // Append all file streams to archive.
107
+ });
120
108
 
109
+ // Append all file streams to archive.
121
110
  fileStreamDetails.forEach(streamDetails => archive.append(streamDetails.stream, {
122
111
  name: streamDetails.filename
123
- })); // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
112
+ }));
124
113
 
125
- archive.pipe(streamPassThrough); // Finalize the archive (ie we are done appending files but streams have to finish yet)
114
+ // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
115
+ archive.pipe(streamPassThrough);
116
+ // Finalize the archive (ie we are done appending files but streams have to finish yet)
126
117
  // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
118
+ archive.finalize();
127
119
 
128
- archive.finalize(); // 3. Return upload stream promise.
129
-
120
+ // 3. Return upload stream promise.
130
121
  return streamPassThroughUploadPromise;
131
122
  }
132
-
133
123
  }
134
-
135
124
  exports.ZipOfZip = ZipOfZip;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_archiver","_interopRequireDefault","require","_stream","path","_interopRequireWildcard","_kebabCase","_uniqid","_s3Stream","Zipper","constructor","config","_defineProperty2","default","archiveFileName","uniqueId","archiveFileKey","kebabCase","exportInfo","name","s3DownloadStreams","prefix","files","map","key","stream","s3Stream","readStream","filename","filesDirName","Readable","from","dataBuffer","process","streamPassThrough","streamPassThroughUploadPromise","writeStream","s3FilesStreams","archive","vending","create","archiveFormat","on","error","Error","code","message","stack","forEach","streamDetails","append","pipe","finalize","exports","ZipOfZip","keys","getFileStreams","basename","fileStreamDetails"],"sources":["zipper.ts"],"sourcesContent":["// TODO: Move \"archive\" in layer\nimport vending, { ArchiverError } from \"archiver\";\nimport S3 from \"aws-sdk/clients/s3\";\nimport { Readable } from \"stream\";\nimport * as path from \"path\";\nimport kebabCase from \"lodash/kebabCase\";\nimport uniqueId from \"uniqid\";\nimport { s3Stream } from \"./s3Stream\";\nimport { File } from \"@webiny/api-file-manager/types\";\n\ninterface FileStreamDetails {\n stream: Readable;\n filename: string;\n}\n\ninterface ExportInfo {\n files: File[];\n name: string;\n dataBuffer: Buffer;\n}\n\nexport interface ZipperConfig {\n exportInfo: ExportInfo;\n archiveFileKey: string;\n}\n\nexport default class Zipper {\n private readonly archiveFormat = \"zip\";\n private readonly filesDirName = \"assets\";\n private readonly archiveFileName: string;\n config: ZipperConfig;\n\n constructor(config: ZipperConfig) {\n this.config = config;\n this.archiveFileName = uniqueId(\n `${this.config.archiveFileKey}/`,\n `-${kebabCase(this.config.exportInfo.name)}.zip`\n );\n }\n\n s3DownloadStreams(): FileStreamDetails[] {\n const exportInfo = this.config.exportInfo;\n const prefix = uniqueId(\"\", `-${kebabCase(exportInfo.name)}`);\n const files = exportInfo.files.map(({ key }) => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${prefix}\\\\${this.filesDirName}\\\\${key}`\n };\n });\n\n return [\n ...files,\n {\n stream: Readable.from(exportInfo.dataBuffer),\n filename: `${prefix}\\\\${exportInfo.name}.json`\n }\n ];\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const s3FilesStreams = this.s3DownloadStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n s3FilesStreams.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n\nexport class ZipOfZip {\n private readonly archiveFormat = \"zip\";\n private readonly archiveFileName: string;\n keys: string[];\n filename: string;\n\n constructor(keys: string[], filename: string) {\n this.keys = keys;\n this.filename = filename;\n this.archiveFileName = uniqueId(\"EXPORTS/\", `-${filename}`);\n }\n\n getFileStreams(): FileStreamDetails[] {\n return this.keys.map(key => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${path.basename(key)}`\n };\n });\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const fileStreamDetails = this.getFileStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n fileStreamDetails.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n"],"mappings":";;;;;;;;;AACA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAC,uBAAA,CAAAH,OAAA;AACA,IAAAI,UAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,OAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAPA;;AA0Be,MAAMO,MAAM,CAAC;EAMxBC,WAAWA,CAACC,MAAoB,EAAE;IAAA,IAAAC,gBAAA,CAAAC,OAAA,yBALD,KAAK;IAAA,IAAAD,gBAAA,CAAAC,OAAA,wBACN,QAAQ;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAA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CAAC,CAAC;EACN;EAEAS,OAAOA,CAAA,EAAuC;IAC1C,MAAM;MAAEC,iBAAiB;MAAEC;IAA+B,CAAC,GAAGT,kBAAQ,CAACU,WAAW,CAC9E,IAAI,CAACtB,eACT,CAAC;;IAED;IACA,MAAM4C,iBAAiB,GAAG,IAAI,CAACF,cAAc,CAAC,CAAC;;IAE/C;IACA,MAAMlB,OAAO,GAAGC,iBAAO,CAACC,MAAM,CAAC,IAAI,CAACC,aAAa,CAAC;IAClD;IACAH,OAAO,CAACI,EAAE,CAAC,OAAO,EAAGC,KAAoB,IAAK;MAC1C,MAAM,IAAIC,KAAK,CACV,GAAED,KAAK,CAACxB,IAAK,IAAGwB,KAAK,CAACE,IAAK,IAAGF,KAAK,CAACG,OAAQ,IAAGH,KAAK,CAACvC,IAAK,IAAGuC,KAAK,CAACI,KAAM,EAC9E,CAAC;IACL,CAAC,CAAC;;IAEF;IACAW,iBAAiB,CAACV,OAAO,CAAEC,aAAgC,IACvDX,OAAO,CAACY,MAAM,CAACD,aAAa,CAACxB,MAAM,EAAE;MAAEN,IAAI,EAAE8B,aAAa,CAACrB;IAAS,CAAC,CACzE,CAAC;;IAED;IACAU,OAAO,CAACa,IAAI,CAACjB,iBAAiB,CAAC;IAC/B;IACA;IACAI,OAAO,CAACc,QAAQ,CAAC,CAAC;;IAElB;IACA,OAAOjB,8BAA8B;EACzC;AACJ;AAACkB,OAAA,CAAAC,QAAA,GAAAA,QAAA"}
@@ -0,0 +1,4 @@
1
+ import { ContextPlugin } from "@webiny/api";
2
+ import { PbImportExportContext } from "../../types";
3
+ declare const _default: ContextPlugin<PbImportExportContext>;
4
+ export default _default;