@kontent-ai/migration-toolkit 3.2.0-preview.1 → 3.2.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.
Files changed (40) hide show
  1. package/dist/core/models/core.models.d.ts +2 -2
  2. package/dist/core/utils/array.utils.js +0 -3
  3. package/dist/core/utils/array.utils.js.map +1 -1
  4. package/dist/core/utils/confirm.utils.d.ts +10 -0
  5. package/dist/core/utils/confirm.utils.js +48 -1
  6. package/dist/core/utils/confirm.utils.js.map +1 -1
  7. package/dist/core/utils/external-id.utils.d.ts +2 -2
  8. package/dist/core/utils/global.utils.d.ts +0 -7
  9. package/dist/core/utils/global.utils.js +0 -54
  10. package/dist/core/utils/global.utils.js.map +1 -1
  11. package/dist/import/context/import-context-fetcher.js +32 -0
  12. package/dist/import/context/import-context-fetcher.js.map +1 -1
  13. package/dist/metadata.js +1 -1
  14. package/dist/metadata.js.map +1 -1
  15. package/dist/toolkit/export.js +1 -18
  16. package/dist/toolkit/export.js.map +1 -1
  17. package/dist/toolkit/file.js +10 -41
  18. package/dist/toolkit/file.js.map +1 -1
  19. package/dist/toolkit/import.js +11 -28
  20. package/dist/toolkit/import.js.map +1 -1
  21. package/dist/toolkit/migrate.js +15 -34
  22. package/dist/toolkit/migrate.js.map +1 -1
  23. package/dist/translation/helpers/rich-text.processor.js +0 -20
  24. package/dist/translation/helpers/rich-text.processor.js.map +1 -1
  25. package/dist/translation/transforms/import-transforms.js +10 -27
  26. package/dist/translation/transforms/import-transforms.js.map +1 -1
  27. package/lib/core/models/core.models.ts +2 -2
  28. package/lib/core/utils/array.utils.ts +0 -3
  29. package/lib/core/utils/confirm.utils.ts +73 -1
  30. package/lib/core/utils/external-id.utils.ts +2 -2
  31. package/lib/core/utils/global.utils.ts +0 -65
  32. package/lib/import/context/import-context-fetcher.ts +38 -0
  33. package/lib/metadata.ts +1 -1
  34. package/lib/toolkit/export.ts +1 -18
  35. package/lib/toolkit/file.ts +9 -43
  36. package/lib/toolkit/import.ts +11 -28
  37. package/lib/toolkit/migrate.ts +16 -35
  38. package/lib/translation/helpers/rich-text.processor.ts +0 -27
  39. package/lib/translation/transforms/import-transforms.ts +12 -32
  40. package/package.json +11 -10
@@ -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
- return await executeWithTrackingAsync({
10
- event: {
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
- if (config.createReportFile) {
25
- const reportFile = importManager.getReportFile(importResult);
26
- await writeFile(reportFile.filename, reportFile.content);
27
- config.logger?.log({
28
- type: "writeFs",
29
- message: `Report '${chalk.yellow(reportFile.filename)}' was created`,
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
- return importResult;
34
- },
35
- logger: config.logger,
36
- });
19
+ return importResult;
37
20
  }
@@ -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
- return await executeWithTrackingAsync({
41
- event: {
42
- tool: "migrationToolkit",
43
- package: {
44
- name: libMetadata.name,
45
- version: libMetadata.version,
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
- return {
69
- importResult,
70
- migrationData,
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,12 +190,6 @@ export function richTextProcessor() {
190
190
  return objectTag;
191
191
  }
192
192
 
193
- if (!itemState.externalIdToUse) {
194
- // when external_id is not available, try falling back to initial codename - this can fail
195
- // if the item does not exist in the target env
196
- return objectTag;
197
- }
198
-
199
193
  return objectTag.replaceAll(
200
194
  `${attributes.codenames.itemCodenameAttribute}="${codename}"`,
201
195
  `${attributes.ids.externalIdAttributeName}="${itemState.externalIdToUse}"`,
@@ -231,13 +225,6 @@ export function richTextProcessor() {
231
225
  if (itemState.item && itemState.state === "exists") {
232
226
  return linkTag;
233
227
  }
234
-
235
- if (!itemState.externalIdToUse) {
236
- // when external_id is not available, try falling back to initial codename - this can fail
237
- // if the item does not exist in the target env
238
- return linkTag;
239
- }
240
-
241
228
  return linkTag.replaceAll(
242
229
  `${attributes.codenames.linkItemCodenameAttribute}="${codename}"`,
243
230
  `${attributes.ids.itemExternalIdAttributeName}="${itemState.externalIdToUse}"`,
@@ -273,13 +260,6 @@ export function richTextProcessor() {
273
260
  if (assetState.asset && assetState.state === "exists") {
274
261
  return figureTag;
275
262
  }
276
-
277
- if (!assetState.externalIdToUse) {
278
- // when external_id is not available, try falling back to initial codename - this can fail
279
- // if the asset does not exist in the target env
280
- return figureTag;
281
- }
282
-
283
263
  return figureTag.replaceAll(
284
264
  `${attributes.codenames.assetCodenameAttribute}="${codename}"`,
285
265
  `${attributes.ids.externalAssetIdAttributeName}="${assetState.externalIdToUse}"`,
@@ -315,13 +295,6 @@ export function richTextProcessor() {
315
295
  if (assetState.asset && assetState.state === "exists") {
316
296
  return linkTag;
317
297
  }
318
-
319
- if (!assetState.externalIdToUse) {
320
- // when external_id is not available, try falling back to initial codename - this can fail
321
- // if the asset does not exist in the target env
322
- return linkTag;
323
- }
324
-
325
298
  return linkTag.replaceAll(
326
299
  `${attributes.codenames.assetCodenameAttribute}="${codename}"`,
327
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 { isNotUndefined, isString } from "../../core/utils/global.utils.js";
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> | undefined>((codename) => {
30
+ .map<Readonly<SharedContracts.IReferenceObjectContract>>((codename) => {
31
31
  const assetState = data.importContext.getAssetStateInTargetEnvironment(codename);
32
- if (assetState.asset) {
33
- return {
34
- id: assetState.asset.id,
35
- };
36
- }
37
-
38
- if (!assetState.externalIdToUse && !assetState.asset) {
39
- return {
40
- codename: assetState.assetCodename,
41
- };
42
- }
43
32
 
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
44
35
  return {
45
- external_id: assetState.externalIdToUse,
36
+ id: assetState.asset ? assetState.asset.id : undefined,
37
+ external_id: assetState.asset ? undefined : assetState.externalIdToUse,
46
38
  };
47
- })
48
- .filter(isNotUndefined);
39
+ });
49
40
 
50
41
  return elementsBuilder.assetElement({
51
42
  element: {
@@ -74,26 +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> | undefined>((codename) => {
68
+ .map<Readonly<SharedContracts.IReferenceObjectContract>>((codename) => {
78
69
  const itemState = data.importContext.getItemStateInTargetEnvironment(codename);
79
70
 
80
- if (itemState.item) {
81
- return {
82
- codename: itemState.item.codename,
83
- };
84
- }
85
-
86
- if (!itemState.externalIdToUse && !itemState.item) {
87
- return {
88
- codename: itemState.itemCodename,
89
- };
90
- }
91
-
71
+ // only reference with external_id if item does not exist in target env
92
72
  return {
93
- external_id: itemState.externalIdToUse,
73
+ codename: itemState.item ? itemState.item.codename : undefined,
74
+ external_id: itemState.item ? undefined : itemState.externalIdToUse,
94
75
  };
95
- })
96
- .filter(isNotUndefined);
76
+ });
97
77
 
98
78
  return elementsBuilder.linkedItemsElement({
99
79
  element: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontent-ai/migration-toolkit",
3
- "version": "3.2.0-preview.1",
3
+ "version": "3.2.1",
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-consulting/tools-analytics": "0.0.12",
53
- "@kontent-ai/management-sdk": "8.5.1",
53
+ "@kontent-ai/management-sdk": "8.5.4",
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.0",
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/biome-config": "0.7.0",
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.4.15",
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": "25.7.0",
78
+ "@types/node": "26.1.0",
78
79
  "@types/prompts": "2.4.9",
79
80
  "@types/yargs": "17.0.35",
80
- "eslint": "10.3.0",
81
+ "eslint": "10.6.0",
81
82
  "tslib": "2.8.1",
82
- "tsx": "4.21.0",
83
+ "tsx": "4.22.5",
83
84
  "typescript": "6.0.3",
84
- "vitest": "4.1.6"
85
+ "vitest": "4.1.9"
85
86
  }
86
87
  }