UNPKG

launchdarkly-vue-client-sdk

Version:
989 lines (988 loc) 76.7 kB
import { ref as Te, onBeforeUnmount as qe, readonly as Oe, inject as _e } from "vue"; function Q(t) { function e(a, n) { Error.captureStackTrace && Error.captureStackTrace(this, this.constructor), this.message = a, this.code = n; } return e.prototype = new Error(), e.prototype.name = t, e.prototype.constructor = e, e; } const ze = Q("LaunchDarklyUnexpectedResponseError"), Je = Q("LaunchDarklyInvalidEnvironmentIdError"), Ke = Q("LaunchDarklyInvalidUserError"), Be = Q("LaunchDarklyInvalidEventKeyError"), Ge = Q("LaunchDarklyInvalidArgumentError"), We = Q("LaunchDarklyFlagFetchError"); for (var j = { LDUnexpectedResponseError: ze, LDInvalidEnvironmentIdError: Je, LDInvalidUserError: Ke, LDInvalidEventKeyError: Be, LDInvalidArgumentError: Ge, LDInvalidDataError: Q("LaunchDarklyInvalidDataError"), LDFlagFetchError: We, LDTimeoutError: Q("LaunchDarklyTimeoutError"), isHttpErrorRecoverable: function(t) { return !(t >= 400 && t < 500) || t === 400 || t === 408 || t === 429; } }, Xe = function(t) { var e = ie(t), a = e[0], n = e[1]; return 3 * (a + n) / 4 - n; }, Ye = function(t) { var e, a, n = ie(t), c = n[0], r = n[1], o = new Ze(function(u, f, l) { return 3 * (f + l) / 4 - l; }(0, c, r)), i = 0, s = r > 0 ? c - 4 : c; for (a = 0; a < s; a += 4) e = G[t.charCodeAt(a)] << 18 | G[t.charCodeAt(a + 1)] << 12 | G[t.charCodeAt(a + 2)] << 6 | G[t.charCodeAt(a + 3)], o[i++] = e >> 16 & 255, o[i++] = e >> 8 & 255, o[i++] = 255 & e; return r === 2 && (e = G[t.charCodeAt(a)] << 2 | G[t.charCodeAt(a + 1)] >> 4, o[i++] = 255 & e), r === 1 && (e = G[t.charCodeAt(a)] << 10 | G[t.charCodeAt(a + 1)] << 4 | G[t.charCodeAt(a + 2)] >> 2, o[i++] = e >> 8 & 255, o[i++] = 255 & e), o; }, Qe = function(t) { for (var e, a = t.length, n = a % 3, c = [], r = 16383, o = 0, i = a - n; o < i; o += r) c.push(tn(t, o, o + r > i ? i : o + r)); return n === 1 ? (e = t[a - 1], c.push(X[e >> 2] + X[e << 4 & 63] + "==")) : n === 2 && (e = (t[a - 2] << 8) + t[a - 1], c.push(X[e >> 10] + X[e >> 4 & 63] + X[e << 2 & 63] + "=")), c.join(""); }, X = [], G = [], Ze = typeof Uint8Array < "u" ? Uint8Array : Array, ae = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", rt = 0; rt < 64; ++rt) X[rt] = ae[rt], G[ae.charCodeAt(rt)] = rt; function ie(t) { var e = t.length; if (e % 4 > 0) throw new Error("Invalid string. Length must be a multiple of 4"); var a = t.indexOf("="); return a === -1 && (a = e), [a, a === e ? 0 : 4 - a % 4]; } function tn(t, e, a) { for (var n, c, r = [], o = e; o < a; o += 3) n = (t[o] << 16 & 16711680) + (t[o + 1] << 8 & 65280) + (255 & t[o + 2]), r.push(X[(c = n) >> 18 & 63] + X[c >> 12 & 63] + X[c >> 6 & 63] + X[63 & c]); return r.join(""); } G[45] = 62, G[95] = 63; var en = { byteLength: Xe, toByteArray: Ye, fromByteArray: Qe }, se = Array.isArray, ce = Object.keys, nn = Object.prototype.hasOwnProperty, rn = function t(e, a) { if (e === a) return !0; if (e && a && typeof e == "object" && typeof a == "object") { var n, c, r, o = se(e), i = se(a); if (o && i) { if ((c = e.length) != a.length) return !1; for (n = c; n-- !== 0; ) if (!t(e[n], a[n])) return !1; return !0; } if (o != i) return !1; var s = e instanceof Date, u = a instanceof Date; if (s != u) return !1; if (s && u) return e.getTime() == a.getTime(); var f = e instanceof RegExp, l = a instanceof RegExp; if (f != l) return !1; if (f && l) return e.toString() == a.toString(); var g = ce(e); if ((c = g.length) !== ce(a).length) return !1; for (n = c; n-- !== 0; ) if (!nn.call(a, g[n])) return !1; for (n = c; n-- !== 0; ) if (!t(e[r = g[n]], a[r])) return !1; return !0; } return e != e && a != a; }; const on = ["key", "ip", "country", "email", "firstName", "lastName", "avatar", "name"]; function ue(t) { const e = unescape(encodeURIComponent(t)); return en.fromByteArray(function(a) { const n = []; for (let c = 0; c < a.length; c++) n.push(a.charCodeAt(c)); return n; }(e)); } function Tt(t, e) { return Object.prototype.hasOwnProperty.call(t, e); } var Ot, I = { appendUrlPath: function(t, e) { return (t.endsWith("/") ? t.substring(0, t.length - 1) : t) + (e.startsWith("/") ? "" : "/") + e; }, base64URLEncode: function(t) { return ue(t).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"); }, btoa: ue, clone: function(t) { return JSON.parse(JSON.stringify(t)); }, deepEquals: function(t, e) { return rn(t, e); }, extend: function(...t) { return t.reduce((e, a) => ({ ...e, ...a }), {}); }, getLDUserAgentString: function(t) { const e = t.version || "?"; return t.userAgent + "/" + e; }, objectHasOwnProperty: Tt, onNextTick: function(t) { setTimeout(t, 0); }, sanitizeContext: function(t) { if (!t) return t; let e; return t.kind !== null && t.kind !== void 0 || on.forEach((a) => { const n = t[a]; n !== void 0 && typeof n != "string" && (e = e || { ...t }, e[a] = String(n)); }), e || t; }, transformValuesToVersionedValues: function(t) { const e = {}; for (const a in t) Tt(t, a) && (e[a] = { value: t[a], version: 0 }); return e; }, transformVersionedValuesToValues: function(t) { const e = {}; for (const a in t) Tt(t, a) && (e[a] = t[a].value); return e; }, wrapPromiseCallback: function(t, e) { const a = t.then((n) => (e && setTimeout(() => { e(null, n); }, 0), n), (n) => { if (!e) return Promise.reject(n); setTimeout(() => { e(n, null); }, 0); }); return e ? void 0 : a; }, once: function(t) { let e, a = !1; return function(...n) { return a || (a = !0, e = t.apply(this, n)), e; }; } }, an = new Uint8Array(16); function le() { if (!Ot && !(Ot = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto < "u" && typeof msCrypto.getRandomValues == "function" && msCrypto.getRandomValues.bind(msCrypto))) throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported"); return Ot(an); } var sn = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i; function wt(t) { return typeof t == "string" && sn.test(t); } for (var fe, Ut, M = [], Rt = 0; Rt < 256; ++Rt) M.push((Rt + 256).toString(16).substr(1)); function yt(t) { var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0, a = (M[t[e + 0]] + M[t[e + 1]] + M[t[e + 2]] + M[t[e + 3]] + "-" + M[t[e + 4]] + M[t[e + 5]] + "-" + M[t[e + 6]] + M[t[e + 7]] + "-" + M[t[e + 8]] + M[t[e + 9]] + "-" + M[t[e + 10]] + M[t[e + 11]] + M[t[e + 12]] + M[t[e + 13]] + M[t[e + 14]] + M[t[e + 15]]).toLowerCase(); if (!wt(a)) throw TypeError("Stringified UUID is invalid"); return a; } var At = 0, Ft = 0; function Ue(t) { if (!wt(t)) throw TypeError("Invalid UUID"); var e, a = new Uint8Array(16); return a[0] = (e = parseInt(t.slice(0, 8), 16)) >>> 24, a[1] = e >>> 16 & 255, a[2] = e >>> 8 & 255, a[3] = 255 & e, a[4] = (e = parseInt(t.slice(9, 13), 16)) >>> 8, a[5] = 255 & e, a[6] = (e = parseInt(t.slice(14, 18), 16)) >>> 8, a[7] = 255 & e, a[8] = (e = parseInt(t.slice(19, 23), 16)) >>> 8, a[9] = 255 & e, a[10] = (e = parseInt(t.slice(24, 36), 16)) / 1099511627776 & 255, a[11] = e / 4294967296 & 255, a[12] = e >>> 24 & 255, a[13] = e >>> 16 & 255, a[14] = e >>> 8 & 255, a[15] = 255 & e, a; } function Re(t, e, a) { function n(c, r, o, i) { if (typeof c == "string" && (c = function(f) { f = unescape(encodeURIComponent(f)); for (var l = [], g = 0; g < f.length; ++g) l.push(f.charCodeAt(g)); return l; }(c)), typeof r == "string" && (r = Ue(r)), r.length !== 16) throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)"); var s = new Uint8Array(16 + c.length); if (s.set(r), s.set(c, r.length), (s = a(s))[6] = 15 & s[6] | e, s[8] = 63 & s[8] | 128, o) { i = i || 0; for (var u = 0; u < 16; ++u) o[i + u] = s[u]; return o; } return yt(s); } try { n.name = t; } catch { } return n.DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8", n.URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8", n; } function de(t) { return 14 + (t + 64 >>> 9 << 4) + 1; } function Y(t, e) { var a = (65535 & t) + (65535 & e); return (t >> 16) + (e >> 16) + (a >> 16) << 16 | 65535 & a; } function bt(t, e, a, n, c, r) { return Y((o = Y(Y(e, t), Y(n, r))) << (i = c) | o >>> 32 - i, a); var o, i; } function q(t, e, a, n, c, r, o) { return bt(e & a | ~e & n, t, e, c, r, o); } function _(t, e, a, n, c, r, o) { return bt(e & n | a & ~n, t, e, c, r, o); } function z(t, e, a, n, c, r, o) { return bt(e ^ a ^ n, t, e, c, r, o); } function J(t, e, a, n, c, r, o) { return bt(a ^ (e | ~n), t, e, c, r, o); } var cn = Re("v3", 48, function(t) { if (typeof t == "string") { var e = unescape(encodeURIComponent(t)); t = new Uint8Array(e.length); for (var a = 0; a < e.length; ++a) t[a] = e.charCodeAt(a); } return function(n) { for (var c = [], r = 32 * n.length, o = "0123456789abcdef", i = 0; i < r; i += 8) { var s = n[i >> 5] >>> i % 32 & 255, u = parseInt(o.charAt(s >>> 4 & 15) + o.charAt(15 & s), 16); c.push(u); } return c; }(function(n, c) { n[c >> 5] |= 128 << c % 32, n[de(c) - 1] = c; for (var r = 1732584193, o = -271733879, i = -1732584194, s = 271733878, u = 0; u < n.length; u += 16) { var f = r, l = o, g = i, h = s; r = q(r, o, i, s, n[u], 7, -680876936), s = q(s, r, o, i, n[u + 1], 12, -389564586), i = q(i, s, r, o, n[u + 2], 17, 606105819), o = q(o, i, s, r, n[u + 3], 22, -1044525330), r = q(r, o, i, s, n[u + 4], 7, -176418897), s = q(s, r, o, i, n[u + 5], 12, 1200080426), i = q(i, s, r, o, n[u + 6], 17, -1473231341), o = q(o, i, s, r, n[u + 7], 22, -45705983), r = q(r, o, i, s, n[u + 8], 7, 1770035416), s = q(s, r, o, i, n[u + 9], 12, -1958414417), i = q(i, s, r, o, n[u + 10], 17, -42063), o = q(o, i, s, r, n[u + 11], 22, -1990404162), r = q(r, o, i, s, n[u + 12], 7, 1804603682), s = q(s, r, o, i, n[u + 13], 12, -40341101), i = q(i, s, r, o, n[u + 14], 17, -1502002290), r = _(r, o = q(o, i, s, r, n[u + 15], 22, 1236535329), i, s, n[u + 1], 5, -165796510), s = _(s, r, o, i, n[u + 6], 9, -1069501632), i = _(i, s, r, o, n[u + 11], 14, 643717713), o = _(o, i, s, r, n[u], 20, -373897302), r = _(r, o, i, s, n[u + 5], 5, -701558691), s = _(s, r, o, i, n[u + 10], 9, 38016083), i = _(i, s, r, o, n[u + 15], 14, -660478335), o = _(o, i, s, r, n[u + 4], 20, -405537848), r = _(r, o, i, s, n[u + 9], 5, 568446438), s = _(s, r, o, i, n[u + 14], 9, -1019803690), i = _(i, s, r, o, n[u + 3], 14, -187363961), o = _(o, i, s, r, n[u + 8], 20, 1163531501), r = _(r, o, i, s, n[u + 13], 5, -1444681467), s = _(s, r, o, i, n[u + 2], 9, -51403784), i = _(i, s, r, o, n[u + 7], 14, 1735328473), r = z(r, o = _(o, i, s, r, n[u + 12], 20, -1926607734), i, s, n[u + 5], 4, -378558), s = z(s, r, o, i, n[u + 8], 11, -2022574463), i = z(i, s, r, o, n[u + 11], 16, 1839030562), o = z(o, i, s, r, n[u + 14], 23, -35309556), r = z(r, o, i, s, n[u + 1], 4, -1530992060), s = z(s, r, o, i, n[u + 4], 11, 1272893353), i = z(i, s, r, o, n[u + 7], 16, -155497632), o = z(o, i, s, r, n[u + 10], 23, -1094730640), r = z(r, o, i, s, n[u + 13], 4, 681279174), s = z(s, r, o, i, n[u], 11, -358537222), i = z(i, s, r, o, n[u + 3], 16, -722521979), o = z(o, i, s, r, n[u + 6], 23, 76029189), r = z(r, o, i, s, n[u + 9], 4, -640364487), s = z(s, r, o, i, n[u + 12], 11, -421815835), i = z(i, s, r, o, n[u + 15], 16, 530742520), r = J(r, o = z(o, i, s, r, n[u + 2], 23, -995338651), i, s, n[u], 6, -198630844), s = J(s, r, o, i, n[u + 7], 10, 1126891415), i = J(i, s, r, o, n[u + 14], 15, -1416354905), o = J(o, i, s, r, n[u + 5], 21, -57434055), r = J(r, o, i, s, n[u + 12], 6, 1700485571), s = J(s, r, o, i, n[u + 3], 10, -1894986606), i = J(i, s, r, o, n[u + 10], 15, -1051523), o = J(o, i, s, r, n[u + 1], 21, -2054922799), r = J(r, o, i, s, n[u + 8], 6, 1873313359), s = J(s, r, o, i, n[u + 15], 10, -30611744), i = J(i, s, r, o, n[u + 6], 15, -1560198380), o = J(o, i, s, r, n[u + 13], 21, 1309151649), r = J(r, o, i, s, n[u + 4], 6, -145523070), s = J(s, r, o, i, n[u + 11], 10, -1120210379), i = J(i, s, r, o, n[u + 2], 15, 718787259), o = J(o, i, s, r, n[u + 9], 21, -343485551), r = Y(r, f), o = Y(o, l), i = Y(i, g), s = Y(s, h); } return [r, o, i, s]; }(function(n) { if (n.length === 0) return []; for (var c = 8 * n.length, r = new Uint32Array(de(c)), o = 0; o < c; o += 8) r[o >> 5] |= (255 & n[o / 8]) << o % 32; return r; }(t), 8 * t.length)); }), un = cn; function ln(t, e, a, n) { switch (t) { case 0: return e & a ^ ~e & n; case 1: case 3: return e ^ a ^ n; case 2: return e & a ^ e & n ^ a & n; } } function Nt(t, e) { return t << e | t >>> 32 - e; } var fn = Re("v5", 80, function(t) { var e = [1518500249, 1859775393, 2400959708, 3395469782], a = [1732584193, 4023233417, 2562383102, 271733878, 3285377520]; if (typeof t == "string") { var n = unescape(encodeURIComponent(t)); t = []; for (var c = 0; c < n.length; ++c) t.push(n.charCodeAt(c)); } else Array.isArray(t) || (t = Array.prototype.slice.call(t)); t.push(128); for (var r = t.length / 4 + 2, o = Math.ceil(r / 16), i = new Array(o), s = 0; s < o; ++s) { for (var u = new Uint32Array(16), f = 0; f < 16; ++f) u[f] = t[64 * s + 4 * f] << 24 | t[64 * s + 4 * f + 1] << 16 | t[64 * s + 4 * f + 2] << 8 | t[64 * s + 4 * f + 3]; i[s] = u; } i[o - 1][14] = 8 * (t.length - 1) / Math.pow(2, 32), i[o - 1][14] = Math.floor(i[o - 1][14]), i[o - 1][15] = 8 * (t.length - 1) & 4294967295; for (var l = 0; l < o; ++l) { for (var g = new Uint32Array(80), h = 0; h < 16; ++h) g[h] = i[l][h]; for (var m = 16; m < 80; ++m) g[m] = Nt(g[m - 3] ^ g[m - 8] ^ g[m - 14] ^ g[m - 16], 1); for (var w = a[0], b = a[1], y = a[2], x = a[3], T = a[4], V = 0; V < 80; ++V) { var P = Math.floor(V / 20), F = Nt(w, 5) + ln(P, b, y, x) + T + e[P] + g[V] >>> 0; T = x, x = y, y = Nt(b, 30) >>> 0, b = w, w = F; } a[0] = a[0] + w >>> 0, a[1] = a[1] + b >>> 0, a[2] = a[2] + y >>> 0, a[3] = a[3] + x >>> 0, a[4] = a[4] + T >>> 0; } return [a[0] >> 24 & 255, a[0] >> 16 & 255, a[0] >> 8 & 255, 255 & a[0], a[1] >> 24 & 255, a[1] >> 16 & 255, a[1] >> 8 & 255, 255 & a[1], a[2] >> 24 & 255, a[2] >> 16 & 255, a[2] >> 8 & 255, 255 & a[2], a[3] >> 24 & 255, a[3] >> 16 & 255, a[3] >> 8 & 255, 255 & a[3], a[4] >> 24 & 255, a[4] >> 16 & 255, a[4] >> 8 & 255, 255 & a[4]]; }), dn = fn, Jt = Object.freeze({ __proto__: null, v1: function(t, e, a) { var n = e && a || 0, c = e || new Array(16), r = (t = t || {}).node || fe, o = t.clockseq !== void 0 ? t.clockseq : Ut; if (r == null || o == null) { var i = t.random || (t.rng || le)(); r == null && (r = fe = [1 | i[0], i[1], i[2], i[3], i[4], i[5]]), o == null && (o = Ut = 16383 & (i[6] << 8 | i[7])); } var s = t.msecs !== void 0 ? t.msecs : Date.now(), u = t.nsecs !== void 0 ? t.nsecs : Ft + 1, f = s - At + (u - Ft) / 1e4; if (f < 0 && t.clockseq === void 0 && (o = o + 1 & 16383), (f < 0 || s > At) && t.nsecs === void 0 && (u = 0), u >= 1e4) throw new Error("uuid.v1(): Can't create more than 10M uuids/sec"); At = s, Ft = u, Ut = o; var l = (1e4 * (268435455 & (s += 122192928e5)) + u) % 4294967296; c[n++] = l >>> 24 & 255, c[n++] = l >>> 16 & 255, c[n++] = l >>> 8 & 255, c[n++] = 255 & l; var g = s / 4294967296 * 1e4 & 268435455; c[n++] = g >>> 8 & 255, c[n++] = 255 & g, c[n++] = g >>> 24 & 15 | 16, c[n++] = g >>> 16 & 255, c[n++] = o >>> 8 | 128, c[n++] = 255 & o; for (var h = 0; h < 6; ++h) c[n + h] = r[h]; return e || yt(c); }, v3: un, v4: function(t, e, a) { var n = (t = t || {}).random || (t.rng || le)(); if (n[6] = 15 & n[6] | 64, n[8] = 63 & n[8] | 128, e) { a = a || 0; for (var c = 0; c < 16; ++c) e[a + c] = n[c]; return e; } return yt(n); }, v5: dn, NIL: "00000000-0000-0000-0000-000000000000", version: function(t) { if (!wt(t)) throw TypeError("Invalid UUID"); return parseInt(t.substr(14, 1), 16); }, validate: wt, stringify: yt, parse: Ue }); const it = ["debug", "info", "warn", "error", "none"]; var Kt = { commonBasicLogger: function(t, e) { if (t && t.destination && typeof t.destination != "function") throw new Error("destination for basicLogger was set to a non-function"); function a(u) { return function(f) { console && console[u] && console[u].call(console, f); }; } const n = t && t.destination ? [t.destination, t.destination, t.destination, t.destination] : [a("log"), a("info"), a("warn"), a("error")], c = !(!t || !t.destination), r = t && t.prefix !== void 0 && t.prefix !== null ? t.prefix : "[LaunchDarkly] "; let o = 1; if (t && t.level) for (let u = 0; u < it.length; u++) it[u] === t.level && (o = u); function i(u, f, l) { if (l.length < 1) return; let g; const h = c ? f + ": " + r : r; if (l.length !== 1 && e) { const m = [...l]; m[0] = h + m[0], g = e(...m); } else g = h + l[0]; try { n[u](g); } catch (m) { console && console.log && console.log("[LaunchDarkly] Configured logger's " + f + " method threw an exception: " + m); } } const s = {}; for (let u = 0; u < it.length; u++) { const f = it[u]; if (f !== "none") if (u < o) s[f] = () => { }; else { const l = u; s[f] = function() { i(l, f, arguments); }; } } return s; }, validateLogger: function(t) { it.forEach((e) => { if (e !== "none" && (!t[e] || typeof t[e] != "function")) throw new Error("Provided logger instance must support logger." + e + "(...) method"); }); } }; function dt(t) { return t && t.message ? t.message : typeof t == "string" || t instanceof String ? t : JSON.stringify(t); } const ot = " Please see https://docs.launchdarkly.com/sdk/client-side/javascript#initialize-the-client for instructions on SDK initialization."; var D = { bootstrapInvalid: function() { return "LaunchDarkly bootstrap data is not available because the back end could not read the flags."; }, bootstrapOldFormat: function() { return "LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly." + ot; }, clientInitialized: function() { return "LaunchDarkly client initialized"; }, clientNotReady: function() { return "LaunchDarkly client is not ready"; }, debugEnqueueingEvent: function(t) { return 'enqueueing "' + t + '" event'; }, debugPostingDiagnosticEvent: function(t) { return "sending diagnostic event (" + t.kind + ")"; }, debugPostingEvents: function(t) { return "sending " + t + " events"; }, debugStreamDelete: function(t) { return 'received streaming deletion for flag "' + t + '"'; }, debugStreamDeleteIgnored: function(t) { return 'received streaming deletion for flag "' + t + '" but ignored due to version check'; }, debugStreamPatch: function(t) { return 'received streaming update for flag "' + t + '"'; }, debugStreamPatchIgnored: function(t) { return 'received streaming update for flag "' + t + '" but ignored due to version check'; }, debugStreamPing: function() { return "received ping message from stream"; }, debugPolling: function(t) { return "polling for feature flags at " + t; }, debugStreamPut: function() { return "received streaming update for all flags"; }, deprecated: function(t, e) { return e ? '"' + t + '" is deprecated, please use "' + e + '"' : '"' + t + '" is deprecated'; }, environmentNotFound: function() { return "Environment not found. Double check that you specified a valid environment/client-side ID." + ot; }, environmentNotSpecified: function() { return "No environment/client-side ID was specified." + ot; }, errorFetchingFlags: function(t) { return "Error fetching flag settings: " + dt(t); }, eventCapacityExceeded: function() { return "Exceeded event queue capacity. Increase capacity to avoid dropping events."; }, eventWithoutContext: function() { return "Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"; }, httpErrorMessage: function(t, e, a) { return "Received error " + t + (t === 401 ? " (invalid SDK key)" : "") + " for " + e + " - " + (j.isHttpErrorRecoverable(t) ? a : "giving up permanently"); }, httpUnavailable: function() { return "Cannot make HTTP requests in this environment." + ot; }, identifyDisabled: function() { return "identify() has no effect here; it must be called on the main client instance"; }, inspectorMethodError: (t, e) => `an inspector: "${e}" of type: "${t}" generated an exception`, invalidContentType: function(t) { return 'Expected application/json content type but got "' + t + '"'; }, invalidData: function() { return "Invalid data received from LaunchDarkly; connection may have been interrupted"; }, invalidInspector: (t, e) => `an inspector: "${e}" of an invalid type (${t}) was configured`, invalidKey: function() { return "Event key must be a string"; }, invalidMetricValue: (t) => `The track function was called with a non-numeric "metricValue" (${t}), only numeric metric values are supported.`, invalidContext: function() { return "Invalid context specified." + ot; }, invalidTagValue: (t) => `Config option "${t}" must only contain letters, numbers, ., _ or -.`, localStorageUnavailable: function(t) { return "local storage is unavailable: " + dt(t); }, networkError: (t) => "network error" + (t ? " (" + t + ")" : ""), optionBelowMinimum: (t, e, a) => 'Config option "' + t + '" was set to ' + e + ", changing to minimum value of " + a, streamClosing: function() { return "Closing stream connection"; }, streamConnecting: function(t) { return "Opening stream connection to " + t; }, streamError: function(t, e) { return "Error on stream connection: " + dt(t) + ", will continue retrying after " + e + " milliseconds."; }, tagValueTooLong: (t) => `Value of "${t}" was longer than 64 characters and was discarded.`, unknownCustomEventKey: function(t) { return 'Custom event "' + t + '" does not exist'; }, unknownOption: (t) => 'Ignoring unknown config option "' + t + '"', contextNotSpecified: function() { return "No context specified." + ot; }, unrecoverableStreamError: (t) => `Error on stream connection ${dt(t)}, giving up permanently`, wrongOptionType: (t, e, a) => 'Config option "' + t + '" should be of type ' + e + ", got " + a + ", using default value", wrongOptionTypeBoolean: (t, e) => 'Config option "' + t + '" should be a boolean, got ' + e + ", converting to boolean" }; const { validateLogger: gn } = Kt, ge = { baseUrl: { default: "https://app.launchdarkly.com" }, streamUrl: { default: "https://clientstream.launchdarkly.com" }, eventsUrl: { default: "https://events.launchdarkly.com" }, sendEvents: { default: !0 }, streaming: { type: "boolean" }, sendLDHeaders: { default: !0 }, requestHeaderTransform: { type: "function" }, sendEventsOnlyForVariation: { default: !1 }, useReport: { default: !1 }, evaluationReasons: { default: !1 }, eventCapacity: { default: 100, minimum: 1 }, flushInterval: { default: 2e3, minimum: 2e3 }, samplingInterval: { default: 0, minimum: 0 }, streamReconnectDelay: { default: 1e3, minimum: 0 }, allAttributesPrivate: { default: !1 }, privateAttributes: { default: [] }, bootstrap: { type: "string|object" }, diagnosticRecordingInterval: { default: 9e5, minimum: 2e3 }, diagnosticOptOut: { default: !1 }, wrapperName: { type: "string" }, wrapperVersion: { type: "string" }, stateProvider: { type: "object" }, application: { validator: function(t, e, a) { const n = {}; return e.id && (n.id = ve(`${t}.id`, e.id, a)), e.version && (n.version = ve(`${t}.version`, e.version, a)), n; } }, inspectors: { default: [] }, hooks: { default: [] }, plugins: { default: [] } }, vn = /^(\w|\.|-)+$/; function jt(t) { return t && t.replace(/\/+$/, ""); } function ve(t, e, a) { if (typeof e == "string" && e.match(vn)) { if (!(e.length > 64)) return e; a.warn(D.tagValueTooLong(t)); } else a.warn(D.invalidTagValue(t)); } var Bt = { baseOptionDefs: ge, validate: function(t, e, a, n) { const c = I.extend({ logger: { default: n } }, ge, a), r = {}; function o(s) { I.onNextTick(() => { e && e.maybeReportError(new j.LDInvalidArgumentError(s)); }); } let i = I.extend({}, t || {}); return function(s) { const u = s; Object.keys(r).forEach((f) => { if (u[f] !== void 0) { const l = r[f]; n && n.warn(D.deprecated(f, l)), l && (u[l] === void 0 && (u[l] = u[f]), delete u[f]); } }); }(i), i = function(s) { const u = I.extend({}, s); return Object.keys(c).forEach((f) => { u[f] !== void 0 && u[f] !== null || (u[f] = c[f] && c[f].default); }), u; }(i), i = function(s) { const u = I.extend({}, s), f = (l) => { if (l === null) return "any"; if (l === void 0) return; if (Array.isArray(l)) return "array"; const g = typeof l; return g === "boolean" || g === "string" || g === "number" || g === "function" ? g : "object"; }; return Object.keys(s).forEach((l) => { const g = s[l]; if (g != null) { const h = c[l]; if (h === void 0) o(D.unknownOption(l)); else { const m = h.type || f(h.default), w = h.validator; if (w) { const b = w(l, s[l], n); b !== void 0 ? u[l] = b : delete u[l]; } else if (m !== "any") { const b = m.split("|"), y = f(g); b.indexOf(y) < 0 ? m === "boolean" ? (u[l] = !!g, o(D.wrongOptionTypeBoolean(l, y))) : (o(D.wrongOptionType(l, m, y)), u[l] = h.default) : y === "number" && h.minimum !== void 0 && g < h.minimum && (o(D.optionBelowMinimum(l, g, h.minimum)), u[l] = h.minimum); } } } }), u.baseUrl = jt(u.baseUrl), u.streamUrl = jt(u.streamUrl), u.eventsUrl = jt(u.eventsUrl), u; }(i), gn(i.logger), i; }, getTags: function(t) { const e = {}; return t && (t.application && t.application.id !== void 0 && t.application.id !== null && (e["application-id"] = [t.application.id]), t.application && t.application.version !== void 0 && t.application.id !== null && (e["application-version"] = [t.application.version])), e; } }; const { getLDUserAgentString: pn } = I; var Gt = { getLDHeaders: function(t, e) { if (e && !e.sendLDHeaders) return {}; const a = {}; a[t.userAgentHeaderName || "User-Agent"] = pn(t), e && e.wrapperName && (a["X-LaunchDarkly-Wrapper"] = e.wrapperVersion ? e.wrapperName + "/" + e.wrapperVersion : e.wrapperName); const n = Bt.getTags(e), c = Object.keys(n); return c.length && (a["x-launchdarkly-tags"] = c.sort().map((r) => Array.isArray(n[r]) ? n[r].sort().map((o) => `${r}/${o}`) : [`${r}/${n[r]}`]).reduce((r, o) => r.concat(o), []).join(" ")), a; }, transformHeaders: function(t, e) { return e && e.requestHeaderTransform ? e.requestHeaderTransform({ ...t }) : t; } }; const { v1: mn } = Jt, { getLDHeaders: hn, transformHeaders: yn } = Gt; var Ae = function(t, e, a) { const n = I.extend({ "Content-Type": "application/json" }, hn(t, a)), c = {}; return c.sendEvents = (r, o, i) => { if (!t.httpRequest) return Promise.resolve(); const s = JSON.stringify(r), u = i ? null : mn(); return function f(l) { const g = i ? n : I.extend({}, n, { "X-LaunchDarkly-Event-Schema": "4", "X-LaunchDarkly-Payload-ID": u }); return t.httpRequest("POST", o, yn(g, a), s).promise.then((h) => { if (h) return h.status >= 400 && j.isHttpErrorRecoverable(h.status) && l ? f(!1) : function(m) { const w = { status: m.status }, b = m.header("date"); if (b) { const y = Date.parse(b); y && (w.serverTime = y); } return w; }(h); }).catch(() => l ? f(!1) : Promise.reject()); }(!0).catch(() => { }); }, c; }, wn = function t(e, a = []) { if (e === null || typeof e != "object") return JSON.stringify(e); if (a.includes(e)) throw new Error("Cycle detected"); return Array.isArray(e) ? `[${e.map((n) => t(n, [...a, e])).map((n) => n === void 0 ? "null" : n).join(",")}]` : `{${Object.keys(e).sort().map((n) => { const c = t(e[n], [...a, e]); if (c !== void 0) return `${JSON.stringify(n)}:${c}`; }).filter((n) => n !== void 0).join(",")}}`; }; const { commonBasicLogger: bn } = Kt; function pe(t) { return typeof t == "string" && t !== "kind" && t.match(/^(\w|\.|-)+$/); } var kt = { checkContext: function(t, e) { if (t) { if (e && (t.kind === void 0 || t.kind === null)) return t.key !== void 0 && t.key !== null; const a = t.key, n = t.kind === void 0 ? "user" : t.kind, c = pe(n), r = n === "multi" || a != null && a !== ""; if (n === "multi") { const o = Object.keys(t).filter((i) => i !== "kind"); return r && o.every((i) => pe(i)) && o.every((i) => { const s = t[i].key; return s != null && s !== ""; }); } return r && c; } return !1; }, getContextKeys: function(t, e = bn()) { if (!t) return; const a = {}, { kind: n, key: c } = t; switch (n) { case void 0: a.user = `${c}`; break; case "multi": Object.entries(t).filter(([r]) => r !== "kind").forEach(([r, o]) => { o && o.key && (a[r] = o.key); }); break; case null: e.warn(`null is not a valid context kind: ${t}`); break; case "": e.warn(`'' is not a valid context kind: ${t}`); break; default: a[n] = `${c}`; } return a; }, getContextKinds: function(t) { return t ? t.kind === null || t.kind === void 0 ? ["user"] : t.kind !== "multi" ? [t.kind] : Object.keys(t).filter((e) => e !== "kind") : []; } }; const { getContextKinds: kn } = kt; var En = function() { const t = {}; let e = 0, a = 0, n = {}, c = {}; return t.summarizeEvent = (r) => { if (r.kind === "feature") { const o = r.key + ":" + (r.variation !== null && r.variation !== void 0 ? r.variation : "") + ":" + (r.version !== null && r.version !== void 0 ? r.version : ""), i = n[o]; let s = c[r.key]; s || (s = /* @__PURE__ */ new Set(), c[r.key] = s), function(u) { return u.context ? kn(u.context) : u.contextKeys ? Object.keys(u.contextKeys) : []; }(r).forEach((u) => s.add(u)), i ? i.count = i.count + 1 : n[o] = { count: 1, key: r.key, version: r.version, variation: r.variation, value: r.value, default: r.default }, (e === 0 || r.creationDate < e) && (e = r.creationDate), r.creationDate > a && (a = r.creationDate); } }, t.getSummary = () => { const r = {}; let o = !0; for (const i of Object.values(n)) { let s = r[i.key]; s || (s = { default: i.default, counters: [], contextKinds: [...c[i.key]] }, r[i.key] = s); const u = { value: i.value, count: i.count }; i.variation !== void 0 && i.variation !== null && (u.variation = i.variation), i.version !== void 0 && i.version !== null ? u.version = i.version : u.unknown = !0, s.counters.push(u), o = !1; } return o ? null : { startDate: e, endDate: a, features: r, kind: "summary" }; }, t.clearSummary = () => { e = 0, a = 0, n = {}, c = {}; }, t; }, Dn = function(t) { let e = {}, a = {}; return { summarizeEvent: function(n) { if (n.kind === "feature") { const c = wn(n.context); if (!c) return; let r = e[c]; r || (e[c] = En(), r = e[c], a[c] = n.context), r.summarizeEvent(n); } }, getSummaries: function() { const n = e, c = a; return e = {}, a = {}, Object.entries(n).map(([r, o]) => { const i = o.getSummary(); return i.context = t.filter(c[r]), i; }); } }; }; function Fe(t) { return t.replace(/~/g, "~0").replace(/\//g, "~1"); } function me(t) { return (t.startsWith("/") ? t.substring(1) : t).split("/").map((e) => e.indexOf("~") >= 0 ? e.replace(/~1/g, "/").replace(/~0/g, "~") : e); } function he(t) { return !t.startsWith("/"); } function ye(t, e) { const a = he(t), n = he(e); if (a && n) return t === e; if (a) { const c = me(e); return c.length === 1 && t === c[0]; } if (n) { const c = me(t); return c.length === 1 && e === c[0]; } return t === e; } function we(t) { return `/${Fe(t)}`; } var $t = { cloneExcluding: function(t, e) { const a = [], n = {}, c = []; for (a.push(...Object.keys(t).map((r) => ({ key: r, ptr: we(r), source: t, parent: n, visited: [t] }))); a.length; ) { const r = a.pop(); if (e.some((o) => ye(o, r.ptr))) c.push(r.ptr); else { const o = r.source[r.key]; if (o === null) r.parent[r.key] = o; else if (Array.isArray(o)) r.parent[r.key] = [...o]; else if (typeof o == "object") { if (r.visited.includes(o)) continue; r.parent[r.key] = {}, a.push(...Object.keys(o).map((i) => { return { key: i, ptr: (s = r.ptr, u = Fe(i), `${s}/${u}`), source: o, parent: r.parent[r.key], visited: [...r.visited, o] }; var s, u; })); } else r.parent[r.key] = o; } } return { cloned: n, excluded: c.sort() }; }, compare: ye, literalToReference: we }, xn = function(t) { const e = {}, a = t.allAttributesPrivate, n = t.privateAttributes || [], c = ["key", "kind", "_meta", "anonymous"], r = ["name", "ip", "firstName", "lastName", "email", "avatar", "country"], o = (i, s) => { if (typeof i != "object" || i === null || Array.isArray(i)) return; const { cloned: u, excluded: f } = $t.cloneExcluding(i, ((l, g) => (a || g && l.anonymous ? Object.keys(l) : [...n, ...l._meta && l._meta.privateAttributes || []]).filter((h) => !c.some((m) => $t.compare(h, m))))(i, s)); return u.key = String(u.key), f.length && (u._meta || (u._meta = {}), u._meta.redactedAttributes = f), u._meta && (delete u._meta.privateAttributes, Object.keys(u._meta).length === 0 && delete u._meta), u.anonymous !== void 0 && (u.anonymous = !!u.anonymous), u; }; return e.filter = (i, s = !1) => i.kind === void 0 || i.kind === null ? o(((u) => { const f = { ...u.custom || {}, kind: "user", key: u.key }; u.anonymous !== void 0 && (f.anonymous = !!u.anonymous); for (const l of r) delete f[l], u[l] !== void 0 && u[l] !== null && (f[l] = String(u[l])); return u.privateAttributeNames !== void 0 && u.privateAttributeNames !== null && (f._meta = f._meta || {}, f._meta.privateAttributes = u.privateAttributeNames.map((l) => l.startsWith("/") ? $t.literalToReference(l) : l)), f; })(i), s) : i.kind === "multi" ? ((u, f) => { const l = { kind: u.kind }, g = Object.keys(u); for (const h of g) if (h !== "kind") { const m = o(u[h], f); m && (l[h] = m); } return l; })(i, s) : o(i, s), e; }; const { getContextKeys: In } = kt; var Sn = function(t, e, a, n = null, c = null, r = null) { const o = {}, i = r || Ae(t, a, e), s = I.appendUrlPath(e.eventsUrl, "/events/bulk/" + a), u = xn(e), f = Dn(u), l = e.samplingInterval, g = e.eventCapacity, h = e.flushInterval, m = e.logger; let w, b = [], y = 0, x = !1, T = !1; function V() { return l === 0 || Math.floor(Math.random() * l) === 0; } function P(S) { const C = I.extend({}, S); return S.kind === "identify" || S.kind === "feature" || S.kind === "custom" ? C.context = u.filter(S.context) : (C.contextKeys = In(S.context, m), delete C.context), S.kind === "feature" && (delete C.trackEvents, delete C.debugEventsUntilDate), C; } function F(S) { b.length < g ? (b.push(S), T = !1) : (T || (T = !0, m.warn(D.eventCapacityExceeded())), n && n.incrementDroppedEvents()); } return o.enqueue = function(S) { if (x) return; let C = !1, B = !1; var L; if (f.summarizeEvent(S), S.kind === "feature" ? V() && (C = !!S.trackEvents, B = !!(L = S).debugEventsUntilDate && L.debugEventsUntilDate > y && L.debugEventsUntilDate > (/* @__PURE__ */ new Date()).getTime()) : C = V(), C && F(P(S)), B) { const O = I.extend({}, S, { kind: "debug" }); O.context = u.filter(O.context), delete O.trackEvents, delete O.debugEventsUntilDate, F(O); } }, o.flush = async function() { if (x) return Promise.resolve(); const S = b; return f.getSummaries().forEach((C) => { Object.keys(C.features).length && S.push(C); }), n && n.setEventsInLastBatch(S.length), S.length === 0 ? Promise.resolve() : (b = [], m.debug(D.debugPostingEvents(S.length)), i.sendEvents(S, s).then((C) => { C && (C.serverTime && (y = C.serverTime), j.isHttpErrorRecoverable(C.status) || (x = !0), C.status >= 400 && I.onNextTick(() => { c.maybeReportError(new j.LDUnexpectedResponseError(D.httpErrorMessage(C.status, "event posting", "some events were dropped"))); })); })); }, o.start = function() { const S = () => { o.flush(), w = setTimeout(S, h); }; w = setTimeout(S, h); }, o.stop = function() { clearTimeout(w); }, o; }, Pn = function(t) { const e = {}, a = {}; return e.on = function(n, c, r) { a[n] = a[n] || [], a[n] = a[n].concat({ handler: c, context: r }); }, e.off = function(n, c, r) { if (a[n]) for (let o = 0; o < a[n].length; o++) a[n][o].handler === c && a[n][o].context === r && (a[n] = a[n].slice(0, o).concat(a[n].slice(o + 1))); }, e.emit = function(n) { if (!a[n]) return; const c = a[n].slice(0); for (let r = 0; r < c.length; r++) c[r].handler.apply(c[r].context, Array.prototype.slice.call(arguments, 1)); }, e.getEvents = function() { return Object.keys(a); }, e.getEventListenerCount = function(n) { return a[n] ? a[n].length : 0; }, e.maybeReportError = function(n) { n && (a.error ? this.emit("error", n) : (t || console).error(n.message)); }, e; }; const gt = "ready", Vt = "initialized", Ht = "failed"; var Cn = function(t) { let e = !1, a = !1, n = null, c = null; const r = new Promise((o) => { const i = () => { t.off(gt, i), o(); }; t.on(gt, i); }).catch(() => { }); return { getInitializationPromise: () => c || (e ? Promise.resolve() : a ? Promise.reject(n) : (c = new Promise((o, i) => { const s = () => { t.off(Vt, s), o(); }, u = (f) => { t.off(Ht, u), i(f); }; t.on(Vt, s), t.on(Ht, u); }), c)), getReadyPromise: () => r, signalSuccess: () => { e || a || (e = !0, t.emit(Vt), t.emit(gt)); }, signalFailure: (o) => { e || a || (a = !0, n = o, t.emit(Ht, o), t.emit(gt)), t.maybeReportError(o); } }; }, Ln = function(t, e, a, n) { const c = {}; function r() { let o = ""; const i = n.getContext(); return i && (o = a || I.btoa(JSON.stringify(i))), "ld:" + e + ":" + o; } return c.loadFlags = () => t.get(r()).then((o) => { if (o == null) return null; try { let i = JSON.parse(o); if (i) { const s = i.$schema; s === void 0 || s < 1 ? i = I.transformValuesToVersionedValues(i) : delete i.$schema; } return i; } catch { return c.clearFlags().then(() => null); } }), c.saveFlags = (o) => { const i = I.extend({}, o, { $schema: 1 }); return t.set(r(), JSON.stringify(i)); }, c.clearFlags = () => t.clear(r()), c; }, Tn = function(t, e) { const a = {}; let n = !1; const c = (r) => { n || (n = !0, e.warn(D.localStorageUnavailable(r))); }; return a.isEnabled = () => !!t, a.get = (r) => new Promise((o) => { t ? t.get(r).then(o).catch((i) => { c(i), o(void 0); }) : o(void 0); }), a.set = (r, o) => new Promise((i) => { t ? t.set(r, o).then(() => i(!0)).catch((s) => { c(s), i(!1); }) : i(!1); }), a.clear = (r) => new Promise((o) => { t ? t.clear(r).then(() => o(!0)).catch((i) => { c(i), o(!1); }) : o(!1); }), a; }; const { appendUrlPath: be, base64URLEncode: On, objectHasOwnProperty: Un } = I, { getLDHeaders: Rn, transformHeaders: An } = Gt, { isHttpErrorRecoverable: Fn } = j; var Nn = function(t, e, a, n) { const c = e.streamUrl, r = e.logger, o = {}, i = be(c, "/eval/" + a), s = e.useReport, u = e.evaluationReasons, f = e.streamReconnectDelay, l = Rn(t, e); let g, h = !1, m = null, w = null, b = null, y = null, x = null, T = 0; function V() { const L = (O = function() { const H = f * Math.pow(2, T); return H > 3e4 ? 3e4 : H; }(), O - Math.trunc(0.5 * Math.random() * O)); var O; return T += 1, L; } function P(L) { if (L.status && typeof L.status == "number" && !Fn(L.status)) return C(), r.error(D.unrecoverableStreamError(L)), void (w && (clearTimeout(w), w = null)); const O = V(); h || (r.warn(D.streamError(L, O)), h = !0), B(!1), C(), F(O); } function F(L) { w || (L ? w = setTimeout(S, L) : S()); } function S() { let L; w = null; let O = ""; const H = { headers: l, readTimeoutMillis: 3e5 }; if (t.eventSourceFactory) { y != null && (O = "h=" + y), s ? t.eventSourceAllowsReport ? (L = i, H.method = "REPORT", H.headers["Content-Type"] = "application/json", H.body = JSON.stringify(b)) : (L = be(c, "/ping/" + a), O = "") : L = i + "/" + On(JSON.stringify(b)), H.headers = An(H.headers, e), u && (O = O + (O ? "&" : "") + "withReasons=true"), L = L + (O ? "?" : "") + O, C(), r.info(D.streamConnecting(L)), g = (/* @__PURE__ */ new Date()).getTime(), m = t.eventSourceFactory(L, H); for (const k in x) Un(x, k) && m.addEventListener(k, x[k]); m.onerror = P, m.onopen = () => { T = 0; }; } } function C() { m && (r.info(D.streamClosing()), m.close(), m = null); } function B(L) { g && n && n.recordStreamInit(g, !L, (/* @__PURE__ */ new Date()).getTime() - g), g = null; } return o.connect = function(L, O, H) { b = L, y = O, x = {}; for (const k in H || {}) x[k] = function(Z) { h = !1, B(!0), H[k] && H[k](Z); }; F(); }, o.disconnect = function() { clearTimeout(w), w = null, C(); }, o.isConnected = function() { return !!(m && t.eventSourceIsActive && t.eventSourceIsActive(m)); }, o; }, jn = function(t) { let e, a, n, c; const r = { addPromise: (o, i) => { e = o, a && a(), a = i, o.then((s) => { e === o && (n(s), t && t()); }, (s) => { e === o && (c(s), t && t()); }); } }; return r.resultPromise = new Promise((o, i) => { n = o, c = i; }), r; }; const { transformHeaders: $n, getLDHeaders: Vn } = Gt, ke = "application/json"; var Hn = function(t, e, a) { const n = e.baseUrl, c = e.useReport, r = e.evaluationReasons, o = e.logger, i = {}, s = {}; function u(f, l) { if (!t.httpRequest) return new Promise((y, x) => { x(new j.LDFlagFetchError(D.httpUnavailable())); }); const g = l ? "REPORT" : "GET", h = Vn(t, e); l && (h["Content-Type"] = ke); let m = s[f]; m || (m = jn(() => { delete s[f]; }), s[f] = m); const w = t.httpRequest(g, f, $n(h, e), l), b = w.promise.then((y) => { if (y.status === 200) { if (y.header("content-type") && y.header("content-type").substring(0, 16) === ke) return JSON.parse(y.body); { const x = D.invalidContentType(y.header("content-type") || ""); return Promise.reject(new j.LDFlagFetchError(x)); } } return Promise.reject(function(x) { return x.status === 404 ? new j.LDInvalidEnvironmentIdError(D.environmentNotFound()) : new j.LDFlagFetchError(D.errorFetchingFlags(x.statusText || String(x.status))); }(y)); }, (y) => Promise.reject(new j.LDFlagFetchError(D.networkError(y)))); return m.addPromise(b, () => { w.cancel && w.cancel(); }), m.resultPromise; } return i.fetchJSON = function(f) { return u(I.appendUrlPath(n, f), null); }, i.fetchFlagSettings = function(f, l) { let g, h, m, w = ""; return c ? (h = [n, "/sdk/evalx/", a, "/context"].join(""), m = JSON.stringify(f)) : (g = I.base64URLEncode(JSON.stringify(f)), h = [n, "/sdk/evalx/", a, "/contexts/", g].join("")), l && (w = "h=" + l), r && (w = w + (w ? "&" : "") + "withReasons=true"), h = h + (w ? "?" : "") + w, o.debug(D.debugPolling(h)), u(h, m); }, i; }, Mn = function(t, e) { const a = {}; let n; return a.setContext = function(c) { n = I.sanitizeContext(c), n && e && e(I.clone(n)); }, a.getContext = function() { return n ? I.clone(n) : null; }, a; }; const { v1: qn } = Jt, { getContextKinds: _n } = kt; var zn = function(t) { function e(n) { return n == null || n === "user" ? "ld:$anonUserId" : `ld:$contextKey:${n}`; } function a(n, c) { return c.key !== null && c.key !== void 0 ? (c.key = c.key.toString(), Promise.resolve(c)) : c.anonymous ? function(r) { return t.get(e(r)); }(n).then((r) => { if (r) return c.key = r, c; { const o = qn(); return c.key = o, function(i, s) { return t.set(e(s), i); }(o, n).then(() => c); } }) : Promise.reject(new j.LDInvalidUserError(D.invalidContext())); } this.processContext = (n) => { if (!n) return Promise.reject(new j.LDInvalidUserError(D.contextNotSpecified())); const c = I.clone(n); if (n.kind === "multi") { const r = _n(c); return Promise.all(r.map((o) => a(o, c[o]))).then(() => c); } return a(n.kind, c); }; }; const { v1: Jn } = Jt, { baseOptionDefs: Mt } = Bt, { appendUrlPath: Kn } = I; var qt = { DiagnosticId: function(t) { const e = { diagnosticId: Jn() }; return t && (e.sdkKeySuffix = t.length > 6 ? t.substring(t.length - 6) : t), e; }, DiagnosticsAccumulator: function(t) { let e, a, n, c; function r(o) { e = o, a = 0, n = 0, c = []; } return r(t), { getProps: () => ({ dataSinceDate: e, droppedEvents: a, eventsInLastBatch: n, streamInits: c }), setProps: (o) => { e = o.dataSinceDate, a = o.droppedEvents || 0, n = o.eventsInLastBatch || 0, c = o.streamInits || []; }, incrementDroppedEvents: () => { a++; }, setEventsInLastBatch: (o) => { n = o; }, recordStreamInit: (o, i, s) => { const u = { timestamp: o, failed: i, durationMillis: s }; c.push(u); }, reset: r }; }, DiagnosticsManager: function(t, e, a, n, c, r, o) { const i = !!t.diagnosticUseCombinedEvent, s = "ld:" + c + ":$diagnostics", u = Kn(r.eventsUrl, "/events/diagnostic/" + c), f = r.diagnosticRecordingInterval, l = a; let g, h, m = !!r.streaming; const w = {}; function b() { return { sdk: T(), configuration: V(), platform: t.diagnosticPlatformData }; } function y(P) { r.logger && r.logger.debug(D.debugPostingDiagnosticEvent(P)), n.sendEvents(P, u, !0).then(() => { }).catch(() => { }); } function x() { y(function() { const P = (/* @__PURE__ */ new Date()).getTime(); let F = { kind: i ? "diagnostic-combined" : "diagnostic", id: o, creationDate: P, ...l.getProps() }; return i && (F = { ...F, ...b() }), l.reset(P), F; }()), h = setTimeout(x, f), g = (/* @__PURE__ */ new Date()).getTime(), i && function() { if (e.isEnabled()) { const P = { ...l.getProps() }; e.set(s, JSON.stringify(P)); } }(); } function T() { const P = { ...t.diagnosticSdkData }; return r.wrapperName && (P.wrapperName = r.wrapperName), r.wrapperVersion && (P.wrapperVersion = r.wrapperVersion), P; } function V() { return { customBaseURI: r.baseUrl !== Mt.baseUrl.default, customStreamURI: r.streamUrl !== Mt.streamUrl.default, customEventsURI: r.eventsUrl !== Mt.eventsUrl.default, eventsCapacity: r.eventCapacity, eventsFlushIntervalMillis: r.flushInterval, reconnectTimeMillis: r.streamReconnectDelay, streamingDisabled: !m, allAttributesPrivate: !!r.allAttributesPrivate, diagnosticRecordingIntervalMillis: r.diagnosticRecordingInterval, usingSecureMode: !!r.hash, bootstrapMode: !!r.bootstrap, fetchGoalsDisabled: !r.fetchGoals, sendEventsOnlyForVariation: !!r.sendEventsOnlyForVariation }; } return w.start = () => { i ? function(P) { if (!e.isEnabled()) return P(!1); e.get(s).then((F) => { if (F) try { const S = JSON.parse(F); l.setProps(S), g = S.dataSinceDate; } catch { } P(!0); }).catch(() => { P(!1); }); }((P) => { if (P) { const F = (g || 0) + f, S = (/* @__PURE__ */ new Date()).getTime(); S >= F ? x() : h = setTimeout(x, F - S); } else Math.floor(4 * Math.random()) === 0 ? x() : h = setTimeout(x, f); }) : (y({ kind: "diagnostic-init", id: o, creationDate: l.getProps().dataSinceDate, ...b() }), h = setTimeout(x, f)); }, w.stop = () => { h && clearTimeout(h); }, w.setStreaming = (P) => { m = P; }, w; } }, Bn = function(t, e) { let a = !1; const n = { type: t.type, name: t.name, synchronous: t.synchronous, method: (...c) => { try { t.method(...c); } catch { a || (a = !0, e.warn(D.inspectorMethodError(n.type, n.name))); } } }; return n; }; const { onNextTick: vt } = I, K = { flagUsed: "flag-used", flagDetailsChanged: "flag-details-changed", flagDetailChanged: "flag-detail-changed", clientIdentityChanged: "client-identity-changed" }; Object.freeze(K); var Gn = { InspectorTypes: K, InspectorManager: function(t, e) { const a = {}, n = { [K.flagUsed]: [], [K.flagDetailsChanged]: [], [K.flagDetailChanged]: [], [K.clientIdentityChanged]: [] }, c = { [K.flagUsed]: [], [K.flagDetailsChanged]: [], [K.flagDetailChanged]: [], [K.clientIdentityChanged]: [] }, r = t && t.map((o) => Bn(o, e)); return r && r.forEach((o) => { Object.prototype.hasOwnProperty.call(n, o.type) && !o.synchronous ? n[o.type].push(o) : Object.prototype.hasOwnProperty.call(c, o.type) && o.synchronous ? c[o.type].push(o) : e.warn(D.invalidInspector(o.type, o.name)); }), a.hasListeners = (o) => n[o] && n[o].length || c[o] && c[o].length, a.onFlagUsed = (o, i, s) => { const u = K.flagUsed; c[u].length && c[u].forEach((f) => f.method(o, i, s)), n[u].length && vt(() => { n[u].forEach((f) => f.method(o, i, s));