zcatalyst-cli 1.18.0-beta.4 → 1.18.0-beta.6

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 (36) hide show
  1. package/docs/commands/ds/import.toml +5 -5
  2. package/docs/commands/zest/generate/index.toml +4 -0
  3. package/lib/authentication/login.js +2 -1
  4. package/lib/code-deck.js +2 -1
  5. package/lib/commands/appsail/add.js +1 -1
  6. package/lib/commands/ds/import.js +37 -21
  7. package/lib/commands/event/generate/index.js +14 -2
  8. package/lib/commands/iac/export.js +5 -1
  9. package/lib/commands/iac/import.js +4 -1
  10. package/lib/commands/index.js +1 -0
  11. package/lib/commands/zest/generate/index.js +304 -0
  12. package/lib/endpoints/index.js +15 -1
  13. package/lib/endpoints/lib/ds-bulk.js +1 -0
  14. package/lib/endpoints/lib/stratus.js +63 -0
  15. package/lib/endpoints/lib/zest.js +124 -0
  16. package/lib/event_generate/stratus.js +52 -0
  17. package/lib/fn-utils/lib/common.js +6 -1
  18. package/lib/init/features/project.js +1 -0
  19. package/lib/internal/api.js +2 -2
  20. package/lib/prompt/index.js +5 -2
  21. package/lib/prompt/types/search-box.js +281 -0
  22. package/lib/serve/server/lib/appsail/index.js +1 -1
  23. package/lib/serve/server/lib/java/index.js +1 -1
  24. package/lib/serve/server/lib/master/utils.js +1 -1
  25. package/lib/serve/server/lib/node/index.js +1 -1
  26. package/lib/serve/server/lib/node/server/package-lock.json +12 -0
  27. package/lib/serve/server/lib/python/index.js +1 -1
  28. package/lib/shell/dependencies/http-functions.js +1 -1
  29. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +1 -0
  30. package/lib/shell/dependencies/local-function.js +3 -3
  31. package/lib/util_modules/constants/lib/dc-type.js +8 -0
  32. package/lib/util_modules/constants/lib/event-action.js +1 -0
  33. package/lib/util_modules/constants/lib/event-source.js +1 -0
  34. package/lib/util_modules/constants/lib/scopes.js +14 -3
  35. package/lib/util_modules/constants/lib/urls.js +8 -0
  36. package/package.json +3 -2
@@ -6,15 +6,15 @@ link = 'https://www.zoho.com/catalyst/help/cli-import-export.html#Import'
6
6
  [IMP-2]
7
7
  context = '''File needed for import! A CSV file is mandatory for executing this command.'''
8
8
  aid = '''Please provide the path of the CSV file present in the local machine with the command, or
9
- provide the file_id of the file that is already uploaded to the File Store in the config json.'''
9
+ provide the object_details of the file that is already uploaded to the Stratus in the config json.'''
10
10
  link = 'https://www.zoho.com/catalyst/help/cli-import-export.html#CSV'
11
11
 
12
12
  [IMP-3]
13
- context = '''No Folders present in the File Store! You must have atleast one folder in the File Store to upload the CSV file.'''
14
- aid = '''Please create atleast one folder in the Catalyst File Store to proceed.'''
13
+ context = '''No Buckets present in the Stratus! You must have atleast one bucket in the Stratus to upload the CSV file.'''
14
+ aid = '''Please create atleast one bucket in the Catalyst Stratus to proceed.'''
15
15
  link = 'https://www.zoho.com/catalyst/help/file-store.html#Creating'
16
16
 
17
17
  [IMP-4]
18
- context = '''The folder ${arg[0]} specified in the ${arg[1]} config file does not exists in the Catalyst file store.'''
19
- aid = '''Please specify the name of a folder that's already present in Catalyst file store. Alternatively, you can try uploading the ${arg[2]} file to a folder in the Catalyst file store and specify it's ${arg[3]} as ${arg[4]} in the ${arg[1]} config file.'''
18
+ context = '''The bucket ${arg[0]} specified in the ${arg[1]} config file does not exists in the Catalyst Stratus.'''
19
+ aid = '''Please specify the name of a bucket that's already present in Catalyst Stratus. Alternatively, you can try uploading the ${arg[2]} file to a bucket in the Catalyst Stratus and specify it's ${arg[3]} as ${arg[4]} in the ${arg[1]} config file.'''
20
20
  link = 'https://catalyst.zoho.com/help/cli-import-export.html#Import_File_Format'
@@ -0,0 +1,4 @@
1
+ [ZEST-GEN-1]
2
+ context = '''Oops! It's looks like you haven't created any specification.'''
3
+ aid = '''Please visit the below link to add a zest specifications.'''
4
+ link = 'https://docs-ea.catalyst.localzoho.com/en/zest/help/introduction/'
@@ -36,7 +36,8 @@ exports.missingScopes = {
36
36
  [constants_1.DC_TYPE.in.value]: ['dataverse'],
37
37
  [constants_1.DC_TYPE.eu.value]: ['quick_ml', 'dataverse'],
38
38
  [constants_1.DC_TYPE.au.value]: ['dataverse'],
39
- [constants_1.DC_TYPE.ca.value]: ['quick_ml', 'dataverse']
39
+ [constants_1.DC_TYPE.ca.value]: ['quick_ml', 'dataverse'],
40
+ [constants_1.DC_TYPE.sa.value]: ['quick_ml', 'dataverse']
40
41
  };
41
42
  class Login {
42
43
  constructor(localhost = true, user = true) {
package/lib/code-deck.js CHANGED
@@ -20,6 +20,7 @@ const prompt_1 = __importDefault(require("./prompt"));
20
20
  const tree_1 = require("./prompt/types/tree");
21
21
  const runtime_store_1 = __importDefault(require("./runtime-store"));
22
22
  const logger_1 = require("./util_modules/logger");
23
+ const project_1 = require("./util_modules/project");
23
24
  const shell_1 = require("./util_modules/shell");
24
25
  function listenDeploy(id, gitUrl) {
25
26
  return __awaiter(this, void 0, void 0, function* () {
@@ -31,7 +32,7 @@ function listenDeploy(id, gitUrl) {
31
32
  arr.push(allGlobalOpts[key]);
32
33
  }
33
34
  return arr;
34
- }, ['--id', id]);
35
+ }, ['--id', id, '--org', (0, project_1.getEnvId)() || '']);
35
36
  const childRes = yield (0, shell_1.spawn)('catalyst', ['iac:status', 'import', ...optsArr], {
36
37
  shell: true,
37
38
  stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
@@ -50,7 +50,7 @@ exports.default = new command_1.default('appsail:add')
50
50
  const config = runtime_store_1.default.get('config');
51
51
  yield (yield Promise.resolve().then(() => __importStar(require('../../init/features')))).appsail();
52
52
  yield config.save();
53
- (0, logger_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) + ' file has been successfully updated with functions details.');
53
+ (0, logger_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) + ' file has been successfully updated with appsail details.');
54
54
  (0, logger_1.info)();
55
55
  (0, logger_1.success)('AppSail service successfully linked');
56
56
  }));
@@ -45,6 +45,7 @@ exports.default = new command_1.default('ds:import [file]')
45
45
  .needs('config', { optional: true })
46
46
  .needs('rc', { optional: true })
47
47
  .action((uploadFile) => __awaiter(void 0, void 0, void 0, function* () {
48
+ var _a, _b, _c;
48
49
  const env = (0, option_1.getOptionValue)('production', false) ? 'Production' : 'Development';
49
50
  const configPath = (0, option_1.getOptionValue)('config', false);
50
51
  const importConfig = configPath ? yield getWriteConfigFromPath(configPath) : {};
@@ -52,44 +53,59 @@ exports.default = new command_1.default('ds:import [file]')
52
53
  if (!tableId) {
53
54
  throw new error_1.default('Table identifier missing', { exit: 0, errorId: 'IMP-1' });
54
55
  }
55
- if (!importConfig.file_id) {
56
+ if (!importConfig.file_id && !((_a = importConfig.object_details) === null || _a === void 0 ? void 0 : _a.object_key)) {
56
57
  if (!uploadFile) {
57
58
  throw new error_1.default('No CSV file provided', { exit: 0, errorId: 'IMP-2' });
58
59
  }
59
- const fileAPI = yield (0, endpoints_1.filestoreAPI)({ env });
60
- const allFolders = (yield fileAPI.getAllFolders());
61
- if (allFolders.length > 0) {
62
- const choices = allFolders.map((folderDetail) => prompt_1.default.choice(folderDetail.folder_name, {
63
- value: folderDetail
60
+ const bucketAPI = yield (0, endpoints_1.stratusAPI)({ env });
61
+ const allBuckets = (yield bucketAPI.getAllBuckets());
62
+ if (allBuckets.length > 0) {
63
+ const choices = allBuckets.map((bucketDetail) => prompt_1.default.choice(bucketDetail.bucket_name, {
64
+ value: bucketDetail
64
65
  }));
65
- const folderAns = yield prompt_1.default.ask(prompt_1.default.question('folder', 'Select a folder to which you want to upload the file to : ', {
66
+ const bucketAns = yield prompt_1.default.ask(prompt_1.default.question('bucket', 'Select a bucket to which you want to upload the object to : ', {
66
67
  type: 'list',
67
68
  choices,
68
- when: !importConfig.folder_id
69
+ when: !((_b = importConfig.object_details) === null || _b === void 0 ? void 0 : _b.bucket_name)
69
70
  }));
70
- folderAns.folder =
71
- folderAns.folder === undefined
72
- ? allFolders.find((folderDetails) => folderDetails.folder_name === importConfig.folder_id ||
73
- folderDetails.id === importConfig.folder_id)
74
- : folderAns.folder;
75
- if (!folderAns.folder) {
76
- throw new error_1.default('Folder not present', {
71
+ const bucket = bucketAns.bucket;
72
+ const bucketName = bucket.bucket_name === undefined
73
+ ? allBuckets.find((bucketDetails) => {
74
+ var _a;
75
+ return bucketDetails.bucket_name ===
76
+ ((_a = importConfig.object_details) === null || _a === void 0 ? void 0 : _a.bucket_name);
77
+ })
78
+ : bucket.bucket_name;
79
+ if (!bucketName) {
80
+ throw new error_1.default('Bucket not present', {
77
81
  exit: 1,
78
82
  errorId: 'IMP-4',
79
83
  arg: [
80
- ansi_colors_1.bold.red(importConfig.folder_id || ''),
84
+ ansi_colors_1.bold.red(((_c = importConfig.object_details) === null || _c === void 0 ? void 0 : _c.bucket_name) || ''),
81
85
  (0, ansi_colors_1.italic)(configPath || ''),
82
86
  (0, ansi_colors_1.bold)(uploadFile),
83
- (0, ansi_colors_1.bold)('Unique ID'),
84
- (0, ansi_colors_1.italic)('file_id')
87
+ (0, ansi_colors_1.bold)('Details(bucket_name and object_key)'),
88
+ (0, ansi_colors_1.italic)('object_details')
85
89
  ]
86
90
  });
87
91
  }
88
- const fileDetails = (yield fileAPI.uploadFile(folderAns.folder.id, fs_1.SYNC.getReadStream((0, path_1.resolve)(uploadFile))));
89
- importConfig.file_id = fileDetails.id;
92
+ try {
93
+ yield bucketAPI.uploadObject(bucketName, uploadFile, fs_1.SYNC.getReadStream((0, path_1.resolve)(uploadFile)));
94
+ }
95
+ catch (err) {
96
+ throw new error_1.default('Error while uploading the object to the stratus. Use --verbose for error details', {
97
+ exit: 1,
98
+ original: err
99
+ });
100
+ }
101
+ const objDetail = {
102
+ bucket_name: bucketName,
103
+ object_key: uploadFile
104
+ };
105
+ importConfig.object_details = objDetail;
90
106
  }
91
107
  else {
92
- throw new error_1.default('folder needed', { exit: 0, errorId: 'IMP-3' });
108
+ throw new error_1.default('bucket needed', { exit: 0, errorId: 'IMP-3' });
93
109
  }
94
110
  }
95
111
  const bulkAPI = yield (0, endpoints_1.bulkDSAPI)({ env });
@@ -149,10 +149,22 @@ exports.default = new command_1.default('event:generate <source> <action>')
149
149
  break;
150
150
  case 'action':
151
151
  const eventRefArr = constants_1.EVENT_REF[remoteSourceName];
152
- const remoteRefAction = action.charAt(0).toUpperCase() + action.slice(1);
152
+ const remoteRefAction = action
153
+ .split('_')
154
+ .map((act) => act.charAt(0).toUpperCase() + act.slice(1))
155
+ .join(' ');
153
156
  (0, logger_1.debug)(`action provided is : ${remoteRefAction}`);
154
157
  const indexOfAction = eventRefArr.indexOf(remoteRefAction);
155
158
  if (indexOfAction < 0) {
159
+ const availableActions = eventRefArr
160
+ .map((act) => {
161
+ act = act
162
+ .split(' ')
163
+ .map((act) => act.charAt(0).toUpperCase() + act.slice(1))
164
+ .join('_');
165
+ return '* ' + act;
166
+ })
167
+ .join('\n');
156
168
  throw new error_1.default('Action incompatible with the source ' + eventRefArr, {
157
169
  exit: 1,
158
170
  errorId: 'IDX-6',
@@ -160,7 +172,7 @@ exports.default = new command_1.default('event:generate <source> <action>')
160
172
  (0, ansi_colors_1.bold)(action),
161
173
  ansi_colors_1.bold.red('X'),
162
174
  (0, ansi_colors_1.bold)(source),
163
- (0, ansi_colors_1.bold)(eventRefArr.map((act) => '* ' + act).join('\n'))
175
+ (0, ansi_colors_1.bold)(availableActions)
164
176
  ]
165
177
  });
166
178
  }
@@ -73,7 +73,11 @@ exports.default = new command_1.default('iac:export')
73
73
  arr.push(allGlobalOpts[key]);
74
74
  }
75
75
  return arr;
76
- }, (env === 'Production' ? ['--production'] : []));
76
+ }, [
77
+ '--org',
78
+ (0, project_1.getEnvId)(),
79
+ ...(env === 'Production' ? ['--production'] : [])
80
+ ]);
77
81
  (0, shell_1.spawn)('catalyst', ['iac:status', 'export', ...optsArr], {
78
82
  shell: true,
79
83
  stdio: 'inherit'
@@ -58,6 +58,7 @@ const logger_1 = require("../../util_modules/logger");
58
58
  const option_1 = require("../../util_modules/option");
59
59
  const shell_1 = require("../../util_modules/shell");
60
60
  const server_js_1 = require("../../util_modules/server.js");
61
+ const project_1 = require("../../util_modules/project");
61
62
  const getZipAndTemplate = (filePath, stagedDeploy) => __awaiter(void 0, void 0, void 0, function* () {
62
63
  const zipFile = filePath
63
64
  ? yield ASYNC.readFile((0, utils_js_1.untildify)(filePath), 'buffer')
@@ -84,6 +85,8 @@ const ensureUserAction = (deployRes) => __awaiter(void 0, void 0, void 0, functi
84
85
  const callbackPort = yield port_resolver_1.default.getFreePort(3000, 10, false);
85
86
  const accessUrl = new url_1.URL(`/baas/v1/project/import/${deployRes.id}/deploy`, `${constants_1.ORIGIN.admin}`);
86
87
  accessUrl.searchParams.set('redirect_url', `http://localhost:${callbackPort}/success`);
88
+ const orgId = (0, project_1.getEnvId)();
89
+ orgId && accessUrl.searchParams.set('catalyst_org', orgId);
87
90
  const server = (0, http_1.createServer)((req, resp) => __awaiter(void 0, void 0, void 0, function* () {
88
91
  try {
89
92
  if (req.url !== '/success') {
@@ -136,7 +139,7 @@ const ensureUserAction = (deployRes) => __awaiter(void 0, void 0, void 0, functi
136
139
  arr.push(allGlobalOpts[key]);
137
140
  }
138
141
  return arr;
139
- }, ['--id', deployRes.id]);
142
+ }, ['--id', deployRes.id, '--org', (0, project_1.getEnvId)() || '']);
140
143
  yield (0, shell_1.spawn)('catalyst', ['iac:status', 'import', ...optsArr], {
141
144
  shell: true,
142
145
  stdio: 'inherit'
@@ -80,6 +80,7 @@ exports.default = (client) => {
80
80
  loadCommand('codelib:install'),
81
81
  loadCommand('event:generate'),
82
82
  loadCommand('event:generate:integ'),
83
+ loadCommand('zest:generate'),
83
84
  loadCommand('event:generate:job'),
84
85
  loadCommand('serve'),
85
86
  loadCommand('deploy'),
@@ -0,0 +1,304 @@
1
+ 'use strict';
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const command_1 = __importDefault(require("../../../internal/command"));
39
+ const constants_1 = require("../../../util_modules/constants");
40
+ const prompt_1 = __importDefault(require("../../../prompt"));
41
+ const js_1 = require("../../../util_modules/js");
42
+ const endpoints_1 = require("../../../endpoints");
43
+ const runtime_store_1 = __importDefault(require("../../../runtime-store"));
44
+ const archiver_1 = __importDefault(require("../../../archiver"));
45
+ const logger_1 = require("../../../util_modules/logger");
46
+ const inquirer_1 = __importStar(require("inquirer"));
47
+ const error_1 = __importDefault(require("../../../error"));
48
+ const project_1 = require("../../../util_modules/project");
49
+ const features_1 = require("../../../init/features");
50
+ const path_1 = require("path");
51
+ const throbber_1 = __importDefault(require("../../../throbber"));
52
+ const config_1 = require("../../../util_modules/config");
53
+ const common_1 = require("../../../init/util/common");
54
+ const ansi_colors_1 = require("ansi-colors");
55
+ const fs_1 = require("../../../util_modules/fs");
56
+ const console_1 = require("console");
57
+ function getSpecification(specs = []) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const res = (yield (yield (0, endpoints_1.zestAPI)()).getSpecifications());
60
+ if (!res) {
61
+ return specs;
62
+ }
63
+ specs.push(...res.specifications);
64
+ if (res.info.more_records) {
65
+ yield getSpecification(specs);
66
+ }
67
+ return specs;
68
+ });
69
+ }
70
+ function searchSpecification(filter, specArray = []) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ if (filter) {
73
+ const response = [];
74
+ specArray.forEach((spec) => {
75
+ if (spec.name.includes(filter)) {
76
+ response.push(spec);
77
+ }
78
+ });
79
+ return response;
80
+ }
81
+ return specArray;
82
+ });
83
+ }
84
+ function pollScheduledJob(job_id) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const throbber = throbber_1.default.getInstance();
87
+ try {
88
+ const res = (yield (yield (0, endpoints_1.zestAPI)()).getScheduledJob(job_id));
89
+ const status = js_1.JS.capitalize(res.scheduled_jobs[0].status);
90
+ if (status === 'Completed') {
91
+ throbber.succeed('processing', { text: `Status >> ${status}` });
92
+ return res;
93
+ }
94
+ throbber.add('processing', { text: `Status >> ${status}` });
95
+ if (status === 'Failed') {
96
+ throbber.fail('processing', { text: `Status >> ${status}` });
97
+ throw new error_1.default('zest generation failed', {
98
+ exit: 2,
99
+ original: `${res.scheduled_jobs[0].action_info.failure_reason}`
100
+ });
101
+ }
102
+ yield js_1.JS.sleep(1000);
103
+ }
104
+ catch (err) {
105
+ throw new error_1.default('Error while processing scheduled job', {
106
+ exit: 2,
107
+ original: err
108
+ });
109
+ }
110
+ return yield pollScheduledJob(job_id);
111
+ });
112
+ }
113
+ function downloadSourceCode(fileId, outputDir, srcType, srcName) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ const zestZip = (yield (yield (0, endpoints_1.zestAPI)()).getFile(fileId, srcType, srcName));
116
+ yield new archiver_1.default().load(zestZip).extract(outputDir).finalize();
117
+ });
118
+ }
119
+ exports.default = new command_1.default('zest:generate')
120
+ .description('Generate the functions or appsail source code for your ZEST Specifications')
121
+ .needs('auth', [
122
+ constants_1.SCOPE.zest_spec_all,
123
+ constants_1.SCOPE.zest_schedule_job_read,
124
+ constants_1.SCOPE.zest_spec_all,
125
+ constants_1.SCOPE.zest_spec_src_action
126
+ ])
127
+ .needs('config', { optional: true })
128
+ .needs('rc', { skipOrgCheck: false })
129
+ .action(() => __awaiter(void 0, void 0, void 0, function* () {
130
+ var _a;
131
+ const specArray = yield getSpecification();
132
+ if (specArray.length === 0) {
133
+ throw new error_1.default('No Specifications Found', {
134
+ exit: 1,
135
+ errorId: 'ZEST-GEN-1'
136
+ });
137
+ }
138
+ yield prompt_1.default.register('search-box');
139
+ const specName = yield inquirer_1.default.prompt([
140
+ {
141
+ type: 'search-box',
142
+ name: 'specs',
143
+ searchable: true,
144
+ pageSize: 10,
145
+ highlight: true,
146
+ notFoundMsg: 'No specifications found!',
147
+ searchMsg: 'Search specifications...',
148
+ message: 'Please search and select the specifications(Use space key to select)',
149
+ source(_answersSoFar, input) {
150
+ input || (input = '');
151
+ return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
152
+ const fuzzyResult = yield searchSpecification(input, specArray);
153
+ const data = fuzzyResult.map((element) => {
154
+ return {
155
+ name: `${element.name}(${element.version})`,
156
+ value: element.id
157
+ };
158
+ });
159
+ resolve(data);
160
+ }));
161
+ },
162
+ validate: (ansArr) => {
163
+ if (js_1.JS.isEmpty(ansArr)) {
164
+ return 'Must select one specification.';
165
+ }
166
+ return true;
167
+ }
168
+ }
169
+ ]);
170
+ const srcTypeAns = yield prompt_1.default.ask(prompt_1.default.question('source', 'Please specify which source type you want to download', {
171
+ type: 'list',
172
+ choices: [
173
+ prompt_1.default.choice('Function', {
174
+ value: 'functions'
175
+ }),
176
+ prompt_1.default.choice('AppSail', {
177
+ value: 'appsail'
178
+ })
179
+ ]
180
+ }));
181
+ const srcType = srcTypeAns.source;
182
+ const sourceLabel = srcType.replace('functions', 'function');
183
+ const runtimeChoices = yield (0, common_1.getRuntimeChoices)({ fnType: 'aio' });
184
+ const ignoreRuntimes = ['node14', 'node12', 'node20'];
185
+ const stackChoices = runtimeChoices.filter((choice) => {
186
+ if (!(choice instanceof inquirer_1.Separator)) {
187
+ return !ignoreRuntimes.includes(choice.value.runtime);
188
+ }
189
+ return choice;
190
+ });
191
+ const srcStackAns = yield prompt_1.default.ask(prompt_1.default.question('stack', `Please select the language for your ${sourceLabel}`, {
192
+ type: 'list',
193
+ choices: stackChoices.map((choice) => {
194
+ if (!(choice instanceof inquirer_1.Separator)) {
195
+ return choice;
196
+ }
197
+ return choice;
198
+ }),
199
+ when: () => {
200
+ return runtimeChoices.length > 1;
201
+ }
202
+ }));
203
+ const srcStack = srcStackAns.stack.runtime;
204
+ const existingSails = config_1.appSailConfig.raw() || [];
205
+ const existingFuncs = ((_a = config_1.functionsConfig.raw()) === null || _a === void 0 ? void 0 : _a.targets) || [];
206
+ const source = yield prompt_1.default.ask(prompt_1.default.question('name', `Please provide a name for your ${(0, ansi_colors_1.bold)(sourceLabel)} `, {
207
+ type: 'input',
208
+ default: 'sample',
209
+ validate: (input) => __awaiter(void 0, void 0, void 0, function* () {
210
+ if (input === '') {
211
+ return 'Please provide a valid name.';
212
+ }
213
+ if (input === '' || !input.match(constants_1.REGEX.functions.package.name)) {
214
+ return `Special characters are not allowed. Includes only alphabets, numbers, hyphen and underscores.`;
215
+ }
216
+ if (srcType === 'functions' &&
217
+ existingFuncs.findIndex((func) => func === input) !== -1) {
218
+ return 'function name already exists';
219
+ }
220
+ if (srcType === 'appsail' &&
221
+ existingSails.findIndex((appSail) => appSail.name === input) !== -1) {
222
+ return 'appsail name already exists';
223
+ }
224
+ return true;
225
+ })
226
+ }));
227
+ const srcName = source.name;
228
+ let sourceCodeRes;
229
+ const resources = [];
230
+ specName.specs.forEach((element) => {
231
+ resources.push({ id: element });
232
+ });
233
+ const config = runtime_store_1.default.get('config');
234
+ let payload, outputDir;
235
+ if (srcType === 'appsail') {
236
+ const generateAppsailParams = {
237
+ resources: resources,
238
+ stack: srcStack,
239
+ name: srcName
240
+ };
241
+ outputDir = (0, project_1.resolveProjectPath)(`appsail-${srcName}`);
242
+ payload = {
243
+ source: outputDir,
244
+ name: srcName
245
+ };
246
+ if (srcStackAns.stack.lang.startsWith('java')) {
247
+ const basePackage = yield prompt_1.default.ask(prompt_1.default.question('basePkg', 'Please specify the base package name', {
248
+ type: 'input',
249
+ default: 'com.zoho'
250
+ }));
251
+ const install = yield prompt_1.default.ask(prompt_1.default.question('consent', 'Do you wish to install dependencies ? ', {
252
+ type: 'confirm',
253
+ default: true
254
+ }));
255
+ Object.assign(generateAppsailParams, {
256
+ with_dependency: install.consent,
257
+ config: {
258
+ base_package: basePackage.basePkg
259
+ }
260
+ });
261
+ }
262
+ sourceCodeRes = yield (yield (0, endpoints_1.zestAPI)()).generateAppsail(generateAppsailParams);
263
+ }
264
+ else {
265
+ const functionsDirPath = (0, project_1.resolveProjectPath)(config.get('functions.source') || constants_1.FOLDERNAME.functions);
266
+ outputDir = (0, path_1.join)(functionsDirPath, srcName);
267
+ payload = {
268
+ source: outputDir,
269
+ name: srcName,
270
+ stack: srcStack,
271
+ type: 'aio'
272
+ };
273
+ sourceCodeRes = yield (yield (0, endpoints_1.zestAPI)()).generateFunction(resources, srcStack, srcName);
274
+ }
275
+ const folderExists = yield fs_1.ASYNC.dirExists(outputDir);
276
+ const overwriteAns = folderExists
277
+ ? yield prompt_1.default.ask(prompt_1.default.question('overwrite', 'Directory ' + (0, ansi_colors_1.underline)(outputDir) + ' already exists. Overwrite ?', {
278
+ type: 'confirm',
279
+ defaultAns: false
280
+ }))
281
+ : { overwrite: true };
282
+ if (!overwriteAns.overwrite) {
283
+ (0, logger_1.labeled)('zest', `${sourceLabel} generation skipped.`).WARN();
284
+ return;
285
+ }
286
+ yield fs_1.ASYNC.deleteDir(outputDir);
287
+ runtime_store_1.default.set(`payload.${srcType}.targets`, [payload]);
288
+ const job_id = sourceCodeRes.job_id;
289
+ const throbber = throbber_1.default.getInstance();
290
+ (0, console_1.info)('\n' + (0, ansi_colors_1.white)('==> ') + `Generating ${js_1.JS.capitalize(sourceLabel)}`);
291
+ const fileId = yield pollScheduledJob(job_id).then((data) => {
292
+ throbber.remove('processing');
293
+ return data.scheduled_jobs[0].action_info.file_id;
294
+ });
295
+ (0, console_1.info)('\n' + (0, ansi_colors_1.white)('==> ') + `Downloading ${js_1.JS.capitalize(sourceLabel)}`);
296
+ yield downloadSourceCode(fileId, outputDir, sourceLabel, srcName);
297
+ (0, features_1.setCatalystConfig)(srcType, true);
298
+ yield config.save();
299
+ (0, console_1.info)();
300
+ (0, logger_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) +
301
+ ` file has been successfully updated with ${sourceLabel} details.`);
302
+ (0, console_1.info)();
303
+ (0, logger_1.success)(`Zest successfully generated in ${(0, ansi_colors_1.bold)((0, path_1.join)(outputDir))}.`);
304
+ }));
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.tunnelAPI = exports.commonAPI = exports.jobScheduling = exports.codeDeck = exports.gitHubAPI = exports.appSailAPI = exports.logAPI = exports.eventBusAPI = exports.functionsAPI = exports.applogicAPI = exports.bulkDSAPI = exports.apigAPI = exports.clientAPI = exports.datastoreAPI = exports.zcqlAPI = exports.queueAPI = exports.filestoreAPI = exports.cacheAPI = exports.sdkAPI = exports.envAPI = exports.projectAPI = exports.orgAPI = void 0;
35
+ exports.tunnelAPI = exports.commonAPI = exports.jobScheduling = exports.codeDeck = exports.gitHubAPI = exports.stratusAPI = exports.zestAPI = exports.appSailAPI = exports.logAPI = exports.eventBusAPI = exports.functionsAPI = exports.applogicAPI = exports.bulkDSAPI = exports.apigAPI = exports.clientAPI = exports.datastoreAPI = exports.zcqlAPI = exports.queueAPI = exports.filestoreAPI = exports.cacheAPI = exports.sdkAPI = exports.envAPI = exports.projectAPI = exports.orgAPI = void 0;
36
36
  const project_1 = require("../util_modules/project");
37
37
  function orgAPI({ auth = true } = {}) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
@@ -156,6 +156,20 @@ function appSailAPI({ auth = true, projectId = (0, project_1.getProjectId)(), en
156
156
  });
157
157
  }
158
158
  exports.appSailAPI = appSailAPI;
159
+ function zestAPI({ auth = true, projectId = (0, project_1.getProjectId)(), env = (0, project_1.getEnvName)() } = {}) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ const zest = (yield Promise.resolve().then(() => __importStar(require('./lib/zest.js')))).default;
162
+ return new zest(projectId, { authNeeded: auth, env, isExternal: true });
163
+ });
164
+ }
165
+ exports.zestAPI = zestAPI;
166
+ function stratusAPI({ auth = true, projectId = (0, project_1.getProjectId)(), env = (0, project_1.getEnvName)() } = {}) {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ const stratus = (yield Promise.resolve().then(() => __importStar(require('./lib/stratus')))).default;
169
+ return new stratus(projectId, { authNeeded: auth, env });
170
+ });
171
+ }
172
+ exports.stratusAPI = stratusAPI;
159
173
  function gitHubAPI() {
160
174
  return __awaiter(this, void 0, void 0, function* () {
161
175
  const gitHub = (yield Promise.resolve().then(() => __importStar(require('./lib/git-hub')))).default;
@@ -50,6 +50,7 @@ class BulkDS {
50
50
  body: {
51
51
  table_identifier: table,
52
52
  operation: config === null || config === void 0 ? void 0 : config.operation,
53
+ object_details: config === null || config === void 0 ? void 0 : config.object_details,
53
54
  file_id: config === null || config === void 0 ? void 0 : config.file_id,
54
55
  callback: config === null || config === void 0 ? void 0 : config.callback,
55
56
  find_by: config === null || config === void 0 ? void 0 : config.find_by,
@@ -0,0 +1,63 @@
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
+ const error_1 = __importDefault(require("../../error"));
16
+ const api_1 = __importDefault(require("../../internal/api"));
17
+ const logger_1 = require("../../util_modules/logger");
18
+ const mime_types_1 = __importDefault(require("mime-types"));
19
+ const constants_1 = require("../../util_modules/constants");
20
+ class Stratus {
21
+ constructor(projectId, opts) {
22
+ this.opts = opts;
23
+ this.projectId = projectId;
24
+ }
25
+ getAllBuckets() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const res = yield new api_1.default(this.opts).get(`/baas/v1/project/${this.projectId}/bucket`);
28
+ if (res.body && res.body.data) {
29
+ return res.body.data;
30
+ }
31
+ (0, logger_1.debug)('get all buckets response from server : ' + res.body);
32
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
33
+ exit: 2
34
+ });
35
+ });
36
+ }
37
+ uploadObject(bucketName, objectName, fileStream) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const extension = objectName.substring(objectName.lastIndexOf('.') + 1).toLowerCase();
40
+ const contentType = mime_types_1.default.lookup(extension + '');
41
+ const res = yield new api_1.default(Object.assign({ origin: `https://${bucketName}` +
42
+ (this.opts.env === 'Development'
43
+ ? '-' + this.opts.env.toLowerCase()
44
+ : '') +
45
+ constants_1.ORIGIN.stratusSuffix, isExternal: true }, this.opts)).put(`/${objectName}`, {
46
+ body: fileStream,
47
+ headers: {
48
+ compress: 'false',
49
+ 'Content-Type': contentType || 'application/octet-stream'
50
+ },
51
+ json: false
52
+ });
53
+ if (res.status === 200) {
54
+ return res.status;
55
+ }
56
+ (0, logger_1.debug)('upload object response from server : ' + res);
57
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
58
+ exit: 2
59
+ });
60
+ });
61
+ }
62
+ }
63
+ exports.default = Stratus;