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

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.
@@ -1,4 +1,25 @@
1
1
  [SERVE-APPSAIL-1]
2
- context = '''The provided build path (${arg[0]}) for the AppSail ${arg[1]} does not exists.'''
2
+ context = '''The provided build path ${arg[0]} for the AppSail ${arg[1]} does not exists.'''
3
3
  aid = '''Please provide a valid build path'''
4
4
  link = ''
5
+
6
+ [SERVE-APPSAIL-2]
7
+ context = '''The build path resolved from the provided relative path "${arg[0]}" does not exists.
8
+ Source path : ${arg[1]}
9
+ Build path : ${arg[2]}
10
+ Resolved Path : ${arg[3]}'''
11
+ aid = '''Please provide a valid relative path as build path'''
12
+ link = ''
13
+
14
+ [SERVE-APPSAIL-3]
15
+ context = '''Unable to start the ${arg[0]} AppSail server with the below parameters.
16
+ Command : ${arg[1]}
17
+ Build path : ${arg[2]}
18
+ Runtime : ${arg[3]}'''
19
+ aid = '''Please fix the errors if any'''
20
+ link = ''
21
+
22
+ [SERVE-APPSAIL-4]
23
+ context = '''Invalid AppSail Stack/Runtime for AppSail ${arg[0]}: ${arg[1]}'''
24
+ aid = '''Please use a supported Stack/Runtime from the below list: \n${arg[2]}'''
25
+ link = ''
@@ -54,7 +54,6 @@ exports.default = new command_1.default('event:generate <source> <action>')
54
54
  .needs('auth')
55
55
  .action(function generate(source, action) {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
- var _a;
58
57
  const unknownArgs = (0, option_1.getUnknownOpts)([]);
59
58
  if (unknownArgs.length % 2 !== 0) {
60
59
  throw new error_1.default('Unknown options are not provided as key value pairs', {
@@ -176,7 +175,7 @@ exports.default = new command_1.default('event:generate <source> <action>')
176
175
  break;
177
176
  }
178
177
  });
179
- const sourceModule = (yield (_a = '../../../event_generate/' + source, Promise.resolve().then(() => __importStar(require(_a))))).default;
178
+ const sourceModule = (yield Promise.resolve().then(() => __importStar(require('../../../event_generate/' + source)))).default;
180
179
  eventJsonContent = yield sourceModule(eventJsonContent, optionMap, action);
181
180
  const jsonContent = JSON.parse(eventJsonContent);
182
181
  Object.keys(jsonContent).forEach((key) => {
@@ -46,7 +46,6 @@ exports.default = new command_1.default('event:generate:integ <service>')
46
46
  .needs('rc')
47
47
  .needs('auth')
48
48
  .action((service) => __awaiter(void 0, void 0, void 0, function* () {
49
- var _a;
50
49
  const availableServices = Object.keys(constants_1.INTEG.service_map);
51
50
  if (!availableServices.includes(service)) {
52
51
  throw new error_1.default('Unknown service requested', {
@@ -57,7 +56,7 @@ exports.default = new command_1.default('event:generate:integ <service>')
57
56
  }
58
57
  const inputs = (0, option_1.getOptionValue)('inputs', '');
59
58
  const serviceValue = constants_1.INTEG.service_map[service];
60
- const serviceModule = (yield (_a = `../../../event_generate/integration/${serviceValue}`, Promise.resolve().then(() => __importStar(require(_a)))))
59
+ const serviceModule = (yield Promise.resolve().then(() => __importStar(require(`../../../event_generate/integration/${serviceValue}`))))
61
60
  .default;
62
61
  const payload = yield serviceModule(inputs);
63
62
  process.stdout.write(payload + '\n');
@@ -36,8 +36,7 @@ exports.default = (client) => {
36
36
  function loadCommand(name) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
38
  return new Promise((resolve, reject) => setTimeout(() => __awaiter(this, void 0, void 0, function* () {
39
- var _a;
40
- const cmd = (yield (_a = './' + name.split(':').join('/'), Promise.resolve().then(() => __importStar(require(_a))))).default;
39
+ const cmd = (yield Promise.resolve().then(() => __importStar(require('./' + name.split(':').join('/'))))).default;
41
40
  try {
42
41
  cmd.register(client);
43
42
  resolve();
@@ -62,5 +62,23 @@ class TunnelAPI {
62
62
  });
63
63
  });
64
64
  }
65
+ tunnelCallback(status, details, data) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const res = yield new api_1.default(this.opts).post(`/baas/v1/project/${this.projectId}/tunneling/callback`, {
68
+ body: {
69
+ status,
70
+ content: Object.assign({}, details),
71
+ data
72
+ }
73
+ });
74
+ if (res.status >= 200 && res.status <= 299) {
75
+ return;
76
+ }
77
+ (0, logger_1.debug)(`tunnel callback response from server ::: status=${res.status} ::: body=${res.body}`);
78
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
79
+ exit: 2
80
+ });
81
+ });
82
+ }
65
83
  }
66
84
  exports.default = TunnelAPI;
@@ -196,7 +196,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
196
196
  stack: appSailStack.runtime,
197
197
  env_variables: {},
198
198
  memory: _appSailConfig.memory || 256,
199
- scripts: _appSailConfig.scripts || {}
199
+ scripts: _appSailConfig.scripts || {},
200
+ raw: {}
200
201
  };
201
202
  if (appSailStack.lang === 'java') {
202
203
  const platform = yield prompt_1.default.ask(prompt_1.default.question('value', 'Please choose a platform for your AppSail: ', {
@@ -38,7 +38,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const index_js_1 = __importDefault(require("../../../prompt/index.js"));
39
39
  const index_js_2 = require("../../../util_modules/constants/index.js");
40
40
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
41
- var _a;
42
41
  const clientInitAnswer = yield index_js_1.default.ask(index_js_1.default.question('clientFlavour', 'Choose the type of client to initialise: ', {
43
42
  type: 'list',
44
43
  choices: index_js_2.PLUGIN.client.map((plugin) => {
@@ -48,5 +47,5 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
48
47
  });
49
48
  })
50
49
  }));
51
- return (yield (_a = './initializers/' + clientInitAnswer.clientFlavour, Promise.resolve().then(() => __importStar(require(_a))))).default();
50
+ return (yield Promise.resolve().then(() => __importStar(require('./initializers/' + clientInitAnswer.clientFlavour)))).default();
52
51
  });
@@ -229,8 +229,7 @@ class Command {
229
229
  (0, logger_1.debug)(e);
230
230
  }
231
231
  yield Promise.all(js_1.JS.map(this.beforeRunners, (before) => __awaiter(this, void 0, void 0, function* () {
232
- var _a;
233
- const beforeModule = (yield (_a = '../command_needs/' + before.fn, Promise.resolve().then(() => __importStar(require(_a))))).default;
232
+ const beforeModule = (yield Promise.resolve().then(() => __importStar(require('../command_needs/' + before.fn)))).default;
234
233
  return beforeModule.call(this, before.args);
235
234
  })));
236
235
  return this.cmdAction.call(this, ...args);
@@ -44,7 +44,6 @@ const rc_1 = __importDefault(require("../internal/rc"));
44
44
  const fs_1 = require("../util_modules/fs");
45
45
  const logger_1 = require("../util_modules/logger");
46
46
  const runMigration = (rc, migFiles, idx = 0) => __awaiter(void 0, void 0, void 0, function* () {
47
- var _a;
48
47
  if (migFiles.length <= idx) {
49
48
  return Promise.resolve();
50
49
  }
@@ -55,7 +54,7 @@ const runMigration = (rc, migFiles, idx = 0) => __awaiter(void 0, void 0, void 0
55
54
  return runMigration(rc, migFiles, ++idx);
56
55
  }
57
56
  try {
58
- const migModule = yield (_a = migFile, Promise.resolve().then(() => __importStar(require(_a))));
57
+ const migModule = yield Promise.resolve().then(() => __importStar(require(migFile)));
59
58
  if (migModule.isRequire()) {
60
59
  (0, logger_1.debug)('migration started for v' + currentMigFileVersion);
61
60
  migModule.migrate();
@@ -84,7 +83,6 @@ const runMigration = (rc, migFiles, idx = 0) => __awaiter(void 0, void 0, void 0
84
83
  return runMigration(rc, migFiles, ++idx);
85
84
  });
86
85
  const runGlobalMigration = (migFiles) => __awaiter(void 0, void 0, void 0, function* () {
87
- var _b;
88
86
  if (migFiles.length === 0) {
89
87
  return;
90
88
  }
@@ -98,7 +96,7 @@ const runGlobalMigration = (migFiles) => __awaiter(void 0, void 0, void 0, funct
98
96
  return runGlobalMigration(migFiles);
99
97
  }
100
98
  try {
101
- const migModule = yield (_b = migFile, Promise.resolve().then(() => __importStar(require(_b))));
99
+ const migModule = yield Promise.resolve().then(() => __importStar(require(migFile)));
102
100
  if (migModule.isRequire()) {
103
101
  (0, logger_1.debug)('migration started for v' + currentMigFileVersion);
104
102
  migModule.migrate();
@@ -42,7 +42,6 @@ const async_js_1 = require("./util_modules/fs/lib/async.js");
42
42
  const error_js_1 = __importDefault(require("./error.js"));
43
43
  const ansi_colors_1 = require("ansi-colors");
44
44
  exports.default = (name, source) => __awaiter(void 0, void 0, void 0, function* () {
45
- var _a, _b;
46
45
  if (name === (0, path_1.basename)(name)) {
47
46
  const projectModulePath = (0, project_js_1.resolveProjectPath)((0, path_1.join)(source, 'node_modules', name));
48
47
  const projectModulePathExists = yield (0, async_js_1.dirExists)(projectModulePath);
@@ -54,7 +53,7 @@ exports.default = (name, source) => __awaiter(void 0, void 0, void 0, function*
54
53
  });
55
54
  }
56
55
  app_module_path_1.default.addPath(projectModulePath);
57
- return _a = projectModulePath, Promise.resolve().then(() => __importStar(require(_a)));
56
+ return Promise.resolve().then(() => __importStar(require(projectModulePath)));
58
57
  }
59
58
  const projectModulePath = (0, project_js_1.resolveProjectPath)(name);
60
59
  const projectModulePathExists = yield (0, async_js_1.dirExists)(projectModulePath);
@@ -66,5 +65,5 @@ exports.default = (name, source) => __awaiter(void 0, void 0, void 0, function*
66
65
  });
67
66
  }
68
67
  app_module_path_1.default.addPath(projectModulePath);
69
- return _b = projectModulePath, Promise.resolve().then(() => __importStar(require(_b)));
68
+ return Promise.resolve().then(() => __importStar(require(projectModulePath)));
70
69
  });
@@ -26,9 +26,6 @@ var ETreeState;
26
26
  ETreeState[ETreeState["EXPANDED"] = 3] = "EXPANDED";
27
27
  })(ETreeState || (ETreeState = {}));
28
28
  class TreeNode {
29
- get indent() {
30
- return this.level * 2;
31
- }
32
29
  constructor(root) {
33
30
  _TreeNode_instances.add(this);
34
31
  this.open = false;
@@ -39,6 +36,9 @@ class TreeNode {
39
36
  this.level = 1;
40
37
  this.root = root;
41
38
  }
39
+ get indent() {
40
+ return this.level * 2;
41
+ }
42
42
  addNode(node) {
43
43
  if (node instanceof TreeNode) {
44
44
  this.leaves.push(node);
@@ -41,7 +41,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
41
41
  name: targ.name + '_proxy',
42
42
  server: 'service'
43
43
  });
44
- return Object.assign(Object.assign({}, targ), { port: { appsail: appsailPort, proxy: proxyPort } });
44
+ return Object.assign(Object.assign({}, targ), { port: { appsail: appsailPort, proxy: proxyPort }, trigger: { kill: false } });
45
45
  })));
46
46
  runtime_store_1.default.set('context.appsail.targets', filledTargets);
47
47
  });
@@ -302,6 +302,11 @@ class Server {
302
302
  var _a;
303
303
  switch (targType) {
304
304
  case 'functions': {
305
+ const headersDisplayed = {
306
+ bio: false,
307
+ aio: false,
308
+ blo: false
309
+ };
305
310
  Object.entries(logTarg).forEach((x) => {
306
311
  const [_targType, _logTarg] = x;
307
312
  if (_logTarg.targs.length === 0) {
@@ -310,48 +315,66 @@ class Server {
310
315
  loggedEntries++;
311
316
  switch (_targType) {
312
317
  case 'bio': {
313
- (0, logger_1.info)();
314
- (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> BasicIO <<<<<<<<<<<<<< '));
315
318
  _logTarg.targs.forEach((t) => {
316
- var _a;
319
+ var _a, _b;
317
320
  const target = t;
318
- if (!((_a = target.target) === null || _a === void 0 ? void 0 : _a.url)) {
321
+ if (!((_a = target.target) === null || _a === void 0 ? void 0 : _a.valid)) {
322
+ return;
323
+ }
324
+ if (!((_b = target.target) === null || _b === void 0 ? void 0 : _b.url)) {
319
325
  throw new error_1.default('Target URL not found', {
320
326
  exit: 2
321
327
  });
322
328
  }
329
+ if (headersDisplayed.bio === false) {
330
+ (0, logger_1.info)();
331
+ (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> BasicIO <<<<<<<<<<<<<< '));
332
+ headersDisplayed.bio = true;
333
+ }
323
334
  bioLogUrl(target, masterPort, _logTarg.nameMaxLength);
324
335
  });
325
336
  (0, logger_1.info)();
326
337
  break;
327
338
  }
328
339
  case 'aio': {
329
- (0, logger_1.info)();
330
- (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>> AdvancedIO <<<<<<<<<<<< '));
331
340
  _logTarg.targs.forEach((t) => {
332
- var _a;
341
+ var _a, _b;
333
342
  const _target = t;
334
- if (!((_a = _target.target) === null || _a === void 0 ? void 0 : _a.url)) {
343
+ if (!((_a = _target.target) === null || _a === void 0 ? void 0 : _a.valid)) {
344
+ return;
345
+ }
346
+ if (!((_b = _target.target) === null || _b === void 0 ? void 0 : _b.url)) {
335
347
  throw new error_1.default('Target URL not found', {
336
348
  exit: 2
337
349
  });
338
350
  }
351
+ if (headersDisplayed.aio === false) {
352
+ (0, logger_1.info)();
353
+ (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>> AdvancedIO <<<<<<<<<<<< '));
354
+ headersDisplayed.aio = true;
355
+ }
339
356
  aioLogUrl(_target, masterPort, _logTarg.nameMaxLength);
340
357
  });
341
358
  (0, logger_1.info)();
342
359
  break;
343
360
  }
344
361
  case 'browserlogic': {
345
- (0, logger_1.info)();
346
- (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>> BrowserLogic <<<<<<<<<<< '));
347
362
  _logTarg.targs.forEach((t) => {
348
- var _a;
363
+ var _a, _b;
349
364
  const target = t;
350
- if (!((_a = target.target) === null || _a === void 0 ? void 0 : _a.url)) {
365
+ if (!((_a = target.target) === null || _a === void 0 ? void 0 : _a.valid)) {
366
+ return;
367
+ }
368
+ if (!((_b = target.target) === null || _b === void 0 ? void 0 : _b.url)) {
351
369
  throw new error_1.default('Target URL not found', {
352
370
  exit: 2
353
371
  });
354
372
  }
373
+ if (headersDisplayed.blo === false) {
374
+ (0, logger_1.info)();
375
+ (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>> BrowserLogic <<<<<<<<<<< '));
376
+ headersDisplayed.blo = true;
377
+ }
355
378
  bioLogUrl(target, masterPort, _logTarg.nameMaxLength);
356
379
  });
357
380
  (0, logger_1.info)();
@@ -367,10 +390,17 @@ class Server {
367
390
  return;
368
391
  }
369
392
  loggedEntries++;
370
- (0, logger_1.info)();
371
- (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> AppSail <<<<<<<<<<<<<< '));
393
+ let isHeaderDisplayed = false;
372
394
  _logTarg.targs.forEach((t) => {
373
395
  const targetSail = t.target;
396
+ if (!targetSail.validity.valid) {
397
+ return;
398
+ }
399
+ if (isHeaderDisplayed === false) {
400
+ (0, logger_1.info)();
401
+ (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> AppSail <<<<<<<<<<<<<< '));
402
+ isHeaderDisplayed = true;
403
+ }
374
404
  const targName = targetSail.name + '';
375
405
  (0, logger_1.labeled)(targName +
376
406
  ' '.repeat((_logTarg.nameMaxLength || targName.length) - targName.length), `http://localhost:${targetSail.port.proxy}`).MESSAGE();
@@ -24,6 +24,8 @@ const archiver_1 = __importDefault(require("../../../../archiver"));
24
24
  const option_1 = require("../../../../util_modules/option");
25
25
  const execute_script_1 = require("../../../../execute-script");
26
26
  const master_1 = __importDefault(require("../master"));
27
+ const ansi_colors_1 = require("ansi-colors");
28
+ const common_1 = require("../../../../init/util/common");
27
29
  function executeHook(script, name, moduleSource) {
28
30
  if ((0, option_1.getOptionValue)('ignoreScripts', false)) {
29
31
  (0, logger_1.debug)(`skipping ${name} hook`);
@@ -37,14 +39,18 @@ const startAppSail = (port, opts) => {
37
39
  if (opts.command) {
38
40
  _opts.push('-c', opts.command);
39
41
  }
40
- return (0, shell_1.spawn)('node', _opts, {
42
+ const child = (0, shell_1.spawn)('node', _opts, {
41
43
  cwd: opts.target,
42
44
  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, X_ZC_RESOURCE_NAME: opts.name + '', CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (opts.env || {}))
45
+ 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_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZC_RESOURCE_NAME: opts.name + '', CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (opts.env || {}))
44
46
  }).RAW();
47
+ return new Promise((_res, _rej) => {
48
+ child.on('spawn', () => _res(child));
49
+ child.on('error', (reason) => _rej(reason));
50
+ });
45
51
  };
46
52
  exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function* () {
47
- var _a, _b, _c, _d;
53
+ var _a, _b, _c, _d, _e, _f, _g;
48
54
  let child;
49
55
  const targetSail = serverDetails.target;
50
56
  if (!targetSail || !targetSail.config) {
@@ -55,9 +61,28 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
55
61
  }
56
62
  const buildPath = (_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.build_path;
57
63
  const target = (yield fs_1.ASYNC.fileExists(buildPath)) ? (0, path_1.dirname)(buildPath) : buildPath;
64
+ if (!(yield fs_1.ASYNC.isPathExists(target))) {
65
+ if ((0, path_1.isAbsolute)(((_c = targetSail.config) === null || _c === void 0 ? void 0 : _c.raw.build_path) || '')) {
66
+ throw new error_1.default('The given AppSail build path does not exists', {
67
+ exit: 1,
68
+ errorId: 'SERVE-APPSAIL-1',
69
+ arg: [ansi_colors_1.italic.underline.red(target), (0, ansi_colors_1.bold)(targetSail.name)]
70
+ });
71
+ }
72
+ throw new error_1.default('The given AppSail build path does not exists: ' + targetSail.name, {
73
+ exit: 1,
74
+ errorId: 'SERVE-APPSAIL-2',
75
+ arg: [
76
+ (0, ansi_colors_1.underline)(((_d = targetSail.config) === null || _d === void 0 ? void 0 : _d.raw.build_path) || ''),
77
+ ansi_colors_1.italic.underline(targetSail.config.raw.source_path || ''),
78
+ ansi_colors_1.italic.underline(((_e = targetSail.config) === null || _e === void 0 ? void 0 : _e.raw.build_path) || ''),
79
+ ansi_colors_1.italic.underline(target)
80
+ ]
81
+ });
82
+ }
58
83
  switch (true) {
59
84
  case targetSail.config.stack.startsWith('node'): {
60
- child = startAppSail(targetSail.port.appsail, {
85
+ child = yield startAppSail(targetSail.port.appsail, {
61
86
  type: 'nodejs',
62
87
  target,
63
88
  command: targetSail.config.command,
@@ -68,7 +93,7 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
68
93
  break;
69
94
  }
70
95
  case targetSail.config.stack.startsWith('python'): {
71
- child = startAppSail(targetSail.port.appsail, {
96
+ child = yield startAppSail(targetSail.port.appsail, {
72
97
  type: 'python',
73
98
  target,
74
99
  command: targetSail.config.command,
@@ -100,7 +125,7 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
100
125
  }
101
126
  }
102
127
  const jettyCommand = `java -jar "${(0, path_1.join)(jettyPath, 'start.jar')}" -Djetty.deploy.monitoredPath="${(0, project_1.resolveProjectPath)(target)}" -Djetty.http.port=${targetSail.port.appsail}`;
103
- child = startAppSail(targetSail.port.appsail, {
128
+ child = yield startAppSail(targetSail.port.appsail, {
104
129
  target,
105
130
  type: 'war',
106
131
  command: jettyCommand,
@@ -110,7 +135,7 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
110
135
  });
111
136
  break;
112
137
  }
113
- child = startAppSail(targetSail.port.appsail, {
138
+ child = yield startAppSail(targetSail.port.appsail, {
114
139
  target,
115
140
  command: targetSail.config.command,
116
141
  type: 'javase',
@@ -121,7 +146,16 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
121
146
  break;
122
147
  }
123
148
  default: {
124
- throw new error_1.default('Invalid AppSail stack');
149
+ const appSailRuntime = yield (0, common_1.getRuntimeDetails)();
150
+ throw new error_1.default('Invalid AppSail stack', {
151
+ exit: 1,
152
+ errorId: 'SERVE-APPSAIL-4',
153
+ arg: [
154
+ (0, ansi_colors_1.bold)(targetSail.name),
155
+ ansi_colors_1.bold.red(targetSail.config.stack),
156
+ appSailRuntime.runtimes.map((val) => (0, ansi_colors_1.bold)(`* ${val}`)).join('\n')
157
+ ]
158
+ });
125
159
  }
126
160
  }
127
161
  const masterServe = yield (0, master_1.default)(targetSail.port.proxy, {
@@ -134,7 +168,7 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
134
168
  }
135
169
  });
136
170
  });
137
- if ((_d = (_c = targetSail.config) === null || _c === void 0 ? void 0 : _c.scripts) === null || _d === void 0 ? void 0 : _d.postserve) {
171
+ if ((_g = (_f = targetSail.config) === null || _f === void 0 ? void 0 : _f.scripts) === null || _g === void 0 ? void 0 : _g.postserve) {
138
172
  child.once('exit', () => {
139
173
  var _a, _b, _c;
140
174
  if (!((_a = targetSail.config) === null || _a === void 0 ? void 0 : _a.scripts)) {
@@ -143,5 +177,27 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
143
177
  executeHook((_c = (_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.scripts) === null || _c === void 0 ? void 0 : _c.postserve, `AppSail [POSTSERVE] [${targetSail.name}]`, targetSail.source);
144
178
  });
145
179
  }
180
+ process.on('SIGINT', () => {
181
+ targetSail.trigger.kill = true;
182
+ });
183
+ child.once('exit', (code) => {
184
+ var _a, _b, _c;
185
+ if (code === 150) {
186
+ targetSail.validity = {
187
+ valid: false,
188
+ reason: 'Unable to start the AppSail'
189
+ };
190
+ throw new error_1.default('Unable to start the AppSail', {
191
+ exit: 1,
192
+ errorId: 'SERVE-APPSAIL-3',
193
+ arg: [
194
+ (0, ansi_colors_1.bold)(targetSail.name),
195
+ ((_a = targetSail.config) === null || _a === void 0 ? void 0 : _a.command) || '',
196
+ (0, ansi_colors_1.underline)(((_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.build_path) || ''),
197
+ ((_c = targetSail.config) === null || _c === void 0 ? void 0 : _c.stack) || ''
198
+ ]
199
+ });
200
+ }
201
+ });
146
202
  return child;
147
203
  });
@@ -1,5 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  /* eslint-disable @typescript-eslint/no-var-requires */
3
+
4
+ // exit codes
5
+ // 150 - start up command failure
6
+
3
7
  const EXEC_SYNC = require('child_process').execSync;
4
8
 
5
9
  const WAR = 'war';
@@ -58,7 +62,11 @@ function main() {
58
62
  throw new Error(`invalid runtime type: ${CMD_ARGS.rtType}`);
59
63
  }
60
64
 
61
- EXEC_SYNC(command.toString(), { stdio: 'inherit', cwd });
65
+ try {
66
+ EXEC_SYNC(command.toString(), { stdio: 'inherit', cwd });
67
+ } catch (er) {
68
+ process.exit(150);
69
+ }
62
70
  }
63
71
 
64
72
  main();
@@ -39,6 +39,9 @@ exports.default = (proxyInstance, masterPort, customProxyUrl) => (req, res) => {
39
39
  proxyInstance.web(req, res, {
40
40
  target: `https://${req.headers['x-zc-project-domain']}`,
41
41
  changeOrigin: true,
42
+ cookieDomainRewrite: {
43
+ [req.headers['x-zc-project-domain'] + '']: 'localhost'
44
+ },
42
45
  ws: true,
43
46
  headers
44
47
  });
@@ -107,12 +107,12 @@ const proxyResponseHandler = ({ systemRoutes, signInRedirect = '/app/local-redir
107
107
  }
108
108
  }
109
109
  }
110
- else if (req.url.startsWith('/accounts') && req.url.includes('/signin')) {
111
- const set = proxyRes.headers['set-cookie'];
112
- set
113
- ? set.push('IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/')
114
- : ['IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/'];
115
- proxyRes.headers['set-cookie'] = set;
110
+ else if (req.url.startsWith('/accounts')) {
111
+ const set = proxyRes.headers['set-cookie'] || [];
112
+ if (req.url.includes('/signin')) {
113
+ set.push('IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/');
114
+ }
115
+ proxyRes.headers['set-cookie'] = set.map(exports.removeSecure);
116
116
  }
117
117
  };
118
118
  exports.proxyResponseHandler = proxyResponseHandler;
@@ -217,7 +217,7 @@ public class JavajobInvoker {
217
217
  JSONObject jobMetaDetails = jobDetails.getJSONObject("job_meta_details");
218
218
  JSONObject jobpoolDetails = jobMetaDetails.getJSONObject("jobpool_details");
219
219
  JSONObject projectDetails = jobpoolDetails.getJSONObject("project_details");
220
- JSONObject capacity = jobDetails.getJSONObject("capacity");
220
+ JSONObject capacity = userData.getJSONObject("capacity");
221
221
  JSONObject params = jobMetaDetails.getJSONObject("params");
222
222
 
223
223
  defaultJob.setJobDetails(jobDetails != null ? (JSONObject) jobDetails : new JSONObject());
@@ -97,7 +97,7 @@ class LocalFunction {
97
97
  return new error_1.default('Invalid input');
98
98
  }
99
99
  return (() => __awaiter(this, void 0, void 0, function* () {
100
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
100
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
101
101
  const projectRoot = runtime_store_1.default.get('project.root');
102
102
  const accessToken = yield credential_1.default.getAccessToken();
103
103
  const slaveOptions = [];
@@ -105,9 +105,9 @@ class LocalFunction {
105
105
  yield fs_1.ASYNC.ensureFile(this.responseFile, true);
106
106
  yield fs_1.ASYNC.ensureFile(this.metaFile, true);
107
107
  if (this.target.type === constants_1.FN_TYPE.job) {
108
- const jobDetails = data;
108
+ const jobData = data;
109
109
  const jobMetaDetails = {
110
- headers: Object.assign(Object.assign({}, (_a = jobDetails.job_meta_details) === null || _a === void 0 ? void 0 : _a.headers), {
110
+ headers: Object.assign(Object.assign({}, (_b = (_a = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _a === void 0 ? void 0 : _a.job_meta_details) === null || _b === void 0 ? void 0 : _b.headers), {
111
111
  'x-zc-projectid': (0, project_1.getProjectId)(),
112
112
  'x-zc-project-domain': (0, project_1.getDomainPrefix)() + '.' + constants_1.ORIGIN.app.replace('https://', ''),
113
113
  'x-zc-project-key': (0, project_1.getDomainKey)(),
@@ -118,8 +118,8 @@ class LocalFunction {
118
118
  'x-zc-admin-cred-token': accessToken,
119
119
  'x-zc-user-type': 'admin'
120
120
  }),
121
- params: ((_b = jobDetails.job_meta_details) === null || _b === void 0 ? void 0 : _b.params) || {},
122
- jobpool_details: ((_c = jobDetails.job_meta_details) === null || _c === void 0 ? void 0 : _c.jobpool_details) || {
121
+ params: ((_d = (_c = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _c === void 0 ? void 0 : _c.job_meta_details) === null || _d === void 0 ? void 0 : _d.params) || {},
122
+ jobpool_details: ((_f = (_e = jobData === null || jobData === void 0 ? void 0 : jobData.job_details) === null || _e === void 0 ? void 0 : _e.job_meta_details) === null || _f === void 0 ? void 0 : _f.jobpool_details) || {
123
123
  type: 'Function',
124
124
  project_details: {
125
125
  project_name: (0, project_1.getProjectName)(),
@@ -127,14 +127,14 @@ class LocalFunction {
127
127
  }
128
128
  }
129
129
  };
130
- jobDetails.job_meta_details = jobMetaDetails;
131
- jobDetails.capacity = jobDetails.capacity || {
130
+ jobData.job_details = Object.assign(Object.assign({}, jobData.job_details), { job_meta_details: jobMetaDetails });
131
+ jobData.capacity = jobData.capacity || {
132
132
  memory: '256'
133
133
  };
134
- data = jobDetails;
134
+ data = jobData;
135
135
  }
136
136
  const slaveFnTarget = { index: this.target.index, name: this.target.name };
137
- if ((_d = this.target.stack) === null || _d === void 0 ? void 0 : _d.startsWith(runtime_1.default.language.node.value)) {
137
+ if ((_g = this.target.stack) === null || _g === void 0 ? void 0 : _g.startsWith(runtime_1.default.language.node.value)) {
138
138
  if (debugPort !== null) {
139
139
  slaveOptions.push('--inspect-brk=' + debugPort);
140
140
  }
@@ -158,10 +158,10 @@ class LocalFunction {
158
158
  this.slave = (0, shell_1.spawn)('node', slaveOptions, {
159
159
  cwd: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name),
160
160
  stdio: 'pipe',
161
- env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_e = this.target) === null || _e === void 0 ? void 0 : _e.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, this.target.env_var)
161
+ env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_h = this.target) === null || _h === void 0 ? void 0 : _h.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, this.target.env_var)
162
162
  }).RAW();
163
163
  }
164
- else if ((_f = this.target.stack) === null || _f === void 0 ? void 0 : _f.startsWith(runtime_1.default.language.java.value)) {
164
+ else if ((_j = this.target.stack) === null || _j === void 0 ? void 0 : _j.startsWith(runtime_1.default.language.java.value)) {
165
165
  const javaInvokerDir = (0, path_1.parse)(this.javaInvoker).dir;
166
166
  slaveOptions.push('-cp');
167
167
  slaveOptions.push(javaInvokerDir +
@@ -196,11 +196,11 @@ class LocalFunction {
196
196
  this.slave = (0, shell_1.spawn)(spawnCommand, slaveOptions, {
197
197
  cwd: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name),
198
198
  stdio: 'pipe',
199
- env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_g = this.target) === null || _g === void 0 ? void 0 : _g.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, this.target.env_var)
199
+ env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_k = this.target) === null || _k === void 0 ? void 0 : _k.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, this.target.env_var)
200
200
  }).RAW();
201
201
  }
202
- else if ((_h = this.target.stack) === null || _h === void 0 ? void 0 : _h.startsWith(runtime_1.default.language.python.value)) {
203
- const stackVersion = (_j = this.target.stack) === null || _j === void 0 ? void 0 : _j.replace('python_', '');
202
+ else if ((_l = this.target.stack) === null || _l === void 0 ? void 0 : _l.startsWith(runtime_1.default.language.python.value)) {
203
+ const stackVersion = (_m = this.target.stack) === null || _m === void 0 ? void 0 : _m.replace('python_', '');
204
204
  const runtimesDir = constants_1.ENVPATH.runtimes.data;
205
205
  const httpPort = parseInt(runtime_store_1.default.get('context.port.http.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic]), 10);
206
206
  const runTimePort = yield port_resolver_1.default.getFreePort(httpPort, 20, false);
@@ -211,10 +211,10 @@ class LocalFunction {
211
211
  this.slave = (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), slaveOptions, {
212
212
  cwd: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name),
213
213
  stdio: 'pipe',
214
- env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_k = this.target) === null || _k === void 0 ? void 0 : _k.id, X_ZOHO_CATALYST_CODE_LOCATION: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name), X_ZOHO_CATALYST_SERVER_LISTEN_PORT: runTimePort.toString(), X_ZOHO_DATA_URL: `http://localhost:${runTimePort}/data`, X_ZOHO_CALLBACK_URL: `http://localhost:${runTimePort}/callback`, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone), X_ZOHO_ADMIN_CRED_TOKEN: 'dummy', X_ZOHO_PROJECT_SECRET_KEY: 'dummy', X_ZOHO_CATALYST_ORG: (0, project_1.getEnvId)(), X_ZOHO_CATALYST_ENVIRONMENT: 'Local', X_ZOHO_JOBMETA_JOBID: 'dummy', CATALYST_FUNCTION_TYPE: constants_1.REMOTE_REF.functions.type[this.target.type] }, this.target.env_var)
214
+ env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_o = this.target) === null || _o === void 0 ? void 0 : _o.id, X_ZOHO_CATALYST_CODE_LOCATION: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name), X_ZOHO_CATALYST_SERVER_LISTEN_PORT: runTimePort.toString(), X_ZOHO_DATA_URL: `http://localhost:${runTimePort}/data`, X_ZOHO_CALLBACK_URL: `http://localhost:${runTimePort}/callback`, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone), X_ZOHO_ADMIN_CRED_TOKEN: 'dummy', X_ZOHO_PROJECT_SECRET_KEY: 'dummy', X_ZOHO_CATALYST_ORG: (0, project_1.getEnvId)(), X_ZOHO_CATALYST_ENVIRONMENT: 'Local', X_ZOHO_JOBMETA_JOBID: 'dummy', CATALYST_FUNCTION_TYPE: constants_1.REMOTE_REF.functions.type[this.target.type] }, this.target.env_var)
215
215
  }).RAW();
216
216
  this.slave.once('spawn', () => __awaiter(this, void 0, void 0, function* () {
217
- var _o;
217
+ var _r;
218
218
  const jsonData = data;
219
219
  jsonData.timestamp = Date.now();
220
220
  const writeResponse = (response, status) => {
@@ -223,15 +223,15 @@ class LocalFunction {
223
223
  };
224
224
  if (this.target.type === constants_1.FN_TYPE.job) {
225
225
  const jobDetailsServer = new http_1.Server((serverReq, serverRes) => __awaiter(this, void 0, void 0, function* () {
226
- var _p, _q, _r;
227
- if ((_p = serverReq.url) === null || _p === void 0 ? void 0 : _p.includes('data')) {
226
+ var _s, _t, _u;
227
+ if ((_s = serverReq.url) === null || _s === void 0 ? void 0 : _s.includes('data')) {
228
228
  serverRes.writeHead(200);
229
229
  serverRes.write(JSON.stringify({
230
230
  data: jsonData
231
231
  }));
232
232
  serverRes.end();
233
233
  }
234
- else if ((_q = serverReq.url) === null || _q === void 0 ? void 0 : _q.includes('callback')) {
234
+ else if ((_t = serverReq.url) === null || _t === void 0 ? void 0 : _t.includes('callback')) {
235
235
  const reqData = yield new Promise((resolve) => {
236
236
  const data = [];
237
237
  serverReq.on('data', (chunk) => data.push(chunk));
@@ -262,7 +262,7 @@ class LocalFunction {
262
262
  else {
263
263
  (0, logger_1.debug)(`Invalid request: (${serverReq.method}) ${serverReq.url}`);
264
264
  writeResponse('INTERNAL_SERVER_ERROR', 500);
265
- (_r = this.slave) === null || _r === void 0 ? void 0 : _r.kill('SIGINT');
265
+ (_u = this.slave) === null || _u === void 0 ? void 0 : _u.kill('SIGINT');
266
266
  return;
267
267
  }
268
268
  }));
@@ -270,7 +270,7 @@ class LocalFunction {
270
270
  jobDetailsServer.listen(runTimePort, () => {
271
271
  (0, logger_1.debug)('server listening on port :' + runTimePort);
272
272
  });
273
- (_o = this.slave) === null || _o === void 0 ? void 0 : _o.once('exit', () => {
273
+ (_r = this.slave) === null || _r === void 0 ? void 0 : _r.once('exit', () => {
274
274
  jobConnDestroyer.destroy();
275
275
  });
276
276
  return;
@@ -347,11 +347,11 @@ class LocalFunction {
347
347
  exit: 2
348
348
  });
349
349
  }
350
- (_l = this.slave.stdout) === null || _l === void 0 ? void 0 : _l.on('data', (message) => {
350
+ (_p = this.slave.stdout) === null || _p === void 0 ? void 0 : _p.on('data', (message) => {
351
351
  (0, shell_1.clearLine)(process.stdout);
352
352
  (0, logger_1.info)(message.toString());
353
353
  });
354
- (_m = this.slave.stderr) === null || _m === void 0 ? void 0 : _m.on('data', (message) => {
354
+ (_q = this.slave.stderr) === null || _q === void 0 ? void 0 : _q.on('data', (message) => {
355
355
  const errorStr = js_1.JS.trim(message.toString());
356
356
  (0, shell_1.clearLine)(process.stdout);
357
357
  (0, logger_1.info)(errorStr);
@@ -379,6 +379,7 @@ class LocalFunction {
379
379
  });
380
380
  break;
381
381
  case constants_1.FN_TYPE.cron:
382
+ case constants_1.FN_TYPE.job:
382
383
  case constants_1.FN_TYPE.event:
383
384
  (0, logger_1.info)(`[status - ${this.target.name}] ${response || 'Unknown'}`);
384
385
  if (!response) {
@@ -33,6 +33,7 @@ const server_1 = require("../../util_modules/server");
33
33
  const ansi_colors_1 = require("ansi-colors");
34
34
  const util_1 = require("util");
35
35
  const project_1 = require("../../util_modules/project");
36
+ const endpoints_1 = require("../../endpoints");
36
37
  class TunnelServer {
37
38
  constructor(repel) {
38
39
  _TunnelServer_contextMap.set(this, {});
@@ -42,6 +43,29 @@ class TunnelServer {
42
43
  _TunnelServer_projectId.set(this, (0, project_1.getProjectId)());
43
44
  __classPrivateFieldSet(this, _TunnelServer_repel, repel, "f");
44
45
  }
46
+ isAsyncFn(fnType) {
47
+ switch (fnType) {
48
+ case 'cron':
49
+ case 'event':
50
+ case 'job': {
51
+ return true;
52
+ }
53
+ }
54
+ return false;
55
+ }
56
+ send(req, res, status = 200, data, contentType) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const body = req.body;
59
+ if (this.isAsyncFn(body.function_details.function_type)) {
60
+ const tunnelAPI = yield (0, endpoints_1.tunnelAPI)();
61
+ yield tunnelAPI.tunnelCallback(status, body.default, data);
62
+ return;
63
+ }
64
+ contentType && res.contentType(contentType);
65
+ res.status(status);
66
+ res.send(data);
67
+ });
68
+ }
45
69
  startServer() {
46
70
  return __awaiter(this, void 0, void 0, function* () {
47
71
  const tunnelPortOpt = Number.parseInt(runtime_store_1.default.get('context.port.tunnel'));
@@ -59,23 +83,33 @@ class TunnelServer {
59
83
  const app = (0, express_1.default)();
60
84
  app.use(express_1.default.json());
61
85
  app.all('/', (req, res) => __awaiter(this, void 0, void 0, function* () {
86
+ if (req.method !== 'POST') {
87
+ res.status(200);
88
+ res.send();
89
+ return;
90
+ }
91
+ const body = req.body;
92
+ if (!body.function_details ||
93
+ !body.function_data ||
94
+ (body.function_details.function_type !== 'integration' && !body.default)) {
95
+ res.status(400);
96
+ res.send();
97
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
98
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write('Invalid tunnel request: ' + (0, util_1.inspect)(body));
99
+ return;
100
+ }
101
+ if (this.isAsyncFn(body.function_details.function_type)) {
102
+ res.status(200);
103
+ res.send();
104
+ }
62
105
  try {
63
- const body = req.body;
64
- if (!body.function_details || !body.function_data) {
65
- res.status(400);
66
- res.send();
67
- __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
68
- __classPrivateFieldGet(this, _TunnelServer_repel, "f").write('Invalid tunnel request: ' + (0, util_1.inspect)(body));
69
- return;
70
- }
71
106
  __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
72
107
  __classPrivateFieldGet(this, _TunnelServer_repel, "f").write((0, ansi_colors_1.bold)(`Received tunnel request from ${body.function_details.function_name}(${body.function_details.function_id})`));
73
108
  const target = body.function_details.function_id in __classPrivateFieldGet(this, _TunnelServer_contextMap, "f")
74
109
  ? __classPrivateFieldGet(this, _TunnelServer_contextMap, "f")[body.function_details.function_id]
75
- : (() => {
110
+ : yield (() => __awaiter(this, void 0, void 0, function* () {
76
111
  if (__classPrivateFieldGet(this, _TunnelServer_projectId, "f") !== body.function_details.project_id) {
77
- res.status(403);
78
- res.send();
112
+ yield this.send(req, res, 403);
79
113
  __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
80
114
  __classPrivateFieldGet(this, _TunnelServer_repel, "f").write('Invalid access: the tunnel is trying to access the functions from a different project');
81
115
  __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
@@ -87,15 +121,14 @@ class TunnelServer {
87
121
  if (namedFn) {
88
122
  return namedFn;
89
123
  }
90
- res.status(404);
91
- res.send();
124
+ yield this.send(req, res, 404);
92
125
  __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
93
126
  __classPrivateFieldGet(this, _TunnelServer_repel, "f").write(`The tunneled function ${(0, ansi_colors_1.bold)(body.function_details.function_name)} is not present in local project directory`);
94
127
  __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
95
128
  __classPrivateFieldGet(this, _TunnelServer_repel, "f").write('[STATUS]');
96
129
  __classPrivateFieldGet(this, _TunnelServer_repel, "f").write('NOT_FOUND');
97
130
  return;
98
- }).bind(this)();
131
+ })).bind(this)();
99
132
  if (!target) {
100
133
  return;
101
134
  }
@@ -103,11 +136,10 @@ class TunnelServer {
103
136
  ? JSON.parse(body.function_data)
104
137
  : body.function_data;
105
138
  target.call(false)(fnData);
106
- const errorHandler = (e) => {
107
- res.status(500);
108
- res.send();
139
+ const errorHandler = (e) => __awaiter(this, void 0, void 0, function* () {
140
+ yield this.send(req, res, 500);
109
141
  (0, logger_1.debug)('Target error: ' + e);
110
- };
142
+ });
111
143
  target.once('error', errorHandler);
112
144
  const response = yield new Promise((resolve, reject) => {
113
145
  target.once('response', (response) => {
@@ -118,13 +150,10 @@ class TunnelServer {
118
150
  resolve(response);
119
151
  });
120
152
  });
121
- response.ContentType && res.setHeader('Content-Type', response.ContentType);
122
- res.status(response.status || 200);
123
- res.send(response.responseBody);
153
+ yield this.send(req, res, response.status, response.responseBody, response.ContentType);
124
154
  }
125
155
  catch (e) {
126
- res.status(500);
127
- res.send();
156
+ yield this.send(req, res, 500);
128
157
  (0, logger_1.debug)(e);
129
158
  }
130
159
  }));
@@ -49,35 +49,29 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
49
49
  const httpServer = new http_functions_1.default({ repl: replServer });
50
50
  const tunnelServer = new tunnel_server_1.default(replServer);
51
51
  const projectRoot = runtime_store_1.default.get('project.root');
52
- try {
53
- yield (0, prepare_1.default)([
54
- constants_1.FN_TYPE.basic,
55
- constants_1.FN_TYPE.cron,
56
- constants_1.FN_TYPE.event,
57
- constants_1.FN_TYPE.integration,
58
- constants_1.FN_TYPE.job
59
- ]);
60
- const targets = runtime_store_1.default
61
- .get('context.functions.targets', [])
62
- .filter((target) => {
63
- if (!target.valid) {
64
- (0, logger_js_1.warning)('target [' +
65
- target.name +
66
- '] is not a valid one reason : ' +
67
- target.failure_reason);
68
- Array.isArray(target.compilationError) &&
69
- target.compilationError.forEach((er) => (0, logger_js_1.error)(er));
70
- Array.isArray(target.compilationWarning) &&
71
- target.compilationWarning.forEach((warn) => (0, logger_js_1.warning)(warn));
72
- }
73
- return target.valid;
74
- });
75
- if (targets.length === 0) {
76
- throw new error_1.default('No functions are ready for serving', {
77
- exit: 0,
78
- errorId: 'SHELL-IDX-1'
79
- });
52
+ yield (0, prepare_1.default)([constants_1.FN_TYPE.basic, constants_1.FN_TYPE.cron, constants_1.FN_TYPE.event, constants_1.FN_TYPE.integration, constants_1.FN_TYPE.job]);
53
+ const targets = runtime_store_1.default
54
+ .get('context.functions.targets', [])
55
+ .filter((target) => {
56
+ if (!target.valid) {
57
+ (0, logger_js_1.warning)('target [' +
58
+ target.name +
59
+ '] is not a valid one reason : ' +
60
+ target.failure_reason);
61
+ Array.isArray(target.compilationError) &&
62
+ target.compilationError.forEach((er) => (0, logger_js_1.error)(er));
63
+ Array.isArray(target.compilationWarning) &&
64
+ target.compilationWarning.forEach((warn) => (0, logger_js_1.warning)(warn));
80
65
  }
66
+ return target.valid;
67
+ });
68
+ if (targets.length === 0) {
69
+ throw new error_1.default('No functions are ready for serving', {
70
+ exit: 0,
71
+ errorId: 'SHELL-IDX-1'
72
+ });
73
+ }
74
+ try {
81
75
  replServer.start();
82
76
  yield tunnelServer.startServer();
83
77
  const tunnelUrl = runtime_store_1.default.get('context.fn_shell.enable_tunnel', undefined);
@@ -26,6 +26,8 @@ function validateConfig(source, configJson) {
26
26
  reason: 'Config file is empty'
27
27
  };
28
28
  }
29
+ const sourcePath = (0, path_1.join)((0, project_1.getProjectRoot)(), source);
30
+ configJson.raw.source_path = sourcePath;
29
31
  if (configJson.buildPath || configJson.build_path) {
30
32
  const buildPath = configJson.build_path || configJson.buildPath;
31
33
  if (!buildPath) {
@@ -34,8 +36,9 @@ function validateConfig(source, configJson) {
34
36
  reason: 'Build Path not present'
35
37
  };
36
38
  }
37
- const absolutePath = (0, path_1.isAbsolute)(buildPath) ? buildPath : (0, path_1.resolve)(source, buildPath);
39
+ const absolutePath = (0, path_1.isAbsolute)(buildPath) ? buildPath : (0, path_1.resolve)(sourcePath, buildPath);
38
40
  configJson.build_path = absolutePath;
41
+ configJson.raw.build_path = buildPath;
39
42
  }
40
43
  if (configJson.catalyst_auth === true) {
41
44
  if (configJson.login_redirect === undefined) {
@@ -121,6 +124,7 @@ function getAllTargetDetails(throwErr = true) {
121
124
  resArr.push(new Promise((res) => __awaiter(this, void 0, void 0, function* () {
122
125
  try {
123
126
  const configJson = yield fs_1.ASYNC.readJSONFile(catalystConfigPth);
127
+ configJson && (configJson.raw = {});
124
128
  const validity = validateConfig(target.source, configJson);
125
129
  return res(Object.assign({ config: configJson, validity }, target));
126
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcatalyst-cli",
3
- "version": "1.18.0-beta.2",
3
+ "version": "1.18.0-beta.3",
4
4
  "description": "Command Line Tool for CATALYST",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {