zcatalyst-cli 1.17.6 → 1.18.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/docs/commands/event/generate/job.toml +7 -0
  2. package/docs/commands/functions/shell.toml +4 -0
  3. package/docs/endpoints/lib/job-scheduling.toml +3 -0
  4. package/docs/internal/command.toml +5 -0
  5. package/docs/shell/dependencies/tunnel-server.toml +4 -0
  6. package/docs/shell/index.toml +7 -0
  7. package/lib/appsail-utils.js +3 -3
  8. package/lib/authentication/index.js +1 -0
  9. package/lib/command_needs/rc.js +1 -1
  10. package/lib/commands/appsail/add.js +1 -0
  11. package/lib/commands/client/setup.js +1 -0
  12. package/lib/commands/event/generate/job.js +82 -0
  13. package/lib/commands/functions/add.js +1 -0
  14. package/lib/commands/functions/delete.js +2 -4
  15. package/lib/commands/functions/setup.js +1 -0
  16. package/lib/commands/functions/shell.js +98 -1
  17. package/lib/commands/index.js +1 -0
  18. package/lib/commands/init.js +2 -6
  19. package/lib/commands/login.js +1 -0
  20. package/lib/commands/logout.js +1 -0
  21. package/lib/commands/pull.js +1 -0
  22. package/lib/commands/serve.js +2 -8
  23. package/lib/commands/whoami.js +1 -0
  24. package/lib/deploy/features/appsail/index.js +19 -17
  25. package/lib/deploy/features/appsail/utils.js +4 -5
  26. package/lib/endpoints/index.js +15 -1
  27. package/lib/endpoints/lib/appsail.js +7 -1
  28. package/lib/endpoints/lib/job-scheduling.js +61 -0
  29. package/lib/endpoints/lib/sdk.js +2 -2
  30. package/lib/endpoints/lib/tunnel.js +66 -0
  31. package/lib/express_middlewares/logger.js +2 -4
  32. package/lib/fn-utils/lib/common.js +2 -3
  33. package/lib/fn-utils/lib/java.js +1 -1
  34. package/lib/fn-utils/lib/python.js +2 -2
  35. package/lib/fn-watcher.js +1 -1
  36. package/lib/init/dependencies/python/ensure-python.js +6 -8
  37. package/lib/init/features/appsail/index.js +14 -10
  38. package/lib/init/features/functions/index.js +4 -0
  39. package/lib/init/features/functions/languages/python.js +21 -5
  40. package/lib/internal/api.js +17 -1
  41. package/lib/internal/command.js +28 -5
  42. package/lib/port-resolver.js +1 -1
  43. package/lib/repl-server.js +9 -0
  44. package/lib/serve/features/appsail.js +2 -3
  45. package/lib/serve/index.js +1 -2
  46. package/lib/serve/server/index.js +8 -9
  47. package/lib/serve/server/lib/appsail/index.js +24 -34
  48. package/lib/serve/server/lib/java/aio_server/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  49. package/lib/serve/server/lib/java/aio_server/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  50. package/lib/serve/server/lib/java/aio_server/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  51. package/lib/serve/server/lib/java/index.js +2 -2
  52. package/lib/serve/server/lib/master/appsail.js +53 -0
  53. package/lib/serve/server/lib/master/functions.js +34 -0
  54. package/lib/serve/server/lib/master/index.js +155 -0
  55. package/lib/{express_middlewares/unknownReqProxy.js → serve/server/lib/master/unknown-req-proxy.js} +4 -7
  56. package/lib/serve/server/lib/master/utils.js +130 -0
  57. package/lib/serve/server/lib/master/web-client.js +39 -0
  58. package/lib/serve/server/lib/node/index.js +3 -3
  59. package/lib/serve/server/lib/python/index.js +6 -3
  60. package/lib/shell/dependencies/http-functions.js +21 -8
  61. package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +28 -32
  62. package/lib/shell/dependencies/invoker/bio/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  63. package/lib/shell/dependencies/invoker/bio/node.mjs +2 -2
  64. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +62 -13
  65. package/lib/shell/dependencies/invoker/cron/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  66. package/lib/shell/dependencies/invoker/cron/node.mjs +28 -24
  67. package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +41 -6
  68. package/lib/shell/dependencies/invoker/event/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  69. package/lib/shell/dependencies/invoker/event/node.mjs +23 -9
  70. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +3 -3
  71. package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  72. package/lib/shell/dependencies/invoker/integ/node.mjs +6 -6
  73. package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +254 -0
  74. package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  75. package/lib/shell/dependencies/invoker/job/java/lib/org.json.jar +0 -0
  76. package/lib/shell/dependencies/invoker/job/node.mjs +93 -0
  77. package/lib/shell/dependencies/local-function.js +399 -200
  78. package/lib/shell/dependencies/tunnel-server.js +173 -0
  79. package/lib/shell/index.js +62 -2
  80. package/lib/shell/prepare/languages/index.js +4 -4
  81. package/lib/shell/prepare/languages/java.js +1 -2
  82. package/lib/shell/prepare/languages/python.js +10 -16
  83. package/lib/throbber/index.js +6 -1
  84. package/lib/userConfig.js +7 -1
  85. package/lib/util_modules/config/index.js +1 -1
  86. package/lib/util_modules/config/lib/{appSail.js → appsail.js} +61 -9
  87. package/lib/util_modules/config/lib/client.js +6 -8
  88. package/lib/util_modules/config/lib/functions.js +6 -8
  89. package/lib/util_modules/constants/index.js +3 -1
  90. package/lib/util_modules/constants/lib/default.js +1 -1
  91. package/lib/util_modules/constants/lib/fn-type.js +2 -1
  92. package/lib/util_modules/constants/lib/needed-scopes.js +61 -0
  93. package/lib/util_modules/constants/lib/placeholders.js +6 -0
  94. package/lib/util_modules/constants/lib/ref-mapping.js +2 -1
  95. package/lib/util_modules/constants/lib/remote-mapping.js +2 -1
  96. package/lib/util_modules/constants/lib/scopes.js +9 -1
  97. package/lib/util_modules/constants/lib/template.js +9 -4
  98. package/lib/util_modules/constants/lib/urls.js +16 -0
  99. package/lib/util_modules/fs/lib/async.js +7 -2
  100. package/lib/util_modules/fs/lib/sync.js +12 -1
  101. package/lib/util_modules/server.js +2 -4
  102. package/lib/winston.js +17 -11
  103. package/package.json +1 -1
  104. package/templates/event/job.json +30 -0
  105. package/templates/init/functions/java/job/.classpath +6 -0
  106. package/templates/init/functions/java/job/.project +17 -0
  107. package/templates/init/functions/java/job/catalyst-config.json +11 -0
  108. package/templates/init/functions/java/job/sample.java +34 -0
  109. package/templates/init/functions/node/aio/package.json +1 -1
  110. package/templates/init/functions/node/bio/package.json +1 -1
  111. package/templates/init/functions/node/cron/package.json +1 -1
  112. package/templates/init/functions/node/event/package.json +1 -1
  113. package/templates/init/functions/node/integ/cliq/package.json +1 -1
  114. package/templates/init/functions/node/integ/convokraft/package.json +1 -1
  115. package/templates/init/functions/node/{stream → job}/catalyst-config.json +3 -2
  116. package/templates/init/functions/node/{stream → job}/package.json +1 -1
  117. package/templates/init/functions/node/job/sample.js +28 -0
  118. package/templates/init/functions/node/job/types/job.d.ts +66 -0
  119. package/templates/init/functions/python/job/catalyst-config.json +11 -0
  120. package/templates/init/functions/python/job/requirements.txt +1 -0
  121. package/templates/init/functions/python/job/sample.py +23 -0
  122. package/templates/init.txt +13 -0
  123. package/lib/serve/server/lib/master.js +0 -317
  124. package/templates/init/functions/node/stream/sample.js +0 -15
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ var _TunnelServer_contextMap, _TunnelServer_server, _TunnelServer_destroyer, _TunnelServer_repel, _TunnelServer_projectId;
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ const express_1 = __importDefault(require("express"));
28
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
29
+ const error_1 = __importDefault(require("../../error"));
30
+ const logger_1 = require("../../util_modules/logger");
31
+ const port_resolver_1 = __importDefault(require("../../port-resolver"));
32
+ const server_1 = require("../../util_modules/server");
33
+ const ansi_colors_1 = require("ansi-colors");
34
+ const util_1 = require("util");
35
+ const project_1 = require("../../util_modules/project");
36
+ class TunnelServer {
37
+ constructor(repel) {
38
+ _TunnelServer_contextMap.set(this, {});
39
+ _TunnelServer_server.set(this, void 0);
40
+ _TunnelServer_destroyer.set(this, void 0);
41
+ _TunnelServer_repel.set(this, void 0);
42
+ _TunnelServer_projectId.set(this, (0, project_1.getProjectId)());
43
+ __classPrivateFieldSet(this, _TunnelServer_repel, repel, "f");
44
+ }
45
+ startServer() {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const tunnelPortOpt = Number.parseInt(runtime_store_1.default.get('context.port.tunnel'));
48
+ if (Number.isNaN(tunnelPortOpt)) {
49
+ return;
50
+ }
51
+ const port = yield port_resolver_1.default.getFreePort(tunnelPortOpt).catch((e) => (0, logger_1.debug)(e));
52
+ if (!port || tunnelPortOpt !== port) {
53
+ throw new error_1.default(`Port unavailable ${tunnelPortOpt}`, {
54
+ exit: 1,
55
+ errorId: 'TUNNEL-1',
56
+ arg: [ansi_colors_1.bold.red(tunnelPortOpt + ''), (0, ansi_colors_1.bold)('--tunnel')]
57
+ });
58
+ }
59
+ const app = (0, express_1.default)();
60
+ app.use(express_1.default.json());
61
+ app.all('/', (req, res) => __awaiter(this, void 0, void 0, function* () {
62
+ 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
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
72
+ __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
+ const target = body.function_details.function_id in __classPrivateFieldGet(this, _TunnelServer_contextMap, "f")
74
+ ? __classPrivateFieldGet(this, _TunnelServer_contextMap, "f")[body.function_details.function_id]
75
+ : (() => {
76
+ if (__classPrivateFieldGet(this, _TunnelServer_projectId, "f") !== body.function_details.project_id) {
77
+ res.status(403);
78
+ res.send();
79
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
80
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write('Invalid access: the tunnel is trying to access the functions from a different project');
81
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
82
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write('[STATUS]');
83
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write('FORBIDDEN');
84
+ return;
85
+ }
86
+ const namedFn = __classPrivateFieldGet(this, _TunnelServer_contextMap, "f")[body.function_details.function_name];
87
+ if (namedFn) {
88
+ return namedFn;
89
+ }
90
+ res.status(404);
91
+ res.send();
92
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
93
+ __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
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
95
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write('[STATUS]');
96
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write('NOT_FOUND');
97
+ return;
98
+ }).bind(this)();
99
+ if (!target) {
100
+ return;
101
+ }
102
+ const fnData = typeof body.function_data === 'string'
103
+ ? JSON.parse(body.function_data)
104
+ : body.function_data;
105
+ target.call(false)(fnData);
106
+ const errorHandler = (e) => {
107
+ res.status(500);
108
+ res.send();
109
+ (0, logger_1.debug)('Target error: ' + e);
110
+ };
111
+ target.once('error', errorHandler);
112
+ const response = yield new Promise((resolve, reject) => {
113
+ target.once('response', (response) => {
114
+ target.removeListener('error', errorHandler);
115
+ if (!response.Status && !response.status) {
116
+ return reject(response);
117
+ }
118
+ resolve(response);
119
+ });
120
+ });
121
+ response.ContentType && res.setHeader('Content-Type', response.ContentType);
122
+ res.status(response.status || 200);
123
+ res.send(response.responseBody);
124
+ }
125
+ catch (e) {
126
+ res.status(500);
127
+ res.send();
128
+ (0, logger_1.debug)(e);
129
+ }
130
+ }));
131
+ return new Promise((res, rej) => {
132
+ try {
133
+ __classPrivateFieldSet(this, _TunnelServer_server, app.listen(port, 'localhost', () => {
134
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write();
135
+ __classPrivateFieldGet(this, _TunnelServer_repel, "f").write((0, ansi_colors_1.bold)('Tunneling server running on port: ' + (0, ansi_colors_1.green)(port + '')));
136
+ res();
137
+ }), "f");
138
+ __classPrivateFieldSet(this, _TunnelServer_destroyer, new server_1.ConnectionDestroyer(__classPrivateFieldGet(this, _TunnelServer_server, "f")), "f");
139
+ __classPrivateFieldGet(this, _TunnelServer_server, "f").on('error', (err) => {
140
+ throw new error_1.default('Tunneling server error', {
141
+ original: err,
142
+ exit: 2
143
+ });
144
+ });
145
+ }
146
+ catch (er) {
147
+ rej(new error_1.default('Unable to start the tunneling server', {
148
+ exit: 2,
149
+ original: er
150
+ }));
151
+ }
152
+ });
153
+ });
154
+ }
155
+ addContext(name, target) {
156
+ if (!__classPrivateFieldGet(this, _TunnelServer_server, "f")) {
157
+ return this;
158
+ }
159
+ __classPrivateFieldGet(this, _TunnelServer_contextMap, "f")[name] = target;
160
+ return this;
161
+ }
162
+ stopServer() {
163
+ var _a;
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ if (!__classPrivateFieldGet(this, _TunnelServer_server, "f")) {
166
+ return;
167
+ }
168
+ return (_a = __classPrivateFieldGet(this, _TunnelServer_destroyer, "f")) === null || _a === void 0 ? void 0 : _a.destroy();
169
+ });
170
+ }
171
+ }
172
+ exports.default = TunnelServer;
173
+ _TunnelServer_contextMap = new WeakMap(), _TunnelServer_server = new WeakMap(), _TunnelServer_destroyer = new WeakMap(), _TunnelServer_repel = new WeakMap(), _TunnelServer_projectId = new WeakMap();
@@ -27,7 +27,10 @@ const http_functions_1 = __importDefault(require("./dependencies/http-functions"
27
27
  const local_function_1 = __importDefault(require("./dependencies/local-function"));
28
28
  const prepare_1 = __importDefault(require("./prepare"));
29
29
  const fn_watcher_1 = __importDefault(require("../fn-watcher"));
30
+ const tunnel_server_1 = __importDefault(require("./dependencies/tunnel-server"));
31
+ const endpoints_1 = require("../endpoints");
30
32
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
33
+ var _a;
31
34
  const replServer = new repl_server_1.default({
32
35
  prompt: 'functions > ',
33
36
  writer: (output) => {
@@ -44,9 +47,16 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
44
47
  }
45
48
  });
46
49
  const httpServer = new http_functions_1.default({ repl: replServer });
50
+ const tunnelServer = new tunnel_server_1.default(replServer);
47
51
  const projectRoot = runtime_store_1.default.get('project.root');
48
52
  try {
49
- 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]);
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
+ ]);
50
60
  const targets = runtime_store_1.default
51
61
  .get('context.functions.targets', [])
52
62
  .filter((target) => {
@@ -55,6 +65,10 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
55
65
  target.name +
56
66
  '] is not a valid one reason : ' +
57
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));
58
72
  }
59
73
  return target.valid;
60
74
  });
@@ -65,6 +79,33 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
65
79
  });
66
80
  }
67
81
  replServer.start();
82
+ yield tunnelServer.startServer();
83
+ const tunnelUrl = runtime_store_1.default.get('context.fn_shell.enable_tunnel', undefined);
84
+ const _tunnelAPI = yield (0, endpoints_1.tunnelAPI)();
85
+ if (tunnelUrl) {
86
+ try {
87
+ yield _tunnelAPI.enableTunnel(typeof tunnelUrl === 'string' ? tunnelUrl : undefined);
88
+ }
89
+ catch (er) {
90
+ const _er = error_1.default.getErrorInstance(er);
91
+ !replServer.closed && replServer.close();
92
+ yield tunnelServer.stopServer();
93
+ if (_er.status === 400) {
94
+ const data = (_a = _er.context) === null || _a === void 0 ? void 0 : _a.body.data;
95
+ throw new error_1.default('Unable to enable tunnel: ' + _er.message, {
96
+ exit: 1,
97
+ original: _er,
98
+ errorId: 'SHELL-IDX-2',
99
+ arg: [ansi_colors_1.italic.red(data.message + ''), ansi_colors_1.italic.red(data.error_code + '')]
100
+ });
101
+ }
102
+ throw new error_1.default('Unable to enable tunnel: ' + _er.message, {
103
+ exit: 2,
104
+ original: _er
105
+ });
106
+ }
107
+ replServer.write(ansi_colors_1.green.bold('Tunneling enabled'));
108
+ }
68
109
  const watchOpt = (0, option_1.getOptionValue)('watch');
69
110
  if (watchOpt === true) {
70
111
  (0, logger_js_1.info)();
@@ -75,7 +116,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
75
116
  yield (0, fn_watcher_1.default)(target);
76
117
  }
77
118
  const localFn = new local_function_1.default(replServer, target);
78
- replServer.setContext(target.name, localFn.call);
119
+ replServer.setContext(target.name, localFn.call());
120
+ tunnelServer.addContext(target.id || target.name, localFn);
79
121
  target.localFn = localFn;
80
122
  })));
81
123
  if (runtime_store_1.default.get('context.port.http.' + constants_1.FN_TYPE.basic, false)) {
@@ -83,6 +125,23 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
83
125
  }
84
126
  yield replServer.wait();
85
127
  yield httpServer.stop();
128
+ yield tunnelServer.stopServer().finally(() => __awaiter(void 0, void 0, void 0, function* () {
129
+ if (!tunnelUrl) {
130
+ return;
131
+ }
132
+ try {
133
+ const tunnelDetails = yield _tunnelAPI.getTunnel();
134
+ if (tunnelDetails.tunnel_status === 'Enabled') {
135
+ yield _tunnelAPI.disableTunnel();
136
+ (0, logger_js_1.info)();
137
+ (0, logger_js_1.info)(ansi_colors_1.green.bold('Tunneling disabled'));
138
+ }
139
+ }
140
+ catch (er) {
141
+ (0, logger_js_1.error)('Error disabling the tunnel');
142
+ (0, logger_js_1.debug)(er);
143
+ }
144
+ }));
86
145
  yield Promise.all(targets.map((target) => __awaiter(void 0, void 0, void 0, function* () {
87
146
  if (target.localFn) {
88
147
  return target.localFn.shutdown();
@@ -94,6 +153,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
94
153
  (0, logger_js_1.success)('shell complete');
95
154
  }
96
155
  catch (e) {
156
+ !replServer.closed && replServer.close();
97
157
  yield Promise.all([
98
158
  fs_1.ASYNC.deleteDir((0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)).catch(),
99
159
  httpServer ? httpServer.stop() : undefined
@@ -47,17 +47,17 @@ function java(targets) {
47
47
  return (yield Promise.resolve().then(() => __importStar(require('./java')))).default(targets);
48
48
  });
49
49
  }
50
- function python(targets, fnWatchEvent) {
50
+ function python(targets) {
51
51
  return __awaiter(this, void 0, void 0, function* () {
52
- return (yield Promise.resolve().then(() => __importStar(require('./python')))).default(targets, fnWatchEvent);
52
+ return (yield Promise.resolve().then(() => __importStar(require('./python')))).default(targets);
53
53
  });
54
54
  }
55
- function prepareFunctions(targets, fnWatchEvent) {
55
+ function prepareFunctions(targets) {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
57
  return Promise.all([
58
58
  node(targets.filter((target) => { var _a; return ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.node.value)) && target.valid; })),
59
59
  java(targets.filter((target) => { var _a; return ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java.value)) && target.valid; })),
60
- python(targets.filter((target) => { var _a; return ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python.value)) && target.valid; }), fnWatchEvent)
60
+ python(targets.filter((target) => { var _a; return ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python.value)) && target.valid; }))
61
61
  ]);
62
62
  });
63
63
  }
@@ -18,7 +18,6 @@ const java_1 = require("../../../fn-utils/lib/java");
18
18
  const runtime_store_1 = __importDefault(require("../../../runtime-store"));
19
19
  const constants_1 = require("../../../util_modules/constants");
20
20
  const fs_1 = require("../../../util_modules/fs");
21
- const fs_2 = require("fs");
22
21
  const throbber_1 = __importDefault(require("../../../throbber"));
23
22
  const error_1 = __importDefault(require("../../../error"));
24
23
  exports.default = (targets) => __awaiter(void 0, void 0, void 0, function* () {
@@ -56,7 +55,7 @@ exports.default = (targets) => __awaiter(void 0, void 0, void 0, function* () {
56
55
  const serverFiles = yield fs_1.ASYNC.walk((0, path_1.dirname)(javaServer));
57
56
  yield Promise.all(serverFiles.map((file) => __awaiter(void 0, void 0, void 0, function* () {
58
57
  try {
59
- return fs_1.ASYNC.copyFile(file.path, (0, path_1.join)(targetBuildPath, (0, path_1.relative)((0, path_1.dirname)(javaServer), file.path.replace('lib' + path_1.sep, ''))), fs_2.constants.COPYFILE_EXCL);
58
+ return fs_1.ASYNC.copyFile(file.path, (0, path_1.join)(targetBuildPath, (0, path_1.relative)((0, path_1.dirname)(javaServer), file.path.replace('lib' + path_1.sep, ''))), false);
60
59
  }
61
60
  catch (e) {
62
61
  const err = error_1.default.getErrorInstance(e).original;
@@ -21,7 +21,7 @@ const pip_install_1 = require("../../../init/dependencies/python/pip-install");
21
21
  const error_1 = __importDefault(require("../../../error"));
22
22
  const fs_extra_1 = require("fs-extra");
23
23
  const throbber_1 = __importDefault(require("../../../throbber"));
24
- exports.default = (targets, fnWatchEvent) => __awaiter(void 0, void 0, void 0, function* () {
24
+ exports.default = (targets) => __awaiter(void 0, void 0, void 0, function* () {
25
25
  if (targets === undefined || targets.length === 0) {
26
26
  return;
27
27
  }
@@ -42,22 +42,16 @@ exports.default = (targets, fnWatchEvent) => __awaiter(void 0, void 0, void 0, f
42
42
  var _a;
43
43
  const buildPath = (0, path_1.join)(runtime_store_1.default.get('project.root'), constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, target.name);
44
44
  const reqFile = (0, path_1.join)(target.source, constants_1.FILENAME.functions.python_requirements);
45
- const requirementsExists = yield fs_1.ASYNC.readFile(reqFile);
46
- const watch = fnWatchEvent
47
- ? fnWatchEvent.pth === constants_1.FILENAME.functions.python_requirements
48
- : true;
49
- if (requirementsExists && watch) {
50
- yield (0, fs_extra_1.ensureDir)(buildPath);
51
- try {
52
- yield (0, pip_install_1.installRequirements)(reqFile, buildPath, (_a = target.stack) === null || _a === void 0 ? void 0 : _a.replace('python_', ''));
53
- }
54
- catch (err) {
55
- const error = error_1.default.getErrorInstance(err);
56
- target.valid = false;
57
- target.failure_reason = error.message;
58
- }
59
- }
45
+ yield (0, fs_extra_1.ensureDir)(buildPath);
60
46
  yield fs_1.ASYNC.emptyDir(buildPath);
47
+ try {
48
+ yield (0, pip_install_1.installRequirements)(reqFile, buildPath, (_a = target.stack) === null || _a === void 0 ? void 0 : _a.replace('python_', ''));
49
+ }
50
+ catch (err) {
51
+ const error = error_1.default.getErrorInstance(err);
52
+ target.valid = false;
53
+ target.failure_reason = error.message;
54
+ }
61
55
  yield fs_1.ASYNC.copyDir(target.source, buildPath);
62
56
  throbber.remove('function_serve_' + target.name);
63
57
  return target;
@@ -42,7 +42,9 @@ class Throbber {
42
42
  options.text = name;
43
43
  }
44
44
  const spinnerProperties = Object.assign(Object.assign({}, this.options), options);
45
- this.spinners[name] = spinnerProperties;
45
+ if (this.spin) {
46
+ this.spinners[name] = spinnerProperties;
47
+ }
46
48
  this.updateSpinnerState();
47
49
  return spinnerProperties;
48
50
  }
@@ -94,6 +96,9 @@ class Throbber {
94
96
  return !!Object.values(this.spinners).find(({ status }) => status === 'spinning');
95
97
  }
96
98
  setSpinnerProperties(name, options, status = 'spinning') {
99
+ if (!this.spin) {
100
+ return;
101
+ }
97
102
  if (!this.spinners[name]) {
98
103
  throw new error_js_1.default(`No spinner initialized with name ${name}`);
99
104
  }
package/lib/userConfig.js CHANGED
@@ -9,7 +9,13 @@ const path_1 = __importDefault(require("path"));
9
9
  const error_1 = __importDefault(require("./error"));
10
10
  class UserConfig {
11
11
  constructor() {
12
- this.validKeys = ['python3_9.bin', 'java8.bin', 'java11.bin', 'java17.bin'];
12
+ this.validKeys = [
13
+ 'python3_9.bin',
14
+ 'java8.bin',
15
+ 'java11.bin',
16
+ 'java17.bin',
17
+ 'javac.disable_warnings'
18
+ ];
13
19
  this.configFilePath = path_1.default.join(constants_1.ENVPATH.userConfig.config, '.zcconfig');
14
20
  this.config = fs_1.SYNC.readJSONFile(this.configFilePath, { checkpath: true }) || {};
15
21
  }
@@ -30,5 +30,5 @@ const clientConfig = __importStar(require("./lib/client"));
30
30
  exports.clientConfig = clientConfig;
31
31
  const functionsConfig = __importStar(require("./lib/functions"));
32
32
  exports.functionsConfig = functionsConfig;
33
- const appSailConfig = __importStar(require("./lib/appSail.js"));
33
+ const appSailConfig = __importStar(require("./lib/appsail"));
34
34
  exports.appSailConfig = appSailConfig;
@@ -13,12 +13,63 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getAllTargetDetails = exports.getTargetDetails = exports.raw = void 0;
16
+ const path_1 = require("path");
16
17
  const error_1 = __importDefault(require("../../../error"));
17
18
  const runtime_store_1 = __importDefault(require("../../../runtime-store"));
18
19
  const constants_1 = require("../../constants");
19
20
  const fs_1 = require("../../fs");
20
- const logger_1 = require("../../logger");
21
21
  const project_1 = require("../../project");
22
+ function validateConfig(source, configJson) {
23
+ if (!configJson) {
24
+ return {
25
+ valid: false,
26
+ reason: 'Config file is empty'
27
+ };
28
+ }
29
+ if (configJson.buildPath || configJson.build_path) {
30
+ const buildPath = configJson.build_path || configJson.buildPath;
31
+ if (!buildPath) {
32
+ return {
33
+ valid: false,
34
+ reason: 'Build Path not present'
35
+ };
36
+ }
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
+ configJson.build_path = absolutePath;
45
+ }
46
+ if (configJson.catalyst_auth === true) {
47
+ if (configJson.login_redirect === undefined) {
48
+ return {
49
+ valid: false,
50
+ reason: 'Login Redirect value incorrect! Please check the entered value.'
51
+ };
52
+ }
53
+ else if (configJson.login_redirect.length === 0) {
54
+ return {
55
+ valid: false,
56
+ reason: 'Login Redirect value empty! Please provide a login redirect URL.'
57
+ };
58
+ }
59
+ else if (configJson.login_redirect.toLowerCase().startsWith('http') ||
60
+ configJson.login_redirect.includes('://') ||
61
+ !configJson.login_redirect.startsWith('/') ||
62
+ configJson.login_redirect.includes('//')) {
63
+ return {
64
+ valid: false,
65
+ reason: 'Login Redirect value not a relative URL! Please provide a relative URL.'
66
+ };
67
+ }
68
+ }
69
+ return {
70
+ valid: true
71
+ };
72
+ }
22
73
  function raw(throwError = false) {
23
74
  const config = runtime_store_1.default.get('config', null);
24
75
  if (config === null) {
@@ -70,17 +121,18 @@ function getAllTargetDetails(throwErr = true) {
70
121
  return resArr;
71
122
  }
72
123
  resArr.push(new Promise((res) => __awaiter(this, void 0, void 0, function* () {
73
- const configJson = yield fs_1.ASYNC.readJSONFile(catalystConfigPth).catch((err) => (0, logger_1.debug)('Unable to read config file: ', err));
74
- if (!configJson) {
75
- return res(Object.assign({ validity: {
124
+ try {
125
+ const configJson = yield fs_1.ASYNC.readJSONFile(catalystConfigPth);
126
+ const validity = validateConfig(target.source, configJson);
127
+ return res(Object.assign({ config: configJson, validity }, target));
128
+ }
129
+ catch (er) {
130
+ const configErr = error_1.default.getErrorInstance(er, { skipHelp: true });
131
+ res(Object.assign({ validity: {
76
132
  valid: false,
77
- reason: 'Config file is empty'
133
+ reason: configErr.message
78
134
  } }, target));
79
135
  }
80
- return res({
81
- appSail: Object.assign(Object.assign({}, target), configJson),
82
- validity: { valid: true }
83
- });
84
136
  })));
85
137
  return resArr;
86
138
  }, []));
@@ -55,16 +55,14 @@ function ignore(sourcePath) {
55
55
  if (js_js_1.JS.indexOf(value, path_1.sep) === js_js_1.JS.size(value) - 1) {
56
56
  return '**' + path_1.sep + js_js_1.JS.initial(value).join('');
57
57
  }
58
- else {
59
- if (js_js_1.JS.startsWith(value, path_1.sep)) {
60
- return js_js_1.JS.endsWith(value, path_1.sep)
61
- ? sourcePath + js_js_1.JS.initial(value).join('')
62
- : sourcePath + value;
63
- }
58
+ if (js_js_1.JS.startsWith(value, path_1.sep)) {
64
59
  return js_js_1.JS.endsWith(value, path_1.sep)
65
- ? sourcePath + path_1.sep + js_js_1.JS.initial(value).join('')
66
- : sourcePath + path_1.sep + value;
60
+ ? sourcePath + js_js_1.JS.initial(value).join('')
61
+ : sourcePath + value;
67
62
  }
63
+ return js_js_1.JS.endsWith(value, path_1.sep)
64
+ ? sourcePath + path_1.sep + js_js_1.JS.initial(value).join('')
65
+ : sourcePath + path_1.sep + value;
68
66
  });
69
67
  }
70
68
  exports.ignore = ignore;
@@ -68,16 +68,14 @@ function ignore(sourcePath) {
68
68
  if (js_1.JS.indexOf(value, path_1.sep) === js_1.JS.size(value) - 1) {
69
69
  return '**' + path_1.sep + js_1.JS.initial(value).join('');
70
70
  }
71
- else {
72
- if (js_1.JS.startsWith(value, path_1.sep)) {
73
- return js_1.JS.endsWith(value, path_1.sep)
74
- ? sourcePath + js_1.JS.initial(value).join('')
75
- : sourcePath + value;
76
- }
71
+ if (js_1.JS.startsWith(value, path_1.sep)) {
77
72
  return js_1.JS.endsWith(value, path_1.sep)
78
- ? sourcePath + path_1.sep + js_1.JS.initial(value).join('')
79
- : sourcePath + path_1.sep + value;
73
+ ? sourcePath + js_1.JS.initial(value).join('')
74
+ : sourcePath + value;
80
75
  }
76
+ return js_1.JS.endsWith(value, path_1.sep)
77
+ ? sourcePath + path_1.sep + js_1.JS.initial(value).join('')
78
+ : sourcePath + path_1.sep + value;
81
79
  });
82
80
  }
83
81
  exports.ignore = ignore;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ENVPATH = exports.RUNTIME = exports.IAC = exports.PLUGIN = exports.ORIGIN = exports.TEMPLATE = exports.SCOPE = exports.REMOTE_REF = exports.REGEX = exports.REFERENCE = exports.PLACEHOLDER = exports.INTEG = exports.FOLDERNAME = exports.FN_TYPE = exports.DC_TYPE = exports.FILENAME = exports.EVENT_SOURCE = exports.EVENT_REF = exports.DEFAULT = exports.CLIQ = exports.AUTH = exports.APIG_RULES = void 0;
6
+ exports.NEEDED_SCOPES = exports.ENVPATH = exports.RUNTIME = exports.IAC = exports.PLUGIN = exports.ORIGIN = exports.TEMPLATE = exports.SCOPE = exports.REMOTE_REF = exports.REGEX = exports.REFERENCE = exports.PLACEHOLDER = exports.INTEG = exports.FOLDERNAME = exports.FN_TYPE = exports.DC_TYPE = exports.FILENAME = exports.EVENT_SOURCE = exports.EVENT_REF = exports.DEFAULT = exports.CLIQ = exports.AUTH = exports.APIG_RULES = void 0;
7
7
  var apig_rules_1 = require("./lib/apig-rules");
8
8
  Object.defineProperty(exports, "APIG_RULES", { enumerable: true, get: function () { return __importDefault(apig_rules_1).default; } });
9
9
  var auth_1 = require("./lib/auth");
@@ -48,3 +48,5 @@ var runtime_1 = require("./lib/runtime");
48
48
  Object.defineProperty(exports, "RUNTIME", { enumerable: true, get: function () { return __importDefault(runtime_1).default; } });
49
49
  var env_path_1 = require("./lib/env-path");
50
50
  Object.defineProperty(exports, "ENVPATH", { enumerable: true, get: function () { return __importDefault(env_path_1).default; } });
51
+ var needed_scopes_1 = require("./lib/needed-scopes");
52
+ Object.defineProperty(exports, "NEEDED_SCOPES", { enumerable: true, get: function () { return __importDefault(needed_scopes_1).default; } });
@@ -17,7 +17,7 @@ exports.default = Object.freeze({
17
17
  browser_logic: 4400,
18
18
  appsail: {
19
19
  master: 3000,
20
- service: 4500
20
+ service: 4600
21
21
  },
22
22
  client: 5000
23
23
  },
@@ -7,5 +7,6 @@ exports.default = Object.freeze({
7
7
  applogic: 'applogic',
8
8
  advanced: 'aio',
9
9
  integration: 'integ',
10
- browserLogic: 'browserlogic'
10
+ browserLogic: 'browserlogic',
11
+ job: 'job'
11
12
  });
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const __1 = require("..");
8
+ const login_1 = require("../../../authentication/login");
9
+ const dc_1 = require("../../../dc");
10
+ const scopes_1 = __importDefault(require("./scopes"));
11
+ const serveScopes = [
12
+ scopes_1.default.api_read,
13
+ scopes_1.default.apig_read,
14
+ scopes_1.default.segment,
15
+ scopes_1.default.cache_read,
16
+ scopes_1.default.cache_create,
17
+ scopes_1.default.cache_delete,
18
+ scopes_1.default.projects,
19
+ scopes_1.default.cron,
20
+ scopes_1.default.zcql,
21
+ scopes_1.default.project_user_read,
22
+ scopes_1.default.project_user_create,
23
+ scopes_1.default.project_user_delete,
24
+ scopes_1.default.project_user_update,
25
+ scopes_1.default.custom_token_generation,
26
+ scopes_1.default.email_send,
27
+ scopes_1.default.datastore,
28
+ scopes_1.default.row,
29
+ scopes_1.default.column,
30
+ scopes_1.default.bulk_create,
31
+ scopes_1.default.bulk_read,
32
+ scopes_1.default.folders,
33
+ scopes_1.default.file_create,
34
+ scopes_1.default.file_read,
35
+ scopes_1.default.file_delete,
36
+ scopes_1.default.functions,
37
+ scopes_1.default.functions_execution,
38
+ scopes_1.default.event_listeners,
39
+ scopes_1.default.event_produce,
40
+ scopes_1.default.security_read,
41
+ scopes_1.default.security_update,
42
+ scopes_1.default.notification_mobile,
43
+ scopes_1.default.notification_web,
44
+ scopes_1.default.search_read,
45
+ scopes_1.default.zia,
46
+ scopes_1.default.quick_ml,
47
+ scopes_1.default.pdf_shot,
48
+ scopes_1.default.dataverse,
49
+ scopes_1.default.circuits_exe_delete,
50
+ scopes_1.default.circuits_exe_read,
51
+ scopes_1.default.circuits_execute,
52
+ scopes_1.default.appsail_read,
53
+ scopes_1.default.jobpool_read,
54
+ scopes_1.default.job,
55
+ scopes_1.default.nosql_table,
56
+ scopes_1.default.nosql_rows
57
+ ];
58
+ const _missingScope = ((_a = login_1.missingScopes[(0, dc_1.getActiveDC)()]) === null || _a === void 0 ? void 0 : _a.map((dvScope) => __1.SCOPE[dvScope])) || [];
59
+ exports.default = Object.freeze({
60
+ SERVE: serveScopes.filter((scope) => !_missingScope.includes(scope))
61
+ });