@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,98 +1,104 @@
|
|
|
1
|
-
import type { ITrackingEventData } from
|
|
2
|
-
import { getTrackingService } from
|
|
3
|
-
import { isBrowser, isNode, isWebWorker } from
|
|
4
|
-
import { format } from
|
|
5
|
-
import { getDefaultLogger } from
|
|
6
|
-
import type { EnvContext } from
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
1
|
+
import type { ITrackingEventData } from "@kontent-ai-consulting/tools-analytics";
|
|
2
|
+
import { getTrackingService } from "@kontent-ai-consulting/tools-analytics";
|
|
3
|
+
import { isBrowser, isNode, isWebWorker } from "browser-or-node";
|
|
4
|
+
import { format } from "bytes";
|
|
5
|
+
import { getDefaultLogger } from "../logs/loggers.js";
|
|
6
|
+
import type { EnvContext } from "../models/core.models.js";
|
|
7
|
+
import { MigrationToolkitError } from "../models/error.models.js";
|
|
8
|
+
import type { Logger } from "../models/log.models.js";
|
|
9
|
+
import { extractErrorData } from "./error.utils.js";
|
|
9
10
|
|
|
10
11
|
export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
|
|
11
12
|
|
|
12
13
|
export const isNotUndefined = <T>(item: T | undefined): item is T => item !== undefined;
|
|
13
14
|
|
|
14
|
-
export const isString = (value: unknown): value is string => typeof value ===
|
|
15
|
+
export const isString = (value: unknown): value is string => typeof value === "string";
|
|
15
16
|
export const isArray = <T>(value: unknown): value is Array<T> => Array.isArray(value);
|
|
16
17
|
|
|
17
18
|
export function formatBytes(bytes: number): string {
|
|
18
|
-
|
|
19
|
+
return format(bytes) ?? "n/a";
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export function exitProgram(data: { readonly message: string }): never {
|
|
22
|
-
|
|
23
|
+
throw new MigrationToolkitError("exitProgram", data.message);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export function getCurrentEnvironment(): EnvContext {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
if (isNode) {
|
|
28
|
+
return "node";
|
|
29
|
+
}
|
|
30
|
+
if (isBrowser || isWebWorker) {
|
|
31
|
+
return "browser";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
throw new MigrationToolkitError(
|
|
35
|
+
"invalidEnvironment",
|
|
36
|
+
`Invalid current environment. This library can be used in node.js or in browsers.`,
|
|
37
|
+
);
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
export const defaultZipFilename: string =
|
|
40
|
+
export const defaultZipFilename: string = "data.zip";
|
|
37
41
|
|
|
38
42
|
export async function executeWithTrackingAsync<TResult>(data: {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
readonly func: () => Promise<TResult extends void ? void : Readonly<TResult>>;
|
|
44
|
+
readonly event: Readonly<ITrackingEventData>;
|
|
45
|
+
readonly logger?: Logger;
|
|
42
46
|
}): Promise<TResult extends void ? void : Readonly<TResult>> {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
47
|
+
const trackingService = getTrackingService();
|
|
48
|
+
const logger = data.logger ?? getDefaultLogger();
|
|
49
|
+
|
|
50
|
+
const event = await runTrackingFuncWithErrorHadlingAsync({
|
|
51
|
+
func: async () => {
|
|
52
|
+
return await trackingService.trackEventAsync(data.event);
|
|
53
|
+
},
|
|
54
|
+
logger: logger,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const result = await data.func();
|
|
59
|
+
|
|
60
|
+
if (event) {
|
|
61
|
+
await runTrackingFuncWithErrorHadlingAsync({
|
|
62
|
+
func: async () => {
|
|
63
|
+
await trackingService.setEventResultAsync({
|
|
64
|
+
eventId: event.eventId,
|
|
65
|
+
result: "success",
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
logger: logger,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return result;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (event) {
|
|
75
|
+
await runTrackingFuncWithErrorHadlingAsync({
|
|
76
|
+
func: async () => {
|
|
77
|
+
await trackingService.setEventResultAsync({
|
|
78
|
+
eventId: event.eventId,
|
|
79
|
+
result: "fail",
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
logger: logger,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
async function runTrackingFuncWithErrorHadlingAsync<T>(data: {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}): Promise<T |
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
readonly func: () => Promise<T>;
|
|
92
|
+
readonly logger: Logger;
|
|
93
|
+
}): Promise<T | undefined> {
|
|
94
|
+
try {
|
|
95
|
+
return await data.func();
|
|
96
|
+
} catch (trackingError) {
|
|
97
|
+
data.logger.log({
|
|
98
|
+
message: `Failed to track event. ${extractErrorData(trackingError).message}`,
|
|
99
|
+
type: "warning",
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
98
104
|
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import type { IRetryStrategyOptions } from
|
|
2
|
-
import { HttpService } from
|
|
3
|
-
import { match } from
|
|
4
|
-
import type { OriginalManagementError } from
|
|
1
|
+
import type { IRetryStrategyOptions } from "@kontent-ai/core-sdk";
|
|
2
|
+
import { HttpService } from "@kontent-ai/core-sdk";
|
|
3
|
+
import { match } from "ts-pattern";
|
|
4
|
+
import type { OriginalManagementError } from "../models/core.models.js";
|
|
5
5
|
|
|
6
6
|
const rateExceededErrorCode: number = 10000;
|
|
7
7
|
|
|
8
8
|
export const defaultHttpService: Readonly<HttpService> = new HttpService({
|
|
9
|
-
|
|
9
|
+
logErrorsToConsole: false,
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
export const defaultRetryStrategy: Readonly<IRetryStrategyOptions> = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
addJitter: true,
|
|
14
|
+
canRetryError: (err) => {
|
|
15
|
+
const originalError = err as OriginalManagementError | undefined;
|
|
16
|
+
const errorCode: number = originalError?.response?.data?.error_code ?? -1;
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
return (
|
|
19
|
+
match(errorCode)
|
|
20
|
+
// retry rate exceeded error
|
|
21
|
+
.with(rateExceededErrorCode, () => true)
|
|
22
|
+
// if error code is set, do not retry the request
|
|
23
|
+
.when(
|
|
24
|
+
(errorCode) => errorCode >= 0,
|
|
25
|
+
() => false,
|
|
26
|
+
)
|
|
27
|
+
.otherwise(() => true)
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
maxAttempts: 3,
|
|
31
|
+
deltaBackoffMs: 1000,
|
|
32
32
|
};
|
|
@@ -1,196 +1,199 @@
|
|
|
1
|
-
import type { IRetryStrategyOptions } from
|
|
1
|
+
import type { IRetryStrategyOptions } from "@kontent-ai/core-sdk";
|
|
2
2
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from
|
|
13
|
-
import { createManagementClient } from
|
|
14
|
-
import chalk from
|
|
15
|
-
import { coreConfig } from
|
|
16
|
-
import type { FlattenedContentType, FlattenedContentTypeElement } from
|
|
17
|
-
import type {
|
|
18
|
-
import { findRequired } from
|
|
19
|
-
import { isNotUndefined } from
|
|
20
|
-
import { defaultHttpService, defaultRetryStrategy } from
|
|
21
|
-
import { runMapiRequestAsync } from
|
|
3
|
+
AssetFolderModels,
|
|
4
|
+
CollectionModels,
|
|
5
|
+
ContentTypeModels,
|
|
6
|
+
ContentTypeSnippetModels,
|
|
7
|
+
EnvironmentModels,
|
|
8
|
+
LanguageModels,
|
|
9
|
+
ManagementClient,
|
|
10
|
+
TaxonomyModels,
|
|
11
|
+
WorkflowModels,
|
|
12
|
+
} from "@kontent-ai/management-sdk";
|
|
13
|
+
import { createManagementClient } from "@kontent-ai/management-sdk";
|
|
14
|
+
import chalk from "chalk";
|
|
15
|
+
import { coreConfig } from "../config.js";
|
|
16
|
+
import type { FlattenedContentType, FlattenedContentTypeElement } from "../models/core.models.js";
|
|
17
|
+
import type { Logger, LogSpinnerData } from "../models/log.models.js";
|
|
18
|
+
import { findRequired } from "./array.utils.js";
|
|
19
|
+
import { isNotUndefined } from "./global.utils.js";
|
|
20
|
+
import { defaultHttpService, defaultRetryStrategy } from "./http.utils.js";
|
|
21
|
+
import { runMapiRequestAsync } from "./run.utils.js";
|
|
22
22
|
|
|
23
23
|
export interface ManagementClientConfig {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
readonly environmentId: string;
|
|
25
|
+
readonly apiKey: string;
|
|
26
|
+
readonly retryStrategy?: Readonly<IRetryStrategyOptions>;
|
|
27
|
+
readonly baseUrl?: string;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function getMigrationManagementClient(config: ManagementClientConfig): Readonly<ManagementClient> {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
return createManagementClient({
|
|
32
|
+
environmentId: config.environmentId,
|
|
33
|
+
retryStrategy: config.retryStrategy ?? defaultRetryStrategy,
|
|
34
|
+
httpService: defaultHttpService,
|
|
35
|
+
apiKey: config.apiKey,
|
|
36
|
+
baseUrl: config.baseUrl,
|
|
37
|
+
headers: [
|
|
38
|
+
{
|
|
39
|
+
header: coreConfig.kontentTrackingHeaderName,
|
|
40
|
+
value: coreConfig.kontentTrackingHeaderValue,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export function managementClientUtils(client: Readonly<ManagementClient>, logger: Logger) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
47
|
+
const getEnvironmentAsync = async (): Promise<EnvironmentModels.EnvironmentInformationModel> => {
|
|
48
|
+
return (await client.environmentInformation().toPromise()).data.project;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const getAllLanguagesAsync = async (logSpinner: LogSpinnerData): Promise<readonly LanguageModels.LanguageModel[]> => {
|
|
52
|
+
return await runMapiRequestAsync({
|
|
53
|
+
logSpinner: logSpinner,
|
|
54
|
+
logger: logger,
|
|
55
|
+
func: async () => (await client.listLanguages().toAllPromise()).data.items,
|
|
56
|
+
action: "list",
|
|
57
|
+
type: "language",
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const getAllCollectionsAsync = async (logSpinner: LogSpinnerData): Promise<readonly CollectionModels.Collection[]> => {
|
|
62
|
+
return await runMapiRequestAsync({
|
|
63
|
+
logger: logger,
|
|
64
|
+
logSpinner: logSpinner,
|
|
65
|
+
func: async () => (await client.listCollections().toPromise()).data.collections,
|
|
66
|
+
action: "list",
|
|
67
|
+
type: "collection",
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const getAllWorkflowsAsync = async (logSpinner: LogSpinnerData): Promise<readonly WorkflowModels.Workflow[]> => {
|
|
72
|
+
return await runMapiRequestAsync({
|
|
73
|
+
logger: logger,
|
|
74
|
+
logSpinner: logSpinner,
|
|
75
|
+
func: async () => (await client.listWorkflows().toPromise()).data,
|
|
76
|
+
action: "list",
|
|
77
|
+
type: "workflow",
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const getAllTaxonomiesAsync = async (logSpinner: LogSpinnerData): Promise<readonly TaxonomyModels.Taxonomy[]> => {
|
|
82
|
+
return await runMapiRequestAsync({
|
|
83
|
+
logger: logger,
|
|
84
|
+
logSpinner: logSpinner,
|
|
85
|
+
func: async () => (await client.listTaxonomies().toAllPromise()).data.items,
|
|
86
|
+
action: "list",
|
|
87
|
+
type: "taxonomy",
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const getAllAssetFoldersAsync = async (logSpinner: LogSpinnerData): Promise<readonly AssetFolderModels.AssetFolder[]> => {
|
|
92
|
+
return await runMapiRequestAsync({
|
|
93
|
+
logger: logger,
|
|
94
|
+
logSpinner: logSpinner,
|
|
95
|
+
func: async () => (await client.listAssetFolders().toPromise()).data.items,
|
|
96
|
+
action: "list",
|
|
97
|
+
type: "assetFolder",
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const getContentTypeElements = (
|
|
102
|
+
contentType: ContentTypeModels.ContentType,
|
|
103
|
+
contentTypeSnippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[],
|
|
104
|
+
): readonly FlattenedContentTypeElement[] => {
|
|
105
|
+
return contentType.elements
|
|
106
|
+
.flatMap((element) => {
|
|
107
|
+
if (!(element.codename && element.id)) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (element.type === "guidelines") {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (element.type === "snippet") {
|
|
116
|
+
const snippetElement = element;
|
|
117
|
+
|
|
118
|
+
// replace snippet element with actual elements
|
|
119
|
+
const contentTypeSnippet = findRequired(
|
|
120
|
+
contentTypeSnippets,
|
|
121
|
+
(snippet) => snippet.id === snippetElement.snippet.id,
|
|
122
|
+
`Could not find content type snippet for element. This snippet is referenced in type '${chalk.red(
|
|
123
|
+
contentType.codename,
|
|
124
|
+
)}'`,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
return contentTypeSnippet.elements.map((snippetElement) => {
|
|
128
|
+
if (snippetElement.type === "guidelines" || snippetElement.type === "snippet") {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
if (!(snippetElement.codename && snippetElement.id)) {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const flattenedElement: FlattenedContentTypeElement = {
|
|
136
|
+
codename: snippetElement.codename,
|
|
137
|
+
name: snippetElement.name,
|
|
138
|
+
type: snippetElement.type,
|
|
139
|
+
id: snippetElement.id,
|
|
140
|
+
element: snippetElement,
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
return flattenedElement;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
const flattenedElement: FlattenedContentTypeElement = {
|
|
147
|
+
codename: element.codename,
|
|
148
|
+
name: element.name,
|
|
149
|
+
id: element.id,
|
|
150
|
+
type: element.type,
|
|
151
|
+
element: element,
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
return flattenedElement;
|
|
155
|
+
})
|
|
156
|
+
.filter(isNotUndefined);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const getFlattenedContentTypesAsync = async (logSpinner: LogSpinnerData): Promise<readonly FlattenedContentType[]> => {
|
|
160
|
+
const contentTypes = await runMapiRequestAsync({
|
|
161
|
+
logger: logger,
|
|
162
|
+
logSpinner: logSpinner,
|
|
163
|
+
func: async () => (await client.listContentTypes().toAllPromise()).data.items,
|
|
164
|
+
action: "list",
|
|
165
|
+
type: "contentType",
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const contentTypeSnippets = await runMapiRequestAsync({
|
|
169
|
+
logger: logger,
|
|
170
|
+
logSpinner: logSpinner,
|
|
171
|
+
func: async () => (await client.listContentTypeSnippets().toAllPromise()).data.items,
|
|
172
|
+
action: "list",
|
|
173
|
+
type: "contentTypeSnippet",
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return [
|
|
177
|
+
...contentTypes.map((contentType) => {
|
|
178
|
+
const importType: FlattenedContentType = {
|
|
179
|
+
name: contentType.name,
|
|
180
|
+
contentTypeCodename: contentType.codename,
|
|
181
|
+
contentTypeId: contentType.id,
|
|
182
|
+
elements: getContentTypeElements(contentType, contentTypeSnippets),
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
return importType;
|
|
186
|
+
}),
|
|
187
|
+
];
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
getAllCollectionsAsync,
|
|
192
|
+
getAllLanguagesAsync,
|
|
193
|
+
getAllWorkflowsAsync,
|
|
194
|
+
getAllTaxonomiesAsync,
|
|
195
|
+
getFlattenedContentTypesAsync,
|
|
196
|
+
getEnvironmentAsync,
|
|
197
|
+
getAllAssetFoldersAsync,
|
|
198
|
+
};
|
|
196
199
|
}
|