@contentstack/cli-migration 1.10.3 → 1.11.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 +2 -2
- package/lib/actions/action-list.d.ts +8 -0
- package/lib/actions/action-list.js +31 -0
- package/lib/actions/action-list.js.map +1 -0
- package/lib/actions/index.d.ts +180 -0
- package/lib/actions/index.js +207 -0
- package/lib/actions/index.js.map +1 -0
- package/lib/commands/cm/stacks/migration.d.ts +14 -0
- package/lib/commands/cm/stacks/migration.js +274 -0
- package/lib/commands/cm/stacks/migration.js.map +1 -0
- package/lib/config/api-config.d.ts +13 -0
- package/lib/config/api-config.js +19 -0
- package/lib/config/api-config.js.map +1 -0
- package/lib/config/default-options.d.ts +5 -0
- package/lib/config/default-options.js +8 -0
- package/lib/config/default-options.js.map +1 -0
- package/lib/config/index.d.ts +4 -0
- package/lib/config/index.js +11 -0
- package/lib/config/index.js.map +1 -0
- package/lib/config/master-locale.d.ts +7 -0
- package/lib/config/master-locale.js +11 -0
- package/lib/config/master-locale.js.map +1 -0
- package/lib/modules/base.d.ts +39 -0
- package/lib/modules/base.js +84 -0
- package/lib/modules/base.js.map +1 -0
- package/lib/modules/content-types.d.ts +61 -0
- package/lib/modules/content-types.js +173 -0
- package/lib/modules/content-types.js.map +1 -0
- package/lib/modules/fields.d.ts +179 -0
- package/lib/modules/fields.js +292 -0
- package/lib/modules/fields.js.map +1 -0
- package/lib/modules/index.d.ts +5 -0
- package/lib/modules/index.js +13 -0
- package/lib/modules/index.js.map +1 -0
- package/lib/modules/locale.d.ts +6 -0
- package/lib/modules/locale.js +27 -0
- package/lib/modules/locale.js.map +1 -0
- package/lib/modules/migration.d.ts +50 -0
- package/lib/modules/migration.js +109 -0
- package/lib/modules/migration.js.map +1 -0
- package/lib/modules/parser.d.ts +3 -0
- package/lib/modules/parser.js +93 -0
- package/lib/modules/parser.js.map +1 -0
- package/lib/services/content-types.d.ts +25 -0
- package/lib/services/content-types.js +302 -0
- package/lib/services/content-types.js.map +1 -0
- package/lib/services/index.d.ts +3 -0
- package/lib/services/index.js +9 -0
- package/lib/services/index.js.map +1 -0
- package/lib/services/locales.d.ts +6 -0
- package/lib/services/locales.js +68 -0
- package/lib/services/locales.js.map +1 -0
- package/lib/utils/auto-retry.d.ts +2 -0
- package/lib/utils/auto-retry.js +30 -0
- package/lib/utils/auto-retry.js.map +1 -0
- package/lib/utils/callsite.d.ts +2 -0
- package/lib/utils/callsite.js +21 -0
- package/lib/utils/callsite.js.map +1 -0
- package/lib/utils/constants.d.ts +108 -0
- package/lib/utils/constants.js +206 -0
- package/lib/utils/constants.js.map +1 -0
- package/lib/utils/contentstack-sdk.d.ts +7 -0
- package/lib/utils/contentstack-sdk.js +53 -0
- package/lib/utils/contentstack-sdk.js.map +1 -0
- package/lib/utils/error-helper.d.ts +2 -0
- package/lib/utils/error-helper.js +102 -0
- package/lib/utils/error-helper.js.map +1 -0
- package/lib/utils/fs-helper.d.ts +4 -0
- package/lib/utils/fs-helper.js +37 -0
- package/lib/utils/fs-helper.js.map +1 -0
- package/lib/utils/get-batches.d.ts +2 -0
- package/lib/utils/get-batches.js +8 -0
- package/lib/utils/get-batches.js.map +1 -0
- package/lib/utils/get-config.d.ts +6 -0
- package/lib/utils/get-config.js +11 -0
- package/lib/utils/get-config.js.map +1 -0
- package/lib/utils/group-by.d.ts +1 -0
- package/lib/utils/group-by.js +41 -0
- package/lib/utils/group-by.js.map +1 -0
- package/lib/utils/index.d.ts +18 -0
- package/lib/utils/index.js +39 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/logger.d.ts +4 -0
- package/lib/utils/logger.js +68 -0
- package/lib/utils/logger.js.map +1 -0
- package/lib/utils/map.d.ts +7 -0
- package/lib/utils/map.js +40 -0
- package/lib/utils/map.js.map +1 -0
- package/lib/utils/migration-logger.d.ts +7 -0
- package/lib/utils/migration-logger.js +26 -0
- package/lib/utils/migration-logger.js.map +1 -0
- package/lib/utils/modules.d.ts +2 -0
- package/lib/utils/modules.js +118 -0
- package/lib/utils/modules.js.map +1 -0
- package/lib/utils/object-helper.d.ts +1 -0
- package/lib/utils/object-helper.js +12 -0
- package/lib/utils/object-helper.js.map +1 -0
- package/lib/utils/request.d.ts +9 -0
- package/lib/utils/request.js +78 -0
- package/lib/utils/request.js.map +1 -0
- package/lib/utils/safe-promise.d.ts +2 -0
- package/lib/utils/safe-promise.js +6 -0
- package/lib/utils/safe-promise.js.map +1 -0
- package/lib/utils/schema-helper.d.ts +5 -0
- package/lib/utils/schema-helper.js +36 -0
- package/lib/utils/schema-helper.js.map +1 -0
- package/lib/utils/success-handler.d.ts +2 -0
- package/lib/utils/success-handler.js +12 -0
- package/lib/utils/success-handler.js.map +1 -0
- package/lib/validators/api-error.d.ts +4 -0
- package/lib/validators/api-error.js +17 -0
- package/lib/validators/api-error.js.map +1 -0
- package/lib/validators/base-validator.d.ts +4 -0
- package/lib/validators/base-validator.js +34 -0
- package/lib/validators/base-validator.js.map +1 -0
- package/lib/validators/create-content-type-validator.d.ts +7 -0
- package/lib/validators/create-content-type-validator.js +45 -0
- package/lib/validators/create-content-type-validator.js.map +1 -0
- package/lib/validators/edit-content-type-validator.d.ts +7 -0
- package/lib/validators/edit-content-type-validator.js +44 -0
- package/lib/validators/edit-content-type-validator.js.map +1 -0
- package/lib/validators/field-validator.d.ts +4 -0
- package/lib/validators/field-validator.js +17 -0
- package/lib/validators/field-validator.js.map +1 -0
- package/lib/validators/index.d.ts +8 -0
- package/lib/validators/index.js +19 -0
- package/lib/validators/index.js.map +1 -0
- package/lib/validators/migration-error.d.ts +4 -0
- package/lib/validators/migration-error.js +16 -0
- package/lib/validators/migration-error.js.map +1 -0
- package/lib/validators/schema-validator.d.ts +4 -0
- package/lib/validators/schema-validator.js +19 -0
- package/lib/validators/schema-validator.js.map +1 -0
- package/lib/validators/type-error.d.ts +5 -0
- package/lib/validators/type-error.js +18 -0
- package/lib/validators/type-error.js.map +1 -0
- package/oclif.manifest.json +145 -0
- package/package.json +21 -11
- package/src/actions/action-list.js +0 -32
- package/src/actions/index.js +0 -217
- package/src/commands/cm/stacks/migration.js +0 -316
- package/src/config/api-config.js +0 -18
- package/src/config/default-options.js +0 -7
- package/src/config/index.js +0 -7
- package/src/config/master-locale.js +0 -10
- package/src/modules/base.js +0 -95
- package/src/modules/content-types.js +0 -208
- package/src/modules/fields.js +0 -339
- package/src/modules/index.js +0 -8
- package/src/modules/locale.js +0 -33
- package/src/modules/migration.js +0 -112
- package/src/modules/parser.js +0 -105
- package/src/services/content-types.js +0 -317
- package/src/services/index.js +0 -6
- package/src/services/locales.js +0 -71
- package/src/utils/auto-retry.js +0 -32
- package/src/utils/callsite.js +0 -23
- package/src/utils/constants.js +0 -223
- package/src/utils/contentstack-sdk.js +0 -70
- package/src/utils/error-helper.js +0 -105
- package/src/utils/fs-helper.js +0 -29
- package/src/utils/get-batches.js +0 -7
- package/src/utils/get-config.js +0 -13
- package/src/utils/group-by.js +0 -38
- package/src/utils/index.js +0 -21
- package/src/utils/logger.js +0 -75
- package/src/utils/map.js +0 -40
- package/src/utils/migration-logger.js +0 -21
- package/src/utils/modules.js +0 -134
- package/src/utils/object-helper.js +0 -9
- package/src/utils/request.js +0 -95
- package/src/utils/safe-promise.js +0 -3
- package/src/utils/schema-helper.js +0 -35
- package/src/utils/success-handler.js +0 -12
- package/src/validators/api-error.js +0 -20
- package/src/validators/base-validator.js +0 -39
- package/src/validators/create-content-type-validator.js +0 -54
- package/src/validators/edit-content-type-validator.js +0 -53
- package/src/validators/field-validator.js +0 -21
- package/src/validators/index.js +0 -11
- package/src/validators/migration-error.js +0 -20
- package/src/validators/schema-validator.js +0 -23
- package/src/validators/type-error.js +0 -22
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/* eslint-disable no-unused-expressions */
|
|
5
|
+
/* eslint-disable no-warning-comments */
|
|
6
|
+
/* eslint-disable camelcase */
|
|
7
|
+
// Dependencies
|
|
8
|
+
// @ts-ignore - no types available
|
|
9
|
+
const listr_1 = tslib_1.__importDefault(require("listr"));
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
const cli_command_1 = require("@contentstack/cli-command");
|
|
12
|
+
// @ts-ignore - no types available
|
|
13
|
+
const async_1 = require("async");
|
|
14
|
+
const modules_1 = require("../../../modules");
|
|
15
|
+
const actions_1 = require("../../../actions");
|
|
16
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
17
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
18
|
+
const validators_1 = require("../../../validators");
|
|
19
|
+
// Utils
|
|
20
|
+
const index_1 = require("../../../utils/index");
|
|
21
|
+
// Properties
|
|
22
|
+
const { get, set, getMapInstance, resetMapInstance } = index_1.map;
|
|
23
|
+
const { requests: _requests, actionMapper, MANAGEMENT_SDK, MANAGEMENT_TOKEN, AUTH_TOKEN, API_KEY, BRANCH, MANAGEMENT_CLIENT, } = index_1.constants;
|
|
24
|
+
class MigrationCommand extends cli_command_1.Command {
|
|
25
|
+
async run() {
|
|
26
|
+
// TODO: filePath validation required.
|
|
27
|
+
const { flags: migrationCommandFlags } = await this.parse(MigrationCommand);
|
|
28
|
+
const branch = migrationCommandFlags.branch;
|
|
29
|
+
const filePath = migrationCommandFlags['file-path'] || migrationCommandFlags.filePath;
|
|
30
|
+
const multi = migrationCommandFlags.multiple || migrationCommandFlags.multi;
|
|
31
|
+
const authtoken = (0, cli_utilities_1.isAuthenticated)();
|
|
32
|
+
const apiKey = migrationCommandFlags['api-key'] || migrationCommandFlags['stack-api-key'];
|
|
33
|
+
const alias = migrationCommandFlags['alias'] || migrationCommandFlags['management-token-alias'];
|
|
34
|
+
const config = migrationCommandFlags['config'];
|
|
35
|
+
if (!authtoken && !alias) {
|
|
36
|
+
this.log("AuthToken is not present in local drive, Hence use 'csdx auth:login' command for login or provide management token alias");
|
|
37
|
+
this.exit();
|
|
38
|
+
}
|
|
39
|
+
if (!filePath || !fs_1.default.existsSync(filePath)) {
|
|
40
|
+
this.log('Please provide the migration script file path, use --file-path flag');
|
|
41
|
+
this.exit();
|
|
42
|
+
}
|
|
43
|
+
// Reset map instance
|
|
44
|
+
const mapInstance = getMapInstance();
|
|
45
|
+
resetMapInstance(mapInstance);
|
|
46
|
+
if (migrationCommandFlags['config-file']) {
|
|
47
|
+
set('config-path', mapInstance, migrationCommandFlags['config-file']);
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(config) && config.length > 0) {
|
|
50
|
+
let configObj = config.reduce((a, v) => {
|
|
51
|
+
//NOTE: Temp code to handle only one spilt(Window absolute path issue).Need to replace with hardcoded config key
|
|
52
|
+
let [key, ...value] = v.split(':');
|
|
53
|
+
const joinedValue = (value === null || value === void 0 ? void 0 : value.length) > 1 ? value === null || value === void 0 ? void 0 : value.join(':') : value === null || value === void 0 ? void 0 : value.join();
|
|
54
|
+
return Object.assign(Object.assign({}, a), { [key]: joinedValue });
|
|
55
|
+
}, {});
|
|
56
|
+
set('config', mapInstance, configObj);
|
|
57
|
+
}
|
|
58
|
+
const APIClient = await (0, cli_utilities_1.managementSDKClient)({ host: this.cmaHost });
|
|
59
|
+
let stackSDKInstance;
|
|
60
|
+
if (branch) {
|
|
61
|
+
set(BRANCH, mapInstance, branch);
|
|
62
|
+
}
|
|
63
|
+
if (alias) {
|
|
64
|
+
let managementToken = this.getToken(alias);
|
|
65
|
+
if (managementToken) {
|
|
66
|
+
set(MANAGEMENT_TOKEN, mapInstance, managementToken);
|
|
67
|
+
set(API_KEY, mapInstance, managementToken.apiKey);
|
|
68
|
+
if (branch) {
|
|
69
|
+
stackSDKInstance = APIClient.stack({
|
|
70
|
+
management_token: managementToken.token,
|
|
71
|
+
api_key: managementToken.apiKey,
|
|
72
|
+
branch_uid: branch,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
stackSDKInstance = APIClient.stack({
|
|
77
|
+
management_token: managementToken.token,
|
|
78
|
+
api_key: managementToken.apiKey,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (authtoken) {
|
|
84
|
+
set(AUTH_TOKEN, mapInstance, authtoken);
|
|
85
|
+
set(API_KEY, mapInstance, apiKey);
|
|
86
|
+
if (branch) {
|
|
87
|
+
stackSDKInstance = APIClient.stack({
|
|
88
|
+
api_key: apiKey,
|
|
89
|
+
branch_uid: branch,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
stackSDKInstance = APIClient.stack({ api_key: apiKey });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
set(MANAGEMENT_SDK, mapInstance, stackSDKInstance);
|
|
97
|
+
set(MANAGEMENT_CLIENT, mapInstance, APIClient);
|
|
98
|
+
if (!(await (0, index_1.installModules)(filePath, multi))) {
|
|
99
|
+
this.log(`Error: Failed to install dependencies for the specified scripts.`);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
if (multi) {
|
|
103
|
+
await this.execMultiFiles(filePath, mapInstance);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
await this.execSingleFile(filePath, mapInstance);
|
|
107
|
+
}
|
|
108
|
+
const errLogPath = `${process.cwd()}/migration-logs`;
|
|
109
|
+
if (fs_1.default.existsSync(errLogPath)) {
|
|
110
|
+
this.log(`The log has been stored at: `, errLogPath);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async execSingleFile(filePath, mapInstance) {
|
|
114
|
+
// Resolved absolute path
|
|
115
|
+
const resolvedMigrationPath = (0, cli_utilities_1.pathValidator)(filePath);
|
|
116
|
+
// User provided migration function - dynamic require for JS migration scripts
|
|
117
|
+
const migrationFunc = require(resolvedMigrationPath);
|
|
118
|
+
const parser = new modules_1.Parser();
|
|
119
|
+
try {
|
|
120
|
+
const migrationParser = await parser.getMigrationParser(migrationFunc);
|
|
121
|
+
if (migrationParser.hasErrors) {
|
|
122
|
+
(0, index_1.errorHelper)(migrationParser.hasErrors);
|
|
123
|
+
// When the process is child, send error message to parent
|
|
124
|
+
if (process.send)
|
|
125
|
+
process.send({ errorOccurred: true });
|
|
126
|
+
this.exit(1);
|
|
127
|
+
}
|
|
128
|
+
// Make calls from here
|
|
129
|
+
const requests = get(_requests, mapInstance);
|
|
130
|
+
// Fetches tasks array
|
|
131
|
+
const tasks = this.getTasks(requests);
|
|
132
|
+
const listr = new listr_1.default(tasks);
|
|
133
|
+
await listr.run();
|
|
134
|
+
requests.splice(0, requests.length);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
(0, index_1.errorHelper)(error, filePath);
|
|
138
|
+
if (process.send)
|
|
139
|
+
process.send({ errorOccurred: true });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async execMultiFiles(filePath, mapInstance) {
|
|
143
|
+
// Resolved absolute path
|
|
144
|
+
const resolvedMigrationPath = (0, cli_utilities_1.pathValidator)(filePath);
|
|
145
|
+
try {
|
|
146
|
+
const files = fs_1.default.readdirSync(resolvedMigrationPath);
|
|
147
|
+
for (const element of files) {
|
|
148
|
+
const file = element;
|
|
149
|
+
if ((0, path_1.extname)(file) === '.js') {
|
|
150
|
+
// eslint-disable-next-line no-await-in-loop
|
|
151
|
+
await this.execSingleFile((0, cli_utilities_1.pathValidator)((0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(filePath), (0, cli_utilities_1.sanitizePath)(file))), mapInstance);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
(0, index_1.errorHelper)(error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
getTasks(requests) {
|
|
160
|
+
const _tasks = [];
|
|
161
|
+
const results = [];
|
|
162
|
+
const taskFn = (reqObj) => {
|
|
163
|
+
const { failedTitle, successTitle, tasks } = reqObj;
|
|
164
|
+
return async (ctx, task) => {
|
|
165
|
+
const [err, result] = await (0, index_1.safePromise)((0, async_1.waterfall)(tasks));
|
|
166
|
+
if (err) {
|
|
167
|
+
ctx.error = true;
|
|
168
|
+
task.title = failedTitle;
|
|
169
|
+
throw err;
|
|
170
|
+
}
|
|
171
|
+
result && results.push(result);
|
|
172
|
+
task.title = successTitle;
|
|
173
|
+
return result;
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
for (const element of requests) {
|
|
177
|
+
let reqObj = element;
|
|
178
|
+
const { title } = reqObj;
|
|
179
|
+
const taskObj = {
|
|
180
|
+
title: title,
|
|
181
|
+
task: taskFn(reqObj),
|
|
182
|
+
};
|
|
183
|
+
_tasks.push(taskObj);
|
|
184
|
+
}
|
|
185
|
+
return _tasks;
|
|
186
|
+
}
|
|
187
|
+
handleErrors() {
|
|
188
|
+
const mapInstance = getMapInstance();
|
|
189
|
+
const actions = get(actionMapper, mapInstance);
|
|
190
|
+
const actionList = new actions_1.ActionList(actions);
|
|
191
|
+
actionList.addValidators(new validators_1.ApiError());
|
|
192
|
+
actionList.addValidators(new validators_1.SchemaValidator());
|
|
193
|
+
actionList.addValidators(new validators_1.MigrationError());
|
|
194
|
+
actionList.addValidators(new validators_1.FieldValidator());
|
|
195
|
+
const errors = actionList.validate();
|
|
196
|
+
(0, index_1.errorHelper)(errors);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
exports.default = MigrationCommand;
|
|
200
|
+
MigrationCommand.description = 'Contentstack migration script.';
|
|
201
|
+
MigrationCommand.examples = [
|
|
202
|
+
'$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key>',
|
|
203
|
+
'$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key> --branch <target branch name>',
|
|
204
|
+
'$ csdx cm:migration --config <key1>:<value1> <key2>:<value2> ... --file-path <migration/script/file/path>',
|
|
205
|
+
'$ csdx cm:migration --config-file <path/to/json/config/file> --file-path <migration/script/file/path>',
|
|
206
|
+
'$ csdx cm:migration --multiple --file-path <migration/scripts/dir/path> ',
|
|
207
|
+
'$ csdx cm:migration --alias --file-path <migration/script/file/path> -k <api-key>',
|
|
208
|
+
];
|
|
209
|
+
MigrationCommand.flags = {
|
|
210
|
+
'stack-api-key': cli_utilities_1.flags.string({
|
|
211
|
+
char: 'k',
|
|
212
|
+
description: 'Use this flag to add the API key of your stack. You must use either the --stack-api-key flag or the --alias flag.',
|
|
213
|
+
exclusive: ['alias'],
|
|
214
|
+
}),
|
|
215
|
+
alias: cli_utilities_1.flags.string({
|
|
216
|
+
char: 'a',
|
|
217
|
+
description: 'Use this flag to add the management token alias. You must use either the --alias flag or the --stack-api-key flag.',
|
|
218
|
+
}),
|
|
219
|
+
'file-path': cli_utilities_1.flags.string({
|
|
220
|
+
description: 'Use this flag to provide the path of the file of the migration script.',
|
|
221
|
+
}),
|
|
222
|
+
branch: cli_utilities_1.flags.string({
|
|
223
|
+
char: 'B',
|
|
224
|
+
description: 'Use this flag to add the branch name where you want to perform the migration. (target branch name)',
|
|
225
|
+
parse: (0, cli_utilities_1.printFlagDeprecation)(['-B'], ['--branch']),
|
|
226
|
+
}),
|
|
227
|
+
'config-file': cli_utilities_1.flags.string({
|
|
228
|
+
description: '[optional] Path of the JSON configuration file.',
|
|
229
|
+
}),
|
|
230
|
+
config: cli_utilities_1.flags.string({
|
|
231
|
+
description: '[optional] Inline configuration, <key1>:<value1>. Passing an external configuration makes the script re-usable.',
|
|
232
|
+
multiple: true,
|
|
233
|
+
}),
|
|
234
|
+
multiple: cli_utilities_1.flags.boolean({
|
|
235
|
+
description: 'This flag helps you to migrate multiple content files in a single instance. Mention the folder path where your migration script files are stored.',
|
|
236
|
+
}),
|
|
237
|
+
// To be deprecated
|
|
238
|
+
'api-key': cli_utilities_1.flags.string({
|
|
239
|
+
char: 'k',
|
|
240
|
+
description: 'With this flag add the API key of your stack.',
|
|
241
|
+
// dependsOn: ['authtoken'],
|
|
242
|
+
exclusive: ['alias'],
|
|
243
|
+
parse: (0, cli_utilities_1.printFlagDeprecation)(['--api-key'], ['-k', '--stack-api-key']),
|
|
244
|
+
hidden: true,
|
|
245
|
+
}),
|
|
246
|
+
authtoken: cli_utilities_1.flags.boolean({
|
|
247
|
+
char: 'A',
|
|
248
|
+
description: 'Use this flag to use the auth token of the current session. After logging in CLI, an auth token is generated for each new session.',
|
|
249
|
+
dependsOn: ['api-key'],
|
|
250
|
+
exclusive: ['alias'],
|
|
251
|
+
parse: (0, cli_utilities_1.printFlagDeprecation)(['-A', '--authtoken']),
|
|
252
|
+
hidden: true,
|
|
253
|
+
}),
|
|
254
|
+
'management-token-alias': cli_utilities_1.flags.string({
|
|
255
|
+
description: 'Alias of the management token.',
|
|
256
|
+
exclusive: ['authtoken'],
|
|
257
|
+
hidden: true,
|
|
258
|
+
parse: (0, cli_utilities_1.printFlagDeprecation)(['--management-token-alias'], ['-a', '--alias']),
|
|
259
|
+
}),
|
|
260
|
+
filePath: cli_utilities_1.flags.string({
|
|
261
|
+
char: 'n',
|
|
262
|
+
description: 'Use this flag to provide the path of the file of the migration script provided by the user.',
|
|
263
|
+
parse: (0, cli_utilities_1.printFlagDeprecation)(['-n', '--filePath'], ['--file-path']),
|
|
264
|
+
hidden: true,
|
|
265
|
+
}),
|
|
266
|
+
multi: cli_utilities_1.flags.boolean({
|
|
267
|
+
description: 'This flag helps you to migrate multiple content files in a single instance.',
|
|
268
|
+
parse: (0, cli_utilities_1.printFlagDeprecation)(['--multi'], ['--multiple']),
|
|
269
|
+
hidden: true,
|
|
270
|
+
}),
|
|
271
|
+
};
|
|
272
|
+
MigrationCommand.aliases = ['cm:migration'];
|
|
273
|
+
MigrationCommand.usage = 'cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>] [--config <value>] [--multiple]';
|
|
274
|
+
//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.js","sourceRoot":"","sources":["../../../../src/commands/cm/stacks/mig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C,CAAC,SAAS,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;QACxD,MAAM,EAAE,IAAI;KACb,CAAC;CACH,CAAC;AAEK,wBAAO,GAAa,CAAC,cAAc,CAAC,CAAC;AAErC,sBAAK,GACV,gJAAgJ,CAAC","sourcesContent":["/* eslint-disable no-unused-expressions */\n/* eslint-disable no-warning-comments */\n/* eslint-disable camelcase */\n// Dependencies\n// @ts-ignore - no types available\nimport Listr from 'listr';\nimport { resolve, extname } from 'path';\nimport { Command } from '@contentstack/cli-command';\n// @ts-ignore - no types available\nimport { waterfall } from 'async';\nimport { Parser } from '../../../modules';\nimport { ActionList } from '../../../actions';\nimport fs from 'fs';\nimport {\n printFlagDeprecation,\n managementSDKClient,\n flags,\n FlagInput,\n isAuthenticated,\n pathValidator,\n sanitizePath,\n} from '@contentstack/cli-utilities';\n\nimport { ApiError, SchemaValidator, MigrationError, FieldValidator } from '../../../validators';\n\n// Utils\nimport { map as _map, constants, safePromise, errorHelper, installModules } from '../../../utils/index';\n// Properties\nconst { get, set, getMapInstance, resetMapInstance } = _map;\nconst {\n requests: _requests,\n actionMapper,\n MANAGEMENT_SDK,\n MANAGEMENT_TOKEN,\n AUTH_TOKEN,\n API_KEY,\n BRANCH,\n MANAGEMENT_CLIENT,\n} = constants;\n\nexport default class MigrationCommand extends Command {\n static description = 'Contentstack migration script.';\n\n static examples: string[] = [\n '$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key>',\n '$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key> --branch <target branch name>',\n '$ csdx cm:migration --config <key1>:<value1> <key2>:<value2> ... --file-path <migration/script/file/path>',\n '$ csdx cm:migration --config-file <path/to/json/config/file> --file-path <migration/script/file/path>',\n '$ csdx cm:migration --multiple --file-path <migration/scripts/dir/path> ',\n '$ csdx cm:migration --alias --file-path <migration/script/file/path> -k <api-key>',\n ];\n\n static flags: FlagInput = {\n 'stack-api-key': flags.string({\n char: 'k',\n description: 'Use this flag to add the API key of your stack. You must use either the --stack-api-key flag or the --alias flag.',\n exclusive: ['alias'],\n }),\n alias: flags.string({\n char: 'a',\n description: 'Use this flag to add the management token alias. You must use either the --alias flag or the --stack-api-key flag.',\n }),\n 'file-path': flags.string({\n description: 'Use this flag to provide the path of the file of the migration script.',\n }),\n branch: flags.string({\n char: 'B',\n description: 'Use this flag to add the branch name where you want to perform the migration. (target branch name)',\n parse: printFlagDeprecation(['-B'], ['--branch']),\n }),\n 'config-file': flags.string({\n description: '[optional] Path of the JSON configuration file.',\n }),\n config: flags.string({\n description: '[optional] Inline configuration, <key1>:<value1>. Passing an external configuration makes the script re-usable.',\n multiple: true,\n }),\n multiple: flags.boolean({\n description: 'This flag helps you to migrate multiple content files in a single instance. Mention the folder path where your migration script files are stored.',\n }),\n\n // To be deprecated\n 'api-key': flags.string({\n char: 'k',\n description: 'With this flag add the API key of your stack.',\n // dependsOn: ['authtoken'],\n exclusive: ['alias'],\n parse: printFlagDeprecation(['--api-key'], ['-k', '--stack-api-key']),\n hidden: true,\n }),\n authtoken: flags.boolean({\n char: 'A',\n description: 'Use this flag to use the auth token of the current session. After logging in CLI, an auth token is generated for each new session.',\n dependsOn: ['api-key'],\n exclusive: ['alias'],\n parse: printFlagDeprecation(['-A', '--authtoken']),\n hidden: true,\n }),\n 'management-token-alias': flags.string({\n description: 'Alias of the management token.',\n exclusive: ['authtoken'],\n hidden: true,\n parse: printFlagDeprecation(['--management-token-alias'], ['-a', '--alias']),\n }),\n filePath: flags.string({\n char: 'n',\n description: 'Use this flag to provide the path of the file of the migration script provided by the user.',\n parse: printFlagDeprecation(['-n', '--filePath'], ['--file-path']),\n hidden: true,\n }),\n multi: flags.boolean({\n description: 'This flag helps you to migrate multiple content files in a single instance.',\n parse: printFlagDeprecation(['--multi'], ['--multiple']),\n hidden: true,\n }),\n };\n\n static aliases: string[] = ['cm:migration'];\n\n static usage: string =\n 'cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>] [--config <value>] [--multiple]';\n\n async run(): Promise<void> {\n // TODO: filePath validation required.\n const { flags: migrationCommandFlags } = await this.parse(MigrationCommand) as any;\n const branch = (migrationCommandFlags as any).branch;\n const filePath = (migrationCommandFlags as any)['file-path'] || (migrationCommandFlags as any).filePath;\n const multi = (migrationCommandFlags as any).multiple || (migrationCommandFlags as any).multi;\n const authtoken = isAuthenticated();\n const apiKey = (migrationCommandFlags as any)['api-key'] || (migrationCommandFlags as any)['stack-api-key'];\n const alias = (migrationCommandFlags as any)['alias'] || (migrationCommandFlags as any)['management-token-alias'];\n const config = (migrationCommandFlags as any)['config'];\n\n if (!authtoken && !alias) {\n this.log(\n \"AuthToken is not present in local drive, Hence use 'csdx auth:login' command for login or provide management token alias\",\n );\n this.exit();\n }\n\n if (!filePath || !fs.existsSync(filePath)) {\n this.log('Please provide the migration script file path, use --file-path flag');\n this.exit();\n }\n\n // Reset map instance\n const mapInstance = getMapInstance();\n resetMapInstance(mapInstance);\n if (migrationCommandFlags['config-file']) {\n set('config-path', mapInstance, migrationCommandFlags['config-file']);\n }\n\n if (Array.isArray(config) && config.length > 0) {\n let configObj = (config as string[]).reduce((a: any, v: string) => {\n //NOTE: Temp code to handle only one spilt(Window absolute path issue).Need to replace with hardcoded config key\n let [key, ...value] = v.split(':');\n const joinedValue = value?.length > 1 ? value?.join(':') : value?.join();\n return { ...a, [key]: joinedValue };\n }, {});\n set('config', mapInstance, configObj);\n }\n\n const APIClient = await managementSDKClient({ host: this.cmaHost });\n let stackSDKInstance: any;\n if (branch) {\n set(BRANCH, mapInstance, branch);\n }\n\n if (alias) {\n let managementToken = this.getToken(alias);\n if (managementToken) {\n set(MANAGEMENT_TOKEN, mapInstance, managementToken);\n set(API_KEY, mapInstance, managementToken.apiKey);\n if (branch) {\n stackSDKInstance = APIClient.stack({\n management_token: managementToken.token,\n api_key: managementToken.apiKey,\n branch_uid: branch,\n });\n } else {\n stackSDKInstance = APIClient.stack({\n management_token: managementToken.token,\n api_key: managementToken.apiKey,\n });\n }\n }\n } else if (authtoken) {\n set(AUTH_TOKEN, mapInstance, authtoken);\n set(API_KEY, mapInstance, apiKey);\n if (branch) {\n stackSDKInstance = APIClient.stack({\n api_key: apiKey,\n branch_uid: branch,\n });\n } else {\n stackSDKInstance = APIClient.stack({ api_key: apiKey });\n }\n }\n\n set(MANAGEMENT_SDK, mapInstance, stackSDKInstance);\n set(MANAGEMENT_CLIENT, mapInstance, APIClient);\n\n if (!(await installModules(filePath, multi))) {\n this.log(`Error: Failed to install dependencies for the specified scripts.`);\n process.exit(1);\n }\n\n if (multi) {\n await this.execMultiFiles(filePath, mapInstance);\n } else {\n await this.execSingleFile(filePath, mapInstance);\n }\n const errLogPath = `${process.cwd()}/migration-logs`;\n if (fs.existsSync(errLogPath)) {\n this.log(`The log has been stored at: `, errLogPath);\n }\n }\n\n async execSingleFile(filePath: string, mapInstance: Map<string, any>): Promise<void> {\n // Resolved absolute path\n const resolvedMigrationPath = pathValidator(filePath);\n // User provided migration function - dynamic require for JS migration scripts\n const migrationFunc = require(resolvedMigrationPath);\n\n const parser = new Parser();\n\n try {\n const migrationParser = await parser.getMigrationParser(migrationFunc);\n if (migrationParser.hasErrors) {\n errorHelper(migrationParser.hasErrors);\n // When the process is child, send error message to parent\n if (process.send) process.send({ errorOccurred: true });\n this.exit(1);\n }\n\n // Make calls from here\n const requests = get(_requests, mapInstance);\n // Fetches tasks array\n const tasks = this.getTasks(requests);\n\n const listr = new Listr(tasks);\n\n await listr.run();\n requests.splice(0, requests.length);\n } catch (error) {\n errorHelper(error, filePath);\n if (process.send) process.send({ errorOccurred: true });\n }\n }\n\n async execMultiFiles(filePath: string, mapInstance: Map<string, any>): Promise<void> {\n // Resolved absolute path\n const resolvedMigrationPath = pathValidator(filePath);\n try {\n const files = fs.readdirSync(resolvedMigrationPath);\n for (const element of files) {\n const file = element;\n if (extname(file) === '.js') {\n // eslint-disable-next-line no-await-in-loop\n await this.execSingleFile(pathValidator(resolve(sanitizePath(filePath), sanitizePath(file))), mapInstance);\n }\n }\n } catch (error) {\n errorHelper(error);\n }\n }\n\n getTasks(requests: any[]): any[] {\n const _tasks: any[] = [];\n const results: any[] = [];\n\n const taskFn = (reqObj: any) => {\n const { failedTitle, successTitle, tasks } = reqObj;\n\n return async (ctx: any, task: any) => {\n const [err, result] = await safePromise(waterfall(tasks));\n if (err) {\n ctx.error = true;\n task.title = failedTitle;\n throw err;\n }\n result && results.push(result);\n task.title = successTitle;\n return result;\n };\n };\n\n for (const element of requests) {\n let reqObj = element;\n const { title } = reqObj;\n const taskObj = {\n title: title,\n task: taskFn(reqObj),\n };\n _tasks.push(taskObj);\n }\n return _tasks;\n }\n\n handleErrors(): void {\n const mapInstance = getMapInstance();\n const actions = get(actionMapper, mapInstance);\n const actionList = new ActionList(actions);\n\n actionList.addValidators(new ApiError());\n actionList.addValidators(new SchemaValidator());\n actionList.addValidators(new MigrationError());\n actionList.addValidators(new FieldValidator());\n\n const errors = actionList.validate();\n errorHelper(errors);\n }\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable camelcase */
|
|
4
|
+
const { CONTENTSTACK_API_KEY, CONTENTSTACK_AUTHTOKEN } = process.env;
|
|
5
|
+
const { version } = require('../../package.json');
|
|
6
|
+
exports.default = {
|
|
7
|
+
hostname: 'api.contentstack.io',
|
|
8
|
+
version: '/v3',
|
|
9
|
+
method: 'GET',
|
|
10
|
+
headers: {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
'Content-Length': null,
|
|
13
|
+
'X-User-Agent': `@contentstack-migration/v${version}`,
|
|
14
|
+
authtoken: CONTENTSTACK_AUTHTOKEN,
|
|
15
|
+
api_key: CONTENTSTACK_API_KEY,
|
|
16
|
+
// management_token: CONTENTSTACK_MANAGEMENT_TOKEN
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=api-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-config.js","sourceRoot":"","sources":["../../src/config/api-config.ts"],"names":[],"mappings":";;AAAA,8BAA8B;AAC9B,MAAM,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AACrE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElD,kBAAe;IACb,QAAQ,EAAE,qBAAqB;IAC/B,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,KAAK;IACb,OAAO,EAAE;QACP,cAAc,EAAE,kBAAkB;QAClC,gBAAgB,EAAE,IAAI;QACtB,cAAc,EAAE,4BAA4B,OAAO,EAAE;QACrD,SAAS,EAAE,sBAAsB;QACjC,OAAO,EAAE,oBAAoB;QAC7B,kDAAkD;KACnD;CACF,CAAC","sourcesContent":["/* eslint-disable camelcase */\nconst { CONTENTSTACK_API_KEY, CONTENTSTACK_AUTHTOKEN } = process.env;\nconst { version } = require('../../package.json');\n\nexport default {\n hostname: 'api.contentstack.io',\n version: '/v3',\n method: 'GET', // Default Http method\n headers: {\n 'Content-Type': 'application/json',\n 'Content-Length': null,\n 'X-User-Agent': `@contentstack-migration/v${version}`,\n authtoken: CONTENTSTACK_AUTHTOKEN,\n api_key: CONTENTSTACK_API_KEY,\n // management_token: CONTENTSTACK_MANAGEMENT_TOKEN\n },\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-options.js","sourceRoot":"","sources":["../../src/config/default-options.ts"],"names":[],"mappings":";AAAA,8BAA8B;;AAE9B,kBAAe;IACb,OAAO,EAAE,KAAK;IACd,SAAS,EAAE,KAAK;CACjB,CAAC","sourcesContent":["/* eslint-disable camelcase */\n\nexport default {\n is_page: false,\n singleton: false,\n};\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.masterLocale = exports.defaultOptions = exports.apiConfig = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const api_config_1 = tslib_1.__importDefault(require("./api-config"));
|
|
6
|
+
exports.apiConfig = api_config_1.default;
|
|
7
|
+
const default_options_1 = tslib_1.__importDefault(require("./default-options"));
|
|
8
|
+
exports.defaultOptions = default_options_1.default;
|
|
9
|
+
const master_locale_1 = tslib_1.__importDefault(require("./master-locale"));
|
|
10
|
+
exports.masterLocale = master_locale_1.default;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;;AAAA,sEAAqC;AAI5B,oBAJF,oBAAS,CAIE;AAHlB,gFAA+C;AAG3B,yBAHb,yBAAc,CAGa;AAFlC,4EAA2C;AAEP,uBAF7B,uBAAY,CAE6B","sourcesContent":["import apiConfig from './api-config';\nimport defaultOptions from './default-options';\nimport masterLocale from './master-locale';\n\nexport { apiConfig, defaultOptions, masterLocale };\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable camelcase */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.default = {
|
|
5
|
+
master_locale: {
|
|
6
|
+
// master locale of the stack
|
|
7
|
+
name: 'English - United States',
|
|
8
|
+
code: 'en-us',
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=master-locale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"master-locale.js","sourceRoot":"","sources":["../../src/config/master-locale.ts"],"names":[],"mappings":";AAAA,8BAA8B;;AAE9B,kBAAe;IACb,aAAa,EAAE;QACb,6BAA6B;QAC7B,IAAI,EAAE,yBAAyB;QAC/B,IAAI,EAAE,OAAO;KACd;CACF,CAAC","sourcesContent":["/* eslint-disable camelcase */\n\nexport default {\n master_locale: {\n // master locale of the stack\n name: 'English - United States',\n code: 'en-us',\n },\n};\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for module classes
|
|
3
|
+
* @class Base
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export default class Base {
|
|
7
|
+
id: string | null;
|
|
8
|
+
action: string | null;
|
|
9
|
+
actions: any[];
|
|
10
|
+
constructor(id?: string, action?: string);
|
|
11
|
+
/**
|
|
12
|
+
* Chained function which takes value for title
|
|
13
|
+
* @param {string} value Title
|
|
14
|
+
* @returns {Base} current instance of inherited class
|
|
15
|
+
*/
|
|
16
|
+
title(value: string): this;
|
|
17
|
+
/**
|
|
18
|
+
* Chained function which takes value for description
|
|
19
|
+
* @param {string} value Description
|
|
20
|
+
* @returns {Base} current instance of inherited class
|
|
21
|
+
*/
|
|
22
|
+
description(value: string): this;
|
|
23
|
+
/**
|
|
24
|
+
* Chained function takes boolean value for force while deleting content type
|
|
25
|
+
* @param {boolean} value Force delete
|
|
26
|
+
* @returns {Base} current instance of inherited class
|
|
27
|
+
*/
|
|
28
|
+
force(value: boolean): this;
|
|
29
|
+
/**
|
|
30
|
+
* Accumulates actions for validating user provided inputs
|
|
31
|
+
* @ignore
|
|
32
|
+
* @param {Object} callsite Gets the file location and file number of caller
|
|
33
|
+
* @param {string} id unique id of action type
|
|
34
|
+
* @param {Object} opts holds payload to be validated
|
|
35
|
+
* @param {string} method type of action
|
|
36
|
+
*/
|
|
37
|
+
dispatch(callsite: any, id: string | null, opts: any, method: string): void;
|
|
38
|
+
getActions(): any[];
|
|
39
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Utils
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
// Actions
|
|
6
|
+
const actions_1 = require("../actions");
|
|
7
|
+
// Utils properties
|
|
8
|
+
const { getMapInstance, get } = utils_1.map;
|
|
9
|
+
const { actionMapper } = utils_1.constants;
|
|
10
|
+
/**
|
|
11
|
+
* Base class for module classes
|
|
12
|
+
* @class Base
|
|
13
|
+
* @ignore
|
|
14
|
+
*/
|
|
15
|
+
class Base {
|
|
16
|
+
constructor(id, action) {
|
|
17
|
+
this.id = id || null;
|
|
18
|
+
this.action = action || null;
|
|
19
|
+
this.actions = [];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Chained function which takes value for title
|
|
23
|
+
* @param {string} value Title
|
|
24
|
+
* @returns {Base} current instance of inherited class
|
|
25
|
+
*/
|
|
26
|
+
title(value) {
|
|
27
|
+
const mapInstance = getMapInstance();
|
|
28
|
+
const { id, action } = this;
|
|
29
|
+
const contentType = get(id, mapInstance);
|
|
30
|
+
contentType[action].content_type.title = value;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Chained function which takes value for description
|
|
35
|
+
* @param {string} value Description
|
|
36
|
+
* @returns {Base} current instance of inherited class
|
|
37
|
+
*/
|
|
38
|
+
description(value) {
|
|
39
|
+
const mapInstance = getMapInstance();
|
|
40
|
+
const { id, action } = this;
|
|
41
|
+
const contentType = get(id, mapInstance);
|
|
42
|
+
contentType[action].content_type.description = value;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Chained function takes boolean value for force while deleting content type
|
|
47
|
+
* @param {boolean} value Force delete
|
|
48
|
+
* @returns {Base} current instance of inherited class
|
|
49
|
+
*/
|
|
50
|
+
force(value) {
|
|
51
|
+
const mapInstance = getMapInstance();
|
|
52
|
+
const { id, action } = this;
|
|
53
|
+
const contentType = get(id, mapInstance);
|
|
54
|
+
contentType[action].content_type.force = value;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Accumulates actions for validating user provided inputs
|
|
59
|
+
* @ignore
|
|
60
|
+
* @param {Object} callsite Gets the file location and file number of caller
|
|
61
|
+
* @param {string} id unique id of action type
|
|
62
|
+
* @param {Object} opts holds payload to be validated
|
|
63
|
+
* @param {string} method type of action
|
|
64
|
+
*/
|
|
65
|
+
dispatch(callsite, id, opts, method) {
|
|
66
|
+
if (!id && !opts) {
|
|
67
|
+
let mapInstance = getMapInstance();
|
|
68
|
+
let actions = get(actionMapper, mapInstance); // Returns an array if empty
|
|
69
|
+
let action = actions_1.actionCreators.customTasks(callsite, opts);
|
|
70
|
+
actions.push(action);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
let mapInstance = getMapInstance();
|
|
74
|
+
let actions = get(actionMapper, mapInstance); // Returns an array if empty
|
|
75
|
+
let action = actions_1.actionCreators.contentType[method](callsite, id, Object.assign(Object.assign({}, opts), { id }));
|
|
76
|
+
actions.push(action);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
getActions() {
|
|
80
|
+
return this.actions;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.default = Base;
|
|
84
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/modules/base.ts"],"names":[],"mappings":";;AAAA,QAAQ;AACR,oCAAkD;AAClD,UAAU;AACV,wCAA4C;AAC5C,mBAAmB;AACnB,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG,WAAI,CAAC;AACrC,MAAM,EAAE,YAAY,EAAE,GAAG,iBAAS,CAAC;AAEnC;;;;GAIG;AACH,MAAqB,IAAI;IAKvB,YAAY,EAAW,EAAE,MAAe;QACtC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,IAAI,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAa;QACjB,MAAM,WA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YACxD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SACtB;aAAM;YACL,IAAI,WAAW,GAAG,cAAc,EAAE,CAAC;YACnC,IAAI,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,4BAA4B;YAC1E,IAAI,MAAM,GAAI,wBAAc,CAAC,WAAmB,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAY,kCAAO,IAAI,KAAE,EAAE,IAAG,CAAC;YAClG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SACtB;IACH,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAjFD,uBAiFC","sourcesContent":["// Utils\nimport { map as _map, constants } from '../utils';\n// Actions\nimport { actionCreators } from '../actions';\n// Utils properties\nconst { getMapInstance, get } = _map;\nconst { actionMapper } = constants;\n\n/**\n * Base class for module classes\n * @class Base\n * @ignore\n */\nexport default class Base {\n id: string | null;\n action: string | null;\n actions: any[];\n\n constructor(id?: string, action?: string) {\n this.id = id || null;\n this.action = action || null;\n this.actions = [];\n }\n\n /**\n * Chained function which takes value for title\n * @param {string} value Title\n * @returns {Base} current instance of inherited class\n */\n title(value: string): this {\n const mapInstance = getMapInstance();\n const { id, action } = this;\n\n const contentType = get(id as string, mapInstance);\n\n contentType[action as string].content_type.title = value;\n\n return this;\n }\n\n /**\n * Chained function which takes value for description\n * @param {string} value Description\n * @returns {Base} current instance of inherited class\n */\n description(value: string): this {\n const mapInstance = getMapInstance();\n const { id, action } = this;\n const contentType = get(id as string, mapInstance);\n contentType[action as string].content_type.description = value;\n return this;\n }\n\n /**\n * Chained function takes boolean value for force while deleting content type\n * @param {boolean} value Force delete\n * @returns {Base} current instance of inherited class\n */\n force(value: boolean): this {\n const mapInstance = getMapInstance();\n const { id, action } = this;\n\n const contentType = get(id as string, mapInstance);\n\n contentType[action as string].content_type.force = value;\n\n return this;\n }\n\n /**\n * Accumulates actions for validating user provided inputs\n * @ignore\n * @param {Object} callsite Gets the file location and file number of caller\n * @param {string} id unique id of action type\n * @param {Object} opts holds payload to be validated\n * @param {string} method type of action\n */\n dispatch(callsite: any, id: string | null, opts: any, method: string): void {\n if (!id && !opts) {\n let mapInstance = getMapInstance();\n let actions = get(actionMapper, mapInstance); // Returns an array if empty\n let action = actionCreators.customTasks(callsite, opts);\n actions.push(action);\n } else {\n let mapInstance = getMapInstance();\n let actions = get(actionMapper, mapInstance); // Returns an array if empty\n let action = (actionCreators.contentType as any)[method](callsite, id as string, { ...opts, id });\n actions.push(action);\n }\n }\n\n getActions(): any[] {\n return this.actions;\n }\n}\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import Field from './fields';
|
|
2
|
+
import { ContentTypeService } from '../services';
|
|
3
|
+
import Base from './base';
|
|
4
|
+
/**
|
|
5
|
+
* ContentType class
|
|
6
|
+
* @class ContentType
|
|
7
|
+
* @augments Base
|
|
8
|
+
*/
|
|
9
|
+
export default class ContentType extends Base {
|
|
10
|
+
contentTypeService: ContentTypeService;
|
|
11
|
+
constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Creates content type by passing content type name and options
|
|
14
|
+
* @param {string} id Content type UID
|
|
15
|
+
* @param {Object} opts Optional: Content type fields definition
|
|
16
|
+
* @returns {Field} instance of Field
|
|
17
|
+
* @example
|
|
18
|
+
* module.exports = ({migration}) => {
|
|
19
|
+
* const blog = migration
|
|
20
|
+
* .createContentType('blog')
|
|
21
|
+
* .title('blog title')
|
|
22
|
+
* .description('blog 1')
|
|
23
|
+
* blog.createField('title').display_name('Title').data_type('text').mandatory(true);
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
26
|
+
createContentType(id: string, opts?: any): Field;
|
|
27
|
+
/**
|
|
28
|
+
* Set content type to singleton or multiple
|
|
29
|
+
* @param {boolean} value set value true to set content type as singleton default it is multiple
|
|
30
|
+
* @returns {ContentType} instance of ContentType for chaining
|
|
31
|
+
*/
|
|
32
|
+
singleton(value: boolean): this;
|
|
33
|
+
/**
|
|
34
|
+
* Set content type to singleton or multiple
|
|
35
|
+
* @param {boolean} value set value false to set content type as content as block default true
|
|
36
|
+
* @returns {ContentType} instance of ContentType for chaining
|
|
37
|
+
*/
|
|
38
|
+
isPage(value: boolean): this;
|
|
39
|
+
/**
|
|
40
|
+
* Edits content type by passing content type name and options
|
|
41
|
+
* @param {string} id Content type UID
|
|
42
|
+
* @param {Object} opts Optional: Content type fields definition
|
|
43
|
+
* @returns {Field} instance of Field
|
|
44
|
+
* @example
|
|
45
|
+
* module.exports = ({migration}) => {
|
|
46
|
+
* const blog = migration.editContentType('blog');
|
|
47
|
+
* blog.description('Changed description');
|
|
48
|
+
* }
|
|
49
|
+
*/
|
|
50
|
+
editContentType(id: string, opts?: any): Field;
|
|
51
|
+
/**
|
|
52
|
+
* Deletes content type by passing content type name
|
|
53
|
+
* @param {string} id Content type UID
|
|
54
|
+
* @returns {Field} instance of Field
|
|
55
|
+
* @example
|
|
56
|
+
* module.exports = {migrations} => {
|
|
57
|
+
* const blog = migrations.deleteContentType('blog');
|
|
58
|
+
* }
|
|
59
|
+
*/
|
|
60
|
+
deleteContentType(id: string): Field;
|
|
61
|
+
}
|