@contentstack/cli-cm-export 1.5.8 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +2 -2
  2. package/lib/commands/cm/stacks/export.d.ts +10 -0
  3. package/lib/commands/cm/stacks/export.js +108 -0
  4. package/lib/config/index.d.ts +3 -0
  5. package/lib/config/index.js +393 -0
  6. package/lib/export/index.d.ts +1 -0
  7. package/lib/export/index.js +8 -0
  8. package/lib/export/module-exporter.d.ts +15 -0
  9. package/lib/export/module-exporter.js +93 -0
  10. package/lib/export/modules/assets.d.ts +54 -0
  11. package/lib/export/modules/assets.js +303 -0
  12. package/lib/export/modules/base-class.d.ts +48 -0
  13. package/lib/export/modules/base-class.js +117 -0
  14. package/lib/export/modules/index.d.ts +3 -0
  15. package/lib/export/modules/index.js +38 -0
  16. package/lib/export/modules/locales.d.ts +16 -0
  17. package/lib/export/modules/locales.js +68 -0
  18. package/lib/export/modules-js/assets.d.ts +43 -0
  19. package/lib/export/modules-js/assets.js +391 -0
  20. package/lib/export/modules-js/content-types.d.ts +21 -0
  21. package/lib/export/modules-js/content-types.js +75 -0
  22. package/lib/export/modules-js/custom-roles.d.ts +21 -0
  23. package/lib/export/modules-js/custom-roles.js +76 -0
  24. package/lib/export/modules-js/entries.d.ts +18 -0
  25. package/lib/export/modules-js/entries.js +141 -0
  26. package/lib/export/modules-js/environments.d.ts +16 -0
  27. package/lib/export/modules-js/environments.js +62 -0
  28. package/lib/export/modules-js/extensions.d.ts +18 -0
  29. package/lib/export/modules-js/extensions.js +57 -0
  30. package/lib/export/modules-js/global-fields.d.ts +22 -0
  31. package/lib/export/modules-js/global-fields.js +107 -0
  32. package/lib/export/modules-js/index.d.ts +1 -0
  33. package/lib/export/modules-js/index.js +33 -0
  34. package/lib/export/modules-js/labels.d.ts +14 -0
  35. package/lib/export/modules-js/labels.js +56 -0
  36. package/lib/export/modules-js/locales.d.ts +23 -0
  37. package/lib/export/modules-js/locales.js +67 -0
  38. package/lib/export/modules-js/marketplace-apps.d.ts +21 -0
  39. package/lib/export/modules-js/marketplace-apps.js +144 -0
  40. package/lib/export/modules-js/stack.d.ts +18 -0
  41. package/lib/export/modules-js/stack.js +91 -0
  42. package/lib/export/modules-js/webhooks.d.ts +18 -0
  43. package/lib/export/modules-js/webhooks.js +60 -0
  44. package/lib/export/modules-js/workflows.d.ts +16 -0
  45. package/lib/export/modules-js/workflows.js +89 -0
  46. package/lib/types/default-config.d.ts +158 -0
  47. package/lib/types/default-config.js +2 -0
  48. package/lib/types/export-config.d.ts +34 -0
  49. package/lib/types/export-config.js +2 -0
  50. package/lib/types/index.d.ts +45 -0
  51. package/lib/types/index.js +2 -0
  52. package/lib/utils/basic-login.d.ts +8 -0
  53. package/lib/utils/basic-login.js +45 -0
  54. package/lib/utils/common-helper.d.ts +11 -0
  55. package/lib/utils/common-helper.js +78 -0
  56. package/lib/utils/export-config-handler.d.ts +3 -0
  57. package/lib/utils/export-config-handler.js +72 -0
  58. package/lib/utils/file-helper.d.ts +14 -0
  59. package/lib/utils/file-helper.js +120 -0
  60. package/lib/utils/index.d.ts +10 -0
  61. package/lib/utils/index.js +21 -0
  62. package/lib/utils/interactive.d.ts +6 -0
  63. package/lib/utils/interactive.js +71 -0
  64. package/lib/utils/logger.d.ts +8 -0
  65. package/lib/utils/logger.js +154 -0
  66. package/lib/utils/marketplace-app-helper.d.ts +1 -0
  67. package/lib/utils/marketplace-app-helper.js +23 -0
  68. package/lib/utils/setup-branches.d.ts +3 -0
  69. package/lib/utils/setup-branches.js +49 -0
  70. package/lib/utils/setup-export-dir.d.ts +2 -0
  71. package/lib/utils/setup-export-dir.js +12 -0
  72. package/messages/index.json +1 -7
  73. package/oclif.manifest.json +1 -1
  74. package/package.json +37 -23
  75. package/src/app.js +0 -161
  76. package/src/commands/cm/stacks/export.js +0 -202
  77. package/src/config/default.js +0 -360
  78. package/src/lib/export/assets.js +0 -451
  79. package/src/lib/export/content-types.js +0 -90
  80. package/src/lib/export/custom-roles.js +0 -93
  81. package/src/lib/export/entries.js +0 -200
  82. package/src/lib/export/environments.js +0 -74
  83. package/src/lib/export/extensions.js +0 -69
  84. package/src/lib/export/global-fields.js +0 -122
  85. package/src/lib/export/labels.js +0 -69
  86. package/src/lib/export/locales.js +0 -72
  87. package/src/lib/export/marketplace-apps.js +0 -184
  88. package/src/lib/export/stack.js +0 -99
  89. package/src/lib/export/webhooks.js +0 -76
  90. package/src/lib/export/workflows.js +0 -110
  91. package/src/lib/util/export-flags.js +0 -193
  92. package/src/lib/util/helper.js +0 -113
  93. package/src/lib/util/index.js +0 -80
  94. package/src/lib/util/log.js +0 -158
  95. package/src/lib/util/login.js +0 -79
  96. package/src/lib/util/marketplace-app-helper.js +0 -24
  97. package/src/lib/util/setup-branches.js +0 -56
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Contentstack Import
3
+ * Copyright (c) 2019 Contentstack LLC
4
+ * MIT Licensed
5
+ */
6
+ import { ExternalConfig } from '../types';
7
+ declare const login: (config: ExternalConfig) => Promise<any>;
8
+ export default login;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /* eslint-disable max-statements-per-line */
3
+ /* eslint-disable no-console */
4
+ /* eslint-disable no-empty */
5
+ /*!
6
+ * Contentstack Import
7
+ * Copyright (c) 2019 Contentstack LLC
8
+ * MIT Licensed
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ const logger_1 = require("./logger");
12
+ const { managementSDKClient, isAuthenticated, cliux, configHandler, authHandler, } = require('@contentstack/cli-utilities');
13
+ const login = async (config) => {
14
+ var _a;
15
+ const client = await managementSDKClient(config);
16
+ if (config.email && config.password) {
17
+ const response = await client.login({ email: config.email, password: config.password }).catch(Promise.reject);
18
+ if ((_a = response === null || response === void 0 ? void 0 : response.user) === null || _a === void 0 ? void 0 : _a.authtoken) {
19
+ config.headers = {
20
+ api_key: config.source_stack,
21
+ access_token: config.access_token,
22
+ authtoken: response.user.authtoken,
23
+ 'X-User-Agent': 'contentstack-export/v',
24
+ };
25
+ await authHandler.setConfigData('basicAuth', response.user);
26
+ (0, logger_1.log)(config, 'Contentstack account authenticated successfully!', 'success');
27
+ return config;
28
+ }
29
+ else {
30
+ (0, logger_1.log)(config, 'Failed to login, Invalid credentials', 'error');
31
+ process.exit(1);
32
+ }
33
+ }
34
+ else if (!config.email && !config.password && config.source_stack && config.access_token) {
35
+ (0, logger_1.log)(config, 'Content types, entries, assets, labels, global fields, extensions modules will be exported', 'success');
36
+ (0, logger_1.log)(config, 'Email, password, or management token is not set in the config, cannot export Webhook and label modules', 'success');
37
+ config.headers = {
38
+ api_key: config.source_stack,
39
+ access_token: config.access_token,
40
+ 'X-User-Agent': 'contentstack-export/v',
41
+ };
42
+ return config;
43
+ }
44
+ };
45
+ exports.default = login;
@@ -0,0 +1,11 @@
1
+ /*!
2
+ * Contentstack Export
3
+ * Copyright (c) 2019 Contentstack LLC
4
+ * MIT Licensed
5
+ */
6
+ import { ExternalConfig } from '../types';
7
+ export declare const validateConfig: (config: ExternalConfig) => void;
8
+ export declare const formatError: (error: any) => any;
9
+ export declare const executeTask: (tasks: unknown[], handler: (task: unknown) => Promise<unknown>, options: {
10
+ concurrency: number;
11
+ }) => Promise<unknown[]>;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /*!
3
+ * Contentstack Export
4
+ * Copyright (c) 2019 Contentstack LLC
5
+ * MIT Licensed
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.executeTask = exports.formatError = exports.validateConfig = void 0;
9
+ const tslib_1 = require("tslib");
10
+ const promise_limit_1 = tslib_1.__importDefault(require("promise-limit"));
11
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
12
+ const validateConfig = function (config) {
13
+ if (!config.host || !config.cdn) {
14
+ throw new Error('Host/CDN end point is missing from config');
15
+ }
16
+ if (config.email && config.password && !config.access_token && !config.source_stack) {
17
+ throw new Error('Kindly provide access_token or api_token');
18
+ }
19
+ else if (!config.email &&
20
+ !config.password &&
21
+ !config.management_token &&
22
+ config.source_stack &&
23
+ !config.access_token &&
24
+ !(0, cli_utilities_1.isAuthenticated)()) {
25
+ throw new Error('Kindly provide management_token or email and password');
26
+ }
27
+ else if (config.email &&
28
+ config.password &&
29
+ !config.access_token &&
30
+ config.source_stack &&
31
+ !config.management_token &&
32
+ !(0, cli_utilities_1.isAuthenticated)()) {
33
+ throw new Error('Kindly provide access_token or management_token');
34
+ }
35
+ else if (!config.email && !config.password && config.preserveStackVersion) {
36
+ throw new Error('Kindly provide Email and password for stack details');
37
+ }
38
+ };
39
+ exports.validateConfig = validateConfig;
40
+ const formatError = function (error) {
41
+ try {
42
+ if (typeof error === 'string') {
43
+ error = JSON.parse(error);
44
+ }
45
+ else {
46
+ error = JSON.parse(error.message);
47
+ }
48
+ }
49
+ catch (e) { }
50
+ let message = error.errorMessage || error.error_message || error.message || error;
51
+ if (error.errors && Object.keys(error.errors).length > 0) {
52
+ Object.keys(error.errors).forEach((e) => {
53
+ let entity = e;
54
+ if (e === 'authorization')
55
+ entity = 'Management Token';
56
+ if (e === 'api_key')
57
+ entity = 'Stack API key';
58
+ if (e === 'uid')
59
+ entity = 'Content Type';
60
+ if (e === 'access_token')
61
+ entity = 'Delivery Token';
62
+ message += ' ' + [entity, error.errors[e]].join(' ');
63
+ });
64
+ }
65
+ return message;
66
+ };
67
+ exports.formatError = formatError;
68
+ const executeTask = function (tasks = [], handler, options) {
69
+ if (typeof handler !== 'function') {
70
+ throw new Error('Invalid handler');
71
+ }
72
+ const { concurrency = 1 } = options;
73
+ const limit = (0, promise_limit_1.default)(concurrency);
74
+ return Promise.all(tasks.map((task) => {
75
+ return limit(() => handler(task));
76
+ }));
77
+ };
78
+ exports.executeTask = executeTask;
@@ -0,0 +1,3 @@
1
+ import { ExportConfig } from '../types';
2
+ declare const setupConfig: (exportCmdFlags: any) => Promise<ExportConfig>;
3
+ export default setupConfig;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const merge_1 = tslib_1.__importDefault(require("merge"));
5
+ const path = tslib_1.__importStar(require("path"));
6
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
7
+ const config_1 = tslib_1.__importDefault(require("../config"));
8
+ const file_helper_1 = require("./file-helper");
9
+ const interactive_1 = require("./interactive");
10
+ const basic_login_1 = tslib_1.__importDefault(require("./basic-login"));
11
+ const lodash_1 = require("lodash");
12
+ const setupConfig = async (exportCmdFlags) => {
13
+ let config = (0, merge_1.default)({}, config_1.default);
14
+ // setup the config
15
+ if (exportCmdFlags['config']) {
16
+ const externalConfig = await (0, file_helper_1.readFile)(exportCmdFlags['config']);
17
+ config = merge_1.default.recursive(config, externalConfig);
18
+ }
19
+ config.exportDir = exportCmdFlags['data'] || exportCmdFlags['data-dir'] || config.data || (await (0, interactive_1.askExportDir)());
20
+ config.exportDir = path.resolve(config.exportDir);
21
+ //Note to support the old key
22
+ config.data = config.exportDir;
23
+ const managementTokenAlias = exportCmdFlags['management-token-alias'] || exportCmdFlags['alias'];
24
+ if (managementTokenAlias) {
25
+ const { token, apiKey } = cli_utilities_1.configHandler.get(`tokens.${managementTokenAlias}`);
26
+ config.management_token = token;
27
+ config.apiKey = apiKey;
28
+ if (!config.management_token) {
29
+ throw new Error(`No management token found on given alias ${managementTokenAlias}`);
30
+ }
31
+ }
32
+ if (!config.management_token) {
33
+ if (!(0, cli_utilities_1.isAuthenticated)()) {
34
+ if (config.username && config.password) {
35
+ await (0, basic_login_1.default)(config);
36
+ }
37
+ else {
38
+ throw new Error('Please login or provide an alias for the management token');
39
+ }
40
+ }
41
+ else {
42
+ config.apiKey =
43
+ exportCmdFlags['stack-uid'] || exportCmdFlags['stack-api-key'] || config.source_stack || (await (0, interactive_1.askAPIKey)());
44
+ if (typeof config.apiKey !== 'string') {
45
+ throw new Error('Invalid API key received');
46
+ }
47
+ }
48
+ }
49
+ // Note support old config
50
+ config.source_stack = config.apiKey;
51
+ config.forceStopMarketplaceAppsPrompt = exportCmdFlags.yes;
52
+ config.auth_token = cli_utilities_1.configHandler.get('authtoken'); // TBD remove once dependent modules are updated
53
+ config.isAuthenticated = (0, cli_utilities_1.isAuthenticated)();
54
+ if (exportCmdFlags['branch']) {
55
+ config.branchName = exportCmdFlags['branch'];
56
+ }
57
+ if (exportCmdFlags['module']) {
58
+ config.moduleName = exportCmdFlags['module'];
59
+ config.singleModuleExport = true;
60
+ }
61
+ if (exportCmdFlags['secured-assets']) {
62
+ config.securedAssets = true;
63
+ }
64
+ if (Array.isArray(exportCmdFlags['content-types']) && exportCmdFlags['content-types'].length > 0) {
65
+ config.contentTypes = exportCmdFlags['content-types'];
66
+ }
67
+ if (Array.isArray(config.filteredModules) && config.filteredModules.length > 0) {
68
+ config.modules.types = (0, lodash_1.filter)(config_1.default.modules.types, (module) => (0, lodash_1.includes)(config.filteredModules, module));
69
+ }
70
+ return config;
71
+ };
72
+ exports.default = setupConfig;
@@ -0,0 +1,14 @@
1
+ import { FsUtility } from '@contentstack/cli-utilities';
2
+ export declare const readFileSync: (filePath: string, parse: boolean) => unknown;
3
+ export declare const readFile: (filePath: string, options?: {
4
+ type: string;
5
+ }) => Promise<any>;
6
+ export declare const readLargeFile: (filePath: string, options?: {
7
+ type?: string;
8
+ }) => Promise<any>;
9
+ export declare const writeFileSync: (filePath: string, data: any) => void;
10
+ export declare const writeFile: (filePath: string, data: any) => Promise<any>;
11
+ export declare const writeLargeFile: (filePath: string, data: any) => Promise<any>;
12
+ export declare const makeDirectory: (dir: string) => void;
13
+ export declare const readdir: (dirPath: string) => any;
14
+ export declare const fsUtil: FsUtility;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fsUtil = exports.readdir = exports.makeDirectory = exports.writeLargeFile = exports.writeFile = exports.writeFileSync = exports.readLargeFile = exports.readFile = exports.readFileSync = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const path = tslib_1.__importStar(require("path"));
7
+ const mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
8
+ const big_json_1 = tslib_1.__importDefault(require("big-json"));
9
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
10
+ const readFileSync = function (filePath, parse) {
11
+ let data;
12
+ parse = typeof parse === 'undefined' ? true : parse;
13
+ filePath = path.resolve(filePath);
14
+ if (fs.existsSync(filePath)) {
15
+ data = parse ? JSON.parse(fs.readFileSync(filePath, 'utf8')) : data;
16
+ }
17
+ return data;
18
+ };
19
+ exports.readFileSync = readFileSync;
20
+ // by default file type is json
21
+ const readFile = async (filePath, options = { type: 'json' }) => {
22
+ return new Promise((resolve, reject) => {
23
+ filePath = path.resolve(filePath);
24
+ fs.readFile(filePath, 'utf-8', (error, data) => {
25
+ if (error) {
26
+ reject(error);
27
+ }
28
+ else {
29
+ if (options.type !== 'json') {
30
+ return resolve(data);
31
+ }
32
+ resolve(JSON.parse(data));
33
+ }
34
+ });
35
+ });
36
+ };
37
+ exports.readFile = readFile;
38
+ const readLargeFile = function (filePath, options = {}) {
39
+ if (typeof filePath !== 'string') {
40
+ return;
41
+ }
42
+ filePath = path.resolve(filePath);
43
+ if (fs.existsSync(filePath)) {
44
+ return new Promise((resolve, reject) => {
45
+ const readStream = fs.createReadStream(filePath, { encoding: 'utf-8' });
46
+ const parseStream = big_json_1.default.createParseStream();
47
+ parseStream.on('data', function (data) {
48
+ if (options.type === 'array') {
49
+ return resolve(Object.values(data));
50
+ }
51
+ resolve(data);
52
+ });
53
+ parseStream.on('error', (error) => {
54
+ console.log('error', error);
55
+ reject(error);
56
+ });
57
+ readStream.pipe(parseStream);
58
+ });
59
+ }
60
+ };
61
+ exports.readLargeFile = readLargeFile;
62
+ const writeFileSync = function (filePath, data) {
63
+ data = typeof data === 'object' ? JSON.stringify(data) : data || '{}';
64
+ fs.writeFileSync(filePath, data);
65
+ };
66
+ exports.writeFileSync = writeFileSync;
67
+ const writeFile = function (filePath, data) {
68
+ return new Promise((resolve, reject) => {
69
+ data = typeof data === 'object' ? JSON.stringify(data) : data || '{}';
70
+ fs.writeFile(filePath, data, (error) => {
71
+ if (error) {
72
+ return reject(error);
73
+ }
74
+ resolve('done');
75
+ });
76
+ });
77
+ };
78
+ exports.writeFile = writeFile;
79
+ const writeLargeFile = function (filePath, data) {
80
+ if (typeof filePath !== 'string' || typeof data !== 'object') {
81
+ return;
82
+ }
83
+ filePath = path.resolve(filePath);
84
+ return new Promise((resolve, reject) => {
85
+ const stringifyStream = big_json_1.default.createStringifyStream({
86
+ body: data,
87
+ });
88
+ var writeStream = fs.createWriteStream(filePath, 'utf-8');
89
+ stringifyStream.pipe(writeStream);
90
+ writeStream.on('finish', () => {
91
+ resolve('');
92
+ });
93
+ writeStream.on('error', (error) => {
94
+ reject(error);
95
+ });
96
+ });
97
+ };
98
+ exports.writeLargeFile = writeLargeFile;
99
+ const makeDirectory = function (dir) {
100
+ for (const key in arguments) {
101
+ const dirname = path.resolve(arguments[key]);
102
+ if (!fs.existsSync(dirname)) {
103
+ mkdirp_1.default.sync(dirname);
104
+ }
105
+ }
106
+ };
107
+ exports.makeDirectory = makeDirectory;
108
+ const readdir = function (dirPath) {
109
+ if (fs.existsSync(dirPath)) {
110
+ return fs.readdirSync(dirPath);
111
+ }
112
+ else {
113
+ return [];
114
+ }
115
+ };
116
+ exports.readdir = readdir;
117
+ exports.fileExistsSync = function (path) {
118
+ return fs.existsSync(path);
119
+ };
120
+ exports.fsUtil = new cli_utilities_1.FsUtility();
@@ -0,0 +1,10 @@
1
+ export * as interactive from './interactive';
2
+ export { default as setupExportConfig } from './export-config-handler';
3
+ export * as fileHelper from './file-helper';
4
+ export { fsUtil } from './file-helper';
5
+ export { default as setupBranches } from './setup-branches';
6
+ export { default as setupExportDir } from './setup-export-dir';
7
+ export { log, unlinkFileLogger } from './logger';
8
+ export { default as login } from './basic-login';
9
+ export * from './common-helper';
10
+ export * from './marketplace-app-helper';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.login = exports.unlinkFileLogger = exports.log = exports.setupExportDir = exports.setupBranches = exports.fsUtil = exports.fileHelper = exports.setupExportConfig = exports.interactive = void 0;
4
+ const tslib_1 = require("tslib");
5
+ exports.interactive = tslib_1.__importStar(require("./interactive"));
6
+ var export_config_handler_1 = require("./export-config-handler");
7
+ Object.defineProperty(exports, "setupExportConfig", { enumerable: true, get: function () { return tslib_1.__importDefault(export_config_handler_1).default; } });
8
+ exports.fileHelper = tslib_1.__importStar(require("./file-helper"));
9
+ var file_helper_1 = require("./file-helper");
10
+ Object.defineProperty(exports, "fsUtil", { enumerable: true, get: function () { return file_helper_1.fsUtil; } });
11
+ var setup_branches_1 = require("./setup-branches");
12
+ Object.defineProperty(exports, "setupBranches", { enumerable: true, get: function () { return tslib_1.__importDefault(setup_branches_1).default; } });
13
+ var setup_export_dir_1 = require("./setup-export-dir");
14
+ Object.defineProperty(exports, "setupExportDir", { enumerable: true, get: function () { return tslib_1.__importDefault(setup_export_dir_1).default; } });
15
+ var logger_1 = require("./logger");
16
+ Object.defineProperty(exports, "log", { enumerable: true, get: function () { return logger_1.log; } });
17
+ Object.defineProperty(exports, "unlinkFileLogger", { enumerable: true, get: function () { return logger_1.unlinkFileLogger; } });
18
+ var basic_login_1 = require("./basic-login");
19
+ Object.defineProperty(exports, "login", { enumerable: true, get: function () { return tslib_1.__importDefault(basic_login_1).default; } });
20
+ tslib_1.__exportStar(require("./common-helper"), exports);
21
+ tslib_1.__exportStar(require("./marketplace-app-helper"), exports);
@@ -0,0 +1,6 @@
1
+ export declare const askPassword: () => Promise<string>;
2
+ export declare const askOTPChannel: () => Promise<string>;
3
+ export declare const askOTP: () => Promise<string>;
4
+ export declare const askUsername: () => Promise<string>;
5
+ export declare const askExportDir: () => Promise<string>;
6
+ export declare const askAPIKey: () => Promise<string>;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.askAPIKey = exports.askExportDir = exports.askUsername = exports.askOTP = exports.askOTPChannel = exports.askPassword = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
6
+ const path = tslib_1.__importStar(require("path"));
7
+ const askPassword = async () => {
8
+ return cli_utilities_1.cliux.inquire({
9
+ type: 'input',
10
+ message: 'CLI_AUTH_LOGIN_ENTER_PASSWORD',
11
+ name: 'password',
12
+ transformer: (pswd) => {
13
+ let pswdMasked = '';
14
+ for (let i = 0; i < pswd.length; i++) {
15
+ pswdMasked += '*';
16
+ }
17
+ return pswdMasked;
18
+ },
19
+ });
20
+ };
21
+ exports.askPassword = askPassword;
22
+ const askOTPChannel = async () => {
23
+ return cli_utilities_1.cliux.inquire({
24
+ type: 'list',
25
+ name: 'otpChannel',
26
+ message: 'CLI_AUTH_LOGIN_ASK_CHANNEL_FOR_OTP',
27
+ choices: [
28
+ { name: 'Authy App', value: 'authy' },
29
+ { name: 'SMS', value: 'sms' },
30
+ ],
31
+ });
32
+ };
33
+ exports.askOTPChannel = askOTPChannel;
34
+ const askOTP = async () => {
35
+ return cli_utilities_1.cliux.inquire({
36
+ type: 'input',
37
+ message: 'CLI_AUTH_LOGIN_ENTER_SECURITY_CODE',
38
+ name: 'tfaToken',
39
+ });
40
+ };
41
+ exports.askOTP = askOTP;
42
+ const askUsername = async () => {
43
+ return cli_utilities_1.cliux.inquire({
44
+ type: 'input',
45
+ message: 'CLI_AUTH_LOGIN_ENTER_EMAIL_ADDRESS',
46
+ name: 'username',
47
+ });
48
+ };
49
+ exports.askUsername = askUsername;
50
+ const askExportDir = async () => {
51
+ const result = await cli_utilities_1.cliux.inquire({
52
+ type: 'input',
53
+ message: 'Enter the path for storing the content: (current folder)',
54
+ name: 'dir',
55
+ });
56
+ if (!result) {
57
+ return process.cwd();
58
+ }
59
+ else {
60
+ return path.resolve(result);
61
+ }
62
+ };
63
+ exports.askExportDir = askExportDir;
64
+ const askAPIKey = async () => {
65
+ return cli_utilities_1.cliux.inquire({
66
+ type: 'input',
67
+ message: 'Enter the stack api key',
68
+ name: 'apiKey',
69
+ });
70
+ };
71
+ exports.askAPIKey = askAPIKey;
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Contentstack Export
3
+ * Copyright (c) 2019 Contentstack LLC
4
+ * MIT Licensed
5
+ */
6
+ import { ExportConfig } from '../types';
7
+ export declare const log: (config: ExportConfig, message: any, type: string) => Promise<void>;
8
+ export declare const unlinkFileLogger: () => void;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ /*!
3
+ * Contentstack Export
4
+ * Copyright (c) 2019 Contentstack LLC
5
+ * MIT Licensed
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.unlinkFileLogger = exports.log = void 0;
9
+ const tslib_1 = require("tslib");
10
+ const winston = tslib_1.__importStar(require("winston"));
11
+ const path = tslib_1.__importStar(require("path"));
12
+ const mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
13
+ const slice = Array.prototype.slice;
14
+ const ansiRegexPattern = [
15
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
16
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
17
+ ].join('|');
18
+ function returnString(args) {
19
+ let returnStr = '';
20
+ if (args && args.length) {
21
+ returnStr = args
22
+ .map(function (item) {
23
+ if (item && typeof item === 'object') {
24
+ try {
25
+ return JSON.stringify(item).replace(/authtoken\":\d"blt................/g, 'authtoken":"blt....');
26
+ }
27
+ catch (error) { }
28
+ return item;
29
+ }
30
+ return item;
31
+ })
32
+ .join(' ')
33
+ .trim();
34
+ }
35
+ returnStr = returnStr.replace(new RegExp(ansiRegexPattern, 'g'), '').trim();
36
+ return returnStr;
37
+ }
38
+ const myCustomLevels = {
39
+ levels: {
40
+ warn: 1,
41
+ info: 2,
42
+ debug: 3,
43
+ },
44
+ colors: {
45
+ //colors aren't being used anywhere as of now, we're using chalk to add colors while logging
46
+ info: 'blue',
47
+ debug: 'green',
48
+ warn: 'yellow',
49
+ error: 'red',
50
+ },
51
+ };
52
+ let logger;
53
+ let errorLogger;
54
+ let successTransport;
55
+ let errorTransport;
56
+ function init(_logPath) {
57
+ if (!logger || !errorLogger) {
58
+ const logsDir = path.resolve(_logPath, 'logs', 'export');
59
+ // Create dir if doesn't already exist
60
+ mkdirp_1.default.sync(logsDir);
61
+ successTransport = {
62
+ filename: path.join(logsDir, 'success.log'),
63
+ maxFiles: 20,
64
+ maxsize: 1000000,
65
+ tailable: true,
66
+ level: 'info',
67
+ };
68
+ errorTransport = {
69
+ filename: path.join(logsDir, 'error.log'),
70
+ maxFiles: 20,
71
+ maxsize: 1000000,
72
+ tailable: true,
73
+ level: 'error',
74
+ };
75
+ logger = winston.createLogger({
76
+ transports: [
77
+ new winston.transports.File(successTransport),
78
+ new winston.transports.Console({ format: winston.format.simple() }),
79
+ ],
80
+ levels: myCustomLevels.levels,
81
+ });
82
+ errorLogger = winston.createLogger({
83
+ transports: [
84
+ new winston.transports.File(errorTransport),
85
+ new winston.transports.Console({
86
+ level: 'error',
87
+ format: winston.format.combine(winston.format.colorize({ all: true, colors: { error: 'red' } }), winston.format.simple()),
88
+ }),
89
+ ],
90
+ levels: { error: 0 },
91
+ });
92
+ }
93
+ return {
94
+ log: function (message) {
95
+ const args = slice.call(arguments);
96
+ const logString = returnString(args);
97
+ if (logString) {
98
+ logger.log('info', logString);
99
+ }
100
+ },
101
+ warn: function () {
102
+ const args = slice.call(arguments);
103
+ const logString = returnString(args);
104
+ if (logString) {
105
+ logger.log('warn', logString);
106
+ }
107
+ },
108
+ error: function (message) {
109
+ const args = slice.call(arguments);
110
+ const logString = returnString(args);
111
+ if (logString) {
112
+ errorLogger.log('error', logString);
113
+ }
114
+ },
115
+ debug: function () {
116
+ const args = slice.call(arguments);
117
+ const logString = returnString(args);
118
+ if (logString) {
119
+ logger.log('debug', logString);
120
+ }
121
+ },
122
+ };
123
+ }
124
+ const log = async (config, message, type) => {
125
+ config.data = config.data || path.join(__dirname, 'logs');
126
+ // ignoring the type argument, as we are not using it to create a logfile anymore
127
+ if (type !== 'error') {
128
+ // removed type argument from init method
129
+ init(config.data).log(message);
130
+ }
131
+ else {
132
+ init(config.data).error(message);
133
+ }
134
+ };
135
+ exports.log = log;
136
+ const unlinkFileLogger = () => {
137
+ if (logger) {
138
+ const transports = logger.transports;
139
+ transports.forEach((transport) => {
140
+ if (transport.name === 'file') {
141
+ logger.remove(transport);
142
+ }
143
+ });
144
+ }
145
+ if (errorLogger) {
146
+ const transports = errorLogger.transports;
147
+ transports.forEach((transport) => {
148
+ if (transport.name === 'file') {
149
+ errorLogger.remove(transport);
150
+ }
151
+ });
152
+ }
153
+ };
154
+ exports.unlinkFileLogger = unlinkFileLogger;
@@ -0,0 +1 @@
1
+ export declare const getDeveloperHubUrl: () => Promise<any>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDeveloperHubUrl = void 0;
4
+ let { default: config } = require('../config');
5
+ const { cliux, configHandler } = require('@contentstack/cli-utilities');
6
+ const getDeveloperHubUrl = async () => {
7
+ const { cma, name } = configHandler.get('region') || {};
8
+ let developerHubBaseUrl = config.developerHubUrls[cma];
9
+ if (!developerHubBaseUrl) {
10
+ developerHubBaseUrl = await cliux.inquire({
11
+ type: 'input',
12
+ name: 'name',
13
+ validate: (url) => {
14
+ if (!url)
15
+ return "Developer-hub URL can't be empty.";
16
+ return true;
17
+ },
18
+ message: `Enter the developer-hub base URL for the ${name} region - `,
19
+ });
20
+ }
21
+ return developerHubBaseUrl.startsWith('http') ? developerHubBaseUrl : `https://${developerHubBaseUrl}`;
22
+ };
23
+ exports.getDeveloperHubUrl = getDeveloperHubUrl;
@@ -0,0 +1,3 @@
1
+ import { ExportConfig } from 'src/types';
2
+ declare const setupBranches: (config: ExportConfig, stackAPIClient: any) => Promise<void>;
3
+ export default setupBranches;