@kontent-ai/migration-toolkit 1.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 (240) hide show
  1. package/.npmignore +13 -0
  2. package/LICENSE.md +9 -0
  3. package/README.md +272 -0
  4. package/dist/es2022/core/helpers/workflow-helper.d.ts +37 -0
  5. package/dist/es2022/core/helpers/workflow-helper.js +67 -0
  6. package/dist/es2022/core/helpers/workflow-helper.js.map +1 -0
  7. package/dist/es2022/core/index.d.ts +15 -0
  8. package/dist/es2022/core/index.js +16 -0
  9. package/dist/es2022/core/index.js.map +1 -0
  10. package/dist/es2022/core/logs/loggers.d.ts +2 -0
  11. package/dist/es2022/core/logs/loggers.js +69 -0
  12. package/dist/es2022/core/logs/loggers.js.map +1 -0
  13. package/dist/es2022/core/models/core.models.d.ts +91 -0
  14. package/dist/es2022/core/models/core.models.js +2 -0
  15. package/dist/es2022/core/models/core.models.js.map +1 -0
  16. package/dist/es2022/core/models/log.models.d.ts +15 -0
  17. package/dist/es2022/core/models/log.models.js +2 -0
  18. package/dist/es2022/core/models/log.models.js.map +1 -0
  19. package/dist/es2022/core/models/migration.models.d.ts +136 -0
  20. package/dist/es2022/core/models/migration.models.js +2 -0
  21. package/dist/es2022/core/models/migration.models.js.map +1 -0
  22. package/dist/es2022/core/utils/array.utils.d.ts +5 -0
  23. package/dist/es2022/core/utils/array.utils.js +27 -0
  24. package/dist/es2022/core/utils/array.utils.js.map +1 -0
  25. package/dist/es2022/core/utils/binary-data.utils.d.ts +5 -0
  26. package/dist/es2022/core/utils/binary-data.utils.js +21 -0
  27. package/dist/es2022/core/utils/binary-data.utils.js.map +1 -0
  28. package/dist/es2022/core/utils/confirm.utils.d.ts +31 -0
  29. package/dist/es2022/core/utils/confirm.utils.js +73 -0
  30. package/dist/es2022/core/utils/confirm.utils.js.map +1 -0
  31. package/dist/es2022/core/utils/error.utils.d.ts +4 -0
  32. package/dist/es2022/core/utils/error.utils.js +50 -0
  33. package/dist/es2022/core/utils/error.utils.js.map +1 -0
  34. package/dist/es2022/core/utils/external-id.utils.d.ts +5 -0
  35. package/dist/es2022/core/utils/external-id.utils.js +5 -0
  36. package/dist/es2022/core/utils/external-id.utils.js.map +1 -0
  37. package/dist/es2022/core/utils/global.utils.d.ts +14 -0
  38. package/dist/es2022/core/utils/global.utils.js +45 -0
  39. package/dist/es2022/core/utils/global.utils.js.map +1 -0
  40. package/dist/es2022/core/utils/http.utils.d.ts +3 -0
  41. package/dist/es2022/core/utils/http.utils.js +29 -0
  42. package/dist/es2022/core/utils/http.utils.js.map +1 -0
  43. package/dist/es2022/core/utils/management-client-utils.d.ts +19 -0
  44. package/dist/es2022/core/utils/management-client-utils.js +129 -0
  45. package/dist/es2022/core/utils/management-client-utils.js.map +1 -0
  46. package/dist/es2022/core/utils/processing-utils.d.ts +12 -0
  47. package/dist/es2022/core/utils/processing-utils.js +39 -0
  48. package/dist/es2022/core/utils/processing-utils.js.map +1 -0
  49. package/dist/es2022/core/utils/run.utils.d.ts +10 -0
  50. package/dist/es2022/core/utils/run.utils.js +37 -0
  51. package/dist/es2022/core/utils/run.utils.js.map +1 -0
  52. package/dist/es2022/export/context/export-context-fetcher.d.ts +4 -0
  53. package/dist/es2022/export/context/export-context-fetcher.js +289 -0
  54. package/dist/es2022/export/context/export-context-fetcher.js.map +1 -0
  55. package/dist/es2022/export/export-manager.d.ts +5 -0
  56. package/dist/es2022/export/export-manager.js +167 -0
  57. package/dist/es2022/export/export-manager.js.map +1 -0
  58. package/dist/es2022/export/export.models.d.ts +55 -0
  59. package/dist/es2022/export/export.models.js +2 -0
  60. package/dist/es2022/export/export.models.js.map +1 -0
  61. package/dist/es2022/export/index.d.ts +2 -0
  62. package/dist/es2022/export/index.js +3 -0
  63. package/dist/es2022/export/index.js.map +1 -0
  64. package/dist/es2022/export/utils/export.utils.d.ts +2 -0
  65. package/dist/es2022/export/utils/export.utils.js +5 -0
  66. package/dist/es2022/export/utils/export.utils.js.map +1 -0
  67. package/dist/es2022/file/file-manager.d.ts +5 -0
  68. package/dist/es2022/file/file-manager.js +29 -0
  69. package/dist/es2022/file/file-manager.js.map +1 -0
  70. package/dist/es2022/file/index.d.ts +1 -0
  71. package/dist/es2022/file/index.js +2 -0
  72. package/dist/es2022/file/index.js.map +1 -0
  73. package/dist/es2022/import/comparers/asset-comparer.d.ts +12 -0
  74. package/dist/es2022/import/comparers/asset-comparer.js +65 -0
  75. package/dist/es2022/import/comparers/asset-comparer.js.map +1 -0
  76. package/dist/es2022/import/context/import-context-fetcher.d.ts +4 -0
  77. package/dist/es2022/import/context/import-context-fetcher.js +235 -0
  78. package/dist/es2022/import/context/import-context-fetcher.js.map +1 -0
  79. package/dist/es2022/import/import-manager.d.ts +4 -0
  80. package/dist/es2022/import/import-manager.js +80 -0
  81. package/dist/es2022/import/import-manager.js.map +1 -0
  82. package/dist/es2022/import/import.models.d.ts +45 -0
  83. package/dist/es2022/import/import.models.js +2 -0
  84. package/dist/es2022/import/import.models.js.map +1 -0
  85. package/dist/es2022/import/importers/assets-importer.d.ts +10 -0
  86. package/dist/es2022/import/importers/assets-importer.js +175 -0
  87. package/dist/es2022/import/importers/assets-importer.js.map +1 -0
  88. package/dist/es2022/import/importers/content-items-importer.d.ts +10 -0
  89. package/dist/es2022/import/importers/content-items-importer.js +97 -0
  90. package/dist/es2022/import/importers/content-items-importer.js.map +1 -0
  91. package/dist/es2022/import/importers/language-variant-importer.d.ts +11 -0
  92. package/dist/es2022/import/importers/language-variant-importer.js +215 -0
  93. package/dist/es2022/import/importers/language-variant-importer.js.map +1 -0
  94. package/dist/es2022/import/importers/workflow-importer.d.ts +18 -0
  95. package/dist/es2022/import/importers/workflow-importer.js +122 -0
  96. package/dist/es2022/import/importers/workflow-importer.js.map +1 -0
  97. package/dist/es2022/import/index.d.ts +2 -0
  98. package/dist/es2022/import/index.js +3 -0
  99. package/dist/es2022/import/index.js.map +1 -0
  100. package/dist/es2022/import/utils/import.utils.d.ts +2 -0
  101. package/dist/es2022/import/utils/import.utils.js +5 -0
  102. package/dist/es2022/import/utils/import.utils.js.map +1 -0
  103. package/dist/es2022/index.d.ts +8 -0
  104. package/dist/es2022/index.js +10 -0
  105. package/dist/es2022/index.js.map +1 -0
  106. package/dist/es2022/metadata.d.ts +5 -0
  107. package/dist/es2022/metadata.js +6 -0
  108. package/dist/es2022/metadata.js.map +1 -0
  109. package/dist/es2022/node/cli/actions/export-action.d.ts +2 -0
  110. package/dist/es2022/node/cli/actions/export-action.js +40 -0
  111. package/dist/es2022/node/cli/actions/export-action.js.map +1 -0
  112. package/dist/es2022/node/cli/actions/import-action.d.ts +2 -0
  113. package/dist/es2022/node/cli/actions/import-action.js +29 -0
  114. package/dist/es2022/node/cli/actions/import-action.js.map +1 -0
  115. package/dist/es2022/node/cli/actions/migrate-action.d.ts +2 -0
  116. package/dist/es2022/node/cli/actions/migrate-action.js +47 -0
  117. package/dist/es2022/node/cli/actions/migrate-action.js.map +1 -0
  118. package/dist/es2022/node/cli/app.d.ts +2 -0
  119. package/dist/es2022/node/cli/app.js +27 -0
  120. package/dist/es2022/node/cli/app.js.map +1 -0
  121. package/dist/es2022/node/cli/args/args-fetcher.d.ts +2 -0
  122. package/dist/es2022/node/cli/args/args-fetcher.js +46 -0
  123. package/dist/es2022/node/cli/args/args-fetcher.js.map +1 -0
  124. package/dist/es2022/node/cli/args/args-setter.d.ts +2 -0
  125. package/dist/es2022/node/cli/args/args-setter.js +31 -0
  126. package/dist/es2022/node/cli/args/args-setter.js.map +1 -0
  127. package/dist/es2022/node/cli/cli.models.d.ts +24 -0
  128. package/dist/es2022/node/cli/cli.models.js +2 -0
  129. package/dist/es2022/node/cli/cli.models.js.map +1 -0
  130. package/dist/es2022/node/cli/commands.d.ts +1 -0
  131. package/dist/es2022/node/cli/commands.js +157 -0
  132. package/dist/es2022/node/cli/commands.js.map +1 -0
  133. package/dist/es2022/toolkit/elements-builder.d.ts +14 -0
  134. package/dist/es2022/toolkit/elements-builder.js +69 -0
  135. package/dist/es2022/toolkit/elements-builder.js.map +1 -0
  136. package/dist/es2022/toolkit/export.d.ts +3 -0
  137. package/dist/es2022/toolkit/export.js +21 -0
  138. package/dist/es2022/toolkit/export.js.map +1 -0
  139. package/dist/es2022/toolkit/file.d.ts +12 -0
  140. package/dist/es2022/toolkit/file.js +50 -0
  141. package/dist/es2022/toolkit/file.js.map +1 -0
  142. package/dist/es2022/toolkit/import.d.ts +2 -0
  143. package/dist/es2022/toolkit/import.js +21 -0
  144. package/dist/es2022/toolkit/import.js.map +1 -0
  145. package/dist/es2022/toolkit/index.d.ts +5 -0
  146. package/dist/es2022/toolkit/index.js +6 -0
  147. package/dist/es2022/toolkit/index.js.map +1 -0
  148. package/dist/es2022/toolkit/migrate.d.ts +21 -0
  149. package/dist/es2022/toolkit/migrate.js +39 -0
  150. package/dist/es2022/toolkit/migrate.js.map +1 -0
  151. package/dist/es2022/translation/extraction/items-extraction.processor.d.ts +24 -0
  152. package/dist/es2022/translation/extraction/items-extraction.processor.js +108 -0
  153. package/dist/es2022/translation/extraction/items-extraction.processor.js.map +1 -0
  154. package/dist/es2022/translation/helpers/rich-text.processor.d.ts +22 -0
  155. package/dist/es2022/translation/helpers/rich-text.processor.js +209 -0
  156. package/dist/es2022/translation/helpers/rich-text.processor.js.map +1 -0
  157. package/dist/es2022/translation/index.d.ts +4 -0
  158. package/dist/es2022/translation/index.js +5 -0
  159. package/dist/es2022/translation/index.js.map +1 -0
  160. package/dist/es2022/translation/transforms/export-transforms.d.ts +3 -0
  161. package/dist/es2022/translation/transforms/export-transforms.js +196 -0
  162. package/dist/es2022/translation/transforms/export-transforms.js.map +1 -0
  163. package/dist/es2022/translation/transforms/import-transforms.d.ts +7 -0
  164. package/dist/es2022/translation/transforms/import-transforms.js +183 -0
  165. package/dist/es2022/translation/transforms/import-transforms.js.map +1 -0
  166. package/dist/es2022/zip/index.d.ts +4 -0
  167. package/dist/es2022/zip/index.js +5 -0
  168. package/dist/es2022/zip/index.js.map +1 -0
  169. package/dist/es2022/zip/zip-manager.d.ts +6 -0
  170. package/dist/es2022/zip/zip-manager.js +27 -0
  171. package/dist/es2022/zip/zip-manager.js.map +1 -0
  172. package/dist/es2022/zip/zip-packager.d.ts +3 -0
  173. package/dist/es2022/zip/zip-packager.js +69 -0
  174. package/dist/es2022/zip/zip-packager.js.map +1 -0
  175. package/dist/es2022/zip/zip-transformer.d.ts +6 -0
  176. package/dist/es2022/zip/zip-transformer.js +82 -0
  177. package/dist/es2022/zip/zip-transformer.js.map +1 -0
  178. package/dist/es2022/zip/zip.models.d.ts +13 -0
  179. package/dist/es2022/zip/zip.models.js +2 -0
  180. package/dist/es2022/zip/zip.models.js.map +1 -0
  181. package/lib/core/helpers/workflow-helper.ts +104 -0
  182. package/lib/core/index.ts +17 -0
  183. package/lib/core/logs/loggers.ts +80 -0
  184. package/lib/core/models/core.models.ts +134 -0
  185. package/lib/core/models/log.models.ts +31 -0
  186. package/lib/core/models/migration.models.ts +165 -0
  187. package/lib/core/utils/array.utils.ts +49 -0
  188. package/lib/core/utils/binary-data.utils.ts +29 -0
  189. package/lib/core/utils/confirm.utils.ts +139 -0
  190. package/lib/core/utils/error.utils.ts +65 -0
  191. package/lib/core/utils/external-id.utils.ts +9 -0
  192. package/lib/core/utils/global.utils.ts +59 -0
  193. package/lib/core/utils/http.utils.ts +35 -0
  194. package/lib/core/utils/management-client-utils.ts +182 -0
  195. package/lib/core/utils/processing-utils.ts +71 -0
  196. package/lib/core/utils/run.utils.ts +51 -0
  197. package/lib/export/context/export-context-fetcher.ts +475 -0
  198. package/lib/export/export-manager.ts +249 -0
  199. package/lib/export/export.models.ts +87 -0
  200. package/lib/export/index.ts +2 -0
  201. package/lib/export/utils/export.utils.ts +10 -0
  202. package/lib/file/file-manager.ts +37 -0
  203. package/lib/file/index.ts +1 -0
  204. package/lib/import/comparers/asset-comparer.ts +113 -0
  205. package/lib/import/context/import-context-fetcher.ts +367 -0
  206. package/lib/import/import-manager.ts +103 -0
  207. package/lib/import/import.models.ts +84 -0
  208. package/lib/import/importers/assets-importer.ts +239 -0
  209. package/lib/import/importers/content-items-importer.ts +142 -0
  210. package/lib/import/importers/language-variant-importer.ts +342 -0
  211. package/lib/import/importers/workflow-importer.ts +159 -0
  212. package/lib/import/index.ts +2 -0
  213. package/lib/import/utils/import.utils.ts +10 -0
  214. package/lib/index.ts +9 -0
  215. package/lib/metadata.ts +6 -0
  216. package/lib/node/cli/actions/export-action.ts +45 -0
  217. package/lib/node/cli/actions/import-action.ts +34 -0
  218. package/lib/node/cli/actions/migrate-action.ts +52 -0
  219. package/lib/node/cli/app.ts +29 -0
  220. package/lib/node/cli/args/args-fetcher.ts +61 -0
  221. package/lib/node/cli/args/args-setter.ts +35 -0
  222. package/lib/node/cli/cli.models.ts +28 -0
  223. package/lib/node/cli/commands.ts +161 -0
  224. package/lib/toolkit/elements-builder.ts +84 -0
  225. package/lib/toolkit/export.ts +21 -0
  226. package/lib/toolkit/file.ts +70 -0
  227. package/lib/toolkit/import.ts +21 -0
  228. package/lib/toolkit/index.ts +5 -0
  229. package/lib/toolkit/migrate.ts +71 -0
  230. package/lib/translation/extraction/items-extraction.processor.ts +181 -0
  231. package/lib/translation/helpers/rich-text.processor.ts +300 -0
  232. package/lib/translation/index.ts +4 -0
  233. package/lib/translation/transforms/export-transforms.ts +253 -0
  234. package/lib/translation/transforms/import-transforms.ts +215 -0
  235. package/lib/zip/index.ts +4 -0
  236. package/lib/zip/zip-manager.ts +33 -0
  237. package/lib/zip/zip-packager.ts +86 -0
  238. package/lib/zip/zip-transformer.ts +105 -0
  239. package/lib/zip/zip.models.ts +12 -0
  240. package/package.json +88 -0
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ import chalk from 'chalk';
3
+
4
+ import { handleError, exitProgram } from '../../core/index.js';
5
+ import { exportActionAsync } from './actions/export-action.js';
6
+ import { importActionAsync } from './actions/import-action.js';
7
+ import { migrateActionAsync } from './actions/migrate-action.js';
8
+ import { argumentsFetcherAsync } from './args/args-fetcher.js';
9
+
10
+ const run = async () => {
11
+ const argsFetcher = await argumentsFetcherAsync();
12
+ const action = argsFetcher.getCliAction();
13
+
14
+ if (action === 'export') {
15
+ return await exportActionAsync(argsFetcher);
16
+ } else if (action === 'import') {
17
+ return await importActionAsync(argsFetcher);
18
+ } else if (action === 'migrate') {
19
+ return await migrateActionAsync(argsFetcher);
20
+ }
21
+
22
+ exitProgram({
23
+ message: `Invalid action '${chalk.red(action)}'`
24
+ });
25
+ };
26
+
27
+ run().catch((err) => {
28
+ handleError(err);
29
+ });
@@ -0,0 +1,61 @@
1
+ import yargs from 'yargs';
2
+ import { hideBin } from 'yargs/helpers';
3
+ import chalk from 'chalk';
4
+ import { CliAction, exitProgram } from '../../../core/index.js';
5
+ import { CliArgumentsFetcher } from '../cli.models.js';
6
+
7
+ type ArgvResult = {
8
+ [x: string]: unknown;
9
+ _: (string | number)[];
10
+ $0: string;
11
+ };
12
+
13
+ export async function argumentsFetcherAsync(): Promise<CliArgumentsFetcher> {
14
+ const argv = yargs(hideBin(process.argv));
15
+ const resolvedArgv: ArgvResult = await argv.argv;
16
+
17
+ const getOptionalArgumentValue = (argName: string) => {
18
+ return resolvedArgv[argName]?.toString();
19
+ };
20
+
21
+ return {
22
+ getCliAction(): CliAction {
23
+ const command = resolvedArgv._?.[0]?.toString()?.toLowerCase();
24
+
25
+ if (command === <CliAction>'export') {
26
+ return 'export';
27
+ }
28
+ if (command === <CliAction>'import') {
29
+ return 'import';
30
+ }
31
+ if (command === <CliAction>'migrate') {
32
+ return 'migrate';
33
+ }
34
+
35
+ throw Error(`Unsupported command '${chalk.yellow(command)}'`);
36
+ },
37
+ getOptionalArgumentValue(argName: string): string | undefined {
38
+ return resolvedArgv[argName]?.toString();
39
+ },
40
+ getRequiredArgumentValue(argName: string): string {
41
+ const value = getOptionalArgumentValue(argName);
42
+
43
+ if (!value) {
44
+ exitProgram({
45
+ message: `Missing '${chalk.yellow(argName)}' argument value`
46
+ });
47
+ }
48
+
49
+ return value;
50
+ },
51
+ getBooleanArgumentValue(argName: string, defaultValue: boolean): boolean {
52
+ const value = getOptionalArgumentValue(argName);
53
+
54
+ if (!value) {
55
+ return defaultValue;
56
+ }
57
+
58
+ return value.toLowerCase() === 'true'.toLowerCase();
59
+ }
60
+ };
61
+ }
@@ -0,0 +1,35 @@
1
+ import yargs from 'yargs';
2
+ import { hideBin } from 'yargs/helpers';
3
+ import { CliArgumentsSetter, Command, CommandOption } from '../cli.models.js';
4
+
5
+ export function argumentsSetter(): CliArgumentsSetter {
6
+ const argv = yargs(hideBin(process.argv));
7
+
8
+ return {
9
+ withCommand(command: Command): CliArgumentsSetter {
10
+ argv.command(command.name, command.description, (yargs) => {
11
+ command.examples.forEach((example) => yargs.example(command.name, example));
12
+ command.options.forEach((option) => {
13
+ yargs.positional(option.name, {
14
+ alias: option.alias,
15
+ describe: option.description,
16
+ type: option.type,
17
+ demandOption: option.isRequired
18
+ });
19
+ });
20
+ });
21
+
22
+ return this;
23
+ },
24
+ withOption(option: CommandOption): CliArgumentsSetter {
25
+ argv.option(option.name, {
26
+ alias: option.alias,
27
+ description: option.description,
28
+ type: option.type,
29
+ demandOption: option.isRequired
30
+ });
31
+
32
+ return this;
33
+ }
34
+ };
35
+ }
@@ -0,0 +1,28 @@
1
+ import { CliAction } from '../../core/index.js';
2
+
3
+ export interface Command {
4
+ readonly name: string;
5
+ readonly description: string;
6
+ readonly options: readonly CommandOption[];
7
+ readonly examples: string[];
8
+ }
9
+
10
+ export interface CommandOption {
11
+ readonly name: string;
12
+ readonly isRequired: boolean;
13
+ readonly alias?: string;
14
+ readonly description?: string;
15
+ readonly type?: 'boolean' | 'number' | 'string';
16
+ }
17
+
18
+ export type CliArgumentsSetter = {
19
+ withCommand(command: Command): CliArgumentsSetter;
20
+ withOption(option: CommandOption): CliArgumentsSetter;
21
+ };
22
+
23
+ export type CliArgumentsFetcher = {
24
+ getCliAction(): CliAction;
25
+ getOptionalArgumentValue(argName: string): string | undefined;
26
+ getRequiredArgumentValue(argName: string): string;
27
+ getBooleanArgumentValue(argName: string, defaultValue: boolean): boolean;
28
+ };
@@ -0,0 +1,161 @@
1
+ import { argumentsSetter } from './args/args-setter.js';
2
+
3
+ export const cliArgs = argumentsSetter()
4
+ .withCommand({
5
+ name: 'export',
6
+ description: 'Exports content (items & assets) from Kontent.ai environment',
7
+ examples: [
8
+ `kontent-ai-migration-toolkit export --sourceEnvironmentId=x --sourceApiKey=x --language=default --items=itemA,itemB`
9
+ ],
10
+ options: [
11
+ {
12
+ name: `sourceApiKey`,
13
+ description: `Api key used for request authorization`,
14
+ type: 'string',
15
+ isRequired: true
16
+ },
17
+ {
18
+ name: `sourceEnvironmentId`,
19
+ description: `Environment id of the source environment`,
20
+ type: 'string',
21
+ isRequired: true
22
+ },
23
+ {
24
+ name: `language`,
25
+ description: `Language codename of items to export`,
26
+ type: 'string',
27
+ isRequired: true
28
+ },
29
+ {
30
+ name: `items`,
31
+ description: `Comma separated item codenames to export`,
32
+ type: 'string',
33
+ isRequired: true
34
+ },
35
+ {
36
+ name: `filename`,
37
+ description: `Name of items file to export / import`,
38
+ type: 'string',
39
+ isRequired: false
40
+ },
41
+ {
42
+ name: `assetsFilename`,
43
+ description: `Name of assets file to export / import`,
44
+ type: 'string',
45
+ isRequired: false
46
+ },
47
+ {
48
+ name: `baseUrl`,
49
+ description: `Custom base URL`,
50
+ type: 'string',
51
+ isRequired: false
52
+ }
53
+ ]
54
+ })
55
+
56
+ .withCommand({
57
+ name: 'import',
58
+ description: 'Imports content (items & assets) into Kontent.ai environment',
59
+ examples: [
60
+ `kontent-ai-migration-toolkit import --targetEnvironmentId=x --targetApiKey=x --filename=items.zip --assetsFilename=assets.zip`
61
+ ],
62
+ options: [
63
+ {
64
+ name: `targetApiKey`,
65
+ description: `Api key used for request authorization`,
66
+ type: 'string',
67
+ isRequired: true
68
+ },
69
+ {
70
+ name: `targetEnvironmentId`,
71
+ description: `Environment id of the target environment`,
72
+ type: 'string',
73
+ isRequired: true
74
+ },
75
+ {
76
+ name: `filename`,
77
+ description: `Name of items file to export / import`,
78
+ type: 'string',
79
+ isRequired: false
80
+ },
81
+ {
82
+ name: `assetsFilename`,
83
+ description: `Name of assets file to export / import`,
84
+ type: 'string',
85
+ isRequired: false
86
+ },
87
+ {
88
+ name: `baseUrl`,
89
+ description: `Custom base URL`,
90
+ type: 'string',
91
+ isRequired: false
92
+ }
93
+ ]
94
+ })
95
+
96
+ .withCommand({
97
+ name: 'migrate',
98
+ description:
99
+ 'Migrates content (items & assets) from one Kontent.ai environment into another Kontent.ai environment',
100
+ examples: [
101
+ `kontent-ai-migration-toolkit migrate --targetEnvironmentId=x --targetApiKey=x --sourceEnvironmentId=x --sourceApiKey=x --language=default --items=itemA,itemB`
102
+ ],
103
+ options: [
104
+ {
105
+ name: `sourceApiKey`,
106
+ description: `Api key used for request authorization`,
107
+ type: 'string',
108
+ isRequired: true
109
+ },
110
+ {
111
+ name: `sourceEnvironmentId`,
112
+ description: `Environment id of the source environment`,
113
+ type: 'string',
114
+ isRequired: true
115
+ },
116
+ {
117
+ name: `language`,
118
+ description: `Language codename of items to export`,
119
+ type: 'string',
120
+ isRequired: true
121
+ },
122
+ {
123
+ name: `items`,
124
+ description: `Comma separated item codenames to export`,
125
+ type: 'string',
126
+ isRequired: true
127
+ },
128
+ {
129
+ name: `targetApiKey`,
130
+ description: `Api key used for request authorization`,
131
+ type: 'string',
132
+ isRequired: true
133
+ },
134
+ {
135
+ name: `targetEnvironmentId`,
136
+ description: `Environment id of the target environment`,
137
+ type: 'string',
138
+ isRequired: true
139
+ },
140
+ {
141
+ name: `baseUrl`,
142
+ description: `Custom base URL`,
143
+ type: 'string',
144
+ isRequired: false
145
+ }
146
+ ]
147
+ })
148
+
149
+ .withOption({
150
+ alias: `f`,
151
+ name: `force`,
152
+ description: `When enabled, confirmation is not required`,
153
+ type: 'boolean',
154
+ isRequired: false
155
+ })
156
+ .withOption({
157
+ alias: `h`,
158
+ name: `help`,
159
+ description: `Show help`,
160
+ isRequired: false
161
+ });
@@ -0,0 +1,84 @@
1
+ import { MigrationElementModels } from '../core/index.js';
2
+
3
+ export const elementsBuilder = {
4
+ textElement: (data: Omit<MigrationElementModels.TextElement, 'type'>): MigrationElementModels.TextElement => {
5
+ return {
6
+ ...data,
7
+ type: 'text'
8
+ };
9
+ },
10
+ assetElement: (data: Omit<MigrationElementModels.AssetElement, 'type'>): MigrationElementModels.AssetElement => {
11
+ return {
12
+ ...data,
13
+ type: 'asset'
14
+ };
15
+ },
16
+ customElement: (data: Omit<MigrationElementModels.CustomElement, 'type'>): MigrationElementModels.CustomElement => {
17
+ return {
18
+ ...data,
19
+ type: 'custom'
20
+ };
21
+ },
22
+ dateTimeElement: (
23
+ data: Omit<MigrationElementModels.DateTimeElement, 'type'>
24
+ ): MigrationElementModels.DateTimeElement => {
25
+ return {
26
+ ...data,
27
+ type: 'date_time'
28
+ };
29
+ },
30
+ linkedItemsElement: (
31
+ data: Omit<MigrationElementModels.LinkedItemsElement, 'type'>
32
+ ): MigrationElementModels.LinkedItemsElement => {
33
+ return {
34
+ ...data,
35
+ type: 'modular_content'
36
+ };
37
+ },
38
+ multipleChoiceElement: (
39
+ data: Omit<MigrationElementModels.MultipleChoiceElement, 'type'>
40
+ ): MigrationElementModels.MultipleChoiceElement => {
41
+ return {
42
+ ...data,
43
+ type: 'multiple_choice'
44
+ };
45
+ },
46
+ numberElement: (data: Omit<MigrationElementModels.NumberElement, 'type'>): MigrationElementModels.NumberElement => {
47
+ return {
48
+ ...data,
49
+ type: 'number'
50
+ };
51
+ },
52
+ richTextElement: (
53
+ data: Omit<MigrationElementModels.RichTextElement, 'type'>
54
+ ): MigrationElementModels.RichTextElement => {
55
+ return {
56
+ ...data,
57
+ type: 'rich_text'
58
+ };
59
+ },
60
+ subpagesElement: (
61
+ data: Omit<MigrationElementModels.SubpagesElement, 'type'>
62
+ ): MigrationElementModels.SubpagesElement => {
63
+ return {
64
+ ...data,
65
+ type: 'subpages'
66
+ };
67
+ },
68
+ taxonomyElement: (
69
+ data: Omit<MigrationElementModels.TaxonomyElement, 'type'>
70
+ ): MigrationElementModels.TaxonomyElement => {
71
+ return {
72
+ ...data,
73
+ type: 'taxonomy'
74
+ };
75
+ },
76
+ urlSlugElement: (
77
+ data: Omit<MigrationElementModels.UrlSlugElement, 'type'>
78
+ ): MigrationElementModels.UrlSlugElement => {
79
+ return {
80
+ ...data,
81
+ type: 'url_slug'
82
+ };
83
+ }
84
+ };
@@ -0,0 +1,21 @@
1
+ import { libMetadata } from '../metadata.js';
2
+ import { MigrationData, executeWithTrackingAsync } from '../core/index.js';
3
+ import { ExportConfig, exportManager } from '../export/index.js';
4
+
5
+ export async function exportAsync(config: ExportConfig): Promise<MigrationData> {
6
+ return await executeWithTrackingAsync({
7
+ event: {
8
+ tool: 'migrationToolkit',
9
+ package: {
10
+ name: libMetadata.name,
11
+ version: libMetadata.version
12
+ },
13
+ action: 'export',
14
+ relatedEnvironmentId: undefined,
15
+ details: {}
16
+ },
17
+ func: async () => {
18
+ return await exportManager(config).exportAsync();
19
+ }
20
+ });
21
+ }
@@ -0,0 +1,70 @@
1
+ import { fileManager } from '../file/index.js';
2
+ import {
3
+ Logger,
4
+ executeWithTrackingAsync,
5
+ getDefaultZipFilename,
6
+ getDefaultLogger,
7
+ MigrationData
8
+ } from '../core/index.js';
9
+ import { zipManager } from '../zip/index.js';
10
+ import { libMetadata } from '../metadata.js';
11
+
12
+ export interface StoreConfig {
13
+ readonly data: MigrationData;
14
+ readonly filename?: string;
15
+ readonly logger?: Logger;
16
+ }
17
+
18
+ export interface ExtractConfig {
19
+ readonly filename?: string;
20
+ readonly logger?: Logger;
21
+ }
22
+
23
+ export async function storeAsync(config: StoreConfig): Promise<void> {
24
+ const logger = config.logger ?? getDefaultLogger();
25
+ const filename: string = getDefaultZipFilename();
26
+
27
+ await executeWithTrackingAsync<void>({
28
+ event: {
29
+ tool: 'migrationToolkit',
30
+ package: {
31
+ name: libMetadata.name,
32
+ version: libMetadata.version
33
+ },
34
+ action: 'store',
35
+ relatedEnvironmentId: undefined,
36
+ details: {}
37
+ },
38
+ func: async () => {
39
+ const zipData = await zipManager(logger).createZipAsync(config.data);
40
+
41
+ if (zipData instanceof Buffer) {
42
+ await fileManager(logger).writeFileAsync(filename, zipData);
43
+ } else {
44
+ throw Error(`Cannot store '${filename}' on File system because the provided zip is not a Buffer`);
45
+ }
46
+ }
47
+ });
48
+ }
49
+
50
+ export async function extractAsync(config: ExtractConfig): Promise<MigrationData> {
51
+ const logger = config.logger ?? getDefaultLogger();
52
+ const filename: string = getDefaultZipFilename();
53
+
54
+ return await executeWithTrackingAsync({
55
+ event: {
56
+ tool: 'migrationToolkit',
57
+ package: {
58
+ name: libMetadata.name,
59
+ version: libMetadata.version
60
+ },
61
+ action: 'extract',
62
+ relatedEnvironmentId: undefined,
63
+ details: {}
64
+ },
65
+ func: async () => {
66
+ const fileData = await fileManager(logger).loadFileAsync(filename);
67
+ return await zipManager(logger).parseZipAsync(fileData);
68
+ }
69
+ });
70
+ }
@@ -0,0 +1,21 @@
1
+ import { executeWithTrackingAsync } from '../core/index.js';
2
+ import { ImportConfig, ImportResult, importManager } from '../import/index.js';
3
+ import { libMetadata } from '../metadata.js';
4
+
5
+ export async function importAsync(config: ImportConfig): Promise<ImportResult> {
6
+ return await executeWithTrackingAsync({
7
+ event: {
8
+ tool: 'migrationToolkit',
9
+ package: {
10
+ name: libMetadata.name,
11
+ version: libMetadata.version
12
+ },
13
+ action: 'import',
14
+ relatedEnvironmentId: undefined,
15
+ details: {}
16
+ },
17
+ func: async () => {
18
+ return await importManager(config).importAsync();
19
+ }
20
+ });
21
+ }
@@ -0,0 +1,5 @@
1
+ export * from './export.js';
2
+ export * from './import.js';
3
+ export * from './elements-builder.js';
4
+ export * from './migrate.js';
5
+ export * from './file.js';
@@ -0,0 +1,71 @@
1
+ import { libMetadata } from '../metadata.js';
2
+ import { IRetryStrategyOptions } from '@kontent-ai/core-sdk';
3
+ import {
4
+ ExternalIdGenerator,
5
+ Logger,
6
+ ManagementClientConfig,
7
+ MigrationData,
8
+ executeWithTrackingAsync,
9
+ getDefaultLogger
10
+ } from '../core/index.js';
11
+ import { SourceExportItem } from '../export/index.js';
12
+ import { exportAsync } from './export.js';
13
+ import { importAsync } from './import.js';
14
+ import { ImportResult } from '../import/index.js';
15
+
16
+ export interface MigrationSource extends ManagementClientConfig {
17
+ readonly items: readonly SourceExportItem[];
18
+ }
19
+
20
+ export interface MigrationTarget extends ManagementClientConfig {}
21
+
22
+ export interface MigrationConfig {
23
+ readonly retryStrategy?: IRetryStrategyOptions;
24
+ readonly externalIdGenerator?: ExternalIdGenerator;
25
+ readonly logger?: Logger;
26
+ readonly sourceEnvironment: MigrationSource;
27
+ readonly targetEnvironment: MigrationTarget;
28
+ }
29
+
30
+ export interface MigrationResult {
31
+ readonly migrationData: MigrationData;
32
+ readonly importResult: ImportResult;
33
+ }
34
+
35
+ export async function migrateAsync(config: MigrationConfig): Promise<MigrationResult> {
36
+ const logger = config.logger ?? getDefaultLogger();
37
+
38
+ return await executeWithTrackingAsync({
39
+ event: {
40
+ tool: 'migrationToolkit',
41
+ package: {
42
+ name: libMetadata.name,
43
+ version: libMetadata.version
44
+ },
45
+ action: 'migrate',
46
+ relatedEnvironmentId: undefined,
47
+ details: {
48
+ itemsCount: config.sourceEnvironment.items.length
49
+ }
50
+ },
51
+ func: async () => {
52
+ const migrationData = await exportAsync({
53
+ ...config.sourceEnvironment,
54
+ logger: logger,
55
+ exportItems: config.sourceEnvironment.items
56
+ });
57
+
58
+ const importResult = await importAsync({
59
+ ...config.targetEnvironment,
60
+ logger: logger,
61
+ data: migrationData,
62
+ externalIdGenerator: config.externalIdGenerator
63
+ });
64
+
65
+ return {
66
+ importResult,
67
+ migrationData
68
+ };
69
+ }
70
+ });
71
+ }