@grafana/alerting
Version:
Grafana Alerting Library – Build vertical integrations on top of the industry-leading alerting solution
37 lines (32 loc) • 1.15 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var runtime = require('@grafana/runtime');
;
const getAPINamespace = () => runtime.config.namespace;
const getAPIBaseURL = (group, version) => {
const subPath = runtime.config.appSubUrl || "";
return `${subPath}/apis/${group}/${version}/namespaces/${getAPINamespace()}`;
};
const getAPIReducerPath = (group, version) => `${group}/${version}`;
const isWellFormed = (str) => {
try {
encodeURIComponent(str);
return true;
} catch (error) {
return false;
}
};
const base64UrlEncode = (value) => {
if (!isWellFormed(value)) {
throw new Error(`Cannot encode malformed UTF-16 string with lone surrogates: ${value}`);
}
const bytes = new TextEncoder().encode(value);
const binString = String.fromCodePoint(...bytes);
const base64 = btoa(binString);
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
};
exports.base64UrlEncode = base64UrlEncode;
exports.getAPIBaseURL = getAPIBaseURL;
exports.getAPINamespace = getAPINamespace;
exports.getAPIReducerPath = getAPIReducerPath;
//# sourceMappingURL=util.cjs.map