@contentstack/cli-cm-import-setup 1.0.0-beta.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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +115 -0
  3. package/bin/dev.cmd +3 -0
  4. package/bin/dev.js +6 -0
  5. package/bin/run.cmd +3 -0
  6. package/bin/run.js +7 -0
  7. package/lib/commands/cm/stacks/import-setup.d.ts +10 -0
  8. package/lib/commands/cm/stacks/import-setup.js +53 -0
  9. package/lib/config/index.d.ts +3 -0
  10. package/lib/config/index.js +77 -0
  11. package/lib/import/import-setup.d.ts +32 -0
  12. package/lib/import/import-setup.js +112 -0
  13. package/lib/import/index.d.ts +1 -0
  14. package/lib/import/index.js +8 -0
  15. package/lib/import/modules/assets.d.ts +27 -0
  16. package/lib/import/modules/assets.js +102 -0
  17. package/lib/import/modules/base-setup.d.ts +37 -0
  18. package/lib/import/modules/base-setup.js +183 -0
  19. package/lib/import/modules/content-types.d.ts +6 -0
  20. package/lib/import/modules/content-types.js +20 -0
  21. package/lib/import/modules/custom-roles.d.ts +0 -0
  22. package/lib/import/modules/custom-roles.js +0 -0
  23. package/lib/import/modules/entries.d.ts +6 -0
  24. package/lib/import/modules/entries.js +20 -0
  25. package/lib/import/modules/extensions.d.ts +20 -0
  26. package/lib/import/modules/extensions.js +61 -0
  27. package/lib/import/modules/global-fields.d.ts +0 -0
  28. package/lib/import/modules/global-fields.js +0 -0
  29. package/lib/import/modules/index.d.ts +0 -0
  30. package/lib/import/modules/index.js +0 -0
  31. package/lib/import/modules/marketplace-apps.d.ts +26 -0
  32. package/lib/import/modules/marketplace-apps.js +81 -0
  33. package/lib/import/modules/taxonomies.d.ts +53 -0
  34. package/lib/import/modules/taxonomies.js +141 -0
  35. package/lib/types/default-config.d.ts +55 -0
  36. package/lib/types/default-config.js +2 -0
  37. package/lib/types/import-config.d.ts +55 -0
  38. package/lib/types/import-config.js +2 -0
  39. package/lib/types/index.d.ts +115 -0
  40. package/lib/types/index.js +2 -0
  41. package/lib/utils/backup-handler.d.ts +2 -0
  42. package/lib/utils/backup-handler.js +61 -0
  43. package/lib/utils/common-helper.d.ts +0 -0
  44. package/lib/utils/common-helper.js +0 -0
  45. package/lib/utils/file-helper.d.ts +15 -0
  46. package/lib/utils/file-helper.js +144 -0
  47. package/lib/utils/import-config-handler.d.ts +3 -0
  48. package/lib/utils/import-config-handler.js +91 -0
  49. package/lib/utils/index.d.ts +7 -0
  50. package/lib/utils/index.js +16 -0
  51. package/lib/utils/interactive.d.ts +3 -0
  52. package/lib/utils/interactive.js +38 -0
  53. package/lib/utils/log.d.ts +12 -0
  54. package/lib/utils/log.js +31 -0
  55. package/lib/utils/logger.d.ts +8 -0
  56. package/lib/utils/logger.js +157 -0
  57. package/lib/utils/login-handler.d.ts +8 -0
  58. package/lib/utils/login-handler.js +53 -0
  59. package/messages/index.json +1 -0
  60. package/oclif.manifest.json +56 -0
  61. package/package.json +96 -0
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trace = exports.logger = exports.initLogger = exports.log = exports.isImportConfig = void 0;
4
+ const path_1 = require("path");
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
6
+ let logger;
7
+ exports.logger = logger;
8
+ function isImportConfig(config) {
9
+ return config.data !== undefined && (config === null || config === void 0 ? void 0 : config.contentVersion) !== undefined;
10
+ }
11
+ exports.isImportConfig = isImportConfig;
12
+ function log(entryOrMessage, logType, hidden) {
13
+ exports.logger = logger = initLogger();
14
+ if (logType === 'error') {
15
+ logger.log(entryOrMessage, logType, hidden);
16
+ }
17
+ else {
18
+ logger.log(entryOrMessage, logType);
19
+ }
20
+ }
21
+ exports.log = log;
22
+ function initLogger(config) {
23
+ var _a;
24
+ if (!logger) {
25
+ const basePath = (0, cli_utilities_1.pathValidator)((0, path_1.join)((0, cli_utilities_1.sanitizePath)((_a = config === null || config === void 0 ? void 0 : config.cliLogsPath) !== null && _a !== void 0 ? _a : process.cwd()), 'logs', 'import'));
26
+ exports.logger = logger = new cli_utilities_1.Logger(Object.assign(config !== null && config !== void 0 ? config : {}, { basePath }));
27
+ }
28
+ return logger;
29
+ }
30
+ exports.initLogger = initLogger;
31
+ exports.trace = log;
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Contentstack Export
3
+ * Copyright (c) 2024 Contentstack LLC
4
+ * MIT Licensed
5
+ */
6
+ import { ImportConfig } from '../types';
7
+ export declare const log: (config: ImportConfig, message: any, type: string) => Promise<void>;
8
+ export declare const unlinkFileLogger: () => void;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ /*!
3
+ * Contentstack Export
4
+ * Copyright (c) 2024 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 cli_utilities_1 = require("@contentstack/cli-utilities");
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
+ var 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
+ var 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((0, cli_utilities_1.sanitizePath)(_logPath), 'logs', 'import');
59
+ successTransport = {
60
+ filename: path.join((0, cli_utilities_1.sanitizePath)(logsDir), 'success.log'),
61
+ maxFiles: 20,
62
+ maxsize: 1000000,
63
+ tailable: true,
64
+ level: 'info',
65
+ };
66
+ errorTransport = {
67
+ filename: path.join((0, cli_utilities_1.sanitizePath)(logsDir), 'error.log'),
68
+ maxFiles: 20,
69
+ maxsize: 1000000,
70
+ tailable: true,
71
+ level: 'error',
72
+ };
73
+ logger = winston.createLogger({
74
+ transports: [
75
+ new winston.transports.File(successTransport),
76
+ new winston.transports.Console({
77
+ format: winston.format.combine(winston.format.simple(), winston.format.colorize({ all: true, colors: { warn: 'yellow', info: 'white' } })),
78
+ }),
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
+ let args = slice.call(arguments);
96
+ let logString = returnString(args);
97
+ if (logString) {
98
+ logger.log('info', logString);
99
+ }
100
+ },
101
+ warn: function (message) {
102
+ let args = slice.call(arguments);
103
+ let logString = returnString(args);
104
+ if (logString) {
105
+ logger.log('warn', logString);
106
+ }
107
+ },
108
+ error: function (message) {
109
+ let args = slice.call(arguments);
110
+ let logString = returnString(args);
111
+ if (logString) {
112
+ errorLogger.log('error', logString);
113
+ }
114
+ },
115
+ debug: function () {
116
+ let args = slice.call(arguments);
117
+ let logString = returnString(args);
118
+ if (logString) {
119
+ logger.log('debug', logString);
120
+ }
121
+ },
122
+ };
123
+ }
124
+ const log = async (config, message, type) => {
125
+ config.cliLogsPath = config.cliLogsPath || 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
+ if (type === 'warn')
130
+ init(config.cliLogsPath).warn(message); //logged warning message in log file
131
+ else
132
+ init(config.cliLogsPath).log(message);
133
+ }
134
+ else {
135
+ init(config.cliLogsPath).error(message);
136
+ }
137
+ };
138
+ exports.log = log;
139
+ const unlinkFileLogger = () => {
140
+ if (logger) {
141
+ const transports = logger.transports;
142
+ transports.forEach((transport) => {
143
+ if (transport.name === 'file') {
144
+ logger.remove(transport);
145
+ }
146
+ });
147
+ }
148
+ if (errorLogger) {
149
+ const transports = errorLogger.transports;
150
+ transports.forEach((transport) => {
151
+ if (transport.name === 'file') {
152
+ errorLogger.remove(transport);
153
+ }
154
+ });
155
+ }
156
+ };
157
+ exports.unlinkFileLogger = unlinkFileLogger;
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Contentstack Import
3
+ * Copyright (c) 2024 Contentstack LLC
4
+ * MIT Licensed
5
+ */
6
+ import { ImportConfig } from '../types';
7
+ declare const login: (config: ImportConfig) => Promise<any>;
8
+ export default login;
@@ -0,0 +1,53 @@
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) 2024 Contentstack LLC
8
+ * MIT Licensed
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ const logger_1 = require("./logger");
12
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
13
+ const login = async (config) => {
14
+ const client = await (0, cli_utilities_1.managementSDKClient)(config);
15
+ if (config.email && config.password) {
16
+ const { user: { authtoken = null } = {} } = await client.login({ email: config.email, password: config.password });
17
+ if (authtoken) {
18
+ config.headers = {
19
+ api_key: config.source_stack,
20
+ access_token: config.access_token,
21
+ authtoken: config.authtoken,
22
+ 'X-User-Agent': 'contentstack-export/v',
23
+ };
24
+ (0, logger_1.log)(config, 'Contentstack account authenticated successfully!', 'success');
25
+ return config;
26
+ }
27
+ else {
28
+ throw new Error('Invalid auth token received after login');
29
+ }
30
+ }
31
+ else if (config.management_token) {
32
+ return config;
33
+ }
34
+ else if ((0, cli_utilities_1.isAuthenticated)()) {
35
+ const stackAPIClient = client.stack({
36
+ api_key: config.target_stack,
37
+ management_token: config.management_token,
38
+ });
39
+ const stack = await stackAPIClient.fetch().catch((error) => {
40
+ var _a;
41
+ let errorstack_key = (_a = error === null || error === void 0 ? void 0 : error.errors) === null || _a === void 0 ? void 0 : _a.api_key;
42
+ if (errorstack_key) {
43
+ (0, logger_1.log)(config, 'Stack Api key ' + errorstack_key[0] + 'Please enter valid Key', 'error');
44
+ throw error;
45
+ }
46
+ (0, logger_1.log)(config, error === null || error === void 0 ? void 0 : error.errorMessage, 'error');
47
+ throw error;
48
+ });
49
+ config.destinationStackName = stack.name;
50
+ return config;
51
+ }
52
+ };
53
+ exports.default = login;
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,56 @@
1
+ {
2
+ "version": "1.0.0-beta.1",
3
+ "commands": {
4
+ "cm:stacks:import-setup": {
5
+ "id": "cm:stacks:import-setup",
6
+ "description": "Import content from a stack",
7
+ "strict": true,
8
+ "usage": "cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]",
9
+ "pluginName": "@contentstack/cli-cm-import-setup",
10
+ "pluginAlias": "@contentstack/cli-cm-import-setup",
11
+ "pluginType": "core",
12
+ "aliases": [
13
+ "cm:import-setup"
14
+ ],
15
+ "hiddenAliases": [],
16
+ "examples": [
17
+ "csdx cm:stacks:import-setup --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>"
18
+ ],
19
+ "flags": {
20
+ "stack-api-key": {
21
+ "name": "stack-api-key",
22
+ "type": "option",
23
+ "char": "k",
24
+ "description": "API key of the target stack",
25
+ "multiple": false
26
+ },
27
+ "data-dir": {
28
+ "name": "data-dir",
29
+ "type": "option",
30
+ "char": "d",
31
+ "description": "path and location where data is stored",
32
+ "multiple": false
33
+ },
34
+ "alias": {
35
+ "name": "alias",
36
+ "type": "option",
37
+ "char": "a",
38
+ "description": "alias of the management token",
39
+ "multiple": false
40
+ },
41
+ "modules": {
42
+ "name": "modules",
43
+ "type": "option",
44
+ "description": "[optional] specific module name",
45
+ "multiple": false,
46
+ "options": [
47
+ "content-types",
48
+ "entries",
49
+ "both"
50
+ ]
51
+ }
52
+ },
53
+ "args": {}
54
+ }
55
+ }
56
+ }
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@contentstack/cli-cm-import-setup",
3
+ "description": "Contentstack CLI plugin to setup the mappers and configurations for the import command",
4
+ "version": "1.0.0-beta.1",
5
+ "author": "Contentstack",
6
+ "bugs": "https://github.com/contentstack/cli/issues",
7
+ "dependencies": {
8
+ "@contentstack/cli-command": "~1.3.2",
9
+ "@contentstack/cli-utilities": "~1.8.0",
10
+ "@oclif/core": "^3.27.0",
11
+ "big-json": "^3.2.0",
12
+ "bluebird": "^3.7.2",
13
+ "chalk": "^4.1.2",
14
+ "debug": "^4.4.0",
15
+ "fs-extra": "^11.1.1",
16
+ "lodash": "^4.17.21",
17
+ "marked": "^4.3.0",
18
+ "merge": "^2.1.1",
19
+ "mkdirp": "^1.0.4",
20
+ "promise-limit": "^2.7.0",
21
+ "tslib": "^2.8.1",
22
+ "uuid": "^9.0.1",
23
+ "winston": "^3.17.0"
24
+ },
25
+ "devDependencies": {
26
+ "@oclif/test": "^4.1.3",
27
+ "@types/big-json": "^3.2.5",
28
+ "@types/bluebird": "^3.5.42",
29
+ "@types/chai": "^4.3.20",
30
+ "@types/fs-extra": "^11.0.4",
31
+ "@types/mkdirp": "^1.0.2",
32
+ "@types/mocha": "^8.2.3",
33
+ "@types/node": "^14.18.63",
34
+ "@types/sinon": "^10.0.20",
35
+ "@types/tar": "^6.1.13",
36
+ "@types/uuid": "^9.0.8",
37
+ "@typescript-eslint/eslint-plugin": "^5.62.0",
38
+ "chai": "^4.5.0",
39
+ "eslint": "^8.57.1",
40
+ "eslint-config-oclif": "^4.0.0",
41
+ "globby": "^10.0.2",
42
+ "mocha": "^10.8.2",
43
+ "nyc": "^15.1.0",
44
+ "oclif": "^3.17.2",
45
+ "rimraf": "^2.7.1",
46
+ "sinon": "^11.1.2",
47
+ "tmp": "^0.2.3",
48
+ "ts-node": "^10.9.2",
49
+ "typescript": "^4.9.5"
50
+ },
51
+ "scripts": {
52
+ "build": "npm run clean && npm run compile",
53
+ "clean": "rm -rf ./lib ./node_modules tsconfig.build.tsbuildinfo",
54
+ "compile": "tsc -b tsconfig.json",
55
+ "postpack": "rm -f oclif.manifest.json",
56
+ "prepack": "pnpm compile && oclif manifest && oclif readme",
57
+ "version": "oclif readme && git add README.md",
58
+ "test:report": "tsc -p test && nyc --reporter=lcov --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
59
+ "pretest": "tsc -p test",
60
+ "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
61
+ "posttest": "npm run lint",
62
+ "lint": "eslint src/**/*.ts",
63
+ "format": "eslint src/**/*.ts --fix",
64
+ "test:integration": "mocha --forbid-only \"test/run.test.js\" --integration-test --timeout 60000",
65
+ "test:unit": "mocha --forbid-only \"test/unit/*.test.ts\""
66
+ },
67
+ "engines": {
68
+ "node": ">=14.0.0"
69
+ },
70
+ "files": [
71
+ "/bin",
72
+ "/lib",
73
+ "/messages",
74
+ "/npm-shrinkwrap.json",
75
+ "/oclif.manifest.json"
76
+ ],
77
+ "homepage": "https://github.com/contentstack/cli",
78
+ "keywords": [
79
+ "contentstack",
80
+ "cli",
81
+ "plugin"
82
+ ],
83
+ "main": "./lib/commands/cm/stacks/import-setup.js",
84
+ "license": "MIT",
85
+ "oclif": {
86
+ "commands": "./lib/commands",
87
+ "bin": "csdx",
88
+ "repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-import-setup/<%- commandPath %>"
89
+ },
90
+ "csdxConfig": {
91
+ "shortCommandName": {
92
+ "cm:stacks:import": "IMPRTSTP"
93
+ }
94
+ },
95
+ "repository": "https://github.com/contentstack/cli"
96
+ }