@kontent-ai/migration-toolkit 2.1.1 → 2.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.
Files changed (36) hide show
  1. package/dist/es2022/core/helpers/workflow-helper.d.ts +10 -0
  2. package/dist/es2022/core/helpers/workflow-helper.js +71 -3
  3. package/dist/es2022/core/helpers/workflow-helper.js.map +1 -1
  4. package/dist/es2022/core/models/migration.schema.d.ts +68 -68
  5. package/dist/es2022/core/utils/global.utils.d.ts +2 -0
  6. package/dist/es2022/core/utils/global.utils.js +43 -10
  7. package/dist/es2022/core/utils/global.utils.js.map +1 -1
  8. package/dist/es2022/core/utils/run.utils.js.map +1 -1
  9. package/dist/es2022/import/importers/language-variant-importer.js +2 -1
  10. package/dist/es2022/import/importers/language-variant-importer.js.map +1 -1
  11. package/dist/es2022/import/importers/workflow-importer.d.ts +5 -1
  12. package/dist/es2022/import/importers/workflow-importer.js +17 -2
  13. package/dist/es2022/import/importers/workflow-importer.js.map +1 -1
  14. package/dist/es2022/metadata.js +2 -2
  15. package/dist/es2022/toolkit/export.js +3 -2
  16. package/dist/es2022/toolkit/export.js.map +1 -1
  17. package/dist/es2022/toolkit/file.js +4 -2
  18. package/dist/es2022/toolkit/file.js.map +1 -1
  19. package/dist/es2022/toolkit/import.js +2 -1
  20. package/dist/es2022/toolkit/import.js.map +1 -1
  21. package/dist/es2022/toolkit/migrate.js +3 -2
  22. package/dist/es2022/toolkit/migrate.js.map +1 -1
  23. package/dist/es2022/translation/transforms/import-transforms.js +1 -1
  24. package/dist/es2022/translation/transforms/import-transforms.js.map +1 -1
  25. package/lib/core/helpers/workflow-helper.ts +106 -8
  26. package/lib/core/utils/global.utils.ts +46 -10
  27. package/lib/core/utils/run.utils.ts +1 -1
  28. package/lib/import/importers/language-variant-importer.ts +2 -1
  29. package/lib/import/importers/workflow-importer.ts +37 -5
  30. package/lib/metadata.ts +2 -2
  31. package/lib/toolkit/export.ts +3 -2
  32. package/lib/toolkit/file.ts +4 -2
  33. package/lib/toolkit/import.ts +2 -1
  34. package/lib/toolkit/migrate.ts +4 -3
  35. package/lib/translation/transforms/import-transforms.ts +1 -1
  36. package/package.json +18 -16
@@ -1,13 +1,15 @@
1
- import { ManagementClient, SharedModels, WorkflowModels } from '@kontent-ai/management-sdk';
1
+ import { LanguageVariantModels, ManagementClient, SharedModels, WorkflowModels } from '@kontent-ai/management-sdk';
2
+ import { match } from 'ts-pattern';
2
3
  import {
3
4
  Logger,
4
- runMapiRequestAsync,
5
5
  LogSpinnerData,
6
6
  MigrationItem,
7
+ MigrationItemVersion,
8
+ runMapiRequestAsync,
9
+ ShortestPathResult,
7
10
  workflowHelper as workflowHelperInit,
8
- MigrationItemVersion
11
+ WorkflowStep
9
12
  } from '../../core/index.js';
10
- import { match } from 'ts-pattern';
11
13
 
12
14
  export function workflowImporter(config: {
13
15
  readonly logger: Logger;
@@ -19,6 +21,9 @@ export function workflowImporter(config: {
19
21
  const publishLanguageVariantAsync = async (data: {
20
22
  readonly logSpinner: LogSpinnerData;
21
23
  readonly migrationItem: MigrationItem;
24
+ readonly languageVariant: Readonly<LanguageVariantModels.ContentItemLanguageVariant>;
25
+ readonly workflowCodename: string;
26
+ readonly stepCodename: string;
22
27
  }): Promise<void> => {
23
28
  await runMapiRequestAsync({
24
29
  logger: config.logger,
@@ -38,6 +43,16 @@ export function workflowImporter(config: {
38
43
  });
39
44
  };
40
45
 
46
+ const getPreviousToPublishStep = (
47
+ workflow: Readonly<WorkflowModels.Workflow>,
48
+ variantStep: WorkflowStep,
49
+ publishStep: WorkflowStep
50
+ ): ShortestPathResult => {
51
+ const steps = workflowHelper.findShortestPathBetweenSteps(workflow, variantStep, publishStep);
52
+
53
+ return steps[steps.length - 2];
54
+ };
55
+
41
56
  const unpublishLanguageVariantAsync = async (data: {
42
57
  readonly logSpinner: LogSpinnerData;
43
58
  readonly migrationItem: MigrationItem;
@@ -331,12 +346,29 @@ export function workflowImporter(config: {
331
346
  readonly stepCodename: string;
332
347
  readonly migrationItem: MigrationItem;
333
348
  readonly migrationItemVersion: MigrationItemVersion;
349
+ readonly languageVariant: Readonly<LanguageVariantModels.ContentItemLanguageVariant>;
334
350
  }): Promise<void> => {
335
351
  return await match(data.stepCodename)
336
352
  .returnType<Promise<void>>()
337
353
  .when(
338
354
  (stepCodename) => workflowHelper.isPublishedStepByCodename(stepCodename),
339
- async () => await publishLanguageVariantAsync(data)
355
+ async () => {
356
+ const { workflow, step: publishStep } = workflowHelper.getWorkflowAndStepByCodenames({
357
+ workflowCodename: data.workflowCodename,
358
+ stepCodename: data.stepCodename
359
+ });
360
+ const variantStep = workflowHelper.getWorkflowStepById(
361
+ workflow,
362
+ data.languageVariant.workflow.stepIdentifier.id as string
363
+ );
364
+ const previousToPublishStep = getPreviousToPublishStep(workflow, variantStep, publishStep);
365
+
366
+ if (previousToPublishStep) {
367
+ await changeWorkflowOfLanguageVariantAsync({ ...data, stepCodename: previousToPublishStep.stepCodename });
368
+ }
369
+
370
+ await publishLanguageVariantAsync(data);
371
+ }
340
372
  )
341
373
  .when(
342
374
  (stepCodename) => workflowHelper.isArchivedStepByCodename(stepCodename),
package/lib/metadata.ts CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  export const libMetadata = {
3
3
  name: '@kontent-ai/migration-toolkit',
4
- timestamp: 'Tue, 08 Oct 2024 13:54:56 GMT',
5
- version: '2.1.1'
4
+ timestamp: 'Tue, 29 Oct 2024 08:38:01 GMT',
5
+ version: '2.2.0'
6
6
  };
@@ -1,6 +1,6 @@
1
- import { libMetadata } from '../metadata.js';
2
1
  import { MigrationData, executeWithTrackingAsync } from '../core/index.js';
3
2
  import { ExportConfig, exportManager } from '../export/index.js';
3
+ import { libMetadata } from '../metadata.js';
4
4
 
5
5
  export async function exportAsync(config: ExportConfig): Promise<MigrationData> {
6
6
  return await executeWithTrackingAsync({
@@ -16,6 +16,7 @@ export async function exportAsync(config: ExportConfig): Promise<MigrationData>
16
16
  },
17
17
  func: async () => {
18
18
  return await exportManager(config).exportAsync();
19
- }
19
+ },
20
+ logger: config.logger
20
21
  });
21
22
  }
@@ -38,7 +38,8 @@ export async function storeAsync(config: StoreConfig): Promise<void> {
38
38
  } else {
39
39
  throw Error(`Cannot store '${filename}' on File system because the provided zip is not a Buffer`);
40
40
  }
41
- }
41
+ },
42
+ logger: config.logger
42
43
  });
43
44
  }
44
45
 
@@ -60,6 +61,7 @@ export async function extractAsync(config: ExtractConfig): Promise<MigrationData
60
61
  func: async () => {
61
62
  const fileData = await fileManager(logger).loadFileAsync(filename);
62
63
  return await zipManager(logger).parseZipAsync(fileData);
63
- }
64
+ },
65
+ logger: config.logger
64
66
  });
65
67
  }
@@ -16,6 +16,7 @@ export async function importAsync(config: ImportConfig): Promise<ImportResult> {
16
16
  },
17
17
  func: async () => {
18
18
  return await importManager(config).importAsync();
19
- }
19
+ },
20
+ logger: config.logger
20
21
  });
21
22
  }
@@ -1,4 +1,3 @@
1
- import { libMetadata } from '../metadata.js';
2
1
  import { IRetryStrategyOptions } from '@kontent-ai/core-sdk';
3
2
  import {
4
3
  ExternalIdGenerator,
@@ -9,9 +8,10 @@ import {
9
8
  getDefaultLogger
10
9
  } from '../core/index.js';
11
10
  import { SourceExportItem } from '../export/index.js';
11
+ import { ImportResult } from '../import/index.js';
12
+ import { libMetadata } from '../metadata.js';
12
13
  import { exportAsync } from './export.js';
13
14
  import { importAsync } from './import.js';
14
- import { ImportResult } from '../import/index.js';
15
15
 
16
16
  export interface MigrationSource extends ManagementClientConfig {
17
17
  readonly items: readonly SourceExportItem[];
@@ -64,6 +64,7 @@ export async function migrateAsync(config: MigrationConfig): Promise<MigrationRe
64
64
  importResult,
65
65
  migrationData
66
66
  };
67
- }
67
+ },
68
+ logger: config.logger
68
69
  });
69
70
  }
@@ -97,7 +97,7 @@ export const importTransforms: Readonly<Record<MigrationElementType, ImportTrans
97
97
  element: {
98
98
  codename: data.elementCodename
99
99
  },
100
- value: data.elementData ? +data.elementData : null
100
+ value: data.elementData.value ? +data.elementData.value : null
101
101
  });
102
102
  },
103
103
  rich_text: (data) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontent-ai/migration-toolkit",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "This program can be used to import content related data into Kontent.ai from various formats. Additionally, it can also be used to export Kontent.ai data using Delivery API.",
5
5
  "preferGlobal": true,
6
6
  "private": false,
@@ -36,6 +36,7 @@
36
36
  "test:export:cli": "tsx lib/node/cli/app export --language=x --items=x --sourceEnvironmentId=x --sourceApiKey=x",
37
37
  "test:help": "tsx lib/node/cli/app --help",
38
38
  "test:help:command": "tsx lib/node/cli/app migrate --help",
39
+ "test:unit": "vitest run --config=vitest.config.js",
39
40
  "lint": "npx eslint lib",
40
41
  "lint:fix": "npx eslint lib --fix",
41
42
  "clean": "tsx scripts/clean.ts",
@@ -55,36 +56,37 @@
55
56
  "@kontent-ai-consulting/tools-analytics": "0.0.7",
56
57
  "@kontent-ai/management-sdk": "7.5.1",
57
58
  "browser-or-node": "3.0.0",
59
+ "buffer": "6.0.3",
58
60
  "bytes": "3.1.2",
59
61
  "chalk": "5.3.0",
62
+ "deep-equal": "2.2.3",
60
63
  "dotenv": "16.4.5",
61
64
  "jszip": "3.10.1",
62
65
  "mime": "4.0.4",
63
66
  "ora": "8.1.0",
67
+ "p-limit": "6.1.0",
64
68
  "prompts": "2.4.2",
69
+ "ts-pattern": "5.5.0",
65
70
  "yargs": "17.7.2",
66
- "p-limit": "6.1.0",
67
- "deep-equal": "2.2.3",
68
- "zod": "3.23.8",
69
- "ts-pattern": "5.4.0",
70
- "buffer": "6.0.3"
71
+ "zod": "3.23.8"
71
72
  },
72
73
  "devDependencies": {
73
- "@eslint/js": "9.12.0",
74
- "@types/deep-equal": "1.0.4",
74
+ "@eslint/js": "9.13.0",
75
75
  "@types/browser-or-node": "1.3.2",
76
76
  "@types/bytes": "3.1.4",
77
+ "@types/deep-equal": "1.0.4",
77
78
  "@types/eslint__js": "8.42.3",
78
- "@types/node": "22.7.5",
79
+ "@types/node": "22.8.2",
79
80
  "@types/prompts": "2.4.9",
80
81
  "@types/yargs": "17.0.33",
81
- "@typescript-eslint/eslint-plugin": "8.8.1",
82
- "@typescript-eslint/parser": "8.8.1",
83
- "eslint": "9.12.0",
82
+ "@typescript-eslint/eslint-plugin": "8.12.1",
83
+ "@typescript-eslint/parser": "8.12.1",
84
+ "eslint": "9.13.0",
84
85
  "standard-version": "9.5.0",
85
- "tslib": "2.7.0",
86
- "tsx": "4.19.1",
87
- "typescript": "5.6.2",
88
- "typescript-eslint": "8.8.1"
86
+ "tslib": "2.8.0",
87
+ "tsx": "4.19.2",
88
+ "typescript": "5.6.3",
89
+ "typescript-eslint": "8.12.1",
90
+ "vitest": "2.1.4"
89
91
  }
90
92
  }