zcatalyst-cli 1.13.3 → 1.14.0
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/docs/client-utils.toml +6 -1
- package/docs/commands/ds/import.toml +5 -0
- package/docs/fn-utils/lib/python.toml +4 -0
- package/docs/init/dependencies/python/ensure-python.toml +12 -0
- package/docs/init/dependencies/python/pip-install.toml +4 -0
- package/docs/serve/index.toml +5 -0
- package/lib/authentication/login.js +2 -1
- package/lib/cli_table/index.js +26 -2
- package/lib/cli_table/src/cell.js +359 -267
- package/lib/cli_table/src/layout-manager.js +231 -209
- package/lib/cli_table/src/table.js +76 -60
- package/lib/cli_table/src/utils.js +259 -224
- package/lib/client-utils.js +18 -4
- package/lib/command_needs/rc.js +57 -8
- package/lib/commands/config/delete.js +23 -0
- package/lib/commands/config/get.js +23 -0
- package/lib/commands/config/list.js +23 -0
- package/lib/commands/config/set.js +29 -0
- package/lib/commands/console/cache.js +31 -1
- package/lib/commands/console/queue.js +31 -1
- package/lib/commands/console/zcql.js +27 -1
- package/lib/commands/ds/export.js +2 -2
- package/lib/commands/ds/import.js +25 -5
- package/lib/commands/ds/status.js +2 -2
- package/lib/commands/iac/export.js +1 -1
- package/lib/commands/iac/import.js +1 -1
- package/lib/commands/iac/pack.js +16 -5
- package/lib/commands/iac/status.js +1 -1
- package/lib/commands/index.js +4 -0
- package/lib/commands/project/list.js +1 -1
- package/lib/commands/project/use.js +1 -1
- package/lib/deploy/features/client.js +2 -2
- package/lib/deploy/features/functions/index.js +13 -3
- package/lib/deploy/features/functions/languages/index.js +19 -2
- package/lib/endpoints/index.js +12 -5
- package/lib/endpoints/lib/env.js +5 -2
- package/lib/endpoints/lib/functions.js +30 -0
- package/lib/endpoints/lib/org.js +35 -0
- package/lib/endpoints/lib/project.js +7 -3
- package/lib/express_middlewares/unknownReqProxy.js +4 -1
- package/lib/fn-utils/index.js +2 -0
- package/lib/fn-utils/lib/common.js +68 -7
- package/lib/fn-utils/lib/integ.js +15 -11
- package/lib/fn-utils/lib/java.js +7 -3
- package/lib/fn-utils/lib/python.js +121 -0
- package/lib/fn-watcher.js +10 -2
- package/lib/index.js +2 -1
- package/lib/init/dependencies/python/ensure-python.js +151 -0
- package/lib/init/dependencies/python/pip-install.js +175 -0
- package/lib/init/features/functions/index.js +50 -29
- package/lib/init/features/functions/languages/index.js +3 -1
- package/lib/init/features/functions/languages/python.js +115 -0
- package/lib/init/features/index.js +2 -2
- package/lib/init/features/project.js +26 -6
- package/lib/init/util/project.js +2 -2
- package/lib/internal/api.js +2 -0
- package/lib/internal/command.js +1 -1
- package/lib/internal/rc.js +2 -0
- package/lib/port-resolver.js +4 -3
- package/lib/prompt/types/file-path.js +1 -1
- package/lib/pull/features/functions/index.js +35 -2
- package/lib/pull/features/functions/languages.js +8 -1
- package/lib/readLineUtils.js +37 -1
- package/lib/readline/features/cache.js +175 -1
- package/lib/readline/features/index.js +7 -1
- package/lib/readline/features/queue.js +209 -1
- package/lib/readline/features/zcql.js +237 -1
- package/lib/readline/index.js +30 -1
- package/lib/serve/index.js +48 -7
- package/lib/serve/server/index.js +118 -44
- package/lib/serve/server/lib/master.js +18 -5
- package/lib/serve/server/lib/node.mjs +41 -0
- package/lib/serve/server/lib/web_client/index.js +7 -3
- package/lib/serve/server/lib/web_client/server.js +31 -15
- package/lib/shell/dependencies/http-functions.js +57 -21
- package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +1 -2
- package/lib/shell/dependencies/invoker/bio/node.mjs +127 -0
- package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
- package/lib/shell/dependencies/invoker/cron/node.mjs +87 -0
- package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +3 -3
- package/lib/shell/dependencies/invoker/event/node.mjs +84 -0
- package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +1 -1
- package/lib/shell/dependencies/invoker/integ/node.mjs +88 -0
- package/lib/shell/dependencies/local-function.js +74 -22
- package/lib/shell/index.js +11 -2
- package/lib/shell/prepare/index.js +21 -0
- package/lib/shell/prepare/languages/index.js +8 -2
- package/lib/shell/prepare/languages/java.js +39 -2
- package/lib/shell/prepare/languages/node.js +21 -2
- package/lib/shell/prepare/languages/python.js +65 -0
- package/lib/throbber/index.js +3 -1
- package/lib/userConfig.js +48 -0
- package/lib/util_modules/constants/index.js +3 -1
- package/lib/util_modules/constants/lib/apig-rules.js +8 -0
- package/lib/util_modules/constants/lib/cliq-handlers.js +17 -1
- package/lib/util_modules/constants/lib/dc-type.js +8 -0
- package/lib/util_modules/constants/lib/default.js +2 -2
- package/lib/util_modules/constants/lib/env-path.js +12 -0
- package/lib/util_modules/constants/lib/file-names.js +4 -1
- package/lib/util_modules/constants/lib/folder-names.js +3 -1
- package/lib/util_modules/constants/lib/placeholders.js +6 -1
- package/lib/util_modules/constants/lib/runtime.js +2 -1
- package/lib/util_modules/constants/lib/scopes.js +1 -0
- package/lib/util_modules/constants/lib/template.js +9 -0
- package/lib/util_modules/constants/lib/urls.js +2 -6
- package/lib/util_modules/context-help.js +2 -0
- package/lib/util_modules/fs/lib/async.js +35 -11
- package/lib/util_modules/project.js +20 -1
- package/package.json +2 -1
- package/templates/init/functions/java/aio/catalyst-config.json +3 -2
- package/templates/init/functions/java/bio/catalyst-config.json +3 -2
- package/templates/init/functions/java/cron/catalyst-config.json +3 -2
- package/templates/init/functions/java/event/catalyst-config.json +3 -2
- package/templates/init/functions/java/integ/cliq/catalyst-config.json +1 -0
- package/templates/init/functions/node/aio/catalyst-config.json +3 -2
- package/templates/init/functions/node/bio/catalyst-config.json +3 -2
- package/templates/init/functions/node/cron/catalyst-config.json +3 -2
- package/templates/init/functions/node/event/catalyst-config.json +3 -2
- package/templates/init/functions/node/integ/cliq/catalyst-config.json +1 -0
- package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +2 -2
- package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +1 -2
- package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +1 -1
- package/templates/init/functions/node/integ/cliq/handlers/installation-handler.js +1 -1
- package/templates/init/functions/node/integ/cliq/handlers/installation-validator.js +1 -1
- package/templates/init/functions/node/integ/cliq/handlers/message-action-handler.js +1 -1
- package/templates/init/functions/node/integ/cliq/handlers/widget-handler.js +1 -1
- package/templates/init/functions/node/integ/cliq/sample.js +4 -4
- package/templates/init/functions/python/aio/catalyst-config.json +11 -0
- package/templates/init/functions/python/aio/requirements.txt +1 -0
- package/templates/init/functions/python/aio/sample.py +26 -0
- package/templates/init/functions/python/bio/catalyst-config.json +11 -0
- package/templates/init/functions/python/bio/requirements.txt +1 -0
- package/templates/init/functions/python/bio/sample.py +6 -0
- package/templates/init/functions/python/cron/catalyst-config.json +11 -0
- package/templates/init/functions/python/cron/requirements.txt +1 -0
- package/templates/init/functions/python/cron/sample.py +18 -0
- package/templates/init/functions/python/event/catalyst-config.json +11 -0
- package/templates/init/functions/python/event/requirements.txt +1 -0
- package/templates/init/functions/python/event/sample.py +21 -0
- package/templates/init/functions/python/integ/cliq/catalyst-config.json +11 -0
- package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +174 -0
- package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +102 -0
- package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +409 -0
- package/templates/init/functions/python/integ/cliq/handlers/installation_handler.py +12 -0
- package/templates/init/functions/python/integ/cliq/handlers/installation_validator.py +16 -0
- package/templates/init/functions/python/integ/cliq/handlers/message_action_handler.py +18 -0
- package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +269 -0
- package/templates/init/functions/python/integ/cliq/requirements.txt +1 -0
- package/templates/init/functions/python/integ/cliq/sample.py +21 -0
- package/lib/serve/server/lib/node.js +0 -62
- package/lib/shell/dependencies/invoker/bio/node.js +0 -80
- package/lib/shell/dependencies/invoker/cron/node.js +0 -54
- package/lib/shell/dependencies/invoker/event/node.js +0 -56
- package/lib/shell/dependencies/invoker/integ/node.js +0 -79
- package/templates/.DS_Store +0 -0
- package/templates/init/.DS_Store +0 -0
- package/templates/init/client/.DS_Store +0 -0
- package/templates/init/client/react/.DS_Store +0 -0
- package/templates/init/functions/node/integ/cliq/.DS_Store +0 -0
|
@@ -50,16 +50,27 @@ const path_1 = require("path");
|
|
|
50
50
|
const error_1 = __importDefault(require("../../error"));
|
|
51
51
|
const fn_utils_1 = require("../../fn-utils");
|
|
52
52
|
const plugin_loader_1 = __importDefault(require("../../plugin-loader"));
|
|
53
|
+
const userConfig_1 = __importDefault(require("../../userConfig"));
|
|
53
54
|
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
54
55
|
const constants_1 = require("../../util_modules/constants");
|
|
55
56
|
const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
|
|
56
|
-
const fs_1 = require("../../util_modules/fs");
|
|
57
57
|
const js_1 = require("../../util_modules/js");
|
|
58
58
|
const logger_1 = require("../../util_modules/logger");
|
|
59
59
|
const shell_1 = require("../../util_modules/shell");
|
|
60
60
|
const master_1 = __importDefault(require("./lib/master"));
|
|
61
61
|
const ansi_colors_1 = require("ansi-colors");
|
|
62
62
|
const stream_1 = require("stream");
|
|
63
|
+
const project_1 = require("../../util_modules/project");
|
|
64
|
+
const http_functions_1 = require("../../shell/dependencies/http-functions");
|
|
65
|
+
const cli_table_1 = require("../../cli_table");
|
|
66
|
+
const bioLogUrl = (name, pthName, httpPort, masterPort) => {
|
|
67
|
+
(0, logger_1.labeled)(`functions(${name})`, 'URL => http://localhost:' + (masterPort === -1 ? httpPort : masterPort) + pthName).MESSAGE();
|
|
68
|
+
};
|
|
69
|
+
const aioLogUrl = (details, masterPort) => {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
(0, logger_1.labeled)(`${details.type}[${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name}]`, `URL : http://localhost:${masterPort}/server/${(_b = details.target) === null || _b === void 0 ? void 0 : _b.name}/`).MESSAGE();
|
|
72
|
+
(0, logger_1.info)();
|
|
73
|
+
};
|
|
63
74
|
class Server {
|
|
64
75
|
constructor() {
|
|
65
76
|
this.targetDetailsArr = [];
|
|
@@ -73,7 +84,12 @@ class Server {
|
|
|
73
84
|
const debugPort = parseInt(runtime_store_1.default.get('context.port.debug.' + constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.basic], '-1'), 10);
|
|
74
85
|
if (!isNaN(httpPort)) {
|
|
75
86
|
fnTargets
|
|
76
|
-
.filter((t) =>
|
|
87
|
+
.filter((t) => {
|
|
88
|
+
var _a;
|
|
89
|
+
return t.url !== undefined &&
|
|
90
|
+
t.type === constants_1.FN_TYPE.basic &&
|
|
91
|
+
!((_a = t.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python));
|
|
92
|
+
})
|
|
77
93
|
.map((t) => js_1.JS.omit(t, ['zip_stream', 'localFn']))
|
|
78
94
|
.forEach((t) => {
|
|
79
95
|
this.targetDetailsArr.push({
|
|
@@ -86,16 +102,12 @@ class Server {
|
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
_spinUpJavaServer(details, masterPort) {
|
|
89
|
-
var _a, _b, _c
|
|
105
|
+
var _a, _b, _c;
|
|
90
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
const
|
|
92
|
-
const
|
|
107
|
+
const projectRoot = runtime_store_1.default.get('project.root');
|
|
108
|
+
const javaServer = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'aioserver', 'JavaaioServer');
|
|
109
|
+
const targetDir = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, (_a = details.target) === null || _a === void 0 ? void 0 : _a.name);
|
|
93
110
|
const label = `${details.type}[${(_b = details.target) === null || _b === void 0 ? void 0 : _b.name}]`;
|
|
94
|
-
fn_utils_1.fnUtils.java.ensureJavaInvoker(javaServer, (0, path_1.normalize)((0, path_1.join)(__dirname, './lib', 'java', 'JavaaioServer.java')));
|
|
95
|
-
const serverFiles = yield fs_1.ASYNC.walk((0, path_1.dirname)(javaServer));
|
|
96
|
-
yield Promise.all(serverFiles.map((file) => __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
return fs_1.ASYNC.copyFile(file, (0, path_1.join)(targetDir, (0, path_1.relative)((0, path_1.dirname)(javaServer), file.replace('lib' + path_1.sep, ''))));
|
|
98
|
-
})));
|
|
99
111
|
const opts = [
|
|
100
112
|
'-cp',
|
|
101
113
|
(0, path_1.join)(targetDir, '*') + fn_utils_1.fnUtils.java.classPathSep + targetDir + path_1.sep,
|
|
@@ -117,28 +129,24 @@ class Server {
|
|
|
117
129
|
return event;
|
|
118
130
|
}
|
|
119
131
|
const child = (0, shell_1.spawn)('java', opts, {
|
|
120
|
-
cwd: targetSource,
|
|
132
|
+
cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)),
|
|
121
133
|
stdio: 'pipe',
|
|
122
|
-
env: {
|
|
123
|
-
X_ZOHO_CATALYST_IS_LOCAL: 'true',
|
|
124
|
-
X_ZOHO_CATALYST_FUNCTION_LOADED: 'true',
|
|
125
|
-
X_ZOHO_CATALYST_CODE_LOCATION: targetDir + path_1.sep,
|
|
126
|
-
X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth,
|
|
127
|
-
X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin
|
|
128
|
-
}
|
|
134
|
+
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)
|
|
129
135
|
}).RAW();
|
|
130
|
-
(0, logger_1.labeled)(label, `URL : http://localhost:${masterPort}/server/${(_d = details.target) === null || _d === void 0 ? void 0 : _d.name}/`).MESSAGE();
|
|
131
|
-
(0, logger_1.info)();
|
|
132
136
|
return child;
|
|
133
137
|
});
|
|
134
138
|
}
|
|
135
139
|
_spinUpProcess(details, masterPort) {
|
|
136
|
-
var _a, _b
|
|
140
|
+
var _a, _b;
|
|
137
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
142
|
const label = `${details.type}[${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name}]`;
|
|
139
|
-
const
|
|
143
|
+
const _c = details.target, { ['watcher']: _ } = _c, serialisableTarget = __rest(_c, ['watcher']);
|
|
144
|
+
const projectRoot = runtime_store_1.default.get('project.root');
|
|
145
|
+
serialisableTarget.index = serialisableTarget.index
|
|
146
|
+
? serialisableTarget.index.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build))
|
|
147
|
+
: undefined;
|
|
140
148
|
const opts = [
|
|
141
|
-
(0, path_1.join)(__dirname, 'lib', 'node.
|
|
149
|
+
(0, path_1.join)(__dirname, 'lib', 'node.mjs'),
|
|
142
150
|
details.httpPort + '',
|
|
143
151
|
JSON.stringify(serialisableTarget)
|
|
144
152
|
];
|
|
@@ -150,6 +158,9 @@ class Server {
|
|
|
150
158
|
const configType = details.type === 'server' ? 'functions' : details.type;
|
|
151
159
|
const servePlugin = yield (0, plugin_loader_1.default)(configType, 'start', targetSource).catch((err) => (0, logger_1.debug)(err));
|
|
152
160
|
if (typeof servePlugin === 'function') {
|
|
161
|
+
if (configType === 'client') {
|
|
162
|
+
process.env.X_CATALYST_WEBAPP_PATH = targetSource;
|
|
163
|
+
}
|
|
153
164
|
const logStreamPlugin = yield (0, plugin_loader_1.default)(configType, 'logs', targetSource).catch((err) => (0, logger_1.debug)(err));
|
|
154
165
|
if (typeof logStreamPlugin === 'function') {
|
|
155
166
|
const stream = yield logStreamPlugin();
|
|
@@ -179,20 +190,34 @@ class Server {
|
|
|
179
190
|
return yield (yield Promise.resolve().then(() => __importStar(require('./lib/web_client/index.js')))).default(details, masterPort);
|
|
180
191
|
}
|
|
181
192
|
const child = (0, shell_1.spawn)('node', opts, {
|
|
182
|
-
cwd: targetSource,
|
|
193
|
+
cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)),
|
|
183
194
|
stdio: 'pipe',
|
|
184
|
-
env: {
|
|
185
|
-
X_ZOHO_CATALYST_IS_LOCAL: 'true',
|
|
186
|
-
X_ZOHO_CATALYST_FUNCTION_LOADED: 'true',
|
|
187
|
-
X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth,
|
|
188
|
-
X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin
|
|
189
|
-
}
|
|
195
|
+
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) }, details.target.env_var)
|
|
190
196
|
}).RAW();
|
|
191
|
-
(0, logger_1.labeled)(label, `URL : http://localhost:${masterPort}/server/${(_c = details.target) === null || _c === void 0 ? void 0 : _c.name}/`).MESSAGE();
|
|
192
|
-
(0, logger_1.info)();
|
|
193
197
|
return child;
|
|
194
198
|
});
|
|
195
199
|
}
|
|
200
|
+
_spinUpPythonServer(details) {
|
|
201
|
+
var _a, _b;
|
|
202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
const projectRoot = runtime_store_1.default.get('project.root');
|
|
204
|
+
const opts = ['-u', 'main.py'];
|
|
205
|
+
const targetSource = (_a = details.target) === null || _a === void 0 ? void 0 : _a.source;
|
|
206
|
+
const runtimesDir = constants_1.ENVPATH.runtimes.data;
|
|
207
|
+
const stackVersion = (_b = details.target.stack) === null || _b === void 0 ? void 0 : _b.replace('python_', '');
|
|
208
|
+
return new Promise((res) => {
|
|
209
|
+
const child = (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), opts, {
|
|
210
|
+
cwd: (0, path_1.join)(runtimesDir, runtime_1.default.language.python, `zcatalyst_runtime_${stackVersion === null || stackVersion === void 0 ? void 0 : stackVersion.replace('_', '')}`),
|
|
211
|
+
stdio: 'pipe',
|
|
212
|
+
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)
|
|
213
|
+
}).RAW();
|
|
214
|
+
child.on('spawn', () => __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
yield (0, http_functions_1.checkIfRuntimeServerRunning)(details.httpPort.toString());
|
|
216
|
+
}));
|
|
217
|
+
res(child);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
}
|
|
196
221
|
add(type, target) {
|
|
197
222
|
const httpPort = runtime_store_1.default.get(`context.port.http.${type === 'server' ? 'functions' : type}.${target.name}`, -1);
|
|
198
223
|
const debugPort = runtime_store_1.default.get(`context.port.debug.${type === 'server' ? 'functions' : type}.${target.name}`, -1);
|
|
@@ -207,7 +232,7 @@ class Server {
|
|
|
207
232
|
});
|
|
208
233
|
}
|
|
209
234
|
startServer(details, masterPort) {
|
|
210
|
-
var _a;
|
|
235
|
+
var _a, _b;
|
|
211
236
|
return __awaiter(this, void 0, void 0, function* () {
|
|
212
237
|
if (details.target === undefined) {
|
|
213
238
|
return;
|
|
@@ -216,17 +241,24 @@ class Server {
|
|
|
216
241
|
if ((_a = details.target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) {
|
|
217
242
|
currentProcess = yield this._spinUpJavaServer(details, masterPort);
|
|
218
243
|
}
|
|
244
|
+
else if ((_b = details.target.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.python)) {
|
|
245
|
+
currentProcess = yield this._spinUpPythonServer(details);
|
|
246
|
+
}
|
|
219
247
|
else {
|
|
220
248
|
currentProcess = yield this._spinUpProcess(details, masterPort);
|
|
221
249
|
}
|
|
222
250
|
details.process = currentProcess;
|
|
223
251
|
const stdout = currentProcess.stdout;
|
|
224
|
-
if (stdout
|
|
225
|
-
stdout.
|
|
252
|
+
if (stdout) {
|
|
253
|
+
stdout.on('data', (chunk) => {
|
|
254
|
+
process.stdout.write(chunk.toString());
|
|
255
|
+
});
|
|
226
256
|
}
|
|
227
257
|
const stderr = currentProcess.stderr;
|
|
228
|
-
if (stderr
|
|
229
|
-
stderr.
|
|
258
|
+
if (stderr) {
|
|
259
|
+
stderr.on('data', (chunk) => {
|
|
260
|
+
process.stderr.write(chunk.toString());
|
|
261
|
+
});
|
|
230
262
|
}
|
|
231
263
|
return new Promise((res) => setTimeout(res, 100));
|
|
232
264
|
});
|
|
@@ -246,6 +278,32 @@ class Server {
|
|
|
246
278
|
}
|
|
247
279
|
const server = yield (0, master_1.default)(masterPort, this.targetDetailsArr);
|
|
248
280
|
this.masterServer = server;
|
|
281
|
+
this.targetDetailsArr.some((t) => {
|
|
282
|
+
var _a;
|
|
283
|
+
if (t.debugPort != -1 &&
|
|
284
|
+
((_a = t.target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python))) {
|
|
285
|
+
const table = (0, cli_table_1.getCustomColourTable)(ansi_colors_1.yellow);
|
|
286
|
+
table.push(['As of now, local debugging for python is not supported']);
|
|
287
|
+
(0, logger_1.info)(table.toString());
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
return false;
|
|
291
|
+
});
|
|
292
|
+
this.targetDetailsArr
|
|
293
|
+
.filter((t) => t.type == 'functions')
|
|
294
|
+
.forEach((t) => {
|
|
295
|
+
const target = t.target;
|
|
296
|
+
if (!target.url) {
|
|
297
|
+
throw new error_1.default('Target URL not found', { exit: 2 });
|
|
298
|
+
}
|
|
299
|
+
bioLogUrl(target.name, new URL(target.url).pathname, t.httpPort, masterPort);
|
|
300
|
+
});
|
|
301
|
+
(0, logger_1.info)();
|
|
302
|
+
this.targetDetailsArr
|
|
303
|
+
.filter((t) => t.type == 'server')
|
|
304
|
+
.forEach((t) => {
|
|
305
|
+
aioLogUrl(t, masterPort);
|
|
306
|
+
});
|
|
249
307
|
return new Promise((res) => {
|
|
250
308
|
server.on('listening', () => {
|
|
251
309
|
this.targetDetailsArr.forEach((targetDetails) => {
|
|
@@ -264,6 +322,7 @@ class Server {
|
|
|
264
322
|
}
|
|
265
323
|
wait() {
|
|
266
324
|
return __awaiter(this, void 0, void 0, function* () {
|
|
325
|
+
const masterPort = runtime_store_1.default.get(`context.port.http.master`, -1);
|
|
267
326
|
if (!this.masterServer) {
|
|
268
327
|
(0, logger_1.debug)('Master server is not started yet.');
|
|
269
328
|
throw new error_1.default('Server cannot be put to wait state.', { exit: 2 });
|
|
@@ -271,7 +330,7 @@ class Server {
|
|
|
271
330
|
this.targetDetailsArr.forEach((targetdetails) => {
|
|
272
331
|
var _a, _b;
|
|
273
332
|
const target = targetdetails.target;
|
|
274
|
-
if (
|
|
333
|
+
if (!target || !targetdetails.process) {
|
|
275
334
|
return;
|
|
276
335
|
}
|
|
277
336
|
(_a = target.watcher) === null || _a === void 0 ? void 0 : _a.on('preparing', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -279,7 +338,19 @@ class Server {
|
|
|
279
338
|
}));
|
|
280
339
|
(_b = target.watcher) === null || _b === void 0 ? void 0 : _b.on('compiled', () => __awaiter(this, void 0, void 0, function* () {
|
|
281
340
|
yield this.restart(target);
|
|
282
|
-
|
|
341
|
+
if (target.type === constants_1.FN_TYPE.basic) {
|
|
342
|
+
(0, logger_1.labeled)(`functions(${target.name})`, 'ready!').MESSAGE();
|
|
343
|
+
if (!target.url) {
|
|
344
|
+
throw new error_1.default('Target URL not found while restarting server', {
|
|
345
|
+
exit: 2
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
bioLogUrl(target.name, new URL(target.url).pathname, targetdetails.httpPort, masterPort);
|
|
349
|
+
}
|
|
350
|
+
else if (target.type === constants_1.FN_TYPE.advanced) {
|
|
351
|
+
(0, logger_1.labeled)(`server[${target.name}]`, 'ready!').MESSAGE();
|
|
352
|
+
aioLogUrl(targetdetails, masterPort);
|
|
353
|
+
}
|
|
283
354
|
setTimeout(() => {
|
|
284
355
|
var _a;
|
|
285
356
|
(_a = target.watcher) === null || _a === void 0 ? void 0 : _a.emit('next');
|
|
@@ -315,9 +386,6 @@ class Server {
|
|
|
315
386
|
if (targetIdx === -1) {
|
|
316
387
|
throw new error_1.default('Unknown target given for restart.', { exit: 2 });
|
|
317
388
|
}
|
|
318
|
-
if (this.targetDetailsArr[targetIdx].type === 'functions') {
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
389
|
const targetProcess = this.targetDetailsArr[targetIdx].process;
|
|
322
390
|
if (!targetProcess) {
|
|
323
391
|
throw new error_1.default('Process is not defined for this target.', { exit: 2 });
|
|
@@ -338,11 +406,17 @@ class Server {
|
|
|
338
406
|
if (targetdetails.process) {
|
|
339
407
|
return this.kill(targetdetails.process);
|
|
340
408
|
}
|
|
341
|
-
})));
|
|
409
|
+
}))).catch((err) => (0, logger_1.debug)('Error stopping the servers: ', err));
|
|
342
410
|
if (this.masterServer) {
|
|
343
411
|
const masterServer = this.masterServer;
|
|
344
412
|
return new Promise((res, rej) => {
|
|
345
|
-
masterServer.close((err) =>
|
|
413
|
+
masterServer.close((err) => {
|
|
414
|
+
if (err) {
|
|
415
|
+
(0, logger_1.debug)('Error stopping the master server: ', err);
|
|
416
|
+
return rej(err);
|
|
417
|
+
}
|
|
418
|
+
res();
|
|
419
|
+
});
|
|
346
420
|
});
|
|
347
421
|
}
|
|
348
422
|
});
|
|
@@ -83,6 +83,13 @@ const proxyResponseHandler = (systemRoutes) => (proxyRes, req, res) => {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
+
else if (req.url.startsWith('/accounts') && req.url.includes('/signin')) {
|
|
87
|
+
const set = proxyRes.headers['set-cookie'];
|
|
88
|
+
set
|
|
89
|
+
? set.push('IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/')
|
|
90
|
+
: ['IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/'];
|
|
91
|
+
proxyRes.headers['set-cookie'] = set;
|
|
92
|
+
}
|
|
86
93
|
};
|
|
87
94
|
function spinUpMaster(listenPort, otherServerDetails) {
|
|
88
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -127,16 +134,18 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
127
134
|
if (res instanceof http_1.ServerResponse) {
|
|
128
135
|
res.writeHead(502, { 'Content-Type': 'json' });
|
|
129
136
|
}
|
|
130
|
-
res.end(JSON.stringify({ error: 'unable to
|
|
131
|
-
console.log(
|
|
137
|
+
res.end(JSON.stringify({ error: 'unable to serve the request' }));
|
|
138
|
+
console.log();
|
|
139
|
+
console.log('Unable to reach the servers to serve the request: ', req.url);
|
|
132
140
|
console.error(err);
|
|
133
141
|
})
|
|
134
142
|
.on('econnreset', (err, req, res, targetUrl) => {
|
|
135
143
|
if (res instanceof http_1.ServerResponse) {
|
|
136
144
|
res.writeHead(502, { 'Content-Type': 'json' });
|
|
137
145
|
}
|
|
138
|
-
res.end(JSON.stringify({ error: 'unable to
|
|
139
|
-
console.log(
|
|
146
|
+
res.end(JSON.stringify({ error: 'unable to serve the request. ECONNRESET.' }));
|
|
147
|
+
console.log();
|
|
148
|
+
console.log('Connection reset while trying to serve the request ', req.url);
|
|
140
149
|
(0, logger_2.debug)('Connection reset from target URL : ', targetUrl);
|
|
141
150
|
console.error(err);
|
|
142
151
|
})
|
|
@@ -150,7 +159,11 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
150
159
|
const appTarget = `http://127.0.0.1:${serverDetail.httpPort}/app/`;
|
|
151
160
|
app.use('/app', (req, res) => {
|
|
152
161
|
const target = serverDetail.target;
|
|
153
|
-
if (req.url
|
|
162
|
+
if (req.url === '/' && target.homepage.includes('/__catalyst')) {
|
|
163
|
+
req.url = target.homepage;
|
|
164
|
+
(0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
|
|
165
|
+
}
|
|
166
|
+
else if (req.url.startsWith('/local-redirect') && target.login_redirect) {
|
|
154
167
|
const isUrl = target.login_redirect.startsWith('/');
|
|
155
168
|
if (isUrl) {
|
|
156
169
|
res.redirect(target.login_redirect);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import express from 'express';
|
|
4
|
+
import { inspect } from 'util';
|
|
5
|
+
import { pathToFileURL } from 'url';
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
const listenPort = parseInt(args[0], 10);
|
|
9
|
+
const fnDetails = JSON.parse(args[1]);
|
|
10
|
+
|
|
11
|
+
const app = express();
|
|
12
|
+
|
|
13
|
+
const targetName = fnDetails.name;
|
|
14
|
+
const index = pathToFileURL(fnDetails.index);
|
|
15
|
+
|
|
16
|
+
app.use('/', async (req, res) => {
|
|
17
|
+
try {
|
|
18
|
+
if (index === undefined) {
|
|
19
|
+
throw new Error('index of AIO function is undefined');
|
|
20
|
+
}
|
|
21
|
+
const userModule = await import(index);
|
|
22
|
+
if (!('default' in userModule)) {
|
|
23
|
+
throw new Error('Could not find any default export');
|
|
24
|
+
}
|
|
25
|
+
if (typeof userModule.default !== 'function') {
|
|
26
|
+
throw new Error('The default export is not a function');
|
|
27
|
+
}
|
|
28
|
+
userModule.default(req, res);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
const errorString = inspect(e);
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.error('[' + targetName + '] ' + errorString);
|
|
33
|
+
res.writeHead(500);
|
|
34
|
+
res.end(errorString);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
app.listen(listenPort).on('error', (err) => {
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.error(err);
|
|
41
|
+
});
|
|
@@ -18,13 +18,17 @@ const server_js_1 = __importDefault(require("./server.js"));
|
|
|
18
18
|
exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
19
|
var _a;
|
|
20
20
|
const target = details.target;
|
|
21
|
-
const
|
|
22
|
-
|
|
21
|
+
const clientListener = yield (0, server_js_1.default)(details.httpPort, target.source, {
|
|
22
|
+
homepage: target.homepage,
|
|
23
|
+
enableWatch: ((_a = target.opts) === null || _a === void 0 ? void 0 : _a.watch) || false,
|
|
24
|
+
notFoundPage: target.notFoundPage
|
|
25
|
+
});
|
|
26
|
+
clientListener.addListener('start', () => {
|
|
23
27
|
var _a, _b;
|
|
24
28
|
const appUrl = 'http://localhost:' + masterPort;
|
|
25
29
|
const label = `${details.type}[${(_a = details.target) === null || _a === void 0 ? void 0 : _a.name}]`;
|
|
26
30
|
(0, logger_1.labeled)(label, `URL : ${appUrl}/app/`).MESSAGE();
|
|
27
31
|
((_b = details.target.opts) === null || _b === void 0 ? void 0 : _b.open) && (0, open_1.default)(appUrl).catch();
|
|
28
32
|
});
|
|
29
|
-
return
|
|
33
|
+
return clientListener;
|
|
30
34
|
});
|
|
@@ -59,7 +59,7 @@ function reloadApp(event, path, liveSockets) {
|
|
|
59
59
|
(0, logger_js_1.info)((0, ansi_colors_1.cyan)(`${event} detected in ${path} of the Web-Client.`));
|
|
60
60
|
liveSockets.forEach((socket) => socket.send('reload'));
|
|
61
61
|
}
|
|
62
|
-
function webClientServer(httpPort, source, homepage, enableWatch) {
|
|
62
|
+
function webClientServer(httpPort, source, { homepage = 'index.html', enableWatch = true, notFoundPage } = {}) {
|
|
63
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
64
|
const eventListener = new events_1.EventEmitter();
|
|
65
65
|
const catalystTempDir = (0, path_1.join)(source, '.catalyst');
|
|
@@ -70,7 +70,7 @@ function webClientServer(httpPort, source, homepage, enableWatch) {
|
|
|
70
70
|
if (reloadScriptSrc) {
|
|
71
71
|
const clientWatcher = (0, chokidar_1.watch)(source, {
|
|
72
72
|
ignoreInitial: true,
|
|
73
|
-
ignored: ['node_modules/**/*']
|
|
73
|
+
ignored: ['node_modules/**/*', `/**/${index_js_1.FILENAME.client.package_json}`]
|
|
74
74
|
});
|
|
75
75
|
const liveSockets = [];
|
|
76
76
|
let watcherReady = false;
|
|
@@ -126,33 +126,49 @@ function webClientServer(httpPort, source, homepage, enableWatch) {
|
|
|
126
126
|
const app = (0, express_1.default)();
|
|
127
127
|
app.use('/app', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
128
128
|
const requestedFile = req.url === '/' ? homepage : decodeURIComponent(req.path);
|
|
129
|
-
if (enableWatch &&
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (!homepageFile) {
|
|
134
|
-
eventListener.emit('error', new error_js_1.default('Unable to read the homepage file', {
|
|
129
|
+
if (enableWatch && (requestedFile.includes('.html') || requestedFile.includes('.htm'))) {
|
|
130
|
+
const htmlFile = yield index_js_2.ASYNC.readFile((0, path_1.join)(source, requestedFile));
|
|
131
|
+
if (!htmlFile) {
|
|
132
|
+
eventListener.emit('error', new error_js_1.default('Unable to read the html file', {
|
|
135
133
|
exit: 1,
|
|
136
134
|
errorId: 'WEB-CLIENT-SERVER-1',
|
|
137
|
-
arg: [ansi_colors_1.red.italic(
|
|
135
|
+
arg: [ansi_colors_1.red.italic(requestedFile)]
|
|
138
136
|
}));
|
|
139
137
|
return;
|
|
140
138
|
}
|
|
141
|
-
const
|
|
142
|
-
? yield injectScript(encodeURIComponent(reloadScriptSrc),
|
|
139
|
+
const injectedHtml = reloadScriptSrc
|
|
140
|
+
? yield injectScript(encodeURIComponent(reloadScriptSrc), htmlFile)
|
|
143
141
|
: undefined;
|
|
144
142
|
res.contentType('text/html');
|
|
145
143
|
res.status(200);
|
|
146
|
-
res.send(
|
|
144
|
+
res.send(injectedHtml || htmlFile);
|
|
147
145
|
return;
|
|
148
146
|
}
|
|
149
147
|
res.sendFile((0, path_1.join)(source, requestedFile), (err) => {
|
|
150
|
-
if (err) {
|
|
151
|
-
|
|
148
|
+
if (!err) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (err.code && err.code === 'ENOENT') {
|
|
152
|
+
(0, logger_js_1.error)((0, ansi_colors_1.red)('[404 - Resource not found]: ') + (0, ansi_colors_1.bold)(requestedFile));
|
|
153
|
+
(0, logger_js_1.info)();
|
|
152
154
|
(0, logger_js_1.debug)(err.stack || err.message);
|
|
153
155
|
res.status(404);
|
|
154
|
-
|
|
156
|
+
notFoundPage
|
|
157
|
+
? res.sendFile(notFoundPage, (e) => {
|
|
158
|
+
if (!e) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
(0, logger_js_1.debug)('Unable to send the 404 page to server: ', e);
|
|
162
|
+
res.status(500);
|
|
163
|
+
res.send('Error sending 404 page to server: ' + e.stack);
|
|
164
|
+
})
|
|
165
|
+
: res.send('Resource not found');
|
|
166
|
+
return;
|
|
155
167
|
}
|
|
168
|
+
(0, logger_js_1.error)('Error fetching the resource: ' + err);
|
|
169
|
+
(0, logger_js_1.debug)(err.stack);
|
|
170
|
+
res.status(500);
|
|
171
|
+
res.send('Error fetching the resource');
|
|
156
172
|
});
|
|
157
173
|
}));
|
|
158
174
|
const server = app.listen(httpPort).on('error', (err) => {
|