zcatalyst-cli 1.15.2 → 1.16.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.
- package/README.md +11 -0
- package/docs/fn-utils/lib/ensure-java-userconfig.toml +15 -0
- package/lib/authentication/login.js +3 -3
- package/lib/command_needs/auth.js +2 -2
- package/lib/command_needs/rc.js +7 -2
- package/lib/commands/iac/import.js +1 -1
- package/lib/commands/init.js +3 -1
- package/lib/commands/project/use.js +4 -0
- package/lib/commands/pull.js +8 -1
- package/lib/commands/serve.js +1 -1
- package/lib/deploy/features/functions/index.js +5 -0
- package/lib/express_middlewares/unknownReqProxy.js +4 -0
- package/lib/fn-utils/lib/ensure-java-userconfig.js +151 -0
- package/lib/fn-utils/lib/java.js +109 -49
- package/lib/internal/credential.js +7 -0
- package/lib/pull/features/apig.js +16 -3
- package/lib/pull/features/client.js +16 -3
- package/lib/pull/features/functions/index.js +62 -32
- package/lib/serve/index.js +12 -1
- package/lib/serve/server/lib/java/index.js +7 -2
- package/lib/serve/server/lib/master.js +32 -7
- package/lib/serve/server/lib/node/server/index.js +1 -1
- package/lib/serve/server/lib/python/index.js +6 -2
- package/lib/serve/server/lib/web_client/server.js +1 -1
- package/lib/shell/dependencies/http-functions.js +19 -6
- package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +4 -6
- package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +3 -4
- package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +3 -5
- package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +2 -2
- package/lib/shell/dependencies/local-function.js +7 -3
- package/lib/shell/prepare/languages/java.js +2 -2
- package/lib/userConfig.js +1 -1
- package/lib/util_modules/constants/lib/apig-rules.js +5 -5
- package/lib/util_modules/constants/lib/plugin.js +1 -1
- package/lib/util_modules/constants/lib/scopes.js +3 -1
- package/package.json +4 -4
|
@@ -29,6 +29,7 @@ const runtime_1 = __importDefault(require("../../../util_modules/constants/lib/r
|
|
|
29
29
|
const error_1 = __importDefault(require("../../../error"));
|
|
30
30
|
const python_1 = require("../../../fn-utils/lib/python");
|
|
31
31
|
const throbber_1 = __importDefault(require("../../../throbber"));
|
|
32
|
+
const ensure_java_userconfig_1 = require("../../../fn-utils/lib/ensure-java-userconfig");
|
|
32
33
|
function selFnsPrompt(targs, fnDirPath) {
|
|
33
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
35
|
const choicesObj = targs.reduce((accumulator, fn) => {
|
|
@@ -134,54 +135,83 @@ exports.default = (_fns) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
134
135
|
});
|
|
135
136
|
}));
|
|
136
137
|
runtime_store_1.default.set('context.functions.targets', targets);
|
|
138
|
+
let isFnPulled = false;
|
|
139
|
+
let isFnPulledFailed = false;
|
|
137
140
|
targets = yield Promise.all(targets.map((fn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
141
|
var _a, _b, _c;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
(
|
|
142
|
+
try {
|
|
143
|
+
yield fs_1.ASYNC.ensureDir(fn.source);
|
|
144
|
+
const buffer = (yield fnAPI.download(fn.id));
|
|
145
|
+
yield new archiver_1.default().load(buffer).extract((0, path_1.join)(fnDirPath, fn.name)).finalize();
|
|
146
|
+
if ((_a = fn.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.node.value)) {
|
|
147
|
+
yield (0, languages_1.node)(fn);
|
|
148
|
+
}
|
|
149
|
+
else if ((_b = fn.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.java.value)) {
|
|
150
|
+
yield (0, ensure_java_userconfig_1.ensureJava)(fn);
|
|
151
|
+
yield (0, languages_1.java)(fn);
|
|
152
|
+
}
|
|
153
|
+
else if ((_c = fn.stack) === null || _c === void 0 ? void 0 : _c.startsWith(runtime_1.default.language.python.value)) {
|
|
154
|
+
yield (0, languages_1.python)(fn);
|
|
155
|
+
const reqFile = (0, path_1.join)(fn.source, constants_1.FILENAME.functions.python_requirements);
|
|
156
|
+
const requirementsExists = yield fs_1.ASYNC.readFile(reqFile);
|
|
157
|
+
if (requirementsExists && fn.valid) {
|
|
158
|
+
try {
|
|
159
|
+
yield (0, python_1.removeRequirements)(reqFile, fn);
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
const err = error_1.default.getErrorInstance(e);
|
|
163
|
+
(fn.valid = false), (fn.failure_reason = err.message);
|
|
164
|
+
}
|
|
159
165
|
}
|
|
160
166
|
}
|
|
167
|
+
const catalystJsonPth = (0, path_1.join)(fn.source, constants_1.FILENAME.catalyst_config);
|
|
168
|
+
const catalystJson = yield fs_1.ASYNC.readJSONFile(catalystJsonPth);
|
|
169
|
+
const fnDetails = (yield fnAPI.getFunction(fn.id));
|
|
170
|
+
const envVariables = js_1.JS.get(fnDetails, 'configuration.environment.variables', false);
|
|
171
|
+
if (catalystJson && envVariables) {
|
|
172
|
+
catalystJson.deployment.env_variables = envVariables;
|
|
173
|
+
yield fs_1.ASYNC.writeJSONFile(catalystJsonPth, catalystJson);
|
|
174
|
+
}
|
|
175
|
+
isFnPulled = true;
|
|
161
176
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
177
|
+
catch (err) {
|
|
178
|
+
const error = err;
|
|
179
|
+
let message = error.message;
|
|
180
|
+
if (error instanceof error_1.default) {
|
|
181
|
+
if (error.errorId && error.errorId === 'JAVACONFIG-3') {
|
|
182
|
+
message = `You are trying to pull a function of a higher stack version[${fn.stack}]. Please provide a valid java binary path for the config key ${fn.stack}.bin to pull function[${fn.name}].`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
throbber.remove('function_pull_' + fn.name);
|
|
186
|
+
(0, logger_1.warning)(`Skipping pull of function(${fn.name}). ${message}`);
|
|
187
|
+
fn.failure_reason = `there was an error while pulling function [${fn.name}]. ${message}`;
|
|
188
|
+
isFnPulledFailed = true;
|
|
169
189
|
}
|
|
170
190
|
throbber.remove('function_pull_' + fn.name);
|
|
171
191
|
return fn;
|
|
172
192
|
})));
|
|
173
193
|
targets = targets.filter((target) => {
|
|
174
|
-
var _a, _b;
|
|
175
|
-
if (!target.valid &&
|
|
194
|
+
var _a, _b, _c;
|
|
195
|
+
if (!target.valid &&
|
|
196
|
+
!((_a = target.failure_reason) === null || _a === void 0 ? void 0 : _a.startsWith('unable to locate python')) &&
|
|
197
|
+
!((_b = target.failure_reason) === null || _b === void 0 ? void 0 : _b.includes('You are trying to pull a function of a higher stack version'))) {
|
|
176
198
|
(0, logger_1.debug)('Invalid target : ' + target.name + ' reason : ' + target.failure_reason);
|
|
177
199
|
(0, logger_1.warning)(`skipping pull of function(${target.name}) since the package is invalid. \nContact catalyst support with debug log.`);
|
|
178
200
|
new error_1.default('invalid package: ' + target.name, { exit: 2 });
|
|
179
201
|
}
|
|
180
|
-
else if (!target.valid && ((
|
|
202
|
+
else if (!target.valid && ((_c = target.failure_reason) === null || _c === void 0 ? void 0 : _c.startsWith('unable to locate python'))) {
|
|
181
203
|
(0, logger_1.warning)(`skipping pull of function(${target.name}) since ${target.failure_reason}`);
|
|
182
204
|
}
|
|
183
205
|
return target.valid;
|
|
184
206
|
});
|
|
185
|
-
|
|
186
|
-
|
|
207
|
+
if (isFnPulled) {
|
|
208
|
+
runtime_store_1.default.set('payload.functions.targets', targets);
|
|
209
|
+
runtime_store_1.default.set('payload.functions.source', fnDirName);
|
|
210
|
+
if (isFnPulledFailed) {
|
|
211
|
+
runtime_store_1.default.set('payload.functions.status', 1);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
runtime_store_1.default.set('payload.functions.status', 2);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
187
217
|
});
|
package/lib/serve/index.js
CHANGED
|
@@ -51,6 +51,7 @@ const logger_1 = require("../util_modules/logger");
|
|
|
51
51
|
const option_1 = require("../util_modules/option");
|
|
52
52
|
const features = __importStar(require("./features"));
|
|
53
53
|
const server_1 = __importDefault(require("./server"));
|
|
54
|
+
const char_1 = require("../util_modules/char");
|
|
54
55
|
exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
56
|
const serveTargets = runtime_store_1.default.get('context.targets', []);
|
|
56
57
|
const advancedServer = new server_1.default();
|
|
@@ -89,6 +90,11 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
89
90
|
}
|
|
90
91
|
const functionTargets = rawTargets.filter((target) => {
|
|
91
92
|
var _a;
|
|
93
|
+
if (target.compilationError) {
|
|
94
|
+
target.compilationError.forEach((error) => {
|
|
95
|
+
console.log(`${(0, ansi_colors_1.red)(char_1.CHAR.error)} Error while compiling function[${target.name}] : ${error}`);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
92
98
|
if (!target.valid) {
|
|
93
99
|
(0, logger_1.warning)('skipping serve of function [' +
|
|
94
100
|
target.name +
|
|
@@ -96,6 +102,11 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
96
102
|
target.failure_reason);
|
|
97
103
|
return false;
|
|
98
104
|
}
|
|
105
|
+
if (target.compilationWarning) {
|
|
106
|
+
target.compilationWarning.forEach((message) => {
|
|
107
|
+
(0, logger_1.warning)(message);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
99
110
|
if (target.type === constants_1.FN_TYPE.advanced) {
|
|
100
111
|
advancedServer.add('server', target);
|
|
101
112
|
}
|
|
@@ -171,7 +182,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
171
182
|
}).catch((err) => (0, logger_1.debug)('Error modifying the permissions: ', err)));
|
|
172
183
|
(0, logger_1.info)('Shutting down server');
|
|
173
184
|
yield Promise.all([
|
|
174
|
-
fs_1.ASYNC.deleteDir(buildFolder).catch(),
|
|
185
|
+
fs_1.ASYNC.deleteDir(buildFolder).catch((err) => (0, logger_1.debug)('Error while deleting directory ', err)),
|
|
175
186
|
advancedServer ? advancedServer.stop() : undefined,
|
|
176
187
|
basicFnServer ? basicFnServer.stop() : undefined
|
|
177
188
|
]);
|
|
@@ -14,14 +14,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const path_1 = require("path");
|
|
16
16
|
const fn_utils_1 = require("../../../../fn-utils");
|
|
17
|
+
const ensure_java_userconfig_1 = require("../../../../fn-utils/lib/ensure-java-userconfig");
|
|
17
18
|
const plugin_loader_1 = __importDefault(require("../../../../plugin-loader"));
|
|
18
19
|
const runtime_store_1 = __importDefault(require("../../../../runtime-store"));
|
|
20
|
+
const userConfig_1 = __importDefault(require("../../../../userConfig"));
|
|
19
21
|
const constants_1 = require("../../../../util_modules/constants");
|
|
20
22
|
const logger_1 = require("../../../../util_modules/logger");
|
|
21
23
|
const project_1 = require("../../../../util_modules/project");
|
|
22
24
|
const shell_1 = require("../../../../util_modules/shell");
|
|
23
25
|
exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
var _a, _b, _c;
|
|
26
|
+
var _a, _b, _c, _d, _e;
|
|
25
27
|
const cwd = runtime_store_1.default.get('cwd');
|
|
26
28
|
const javaServer = (0, path_1.join)(cwd, constants_1.FOLDERNAME.build, '.catalyst', 'aioserver', 'JavaaioServer');
|
|
27
29
|
const targetDir = (0, path_1.join)(cwd, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, (_a = details.target) === null || _a === void 0 ? void 0 : _a.name);
|
|
@@ -46,7 +48,10 @@ exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, fun
|
|
|
46
48
|
(0, logger_1.labeled)(label, `Plugin : "${runtime_store_1.default.get(`context.${configType}.plugins.start${targetSource ? '.' + targetSource : ''}`)}" is used for ${details.type} serve`).MESSAGE();
|
|
47
49
|
return event;
|
|
48
50
|
}
|
|
49
|
-
|
|
51
|
+
const configKey = `${(_d = details.target) === null || _d === void 0 ? void 0 : _d.stack}.bin`;
|
|
52
|
+
const userConfigCmd = userConfig_1.default.get(configKey);
|
|
53
|
+
const spawnCommand = (0, ensure_java_userconfig_1.getJavaSpawnCommand)(userConfigCmd, 'java', (_e = details.target) === null || _e === void 0 ? void 0 : _e.stack);
|
|
54
|
+
return (0, shell_1.spawn)(spawnCommand, opts, {
|
|
50
55
|
cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(cwd, (0, path_1.join)(cwd, constants_1.FOLDERNAME.build)),
|
|
51
56
|
stdio: 'pipe',
|
|
52
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)
|
|
@@ -105,10 +105,26 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
105
105
|
const customProxyUrl = (0, option_1.getOptionValue)('proxy');
|
|
106
106
|
const app = (0, express_1.default)();
|
|
107
107
|
let systemRoutes;
|
|
108
|
+
const nonApigURL = ['/accounts', '/clientoauth', '/_wms', '/wmssrv'];
|
|
108
109
|
app.use((0, logger_1.default)((_a = otherServerDetails.appSail) === null || _a === void 0 ? void 0 : _a.at(0)));
|
|
109
110
|
app.use(cookie_parser_1.default);
|
|
110
111
|
app.use((0, project_1.default)(projectDetails));
|
|
111
112
|
app.use(authenticator_1.default);
|
|
113
|
+
app.use(nonApigURL, (req, res) => {
|
|
114
|
+
req.url = req.originalUrl;
|
|
115
|
+
(0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
|
|
116
|
+
});
|
|
117
|
+
app.use('*/.catalyst%2Freload-script.js', (req, res) => {
|
|
118
|
+
var _a;
|
|
119
|
+
req.url = '/.catalyst%2Freload-script.js';
|
|
120
|
+
(_a = otherServerDetails.client) === null || _a === void 0 ? void 0 : _a.forEach((clientDetails) => {
|
|
121
|
+
const appTarget = `http://127.0.0.1:${clientDetails.httpPort}/app/`;
|
|
122
|
+
proxy.web(req, res, {
|
|
123
|
+
target: appTarget,
|
|
124
|
+
changeOrigin: true
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
112
128
|
if (rules !== -1) {
|
|
113
129
|
for (const [sourceURL, methodByConfig] of Object.entries(rules)) {
|
|
114
130
|
const router = app.route(sourceURL);
|
|
@@ -130,7 +146,10 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
130
146
|
}
|
|
131
147
|
app.use('/', apig_matcher_1.default, auth_checker_1.default, url_rewriter_1.default);
|
|
132
148
|
}
|
|
133
|
-
const proxy = (0, http_proxy_1.createProxyServer)(
|
|
149
|
+
const proxy = (0, http_proxy_1.createProxyServer)({
|
|
150
|
+
hostRewrite: `localhost:${listenPort}`,
|
|
151
|
+
protocolRewrite: 'http'
|
|
152
|
+
})
|
|
134
153
|
.on('error', (err, req, res) => {
|
|
135
154
|
if (res instanceof http_1.ServerResponse) {
|
|
136
155
|
res.writeHead(502, { 'Content-Type': 'json' });
|
|
@@ -248,11 +267,17 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
248
267
|
case 'appSail': {
|
|
249
268
|
(_d = otherServerDetails.appSail) === null || _d === void 0 ? void 0 : _d.forEach((appSailDetails) => {
|
|
250
269
|
app.use('/', (req, res) => {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
270
|
+
var _a;
|
|
271
|
+
if ((_a = req.url) === null || _a === void 0 ? void 0 : _a.includes('/__catalyst/sdk/init.js')) {
|
|
272
|
+
(0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
proxy.web(req, res, {
|
|
276
|
+
target: `http://127.0.0.1:${appSailDetails.target.port
|
|
277
|
+
.appsail}`,
|
|
278
|
+
ws: true
|
|
279
|
+
});
|
|
280
|
+
}
|
|
256
281
|
});
|
|
257
282
|
});
|
|
258
283
|
break;
|
|
@@ -265,7 +290,7 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
265
290
|
});
|
|
266
291
|
app.use('/', (0, unknownReqProxy_1.default)(proxy, customProxyUrl));
|
|
267
292
|
app.use(error_handler_1.default);
|
|
268
|
-
const expressServer = app.listen(listenPort).on('error', (err) => {
|
|
293
|
+
const expressServer = app.listen(listenPort, '127.0.0.1').on('error', (err) => {
|
|
269
294
|
if (proxy) {
|
|
270
295
|
proxyDestroyer.destroy();
|
|
271
296
|
}
|
|
@@ -69,7 +69,7 @@ const browserLogicHandler = async (req, res) => {
|
|
|
69
69
|
|
|
70
70
|
const server = createServer(type === 'browserlogic' ? browserLogicHandler : aioHandler);
|
|
71
71
|
|
|
72
|
-
server.listen(listenPort).on('error', (err) => {
|
|
72
|
+
server.listen(listenPort, '127.0.0.1').on('error', (err) => {
|
|
73
73
|
// eslint-disable-next-line no-console
|
|
74
74
|
console.error(err);
|
|
75
75
|
});
|
|
@@ -24,13 +24,17 @@ const util_1 = require("util");
|
|
|
24
24
|
exports.default = (details) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
25
|
var _a, _b;
|
|
26
26
|
const projectRoot = runtime_store_1.default.get('project.root');
|
|
27
|
-
const opts = ['-u', 'main.py'];
|
|
28
27
|
const targetSource = (_a = details.target) === null || _a === void 0 ? void 0 : _a.source;
|
|
29
28
|
const runtimesDir = constants_1.ENVPATH.runtimes.data;
|
|
29
|
+
const cwd = runtime_store_1.default.get('cwd');
|
|
30
30
|
const stackVersion = (_b = details.target.stack) === null || _b === void 0 ? void 0 : _b.replace('python_', '');
|
|
31
|
+
const opts = [
|
|
32
|
+
'-u',
|
|
33
|
+
(0, path_1.join)(runtimesDir, constants_1.RUNTIME.language.python.value, `zcatalyst_runtime_${stackVersion === null || stackVersion === void 0 ? void 0 : stackVersion.replace('_', '')}`, 'main.py')
|
|
34
|
+
];
|
|
31
35
|
return new Promise((res) => {
|
|
32
36
|
const child = (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), opts, {
|
|
33
|
-
cwd:
|
|
37
|
+
cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(cwd, (0, path_1.join)(cwd, constants_1.FOLDERNAME.build)),
|
|
34
38
|
stdio: 'pipe',
|
|
35
39
|
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_CODE_LOCATION: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)), X_ZOHO_CATALYST_SERVER_LISTEN_PORT: details.httpPort.toString(), CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
|
|
36
40
|
}).RAW();
|
|
@@ -174,7 +174,7 @@ function webClientServer(httpPort, source, { homepage = 'index.html', enableWatc
|
|
|
174
174
|
res.send('Error fetching the resource');
|
|
175
175
|
});
|
|
176
176
|
}));
|
|
177
|
-
const server = app.listen(httpPort).on('error', (err) => {
|
|
177
|
+
const server = app.listen(httpPort, '127.0.0.1').on('error', (err) => {
|
|
178
178
|
eventListener.emit('error', err);
|
|
179
179
|
});
|
|
180
180
|
const expressDestroyer = new server_js_1.ConnectionDestroyer(server);
|
|
@@ -28,10 +28,12 @@ const constants_1 = require("../../util_modules/constants");
|
|
|
28
28
|
const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
|
|
29
29
|
const fs_1 = require("../../util_modules/fs");
|
|
30
30
|
const js_1 = require("../../util_modules/js");
|
|
31
|
+
const userConfig_1 = __importDefault(require("../../userConfig"));
|
|
31
32
|
const logger_2 = require("../../util_modules/logger");
|
|
32
33
|
const project_2 = require("../../util_modules/project");
|
|
33
34
|
const shell_1 = require("../../util_modules/shell");
|
|
34
35
|
const request_1 = __importDefault(require("request"));
|
|
36
|
+
const ensure_java_userconfig_1 = require("../../fn-utils/lib/ensure-java-userconfig");
|
|
35
37
|
const option_1 = require("../../util_modules/option");
|
|
36
38
|
const server_1 = require("../../util_modules/server");
|
|
37
39
|
const logUrl = (name, pthName, httpPort, masterPort) => {
|
|
@@ -79,7 +81,7 @@ class HttpFunctions {
|
|
|
79
81
|
[constants_1.FN_TYPE.basic]: (0, path_1.normalize)((0, path_1.join)(__dirname, './invoker', constants_1.FN_TYPE.basic, 'node.mjs'))
|
|
80
82
|
};
|
|
81
83
|
this.javaInvoker = {
|
|
82
|
-
[constants_1.FN_TYPE.basic]: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst'
|
|
84
|
+
[constants_1.FN_TYPE.basic]: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst')
|
|
83
85
|
};
|
|
84
86
|
this.requestFile = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'user_req_body');
|
|
85
87
|
this.responseFile = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'user_res_body');
|
|
@@ -214,7 +216,10 @@ class HttpFunctions {
|
|
|
214
216
|
});
|
|
215
217
|
}
|
|
216
218
|
else if ((_b = fnTarget.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.java.value)) {
|
|
217
|
-
const
|
|
219
|
+
const invoker = fnTarget.type === constants_1.FN_TYPE.basic
|
|
220
|
+
? this.javaInvoker[fnTarget.type] + `/${fnTarget.stack}/JavabioInvoker`
|
|
221
|
+
: this.javaInvoker[fnTarget.type];
|
|
222
|
+
const javaInvokerDir = (0, path_1.parse)(invoker).dir;
|
|
218
223
|
slaveOptions.push('-cp');
|
|
219
224
|
slaveOptions.push(javaInvokerDir +
|
|
220
225
|
fn_utils_1.fnUtils.java.classPathSep +
|
|
@@ -225,7 +230,7 @@ class HttpFunctions {
|
|
|
225
230
|
debugPort +
|
|
226
231
|
',server=y,suspend=y');
|
|
227
232
|
}
|
|
228
|
-
slaveOptions.push((0, path_1.basename)(
|
|
233
|
+
slaveOptions.push((0, path_1.basename)(invoker));
|
|
229
234
|
slaveOptions.push(javaInvokerDir);
|
|
230
235
|
slaveOptions.push(JSON.stringify(fnTarget));
|
|
231
236
|
slaveOptions.push(query);
|
|
@@ -243,9 +248,13 @@ class HttpFunctions {
|
|
|
243
248
|
'x-zc-cookie': request.headers['x-zc-cookie'],
|
|
244
249
|
'x-zc-user-type': request.headers['x-zc-user-type']
|
|
245
250
|
}));
|
|
251
|
+
const configKey = `${fnTarget.stack}.bin`;
|
|
252
|
+
const userConfigCmd = userConfig_1.default.get(configKey);
|
|
253
|
+
const spawnCommand = (0, ensure_java_userconfig_1.getJavaSpawnCommand)(userConfigCmd, 'java', fnTarget.stack);
|
|
246
254
|
slave = this.q.push({
|
|
247
|
-
command:
|
|
255
|
+
command: spawnCommand,
|
|
248
256
|
options: slaveOptions,
|
|
257
|
+
target: fnTarget,
|
|
249
258
|
pth: (0, path_1.join)(runtime_store_1.default.get('project.root'), constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, fnTarget.name),
|
|
250
259
|
req: request,
|
|
251
260
|
id: fnTarget.name,
|
|
@@ -299,7 +308,11 @@ class HttpFunctions {
|
|
|
299
308
|
.forEach((t) => {
|
|
300
309
|
var _a;
|
|
301
310
|
if ((_a = t.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java.value)) {
|
|
302
|
-
|
|
311
|
+
const invoker = t.type === constants_1.FN_TYPE.basic
|
|
312
|
+
? this.javaInvoker[t.type] +
|
|
313
|
+
`/${t.stack}/JavabioInvoker`
|
|
314
|
+
: this.javaInvoker[t.type];
|
|
315
|
+
fn_utils_1.fnUtils.java.ensureJavaInvoker(invoker, (0, path_1.normalize)((0, path_1.join)(__dirname, './invoker', t.type, 'java', 'Java' + t.type + 'Invoker.java')), t);
|
|
303
316
|
}
|
|
304
317
|
const pthName = new url_1.URL(t.url).pathname;
|
|
305
318
|
if (pthName !== null) {
|
|
@@ -313,7 +326,7 @@ class HttpFunctions {
|
|
|
313
326
|
}
|
|
314
327
|
});
|
|
315
328
|
return new Promise((res) => {
|
|
316
|
-
const server = this.app.listen(httpPort, () => {
|
|
329
|
+
const server = this.app.listen(httpPort, '127.0.0.1', () => {
|
|
317
330
|
this.targets.forEach((target) => {
|
|
318
331
|
var _a, _b;
|
|
319
332
|
(_a = target.watcher) === null || _a === void 0 ? void 0 : _a.on('preparing', () => {
|
|
@@ -91,9 +91,8 @@ public class JavabioInvoker {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
private static void writeResponse(JSONObject responseJson, JSONObject metaJson, String invokerDir) throws Exception {
|
|
94
|
-
String responseFilePath = Paths.get(invokerDir, "user_res_body").toString();
|
|
95
|
-
String responseMeta = Paths.get(invokerDir, "user_meta.json").toString();
|
|
96
|
-
|
|
94
|
+
String responseFilePath = Paths.get(invokerDir, "../user_res_body").toString();
|
|
95
|
+
String responseMeta = Paths.get(invokerDir, "../user_meta.json").toString();
|
|
97
96
|
BufferedWriter responseWriter = new BufferedWriter(new FileWriter(responseFilePath));
|
|
98
97
|
String responseStr = responseJson.toString();
|
|
99
98
|
responseWriter.write(responseStr);
|
|
@@ -194,7 +193,7 @@ public class JavabioInvoker {
|
|
|
194
193
|
LogHandler handler = new JavabioInvoker().new LogHandler();
|
|
195
194
|
rootLogger.addHandler(handler);
|
|
196
195
|
|
|
197
|
-
Path requestFilePath = Paths.get(invokerDir, "user_req_body");
|
|
196
|
+
Path requestFilePath = Paths.get(invokerDir, "../user_req_body");
|
|
198
197
|
|
|
199
198
|
HashMap<String, Object> userBody = new HashMap<String, Object>();
|
|
200
199
|
|
|
@@ -222,8 +221,7 @@ public class JavabioInvoker {
|
|
|
222
221
|
HashMap<String, Object> target = jsonToMap(args[1]);
|
|
223
222
|
String fnExeName = (String) target.get("index");
|
|
224
223
|
String fnName = (String) target.get("name");
|
|
225
|
-
String fnExePath = Paths.get(invokerDir, "
|
|
226
|
-
|
|
224
|
+
String fnExePath = Paths.get(invokerDir, "../../", "functions", fnName).normalize().toString();
|
|
227
225
|
HashMap<String, Object> queryData = jsonToMap(args[2]);
|
|
228
226
|
HashMap<String, Object> projectData = jsonToMap(args[3]);
|
|
229
227
|
HashMap<String, Object> authData = jsonToMap(args[4]);
|
|
@@ -92,8 +92,7 @@ public class JavacronInvoker {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
private static void writeResponse(String response, String invokerDir) throws Exception {
|
|
95
|
-
String responseFilePath = Paths.get(invokerDir, "user_res_body").toString();
|
|
96
|
-
|
|
95
|
+
String responseFilePath = Paths.get(invokerDir, "../user_res_body").toString();
|
|
97
96
|
BufferedWriter responseWriter = new BufferedWriter(new FileWriter(responseFilePath));
|
|
98
97
|
responseWriter.write(response);
|
|
99
98
|
responseWriter.close();
|
|
@@ -168,7 +167,7 @@ public class JavacronInvoker {
|
|
|
168
167
|
LogHandler handler = new JavacronInvoker().new LogHandler();
|
|
169
168
|
rootLogger.addHandler(handler);
|
|
170
169
|
|
|
171
|
-
Path requestFilePath = Paths.get(invokerDir, "user_req_body");
|
|
170
|
+
Path requestFilePath = Paths.get(invokerDir, "../user_req_body");
|
|
172
171
|
|
|
173
172
|
HashMap<String, Object> userBody = new HashMap<String, Object>();
|
|
174
173
|
|
|
@@ -196,7 +195,7 @@ public class JavacronInvoker {
|
|
|
196
195
|
HashMap<String, Object> target = jsonToMap(args[1]);
|
|
197
196
|
String fnExeName = (String) target.get("index");
|
|
198
197
|
String fnName = (String) target.get("name");
|
|
199
|
-
String fnExePath = Paths.get(invokerDir, "
|
|
198
|
+
String fnExePath = Paths.get(invokerDir, "../../", "functions", fnName).normalize().toString();
|
|
200
199
|
|
|
201
200
|
HashMap<String, Object> queryData = jsonToMap(args[2]);
|
|
202
201
|
HashMap<String, Object> projectData = jsonToMap(args[3]);
|
|
@@ -92,7 +92,7 @@ public class JavaeventInvoker {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
private static void writeResponse(String response, String invokerDir) throws Exception {
|
|
95
|
-
String responseFilePath = Paths.get(invokerDir, "user_res_body").toString();
|
|
95
|
+
String responseFilePath = Paths.get(invokerDir, "../user_res_body").toString();
|
|
96
96
|
|
|
97
97
|
BufferedWriter responseWriter = new BufferedWriter(new FileWriter(responseFilePath));
|
|
98
98
|
responseWriter.write(response);
|
|
@@ -168,7 +168,7 @@ public class JavaeventInvoker {
|
|
|
168
168
|
LogHandler handler = new JavaeventInvoker().new LogHandler();
|
|
169
169
|
rootLogger.addHandler(handler);
|
|
170
170
|
|
|
171
|
-
Path requestFilePath = Paths.get(invokerDir, "user_req_body");
|
|
171
|
+
Path requestFilePath = Paths.get(invokerDir, "../user_req_body");
|
|
172
172
|
|
|
173
173
|
HashMap<String, Object> userBody = new HashMap<String, Object>();
|
|
174
174
|
|
|
@@ -196,12 +196,10 @@ public class JavaeventInvoker {
|
|
|
196
196
|
HashMap<String, Object> target = jsonToMap(args[1]);
|
|
197
197
|
String fnExeName = (String) target.get("index");
|
|
198
198
|
String fnName = (String) target.get("name");
|
|
199
|
-
String fnExePath = Paths.get(invokerDir, "
|
|
200
|
-
|
|
199
|
+
String fnExePath = Paths.get(invokerDir, "../../", "functions", fnName).normalize().toString();
|
|
201
200
|
HashMap<String, Object> queryData = jsonToMap(args[2]);
|
|
202
201
|
HashMap<String, Object> projectData = jsonToMap(args[3]);
|
|
203
202
|
HashMap<String, Object> authData = jsonToMap(args[4]);
|
|
204
|
-
|
|
205
203
|
File[] jarFiles = new File(fnExePath).listFiles(new FilenameFilter() {
|
|
206
204
|
@Override
|
|
207
205
|
public boolean accept(File dir, String name) {
|
|
@@ -89,7 +89,7 @@ public class JavaintegInvoker {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
private static void writeResponse(String responseString, String invokerDir) throws Exception {
|
|
92
|
-
String responseFilePath = Paths.get(invokerDir, "user_res_body").toString();
|
|
92
|
+
String responseFilePath = Paths.get(invokerDir, "../user_res_body").toString();
|
|
93
93
|
|
|
94
94
|
BufferedWriter responseWriter = new BufferedWriter(new FileWriter(responseFilePath));
|
|
95
95
|
responseWriter.write(responseString);
|
|
@@ -172,7 +172,7 @@ public class JavaintegInvoker {
|
|
|
172
172
|
HashMap<String, Object> target = jsonToMap(args[1]);
|
|
173
173
|
String fnExeName = (String) target.get("index");
|
|
174
174
|
String fnName = (String) target.get("name");
|
|
175
|
-
String fnExePath = Paths.get(invokerDir, "
|
|
175
|
+
String fnExePath = Paths.get(invokerDir, "../../", "functions", fnName).normalize().toString();
|
|
176
176
|
|
|
177
177
|
Path configJsonPath = Paths.get(fnExePath, "catalyst-config.json");
|
|
178
178
|
|
|
@@ -28,6 +28,7 @@ const logger_1 = require("../../util_modules/logger");
|
|
|
28
28
|
const project_1 = require("../../util_modules/project");
|
|
29
29
|
const shell_1 = require("../../util_modules/shell");
|
|
30
30
|
const http_functions_1 = require("../dependencies/http-functions");
|
|
31
|
+
const ensure_java_userconfig_1 = require("../../fn-utils/lib/ensure-java-userconfig");
|
|
31
32
|
class LocalFunction {
|
|
32
33
|
constructor(repl, target) {
|
|
33
34
|
var _a, _b, _c;
|
|
@@ -41,9 +42,9 @@ class LocalFunction {
|
|
|
41
42
|
this.slave = null;
|
|
42
43
|
this.nodeInvoker = (0, path_1.normalize)((0, path_1.join)(__dirname, './invoker', target.type, 'node.mjs'));
|
|
43
44
|
const projectRoot = runtime_store_1.default.get('project.root');
|
|
44
|
-
this.javaInvoker = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'Java' + target.type + 'Invoker');
|
|
45
|
+
this.javaInvoker = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', target.stack, 'Java' + target.type + 'Invoker');
|
|
45
46
|
if ((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java.value)) {
|
|
46
|
-
fn_utils_1.fnUtils.java.ensureJavaInvoker(this.javaInvoker, (0, path_1.normalize)((0, path_1.join)(__dirname, './invoker', target.type, 'java', 'Java' + target.type + 'Invoker.java')));
|
|
47
|
+
fn_utils_1.fnUtils.java.ensureJavaInvoker(this.javaInvoker, (0, path_1.normalize)((0, path_1.join)(__dirname, './invoker', target.type, 'java', 'Java' + target.type + 'Invoker.java')), target);
|
|
47
48
|
}
|
|
48
49
|
this.responseFile = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'user_res_body');
|
|
49
50
|
this.metaFile = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'user_meta.json');
|
|
@@ -146,7 +147,10 @@ class LocalFunction {
|
|
|
146
147
|
'x-zc-admin-cred-token': accessToken,
|
|
147
148
|
'x-zc-user-type': 'admin'
|
|
148
149
|
}));
|
|
149
|
-
|
|
150
|
+
const configKey = `${this.target.stack}.bin`;
|
|
151
|
+
const userConfigCmd = userConfig_1.default.get(configKey);
|
|
152
|
+
const spawnCommand = (0, ensure_java_userconfig_1.getJavaSpawnCommand)(userConfigCmd, 'java', this.target.stack);
|
|
153
|
+
this.slave = (0, shell_1.spawn)(spawnCommand, slaveOptions, {
|
|
150
154
|
cwd: (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, this.target.name),
|
|
151
155
|
stdio: 'pipe',
|
|
152
156
|
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, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, this.target.env_var)
|
|
@@ -52,9 +52,9 @@ exports.default = (targets) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
52
52
|
if (target.type === constants_1.FN_TYPE.advanced ||
|
|
53
53
|
target.type === constants_1.FN_TYPE.applogic ||
|
|
54
54
|
target.type === constants_1.FN_TYPE.browserLogic) {
|
|
55
|
-
const javaServer = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'aioserver', 'JavaaioServer');
|
|
55
|
+
const javaServer = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', target.stack, 'aioserver', 'JavaaioServer');
|
|
56
56
|
const javaInvoker = (0, path_1.join)(__dirname, '../../../serve/server/lib/java/aio_server/JavaaioServer.java');
|
|
57
|
-
(0, java_1.ensureJavaInvoker)(javaServer, javaInvoker);
|
|
57
|
+
(0, java_1.ensureJavaInvoker)(javaServer, javaInvoker, target);
|
|
58
58
|
const serverFiles = yield fs_1.ASYNC.walk((0, path_1.dirname)(javaServer));
|
|
59
59
|
yield Promise.all(serverFiles.map((file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
60
|
try {
|
package/lib/userConfig.js
CHANGED
|
@@ -9,7 +9,7 @@ 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'];
|
|
12
|
+
this.validKeys = ['python3_9.bin', 'java8.bin', 'java11.bin', 'java17.bin'];
|
|
13
13
|
this.configFilePath = path_1.default.join(constants_1.ENVPATH.userConfig.config, '.zcconfig');
|
|
14
14
|
this.config = fs_1.SYNC.readJSONFile(this.configFilePath, { checkpath: true }) || {};
|
|
15
15
|
}
|
|
@@ -163,7 +163,7 @@ exports.default = Object.freeze([
|
|
|
163
163
|
},
|
|
164
164
|
{
|
|
165
165
|
name: 'catalyst_default_get_folder',
|
|
166
|
-
source_endpoint: '/baas/v1/project/{projectId:[0-9]+}/folder/{folderId:([
|
|
166
|
+
source_endpoint: '/baas/v1/project/{projectId:[0-9]+}/folder/{folderId:([A-Za-z0-9_]+)}',
|
|
167
167
|
target_endpoint: '/baas/v1/project/{projectId}/folder/{folderId}',
|
|
168
168
|
method: 'GET',
|
|
169
169
|
authentication: undefined,
|
|
@@ -171,7 +171,7 @@ exports.default = Object.freeze([
|
|
|
171
171
|
},
|
|
172
172
|
{
|
|
173
173
|
name: 'catalyst_default_upload_file',
|
|
174
|
-
source_endpoint: '/baas/v1/project/{projectId:[0-9]+}/folder/{folderId:[
|
|
174
|
+
source_endpoint: '/baas/v1/project/{projectId:[0-9]+}/folder/{folderId:[A-Za-z0-9_]+}/file',
|
|
175
175
|
target_endpoint: '/baas/v1/project/{projectId}/folder/{folderId}/file',
|
|
176
176
|
method: 'POST',
|
|
177
177
|
authentication: undefined,
|
|
@@ -179,7 +179,7 @@ exports.default = Object.freeze([
|
|
|
179
179
|
},
|
|
180
180
|
{
|
|
181
181
|
name: 'catalyst_default_get_file',
|
|
182
|
-
source_endpoint: '/baas/v1/project/{projectId:[0-9]+}/folder/{folderId:[
|
|
182
|
+
source_endpoint: '/baas/v1/project/{projectId:[0-9]+}/folder/{folderId:[A-Za-z0-9_]+}/file/{fileId:[0-9]+}',
|
|
183
183
|
target_endpoint: '/baas/v1/project/{projectId}/folder/{folderId}/file/{fileId}',
|
|
184
184
|
method: 'GET',
|
|
185
185
|
authentication: undefined,
|
|
@@ -187,7 +187,7 @@ exports.default = Object.freeze([
|
|
|
187
187
|
},
|
|
188
188
|
{
|
|
189
189
|
name: 'catalyst_default_delete_file',
|
|
190
|
-
source_endpoint: '/baas/v1/project/{projectId:[0-9]+}/folder/{folderId:[
|
|
190
|
+
source_endpoint: '/baas/v1/project/{projectId:[0-9]+}/folder/{folderId:[A-Za-z0-9_]+}/file/{fileId:[0-9]+}',
|
|
191
191
|
target_endpoint: '/baas/v1/project/{projectId}/folder/{folderId}/file/{fileId}',
|
|
192
192
|
method: 'DELETE',
|
|
193
193
|
authentication: undefined,
|
|
@@ -195,7 +195,7 @@ exports.default = Object.freeze([
|
|
|
195
195
|
},
|
|
196
196
|
{
|
|
197
197
|
name: 'catalyst_default_download_file',
|
|
198
|
-
source_endpoint: '/baas/v1/project/{projectId:[0-9]+}/folder/{folderId:[
|
|
198
|
+
source_endpoint: '/baas/v1/project/{projectId:[0-9]+}/folder/{folderId:[A-Za-z0-9_]+}/file/{fileId:[0-9]+}/download',
|
|
199
199
|
target_endpoint: '/baas/v1/project/{projectId}/folder/{folderId}/file/{fileId}/download',
|
|
200
200
|
method: 'GET',
|
|
201
201
|
authentication: undefined,
|
|
@@ -47,7 +47,9 @@ exports.default = Object.freeze({
|
|
|
47
47
|
notification_web: 'ZohoCatalyst.notifications.web',
|
|
48
48
|
search_read: 'ZohoCatalyst.search.READ',
|
|
49
49
|
zia: 'ZohoCatalyst.mlkit.READ',
|
|
50
|
-
|
|
50
|
+
quick_ml: 'QuickML.deployment.READ',
|
|
51
|
+
pdf_shot: 'ZohoCatalyst.pdfshot.execute',
|
|
52
|
+
dataverse: 'ZohoCatalyst.dataverse.execute',
|
|
51
53
|
circuits_execute: 'ZohoCatalyst.circuits.execute',
|
|
52
54
|
circuits_exe_read: 'ZohoCatalyst.circuits.execution.READ',
|
|
53
55
|
circuits_exe_delete: 'ZohoCatalyst.circuits.execution.DELETE',
|