@unleash/proxy-client-vue 0.1.7-beta.0 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,779 +1,885 @@
1
- import { toRefs, ref, reactive, defineComponent, provide, onMounted, renderSlot, inject, onUnmounted } from "vue";
2
- var t = function(e2, r2) {
3
- return t = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t2, e3) {
4
- t2.__proto__ = e3;
5
- } || function(t2, e3) {
6
- for (var r3 in e3)
7
- Object.prototype.hasOwnProperty.call(e3, r3) && (t2[r3] = e3[r3]);
8
- }, t(e2, r2);
1
+ import { ref as N, reactive as mt, toRefs as gt, defineComponent as yt, provide as X, onMounted as bt, renderSlot as xt, inject as A, onUnmounted as nt } from "vue";
2
+ var j = function(o, t) {
3
+ return j = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, r) {
4
+ e.__proto__ = r;
5
+ } || function(e, r) {
6
+ for (var n in r) Object.prototype.hasOwnProperty.call(r, n) && (e[n] = r[n]);
7
+ }, j(o, t);
9
8
  };
10
- var e = function() {
11
- return e = Object.assign || function(t2) {
12
- for (var e2, r2 = 1, n2 = arguments.length; r2 < n2; r2++)
13
- for (var o2 in e2 = arguments[r2])
14
- Object.prototype.hasOwnProperty.call(e2, o2) && (t2[o2] = e2[o2]);
15
- return t2;
16
- }, e.apply(this, arguments);
9
+ function ot(o, t) {
10
+ if (typeof t != "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
11
+ function e() {
12
+ this.constructor = o;
13
+ }
14
+ j(o, t), o.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
15
+ }
16
+ var p = function() {
17
+ return p = Object.assign || function(o) {
18
+ for (var t, e = 1, r = arguments.length; e < r; e++) for (var n in t = arguments[e]) Object.prototype.hasOwnProperty.call(t, n) && (o[n] = t[n]);
19
+ return o;
20
+ }, p.apply(this, arguments);
17
21
  };
18
- function r(t2, e2, r2, n2) {
19
- return new (r2 || (r2 = Promise))(function(o2, i2) {
20
- function s2(t3) {
22
+ function g(o, t, e, r) {
23
+ return new (e || (e = Promise))((function(n, s) {
24
+ function i(c) {
21
25
  try {
22
- c2(n2.next(t3));
23
- } catch (t4) {
24
- i2(t4);
26
+ l(r.next(c));
27
+ } catch (a) {
28
+ s(a);
25
29
  }
26
30
  }
27
- function a2(t3) {
31
+ function u(c) {
28
32
  try {
29
- c2(n2.throw(t3));
30
- } catch (t4) {
31
- i2(t4);
33
+ l(r.throw(c));
34
+ } catch (a) {
35
+ s(a);
32
36
  }
33
37
  }
34
- function c2(t3) {
35
- var e3;
36
- t3.done ? o2(t3.value) : (e3 = t3.value, e3 instanceof r2 ? e3 : new r2(function(t4) {
37
- t4(e3);
38
- })).then(s2, a2);
38
+ function l(c) {
39
+ var a;
40
+ c.done ? n(c.value) : (a = c.value, a instanceof e ? a : new e((function(f) {
41
+ f(a);
42
+ }))).then(i, u);
39
43
  }
40
- c2((n2 = n2.apply(t2, e2 || [])).next());
41
- });
44
+ l((r = r.apply(o, t || [])).next());
45
+ }));
42
46
  }
43
- function n(t2, e2) {
44
- var r2, n2, o2, i2 = { label: 0, sent: function() {
45
- if (1 & o2[0])
46
- throw o2[1];
47
- return o2[1];
48
- }, trys: [], ops: [] }, s2 = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
49
- return s2.next = a2(0), s2.throw = a2(1), s2.return = a2(2), typeof Symbol == "function" && (s2[Symbol.iterator] = function() {
47
+ function y(o, t) {
48
+ var e, r, n, s = { label: 0, sent: function() {
49
+ if (1 & n[0]) throw n[1];
50
+ return n[1];
51
+ }, trys: [], ops: [] }, i = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
52
+ return i.next = u(0), i.throw = u(1), i.return = u(2), typeof Symbol == "function" && (i[Symbol.iterator] = function() {
50
53
  return this;
51
- }), s2;
52
- function a2(a3) {
53
- return function(c2) {
54
- return function(a4) {
55
- if (r2)
56
- throw new TypeError("Generator is already executing.");
57
- for (; s2 && (s2 = 0, a4[0] && (i2 = 0)), i2; )
58
- try {
59
- if (r2 = 1, n2 && (o2 = 2 & a4[0] ? n2.return : a4[0] ? n2.throw || ((o2 = n2.return) && o2.call(n2), 0) : n2.next) && !(o2 = o2.call(n2, a4[1])).done)
60
- return o2;
61
- switch (n2 = 0, o2 && (a4 = [2 & a4[0], o2.value]), a4[0]) {
62
- case 0:
63
- case 1:
64
- o2 = a4;
65
- break;
66
- case 4:
67
- return i2.label++, { value: a4[1], done: false };
68
- case 5:
69
- i2.label++, n2 = a4[1], a4 = [0];
70
- continue;
71
- case 7:
72
- a4 = i2.ops.pop(), i2.trys.pop();
54
+ }), i;
55
+ function u(l) {
56
+ return function(c) {
57
+ return (function(a) {
58
+ if (e) throw new TypeError("Generator is already executing.");
59
+ for (; i && (i = 0, a[0] && (s = 0)), s; ) try {
60
+ if (e = 1, r && (n = 2 & a[0] ? r.return : a[0] ? r.throw || ((n = r.return) && n.call(r), 0) : r.next) && !(n = n.call(r, a[1])).done) return n;
61
+ switch (r = 0, n && (a = [2 & a[0], n.value]), a[0]) {
62
+ case 0:
63
+ case 1:
64
+ n = a;
65
+ break;
66
+ case 4:
67
+ return s.label++, { value: a[1], done: !1 };
68
+ case 5:
69
+ s.label++, r = a[1], a = [0];
70
+ continue;
71
+ case 7:
72
+ a = s.ops.pop(), s.trys.pop();
73
+ continue;
74
+ default:
75
+ if (n = s.trys, !((n = n.length > 0 && n[n.length - 1]) || a[0] !== 6 && a[0] !== 2)) {
76
+ s = 0;
73
77
  continue;
74
- default:
75
- if (!(o2 = i2.trys, (o2 = o2.length > 0 && o2[o2.length - 1]) || a4[0] !== 6 && a4[0] !== 2)) {
76
- i2 = 0;
77
- continue;
78
- }
79
- if (a4[0] === 3 && (!o2 || a4[1] > o2[0] && a4[1] < o2[3])) {
80
- i2.label = a4[1];
81
- break;
82
- }
83
- if (a4[0] === 6 && i2.label < o2[1]) {
84
- i2.label = o2[1], o2 = a4;
85
- break;
86
- }
87
- if (o2 && i2.label < o2[2]) {
88
- i2.label = o2[2], i2.ops.push(a4);
89
- break;
90
- }
91
- o2[2] && i2.ops.pop(), i2.trys.pop();
92
- continue;
93
- }
94
- a4 = e2.call(t2, i2);
95
- } catch (t3) {
96
- a4 = [6, t3], n2 = 0;
97
- } finally {
98
- r2 = o2 = 0;
78
+ }
79
+ if (a[0] === 3 && (!n || a[1] > n[0] && a[1] < n[3])) {
80
+ s.label = a[1];
81
+ break;
82
+ }
83
+ if (a[0] === 6 && s.label < n[1]) {
84
+ s.label = n[1], n = a;
85
+ break;
86
+ }
87
+ if (n && s.label < n[2]) {
88
+ s.label = n[2], s.ops.push(a);
89
+ break;
90
+ }
91
+ n[2] && s.ops.pop(), s.trys.pop();
92
+ continue;
99
93
  }
100
- if (5 & a4[0])
101
- throw a4[1];
102
- return { value: a4[0] ? a4[1] : void 0, done: true };
103
- }([a3, c2]);
94
+ a = t.call(o, s);
95
+ } catch (f) {
96
+ a = [6, f], r = 0;
97
+ } finally {
98
+ e = n = 0;
99
+ }
100
+ if (5 & a[0]) throw a[1];
101
+ return { value: a[0] ? a[1] : void 0, done: !0 };
102
+ })([l, c]);
104
103
  };
105
104
  }
106
105
  }
107
- typeof SuppressedError == "function" && SuppressedError;
108
- var o = { exports: {} };
109
- function i() {
106
+ function C(o, t, e) {
107
+ if (e || arguments.length === 2) for (var r, n = 0, s = t.length; n < s; n++) !r && n in t || (r || (r = Array.prototype.slice.call(t, 0, n)), r[n] = t[n]);
108
+ return o.concat(r || Array.prototype.slice.call(t));
110
109
  }
111
- i.prototype = { on: function(t2, e2, r2) {
112
- var n2 = this.e || (this.e = {});
113
- return (n2[t2] || (n2[t2] = [])).push({ fn: e2, ctx: r2 }), this;
114
- }, once: function(t2, e2, r2) {
115
- var n2 = this;
116
- function o2() {
117
- n2.off(t2, o2), e2.apply(r2, arguments);
110
+ var Z, P = { exports: {} }, st = (function() {
111
+ if (Z) return P.exports;
112
+ function o() {
118
113
  }
119
- return o2._ = e2, this.on(t2, o2, r2);
120
- }, emit: function(t2) {
121
- for (var e2 = [].slice.call(arguments, 1), r2 = ((this.e || (this.e = {}))[t2] || []).slice(), n2 = 0, o2 = r2.length; n2 < o2; n2++)
122
- r2[n2].fn.apply(r2[n2].ctx, e2);
123
- return this;
124
- }, off: function(t2, e2) {
125
- var r2 = this.e || (this.e = {}), n2 = r2[t2], o2 = [];
126
- if (n2 && e2)
127
- for (var i2 = 0, s2 = n2.length; i2 < s2; i2++)
128
- n2[i2].fn !== e2 && n2[i2].fn._ !== e2 && o2.push(n2[i2]);
129
- return o2.length ? r2[t2] = o2 : delete r2[t2], this;
130
- } }, o.exports = i;
131
- var s = o.exports.TinyEmitter = i, a = function(t2) {
132
- var e2 = t2[1];
133
- return e2 != null;
134
- }, c = function(t2) {
135
- var e2 = t2.properties, r2 = e2 === void 0 ? {} : e2, n2 = function(t3, e3) {
136
- var r3 = {};
137
- for (var n3 in t3)
138
- Object.prototype.hasOwnProperty.call(t3, n3) && e3.indexOf(n3) < 0 && (r3[n3] = t3[n3]);
139
- if (t3 != null && typeof Object.getOwnPropertySymbols == "function") {
140
- var o3 = 0;
141
- for (n3 = Object.getOwnPropertySymbols(t3); o3 < n3.length; o3++)
142
- e3.indexOf(n3[o3]) < 0 && Object.prototype.propertyIsEnumerable.call(t3, n3[o3]) && (r3[n3[o3]] = t3[n3[o3]]);
114
+ return Z = 1, o.prototype = { on: function(t, e, r) {
115
+ var n = this.e || (this.e = {});
116
+ return (n[t] || (n[t] = [])).push({ fn: e, ctx: r }), this;
117
+ }, once: function(t, e, r) {
118
+ var n = this;
119
+ function s() {
120
+ n.off(t, s), e.apply(r, arguments);
143
121
  }
144
- return r3;
145
- }(t2, ["properties"]), o2 = function(t3) {
146
- return Object.entries(t3).sort(function(t4, e3) {
147
- var r3 = t4[0], n3 = e3[0];
148
- return r3.localeCompare(n3, void 0);
149
- });
122
+ return s._ = e, this.on(t, s, r);
123
+ }, emit: function(t) {
124
+ for (var e = [].slice.call(arguments, 1), r = ((this.e || (this.e = {}))[t] || []).slice(), n = 0, s = r.length; n < s; n++) r[n].fn.apply(r[n].ctx, e);
125
+ return this;
126
+ }, off: function(t, e) {
127
+ var r = this.e || (this.e = {}), n = r[t], s = [];
128
+ if (n && e) for (var i = 0, u = n.length; i < u; i++) n[i].fn !== e && n[i].fn._ !== e && s.push(n[i]);
129
+ return s.length ? r[t] = s : delete r[t], this;
130
+ } }, P.exports = o, P.exports.TinyEmitter = o, P.exports;
131
+ })(), F = function(o) {
132
+ var t = o[1];
133
+ return t != null;
134
+ }, Tt = function(o) {
135
+ var t = o.properties, e = t === void 0 ? {} : t, r = (function(s, i) {
136
+ var u = {};
137
+ for (var l in s) Object.prototype.hasOwnProperty.call(s, l) && i.indexOf(l) < 0 && (u[l] = s[l]);
138
+ if (s != null && typeof Object.getOwnPropertySymbols == "function") {
139
+ var c = 0;
140
+ for (l = Object.getOwnPropertySymbols(s); c < l.length; c++) i.indexOf(l[c]) < 0 && Object.prototype.propertyIsEnumerable.call(s, l[c]) && (u[l[c]] = s[l[c]]);
141
+ }
142
+ return u;
143
+ })(o, ["properties"]), n = function(s) {
144
+ return Object.entries(s).sort((function(i, u) {
145
+ var l = i[0], c = u[0];
146
+ return l.localeCompare(c, void 0);
147
+ }));
150
148
  };
151
- return JSON.stringify([o2(n2), o2(r2)]);
152
- }, u = function(t2) {
153
- return r(void 0, void 0, void 0, function() {
154
- var e2;
155
- return n(this, function(o2) {
156
- switch (o2.label) {
149
+ return JSON.stringify([n(r), n(e)]);
150
+ }, V = function(o) {
151
+ return g(void 0, void 0, void 0, (function() {
152
+ var t;
153
+ return y(this, (function(e) {
154
+ switch (e.label) {
157
155
  case 0:
158
- e2 = c(t2), o2.label = 1;
156
+ t = Tt(o), e.label = 1;
159
157
  case 1:
160
- return o2.trys.push([1, 3, , 4]), [4, (i2 = e2, r(void 0, void 0, void 0, function() {
161
- var t3, e3, r2, o3, s2;
162
- return n(this, function(n2) {
163
- switch (n2.label) {
158
+ return e.trys.push([1, 3, , 4]), [4, (r = t, g(void 0, void 0, void 0, (function() {
159
+ var n, s, i, u, l;
160
+ return y(this, (function(c) {
161
+ switch (c.label) {
164
162
  case 0:
165
- if (t3 = typeof globalThis != "undefined" && ((o3 = globalThis.crypto) === null || o3 === void 0 ? void 0 : o3.subtle) ? (s2 = globalThis.crypto) === null || s2 === void 0 ? void 0 : s2.subtle : void 0, typeof TextEncoder == "undefined" || !(t3 == null ? void 0 : t3.digest) || typeof Uint8Array == "undefined")
166
- throw new Error("Hashing function not available");
167
- return e3 = new TextEncoder().encode(i2), [4, t3.digest("SHA-256", e3)];
163
+ if (n = typeof globalThis < "u" && (!((u = globalThis.crypto) === null || u === void 0) && u.subtle) ? (l = globalThis.crypto) === null || l === void 0 ? void 0 : l.subtle : void 0, typeof TextEncoder > "u" || !(n != null && n.digest) || typeof Uint8Array > "u") throw new Error("Hashing function not available");
164
+ return s = new TextEncoder().encode(r), [4, n.digest("SHA-256", s)];
168
165
  case 1:
169
- return r2 = n2.sent(), [2, Array.from(new Uint8Array(r2)).map(function(t4) {
170
- return t4.toString(16).padStart(2, "0");
171
- }).join("")];
166
+ return i = c.sent(), [2, Array.from(new Uint8Array(i)).map((function(a) {
167
+ return a.toString(16).padStart(2, "0");
168
+ })).join("")];
172
169
  }
173
- });
174
- }))];
170
+ }));
171
+ })))];
175
172
  case 2:
176
- return [2, o2.sent()];
173
+ return [2, e.sent()];
177
174
  case 3:
178
- return o2.sent(), [2, e2];
175
+ return e.sent(), [2, t];
179
176
  case 4:
180
177
  return [2];
181
178
  }
182
- var i2;
183
- });
184
- });
185
- }, l = "unleash-js@3.7.2", h = function() {
186
- }, p = function() {
187
- function t2(t3) {
188
- var e2 = t3.onError, r2 = t3.onSent, n2 = t3.appName, o2 = t3.metricsInterval, i2 = t3.disableMetrics, s2 = i2 !== void 0 && i2, a2 = t3.url, c2 = t3.clientKey, u2 = t3.fetch, l2 = t3.headerName, p2 = t3.customHeaders, f2 = p2 === void 0 ? {} : p2, d2 = t3.metricsIntervalInitial, v2 = t3.connectionId;
189
- this.onError = e2, this.onSent = r2 || h, this.disabled = s2, this.metricsInterval = 1e3 * o2, this.metricsIntervalInitial = 1e3 * d2, this.appName = n2, this.url = a2 instanceof URL ? a2 : new URL(a2), this.clientKey = c2, this.bucket = this.createEmptyBucket(), this.fetch = u2, this.headerName = l2, this.customHeaders = f2, this.connectionId = v2;
179
+ var r;
180
+ }));
181
+ }));
182
+ }, it = function(o) {
183
+ var t, e = o.clientKey, r = o.appName, n = o.connectionId, s = o.customHeaders, i = o.headerName, u = i === void 0 ? "authorization" : i, l = o.etag, c = o.isPost, a = ((t = { accept: "application/json" })[u.toLocaleLowerCase()] = e, t["unleash-sdk"] = "unleash-js-sdk:3.8.2", t["unleash-appname"] = r, t);
184
+ return c && (a["content-type"] = "application/json"), l && (a["if-none-match"] = l), Object.entries(s || {}).filter(F).forEach((function(f) {
185
+ var x = f[0], T = f[1];
186
+ return a[x.toLocaleLowerCase()] = T;
187
+ })), a["unleash-connection-id"] = n, a;
188
+ }, Et = function() {
189
+ }, wt = (function() {
190
+ function o(t) {
191
+ var e = t.onError, r = t.onSent, n = t.appName, s = t.metricsInterval, i = t.disableMetrics, u = i !== void 0 && i, l = t.url, c = t.clientKey, a = t.fetch, f = t.headerName, x = t.customHeaders, T = x === void 0 ? {} : x, b = t.metricsIntervalInitial, d = t.connectionId, v = t.metricRegistry;
192
+ this.onError = e, this.onSent = r || Et, this.disabled = u, this.metricsInterval = 1e3 * s, this.metricsIntervalInitial = 1e3 * b, this.appName = n, this.url = l instanceof URL ? l : new URL(l), this.clientKey = c, this.bucket = this.createEmptyBucket(), this.fetch = a, this.headerName = f, this.customHeaders = T, this.connectionId = d, this.metricRegistry = v;
190
193
  }
191
- return t2.prototype.start = function() {
192
- var t3 = this;
193
- if (this.disabled)
194
- return false;
195
- typeof this.metricsInterval == "number" && this.metricsInterval > 0 && (this.metricsIntervalInitial > 0 ? setTimeout(function() {
196
- t3.startTimer(), t3.sendMetrics();
197
- }, this.metricsIntervalInitial) : this.startTimer());
198
- }, t2.prototype.stop = function() {
199
- this.timer && (clearTimeout(this.timer), delete this.timer);
200
- }, t2.prototype.createEmptyBucket = function() {
201
- return { start: new Date(), stop: null, toggles: {} };
202
- }, t2.prototype.getHeaders = function() {
203
- var t3, e2 = ((t3 = {})[this.headerName] = this.clientKey, t3.Accept = "application/json", t3["Content-Type"] = "application/json", t3["x-unleash-sdk"] = l, t3["x-unleash-connection-id"] = this.connectionId, t3["x-unleash-appname"] = this.appName, t3);
204
- return Object.entries(this.customHeaders).filter(a).forEach(function(t4) {
205
- var r2 = t4[0], n2 = t4[1];
206
- return e2[r2] = n2;
207
- }), e2;
208
- }, t2.prototype.sendMetrics = function() {
209
- return r(this, void 0, void 0, function() {
210
- var t3, e2, r2;
211
- return n(this, function(n2) {
212
- switch (n2.label) {
194
+ return o.prototype.start = function() {
195
+ var t = this;
196
+ if (this.disabled) return !1;
197
+ this.setupMetricsFlushOnPageUnload(), typeof this.metricsInterval == "number" && this.metricsInterval > 0 && (this.metricsIntervalInitial > 0 ? setTimeout((function() {
198
+ t.startTimer(), t.sendMetrics();
199
+ }), this.metricsIntervalInitial) : this.startTimer());
200
+ }, o.prototype.stop = function() {
201
+ this.timer && (clearInterval(this.timer), delete this.timer), this.removeMetricsFlushOnPageUnload();
202
+ }, o.prototype.createEmptyBucket = function() {
203
+ return { start: /* @__PURE__ */ new Date(), stop: null, toggles: {} };
204
+ }, o.prototype.getHeaders = function() {
205
+ return it({ clientKey: this.clientKey, appName: this.appName, connectionId: this.connectionId, customHeaders: this.customHeaders, headerName: this.headerName, isPost: !0 });
206
+ }, o.prototype.sendMetrics = function() {
207
+ return g(this, arguments, void 0, (function(t) {
208
+ var e, r, n, s = (t === void 0 ? {} : t).fireAndForget, i = s !== void 0 && s;
209
+ return y(this, (function(u) {
210
+ switch (u.label) {
213
211
  case 0:
214
- if (t3 = "".concat(this.url, "/client/metrics"), e2 = this.getPayload(), this.bucketIsEmpty(e2))
215
- return [2];
216
- n2.label = 1;
212
+ if (e = "".concat(this.url.toString().replace(/\/$/, ""), "/client/metrics"), r = this.getPayload(), this.bucketIsEmpty(r) && (!r.impactMetrics || r.impactMetrics.length === 0)) return [2];
213
+ u.label = 1;
217
214
  case 1:
218
- return n2.trys.push([1, 3, , 4]), [4, this.fetch(t3, { cache: "no-cache", method: "POST", headers: this.getHeaders(), body: JSON.stringify(e2) })];
215
+ return u.trys.push([1, 3, , 4]), [4, this.fetch(e, { cache: "no-cache", method: "POST", headers: this.getHeaders(), body: JSON.stringify(r), keepalive: i })];
219
216
  case 2:
220
- return n2.sent(), this.onSent(e2), [3, 4];
217
+ return u.sent(), this.onSent(r), [3, 4];
221
218
  case 3:
222
- return r2 = n2.sent(), console.error("Unleash: unable to send feature metrics", r2), this.onError(r2), [3, 4];
219
+ return n = u.sent(), console.error("Unleash: unable to send feature metrics", n), this.onError(n), [3, 4];
223
220
  case 4:
224
221
  return [2];
225
222
  }
226
- });
223
+ }));
224
+ }));
225
+ }, o.prototype.count = function(t, e) {
226
+ return !(this.disabled || !this.bucket) && (this.assertBucket(t), this.bucket.toggles[t][e ? "yes" : "no"]++, !0);
227
+ }, o.prototype.countVariant = function(t, e) {
228
+ return !(this.disabled || !this.bucket) && (this.assertBucket(t), this.bucket.toggles[t].variants[e] ? this.bucket.toggles[t].variants[e] += 1 : this.bucket.toggles[t].variants[e] = 1, !0);
229
+ }, o.prototype.assertBucket = function(t) {
230
+ if (this.disabled || !this.bucket) return !1;
231
+ this.bucket.toggles[t] || (this.bucket.toggles[t] = { yes: 0, no: 0, variants: {} });
232
+ }, o.prototype.startTimer = function() {
233
+ var t = this;
234
+ this.timer = setInterval((function() {
235
+ t.sendMetrics();
236
+ }), this.metricsInterval);
237
+ }, o.prototype.bucketIsEmpty = function(t) {
238
+ return Object.keys(t.bucket.toggles).length === 0;
239
+ }, o.prototype.getPayload = function() {
240
+ var t, e = p(p({}, this.bucket), { stop: /* @__PURE__ */ new Date() });
241
+ this.bucket = this.createEmptyBucket();
242
+ var r = { bucket: e, appName: this.appName, instanceId: "browser" }, n = ((t = this.metricRegistry) === null || t === void 0 ? void 0 : t.collect()) || [];
243
+ return r.impactMetrics = n, r;
244
+ }, o.prototype.setupMetricsFlushOnPageUnload = function() {
245
+ var t = this;
246
+ typeof document > "u" || typeof window > "u" || typeof document.addEventListener != "function" || document.addEventListener("visibilitychange", this.flushMetricsOnPageUnload = function() {
247
+ document.visibilityState === "hidden" && t.sendMetrics({ fireAndForget: !0 });
227
248
  });
228
- }, t2.prototype.count = function(t3, e2) {
229
- return !(this.disabled || !this.bucket) && (this.assertBucket(t3), this.bucket.toggles[t3][e2 ? "yes" : "no"]++, true);
230
- }, t2.prototype.countVariant = function(t3, e2) {
231
- return !(this.disabled || !this.bucket) && (this.assertBucket(t3), this.bucket.toggles[t3].variants[e2] ? this.bucket.toggles[t3].variants[e2] += 1 : this.bucket.toggles[t3].variants[e2] = 1, true);
232
- }, t2.prototype.assertBucket = function(t3) {
233
- if (this.disabled || !this.bucket)
234
- return false;
235
- this.bucket.toggles[t3] || (this.bucket.toggles[t3] = { yes: 0, no: 0, variants: {} });
236
- }, t2.prototype.startTimer = function() {
237
- var t3 = this;
238
- this.timer = setInterval(function() {
239
- t3.sendMetrics();
240
- }, this.metricsInterval);
241
- }, t2.prototype.bucketIsEmpty = function(t3) {
242
- return Object.keys(t3.bucket.toggles).length === 0;
243
- }, t2.prototype.getPayload = function() {
244
- var t3 = e(e({}, this.bucket), { stop: new Date() });
245
- return this.bucket = this.createEmptyBucket(), { bucket: t3, appName: this.appName, instanceId: "browser" };
246
- }, t2;
247
- }(), f = function() {
248
- function t2() {
249
+ }, o.prototype.removeMetricsFlushOnPageUnload = function() {
250
+ this.flushMetricsOnPageUnload && (document.removeEventListener("visibilitychange", this.flushMetricsOnPageUnload), this.flushMetricsOnPageUnload = void 0);
251
+ }, o;
252
+ })(), St = (function() {
253
+ function o() {
249
254
  this.store = /* @__PURE__ */ new Map();
250
255
  }
251
- return t2.prototype.save = function(t3, e2) {
252
- return r(this, void 0, void 0, function() {
253
- return n(this, function(r2) {
254
- return this.store.set(t3, e2), [2];
255
- });
256
- });
257
- }, t2.prototype.get = function(t3) {
258
- return r(this, void 0, void 0, function() {
259
- return n(this, function(e2) {
260
- return [2, this.store.get(t3)];
261
- });
262
- });
263
- }, t2;
264
- }(), d = function() {
265
- function t2(t3) {
266
- t3 === void 0 && (t3 = "unleash:repository"), this.prefix = t3;
256
+ return o.prototype.save = function(t, e) {
257
+ return g(this, void 0, void 0, (function() {
258
+ return y(this, (function(r) {
259
+ return this.store.set(t, e), [2];
260
+ }));
261
+ }));
262
+ }, o.prototype.get = function(t) {
263
+ return g(this, void 0, void 0, (function() {
264
+ return y(this, (function(e) {
265
+ return [2, this.store.get(t)];
266
+ }));
267
+ }));
268
+ }, o;
269
+ })(), Rt = (function() {
270
+ function o(t) {
271
+ t === void 0 && (t = "unleash:repository"), this.prefix = t;
267
272
  }
268
- return t2.prototype.save = function(t3, e2) {
269
- return r(this, void 0, void 0, function() {
270
- var r2, o2;
271
- return n(this, function(n2) {
272
- r2 = JSON.stringify(e2), o2 = "".concat(this.prefix, ":").concat(t3);
273
+ return o.prototype.save = function(t, e) {
274
+ return g(this, void 0, void 0, (function() {
275
+ var r, n;
276
+ return y(this, (function(s) {
277
+ r = JSON.stringify(e), n = "".concat(this.prefix, ":").concat(t);
273
278
  try {
274
- window.localStorage.setItem(o2, r2);
275
- } catch (t4) {
276
- console.error(t4);
279
+ window.localStorage.setItem(n, r);
280
+ } catch (i) {
281
+ console.error(i);
277
282
  }
278
283
  return [2];
279
- });
280
- });
281
- }, t2.prototype.get = function(t3) {
284
+ }));
285
+ }));
286
+ }, o.prototype.get = function(t) {
282
287
  try {
283
- var e2 = "".concat(this.prefix, ":").concat(t3), r2 = window.localStorage.getItem(e2);
284
- return r2 ? JSON.parse(r2) : void 0;
285
- } catch (t4) {
286
- console.error(t4);
288
+ var e = "".concat(this.prefix, ":").concat(t), r = window.localStorage.getItem(e);
289
+ return r ? JSON.parse(r) : void 0;
290
+ } catch (n) {
291
+ console.error(n);
287
292
  }
288
- }, t2;
289
- }();
290
- let v;
291
- const m = new Uint8Array(16);
292
- function g() {
293
- if (!v && (v = typeof crypto != "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !v))
294
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
295
- return v(m);
293
+ }, o;
294
+ })(), at = function() {
295
+ var o;
296
+ return typeof globalThis < "u" && (!((o = globalThis.crypto) === null || o === void 0) && o.randomUUID) ? globalThis.crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (function(t) {
297
+ var e = 16 * Math.random() | 0;
298
+ return (t === "x" ? e : 3 & e | 8).toString(16);
299
+ }));
300
+ }, It = (function() {
301
+ function o() {
302
+ }
303
+ return o.prototype.generateEventId = function() {
304
+ return at();
305
+ }, o.prototype.createImpressionEvent = function(t, e, r, n, s, i) {
306
+ var u = this.createBaseEvent(t, e, r, n, s);
307
+ return i ? p(p({}, u), { variant: i }) : u;
308
+ }, o.prototype.createBaseEvent = function(t, e, r, n, s) {
309
+ return { eventType: n, eventId: this.generateEventId(), context: t, enabled: e, featureName: r, impressionData: s };
310
+ }, o;
311
+ })();
312
+ function ut(o) {
313
+ return o !== void 0 && !Number.isFinite(o);
296
314
  }
297
- const y = [];
298
- for (let t2 = 0; t2 < 256; ++t2)
299
- y.push((t2 + 256).toString(16).slice(1));
300
- var b = { randomUUID: typeof crypto != "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
301
- function x(t2, e2, r2) {
302
- if (b.randomUUID && !e2 && !t2)
303
- return b.randomUUID();
304
- const n2 = (t2 = t2 || {}).random || (t2.rng || g)();
305
- if (n2[6] = 15 & n2[6] | 64, n2[8] = 63 & n2[8] | 128, e2) {
306
- r2 = r2 || 0;
307
- for (let t3 = 0; t3 < 16; ++t3)
308
- e2[r2 + t3] = n2[t3];
309
- return e2;
315
+ function _(o) {
316
+ return o ? Object.keys(o).sort().map((function(t) {
317
+ return "".concat(t, "=").concat(o[t]);
318
+ })).join(",") : "";
319
+ }
320
+ function ct(o) {
321
+ var t = {};
322
+ if (!o) return t;
323
+ for (var e = 0, r = o.split(","); e < r.length; e++) {
324
+ var n = r[e].split("="), s = n[0], i = n[1];
325
+ t[s] = i;
310
326
  }
311
- return function(t3, e3 = 0) {
312
- return y[t3[e3 + 0]] + y[t3[e3 + 1]] + y[t3[e3 + 2]] + y[t3[e3 + 3]] + "-" + y[t3[e3 + 4]] + y[t3[e3 + 5]] + "-" + y[t3[e3 + 6]] + y[t3[e3 + 7]] + "-" + y[t3[e3 + 8]] + y[t3[e3 + 9]] + "-" + y[t3[e3 + 10]] + y[t3[e3 + 11]] + y[t3[e3 + 12]] + y[t3[e3 + 13]] + y[t3[e3 + 14]] + y[t3[e3 + 15]];
313
- }(n2);
327
+ return t;
314
328
  }
315
- var T = function() {
316
- function t2() {
329
+ var kt = function(o) {
330
+ return "value" in o;
331
+ }, tt = function(o) {
332
+ return "buckets" in o;
333
+ }, Ot = (function() {
334
+ function o(t) {
335
+ this.opts = t, this.values = /* @__PURE__ */ new Map();
336
+ }
337
+ return o.prototype.inc = function(t, e) {
338
+ var r;
339
+ if (!ut(t)) {
340
+ var n = t ?? 1;
341
+ if (!(n <= 0)) {
342
+ var s = _(e), i = (r = this.values.get(s)) !== null && r !== void 0 ? r : 0;
343
+ this.values.set(s, i + n);
344
+ }
345
+ }
346
+ }, o.prototype.collect = function() {
347
+ var t = Array.from(this.values.entries()).map((function(e) {
348
+ var r = e[0], n = e[1];
349
+ return { labels: ct(r), value: n };
350
+ }));
351
+ return this.values.clear(), t.length === 0 && t.push({ labels: {}, value: 0 }), { name: this.opts.name, help: this.opts.help, type: "counter", samples: t };
352
+ }, o;
353
+ })(), Nt = (function() {
354
+ function o(t) {
355
+ this.opts = t, this.values = /* @__PURE__ */ new Map();
356
+ var e = t.buckets && t.buckets.length > 0 ? t.buckets : [5e-3, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10], r = Array.from(new Set(e.filter((function(n) {
357
+ return n !== 1 / 0;
358
+ })))).sort((function(n, s) {
359
+ return n - s;
360
+ }));
361
+ this.buckets = C(C([], r, !0), [1 / 0], !1);
317
362
  }
318
- return t2.prototype.generateEventId = function() {
319
- return x();
320
- }, t2.prototype.createImpressionEvent = function(t3, r2, n2, o2, i2, s2) {
321
- var a2 = this.createBaseEvent(t3, r2, n2, o2, i2);
322
- return s2 ? e(e({}, a2), { variant: s2 }) : a2;
323
- }, t2.prototype.createBaseEvent = function(t3, e2, r2, n2, o2) {
324
- return { eventType: n2, eventId: this.generateEventId(), context: t3, enabled: e2, featureName: r2, impressionData: o2 };
325
- }, t2;
326
- }(), w = ["userId", "sessionId", "remoteAddress", "currentTime"], E = function(t2) {
327
- return w.includes(t2);
328
- }, S = { INIT: "initialized", ERROR: "error", READY: "ready", UPDATE: "update", IMPRESSION: "impression", SENT: "sent", RECOVERED: "recovered" }, I = "isEnabled", R = "getVariant", O = { name: "disabled", enabled: false, feature_enabled: false }, k = "repo", N = "repoLastUpdateTimestamp", A = function() {
363
+ return o.prototype.restore = function(t) {
364
+ var e = _(t.labels), r = { count: t.count, sum: t.sum, buckets: new Map(t.buckets.map((function(n) {
365
+ return [n.le === "+Inf" ? 1 / 0 : n.le, n.count];
366
+ }))) };
367
+ this.values.set(e, r);
368
+ }, o.prototype.observe = function(t, e) {
369
+ var r;
370
+ if (!ut(t)) {
371
+ var n = _(e), s = this.values.get(n);
372
+ if (!s) {
373
+ for (var i = /* @__PURE__ */ new Map(), u = 0, l = this.buckets; u < l.length; u++) {
374
+ var c = l[u];
375
+ i.set(c, 0);
376
+ }
377
+ s = { count: 0, sum: 0, buckets: i }, this.values.set(n, s);
378
+ }
379
+ s.count++, s.sum += t;
380
+ for (var a = 0, f = this.buckets; a < f.length; a++)
381
+ if (t <= (c = f[a])) {
382
+ var x = (r = s.buckets.get(c)) !== null && r !== void 0 ? r : 0;
383
+ s.buckets.set(c, x + 1);
384
+ }
385
+ }
386
+ }, o.prototype.collect = function() {
387
+ var t = Array.from(this.values.entries()).map((function(e) {
388
+ var r = e[0], n = e[1];
389
+ return { labels: ct(r), count: n.count, sum: n.sum, buckets: Array.from(n.buckets.entries()).map((function(s) {
390
+ var i = s[0];
391
+ return { le: i === 1 / 0 ? "+Inf" : i, count: s[1] };
392
+ })) };
393
+ }));
394
+ return this.values.clear(), t.length === 0 && t.push({ labels: {}, count: 0, sum: 0, buckets: this.buckets.map((function(e) {
395
+ return { le: e === 1 / 0 ? "+Inf" : e, count: 0 };
396
+ })) }), { name: this.opts.name, help: this.opts.help, type: "histogram", samples: t };
397
+ }, o;
398
+ })(), Ct = (function() {
399
+ function o() {
400
+ this.counters = /* @__PURE__ */ new Map(), this.histograms = /* @__PURE__ */ new Map();
401
+ }
402
+ return o.prototype.getCounter = function(t) {
403
+ return this.counters.get(t);
404
+ }, o.prototype.getHistogram = function(t) {
405
+ return this.histograms.get(t);
406
+ }, o.prototype.counter = function(t) {
407
+ var e = t.name, r = this.counters.get(e);
408
+ return r || (r = new Ot(t), this.counters.set(e, r)), r;
409
+ }, o.prototype.histogram = function(t) {
410
+ var e = t.name, r = this.histograms.get(e);
411
+ return r || (r = new Nt(t), this.histograms.set(e, r)), r;
412
+ }, o.prototype.collect = function() {
413
+ var t = Array.from(this.counters.values()).map((function(n) {
414
+ return n.collect();
415
+ })), e = Array.from(this.histograms.values()).map((function(n) {
416
+ return n.collect();
417
+ })), r = C(C([], t, !0), e, !0).filter((function(n) {
418
+ return n.samples.length > 0;
419
+ }));
420
+ return r.length > 0 ? r : [];
421
+ }, o.prototype.restore = function(t) {
422
+ for (var e = function(i) {
423
+ switch (i.type) {
424
+ case "counter":
425
+ for (var u = r.counter({ name: i.name, help: i.help }), l = 0, c = i.samples; l < c.length; l++) {
426
+ var a = c[l];
427
+ kt(a) && u.inc(a.value, a.labels);
428
+ }
429
+ break;
430
+ case "histogram":
431
+ var f = i.samples.find(tt);
432
+ if (f) {
433
+ var x = f.buckets.map((function(b) {
434
+ return b.le === "+Inf" ? 1 / 0 : b.le;
435
+ })), T = r.histogram({ name: i.name, help: i.help, buckets: x });
436
+ i.samples.filter(tt).forEach((function(b) {
437
+ T.restore(b);
438
+ }));
439
+ }
440
+ }
441
+ }, r = this, n = 0, s = t; n < s.length; n++)
442
+ e(s[n]);
443
+ }, o;
444
+ })(), m = { INIT: "initialized", ERROR: "error", READY: "ready", UPDATE: "update", IMPRESSION: "impression", SENT: "sent", RECOVERED: "recovered", WARN: "warn" }, At = (function(o) {
445
+ function t(e, r, n) {
446
+ var s = o.call(this) || this;
447
+ return s.metricRegistry = e, s.appName = r, s.environment = n, s;
448
+ }
449
+ return ot(t, o), t.prototype.defineCounter = function(e, r) {
450
+ e && r ? this.metricRegistry.counter({ name: e, help: r, labelNames: ["featureName", "appName", "environment"] }) : this.emit(m.WARN, "Counter name or help cannot be empty: ".concat(e, ", ").concat(r, "."));
451
+ }, t.prototype.defineHistogram = function(e, r, n) {
452
+ e && r ? this.metricRegistry.histogram({ name: e, help: r, labelNames: ["featureName", "appName", "environment"], buckets: n }) : this.emit(m.WARN, "Histogram name or help cannot be empty: ".concat(e, ", ").concat(r, "."));
453
+ }, t.prototype.incrementCounter = function(e, r) {
454
+ var n = this.metricRegistry.getCounter(e);
455
+ if (n) {
456
+ var s = { appName: this.appName, environment: this.environment };
457
+ n.inc(r, s);
458
+ } else this.emit(m.WARN, "Counter ".concat(e, " not defined, this counter will not be incremented."));
459
+ }, t.prototype.observeHistogram = function(e, r) {
460
+ var n = this.metricRegistry.getHistogram(e);
461
+ if (n) {
462
+ var s = { appName: this.appName, environment: this.environment };
463
+ n.observe(r, s);
464
+ } else this.emit(m.WARN, "Histogram ".concat(e, " not defined, this histogram will not be updated."));
465
+ }, t;
466
+ })(st.TinyEmitter), Ut = ["userId", "sessionId", "remoteAddress", "currentTime"], et = function(o) {
467
+ return Ut.includes(o);
468
+ }, Pt = "isEnabled", Mt = "getVariant", Lt = { name: "disabled", enabled: !1, feature_enabled: !1 }, D = "repo", rt = "repoLastUpdateTimestamp", Ht = function() {
329
469
  try {
330
- if (typeof window != "undefined" && "fetch" in window)
331
- return fetch.bind(window);
332
- if ("fetch" in globalThis)
333
- return fetch.bind(globalThis);
334
- } catch (t2) {
335
- console.error('Unleash failed to resolve "fetch"', t2);
470
+ if (typeof window < "u" && "fetch" in window) return fetch.bind(window);
471
+ if ("fetch" in globalThis) return fetch.bind(globalThis);
472
+ } catch (o) {
473
+ console.error('Unleash failed to resolve "fetch"', o);
336
474
  }
337
- }, U = function(o2) {
338
- function i2(t2) {
339
- var r2 = t2.storageProvider, n2 = t2.url, i3 = t2.clientKey, s2 = t2.disableRefresh, a2 = s2 !== void 0 && s2, c2 = t2.refreshInterval, u2 = c2 === void 0 ? 30 : c2, l2 = t2.metricsInterval, h2 = l2 === void 0 ? 30 : l2, v2 = t2.metricsIntervalInitial, m2 = v2 === void 0 ? 2 : v2, g2 = t2.disableMetrics, y2 = g2 !== void 0 && g2, b2 = t2.appName, x2 = t2.environment, w2 = x2 === void 0 ? "default" : x2, E2 = t2.context, I2 = t2.fetch, R2 = I2 === void 0 ? A() : I2, O2 = t2.createAbortController, k2 = O2 === void 0 ? function() {
475
+ }, Dt = (function(o) {
476
+ function t(e) {
477
+ var r, n = e.storageProvider, s = e.url, i = e.clientKey, u = e.disableRefresh, l = u !== void 0 && u, c = e.refreshInterval, a = c === void 0 ? 30 : c, f = e.metricsInterval, x = f === void 0 ? 30 : f, T = e.metricsIntervalInitial, b = T === void 0 ? 2 : T, d = e.disableMetrics, v = d !== void 0 && d, E = e.appName, k = e.environment, U = k === void 0 ? "default" : k, M = e.context, K = e.fetch, L = K === void 0 ? Ht() : K, B = e.createAbortController, q = B === void 0 ? (function() {
340
478
  try {
341
- if (typeof window != "undefined" && "AbortController" in window)
342
- return function() {
343
- return new window.AbortController();
344
- };
345
- if ("fetch" in globalThis)
346
- return function() {
347
- return new globalThis.AbortController();
348
- };
349
- } catch (t3) {
350
- console.error('Unleash failed to resolve "AbortController" factory', t3);
479
+ if (typeof window < "u" && "AbortController" in window) return function() {
480
+ return new window.AbortController();
481
+ };
482
+ if ("fetch" in globalThis) return function() {
483
+ return new globalThis.AbortController();
484
+ };
485
+ } catch (I) {
486
+ console.error('Unleash failed to resolve "AbortController" factory', I);
351
487
  }
352
- }() : O2, N2 = t2.bootstrap, U2 = t2.bootstrapOverride, D = U2 === void 0 || U2, j = t2.headerName, C = j === void 0 ? "Authorization" : j, P = t2.customHeaders, L = P === void 0 ? {} : P, H = t2.impressionDataAll, M = H !== void 0 && H, _ = t2.usePOSTrequests, F = _ !== void 0 && _, K = t2.experimental, V = o2.call(this) || this;
353
- if (V.toggles = [], V.etag = "", V.readyEventEmitted = false, V.fetchedFromServer = false, V.usePOSTrequests = false, V.started = false, !n2)
354
- throw new Error("url is required");
355
- if (!i3)
356
- throw new Error("clientKey is required");
357
- if (!b2)
358
- throw new Error("appName is required.");
359
- return V.eventsHandler = new T(), V.impressionDataAll = M, V.toggles = N2 && N2.length > 0 ? N2 : [], V.url = n2 instanceof URL ? n2 : new URL(n2), V.clientKey = i3, V.headerName = C, V.customHeaders = L, V.storage = r2 || (typeof window != "undefined" ? new d() : new f()), V.refreshInterval = a2 ? 0 : 1e3 * u2, V.context = e({ appName: b2, environment: w2 }, E2), V.usePOSTrequests = F, V.sdkState = "initializing", V.experimental = e({}, K), (K == null ? void 0 : K.togglesStorageTTL) && (K == null ? void 0 : K.togglesStorageTTL) > 0 && (V.experimental.togglesStorageTTL = 1e3 * K.togglesStorageTTL), V.lastRefreshTimestamp = 0, V.ready = new Promise(function(t3) {
360
- V.init().then(t3).catch(function(e2) {
361
- console.error(e2), V.sdkState = "error", V.emit(S.ERROR, e2), V.lastError = e2, t3();
362
- });
363
- }), R2 || console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'), k2 || console.error('Unleash: You must either provide your own "AbortController" implementation or run in an environment where "AbortController" is available.'), V.fetch = R2, V.createAbortController = k2, V.bootstrap = N2 && N2.length > 0 ? N2 : void 0, V.bootstrapOverride = D, V.connectionId = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t3) {
364
- var e2 = 16 * Math.random() | 0;
365
- return (t3 === "x" ? e2 : 3 & e2 | 8).toString(16);
366
- }), V.metrics = new p({ onError: V.emit.bind(V, S.ERROR), onSent: V.emit.bind(V, S.SENT), appName: b2, metricsInterval: h2, disableMetrics: y2, url: V.url, clientKey: i3, fetch: R2, headerName: C, customHeaders: L, metricsIntervalInitial: m2, connectionId: V.connectionId }), V;
488
+ })() : B, R = e.bootstrap, Y = e.bootstrapOverride, ft = Y === void 0 || Y, W = e.headerName, z = W === void 0 ? "Authorization" : W, J = e.customHeaders, G = J === void 0 ? {} : J, $ = e.impressionDataAll, pt = $ !== void 0 && $, Q = e.usePOSTrequests, dt = Q !== void 0 && Q, w = e.experimental, h = o.call(this) || this;
489
+ if (h.toggles = [], h.etag = "", h.readyEventEmitted = !1, h.fetchedFromServer = !1, h.usePOSTrequests = !1, h.started = !1, !s) throw new Error("url is required");
490
+ if (!i) throw new Error("clientKey is required");
491
+ if (!E) throw new Error("appName is required.");
492
+ h.eventsHandler = new It(), h.impressionDataAll = pt, h.toggles = R && R.length > 0 ? R : [], h.url = s instanceof URL ? s : new URL(s), h.clientKey = i, h.headerName = z, h.customHeaders = G, h.storage = n || (typeof window < "u" ? new Rt() : new St()), h.refreshInterval = l ? 0 : 1e3 * a, h.context = p({ appName: E, environment: U }, M), h.usePOSTrequests = dt, h.sdkState = "initializing";
493
+ var O = w == null ? void 0 : w.metricsUrl;
494
+ !O || O instanceof URL || (O = new URL(O)), h.experimental = p(p({}, w), { metricsUrl: O }), w != null && w.togglesStorageTTL && (w == null ? void 0 : w.togglesStorageTTL) > 0 && (h.experimental.togglesStorageTTL = 1e3 * w.togglesStorageTTL), h.lastRefreshTimestamp = 0, h.ready = new Promise((function(I) {
495
+ h.init().then(I).catch((function(H) {
496
+ console.error(H), h.sdkState = "error", h.emit(m.ERROR, H), h.lastError = H, I();
497
+ }));
498
+ })), L || console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'), q || console.error('Unleash: You must either provide your own "AbortController" implementation or run in an environment where "AbortController" is available.'), h.fetch = L, h.createAbortController = q, h.bootstrap = R && R.length > 0 ? R : void 0, h.bootstrapOverride = ft, h.connectionId = at(), h.metricRegistry = new Ct();
499
+ var vt = h.resolveEnvironment(i, U);
500
+ return h.impactMetrics = new At(h.metricRegistry, E, vt), h.metrics = new wt({ onError: function(I) {
501
+ return h.emit(m.ERROR, { type: "metrics", error: I });
502
+ }, onSent: h.emit.bind(h, m.SENT), appName: E, metricsInterval: x, disableMetrics: v, url: ((r = h.experimental) === null || r === void 0 ? void 0 : r.metricsUrl) || h.url, clientKey: i, fetch: L, headerName: z, customHeaders: G, metricsIntervalInitial: b, connectionId: h.connectionId, metricRegistry: h.metricRegistry }), h;
367
503
  }
368
- return function(e2, r2) {
369
- if (typeof r2 != "function" && r2 !== null)
370
- throw new TypeError("Class extends value " + String(r2) + " is not a constructor or null");
371
- function n2() {
372
- this.constructor = e2;
373
- }
374
- t(e2, r2), e2.prototype = r2 === null ? Object.create(r2) : (n2.prototype = r2.prototype, new n2());
375
- }(i2, o2), i2.prototype.getAllToggles = function() {
376
- return function(t2, e2, r2) {
377
- if (r2 || arguments.length === 2)
378
- for (var n2, o3 = 0, i3 = e2.length; o3 < i3; o3++)
379
- !n2 && o3 in e2 || (n2 || (n2 = Array.prototype.slice.call(e2, 0, o3)), n2[o3] = e2[o3]);
380
- return t2.concat(n2 || Array.prototype.slice.call(e2));
381
- }([], this.toggles, true);
382
- }, i2.prototype.isEnabled = function(t2) {
383
- var e2, r2 = this.toggles.find(function(e3) {
384
- return e3.name === t2;
385
- }), n2 = !!r2 && r2.enabled;
386
- if (this.metrics.count(t2, n2), (r2 == null ? void 0 : r2.impressionData) || this.impressionDataAll) {
387
- var o3 = this.eventsHandler.createImpressionEvent(this.context, n2, t2, I, (e2 = r2 == null ? void 0 : r2.impressionData) !== null && e2 !== void 0 ? e2 : void 0);
388
- this.emit(S.IMPRESSION, o3);
504
+ return ot(t, o), t.prototype.getAllToggles = function() {
505
+ return C([], this.toggles, !0);
506
+ }, t.prototype.isEnabled = function(e) {
507
+ var r, n = this.toggles.find((function(u) {
508
+ return u.name === e;
509
+ })), s = !!n && n.enabled;
510
+ if (this.metrics.count(e, s), (n == null ? void 0 : n.impressionData) || this.impressionDataAll) {
511
+ var i = this.eventsHandler.createImpressionEvent(this.context, s, e, Pt, (r = n == null ? void 0 : n.impressionData) !== null && r !== void 0 ? r : void 0);
512
+ this.emit(m.IMPRESSION, i);
389
513
  }
390
- return n2;
391
- }, i2.prototype.getVariant = function(t2) {
392
- var r2, n2 = this.toggles.find(function(e2) {
393
- return e2.name === t2;
394
- }), o3 = (n2 == null ? void 0 : n2.enabled) || false, i3 = n2 ? n2.variant : O;
395
- if (i3.name && this.metrics.countVariant(t2, i3.name), this.metrics.count(t2, o3), (n2 == null ? void 0 : n2.impressionData) || this.impressionDataAll) {
396
- var s2 = this.eventsHandler.createImpressionEvent(this.context, o3, t2, R, (r2 = n2 == null ? void 0 : n2.impressionData) !== null && r2 !== void 0 ? r2 : void 0, i3.name);
397
- this.emit(S.IMPRESSION, s2);
514
+ return s;
515
+ }, t.prototype.getVariant = function(e) {
516
+ var r, n = this.toggles.find((function(l) {
517
+ return l.name === e;
518
+ })), s = (n == null ? void 0 : n.enabled) || !1, i = n ? n.variant : Lt;
519
+ if (i.name && this.metrics.countVariant(e, i.name), this.metrics.count(e, s), (n == null ? void 0 : n.impressionData) || this.impressionDataAll) {
520
+ var u = this.eventsHandler.createImpressionEvent(this.context, s, e, Mt, (r = n == null ? void 0 : n.impressionData) !== null && r !== void 0 ? r : void 0, i.name);
521
+ this.emit(m.IMPRESSION, u);
398
522
  }
399
- return e(e({}, i3), { feature_enabled: o3 });
400
- }, i2.prototype.updateToggles = function() {
401
- return r(this, void 0, void 0, function() {
402
- var t2 = this;
403
- return n(this, function(e2) {
404
- switch (e2.label) {
523
+ return p(p({}, i), { feature_enabled: s });
524
+ }, t.prototype.updateToggles = function() {
525
+ return g(this, void 0, void 0, (function() {
526
+ var e = this;
527
+ return y(this, (function(r) {
528
+ switch (r.label) {
405
529
  case 0:
406
530
  return this.timerRef || this.fetchedFromServer ? [4, this.fetchToggles()] : [3, 2];
407
531
  case 1:
408
- return e2.sent(), [3, 4];
532
+ return r.sent(), [3, 4];
409
533
  case 2:
410
- return this.started ? [4, new Promise(function(e3) {
411
- var r2 = function() {
412
- t2.fetchToggles().then(function() {
413
- t2.off(S.READY, r2), e3();
414
- });
534
+ return this.started ? [4, new Promise((function(n) {
535
+ var s = function() {
536
+ e.fetchToggles().then((function() {
537
+ e.off(m.READY, s), n();
538
+ }));
415
539
  };
416
- t2.once(S.READY, r2);
417
- })] : [3, 4];
540
+ e.once(m.READY, s);
541
+ }))] : [3, 4];
418
542
  case 3:
419
- e2.sent(), e2.label = 4;
543
+ r.sent(), r.label = 4;
420
544
  case 4:
421
545
  return [2];
422
546
  }
423
- });
424
- });
425
- }, i2.prototype.updateContext = function(t2) {
426
- return r(this, void 0, void 0, function() {
427
- var r2;
428
- return n(this, function(n2) {
429
- switch (n2.label) {
547
+ }));
548
+ }));
549
+ }, t.prototype.updateContext = function(e) {
550
+ return g(this, void 0, void 0, (function() {
551
+ var r;
552
+ return y(this, (function(n) {
553
+ switch (n.label) {
430
554
  case 0:
431
- return (t2.appName || t2.environment) && console.warn("appName and environment are static. They can't be updated with updateContext."), r2 = { environment: this.context.environment, appName: this.context.appName, sessionId: this.context.sessionId }, this.context = e(e({}, r2), t2), [4, this.updateToggles()];
555
+ return (e.appName || e.environment) && this.emit(m.WARN, "appName and environment are static. They can't be updated with updateContext."), r = { environment: this.context.environment, appName: this.context.appName, sessionId: this.context.sessionId }, this.context = p(p({}, r), e), [4, this.updateToggles()];
432
556
  case 1:
433
- return n2.sent(), [2];
557
+ return n.sent(), [2];
434
558
  }
435
- });
436
- });
437
- }, i2.prototype.getContext = function() {
438
- return e({}, this.context);
439
- }, i2.prototype.setContextField = function(t2, r2) {
440
- var n2, o3;
441
- if (E(t2))
442
- this.context = e(e({}, this.context), ((n2 = {})[t2] = r2, n2));
443
- else {
444
- var i3 = e(e({}, this.context.properties), ((o3 = {})[t2] = r2, o3));
445
- this.context = e(e({}, this.context), { properties: i3 });
446
- }
447
- this.updateToggles();
448
- }, i2.prototype.removeContextField = function(t2) {
449
- var r2;
450
- E(t2) ? this.context = e(e({}, this.context), ((r2 = {})[t2] = void 0, r2)) : typeof this.context.properties == "object" && delete this.context.properties[t2], this.updateToggles();
451
- }, i2.prototype.setReady = function() {
452
- this.readyEventEmitted = true, this.emit(S.READY);
453
- }, i2.prototype.init = function() {
454
- return r(this, void 0, void 0, function() {
455
- var t2, r2, o3;
456
- return n(this, function(n2) {
457
- switch (n2.label) {
559
+ }));
560
+ }));
561
+ }, t.prototype.getContext = function() {
562
+ return p({}, this.context);
563
+ }, t.prototype.setContextField = function(e, r) {
564
+ return g(this, void 0, void 0, (function() {
565
+ var n, s, i;
566
+ return y(this, (function(u) {
567
+ switch (u.label) {
568
+ case 0:
569
+ return et(e) ? this.context = p(p({}, this.context), ((s = {})[e] = r, s)) : (n = p(p({}, this.context.properties), ((i = {})[e] = r, i)), this.context = p(p({}, this.context), { properties: n })), [4, this.updateToggles()];
570
+ case 1:
571
+ return u.sent(), [2];
572
+ }
573
+ }));
574
+ }));
575
+ }, t.prototype.removeContextField = function(e) {
576
+ return g(this, void 0, void 0, (function() {
577
+ var r;
578
+ return y(this, (function(n) {
579
+ switch (n.label) {
580
+ case 0:
581
+ return et(e) ? this.context = p(p({}, this.context), ((r = {})[e] = void 0, r)) : typeof this.context.properties == "object" && delete this.context.properties[e], [4, this.updateToggles()];
582
+ case 1:
583
+ return n.sent(), [2];
584
+ }
585
+ }));
586
+ }));
587
+ }, t.prototype.setReady = function() {
588
+ this.readyEventEmitted = !0, this.emit(m.READY);
589
+ }, t.prototype.init = function() {
590
+ return g(this, void 0, void 0, (function() {
591
+ var e, r, n;
592
+ return y(this, (function(s) {
593
+ switch (s.label) {
458
594
  case 0:
459
595
  return [4, this.resolveSessionId()];
460
596
  case 1:
461
- return t2 = n2.sent(), this.context = e({ sessionId: t2 }, this.context), r2 = this, [4, this.storage.get(k)];
597
+ return e = s.sent(), this.context = p({ sessionId: e }, this.context), [4, this.storage.get(D)];
462
598
  case 2:
463
- return r2.toggles = n2.sent() || [], o3 = this, [4, this.getLastRefreshTimestamp()];
599
+ return r = s.sent() || [], n = this, [4, this.getLastRefreshTimestamp()];
464
600
  case 3:
465
- return o3.lastRefreshTimestamp = n2.sent(), !this.bootstrap || !this.bootstrapOverride && this.toggles.length !== 0 ? [3, 6] : [4, this.storage.save(k, this.bootstrap)];
601
+ return n.lastRefreshTimestamp = s.sent(), !this.bootstrap || !this.bootstrapOverride && r.length !== 0 ? [3, 6] : [4, this.storage.save(D, this.bootstrap)];
466
602
  case 4:
467
- return n2.sent(), this.toggles = this.bootstrap, this.sdkState = "healthy", [4, this.storeLastRefreshTimestamp()];
603
+ return s.sent(), this.toggles = this.bootstrap, this.sdkState = "healthy", [4, this.storeLastRefreshTimestamp()];
468
604
  case 5:
469
- n2.sent(), this.setReady(), n2.label = 6;
605
+ return s.sent(), this.setReady(), [3, 7];
470
606
  case 6:
471
- return this.sdkState = "healthy", this.emit(S.INIT), [2];
607
+ this.toggles = r, s.label = 7;
608
+ case 7:
609
+ return this.sdkState = "healthy", this.emit(m.INIT), [2];
472
610
  }
473
- });
474
- });
475
- }, i2.prototype.start = function() {
476
- return r(this, void 0, void 0, function() {
477
- var t2, e2 = this;
478
- return n(this, function(r2) {
479
- switch (r2.label) {
611
+ }));
612
+ }));
613
+ }, t.prototype.start = function() {
614
+ return g(this, void 0, void 0, (function() {
615
+ var e, r = this;
616
+ return y(this, (function(n) {
617
+ switch (n.label) {
480
618
  case 0:
481
- return this.started = true, this.timerRef ? (console.error("Unleash SDK has already started, if you want to restart the SDK you should call client.stop() before starting again."), [2]) : [4, this.ready];
619
+ return this.started = !0, this.timerRef ? (console.error("Unleash SDK has already started, if you want to restart the SDK you should call client.stop() before starting again."), [2]) : [4, this.ready];
482
620
  case 1:
483
- return r2.sent(), this.metrics.start(), t2 = this.refreshInterval, [4, this.initialFetchToggles()];
621
+ return n.sent(), this.metrics.start(), e = this.refreshInterval, [4, this.initialFetchToggles()];
484
622
  case 2:
485
- return r2.sent(), t2 > 0 && (this.timerRef = setInterval(function() {
486
- return e2.fetchToggles();
487
- }, t2)), [2];
623
+ return n.sent(), e > 0 && (this.timerRef = setInterval((function() {
624
+ return r.fetchToggles();
625
+ }), e)), [2];
488
626
  }
489
- });
490
- });
491
- }, i2.prototype.stop = function() {
627
+ }));
628
+ }));
629
+ }, t.prototype.stop = function() {
492
630
  this.timerRef && (clearInterval(this.timerRef), this.timerRef = void 0), this.metrics.stop();
493
- }, i2.prototype.isReady = function() {
631
+ }, t.prototype.isReady = function() {
494
632
  return this.readyEventEmitted;
495
- }, i2.prototype.getError = function() {
633
+ }, t.prototype.getError = function() {
496
634
  return this.sdkState === "error" ? this.lastError : void 0;
497
- }, i2.prototype.sendMetrics = function() {
635
+ }, t.prototype.sendMetrics = function() {
498
636
  return this.metrics.sendMetrics();
499
- }, i2.prototype.resolveSessionId = function() {
500
- return r(this, void 0, void 0, function() {
501
- var t2;
502
- return n(this, function(e2) {
503
- switch (e2.label) {
637
+ }, t.prototype.resolveSessionId = function() {
638
+ return g(this, void 0, void 0, (function() {
639
+ var e;
640
+ return y(this, (function(r) {
641
+ switch (r.label) {
504
642
  case 0:
505
643
  return this.context.sessionId ? [2, this.context.sessionId] : [4, this.storage.get("sessionId")];
506
644
  case 1:
507
- return (t2 = e2.sent()) ? [3, 3] : (t2 = Math.floor(1e9 * Math.random()), [4, this.storage.save("sessionId", t2.toString(10))]);
645
+ return (e = r.sent()) ? [3, 3] : (e = Math.floor(1e9 * Math.random()), [4, this.storage.save("sessionId", e.toString(10))]);
508
646
  case 2:
509
- e2.sent(), e2.label = 3;
647
+ r.sent(), r.label = 3;
510
648
  case 3:
511
- return [2, t2.toString(10)];
649
+ return [2, e.toString(10)];
512
650
  }
513
- });
514
- });
515
- }, i2.prototype.getHeaders = function() {
516
- var t2, e2 = this.usePOSTrequests, r2 = ((t2 = {})[this.headerName] = this.clientKey, t2.Accept = "application/json", t2["x-unleash-sdk"] = l, t2["x-unleash-connection-id"] = this.connectionId, t2["x-unleash-appname"] = this.context.appName, t2);
517
- return e2 && (r2["Content-Type"] = "application/json"), this.etag && (r2["If-None-Match"] = this.etag), Object.entries(this.customHeaders).filter(a).forEach(function(t3) {
518
- var e3 = t3[0], n2 = t3[1];
519
- return r2[e3] = n2;
520
- }), r2;
521
- }, i2.prototype.storeToggles = function(t2) {
522
- return r(this, void 0, void 0, function() {
523
- return n(this, function(e2) {
524
- switch (e2.label) {
651
+ }));
652
+ }));
653
+ }, t.prototype.getHeaders = function() {
654
+ return it({ clientKey: this.clientKey, connectionId: this.connectionId, appName: this.context.appName, customHeaders: this.customHeaders, headerName: this.headerName, etag: this.etag, isPost: this.usePOSTrequests });
655
+ }, t.prototype.storeToggles = function(e) {
656
+ return g(this, void 0, void 0, (function() {
657
+ return y(this, (function(r) {
658
+ switch (r.label) {
525
659
  case 0:
526
- return this.toggles = t2, this.emit(S.UPDATE), [4, this.storage.save(k, t2)];
660
+ return this.toggles = e, this.emit(m.UPDATE), [4, this.storage.save(D, e)];
527
661
  case 1:
528
- return e2.sent(), [2];
662
+ return r.sent(), [2];
529
663
  }
530
- });
531
- });
532
- }, i2.prototype.isTogglesStorageTTLEnabled = function() {
533
- var t2;
534
- return !!(((t2 = this.experimental) === null || t2 === void 0 ? void 0 : t2.togglesStorageTTL) && this.experimental.togglesStorageTTL > 0);
535
- }, i2.prototype.isUpToDate = function() {
536
- var t2;
537
- if (!this.isTogglesStorageTTLEnabled())
538
- return false;
539
- var e2 = Date.now(), r2 = ((t2 = this.experimental) === null || t2 === void 0 ? void 0 : t2.togglesStorageTTL) || 0;
540
- return this.lastRefreshTimestamp > 0 && this.lastRefreshTimestamp <= e2 && e2 - this.lastRefreshTimestamp <= r2;
541
- }, i2.prototype.getLastRefreshTimestamp = function() {
542
- return r(this, void 0, void 0, function() {
543
- var t2, e2;
544
- return n(this, function(r2) {
545
- switch (r2.label) {
664
+ }));
665
+ }));
666
+ }, t.prototype.isTogglesStorageTTLEnabled = function() {
667
+ var e;
668
+ return !!(!((e = this.experimental) === null || e === void 0) && e.togglesStorageTTL && this.experimental.togglesStorageTTL > 0);
669
+ }, t.prototype.isUpToDate = function() {
670
+ var e;
671
+ if (!this.isTogglesStorageTTLEnabled()) return !1;
672
+ var r = Date.now(), n = ((e = this.experimental) === null || e === void 0 ? void 0 : e.togglesStorageTTL) || 0;
673
+ return this.lastRefreshTimestamp > 0 && this.lastRefreshTimestamp <= r && r - this.lastRefreshTimestamp <= n;
674
+ }, t.prototype.getLastRefreshTimestamp = function() {
675
+ return g(this, void 0, void 0, (function() {
676
+ var e, r;
677
+ return y(this, (function(n) {
678
+ switch (n.label) {
546
679
  case 0:
547
- return this.isTogglesStorageTTLEnabled() ? [4, this.storage.get(N)] : [3, 3];
680
+ return this.isTogglesStorageTTLEnabled() ? [4, this.storage.get(rt)] : [3, 3];
548
681
  case 1:
549
- return t2 = r2.sent(), [4, u(this.context)];
682
+ return e = n.sent(), [4, V(this.context)];
550
683
  case 2:
551
- return e2 = r2.sent(), [2, (t2 == null ? void 0 : t2.key) === e2 ? t2.timestamp : 0];
684
+ return r = n.sent(), [2, (e == null ? void 0 : e.key) === r ? e.timestamp : 0];
552
685
  case 3:
553
686
  return [2, 0];
554
687
  }
555
- });
556
- });
557
- }, i2.prototype.storeLastRefreshTimestamp = function() {
558
- return r(this, void 0, void 0, function() {
559
- var t2, e2;
560
- return n(this, function(r2) {
561
- switch (r2.label) {
688
+ }));
689
+ }));
690
+ }, t.prototype.storeLastRefreshTimestamp = function() {
691
+ return g(this, void 0, void 0, (function() {
692
+ var e, r;
693
+ return y(this, (function(n) {
694
+ switch (n.label) {
562
695
  case 0:
563
- return this.isTogglesStorageTTLEnabled() ? (this.lastRefreshTimestamp = Date.now(), e2 = {}, [4, u(this.context)]) : [3, 3];
696
+ return this.isTogglesStorageTTLEnabled() ? (this.lastRefreshTimestamp = Date.now(), r = {}, [4, V(this.context)]) : [3, 3];
564
697
  case 1:
565
- return e2.key = r2.sent(), e2.timestamp = this.lastRefreshTimestamp, t2 = e2, [4, this.storage.save(N, t2)];
698
+ return r.key = n.sent(), r.timestamp = this.lastRefreshTimestamp, e = r, [4, this.storage.save(rt, e)];
566
699
  case 2:
567
- r2.sent(), r2.label = 3;
700
+ n.sent(), n.label = 3;
568
701
  case 3:
569
702
  return [2];
570
703
  }
571
- });
572
- });
573
- }, i2.prototype.initialFetchToggles = function() {
574
- if (!this.isUpToDate())
575
- return this.fetchToggles();
576
- this.fetchedFromServer || (this.fetchedFromServer = true, this.setReady());
577
- }, i2.prototype.fetchToggles = function() {
578
- return r(this, void 0, void 0, function() {
579
- var t2, e2, r2, o3, i3, s2, c2, u2, l2;
580
- return n(this, function(n2) {
581
- switch (n2.label) {
704
+ }));
705
+ }));
706
+ }, t.prototype.initialFetchToggles = function() {
707
+ if (!this.isUpToDate()) return this.fetchToggles();
708
+ this.fetchedFromServer || (this.fetchedFromServer = !0, this.setReady());
709
+ }, t.prototype.fetchToggles = function() {
710
+ return g(this, void 0, void 0, (function() {
711
+ var e, r, n, s, i, u, l, c, a;
712
+ return y(this, (function(f) {
713
+ switch (f.label) {
582
714
  case 0:
583
- if (!this.fetch)
584
- return [3, 9];
585
- this.abortController && this.abortController.abort(), this.abortController = (l2 = this.createAbortController) === null || l2 === void 0 ? void 0 : l2.call(this), t2 = this.abortController ? this.abortController.signal : void 0, n2.label = 1;
715
+ if (!this.fetch) return [3, 9];
716
+ this.abortController && !this.abortController.signal.aborted && this.abortController.abort(), this.abortController = (a = this.createAbortController) === null || a === void 0 ? void 0 : a.call(this), e = this.abortController ? this.abortController.signal : void 0, f.label = 1;
586
717
  case 1:
587
- return n2.trys.push([1, 7, 8, 9]), e2 = this.usePOSTrequests, r2 = e2 ? this.url : function(t3, e3) {
588
- var r3 = new URL(t3.toString());
589
- return Object.entries(e3).filter(a).forEach(function(t4) {
590
- var e4 = t4[0], n3 = t4[1];
591
- e4 === "properties" && n3 ? Object.entries(n3).filter(a).forEach(function(t5) {
592
- var e5 = t5[0], n4 = t5[1];
593
- return r3.searchParams.append("properties[".concat(e5, "]"), n4);
594
- }) : r3.searchParams.append(e4, n3);
595
- }), r3;
596
- }(this.url, this.context), o3 = e2 ? "POST" : "GET", i3 = e2 ? JSON.stringify({ context: this.context }) : void 0, [4, this.fetch(r2.toString(), { method: o3, cache: "no-cache", headers: this.getHeaders(), body: i3, signal: t2 })];
718
+ return f.trys.push([1, 7, 8, 9]), r = this.usePOSTrequests, n = r ? this.url : (function(x, T) {
719
+ var b = new URL(x.toString());
720
+ return Object.entries(T).filter(F).forEach((function(d) {
721
+ var v = d[0], E = d[1];
722
+ v === "properties" && E ? Object.entries(E).filter(F).forEach((function(k) {
723
+ var U = k[0], M = k[1];
724
+ return b.searchParams.append("properties[".concat(U, "]"), M);
725
+ })) : b.searchParams.append(v, E);
726
+ })), b;
727
+ })(this.url, this.context), s = r ? "POST" : "GET", i = r ? JSON.stringify({ context: this.context }) : void 0, [4, this.fetch(n.toString(), { method: s, cache: "no-cache", headers: this.getHeaders(), body: i, signal: e })];
597
728
  case 2:
598
- return s2 = n2.sent(), this.sdkState === "error" && s2.status < 400 && (this.sdkState = "healthy", this.emit(S.RECOVERED)), s2.ok ? (this.etag = s2.headers.get("ETag") || "", [4, s2.json()]) : [3, 5];
729
+ return u = f.sent(), this.sdkState === "error" && u.status < 400 && (this.sdkState = "healthy", this.emit(m.RECOVERED)), u.ok ? (this.etag = u.headers.get("ETag") || "", [4, u.json()]) : [3, 5];
599
730
  case 3:
600
- return c2 = n2.sent(), [4, this.storeToggles(c2.toggles)];
731
+ return l = f.sent(), [4, this.storeToggles(l.toggles)];
601
732
  case 4:
602
- return n2.sent(), this.sdkState !== "healthy" && (this.sdkState = "healthy"), this.fetchedFromServer || (this.fetchedFromServer = true, this.setReady()), this.storeLastRefreshTimestamp(), [3, 6];
733
+ return f.sent(), this.sdkState !== "healthy" && (this.sdkState = "healthy"), this.fetchedFromServer || (this.fetchedFromServer = !0, this.setReady()), this.storeLastRefreshTimestamp(), [3, 6];
603
734
  case 5:
604
- s2.status === 304 ? this.storeLastRefreshTimestamp() : (console.error("Unleash: Fetching feature toggles did not have an ok response"), this.sdkState = "error", this.emit(S.ERROR, { type: "HttpError", code: s2.status }), this.lastError = { type: "HttpError", code: s2.status }), n2.label = 6;
735
+ u.status === 304 ? this.storeLastRefreshTimestamp() : (console.error("Unleash: Fetching feature toggles did not have an ok response"), this.sdkState = "error", this.emit(m.ERROR, { type: "HttpError", code: u.status }), this.lastError = { type: "HttpError", code: u.status }), f.label = 6;
605
736
  case 6:
606
737
  return [3, 9];
607
738
  case 7:
608
- return typeof (u2 = n2.sent()) == "object" && u2 !== null && "name" in u2 && u2.name === "AbortError" || (console.error("Unleash: unable to fetch feature toggles", u2), this.sdkState = "error", this.emit(S.ERROR, u2), this.lastError = u2), [3, 9];
739
+ return typeof (c = f.sent()) == "object" && c !== null && "name" in c && c.name === "AbortError" || (console.error("Unleash: unable to fetch feature toggles", c), this.sdkState = "error", this.emit(m.ERROR, { type: "fetch-toggles", error: c }), this.lastError = c), [3, 9];
609
740
  case 8:
610
741
  return this.abortController = null, [7];
611
742
  case 9:
612
743
  return [2];
613
744
  }
614
- });
615
- });
616
- }, i2;
617
- }(s);
618
- const ContextStateSymbol = Symbol("Context state identifier");
619
- const ContextUpdateSymbol = Symbol("Context update identifier");
620
- function useUnleashProvide({
621
- config,
622
- unleashClient,
623
- startClient = true
745
+ }));
746
+ }));
747
+ }, t.prototype.resolveEnvironment = function(e, r) {
748
+ return (function(n) {
749
+ var s = n.indexOf(":");
750
+ if (s !== -1) {
751
+ var i = n.slice(s + 1), u = i.lastIndexOf(".");
752
+ if (u !== -1) return i.slice(0, u);
753
+ }
754
+ })(e) || r;
755
+ }, t;
756
+ })(st.TinyEmitter);
757
+ const S = Symbol("Context state identifier"), lt = Symbol("Context update identifier");
758
+ function ht({
759
+ config: o,
760
+ unleashClient: t,
761
+ startClient: e = !0
624
762
  }) {
625
- var _a, _b;
626
- const client = ref(unleashClient);
627
- const flagsReady = ref(false);
628
- const flagsError = ref(null);
629
- if (!config && !unleashClient) {
630
- console.warn(`You must provide either a config or an unleash client to the flag provider. If you are initializing the client in useEffect, you can avoid this warning by
631
- checking if the client exists before rendering.`);
632
- }
633
- if (!client.value && config) {
634
- client.value = new U(config);
635
- }
636
- (_a = client.value) == null ? void 0 : _a.on("ready", () => {
637
- flagsReady.value = true;
763
+ var T, b;
764
+ const r = N(t), n = N(!1), s = N(null);
765
+ !o && !t && console.warn(
766
+ `You must provide either a config or an unleash client to the flag provider. If you are initializing the client in useEffect, you can avoid this warning by
767
+ checking if the client exists before rendering.`
768
+ ), !r.value && o && (r.value = new Dt(o)), (T = r.value) == null || T.on("ready", () => {
769
+ n.value = !0;
770
+ }), (b = r.value) == null || b.on("error", (d) => {
771
+ s.value = d;
638
772
  });
639
- (_b = client.value) == null ? void 0 : _b.on("error", (e2) => {
640
- flagsError.value = e2;
641
- });
642
- const updateContext = async (context2) => {
643
- var _a2;
644
- await ((_a2 = client.value) == null ? void 0 : _a2.updateContext(context2));
645
- };
646
- const isEnabled = (name) => {
647
- var _a2;
648
- return (_a2 = client.value) == null ? void 0 : _a2.isEnabled(name);
649
- };
650
- const getVariant = (name) => {
651
- var _a2;
652
- return (_a2 = client.value) == null ? void 0 : _a2.getVariant(name);
653
- };
654
- const on = (event, ...args) => {
655
- var _a2;
656
- return (_a2 = client.value) == null ? void 0 : _a2.on(event, ...args);
657
- };
658
- const context = reactive({
659
- on,
660
- updateContext,
661
- isEnabled,
662
- getVariant,
663
- client,
664
- flagsReady,
665
- flagsError
666
- });
667
- const update = (property, value) => {
668
- context[property] = value;
669
- };
670
- const start = () => {
671
- var _a2;
672
- if (startClient || !unleashClient) {
673
- (_a2 = client == null ? void 0 : client.value) == null ? void 0 : _a2.start();
674
- }
773
+ const a = mt({
774
+ on: (d, ...v) => {
775
+ var E;
776
+ return (E = r.value) == null ? void 0 : E.on(d, ...v);
777
+ },
778
+ updateContext: async (d) => {
779
+ var v;
780
+ await ((v = r.value) == null ? void 0 : v.updateContext(d));
781
+ },
782
+ isEnabled: (d) => {
783
+ var v;
784
+ return (v = r.value) == null ? void 0 : v.isEnabled(d);
785
+ },
786
+ getVariant: (d) => {
787
+ var v;
788
+ return (v = r.value) == null ? void 0 : v.getVariant(d);
789
+ },
790
+ client: r,
791
+ flagsReady: n,
792
+ flagsError: s
793
+ }), f = (d, v) => {
794
+ a[d] = v;
795
+ }, x = () => {
796
+ var d;
797
+ (e || !t) && ((d = r == null ? void 0 : r.value) == null || d.start());
675
798
  };
676
799
  return {
677
- context: toRefs(context),
678
- update,
679
- start
800
+ context: gt(a),
801
+ update: f,
802
+ start: x
680
803
  };
681
804
  }
682
- const _sfc_main = /* @__PURE__ */ defineComponent({
805
+ const _t = /* @__PURE__ */ yt({
683
806
  __name: "FlagProvider",
684
807
  props: {
685
- config: null,
686
- unleashClient: null,
687
- startClient: { type: Boolean }
808
+ config: {},
809
+ unleashClient: {},
810
+ startClient: { type: Boolean, default: !0 }
688
811
  },
689
- setup(__props) {
690
- const {
691
- config,
692
- unleashClient,
693
- startClient = true
694
- } = __props;
695
- const { context, start, update } = useUnleashProvide({
696
- config,
697
- unleashClient,
698
- startClient
699
- });
700
- provide(ContextStateSymbol, context);
701
- provide(ContextUpdateSymbol, update);
702
- onMounted(() => {
703
- start();
812
+ setup(o) {
813
+ const { context: t, start: e, update: r } = ht({
814
+ config: o.config,
815
+ unleashClient: o.unleashClient,
816
+ startClient: o.startClient
704
817
  });
705
- return (_ctx, _cache) => {
706
- return renderSlot(_ctx.$slots, "default");
707
- };
818
+ return X(S, t), X(lt, r), bt(() => {
819
+ e();
820
+ }), (n, s) => xt(n.$slots, "default");
708
821
  }
709
- });
710
- const useFlag = (name) => {
711
- const { isEnabled, client } = inject(ContextStateSymbol, {});
712
- const flag = ref(Boolean(isEnabled == null ? void 0 : isEnabled.value(name)));
713
- function onUpdate() {
714
- const enabled = isEnabled == null ? void 0 : isEnabled.value(name);
715
- if (enabled !== flag.value) {
716
- flag.value = !!enabled;
717
- }
822
+ }), Kt = (o) => {
823
+ const { isEnabled: t, client: e } = A(S, {}), r = N(!!(t != null && t.value(o)));
824
+ function n() {
825
+ const i = t == null ? void 0 : t.value(o);
826
+ i !== r.value && (r.value = !!i);
718
827
  }
719
- function onReady() {
720
- flag.value = Boolean(isEnabled == null ? void 0 : isEnabled.value(name));
828
+ function s() {
829
+ r.value = !!(t != null && t.value(o));
721
830
  }
722
- client == null ? void 0 : client.value.on("ready", onReady);
723
- client == null ? void 0 : client.value.on("update", onUpdate);
724
- onUnmounted(() => {
725
- client == null ? void 0 : client.value.off("ready", onReady);
726
- client == null ? void 0 : client.value.off("update", onUpdate);
727
- });
728
- return flag;
729
- };
730
- const useFlagsStatus = () => {
731
- const { flagsReady, flagsError } = inject(ContextStateSymbol, {});
732
- return { flagsReady, flagsError };
733
- };
734
- const variantHasChanged = (oldVariant, newVariant) => {
735
- var _a, _b, _c, _d;
736
- const variantsAreEqual = (oldVariant == null ? void 0 : oldVariant.name) === (newVariant == null ? void 0 : newVariant.name) && (oldVariant == null ? void 0 : oldVariant.enabled) === (newVariant == null ? void 0 : newVariant.enabled) && (oldVariant == null ? void 0 : oldVariant.feature_enabled) === (newVariant == null ? void 0 : newVariant.feature_enabled) && ((_a = oldVariant == null ? void 0 : oldVariant.payload) == null ? void 0 : _a.type) === ((_b = newVariant == null ? void 0 : newVariant.payload) == null ? void 0 : _b.type) && ((_c = oldVariant == null ? void 0 : oldVariant.payload) == null ? void 0 : _c.value) === ((_d = newVariant == null ? void 0 : newVariant.payload) == null ? void 0 : _d.value);
737
- return !variantsAreEqual;
738
- };
739
- const useVariant = (name) => {
740
- const { getVariant, client } = inject(ContextStateSymbol, {});
741
- const variant = ref(getVariant == null ? void 0 : getVariant.value(name));
742
- function onUpdate() {
743
- const newVariant = getVariant == null ? void 0 : getVariant.value(name);
744
- if (variantHasChanged(variant == null ? void 0 : variant.value, newVariant)) {
745
- variant.value = newVariant;
746
- }
831
+ return e == null || e.value.on("ready", s), e == null || e.value.on("update", n), nt(() => {
832
+ e == null || e.value.off("ready", s), e == null || e.value.off("update", n);
833
+ }), r;
834
+ }, Bt = () => {
835
+ const { flagsReady: o, flagsError: t } = A(
836
+ S,
837
+ {}
838
+ );
839
+ return { flagsReady: o, flagsError: t };
840
+ }, jt = (o, t) => {
841
+ var r, n, s, i;
842
+ return !((o == null ? void 0 : o.name) === (t == null ? void 0 : t.name) && (o == null ? void 0 : o.enabled) === (t == null ? void 0 : t.enabled) && (o == null ? void 0 : o.feature_enabled) === (t == null ? void 0 : t.feature_enabled) && ((r = o == null ? void 0 : o.payload) == null ? void 0 : r.type) === ((n = t == null ? void 0 : t.payload) == null ? void 0 : n.type) && ((s = o == null ? void 0 : o.payload) == null ? void 0 : s.value) === ((i = t == null ? void 0 : t.payload) == null ? void 0 : i.value));
843
+ }, qt = (o) => {
844
+ const { getVariant: t, client: e } = A(S, {}), r = N(t == null ? void 0 : t.value(o));
845
+ function n() {
846
+ const i = t == null ? void 0 : t.value(o);
847
+ jt(r == null ? void 0 : r.value, i) && (r.value = i);
747
848
  }
748
- function onReady() {
749
- variant.value = getVariant == null ? void 0 : getVariant.value(name);
849
+ function s() {
850
+ r.value = t == null ? void 0 : t.value(o);
750
851
  }
751
- client == null ? void 0 : client.value.on("ready", onReady);
752
- client == null ? void 0 : client.value.on("update", onUpdate);
753
- onUnmounted(() => {
754
- client == null ? void 0 : client.value.off("ready", onReady);
755
- client == null ? void 0 : client.value.off("update", onUpdate);
756
- });
757
- return variant || {};
758
- };
759
- const useUnleashContext = () => {
760
- const { updateContext } = inject(ContextStateSymbol, {});
761
- return updateContext == null ? void 0 : updateContext.value;
762
- };
763
- const useUnleashClient = () => {
764
- const { client } = inject(ContextStateSymbol, {});
765
- return client == null ? void 0 : client.value;
766
- };
767
- const plugin = {
768
- install(app, { config, unleashClient, startClient }) {
769
- const { context, update, start } = useUnleashProvide({
770
- config,
771
- unleashClient,
772
- startClient
852
+ return e == null || e.value.on("ready", s), e == null || e.value.on("update", n), nt(() => {
853
+ e == null || e.value.off("ready", s), e == null || e.value.off("update", n);
854
+ }), r || {};
855
+ }, Yt = () => {
856
+ const { updateContext: o } = A(S, {});
857
+ return o == null ? void 0 : o.value;
858
+ }, Wt = () => {
859
+ const { client: o } = A(S, {});
860
+ return o == null ? void 0 : o.value;
861
+ }, zt = {
862
+ install(o, { config: t, unleashClient: e, startClient: r }) {
863
+ const { context: n, update: s, start: i } = ht({
864
+ config: t,
865
+ unleashClient: e,
866
+ startClient: r
773
867
  });
774
- app.provide(ContextStateSymbol, context);
775
- app.provide(ContextUpdateSymbol, update);
776
- start();
868
+ o.provide(S, n), o.provide(lt, s), i();
777
869
  }
778
870
  };
779
- export { ContextStateSymbol, ContextUpdateSymbol, _sfc_main as FlagProvider, f as InMemoryStorageProvider, d as LocalStorageProvider, U as UnleashClient, _sfc_main as default, plugin, useFlag, useFlagsStatus, useUnleashClient, useUnleashContext, useVariant };
871
+ export {
872
+ S as ContextStateSymbol,
873
+ lt as ContextUpdateSymbol,
874
+ _t as FlagProvider,
875
+ St as InMemoryStorageProvider,
876
+ Rt as LocalStorageProvider,
877
+ Dt as UnleashClient,
878
+ _t as default,
879
+ zt as plugin,
880
+ Kt as useFlag,
881
+ Bt as useFlagsStatus,
882
+ Wt as useUnleashClient,
883
+ Yt as useUnleashContext,
884
+ qt as useVariant
885
+ };