@webiny/api-page-builder-import-export 0.0.0-ee-vpcs.549378cf03

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 (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -0
  3. package/client.d.ts +8 -0
  4. package/client.js +47 -0
  5. package/client.js.map +1 -0
  6. package/export/combine/blocksHandler.d.ts +6 -0
  7. package/export/combine/blocksHandler.js +106 -0
  8. package/export/combine/blocksHandler.js.map +1 -0
  9. package/export/combine/index.d.ts +16 -0
  10. package/export/combine/index.js +30 -0
  11. package/export/combine/index.js.map +1 -0
  12. package/export/combine/pagesHandler.d.ts +6 -0
  13. package/export/combine/pagesHandler.js +106 -0
  14. package/export/combine/pagesHandler.js.map +1 -0
  15. package/export/process/blocksHandler.d.ts +6 -0
  16. package/export/process/blocksHandler.js +176 -0
  17. package/export/process/blocksHandler.js.map +1 -0
  18. package/export/process/index.d.ts +20 -0
  19. package/export/process/index.js +27 -0
  20. package/export/process/index.js.map +1 -0
  21. package/export/process/pagesHandler.d.ts +6 -0
  22. package/export/process/pagesHandler.js +204 -0
  23. package/export/process/pagesHandler.js.map +1 -0
  24. package/export/s3Stream.d.ts +31 -0
  25. package/export/s3Stream.js +113 -0
  26. package/export/s3Stream.js.map +1 -0
  27. package/export/utils.d.ts +16 -0
  28. package/export/utils.js +135 -0
  29. package/export/utils.js.map +1 -0
  30. package/export/zipper.d.ts +37 -0
  31. package/export/zipper.js +136 -0
  32. package/export/zipper.js.map +1 -0
  33. package/graphql/crud/blocks.crud.d.ts +4 -0
  34. package/graphql/crud/blocks.crud.js +155 -0
  35. package/graphql/crud/blocks.crud.js.map +1 -0
  36. package/graphql/crud/importExportTasks.crud.d.ts +5 -0
  37. package/graphql/crud/importExportTasks.crud.js +411 -0
  38. package/graphql/crud/importExportTasks.crud.js.map +1 -0
  39. package/graphql/crud/pages.crud.d.ts +4 -0
  40. package/graphql/crud/pages.crud.js +172 -0
  41. package/graphql/crud/pages.crud.js.map +1 -0
  42. package/graphql/crud.d.ts +3 -0
  43. package/graphql/crud.js +18 -0
  44. package/graphql/crud.js.map +1 -0
  45. package/graphql/graphql/blocks.gql.d.ts +4 -0
  46. package/graphql/graphql/blocks.gql.js +57 -0
  47. package/graphql/graphql/blocks.gql.js.map +1 -0
  48. package/graphql/graphql/importExportTasks.gql.d.ts +4 -0
  49. package/graphql/graphql/importExportTasks.gql.js +80 -0
  50. package/graphql/graphql/importExportTasks.gql.js.map +1 -0
  51. package/graphql/graphql/pages.gql.d.ts +4 -0
  52. package/graphql/graphql/pages.gql.js +68 -0
  53. package/graphql/graphql/pages.gql.js.map +1 -0
  54. package/graphql/graphql/utils/resolve.d.ts +3 -0
  55. package/graphql/graphql/utils/resolve.js +18 -0
  56. package/graphql/graphql/utils/resolve.js.map +1 -0
  57. package/graphql/graphql.d.ts +3 -0
  58. package/graphql/graphql.js +17 -0
  59. package/graphql/graphql.js.map +1 -0
  60. package/graphql/index.d.ts +3 -0
  61. package/graphql/index.js +16 -0
  62. package/graphql/index.js.map +1 -0
  63. package/graphql/types.d.ts +82 -0
  64. package/graphql/types.js +5 -0
  65. package/graphql/types.js.map +1 -0
  66. package/import/create/blocksHandler.d.ts +3 -0
  67. package/import/create/blocksHandler.js +110 -0
  68. package/import/create/blocksHandler.js.map +1 -0
  69. package/import/create/index.d.ts +23 -0
  70. package/import/create/index.js +30 -0
  71. package/import/create/index.js.map +1 -0
  72. package/import/create/pagesHandler.d.ts +3 -0
  73. package/import/create/pagesHandler.js +110 -0
  74. package/import/create/pagesHandler.js.map +1 -0
  75. package/import/process/blocksHandler.d.ts +3 -0
  76. package/import/process/blocksHandler.js +175 -0
  77. package/import/process/blocksHandler.js.map +1 -0
  78. package/import/process/index.d.ts +19 -0
  79. package/import/process/index.js +27 -0
  80. package/import/process/index.js.map +1 -0
  81. package/import/process/pagesHandler.d.ts +3 -0
  82. package/import/process/pagesHandler.js +180 -0
  83. package/import/process/pagesHandler.js.map +1 -0
  84. package/import/utils.d.ts +49 -0
  85. package/import/utils.js +641 -0
  86. package/import/utils.js.map +1 -0
  87. package/mockSecurity.d.ts +2 -0
  88. package/mockSecurity.js +13 -0
  89. package/mockSecurity.js.map +1 -0
  90. package/package.json +82 -0
  91. package/types.d.ts +190 -0
  92. package/types.js +42 -0
  93. package/types.js.map +1 -0
@@ -0,0 +1,136 @@
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.name)}.zip`);
35
+ }
36
+
37
+ s3DownloadStreams() {
38
+ const exportInfo = this.config.exportInfo;
39
+ const prefix = (0, _uniqid.default)("", `-${(0, _kebabCase.default)(exportInfo.name)}`);
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.dataBuffer),
50
+ filename: `${prefix}\\${exportInfo.name}.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
+
86
+ class ZipOfZip {
87
+ constructor(keys, filename) {
88
+ (0, _defineProperty2.default)(this, "archiveFormat", "zip");
89
+ (0, _defineProperty2.default)(this, "archiveFileName", void 0);
90
+ (0, _defineProperty2.default)(this, "keys", void 0);
91
+ (0, _defineProperty2.default)(this, "filename", void 0);
92
+ this.keys = keys;
93
+ this.filename = filename;
94
+ this.archiveFileName = (0, _uniqid.default)("", `-${filename}`);
95
+ }
96
+
97
+ getFileStreams() {
98
+ return this.keys.map(key => {
99
+ return {
100
+ stream: _s3Stream.s3Stream.readStream(key),
101
+ filename: `${path.basename(key)}`
102
+ };
103
+ });
104
+ }
105
+
106
+ process() {
107
+ const {
108
+ streamPassThrough,
109
+ streamPassThroughUploadPromise
110
+ } = _s3Stream.s3Stream.writeStream(this.archiveFileName); // 1. Read all files from S3 using stream.
111
+
112
+
113
+ const fileStreamDetails = this.getFileStreams(); // 2. Prepare zip from the file stream.
114
+
115
+ const archive = _archiver.default.create(this.archiveFormat); // Handle archive events.
116
+
117
+
118
+ archive.on("error", error => {
119
+ throw new Error(`${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`);
120
+ }); // Append all file streams to archive.
121
+
122
+ fileStreamDetails.forEach(streamDetails => archive.append(streamDetails.stream, {
123
+ name: streamDetails.filename
124
+ })); // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.
125
+
126
+ archive.pipe(streamPassThrough); // Finalize the archive (ie we are done appending files but streams have to finish yet)
127
+ // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
128
+
129
+ archive.finalize(); // 3. Return upload stream promise.
130
+
131
+ return streamPassThroughUploadPromise;
132
+ }
133
+
134
+ }
135
+
136
+ exports.ZipOfZip = ZipOfZip;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Zipper","constructor","config","archiveFileName","uniqueId","archiveFileKey","kebabCase","exportInfo","name","s3DownloadStreams","prefix","files","map","key","stream","s3Stream","readStream","filename","filesDirName","path","basename","Readable","from","dataBuffer","process","streamPassThrough","streamPassThroughUploadPromise","writeStream","s3FilesStreams","archive","vending","create","archiveFormat","on","error","Error","code","message","stack","forEach","streamDetails","append","pipe","finalize","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 { 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}\\\\${path.basename(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(\"\", `-${filename}`);\n }\n\n getFileStreams(): FileStreamDetails[] {\n return this.keys.map(key => {\n return {\n stream: s3Stream.readStream(key),\n filename: `${path.basename(key)}`\n };\n });\n }\n\n process(): Promise<S3.ManagedUpload.SendData> {\n const { streamPassThrough, streamPassThroughUploadPromise } = s3Stream.writeStream(\n this.archiveFileName\n );\n\n // 1. Read all files from S3 using stream.\n const fileStreamDetails = this.getFileStreams();\n\n // 2. Prepare zip from the file stream.\n const archive = vending.create(this.archiveFormat);\n // Handle archive events.\n archive.on(\"error\", (error: ArchiverError) => {\n throw new Error(\n `${error.name} ${error.code} ${error.message} ${error.path} ${error.stack}`\n );\n });\n\n // Append all file streams to archive.\n fileStreamDetails.forEach((streamDetails: FileStreamDetails) =>\n archive.append(streamDetails.stream, { name: streamDetails.filename })\n );\n\n // Pipe archive output to streamPassThrough (Transform Stream) which will be uploaded to S3.\n archive.pipe(streamPassThrough);\n // Finalize the archive (ie we are done appending files but streams have to finish yet)\n // 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand\n archive.finalize();\n\n // 3. Return upload stream promise.\n return streamPassThroughUploadPromise;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAPA;AA0Be,MAAMA,MAAN,CAAa;EAMxBC,WAAW,CAACC,MAAD,EAAuB;IAAA,qDALD,KAKC;IAAA,oDAJF,QAIE;IAAA;IAAA;IAC9B,KAAKA,MAAL,GAAcA,MAAd;IACA,KAAKC,eAAL,GAAuB,IAAAC,eAAA,EAClB,GAAE,KAAKF,MAAL,CAAYG,cAAe,GADX,EAElB,IAAG,IAAAC,kBAAA,EAAU,KAAKJ,MAAL,CAAYK,UAAZ,CAAuBC,IAAjC,CAAuC,MAFxB,C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IAAIC,KAAJ,CACD,GAAED,KAAK,CAAC1B,IAAK,IAAG0B,KAAK,CAACE,IAAK,IAAGF,KAAK,CAACG,OAAQ,IAAGH,KAAK,CAACf,IAAK,IAAGe,KAAK,CAACI,KAAM,EADxE,CAAN;IAGH,CAJD,EAX0C,CAiB1C;;IACAS,iBAAiB,CAACR,OAAlB,CAA2BC,aAAD,IACtBX,OAAO,CAACY,MAAR,CAAeD,aAAa,CAAC1B,MAA7B,EAAqC;MAAEN,IAAI,EAAEgC,aAAa,CAACvB;IAAtB,CAArC,CADJ,EAlB0C,CAsB1C;;IACAY,OAAO,CAACa,IAAR,CAAajB,iBAAb,EAvB0C,CAwB1C;IACA;;IACAI,OAAO,CAACc,QAAR,GA1B0C,CA4B1C;;IACA,OAAOjB,8BAAP;EACH;;AAnDiB"}
@@ -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;
@@ -0,0 +1,155 @@
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.default = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ var _handlerGraphql = require("@webiny/handler-graphql");
13
+
14
+ var _api = require("@webiny/api");
15
+
16
+ var _checkBasePermissions = _interopRequireDefault(require("@webiny/api-page-builder/graphql/crud/utils/checkBasePermissions"));
17
+
18
+ var _types = require("../../types");
19
+
20
+ var _client = require("../../client");
21
+
22
+ var _utils = require("../../import/utils");
23
+
24
+ var _utils2 = require("../../export/utils");
25
+
26
+ var _utils3 = require("@webiny/utils");
27
+
28
+ const PERMISSION_NAME = "pb.block";
29
+ const EXPORT_BLOCKS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER;
30
+ const IMPORT_BLOCKS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER;
31
+
32
+ var _default = new _api.ContextPlugin(context => {
33
+ const importExportCrud = {
34
+ async importBlocks({
35
+ category: categorySlug,
36
+ zipFileUrl
37
+ }) {
38
+ await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
39
+ rwd: "w"
40
+ }); // Bail out early if category not found
41
+
42
+ const category = await context.pageBuilder.getBlockCategory(categorySlug);
43
+
44
+ if (!category) {
45
+ throw new _handlerGraphql.NotFoundError(`Category with slug "${categorySlug}" not found.`);
46
+ } // Create a task for import block
47
+
48
+
49
+ const task = await context.pageBuilder.importExportTask.createTask({
50
+ status: _types.ImportExportTaskStatus.PENDING,
51
+ input: {
52
+ category: categorySlug,
53
+ zipFileUrl
54
+ }
55
+ });
56
+ /**
57
+ * Import Blocks
58
+ * ImportBlocks
59
+ * importBlocks
60
+ */
61
+
62
+ await (0, _client.invokeHandlerClient)({
63
+ context,
64
+ name: IMPORT_BLOCKS_CREATE_HANDLER,
65
+ payload: {
66
+ category: categorySlug,
67
+ zipFileUrl,
68
+ task,
69
+ type: "block",
70
+ identity: context.security.getIdentity()
71
+ },
72
+ description: "Import Blocks - create"
73
+ });
74
+ return {
75
+ task
76
+ };
77
+ },
78
+
79
+ async exportBlocks({
80
+ ids: initialBlockIds,
81
+ where
82
+ }) {
83
+ await (0, _checkBasePermissions.default)(context, PERMISSION_NAME, {
84
+ rwd: "w"
85
+ });
86
+ let blockIds = initialBlockIds || []; // If no ids are provided then it means we want to export all blocks
87
+
88
+ if (!initialBlockIds || Array.isArray(initialBlockIds) && initialBlockIds.length === 0) {
89
+ blockIds = [];
90
+ const blocks = await context.pageBuilder.listPageBlocks({
91
+ where
92
+ }); // Save block ids
93
+
94
+ blocks.forEach(block => blockIds.push(block.id));
95
+ }
96
+
97
+ if (blockIds.length === 0) {
98
+ throw new _error.default("Cannot export blocks - no blocks found for provided inputs.", "EMPTY_EXPORT_NO_BLOCKS_FOUND");
99
+ } // Create the main task for blocks export.
100
+
101
+
102
+ const task = await context.pageBuilder.importExportTask.createTask({
103
+ status: _types.ImportExportTaskStatus.PENDING
104
+ });
105
+ const exportBlocksDataKey = `${_utils2.EXPORT_BLOCKS_FOLDER_KEY}/${task.id}`; // For each block create a sub task and invoke the process handler.
106
+
107
+ for (let i = 0; i < blockIds.length; i++) {
108
+ const blockId = blockIds[i]; // Create sub task.
109
+
110
+ await context.pageBuilder.importExportTask.createSubTask(task.id, (0, _utils3.zeroPad)(i + 1, 5), {
111
+ status: _types.ImportExportTaskStatus.PENDING,
112
+ input: {
113
+ blockId,
114
+ exportBlocksDataKey
115
+ }
116
+ });
117
+ } // Update main task status.
118
+
119
+
120
+ await context.pageBuilder.importExportTask.updateTask(task.id, {
121
+ status: _types.ImportExportTaskStatus.PROCESSING,
122
+ stats: (0, _utils.initialStats)(blockIds.length),
123
+ input: {
124
+ exportBlocksDataKey
125
+ }
126
+ });
127
+ /**
128
+ * Export Blocks
129
+ * ExportBlocks
130
+ * exportBlocks
131
+ */
132
+ // Invoke handler.
133
+
134
+ await (0, _client.invokeHandlerClient)({
135
+ context,
136
+ name: EXPORT_BLOCKS_PROCESS_HANDLER,
137
+ payload: {
138
+ taskId: task.id,
139
+ subTaskIndex: 1,
140
+ type: "block",
141
+ identity: context.security.getIdentity()
142
+ },
143
+ description: "Export blocks - process"
144
+ });
145
+ return {
146
+ task
147
+ };
148
+ }
149
+
150
+ }; // Modify context
151
+
152
+ context.pageBuilder.blocks = importExportCrud;
153
+ });
154
+
155
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["PERMISSION_NAME","EXPORT_BLOCKS_PROCESS_HANDLER","process","env","EXPORT_PROCESS_HANDLER","IMPORT_BLOCKS_CREATE_HANDLER","IMPORT_CREATE_HANDLER","ContextPlugin","context","importExportCrud","importBlocks","category","categorySlug","zipFileUrl","checkBasePermissions","rwd","pageBuilder","getBlockCategory","NotFoundError","task","importExportTask","createTask","status","ImportExportTaskStatus","PENDING","input","invokeHandlerClient","name","payload","type","identity","security","getIdentity","description","exportBlocks","ids","initialBlockIds","where","blockIds","Array","isArray","length","blocks","listPageBlocks","forEach","block","push","id","WebinyError","exportBlocksDataKey","EXPORT_BLOCKS_FOLDER_KEY","i","blockId","createSubTask","zeroPad","updateTask","PROCESSING","stats","initialStats","taskId","subTaskIndex"],"sources":["blocks.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport checkBasePermissions from \"@webiny/api-page-builder/graphql/crud/utils/checkBasePermissions\";\nimport { ImportExportTaskStatus, BlocksImportExportCrud, PbImportExportContext } from \"~/types\";\nimport { invokeHandlerClient } from \"~/client\";\nimport { Payload as CreateHandlerPayload } from \"~/import/create\";\nimport { initialStats } from \"~/import/utils\";\nimport { Payload as ExportBlocksProcessHandlerPayload } from \"~/export/process\";\nimport { EXPORT_BLOCKS_FOLDER_KEY } from \"~/export/utils\";\nimport { zeroPad } from \"@webiny/utils\";\n\nconst PERMISSION_NAME = \"pb.block\";\nconst EXPORT_BLOCKS_PROCESS_HANDLER = process.env.EXPORT_PROCESS_HANDLER as string;\nconst IMPORT_BLOCKS_CREATE_HANDLER = process.env.IMPORT_CREATE_HANDLER as string;\n\nexport default new ContextPlugin<PbImportExportContext>(context => {\n const importExportCrud: BlocksImportExportCrud = {\n async importBlocks({ category: categorySlug, zipFileUrl }) {\n await checkBasePermissions(context, PERMISSION_NAME, {\n rwd: \"w\"\n });\n\n // Bail out early if category not found\n const category = await context.pageBuilder.getBlockCategory(categorySlug);\n if (!category) {\n throw new NotFoundError(`Category with slug \"${categorySlug}\" not found.`);\n }\n\n // Create a task for import block\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING,\n input: {\n category: categorySlug,\n zipFileUrl\n }\n });\n /**\n * Import Blocks\n * ImportBlocks\n * importBlocks\n */\n await invokeHandlerClient<CreateHandlerPayload>({\n context,\n name: IMPORT_BLOCKS_CREATE_HANDLER,\n payload: {\n category: categorySlug,\n zipFileUrl,\n task,\n type: \"block\",\n identity: context.security.getIdentity()\n },\n description: \"Import Blocks - create\"\n });\n\n return {\n task\n };\n },\n\n async exportBlocks({ ids: initialBlockIds, where }) {\n await checkBasePermissions(context, PERMISSION_NAME, {\n rwd: \"w\"\n });\n let blockIds: string[] = initialBlockIds || [];\n // If no ids are provided then it means we want to export all blocks\n if (\n !initialBlockIds ||\n (Array.isArray(initialBlockIds) && initialBlockIds.length === 0)\n ) {\n blockIds = [];\n const blocks = await context.pageBuilder.listPageBlocks({ where });\n // Save block ids\n blocks.forEach(block => blockIds.push(block.id));\n }\n\n if (blockIds.length === 0) {\n throw new WebinyError(\n \"Cannot export blocks - no blocks found for provided inputs.\",\n \"EMPTY_EXPORT_NO_BLOCKS_FOUND\"\n );\n }\n\n // Create the main task for blocks export.\n const task = await context.pageBuilder.importExportTask.createTask({\n status: ImportExportTaskStatus.PENDING\n });\n const exportBlocksDataKey = `${EXPORT_BLOCKS_FOLDER_KEY}/${task.id}`;\n // For each block create a sub task and invoke the process handler.\n for (let i = 0; i < blockIds.length; i++) {\n const blockId = blockIds[i];\n // Create sub task.\n await context.pageBuilder.importExportTask.createSubTask(\n task.id,\n zeroPad(i + 1, 5),\n {\n status: ImportExportTaskStatus.PENDING,\n input: {\n blockId,\n exportBlocksDataKey\n }\n }\n );\n }\n // Update main task status.\n await context.pageBuilder.importExportTask.updateTask(task.id, {\n status: ImportExportTaskStatus.PROCESSING,\n stats: initialStats(blockIds.length),\n input: {\n exportBlocksDataKey\n }\n });\n\n /**\n * Export Blocks\n * ExportBlocks\n * exportBlocks\n */\n // Invoke handler.\n await invokeHandlerClient<ExportBlocksProcessHandlerPayload>({\n context,\n name: EXPORT_BLOCKS_PROCESS_HANDLER,\n payload: {\n taskId: task.id,\n subTaskIndex: 1,\n type: \"block\",\n identity: context.security.getIdentity()\n },\n description: \"Export blocks - process\"\n });\n\n return { task };\n }\n };\n // Modify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ADsC,CAEtC;;QACA,MAAM3C,OAAO,CAACQ,WAAR,CAAoBI,gBAApB,CAAqCiC,aAArC,CACFlC,IAAI,CAAC4B,EADH,EAEF,IAAAO,eAAA,EAAQH,CAAC,GAAG,CAAZ,EAAe,CAAf,CAFE,EAGF;UACI7B,MAAM,EAAEC,6BAAA,CAAuBC,OADnC;UAEIC,KAAK,EAAE;YACH2B,OADG;YAEHH;UAFG;QAFX,CAHE,CAAN;MAWH,CA3C+C,CA4ChD;;;MACA,MAAMzC,OAAO,CAACQ,WAAR,CAAoBI,gBAApB,CAAqCmC,UAArC,CAAgDpC,IAAI,CAAC4B,EAArD,EAAyD;QAC3DzB,MAAM,EAAEC,6BAAA,CAAuBiC,UAD4B;QAE3DC,KAAK,EAAE,IAAAC,mBAAA,EAAapB,QAAQ,CAACG,MAAtB,CAFoD;QAG3DhB,KAAK,EAAE;UACHwB;QADG;MAHoD,CAAzD,CAAN;MAQA;AACZ;AACA;AACA;AACA;MACY;;MACA,MAAM,IAAAvB,2BAAA,EAAuD;QACzDlB,OADyD;QAEzDmB,IAAI,EAAE1B,6BAFmD;QAGzD2B,OAAO,EAAE;UACL+B,MAAM,EAAExC,IAAI,CAAC4B,EADR;UAELa,YAAY,EAAE,CAFT;UAGL/B,IAAI,EAAE,OAHD;UAILC,QAAQ,EAAEtB,OAAO,CAACuB,QAAR,CAAiBC,WAAjB;QAJL,CAHgD;QASzDC,WAAW,EAAE;MAT4C,CAAvD,CAAN;MAYA,OAAO;QAAEd;MAAF,CAAP;IACH;;EAnH4C,CAAjD,CAD+D,CAsH/D;;EACAX,OAAO,CAACQ,WAAR,CAAoB0B,MAApB,GAA6BjC,gBAA7B;AACH,CAxHc,C"}
@@ -0,0 +1,5 @@
1
+ import { ContextPlugin } from "@webiny/api";
2
+ import { ImportExportPluginsParams } from "../../types";
3
+ import { PbImportExportContext } from "../types";
4
+ declare const _default: ({ storageOperations }: ImportExportPluginsParams) => ContextPlugin<PbImportExportContext>;
5
+ export default _default;