@contentstack/cli-cm-import 1.5.11 → 1.7.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 (126) hide show
  1. package/README.md +6 -14
  2. package/bin/dev +17 -0
  3. package/bin/dev.cmd +3 -0
  4. package/bin/run +6 -0
  5. package/bin/run.cmd +3 -0
  6. package/lib/commands/cm/stacks/import.d.ts +10 -0
  7. package/lib/commands/cm/stacks/import.js +111 -0
  8. package/lib/config/index.d.ts +3 -0
  9. package/lib/config/index.js +395 -0
  10. package/lib/import/index.d.ts +1 -0
  11. package/lib/import/index.js +8 -0
  12. package/lib/import/module-importer.d.ts +13 -0
  13. package/lib/import/module-importer.js +70 -0
  14. package/lib/import/modules/assets.d.ts +63 -0
  15. package/lib/import/modules/assets.js +265 -0
  16. package/lib/import/modules/base-class.d.ts +70 -0
  17. package/lib/import/modules/base-class.js +218 -0
  18. package/lib/import/modules/content-types.d.ts +56 -0
  19. package/lib/import/modules/content-types.js +186 -0
  20. package/lib/import/modules/custom-roles.d.ts +37 -0
  21. package/lib/import/modules/custom-roles.js +171 -0
  22. package/lib/import/modules/environments.d.ts +27 -0
  23. package/lib/import/modules/environments.js +106 -0
  24. package/lib/import/modules/extensions.d.ts +27 -0
  25. package/lib/import/modules/extensions.js +106 -0
  26. package/lib/import/modules/global-fields.d.ts +34 -0
  27. package/lib/import/modules/global-fields.js +99 -0
  28. package/lib/import/modules/index.d.ts +2 -0
  29. package/lib/import/modules/index.js +19 -0
  30. package/lib/import/modules/labels.d.ts +34 -0
  31. package/lib/import/modules/labels.js +171 -0
  32. package/lib/import/modules/locales.d.ts +31 -0
  33. package/lib/import/modules/locales.js +144 -0
  34. package/lib/import/modules/marketplace-apps.d.ts +51 -0
  35. package/lib/import/modules/marketplace-apps.js +297 -0
  36. package/lib/import/modules/webhooks.d.ts +27 -0
  37. package/lib/import/modules/webhooks.js +110 -0
  38. package/lib/import/modules-js/assets.d.ts +33 -0
  39. package/lib/import/modules-js/assets.js +415 -0
  40. package/lib/import/modules-js/content-types.d.ts +33 -0
  41. package/lib/import/modules-js/content-types.js +176 -0
  42. package/lib/import/modules-js/custom-roles.d.ts +15 -0
  43. package/lib/import/modules-js/custom-roles.js +143 -0
  44. package/lib/import/modules-js/entries.d.ts +54 -0
  45. package/lib/import/modules-js/entries.js +1260 -0
  46. package/lib/import/modules-js/environments.d.ts +13 -0
  47. package/lib/import/modules-js/environments.js +85 -0
  48. package/lib/import/modules-js/extensions.d.ts +18 -0
  49. package/lib/import/modules-js/extensions.js +86 -0
  50. package/lib/import/modules-js/global-fields.d.ts +13 -0
  51. package/lib/import/modules-js/global-fields.js +109 -0
  52. package/lib/import/modules-js/index.d.ts +1 -0
  53. package/lib/import/modules-js/index.js +33 -0
  54. package/lib/import/modules-js/labels.d.ts +20 -0
  55. package/lib/import/modules-js/labels.js +148 -0
  56. package/lib/import/modules-js/locales.d.ts +24 -0
  57. package/lib/import/modules-js/locales.js +196 -0
  58. package/lib/import/modules-js/marketplace-apps.d.ts +60 -0
  59. package/lib/import/modules-js/marketplace-apps.js +409 -0
  60. package/lib/import/modules-js/webhooks.d.ts +17 -0
  61. package/lib/import/modules-js/webhooks.js +85 -0
  62. package/lib/import/modules-js/workflows.d.ts +18 -0
  63. package/lib/import/modules-js/workflows.js +132 -0
  64. package/lib/types/default-config.d.ts +143 -0
  65. package/lib/types/default-config.js +2 -0
  66. package/lib/types/import-config.d.ts +52 -0
  67. package/lib/types/import-config.js +2 -0
  68. package/lib/types/index.d.ts +63 -0
  69. package/lib/types/index.js +4 -0
  70. package/lib/utils/asset-helper.d.ts +4 -0
  71. package/lib/utils/asset-helper.js +387 -0
  72. package/lib/utils/backup-handler.d.ts +2 -0
  73. package/lib/utils/backup-handler.js +31 -0
  74. package/lib/utils/common-helper.d.ts +20 -0
  75. package/lib/utils/common-helper.js +244 -0
  76. package/lib/utils/content-type-helper.d.ts +51 -0
  77. package/lib/utils/content-type-helper.js +145 -0
  78. package/lib/utils/entries-helper.d.ts +4 -0
  79. package/lib/utils/entries-helper.js +252 -0
  80. package/lib/utils/extension-helper.d.ts +5 -0
  81. package/lib/utils/extension-helper.js +84 -0
  82. package/lib/utils/file-helper.d.ts +14 -0
  83. package/lib/utils/file-helper.js +140 -0
  84. package/lib/utils/import-config-handler.d.ts +3 -0
  85. package/lib/utils/import-config-handler.js +73 -0
  86. package/lib/utils/index.d.ts +12 -0
  87. package/lib/utils/index.js +39 -0
  88. package/lib/utils/interactive.d.ts +7 -0
  89. package/lib/utils/interactive.js +88 -0
  90. package/lib/utils/logger.d.ts +8 -0
  91. package/lib/utils/logger.js +154 -0
  92. package/lib/utils/login-handler.d.ts +8 -0
  93. package/lib/utils/login-handler.js +53 -0
  94. package/lib/utils/marketplace-app-helper.d.ts +16 -0
  95. package/lib/utils/marketplace-app-helper.js +143 -0
  96. package/messages/index.json +1 -7
  97. package/oclif.manifest.json +2 -2
  98. package/package.json +46 -20
  99. package/src/app.js +0 -217
  100. package/src/commands/cm/stacks/import.js +0 -161
  101. package/src/config/default.js +0 -352
  102. package/src/lib/import/assets.js +0 -495
  103. package/src/lib/import/content-types.js +0 -201
  104. package/src/lib/import/custom-roles.js +0 -169
  105. package/src/lib/import/entries.js +0 -1495
  106. package/src/lib/import/environments.js +0 -106
  107. package/src/lib/import/extensions.js +0 -108
  108. package/src/lib/import/global-fields.js +0 -135
  109. package/src/lib/import/labels.js +0 -175
  110. package/src/lib/import/locales.js +0 -216
  111. package/src/lib/import/marketplace-apps.js +0 -542
  112. package/src/lib/import/webhooks.js +0 -113
  113. package/src/lib/import/workflows.js +0 -166
  114. package/src/lib/util/extensionsUidReplace.js +0 -67
  115. package/src/lib/util/fs.js +0 -124
  116. package/src/lib/util/import-flags.js +0 -187
  117. package/src/lib/util/index.js +0 -222
  118. package/src/lib/util/log.js +0 -144
  119. package/src/lib/util/login.js +0 -58
  120. package/src/lib/util/lookupReplaceAssets.js +0 -366
  121. package/src/lib/util/lookupReplaceEntries.js +0 -250
  122. package/src/lib/util/marketplace-app-helper.js +0 -31
  123. package/src/lib/util/removeReferenceFields.js +0 -59
  124. package/src/lib/util/schemaTemplate.js +0 -38
  125. package/src/lib/util/supress-mandatory-fields.js +0 -34
  126. package/src/lib/util/upload.js +0 -56
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.selectConfiguration = exports.getAppName = exports.askAppName = exports.askEncryptionKey = exports.askDeveloperHubUrl = exports.askAPIKey = exports.askContentDir = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
6
+ const path = tslib_1.__importStar(require("path"));
7
+ const first_1 = tslib_1.__importDefault(require("lodash/first"));
8
+ const split_1 = tslib_1.__importDefault(require("lodash/split"));
9
+ const askContentDir = async () => {
10
+ const result = await cli_utilities_1.cliux.inquire({
11
+ type: 'input',
12
+ message: 'Enter the path for the content',
13
+ name: 'dir',
14
+ });
15
+ return path.resolve(result);
16
+ };
17
+ exports.askContentDir = askContentDir;
18
+ const askAPIKey = async () => {
19
+ return cli_utilities_1.cliux.inquire({
20
+ type: 'input',
21
+ message: 'Enter the stack api key',
22
+ name: 'apiKey',
23
+ });
24
+ };
25
+ exports.askAPIKey = askAPIKey;
26
+ const askDeveloperHubUrl = async (regionName) => {
27
+ return await cli_utilities_1.cliux.inquire({
28
+ type: 'input',
29
+ name: 'name',
30
+ validate: (url) => {
31
+ if (!url)
32
+ return "Developer-hub URL can't be empty.";
33
+ return true;
34
+ },
35
+ message: `Enter the developer-hub base URL for the ${regionName} region -`,
36
+ });
37
+ };
38
+ exports.askDeveloperHubUrl = askDeveloperHubUrl;
39
+ const askEncryptionKey = async (defaultValue) => {
40
+ return await cli_utilities_1.cliux.inquire({
41
+ type: 'input',
42
+ name: 'name',
43
+ default: defaultValue,
44
+ validate: (key) => {
45
+ if (!key)
46
+ return "Encryption key can't be empty.";
47
+ return true;
48
+ },
49
+ message: 'Enter marketplace app configurations encryption key',
50
+ });
51
+ };
52
+ exports.askEncryptionKey = askEncryptionKey;
53
+ const askAppName = async (app, appSuffix) => {
54
+ return await cli_utilities_1.cliux.inquire({
55
+ type: 'input',
56
+ name: 'name',
57
+ validate: validateAppName,
58
+ default: (0, exports.getAppName)(app.name, appSuffix),
59
+ message: `${app.name} app already exist. Enter a new name to create an app.?`,
60
+ });
61
+ };
62
+ exports.askAppName = askAppName;
63
+ const getAppName = (name, appSuffix = 1) => {
64
+ if (name.length >= 19)
65
+ name = name.slice(0, 18);
66
+ name = `${(0, first_1.default)((0, split_1.default)(name, '◈'))}◈${appSuffix}`;
67
+ return name;
68
+ };
69
+ exports.getAppName = getAppName;
70
+ const validateAppName = (name) => {
71
+ if (name.length < 3 || name.length > 20) {
72
+ return 'The app name should be within 3-20 characters long.';
73
+ }
74
+ return true;
75
+ };
76
+ const selectConfiguration = async () => {
77
+ return await cli_utilities_1.cliux.inquire({
78
+ choices: [
79
+ 'Update it with the new configuration.',
80
+ 'Do not update the configuration (WARNING!!! If you do not update the configuration, there may be some issues with the content which you import).',
81
+ 'Exit',
82
+ ],
83
+ type: 'list',
84
+ name: 'value',
85
+ message: 'Choose the option to proceed',
86
+ });
87
+ };
88
+ exports.selectConfiguration = selectConfiguration;
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Contentstack Export
3
+ * Copyright (c) 2019 Contentstack LLC
4
+ * MIT Licensed
5
+ */
6
+ import { ImportConfig } from '../types';
7
+ export declare const log: (config: ImportConfig, message: any, type: string) => Promise<void>;
8
+ export declare const unlinkFileLogger: () => void;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ /*!
3
+ * Contentstack Export
4
+ * Copyright (c) 2019 Contentstack LLC
5
+ * MIT Licensed
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.unlinkFileLogger = exports.log = void 0;
9
+ const tslib_1 = require("tslib");
10
+ const winston = tslib_1.__importStar(require("winston"));
11
+ const path = tslib_1.__importStar(require("path"));
12
+ const mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
13
+ const slice = Array.prototype.slice;
14
+ const ansiRegexPattern = [
15
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
16
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
17
+ ].join('|');
18
+ function returnString(args) {
19
+ var returnStr = '';
20
+ if (args && args.length) {
21
+ returnStr = args
22
+ .map(function (item) {
23
+ if (item && typeof item === 'object') {
24
+ try {
25
+ return JSON.stringify(item).replace(/authtoken\":\d"blt................/g, 'authtoken":"blt....');
26
+ }
27
+ catch (error) { }
28
+ return item;
29
+ }
30
+ return item;
31
+ })
32
+ .join(' ')
33
+ .trim();
34
+ }
35
+ returnStr = returnStr.replace(new RegExp(ansiRegexPattern, 'g'), '').trim();
36
+ return returnStr;
37
+ }
38
+ var myCustomLevels = {
39
+ levels: {
40
+ warn: 1,
41
+ info: 2,
42
+ debug: 3,
43
+ },
44
+ colors: {
45
+ //colors aren't being used anywhere as of now, we're using chalk to add colors while logging
46
+ info: 'blue',
47
+ debug: 'green',
48
+ warn: 'yellow',
49
+ error: 'red',
50
+ },
51
+ };
52
+ let logger;
53
+ let errorLogger;
54
+ let successTransport;
55
+ let errorTransport;
56
+ function init(_logPath) {
57
+ if (!logger || !errorLogger) {
58
+ var logsDir = path.resolve(_logPath, 'logs', 'export');
59
+ // Create dir if doesn't already exist
60
+ mkdirp_1.default.sync(logsDir);
61
+ successTransport = {
62
+ filename: path.join(logsDir, 'success.log'),
63
+ maxFiles: 20,
64
+ maxsize: 1000000,
65
+ tailable: true,
66
+ level: 'info',
67
+ };
68
+ errorTransport = {
69
+ filename: path.join(logsDir, 'error.log'),
70
+ maxFiles: 20,
71
+ maxsize: 1000000,
72
+ tailable: true,
73
+ level: 'error',
74
+ };
75
+ logger = winston.createLogger({
76
+ transports: [
77
+ new winston.transports.File(successTransport),
78
+ new winston.transports.Console({ format: winston.format.simple() }),
79
+ ],
80
+ levels: myCustomLevels.levels,
81
+ });
82
+ errorLogger = winston.createLogger({
83
+ transports: [
84
+ new winston.transports.File(errorTransport),
85
+ new winston.transports.Console({
86
+ level: 'error',
87
+ format: winston.format.combine(winston.format.colorize({ all: true, colors: { error: 'red' } }), winston.format.simple()),
88
+ }),
89
+ ],
90
+ levels: { error: 0 },
91
+ });
92
+ }
93
+ return {
94
+ log: function (message) {
95
+ let args = slice.call(arguments);
96
+ let logString = returnString(args);
97
+ if (logString) {
98
+ logger.log('info', logString);
99
+ }
100
+ },
101
+ warn: function () {
102
+ let args = slice.call(arguments);
103
+ let logString = returnString(args);
104
+ if (logString) {
105
+ logger.log('warn', logString);
106
+ }
107
+ },
108
+ error: function (message) {
109
+ let args = slice.call(arguments);
110
+ let logString = returnString(args);
111
+ if (logString) {
112
+ errorLogger.log('error', logString);
113
+ }
114
+ },
115
+ debug: function () {
116
+ let args = slice.call(arguments);
117
+ let logString = returnString(args);
118
+ if (logString) {
119
+ logger.log('debug', logString);
120
+ }
121
+ },
122
+ };
123
+ }
124
+ const log = async (config, message, type) => {
125
+ config.data = config.data || path.join(__dirname, 'logs');
126
+ // ignoring the type argument, as we are not using it to create a logfile anymore
127
+ if (type !== 'error') {
128
+ // removed type argument from init method
129
+ init(config.data).log(message);
130
+ }
131
+ else {
132
+ init(config.data).error(message);
133
+ }
134
+ };
135
+ exports.log = log;
136
+ const unlinkFileLogger = () => {
137
+ if (logger) {
138
+ const transports = logger.transports;
139
+ transports.forEach((transport) => {
140
+ if (transport.name === 'file') {
141
+ logger.remove(transport);
142
+ }
143
+ });
144
+ }
145
+ if (errorLogger) {
146
+ const transports = errorLogger.transports;
147
+ transports.forEach((transport) => {
148
+ if (transport.name === 'file') {
149
+ errorLogger.remove(transport);
150
+ }
151
+ });
152
+ }
153
+ };
154
+ exports.unlinkFileLogger = unlinkFileLogger;
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Contentstack Import
3
+ * Copyright (c) 2019 Contentstack LLC
4
+ * MIT Licensed
5
+ */
6
+ import { ImportConfig } from '../types';
7
+ declare const login: (config: ImportConfig) => Promise<any>;
8
+ export default login;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /* eslint-disable max-statements-per-line */
3
+ /* eslint-disable no-console */
4
+ /* eslint-disable no-empty */
5
+ /*!
6
+ * Contentstack Import
7
+ * Copyright (c) 2019 Contentstack LLC
8
+ * MIT Licensed
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ const logger_1 = require("./logger");
12
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
13
+ const login = async (config) => {
14
+ const client = await (0, cli_utilities_1.managementSDKClient)(config);
15
+ if (config.email && config.password) {
16
+ const { user: { authtoken = null } = {} } = await client.login({ email: config.email, password: config.password });
17
+ if (authtoken) {
18
+ config.headers = {
19
+ api_key: config.source_stack,
20
+ access_token: config.access_token,
21
+ authtoken: config.authtoken,
22
+ 'X-User-Agent': 'contentstack-export/v',
23
+ };
24
+ (0, logger_1.log)(config, 'Contentstack account authenticated successfully!', 'success');
25
+ return config;
26
+ }
27
+ else {
28
+ throw new Error('Invalid auth token received after login');
29
+ }
30
+ }
31
+ else if (config.management_token) {
32
+ return config;
33
+ }
34
+ else if ((0, cli_utilities_1.isAuthenticated)()) {
35
+ const stackAPIClient = client.stack({
36
+ api_key: config.target_stack,
37
+ management_token: config.management_token,
38
+ });
39
+ const stack = await stackAPIClient.fetch().catch((error) => {
40
+ var _a;
41
+ let errorstack_key = (_a = error === null || error === void 0 ? void 0 : error.errors) === null || _a === void 0 ? void 0 : _a.api_key;
42
+ if (errorstack_key) {
43
+ (0, logger_1.log)(config, 'Stack Api key ' + errorstack_key[0] + 'Please enter valid Key', 'error');
44
+ throw error;
45
+ }
46
+ (0, logger_1.log)(config, error === null || error === void 0 ? void 0 : error.errorMessage, 'error');
47
+ throw error;
48
+ });
49
+ config.destinationStackName = stack.name;
50
+ return config;
51
+ }
52
+ };
53
+ exports.default = login;
@@ -0,0 +1,16 @@
1
+ import { HttpClient, ContentstackClient } from '@contentstack/cli-utilities';
2
+ import { ImportConfig } from '../types';
3
+ export declare const getAllStackSpecificApps: (developerHubBaseUrl: string, httpClient: HttpClient, config: ImportConfig) => Promise<any>;
4
+ export declare const getDeveloperHubUrl: (config: ImportConfig) => Promise<string>;
5
+ export declare const getOrgUid: (config: ImportConfig) => Promise<string>;
6
+ export declare const getConfirmationToCreateApps: (privateApps: any, config: ImportConfig) => Promise<boolean>;
7
+ export declare const createPrivateApp: (client: ContentstackClient, config: ImportConfig, app: any) => Promise<any>;
8
+ export declare const installApp: (client: ContentstackClient, config: ImportConfig, appManifestUid?: string, mappedUid?: string) => Promise<any>;
9
+ export declare const handleNameConflict: (app: any, appSuffix: number, config: ImportConfig) => Promise<any>;
10
+ export declare const makeRedirectUrlCall: (response: any, appName: string, config: ImportConfig) => Promise<void>;
11
+ export declare const confirmToCloseProcess: (installation: any, config: ImportConfig) => Promise<void>;
12
+ export declare const ifAppAlreadyExist: (app: any, currentStackApp: any, config: ImportConfig) => Promise<{}>;
13
+ export declare const updateAppConfig: (client: ContentstackClient, config: ImportConfig, app: any, payload: {
14
+ configuration: Record<string, unknown>;
15
+ server_configuration: Record<string, unknown>;
16
+ }) => Promise<any>;
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateAppConfig = exports.ifAppAlreadyExist = exports.confirmToCloseProcess = exports.makeRedirectUrlCall = exports.handleNameConflict = exports.installApp = exports.createPrivateApp = exports.getConfirmationToCreateApps = exports.getOrgUid = exports.getDeveloperHubUrl = exports.getAllStackSpecificApps = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
6
+ const map_1 = tslib_1.__importDefault(require("lodash/map"));
7
+ const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
8
+ const includes_1 = tslib_1.__importDefault(require("lodash/includes"));
9
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
10
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
11
+ const logger_1 = require("./logger");
12
+ const interactive_1 = require("./interactive");
13
+ const utils_1 = require("../utils");
14
+ const interactive_2 = require("../utils/interactive");
15
+ const getAllStackSpecificApps = async (developerHubBaseUrl, httpClient, config) => {
16
+ return await httpClient
17
+ .get(`${developerHubBaseUrl}/installations?target_uids=${config.target_stack}`)
18
+ .then(({ data }) => data.data)
19
+ .catch((error) => (0, logger_1.log)(config, `Failed to export marketplace-apps ${(0, utils_1.formatError)(error)}`, 'error'));
20
+ };
21
+ exports.getAllStackSpecificApps = getAllStackSpecificApps;
22
+ const getDeveloperHubUrl = async (config) => {
23
+ const { cma, name } = cli_utilities_1.configHandler.get('region') || {};
24
+ let developerHubBaseUrl = config.developerHubUrls[cma];
25
+ if (!developerHubBaseUrl) {
26
+ developerHubBaseUrl = await (0, interactive_1.askDeveloperHubUrl)(name);
27
+ }
28
+ return developerHubBaseUrl.startsWith('http') ? developerHubBaseUrl : `https://${developerHubBaseUrl}`;
29
+ };
30
+ exports.getDeveloperHubUrl = getDeveloperHubUrl;
31
+ const getOrgUid = async (config) => {
32
+ const tempAPIClient = await (0, cli_utilities_1.managementSDKClient)({ host: config.host });
33
+ const tempStackData = await tempAPIClient
34
+ .stack({ api_key: config.target_stack })
35
+ .fetch()
36
+ .catch((error) => {
37
+ (0, logger_1.log)(config, (0, utils_1.formatError)(error), 'error');
38
+ });
39
+ return (tempStackData === null || tempStackData === void 0 ? void 0 : tempStackData.org_uid) || '';
40
+ };
41
+ exports.getOrgUid = getOrgUid;
42
+ const getConfirmationToCreateApps = async (privateApps, config) => {
43
+ if (!config.forceStopMarketplaceAppsPrompt) {
44
+ if (!(await cli_utilities_1.cliux.confirm(chalk_1.default.yellow(`WARNING!!! The listed apps are private apps that are not available in the destination stack: \n\n${(0, map_1.default)(privateApps, ({ manifest: { name } }, index) => `${String(index + 1)}) ${name}`).join('\n')}\n\nWould you like to re-create the private app and then proceed with the installation? (y/n)`)))) {
45
+ if (await cli_utilities_1.cliux.confirm(chalk_1.default.yellow(`\nWARNING!!! Canceling the app re-creation may break the content type and entry import. Would you like to proceed without re-create the private app? (y/n)`))) {
46
+ return Promise.resolve(true);
47
+ }
48
+ if (!(await cli_utilities_1.cliux.confirm(chalk_1.default.yellow('\nWould you like to re-create the private app and then proceed with the installation? (y/n)')))) {
49
+ process.exit();
50
+ }
51
+ }
52
+ }
53
+ };
54
+ exports.getConfirmationToCreateApps = getConfirmationToCreateApps;
55
+ const createPrivateApp = async (client, config, app) => {
56
+ const privateApp = (0, omit_1.default)(app, ['uid']);
57
+ return await client
58
+ .organization(config.org_uid)
59
+ .app()
60
+ .create(privateApp)
61
+ .catch((error) => error);
62
+ };
63
+ exports.createPrivateApp = createPrivateApp;
64
+ const installApp = async (client, config, appManifestUid, mappedUid) => {
65
+ const appUid = mappedUid || appManifestUid;
66
+ return await client
67
+ .organization(config.org_uid)
68
+ .app(appUid)
69
+ .install({ targetUid: config.target_stack, targetType: 'stack' })
70
+ .catch((error) => error);
71
+ };
72
+ exports.installApp = installApp;
73
+ const handleNameConflict = async (app, appSuffix, config) => {
74
+ const appName = config.forceStopMarketplaceAppsPrompt
75
+ ? (0, interactive_2.getAppName)(app.name, appSuffix)
76
+ : await (0, interactive_2.askAppName)(app, appSuffix);
77
+ app.name = appName;
78
+ return app;
79
+ };
80
+ exports.handleNameConflict = handleNameConflict;
81
+ const makeRedirectUrlCall = async (response, appName, config) => {
82
+ if (response.redirect_url) {
83
+ (0, logger_1.log)(config, `${appName} - OAuth api call started.!`, 'info');
84
+ await new cli_utilities_1.HttpClient({ maxRedirects: 20, maxBodyLength: Infinity })
85
+ .get(response.redirect_url)
86
+ .then(async ({ response }) => {
87
+ if ((0, includes_1.default)([501, 403], response.status)) {
88
+ (0, logger_1.log)(config, `${appName} - ${response.statusText}, OAuth api call failed.!`, 'error');
89
+ (0, logger_1.log)(config, (0, utils_1.formatError)(response), 'error');
90
+ await (0, exports.confirmToCloseProcess)(response.data, config);
91
+ }
92
+ else {
93
+ (0, logger_1.log)(config, `${appName} - OAuth api call completed.!`, 'success');
94
+ }
95
+ })
96
+ .catch((error) => {
97
+ if ((0, includes_1.default)([501, 403], error.status)) {
98
+ (0, logger_1.log)(config, (0, utils_1.formatError)(error), 'error');
99
+ }
100
+ });
101
+ }
102
+ };
103
+ exports.makeRedirectUrlCall = makeRedirectUrlCall;
104
+ const confirmToCloseProcess = async (installation, config) => {
105
+ cli_utilities_1.cliux.print(`\nWARNING!!! ${(0, utils_1.formatError)(installation.message)}\n`, { color: 'yellow' });
106
+ if (!config.forceStopMarketplaceAppsPrompt) {
107
+ if (!(await cli_utilities_1.cliux.confirm(chalk_1.default.yellow('WARNING!!! The above error may have an impact if the failed app is referenced in entries/content type. Would you like to proceed? (y/n)')))) {
108
+ process.exit();
109
+ }
110
+ }
111
+ };
112
+ exports.confirmToCloseProcess = confirmToCloseProcess;
113
+ const ifAppAlreadyExist = async (app, currentStackApp, config) => {
114
+ let updateParam = {};
115
+ const { manifest: { name }, configuration, server_configuration, } = app;
116
+ if (!(0, isEmpty_1.default)(configuration) || !(0, isEmpty_1.default)(server_configuration)) {
117
+ cli_utilities_1.cliux.print(`\nWARNING!!! The ${name} app already exists and it may have its own configuration. But the current app you install has its own configuration which is used internally to manage content.\n`, { color: 'yellow' });
118
+ const configOption = config.forceStopMarketplaceAppsPrompt
119
+ ? 'Update it with the new configuration.'
120
+ : await (0, interactive_2.selectConfiguration)();
121
+ if (configOption === 'Exit') {
122
+ process.exit();
123
+ }
124
+ else if (configOption === 'Update it with the new configuration.') {
125
+ updateParam = Object.assign(Object.assign({ manifest: app.manifest }, currentStackApp), { configuration, server_configuration });
126
+ }
127
+ }
128
+ return updateParam;
129
+ };
130
+ exports.ifAppAlreadyExist = ifAppAlreadyExist;
131
+ const updateAppConfig = async (client, config, app, payload) => {
132
+ var _a;
133
+ let installation = client.organization(config.org_uid).app((_a = app === null || app === void 0 ? void 0 : app.manifest) === null || _a === void 0 ? void 0 : _a.uid).installation(app === null || app === void 0 ? void 0 : app.uid);
134
+ installation = Object.assign(installation, payload);
135
+ return await installation
136
+ .update()
137
+ .then((data) => {
138
+ var _a;
139
+ (0, logger_1.log)(config, `${(_a = app === null || app === void 0 ? void 0 : app.manifest) === null || _a === void 0 ? void 0 : _a.name} app config updated successfully.!`, 'success');
140
+ })
141
+ .catch((error) => (0, logger_1.log)(config, `Failed to update app config.${(0, utils_1.formatError)(error)}`, 'error'));
142
+ };
143
+ exports.updateAppConfig = updateAppConfig;
@@ -1,7 +1 @@
1
- {
2
- "promptMessageList": {
3
- "promptMasterLocale": "Provide the master locale of the destination stack",
4
- "promptTargetStack": "Provide the API Key of the destination stack",
5
- "promptPathStoredData": "Provide the path of the stored content"
6
- }
7
- }
1
+ {}
@@ -1,9 +1,9 @@
1
1
  {
2
- "version": "1.5.11",
2
+ "version": "1.7.0",
3
3
  "commands": {
4
4
  "cm:stacks:import": {
5
5
  "id": "cm:stacks:import",
6
- "description": "Import script for importing the content into the new stack\n...\nOnce you export content from the source stack, import it to your destination stack by using the cm:stacks:import command.\n",
6
+ "description": "Import content from a stack",
7
7
  "strict": true,
8
8
  "usage": "cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]",
9
9
  "pluginName": "@contentstack/cli-cm-import",
package/package.json CHANGED
@@ -1,42 +1,77 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.5.11",
4
+ "version": "1.7.0",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "^1.2.9",
9
- "@contentstack/cli-utilities": "^1.4.5",
8
+ "@contentstack/cli-command": "^1.2.11",
9
+ "@contentstack/cli-utilities": "^1.5.1",
10
+ "@contentstack/management": "~1.10.0",
10
11
  "@oclif/config": "^1.18.3",
12
+ "@oclif/core": "^2.9.3",
11
13
  "big-json": "^3.2.0",
12
14
  "bluebird": "^3.7.2",
13
15
  "chalk": "^4.1.2",
14
16
  "debug": "^4.1.0",
15
- "fs-extra": "^11.1.1",
16
17
  "lodash": "^4.17.20",
17
18
  "marked": "^4.0.17",
19
+ "merge": "^2.1.1",
18
20
  "mkdirp": "^1.0.4",
21
+ "ncp": "^2.0.0",
19
22
  "promise-limit": "^2.7.0",
23
+ "tslib": "^2.4.1",
20
24
  "winston": "^3.7.2"
21
25
  },
22
26
  "devDependencies": {
23
27
  "@oclif/test": "^1.2.6",
28
+ "@types/bluebird": "^3.5.38",
29
+ "@types/chai": "^4.2.18",
30
+ "@types/mkdirp": "^1.0.2",
31
+ "@types/mocha": "^8.2.2",
32
+ "@types/ncp": "^2.0.5",
33
+ "@types/node": "^14.14.32",
34
+ "@types/sinon": "^10.0.2",
35
+ "@types/tar": "^4.0.3",
36
+ "@typescript-eslint/eslint-plugin": "^5.48.2",
24
37
  "chai": "^4.2.0",
25
38
  "eslint": "^8.18.0",
26
39
  "eslint-config-oclif": "^4.0.0",
27
40
  "globby": "^10.0.2",
28
41
  "mocha": "^10.0.0",
29
42
  "nyc": "^15.1.0",
30
- "oclif": "^3.8.1"
43
+ "oclif": "^3.8.1",
44
+ "rimraf": "^2.7.1",
45
+ "sinon": "^11.1.1",
46
+ "tmp": "^0.2.1",
47
+ "ts-node": "^10.9.1",
48
+ "typescript": "^4.9.3"
49
+ },
50
+ "scripts": {
51
+ "build": "npm run clean && npm run compile",
52
+ "clean": "rm -rf ./lib ./node_modules tsconfig.build.tsbuildinfo",
53
+ "compile": "tsc -b tsconfig.json",
54
+ "postpack": "rm -f oclif.manifest.json",
55
+ "prepack": "pnpm compile && oclif manifest && oclif readme",
56
+ "version": "oclif readme && git add README.md",
57
+ "test:report": "tsc -p test && nyc --reporter=lcov --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
58
+ "pretest": "tsc -p test",
59
+ "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
60
+ "posttest": "npm run lint",
61
+ "lint": "eslint src/**/*.ts",
62
+ "format": "eslint src/**/*.ts --fix",
63
+ "test:integration": "mocha --forbid-only \"test/run.test.js\" --integration-test --timeout 60000",
64
+ "test:unit": "mocha --forbid-only \"test/unit/*.test.ts\""
31
65
  },
32
66
  "engines": {
33
67
  "node": ">=14.0.0"
34
68
  },
35
69
  "files": [
70
+ "/bin",
71
+ "/lib",
72
+ "/messages",
36
73
  "/npm-shrinkwrap.json",
37
- "/oclif.manifest.json",
38
- "/src",
39
- "/messages"
74
+ "/oclif.manifest.json"
40
75
  ],
41
76
  "homepage": "https://github.com/contentstack/cli",
42
77
  "keywords": [
@@ -44,19 +79,10 @@
44
79
  "cli",
45
80
  "plugin"
46
81
  ],
47
- "scripts": {
48
- "pack": "npm pack && mv *.tgz ../../build",
49
- "postpack": "rm -f oclif.manifest.json",
50
- "prepack": "oclif manifest && oclif readme",
51
- "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
52
- "version": "oclif readme && git add README.md",
53
- "test:integration": "mocha --forbid-only \"test/run.test.js\" --integration-test --timeout 60000",
54
- "clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo"
55
- },
56
- "main": "./src/commands/cm/stacks/import.js",
82
+ "main": "./lib/commands/cm/stacks/import.js",
57
83
  "license": "MIT",
58
84
  "oclif": {
59
- "commands": "./src/commands",
85
+ "commands": "./lib/commands",
60
86
  "bin": "csdx",
61
87
  "repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-import/<%- commandPath %>"
62
88
  },
@@ -66,7 +92,7 @@
66
92
  },
67
93
  "shortCommandName": {
68
94
  "cm:stacks:import": "IMPRT",
69
- "cm:import": "O-IMPRT"
95
+ "cm:import": "IMPRT"
70
96
  }
71
97
  },
72
98
  "repository": "https://github.com/contentstack/cli"