@kontent-ai/migration-toolkit 1.5.0 → 2.0.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/dist/es2022/core/models/migration.models.d.ts +4 -5
- package/dist/es2022/core/models/migration.schema.d.ts +46 -233
- package/dist/es2022/core/models/migration.schema.js +7 -22
- package/dist/es2022/core/models/migration.schema.js.map +1 -1
- package/dist/es2022/core/utils/binary-data.utils.d.ts +1 -0
- package/dist/es2022/core/utils/binary-data.utils.js.map +1 -1
- package/dist/es2022/export/export-manager.d.ts +1 -1
- package/dist/es2022/export/export-manager.js +6 -5
- package/dist/es2022/export/export-manager.js.map +1 -1
- package/dist/es2022/export/export.models.d.ts +4 -3
- package/dist/es2022/import/comparers/asset-comparer.js +2 -2
- package/dist/es2022/import/comparers/asset-comparer.js.map +1 -1
- package/dist/es2022/import/import.models.d.ts +2 -2
- package/dist/es2022/import/importers/assets-importer.js +15 -7
- package/dist/es2022/import/importers/assets-importer.js.map +1 -1
- package/dist/es2022/import/importers/language-variant-importer.js +4 -4
- package/dist/es2022/import/importers/language-variant-importer.js.map +1 -1
- package/dist/es2022/metadata.js +2 -2
- package/dist/es2022/toolkit/file.js +3 -2
- package/dist/es2022/toolkit/file.js.map +1 -1
- package/dist/es2022/translation/extraction/items-extraction.processor.d.ts +2 -2
- package/dist/es2022/translation/extraction/items-extraction.processor.js +10 -4
- package/dist/es2022/translation/extraction/items-extraction.processor.js.map +1 -1
- package/dist/es2022/translation/helpers/rich-text.processor.d.ts +2 -0
- package/dist/es2022/translation/helpers/rich-text.processor.js +56 -1
- package/dist/es2022/translation/helpers/rich-text.processor.js.map +1 -1
- package/dist/es2022/translation/transforms/export-transforms.js +131 -83
- package/dist/es2022/translation/transforms/export-transforms.js.map +1 -1
- package/dist/es2022/translation/transforms/import-transforms.js +22 -19
- package/dist/es2022/translation/transforms/import-transforms.js.map +1 -1
- package/dist/es2022/zip/zip-manager.d.ts +1 -0
- package/dist/es2022/zip/zip-manager.js +1 -1
- package/dist/es2022/zip/zip-manager.js.map +1 -1
- package/dist/es2022/zip/zip-packager.js +2 -1
- package/dist/es2022/zip/zip-packager.js.map +1 -1
- package/dist/es2022/zip/zip-transformer.d.ts +1 -1
- package/dist/es2022/zip/zip-transformer.js +3 -3
- package/dist/es2022/zip/zip-transformer.js.map +1 -1
- package/dist/es2022/zip/zip.models.d.ts +1 -0
- package/lib/core/models/migration.models.ts +12 -15
- package/lib/core/models/migration.schema.ts +11 -36
- package/lib/core/utils/binary-data.utils.ts +1 -0
- package/lib/export/export-manager.ts +22 -21
- package/lib/export/export.models.ts +18 -17
- package/lib/import/comparers/asset-comparer.ts +2 -2
- package/lib/import/import.models.ts +17 -17
- package/lib/import/importers/assets-importer.ts +25 -16
- package/lib/import/importers/language-variant-importer.ts +13 -13
- package/lib/metadata.ts +2 -2
- package/lib/toolkit/file.ts +3 -2
- package/lib/translation/extraction/items-extraction.processor.ts +16 -9
- package/lib/translation/helpers/rich-text.processor.ts +81 -1
- package/lib/translation/transforms/export-transforms.ts +143 -103
- package/lib/translation/transforms/import-transforms.ts +27 -31
- package/lib/zip/zip-manager.ts +2 -1
- package/lib/zip/zip-packager.ts +4 -3
- package/lib/zip/zip-transformer.ts +4 -4
- package/lib/zip/zip.models.ts +1 -0
- package/package.json +14 -13
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import {
|
|
3
|
+
MigrationAssetDescriptionSchema,
|
|
4
|
+
MigrationAssetSchema,
|
|
3
5
|
MigrationComponentSchema,
|
|
4
|
-
|
|
5
|
-
MigrationElementValueSchema,
|
|
6
|
-
MigrationReferenceSchema,
|
|
7
|
-
MigrationUrlSlugElementValueSchema,
|
|
8
|
-
MigrationUrlSlugModeSchema,
|
|
9
|
-
MigrationRichTextElementValueSchema,
|
|
6
|
+
MigrationDataSchema,
|
|
10
7
|
MigrationElementSchema,
|
|
11
8
|
MigrationElementsSchema,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
MigrationAssetSchema,
|
|
15
|
-
MigrationItemVersionSchema,
|
|
9
|
+
MigrationElementTypeSchema,
|
|
10
|
+
MigrationElementValueSchema,
|
|
16
11
|
MigrationItemSchema,
|
|
17
|
-
MigrationItemSystemSchema
|
|
12
|
+
MigrationItemSystemSchema,
|
|
13
|
+
MigrationItemVersionSchema,
|
|
14
|
+
MigrationReferenceSchema,
|
|
15
|
+
MigrationUrlSlugModeSchema
|
|
18
16
|
} from './migration.schema.js';
|
|
19
17
|
|
|
20
18
|
export namespace MigrationElementModels {
|
|
@@ -28,13 +26,13 @@ export namespace MigrationElementModels {
|
|
|
28
26
|
|
|
29
27
|
export type TextElement = MigrationElementDef<'text', string>;
|
|
30
28
|
export type NumberElement = MigrationElementDef<'number', number>;
|
|
31
|
-
export type RichTextElement = MigrationElementDef<'rich_text',
|
|
29
|
+
export type RichTextElement = MigrationElementDef<'rich_text', string>;
|
|
32
30
|
export type MultipleChoiceElement = MigrationElementDef<'multiple_choice', MigrationReference[]>;
|
|
33
31
|
export type DateTimeElement = MigrationElementDef<'date_time', string>;
|
|
34
32
|
export type AssetElement = MigrationElementDef<'asset', MigrationReference[]>;
|
|
35
33
|
export type LinkedItemsElement = MigrationElementDef<'modular_content', MigrationReference[]>;
|
|
36
34
|
export type TaxonomyElement = MigrationElementDef<'taxonomy', MigrationReference[]>;
|
|
37
|
-
export type UrlSlugElement = MigrationElementDef<'url_slug',
|
|
35
|
+
export type UrlSlugElement = MigrationElementDef<'url_slug', string>;
|
|
38
36
|
export type CustomElement = MigrationElementDef<'custom', string>;
|
|
39
37
|
export type SubpagesElement = MigrationElementDef<'subpages', MigrationReference[]>;
|
|
40
38
|
}
|
|
@@ -58,11 +56,10 @@ export type MigrationItemSystem<
|
|
|
58
56
|
};
|
|
59
57
|
export type MigrationUrlSlugMode = z.infer<typeof MigrationUrlSlugModeSchema>;
|
|
60
58
|
export type MigrationElementType = z.infer<typeof MigrationElementTypeSchema>;
|
|
61
|
-
export type MigrationUrlSlugElementValue = z.infer<typeof MigrationUrlSlugElementValueSchema>;
|
|
62
|
-
export type MigrationRichTextElementValue = z.infer<typeof MigrationRichTextElementValueSchema>;
|
|
63
59
|
export type MigrationComponent = z.infer<typeof MigrationComponentSchema>;
|
|
64
60
|
export type MigrationElementValue = z.infer<typeof MigrationElementValueSchema>;
|
|
65
61
|
export type MigrationElement = z.infer<typeof MigrationElementSchema>;
|
|
62
|
+
export type MigrationElementTransformData = Omit<MigrationElement, 'type'>;
|
|
66
63
|
export type MigrationElements = z.infer<typeof MigrationElementsSchema>;
|
|
67
64
|
export type MigrationAssetDescription = z.infer<typeof MigrationAssetDescriptionSchema>;
|
|
68
65
|
export type MigrationAsset = z.infer<typeof MigrationAssetSchema>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
|
|
3
4
|
interface Elements {
|
|
@@ -5,12 +6,6 @@ interface Elements {
|
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
type UrlSlugMode = 'autogenerated' | 'custom';
|
|
8
|
-
|
|
9
|
-
type UrlSlugElementValue = {
|
|
10
|
-
readonly value?: string;
|
|
11
|
-
readonly mode: UrlSlugMode;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
9
|
type Reference = { readonly codename: string };
|
|
15
10
|
|
|
16
11
|
type Component = {
|
|
@@ -21,16 +16,14 @@ type Component = {
|
|
|
21
16
|
readonly elements: Elements;
|
|
22
17
|
};
|
|
23
18
|
|
|
24
|
-
type
|
|
25
|
-
readonly value: string;
|
|
26
|
-
readonly components: Readonly<Component[]>;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type ElementValue = string | undefined | number | Reference[] | RichTextElementValue | UrlSlugElementValue;
|
|
19
|
+
type ElementValue = string | undefined | number | Reference[];
|
|
30
20
|
|
|
31
21
|
type Element = {
|
|
32
22
|
readonly type: ElementType;
|
|
33
23
|
readonly value?: ElementValue;
|
|
24
|
+
readonly display_timezone?: string;
|
|
25
|
+
readonly components?: readonly Component[];
|
|
26
|
+
readonly mode?: UrlSlugMode;
|
|
34
27
|
};
|
|
35
28
|
|
|
36
29
|
type ElementType =
|
|
@@ -99,33 +92,15 @@ export const MigrationComponentSchema = z
|
|
|
99
92
|
})
|
|
100
93
|
.readonly();
|
|
101
94
|
|
|
102
|
-
export const
|
|
103
|
-
.strictObject({
|
|
104
|
-
value: z.optional(z.string()),
|
|
105
|
-
mode: MigrationUrlSlugModeSchema
|
|
106
|
-
})
|
|
107
|
-
.readonly();
|
|
108
|
-
|
|
109
|
-
export const MigrationRichTextElementValueSchema = z
|
|
110
|
-
.strictObject({
|
|
111
|
-
value: z.string(),
|
|
112
|
-
components: z.array(MigrationComponentSchema).readonly()
|
|
113
|
-
})
|
|
114
|
-
.readonly();
|
|
115
|
-
|
|
116
|
-
export const MigrationElementValueSchema = z.union([
|
|
117
|
-
z.string(),
|
|
118
|
-
z.undefined(),
|
|
119
|
-
z.number(),
|
|
120
|
-
z.array(MigrationReferenceSchema),
|
|
121
|
-
MigrationRichTextElementValueSchema,
|
|
122
|
-
MigrationUrlSlugElementValueSchema
|
|
123
|
-
]);
|
|
95
|
+
export const MigrationElementValueSchema = z.union([z.string(), z.undefined(), z.number(), z.array(MigrationReferenceSchema)]);
|
|
124
96
|
|
|
125
97
|
export const MigrationElementSchema = z
|
|
126
98
|
.strictObject({
|
|
127
99
|
type: MigrationElementTypeSchema,
|
|
128
|
-
value: MigrationElementValueSchema
|
|
100
|
+
value: MigrationElementValueSchema,
|
|
101
|
+
display_timezone: z.string().optional(),
|
|
102
|
+
components: z.array(MigrationComponentSchema).readonly().optional(),
|
|
103
|
+
mode: MigrationUrlSlugModeSchema.optional()
|
|
129
104
|
})
|
|
130
105
|
.readonly();
|
|
131
106
|
|
|
@@ -170,7 +145,7 @@ const BaseMigrationAssetSchema = z.strictObject({
|
|
|
170
145
|
});
|
|
171
146
|
|
|
172
147
|
export const MigrationAssetSchema = BaseMigrationAssetSchema.extend({
|
|
173
|
-
|
|
148
|
+
binary_data: z.union([z.instanceof(Buffer), z.instanceof(Blob)])
|
|
174
149
|
}).readonly();
|
|
175
150
|
|
|
176
151
|
export const ZipMigrationAssetSchema = BaseMigrationAssetSchema.extend({
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { ExportContext, ExportConfig, ExportItem } from './export.models.js';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
1
|
import { AssetFolderModels, AssetModels, CollectionModels, ElementModels } from '@kontent-ai/management-sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
4
3
|
import {
|
|
5
|
-
MigrationAsset,
|
|
6
|
-
MigrationItem,
|
|
7
|
-
FlattenedContentTypeElement,
|
|
8
4
|
extractErrorData,
|
|
9
|
-
|
|
10
|
-
getBinaryDataFromUrlAsync,
|
|
11
|
-
MigrationElements,
|
|
5
|
+
findRequired,
|
|
12
6
|
FlattenedContentType,
|
|
13
|
-
|
|
7
|
+
FlattenedContentTypeElement,
|
|
8
|
+
getBinaryDataFromUrlAsync,
|
|
14
9
|
getDefaultLogger,
|
|
15
|
-
MigrationData,
|
|
16
|
-
isNotUndefined,
|
|
17
|
-
MigrationElementValue,
|
|
18
10
|
getMigrationManagementClient,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
MigrationItemsSchema,
|
|
11
|
+
isNotUndefined,
|
|
12
|
+
MigrationAsset,
|
|
22
13
|
MigrationAssetsSchema,
|
|
23
|
-
|
|
14
|
+
MigrationComponent,
|
|
15
|
+
MigrationData,
|
|
16
|
+
MigrationElements,
|
|
17
|
+
MigrationElementTransformData,
|
|
18
|
+
MigrationItem,
|
|
19
|
+
MigrationItemsSchema,
|
|
20
|
+
MigrationItemVersion,
|
|
21
|
+
processItemsAsync,
|
|
22
|
+
Writeable
|
|
24
23
|
} from '../core/index.js';
|
|
25
24
|
import { exportTransforms } from '../translation/index.js';
|
|
26
25
|
import { exportContextFetcherAsync } from './context/export-context-fetcher.js';
|
|
26
|
+
import { ExportConfig, ExportContext, ExportItem } from './export.models.js';
|
|
27
27
|
|
|
28
28
|
export function exportManager(config: ExportConfig) {
|
|
29
29
|
const logger = config.logger ?? getDefaultLogger();
|
|
@@ -111,7 +111,7 @@ export function exportManager(config: ExportConfig) {
|
|
|
111
111
|
|
|
112
112
|
model[typeElement.codename] = {
|
|
113
113
|
type: typeElement.type,
|
|
114
|
-
|
|
114
|
+
...getMigrationElementToStore({
|
|
115
115
|
context: context,
|
|
116
116
|
contentType: contentType,
|
|
117
117
|
exportElement: itemElement,
|
|
@@ -123,12 +123,12 @@ export function exportManager(config: ExportConfig) {
|
|
|
123
123
|
}, {});
|
|
124
124
|
};
|
|
125
125
|
|
|
126
|
-
const
|
|
126
|
+
const getMigrationElementToStore = (data: {
|
|
127
127
|
context: ExportContext;
|
|
128
128
|
contentType: FlattenedContentType;
|
|
129
129
|
typeElement: FlattenedContentTypeElement;
|
|
130
130
|
exportElement: ElementModels.ContentItemElement;
|
|
131
|
-
}):
|
|
131
|
+
}): MigrationElementTransformData => {
|
|
132
132
|
try {
|
|
133
133
|
return exportTransforms[data.typeElement.type]({
|
|
134
134
|
context: data.context,
|
|
@@ -136,7 +136,8 @@ export function exportManager(config: ExportConfig) {
|
|
|
136
136
|
exportElement: {
|
|
137
137
|
components: data.exportElement.components.map((component) => mapToMigrationComponent(data.context, component)),
|
|
138
138
|
value: data.exportElement.value,
|
|
139
|
-
urlSlugMode: data.exportElement.mode
|
|
139
|
+
urlSlugMode: data.exportElement.mode,
|
|
140
|
+
displayTimezone: data.exportElement.display_timezone
|
|
140
141
|
}
|
|
141
142
|
});
|
|
142
143
|
} catch (error) {
|
|
@@ -204,7 +205,7 @@ export function exportManager(config: ExportConfig) {
|
|
|
204
205
|
filename: asset.fileName,
|
|
205
206
|
title: asset.title ?? '',
|
|
206
207
|
codename: asset.codename,
|
|
207
|
-
|
|
208
|
+
binary_data: binaryData.data,
|
|
208
209
|
collection: assetCollection ? { codename: assetCollection.codename } : undefined,
|
|
209
210
|
folder: assetFolder ? { codename: assetFolder.codename } : undefined,
|
|
210
211
|
descriptions: asset.descriptions.map((description) => {
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
AssetFolderModels,
|
|
3
|
+
CollectionModels,
|
|
4
|
+
ContentItemModels,
|
|
5
|
+
LanguageModels,
|
|
6
|
+
LanguageVariantModels,
|
|
7
|
+
ManagementClient,
|
|
8
|
+
SharedModels,
|
|
9
|
+
TaxonomyModels,
|
|
10
|
+
WorkflowModels
|
|
11
|
+
} from '@kontent-ai/management-sdk';
|
|
12
|
+
import {
|
|
4
13
|
AssetStateInSourceEnvironmentById,
|
|
14
|
+
FlattenedContentType,
|
|
5
15
|
FlattenedContentTypeElement,
|
|
6
16
|
ItemStateInSourceEnvironmentById,
|
|
7
|
-
|
|
8
|
-
|
|
17
|
+
Logger,
|
|
18
|
+
ManagementClientConfig,
|
|
9
19
|
MigrationComponent,
|
|
20
|
+
MigrationElementTransformData,
|
|
10
21
|
MigrationUrlSlugMode,
|
|
11
|
-
|
|
22
|
+
ReferencedDataInLanguageVariants
|
|
12
23
|
} from '../core/index.js';
|
|
13
|
-
import {
|
|
14
|
-
LanguageVariantModels,
|
|
15
|
-
ContentItemModels,
|
|
16
|
-
WorkflowModels,
|
|
17
|
-
CollectionModels,
|
|
18
|
-
LanguageModels,
|
|
19
|
-
TaxonomyModels,
|
|
20
|
-
ManagementClient,
|
|
21
|
-
SharedModels,
|
|
22
|
-
AssetFolderModels
|
|
23
|
-
} from '@kontent-ai/management-sdk';
|
|
24
24
|
|
|
25
25
|
export interface ExportContextEnvironmentData {
|
|
26
26
|
readonly languages: readonly Readonly<LanguageModels.LanguageModel>[];
|
|
@@ -37,13 +37,14 @@ export interface ExportElement {
|
|
|
37
37
|
readonly value: ExportElementValue;
|
|
38
38
|
readonly components: readonly MigrationComponent[];
|
|
39
39
|
readonly urlSlugMode: MigrationUrlSlugMode | undefined;
|
|
40
|
+
readonly displayTimezone: string | undefined;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
export type ExportTransformFunc = (data: {
|
|
43
44
|
readonly typeElement: FlattenedContentTypeElement;
|
|
44
45
|
readonly exportElement: ExportElement;
|
|
45
46
|
readonly context: ExportContext;
|
|
46
|
-
}) =>
|
|
47
|
+
}) => MigrationElementTransformData;
|
|
47
48
|
|
|
48
49
|
export interface ExportContext {
|
|
49
50
|
readonly environmentData: ExportContextEnvironmentData;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssetFolderModels, AssetModels, CollectionModels, LanguageModels } from '@kontent-ai/management-sdk';
|
|
2
|
-
import { MigrationAsset, MigrationAssetDescription, findRequired, geSizeInBytes } from '../../core/index.js';
|
|
3
2
|
import deepEqual from 'deep-equal';
|
|
3
|
+
import { MigrationAsset, MigrationAssetDescription, findRequired, geSizeInBytes } from '../../core/index.js';
|
|
4
4
|
|
|
5
5
|
export function shouldUpdateAsset(data: {
|
|
6
6
|
readonly migrationAsset: MigrationAsset;
|
|
@@ -29,7 +29,7 @@ function isBinaryFileIdentical(data: {
|
|
|
29
29
|
readonly migrationAsset: MigrationAsset;
|
|
30
30
|
readonly targetAsset: Readonly<AssetModels.Asset>;
|
|
31
31
|
}): boolean {
|
|
32
|
-
const sourceFileSize = geSizeInBytes(data.migrationAsset.
|
|
32
|
+
const sourceFileSize = geSizeInBytes(data.migrationAsset.binary_data);
|
|
33
33
|
const targetFileSize = data.targetAsset.size;
|
|
34
34
|
|
|
35
35
|
const sourceFilename = data.migrationAsset.filename;
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MigrationItem,
|
|
3
|
-
MigrationAsset,
|
|
4
|
-
Logger,
|
|
5
|
-
AssetStateInTargetEnvironmentByCodename,
|
|
6
|
-
ItemStateInTargetEnvironmentByCodename,
|
|
7
|
-
ReferencedDataInMigrationItems,
|
|
8
|
-
LanguageVariantStateInTargetEnvironmentByCodename,
|
|
9
|
-
ExternalIdGenerator,
|
|
10
|
-
FlattenedContentTypeElement,
|
|
11
|
-
MigrationElementValue,
|
|
12
|
-
MigrationElementType,
|
|
13
|
-
MigrationData,
|
|
14
|
-
ManagementClientConfig,
|
|
15
|
-
FlattenedContentType
|
|
16
|
-
} from '../core/index.js';
|
|
17
1
|
import {
|
|
18
2
|
AssetFolderModels,
|
|
19
3
|
AssetModels,
|
|
@@ -25,6 +9,22 @@ import {
|
|
|
25
9
|
ManagementClient,
|
|
26
10
|
WorkflowModels
|
|
27
11
|
} from '@kontent-ai/management-sdk';
|
|
12
|
+
import {
|
|
13
|
+
AssetStateInTargetEnvironmentByCodename,
|
|
14
|
+
ExternalIdGenerator,
|
|
15
|
+
FlattenedContentType,
|
|
16
|
+
FlattenedContentTypeElement,
|
|
17
|
+
ItemStateInTargetEnvironmentByCodename,
|
|
18
|
+
LanguageVariantStateInTargetEnvironmentByCodename,
|
|
19
|
+
Logger,
|
|
20
|
+
ManagementClientConfig,
|
|
21
|
+
MigrationAsset,
|
|
22
|
+
MigrationData,
|
|
23
|
+
MigrationElementTransformData,
|
|
24
|
+
MigrationElementType,
|
|
25
|
+
MigrationItem,
|
|
26
|
+
ReferencedDataInMigrationItems
|
|
27
|
+
} from '../core/index.js';
|
|
28
28
|
|
|
29
29
|
export interface ImportContextConfig {
|
|
30
30
|
readonly logger: Logger;
|
|
@@ -66,7 +66,7 @@ export interface ImportContext {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export type ImportTransformFunc = (data: {
|
|
69
|
-
readonly
|
|
69
|
+
readonly elementData: MigrationElementTransformData;
|
|
70
70
|
readonly elementCodename: string;
|
|
71
71
|
readonly importContext: ImportContext;
|
|
72
72
|
readonly migrationItems: readonly MigrationItem[];
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { AssetModels, ManagementClient, SharedContracts } from '@kontent-ai/management-sdk';
|
|
1
|
+
import { AssetModels, LanguageModels, ManagementClient, SharedContracts } from '@kontent-ai/management-sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import mime from 'mime';
|
|
2
4
|
import {
|
|
3
|
-
|
|
5
|
+
geSizeInBytes,
|
|
6
|
+
isNotUndefined,
|
|
4
7
|
Logger,
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
LogSpinnerData,
|
|
9
|
+
MigrationAsset,
|
|
7
10
|
MigrationAssetDescription,
|
|
8
11
|
MigrationReference,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
LogSpinnerData
|
|
12
|
+
processItemsAsync,
|
|
13
|
+
runMapiRequestAsync
|
|
12
14
|
} from '../../core/index.js';
|
|
13
|
-
import mime from 'mime';
|
|
14
|
-
import chalk from 'chalk';
|
|
15
|
-
import { ImportContext, ImportResult } from '../import.models.js';
|
|
16
15
|
import { shouldReplaceBinaryFile, shouldUpdateAsset } from '../comparers/asset-comparer.js';
|
|
16
|
+
import { ImportContext, ImportResult } from '../import.models.js';
|
|
17
17
|
|
|
18
18
|
interface AssetToEdit {
|
|
19
19
|
migrationAsset: MigrationAsset;
|
|
@@ -27,9 +27,11 @@ export function assetsImporter(data: {
|
|
|
27
27
|
readonly importContext: ImportContext;
|
|
28
28
|
}) {
|
|
29
29
|
const getAssetsToUpload = (): readonly MigrationAsset[] => {
|
|
30
|
-
return data.importContext.categorizedImportData.assets
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
return data.importContext.categorizedImportData.assets
|
|
31
|
+
.filter((asset) => {
|
|
32
|
+
return data.importContext.getAssetStateInTargetEnvironment(asset.codename).state === 'doesNotExists';
|
|
33
|
+
})
|
|
34
|
+
.map((asset) => ({ ...asset, descriptions: asset.descriptions?.filter(filterInvalidLanguages) }));
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
const getAssetsToEdit = (): readonly AssetToEdit[] => {
|
|
@@ -54,7 +56,10 @@ export function assetsImporter(data: {
|
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
return {
|
|
57
|
-
migrationAsset:
|
|
59
|
+
migrationAsset: {
|
|
60
|
+
...migrationAsset,
|
|
61
|
+
descriptions: migrationAsset.descriptions?.filter(filterInvalidLanguages)
|
|
62
|
+
},
|
|
58
63
|
replaceBinaryFile: shouldReplaceBinaryFile({
|
|
59
64
|
migrationAsset: migrationAsset,
|
|
60
65
|
targetAsset: assetState.asset
|
|
@@ -117,6 +122,10 @@ export function assetsImporter(data: {
|
|
|
117
122
|
});
|
|
118
123
|
};
|
|
119
124
|
|
|
125
|
+
const filterInvalidLanguages = (description: MigrationAssetDescription): Readonly<LanguageModels.LanguageModel> | undefined => {
|
|
126
|
+
return data.importContext.environmentData.languages.find((lang) => lang.codename === description.language.codename);
|
|
127
|
+
};
|
|
128
|
+
|
|
120
129
|
const mapAssetCollection = (
|
|
121
130
|
migrationCollection: MigrationReference | undefined
|
|
122
131
|
): Readonly<AssetModels.IAssetCollectionReferenceObject> | undefined => {
|
|
@@ -165,8 +174,8 @@ export function assetsImporter(data: {
|
|
|
165
174
|
await data.client
|
|
166
175
|
.uploadBinaryFile()
|
|
167
176
|
.withData({
|
|
168
|
-
binaryData: migrationAsset.
|
|
169
|
-
contentLength: geSizeInBytes(migrationAsset.
|
|
177
|
+
binaryData: migrationAsset.binary_data,
|
|
178
|
+
contentLength: geSizeInBytes(migrationAsset.binary_data),
|
|
170
179
|
contentType: mime.getType(migrationAsset.filename) ?? '',
|
|
171
180
|
filename: migrationAsset.filename
|
|
172
181
|
})
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { match } from 'ts-pattern';
|
|
2
1
|
import { ContentItemModels, ElementContracts, LanguageVariantModels, ManagementClient, WorkflowModels } from '@kontent-ai/management-sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { match } from 'ts-pattern';
|
|
3
4
|
import {
|
|
5
|
+
findRequired,
|
|
6
|
+
isNotUndefined,
|
|
7
|
+
LanguageVariantSchedulesStateValues,
|
|
8
|
+
LanguageVariantStateInTargetEnvironmentByCodename,
|
|
4
9
|
Logger,
|
|
5
|
-
processItemsAsync,
|
|
6
|
-
runMapiRequestAsync,
|
|
7
|
-
MigrationItem,
|
|
8
10
|
LogSpinnerData,
|
|
9
11
|
MigrationElement,
|
|
12
|
+
MigrationItem,
|
|
10
13
|
MigrationItemVersion,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
LanguageVariantSchedulesStateValues,
|
|
15
|
-
LanguageVariantStateInTargetEnvironmentByCodename
|
|
14
|
+
processItemsAsync,
|
|
15
|
+
runMapiRequestAsync,
|
|
16
|
+
workflowHelper
|
|
16
17
|
} from '../../core/index.js';
|
|
17
|
-
import chalk from 'chalk';
|
|
18
|
-
import { ImportContext } from '../import.models.js';
|
|
19
18
|
import { importTransforms } from '../../translation/index.js';
|
|
20
|
-
import {
|
|
19
|
+
import { ImportContext } from '../import.models.js';
|
|
21
20
|
import { throwErrorForMigrationItem } from '../utils/import.utils.js';
|
|
21
|
+
import { workflowImporter as workflowImporterInit } from './workflow-importer.js';
|
|
22
22
|
|
|
23
23
|
export function languageVariantImporter(config: {
|
|
24
24
|
readonly logger: Logger;
|
|
@@ -290,7 +290,7 @@ export function languageVariantImporter(config: {
|
|
|
290
290
|
elementCodename: elementCodename,
|
|
291
291
|
importContext: config.importContext,
|
|
292
292
|
migrationItems: config.importContext.categorizedImportData.contentItems,
|
|
293
|
-
|
|
293
|
+
elementData: element
|
|
294
294
|
});
|
|
295
295
|
|
|
296
296
|
return importTransformResult;
|
package/lib/metadata.ts
CHANGED
package/lib/toolkit/file.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { defaultZipFilename, executeWithTrackingAsync, getDefaultLogger, Logger, MigrationData } from '../core/index.js';
|
|
1
3
|
import { fileManager } from '../file/index.js';
|
|
2
|
-
import { Logger, executeWithTrackingAsync, defaultZipFilename, getDefaultLogger, MigrationData } from '../core/index.js';
|
|
3
|
-
import { zipManager } from '../zip/index.js';
|
|
4
4
|
import { libMetadata } from '../metadata.js';
|
|
5
|
+
import { zipManager } from '../zip/index.js';
|
|
5
6
|
|
|
6
7
|
export interface StoreConfig {
|
|
7
8
|
readonly data: MigrationData;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ElementModels } from '@kontent-ai/management-sdk';
|
|
2
|
+
import { GetFlattenedElementByIds } from 'lib/export/export.models.js';
|
|
3
|
+
import { match, P } from 'ts-pattern';
|
|
2
4
|
import {
|
|
3
5
|
MigrationElementModels,
|
|
4
6
|
MigrationElements,
|
|
7
|
+
parseAsMigrationReferencesArray,
|
|
5
8
|
ReferencedDataInLanguageVariants,
|
|
6
|
-
ReferencedDataInMigrationItems
|
|
7
|
-
parseAsMigrationReferencesArray
|
|
9
|
+
ReferencedDataInMigrationItems
|
|
8
10
|
} from '../../core/index.js';
|
|
9
11
|
import { GetFlattenedElementByCodenames } from '../../import/index.js';
|
|
10
|
-
import {
|
|
11
|
-
import { GetFlattenedElementByIds } from 'lib/export/export.models.js';
|
|
12
|
-
import { match, P } from 'ts-pattern';
|
|
12
|
+
import { richTextProcessor } from '../index.js';
|
|
13
13
|
|
|
14
14
|
export interface ExtractItemById {
|
|
15
15
|
readonly elements: Readonly<ElementModels.ContentItemElement>[];
|
|
@@ -59,6 +59,10 @@ export function itemsExtractionProcessor() {
|
|
|
59
59
|
.processAssetIds(rteValue ?? '')
|
|
60
60
|
.ids.forEach((id) => extractedIds.assetIds.add(id));
|
|
61
61
|
|
|
62
|
+
richTextProcessor()
|
|
63
|
+
.processLinkAssetIds(rteValue ?? '')
|
|
64
|
+
.ids.forEach((id) => extractedIds.assetIds.add(id));
|
|
65
|
+
|
|
62
66
|
// recursively extract data from components as well because they may reference additional assets & content items
|
|
63
67
|
const extractedComponents = extractReferencedDataFromExtractItems(
|
|
64
68
|
itemElement.components.map((component) => {
|
|
@@ -106,11 +110,10 @@ export function itemsExtractionProcessor() {
|
|
|
106
110
|
return Object.entries(item.elements).reduce<ReferencedDataInMigrationItemsLocal>(
|
|
107
111
|
(childExtractedCodenames, [elementCodename, element]) => {
|
|
108
112
|
const flattenedElement = getElement(item.contentTypeCodename, elementCodename, element.type);
|
|
109
|
-
|
|
110
113
|
match(flattenedElement.type)
|
|
111
114
|
.with('rich_text', () => {
|
|
112
115
|
const richTextElementValue = element as MigrationElementModels.RichTextElement;
|
|
113
|
-
const richTextHtml = richTextElementValue
|
|
116
|
+
const richTextHtml = richTextElementValue?.value ?? '';
|
|
114
117
|
|
|
115
118
|
// items
|
|
116
119
|
richTextProcessor()
|
|
@@ -126,9 +129,13 @@ export function itemsExtractionProcessor() {
|
|
|
126
129
|
.processAssetCodenames(richTextHtml)
|
|
127
130
|
.codenames.forEach((codename) => childExtractedCodenames.assetCodenames.add(codename));
|
|
128
131
|
|
|
132
|
+
richTextProcessor()
|
|
133
|
+
.processLinkAssetCodenames(richTextHtml)
|
|
134
|
+
.codenames.forEach((codename) => childExtractedCodenames.assetCodenames.add(codename));
|
|
135
|
+
|
|
129
136
|
// recursively extract data from components as well because they may reference additional assets & content items
|
|
130
137
|
const extractedComponents = extractReferencedItemsFromMigrationItems(
|
|
131
|
-
(
|
|
138
|
+
(element.components ?? []).map((component) => {
|
|
132
139
|
const extractionItem: ExtractItemByCodename = {
|
|
133
140
|
contentTypeCodename: component.system.type.codename,
|
|
134
141
|
elements: component.elements
|
|
@@ -126,6 +126,42 @@ export function richTextProcessor() {
|
|
|
126
126
|
};
|
|
127
127
|
};
|
|
128
128
|
|
|
129
|
+
const processLinkAssetIds = (richTextHtml: string, replaceFunc?: IdReplaceFunc): ProcessIdsResult => {
|
|
130
|
+
const assetIds = new Set<string>();
|
|
131
|
+
|
|
132
|
+
if (!richTextHtml) {
|
|
133
|
+
return {
|
|
134
|
+
html: richTextHtml,
|
|
135
|
+
ids: assetIds
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
richTextHtml = richTextHtml.replaceAll(rteRegexes.elements.linkTagRegex, (linkTag) => {
|
|
140
|
+
const assetIdMatch = linkTag.match(rteRegexes.ids.dataAssetIdAttrRegex);
|
|
141
|
+
if (assetIdMatch && (assetIdMatch?.length ?? 0) >= 2) {
|
|
142
|
+
const assetId = assetIdMatch[1];
|
|
143
|
+
|
|
144
|
+
assetIds.add(assetId);
|
|
145
|
+
|
|
146
|
+
if (replaceFunc) {
|
|
147
|
+
const { codename } = replaceFunc(assetId);
|
|
148
|
+
|
|
149
|
+
return linkTag.replaceAll(
|
|
150
|
+
`${attributes.ids.assetIdAttributeName}="${assetId}"`,
|
|
151
|
+
`${attributes.codenames.assetCodenameAttribute}="${codename}"`
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return linkTag;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
html: richTextHtml,
|
|
161
|
+
ids: assetIds
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
|
|
129
165
|
const processLinkItemIds = (richTextHtml: string, replaceFunc?: IdReplaceFunc): ProcessIdsResult => {
|
|
130
166
|
const linkItemIds = new Set<string>();
|
|
131
167
|
|
|
@@ -288,13 +324,57 @@ export function richTextProcessor() {
|
|
|
288
324
|
html: richTextHtml
|
|
289
325
|
};
|
|
290
326
|
};
|
|
327
|
+
|
|
328
|
+
const processLinkAssetCodenames = (
|
|
329
|
+
richTextHtml: string,
|
|
330
|
+
replaceFunc?: CodenameReplaceFunc<AssetStateInTargetEnvironmentByCodename>
|
|
331
|
+
): ProcessCodenamesResult => {
|
|
332
|
+
const assetCodenames = new Set<string>();
|
|
333
|
+
|
|
334
|
+
if (!richTextHtml) {
|
|
335
|
+
return {
|
|
336
|
+
codenames: assetCodenames,
|
|
337
|
+
html: richTextHtml
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
richTextHtml = richTextHtml.replaceAll(rteRegexes.elements.linkTagRegex, (linkTag) => {
|
|
342
|
+
const codenameMatch = linkTag.match(rteRegexes.codenames.rteAssetCodenameRegex);
|
|
343
|
+
if (codenameMatch && (codenameMatch?.length ?? 0) >= 2) {
|
|
344
|
+
const codename = codenameMatch[1];
|
|
345
|
+
|
|
346
|
+
assetCodenames.add(codename);
|
|
347
|
+
|
|
348
|
+
if (replaceFunc) {
|
|
349
|
+
const assetState = replaceFunc(codename);
|
|
350
|
+
|
|
351
|
+
if (assetState.asset && assetState.state === 'exists') {
|
|
352
|
+
return linkTag;
|
|
353
|
+
}
|
|
354
|
+
return linkTag.replaceAll(
|
|
355
|
+
`${attributes.codenames.assetCodenameAttribute}="${codename}"`,
|
|
356
|
+
`${attributes.ids.externalAssetIdAttributeName}="${assetState.externalIdToUse}"`
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return linkTag;
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
return {
|
|
365
|
+
codenames: assetCodenames,
|
|
366
|
+
html: richTextHtml
|
|
367
|
+
};
|
|
368
|
+
};
|
|
291
369
|
|
|
292
370
|
return {
|
|
293
371
|
processAssetIds,
|
|
294
372
|
processDataIds,
|
|
295
373
|
processLinkItemIds,
|
|
374
|
+
processLinkAssetIds,
|
|
296
375
|
processAssetCodenames,
|
|
297
376
|
processItemCodenames,
|
|
298
|
-
processLinkItemCodenames
|
|
377
|
+
processLinkItemCodenames,
|
|
378
|
+
processLinkAssetCodenames
|
|
299
379
|
};
|
|
300
380
|
}
|