@applitools/core-base
Advanced tools
Comparing version 1.20.0 to 1.21.0
# Changelog | ||
## [1.21.0](https://github.com/Applitools-Dev/sdk/compare/js/core-base@1.20.0...js/core-base@1.21.0) (2024-12-18) | ||
### Features | ||
* check for new ufg balancer - cache result in getAccountInfo instead of makeCoreRequests ([#2692](https://github.com/Applitools-Dev/sdk/issues/2692)) ([e2a9705](https://github.com/Applitools-Dev/sdk/commit/e2a970594ffa6527798c5fac7a72188e30da986d)) | ||
* check for new ufg balancer ([#2683](https://github.com/Applitools-Dev/sdk/issues/2683)) ([60ca9f9](https://github.com/Applitools-Dev/sdk/commit/60ca9f98d37374c918e9c634af46d7f8266b95fc)) | ||
### Bug Fixes | ||
* move apiKey from query param to request header ([d1d2642](https://github.com/Applitools-Dev/sdk/commit/d1d26424c64d8e03981b1482ca49870a866bc164)) | ||
### Dependencies | ||
* @applitools/utils bumped to 1.7.6 | ||
#### Bug Fixes | ||
* support webdriver.io 9 ([baee5ce](https://github.com/Applitools-Dev/sdk/commit/baee5ce96e8220c337b007e3a517b5546ce0fedc)) | ||
* @applitools/logger bumped to 2.0.20 | ||
* @applitools/req bumped to 1.7.5 | ||
* @applitools/image bumped to 1.1.15 | ||
## [1.20.0](https://github.com/Applitools-Dev/sdk/compare/js/core-base@1.19.3...js/core-base@1.20.0) (2024-12-05) | ||
@@ -4,0 +31,0 @@ |
@@ -16,2 +16,3 @@ "use strict"; | ||
const heartbeat_1 = require("./heartbeat"); | ||
const open_check_and_close_1 = require("./open-check-and-close"); | ||
function makeCore({ agentId = 'core-base', concurrency, logger: defaultLogger, offlineLocationPath, }) { | ||
@@ -30,2 +31,3 @@ const logger = (0, logger_1.makeLogger)({ logger: defaultLogger, format: { label: 'core-base' } }); | ||
openFunctionalSession: (0, open_functional_session_1.makeOpenFunctionalSession)({ requests, agentId, concurrency, logger }), | ||
openCheckAndClose: (0, open_check_and_close_1.makeOpenCheckAndClose)({ requests, agentId, logger }), | ||
locate: (0, locate_1.makeLocate)({ requests, agentId, logger }), | ||
@@ -32,0 +34,0 @@ locateText: (0, locate_text_1.makeLocateText)({ requests, agentId, logger }), |
@@ -35,3 +35,3 @@ "use strict"; | ||
baseUrl: settings.eyesServerUrl, | ||
query: { apiKey: settings.apiKey, removeSession: settings.removeSession }, | ||
query: { removeSession: settings.removeSession }, | ||
headers: { | ||
@@ -42,2 +42,3 @@ Accept: 'application/json', | ||
'User-Agent': settings.agentId, | ||
'X-Eyes-Api-Key': settings.apiKey, | ||
}, | ||
@@ -100,3 +101,2 @@ proxy: settings.proxy, | ||
async afterResponse({ request, response, options }) { | ||
var _a, _b; | ||
if ((options === null || options === void 0 ? void 0 : options.expected) && | ||
@@ -107,5 +107,6 @@ (utils.types.isArray(options === null || options === void 0 ? void 0 : options.expected) | ||
const requestId = request.headers.get('x-applitools-eyes-client-request-id'); | ||
const requestApiKey = request.headers.get('X-Eyes-Api-Key'); | ||
const body = await response.clone().text(); | ||
const bodyStr = body ? ` and body "${body}"` : ''; | ||
if (response.status === 401 && (!((_a = options.query) === null || _a === void 0 ? void 0 : _a.apiKey) || ((_b = options.query) === null || _b === void 0 ? void 0 : _b.apiKey) === 'undefined')) { | ||
if (response.status === 401 && (!requestApiKey || requestApiKey === 'undefined')) { | ||
throw new missingApiKeyError_1.MissingApiKeyError(); | ||
@@ -112,0 +113,0 @@ } |
@@ -53,2 +53,3 @@ "use strict"; | ||
sendHeartbeat, | ||
openCheckAndClose, | ||
}; | ||
@@ -247,2 +248,5 @@ return core; | ||
} | ||
async function openCheckAndClose() { | ||
throw new Error('not implemented'); | ||
} | ||
} | ||
@@ -249,0 +253,0 @@ function createTestFolder(basePath, settings) { |
@@ -25,4 +25,8 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.makeFunctionalSessionRequests = exports.makeEyesRequests = exports.makeCoreRequestsWithCache = void 0; | ||
const req_1 = __importDefault(require("@applitools/req")); | ||
const logger_1 = require("@applitools/logger"); | ||
@@ -50,2 +54,3 @@ const req_eyes_1 = require("./req-eyes"); | ||
openFunctionalSession, | ||
openCheckAndClose, | ||
locate, | ||
@@ -247,2 +252,94 @@ locateText, | ||
} | ||
async function openCheckAndClose({ target, settings, logger = mainLogger, }) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
const req = (0, req_eyes_1.makeReqEyes)({ settings, fetch, logger }); | ||
logger.log('Request "openCheckAndClose" called with settings', settings); | ||
const account = await getAccountInfoWithCache({ settings, logger }); | ||
const upload = (0, upload_1.makeUpload)({ | ||
settings: { uploadUrl: account.uploadUrl, proxy: settings.proxy }, | ||
logger: mainLogger, | ||
}); | ||
[target.image, target.dom, settings.domMapping] = await Promise.all([ | ||
upload({ name: 'image', resource: target.image, logger }), | ||
target.dom && upload({ name: 'dom', resource: target.dom, gzip: true, logger }), | ||
settings.domMapping && upload({ name: 'domMapping', resource: settings.domMapping, gzip: true, logger }), | ||
]); | ||
const matchOptions = toServerMatchOptions({ target, settings }); | ||
const openCheckAndCloseResponse = req('./api/sessions/autonomous-start-match-end', { | ||
name: 'openCheckAndClose', | ||
method: 'POST', | ||
body: { | ||
startInfo: { | ||
agentId: settings.agentId, | ||
agentSessionId: settings.userTestId, | ||
agentRunId: settings.userTestId, | ||
sessionType: settings.sessionType, | ||
appIdOrName: settings.appName, | ||
scenarioIdOrName: settings.testName, | ||
displayName: settings.displayName, | ||
properties: [...((_a = settings.properties) !== null && _a !== void 0 ? _a : []), ...((_c = (_b = settings.environment) === null || _b === void 0 ? void 0 : _b.properties) !== null && _c !== void 0 ? _c : [])], | ||
batchInfo: settings.batch && { | ||
id: settings.batch.id, | ||
name: settings.batch.name, | ||
batchSequenceName: settings.batch.sequenceName, | ||
startedAt: settings.batch.startedAt, | ||
notifyOnCompletion: settings.batch.notifyOnCompletion, | ||
properties: settings.batch.properties, | ||
buildId: settings.batch.buildId, | ||
}, | ||
egSessionId: (_e = (_d = settings.environment) === null || _d === void 0 ? void 0 : _d.ecSessionId) !== null && _e !== void 0 ? _e : null, | ||
environment: settings.environment && | ||
(settings.environment.rawEnvironment | ||
? { | ||
...settings.environment.rawEnvironment, | ||
os: (_f = settings.environment.os) !== null && _f !== void 0 ? _f : settings.environment.rawEnvironment.os, | ||
osInfo: (_g = settings.environment.displayOs) !== null && _g !== void 0 ? _g : settings.environment.rawEnvironment.osInfo, | ||
hostingApp: (_h = settings.environment.hostingApp) !== null && _h !== void 0 ? _h : settings.environment.rawEnvironment.hostingApp, | ||
hostingAppInfo: (_j = settings.environment.displayHostingApp) !== null && _j !== void 0 ? _j : settings.environment.rawEnvironment.hostingAppInfo, | ||
} | ||
: { | ||
deviceInfo: settings.environment.deviceName, | ||
os: settings.environment.os, | ||
osInfo: settings.environment.displayOs, | ||
hostingApp: settings.environment.hostingApp, | ||
hostingAppInfo: settings.environment.displayHostingApp, | ||
displaySize: settings.environment.viewportSize | ||
? utils.geometry.round(settings.environment.viewportSize) | ||
: { width: 0, height: 0 }, | ||
inferred: settings.environment.userAgent && `useragent:${settings.environment.userAgent}`, | ||
}), | ||
environmentName: settings.environmentName, | ||
baselineEnvName: settings.baselineEnvName, | ||
branchName: settings.branchName, | ||
parentBranchName: settings.parentBranchName, | ||
baselineBranchName: settings.baselineBranchName, | ||
compareWithParentBranch: settings.compareWithParentBranch, | ||
parentBranchBaselineSavedBefore: settings.gitBranchingTimestamp, | ||
ignoreBaseline: settings.ignoreBaseline, | ||
saveDiffs: settings.saveDiffs, | ||
timeout: settings.abortIdleTestTimeout, | ||
isComponentAgent: settings.isComponentTest, | ||
fallbackExpectedOutput: settings.fallbackBaselineId, | ||
latestCommitInfo: settings.latestCommitInfo, | ||
processId: settings.processId, | ||
replaceExisting: settings.removeDuplicateTests, | ||
}, | ||
...matchOptions, | ||
options: { | ||
...matchOptions.options, | ||
}, | ||
removeSession: false, | ||
removeSessionIfMatching: settings.ignoreMismatch, | ||
updateBaselineIfNew: settings.updateBaselineIfNew, | ||
updateBaselineIfDifferent: settings.updateBaselineIfDifferent, | ||
}, | ||
expected: [200, 201], | ||
logger, | ||
}); | ||
return openCheckAndCloseResponse | ||
.then(() => { | ||
logger.log('Request "openCheckAndCloseResponse" finished successfully'); | ||
}) | ||
.catch(() => undefined); | ||
} | ||
async function locate({ target, settings, logger = mainLogger, }) { | ||
@@ -353,25 +450,82 @@ logger = logger.extend(mainLogger, { tags: [`core-request-${utils.general.shortid()}`] }); | ||
}); | ||
const result = await response.json().then(result => { | ||
const { serviceUrl: ufgServerUrl, accessToken, mobileDevicesListUrl: supportedEnvironmentsUrl, resultsUrl: uploadUrl, ...rest } = result; | ||
return { | ||
eyesServer: { | ||
eyesServerUrl: settings.eyesServerUrl, | ||
apiKey: settings.apiKey, | ||
agentId: settings.agentId, | ||
proxy: settings.proxy, | ||
useDnsCache: settings.useDnsCache, | ||
}, | ||
ufgServer: { | ||
ufgServerUrl, | ||
accessToken, | ||
agentId: settings.agentId, | ||
proxy: settings.proxy, | ||
useDnsCache: settings.useDnsCache, | ||
}, | ||
supportedEnvironmentsUrl, | ||
uploadUrl, | ||
...rest, | ||
}; | ||
}); | ||
const res = (await response.json()); | ||
const { serviceUrl: ufgServerUrl, serviceUrlNew: ufgServerUrlNew, accessToken, mobileDevicesListUrl: supportedEnvironmentsUrl, resultsUrl: uploadUrl, ...rest } = res; | ||
const result = { | ||
eyesServer: { | ||
eyesServerUrl: settings.eyesServerUrl, | ||
apiKey: settings.apiKey, | ||
agentId: settings.agentId, | ||
proxy: settings.proxy, | ||
useDnsCache: settings.useDnsCache, | ||
}, | ||
ufgServer: { | ||
ufgServerUrl: await getServiceUrl({ ufgServerUrl, ufgServerUrlNew, eyesServer: settings }, logger), | ||
accessToken, | ||
agentId: settings.agentId, | ||
proxy: settings.proxy, | ||
useDnsCache: settings.useDnsCache, | ||
}, | ||
supportedEnvironmentsUrl, | ||
uploadUrl, | ||
...rest, | ||
}; | ||
logger.log('Request "getAccountInfo" finished successfully with body', result); | ||
async function getServiceUrl(settings, logger) { | ||
const serviceUrlNew = await checkServiceUrl(settings.ufgServerUrlNew, settings.eyesServer, logger); | ||
if (serviceUrlNew) { | ||
logger.log('Using a new UFG service.', { previous: settings.ufgServerUrl, current: serviceUrlNew }); | ||
return serviceUrlNew; | ||
} | ||
return settings.ufgServerUrl; | ||
} | ||
async function checkServiceUrl(serviceUrl, settings, logger) { | ||
return new Promise(async (resolve) => { | ||
try { | ||
if (!serviceUrl) | ||
return resolve(undefined); | ||
const response = await (0, req_1.default)(serviceUrl, { | ||
method: 'GET', | ||
connectionTimeout: 2000, | ||
}); | ||
// If the service is not blocked, the response status will be 404 | ||
if (response && ((response.status >= 200 && response.status < 300) || response.status === 404)) | ||
return resolve(serviceUrl); | ||
else { | ||
logEvent({ | ||
settings: { | ||
level: 'Notice', | ||
event: { | ||
type: 'serviceUrlNew', | ||
message: `UFG 'serviceUrlNew' is blocked`, | ||
serviceUrlNew: serviceUrl, | ||
}, | ||
eyesServerUrl: settings.eyesServerUrl, | ||
apiKey: settings.apiKey, | ||
}, | ||
}).catch(err => logger.log('Error logging event', { error: err, event: `UFG 'serviceUrlNew' is blocked` })); | ||
return resolve(undefined); | ||
} | ||
} | ||
catch (error) { | ||
logger.error(error); | ||
logEvent({ | ||
settings: { | ||
level: 'Notice', | ||
event: { | ||
type: 'serviceUrlNew', | ||
message: `an error occured while accessing to UFG 'serviceUrlNew', the url is probably blocked`, | ||
serviceUrlNew: serviceUrl, | ||
error: error.message, | ||
}, | ||
eyesServerUrl: settings.eyesServerUrl, | ||
apiKey: settings.apiKey, | ||
}, | ||
}).catch(err => logger.log('Error logging event', { | ||
error: err, | ||
event: `an error occured while accessing to UFG 'serviceUrlNew', the url is probably blocked`, | ||
})); | ||
return resolve(undefined); | ||
} | ||
}); | ||
} | ||
return result; | ||
@@ -378,0 +532,0 @@ } |
{ | ||
"name": "@applitools/core-base", | ||
"version": "1.20.0", | ||
"version": "1.21.0", | ||
"homepage": "https://applitools.com", | ||
@@ -45,6 +45,6 @@ "bugs": { | ||
"dependencies": { | ||
"@applitools/image": "1.1.14", | ||
"@applitools/logger": "2.0.19", | ||
"@applitools/req": "1.7.4", | ||
"@applitools/utils": "1.7.5", | ||
"@applitools/image": "1.1.15", | ||
"@applitools/logger": "2.0.20", | ||
"@applitools/req": "1.7.5", | ||
"@applitools/utils": "1.7.6", | ||
"abort-controller": "3.0.0", | ||
@@ -51,0 +51,0 @@ "throat": "6.0.2" |
@@ -1,2 +0,2 @@ | ||
import type { Core, Eyes, FunctionalSession, OpenSettings, ReportSettings, VisualTest, FunctionalTest, HeartbeatSettings, UpdateIfScmSettings, UpdateIfScmResult } from '../types'; | ||
import type { ImageTarget, Core, Eyes, FunctionalSession, OpenSettings, CheckSettings, CloseSettings, ReportSettings, VisualTest, FunctionalTest, HeartbeatSettings, UpdateIfScmSettings, UpdateIfScmResult } from '../types'; | ||
import { type Fetch } from '@applitools/req'; | ||
@@ -16,2 +16,7 @@ import { type Logger } from '@applitools/logger'; | ||
}): Promise<FunctionalSessionRequests>; | ||
openCheckAndClose(options: { | ||
target: ImageTarget; | ||
settings: OpenSettings & CheckSettings & CloseSettings; | ||
logger?: Logger; | ||
}): Promise<void>; | ||
updateIfScm(options: { | ||
@@ -18,0 +23,0 @@ settings: UpdateIfScmSettings; |
@@ -27,2 +27,7 @@ import { type MaybeArray, type Region, type Size, type Location } from '@applitools/utils'; | ||
}): Promise<FunctionalSession>; | ||
openCheckAndClose(options: { | ||
target: Target; | ||
settings: OpenSettings & CheckSettings & CloseSettings; | ||
logger?: Logger; | ||
}): Promise<void>; | ||
locate<TLocator extends string>(options: { | ||
@@ -29,0 +34,0 @@ target: Target; |
210051
59
3502
15
+ Added@applitools/image@1.1.15(transitive)
+ Added@applitools/logger@2.0.20(transitive)
+ Added@applitools/req@1.7.5(transitive)
+ Added@applitools/utils@1.7.6(transitive)
- Removed@applitools/image@1.1.14(transitive)
- Removed@applitools/logger@2.0.19(transitive)
- Removed@applitools/req@1.7.4(transitive)
- Removed@applitools/utils@1.7.5(transitive)
Updated@applitools/image@1.1.15
Updated@applitools/logger@2.0.20
Updated@applitools/req@1.7.5
Updated@applitools/utils@1.7.6