@kontent-ai/migration-toolkit 1.0.1 → 1.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.
- package/README.md +1 -1
- package/dist/es2022/core/index.d.ts +1 -0
- package/dist/es2022/core/index.js +1 -0
- package/dist/es2022/core/index.js.map +1 -1
- package/dist/es2022/core/logs/loggers.js +1 -4
- package/dist/es2022/core/logs/loggers.js.map +1 -1
- package/dist/es2022/core/models/core.models.d.ts +9 -10
- package/dist/es2022/core/models/log.models.d.ts +2 -2
- package/dist/es2022/core/models/migration.models.d.ts +47 -133
- package/dist/es2022/core/models/migration.schema.d.ts +1240 -0
- package/dist/es2022/core/models/migration.schema.js +113 -0
- package/dist/es2022/core/models/migration.schema.js.map +1 -0
- package/dist/es2022/core/utils/confirm.utils.js +3 -3
- package/dist/es2022/core/utils/confirm.utils.js.map +1 -1
- package/dist/es2022/core/utils/error.utils.js +8 -2
- package/dist/es2022/core/utils/error.utils.js.map +1 -1
- package/dist/es2022/core/utils/global.utils.d.ts +4 -1
- package/dist/es2022/core/utils/global.utils.js +1 -3
- package/dist/es2022/core/utils/global.utils.js.map +1 -1
- package/dist/es2022/export/context/export-context-fetcher.js +11 -7
- package/dist/es2022/export/context/export-context-fetcher.js.map +1 -1
- package/dist/es2022/export/export-manager.js +3 -3
- package/dist/es2022/export/export-manager.js.map +1 -1
- package/dist/es2022/import/import-manager.js.map +1 -1
- package/dist/es2022/metadata.js +2 -2
- package/dist/es2022/node/cli/actions/export-action.js +2 -2
- package/dist/es2022/node/cli/actions/export-action.js.map +1 -1
- package/dist/es2022/node/cli/actions/import-action.js +2 -2
- package/dist/es2022/node/cli/actions/import-action.js.map +1 -1
- package/dist/es2022/toolkit/file.js +3 -3
- package/dist/es2022/toolkit/file.js.map +1 -1
- package/dist/es2022/translation/transforms/export-transforms.js.map +1 -1
- package/dist/es2022/zip/zip-transformer.js +9 -6
- package/dist/es2022/zip/zip-transformer.js.map +1 -1
- package/dist/es2022/zip/zip.models.d.ts +1 -1
- package/lib/core/index.ts +1 -0
- package/lib/core/logs/loggers.ts +1 -6
- package/lib/core/models/core.models.ts +11 -17
- package/lib/core/models/log.models.ts +7 -4
- package/lib/core/models/migration.models.ts +78 -158
- package/lib/core/models/migration.schema.ts +178 -0
- package/lib/core/utils/confirm.utils.ts +4 -4
- package/lib/core/utils/error.utils.ts +9 -6
- package/lib/core/utils/global.utils.ts +3 -3
- package/lib/export/context/export-context-fetcher.ts +23 -55
- package/lib/export/export-manager.ts +16 -20
- package/lib/import/import-manager.ts +2 -6
- package/lib/metadata.ts +2 -2
- package/lib/node/cli/actions/export-action.ts +2 -2
- package/lib/node/cli/actions/import-action.ts +2 -2
- package/lib/toolkit/file.ts +3 -9
- package/lib/translation/transforms/export-transforms.ts +1 -4
- package/lib/zip/zip-transformer.ts +25 -11
- package/lib/zip/zip.models.ts +1 -1
- package/package.json +10 -9
package/lib/core/logs/loggers.ts
CHANGED
|
@@ -63,12 +63,7 @@ function getLogDataMessage(data: LogSpinnerMessage): string {
|
|
|
63
63
|
|
|
64
64
|
if (data.type === 'info') {
|
|
65
65
|
typeColor = chalk.cyan;
|
|
66
|
-
} else if (
|
|
67
|
-
data.type === 'error' ||
|
|
68
|
-
data.type === 'errorData' ||
|
|
69
|
-
data.type === 'warning' ||
|
|
70
|
-
data.type === 'cancel'
|
|
71
|
-
) {
|
|
66
|
+
} else if (data.type === 'error' || data.type === 'errorData' || data.type === 'warning' || data.type === 'cancel') {
|
|
72
67
|
typeColor = chalk.red;
|
|
73
68
|
} else if (data.type === 'completed') {
|
|
74
69
|
typeColor = chalk.green;
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AssetModels,
|
|
3
|
-
ContentItemModels,
|
|
4
|
-
ContentTypeElements,
|
|
5
|
-
LanguageVariantModels,
|
|
6
|
-
WorkflowModels
|
|
7
|
-
} from '@kontent-ai/management-sdk';
|
|
1
|
+
import { AssetModels, ContentItemModels, ContentTypeElements, LanguageVariantModels, WorkflowModels } from '@kontent-ai/management-sdk';
|
|
8
2
|
import { MigrationElementType } from './migration.models.js';
|
|
9
3
|
import { WorkflowStep } from '../helpers/workflow-helper.js';
|
|
10
4
|
|
|
11
5
|
export type TargetItemState = 'exists' | 'doesNotExists';
|
|
12
6
|
export type CliAction = 'export' | 'import' | 'migrate';
|
|
13
|
-
export type GeneralItemType = 'exportedItem' | 'migrationItem';
|
|
14
|
-
export type GeneralActionType = 'readFs' | 'skip' | 'writeFs' | 'download';
|
|
15
7
|
export type EnvContext = 'browser' | 'node';
|
|
16
8
|
|
|
17
9
|
export type MapiAction =
|
|
@@ -26,6 +18,8 @@ export type MapiAction =
|
|
|
26
18
|
| 'upsert'
|
|
27
19
|
| 'createNewVersion';
|
|
28
20
|
|
|
21
|
+
export type MigrationItemType = 'exportItem';
|
|
22
|
+
|
|
29
23
|
export type MapiType =
|
|
30
24
|
| 'contentType'
|
|
31
25
|
| 'asset'
|
|
@@ -40,7 +34,7 @@ export type MapiType =
|
|
|
40
34
|
|
|
41
35
|
export interface ItemInfo {
|
|
42
36
|
readonly title: string;
|
|
43
|
-
readonly itemType:
|
|
37
|
+
readonly itemType: MapiType | MigrationItemType;
|
|
44
38
|
}
|
|
45
39
|
|
|
46
40
|
export interface ErrorData {
|
|
@@ -121,14 +115,14 @@ export interface FlattenedContentType {
|
|
|
121
115
|
}
|
|
122
116
|
|
|
123
117
|
export interface OriginalManagementError {
|
|
124
|
-
response?: {
|
|
125
|
-
status?: number;
|
|
126
|
-
config?: {
|
|
127
|
-
url?: string;
|
|
128
|
-
data?: string;
|
|
118
|
+
readonly response?: {
|
|
119
|
+
readonly status?: number;
|
|
120
|
+
readonly config?: {
|
|
121
|
+
readonly url?: string;
|
|
122
|
+
readonly data?: string;
|
|
129
123
|
};
|
|
130
|
-
data?: {
|
|
131
|
-
error_code?: number;
|
|
124
|
+
readonly data?: {
|
|
125
|
+
readonly error_code?: number;
|
|
132
126
|
};
|
|
133
127
|
};
|
|
134
128
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MigrationItemType, MapiAction, MapiType } from '../index.js';
|
|
2
2
|
|
|
3
3
|
export type DebugType =
|
|
4
4
|
| 'error'
|
|
@@ -8,10 +8,13 @@ export type DebugType =
|
|
|
8
8
|
| 'errorData'
|
|
9
9
|
| 'cancel'
|
|
10
10
|
| 'process'
|
|
11
|
+
| 'readFs'
|
|
12
|
+
| 'skip'
|
|
13
|
+
| 'writeFs'
|
|
14
|
+
| 'download'
|
|
15
|
+
| MigrationItemType
|
|
11
16
|
| MapiType
|
|
12
|
-
|
|
|
13
|
-
| MapiAction
|
|
14
|
-
| GeneralItemType;
|
|
17
|
+
| MapiAction;
|
|
15
18
|
|
|
16
19
|
export interface LogMessage {
|
|
17
20
|
readonly type: DebugType;
|
|
@@ -1,165 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface MigrationUrlSlugElementValue {
|
|
22
|
-
value: string | undefined;
|
|
23
|
-
mode: MigrationUrlSlugMode;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface MigrationComponent {
|
|
27
|
-
system: {
|
|
28
|
-
id: string;
|
|
29
|
-
type: MigrationReference;
|
|
30
|
-
};
|
|
31
|
-
elements: MigrationElements;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type MigrationElementValue =
|
|
35
|
-
| string
|
|
36
|
-
| undefined
|
|
37
|
-
| MigrationReference[]
|
|
38
|
-
| number
|
|
39
|
-
| MigrationRichTextElementValue
|
|
40
|
-
| MigrationUrlSlugElementValue;
|
|
41
|
-
|
|
42
|
-
export interface MigrationElement<
|
|
43
|
-
TElementType extends MigrationElementType = MigrationElementType,
|
|
44
|
-
TValue extends MigrationElementValue = MigrationElementValue
|
|
45
|
-
> {
|
|
46
|
-
/**
|
|
47
|
-
* Value of the element
|
|
48
|
-
*/
|
|
49
|
-
readonly value: TValue;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Type of the element
|
|
53
|
-
*/
|
|
54
|
-
readonly type: TElementType;
|
|
55
|
-
}
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import {
|
|
3
|
+
MigrationComponentSchema,
|
|
4
|
+
MigrationElementTypeSchema,
|
|
5
|
+
MigrationElementValueSchema,
|
|
6
|
+
MigrationReferenceSchema,
|
|
7
|
+
MigrationUrlSlugElementValueSchema,
|
|
8
|
+
MigrationUrlSlugModeSchema,
|
|
9
|
+
MigrationRichTextElementValueSchema,
|
|
10
|
+
MigrationElementSchema,
|
|
11
|
+
MigrationElementsSchema,
|
|
12
|
+
MigrationAssetDescriptionSchema,
|
|
13
|
+
MigrationDataSchema,
|
|
14
|
+
MigrationAssetSchema,
|
|
15
|
+
MigrationItemVersionSchema,
|
|
16
|
+
MigrationItemSchema,
|
|
17
|
+
MigrationItemSystemSchema
|
|
18
|
+
} from './migration.schema.js';
|
|
56
19
|
|
|
57
20
|
export namespace MigrationElementModels {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
export interface AssetElement extends MigrationElement<'asset', MigrationReference[] | undefined> {}
|
|
65
|
-
export interface LinkedItemsElement extends MigrationElement<'modular_content', MigrationReference[] | undefined> {}
|
|
66
|
-
export interface TaxonomyElement extends MigrationElement<'taxonomy', MigrationReference[] | undefined> {}
|
|
67
|
-
export interface UrlSlugElement extends MigrationElement<'url_slug', MigrationUrlSlugElementValue | undefined> {}
|
|
68
|
-
export interface CustomElement extends MigrationElement<'custom', string | undefined> {}
|
|
69
|
-
export interface SubpagesElement extends MigrationElement<'subpages', MigrationReference[] | undefined> {}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface MigrationElements {
|
|
73
|
-
[elementCodename: string]: MigrationElement;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface MigrationItemVersion<TElements extends MigrationElements = MigrationElements> {
|
|
77
|
-
readonly elements: TElements;
|
|
78
|
-
readonly workflow_step: MigrationReference;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface MigrationItem<TElements extends MigrationElements = MigrationElements> {
|
|
82
|
-
readonly system: {
|
|
83
|
-
/**
|
|
84
|
-
* Codename of the content item
|
|
85
|
-
*/
|
|
86
|
-
readonly codename: string;
|
|
87
|
-
/**
|
|
88
|
-
* Name of the content item
|
|
89
|
-
*/
|
|
90
|
-
readonly name: string;
|
|
91
|
-
/**
|
|
92
|
-
* Language of the language variant
|
|
93
|
-
*/
|
|
94
|
-
readonly language: MigrationReference;
|
|
95
|
-
/**
|
|
96
|
-
* Content type of the item
|
|
97
|
-
*/
|
|
98
|
-
readonly type: MigrationReference;
|
|
99
|
-
/**
|
|
100
|
-
* Collection of the item
|
|
101
|
-
*/
|
|
102
|
-
readonly collection: MigrationReference;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Workflow of the item
|
|
106
|
-
*/
|
|
107
|
-
readonly workflow: MigrationReference;
|
|
21
|
+
type MigrationElementDef<
|
|
22
|
+
TElementType extends MigrationElementType = MigrationElementType,
|
|
23
|
+
TValue extends MigrationElementValue = MigrationElementValue
|
|
24
|
+
> = {
|
|
25
|
+
readonly value: TValue | undefined;
|
|
26
|
+
readonly type: TElementType;
|
|
108
27
|
};
|
|
109
|
-
readonly versions: MigrationItemVersion<TElements>[];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export interface MigrationReference {
|
|
113
|
-
/**
|
|
114
|
-
* Codename of the referenced object
|
|
115
|
-
*/
|
|
116
|
-
readonly codename: string;
|
|
117
|
-
}
|
|
118
28
|
|
|
119
|
-
export
|
|
120
|
-
|
|
121
|
-
|
|
29
|
+
export type TextElement = MigrationElementDef<'text', string>;
|
|
30
|
+
export type NumberElement = MigrationElementDef<'number', number>;
|
|
31
|
+
export type RichTextElement = MigrationElementDef<'rich_text', MigrationRichTextElementValue>;
|
|
32
|
+
export type MultipleChoiceElement = MigrationElementDef<'multiple_choice', MigrationReference[]>;
|
|
33
|
+
export type DateTimeElement = MigrationElementDef<'date_time', string>;
|
|
34
|
+
export type AssetElement = MigrationElementDef<'asset', MigrationReference[]>;
|
|
35
|
+
export type LinkedItemsElement = MigrationElementDef<'modular_content', MigrationReference[]>;
|
|
36
|
+
export type TaxonomyElement = MigrationElementDef<'taxonomy', MigrationReference[]>;
|
|
37
|
+
export type UrlSlugElement = MigrationElementDef<'url_slug', MigrationUrlSlugElementValue>;
|
|
38
|
+
export type CustomElement = MigrationElementDef<'custom', string>;
|
|
39
|
+
export type SubpagesElement = MigrationElementDef<'subpages', MigrationReference[]>;
|
|
122
40
|
}
|
|
123
41
|
|
|
124
|
-
export
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
42
|
+
export type MigrationReference<T extends string = string> = z.infer<typeof MigrationReferenceSchema> & {
|
|
43
|
+
readonly codename: T;
|
|
44
|
+
};
|
|
45
|
+
export type MigrationItemSystem<
|
|
46
|
+
TLanguage extends string = string,
|
|
47
|
+
TType extends string = string,
|
|
48
|
+
TCollection extends string = string,
|
|
49
|
+
TWorkflow extends string = string
|
|
50
|
+
> = z.infer<typeof MigrationItemSystemSchema> & {
|
|
128
51
|
readonly codename: string;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
readonly
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
readonly
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
*/
|
|
164
|
-
readonly assets: readonly MigrationAsset[];
|
|
165
|
-
}
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly language: MigrationReference<TLanguage>;
|
|
54
|
+
readonly type: MigrationReference<TType>;
|
|
55
|
+
readonly collection: MigrationReference<TCollection>;
|
|
56
|
+
readonly workflow: MigrationReference<TWorkflow>;
|
|
57
|
+
};
|
|
58
|
+
export type MigrationUrlSlugMode = z.infer<typeof MigrationUrlSlugModeSchema>;
|
|
59
|
+
export type MigrationElementType = z.infer<typeof MigrationElementTypeSchema>;
|
|
60
|
+
export type MigrationUrlSlugElementValue = z.infer<typeof MigrationUrlSlugElementValueSchema>;
|
|
61
|
+
export type MigrationRichTextElementValue = z.infer<typeof MigrationRichTextElementValueSchema>;
|
|
62
|
+
export type MigrationComponent = z.infer<typeof MigrationComponentSchema>;
|
|
63
|
+
export type MigrationElementValue = z.infer<typeof MigrationElementValueSchema>;
|
|
64
|
+
export type MigrationElement = z.infer<typeof MigrationElementSchema>;
|
|
65
|
+
export type MigrationElements = z.infer<typeof MigrationElementsSchema>;
|
|
66
|
+
export type MigrationAssetDescription = z.infer<typeof MigrationAssetDescriptionSchema>;
|
|
67
|
+
export type MigrationAsset = z.infer<typeof MigrationAssetSchema>;
|
|
68
|
+
export type MigrationData = z.infer<typeof MigrationDataSchema>;
|
|
69
|
+
|
|
70
|
+
export type MigrationItemVersion<
|
|
71
|
+
TElements extends MigrationElements = MigrationElements,
|
|
72
|
+
TWorkflowStepCodename extends string = string
|
|
73
|
+
> = z.infer<typeof MigrationItemVersionSchema> & {
|
|
74
|
+
readonly elements: Readonly<TElements>;
|
|
75
|
+
readonly workflow_step: MigrationReference<TWorkflowStepCodename>;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type MigrationItem<
|
|
79
|
+
TElements extends MigrationElements = MigrationElements,
|
|
80
|
+
TSystem extends MigrationItemSystem = MigrationItemSystem,
|
|
81
|
+
TWorkflowStepCodename extends string = string
|
|
82
|
+
> = z.infer<typeof MigrationItemSchema> & {
|
|
83
|
+
readonly versions: Readonly<MigrationItemVersion<TElements, TWorkflowStepCodename>[]>;
|
|
84
|
+
readonly system: TSystem;
|
|
85
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
interface Elements {
|
|
4
|
+
readonly [key: string]: Element;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type UrlSlugMode = 'autogenerated' | 'custom';
|
|
8
|
+
|
|
9
|
+
type UrlSlugElementValue = {
|
|
10
|
+
readonly value?: string;
|
|
11
|
+
readonly mode: UrlSlugMode;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type Reference = { readonly codename: string };
|
|
15
|
+
|
|
16
|
+
type Component = {
|
|
17
|
+
readonly system: {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly type: Reference;
|
|
20
|
+
};
|
|
21
|
+
readonly elements: Elements;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type RichTextElementValue = {
|
|
25
|
+
readonly value: string;
|
|
26
|
+
readonly components: Readonly<Component[]>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type ElementValue = string | undefined | number | Reference[] | RichTextElementValue | UrlSlugElementValue;
|
|
30
|
+
|
|
31
|
+
type Element = {
|
|
32
|
+
readonly type: ElementType;
|
|
33
|
+
readonly value?: ElementValue;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type ElementType =
|
|
37
|
+
| 'text'
|
|
38
|
+
| 'rich_text'
|
|
39
|
+
| 'number'
|
|
40
|
+
| 'multiple_choice'
|
|
41
|
+
| 'date_time'
|
|
42
|
+
| 'asset'
|
|
43
|
+
| 'modular_content'
|
|
44
|
+
| 'taxonomy'
|
|
45
|
+
| 'url_slug'
|
|
46
|
+
| 'custom'
|
|
47
|
+
| 'subpages';
|
|
48
|
+
|
|
49
|
+
export const MigrationUrlSlugModeSchema = z.enum(['autogenerated', 'custom']).readonly();
|
|
50
|
+
export const MigrationElementTypeSchema = z
|
|
51
|
+
.enum([
|
|
52
|
+
'text',
|
|
53
|
+
'rich_text',
|
|
54
|
+
'number',
|
|
55
|
+
'multiple_choice',
|
|
56
|
+
'date_time',
|
|
57
|
+
'asset',
|
|
58
|
+
'modular_content',
|
|
59
|
+
'taxonomy',
|
|
60
|
+
'url_slug',
|
|
61
|
+
'custom',
|
|
62
|
+
'subpages'
|
|
63
|
+
])
|
|
64
|
+
.readonly();
|
|
65
|
+
|
|
66
|
+
export const MigrationReferenceSchema = z
|
|
67
|
+
.strictObject({
|
|
68
|
+
codename: z.string().readonly()
|
|
69
|
+
})
|
|
70
|
+
.readonly();
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* ZodType is needed to be specified here due to the use of 'lazy' & circular dependency between types
|
|
74
|
+
* Otherwise TS has no way of statically inferring the type
|
|
75
|
+
*/
|
|
76
|
+
export const MigrationElementsSchema: z.ZodReadonly<z.ZodType<Elements>> = z
|
|
77
|
+
.record(
|
|
78
|
+
z.string(),
|
|
79
|
+
z.lazy(() => MigrationElementSchema)
|
|
80
|
+
)
|
|
81
|
+
.readonly();
|
|
82
|
+
|
|
83
|
+
export const MigrationComponentSchema = z
|
|
84
|
+
.strictObject({
|
|
85
|
+
system: z.strictObject({
|
|
86
|
+
id: z.string(),
|
|
87
|
+
type: MigrationReferenceSchema
|
|
88
|
+
}),
|
|
89
|
+
elements: MigrationElementsSchema
|
|
90
|
+
})
|
|
91
|
+
.readonly();
|
|
92
|
+
|
|
93
|
+
export const MigrationUrlSlugElementValueSchema = z
|
|
94
|
+
.strictObject({
|
|
95
|
+
value: z.optional(z.string()),
|
|
96
|
+
mode: MigrationUrlSlugModeSchema
|
|
97
|
+
})
|
|
98
|
+
.readonly();
|
|
99
|
+
|
|
100
|
+
export const MigrationRichTextElementValueSchema = z
|
|
101
|
+
.strictObject({
|
|
102
|
+
value: z.string(),
|
|
103
|
+
components: z.array(MigrationComponentSchema).readonly()
|
|
104
|
+
})
|
|
105
|
+
.readonly();
|
|
106
|
+
|
|
107
|
+
export const MigrationElementValueSchema = z.union([
|
|
108
|
+
z.string(),
|
|
109
|
+
z.undefined(),
|
|
110
|
+
z.number(),
|
|
111
|
+
z.array(MigrationReferenceSchema),
|
|
112
|
+
MigrationRichTextElementValueSchema,
|
|
113
|
+
MigrationUrlSlugElementValueSchema
|
|
114
|
+
]);
|
|
115
|
+
|
|
116
|
+
export const MigrationElementSchema = z
|
|
117
|
+
.strictObject({
|
|
118
|
+
type: MigrationElementTypeSchema,
|
|
119
|
+
value: MigrationElementValueSchema
|
|
120
|
+
})
|
|
121
|
+
.readonly();
|
|
122
|
+
|
|
123
|
+
export const MigrationItemVersionSchema = z
|
|
124
|
+
.strictObject({
|
|
125
|
+
workflow_step: MigrationReferenceSchema,
|
|
126
|
+
elements: MigrationElementsSchema
|
|
127
|
+
})
|
|
128
|
+
.readonly();
|
|
129
|
+
|
|
130
|
+
export const MigrationItemSystemSchema = z.strictObject({
|
|
131
|
+
codename: z.string(),
|
|
132
|
+
name: z.string(),
|
|
133
|
+
language: MigrationReferenceSchema,
|
|
134
|
+
type: MigrationReferenceSchema,
|
|
135
|
+
collection: MigrationReferenceSchema,
|
|
136
|
+
workflow: MigrationReferenceSchema
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export const MigrationItemSchema = z
|
|
140
|
+
.strictObject({
|
|
141
|
+
system: MigrationItemSystemSchema,
|
|
142
|
+
versions: z.array(MigrationItemVersionSchema).readonly()
|
|
143
|
+
})
|
|
144
|
+
.readonly();
|
|
145
|
+
|
|
146
|
+
export const MigrationAssetDescriptionSchema = z
|
|
147
|
+
.strictObject({
|
|
148
|
+
language: MigrationReferenceSchema,
|
|
149
|
+
description: z.optional(z.string())
|
|
150
|
+
})
|
|
151
|
+
.readonly();
|
|
152
|
+
|
|
153
|
+
const BaseMigrationAssetSchema = z.strictObject({
|
|
154
|
+
codename: z.string(),
|
|
155
|
+
filename: z.string(),
|
|
156
|
+
title: z.string(),
|
|
157
|
+
collection: z.optional(MigrationReferenceSchema),
|
|
158
|
+
descriptions: z.optional(z.array(MigrationAssetDescriptionSchema)).readonly()
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
export const MigrationAssetSchema = BaseMigrationAssetSchema.extend({
|
|
162
|
+
binaryData: z.union([z.instanceof(Buffer), z.instanceof(Blob)])
|
|
163
|
+
}).readonly();
|
|
164
|
+
|
|
165
|
+
export const ZipMigrationAssetSchema = BaseMigrationAssetSchema.extend({
|
|
166
|
+
_zipFilename: z.string()
|
|
167
|
+
}).readonly();
|
|
168
|
+
|
|
169
|
+
export const MigrationAssetsSchema = z.array(MigrationAssetSchema).readonly();
|
|
170
|
+
export const ZipMigrationAssetsSchema = z.array(ZipMigrationAssetSchema).readonly();
|
|
171
|
+
export const MigrationItemsSchema = z.array(MigrationItemSchema).readonly();
|
|
172
|
+
|
|
173
|
+
export const MigrationDataSchema = z
|
|
174
|
+
.strictObject({
|
|
175
|
+
items: MigrationItemsSchema,
|
|
176
|
+
assets: MigrationAssetsSchema
|
|
177
|
+
})
|
|
178
|
+
.readonly();
|
|
@@ -23,7 +23,7 @@ export async function confirmExportAsync(data: {
|
|
|
23
23
|
data.dataToExport.itemsCount
|
|
24
24
|
)}' content ${getItemsPluralText(data.dataToExport.itemsCount)} from ${chalk.yellow(
|
|
25
25
|
environment.name
|
|
26
|
-
)} (${chalk.
|
|
26
|
+
)} (${chalk.magenta(environment.environment)})?`;
|
|
27
27
|
|
|
28
28
|
await confirmAsync({
|
|
29
29
|
force: data.force,
|
|
@@ -65,9 +65,9 @@ export async function confirmMigrateAsync(data: {
|
|
|
65
65
|
|
|
66
66
|
const text: string = `Are you sure to migrate '${chalk.cyan(data.dataToMigrate.itemsCount)}' ${getItemsPluralText(
|
|
67
67
|
data.dataToMigrate.itemsCount
|
|
68
|
-
)} from ${chalk.yellow(sourceEnvironment.name)} (${chalk.
|
|
68
|
+
)} from ${chalk.yellow(sourceEnvironment.name)} (${chalk.magenta(
|
|
69
69
|
sourceEnvironment.environment
|
|
70
|
-
)}) to environment ${chalk.yellow(targetEnvironment.name)} (${chalk.
|
|
70
|
+
)}) to environment ${chalk.yellow(targetEnvironment.name)} (${chalk.magenta(targetEnvironment.environment)}) ?`;
|
|
71
71
|
|
|
72
72
|
await confirmAsync({
|
|
73
73
|
force: data.force,
|
|
@@ -91,7 +91,7 @@ export async function confirmImportAsync(data: {
|
|
|
91
91
|
data.logger
|
|
92
92
|
).getEnvironmentAsync();
|
|
93
93
|
|
|
94
|
-
const text: string = `Are you sure to import data into ${chalk.yellow(environment.name)} (${chalk.
|
|
94
|
+
const text: string = `Are you sure to import data into ${chalk.yellow(environment.name)} (${chalk.magenta(
|
|
95
95
|
environment.environment
|
|
96
96
|
)})?`;
|
|
97
97
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SharedModels } from '@kontent-ai/management-sdk';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { ErrorData, OriginalManagementError } from '../models/core.models.js';
|
|
4
|
+
import { ZodError } from 'zod';
|
|
4
5
|
|
|
5
6
|
export function extractErrorData(error: unknown): ErrorData {
|
|
6
7
|
let isUnknownError: boolean = true;
|
|
@@ -10,15 +11,17 @@ export function extractErrorData(error: unknown): ErrorData {
|
|
|
10
11
|
|
|
11
12
|
if (error instanceof SharedModels.ContentManagementBaseKontentError) {
|
|
12
13
|
isUnknownError = false;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const originalError: OriginalManagementError | undefined = error.originalError as
|
|
16
|
-
| OriginalManagementError
|
|
17
|
-
| undefined;
|
|
14
|
+
const originalError = error.originalError as OriginalManagementError | undefined;
|
|
18
15
|
|
|
19
16
|
requestUrl = originalError?.response?.config?.url;
|
|
20
17
|
requestData = originalError?.response?.config?.data;
|
|
21
|
-
|
|
18
|
+
|
|
19
|
+
message = `${error.message}: ${error.validationErrors.map((m) => m.message).join(', ')}`;
|
|
20
|
+
} else if (error instanceof ZodError) {
|
|
21
|
+
isUnknownError = false;
|
|
22
|
+
message = `Found '${chalk.red(error.issues.length)}' parsing errors: \n${error.issues.reduce<string>((current, issue, index) => {
|
|
23
|
+
return (current += `\n${index + 1}. ${chalk.red(issue.message)} (${chalk.yellow('path')}: ${issue.path.join(',')})`);
|
|
24
|
+
}, '')}`;
|
|
22
25
|
} else if (error instanceof Error) {
|
|
23
26
|
message = error.message;
|
|
24
27
|
}
|
|
@@ -3,6 +3,8 @@ import { ITrackingEventData, getTrackingService } from '@kontent-ai-consulting/t
|
|
|
3
3
|
import { isBrowser, isNode, isWebWorker } from 'browser-or-node';
|
|
4
4
|
import { EnvContext } from '../models/core.models.js';
|
|
5
5
|
|
|
6
|
+
export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
|
|
7
|
+
|
|
6
8
|
export const isNotUndefined = <T>(item: T | undefined): item is T => item !== undefined;
|
|
7
9
|
|
|
8
10
|
export function formatBytes(bytes: number): string {
|
|
@@ -28,9 +30,7 @@ export function getCurrentEnvironment(): EnvContext {
|
|
|
28
30
|
throw Error(`Invalid current environment. This library can be used in node.js or in browsers.`);
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
export
|
|
32
|
-
return `data.zip`;
|
|
33
|
-
}
|
|
33
|
+
export const defaultZipFilename: string = 'data.zip';
|
|
34
34
|
|
|
35
35
|
export async function executeWithTrackingAsync<TResult>(data: {
|
|
36
36
|
func: () => Promise<TResult extends void ? void : Readonly<TResult>>;
|