@contentstack/cli-cm-import 1.6.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/commands/cm/stacks/import.js +1 -1
- package/lib/config/index.js +24 -1
- package/lib/import/modules/base-class.d.ts +3 -2
- package/lib/import/modules/base-class.js +53 -0
- package/lib/import/modules/content-types.d.ts +56 -0
- package/lib/import/modules/content-types.js +186 -0
- package/lib/import/modules/custom-roles.d.ts +37 -0
- package/lib/import/modules/custom-roles.js +171 -0
- package/lib/import/modules/environments.d.ts +27 -0
- package/lib/import/modules/environments.js +106 -0
- package/lib/import/modules/extensions.d.ts +27 -0
- package/lib/import/modules/extensions.js +106 -0
- package/lib/import/modules/global-fields.d.ts +34 -0
- package/lib/import/modules/global-fields.js +99 -0
- package/lib/import/modules/labels.d.ts +34 -0
- package/lib/import/modules/labels.js +171 -0
- package/lib/import/modules/locales.js +0 -8
- package/lib/import/modules/marketplace-apps.d.ts +51 -0
- package/lib/import/modules/marketplace-apps.js +309 -0
- package/lib/import/modules/webhooks.d.ts +27 -0
- package/lib/import/modules/webhooks.js +110 -0
- package/lib/import/modules-js/custom-roles.js +2 -0
- package/lib/import/modules-js/entries.js +8 -2
- package/lib/import/modules-js/extensions.d.ts +1 -0
- package/lib/import/modules-js/marketplace-apps.js +11 -11
- package/lib/types/default-config.d.ts +13 -0
- package/lib/types/import-config.d.ts +1 -0
- package/lib/types/index.d.ts +33 -0
- package/lib/types/index.js +2 -0
- package/lib/utils/content-type-helper.d.ts +3 -1
- package/lib/utils/content-type-helper.js +3 -1
- package/lib/utils/extension-helper.d.ts +0 -5
- package/lib/utils/extension-helper.js +23 -11
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +11 -1
- package/lib/utils/interactive.d.ts +5 -0
- package/lib/utils/interactive.js +66 -1
- package/lib/utils/marketplace-app-helper.d.ts +13 -1
- package/lib/utils/marketplace-app-helper.js +127 -15
- package/oclif.manifest.json +1 -1
- package/package.json +6 -6
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* extension lookup
|
|
3
3
|
*/
|
|
4
|
-
/*!
|
|
5
|
-
* Contentstack Import
|
|
6
|
-
* Copyright (c) 2019 Contentstack LLC
|
|
7
|
-
* MIT Licensed
|
|
8
|
-
*/
|
|
9
4
|
import { ImportConfig } from '../types';
|
|
10
5
|
export declare const lookupExtension: (config: ImportConfig, schema: any, preserveStackVersion: any, installedExtensions: any) => void;
|
|
@@ -4,15 +4,18 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.lookupExtension = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
/*!
|
|
8
|
+
* Contentstack Import
|
|
9
|
+
* Copyright (c) 2019 Contentstack LLC
|
|
10
|
+
* MIT Licensed
|
|
11
|
+
*/
|
|
12
|
+
const node_path_1 = require("node:path");
|
|
13
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
11
14
|
// eslint-disable-next-line camelcase
|
|
12
15
|
const lookupExtension = function (config, schema, preserveStackVersion, installedExtensions) {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
+
const fs = new cli_utilities_1.FsUtility({ basePath: config.backupDir });
|
|
17
|
+
const extensionPath = (0, node_path_1.join)(config.backupDir, 'mapper/extensions', 'uid-mapping.json');
|
|
18
|
+
const globalfieldsPath = (0, node_path_1.join)(config.backupDir, 'mapper/globalfields', 'uid-mapping.json');
|
|
16
19
|
for (let i in schema) {
|
|
17
20
|
if (schema[i].data_type === 'group') {
|
|
18
21
|
(0, exports.lookupExtension)(config, schema[i].schema, preserveStackVersion, installedExtensions);
|
|
@@ -37,16 +40,25 @@ const lookupExtension = function (config, schema, preserveStackVersion, installe
|
|
|
37
40
|
schema[i].field_metadata.ref_multiple_content_types = true;
|
|
38
41
|
}
|
|
39
42
|
}
|
|
43
|
+
else if (schema[i].data_type === 'reference' &&
|
|
44
|
+
schema[i].field_metadata.hasOwnProperty('ref_multiple_content_types') &&
|
|
45
|
+
installedExtensions &&
|
|
46
|
+
installedExtensions[schema[i].extension_uid]) {
|
|
47
|
+
schema[i].extension_uid = installedExtensions[schema[i].extension_uid];
|
|
48
|
+
}
|
|
49
|
+
else if (schema[i].data_type === 'text' && installedExtensions && installedExtensions[schema[i].extension_uid]) {
|
|
50
|
+
schema[i].extension_uid = installedExtensions[schema[i].extension_uid];
|
|
51
|
+
}
|
|
40
52
|
else if (schema[i].data_type === 'global_field') {
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
const global_fields_key_value = schema[i].reference_to;
|
|
54
|
+
const global_fields_data = fs.readFile(globalfieldsPath);
|
|
43
55
|
if (global_fields_data && global_fields_data.hasOwnProperty(global_fields_key_value)) {
|
|
44
56
|
schema[i].reference_to = global_fields_data[global_fields_key_value];
|
|
45
57
|
}
|
|
46
58
|
}
|
|
47
59
|
else if (schema[i].hasOwnProperty('extension_uid')) {
|
|
48
60
|
const extension_key_value = schema[i].extension_uid;
|
|
49
|
-
const data =
|
|
61
|
+
const data = fs.readFile(extensionPath);
|
|
50
62
|
if (data && data.hasOwnProperty(extension_key_value)) {
|
|
51
63
|
// eslint-disable-next-line camelcase
|
|
52
64
|
schema[i].extension_uid = data[extension_key_value];
|
|
@@ -59,7 +71,7 @@ const lookupExtension = function (config, schema, preserveStackVersion, installe
|
|
|
59
71
|
}
|
|
60
72
|
else if (schema[i].data_type === 'json' && schema[i].hasOwnProperty('plugins') && schema[i].plugins.length > 0) {
|
|
61
73
|
const newPluginUidsArray = [];
|
|
62
|
-
const data =
|
|
74
|
+
const data = fs.readFile(extensionPath);
|
|
63
75
|
schema[i].plugins.forEach((extension_key_value) => {
|
|
64
76
|
if (data && data.hasOwnProperty(extension_key_value)) {
|
|
65
77
|
newPluginUidsArray.push(data[extension_key_value]);
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { fsUtil } from './file-helper';
|
|
|
5
5
|
export { default as backupHandler } from './backup-handler';
|
|
6
6
|
export { log, unlinkFileLogger } from './logger';
|
|
7
7
|
export { uploadAssetHelper, lookupAssets } from './asset-helper';
|
|
8
|
-
export { getDeveloperHubUrl } from './marketplace-app-helper';
|
|
8
|
+
export { getDeveloperHubUrl, getOrgUid, getConfirmationToCreateApps, createPrivateApp, handleNameConflict, installApp, makeRedirectUrlCall, confirmToCloseProcess, getAllStackSpecificApps, ifAppAlreadyExist, updateAppConfig } from './marketplace-app-helper';
|
|
9
9
|
export { schemaTemplate, suppressSchemaReference, removeReferenceFields } from './content-type-helper';
|
|
10
10
|
export { lookupExtension } from './extension-helper';
|
|
11
11
|
export { lookupEntries } from './entries-helper';
|
package/lib/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lookupEntries = exports.lookupExtension = exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = exports.getDeveloperHubUrl = exports.lookupAssets = exports.uploadAssetHelper = exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = void 0;
|
|
3
|
+
exports.lookupEntries = exports.lookupExtension = exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = exports.updateAppConfig = exports.ifAppAlreadyExist = exports.getAllStackSpecificApps = exports.confirmToCloseProcess = exports.makeRedirectUrlCall = exports.installApp = exports.handleNameConflict = exports.createPrivateApp = exports.getConfirmationToCreateApps = exports.getOrgUid = exports.getDeveloperHubUrl = exports.lookupAssets = exports.uploadAssetHelper = exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
exports.interactive = tslib_1.__importStar(require("./interactive"));
|
|
6
6
|
var import_config_handler_1 = require("./import-config-handler");
|
|
@@ -18,6 +18,16 @@ Object.defineProperty(exports, "uploadAssetHelper", { enumerable: true, get: fun
|
|
|
18
18
|
Object.defineProperty(exports, "lookupAssets", { enumerable: true, get: function () { return asset_helper_1.lookupAssets; } });
|
|
19
19
|
var marketplace_app_helper_1 = require("./marketplace-app-helper");
|
|
20
20
|
Object.defineProperty(exports, "getDeveloperHubUrl", { enumerable: true, get: function () { return marketplace_app_helper_1.getDeveloperHubUrl; } });
|
|
21
|
+
Object.defineProperty(exports, "getOrgUid", { enumerable: true, get: function () { return marketplace_app_helper_1.getOrgUid; } });
|
|
22
|
+
Object.defineProperty(exports, "getConfirmationToCreateApps", { enumerable: true, get: function () { return marketplace_app_helper_1.getConfirmationToCreateApps; } });
|
|
23
|
+
Object.defineProperty(exports, "createPrivateApp", { enumerable: true, get: function () { return marketplace_app_helper_1.createPrivateApp; } });
|
|
24
|
+
Object.defineProperty(exports, "handleNameConflict", { enumerable: true, get: function () { return marketplace_app_helper_1.handleNameConflict; } });
|
|
25
|
+
Object.defineProperty(exports, "installApp", { enumerable: true, get: function () { return marketplace_app_helper_1.installApp; } });
|
|
26
|
+
Object.defineProperty(exports, "makeRedirectUrlCall", { enumerable: true, get: function () { return marketplace_app_helper_1.makeRedirectUrlCall; } });
|
|
27
|
+
Object.defineProperty(exports, "confirmToCloseProcess", { enumerable: true, get: function () { return marketplace_app_helper_1.confirmToCloseProcess; } });
|
|
28
|
+
Object.defineProperty(exports, "getAllStackSpecificApps", { enumerable: true, get: function () { return marketplace_app_helper_1.getAllStackSpecificApps; } });
|
|
29
|
+
Object.defineProperty(exports, "ifAppAlreadyExist", { enumerable: true, get: function () { return marketplace_app_helper_1.ifAppAlreadyExist; } });
|
|
30
|
+
Object.defineProperty(exports, "updateAppConfig", { enumerable: true, get: function () { return marketplace_app_helper_1.updateAppConfig; } });
|
|
21
31
|
var content_type_helper_1 = require("./content-type-helper");
|
|
22
32
|
Object.defineProperty(exports, "schemaTemplate", { enumerable: true, get: function () { return content_type_helper_1.schemaTemplate; } });
|
|
23
33
|
Object.defineProperty(exports, "suppressSchemaReference", { enumerable: true, get: function () { return content_type_helper_1.suppressSchemaReference; } });
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export declare const askContentDir: () => Promise<string>;
|
|
2
2
|
export declare const askAPIKey: () => Promise<string>;
|
|
3
|
+
export declare const askDeveloperHubUrl: (regionName: string) => Promise<string>;
|
|
4
|
+
export declare const askEncryptionKey: (defaultValue: unknown) => Promise<string>;
|
|
5
|
+
export declare const askAppName: (app: any, appSuffix: number) => Promise<string>;
|
|
6
|
+
export declare const getAppName: (name: string, appSuffix?: number) => string;
|
|
7
|
+
export declare const selectConfiguration: () => Promise<string>;
|
package/lib/utils/interactive.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.askAPIKey = exports.askContentDir = void 0;
|
|
3
|
+
exports.selectConfiguration = exports.getAppName = exports.askAppName = exports.askEncryptionKey = exports.askDeveloperHubUrl = exports.askAPIKey = exports.askContentDir = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
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"));
|
|
7
9
|
const askContentDir = async () => {
|
|
8
10
|
const result = await cli_utilities_1.cliux.inquire({
|
|
9
11
|
type: 'input',
|
|
@@ -21,3 +23,66 @@ const askAPIKey = async () => {
|
|
|
21
23
|
});
|
|
22
24
|
};
|
|
23
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;
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import { HttpClient } from '@contentstack/cli-utilities';
|
|
1
|
+
import { HttpClient, ContentstackClient } from '@contentstack/cli-utilities';
|
|
2
2
|
import { ImportConfig } from '../types';
|
|
3
3
|
export declare const getAllStackSpecificApps: (developerHubBaseUrl: string, httpClient: HttpClient, config: ImportConfig) => Promise<any>;
|
|
4
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>;
|
|
@@ -1,31 +1,143 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDeveloperHubUrl = exports.getAllStackSpecificApps = void 0;
|
|
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"));
|
|
4
10
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
11
|
const logger_1 = require("./logger");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
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
|
|
9
17
|
.get(`${developerHubBaseUrl}/installations?target_uids=${config.target_stack}`)
|
|
10
18
|
.then(({ data }) => data.data)
|
|
11
|
-
.catch((error) => (0, logger_1.log)(config, `Failed to export marketplace-apps ${formatError(error)}`, 'error'));
|
|
19
|
+
.catch((error) => (0, logger_1.log)(config, `Failed to export marketplace-apps ${(0, utils_1.formatError)(error)}`, 'error'));
|
|
12
20
|
};
|
|
13
21
|
exports.getAllStackSpecificApps = getAllStackSpecificApps;
|
|
14
22
|
const getDeveloperHubUrl = async (config) => {
|
|
15
23
|
const { cma, name } = cli_utilities_1.configHandler.get('region') || {};
|
|
16
24
|
let developerHubBaseUrl = config.developerHubUrls[cma];
|
|
17
25
|
if (!developerHubBaseUrl) {
|
|
18
|
-
developerHubBaseUrl = await
|
|
19
|
-
type: 'input',
|
|
20
|
-
name: 'name',
|
|
21
|
-
validate: (url) => {
|
|
22
|
-
if (!url)
|
|
23
|
-
return "Developer-hub URL can't be empty.";
|
|
24
|
-
return true;
|
|
25
|
-
},
|
|
26
|
-
message: `Enter the developer-hub base URL for the ${name} region -`,
|
|
27
|
-
});
|
|
26
|
+
developerHubBaseUrl = await (0, interactive_1.askDeveloperHubUrl)(name);
|
|
28
27
|
}
|
|
29
28
|
return developerHubBaseUrl.startsWith('http') ? developerHubBaseUrl : `https://${developerHubBaseUrl}`;
|
|
30
29
|
};
|
|
31
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;
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.7.1",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-command": "^1.2.
|
|
9
|
-
"@contentstack/cli-utilities": "^1.5.
|
|
10
|
-
"@contentstack/management":
|
|
8
|
+
"@contentstack/cli-command": "^1.2.11",
|
|
9
|
+
"@contentstack/cli-utilities": "^1.5.1",
|
|
10
|
+
"@contentstack/management": "~1.10.0",
|
|
11
11
|
"@oclif/config": "^1.18.3",
|
|
12
|
-
"@oclif/core": "^2.3
|
|
12
|
+
"@oclif/core": "^2.9.3",
|
|
13
13
|
"big-json": "^3.2.0",
|
|
14
14
|
"bluebird": "^3.7.2",
|
|
15
15
|
"chalk": "^4.1.2",
|
|
@@ -96,4 +96,4 @@
|
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
98
|
"repository": "https://github.com/contentstack/cli"
|
|
99
|
-
}
|
|
99
|
+
}
|