@unleash/proxy-client-vue 0.0.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,1565 +1,479 @@
1
1
  import { toRefs, ref, reactive, defineComponent, provide, onMounted, renderSlot, inject, onUnmounted } from "vue";
2
- var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
3
- function getAugmentedNamespace(n) {
4
- if (n.__esModule)
5
- return n;
6
- var a = Object.defineProperty({}, "__esModule", { value: true });
7
- Object.keys(n).forEach(function(k) {
8
- var d = Object.getOwnPropertyDescriptor(n, k);
9
- Object.defineProperty(a, k, d.get ? d : {
10
- enumerable: true,
11
- get: function() {
12
- return n[k];
13
- }
14
- });
15
- });
16
- return a;
17
- }
18
- var build = {};
19
- var tinyEmitter = { exports: {} };
20
- function E() {
21
- }
22
- E.prototype = {
23
- on: function(name, callback, ctx) {
24
- var e = this.e || (this.e = {});
25
- (e[name] || (e[name] = [])).push({
26
- fn: callback,
27
- ctx
28
- });
29
- return this;
30
- },
31
- once: function(name, callback, ctx) {
32
- var self2 = this;
33
- function listener() {
34
- self2.off(name, listener);
35
- callback.apply(ctx, arguments);
36
- }
37
- listener._ = callback;
38
- return this.on(name, listener, ctx);
39
- },
40
- emit: function(name) {
41
- var data = [].slice.call(arguments, 1);
42
- var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
43
- var i = 0;
44
- var len = evtArr.length;
45
- for (i; i < len; i++) {
46
- evtArr[i].fn.apply(evtArr[i].ctx, data);
47
- }
48
- return this;
49
- },
50
- off: function(name, callback) {
51
- var e = this.e || (this.e = {});
52
- var evts = e[name];
53
- var liveEvents = [];
54
- if (evts && callback) {
55
- for (var i = 0, len = evts.length; i < len; i++) {
56
- if (evts[i].fn !== callback && evts[i].fn._ !== callback)
57
- liveEvents.push(evts[i]);
58
- }
59
- }
60
- liveEvents.length ? e[name] = liveEvents : delete e[name];
61
- return this;
62
- }
2
+ var t = function(e2, n2) {
3
+ return t = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t2, e3) {
4
+ t2.__proto__ = e3;
5
+ } || function(t2, e3) {
6
+ for (var n3 in e3)
7
+ Object.prototype.hasOwnProperty.call(e3, n3) && (t2[n3] = e3[n3]);
8
+ }, t(e2, n2);
63
9
  };
64
- tinyEmitter.exports = E;
65
- tinyEmitter.exports.TinyEmitter = E;
66
- var metrics = {};
67
- var util = {};
68
- (function(exports) {
69
- Object.defineProperty(exports, "__esModule", { value: true });
70
- exports.urlWithContextAsQuery = exports.notNullOrUndefined = void 0;
71
- var notNullOrUndefined = function(_a) {
72
- var value = _a[1];
73
- return value !== void 0 && value !== null;
74
- };
75
- exports.notNullOrUndefined = notNullOrUndefined;
76
- var urlWithContextAsQuery = function(url, context) {
77
- var urlWithQuery = new URL(url.toString());
78
- Object.entries(context).filter(exports.notNullOrUndefined).forEach(function(_a) {
79
- var contextKey = _a[0], contextValue = _a[1];
80
- if (contextKey === "properties" && contextValue) {
81
- Object.entries(contextValue).filter(exports.notNullOrUndefined).forEach(function(_a2) {
82
- var propertyKey = _a2[0], propertyValue = _a2[1];
83
- return urlWithQuery.searchParams.append("properties[".concat(propertyKey, "]"), propertyValue);
84
- });
85
- } else {
86
- urlWithQuery.searchParams.append(contextKey, contextValue);
87
- }
88
- });
89
- return urlWithQuery;
90
- };
91
- exports.urlWithContextAsQuery = urlWithContextAsQuery;
92
- })(util);
93
- var __assign$1 = commonjsGlobal && commonjsGlobal.__assign || function() {
94
- __assign$1 = Object.assign || function(t) {
95
- for (var s, i = 1, n = arguments.length; i < n; i++) {
96
- s = arguments[i];
97
- for (var p in s)
98
- if (Object.prototype.hasOwnProperty.call(s, p))
99
- t[p] = s[p];
100
- }
101
- return t;
102
- };
103
- return __assign$1.apply(this, arguments);
10
+ var e = function() {
11
+ return e = Object.assign || function(t2) {
12
+ for (var e2, n2 = 1, r2 = arguments.length; n2 < r2; n2++)
13
+ for (var i2 in e2 = arguments[n2])
14
+ Object.prototype.hasOwnProperty.call(e2, i2) && (t2[i2] = e2[i2]);
15
+ return t2;
16
+ }, e.apply(this, arguments);
104
17
  };
105
- var __awaiter$2 = commonjsGlobal && commonjsGlobal.__awaiter || function(thisArg, _arguments, P, generator) {
106
- function adopt(value) {
107
- return value instanceof P ? value : new P(function(resolve) {
108
- resolve(value);
109
- });
110
- }
111
- return new (P || (P = Promise))(function(resolve, reject) {
112
- function fulfilled(value) {
18
+ function n(t2, e2, n2, r2) {
19
+ return new (n2 || (n2 = Promise))(function(i2, o2) {
20
+ function s2(t3) {
113
21
  try {
114
- step(generator.next(value));
115
- } catch (e) {
116
- reject(e);
22
+ c2(r2.next(t3));
23
+ } catch (t4) {
24
+ o2(t4);
117
25
  }
118
26
  }
119
- function rejected(value) {
27
+ function a2(t3) {
120
28
  try {
121
- step(generator["throw"](value));
122
- } catch (e) {
123
- reject(e);
29
+ c2(r2.throw(t3));
30
+ } catch (t4) {
31
+ o2(t4);
124
32
  }
125
33
  }
126
- function step(result) {
127
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
34
+ function c2(t3) {
35
+ var e3;
36
+ t3.done ? i2(t3.value) : (e3 = t3.value, e3 instanceof n2 ? e3 : new n2(function(t4) {
37
+ t4(e3);
38
+ })).then(s2, a2);
128
39
  }
129
- step((generator = generator.apply(thisArg, _arguments || [])).next());
40
+ c2((r2 = r2.apply(t2, e2 || [])).next());
130
41
  });
131
- };
132
- var __generator$2 = commonjsGlobal && commonjsGlobal.__generator || function(thisArg, body) {
133
- var _ = { label: 0, sent: function() {
134
- if (t[0] & 1)
135
- throw t[1];
136
- return t[1];
137
- }, trys: [], ops: [] }, f2, y, t, g;
138
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
42
+ }
43
+ function r(t2, e2) {
44
+ var n2, r2, i2, o2, s2 = { label: 0, sent: function() {
45
+ if (1 & i2[0])
46
+ throw i2[1];
47
+ return i2[1];
48
+ }, trys: [], ops: [] };
49
+ return o2 = { next: a2(0), throw: a2(1), return: a2(2) }, typeof Symbol == "function" && (o2[Symbol.iterator] = function() {
139
50
  return this;
140
- }), g;
141
- function verb(n) {
142
- return function(v) {
143
- return step([n, v]);
144
- };
145
- }
146
- function step(op) {
147
- if (f2)
148
- throw new TypeError("Generator is already executing.");
149
- while (_)
150
- try {
151
- if (f2 = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
152
- return t;
153
- if (y = 0, t)
154
- op = [op[0] & 2, t.value];
155
- switch (op[0]) {
156
- case 0:
157
- case 1:
158
- t = op;
159
- break;
160
- case 4:
161
- _.label++;
162
- return { value: op[1], done: false };
163
- case 5:
164
- _.label++;
165
- y = op[1];
166
- op = [0];
167
- continue;
168
- case 7:
169
- op = _.ops.pop();
170
- _.trys.pop();
171
- continue;
172
- default:
173
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
174
- _ = 0;
175
- continue;
176
- }
177
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
178
- _.label = op[1];
179
- break;
180
- }
181
- if (op[0] === 6 && _.label < t[1]) {
182
- _.label = t[1];
183
- t = op;
184
- break;
185
- }
186
- if (t && _.label < t[2]) {
187
- _.label = t[2];
188
- _.ops.push(op);
189
- break;
51
+ }), o2;
52
+ function a2(a3) {
53
+ return function(c2) {
54
+ return function(a4) {
55
+ if (n2)
56
+ throw new TypeError("Generator is already executing.");
57
+ for (; o2 && (o2 = 0, a4[0] && (s2 = 0)), s2; )
58
+ try {
59
+ if (n2 = 1, r2 && (i2 = 2 & a4[0] ? r2.return : a4[0] ? r2.throw || ((i2 = r2.return) && i2.call(r2), 0) : r2.next) && !(i2 = i2.call(r2, a4[1])).done)
60
+ return i2;
61
+ switch (r2 = 0, i2 && (a4 = [2 & a4[0], i2.value]), a4[0]) {
62
+ case 0:
63
+ case 1:
64
+ i2 = a4;
65
+ break;
66
+ case 4:
67
+ return s2.label++, { value: a4[1], done: false };
68
+ case 5:
69
+ s2.label++, r2 = a4[1], a4 = [0];
70
+ continue;
71
+ case 7:
72
+ a4 = s2.ops.pop(), s2.trys.pop();
73
+ continue;
74
+ default:
75
+ if (!(i2 = s2.trys, (i2 = i2.length > 0 && i2[i2.length - 1]) || a4[0] !== 6 && a4[0] !== 2)) {
76
+ s2 = 0;
77
+ continue;
78
+ }
79
+ if (a4[0] === 3 && (!i2 || a4[1] > i2[0] && a4[1] < i2[3])) {
80
+ s2.label = a4[1];
81
+ break;
82
+ }
83
+ if (a4[0] === 6 && s2.label < i2[1]) {
84
+ s2.label = i2[1], i2 = a4;
85
+ break;
86
+ }
87
+ if (i2 && s2.label < i2[2]) {
88
+ s2.label = i2[2], s2.ops.push(a4);
89
+ break;
90
+ }
91
+ i2[2] && s2.ops.pop(), s2.trys.pop();
92
+ continue;
190
93
  }
191
- if (t[2])
192
- _.ops.pop();
193
- _.trys.pop();
194
- continue;
195
- }
196
- op = body.call(thisArg, _);
197
- } catch (e) {
198
- op = [6, e];
199
- y = 0;
200
- } finally {
201
- f2 = t = 0;
202
- }
203
- if (op[0] & 5)
204
- throw op[1];
205
- return { value: op[0] ? op[1] : void 0, done: true };
206
- }
207
- };
208
- Object.defineProperty(metrics, "__esModule", { value: true });
209
- var util_1 = util;
210
- var doNothing = function() {
211
- };
212
- var Metrics = function() {
213
- function Metrics2(_a) {
214
- var onError = _a.onError, onSent = _a.onSent, appName = _a.appName, metricsInterval = _a.metricsInterval, _b = _a.disableMetrics, disableMetrics = _b === void 0 ? false : _b, url = _a.url, clientKey = _a.clientKey, fetch2 = _a.fetch, headerName = _a.headerName, _c = _a.customHeaders, customHeaders = _c === void 0 ? {} : _c;
215
- this.onError = onError;
216
- this.onSent = onSent || doNothing;
217
- this.disabled = disableMetrics;
218
- this.metricsInterval = metricsInterval * 1e3;
219
- this.appName = appName;
220
- this.url = url instanceof URL ? url : new URL(url);
221
- this.clientKey = clientKey;
222
- this.bucket = this.createEmptyBucket();
223
- this.fetch = fetch2;
224
- this.headerName = headerName;
225
- this.customHeaders = customHeaders;
94
+ a4 = e2.call(t2, s2);
95
+ } catch (t3) {
96
+ a4 = [6, t3], r2 = 0;
97
+ } finally {
98
+ n2 = i2 = 0;
99
+ }
100
+ if (5 & a4[0])
101
+ throw a4[1];
102
+ return { value: a4[0] ? a4[1] : void 0, done: true };
103
+ }([a3, c2]);
104
+ };
226
105
  }
227
- Metrics2.prototype.start = function() {
228
- var _this = this;
229
- if (this.disabled) {
106
+ }
107
+ typeof SuppressedError == "function" && SuppressedError;
108
+ var i = { exports: {} };
109
+ function o() {
110
+ }
111
+ o.prototype = { on: function(t2, e2, n2) {
112
+ var r2 = this.e || (this.e = {});
113
+ return (r2[t2] || (r2[t2] = [])).push({ fn: e2, ctx: n2 }), this;
114
+ }, once: function(t2, e2, n2) {
115
+ var r2 = this;
116
+ function i2() {
117
+ r2.off(t2, i2), e2.apply(n2, arguments);
118
+ }
119
+ return i2._ = e2, this.on(t2, i2, n2);
120
+ }, emit: function(t2) {
121
+ for (var e2 = [].slice.call(arguments, 1), n2 = ((this.e || (this.e = {}))[t2] || []).slice(), r2 = 0, i2 = n2.length; r2 < i2; r2++)
122
+ n2[r2].fn.apply(n2[r2].ctx, e2);
123
+ return this;
124
+ }, off: function(t2, e2) {
125
+ var n2 = this.e || (this.e = {}), r2 = n2[t2], i2 = [];
126
+ if (r2 && e2)
127
+ for (var o2 = 0, s2 = r2.length; o2 < s2; o2++)
128
+ r2[o2].fn !== e2 && r2[o2].fn._ !== e2 && i2.push(r2[o2]);
129
+ return i2.length ? n2[t2] = i2 : delete n2[t2], this;
130
+ } }, i.exports = o;
131
+ var s = i.exports.TinyEmitter = o, a = function(t2) {
132
+ var e2 = t2[1];
133
+ return e2 != null;
134
+ }, c = function() {
135
+ }, u = function() {
136
+ function t2(t3) {
137
+ var e2 = t3.onError, n2 = t3.onSent, r2 = t3.appName, i2 = t3.metricsInterval, o2 = t3.disableMetrics, s2 = o2 !== void 0 && o2, a2 = t3.url, u2 = t3.clientKey, h2 = t3.fetch, l2 = t3.headerName, p2 = t3.customHeaders, f2 = p2 === void 0 ? {} : p2;
138
+ this.onError = e2, this.onSent = n2 || c, this.disabled = s2, this.metricsInterval = 1e3 * i2, this.appName = r2, this.url = a2 instanceof URL ? a2 : new URL(a2), this.clientKey = u2, this.bucket = this.createEmptyBucket(), this.fetch = h2, this.headerName = l2, this.customHeaders = f2;
139
+ }
140
+ return t2.prototype.start = function() {
141
+ var t3 = this;
142
+ if (this.disabled)
230
143
  return false;
231
- }
232
- if (typeof this.metricsInterval === "number" && this.metricsInterval > 0) {
233
- setTimeout(function() {
234
- _this.startTimer();
235
- _this.sendMetrics();
236
- }, 2e3);
237
- }
238
- };
239
- Metrics2.prototype.stop = function() {
240
- if (this.timer) {
241
- clearTimeout(this.timer);
242
- delete this.timer;
243
- }
244
- };
245
- Metrics2.prototype.createEmptyBucket = function() {
246
- return {
247
- start: new Date(),
248
- stop: null,
249
- toggles: {}
250
- };
251
- };
252
- Metrics2.prototype.getHeaders = function() {
253
- var _a;
254
- var headers = (_a = {}, _a[this.headerName] = this.clientKey, _a.Accept = "application/json", _a["Content-Type"] = "application/json", _a);
255
- Object.entries(this.customHeaders).filter(util_1.notNullOrUndefined).forEach(function(_a2) {
256
- var name = _a2[0], value = _a2[1];
257
- return headers[name] = value;
258
- });
259
- return headers;
260
- };
261
- Metrics2.prototype.sendMetrics = function() {
262
- return __awaiter$2(this, void 0, void 0, function() {
263
- var url, payload, e_1;
264
- return __generator$2(this, function(_a) {
265
- switch (_a.label) {
144
+ typeof this.metricsInterval == "number" && this.metricsInterval > 0 && setTimeout(function() {
145
+ t3.startTimer(), t3.sendMetrics();
146
+ }, 2e3);
147
+ }, t2.prototype.stop = function() {
148
+ this.timer && (clearTimeout(this.timer), delete this.timer);
149
+ }, t2.prototype.createEmptyBucket = function() {
150
+ return { start: new Date(), stop: null, toggles: {} };
151
+ }, t2.prototype.getHeaders = function() {
152
+ var t3, e2 = ((t3 = {})[this.headerName] = this.clientKey, t3.Accept = "application/json", t3["Content-Type"] = "application/json", t3);
153
+ return Object.entries(this.customHeaders).filter(a).forEach(function(t4) {
154
+ var n2 = t4[0], r2 = t4[1];
155
+ return e2[n2] = r2;
156
+ }), e2;
157
+ }, t2.prototype.sendMetrics = function() {
158
+ return n(this, void 0, void 0, function() {
159
+ var t3, e2, n2;
160
+ return r(this, function(r2) {
161
+ switch (r2.label) {
266
162
  case 0:
267
- url = "".concat(this.url, "/client/metrics");
268
- payload = this.getPayload();
269
- if (this.bucketIsEmpty(payload)) {
163
+ if (t3 = "".concat(this.url, "/client/metrics"), e2 = this.getPayload(), this.bucketIsEmpty(e2))
270
164
  return [2];
271
- }
272
- _a.label = 1;
165
+ r2.label = 1;
273
166
  case 1:
274
- _a.trys.push([1, 3, , 4]);
275
- return [4, this.fetch(url, {
276
- cache: "no-cache",
277
- method: "POST",
278
- headers: this.getHeaders(),
279
- body: JSON.stringify(payload)
280
- })];
167
+ return r2.trys.push([1, 3, , 4]), [4, this.fetch(t3, { cache: "no-cache", method: "POST", headers: this.getHeaders(), body: JSON.stringify(e2) })];
281
168
  case 2:
282
- _a.sent();
283
- this.onSent(payload);
284
- return [3, 4];
169
+ return r2.sent(), this.onSent(e2), [3, 4];
285
170
  case 3:
286
- e_1 = _a.sent();
287
- console.error("Unleash: unable to send feature metrics", e_1);
288
- this.onError(e_1);
289
- return [3, 4];
171
+ return n2 = r2.sent(), console.error("Unleash: unable to send feature metrics", n2), this.onError(n2), [3, 4];
290
172
  case 4:
291
173
  return [2];
292
174
  }
293
175
  });
294
176
  });
295
- };
296
- Metrics2.prototype.count = function(name, enabled) {
297
- if (this.disabled || !this.bucket) {
177
+ }, t2.prototype.count = function(t3, e2) {
178
+ return !(this.disabled || !this.bucket) && (this.assertBucket(t3), this.bucket.toggles[t3][e2 ? "yes" : "no"]++, true);
179
+ }, t2.prototype.countVariant = function(t3, e2) {
180
+ return !(this.disabled || !this.bucket) && (this.assertBucket(t3), this.bucket.toggles[t3].variants[e2] ? this.bucket.toggles[t3].variants[e2] += 1 : this.bucket.toggles[t3].variants[e2] = 1, true);
181
+ }, t2.prototype.assertBucket = function(t3) {
182
+ if (this.disabled || !this.bucket)
298
183
  return false;
299
- }
300
- this.assertBucket(name);
301
- this.bucket.toggles[name][enabled ? "yes" : "no"]++;
302
- return true;
303
- };
304
- Metrics2.prototype.countVariant = function(name, variant) {
305
- if (this.disabled || !this.bucket) {
306
- return false;
307
- }
308
- this.assertBucket(name);
309
- if (this.bucket.toggles[name].variants[variant]) {
310
- this.bucket.toggles[name].variants[variant] += 1;
311
- } else {
312
- this.bucket.toggles[name].variants[variant] = 1;
313
- }
314
- return true;
315
- };
316
- Metrics2.prototype.assertBucket = function(name) {
317
- if (this.disabled || !this.bucket) {
318
- return false;
319
- }
320
- if (!this.bucket.toggles[name]) {
321
- this.bucket.toggles[name] = {
322
- yes: 0,
323
- no: 0,
324
- variants: {}
325
- };
326
- }
327
- };
328
- Metrics2.prototype.startTimer = function() {
329
- var _this = this;
184
+ this.bucket.toggles[t3] || (this.bucket.toggles[t3] = { yes: 0, no: 0, variants: {} });
185
+ }, t2.prototype.startTimer = function() {
186
+ var t3 = this;
330
187
  this.timer = setInterval(function() {
331
- _this.sendMetrics();
188
+ t3.sendMetrics();
332
189
  }, this.metricsInterval);
333
- };
334
- Metrics2.prototype.bucketIsEmpty = function(payload) {
335
- return Object.keys(payload.bucket.toggles).length === 0;
336
- };
337
- Metrics2.prototype.getPayload = function() {
338
- var bucket = __assign$1(__assign$1({}, this.bucket), { stop: new Date() });
339
- this.bucket = this.createEmptyBucket();
340
- return {
341
- bucket,
342
- appName: this.appName,
343
- instanceId: "browser"
344
- };
345
- };
346
- return Metrics2;
347
- }();
348
- metrics.default = Metrics;
349
- var storageProviderInmemory = {};
350
- var __awaiter$1 = commonjsGlobal && commonjsGlobal.__awaiter || function(thisArg, _arguments, P, generator) {
351
- function adopt(value) {
352
- return value instanceof P ? value : new P(function(resolve) {
353
- resolve(value);
354
- });
355
- }
356
- return new (P || (P = Promise))(function(resolve, reject) {
357
- function fulfilled(value) {
358
- try {
359
- step(generator.next(value));
360
- } catch (e) {
361
- reject(e);
362
- }
363
- }
364
- function rejected(value) {
365
- try {
366
- step(generator["throw"](value));
367
- } catch (e) {
368
- reject(e);
369
- }
370
- }
371
- function step(result) {
372
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
373
- }
374
- step((generator = generator.apply(thisArg, _arguments || [])).next());
375
- });
376
- };
377
- var __generator$1 = commonjsGlobal && commonjsGlobal.__generator || function(thisArg, body) {
378
- var _ = { label: 0, sent: function() {
379
- if (t[0] & 1)
380
- throw t[1];
381
- return t[1];
382
- }, trys: [], ops: [] }, f2, y, t, g;
383
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
384
- return this;
385
- }), g;
386
- function verb(n) {
387
- return function(v) {
388
- return step([n, v]);
389
- };
390
- }
391
- function step(op) {
392
- if (f2)
393
- throw new TypeError("Generator is already executing.");
394
- while (_)
395
- try {
396
- if (f2 = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
397
- return t;
398
- if (y = 0, t)
399
- op = [op[0] & 2, t.value];
400
- switch (op[0]) {
401
- case 0:
402
- case 1:
403
- t = op;
404
- break;
405
- case 4:
406
- _.label++;
407
- return { value: op[1], done: false };
408
- case 5:
409
- _.label++;
410
- y = op[1];
411
- op = [0];
412
- continue;
413
- case 7:
414
- op = _.ops.pop();
415
- _.trys.pop();
416
- continue;
417
- default:
418
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
419
- _ = 0;
420
- continue;
421
- }
422
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
423
- _.label = op[1];
424
- break;
425
- }
426
- if (op[0] === 6 && _.label < t[1]) {
427
- _.label = t[1];
428
- t = op;
429
- break;
430
- }
431
- if (t && _.label < t[2]) {
432
- _.label = t[2];
433
- _.ops.push(op);
434
- break;
435
- }
436
- if (t[2])
437
- _.ops.pop();
438
- _.trys.pop();
439
- continue;
440
- }
441
- op = body.call(thisArg, _);
442
- } catch (e) {
443
- op = [6, e];
444
- y = 0;
445
- } finally {
446
- f2 = t = 0;
447
- }
448
- if (op[0] & 5)
449
- throw op[1];
450
- return { value: op[0] ? op[1] : void 0, done: true };
451
- }
452
- };
453
- Object.defineProperty(storageProviderInmemory, "__esModule", { value: true });
454
- var InMemoryStorageProvider = function() {
455
- function InMemoryStorageProvider2() {
190
+ }, t2.prototype.bucketIsEmpty = function(t3) {
191
+ return Object.keys(t3.bucket.toggles).length === 0;
192
+ }, t2.prototype.getPayload = function() {
193
+ var t3 = e(e({}, this.bucket), { stop: new Date() });
194
+ return this.bucket = this.createEmptyBucket(), { bucket: t3, appName: this.appName, instanceId: "browser" };
195
+ }, t2;
196
+ }(), h = function() {
197
+ function t2() {
456
198
  this.store = /* @__PURE__ */ new Map();
457
199
  }
458
- InMemoryStorageProvider2.prototype.save = function(name, data) {
459
- return __awaiter$1(this, void 0, void 0, function() {
460
- return __generator$1(this, function(_a) {
461
- this.store.set(name, data);
462
- return [2];
200
+ return t2.prototype.save = function(t3, e2) {
201
+ return n(this, void 0, void 0, function() {
202
+ return r(this, function(n2) {
203
+ return this.store.set(t3, e2), [2];
463
204
  });
464
205
  });
465
- };
466
- InMemoryStorageProvider2.prototype.get = function(name) {
467
- return __awaiter$1(this, void 0, void 0, function() {
468
- return __generator$1(this, function(_a) {
469
- return [2, this.store.get(name)];
206
+ }, t2.prototype.get = function(t3) {
207
+ return n(this, void 0, void 0, function() {
208
+ return r(this, function(e2) {
209
+ return [2, this.store.get(t3)];
470
210
  });
471
211
  });
472
- };
473
- return InMemoryStorageProvider2;
474
- }();
475
- storageProviderInmemory.default = InMemoryStorageProvider;
476
- var storageProviderLocal = {};
477
- var __awaiter = commonjsGlobal && commonjsGlobal.__awaiter || function(thisArg, _arguments, P, generator) {
478
- function adopt(value) {
479
- return value instanceof P ? value : new P(function(resolve) {
480
- resolve(value);
481
- });
482
- }
483
- return new (P || (P = Promise))(function(resolve, reject) {
484
- function fulfilled(value) {
485
- try {
486
- step(generator.next(value));
487
- } catch (e) {
488
- reject(e);
489
- }
490
- }
491
- function rejected(value) {
492
- try {
493
- step(generator["throw"](value));
494
- } catch (e) {
495
- reject(e);
496
- }
497
- }
498
- function step(result) {
499
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
500
- }
501
- step((generator = generator.apply(thisArg, _arguments || [])).next());
502
- });
503
- };
504
- var __generator = commonjsGlobal && commonjsGlobal.__generator || function(thisArg, body) {
505
- var _ = { label: 0, sent: function() {
506
- if (t[0] & 1)
507
- throw t[1];
508
- return t[1];
509
- }, trys: [], ops: [] }, f2, y, t, g;
510
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
511
- return this;
512
- }), g;
513
- function verb(n) {
514
- return function(v) {
515
- return step([n, v]);
516
- };
517
- }
518
- function step(op) {
519
- if (f2)
520
- throw new TypeError("Generator is already executing.");
521
- while (_)
522
- try {
523
- if (f2 = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
524
- return t;
525
- if (y = 0, t)
526
- op = [op[0] & 2, t.value];
527
- switch (op[0]) {
528
- case 0:
529
- case 1:
530
- t = op;
531
- break;
532
- case 4:
533
- _.label++;
534
- return { value: op[1], done: false };
535
- case 5:
536
- _.label++;
537
- y = op[1];
538
- op = [0];
539
- continue;
540
- case 7:
541
- op = _.ops.pop();
542
- _.trys.pop();
543
- continue;
544
- default:
545
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
546
- _ = 0;
547
- continue;
548
- }
549
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
550
- _.label = op[1];
551
- break;
552
- }
553
- if (op[0] === 6 && _.label < t[1]) {
554
- _.label = t[1];
555
- t = op;
556
- break;
557
- }
558
- if (t && _.label < t[2]) {
559
- _.label = t[2];
560
- _.ops.push(op);
561
- break;
562
- }
563
- if (t[2])
564
- _.ops.pop();
565
- _.trys.pop();
566
- continue;
567
- }
568
- op = body.call(thisArg, _);
569
- } catch (e) {
570
- op = [6, e];
571
- y = 0;
572
- } finally {
573
- f2 = t = 0;
574
- }
575
- if (op[0] & 5)
576
- throw op[1];
577
- return { value: op[0] ? op[1] : void 0, done: true };
578
- }
579
- };
580
- Object.defineProperty(storageProviderLocal, "__esModule", { value: true });
581
- var LocalStorageProvider = function() {
582
- function LocalStorageProvider2() {
212
+ }, t2;
213
+ }(), l = function() {
214
+ function t2() {
583
215
  this.prefix = "unleash:repository";
584
216
  }
585
- LocalStorageProvider2.prototype.save = function(name, data) {
586
- return __awaiter(this, void 0, void 0, function() {
587
- var repo, key;
588
- return __generator(this, function(_a) {
589
- repo = JSON.stringify(data);
590
- key = "".concat(this.prefix, ":").concat(name);
217
+ return t2.prototype.save = function(t3, e2) {
218
+ return n(this, void 0, void 0, function() {
219
+ var n2, i2;
220
+ return r(this, function(r2) {
221
+ n2 = JSON.stringify(e2), i2 = "".concat(this.prefix, ":").concat(t3);
591
222
  try {
592
- window.localStorage.setItem(key, repo);
593
- } catch (ex) {
594
- console.error(ex);
223
+ window.localStorage.setItem(i2, n2);
224
+ } catch (t4) {
225
+ console.error(t4);
595
226
  }
596
227
  return [2];
597
228
  });
598
229
  });
599
- };
600
- LocalStorageProvider2.prototype.get = function(name) {
230
+ }, t2.prototype.get = function(t3) {
601
231
  try {
602
- var key = "".concat(this.prefix, ":").concat(name);
603
- var data = window.localStorage.getItem(key);
604
- return data ? JSON.parse(data) : void 0;
605
- } catch (e) {
606
- console.error(e);
232
+ var e2 = "".concat(this.prefix, ":").concat(t3), n2 = window.localStorage.getItem(e2);
233
+ return n2 ? JSON.parse(n2) : void 0;
234
+ } catch (t4) {
235
+ console.error(t4);
607
236
  }
608
- };
609
- return LocalStorageProvider2;
237
+ }, t2;
610
238
  }();
611
- storageProviderLocal.default = LocalStorageProvider;
612
- var eventsHandler = {};
613
- var getRandomValues;
614
- var rnds8 = new Uint8Array(16);
615
- function rng() {
616
- if (!getRandomValues) {
617
- getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== "undefined" && typeof msCrypto.getRandomValues === "function" && msCrypto.getRandomValues.bind(msCrypto);
618
- if (!getRandomValues) {
619
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
620
- }
621
- }
622
- return getRandomValues(rnds8);
623
- }
624
- var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
625
- function validate(uuid) {
626
- return typeof uuid === "string" && REGEX.test(uuid);
239
+ let p;
240
+ const f = new Uint8Array(16);
241
+ function d() {
242
+ if (!p && (p = typeof crypto != "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !p))
243
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
244
+ return p(f);
627
245
  }
628
- var byteToHex = [];
629
- for (var i = 0; i < 256; ++i) {
630
- byteToHex.push((i + 256).toString(16).substr(1));
631
- }
632
- function stringify(arr) {
633
- var offset = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
634
- var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
635
- if (!validate(uuid)) {
636
- throw TypeError("Stringified UUID is invalid");
637
- }
638
- return uuid;
246
+ const v = [];
247
+ for (let t2 = 0; t2 < 256; ++t2)
248
+ v.push((t2 + 256).toString(16).slice(1));
249
+ var m = { randomUUID: typeof crypto != "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
250
+ function y(t2, e2, n2) {
251
+ if (m.randomUUID && !e2 && !t2)
252
+ return m.randomUUID();
253
+ const r2 = (t2 = t2 || {}).random || (t2.rng || d)();
254
+ if (r2[6] = 15 & r2[6] | 64, r2[8] = 63 & r2[8] | 128, e2) {
255
+ n2 = n2 || 0;
256
+ for (let t3 = 0; t3 < 16; ++t3)
257
+ e2[n2 + t3] = r2[t3];
258
+ return e2;
259
+ }
260
+ return function(t3, e3 = 0) {
261
+ return v[t3[e3 + 0]] + v[t3[e3 + 1]] + v[t3[e3 + 2]] + v[t3[e3 + 3]] + "-" + v[t3[e3 + 4]] + v[t3[e3 + 5]] + "-" + v[t3[e3 + 6]] + v[t3[e3 + 7]] + "-" + v[t3[e3 + 8]] + v[t3[e3 + 9]] + "-" + v[t3[e3 + 10]] + v[t3[e3 + 11]] + v[t3[e3 + 12]] + v[t3[e3 + 13]] + v[t3[e3 + 14]] + v[t3[e3 + 15]];
262
+ }(r2);
639
263
  }
640
- var _nodeId;
641
- var _clockseq;
642
- var _lastMSecs = 0;
643
- var _lastNSecs = 0;
644
- function v1(options, buf, offset) {
645
- var i = buf && offset || 0;
646
- var b = buf || new Array(16);
647
- options = options || {};
648
- var node = options.node || _nodeId;
649
- var clockseq = options.clockseq !== void 0 ? options.clockseq : _clockseq;
650
- if (node == null || clockseq == null) {
651
- var seedBytes = options.random || (options.rng || rng)();
652
- if (node == null) {
653
- node = _nodeId = [seedBytes[0] | 1, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
654
- }
655
- if (clockseq == null) {
656
- clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 16383;
657
- }
658
- }
659
- var msecs = options.msecs !== void 0 ? options.msecs : Date.now();
660
- var nsecs = options.nsecs !== void 0 ? options.nsecs : _lastNSecs + 1;
661
- var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 1e4;
662
- if (dt < 0 && options.clockseq === void 0) {
663
- clockseq = clockseq + 1 & 16383;
664
- }
665
- if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === void 0) {
666
- nsecs = 0;
667
- }
668
- if (nsecs >= 1e4) {
669
- throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
670
- }
671
- _lastMSecs = msecs;
672
- _lastNSecs = nsecs;
673
- _clockseq = clockseq;
674
- msecs += 122192928e5;
675
- var tl = ((msecs & 268435455) * 1e4 + nsecs) % 4294967296;
676
- b[i++] = tl >>> 24 & 255;
677
- b[i++] = tl >>> 16 & 255;
678
- b[i++] = tl >>> 8 & 255;
679
- b[i++] = tl & 255;
680
- var tmh = msecs / 4294967296 * 1e4 & 268435455;
681
- b[i++] = tmh >>> 8 & 255;
682
- b[i++] = tmh & 255;
683
- b[i++] = tmh >>> 24 & 15 | 16;
684
- b[i++] = tmh >>> 16 & 255;
685
- b[i++] = clockseq >>> 8 | 128;
686
- b[i++] = clockseq & 255;
687
- for (var n = 0; n < 6; ++n) {
688
- b[i + n] = node[n];
689
- }
690
- return buf || stringify(b);
691
- }
692
- function parse(uuid) {
693
- if (!validate(uuid)) {
694
- throw TypeError("Invalid UUID");
695
- }
696
- var v;
697
- var arr = new Uint8Array(16);
698
- arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
699
- arr[1] = v >>> 16 & 255;
700
- arr[2] = v >>> 8 & 255;
701
- arr[3] = v & 255;
702
- arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
703
- arr[5] = v & 255;
704
- arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
705
- arr[7] = v & 255;
706
- arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
707
- arr[9] = v & 255;
708
- arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 1099511627776 & 255;
709
- arr[11] = v / 4294967296 & 255;
710
- arr[12] = v >>> 24 & 255;
711
- arr[13] = v >>> 16 & 255;
712
- arr[14] = v >>> 8 & 255;
713
- arr[15] = v & 255;
714
- return arr;
715
- }
716
- function stringToBytes(str) {
717
- str = unescape(encodeURIComponent(str));
718
- var bytes = [];
719
- for (var i = 0; i < str.length; ++i) {
720
- bytes.push(str.charCodeAt(i));
721
- }
722
- return bytes;
723
- }
724
- var DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
725
- var URL$1 = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
726
- function v35(name, version2, hashfunc) {
727
- function generateUUID(value, namespace, buf, offset) {
728
- if (typeof value === "string") {
729
- value = stringToBytes(value);
730
- }
731
- if (typeof namespace === "string") {
732
- namespace = parse(namespace);
733
- }
734
- if (namespace.length !== 16) {
735
- throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
736
- }
737
- var bytes = new Uint8Array(16 + value.length);
738
- bytes.set(namespace);
739
- bytes.set(value, namespace.length);
740
- bytes = hashfunc(bytes);
741
- bytes[6] = bytes[6] & 15 | version2;
742
- bytes[8] = bytes[8] & 63 | 128;
743
- if (buf) {
744
- offset = offset || 0;
745
- for (var i = 0; i < 16; ++i) {
746
- buf[offset + i] = bytes[i];
747
- }
748
- return buf;
749
- }
750
- return stringify(bytes);
751
- }
264
+ var g = function() {
265
+ function t2() {
266
+ }
267
+ return t2.prototype.generateEventId = function() {
268
+ return y();
269
+ }, t2.prototype.createImpressionEvent = function(t3, n2, r2, i2, o2, s2) {
270
+ var a2 = this.createBaseEvent(t3, n2, r2, i2, o2);
271
+ return s2 ? e(e({}, a2), { variant: s2 }) : a2;
272
+ }, t2.prototype.createBaseEvent = function(t3, e2, n2, r2, i2) {
273
+ return { eventType: r2, eventId: this.generateEventId(), context: t3, enabled: e2, featureName: n2, impressionData: i2 };
274
+ }, t2;
275
+ }(), b = ["userId", "sessionId", "remoteAddress"], w = { INIT: "initialized", ERROR: "error", READY: "ready", UPDATE: "update", IMPRESSION: "impression", SENT: "sent" }, E = "isEnabled", I = "getVariant", x = { name: "disabled", enabled: false, feature_enabled: false }, R = "repo", S = function() {
752
276
  try {
753
- generateUUID.name = name;
754
- } catch (err) {
755
- }
756
- generateUUID.DNS = DNS;
757
- generateUUID.URL = URL$1;
758
- return generateUUID;
759
- }
760
- function md5(bytes) {
761
- if (typeof bytes === "string") {
762
- var msg = unescape(encodeURIComponent(bytes));
763
- bytes = new Uint8Array(msg.length);
764
- for (var i = 0; i < msg.length; ++i) {
765
- bytes[i] = msg.charCodeAt(i);
766
- }
767
- }
768
- return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8));
769
- }
770
- function md5ToHexEncodedArray(input) {
771
- var output = [];
772
- var length32 = input.length * 32;
773
- var hexTab = "0123456789abcdef";
774
- for (var i = 0; i < length32; i += 8) {
775
- var x = input[i >> 5] >>> i % 32 & 255;
776
- var hex = parseInt(hexTab.charAt(x >>> 4 & 15) + hexTab.charAt(x & 15), 16);
777
- output.push(hex);
778
- }
779
- return output;
780
- }
781
- function getOutputLength(inputLength8) {
782
- return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
783
- }
784
- function wordsToMd5(x, len) {
785
- x[len >> 5] |= 128 << len % 32;
786
- x[getOutputLength(len) - 1] = len;
787
- var a = 1732584193;
788
- var b = -271733879;
789
- var c = -1732584194;
790
- var d = 271733878;
791
- for (var i = 0; i < x.length; i += 16) {
792
- var olda = a;
793
- var oldb = b;
794
- var oldc = c;
795
- var oldd = d;
796
- a = md5ff(a, b, c, d, x[i], 7, -680876936);
797
- d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
798
- c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
799
- b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
800
- a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
801
- d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
802
- c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
803
- b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
804
- a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
805
- d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
806
- c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
807
- b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
808
- a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
809
- d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
810
- c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
811
- b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
812
- a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
813
- d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
814
- c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
815
- b = md5gg(b, c, d, a, x[i], 20, -373897302);
816
- a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
817
- d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
818
- c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
819
- b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
820
- a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
821
- d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
822
- c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
823
- b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
824
- a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
825
- d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
826
- c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
827
- b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
828
- a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
829
- d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
830
- c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
831
- b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
832
- a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
833
- d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
834
- c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
835
- b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
836
- a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
837
- d = md5hh(d, a, b, c, x[i], 11, -358537222);
838
- c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
839
- b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
840
- a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
841
- d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
842
- c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
843
- b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
844
- a = md5ii(a, b, c, d, x[i], 6, -198630844);
845
- d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
846
- c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
847
- b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
848
- a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
849
- d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
850
- c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
851
- b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
852
- a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
853
- d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
854
- c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
855
- b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
856
- a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
857
- d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
858
- c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
859
- b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
860
- a = safeAdd(a, olda);
861
- b = safeAdd(b, oldb);
862
- c = safeAdd(c, oldc);
863
- d = safeAdd(d, oldd);
864
- }
865
- return [a, b, c, d];
866
- }
867
- function bytesToWords(input) {
868
- if (input.length === 0) {
869
- return [];
870
- }
871
- var length8 = input.length * 8;
872
- var output = new Uint32Array(getOutputLength(length8));
873
- for (var i = 0; i < length8; i += 8) {
874
- output[i >> 5] |= (input[i / 8] & 255) << i % 32;
875
- }
876
- return output;
877
- }
878
- function safeAdd(x, y) {
879
- var lsw = (x & 65535) + (y & 65535);
880
- var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
881
- return msw << 16 | lsw & 65535;
882
- }
883
- function bitRotateLeft(num, cnt) {
884
- return num << cnt | num >>> 32 - cnt;
885
- }
886
- function md5cmn(q, a, b, x, s, t) {
887
- return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
888
- }
889
- function md5ff(a, b, c, d, x, s, t) {
890
- return md5cmn(b & c | ~b & d, a, b, x, s, t);
891
- }
892
- function md5gg(a, b, c, d, x, s, t) {
893
- return md5cmn(b & d | c & ~d, a, b, x, s, t);
894
- }
895
- function md5hh(a, b, c, d, x, s, t) {
896
- return md5cmn(b ^ c ^ d, a, b, x, s, t);
897
- }
898
- function md5ii(a, b, c, d, x, s, t) {
899
- return md5cmn(c ^ (b | ~d), a, b, x, s, t);
900
- }
901
- var v3 = v35("v3", 48, md5);
902
- var v3$1 = v3;
903
- function v4(options, buf, offset) {
904
- options = options || {};
905
- var rnds = options.random || (options.rng || rng)();
906
- rnds[6] = rnds[6] & 15 | 64;
907
- rnds[8] = rnds[8] & 63 | 128;
908
- if (buf) {
909
- offset = offset || 0;
910
- for (var i = 0; i < 16; ++i) {
911
- buf[offset + i] = rnds[i];
912
- }
913
- return buf;
914
- }
915
- return stringify(rnds);
916
- }
917
- function f(s, x, y, z) {
918
- switch (s) {
919
- case 0:
920
- return x & y ^ ~x & z;
921
- case 1:
922
- return x ^ y ^ z;
923
- case 2:
924
- return x & y ^ x & z ^ y & z;
925
- case 3:
926
- return x ^ y ^ z;
927
- }
928
- }
929
- function ROTL(x, n) {
930
- return x << n | x >>> 32 - n;
931
- }
932
- function sha1(bytes) {
933
- var K = [1518500249, 1859775393, 2400959708, 3395469782];
934
- var H = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
935
- if (typeof bytes === "string") {
936
- var msg = unescape(encodeURIComponent(bytes));
937
- bytes = [];
938
- for (var i = 0; i < msg.length; ++i) {
939
- bytes.push(msg.charCodeAt(i));
940
- }
941
- } else if (!Array.isArray(bytes)) {
942
- bytes = Array.prototype.slice.call(bytes);
943
- }
944
- bytes.push(128);
945
- var l = bytes.length / 4 + 2;
946
- var N = Math.ceil(l / 16);
947
- var M = new Array(N);
948
- for (var _i = 0; _i < N; ++_i) {
949
- var arr = new Uint32Array(16);
950
- for (var j = 0; j < 16; ++j) {
951
- arr[j] = bytes[_i * 64 + j * 4] << 24 | bytes[_i * 64 + j * 4 + 1] << 16 | bytes[_i * 64 + j * 4 + 2] << 8 | bytes[_i * 64 + j * 4 + 3];
952
- }
953
- M[_i] = arr;
954
- }
955
- M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
956
- M[N - 1][14] = Math.floor(M[N - 1][14]);
957
- M[N - 1][15] = (bytes.length - 1) * 8 & 4294967295;
958
- for (var _i2 = 0; _i2 < N; ++_i2) {
959
- var W = new Uint32Array(80);
960
- for (var t = 0; t < 16; ++t) {
961
- W[t] = M[_i2][t];
962
- }
963
- for (var _t = 16; _t < 80; ++_t) {
964
- W[_t] = ROTL(W[_t - 3] ^ W[_t - 8] ^ W[_t - 14] ^ W[_t - 16], 1);
965
- }
966
- var a = H[0];
967
- var b = H[1];
968
- var c = H[2];
969
- var d = H[3];
970
- var e = H[4];
971
- for (var _t2 = 0; _t2 < 80; ++_t2) {
972
- var s = Math.floor(_t2 / 20);
973
- var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[_t2] >>> 0;
974
- e = d;
975
- d = c;
976
- c = ROTL(b, 30) >>> 0;
977
- b = a;
978
- a = T;
979
- }
980
- H[0] = H[0] + a >>> 0;
981
- H[1] = H[1] + b >>> 0;
982
- H[2] = H[2] + c >>> 0;
983
- H[3] = H[3] + d >>> 0;
984
- H[4] = H[4] + e >>> 0;
985
- }
986
- return [H[0] >> 24 & 255, H[0] >> 16 & 255, H[0] >> 8 & 255, H[0] & 255, H[1] >> 24 & 255, H[1] >> 16 & 255, H[1] >> 8 & 255, H[1] & 255, H[2] >> 24 & 255, H[2] >> 16 & 255, H[2] >> 8 & 255, H[2] & 255, H[3] >> 24 & 255, H[3] >> 16 & 255, H[3] >> 8 & 255, H[3] & 255, H[4] >> 24 & 255, H[4] >> 16 & 255, H[4] >> 8 & 255, H[4] & 255];
987
- }
988
- var v5 = v35("v5", 80, sha1);
989
- var v5$1 = v5;
990
- var nil = "00000000-0000-0000-0000-000000000000";
991
- function version(uuid) {
992
- if (!validate(uuid)) {
993
- throw TypeError("Invalid UUID");
994
- }
995
- return parseInt(uuid.substr(14, 1), 16);
996
- }
997
- var esmBrowser = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
998
- __proto__: null,
999
- v1,
1000
- v3: v3$1,
1001
- v4,
1002
- v5: v5$1,
1003
- NIL: nil,
1004
- version,
1005
- validate,
1006
- stringify,
1007
- parse
1008
- }, Symbol.toStringTag, { value: "Module" }));
1009
- var require$$0 = /* @__PURE__ */ getAugmentedNamespace(esmBrowser);
1010
- var __assign = commonjsGlobal && commonjsGlobal.__assign || function() {
1011
- __assign = Object.assign || function(t) {
1012
- for (var s, i = 1, n = arguments.length; i < n; i++) {
1013
- s = arguments[i];
1014
- for (var p in s)
1015
- if (Object.prototype.hasOwnProperty.call(s, p))
1016
- t[p] = s[p];
1017
- }
1018
- return t;
1019
- };
1020
- return __assign.apply(this, arguments);
1021
- };
1022
- Object.defineProperty(eventsHandler, "__esModule", { value: true });
1023
- var uuid_1 = require$$0;
1024
- var EventsHandler = function() {
1025
- function EventsHandler2() {
1026
- }
1027
- EventsHandler2.prototype.generateEventId = function() {
1028
- return (0, uuid_1.v4)();
1029
- };
1030
- EventsHandler2.prototype.createImpressionEvent = function(context, enabled, featureName, eventType, impressionData, variant) {
1031
- var baseEvent = this.createBaseEvent(context, enabled, featureName, eventType, impressionData);
1032
- if (variant) {
1033
- return __assign(__assign({}, baseEvent), { variant });
1034
- }
1035
- return baseEvent;
1036
- };
1037
- EventsHandler2.prototype.createBaseEvent = function(context, enabled, featureName, eventType, impressionData) {
1038
- return {
1039
- eventType,
1040
- eventId: this.generateEventId(),
1041
- context,
1042
- enabled,
1043
- featureName,
1044
- impressionData
1045
- };
1046
- };
1047
- return EventsHandler2;
1048
- }();
1049
- eventsHandler.default = EventsHandler;
1050
- (function(exports) {
1051
- var __extends = commonjsGlobal && commonjsGlobal.__extends || function() {
1052
- var extendStatics = function(d, b) {
1053
- extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
1054
- d2.__proto__ = b2;
1055
- } || function(d2, b2) {
1056
- for (var p in b2)
1057
- if (Object.prototype.hasOwnProperty.call(b2, p))
1058
- d2[p] = b2[p];
1059
- };
1060
- return extendStatics(d, b);
1061
- };
1062
- return function(d, b) {
1063
- if (typeof b !== "function" && b !== null)
1064
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1065
- extendStatics(d, b);
1066
- function __() {
1067
- this.constructor = d;
1068
- }
1069
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1070
- };
1071
- }();
1072
- var __assign2 = commonjsGlobal && commonjsGlobal.__assign || function() {
1073
- __assign2 = Object.assign || function(t) {
1074
- for (var s, i = 1, n = arguments.length; i < n; i++) {
1075
- s = arguments[i];
1076
- for (var p in s)
1077
- if (Object.prototype.hasOwnProperty.call(s, p))
1078
- t[p] = s[p];
1079
- }
1080
- return t;
1081
- };
1082
- return __assign2.apply(this, arguments);
1083
- };
1084
- var __awaiter2 = commonjsGlobal && commonjsGlobal.__awaiter || function(thisArg, _arguments, P, generator) {
1085
- function adopt(value) {
1086
- return value instanceof P ? value : new P(function(resolve) {
1087
- resolve(value);
277
+ if (typeof window != "undefined" && "fetch" in window)
278
+ return fetch.bind(window);
279
+ if ("fetch" in globalThis)
280
+ return fetch.bind(globalThis);
281
+ } catch (t2) {
282
+ console.error('Unleash failed to resolve "fetch"', t2);
283
+ }
284
+ }, T = function(i2) {
285
+ function o2(t2) {
286
+ var n2 = t2.storageProvider, r2 = t2.url, o3 = t2.clientKey, s2 = t2.disableRefresh, a2 = s2 !== void 0 && s2, c2 = t2.refreshInterval, p2 = c2 === void 0 ? 30 : c2, f2 = t2.metricsInterval, d2 = f2 === void 0 ? 30 : f2, v2 = t2.disableMetrics, m2 = v2 !== void 0 && v2, y2 = t2.appName, b2 = t2.environment, E2 = b2 === void 0 ? "default" : b2, I2 = t2.context, x2 = t2.fetch, R2 = x2 === void 0 ? S() : x2, T2 = t2.bootstrap, O = t2.bootstrapOverride, N = O === void 0 || O, k = t2.headerName, D = k === void 0 ? "Authorization" : k, U = t2.customHeaders, P = U === void 0 ? {} : U, A = t2.impressionDataAll, j = A !== void 0 && A, H = t2.usePOSTrequests, M = H !== void 0 && H, _ = i2.call(this) || this;
287
+ if (_.toggles = [], _.etag = "", _.readyEventEmitted = false, _.usePOSTrequests = false, _.started = false, !r2)
288
+ throw new Error("url is required");
289
+ if (!o3)
290
+ throw new Error("clientKey is required");
291
+ if (!y2)
292
+ throw new Error("appName is required.");
293
+ return _.eventsHandler = new g(), _.impressionDataAll = j, _.toggles = T2 && T2.length > 0 ? T2 : [], _.url = r2 instanceof URL ? r2 : new URL(r2), _.clientKey = o3, _.headerName = D, _.customHeaders = P, _.storage = n2 || (typeof window != "undefined" ? new l() : new h()), _.refreshInterval = a2 ? 0 : 1e3 * p2, _.context = e({ appName: y2, environment: E2 }, I2), _.usePOSTrequests = M, _.ready = new Promise(function(t3) {
294
+ _.init().then(t3).catch(function(e2) {
295
+ console.error(e2), _.emit(w.ERROR, e2), t3();
1088
296
  });
1089
- }
1090
- return new (P || (P = Promise))(function(resolve, reject) {
1091
- function fulfilled(value) {
1092
- try {
1093
- step(generator.next(value));
1094
- } catch (e) {
1095
- reject(e);
1096
- }
1097
- }
1098
- function rejected(value) {
1099
- try {
1100
- step(generator["throw"](value));
1101
- } catch (e) {
1102
- reject(e);
297
+ }), R2 || console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'), _.fetch = R2, _.bootstrap = T2 && T2.length > 0 ? T2 : void 0, _.bootstrapOverride = N, _.metrics = new u({ onError: _.emit.bind(_, w.ERROR), onSent: _.emit.bind(_, w.SENT), appName: y2, metricsInterval: d2, disableMetrics: m2, url: _.url, clientKey: o3, fetch: R2, headerName: D, customHeaders: P }), _;
298
+ }
299
+ return function(e2, n2) {
300
+ if (typeof n2 != "function" && n2 !== null)
301
+ throw new TypeError("Class extends value " + String(n2) + " is not a constructor or null");
302
+ function r2() {
303
+ this.constructor = e2;
304
+ }
305
+ t(e2, n2), e2.prototype = n2 === null ? Object.create(n2) : (r2.prototype = n2.prototype, new r2());
306
+ }(o2, i2), o2.prototype.getAllToggles = function() {
307
+ return function(t2, e2, n2) {
308
+ if (n2 || arguments.length === 2)
309
+ for (var r2, i3 = 0, o3 = e2.length; i3 < o3; i3++)
310
+ !r2 && i3 in e2 || (r2 || (r2 = Array.prototype.slice.call(e2, 0, i3)), r2[i3] = e2[i3]);
311
+ return t2.concat(r2 || Array.prototype.slice.call(e2));
312
+ }([], this.toggles, true);
313
+ }, o2.prototype.isEnabled = function(t2) {
314
+ var e2, n2 = this.toggles.find(function(e3) {
315
+ return e3.name === t2;
316
+ }), r2 = !!n2 && n2.enabled;
317
+ if (this.metrics.count(t2, r2), (n2 == null ? void 0 : n2.impressionData) || this.impressionDataAll) {
318
+ var i3 = this.eventsHandler.createImpressionEvent(this.context, r2, t2, E, (e2 = n2 == null ? void 0 : n2.impressionData) !== null && e2 !== void 0 ? e2 : void 0);
319
+ this.emit(w.IMPRESSION, i3);
320
+ }
321
+ return r2;
322
+ }, o2.prototype.getVariant = function(t2) {
323
+ var n2, r2 = this.toggles.find(function(e2) {
324
+ return e2.name === t2;
325
+ }), i3 = (r2 == null ? void 0 : r2.enabled) || false, o3 = r2 ? r2.variant : x;
326
+ if (o3.name && this.metrics.countVariant(t2, o3.name), this.metrics.count(t2, i3), (r2 == null ? void 0 : r2.impressionData) || this.impressionDataAll) {
327
+ var s2 = this.eventsHandler.createImpressionEvent(this.context, i3, t2, I, (n2 = r2 == null ? void 0 : r2.impressionData) !== null && n2 !== void 0 ? n2 : void 0, o3.name);
328
+ this.emit(w.IMPRESSION, s2);
329
+ }
330
+ return e(e({}, o3), { feature_enabled: i3 });
331
+ }, o2.prototype.updateContext = function(t2) {
332
+ return n(this, void 0, void 0, function() {
333
+ var n2, i3 = this;
334
+ return r(this, function(r2) {
335
+ switch (r2.label) {
336
+ case 0:
337
+ return (t2.appName || t2.environment) && console.warn("appName and environment are static. They can't be updated with updateContext."), n2 = { environment: this.context.environment, appName: this.context.appName, sessionId: this.context.sessionId }, this.context = e(e({}, n2), t2), this.timerRef || this.readyEventEmitted ? [4, this.fetchToggles()] : [3, 2];
338
+ case 1:
339
+ return r2.sent(), [3, 4];
340
+ case 2:
341
+ return this.started ? [4, new Promise(function(t3) {
342
+ var e2 = function() {
343
+ i3.fetchToggles().then(function() {
344
+ i3.off(w.READY, e2), t3();
345
+ });
346
+ };
347
+ i3.once(w.READY, e2);
348
+ })] : [3, 4];
349
+ case 3:
350
+ r2.sent(), r2.label = 4;
351
+ case 4:
352
+ return [2];
1103
353
  }
1104
- }
1105
- function step(result) {
1106
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1107
- }
1108
- step((generator = generator.apply(thisArg, _arguments || [])).next());
354
+ });
1109
355
  });
1110
- };
1111
- var __generator2 = commonjsGlobal && commonjsGlobal.__generator || function(thisArg, body) {
1112
- var _ = { label: 0, sent: function() {
1113
- if (t[0] & 1)
1114
- throw t[1];
1115
- return t[1];
1116
- }, trys: [], ops: [] }, f2, y, t, g;
1117
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1118
- return this;
1119
- }), g;
1120
- function verb(n) {
1121
- return function(v) {
1122
- return step([n, v]);
1123
- };
1124
- }
1125
- function step(op) {
1126
- if (f2)
1127
- throw new TypeError("Generator is already executing.");
1128
- while (_)
1129
- try {
1130
- if (f2 = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
1131
- return t;
1132
- if (y = 0, t)
1133
- op = [op[0] & 2, t.value];
1134
- switch (op[0]) {
1135
- case 0:
1136
- case 1:
1137
- t = op;
1138
- break;
1139
- case 4:
1140
- _.label++;
1141
- return { value: op[1], done: false };
1142
- case 5:
1143
- _.label++;
1144
- y = op[1];
1145
- op = [0];
1146
- continue;
1147
- case 7:
1148
- op = _.ops.pop();
1149
- _.trys.pop();
1150
- continue;
1151
- default:
1152
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1153
- _ = 0;
1154
- continue;
1155
- }
1156
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1157
- _.label = op[1];
1158
- break;
1159
- }
1160
- if (op[0] === 6 && _.label < t[1]) {
1161
- _.label = t[1];
1162
- t = op;
1163
- break;
1164
- }
1165
- if (t && _.label < t[2]) {
1166
- _.label = t[2];
1167
- _.ops.push(op);
1168
- break;
1169
- }
1170
- if (t[2])
1171
- _.ops.pop();
1172
- _.trys.pop();
1173
- continue;
1174
- }
1175
- op = body.call(thisArg, _);
1176
- } catch (e) {
1177
- op = [6, e];
1178
- y = 0;
1179
- } finally {
1180
- f2 = t = 0;
1181
- }
1182
- if (op[0] & 5)
1183
- throw op[1];
1184
- return { value: op[0] ? op[1] : void 0, done: true };
1185
- }
1186
- };
1187
- var __spreadArray = commonjsGlobal && commonjsGlobal.__spreadArray || function(to, from, pack) {
1188
- if (pack || arguments.length === 2)
1189
- for (var i = 0, l = from.length, ar; i < l; i++) {
1190
- if (ar || !(i in from)) {
1191
- if (!ar)
1192
- ar = Array.prototype.slice.call(from, 0, i);
1193
- ar[i] = from[i];
356
+ }, o2.prototype.getContext = function() {
357
+ return e({}, this.context);
358
+ }, o2.prototype.setContextField = function(t2, n2) {
359
+ var r2, i3;
360
+ if (b.includes(t2))
361
+ this.context = e(e({}, this.context), ((r2 = {})[t2] = n2, r2));
362
+ else {
363
+ var o3 = e(e({}, this.context.properties), ((i3 = {})[t2] = n2, i3));
364
+ this.context = e(e({}, this.context), { properties: o3 });
365
+ }
366
+ this.timerRef && this.fetchToggles();
367
+ }, o2.prototype.init = function() {
368
+ return n(this, void 0, void 0, function() {
369
+ var t2, n2;
370
+ return r(this, function(r2) {
371
+ switch (r2.label) {
372
+ case 0:
373
+ return [4, this.resolveSessionId()];
374
+ case 1:
375
+ return t2 = r2.sent(), this.context = e({ sessionId: t2 }, this.context), n2 = this, [4, this.storage.get(R)];
376
+ case 2:
377
+ return n2.toggles = r2.sent() || [], !this.bootstrap || !this.bootstrapOverride && this.toggles.length !== 0 ? [3, 4] : [4, this.storage.save(R, this.bootstrap)];
378
+ case 3:
379
+ r2.sent(), this.toggles = this.bootstrap, this.emit(w.READY), r2.label = 4;
380
+ case 4:
381
+ return this.emit(w.INIT), [2];
1194
382
  }
1195
- }
1196
- return to.concat(ar || Array.prototype.slice.call(from));
1197
- };
1198
- Object.defineProperty(exports, "__esModule", { value: true });
1199
- exports.InMemoryStorageProvider = exports.LocalStorageProvider = exports.UnleashClient = exports.resolveFetch = exports.EVENTS = void 0;
1200
- var tiny_emitter_1 = tinyEmitter.exports;
1201
- var metrics_1 = metrics;
1202
- var storage_provider_inmemory_1 = storageProviderInmemory;
1203
- exports.InMemoryStorageProvider = storage_provider_inmemory_1.default;
1204
- var storage_provider_local_1 = storageProviderLocal;
1205
- exports.LocalStorageProvider = storage_provider_local_1.default;
1206
- var events_handler_1 = eventsHandler;
1207
- var util_12 = util;
1208
- var DEFINED_FIELDS = ["userId", "sessionId", "remoteAddress"];
1209
- exports.EVENTS = {
1210
- INIT: "initialized",
1211
- ERROR: "error",
1212
- READY: "ready",
1213
- UPDATE: "update",
1214
- IMPRESSION: "impression",
1215
- SENT: "sent"
1216
- };
1217
- var IMPRESSION_EVENTS = {
1218
- IS_ENABLED: "isEnabled",
1219
- GET_VARIANT: "getVariant"
1220
- };
1221
- var defaultVariant = { name: "disabled", enabled: false };
1222
- var storeKey = "repo";
1223
- var resolveFetch = function() {
1224
- try {
1225
- if (typeof window !== "undefined" && "fetch" in window) {
1226
- return fetch.bind(window);
1227
- } else if ("fetch" in globalThis) {
1228
- return fetch.bind(globalThis);
1229
- }
1230
- } catch (e) {
1231
- console.error('Unleash failed to resolve "fetch"', e);
1232
- }
1233
- return void 0;
1234
- };
1235
- exports.resolveFetch = resolveFetch;
1236
- var UnleashClient2 = function(_super) {
1237
- __extends(UnleashClient3, _super);
1238
- function UnleashClient3(_a) {
1239
- var storageProvider = _a.storageProvider, url = _a.url, clientKey = _a.clientKey, _b = _a.disableRefresh, disableRefresh = _b === void 0 ? false : _b, _c = _a.refreshInterval, refreshInterval = _c === void 0 ? 30 : _c, _d = _a.metricsInterval, metricsInterval = _d === void 0 ? 30 : _d, _e = _a.disableMetrics, disableMetrics = _e === void 0 ? false : _e, appName = _a.appName, _f = _a.environment, environment = _f === void 0 ? "default" : _f, context = _a.context, _g = _a.fetch, fetch2 = _g === void 0 ? (0, exports.resolveFetch)() : _g, bootstrap = _a.bootstrap, _h = _a.bootstrapOverride, bootstrapOverride = _h === void 0 ? true : _h, _j = _a.headerName, headerName = _j === void 0 ? "Authorization" : _j, _k = _a.customHeaders, customHeaders = _k === void 0 ? {} : _k, _l = _a.impressionDataAll, impressionDataAll = _l === void 0 ? false : _l, _m = _a.usePOSTrequests, usePOSTrequests = _m === void 0 ? false : _m;
1240
- var _this = _super.call(this) || this;
1241
- _this.toggles = [];
1242
- _this.etag = "";
1243
- _this.readyEventEmitted = false;
1244
- _this.usePOSTrequests = false;
1245
- _this.started = false;
1246
- if (!url) {
1247
- throw new Error("url is required");
1248
- }
1249
- if (!clientKey) {
1250
- throw new Error("clientKey is required");
1251
- }
1252
- if (!appName) {
1253
- throw new Error("appName is required.");
1254
- }
1255
- _this.eventsHandler = new events_handler_1.default();
1256
- _this.impressionDataAll = impressionDataAll;
1257
- _this.toggles = bootstrap && bootstrap.length > 0 ? bootstrap : [];
1258
- _this.url = url instanceof URL ? url : new URL(url);
1259
- _this.clientKey = clientKey;
1260
- _this.headerName = headerName;
1261
- _this.customHeaders = customHeaders;
1262
- _this.storage = storageProvider || (typeof window !== "undefined" ? new storage_provider_local_1.default() : new storage_provider_inmemory_1.default());
1263
- _this.refreshInterval = disableRefresh ? 0 : refreshInterval * 1e3;
1264
- _this.context = __assign2({ appName, environment }, context);
1265
- _this.usePOSTrequests = usePOSTrequests;
1266
- _this.ready = new Promise(function(resolve) {
1267
- _this.init().then(resolve).catch(function(error) {
1268
- console.error(error);
1269
- _this.emit(exports.EVENTS.ERROR, error);
1270
- resolve();
1271
- });
1272
- });
1273
- if (!fetch2) {
1274
- console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.');
1275
- }
1276
- _this.fetch = fetch2;
1277
- _this.bootstrap = bootstrap && bootstrap.length > 0 ? bootstrap : void 0;
1278
- _this.bootstrapOverride = bootstrapOverride;
1279
- _this.metrics = new metrics_1.default({
1280
- onError: _this.emit.bind(_this, exports.EVENTS.ERROR),
1281
- onSent: _this.emit.bind(_this, exports.EVENTS.SENT),
1282
- appName,
1283
- metricsInterval,
1284
- disableMetrics,
1285
- url: _this.url,
1286
- clientKey,
1287
- fetch: fetch2,
1288
- headerName,
1289
- customHeaders
1290
- });
1291
- return _this;
1292
- }
1293
- UnleashClient3.prototype.getAllToggles = function() {
1294
- return __spreadArray([], this.toggles, true);
1295
- };
1296
- UnleashClient3.prototype.isEnabled = function(toggleName) {
1297
- var _a;
1298
- var toggle = this.toggles.find(function(t) {
1299
- return t.name === toggleName;
1300
383
  });
1301
- var enabled = toggle ? toggle.enabled : false;
1302
- this.metrics.count(toggleName, enabled);
1303
- if ((toggle === null || toggle === void 0 ? void 0 : toggle.impressionData) || this.impressionDataAll) {
1304
- var event_1 = this.eventsHandler.createImpressionEvent(this.context, enabled, toggleName, IMPRESSION_EVENTS.IS_ENABLED, (_a = toggle === null || toggle === void 0 ? void 0 : toggle.impressionData) !== null && _a !== void 0 ? _a : void 0);
1305
- this.emit(exports.EVENTS.IMPRESSION, event_1);
1306
- }
1307
- return enabled;
1308
- };
1309
- UnleashClient3.prototype.getVariant = function(toggleName) {
1310
- var _a;
1311
- var toggle = this.toggles.find(function(t) {
1312
- return t.name === toggleName;
1313
- });
1314
- var enabled = (toggle === null || toggle === void 0 ? void 0 : toggle.enabled) || false;
1315
- var variant = toggle ? toggle.variant : defaultVariant;
1316
- if (variant.name) {
1317
- this.metrics.countVariant(toggleName, variant.name);
1318
- }
1319
- this.metrics.count(toggleName, enabled);
1320
- if ((toggle === null || toggle === void 0 ? void 0 : toggle.impressionData) || this.impressionDataAll) {
1321
- var event_2 = this.eventsHandler.createImpressionEvent(this.context, enabled, toggleName, IMPRESSION_EVENTS.GET_VARIANT, (_a = toggle === null || toggle === void 0 ? void 0 : toggle.impressionData) !== null && _a !== void 0 ? _a : void 0, variant.name);
1322
- this.emit(exports.EVENTS.IMPRESSION, event_2);
1323
- }
1324
- return variant;
1325
- };
1326
- UnleashClient3.prototype.updateContext = function(context) {
1327
- return __awaiter2(this, void 0, void 0, function() {
1328
- var staticContext;
1329
- var _this = this;
1330
- return __generator2(this, function(_a) {
1331
- switch (_a.label) {
1332
- case 0:
1333
- if (context.appName || context.environment) {
1334
- console.warn("appName and environment are static. They can't be updated with updateContext.");
1335
- }
1336
- staticContext = {
1337
- environment: this.context.environment,
1338
- appName: this.context.appName,
1339
- sessionId: this.context.sessionId
1340
- };
1341
- this.context = __assign2(__assign2({}, staticContext), context);
1342
- if (!(this.timerRef || this.readyEventEmitted))
1343
- return [3, 2];
1344
- return [4, this.fetchToggles()];
1345
- case 1:
1346
- _a.sent();
1347
- return [3, 4];
1348
- case 2:
1349
- if (!this.started)
1350
- return [3, 4];
1351
- return [4, new Promise(function(resolve) {
1352
- var listener = function() {
1353
- _this.fetchToggles().then(function() {
1354
- _this.off(exports.EVENTS.READY, listener);
1355
- resolve();
1356
- });
1357
- };
1358
- _this.once(exports.EVENTS.READY, listener);
1359
- })];
1360
- case 3:
1361
- _a.sent();
1362
- _a.label = 4;
1363
- case 4:
1364
- return [2];
1365
- }
1366
- });
1367
- });
1368
- };
1369
- UnleashClient3.prototype.getContext = function() {
1370
- return __assign2({}, this.context);
1371
- };
1372
- UnleashClient3.prototype.setContextField = function(field, value) {
1373
- var _a, _b;
1374
- if (DEFINED_FIELDS.includes(field)) {
1375
- this.context = __assign2(__assign2({}, this.context), (_a = {}, _a[field] = value, _a));
1376
- } else {
1377
- var properties = __assign2(__assign2({}, this.context.properties), (_b = {}, _b[field] = value, _b));
1378
- this.context = __assign2(__assign2({}, this.context), { properties });
1379
- }
1380
- if (this.timerRef) {
1381
- this.fetchToggles();
1382
- }
1383
- };
1384
- UnleashClient3.prototype.init = function() {
1385
- return __awaiter2(this, void 0, void 0, function() {
1386
- var sessionId, _a;
1387
- return __generator2(this, function(_b) {
1388
- switch (_b.label) {
1389
- case 0:
1390
- return [4, this.resolveSessionId()];
1391
- case 1:
1392
- sessionId = _b.sent();
1393
- this.context = __assign2({ sessionId }, this.context);
1394
- _a = this;
1395
- return [4, this.storage.get(storeKey)];
1396
- case 2:
1397
- _a.toggles = _b.sent() || [];
1398
- if (!(this.bootstrap && (this.bootstrapOverride || this.toggles.length === 0)))
1399
- return [3, 4];
1400
- return [4, this.storage.save(storeKey, this.bootstrap)];
1401
- case 3:
1402
- _b.sent();
1403
- this.toggles = this.bootstrap;
1404
- this.emit(exports.EVENTS.READY);
1405
- _b.label = 4;
1406
- case 4:
1407
- this.emit(exports.EVENTS.INIT);
1408
- return [2];
1409
- }
1410
- });
1411
- });
1412
- };
1413
- UnleashClient3.prototype.start = function() {
1414
- return __awaiter2(this, void 0, void 0, function() {
1415
- var interval;
1416
- var _this = this;
1417
- return __generator2(this, function(_a) {
1418
- switch (_a.label) {
1419
- case 0:
1420
- this.started = true;
1421
- if (this.timerRef) {
1422
- console.error("Unleash SDK has already started, if you want to restart the SDK you should call client.stop() before starting again.");
1423
- return [2];
1424
- }
1425
- return [4, this.ready];
1426
- case 1:
1427
- _a.sent();
1428
- this.metrics.start();
1429
- interval = this.refreshInterval;
1430
- return [4, this.fetchToggles()];
1431
- case 2:
1432
- _a.sent();
1433
- if (interval > 0) {
1434
- this.timerRef = setInterval(function() {
1435
- return _this.fetchToggles();
1436
- }, interval);
1437
- }
1438
- return [2];
1439
- }
1440
- });
1441
- });
1442
- };
1443
- UnleashClient3.prototype.stop = function() {
1444
- if (this.timerRef) {
1445
- clearInterval(this.timerRef);
1446
- this.timerRef = void 0;
1447
- }
1448
- this.metrics.stop();
1449
- };
1450
- UnleashClient3.prototype.resolveSessionId = function() {
1451
- return __awaiter2(this, void 0, void 0, function() {
1452
- var sessionId;
1453
- return __generator2(this, function(_a) {
1454
- switch (_a.label) {
1455
- case 0:
1456
- if (!this.context.sessionId)
1457
- return [3, 1];
1458
- return [2, this.context.sessionId];
1459
- case 1:
1460
- return [4, this.storage.get("sessionId")];
1461
- case 2:
1462
- sessionId = _a.sent();
1463
- if (!!sessionId)
1464
- return [3, 4];
1465
- sessionId = Math.floor(Math.random() * 1e9);
1466
- return [4, this.storage.save("sessionId", sessionId)];
1467
- case 3:
1468
- _a.sent();
1469
- _a.label = 4;
1470
- case 4:
1471
- return [2, sessionId];
1472
- }
1473
- });
384
+ });
385
+ }, o2.prototype.start = function() {
386
+ return n(this, void 0, void 0, function() {
387
+ var t2, e2 = this;
388
+ return r(this, function(n2) {
389
+ switch (n2.label) {
390
+ case 0:
391
+ 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
+ case 1:
393
+ return n2.sent(), this.metrics.start(), t2 = this.refreshInterval, [4, this.fetchToggles()];
394
+ case 2:
395
+ return n2.sent(), t2 > 0 && (this.timerRef = setInterval(function() {
396
+ return e2.fetchToggles();
397
+ }, t2)), [2];
398
+ }
1474
399
  });
1475
- };
1476
- UnleashClient3.prototype.getHeaders = function() {
1477
- var _a;
1478
- var headers = (_a = {}, _a[this.headerName] = this.clientKey, _a.Accept = "application/json", _a["Content-Type"] = "application/json", _a["If-None-Match"] = this.etag, _a);
1479
- Object.entries(this.customHeaders).filter(util_12.notNullOrUndefined).forEach(function(_a2) {
1480
- var name = _a2[0], value = _a2[1];
1481
- return headers[name] = value;
400
+ });
401
+ }, o2.prototype.stop = function() {
402
+ this.timerRef && (clearInterval(this.timerRef), this.timerRef = void 0), this.metrics.stop();
403
+ }, o2.prototype.resolveSessionId = function() {
404
+ return n(this, void 0, void 0, function() {
405
+ var t2;
406
+ return r(this, function(e2) {
407
+ switch (e2.label) {
408
+ case 0:
409
+ return this.context.sessionId ? [2, this.context.sessionId] : [3, 1];
410
+ case 1:
411
+ return [4, this.storage.get("sessionId")];
412
+ case 2:
413
+ return (t2 = e2.sent()) ? [3, 4] : (t2 = Math.floor(1e9 * Math.random()), [4, this.storage.save("sessionId", t2)]);
414
+ case 3:
415
+ e2.sent(), e2.label = 4;
416
+ case 4:
417
+ return [2, t2];
418
+ }
1482
419
  });
1483
- return headers;
1484
- };
1485
- UnleashClient3.prototype.storeToggles = function(toggles) {
1486
- return __awaiter2(this, void 0, void 0, function() {
1487
- return __generator2(this, function(_a) {
1488
- switch (_a.label) {
1489
- case 0:
1490
- this.toggles = toggles;
1491
- this.emit(exports.EVENTS.UPDATE);
1492
- return [4, this.storage.save(storeKey, toggles)];
1493
- case 1:
1494
- _a.sent();
1495
- return [2];
1496
- }
1497
- });
420
+ });
421
+ }, o2.prototype.getHeaders = function() {
422
+ var t2, e2 = ((t2 = {})[this.headerName] = this.clientKey, t2.Accept = "application/json", t2["Content-Type"] = "application/json", t2["If-None-Match"] = this.etag, t2);
423
+ return Object.entries(this.customHeaders).filter(a).forEach(function(t3) {
424
+ var n2 = t3[0], r2 = t3[1];
425
+ return e2[n2] = r2;
426
+ }), e2;
427
+ }, o2.prototype.storeToggles = function(t2) {
428
+ return n(this, void 0, void 0, function() {
429
+ return r(this, function(e2) {
430
+ switch (e2.label) {
431
+ case 0:
432
+ return this.toggles = t2, this.emit(w.UPDATE), [4, this.storage.save(R, t2)];
433
+ case 1:
434
+ return e2.sent(), [2];
435
+ }
1498
436
  });
1499
- };
1500
- UnleashClient3.prototype.fetchToggles = function() {
1501
- return __awaiter2(this, void 0, void 0, function() {
1502
- var isPOST, url, method, body, response, data, e_1;
1503
- return __generator2(this, function(_a) {
1504
- switch (_a.label) {
1505
- case 0:
1506
- if (!this.fetch)
1507
- return [3, 8];
1508
- _a.label = 1;
1509
- case 1:
1510
- _a.trys.push([1, 7, , 8]);
1511
- isPOST = this.usePOSTrequests;
1512
- url = isPOST ? this.url : (0, util_12.urlWithContextAsQuery)(this.url, this.context);
1513
- method = isPOST ? "POST" : "GET";
1514
- body = isPOST ? JSON.stringify({ context: this.context }) : void 0;
1515
- return [4, this.fetch(url.toString(), {
1516
- method,
1517
- cache: "no-cache",
1518
- headers: this.getHeaders(),
1519
- body
1520
- })];
1521
- case 2:
1522
- response = _a.sent();
1523
- if (!(response.ok && response.status !== 304))
1524
- return [3, 5];
1525
- this.etag = response.headers.get("ETag") || "";
1526
- return [4, response.json()];
1527
- case 3:
1528
- data = _a.sent();
1529
- return [4, this.storeToggles(data.toggles)];
1530
- case 4:
1531
- _a.sent();
1532
- if (!this.bootstrap && !this.readyEventEmitted) {
1533
- this.emit(exports.EVENTS.READY);
1534
- this.readyEventEmitted = true;
1535
- }
1536
- return [3, 6];
1537
- case 5:
1538
- if (!response.ok && response.status !== 304) {
1539
- console.error("Unleash: Fetching feature toggles did not have an ok response");
1540
- this.emit(exports.EVENTS.ERROR, {
1541
- type: "HttpError",
1542
- code: response.status
1543
- });
1544
- }
1545
- _a.label = 6;
1546
- case 6:
1547
- return [3, 8];
1548
- case 7:
1549
- e_1 = _a.sent();
1550
- console.error("Unleash: unable to fetch feature toggles", e_1);
1551
- this.emit(exports.EVENTS.ERROR, e_1);
437
+ });
438
+ }, o2.prototype.fetchToggles = function() {
439
+ return n(this, void 0, void 0, function() {
440
+ var t2, e2, n2, i3, o3, s2, c2;
441
+ return r(this, function(r2) {
442
+ switch (r2.label) {
443
+ case 0:
444
+ if (!this.fetch)
1552
445
  return [3, 8];
1553
- case 8:
1554
- return [2];
1555
- }
1556
- });
446
+ r2.label = 1;
447
+ case 1:
448
+ return r2.trys.push([1, 7, , 8]), t2 = this.usePOSTrequests, e2 = t2 ? this.url : function(t3, e3) {
449
+ var n3 = new URL(t3.toString());
450
+ return Object.entries(e3).filter(a).forEach(function(t4) {
451
+ var e4 = t4[0], r3 = t4[1];
452
+ e4 === "properties" && r3 ? Object.entries(r3).filter(a).forEach(function(t5) {
453
+ var e5 = t5[0], r4 = t5[1];
454
+ return n3.searchParams.append("properties[".concat(e5, "]"), r4);
455
+ }) : n3.searchParams.append(e4, r3);
456
+ }), n3;
457
+ }(this.url, this.context), n2 = t2 ? "POST" : "GET", i3 = t2 ? JSON.stringify({ context: this.context }) : void 0, [4, this.fetch(e2.toString(), { method: n2, cache: "no-cache", headers: this.getHeaders(), body: i3 })];
458
+ case 2:
459
+ return (o3 = r2.sent()).ok && o3.status !== 304 ? (this.etag = o3.headers.get("ETag") || "", [4, o3.json()]) : [3, 5];
460
+ case 3:
461
+ return s2 = r2.sent(), [4, this.storeToggles(s2.toggles)];
462
+ case 4:
463
+ return r2.sent(), this.bootstrap || this.readyEventEmitted || (this.emit(w.READY), this.readyEventEmitted = true), [3, 6];
464
+ case 5:
465
+ o3.ok || o3.status === 304 || (console.error("Unleash: Fetching feature toggles did not have an ok response"), this.emit(w.ERROR, { type: "HttpError", code: o3.status })), r2.label = 6;
466
+ case 6:
467
+ return [3, 8];
468
+ case 7:
469
+ return c2 = r2.sent(), console.error("Unleash: unable to fetch feature toggles", c2), this.emit(w.ERROR, c2), [3, 8];
470
+ case 8:
471
+ return [2];
472
+ }
1557
473
  });
1558
- };
1559
- return UnleashClient3;
1560
- }(tiny_emitter_1.TinyEmitter);
1561
- exports.UnleashClient = UnleashClient2;
1562
- })(build);
474
+ });
475
+ }, o2;
476
+ }(s);
1563
477
  const ContextStateSymbol = Symbol("Context state identifier");
1564
478
  const ContextUpdateSymbol = Symbol("Context update identifier");
1565
479
  function useUnleashProvide({
@@ -1576,13 +490,13 @@ function useUnleashProvide({
1576
490
  checking if the client exists before rendering.`);
1577
491
  }
1578
492
  if (!client.value && config) {
1579
- client.value = new build.UnleashClient(config);
493
+ client.value = new T(config);
1580
494
  }
1581
495
  (_a = client.value) == null ? void 0 : _a.on("ready", () => {
1582
496
  flagsReady.value = true;
1583
497
  });
1584
- (_b = client.value) == null ? void 0 : _b.on("error", (e) => {
1585
- flagsError.value = e;
498
+ (_b = client.value) == null ? void 0 : _b.on("error", (e2) => {
499
+ flagsError.value = e2;
1586
500
  });
1587
501
  const updateContext = async (context2) => {
1588
502
  var _a2;
@@ -1676,13 +590,17 @@ const useFlagsStatus = () => {
1676
590
  const { flagsReady, flagsError } = inject(ContextStateSymbol, {});
1677
591
  return { flagsReady, flagsError };
1678
592
  };
593
+ const variantHasChanged = (oldVariant, newVariant) => {
594
+ var _a, _b, _c, _d;
595
+ const variantsAreEqual = (oldVariant == null ? void 0 : oldVariant.name) === (newVariant == null ? void 0 : newVariant.name) && (oldVariant == null ? void 0 : oldVariant.enabled) === (newVariant == null ? void 0 : newVariant.enabled) && (oldVariant == null ? void 0 : oldVariant.feature_enabled) === (newVariant == null ? void 0 : newVariant.feature_enabled) && ((_a = oldVariant == null ? void 0 : oldVariant.payload) == null ? void 0 : _a.type) === ((_b = newVariant == null ? void 0 : newVariant.payload) == null ? void 0 : _b.type) && ((_c = oldVariant == null ? void 0 : oldVariant.payload) == null ? void 0 : _c.value) === ((_d = newVariant == null ? void 0 : newVariant.payload) == null ? void 0 : _d.value);
596
+ return !variantsAreEqual;
597
+ };
1679
598
  const useVariant = (name) => {
1680
599
  const { getVariant, client } = inject(ContextStateSymbol, {});
1681
600
  const variant = ref(getVariant == null ? void 0 : getVariant.value(name));
1682
601
  function onUpdate() {
1683
- var _a, _b;
1684
602
  const newVariant = getVariant == null ? void 0 : getVariant.value(name);
1685
- if ((newVariant == null ? void 0 : newVariant.name) !== ((_a = variant.value) == null ? void 0 : _a.name) || (newVariant == null ? void 0 : newVariant.enabled) !== ((_b = variant.value) == null ? void 0 : _b.enabled)) {
603
+ if (variantHasChanged(variant == null ? void 0 : variant.value, newVariant)) {
1686
604
  variant.value = newVariant;
1687
605
  }
1688
606
  }
@@ -1717,7 +635,4 @@ const plugin = {
1717
635
  start();
1718
636
  }
1719
637
  };
1720
- var InMemoryStorageProvider$1 = build.InMemoryStorageProvider;
1721
- var LocalStorageProvider$1 = build.LocalStorageProvider;
1722
- var UnleashClient = build.UnleashClient;
1723
- export { ContextStateSymbol, ContextUpdateSymbol, _sfc_main as FlagProvider, InMemoryStorageProvider$1 as InMemoryStorageProvider, LocalStorageProvider$1 as LocalStorageProvider, UnleashClient, _sfc_main as default, plugin, useFlag, useFlagsStatus, useUnleashClient, useUnleashContext, useVariant };
638
+ export { ContextStateSymbol, ContextUpdateSymbol, _sfc_main as FlagProvider, h as InMemoryStorageProvider, l as LocalStorageProvider, T as UnleashClient, _sfc_main as default, plugin, useFlag, useFlagsStatus, useUnleashClient, useUnleashContext, useVariant };