@unleash/proxy-client-vue 0.0.7-beta.5 → 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/FlagProvider.vue.d.ts +65 -0
- package/dist/env.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +154 -120
- package/dist/index.umd.js +2 -3
- package/dist/plugin.d.ts +2 -3
- package/dist/useFlag.d.ts +1 -1
- package/dist/useFlagsStatus.d.ts +1 -1
- package/dist/useUnleashProvide.d.ts +1 -1
- package/dist/useVariant.d.ts +1 -1
- package/package.json +5 -14
- package/dist/FlagProvider.d.ts +0 -35
- package/dist/index.es.js.map +0 -1
- package/dist/index.umd.js.map +0 -1
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, reactive,
|
|
1
|
+
import { toRefs, ref, reactive, defineComponent, provide, onMounted, renderSlot, inject, onUnmounted } from "vue";
|
|
2
2
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
3
3
|
function getAugmentedNamespace(n) {
|
|
4
4
|
if (n.__esModule)
|
|
@@ -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) {
|
|
@@ -994,14 +1047,6 @@ var EventsHandler = function() {
|
|
|
994
1047
|
return EventsHandler2;
|
|
995
1048
|
}();
|
|
996
1049
|
eventsHandler.default = EventsHandler;
|
|
997
|
-
var util = {};
|
|
998
|
-
Object.defineProperty(util, "__esModule", { value: true });
|
|
999
|
-
util.notNullOrUndefined = void 0;
|
|
1000
|
-
var notNullOrUndefined = function(_a) {
|
|
1001
|
-
var value = _a[1];
|
|
1002
|
-
return value !== void 0 && value !== null;
|
|
1003
|
-
};
|
|
1004
|
-
util.notNullOrUndefined = notNullOrUndefined;
|
|
1005
1050
|
(function(exports) {
|
|
1006
1051
|
var __extends = commonjsGlobal && commonjsGlobal.__extends || function() {
|
|
1007
1052
|
var extendStatics = function(d, b) {
|
|
@@ -1159,14 +1204,15 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1159
1204
|
var storage_provider_local_1 = storageProviderLocal;
|
|
1160
1205
|
exports.LocalStorageProvider = storage_provider_local_1.default;
|
|
1161
1206
|
var events_handler_1 = eventsHandler;
|
|
1162
|
-
var
|
|
1207
|
+
var util_12 = util;
|
|
1163
1208
|
var DEFINED_FIELDS = ["userId", "sessionId", "remoteAddress"];
|
|
1164
1209
|
exports.EVENTS = {
|
|
1165
1210
|
INIT: "initialized",
|
|
1166
1211
|
ERROR: "error",
|
|
1167
1212
|
READY: "ready",
|
|
1168
1213
|
UPDATE: "update",
|
|
1169
|
-
IMPRESSION: "impression"
|
|
1214
|
+
IMPRESSION: "impression",
|
|
1215
|
+
SENT: "sent"
|
|
1170
1216
|
};
|
|
1171
1217
|
var IMPRESSION_EVENTS = {
|
|
1172
1218
|
IS_ENABLED: "isEnabled",
|
|
@@ -1176,7 +1222,7 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1176
1222
|
var storeKey = "repo";
|
|
1177
1223
|
var resolveFetch = function() {
|
|
1178
1224
|
try {
|
|
1179
|
-
if ("fetch" in window) {
|
|
1225
|
+
if (typeof window !== "undefined" && "fetch" in window) {
|
|
1180
1226
|
return fetch.bind(window);
|
|
1181
1227
|
} else if ("fetch" in globalThis) {
|
|
1182
1228
|
return fetch.bind(globalThis);
|
|
@@ -1190,11 +1236,13 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1190
1236
|
var UnleashClient2 = function(_super) {
|
|
1191
1237
|
__extends(UnleashClient3, _super);
|
|
1192
1238
|
function UnleashClient3(_a) {
|
|
1193
|
-
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;
|
|
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;
|
|
1194
1240
|
var _this = _super.call(this) || this;
|
|
1195
1241
|
_this.toggles = [];
|
|
1196
1242
|
_this.etag = "";
|
|
1197
1243
|
_this.readyEventEmitted = false;
|
|
1244
|
+
_this.usePOSTrequests = false;
|
|
1245
|
+
_this.started = false;
|
|
1198
1246
|
if (!url) {
|
|
1199
1247
|
throw new Error("url is required");
|
|
1200
1248
|
}
|
|
@@ -1211,9 +1259,10 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1211
1259
|
_this.clientKey = clientKey;
|
|
1212
1260
|
_this.headerName = headerName;
|
|
1213
1261
|
_this.customHeaders = customHeaders;
|
|
1214
|
-
_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());
|
|
1215
1263
|
_this.refreshInterval = disableRefresh ? 0 : refreshInterval * 1e3;
|
|
1216
1264
|
_this.context = __assign2({ appName, environment }, context);
|
|
1265
|
+
_this.usePOSTrequests = usePOSTrequests;
|
|
1217
1266
|
_this.ready = new Promise(function(resolve) {
|
|
1218
1267
|
_this.init().then(resolve).catch(function(error) {
|
|
1219
1268
|
console.error(error);
|
|
@@ -1229,13 +1278,15 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1229
1278
|
_this.bootstrapOverride = bootstrapOverride;
|
|
1230
1279
|
_this.metrics = new metrics_1.default({
|
|
1231
1280
|
onError: _this.emit.bind(_this, exports.EVENTS.ERROR),
|
|
1281
|
+
onSent: _this.emit.bind(_this, exports.EVENTS.SENT),
|
|
1232
1282
|
appName,
|
|
1233
1283
|
metricsInterval,
|
|
1234
1284
|
disableMetrics,
|
|
1235
1285
|
url: _this.url,
|
|
1236
1286
|
clientKey,
|
|
1237
1287
|
fetch: fetch2,
|
|
1238
|
-
headerName
|
|
1288
|
+
headerName,
|
|
1289
|
+
customHeaders
|
|
1239
1290
|
});
|
|
1240
1291
|
return _this;
|
|
1241
1292
|
}
|
|
@@ -1243,26 +1294,31 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1243
1294
|
return __spreadArray([], this.toggles, true);
|
|
1244
1295
|
};
|
|
1245
1296
|
UnleashClient3.prototype.isEnabled = function(toggleName) {
|
|
1297
|
+
var _a;
|
|
1246
1298
|
var toggle = this.toggles.find(function(t) {
|
|
1247
1299
|
return t.name === toggleName;
|
|
1248
1300
|
});
|
|
1249
1301
|
var enabled = toggle ? toggle.enabled : false;
|
|
1250
1302
|
this.metrics.count(toggleName, enabled);
|
|
1251
1303
|
if ((toggle === null || toggle === void 0 ? void 0 : toggle.impressionData) || this.impressionDataAll) {
|
|
1252
|
-
var event_1 = this.eventsHandler.createImpressionEvent(this.context, enabled, toggleName, IMPRESSION_EVENTS.IS_ENABLED, (toggle === null || toggle === void 0 ? void 0 : toggle.impressionData)
|
|
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);
|
|
1253
1305
|
this.emit(exports.EVENTS.IMPRESSION, event_1);
|
|
1254
1306
|
}
|
|
1255
1307
|
return enabled;
|
|
1256
1308
|
};
|
|
1257
1309
|
UnleashClient3.prototype.getVariant = function(toggleName) {
|
|
1310
|
+
var _a;
|
|
1258
1311
|
var toggle = this.toggles.find(function(t) {
|
|
1259
1312
|
return t.name === toggleName;
|
|
1260
1313
|
});
|
|
1261
1314
|
var enabled = (toggle === null || toggle === void 0 ? void 0 : toggle.enabled) || false;
|
|
1262
1315
|
var variant = toggle ? toggle.variant : defaultVariant;
|
|
1263
|
-
|
|
1316
|
+
if (variant.name) {
|
|
1317
|
+
this.metrics.countVariant(toggleName, variant.name);
|
|
1318
|
+
}
|
|
1319
|
+
this.metrics.count(toggleName, enabled);
|
|
1264
1320
|
if ((toggle === null || toggle === void 0 ? void 0 : toggle.impressionData) || this.impressionDataAll) {
|
|
1265
|
-
var event_2 = this.eventsHandler.createImpressionEvent(this.context, enabled, toggleName, IMPRESSION_EVENTS.GET_VARIANT, (toggle === null || toggle === void 0 ? void 0 : toggle.impressionData)
|
|
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);
|
|
1266
1322
|
this.emit(exports.EVENTS.IMPRESSION, event_2);
|
|
1267
1323
|
}
|
|
1268
1324
|
return variant;
|
|
@@ -1270,6 +1326,7 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1270
1326
|
UnleashClient3.prototype.updateContext = function(context) {
|
|
1271
1327
|
return __awaiter2(this, void 0, void 0, function() {
|
|
1272
1328
|
var staticContext;
|
|
1329
|
+
var _this = this;
|
|
1273
1330
|
return __generator2(this, function(_a) {
|
|
1274
1331
|
switch (_a.label) {
|
|
1275
1332
|
case 0:
|
|
@@ -1282,13 +1339,28 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1282
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,7 +1499,7 @@ 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:
|
|
@@ -1435,22 +1508,15 @@ util.notNullOrUndefined = notNullOrUndefined;
|
|
|
1435
1508
|
_a.label = 1;
|
|
1436
1509
|
case 1:
|
|
1437
1510
|
_a.trys.push([1, 7, , 8]);
|
|
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(), {
|
|
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();
|
|
@@ -1506,10 +1572,8 @@ function useUnleashProvide({
|
|
|
1506
1572
|
const flagsReady = ref(false);
|
|
1507
1573
|
const flagsError = ref(null);
|
|
1508
1574
|
if (!config && !unleashClient) {
|
|
1509
|
-
console.warn(
|
|
1510
|
-
|
|
1511
|
-
checking if the client exists before rendering.`
|
|
1512
|
-
);
|
|
1575
|
+
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
|
|
1576
|
+
checking if the client exists before rendering.`);
|
|
1513
1577
|
}
|
|
1514
1578
|
if (!client.value && config) {
|
|
1515
1579
|
client.value = new build.UnleashClient(config);
|
|
@@ -1560,39 +1624,32 @@ function useUnleashProvide({
|
|
|
1560
1624
|
start
|
|
1561
1625
|
};
|
|
1562
1626
|
}
|
|
1563
|
-
|
|
1564
|
-
|
|
1627
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
1628
|
+
__name: "FlagProvider",
|
|
1565
1629
|
props: {
|
|
1566
|
-
config:
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
},
|
|
1570
|
-
unleashClient: {
|
|
1571
|
-
type: Object,
|
|
1572
|
-
required: false
|
|
1573
|
-
},
|
|
1574
|
-
startClient: {
|
|
1575
|
-
type: Boolean,
|
|
1576
|
-
required: false,
|
|
1577
|
-
default: true
|
|
1578
|
-
}
|
|
1630
|
+
config: null,
|
|
1631
|
+
unleashClient: null,
|
|
1632
|
+
startClient: { type: Boolean }
|
|
1579
1633
|
},
|
|
1580
|
-
setup(
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1634
|
+
setup(__props) {
|
|
1635
|
+
const {
|
|
1636
|
+
config,
|
|
1637
|
+
unleashClient,
|
|
1638
|
+
startClient = true
|
|
1639
|
+
} = __props;
|
|
1640
|
+
const { context, start, update } = useUnleashProvide({
|
|
1641
|
+
config,
|
|
1642
|
+
unleashClient,
|
|
1643
|
+
startClient
|
|
1586
1644
|
});
|
|
1587
|
-
const vm = getCurrentInstance();
|
|
1588
|
-
const h$1 = h.bind(vm);
|
|
1589
1645
|
provide(ContextStateSymbol, context);
|
|
1590
1646
|
provide(ContextUpdateSymbol, update);
|
|
1591
1647
|
onMounted(() => {
|
|
1592
|
-
console.log("start");
|
|
1593
1648
|
start();
|
|
1594
1649
|
});
|
|
1595
|
-
return () =>
|
|
1650
|
+
return (_ctx, _cache) => {
|
|
1651
|
+
return renderSlot(_ctx.$slots, "default");
|
|
1652
|
+
};
|
|
1596
1653
|
}
|
|
1597
1654
|
});
|
|
1598
1655
|
const useFlag = (name) => {
|
|
@@ -1616,10 +1673,7 @@ const useFlag = (name) => {
|
|
|
1616
1673
|
return flag;
|
|
1617
1674
|
};
|
|
1618
1675
|
const useFlagsStatus = () => {
|
|
1619
|
-
const { flagsReady, flagsError } = inject(
|
|
1620
|
-
ContextStateSymbol,
|
|
1621
|
-
{}
|
|
1622
|
-
);
|
|
1676
|
+
const { flagsReady, flagsError } = inject(ContextStateSymbol, {});
|
|
1623
1677
|
return { flagsReady, flagsError };
|
|
1624
1678
|
};
|
|
1625
1679
|
const useVariant = (name) => {
|
|
@@ -1651,39 +1705,19 @@ const useUnleashClient = () => {
|
|
|
1651
1705
|
const { client } = inject(ContextStateSymbol, {});
|
|
1652
1706
|
return client == null ? void 0 : client.value;
|
|
1653
1707
|
};
|
|
1654
|
-
|
|
1655
|
-
config,
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
const vue3 = vue;
|
|
1668
|
-
vue3.provide(ContextStateSymbol, context);
|
|
1669
|
-
vue3.provide(ContextUpdateSymbol, update);
|
|
1670
|
-
} else {
|
|
1671
|
-
const vue2 = vue;
|
|
1672
|
-
vue2.mixin({
|
|
1673
|
-
provide() {
|
|
1674
|
-
return {
|
|
1675
|
-
[ContextStateSymbol]: context,
|
|
1676
|
-
[ContextUpdateSymbol]: update
|
|
1677
|
-
};
|
|
1678
|
-
}
|
|
1679
|
-
});
|
|
1680
|
-
}
|
|
1681
|
-
start();
|
|
1682
|
-
}
|
|
1683
|
-
};
|
|
1684
|
-
}
|
|
1685
|
-
var InMemoryStorageProvider = build.InMemoryStorageProvider;
|
|
1708
|
+
const plugin = {
|
|
1709
|
+
install(app, { config, unleashClient, startClient }) {
|
|
1710
|
+
const { context, update, start } = useUnleashProvide({
|
|
1711
|
+
config,
|
|
1712
|
+
unleashClient,
|
|
1713
|
+
startClient
|
|
1714
|
+
});
|
|
1715
|
+
app.provide(ContextStateSymbol, context);
|
|
1716
|
+
app.provide(ContextUpdateSymbol, update);
|
|
1717
|
+
start();
|
|
1718
|
+
}
|
|
1719
|
+
};
|
|
1720
|
+
var InMemoryStorageProvider$1 = build.InMemoryStorageProvider;
|
|
1686
1721
|
var LocalStorageProvider$1 = build.LocalStorageProvider;
|
|
1687
1722
|
var UnleashClient = build.UnleashClient;
|
|
1688
|
-
export { ContextStateSymbol, ContextUpdateSymbol, FlagProvider, InMemoryStorageProvider, LocalStorageProvider$1 as LocalStorageProvider, UnleashClient,
|
|
1689
|
-
//# sourceMappingURL=index.es.js.map
|
|
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 };
|