@kontent-ai/migration-toolkit 1.4.0 → 1.5.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 +1 -4
- package/dist/es2022/core/helpers/workflow-helper.d.ts +1 -0
- package/dist/es2022/core/helpers/workflow-helper.js +6 -4
- package/dist/es2022/core/helpers/workflow-helper.js.map +1 -1
- package/dist/es2022/core/logs/loggers.js +13 -22
- package/dist/es2022/core/logs/loggers.js.map +1 -1
- package/dist/es2022/core/models/core.models.d.ts +16 -6
- package/dist/es2022/core/models/migration.schema.d.ts +247 -0
- package/dist/es2022/core/models/migration.schema.js +12 -2
- package/dist/es2022/core/models/migration.schema.js.map +1 -1
- package/dist/es2022/core/utils/array.utils.js.map +1 -1
- package/dist/es2022/core/utils/binary-data.utils.js +2 -6
- package/dist/es2022/core/utils/binary-data.utils.js.map +1 -1
- package/dist/es2022/core/utils/confirm.utils.js +10 -14
- package/dist/es2022/core/utils/confirm.utils.js.map +1 -1
- package/dist/es2022/core/utils/error.utils.js +35 -27
- package/dist/es2022/core/utils/error.utils.js.map +1 -1
- package/dist/es2022/core/utils/http.utils.js +7 -11
- package/dist/es2022/core/utils/http.utils.js.map +1 -1
- package/dist/es2022/core/utils/management-client-utils.d.ts +2 -1
- package/dist/es2022/core/utils/management-client-utils.js +11 -1
- package/dist/es2022/core/utils/management-client-utils.js.map +1 -1
- package/dist/es2022/core/utils/run.utils.js +12 -10
- package/dist/es2022/core/utils/run.utils.js.map +1 -1
- package/dist/es2022/export/context/export-context-fetcher.js +2 -1
- package/dist/es2022/export/context/export-context-fetcher.js.map +1 -1
- package/dist/es2022/export/export-manager.js +8 -0
- package/dist/es2022/export/export-manager.js.map +1 -1
- package/dist/es2022/export/export.models.d.ts +2 -1
- package/dist/es2022/import/comparers/asset-comparer.d.ts +2 -1
- package/dist/es2022/import/comparers/asset-comparer.js +9 -17
- package/dist/es2022/import/comparers/asset-comparer.js.map +1 -1
- package/dist/es2022/import/context/import-context-fetcher.js +120 -40
- package/dist/es2022/import/context/import-context-fetcher.js.map +1 -1
- package/dist/es2022/import/import.models.d.ts +2 -1
- package/dist/es2022/import/importers/assets-importer.js +25 -7
- package/dist/es2022/import/importers/assets-importer.js.map +1 -1
- package/dist/es2022/import/importers/language-variant-importer.js +95 -87
- package/dist/es2022/import/importers/language-variant-importer.js.map +1 -1
- package/dist/es2022/import/importers/workflow-importer.d.ts +41 -4
- package/dist/es2022/import/importers/workflow-importer.js +158 -17
- package/dist/es2022/import/importers/workflow-importer.js.map +1 -1
- package/dist/es2022/metadata.js +2 -2
- package/dist/es2022/node/cli/app.js +8 -12
- package/dist/es2022/node/cli/app.js.map +1 -1
- package/dist/es2022/node/cli/args/args-fetcher.js +9 -10
- package/dist/es2022/node/cli/args/args-fetcher.js.map +1 -1
- package/dist/es2022/toolkit/migrate.d.ts +1 -3
- package/dist/es2022/toolkit/migrate.js.map +1 -1
- package/dist/es2022/translation/extraction/items-extraction.processor.js +17 -17
- package/dist/es2022/translation/extraction/items-extraction.processor.js.map +1 -1
- package/dist/es2022/zip/zip-packager.js +13 -18
- package/dist/es2022/zip/zip-packager.js.map +1 -1
- package/dist/es2022/zip/zip-transformer.js +3 -1
- package/dist/es2022/zip/zip-transformer.js.map +1 -1
- package/lib/core/helpers/workflow-helper.ts +8 -8
- package/lib/core/logs/loggers.ts +14 -22
- package/lib/core/models/core.models.ts +23 -4
- package/lib/core/models/migration.schema.ts +13 -2
- package/lib/core/utils/array.utils.ts +2 -10
- package/lib/core/utils/binary-data.utils.ts +2 -7
- package/lib/core/utils/confirm.utils.ts +18 -24
- package/lib/core/utils/error.utils.ts +50 -30
- package/lib/core/utils/http.utils.ts +14 -15
- package/lib/core/utils/management-client-utils.ts +188 -176
- package/lib/core/utils/run.utils.ts +27 -18
- package/lib/export/context/export-context-fetcher.ts +2 -1
- package/lib/export/export-manager.ts +14 -3
- package/lib/export/export.models.ts +3 -1
- package/lib/import/comparers/asset-comparer.ts +16 -24
- package/lib/import/context/import-context-fetcher.ts +179 -85
- package/lib/import/import.models.ts +2 -0
- package/lib/import/importers/assets-importer.ts +41 -25
- package/lib/import/importers/language-variant-importer.ts +119 -111
- package/lib/import/importers/workflow-importer.ts +228 -20
- package/lib/metadata.ts +2 -2
- package/lib/node/cli/app.ts +11 -12
- package/lib/node/cli/args/args-fetcher.ts +12 -14
- package/lib/toolkit/migrate.ts +1 -3
- package/lib/translation/extraction/items-extraction.processor.ts +93 -93
- package/lib/zip/zip-packager.ts +26 -28
- package/lib/zip/zip-transformer.ts +3 -1
- package/package.json +13 -12
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { formatBytes, getCurrentEnvironment, exitProgram, getDefaultLogger } from '../core/index.js';
|
|
3
|
+
import { match } from 'ts-pattern';
|
|
3
4
|
export function zipPackager(jsZip) {
|
|
4
5
|
const getZipOutputType = () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return 'nodebuffer';
|
|
11
|
-
}
|
|
12
|
-
exitProgram({
|
|
13
|
-
message: `Unsupported context`
|
|
14
|
-
});
|
|
6
|
+
return match(getCurrentEnvironment())
|
|
7
|
+
.returnType()
|
|
8
|
+
.with('browser', () => 'blob')
|
|
9
|
+
.with('node', () => 'nodebuffer')
|
|
10
|
+
.exhaustive();
|
|
15
11
|
};
|
|
16
12
|
const getZipSizeInBytes = (zipData) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
message: `Unrecognized zip data type '${typeof zipData}'`
|
|
13
|
+
return match(zipData)
|
|
14
|
+
.when((data) => data instanceof Blob, (data) => data.size)
|
|
15
|
+
.when((data) => data instanceof Buffer, (data) => data.byteLength)
|
|
16
|
+
.otherwise(() => {
|
|
17
|
+
exitProgram({
|
|
18
|
+
message: `Unrecognized zip data type '${typeof zipData}'`
|
|
19
|
+
});
|
|
25
20
|
});
|
|
26
21
|
};
|
|
27
22
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zip-packager.js","sourceRoot":"","sources":["../../../lib/zip/zip-packager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAU,WAAW,EAAE,qBAAqB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"zip-packager.js","sourceRoot":"","sources":["../../../lib/zip/zip-packager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAU,WAAW,EAAE,qBAAqB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE7G,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAInC,MAAM,UAAU,WAAW,CAAC,KAAY;IACpC,MAAM,gBAAgB,GAAG,GAA0B,EAAE;QACjD,OAAO,KAAK,CAAC,qBAAqB,EAAE,CAAC;aAChC,UAAU,EAAiB;aAC3B,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC;aAC7B,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC;aAChC,UAAU,EAAE,CAAC;IACtB,CAAC,CAAC;IAEF,MAAM,iBAAiB,GAAG,CAAC,OAAuB,EAAU,EAAE;QAC1D,OAAO,KAAK,CAAC,OAAO,CAAC;aAChB,IAAI,CACD,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,YAAY,IAAI,EAC9B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CACtB;aACA,IAAI,CACD,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,YAAY,MAAM,EAChC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAC5B;aACA,SAAS,CAAC,GAAG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AAM,CAAC,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG;aAClG,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,KAAK,CAAC,kBAAkB,CAAC,QAAgB;YACrC,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC;YACzE,OAAO,UAAU,CAAC;QACtB,CAAC;QACD,KAAK,CAAC,mBAAmB,CAAC,QAAgB;YACtC,OAAO,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvD,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -28,7 +28,8 @@ export function zipTransformer(zip, logger) {
|
|
|
28
28
|
title: asset.title,
|
|
29
29
|
codename: asset.codename,
|
|
30
30
|
collection: asset.collection,
|
|
31
|
-
descriptions: asset.descriptions
|
|
31
|
+
descriptions: asset.descriptions,
|
|
32
|
+
folder: asset.folder
|
|
32
33
|
});
|
|
33
34
|
if (asset.binaryData) {
|
|
34
35
|
codenameFolder.addFile(asset.filename, asset.binaryData);
|
|
@@ -60,6 +61,7 @@ export function zipTransformer(zip, logger) {
|
|
|
60
61
|
collection: assetRecord.collection,
|
|
61
62
|
title: assetRecord.title,
|
|
62
63
|
descriptions: assetRecord.descriptions,
|
|
64
|
+
folder: assetRecord.folder,
|
|
63
65
|
binaryData: binaryFile
|
|
64
66
|
};
|
|
65
67
|
return migrationAsset;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zip-transformer.js","sourceRoot":"","sources":["../../../lib/zip/zip-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAKH,oBAAoB,EAEpB,wBAAwB,EACxB,gBAAgB,EAChB,QAAQ,EACX,MAAM,kBAAkB,CAAC;AAI1B,MAA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AE,CAAC,CAAC;QAC/D,CAAC;QACD,KAAK,CAAC,UAAU;YACZ,MAAM,KAAK,GAAG,MAAM,UAAU,EAAE,CAAC;YACjC,MAAM,MAAM,GAAG,MAAM,WAAW,EAAE,CAAC;YAEnC,MAAM,aAAa,GAAkB;gBACjC,MAAM,EAAE,MAAM;gBACd,KAAK,EAAE,KAAK;aACf,CAAC;YACF,OAAO,aAAa,CAAC;QACzB,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -33,18 +33,13 @@ export function workflowHelper(workflows: readonly Readonly<WorkflowModels.Workf
|
|
|
33
33
|
return getWorkflow({
|
|
34
34
|
errorMessage: [
|
|
35
35
|
`Workflow with codename '${chalk.red(workflowCodename)}' does not exist in target project`,
|
|
36
|
-
`Available workflows are (${workflows.length}): ${workflows
|
|
37
|
-
.map((m) => chalk.cyan(m.codename))
|
|
38
|
-
.join(', ')}`
|
|
36
|
+
`Available workflows are (${workflows.length}): ${workflows.map((m) => chalk.cyan(m.codename)).join(', ')}`
|
|
39
37
|
].join(', '),
|
|
40
38
|
match: (workflow) => workflow.codename.toLowerCase() === workflowCodename.toLowerCase()
|
|
41
39
|
});
|
|
42
40
|
};
|
|
43
41
|
|
|
44
|
-
const getWorkflowStepByCodename = (
|
|
45
|
-
workflow: Readonly<WorkflowModels.Workflow>,
|
|
46
|
-
stepCodename: string
|
|
47
|
-
): WorkflowStep => {
|
|
42
|
+
const getWorkflowStepByCodename = (workflow: Readonly<WorkflowModels.Workflow>, stepCodename: string): WorkflowStep => {
|
|
48
43
|
return getWorkflowStep(workflow, {
|
|
49
44
|
errorMessage: [
|
|
50
45
|
`Workflow step with codename '${chalk.red(stepCodename)}' does not exist in target project`,
|
|
@@ -90,6 +85,10 @@ export function workflowHelper(workflows: readonly Readonly<WorkflowModels.Workf
|
|
|
90
85
|
return workflows.find((workflow) => workflow.scheduledStep.codename === stepCodename) ? true : false;
|
|
91
86
|
};
|
|
92
87
|
|
|
88
|
+
const isPublishedStepById = (stepId: string): boolean => {
|
|
89
|
+
return workflows.find((workflow) => workflow.publishedStep.id === stepId) ? true : false;
|
|
90
|
+
};
|
|
91
|
+
|
|
93
92
|
return {
|
|
94
93
|
getWorkflowByCodename,
|
|
95
94
|
getWorkflowStepByCodename,
|
|
@@ -99,6 +98,7 @@ export function workflowHelper(workflows: readonly Readonly<WorkflowModels.Workf
|
|
|
99
98
|
getWorkflow,
|
|
100
99
|
isPublishedStepByCodename,
|
|
101
100
|
isArchivedStepByCodename,
|
|
102
|
-
isScheduledStepByCodename
|
|
101
|
+
isScheduledStepByCodename,
|
|
102
|
+
isPublishedStepById
|
|
103
103
|
};
|
|
104
104
|
}
|
package/lib/core/logs/loggers.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
1
|
+
import chalk, { ChalkInstance } from 'chalk';
|
|
2
2
|
import { Logger, LogSpinnerMessage } from '../models/log.models.js';
|
|
3
3
|
import { getCurrentEnvironment } from '../utils/global.utils.js';
|
|
4
|
+
import { match, P } from 'ts-pattern';
|
|
4
5
|
|
|
5
6
|
const originalWarn = console.warn;
|
|
6
7
|
|
|
7
8
|
export function getDefaultLogger(): Logger {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
if (currentEnv === 'browser') {
|
|
14
|
-
return defaultBrowserLogger;
|
|
15
|
-
}
|
|
16
|
-
throw Error(`Invalid environment`);
|
|
9
|
+
return match(getCurrentEnvironment())
|
|
10
|
+
.with('node', () => defaultNodeLogger)
|
|
11
|
+
.with('browser', () => defaultBrowserLogger)
|
|
12
|
+
.exhaustive();
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
const defaultNodeLogger: Logger = {
|
|
@@ -59,17 +55,13 @@ const defaultBrowserLogger: Logger = {
|
|
|
59
55
|
};
|
|
60
56
|
|
|
61
57
|
function getLogDataMessage(data: LogSpinnerMessage): string {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
typeColor = chalk.green;
|
|
70
|
-
} else if (data.type === 'skip') {
|
|
71
|
-
typeColor = chalk.gray;
|
|
72
|
-
}
|
|
58
|
+
const color = match(data.type)
|
|
59
|
+
.returnType<ChalkInstance>()
|
|
60
|
+
.with('info', () => chalk.cyan)
|
|
61
|
+
.with(P.union('error', 'errorData', 'warning', 'cancel'), () => chalk.red)
|
|
62
|
+
.with('completed', () => chalk.green)
|
|
63
|
+
.with('skip', () => chalk.gray)
|
|
64
|
+
.otherwise(() => chalk.yellow);
|
|
73
65
|
|
|
74
|
-
return `${
|
|
66
|
+
return `${color(data.type)}: ${data.message}`;
|
|
75
67
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AssetModels, ContentItemModels, ContentTypeElements, LanguageVariantModels, WorkflowModels } from '@kontent-ai/management-sdk';
|
|
2
2
|
import { MigrationElementType } from './migration.models.js';
|
|
3
|
-
import { WorkflowStep } from '../helpers/workflow-helper.js';
|
|
4
3
|
|
|
4
|
+
export type LiteralUnion<T extends string> = T | (string & {});
|
|
5
5
|
export type TargetItemState = 'exists' | 'doesNotExists';
|
|
6
6
|
export type CliAction = 'export' | 'import' | 'migrate';
|
|
7
7
|
export type EnvContext = 'browser' | 'node';
|
|
@@ -16,12 +16,17 @@ export type MapiAction =
|
|
|
16
16
|
| 'upload'
|
|
17
17
|
| 'create'
|
|
18
18
|
| 'upsert'
|
|
19
|
+
| 'schedulePublish'
|
|
20
|
+
| 'scheduleUnpublish'
|
|
21
|
+
| 'cancelScheduledPublish'
|
|
22
|
+
| 'cancelScheduledUnpublish'
|
|
19
23
|
| 'createNewVersion';
|
|
20
24
|
|
|
21
25
|
export type MigrationItemType = 'exportItem';
|
|
22
26
|
|
|
23
27
|
export type MapiType =
|
|
24
28
|
| 'contentType'
|
|
29
|
+
| 'assetFolder'
|
|
25
30
|
| 'asset'
|
|
26
31
|
| 'contentTypeSnippet'
|
|
27
32
|
| 'contentItem'
|
|
@@ -32,6 +37,15 @@ export type MapiType =
|
|
|
32
37
|
| 'binaryFile'
|
|
33
38
|
| 'workflow';
|
|
34
39
|
|
|
40
|
+
export type LanguageVariantWorkflowStateValues = 'published' | 'archived' | 'draft' | 'scheduled';
|
|
41
|
+
export type LanguageVariantSchedulesStateValues = 'scheduledPublish' | 'scheduledUnpublish' | 'n/a';
|
|
42
|
+
export type LanguageVariantWorkflowState =
|
|
43
|
+
| {
|
|
44
|
+
readonly workflowState: LanguageVariantWorkflowStateValues;
|
|
45
|
+
readonly scheduledState: LanguageVariantSchedulesStateValues;
|
|
46
|
+
}
|
|
47
|
+
| undefined;
|
|
48
|
+
|
|
35
49
|
export interface ItemInfo {
|
|
36
50
|
readonly title: string;
|
|
37
51
|
readonly itemType: MapiType | MigrationItemType;
|
|
@@ -74,13 +88,18 @@ export interface ItemStateInTargetEnvironmentByCodename {
|
|
|
74
88
|
readonly externalIdToUse: string;
|
|
75
89
|
}
|
|
76
90
|
|
|
91
|
+
export interface LanguageVariantStateData {
|
|
92
|
+
readonly languageVariant: Readonly<LanguageVariantModels.ContentItemLanguageVariant> | undefined;
|
|
93
|
+
readonly workflow: Readonly<WorkflowModels.Workflow> | undefined;
|
|
94
|
+
readonly workflowState: LanguageVariantWorkflowState;
|
|
95
|
+
}
|
|
96
|
+
|
|
77
97
|
export interface LanguageVariantStateInTargetEnvironmentByCodename {
|
|
78
98
|
readonly state: TargetItemState;
|
|
79
99
|
readonly itemCodename: string;
|
|
80
100
|
readonly languageCodename: string;
|
|
81
|
-
readonly
|
|
82
|
-
readonly
|
|
83
|
-
readonly step: Readonly<WorkflowStep> | undefined;
|
|
101
|
+
readonly publishedLanguageVariant: LanguageVariantStateData | undefined;
|
|
102
|
+
readonly draftLanguageVariant: LanguageVariantStateData | undefined;
|
|
84
103
|
}
|
|
85
104
|
|
|
86
105
|
export interface AssetStateInTargetEnvironmentByCodename {
|
|
@@ -69,6 +69,15 @@ export const MigrationReferenceSchema = z
|
|
|
69
69
|
})
|
|
70
70
|
.readonly();
|
|
71
71
|
|
|
72
|
+
export const ScheduleSchema = z
|
|
73
|
+
.strictObject({
|
|
74
|
+
publish_time: z.string().datetime().optional().readonly(),
|
|
75
|
+
publish_display_timezone: z.string().optional().readonly(),
|
|
76
|
+
unpublish_time: z.string().datetime().optional().readonly(),
|
|
77
|
+
unpublish_display_timezone: z.string().optional().readonly()
|
|
78
|
+
})
|
|
79
|
+
.readonly();
|
|
80
|
+
|
|
72
81
|
/**
|
|
73
82
|
* ZodType is needed to be specified here due to the use of 'lazy' & circular dependency between types
|
|
74
83
|
* Otherwise TS has no way of statically inferring the type
|
|
@@ -123,7 +132,8 @@ export const MigrationElementSchema = z
|
|
|
123
132
|
export const MigrationItemVersionSchema = z
|
|
124
133
|
.strictObject({
|
|
125
134
|
workflow_step: MigrationReferenceSchema,
|
|
126
|
-
elements: MigrationElementsSchema
|
|
135
|
+
elements: MigrationElementsSchema,
|
|
136
|
+
schedule: ScheduleSchema.optional()
|
|
127
137
|
})
|
|
128
138
|
.readonly();
|
|
129
139
|
|
|
@@ -155,7 +165,8 @@ const BaseMigrationAssetSchema = z.strictObject({
|
|
|
155
165
|
filename: z.string(),
|
|
156
166
|
title: z.string(),
|
|
157
167
|
collection: z.optional(MigrationReferenceSchema),
|
|
158
|
-
descriptions: z.optional(z.array(MigrationAssetDescriptionSchema)).readonly()
|
|
168
|
+
descriptions: z.optional(z.array(MigrationAssetDescriptionSchema)).readonly(),
|
|
169
|
+
folder: z.optional(MigrationReferenceSchema)
|
|
159
170
|
});
|
|
160
171
|
|
|
161
172
|
export const MigrationAssetSchema = BaseMigrationAssetSchema.extend({
|
|
@@ -10,16 +10,8 @@ export function parseAsMigrationReferencesArray(value: MigrationElementValue): r
|
|
|
10
10
|
throw Error(`Value is not an array`);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export function findRequired<T>(
|
|
14
|
-
|
|
15
|
-
predicate: (item: T, index: number) => boolean,
|
|
16
|
-
errorMessage: string
|
|
17
|
-
): T;
|
|
18
|
-
export function findRequired<T>(
|
|
19
|
-
array: readonly T[],
|
|
20
|
-
predicate: (item: T, index: number) => boolean,
|
|
21
|
-
errorMessage: () => never
|
|
22
|
-
): T;
|
|
13
|
+
export function findRequired<T>(array: readonly T[], predicate: (item: T, index: number) => boolean, errorMessage: string): T;
|
|
14
|
+
export function findRequired<T>(array: readonly T[], predicate: (item: T, index: number) => boolean, errorMessage: () => never): T;
|
|
23
15
|
export function findRequired<T>(
|
|
24
16
|
array: readonly T[],
|
|
25
17
|
predicate: (item: T, index: number) => boolean,
|
|
@@ -14,16 +14,11 @@ export async function getBinaryDataFromUrlAsync(url: string): Promise<{ data: Bu
|
|
|
14
14
|
}
|
|
15
15
|
);
|
|
16
16
|
|
|
17
|
-
const
|
|
18
|
-
const contentLength = contentLengthHeader ? +contentLengthHeader.value : 0;
|
|
17
|
+
const contentLength = +(response.headers.find((m) => m.header.toLowerCase() === 'content-length')?.value ?? 0);
|
|
19
18
|
|
|
20
19
|
return { data: response.data, contentLength: contentLength };
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
export function geSizeInBytes(data: Blob | Buffer): number {
|
|
24
|
-
|
|
25
|
-
return data.size;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return data.byteLength;
|
|
23
|
+
return data instanceof Blob ? data.size : data.byteLength;
|
|
29
24
|
}
|
|
@@ -19,11 +19,9 @@ export async function confirmExportAsync(data: {
|
|
|
19
19
|
data.logger
|
|
20
20
|
).getEnvironmentAsync();
|
|
21
21
|
|
|
22
|
-
const text: string = `Are you sure to export '${chalk.cyan(
|
|
22
|
+
const text: string = `Are you sure to export '${chalk.cyan(data.dataToExport.itemsCount)}' content ${getItemsPluralText(
|
|
23
23
|
data.dataToExport.itemsCount
|
|
24
|
-
)}
|
|
25
|
-
environment.name
|
|
26
|
-
)} (${chalk.magenta(environment.environment)})?`;
|
|
24
|
+
)} from ${chalk.yellow(environment.name)} (${chalk.magenta(environment.environment)})?`;
|
|
27
25
|
|
|
28
26
|
await confirmAsync({
|
|
29
27
|
force: data.force,
|
|
@@ -65,9 +63,9 @@ export async function confirmMigrateAsync(data: {
|
|
|
65
63
|
|
|
66
64
|
const text: string = `Are you sure to migrate '${chalk.cyan(data.dataToMigrate.itemsCount)}' ${getItemsPluralText(
|
|
67
65
|
data.dataToMigrate.itemsCount
|
|
68
|
-
)} from ${chalk.yellow(sourceEnvironment.name)} (${chalk.magenta(
|
|
69
|
-
|
|
70
|
-
)}
|
|
66
|
+
)} from ${chalk.yellow(sourceEnvironment.name)} (${chalk.magenta(sourceEnvironment.environment)}) to environment ${chalk.yellow(
|
|
67
|
+
targetEnvironment.name
|
|
68
|
+
)} (${chalk.magenta(targetEnvironment.environment)}) ?`;
|
|
71
69
|
|
|
72
70
|
await confirmAsync({
|
|
73
71
|
force: data.force,
|
|
@@ -91,9 +89,7 @@ export async function confirmImportAsync(data: {
|
|
|
91
89
|
data.logger
|
|
92
90
|
).getEnvironmentAsync();
|
|
93
91
|
|
|
94
|
-
const text: string = `Are you sure to import data into ${chalk.yellow(environment.name)} (${chalk.magenta(
|
|
95
|
-
environment.environment
|
|
96
|
-
)})?`;
|
|
92
|
+
const text: string = `Are you sure to import data into ${chalk.yellow(environment.name)} (${chalk.magenta(environment.environment)})?`;
|
|
97
93
|
|
|
98
94
|
await confirmAsync({
|
|
99
95
|
force: data.force,
|
|
@@ -116,24 +112,22 @@ async function confirmAsync(data: {
|
|
|
116
112
|
if (data.force) {
|
|
117
113
|
data.logger.log({
|
|
118
114
|
type: 'info',
|
|
119
|
-
message: `Skipping confirmation
|
|
120
|
-
});
|
|
121
|
-
} else {
|
|
122
|
-
const confirmed = await prompts.default({
|
|
123
|
-
type: 'confirm',
|
|
124
|
-
name: 'confirm',
|
|
125
|
-
message: `${chalk.cyan(data.action)}: ${data.message}`
|
|
115
|
+
message: `Skipping confirmation`
|
|
126
116
|
});
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
127
119
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
120
|
+
const confirmed = await prompts.default({
|
|
121
|
+
type: 'confirm',
|
|
122
|
+
name: 'confirm',
|
|
123
|
+
message: `${chalk.cyan(data.action)}: ${data.message}`
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (!confirmed.confirm) {
|
|
127
|
+
throw Error(`Confirmation refused.`);
|
|
131
128
|
}
|
|
132
129
|
}
|
|
133
130
|
|
|
134
131
|
function getItemsPluralText(count: number): string {
|
|
135
|
-
|
|
136
|
-
return 'item';
|
|
137
|
-
}
|
|
138
|
-
return 'items';
|
|
132
|
+
return count === 1 ? 'item' : 'items';
|
|
139
133
|
}
|
|
@@ -2,39 +2,59 @@ import { SharedModels } from '@kontent-ai/management-sdk';
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { ErrorData, OriginalManagementError } from '../models/core.models.js';
|
|
4
4
|
import { ZodError } from 'zod';
|
|
5
|
+
import { match } from 'ts-pattern';
|
|
5
6
|
|
|
6
7
|
export function extractErrorData(error: unknown): ErrorData {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
return match(error)
|
|
9
|
+
.returnType<ErrorData>()
|
|
10
|
+
.when(
|
|
11
|
+
(error) => error instanceof SharedModels.ContentManagementBaseKontentError,
|
|
12
|
+
(error) => {
|
|
13
|
+
const originalError = error.originalError as OriginalManagementError | undefined;
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
15
|
+
return {
|
|
16
|
+
isUnknownError: false,
|
|
17
|
+
error: error,
|
|
18
|
+
message: `${error.message} ${error.validationErrors.map((m) => m.message).join(', ')}`,
|
|
19
|
+
requestUrl: originalError?.response?.config?.url,
|
|
20
|
+
requestData: originalError?.response?.config?.data
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
.when(
|
|
25
|
+
(error) => error instanceof ZodError,
|
|
26
|
+
(error) => {
|
|
27
|
+
return {
|
|
28
|
+
isUnknownError: false,
|
|
29
|
+
error: error,
|
|
30
|
+
message: `Found '${chalk.red(error.issues.length)}' parsing errors: \n${error.issues.reduce<string>(
|
|
31
|
+
(current, issue, index) => {
|
|
32
|
+
return (current += `\n${index + 1}. ${chalk.red(issue.message)} (${chalk.yellow('path')}: ${issue.path.join(
|
|
33
|
+
','
|
|
34
|
+
)})`);
|
|
35
|
+
},
|
|
36
|
+
''
|
|
37
|
+
)}`
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
.when(
|
|
42
|
+
(error) => error instanceof Error,
|
|
43
|
+
(error) => {
|
|
44
|
+
return {
|
|
45
|
+
isUnknownError: false,
|
|
46
|
+
error: error,
|
|
47
|
+
message: error.message
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
.otherwise((error) => {
|
|
52
|
+
return {
|
|
53
|
+
isUnknownError: true,
|
|
54
|
+
error: error,
|
|
55
|
+
message: `Unknown error`
|
|
56
|
+
};
|
|
57
|
+
});
|
|
38
58
|
}
|
|
39
59
|
|
|
40
60
|
export function is404Error(error: unknown): boolean {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HttpService, IRetryStrategyOptions } from '@kontent-ai/core-sdk';
|
|
2
2
|
import { OriginalManagementError } from '../models/core.models.js';
|
|
3
|
+
import { match } from 'ts-pattern';
|
|
3
4
|
|
|
4
5
|
const rateExceededErrorCode: number = 10000;
|
|
5
6
|
const notFoundErrorCode: number = 10000;
|
|
@@ -14,21 +15,19 @@ export const defaultRetryStrategy: Readonly<IRetryStrategyOptions> = {
|
|
|
14
15
|
const originalError = err as OriginalManagementError | undefined;
|
|
15
16
|
const errorCode: number = originalError?.response?.data?.error_code ?? -1;
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
return true;
|
|
18
|
+
return (
|
|
19
|
+
match(errorCode)
|
|
20
|
+
// retry rate exceeded error
|
|
21
|
+
.with(rateExceededErrorCode, () => true)
|
|
22
|
+
// do not retry errors indicating resource does not exist
|
|
23
|
+
.with(notFoundErrorCode, () => false)
|
|
24
|
+
// if error code is set, do not retry the request
|
|
25
|
+
.when(
|
|
26
|
+
(errorCode) => errorCode >= 0,
|
|
27
|
+
() => false
|
|
28
|
+
)
|
|
29
|
+
.otherwise(() => true)
|
|
30
|
+
);
|
|
32
31
|
},
|
|
33
32
|
maxAttempts: 3,
|
|
34
33
|
deltaBackoffMs: 1000
|