@contentstack/cli-cm-import 1.8.3 → 1.9.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.
- package/README.md +1 -1
- package/bin/dev +4 -15
- package/lib/commands/cm/stacks/import.js +5 -2
- package/lib/config/index.js +2 -16
- package/lib/import/module-importer.js +2 -5
- package/lib/import/modules/assets.js +5 -2
- package/lib/import/modules/base-class.js +29 -14
- package/lib/import/modules/custom-roles.d.ts +1 -1
- package/lib/import/modules/custom-roles.js +12 -7
- package/lib/import/modules/entries.js +119 -68
- package/lib/import/modules/environments.d.ts +1 -1
- package/lib/import/modules/environments.js +3 -4
- package/lib/import/modules/extensions.js +3 -4
- package/lib/import/modules/global-fields.js +3 -2
- package/lib/import/modules/labels.d.ts +2 -2
- package/lib/import/modules/labels.js +6 -7
- package/lib/import/modules/marketplace-apps.d.ts +1 -0
- package/lib/import/modules/marketplace-apps.js +11 -5
- package/lib/import/modules/webhooks.d.ts +1 -1
- package/lib/import/modules/webhooks.js +3 -4
- package/lib/import/modules/workflows.js +11 -7
- package/lib/import/modules-js/entries.js +3 -3
- package/lib/import/modules-js/marketplace-apps.d.ts +1 -0
- package/lib/import/modules-js/marketplace-apps.js +9 -2
- package/lib/import/modules-js/workflows.js +5 -1
- package/lib/types/default-config.d.ts +0 -2
- package/lib/types/import-config.d.ts +1 -0
- package/lib/utils/asset-helper.d.ts +1 -1
- package/lib/utils/asset-helper.js +1 -2
- package/lib/utils/backup-handler.js +37 -17
- package/lib/utils/entries-helper.d.ts +6 -3
- package/lib/utils/entries-helper.js +14 -14
- package/lib/utils/import-config-handler.js +7 -0
- package/lib/utils/logger.js +1 -1
- package/lib/utils/marketplace-app-helper.js +9 -2
- package/oclif.manifest.json +1 -1
- package/package.json +6 -6
|
@@ -4,13 +4,12 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
5
5
|
const values_1 = tslib_1.__importDefault(require("lodash/values"));
|
|
6
6
|
const node_path_1 = require("node:path");
|
|
7
|
-
const config_1 = tslib_1.__importDefault(require("../../config"));
|
|
8
7
|
const utils_1 = require("../../utils");
|
|
9
8
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
10
9
|
class ImportEnvironments extends base_class_1.default {
|
|
11
10
|
constructor({ importConfig, stackAPIClient }) {
|
|
12
11
|
super({ importConfig, stackAPIClient });
|
|
13
|
-
this.environmentsConfig =
|
|
12
|
+
this.environmentsConfig = importConfig.modules.environments;
|
|
14
13
|
this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'environments');
|
|
15
14
|
this.environmentsFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.environmentsConfig.dirName);
|
|
16
15
|
this.envUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, 'uid-mapping.json');
|
|
@@ -51,7 +50,7 @@ class ImportEnvironments extends base_class_1.default {
|
|
|
51
50
|
async importEnvironments() {
|
|
52
51
|
if (this.environments === undefined || (0, isEmpty_1.default)(this.environments)) {
|
|
53
52
|
(0, utils_1.log)(this.importConfig, 'No Environment Found', 'info');
|
|
54
|
-
return
|
|
53
|
+
return;
|
|
55
54
|
}
|
|
56
55
|
const apiContent = (0, values_1.default)(this.environments);
|
|
57
56
|
const onSuccess = ({ response, apiData: { uid, name } = { uid: null, name: '' } }) => {
|
|
@@ -83,7 +82,7 @@ class ImportEnvironments extends base_class_1.default {
|
|
|
83
82
|
entity: 'create-environments',
|
|
84
83
|
includeParamOnCompletion: true,
|
|
85
84
|
},
|
|
86
|
-
concurrencyLimit:
|
|
85
|
+
concurrencyLimit: this.importConfig.fetchConcurrency || 2,
|
|
87
86
|
}, undefined, false);
|
|
88
87
|
}
|
|
89
88
|
/**
|
|
@@ -4,13 +4,12 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
5
5
|
const values_1 = tslib_1.__importDefault(require("lodash/values"));
|
|
6
6
|
const node_path_1 = require("node:path");
|
|
7
|
-
const config_1 = tslib_1.__importDefault(require("../../config"));
|
|
8
7
|
const utils_1 = require("../../utils");
|
|
9
8
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
10
9
|
class ImportExtensions extends base_class_1.default {
|
|
11
10
|
constructor({ importConfig, stackAPIClient }) {
|
|
12
11
|
super({ importConfig, stackAPIClient });
|
|
13
|
-
this.extensionsConfig =
|
|
12
|
+
this.extensionsConfig = importConfig.modules.extensions;
|
|
14
13
|
this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'extensions');
|
|
15
14
|
this.extensionsFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.extensionsConfig.dirName);
|
|
16
15
|
this.extUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, 'uid-mapping.json');
|
|
@@ -51,7 +50,7 @@ class ImportExtensions extends base_class_1.default {
|
|
|
51
50
|
async importExtensions() {
|
|
52
51
|
if (this.extensions === undefined || (0, isEmpty_1.default)(this.extensions)) {
|
|
53
52
|
(0, utils_1.log)(this.importConfig, 'No Extensions Found', 'info');
|
|
54
|
-
return
|
|
53
|
+
return;
|
|
55
54
|
}
|
|
56
55
|
const apiContent = (0, values_1.default)(this.extensions);
|
|
57
56
|
const onSuccess = ({ response, apiData: { uid, title } = { uid: null, title: '' } }) => {
|
|
@@ -83,7 +82,7 @@ class ImportExtensions extends base_class_1.default {
|
|
|
83
82
|
entity: 'create-extensions',
|
|
84
83
|
includeParamOnCompletion: true,
|
|
85
84
|
},
|
|
86
|
-
concurrencyLimit:
|
|
85
|
+
concurrencyLimit: this.importConfig.concurrency || this.importConfig.fetchConcurrency || 1,
|
|
87
86
|
}, undefined, false);
|
|
88
87
|
}
|
|
89
88
|
/**
|
|
@@ -72,8 +72,9 @@ class ImportGlobalFields extends base_class_1.default {
|
|
|
72
72
|
async createGFs({ apiParams, element: globalField, isLastRequest, }) {
|
|
73
73
|
return new Promise(async (resolve, reject) => {
|
|
74
74
|
(0, utils_1.lookupExtension)(this.config, globalField.schema, this.config.preserveStackVersion, this.installedExtensions);
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
let flag = { supressed: false };
|
|
76
|
+
await (0, utils_1.removeReferenceFields)(globalField.schema, flag, this.stackAPIClient);
|
|
77
|
+
if (flag.supressed) {
|
|
77
78
|
this.pendingGFs.push(globalField.uid);
|
|
78
79
|
}
|
|
79
80
|
return this.stack
|
|
@@ -17,7 +17,7 @@ export default class Importlabels extends BaseClass {
|
|
|
17
17
|
* @returns {Promise<void>} Promise<void>
|
|
18
18
|
*/
|
|
19
19
|
start(): Promise<void>;
|
|
20
|
-
importlabels(): Promise<
|
|
20
|
+
importlabels(): Promise<void>;
|
|
21
21
|
/**
|
|
22
22
|
* @method serializelabels
|
|
23
23
|
* @param {ApiOptions} apiOptions ApiOptions
|
|
@@ -30,5 +30,5 @@ export default class Importlabels extends BaseClass {
|
|
|
30
30
|
* @param {ApiOptions} apiOptions ApiOptions
|
|
31
31
|
* @returns {ApiOptions} ApiOptions
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
serializeUpdateLabels(apiOptions: ApiOptions): ApiOptions;
|
|
34
34
|
}
|
|
@@ -5,13 +5,12 @@ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
|
5
5
|
const values_1 = tslib_1.__importDefault(require("lodash/values"));
|
|
6
6
|
const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
|
-
const config_1 = tslib_1.__importDefault(require("../../config"));
|
|
9
8
|
const utils_1 = require("../../utils");
|
|
10
9
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
11
10
|
class Importlabels extends base_class_1.default {
|
|
12
11
|
constructor({ importConfig, stackAPIClient }) {
|
|
13
12
|
super({ importConfig, stackAPIClient });
|
|
14
|
-
this.labelsConfig =
|
|
13
|
+
this.labelsConfig = importConfig.modules.labels;
|
|
15
14
|
this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'labels');
|
|
16
15
|
this.labelsFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.labelsConfig.dirName);
|
|
17
16
|
this.labelUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, 'uid-mapping.json');
|
|
@@ -56,7 +55,7 @@ class Importlabels extends base_class_1.default {
|
|
|
56
55
|
async importlabels() {
|
|
57
56
|
if (this.labels === undefined || (0, isEmpty_1.default)(this.labels)) {
|
|
58
57
|
(0, utils_1.log)(this.importConfig, 'No Label Found', 'info');
|
|
59
|
-
return
|
|
58
|
+
return;
|
|
60
59
|
}
|
|
61
60
|
const apiContent = (0, values_1.default)(this.labels);
|
|
62
61
|
const onSuccess = ({ response, apiData: { uid, name } = { uid: null, name: '' } }) => {
|
|
@@ -86,7 +85,7 @@ class Importlabels extends base_class_1.default {
|
|
|
86
85
|
entity: 'create-labels',
|
|
87
86
|
includeParamOnCompletion: true,
|
|
88
87
|
},
|
|
89
|
-
concurrencyLimit:
|
|
88
|
+
concurrencyLimit: this.importConfig.fetchConcurrency || 1,
|
|
90
89
|
}, undefined, false);
|
|
91
90
|
}
|
|
92
91
|
/**
|
|
@@ -124,13 +123,13 @@ class Importlabels extends base_class_1.default {
|
|
|
124
123
|
apiContent,
|
|
125
124
|
processName: 'update labels',
|
|
126
125
|
apiParams: {
|
|
127
|
-
serializeData: this.
|
|
126
|
+
serializeData: this.serializeUpdateLabels.bind(this),
|
|
128
127
|
reject: onReject.bind(this),
|
|
129
128
|
resolve: onSuccess.bind(this),
|
|
130
129
|
entity: 'update-labels',
|
|
131
130
|
includeParamOnCompletion: true,
|
|
132
131
|
},
|
|
133
|
-
concurrencyLimit:
|
|
132
|
+
concurrencyLimit: this.importConfig.fetchConcurrency || 1,
|
|
134
133
|
}, undefined, false);
|
|
135
134
|
}
|
|
136
135
|
}
|
|
@@ -139,7 +138,7 @@ class Importlabels extends base_class_1.default {
|
|
|
139
138
|
* @param {ApiOptions} apiOptions ApiOptions
|
|
140
139
|
* @returns {ApiOptions} ApiOptions
|
|
141
140
|
*/
|
|
142
|
-
|
|
141
|
+
serializeUpdateLabels(apiOptions) {
|
|
143
142
|
var _a, _b;
|
|
144
143
|
const { apiData: label } = apiOptions;
|
|
145
144
|
const labelUid = label.uid;
|
|
@@ -16,6 +16,7 @@ export default class ImportMarketplaceApps extends BaseClass {
|
|
|
16
16
|
developerHubBaseUrl: string;
|
|
17
17
|
sdkClient: ContentstackClient;
|
|
18
18
|
nodeCrypto: NodeCrypto;
|
|
19
|
+
appSdkAxiosInstance: any;
|
|
19
20
|
constructor({ importConfig, stackAPIClient }: ModuleClassParams);
|
|
20
21
|
/**
|
|
21
22
|
* @method start
|
|
@@ -13,14 +13,13 @@ const filter_1 = tslib_1.__importDefault(require("lodash/filter"));
|
|
|
13
13
|
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
14
14
|
const toLower_1 = tslib_1.__importDefault(require("lodash/toLower"));
|
|
15
15
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
16
|
-
const config_1 = tslib_1.__importDefault(require("../../config"));
|
|
17
16
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
18
17
|
const interactive_1 = require("../../utils/interactive");
|
|
19
18
|
const utils_1 = require("../../utils");
|
|
20
19
|
class ImportMarketplaceApps extends base_class_1.default {
|
|
21
20
|
constructor({ importConfig, stackAPIClient }) {
|
|
22
21
|
super({ importConfig, stackAPIClient });
|
|
23
|
-
this.marketPlaceAppConfig =
|
|
22
|
+
this.marketPlaceAppConfig = importConfig.modules.marketplace_apps;
|
|
24
23
|
this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'marketplace_apps');
|
|
25
24
|
this.marketPlaceFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.marketPlaceAppConfig.dirName);
|
|
26
25
|
this.marketPlaceUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, 'uid-mapping.json');
|
|
@@ -54,6 +53,9 @@ class ImportMarketplaceApps extends base_class_1.default {
|
|
|
54
53
|
await utils_1.fsUtil.makeDirectory(this.mapperDirPath);
|
|
55
54
|
this.developerHubBaseUrl = this.importConfig.developerHubBaseUrl || (await (0, utils_1.getDeveloperHubUrl)(this.importConfig));
|
|
56
55
|
this.sdkClient = await (0, cli_utilities_1.managementSDKClient)({ endpoint: this.developerHubBaseUrl });
|
|
56
|
+
this.appSdkAxiosInstance = await (0, cli_utilities_1.managementSDKClient)({
|
|
57
|
+
host: this.developerHubBaseUrl.split('://').pop()
|
|
58
|
+
});
|
|
57
59
|
this.importConfig.org_uid = await (0, utils_1.getOrgUid)(this.importConfig);
|
|
58
60
|
await this.setHttpClient();
|
|
59
61
|
await this.startInstallation();
|
|
@@ -298,10 +300,14 @@ class ImportMarketplaceApps extends base_class_1.default {
|
|
|
298
300
|
}
|
|
299
301
|
// TODO migrate this HTTP API call into SDK
|
|
300
302
|
// NOTE Use updateAppConfig(this.sdkClient, this.importConfig, app, payload) utility when migrating to SDK call;
|
|
301
|
-
return this.
|
|
302
|
-
.put(`${this.developerHubBaseUrl}/installations/${uid}`, payload
|
|
303
|
+
return this.appSdkAxiosInstance.axiosInstance
|
|
304
|
+
.put(`${this.developerHubBaseUrl}/installations/${uid}`, payload, {
|
|
305
|
+
headers: {
|
|
306
|
+
organization_uid: this.importConfig.org_uid,
|
|
307
|
+
},
|
|
308
|
+
})
|
|
303
309
|
.then(({ data }) => {
|
|
304
|
-
if (data.message) {
|
|
310
|
+
if (data === null || data === void 0 ? void 0 : data.message) {
|
|
305
311
|
(0, utils_1.log)(this.importConfig, (0, utils_1.formatError)(data.message), 'success');
|
|
306
312
|
}
|
|
307
313
|
else {
|
|
@@ -17,7 +17,7 @@ export default class ImportWebhooks extends BaseClass {
|
|
|
17
17
|
* @returns {Promise<void>} Promise<void>
|
|
18
18
|
*/
|
|
19
19
|
start(): Promise<void>;
|
|
20
|
-
importWebhooks(): Promise<
|
|
20
|
+
importWebhooks(): Promise<void>;
|
|
21
21
|
/**
|
|
22
22
|
* @method serializeWebhooks
|
|
23
23
|
* @param {ApiOptions} apiOptions ApiOptions
|
|
@@ -4,13 +4,12 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
5
5
|
const values_1 = tslib_1.__importDefault(require("lodash/values"));
|
|
6
6
|
const node_path_1 = require("node:path");
|
|
7
|
-
const config_1 = tslib_1.__importDefault(require("../../config"));
|
|
8
7
|
const utils_1 = require("../../utils");
|
|
9
8
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
10
9
|
class ImportWebhooks extends base_class_1.default {
|
|
11
10
|
constructor({ importConfig, stackAPIClient }) {
|
|
12
11
|
super({ importConfig, stackAPIClient });
|
|
13
|
-
this.webhooksConfig =
|
|
12
|
+
this.webhooksConfig = importConfig.modules.webhooks;
|
|
14
13
|
this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'webhooks');
|
|
15
14
|
this.webhooksFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.webhooksConfig.dirName);
|
|
16
15
|
this.webhookUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, 'uid-mapping.json');
|
|
@@ -53,7 +52,7 @@ class ImportWebhooks extends base_class_1.default {
|
|
|
53
52
|
async importWebhooks() {
|
|
54
53
|
if (this.webhooks === undefined || (0, isEmpty_1.default)(this.webhooks)) {
|
|
55
54
|
(0, utils_1.log)(this.importConfig, 'No Webhook Found', 'info');
|
|
56
|
-
return
|
|
55
|
+
return;
|
|
57
56
|
}
|
|
58
57
|
const apiContent = (0, values_1.default)(this.webhooks);
|
|
59
58
|
const onSuccess = ({ response, apiData: { uid, name } = { uid: null, name: '' } }) => {
|
|
@@ -84,7 +83,7 @@ class ImportWebhooks extends base_class_1.default {
|
|
|
84
83
|
entity: 'create-webhooks',
|
|
85
84
|
includeParamOnCompletion: true,
|
|
86
85
|
},
|
|
87
|
-
concurrencyLimit:
|
|
86
|
+
concurrencyLimit: this.importConfig.fetchConcurrency || 1,
|
|
88
87
|
}, undefined, false);
|
|
89
88
|
}
|
|
90
89
|
/**
|
|
@@ -10,13 +10,12 @@ const filter_1 = tslib_1.__importDefault(require("lodash/filter"));
|
|
|
10
10
|
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
11
11
|
const cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
|
|
12
12
|
const findIndex_1 = tslib_1.__importDefault(require("lodash/findIndex"));
|
|
13
|
-
const config_1 = tslib_1.__importDefault(require("../../config"));
|
|
14
13
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
15
14
|
const utils_1 = require("../../utils");
|
|
16
15
|
class ImportWorkflows extends base_class_1.default {
|
|
17
16
|
constructor({ importConfig, stackAPIClient }) {
|
|
18
17
|
super({ importConfig, stackAPIClient });
|
|
19
|
-
this.workflowsConfig =
|
|
18
|
+
this.workflowsConfig = importConfig.modules.workflows;
|
|
20
19
|
this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'workflows');
|
|
21
20
|
this.workflowsFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.workflowsConfig.dirName);
|
|
22
21
|
this.workflowUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, 'uid-mapping.json');
|
|
@@ -99,10 +98,11 @@ class ImportWorkflows extends base_class_1.default {
|
|
|
99
98
|
utils_1.fsUtil.writeFile(this.workflowUidMapperPath, this.workflowUidMapper);
|
|
100
99
|
};
|
|
101
100
|
const onReject = ({ error, apiData }) => {
|
|
102
|
-
var _a;
|
|
101
|
+
var _a, _b;
|
|
103
102
|
const err = (error === null || error === void 0 ? void 0 : error.message) ? JSON.parse(error.message) : error;
|
|
104
103
|
const { name } = apiData;
|
|
105
|
-
|
|
104
|
+
const workflowExists = ((_a = err === null || err === void 0 ? void 0 : err.errors) === null || _a === void 0 ? void 0 : _a.name) || ((_b = err === null || err === void 0 ? void 0 : err.errors) === null || _b === void 0 ? void 0 : _b['workflow.name']);
|
|
105
|
+
if (workflowExists) {
|
|
106
106
|
(0, utils_1.log)(this.importConfig, `Workflow '${name}' already exists`, 'info');
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
@@ -125,7 +125,7 @@ class ImportWorkflows extends base_class_1.default {
|
|
|
125
125
|
entity: 'create-workflows',
|
|
126
126
|
includeParamOnCompletion: true,
|
|
127
127
|
},
|
|
128
|
-
concurrencyLimit:
|
|
128
|
+
concurrencyLimit: this.importConfig.fetchConcurrency || 1,
|
|
129
129
|
}, undefined, false);
|
|
130
130
|
}
|
|
131
131
|
updateNextAvailableStagesUid(workflow, newWorkflowStages, oldWorkflowStages) {
|
|
@@ -143,7 +143,11 @@ class ImportWorkflows extends base_class_1.default {
|
|
|
143
143
|
return newStage;
|
|
144
144
|
});
|
|
145
145
|
const updateWorkflow = this.stack.workflow(workflow.uid);
|
|
146
|
-
Object.assign(updateWorkflow, {
|
|
146
|
+
Object.assign(updateWorkflow, {
|
|
147
|
+
name: workflow.name,
|
|
148
|
+
branches: workflow.branches,
|
|
149
|
+
workflow_stages: newWorkflowStages,
|
|
150
|
+
});
|
|
147
151
|
return updateWorkflow.update();
|
|
148
152
|
}
|
|
149
153
|
/**
|
|
@@ -205,7 +209,7 @@ class ImportWorkflows extends base_class_1.default {
|
|
|
205
209
|
includeParamOnCompletion: true,
|
|
206
210
|
additionalInfo: { workflowUid: workflow.uid, stageIndex },
|
|
207
211
|
},
|
|
208
|
-
concurrencyLimit:
|
|
212
|
+
concurrencyLimit: this.importConfig.fetchConcurrency || 1,
|
|
209
213
|
}, undefined, false);
|
|
210
214
|
}
|
|
211
215
|
stageIndex++;
|
|
@@ -14,7 +14,7 @@ const { default: config } = require('../../config');
|
|
|
14
14
|
const addlogs = log;
|
|
15
15
|
module.exports = class ImportEntries {
|
|
16
16
|
constructor(importConfig, stackAPIClient) {
|
|
17
|
-
this.skipFiles = ['__master.json', '__priority.json', 'schema.json'];
|
|
17
|
+
this.skipFiles = ['__master.json', '__priority.json', 'schema.json', '.DS_Store'];
|
|
18
18
|
this.config = _.merge(config, importConfig);
|
|
19
19
|
this.stackAPIClient = stackAPIClient;
|
|
20
20
|
this.mappedAssetUidPath = path.resolve(this.config.data, 'mapper', 'assets', 'uid-mapping.json');
|
|
@@ -1029,7 +1029,7 @@ module.exports = class ImportEntries {
|
|
|
1029
1029
|
// only checking one level deep, not recursive
|
|
1030
1030
|
if (element.length) {
|
|
1031
1031
|
for (const item of element) {
|
|
1032
|
-
if ((item.type === 'p' || item.type === 'a') && item.children && item.children.length > 0) {
|
|
1032
|
+
if ((item.type === 'p' || item.type === 'a' || item.type === 'span') && item.children && item.children.length > 0) {
|
|
1033
1033
|
return this.doEntryReferencesExist(item.children);
|
|
1034
1034
|
}
|
|
1035
1035
|
else if (this.isEntryRef(item)) {
|
|
@@ -1041,7 +1041,7 @@ module.exports = class ImportEntries {
|
|
|
1041
1041
|
if (this.isEntryRef(element)) {
|
|
1042
1042
|
return true;
|
|
1043
1043
|
}
|
|
1044
|
-
if ((element.type === 'p' || element.type === 'a') && element.children && element.children.length > 0) {
|
|
1044
|
+
if ((element.type === 'p' || element.type === 'a' || element.type === 'span') && element.children && element.children.length > 0) {
|
|
1045
1045
|
return this.doEntryReferencesExist(element.children);
|
|
1046
1046
|
}
|
|
1047
1047
|
}
|
|
@@ -19,6 +19,7 @@ declare class ImportMarketplaceApps {
|
|
|
19
19
|
start(): Promise<void>;
|
|
20
20
|
mapperDirPath: string;
|
|
21
21
|
uidMapperPath: string;
|
|
22
|
+
appSdkAxiosInstance: any;
|
|
22
23
|
getOrgUid(): Promise<void>;
|
|
23
24
|
getAndValidateEncryptionKey(defaultValue: any, retry?: number): any;
|
|
24
25
|
nodeCrypto: NodeCrypto;
|
|
@@ -38,6 +38,9 @@ module.exports = class ImportMarketplaceApps {
|
|
|
38
38
|
}
|
|
39
39
|
this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl(this.config));
|
|
40
40
|
this.client = await managementSDKClient({ endpoint: this.developerHubBaseUrl });
|
|
41
|
+
this.appSdkAxiosInstance = await managementSDKClient({
|
|
42
|
+
host: this.developerHubBaseUrl.split('://').pop()
|
|
43
|
+
});
|
|
41
44
|
await this.getOrgUid();
|
|
42
45
|
const httpClient = new HttpClient();
|
|
43
46
|
if (!this.config.auth_token) {
|
|
@@ -392,8 +395,12 @@ module.exports = class ImportMarketplaceApps {
|
|
|
392
395
|
if (_.isEmpty(app) || _.isEmpty(payload) || !uid) {
|
|
393
396
|
return Promise.resolve();
|
|
394
397
|
}
|
|
395
|
-
return this.
|
|
396
|
-
.put(`${this.developerHubBaseUrl}/installations/${uid}`, payload
|
|
398
|
+
return this.appSdkAxiosInstance.axiosInstance
|
|
399
|
+
.put(`${this.developerHubBaseUrl}/installations/${uid}`, payload, {
|
|
400
|
+
headers: {
|
|
401
|
+
organization_uid: this.config.org_uid
|
|
402
|
+
},
|
|
403
|
+
})
|
|
397
404
|
.then(({ data }) => {
|
|
398
405
|
if (data.message) {
|
|
399
406
|
log(this.config, formatError(data.message), 'success');
|
|
@@ -159,7 +159,11 @@ module.exports = class importWorkflows {
|
|
|
159
159
|
return newStage;
|
|
160
160
|
});
|
|
161
161
|
const updateWorkflow = this.stackAPIClient.workflow(workflow.uid);
|
|
162
|
-
Object.assign(updateWorkflow, {
|
|
162
|
+
Object.assign(updateWorkflow, {
|
|
163
|
+
name: workflow.name,
|
|
164
|
+
branches: workflow.branches,
|
|
165
|
+
workflow_stages: newWorkflowStages,
|
|
166
|
+
});
|
|
163
167
|
return updateWorkflow.update();
|
|
164
168
|
}
|
|
165
169
|
};
|
|
@@ -128,7 +128,6 @@ export default interface DefaultConfig {
|
|
|
128
128
|
stacks: string;
|
|
129
129
|
labels: string;
|
|
130
130
|
};
|
|
131
|
-
updatedModules: string[];
|
|
132
131
|
rateLimit: number;
|
|
133
132
|
preserveStackVersion: boolean;
|
|
134
133
|
entriesPublish: boolean;
|
|
@@ -139,6 +138,5 @@ export default interface DefaultConfig {
|
|
|
139
138
|
developerHubBaseUrl: string;
|
|
140
139
|
marketplaceAppEncryptionKey: string;
|
|
141
140
|
getEncryptionKeyMaxRetry: number;
|
|
142
|
-
useNewModuleStructure: boolean;
|
|
143
141
|
createBackupDir?: string;
|
|
144
142
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import Bluebird from 'bluebird';
|
|
2
|
-
import { ImportConfig } from '
|
|
2
|
+
import { ImportConfig } from '../types';
|
|
3
3
|
export declare const uploadAssetHelper: (config: ImportConfig, req: any, fsPath: string, RETRY?: number) => Bluebird<unknown>;
|
|
4
4
|
export declare const lookupAssets: (data: Record<string, any>, mappedAssetUids: Record<string, any>, mappedAssetUrls: Record<string, any>, assetUidMapperPath: string, installedExtensions: Record<string, any>[]) => any;
|
|
@@ -191,8 +191,7 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
|
|
|
191
191
|
jsonRteData.children.forEach((element) => {
|
|
192
192
|
if (element.type) {
|
|
193
193
|
switch (element.type) {
|
|
194
|
-
|
|
195
|
-
case 'p': {
|
|
194
|
+
default: {
|
|
196
195
|
if (element.children && element.children.length > 0) {
|
|
197
196
|
gatherJsonRteAssetIds(element);
|
|
198
197
|
}
|
|
@@ -2,33 +2,38 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const path = tslib_1.__importStar(require("path"));
|
|
5
|
-
const
|
|
5
|
+
const fs_extra_1 = require("fs-extra");
|
|
6
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
7
|
const index_1 = require("./index");
|
|
7
8
|
function setupBackupDir(importConfig) {
|
|
8
9
|
return new Promise(async (resolve, reject) => {
|
|
9
10
|
if (importConfig.hasOwnProperty('useBackedupDir')) {
|
|
10
11
|
return resolve(importConfig.useBackedupDir);
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
let backupDirPath
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const subDir = isSubDirectory(importConfig);
|
|
14
|
+
let backupDirPath;
|
|
15
|
+
if (subDir) {
|
|
16
|
+
backupDirPath = path.resolve(importConfig.contentDir, '..', '_backup_' + Math.floor(Math.random() * 1000));
|
|
17
|
+
if (importConfig.createBackupDir) {
|
|
18
|
+
cli_utilities_1.cliux.print(`Warning!!! Provided backup directory path is a sub directory of the content directory, Cannot copy to a sub directory. Hence new backup directory created - ${backupDirPath}`, {
|
|
19
|
+
color: 'yellow',
|
|
20
|
+
});
|
|
17
21
|
}
|
|
18
|
-
index_1.fileHelper.makeDirectory(importConfig.createBackupDir);
|
|
19
|
-
backupDirPath = importConfig.createBackupDir;
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
else {
|
|
24
|
+
//NOTE: If the backup folder's directory is provided, create it at that location; otherwise, the default path (working directory).
|
|
25
|
+
backupDirPath = path.join(process.cwd(), '_backup_' + Math.floor(Math.random() * 1000));
|
|
26
|
+
if (importConfig.createBackupDir) {
|
|
27
|
+
if (index_1.fileHelper.fileExistsSync(importConfig.createBackupDir)) {
|
|
28
|
+
index_1.fileHelper.removeDirSync(importConfig.createBackupDir);
|
|
26
29
|
}
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
index_1.fileHelper.makeDirectory(importConfig.createBackupDir);
|
|
31
|
+
backupDirPath = importConfig.createBackupDir;
|
|
32
|
+
}
|
|
29
33
|
}
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
if (backupDirPath) {
|
|
35
|
+
cli_utilities_1.cliux.print('Copying content to the backup directory...');
|
|
36
|
+
return (0, fs_extra_1.copy)(importConfig.contentDir, backupDirPath, (error) => {
|
|
32
37
|
if (error) {
|
|
33
38
|
return reject(error);
|
|
34
39
|
}
|
|
@@ -38,3 +43,18 @@ function setupBackupDir(importConfig) {
|
|
|
38
43
|
});
|
|
39
44
|
}
|
|
40
45
|
exports.default = setupBackupDir;
|
|
46
|
+
/**
|
|
47
|
+
* Check whether provided backup directory path is sub directory or not
|
|
48
|
+
* @param importConfig
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
function isSubDirectory(importConfig) {
|
|
52
|
+
const parent = importConfig.contentDir;
|
|
53
|
+
const child = importConfig.createBackupDir ? importConfig.createBackupDir : process.cwd();
|
|
54
|
+
const relative = path.relative(parent, child);
|
|
55
|
+
if (relative) {
|
|
56
|
+
return relative && !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
57
|
+
}
|
|
58
|
+
//true if both parent and child have same path
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Entries lookup
|
|
3
3
|
*/
|
|
4
|
-
export declare const lookupEntries: (data:
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export declare const lookupEntries: (data: {
|
|
5
|
+
content_type: any;
|
|
6
|
+
entry: any;
|
|
7
|
+
}, mappedUids: Record<string, any>, uidMapperPath: string) => any;
|
|
8
|
+
export declare const removeUidsFromJsonRteFields: (entry: Record<string, any>, ctSchema?: Record<string, any>[]) => Record<string, any>;
|
|
9
|
+
export declare const removeEntryRefsFromJSONRTE: (entry: Record<string, any>, ctSchema?: Record<string, any>[]) => Record<string, any>;
|
|
7
10
|
export declare const restoreJsonRteEntryRefs: (entry: Record<string, any>, sourceStackEntry: any, ctSchema: any, { mappedAssetUids, mappedAssetUrls }: any) => Record<string, any>;
|
|
@@ -21,8 +21,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
21
21
|
jsonRteData.children.forEach((element) => {
|
|
22
22
|
if (element.type) {
|
|
23
23
|
switch (element.type) {
|
|
24
|
-
|
|
25
|
-
case 'p': {
|
|
24
|
+
default: {
|
|
26
25
|
if (element.children && element.children.length > 0) {
|
|
27
26
|
gatherJsonRteEntryIds(element);
|
|
28
27
|
}
|
|
@@ -95,7 +94,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
95
94
|
}
|
|
96
95
|
};
|
|
97
96
|
const find = function (schema = [], _entry) {
|
|
98
|
-
for (let i = 0, _i = schema.length; i < _i; i++) {
|
|
97
|
+
for (let i = 0, _i = schema === null || schema === void 0 ? void 0 : schema.length; i < _i; i++) {
|
|
99
98
|
switch (schema[i].data_type) {
|
|
100
99
|
case 'reference':
|
|
101
100
|
if (Array.isArray(schema[i].reference_to)) {
|
|
@@ -135,7 +134,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
135
134
|
}
|
|
136
135
|
}
|
|
137
136
|
};
|
|
138
|
-
function findEntryIdsFromJsonRte(entry, ctSchema) {
|
|
137
|
+
function findEntryIdsFromJsonRte(entry, ctSchema = []) {
|
|
139
138
|
for (const element of ctSchema) {
|
|
140
139
|
switch (element.data_type) {
|
|
141
140
|
case 'blocks': {
|
|
@@ -250,7 +249,7 @@ function findUidsInNewRefFields(entry, uids) {
|
|
|
250
249
|
}
|
|
251
250
|
}
|
|
252
251
|
}
|
|
253
|
-
const removeUidsFromJsonRteFields = (entry, ctSchema) => {
|
|
252
|
+
const removeUidsFromJsonRteFields = (entry, ctSchema = []) => {
|
|
254
253
|
for (const element of ctSchema) {
|
|
255
254
|
switch (element.data_type) {
|
|
256
255
|
case 'blocks': {
|
|
@@ -340,7 +339,7 @@ function removeUidsFromChildren(children) {
|
|
|
340
339
|
return children;
|
|
341
340
|
}
|
|
342
341
|
}
|
|
343
|
-
const removeEntryRefsFromJSONRTE = (entry, ctSchema) => {
|
|
342
|
+
const removeEntryRefsFromJSONRTE = (entry, ctSchema = []) => {
|
|
344
343
|
for (const element of ctSchema) {
|
|
345
344
|
switch (element.data_type) {
|
|
346
345
|
case 'blocks': {
|
|
@@ -380,7 +379,8 @@ const removeEntryRefsFromJSONRTE = (entry, ctSchema) => {
|
|
|
380
379
|
let entryReferences = jsonRteData.children.filter((e) => doEntryReferencesExist(e));
|
|
381
380
|
if (entryReferences.length > 0) {
|
|
382
381
|
jsonRteData.children = jsonRteData.children.filter((e) => !doEntryReferencesExist(e));
|
|
383
|
-
if (jsonRteData.children.length === 0) {
|
|
382
|
+
if (jsonRteData.children.length === 0) {
|
|
383
|
+
// empty children array are no longer acceptable by the API, a default structure must be there
|
|
384
384
|
jsonRteData.children.push(JSON.parse(structuredPTag));
|
|
385
385
|
}
|
|
386
386
|
return jsonRteData; // return jsonRteData without entry references
|
|
@@ -412,7 +412,7 @@ function doEntryReferencesExist(element) {
|
|
|
412
412
|
// only checking one level deep, not recursive
|
|
413
413
|
if (element.length) {
|
|
414
414
|
for (const item of element) {
|
|
415
|
-
if ((item.type === 'p' || item.type === 'a') && item.children && item.children.length > 0) {
|
|
415
|
+
if ((item.type === 'p' || item.type === 'a' || item.type === 'span') && item.children && item.children.length > 0) {
|
|
416
416
|
return doEntryReferencesExist(item.children);
|
|
417
417
|
}
|
|
418
418
|
else if (isEntryRef(item)) {
|
|
@@ -424,7 +424,7 @@ function doEntryReferencesExist(element) {
|
|
|
424
424
|
if (isEntryRef(element)) {
|
|
425
425
|
return true;
|
|
426
426
|
}
|
|
427
|
-
if ((element.type === 'p' || element.type === 'a') && element.children && element.children.length > 0) {
|
|
427
|
+
if ((element.type === 'p' || element.type === 'a' || element.type === 'span') && element.children && element.children.length > 0) {
|
|
428
428
|
return doEntryReferencesExist(element.children);
|
|
429
429
|
}
|
|
430
430
|
}
|
|
@@ -433,14 +433,14 @@ function doEntryReferencesExist(element) {
|
|
|
433
433
|
function isEntryRef(element) {
|
|
434
434
|
return element.type === 'reference' && element.attrs.type === 'entry';
|
|
435
435
|
}
|
|
436
|
-
const restoreJsonRteEntryRefs = (entry, sourceStackEntry, ctSchema, { mappedAssetUids, mappedAssetUrls }) => {
|
|
436
|
+
const restoreJsonRteEntryRefs = (entry, sourceStackEntry, ctSchema = [], { mappedAssetUids, mappedAssetUrls }) => {
|
|
437
437
|
// let mappedAssetUids = fileHelper.readFileSync(this.mappedAssetUidPath) || {};
|
|
438
438
|
// let mappedAssetUrls = fileHelper.readFileSync(this.mappedAssetUrlPath) || {};
|
|
439
439
|
for (const element of ctSchema) {
|
|
440
440
|
switch (element.data_type) {
|
|
441
441
|
case 'blocks': {
|
|
442
442
|
if (entry[element.uid]) {
|
|
443
|
-
if (element.multiple) {
|
|
443
|
+
if (element.multiple && Array.isArray(entry[element.uid])) {
|
|
444
444
|
entry[element.uid] = entry[element.uid].map((e, eIndex) => {
|
|
445
445
|
let key = Object.keys(e).pop();
|
|
446
446
|
let subBlock = element.blocks.filter((block) => block.uid === key).pop();
|
|
@@ -458,7 +458,7 @@ const restoreJsonRteEntryRefs = (entry, sourceStackEntry, ctSchema, { mappedAsse
|
|
|
458
458
|
case 'global_field':
|
|
459
459
|
case 'group': {
|
|
460
460
|
if (entry[element.uid]) {
|
|
461
|
-
if (element.multiple) {
|
|
461
|
+
if (element.multiple && Array.isArray(entry[element.uid])) {
|
|
462
462
|
entry[element.uid] = entry[element.uid].map((e, eIndex) => {
|
|
463
463
|
let sourceStackElement = sourceStackEntry[element.uid][eIndex];
|
|
464
464
|
e = (0, exports.restoreJsonRteEntryRefs)(e, sourceStackElement, element.schema, { mappedAssetUids, mappedAssetUrls });
|
|
@@ -477,7 +477,7 @@ const restoreJsonRteEntryRefs = (entry, sourceStackEntry, ctSchema, { mappedAsse
|
|
|
477
477
|
}
|
|
478
478
|
case 'json': {
|
|
479
479
|
if (entry[element.uid] && element.field_metadata.rich_text_type) {
|
|
480
|
-
if (element.multiple) {
|
|
480
|
+
if (element.multiple && Array.isArray(entry[element.uid])) {
|
|
481
481
|
entry[element.uid] = entry[element.uid].map((field, index) => {
|
|
482
482
|
// i am facing a Maximum call stack exceeded issue,
|
|
483
483
|
// probably because of this loop operation
|
|
@@ -544,7 +544,7 @@ function setDirtyTrue(jsonRteChild) {
|
|
|
544
544
|
}
|
|
545
545
|
delete jsonRteChild.uid;
|
|
546
546
|
if (jsonRteChild.children && jsonRteChild.children.length > 0) {
|
|
547
|
-
jsonRteChild.children = jsonRteChild.children.map((subElement) =>
|
|
547
|
+
jsonRteChild.children = jsonRteChild.children.map((subElement) => setDirtyTrue(subElement));
|
|
548
548
|
}
|
|
549
549
|
}
|
|
550
550
|
return jsonRteChild;
|