@contentstack/cli-cm-import 1.5.10 → 1.6.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 +6 -14
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +6 -0
- package/bin/run.cmd +3 -0
- package/lib/commands/cm/stacks/import.d.ts +10 -0
- package/lib/commands/cm/stacks/import.js +111 -0
- package/lib/config/index.d.ts +3 -0
- package/lib/config/index.js +372 -0
- package/lib/import/index.d.ts +1 -0
- package/lib/import/index.js +8 -0
- package/lib/import/module-importer.d.ts +13 -0
- package/lib/import/module-importer.js +70 -0
- package/lib/import/modules/assets.d.ts +63 -0
- package/lib/import/modules/assets.js +265 -0
- package/lib/import/modules/base-class.d.ts +69 -0
- package/lib/import/modules/base-class.js +165 -0
- package/lib/import/modules/index.d.ts +2 -0
- package/lib/import/modules/index.js +19 -0
- package/lib/import/modules/locales.d.ts +31 -0
- package/lib/import/modules/locales.js +152 -0
- package/lib/import/modules-js/assets.d.ts +33 -0
- package/lib/import/modules-js/assets.js +415 -0
- package/lib/import/modules-js/content-types.d.ts +33 -0
- package/lib/import/modules-js/content-types.js +176 -0
- package/lib/import/modules-js/custom-roles.d.ts +15 -0
- package/lib/import/modules-js/custom-roles.js +141 -0
- package/lib/import/modules-js/entries.d.ts +54 -0
- package/lib/import/modules-js/entries.js +1260 -0
- package/lib/import/modules-js/environments.d.ts +13 -0
- package/lib/import/modules-js/environments.js +85 -0
- package/lib/import/modules-js/extensions.d.ts +17 -0
- package/lib/import/modules-js/extensions.js +86 -0
- package/lib/import/modules-js/global-fields.d.ts +13 -0
- package/lib/import/modules-js/global-fields.js +109 -0
- package/lib/import/modules-js/index.d.ts +1 -0
- package/lib/import/modules-js/index.js +33 -0
- package/lib/import/modules-js/labels.d.ts +20 -0
- package/lib/import/modules-js/labels.js +148 -0
- package/lib/import/modules-js/locales.d.ts +24 -0
- package/lib/import/modules-js/locales.js +196 -0
- package/lib/import/modules-js/marketplace-apps.d.ts +60 -0
- package/lib/import/modules-js/marketplace-apps.js +409 -0
- package/lib/import/modules-js/webhooks.d.ts +17 -0
- package/lib/import/modules-js/webhooks.js +85 -0
- package/lib/import/modules-js/workflows.d.ts +18 -0
- package/lib/import/modules-js/workflows.js +132 -0
- package/lib/types/default-config.d.ts +130 -0
- package/lib/types/default-config.js +2 -0
- package/lib/types/import-config.d.ts +51 -0
- package/lib/types/import-config.js +2 -0
- package/lib/types/index.d.ts +30 -0
- package/lib/types/index.js +2 -0
- package/lib/utils/asset-helper.d.ts +4 -0
- package/lib/utils/asset-helper.js +387 -0
- package/lib/utils/backup-handler.d.ts +2 -0
- package/lib/utils/backup-handler.js +31 -0
- package/lib/utils/common-helper.d.ts +20 -0
- package/lib/utils/common-helper.js +244 -0
- package/lib/utils/content-type-helper.d.ts +49 -0
- package/lib/utils/content-type-helper.js +143 -0
- package/lib/utils/entries-helper.d.ts +4 -0
- package/lib/utils/entries-helper.js +252 -0
- package/lib/utils/extension-helper.d.ts +10 -0
- package/lib/utils/extension-helper.js +72 -0
- package/lib/utils/file-helper.d.ts +14 -0
- package/lib/utils/file-helper.js +140 -0
- package/lib/utils/import-config-handler.d.ts +3 -0
- package/lib/utils/import-config-handler.js +73 -0
- package/lib/utils/index.d.ts +12 -0
- package/lib/utils/index.js +29 -0
- package/lib/utils/interactive.d.ts +2 -0
- package/lib/utils/interactive.js +23 -0
- package/lib/utils/logger.d.ts +8 -0
- package/lib/utils/logger.js +154 -0
- package/lib/utils/login-handler.d.ts +8 -0
- package/lib/utils/login-handler.js +53 -0
- package/lib/utils/marketplace-app-helper.d.ts +4 -0
- package/lib/utils/marketplace-app-helper.js +31 -0
- package/messages/index.json +1 -7
- package/oclif.manifest.json +2 -2
- package/package.json +47 -21
- package/src/app.js +0 -217
- package/src/commands/cm/stacks/import.js +0 -161
- package/src/config/default.js +0 -352
- package/src/lib/import/assets.js +0 -495
- package/src/lib/import/content-types.js +0 -201
- package/src/lib/import/custom-roles.js +0 -169
- package/src/lib/import/entries.js +0 -1480
- package/src/lib/import/environments.js +0 -106
- package/src/lib/import/extensions.js +0 -108
- package/src/lib/import/global-fields.js +0 -135
- package/src/lib/import/labels.js +0 -175
- package/src/lib/import/locales.js +0 -216
- package/src/lib/import/marketplace-apps.js +0 -542
- package/src/lib/import/webhooks.js +0 -113
- package/src/lib/import/workflows.js +0 -166
- package/src/lib/util/extensionsUidReplace.js +0 -67
- package/src/lib/util/fs.js +0 -124
- package/src/lib/util/import-flags.js +0 -187
- package/src/lib/util/index.js +0 -222
- package/src/lib/util/log.js +0 -144
- package/src/lib/util/login.js +0 -58
- package/src/lib/util/lookupReplaceAssets.js +0 -366
- package/src/lib/util/lookupReplaceEntries.js +0 -250
- package/src/lib/util/marketplace-app-helper.js +0 -31
- package/src/lib/util/removeReferenceFields.js +0 -59
- package/src/lib/util/schemaTemplate.js +0 -38
- package/src/lib/util/supress-mandatory-fields.js +0 -34
- package/src/lib/util/upload.js +0 -56
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
/*!
|
|
4
|
+
* Contentstack Import
|
|
5
|
+
* Copyright (c) 2019 Contentstack LLC
|
|
6
|
+
* MIT Licensed
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.validateBranch = exports.executeTask = exports.formatError = exports.getConfig = exports.field_rules_update = exports.masterLocalDetails = exports.sanitizeStack = exports.buildAppConfig = exports.validateConfig = exports.initialization = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const _ = tslib_1.__importStar(require("lodash"));
|
|
12
|
+
const path = tslib_1.__importStar(require("path"));
|
|
13
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
14
|
+
const file_helper_1 = require("./file-helper");
|
|
15
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
16
|
+
const logger_1 = require("./logger");
|
|
17
|
+
const config_1 = tslib_1.__importDefault(require("../config"));
|
|
18
|
+
const promise_limit_1 = tslib_1.__importDefault(require("promise-limit"));
|
|
19
|
+
let config;
|
|
20
|
+
const initialization = (configData) => {
|
|
21
|
+
config = (0, exports.buildAppConfig)(configData);
|
|
22
|
+
const res = (0, exports.validateConfig)(config);
|
|
23
|
+
if ((res && res !== 'error') || res === undefined) {
|
|
24
|
+
return config;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.initialization = initialization;
|
|
28
|
+
const validateConfig = (importConfig) => {
|
|
29
|
+
if (importConfig.email && importConfig.password && !importConfig.target_stack) {
|
|
30
|
+
(0, logger_1.log)(importConfig, chalk_1.default.red('Kindly provide api_token'), 'error');
|
|
31
|
+
return 'error';
|
|
32
|
+
}
|
|
33
|
+
else if (!importConfig.email &&
|
|
34
|
+
!importConfig.password &&
|
|
35
|
+
!importConfig.management_token &&
|
|
36
|
+
importConfig.target_stack &&
|
|
37
|
+
!(0, cli_utilities_1.isAuthenticated)()) {
|
|
38
|
+
(0, logger_1.log)(importConfig, chalk_1.default.red('Kindly provide management_token or email and password'), 'error');
|
|
39
|
+
return 'error';
|
|
40
|
+
}
|
|
41
|
+
else if (!importConfig.email && !importConfig.password && importConfig.preserveStackVersion) {
|
|
42
|
+
(0, logger_1.log)(importConfig, chalk_1.default.red('Kindly provide Email and password for old version stack'), 'error');
|
|
43
|
+
return 'error';
|
|
44
|
+
}
|
|
45
|
+
else if ((importConfig.email && !importConfig.password) || (!importConfig.email && importConfig.password)) {
|
|
46
|
+
(0, logger_1.log)(importConfig, chalk_1.default.red('Kindly provide Email and password'), 'error');
|
|
47
|
+
return 'error';
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.validateConfig = validateConfig;
|
|
51
|
+
const buildAppConfig = (importConfig) => {
|
|
52
|
+
importConfig = _.merge(config_1.default, importConfig);
|
|
53
|
+
return importConfig;
|
|
54
|
+
};
|
|
55
|
+
exports.buildAppConfig = buildAppConfig;
|
|
56
|
+
const sanitizeStack = (importConfig) => {
|
|
57
|
+
if (typeof importConfig.preserveStackVersion !== 'boolean' || !importConfig.preserveStackVersion) {
|
|
58
|
+
return Promise.resolve();
|
|
59
|
+
}
|
|
60
|
+
(0, logger_1.log)(importConfig, 'Running script to maintain stack version.', 'success');
|
|
61
|
+
try {
|
|
62
|
+
const httpClient = cli_utilities_1.HttpClient.create();
|
|
63
|
+
httpClient.headers(importConfig.headers);
|
|
64
|
+
return httpClient.get(`https://${importConfig.host}/v3${importConfig.apis.stacks}`).then((stackDetails) => {
|
|
65
|
+
if (stackDetails.data && stackDetails.data.stack && stackDetails.data.stack.settings) {
|
|
66
|
+
const newStackVersion = stackDetails.data.stack.settings.version;
|
|
67
|
+
const newStackDate = new Date(newStackVersion).toString();
|
|
68
|
+
const stackFilePath = path.join(importConfig.data, importConfig.modules.stack.dirName, importConfig.modules.stack.fileName);
|
|
69
|
+
const oldStackDetails = (0, file_helper_1.readFileSync)(stackFilePath);
|
|
70
|
+
if (!oldStackDetails || !oldStackDetails.settings || !oldStackDetails.settings.hasOwnProperty('version')) {
|
|
71
|
+
throw new Error(`${JSON.stringify(oldStackDetails)} is invalid!`);
|
|
72
|
+
}
|
|
73
|
+
const oldStackDate = new Date(oldStackDetails.settings.version).toString();
|
|
74
|
+
if (oldStackDate > newStackDate) {
|
|
75
|
+
throw new Error('Migration Error. You cannot migrate data from new stack onto old. Kindly contact support@contentstack.com for more details.');
|
|
76
|
+
}
|
|
77
|
+
else if (oldStackDate === newStackDate) {
|
|
78
|
+
(0, logger_1.log)(importConfig, 'The version of both the stacks are same.', 'success');
|
|
79
|
+
return Promise.resolve();
|
|
80
|
+
}
|
|
81
|
+
(0, logger_1.log)(importConfig, 'Updating stack version.', 'success');
|
|
82
|
+
return httpClient
|
|
83
|
+
.put(`https://${importConfig.host}/v3${importConfig.apis.stacks}settings/set-version`, {
|
|
84
|
+
stack_settings: {
|
|
85
|
+
version: '2017-10-14', // This can be used as a variable
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
.then((response) => {
|
|
89
|
+
(0, logger_1.log)(importConfig, `Stack version preserved successfully!\n${JSON.stringify(response.data)}`, 'success');
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
throw new Error(`Unexpected stack details ${stackDetails && JSON.stringify(stackDetails.data)}`);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
console.log(error);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
exports.sanitizeStack = sanitizeStack;
|
|
100
|
+
const masterLocalDetails = (stackAPIClient) => {
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
const result = stackAPIClient.locale().query();
|
|
103
|
+
result
|
|
104
|
+
.find()
|
|
105
|
+
.then((response) => {
|
|
106
|
+
const masterLocalObj = response.items.filter((obj) => {
|
|
107
|
+
if (obj.fallback_locale === null) {
|
|
108
|
+
return obj;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return resolve(masterLocalObj[0]);
|
|
112
|
+
})
|
|
113
|
+
.catch((error) => {
|
|
114
|
+
return reject(error);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
exports.masterLocalDetails = masterLocalDetails;
|
|
119
|
+
const field_rules_update = (importConfig, ctPath) => {
|
|
120
|
+
return new Promise(async (resolve, reject) => {
|
|
121
|
+
let client = await (0, cli_utilities_1.managementSDKClient)(config);
|
|
122
|
+
(0, file_helper_1.readFile)(path.join(ctPath + '/field_rules_uid.json'))
|
|
123
|
+
.then(async (data) => {
|
|
124
|
+
const ct_field_visibility_uid = JSON.parse(data);
|
|
125
|
+
let ct_files = (0, file_helper_1.readdirSync)(ctPath);
|
|
126
|
+
if (ct_field_visibility_uid && ct_field_visibility_uid != 'undefined') {
|
|
127
|
+
for (const ele of ct_field_visibility_uid) {
|
|
128
|
+
if (ct_files.indexOf(ele + '.json') > -1) {
|
|
129
|
+
let schema = require(path.resolve(ctPath, ele));
|
|
130
|
+
// await field_rules_update(schema)
|
|
131
|
+
let fieldRuleLength = schema.field_rules.length;
|
|
132
|
+
for (let k = 0; k < fieldRuleLength; k++) {
|
|
133
|
+
let fieldRuleConditionLength = schema.field_rules[k].conditions.length;
|
|
134
|
+
for (let i = 0; i < fieldRuleConditionLength; i++) {
|
|
135
|
+
if (schema.field_rules[k].conditions[i].operand_field === 'reference') {
|
|
136
|
+
let entryMapperPath = path.resolve(importConfig.data, 'mapper', 'entries');
|
|
137
|
+
let entryUidMapperPath = path.join(entryMapperPath, 'uid-mapping.json');
|
|
138
|
+
let fieldRulesValue = schema.field_rules[k].conditions[i].value;
|
|
139
|
+
let fieldRulesArray = fieldRulesValue.split('.');
|
|
140
|
+
let updatedValue = [];
|
|
141
|
+
for (const element of fieldRulesArray) {
|
|
142
|
+
let splitedFieldRulesValue = element;
|
|
143
|
+
let oldUid = (0, file_helper_1.readFileSync)(path.join(entryUidMapperPath));
|
|
144
|
+
if (oldUid.hasOwnProperty(splitedFieldRulesValue)) {
|
|
145
|
+
updatedValue.push(oldUid[splitedFieldRulesValue]);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
updatedValue.push(element);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
schema.field_rules[k].conditions[i].value = updatedValue.join('.');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const stackAPIClient = client.stack({
|
|
155
|
+
api_key: importConfig.target_stack,
|
|
156
|
+
management_token: importConfig.management_token,
|
|
157
|
+
});
|
|
158
|
+
let ctObj = stackAPIClient.contentType(schema.uid);
|
|
159
|
+
Object.assign(ctObj, _.cloneDeep(schema));
|
|
160
|
+
ctObj
|
|
161
|
+
.update()
|
|
162
|
+
.then(() => {
|
|
163
|
+
return resolve('');
|
|
164
|
+
})
|
|
165
|
+
.catch((error) => {
|
|
166
|
+
return reject(error);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
.catch(reject);
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
exports.field_rules_update = field_rules_update;
|
|
177
|
+
const getConfig = () => {
|
|
178
|
+
return config;
|
|
179
|
+
};
|
|
180
|
+
exports.getConfig = getConfig;
|
|
181
|
+
const formatError = (error) => {
|
|
182
|
+
try {
|
|
183
|
+
if (typeof error === 'string') {
|
|
184
|
+
error = JSON.parse(error);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
error = JSON.parse(error.message);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch (e) { }
|
|
191
|
+
let message = (error === null || error === void 0 ? void 0 : error.errorMessage) || (error === null || error === void 0 ? void 0 : error.error_message) || (error === null || error === void 0 ? void 0 : error.message) || error;
|
|
192
|
+
if (error && error.errors && Object.keys(error.errors).length > 0) {
|
|
193
|
+
Object.keys(error.errors).forEach((e) => {
|
|
194
|
+
let entity = e;
|
|
195
|
+
if (e === 'authorization')
|
|
196
|
+
entity = 'Management Token';
|
|
197
|
+
if (e === 'api_key')
|
|
198
|
+
entity = 'Stack API key';
|
|
199
|
+
if (e === 'uid')
|
|
200
|
+
entity = 'Content Type';
|
|
201
|
+
if (e === 'access_token')
|
|
202
|
+
entity = 'Delivery Token';
|
|
203
|
+
message += ' ' + [entity, error.errors[e]].join(' ');
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return message;
|
|
207
|
+
};
|
|
208
|
+
exports.formatError = formatError;
|
|
209
|
+
const executeTask = (tasks = [], handler, options) => {
|
|
210
|
+
if (typeof handler !== 'function') {
|
|
211
|
+
throw new Error('Invalid handler');
|
|
212
|
+
}
|
|
213
|
+
const { concurrency = 1 } = options;
|
|
214
|
+
const limit = (0, promise_limit_1.default)(concurrency);
|
|
215
|
+
return Promise.all(tasks.map((task) => {
|
|
216
|
+
return limit(() => handler(task));
|
|
217
|
+
}));
|
|
218
|
+
};
|
|
219
|
+
exports.executeTask = executeTask;
|
|
220
|
+
const validateBranch = async (stackAPIClient, config, branch) => {
|
|
221
|
+
return new Promise(async (resolve, reject) => {
|
|
222
|
+
try {
|
|
223
|
+
const data = await stackAPIClient.branch(branch).fetch();
|
|
224
|
+
if (data && typeof data === 'object') {
|
|
225
|
+
if (data.error_message) {
|
|
226
|
+
(0, logger_1.log)(config, chalk_1.default.red(data.error_message), 'error');
|
|
227
|
+
(0, logger_1.log)(config, chalk_1.default.red('No branch found with the name ' + branch), 'error');
|
|
228
|
+
reject({ message: 'No branch found with the name ' + branch, error: data.error_message });
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
resolve(data);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
reject({ message: 'No branch found with the name ' + branch, error: {} });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
(0, logger_1.log)(config, chalk_1.default.red('No branch found with the name ' + branch), 'error');
|
|
240
|
+
reject({ message: 'No branch found with the name ' + branch, error });
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
exports.validateBranch = validateBranch;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content type utiles
|
|
3
|
+
* schema template
|
|
4
|
+
* remove reference fields
|
|
5
|
+
* suppress mandatory fields
|
|
6
|
+
*/
|
|
7
|
+
export declare const schemaTemplate: {
|
|
8
|
+
content_type: {
|
|
9
|
+
title: string;
|
|
10
|
+
uid: string;
|
|
11
|
+
schema: ({
|
|
12
|
+
display_name: string;
|
|
13
|
+
uid: string;
|
|
14
|
+
data_type: string;
|
|
15
|
+
field_metadata: {
|
|
16
|
+
_default: boolean;
|
|
17
|
+
};
|
|
18
|
+
unique: boolean;
|
|
19
|
+
mandatory: boolean;
|
|
20
|
+
multiple: boolean;
|
|
21
|
+
} | {
|
|
22
|
+
display_name: string;
|
|
23
|
+
uid: string;
|
|
24
|
+
data_type: string;
|
|
25
|
+
field_metadata: {
|
|
26
|
+
_default: boolean;
|
|
27
|
+
};
|
|
28
|
+
unique: boolean;
|
|
29
|
+
multiple: boolean;
|
|
30
|
+
mandatory?: undefined;
|
|
31
|
+
})[];
|
|
32
|
+
options: {
|
|
33
|
+
title: string;
|
|
34
|
+
publishable: boolean;
|
|
35
|
+
is_page: boolean;
|
|
36
|
+
singleton: boolean;
|
|
37
|
+
sub_title: string[];
|
|
38
|
+
url_pattern: string;
|
|
39
|
+
url_prefix: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/*!
|
|
44
|
+
* Contentstack Import
|
|
45
|
+
* Copyright (c) 2019 Contentstack LLC
|
|
46
|
+
* MIT Licensed
|
|
47
|
+
*/
|
|
48
|
+
export declare const suppressSchemaReference: (schema: any, flag: any) => void;
|
|
49
|
+
export declare const removeReferenceFields: (schema: any, flag: any, stackAPIClient: any) => Promise<void>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Content type utiles
|
|
4
|
+
* schema template
|
|
5
|
+
* remove reference fields
|
|
6
|
+
* suppress mandatory fields
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = void 0;
|
|
10
|
+
exports.schemaTemplate = {
|
|
11
|
+
content_type: {
|
|
12
|
+
title: 'Seed',
|
|
13
|
+
uid: '',
|
|
14
|
+
schema: [
|
|
15
|
+
{
|
|
16
|
+
display_name: 'Title',
|
|
17
|
+
uid: 'title',
|
|
18
|
+
data_type: 'text',
|
|
19
|
+
field_metadata: {
|
|
20
|
+
_default: true,
|
|
21
|
+
},
|
|
22
|
+
unique: false,
|
|
23
|
+
mandatory: true,
|
|
24
|
+
multiple: false,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
display_name: 'URL',
|
|
28
|
+
uid: 'url',
|
|
29
|
+
data_type: 'text',
|
|
30
|
+
field_metadata: {
|
|
31
|
+
_default: true,
|
|
32
|
+
},
|
|
33
|
+
unique: false,
|
|
34
|
+
multiple: false,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
options: {
|
|
38
|
+
title: 'title',
|
|
39
|
+
publishable: true,
|
|
40
|
+
is_page: true,
|
|
41
|
+
singleton: false,
|
|
42
|
+
sub_title: ['url'],
|
|
43
|
+
url_pattern: '/:title',
|
|
44
|
+
url_prefix: '/',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
/*!
|
|
49
|
+
* Contentstack Import
|
|
50
|
+
* Copyright (c) 2019 Contentstack LLC
|
|
51
|
+
* MIT Licensed
|
|
52
|
+
*/
|
|
53
|
+
const suppressSchemaReference = function (schema, flag) {
|
|
54
|
+
for (var i in schema) {
|
|
55
|
+
if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
|
|
56
|
+
(0, exports.suppressSchemaReference)(schema[i].schema, flag);
|
|
57
|
+
}
|
|
58
|
+
else if (schema[i].data_type === 'blocks') {
|
|
59
|
+
for (var block in schema[i].blocks) {
|
|
60
|
+
(0, exports.suppressSchemaReference)(schema[i].blocks[block].schema, flag);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else if (schema[i].data_type === 'reference') {
|
|
64
|
+
flag.references = true;
|
|
65
|
+
}
|
|
66
|
+
else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) {
|
|
67
|
+
flag.jsonRte = true;
|
|
68
|
+
if (schema[i].field_metadata.embed_entry === true)
|
|
69
|
+
flag.jsonRteEmbeddedEntries = true;
|
|
70
|
+
}
|
|
71
|
+
if ((schema[i].hasOwnProperty('mandatory') && schema[i].mandatory) ||
|
|
72
|
+
(schema[i].hasOwnProperty('unique') && schema[i].unique)) {
|
|
73
|
+
if (schema[i].uid !== 'title') {
|
|
74
|
+
schema[i].unique = false;
|
|
75
|
+
schema[i].mandatory = false;
|
|
76
|
+
flag.suppressed = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
exports.suppressSchemaReference = suppressSchemaReference;
|
|
82
|
+
const removeReferenceFields = async function (schema, flag, stackAPIClient) {
|
|
83
|
+
for (let i = 0; i < schema.length; i++) {
|
|
84
|
+
if (schema[i].data_type === 'group') {
|
|
85
|
+
await (0, exports.removeReferenceFields)(schema[i].schema, flag, stackAPIClient);
|
|
86
|
+
}
|
|
87
|
+
else if (schema[i].data_type === 'blocks') {
|
|
88
|
+
for (var block in schema[i].blocks) {
|
|
89
|
+
await (0, exports.removeReferenceFields)(schema[i].blocks[block].schema, flag, stackAPIClient);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (schema[i].data_type === 'reference' || schema[i].reference_to) {
|
|
93
|
+
flag.supressed = true;
|
|
94
|
+
// Check if content-type exists
|
|
95
|
+
// If exists, then no change should be required.
|
|
96
|
+
let isContentTypeError = false;
|
|
97
|
+
for (let j = 0; j < schema[i].reference_to.length; j++) {
|
|
98
|
+
try {
|
|
99
|
+
await stackAPIClient.contentType(schema[i].reference_to[j]).fetch();
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
// Else warn and modify the schema object.
|
|
103
|
+
isContentTypeError = true;
|
|
104
|
+
console.warn(`Content-type ${schema[i].reference_to[j]} does not exist. Removing the field from schema`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (isContentTypeError) {
|
|
108
|
+
schema.splice(i, 1);
|
|
109
|
+
--i;
|
|
110
|
+
if (schema.length < 1) {
|
|
111
|
+
schema.push({
|
|
112
|
+
data_type: 'text',
|
|
113
|
+
display_name: 'dummyTest',
|
|
114
|
+
uid: 'dummy_test',
|
|
115
|
+
field_metadata: {
|
|
116
|
+
description: '',
|
|
117
|
+
default_value: '',
|
|
118
|
+
version: 3,
|
|
119
|
+
},
|
|
120
|
+
format: '',
|
|
121
|
+
error_messages: {
|
|
122
|
+
format: '',
|
|
123
|
+
},
|
|
124
|
+
multiple: false,
|
|
125
|
+
mandatory: false,
|
|
126
|
+
unique: false,
|
|
127
|
+
non_localizable: false,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (
|
|
133
|
+
// handling entry references in json rte
|
|
134
|
+
schema[i].data_type === 'json' &&
|
|
135
|
+
schema[i].field_metadata.rich_text_type &&
|
|
136
|
+
schema[i].field_metadata.embed_entry &&
|
|
137
|
+
schema[i].reference_to.length > 1) {
|
|
138
|
+
flag.supressed = true;
|
|
139
|
+
schema[i].reference_to = ['sys_assets'];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
exports.removeReferenceFields = removeReferenceFields;
|