@unleash/proxy-client-vue 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -20
- package/dist/index.es.js +149 -74
- package/dist/index.umd.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
PoC for a Vue SDK for [Unleash](https://www.getunleash.io/) based on the official [proxy-client-react](https://github.com/Unleash/proxy-client-react).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Usage note
|
|
6
6
|
|
|
7
|
-
This library is meant to be used with
|
|
7
|
+
This library is meant to be used with [Unleash Edge](https://github.com/Unleash/unleash-edge/), the [Unleash front-end API](https://docs.getunleash.io/reference/front-end-api) , or the [Unleash proxy](https://github.com/Unleash/unleash-proxy).
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
It is **not** compatible with the Unleash client API.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
10
12
|
|
|
11
13
|
```bash
|
|
12
14
|
npm install @unleash/proxy-client-vue
|
|
@@ -14,9 +16,9 @@ npm install @unleash/proxy-client-vue
|
|
|
14
16
|
yarn add @unleash/proxy-client-vue
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
## Initialization
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
### Using config:
|
|
20
22
|
|
|
21
23
|
```jsx
|
|
22
24
|
import { createApp } from 'vue'
|
|
@@ -29,7 +31,6 @@ const config = {
|
|
|
29
31
|
clientKey: 'PROXYKEY',
|
|
30
32
|
refreshInterval: 15,
|
|
31
33
|
appName: 'your-app-name',
|
|
32
|
-
environment: 'dev'
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
const app = createApp(App)
|
|
@@ -43,11 +44,10 @@ Or use the FlagProvider component like this in your entrypoint file (typically A
|
|
|
43
44
|
import { FlagProvider } from '@unleash/proxy-client-vue'
|
|
44
45
|
|
|
45
46
|
const config = {
|
|
46
|
-
url: 'https://
|
|
47
|
-
clientKey: '
|
|
47
|
+
url: 'https://UNLEASH-INSTANCE/api/frontend',
|
|
48
|
+
clientKey: 'CLIENT—SIDE—API—TOKEN',
|
|
48
49
|
refreshInterval: 15,
|
|
49
50
|
appName: 'your-app-name',
|
|
50
|
-
environment: 'dev'
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
<template>
|
|
@@ -57,7 +57,7 @@ const config = {
|
|
|
57
57
|
</template>
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
### Initializing your own client
|
|
61
61
|
|
|
62
62
|
```jsx
|
|
63
63
|
import { createApp } from 'vue'
|
|
@@ -70,7 +70,6 @@ const config = {
|
|
|
70
70
|
clientKey: 'PROXYKEY',
|
|
71
71
|
refreshInterval: 15,
|
|
72
72
|
appName: 'your-app-name',
|
|
73
|
-
environment: 'dev'
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
const client = new UnleashClient(config)
|
|
@@ -86,11 +85,10 @@ Or, using FlagProvider:
|
|
|
86
85
|
import { FlagProvider, UnleashClient } from '@unleash/proxy-client-vue'
|
|
87
86
|
|
|
88
87
|
const config = {
|
|
89
|
-
url: 'https://
|
|
90
|
-
clientKey: '
|
|
88
|
+
url: 'https://UNLEASH-INSTANCE/api/frontend',
|
|
89
|
+
clientKey: 'CLIENT—SIDE—API—TOKEN',
|
|
91
90
|
refreshInterval: 15,
|
|
92
91
|
appName: 'your-app-name',
|
|
93
|
-
environment: 'dev'
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
const client = new UnleashClient(config)
|
|
@@ -102,7 +100,7 @@ const client = new UnleashClient(config)
|
|
|
102
100
|
</template>
|
|
103
101
|
```
|
|
104
102
|
|
|
105
|
-
|
|
103
|
+
### Deferring client start
|
|
106
104
|
|
|
107
105
|
By default, the Unleash client will start polling the Proxy for toggles immediately when the `FlagProvider` component renders. You can delay the polling by:
|
|
108
106
|
|
|
@@ -141,9 +139,9 @@ onMounted(() => {
|
|
|
141
139
|
</template>
|
|
142
140
|
```
|
|
143
141
|
|
|
144
|
-
|
|
142
|
+
## Usage
|
|
145
143
|
|
|
146
|
-
|
|
144
|
+
### Check feature toggle status
|
|
147
145
|
|
|
148
146
|
To check if a feature is enabled:
|
|
149
147
|
|
|
@@ -160,7 +158,7 @@ const enabled = useFlag('travel.landing')
|
|
|
160
158
|
</template>
|
|
161
159
|
```
|
|
162
160
|
|
|
163
|
-
|
|
161
|
+
### Check variants
|
|
164
162
|
|
|
165
163
|
To check variants:
|
|
166
164
|
|
|
@@ -178,7 +176,7 @@ const variant = useVariant('travel.landing')
|
|
|
178
176
|
</template>
|
|
179
177
|
```
|
|
180
178
|
|
|
181
|
-
|
|
179
|
+
### Defer rendering until flags fetched
|
|
182
180
|
|
|
183
181
|
useFlagsStatus retrieves the ready state and error events.
|
|
184
182
|
Follow the following steps in order to delay rendering until the flags have been fetched.
|
|
@@ -192,7 +190,7 @@ const { flagsReady, flagsError } = useFlagsStatus()
|
|
|
192
190
|
<MyComponent v-else error={flagsError} />
|
|
193
191
|
```
|
|
194
192
|
|
|
195
|
-
|
|
193
|
+
### Updating context
|
|
196
194
|
|
|
197
195
|
Follow the following steps in order to update the unleash context:
|
|
198
196
|
|
package/dist/index.es.js
CHANGED
|
@@ -64,6 +64,32 @@ E.prototype = {
|
|
|
64
64
|
tinyEmitter.exports = E;
|
|
65
65
|
tinyEmitter.exports.TinyEmitter = E;
|
|
66
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);
|
|
67
93
|
var __assign$1 = commonjsGlobal && commonjsGlobal.__assign || function() {
|
|
68
94
|
__assign$1 = Object.assign || function(t) {
|
|
69
95
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -180,10 +206,14 @@ var __generator$2 = commonjsGlobal && commonjsGlobal.__generator || function(thi
|
|
|
180
206
|
}
|
|
181
207
|
};
|
|
182
208
|
Object.defineProperty(metrics, "__esModule", { value: true });
|
|
209
|
+
var util_1 = util;
|
|
210
|
+
var doNothing = function() {
|
|
211
|
+
};
|
|
183
212
|
var Metrics = function() {
|
|
184
213
|
function Metrics2(_a) {
|
|
185
|
-
var onError = _a.onError, 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;
|
|
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;
|
|
186
215
|
this.onError = onError;
|
|
216
|
+
this.onSent = onSent || doNothing;
|
|
187
217
|
this.disabled = disableMetrics;
|
|
188
218
|
this.metricsInterval = metricsInterval * 1e3;
|
|
189
219
|
this.appName = appName;
|
|
@@ -192,6 +222,7 @@ var Metrics = function() {
|
|
|
192
222
|
this.bucket = this.createEmptyBucket();
|
|
193
223
|
this.fetch = fetch2;
|
|
194
224
|
this.headerName = headerName;
|
|
225
|
+
this.customHeaders = customHeaders;
|
|
195
226
|
}
|
|
196
227
|
Metrics2.prototype.start = function() {
|
|
197
228
|
var _this = this;
|
|
@@ -218,32 +249,41 @@ var Metrics = function() {
|
|
|
218
249
|
toggles: {}
|
|
219
250
|
};
|
|
220
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
|
+
};
|
|
221
261
|
Metrics2.prototype.sendMetrics = function() {
|
|
222
262
|
return __awaiter$2(this, void 0, void 0, function() {
|
|
223
263
|
var url, payload, e_1;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
switch (_b.label) {
|
|
264
|
+
return __generator$2(this, function(_a) {
|
|
265
|
+
switch (_a.label) {
|
|
227
266
|
case 0:
|
|
228
267
|
url = "".concat(this.url, "/client/metrics");
|
|
229
268
|
payload = this.getPayload();
|
|
230
269
|
if (this.bucketIsEmpty(payload)) {
|
|
231
270
|
return [2];
|
|
232
271
|
}
|
|
233
|
-
|
|
272
|
+
_a.label = 1;
|
|
234
273
|
case 1:
|
|
235
|
-
|
|
274
|
+
_a.trys.push([1, 3, , 4]);
|
|
236
275
|
return [4, this.fetch(url, {
|
|
237
276
|
cache: "no-cache",
|
|
238
277
|
method: "POST",
|
|
239
|
-
headers:
|
|
278
|
+
headers: this.getHeaders(),
|
|
240
279
|
body: JSON.stringify(payload)
|
|
241
280
|
})];
|
|
242
281
|
case 2:
|
|
243
|
-
|
|
282
|
+
_a.sent();
|
|
283
|
+
this.onSent(payload);
|
|
244
284
|
return [3, 4];
|
|
245
285
|
case 3:
|
|
246
|
-
e_1 =
|
|
286
|
+
e_1 = _a.sent();
|
|
247
287
|
console.error("Unleash: unable to send feature metrics", e_1);
|
|
248
288
|
this.onError(e_1);
|
|
249
289
|
return [3, 4];
|
|
@@ -261,6 +301,18 @@ var Metrics = function() {
|
|
|
261
301
|
this.bucket.toggles[name][enabled ? "yes" : "no"]++;
|
|
262
302
|
return true;
|
|
263
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
|
+
};
|
|
264
316
|
Metrics2.prototype.assertBucket = function(name) {
|
|
265
317
|
if (this.disabled || !this.bucket) {
|
|
266
318
|
return false;
|
|
@@ -268,7 +320,8 @@ var Metrics = function() {
|
|
|
268
320
|
if (!this.bucket.toggles[name]) {
|
|
269
321
|
this.bucket.toggles[name] = {
|
|
270
322
|
yes: 0,
|
|
271
|
-
no: 0
|
|
323
|
+
no: 0,
|
|
324
|
+
variants: {}
|
|
272
325
|
};
|
|
273
326
|
}
|
|
274
327
|
};
|
|
@@ -398,11 +451,11 @@ var __generator$1 = commonjsGlobal && commonjsGlobal.__generator || function(thi
|
|
|
398
451
|
}
|
|
399
452
|
};
|
|
400
453
|
Object.defineProperty(storageProviderInmemory, "__esModule", { value: true });
|
|
401
|
-
var
|
|
402
|
-
function
|
|
454
|
+
var InMemoryStorageProvider = function() {
|
|
455
|
+
function InMemoryStorageProvider2() {
|
|
403
456
|
this.store = /* @__PURE__ */ new Map();
|
|
404
457
|
}
|
|
405
|
-
|
|
458
|
+
InMemoryStorageProvider2.prototype.save = function(name, data) {
|
|
406
459
|
return __awaiter$1(this, void 0, void 0, function() {
|
|
407
460
|
return __generator$1(this, function(_a) {
|
|
408
461
|
this.store.set(name, data);
|
|
@@ -410,16 +463,16 @@ var ImMemoryStorageProvider = function() {
|
|
|
410
463
|
});
|
|
411
464
|
});
|
|
412
465
|
};
|
|
413
|
-
|
|
466
|
+
InMemoryStorageProvider2.prototype.get = function(name) {
|
|
414
467
|
return __awaiter$1(this, void 0, void 0, function() {
|
|
415
468
|
return __generator$1(this, function(_a) {
|
|
416
469
|
return [2, this.store.get(name)];
|
|
417
470
|
});
|
|
418
471
|
});
|
|
419
472
|
};
|
|
420
|
-
return
|
|
473
|
+
return InMemoryStorageProvider2;
|
|
421
474
|
}();
|
|
422
|
-
storageProviderInmemory.default =
|
|
475
|
+
storageProviderInmemory.default = InMemoryStorageProvider;
|
|
423
476
|
var storageProviderLocal = {};
|
|
424
477
|
var __awaiter = commonjsGlobal && commonjsGlobal.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
425
478
|
function adopt(value) {
|
|
@@ -974,33 +1027,26 @@ var EventsHandler = function() {
|
|
|
974
1027
|
EventsHandler2.prototype.generateEventId = function() {
|
|
975
1028
|
return (0, uuid_1.v4)();
|
|
976
1029
|
};
|
|
977
|
-
EventsHandler2.prototype.createImpressionEvent = function(context, enabled, featureName, eventType, variant) {
|
|
978
|
-
var baseEvent = this.createBaseEvent(context, enabled, featureName, eventType);
|
|
1030
|
+
EventsHandler2.prototype.createImpressionEvent = function(context, enabled, featureName, eventType, impressionData, variant) {
|
|
1031
|
+
var baseEvent = this.createBaseEvent(context, enabled, featureName, eventType, impressionData);
|
|
979
1032
|
if (variant) {
|
|
980
1033
|
return __assign(__assign({}, baseEvent), { variant });
|
|
981
1034
|
}
|
|
982
1035
|
return baseEvent;
|
|
983
1036
|
};
|
|
984
|
-
EventsHandler2.prototype.createBaseEvent = function(context, enabled, featureName, eventType) {
|
|
1037
|
+
EventsHandler2.prototype.createBaseEvent = function(context, enabled, featureName, eventType, impressionData) {
|
|
985
1038
|
return {
|
|
986
1039
|
eventType,
|
|
987
1040
|
eventId: this.generateEventId(),
|
|
988
1041
|
context,
|
|
989
1042
|
enabled,
|
|
990
|
-
featureName
|
|
1043
|
+
featureName,
|
|
1044
|
+
impressionData
|
|
991
1045
|
};
|
|
992
1046
|
};
|
|
993
1047
|
return EventsHandler2;
|
|
994
1048
|
}();
|
|
995
1049
|
eventsHandler.default = EventsHandler;
|
|
996
|
-
var util = {};
|
|
997
|
-
Object.defineProperty(util, "__esModule", { value: true });
|
|
998
|
-
util.notNullOrUndefined = void 0;
|
|
999
|
-
var notNullOrUndefined = function(_a) {
|
|
1000
|
-
var value = _a[1];
|
|
1001
|
-
return value !== void 0 && value !== null;
|
|
1002
|
-
};
|
|
1003
|
-
util.notNullOrUndefined = notNullOrUndefined;
|
|
1004
1050
|
(function(exports) {
|
|
1005
1051
|
var __extends = commonjsGlobal && commonjsGlobal.__extends || function() {
|
|
1006
1052
|
var extendStatics = function(d, b) {
|
|
@@ -1158,14 +1204,15 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1158
1204
|
var storage_provider_local_1 = storageProviderLocal;
|
|
1159
1205
|
exports.LocalStorageProvider = storage_provider_local_1.default;
|
|
1160
1206
|
var events_handler_1 = eventsHandler;
|
|
1161
|
-
var
|
|
1207
|
+
var util_12 = util;
|
|
1162
1208
|
var DEFINED_FIELDS = ["userId", "sessionId", "remoteAddress"];
|
|
1163
1209
|
exports.EVENTS = {
|
|
1164
1210
|
INIT: "initialized",
|
|
1165
1211
|
ERROR: "error",
|
|
1166
1212
|
READY: "ready",
|
|
1167
1213
|
UPDATE: "update",
|
|
1168
|
-
IMPRESSION: "impression"
|
|
1214
|
+
IMPRESSION: "impression",
|
|
1215
|
+
SENT: "sent"
|
|
1169
1216
|
};
|
|
1170
1217
|
var IMPRESSION_EVENTS = {
|
|
1171
1218
|
IS_ENABLED: "isEnabled",
|
|
@@ -1175,7 +1222,7 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1175
1222
|
var storeKey = "repo";
|
|
1176
1223
|
var resolveFetch = function() {
|
|
1177
1224
|
try {
|
|
1178
|
-
if ("fetch" in window) {
|
|
1225
|
+
if (typeof window !== "undefined" && "fetch" in window) {
|
|
1179
1226
|
return fetch.bind(window);
|
|
1180
1227
|
} else if ("fetch" in globalThis) {
|
|
1181
1228
|
return fetch.bind(globalThis);
|
|
@@ -1189,11 +1236,13 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1189
1236
|
var UnleashClient2 = function(_super) {
|
|
1190
1237
|
__extends(UnleashClient3, _super);
|
|
1191
1238
|
function UnleashClient3(_a) {
|
|
1192
|
-
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;
|
|
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;
|
|
1193
1240
|
var _this = _super.call(this) || this;
|
|
1194
1241
|
_this.toggles = [];
|
|
1195
1242
|
_this.etag = "";
|
|
1196
1243
|
_this.readyEventEmitted = false;
|
|
1244
|
+
_this.usePOSTrequests = false;
|
|
1245
|
+
_this.started = false;
|
|
1197
1246
|
if (!url) {
|
|
1198
1247
|
throw new Error("url is required");
|
|
1199
1248
|
}
|
|
@@ -1204,14 +1253,16 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1204
1253
|
throw new Error("appName is required.");
|
|
1205
1254
|
}
|
|
1206
1255
|
_this.eventsHandler = new events_handler_1.default();
|
|
1256
|
+
_this.impressionDataAll = impressionDataAll;
|
|
1207
1257
|
_this.toggles = bootstrap && bootstrap.length > 0 ? bootstrap : [];
|
|
1208
1258
|
_this.url = url instanceof URL ? url : new URL(url);
|
|
1209
1259
|
_this.clientKey = clientKey;
|
|
1210
1260
|
_this.headerName = headerName;
|
|
1211
1261
|
_this.customHeaders = customHeaders;
|
|
1212
|
-
_this.storage = storageProvider || new storage_provider_local_1.default();
|
|
1262
|
+
_this.storage = storageProvider || (typeof window !== "undefined" ? new storage_provider_local_1.default() : new storage_provider_inmemory_1.default());
|
|
1213
1263
|
_this.refreshInterval = disableRefresh ? 0 : refreshInterval * 1e3;
|
|
1214
1264
|
_this.context = __assign2({ appName, environment }, context);
|
|
1265
|
+
_this.usePOSTrequests = usePOSTrequests;
|
|
1215
1266
|
_this.ready = new Promise(function(resolve) {
|
|
1216
1267
|
_this.init().then(resolve).catch(function(error) {
|
|
1217
1268
|
console.error(error);
|
|
@@ -1227,13 +1278,15 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1227
1278
|
_this.bootstrapOverride = bootstrapOverride;
|
|
1228
1279
|
_this.metrics = new metrics_1.default({
|
|
1229
1280
|
onError: _this.emit.bind(_this, exports.EVENTS.ERROR),
|
|
1281
|
+
onSent: _this.emit.bind(_this, exports.EVENTS.SENT),
|
|
1230
1282
|
appName,
|
|
1231
1283
|
metricsInterval,
|
|
1232
1284
|
disableMetrics,
|
|
1233
1285
|
url: _this.url,
|
|
1234
1286
|
clientKey,
|
|
1235
1287
|
fetch: fetch2,
|
|
1236
|
-
headerName
|
|
1288
|
+
headerName,
|
|
1289
|
+
customHeaders
|
|
1237
1290
|
});
|
|
1238
1291
|
return _this;
|
|
1239
1292
|
}
|
|
@@ -1241,36 +1294,39 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1241
1294
|
return __spreadArray([], this.toggles, true);
|
|
1242
1295
|
};
|
|
1243
1296
|
UnleashClient3.prototype.isEnabled = function(toggleName) {
|
|
1297
|
+
var _a;
|
|
1244
1298
|
var toggle = this.toggles.find(function(t) {
|
|
1245
1299
|
return t.name === toggleName;
|
|
1246
1300
|
});
|
|
1247
1301
|
var enabled = toggle ? toggle.enabled : false;
|
|
1248
1302
|
this.metrics.count(toggleName, enabled);
|
|
1249
|
-
if (toggle === null || toggle === void 0 ? void 0 : toggle.impressionData) {
|
|
1250
|
-
var event_1 = this.eventsHandler.createImpressionEvent(this.context, enabled, toggleName, IMPRESSION_EVENTS.IS_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);
|
|
1251
1305
|
this.emit(exports.EVENTS.IMPRESSION, event_1);
|
|
1252
1306
|
}
|
|
1253
1307
|
return enabled;
|
|
1254
1308
|
};
|
|
1255
1309
|
UnleashClient3.prototype.getVariant = function(toggleName) {
|
|
1310
|
+
var _a;
|
|
1256
1311
|
var toggle = this.toggles.find(function(t) {
|
|
1257
1312
|
return t.name === toggleName;
|
|
1258
1313
|
});
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
this.
|
|
1268
|
-
return defaultVariant;
|
|
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);
|
|
1269
1323
|
}
|
|
1324
|
+
return variant;
|
|
1270
1325
|
};
|
|
1271
1326
|
UnleashClient3.prototype.updateContext = function(context) {
|
|
1272
1327
|
return __awaiter2(this, void 0, void 0, function() {
|
|
1273
1328
|
var staticContext;
|
|
1329
|
+
var _this = this;
|
|
1274
1330
|
return __generator2(this, function(_a) {
|
|
1275
1331
|
switch (_a.label) {
|
|
1276
1332
|
case 0:
|
|
@@ -1279,16 +1335,32 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1279
1335
|
}
|
|
1280
1336
|
staticContext = {
|
|
1281
1337
|
environment: this.context.environment,
|
|
1282
|
-
appName: this.context.appName
|
|
1338
|
+
appName: this.context.appName,
|
|
1339
|
+
sessionId: this.context.sessionId
|
|
1283
1340
|
};
|
|
1284
1341
|
this.context = __assign2(__assign2({}, staticContext), context);
|
|
1285
|
-
if (!this.timerRef)
|
|
1342
|
+
if (!(this.timerRef || this.readyEventEmitted))
|
|
1286
1343
|
return [3, 2];
|
|
1287
1344
|
return [4, this.fetchToggles()];
|
|
1288
1345
|
case 1:
|
|
1289
1346
|
_a.sent();
|
|
1290
|
-
|
|
1347
|
+
return [3, 4];
|
|
1291
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:
|
|
1292
1364
|
return [2];
|
|
1293
1365
|
}
|
|
1294
1366
|
});
|
|
@@ -1345,6 +1417,7 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1345
1417
|
return __generator2(this, function(_a) {
|
|
1346
1418
|
switch (_a.label) {
|
|
1347
1419
|
case 0:
|
|
1420
|
+
this.started = true;
|
|
1348
1421
|
if (this.timerRef) {
|
|
1349
1422
|
console.error("Unleash SDK has already started, if you want to restart the SDK you should call client.stop() before starting again.");
|
|
1350
1423
|
return [2];
|
|
@@ -1403,7 +1476,7 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1403
1476
|
UnleashClient3.prototype.getHeaders = function() {
|
|
1404
1477
|
var _a;
|
|
1405
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);
|
|
1406
|
-
Object.entries(this.customHeaders).filter(
|
|
1479
|
+
Object.entries(this.customHeaders).filter(util_12.notNullOrUndefined).forEach(function(_a2) {
|
|
1407
1480
|
var name = _a2[0], value = _a2[1];
|
|
1408
1481
|
return headers[name] = value;
|
|
1409
1482
|
});
|
|
@@ -1426,31 +1499,24 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1426
1499
|
};
|
|
1427
1500
|
UnleashClient3.prototype.fetchToggles = function() {
|
|
1428
1501
|
return __awaiter2(this, void 0, void 0, function() {
|
|
1429
|
-
var
|
|
1502
|
+
var isPOST, url, method, body, response, data, e_1;
|
|
1430
1503
|
return __generator2(this, function(_a) {
|
|
1431
1504
|
switch (_a.label) {
|
|
1432
1505
|
case 0:
|
|
1433
1506
|
if (!this.fetch)
|
|
1434
|
-
return [3,
|
|
1507
|
+
return [3, 8];
|
|
1435
1508
|
_a.label = 1;
|
|
1436
1509
|
case 1:
|
|
1437
|
-
_a.trys.push([1,
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
var propertyKey = _a3[0], propertyValue = _a3[1];
|
|
1445
|
-
return urlWithQuery_1.searchParams.append("properties[".concat(propertyKey, "]"), propertyValue);
|
|
1446
|
-
});
|
|
1447
|
-
} else {
|
|
1448
|
-
urlWithQuery_1.searchParams.append(contextKey, contextValue);
|
|
1449
|
-
}
|
|
1450
|
-
});
|
|
1451
|
-
return [4, this.fetch(urlWithQuery_1.toString(), {
|
|
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,
|
|
1452
1517
|
cache: "no-cache",
|
|
1453
|
-
headers: this.getHeaders()
|
|
1518
|
+
headers: this.getHeaders(),
|
|
1519
|
+
body
|
|
1454
1520
|
})];
|
|
1455
1521
|
case 2:
|
|
1456
1522
|
response = _a.sent();
|
|
@@ -1467,15 +1533,24 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1467
1533
|
this.emit(exports.EVENTS.READY);
|
|
1468
1534
|
this.readyEventEmitted = true;
|
|
1469
1535
|
}
|
|
1470
|
-
|
|
1536
|
+
return [3, 6];
|
|
1471
1537
|
case 5:
|
|
1472
|
-
|
|
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;
|
|
1473
1546
|
case 6:
|
|
1547
|
+
return [3, 8];
|
|
1548
|
+
case 7:
|
|
1474
1549
|
e_1 = _a.sent();
|
|
1475
1550
|
console.error("Unleash: unable to fetch feature toggles", e_1);
|
|
1476
1551
|
this.emit(exports.EVENTS.ERROR, e_1);
|
|
1477
|
-
return [3,
|
|
1478
|
-
case
|
|
1552
|
+
return [3, 8];
|
|
1553
|
+
case 8:
|
|
1479
1554
|
return [2];
|
|
1480
1555
|
}
|
|
1481
1556
|
});
|
|
@@ -1642,7 +1717,7 @@ const plugin = {
|
|
|
1642
1717
|
start();
|
|
1643
1718
|
}
|
|
1644
1719
|
};
|
|
1645
|
-
var InMemoryStorageProvider = build.InMemoryStorageProvider;
|
|
1720
|
+
var InMemoryStorageProvider$1 = build.InMemoryStorageProvider;
|
|
1646
1721
|
var LocalStorageProvider$1 = build.LocalStorageProvider;
|
|
1647
1722
|
var UnleashClient = build.UnleashClient;
|
|
1648
|
-
export { ContextStateSymbol, ContextUpdateSymbol, _sfc_main as FlagProvider, InMemoryStorageProvider, LocalStorageProvider$1 as LocalStorageProvider, UnleashClient, _sfc_main as default, plugin, useFlag, useFlagsStatus, useUnleashClient, useUnleashContext, useVariant };
|
|
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 };
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(_,b){typeof exports=="object"&&typeof module!="undefined"?b(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],b):(_=typeof globalThis!="undefined"?globalThis:_||self,b(_["proxy-client-vue"]={},_.Vue))})(this,function(_,b){"use strict";var g=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function xe(t){if(t.__esModule)return t;var o=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach(function(e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(o,e,n.get?n:{enumerable:!0,get:function(){return t[e]}})}),o}var F={},z={exports:{}};function Z(){}Z.prototype={on:function(t,o,e){var n=this.e||(this.e={});return(n[t]||(n[t]=[])).push({fn:o,ctx:e}),this},once:function(t,o,e){var n=this;function a(){n.off(t,a),o.apply(e,arguments)}return a._=o,this.on(t,a,e)},emit:function(t){var o=[].slice.call(arguments,1),e=((this.e||(this.e={}))[t]||[]).slice(),n=0,a=e.length;for(n;n<a;n++)e[n].fn.apply(e[n].ctx,o);return this},off:function(t,o){var e=this.e||(this.e={}),n=e[t],a=[];if(n&&o)for(var r=0,i=n.length;r<i;r++)n[r].fn!==o&&n[r].fn._!==o&&a.push(n[r]);return a.length?e[t]=a:delete e[t],this}},z.exports=Z,z.exports.TinyEmitter=Z;var W={},$=g&&g.__assign||function(){return $=Object.assign||function(t){for(var o,e=1,n=arguments.length;e<n;e++){o=arguments[e];for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&(t[a]=o[a])}return t},$.apply(this,arguments)},Re=g&&g.__awaiter||function(t,o,e,n){function a(r){return r instanceof e?r:new e(function(i){i(r)})}return new(e||(e=Promise))(function(r,i){function d(h){try{s(n.next(h))}catch(m){i(m)}}function v(h){try{s(n.throw(h))}catch(m){i(m)}}function s(h){h.done?r(h.value):a(h.value).then(d,v)}s((n=n.apply(t,o||[])).next())})},Me=g&&g.__generator||function(t,o){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,i;return i={next:d(0),throw:d(1),return:d(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function d(s){return function(h){return v([s,h])}}function v(s){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,a&&(r=s[0]&2?a.return:s[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,s[1])).done)return r;switch(a=0,r&&(s=[s[0]&2,r.value]),s[0]){case 0:case 1:r=s;break;case 4:return e.label++,{value:s[1],done:!1};case 5:e.label++,a=s[1],s=[0];continue;case 7:s=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){e.label=s[1];break}if(s[0]===6&&e.label<r[1]){e.label=r[1],r=s;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(s);break}r[2]&&e.ops.pop(),e.trys.pop();continue}s=o.call(t,e)}catch(h){s=[6,h],a=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(W,"__esModule",{value:!0});var Ae=function(){function t(o){var e=o.onError,n=o.appName,a=o.metricsInterval,r=o.disableMetrics,i=r===void 0?!1:r,d=o.url,v=o.clientKey,s=o.fetch,h=o.headerName;this.onError=e,this.disabled=i,this.metricsInterval=a*1e3,this.appName=n,this.url=d instanceof URL?d:new URL(d),this.clientKey=v,this.bucket=this.createEmptyBucket(),this.fetch=s,this.headerName=h}return t.prototype.start=function(){var o=this;if(this.disabled)return!1;typeof this.metricsInterval=="number"&&this.metricsInterval>0&&setTimeout(function(){o.startTimer(),o.sendMetrics()},2e3)},t.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer)},t.prototype.createEmptyBucket=function(){return{start:new Date,stop:null,toggles:{}}},t.prototype.sendMetrics=function(){return Re(this,void 0,void 0,function(){var o,e,n,a;return Me(this,function(r){switch(r.label){case 0:if(o="".concat(this.url,"/client/metrics"),e=this.getPayload(),this.bucketIsEmpty(e))return[2];r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.fetch(o,{cache:"no-cache",method:"POST",headers:(a={},a[this.headerName]=this.clientKey,a.Accept="application/json",a["Content-Type"]="application/json",a),body:JSON.stringify(e)})];case 2:return r.sent(),[3,4];case 3:return n=r.sent(),console.error("Unleash: unable to send feature metrics",n),this.onError(n),[3,4];case 4:return[2]}})})},t.prototype.count=function(o,e){return this.disabled||!this.bucket?!1:(this.assertBucket(o),this.bucket.toggles[o][e?"yes":"no"]++,!0)},t.prototype.assertBucket=function(o){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[o]||(this.bucket.toggles[o]={yes:0,no:0})},t.prototype.startTimer=function(){var o=this;this.timer=setInterval(function(){o.sendMetrics()},this.metricsInterval)},t.prototype.bucketIsEmpty=function(o){return Object.keys(o.bucket.toggles).length===0},t.prototype.getPayload=function(){var o=$($({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:o,appName:this.appName,instanceId:"browser"}},t}();W.default=Ae;var ee={},he=g&&g.__awaiter||function(t,o,e,n){function a(r){return r instanceof e?r:new e(function(i){i(r)})}return new(e||(e=Promise))(function(r,i){function d(h){try{s(n.next(h))}catch(m){i(m)}}function v(h){try{s(n.throw(h))}catch(m){i(m)}}function s(h){h.done?r(h.value):a(h.value).then(d,v)}s((n=n.apply(t,o||[])).next())})},de=g&&g.__generator||function(t,o){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,i;return i={next:d(0),throw:d(1),return:d(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function d(s){return function(h){return v([s,h])}}function v(s){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,a&&(r=s[0]&2?a.return:s[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,s[1])).done)return r;switch(a=0,r&&(s=[s[0]&2,r.value]),s[0]){case 0:case 1:r=s;break;case 4:return e.label++,{value:s[1],done:!1};case 5:e.label++,a=s[1],s=[0];continue;case 7:s=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){e.label=s[1];break}if(s[0]===6&&e.label<r[1]){e.label=r[1],r=s;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(s);break}r[2]&&e.ops.pop(),e.trys.pop();continue}s=o.call(t,e)}catch(h){s=[6,h],a=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(ee,"__esModule",{value:!0});var ke=function(){function t(){this.store=new Map}return t.prototype.save=function(o,e){return he(this,void 0,void 0,function(){return de(this,function(n){return this.store.set(o,e),[2]})})},t.prototype.get=function(o){return he(this,void 0,void 0,function(){return de(this,function(e){return[2,this.store.get(o)]})})},t}();ee.default=ke;var te={},Ce=g&&g.__awaiter||function(t,o,e,n){function a(r){return r instanceof e?r:new e(function(i){i(r)})}return new(e||(e=Promise))(function(r,i){function d(h){try{s(n.next(h))}catch(m){i(m)}}function v(h){try{s(n.throw(h))}catch(m){i(m)}}function s(h){h.done?r(h.value):a(h.value).then(d,v)}s((n=n.apply(t,o||[])).next())})},Pe=g&&g.__generator||function(t,o){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,i;return i={next:d(0),throw:d(1),return:d(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function d(s){return function(h){return v([s,h])}}function v(s){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,a&&(r=s[0]&2?a.return:s[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,s[1])).done)return r;switch(a=0,r&&(s=[s[0]&2,r.value]),s[0]){case 0:case 1:r=s;break;case 4:return e.label++,{value:s[1],done:!1};case 5:e.label++,a=s[1],s=[0];continue;case 7:s=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){e.label=s[1];break}if(s[0]===6&&e.label<r[1]){e.label=r[1],r=s;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(s);break}r[2]&&e.ops.pop(),e.trys.pop();continue}s=o.call(t,e)}catch(h){s=[6,h],a=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(te,"__esModule",{value:!0});var je=function(){function t(){this.prefix="unleash:repository"}return t.prototype.save=function(o,e){return Ce(this,void 0,void 0,function(){var n,a;return Pe(this,function(r){n=JSON.stringify(e),a="".concat(this.prefix,":").concat(o);try{window.localStorage.setItem(a,n)}catch(i){console.error(i)}return[2]})})},t.prototype.get=function(o){try{var e="".concat(this.prefix,":").concat(o),n=window.localStorage.getItem(e);return n?JSON.parse(n):void 0}catch(a){console.error(a)}},t}();te.default=je;var re={},q,De=new Uint8Array(16);function ve(){if(!q&&(q=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto!="undefined"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!q))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return q(De)}var Le=/^(?:[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;function G(t){return typeof t=="string"&&Le.test(t)}for(var O=[],ne=0;ne<256;++ne)O.push((ne+256).toString(16).substr(1));function B(t){var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=(O[t[o+0]]+O[t[o+1]]+O[t[o+2]]+O[t[o+3]]+"-"+O[t[o+4]]+O[t[o+5]]+"-"+O[t[o+6]]+O[t[o+7]]+"-"+O[t[o+8]]+O[t[o+9]]+"-"+O[t[o+10]]+O[t[o+11]]+O[t[o+12]]+O[t[o+13]]+O[t[o+14]]+O[t[o+15]]).toLowerCase();if(!G(e))throw TypeError("Stringified UUID is invalid");return e}var ye,ae,oe=0,ie=0;function Ve(t,o,e){var n=o&&e||0,a=o||new Array(16);t=t||{};var r=t.node||ye,i=t.clockseq!==void 0?t.clockseq:ae;if(r==null||i==null){var d=t.random||(t.rng||ve)();r==null&&(r=ye=[d[0]|1,d[1],d[2],d[3],d[4],d[5]]),i==null&&(i=ae=(d[6]<<8|d[7])&16383)}var v=t.msecs!==void 0?t.msecs:Date.now(),s=t.nsecs!==void 0?t.nsecs:ie+1,h=v-oe+(s-ie)/1e4;if(h<0&&t.clockseq===void 0&&(i=i+1&16383),(h<0||v>oe)&&t.nsecs===void 0&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");oe=v,ie=s,ae=i,v+=122192928e5;var m=((v&268435455)*1e4+s)%4294967296;a[n++]=m>>>24&255,a[n++]=m>>>16&255,a[n++]=m>>>8&255,a[n++]=m&255;var A=v/4294967296*1e4&268435455;a[n++]=A>>>8&255,a[n++]=A&255,a[n++]=A>>>24&15|16,a[n++]=A>>>16&255,a[n++]=i>>>8|128,a[n++]=i&255;for(var C=0;C<6;++C)a[n+C]=r[C];return o||B(a)}function pe(t){if(!G(t))throw TypeError("Invalid UUID");var o,e=new Uint8Array(16);return e[0]=(o=parseInt(t.slice(0,8),16))>>>24,e[1]=o>>>16&255,e[2]=o>>>8&255,e[3]=o&255,e[4]=(o=parseInt(t.slice(9,13),16))>>>8,e[5]=o&255,e[6]=(o=parseInt(t.slice(14,18),16))>>>8,e[7]=o&255,e[8]=(o=parseInt(t.slice(19,23),16))>>>8,e[9]=o&255,e[10]=(o=parseInt(t.slice(24,36),16))/1099511627776&255,e[11]=o/4294967296&255,e[12]=o>>>24&255,e[13]=o>>>16&255,e[14]=o>>>8&255,e[15]=o&255,e}function Ke(t){t=unescape(encodeURIComponent(t));for(var o=[],e=0;e<t.length;++e)o.push(t.charCodeAt(e));return o}var He="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Fe="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function ge(t,o,e){function n(a,r,i,d){if(typeof a=="string"&&(a=Ke(a)),typeof r=="string"&&(r=pe(r)),r.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var v=new Uint8Array(16+a.length);if(v.set(r),v.set(a,r.length),v=e(v),v[6]=v[6]&15|o,v[8]=v[8]&63|128,i){d=d||0;for(var s=0;s<16;++s)i[d+s]=v[s];return i}return B(v)}try{n.name=t}catch{}return n.DNS=He,n.URL=Fe,n}function $e(t){if(typeof t=="string"){var o=unescape(encodeURIComponent(t));t=new Uint8Array(o.length);for(var e=0;e<o.length;++e)t[e]=o.charCodeAt(e)}return qe(Ge(Be(t),t.length*8))}function qe(t){for(var o=[],e=t.length*32,n="0123456789abcdef",a=0;a<e;a+=8){var r=t[a>>5]>>>a%32&255,i=parseInt(n.charAt(r>>>4&15)+n.charAt(r&15),16);o.push(i)}return o}function me(t){return(t+64>>>9<<4)+14+1}function Ge(t,o){t[o>>5]|=128<<o%32,t[me(o)-1]=o;for(var e=1732584193,n=-271733879,a=-1732584194,r=271733878,i=0;i<t.length;i+=16){var d=e,v=n,s=a,h=r;e=U(e,n,a,r,t[i],7,-680876936),r=U(r,e,n,a,t[i+1],12,-389564586),a=U(a,r,e,n,t[i+2],17,606105819),n=U(n,a,r,e,t[i+3],22,-1044525330),e=U(e,n,a,r,t[i+4],7,-176418897),r=U(r,e,n,a,t[i+5],12,1200080426),a=U(a,r,e,n,t[i+6],17,-1473231341),n=U(n,a,r,e,t[i+7],22,-45705983),e=U(e,n,a,r,t[i+8],7,1770035416),r=U(r,e,n,a,t[i+9],12,-1958414417),a=U(a,r,e,n,t[i+10],17,-42063),n=U(n,a,r,e,t[i+11],22,-1990404162),e=U(e,n,a,r,t[i+12],7,1804603682),r=U(r,e,n,a,t[i+13],12,-40341101),a=U(a,r,e,n,t[i+14],17,-1502002290),n=U(n,a,r,e,t[i+15],22,1236535329),e=x(e,n,a,r,t[i+1],5,-165796510),r=x(r,e,n,a,t[i+6],9,-1069501632),a=x(a,r,e,n,t[i+11],14,643717713),n=x(n,a,r,e,t[i],20,-373897302),e=x(e,n,a,r,t[i+5],5,-701558691),r=x(r,e,n,a,t[i+10],9,38016083),a=x(a,r,e,n,t[i+15],14,-660478335),n=x(n,a,r,e,t[i+4],20,-405537848),e=x(e,n,a,r,t[i+9],5,568446438),r=x(r,e,n,a,t[i+14],9,-1019803690),a=x(a,r,e,n,t[i+3],14,-187363961),n=x(n,a,r,e,t[i+8],20,1163531501),e=x(e,n,a,r,t[i+13],5,-1444681467),r=x(r,e,n,a,t[i+2],9,-51403784),a=x(a,r,e,n,t[i+7],14,1735328473),n=x(n,a,r,e,t[i+12],20,-1926607734),e=R(e,n,a,r,t[i+5],4,-378558),r=R(r,e,n,a,t[i+8],11,-2022574463),a=R(a,r,e,n,t[i+11],16,1839030562),n=R(n,a,r,e,t[i+14],23,-35309556),e=R(e,n,a,r,t[i+1],4,-1530992060),r=R(r,e,n,a,t[i+4],11,1272893353),a=R(a,r,e,n,t[i+7],16,-155497632),n=R(n,a,r,e,t[i+10],23,-1094730640),e=R(e,n,a,r,t[i+13],4,681279174),r=R(r,e,n,a,t[i],11,-358537222),a=R(a,r,e,n,t[i+3],16,-722521979),n=R(n,a,r,e,t[i+6],23,76029189),e=R(e,n,a,r,t[i+9],4,-640364487),r=R(r,e,n,a,t[i+12],11,-421815835),a=R(a,r,e,n,t[i+15],16,530742520),n=R(n,a,r,e,t[i+2],23,-995338651),e=M(e,n,a,r,t[i],6,-198630844),r=M(r,e,n,a,t[i+7],10,1126891415),a=M(a,r,e,n,t[i+14],15,-1416354905),n=M(n,a,r,e,t[i+5],21,-57434055),e=M(e,n,a,r,t[i+12],6,1700485571),r=M(r,e,n,a,t[i+3],10,-1894986606),a=M(a,r,e,n,t[i+10],15,-1051523),n=M(n,a,r,e,t[i+1],21,-2054922799),e=M(e,n,a,r,t[i+8],6,1873313359),r=M(r,e,n,a,t[i+15],10,-30611744),a=M(a,r,e,n,t[i+6],15,-1560198380),n=M(n,a,r,e,t[i+13],21,1309151649),e=M(e,n,a,r,t[i+4],6,-145523070),r=M(r,e,n,a,t[i+11],10,-1120210379),a=M(a,r,e,n,t[i+2],15,718787259),n=M(n,a,r,e,t[i+9],21,-343485551),e=L(e,d),n=L(n,v),a=L(a,s),r=L(r,h)}return[e,n,a,r]}function Be(t){if(t.length===0)return[];for(var o=t.length*8,e=new Uint32Array(me(o)),n=0;n<o;n+=8)e[n>>5]|=(t[n/8]&255)<<n%32;return e}function L(t,o){var e=(t&65535)+(o&65535),n=(t>>16)+(o>>16)+(e>>16);return n<<16|e&65535}function Ye(t,o){return t<<o|t>>>32-o}function Y(t,o,e,n,a,r){return L(Ye(L(L(o,t),L(n,r)),a),e)}function U(t,o,e,n,a,r,i){return Y(o&e|~o&n,t,o,a,r,i)}function x(t,o,e,n,a,r,i){return Y(o&n|e&~n,t,o,a,r,i)}function R(t,o,e,n,a,r,i){return Y(o^e^n,t,o,a,r,i)}function M(t,o,e,n,a,r,i){return Y(e^(o|~n),t,o,a,r,i)}var Je=ge("v3",48,$e),Qe=Je;function Xe(t,o,e){t=t||{};var n=t.random||(t.rng||ve)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,o){e=e||0;for(var a=0;a<16;++a)o[e+a]=n[a];return o}return B(n)}function ze(t,o,e,n){switch(t){case 0:return o&e^~o&n;case 1:return o^e^n;case 2:return o&e^o&n^e&n;case 3:return o^e^n}}function se(t,o){return t<<o|t>>>32-o}function Ze(t){var o=[1518500249,1859775393,2400959708,3395469782],e=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof t=="string"){var n=unescape(encodeURIComponent(t));t=[];for(var a=0;a<n.length;++a)t.push(n.charCodeAt(a))}else Array.isArray(t)||(t=Array.prototype.slice.call(t));t.push(128);for(var r=t.length/4+2,i=Math.ceil(r/16),d=new Array(i),v=0;v<i;++v){for(var s=new Uint32Array(16),h=0;h<16;++h)s[h]=t[v*64+h*4]<<24|t[v*64+h*4+1]<<16|t[v*64+h*4+2]<<8|t[v*64+h*4+3];d[v]=s}d[i-1][14]=(t.length-1)*8/Math.pow(2,32),d[i-1][14]=Math.floor(d[i-1][14]),d[i-1][15]=(t.length-1)*8&4294967295;for(var m=0;m<i;++m){for(var A=new Uint32Array(80),C=0;C<16;++C)A[C]=d[m][C];for(var P=16;P<80;++P)A[P]=se(A[P-3]^A[P-8]^A[P-14]^A[P-16],1);for(var w=e[0],T=e[1],j=e[2],I=e[3],y=e[4],u=0;u<80;++u){var f=Math.floor(u/20),c=se(w,5)+ze(f,T,j,I)+y+o[f]+A[u]>>>0;y=I,I=j,j=se(T,30)>>>0,T=w,w=c}e[0]=e[0]+w>>>0,e[1]=e[1]+T>>>0,e[2]=e[2]+j>>>0,e[3]=e[3]+I>>>0,e[4]=e[4]+y>>>0}return[e[0]>>24&255,e[0]>>16&255,e[0]>>8&255,e[0]&255,e[1]>>24&255,e[1]>>16&255,e[1]>>8&255,e[1]&255,e[2]>>24&255,e[2]>>16&255,e[2]>>8&255,e[2]&255,e[3]>>24&255,e[3]>>16&255,e[3]>>8&255,e[3]&255,e[4]>>24&255,e[4]>>16&255,e[4]>>8&255,e[4]&255]}var We=ge("v5",80,Ze),et=We,tt="00000000-0000-0000-0000-000000000000";function rt(t){if(!G(t))throw TypeError("Invalid UUID");return parseInt(t.substr(14,1),16)}var nt=Object.freeze(Object.defineProperty({__proto__:null,v1:Ve,v3:Qe,v4:Xe,v5:et,NIL:tt,version:rt,validate:G,stringify:B,parse:pe},Symbol.toStringTag,{value:"Module"})),at=xe(nt),J=g&&g.__assign||function(){return J=Object.assign||function(t){for(var o,e=1,n=arguments.length;e<n;e++){o=arguments[e];for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&(t[a]=o[a])}return t},J.apply(this,arguments)};Object.defineProperty(re,"__esModule",{value:!0});var ot=at,it=function(){function t(){}return t.prototype.generateEventId=function(){return(0,ot.v4)()},t.prototype.createImpressionEvent=function(o,e,n,a,r){var i=this.createBaseEvent(o,e,n,a);return r?J(J({},i),{variant:r}):i},t.prototype.createBaseEvent=function(o,e,n,a){return{eventType:a,eventId:this.generateEventId(),context:o,enabled:e,featureName:n}},t}();re.default=it;var Q={};Object.defineProperty(Q,"__esModule",{value:!0}),Q.notNullOrUndefined=void 0;var st=function(t){var o=t[1];return o!=null};Q.notNullOrUndefined=st,function(t){var o=g&&g.__extends||function(){var I=function(y,u){return I=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(f,c){f.__proto__=c}||function(f,c){for(var l in c)Object.prototype.hasOwnProperty.call(c,l)&&(f[l]=c[l])},I(y,u)};return function(y,u){if(typeof u!="function"&&u!==null)throw new TypeError("Class extends value "+String(u)+" is not a constructor or null");I(y,u);function f(){this.constructor=y}y.prototype=u===null?Object.create(u):(f.prototype=u.prototype,new f)}}(),e=g&&g.__assign||function(){return e=Object.assign||function(I){for(var y,u=1,f=arguments.length;u<f;u++){y=arguments[u];for(var c in y)Object.prototype.hasOwnProperty.call(y,c)&&(I[c]=y[c])}return I},e.apply(this,arguments)},n=g&&g.__awaiter||function(I,y,u,f){function c(l){return l instanceof u?l:new u(function(S){S(l)})}return new(u||(u=Promise))(function(l,S){function k(N){try{p(f.next(N))}catch(K){S(K)}}function D(N){try{p(f.throw(N))}catch(K){S(K)}}function p(N){N.done?l(N.value):c(N.value).then(k,D)}p((f=f.apply(I,y||[])).next())})},a=g&&g.__generator||function(I,y){var u={label:0,sent:function(){if(l[0]&1)throw l[1];return l[1]},trys:[],ops:[]},f,c,l,S;return S={next:k(0),throw:k(1),return:k(2)},typeof Symbol=="function"&&(S[Symbol.iterator]=function(){return this}),S;function k(p){return function(N){return D([p,N])}}function D(p){if(f)throw new TypeError("Generator is already executing.");for(;u;)try{if(f=1,c&&(l=p[0]&2?c.return:p[0]?c.throw||((l=c.return)&&l.call(c),0):c.next)&&!(l=l.call(c,p[1])).done)return l;switch(c=0,l&&(p=[p[0]&2,l.value]),p[0]){case 0:case 1:l=p;break;case 4:return u.label++,{value:p[1],done:!1};case 5:u.label++,c=p[1],p=[0];continue;case 7:p=u.ops.pop(),u.trys.pop();continue;default:if(l=u.trys,!(l=l.length>0&&l[l.length-1])&&(p[0]===6||p[0]===2)){u=0;continue}if(p[0]===3&&(!l||p[1]>l[0]&&p[1]<l[3])){u.label=p[1];break}if(p[0]===6&&u.label<l[1]){u.label=l[1],l=p;break}if(l&&u.label<l[2]){u.label=l[2],u.ops.push(p);break}l[2]&&u.ops.pop(),u.trys.pop();continue}p=y.call(I,u)}catch(N){p=[6,N],c=0}finally{f=l=0}if(p[0]&5)throw p[1];return{value:p[0]?p[1]:void 0,done:!0}}},r=g&&g.__spreadArray||function(I,y,u){if(u||arguments.length===2)for(var f=0,c=y.length,l;f<c;f++)(l||!(f in y))&&(l||(l=Array.prototype.slice.call(y,0,f)),l[f]=y[f]);return I.concat(l||Array.prototype.slice.call(y))};Object.defineProperty(t,"__esModule",{value:!0}),t.InMemoryStorageProvider=t.LocalStorageProvider=t.UnleashClient=t.resolveFetch=t.EVENTS=void 0;var i=z.exports,d=W,v=ee;t.InMemoryStorageProvider=v.default;var s=te;t.LocalStorageProvider=s.default;var h=re,m=Q,A=["userId","sessionId","remoteAddress"];t.EVENTS={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression"};var C={IS_ENABLED:"isEnabled",GET_VARIANT:"getVariant"},P={name:"disabled",enabled:!1},w="repo",T=function(){try{if("fetch"in window)return fetch.bind(window);if("fetch"in globalThis)return fetch.bind(globalThis)}catch(I){console.error('Unleash failed to resolve "fetch"',I)}};t.resolveFetch=T;var j=function(I){o(y,I);function y(u){var f=u.storageProvider,c=u.url,l=u.clientKey,S=u.disableRefresh,k=S===void 0?!1:S,D=u.refreshInterval,p=D===void 0?30:D,N=u.metricsInterval,K=N===void 0?30:N,X=u.disableMetrics,fe=X===void 0?!1:X,ce=u.appName,Ee=u.environment,vt=Ee===void 0?"default":Ee,yt=u.context,Ie=u.fetch,le=Ie===void 0?(0,t.resolveFetch)():Ie,H=u.bootstrap,Se=u.bootstrapOverride,pt=Se===void 0?!0:Se,_e=u.headerName,Te=_e===void 0?"Authorization":_e,Ne=u.customHeaders,gt=Ne===void 0?{}:Ne,E=I.call(this)||this;if(E.toggles=[],E.etag="",E.readyEventEmitted=!1,!c)throw new Error("url is required");if(!l)throw new Error("clientKey is required");if(!ce)throw new Error("appName is required.");return E.eventsHandler=new h.default,E.toggles=H&&H.length>0?H:[],E.url=c instanceof URL?c:new URL(c),E.clientKey=l,E.headerName=Te,E.customHeaders=gt,E.storage=f||new s.default,E.refreshInterval=k?0:p*1e3,E.context=e({appName:ce,environment:vt},yt),E.ready=new Promise(function(Oe){E.init().then(Oe).catch(function(Ue){console.error(Ue),E.emit(t.EVENTS.ERROR,Ue),Oe()})}),le||console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'),E.fetch=le,E.bootstrap=H&&H.length>0?H:void 0,E.bootstrapOverride=pt,E.metrics=new d.default({onError:E.emit.bind(E,t.EVENTS.ERROR),appName:ce,metricsInterval:K,disableMetrics:fe,url:E.url,clientKey:l,fetch:le,headerName:Te}),E}return y.prototype.getAllToggles=function(){return r([],this.toggles,!0)},y.prototype.isEnabled=function(u){var f=this.toggles.find(function(S){return S.name===u}),c=f?f.enabled:!1;if(this.metrics.count(u,c),f!=null&&f.impressionData){var l=this.eventsHandler.createImpressionEvent(this.context,c,u,C.IS_ENABLED);this.emit(t.EVENTS.IMPRESSION,l)}return c},y.prototype.getVariant=function(u){var f=this.toggles.find(function(l){return l.name===u});if(f){if(this.metrics.count(u,!0),f.impressionData){var c=this.eventsHandler.createImpressionEvent(this.context,f.enabled,u,C.GET_VARIANT,f.variant.name);this.emit(t.EVENTS.IMPRESSION,c)}return f.variant}else return this.metrics.count(u,!1),P},y.prototype.updateContext=function(u){return n(this,void 0,void 0,function(){var f;return a(this,function(c){switch(c.label){case 0:return(u.appName||u.environment)&&console.warn("appName and environment are static. They can't be updated with updateContext."),f={environment:this.context.environment,appName:this.context.appName},this.context=e(e({},f),u),this.timerRef?[4,this.fetchToggles()]:[3,2];case 1:c.sent(),c.label=2;case 2:return[2]}})})},y.prototype.getContext=function(){return e({},this.context)},y.prototype.setContextField=function(u,f){var c,l;if(A.includes(u))this.context=e(e({},this.context),(c={},c[u]=f,c));else{var S=e(e({},this.context.properties),(l={},l[u]=f,l));this.context=e(e({},this.context),{properties:S})}this.timerRef&&this.fetchToggles()},y.prototype.init=function(){return n(this,void 0,void 0,function(){var u,f;return a(this,function(c){switch(c.label){case 0:return[4,this.resolveSessionId()];case 1:return u=c.sent(),this.context=e({sessionId:u},this.context),f=this,[4,this.storage.get(w)];case 2:return f.toggles=c.sent()||[],this.bootstrap&&(this.bootstrapOverride||this.toggles.length===0)?[4,this.storage.save(w,this.bootstrap)]:[3,4];case 3:c.sent(),this.toggles=this.bootstrap,this.emit(t.EVENTS.READY),c.label=4;case 4:return this.emit(t.EVENTS.INIT),[2]}})})},y.prototype.start=function(){return n(this,void 0,void 0,function(){var u,f=this;return a(this,function(c){switch(c.label){case 0:return 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 c.sent(),this.metrics.start(),u=this.refreshInterval,[4,this.fetchToggles()];case 2:return c.sent(),u>0&&(this.timerRef=setInterval(function(){return f.fetchToggles()},u)),[2]}})})},y.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},y.prototype.resolveSessionId=function(){return n(this,void 0,void 0,function(){var u;return a(this,function(f){switch(f.label){case 0:return this.context.sessionId?[2,this.context.sessionId]:[3,1];case 1:return[4,this.storage.get("sessionId")];case 2:return u=f.sent(),u?[3,4]:(u=Math.floor(Math.random()*1e9),[4,this.storage.save("sessionId",u)]);case 3:f.sent(),f.label=4;case 4:return[2,u]}})})},y.prototype.getHeaders=function(){var u,f=(u={},u[this.headerName]=this.clientKey,u.Accept="application/json",u["Content-Type"]="application/json",u["If-None-Match"]=this.etag,u);return Object.entries(this.customHeaders).filter(m.notNullOrUndefined).forEach(function(c){var l=c[0],S=c[1];return f[l]=S}),f},y.prototype.storeToggles=function(u){return n(this,void 0,void 0,function(){return a(this,function(f){switch(f.label){case 0:return this.toggles=u,this.emit(t.EVENTS.UPDATE),[4,this.storage.save(w,u)];case 1:return f.sent(),[2]}})})},y.prototype.fetchToggles=function(){return n(this,void 0,void 0,function(){var u,f,c,l,S;return a(this,function(k){switch(k.label){case 0:if(!this.fetch)return[3,7];k.label=1;case 1:return k.trys.push([1,6,,7]),u=this.context,f=new URL(this.url.toString()),Object.entries(u).filter(m.notNullOrUndefined).forEach(function(D){var p=D[0],N=D[1];p==="properties"&&N?Object.entries(N).filter(m.notNullOrUndefined).forEach(function(K){var X=K[0],fe=K[1];return f.searchParams.append("properties[".concat(X,"]"),fe)}):f.searchParams.append(p,N)}),[4,this.fetch(f.toString(),{cache:"no-cache",headers:this.getHeaders()})];case 2:return c=k.sent(),c.ok&&c.status!==304?(this.etag=c.headers.get("ETag")||"",[4,c.json()]):[3,5];case 3:return l=k.sent(),[4,this.storeToggles(l.toggles)];case 4:k.sent(),!this.bootstrap&&!this.readyEventEmitted&&(this.emit(t.EVENTS.READY),this.readyEventEmitted=!0),k.label=5;case 5:return[3,7];case 6:return S=k.sent(),console.error("Unleash: unable to fetch feature toggles",S),this.emit(t.EVENTS.ERROR,S),[3,7];case 7:return[2]}})})},y}(i.TinyEmitter);t.UnleashClient=j}(F);const V=Symbol("Context state identifier"),ue=Symbol("Context update identifier");function be({config:t,unleashClient:o,startClient:e=!0}){var C,P;const n=b.ref(o),a=b.ref(!1),r=b.ref(null);!t&&!o&&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.`),!n.value&&t&&(n.value=new
|
|
1
|
+
(function(T,E){typeof exports=="object"&&typeof module!="undefined"?E(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],E):(T=typeof globalThis!="undefined"?globalThis:T||self,E(T["proxy-client-vue"]={},T.Vue))})(this,function(T,E){"use strict";var w=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function xe(t){if(t.__esModule)return t;var o=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach(function(e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(o,e,n.get?n:{enumerable:!0,get:function(){return t[e]}})}),o}var K={},J={exports:{}};function X(){}X.prototype={on:function(t,o,e){var n=this.e||(this.e={});return(n[t]||(n[t]=[])).push({fn:o,ctx:e}),this},once:function(t,o,e){var n=this;function a(){n.off(t,a),o.apply(e,arguments)}return a._=o,this.on(t,a,e)},emit:function(t){var o=[].slice.call(arguments,1),e=((this.e||(this.e={}))[t]||[]).slice(),n=0,a=e.length;for(n;n<a;n++)e[n].fn.apply(e[n].ctx,o);return this},off:function(t,o){var e=this.e||(this.e={}),n=e[t],a=[];if(n&&o)for(var r=0,i=n.length;r<i;r++)n[r].fn!==o&&n[r].fn._!==o&&a.push(n[r]);return a.length?e[t]=a:delete e[t],this}},J.exports=X,J.exports.TinyEmitter=X;var z={},W={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.urlWithContextAsQuery=t.notNullOrUndefined=void 0;var o=function(n){var a=n[1];return a!=null};t.notNullOrUndefined=o;var e=function(n,a){var r=new URL(n.toString());return Object.entries(a).filter(t.notNullOrUndefined).forEach(function(i){var h=i[0],v=i[1];h==="properties"&&v?Object.entries(v).filter(t.notNullOrUndefined).forEach(function(s){var d=s[0],m=s[1];return r.searchParams.append("properties[".concat(d,"]"),m)}):r.searchParams.append(h,v)}),r};t.urlWithContextAsQuery=e})(W);var F=w&&w.__assign||function(){return F=Object.assign||function(t){for(var o,e=1,n=arguments.length;e<n;e++){o=arguments[e];for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&(t[a]=o[a])}return t},F.apply(this,arguments)},ke=w&&w.__awaiter||function(t,o,e,n){function a(r){return r instanceof e?r:new e(function(i){i(r)})}return new(e||(e=Promise))(function(r,i){function h(d){try{s(n.next(d))}catch(m){i(m)}}function v(d){try{s(n.throw(d))}catch(m){i(m)}}function s(d){d.done?r(d.value):a(d.value).then(h,v)}s((n=n.apply(t,o||[])).next())})},Pe=w&&w.__generator||function(t,o){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,i;return i={next:h(0),throw:h(1),return:h(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function h(s){return function(d){return v([s,d])}}function v(s){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,a&&(r=s[0]&2?a.return:s[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,s[1])).done)return r;switch(a=0,r&&(s=[s[0]&2,r.value]),s[0]){case 0:case 1:r=s;break;case 4:return e.label++,{value:s[1],done:!1};case 5:e.label++,a=s[1],s=[0];continue;case 7:s=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){e.label=s[1];break}if(s[0]===6&&e.label<r[1]){e.label=r[1],r=s;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(s);break}r[2]&&e.ops.pop(),e.trys.pop();continue}s=o.call(t,e)}catch(d){s=[6,d],a=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(z,"__esModule",{value:!0});var Ce=W,Me=function(){},je=function(){function t(o){var e=o.onError,n=o.onSent,a=o.appName,r=o.metricsInterval,i=o.disableMetrics,h=i===void 0?!1:i,v=o.url,s=o.clientKey,d=o.fetch,m=o.headerName,_=o.customHeaders,R=_===void 0?{}:_;this.onError=e,this.onSent=n||Me,this.disabled=h,this.metricsInterval=r*1e3,this.appName=a,this.url=v instanceof URL?v:new URL(v),this.clientKey=s,this.bucket=this.createEmptyBucket(),this.fetch=d,this.headerName=m,this.customHeaders=R}return t.prototype.start=function(){var o=this;if(this.disabled)return!1;typeof this.metricsInterval=="number"&&this.metricsInterval>0&&setTimeout(function(){o.startTimer(),o.sendMetrics()},2e3)},t.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer)},t.prototype.createEmptyBucket=function(){return{start:new Date,stop:null,toggles:{}}},t.prototype.getHeaders=function(){var o,e=(o={},o[this.headerName]=this.clientKey,o.Accept="application/json",o["Content-Type"]="application/json",o);return Object.entries(this.customHeaders).filter(Ce.notNullOrUndefined).forEach(function(n){var a=n[0],r=n[1];return e[a]=r}),e},t.prototype.sendMetrics=function(){return ke(this,void 0,void 0,function(){var o,e,n;return Pe(this,function(a){switch(a.label){case 0:if(o="".concat(this.url,"/client/metrics"),e=this.getPayload(),this.bucketIsEmpty(e))return[2];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.fetch(o,{cache:"no-cache",method:"POST",headers:this.getHeaders(),body:JSON.stringify(e)})];case 2:return a.sent(),this.onSent(e),[3,4];case 3:return n=a.sent(),console.error("Unleash: unable to send feature metrics",n),this.onError(n),[3,4];case 4:return[2]}})})},t.prototype.count=function(o,e){return this.disabled||!this.bucket?!1:(this.assertBucket(o),this.bucket.toggles[o][e?"yes":"no"]++,!0)},t.prototype.countVariant=function(o,e){return this.disabled||!this.bucket?!1:(this.assertBucket(o),this.bucket.toggles[o].variants[e]?this.bucket.toggles[o].variants[e]+=1:this.bucket.toggles[o].variants[e]=1,!0)},t.prototype.assertBucket=function(o){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[o]||(this.bucket.toggles[o]={yes:0,no:0,variants:{}})},t.prototype.startTimer=function(){var o=this;this.timer=setInterval(function(){o.sendMetrics()},this.metricsInterval)},t.prototype.bucketIsEmpty=function(o){return Object.keys(o.bucket.toggles).length===0},t.prototype.getPayload=function(){var o=F(F({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:o,appName:this.appName,instanceId:"browser"}},t}();z.default=je;var Z={},ce=w&&w.__awaiter||function(t,o,e,n){function a(r){return r instanceof e?r:new e(function(i){i(r)})}return new(e||(e=Promise))(function(r,i){function h(d){try{s(n.next(d))}catch(m){i(m)}}function v(d){try{s(n.throw(d))}catch(m){i(m)}}function s(d){d.done?r(d.value):a(d.value).then(h,v)}s((n=n.apply(t,o||[])).next())})},le=w&&w.__generator||function(t,o){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,i;return i={next:h(0),throw:h(1),return:h(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function h(s){return function(d){return v([s,d])}}function v(s){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,a&&(r=s[0]&2?a.return:s[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,s[1])).done)return r;switch(a=0,r&&(s=[s[0]&2,r.value]),s[0]){case 0:case 1:r=s;break;case 4:return e.label++,{value:s[1],done:!1};case 5:e.label++,a=s[1],s=[0];continue;case 7:s=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){e.label=s[1];break}if(s[0]===6&&e.label<r[1]){e.label=r[1],r=s;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(s);break}r[2]&&e.ops.pop(),e.trys.pop();continue}s=o.call(t,e)}catch(d){s=[6,d],a=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(Z,"__esModule",{value:!0});var De=function(){function t(){this.store=new Map}return t.prototype.save=function(o,e){return ce(this,void 0,void 0,function(){return le(this,function(n){return this.store.set(o,e),[2]})})},t.prototype.get=function(o){return ce(this,void 0,void 0,function(){return le(this,function(e){return[2,this.store.get(o)]})})},t}();Z.default=De;var ee={},Ve=w&&w.__awaiter||function(t,o,e,n){function a(r){return r instanceof e?r:new e(function(i){i(r)})}return new(e||(e=Promise))(function(r,i){function h(d){try{s(n.next(d))}catch(m){i(m)}}function v(d){try{s(n.throw(d))}catch(m){i(m)}}function s(d){d.done?r(d.value):a(d.value).then(h,v)}s((n=n.apply(t,o||[])).next())})},He=w&&w.__generator||function(t,o){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,i;return i={next:h(0),throw:h(1),return:h(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function h(s){return function(d){return v([s,d])}}function v(s){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,a&&(r=s[0]&2?a.return:s[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,s[1])).done)return r;switch(a=0,r&&(s=[s[0]&2,r.value]),s[0]){case 0:case 1:r=s;break;case 4:return e.label++,{value:s[1],done:!1};case 5:e.label++,a=s[1],s=[0];continue;case 7:s=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){e.label=s[1];break}if(s[0]===6&&e.label<r[1]){e.label=r[1],r=s;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(s);break}r[2]&&e.ops.pop(),e.trys.pop();continue}s=o.call(t,e)}catch(d){s=[6,d],a=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(ee,"__esModule",{value:!0});var Le=function(){function t(){this.prefix="unleash:repository"}return t.prototype.save=function(o,e){return Ve(this,void 0,void 0,function(){var n,a;return He(this,function(r){n=JSON.stringify(e),a="".concat(this.prefix,":").concat(o);try{window.localStorage.setItem(a,n)}catch(i){console.error(i)}return[2]})})},t.prototype.get=function(o){try{var e="".concat(this.prefix,":").concat(o),n=window.localStorage.getItem(e);return n?JSON.parse(n):void 0}catch(a){console.error(a)}},t}();ee.default=Le;var te={},$,Ke=new Uint8Array(16);function de(){if(!$&&($=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto!="undefined"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!$))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return $(Ke)}var qe=/^(?:[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;function G(t){return typeof t=="string"&&qe.test(t)}for(var O=[],re=0;re<256;++re)O.push((re+256).toString(16).substr(1));function B(t){var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=(O[t[o+0]]+O[t[o+1]]+O[t[o+2]]+O[t[o+3]]+"-"+O[t[o+4]]+O[t[o+5]]+"-"+O[t[o+6]]+O[t[o+7]]+"-"+O[t[o+8]]+O[t[o+9]]+"-"+O[t[o+10]]+O[t[o+11]]+O[t[o+12]]+O[t[o+13]]+O[t[o+14]]+O[t[o+15]]).toLowerCase();if(!G(e))throw TypeError("Stringified UUID is invalid");return e}var he,ne,ae=0,oe=0;function Fe(t,o,e){var n=o&&e||0,a=o||new Array(16);t=t||{};var r=t.node||he,i=t.clockseq!==void 0?t.clockseq:ne;if(r==null||i==null){var h=t.random||(t.rng||de)();r==null&&(r=he=[h[0]|1,h[1],h[2],h[3],h[4],h[5]]),i==null&&(i=ne=(h[6]<<8|h[7])&16383)}var v=t.msecs!==void 0?t.msecs:Date.now(),s=t.nsecs!==void 0?t.nsecs:oe+1,d=v-ae+(s-oe)/1e4;if(d<0&&t.clockseq===void 0&&(i=i+1&16383),(d<0||v>ae)&&t.nsecs===void 0&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");ae=v,oe=s,ne=i,v+=122192928e5;var m=((v&268435455)*1e4+s)%4294967296;a[n++]=m>>>24&255,a[n++]=m>>>16&255,a[n++]=m>>>8&255,a[n++]=m&255;var _=v/4294967296*1e4&268435455;a[n++]=_>>>8&255,a[n++]=_&255,a[n++]=_>>>24&15|16,a[n++]=_>>>16&255,a[n++]=i>>>8|128,a[n++]=i&255;for(var R=0;R<6;++R)a[n+R]=r[R];return o||B(a)}function ve(t){if(!G(t))throw TypeError("Invalid UUID");var o,e=new Uint8Array(16);return e[0]=(o=parseInt(t.slice(0,8),16))>>>24,e[1]=o>>>16&255,e[2]=o>>>8&255,e[3]=o&255,e[4]=(o=parseInt(t.slice(9,13),16))>>>8,e[5]=o&255,e[6]=(o=parseInt(t.slice(14,18),16))>>>8,e[7]=o&255,e[8]=(o=parseInt(t.slice(19,23),16))>>>8,e[9]=o&255,e[10]=(o=parseInt(t.slice(24,36),16))/1099511627776&255,e[11]=o/4294967296&255,e[12]=o>>>24&255,e[13]=o>>>16&255,e[14]=o>>>8&255,e[15]=o&255,e}function $e(t){t=unescape(encodeURIComponent(t));for(var o=[],e=0;e<t.length;++e)o.push(t.charCodeAt(e));return o}var Ge="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Be="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function ye(t,o,e){function n(a,r,i,h){if(typeof a=="string"&&(a=$e(a)),typeof r=="string"&&(r=ve(r)),r.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var v=new Uint8Array(16+a.length);if(v.set(r),v.set(a,r.length),v=e(v),v[6]=v[6]&15|o,v[8]=v[8]&63|128,i){h=h||0;for(var s=0;s<16;++s)i[h+s]=v[s];return i}return B(v)}try{n.name=t}catch{}return n.DNS=Ge,n.URL=Be,n}function Ye(t){if(typeof t=="string"){var o=unescape(encodeURIComponent(t));t=new Uint8Array(o.length);for(var e=0;e<o.length;++e)t[e]=o.charCodeAt(e)}return Qe(Je(Xe(t),t.length*8))}function Qe(t){for(var o=[],e=t.length*32,n="0123456789abcdef",a=0;a<e;a+=8){var r=t[a>>5]>>>a%32&255,i=parseInt(n.charAt(r>>>4&15)+n.charAt(r&15),16);o.push(i)}return o}function pe(t){return(t+64>>>9<<4)+14+1}function Je(t,o){t[o>>5]|=128<<o%32,t[pe(o)-1]=o;for(var e=1732584193,n=-271733879,a=-1732584194,r=271733878,i=0;i<t.length;i+=16){var h=e,v=n,s=a,d=r;e=A(e,n,a,r,t[i],7,-680876936),r=A(r,e,n,a,t[i+1],12,-389564586),a=A(a,r,e,n,t[i+2],17,606105819),n=A(n,a,r,e,t[i+3],22,-1044525330),e=A(e,n,a,r,t[i+4],7,-176418897),r=A(r,e,n,a,t[i+5],12,1200080426),a=A(a,r,e,n,t[i+6],17,-1473231341),n=A(n,a,r,e,t[i+7],22,-45705983),e=A(e,n,a,r,t[i+8],7,1770035416),r=A(r,e,n,a,t[i+9],12,-1958414417),a=A(a,r,e,n,t[i+10],17,-42063),n=A(n,a,r,e,t[i+11],22,-1990404162),e=A(e,n,a,r,t[i+12],7,1804603682),r=A(r,e,n,a,t[i+13],12,-40341101),a=A(a,r,e,n,t[i+14],17,-1502002290),n=A(n,a,r,e,t[i+15],22,1236535329),e=x(e,n,a,r,t[i+1],5,-165796510),r=x(r,e,n,a,t[i+6],9,-1069501632),a=x(a,r,e,n,t[i+11],14,643717713),n=x(n,a,r,e,t[i],20,-373897302),e=x(e,n,a,r,t[i+5],5,-701558691),r=x(r,e,n,a,t[i+10],9,38016083),a=x(a,r,e,n,t[i+15],14,-660478335),n=x(n,a,r,e,t[i+4],20,-405537848),e=x(e,n,a,r,t[i+9],5,568446438),r=x(r,e,n,a,t[i+14],9,-1019803690),a=x(a,r,e,n,t[i+3],14,-187363961),n=x(n,a,r,e,t[i+8],20,1163531501),e=x(e,n,a,r,t[i+13],5,-1444681467),r=x(r,e,n,a,t[i+2],9,-51403784),a=x(a,r,e,n,t[i+7],14,1735328473),n=x(n,a,r,e,t[i+12],20,-1926607734),e=k(e,n,a,r,t[i+5],4,-378558),r=k(r,e,n,a,t[i+8],11,-2022574463),a=k(a,r,e,n,t[i+11],16,1839030562),n=k(n,a,r,e,t[i+14],23,-35309556),e=k(e,n,a,r,t[i+1],4,-1530992060),r=k(r,e,n,a,t[i+4],11,1272893353),a=k(a,r,e,n,t[i+7],16,-155497632),n=k(n,a,r,e,t[i+10],23,-1094730640),e=k(e,n,a,r,t[i+13],4,681279174),r=k(r,e,n,a,t[i],11,-358537222),a=k(a,r,e,n,t[i+3],16,-722521979),n=k(n,a,r,e,t[i+6],23,76029189),e=k(e,n,a,r,t[i+9],4,-640364487),r=k(r,e,n,a,t[i+12],11,-421815835),a=k(a,r,e,n,t[i+15],16,530742520),n=k(n,a,r,e,t[i+2],23,-995338651),e=P(e,n,a,r,t[i],6,-198630844),r=P(r,e,n,a,t[i+7],10,1126891415),a=P(a,r,e,n,t[i+14],15,-1416354905),n=P(n,a,r,e,t[i+5],21,-57434055),e=P(e,n,a,r,t[i+12],6,1700485571),r=P(r,e,n,a,t[i+3],10,-1894986606),a=P(a,r,e,n,t[i+10],15,-1051523),n=P(n,a,r,e,t[i+1],21,-2054922799),e=P(e,n,a,r,t[i+8],6,1873313359),r=P(r,e,n,a,t[i+15],10,-30611744),a=P(a,r,e,n,t[i+6],15,-1560198380),n=P(n,a,r,e,t[i+13],21,1309151649),e=P(e,n,a,r,t[i+4],6,-145523070),r=P(r,e,n,a,t[i+11],10,-1120210379),a=P(a,r,e,n,t[i+2],15,718787259),n=P(n,a,r,e,t[i+9],21,-343485551),e=V(e,h),n=V(n,v),a=V(a,s),r=V(r,d)}return[e,n,a,r]}function Xe(t){if(t.length===0)return[];for(var o=t.length*8,e=new Uint32Array(pe(o)),n=0;n<o;n+=8)e[n>>5]|=(t[n/8]&255)<<n%32;return e}function V(t,o){var e=(t&65535)+(o&65535),n=(t>>16)+(o>>16)+(e>>16);return n<<16|e&65535}function ze(t,o){return t<<o|t>>>32-o}function Y(t,o,e,n,a,r){return V(ze(V(V(o,t),V(n,r)),a),e)}function A(t,o,e,n,a,r,i){return Y(o&e|~o&n,t,o,a,r,i)}function x(t,o,e,n,a,r,i){return Y(o&n|e&~n,t,o,a,r,i)}function k(t,o,e,n,a,r,i){return Y(o^e^n,t,o,a,r,i)}function P(t,o,e,n,a,r,i){return Y(e^(o|~n),t,o,a,r,i)}var We=ye("v3",48,Ye),Ze=We;function et(t,o,e){t=t||{};var n=t.random||(t.rng||de)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,o){e=e||0;for(var a=0;a<16;++a)o[e+a]=n[a];return o}return B(n)}function tt(t,o,e,n){switch(t){case 0:return o&e^~o&n;case 1:return o^e^n;case 2:return o&e^o&n^e&n;case 3:return o^e^n}}function ie(t,o){return t<<o|t>>>32-o}function rt(t){var o=[1518500249,1859775393,2400959708,3395469782],e=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof t=="string"){var n=unescape(encodeURIComponent(t));t=[];for(var a=0;a<n.length;++a)t.push(n.charCodeAt(a))}else Array.isArray(t)||(t=Array.prototype.slice.call(t));t.push(128);for(var r=t.length/4+2,i=Math.ceil(r/16),h=new Array(i),v=0;v<i;++v){for(var s=new Uint32Array(16),d=0;d<16;++d)s[d]=t[v*64+d*4]<<24|t[v*64+d*4+1]<<16|t[v*64+d*4+2]<<8|t[v*64+d*4+3];h[v]=s}h[i-1][14]=(t.length-1)*8/Math.pow(2,32),h[i-1][14]=Math.floor(h[i-1][14]),h[i-1][15]=(t.length-1)*8&4294967295;for(var m=0;m<i;++m){for(var _=new Uint32Array(80),R=0;R<16;++R)_[R]=h[m][R];for(var M=16;M<80;++M)_[M]=ie(_[M-3]^_[M-8]^_[M-14]^_[M-16],1);for(var S=e[0],N=e[1],D=e[2],I=e[3],p=e[4],u=0;u<80;++u){var l=Math.floor(u/20),f=ie(S,5)+tt(l,N,D,I)+p+o[l]+_[u]>>>0;p=I,I=D,D=ie(N,30)>>>0,N=S,S=f}e[0]=e[0]+S>>>0,e[1]=e[1]+N>>>0,e[2]=e[2]+D>>>0,e[3]=e[3]+I>>>0,e[4]=e[4]+p>>>0}return[e[0]>>24&255,e[0]>>16&255,e[0]>>8&255,e[0]&255,e[1]>>24&255,e[1]>>16&255,e[1]>>8&255,e[1]&255,e[2]>>24&255,e[2]>>16&255,e[2]>>8&255,e[2]&255,e[3]>>24&255,e[3]>>16&255,e[3]>>8&255,e[3]&255,e[4]>>24&255,e[4]>>16&255,e[4]>>8&255,e[4]&255]}var nt=ye("v5",80,rt),at=nt,ot="00000000-0000-0000-0000-000000000000";function it(t){if(!G(t))throw TypeError("Invalid UUID");return parseInt(t.substr(14,1),16)}var st=Object.freeze(Object.defineProperty({__proto__:null,v1:Fe,v3:Ze,v4:et,v5:at,NIL:ot,version:it,validate:G,stringify:B,parse:ve},Symbol.toStringTag,{value:"Module"})),ut=xe(st),Q=w&&w.__assign||function(){return Q=Object.assign||function(t){for(var o,e=1,n=arguments.length;e<n;e++){o=arguments[e];for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&(t[a]=o[a])}return t},Q.apply(this,arguments)};Object.defineProperty(te,"__esModule",{value:!0});var ft=ut,ct=function(){function t(){}return t.prototype.generateEventId=function(){return(0,ft.v4)()},t.prototype.createImpressionEvent=function(o,e,n,a,r,i){var h=this.createBaseEvent(o,e,n,a,r);return i?Q(Q({},h),{variant:i}):h},t.prototype.createBaseEvent=function(o,e,n,a,r){return{eventType:a,eventId:this.generateEventId(),context:o,enabled:e,featureName:n,impressionData:r}},t}();te.default=ct,function(t){var o=w&&w.__extends||function(){var I=function(p,u){return I=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(l,f){l.__proto__=f}||function(l,f){for(var c in f)Object.prototype.hasOwnProperty.call(f,c)&&(l[c]=f[c])},I(p,u)};return function(p,u){if(typeof u!="function"&&u!==null)throw new TypeError("Class extends value "+String(u)+" is not a constructor or null");I(p,u);function l(){this.constructor=p}p.prototype=u===null?Object.create(u):(l.prototype=u.prototype,new l)}}(),e=w&&w.__assign||function(){return e=Object.assign||function(I){for(var p,u=1,l=arguments.length;u<l;u++){p=arguments[u];for(var f in p)Object.prototype.hasOwnProperty.call(p,f)&&(I[f]=p[f])}return I},e.apply(this,arguments)},n=w&&w.__awaiter||function(I,p,u,l){function f(c){return c instanceof u?c:new u(function(g){g(c)})}return new(u||(u=Promise))(function(c,g){function U(C){try{y(l.next(C))}catch(q){g(q)}}function j(C){try{y(l.throw(C))}catch(q){g(q)}}function y(C){C.done?c(C.value):f(C.value).then(U,j)}y((l=l.apply(I,p||[])).next())})},a=w&&w.__generator||function(I,p){var u={label:0,sent:function(){if(c[0]&1)throw c[1];return c[1]},trys:[],ops:[]},l,f,c,g;return g={next:U(0),throw:U(1),return:U(2)},typeof Symbol=="function"&&(g[Symbol.iterator]=function(){return this}),g;function U(y){return function(C){return j([y,C])}}function j(y){if(l)throw new TypeError("Generator is already executing.");for(;u;)try{if(l=1,f&&(c=y[0]&2?f.return:y[0]?f.throw||((c=f.return)&&c.call(f),0):f.next)&&!(c=c.call(f,y[1])).done)return c;switch(f=0,c&&(y=[y[0]&2,c.value]),y[0]){case 0:case 1:c=y;break;case 4:return u.label++,{value:y[1],done:!1};case 5:u.label++,f=y[1],y=[0];continue;case 7:y=u.ops.pop(),u.trys.pop();continue;default:if(c=u.trys,!(c=c.length>0&&c[c.length-1])&&(y[0]===6||y[0]===2)){u=0;continue}if(y[0]===3&&(!c||y[1]>c[0]&&y[1]<c[3])){u.label=y[1];break}if(y[0]===6&&u.label<c[1]){u.label=c[1],c=y;break}if(c&&u.label<c[2]){u.label=c[2],u.ops.push(y);break}c[2]&&u.ops.pop(),u.trys.pop();continue}y=p.call(I,u)}catch(C){y=[6,C],f=0}finally{l=c=0}if(y[0]&5)throw y[1];return{value:y[0]?y[1]:void 0,done:!0}}},r=w&&w.__spreadArray||function(I,p,u){if(u||arguments.length===2)for(var l=0,f=p.length,c;l<f;l++)(c||!(l in p))&&(c||(c=Array.prototype.slice.call(p,0,l)),c[l]=p[l]);return I.concat(c||Array.prototype.slice.call(p))};Object.defineProperty(t,"__esModule",{value:!0}),t.InMemoryStorageProvider=t.LocalStorageProvider=t.UnleashClient=t.resolveFetch=t.EVENTS=void 0;var i=J.exports,h=z,v=Z;t.InMemoryStorageProvider=v.default;var s=ee;t.LocalStorageProvider=s.default;var d=te,m=W,_=["userId","sessionId","remoteAddress"];t.EVENTS={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression",SENT:"sent"};var R={IS_ENABLED:"isEnabled",GET_VARIANT:"getVariant"},M={name:"disabled",enabled:!1},S="repo",N=function(){try{if(typeof window!="undefined"&&"fetch"in window)return fetch.bind(window);if("fetch"in globalThis)return fetch.bind(globalThis)}catch(I){console.error('Unleash failed to resolve "fetch"',I)}};t.resolveFetch=N;var D=function(I){o(p,I);function p(u){var l=u.storageProvider,f=u.url,c=u.clientKey,g=u.disableRefresh,U=g===void 0?!1:g,j=u.refreshInterval,y=j===void 0?30:j,C=u.metricsInterval,q=C===void 0?30:C,be=u.disableMetrics,gt=be===void 0?!1:be,ue=u.appName,we=u.environment,mt=we===void 0?"default":we,bt=u.context,Ee=u.fetch,fe=Ee===void 0?(0,t.resolveFetch)():Ee,L=u.bootstrap,Se=u.bootstrapOverride,wt=Se===void 0?!0:Se,Ie=u.headerName,Te=Ie===void 0?"Authorization":Ie,_e=u.customHeaders,Ne=_e===void 0?{}:_e,Oe=u.impressionDataAll,Et=Oe===void 0?!1:Oe,Re=u.usePOSTrequests,St=Re===void 0?!1:Re,b=I.call(this)||this;if(b.toggles=[],b.etag="",b.readyEventEmitted=!1,b.usePOSTrequests=!1,b.started=!1,!f)throw new Error("url is required");if(!c)throw new Error("clientKey is required");if(!ue)throw new Error("appName is required.");return b.eventsHandler=new d.default,b.impressionDataAll=Et,b.toggles=L&&L.length>0?L:[],b.url=f instanceof URL?f:new URL(f),b.clientKey=c,b.headerName=Te,b.customHeaders=Ne,b.storage=l||(typeof window!="undefined"?new s.default:new v.default),b.refreshInterval=U?0:y*1e3,b.context=e({appName:ue,environment:mt},bt),b.usePOSTrequests=St,b.ready=new Promise(function(Ue){b.init().then(Ue).catch(function(Ae){console.error(Ae),b.emit(t.EVENTS.ERROR,Ae),Ue()})}),fe||console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'),b.fetch=fe,b.bootstrap=L&&L.length>0?L:void 0,b.bootstrapOverride=wt,b.metrics=new h.default({onError:b.emit.bind(b,t.EVENTS.ERROR),onSent:b.emit.bind(b,t.EVENTS.SENT),appName:ue,metricsInterval:q,disableMetrics:gt,url:b.url,clientKey:c,fetch:fe,headerName:Te,customHeaders:Ne}),b}return p.prototype.getAllToggles=function(){return r([],this.toggles,!0)},p.prototype.isEnabled=function(u){var l,f=this.toggles.find(function(U){return U.name===u}),c=f?f.enabled:!1;if(this.metrics.count(u,c),(f==null?void 0:f.impressionData)||this.impressionDataAll){var g=this.eventsHandler.createImpressionEvent(this.context,c,u,R.IS_ENABLED,(l=f==null?void 0:f.impressionData)!==null&&l!==void 0?l:void 0);this.emit(t.EVENTS.IMPRESSION,g)}return c},p.prototype.getVariant=function(u){var l,f=this.toggles.find(function(j){return j.name===u}),c=(f==null?void 0:f.enabled)||!1,g=f?f.variant:M;if(g.name&&this.metrics.countVariant(u,g.name),this.metrics.count(u,c),(f==null?void 0:f.impressionData)||this.impressionDataAll){var U=this.eventsHandler.createImpressionEvent(this.context,c,u,R.GET_VARIANT,(l=f==null?void 0:f.impressionData)!==null&&l!==void 0?l:void 0,g.name);this.emit(t.EVENTS.IMPRESSION,U)}return g},p.prototype.updateContext=function(u){return n(this,void 0,void 0,function(){var l,f=this;return a(this,function(c){switch(c.label){case 0:return(u.appName||u.environment)&&console.warn("appName and environment are static. They can't be updated with updateContext."),l={environment:this.context.environment,appName:this.context.appName,sessionId:this.context.sessionId},this.context=e(e({},l),u),this.timerRef||this.readyEventEmitted?[4,this.fetchToggles()]:[3,2];case 1:return c.sent(),[3,4];case 2:return this.started?[4,new Promise(function(g){var U=function(){f.fetchToggles().then(function(){f.off(t.EVENTS.READY,U),g()})};f.once(t.EVENTS.READY,U)})]:[3,4];case 3:c.sent(),c.label=4;case 4:return[2]}})})},p.prototype.getContext=function(){return e({},this.context)},p.prototype.setContextField=function(u,l){var f,c;if(_.includes(u))this.context=e(e({},this.context),(f={},f[u]=l,f));else{var g=e(e({},this.context.properties),(c={},c[u]=l,c));this.context=e(e({},this.context),{properties:g})}this.timerRef&&this.fetchToggles()},p.prototype.init=function(){return n(this,void 0,void 0,function(){var u,l;return a(this,function(f){switch(f.label){case 0:return[4,this.resolveSessionId()];case 1:return u=f.sent(),this.context=e({sessionId:u},this.context),l=this,[4,this.storage.get(S)];case 2:return l.toggles=f.sent()||[],this.bootstrap&&(this.bootstrapOverride||this.toggles.length===0)?[4,this.storage.save(S,this.bootstrap)]:[3,4];case 3:f.sent(),this.toggles=this.bootstrap,this.emit(t.EVENTS.READY),f.label=4;case 4:return this.emit(t.EVENTS.INIT),[2]}})})},p.prototype.start=function(){return n(this,void 0,void 0,function(){var u,l=this;return a(this,function(f){switch(f.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 f.sent(),this.metrics.start(),u=this.refreshInterval,[4,this.fetchToggles()];case 2:return f.sent(),u>0&&(this.timerRef=setInterval(function(){return l.fetchToggles()},u)),[2]}})})},p.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},p.prototype.resolveSessionId=function(){return n(this,void 0,void 0,function(){var u;return a(this,function(l){switch(l.label){case 0:return this.context.sessionId?[2,this.context.sessionId]:[3,1];case 1:return[4,this.storage.get("sessionId")];case 2:return u=l.sent(),u?[3,4]:(u=Math.floor(Math.random()*1e9),[4,this.storage.save("sessionId",u)]);case 3:l.sent(),l.label=4;case 4:return[2,u]}})})},p.prototype.getHeaders=function(){var u,l=(u={},u[this.headerName]=this.clientKey,u.Accept="application/json",u["Content-Type"]="application/json",u["If-None-Match"]=this.etag,u);return Object.entries(this.customHeaders).filter(m.notNullOrUndefined).forEach(function(f){var c=f[0],g=f[1];return l[c]=g}),l},p.prototype.storeToggles=function(u){return n(this,void 0,void 0,function(){return a(this,function(l){switch(l.label){case 0:return this.toggles=u,this.emit(t.EVENTS.UPDATE),[4,this.storage.save(S,u)];case 1:return l.sent(),[2]}})})},p.prototype.fetchToggles=function(){return n(this,void 0,void 0,function(){var u,l,f,c,g,U,j;return a(this,function(y){switch(y.label){case 0:if(!this.fetch)return[3,8];y.label=1;case 1:return y.trys.push([1,7,,8]),u=this.usePOSTrequests,l=u?this.url:(0,m.urlWithContextAsQuery)(this.url,this.context),f=u?"POST":"GET",c=u?JSON.stringify({context:this.context}):void 0,[4,this.fetch(l.toString(),{method:f,cache:"no-cache",headers:this.getHeaders(),body:c})];case 2:return g=y.sent(),g.ok&&g.status!==304?(this.etag=g.headers.get("ETag")||"",[4,g.json()]):[3,5];case 3:return U=y.sent(),[4,this.storeToggles(U.toggles)];case 4:return y.sent(),!this.bootstrap&&!this.readyEventEmitted&&(this.emit(t.EVENTS.READY),this.readyEventEmitted=!0),[3,6];case 5:!g.ok&&g.status!==304&&(console.error("Unleash: Fetching feature toggles did not have an ok response"),this.emit(t.EVENTS.ERROR,{type:"HttpError",code:g.status})),y.label=6;case 6:return[3,8];case 7:return j=y.sent(),console.error("Unleash: unable to fetch feature toggles",j),this.emit(t.EVENTS.ERROR,j),[3,8];case 8:return[2]}})})},p}(i.TinyEmitter);t.UnleashClient=D}(K);const H=Symbol("Context state identifier"),se=Symbol("Context update identifier");function ge({config:t,unleashClient:o,startClient:e=!0}){var R,M;const n=E.ref(o),a=E.ref(!1),r=E.ref(null);!t&&!o&&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.`),!n.value&&t&&(n.value=new K.UnleashClient(t)),(R=n.value)==null||R.on("ready",()=>{a.value=!0}),(M=n.value)==null||M.on("error",S=>{r.value=S});const i=async S=>{var N;await((N=n.value)==null?void 0:N.updateContext(S))},h=S=>{var N;return(N=n.value)==null?void 0:N.isEnabled(S)},v=S=>{var N;return(N=n.value)==null?void 0:N.getVariant(S)},s=(S,...N)=>{var D;return(D=n.value)==null?void 0:D.on(S,...N)},d=E.reactive({on:s,updateContext:i,isEnabled:h,getVariant:v,client:n,flagsReady:a,flagsError:r}),m=(S,N)=>{d[S]=N},_=()=>{var S;(e||!o)&&((S=n==null?void 0:n.value)==null||S.start())};return{context:E.toRefs(d),update:m,start:_}}const me=E.defineComponent({__name:"FlagProvider",props:{config:null,unleashClient:null,startClient:{type:Boolean}},setup(t){const{config:o,unleashClient:e,startClient:n=!0}=t,{context:a,start:r,update:i}=ge({config:o,unleashClient:e,startClient:n});return E.provide(H,a),E.provide(se,i),E.onMounted(()=>{r()}),(h,v)=>E.renderSlot(h.$slots,"default")}}),lt=t=>{const{isEnabled:o,client:e}=E.inject(H,{}),n=E.ref(Boolean(o==null?void 0:o.value(t)));function a(){const i=o==null?void 0:o.value(t);i!==n.value&&(n.value=!!i)}function r(){n.value=Boolean(o==null?void 0:o.value(t))}return e==null||e.value.on("ready",r),e==null||e.value.on("update",a),E.onUnmounted(()=>{e==null||e.value.off("ready",r),e==null||e.value.off("update",a)}),n},dt=()=>{const{flagsReady:t,flagsError:o}=E.inject(H,{});return{flagsReady:t,flagsError:o}},ht=t=>{const{getVariant:o,client:e}=E.inject(H,{}),n=E.ref(o==null?void 0:o.value(t));function a(){var h,v;const i=o==null?void 0:o.value(t);((i==null?void 0:i.name)!==((h=n.value)==null?void 0:h.name)||(i==null?void 0:i.enabled)!==((v=n.value)==null?void 0:v.enabled))&&(n.value=i)}function r(){n.value=o==null?void 0:o.value(t)}return e==null||e.value.on("ready",r),e==null||e.value.on("update",a),E.onUnmounted(()=>{e==null||e.value.off("ready",r),e==null||e.value.off("update",a)}),n||{}},vt=()=>{const{updateContext:t}=E.inject(H,{});return t==null?void 0:t.value},yt=()=>{const{client:t}=E.inject(H,{});return t==null?void 0:t.value},pt={install(t,{config:o,unleashClient:e,startClient:n}){const{context:a,update:r,start:i}=ge({config:o,unleashClient:e,startClient:n});t.provide(H,a),t.provide(se,r),i()}};T.ContextStateSymbol=H,T.ContextUpdateSymbol=se,T.FlagProvider=me,T.InMemoryStorageProvider=K.InMemoryStorageProvider,T.LocalStorageProvider=K.LocalStorageProvider,T.UnleashClient=K.UnleashClient,T.default=me,T.plugin=pt,T.useFlag=lt,T.useFlagsStatus=dt,T.useUnleashClient=yt,T.useUnleashContext=vt,T.useVariant=ht,Object.defineProperties(T,{__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.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Vue interface for working with Unleash",
|
|
5
5
|
"main": "./dist/index.umd.js",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"preview": "vite preview"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"unleash-proxy-client": "^2.
|
|
30
|
+
"unleash-proxy-client": "^2.5.0",
|
|
31
31
|
"vue": "^3.2.45"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|