@kontent-ai/migration-toolkit 3.2.0-preview.0 → 3.2.0
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/dist/core/models/core.models.d.ts +2 -2
- package/dist/core/utils/array.utils.js +0 -3
- package/dist/core/utils/array.utils.js.map +1 -1
- package/dist/core/utils/confirm.utils.d.ts +10 -0
- package/dist/core/utils/confirm.utils.js +48 -1
- package/dist/core/utils/confirm.utils.js.map +1 -1
- package/dist/core/utils/external-id.utils.d.ts +2 -2
- package/dist/core/utils/global.utils.d.ts +0 -7
- package/dist/core/utils/global.utils.js +0 -54
- package/dist/core/utils/global.utils.js.map +1 -1
- package/dist/import/context/import-context-fetcher.js +32 -0
- package/dist/import/context/import-context-fetcher.js.map +1 -1
- package/dist/metadata.js +1 -1
- package/dist/metadata.js.map +1 -1
- package/dist/toolkit/export.js +1 -18
- package/dist/toolkit/export.js.map +1 -1
- package/dist/toolkit/file.js +10 -41
- package/dist/toolkit/file.js.map +1 -1
- package/dist/toolkit/import.js +11 -28
- package/dist/toolkit/import.js.map +1 -1
- package/dist/toolkit/migrate.js +15 -34
- package/dist/toolkit/migrate.js.map +1 -1
- package/dist/translation/helpers/rich-text.processor.js +0 -12
- package/dist/translation/helpers/rich-text.processor.js.map +1 -1
- package/dist/translation/transforms/import-transforms.js +13 -27
- package/dist/translation/transforms/import-transforms.js.map +1 -1
- package/lib/core/models/core.models.ts +2 -2
- package/lib/core/utils/array.utils.ts +0 -3
- package/lib/core/utils/confirm.utils.ts +73 -1
- package/lib/core/utils/external-id.utils.ts +2 -2
- package/lib/core/utils/global.utils.ts +0 -65
- package/lib/import/context/import-context-fetcher.ts +38 -0
- package/lib/metadata.ts +1 -1
- package/lib/toolkit/export.ts +1 -18
- package/lib/toolkit/file.ts +9 -43
- package/lib/toolkit/import.ts +11 -28
- package/lib/toolkit/migrate.ts +16 -35
- package/lib/translation/helpers/rich-text.processor.ts +0 -19
- package/lib/translation/transforms/import-transforms.ts +16 -34
- package/package.json +11 -10
package/lib/toolkit/import.ts
CHANGED
|
@@ -1,37 +1,20 @@
|
|
|
1
1
|
import { writeFile } from "node:fs/promises";
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
-
import { executeWithTrackingAsync } from "../core/utils/global.utils.js";
|
|
4
3
|
import type { ImportConfig, ImportResult } from "../import/import.models.js";
|
|
5
4
|
import { importManager as _importManager } from "../import/import-manager.js";
|
|
6
|
-
import { libMetadata } from "../metadata.js";
|
|
7
5
|
|
|
8
6
|
export async function importAsync(config: ImportConfig): Promise<ImportResult> {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
tool: "migrationToolkit",
|
|
12
|
-
package: {
|
|
13
|
-
name: libMetadata.name,
|
|
14
|
-
version: libMetadata.version,
|
|
15
|
-
},
|
|
16
|
-
action: "import",
|
|
17
|
-
relatedEnvironmentId: undefined,
|
|
18
|
-
details: {},
|
|
19
|
-
},
|
|
20
|
-
func: async () => {
|
|
21
|
-
const importManager = _importManager(config);
|
|
22
|
-
const importResult = await importManager.importAsync();
|
|
7
|
+
const importManager = _importManager(config);
|
|
8
|
+
const importResult = await importManager.importAsync();
|
|
23
9
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
10
|
+
if (config.createReportFile) {
|
|
11
|
+
const reportFile = importManager.getReportFile(importResult);
|
|
12
|
+
await writeFile(reportFile.filename, reportFile.content);
|
|
13
|
+
config.logger?.log({
|
|
14
|
+
type: "writeFs",
|
|
15
|
+
message: `Report '${chalk.yellow(reportFile.filename)}' was created`,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
32
18
|
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
logger: config.logger,
|
|
36
|
-
});
|
|
19
|
+
return importResult;
|
|
37
20
|
}
|
package/lib/toolkit/migrate.ts
CHANGED
|
@@ -3,11 +3,9 @@ import { getDefaultLogger } from "../core/logs/loggers.js";
|
|
|
3
3
|
import type { Logger } from "../core/models/log.models.js";
|
|
4
4
|
import type { MigrationData } from "../core/models/migration.models.js";
|
|
5
5
|
import type { ExternalIdGenerator } from "../core/utils/external-id.utils.js";
|
|
6
|
-
import { executeWithTrackingAsync } from "../core/utils/global.utils.js";
|
|
7
6
|
import type { ManagementClientConfig } from "../core/utils/management-client-utils.js";
|
|
8
7
|
import type { SourceExportItem } from "../export/export.models.js";
|
|
9
8
|
import type { ImportResult } from "../import/import.models.js";
|
|
10
|
-
import { libMetadata } from "../metadata.js";
|
|
11
9
|
import { exportAsync } from "./export.js";
|
|
12
10
|
import { importAsync } from "./import.js";
|
|
13
11
|
|
|
@@ -37,39 +35,22 @@ export type MigrationResult = {
|
|
|
37
35
|
export async function migrateAsync(config: MigrationConfig): Promise<MigrationResult> {
|
|
38
36
|
const logger = config.logger ?? getDefaultLogger();
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
action: "migrate",
|
|
48
|
-
relatedEnvironmentId: undefined,
|
|
49
|
-
details: {
|
|
50
|
-
itemsCount: config.sourceEnvironment.items.length,
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
func: async () => {
|
|
54
|
-
const migrationData = await exportAsync({
|
|
55
|
-
...config.sourceEnvironment,
|
|
56
|
-
logger: logger,
|
|
57
|
-
exportItems: config.sourceEnvironment.items,
|
|
58
|
-
skipMissingReferences: config.sourceEnvironment.skipMissingReferences,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const importResult = await importAsync({
|
|
62
|
-
...config.targetEnvironment,
|
|
63
|
-
logger: logger,
|
|
64
|
-
data: migrationData,
|
|
65
|
-
externalIdGenerator: config.externalIdGenerator,
|
|
66
|
-
});
|
|
38
|
+
const migrationData = await exportAsync({
|
|
39
|
+
...config.sourceEnvironment,
|
|
40
|
+
logger: logger,
|
|
41
|
+
exportItems: config.sourceEnvironment.items,
|
|
42
|
+
skipMissingReferences: config.sourceEnvironment.skipMissingReferences,
|
|
43
|
+
});
|
|
67
44
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
logger: config.logger,
|
|
45
|
+
const importResult = await importAsync({
|
|
46
|
+
...config.targetEnvironment,
|
|
47
|
+
logger: logger,
|
|
48
|
+
data: migrationData,
|
|
49
|
+
externalIdGenerator: config.externalIdGenerator,
|
|
74
50
|
});
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
importResult,
|
|
54
|
+
migrationData,
|
|
55
|
+
};
|
|
75
56
|
}
|
|
@@ -190,10 +190,6 @@ export function richTextProcessor() {
|
|
|
190
190
|
return objectTag;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
if (!itemState.externalIdToUse) {
|
|
194
|
-
return "";
|
|
195
|
-
}
|
|
196
|
-
|
|
197
193
|
return objectTag.replaceAll(
|
|
198
194
|
`${attributes.codenames.itemCodenameAttribute}="${codename}"`,
|
|
199
195
|
`${attributes.ids.externalIdAttributeName}="${itemState.externalIdToUse}"`,
|
|
@@ -229,11 +225,6 @@ export function richTextProcessor() {
|
|
|
229
225
|
if (itemState.item && itemState.state === "exists") {
|
|
230
226
|
return linkTag;
|
|
231
227
|
}
|
|
232
|
-
|
|
233
|
-
if (!itemState.externalIdToUse) {
|
|
234
|
-
return "";
|
|
235
|
-
}
|
|
236
|
-
|
|
237
228
|
return linkTag.replaceAll(
|
|
238
229
|
`${attributes.codenames.linkItemCodenameAttribute}="${codename}"`,
|
|
239
230
|
`${attributes.ids.itemExternalIdAttributeName}="${itemState.externalIdToUse}"`,
|
|
@@ -269,11 +260,6 @@ export function richTextProcessor() {
|
|
|
269
260
|
if (assetState.asset && assetState.state === "exists") {
|
|
270
261
|
return figureTag;
|
|
271
262
|
}
|
|
272
|
-
|
|
273
|
-
if (!assetState.externalIdToUse) {
|
|
274
|
-
return "";
|
|
275
|
-
}
|
|
276
|
-
|
|
277
263
|
return figureTag.replaceAll(
|
|
278
264
|
`${attributes.codenames.assetCodenameAttribute}="${codename}"`,
|
|
279
265
|
`${attributes.ids.externalAssetIdAttributeName}="${assetState.externalIdToUse}"`,
|
|
@@ -309,11 +295,6 @@ export function richTextProcessor() {
|
|
|
309
295
|
if (assetState.asset && assetState.state === "exists") {
|
|
310
296
|
return linkTag;
|
|
311
297
|
}
|
|
312
|
-
|
|
313
|
-
if (!assetState.externalIdToUse) {
|
|
314
|
-
return "";
|
|
315
|
-
}
|
|
316
|
-
|
|
317
298
|
return linkTag.replaceAll(
|
|
318
299
|
`${attributes.codenames.assetCodenameAttribute}="${codename}"`,
|
|
319
300
|
`${attributes.ids.externalAssetIdAttributeName}="${assetState.externalIdToUse}"`,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type LanguageVariantElements, LanguageVariantElementsBuilder, type SharedContracts } from "@kontent-ai/management-sdk";
|
|
2
2
|
import type { MigrationElementTransformData, MigrationElementType, MigrationItem } from "../../core/models/migration.models.js";
|
|
3
3
|
import { parseAsMigrationReferencesArray } from "../../core/utils/array.utils.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isString } from "../../core/utils/global.utils.js";
|
|
5
5
|
import type { ImportContext, ImportTransformFunc } from "../../import/import.models.js";
|
|
6
6
|
import { richTextProcessor } from "../helpers/rich-text.processor.js";
|
|
7
7
|
|
|
@@ -27,25 +27,16 @@ export const importTransforms: Readonly<Record<MigrationElementType, ImportTrans
|
|
|
27
27
|
asset: (data) => {
|
|
28
28
|
const assetReferences = parseAsMigrationReferencesArray(data.elementData.value)
|
|
29
29
|
.map((reference) => reference.codename)
|
|
30
|
-
.map<Readonly<SharedContracts.IReferenceObjectContract
|
|
30
|
+
.map<Readonly<SharedContracts.IReferenceObjectContract>>((codename) => {
|
|
31
31
|
const assetState = data.importContext.getAssetStateInTargetEnvironment(codename);
|
|
32
|
-
// API currently only supports referencing assets by ids only, not by codenames
|
|
33
|
-
|
|
34
|
-
if (assetState.asset) {
|
|
35
|
-
return {
|
|
36
|
-
id: assetState.asset.id,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (assetState.externalIdToUse && assetState.state === "doesNotExists") {
|
|
41
|
-
return {
|
|
42
|
-
external_id: assetState.externalIdToUse,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
32
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
// only reference with external_id if item does not exist in target env
|
|
34
|
+
// API currently only supports referencing assets by ids only, not by codenames
|
|
35
|
+
return {
|
|
36
|
+
id: assetState.asset ? assetState.asset.id : undefined,
|
|
37
|
+
external_id: assetState.asset ? undefined : assetState.externalIdToUse,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
49
40
|
|
|
50
41
|
return elementsBuilder.assetElement({
|
|
51
42
|
element: {
|
|
@@ -74,24 +65,15 @@ export const importTransforms: Readonly<Record<MigrationElementType, ImportTrans
|
|
|
74
65
|
modular_content: (data) => {
|
|
75
66
|
const linkedItemReferences = parseAsMigrationReferencesArray(data.elementData.value)
|
|
76
67
|
.map((reference) => reference.codename)
|
|
77
|
-
.map<Readonly<SharedContracts.IReferenceObjectContract
|
|
68
|
+
.map<Readonly<SharedContracts.IReferenceObjectContract>>((codename) => {
|
|
78
69
|
const itemState = data.importContext.getItemStateInTargetEnvironment(codename);
|
|
79
70
|
|
|
80
|
-
if
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (itemState.externalIdToUse && itemState.state === "doesNotExists") {
|
|
87
|
-
return {
|
|
88
|
-
external_id: itemState.externalIdToUse,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return undefined;
|
|
93
|
-
})
|
|
94
|
-
.filter(isNotUndefined);
|
|
71
|
+
// only reference with external_id if item does not exist in target env
|
|
72
|
+
return {
|
|
73
|
+
codename: itemState.item ? itemState.item.codename : undefined,
|
|
74
|
+
external_id: itemState.item ? undefined : itemState.externalIdToUse,
|
|
75
|
+
};
|
|
76
|
+
});
|
|
95
77
|
|
|
96
78
|
return elementsBuilder.linkedItemsElement({
|
|
97
79
|
element: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kontent-ai/migration-toolkit",
|
|
3
|
-
"version": "3.2.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "This program can be used to import content related data into Kontent.ai from various sources. The included functionality enables the content & asset export/import from Kontent.ai environments.",
|
|
5
5
|
"preferGlobal": true,
|
|
6
6
|
"private": false,
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"biome:fix:unsafe": "biome check --write --unsafe",
|
|
33
33
|
"clean": "tsx scripts/clean.ts",
|
|
34
34
|
"update:version": "tsx ./scripts/version/update-version.ts && npm run biome:fix",
|
|
35
|
+
"test:clean": "cd scripts/test && tsx test-clean.ts",
|
|
35
36
|
"test:migrate": "cd scripts/test && tsx test-migrate.ts",
|
|
36
37
|
"test:import": "cd scripts/test && tsx test-import.ts",
|
|
37
38
|
"test:export": "cd scripts/test && tsx test-export.ts",
|
|
@@ -49,8 +50,7 @@
|
|
|
49
50
|
],
|
|
50
51
|
"license": "MIT",
|
|
51
52
|
"dependencies": {
|
|
52
|
-
"@kontent-ai
|
|
53
|
-
"@kontent-ai/management-sdk": "8.5.1",
|
|
53
|
+
"@kontent-ai/management-sdk": "8.5.2",
|
|
54
54
|
"browser-or-node": "3.0.0",
|
|
55
55
|
"buffer": "6.0.3",
|
|
56
56
|
"bytes": "3.1.2",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"dotenv": "17.4.2",
|
|
60
60
|
"jszip": "3.10.1",
|
|
61
61
|
"mime": "4.1.0",
|
|
62
|
-
"ora": "9.4.
|
|
62
|
+
"ora": "9.4.1",
|
|
63
63
|
"p-limit": "7.3.0",
|
|
64
64
|
"prompts": "2.4.2",
|
|
65
65
|
"ts-pattern": "5.9.0",
|
|
@@ -67,20 +67,21 @@
|
|
|
67
67
|
"zod": "4.4.3"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@kontent-ai/
|
|
70
|
+
"@kontent-ai/data-ops": "2.7.0",
|
|
71
|
+
"@kontent-ai/biome-config": "0.7.3",
|
|
71
72
|
"@kontent-ai/eslint-config": "2.4.1",
|
|
72
|
-
"@biomejs/biome": "2.
|
|
73
|
+
"@biomejs/biome": "2.5.1",
|
|
73
74
|
"@eslint/js": "10.0.1",
|
|
74
75
|
"@types/browser-or-node": "1.3.2",
|
|
75
76
|
"@types/bytes": "3.1.5",
|
|
76
77
|
"@types/deep-equal": "1.0.4",
|
|
77
|
-
"@types/node": "
|
|
78
|
+
"@types/node": "26.1.0",
|
|
78
79
|
"@types/prompts": "2.4.9",
|
|
79
80
|
"@types/yargs": "17.0.35",
|
|
80
|
-
"eslint": "10.
|
|
81
|
+
"eslint": "10.6.0",
|
|
81
82
|
"tslib": "2.8.1",
|
|
82
|
-
"tsx": "4.
|
|
83
|
+
"tsx": "4.22.5",
|
|
83
84
|
"typescript": "6.0.3",
|
|
84
|
-
"vitest": "4.1.
|
|
85
|
+
"vitest": "4.1.9"
|
|
85
86
|
}
|
|
86
87
|
}
|