@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
36 lines (35 loc) • 1.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.url = void 0;
var telemetryEndpointMatcher = /^\/v1\/(metrics|keys)\/(config|usage|ss|cs)/;
var eventsEndpointMatcher = /^\/(testImpressions|metrics|events)/;
var authEndpointMatcher = /^\/(v2|v3)\/auth/;
var streamingEndpointMatcher = /^\/(sse|event-stream)/;
var configsEndpointMatcher = /^\/v1\/(configs|segmentChanges)/;
/**
* Get URL based on a given target (path).
* ATM, it is only used for testing purposes.
*
* @param settings - settings object
* @param target - url path
* @returns complete url
*/
function url(settings, target) {
if (telemetryEndpointMatcher.test(target)) {
return "".concat(settings.urls.telemetry).concat(target);
}
if (eventsEndpointMatcher.test(target)) {
return "".concat(settings.urls.events).concat(target);
}
if (authEndpointMatcher.test(target)) {
return "".concat(settings.urls.auth).concat(target);
}
if (streamingEndpointMatcher.test(target)) {
return "".concat(settings.urls.streaming).concat(target);
}
if (configsEndpointMatcher.test(target)) {
return "".concat(settings.urls.configs).concat(target);
}
return "".concat(settings.urls.sdk).concat(target);
}
exports.url = url;