@unleash/proxy-client-vue 0.1.1 → 0.1.3
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/FlagProvider.vue.d.ts +6 -0
- package/dist/index.es.js +383 -245
- package/dist/index.umd.js +2 -2
- package/dist/useUnleashProvide.d.ts +6 -0
- package/package.json +6 -6
|
@@ -22,6 +22,7 @@ declare const _sfc_main: import("vue").DefineComponent<{
|
|
|
22
22
|
getAllToggles: () => import("unleash-proxy-client").IToggle[];
|
|
23
23
|
isEnabled: (toggleName: string) => boolean;
|
|
24
24
|
getVariant: (toggleName: string) => import("unleash-proxy-client").IVariant;
|
|
25
|
+
updateToggles: () => Promise<void>;
|
|
25
26
|
updateContext: (context: import("unleash-proxy-client").IMutableContext) => Promise<void>;
|
|
26
27
|
getContext: () => {
|
|
27
28
|
appName: string;
|
|
@@ -29,13 +30,18 @@ declare const _sfc_main: import("vue").DefineComponent<{
|
|
|
29
30
|
userId?: string | undefined;
|
|
30
31
|
sessionId?: string | undefined;
|
|
31
32
|
remoteAddress?: string | undefined;
|
|
33
|
+
currentTime?: string | undefined;
|
|
32
34
|
properties?: {
|
|
33
35
|
[key: string]: string;
|
|
34
36
|
} | undefined;
|
|
35
37
|
};
|
|
36
38
|
setContextField: (field: string, value: string) => void;
|
|
39
|
+
removeContextField: (field: string) => void;
|
|
37
40
|
start: () => Promise<void>;
|
|
38
41
|
stop: () => void;
|
|
42
|
+
isReady: () => boolean;
|
|
43
|
+
getError: () => any;
|
|
44
|
+
sendMetrics: () => Promise<void>;
|
|
39
45
|
on: (event: string, callback: Function, ctx?: any) => UnleashClient;
|
|
40
46
|
once: (event: string, callback: Function, ctx?: any) => UnleashClient;
|
|
41
47
|
emit: (event: string, ...args: any[]) => UnleashClient;
|
package/dist/index.es.js
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
1
|
import { toRefs, ref, reactive, defineComponent, provide, onMounted, renderSlot, inject, onUnmounted } from "vue";
|
|
2
|
-
var t = function(e2,
|
|
2
|
+
var t = function(e2, r2) {
|
|
3
3
|
return t = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t2, e3) {
|
|
4
4
|
t2.__proto__ = e3;
|
|
5
5
|
} || function(t2, e3) {
|
|
6
|
-
for (var
|
|
7
|
-
Object.prototype.hasOwnProperty.call(e3,
|
|
8
|
-
}, t(e2,
|
|
6
|
+
for (var r3 in e3)
|
|
7
|
+
Object.prototype.hasOwnProperty.call(e3, r3) && (t2[r3] = e3[r3]);
|
|
8
|
+
}, t(e2, r2);
|
|
9
9
|
};
|
|
10
10
|
var e = function() {
|
|
11
11
|
return e = Object.assign || function(t2) {
|
|
12
|
-
for (var e2,
|
|
13
|
-
for (var
|
|
14
|
-
Object.prototype.hasOwnProperty.call(e2,
|
|
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
15
|
return t2;
|
|
16
16
|
}, e.apply(this, arguments);
|
|
17
17
|
};
|
|
18
|
-
function
|
|
19
|
-
return new (
|
|
18
|
+
function r(t2, e2, r2, n2) {
|
|
19
|
+
return new (r2 || (r2 = Promise))(function(o2, i2) {
|
|
20
20
|
function s2(t3) {
|
|
21
21
|
try {
|
|
22
|
-
c2(
|
|
22
|
+
c2(n2.next(t3));
|
|
23
23
|
} catch (t4) {
|
|
24
|
-
|
|
24
|
+
i2(t4);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
function a2(t3) {
|
|
28
28
|
try {
|
|
29
|
-
c2(
|
|
29
|
+
c2(n2.throw(t3));
|
|
30
30
|
} catch (t4) {
|
|
31
|
-
|
|
31
|
+
i2(t4);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
function c2(t3) {
|
|
35
35
|
var e3;
|
|
36
|
-
t3.done ?
|
|
36
|
+
t3.done ? o2(t3.value) : (e3 = t3.value, e3 instanceof r2 ? e3 : new r2(function(t4) {
|
|
37
37
|
t4(e3);
|
|
38
38
|
})).then(s2, a2);
|
|
39
39
|
}
|
|
40
|
-
c2((
|
|
40
|
+
c2((n2 = n2.apply(t2, e2 || [])).next());
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
var
|
|
45
|
-
if (1 &
|
|
46
|
-
throw
|
|
47
|
-
return
|
|
48
|
-
}, trys: [], ops: [] };
|
|
49
|
-
return
|
|
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() {
|
|
50
50
|
return this;
|
|
51
|
-
}),
|
|
51
|
+
}), s2;
|
|
52
52
|
function a2(a3) {
|
|
53
53
|
return function(c2) {
|
|
54
54
|
return function(a4) {
|
|
55
|
-
if (
|
|
55
|
+
if (r2)
|
|
56
56
|
throw new TypeError("Generator is already executing.");
|
|
57
|
-
for (;
|
|
57
|
+
for (; s2 && (s2 = 0, a4[0] && (i2 = 0)), i2; )
|
|
58
58
|
try {
|
|
59
|
-
if (
|
|
60
|
-
return
|
|
61
|
-
switch (
|
|
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
62
|
case 0:
|
|
63
63
|
case 1:
|
|
64
|
-
|
|
64
|
+
o2 = a4;
|
|
65
65
|
break;
|
|
66
66
|
case 4:
|
|
67
|
-
return
|
|
67
|
+
return i2.label++, { value: a4[1], done: false };
|
|
68
68
|
case 5:
|
|
69
|
-
|
|
69
|
+
i2.label++, n2 = a4[1], a4 = [0];
|
|
70
70
|
continue;
|
|
71
71
|
case 7:
|
|
72
|
-
a4 =
|
|
72
|
+
a4 = i2.ops.pop(), i2.trys.pop();
|
|
73
73
|
continue;
|
|
74
74
|
default:
|
|
75
|
-
if (!(
|
|
76
|
-
|
|
75
|
+
if (!(o2 = i2.trys, (o2 = o2.length > 0 && o2[o2.length - 1]) || a4[0] !== 6 && a4[0] !== 2)) {
|
|
76
|
+
i2 = 0;
|
|
77
77
|
continue;
|
|
78
78
|
}
|
|
79
|
-
if (a4[0] === 3 && (!
|
|
80
|
-
|
|
79
|
+
if (a4[0] === 3 && (!o2 || a4[1] > o2[0] && a4[1] < o2[3])) {
|
|
80
|
+
i2.label = a4[1];
|
|
81
81
|
break;
|
|
82
82
|
}
|
|
83
|
-
if (a4[0] === 6 &&
|
|
84
|
-
|
|
83
|
+
if (a4[0] === 6 && i2.label < o2[1]) {
|
|
84
|
+
i2.label = o2[1], o2 = a4;
|
|
85
85
|
break;
|
|
86
86
|
}
|
|
87
|
-
if (
|
|
88
|
-
|
|
87
|
+
if (o2 && i2.label < o2[2]) {
|
|
88
|
+
i2.label = o2[2], i2.ops.push(a4);
|
|
89
89
|
break;
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
o2[2] && i2.ops.pop(), i2.trys.pop();
|
|
92
92
|
continue;
|
|
93
93
|
}
|
|
94
|
-
a4 = e2.call(t2,
|
|
94
|
+
a4 = e2.call(t2, i2);
|
|
95
95
|
} catch (t3) {
|
|
96
|
-
a4 = [6, t3],
|
|
96
|
+
a4 = [6, t3], n2 = 0;
|
|
97
97
|
} finally {
|
|
98
|
-
|
|
98
|
+
r2 = o2 = 0;
|
|
99
99
|
}
|
|
100
100
|
if (5 & a4[0])
|
|
101
101
|
throw a4[1];
|
|
@@ -105,70 +105,147 @@ function r(t2, e2) {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
typeof SuppressedError == "function" && SuppressedError;
|
|
108
|
-
var
|
|
109
|
-
function
|
|
108
|
+
var o = { exports: {} };
|
|
109
|
+
function i() {
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
var
|
|
113
|
-
return (
|
|
114
|
-
}, once: function(t2, e2,
|
|
115
|
-
var
|
|
116
|
-
function
|
|
117
|
-
|
|
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);
|
|
118
118
|
}
|
|
119
|
-
return
|
|
119
|
+
return o2._ = e2, this.on(t2, o2, r2);
|
|
120
120
|
}, emit: function(t2) {
|
|
121
|
-
for (var e2 = [].slice.call(arguments, 1),
|
|
122
|
-
n2
|
|
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
123
|
return this;
|
|
124
124
|
}, off: function(t2, e2) {
|
|
125
|
-
var
|
|
126
|
-
if (
|
|
127
|
-
for (var
|
|
128
|
-
|
|
129
|
-
return
|
|
130
|
-
} },
|
|
131
|
-
var s =
|
|
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;
|
|
132
|
+
let a;
|
|
133
|
+
const c = new Uint8Array(16);
|
|
134
|
+
function u() {
|
|
135
|
+
if (!a && (a = typeof crypto != "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !a))
|
|
136
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
137
|
+
return a(c);
|
|
138
|
+
}
|
|
139
|
+
const l = [];
|
|
140
|
+
for (let t2 = 0; t2 < 256; ++t2)
|
|
141
|
+
l.push((t2 + 256).toString(16).slice(1));
|
|
142
|
+
var h = { randomUUID: typeof crypto != "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
|
|
143
|
+
function p(t2, e2, r2) {
|
|
144
|
+
if (h.randomUUID && !e2 && !t2)
|
|
145
|
+
return h.randomUUID();
|
|
146
|
+
const n2 = (t2 = t2 || {}).random || (t2.rng || u)();
|
|
147
|
+
if (n2[6] = 15 & n2[6] | 64, n2[8] = 63 & n2[8] | 128, e2) {
|
|
148
|
+
r2 = r2 || 0;
|
|
149
|
+
for (let t3 = 0; t3 < 16; ++t3)
|
|
150
|
+
e2[r2 + t3] = n2[t3];
|
|
151
|
+
return e2;
|
|
152
|
+
}
|
|
153
|
+
return function(t3, e3 = 0) {
|
|
154
|
+
return l[t3[e3 + 0]] + l[t3[e3 + 1]] + l[t3[e3 + 2]] + l[t3[e3 + 3]] + "-" + l[t3[e3 + 4]] + l[t3[e3 + 5]] + "-" + l[t3[e3 + 6]] + l[t3[e3 + 7]] + "-" + l[t3[e3 + 8]] + l[t3[e3 + 9]] + "-" + l[t3[e3 + 10]] + l[t3[e3 + 11]] + l[t3[e3 + 12]] + l[t3[e3 + 13]] + l[t3[e3 + 14]] + l[t3[e3 + 15]];
|
|
155
|
+
}(n2);
|
|
156
|
+
}
|
|
157
|
+
var f = function(t2) {
|
|
132
158
|
var e2 = t2[1];
|
|
133
159
|
return e2 != null;
|
|
134
|
-
},
|
|
135
|
-
},
|
|
160
|
+
}, d = function(t2) {
|
|
161
|
+
var e2 = t2.properties, r2 = e2 === void 0 ? {} : e2, n2 = function(t3, e3) {
|
|
162
|
+
var r3 = {};
|
|
163
|
+
for (var n3 in t3)
|
|
164
|
+
Object.prototype.hasOwnProperty.call(t3, n3) && e3.indexOf(n3) < 0 && (r3[n3] = t3[n3]);
|
|
165
|
+
if (t3 != null && typeof Object.getOwnPropertySymbols == "function") {
|
|
166
|
+
var o3 = 0;
|
|
167
|
+
for (n3 = Object.getOwnPropertySymbols(t3); o3 < n3.length; o3++)
|
|
168
|
+
e3.indexOf(n3[o3]) < 0 && Object.prototype.propertyIsEnumerable.call(t3, n3[o3]) && (r3[n3[o3]] = t3[n3[o3]]);
|
|
169
|
+
}
|
|
170
|
+
return r3;
|
|
171
|
+
}(t2, ["properties"]), o2 = function(t3) {
|
|
172
|
+
return Object.entries(t3).sort(function(t4, e3) {
|
|
173
|
+
var r3 = t4[0], n3 = e3[0];
|
|
174
|
+
return r3.localeCompare(n3, void 0);
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
return JSON.stringify([o2(n2), o2(r2)]);
|
|
178
|
+
}, v = function(t2) {
|
|
179
|
+
return r(void 0, void 0, void 0, function() {
|
|
180
|
+
var e2;
|
|
181
|
+
return n(this, function(o2) {
|
|
182
|
+
switch (o2.label) {
|
|
183
|
+
case 0:
|
|
184
|
+
e2 = d(t2), o2.label = 1;
|
|
185
|
+
case 1:
|
|
186
|
+
return o2.trys.push([1, 3, , 4]), [4, (i2 = e2, r(void 0, void 0, void 0, function() {
|
|
187
|
+
var t3, e3, r2, o3, s2;
|
|
188
|
+
return n(this, function(n2) {
|
|
189
|
+
switch (n2.label) {
|
|
190
|
+
case 0:
|
|
191
|
+
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")
|
|
192
|
+
throw new Error("Hashing function not available");
|
|
193
|
+
return e3 = new TextEncoder().encode(i2), [4, t3.digest("SHA-256", e3)];
|
|
194
|
+
case 1:
|
|
195
|
+
return r2 = n2.sent(), [2, Array.from(new Uint8Array(r2)).map(function(t4) {
|
|
196
|
+
return t4.toString(16).padStart(2, "0");
|
|
197
|
+
}).join("")];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}))];
|
|
201
|
+
case 2:
|
|
202
|
+
return [2, o2.sent()];
|
|
203
|
+
case 3:
|
|
204
|
+
return o2.sent(), [2, e2];
|
|
205
|
+
case 4:
|
|
206
|
+
return [2];
|
|
207
|
+
}
|
|
208
|
+
var i2;
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}, m = "unleash-js@3.7.1", g = function() {
|
|
212
|
+
}, y = function() {
|
|
136
213
|
function t2(t3) {
|
|
137
|
-
var e2 = t3.onError,
|
|
138
|
-
this.onError = e2, this.onSent =
|
|
214
|
+
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, h2 = t3.customHeaders, p2 = h2 === void 0 ? {} : h2, f2 = t3.metricsIntervalInitial, d2 = t3.connectionId;
|
|
215
|
+
this.onError = e2, this.onSent = r2 || g, this.disabled = s2, this.metricsInterval = 1e3 * o2, this.metricsIntervalInitial = 1e3 * f2, 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 = p2, this.connectionId = d2;
|
|
139
216
|
}
|
|
140
217
|
return t2.prototype.start = function() {
|
|
141
218
|
var t3 = this;
|
|
142
219
|
if (this.disabled)
|
|
143
220
|
return false;
|
|
144
|
-
typeof this.metricsInterval == "number" && this.metricsInterval > 0 && setTimeout(function() {
|
|
221
|
+
typeof this.metricsInterval == "number" && this.metricsInterval > 0 && (this.metricsIntervalInitial > 0 ? setTimeout(function() {
|
|
145
222
|
t3.startTimer(), t3.sendMetrics();
|
|
146
|
-
},
|
|
223
|
+
}, this.metricsIntervalInitial) : this.startTimer());
|
|
147
224
|
}, t2.prototype.stop = function() {
|
|
148
225
|
this.timer && (clearTimeout(this.timer), delete this.timer);
|
|
149
226
|
}, t2.prototype.createEmptyBucket = function() {
|
|
150
227
|
return { start: new Date(), stop: null, toggles: {} };
|
|
151
228
|
}, t2.prototype.getHeaders = function() {
|
|
152
|
-
var t3, e2 = ((t3 = {})[this.headerName] = this.clientKey, t3.Accept = "application/json", t3["Content-Type"] = "application/json", t3);
|
|
153
|
-
return Object.entries(this.customHeaders).filter(
|
|
154
|
-
var
|
|
155
|
-
return e2[
|
|
229
|
+
var t3, e2 = ((t3 = {})[this.headerName] = this.clientKey, t3.Accept = "application/json", t3["Content-Type"] = "application/json", t3["x-unleash-sdk"] = m, t3["x-unleash-connection-id"] = this.connectionId, t3["x-unleash-appname"] = this.appName, t3);
|
|
230
|
+
return Object.entries(this.customHeaders).filter(f).forEach(function(t4) {
|
|
231
|
+
var r2 = t4[0], n2 = t4[1];
|
|
232
|
+
return e2[r2] = n2;
|
|
156
233
|
}), e2;
|
|
157
234
|
}, t2.prototype.sendMetrics = function() {
|
|
158
|
-
return
|
|
159
|
-
var t3, e2,
|
|
160
|
-
return
|
|
161
|
-
switch (
|
|
235
|
+
return r(this, void 0, void 0, function() {
|
|
236
|
+
var t3, e2, r2;
|
|
237
|
+
return n(this, function(n2) {
|
|
238
|
+
switch (n2.label) {
|
|
162
239
|
case 0:
|
|
163
240
|
if (t3 = "".concat(this.url, "/client/metrics"), e2 = this.getPayload(), this.bucketIsEmpty(e2))
|
|
164
241
|
return [2];
|
|
165
|
-
|
|
242
|
+
n2.label = 1;
|
|
166
243
|
case 1:
|
|
167
|
-
return
|
|
244
|
+
return n2.trys.push([1, 3, , 4]), [4, this.fetch(t3, { cache: "no-cache", method: "POST", headers: this.getHeaders(), body: JSON.stringify(e2) })];
|
|
168
245
|
case 2:
|
|
169
|
-
return
|
|
246
|
+
return n2.sent(), this.onSent(e2), [3, 4];
|
|
170
247
|
case 3:
|
|
171
|
-
return
|
|
248
|
+
return r2 = n2.sent(), console.error("Unleash: unable to send feature metrics", r2), this.onError(r2), [3, 4];
|
|
172
249
|
case 4:
|
|
173
250
|
return [2];
|
|
174
251
|
}
|
|
@@ -193,34 +270,34 @@ var s = i.exports.TinyEmitter = o, a = function(t2) {
|
|
|
193
270
|
var t3 = e(e({}, this.bucket), { stop: new Date() });
|
|
194
271
|
return this.bucket = this.createEmptyBucket(), { bucket: t3, appName: this.appName, instanceId: "browser" };
|
|
195
272
|
}, t2;
|
|
196
|
-
}(),
|
|
273
|
+
}(), b = function() {
|
|
197
274
|
function t2() {
|
|
198
275
|
this.store = /* @__PURE__ */ new Map();
|
|
199
276
|
}
|
|
200
277
|
return t2.prototype.save = function(t3, e2) {
|
|
201
|
-
return
|
|
202
|
-
return
|
|
278
|
+
return r(this, void 0, void 0, function() {
|
|
279
|
+
return n(this, function(r2) {
|
|
203
280
|
return this.store.set(t3, e2), [2];
|
|
204
281
|
});
|
|
205
282
|
});
|
|
206
283
|
}, t2.prototype.get = function(t3) {
|
|
207
|
-
return
|
|
208
|
-
return
|
|
284
|
+
return r(this, void 0, void 0, function() {
|
|
285
|
+
return n(this, function(e2) {
|
|
209
286
|
return [2, this.store.get(t3)];
|
|
210
287
|
});
|
|
211
288
|
});
|
|
212
289
|
}, t2;
|
|
213
|
-
}(),
|
|
214
|
-
function t2() {
|
|
215
|
-
|
|
290
|
+
}(), T = function() {
|
|
291
|
+
function t2(t3) {
|
|
292
|
+
t3 === void 0 && (t3 = "unleash:repository"), this.prefix = t3;
|
|
216
293
|
}
|
|
217
294
|
return t2.prototype.save = function(t3, e2) {
|
|
218
|
-
return
|
|
219
|
-
var
|
|
220
|
-
return
|
|
221
|
-
|
|
295
|
+
return r(this, void 0, void 0, function() {
|
|
296
|
+
var r2, o2;
|
|
297
|
+
return n(this, function(n2) {
|
|
298
|
+
r2 = JSON.stringify(e2), o2 = "".concat(this.prefix, ":").concat(t3);
|
|
222
299
|
try {
|
|
223
|
-
window.localStorage.setItem(
|
|
300
|
+
window.localStorage.setItem(o2, r2);
|
|
224
301
|
} catch (t4) {
|
|
225
302
|
console.error(t4);
|
|
226
303
|
}
|
|
@@ -229,50 +306,26 @@ var s = i.exports.TinyEmitter = o, a = function(t2) {
|
|
|
229
306
|
});
|
|
230
307
|
}, t2.prototype.get = function(t3) {
|
|
231
308
|
try {
|
|
232
|
-
var e2 = "".concat(this.prefix, ":").concat(t3),
|
|
233
|
-
return
|
|
309
|
+
var e2 = "".concat(this.prefix, ":").concat(t3), r2 = window.localStorage.getItem(e2);
|
|
310
|
+
return r2 ? JSON.parse(r2) : void 0;
|
|
234
311
|
} catch (t4) {
|
|
235
312
|
console.error(t4);
|
|
236
313
|
}
|
|
237
314
|
}, t2;
|
|
238
|
-
}()
|
|
239
|
-
let p;
|
|
240
|
-
const f = new Uint8Array(16);
|
|
241
|
-
function d() {
|
|
242
|
-
if (!p && (p = typeof crypto != "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !p))
|
|
243
|
-
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
244
|
-
return p(f);
|
|
245
|
-
}
|
|
246
|
-
const v = [];
|
|
247
|
-
for (let t2 = 0; t2 < 256; ++t2)
|
|
248
|
-
v.push((t2 + 256).toString(16).slice(1));
|
|
249
|
-
var m = { randomUUID: typeof crypto != "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
|
|
250
|
-
function y(t2, e2, n2) {
|
|
251
|
-
if (m.randomUUID && !e2 && !t2)
|
|
252
|
-
return m.randomUUID();
|
|
253
|
-
const r2 = (t2 = t2 || {}).random || (t2.rng || d)();
|
|
254
|
-
if (r2[6] = 15 & r2[6] | 64, r2[8] = 63 & r2[8] | 128, e2) {
|
|
255
|
-
n2 = n2 || 0;
|
|
256
|
-
for (let t3 = 0; t3 < 16; ++t3)
|
|
257
|
-
e2[n2 + t3] = r2[t3];
|
|
258
|
-
return e2;
|
|
259
|
-
}
|
|
260
|
-
return function(t3, e3 = 0) {
|
|
261
|
-
return v[t3[e3 + 0]] + v[t3[e3 + 1]] + v[t3[e3 + 2]] + v[t3[e3 + 3]] + "-" + v[t3[e3 + 4]] + v[t3[e3 + 5]] + "-" + v[t3[e3 + 6]] + v[t3[e3 + 7]] + "-" + v[t3[e3 + 8]] + v[t3[e3 + 9]] + "-" + v[t3[e3 + 10]] + v[t3[e3 + 11]] + v[t3[e3 + 12]] + v[t3[e3 + 13]] + v[t3[e3 + 14]] + v[t3[e3 + 15]];
|
|
262
|
-
}(r2);
|
|
263
|
-
}
|
|
264
|
-
var g = function() {
|
|
315
|
+
}(), w = function() {
|
|
265
316
|
function t2() {
|
|
266
317
|
}
|
|
267
318
|
return t2.prototype.generateEventId = function() {
|
|
268
|
-
return
|
|
269
|
-
}, t2.prototype.createImpressionEvent = function(t3, n2,
|
|
270
|
-
var a2 = this.createBaseEvent(t3, n2,
|
|
319
|
+
return p();
|
|
320
|
+
}, t2.prototype.createImpressionEvent = function(t3, r2, n2, o2, i2, s2) {
|
|
321
|
+
var a2 = this.createBaseEvent(t3, r2, n2, o2, i2);
|
|
271
322
|
return s2 ? e(e({}, a2), { variant: s2 }) : a2;
|
|
272
|
-
}, t2.prototype.createBaseEvent = function(t3, e2,
|
|
273
|
-
return { eventType:
|
|
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 };
|
|
274
325
|
}, t2;
|
|
275
|
-
}(),
|
|
326
|
+
}(), E = ["userId", "sessionId", "remoteAddress", "currentTime"], S = function(t2) {
|
|
327
|
+
return E.includes(t2);
|
|
328
|
+
}, I = { INIT: "initialized", ERROR: "error", READY: "ready", UPDATE: "update", IMPRESSION: "impression", SENT: "sent", RECOVERED: "recovered" }, x = "isEnabled", R = "getVariant", O = { name: "disabled", enabled: false, feature_enabled: false }, k = "repo", N = "repoLastUpdateTimestamp", A = function() {
|
|
276
329
|
try {
|
|
277
330
|
if (typeof window != "undefined" && "fetch" in window)
|
|
278
331
|
return fetch.bind(window);
|
|
@@ -281,198 +334,283 @@ var g = function() {
|
|
|
281
334
|
} catch (t2) {
|
|
282
335
|
console.error('Unleash failed to resolve "fetch"', t2);
|
|
283
336
|
}
|
|
284
|
-
},
|
|
285
|
-
function
|
|
286
|
-
var
|
|
287
|
-
|
|
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, f2 = t2.metricsIntervalInitial, d2 = f2 === void 0 ? 2 : f2, v2 = t2.disableMetrics, m2 = v2 !== void 0 && v2, g2 = t2.appName, E2 = t2.environment, S2 = E2 === void 0 ? "default" : E2, x2 = t2.context, R2 = t2.fetch, O2 = R2 === void 0 ? A() : R2, k2 = t2.createAbortController, N2 = k2 === void 0 ? function() {
|
|
340
|
+
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);
|
|
351
|
+
}
|
|
352
|
+
}() : k2, U2 = t2.bootstrap, D = t2.bootstrapOverride, j = D === void 0 || D, C = t2.headerName, P = C === void 0 ? "Authorization" : C, L = t2.customHeaders, H = L === void 0 ? {} : L, M = t2.impressionDataAll, _ = M !== void 0 && M, F = t2.usePOSTrequests, K = F !== void 0 && F, V = t2.experimental, q = o2.call(this) || this;
|
|
353
|
+
if (q.toggles = [], q.etag = "", q.readyEventEmitted = false, q.fetchedFromServer = false, q.usePOSTrequests = false, q.started = false, !n2)
|
|
288
354
|
throw new Error("url is required");
|
|
289
|
-
if (!
|
|
355
|
+
if (!i3)
|
|
290
356
|
throw new Error("clientKey is required");
|
|
291
|
-
if (!
|
|
357
|
+
if (!g2)
|
|
292
358
|
throw new Error("appName is required.");
|
|
293
|
-
return
|
|
294
|
-
|
|
295
|
-
console.error(e2),
|
|
359
|
+
return q.eventsHandler = new w(), q.impressionDataAll = _, q.toggles = U2 && U2.length > 0 ? U2 : [], q.url = n2 instanceof URL ? n2 : new URL(n2), q.clientKey = i3, q.headerName = P, q.customHeaders = H, q.storage = r2 || (typeof window != "undefined" ? new T() : new b()), q.refreshInterval = a2 ? 0 : 1e3 * u2, q.context = e({ appName: g2, environment: S2 }, x2), q.usePOSTrequests = K, q.sdkState = "initializing", q.experimental = e({}, V), (V == null ? void 0 : V.togglesStorageTTL) && (V == null ? void 0 : V.togglesStorageTTL) > 0 && (q.experimental.togglesStorageTTL = 1e3 * V.togglesStorageTTL), q.lastRefreshTimestamp = 0, q.ready = new Promise(function(t3) {
|
|
360
|
+
q.init().then(t3).catch(function(e2) {
|
|
361
|
+
console.error(e2), q.sdkState = "error", q.emit(I.ERROR, e2), q.lastError = e2, t3();
|
|
296
362
|
});
|
|
297
|
-
}),
|
|
363
|
+
}), O2 || console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'), N2 || console.error('Unleash: You must either provide your own "AbortController" implementation or run in an environment where "AbortController" is available.'), q.fetch = O2, q.createAbortController = N2, q.bootstrap = U2 && U2.length > 0 ? U2 : void 0, q.bootstrapOverride = j, q.connectionId = p(), q.metrics = new y({ onError: q.emit.bind(q, I.ERROR), onSent: q.emit.bind(q, I.SENT), appName: g2, metricsInterval: h2, disableMetrics: m2, url: q.url, clientKey: i3, fetch: O2, headerName: P, customHeaders: H, metricsIntervalInitial: d2, connectionId: q.connectionId }), q;
|
|
298
364
|
}
|
|
299
|
-
return function(e2,
|
|
300
|
-
if (typeof
|
|
301
|
-
throw new TypeError("Class extends value " + String(
|
|
302
|
-
function
|
|
365
|
+
return function(e2, r2) {
|
|
366
|
+
if (typeof r2 != "function" && r2 !== null)
|
|
367
|
+
throw new TypeError("Class extends value " + String(r2) + " is not a constructor or null");
|
|
368
|
+
function n2() {
|
|
303
369
|
this.constructor = e2;
|
|
304
370
|
}
|
|
305
|
-
t(e2,
|
|
306
|
-
}(
|
|
307
|
-
return function(t2, e2,
|
|
308
|
-
if (
|
|
309
|
-
for (var
|
|
310
|
-
!
|
|
311
|
-
return t2.concat(
|
|
371
|
+
t(e2, r2), e2.prototype = r2 === null ? Object.create(r2) : (n2.prototype = r2.prototype, new n2());
|
|
372
|
+
}(i2, o2), i2.prototype.getAllToggles = function() {
|
|
373
|
+
return function(t2, e2, r2) {
|
|
374
|
+
if (r2 || arguments.length === 2)
|
|
375
|
+
for (var n2, o3 = 0, i3 = e2.length; o3 < i3; o3++)
|
|
376
|
+
!n2 && o3 in e2 || (n2 || (n2 = Array.prototype.slice.call(e2, 0, o3)), n2[o3] = e2[o3]);
|
|
377
|
+
return t2.concat(n2 || Array.prototype.slice.call(e2));
|
|
312
378
|
}([], this.toggles, true);
|
|
313
|
-
},
|
|
314
|
-
var e2,
|
|
379
|
+
}, i2.prototype.isEnabled = function(t2) {
|
|
380
|
+
var e2, r2 = this.toggles.find(function(e3) {
|
|
315
381
|
return e3.name === t2;
|
|
316
|
-
}),
|
|
317
|
-
if (this.metrics.count(t2,
|
|
318
|
-
var
|
|
319
|
-
this.emit(
|
|
382
|
+
}), n2 = !!r2 && r2.enabled;
|
|
383
|
+
if (this.metrics.count(t2, n2), (r2 == null ? void 0 : r2.impressionData) || this.impressionDataAll) {
|
|
384
|
+
var o3 = this.eventsHandler.createImpressionEvent(this.context, n2, t2, x, (e2 = r2 == null ? void 0 : r2.impressionData) !== null && e2 !== void 0 ? e2 : void 0);
|
|
385
|
+
this.emit(I.IMPRESSION, o3);
|
|
320
386
|
}
|
|
321
|
-
return
|
|
322
|
-
},
|
|
323
|
-
var
|
|
387
|
+
return n2;
|
|
388
|
+
}, i2.prototype.getVariant = function(t2) {
|
|
389
|
+
var r2, n2 = this.toggles.find(function(e2) {
|
|
324
390
|
return e2.name === t2;
|
|
325
|
-
}),
|
|
326
|
-
if (
|
|
327
|
-
var s2 = this.eventsHandler.createImpressionEvent(this.context,
|
|
328
|
-
this.emit(
|
|
391
|
+
}), o3 = (n2 == null ? void 0 : n2.enabled) || false, i3 = n2 ? n2.variant : O;
|
|
392
|
+
if (i3.name && this.metrics.countVariant(t2, i3.name), this.metrics.count(t2, o3), (n2 == null ? void 0 : n2.impressionData) || this.impressionDataAll) {
|
|
393
|
+
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);
|
|
394
|
+
this.emit(I.IMPRESSION, s2);
|
|
329
395
|
}
|
|
330
|
-
return e(e({},
|
|
331
|
-
},
|
|
332
|
-
return
|
|
333
|
-
var
|
|
334
|
-
return
|
|
335
|
-
switch (
|
|
396
|
+
return e(e({}, i3), { feature_enabled: o3 });
|
|
397
|
+
}, i2.prototype.updateToggles = function() {
|
|
398
|
+
return r(this, void 0, void 0, function() {
|
|
399
|
+
var t2 = this;
|
|
400
|
+
return n(this, function(e2) {
|
|
401
|
+
switch (e2.label) {
|
|
336
402
|
case 0:
|
|
337
|
-
return
|
|
403
|
+
return this.timerRef || this.fetchedFromServer ? [4, this.fetchToggles()] : [3, 2];
|
|
338
404
|
case 1:
|
|
339
|
-
return
|
|
405
|
+
return e2.sent(), [3, 4];
|
|
340
406
|
case 2:
|
|
341
|
-
return this.started ? [4, new Promise(function(
|
|
342
|
-
var
|
|
343
|
-
|
|
344
|
-
|
|
407
|
+
return this.started ? [4, new Promise(function(e3) {
|
|
408
|
+
var r2 = function() {
|
|
409
|
+
t2.fetchToggles().then(function() {
|
|
410
|
+
t2.off(I.READY, r2), e3();
|
|
345
411
|
});
|
|
346
412
|
};
|
|
347
|
-
|
|
413
|
+
t2.once(I.READY, r2);
|
|
348
414
|
})] : [3, 4];
|
|
349
415
|
case 3:
|
|
350
|
-
|
|
416
|
+
e2.sent(), e2.label = 4;
|
|
351
417
|
case 4:
|
|
352
418
|
return [2];
|
|
353
419
|
}
|
|
354
420
|
});
|
|
355
421
|
});
|
|
356
|
-
},
|
|
422
|
+
}, i2.prototype.updateContext = function(t2) {
|
|
423
|
+
return r(this, void 0, void 0, function() {
|
|
424
|
+
var r2;
|
|
425
|
+
return n(this, function(n2) {
|
|
426
|
+
switch (n2.label) {
|
|
427
|
+
case 0:
|
|
428
|
+
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()];
|
|
429
|
+
case 1:
|
|
430
|
+
return n2.sent(), [2];
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
}, i2.prototype.getContext = function() {
|
|
357
435
|
return e({}, this.context);
|
|
358
|
-
},
|
|
359
|
-
var
|
|
360
|
-
if (
|
|
361
|
-
this.context = e(e({}, this.context), ((
|
|
436
|
+
}, i2.prototype.setContextField = function(t2, r2) {
|
|
437
|
+
var n2, o3;
|
|
438
|
+
if (S(t2))
|
|
439
|
+
this.context = e(e({}, this.context), ((n2 = {})[t2] = r2, n2));
|
|
362
440
|
else {
|
|
363
|
-
var
|
|
364
|
-
this.context = e(e({}, this.context), { properties:
|
|
441
|
+
var i3 = e(e({}, this.context.properties), ((o3 = {})[t2] = r2, o3));
|
|
442
|
+
this.context = e(e({}, this.context), { properties: i3 });
|
|
365
443
|
}
|
|
366
|
-
this.
|
|
367
|
-
},
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
444
|
+
this.updateToggles();
|
|
445
|
+
}, i2.prototype.removeContextField = function(t2) {
|
|
446
|
+
var r2;
|
|
447
|
+
S(t2) ? this.context = e(e({}, this.context), ((r2 = {})[t2] = void 0, r2)) : typeof this.context.properties == "object" && delete this.context.properties[t2], this.updateToggles();
|
|
448
|
+
}, i2.prototype.setReady = function() {
|
|
449
|
+
this.readyEventEmitted = true, this.emit(I.READY);
|
|
450
|
+
}, i2.prototype.init = function() {
|
|
451
|
+
return r(this, void 0, void 0, function() {
|
|
452
|
+
var t2, r2, o3;
|
|
453
|
+
return n(this, function(n2) {
|
|
454
|
+
switch (n2.label) {
|
|
372
455
|
case 0:
|
|
373
456
|
return [4, this.resolveSessionId()];
|
|
374
457
|
case 1:
|
|
375
|
-
return t2 =
|
|
458
|
+
return t2 = n2.sent(), this.context = e({ sessionId: t2 }, this.context), r2 = this, [4, this.storage.get(k)];
|
|
376
459
|
case 2:
|
|
377
|
-
return
|
|
460
|
+
return r2.toggles = n2.sent() || [], o3 = this, [4, this.getLastRefreshTimestamp()];
|
|
378
461
|
case 3:
|
|
379
|
-
|
|
462
|
+
return o3.lastRefreshTimestamp = n2.sent(), !this.bootstrap || !this.bootstrapOverride && this.toggles.length !== 0 ? [3, 6] : [4, this.storage.save(k, this.bootstrap)];
|
|
380
463
|
case 4:
|
|
381
|
-
return
|
|
464
|
+
return n2.sent(), this.toggles = this.bootstrap, this.sdkState = "healthy", [4, this.storeLastRefreshTimestamp()];
|
|
465
|
+
case 5:
|
|
466
|
+
n2.sent(), this.setReady(), n2.label = 6;
|
|
467
|
+
case 6:
|
|
468
|
+
return this.sdkState = "healthy", this.emit(I.INIT), [2];
|
|
382
469
|
}
|
|
383
470
|
});
|
|
384
471
|
});
|
|
385
|
-
},
|
|
386
|
-
return
|
|
472
|
+
}, i2.prototype.start = function() {
|
|
473
|
+
return r(this, void 0, void 0, function() {
|
|
387
474
|
var t2, e2 = this;
|
|
388
|
-
return
|
|
389
|
-
switch (
|
|
475
|
+
return n(this, function(r2) {
|
|
476
|
+
switch (r2.label) {
|
|
390
477
|
case 0:
|
|
391
478
|
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];
|
|
392
479
|
case 1:
|
|
393
|
-
return
|
|
480
|
+
return r2.sent(), this.metrics.start(), t2 = this.refreshInterval, [4, this.initialFetchToggles()];
|
|
394
481
|
case 2:
|
|
395
|
-
return
|
|
482
|
+
return r2.sent(), t2 > 0 && (this.timerRef = setInterval(function() {
|
|
396
483
|
return e2.fetchToggles();
|
|
397
484
|
}, t2)), [2];
|
|
398
485
|
}
|
|
399
486
|
});
|
|
400
487
|
});
|
|
401
|
-
},
|
|
488
|
+
}, i2.prototype.stop = function() {
|
|
402
489
|
this.timerRef && (clearInterval(this.timerRef), this.timerRef = void 0), this.metrics.stop();
|
|
403
|
-
},
|
|
404
|
-
return
|
|
490
|
+
}, i2.prototype.isReady = function() {
|
|
491
|
+
return this.readyEventEmitted;
|
|
492
|
+
}, i2.prototype.getError = function() {
|
|
493
|
+
return this.sdkState === "error" ? this.lastError : void 0;
|
|
494
|
+
}, i2.prototype.sendMetrics = function() {
|
|
495
|
+
return this.metrics.sendMetrics();
|
|
496
|
+
}, i2.prototype.resolveSessionId = function() {
|
|
497
|
+
return r(this, void 0, void 0, function() {
|
|
405
498
|
var t2;
|
|
406
|
-
return
|
|
499
|
+
return n(this, function(e2) {
|
|
407
500
|
switch (e2.label) {
|
|
408
501
|
case 0:
|
|
409
|
-
return this.context.sessionId ? [2, this.context.sessionId] : [
|
|
502
|
+
return this.context.sessionId ? [2, this.context.sessionId] : [4, this.storage.get("sessionId")];
|
|
410
503
|
case 1:
|
|
411
|
-
return [4, this.storage.
|
|
504
|
+
return (t2 = e2.sent()) ? [3, 3] : (t2 = Math.floor(1e9 * Math.random()), [4, this.storage.save("sessionId", t2.toString(10))]);
|
|
412
505
|
case 2:
|
|
413
|
-
|
|
506
|
+
e2.sent(), e2.label = 3;
|
|
414
507
|
case 3:
|
|
415
|
-
|
|
416
|
-
case 4:
|
|
417
|
-
return [2, t2];
|
|
508
|
+
return [2, t2.toString(10)];
|
|
418
509
|
}
|
|
419
510
|
});
|
|
420
511
|
});
|
|
421
|
-
},
|
|
422
|
-
var t2, e2 = ((t2 = {})[this.headerName] = this.clientKey, t2.Accept = "application/json", t2["
|
|
423
|
-
return Object.entries(this.customHeaders).filter(
|
|
424
|
-
var
|
|
425
|
-
return
|
|
426
|
-
}),
|
|
427
|
-
},
|
|
428
|
-
return
|
|
429
|
-
return
|
|
512
|
+
}, i2.prototype.getHeaders = function() {
|
|
513
|
+
var t2, e2 = this.usePOSTrequests, r2 = ((t2 = {})[this.headerName] = this.clientKey, t2.Accept = "application/json", t2["x-unleash-sdk"] = m, t2["x-unleash-connection-id"] = this.connectionId, t2["x-unleash-appname"] = this.context.appName, t2);
|
|
514
|
+
return e2 && (r2["Content-Type"] = "application/json"), this.etag && (r2["If-None-Match"] = this.etag), Object.entries(this.customHeaders).filter(f).forEach(function(t3) {
|
|
515
|
+
var e3 = t3[0], n2 = t3[1];
|
|
516
|
+
return r2[e3] = n2;
|
|
517
|
+
}), r2;
|
|
518
|
+
}, i2.prototype.storeToggles = function(t2) {
|
|
519
|
+
return r(this, void 0, void 0, function() {
|
|
520
|
+
return n(this, function(e2) {
|
|
430
521
|
switch (e2.label) {
|
|
431
522
|
case 0:
|
|
432
|
-
return this.toggles = t2, this.emit(
|
|
523
|
+
return this.toggles = t2, this.emit(I.UPDATE), [4, this.storage.save(k, t2)];
|
|
433
524
|
case 1:
|
|
434
525
|
return e2.sent(), [2];
|
|
435
526
|
}
|
|
436
527
|
});
|
|
437
528
|
});
|
|
438
|
-
},
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
529
|
+
}, i2.prototype.isTogglesStorageTTLEnabled = function() {
|
|
530
|
+
var t2;
|
|
531
|
+
return !!(((t2 = this.experimental) === null || t2 === void 0 ? void 0 : t2.togglesStorageTTL) && this.experimental.togglesStorageTTL > 0);
|
|
532
|
+
}, i2.prototype.isUpToDate = function() {
|
|
533
|
+
var t2;
|
|
534
|
+
if (!this.isTogglesStorageTTLEnabled())
|
|
535
|
+
return false;
|
|
536
|
+
var e2 = Date.now(), r2 = ((t2 = this.experimental) === null || t2 === void 0 ? void 0 : t2.togglesStorageTTL) || 0;
|
|
537
|
+
return this.lastRefreshTimestamp > 0 && this.lastRefreshTimestamp <= e2 && e2 - this.lastRefreshTimestamp <= r2;
|
|
538
|
+
}, i2.prototype.getLastRefreshTimestamp = function() {
|
|
539
|
+
return r(this, void 0, void 0, function() {
|
|
540
|
+
var t2, e2;
|
|
541
|
+
return n(this, function(r2) {
|
|
542
|
+
switch (r2.label) {
|
|
543
|
+
case 0:
|
|
544
|
+
return this.isTogglesStorageTTLEnabled() ? [4, this.storage.get(N)] : [3, 3];
|
|
545
|
+
case 1:
|
|
546
|
+
return t2 = r2.sent(), [4, v(this.context)];
|
|
547
|
+
case 2:
|
|
548
|
+
return e2 = r2.sent(), [2, (t2 == null ? void 0 : t2.key) === e2 ? t2.timestamp : 0];
|
|
549
|
+
case 3:
|
|
550
|
+
return [2, 0];
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
}, i2.prototype.storeLastRefreshTimestamp = function() {
|
|
555
|
+
return r(this, void 0, void 0, function() {
|
|
556
|
+
var t2, e2;
|
|
557
|
+
return n(this, function(r2) {
|
|
442
558
|
switch (r2.label) {
|
|
559
|
+
case 0:
|
|
560
|
+
return this.isTogglesStorageTTLEnabled() ? (this.lastRefreshTimestamp = Date.now(), e2 = {}, [4, v(this.context)]) : [3, 3];
|
|
561
|
+
case 1:
|
|
562
|
+
return e2.key = r2.sent(), e2.timestamp = this.lastRefreshTimestamp, t2 = e2, [4, this.storage.save(N, t2)];
|
|
563
|
+
case 2:
|
|
564
|
+
r2.sent(), r2.label = 3;
|
|
565
|
+
case 3:
|
|
566
|
+
return [2];
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
}, i2.prototype.initialFetchToggles = function() {
|
|
571
|
+
if (!this.isUpToDate())
|
|
572
|
+
return this.fetchToggles();
|
|
573
|
+
this.fetchedFromServer || (this.fetchedFromServer = true, this.setReady());
|
|
574
|
+
}, i2.prototype.fetchToggles = function() {
|
|
575
|
+
return r(this, void 0, void 0, function() {
|
|
576
|
+
var t2, e2, r2, o3, i3, s2, a2, c2, u2;
|
|
577
|
+
return n(this, function(n2) {
|
|
578
|
+
switch (n2.label) {
|
|
443
579
|
case 0:
|
|
444
580
|
if (!this.fetch)
|
|
445
|
-
return [3,
|
|
446
|
-
|
|
581
|
+
return [3, 9];
|
|
582
|
+
this.abortController && this.abortController.abort(), this.abortController = (u2 = this.createAbortController) === null || u2 === void 0 ? void 0 : u2.call(this), t2 = this.abortController ? this.abortController.signal : void 0, n2.label = 1;
|
|
447
583
|
case 1:
|
|
448
|
-
return
|
|
449
|
-
var
|
|
450
|
-
return Object.entries(e3).filter(
|
|
451
|
-
var e4 = t4[0],
|
|
452
|
-
e4 === "properties" &&
|
|
453
|
-
var e5 = t5[0],
|
|
454
|
-
return
|
|
455
|
-
}) :
|
|
456
|
-
}),
|
|
457
|
-
}(this.url, this.context),
|
|
584
|
+
return n2.trys.push([1, 7, 8, 9]), e2 = this.usePOSTrequests, r2 = e2 ? this.url : function(t3, e3) {
|
|
585
|
+
var r3 = new URL(t3.toString());
|
|
586
|
+
return Object.entries(e3).filter(f).forEach(function(t4) {
|
|
587
|
+
var e4 = t4[0], n3 = t4[1];
|
|
588
|
+
e4 === "properties" && n3 ? Object.entries(n3).filter(f).forEach(function(t5) {
|
|
589
|
+
var e5 = t5[0], n4 = t5[1];
|
|
590
|
+
return r3.searchParams.append("properties[".concat(e5, "]"), n4);
|
|
591
|
+
}) : r3.searchParams.append(e4, n3);
|
|
592
|
+
}), r3;
|
|
593
|
+
}(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 })];
|
|
458
594
|
case 2:
|
|
459
|
-
return
|
|
595
|
+
return s2 = n2.sent(), this.sdkState === "error" && s2.status < 400 && (this.sdkState = "healthy", this.emit(I.RECOVERED)), s2.ok ? (this.etag = s2.headers.get("ETag") || "", [4, s2.json()]) : [3, 5];
|
|
460
596
|
case 3:
|
|
461
|
-
return
|
|
597
|
+
return a2 = n2.sent(), [4, this.storeToggles(a2.toggles)];
|
|
462
598
|
case 4:
|
|
463
|
-
return
|
|
599
|
+
return n2.sent(), this.sdkState !== "healthy" && (this.sdkState = "healthy"), this.fetchedFromServer || (this.fetchedFromServer = true, this.setReady()), this.storeLastRefreshTimestamp(), [3, 6];
|
|
464
600
|
case 5:
|
|
465
|
-
|
|
601
|
+
s2.status === 304 ? this.storeLastRefreshTimestamp() : (console.error("Unleash: Fetching feature toggles did not have an ok response"), this.sdkState = "error", this.emit(I.ERROR, { type: "HttpError", code: s2.status }), this.lastError = { type: "HttpError", code: s2.status }), n2.label = 6;
|
|
466
602
|
case 6:
|
|
467
|
-
return [3,
|
|
603
|
+
return [3, 9];
|
|
468
604
|
case 7:
|
|
469
|
-
return c2 =
|
|
605
|
+
return typeof (c2 = n2.sent()) == "object" && c2 !== null && "name" in c2 && c2.name === "AbortError" || (console.error("Unleash: unable to fetch feature toggles", c2), this.sdkState = "error", this.emit(I.ERROR, c2), this.lastError = c2), [3, 9];
|
|
470
606
|
case 8:
|
|
607
|
+
return this.abortController = null, [7];
|
|
608
|
+
case 9:
|
|
471
609
|
return [2];
|
|
472
610
|
}
|
|
473
611
|
});
|
|
474
612
|
});
|
|
475
|
-
},
|
|
613
|
+
}, i2;
|
|
476
614
|
}(s);
|
|
477
615
|
const ContextStateSymbol = Symbol("Context state identifier");
|
|
478
616
|
const ContextUpdateSymbol = Symbol("Context update identifier");
|
|
@@ -490,7 +628,7 @@ function useUnleashProvide({
|
|
|
490
628
|
checking if the client exists before rendering.`);
|
|
491
629
|
}
|
|
492
630
|
if (!client.value && config) {
|
|
493
|
-
client.value = new
|
|
631
|
+
client.value = new U(config);
|
|
494
632
|
}
|
|
495
633
|
(_a = client.value) == null ? void 0 : _a.on("ready", () => {
|
|
496
634
|
flagsReady.value = true;
|
|
@@ -635,4 +773,4 @@ const plugin = {
|
|
|
635
773
|
start();
|
|
636
774
|
}
|
|
637
775
|
};
|
|
638
|
-
export { ContextStateSymbol, ContextUpdateSymbol, _sfc_main as FlagProvider,
|
|
776
|
+
export { ContextStateSymbol, ContextUpdateSymbol, _sfc_main as FlagProvider, b as InMemoryStorageProvider, T as LocalStorageProvider, U as UnleashClient, _sfc_main as default, plugin, useFlag, useFlagsStatus, useUnleashClient, useUnleashContext, useVariant };
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(d,h){typeof exports=="object"&&typeof module!="undefined"?h(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],h):(d=typeof globalThis!="undefined"?globalThis:d||self,h(d["proxy-client-vue"]={},d.Vue))})(this,function(d,h){"use strict";var P=function(o,r){return P=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])},P(o,r)},v=function(){return v=Object.assign||function(o){for(var r,t=1,n=arguments.length;t<n;t++)for(var e in r=arguments[t])Object.prototype.hasOwnProperty.call(r,e)&&(o[e]=r[e]);return o},v.apply(this,arguments)};function I(o,r,t,n){return new(t||(t=Promise))(function(e,s){function i(l){try{f(n.next(l))}catch(a){s(a)}}function c(l){try{f(n.throw(l))}catch(a){s(a)}}function f(l){var a;l.done?e(l.value):(a=l.value,a instanceof t?a:new t(function(b){b(a)})).then(i,c)}f((n=n.apply(o,r||[])).next())})}function S(o,r){var t,n,e,s,i={label:0,sent:function(){if(1&e[0])throw e[1];return e[1]},trys:[],ops:[]};return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(f){return function(l){return function(a){if(t)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(t=1,n&&(e=2&a[0]?n.return:a[0]?n.throw||((e=n.return)&&e.call(n),0):n.next)&&!(e=e.call(n,a[1])).done)return e;switch(n=0,e&&(a=[2&a[0],e.value]),a[0]){case 0:case 1:e=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(e=i.trys,!((e=e.length>0&&e[e.length-1])||a[0]!==6&&a[0]!==2)){i=0;continue}if(a[0]===3&&(!e||a[1]>e[0]&&a[1]<e[3])){i.label=a[1];break}if(a[0]===6&&i.label<e[1]){i.label=e[1],e=a;break}if(e&&i.label<e[2]){i.label=e[2],i.ops.push(a);break}e[2]&&i.ops.pop(),i.trys.pop();continue}a=r.call(o,i)}catch(b){a=[6,b],n=0}finally{t=e=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([f,l])}}}typeof SuppressedError=="function"&&SuppressedError;var _={exports:{}};function D(){}D.prototype={on:function(o,r,t){var n=this.e||(this.e={});return(n[o]||(n[o]=[])).push({fn:r,ctx:t}),this},once:function(o,r,t){var n=this;function e(){n.off(o,e),r.apply(t,arguments)}return e._=r,this.on(o,e,t)},emit:function(o){for(var r=[].slice.call(arguments,1),t=((this.e||(this.e={}))[o]||[]).slice(),n=0,e=t.length;n<e;n++)t[n].fn.apply(t[n].ctx,r);return this},off:function(o,r){var t=this.e||(this.e={}),n=t[o],e=[];if(n&&r)for(var s=0,i=n.length;s<i;s++)n[s].fn!==r&&n[s].fn._!==r&&e.push(n[s]);return e.length?t[o]=e:delete t[o],this}},_.exports=D;var Z=_.exports.TinyEmitter=D,O=function(o){var r=o[1];return r!=null},V=function(){},tt=function(){function o(r){var t=r.onError,n=r.onSent,e=r.appName,s=r.metricsInterval,i=r.disableMetrics,c=i!==void 0&&i,f=r.url,l=r.clientKey,a=r.fetch,b=r.headerName,E=r.customHeaders,x=E===void 0?{}:E;this.onError=t,this.onSent=n||V,this.disabled=c,this.metricsInterval=1e3*s,this.appName=e,this.url=f instanceof URL?f:new URL(f),this.clientKey=l,this.bucket=this.createEmptyBucket(),this.fetch=a,this.headerName=b,this.customHeaders=x}return o.prototype.start=function(){var r=this;if(this.disabled)return!1;typeof this.metricsInterval=="number"&&this.metricsInterval>0&&setTimeout(function(){r.startTimer(),r.sendMetrics()},2e3)},o.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer)},o.prototype.createEmptyBucket=function(){return{start:new Date,stop:null,toggles:{}}},o.prototype.getHeaders=function(){var r,t=((r={})[this.headerName]=this.clientKey,r.Accept="application/json",r["Content-Type"]="application/json",r);return Object.entries(this.customHeaders).filter(O).forEach(function(n){var e=n[0],s=n[1];return t[e]=s}),t},o.prototype.sendMetrics=function(){return I(this,void 0,void 0,function(){var r,t,n;return S(this,function(e){switch(e.label){case 0:if(r="".concat(this.url,"/client/metrics"),t=this.getPayload(),this.bucketIsEmpty(t))return[2];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.fetch(r,{cache:"no-cache",method:"POST",headers:this.getHeaders(),body:JSON.stringify(t)})];case 2:return e.sent(),this.onSent(t),[3,4];case 3:return n=e.sent(),console.error("Unleash: unable to send feature metrics",n),this.onError(n),[3,4];case 4:return[2]}})})},o.prototype.count=function(r,t){return!(this.disabled||!this.bucket)&&(this.assertBucket(r),this.bucket.toggles[r][t?"yes":"no"]++,!0)},o.prototype.countVariant=function(r,t){return!(this.disabled||!this.bucket)&&(this.assertBucket(r),this.bucket.toggles[r].variants[t]?this.bucket.toggles[r].variants[t]+=1:this.bucket.toggles[r].variants[t]=1,!0)},o.prototype.assertBucket=function(r){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[r]||(this.bucket.toggles[r]={yes:0,no:0,variants:{}})},o.prototype.startTimer=function(){var r=this;this.timer=setInterval(function(){r.sendMetrics()},this.metricsInterval)},o.prototype.bucketIsEmpty=function(r){return Object.keys(r.bucket.toggles).length===0},o.prototype.getPayload=function(){var r=v(v({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:r,appName:this.appName,instanceId:"browser"}},o}(),M=function(){function o(){this.store=new Map}return o.prototype.save=function(r,t){return I(this,void 0,void 0,function(){return S(this,function(n){return this.store.set(r,t),[2]})})},o.prototype.get=function(r){return I(this,void 0,void 0,function(){return S(this,function(t){return[2,this.store.get(r)]})})},o}(),H=function(){function o(){this.prefix="unleash:repository"}return o.prototype.save=function(r,t){return I(this,void 0,void 0,function(){var n,e;return S(this,function(s){n=JSON.stringify(t),e="".concat(this.prefix,":").concat(r);try{window.localStorage.setItem(e,n)}catch(i){console.error(i)}return[2]})})},o.prototype.get=function(r){try{var t="".concat(this.prefix,":").concat(r),n=window.localStorage.getItem(t);return n?JSON.parse(n):void 0}catch(e){console.error(e)}},o}();let N;const et=new Uint8Array(16);function nt(){if(!N&&(N=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!N))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return N(et)}const y=[];for(let o=0;o<256;++o)y.push((o+256).toString(16).slice(1));var B={randomUUID:typeof crypto!="undefined"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function rt(o,r,t){if(B.randomUUID&&!r&&!o)return B.randomUUID();const n=(o=o||{}).random||(o.rng||nt)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,r){t=t||0;for(let e=0;e<16;++e)r[t+e]=n[e];return r}return function(e,s=0){return y[e[s+0]]+y[e[s+1]]+y[e[s+2]]+y[e[s+3]]+"-"+y[e[s+4]]+y[e[s+5]]+"-"+y[e[s+6]]+y[e[s+7]]+"-"+y[e[s+8]]+y[e[s+9]]+"-"+y[e[s+10]]+y[e[s+11]]+y[e[s+12]]+y[e[s+13]]+y[e[s+14]]+y[e[s+15]]}(n)}var ot=function(){function o(){}return o.prototype.generateEventId=function(){return rt()},o.prototype.createImpressionEvent=function(r,t,n,e,s,i){var c=this.createBaseEvent(r,t,n,e,s);return i?v(v({},c),{variant:i}):c},o.prototype.createBaseEvent=function(r,t,n,e,s){return{eventType:e,eventId:this.generateEventId(),context:r,enabled:t,featureName:n,impressionData:s}},o}(),st=["userId","sessionId","remoteAddress"],g={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression",SENT:"sent"},it="isEnabled",at="getVariant",ut={name:"disabled",enabled:!1,feature_enabled:!1},j="repo",ct=function(){try{if(typeof window!="undefined"&&"fetch"in window)return fetch.bind(window);if("fetch"in globalThis)return fetch.bind(globalThis)}catch(o){console.error('Unleash failed to resolve "fetch"',o)}},q=function(o){function r(t){var n=t.storageProvider,e=t.url,s=t.clientKey,i=t.disableRefresh,c=i!==void 0&&i,f=t.refreshInterval,l=f===void 0?30:f,a=t.metricsInterval,b=a===void 0?30:a,E=t.disableMetrics,x=E!==void 0&&E,R=t.appName,p=t.environment,m=p===void 0?"default":p,T=t.context,k=t.fetch,C=k===void 0?ct():k,U=t.bootstrap,Y=t.bootstrapOverride,mt=Y===void 0||Y,L=t.headerName,J=L===void 0?"Authorization":L,z=t.customHeaders,G=z===void 0?{}:z,$=t.impressionDataAll,gt=$!==void 0&&$,Q=t.usePOSTrequests,bt=Q!==void 0&&Q,u=o.call(this)||this;if(u.toggles=[],u.etag="",u.readyEventEmitted=!1,u.usePOSTrequests=!1,u.started=!1,!e)throw new Error("url is required");if(!s)throw new Error("clientKey is required");if(!R)throw new Error("appName is required.");return u.eventsHandler=new ot,u.impressionDataAll=gt,u.toggles=U&&U.length>0?U:[],u.url=e instanceof URL?e:new URL(e),u.clientKey=s,u.headerName=J,u.customHeaders=G,u.storage=n||(typeof window!="undefined"?new H:new M),u.refreshInterval=c?0:1e3*l,u.context=v({appName:R,environment:m},T),u.usePOSTrequests=bt,u.ready=new Promise(function(W){u.init().then(W).catch(function(X){console.error(X),u.emit(g.ERROR,X),W()})}),C||console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'),u.fetch=C,u.bootstrap=U&&U.length>0?U:void 0,u.bootstrapOverride=mt,u.metrics=new tt({onError:u.emit.bind(u,g.ERROR),onSent:u.emit.bind(u,g.SENT),appName:R,metricsInterval:b,disableMetrics:x,url:u.url,clientKey:s,fetch:C,headerName:J,customHeaders:G}),u}return function(t,n){if(typeof n!="function"&&n!==null)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function e(){this.constructor=t}P(t,n),t.prototype=n===null?Object.create(n):(e.prototype=n.prototype,new e)}(r,o),r.prototype.getAllToggles=function(){return function(t,n,e){if(e||arguments.length===2)for(var s,i=0,c=n.length;i<c;i++)!s&&i in n||(s||(s=Array.prototype.slice.call(n,0,i)),s[i]=n[i]);return t.concat(s||Array.prototype.slice.call(n))}([],this.toggles,!0)},r.prototype.isEnabled=function(t){var n,e=this.toggles.find(function(c){return c.name===t}),s=!!e&&e.enabled;if(this.metrics.count(t,s),(e==null?void 0:e.impressionData)||this.impressionDataAll){var i=this.eventsHandler.createImpressionEvent(this.context,s,t,it,(n=e==null?void 0:e.impressionData)!==null&&n!==void 0?n:void 0);this.emit(g.IMPRESSION,i)}return s},r.prototype.getVariant=function(t){var n,e=this.toggles.find(function(f){return f.name===t}),s=(e==null?void 0:e.enabled)||!1,i=e?e.variant:ut;if(i.name&&this.metrics.countVariant(t,i.name),this.metrics.count(t,s),(e==null?void 0:e.impressionData)||this.impressionDataAll){var c=this.eventsHandler.createImpressionEvent(this.context,s,t,at,(n=e==null?void 0:e.impressionData)!==null&&n!==void 0?n:void 0,i.name);this.emit(g.IMPRESSION,c)}return v(v({},i),{feature_enabled:s})},r.prototype.updateContext=function(t){return I(this,void 0,void 0,function(){var n,e=this;return S(this,function(s){switch(s.label){case 0:return(t.appName||t.environment)&&console.warn("appName and environment are static. They can't be updated with updateContext."),n={environment:this.context.environment,appName:this.context.appName,sessionId:this.context.sessionId},this.context=v(v({},n),t),this.timerRef||this.readyEventEmitted?[4,this.fetchToggles()]:[3,2];case 1:return s.sent(),[3,4];case 2:return this.started?[4,new Promise(function(i){var c=function(){e.fetchToggles().then(function(){e.off(g.READY,c),i()})};e.once(g.READY,c)})]:[3,4];case 3:s.sent(),s.label=4;case 4:return[2]}})})},r.prototype.getContext=function(){return v({},this.context)},r.prototype.setContextField=function(t,n){var e,s;if(st.includes(t))this.context=v(v({},this.context),((e={})[t]=n,e));else{var i=v(v({},this.context.properties),((s={})[t]=n,s));this.context=v(v({},this.context),{properties:i})}this.timerRef&&this.fetchToggles()},r.prototype.init=function(){return I(this,void 0,void 0,function(){var t,n;return S(this,function(e){switch(e.label){case 0:return[4,this.resolveSessionId()];case 1:return t=e.sent(),this.context=v({sessionId:t},this.context),n=this,[4,this.storage.get(j)];case 2:return n.toggles=e.sent()||[],!this.bootstrap||!this.bootstrapOverride&&this.toggles.length!==0?[3,4]:[4,this.storage.save(j,this.bootstrap)];case 3:e.sent(),this.toggles=this.bootstrap,this.emit(g.READY),e.label=4;case 4:return this.emit(g.INIT),[2]}})})},r.prototype.start=function(){return I(this,void 0,void 0,function(){var t,n=this;return S(this,function(e){switch(e.label){case 0: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];case 1:return e.sent(),this.metrics.start(),t=this.refreshInterval,[4,this.fetchToggles()];case 2:return e.sent(),t>0&&(this.timerRef=setInterval(function(){return n.fetchToggles()},t)),[2]}})})},r.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},r.prototype.resolveSessionId=function(){return I(this,void 0,void 0,function(){var t;return S(this,function(n){switch(n.label){case 0:return this.context.sessionId?[2,this.context.sessionId]:[3,1];case 1:return[4,this.storage.get("sessionId")];case 2:return(t=n.sent())?[3,4]:(t=Math.floor(1e9*Math.random()),[4,this.storage.save("sessionId",t)]);case 3:n.sent(),n.label=4;case 4:return[2,t]}})})},r.prototype.getHeaders=function(){var t,n=((t={})[this.headerName]=this.clientKey,t.Accept="application/json",t["Content-Type"]="application/json",t["If-None-Match"]=this.etag,t);return Object.entries(this.customHeaders).filter(O).forEach(function(e){var s=e[0],i=e[1];return n[s]=i}),n},r.prototype.storeToggles=function(t){return I(this,void 0,void 0,function(){return S(this,function(n){switch(n.label){case 0:return this.toggles=t,this.emit(g.UPDATE),[4,this.storage.save(j,t)];case 1:return n.sent(),[2]}})})},r.prototype.fetchToggles=function(){return I(this,void 0,void 0,function(){var t,n,e,s,i,c,f;return S(this,function(l){switch(l.label){case 0:if(!this.fetch)return[3,8];l.label=1;case 1:return l.trys.push([1,7,,8]),t=this.usePOSTrequests,n=t?this.url:function(a,b){var E=new URL(a.toString());return Object.entries(b).filter(O).forEach(function(x){var R=x[0],p=x[1];R==="properties"&&p?Object.entries(p).filter(O).forEach(function(m){var T=m[0],k=m[1];return E.searchParams.append("properties[".concat(T,"]"),k)}):E.searchParams.append(R,p)}),E}(this.url,this.context),e=t?"POST":"GET",s=t?JSON.stringify({context:this.context}):void 0,[4,this.fetch(n.toString(),{method:e,cache:"no-cache",headers:this.getHeaders(),body:s})];case 2:return(i=l.sent()).ok&&i.status!==304?(this.etag=i.headers.get("ETag")||"",[4,i.json()]):[3,5];case 3:return c=l.sent(),[4,this.storeToggles(c.toggles)];case 4:return l.sent(),this.bootstrap||this.readyEventEmitted||(this.emit(g.READY),this.readyEventEmitted=!0),[3,6];case 5:i.ok||i.status===304||(console.error("Unleash: Fetching feature toggles did not have an ok response"),this.emit(g.ERROR,{type:"HttpError",code:i.status})),l.label=6;case 6:return[3,8];case 7:return f=l.sent(),console.error("Unleash: unable to fetch feature toggles",f),this.emit(g.ERROR,f),[3,8];case 8:return[2]}})})},r}(Z);const w=Symbol("Context state identifier"),A=Symbol("Context update identifier");function K({config:o,unleashClient:r,startClient:t=!0}){var x,R;const n=h.ref(r),e=h.ref(!1),s=h.ref(null);!o&&!r&&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
|
|
2
|
-
checking if the client exists before rendering.`),!
|
|
1
|
+
(function(v,f){typeof exports=="object"&&typeof module!="undefined"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):(v=typeof globalThis!="undefined"?globalThis:v||self,f(v["proxy-client-vue"]={},v.Vue))})(this,function(v,f){"use strict";var P=function(s,n){return P=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])},P(s,n)},p=function(){return p=Object.assign||function(s){for(var n,t=1,r=arguments.length;t<r;t++)for(var e in n=arguments[t])Object.prototype.hasOwnProperty.call(n,e)&&(s[e]=n[e]);return s},p.apply(this,arguments)};function b(s,n,t,r){return new(t||(t=Promise))(function(e,o){function i(h){try{l(r.next(h))}catch(a){o(a)}}function c(h){try{l(r.throw(h))}catch(a){o(a)}}function l(h){var a;h.done?e(h.value):(a=h.value,a instanceof t?a:new t(function(g){g(a)})).then(i,c)}l((r=r.apply(s,n||[])).next())})}function T(s,n){var t,r,e,o={label:0,sent:function(){if(1&e[0])throw e[1];return e[1]},trys:[],ops:[]},i=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function c(l){return function(h){return function(a){if(t)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(o=0)),o;)try{if(t=1,r&&(e=2&a[0]?r.return:a[0]?r.throw||((e=r.return)&&e.call(r),0):r.next)&&!(e=e.call(r,a[1])).done)return e;switch(r=0,e&&(a=[2&a[0],e.value]),a[0]){case 0:case 1:e=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(e=o.trys,!((e=e.length>0&&e[e.length-1])||a[0]!==6&&a[0]!==2)){o=0;continue}if(a[0]===3&&(!e||a[1]>e[0]&&a[1]<e[3])){o.label=a[1];break}if(a[0]===6&&o.label<e[1]){o.label=e[1],e=a;break}if(e&&o.label<e[2]){o.label=e[2],o.ops.push(a);break}e[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(s,o)}catch(g){a=[6,g],r=0}finally{t=e=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([l,h])}}}typeof SuppressedError=="function"&&SuppressedError;var q={exports:{}};function D(){}D.prototype={on:function(s,n,t){var r=this.e||(this.e={});return(r[s]||(r[s]=[])).push({fn:n,ctx:t}),this},once:function(s,n,t){var r=this;function e(){r.off(s,e),n.apply(t,arguments)}return e._=n,this.on(s,e,t)},emit:function(s){for(var n=[].slice.call(arguments,1),t=((this.e||(this.e={}))[s]||[]).slice(),r=0,e=t.length;r<e;r++)t[r].fn.apply(t[r].ctx,n);return this},off:function(s,n){var t=this.e||(this.e={}),r=t[s],e=[];if(r&&n)for(var o=0,i=r.length;o<i;o++)r[o].fn!==n&&r[o].fn._!==n&&e.push(r[o]);return e.length?t[s]=e:delete t[s],this}},q.exports=D;var ct=q.exports.TinyEmitter=D;let U;const ut=new Uint8Array(16);function lt(){if(!U&&(U=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!U))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return U(ut)}const y=[];for(let s=0;s<256;++s)y.push((s+256).toString(16).slice(1));var B={randomUUID:typeof crypto!="undefined"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function K(s,n,t){if(B.randomUUID&&!n&&!s)return B.randomUUID();const r=(s=s||{}).random||(s.rng||lt)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,n){t=t||0;for(let e=0;e<16;++e)n[t+e]=r[e];return n}return function(e,o=0){return y[e[o+0]]+y[e[o+1]]+y[e[o+2]]+y[e[o+3]]+"-"+y[e[o+4]]+y[e[o+5]]+"-"+y[e[o+6]]+y[e[o+7]]+"-"+y[e[o+8]]+y[e[o+9]]+"-"+y[e[o+10]]+y[e[o+11]]+y[e[o+12]]+y[e[o+13]]+y[e[o+14]]+y[e[o+15]]}(r)}var C=function(s){var n=s[1];return n!=null},ht=function(s){var n=s.properties,t=n===void 0?{}:n,r=function(o,i){var c={};for(var l in o)Object.prototype.hasOwnProperty.call(o,l)&&i.indexOf(l)<0&&(c[l]=o[l]);if(o!=null&&typeof Object.getOwnPropertySymbols=="function"){var h=0;for(l=Object.getOwnPropertySymbols(o);h<l.length;h++)i.indexOf(l[h])<0&&Object.prototype.propertyIsEnumerable.call(o,l[h])&&(c[l[h]]=o[l[h]])}return c}(s,["properties"]),e=function(o){return Object.entries(o).sort(function(i,c){var l=i[0],h=c[0];return l.localeCompare(h,void 0)})};return JSON.stringify([e(r),e(t)])},Y=function(s){return b(void 0,void 0,void 0,function(){var n;return T(this,function(t){switch(t.label){case 0:n=ht(s),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,(r=n,b(void 0,void 0,void 0,function(){var e,o,i,c,l;return T(this,function(h){switch(h.label){case 0:if(e=typeof globalThis!="undefined"&&((c=globalThis.crypto)===null||c===void 0?void 0:c.subtle)?(l=globalThis.crypto)===null||l===void 0?void 0:l.subtle:void 0,typeof TextEncoder=="undefined"||!(e!=null&&e.digest)||typeof Uint8Array=="undefined")throw new Error("Hashing function not available");return o=new TextEncoder().encode(r),[4,e.digest("SHA-256",o)];case 1:return i=h.sent(),[2,Array.from(new Uint8Array(i)).map(function(a){return a.toString(16).padStart(2,"0")}).join("")]}})}))];case 2:return[2,t.sent()];case 3:return t.sent(),[2,n];case 4:return[2]}var r})})},J="unleash-js@3.7.1",ft=function(){},pt=function(){function s(n){var t=n.onError,r=n.onSent,e=n.appName,o=n.metricsInterval,i=n.disableMetrics,c=i!==void 0&&i,l=n.url,h=n.clientKey,a=n.fetch,g=n.headerName,I=n.customHeaders,R=I===void 0?{}:I,E=n.metricsIntervalInitial,d=n.connectionId;this.onError=t,this.onSent=r||ft,this.disabled=c,this.metricsInterval=1e3*o,this.metricsIntervalInitial=1e3*E,this.appName=e,this.url=l instanceof URL?l:new URL(l),this.clientKey=h,this.bucket=this.createEmptyBucket(),this.fetch=a,this.headerName=g,this.customHeaders=R,this.connectionId=d}return s.prototype.start=function(){var n=this;if(this.disabled)return!1;typeof this.metricsInterval=="number"&&this.metricsInterval>0&&(this.metricsIntervalInitial>0?setTimeout(function(){n.startTimer(),n.sendMetrics()},this.metricsIntervalInitial):this.startTimer())},s.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer)},s.prototype.createEmptyBucket=function(){return{start:new Date,stop:null,toggles:{}}},s.prototype.getHeaders=function(){var n,t=((n={})[this.headerName]=this.clientKey,n.Accept="application/json",n["Content-Type"]="application/json",n["x-unleash-sdk"]=J,n["x-unleash-connection-id"]=this.connectionId,n["x-unleash-appname"]=this.appName,n);return Object.entries(this.customHeaders).filter(C).forEach(function(r){var e=r[0],o=r[1];return t[e]=o}),t},s.prototype.sendMetrics=function(){return b(this,void 0,void 0,function(){var n,t,r;return T(this,function(e){switch(e.label){case 0:if(n="".concat(this.url,"/client/metrics"),t=this.getPayload(),this.bucketIsEmpty(t))return[2];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.fetch(n,{cache:"no-cache",method:"POST",headers:this.getHeaders(),body:JSON.stringify(t)})];case 2:return e.sent(),this.onSent(t),[3,4];case 3:return r=e.sent(),console.error("Unleash: unable to send feature metrics",r),this.onError(r),[3,4];case 4:return[2]}})})},s.prototype.count=function(n,t){return!(this.disabled||!this.bucket)&&(this.assertBucket(n),this.bucket.toggles[n][t?"yes":"no"]++,!0)},s.prototype.countVariant=function(n,t){return!(this.disabled||!this.bucket)&&(this.assertBucket(n),this.bucket.toggles[n].variants[t]?this.bucket.toggles[n].variants[t]+=1:this.bucket.toggles[n].variants[t]=1,!0)},s.prototype.assertBucket=function(n){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[n]||(this.bucket.toggles[n]={yes:0,no:0,variants:{}})},s.prototype.startTimer=function(){var n=this;this.timer=setInterval(function(){n.sendMetrics()},this.metricsInterval)},s.prototype.bucketIsEmpty=function(n){return Object.keys(n.bucket.toggles).length===0},s.prototype.getPayload=function(){var n=p(p({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:n,appName:this.appName,instanceId:"browser"}},s}(),z=function(){function s(){this.store=new Map}return s.prototype.save=function(n,t){return b(this,void 0,void 0,function(){return T(this,function(r){return this.store.set(n,t),[2]})})},s.prototype.get=function(n){return b(this,void 0,void 0,function(){return T(this,function(t){return[2,this.store.get(n)]})})},s}(),G=function(){function s(n){n===void 0&&(n="unleash:repository"),this.prefix=n}return s.prototype.save=function(n,t){return b(this,void 0,void 0,function(){var r,e;return T(this,function(o){r=JSON.stringify(t),e="".concat(this.prefix,":").concat(n);try{window.localStorage.setItem(e,r)}catch(i){console.error(i)}return[2]})})},s.prototype.get=function(n){try{var t="".concat(this.prefix,":").concat(n),r=window.localStorage.getItem(t);return r?JSON.parse(r):void 0}catch(e){console.error(e)}},s}(),dt=function(){function s(){}return s.prototype.generateEventId=function(){return K()},s.prototype.createImpressionEvent=function(n,t,r,e,o,i){var c=this.createBaseEvent(n,t,r,e,o);return i?p(p({},c),{variant:i}):c},s.prototype.createBaseEvent=function(n,t,r,e,o){return{eventType:e,eventId:this.generateEventId(),context:n,enabled:t,featureName:r,impressionData:o}},s}(),vt=["userId","sessionId","remoteAddress","currentTime"],$=function(s){return vt.includes(s)},S={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression",SENT:"sent",RECOVERED:"recovered"},mt="isEnabled",gt="getVariant",yt={name:"disabled",enabled:!1,feature_enabled:!1},L="repo",Q="repoLastUpdateTimestamp",bt=function(){try{if(typeof window!="undefined"&&"fetch"in window)return fetch.bind(window);if("fetch"in globalThis)return fetch.bind(globalThis)}catch(s){console.error('Unleash failed to resolve "fetch"',s)}},W=function(s){function n(t){var r=t.storageProvider,e=t.url,o=t.clientKey,i=t.disableRefresh,c=i!==void 0&&i,l=t.refreshInterval,h=l===void 0?30:l,a=t.metricsInterval,g=a===void 0?30:a,I=t.metricsIntervalInitial,R=I===void 0?2:I,E=t.disableMetrics,d=E!==void 0&&E,m=t.appName,x=t.environment,N=x===void 0?"default":x,H=t.context,A=t.fetch,M=A===void 0?bt():A,V=t.createAbortController,tt=V===void 0?function(){try{if(typeof window!="undefined"&&"AbortController"in window)return function(){return new window.AbortController};if("fetch"in globalThis)return function(){return new globalThis.AbortController}}catch(j){console.error('Unleash failed to resolve "AbortController" factory',j)}}():V,O=t.bootstrap,et=t.bootstrapOverride,Ot=et===void 0||et,rt=t.headerName,nt=rt===void 0?"Authorization":rt,ot=t.customHeaders,st=ot===void 0?{}:ot,it=t.impressionDataAll,kt=it!==void 0&&it,at=t.usePOSTrequests,Ut=at!==void 0&&at,k=t.experimental,u=s.call(this)||this;if(u.toggles=[],u.etag="",u.readyEventEmitted=!1,u.fetchedFromServer=!1,u.usePOSTrequests=!1,u.started=!1,!e)throw new Error("url is required");if(!o)throw new Error("clientKey is required");if(!m)throw new Error("appName is required.");return u.eventsHandler=new dt,u.impressionDataAll=kt,u.toggles=O&&O.length>0?O:[],u.url=e instanceof URL?e:new URL(e),u.clientKey=o,u.headerName=nt,u.customHeaders=st,u.storage=r||(typeof window!="undefined"?new G:new z),u.refreshInterval=c?0:1e3*h,u.context=p({appName:m,environment:N},H),u.usePOSTrequests=Ut,u.sdkState="initializing",u.experimental=p({},k),(k==null?void 0:k.togglesStorageTTL)&&(k==null?void 0:k.togglesStorageTTL)>0&&(u.experimental.togglesStorageTTL=1e3*k.togglesStorageTTL),u.lastRefreshTimestamp=0,u.ready=new Promise(function(j){u.init().then(j).catch(function(F){console.error(F),u.sdkState="error",u.emit(S.ERROR,F),u.lastError=F,j()})}),M||console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'),tt||console.error('Unleash: You must either provide your own "AbortController" implementation or run in an environment where "AbortController" is available.'),u.fetch=M,u.createAbortController=tt,u.bootstrap=O&&O.length>0?O:void 0,u.bootstrapOverride=Ot,u.connectionId=K(),u.metrics=new pt({onError:u.emit.bind(u,S.ERROR),onSent:u.emit.bind(u,S.SENT),appName:m,metricsInterval:g,disableMetrics:d,url:u.url,clientKey:o,fetch:M,headerName:nt,customHeaders:st,metricsIntervalInitial:R,connectionId:u.connectionId}),u}return function(t,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function e(){this.constructor=t}P(t,r),t.prototype=r===null?Object.create(r):(e.prototype=r.prototype,new e)}(n,s),n.prototype.getAllToggles=function(){return function(t,r,e){if(e||arguments.length===2)for(var o,i=0,c=r.length;i<c;i++)!o&&i in r||(o||(o=Array.prototype.slice.call(r,0,i)),o[i]=r[i]);return t.concat(o||Array.prototype.slice.call(r))}([],this.toggles,!0)},n.prototype.isEnabled=function(t){var r,e=this.toggles.find(function(c){return c.name===t}),o=!!e&&e.enabled;if(this.metrics.count(t,o),(e==null?void 0:e.impressionData)||this.impressionDataAll){var i=this.eventsHandler.createImpressionEvent(this.context,o,t,mt,(r=e==null?void 0:e.impressionData)!==null&&r!==void 0?r:void 0);this.emit(S.IMPRESSION,i)}return o},n.prototype.getVariant=function(t){var r,e=this.toggles.find(function(l){return l.name===t}),o=(e==null?void 0:e.enabled)||!1,i=e?e.variant:yt;if(i.name&&this.metrics.countVariant(t,i.name),this.metrics.count(t,o),(e==null?void 0:e.impressionData)||this.impressionDataAll){var c=this.eventsHandler.createImpressionEvent(this.context,o,t,gt,(r=e==null?void 0:e.impressionData)!==null&&r!==void 0?r:void 0,i.name);this.emit(S.IMPRESSION,c)}return p(p({},i),{feature_enabled:o})},n.prototype.updateToggles=function(){return b(this,void 0,void 0,function(){var t=this;return T(this,function(r){switch(r.label){case 0:return this.timerRef||this.fetchedFromServer?[4,this.fetchToggles()]:[3,2];case 1:return r.sent(),[3,4];case 2:return this.started?[4,new Promise(function(e){var o=function(){t.fetchToggles().then(function(){t.off(S.READY,o),e()})};t.once(S.READY,o)})]:[3,4];case 3:r.sent(),r.label=4;case 4:return[2]}})})},n.prototype.updateContext=function(t){return b(this,void 0,void 0,function(){var r;return T(this,function(e){switch(e.label){case 0:return(t.appName||t.environment)&&console.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),t),[4,this.updateToggles()];case 1:return e.sent(),[2]}})})},n.prototype.getContext=function(){return p({},this.context)},n.prototype.setContextField=function(t,r){var e,o;if($(t))this.context=p(p({},this.context),((e={})[t]=r,e));else{var i=p(p({},this.context.properties),((o={})[t]=r,o));this.context=p(p({},this.context),{properties:i})}this.updateToggles()},n.prototype.removeContextField=function(t){var r;$(t)?this.context=p(p({},this.context),((r={})[t]=void 0,r)):typeof this.context.properties=="object"&&delete this.context.properties[t],this.updateToggles()},n.prototype.setReady=function(){this.readyEventEmitted=!0,this.emit(S.READY)},n.prototype.init=function(){return b(this,void 0,void 0,function(){var t,r,e;return T(this,function(o){switch(o.label){case 0:return[4,this.resolveSessionId()];case 1:return t=o.sent(),this.context=p({sessionId:t},this.context),r=this,[4,this.storage.get(L)];case 2:return r.toggles=o.sent()||[],e=this,[4,this.getLastRefreshTimestamp()];case 3:return e.lastRefreshTimestamp=o.sent(),!this.bootstrap||!this.bootstrapOverride&&this.toggles.length!==0?[3,6]:[4,this.storage.save(L,this.bootstrap)];case 4:return o.sent(),this.toggles=this.bootstrap,this.sdkState="healthy",[4,this.storeLastRefreshTimestamp()];case 5:o.sent(),this.setReady(),o.label=6;case 6:return this.sdkState="healthy",this.emit(S.INIT),[2]}})})},n.prototype.start=function(){return b(this,void 0,void 0,function(){var t,r=this;return T(this,function(e){switch(e.label){case 0: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];case 1:return e.sent(),this.metrics.start(),t=this.refreshInterval,[4,this.initialFetchToggles()];case 2:return e.sent(),t>0&&(this.timerRef=setInterval(function(){return r.fetchToggles()},t)),[2]}})})},n.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},n.prototype.isReady=function(){return this.readyEventEmitted},n.prototype.getError=function(){return this.sdkState==="error"?this.lastError:void 0},n.prototype.sendMetrics=function(){return this.metrics.sendMetrics()},n.prototype.resolveSessionId=function(){return b(this,void 0,void 0,function(){var t;return T(this,function(r){switch(r.label){case 0:return this.context.sessionId?[2,this.context.sessionId]:[4,this.storage.get("sessionId")];case 1:return(t=r.sent())?[3,3]:(t=Math.floor(1e9*Math.random()),[4,this.storage.save("sessionId",t.toString(10))]);case 2:r.sent(),r.label=3;case 3:return[2,t.toString(10)]}})})},n.prototype.getHeaders=function(){var t,r=this.usePOSTrequests,e=((t={})[this.headerName]=this.clientKey,t.Accept="application/json",t["x-unleash-sdk"]=J,t["x-unleash-connection-id"]=this.connectionId,t["x-unleash-appname"]=this.context.appName,t);return r&&(e["Content-Type"]="application/json"),this.etag&&(e["If-None-Match"]=this.etag),Object.entries(this.customHeaders).filter(C).forEach(function(o){var i=o[0],c=o[1];return e[i]=c}),e},n.prototype.storeToggles=function(t){return b(this,void 0,void 0,function(){return T(this,function(r){switch(r.label){case 0:return this.toggles=t,this.emit(S.UPDATE),[4,this.storage.save(L,t)];case 1:return r.sent(),[2]}})})},n.prototype.isTogglesStorageTTLEnabled=function(){var t;return!!(((t=this.experimental)===null||t===void 0?void 0:t.togglesStorageTTL)&&this.experimental.togglesStorageTTL>0)},n.prototype.isUpToDate=function(){var t;if(!this.isTogglesStorageTTLEnabled())return!1;var r=Date.now(),e=((t=this.experimental)===null||t===void 0?void 0:t.togglesStorageTTL)||0;return this.lastRefreshTimestamp>0&&this.lastRefreshTimestamp<=r&&r-this.lastRefreshTimestamp<=e},n.prototype.getLastRefreshTimestamp=function(){return b(this,void 0,void 0,function(){var t,r;return T(this,function(e){switch(e.label){case 0:return this.isTogglesStorageTTLEnabled()?[4,this.storage.get(Q)]:[3,3];case 1:return t=e.sent(),[4,Y(this.context)];case 2:return r=e.sent(),[2,(t==null?void 0:t.key)===r?t.timestamp:0];case 3:return[2,0]}})})},n.prototype.storeLastRefreshTimestamp=function(){return b(this,void 0,void 0,function(){var t,r;return T(this,function(e){switch(e.label){case 0:return this.isTogglesStorageTTLEnabled()?(this.lastRefreshTimestamp=Date.now(),r={},[4,Y(this.context)]):[3,3];case 1:return r.key=e.sent(),r.timestamp=this.lastRefreshTimestamp,t=r,[4,this.storage.save(Q,t)];case 2:e.sent(),e.label=3;case 3:return[2]}})})},n.prototype.initialFetchToggles=function(){if(!this.isUpToDate())return this.fetchToggles();this.fetchedFromServer||(this.fetchedFromServer=!0,this.setReady())},n.prototype.fetchToggles=function(){return b(this,void 0,void 0,function(){var t,r,e,o,i,c,l,h,a;return T(this,function(g){switch(g.label){case 0:if(!this.fetch)return[3,9];this.abortController&&this.abortController.abort(),this.abortController=(a=this.createAbortController)===null||a===void 0?void 0:a.call(this),t=this.abortController?this.abortController.signal:void 0,g.label=1;case 1:return g.trys.push([1,7,8,9]),r=this.usePOSTrequests,e=r?this.url:function(I,R){var E=new URL(I.toString());return Object.entries(R).filter(C).forEach(function(d){var m=d[0],x=d[1];m==="properties"&&x?Object.entries(x).filter(C).forEach(function(N){var H=N[0],A=N[1];return E.searchParams.append("properties[".concat(H,"]"),A)}):E.searchParams.append(m,x)}),E}(this.url,this.context),o=r?"POST":"GET",i=r?JSON.stringify({context:this.context}):void 0,[4,this.fetch(e.toString(),{method:o,cache:"no-cache",headers:this.getHeaders(),body:i,signal:t})];case 2:return c=g.sent(),this.sdkState==="error"&&c.status<400&&(this.sdkState="healthy",this.emit(S.RECOVERED)),c.ok?(this.etag=c.headers.get("ETag")||"",[4,c.json()]):[3,5];case 3:return l=g.sent(),[4,this.storeToggles(l.toggles)];case 4:return g.sent(),this.sdkState!=="healthy"&&(this.sdkState="healthy"),this.fetchedFromServer||(this.fetchedFromServer=!0,this.setReady()),this.storeLastRefreshTimestamp(),[3,6];case 5:c.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:c.status}),this.lastError={type:"HttpError",code:c.status}),g.label=6;case 6:return[3,9];case 7:return typeof(h=g.sent())=="object"&&h!==null&&"name"in h&&h.name==="AbortError"||(console.error("Unleash: unable to fetch feature toggles",h),this.sdkState="error",this.emit(S.ERROR,h),this.lastError=h),[3,9];case 8:return this.abortController=null,[7];case 9:return[2]}})})},n}(ct);const w=Symbol("Context state identifier"),_=Symbol("Context update identifier");function X({config:s,unleashClient:n,startClient:t=!0}){var R,E;const r=f.ref(n),e=f.ref(!1),o=f.ref(null);!s&&!n&&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
|
|
2
|
+
checking if the client exists before rendering.`),!r.value&&s&&(r.value=new W(s)),(R=r.value)==null||R.on("ready",()=>{e.value=!0}),(E=r.value)==null||E.on("error",d=>{o.value=d});const i=async d=>{var m;await((m=r.value)==null?void 0:m.updateContext(d))},c=d=>{var m;return(m=r.value)==null?void 0:m.isEnabled(d)},l=d=>{var m;return(m=r.value)==null?void 0:m.getVariant(d)},h=(d,...m)=>{var x;return(x=r.value)==null?void 0:x.on(d,...m)},a=f.reactive({on:h,updateContext:i,isEnabled:c,getVariant:l,client:r,flagsReady:e,flagsError:o}),g=(d,m)=>{a[d]=m},I=()=>{var d;(t||!n)&&((d=r==null?void 0:r.value)==null||d.start())};return{context:f.toRefs(a),update:g,start:I}}const Z=f.defineComponent({__name:"FlagProvider",props:{config:null,unleashClient:null,startClient:{type:Boolean}},setup(s){const{config:n,unleashClient:t,startClient:r=!0}=s,{context:e,start:o,update:i}=X({config:n,unleashClient:t,startClient:r});return f.provide(w,e),f.provide(_,i),f.onMounted(()=>{o()}),(c,l)=>f.renderSlot(c.$slots,"default")}}),Tt=s=>{const{isEnabled:n,client:t}=f.inject(w,{}),r=f.ref(Boolean(n==null?void 0:n.value(s)));function e(){const i=n==null?void 0:n.value(s);i!==r.value&&(r.value=!!i)}function o(){r.value=Boolean(n==null?void 0:n.value(s))}return t==null||t.value.on("ready",o),t==null||t.value.on("update",e),f.onUnmounted(()=>{t==null||t.value.off("ready",o),t==null||t.value.off("update",e)}),r},St=()=>{const{flagsReady:s,flagsError:n}=f.inject(w,{});return{flagsReady:s,flagsError:n}},Et=(s,n)=>{var r,e,o,i;return!((s==null?void 0:s.name)===(n==null?void 0:n.name)&&(s==null?void 0:s.enabled)===(n==null?void 0:n.enabled)&&(s==null?void 0:s.feature_enabled)===(n==null?void 0:n.feature_enabled)&&((r=s==null?void 0:s.payload)==null?void 0:r.type)===((e=n==null?void 0:n.payload)==null?void 0:e.type)&&((o=s==null?void 0:s.payload)==null?void 0:o.value)===((i=n==null?void 0:n.payload)==null?void 0:i.value))},It=s=>{const{getVariant:n,client:t}=f.inject(w,{}),r=f.ref(n==null?void 0:n.value(s));function e(){const i=n==null?void 0:n.value(s);Et(r==null?void 0:r.value,i)&&(r.value=i)}function o(){r.value=n==null?void 0:n.value(s)}return t==null||t.value.on("ready",o),t==null||t.value.on("update",e),f.onUnmounted(()=>{t==null||t.value.off("ready",o),t==null||t.value.off("update",e)}),r||{}},xt=()=>{const{updateContext:s}=f.inject(w,{});return s==null?void 0:s.value},wt=()=>{const{client:s}=f.inject(w,{});return s==null?void 0:s.value},Rt={install(s,{config:n,unleashClient:t,startClient:r}){const{context:e,update:o,start:i}=X({config:n,unleashClient:t,startClient:r});s.provide(w,e),s.provide(_,o),i()}};v.ContextStateSymbol=w,v.ContextUpdateSymbol=_,v.FlagProvider=Z,v.InMemoryStorageProvider=z,v.LocalStorageProvider=G,v.UnleashClient=W,v.default=Z,v.plugin=Rt,v.useFlag=Tt,v.useFlagsStatus=St,v.useUnleashClient=wt,v.useUnleashContext=xt,v.useVariant=It,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -14,6 +14,7 @@ declare function useUnleashProvide({ config, unleashClient, startClient }: IProv
|
|
|
14
14
|
getAllToggles: () => import("unleash-proxy-client").IToggle[];
|
|
15
15
|
isEnabled: (toggleName: string) => boolean;
|
|
16
16
|
getVariant: (toggleName: string) => import("unleash-proxy-client").IVariant;
|
|
17
|
+
updateToggles: () => Promise<void>;
|
|
17
18
|
updateContext: (context: import("unleash-proxy-client").IMutableContext) => Promise<void>;
|
|
18
19
|
getContext: () => {
|
|
19
20
|
appName: string;
|
|
@@ -21,13 +22,18 @@ declare function useUnleashProvide({ config, unleashClient, startClient }: IProv
|
|
|
21
22
|
userId?: string | undefined;
|
|
22
23
|
sessionId?: string | undefined;
|
|
23
24
|
remoteAddress?: string | undefined;
|
|
25
|
+
currentTime?: string | undefined;
|
|
24
26
|
properties?: {
|
|
25
27
|
[key: string]: string;
|
|
26
28
|
} | undefined;
|
|
27
29
|
};
|
|
28
30
|
setContextField: (field: string, value: string) => void;
|
|
31
|
+
removeContextField: (field: string) => void;
|
|
29
32
|
start: () => Promise<void>;
|
|
30
33
|
stop: () => void;
|
|
34
|
+
isReady: () => boolean;
|
|
35
|
+
getError: () => any;
|
|
36
|
+
sendMetrics: () => Promise<void>;
|
|
31
37
|
on: (event: string, callback: Function, ctx?: any) => UnleashClient;
|
|
32
38
|
once: (event: string, callback: Function, ctx?: any) => UnleashClient;
|
|
33
39
|
emit: (event: string, ...args: any[]) => UnleashClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unleash/proxy-client-vue",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Vue interface for working with Unleash",
|
|
5
5
|
"main": "./dist/index.umd.js",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
19
|
"import": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.es.js"
|
|
22
22
|
},
|
|
23
23
|
"require": {
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.umd.js"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
},
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"preview": "vite preview"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"unleash-proxy-client": "^3.
|
|
36
|
+
"unleash-proxy-client": "^3.7.1",
|
|
37
37
|
"vue": "^3.2.45"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|