zcatalyst-cli 1.18.0-beta.1 → 1.18.0-beta.2

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 (33) hide show
  1. package/docs/command_needs/rc.toml +8 -8
  2. package/lib/command_needs/rc.js +7 -7
  3. package/lib/commands/appsail/add.js +1 -1
  4. package/lib/commands/client/setup.js +1 -1
  5. package/lib/commands/codelib/install.js +5 -2
  6. package/lib/commands/functions/add.js +1 -1
  7. package/lib/commands/functions/setup.js +1 -1
  8. package/lib/commands/init.js +8 -1
  9. package/lib/deploy/features/appsail/index.js +25 -10
  10. package/lib/endpoints/index.js +2 -2
  11. package/lib/init/features/appsail/index.js +32 -26
  12. package/lib/init/features/project.js +5 -15
  13. package/lib/internal/api.js +13 -5
  14. package/lib/prompt/types/file-path.js +1 -1
  15. package/lib/serve/server/lib/appsail/index.js +9 -5
  16. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  17. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +14 -0
  18. package/lib/shell/dependencies/invoker/integ/node.mjs +13 -0
  19. package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +14 -0
  20. package/lib/util_modules/config/lib/appsail.js +5 -7
  21. package/lib/util_modules/fs/lib/async.js +7 -2
  22. package/package.json +1 -1
  23. package/templates/init/functions/java/job/sample.java +1 -1
  24. package/templates/init/functions/node/aio/sample.js +7 -0
  25. package/templates/init/functions/node/bio/sample.js +5 -0
  26. package/templates/init/functions/node/bio/types/basicio.d.ts +57 -0
  27. package/templates/init/functions/node/cron/sample.js +5 -0
  28. package/templates/init/functions/node/cron/types/cron.d.ts +64 -0
  29. package/templates/init/functions/node/event/sample.js +11 -8
  30. package/templates/init/functions/node/event/types/event.d.ts +82 -0
  31. package/templates/init/functions/node/job/sample.js +0 -1
  32. package/templates/init/functions/node/job/types/job.d.ts +0 -4
  33. package/templates/init/functions/python/job/sample.py +0 -1
@@ -1,7 +1,7 @@
1
1
  [RC-1]
2
2
  context = '''The project(${arg[0]}) provided with the ${arg[1]} option is not available is not available in the ${arg[3]} org.'''
3
3
  aid = '''Please use one of the available projects with the ${arg[1]} option or specify the correct org \nThe available projects in the ${arg[3]} org are: \n${arg[2]}'''
4
- link = 'https://www.zoho.com/catalyst/help/cli-options.html#Project'
4
+ link = 'https://docs.catalyst.zoho.com/en/cli/v1/initialize-resources/initialize-new-project/'
5
5
 
6
6
  [RC-2]
7
7
  context = '''Unable to load the ${arg[0]} file.'''
@@ -10,18 +10,18 @@ link = ''
10
10
 
11
11
  [RC-3]
12
12
  context = '''Oops!!! It looks like you're not inside a Catalyst app directory because we are unable to locate the ${arg[0]} file.'''
13
- aid = '''Please run the ${arg[1]} command to initialise or specify a valid project with the ${arg[2]} option.'''
14
- link = 'https://www.zoho.com/catalyst/help/cli-init.html#Initialize_All'
13
+ aid = '''Please run the ${arg[1]} command to initialize or specify a valid project with the ${arg[2]} option.'''
14
+ link = 'https://docs.catalyst.zoho.com/en/cli/v1/initialize-resources/introduction/#Initialize_Alll'
15
15
 
16
16
  [RC-4]
17
17
  context = '''The ${arg[0]} file is corrupted.'''
18
- aid = '''Please delete the ${arg[0]} file in the Catalyst app directory and initialise the project with the ${arg[1]} command or \nSpecify a valid project with the ${arg[2]} option.'''
19
- link = 'https://www.zoho.com/catalyst/help/cli-init.html#Options'
18
+ aid = '''Please delete the ${arg[0]} file in the Catalyst app directory and initialize the project with the ${arg[1]} command or \nSpecify a valid project with the ${arg[2]} option.'''
19
+ link = 'https://docs.catalyst.zoho.com/en/cli/v1/initialize-resources/initialize-options/#--force'
20
20
 
21
21
  [RC-5]
22
- context = '''The project which is currently active doesn't seems to be present in Catalyst remote console.'''
23
- aid = '''Use the ${arg[0]} command in order to change the existing active project.'''
24
- link = 'https://www.zoho.com/catalyst/help/cli-projects.html#Use'
22
+ context = '''Oops!!! It looks like you don't have access to the currently initialized project ${arg[0]}.'''
23
+ aid = '''Please contact the owner or an administrator of the project.\nIf you would like to initialize a new project for this directory, please use the below command\n${arg[1]}'''
24
+ link = 'https://docs.catalyst.zoho.com/en/cli/v1/initialize-resources/initialize-options/#--force'
25
25
 
26
26
  [RC-6]
27
27
  context = '''The Catalyst portal initialized in the current project directory is not accessible with the currently logged in user.\n
@@ -192,7 +192,7 @@ exports.default = ({ optional = false, resolveOnNotFound = false, skipOrgCheck =
192
192
  });
193
193
  }
194
194
  if (typeof finalEnvObj !== 'undefined') {
195
- projectApi = yield (0, endpoints_1.projectAPI)({ auth: true, org: finalEnvObj.id });
195
+ projectApi = yield (0, endpoints_1.projectAPI)({ auth: true, org: finalEnvObj.id, printError: false });
196
196
  envApi = yield (0, endpoints_1.envAPI)({ auth: true, org: finalEnvObj.id });
197
197
  }
198
198
  const projectDetails = yield projectApi
@@ -200,19 +200,19 @@ exports.default = ({ optional = false, resolveOnNotFound = false, skipOrgCheck =
200
200
  .catch((err) => __awaiter(void 0, void 0, void 0, function* () {
201
201
  if (js_1.JS.hasIn(err, 'context.response.statusCode')) {
202
202
  switch (err.context.response.statusCode) {
203
+ case 401:
203
204
  case 404: {
204
- (0, logger_1.message)('cleaning up ' +
205
- constants_1.FILENAME.rc +
206
- ' since the current active project for this folder is not found in remote');
207
- yield (0, project_2.removeProject)(finalProjectObj.id + '');
208
205
  if (resolveOnNotFound) {
209
206
  finalProjectObj = undefined;
210
207
  return;
211
208
  }
212
- throw new error_1.default('active project not found in remote', {
209
+ throw new error_1.default('no access to project: ' + (finalProjectObj === null || finalProjectObj === void 0 ? void 0 : finalProjectObj.id), {
213
210
  exit: 1,
214
211
  errorId: 'RC-5',
215
- arg: [(0, ansi_colors_1.bold)('catalyst project:use')]
212
+ arg: [
213
+ (0, ansi_colors_1.bold)(`${finalProjectObj === null || finalProjectObj === void 0 ? void 0 : finalProjectObj.name}(${finalProjectObj === null || finalProjectObj === void 0 ? void 0 : finalProjectObj.id})`),
214
+ (0, ansi_colors_1.bold)((0, ansi_colors_1.cyan)('command: ') + 'catalyst init --force')
215
+ ]
216
216
  });
217
217
  }
218
218
  case 403: {
@@ -43,7 +43,7 @@ const logger_1 = require("../../util_modules/logger");
43
43
  exports.default = new command_1.default('appsail:add')
44
44
  .description('Link an already existing AppSail service to Catalyst Project')
45
45
  .needs('auth', [constants_1.SCOPE.functions])
46
- .needs('config')
46
+ .needs('config', { optional: true })
47
47
  .needs('rc')
48
48
  .ci(false)
49
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -43,7 +43,7 @@ const logger_1 = require("../../util_modules/logger");
43
43
  exports.default = new command_1.default('client:setup')
44
44
  .description('Set up and configure the client directory in your project directory')
45
45
  .needs('auth', [constants_1.SCOPE.webapp])
46
- .needs('config')
46
+ .needs('config', { optional: true })
47
47
  .needs('rc')
48
48
  .ci(false)
49
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -32,7 +32,7 @@ exports.default = new command_1.default('codelib:install [git-url]')
32
32
  .description('Install the code library functionalities into your project')
33
33
  .option('-c, --continue <install-id>', 'Continue CodeLib install')
34
34
  .needs('auth', [constants_1.SCOPE.project_import_create])
35
- .needs('config')
35
+ .needs('config', { optional: true })
36
36
  .needs('rc')
37
37
  .action((gitUrl) => __awaiter(void 0, void 0, void 0, function* () {
38
38
  var _a;
@@ -72,7 +72,10 @@ exports.default = new command_1.default('codelib:install [git-url]')
72
72
  if (!gitUrl) {
73
73
  throw new error_1.default('Invalid code lib', { exit: 2 });
74
74
  }
75
- return;
75
+ throw new error_1.default(`Error while downloading codelib.`, {
76
+ exit: 2,
77
+ original: `Occurred while processing ${gitUrl}`
78
+ });
76
79
  }
77
80
  const templateFile = yield (0, code_deck_1.getTemplateFile)(deckZip);
78
81
  const templateJson = JSON.parse(templateFile || '');
@@ -43,7 +43,7 @@ const logger_1 = require("../../util_modules/logger");
43
43
  exports.default = new command_1.default('functions:add')
44
44
  .description('Add a function of the required stack to the function directory')
45
45
  .needs('auth', [constants_1.SCOPE.functions])
46
- .needs('config')
46
+ .needs('config', { optional: true })
47
47
  .needs('rc')
48
48
  .ci(false)
49
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -43,7 +43,7 @@ const logger_1 = require("../../util_modules/logger");
43
43
  exports.default = new command_1.default('functions:setup')
44
44
  .description('Set up and configure the function directory in your project directory')
45
45
  .needs('auth', [constants_1.SCOPE.functions])
46
- .needs('config')
46
+ .needs('config', { optional: true })
47
47
  .needs('rc')
48
48
  .ci(false)
49
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -100,8 +100,15 @@ exports.default = new command_1.default('init [feature]')
100
100
  return;
101
101
  }
102
102
  if (feature !== 'project') {
103
- yield (0, features_1.project)();
103
+ try {
104
+ yield (0, features_1.project)();
105
+ }
106
+ catch (er) {
107
+ (0, logger_1.debug)(er);
108
+ return;
109
+ }
104
110
  }
111
+ (0, logger_1.info)();
105
112
  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 ' +
106
113
  (0, ansi_colors_1.cyan)('<return> ') +
107
114
  'to proceed.\n', {
@@ -31,6 +31,7 @@ const option_1 = require("../../../util_modules/option");
31
31
  const project_1 = require("../../../util_modules/project");
32
32
  const utils_1 = require("./utils");
33
33
  const throbber_1 = __importDefault(require("../../../throbber"));
34
+ const minimatch_1 = __importDefault(require("minimatch"));
34
35
  function executeHook(script, name, moduleSource) {
35
36
  if ((0, option_1.getOptionValue)('ignoreScripts', false)) {
36
37
  (0, logger_1.debug)(`skipping ${name} hook`);
@@ -183,29 +184,42 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
183
184
  var _a, _b;
184
185
  const targ = _targ.config;
185
186
  const prevRes = yield result;
187
+ const throbberName = `prepare_appsail_${_targ.name}`;
186
188
  try {
187
189
  if ((_a = targ.scripts) === null || _a === void 0 ? void 0 : _a.predeploy) {
188
190
  executeHook(targ.scripts.predeploy, 'predeploy', _targ.source);
189
191
  }
190
- const throbberName = `prepare_appsail_${_targ.name}`;
191
192
  throbber.add(throbberName, {
192
193
  text: `Preparing AppSail[${_targ.name}]`
193
194
  });
194
- const zip = new archiver_1.default();
195
- const ignoreFile = yield fs_1.ASYNC.readFile((0, path_1.join)(_targ.source, constants_1.FILENAME.catalyst_ignore));
196
195
  const folderPath = targ.build_path;
196
+ const isBuildPath = yield fs_1.ASYNC.isPathExists(folderPath);
197
+ if (!isBuildPath) {
198
+ throw new error_1.default(`the build path doesn't exists: ${folderPath}`, {
199
+ exit: 1,
200
+ skipHelp: true
201
+ });
202
+ }
203
+ const ignoreFile = yield fs_1.ASYNC.readFile((0, path_1.join)(_targ.source, constants_1.FILENAME.catalyst_ignore));
204
+ const excludePatterns = [
205
+ '**/.DS_Store',
206
+ '**/.vscode/**/*',
207
+ `**/${constants_1.FILENAME.log}`,
208
+ `**/${constants_1.FILENAME.config}`,
209
+ `**/${constants_1.FILENAME.rc}`,
210
+ `**/${constants_1.FILENAME.app_config}`,
211
+ `**/${constants_1.FILENAME.catalyst_ignore}`,
212
+ ...((ignoreFile === null || ignoreFile === void 0 ? void 0 : ignoreFile.split('\n')) || [])
213
+ ];
197
214
  const folderContents = yield fs_1.ASYNC.walk(folderPath, {
198
215
  filter: {
199
- exclude: [
200
- '**/.DS_Store',
201
- '**/.vscode/**/*',
202
- `**/${constants_1.FILENAME.app_config}`,
203
- `**/${constants_1.FILENAME.catalyst_ignore}`,
204
- ...((ignoreFile === null || ignoreFile === void 0 ? void 0 : ignoreFile.split('\n')) || [])
205
- ],
216
+ exclude: (path) => __awaiter(void 0, void 0, void 0, function* () {
217
+ return !!excludePatterns.find((glob) => (0, minimatch_1.default)(path.replace(folderPath + path_1.sep, ''), glob, { dot: true }));
218
+ }),
206
219
  excludeDir: true
207
220
  }
208
221
  });
222
+ const zip = new archiver_1.default();
209
223
  folderContents.forEach((content) => {
210
224
  zip.add(content.path === folderPath
211
225
  ? (0, path_1.basename)(content.path)
@@ -234,6 +248,7 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
234
248
  }
235
249
  }
236
250
  catch (err) {
251
+ throbber.remove(throbberName);
237
252
  (0, logger_1.debug)(err);
238
253
  _targ.validity = {
239
254
  valid: false,
@@ -41,10 +41,10 @@ function orgAPI({ auth = true } = {}) {
41
41
  });
42
42
  }
43
43
  exports.orgAPI = orgAPI;
44
- function projectAPI({ auth = true, org = (0, project_1.getEnvId)() } = {}) {
44
+ function projectAPI({ auth = true, org = (0, project_1.getEnvId)(), printError = true } = {}) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
46
  const project = (yield Promise.resolve().then(() => __importStar(require('./lib/project')))).default;
47
- return new project({ authNeeded: auth }, org);
47
+ return new project({ authNeeded: auth, printError }, org);
48
48
  });
49
49
  }
50
50
  exports.projectAPI = projectAPI;
@@ -141,21 +141,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
141
141
  })
142
142
  }))).source
143
143
  };
144
- const appConfigPth = (0, path_1.join)(_appSailConfig.source, constants_1.FILENAME.app_config);
145
- const isAppConfig = yield fs_1.ASYNC.fileExists(appConfigPth);
146
144
  const existingSails = config_1.appSailConfig.raw() || [];
147
- yield prompt_1.default.register('file-path');
148
- const appSail = yield prompt_1.default.ask(prompt_1.default.question('buildPath', 'Please provide the build path of your AppSail service: ', {
149
- type: 'file-path',
150
- validate: (pth) => __awaiter(void 0, void 0, void 0, function* () {
151
- const buildPath = (0, path_1.resolve)(runtime_store_1.default.get('cwd'), pth.value);
152
- if ((yield fs_1.ASYNC.dirExists(buildPath)) || (yield fs_1.ASYNC.fileExists(buildPath))) {
153
- return true;
154
- }
155
- return 'Path does not exists';
156
- }),
157
- when: !_appSailConfig.build
158
- }), prompt_1.default.question('name', 'Please provide the name for your AppSail: ', {
145
+ const appName = yield prompt_1.default.ask(prompt_1.default.question('name', 'Please provide the name for your AppSail: ', {
159
146
  type: 'input',
160
147
  default: 'AppSail',
161
148
  validate: (name) => {
@@ -172,16 +159,40 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
172
159
  : true;
173
160
  }
174
161
  }));
175
- const appSailStack = _appSailConfig.stack ||
176
- (yield (0, common_1.getRuntimePromptAnswer)('Please choose a stack for your AppSail: '));
177
162
  const payload = {
178
- source: _appSailConfig.source,
179
- name: appSail.name
163
+ source: (0, path_1.relative)((0, project_1.getProjectRoot)(), _appSailConfig.source) || '.',
164
+ name: appName.name
180
165
  };
166
+ const appConfigPth = (0, path_1.join)(_appSailConfig.source, constants_1.FILENAME.app_config);
167
+ const isAppConfig = yield fs_1.ASYNC.fileExists(appConfigPth);
168
+ if (isAppConfig) {
169
+ (0, logger_1.info)();
170
+ (0, logger_1.warning)(`The ${(0, ansi_colors_1.bold)(constants_1.FILENAME.app_config)} file is already present in the appsail directory`);
171
+ }
172
+ const overWrite = yield prompt_1.default.ask(prompt_1.default.question('appConfig', 'Do you wish to overwrite the ' + constants_1.FILENAME.app_config, {
173
+ type: 'confirm',
174
+ default: false,
175
+ when: isAppConfig
176
+ }));
177
+ const activeWrite = overWrite.appConfig !== false;
178
+ if (!activeWrite) {
179
+ runtime_store_1.default.set('payload.appsail.targets', [payload]);
180
+ return;
181
+ }
182
+ const buildPath = yield prompt_1.default.ask(prompt_1.default.question('path', 'Please provide the build path of your AppSail service: ', {
183
+ type: 'input',
184
+ rootPath: _appSailConfig.source,
185
+ when: !_appSailConfig.build && activeWrite
186
+ }));
187
+ const appSailStack = _appSailConfig.stack ||
188
+ (yield (0, common_1.getRuntimePromptAnswer)('Please choose a stack for your AppSail: '));
181
189
  const appConfig = {
182
190
  command: _appSailConfig.command ||
183
- 'echo Please specify the start-up command in the app-config.json file under the key command',
184
- build_path: _appSailConfig.build || './' + (0, path_1.relative)(_appSailConfig.source, appSail.buildPath),
191
+ 'echo Please specify the start-up command in the app-config.json file under the key command for AppSail $X_ZC_RESOURCE_NAME',
192
+ build_path: _appSailConfig.build ||
193
+ ((0, path_1.isAbsolute)(buildPath.path)
194
+ ? (0, path_1.relative)(_appSailConfig.source, buildPath.path) || '.'
195
+ : buildPath.path),
185
196
  stack: appSailStack.runtime,
186
197
  env_variables: {},
187
198
  memory: _appSailConfig.memory || 256,
@@ -208,10 +219,5 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
208
219
  }
209
220
  }
210
221
  runtime_store_1.default.set('payload.appsail.targets', [payload]);
211
- if (isAppConfig) {
212
- (0, logger_1.message)((0, ansi_colors_1.bold)(`app-config.json`) + ` file already exist in ${(0, ansi_colors_1.underline)(_appSailConfig.source)}`);
213
- }
214
- else {
215
- yield fs_1.ASYNC.writeJSONFile(appConfigPth, appConfig);
216
- }
222
+ activeWrite && (yield fs_1.ASYNC.writeJSONFile(appConfigPth, appConfig));
217
223
  });
@@ -34,26 +34,16 @@ const client_utils_1 = require("../../client-utils");
34
34
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
35
35
  var _a, _b;
36
36
  const orgAPI = yield (0, endpoints_1.orgAPI)();
37
- const projectAPIWithoutOrg = yield (0, endpoints_1.projectAPI)();
38
37
  const defaultRCProjectName = (0, project_1.getDefaultProjectName)(null);
39
38
  const defaultRCProjectId = (0, project_1.getDefaultProjectId)(null);
40
39
  if (defaultRCProjectName !== null &&
41
40
  defaultRCProjectId !== null &&
42
41
  !(0, option_1.getOptionValue)('force', false)) {
43
- (0, logger_1.message)(constants_1.FILENAME.rc + ' already has ' + (0, ansi_colors_1.bold)(defaultRCProjectName) + ' as a default project.');
44
- try {
45
- yield projectAPIWithoutOrg.getProject(defaultRCProjectId);
46
- throw new error_1.default('Skipping project setup, since project directory contains a default project. To overwrite use --force option');
47
- }
48
- catch (err) {
49
- if (js_1.JS.get(err, 'context.response.statusCode') !== 404) {
50
- throw err;
51
- }
52
- (0, logger_1.warning)('cleaning up ' +
53
- constants_1.FILENAME.rc +
54
- ' since the current default project for this folder is not found in remote');
55
- yield (0, project_1.removeProject)(defaultRCProjectId + '');
56
- }
42
+ (0, logger_1.message)(constants_1.FILENAME.rc +
43
+ ' already has ' +
44
+ (0, ansi_colors_1.bold)(defaultRCProjectName) +
45
+ ' as a default project. To overwrite use --force option');
46
+ throw new error_1.default('Skipping project setup, since project directory contains a default project. To overwrite use --force option', { skipHelp: true, exit: 0 });
57
47
  }
58
48
  const orgList = yield orgAPI.getAllOrgs();
59
49
  if (orgList.length === 0) {
@@ -47,7 +47,7 @@ const project_1 = require("../util_modules/project");
47
47
  const fs_1 = require("fs");
48
48
  const throbber_1 = __importDefault(require("../throbber"));
49
49
  class API {
50
- constructor({ authNeeded = true, resolveOnError = false, maxRetry = 3, env = constants_1.DEFAULT.env_name, log = {}, headers = {}, isExternal = false, origin = constants_1.ORIGIN.admin, showWarning = true, envId = (0, project_1.getEnvId)() } = {}) {
50
+ constructor({ authNeeded = true, resolveOnError = false, maxRetry = 3, env = constants_1.DEFAULT.env_name, log = {}, headers = {}, isExternal = false, origin = constants_1.ORIGIN.admin, showWarning = true, envId = (0, project_1.getEnvId)(), printError = true } = {}) {
51
51
  this.requestOpts = {
52
52
  url: origin,
53
53
  method: 'GET',
@@ -73,6 +73,7 @@ class API {
73
73
  this.maxRetryCount = maxRetry;
74
74
  this.retryCount = 0;
75
75
  this.showWarning = showWarning;
76
+ this.printError = printError;
76
77
  }
77
78
  _logReq() {
78
79
  let qs = this.requestOpts.qs
@@ -113,7 +114,9 @@ class API {
113
114
  (0, logger_1.debug)('TOTAL TIME TAKEN : ' + Number(resp.timings.end.toFixed(3)) + ' ms\n');
114
115
  (0, logger_1.debug)('REQUEST PHASES : ' + resp.timingPhases);
115
116
  }
116
- if (this.logOpts.progress !== undefined) {
117
+ if (resp.statusCode >= 200 &&
118
+ resp.statusCode < 300 &&
119
+ this.logOpts.progress !== undefined) {
117
120
  js_1.JS.set(this.logOpts, 'progress.total', resp.headers['content-length']);
118
121
  this.downloadProgress = new progress_1.default(this.logOpts.progress);
119
122
  }
@@ -153,11 +156,11 @@ class API {
153
156
  if (resp.statusCode >= 400 && !this.logOpts.skipRespBody) {
154
157
  (0, logger_1.debug)('Response Body : ' + JSON.stringify(resp.body) + '\n');
155
158
  if (!this.resolveOnHTTPError) {
156
- const errRes = (0, errorResponse_1.default)(resp, body);
159
+ const errRes = (0, errorResponse_1.default)(resp, body, !this.printError);
157
160
  this._logDownloadProgress({ error: errRes });
158
161
  throw errRes;
159
162
  }
160
- this._logDownloadProgress({ error: (0, errorResponse_1.default)(resp, body, true) });
163
+ this._logDownloadProgress({ error: (0, errorResponse_1.default)(resp, body, !this.printError) });
161
164
  }
162
165
  return {
163
166
  status: resp.statusCode,
@@ -188,6 +191,7 @@ class API {
188
191
  return new Promise((resolve, reject) => {
189
192
  const responseBuffer = [];
190
193
  let isJSONResponse = false;
194
+ let isErrorPage = false;
191
195
  const throbber = throbber_1.default.getInstance();
192
196
  if (this.logOpts.uploadProgress !== undefined &&
193
197
  this.logOpts.stream instanceof fs_1.ReadStream) {
@@ -230,6 +234,7 @@ class API {
230
234
  }))
231
235
  .on('response', (resp) => {
232
236
  isJSONResponse = js_1.JS.includes(resp.headers['content-type'], 'json');
237
+ isErrorPage = !(resp.statusCode >= 200 && resp.statusCode < 300);
233
238
  this._logResp(resp);
234
239
  })
235
240
  .on('complete', (resp, body) => __awaiter(this, void 0, void 0, function* () {
@@ -244,7 +249,9 @@ class API {
244
249
  if (isJSONResponse) {
245
250
  responseBuffer.push(data);
246
251
  }
247
- this._logDownloadProgress({ chunk: data });
252
+ if (!isErrorPage) {
253
+ this._logDownloadProgress({ chunk: data });
254
+ }
248
255
  });
249
256
  });
250
257
  });
@@ -252,6 +259,7 @@ class API {
252
259
  fire(method, path, options) {
253
260
  return __awaiter(this, void 0, void 0, function* () {
254
261
  this.resolveOnHTTPError = js_1.JS.get(options, 'resolveOnError', this.resolveOnHTTPError);
262
+ this.printError = (options === null || options === void 0 ? void 0 : options.printError) || this.printError;
255
263
  this.maxRetryCount = js_1.JS.get(options, 'maxRetry', this.maxRetryCount);
256
264
  this.authNeeded = js_1.JS.get(options, 'authNeeded', this.authNeeded);
257
265
  this.logOpts = js_1.JS.get(options, 'log', this.logOpts);
@@ -36,7 +36,7 @@ class InquirerFilePath extends inquirer_autocomplete_prompt_1.default {
36
36
  constructor(question, rl, answers) {
37
37
  const { rootPath = '.', exclude = [] } = question;
38
38
  const questionBase = Object.assign({
39
- emptyText: 'No valid file inside current directory!. Try giving the entire path and press ' +
39
+ emptyText: 'No valid file path inside current directory!. Try giving the entire path and press ' +
40
40
  (0, ansi_colors_1.cyan)('<return> ') +
41
41
  'key'
42
42
  }, question, {
@@ -40,7 +40,7 @@ const startAppSail = (port, opts) => {
40
40
  return (0, shell_1.spawn)('node', _opts, {
41
41
  cwd: opts.target,
42
42
  stdio: 'pipe',
43
- env: Object.assign({ X_ZOHO_CATALYST_LISTEN_PORT: port + '', X_ZOHO_CATALYST_RUNTIME_MEMORY: opts.memory + '', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (opts.env || {}))
43
+ env: Object.assign({ X_ZOHO_CATALYST_LISTEN_PORT: port + '', X_ZOHO_CATALYST_RUNTIME_MEMORY: opts.memory + '', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZC_RESOURCE_NAME: opts.name + '', CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (opts.env || {}))
44
44
  }).RAW();
45
45
  };
46
46
  exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function* () {
@@ -62,7 +62,8 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
62
62
  target,
63
63
  command: targetSail.config.command,
64
64
  memory: targetSail.config.memory || 256,
65
- env: targetSail.config.env_variables
65
+ env: targetSail.config.env_variables,
66
+ name: targetSail.name
66
67
  });
67
68
  break;
68
69
  }
@@ -72,7 +73,8 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
72
73
  target,
73
74
  command: targetSail.config.command,
74
75
  memory: targetSail.config.memory || 256,
75
- env: targetSail.config.env_variables
76
+ env: targetSail.config.env_variables,
77
+ name: targetSail.name
76
78
  });
77
79
  break;
78
80
  }
@@ -103,7 +105,8 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
103
105
  type: 'war',
104
106
  command: jettyCommand,
105
107
  memory: targetSail.config.memory || 256,
106
- env: Object.assign({ JETTY_BASE: (0, path_1.join)(jettyPath, 'JETTY_BASE') }, targetSail.config.env_variables)
108
+ env: Object.assign({ JETTY_BASE: (0, path_1.join)(jettyPath, 'JETTY_BASE') }, targetSail.config.env_variables),
109
+ name: targetSail.name
107
110
  });
108
111
  break;
109
112
  }
@@ -112,7 +115,8 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
112
115
  command: targetSail.config.command,
113
116
  type: 'javase',
114
117
  memory: targetSail.config.memory || 256,
115
- env: targetSail.config.env_variables
118
+ env: targetSail.config.env_variables,
119
+ name: targetSail.name
116
120
  });
117
121
  break;
118
122
  }
@@ -276,7 +276,7 @@ public class JavacronInvoker {
276
276
  Method runner = cls.getMethod("handleCronExecute", CronRequest.class, Context.class);
277
277
  CRON_STATUS cronStatus = null;
278
278
 
279
- if(System.getenv("DEBUG").equals("false")) {
279
+ if(System.getenv("DEBUG") != null && System.getenv("DEBUG").equals("false")) {
280
280
  Timer executionTimer = new Timer(true);
281
281
  executionTimer.schedule(new TimerTask() {
282
282
  @Override
@@ -14,6 +14,9 @@ import java.nio.file.Path;
14
14
  import java.nio.file.Paths;
15
15
  import java.util.HashMap;
16
16
  import java.util.Iterator;
17
+ import java.util.Timer;
18
+ import java.util.TimerTask;
19
+ import java.util.concurrent.TimeoutException;
17
20
  import java.util.logging.Handler;
18
21
  import java.util.logging.LogManager;
19
22
  import java.util.logging.LogRecord;
@@ -231,6 +234,17 @@ public class JavaintegInvoker {
231
234
 
232
235
  Method runner = cls.getMethod("runner", ZCIntegRequest.class);
233
236
  ZCIntegResponse integResponse = null;
237
+
238
+ if(System.getenv("DEBUG") != null && System.getenv("DEBUG").equals("false")) {
239
+ Timer executionTimer = new Timer(true);
240
+ executionTimer.schedule(new TimerTask() {
241
+ @Override
242
+ public void run() {
243
+ throwAndExit(new TimeoutException("function execution timeout"), 408, invokerDir);
244
+ }
245
+ }, 900000L); // 15 mins
246
+ }
247
+
234
248
  try {
235
249
  integResponse = (ZCIntegResponse) runner.invoke(cls.getDeclaredConstructor().newInstance(), integRequest);
236
250
  } catch (Exception e) {
@@ -20,6 +20,19 @@ const writeAndExit = (resp) => {
20
20
  process.exit(0);
21
21
  };
22
22
 
23
+ /**
24
+ * execution timeout of 15 minutes
25
+ */
26
+ const timeout = 15 * 60 * 1000;
27
+ // const endTime = timeout + Date.now();
28
+
29
+ // exit on timeout
30
+ process.env.DEBUG === 'false' &&
31
+ setTimeout(() => {
32
+ writeToFile('TIMEOUT', 408);
33
+ process.exit(0);
34
+ }, timeout);
35
+
23
36
  const integrationRequest = data || {};
24
37
 
25
38
  integrationRequest.catalystHeaders = Object.assign(projectJson, authJson);
@@ -10,6 +10,9 @@ import java.net.URLClassLoader;
10
10
  import java.nio.file.Paths;
11
11
  import java.util.HashMap;
12
12
  import java.util.Iterator;
13
+ import java.util.Timer;
14
+ import java.util.TimerTask;
15
+ import java.util.concurrent.TimeoutException;
13
16
  import java.util.logging.Handler;
14
17
  import java.util.logging.LogManager;
15
18
  import java.util.logging.LogRecord;
@@ -233,6 +236,17 @@ public class JavajobInvoker {
233
236
 
234
237
  Method runner = cls.getMethod("handleJobExecute", JobRequest.class, Context.class);
235
238
  JOB_STATUS jobStatus = null;
239
+
240
+ if(System.getenv("DEBUG") != null && System.getenv("DEBUG").equals("false")) {
241
+ Timer executionTimer = new Timer(true);
242
+ executionTimer.schedule(new TimerTask() {
243
+ @Override
244
+ public void run() {
245
+ throwAndExit(new TimeoutException("function execution timeout"), 408, invokerDir);
246
+ }
247
+ }, defaultContext.getMaxExecutionTimeMs());
248
+ }
249
+
236
250
  try {
237
251
  jobStatus = (JOB_STATUS) runner.invoke(cls.getDeclaredConstructor().newInstance(), jobRequest, context);
238
252
  } catch (Exception e) {
@@ -35,12 +35,6 @@ function validateConfig(source, configJson) {
35
35
  };
36
36
  }
37
37
  const absolutePath = (0, path_1.isAbsolute)(buildPath) ? buildPath : (0, path_1.resolve)(source, buildPath);
38
- if (!fs_1.SYNC.pathExists(absolutePath)) {
39
- return {
40
- valid: false,
41
- reason: 'Build Path does not exists'
42
- };
43
- }
44
38
  configJson.build_path = absolutePath;
45
39
  }
46
40
  if (configJson.catalyst_auth === true) {
@@ -78,7 +72,11 @@ function raw(throwError = false) {
78
72
  }
79
73
  return;
80
74
  }
81
- return config.get('appsail');
75
+ const appsailConfig = config.get('appsail');
76
+ return appsailConfig === null || appsailConfig === void 0 ? void 0 : appsailConfig.map((_conf) => {
77
+ _conf.source = (0, path_1.isAbsolute)(_conf.source) ? _conf.source : (0, path_1.normalize)(_conf.source);
78
+ return _conf;
79
+ });
82
80
  }
83
81
  exports.raw = raw;
84
82
  function getTargetDetails(name) {
@@ -99,8 +99,13 @@ function walk(dir, { filter = {
99
99
  const isEntryPthDir = entryPathStats.isDirectory() && !entryPathStats.isSymbolicLink();
100
100
  let excludeMatch = false;
101
101
  if (!(isEntryPthDir && !filter.excludeDir)) {
102
- for (const glob of filter.exclude || []) {
103
- excludeMatch = excludeMatch || (0, minimatch_1.default)(entryPath, glob);
102
+ if (typeof filter.exclude === 'function') {
103
+ excludeMatch = excludeMatch || (yield filter.exclude(entryPath));
104
+ }
105
+ else if (Array.isArray(filter.exclude)) {
106
+ for (const glob of filter.exclude || []) {
107
+ excludeMatch = excludeMatch || (0, minimatch_1.default)(entryPath, glob);
108
+ }
104
109
  }
105
110
  }
106
111
  if (excludeMatch) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcatalyst-cli",
3
- "version": "1.18.0-beta.1",
3
+ "version": "1.18.0-beta.2",
4
4
  "description": "Command Line Tool for CATALYST",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -23,7 +23,7 @@ public class {{_CLASS_}} implements CatalystJobHandler {
23
23
  }
24
24
  LOGGER.log(Level.SEVERE, "Project Details " + request.getProjectDetails().toString());
25
25
  ZCCache.getInstance().putCacheValue("JobSample", "Working", 1l);
26
- LOGGER.log(Level.SEVERE, "Inserted SucessFully:)");
26
+ LOGGER.log(Level.SEVERE, "Inserted SuccessFully:)");
27
27
  } catch (Exception e) {
28
28
  LOGGER.log(Level.SEVERE, "Exception in Job Function", e);
29
29
  return JOB_STATUS.FAILURE;
@@ -1,5 +1,12 @@
1
1
  'use strict';
2
2
 
3
+ const { IncomingMessage, ServerResponse } = require("http");
4
+
5
+ /**
6
+ *
7
+ * @param {IncomingMessage} req
8
+ * @param {ServerResponse} res
9
+ */
3
10
  module.exports = (req, res) => {
4
11
  var url = req.url;
5
12
 
@@ -1,3 +1,8 @@
1
+ /**
2
+ *
3
+ * @param {import('./types/basicio').Context} context
4
+ * @param {import('./types/basicio').BasicIO} basicIO
5
+ */
1
6
  module.exports = (context, basicIO) => {
2
7
  /*
3
8
  BASICIO FUNCTIONALITIES
@@ -0,0 +1,57 @@
1
+ /**
2
+ * This is a utility file with the type declaration of the BasicIO function parameters
3
+ */
4
+
5
+ /**
6
+ * Type of the BasicIO object. Contains the functional APIs of BasicIO
7
+ */
8
+ export interface BasicIO {
9
+ /**
10
+ * Write to the BasicIO output
11
+ * @param value input string
12
+ * @returns
13
+ */
14
+ write: (value: string) => void;
15
+ /**
16
+ * Set the BasicIO status code
17
+ * @param statusCode status code of BasicIO
18
+ * @returns
19
+ */
20
+ setStatus: (statusCode: number) => void;
21
+ /**
22
+ * Get the input argument values of the BasicIO
23
+ * @param key argument name(key)
24
+ * @returns argument value as string
25
+ */
26
+ getArgument: (key: string) => string;
27
+ /**
28
+ * Get all input arguments
29
+ * @returns all arguments as key value pair
30
+ */
31
+ getAllArguments: () => Record<string, string>;
32
+ }
33
+
34
+ /**
35
+ * Type of the context object of the function
36
+ */
37
+ export interface Context {
38
+ /**
39
+ * Contains catalyst auth headers (for internal use)
40
+ */
41
+ catalystHeaders: Record<string, string>;
42
+ /**
43
+ * To indicate the end of a function execution
44
+ * @returns
45
+ */
46
+ close: () => void;
47
+ /**
48
+ * Fetch the remaining execution time of the function
49
+ * @returns remaining execution time in milliseconds
50
+ */
51
+ getRemainingExecutionTimeMs: () => number;
52
+ /**
53
+ * Fetch the maximum execution time of the function
54
+ * @returns maximum execution time in milliseconds
55
+ */
56
+ getMaxExecutionTimeMs: () => number;
57
+ }
@@ -1,3 +1,8 @@
1
+ /**
2
+ *
3
+ * @param {import('./types/cron').CronDetails} cronDetails
4
+ * @param {import('./types/cron').Context} context
5
+ */
1
6
  module.exports = (cronDetails, context) => {
2
7
  console.log('Hello from {{_MAIN_}}');
3
8
 
@@ -0,0 +1,64 @@
1
+ /**
2
+ * This is a utility file with the type declaration of the Cron function parameters
3
+ */
4
+
5
+ /**
6
+ * Type of Cron Details object. Contains the details of the scheduled cron
7
+ */
8
+ export interface CronDetails {
9
+ /**
10
+ * Get the input param value of the Cron function
11
+ * @returns input param value
12
+ */
13
+ getCronParam: () => string;
14
+ /**
15
+ * Get all input params of the Cron function
16
+ * @returns all input params as key value pairs
17
+ */
18
+ getAllCronParam: () => Record<string, string>;
19
+ /**
20
+ * Get the remaining execution count of the cron job
21
+ * @returns remaining execution count
22
+ */
23
+ getRemainingExecutionCount: () => number;
24
+ /**
25
+ * Get the details of the cron which executed the function
26
+ * @returns cron details
27
+ */
28
+ getCronDetails: () => Record<string, unknown>;
29
+ /**
30
+ * Get the current project details
31
+ * @returns project details
32
+ */
33
+ getProjectDetails: () => Record<string, unknown>;
34
+ }
35
+
36
+ /**
37
+ * Type of the Context object of the Cron function
38
+ */
39
+ export interface Context {
40
+ /**
41
+ * Contains catalyst auth headers (for internal use)
42
+ */
43
+ catalystHeaders: Record<string, string>;
44
+ /**
45
+ * Close the Cron function with success response
46
+ * @returns
47
+ */
48
+ closeWithSuccess: () => void;
49
+ /**
50
+ * Close the Cron function failure response
51
+ * @returns
52
+ */
53
+ closeWithFailure: () => void;
54
+ /**
55
+ * Get the remaining execution time of the Cron function
56
+ * @returns remaining execution time in milliseconds
57
+ */
58
+ getRemainingExecutionTimeMs: () => number;
59
+ /**
60
+ * Get the maximum possible execution time of the Cron function
61
+ * @returns maximum possible execution time in milliseconds
62
+ */
63
+ getMaxExecutionTimeMs: () => number;
64
+ }
@@ -1,20 +1,23 @@
1
+ /**
2
+ *
3
+ * @param {import('./types/event').EventDetails} event
4
+ * @param {import('./types/event').Context} context
5
+ */
1
6
  module.exports = (event, context) => {
2
7
  /*
3
8
  EVENT FUNCTIONALITIES
4
9
  */
5
- // const DATA = event.data; //event data
6
- // const TIME = event.time; //event occured time
10
+ // const DATA = event.getData(); //event data
11
+ // const TIME = event.getTime(); //event occurred time
7
12
 
8
- // const SOURCE_DETAILS = event.getSourceDetails(); //event source details
9
- // const SOURCE_ACTION = SOURCE_DETAILS.action; //(insert | fetch | invoke ...)
10
- // const SOURCE_TYPE = SOURCE_DETAILS.type; //(datastore | cache | queue ...)
11
- // const SOURCE_ENTITY_ID = SOURCE_DETAILS.entityId; //if type is datastore then entity id is tableid
13
+ // const ACTION = event.getAction(); //(insert | fetch | invoke ...)
14
+ // const SOURCE = event.getSource(); //(datastore | cache | queue ...)
15
+ // const SOURCE_ENTITY_ID = event.getSourceEntityId(); //if type is datastore then entity id is tableid
12
16
 
13
- // const SOURCE_BUS_DETAILS = SOURCE_DETAILS.getBusDetails(); //event bus details
17
+ // const SOURCE_BUS_DETAILS = event.getBusDetails(); //event bus details
14
18
  // const SOURCE_BUS_ID = SOURCE_BUS_DETAILS.id; //event bus id
15
19
 
16
20
  // const PROJECT_DETAILS = event.getProjectDetails(); //event project details
17
- // const FUNCTION_DETAILS = event.getFunctionDetails(); //event function details
18
21
 
19
22
  console.log('Hello from {{_MAIN_}}');
20
23
 
@@ -0,0 +1,82 @@
1
+ /**
2
+ * This is a utility file with the type declaration of the Event function parameters
3
+ */
4
+
5
+ /**
6
+ * Type of Event Details object. Contains the details of the triggered Event
7
+ */
8
+ export interface EventDetails {
9
+ /**
10
+ * Event data
11
+ */
12
+ data: Record<string, unknown>;
13
+ /**
14
+ * Time of the event
15
+ */
16
+ time: number;
17
+ /**
18
+ * Get the project details of the event function
19
+ * @returns project details
20
+ */
21
+ getProjectDetails: () => Record<string, unknown>;
22
+ /**
23
+ * Functional API to get the data of the event
24
+ * @returns event data
25
+ */
26
+ getData: () => Record<string, unknown>;
27
+ /**
28
+ * Functional API to get the time of the event
29
+ * @returns event time
30
+ */
31
+ getTime: () => number;
32
+ /**
33
+ * Get the action that triggered the event
34
+ * @returns action
35
+ */
36
+ getAction: () => string;
37
+ /**
38
+ * Get the source of the event
39
+ * @returns event source
40
+ */
41
+ getSource: () => string;
42
+ /**
43
+ * Get the Id of the entity that triggered the event
44
+ * @returns source entity's Id
45
+ */
46
+ getSourceEntityId: () => string;
47
+ /**
48
+ * Get the details of the event bus
49
+ * @returns event bus details
50
+ */
51
+ getEventBusDetails: () => Record<string, unknown>;
52
+ }
53
+
54
+ /**
55
+ * Type of the Context object of the Event function
56
+ */
57
+ export interface Context {
58
+ /**
59
+ * Contains catalyst auth headers (for internal use)
60
+ */
61
+ catalystHeaders: Record<string, string>;
62
+ /**
63
+ * Close the Event function with success response
64
+ * @returns
65
+ */
66
+ closeWithSuccess: () => void;
67
+ /**
68
+ * Close the Event function failure response
69
+ * @returns
70
+ */
71
+ closeWithFailure: () => void;
72
+ /**
73
+ * Get the remaining execution time of the Event function
74
+ * @returns remaining execution time in milliseconds
75
+ */
76
+ getRemainingExecutionTimeMs: () => number;
77
+ /**
78
+ * Get the maximum possible execution time of the Event function
79
+ * @returns maximum possible execution time in milliseconds
80
+ */
81
+ getMaxExecutionTimeMs: () => number;
82
+ }
@@ -15,7 +15,6 @@ module.exports = (jobRequest, context) => {
15
15
  const projectDetails = jobRequest.getProjectDetails(); // to get the current project details
16
16
  const jobDetails = jobRequest.getJobDetails(); // to get the current job details
17
17
  const jobMetaDetails = jobRequest.getJobMetaDetails(); // to get the current job's meta details
18
- const jobpoolDetails = jobRequest.getJobpoolDetails(); // to get the current function job pool's details
19
18
  const getJobCapacityAttributes = jobRequest.getJobCapacityAttributes(); // to get the current jobs capacity
20
19
  const allJobParams = jobRequest.getAllJobParams(); // to get all the parameters supplied to the job function
21
20
  const jobParam = jobRequest.getJobParam('key'); // to get the value of a particular parameter supplied to the job function
@@ -18,10 +18,6 @@ export interface JobRequest {
18
18
  * @returns Meta details of the current job
19
19
  */
20
20
  getJobMetaDetails: () => Record<string, unknown>;
21
- /**
22
- * @returns Job pool details of the current job
23
- */
24
- getJobpoolDetails: () => Record<string, unknown>;
25
21
  /**
26
22
  * @returns Capacity attributes of the current job
27
23
  */
@@ -11,7 +11,6 @@ def handler(job_request, context):
11
11
  job_details = job_request.get_job_details() # get the details of the current job
12
12
  project_details = job_request.get_project_details() # get the details of the current project
13
13
  job_meta_details = job_request.get_job_meta_details() # get the job meta of the current job
14
- job_pool_details = job_request.get_job_pool_details() # get the current functions job pool details
15
14
  job_capacity_attributes = job_request.get_job_capacity_attributes() # get the current jobs capacity
16
15
  all_job_params = job_request.get_all_job_params() # get all the parameters supplied to the job function
17
16
  job_param = job_request.get_job_param('key') # get the value of a particular parameter supplied to the job function