zcatalyst-cli 1.14.1 → 1.15.0-beta.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/lib/endpoints/index.js +8 -1
- package/lib/endpoints/lib/catalyst-details.js +8 -4
- package/lib/endpoints/lib/common.js +46 -0
- package/lib/endpoints/lib/env.js +2 -4
- package/lib/endpoints/lib/project.js +3 -6
- package/lib/endpoints/lib/sdk.js +20 -11
- package/lib/errorResponse.js +2 -1
- package/lib/fn-utils/lib/browserLogic.js +70 -0
- package/lib/fn-utils/lib/common.js +9 -2
- package/lib/fn-utils/lib/java.js +11 -3
- package/lib/init/dependencies/package-json.js +2 -18
- package/lib/init/dependencies/python/pip-install.js +21 -1
- package/lib/init/features/functions/index.js +6 -3
- package/lib/init/features/functions/languages/java.js +22 -3
- package/lib/init/features/functions/languages/node.js +25 -7
- package/lib/init/features/index.js +1 -1
- package/lib/internal/api.js +26 -13
- package/lib/progress.js +6 -1
- package/lib/serve/features/index.js +1 -1
- package/lib/serve/index.js +4 -1
- package/lib/serve/server/index.js +6 -3
- package/lib/serve/server/lib/java/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/lib/catalyst-java-runtime-1.0.0.jar +0 -0
- package/lib/serve/server/lib/master.js +16 -14
- package/lib/serve/server/lib/node/browserlogic/browserlogic-playwright.js +25 -0
- package/lib/serve/server/lib/node/browserlogic/browserlogic-puppeteer.js +22 -0
- package/lib/serve/server/lib/node/browserlogic/browserlogic-selenium.js +44 -0
- package/lib/serve/server/lib/node/browserlogic/index.js +24 -0
- package/lib/serve/server/lib/node/browserlogic/utils/deferred_promise.js +21 -0
- package/lib/serve/server/lib/node/browserlogic/utils/playwright-handler.js +34 -0
- package/lib/serve/server/lib/node/browserlogic/utils/puppeteer-handler.js +35 -0
- package/lib/serve/server/lib/node/browserlogic/utils/selenium-handler.js +59 -0
- package/lib/serve/server/lib/node/index.js +75 -0
- package/lib/serve/server/lib/node/package.json +7 -0
- package/lib/shell/dependencies/local-function.js +2 -1
- package/lib/shell/index.js +7 -1
- package/lib/shell/prepare/languages/java.js +3 -1
- package/lib/util_modules/constants/lib/browserLogic.js +14 -0
- package/lib/util_modules/constants/lib/default.js +4 -2
- package/lib/util_modules/constants/lib/fn-type.js +2 -1
- package/lib/util_modules/constants/lib/placeholders.js +2 -1
- package/lib/util_modules/constants/lib/ref-mapping.js +2 -1
- package/lib/util_modules/constants/lib/remote-mapping.js +2 -1
- package/lib/util_modules/constants/lib/template.js +9 -0
- package/lib/util_modules/context-help.js +5 -2
- package/package.json +1 -1
- package/templates/init/functions/java/browserLogic/playwright/.classpath +6 -0
- package/templates/init/functions/java/browserLogic/playwright/.project +17 -0
- package/templates/init/functions/java/browserLogic/playwright/catalyst-config.json +11 -0
- package/templates/init/functions/java/browserLogic/playwright/sample.java +38 -0
- package/templates/init/functions/java/browserLogic/selenium/.classpath +6 -0
- package/templates/init/functions/java/browserLogic/selenium/.project +17 -0
- package/templates/init/functions/java/browserLogic/selenium/catalyst-config.json +11 -0
- package/templates/init/functions/java/browserLogic/selenium/sample.java +38 -0
- package/templates/init/functions/node/browserlogic/playwright/catalyst-config.json +11 -0
- package/templates/init/functions/node/browserlogic/playwright/package.json +7 -0
- package/templates/init/functions/node/browserlogic/playwright/sample.js +10 -0
- package/templates/init/functions/node/browserlogic/puppeteer/catalyst-config.json +11 -0
- package/templates/init/functions/node/browserlogic/puppeteer/package.json +7 -0
- package/templates/init/functions/node/browserlogic/puppeteer/sample.js +10 -0
- package/templates/init/functions/node/browserlogic/selenium/catalyst-config.json +11 -0
- package/templates/init/functions/node/browserlogic/selenium/package.json +7 -0
- package/templates/init/functions/node/browserlogic/selenium/sample.js +10 -0
- package/templates/init/functions/python/aio/sample.py +5 -2
- package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +4 -4
- package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +2 -2
- package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +5 -5
- package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +15 -15
- package/lib/serve/server/lib/node.mjs +0 -41
package/lib/internal/api.js
CHANGED
|
@@ -45,21 +45,25 @@ const js_1 = require("../util_modules/js");
|
|
|
45
45
|
const logger_1 = require("../util_modules/logger");
|
|
46
46
|
const project_1 = require("../util_modules/project");
|
|
47
47
|
class API {
|
|
48
|
-
constructor({ authNeeded = true, resolveOnError = false, maxRetry = 3, env = constants_1.DEFAULT.env_name, log = {}, headers = {} } = {}) {
|
|
48
|
+
constructor({ authNeeded = true, resolveOnError = false, maxRetry = 3, env = constants_1.DEFAULT.env_name, log = {}, headers = {}, isExternal = false, origin = constants_1.ORIGIN.admin, showWarning = true, envId = (0, project_1.getEnvId)() } = {}) {
|
|
49
49
|
this.requestOpts = {
|
|
50
|
-
url:
|
|
50
|
+
url: origin,
|
|
51
51
|
method: 'GET',
|
|
52
52
|
json: true,
|
|
53
|
-
headers
|
|
54
|
-
'/' +
|
|
55
|
-
runtime_store_1.default.get('context.cli.package.version'), 'X-CATALYST-Environment': env })
|
|
53
|
+
headers
|
|
56
54
|
};
|
|
55
|
+
if (!isExternal) {
|
|
56
|
+
this.requestOpts.headers = Object.assign(Object.assign({}, this.requestOpts.headers), { Accept: 'application/vnd.catalyst.v2+json', 'User-Agent': runtime_store_1.default.get('context.cli.package.name') +
|
|
57
|
+
'/' +
|
|
58
|
+
runtime_store_1.default.get('context.cli.package.version'), 'X-CATALYST-Environment': env, 'CATALYST-ORG': envId });
|
|
59
|
+
}
|
|
57
60
|
this.authNeeded = authNeeded;
|
|
58
61
|
this.resolveOnHTTPError = resolveOnError;
|
|
59
62
|
this.logOpts = log;
|
|
60
63
|
this.maxRetryCount = maxRetry;
|
|
61
64
|
this.retryCount = 0;
|
|
62
65
|
this.progress = null;
|
|
66
|
+
this.showWarning = showWarning;
|
|
63
67
|
}
|
|
64
68
|
_logReq() {
|
|
65
69
|
let qs = this.requestOpts.qs
|
|
@@ -98,9 +102,9 @@ class API {
|
|
|
98
102
|
this.progress = new progress_1.default(this.logOpts.progress);
|
|
99
103
|
}
|
|
100
104
|
}
|
|
101
|
-
_logProgress(chunk) {
|
|
105
|
+
_logProgress({ chunk, error } = {}) {
|
|
102
106
|
if (this.progress !== null) {
|
|
103
|
-
this.progress.tick(chunk.length);
|
|
107
|
+
!chunk || error ? this.progress.error(error) : this.progress.tick(chunk.length);
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
_addAuthHeader() {
|
|
@@ -124,8 +128,11 @@ class API {
|
|
|
124
128
|
if (resp.statusCode >= 400 && !this.logOpts.skipRespBody) {
|
|
125
129
|
(0, logger_1.debug)('Response Body : ' + JSON.stringify(resp.body) + '\n');
|
|
126
130
|
if (!this.resolveOnHTTPError) {
|
|
127
|
-
|
|
131
|
+
const errRes = (0, errorResponse_1.default)(resp, body);
|
|
132
|
+
this._logProgress({ error: errRes });
|
|
133
|
+
throw errRes;
|
|
128
134
|
}
|
|
135
|
+
this._logProgress({ error: (0, errorResponse_1.default)(resp, body, true) });
|
|
129
136
|
}
|
|
130
137
|
return {
|
|
131
138
|
status: resp.statusCode,
|
|
@@ -162,8 +169,9 @@ class API {
|
|
|
162
169
|
case 'ETIMEDOUT':
|
|
163
170
|
case 'ENOTFOUND':
|
|
164
171
|
case 'ESOCKETTIMEDOUT':
|
|
165
|
-
|
|
166
|
-
|
|
172
|
+
this.showWarning &&
|
|
173
|
+
(0, logger_1.warning)(err.code +
|
|
174
|
+
' has occured while communicating remote server. Kindly be patient while the cli retries this request.');
|
|
167
175
|
try {
|
|
168
176
|
resolve(yield this._retry(err));
|
|
169
177
|
}
|
|
@@ -196,7 +204,7 @@ class API {
|
|
|
196
204
|
if (isJSONResponse) {
|
|
197
205
|
responseBuffer.push(data);
|
|
198
206
|
}
|
|
199
|
-
this._logProgress(data);
|
|
207
|
+
this._logProgress({ chunk: data });
|
|
200
208
|
});
|
|
201
209
|
});
|
|
202
210
|
});
|
|
@@ -208,8 +216,8 @@ class API {
|
|
|
208
216
|
this.authNeeded = js_1.JS.get(options, 'authNeeded', this.authNeeded);
|
|
209
217
|
this.logOpts = js_1.JS.get(options, 'log', this.logOpts);
|
|
210
218
|
this.requestOpts = js_1.JS.defaultsDeep(js_1.JS.omit(options, ['origin', 'auth', 'maxRetry', 'resolveOnError', 'log']), this.requestOpts);
|
|
211
|
-
this.requestOpts.url =
|
|
212
|
-
|
|
219
|
+
this.requestOpts.url =
|
|
220
|
+
js_1.JS.get(options, 'origin', this.requestOpts.url || constants_1.ORIGIN.admin) + path;
|
|
213
221
|
this.requestOpts.method = method;
|
|
214
222
|
if (this.authNeeded) {
|
|
215
223
|
yield this._addAuthHeader();
|
|
@@ -238,5 +246,10 @@ class API {
|
|
|
238
246
|
return this.fire('DELETE', path, options);
|
|
239
247
|
});
|
|
240
248
|
}
|
|
249
|
+
head(path) {
|
|
250
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
+
return this.fire('HEAD', path);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
241
254
|
}
|
|
242
255
|
exports.default = API;
|
package/lib/progress.js
CHANGED
|
@@ -7,7 +7,7 @@ const ansi_colors_1 = require("ansi-colors");
|
|
|
7
7
|
const pretty_ms_1 = __importDefault(require("pretty-ms"));
|
|
8
8
|
const throbber_1 = __importDefault(require("./throbber"));
|
|
9
9
|
class Progress {
|
|
10
|
-
constructor({ title = '', fillChar = '·', bgChar = ' ', startingChar = '[', endingChar = ']', total = 10 } = {}) {
|
|
10
|
+
constructor({ title = '', fillChar = '·', bgChar = ' ', startingChar = '[', endingChar = ']', total = 10, failure } = {}) {
|
|
11
11
|
this.title = title;
|
|
12
12
|
this.fillChar = fillChar;
|
|
13
13
|
this.bgChar = bgChar;
|
|
@@ -18,6 +18,7 @@ class Progress {
|
|
|
18
18
|
this.startTime = process.hrtime();
|
|
19
19
|
this.currentProgress = 0;
|
|
20
20
|
this.currentProgressFrame = '';
|
|
21
|
+
this.failure = failure;
|
|
21
22
|
}
|
|
22
23
|
get MAX_SCREEN_LENGTH() {
|
|
23
24
|
return 35;
|
|
@@ -37,6 +38,10 @@ class Progress {
|
|
|
37
38
|
updateProgress(text) {
|
|
38
39
|
this.throbber.update(this.title, { text });
|
|
39
40
|
}
|
|
41
|
+
error(err) {
|
|
42
|
+
const msg = this.failure ? this.failure(err) : typeof err === 'string' ? err : err === null || err === void 0 ? void 0 : err.message;
|
|
43
|
+
msg ? this.throbber.fail(this.title, { text: msg }) : this.throbber.remove(this.title);
|
|
44
|
+
}
|
|
40
45
|
tick(count = 1) {
|
|
41
46
|
let prependedHeader = '';
|
|
42
47
|
if (this.currentProgress === 0) {
|
|
@@ -63,7 +63,7 @@ exports.client = client;
|
|
|
63
63
|
function functions() {
|
|
64
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
65
|
const fnModule = yield Promise.resolve().then(() => __importStar(require('../../shell/prepare')));
|
|
66
|
-
yield fnModule.default([constants_1.FN_TYPE.basic, constants_1.FN_TYPE.advanced]);
|
|
66
|
+
yield fnModule.default([constants_1.FN_TYPE.basic, constants_1.FN_TYPE.advanced, constants_1.FN_TYPE.browserLogic]);
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
exports.functions = functions;
|
package/lib/serve/index.js
CHANGED
|
@@ -95,7 +95,10 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
95
95
|
if (target.type === constants_1.FN_TYPE.advanced) {
|
|
96
96
|
advancedServer.add('server', target);
|
|
97
97
|
}
|
|
98
|
-
if (target.type === constants_1.FN_TYPE.
|
|
98
|
+
else if (target.type === constants_1.FN_TYPE.browserLogic) {
|
|
99
|
+
advancedServer.add('functions', target);
|
|
100
|
+
}
|
|
101
|
+
else if (target.type === constants_1.FN_TYPE.basic &&
|
|
99
102
|
((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python))) {
|
|
100
103
|
advancedServer.add('functions', target);
|
|
101
104
|
}
|
|
@@ -111,7 +111,7 @@ class Server {
|
|
|
111
111
|
const opts = [
|
|
112
112
|
'-cp',
|
|
113
113
|
(0, path_1.join)(targetDir, '*') + fn_utils_1.fnUtils.java.classPathSep + targetDir + path_1.sep,
|
|
114
|
-
|
|
114
|
+
`-DCATALYST_FUNCTION_TYPE=${constants_1.REMOTE_REF.functions.type[details.target.type]}`
|
|
115
115
|
];
|
|
116
116
|
if (details.debugPort !== -1) {
|
|
117
117
|
(0, logger_1.labeled)(label, 'you can attach your debugger at port : ' + details.debugPort).MESSAGE();
|
|
@@ -128,6 +128,9 @@ class Server {
|
|
|
128
128
|
(0, logger_1.labeled)(label, `Plugin : "${runtime_store_1.default.get(`context.${configType}.plugins.start${targetSource ? '.' + targetSource : ''}`)}" is used for ${details.type} serve`).MESSAGE();
|
|
129
129
|
return event;
|
|
130
130
|
}
|
|
131
|
+
if (details.target.type === constants_1.FN_TYPE.browserLogic) {
|
|
132
|
+
details.target.env_var = Object.assign({ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true }, details.target.env_var);
|
|
133
|
+
}
|
|
131
134
|
const child = (0, shell_1.spawn)('java', opts, {
|
|
132
135
|
cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)),
|
|
133
136
|
stdio: 'pipe',
|
|
@@ -146,7 +149,7 @@ class Server {
|
|
|
146
149
|
? serialisableTarget.index.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build))
|
|
147
150
|
: undefined;
|
|
148
151
|
const opts = [
|
|
149
|
-
(0, path_1.join)(__dirname, 'lib', 'node
|
|
152
|
+
(0, path_1.join)(__dirname, 'lib', 'node'),
|
|
150
153
|
details.httpPort + '',
|
|
151
154
|
JSON.stringify(serialisableTarget)
|
|
152
155
|
];
|
|
@@ -192,7 +195,7 @@ class Server {
|
|
|
192
195
|
const child = (0, shell_1.spawn)('node', opts, {
|
|
193
196
|
cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)),
|
|
194
197
|
stdio: 'pipe',
|
|
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)
|
|
198
|
+
env: Object.assign({ NODE_PATH: targetSource + path_1.sep + 'node_modules', 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)
|
|
196
199
|
}).RAW();
|
|
197
200
|
return child;
|
|
198
201
|
});
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -153,7 +153,7 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
153
153
|
.on('close', () => (0, logger_2.debug)('proxy closed'));
|
|
154
154
|
const proxyDestroyer = new server_js_1.ConnectionDestroyer(proxy);
|
|
155
155
|
otherServerDetails.forEach((serverDetail) => {
|
|
156
|
-
var _a
|
|
156
|
+
var _a;
|
|
157
157
|
switch (serverDetail.type) {
|
|
158
158
|
case 'client':
|
|
159
159
|
const appTarget = `http://127.0.0.1:${serverDetail.httpPort}/app/`;
|
|
@@ -198,33 +198,35 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
198
198
|
});
|
|
199
199
|
break;
|
|
200
200
|
case 'functions':
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
const fnTarget = serverDetail.target;
|
|
202
|
+
app.use(`/server/${fnTarget.name}${fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''}`, (req, res) => {
|
|
203
203
|
proxy.web(req, res, {
|
|
204
|
-
target: `http://127.0.0.1:${serverDetail.httpPort}/server/${
|
|
204
|
+
target: `http://127.0.0.1:${serverDetail.httpPort}/server/${fnTarget.name}${fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''}`,
|
|
205
205
|
ws: true
|
|
206
206
|
});
|
|
207
207
|
});
|
|
208
|
-
app.use('/baas/v1/project/:projectId/function/' +
|
|
209
|
-
|
|
208
|
+
app.use('/baas/v1/project/:projectId/function/' +
|
|
209
|
+
fnTarget.name +
|
|
210
|
+
(fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''), (req, res) => {
|
|
210
211
|
proxy.web(req, res, {
|
|
211
|
-
target: `http://127.0.0.1:${serverDetail.httpPort}/server/${
|
|
212
|
+
target: `http://127.0.0.1:${serverDetail.httpPort}/server/${fnTarget.name}${fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''}`,
|
|
212
213
|
ws: true
|
|
213
214
|
});
|
|
214
215
|
});
|
|
215
|
-
if (
|
|
216
|
-
app.use('/server/' +
|
|
217
|
-
|
|
216
|
+
if (fnTarget.id) {
|
|
217
|
+
app.use('/server/' +
|
|
218
|
+
fnTarget.id +
|
|
219
|
+
(fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''), (req, res) => {
|
|
218
220
|
proxy.web(req, res, {
|
|
219
|
-
target: `http://127.0.0.1:${serverDetail.httpPort}/server/${
|
|
221
|
+
target: `http://127.0.0.1:${serverDetail.httpPort}/server/${fnTarget.id}${fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''}`,
|
|
220
222
|
ws: true
|
|
221
223
|
});
|
|
222
224
|
});
|
|
223
225
|
app.use('/baas/v1/project/:projectId/function/' +
|
|
224
|
-
|
|
225
|
-
|
|
226
|
+
fnTarget.id +
|
|
227
|
+
(fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''), (req, res) => {
|
|
226
228
|
proxy.web(req, res, {
|
|
227
|
-
target: `http://127.0.0.1:${serverDetail.httpPort}/server/${
|
|
229
|
+
target: `http://127.0.0.1:${serverDetail.httpPort}/server/${fnTarget.id}${fnTarget.type === constants_1.FN_TYPE.browserLogic ? '/execute' : ''}`,
|
|
228
230
|
ws: true
|
|
229
231
|
});
|
|
230
232
|
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author eraianbu-5628
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict"
|
|
7
|
+
|
|
8
|
+
import PLAYWRIGHT_HANDLER from './utils/playwright-handler.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export const constructFunctionParameters = async (REQUEST, RESPONSE) => {
|
|
12
|
+
const browser = await PLAYWRIGHT_HANDLER.getBrowser();
|
|
13
|
+
const context = await browser.newContext();
|
|
14
|
+
const page = await context.newPage();
|
|
15
|
+
return [REQUEST, RESPONSE, page];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const close = async (REQUEST, RESPONSE, page) => {
|
|
19
|
+
try {
|
|
20
|
+
page.context().close();
|
|
21
|
+
}
|
|
22
|
+
catch (ERROR) {
|
|
23
|
+
console.error(ERROR);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author eraianbu-5628
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import PUPPETEER_HANDLER from './utils/puppeteer-handler.js';
|
|
7
|
+
|
|
8
|
+
export const constructFunctionParameters = async (REQUEST, RESPONSE, path) => {
|
|
9
|
+
const browser = await PUPPETEER_HANDLER.getBrowser(path);
|
|
10
|
+
const context = await browser.createIncognitoBrowserContext();
|
|
11
|
+
const page = await context.newPage();
|
|
12
|
+
return [REQUEST, RESPONSE, page];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const close = async (REQUEST, RESPONSE, page) => {
|
|
16
|
+
try {
|
|
17
|
+
page.browserContext().close();
|
|
18
|
+
}
|
|
19
|
+
catch (ERROR) {
|
|
20
|
+
console.error(ERROR);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author eraianbu-5628
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict"
|
|
7
|
+
|
|
8
|
+
import SELENIUM_HANDLER from './utils/selenium-handler.js';
|
|
9
|
+
|
|
10
|
+
import { createRequire } from 'module';
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
|
|
13
|
+
const webdriver = require('selenium-webdriver');
|
|
14
|
+
const chrome = require('selenium-webdriver/chrome');
|
|
15
|
+
|
|
16
|
+
export default (REQUEST, RESPONSE) => {
|
|
17
|
+
return Promise.resolve([REQUEST, RESPONSE]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const constructFunctionParameters = async (REQUEST, RESPONSE) => {
|
|
21
|
+
const seleniumDriver = await SELENIUM_HANDLER.getBrowser();
|
|
22
|
+
let options = new chrome.Options();
|
|
23
|
+
let driver = new webdriver.Builder()
|
|
24
|
+
.forBrowser('chrome')
|
|
25
|
+
.withCapabilities({
|
|
26
|
+
browserName: 'chrome',
|
|
27
|
+
'goog:chromeOptions': {
|
|
28
|
+
debuggerAddress: '127.0.0.1:9002'
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
.build();
|
|
32
|
+
|
|
33
|
+
await driver.switchTo().newWindow('window');
|
|
34
|
+
return [REQUEST, RESPONSE, driver];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const close = async (REQUEST, RESPONSE, driver) => {
|
|
38
|
+
try {
|
|
39
|
+
driver.quit();
|
|
40
|
+
}
|
|
41
|
+
catch (ERROR) {
|
|
42
|
+
console.error(ERROR);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default async (module) => {
|
|
2
|
+
let framework;
|
|
3
|
+
let logic;
|
|
4
|
+
if ('puppeteer' in module) {
|
|
5
|
+
framework = await import('./browserlogic-puppeteer.js');
|
|
6
|
+
logic = module.puppeteer;
|
|
7
|
+
} else if ('playwright' in module) {
|
|
8
|
+
framework = await import('./browserlogic-playwright.js');
|
|
9
|
+
logic = module.playwright;
|
|
10
|
+
} else if ('selenium' in module) {
|
|
11
|
+
framework = await import('./browserlogic-selenium.js');
|
|
12
|
+
logic = module.selenium;
|
|
13
|
+
} else {
|
|
14
|
+
throw new Error(`unsupported browser logic framework type`);
|
|
15
|
+
}
|
|
16
|
+
if (typeof logic !== 'function') {
|
|
17
|
+
throw new Error('User export not a function');
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
constructFunctionParameters: framework.constructFunctionParameters,
|
|
21
|
+
close: framework.close,
|
|
22
|
+
logic
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeferredPromise shares the same api like normal promise. But it has additional control for
|
|
3
|
+
* reject and resolve from remote. It is basically a wrapper over normal promise.
|
|
4
|
+
*/
|
|
5
|
+
export default class DeferredPromise {
|
|
6
|
+
constructor() {
|
|
7
|
+
this._inner = new Promise((RESOLVE, REJECT) => {
|
|
8
|
+
this.resolve = RESOLVE;
|
|
9
|
+
this.reject = REJECT;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// Propagating api to inner promise.
|
|
13
|
+
this.then = this._inner.then.bind(this._inner);
|
|
14
|
+
this.catch = this._inner.catch.bind(this._inner);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// refer: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag
|
|
18
|
+
get [Symbol.toStringTag]() {
|
|
19
|
+
return 'Promise';
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import DEFERED_PROMISE from './deferred_promise.js';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const playwright = require('playwright-core');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @author eraianbu-5628
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
let browser;
|
|
13
|
+
let browserlaunching = false;
|
|
14
|
+
let browserPromise = new DEFERED_PROMISE();
|
|
15
|
+
|
|
16
|
+
const CHROME_EXECUTABLE_PATH = process.env.CHROME_EXECUTABLE_PATH || "/usr/bin/google-chrome";
|
|
17
|
+
|
|
18
|
+
async function getBrowser() {
|
|
19
|
+
if ((!browser || !browser.isConnected()) && !browserlaunching) {
|
|
20
|
+
browserPromise = new DEFERED_PROMISE();
|
|
21
|
+
browserlaunching = true;
|
|
22
|
+
let args = ['--remote-debugging-port=9002'];// No I18N
|
|
23
|
+
browser = await playwright.chromium.launch({ executablePath: CHROME_EXECUTABLE_PATH, args: args, headless: true });
|
|
24
|
+
let version = await browser.version();
|
|
25
|
+
console.log("Chrome started successfully " + version);
|
|
26
|
+
browserPromise.resolve()
|
|
27
|
+
browserlaunching = false;
|
|
28
|
+
}
|
|
29
|
+
return browserPromise.then(async () => {
|
|
30
|
+
return browser;
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default { getBrowser };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import DEFERED_PROMISE from './deferred_promise.js';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
|
|
6
|
+
const puppeteer = require('puppeteer-core');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @author eraianbu-5628
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
let browser;
|
|
14
|
+
let browserlaunching = false;
|
|
15
|
+
let browserPromise = new DEFERED_PROMISE();
|
|
16
|
+
|
|
17
|
+
const CHROME_EXECUTABLE_PATH = process.env.CHROME_EXECUTABLE_PATH || "/usr/bin/google-chrome";
|
|
18
|
+
|
|
19
|
+
async function getBrowser(path) {
|
|
20
|
+
if ((!browser || !browser.isConnected()) && !browserlaunching) {
|
|
21
|
+
browserPromise = new DEFERED_PROMISE();
|
|
22
|
+
browserlaunching = true;
|
|
23
|
+
let args = ['--remote-debugging-port=9002'];// No I18N
|
|
24
|
+
browser = await puppeteer.launch({ executablePath: CHROME_EXECUTABLE_PATH, args: args, headless: true });
|
|
25
|
+
let version = await browser.version();
|
|
26
|
+
console.log("Chrome started successfully " + version);
|
|
27
|
+
browserPromise.resolve()
|
|
28
|
+
browserlaunching = false;
|
|
29
|
+
}
|
|
30
|
+
return browserPromise.then(async () => {
|
|
31
|
+
return browser;
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default {getBrowser}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import DEFERED_PROMISE from './deferred_promise.js';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const webdriver = require('selenium-webdriver');
|
|
6
|
+
const chrome = require('selenium-webdriver/chrome');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @author eraianbu-5628
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
let driver;
|
|
14
|
+
let browserlaunching = false;
|
|
15
|
+
let browserPromise = new DEFERED_PROMISE();
|
|
16
|
+
|
|
17
|
+
async function getBrowser() {
|
|
18
|
+
if ((!driver || !isConnected()) && !browserlaunching) {
|
|
19
|
+
browserPromise = new DEFERED_PROMISE();
|
|
20
|
+
browserlaunching = true;
|
|
21
|
+
|
|
22
|
+
var options = new chrome.Options();
|
|
23
|
+
options.addArguments("--no-sandbox");
|
|
24
|
+
options.addArguments('--headless') ;
|
|
25
|
+
options.addArguments('--disable-dev-shm-usage');
|
|
26
|
+
options.addArguments('--remote-debugging-port=9002');
|
|
27
|
+
|
|
28
|
+
const chromeCapabilities = webdriver.Capabilities.chrome();
|
|
29
|
+
driver = new webdriver.Builder()
|
|
30
|
+
.forBrowser(webdriver.Browser.CHROME)
|
|
31
|
+
.setChromeOptions(options)
|
|
32
|
+
.withCapabilities(chromeCapabilities)
|
|
33
|
+
.build();
|
|
34
|
+
|
|
35
|
+
let version = (await driver.getCapabilities()).get('browserVersion');
|
|
36
|
+
await driver.getTitle();
|
|
37
|
+
console.log("Chrome started successfully " + version);
|
|
38
|
+
browserPromise.resolve()
|
|
39
|
+
browserlaunching = false;
|
|
40
|
+
}
|
|
41
|
+
return browserPromise.then(async () => {
|
|
42
|
+
return driver;
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isConnected()
|
|
47
|
+
{
|
|
48
|
+
try
|
|
49
|
+
{
|
|
50
|
+
driver.getTitle();
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch{
|
|
54
|
+
driver = undefined;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default {getBrowser}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
const type = fnDetails.type;
|
|
16
|
+
|
|
17
|
+
app.all('/server/:fnId/execute', async (req, res) => {
|
|
18
|
+
try {
|
|
19
|
+
if (index === undefined) {
|
|
20
|
+
throw new Error(`index of ${type} function is undefined`);
|
|
21
|
+
}
|
|
22
|
+
if (type !== 'browserlogic') {
|
|
23
|
+
throw new Error('Invalid URL pattern for the functions type: ' + type);
|
|
24
|
+
}
|
|
25
|
+
const userModule = await import(index);
|
|
26
|
+
const browserLogic = await import('./browserlogic/index.js');
|
|
27
|
+
const browserModule = await browserLogic.default(userModule);
|
|
28
|
+
const fnParams = await browserModule.constructFunctionParameters(
|
|
29
|
+
req,
|
|
30
|
+
res,
|
|
31
|
+
fnDetails.source
|
|
32
|
+
);
|
|
33
|
+
try {
|
|
34
|
+
await browserModule.logic(...fnParams);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
browserModule.close(...fnParams);
|
|
37
|
+
}
|
|
38
|
+
} catch (er) {
|
|
39
|
+
const errorString = inspect(er);
|
|
40
|
+
// eslint-disable-next-line no-console
|
|
41
|
+
console.error('[' + targetName + '] ' + errorString);
|
|
42
|
+
res.writeHead(500);
|
|
43
|
+
res.end(errorString);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
app.all('/', async (req, res) => {
|
|
48
|
+
try {
|
|
49
|
+
if (index === undefined) {
|
|
50
|
+
throw new Error(`index of ${type} function is undefined`);
|
|
51
|
+
}
|
|
52
|
+
const userModule = await import(index);
|
|
53
|
+
if (type !== 'aio') {
|
|
54
|
+
throw new Error('Invalid URL pattern for the functions type: ' + type);
|
|
55
|
+
}
|
|
56
|
+
if (!('default' in userModule)) {
|
|
57
|
+
throw new Error('Could not find any default export');
|
|
58
|
+
}
|
|
59
|
+
if (typeof userModule.default !== 'function') {
|
|
60
|
+
throw new Error('The default export is not a function');
|
|
61
|
+
}
|
|
62
|
+
await userModule.default(req, res);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
const errorString = inspect(e);
|
|
65
|
+
// eslint-disable-next-line no-console
|
|
66
|
+
console.error('[' + targetName + '] ' + errorString);
|
|
67
|
+
res.writeHead(500);
|
|
68
|
+
res.end(errorString);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
app.listen(listenPort).on('error', (err) => {
|
|
73
|
+
// eslint-disable-next-line no-console
|
|
74
|
+
console.error(err);
|
|
75
|
+
});
|
|
@@ -31,7 +31,8 @@ const http_functions_1 = require("../dependencies/http-functions");
|
|
|
31
31
|
class LocalFunction {
|
|
32
32
|
constructor(repl, target) {
|
|
33
33
|
var _a, _b, _c;
|
|
34
|
-
if (target.type === undefined ||
|
|
34
|
+
if (target.type === undefined ||
|
|
35
|
+
!Object.values(constants_1.FN_TYPE).includes(target.type)) {
|
|
35
36
|
throw new error_1.default('target type is not defined', { exit: 2 });
|
|
36
37
|
}
|
|
37
38
|
this.repl = repl;
|
package/lib/shell/index.js
CHANGED
|
@@ -46,7 +46,13 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
46
46
|
const httpServer = new http_functions_1.default({ repl: replServer });
|
|
47
47
|
const projectRoot = runtime_store_1.default.get('project.root');
|
|
48
48
|
try {
|
|
49
|
-
yield (0, prepare_1.default)([
|
|
49
|
+
yield (0, prepare_1.default)([
|
|
50
|
+
constants_1.FN_TYPE.basic,
|
|
51
|
+
constants_1.FN_TYPE.cron,
|
|
52
|
+
constants_1.FN_TYPE.event,
|
|
53
|
+
constants_1.FN_TYPE.integration,
|
|
54
|
+
constants_1.FN_TYPE.browserLogic
|
|
55
|
+
]);
|
|
50
56
|
const targets = runtime_store_1.default
|
|
51
57
|
.get('context.functions.targets', [])
|
|
52
58
|
.filter((target) => {
|
|
@@ -48,7 +48,9 @@ exports.default = (targets) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
48
48
|
yield fs_1.ASYNC.chmod(targetBuildPath, '755', { recursive: true });
|
|
49
49
|
yield fs_1.ASYNC.deleteDir(targetBuildPath);
|
|
50
50
|
}
|
|
51
|
-
if (target.type === constants_1.FN_TYPE.advanced ||
|
|
51
|
+
if (target.type === constants_1.FN_TYPE.advanced ||
|
|
52
|
+
target.type === constants_1.FN_TYPE.applogic ||
|
|
53
|
+
target.type == constants_1.FN_TYPE.browserLogic) {
|
|
52
54
|
const javaServer = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'aioserver', 'JavaaioServer');
|
|
53
55
|
const javaInvoker = (0, path_1.join)(__dirname, '../../../serve/server/lib/java/JavaaioServer.java');
|
|
54
56
|
(0, java_1.ensureJavaInvoker)(javaServer, javaInvoker);
|