zcatalyst-cli 1.18.0-beta.0 → 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 (129) hide show
  1. package/docs/command_needs/rc.toml +8 -8
  2. package/docs/commands/event/generate/job.toml +7 -0
  3. package/docs/endpoints/lib/job-scheduling.toml +3 -0
  4. package/docs/internal/command.toml +5 -0
  5. package/lib/appsail-utils.js +4 -10
  6. package/lib/authentication/index.js +1 -0
  7. package/lib/bin/catalyst.js +1 -1
  8. package/lib/command_needs/rc.js +8 -8
  9. package/lib/commands/appsail/add.js +2 -1
  10. package/lib/commands/client/setup.js +2 -1
  11. package/lib/commands/codelib/install.js +5 -2
  12. package/lib/commands/event/generate/index.js +2 -1
  13. package/lib/commands/event/generate/integ.js +2 -1
  14. package/lib/commands/event/generate/job.js +82 -0
  15. package/lib/commands/functions/add.js +2 -1
  16. package/lib/commands/functions/delete.js +2 -4
  17. package/lib/commands/functions/setup.js +2 -1
  18. package/lib/commands/functions/shell.js +1 -0
  19. package/lib/commands/index.js +3 -1
  20. package/lib/commands/init.js +10 -7
  21. package/lib/commands/login.js +1 -0
  22. package/lib/commands/logout.js +1 -0
  23. package/lib/commands/pull.js +1 -0
  24. package/lib/commands/serve.js +1 -1
  25. package/lib/commands/whoami.js +1 -0
  26. package/lib/deploy/features/appsail/index.js +42 -25
  27. package/lib/deploy/features/appsail/utils.js +4 -5
  28. package/lib/endpoints/index.js +10 -3
  29. package/lib/endpoints/lib/appsail.js +7 -1
  30. package/lib/endpoints/lib/job-scheduling.js +61 -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 +36 -26
  38. package/lib/init/features/client/index.js +2 -1
  39. package/lib/init/features/functions/index.js +4 -0
  40. package/lib/init/features/functions/languages/python.js +21 -5
  41. package/lib/init/features/project.js +5 -15
  42. package/lib/internal/api.js +25 -6
  43. package/lib/internal/command.js +30 -6
  44. package/lib/migration/index.js +4 -2
  45. package/lib/optional-import.js +3 -2
  46. package/lib/prompt/types/file-path.js +1 -1
  47. package/lib/prompt/types/tree.js +3 -3
  48. package/lib/serve/features/appsail.js +2 -3
  49. package/lib/serve/index.js +1 -2
  50. package/lib/serve/server/index.js +8 -9
  51. package/lib/serve/server/lib/appsail/index.js +29 -35
  52. package/lib/serve/server/lib/java/aio_server/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  53. package/lib/serve/server/lib/java/aio_server/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  54. package/lib/serve/server/lib/java/aio_server/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  55. package/lib/serve/server/lib/java/index.js +2 -2
  56. package/lib/serve/server/lib/master/appsail.js +53 -0
  57. package/lib/serve/server/lib/master/functions.js +34 -0
  58. package/lib/serve/server/lib/master/index.js +155 -0
  59. package/lib/{express_middlewares/unknownReqProxy.js → serve/server/lib/master/unknown-req-proxy.js} +4 -7
  60. package/lib/serve/server/lib/master/utils.js +130 -0
  61. package/lib/serve/server/lib/master/web-client.js +39 -0
  62. package/lib/serve/server/lib/node/index.js +3 -3
  63. package/lib/serve/server/lib/python/index.js +3 -3
  64. package/lib/shell/dependencies/invoker/bio/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  65. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  66. package/lib/shell/dependencies/invoker/cron/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  67. package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +2 -1
  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 +1 -0
  70. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +14 -0
  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 +13 -0
  73. package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +268 -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 +121 -13
  78. package/lib/shell/index.js +7 -1
  79. package/lib/shell/prepare/languages/index.js +4 -4
  80. package/lib/shell/prepare/languages/java.js +1 -2
  81. package/lib/shell/prepare/languages/python.js +10 -16
  82. package/lib/throbber/index.js +6 -1
  83. package/lib/userConfig.js +7 -1
  84. package/lib/util_modules/config/index.js +1 -1
  85. package/lib/util_modules/config/lib/{appSail.js → appsail.js} +60 -10
  86. package/lib/util_modules/config/lib/client.js +6 -8
  87. package/lib/util_modules/config/lib/functions.js +6 -8
  88. package/lib/util_modules/constants/lib/default.js +9 -9
  89. package/lib/util_modules/constants/lib/fn-type.js +2 -1
  90. package/lib/util_modules/constants/lib/needed-scopes.js +53 -44
  91. package/lib/util_modules/constants/lib/placeholders.js +6 -0
  92. package/lib/util_modules/constants/lib/ref-mapping.js +2 -1
  93. package/lib/util_modules/constants/lib/remote-mapping.js +2 -1
  94. package/lib/util_modules/constants/lib/scopes.js +5 -1
  95. package/lib/util_modules/constants/lib/template.js +9 -4
  96. package/lib/util_modules/constants/lib/urls.js +8 -0
  97. package/lib/util_modules/fs/lib/async.js +14 -4
  98. package/lib/util_modules/fs/lib/sync.js +12 -1
  99. package/lib/util_modules/server.js +2 -4
  100. package/lib/winston.js +17 -11
  101. package/package.json +1 -1
  102. package/templates/event/job.json +30 -0
  103. package/templates/init/functions/java/job/.classpath +6 -0
  104. package/templates/init/functions/java/job/.project +17 -0
  105. package/templates/init/functions/java/job/catalyst-config.json +11 -0
  106. package/templates/init/functions/java/job/sample.java +34 -0
  107. package/templates/init/functions/node/aio/package.json +1 -1
  108. package/templates/init/functions/node/aio/sample.js +7 -0
  109. package/templates/init/functions/node/bio/package.json +1 -1
  110. package/templates/init/functions/node/bio/sample.js +5 -0
  111. package/templates/init/functions/node/bio/types/basicio.d.ts +57 -0
  112. package/templates/init/functions/node/cron/package.json +1 -1
  113. package/templates/init/functions/node/cron/sample.js +5 -0
  114. package/templates/init/functions/node/cron/types/cron.d.ts +64 -0
  115. package/templates/init/functions/node/event/package.json +1 -1
  116. package/templates/init/functions/node/event/sample.js +11 -8
  117. package/templates/init/functions/node/event/types/event.d.ts +82 -0
  118. package/templates/init/functions/node/integ/cliq/package.json +1 -1
  119. package/templates/init/functions/node/integ/convokraft/package.json +1 -1
  120. package/templates/init/functions/node/{stream → job}/catalyst-config.json +3 -2
  121. package/templates/init/functions/node/{stream → job}/package.json +1 -1
  122. package/templates/init/functions/node/job/sample.js +27 -0
  123. package/templates/init/functions/node/job/types/job.d.ts +62 -0
  124. package/templates/init/functions/python/job/catalyst-config.json +11 -0
  125. package/templates/init/functions/python/job/requirements.txt +1 -0
  126. package/templates/init/functions/python/job/sample.py +22 -0
  127. package/templates/init.txt +13 -0
  128. package/lib/serve/server/lib/master.js +0 -326
  129. package/templates/init/functions/node/stream/sample.js +0 -15
@@ -47,15 +47,19 @@ 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',
54
54
  json: true,
55
55
  headers
56
56
  };
57
+ const projectSecretKey = process.env.CATALYST_PROJECT_SECRET_KEY;
57
58
  if (!isExternal) {
58
59
  this.requestOpts.headers = Object.assign(Object.assign({}, this.requestOpts.headers), { Accept: 'application/vnd.catalyst.v2+json', 'X-CATALYST-Environment': env });
60
+ if (projectSecretKey) {
61
+ this.requestOpts.headers['X-ZC-PROJECT-SECRET-KEY'] = projectSecretKey;
62
+ }
59
63
  if (envId) {
60
64
  this.requestOpts.headers['CATALYST-ORG'] = envId;
61
65
  }
@@ -69,6 +73,7 @@ class API {
69
73
  this.maxRetryCount = maxRetry;
70
74
  this.retryCount = 0;
71
75
  this.showWarning = showWarning;
76
+ this.printError = printError;
72
77
  }
73
78
  _logReq() {
74
79
  let qs = this.requestOpts.qs
@@ -92,17 +97,26 @@ class API {
92
97
  '\n');
93
98
  }
94
99
  _logResp(resp) {
100
+ const ignoreHeaders = [
101
+ 'content-security-policy-report-only',
102
+ 'set-cookie',
103
+ 'content-security-policy'
104
+ ];
105
+ const logHeaders = Object.assign({}, resp.headers);
106
+ ignoreHeaders.forEach((header) => delete logHeaders[header]);
95
107
  (0, logger_1.debug)('<<<< HTTP RESPONSE : ' +
96
108
  resp.statusCode +
97
109
  '\n' +
98
110
  'Response Headers: ' +
99
- JSON.stringify(resp.headers) +
111
+ JSON.stringify(logHeaders) +
100
112
  '\n');
101
113
  if (!js_1.JS.isUndefined(resp.timings)) {
102
114
  (0, logger_1.debug)('TOTAL TIME TAKEN : ' + Number(resp.timings.end.toFixed(3)) + ' ms\n');
103
115
  (0, logger_1.debug)('REQUEST PHASES : ' + resp.timingPhases);
104
116
  }
105
- if (this.logOpts.progress !== undefined) {
117
+ if (resp.statusCode >= 200 &&
118
+ resp.statusCode < 300 &&
119
+ this.logOpts.progress !== undefined) {
106
120
  js_1.JS.set(this.logOpts, 'progress.total', resp.headers['content-length']);
107
121
  this.downloadProgress = new progress_1.default(this.logOpts.progress);
108
122
  }
@@ -142,11 +156,11 @@ class API {
142
156
  if (resp.statusCode >= 400 && !this.logOpts.skipRespBody) {
143
157
  (0, logger_1.debug)('Response Body : ' + JSON.stringify(resp.body) + '\n');
144
158
  if (!this.resolveOnHTTPError) {
145
- const errRes = (0, errorResponse_1.default)(resp, body);
159
+ const errRes = (0, errorResponse_1.default)(resp, body, !this.printError);
146
160
  this._logDownloadProgress({ error: errRes });
147
161
  throw errRes;
148
162
  }
149
- this._logDownloadProgress({ error: (0, errorResponse_1.default)(resp, body, true) });
163
+ this._logDownloadProgress({ error: (0, errorResponse_1.default)(resp, body, !this.printError) });
150
164
  }
151
165
  return {
152
166
  status: resp.statusCode,
@@ -177,6 +191,7 @@ class API {
177
191
  return new Promise((resolve, reject) => {
178
192
  const responseBuffer = [];
179
193
  let isJSONResponse = false;
194
+ let isErrorPage = false;
180
195
  const throbber = throbber_1.default.getInstance();
181
196
  if (this.logOpts.uploadProgress !== undefined &&
182
197
  this.logOpts.stream instanceof fs_1.ReadStream) {
@@ -219,6 +234,7 @@ class API {
219
234
  }))
220
235
  .on('response', (resp) => {
221
236
  isJSONResponse = js_1.JS.includes(resp.headers['content-type'], 'json');
237
+ isErrorPage = !(resp.statusCode >= 200 && resp.statusCode < 300);
222
238
  this._logResp(resp);
223
239
  })
224
240
  .on('complete', (resp, body) => __awaiter(this, void 0, void 0, function* () {
@@ -233,7 +249,9 @@ class API {
233
249
  if (isJSONResponse) {
234
250
  responseBuffer.push(data);
235
251
  }
236
- this._logDownloadProgress({ chunk: data });
252
+ if (!isErrorPage) {
253
+ this._logDownloadProgress({ chunk: data });
254
+ }
237
255
  });
238
256
  });
239
257
  });
@@ -241,6 +259,7 @@ class API {
241
259
  fire(method, path, options) {
242
260
  return __awaiter(this, void 0, void 0, function* () {
243
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;
244
263
  this.maxRetryCount = js_1.JS.get(options, 'maxRetry', this.maxRetryCount);
245
264
  this.authNeeded = js_1.JS.get(options, 'authNeeded', this.authNeeded);
246
265
  this.logOpts = js_1.JS.get(options, 'log', this.logOpts);
@@ -46,9 +46,12 @@ const js_1 = require("../util_modules/js");
46
46
  const logger_1 = require("../util_modules/logger");
47
47
  const option_1 = require("../util_modules/option");
48
48
  const project_1 = require("../util_modules/project");
49
+ const env_1 = require("../util_modules/env");
49
50
  class Command {
50
51
  constructor(cmd) {
52
+ this.subCommand = [];
51
53
  this.isSubCommand = false;
54
+ this.isCICommand = true;
52
55
  this.command = cmd;
53
56
  this.cmdName = cmd.split(' ')[0];
54
57
  this.aliasName = null;
@@ -88,9 +91,15 @@ class Command {
88
91
  this.helpText = text;
89
92
  return this;
90
93
  }
91
- addSubCommand(command) {
92
- this.subCommand = command;
93
- command.isSubCommand = true;
94
+ addSubCommand(...commands) {
95
+ commands.forEach((command) => {
96
+ this.subCommand.push(command);
97
+ command.isSubCommand = true;
98
+ });
99
+ return this;
100
+ }
101
+ ci(value) {
102
+ this.isCICommand = value;
94
103
  return this;
95
104
  }
96
105
  helpConfig(config) {
@@ -110,9 +119,14 @@ class Command {
110
119
  return this;
111
120
  }
112
121
  register(client, cli) {
122
+ var _a;
113
123
  this.client = client;
114
124
  const program = cli || client.cli;
115
- const cmd = program.command(this.command);
125
+ let opts = {};
126
+ if (env_1.isCI && !this.isCICommand) {
127
+ opts = { hidden: true };
128
+ }
129
+ const cmd = program.command(this.command, opts);
116
130
  if (this.aliasName !== null) {
117
131
  cmd.alias(this.aliasName);
118
132
  }
@@ -140,6 +154,13 @@ class Command {
140
154
  const runner = this.runner();
141
155
  const start = Date.now();
142
156
  const argCount = cmd._args.length;
157
+ if (!this.isCICommand && env_1.isCI) {
158
+ return (0, errorOut_1.default)(new error_1.default('Environment not supported', {
159
+ exit: 1,
160
+ errorId: 'CMD-2',
161
+ arg: [(0, ansi_colors_1.bold)(cmd.name()), (0, ansi_colors_1.bold)('CI=true catalyst help')]
162
+ }));
163
+ }
143
164
  if (programArgs.slice(-1)[0].args.length > argCount &&
144
165
  !this.allowUnknownOptions) {
145
166
  return (0, errorOut_1.default)(new error_1.default('Too many arguments', {
@@ -163,7 +184,9 @@ class Command {
163
184
  }
164
185
  }));
165
186
  if (this.subCommand) {
166
- this.subCommand.register(client, cmd);
187
+ (_a = this.subCommand) === null || _a === void 0 ? void 0 : _a.forEach((subCmd) => {
188
+ subCmd.register(client, cmd);
189
+ });
167
190
  }
168
191
  return cmd;
169
192
  }
@@ -206,7 +229,8 @@ class Command {
206
229
  (0, logger_1.debug)(e);
207
230
  }
208
231
  yield Promise.all(js_1.JS.map(this.beforeRunners, (before) => __awaiter(this, void 0, void 0, function* () {
209
- const beforeModule = (yield Promise.resolve().then(() => __importStar(require('../command_needs/' + before.fn)))).default;
232
+ var _a;
233
+ const beforeModule = (yield (_a = '../command_needs/' + before.fn, Promise.resolve().then(() => __importStar(require(_a))))).default;
210
234
  return beforeModule.call(this, before.args);
211
235
  })));
212
236
  return this.cmdAction.call(this, ...args);
@@ -44,6 +44,7 @@ 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;
47
48
  if (migFiles.length <= idx) {
48
49
  return Promise.resolve();
49
50
  }
@@ -54,7 +55,7 @@ const runMigration = (rc, migFiles, idx = 0) => __awaiter(void 0, void 0, void 0
54
55
  return runMigration(rc, migFiles, ++idx);
55
56
  }
56
57
  try {
57
- const migModule = yield Promise.resolve().then(() => __importStar(require(migFile)));
58
+ const migModule = yield (_a = migFile, Promise.resolve().then(() => __importStar(require(_a))));
58
59
  if (migModule.isRequire()) {
59
60
  (0, logger_1.debug)('migration started for v' + currentMigFileVersion);
60
61
  migModule.migrate();
@@ -83,6 +84,7 @@ const runMigration = (rc, migFiles, idx = 0) => __awaiter(void 0, void 0, void 0
83
84
  return runMigration(rc, migFiles, ++idx);
84
85
  });
85
86
  const runGlobalMigration = (migFiles) => __awaiter(void 0, void 0, void 0, function* () {
87
+ var _b;
86
88
  if (migFiles.length === 0) {
87
89
  return;
88
90
  }
@@ -96,7 +98,7 @@ const runGlobalMigration = (migFiles) => __awaiter(void 0, void 0, void 0, funct
96
98
  return runGlobalMigration(migFiles);
97
99
  }
98
100
  try {
99
- const migModule = yield Promise.resolve().then(() => __importStar(require(migFile)));
101
+ const migModule = yield (_b = migFile, Promise.resolve().then(() => __importStar(require(_b))));
100
102
  if (migModule.isRequire()) {
101
103
  (0, logger_1.debug)('migration started for v' + currentMigFileVersion);
102
104
  migModule.migrate();
@@ -42,6 +42,7 @@ 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;
45
46
  if (name === (0, path_1.basename)(name)) {
46
47
  const projectModulePath = (0, project_js_1.resolveProjectPath)((0, path_1.join)(source, 'node_modules', name));
47
48
  const projectModulePathExists = yield (0, async_js_1.dirExists)(projectModulePath);
@@ -53,7 +54,7 @@ exports.default = (name, source) => __awaiter(void 0, void 0, void 0, function*
53
54
  });
54
55
  }
55
56
  app_module_path_1.default.addPath(projectModulePath);
56
- return Promise.resolve().then(() => __importStar(require(projectModulePath)));
57
+ return _a = projectModulePath, Promise.resolve().then(() => __importStar(require(_a)));
57
58
  }
58
59
  const projectModulePath = (0, project_js_1.resolveProjectPath)(name);
59
60
  const projectModulePathExists = yield (0, async_js_1.dirExists)(projectModulePath);
@@ -65,5 +66,5 @@ exports.default = (name, source) => __awaiter(void 0, void 0, void 0, function*
65
66
  });
66
67
  }
67
68
  app_module_path_1.default.addPath(projectModulePath);
68
- return Promise.resolve().then(() => __importStar(require(projectModulePath)));
69
+ return _b = projectModulePath, Promise.resolve().then(() => __importStar(require(_b)));
69
70
  });
@@ -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, {
@@ -26,6 +26,9 @@ 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
+ }
29
32
  constructor(root) {
30
33
  _TreeNode_instances.add(this);
31
34
  this.open = false;
@@ -36,9 +39,6 @@ class TreeNode {
36
39
  this.level = 1;
37
40
  this.root = root;
38
41
  }
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);
@@ -27,19 +27,18 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
27
27
  }
28
28
  const validated = (0, appsail_utils_1.validateAppSail)(optionTargets);
29
29
  const filledTargets = yield Promise.all(validated.map((targ) => __awaiter(void 0, void 0, void 0, function* () {
30
- var _a, _b;
31
30
  if (!targ.validity.valid) {
32
31
  return targ;
33
32
  }
34
33
  const proxyPort = yield port_resolver_1.default.getPort('appsail', 'http', {
35
- name: ((_a = targ.appSail) === null || _a === void 0 ? void 0 : _a.name) + '_proxy',
34
+ name: targ.name + '_proxy',
36
35
  searchSpan: 10,
37
36
  server: 'master'
38
37
  }).catch((err) => {
39
38
  throw new error_1.default('No free ports between 3000 and 3010. AppSail needs the ports within this range to function properly', { original: err });
40
39
  });
41
40
  const appsailPort = yield port_resolver_1.default.getPort('appsail', 'http', {
42
- name: ((_b = targ.appSail) === null || _b === void 0 ? void 0 : _b.name) + '_proxy',
41
+ name: targ.name + '_proxy',
43
42
  server: 'service'
44
43
  });
45
44
  return Object.assign(Object.assign({}, targ), { port: { appsail: appsailPort, proxy: proxyPort } });
@@ -108,10 +108,9 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
108
108
  if (serveTargets.includes('appsail')) {
109
109
  const appSail = runtime_store_1.default.get('context.appsail.targets', []);
110
110
  const validAppSail = appSail.filter((sail) => {
111
- var _a;
112
111
  if (!sail.validity.valid) {
113
112
  (0, logger_1.warning)('skipping serve of AppSail service [' +
114
- ((_a = sail.appSail) === null || _a === void 0 ? void 0 : _a.name) +
113
+ sail.name +
115
114
  '] since ' +
116
115
  sail.validity.reason);
117
116
  return false;
@@ -117,7 +117,7 @@ class Server {
117
117
  });
118
118
  }
119
119
  startServer(details, masterPort) {
120
- var _a, _b, _c;
120
+ var _a, _b;
121
121
  return __awaiter(this, void 0, void 0, function* () {
122
122
  if (details.target === undefined) {
123
123
  return details;
@@ -170,7 +170,7 @@ class Server {
170
170
  if (details.type === 'appsail') {
171
171
  const target = details.target;
172
172
  target.validity.valid = false;
173
- (0, logger_1.labeled)(`AppSail[${(_c = target.appSail) === null || _c === void 0 ? void 0 : _c.name}]`, error).ERROR();
173
+ (0, logger_1.labeled)(`AppSail[${target.name}]`, error).ERROR();
174
174
  }
175
175
  else if (details.type === 'client') {
176
176
  const target = details.target;
@@ -252,7 +252,7 @@ class Server {
252
252
  }
253
253
  this.masterServer =
254
254
  masterTargets.length > 0
255
- ? yield (0, master_1.default)(masterPort, masterTargets.targets)
255
+ ? yield (0, master_1.default)(masterPort, { otherServerDetails: masterTargets.targets })
256
256
  : undefined;
257
257
  startPromise = new Promise((res) => {
258
258
  this.masterServer
@@ -284,16 +284,16 @@ class Server {
284
284
  }
285
285
  if (this.targetsMap.appSail.length > 0) {
286
286
  yield Promise.all(this.targetsMap.appSail.map((targSail) => this.startServer(targSail, -1).then((details) => {
287
- var _a, _b, _c, _d, _e, _f;
287
+ var _a, _b, _c, _d;
288
288
  const serverDetails = details;
289
289
  if (!((_a = serverDetails.target) === null || _a === void 0 ? void 0 : _a.validity.valid)) {
290
290
  return;
291
291
  }
292
292
  logUrls.appsail.targs.push(targSail);
293
293
  logUrls.appsail.nameMaxLength =
294
- ((_c = (_b = targSail.target) === null || _b === void 0 ? void 0 : _b.appSail) === null || _c === void 0 ? void 0 : _c.name) &&
295
- ((_e = (_d = targSail.target) === null || _d === void 0 ? void 0 : _d.appSail) === null || _e === void 0 ? void 0 : _e.name.length) > logUrls.appsail.nameMaxLength
296
- ? (_f = targSail.target) === null || _f === void 0 ? void 0 : _f.appSail.name.length
294
+ ((_b = targSail.target) === null || _b === void 0 ? void 0 : _b.name) &&
295
+ ((_c = targSail.target) === null || _c === void 0 ? void 0 : _c.name.length) > logUrls.appsail.nameMaxLength
296
+ ? (_d = targSail.target) === null || _d === void 0 ? void 0 : _d.name.length
297
297
  : logUrls.appsail.nameMaxLength;
298
298
  })));
299
299
  }
@@ -370,9 +370,8 @@ class Server {
370
370
  (0, logger_1.info)();
371
371
  (0, logger_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>> AppSail <<<<<<<<<<<<<< '));
372
372
  _logTarg.targs.forEach((t) => {
373
- var _a;
374
373
  const targetSail = t.target;
375
- const targName = ((_a = targetSail.appSail) === null || _a === void 0 ? void 0 : _a.name) + '';
374
+ const targName = targetSail.name + '';
376
375
  (0, logger_1.labeled)(targName +
377
376
  ' '.repeat((_logTarg.nameMaxLength || targName.length) - targName.length), `http://localhost:${targetSail.port.proxy}`).MESSAGE();
378
377
  });
@@ -24,7 +24,6 @@ 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
27
  function executeHook(script, name, moduleSource) {
29
28
  if ((0, option_1.getOptionValue)('ignoreScripts', false)) {
30
29
  (0, logger_1.debug)(`skipping ${name} hook`);
@@ -41,53 +40,46 @@ const startAppSail = (port, opts) => {
41
40
  return (0, shell_1.spawn)('node', _opts, {
42
41
  cwd: opts.target,
43
42
  stdio: 'pipe',
44
- 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 || {}))
45
44
  }).RAW();
46
45
  };
47
46
  exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function* () {
48
47
  var _a, _b, _c, _d;
49
48
  let child;
50
49
  const targetSail = serverDetails.target;
51
- if (!targetSail || !targetSail.appSail) {
50
+ if (!targetSail || !targetSail.config) {
52
51
  throw new error_1.default('AppSail details not found');
53
52
  }
54
- if ((_a = targetSail.appSail.scripts) === null || _a === void 0 ? void 0 : _a.preserve) {
55
- executeHook(targetSail.appSail.scripts.preserve, `AppSail [PRESERVE] [${(_b = targetSail.appSail) === null || _b === void 0 ? void 0 : _b.name}]`, targetSail.appSail.source);
56
- }
57
- const buildPath = targetSail.appSail.buildPath
58
- ? targetSail.appSail.buildPath
59
- : (_c = targetSail.appSail) === null || _c === void 0 ? void 0 : _c.build_path;
60
- if (!(yield fs_1.ASYNC.isPathExists(buildPath))) {
61
- throw new error_1.default(`Build path does not exists [${buildPath}]`, {
62
- exit: 1,
63
- errorId: 'SERVE-APPSAIL-1',
64
- arg: [ansi_colors_1.italic.red(buildPath), (0, ansi_colors_1.bold)(targetSail.appSail.name)]
65
- });
53
+ if ((_a = targetSail.config.scripts) === null || _a === void 0 ? void 0 : _a.preserve) {
54
+ executeHook(targetSail.config.scripts.preserve, `AppSail [PRESERVE] [${targetSail.name}]`, targetSail.source);
66
55
  }
56
+ const buildPath = (_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.build_path;
67
57
  const target = (yield fs_1.ASYNC.fileExists(buildPath)) ? (0, path_1.dirname)(buildPath) : buildPath;
68
58
  switch (true) {
69
- case targetSail.appSail.stack.startsWith('node'): {
59
+ case targetSail.config.stack.startsWith('node'): {
70
60
  child = startAppSail(targetSail.port.appsail, {
71
61
  type: 'nodejs',
72
62
  target,
73
- command: targetSail.appSail.command,
74
- memory: targetSail.appSail.memory || 256,
75
- env: targetSail.appSail.env_variables
63
+ command: targetSail.config.command,
64
+ memory: targetSail.config.memory || 256,
65
+ env: targetSail.config.env_variables,
66
+ name: targetSail.name
76
67
  });
77
68
  break;
78
69
  }
79
- case targetSail.appSail.stack.startsWith('python'): {
70
+ case targetSail.config.stack.startsWith('python'): {
80
71
  child = startAppSail(targetSail.port.appsail, {
81
72
  type: 'python',
82
73
  target,
83
- command: targetSail.appSail.command,
84
- memory: targetSail.appSail.memory || 256,
85
- env: targetSail.appSail.env_variables
74
+ command: targetSail.config.command,
75
+ memory: targetSail.config.memory || 256,
76
+ env: targetSail.config.env_variables,
77
+ name: targetSail.name
86
78
  });
87
79
  break;
88
80
  }
89
- case targetSail.appSail.stack.startsWith('java'): {
90
- if (targetSail.appSail.platform === 'war') {
81
+ case targetSail.config.stack.startsWith('java'): {
82
+ if (targetSail.config.platform === 'war') {
91
83
  const jettyPath = (0, path_1.join)(constants_1.ENVPATH.runtimes.data, 'jetty');
92
84
  if (!(yield fs_1.ASYNC.fileExists((0, path_1.join)(jettyPath, 'start.jar')).catch((err) => (0, logger_1.debug)(err)))) {
93
85
  try {
@@ -112,17 +104,19 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
112
104
  target,
113
105
  type: 'war',
114
106
  command: jettyCommand,
115
- memory: targetSail.appSail.memory || 256,
116
- env: Object.assign({ JETTY_BASE: (0, path_1.join)(jettyPath, 'JETTY_BASE') }, targetSail.appSail.env_variables)
107
+ memory: targetSail.config.memory || 256,
108
+ env: Object.assign({ JETTY_BASE: (0, path_1.join)(jettyPath, 'JETTY_BASE') }, targetSail.config.env_variables),
109
+ name: targetSail.name
117
110
  });
118
111
  break;
119
112
  }
120
113
  child = startAppSail(targetSail.port.appsail, {
121
114
  target,
122
- command: targetSail.appSail.command,
115
+ command: targetSail.config.command,
123
116
  type: 'javase',
124
- memory: targetSail.appSail.memory || 256,
125
- env: targetSail.appSail.env_variables
117
+ memory: targetSail.config.memory || 256,
118
+ env: targetSail.config.env_variables,
119
+ name: targetSail.name
126
120
  });
127
121
  break;
128
122
  }
@@ -131,7 +125,7 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
131
125
  }
132
126
  }
133
127
  const masterServe = yield (0, master_1.default)(targetSail.port.proxy, {
134
- appSail: [serverDetails]
128
+ appSailDetails: serverDetails
135
129
  });
136
130
  child.once('exit', () => {
137
131
  masterServe.close((err) => {
@@ -140,13 +134,13 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
140
134
  }
141
135
  });
142
136
  });
143
- if ((_d = targetSail.appSail.scripts) === null || _d === void 0 ? void 0 : _d.postserve) {
137
+ if ((_d = (_c = targetSail.config) === null || _c === void 0 ? void 0 : _c.scripts) === null || _d === void 0 ? void 0 : _d.postserve) {
144
138
  child.once('exit', () => {
145
- var _a, _b, _c, _d;
146
- if (!((_a = targetSail.appSail) === null || _a === void 0 ? void 0 : _a.scripts)) {
139
+ var _a, _b, _c;
140
+ if (!((_a = targetSail.config) === null || _a === void 0 ? void 0 : _a.scripts)) {
147
141
  return;
148
142
  }
149
- executeHook((_b = targetSail.appSail.scripts) === null || _b === void 0 ? void 0 : _b.postserve, `AppSail [POSTSERVE] [${(_c = targetSail.appSail) === null || _c === void 0 ? void 0 : _c.name}]`, (_d = targetSail.appSail) === null || _d === void 0 ? void 0 : _d.source);
143
+ 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);
150
144
  });
151
145
  }
152
146
  return child;
@@ -23,7 +23,7 @@ const logger_1 = require("../../../../util_modules/logger");
23
23
  const project_1 = require("../../../../util_modules/project");
24
24
  const shell_1 = require("../../../../util_modules/shell");
25
25
  exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, function* () {
26
- var _a, _b, _c, _d, _e;
26
+ var _a, _b, _c, _d, _e, _f;
27
27
  const projectRoot = runtime_store_1.default.get('project.root');
28
28
  const javaServer = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'aioserver', 'JavaaioServer');
29
29
  const targetDir = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, (_a = details.target) === null || _a === void 0 ? void 0 : _a.name);
@@ -54,6 +54,6 @@ exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, fun
54
54
  return (0, shell_1.spawn)(spawnCommand, opts, {
55
55
  cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)),
56
56
  stdio: 'pipe',
57
- env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_CODE_LOCATION: targetDir + path_1.sep, 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) }, details.target.env_var)
57
+ env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_CODE_LOCATION: targetDir + path_1.sep, X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_f = details.target) === null || _f === void 0 ? void 0 : _f.id, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
58
58
  }).RAW();
59
59
  });
@@ -0,0 +1,53 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addAppSailRoutes = void 0;
13
+ const utils_1 = require("./utils");
14
+ function addAppSailRoutes(app, details, proxy, unknownProxy) {
15
+ var _a, _b;
16
+ app.use('/__catalyst/sdk/init.js', (req, res) => __awaiter(this, void 0, void 0, function* () {
17
+ const initJs = yield (0, utils_1.appsailInitJs)();
18
+ const _write = res.write;
19
+ res.write = () => {
20
+ res.setHeader('Content-Length', initJs.length);
21
+ return _write.call(res, initJs, 'utf-8');
22
+ };
23
+ req.url = req.originalUrl;
24
+ unknownProxy(req, res);
25
+ }));
26
+ app.use('/baas/logout', (req, res) => {
27
+ req.url = req.originalUrl;
28
+ unknownProxy(req, res);
29
+ });
30
+ ((_b = (_a = details.target) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.catalyst_auth) === true &&
31
+ app.use(['/__catalyst', '/accounts', '/oauthorize'], (req, res) => {
32
+ if (req.url.includes('/appsail/logout_redirect')) {
33
+ res.redirect(typeof req.query.service_url === 'string' ? req.query.service_url : '/');
34
+ return;
35
+ }
36
+ req.url = req.originalUrl;
37
+ unknownProxy(req, res);
38
+ });
39
+ app.use('/', (req, res) => __awaiter(this, void 0, void 0, function* () {
40
+ var _c, _d;
41
+ if (req.header('catalyst-component') === 'true') {
42
+ ((_d = (_c = details.target) === null || _c === void 0 ? void 0 : _c.config) === null || _d === void 0 ? void 0 : _d.catalyst_auth) === true
43
+ ? unknownProxy(req, res)
44
+ : res.sendStatus(400);
45
+ return;
46
+ }
47
+ proxy.web(req, res, {
48
+ target: `http://127.0.0.1:${details.target.port.appsail}`,
49
+ ws: true
50
+ });
51
+ }));
52
+ }
53
+ exports.addAppSailRoutes = addAppSailRoutes;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addFnRoutes = void 0;
4
+ const constants_1 = require("../../../../util_modules/constants");
5
+ function addFnRoutes(app, details, proxy) {
6
+ const fnTarget = details.target;
7
+ app.use(`/server/${fnTarget.name}`, (req, res) => {
8
+ proxy.web(req, res, {
9
+ target: `http://127.0.0.1:${details.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic ? `/server/${fnTarget.name}/execute` : ''}`,
10
+ ws: true
11
+ });
12
+ });
13
+ app.use(`/baas/v1/project/:projectId/function/${fnTarget.name}`, (req, res) => {
14
+ proxy.web(req, res, {
15
+ target: `http://127.0.0.1:${details.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic ? `/server/${fnTarget.name}/execute` : ''}`,
16
+ ws: true
17
+ });
18
+ });
19
+ if (fnTarget.id) {
20
+ app.use(`/server/${fnTarget.id}`, (req, res) => {
21
+ proxy.web(req, res, {
22
+ target: `http://127.0.0.1:${details.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic ? `/server/${fnTarget.id}/execute` : ''}`,
23
+ ws: true
24
+ });
25
+ });
26
+ app.use(`/baas/v1/project/:projectId/function/${fnTarget.id}`, (req, res) => {
27
+ proxy.web(req, res, {
28
+ target: `http://127.0.0.1:${details.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic ? `/server/${fnTarget.id}/execute` : ''}`,
29
+ ws: true
30
+ });
31
+ });
32
+ }
33
+ }
34
+ exports.addFnRoutes = addFnRoutes;