@contentstack/cli-cm-import 1.28.1 → 2.0.0-beta

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 (85) hide show
  1. package/README.md +5 -7
  2. package/lib/commands/cm/stacks/import.d.ts +2 -0
  3. package/lib/commands/cm/stacks/import.js +46 -11
  4. package/lib/config/index.js +0 -1
  5. package/lib/import/module-importer.js +6 -20
  6. package/lib/import/modules/assets.d.ts +6 -0
  7. package/lib/import/modules/assets.js +102 -25
  8. package/lib/import/modules/base-class.d.ts +17 -0
  9. package/lib/import/modules/base-class.js +45 -0
  10. package/lib/import/modules/content-types.d.ts +7 -10
  11. package/lib/import/modules/content-types.js +132 -68
  12. package/lib/import/modules/custom-roles.d.ts +6 -2
  13. package/lib/import/modules/custom-roles.js +80 -69
  14. package/lib/import/modules/entries.d.ts +7 -0
  15. package/lib/import/modules/entries.js +278 -163
  16. package/lib/import/modules/environments.d.ts +3 -0
  17. package/lib/import/modules/environments.js +69 -38
  18. package/lib/import/modules/extensions.d.ts +3 -0
  19. package/lib/import/modules/extensions.js +99 -64
  20. package/lib/import/modules/global-fields.d.ts +8 -1
  21. package/lib/import/modules/global-fields.js +123 -63
  22. package/lib/import/modules/index.d.ts +1 -0
  23. package/lib/import/modules/index.js +1 -0
  24. package/lib/import/modules/labels.d.ts +3 -0
  25. package/lib/import/modules/labels.js +104 -54
  26. package/lib/import/modules/locales.d.ts +15 -4
  27. package/lib/import/modules/locales.js +194 -94
  28. package/lib/import/modules/marketplace-apps.d.ts +6 -3
  29. package/lib/import/modules/marketplace-apps.js +177 -102
  30. package/lib/import/modules/personalize.d.ts +11 -4
  31. package/lib/import/modules/personalize.js +138 -47
  32. package/lib/import/modules/stack.d.ts +6 -0
  33. package/lib/import/modules/stack.js +71 -27
  34. package/lib/import/modules/taxonomies.d.ts +4 -2
  35. package/lib/import/modules/taxonomies.js +60 -46
  36. package/lib/import/modules/variant-entries.d.ts +7 -4
  37. package/lib/import/modules/variant-entries.js +76 -35
  38. package/lib/import/modules/webhooks.d.ts +3 -0
  39. package/lib/import/modules/webhooks.js +71 -40
  40. package/lib/import/modules/workflows.d.ts +3 -0
  41. package/lib/import/modules/workflows.js +98 -48
  42. package/lib/types/default-config.d.ts +0 -1
  43. package/lib/types/import-config.d.ts +0 -1
  44. package/lib/types/index.d.ts +1 -12
  45. package/lib/utils/backup-handler.js +0 -1
  46. package/lib/utils/constants.d.ts +243 -0
  47. package/lib/utils/constants.js +264 -0
  48. package/lib/utils/import-config-handler.js +2 -0
  49. package/lib/utils/import-path-resolver.js +3 -13
  50. package/lib/utils/index.d.ts +1 -1
  51. package/lib/utils/index.js +6 -2
  52. package/lib/utils/marketplace-app-helper.js +3 -8
  53. package/lib/utils/progress-strategy-registry.d.ts +7 -0
  54. package/lib/utils/progress-strategy-registry.js +72 -0
  55. package/lib/utils/setup-branch.js +1 -1
  56. package/oclif.manifest.json +2 -2
  57. package/package.json +2 -2
  58. package/lib/import/modules-js/assets.d.ts +0 -33
  59. package/lib/import/modules-js/assets.js +0 -428
  60. package/lib/import/modules-js/content-types.d.ts +0 -34
  61. package/lib/import/modules-js/content-types.js +0 -204
  62. package/lib/import/modules-js/custom-roles.d.ts +0 -15
  63. package/lib/import/modules-js/custom-roles.js +0 -143
  64. package/lib/import/modules-js/entries.d.ts +0 -54
  65. package/lib/import/modules-js/entries.js +0 -1280
  66. package/lib/import/modules-js/environments.d.ts +0 -13
  67. package/lib/import/modules-js/environments.js +0 -85
  68. package/lib/import/modules-js/extensions.d.ts +0 -18
  69. package/lib/import/modules-js/extensions.js +0 -86
  70. package/lib/import/modules-js/global-fields.d.ts +0 -13
  71. package/lib/import/modules-js/global-fields.js +0 -106
  72. package/lib/import/modules-js/index.d.ts +0 -1
  73. package/lib/import/modules-js/index.js +0 -33
  74. package/lib/import/modules-js/labels.d.ts +0 -20
  75. package/lib/import/modules-js/labels.js +0 -148
  76. package/lib/import/modules-js/locales.d.ts +0 -24
  77. package/lib/import/modules-js/locales.js +0 -196
  78. package/lib/import/modules-js/marketplace-apps.d.ts +0 -63
  79. package/lib/import/modules-js/marketplace-apps.js +0 -429
  80. package/lib/import/modules-js/webhooks.d.ts +0 -17
  81. package/lib/import/modules-js/webhooks.js +0 -85
  82. package/lib/import/modules-js/workflows.d.ts +0 -19
  83. package/lib/import/modules-js/workflows.js +0 -170
  84. package/lib/utils/log.d.ts +0 -12
  85. package/lib/utils/log.js +0 -31
@@ -1,196 +0,0 @@
1
- /* eslint-disable no-prototype-builtins */
2
- /*!
3
- * Contentstack Import
4
- * Copyright (c) 2024 Contentstack LLC
5
- * MIT Licensed
6
- */
7
- let fs = require('fs');
8
- let path = require('path');
9
- let chalk = require('chalk');
10
- let mkdirp = require('mkdirp');
11
- let Promise = require('bluebird');
12
- let { isEmpty, merge, cloneDeep } = require('lodash');
13
- const { cliux } = require('@contentstack/cli-utilities');
14
- let { default: config } = require('../../config');
15
- const { fileHelper, log, formatError } = require('../../utils');
16
- module.exports = class ImportLanguages {
17
- constructor(importConfig, stackAPIClient) {
18
- var _a;
19
- this.config = merge(config, importConfig);
20
- this.stackAPIClient = stackAPIClient;
21
- this.fails = [];
22
- this.success = [];
23
- this.langUidMapper = {};
24
- this.masterLanguage = (_a = importConfig.master_locale) === null || _a === void 0 ? void 0 : _a.code;
25
- this.langConfig = importConfig.modules.locales;
26
- this.sourceMasterLangConfig = config.modules.masterLocale;
27
- this.reqConcurrency = importConfig.concurrency || importConfig.fetchConcurrency || 1;
28
- }
29
- start() {
30
- log(this.config, 'Migrating languages', 'success');
31
- const self = this;
32
- let langMapperPath = path.resolve(this.config.data, 'mapper', 'languages');
33
- let langFolderPath = path.resolve(this.config.data, this.langConfig.dirName);
34
- let langFailsPath = path.resolve(this.config.data, 'mapper', 'languages', 'fails.json');
35
- let langUidMapperPath = path.resolve(this.config.data, 'mapper', 'languages', 'uid-mapper.json');
36
- self.langSuccessPath = path.resolve(this.config.data, 'mapper', 'languages', 'success.json');
37
- self.languages = fileHelper.readFileSync(path.resolve(langFolderPath, this.langConfig.fileName));
38
- self.sourceMasterLanguages = fileHelper.readFileSync(path.resolve(langFolderPath, this.sourceMasterLangConfig.fileName));
39
- mkdirp.sync(langMapperPath);
40
- if (fs.existsSync(langUidMapperPath)) {
41
- self.langUidMapper = fileHelper.readFileSync(langUidMapperPath);
42
- self.langUidMapper = self.langUidMapper || {};
43
- }
44
- return new Promise(async function (resolve, reject) {
45
- if (self.languages === undefined || isEmpty(self.languages)) {
46
- log(self.config, chalk.white('No Languages Found'), 'success');
47
- return resolve({ empty: true });
48
- }
49
- let sourceMasterLangDetails = self.sourceMasterLanguages && Object.values(self.sourceMasterLanguages);
50
- if (sourceMasterLangDetails &&
51
- sourceMasterLangDetails[0] &&
52
- sourceMasterLangDetails[0]['code'] &&
53
- self.masterLanguage['code'] === sourceMasterLangDetails[0]['code']) {
54
- await self.checkAndUpdateMasterLocaleName(sourceMasterLangDetails).catch((error) => {
55
- log(self.config, formatError(error), 'warn');
56
- });
57
- }
58
- let langUids = Object.keys(self.languages);
59
- return Promise.map(langUids, (langUid) => {
60
- let lang = self.languages[langUid];
61
- if (!self.langUidMapper.hasOwnProperty(langUid) && lang.code !== self.masterLanguage) {
62
- let requestOption = {
63
- locale: {
64
- code: lang.code,
65
- name: lang.name,
66
- },
67
- };
68
- return self.stackAPIClient
69
- .locale()
70
- .create(requestOption)
71
- .then((locale) => {
72
- self.success.push(locale.items);
73
- self.langUidMapper[langUid] = locale.uid;
74
- fileHelper.writeFileSync(langUidMapperPath, self.langUidMapper);
75
- })
76
- .catch(function (err) {
77
- var _a;
78
- let error = JSON.parse(err.message);
79
- if (error.hasOwnProperty('errorCode') && error.errorCode === 247) {
80
- if ((_a = error === null || error === void 0 ? void 0 : error.errors) === null || _a === void 0 ? void 0 : _a.code) {
81
- log(self.config, error.errors.code[0], 'error');
82
- }
83
- else {
84
- log(self.config, err, 'error');
85
- }
86
- return err;
87
- }
88
- self.fails.push(lang);
89
- log(self.config, `Language '${lang.code}' failed to import\n`, 'error');
90
- log(self.config, formatError(err), 'error');
91
- });
92
- }
93
- else {
94
- // the language has already been created
95
- log(self.config, `The language '${lang.code}' already exists.`, 'error');
96
- }
97
- return Promise.resolve();
98
- // import 2 languages at a time
99
- }, { concurrency: self.reqConcurrency })
100
- .then(function () {
101
- // languages have imported successfully
102
- return self
103
- .updateLocales(langUids)
104
- .then(() => {
105
- fileHelper.writeFileSync(self.langSuccessPath, self.success);
106
- log(self.config, chalk.green('Languages have been imported successfully!'), 'success');
107
- resolve();
108
- })
109
- .catch(function (error) {
110
- log(self.config, formatError(error), 'error');
111
- reject(error);
112
- });
113
- })
114
- .catch(function (error) {
115
- // error while importing languages
116
- fileHelper.writeFileSync(langFailsPath, self.fails);
117
- log(self.config, `Language import failed. ${formatError(error)}`, 'error');
118
- reject('failed to import Languages');
119
- });
120
- });
121
- }
122
- updateLocales(langUids) {
123
- let self = this;
124
- return new Promise(function (resolve, reject) {
125
- Promise.all(langUids.map(async (langUid) => {
126
- let lang = {};
127
- let requireKeys = self.config.modules.locales.requiredKeys;
128
- let _lang = self.languages[langUid];
129
- requireKeys.forEach((e) => {
130
- lang[e] = _lang[e];
131
- });
132
- let langobj = self.stackAPIClient.locale(lang.code);
133
- Object.assign(langobj, cloneDeep(lang));
134
- langobj.update().then(() => {
135
- // empty function
136
- });
137
- }))
138
- .then(resolve)
139
- .catch((error) => {
140
- log(self.config, formatError(error), 'error');
141
- reject(error);
142
- });
143
- });
144
- }
145
- checkAndUpdateMasterLocaleName(sourceMasterLangDetails) {
146
- let self = this;
147
- return new Promise(async function (resolve, reject) {
148
- let masterLangDetails = await self.stackAPIClient
149
- .locale(self.masterLanguage['code'])
150
- .fetch()
151
- .catch((error) => {
152
- log(self.config, formatError(error), 'warn');
153
- });
154
- if (masterLangDetails &&
155
- masterLangDetails['name'] &&
156
- sourceMasterLangDetails[0]['name'] &&
157
- masterLangDetails['name'].toString().toUpperCase() !==
158
- sourceMasterLangDetails[0]['name'].toString().toUpperCase()) {
159
- cliux.print('WARNING!!! The master language name for the source and destination is different.', {
160
- color: 'yellow',
161
- });
162
- cliux.print(`Old Master language name: ${masterLangDetails['name']}`, { color: 'red' });
163
- cliux.print(`New Master language name: ${sourceMasterLangDetails[0]['name']}`, { color: 'green' });
164
- let confirm = await cliux.inquire({
165
- type: 'confirm',
166
- message: 'Are you sure you want to update name of master language?',
167
- name: 'confirmation',
168
- });
169
- if (confirm) {
170
- let languid = sourceMasterLangDetails[0] && sourceMasterLangDetails[0]['uid'];
171
- let lang = self.sourceMasterLanguages[languid];
172
- if (!lang)
173
- return reject('Locale not found.!');
174
- const langObj = self.stackAPIClient.locale(lang.code);
175
- Object.assign(langObj, { name: lang.name });
176
- langObj
177
- .update()
178
- .then(() => {
179
- fileHelper.writeFileSync(self.langSuccessPath, self.success);
180
- log(self.config, chalk.green('Master Languages name have been updated successfully!'), 'success');
181
- resolve();
182
- })
183
- .catch(function (error) {
184
- reject(error);
185
- });
186
- }
187
- else {
188
- resolve();
189
- }
190
- }
191
- else {
192
- resolve();
193
- }
194
- });
195
- }
196
- };
@@ -1,63 +0,0 @@
1
- export = ImportMarketplaceApps;
2
- declare class ImportMarketplaceApps {
3
- constructor(importConfig: any, stackAPIClient: any);
4
- client: any;
5
- httpClient: any;
6
- appOriginalName: any;
7
- appUidMapping: {};
8
- appNameMapping: {};
9
- marketplaceApps: any[];
10
- installationUidMapping: {};
11
- developerHubBaseUrl: any;
12
- marketplaceAppFolderPath: string;
13
- marketplaceAppConfig: {
14
- dirName: string;
15
- fileName: string;
16
- };
17
- config: any;
18
- stackAPIClient: any;
19
- start(): Promise<void>;
20
- mapperDirPath: string;
21
- uidMapperPath: string;
22
- appSdkAxiosInstance: any;
23
- getOrgUid(): Promise<void>;
24
- getAndValidateEncryptionKey(defaultValue: any, retry?: number): any;
25
- nodeCrypto: NodeCrypto;
26
- /**
27
- * @method startInstallation
28
- * @returns {Promise<void>}
29
- */
30
- startInstallation(): Promise<void>;
31
- generateUidMapper(): Promise<{}>;
32
- /**
33
- * @method handleAllPrivateAppsCreationProcess
34
- * @param {Object} options
35
- * @returns {Promise<void>}
36
- */
37
- handleAllPrivateAppsCreationProcess(): Promise<void>;
38
- getConfirmationToCreateApps(privateApps: any): Promise<boolean>;
39
- createPrivateApps(app: any, uidCleaned?: boolean, appSuffix?: number): any;
40
- appCreationCallback(app: any, response: any, appSuffix: any): any;
41
- handleNameConflict(app: any, appSuffix: any): any;
42
- updateManifestUILocations(locations: any, type?: string, appSuffix?: number): any[];
43
- getAppName(name: any, appSuffix?: number): any;
44
- /**
45
- * @method installApps
46
- *
47
- * @param {Record<string, any>} app
48
- * @param {Record<string, any>[]} installedApps
49
- * @returns {Promise<void>}
50
- */
51
- installApps(app: Record<string, any>, installedApps: Record<string, any>[]): Promise<void>;
52
- makeRedirectUrlCall(response: any, appName: any): Promise<void>;
53
- ifAppAlreadyExist(app: any, currentStackApp: any): Promise<any>;
54
- confirmToCloseProcess(installation: any): Promise<void>;
55
- /**
56
- * @method updateAppsConfig
57
- * @param {Object<{ data, app }>} param
58
- * @returns {Promise<void>}
59
- */
60
- updateAppsConfig(app: any): Promise<void>;
61
- validateAppName(name: any): true | "The app name should be within 3-20 characters long.";
62
- }
63
- import { NodeCrypto } from "@contentstack/cli-utilities";