@applitools/tunnel-client
Advanced tools
Comparing version 0.0.3 to 0.0.4
# Changelog | ||
## [0.0.4](https://github.com/applitools/eyes.sdk.javascript1/compare/js/tunnel-client@0.0.3...js/tunnel-client@0.0.4) (2023-06-15) | ||
### Bug Fixes | ||
* improve stability and logging ([#1658](https://github.com/applitools/eyes.sdk.javascript1/issues/1658)) ([6ba65dd](https://github.com/applitools/eyes.sdk.javascript1/commit/6ba65dd4813ee102e41ecf930b3bc7c87e13495c)) | ||
### Dependencies | ||
* The following workspace dependencies were updated | ||
* dependencies | ||
* @applitools/req bumped from 1.3.1 to 1.3.2 | ||
* @applitools/socket bumped from 1.1.2 to 1.1.3 | ||
## [0.0.3](https://github.com/applitools/eyes.sdk.javascript1/compare/js/tunnel-client-v0.0.2...js/tunnel-client@0.0.3) (2023-06-13) | ||
@@ -4,0 +19,0 @@ |
@@ -29,10 +29,13 @@ "use strict"; | ||
const utils = __importStar(require("@applitools/utils")); | ||
async function* makeGenerator({ settings, }) { | ||
var _a; | ||
async function* makeGenerator({ settings, logger, }) { | ||
var _a, _b; | ||
(_a = settings.pollingTimeout) !== null && _a !== void 0 ? _a : (settings.pollingTimeout = 10000); | ||
const req = (0, req_1.makeReq)({ | ||
baseUrl: settings.pollingServerUrl, | ||
retry: { | ||
timeout: 10000, | ||
validate: ({ response, error }) => (response === null || response === void 0 ? void 0 : response.status) !== 200 && !utils.types.instanceOf(error, 'AbortError'), | ||
}, | ||
timeout: (_a = settings.timeout) !== null && _a !== void 0 ? _a : 5 * 60000, | ||
hooks: [handleLogs({ logger })], | ||
timeout: (_b = settings.timeout) !== null && _b !== void 0 ? _b : 5 * 60000, | ||
}); | ||
@@ -81,8 +84,12 @@ const response = await req(`/tunnel-agents/${settings.agentId}/init`, { | ||
}); | ||
const result = await response.json(); | ||
if (result.abort) { | ||
return [{ name: 'TunnelClient.close', payload: { reason: result.abort_reason } }]; | ||
} | ||
else { | ||
const incomingRequestMessages = result.tasks.flatMap((task) => { | ||
let incomingRequestMessages = []; | ||
let pollingTimeout = settings.pollingTimeout; | ||
try { | ||
const result = await response.json(); | ||
if (result.abort) { | ||
return [{ name: 'TunnelClient.close', payload: { reason: result.abort_reason } }]; | ||
} | ||
if (result.polling_interval_sec) | ||
pollingTimeout = result.polling_interval_sec * 1000; | ||
incomingRequestMessages = result.tasks.flatMap((task) => { | ||
if (task.type === 'CREATE_TUNNEL') { | ||
@@ -126,18 +133,49 @@ return { | ||
}); | ||
pendingRequestMessages = pendingRequestMessages.concat(incomingRequestMessages); | ||
outgoingResponseMessages = []; | ||
const outgoingMessages = yield incomingRequestMessages; | ||
outgoingMessages.forEach(message => { | ||
if (message.name === 'TunnelClient.list') | ||
tunnelsEventMessage = message; | ||
else if (message.name === 'TunnelClient.metrics') | ||
metricsEventMessage = message; | ||
else | ||
outgoingResponseMessages.push(message); | ||
}); | ||
pendingRequestMessages = pendingRequestMessages.filter(pendingMessage => !outgoingResponseMessages.some(outgoingMessage => outgoingMessage.key === pendingMessage.key)); | ||
} | ||
await utils.general.sleep(result.polling_interval_sec * 1000); | ||
catch (error) { | ||
logger.error(error); | ||
incomingRequestMessages = []; | ||
} | ||
pendingRequestMessages = pendingRequestMessages.concat(incomingRequestMessages); | ||
outgoingResponseMessages = []; | ||
const outgoingMessages = yield incomingRequestMessages; | ||
outgoingMessages.forEach(message => { | ||
if (message.name === 'TunnelClient.list') | ||
tunnelsEventMessage = message; | ||
else if (message.name === 'TunnelClient.metrics') | ||
metricsEventMessage = message; | ||
else | ||
outgoingResponseMessages.push(message); | ||
}); | ||
pendingRequestMessages = pendingRequestMessages.filter(pendingMessage => !outgoingResponseMessages.some(outgoingMessage => outgoingMessage.key === pendingMessage.key)); | ||
await utils.general.sleep(pollingTimeout); | ||
} | ||
} | ||
exports.makeGenerator = makeGenerator; | ||
function handleLogs({ logger } = {}) { | ||
const guid = utils.general.guid(); | ||
let counter = 0; | ||
return { | ||
beforeRequest({ request, options }) { | ||
let requestId = request.headers.get('x-applitools-eyes-client-request-id'); | ||
if (!requestId) { | ||
requestId = `${counter++}--${guid}`; | ||
request.headers.set('x-applitools-eyes-client-request-id', requestId); | ||
} | ||
logger === null || logger === void 0 ? void 0 : logger.log(`Request [${requestId}] will be sent to the address "[${request.method}]${request.url}" with body`, options === null || options === void 0 ? void 0 : options.body); | ||
}, | ||
beforeRetry({ request, attempt, error, response, options }) { | ||
const requestId = request.headers.get('x-applitools-eyes-client-request-id'); | ||
logger === null || logger === void 0 ? void 0 : logger.log(`Request [${requestId}] that was sent to the address "[${request.method}]${request.url}" with body`, options === null || options === void 0 ? void 0 : options.body, `is going to retried due to ${error ? 'an error' : 'a response with status'}`, error !== null && error !== void 0 ? error : `${response.statusText}(${response.status})`); | ||
request.headers.set('x-applitools-eyes-client-request-id', `${requestId.split('#', 1)[0]}#${attempt + 1}`); | ||
}, | ||
async afterResponse({ request, response }) { | ||
const requestId = request.headers.get('x-applitools-eyes-client-request-id'); | ||
logger === null || logger === void 0 ? void 0 : logger.log(`Request [${requestId}] that was sent to the address "[${request.method}]${request.url}" respond with ${response.statusText}(${response.status})`, !response.ok ? `and body ${JSON.stringify(await response.clone().text())}` : ''); | ||
}, | ||
afterError({ request, error }) { | ||
const requestId = request.headers.get('x-applitools-eyes-client-request-id'); | ||
logger === null || logger === void 0 ? void 0 : logger.error(`Request [${requestId}] that was sent to the address "[${request.method}]${request.url}" failed with error`, error); | ||
}, | ||
}; | ||
} |
{ | ||
"name": "@applitools/tunnel-client", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"homepage": "https://applitools.com", | ||
@@ -66,4 +66,4 @@ "bugs": { | ||
"@applitools/logger": "2.0.3", | ||
"@applitools/req": "1.3.1", | ||
"@applitools/socket": "1.1.2", | ||
"@applitools/req": "1.3.2", | ||
"@applitools/socket": "1.1.3", | ||
"@applitools/utils": "1.4.0", | ||
@@ -80,3 +80,6 @@ "yargs": "^17.7.2" | ||
"node": ">=18.12.0" | ||
}, | ||
"publishConfig": { | ||
"access": "restricted" | ||
} | ||
} |
import type { TunnelClientWorkerSettings } from './types'; | ||
import { type Logger } from '@applitools/logger'; | ||
export declare function makeGenerator({ settings, }: { | ||
export declare function makeGenerator({ settings, logger, }: { | ||
settings: TunnelClientWorkerSettings; | ||
logger: Logger; | ||
}): AsyncGenerator<Record<string, any>[], Record<string, any>[], Record<string, any>[]>; |
@@ -8,2 +8,3 @@ export interface TunnelClientSettings { | ||
agentId: string; | ||
pollingTimeout?: number; | ||
timeout?: number; | ||
@@ -10,0 +11,0 @@ envInfo?: Record<string, any>; |
43439
552
+ Added@applitools/req@1.3.2(transitive)
+ Added@applitools/socket@1.1.3(transitive)
- Removed@applitools/req@1.3.1(transitive)
- Removed@applitools/socket@1.1.2(transitive)
Updated@applitools/req@1.3.2
Updated@applitools/socket@1.1.3