@contentstack/cli-cm-import 1.2.4 → 1.4.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/LICENSE +1 -1
- package/README.md +84 -24
- package/oclif.manifest.json +129 -1
- package/package.json +11 -11
- package/src/app.js +48 -60
- package/src/commands/cm/stacks/import.js +3 -4
- package/src/config/default.js +6 -1
- package/src/lib/import/assets.js +261 -247
- package/src/lib/import/content-types.js +19 -21
- package/src/lib/import/custom-roles.js +7 -17
- package/src/lib/import/entries.js +344 -360
- package/src/lib/import/environments.js +5 -7
- package/src/lib/import/extensions.js +6 -9
- package/src/lib/import/global-fields.js +7 -17
- package/src/lib/import/labels.js +5 -8
- package/src/lib/import/locales.js +76 -13
- package/src/lib/import/marketplace-apps.js +387 -412
- package/src/lib/import/webhooks.js +4 -6
- package/src/lib/import/workflows.js +6 -15
- package/src/lib/util/extensionsUidReplace.js +2 -33
- package/src/lib/util/fs.js +4 -0
- package/src/lib/util/index.js +71 -72
- package/src/lib/util/login.js +45 -42
- package/src/lib/util/lookupReplaceAssets.js +9 -98
- package/src/lib/util/marketplace-app-helper.js +10 -37
- package/src/lib/util/upload.js +30 -23
- package/src/lib/util/contentstack-management-sdk.js +0 -41
|
@@ -15,7 +15,6 @@ const helper = require('../util/fs');
|
|
|
15
15
|
const { formatError } = require('../util');
|
|
16
16
|
const { addlogs } = require('../util/log');
|
|
17
17
|
const config = require('../../config/default');
|
|
18
|
-
const stack = require('../util/contentstack-management-sdk');
|
|
19
18
|
|
|
20
19
|
module.exports = class ImportWebhooks {
|
|
21
20
|
config;
|
|
@@ -25,15 +24,15 @@ module.exports = class ImportWebhooks {
|
|
|
25
24
|
webhooksConfig = config.modules.webhooks;
|
|
26
25
|
reqConcurrency = config.concurrency || config.fetchConcurrency;
|
|
27
26
|
|
|
28
|
-
constructor(
|
|
29
|
-
this.config = merge(config,
|
|
27
|
+
constructor(importConfig, stackAPIClient) {
|
|
28
|
+
this.config = merge(config, importConfig);
|
|
29
|
+
this.stackAPIClient = stackAPIClient;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
start() {
|
|
33
33
|
addlogs(this.config, chalk.white('Migrating webhooks'), 'success');
|
|
34
34
|
|
|
35
35
|
const self = this;
|
|
36
|
-
const client = stack.Client(this.config);
|
|
37
36
|
|
|
38
37
|
let webMapperPath = path.resolve(this.config.data, 'mapper', 'webhooks');
|
|
39
38
|
let webFailsPath = path.resolve(this.config.data, 'mapper', 'webhooks', 'fails.json');
|
|
@@ -68,8 +67,7 @@ module.exports = class ImportWebhooks {
|
|
|
68
67
|
if (!self.webUidMapper.hasOwnProperty(webUid)) {
|
|
69
68
|
let requestOption = { json: { webhook: web } };
|
|
70
69
|
|
|
71
|
-
return
|
|
72
|
-
.stack({ api_key: self.config.target_stack, management_token: self.config.management_token })
|
|
70
|
+
return self.stackAPIClient
|
|
73
71
|
.webhook()
|
|
74
72
|
.create(requestOption.json)
|
|
75
73
|
.then(function (response) {
|
|
@@ -15,19 +15,17 @@ const helper = require('../util/fs');
|
|
|
15
15
|
const { formatError } = require('../util');
|
|
16
16
|
const { addlogs } = require('../util/log');
|
|
17
17
|
let config = require('../../config/default');
|
|
18
|
-
let stack = require('../util/contentstack-management-sdk');
|
|
19
18
|
|
|
20
19
|
module.exports = class importWorkflows {
|
|
21
|
-
client;
|
|
22
20
|
fails = [];
|
|
23
21
|
success = [];
|
|
24
22
|
workflowUidMapper = {};
|
|
25
23
|
workflowConfig = config.modules.workflows;
|
|
26
24
|
reqConcurrency = config.concurrency || config.fetchConcurrency || 1;
|
|
27
25
|
|
|
28
|
-
constructor(
|
|
29
|
-
this.config = merge(config,
|
|
30
|
-
this.
|
|
26
|
+
constructor(importConfig, stackAPIClient) {
|
|
27
|
+
this.config = merge(config, importConfig);
|
|
28
|
+
this.stackAPIClient = stackAPIClient;
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
start() {
|
|
@@ -63,10 +61,7 @@ module.exports = class importWorkflows {
|
|
|
63
61
|
if (!self.workflowUidMapper.hasOwnProperty(workflowUid)) {
|
|
64
62
|
const roleNameMap = {};
|
|
65
63
|
const workflowStages = workflow.workflow_stages;
|
|
66
|
-
const roles = await self.
|
|
67
|
-
.stack({ api_key: self.config.target_stack, management_token: self.config.management_token })
|
|
68
|
-
.role()
|
|
69
|
-
.fetchAll();
|
|
64
|
+
const roles = await self.stackAPIClient.role().fetchAll();
|
|
70
65
|
|
|
71
66
|
for (const role of roles.items) {
|
|
72
67
|
roleNameMap[role.name] = role.uid;
|
|
@@ -92,10 +87,7 @@ module.exports = class importWorkflows {
|
|
|
92
87
|
});
|
|
93
88
|
}
|
|
94
89
|
|
|
95
|
-
const role = await self.
|
|
96
|
-
.stack({ api_key: self.config.target_stack, management_token: self.config.management_token })
|
|
97
|
-
.role()
|
|
98
|
-
.create({ role: roleData });
|
|
90
|
+
const role = await self.stackAPIClient.role().create({ role: roleData });
|
|
99
91
|
stage.SYS_ACL.roles.uids[i] = role.uid;
|
|
100
92
|
roleNameMap[roleData.name] = role.uid;
|
|
101
93
|
} else {
|
|
@@ -126,8 +118,7 @@ module.exports = class importWorkflows {
|
|
|
126
118
|
workflow.branches = ['main'];
|
|
127
119
|
}
|
|
128
120
|
|
|
129
|
-
return self.
|
|
130
|
-
.stack({ api_key: self.config.target_stack, management_token: self.config.management_token })
|
|
121
|
+
return self.stackAPIClient
|
|
131
122
|
.workflow()
|
|
132
123
|
.create({ workflow })
|
|
133
124
|
.then(function (response) {
|
|
@@ -12,7 +12,6 @@ let util = require('../util');
|
|
|
12
12
|
let config = util.getConfig();
|
|
13
13
|
let extensionPath = path.resolve(config.data, 'mapper/extensions', 'uid-mapping.json');
|
|
14
14
|
let globalfieldsPath = path.resolve(config.data, 'mapper/globalfields', 'uid-mapping.json');
|
|
15
|
-
const marketplaceAppPath = path.resolve(config.data, 'marketplace_apps', 'marketplace_apps.json');
|
|
16
15
|
|
|
17
16
|
// eslint-disable-next-line camelcase
|
|
18
17
|
let extension_uid_Replace = (module.exports = function (schema, preserveStackVersion, installedExtensions) {
|
|
@@ -50,38 +49,8 @@ let extension_uid_Replace = (module.exports = function (schema, preserveStackVer
|
|
|
50
49
|
// eslint-disable-next-line camelcase
|
|
51
50
|
schema[i].extension_uid = data[extension_key_value];
|
|
52
51
|
} else if (schema[i].field_metadata && schema[i].field_metadata.extension) {
|
|
53
|
-
if (installedExtensions) {
|
|
54
|
-
|
|
55
|
-
const oldExt = _.find(marketplaceApps, { uid: schema[i].extension_uid });
|
|
56
|
-
|
|
57
|
-
if (oldExt) {
|
|
58
|
-
let ext = _.find(installedExtensions, (ext) => {
|
|
59
|
-
const { type, title, app_uid } = ext;
|
|
60
|
-
|
|
61
|
-
if (type === 'field' && app_uid === oldExt.app_uid) {
|
|
62
|
-
const titles = [
|
|
63
|
-
...(oldExt.manifest
|
|
64
|
-
? _.map(
|
|
65
|
-
_.map(
|
|
66
|
-
oldExt.manifest && oldExt.manifest.ui_location && oldExt.manifest.ui_location.locations,
|
|
67
|
-
'meta',
|
|
68
|
-
).flat(),
|
|
69
|
-
'name',
|
|
70
|
-
)
|
|
71
|
-
: []),
|
|
72
|
-
oldExt.title,
|
|
73
|
-
];
|
|
74
|
-
|
|
75
|
-
return _.includes(titles, title);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return false;
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
if (ext) {
|
|
82
|
-
schema[i].extension_uid = ext.uid;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
52
|
+
if (installedExtensions && installedExtensions[schema[i].extension_uid]) {
|
|
53
|
+
schema[i].extension_uid = installedExtensions[schema[i].extension_uid];
|
|
85
54
|
}
|
|
86
55
|
}
|
|
87
56
|
} else if (schema[i].data_type === 'json' && schema[i].hasOwnProperty('plugins') && schema[i].plugins.length > 0) {
|
package/src/lib/util/fs.js
CHANGED
package/src/lib/util/index.js
CHANGED
|
@@ -5,27 +5,26 @@
|
|
|
5
5
|
* MIT Licensed
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
const { HttpClient } = require('@contentstack/cli-utilities');
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const stack = require('./contentstack-management-sdk');
|
|
8
|
+
const _ = require('lodash');
|
|
9
|
+
const { HttpClient, managementSDKClient } = require('@contentstack/cli-utilities');
|
|
10
|
+
const fs = require('./fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const chalk = require('chalk');
|
|
13
|
+
const { addlogs } = require('./log');
|
|
14
|
+
const defaultConfig = require('../../config/default');
|
|
16
15
|
const promiseLimit = require('promise-limit');
|
|
17
|
-
|
|
16
|
+
let config;
|
|
18
17
|
|
|
19
|
-
exports.initialization =
|
|
18
|
+
exports.initialization = (configData) => {
|
|
20
19
|
config = this.buildAppConfig(configData);
|
|
21
|
-
|
|
20
|
+
const res = this.validateConfig(config);
|
|
22
21
|
|
|
23
22
|
if ((res && res !== 'error') || res === undefined) {
|
|
24
23
|
return config;
|
|
25
24
|
}
|
|
26
25
|
};
|
|
27
26
|
|
|
28
|
-
exports.validateConfig =
|
|
27
|
+
exports.validateConfig = (importConfig) => {
|
|
29
28
|
if (importConfig.email && importConfig.password && !importConfig.target_stack) {
|
|
30
29
|
addlogs(importConfig, chalk.red('Kindly provide api_token'), 'error');
|
|
31
30
|
return 'error';
|
|
@@ -47,12 +46,12 @@ exports.validateConfig = function (importConfig) {
|
|
|
47
46
|
}
|
|
48
47
|
};
|
|
49
48
|
|
|
50
|
-
exports.buildAppConfig =
|
|
49
|
+
exports.buildAppConfig = (importConfig) => {
|
|
51
50
|
importConfig = _.merge(defaultConfig, importConfig);
|
|
52
51
|
return importConfig;
|
|
53
52
|
};
|
|
54
53
|
|
|
55
|
-
exports.sanitizeStack =
|
|
54
|
+
exports.sanitizeStack = (importConfig) => {
|
|
56
55
|
if (typeof importConfig.preserveStackVersion !== 'boolean' || !importConfig.preserveStackVersion) {
|
|
57
56
|
return Promise.resolve();
|
|
58
57
|
}
|
|
@@ -103,17 +102,13 @@ exports.sanitizeStack = function (importConfig) {
|
|
|
103
102
|
}
|
|
104
103
|
};
|
|
105
104
|
|
|
106
|
-
exports.masterLocalDetails =
|
|
107
|
-
let client = stack.Client(credentialConfig);
|
|
105
|
+
exports.masterLocalDetails = (stackAPIClient) => {
|
|
108
106
|
return new Promise((resolve, reject) => {
|
|
109
|
-
|
|
110
|
-
.stack({ api_key: credentialConfig.target_stack, management_token: credentialConfig.management_token })
|
|
111
|
-
.locale()
|
|
112
|
-
.query();
|
|
107
|
+
const result = stackAPIClient.locale().query();
|
|
113
108
|
result
|
|
114
109
|
.find()
|
|
115
110
|
.then((response) => {
|
|
116
|
-
|
|
111
|
+
const masterLocalObj = response.items.filter((obj) => {
|
|
117
112
|
if (obj.fallback_locale === null) {
|
|
118
113
|
return obj;
|
|
119
114
|
}
|
|
@@ -126,68 +121,72 @@ exports.masterLocalDetails = function (credentialConfig) {
|
|
|
126
121
|
});
|
|
127
122
|
};
|
|
128
123
|
|
|
129
|
-
exports.field_rules_update =
|
|
130
|
-
return new Promise(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
124
|
+
exports.field_rules_update = (importConfig, ctPath) => {
|
|
125
|
+
return new Promise((resolve, reject) => {
|
|
126
|
+
managementSDKClient(config)
|
|
127
|
+
.then((APIClient) => {
|
|
128
|
+
fs.readFileSync(path.join(ctPath + '/field_rules_uid.json'), async (err, data) => {
|
|
129
|
+
if (err) {
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
132
|
+
const ct_field_visibility_uid = JSON.parse(data);
|
|
133
|
+
let ct_files = fs.readdirSync(ctPath);
|
|
134
|
+
if (ct_field_visibility_uid && ct_field_visibility_uid != 'undefined') {
|
|
135
|
+
for (const ele of ct_field_visibility_uid) {
|
|
136
|
+
if (ct_files.indexOf(ele + '.json') > -1) {
|
|
137
|
+
let schema = require(path.resolve(ctPath, ele));
|
|
138
|
+
// await field_rules_update(schema)
|
|
139
|
+
let fieldRuleLength = schema.field_rules.length;
|
|
140
|
+
for (let k = 0; k < fieldRuleLength; k++) {
|
|
141
|
+
let fieldRuleConditionLength = schema.field_rules[k].conditions.length;
|
|
142
|
+
for (let i = 0; i < fieldRuleConditionLength; i++) {
|
|
143
|
+
if (schema.field_rules[k].conditions[i].operand_field === 'reference') {
|
|
144
|
+
let entryMapperPath = path.resolve(importConfig.data, 'mapper', 'entries');
|
|
145
|
+
let entryUidMapperPath = path.join(entryMapperPath, 'uid-mapping.json');
|
|
146
|
+
let fieldRulesValue = schema.field_rules[k].conditions[i].value;
|
|
147
|
+
let fieldRulesArray = fieldRulesValue.split('.');
|
|
148
|
+
let updatedValue = [];
|
|
149
|
+
for (const element of fieldRulesArray) {
|
|
150
|
+
let splitedFieldRulesValue = element;
|
|
151
|
+
let oldUid = helper.readFileSync(path.join(entryUidMapperPath));
|
|
152
|
+
if (oldUid.hasOwnProperty(splitedFieldRulesValue)) {
|
|
153
|
+
updatedValue.push(oldUid[splitedFieldRulesValue]);
|
|
154
|
+
} else {
|
|
155
|
+
updatedValue.push(element);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
schema.field_rules[k].conditions[i].value = updatedValue.join('.');
|
|
161
159
|
}
|
|
162
160
|
}
|
|
163
|
-
schema.field_rules[k].conditions[i].value = updatedValue.join('.');
|
|
164
161
|
}
|
|
162
|
+
const stackAPIClient = APIClient.stack({
|
|
163
|
+
api_key: importConfig.target_stack,
|
|
164
|
+
management_token: importConfig.management_token,
|
|
165
|
+
});
|
|
166
|
+
let ctObj = stackAPIClient.contentType(schema.uid);
|
|
167
|
+
Object.assign(ctObj, _.cloneDeep(schema));
|
|
168
|
+
ctObj
|
|
169
|
+
.update()
|
|
170
|
+
.then(() => {
|
|
171
|
+
return resolve();
|
|
172
|
+
})
|
|
173
|
+
.catch((error) => {
|
|
174
|
+
return reject(error);
|
|
175
|
+
});
|
|
165
176
|
}
|
|
166
177
|
}
|
|
167
|
-
let ctObj = client
|
|
168
|
-
.stack({ api_key: importConfig.target_stack, management_token: importConfig.management_token })
|
|
169
|
-
.contentType(schema.uid);
|
|
170
|
-
Object.assign(ctObj, _.cloneDeep(schema));
|
|
171
|
-
ctObj
|
|
172
|
-
.update()
|
|
173
|
-
.then(() => {
|
|
174
|
-
return resolve();
|
|
175
|
-
})
|
|
176
|
-
.catch(function (error) {
|
|
177
|
-
return reject(error);
|
|
178
|
-
});
|
|
179
178
|
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
179
|
+
});
|
|
180
|
+
})
|
|
181
|
+
.catch(reject);
|
|
183
182
|
});
|
|
184
183
|
};
|
|
185
184
|
|
|
186
|
-
exports.getConfig =
|
|
185
|
+
exports.getConfig = () => {
|
|
187
186
|
return config;
|
|
188
187
|
};
|
|
189
188
|
|
|
190
|
-
exports.formatError =
|
|
189
|
+
exports.formatError = (error) => {
|
|
191
190
|
try {
|
|
192
191
|
if (typeof error === 'string') {
|
|
193
192
|
error = JSON.parse(error);
|
|
@@ -209,7 +208,7 @@ exports.formatError = function (error) {
|
|
|
209
208
|
return message;
|
|
210
209
|
};
|
|
211
210
|
|
|
212
|
-
exports.executeTask =
|
|
211
|
+
exports.executeTask = (handler, options, tasks = []) => {
|
|
213
212
|
if (typeof handler !== 'function') {
|
|
214
213
|
throw new Error('Invalid handler');
|
|
215
214
|
}
|
package/src/lib/util/login.js
CHANGED
|
@@ -8,49 +8,52 @@
|
|
|
8
8
|
const chalk = require('chalk');
|
|
9
9
|
|
|
10
10
|
const { addlogs } = require('../util/log');
|
|
11
|
-
|
|
12
|
-
let client;
|
|
11
|
+
const { managementSDKClient } = require('@contentstack/cli-utilities');
|
|
13
12
|
|
|
14
|
-
module.exports =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.
|
|
35
|
-
} else if (config.management_token) {
|
|
36
|
-
return resolve();
|
|
37
|
-
} else if (config.auth_token) {
|
|
38
|
-
client
|
|
39
|
-
.stack({ api_key: config.target_stack, management_token: config.management_token })
|
|
40
|
-
.fetch()
|
|
41
|
-
.then(function (stack) {
|
|
42
|
-
config.destinationStackName = stack.name
|
|
13
|
+
module.exports = (config) => {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
managementSDKClient(config)
|
|
16
|
+
.then((APIClient) => {
|
|
17
|
+
// eslint-disable-next-line no-console
|
|
18
|
+
if (config.email && config.password) {
|
|
19
|
+
console.log('Logging into Contentstack');
|
|
20
|
+
return APIClient.login({ email: config.email, password: config.password })
|
|
21
|
+
.then((response) => {
|
|
22
|
+
// eslint-disable-next-line no-console
|
|
23
|
+
console.log(chalk.green('Contentstack account authenticated successfully!'));
|
|
24
|
+
config.authtoken = response.user.authtoken;
|
|
25
|
+
config.headers = {
|
|
26
|
+
api_key: config.target_stack,
|
|
27
|
+
authtoken: config.authtoken,
|
|
28
|
+
'X-User-Agent': 'contentstack-import/v',
|
|
29
|
+
};
|
|
30
|
+
return resolve(config);
|
|
31
|
+
})
|
|
32
|
+
.catch(reject);
|
|
33
|
+
} else if (config.management_token) {
|
|
43
34
|
return resolve();
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
} else if (config.auth_token) {
|
|
36
|
+
const stackAPIClient = APIClient.stack({
|
|
37
|
+
api_key: config.target_stack,
|
|
38
|
+
management_token: config.management_token,
|
|
39
|
+
});
|
|
40
|
+
stackAPIClient
|
|
41
|
+
.fetch()
|
|
42
|
+
.then((stack) => {
|
|
43
|
+
config.destinationStackName = stack.name;
|
|
44
|
+
return resolve();
|
|
45
|
+
})
|
|
46
|
+
.catch((error) => {
|
|
47
|
+
let errorstack_key = error.errors.api_key;
|
|
48
|
+
if (error.errors.api_key) {
|
|
49
|
+
addlogs(config, chalk.red('Stack Api key ' + errorstack_key[0], 'Please enter valid Key'), 'error');
|
|
50
|
+
return reject(error);
|
|
51
|
+
}
|
|
52
|
+
addlogs(config, error.errorMessage, 'error');
|
|
53
|
+
return reject(error);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
.catch((error) => reject(error));
|
|
55
58
|
});
|
|
56
59
|
};
|
|
@@ -10,9 +10,6 @@ let _ = require('lodash');
|
|
|
10
10
|
let { marked } = require('marked');
|
|
11
11
|
|
|
12
12
|
let helper = require('./fs');
|
|
13
|
-
const { getConfig } = require('./');
|
|
14
|
-
let config = getConfig();
|
|
15
|
-
const marketplaceAppPath = path.resolve(config.data, 'marketplace_apps', 'marketplace_apps.json');
|
|
16
13
|
|
|
17
14
|
// get assets object
|
|
18
15
|
module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMapperPath, installedExtensions) {
|
|
@@ -75,38 +72,8 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
|
|
|
75
72
|
) {
|
|
76
73
|
findAssetIdsFromJsonCustomFields(data.entry, data.content_type.schema);
|
|
77
74
|
} else if (schema[i].data_type === 'json' && schema[i].field_metadata.extension) {
|
|
78
|
-
if (installedExtensions) {
|
|
79
|
-
|
|
80
|
-
const oldExt = _.find(marketplaceApps, { uid: schema[i].extension_uid });
|
|
81
|
-
|
|
82
|
-
if (oldExt) {
|
|
83
|
-
let ext = _.find(installedExtensions, (ext) => {
|
|
84
|
-
const { type, title, app_uid } = ext;
|
|
85
|
-
|
|
86
|
-
if (type === 'field' && app_uid === oldExt.app_uid) {
|
|
87
|
-
const titles = [
|
|
88
|
-
...(oldExt.manifest
|
|
89
|
-
? _.map(
|
|
90
|
-
_.map(
|
|
91
|
-
oldExt.manifest && oldExt.manifest.ui_location && oldExt.manifest.ui_location.locations,
|
|
92
|
-
'meta',
|
|
93
|
-
).flat(),
|
|
94
|
-
'name',
|
|
95
|
-
)
|
|
96
|
-
: []),
|
|
97
|
-
oldExt.title,
|
|
98
|
-
];
|
|
99
|
-
|
|
100
|
-
return _.includes(titles, title);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return false;
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
if (ext) {
|
|
107
|
-
schema[i].extension_uid = ext.uid;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
75
|
+
if (installedExtensions && installedExtensions[schema[i].extension_uid]) {
|
|
76
|
+
schema[i].extension_uid = installedExtensions[schema[i].extension_uid];
|
|
110
77
|
}
|
|
111
78
|
}
|
|
112
79
|
}
|
|
@@ -116,71 +83,13 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
|
|
|
116
83
|
ctSchema.map((row) => {
|
|
117
84
|
if (row.data_type === 'json') {
|
|
118
85
|
if (entryObj[row.uid] && row.field_metadata.extension && row.field_metadata.is_asset) {
|
|
119
|
-
if (installedExtensions) {
|
|
120
|
-
|
|
121
|
-
const oldExt = _.find(marketplaceApps, { uid: row.extension_uid });
|
|
122
|
-
|
|
123
|
-
if (oldExt) {
|
|
124
|
-
let ext = _.find(installedExtensions, (ext) => {
|
|
125
|
-
const { type, title, app_uid } = ext;
|
|
126
|
-
|
|
127
|
-
if (type === 'field' && app_uid === oldExt.app_uid) {
|
|
128
|
-
const titles = [
|
|
129
|
-
...(oldExt.manifest
|
|
130
|
-
? _.map(
|
|
131
|
-
_.map(
|
|
132
|
-
oldExt.manifest && oldExt.manifest.ui_location && oldExt.manifest.ui_location.locations,
|
|
133
|
-
'meta',
|
|
134
|
-
).flat(),
|
|
135
|
-
'name',
|
|
136
|
-
)
|
|
137
|
-
: []),
|
|
138
|
-
oldExt.title,
|
|
139
|
-
];
|
|
140
|
-
|
|
141
|
-
return _.includes(titles, title);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return false;
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
if (ext) {
|
|
148
|
-
row.extension_uid = ext.uid;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
86
|
+
if (installedExtensions && installedExtensions[row.extension_uid]) {
|
|
87
|
+
row.extension_uid = installedExtensions[row.extension_uid];
|
|
151
88
|
}
|
|
152
89
|
|
|
153
90
|
if (entryObj[row.uid].metadata && entryObj[row.uid].metadata.extension_uid) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (oldExt) {
|
|
158
|
-
let ext = _.find(installedExtensions, (ext) => {
|
|
159
|
-
const { type, title, app_uid } = ext;
|
|
160
|
-
|
|
161
|
-
if (type === 'field' && app_uid === oldExt.app_uid) {
|
|
162
|
-
const titles = [
|
|
163
|
-
...(oldExt.manifest
|
|
164
|
-
? _.map(
|
|
165
|
-
_.map(
|
|
166
|
-
oldExt.manifest && oldExt.manifest.ui_location && oldExt.manifest.ui_location.locations,
|
|
167
|
-
'meta',
|
|
168
|
-
).flat(),
|
|
169
|
-
'name',
|
|
170
|
-
)
|
|
171
|
-
: []),
|
|
172
|
-
oldExt.title,
|
|
173
|
-
];
|
|
174
|
-
|
|
175
|
-
return _.includes(titles, title);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return false;
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
if (ext) {
|
|
182
|
-
entryObj[row.uid].metadata.extension_uid = ext.uid;
|
|
183
|
-
}
|
|
91
|
+
if (installedExtensions && installedExtensions[entryObj[row.uid].metadata.extension_uid]) {
|
|
92
|
+
entryObj[row.uid].metadata.extension_uid = installedExtensions[entryObj[row.uid].metadata.extension_uid];
|
|
184
93
|
}
|
|
185
94
|
}
|
|
186
95
|
}
|
|
@@ -310,7 +219,9 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
|
|
|
310
219
|
[data.entry.uid]: matchedUids,
|
|
311
220
|
};
|
|
312
221
|
}
|
|
313
|
-
helper.
|
|
222
|
+
if (!helper.fileExistsSync(path.join(assetUidMapperPath, 'matched-asset-uids.json'))) {
|
|
223
|
+
helper.writeFile(path.join(assetUidMapperPath, 'matched-asset-uids.json'));
|
|
224
|
+
}
|
|
314
225
|
}
|
|
315
226
|
|
|
316
227
|
if (unmatchedUids.length) {
|
|
@@ -1,41 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const queryRequestOptions = {
|
|
10
|
-
include_marketplace_extensions: true,
|
|
11
|
-
};
|
|
12
|
-
const { target_stack: api_key, management_token, auth_token } = config || {};
|
|
13
|
-
|
|
14
|
-
if (api_key && management_token) {
|
|
15
|
-
return client
|
|
16
|
-
.stack({ api_key, management_token })
|
|
17
|
-
.extension()
|
|
18
|
-
.query(queryRequestOptions)
|
|
19
|
-
.find()
|
|
20
|
-
.then(({ items }) => resolve(items))
|
|
21
|
-
.catch(reject);
|
|
22
|
-
} else if (api_key && auth_token) {
|
|
23
|
-
const { cma } = configHandler.get('region') || {};
|
|
24
|
-
const headers = {
|
|
25
|
-
api_key,
|
|
26
|
-
authtoken: auth_token,
|
|
27
|
-
};
|
|
28
|
-
const httpClient = new HttpClient().headers(headers);
|
|
29
|
-
httpClient
|
|
30
|
-
.get(`${cma}/v3/extensions/?include_marketplace_extensions=true`)
|
|
31
|
-
.then(({ data: { extensions } }) => resolve(extensions));
|
|
32
|
-
} else {
|
|
33
|
-
resolve([]);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
1
|
+
const { formatError } = require('.');
|
|
2
|
+
const { cliux, configHandler } = require('@contentstack/cli-utilities');
|
|
3
|
+
|
|
4
|
+
const getAllStackSpecificApps = (developerHubBaseUrl, httpClient, config) => {
|
|
5
|
+
return httpClient
|
|
6
|
+
.get(`${developerHubBaseUrl}/installations?target_uids=${config.target_stack}`)
|
|
7
|
+
.then(({ data }) => data.data)
|
|
8
|
+
.catch((error) => log(config, `Failed to export marketplace-apps ${formatError(error)}`, 'error'));
|
|
36
9
|
};
|
|
37
10
|
|
|
38
|
-
const getDeveloperHubUrl = async () => {
|
|
11
|
+
const getDeveloperHubUrl = async (config) => {
|
|
39
12
|
const { cma, name } = configHandler.get('region') || {};
|
|
40
13
|
let developerHubBaseUrl = config.developerHubUrls[cma];
|
|
41
14
|
|
|
@@ -55,4 +28,4 @@ const getDeveloperHubUrl = async () => {
|
|
|
55
28
|
return developerHubBaseUrl.startsWith('http') ? developerHubBaseUrl : `https://${developerHubBaseUrl}`;
|
|
56
29
|
};
|
|
57
30
|
|
|
58
|
-
module.exports = {
|
|
31
|
+
module.exports = { getAllStackSpecificApps, getDeveloperHubUrl };
|