@applitools/execution-grid-client
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -30,5 +30,5 @@ "use strict"; | ||
exports.makeServer = void 0; | ||
require("./http-extension"); | ||
const http_1 = require("http"); | ||
const proxy_1 = require("./proxy"); | ||
const tunnel_1 = require("./tunnel"); | ||
const raw_body_1 = __importDefault(require("raw-body")); | ||
@@ -41,14 +41,24 @@ const logger_1 = require("@applitools/logger"); | ||
const RETRY_ERROR_CODES = ['CONCURRENCY_LIMIT_REACHED', 'NO_AVAILABLE_DRIVER_POD']; | ||
function makeServer({ port = 0, forwardingUrl = 'https://exec-wus.applitools.com', tunnelUrl, serverUrl = process.env.APPLITOOLS_SERVER_URL, apiKey = process.env.APPLITOOLS_API_KEY, logger, } = {}) { | ||
function makeServer({ port = 0, forwardingUrl = 'https://exec-wus.applitools.com', tunnelUrl = process.env.APPLITOOLS_EG_TUNNEL_URL, serverUrl = process.env.APPLITOOLS_SERVER_URL, apiKey = process.env.APPLITOOLS_API_KEY, logger, } = {}) { | ||
logger = logger ? logger.extend({ label: 'eg-client' }) : (0, logger_1.makeLogger)({ label: 'eg-client', colors: true }); | ||
const sessions = new Map(); | ||
const { createTunnel, deleteTunnel } = (0, tunnel_1.makeTunnelManager)({ tunnelUrl, logger }); | ||
const server = (0, http_1.createServer)(async (request, response) => { | ||
if (request.method === 'POST' && request.url === '/session') { | ||
return handleNewSession(request, response); | ||
try { | ||
if (request.method === 'POST' && /^\/session\/?$/.test(request.url)) { | ||
return await handleNewSession(request, response); | ||
} | ||
else if (request.method === 'DELETE' && /^\/session\/[^\/]+\/?$/.test(request.url)) { | ||
return await handleStopSession(request, response); | ||
} | ||
else { | ||
return (0, proxy_1.proxy)(request, response, { target: forwardingUrl, forward: true }); | ||
} | ||
} | ||
else if (request.method === 'DELETE' && request.url === '/session/sessionID') { | ||
// return handleStopSession(request, response) | ||
catch (err) { | ||
logger.error(`Error during processing request:`, err); | ||
response | ||
.writeHead(500) | ||
.end(JSON.stringify({ value: { error: 'internal proxy server error', message: err.message, stacktrace: '' } })); | ||
} | ||
else { | ||
return (0, proxy_1.proxy)(request, response, { target: forwardingUrl, forward: true }); | ||
} | ||
}); | ||
@@ -63,4 +73,3 @@ server.listen(port, 'localhost'); | ||
server.on('error', async (err) => { | ||
logger.fatal('Error starting proxy server'); | ||
logger.fatal(err); | ||
logger.fatal('Error starting proxy server', err); | ||
reject(err); | ||
@@ -70,4 +79,4 @@ }); | ||
async function handleNewSession(request, response) { | ||
var _a, _b, _c, _d, _e, _f; | ||
const state = {}; | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
const session = {}; | ||
const requestLogger = logger.extend({ | ||
@@ -81,10 +90,6 @@ tags: { signature: `[${request.method}]${request.url}`, requestId: utils.general.guid() }, | ||
const capabilities = (_b = (_a = requestBody.capabilities) === null || _a === void 0 ? void 0 : _a.alwaysMatch) !== null && _b !== void 0 ? _b : requestBody.desiredCapabilities; | ||
state.serverUrl = capabilities['applitools:eyesServerUrl'] = (_c = capabilities['applitools:eyesServerUrl']) !== null && _c !== void 0 ? _c : serverUrl; | ||
state.apiKey = capabilities['applitools:apiKey'] = (_d = capabilities['applitools:apiKey']) !== null && _d !== void 0 ? _d : apiKey; | ||
session.serverUrl = capabilities['applitools:eyesServerUrl'] = (_c = capabilities['applitools:eyesServerUrl']) !== null && _c !== void 0 ? _c : serverUrl; | ||
session.apiKey = capabilities['applitools:apiKey'] = (_d = capabilities['applitools:apiKey']) !== null && _d !== void 0 ? _d : apiKey; | ||
if (capabilities['applitools:tunnel']) { | ||
const tunnelId = await fetch(`${tunnelUrl}/tunnels`, { | ||
method: 'POST', | ||
headers: { 'x-eyes-server-url': state.serverUrl, 'x-eyes-api-key': state.apiKey }, | ||
}).then(response => response.json()); | ||
state.tunnelId = capabilities['applitools:x-tunnel-id-0'] = tunnelId; | ||
session.tunnelId = capabilities['applitools:x-tunnel-id-0'] = await createTunnel(session); | ||
} | ||
@@ -102,2 +107,4 @@ requestLogger.log('Request body has modified:', requestBody); | ||
if (!RETRY_ERROR_CODES.includes((_f = (_e = responseBody.value) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.appliErrorCode)) { | ||
if ((_g = responseBody.value) === null || _g === void 0 ? void 0 : _g.sessionId) | ||
sessions.set(responseBody.value.sessionId, session); | ||
response.writeHead(proxyResponse.statusCode, proxyResponse.headers).end(JSON.stringify(responseBody)); | ||
@@ -112,3 +119,18 @@ return; | ||
} | ||
async function handleStopSession(request, response) { | ||
const requestLogger = logger.extend({ | ||
tags: { signature: `[${request.method}]${request.url}`, requestId: utils.general.guid() }, | ||
}); | ||
const sessionId = request.url.split('/').pop(); | ||
requestLogger.log(`Request was intercepted with sessionId:`, sessionId); | ||
const proxyResponse = await (0, proxy_1.proxy)(request, response, { target: forwardingUrl }); | ||
const session = sessions.get(sessionId); | ||
if (session.tunnelId) { | ||
await deleteTunnel(session); | ||
requestLogger.log(`Tunnel with id ${session.tunnelId} was deleted for session with id ${sessionId}`); | ||
} | ||
sessions.delete(sessionId); | ||
proxyResponse.pipe(response.writeHead(proxyResponse.statusCode, proxyResponse.headers)); | ||
} | ||
} | ||
exports.makeServer = makeServer; |
{ | ||
"name": "@applitools/execution-grid-client", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -10,5 +10,2 @@ "license": "SEE LICENSE IN LICENSE", | ||
}, | ||
"publishConfig": { | ||
"access": "restricted" | ||
}, | ||
"bin": { | ||
@@ -49,3 +46,3 @@ "eg-client": "./bin/cli.js" | ||
"http-proxy": "1.18.1", | ||
"node-fetch": "3.2.4", | ||
"node-fetch": "2.6.7", | ||
"raw-body": "2.5.1", | ||
@@ -56,6 +53,7 @@ "yargs": "17.4.1" | ||
"@applitools/bongo": "^2.0.3", | ||
"@applitools/eg-demo": "1.0.2", | ||
"@applitools/eg-demo": "^1.0.2", | ||
"@types/http-proxy": "^1.17.8", | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "^17.0.31", | ||
"@types/node-fetch": "^2.6.1", | ||
"@types/selenium-webdriver": "^4.0.19", | ||
@@ -62,0 +60,0 @@ "@types/yargs": "^17.0.10", |
/// <reference types="node" /> | ||
import './http-extension'; | ||
import { type Server } from 'http'; | ||
@@ -4,0 +3,0 @@ import { type Logger } from '@applitools/logger'; |
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import { type IncomingMessage, type ServerResponse } from 'http'; | ||
@@ -2,0 +3,0 @@ declare type ProxyOptions = { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
32930
14
338
2
22
4
+ Addednode-fetch@2.6.7(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removeddata-uri-to-buffer@4.0.1(transitive)
- Removedfetch-blob@3.2.0(transitive)
- Removedformdata-polyfill@4.0.10(transitive)
- Removednode-domexception@1.0.0(transitive)
- Removednode-fetch@3.2.4(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)
Updatednode-fetch@2.6.7