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