@lectra/ld-react-feature-flags
Version:
Integrate Launch Darkly in your React app in a breeze
572 lines (542 loc) • 82 kB
JavaScript
'use strict';
var React = require('react');
var PropTypes = require('prop-types');
function _typeof$1(o) {
"@babel/helpers - typeof";
return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof$1(o);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _toPrimitive(input, hint) {
if (_typeof$1(input) !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (_typeof$1(res) !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return _typeof$1(key) === "symbol" ? key : String(key);
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _possibleConstructorReturn(self, call) {
if (call && (_typeof$1(call) === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
var FlagsContext = /*#__PURE__*/React.createContext();
var camelize = function camelize(str) {
return str.replace(/\W+(.)/g, function (match, chr) {
return chr.toUpperCase();
});
};
function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
var FlagsConsumer = /*#__PURE__*/function (_Component) {
_inherits(FlagsConsumer, _Component);
var _super = _createSuper$2(FlagsConsumer);
function FlagsConsumer() {
var _this;
_classCallCheck(this, FlagsConsumer);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "renderChildrenOrRenderOn", function (featureProps, children, renderOn) {
if (renderOn) {
return renderOn(featureProps);
}
if (children && _typeof$1(children)) {
return /*#__PURE__*/React.cloneElement(children, {
flag: featureProps
});
}
return React.Fragment;
});
return _this;
}
_createClass(FlagsConsumer, [{
key: "render",
value: function render() {
var _this2 = this;
var _this$props = this.props,
flag = _this$props.flag,
children = _this$props.children,
renderOn = _this$props.renderOn,
fallbackRender = _this$props.fallbackRender;
return /*#__PURE__*/React.createElement(FlagsContext.Consumer, null, function (ldClient) {
var flagValue = ldClient.variation(flag, false);
var featureProps = _defineProperty({}, camelize(flag), flagValue);
return function () {
if (flagValue === true) {
return _this2.renderChildrenOrRenderOn(featureProps, children, renderOn);
}
if (flagValue === false) {
return fallbackRender ? fallbackRender(featureProps) : null;
}
if (typeof flagValue !== 'boolean') {
return _this2.renderChildrenOrRenderOn(featureProps, children, renderOn);
}
return null;
}();
});
}
}]);
return FlagsConsumer;
}(React.Component);
_defineProperty(FlagsConsumer, "propTypes", {
children: PropTypes.any,
flag: PropTypes.string.isRequired,
renderOn: PropTypes.func,
fallbackRender: PropTypes.func
});
_defineProperty(FlagsConsumer, "defaultProps", {
renderOn: undefined,
fallbackRender: undefined
});
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
var regeneratorRuntime$1 = {exports: {}};
var _typeof = {exports: {}};
(function (module) {
function _typeof(o) {
"@babel/helpers - typeof";
return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(o);
}
module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
} (_typeof));
var _typeofExports = _typeof.exports;
(function (module) {
var _typeof = _typeofExports["default"];
function _regeneratorRuntime() {
module.exports = _regeneratorRuntime = function _regeneratorRuntime() {
return e;
}, module.exports.__esModule = true, module.exports["default"] = module.exports;
var t,
e = {},
r = Object.prototype,
n = r.hasOwnProperty,
o = Object.defineProperty || function (t, e, r) {
t[e] = r.value;
},
i = "function" == typeof Symbol ? Symbol : {},
a = i.iterator || "@@iterator",
c = i.asyncIterator || "@@asyncIterator",
u = i.toStringTag || "@@toStringTag";
function define(t, e, r) {
return Object.defineProperty(t, e, {
value: r,
enumerable: !0,
configurable: !0,
writable: !0
}), t[e];
}
try {
define({}, "");
} catch (t) {
define = function define(t, e, r) {
return t[e] = r;
};
}
function wrap(t, e, r, n) {
var i = e && e.prototype instanceof Generator ? e : Generator,
a = Object.create(i.prototype),
c = new Context(n || []);
return o(a, "_invoke", {
value: makeInvokeMethod(t, r, c)
}), a;
}
function tryCatch(t, e, r) {
try {
return {
type: "normal",
arg: t.call(e, r)
};
} catch (t) {
return {
type: "throw",
arg: t
};
}
}
e.wrap = wrap;
var h = "suspendedStart",
l = "suspendedYield",
f = "executing",
s = "completed",
y = {};
function Generator() {}
function GeneratorFunction() {}
function GeneratorFunctionPrototype() {}
var p = {};
define(p, a, function () {
return this;
});
var d = Object.getPrototypeOf,
v = d && d(d(values([])));
v && v !== r && n.call(v, a) && (p = v);
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
function defineIteratorMethods(t) {
["next", "throw", "return"].forEach(function (e) {
define(t, e, function (t) {
return this._invoke(e, t);
});
});
}
function AsyncIterator(t, e) {
function invoke(r, o, i, a) {
var c = tryCatch(t[r], t, o);
if ("throw" !== c.type) {
var u = c.arg,
h = u.value;
return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
invoke("next", t, i, a);
}, function (t) {
invoke("throw", t, i, a);
}) : e.resolve(h).then(function (t) {
u.value = t, i(u);
}, function (t) {
return invoke("throw", t, i, a);
});
}
a(c.arg);
}
var r;
o(this, "_invoke", {
value: function value(t, n) {
function callInvokeWithMethodAndArg() {
return new e(function (e, r) {
invoke(t, n, e, r);
});
}
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
}
});
}
function makeInvokeMethod(e, r, n) {
var o = h;
return function (i, a) {
if (o === f) throw new Error("Generator is already running");
if (o === s) {
if ("throw" === i) throw a;
return {
value: t,
done: !0
};
}
for (n.method = i, n.arg = a;;) {
var c = n.delegate;
if (c) {
var u = maybeInvokeDelegate(c, n);
if (u) {
if (u === y) continue;
return u;
}
}
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
if (o === h) throw o = s, n.arg;
n.dispatchException(n.arg);
} else "return" === n.method && n.abrupt("return", n.arg);
o = f;
var p = tryCatch(e, r, n);
if ("normal" === p.type) {
if (o = n.done ? s : l, p.arg === y) continue;
return {
value: p.arg,
done: n.done
};
}
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
}
};
}
function maybeInvokeDelegate(e, r) {
var n = r.method,
o = e.iterator[n];
if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
var i = tryCatch(o, e.iterator, r.arg);
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
var a = i.arg;
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
}
function pushTryEntry(t) {
var e = {
tryLoc: t[0]
};
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
}
function resetTryEntry(t) {
var e = t.completion || {};
e.type = "normal", delete e.arg, t.completion = e;
}
function Context(t) {
this.tryEntries = [{
tryLoc: "root"
}], t.forEach(pushTryEntry, this), this.reset(!0);
}
function values(e) {
if (e || "" === e) {
var r = e[a];
if (r) return r.call(e);
if ("function" == typeof e.next) return e;
if (!isNaN(e.length)) {
var o = -1,
i = function next() {
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
return next.value = t, next.done = !0, next;
};
return i.next = i;
}
}
throw new TypeError(_typeof(e) + " is not iterable");
}
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
value: GeneratorFunctionPrototype,
configurable: !0
}), o(GeneratorFunctionPrototype, "constructor", {
value: GeneratorFunction,
configurable: !0
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
var e = "function" == typeof t && t.constructor;
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
}, e.mark = function (t) {
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
}, e.awrap = function (t) {
return {
__await: t
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
return this;
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
void 0 === i && (i = Promise);
var a = new AsyncIterator(wrap(t, r, n, o), i);
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
return t.done ? t.value : a.next();
});
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
return this;
}), define(g, "toString", function () {
return "[object Generator]";
}), e.keys = function (t) {
var e = Object(t),
r = [];
for (var n in e) r.push(n);
return r.reverse(), function next() {
for (; r.length;) {
var t = r.pop();
if (t in e) return next.value = t, next.done = !1, next;
}
return next.done = !0, next;
};
}, e.values = values, Context.prototype = {
constructor: Context,
reset: function reset(e) {
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
},
stop: function stop() {
this.done = !0;
var t = this.tryEntries[0].completion;
if ("throw" === t.type) throw t.arg;
return this.rval;
},
dispatchException: function dispatchException(e) {
if (this.done) throw e;
var r = this;
function handle(n, o) {
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
}
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
var i = this.tryEntries[o],
a = i.completion;
if ("root" === i.tryLoc) return handle("end");
if (i.tryLoc <= this.prev) {
var c = n.call(i, "catchLoc"),
u = n.call(i, "finallyLoc");
if (c && u) {
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
} else if (c) {
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
} else {
if (!u) throw new Error("try statement without catch or finally");
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
}
}
}
},
abrupt: function abrupt(t, e) {
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
var o = this.tryEntries[r];
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
var i = o;
break;
}
}
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
var a = i ? i.completion : {};
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
},
complete: function complete(t, e) {
if ("throw" === t.type) throw t.arg;
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
},
finish: function finish(t) {
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
var r = this.tryEntries[e];
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
}
},
"catch": function _catch(t) {
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
var r = this.tryEntries[e];
if (r.tryLoc === t) {
var n = r.completion;
if ("throw" === n.type) {
var o = n.arg;
resetTryEntry(r);
}
return o;
}
}
throw new Error("illegal catch attempt");
},
delegateYield: function delegateYield(e, r, n) {
return this.delegate = {
iterator: values(e),
resultName: r,
nextLoc: n
}, "next" === this.method && (this.arg = t), y;
}
}, e;
}
module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
} (regeneratorRuntime$1));
var regeneratorRuntimeExports = regeneratorRuntime$1.exports;
// TODO(Babel 8): Remove this file.
var runtime = regeneratorRuntimeExports();
var regenerator = runtime;
// Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
try {
regeneratorRuntime = runtime;
} catch (accidentalStrictMode) {
if (typeof globalThis === "object") {
globalThis.regeneratorRuntime = runtime;
} else {
Function("r", "regeneratorRuntime = r")(runtime);
}
}
var _regeneratorRuntime = /*@__PURE__*/getDefaultExportFromCjs(regenerator);
function e(e){function t(e,t){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=t;}return t.prototype=new Error,t.prototype.name=e,t.prototype.constructor=t,t}const t=e("LaunchDarklyUnexpectedResponseError"),n=e("LaunchDarklyInvalidEnvironmentIdError"),r=e("LaunchDarklyInvalidUserError"),o=e("LaunchDarklyInvalidEventKeyError"),i=e("LaunchDarklyInvalidArgumentError"),a=e("LaunchDarklyFlagFetchError");for(var s={LDUnexpectedResponseError:t,LDInvalidEnvironmentIdError:n,LDInvalidUserError:r,LDInvalidEventKeyError:o,LDInvalidArgumentError:i,LDInvalidDataError:e("LaunchDarklyInvalidDataError"),LDFlagFetchError:a,isHttpErrorRecoverable:function(e){return !(e>=400&&e<500)||(400===e||408===e||429===e)}},c=function(e){var t=m(e),n=t[0],r=t[1];return 3*(n+r)/4-r},u=function(e){var t,n,r=m(e),o=r[0],i=r[1],a=new g(function(e,t,n){return 3*(t+n)/4-n}(0,o,i)),s=0,c=i>0?o-4:o;for(n=0;n<c;n+=4)t=f[e.charCodeAt(n)]<<18|f[e.charCodeAt(n+1)]<<12|f[e.charCodeAt(n+2)]<<6|f[e.charCodeAt(n+3)],a[s++]=t>>16&255,a[s++]=t>>8&255,a[s++]=255&t;2===i&&(t=f[e.charCodeAt(n)]<<2|f[e.charCodeAt(n+1)]>>4,a[s++]=255&t);1===i&&(t=f[e.charCodeAt(n)]<<10|f[e.charCodeAt(n+1)]<<4|f[e.charCodeAt(n+2)]>>2,a[s++]=t>>8&255,a[s++]=255&t);return a},l=function(e){for(var t,n=e.length,r=n%3,o=[],i=16383,a=0,s=n-r;a<s;a+=i)o.push(h(e,a,a+i>s?s:a+i));1===r?(t=e[n-1],o.push(d[t>>2]+d[t<<4&63]+"==")):2===r&&(t=(e[n-2]<<8)+e[n-1],o.push(d[t>>10]+d[t>>4&63]+d[t<<2&63]+"="));return o.join("")},d=[],f=[],g="undefined"!=typeof Uint8Array?Uint8Array:Array,v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",p=0;p<64;++p)d[p]=v[p],f[v.charCodeAt(p)]=p;function m(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return -1===n&&(n=t),[n,n===t?0:4-n%4]}function h(e,t,n){for(var r,o,i=[],a=t;a<n;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),i.push(d[(o=r)>>18&63]+d[o>>12&63]+d[o>>6&63]+d[63&o]);return i.join("")}f["-".charCodeAt(0)]=62,f["_".charCodeAt(0)]=63;var y={byteLength:c,toByteArray:u,fromByteArray:l},w=Array.isArray,b=Object.keys,k=Object.prototype.hasOwnProperty,E=function e(t,n){if(t===n)return !0;if(t&&n&&"object"==typeof t&&"object"==typeof n){var r,o,i,a=w(t),s=w(n);if(a&&s){if((o=t.length)!=n.length)return !1;for(r=o;0!=r--;)if(!e(t[r],n[r]))return !1;return !0}if(a!=s)return !1;var c=t instanceof Date,u=n instanceof Date;if(c!=u)return !1;if(c&&u)return t.getTime()==n.getTime();var l=t instanceof RegExp,d=n instanceof RegExp;if(l!=d)return !1;if(l&&d)return t.toString()==n.toString();var f=b(t);if((o=f.length)!==b(n).length)return !1;for(r=o;0!=r--;)if(!k.call(n,f[r]))return !1;for(r=o;0!=r--;)if(!e(t[i=f[r]],n[i]))return !1;return !0}return t!=t&&n!=n};const D=["key","ip","country","email","firstName","lastName","avatar","name"];function C(e){const t=unescape(encodeURIComponent(e));return y.fromByteArray(function(e){const t=[];for(let n=0;n<e.length;n++)t.push(e.charCodeAt(n));return t}(t))}function x(e){return C(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function P(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var S,I={appendUrlPath:function(e,t){return (e.endsWith("/")?e.substring(0,e.length-1):e)+(t.startsWith("/")?"":"/")+t},base64URLEncode:x,btoa:C,chunkEventsForUrl:function(e,t){const n=t.slice(0),r=[];let o,i=e;for(;n.length>0;){for(o=[];i>0;){const e=n.shift();if(!e)break;i-=x(JSON.stringify(e)).length,i<0&&o.length>0?n.unshift(e):o.push(e);}i=e,r.push(o);}return r},clone:function(e){return JSON.parse(JSON.stringify(e))},deepEquals:function(e,t){return E(e,t)},extend:function(...e){return e.reduce(((e,t)=>({...e,...t})),{})},getLDUserAgentString:function(e){const t=e.version||"?";return e.userAgent+"/"+t},objectHasOwnProperty:P,onNextTick:function(e){setTimeout(e,0);},sanitizeContext:function(e){if(!e)return e;let t;return null!==e.kind&&void 0!==e.kind||D.forEach((n=>{const r=e[n];void 0!==r&&"string"!=typeof r&&(t=t||{...e},t[n]=String(r));})),t||e},transformValuesToVersionedValues:function(e){const t={};for(const n in e)P(e,n)&&(t[n]={value:e[n],version:0});return t},transformVersionedValuesToValues:function(e){const t={};for(const n in e)P(e,n)&&(t[n]=e[n].value);return t},wrapPromiseCallback:function(e,t){const n=e.then((e=>(t&&setTimeout((()=>{t(null,e);}),0),e)),(e=>{if(!t)return Promise.reject(e);setTimeout((()=>{t(e,null);}),0);}));return t?void 0:n}},O=new Uint8Array(16);function L(){if(!S&&!(S="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return S(O)}var U=/^(?:[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 T(e){return "string"==typeof e&&U.test(e)}for(var R,A,j=[],F=0;F<256;++F)j.push((F+256).toString(16).substr(1));function N(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(j[e[t+0]]+j[e[t+1]]+j[e[t+2]]+j[e[t+3]]+"-"+j[e[t+4]]+j[e[t+5]]+"-"+j[e[t+6]]+j[e[t+7]]+"-"+j[e[t+8]]+j[e[t+9]]+"-"+j[e[t+10]]+j[e[t+11]]+j[e[t+12]]+j[e[t+13]]+j[e[t+14]]+j[e[t+15]]).toLowerCase();if(!T(n))throw TypeError("Stringified UUID is invalid");return n}var $=0,V=0;function H(e){if(!T(e))throw TypeError("Invalid UUID");var t,n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n}function q(e,t,n){function r(e,r,o,i){if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));for(var t=[],n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}(e)),"string"==typeof r&&(r=H(r)),16!==r.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var a=new Uint8Array(16+e.length);if(a.set(r),a.set(e,r.length),(a=n(a))[6]=15&a[6]|t,a[8]=63&a[8]|128,o){i=i||0;for(var s=0;s<16;++s)o[i+s]=a[s];return o}return N(a)}try{r.name=e;}catch(e){}return r.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",r.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",r}function M(e){return 14+(e+64>>>9<<4)+1}function K(e,t){var n=(65535&e)+(65535&t);return (e>>16)+(t>>16)+(n>>16)<<16|65535&n}function _(e,t,n,r,o,i){return K((a=K(K(t,e),K(r,i)))<<(s=o)|a>>>32-s,n);var a,s;}function J(e,t,n,r,o,i,a){return _(t&n|~t&r,e,t,o,i,a)}function z(e,t,n,r,o,i,a){return _(t&r|n&~r,e,t,o,i,a)}function B(e,t,n,r,o,i,a){return _(t^n^r,e,t,o,i,a)}function G(e,t,n,r,o,i,a){return _(n^(t|~r),e,t,o,i,a)}var W=q("v3",48,(function(e){if("string"==typeof e){var t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(var n=0;n<t.length;++n)e[n]=t.charCodeAt(n);}return function(e){for(var t=[],n=32*e.length,r="0123456789abcdef",o=0;o<n;o+=8){var i=e[o>>5]>>>o%32&255,a=parseInt(r.charAt(i>>>4&15)+r.charAt(15&i),16);t.push(a);}return t}(function(e,t){e[t>>5]|=128<<t%32,e[M(t)-1]=t;for(var n=1732584193,r=-271733879,o=-1732584194,i=271733878,a=0;a<e.length;a+=16){var s=n,c=r,u=o,l=i;n=J(n,r,o,i,e[a],7,-680876936),i=J(i,n,r,o,e[a+1],12,-389564586),o=J(o,i,n,r,e[a+2],17,606105819),r=J(r,o,i,n,e[a+3],22,-1044525330),n=J(n,r,o,i,e[a+4],7,-176418897),i=J(i,n,r,o,e[a+5],12,1200080426),o=J(o,i,n,r,e[a+6],17,-1473231341),r=J(r,o,i,n,e[a+7],22,-45705983),n=J(n,r,o,i,e[a+8],7,1770035416),i=J(i,n,r,o,e[a+9],12,-1958414417),o=J(o,i,n,r,e[a+10],17,-42063),r=J(r,o,i,n,e[a+11],22,-1990404162),n=J(n,r,o,i,e[a+12],7,1804603682),i=J(i,n,r,o,e[a+13],12,-40341101),o=J(o,i,n,r,e[a+14],17,-1502002290),n=z(n,r=J(r,o,i,n,e[a+15],22,1236535329),o,i,e[a+1],5,-165796510),i=z(i,n,r,o,e[a+6],9,-1069501632),o=z(o,i,n,r,e[a+11],14,643717713),r=z(r,o,i,n,e[a],20,-373897302),n=z(n,r,o,i,e[a+5],5,-701558691),i=z(i,n,r,o,e[a+10],9,38016083),o=z(o,i,n,r,e[a+15],14,-660478335),r=z(r,o,i,n,e[a+4],20,-405537848),n=z(n,r,o,i,e[a+9],5,568446438),i=z(i,n,r,o,e[a+14],9,-1019803690),o=z(o,i,n,r,e[a+3],14,-187363961),r=z(r,o,i,n,e[a+8],20,1163531501),n=z(n,r,o,i,e[a+13],5,-1444681467),i=z(i,n,r,o,e[a+2],9,-51403784),o=z(o,i,n,r,e[a+7],14,1735328473),n=B(n,r=z(r,o,i,n,e[a+12],20,-1926607734),o,i,e[a+5],4,-378558),i=B(i,n,r,o,e[a+8],11,-2022574463),o=B(o,i,n,r,e[a+11],16,1839030562),r=B(r,o,i,n,e[a+14],23,-35309556),n=B(n,r,o,i,e[a+1],4,-1530992060),i=B(i,n,r,o,e[a+4],11,1272893353),o=B(o,i,n,r,e[a+7],16,-155497632),r=B(r,o,i,n,e[a+10],23,-1094730640),n=B(n,r,o,i,e[a+13],4,681279174),i=B(i,n,r,o,e[a],11,-358537222),o=B(o,i,n,r,e[a+3],16,-722521979),r=B(r,o,i,n,e[a+6],23,76029189),n=B(n,r,o,i,e[a+9],4,-640364487),i=B(i,n,r,o,e[a+12],11,-421815835),o=B(o,i,n,r,e[a+15],16,530742520),n=G(n,r=B(r,o,i,n,e[a+2],23,-995338651),o,i,e[a],6,-198630844),i=G(i,n,r,o,e[a+7],10,1126891415),o=G(o,i,n,r,e[a+14],15,-1416354905),r=G(r,o,i,n,e[a+5],21,-57434055),n=G(n,r,o,i,e[a+12],6,1700485571),i=G(i,n,r,o,e[a+3],10,-1894986606),o=G(o,i,n,r,e[a+10],15,-1051523),r=G(r,o,i,n,e[a+1],21,-2054922799),n=G(n,r,o,i,e[a+8],6,1873313359),i=G(i,n,r,o,e[a+15],10,-30611744),o=G(o,i,n,r,e[a+6],15,-1560198380),r=G(r,o,i,n,e[a+13],21,1309151649),n=G(n,r,o,i,e[a+4],6,-145523070),i=G(i,n,r,o,e[a+11],10,-1120210379),o=G(o,i,n,r,e[a+2],15,718787259),r=G(r,o,i,n,e[a+9],21,-343485551),n=K(n,s),r=K(r,c),o=K(o,u),i=K(i,l);}return [n,r,o,i]}(function(e){if(0===e.length)return [];for(var t=8*e.length,n=new Uint32Array(M(t)),r=0;r<t;r+=8)n[r>>5]|=(255&e[r/8])<<r%32;return n}(e),8*e.length))})),X=W;function Q(e,t,n,r){switch(e){case 0:return t&n^~t&r;case 1:case 3:return t^n^r;case 2:return t&n^t&r^n&r}}function Y(e,t){return e<<t|e>>>32-t}var Z=q("v5",80,(function(e){var t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){var r=unescape(encodeURIComponent(e));e=[];for(var o=0;o<r.length;++o)e.push(r.charCodeAt(o));}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);for(var i=e.length/4+2,a=Math.ceil(i/16),s=new Array(a),c=0;c<a;++c){for(var u=new Uint32Array(16),l=0;l<16;++l)u[l]=e[64*c+4*l]<<24|e[64*c+4*l+1]<<16|e[64*c+4*l+2]<<8|e[64*c+4*l+3];s[c]=u;}s[a-1][14]=8*(e.length-1)/Math.pow(2,32),s[a-1][14]=Math.floor(s[a-1][14]),s[a-1][15]=8*(e.length-1)&4294967295;for(var d=0;d<a;++d){for(var f=new Uint32Array(80),g=0;g<16;++g)f[g]=s[d][g];for(var v=16;v<80;++v)f[v]=Y(f[v-3]^f[v-8]^f[v-14]^f[v-16],1);for(var p=n[0],m=n[1],h=n[2],y=n[3],w=n[4],b=0;b<80;++b){var k=Math.floor(b/20),E=Y(p,5)+Q(k,m,h,y)+w+t[k]+f[b]>>>0;w=y,y=h,h=Y(m,30)>>>0,m=p,p=E;}n[0]=n[0]+p>>>0,n[1]=n[1]+m>>>0,n[2]=n[2]+h>>>0,n[3]=n[3]+y>>>0,n[4]=n[4]+w>>>0;}return [n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,255&n[0],n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,255&n[1],n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,255&n[2],n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,255&n[3],n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,255&n[4]]})),ee=Z;var te=Object.freeze({__proto__:null,v1:function(e,t,n){var r=t&&n||0,o=t||new Array(16),i=(e=e||{}).node||R,a=void 0!==e.clockseq?e.clockseq:A;if(null==i||null==a){var s=e.random||(e.rng||L)();null==i&&(i=R=[1|s[0],s[1],s[2],s[3],s[4],s[5]]),null==a&&(a=A=16383&(s[6]<<8|s[7]));}var c=void 0!==e.msecs?e.msecs:Date.now(),u=void 0!==e.nsecs?e.nsecs:V+1,l=c-$+(u-V)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||c>$)&&void 0===e.nsecs&&(u=0),u>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");$=c,V=u,A=a;var d=(1e4*(268435455&(c+=122192928e5))+u)%4294967296;o[r++]=d>>>24&255,o[r++]=d>>>16&255,o[r++]=d>>>8&255,o[r++]=255&d;var f=c/4294967296*1e4&268435455;o[r++]=f>>>8&255,o[r++]=255&f,o[r++]=f>>>24&15|16,o[r++]=f>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var g=0;g<6;++g)o[r+g]=i[g];return t||N(o)},v3:X,v4:function(e,t,n){var r=(e=e||{}).random||(e.rng||L)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=r[o];return t}return N(r)},v5:ee,NIL:"00000000-0000-0000-0000-000000000000",version:function(e){if(!T(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)},validate:T,stringify:N,parse:H});const ne=["debug","info","warn","error","none"];var re={commonBasicLogger:function(e,t){if(e&&e.destination&&"function"!=typeof e.destination)throw new Error("destination for basicLogger was set to a non-function");function n(e){return function(t){console&&console[e]&&console[e].call(console,t);}}const r=e&&e.destination?[e.destination,e.destination,e.destination,e.destination]:[n("log"),n("info"),n("warn"),n("error")],o=!(!e||!e.destination),i=e&&void 0!==e.prefix&&null!==e.prefix?e.prefix:"[LaunchDarkly] ";let a=1;if(e&&e.level)for(let t=0;t<ne.length;t++)ne[t]===e.level&&(a=t);function s(e,n,a){if(a.length<1)return;let s;const c=o?n+": "+i:i;if(1!==a.length&&t){const e=[...a];e[0]=c+e[0],s=t(...e);}else s=c+a[0];try{r[e](s);}catch(e){console&&console.log&&console.log("[LaunchDarkly] Configured logger's "+n+" method threw an exception: "+e);}}const c={};for(let e=0;e<ne.length;e++){const t=ne[e];if("none"!==t)if(e<a)c[t]=()=>{};else {const n=e;c[t]=function(){s(n,t,arguments);};}}return c},validateLogger:function(e){ne.forEach((t=>{if("none"!==t&&(!e[t]||"function"!=typeof e[t]))throw new Error("Provided logger instance must support logger."+t+"(...) method")}));}};function oe(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}const ie=" Please see https://docs.launchdarkly.com/sdk/client-side/javascript#initializing-the-client for instructions on SDK initialization.";var ae={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."+ie},clientInitialized:function(){return "LaunchDarkly client initialized"},clientNotReady:function(){return "LaunchDarkly client is not ready"},debugEnqueueingEvent:function(e){return 'enqueueing "'+e+'" event'},debugPostingDiagnosticEvent:function(e){return "sending diagnostic event ("+e.kind+")"},debugPostingEvents:function(e){return "sending "+e+" events"},debugStreamDelete:function(e){return 'received streaming deletion for flag "'+e+'"'},debugStreamDeleteIgnored:function(e){return 'received streaming deletion for flag "'+e+'" but ignored due to version check'},debugStreamPatch:function(e){return 'received streaming update for flag "'+e+'"'},debugStreamPatchIgnored:function(e){return 'received streaming update for flag "'+e+'" but ignored due to version check'},debugStreamPing:function(){return "received ping message from stream"},debugPolling:function(e){return "polling for feature flags at "+e},debugStreamPut:function(){return "received streaming update for all flags"},deprecated:function(e,t){return t?'"'+e+'" is deprecated, please use "'+t+'"':'"'+e+'" is deprecated'},environmentNotFound:function(){return "Environment not found. Double check that you specified a valid environment/client-side ID."+ie},environmentNotSpecified:function(){return "No environment/client-side ID was specified."+ie},errorFetchingFlags:function(e){return "Error fetching flag settings: "+oe(e)},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(e,t,n){return "Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+t+" - "+(s.isHttpErrorRecoverable(e)?n:"giving up permanently")},httpUnavailable:function(){return "Cannot make HTTP requests in this environment."+ie},identifyDisabled:function(){return "identify() has no effect here; it must be called on the main client instance"},inspectorMethodError:(e,t)=>`an inspector: "${t}" of type: "${e}" generated an exception`,invalidContentType:function(e){return 'Expected application/json content type but got "'+e+'"'},invalidData:function(){return "Invalid data received from LaunchDarkly; connection may have been interrupted"},invalidInspector:(e,t)=>`an inspector: "${t}" of an invalid type (${e}) was configured`,invalidKey:function(){return "Event key must be a string"},invalidContext:function(){return "Invalid context specified."+ie},invalidTagValue:e=>`Config option "${e}" must only contain letters, numbers, ., _ or -.`,localStorageUnavailable:function(e){return "local storage is unavailable: "+oe(e)},networkError:e=>"network error"+(e?" ("+e+")":""),optionBelowMinimum:(e,t,n)=>'Config option "'+e+'" was set to '+t+", changing to minimum value of "+n,streamClosing:function(){return "Closing stream connection"},streamConnecting:function(e){return "Opening stream connection to "+e},streamError:function(e,t){return "Error on stream connection: "+oe(e)+", will continue retrying after "+t+" milliseconds."},tagValueTooLong:e=>`Value of "${e}" was longer than 64 characters and was discarded.`,unknownCustomEventKey:function(e){return 'Custom event "'+e+'" does not exist'},unknownOption:e=>'Ignoring unknown config option "'+e+'"',contextNotSpecified:function(){return "No context specified."+ie},unrecoverableStreamError:e=>`Error on stream connection ${oe(e)}, giving up permanently`,wrongOptionType:(e,t,n)=>'Config option "'+e+'" should be of type '+t+", got "+n+", using default value",wrongOptionTypeBoolean:(e,t)=>'Config option "'+e+'" should be a boolean, got '+t+", converting to boolean"};const{validateLogger:se}=re,ce={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(e,t,n){const r={};t.id&&(r.id=de(`${e}.id`,t.id,n));t.version&&(r.version=de(`${e}.version`,t.version,n));return r}},inspectors:{default:[]}},ue=/^(\w|\.|-)+$/;function le(e){return e&&e.replace(/\/+$/,"")}function de(e,t,n){if("string"==typeof t&&t.match(ue)){if(!(t.length>64))return t;n.warn(ae.tagValueTooLong(e));}else n.warn(ae.invalidTagValue(e));}var fe={baseOptionDefs:ce,validate:function(e,t,n,r){const o=I.extend({logger:{default:r}},ce,n),i={};function a(e){I.onNextTick((()=>{t&&t.maybeReportError(new s.LDInvalidArgumentError(e));}));}let c=I.extend({},e||{});return function(e){const t=e;Object.keys(i).forEach((e=>{if(void 0!==t[e]){const n=i[e];r&&r.warn(ae.deprecated(e,n)),n&&(void 0===t[n]&&(t[n]=t[e]),delete t[e]);}}));}(c),c=function(e){const t=I.extend({},e);return Object.keys(o).forEach((e=>{void 0!==t[e]&&null!==t[e]||(t[e]=o[e]&&o[e].default);})),t}(c),c=function(e){const t=I.extend({},e),n=e=>{if(null===e)return "any";if(void 0===e)return;if(Array.isArray(e))return "array";const t=typeof e;return "boolean"===t||"string"===t||"number"===t||"function"===t?t:"object"};return Object.keys(e).forEach((i=>{const s=e[i];if(null!=s){const c=o[i];if(void 0===c)a(ae.unknownOption(i));else {const o=c.type||n(c.default),u=c.validator;if(u){const n=u(i,e[i],r);void 0!==n?t[i]=n:delete t[i];}else if("any"!==o){const e=o.split("|"),r=n(s);e.indexOf(r)<0?"boolean"===o?(t[i]=!!s,a(ae.wrongOptionTypeBoolean(i,r))):(a(ae.wrongOptionType(i,o,r)),t[i]=c.default):"number"===r&&void 0!==c.minimum&&s<c.minimum&&(a(ae.optionBelowMinimum(i,s,c.minimum)),t[i]=c.minimum);}}}})),t.baseUrl=le(t.baseUrl),t.streamUrl=le(t.streamUrl),t.eventsUrl=le(t.eventsUrl),t}(c),se(c.logger),c},getTags:function(e){const t={};return e&&(e.application&&void 0!==e.application.id&&null!==e.application.id&&(t["application-id"]=[e.application.id]),e.application&&void 0!==e.application.version&&null!==e.application.id&&(t["application-version"]=[e.application.version])),t}};const{getLDUserAgentString:ge}=I;var ve={getLDHeaders:function(e,t){if(t&&!t.sendLDHeaders)return {};const n={};n[e.userAgentHeaderName||"User-Agent"]=ge(e),t&&t.wrapperName&&(n["X-LaunchDarkly-Wrapper"]=t.wrapperVersion?t.wrapperName+"/"+t.wrapperVersion:t.wrapperName);const r=fe.getTags(t),o=Object.keys(r);return o.length&&(n["x-launchdarkly-tags"]=o.sort().map((e=>Array.isArray(r[e])?r[e].sort().map((t=>`${e}/${t}`)):[`${e}/${r[e]}`])).reduce(((e,t)=>e.concat(t)),[]).join(" ")),n},transformHeaders:function(e,t){return t&&t.requestHeaderTransform?t.requestHeaderTransform({...e}):e}};const{v1:pe}=te,{getLDHeaders:me,transformHeaders:he}=ve;var ye=function(e,t,n){const r="/a/"+t+".gif",o=I.extend({"Content-Type":"application/json"},me(e,n)),i=e.httpFallbackPing,a={};return a.sendChunk=(t,a,c,u)=>{const l=JSON.stringify(t),d=c?null:pe();return u?function t(r){const i=c?o:I.extend({},o,{"X-LaunchDarkly-Event-Schema":"4","X-LaunchDarkly-Payload-ID":d});return e.httpRequest("POST",a,he(i,n),l).promise.then((e=>{if(e)return e.status>=400&&s.isHttpErrorRecoverable(e.status)&&r?t(!1):function(e){const t={status:e.status},n=e.header("date");if(n){const e=Date.parse(n);e&&(t.serverTime=e);}return t}(e)})).catch((()=>r?t(!1):Promise.reject()))}(!0).catch((()=>{})):(i&&i(a+r+"?d="+I.base64URLEncode(l)),Promise.resolve())},a.sendEvents=function(t,n,r){if(!e.httpRequest)return Promise.resolve();const o=e.httpAllowsPost();let i;i=o?[t]:I.chunkEventsForUrl(2e3-n.length,t);const s=[];for(let e=0;e<i.length;e++)s.push(a.sendChunk(i[e],n,r,o));return Promise.all(s)},a};const{commonBasicLogger:we}=re;function be(e){return "string"==typeof e&&"kind"!==e&&e.match(/^(\w|\.|-)+$/)}function ke(e){return e.includes("%")||e.includes(":")?e.replace(/%/g,"%25").replace(/:/g,"%3A"):e}var Ee={checkContext:function(e,t){if(e){if(t&&(void 0===e.kind||null===e.kind))return void 0!==e.key&&null!==e.key;const n=e.key,r=void 0===e.kind?"user":e.kind,o=be(r),i="multi"===r||null!=n&&""!==n;if("multi"===r){const t=Object.keys(e).filter((e=>"kind"!==e));return i&&t.every((e=>be(e)))&&t.every((t=>{const n=e[t].key;return null!=n&&""!==n}))}return i&&o}return !1},getContextKeys:function(e,t=we()){if(!e)return;const n={},{kind:r,key:o}=e;switch(r){case void 0:n.user=`${o}`;break;case"multi":Object.entries(e).filter((([e])=>"kind"!==e)).forEach((([e,t])=>{t&&t.key&&(n[e]=t.key);}));break;case null:t.warn(`null is not a valid context kind: ${e}`);break;case"":t.warn(`'' is not a valid context kind: ${e}`);break;default:n[r]=`${o}`;}return n},getContextKinds:function(e){return e?null===e.kind||void 0===e.kind?["user"]:"multi"!==e.kind?[e.kind]:Object.keys(e).filter((e=>"kind"!==e)):[]},getCanonicalKey:function(e){if(e){if((void 0===e.kind||null===e.kind||"user"===e.kind)&&e.key)return e.key;if("multi"!==e.kind&&e.key)return `${e.kind}:${ke(e.key)}`;if("multi"===e.kind)return Object.keys(e).sort().filter((e=>"kind"!==e)).map((t=>`${t}:${ke(e[t].key)}`)).join(":")}}};const{getContextKinds:De}=Ee;var Ce=function(){const e={};let t=0,n=0,r={},o={};return e.summarizeEvent=e=>{if("feature"===e.kind){const i=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),a=r[i];let s=o[e.key];s||(s=new Set,o[e.key]=s),function(e){return e.context?De(e.context):e.contextKeys?Object.keys(e.contextKeys):[]}(e).forEach((e=>s.add(e))),a?a.count=a.count+1:r[i]={count:1,key:e.key,version:e.version,variation:e.variation,value:e.value,default:e.default},(0===t||e.creationDate<t)&&(t=e.creationDate),e.creationDate>n&&(n=e.creationDate);}},e.getSummary=()=>{const e={};let i=!0;for(const t of Object.values(r)){let n=e[t.key];n||(n={default:t.default,counters:[],contextKinds:[...o[t.key]]},e[t.key]=n);const r={value:t.value,count:t.count};void 0!==t.variation&&null!==t.variation&&(r.variation=t.variation),void 0!==t.version&&null!==t.version?r.version=t.version:r.unknown=!0,n.counters.push(r),i=!1;}return i?null:{startDate:t,endDate:n,features:e}},e.clearSummary=()=>{t=0,n=0,r={},o={};},e};function xe(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function Pe(e){return (e.startsWith("/")?e.substring(1):e).split("/").map((e=>e.indexOf("~")>=0?e.replace(/~1/g,"/").replace(/~0/g,"~"):e))}function Se(e){return !e.startsWith("/")}function Ie(e,t){const n=Se(e),r=Se(t);if(n&&r)return e===t;if(n){const n=Pe(t);return 1===n.length&&e===n[0]}if(r){const n=Pe(e);return 1===n.length&&t===n[0]}return e===t}function Oe(e){return `/${xe(e)}`}var Le={cloneExcluding:function(e,t){const n=[],r={},o=[];for(n.push(...Object.keys(e).map((t=>({key:t,ptr:Oe(t),source:e,parent:r,visited:[e]}))));n.length;){const e=n.pop();if(t.some((t=>Ie(t,e.ptr))))o.push(e.ptr);else {const t=e.source[e.key];if(null===t)e.parent[e.key]=t;else if(Array.isArray(t))e.parent[e.key]=[...t];else if("object"==typeof t){if(e.visited.includes(t))continue;e.parent[e.key]={},n.push(...Object.keys(t).map((n=>{return {key:n,ptr:(r=e.ptr,o=xe(n),`${r}/${o}`),source:t,parent:e.parent[e.key],visited:[...e.visited,t]};var r,o;})));}else e.parent[e.key]=t;}}return {cloned:r,excluded:o.sort()}},compare:Ie,literalToReference:Oe};var Ue=function(e){const t={},n=e.allAttributesPrivate,r=e.privateAttributes||[],o=["key","kind","_meta","anonymous"],i=["name","ip","firstName","lastName","email","avatar","country"],a=e=>{if("object"!=typeof e||null===e||Array.isArray(e))return;const{cloned:t,excluded:i}=Le.cloneExcluding(e,(e=>(n?Object.keys(e):[...r,...e._meta&&e._meta.privateAttributes||[]]).filter((e=>!o.some((t=>Le.compare(e,t))))))(e));return t.key=String(t.key),i.length&&(t._meta||(t._meta={}),t._meta.redactedAttributes=i),t._meta&&(delete t._meta.privateAttributes,0===Object.keys(t._meta).length&&delete t._meta),void 0!==t.anonymous&&(t.anonymous=!!t.anonymous),t};return t.filter=e=>void 0===e.kind||null===e.kind?a((e=>{const t={...e.custom||{},kind:"user",key:e.key};void 0!==e.anonymous&&(t.anonymous=!!e.anonymous);for(const n of i)delete t[n],void 0!==e[n]&&null!==e[n]&&(t[n]=String(e[n]));return void 0!==e.privateAttributeNames&&null!==e.privateAttributeNames&&(t._meta=t._meta||{},t._meta.privateAttributes=e.privateAttributeNames.map((e=>e.startsWith("/")?Le.literalToReference(e):e))),t})(e)):"multi"===e.kind?(e=>{const t={kind:e.kind},n=Object.keys(e);for(const r of n)if("kind"!==r){const n=a(e[r]);n&&(t[r]=n);}return t})(e):a(e),t};const{getContextKeys:Te}=Ee;var Re=function(e,t,n,r=null,o=null,i=null){const a={},c=i||ye(e,n,t),u=I.appendUrlPath(t.eventsUrl,"/events/bulk/"+n),l=Ce(),d=Ue(t),f=t.samplingInterval,g=t.eventCapacity,v=t.flushInterval,p=t.logger;let m,h=[],y=0,w=!1,b=!1;function k(){return 0===f||0===Math.floor(Math.random()*f)}function E(e){const t=I.extend({},e);return "identify"===e.kind?t.context=d.filter(e.context):(t.contextKeys=Te(e.context,p),delete t.context),"feature"===e.kind&&(delete t.trackEvents,delete t.debugEventsUntilDate),t}function D(e){h.length<g?(h.push(e),b=!1):(b||(b=!0,p.warn(ae.eventCapacityExceeded())),r&&r.incrementDroppedEvents());}return a.enqueue=function(e){if(w)return;let t=!1,n=!1;var r;if(l.summarizeEvent(e),"feature"===e.kind?k()&&(t=!!e.trackEvents,n=!!(r=e).debugEventsUntilDate&&r.debugEventsUntilDate>y&&r.debugEventsUntilDate>(new Date).getTime()):t=k(),t&&D(E(e)),n){const t=I.extend({},e,{kind:"debug"});t.context=d.filter(t.context),delete t.trackEvents,delete t.debugEventsUntilDate,D(t);}},a.flush=function(){if(w)return Promise.resolve();const e=h,t=l.getSummary();return l.clearSummary(),t&&(t.kind="summary",e.push(t)),r&&r.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(h=[],p.debug(ae.debugPostingEvents(e.length)),c.sendEvents(e,u).then((e=>{const t=e&&e[0];t&&(t.serverTime&&(y=t.serverTime),s.isHttpErrorRecoverable(t.status)||(w=!0),t.status>=400&&I.onNextTick((()=>{o.maybeReportError(new s.LDUnexpectedResponseError(ae.httpErrorMessage(t.status,"event posting","some events were dropped")));})));})))},a.start=function(){const e=()=>{a.flush(),m=setTimeout(e,v);};m=setTimeout(e,v);},a.stop=function(){clearTimeout(m);},a};var Ae=function(e){const t={},n={};return t.on=function(e,t,r){n[e]=n[e]||[],n[e]=n[e].concat({handler:t,context:r});},t.off=function(e,t,r){if(n[e])for(let o=0;o<n[e].length;o++)n[e][o].handler===t&&n[e][o].context===r&&(n[e]=n[e].slice(0,o).concat(n[e].slice(o+1)));},t.emit=function(e){if(!n[e])return;const t=n[e].slice(0);for(let e=0;e<t.length;e++)t[e].handler.apply(t[e].context,Array.prototype.slice.call(arguments,1));},t.getEvents=function(){return Object.keys(n)},t.getEventListenerCount=function(e){return n[e]?n[e].length:0},t.maybeReportError=function(t){t&&(n["error"]?this.emit("error",t):(e||console).error(t.message));},t};const je="ready",Fe="initialized",Ne="failed";var $e=function(e){let t=!1,n=!1,r=null,o=null;const i=new Promise((t=>{const n=()=>{e.off(je,n),t();};e.on(je,n);})).catch((()=>{}));return {getInitializationPromise:()=>o||(t?Promise.resolve():n?Promise.reject(r):(o=new Promise(((t,n)=>{const r=()=>{e.off(Fe,r),t();},o=t=>{e.off(Ne,o),n(t);};e.on(Fe,r),e.on(Ne,o);})),o)),getReadyPromise:()=>i,signalSuccess:()=>{t||n||(t=!0,e.emit(Fe),e.emit(je));},signalFailure:o=>{t||n||(n=!0,r=o,e.emit(Ne,o),e.emit(je)),e.maybeReportError(o);}}};var Ve=func