zcatalyst-cli 1.8.0 → 1.10.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.
Files changed (113) hide show
  1. package/README.md +31 -10
  2. package/docs/command_needs/auth.toml +5 -0
  3. package/docs/commands/iac/export.toml +4 -0
  4. package/docs/commands/iac/import.toml +4 -0
  5. package/docs/commands/iac/status.toml +4 -0
  6. package/docs/commands/project/use.toml +6 -0
  7. package/docs/iac/status/bundle.toml +4 -0
  8. package/lib/api-timer.js +81 -0
  9. package/lib/apig-utils.js +16 -14
  10. package/lib/archiver.js +83 -45
  11. package/lib/authentication/login.js +4 -2
  12. package/lib/bin/catalyst.js +0 -1
  13. package/lib/client-utils.js +22 -22
  14. package/lib/client.js +0 -3
  15. package/lib/command_needs/auth.js +12 -3
  16. package/lib/command_needs/rc.js +12 -7
  17. package/lib/commands/apig/disable.js +1 -1
  18. package/lib/commands/apig/enable.js +1 -1
  19. package/lib/commands/apig/status.js +7 -5
  20. package/lib/commands/client/delete.js +3 -5
  21. package/lib/commands/client/setup.js +1 -1
  22. package/lib/commands/deploy.js +4 -2
  23. package/lib/commands/ds/export.js +4 -2
  24. package/lib/commands/ds/import.js +4 -2
  25. package/lib/commands/ds/status.js +146 -150
  26. package/lib/commands/event/generate/index.js +1 -1
  27. package/lib/commands/event/generate/integ.js +1 -1
  28. package/lib/commands/functions/add.js +1 -1
  29. package/lib/commands/functions/config.js +1 -1
  30. package/lib/commands/functions/delete.js +1 -1
  31. package/lib/commands/functions/setup.js +1 -1
  32. package/lib/commands/functions/shell.js +1 -1
  33. package/lib/commands/help.js +0 -22
  34. package/lib/commands/iac/export.js +85 -0
  35. package/lib/commands/iac/import.js +187 -0
  36. package/lib/commands/iac/pack.js +129 -0
  37. package/lib/commands/iac/status.js +63 -0
  38. package/lib/commands/index.js +4 -0
  39. package/lib/commands/init.js +34 -27
  40. package/lib/commands/login.js +1 -1
  41. package/lib/commands/logout.js +1 -1
  42. package/lib/commands/project/list.js +11 -7
  43. package/lib/commands/project/reset.js +1 -1
  44. package/lib/commands/project/use.js +42 -25
  45. package/lib/commands/pull.js +1 -1
  46. package/lib/commands/run.js +1 -1
  47. package/lib/commands/serve.js +6 -5
  48. package/lib/commands/token/generate.js +1 -1
  49. package/lib/commands/token/list.js +1 -1
  50. package/lib/commands/token/revoke.js +1 -1
  51. package/lib/commands/whoami.js +1 -1
  52. package/lib/deploy/features/functions/index.js +2 -1
  53. package/lib/deploy/index.js +3 -1
  54. package/lib/endpoints/lib/iac.js +134 -0
  55. package/lib/error.js +43 -9
  56. package/lib/errorOut.js +9 -2
  57. package/lib/express_middlewares/unknownReqProxy.js +18 -7
  58. package/lib/fn-utils/lib/common.js +32 -12
  59. package/lib/fn-utils/lib/java.js +8 -9
  60. package/lib/fn-utils/lib/node.js +7 -1
  61. package/lib/fn-watcher.js +67 -0
  62. package/lib/iac/status/bundle.js +82 -0
  63. package/lib/iac/status/deploy.js +74 -0
  64. package/lib/iac/status/util/index.js +26 -0
  65. package/lib/index.js +13 -19
  66. package/lib/init/features/client.js +2 -3
  67. package/lib/init/features/functions/languages/java.js +2 -5
  68. package/lib/init/features/functions/languages/node.js +2 -5
  69. package/lib/init/features/index.js +8 -3
  70. package/lib/init/features/project.js +70 -33
  71. package/lib/init/util/client.js +12 -0
  72. package/lib/init/util/functions.js +20 -0
  73. package/lib/init/util/project.js +35 -0
  74. package/lib/internal/api.js +6 -9
  75. package/lib/internal/command.js +3 -3
  76. package/lib/internal/config.js +6 -4
  77. package/lib/migration/index.js +10 -6
  78. package/lib/option-filter.js +4 -1
  79. package/lib/port-resolver.js +18 -16
  80. package/lib/prompt/index.js +92 -0
  81. package/lib/prompt/types/file-path.js +95 -0
  82. package/lib/pull/features/client.js +1 -1
  83. package/lib/pull/features/functions/index.js +5 -7
  84. package/lib/pull/index.js +4 -1
  85. package/lib/serve/features/index.js +3 -1
  86. package/lib/serve/index.js +8 -4
  87. package/lib/serve/server/index.js +134 -64
  88. package/lib/serve/server/lib/master.js +5 -4
  89. package/lib/shell/dependencies/http-functions.js +46 -21
  90. package/lib/shell/dependencies/local-function.js +17 -48
  91. package/lib/shell/index.js +9 -10
  92. package/lib/shell/prepare/index.js +1 -5
  93. package/lib/shell/prepare/languages/index.js +14 -3
  94. package/lib/track.js +3 -1
  95. package/lib/util_modules/constants/index.js +3 -1
  96. package/lib/util_modules/constants/lib/file-names.js +2 -1
  97. package/lib/util_modules/constants/lib/iac.js +8 -0
  98. package/lib/util_modules/constants/lib/regex.js +2 -1
  99. package/lib/util_modules/constants/lib/scopes.js +5 -0
  100. package/lib/util_modules/constants/project.js +6 -0
  101. package/lib/util_modules/contextHelp.js +25 -14
  102. package/lib/util_modules/env.js +2 -5
  103. package/lib/util_modules/fs/index.js +9 -1
  104. package/lib/util_modules/fs/lib/async.js +29 -22
  105. package/lib/util_modules/js.js +6 -0
  106. package/lib/util_modules/logger.js +11 -10
  107. package/lib/util_modules/parser/toml.js +5 -1
  108. package/lib/util_modules/project.js +34 -19
  109. package/lib/util_modules/shell.js +6 -5
  110. package/package.json +12 -7
  111. package/scripts/postInstall.js +31 -0
  112. package/templates/iacSuccess.html +391 -0
  113. package/lib/prompt.js +0 -49
@@ -0,0 +1,187 @@
1
+ 'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.iacImport = void 0;
16
+ const ansi_colors_1 = require("ansi-colors");
17
+ const http_1 = require("http");
18
+ const open_1 = __importDefault(require("open"));
19
+ const path_1 = require("path");
20
+ const url_1 = require("url");
21
+ const archiver_1 = __importDefault(require("../../archiver"));
22
+ const iac_1 = __importDefault(require("../../endpoints/lib/iac"));
23
+ const error_1 = __importDefault(require("../../error"));
24
+ const command_1 = __importDefault(require("../../internal/command"));
25
+ const port_resolver_1 = __importDefault(require("../../port-resolver"));
26
+ const prompt_1 = __importDefault(require("../../prompt"));
27
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
28
+ const constants_1 = require("../../util_modules/constants");
29
+ const env_1 = require("../../util_modules/env");
30
+ const fs_1 = require("../../util_modules/fs");
31
+ const js_1 = require("../../util_modules/js");
32
+ const logger_1 = require("../../util_modules/logger");
33
+ const option_1 = require("../../util_modules/option");
34
+ const shell_1 = require("../../util_modules/shell");
35
+ const getZipAndTemplate = (filePath, stagedDeploy) => __awaiter(void 0, void 0, void 0, function* () {
36
+ const zipFile = filePath
37
+ ? yield fs_1.ASYNC.readFile(fs_1.untildify(filePath), 'buffer')
38
+ : (stagedDeploy === null || stagedDeploy === void 0 ? void 0 : stagedDeploy.id)
39
+ ? yield new iac_1.default().deployDownload(stagedDeploy.id)
40
+ : undefined;
41
+ if (!zipFile) {
42
+ throw filePath
43
+ ? new error_1.default('Provided zip file path does not exists!')
44
+ : new error_1.default('Unable to get zip file from server!', { exit: 2 });
45
+ }
46
+ const zipArchive = new archiver_1.default().load(zipFile);
47
+ const templateFile = yield zipArchive.readFile(constants_1.REGEX.project.template);
48
+ if (!templateFile) {
49
+ throw new error_1.default('No project template found', {
50
+ exit: 1,
51
+ errorId: 'I-1'
52
+ });
53
+ }
54
+ return [zipArchive, templateFile];
55
+ });
56
+ const ensureUserAction = (deployRes) => __awaiter(void 0, void 0, void 0, function* () {
57
+ const userActionError = yield new Promise((res, rej) => __awaiter(void 0, void 0, void 0, function* () {
58
+ const callbackPort = yield port_resolver_1.default.getFreePort(3000, 10, false);
59
+ const accessUrl = new url_1.URL(`/baas/v1/project/import/${deployRes.id}/deploy`, `${constants_1.ORIGIN.admin}`);
60
+ accessUrl.searchParams.set('redirect_url', `http://localhost:${callbackPort}/success`);
61
+ const server = http_1.createServer((req, resp) => __awaiter(void 0, void 0, void 0, function* () {
62
+ try {
63
+ if (req.url !== '/success') {
64
+ resp.writeHead(404);
65
+ resp.end();
66
+ return;
67
+ }
68
+ const htmlFile = yield fs_1.ASYNC.readFile(path_1.join(__dirname, '../../../templates/iacSuccess.html'));
69
+ resp.setHeader('Content-Type', 'text/html');
70
+ resp.writeHead(200);
71
+ resp.end(htmlFile, () => {
72
+ req.socket.destroy();
73
+ server.close(res);
74
+ });
75
+ }
76
+ catch (e) {
77
+ server.close(() => res(e));
78
+ }
79
+ }));
80
+ server.listen(callbackPort, () => {
81
+ const urlString = accessUrl.toString();
82
+ logger_1.info();
83
+ logger_1.info('Visit this URL on this device to proceed:');
84
+ logger_1.info(ansi_colors_1.bold.underline(urlString));
85
+ logger_1.info();
86
+ open_1.default(urlString).catch();
87
+ });
88
+ server.on('error', (err) => {
89
+ rej(err);
90
+ });
91
+ }));
92
+ if (userActionError) {
93
+ throw new error_1.default('Error while verifying user action', {
94
+ original: userActionError,
95
+ exit: 2
96
+ });
97
+ }
98
+ logger_1.info();
99
+ logger_1.success(`Successfully scheduled import job for project "${deployRes.project_details.project_name}" with jobid "${deployRes.id}"`);
100
+ if (option_1.getCurrentCommand() === 'init' || env_1.isPrimaryShell()) {
101
+ const exitListeners = process.listeners('exit');
102
+ process.removeAllListeners('exit');
103
+ const allGlobalOpts = runtime_store_1.default.get('opts.globalOpts', {});
104
+ const optsArr = Object.keys(allGlobalOpts).reduce((arr, key) => {
105
+ arr.push('--' + key);
106
+ if (allGlobalOpts[key]) {
107
+ arr.push(allGlobalOpts[key]);
108
+ }
109
+ return arr;
110
+ }, ['--id', deployRes.id]);
111
+ yield shell_1.spawn('catalyst', ['iac:status', 'import', ...optsArr], {
112
+ shell: true,
113
+ stdio: 'inherit'
114
+ }).ASYNC();
115
+ (exitListeners || []).forEach((listner) => {
116
+ process.addListener('exit', listner);
117
+ });
118
+ }
119
+ });
120
+ const iacImport = (filePath, projectName) => __awaiter(void 0, void 0, void 0, function* () {
121
+ const iacAPI = new iac_1.default();
122
+ const allDeploys = yield iacAPI.allDeploys();
123
+ const stagedDeploy = allDeploys.find((deploy) => deploy.status === 'Staged');
124
+ const stagedAns = yield prompt_1.default.ask(prompt_1.default.question('consent', `Do you wish to continue setting up the already staged project (${stagedDeploy === null || stagedDeploy === void 0 ? void 0 : stagedDeploy.project_details.project_name}):`, {
125
+ type: 'confirm',
126
+ defaultAns: true,
127
+ suffix: '\n Note: Declining will delete the old staged project!',
128
+ when: !!stagedDeploy
129
+ }));
130
+ if (stagedDeploy && (stagedAns === null || stagedAns === void 0 ? void 0 : stagedAns.consent)) {
131
+ const [zipArchive, templateFile] = yield getZipAndTemplate(undefined, stagedDeploy);
132
+ yield ensureUserAction(stagedDeploy);
133
+ return [zipArchive, templateFile, stagedDeploy];
134
+ }
135
+ if (stagedDeploy && !(stagedAns === null || stagedAns === void 0 ? void 0 : stagedAns.consent)) {
136
+ yield iacAPI.deployDelete(stagedDeploy.id);
137
+ logger_1.message(`Successfully deleted project ${stagedDeploy === null || stagedDeploy === void 0 ? void 0 : stagedDeploy.project_details.project_name} from console.`);
138
+ }
139
+ if (!filePath) {
140
+ yield prompt_1.default.register('file-path');
141
+ }
142
+ const userReply = yield prompt_1.default.ask(prompt_1.default.question('projectName', 'Provide a name for your new project:', {
143
+ when: !projectName,
144
+ validate: (ans) => ans.match(constants_1.REGEX.project.name)
145
+ ? true
146
+ : `Project Name is invalid, it should match ${constants_1.REGEX.project.name}`
147
+ }), prompt_1.default.question('filePath', 'Provide the path of the zip file that you would like to use?', {
148
+ type: 'file-path',
149
+ when: !filePath,
150
+ exclude: ['**/!(*.zip)', '**/.*'],
151
+ validate: ({ value }) => __awaiter(void 0, void 0, void 0, function* () {
152
+ if (value && value.endsWith('.zip')) {
153
+ return (yield fs_1.ASYNC.fileExists(value)) ? true : 'File does not exists!';
154
+ }
155
+ return 'Invalid zip file!';
156
+ })
157
+ }));
158
+ projectName = (userReply.projectName || projectName);
159
+ filePath = (userReply.filePath || filePath);
160
+ if (!filePath.endsWith('.zip')) {
161
+ throw new error_1.default('Provided file type is not supported. Provide a zip path.');
162
+ }
163
+ const [zipArchive, templateFile] = yield getZipAndTemplate(filePath);
164
+ const parsedJSON = js_1.JS.parseJSON(templateFile);
165
+ const format = parsedJSON ? constants_1.IAC.template_format.json : constants_1.IAC.template_format.yml;
166
+ const deployRes = yield new iac_1.default().deploy(projectName, format, fs_1.SYNC.getReadStream(filePath));
167
+ yield ensureUserAction(deployRes);
168
+ return [zipArchive, templateFile, deployRes];
169
+ });
170
+ exports.iacImport = iacImport;
171
+ exports.default = new command_1.default('iac:import [file_path]')
172
+ .description('Deploy the iac zip file to console and create a new project with it.')
173
+ .option('-n, --name <project_name>', 'name of the project to be used')
174
+ .needs('auth', [
175
+ constants_1.SCOPE.project_import_read,
176
+ constants_1.SCOPE.project_import_create,
177
+ constants_1.SCOPE.project_import_delete
178
+ ])
179
+ .needs('config', { optional: true })
180
+ .needs('rc', { optional: true })
181
+ .action((filePath) => __awaiter(void 0, void 0, void 0, function* () {
182
+ const nameOptValue = option_1.getOptionValue('name');
183
+ if (nameOptValue && !nameOptValue.match(constants_1.REGEX.project.name)) {
184
+ throw new error_1.default(`Project Name is invalid, it should match ${constants_1.REGEX.project.name}`);
185
+ }
186
+ yield exports.iacImport(filePath, nameOptValue);
187
+ }));
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ const path_1 = require("path");
35
+ const archiver_1 = __importDefault(require("../../archiver"));
36
+ const client_utils_1 = require("../../client-utils");
37
+ const languages_1 = require("../../deploy/features/functions/languages");
38
+ const error_1 = __importDefault(require("../../error"));
39
+ const fn_utils_1 = require("../../fn-utils");
40
+ const command_1 = __importDefault(require("../../internal/command"));
41
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
42
+ const constants_1 = require("../../util_modules/constants");
43
+ const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
44
+ const fs_1 = require("../../util_modules/fs");
45
+ const js_1 = require("../../util_modules/js");
46
+ const logger_1 = require("../../util_modules/logger");
47
+ const yaml_1 = __importDefault(require("yaml"));
48
+ const ansi_colors_1 = require("ansi-colors");
49
+ exports.default = new command_1.default('iac:pack [zip_name]')
50
+ .description('Creates a import ready zip file')
51
+ .needs('auth')
52
+ .needs('config')
53
+ .action((userZipName) => __awaiter(void 0, void 0, void 0, function* () {
54
+ var _a, _b;
55
+ const config = runtime_store_1.default.get('config');
56
+ const rootDir = path_1.dirname(config.configPath);
57
+ const filesAtRoot = yield fs_1.ASYNC.walk(rootDir, { excludeDir: true, depth: 1 });
58
+ const templateFilePth = filesAtRoot.find((fileName) => fileName.match(constants_1.REGEX.project.template));
59
+ if (templateFilePth === undefined) {
60
+ throw new error_1.default('No template file found', { exit: 1 });
61
+ }
62
+ const templateFile = yield fs_1.ASYNC.readFile(templateFilePth);
63
+ if (templateFile === undefined) {
64
+ throw new error_1.default('Unable to read template file', { exit: 1 });
65
+ }
66
+ const templateJson = js_1.JS.parseJSON(templateFile) || yaml_1.default.parse(templateFile);
67
+ const templateFns = ((_a = templateJson.components) === null || _a === void 0 ? void 0 : _a.Functions) || [];
68
+ const templateClient = ((_b = templateJson.components) === null || _b === void 0 ? void 0 : _b.WebClient) || [];
69
+ const hrTime = process.hrtime();
70
+ const archiveName = (userZipName === null || userZipName === void 0 ? void 0 : userZipName.replace('.zip', '')) || `iac_${hrTime[0] * 1000000000 + hrTime[1]}`;
71
+ const finalZip = new archiver_1.default(archiveName);
72
+ const optionFilter = yield Promise.resolve().then(() => __importStar(require('../../option-filter')));
73
+ const components = optionFilter.filterTargets(false);
74
+ yield Promise.all(components.map((component) => __awaiter(void 0, void 0, void 0, function* () {
75
+ switch (component) {
76
+ case 'functions':
77
+ const fnTargets = yield fn_utils_1.fnUtils.common.validate();
78
+ const refinedFns = yield fn_utils_1.fnUtils.common.refineTargets(fnTargets, false);
79
+ const fnNameByCodePath = {};
80
+ const [nodeFns, javaFns] = refinedFns.reduce((acc, fn) => {
81
+ var _a, _b;
82
+ if (!fn.valid) {
83
+ throw new error_1.default(`Unable to pack since "${fn.name}" is not valid. Reason: ${fn.failure_reason}`);
84
+ }
85
+ const fnTemplateConfig = templateFns.find((tfn) => fn.name === tfn.properties.name);
86
+ if (!fnTemplateConfig) {
87
+ throw new error_1.default(`No property found for function ${fn.name} in project template`, { exit: 1 });
88
+ }
89
+ fnNameByCodePath[fn.name] = fnTemplateConfig.properties.code.path;
90
+ if ((_a = fn.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.nodejs)) {
91
+ acc[0].push(fn);
92
+ }
93
+ if ((_b = fn.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.java)) {
94
+ acc[1].push(fn);
95
+ }
96
+ return acc;
97
+ }, [[], []]);
98
+ const packedNodeFns = yield languages_1.node(nodeFns);
99
+ const packedJavaFns = yield languages_1.java(javaFns);
100
+ const packedFns = [...(packedNodeFns || []), ...(packedJavaFns || [])];
101
+ packedFns.forEach((fn) => {
102
+ if (!fn.valid) {
103
+ throw new error_1.default(`Unable to pack since "${fn.name}" is not valid. Reason: ${fn.failure_reason}`);
104
+ }
105
+ finalZip.add(fnNameByCodePath[fn.name], fn.zip_stream);
106
+ });
107
+ break;
108
+ case 'client':
109
+ yield client_utils_1.clientUtils.validate();
110
+ const clientName = runtime_store_1.default.get('context.client.name');
111
+ const clientTeamplateConfig = templateClient.find((tClient) => clientName === tClient.properties.app_name);
112
+ if (!clientTeamplateConfig) {
113
+ throw new error_1.default(`No property found for client ${clientName} in project template`, { exit: 1 });
114
+ }
115
+ const clientZipStream = yield client_utils_1.clientUtils.pack();
116
+ finalZip.add(clientTeamplateConfig.properties.code.path, clientZipStream);
117
+ break;
118
+ default:
119
+ logger_1.debug(`skipping ${component} since there is no processing needed`);
120
+ break;
121
+ }
122
+ })));
123
+ finalZip.add(path_1.parse(templateFilePth).name + '.json', JSON.stringify(templateJson, null, 2) + '\n');
124
+ yield (yield finalZip.finalize()).writeZip(rootDir);
125
+ logger_1.message(ansi_colors_1.bold(path_1.relative(runtime_store_1.default.get('cwd'), path_1.join(rootDir, archiveName))) +
126
+ '.zip file has been successfully created.');
127
+ logger_1.info();
128
+ logger_1.success('Catalyst pack complete');
129
+ }));
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ const ansi_colors_1 = require("ansi-colors");
35
+ const error_1 = __importDefault(require("../../error"));
36
+ const command_1 = __importDefault(require("../../internal/command"));
37
+ const constants_1 = require("../../util_modules/constants");
38
+ exports.default = new command_1.default('iac:status <operation>')
39
+ .description('Displays the status of iac schedule progress')
40
+ .option('--id <id>', 'Schedule id of the import operation.')
41
+ .option('--production', 'flag for pointing to production environment (only for export)')
42
+ .needs('auth', [constants_1.SCOPE.project_import_read, constants_1.SCOPE.project_export_read])
43
+ .needs('config', { optional: true })
44
+ .needs('rc', { optional: true })
45
+ .action((operation) => __awaiter(void 0, void 0, void 0, function* () {
46
+ switch (operation) {
47
+ case 'import':
48
+ const { default: deploy } = yield Promise.resolve().then(() => __importStar(require('../../iac/status/deploy')));
49
+ yield deploy();
50
+ break;
51
+ case 'export':
52
+ const { default: bundle } = yield Promise.resolve().then(() => __importStar(require('../../iac/status/bundle')));
53
+ yield bundle();
54
+ break;
55
+ default:
56
+ throw new error_1.default('Unsupported operation', {
57
+ exit: 1,
58
+ errorId: 'S-1',
59
+ arg: [ansi_colors_1.bold(operation)]
60
+ });
61
+ }
62
+ return;
63
+ }));
@@ -54,6 +54,10 @@ exports.default = (client) => {
54
54
  loadCommand('project:reset'),
55
55
  loadCommand('init'),
56
56
  loadCommand('pull'),
57
+ loadCommand('iac:pack'),
58
+ loadCommand('iac:import'),
59
+ loadCommand('iac:export'),
60
+ loadCommand('iac:status'),
57
61
  loadCommand('apig:status'),
58
62
  loadCommand('apig:enable'),
59
63
  loadCommand('apig:disable'),
@@ -32,6 +32,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  const ansi_colors_1 = require("ansi-colors");
35
+ const features_1 = require("../init/features");
35
36
  const command_1 = __importDefault(require("../internal/command"));
36
37
  const prompt_1 = __importDefault(require("../prompt"));
37
38
  const runtime_store_1 = __importDefault(require("../runtime-store"));
@@ -41,14 +42,26 @@ const fs_1 = require("../util_modules/fs");
41
42
  const js_1 = require("../util_modules/js");
42
43
  const logger_1 = require("../util_modules/logger");
43
44
  const shell_1 = require("../util_modules/shell");
45
+ const saveAndComplete = (config) => __awaiter(void 0, void 0, void 0, function* () {
46
+ yield config.save();
47
+ logger_1.message(ansi_colors_1.bold(constants_1.FILENAME.config) + ' file has been successfully created with feature details.');
48
+ logger_1.info();
49
+ logger_1.success('Catalyst initialization complete!');
50
+ });
44
51
  exports.default = new command_1.default('init [feature]')
45
- .description('Initialize a Catalyst sample project in the current directory')
52
+ .description('Initialize a Catalyst project, function, and client resources in the local directory')
46
53
  .option('--force', 'force initialise a project for this directory')
47
54
  .ignore(['project'])
48
- .needs('auth', [constants_1.SCOPE.projects, constants_1.SCOPE.stratus_create, constants_1.SCOPE.stratus_read])
55
+ .needs('auth', [
56
+ constants_1.SCOPE.projects,
57
+ constants_1.SCOPE.stratus_create,
58
+ constants_1.SCOPE.stratus_read,
59
+ constants_1.SCOPE.project_import_create
60
+ ])
49
61
  .needs('config', { optional: true })
50
62
  .needs('rc', { optional: true, resolveOnNotFound: true })
51
63
  .action((feature) => __awaiter(void 0, void 0, void 0, function* () {
64
+ var _a;
52
65
  const config = runtime_store_1.default.get('config');
53
66
  const homeDir = (yield Promise.resolve().then(() => __importStar(require('os')))).homedir();
54
67
  const warnings = [];
@@ -70,7 +83,7 @@ exports.default = new command_1.default('init [feature]')
70
83
  '\n';
71
84
  }
72
85
  shell_1.clearStdout(true);
73
- const bannerString = yield fs_1.ASYNC.readFile(constants_1.TEMPLATE.banner, 'utf8');
86
+ const bannerString = yield fs_1.ASYNC.readFile(constants_1.TEMPLATE.banner);
74
87
  logger_1.info('\n' +
75
88
  ansi_colors_1.blueBright.bold(bannerString) +
76
89
  "\nYou're about to initialize a Catalyst project in this directory:\n\n " +
@@ -86,12 +99,12 @@ exports.default = new command_1.default('init [feature]')
86
99
  logger_1.message('Aborted by user.');
87
100
  return;
88
101
  }
89
- let featureAns;
90
- if (typeof feature === 'string') {
91
- featureAns = { features: [feature] };
92
- }
93
- else {
94
- const featureChoices = [
102
+ yield features_1.project();
103
+ const featureAns = yield prompt_1.default.ask(prompt_1.default.question('features', 'Which are the features you want to setup for this folder?\n This step is optional! Press ' +
104
+ ansi_colors_1.cyan('<return> ') +
105
+ 'to proceed.\n', {
106
+ type: 'checkbox',
107
+ choices: [
95
108
  prompt_1.default.choice('Functions: Configure and deploy http/non-http functions', {
96
109
  value: 'functions',
97
110
  short: 'Functions'
@@ -99,25 +112,19 @@ exports.default = new command_1.default('init [feature]')
99
112
  prompt_1.default.choice('Client: Configure and deploy client files', {
100
113
  value: 'client',
101
114
  short: 'Client'
102
- }),
103
- prompt_1.default.choice('Project: Sets a base project for this directory', {
104
- value: 'project',
105
- short: 'Project',
106
- disabled: ansi_colors_1.red('"mandatory"')
107
115
  })
108
- ];
109
- featureAns = yield prompt_1.default.ask(prompt_1.default.question('features', 'Which are the features you want to setup for this folder?\n This step is optional if you already have a project press ' +
110
- ansi_colors_1.cyan('<return>') +
111
- ' to proceed.\n', {
112
- type: 'checkbox',
113
- choices: featureChoices
114
- }));
116
+ ],
117
+ when: !runtime_store_1.default.get('payload.project.import', false) &&
118
+ typeof feature !== 'string'
119
+ }));
120
+ if (!((_a = featureAns.features) === null || _a === void 0 ? void 0 : _a.length) &&
121
+ (runtime_store_1.default.get('payload.project.import', false) || typeof feature !== 'string')) {
122
+ return saveAndComplete(config);
123
+ }
124
+ if (typeof feature === 'string') {
125
+ featureAns.features = [feature];
115
126
  }
116
- const features = js_1.JS.get(featureAns, 'features', []);
117
- runtime_store_1.default.set('context.features', ['project'].concat(features));
127
+ runtime_store_1.default.set('context.features', featureAns.features);
118
128
  yield (yield Promise.resolve().then(() => __importStar(require('../init')))).default();
119
- yield config.save();
120
- logger_1.message(ansi_colors_1.bold(constants_1.FILENAME.config) + ' file has been successfully created with feature details.');
121
- logger_1.info();
122
- logger_1.success('Catalyst initialization complete!');
129
+ return saveAndComplete(config);
123
130
  }));
@@ -33,7 +33,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  const command_1 = __importDefault(require("../internal/command"));
35
35
  exports.default = new command_1.default('login')
36
- .description('Log the CLI in to your Zoho Catalyst account')
36
+ .description('Log the CLI in to your Catalyst account')
37
37
  .option('--no-localhost', 'login without browser')
38
38
  .option('--force', 'force reauthentication')
39
39
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -33,7 +33,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  const command_1 = __importDefault(require("../internal/command"));
35
35
  exports.default = new command_1.default('logout')
36
- .description('Log the CLI out of your Zoho Catalyst account')
36
+ .description('Log the CLI out of your Catalyst account')
37
37
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
38
38
  const auth = yield Promise.resolve().then(() => __importStar(require('../authentication')));
39
39
  return auth.logout();
@@ -35,10 +35,11 @@ const ansi_colors_1 = require("ansi-colors");
35
35
  const endpoints_1 = require("../../endpoints");
36
36
  const command_1 = __importDefault(require("../../internal/command"));
37
37
  const constants_1 = require("../../util_modules/constants");
38
+ const project_1 = __importDefault(require("../../util_modules/constants/project"));
38
39
  const logger_1 = require("../../util_modules/logger");
39
- const project_1 = require("../../util_modules/project");
40
+ const project_2 = require("../../util_modules/project");
40
41
  exports.default = new command_1.default('project:list')
41
- .description('List the Catalyst projects you have access to')
42
+ .description('List all the Catalyst projects you have access to')
42
43
  .needs('auth', [constants_1.SCOPE.projects])
43
44
  .needs('config', { optional: true, resolveOnNotFound: true })
44
45
  .needs('rc', { optional: true })
@@ -55,19 +56,22 @@ exports.default = new command_1.default('project:list')
55
56
  { hAlign: 'center', content: ansi_colors_1.red.bold('Project Name') },
56
57
  { hAlign: 'center', content: ansi_colors_1.red.bold('Project ID') }
57
58
  ]);
58
- const activeProjectId = project_1.getProjectId(null);
59
- const defaultProjectId = project_1.getDefaultProjectId(null);
59
+ const activeProjectId = project_2.getProjectId(null);
60
+ const defaultProjectId = project_2.getDefaultProjectId(null);
60
61
  projects.forEach((project) => {
61
62
  let displayId = project.id + '';
62
63
  let displayName = project.project_name;
63
- let enhance = null;
64
+ let enhance = '';
64
65
  if (activeProjectId === displayId) {
65
66
  enhance = ' (active)';
66
67
  }
67
68
  if (defaultProjectId === displayId) {
68
- enhance = enhance === null ? ' (base)' : enhance + ' (base)';
69
+ enhance += ' (base)';
69
70
  }
70
- if (enhance !== null) {
71
+ if (project.project_type && !project_1.default.accepted_types.includes(project.project_type)) {
72
+ enhance += `(${project.project_type})`;
73
+ }
74
+ if (enhance !== '') {
71
75
  displayName = ansi_colors_1.cyan(displayName + enhance);
72
76
  displayId = ansi_colors_1.cyan(displayId + '');
73
77
  }
@@ -17,7 +17,7 @@ const constants_1 = require("../../util_modules/constants");
17
17
  const logger_1 = require("../../util_modules/logger");
18
18
  const project_1 = require("../../util_modules/project");
19
19
  exports.default = new command_1.default('project:reset')
20
- .description('Clear an active selection of project and reset to base project')
20
+ .description('Clear an active project selection and reset to the base project')
21
21
  .needs('auth', [constants_1.SCOPE.projects])
22
22
  .needs('config', { optional: true, resolveOnNotFound: true })
23
23
  .needs('rc')