@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
24 lines (23 loc) • 686 B
JavaScript
export const MIN_BACKOFF_MS = 1e4;
export const MAX_BACKOFF_MS = 3e5;
export const BACKOFF_SCALE_FACTOR = 3;
export const MAX_RETRIES = 5;
export function randomInRange(t, e) {
return Math.floor(Math.random() * (e - t + 1)) + t;
}
export function calculateBackoff(t) {
let e = t;
return (
(null === e || e < 1e4) && (e = 1e4),
Math.min(3e5, randomInRange(1e4, 3 * e))
);
}
export function buildSseUrl(t, e, n, o, r) {
const c = /^https?:\/\//i.test(t) ? t : `https://${t}`;
let p = `mite=${encodeURIComponent(e)}&attempts=${n}`;
return (
o && (p += `&auth=${encodeURIComponent(o)}`),
r && (p += `&rcs=${encodeURIComponent(r)}`),
`${c}/sse?${p}`
);
}