zcatalyst-cli 1.12.0 → 1.12.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/lib/authentication/login.js +10 -12
- package/lib/commands/client/delete.js +1 -1
- package/lib/commands/ds/status.js +5 -5
- package/lib/commands/functions/delete.js +2 -2
- package/lib/commands/iac/import.js +8 -4
- package/lib/fn-utils/lib/java.js +5 -3
- package/lib/init/features/functions/index.js +14 -5
- package/lib/prompt/index.js +1 -1
- package/lib/pull/features/functions/index.js +1 -1
- package/lib/serve/server/lib/java/JavaaioServer.java +3 -2
- package/lib/serve/server/lib/master.js +9 -23
- package/lib/serve/server/lib/web_client/server.js +6 -3
- package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +7 -1
- package/lib/shell/dependencies/invoker/bio/node.js +5 -2
- package/lib/util_modules/server.js +53 -0
- package/package.json +2 -2
- package/templates/init/functions/java/integ/cliq/com/handlers/BotHandler.java +21 -3
- package/templates/init/functions/node/integ/cliq/.DS_Store +0 -0
- package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +21 -5
- package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +3 -3
- package/templates/init/functions/node/integ/cliq/package.json +2 -1
- package/templates/init/functions/node/integ/cliq/sample.js +3 -1
|
@@ -13,7 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const ansi_colors_1 = require("ansi-colors");
|
|
16
|
-
const http_1 =
|
|
16
|
+
const http_1 = require("http");
|
|
17
|
+
const server_js_1 = require("../util_modules/server.js");
|
|
17
18
|
const open_1 = __importDefault(require("open"));
|
|
18
19
|
const path_1 = require("path");
|
|
19
20
|
const portfinder_1 = require("portfinder");
|
|
@@ -277,12 +278,10 @@ class Login {
|
|
|
277
278
|
const callbackUrl = this._getCallbackUrl(port);
|
|
278
279
|
const authUrl = this._getLoginUrl(callbackUrl);
|
|
279
280
|
let reqCount = 0;
|
|
280
|
-
const server = http_1.
|
|
281
|
+
const server = http_1.createServer((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
281
282
|
try {
|
|
282
283
|
let processReq = true;
|
|
283
|
-
if (reqCount + 1 > 1 ||
|
|
284
|
-
req.url === '/favicon.ico' ||
|
|
285
|
-
req.url === undefined) {
|
|
284
|
+
if (reqCount + 1 > 1 || req.url === '/favicon.ico' || req.url === undefined) {
|
|
286
285
|
logger_1.debug('unknown request received : ' + req.url);
|
|
287
286
|
processReq = false;
|
|
288
287
|
res.writeHead(404);
|
|
@@ -305,7 +304,7 @@ class Login {
|
|
|
305
304
|
defaultAns: true
|
|
306
305
|
}));
|
|
307
306
|
if (!ans.DC) {
|
|
308
|
-
|
|
307
|
+
yield destroyer.destroy(true).catch((err) => logger_1.debug(err));
|
|
309
308
|
reject(new error_1.default('Aborted by user.\n', {
|
|
310
309
|
exit: 1
|
|
311
310
|
}));
|
|
@@ -317,7 +316,8 @@ class Login {
|
|
|
317
316
|
js_1.JS.set(result, 'token', this.salt + '_' + result.refresh_token);
|
|
318
317
|
credential_1.default.oneTimeToken = result.access_token;
|
|
319
318
|
const userDetails = yield this._getUserDetails();
|
|
320
|
-
|
|
319
|
+
yield destroyer.destroy(true).catch((err) => logger_1.debug(err));
|
|
320
|
+
yield new Promise((res) => setTimeout(res, 2000));
|
|
321
321
|
resolve({
|
|
322
322
|
user: userDetails,
|
|
323
323
|
token: result,
|
|
@@ -327,23 +327,21 @@ class Login {
|
|
|
327
327
|
}
|
|
328
328
|
else if (processReq) {
|
|
329
329
|
yield this._respondWithFile(req, res, 400, '../../templates/loginFailure.html');
|
|
330
|
-
|
|
330
|
+
yield destroyer.destroy(true).catch((err) => logger_1.debug(err));
|
|
331
331
|
reject(new error_1.default("Credentials doesn't seem to be valid.\n", {
|
|
332
332
|
exit: 1
|
|
333
333
|
}));
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
catch (e) {
|
|
337
|
-
|
|
337
|
+
yield destroyer.destroy(true).catch((err) => logger_1.debug(err));
|
|
338
338
|
reject(new error_1.default('Server crashed with error.\n', {
|
|
339
339
|
exit: 2,
|
|
340
340
|
original: error_1.default.getErrorInstance(e)
|
|
341
341
|
}));
|
|
342
342
|
}
|
|
343
343
|
}));
|
|
344
|
-
|
|
345
|
-
socket.unref();
|
|
346
|
-
});
|
|
344
|
+
const destroyer = new server_js_1.ConnectionDestroyer(server);
|
|
347
345
|
server.listen(port, () => {
|
|
348
346
|
logger_1.info();
|
|
349
347
|
logger_1.info('Visit this URL on this device to log in:');
|
|
@@ -154,7 +154,7 @@ exports.default = new command_1.default('client:delete [client_version]')
|
|
|
154
154
|
}
|
|
155
155
|
historyArr = [ipVersion];
|
|
156
156
|
}
|
|
157
|
-
choicesArray.push(prompt_1.default.
|
|
157
|
+
choicesArray.push(prompt_1.default.separator('-------REMOTE-------'));
|
|
158
158
|
js_1.JS.forEach(historyArr, (history) => {
|
|
159
159
|
const version = js_1.JS.get(history, 'status', false)
|
|
160
160
|
? `${history.app_version} (${ansi_colors_1.cyan('live')})`
|
|
@@ -123,7 +123,7 @@ const spinnerFn = (jobId, dsReport, cumulativeStatus, throbber, spinner, bulkApi
|
|
|
123
123
|
text: getSpinnerTxt(reportTable, dsReport)
|
|
124
124
|
});
|
|
125
125
|
needIteration = false;
|
|
126
|
-
resolve();
|
|
126
|
+
resolve(dsReport);
|
|
127
127
|
break;
|
|
128
128
|
case 'Failed':
|
|
129
129
|
reportTable.unshift([
|
|
@@ -137,7 +137,7 @@ const spinnerFn = (jobId, dsReport, cumulativeStatus, throbber, spinner, bulkApi
|
|
|
137
137
|
text: getSpinnerTxt(reportTable, dsReport)
|
|
138
138
|
});
|
|
139
139
|
needIteration = false;
|
|
140
|
-
resolve();
|
|
140
|
+
resolve(dsReport);
|
|
141
141
|
break;
|
|
142
142
|
default:
|
|
143
143
|
needIteration = false;
|
|
@@ -231,13 +231,13 @@ exports.default = new command_1.default('ds:status <operation> [jobid]')
|
|
|
231
231
|
const spinner = 'DS bulk ' + operation;
|
|
232
232
|
const throbber = throbber_1.default.getInstance();
|
|
233
233
|
throbber.add(spinner);
|
|
234
|
-
yield new Promise(spinnerFn(jobId, dsReport, cumulativeStatus, throbber, spinner, bulkApi, displayOpr, action));
|
|
235
|
-
if (
|
|
234
|
+
const finalDsReport = yield new Promise(spinnerFn(jobId, dsReport, cumulativeStatus, throbber, spinner, bulkApi, displayOpr, action));
|
|
235
|
+
if (finalDsReport.results && finalDsReport.results.download_url) {
|
|
236
236
|
const ans = yield prompt_1.default.ask(prompt_1.default.question('download', 'Do you like to download the report of this job to your cmd execution directory?', { type: 'confirm', defaultAns: false }));
|
|
237
237
|
if (ans.download) {
|
|
238
238
|
const hrTime = process.hrtime();
|
|
239
239
|
const fileName = `${displayOpr}_${jobId}_${hrTime[0] * 1000000000 + hrTime[1]}.zip`;
|
|
240
|
-
const bulkReport = (yield bulkApi.downloadReport(
|
|
240
|
+
const bulkReport = (yield bulkApi.downloadReport(finalDsReport.results.download_url, fileName));
|
|
241
241
|
return fs_1.ASYNC.writeFile(path_1.join(process.cwd(), fileName), bulkReport);
|
|
242
242
|
}
|
|
243
243
|
}
|
|
@@ -116,7 +116,7 @@ exports.default = new command_1.default('functions:delete [function_name_or_id]'
|
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
118
|
if (localChoices.length > 0) {
|
|
119
|
-
localChoices.unshift(prompt_1.default.
|
|
119
|
+
localChoices.unshift(prompt_1.default.separator('-------LOCAL-------'));
|
|
120
120
|
}
|
|
121
121
|
choiceArr.push(...localChoices);
|
|
122
122
|
}
|
|
@@ -165,7 +165,7 @@ exports.default = new command_1.default('functions:delete [function_name_or_id]'
|
|
|
165
165
|
});
|
|
166
166
|
});
|
|
167
167
|
if (remoteChoices.length > 0) {
|
|
168
|
-
remoteChoices.unshift(prompt_1.default.
|
|
168
|
+
remoteChoices.unshift(prompt_1.default.separator('-------REMOTE------'));
|
|
169
169
|
}
|
|
170
170
|
choiceArr.push(...remoteChoices);
|
|
171
171
|
}
|
|
@@ -53,6 +53,7 @@ const js_1 = require("../../util_modules/js");
|
|
|
53
53
|
const logger_1 = require("../../util_modules/logger");
|
|
54
54
|
const option_1 = require("../../util_modules/option");
|
|
55
55
|
const shell_1 = require("../../util_modules/shell");
|
|
56
|
+
const server_js_1 = require("../../util_modules/server.js");
|
|
56
57
|
const getZipAndTemplate = (filePath, stagedDeploy) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
58
|
const zipFile = filePath
|
|
58
59
|
? yield ASYNC.readFile(utils_js_1.untildify(filePath), 'buffer')
|
|
@@ -89,15 +90,18 @@ const ensureUserAction = (deployRes) => __awaiter(void 0, void 0, void 0, functi
|
|
|
89
90
|
const htmlFile = yield ASYNC.readFile(path_1.join(__dirname, '../../../templates/iacSuccess.html'));
|
|
90
91
|
resp.setHeader('Content-Type', 'text/html');
|
|
91
92
|
resp.writeHead(200);
|
|
92
|
-
resp.end(htmlFile, () => {
|
|
93
|
+
resp.end(htmlFile, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
94
|
req.socket.destroy();
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
yield destroyer.destroy().catch((err) => logger_1.debug(err));
|
|
96
|
+
res();
|
|
97
|
+
}));
|
|
96
98
|
}
|
|
97
99
|
catch (e) {
|
|
98
|
-
|
|
100
|
+
yield destroyer.destroy().catch((err) => logger_1.debug(err));
|
|
101
|
+
res(e);
|
|
99
102
|
}
|
|
100
103
|
}));
|
|
104
|
+
const destroyer = new server_js_1.ConnectionDestroyer(server);
|
|
101
105
|
server.listen(callbackPort, () => {
|
|
102
106
|
const urlString = accessUrl.toString();
|
|
103
107
|
logger_1.info();
|
package/lib/fn-utils/lib/java.js
CHANGED
|
@@ -192,16 +192,17 @@ function normaliseClasspath(pth, libFolder) {
|
|
|
192
192
|
}
|
|
193
193
|
exports.normaliseClasspath = normaliseClasspath;
|
|
194
194
|
function compileTarget(target) {
|
|
195
|
+
var _a;
|
|
195
196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
196
197
|
const targetSource = target.source;
|
|
197
198
|
const outputFolder = path_1.join(targetSource, '.output');
|
|
198
199
|
const integ = target.integ_config;
|
|
199
|
-
const entries = [path_1.join(targetSource, target.index + '.java')];
|
|
200
|
+
const entries = [path_1.join(targetSource, ((_a = target.index) === null || _a === void 0 ? void 0 : _a.replace(/\./g, path_1.sep)) + '.java')];
|
|
200
201
|
if (integ && integ.length > 0) {
|
|
201
202
|
integ.forEach((integConf) => {
|
|
202
203
|
const handlers = integConf.handlers;
|
|
203
204
|
Object.keys(handlers).forEach((handler) => {
|
|
204
|
-
entries.push(path_1.join(targetSource, handlers[handler].replace(
|
|
205
|
+
entries.push(path_1.join(targetSource, handlers[handler].replace(/\./g, path_1.sep) + '.java'));
|
|
205
206
|
});
|
|
206
207
|
});
|
|
207
208
|
}
|
|
@@ -338,6 +339,7 @@ function checkJavaCompatibility() {
|
|
|
338
339
|
});
|
|
339
340
|
}
|
|
340
341
|
function validate(targets, idx) {
|
|
342
|
+
var _a;
|
|
341
343
|
return __awaiter(this, void 0, void 0, function* () {
|
|
342
344
|
if (targets.length < idx + 1) {
|
|
343
345
|
return;
|
|
@@ -348,7 +350,7 @@ function validate(targets, idx) {
|
|
|
348
350
|
const classpath = path_1.join(targetSource, constants_1.FILENAME.functions.java_classpath);
|
|
349
351
|
const projectPath = path_1.join(targetSource, constants_1.FILENAME.functions.java_project);
|
|
350
352
|
const libFolder = path_1.join(targetSource, 'lib');
|
|
351
|
-
const entry = path_1.join(targetSource, currentTarget.index + '.java');
|
|
353
|
+
const entry = path_1.join(targetSource, ((_a = currentTarget.index) === null || _a === void 0 ? void 0 : _a.replace(/\./g, path_1.sep)) + '.java');
|
|
352
354
|
const entryFileExists = yield fs_1.ASYNC.fileExists(entry);
|
|
353
355
|
const classPathExists = yield fs_1.ASYNC.fileExists(classpath);
|
|
354
356
|
if (!entryFileExists) {
|
|
@@ -85,7 +85,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
85
85
|
logger_1.debug('Language cannot be identified hence skipping');
|
|
86
86
|
return acc;
|
|
87
87
|
}
|
|
88
|
-
const
|
|
88
|
+
const runtimeLang = langArr[0];
|
|
89
|
+
const langFn = languages_1.default[runtimeLang];
|
|
89
90
|
let displayValue = value;
|
|
90
91
|
let disabled = false;
|
|
91
92
|
if (runtimeDetails.eol_runtimes && runtimeDetails.eol_runtimes[value]) {
|
|
@@ -106,14 +107,22 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
106
107
|
return acc;
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
|
-
acc.
|
|
110
|
+
if (acc[runtimeLang].length === 0) {
|
|
111
|
+
const sep = {
|
|
112
|
+
node: '---NodeJS---',
|
|
113
|
+
java: '----Java----'
|
|
114
|
+
};
|
|
115
|
+
acc[runtimeLang].push(prompt_1.default.separator(sep[runtimeLang]));
|
|
116
|
+
}
|
|
117
|
+
acc[runtimeLang].push(prompt_1.default.choice(displayValue, { value: langFn(value), short: value, disabled }));
|
|
110
118
|
return acc;
|
|
111
|
-
}, []);
|
|
119
|
+
}, { node: [], java: [] });
|
|
120
|
+
const runtimeChoicesArr = [...runtimeChoices.java, ...runtimeChoices.node];
|
|
112
121
|
const runtimeAns = yield prompt_1.default.ask(prompt_1.default.question('runtime', 'Which runtime do you prefer to write your function?', {
|
|
113
122
|
type: 'list',
|
|
114
|
-
choices:
|
|
123
|
+
choices: runtimeChoicesArr,
|
|
115
124
|
when: () => {
|
|
116
|
-
return
|
|
125
|
+
return runtimeChoicesArr.length > 1;
|
|
117
126
|
}
|
|
118
127
|
}));
|
|
119
128
|
if (runtimeAns === undefined || runtimeAns.runtime === undefined) {
|
package/lib/prompt/index.js
CHANGED
|
@@ -57,7 +57,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
57
57
|
return accumulator;
|
|
58
58
|
}, {});
|
|
59
59
|
const choicesArr = js_1.JS.transform(choicesObj, (result, value, key) => {
|
|
60
|
-
result.push(prompt_1.default.
|
|
60
|
+
result.push(prompt_1.default.separator('----' + key + '----'));
|
|
61
61
|
result.push(...value);
|
|
62
62
|
return result;
|
|
63
63
|
}, []);
|
|
@@ -67,11 +67,12 @@ public class JavaaioServer extends DefaultCoreServer {
|
|
|
67
67
|
LogManager manager = LogManager.getLogManager();
|
|
68
68
|
manager.reset();
|
|
69
69
|
Logger rootLogger = manager.getLogger("");
|
|
70
|
-
|
|
70
|
+
JavaaioServer aioServer = new JavaaioServer();
|
|
71
|
+
LogHandler handler = aioServer.new LogHandler();
|
|
71
72
|
rootLogger.addHandler(handler);
|
|
72
73
|
|
|
73
74
|
port = Integer.parseInt(args[0]);
|
|
74
|
-
|
|
75
|
+
aioServer.start();
|
|
75
76
|
}
|
|
76
77
|
catch (Exception e) {
|
|
77
78
|
System.out.println(getStackTraceAsString(e));
|
|
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const express_1 = __importDefault(require("express"));
|
|
16
|
-
const http_proxy_1 = require("http-proxy");
|
|
17
16
|
const error_1 = __importDefault(require("../../../error"));
|
|
18
17
|
const apig_matcher_1 = __importDefault(require("../../../express_middlewares/apig-matcher"));
|
|
19
18
|
const auth_checker_1 = __importDefault(require("../../../express_middlewares/auth-checker"));
|
|
@@ -30,6 +29,8 @@ const js_1 = require("../../../util_modules/js");
|
|
|
30
29
|
const logger_2 = require("../../../util_modules/logger");
|
|
31
30
|
const project_2 = require("../../../util_modules/project");
|
|
32
31
|
const option_1 = require("../../../util_modules/option");
|
|
32
|
+
const server_js_1 = require("../../../util_modules/server.js");
|
|
33
|
+
const http_proxy_1 = require("http-proxy");
|
|
33
34
|
const removeSecure = (str) => str.replace(/;\s?Secure/i, '').replace(/;\s?SameSite=None/i, '');
|
|
34
35
|
const redirectByAuth = (req, res, redirectUrl) => {
|
|
35
36
|
if (req.headers['x-zc-user-cred-token'] === undefined) {
|
|
@@ -94,7 +95,6 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
94
95
|
const rules = runtime_store_1.default.get('context.apig.local.config', -1);
|
|
95
96
|
const customProxyUrl = option_1.getOptionValue('proxy');
|
|
96
97
|
const app = express_1.default();
|
|
97
|
-
const connections = {};
|
|
98
98
|
let systemRoutes;
|
|
99
99
|
app.use(logger_1.default);
|
|
100
100
|
app.use(cookie_parser_1.default);
|
|
@@ -130,14 +130,8 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
130
130
|
console.error(err);
|
|
131
131
|
})
|
|
132
132
|
.on('proxyRes', proxyResponseHandler(systemRoutes))
|
|
133
|
-
.on('proxyReq', (proxyReq) => {
|
|
134
|
-
const id = js_1.JS.randomNumber(4) + '';
|
|
135
|
-
connections[id] = proxyReq;
|
|
136
|
-
proxyReq.on('finish', () => {
|
|
137
|
-
delete connections[id];
|
|
138
|
-
});
|
|
139
|
-
})
|
|
140
133
|
.on('close', () => logger_2.debug('proxy closed'));
|
|
134
|
+
const proxyDestroyer = new server_js_1.ConnectionDestroyer(proxy);
|
|
141
135
|
otherServerDetails.forEach((serverDetail) => {
|
|
142
136
|
var _a, _b, _c, _d, _e, _f;
|
|
143
137
|
switch (serverDetail.type) {
|
|
@@ -222,25 +216,17 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
222
216
|
app.use(error_handler_1.default);
|
|
223
217
|
const expressServer = app.listen(listenPort).on('error', (err) => {
|
|
224
218
|
if (proxy) {
|
|
225
|
-
|
|
219
|
+
proxyDestroyer.destroy();
|
|
226
220
|
}
|
|
227
221
|
console.error(err);
|
|
228
222
|
});
|
|
223
|
+
const expressDestroyer = new server_js_1.ConnectionDestroyer(expressServer);
|
|
229
224
|
expressServer.maxConnections = 100;
|
|
230
|
-
process.on('SIGINT', () =>
|
|
231
|
-
|
|
232
|
-
}));
|
|
233
|
-
expressServer.on('connection', (socket) => {
|
|
234
|
-
const id = js_1.JS.randomNumber(4) + '';
|
|
235
|
-
connections[id] = socket;
|
|
236
|
-
socket.on('close', () => {
|
|
237
|
-
delete connections[id];
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
expressServer.on('close', () => {
|
|
225
|
+
process.on('SIGINT', () => expressDestroyer.destroy(false));
|
|
226
|
+
expressServer.on('close', () => __awaiter(this, void 0, void 0, function* () {
|
|
241
227
|
logger_2.info('Shutting down server');
|
|
242
|
-
|
|
243
|
-
});
|
|
228
|
+
yield proxyDestroyer.destroy().catch((err) => logger_2.debug(err));
|
|
229
|
+
}));
|
|
244
230
|
expressServer.on('upgrade', (...upgradeParam) => {
|
|
245
231
|
app.emit('upgrade', ...upgradeParam);
|
|
246
232
|
});
|
|
@@ -23,6 +23,7 @@ const path_1 = require("path");
|
|
|
23
23
|
const ws_1 = require("ws");
|
|
24
24
|
const port_resolver_js_1 = __importDefault(require("../../../../port-resolver.js"));
|
|
25
25
|
const ansi_colors_1 = require("ansi-colors");
|
|
26
|
+
const server_js_1 = require("../../../../util_modules/server.js");
|
|
26
27
|
function prepareScriptFile(dir, port) {
|
|
27
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
29
|
const scriptFile = yield index_js_2.ASYNC.readFile(index_js_1.TEMPLATE.client.basic.socket);
|
|
@@ -157,14 +158,16 @@ function webClientServer(httpPort, source, homepage, enableWatch) {
|
|
|
157
158
|
const server = app.listen(httpPort).on('error', (err) => {
|
|
158
159
|
eventListener.emit('error', err);
|
|
159
160
|
});
|
|
161
|
+
const expressDestroyer = new server_js_1.ConnectionDestroyer(server);
|
|
160
162
|
eventListener.on('error', (err) => {
|
|
161
163
|
logger_js_1.error('Error when serving the web-client: ' + err.message);
|
|
162
164
|
logger_js_1.info('Please exit the command to get more info');
|
|
163
165
|
eventListener.emit('close');
|
|
164
166
|
});
|
|
165
|
-
eventListener.on('close', () => {
|
|
166
|
-
|
|
167
|
-
|
|
167
|
+
eventListener.on('close', () => __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
yield expressDestroyer.destroy();
|
|
169
|
+
logger_js_1.debug('client server closed');
|
|
170
|
+
}));
|
|
168
171
|
return new Promise((res) => server.on('listening', () => res(eventListener)));
|
|
169
172
|
});
|
|
170
173
|
}
|
|
@@ -94,10 +94,16 @@ public class JavabioInvoker {
|
|
|
94
94
|
String responseMeta = Paths.get(invokerDir, "user_meta.json").toString();
|
|
95
95
|
|
|
96
96
|
BufferedWriter responseWriter = new BufferedWriter(new FileWriter(responseFilePath));
|
|
97
|
-
|
|
97
|
+
String responseStr = responseJson.toString();
|
|
98
|
+
responseWriter.write(responseStr);
|
|
98
99
|
responseWriter.close();
|
|
99
100
|
|
|
100
101
|
BufferedWriter metaWriter = new BufferedWriter(new FileWriter(responseMeta));
|
|
102
|
+
|
|
103
|
+
JSONObject metaResp = ((JSONObject) metaJson.get("response"));
|
|
104
|
+
metaResp.put("Content-Type", "application/json");
|
|
105
|
+
metaResp.put("Content-Length", responseStr.length());
|
|
106
|
+
|
|
101
107
|
metaWriter.write(metaJson.toString());
|
|
102
108
|
metaWriter.close();
|
|
103
109
|
}
|
|
@@ -11,8 +11,11 @@ const buildDir = JSON.parse(args[4]);
|
|
|
11
11
|
const requestFile = path.join(buildDir, '.catalyst', 'user_req_body');
|
|
12
12
|
const responseFile = path.join(buildDir, '.catalyst', 'user_res_body');
|
|
13
13
|
const metaFile = path.join(buildDir, '.catalyst', 'user_meta.json');
|
|
14
|
-
const writeToFile = (
|
|
15
|
-
|
|
14
|
+
const writeToFile = (respJson, metaJson) => {
|
|
15
|
+
const respStr = JSON.stringify(respJson);
|
|
16
|
+
fs.writeFileSync(responseFile, respStr);
|
|
17
|
+
metaJson.response['Content-Type'] = 'application/json';
|
|
18
|
+
metaJson.response['Content-Length'] = respStr.length;
|
|
16
19
|
fs.writeFileSync(metaFile, JSON.stringify(metaJson));
|
|
17
20
|
};
|
|
18
21
|
let body = {};
|
|
@@ -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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ConnectionDestroyer = void 0;
|
|
16
|
+
const http_proxy_1 = __importDefault(require("http-proxy"));
|
|
17
|
+
class ConnectionDestroyer {
|
|
18
|
+
constructor(server) {
|
|
19
|
+
this.server = server;
|
|
20
|
+
this.connections = new Set();
|
|
21
|
+
if (this.server instanceof http_proxy_1.default) {
|
|
22
|
+
this.server.on('proxyReq', (req) => {
|
|
23
|
+
req.on('finish', () => this.connections.delete(req));
|
|
24
|
+
this.connections.add(req);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.server.on('connection', (sock) => {
|
|
29
|
+
sock.on('close', () => this.connections.delete(sock));
|
|
30
|
+
this.connections.add(sock);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
destroy(terminate = true, err) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
this.connections.forEach((sock) => {
|
|
38
|
+
sock.destroy(err);
|
|
39
|
+
});
|
|
40
|
+
if (terminate) {
|
|
41
|
+
if (this.server instanceof http_proxy_1.default) {
|
|
42
|
+
return this.server.close(() => resolve());
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return this.server.close((err) => err instanceof Error ? reject(err) : resolve());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
resolve();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.ConnectionDestroyer = ConnectionDestroyer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zcatalyst-cli",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"description": "Command Line Tool for CATALYST",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@types/jest": "^26.0.24",
|
|
71
71
|
"@types/lodash": "^4.14.172",
|
|
72
72
|
"@types/minimatch": "^3.0.5",
|
|
73
|
-
"@types/node": "^16.
|
|
73
|
+
"@types/node": "^16.11.21",
|
|
74
74
|
"@types/request": "^2.48.7",
|
|
75
75
|
"@types/semver": "^7.3.8",
|
|
76
76
|
"@types/update-notifier": "^5.1.0",
|
|
@@ -31,6 +31,7 @@ import com.zc.cliq.requests.BotParticipationHandlerRequest;
|
|
|
31
31
|
import com.zc.cliq.requests.BotWebhookHandlerRequest;
|
|
32
32
|
import com.zc.cliq.requests.BotWelcomeHandlerRequest;
|
|
33
33
|
import com.zc.cliq.util.ZCCliqUtil;
|
|
34
|
+
import com.zc.component.cache.ZCCache;
|
|
34
35
|
|
|
35
36
|
public class BotHandler implements com.zc.cliq.interfaces.BotHandler {
|
|
36
37
|
Logger LOGGER = Logger.getLogger(BotHandler.class.getName());
|
|
@@ -82,7 +83,13 @@ public class BotHandler implements com.zc.cliq.interfaces.BotHandler {
|
|
|
82
83
|
param2.addSuggestion("IT");
|
|
83
84
|
param2.addSuggestion("MECH");
|
|
84
85
|
|
|
85
|
-
|
|
86
|
+
BotContextParam param3 = BotContextParam.getInstance();
|
|
87
|
+
param3.setName("cache");
|
|
88
|
+
param3.setQuestion("Do you wish to put this detail in Catalyst Cache ?");
|
|
89
|
+
param3.addSuggestion("YES");
|
|
90
|
+
param3.addSuggestion("NO");
|
|
91
|
+
|
|
92
|
+
context.setParams(param1, param2, param3);
|
|
86
93
|
resp.put("context", context);
|
|
87
94
|
} else if (message.equalsIgnoreCase("button")) {
|
|
88
95
|
|
|
@@ -117,8 +124,19 @@ public class BotHandler implements com.zc.cliq.interfaces.BotHandler {
|
|
|
117
124
|
if (req.getContextId().equals("personal_details")) {
|
|
118
125
|
Map<String, String> answers = req.getAnswers();
|
|
119
126
|
StringBuilder str = new StringBuilder();
|
|
120
|
-
str.append("Name
|
|
121
|
-
str.append("Department
|
|
127
|
+
str.append("*Name*: ").append(answers.get("name")).append("\n");
|
|
128
|
+
str.append("*Department*: ").append(answers.get("dept")).append("\n");
|
|
129
|
+
|
|
130
|
+
if(answers.get("cache").equals("YES")) {
|
|
131
|
+
try {
|
|
132
|
+
ZCCache cache = ZCCache.getInstance();
|
|
133
|
+
cache.putCacheValue("Name", answers.get("name"), 1L);
|
|
134
|
+
cache.putCacheValue("Department", answers.get("dept"), 1L);
|
|
135
|
+
str.append("This data is now available in Catalyst Cache's default segment.");
|
|
136
|
+
} catch(Exception ex) {
|
|
137
|
+
System.out.print("Error putting the value to cache: " + ex.toString());
|
|
138
|
+
}
|
|
139
|
+
}
|
|
122
140
|
|
|
123
141
|
resp.put("text", "Nice ! I have collected your info: \n" + str.toString());
|
|
124
142
|
}
|
|
Binary file
|
|
@@ -46,8 +46,14 @@ botHandler.messageHandler(async (req, res) => {
|
|
|
46
46
|
param2.addSuggestion('CSE');
|
|
47
47
|
param2.addSuggestion('IT');
|
|
48
48
|
param2.addSuggestion('MECH');
|
|
49
|
+
|
|
50
|
+
const param3 = context.newParam();
|
|
51
|
+
param3.name = 'cache';
|
|
52
|
+
param3.question = "Do you wish to put this detail in Catalyst Cache ?"
|
|
53
|
+
param3.addSuggestion('YES');
|
|
54
|
+
param3.addSuggestion('NO');
|
|
49
55
|
|
|
50
|
-
context.addParams(param1, param2);
|
|
56
|
+
context.addParams(param1, param2, param3);
|
|
51
57
|
res.context = context;
|
|
52
58
|
}
|
|
53
59
|
else if (comp(msg, 'button')) {
|
|
@@ -77,13 +83,23 @@ botHandler.messageHandler(async (req, res) => {
|
|
|
77
83
|
}
|
|
78
84
|
});
|
|
79
85
|
|
|
80
|
-
botHandler.contextHandler(async (req, res) => {
|
|
86
|
+
botHandler.contextHandler(async (req, res, app) => {
|
|
81
87
|
if(req.context_id === 'personal_details') {
|
|
82
88
|
const answer = req.answers;
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
let text = `Nice! I have collected your info: \n*Name*: ${answer.name.text} \n*Department*: ${answer.dept.text}`
|
|
90
|
+
|
|
91
|
+
if(answer.cache.text === 'YES') {
|
|
92
|
+
try {
|
|
93
|
+
const segment = app.cache().segment();
|
|
94
|
+
await segment.put('Name', answer.name.text);
|
|
95
|
+
await segment.put('Department', answer.dept.text);
|
|
96
|
+
text += '\nThis data is now available in Catalyst Cache\'s default segment.'
|
|
97
|
+
} catch(err) {
|
|
98
|
+
console.error('Error putting value in cache', err);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
85
101
|
|
|
86
|
-
res.setText(
|
|
102
|
+
res.setText(text);
|
|
87
103
|
}
|
|
88
104
|
return res;
|
|
89
105
|
});
|
|
@@ -36,17 +36,17 @@ command.executionHandler(async (req, res) => {
|
|
|
36
36
|
|
|
37
37
|
command.suggestionHandler(async (req, res) => {
|
|
38
38
|
if(comp(req.name,'catalystresource')) {
|
|
39
|
-
const suggestion1 = command.
|
|
39
|
+
const suggestion1 = command.newCommandSuggestion();
|
|
40
40
|
suggestion1.title = 'API doc';
|
|
41
41
|
suggestion1.description = 'Catalyst API documentation';
|
|
42
42
|
suggestion1.imageurl = 'https://www.zohowebstatic.com/sites/default/files/styles/product-home-page/public/catalyst-icon.png';
|
|
43
43
|
|
|
44
|
-
const suggestion2 = command.
|
|
44
|
+
const suggestion2 = command.newCommandSuggestion();
|
|
45
45
|
suggestion2.title = 'CLI doc';
|
|
46
46
|
suggestion2.description = 'Catalyst CLI documentation';
|
|
47
47
|
suggestion2.imageurl = 'https://www.zohowebstatic.com/sites/default/files/styles/product-home-page/public/catalyst-icon.png';
|
|
48
48
|
|
|
49
|
-
const suggestion3 = command.
|
|
49
|
+
const suggestion3 = command.newCommandSuggestion();
|
|
50
50
|
suggestion3.title = 'Help docs';
|
|
51
51
|
suggestion3.description = 'Catalyst help documentation';
|
|
52
52
|
suggestion3.imageurl = 'https://www.zohowebstatic.com/sites/default/files/styles/product-home-page/public/catalyst-icon.png';
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const Cliq = require('zcatalyst-integ-cliq');
|
|
3
|
+
const catalyst = require('zcatalyst-sdk-node');
|
|
3
4
|
|
|
4
5
|
module.exports = async (request, response) => {
|
|
5
6
|
try {
|
|
6
|
-
const
|
|
7
|
+
const app = catalyst.initialize(request);
|
|
8
|
+
const handlerResponse = await Cliq.default(request, app);
|
|
7
9
|
response.end(handlerResponse);
|
|
8
10
|
} catch (err) {
|
|
9
11
|
console.log('Error while executing handler. ', err);
|