@unleash/proxy-client-vue 0.1.6 → 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/README.md +6 -0
- package/dist/FlagProvider.vue.d.ts +19 -69
- package/dist/index.es.js +745 -639
- package/dist/index.umd.js +2 -2
- package/dist/useFlag.d.ts +1 -1
- package/dist/useFlagsStatus.d.ts +2 -2
- package/dist/useUnleashProvide.d.ts +19 -9
- package/dist/useVariant.d.ts +9 -0
- package/package.json +11 -12
- package/dist/env.d.ts +0 -8
package/dist/index.es.js
CHANGED
|
@@ -1,779 +1,885 @@
|
|
|
1
|
-
import {
|
|
2
|
-
var
|
|
3
|
-
return
|
|
4
|
-
|
|
5
|
-
} || function(
|
|
6
|
-
for (var
|
|
7
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
19
|
-
return new (
|
|
20
|
-
function
|
|
22
|
+
function g(o, t, e, r) {
|
|
23
|
+
return new (e || (e = Promise))((function(n, s) {
|
|
24
|
+
function i(c) {
|
|
21
25
|
try {
|
|
22
|
-
|
|
23
|
-
} catch (
|
|
24
|
-
|
|
26
|
+
l(r.next(c));
|
|
27
|
+
} catch (a) {
|
|
28
|
+
s(a);
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
|
-
function
|
|
31
|
+
function u(c) {
|
|
28
32
|
try {
|
|
29
|
-
|
|
30
|
-
} catch (
|
|
31
|
-
|
|
33
|
+
l(r.throw(c));
|
|
34
|
+
} catch (a) {
|
|
35
|
+
s(a);
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
|
-
function
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})).then(
|
|
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
|
-
|
|
41
|
-
});
|
|
44
|
+
l((r = r.apply(o, t || [])).next());
|
|
45
|
+
}));
|
|
42
46
|
}
|
|
43
|
-
function
|
|
44
|
-
var
|
|
45
|
-
if (1 &
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
}),
|
|
52
|
-
function
|
|
53
|
-
return function(
|
|
54
|
-
return function(
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
108
|
-
var
|
|
109
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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([
|
|
152
|
-
},
|
|
153
|
-
return
|
|
154
|
-
var
|
|
155
|
-
return
|
|
156
|
-
switch (
|
|
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
|
-
|
|
156
|
+
t = Tt(o), e.label = 1;
|
|
159
157
|
case 1:
|
|
160
|
-
return
|
|
161
|
-
var
|
|
162
|
-
return
|
|
163
|
-
switch (
|
|
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 (
|
|
166
|
-
|
|
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
|
|
170
|
-
return
|
|
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,
|
|
173
|
+
return [2, e.sent()];
|
|
177
174
|
case 3:
|
|
178
|
-
return
|
|
175
|
+
return e.sent(), [2, t];
|
|
179
176
|
case 4:
|
|
180
177
|
return [2];
|
|
181
178
|
}
|
|
182
|
-
var
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
var
|
|
189
|
-
|
|
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
|
|
192
|
-
var
|
|
193
|
-
if (this.disabled)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return
|
|
205
|
-
var
|
|
206
|
-
return
|
|
207
|
-
|
|
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 (
|
|
215
|
-
|
|
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
|
|
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
|
|
217
|
+
return u.sent(), this.onSent(r), [3, 4];
|
|
221
218
|
case 3:
|
|
222
|
-
return
|
|
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
|
-
},
|
|
229
|
-
|
|
230
|
-
},
|
|
231
|
-
|
|
232
|
-
|
|
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
|
|
252
|
-
return
|
|
253
|
-
return
|
|
254
|
-
return this.store.set(
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
},
|
|
258
|
-
return
|
|
259
|
-
return
|
|
260
|
-
return [2, this.store.get(
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
},
|
|
264
|
-
}(),
|
|
265
|
-
function
|
|
266
|
-
|
|
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
|
|
269
|
-
return
|
|
270
|
-
var
|
|
271
|
-
return
|
|
272
|
-
|
|
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(
|
|
275
|
-
} catch (
|
|
276
|
-
console.error(
|
|
279
|
+
window.localStorage.setItem(n, r);
|
|
280
|
+
} catch (i) {
|
|
281
|
+
console.error(i);
|
|
277
282
|
}
|
|
278
283
|
return [2];
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
},
|
|
284
|
+
}));
|
|
285
|
+
}));
|
|
286
|
+
}, o.prototype.get = function(t) {
|
|
282
287
|
try {
|
|
283
|
-
var
|
|
284
|
-
return
|
|
285
|
-
} catch (
|
|
286
|
-
console.error(
|
|
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
|
-
},
|
|
289
|
-
}()
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
|
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
|
|
316
|
-
|
|
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
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
},
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
-
},
|
|
338
|
-
function
|
|
339
|
-
var
|
|
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
|
|
342
|
-
return
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
-
}() :
|
|
353
|
-
if (
|
|
354
|
-
|
|
355
|
-
if (!
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
return (
|
|
366
|
-
}
|
|
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
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|
|
391
|
-
},
|
|
392
|
-
var
|
|
393
|
-
return
|
|
394
|
-
}),
|
|
395
|
-
if (
|
|
396
|
-
var
|
|
397
|
-
this.emit(
|
|
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
|
|
400
|
-
},
|
|
401
|
-
return
|
|
402
|
-
var
|
|
403
|
-
return
|
|
404
|
-
switch (
|
|
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
|
|
532
|
+
return r.sent(), [3, 4];
|
|
409
533
|
case 2:
|
|
410
|
-
return this.started ? [4, new Promise(function(
|
|
411
|
-
var
|
|
412
|
-
|
|
413
|
-
|
|
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
|
-
|
|
417
|
-
})] : [3, 4];
|
|
540
|
+
e.once(m.READY, s);
|
|
541
|
+
}))] : [3, 4];
|
|
418
542
|
case 3:
|
|
419
|
-
|
|
543
|
+
r.sent(), r.label = 4;
|
|
420
544
|
case 4:
|
|
421
545
|
return [2];
|
|
422
546
|
}
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
},
|
|
426
|
-
return
|
|
427
|
-
var
|
|
428
|
-
return
|
|
429
|
-
switch (
|
|
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 (
|
|
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
|
|
557
|
+
return n.sent(), [2];
|
|
434
558
|
}
|
|
435
|
-
});
|
|
436
|
-
});
|
|
437
|
-
},
|
|
438
|
-
return
|
|
439
|
-
},
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
},
|
|
452
|
-
this
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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
|
|
597
|
+
return e = s.sent(), this.context = p({ sessionId: e }, this.context), [4, this.storage.get(D)];
|
|
462
598
|
case 2:
|
|
463
|
-
return
|
|
599
|
+
return r = s.sent() || [], n = this, [4, this.getLastRefreshTimestamp()];
|
|
464
600
|
case 3:
|
|
465
|
-
return
|
|
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
|
|
603
|
+
return s.sent(), this.toggles = this.bootstrap, this.sdkState = "healthy", [4, this.storeLastRefreshTimestamp()];
|
|
468
604
|
case 5:
|
|
469
|
-
|
|
605
|
+
return s.sent(), this.setReady(), [3, 7];
|
|
470
606
|
case 6:
|
|
471
|
-
|
|
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
|
-
},
|
|
476
|
-
return
|
|
477
|
-
var
|
|
478
|
-
return
|
|
479
|
-
switch (
|
|
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 =
|
|
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
|
|
621
|
+
return n.sent(), this.metrics.start(), e = this.refreshInterval, [4, this.initialFetchToggles()];
|
|
484
622
|
case 2:
|
|
485
|
-
return
|
|
486
|
-
return
|
|
487
|
-
},
|
|
623
|
+
return n.sent(), e > 0 && (this.timerRef = setInterval((function() {
|
|
624
|
+
return r.fetchToggles();
|
|
625
|
+
}), e)), [2];
|
|
488
626
|
}
|
|
489
|
-
});
|
|
490
|
-
});
|
|
491
|
-
},
|
|
627
|
+
}));
|
|
628
|
+
}));
|
|
629
|
+
}, t.prototype.stop = function() {
|
|
492
630
|
this.timerRef && (clearInterval(this.timerRef), this.timerRef = void 0), this.metrics.stop();
|
|
493
|
-
},
|
|
631
|
+
}, t.prototype.isReady = function() {
|
|
494
632
|
return this.readyEventEmitted;
|
|
495
|
-
},
|
|
633
|
+
}, t.prototype.getError = function() {
|
|
496
634
|
return this.sdkState === "error" ? this.lastError : void 0;
|
|
497
|
-
},
|
|
635
|
+
}, t.prototype.sendMetrics = function() {
|
|
498
636
|
return this.metrics.sendMetrics();
|
|
499
|
-
},
|
|
500
|
-
return
|
|
501
|
-
var
|
|
502
|
-
return
|
|
503
|
-
switch (
|
|
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 (
|
|
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
|
-
|
|
647
|
+
r.sent(), r.label = 3;
|
|
510
648
|
case 3:
|
|
511
|
-
return [2,
|
|
649
|
+
return [2, e.toString(10)];
|
|
512
650
|
}
|
|
513
|
-
});
|
|
514
|
-
});
|
|
515
|
-
},
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
return
|
|
520
|
-
|
|
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 =
|
|
660
|
+
return this.toggles = e, this.emit(m.UPDATE), [4, this.storage.save(D, e)];
|
|
527
661
|
case 1:
|
|
528
|
-
return
|
|
662
|
+
return r.sent(), [2];
|
|
529
663
|
}
|
|
530
|
-
});
|
|
531
|
-
});
|
|
532
|
-
},
|
|
533
|
-
var
|
|
534
|
-
return !!(((
|
|
535
|
-
},
|
|
536
|
-
var
|
|
537
|
-
if (!this.isTogglesStorageTTLEnabled())
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
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(
|
|
680
|
+
return this.isTogglesStorageTTLEnabled() ? [4, this.storage.get(rt)] : [3, 3];
|
|
548
681
|
case 1:
|
|
549
|
-
return
|
|
682
|
+
return e = n.sent(), [4, V(this.context)];
|
|
550
683
|
case 2:
|
|
551
|
-
return
|
|
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
|
-
},
|
|
558
|
-
return
|
|
559
|
-
var
|
|
560
|
-
return
|
|
561
|
-
switch (
|
|
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(),
|
|
696
|
+
return this.isTogglesStorageTTLEnabled() ? (this.lastRefreshTimestamp = Date.now(), r = {}, [4, V(this.context)]) : [3, 3];
|
|
564
697
|
case 1:
|
|
565
|
-
return
|
|
698
|
+
return r.key = n.sent(), r.timestamp = this.lastRefreshTimestamp, e = r, [4, this.storage.save(rt, e)];
|
|
566
699
|
case 2:
|
|
567
|
-
|
|
700
|
+
n.sent(), n.label = 3;
|
|
568
701
|
case 3:
|
|
569
702
|
return [2];
|
|
570
703
|
}
|
|
571
|
-
});
|
|
572
|
-
});
|
|
573
|
-
},
|
|
574
|
-
if (!this.isUpToDate())
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
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
|
-
|
|
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
|
|
588
|
-
var
|
|
589
|
-
return Object.entries(
|
|
590
|
-
var
|
|
591
|
-
|
|
592
|
-
var
|
|
593
|
-
return
|
|
594
|
-
}) :
|
|
595
|
-
}),
|
|
596
|
-
}(this.url, this.context),
|
|
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
|
|
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
|
|
731
|
+
return l = f.sent(), [4, this.storeToggles(l.toggles)];
|
|
601
732
|
case 4:
|
|
602
|
-
return
|
|
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
|
-
|
|
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 (
|
|
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
|
-
},
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
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
|
|
626
|
-
const
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
}
|
|
633
|
-
|
|
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
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
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:
|
|
678
|
-
update,
|
|
679
|
-
start
|
|
800
|
+
context: gt(a),
|
|
801
|
+
update: f,
|
|
802
|
+
start: x
|
|
680
803
|
};
|
|
681
804
|
}
|
|
682
|
-
const
|
|
805
|
+
const _t = /* @__PURE__ */ yt({
|
|
683
806
|
__name: "FlagProvider",
|
|
684
807
|
props: {
|
|
685
|
-
config:
|
|
686
|
-
unleashClient:
|
|
687
|
-
startClient: { type: Boolean }
|
|
808
|
+
config: {},
|
|
809
|
+
unleashClient: {},
|
|
810
|
+
startClient: { type: Boolean, default: !0 }
|
|
688
811
|
},
|
|
689
|
-
setup(
|
|
690
|
-
const {
|
|
691
|
-
config,
|
|
692
|
-
unleashClient,
|
|
693
|
-
startClient
|
|
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 (
|
|
706
|
-
|
|
707
|
-
};
|
|
818
|
+
return X(S, t), X(lt, r), bt(() => {
|
|
819
|
+
e();
|
|
820
|
+
}), (n, s) => xt(n.$slots, "default");
|
|
708
821
|
}
|
|
709
|
-
})
|
|
710
|
-
const
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
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
|
|
720
|
-
|
|
828
|
+
function s() {
|
|
829
|
+
r.value = !!(t != null && t.value(o));
|
|
721
830
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
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
|
|
749
|
-
|
|
849
|
+
function s() {
|
|
850
|
+
r.value = t == null ? void 0 : t.value(o);
|
|
750
851
|
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
};
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
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
|
-
|
|
775
|
-
app.provide(ContextUpdateSymbol, update);
|
|
776
|
-
start();
|
|
868
|
+
o.provide(S, n), o.provide(lt, s), i();
|
|
777
869
|
}
|
|
778
870
|
};
|
|
779
|
-
export {
|
|
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
|
+
};
|