@kontent-ai/migration-toolkit 2.9.1 → 3.0.0-1
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/README.md +19 -17
- package/dist/core/config.js +3 -3
- package/dist/core/config.js.map +1 -1
- package/dist/core/helpers/workflow-helper.d.ts +1 -1
- package/dist/core/helpers/workflow-helper.js +28 -26
- package/dist/core/helpers/workflow-helper.js.map +1 -1
- package/dist/core/logs/loggers.d.ts +1 -1
- package/dist/core/logs/loggers.js +15 -15
- package/dist/core/logs/loggers.js.map +1 -1
- package/dist/core/models/core.models.d.ts +29 -22
- package/dist/core/models/error.models.d.ts +26 -0
- package/dist/core/models/error.models.js +104 -0
- package/dist/core/models/error.models.js.map +1 -0
- package/dist/core/models/log.models.d.ts +2 -2
- package/dist/core/models/migration.models.d.ts +17 -19
- package/dist/core/models/migration.schema.d.ts +9 -9
- package/dist/core/models/migration.schema.js +28 -28
- package/dist/core/models/migration.schema.js.map +1 -1
- package/dist/core/utils/array.utils.d.ts +1 -1
- package/dist/core/utils/array.utils.js +4 -3
- package/dist/core/utils/array.utils.js.map +1 -1
- package/dist/core/utils/binary-data.utils.d.ts +1 -1
- package/dist/core/utils/binary-data.utils.js +6 -6
- package/dist/core/utils/binary-data.utils.js.map +1 -1
- package/dist/core/utils/confirm.utils.d.ts +3 -1
- package/dist/core/utils/confirm.utils.js +92 -24
- package/dist/core/utils/confirm.utils.js.map +1 -1
- package/dist/core/utils/error.utils.d.ts +1 -1
- package/dist/core/utils/error.utils.js +16 -14
- package/dist/core/utils/error.utils.js.map +1 -1
- package/dist/core/utils/external-id.utils.js +1 -1
- package/dist/core/utils/external-id.utils.js.map +1 -1
- package/dist/core/utils/global.utils.d.ts +3 -3
- package/dist/core/utils/global.utils.js +20 -18
- package/dist/core/utils/global.utils.js.map +1 -1
- package/dist/core/utils/http.utils.d.ts +2 -2
- package/dist/core/utils/http.utils.js +4 -4
- package/dist/core/utils/http.utils.js.map +1 -1
- package/dist/core/utils/management-client-utils.d.ts +4 -4
- package/dist/core/utils/management-client-utils.js +37 -34
- package/dist/core/utils/management-client-utils.js.map +1 -1
- package/dist/core/utils/processing-utils.d.ts +4 -4
- package/dist/core/utils/processing-utils.js +13 -13
- package/dist/core/utils/processing-utils.js.map +1 -1
- package/dist/core/utils/run.utils.d.ts +2 -2
- package/dist/core/utils/run.utils.js +7 -7
- package/dist/core/utils/run.utils.js.map +1 -1
- package/dist/core/utils/try.utils.d.ts +14 -0
- package/dist/core/utils/try.utils.js +18 -0
- package/dist/core/utils/try.utils.js.map +1 -0
- package/dist/export/context/export-context-fetcher.d.ts +1 -1
- package/dist/export/context/export-context-fetcher.js +92 -62
- package/dist/export/context/export-context-fetcher.js.map +1 -1
- package/dist/export/export-manager.d.ts +2 -2
- package/dist/export/export-manager.js +73 -59
- package/dist/export/export-manager.js.map +1 -1
- package/dist/export/export.models.d.ts +21 -2
- package/dist/export/utils/export.utils.d.ts +1 -1
- package/dist/export/utils/export.utils.js +3 -2
- package/dist/export/utils/export.utils.js.map +1 -1
- package/dist/file/file-manager.d.ts +2 -2
- package/dist/file/file-manager.js +7 -7
- package/dist/file/file-manager.js.map +1 -1
- package/dist/import/comparers/asset-comparer.d.ts +2 -2
- package/dist/import/comparers/asset-comparer.js +12 -11
- package/dist/import/comparers/asset-comparer.js.map +1 -1
- package/dist/import/context/import-context-fetcher.d.ts +1 -1
- package/dist/import/context/import-context-fetcher.js +77 -73
- package/dist/import/context/import-context-fetcher.js.map +1 -1
- package/dist/import/import-manager.d.ts +1 -1
- package/dist/import/import-manager.js +59 -56
- package/dist/import/import-manager.js.map +1 -1
- package/dist/import/import.models.d.ts +6 -2
- package/dist/import/importers/assets-importer.d.ts +3 -3
- package/dist/import/importers/assets-importer.js +46 -43
- package/dist/import/importers/assets-importer.js.map +1 -1
- package/dist/import/importers/content-items-importer.d.ts +3 -3
- package/dist/import/importers/content-items-importer.js +28 -25
- package/dist/import/importers/content-items-importer.js.map +1 -1
- package/dist/import/importers/language-variant-importer.d.ts +3 -3
- package/dist/import/importers/language-variant-importer.js +45 -45
- package/dist/import/importers/language-variant-importer.js.map +1 -1
- package/dist/import/importers/workflow-importer.d.ts +3 -2
- package/dist/import/importers/workflow-importer.js +58 -54
- package/dist/import/importers/workflow-importer.js.map +1 -1
- package/dist/import/utils/import.utils.d.ts +1 -1
- package/dist/import/utils/import.utils.js +3 -2
- package/dist/import/utils/import.utils.js.map +1 -1
- package/dist/index.d.ts +11 -7
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/dist/metadata.js +3 -3
- package/dist/metadata.js.map +1 -1
- package/dist/node/cli/actions/export-action.d.ts +1 -1
- package/dist/node/cli/actions/export-action.js +29 -23
- package/dist/node/cli/actions/export-action.js.map +1 -1
- package/dist/node/cli/actions/import-action.d.ts +1 -1
- package/dist/node/cli/actions/import-action.js +15 -12
- package/dist/node/cli/actions/import-action.js.map +1 -1
- package/dist/node/cli/actions/migrate-action.d.ts +1 -1
- package/dist/node/cli/actions/migrate-action.js +26 -22
- package/dist/node/cli/actions/migrate-action.js.map +1 -1
- package/dist/node/cli/app.js +13 -12
- package/dist/node/cli/app.js.map +1 -1
- package/dist/node/cli/args/args-fetcher.d.ts +1 -1
- package/dist/node/cli/args/args-fetcher.js +14 -13
- package/dist/node/cli/args/args-fetcher.js.map +1 -1
- package/dist/node/cli/args/args-setter.d.ts +1 -1
- package/dist/node/cli/args/args-setter.js +8 -6
- package/dist/node/cli/args/args-setter.js.map +1 -1
- package/dist/node/cli/cli.models.d.ts +2 -2
- package/dist/node/cli/commands.js +68 -56
- package/dist/node/cli/commands.js.map +1 -1
- package/dist/toolkit/elements-builder.d.ts +1 -1
- package/dist/toolkit/elements-builder.js +12 -12
- package/dist/toolkit/elements-builder.js.map +1 -1
- package/dist/toolkit/export.d.ts +2 -2
- package/dist/toolkit/export.js +8 -8
- package/dist/toolkit/export.js.map +1 -1
- package/dist/toolkit/file.d.ts +2 -1
- package/dist/toolkit/file.js +18 -16
- package/dist/toolkit/file.js.map +1 -1
- package/dist/toolkit/import.d.ts +1 -1
- package/dist/toolkit/import.js +12 -12
- package/dist/toolkit/import.js.map +1 -1
- package/dist/toolkit/migrate.d.ts +13 -4
- package/dist/toolkit/migrate.js +15 -13
- package/dist/toolkit/migrate.js.map +1 -1
- package/dist/translation/extraction/items-extraction.processor.d.ts +5 -4
- package/dist/translation/extraction/items-extraction.processor.js +73 -35
- package/dist/translation/extraction/items-extraction.processor.js.map +1 -1
- package/dist/translation/helpers/export-placeholder.utils.d.ts +11 -0
- package/dist/translation/helpers/export-placeholder.utils.js +11 -0
- package/dist/translation/helpers/export-placeholder.utils.js.map +1 -0
- package/dist/translation/helpers/rich-text.processor.d.ts +6 -6
- package/dist/translation/helpers/rich-text.processor.js +38 -38
- package/dist/translation/helpers/rich-text.processor.js.map +1 -1
- package/dist/translation/transforms/export-transforms.d.ts +2 -2
- package/dist/translation/transforms/export-transforms.js +93 -67
- package/dist/translation/transforms/export-transforms.js.map +1 -1
- package/dist/translation/transforms/import-transforms.d.ts +2 -2
- package/dist/translation/transforms/import-transforms.js +38 -40
- package/dist/translation/transforms/import-transforms.js.map +1 -1
- package/dist/zip/zip-manager.d.ts +4 -3
- package/dist/zip/zip-manager.js +9 -9
- package/dist/zip/zip-manager.js.map +1 -1
- package/dist/zip/zip-packager.d.ts +2 -2
- package/dist/zip/zip-packager.js +19 -17
- package/dist/zip/zip-packager.js.map +1 -1
- package/dist/zip/zip-transformer.d.ts +3 -2
- package/dist/zip/zip-transformer.js +16 -15
- package/dist/zip/zip-transformer.js.map +1 -1
- package/dist/zip/zip.models.d.ts +2 -2
- package/lib/core/config.ts +6 -6
- package/lib/core/helpers/workflow-helper.ts +190 -185
- package/lib/core/logs/loggers.ts +52 -52
- package/lib/core/models/core.models.ts +130 -119
- package/lib/core/models/error.models.ts +148 -0
- package/lib/core/models/log.models.ts +20 -20
- package/lib/core/models/migration.models.ts +54 -57
- package/lib/core/models/migration.schema.ts +108 -108
- package/lib/core/utils/array.utils.ts +43 -42
- package/lib/core/utils/binary-data.utils.ts +16 -16
- package/lib/core/utils/confirm.utils.ts +184 -106
- package/lib/core/utils/error.utils.ts +69 -72
- package/lib/core/utils/external-id.utils.ts +4 -4
- package/lib/core/utils/global.utils.ts +81 -75
- package/lib/core/utils/http.utils.ts +23 -23
- package/lib/core/utils/management-client-utils.ts +189 -186
- package/lib/core/utils/processing-utils.ts +82 -82
- package/lib/core/utils/run.utils.ts +50 -50
- package/lib/core/utils/try.utils.ts +30 -0
- package/lib/export/context/export-context-fetcher.ts +472 -447
- package/lib/export/export-manager.ts +250 -232
- package/lib/export/export.models.ts +71 -56
- package/lib/export/utils/export.utils.ts +9 -7
- package/lib/file/file-manager.ts +28 -28
- package/lib/import/comparers/asset-comparer.ts +107 -106
- package/lib/import/context/import-context-fetcher.ts +462 -462
- package/lib/import/import-manager.ts +243 -240
- package/lib/import/import.models.ts +69 -67
- package/lib/import/importers/assets-importer.ts +240 -236
- package/lib/import/importers/content-items-importer.ts +126 -122
- package/lib/import/importers/language-variant-importer.ts +324 -328
- package/lib/import/importers/workflow-importer.ts +372 -367
- package/lib/import/utils/import.utils.ts +9 -7
- package/lib/index.ts +12 -8
- package/lib/metadata.ts +3 -4
- package/lib/node/cli/actions/export-action.ts +44 -38
- package/lib/node/cli/actions/import-action.ts +32 -29
- package/lib/node/cli/actions/migrate-action.ts +50 -46
- package/lib/node/cli/app.ts +21 -21
- package/lib/node/cli/args/args-fetcher.ts +55 -54
- package/lib/node/cli/args/args-setter.ts +34 -32
- package/lib/node/cli/cli.models.ts +17 -17
- package/lib/node/cli/commands.ts +165 -153
- package/lib/toolkit/elements-builder.ts +69 -69
- package/lib/toolkit/export.ts +21 -21
- package/lib/toolkit/file.ts +59 -53
- package/lib/toolkit/import.ts +32 -32
- package/lib/toolkit/migrate.ts +60 -49
- package/lib/translation/extraction/items-extraction.processor.ts +203 -173
- package/lib/translation/helpers/export-placeholder.utils.ts +10 -0
- package/lib/translation/helpers/rich-text.processor.ts +311 -311
- package/lib/translation/transforms/export-transforms.ts +313 -279
- package/lib/translation/transforms/import-transforms.ts +188 -191
- package/lib/zip/zip-manager.ts +28 -27
- package/lib/zip/zip-packager.ts +75 -73
- package/lib/zip/zip-transformer.ts +112 -107
- package/lib/zip/zip.models.ts +7 -7
- package/package.json +91 -84
- package/dist/core/index.d.ts +0 -16
- package/dist/core/index.js +0 -17
- package/dist/core/index.js.map +0 -1
- package/dist/export/index.d.ts +0 -2
- package/dist/export/index.js +0 -3
- package/dist/export/index.js.map +0 -1
- package/dist/file/index.d.ts +0 -1
- package/dist/file/index.js +0 -2
- package/dist/file/index.js.map +0 -1
- package/dist/import/index.d.ts +0 -2
- package/dist/import/index.js +0 -3
- package/dist/import/index.js.map +0 -1
- package/dist/toolkit/index.d.ts +0 -5
- package/dist/toolkit/index.js +0 -6
- package/dist/toolkit/index.js.map +0 -1
- package/dist/translation/index.d.ts +0 -4
- package/dist/translation/index.js +0 -5
- package/dist/translation/index.js.map +0 -1
- package/dist/zip/index.d.ts +0 -4
- package/dist/zip/index.js +0 -5
- package/dist/zip/index.js.map +0 -1
- package/lib/core/index.ts +0 -18
- package/lib/export/index.ts +0 -2
- package/lib/file/index.ts +0 -1
- package/lib/import/index.ts +0 -2
- package/lib/toolkit/index.ts +0 -5
- package/lib/translation/index.ts +0 -4
- package/lib/zip/index.ts +0 -4
|
@@ -1,133 +1,211 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import type { EnvironmentModels } from "@kontent-ai/management-sdk";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { match, P } from "ts-pattern";
|
|
4
|
+
import { MigrationToolkitError } from "../models/error.models.js";
|
|
5
|
+
import type { Logger } from "../models/log.models.js";
|
|
6
|
+
import { getMigrationManagementClient, managementClientUtils } from "./management-client-utils.js";
|
|
4
7
|
|
|
5
8
|
export async function confirmExportAsync(data: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
readonly force: boolean;
|
|
10
|
+
readonly environmentId: string;
|
|
11
|
+
readonly apiKey: string;
|
|
12
|
+
readonly logger: Logger;
|
|
13
|
+
readonly skipMissingReferences: boolean;
|
|
14
|
+
readonly dataToExport: {
|
|
15
|
+
readonly itemsCount: number;
|
|
16
|
+
};
|
|
13
17
|
}): Promise<void> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const environment = await managementClientUtils(
|
|
19
|
+
getMigrationManagementClient({
|
|
20
|
+
environmentId: data.environmentId,
|
|
21
|
+
apiKey: data.apiKey,
|
|
22
|
+
}),
|
|
23
|
+
data.logger,
|
|
24
|
+
).getEnvironmentAsync();
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
const text = getConfirmText({
|
|
27
|
+
action: "export",
|
|
28
|
+
itemsCount: data.dataToExport.itemsCount,
|
|
29
|
+
sourceEnvironment: environment,
|
|
30
|
+
skipMissingReferences: data.skipMissingReferences,
|
|
31
|
+
});
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
await confirmAsync({
|
|
34
|
+
force: data.force,
|
|
35
|
+
logger: data.logger,
|
|
36
|
+
action: "Export",
|
|
37
|
+
message: text,
|
|
38
|
+
});
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
export async function confirmMigrateAsync(data: {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
readonly force: boolean;
|
|
43
|
+
readonly sourceEnvironment: {
|
|
44
|
+
readonly environmentId: string;
|
|
45
|
+
readonly apiKey: string;
|
|
46
|
+
};
|
|
47
|
+
readonly targetEnvironment: {
|
|
48
|
+
readonly environmentId: string;
|
|
49
|
+
readonly apiKey: string;
|
|
50
|
+
};
|
|
51
|
+
readonly skipMissingReferences: boolean;
|
|
52
|
+
readonly logger: Logger;
|
|
53
|
+
readonly dataToMigrate: {
|
|
54
|
+
readonly itemsCount: number;
|
|
55
|
+
};
|
|
48
56
|
}): Promise<void> {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
const sourceEnvironment = await managementClientUtils(
|
|
58
|
+
getMigrationManagementClient({
|
|
59
|
+
environmentId: data.sourceEnvironment.environmentId,
|
|
60
|
+
apiKey: data.sourceEnvironment.apiKey,
|
|
61
|
+
}),
|
|
62
|
+
data.logger,
|
|
63
|
+
).getEnvironmentAsync();
|
|
64
|
+
const targetEnvironment = await managementClientUtils(
|
|
65
|
+
getMigrationManagementClient({
|
|
66
|
+
environmentId: data.targetEnvironment.environmentId,
|
|
67
|
+
apiKey: data.targetEnvironment.apiKey,
|
|
68
|
+
}),
|
|
69
|
+
data.logger,
|
|
70
|
+
).getEnvironmentAsync();
|
|
63
71
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
const text = getConfirmText({
|
|
73
|
+
action: "migrate",
|
|
74
|
+
itemsCount: data.dataToMigrate.itemsCount,
|
|
75
|
+
sourceEnvironment,
|
|
76
|
+
targetEnvironment,
|
|
77
|
+
skipMissingReferences: data.skipMissingReferences,
|
|
78
|
+
});
|
|
69
79
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
await confirmAsync({
|
|
81
|
+
force: data.force,
|
|
82
|
+
logger: data.logger,
|
|
83
|
+
action: "Migrate",
|
|
84
|
+
message: text,
|
|
85
|
+
});
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
export async function confirmImportAsync(data: {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
readonly force: boolean;
|
|
90
|
+
readonly environmentId: string;
|
|
91
|
+
readonly apiKey: string;
|
|
92
|
+
readonly logger: Logger;
|
|
83
93
|
}): Promise<void> {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
const environment = await managementClientUtils(
|
|
95
|
+
getMigrationManagementClient({
|
|
96
|
+
environmentId: data.environmentId,
|
|
97
|
+
apiKey: data.apiKey,
|
|
98
|
+
}),
|
|
99
|
+
data.logger,
|
|
100
|
+
).getEnvironmentAsync();
|
|
91
101
|
|
|
92
|
-
|
|
102
|
+
const text = getConfirmText({
|
|
103
|
+
action: "import",
|
|
104
|
+
targetEnvironment: environment,
|
|
105
|
+
itemsCount: undefined,
|
|
106
|
+
});
|
|
93
107
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
108
|
+
await confirmAsync({
|
|
109
|
+
force: data.force,
|
|
110
|
+
logger: data.logger,
|
|
111
|
+
action: "Import",
|
|
112
|
+
message: text,
|
|
113
|
+
});
|
|
100
114
|
}
|
|
101
115
|
|
|
102
116
|
async function confirmAsync(data: {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
117
|
+
readonly action: string;
|
|
118
|
+
readonly message: string;
|
|
119
|
+
readonly force: boolean;
|
|
120
|
+
readonly logger: Logger;
|
|
107
121
|
}): Promise<void> {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
122
|
+
// Prompts is imported dynamically because it's a node.js only module and would not work if user
|
|
123
|
+
// tried using this library in a browser
|
|
124
|
+
const prompts = await import("prompts");
|
|
111
125
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
if (data.force) {
|
|
127
|
+
data.logger.log({
|
|
128
|
+
type: "info",
|
|
129
|
+
message: `Skipping confirmation`,
|
|
130
|
+
});
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
119
133
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
134
|
+
const confirmed = await prompts.default({
|
|
135
|
+
type: "confirm",
|
|
136
|
+
name: "confirm",
|
|
137
|
+
message: `${chalk.cyan(data.action)}: ${data.message}`,
|
|
138
|
+
});
|
|
125
139
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
140
|
+
if (!confirmed.confirm) {
|
|
141
|
+
throw new MigrationToolkitError("confirmationRefused", `Confirmation refused.`);
|
|
142
|
+
}
|
|
129
143
|
}
|
|
130
144
|
|
|
131
|
-
function
|
|
132
|
-
|
|
145
|
+
function getConfirmText({
|
|
146
|
+
action,
|
|
147
|
+
itemsCount,
|
|
148
|
+
sourceEnvironment,
|
|
149
|
+
targetEnvironment,
|
|
150
|
+
skipMissingReferences,
|
|
151
|
+
}: {
|
|
152
|
+
readonly action: "export" | "import" | "migrate";
|
|
153
|
+
readonly skipMissingReferences?: boolean;
|
|
154
|
+
readonly itemsCount?: number;
|
|
155
|
+
readonly sourceEnvironment?: EnvironmentModels.EnvironmentInformationModel;
|
|
156
|
+
readonly targetEnvironment?: EnvironmentModels.EnvironmentInformationModel;
|
|
157
|
+
}): string {
|
|
158
|
+
const lines: readonly string[] = [
|
|
159
|
+
`\n${"=".repeat(70)}`,
|
|
160
|
+
...match(action)
|
|
161
|
+
.returnType<readonly string[]>()
|
|
162
|
+
.with("export", () => [
|
|
163
|
+
`${chalk.cyan("📤 Source environment:")}`,
|
|
164
|
+
` ${chalk.gray("├─")} Name: ${chalk.yellow.bold(sourceEnvironment?.name)}`,
|
|
165
|
+
` ${chalk.gray("├─")} Environment: ${chalk.green.bold(sourceEnvironment?.environment)}`,
|
|
166
|
+
` ${chalk.gray("└─")} ID: ${chalk.dim(sourceEnvironment?.id)}`,
|
|
167
|
+
])
|
|
168
|
+
.with("import", () => [
|
|
169
|
+
`${chalk.cyan("📥 Target environment:")}`,
|
|
170
|
+
` ${chalk.gray("├─")} Name: ${chalk.yellow.bold(targetEnvironment?.name)}`,
|
|
171
|
+
` ${chalk.gray("├─")} Environment: ${chalk.green.bold(targetEnvironment?.environment)}`,
|
|
172
|
+
` ${chalk.gray("└─")} ID: ${chalk.dim(targetEnvironment?.id)}`,
|
|
173
|
+
])
|
|
174
|
+
.with("migrate", () => [
|
|
175
|
+
`${chalk.cyan("📤 Source environment:")}`,
|
|
176
|
+
` ${chalk.gray("├─")} Name: ${chalk.yellow.bold(sourceEnvironment?.name)}`,
|
|
177
|
+
` ${chalk.gray("├─")} Environment: ${chalk.green.bold(sourceEnvironment?.environment)}`,
|
|
178
|
+
` ${chalk.gray("└─")} ID: ${chalk.dim(sourceEnvironment?.id)}`,
|
|
179
|
+
`${chalk.cyan("📥 Target environment:")}`,
|
|
180
|
+
` ${chalk.gray("├─")} Name: ${chalk.yellow.bold(targetEnvironment?.name)}`,
|
|
181
|
+
` ${chalk.gray("├─")} Environment: ${chalk.green.bold(targetEnvironment?.environment)}`,
|
|
182
|
+
` ${chalk.gray("└─")} ID: ${chalk.dim(targetEnvironment?.id)}`,
|
|
183
|
+
])
|
|
184
|
+
.exhaustive(),
|
|
185
|
+
"\n",
|
|
186
|
+
...match(itemsCount)
|
|
187
|
+
.returnType<readonly string[]>()
|
|
188
|
+
.with(P.nonNullable, (itemsCount) => [
|
|
189
|
+
`${chalk.cyan("📦 Items to process:")}`,
|
|
190
|
+
` ${chalk.gray("├─")} Count: ${chalk.green.bold(itemsCount)}`,
|
|
191
|
+
"",
|
|
192
|
+
])
|
|
193
|
+
.otherwise(() => []),
|
|
194
|
+
...match(action)
|
|
195
|
+
.returnType<readonly string[]>()
|
|
196
|
+
.with(P.union("export", "migrate"), () => [
|
|
197
|
+
`${chalk.cyan("⚙️ Configuration:")}`,
|
|
198
|
+
` ${chalk.gray("└─")} Skip missing references: ${chalk.green.bold(skipMissingReferences ? "Yes" : "No")}`,
|
|
199
|
+
"",
|
|
200
|
+
])
|
|
201
|
+
.otherwise(() => []),
|
|
202
|
+
`${chalk.yellow("⚠")} ${match(action)
|
|
203
|
+
.returnType<string>()
|
|
204
|
+
.with("export", () => "Are you sure you want to export the data?")
|
|
205
|
+
.with("import", () => "Are you sure you want to import the data?")
|
|
206
|
+
.with("migrate", () => "Are you sure you want to migrate the data?")
|
|
207
|
+
.exhaustive()}`,
|
|
208
|
+
];
|
|
209
|
+
|
|
210
|
+
return lines.join("\n");
|
|
133
211
|
}
|
|
@@ -1,88 +1,85 @@
|
|
|
1
|
-
import { SharedModels } from
|
|
2
|
-
import chalk from
|
|
3
|
-
import { match } from
|
|
4
|
-
import { ZodError } from
|
|
5
|
-
import type { ErrorData, OriginalManagementError } from
|
|
1
|
+
import { SharedModels } from "@kontent-ai/management-sdk";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { match } from "ts-pattern";
|
|
4
|
+
import { ZodError } from "zod";
|
|
5
|
+
import type { ErrorData, OriginalManagementError } from "../models/core.models.js";
|
|
6
6
|
|
|
7
7
|
export function extractErrorData(error: unknown): ErrorData {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
return match(error)
|
|
9
|
+
.returnType<ErrorData>()
|
|
10
|
+
.when(
|
|
11
|
+
(error) => error instanceof SharedModels.ContentManagementBaseKontentError,
|
|
12
|
+
(error) => {
|
|
13
|
+
const originalError = error.originalError as OriginalManagementError | undefined;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
message: `Unknown error`
|
|
56
|
-
};
|
|
57
|
-
});
|
|
15
|
+
return {
|
|
16
|
+
isUnknownError: false,
|
|
17
|
+
error: error,
|
|
18
|
+
message: `${error.message} ${error.validationErrors.map((m) => m.message).join(", ")}`,
|
|
19
|
+
requestUrl: originalError?.response?.config?.url,
|
|
20
|
+
requestData: originalError?.response?.config?.data,
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
)
|
|
24
|
+
.when(
|
|
25
|
+
(error) => error instanceof ZodError,
|
|
26
|
+
(error) => {
|
|
27
|
+
const parsingErrorsMsg = error.issues.reduce<string>((current, issue, index) => {
|
|
28
|
+
const message = `\n${index + 1}. ${chalk.red(issue.message)} (${chalk.yellow("path")}: ${issue.path.join(",")})`;
|
|
29
|
+
return `${current}${message}`;
|
|
30
|
+
}, "");
|
|
31
|
+
return {
|
|
32
|
+
isUnknownError: false,
|
|
33
|
+
error: error,
|
|
34
|
+
message: `Found '${chalk.red(error.issues.length)}' parsing errors: \n${parsingErrorsMsg}`,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
)
|
|
38
|
+
.when(
|
|
39
|
+
(error) => error instanceof Error,
|
|
40
|
+
(error) => {
|
|
41
|
+
return {
|
|
42
|
+
isUnknownError: false,
|
|
43
|
+
error: error,
|
|
44
|
+
message: error.message,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
)
|
|
48
|
+
.otherwise((error) => {
|
|
49
|
+
return {
|
|
50
|
+
isUnknownError: true,
|
|
51
|
+
error: error,
|
|
52
|
+
message: `Unknown error`,
|
|
53
|
+
};
|
|
54
|
+
});
|
|
58
55
|
}
|
|
59
56
|
|
|
60
57
|
export function is404Error(error: unknown): boolean {
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
if (error instanceof SharedModels.ContentManagementBaseKontentError) {
|
|
59
|
+
const originalError = error.originalError as OriginalManagementError | undefined;
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
if (originalError?.response?.status === 404) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
68
65
|
|
|
69
|
-
|
|
66
|
+
return false;
|
|
70
67
|
}
|
|
71
68
|
|
|
72
69
|
export function handleError(error: unknown): void {
|
|
73
|
-
|
|
70
|
+
const errorData = extractErrorData(error);
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
if (errorData.isUnknownError) {
|
|
73
|
+
console.error(error);
|
|
74
|
+
}
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
if (errorData.requestData) {
|
|
77
|
+
console.log(`${chalk.red("Request data")}: ${errorData.requestData}`);
|
|
78
|
+
}
|
|
82
79
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
if (errorData.requestUrl) {
|
|
81
|
+
console.log(`${chalk.red("Request url")}: ${errorData.requestUrl}`);
|
|
82
|
+
}
|
|
86
83
|
|
|
87
|
-
|
|
84
|
+
console.error(errorData.message);
|
|
88
85
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export interface ExternalIdGenerator {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
readonly assetExternalId: (codename: string) => string;
|
|
3
|
+
readonly contentItemExternalId: (codename: string) => string;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export const defaultExternalIdGenerator: ExternalIdGenerator = {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
assetExternalId: (codename) => `asset_${codename}`,
|
|
8
|
+
contentItemExternalId: (codename) => `item_${codename}`,
|
|
9
9
|
};
|