@kontent-ai/migration-toolkit 2.9.0 → 3.0.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.
Files changed (235) 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 +27 -22
  11. package/dist/core/models/error.models.d.ts +14 -0
  12. package/dist/core/models/error.models.js +25 -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 +14 -14
  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 +1 -1
  26. package/dist/core/utils/confirm.utils.js +21 -20
  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 +8 -1
  34. package/dist/core/utils/global.utils.js +64 -9
  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 +34 -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/export/context/export-context-fetcher.d.ts +1 -1
  49. package/dist/export/context/export-context-fetcher.js +92 -62
  50. package/dist/export/context/export-context-fetcher.js.map +1 -1
  51. package/dist/export/export-manager.d.ts +2 -2
  52. package/dist/export/export-manager.js +46 -37
  53. package/dist/export/export-manager.js.map +1 -1
  54. package/dist/export/export.models.d.ts +21 -2
  55. package/dist/export/utils/export.utils.d.ts +1 -1
  56. package/dist/export/utils/export.utils.js +3 -2
  57. package/dist/export/utils/export.utils.js.map +1 -1
  58. package/dist/file/file-manager.d.ts +2 -2
  59. package/dist/file/file-manager.js +7 -7
  60. package/dist/file/file-manager.js.map +1 -1
  61. package/dist/import/comparers/asset-comparer.d.ts +2 -2
  62. package/dist/import/comparers/asset-comparer.js +12 -11
  63. package/dist/import/comparers/asset-comparer.js.map +1 -1
  64. package/dist/import/context/import-context-fetcher.d.ts +1 -1
  65. package/dist/import/context/import-context-fetcher.js +77 -73
  66. package/dist/import/context/import-context-fetcher.js.map +1 -1
  67. package/dist/import/import-manager.d.ts +1 -1
  68. package/dist/import/import-manager.js +59 -56
  69. package/dist/import/import-manager.js.map +1 -1
  70. package/dist/import/import.models.d.ts +6 -2
  71. package/dist/import/importers/assets-importer.d.ts +3 -3
  72. package/dist/import/importers/assets-importer.js +46 -43
  73. package/dist/import/importers/assets-importer.js.map +1 -1
  74. package/dist/import/importers/content-items-importer.d.ts +3 -3
  75. package/dist/import/importers/content-items-importer.js +28 -25
  76. package/dist/import/importers/content-items-importer.js.map +1 -1
  77. package/dist/import/importers/language-variant-importer.d.ts +3 -3
  78. package/dist/import/importers/language-variant-importer.js +45 -45
  79. package/dist/import/importers/language-variant-importer.js.map +1 -1
  80. package/dist/import/importers/workflow-importer.d.ts +3 -2
  81. package/dist/import/importers/workflow-importer.js +58 -54
  82. package/dist/import/importers/workflow-importer.js.map +1 -1
  83. package/dist/import/utils/import.utils.d.ts +1 -1
  84. package/dist/import/utils/import.utils.js +3 -2
  85. package/dist/import/utils/import.utils.js.map +1 -1
  86. package/dist/index.d.ts +11 -7
  87. package/dist/index.js +10 -8
  88. package/dist/index.js.map +1 -1
  89. package/dist/metadata.js +3 -3
  90. package/dist/metadata.js.map +1 -1
  91. package/dist/node/cli/actions/export-action.d.ts +1 -1
  92. package/dist/node/cli/actions/export-action.js +28 -23
  93. package/dist/node/cli/actions/export-action.js.map +1 -1
  94. package/dist/node/cli/actions/import-action.d.ts +1 -1
  95. package/dist/node/cli/actions/import-action.js +15 -12
  96. package/dist/node/cli/actions/import-action.js.map +1 -1
  97. package/dist/node/cli/actions/migrate-action.d.ts +1 -1
  98. package/dist/node/cli/actions/migrate-action.js +25 -22
  99. package/dist/node/cli/actions/migrate-action.js.map +1 -1
  100. package/dist/node/cli/app.js +13 -12
  101. package/dist/node/cli/app.js.map +1 -1
  102. package/dist/node/cli/args/args-fetcher.d.ts +1 -1
  103. package/dist/node/cli/args/args-fetcher.js +14 -13
  104. package/dist/node/cli/args/args-fetcher.js.map +1 -1
  105. package/dist/node/cli/args/args-setter.d.ts +1 -1
  106. package/dist/node/cli/args/args-setter.js +8 -6
  107. package/dist/node/cli/args/args-setter.js.map +1 -1
  108. package/dist/node/cli/cli.models.d.ts +2 -2
  109. package/dist/node/cli/commands.js +68 -56
  110. package/dist/node/cli/commands.js.map +1 -1
  111. package/dist/toolkit/elements-builder.d.ts +1 -1
  112. package/dist/toolkit/elements-builder.js +12 -12
  113. package/dist/toolkit/elements-builder.js.map +1 -1
  114. package/dist/toolkit/export.d.ts +2 -2
  115. package/dist/toolkit/export.js +19 -2
  116. package/dist/toolkit/export.js.map +1 -1
  117. package/dist/toolkit/file.d.ts +2 -1
  118. package/dist/toolkit/file.js +46 -13
  119. package/dist/toolkit/file.js.map +1 -1
  120. package/dist/toolkit/import.d.ts +1 -1
  121. package/dist/toolkit/import.js +31 -14
  122. package/dist/toolkit/import.js.map +1 -1
  123. package/dist/toolkit/migrate.d.ts +13 -4
  124. package/dist/toolkit/migrate.js +37 -17
  125. package/dist/toolkit/migrate.js.map +1 -1
  126. package/dist/translation/extraction/items-extraction.processor.d.ts +5 -4
  127. package/dist/translation/extraction/items-extraction.processor.js +73 -35
  128. package/dist/translation/extraction/items-extraction.processor.js.map +1 -1
  129. package/dist/translation/helpers/export-placeholder.utils.d.ts +11 -0
  130. package/dist/translation/helpers/export-placeholder.utils.js +11 -0
  131. package/dist/translation/helpers/export-placeholder.utils.js.map +1 -0
  132. package/dist/translation/helpers/rich-text.processor.d.ts +6 -6
  133. package/dist/translation/helpers/rich-text.processor.js +38 -38
  134. package/dist/translation/helpers/rich-text.processor.js.map +1 -1
  135. package/dist/translation/transforms/export-transforms.d.ts +2 -2
  136. package/dist/translation/transforms/export-transforms.js +93 -67
  137. package/dist/translation/transforms/export-transforms.js.map +1 -1
  138. package/dist/translation/transforms/import-transforms.d.ts +2 -2
  139. package/dist/translation/transforms/import-transforms.js +38 -40
  140. package/dist/translation/transforms/import-transforms.js.map +1 -1
  141. package/dist/zip/zip-manager.d.ts +4 -3
  142. package/dist/zip/zip-manager.js +9 -9
  143. package/dist/zip/zip-manager.js.map +1 -1
  144. package/dist/zip/zip-packager.d.ts +2 -2
  145. package/dist/zip/zip-packager.js +19 -17
  146. package/dist/zip/zip-packager.js.map +1 -1
  147. package/dist/zip/zip-transformer.d.ts +3 -2
  148. package/dist/zip/zip-transformer.js +16 -15
  149. package/dist/zip/zip-transformer.js.map +1 -1
  150. package/dist/zip/zip.models.d.ts +2 -2
  151. package/lib/core/config.ts +6 -6
  152. package/lib/core/helpers/workflow-helper.ts +190 -185
  153. package/lib/core/logs/loggers.ts +52 -52
  154. package/lib/core/models/core.models.ts +128 -119
  155. package/lib/core/models/error.models.ts +41 -0
  156. package/lib/core/models/log.models.ts +20 -20
  157. package/lib/core/models/migration.models.ts +54 -54
  158. package/lib/core/models/migration.schema.ts +108 -108
  159. package/lib/core/utils/array.utils.ts +43 -42
  160. package/lib/core/utils/binary-data.utils.ts +16 -16
  161. package/lib/core/utils/confirm.utils.ts +106 -105
  162. package/lib/core/utils/error.utils.ts +69 -72
  163. package/lib/core/utils/external-id.utils.ts +4 -4
  164. package/lib/core/utils/global.utils.ts +86 -15
  165. package/lib/core/utils/http.utils.ts +23 -23
  166. package/lib/core/utils/management-client-utils.ts +186 -186
  167. package/lib/core/utils/processing-utils.ts +82 -82
  168. package/lib/core/utils/run.utils.ts +50 -50
  169. package/lib/export/context/export-context-fetcher.ts +472 -447
  170. package/lib/export/export-manager.ts +233 -232
  171. package/lib/export/export.models.ts +71 -56
  172. package/lib/export/utils/export.utils.ts +9 -7
  173. package/lib/file/file-manager.ts +28 -28
  174. package/lib/import/comparers/asset-comparer.ts +107 -106
  175. package/lib/import/context/import-context-fetcher.ts +462 -462
  176. package/lib/import/import-manager.ts +243 -240
  177. package/lib/import/import.models.ts +69 -67
  178. package/lib/import/importers/assets-importer.ts +240 -236
  179. package/lib/import/importers/content-items-importer.ts +126 -122
  180. package/lib/import/importers/language-variant-importer.ts +324 -328
  181. package/lib/import/importers/workflow-importer.ts +372 -367
  182. package/lib/import/utils/import.utils.ts +9 -7
  183. package/lib/index.ts +12 -8
  184. package/lib/metadata.ts +3 -4
  185. package/lib/node/cli/actions/export-action.ts +43 -38
  186. package/lib/node/cli/actions/import-action.ts +32 -29
  187. package/lib/node/cli/actions/migrate-action.ts +49 -46
  188. package/lib/node/cli/app.ts +21 -21
  189. package/lib/node/cli/args/args-fetcher.ts +55 -54
  190. package/lib/node/cli/args/args-setter.ts +34 -32
  191. package/lib/node/cli/cli.models.ts +17 -17
  192. package/lib/node/cli/commands.ts +165 -153
  193. package/lib/toolkit/elements-builder.ts +69 -69
  194. package/lib/toolkit/export.ts +21 -4
  195. package/lib/toolkit/file.ts +59 -22
  196. package/lib/toolkit/import.ts +32 -15
  197. package/lib/toolkit/migrate.ts +60 -31
  198. package/lib/translation/extraction/items-extraction.processor.ts +203 -173
  199. package/lib/translation/helpers/export-placeholder.utils.ts +10 -0
  200. package/lib/translation/helpers/rich-text.processor.ts +311 -311
  201. package/lib/translation/transforms/export-transforms.ts +313 -279
  202. package/lib/translation/transforms/import-transforms.ts +188 -191
  203. package/lib/zip/zip-manager.ts +28 -27
  204. package/lib/zip/zip-packager.ts +75 -73
  205. package/lib/zip/zip-transformer.ts +112 -107
  206. package/lib/zip/zip.models.ts +7 -7
  207. package/package.json +91 -85
  208. package/dist/core/index.d.ts +0 -16
  209. package/dist/core/index.js +0 -17
  210. package/dist/core/index.js.map +0 -1
  211. package/dist/export/index.d.ts +0 -2
  212. package/dist/export/index.js +0 -3
  213. package/dist/export/index.js.map +0 -1
  214. package/dist/file/index.d.ts +0 -1
  215. package/dist/file/index.js +0 -2
  216. package/dist/file/index.js.map +0 -1
  217. package/dist/import/index.d.ts +0 -2
  218. package/dist/import/index.js +0 -3
  219. package/dist/import/index.js.map +0 -1
  220. package/dist/toolkit/index.d.ts +0 -5
  221. package/dist/toolkit/index.js +0 -6
  222. package/dist/toolkit/index.js.map +0 -1
  223. package/dist/translation/index.d.ts +0 -4
  224. package/dist/translation/index.js +0 -5
  225. package/dist/translation/index.js.map +0 -1
  226. package/dist/zip/index.d.ts +0 -4
  227. package/dist/zip/index.js +0 -5
  228. package/dist/zip/index.js.map +0 -1
  229. package/lib/core/index.ts +0 -18
  230. package/lib/export/index.ts +0 -2
  231. package/lib/file/index.ts +0 -1
  232. package/lib/import/index.ts +0 -2
  233. package/lib/toolkit/index.ts +0 -5
  234. package/lib/translation/index.ts +0 -4
  235. package/lib/zip/index.ts +0 -4
@@ -1,155 +1,155 @@
1
- import { Buffer as BufferProxy } from 'buffer';
2
- import { z } from 'zod';
1
+ import { Buffer as BufferProxy } from "buffer";
2
+ import { z } from "zod";
3
3
 
4
4
  interface Elements {
5
- readonly [key: string]: Element;
5
+ readonly [key: string]: Element;
6
6
  }
7
7
 
8
- type UrlSlugMode = 'autogenerated' | 'custom';
8
+ type UrlSlugMode = "autogenerated" | "custom";
9
9
  type Reference = { readonly codename: string };
10
10
 
11
11
  type Component = {
12
- readonly system: {
13
- readonly id: string;
14
- readonly type: Reference;
15
- };
16
- readonly elements: Elements;
12
+ readonly system: {
13
+ readonly id: string;
14
+ readonly type: Reference;
15
+ };
16
+ readonly elements: Elements;
17
17
  };
18
18
 
19
19
  type ElementValue = string | undefined | number | Reference[];
20
20
 
21
21
  type Element = {
22
- readonly type: ElementType;
23
- readonly value?: ElementValue;
24
- readonly display_timezone?: string;
25
- readonly components?: readonly Component[];
26
- readonly mode?: UrlSlugMode;
22
+ readonly type: ElementType;
23
+ readonly value?: ElementValue;
24
+ readonly display_timezone?: string;
25
+ readonly components?: readonly Component[];
26
+ readonly mode?: UrlSlugMode;
27
27
  };
28
28
 
29
29
  type ElementType =
30
- | 'text'
31
- | 'rich_text'
32
- | 'number'
33
- | 'multiple_choice'
34
- | 'date_time'
35
- | 'asset'
36
- | 'modular_content'
37
- | 'taxonomy'
38
- | 'url_slug'
39
- | 'custom'
40
- | 'subpages';
41
-
42
- export const MigrationUrlSlugModeSchema = z.enum(['autogenerated', 'custom']).readonly();
30
+ | "text"
31
+ | "rich_text"
32
+ | "number"
33
+ | "multiple_choice"
34
+ | "date_time"
35
+ | "asset"
36
+ | "modular_content"
37
+ | "taxonomy"
38
+ | "url_slug"
39
+ | "custom"
40
+ | "subpages";
41
+
42
+ export const MigrationUrlSlugModeSchema = z.enum(["autogenerated", "custom"]).readonly();
43
43
  export const MigrationElementTypeSchema = z
44
- .enum([
45
- 'text',
46
- 'rich_text',
47
- 'number',
48
- 'multiple_choice',
49
- 'date_time',
50
- 'asset',
51
- 'modular_content',
52
- 'taxonomy',
53
- 'url_slug',
54
- 'custom',
55
- 'subpages'
56
- ])
57
- .readonly();
44
+ .enum([
45
+ "text",
46
+ "rich_text",
47
+ "number",
48
+ "multiple_choice",
49
+ "date_time",
50
+ "asset",
51
+ "modular_content",
52
+ "taxonomy",
53
+ "url_slug",
54
+ "custom",
55
+ "subpages",
56
+ ])
57
+ .readonly();
58
58
 
59
59
  export const MigrationReferenceSchema = z
60
- .strictObject({
61
- codename: z.string().readonly()
62
- })
63
- .readonly();
60
+ .strictObject({
61
+ codename: z.string().readonly(),
62
+ })
63
+ .readonly();
64
64
 
65
65
  export const ScheduleSchema = z
66
- .strictObject({
67
- publish_time: z.string().datetime().optional().readonly(),
68
- publish_display_timezone: z.string().optional().readonly(),
69
- unpublish_time: z.string().datetime().optional().readonly(),
70
- unpublish_display_timezone: z.string().optional().readonly()
71
- })
72
- .readonly();
66
+ .strictObject({
67
+ publish_time: z.string().datetime().optional().readonly(),
68
+ publish_display_timezone: z.string().optional().readonly(),
69
+ unpublish_time: z.string().datetime().optional().readonly(),
70
+ unpublish_display_timezone: z.string().optional().readonly(),
71
+ })
72
+ .readonly();
73
73
 
74
74
  /**
75
75
  * ZodType is needed to be specified here due to the use of 'lazy' & circular dependency between types
76
76
  * Otherwise TS has no way of statically inferring the type
77
77
  */
78
78
  export const MigrationElementsSchema: z.ZodReadonly<z.ZodType<Elements>> = z
79
- .record(
80
- z.string(),
81
- z.lazy(() => MigrationElementSchema)
82
- )
83
- .readonly();
79
+ .record(
80
+ z.string(),
81
+ z.lazy(() => MigrationElementSchema),
82
+ )
83
+ .readonly();
84
84
 
85
85
  export const MigrationComponentSchema = z
86
- .strictObject({
87
- system: z.strictObject({
88
- id: z.string(),
89
- type: MigrationReferenceSchema
90
- }),
91
- elements: MigrationElementsSchema
92
- })
93
- .readonly();
86
+ .strictObject({
87
+ system: z.strictObject({
88
+ id: z.string(),
89
+ type: MigrationReferenceSchema,
90
+ }),
91
+ elements: MigrationElementsSchema,
92
+ })
93
+ .readonly();
94
94
 
95
95
  export const MigrationElementValueSchema = z.union([z.string(), z.undefined(), z.number(), z.array(MigrationReferenceSchema)]);
96
96
 
97
97
  export const MigrationElementSchema = z
98
- .strictObject({
99
- type: MigrationElementTypeSchema,
100
- value: MigrationElementValueSchema.optional(),
101
- display_timezone: z.string().optional(),
102
- components: z.array(MigrationComponentSchema).readonly().optional(),
103
- mode: MigrationUrlSlugModeSchema.optional()
104
- })
105
- .readonly();
98
+ .strictObject({
99
+ type: MigrationElementTypeSchema,
100
+ value: MigrationElementValueSchema.optional(),
101
+ display_timezone: z.string().optional(),
102
+ components: z.array(MigrationComponentSchema).readonly().optional(),
103
+ mode: MigrationUrlSlugModeSchema.optional(),
104
+ })
105
+ .readonly();
106
106
 
107
107
  export const MigrationItemVersionSchema = z
108
- .strictObject({
109
- workflow_step: MigrationReferenceSchema,
110
- elements: MigrationElementsSchema,
111
- schedule: ScheduleSchema.optional()
112
- })
113
- .readonly();
108
+ .strictObject({
109
+ workflow_step: MigrationReferenceSchema,
110
+ elements: MigrationElementsSchema,
111
+ schedule: ScheduleSchema.optional(),
112
+ })
113
+ .readonly();
114
114
 
115
115
  export const MigrationItemSystemSchema = z.strictObject({
116
- codename: z.string(),
117
- name: z.string(),
118
- language: MigrationReferenceSchema,
119
- type: MigrationReferenceSchema,
120
- collection: MigrationReferenceSchema,
121
- workflow: MigrationReferenceSchema
116
+ codename: z.string(),
117
+ name: z.string(),
118
+ language: MigrationReferenceSchema,
119
+ type: MigrationReferenceSchema,
120
+ collection: MigrationReferenceSchema,
121
+ workflow: MigrationReferenceSchema,
122
122
  });
123
123
 
124
124
  export const MigrationItemSchema = z
125
- .strictObject({
126
- system: MigrationItemSystemSchema,
127
- versions: z.array(MigrationItemVersionSchema).readonly()
128
- })
129
- .readonly();
125
+ .strictObject({
126
+ system: MigrationItemSystemSchema,
127
+ versions: z.array(MigrationItemVersionSchema).readonly(),
128
+ })
129
+ .readonly();
130
130
 
131
131
  export const MigrationAssetDescriptionSchema = z
132
- .strictObject({
133
- language: MigrationReferenceSchema,
134
- description: z.optional(z.string())
135
- })
136
- .readonly();
132
+ .strictObject({
133
+ language: MigrationReferenceSchema,
134
+ description: z.optional(z.string()),
135
+ })
136
+ .readonly();
137
137
 
138
138
  const BaseMigrationAssetSchema = z.strictObject({
139
- codename: z.string(),
140
- filename: z.string(),
141
- title: z.string(),
142
- collection: z.optional(MigrationReferenceSchema),
143
- descriptions: z.optional(z.array(MigrationAssetDescriptionSchema)).readonly(),
144
- folder: z.optional(MigrationReferenceSchema)
139
+ codename: z.string(),
140
+ filename: z.string(),
141
+ title: z.string().optional(),
142
+ collection: z.optional(MigrationReferenceSchema),
143
+ descriptions: z.optional(z.array(MigrationAssetDescriptionSchema)).readonly(),
144
+ folder: z.optional(MigrationReferenceSchema),
145
145
  });
146
146
 
147
147
  export const MigrationAssetSchema = BaseMigrationAssetSchema.extend({
148
- binary_data: z.union([z.instanceof(BufferProxy), z.instanceof(Blob)])
148
+ binary_data: z.union([z.instanceof(BufferProxy), z.instanceof(Blob)]),
149
149
  }).readonly();
150
150
 
151
151
  export const ZipMigrationAssetSchema = BaseMigrationAssetSchema.extend({
152
- _zipFilename: z.string()
152
+ _zipFilename: z.string(),
153
153
  }).readonly();
154
154
 
155
155
  export const MigrationAssetsSchema = z.array(MigrationAssetSchema).readonly();
@@ -157,8 +157,8 @@ export const ZipMigrationAssetsSchema = z.array(ZipMigrationAssetSchema).readonl
157
157
  export const MigrationItemsSchema = z.array(MigrationItemSchema).readonly();
158
158
 
159
159
  export const MigrationDataSchema = z
160
- .strictObject({
161
- items: MigrationItemsSchema,
162
- assets: MigrationAssetsSchema
163
- })
164
- .readonly();
160
+ .strictObject({
161
+ items: MigrationItemsSchema,
162
+ assets: MigrationAssetsSchema,
163
+ })
164
+ .readonly();
@@ -1,42 +1,43 @@
1
- import type { MigrationElementValue, MigrationReference } from '../models/migration.models.js';
2
- import { isArray, isString } from './global.utils.js';
3
-
4
- export function parseAsMigrationReferencesArray(value: MigrationElementValue): readonly MigrationReference[] {
5
- if (!value) {
6
- return [];
7
- }
8
- if (isArray(value)) {
9
- return value;
10
- }
11
- throw Error(`Value is not an array`);
12
- }
13
-
14
- export function findRequired<T>(array: readonly T[], predicate: (item: T, index: number) => boolean, errorMessage: string): T;
15
- export function findRequired<T>(array: readonly T[], predicate: (item: T, index: number) => boolean, errorMessage: () => never): T;
16
- export function findRequired<T>(
17
- array: readonly T[],
18
- predicate: (item: T, index: number) => boolean,
19
- errorMessage: string | (() => never)
20
- ): T {
21
- const item = array.find(predicate);
22
-
23
- if (item) {
24
- return item;
25
- }
26
-
27
- if (isString(errorMessage)) {
28
- throw Error(errorMessage);
29
- }
30
- return errorMessage();
31
- }
32
-
33
- export async function mapAsync<Input, Result>(
34
- array: readonly Input[],
35
- callbackAsync: (item: Readonly<Input>, index: number, array: readonly Input[]) => Promise<Readonly<Result>>
36
- ): Promise<readonly Result[]> {
37
- const results: Result[] = [];
38
- for (let i = 0; i < array.length; i++) {
39
- results.push(await callbackAsync(array[i], i, array));
40
- }
41
- return results;
42
- }
1
+ import { MigrationToolkitError } from "../models/error.models.js";
2
+ import type { MigrationElementValue, MigrationReference } from "../models/migration.models.js";
3
+ import { isArray, isString } from "./global.utils.js";
4
+
5
+ export function parseAsMigrationReferencesArray(value: MigrationElementValue): readonly MigrationReference[] {
6
+ if (!value) {
7
+ return [];
8
+ }
9
+ if (isArray(value)) {
10
+ return value;
11
+ }
12
+ throw new MigrationToolkitError("invalidValue", `Value is not an array`);
13
+ }
14
+
15
+ export function findRequired<T>(array: readonly T[], predicate: (item: T, index: number) => boolean, errorMessage: string): T;
16
+ export function findRequired<T>(array: readonly T[], predicate: (item: T, index: number) => boolean, errorMessage: () => never): T;
17
+ export function findRequired<T>(
18
+ array: readonly T[],
19
+ predicate: (item: T, index: number) => boolean,
20
+ errorMessage: string | (() => never),
21
+ ): T {
22
+ const item = array.find(predicate);
23
+
24
+ if (item) {
25
+ return item;
26
+ }
27
+
28
+ if (isString(errorMessage)) {
29
+ throw new MigrationToolkitError("findRequiredError", errorMessage);
30
+ }
31
+ return errorMessage();
32
+ }
33
+
34
+ export async function mapAsync<Input, Result>(
35
+ array: readonly Input[],
36
+ callbackAsync: (item: Readonly<Input>, index: number, array: readonly Input[]) => Promise<Readonly<Result>>,
37
+ ): Promise<readonly Result[]> {
38
+ const results: Result[] = [];
39
+ for (let i = 0; i < array.length; i++) {
40
+ results.push(await callbackAsync(array[i], i, array));
41
+ }
42
+ return results;
43
+ }
@@ -1,25 +1,25 @@
1
- import type { FileBinaryData } from '../../zip/index.js';
2
- import { defaultHttpService, defaultRetryStrategy } from './http.utils.js';
1
+ import type { FileBinaryData } from "../../zip/zip.models.js";
2
+ import { defaultHttpService, defaultRetryStrategy } from "./http.utils.js";
3
3
 
4
4
  export async function getBinaryDataFromUrlAsync(url: string): Promise<{ readonly data: FileBinaryData; readonly contentLength: number }> {
5
- // temp fix for Kontent.ai Repository not validating url
6
- const fixedUrl = url.replace('#', '%23');
5
+ // temp fix for Kontent.ai Repository not validating url
6
+ const fixedUrl = url.replace("#", "%23");
7
7
 
8
- const response = await defaultHttpService.getAsync<FileBinaryData>(
9
- {
10
- url: fixedUrl
11
- },
12
- {
13
- responseType: 'arraybuffer',
14
- retryStrategy: defaultRetryStrategy
15
- }
16
- );
8
+ const response = await defaultHttpService.getAsync<FileBinaryData>(
9
+ {
10
+ url: fixedUrl,
11
+ },
12
+ {
13
+ responseType: "arraybuffer",
14
+ retryStrategy: defaultRetryStrategy,
15
+ },
16
+ );
17
17
 
18
- const contentLength = +(response.headers.find((m) => m.header.toLowerCase() === 'content-length')?.value ?? 0);
18
+ const contentLength = +(response.headers.find((m) => m.header.toLowerCase() === "content-length")?.value ?? 0);
19
19
 
20
- return { data: response.data, contentLength: contentLength };
20
+ return { data: response.data, contentLength: contentLength };
21
21
  }
22
22
 
23
23
  export function geSizeInBytes(data: FileBinaryData): number {
24
- return data instanceof Blob ? data.size : data.byteLength;
24
+ return data instanceof Blob ? data.size : data.byteLength;
25
25
  }
@@ -1,133 +1,134 @@
1
- import chalk from 'chalk';
2
- import type { Logger } from '../models/log.models.js';
3
- import { getMigrationManagementClient, managementClientUtils } from './management-client-utils.js';
1
+ import chalk from "chalk";
2
+ import { MigrationToolkitError } from "../models/error.models.js";
3
+ import type { Logger } from "../models/log.models.js";
4
+ import { getMigrationManagementClient, managementClientUtils } from "./management-client-utils.js";
4
5
 
5
6
  export async function confirmExportAsync(data: {
6
- readonly force: boolean;
7
- readonly environmentId: string;
8
- readonly apiKey: string;
9
- readonly logger: Logger;
10
- readonly dataToExport: {
11
- readonly itemsCount: number;
12
- };
7
+ readonly force: boolean;
8
+ readonly environmentId: string;
9
+ readonly apiKey: string;
10
+ readonly logger: Logger;
11
+ readonly dataToExport: {
12
+ readonly itemsCount: number;
13
+ };
13
14
  }): Promise<void> {
14
- const environment = await managementClientUtils(
15
- getMigrationManagementClient({
16
- environmentId: data.environmentId,
17
- apiKey: data.apiKey
18
- }),
19
- data.logger
20
- ).getEnvironmentAsync();
15
+ const environment = await managementClientUtils(
16
+ getMigrationManagementClient({
17
+ environmentId: data.environmentId,
18
+ apiKey: data.apiKey,
19
+ }),
20
+ data.logger,
21
+ ).getEnvironmentAsync();
21
22
 
22
- const text: string = `Are you sure to export '${chalk.cyan(data.dataToExport.itemsCount)}' content ${getItemsPluralText(
23
- data.dataToExport.itemsCount
24
- )} from ${chalk.yellow(environment.name)} (${chalk.magenta(environment.environment)})?`;
23
+ const text: string = `Are you sure to export '${chalk.cyan(data.dataToExport.itemsCount)}' content ${getItemsPluralText(
24
+ data.dataToExport.itemsCount,
25
+ )} from ${chalk.yellow(environment.name)} (${chalk.magenta(environment.environment)})?`;
25
26
 
26
- await confirmAsync({
27
- force: data.force,
28
- logger: data.logger,
29
- action: 'Export',
30
- message: text
31
- });
27
+ await confirmAsync({
28
+ force: data.force,
29
+ logger: data.logger,
30
+ action: "Export",
31
+ message: text,
32
+ });
32
33
  }
33
34
 
34
35
  export async function confirmMigrateAsync(data: {
35
- readonly force: boolean;
36
- readonly sourceEnvironment: {
37
- readonly environmentId: string;
38
- readonly apiKey: string;
39
- };
40
- readonly targetEnvironment: {
41
- readonly environmentId: string;
42
- readonly apiKey: string;
43
- };
44
- readonly logger: Logger;
45
- readonly dataToMigrate: {
46
- readonly itemsCount: number;
47
- };
36
+ readonly force: boolean;
37
+ readonly sourceEnvironment: {
38
+ readonly environmentId: string;
39
+ readonly apiKey: string;
40
+ };
41
+ readonly targetEnvironment: {
42
+ readonly environmentId: string;
43
+ readonly apiKey: string;
44
+ };
45
+ readonly logger: Logger;
46
+ readonly dataToMigrate: {
47
+ readonly itemsCount: number;
48
+ };
48
49
  }): Promise<void> {
49
- const sourceEnvironment = await managementClientUtils(
50
- getMigrationManagementClient({
51
- environmentId: data.sourceEnvironment.environmentId,
52
- apiKey: data.sourceEnvironment.apiKey
53
- }),
54
- data.logger
55
- ).getEnvironmentAsync();
56
- const targetEnvironment = await managementClientUtils(
57
- getMigrationManagementClient({
58
- environmentId: data.targetEnvironment.environmentId,
59
- apiKey: data.targetEnvironment.apiKey
60
- }),
61
- data.logger
62
- ).getEnvironmentAsync();
50
+ const sourceEnvironment = await managementClientUtils(
51
+ getMigrationManagementClient({
52
+ environmentId: data.sourceEnvironment.environmentId,
53
+ apiKey: data.sourceEnvironment.apiKey,
54
+ }),
55
+ data.logger,
56
+ ).getEnvironmentAsync();
57
+ const targetEnvironment = await managementClientUtils(
58
+ getMigrationManagementClient({
59
+ environmentId: data.targetEnvironment.environmentId,
60
+ apiKey: data.targetEnvironment.apiKey,
61
+ }),
62
+ data.logger,
63
+ ).getEnvironmentAsync();
63
64
 
64
- const text: string = `Are you sure to migrate '${chalk.cyan(data.dataToMigrate.itemsCount)}' ${getItemsPluralText(
65
- data.dataToMigrate.itemsCount
66
- )} from ${chalk.yellow(sourceEnvironment.name)} (${chalk.magenta(sourceEnvironment.environment)}) to environment ${chalk.yellow(
67
- targetEnvironment.name
68
- )} (${chalk.magenta(targetEnvironment.environment)}) ?`;
65
+ const text: string = `Are you sure to migrate '${chalk.cyan(data.dataToMigrate.itemsCount)}' ${getItemsPluralText(
66
+ data.dataToMigrate.itemsCount,
67
+ )} from ${chalk.yellow(sourceEnvironment.name)} (${chalk.magenta(sourceEnvironment.environment)}) to environment ${chalk.yellow(
68
+ targetEnvironment.name,
69
+ )} (${chalk.magenta(targetEnvironment.environment)}) ?`;
69
70
 
70
- await confirmAsync({
71
- force: data.force,
72
- logger: data.logger,
73
- action: 'Migrate',
74
- message: text
75
- });
71
+ await confirmAsync({
72
+ force: data.force,
73
+ logger: data.logger,
74
+ action: "Migrate",
75
+ message: text,
76
+ });
76
77
  }
77
78
 
78
79
  export async function confirmImportAsync(data: {
79
- readonly force: boolean;
80
- readonly environmentId: string;
81
- readonly apiKey: string;
82
- readonly logger: Logger;
80
+ readonly force: boolean;
81
+ readonly environmentId: string;
82
+ readonly apiKey: string;
83
+ readonly logger: Logger;
83
84
  }): Promise<void> {
84
- const environment = await managementClientUtils(
85
- getMigrationManagementClient({
86
- environmentId: data.environmentId,
87
- apiKey: data.apiKey
88
- }),
89
- data.logger
90
- ).getEnvironmentAsync();
85
+ const environment = await managementClientUtils(
86
+ getMigrationManagementClient({
87
+ environmentId: data.environmentId,
88
+ apiKey: data.apiKey,
89
+ }),
90
+ data.logger,
91
+ ).getEnvironmentAsync();
91
92
 
92
- const text: string = `Are you sure to import data into ${chalk.yellow(environment.name)} (${chalk.magenta(environment.environment)})?`;
93
+ const text: string = `Are you sure to import data into ${chalk.yellow(environment.name)} (${chalk.magenta(environment.environment)})?`;
93
94
 
94
- await confirmAsync({
95
- force: data.force,
96
- logger: data.logger,
97
- action: 'Import',
98
- message: text
99
- });
95
+ await confirmAsync({
96
+ force: data.force,
97
+ logger: data.logger,
98
+ action: "Import",
99
+ message: text,
100
+ });
100
101
  }
101
102
 
102
103
  async function confirmAsync(data: {
103
- readonly action: string;
104
- readonly message: string;
105
- readonly force: boolean;
106
- readonly logger: Logger;
104
+ readonly action: string;
105
+ readonly message: string;
106
+ readonly force: boolean;
107
+ readonly logger: Logger;
107
108
  }): Promise<void> {
108
- // Prompts is imported dynamically because it's a node.js only module and would not work if user
109
- // tried using this library in a browser
110
- const prompts = await import('prompts');
109
+ // Prompts is imported dynamically because it's a node.js only module and would not work if user
110
+ // tried using this library in a browser
111
+ const prompts = await import("prompts");
111
112
 
112
- if (data.force) {
113
- data.logger.log({
114
- type: 'info',
115
- message: `Skipping confirmation`
116
- });
117
- return;
118
- }
113
+ if (data.force) {
114
+ data.logger.log({
115
+ type: "info",
116
+ message: `Skipping confirmation`,
117
+ });
118
+ return;
119
+ }
119
120
 
120
- const confirmed = await prompts.default({
121
- type: 'confirm',
122
- name: 'confirm',
123
- message: `${chalk.cyan(data.action)}: ${data.message}`
124
- });
121
+ const confirmed = await prompts.default({
122
+ type: "confirm",
123
+ name: "confirm",
124
+ message: `${chalk.cyan(data.action)}: ${data.message}`,
125
+ });
125
126
 
126
- if (!confirmed.confirm) {
127
- throw Error(`Confirmation refused.`);
128
- }
127
+ if (!confirmed.confirm) {
128
+ throw new MigrationToolkitError("confirmationRefused", `Confirmation refused.`);
129
+ }
129
130
  }
130
131
 
131
132
  function getItemsPluralText(count: number): string {
132
- return count === 1 ? 'item' : 'items';
133
+ return count === 1 ? "item" : "items";
133
134
  }