@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.
Files changed (239) hide show
  1. package/README.md +19 -17
  2. package/dist/core/config.js +3 -3
  3. package/dist/core/config.js.map +1 -1
  4. package/dist/core/helpers/workflow-helper.d.ts +1 -1
  5. package/dist/core/helpers/workflow-helper.js +28 -26
  6. package/dist/core/helpers/workflow-helper.js.map +1 -1
  7. package/dist/core/logs/loggers.d.ts +1 -1
  8. package/dist/core/logs/loggers.js +15 -15
  9. package/dist/core/logs/loggers.js.map +1 -1
  10. package/dist/core/models/core.models.d.ts +29 -22
  11. package/dist/core/models/error.models.d.ts +26 -0
  12. package/dist/core/models/error.models.js +104 -0
  13. package/dist/core/models/error.models.js.map +1 -0
  14. package/dist/core/models/log.models.d.ts +2 -2
  15. package/dist/core/models/migration.models.d.ts +17 -19
  16. package/dist/core/models/migration.schema.d.ts +9 -9
  17. package/dist/core/models/migration.schema.js +28 -28
  18. package/dist/core/models/migration.schema.js.map +1 -1
  19. package/dist/core/utils/array.utils.d.ts +1 -1
  20. package/dist/core/utils/array.utils.js +4 -3
  21. package/dist/core/utils/array.utils.js.map +1 -1
  22. package/dist/core/utils/binary-data.utils.d.ts +1 -1
  23. package/dist/core/utils/binary-data.utils.js +6 -6
  24. package/dist/core/utils/binary-data.utils.js.map +1 -1
  25. package/dist/core/utils/confirm.utils.d.ts +3 -1
  26. package/dist/core/utils/confirm.utils.js +92 -24
  27. package/dist/core/utils/confirm.utils.js.map +1 -1
  28. package/dist/core/utils/error.utils.d.ts +1 -1
  29. package/dist/core/utils/error.utils.js +16 -14
  30. package/dist/core/utils/error.utils.js.map +1 -1
  31. package/dist/core/utils/external-id.utils.js +1 -1
  32. package/dist/core/utils/external-id.utils.js.map +1 -1
  33. package/dist/core/utils/global.utils.d.ts +3 -3
  34. package/dist/core/utils/global.utils.js +20 -18
  35. package/dist/core/utils/global.utils.js.map +1 -1
  36. package/dist/core/utils/http.utils.d.ts +2 -2
  37. package/dist/core/utils/http.utils.js +4 -4
  38. package/dist/core/utils/http.utils.js.map +1 -1
  39. package/dist/core/utils/management-client-utils.d.ts +4 -4
  40. package/dist/core/utils/management-client-utils.js +37 -34
  41. package/dist/core/utils/management-client-utils.js.map +1 -1
  42. package/dist/core/utils/processing-utils.d.ts +4 -4
  43. package/dist/core/utils/processing-utils.js +13 -13
  44. package/dist/core/utils/processing-utils.js.map +1 -1
  45. package/dist/core/utils/run.utils.d.ts +2 -2
  46. package/dist/core/utils/run.utils.js +7 -7
  47. package/dist/core/utils/run.utils.js.map +1 -1
  48. package/dist/core/utils/try.utils.d.ts +14 -0
  49. package/dist/core/utils/try.utils.js +18 -0
  50. package/dist/core/utils/try.utils.js.map +1 -0
  51. package/dist/export/context/export-context-fetcher.d.ts +1 -1
  52. package/dist/export/context/export-context-fetcher.js +92 -62
  53. package/dist/export/context/export-context-fetcher.js.map +1 -1
  54. package/dist/export/export-manager.d.ts +2 -2
  55. package/dist/export/export-manager.js +73 -59
  56. package/dist/export/export-manager.js.map +1 -1
  57. package/dist/export/export.models.d.ts +21 -2
  58. package/dist/export/utils/export.utils.d.ts +1 -1
  59. package/dist/export/utils/export.utils.js +3 -2
  60. package/dist/export/utils/export.utils.js.map +1 -1
  61. package/dist/file/file-manager.d.ts +2 -2
  62. package/dist/file/file-manager.js +7 -7
  63. package/dist/file/file-manager.js.map +1 -1
  64. package/dist/import/comparers/asset-comparer.d.ts +2 -2
  65. package/dist/import/comparers/asset-comparer.js +12 -11
  66. package/dist/import/comparers/asset-comparer.js.map +1 -1
  67. package/dist/import/context/import-context-fetcher.d.ts +1 -1
  68. package/dist/import/context/import-context-fetcher.js +77 -73
  69. package/dist/import/context/import-context-fetcher.js.map +1 -1
  70. package/dist/import/import-manager.d.ts +1 -1
  71. package/dist/import/import-manager.js +59 -56
  72. package/dist/import/import-manager.js.map +1 -1
  73. package/dist/import/import.models.d.ts +6 -2
  74. package/dist/import/importers/assets-importer.d.ts +3 -3
  75. package/dist/import/importers/assets-importer.js +46 -43
  76. package/dist/import/importers/assets-importer.js.map +1 -1
  77. package/dist/import/importers/content-items-importer.d.ts +3 -3
  78. package/dist/import/importers/content-items-importer.js +28 -25
  79. package/dist/import/importers/content-items-importer.js.map +1 -1
  80. package/dist/import/importers/language-variant-importer.d.ts +3 -3
  81. package/dist/import/importers/language-variant-importer.js +45 -45
  82. package/dist/import/importers/language-variant-importer.js.map +1 -1
  83. package/dist/import/importers/workflow-importer.d.ts +3 -2
  84. package/dist/import/importers/workflow-importer.js +58 -54
  85. package/dist/import/importers/workflow-importer.js.map +1 -1
  86. package/dist/import/utils/import.utils.d.ts +1 -1
  87. package/dist/import/utils/import.utils.js +3 -2
  88. package/dist/import/utils/import.utils.js.map +1 -1
  89. package/dist/index.d.ts +11 -7
  90. package/dist/index.js +10 -8
  91. package/dist/index.js.map +1 -1
  92. package/dist/metadata.js +3 -3
  93. package/dist/metadata.js.map +1 -1
  94. package/dist/node/cli/actions/export-action.d.ts +1 -1
  95. package/dist/node/cli/actions/export-action.js +29 -23
  96. package/dist/node/cli/actions/export-action.js.map +1 -1
  97. package/dist/node/cli/actions/import-action.d.ts +1 -1
  98. package/dist/node/cli/actions/import-action.js +15 -12
  99. package/dist/node/cli/actions/import-action.js.map +1 -1
  100. package/dist/node/cli/actions/migrate-action.d.ts +1 -1
  101. package/dist/node/cli/actions/migrate-action.js +26 -22
  102. package/dist/node/cli/actions/migrate-action.js.map +1 -1
  103. package/dist/node/cli/app.js +13 -12
  104. package/dist/node/cli/app.js.map +1 -1
  105. package/dist/node/cli/args/args-fetcher.d.ts +1 -1
  106. package/dist/node/cli/args/args-fetcher.js +14 -13
  107. package/dist/node/cli/args/args-fetcher.js.map +1 -1
  108. package/dist/node/cli/args/args-setter.d.ts +1 -1
  109. package/dist/node/cli/args/args-setter.js +8 -6
  110. package/dist/node/cli/args/args-setter.js.map +1 -1
  111. package/dist/node/cli/cli.models.d.ts +2 -2
  112. package/dist/node/cli/commands.js +68 -56
  113. package/dist/node/cli/commands.js.map +1 -1
  114. package/dist/toolkit/elements-builder.d.ts +1 -1
  115. package/dist/toolkit/elements-builder.js +12 -12
  116. package/dist/toolkit/elements-builder.js.map +1 -1
  117. package/dist/toolkit/export.d.ts +2 -2
  118. package/dist/toolkit/export.js +8 -8
  119. package/dist/toolkit/export.js.map +1 -1
  120. package/dist/toolkit/file.d.ts +2 -1
  121. package/dist/toolkit/file.js +18 -16
  122. package/dist/toolkit/file.js.map +1 -1
  123. package/dist/toolkit/import.d.ts +1 -1
  124. package/dist/toolkit/import.js +12 -12
  125. package/dist/toolkit/import.js.map +1 -1
  126. package/dist/toolkit/migrate.d.ts +13 -4
  127. package/dist/toolkit/migrate.js +15 -13
  128. package/dist/toolkit/migrate.js.map +1 -1
  129. package/dist/translation/extraction/items-extraction.processor.d.ts +5 -4
  130. package/dist/translation/extraction/items-extraction.processor.js +73 -35
  131. package/dist/translation/extraction/items-extraction.processor.js.map +1 -1
  132. package/dist/translation/helpers/export-placeholder.utils.d.ts +11 -0
  133. package/dist/translation/helpers/export-placeholder.utils.js +11 -0
  134. package/dist/translation/helpers/export-placeholder.utils.js.map +1 -0
  135. package/dist/translation/helpers/rich-text.processor.d.ts +6 -6
  136. package/dist/translation/helpers/rich-text.processor.js +38 -38
  137. package/dist/translation/helpers/rich-text.processor.js.map +1 -1
  138. package/dist/translation/transforms/export-transforms.d.ts +2 -2
  139. package/dist/translation/transforms/export-transforms.js +93 -67
  140. package/dist/translation/transforms/export-transforms.js.map +1 -1
  141. package/dist/translation/transforms/import-transforms.d.ts +2 -2
  142. package/dist/translation/transforms/import-transforms.js +38 -40
  143. package/dist/translation/transforms/import-transforms.js.map +1 -1
  144. package/dist/zip/zip-manager.d.ts +4 -3
  145. package/dist/zip/zip-manager.js +9 -9
  146. package/dist/zip/zip-manager.js.map +1 -1
  147. package/dist/zip/zip-packager.d.ts +2 -2
  148. package/dist/zip/zip-packager.js +19 -17
  149. package/dist/zip/zip-packager.js.map +1 -1
  150. package/dist/zip/zip-transformer.d.ts +3 -2
  151. package/dist/zip/zip-transformer.js +16 -15
  152. package/dist/zip/zip-transformer.js.map +1 -1
  153. package/dist/zip/zip.models.d.ts +2 -2
  154. package/lib/core/config.ts +6 -6
  155. package/lib/core/helpers/workflow-helper.ts +190 -185
  156. package/lib/core/logs/loggers.ts +52 -52
  157. package/lib/core/models/core.models.ts +130 -119
  158. package/lib/core/models/error.models.ts +148 -0
  159. package/lib/core/models/log.models.ts +20 -20
  160. package/lib/core/models/migration.models.ts +54 -57
  161. package/lib/core/models/migration.schema.ts +108 -108
  162. package/lib/core/utils/array.utils.ts +43 -42
  163. package/lib/core/utils/binary-data.utils.ts +16 -16
  164. package/lib/core/utils/confirm.utils.ts +184 -106
  165. package/lib/core/utils/error.utils.ts +69 -72
  166. package/lib/core/utils/external-id.utils.ts +4 -4
  167. package/lib/core/utils/global.utils.ts +81 -75
  168. package/lib/core/utils/http.utils.ts +23 -23
  169. package/lib/core/utils/management-client-utils.ts +189 -186
  170. package/lib/core/utils/processing-utils.ts +82 -82
  171. package/lib/core/utils/run.utils.ts +50 -50
  172. package/lib/core/utils/try.utils.ts +30 -0
  173. package/lib/export/context/export-context-fetcher.ts +472 -447
  174. package/lib/export/export-manager.ts +250 -232
  175. package/lib/export/export.models.ts +71 -56
  176. package/lib/export/utils/export.utils.ts +9 -7
  177. package/lib/file/file-manager.ts +28 -28
  178. package/lib/import/comparers/asset-comparer.ts +107 -106
  179. package/lib/import/context/import-context-fetcher.ts +462 -462
  180. package/lib/import/import-manager.ts +243 -240
  181. package/lib/import/import.models.ts +69 -67
  182. package/lib/import/importers/assets-importer.ts +240 -236
  183. package/lib/import/importers/content-items-importer.ts +126 -122
  184. package/lib/import/importers/language-variant-importer.ts +324 -328
  185. package/lib/import/importers/workflow-importer.ts +372 -367
  186. package/lib/import/utils/import.utils.ts +9 -7
  187. package/lib/index.ts +12 -8
  188. package/lib/metadata.ts +3 -4
  189. package/lib/node/cli/actions/export-action.ts +44 -38
  190. package/lib/node/cli/actions/import-action.ts +32 -29
  191. package/lib/node/cli/actions/migrate-action.ts +50 -46
  192. package/lib/node/cli/app.ts +21 -21
  193. package/lib/node/cli/args/args-fetcher.ts +55 -54
  194. package/lib/node/cli/args/args-setter.ts +34 -32
  195. package/lib/node/cli/cli.models.ts +17 -17
  196. package/lib/node/cli/commands.ts +165 -153
  197. package/lib/toolkit/elements-builder.ts +69 -69
  198. package/lib/toolkit/export.ts +21 -21
  199. package/lib/toolkit/file.ts +59 -53
  200. package/lib/toolkit/import.ts +32 -32
  201. package/lib/toolkit/migrate.ts +60 -49
  202. package/lib/translation/extraction/items-extraction.processor.ts +203 -173
  203. package/lib/translation/helpers/export-placeholder.utils.ts +10 -0
  204. package/lib/translation/helpers/rich-text.processor.ts +311 -311
  205. package/lib/translation/transforms/export-transforms.ts +313 -279
  206. package/lib/translation/transforms/import-transforms.ts +188 -191
  207. package/lib/zip/zip-manager.ts +28 -27
  208. package/lib/zip/zip-packager.ts +75 -73
  209. package/lib/zip/zip-transformer.ts +112 -107
  210. package/lib/zip/zip.models.ts +7 -7
  211. package/package.json +91 -84
  212. package/dist/core/index.d.ts +0 -16
  213. package/dist/core/index.js +0 -17
  214. package/dist/core/index.js.map +0 -1
  215. package/dist/export/index.d.ts +0 -2
  216. package/dist/export/index.js +0 -3
  217. package/dist/export/index.js.map +0 -1
  218. package/dist/file/index.d.ts +0 -1
  219. package/dist/file/index.js +0 -2
  220. package/dist/file/index.js.map +0 -1
  221. package/dist/import/index.d.ts +0 -2
  222. package/dist/import/index.js +0 -3
  223. package/dist/import/index.js.map +0 -1
  224. package/dist/toolkit/index.d.ts +0 -5
  225. package/dist/toolkit/index.js +0 -6
  226. package/dist/toolkit/index.js.map +0 -1
  227. package/dist/translation/index.d.ts +0 -4
  228. package/dist/translation/index.js +0 -5
  229. package/dist/translation/index.js.map +0 -1
  230. package/dist/zip/index.d.ts +0 -4
  231. package/dist/zip/index.js +0 -5
  232. package/dist/zip/index.js.map +0 -1
  233. package/lib/core/index.ts +0 -18
  234. package/lib/export/index.ts +0 -2
  235. package/lib/file/index.ts +0 -1
  236. package/lib/import/index.ts +0 -2
  237. package/lib/toolkit/index.ts +0 -5
  238. package/lib/translation/index.ts +0 -4
  239. package/lib/zip/index.ts +0 -4
@@ -1,169 +1,180 @@
1
1
  import type {
2
- AssetModels,
3
- ContentItemModels,
4
- ContentTypeElements,
5
- LanguageVariantModels,
6
- WorkflowModels
7
- } from '@kontent-ai/management-sdk';
8
- import type { MigrationElementType } from './migration.models.js';
2
+ AssetModels,
3
+ ContentItemModels,
4
+ ContentTypeElements,
5
+ LanguageVariantModels,
6
+ WorkflowModels,
7
+ } from "@kontent-ai/management-sdk";
8
+ import type { MigrationElementType } from "./migration.models.js";
9
9
 
10
10
  export type LiteralUnion<T extends string> = T | (string & {});
11
- export type TargetItemState = 'exists' | 'doesNotExists';
12
- export type CliAction = 'export' | 'import' | 'migrate';
13
- export type EnvContext = 'browser' | 'node';
11
+ export type TargetItemState = "exists" | "doesNotExists";
12
+ export type CliAction = "export" | "import" | "migrate";
13
+ export type EnvContext = "browser" | "node";
14
14
 
15
15
  export type MapiAction =
16
- | 'list'
17
- | 'view'
18
- | 'archive'
19
- | 'unpublish'
20
- | 'changeWorkflowStep'
21
- | 'publish'
22
- | 'upload'
23
- | 'create'
24
- | 'upsert'
25
- | 'schedulePublish'
26
- | 'scheduleUnpublish'
27
- | 'cancelScheduledPublish'
28
- | 'cancelScheduledUnpublish'
29
- | 'createNewVersion';
30
-
31
- export type MigrationItemType = 'exportItem';
16
+ | "list"
17
+ | "view"
18
+ | "archive"
19
+ | "unpublish"
20
+ | "changeWorkflowStep"
21
+ | "publish"
22
+ | "upload"
23
+ | "create"
24
+ | "upsert"
25
+ | "schedulePublish"
26
+ | "scheduleUnpublish"
27
+ | "cancelScheduledPublish"
28
+ | "cancelScheduledUnpublish"
29
+ | "createNewVersion";
30
+
31
+ export type MigrationItemType = "exportItem";
32
32
 
33
33
  export type MapiType =
34
- | 'contentType'
35
- | 'assetFolder'
36
- | 'asset'
37
- | 'contentTypeSnippet'
38
- | 'contentItem'
39
- | 'languageVariant'
40
- | 'language'
41
- | 'collection'
42
- | 'taxonomy'
43
- | 'binaryFile'
44
- | 'workflow';
45
-
46
- export type LanguageVariantWorkflowStateValues = 'published' | 'archived' | 'draft' | 'scheduled';
47
- export type LanguageVariantSchedulesStateValues = 'scheduledPublish' | 'scheduledUnpublish' | 'n/a';
34
+ | "contentType"
35
+ | "assetFolder"
36
+ | "asset"
37
+ | "contentTypeSnippet"
38
+ | "contentItem"
39
+ | "languageVariant"
40
+ | "language"
41
+ | "collection"
42
+ | "taxonomy"
43
+ | "binaryFile"
44
+ | "workflow";
45
+
46
+ export type LanguageVariantWorkflowStateValues = "published" | "archived" | "draft" | "scheduled";
47
+ export type LanguageVariantSchedulesStateValues = "scheduledPublish" | "scheduledUnpublish" | "n/a";
48
48
  export type LanguageVariantWorkflowState =
49
- | {
50
- readonly workflowState: LanguageVariantWorkflowStateValues;
51
- readonly scheduledState: LanguageVariantSchedulesStateValues;
52
- }
53
- | undefined;
49
+ | {
50
+ readonly workflowState: LanguageVariantWorkflowStateValues;
51
+ readonly scheduledState: LanguageVariantSchedulesStateValues;
52
+ }
53
+ | undefined;
54
54
 
55
55
  export interface ItemInfo {
56
- readonly title: string;
57
- readonly itemType: MapiType | MigrationItemType;
56
+ readonly title: string;
57
+ readonly itemType: MapiType | MigrationItemType;
58
58
  }
59
59
 
60
60
  export interface ErrorData {
61
- readonly message: string;
62
- readonly requestData?: string;
63
- readonly requestUrl?: string;
64
- readonly isUnknownError: boolean;
65
- readonly error: unknown;
61
+ readonly message: string;
62
+ readonly requestData?: string;
63
+ readonly requestUrl?: string;
64
+ readonly isUnknownError: boolean;
65
+ readonly error: unknown;
66
66
  }
67
67
 
68
68
  export interface ReferencedDataInMigrationItems {
69
- readonly itemCodenames: ReadonlySet<string>;
70
- readonly assetCodenames: ReadonlySet<string>;
69
+ readonly itemCodenames: ReadonlySet<string>;
70
+ readonly assetCodenames: ReadonlySet<string>;
71
71
  }
72
72
 
73
73
  export interface ReferencedDataInLanguageVariants {
74
- readonly itemIds: ReadonlySet<string>;
75
- readonly assetIds: ReadonlySet<string>;
74
+ readonly itemIds: ReadonlySet<string>;
75
+ readonly assetIds: ReadonlySet<string>;
76
76
  }
77
77
 
78
- export interface ItemStateInSourceEnvironmentById {
79
- readonly state: TargetItemState;
80
- readonly id: string;
81
- readonly item: Readonly<ContentItemModels.ContentItem> | undefined;
82
- }
83
-
84
- export interface AssetStateInSourceEnvironmentById {
85
- readonly state: TargetItemState;
86
- readonly id: string;
87
- readonly asset: Readonly<AssetModels.Asset> | undefined;
88
- }
78
+ type DataStateInSourceEnvironmentById<T extends Readonly<ContentItemModels.ContentItem> | Readonly<AssetModels.Asset>> = {
79
+ readonly id: string;
80
+ } & (
81
+ | {
82
+ readonly state: "exists";
83
+ readonly data: T;
84
+ }
85
+ | {
86
+ readonly state: "doesNotExists";
87
+ readonly data?: never;
88
+ }
89
+ | {
90
+ readonly state: "skip";
91
+ readonly data?: never;
92
+ }
93
+ );
94
+
95
+ export type ItemStateInSourceEnvironmentById = DataStateInSourceEnvironmentById<Readonly<ContentItemModels.ContentItem>>;
96
+
97
+ export type AssetStateInSourceEnvironmentById = DataStateInSourceEnvironmentById<Readonly<AssetModels.Asset>>;
89
98
 
90
99
  export interface ItemStateInTargetEnvironmentByCodename {
91
- readonly state: TargetItemState;
92
- readonly itemCodename: string;
93
- readonly item: Readonly<ContentItemModels.ContentItem> | undefined;
94
- readonly externalIdToUse: string;
100
+ readonly state: TargetItemState;
101
+ readonly itemCodename: string;
102
+ readonly item: Readonly<ContentItemModels.ContentItem> | undefined;
103
+ readonly externalIdToUse: string;
95
104
  }
96
105
 
97
106
  export interface LanguageVariantStateData {
98
- readonly languageVariant: Readonly<LanguageVariantModels.ContentItemLanguageVariant> | undefined;
99
- readonly workflow: Readonly<WorkflowModels.Workflow> | undefined;
100
- readonly workflowState: LanguageVariantWorkflowState;
107
+ readonly languageVariant: Readonly<LanguageVariantModels.ContentItemLanguageVariant> | undefined;
108
+ readonly workflow: Readonly<WorkflowModels.Workflow> | undefined;
109
+ readonly workflowState: LanguageVariantWorkflowState;
101
110
  }
102
111
 
103
112
  export interface LanguageVariantStateInTargetEnvironmentByCodename {
104
- readonly state: TargetItemState;
105
- readonly itemCodename: string;
106
- readonly languageCodename: string;
107
- readonly publishedLanguageVariant: LanguageVariantStateData | undefined;
108
- readonly draftLanguageVariant: LanguageVariantStateData | undefined;
113
+ readonly state: TargetItemState;
114
+ readonly itemCodename: string;
115
+ readonly languageCodename: string;
116
+ readonly publishedLanguageVariant: LanguageVariantStateData | undefined;
117
+ readonly draftLanguageVariant: LanguageVariantStateData | undefined;
109
118
  }
110
119
 
111
120
  export interface AssetStateInTargetEnvironmentByCodename {
112
- readonly state: TargetItemState;
113
- readonly assetCodename: string;
114
- readonly asset: Readonly<AssetModels.Asset> | undefined;
115
- readonly externalIdToUse: string;
121
+ readonly state: TargetItemState;
122
+ readonly assetCodename: string;
123
+ readonly asset: Readonly<AssetModels.Asset> | undefined;
124
+ readonly externalIdToUse: string;
116
125
  }
117
126
 
118
127
  export interface PackageMetadata {
119
- readonly created: Date;
120
- readonly environmentId: string;
121
- readonly dataOverview: PackageDataOverview;
128
+ readonly created: Date;
129
+ readonly environmentId: string;
130
+ readonly dataOverview: PackageDataOverview;
122
131
  }
123
132
 
124
133
  export interface PackageDataOverview {
125
- readonly contentItemsCount: number;
126
- readonly assetsCount: number;
134
+ readonly contentItemsCount: number;
135
+ readonly assetsCount: number;
127
136
  }
128
137
 
129
138
  export interface FlattenedContentTypeElement {
130
- readonly codename: string;
131
- readonly id: string;
132
- readonly type: MigrationElementType;
133
- readonly element: Readonly<ContentTypeElements.ContentTypeElementModel>;
139
+ readonly codename: string;
140
+ readonly name: string | undefined;
141
+ readonly id: string;
142
+ readonly type: MigrationElementType;
143
+ readonly element: Readonly<ContentTypeElements.ContentTypeElementModel>;
134
144
  }
135
145
 
136
146
  export interface FlattenedContentType {
137
- readonly contentTypeCodename: string;
138
- readonly contentTypeId: string;
139
- readonly elements: readonly FlattenedContentTypeElement[];
147
+ readonly contentTypeCodename: string;
148
+ readonly name: string;
149
+ readonly contentTypeId: string;
150
+ readonly elements: readonly FlattenedContentTypeElement[];
140
151
  }
141
152
 
142
153
  export interface OriginalManagementError {
143
- readonly response?: {
144
- readonly status?: number;
145
- readonly config?: {
146
- readonly url?: string;
147
- readonly data?: string;
148
- };
149
- readonly data?: {
150
- readonly error_code?: number;
151
- };
152
- };
154
+ readonly response?: {
155
+ readonly status?: number;
156
+ readonly config?: {
157
+ readonly url?: string;
158
+ readonly data?: string;
159
+ };
160
+ readonly data?: {
161
+ readonly error_code?: number;
162
+ };
163
+ };
153
164
  }
154
165
 
155
166
  export type ItemProcessingResult<InputItem, OutputItem> =
156
- | {
157
- readonly state: 'valid';
158
- readonly inputItem: InputItem;
159
- readonly outputItem: OutputItem;
160
- }
161
- | {
162
- readonly state: 'error';
163
- readonly inputItem: InputItem;
164
- readonly error: unknown;
165
- }
166
- | {
167
- readonly state: '404';
168
- readonly inputItem: InputItem;
169
- };
167
+ | {
168
+ readonly state: "valid";
169
+ readonly inputItem: InputItem;
170
+ readonly outputItem: OutputItem;
171
+ }
172
+ | {
173
+ readonly state: "error";
174
+ readonly inputItem: InputItem;
175
+ readonly error: unknown;
176
+ }
177
+ | {
178
+ readonly state: "404";
179
+ readonly inputItem: InputItem;
180
+ };
@@ -0,0 +1,148 @@
1
+ import chalk from "chalk";
2
+ import { match, P } from "ts-pattern";
3
+ import type { ExportItem, ExportItemVersion } from "../../export/export.models.js";
4
+ import type { ErrorData, FlattenedContentType, FlattenedContentTypeElement } from "./core.models.js";
5
+
6
+ const missingReferencesMessage = `You can skip missing references using the '${chalk.green("skipMissingReferences")}' option.`;
7
+
8
+ export type MigrationToolkitErrorType =
9
+ | "confirmationRefused"
10
+ | "invalidZip"
11
+ | "invalidFolder"
12
+ | "unsupportedCommand"
13
+ | "importFailedForItem"
14
+ | "invalidElement"
15
+ | "exportFailedForItem"
16
+ | "missingContentType"
17
+ | "invalidEnvironment"
18
+ | "exitProgram"
19
+ | "missingItem"
20
+ | "findRequiredError"
21
+ | "missingWorkflowStep"
22
+ | "missingAsset"
23
+ | "missingTaxonomyTerm"
24
+ | "invalidValue"
25
+ | "invalidMultipleChoiceOption";
26
+
27
+ export class MigrationToolkitError extends Error {
28
+ constructor(
29
+ public readonly type: MigrationToolkitErrorType,
30
+ readonly message: string,
31
+ ) {
32
+ super(message);
33
+ }
34
+ }
35
+
36
+ export class MissingItemError extends MigrationToolkitError {
37
+ constructor(public readonly id: string) {
38
+ super("missingItem", `Missing item with id '${chalk.red(id)}'`);
39
+ }
40
+ }
41
+
42
+ export class MissingAssetError extends MigrationToolkitError {
43
+ constructor(public readonly id: string) {
44
+ super("missingAsset", `Missing asset with id '${chalk.red(id)}'`);
45
+ }
46
+ }
47
+
48
+ export class InvalidValueError extends MigrationToolkitError {
49
+ constructor({
50
+ element,
51
+ value,
52
+ contentType,
53
+ errorData,
54
+ exportItem,
55
+ exportItemVersion,
56
+ }: {
57
+ readonly exportItem: ExportItem;
58
+ readonly exportItemVersion: ExportItemVersion;
59
+ readonly element: FlattenedContentTypeElement;
60
+ readonly contentType: FlattenedContentType;
61
+ readonly value: unknown;
62
+ readonly errorData: ErrorData;
63
+ }) {
64
+ const { missingReferenceId, isMissingReference } = match(errorData.error)
65
+ .returnType<{ readonly missingReferenceId: string | undefined; readonly isMissingReference: boolean }>()
66
+ .when(
67
+ (m) => m instanceof MissingAssetError || m instanceof MissingItemError,
68
+ (m) => {
69
+ return {
70
+ missingReferenceId: m.id,
71
+ isMissingReference: true,
72
+ };
73
+ },
74
+ )
75
+ .otherwise(() => {
76
+ return {
77
+ missingReferenceId: undefined,
78
+ isMissingReference: false,
79
+ };
80
+ });
81
+
82
+ const getValueToDisplay = () => {
83
+ let jsonValue: string | undefined;
84
+
85
+ try {
86
+ jsonValue = JSON.stringify(value, null, 2);
87
+ } catch {
88
+ jsonValue = undefined;
89
+ }
90
+
91
+ const baseValue = match(jsonValue)
92
+ .returnType<string>()
93
+ .with(P.string, (jsonValue) =>
94
+ jsonValue
95
+ .split("\n")
96
+ .map((line) => ` ${line}`)
97
+ .join("\n"),
98
+ )
99
+ .otherwise(() => value?.toString() ?? "");
100
+
101
+ // Highlight missing reference ID in red if present
102
+ return missingReferenceId ? baseValue.replaceAll(missingReferenceId, chalk.red(missingReferenceId)) : baseValue;
103
+ };
104
+
105
+ const lines: readonly string[] = [
106
+ "",
107
+ chalk.red("❌ Invalid value error"),
108
+ "",
109
+ `${chalk.cyan("📝 Content type:")}`,
110
+ ` ${chalk.gray("├─")} Name: ${chalk.yellow.bold(contentType.name)}`,
111
+ ` ${chalk.gray("├─")} Codename: ${chalk.yellow.bold(contentType.contentTypeCodename)}`,
112
+ ` ${chalk.gray("└─")} ID: ${chalk.dim(contentType.contentTypeId)}`,
113
+ "",
114
+ `${chalk.cyan("🔧 Element:")}`,
115
+ ` ${chalk.gray("├─")} Name: ${chalk.yellow.bold(element.name)}`,
116
+ ` ${chalk.gray("├─")} Codename: ${chalk.yellow.bold(element.codename)}`,
117
+ ` ${chalk.gray("├─")} Type: ${chalk.green.bold(element.type)}`,
118
+ ` ${chalk.gray("└─")} ID: ${chalk.dim(element.id)}`,
119
+ "",
120
+ `${chalk.cyan("📦 Item:")}`,
121
+ ` ${chalk.gray("├─")} Item codename: ${chalk.yellow.bold(exportItem.requestItem.itemCodename)}`,
122
+ ` ${chalk.gray("├─")} Language codename: ${chalk.yellow.bold(exportItem.requestItem.languageCodename)}`,
123
+ ` ${chalk.gray("└─")} Version codename: ${chalk.yellow.bold(exportItemVersion.workflowStepCodename)}`,
124
+ "",
125
+ `${chalk.cyan("📦 Item version:")}`,
126
+ ` ${chalk.gray("├─")} Workflow step codename: ${chalk.yellow.bold(exportItemVersion.workflowStepCodename)}`,
127
+ ` ${chalk.gray("└─")} Language variant: ${chalk.yellow.bold(exportItemVersion.languageVariant.language.codename)}`,
128
+ "",
129
+ chalk.cyan("Invalid Value:"),
130
+ chalk.dim(getValueToDisplay()),
131
+ "",
132
+ ...match(errorData.message)
133
+ .returnType<readonly string[]>()
134
+ .with(P.string, (message) => [chalk.cyan("Error Details:"), chalk.gray(` ${message}`), ""])
135
+ .otherwise(() => []),
136
+ ...match(errorData.requestUrl)
137
+ .returnType<readonly string[]>()
138
+ .with(P.string, (requestUrl) => [chalk.cyan("Request URL:"), chalk.gray(` ${requestUrl}`), ""])
139
+ .otherwise(() => []),
140
+ ...match(isMissingReference)
141
+ .returnType<readonly string[]>()
142
+ .with(true, () => [chalk.cyan("💡 Tip:"), chalk.gray(` ${missingReferencesMessage}`), ""])
143
+ .otherwise(() => []),
144
+ ];
145
+
146
+ super("invalidValue", lines.join("\n"));
147
+ }
148
+ }
@@ -1,34 +1,34 @@
1
- import type { MapiAction, MapiType, MigrationItemType } from '../index.js';
1
+ import type { MapiAction, MapiType, MigrationItemType } from "./core.models.js";
2
2
 
3
3
  export type DebugType =
4
- | 'error'
5
- | 'completed'
6
- | 'warning'
7
- | 'info'
8
- | 'errorData'
9
- | 'cancel'
10
- | 'process'
11
- | 'readFs'
12
- | 'skip'
13
- | 'writeFs'
14
- | 'download'
15
- | MigrationItemType
16
- | MapiType
17
- | MapiAction;
4
+ | "error"
5
+ | "completed"
6
+ | "warning"
7
+ | "info"
8
+ | "errorData"
9
+ | "cancel"
10
+ | "process"
11
+ | "readFs"
12
+ | "skip"
13
+ | "writeFs"
14
+ | "download"
15
+ | MigrationItemType
16
+ | MapiType
17
+ | MapiAction;
18
18
 
19
19
  export interface LogMessage {
20
- readonly type?: DebugType;
21
- readonly message: string;
20
+ readonly type?: DebugType;
21
+ readonly message: string;
22
22
  }
23
23
 
24
24
  export interface LogSpinnerMessage extends LogMessage {
25
- readonly prefix?: string;
25
+ readonly prefix?: string;
26
26
  }
27
27
 
28
28
  export type LogData = (data: LogMessage) => void;
29
29
  export type LogSpinnerData = (data: LogSpinnerMessage) => void;
30
30
 
31
31
  export interface Logger {
32
- readonly logWithSpinnerAsync: <T>(func: (logData: LogSpinnerData) => Promise<T>) => Promise<T>;
33
- readonly log: LogData;
32
+ readonly logWithSpinnerAsync: <T>(func: (logData: LogSpinnerData) => Promise<T>) => Promise<T>;
33
+ readonly log: LogData;
34
34
  }
@@ -1,83 +1,80 @@
1
- import type { z } from 'zod';
1
+ import type { z } from "zod";
2
2
  import type {
3
- MigrationAssetDescriptionSchema,
4
- MigrationAssetSchema,
5
- MigrationComponentSchema,
6
- MigrationDataSchema,
7
- MigrationElementSchema,
8
- MigrationElementsSchema,
9
- MigrationElementTypeSchema,
10
- MigrationElementValueSchema,
11
- MigrationItemSchema,
12
- MigrationItemSystemSchema,
13
- MigrationItemVersionSchema,
14
- MigrationReferenceSchema,
15
- MigrationUrlSlugModeSchema
16
- } from './migration.schema.js';
3
+ MigrationAssetDescriptionSchema,
4
+ MigrationAssetSchema,
5
+ MigrationComponentSchema,
6
+ MigrationDataSchema,
7
+ MigrationElementSchema,
8
+ MigrationElementsSchema,
9
+ MigrationElementTypeSchema,
10
+ MigrationElementValueSchema,
11
+ MigrationItemSystemSchema,
12
+ MigrationItemVersionSchema,
13
+ MigrationReferenceSchema,
14
+ MigrationUrlSlugModeSchema,
15
+ } from "./migration.schema.js";
17
16
 
18
17
  export namespace MigrationElementModels {
19
- type MigrationElementDef<
20
- TElementType extends MigrationElementType = MigrationElementType,
21
- TValue extends MigrationElementValue = MigrationElementValue
22
- > = {
23
- readonly value: TValue | undefined;
24
- readonly type: TElementType;
25
- };
18
+ type MigrationElementDef<
19
+ TElementType extends MigrationElementType = MigrationElementType,
20
+ TValue extends MigrationElementValue = MigrationElementValue,
21
+ > = {
22
+ readonly value: TValue | undefined;
23
+ readonly type: TElementType;
24
+ };
26
25
 
27
- export type TextElement = MigrationElementDef<'text', string>;
28
- export type NumberElement = MigrationElementDef<'number', number>;
29
- export type RichTextElement = MigrationElementDef<'rich_text', string> & Pick<MigrationElement, 'components'>;
30
- export type MultipleChoiceElement = MigrationElementDef<'multiple_choice', MigrationReference[]>;
31
- export type DateTimeElement = MigrationElementDef<'date_time', string> & Pick<MigrationElement, 'display_timezone'>;
32
- export type AssetElement = MigrationElementDef<'asset', MigrationReference[]>;
33
- export type LinkedItemsElement = MigrationElementDef<'modular_content', MigrationReference[]>;
34
- export type TaxonomyElement = MigrationElementDef<'taxonomy', MigrationReference[]>;
35
- export type UrlSlugElement = MigrationElementDef<'url_slug', string> & Pick<MigrationElement, 'mode'>;
36
- export type CustomElement = MigrationElementDef<'custom', string>;
37
- export type SubpagesElement = MigrationElementDef<'subpages', MigrationReference[]>;
26
+ export type TextElement = MigrationElementDef<"text", string>;
27
+ export type NumberElement = MigrationElementDef<"number", number>;
28
+ export type RichTextElement = MigrationElementDef<"rich_text", string> & Pick<MigrationElement, "components">;
29
+ export type MultipleChoiceElement = MigrationElementDef<"multiple_choice", MigrationReference[]>;
30
+ export type DateTimeElement = MigrationElementDef<"date_time", string> & Pick<MigrationElement, "display_timezone">;
31
+ export type AssetElement = MigrationElementDef<"asset", MigrationReference[]>;
32
+ export type LinkedItemsElement = MigrationElementDef<"modular_content", MigrationReference[]>;
33
+ export type TaxonomyElement = MigrationElementDef<"taxonomy", MigrationReference[]>;
34
+ export type UrlSlugElement = MigrationElementDef<"url_slug", string> & Pick<MigrationElement, "mode">;
35
+ export type CustomElement = MigrationElementDef<"custom", string>;
36
+ export type SubpagesElement = MigrationElementDef<"subpages", MigrationReference[]>;
38
37
  }
39
38
 
40
- export type MigrationReference<T extends string = string> = z.infer<typeof MigrationReferenceSchema> & {
41
- readonly codename: T;
39
+ export type MigrationReference<T extends string = string> = Omit<z.infer<typeof MigrationReferenceSchema>, "codename"> & {
40
+ readonly codename: T;
42
41
  };
43
42
 
44
43
  export type MigrationItemSystem<
45
- TTypeCodenames extends string = string,
46
- TLanguageCodenames extends string = string,
47
- TCollectionCodenames extends string = string,
48
- TWorkflowCodenames extends string = string
49
- > = z.infer<typeof MigrationItemSystemSchema> & {
50
- readonly codename: string;
51
- readonly name: string;
52
- readonly language: MigrationReference<TLanguageCodenames>;
53
- readonly type: MigrationReference<TTypeCodenames>;
54
- readonly collection: MigrationReference<TCollectionCodenames>;
55
- readonly workflow: MigrationReference<TWorkflowCodenames>;
44
+ TTypeCodenames extends string = string,
45
+ TLanguageCodenames extends string = string,
46
+ TCollectionCodenames extends string = string,
47
+ TWorkflowCodenames extends string = string,
48
+ > = Pick<z.infer<typeof MigrationItemSystemSchema>, "codename" | "name"> & {
49
+ readonly language: MigrationReference<TLanguageCodenames>;
50
+ readonly type: MigrationReference<TTypeCodenames>;
51
+ readonly collection: MigrationReference<TCollectionCodenames>;
52
+ readonly workflow: MigrationReference<TWorkflowCodenames>;
56
53
  };
57
54
  export type MigrationUrlSlugMode = z.infer<typeof MigrationUrlSlugModeSchema>;
58
55
  export type MigrationElementType = z.infer<typeof MigrationElementTypeSchema>;
59
56
  export type MigrationComponent = z.infer<typeof MigrationComponentSchema>;
60
57
  export type MigrationElementValue = z.infer<typeof MigrationElementValueSchema>;
61
58
  export type MigrationElement = z.infer<typeof MigrationElementSchema>;
62
- export type MigrationElementTransformData = Omit<MigrationElement, 'type'>;
59
+ export type MigrationElementTransformData = Omit<MigrationElement, "type">;
63
60
  export type MigrationElements = z.infer<typeof MigrationElementsSchema>;
64
61
  export type MigrationAssetDescription = z.infer<typeof MigrationAssetDescriptionSchema>;
65
62
  export type MigrationAsset = z.infer<typeof MigrationAssetSchema>;
66
63
  export type MigrationData = z.infer<typeof MigrationDataSchema>;
67
64
 
68
65
  export type MigrationItemVersion<
69
- TElements extends MigrationElements = MigrationElements,
70
- TWorkflowStepCodenames extends string = string
66
+ TElements extends MigrationElements = MigrationElements,
67
+ TWorkflowStepCodenames extends string = string,
71
68
  > = z.infer<typeof MigrationItemVersionSchema> & {
72
- readonly elements: Readonly<TElements>;
73
- readonly workflow_step: MigrationReference<TWorkflowStepCodenames>;
69
+ readonly elements: Readonly<TElements>;
70
+ readonly workflow_step: MigrationReference<TWorkflowStepCodenames>;
74
71
  };
75
72
 
76
73
  export type MigrationItem<
77
- TElements extends MigrationElements = MigrationElements,
78
- TSystem extends MigrationItemSystem = MigrationItemSystem,
79
- TWorkflowStepCodenames extends string = string
80
- > = z.infer<typeof MigrationItemSchema> & {
81
- readonly versions: Readonly<MigrationItemVersion<TElements, TWorkflowStepCodenames>[]>;
82
- readonly system: TSystem;
74
+ TElements extends MigrationElements = MigrationElements,
75
+ TSystem extends MigrationItemSystem = MigrationItemSystem,
76
+ TWorkflowStepCodenames extends string = string,
77
+ > = {
78
+ readonly versions: Readonly<MigrationItemVersion<TElements, TWorkflowStepCodenames>[]>;
79
+ readonly system: TSystem;
83
80
  };