zcatalyst-cli 1.17.6 → 1.18.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 (124) hide show
  1. package/docs/commands/event/generate/job.toml +7 -0
  2. package/docs/commands/functions/shell.toml +4 -0
  3. package/docs/endpoints/lib/job-scheduling.toml +3 -0
  4. package/docs/internal/command.toml +5 -0
  5. package/docs/shell/dependencies/tunnel-server.toml +4 -0
  6. package/docs/shell/index.toml +7 -0
  7. package/lib/appsail-utils.js +3 -3
  8. package/lib/authentication/index.js +1 -0
  9. package/lib/command_needs/rc.js +1 -1
  10. package/lib/commands/appsail/add.js +1 -0
  11. package/lib/commands/client/setup.js +1 -0
  12. package/lib/commands/event/generate/job.js +82 -0
  13. package/lib/commands/functions/add.js +1 -0
  14. package/lib/commands/functions/delete.js +2 -4
  15. package/lib/commands/functions/setup.js +1 -0
  16. package/lib/commands/functions/shell.js +98 -1
  17. package/lib/commands/index.js +1 -0
  18. package/lib/commands/init.js +2 -6
  19. package/lib/commands/login.js +1 -0
  20. package/lib/commands/logout.js +1 -0
  21. package/lib/commands/pull.js +1 -0
  22. package/lib/commands/serve.js +2 -8
  23. package/lib/commands/whoami.js +1 -0
  24. package/lib/deploy/features/appsail/index.js +19 -17
  25. package/lib/deploy/features/appsail/utils.js +4 -5
  26. package/lib/endpoints/index.js +15 -1
  27. package/lib/endpoints/lib/appsail.js +7 -1
  28. package/lib/endpoints/lib/job-scheduling.js +61 -0
  29. package/lib/endpoints/lib/sdk.js +2 -2
  30. package/lib/endpoints/lib/tunnel.js +66 -0
  31. package/lib/express_middlewares/logger.js +2 -4
  32. package/lib/fn-utils/lib/common.js +2 -3
  33. package/lib/fn-utils/lib/java.js +1 -1
  34. package/lib/fn-utils/lib/python.js +2 -2
  35. package/lib/fn-watcher.js +1 -1
  36. package/lib/init/dependencies/python/ensure-python.js +6 -8
  37. package/lib/init/features/appsail/index.js +14 -10
  38. package/lib/init/features/functions/index.js +4 -0
  39. package/lib/init/features/functions/languages/python.js +21 -5
  40. package/lib/internal/api.js +17 -1
  41. package/lib/internal/command.js +28 -5
  42. package/lib/port-resolver.js +1 -1
  43. package/lib/repl-server.js +9 -0
  44. package/lib/serve/features/appsail.js +2 -3
  45. package/lib/serve/index.js +1 -2
  46. package/lib/serve/server/index.js +8 -9
  47. package/lib/serve/server/lib/appsail/index.js +24 -34
  48. package/lib/serve/server/lib/java/aio_server/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  49. package/lib/serve/server/lib/java/aio_server/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  50. package/lib/serve/server/lib/java/aio_server/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  51. package/lib/serve/server/lib/java/index.js +2 -2
  52. package/lib/serve/server/lib/master/appsail.js +53 -0
  53. package/lib/serve/server/lib/master/functions.js +34 -0
  54. package/lib/serve/server/lib/master/index.js +155 -0
  55. package/lib/{express_middlewares/unknownReqProxy.js → serve/server/lib/master/unknown-req-proxy.js} +4 -7
  56. package/lib/serve/server/lib/master/utils.js +130 -0
  57. package/lib/serve/server/lib/master/web-client.js +39 -0
  58. package/lib/serve/server/lib/node/index.js +3 -3
  59. package/lib/serve/server/lib/python/index.js +6 -3
  60. package/lib/shell/dependencies/http-functions.js +21 -8
  61. package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +28 -32
  62. package/lib/shell/dependencies/invoker/bio/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  63. package/lib/shell/dependencies/invoker/bio/node.mjs +2 -2
  64. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +62 -13
  65. package/lib/shell/dependencies/invoker/cron/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  66. package/lib/shell/dependencies/invoker/cron/node.mjs +28 -24
  67. package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +41 -6
  68. package/lib/shell/dependencies/invoker/event/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  69. package/lib/shell/dependencies/invoker/event/node.mjs +23 -9
  70. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +3 -3
  71. package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  72. package/lib/shell/dependencies/invoker/integ/node.mjs +6 -6
  73. package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +254 -0
  74. package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  75. package/lib/shell/dependencies/invoker/job/java/lib/org.json.jar +0 -0
  76. package/lib/shell/dependencies/invoker/job/node.mjs +93 -0
  77. package/lib/shell/dependencies/local-function.js +399 -200
  78. package/lib/shell/dependencies/tunnel-server.js +173 -0
  79. package/lib/shell/index.js +62 -2
  80. package/lib/shell/prepare/languages/index.js +4 -4
  81. package/lib/shell/prepare/languages/java.js +1 -2
  82. package/lib/shell/prepare/languages/python.js +10 -16
  83. package/lib/throbber/index.js +6 -1
  84. package/lib/userConfig.js +7 -1
  85. package/lib/util_modules/config/index.js +1 -1
  86. package/lib/util_modules/config/lib/{appSail.js → appsail.js} +61 -9
  87. package/lib/util_modules/config/lib/client.js +6 -8
  88. package/lib/util_modules/config/lib/functions.js +6 -8
  89. package/lib/util_modules/constants/index.js +3 -1
  90. package/lib/util_modules/constants/lib/default.js +1 -1
  91. package/lib/util_modules/constants/lib/fn-type.js +2 -1
  92. package/lib/util_modules/constants/lib/needed-scopes.js +61 -0
  93. package/lib/util_modules/constants/lib/placeholders.js +6 -0
  94. package/lib/util_modules/constants/lib/ref-mapping.js +2 -1
  95. package/lib/util_modules/constants/lib/remote-mapping.js +2 -1
  96. package/lib/util_modules/constants/lib/scopes.js +9 -1
  97. package/lib/util_modules/constants/lib/template.js +9 -4
  98. package/lib/util_modules/constants/lib/urls.js +16 -0
  99. package/lib/util_modules/fs/lib/async.js +7 -2
  100. package/lib/util_modules/fs/lib/sync.js +12 -1
  101. package/lib/util_modules/server.js +2 -4
  102. package/lib/winston.js +17 -11
  103. package/package.json +1 -1
  104. package/templates/event/job.json +30 -0
  105. package/templates/init/functions/java/job/.classpath +6 -0
  106. package/templates/init/functions/java/job/.project +17 -0
  107. package/templates/init/functions/java/job/catalyst-config.json +11 -0
  108. package/templates/init/functions/java/job/sample.java +34 -0
  109. package/templates/init/functions/node/aio/package.json +1 -1
  110. package/templates/init/functions/node/bio/package.json +1 -1
  111. package/templates/init/functions/node/cron/package.json +1 -1
  112. package/templates/init/functions/node/event/package.json +1 -1
  113. package/templates/init/functions/node/integ/cliq/package.json +1 -1
  114. package/templates/init/functions/node/integ/convokraft/package.json +1 -1
  115. package/templates/init/functions/node/{stream → job}/catalyst-config.json +3 -2
  116. package/templates/init/functions/node/{stream → job}/package.json +1 -1
  117. package/templates/init/functions/node/job/sample.js +28 -0
  118. package/templates/init/functions/node/job/types/job.d.ts +66 -0
  119. package/templates/init/functions/python/job/catalyst-config.json +11 -0
  120. package/templates/init/functions/python/job/requirements.txt +1 -0
  121. package/templates/init/functions/python/job/sample.py +23 -0
  122. package/templates/init.txt +13 -0
  123. package/lib/serve/server/lib/master.js +0 -317
  124. package/templates/init/functions/node/stream/sample.js +0 -15
@@ -0,0 +1,7 @@
1
+ [JOB-1]
2
+ context = '''No Jobpools were present in the development environment for project ${arg[0]}'''
3
+ aid = '''Please visit the below link to create your first jobpool\n${arg[1]}'''
4
+
5
+ [JOB-2]
6
+ context = '''No function Jobpools were present in the development environment for project ${arg[0]}'''
7
+ aid = '''Please visit the below link to create a functions jobpool\n${arg[1]}'''
@@ -0,0 +1,4 @@
1
+ [FSHELL-1]
2
+ context = '''Tunneling has not yet been configured for your project ${arg[0]}.'''
3
+ aid = '''Please visit this link to get started: ${arg[1]}'''
4
+ link = ''
@@ -0,0 +1,3 @@
1
+ [JOB-SCHEDULING-1]
2
+ context = '''The Jobpool ${arg[0]} is not available in the Catalyst Development environment'''
3
+ aid = '''Please select from one of the Jobpools listed below:\n${arg[1]}'''
@@ -2,3 +2,8 @@
2
2
  context = '''Too many arguments specified with the command: ${arg[0]}.'''
3
3
  aid = '''Use ${arg[1]} command to get the usage instructions.'''
4
4
  link = 'https://www.zoho.com/catalyst/help/cli-help.html'
5
+
6
+ [CMD-2]
7
+ context = '''The command ${arg[0]} provided is not supported in CI enviroment.'''
8
+ aid = '''Use '${arg[1]}' to know the commands supported in CI.'''
9
+ link = ''
@@ -0,0 +1,4 @@
1
+ [TUNNEL-1]
2
+ context = '''The port ${arg[0]} provided with the option ${arg[1]} is not available for use.'''
3
+ aid = '''Please specify a different port with the ${arg[1]} option to start the tunneling server.'''
4
+ link = ''
@@ -2,3 +2,10 @@
2
2
  context = '''No valid functions to Serve!'''
3
3
  aid = '''Please rectify the above errors, if any and try once again.'''
4
4
  link = 'https://www.zoho.com/catalyst/help/cli-functions.html#Shell'
5
+
6
+ [SHELL-IDX-2]
7
+ context = '''Cannot enable Tunneling from ZCatalyst CLI.
8
+ Reason: ${arg[0]}
9
+ Error Code: ${arg[1]}'''
10
+ aid = '''Please rectify the above errors and try once again.'''
11
+ link = 'https://www.zoho.com/catalyst/help/cli-functions.html#Shell'
@@ -27,7 +27,7 @@ function filterTargets(allTargets) {
27
27
  return allTargets;
28
28
  }
29
29
  const refined = onlyTargs.reduce((filtered, filter) => {
30
- const targDetailsIdx = allTargets.findIndex((targ) => { var _a; return ((_a = targ.appSail) === null || _a === void 0 ? void 0 : _a.name) === filter; });
30
+ const targDetailsIdx = allTargets.findIndex((targ) => targ.name === filter);
31
31
  if (targDetailsIdx === -1) {
32
32
  filtered.unmatched.push(filter);
33
33
  }
@@ -49,7 +49,7 @@ function filterTargets(allTargets) {
49
49
  if (except !== undefined) {
50
50
  const exceptTargs = getAppSailFilters(except);
51
51
  const refined = exceptTargs.reduce((filtered, filter) => {
52
- const targDetailsIdx = allTargets.findIndex((targ) => { var _a; return ((_a = targ.appSail) === null || _a === void 0 ? void 0 : _a.name) === filter; });
52
+ const targDetailsIdx = allTargets.findIndex((targ) => targ.name === filter);
53
53
  if (targDetailsIdx === -1) {
54
54
  filtered.unmatched.push(filter);
55
55
  }
@@ -72,7 +72,7 @@ exports.filterTargets = filterTargets;
72
72
  function validateAppSail(targDetails) {
73
73
  targDetails.forEach((targ) => {
74
74
  var _a, _b;
75
- if (targ.validity.valid && ((_a = targ.appSail) === null || _a === void 0 ? void 0 : _a.platform) !== 'war' && !((_b = targ.appSail) === null || _b === void 0 ? void 0 : _b.command)) {
75
+ if (targ.validity.valid && ((_a = targ.config) === null || _a === void 0 ? void 0 : _a.platform) !== 'war' && !((_b = targ.config) === null || _b === void 0 ? void 0 : _b.command)) {
76
76
  targ.validity = {
77
77
  valid: false,
78
78
  reason: 'Start-up command missing'
@@ -113,6 +113,7 @@ function login() {
113
113
  const token = config_store_1.default.get(`${activeDC}.credential`);
114
114
  if (user && token && !(0, option_1.getOptionValue)('force', false)) {
115
115
  (0, logger_1.message)('No need to login. Already logged as: ' + ansi_colors_1.default.cyan.bold(user.Email));
116
+ (0, dc_1.updateActiveDC)(activeDC);
116
117
  return;
117
118
  }
118
119
  const ans = yield prompt_1.default.ask(prompt_1.default.question('collectUsage', 'Allow Catalyst to collect CLI error reporting information?', {
@@ -33,7 +33,7 @@ exports.default = ({ optional = false, resolveOnNotFound = false, skipOrgCheck =
33
33
  const globProjectOpt = (0, option_1.getGlobalOptionValue)('project', null);
34
34
  const projectOpt = globProjectOpt
35
35
  ? globProjectOpt
36
- : (0, env_1.getEnvVariable)('CATALYST_PROJECT', null);
36
+ : (0, env_1.getEnvVariable)('CATALYST_PROJECT_ID', (0, env_1.getEnvVariable)('CATALYST_PROJECT', null));
37
37
  const orgApi = yield (0, endpoints_1.orgAPI)();
38
38
  if (orgOpt !== null) {
39
39
  const orgList = yield orgApi.getAllOrgs();
@@ -45,6 +45,7 @@ exports.default = new command_1.default('appsail:add')
45
45
  .needs('auth', [constants_1.SCOPE.functions])
46
46
  .needs('config')
47
47
  .needs('rc')
48
+ .ci(false)
48
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
49
50
  const config = runtime_store_1.default.get('config');
50
51
  yield (yield Promise.resolve().then(() => __importStar(require('../../init/features')))).appsail();
@@ -45,6 +45,7 @@ exports.default = new command_1.default('client:setup')
45
45
  .needs('auth', [constants_1.SCOPE.webapp])
46
46
  .needs('config')
47
47
  .needs('rc')
48
+ .ci(false)
48
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
49
50
  const config = runtime_store_1.default.get('config');
50
51
  yield (yield Promise.resolve().then(() => __importStar(require('../../init/features')))).client();
@@ -0,0 +1,82 @@
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 ansi_colors_1 = require("ansi-colors");
16
+ const endpoints_1 = require("../../../endpoints");
17
+ const error_1 = __importDefault(require("../../../error"));
18
+ const command_1 = __importDefault(require("../../../internal/command"));
19
+ const prompt_1 = __importDefault(require("../../../prompt"));
20
+ const constants_1 = require("../../../util_modules/constants");
21
+ const fs_1 = require("../../../util_modules/fs");
22
+ const project_1 = require("../../../util_modules/project");
23
+ exports.default = new command_1.default('event:generate:job [jobpool_id]')
24
+ .description('Generate sample payloads for job functions')
25
+ .needs('rc')
26
+ .needs('auth')
27
+ .action((jobpoolId) => __awaiter(void 0, void 0, void 0, function* () {
28
+ if (!fs_1.ASYNC.fileExists(constants_1.TEMPLATE.job_data)) {
29
+ throw new error_1.default('Could not read request template', { exit: 2 });
30
+ }
31
+ const jobData = yield fs_1.ASYNC.readFile(constants_1.TEMPLATE.job_data);
32
+ const jobDataJson = JSON.parse(jobData || '');
33
+ const jobpoolAPI = yield (0, endpoints_1.jobScheduling)();
34
+ const jobpoolDetails = jobpoolId
35
+ ? yield jobpoolAPI.getJobpoolDetails(jobpoolId)
36
+ : yield (() => __awaiter(void 0, void 0, void 0, function* () {
37
+ const allJobpoolDetails = yield jobpoolAPI.getJobpoolDetails();
38
+ if (allJobpoolDetails.length === 0) {
39
+ throw new error_1.default('No jobpool present in development environment', {
40
+ exit: 1,
41
+ errorId: 'JOB-1',
42
+ arg: [
43
+ (0, ansi_colors_1.bold)(`${(0, project_1.getProjectName)()} (${(0, project_1.getProjectId)()})`),
44
+ ansi_colors_1.italic.underline(`${constants_1.ORIGIN.console}/baas/${(0, project_1.getEnvId)()}/project/${(0, project_1.getProjectId)()}/Development#/jobscheduling/jobpool`)
45
+ ]
46
+ });
47
+ }
48
+ const jobpoolChoices = allJobpoolDetails.reduce((poolChoices, _pool) => {
49
+ if (_pool.type !== 'Function') {
50
+ return poolChoices;
51
+ }
52
+ poolChoices.push(prompt_1.default.choice(`${_pool.name} [${_pool.id}]`, {
53
+ value: _pool,
54
+ short: _pool.name
55
+ }));
56
+ return poolChoices;
57
+ }, []);
58
+ if (jobpoolChoices.length === 0) {
59
+ throw new error_1.default('No valid function jobpool available in the development environment', {
60
+ exit: 1,
61
+ errorId: 'JOB-2',
62
+ arg: [
63
+ (0, ansi_colors_1.bold)(`${(0, project_1.getProjectName)()} (${(0, project_1.getProjectId)()})`),
64
+ ansi_colors_1.italic.underline(`${constants_1.ORIGIN.console}/baas/${(0, project_1.getEnvId)()}/project/${(0, project_1.getProjectId)()}/Development#/jobscheduling/jobpool`)
65
+ ]
66
+ });
67
+ }
68
+ const jobpoolQuestion = yield prompt_1.default.ask(prompt_1.default.question('details', "Please choose one of the function jobpool's to generate the data", {
69
+ type: 'list',
70
+ choices: jobpoolChoices
71
+ }));
72
+ return jobpoolQuestion.details;
73
+ }))();
74
+ if (jobpoolDetails.type !== 'Function') {
75
+ throw new error_1.default(`The jobpool ${jobpoolId || jobpoolDetails.name || jobpoolDetails.id} is not a function jobpool`, {
76
+ exit: 1
77
+ });
78
+ }
79
+ jobDataJson.job_details.job_meta_details.jobpool_id = jobpoolDetails.id;
80
+ jobDataJson.job_details.job_meta_details.jobpool_details = jobpoolDetails;
81
+ process.stdout.write(JSON.stringify(jobDataJson, null, ' ') + '\n');
82
+ }));
@@ -45,6 +45,7 @@ exports.default = new command_1.default('functions:add')
45
45
  .needs('auth', [constants_1.SCOPE.functions])
46
46
  .needs('config')
47
47
  .needs('rc')
48
+ .ci(false)
48
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
49
50
  const config = runtime_store_1.default.get('config');
50
51
  yield (yield Promise.resolve().then(() => __importStar(require('../../init/features')))).functions(true);
@@ -199,10 +199,8 @@ exports.default = new command_1.default('functions:delete [function_name_or_id]'
199
199
  if (fn.location === remote && fn.id !== undefined) {
200
200
  return fnApi.delete(fn.id + '');
201
201
  }
202
- else {
203
- if (fn.source) {
204
- return (0, common_1.deleteFunctionLocal)(fn.source);
205
- }
202
+ if (fn.source) {
203
+ return (0, common_1.deleteFunctionLocal)(fn.source);
206
204
  }
207
205
  return;
208
206
  }));
@@ -45,6 +45,7 @@ exports.default = new command_1.default('functions:setup')
45
45
  .needs('auth', [constants_1.SCOPE.functions])
46
46
  .needs('config')
47
47
  .needs('rc')
48
+ .ci(false)
48
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
49
50
  const config = runtime_store_1.default.get('config');
50
51
  yield (yield Promise.resolve().then(() => __importStar(require('../../init/features')))).functions();
@@ -35,24 +35,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
+ const ansi_colors_1 = require("ansi-colors");
39
+ const endpoints_1 = require("../../endpoints");
40
+ const error_1 = __importDefault(require("../../error"));
38
41
  const command_1 = __importDefault(require("../../internal/command"));
42
+ const prompt_1 = __importDefault(require("../../prompt"));
39
43
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
40
44
  const constants_1 = require("../../util_modules/constants");
45
+ const logger_1 = require("../../util_modules/logger");
41
46
  const option_1 = require("../../util_modules/option");
47
+ const project_1 = require("../../util_modules/project");
42
48
  exports.default = new command_1.default('functions:shell')
43
49
  .description('Launch a node shell to test emulated functions of any stack or type, other than Advanced I/O functions')
44
50
  .option('--http [port]', 'enables http mode for the basicIO functions and start server at specified port' +
45
51
  `(default: ${constants_1.DEFAULT.serve_port.http.basicio})`)
46
52
  .option('--debug [port]', 'the functions are invoked from local environment enabling debugging options on provided port.' +
47
53
  `(default: ${constants_1.DEFAULT.serve_port.debug.basicio})`)
54
+ .option('--tunnel <port>', 'start tunneling functions at the specified port')
55
+ .option('--enable-tunnel [tunnel-url]', 'enable tunneling for this particular command execution')
48
56
  .option('--ignore-scripts', 'ignore the pre and post lifecycle scripts')
49
57
  .option('--watch', 'watch for file and directory changes and enable hot reload' +
50
58
  '\n' +
51
59
  '(deprecated: The watch mode will be enabled by default. To disable watch mode use the --no-watch option)')
52
60
  .option('--no-watch', 'disable watching the files for changes')
53
- .needs('auth', [constants_1.SCOPE.functions, constants_1.SCOPE.functions_execution, constants_1.SCOPE.custom_token_generation])
61
+ .needs('auth', constants_1.NEEDED_SCOPES.SERVE)
54
62
  .needs('config')
55
63
  .needs('rc')
64
+ .ci(false)
56
65
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
57
66
  const httpOpt = (0, option_1.getOptionValue)('http', false);
58
67
  if (httpOpt && typeof httpOpt !== 'boolean') {
@@ -62,5 +71,93 @@ exports.default = new command_1.default('functions:shell')
62
71
  if (debugOpt && typeof debugOpt !== 'boolean') {
63
72
  runtime_store_1.default.set('context.port.debug.bio', debugOpt);
64
73
  }
74
+ const tunnelOpt = (0, option_1.getOptionValue)('tunnel', false);
75
+ if (tunnelOpt && typeof tunnelOpt !== 'boolean') {
76
+ runtime_store_1.default.set('context.port.tunnel', tunnelOpt);
77
+ }
78
+ const enableTunnelOpt = (0, option_1.getOptionValue)('enableTunnel', false);
79
+ if (!tunnelOpt && enableTunnelOpt) {
80
+ throw new error_1.default('Invalid Command. Use --enable-tunnel option with the -—tunnel option.', { exit: 1 });
81
+ }
82
+ if (enableTunnelOpt) {
83
+ const _tunnelAPI = yield (0, endpoints_1.tunnelAPI)();
84
+ const tunnelDetails = yield _tunnelAPI.getTunnel().catch((er) => {
85
+ const _er = error_1.default.getErrorInstance(er);
86
+ if (_er.status === 404) {
87
+ throw new error_1.default('Tunneling not configured', {
88
+ exit: 1,
89
+ errorId: 'FSHELL-1',
90
+ arg: [
91
+ (0, ansi_colors_1.bold)(`${(0, project_1.getProjectName)()}(${(0, project_1.getProjectId)()})`),
92
+ ansi_colors_1.italic.underline(`${constants_1.ORIGIN.console}/baas/${(0, project_1.getEnvId)()}/project/${(0, project_1.getProjectId)()}/Development#/settings/project/tunneling`)
93
+ ]
94
+ });
95
+ }
96
+ throw _er;
97
+ });
98
+ if (tunnelDetails.tunnel_status === 'Disabled') {
99
+ runtime_store_1.default.set('context.fn_shell.enable_tunnel', enableTunnelOpt);
100
+ (0, logger_1.info)();
101
+ (0, logger_1.info)((0, ansi_colors_1.yellow)('Tunneling will be disabled at the end of this command execution'));
102
+ (0, logger_1.info)();
103
+ }
104
+ else {
105
+ (0, logger_1.info)();
106
+ (0, logger_1.info)(`Tunneling is already enabled for the project ${(0, ansi_colors_1.bold)((0, project_1.getProjectName)())}(${(0, project_1.getProjectId)()}) with the configurations below:`);
107
+ (0, logger_1.info)();
108
+ (0, logger_1.info)((0, ansi_colors_1.bold)('Tunneling URL: ') + ansi_colors_1.italic.underline(tunnelDetails.tunnel_url));
109
+ (0, logger_1.info)((0, ansi_colors_1.bold)('Tunneled functions: '));
110
+ tunnelDetails.function_details.forEach((fn) => {
111
+ (0, logger_1.info)('* ' + fn.name);
112
+ });
113
+ (0, logger_1.info)((0, ansi_colors_1.bold)('Enabled by: ') + (0, ansi_colors_1.italic)(tunnelDetails.created_by.email_id));
114
+ (0, logger_1.info)((0, ansi_colors_1.bold)('Enabled on: ') + tunnelDetails.enabled_time);
115
+ (0, logger_1.info)();
116
+ if (typeof enableTunnelOpt === 'boolean') {
117
+ const continueAsIs = yield prompt_1.default.ask(prompt_1.default.question('consent', 'Do you wish to continue ?', {
118
+ type: 'list',
119
+ choices: [
120
+ prompt_1.default.choice('continue', { value: true, short: 'continue' }),
121
+ prompt_1.default.choice('abort', { value: false, short: 'aborted' })
122
+ ]
123
+ }));
124
+ if (continueAsIs.consent === false) {
125
+ return;
126
+ }
127
+ (0, logger_1.info)();
128
+ (0, logger_1.info)('Ignoring `--enable-tunnel` option since tunneling is already enabled');
129
+ (0, logger_1.info)();
130
+ }
131
+ else if (enableTunnelOpt !== tunnelDetails.tunnel_url) {
132
+ (0, logger_1.info)('Tunneling has already been enabled with a different tunneling URL.');
133
+ (0, logger_1.info)('Do you wish to update the tunnel request with the tunneling URL entered in the --enable-tunnel option?');
134
+ (0, logger_1.info)();
135
+ (0, logger_1.info)((0, ansi_colors_1.red)('- ' + tunnelDetails.tunnel_url));
136
+ (0, logger_1.info)((0, ansi_colors_1.green)('+ ' + enableTunnelOpt));
137
+ (0, logger_1.info)();
138
+ const updateCont = yield prompt_1.default.ask(prompt_1.default.question('consent', 'Do you wish to update and continue', {
139
+ type: 'list',
140
+ choices: [
141
+ prompt_1.default.choice('continue', { value: true, short: 'continue' }),
142
+ prompt_1.default.choice('abort', { value: false, short: 'aborted' })
143
+ ]
144
+ }));
145
+ if (updateCont.consent === false) {
146
+ return;
147
+ }
148
+ yield (yield (0, endpoints_1.tunnelAPI)()).disableTunnel();
149
+ runtime_store_1.default.set('context.fn_shell.enable_tunnel', enableTunnelOpt);
150
+ (0, logger_1.info)();
151
+ (0, logger_1.info)((0, ansi_colors_1.yellow)('Tunneling will be disabled at the end of this command execution'));
152
+ (0, logger_1.info)();
153
+ }
154
+ else {
155
+ (0, logger_1.info)();
156
+ (0, logger_1.info)('Ignoring `--enable-tunnel` option since a tunnel already exists with the same tunnel url provided: ' +
157
+ ansi_colors_1.italic.underline(enableTunnelOpt));
158
+ (0, logger_1.info)();
159
+ }
160
+ }
161
+ }
65
162
  return (yield Promise.resolve().then(() => __importStar(require('../../shell')))).default();
66
163
  }));
@@ -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('event:generate:job'),
83
84
  loadCommand('serve'),
84
85
  loadCommand('deploy'),
85
86
  loadCommand('help'),
@@ -56,14 +56,10 @@ exports.default = new command_1.default('init [feature]')
56
56
  .description('Initialize a Catalyst project, function, and client resources in the local directory')
57
57
  .option('--force', 'force initialise a project for this directory')
58
58
  .ignore(['project'])
59
- .needs('auth', [
60
- constants_1.SCOPE.projects,
61
- constants_1.SCOPE.stratus_create,
62
- constants_1.SCOPE.stratus_read,
63
- constants_1.SCOPE.project_import_create
64
- ])
59
+ .needs('auth', [constants_1.SCOPE.projects, constants_1.SCOPE.project_import_create])
65
60
  .needs('config', { optional: true })
66
61
  .needs('rc', { optional: true, resolveOnNotFound: true })
62
+ .ci(false)
67
63
  .action((feature) => __awaiter(void 0, void 0, void 0, function* () {
68
64
  var _a;
69
65
  const config = runtime_store_1.default.get('config');
@@ -40,6 +40,7 @@ exports.default = new command_1.default('login')
40
40
  .description('Log the CLI in to your Catalyst account')
41
41
  .option('--no-localhost', 'login without browser')
42
42
  .option('--force', 'force reauthentication')
43
+ .ci(false)
43
44
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
44
45
  const auth = yield Promise.resolve().then(() => __importStar(require('../authentication')));
45
46
  return auth.login();
@@ -38,6 +38,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const command_1 = __importDefault(require("../internal/command"));
39
39
  exports.default = new command_1.default('logout')
40
40
  .description('Log the CLI out of your Catalyst account')
41
+ .ci(false)
41
42
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
42
43
  const auth = yield Promise.resolve().then(() => __importStar(require('../authentication')));
43
44
  return auth.logout();
@@ -50,6 +50,7 @@ exports.default = new command_1.default('pull [feature]')
50
50
  .needs('auth', [constants_1.SCOPE.functions, constants_1.SCOPE.webapp])
51
51
  .needs('config', { optional: true })
52
52
  .needs('rc')
53
+ .ci(false)
53
54
  .action((feature) => __awaiter(void 0, void 0, void 0, function* () {
54
55
  const config = runtime_store_1.default.get('config');
55
56
  const homeDir = (yield Promise.resolve().then(() => __importStar(require('os')))).homedir();
@@ -47,15 +47,9 @@ exports.default = new command_1.default('serve')
47
47
  .option('--only <targets>', 'only serve specified, comma-separated targets (e.g. "client,functions:f1")')
48
48
  .option('--no-watch', 'disable watching the files for changes')
49
49
  .option('--except <targets>', 'serve all targets except specified (e.g. "client")')
50
- .option('--ignore-scripts', 'ignore the pre and post lifescycle scripts')
50
+ .option('--ignore-scripts', 'ignore the pre and post lifecycle scripts')
51
51
  .option('--no-open', 'disable opening the client automatically when served')
52
- .needs('auth', [
53
- constants_1.SCOPE.functions,
54
- constants_1.SCOPE.functions_execution,
55
- constants_1.SCOPE.webapp,
56
- constants_1.SCOPE.pdf_shot,
57
- constants_1.SCOPE.custom_token_generation
58
- ])
52
+ .needs('auth', constants_1.NEEDED_SCOPES.SERVE)
59
53
  .needs('config')
60
54
  .needs('rc')
61
55
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -19,6 +19,7 @@ const command_1 = __importDefault(require("../internal/command"));
19
19
  const logger_1 = require("../util_modules/logger");
20
20
  exports.default = new command_1.default('whoami')
21
21
  .description('Print the email address of the user currently logged in')
22
+ .ci(false)
22
23
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
23
24
  const activeDC = (0, dc_1.getActiveDC)();
24
25
  const user = config_store_1.default.get(`${activeDC}.user`);
@@ -57,7 +57,7 @@ function getConfigJsonInputs() {
57
57
  when: () => optValues.build_path === false,
58
58
  rootPath: cwd,
59
59
  validate: ({ value }) => __awaiter(this, void 0, void 0, function* () {
60
- const pathRes = (0, utils_1.validateBuildPath)(value);
60
+ const pathRes = yield (0, utils_1.validateBuildPath)(value);
61
61
  if (!pathRes) {
62
62
  return `Invalid path: ${value}`;
63
63
  }
@@ -142,7 +142,9 @@ function getStandAloneTarget() {
142
142
  configJson.stack = configJson.stack.runtime;
143
143
  }
144
144
  return {
145
- appSail: Object.assign({ name: nameOpt === false ? appSailName.name : nameOpt, source: cwd }, configJson),
145
+ name: nameOpt === false ? appSailName.name : nameOpt,
146
+ source: cwd,
147
+ config: configJson,
146
148
  validity: { valid: true }
147
149
  };
148
150
  });
@@ -157,15 +159,15 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
157
159
  const filtered = (0, appsail_utils_1.filterTargets)(targets);
158
160
  let pythonPrompt = false;
159
161
  const validTargets = (0, appsail_utils_1.validateAppSail)(filtered).filter((targ) => {
160
- var _a, _b;
162
+ var _a;
161
163
  if (targ.validity.valid) {
162
164
  if (!pythonPrompt &&
163
- ((_a = targ.appSail) === null || _a === void 0 ? void 0 : _a.stack.startsWith(constants_1.RUNTIME.language.python.value))) {
165
+ ((_a = targ.config) === null || _a === void 0 ? void 0 : _a.stack.startsWith(constants_1.RUNTIME.language.python.value))) {
164
166
  pythonPrompt = true;
165
167
  }
166
168
  return targ;
167
169
  }
168
- (0, logger_1.labeled)('AppSail: ', 'Invalid AppSail service ' + (0, ansi_colors_1.bold)(((_b = targ.appSail) === null || _b === void 0 ? void 0 : _b.name) || 'Unknown')).ERROR();
170
+ (0, logger_1.labeled)('AppSail: ', 'Invalid AppSail service ' + (0, ansi_colors_1.bold)(targ.name || 'Unknown')).ERROR();
169
171
  (0, logger_1.error)('Reason: ' + targ.validity.reason);
170
172
  (0, logger_1.info)();
171
173
  return false;
@@ -179,20 +181,19 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
179
181
  const throbber = throbber_1.default.getInstance();
180
182
  const deployRes = yield validTargets.reduce((result, _targ) => __awaiter(void 0, void 0, void 0, function* () {
181
183
  var _a, _b;
182
- const targ = _targ.appSail;
184
+ const targ = _targ.config;
183
185
  const prevRes = yield result;
184
186
  try {
185
187
  if ((_a = targ.scripts) === null || _a === void 0 ? void 0 : _a.predeploy) {
186
- executeHook(targ.scripts.predeploy, 'predeploy', targ.source);
188
+ executeHook(targ.scripts.predeploy, 'predeploy', _targ.source);
187
189
  }
188
- const throbberName = `prepare_appsail_${targ.name}`;
190
+ const throbberName = `prepare_appsail_${_targ.name}`;
189
191
  throbber.add(throbberName, {
190
- text: `Preparing AppSail[${targ.name}]`
192
+ text: `Preparing AppSail[${_targ.name}]`
191
193
  });
192
194
  const zip = new archiver_1.default();
193
- const buildPath = targ.buildPath ? targ.buildPath : targ.build_path;
194
- const folderPath = (0, project_1.resolveProjectPath)(buildPath);
195
- const ignoreFile = yield fs_1.ASYNC.readFile((0, path_1.join)(folderPath, constants_1.FILENAME.catalyst_ignore));
195
+ const ignoreFile = yield fs_1.ASYNC.readFile((0, path_1.join)(_targ.source, constants_1.FILENAME.catalyst_ignore));
196
+ const folderPath = targ.build_path;
196
197
  const folderContents = yield fs_1.ASYNC.walk(folderPath, {
197
198
  filter: {
198
199
  exclude: [
@@ -215,19 +216,21 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
215
216
  const finalized = yield zip.finalize();
216
217
  const zipStream = yield finalized.fsStream();
217
218
  throbber.remove(throbberName);
218
- const { stack, name, command, memory, platform, env_variables } = targ;
219
+ const { stack, command, memory, platform, env_variables, catalyst_auth, login_redirect } = targ;
219
220
  const apiRes = yield sailAPI.deploy(zipStream.stream, {
220
221
  stack,
221
- name,
222
+ name: _targ.name,
222
223
  memory,
223
224
  platform,
224
225
  command,
226
+ catalystAuth: catalyst_auth,
227
+ loginRedirect: login_redirect,
225
228
  envVariables: env_variables,
226
229
  contentLength: zipStream.length
227
230
  });
228
231
  _targ.url = apiRes.url;
229
232
  if ((_b = targ.scripts) === null || _b === void 0 ? void 0 : _b.postdeploy) {
230
- executeHook(targ.scripts.postdeploy, 'postdeploy', targ.source);
233
+ executeHook(targ.scripts.postdeploy, 'postdeploy', _targ.source);
231
234
  }
232
235
  }
233
236
  catch (err) {
@@ -241,10 +244,9 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
241
244
  return Promise.resolve(prevRes);
242
245
  }), Promise.resolve([]));
243
246
  const deployedValidTargets = deployRes.filter((targ) => {
244
- var _a;
245
247
  if (!targ.validity.valid) {
246
248
  (0, logger_1.warning)('Deploy of AppSail [' +
247
- ((_a = targ.appSail) === null || _a === void 0 ? void 0 : _a.name) +
249
+ targ.name +
248
250
  '] was unsuccessful since ' +
249
251
  targ.validity.reason);
250
252
  }
@@ -36,10 +36,10 @@ function validateOptions(validationFn, option, ...args) {
36
36
  exports.validateOptions = validateOptions;
37
37
  function validateBuildPath(path) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
39
- const cwd = process.cwd();
39
+ const cwd = runtime_store_1.default.get('cwd');
40
40
  if (path) {
41
41
  const buildPath = (0, path_1.isAbsolute)(path) ? path : (0, path_1.resolve)(cwd, path);
42
- return (yield fs_1.ASYNC.dirExists(buildPath)) ? path : false;
42
+ return (yield fs_1.ASYNC.isPathExists(buildPath)) ? path : false;
43
43
  }
44
44
  return false;
45
45
  });
@@ -79,11 +79,10 @@ exports.validateName = validateName;
79
79
  function urlLogger() {
80
80
  const deployTargets = runtime_store_1.default.get('payload.appsail.targets', []);
81
81
  deployTargets.forEach((sail) => {
82
- var _a, _b;
83
82
  if (sail.url !== undefined) {
84
- (0, logger_1.labeled)(`AppSail(${(_a = sail.appSail) === null || _a === void 0 ? void 0 : _a.name})`, 'URL => ' + sail.url).MESSAGE();
83
+ (0, logger_1.labeled)(`AppSail(${sail.name})`, 'URL => ' + sail.url).MESSAGE();
85
84
  }
86
- (0, logger_1.labeled)(`AppSail(${(_b = sail.appSail) === null || _b === void 0 ? void 0 : _b.name})`, 'deploy successful').SUCCESS();
85
+ (0, logger_1.labeled)(`AppSail(${sail.name})`, 'deploy successful').SUCCESS();
87
86
  (0, logger_1.info)();
88
87
  });
89
88
  return deployTargets;
@@ -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.commonAPI = 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.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* () {
@@ -170,6 +170,13 @@ function codeDeck() {
170
170
  });
171
171
  }
172
172
  exports.codeDeck = codeDeck;
173
+ function jobScheduling({ auth = true, projectId = (0, project_1.getProjectId)() } = {}) {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ const jobScheduling = (yield Promise.resolve().then(() => __importStar(require('./lib/job-scheduling')))).default;
176
+ return new jobScheduling(projectId, { authNeeded: auth });
177
+ });
178
+ }
179
+ exports.jobScheduling = jobScheduling;
173
180
  function commonAPI() {
174
181
  return __awaiter(this, void 0, void 0, function* () {
175
182
  const common = (yield Promise.resolve().then(() => __importStar(require('./lib/common')))).default;
@@ -177,3 +184,10 @@ function commonAPI() {
177
184
  });
178
185
  }
179
186
  exports.commonAPI = commonAPI;
187
+ function tunnelAPI({ auth = true, projectId = (0, project_1.getProjectId)() } = {}) {
188
+ return __awaiter(this, void 0, void 0, function* () {
189
+ const tunnel = (yield Promise.resolve().then(() => __importStar(require('./lib/tunnel')))).default;
190
+ return new tunnel(projectId, { authNeeded: auth });
191
+ });
192
+ }
193
+ exports.tunnelAPI = tunnelAPI;
@@ -21,7 +21,7 @@ class AppSail {
21
21
  this.opts = opts;
22
22
  this.projectId = projectId;
23
23
  }
24
- deploy(sourceFsStream, { stack, name, contentLength, command, memory, platform, envVariables = {} }) {
24
+ deploy(sourceFsStream, { stack, name, contentLength, command, memory, platform, envVariables = {}, catalystAuth, loginRedirect }) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
26
  const formData = {
27
27
  stack,
@@ -43,6 +43,12 @@ class AppSail {
43
43
  variables: envVariables
44
44
  };
45
45
  }
46
+ if (typeof catalystAuth === 'boolean') {
47
+ configuration.catalyst_auth = catalystAuth;
48
+ if (typeof loginRedirect === 'string') {
49
+ configuration.login_redirect = loginRedirect;
50
+ }
51
+ }
46
52
  if (Object.keys(configuration).length > 0) {
47
53
  formData.configuration = JSON.stringify(configuration);
48
54
  }