@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,392 +1,397 @@
|
|
|
1
|
-
import type { LanguageVariantModels, ManagementClient, WorkflowModels } from
|
|
2
|
-
import { SharedModels } from
|
|
3
|
-
import { match } from
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
1
|
+
import type { LanguageVariantModels, ManagementClient, WorkflowModels } from "@kontent-ai/management-sdk";
|
|
2
|
+
import { SharedModels } from "@kontent-ai/management-sdk";
|
|
3
|
+
import { match } from "ts-pattern";
|
|
4
|
+
import { type ShortestPathResult, type WorkflowStep, workflowHelper as workflowHelperInit } from "../../core/helpers/workflow-helper.js";
|
|
5
|
+
import type { Logger, LogSpinnerData } from "../../core/models/log.models.js";
|
|
6
|
+
import type { MigrationItem, MigrationItemVersion } from "../../core/models/migration.models.js";
|
|
7
|
+
import { runMapiRequestAsync } from "../../core/utils/run.utils.js";
|
|
6
8
|
|
|
7
9
|
export function workflowImporter(config: {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
readonly logger: Logger;
|
|
11
|
+
readonly managementClient: Readonly<ManagementClient>;
|
|
12
|
+
readonly workflows: readonly Readonly<WorkflowModels.Workflow>[];
|
|
11
13
|
}) {
|
|
12
|
-
|
|
14
|
+
const workflowHelper = workflowHelperInit(config.workflows);
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
16
|
+
const publishLanguageVariantAsync = async (data: {
|
|
17
|
+
readonly logSpinner: LogSpinnerData;
|
|
18
|
+
readonly migrationItem: MigrationItem;
|
|
19
|
+
readonly languageVariant: Readonly<LanguageVariantModels.ContentItemLanguageVariant>;
|
|
20
|
+
readonly workflowCodename: string;
|
|
21
|
+
readonly stepCodename: string;
|
|
22
|
+
}): Promise<void> => {
|
|
23
|
+
await runMapiRequestAsync({
|
|
24
|
+
logger: config.logger,
|
|
25
|
+
func: async () =>
|
|
26
|
+
(
|
|
27
|
+
await config.managementClient
|
|
28
|
+
.publishLanguageVariant()
|
|
29
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
30
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
31
|
+
.withoutData()
|
|
32
|
+
.toPromise()
|
|
33
|
+
).data,
|
|
34
|
+
action: "publish",
|
|
35
|
+
type: "languageVariant",
|
|
36
|
+
logSpinner: data.logSpinner,
|
|
37
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename})`,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
const getPreviousToPublishStep = (
|
|
42
|
+
workflow: Readonly<WorkflowModels.Workflow>,
|
|
43
|
+
variantStep: WorkflowStep,
|
|
44
|
+
publishStep: WorkflowStep,
|
|
45
|
+
): ShortestPathResult | undefined => {
|
|
46
|
+
const steps = workflowHelper.findShortestPathBetweenSteps(workflow, variantStep, publishStep);
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
if (steps.length < 2) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return steps[steps.length - 2];
|
|
52
|
+
};
|
|
48
53
|
|
|
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
|
-
|
|
54
|
+
const unpublishLanguageVariantAsync = async (data: {
|
|
55
|
+
readonly logSpinner: LogSpinnerData;
|
|
56
|
+
readonly migrationItem: MigrationItem;
|
|
57
|
+
}): Promise<void> => {
|
|
58
|
+
// unpublish the language variant first if published
|
|
59
|
+
// there is no way to determine if language variant is published via MAPI
|
|
60
|
+
// so we have to always try unpublishing first and catching possible errors
|
|
61
|
+
try {
|
|
62
|
+
await runMapiRequestAsync({
|
|
63
|
+
logger: config.logger,
|
|
64
|
+
func: async () =>
|
|
65
|
+
(
|
|
66
|
+
await config.managementClient
|
|
67
|
+
.unpublishLanguageVariant()
|
|
68
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
69
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
70
|
+
.withoutData()
|
|
71
|
+
.toPromise()
|
|
72
|
+
).data,
|
|
73
|
+
action: "unpublish",
|
|
74
|
+
type: "languageVariant",
|
|
75
|
+
logSpinner: data.logSpinner,
|
|
76
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename})`,
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error instanceof SharedModels.ContentManagementBaseKontentError) {
|
|
80
|
+
data.logSpinner({
|
|
81
|
+
type: "unpublish",
|
|
82
|
+
message: `Unpublish failed, but this may be expected behavior as we cannot determine if there is a published version already. Error received: ${error.message}`,
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
84
89
|
|
|
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
|
-
|
|
90
|
+
const schedulePublishLanguageVariantAsync = async (data: {
|
|
91
|
+
readonly logSpinner: LogSpinnerData;
|
|
92
|
+
readonly migrationItem: MigrationItem;
|
|
93
|
+
readonly schedule: {
|
|
94
|
+
readonly publish_time: string;
|
|
95
|
+
readonly publish_display_timezone: string;
|
|
96
|
+
};
|
|
97
|
+
}): Promise<void> => {
|
|
98
|
+
await runMapiRequestAsync({
|
|
99
|
+
logger: config.logger,
|
|
100
|
+
func: async () =>
|
|
101
|
+
(
|
|
102
|
+
await config.managementClient
|
|
103
|
+
.publishLanguageVariant()
|
|
104
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
105
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
106
|
+
.withData({
|
|
107
|
+
scheduled_to: data.schedule.publish_time,
|
|
108
|
+
display_timezone: data.schedule.publish_display_timezone,
|
|
109
|
+
})
|
|
110
|
+
.toPromise()
|
|
111
|
+
).data,
|
|
112
|
+
action: "schedulePublish",
|
|
113
|
+
type: "languageVariant",
|
|
114
|
+
logSpinner: data.logSpinner,
|
|
115
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename})`,
|
|
116
|
+
});
|
|
117
|
+
};
|
|
113
118
|
|
|
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
|
-
|
|
119
|
+
const scheduleUnpublishLanguageVariantAsync = async (data: {
|
|
120
|
+
readonly logSpinner: LogSpinnerData;
|
|
121
|
+
readonly migrationItem: MigrationItem;
|
|
122
|
+
readonly schedule: {
|
|
123
|
+
readonly unpublish_time: string;
|
|
124
|
+
readonly unpublish_display_timezone: string;
|
|
125
|
+
};
|
|
126
|
+
}): Promise<void> => {
|
|
127
|
+
await runMapiRequestAsync({
|
|
128
|
+
logger: config.logger,
|
|
129
|
+
func: async () =>
|
|
130
|
+
(
|
|
131
|
+
await config.managementClient
|
|
132
|
+
.unpublishLanguageVariant()
|
|
133
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
134
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
135
|
+
.withData({
|
|
136
|
+
scheduled_to: data.schedule.unpublish_time,
|
|
137
|
+
display_timezone: data.schedule.unpublish_display_timezone,
|
|
138
|
+
})
|
|
139
|
+
.toPromise()
|
|
140
|
+
).data,
|
|
141
|
+
action: "scheduleUnpublish",
|
|
142
|
+
type: "languageVariant",
|
|
143
|
+
logSpinner: data.logSpinner,
|
|
144
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename})`,
|
|
145
|
+
});
|
|
146
|
+
};
|
|
142
147
|
|
|
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
|
-
|
|
148
|
+
const archiveLanguageVariantAsync = async (data: {
|
|
149
|
+
readonly logSpinner: LogSpinnerData;
|
|
150
|
+
readonly workflowCodename: string;
|
|
151
|
+
readonly migrationItem: MigrationItem;
|
|
152
|
+
}): Promise<void> => {
|
|
153
|
+
const workflow = workflowHelper.getWorkflowByCodename(data.workflowCodename);
|
|
154
|
+
await runMapiRequestAsync({
|
|
155
|
+
logger: config.logger,
|
|
156
|
+
func: async () =>
|
|
157
|
+
(
|
|
158
|
+
await config.managementClient
|
|
159
|
+
.changeWorkflowOfLanguageVariant()
|
|
160
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
161
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
162
|
+
.withData({
|
|
163
|
+
step_identifier: {
|
|
164
|
+
codename: workflow.archivedStep.codename,
|
|
165
|
+
},
|
|
166
|
+
workflow_identifier: {
|
|
167
|
+
codename: workflow.codename,
|
|
168
|
+
},
|
|
169
|
+
})
|
|
170
|
+
.toPromise()
|
|
171
|
+
).data,
|
|
172
|
+
action: "archive",
|
|
173
|
+
type: "languageVariant",
|
|
174
|
+
logSpinner: data.logSpinner,
|
|
175
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename}) -> ${workflow.archivedStep.codename}`,
|
|
176
|
+
});
|
|
177
|
+
};
|
|
173
178
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
179
|
+
const changeWorkflowOfLanguageVariantAsync = async (data: {
|
|
180
|
+
readonly logSpinner: LogSpinnerData;
|
|
181
|
+
readonly workflowCodename: string;
|
|
182
|
+
readonly stepCodename: string;
|
|
183
|
+
readonly migrationItem: MigrationItem;
|
|
184
|
+
}): Promise<void> => {
|
|
185
|
+
const { workflow, step } = workflowHelper.getWorkflowAndStepByCodenames({
|
|
186
|
+
workflowCodename: data.workflowCodename,
|
|
187
|
+
stepCodename: data.stepCodename,
|
|
188
|
+
});
|
|
184
189
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
190
|
+
await runMapiRequestAsync({
|
|
191
|
+
logger: config.logger,
|
|
192
|
+
func: async () =>
|
|
193
|
+
(
|
|
194
|
+
await config.managementClient
|
|
195
|
+
.changeWorkflowOfLanguageVariant()
|
|
196
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
197
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
198
|
+
.withData({
|
|
199
|
+
step_identifier: {
|
|
200
|
+
codename: step.codename,
|
|
201
|
+
},
|
|
202
|
+
workflow_identifier: {
|
|
203
|
+
codename: workflow.codename,
|
|
204
|
+
},
|
|
205
|
+
})
|
|
206
|
+
.toPromise()
|
|
207
|
+
).data,
|
|
208
|
+
action: "changeWorkflowStep",
|
|
209
|
+
type: "languageVariant",
|
|
210
|
+
logSpinner: data.logSpinner,
|
|
211
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename}) -> ${step.codename}`,
|
|
212
|
+
});
|
|
213
|
+
};
|
|
209
214
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
215
|
+
const createNewVersionOfLanguageVariantAsync = async (data: {
|
|
216
|
+
readonly logSpinner: LogSpinnerData;
|
|
217
|
+
readonly migrationItem: MigrationItem;
|
|
218
|
+
}): Promise<void> => {
|
|
219
|
+
await runMapiRequestAsync({
|
|
220
|
+
logger: config.logger,
|
|
221
|
+
func: async () => {
|
|
222
|
+
await config.managementClient
|
|
223
|
+
.createNewVersionOfLanguageVariant()
|
|
224
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
225
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
226
|
+
.toPromise();
|
|
227
|
+
},
|
|
228
|
+
action: "createNewVersion",
|
|
229
|
+
type: "languageVariant",
|
|
230
|
+
logSpinner: data.logSpinner,
|
|
231
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename})`,
|
|
232
|
+
});
|
|
233
|
+
};
|
|
229
234
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
235
|
+
const cancelScheduledPublishAsync = async (data: {
|
|
236
|
+
readonly logSpinner: LogSpinnerData;
|
|
237
|
+
readonly migrationItem: MigrationItem;
|
|
238
|
+
}): Promise<void> => {
|
|
239
|
+
await runMapiRequestAsync({
|
|
240
|
+
logger: config.logger,
|
|
241
|
+
func: async () => {
|
|
242
|
+
await config.managementClient
|
|
243
|
+
.cancelSheduledPublishingOfLanguageVariant()
|
|
244
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
245
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
246
|
+
.toPromise();
|
|
247
|
+
},
|
|
248
|
+
action: "cancelScheduledPublish",
|
|
249
|
+
type: "languageVariant",
|
|
250
|
+
logSpinner: data.logSpinner,
|
|
251
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename}) -> Cancel scheduled publish`,
|
|
252
|
+
});
|
|
253
|
+
};
|
|
249
254
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
255
|
+
const cancelScheduledUnpublishAsync = async (data: {
|
|
256
|
+
readonly logSpinner: LogSpinnerData;
|
|
257
|
+
readonly migrationItem: MigrationItem;
|
|
258
|
+
}): Promise<void> => {
|
|
259
|
+
await runMapiRequestAsync({
|
|
260
|
+
logger: config.logger,
|
|
261
|
+
func: async () => {
|
|
262
|
+
await config.managementClient
|
|
263
|
+
.cancelSheduledUnpublishingOfLanguageVariant()
|
|
264
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
265
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
266
|
+
.toPromise();
|
|
267
|
+
},
|
|
268
|
+
action: "cancelScheduledUnpublish",
|
|
269
|
+
type: "languageVariant",
|
|
270
|
+
logSpinner: data.logSpinner,
|
|
271
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename}) -> Cancel scheduled unpublish`,
|
|
272
|
+
});
|
|
273
|
+
};
|
|
269
274
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
275
|
+
const moveToDraftStepAsync = async (data: {
|
|
276
|
+
readonly logSpinner: LogSpinnerData;
|
|
277
|
+
readonly migrationItem: MigrationItem;
|
|
278
|
+
}): Promise<void> => {
|
|
279
|
+
const workflow = workflowHelper.getWorkflowByCodename(data.migrationItem.system.workflow.codename);
|
|
280
|
+
const firstWorkflowStep = workflow.steps.length ? workflow.steps[0] : undefined;
|
|
276
281
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
282
|
+
if (firstWorkflowStep) {
|
|
283
|
+
await runMapiRequestAsync({
|
|
284
|
+
logger: config.logger,
|
|
285
|
+
func: async () => {
|
|
286
|
+
await config.managementClient
|
|
287
|
+
.changeWorkflowOfLanguageVariant()
|
|
288
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
289
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
290
|
+
.withData({
|
|
291
|
+
workflow_identifier: {
|
|
292
|
+
codename: workflow.codename,
|
|
293
|
+
},
|
|
294
|
+
step_identifier: {
|
|
295
|
+
codename: firstWorkflowStep.codename,
|
|
296
|
+
},
|
|
297
|
+
})
|
|
298
|
+
.toPromise();
|
|
299
|
+
},
|
|
300
|
+
action: "changeWorkflowStep",
|
|
301
|
+
type: "languageVariant",
|
|
302
|
+
logSpinner: data.logSpinner,
|
|
303
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename}) -> ${firstWorkflowStep.codename}`,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
};
|
|
302
307
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
308
|
+
const setScheduledStateOfLanguageVariantAsync = async (data: {
|
|
309
|
+
readonly logSpinner: LogSpinnerData;
|
|
310
|
+
readonly migrationItem: MigrationItem;
|
|
311
|
+
readonly migrationItemVersion: MigrationItemVersion;
|
|
312
|
+
}): Promise<void> => {
|
|
313
|
+
if (!data.migrationItemVersion.schedule) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
311
316
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
317
|
+
// set scheduling
|
|
318
|
+
if (data.migrationItemVersion.schedule.unpublish_time && data.migrationItemVersion.schedule.unpublish_display_timezone) {
|
|
319
|
+
await scheduleUnpublishLanguageVariantAsync({
|
|
320
|
+
logSpinner: data.logSpinner,
|
|
321
|
+
migrationItem: data.migrationItem,
|
|
322
|
+
schedule: {
|
|
323
|
+
unpublish_time: data.migrationItemVersion.schedule.unpublish_time,
|
|
324
|
+
unpublish_display_timezone: data.migrationItemVersion.schedule.unpublish_display_timezone,
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
}
|
|
323
328
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
329
|
+
if (data.migrationItemVersion.schedule.publish_time && data.migrationItemVersion.schedule.publish_display_timezone) {
|
|
330
|
+
await schedulePublishLanguageVariantAsync({
|
|
331
|
+
logSpinner: data.logSpinner,
|
|
332
|
+
migrationItem: data.migrationItem,
|
|
333
|
+
schedule: {
|
|
334
|
+
publish_time: data.migrationItemVersion.schedule.publish_time,
|
|
335
|
+
publish_display_timezone: data.migrationItemVersion.schedule.publish_display_timezone,
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
};
|
|
335
340
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
341
|
+
const setWorkflowOfLanguageVariantAsync = async (data: {
|
|
342
|
+
readonly logSpinner: LogSpinnerData;
|
|
343
|
+
readonly workflowCodename: string;
|
|
344
|
+
readonly stepCodename: string;
|
|
345
|
+
readonly migrationItem: MigrationItem;
|
|
346
|
+
readonly migrationItemVersion: MigrationItemVersion;
|
|
347
|
+
readonly languageVariant: Readonly<LanguageVariantModels.ContentItemLanguageVariant>;
|
|
348
|
+
}): Promise<void> => {
|
|
349
|
+
return await match(data.stepCodename)
|
|
350
|
+
.returnType<Promise<void>>()
|
|
351
|
+
.when(
|
|
352
|
+
(stepCodename) => workflowHelper.isPublishedStepByCodename(stepCodename),
|
|
353
|
+
async () => {
|
|
354
|
+
const { workflow, step: publishStep } = workflowHelper.getWorkflowAndStepByCodenames({
|
|
355
|
+
workflowCodename: data.workflowCodename,
|
|
356
|
+
stepCodename: data.stepCodename,
|
|
357
|
+
});
|
|
358
|
+
const variantStep = workflowHelper.getWorkflowStepById(
|
|
359
|
+
workflow,
|
|
360
|
+
data.languageVariant.workflow.stepIdentifier.id as string,
|
|
361
|
+
);
|
|
362
|
+
const previousToPublishStep = getPreviousToPublishStep(workflow, variantStep, publishStep);
|
|
358
363
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
364
|
+
if (previousToPublishStep) {
|
|
365
|
+
await changeWorkflowOfLanguageVariantAsync({ ...data, stepCodename: previousToPublishStep.stepCodename });
|
|
366
|
+
}
|
|
362
367
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
368
|
+
await publishLanguageVariantAsync(data);
|
|
369
|
+
},
|
|
370
|
+
)
|
|
371
|
+
.when(
|
|
372
|
+
(stepCodename) => workflowHelper.isArchivedStepByCodename(stepCodename),
|
|
373
|
+
async () => await archiveLanguageVariantAsync(data),
|
|
374
|
+
)
|
|
375
|
+
.when(
|
|
376
|
+
(stepCodename) => workflowHelper.isScheduledStepByCodename(stepCodename),
|
|
377
|
+
async () => {
|
|
378
|
+
// do nothing for scheduled step
|
|
379
|
+
return await Promise.resolve();
|
|
380
|
+
},
|
|
381
|
+
)
|
|
382
|
+
.otherwise(async () => await changeWorkflowOfLanguageVariantAsync(data));
|
|
383
|
+
};
|
|
379
384
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
385
|
+
return {
|
|
386
|
+
setScheduledStateOfLanguageVariantAsync,
|
|
387
|
+
setWorkflowOfLanguageVariantAsync,
|
|
388
|
+
publishLanguageVariantAsync,
|
|
389
|
+
unpublishLanguageVariantAsync,
|
|
390
|
+
archiveLanguageVariantAsync,
|
|
391
|
+
changeWorkflowOfLanguageVariantAsync,
|
|
392
|
+
moveToDraftStepAsync,
|
|
393
|
+
createNewVersionOfLanguageVariantAsync,
|
|
394
|
+
cancelScheduledPublishAsync,
|
|
395
|
+
cancelScheduledUnpublishAsync,
|
|
396
|
+
};
|
|
392
397
|
}
|