@unleash/proxy-client-vue 0.1.3 → 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/index.es.js +77 -74
- package/dist/index.umd.js +2 -2
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -128,36 +128,10 @@ i.prototype = { on: function(t2, e2, r2) {
|
|
|
128
128
|
n2[i2].fn !== e2 && n2[i2].fn._ !== e2 && o2.push(n2[i2]);
|
|
129
129
|
return o2.length ? r2[t2] = o2 : delete r2[t2], this;
|
|
130
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) {
|
|
131
|
+
var s = o.exports.TinyEmitter = i, a = function(t2) {
|
|
158
132
|
var e2 = t2[1];
|
|
159
133
|
return e2 != null;
|
|
160
|
-
},
|
|
134
|
+
}, c = function(t2) {
|
|
161
135
|
var e2 = t2.properties, r2 = e2 === void 0 ? {} : e2, n2 = function(t3, e3) {
|
|
162
136
|
var r3 = {};
|
|
163
137
|
for (var n3 in t3)
|
|
@@ -175,13 +149,13 @@ var f = function(t2) {
|
|
|
175
149
|
});
|
|
176
150
|
};
|
|
177
151
|
return JSON.stringify([o2(n2), o2(r2)]);
|
|
178
|
-
},
|
|
152
|
+
}, u = function(t2) {
|
|
179
153
|
return r(void 0, void 0, void 0, function() {
|
|
180
154
|
var e2;
|
|
181
155
|
return n(this, function(o2) {
|
|
182
156
|
switch (o2.label) {
|
|
183
157
|
case 0:
|
|
184
|
-
e2 =
|
|
158
|
+
e2 = c(t2), o2.label = 1;
|
|
185
159
|
case 1:
|
|
186
160
|
return o2.trys.push([1, 3, , 4]), [4, (i2 = e2, r(void 0, void 0, void 0, function() {
|
|
187
161
|
var t3, e3, r2, o3, s2;
|
|
@@ -208,11 +182,11 @@ var f = function(t2) {
|
|
|
208
182
|
var i2;
|
|
209
183
|
});
|
|
210
184
|
});
|
|
211
|
-
},
|
|
212
|
-
},
|
|
185
|
+
}, l = "unleash-js@3.7.2", h = function() {
|
|
186
|
+
}, p = function() {
|
|
213
187
|
function t2(t3) {
|
|
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,
|
|
215
|
-
this.onError = e2, this.onSent = r2 ||
|
|
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;
|
|
216
190
|
}
|
|
217
191
|
return t2.prototype.start = function() {
|
|
218
192
|
var t3 = this;
|
|
@@ -226,8 +200,8 @@ var f = function(t2) {
|
|
|
226
200
|
}, t2.prototype.createEmptyBucket = function() {
|
|
227
201
|
return { start: new Date(), stop: null, toggles: {} };
|
|
228
202
|
}, t2.prototype.getHeaders = function() {
|
|
229
|
-
var t3, e2 = ((t3 = {})[this.headerName] = this.clientKey, t3.Accept = "application/json", t3["Content-Type"] = "application/json", t3["x-unleash-sdk"] =
|
|
230
|
-
return Object.entries(this.customHeaders).filter(
|
|
203
|
+
var t3, e2 = ((t3 = {})[this.headerName] = this.clientKey, t3.Accept = "application/json", t3["Content-Type"] = "application/json", t3["x-unleash-sdk"] = l, t3["x-unleash-connection-id"] = this.connectionId, t3["x-unleash-appname"] = this.appName, t3);
|
|
204
|
+
return Object.entries(this.customHeaders).filter(a).forEach(function(t4) {
|
|
231
205
|
var r2 = t4[0], n2 = t4[1];
|
|
232
206
|
return e2[r2] = n2;
|
|
233
207
|
}), e2;
|
|
@@ -270,7 +244,7 @@ var f = function(t2) {
|
|
|
270
244
|
var t3 = e(e({}, this.bucket), { stop: new Date() });
|
|
271
245
|
return this.bucket = this.createEmptyBucket(), { bucket: t3, appName: this.appName, instanceId: "browser" };
|
|
272
246
|
}, t2;
|
|
273
|
-
}(),
|
|
247
|
+
}(), f = function() {
|
|
274
248
|
function t2() {
|
|
275
249
|
this.store = /* @__PURE__ */ new Map();
|
|
276
250
|
}
|
|
@@ -287,7 +261,7 @@ var f = function(t2) {
|
|
|
287
261
|
});
|
|
288
262
|
});
|
|
289
263
|
}, t2;
|
|
290
|
-
}(),
|
|
264
|
+
}(), d = function() {
|
|
291
265
|
function t2(t3) {
|
|
292
266
|
t3 === void 0 && (t3 = "unleash:repository"), this.prefix = t3;
|
|
293
267
|
}
|
|
@@ -312,20 +286,46 @@ var f = function(t2) {
|
|
|
312
286
|
console.error(t4);
|
|
313
287
|
}
|
|
314
288
|
}, t2;
|
|
315
|
-
}()
|
|
289
|
+
}();
|
|
290
|
+
let v;
|
|
291
|
+
const m = new Uint8Array(16);
|
|
292
|
+
function g() {
|
|
293
|
+
if (!v && (v = typeof crypto != "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !v))
|
|
294
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
295
|
+
return v(m);
|
|
296
|
+
}
|
|
297
|
+
const y = [];
|
|
298
|
+
for (let t2 = 0; t2 < 256; ++t2)
|
|
299
|
+
y.push((t2 + 256).toString(16).slice(1));
|
|
300
|
+
var b = { randomUUID: typeof crypto != "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
|
|
301
|
+
function x(t2, e2, r2) {
|
|
302
|
+
if (b.randomUUID && !e2 && !t2)
|
|
303
|
+
return b.randomUUID();
|
|
304
|
+
const n2 = (t2 = t2 || {}).random || (t2.rng || g)();
|
|
305
|
+
if (n2[6] = 15 & n2[6] | 64, n2[8] = 63 & n2[8] | 128, e2) {
|
|
306
|
+
r2 = r2 || 0;
|
|
307
|
+
for (let t3 = 0; t3 < 16; ++t3)
|
|
308
|
+
e2[r2 + t3] = n2[t3];
|
|
309
|
+
return e2;
|
|
310
|
+
}
|
|
311
|
+
return function(t3, e3 = 0) {
|
|
312
|
+
return y[t3[e3 + 0]] + y[t3[e3 + 1]] + y[t3[e3 + 2]] + y[t3[e3 + 3]] + "-" + y[t3[e3 + 4]] + y[t3[e3 + 5]] + "-" + y[t3[e3 + 6]] + y[t3[e3 + 7]] + "-" + y[t3[e3 + 8]] + y[t3[e3 + 9]] + "-" + y[t3[e3 + 10]] + y[t3[e3 + 11]] + y[t3[e3 + 12]] + y[t3[e3 + 13]] + y[t3[e3 + 14]] + y[t3[e3 + 15]];
|
|
313
|
+
}(n2);
|
|
314
|
+
}
|
|
315
|
+
var T = function() {
|
|
316
316
|
function t2() {
|
|
317
317
|
}
|
|
318
318
|
return t2.prototype.generateEventId = function() {
|
|
319
|
-
return
|
|
319
|
+
return x();
|
|
320
320
|
}, t2.prototype.createImpressionEvent = function(t3, r2, n2, o2, i2, s2) {
|
|
321
321
|
var a2 = this.createBaseEvent(t3, r2, n2, o2, i2);
|
|
322
322
|
return s2 ? e(e({}, a2), { variant: s2 }) : a2;
|
|
323
323
|
}, t2.prototype.createBaseEvent = function(t3, e2, r2, n2, o2) {
|
|
324
324
|
return { eventType: n2, eventId: this.generateEventId(), context: t3, enabled: e2, featureName: r2, impressionData: o2 };
|
|
325
325
|
}, t2;
|
|
326
|
-
}(),
|
|
327
|
-
return
|
|
328
|
-
},
|
|
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() {
|
|
329
329
|
try {
|
|
330
330
|
if (typeof window != "undefined" && "fetch" in window)
|
|
331
331
|
return fetch.bind(window);
|
|
@@ -336,7 +336,7 @@ var f = function(t2) {
|
|
|
336
336
|
}
|
|
337
337
|
}, U = function(o2) {
|
|
338
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,
|
|
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
340
|
try {
|
|
341
341
|
if (typeof window != "undefined" && "AbortController" in window)
|
|
342
342
|
return function() {
|
|
@@ -349,18 +349,21 @@ var f = function(t2) {
|
|
|
349
349
|
} catch (t3) {
|
|
350
350
|
console.error('Unleash failed to resolve "AbortController" factory', t3);
|
|
351
351
|
}
|
|
352
|
-
}() :
|
|
353
|
-
if (
|
|
352
|
+
}() : O2, N2 = t2.bootstrap, U2 = t2.bootstrapOverride, D = U2 === void 0 || U2, j = t2.headerName, C = j === void 0 ? "Authorization" : j, P = t2.customHeaders, L = P === void 0 ? {} : P, H = t2.impressionDataAll, M = H !== void 0 && H, _ = t2.usePOSTrequests, F = _ !== void 0 && _, K = t2.experimental, V = o2.call(this) || this;
|
|
353
|
+
if (V.toggles = [], V.etag = "", V.readyEventEmitted = false, V.fetchedFromServer = false, V.usePOSTrequests = false, V.started = false, !n2)
|
|
354
354
|
throw new Error("url is required");
|
|
355
355
|
if (!i3)
|
|
356
356
|
throw new Error("clientKey is required");
|
|
357
|
-
if (!
|
|
357
|
+
if (!b2)
|
|
358
358
|
throw new Error("appName is required.");
|
|
359
|
-
return
|
|
360
|
-
|
|
361
|
-
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();
|
|
362
362
|
});
|
|
363
|
-
}),
|
|
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;
|
|
364
367
|
}
|
|
365
368
|
return function(e2, r2) {
|
|
366
369
|
if (typeof r2 != "function" && r2 !== null)
|
|
@@ -381,8 +384,8 @@ var f = function(t2) {
|
|
|
381
384
|
return e3.name === t2;
|
|
382
385
|
}), n2 = !!r2 && r2.enabled;
|
|
383
386
|
if (this.metrics.count(t2, n2), (r2 == null ? void 0 : r2.impressionData) || this.impressionDataAll) {
|
|
384
|
-
var o3 = this.eventsHandler.createImpressionEvent(this.context, n2, t2,
|
|
385
|
-
this.emit(
|
|
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);
|
|
386
389
|
}
|
|
387
390
|
return n2;
|
|
388
391
|
}, i2.prototype.getVariant = function(t2) {
|
|
@@ -391,7 +394,7 @@ var f = function(t2) {
|
|
|
391
394
|
}), o3 = (n2 == null ? void 0 : n2.enabled) || false, i3 = n2 ? n2.variant : O;
|
|
392
395
|
if (i3.name && this.metrics.countVariant(t2, i3.name), this.metrics.count(t2, o3), (n2 == null ? void 0 : n2.impressionData) || this.impressionDataAll) {
|
|
393
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);
|
|
394
|
-
this.emit(
|
|
397
|
+
this.emit(S.IMPRESSION, s2);
|
|
395
398
|
}
|
|
396
399
|
return e(e({}, i3), { feature_enabled: o3 });
|
|
397
400
|
}, i2.prototype.updateToggles = function() {
|
|
@@ -407,10 +410,10 @@ var f = function(t2) {
|
|
|
407
410
|
return this.started ? [4, new Promise(function(e3) {
|
|
408
411
|
var r2 = function() {
|
|
409
412
|
t2.fetchToggles().then(function() {
|
|
410
|
-
t2.off(
|
|
413
|
+
t2.off(S.READY, r2), e3();
|
|
411
414
|
});
|
|
412
415
|
};
|
|
413
|
-
t2.once(
|
|
416
|
+
t2.once(S.READY, r2);
|
|
414
417
|
})] : [3, 4];
|
|
415
418
|
case 3:
|
|
416
419
|
e2.sent(), e2.label = 4;
|
|
@@ -435,7 +438,7 @@ var f = function(t2) {
|
|
|
435
438
|
return e({}, this.context);
|
|
436
439
|
}, i2.prototype.setContextField = function(t2, r2) {
|
|
437
440
|
var n2, o3;
|
|
438
|
-
if (
|
|
441
|
+
if (E(t2))
|
|
439
442
|
this.context = e(e({}, this.context), ((n2 = {})[t2] = r2, n2));
|
|
440
443
|
else {
|
|
441
444
|
var i3 = e(e({}, this.context.properties), ((o3 = {})[t2] = r2, o3));
|
|
@@ -444,9 +447,9 @@ var f = function(t2) {
|
|
|
444
447
|
this.updateToggles();
|
|
445
448
|
}, i2.prototype.removeContextField = function(t2) {
|
|
446
449
|
var r2;
|
|
447
|
-
|
|
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();
|
|
448
451
|
}, i2.prototype.setReady = function() {
|
|
449
|
-
this.readyEventEmitted = true, this.emit(
|
|
452
|
+
this.readyEventEmitted = true, this.emit(S.READY);
|
|
450
453
|
}, i2.prototype.init = function() {
|
|
451
454
|
return r(this, void 0, void 0, function() {
|
|
452
455
|
var t2, r2, o3;
|
|
@@ -465,7 +468,7 @@ var f = function(t2) {
|
|
|
465
468
|
case 5:
|
|
466
469
|
n2.sent(), this.setReady(), n2.label = 6;
|
|
467
470
|
case 6:
|
|
468
|
-
return this.sdkState = "healthy", this.emit(
|
|
471
|
+
return this.sdkState = "healthy", this.emit(S.INIT), [2];
|
|
469
472
|
}
|
|
470
473
|
});
|
|
471
474
|
});
|
|
@@ -510,8 +513,8 @@ var f = function(t2) {
|
|
|
510
513
|
});
|
|
511
514
|
});
|
|
512
515
|
}, i2.prototype.getHeaders = function() {
|
|
513
|
-
var t2, e2 = this.usePOSTrequests, r2 = ((t2 = {})[this.headerName] = this.clientKey, t2.Accept = "application/json", t2["x-unleash-sdk"] =
|
|
514
|
-
return e2 && (r2["Content-Type"] = "application/json"), this.etag && (r2["If-None-Match"] = this.etag), Object.entries(this.customHeaders).filter(
|
|
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) {
|
|
515
518
|
var e3 = t3[0], n2 = t3[1];
|
|
516
519
|
return r2[e3] = n2;
|
|
517
520
|
}), r2;
|
|
@@ -520,7 +523,7 @@ var f = function(t2) {
|
|
|
520
523
|
return n(this, function(e2) {
|
|
521
524
|
switch (e2.label) {
|
|
522
525
|
case 0:
|
|
523
|
-
return this.toggles = t2, this.emit(
|
|
526
|
+
return this.toggles = t2, this.emit(S.UPDATE), [4, this.storage.save(k, t2)];
|
|
524
527
|
case 1:
|
|
525
528
|
return e2.sent(), [2];
|
|
526
529
|
}
|
|
@@ -543,7 +546,7 @@ var f = function(t2) {
|
|
|
543
546
|
case 0:
|
|
544
547
|
return this.isTogglesStorageTTLEnabled() ? [4, this.storage.get(N)] : [3, 3];
|
|
545
548
|
case 1:
|
|
546
|
-
return t2 = r2.sent(), [4,
|
|
549
|
+
return t2 = r2.sent(), [4, u(this.context)];
|
|
547
550
|
case 2:
|
|
548
551
|
return e2 = r2.sent(), [2, (t2 == null ? void 0 : t2.key) === e2 ? t2.timestamp : 0];
|
|
549
552
|
case 3:
|
|
@@ -557,7 +560,7 @@ var f = function(t2) {
|
|
|
557
560
|
return n(this, function(r2) {
|
|
558
561
|
switch (r2.label) {
|
|
559
562
|
case 0:
|
|
560
|
-
return this.isTogglesStorageTTLEnabled() ? (this.lastRefreshTimestamp = Date.now(), e2 = {}, [4,
|
|
563
|
+
return this.isTogglesStorageTTLEnabled() ? (this.lastRefreshTimestamp = Date.now(), e2 = {}, [4, u(this.context)]) : [3, 3];
|
|
561
564
|
case 1:
|
|
562
565
|
return e2.key = r2.sent(), e2.timestamp = this.lastRefreshTimestamp, t2 = e2, [4, this.storage.save(N, t2)];
|
|
563
566
|
case 2:
|
|
@@ -573,36 +576,36 @@ var f = function(t2) {
|
|
|
573
576
|
this.fetchedFromServer || (this.fetchedFromServer = true, this.setReady());
|
|
574
577
|
}, i2.prototype.fetchToggles = function() {
|
|
575
578
|
return r(this, void 0, void 0, function() {
|
|
576
|
-
var t2, e2, r2, o3, i3, s2,
|
|
579
|
+
var t2, e2, r2, o3, i3, s2, c2, u2, l2;
|
|
577
580
|
return n(this, function(n2) {
|
|
578
581
|
switch (n2.label) {
|
|
579
582
|
case 0:
|
|
580
583
|
if (!this.fetch)
|
|
581
584
|
return [3, 9];
|
|
582
|
-
this.abortController && this.abortController.abort(), this.abortController = (
|
|
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;
|
|
583
586
|
case 1:
|
|
584
587
|
return n2.trys.push([1, 7, 8, 9]), e2 = this.usePOSTrequests, r2 = e2 ? this.url : function(t3, e3) {
|
|
585
588
|
var r3 = new URL(t3.toString());
|
|
586
|
-
return Object.entries(e3).filter(
|
|
589
|
+
return Object.entries(e3).filter(a).forEach(function(t4) {
|
|
587
590
|
var e4 = t4[0], n3 = t4[1];
|
|
588
|
-
e4 === "properties" && n3 ? Object.entries(n3).filter(
|
|
591
|
+
e4 === "properties" && n3 ? Object.entries(n3).filter(a).forEach(function(t5) {
|
|
589
592
|
var e5 = t5[0], n4 = t5[1];
|
|
590
593
|
return r3.searchParams.append("properties[".concat(e5, "]"), n4);
|
|
591
594
|
}) : r3.searchParams.append(e4, n3);
|
|
592
595
|
}), r3;
|
|
593
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 })];
|
|
594
597
|
case 2:
|
|
595
|
-
return s2 = n2.sent(), this.sdkState === "error" && s2.status < 400 && (this.sdkState = "healthy", this.emit(
|
|
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];
|
|
596
599
|
case 3:
|
|
597
|
-
return
|
|
600
|
+
return c2 = n2.sent(), [4, this.storeToggles(c2.toggles)];
|
|
598
601
|
case 4:
|
|
599
602
|
return n2.sent(), this.sdkState !== "healthy" && (this.sdkState = "healthy"), this.fetchedFromServer || (this.fetchedFromServer = true, this.setReady()), this.storeLastRefreshTimestamp(), [3, 6];
|
|
600
603
|
case 5:
|
|
601
|
-
s2.status === 304 ? this.storeLastRefreshTimestamp() : (console.error("Unleash: Fetching feature toggles did not have an ok response"), this.sdkState = "error", this.emit(
|
|
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;
|
|
602
605
|
case 6:
|
|
603
606
|
return [3, 9];
|
|
604
607
|
case 7:
|
|
605
|
-
return typeof (
|
|
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];
|
|
606
609
|
case 8:
|
|
607
610
|
return this.abortController = null, [7];
|
|
608
611
|
case 9:
|
|
@@ -773,4 +776,4 @@ const plugin = {
|
|
|
773
776
|
start();
|
|
774
777
|
}
|
|
775
778
|
};
|
|
776
|
-
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(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
|
|
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"}})});
|
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.7.
|
|
36
|
+
"unleash-proxy-client": "^3.7.2",
|
|
37
37
|
"vue": "^3.2.45"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|