@feedmepos/mf-brand-app-builder 0.5.31-dev.1 → 0.5.31-prod

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.
@@ -0,0 +1,866 @@
1
+ var ue = Object.defineProperty;
2
+ var ce = (C, c, v) => c in C ? ue(C, c, { enumerable: !0, configurable: !0, writable: !0, value: v }) : C[c] = v;
3
+ var st = (C, c, v) => ce(C, typeof c != "symbol" ? c + "" : c, v);
4
+ import { readonly as Pt, ref as $, watch as he } from "vue";
5
+ import { useCoreStore as ve } from "@feedmepos/mf-common";
6
+ import { c as lt } from "./_commonjsHelpers-DaMA6jEr.js";
7
+ var Ut = { exports: {} };
8
+ (function(C, c) {
9
+ (function(v, g) {
10
+ g(c);
11
+ })(lt, function(v) {
12
+ var g = { getItemSync: function(a) {
13
+ try {
14
+ return localStorage.getItem(a) || null;
15
+ } catch {
16
+ return null;
17
+ }
18
+ }, getItem: function(a, e) {
19
+ var t = this;
20
+ return new Promise(function(i, n) {
21
+ try {
22
+ var r = t.getItemSync(a);
23
+ e == null || e(null, r), i(r);
24
+ } catch (o) {
25
+ e && e(o, null), n(o);
26
+ }
27
+ });
28
+ }, setItem: function(a, e, t) {
29
+ return new Promise(function(i, n) {
30
+ try {
31
+ localStorage.setItem(a, e), t && t(null, e), i(e);
32
+ } catch (r) {
33
+ t && t(r, null), n(r);
34
+ }
35
+ });
36
+ } }, s = function() {
37
+ return s = Object.assign || function(a) {
38
+ for (var e, t = 1, i = arguments.length; t < i; t++) for (var n in e = arguments[t]) Object.prototype.hasOwnProperty.call(e, n) && (a[n] = e[n]);
39
+ return a;
40
+ }, s.apply(this, arguments);
41
+ };
42
+ function F(a, e, t, i) {
43
+ return new (t || (t = Promise))(function(n, r) {
44
+ function o(p) {
45
+ try {
46
+ h(i.next(p));
47
+ } catch (l) {
48
+ r(l);
49
+ }
50
+ }
51
+ function u(p) {
52
+ try {
53
+ h(i.throw(p));
54
+ } catch (l) {
55
+ r(l);
56
+ }
57
+ }
58
+ function h(p) {
59
+ var l;
60
+ p.done ? n(p.value) : (l = p.value, l instanceof t ? l : new t(function(y) {
61
+ y(l);
62
+ })).then(o, u);
63
+ }
64
+ h((i = i.apply(a, [])).next());
65
+ });
66
+ }
67
+ function I(a, e) {
68
+ var t, i, n, r, o = { label: 0, sent: function() {
69
+ if (1 & n[0]) throw n[1];
70
+ return n[1];
71
+ }, trys: [], ops: [] };
72
+ return r = { next: u(0), throw: u(1), return: u(2) }, typeof Symbol == "function" && (r[Symbol.iterator] = function() {
73
+ return this;
74
+ }), r;
75
+ function u(h) {
76
+ return function(p) {
77
+ return function(l) {
78
+ if (t) throw new TypeError("Generator is already executing.");
79
+ for (; o; ) try {
80
+ if (t = 1, i && (n = 2 & l[0] ? i.return : l[0] ? i.throw || ((n = i.return) && n.call(i), 0) : i.next) && !(n = n.call(i, l[1])).done) return n;
81
+ switch (i = 0, n && (l = [2 & l[0], n.value]), l[0]) {
82
+ case 0:
83
+ case 1:
84
+ n = l;
85
+ break;
86
+ case 4:
87
+ return o.label++, { value: l[1], done: !1 };
88
+ case 5:
89
+ o.label++, i = l[1], l = [0];
90
+ continue;
91
+ case 7:
92
+ l = o.ops.pop(), o.trys.pop();
93
+ continue;
94
+ default:
95
+ if (n = o.trys, !((n = n.length > 0 && n[n.length - 1]) || l[0] !== 6 && l[0] !== 2)) {
96
+ o = 0;
97
+ continue;
98
+ }
99
+ if (l[0] === 3 && (!n || l[1] > n[0] && l[1] < n[3])) {
100
+ o.label = l[1];
101
+ break;
102
+ }
103
+ if (l[0] === 6 && o.label < n[1]) {
104
+ o.label = n[1], n = l;
105
+ break;
106
+ }
107
+ if (n && o.label < n[2]) {
108
+ o.label = n[2], o.ops.push(l);
109
+ break;
110
+ }
111
+ n[2] && o.ops.pop(), o.trys.pop();
112
+ continue;
113
+ }
114
+ l = e.call(a, o);
115
+ } catch (y) {
116
+ l = [6, y], i = 0;
117
+ } finally {
118
+ t = n = 0;
119
+ }
120
+ if (5 & l[0]) throw l[1];
121
+ return { value: l[0] ? l[1] : void 0, done: !0 };
122
+ }([h, p]);
123
+ };
124
+ }
125
+ }
126
+ function N(a, e, t) {
127
+ for (var i, n = 0, r = e.length; n < r; n++) !i && n in e || (i || (i = Array.prototype.slice.call(e, 0, n)), i[n] = e[n]);
128
+ return a.concat(i || Array.prototype.slice.call(e));
129
+ }
130
+ var k = function a(e, t) {
131
+ if (e === t) return !0;
132
+ if (e && t && typeof e == "object" && typeof t == "object") {
133
+ if (e.constructor !== t.constructor) return !1;
134
+ var i, n, r;
135
+ if (Array.isArray(e)) {
136
+ if ((i = e.length) != t.length) return !1;
137
+ for (n = i; n-- != 0; ) if (!a(e[n], t[n])) return !1;
138
+ return !0;
139
+ }
140
+ if (e.constructor === RegExp) return e.source === t.source && e.flags === t.flags;
141
+ if (e.valueOf !== Object.prototype.valueOf) return e.valueOf() === t.valueOf();
142
+ if (e.toString !== Object.prototype.toString) return e.toString() === t.toString();
143
+ if ((i = (r = Object.keys(e)).length) !== Object.keys(t).length) return !1;
144
+ for (n = i; n-- != 0; ) if (!Object.prototype.hasOwnProperty.call(t, r[n])) return !1;
145
+ for (n = i; n-- != 0; ) {
146
+ var o = r[n];
147
+ if (!a(e[o], t[o])) return !1;
148
+ }
149
+ return !0;
150
+ }
151
+ return e != e && t != t;
152
+ };
153
+ function _(a, e) {
154
+ var t = Object.keys(e || {}).filter(function(i) {
155
+ var n = a == null ? void 0 : a[i], r = e == null ? void 0 : e[i];
156
+ return !k(n, r);
157
+ });
158
+ return Object.keys(a || {}).filter(function(i) {
159
+ Object.keys(e || {}).includes(i) || t.push(i);
160
+ }), Object.keys(t).length ? t : null;
161
+ }
162
+ var d, f;
163
+ function b(a, e, t) {
164
+ var i = "shortString", n = !0;
165
+ typeof t == "number" && (i = "javaDouble", n = !1), a[i] = a[i] || {}, a[i][e] = n ? t + "" : t;
166
+ }
167
+ function V(a) {
168
+ return !!a && typeof a == "object" && a.value !== void 0;
169
+ }
170
+ function at(a) {
171
+ return Object.fromEntries(Object.entries(a).map(function(e) {
172
+ var t = e[0], i = e[1];
173
+ return [t, V(i) ? i : { value: i }];
174
+ }));
175
+ }
176
+ function ct(a) {
177
+ return s(s({}, a), { identity: a.identity ? s(s({}, a.identity), { traits: at(a.identity.traits || {}) }) : void 0 });
178
+ }
179
+ (function(a) {
180
+ a.NONE = "NONE", a.DEFAULT_FLAGS = "DEFAULT_FLAGS", a.CACHE = "CACHE", a.SERVER = "SERVER";
181
+ })(d || (d = {}));
182
+ var ht, O = null, ae = "FLAGSMITH_EVENT", rt = ae, Dt = "https://edge.api.flagsmith.com/api/v1/", Gt = "flagsmith_value_", Jt = "flagsmith_enabled_", Vt = "flagsmith_trait_", re = function() {
183
+ function a(e) {
184
+ var t = this;
185
+ this._trigger = null, this._triggerLoadingState = null, this.timestamp = null, this.isLoading = !1, this.eventSource = null, this.getFlags = function() {
186
+ var i = t, n = i.api, r = i.evaluationContext;
187
+ t.log("Get Flags"), t.isLoading = !0, t.loadingState.isFetching || t.setLoadingState(s(s({}, t.loadingState), { isFetching: !0 }));
188
+ var o = "".concat(t.getContext().identity), u = function(h) {
189
+ var p, l, y, x;
190
+ if (h && o === "".concat(t.getContext().identity)) {
191
+ var U = h.flags, L = h.traits, P = h.identifier;
192
+ t.isLoading = !1;
193
+ var A = {}, j = {};
194
+ L = L || [], (U = U || []).forEach(function(m) {
195
+ A[m.feature.name.toLowerCase().replace(/ /g, "_")] = { id: m.feature.id, enabled: m.enabled, value: m.feature_state_value };
196
+ }), L.forEach(function(m) {
197
+ j[m.trait_key.toLowerCase().replace(/ /g, "_")] = { transient: m.transient, value: m.trait_value };
198
+ }), t.oldFlags = s({}, t.flags);
199
+ var K = _(t.oldFlags, A), W = _((p = t.evaluationContext.identity) === null || p === void 0 ? void 0 : p.traits, j);
200
+ if ((P || Object.keys(j).length) && (t.evaluationContext.identity = s(s({}, t.evaluationContext.identity), { traits: j }), P && (t.evaluationContext.identity.identifier = P)), t.flags = A, t.updateStorage(), t._onChange(t.oldFlags, { isFromServer: !0, flagsChanged: K, traitsChanged: W }, t._loadedState(null, d.SERVER)), t.datadogRum) try {
201
+ if (t.datadogRum.trackTraits) {
202
+ var tt = {};
203
+ Object.keys(((l = t.evaluationContext.identity) === null || l === void 0 ? void 0 : l.traits) || {}).map(function(m) {
204
+ tt[Vt + m] = t.getTrait(m);
205
+ });
206
+ var q = s(s(s({}, t.datadogRum.client.getUser()), { id: t.datadogRum.client.getUser().id || ((y = t.evaluationContext.identity) === null || y === void 0 ? void 0 : y.identifier) }), tt);
207
+ t.log("Setting Datadog user", q), t.datadogRum.client.setUser(q);
208
+ }
209
+ } catch (m) {
210
+ console.error(m);
211
+ }
212
+ if (t.dtrum) try {
213
+ var E = { javaDouble: {}, date: {}, shortString: {}, javaLongOrObject: {} };
214
+ Object.keys(t.flags).map(function(m) {
215
+ b(E, Gt + m, t.getValue(m, { skipAnalytics: !0 })), b(E, Jt + m, t.hasFeature(m, { skipAnalytics: !0 }));
216
+ }), Object.keys(((x = t.evaluationContext.identity) === null || x === void 0 ? void 0 : x.traits) || {}).map(function(m) {
217
+ b(E, Vt + m, t.getTrait(m));
218
+ }), t.log("Sending javaLongOrObject traits to dynatrace", E.javaLongOrObject), t.log("Sending date traits to dynatrace", E.date), t.log("Sending shortString traits to dynatrace", E.shortString), t.log("Sending javaDouble to dynatrace", E.javaDouble), t.dtrum.sendSessionProperties(E.javaLongOrObject, E.date, E.shortString, E.javaDouble);
219
+ } catch (m) {
220
+ console.error(m);
221
+ }
222
+ }
223
+ };
224
+ return r.identity ? Promise.all([r.identity.traits && Object.keys(r.identity.traits).length || !r.identity.identifier ? t.getJSON(n + "identities/", "POST", JSON.stringify({ identifier: r.identity.identifier, transient: r.identity.transient, traits: Object.entries(r.identity.traits).map(function(h) {
225
+ var p = h[0], l = h[1];
226
+ return { trait_key: p, trait_value: l == null ? void 0 : l.value, transient: l == null ? void 0 : l.transient };
227
+ }).filter(function(h) {
228
+ return h.trait_value !== void 0 || (t.log("Warning - attempted to set an undefined trait value for key", h.trait_key), !1);
229
+ }) })) : t.getJSON(n + "identities/?identifier=" + encodeURIComponent(r.identity.identifier) + (r.identity.transient ? "&transient=true" : ""))]).then(function(h) {
230
+ return t.evaluationContext.identity = s(s({}, t.evaluationContext.identity), { traits: {} }), u(h == null ? void 0 : h[0]);
231
+ }).catch(function(h) {
232
+ var p = h.message, l = new Error(p);
233
+ return Promise.reject(l);
234
+ }) : t.getJSON(n + "flags/").then(function(h) {
235
+ return u({ flags: h, traits: void 0 });
236
+ });
237
+ }, this.analyticsFlags = function() {
238
+ var i = t.api;
239
+ if (t.evaluationEvent && t.evaluationContext.environment && t.evaluationEvent[t.evaluationContext.environment.apiKey]) return t.evaluationEvent && Object.getOwnPropertyNames(t.evaluationEvent).length !== 0 && Object.getOwnPropertyNames(t.evaluationEvent[t.evaluationContext.environment.apiKey]).length !== 0 ? t.getJSON(i + "analytics/flags/", "POST", JSON.stringify(t.evaluationEvent[t.evaluationContext.environment.apiKey])).then(function(n) {
240
+ if (t.evaluationContext.environment) {
241
+ var r = t.getState();
242
+ t.evaluationEvent || (t.evaluationEvent = {}), t.evaluationEvent[t.evaluationContext.environment.apiKey] = {}, t.setState(s(s({}, r), { evaluationEvent: t.evaluationEvent })), t.updateEventStorage();
243
+ }
244
+ }).catch(function(n) {
245
+ t.log("Exception fetching evaluationEvent", n);
246
+ }) : void 0;
247
+ }, this.datadogRum = null, this.loadingState = { isLoading: !0, isFetching: !0, error: null, source: d.NONE }, this.canUseStorage = !1, this.analyticsInterval = null, this.api = null, this.cacheFlags = !1, this.ts = null, this.enableAnalytics = !1, this.enableLogs = !1, this.evaluationContext = {}, this.evaluationEvent = null, this.flags = null, this.getFlagInterval = null, this.headers = null, this.initialised = !1, this.oldFlags = null, this.onChange = null, this.onError = null, this.ticks = null, this.timer = null, this.dtrum = null, this.withTraits = null, this.cacheOptions = { ttl: 0, skipAPI: !1, loadStale: !1, storageKey: void 0 }, this.getValue = function(i, n, r) {
248
+ var o = t.flags && t.flags[i.toLowerCase().replace(/ /g, "_")], u = null;
249
+ if (o && (u = o.value), n != null && n.skipAnalytics || r || t.evaluateFlag(i, "VALUE"), u === null && (n == null ? void 0 : n.fallback) !== void 0) return n.fallback;
250
+ if (n != null && n.json) try {
251
+ return u === null ? (t.log("Tried to parse null flag as JSON: " + i), null) : JSON.parse(u);
252
+ } catch {
253
+ return n.fallback;
254
+ }
255
+ return u;
256
+ }, this.getTrait = function(i) {
257
+ var n, r;
258
+ return ((n = t.evaluationContext.identity) === null || n === void 0 ? void 0 : n.traits) && ((r = t.evaluationContext.identity.traits[i.toLowerCase().replace(/ /g, "_")]) === null || r === void 0 ? void 0 : r.value);
259
+ }, this.getAllTraits = function() {
260
+ var i;
261
+ return Object.fromEntries(Object.entries(((i = t.evaluationContext.identity) === null || i === void 0 ? void 0 : i.traits) || {}).map(function(n) {
262
+ var r = n[0], o = n[1];
263
+ return [r, o == null ? void 0 : o.value];
264
+ }));
265
+ }, this.setContext = function(i) {
266
+ var n = ct(i);
267
+ return t.evaluationContext = s(s({}, n), { environment: n.environment || t.evaluationContext.environment }), t.initialised ? t.getFlags() : Promise.resolve();
268
+ }, this.getContext = function() {
269
+ return t.evaluationContext;
270
+ }, this.updateContext = function(i) {
271
+ return t.setContext(s(s({}, t.getContext()), i));
272
+ }, this.setTrait = function(i, n) {
273
+ var r;
274
+ if (t.api) return t.setContext(s(s({}, t.evaluationContext), { identity: s(s({}, t.evaluationContext.identity), { traits: s(s({}, (r = t.evaluationContext.identity) === null || r === void 0 ? void 0 : r.traits), at(Object.fromEntries([[i, n]]))) }) }));
275
+ }, this.setTraits = function(i) {
276
+ var n;
277
+ if (t.api) return t.setContext(s(s({}, t.evaluationContext), { identity: s(s({}, t.evaluationContext.identity), { traits: s(s({}, (n = t.evaluationContext.identity) === null || n === void 0 ? void 0 : n.traits), Object.fromEntries(Object.entries(i).map(function(r) {
278
+ var o = r[0], u = r[1];
279
+ return [o, V(u) ? u : { value: u }];
280
+ }))) }) }));
281
+ console.error("Attempted to setTraits a user before calling flagsmith.init. Call flagsmith.init first, if you wish to prevent it sending a request for flags, call init with preventFetch:true.");
282
+ }, this.hasFeature = function(i, n) {
283
+ var r = typeof n == "object", o = t.flags && t.flags[i.toLowerCase().replace(/ /g, "_")], u = !1;
284
+ return !o && r && n.fallback !== void 0 ? u = n == null ? void 0 : n.fallback : o && o.enabled && (u = !0), (r && !n.skipAnalytics || !n) && t.evaluateFlag(i, "ENABLED"), u;
285
+ }, this.getStorageKey = function() {
286
+ var i, n;
287
+ return ((i = t.cacheOptions) === null || i === void 0 ? void 0 : i.storageKey) || "FLAGSMITH_DB_" + ((n = t.evaluationContext.environment) === null || n === void 0 ? void 0 : n.apiKey);
288
+ }, this.getJSON = function(i, n, r) {
289
+ var o, u = t;
290
+ u.evaluationContext;
291
+ var h = u.headers, p = { method: n || "GET", body: r, cache: "no-cache", headers: {} };
292
+ t.evaluationContext.environment && (p.headers["X-Environment-Key"] = t.evaluationContext.environment.apiKey), n && n !== "GET" && (p.headers["Content-Type"] = "application/json; charset=utf-8"), h && Object.assign(p.headers, h), f || console.error("Flagsmith: fetch is undefined, please specify a fetch implementation into flagsmith.init to support SSR.");
293
+ var l = "".concat((o = t.evaluationContext.identity) === null || o === void 0 ? void 0 : o.identifier);
294
+ return f(i, p).then(function(y) {
295
+ var x, U, L = "".concat((x = t.evaluationContext.identity) === null || x === void 0 ? void 0 : x.identifier);
296
+ if (l === L) {
297
+ var P = (U = y.headers) === null || U === void 0 ? void 0 : U.get("x-flagsmith-document-updated-at");
298
+ if (P) try {
299
+ var A = parseFloat(P);
300
+ if (isNaN(A)) return Promise.reject("Failed to parse x-flagsmith-document-updated-at");
301
+ t.timestamp = A;
302
+ } catch (j) {
303
+ t.log(j, "Failed to parse x-flagsmith-document-updated-at", P);
304
+ }
305
+ return t.log("Fetch response: " + y.status + " " + (n || "GET") + 0 + i), y.text().then(function(j) {
306
+ var K = j;
307
+ try {
308
+ K = JSON.parse(j);
309
+ } catch {
310
+ }
311
+ return !K && y.status && (K = "API Response: ".concat(y.status)), y.status && y.status >= 200 && y.status < 300 ? K : Promise.reject(new Error(K));
312
+ });
313
+ }
314
+ t.log("Received response with identity mismatch, ignoring response. Requested: ".concat(l, ", Current: ").concat(L));
315
+ });
316
+ }, this.evaluateFlag = function(i, n) {
317
+ if (t.datadogRum && (t.datadogRum.client.addFeatureFlagEvaluation ? n === "VALUE" ? t.datadogRum.client.addFeatureFlagEvaluation(Gt + i, t.getValue(i, {}, !0)) : t.datadogRum.client.addFeatureFlagEvaluation(Jt + i, t.hasFeature(i, !0)) : console.error("Flagsmith: Your datadog RUM client does not support the function addFeatureFlagEvaluation, please update it.")), t.enableAnalytics) {
318
+ if (!t.evaluationEvent || !t.evaluationContext.environment) return;
319
+ t.evaluationEvent[t.evaluationContext.environment.apiKey] || (t.evaluationEvent[t.evaluationContext.environment.apiKey] = {}), t.evaluationEvent[t.evaluationContext.environment.apiKey][i] === void 0 && (t.evaluationEvent[t.evaluationContext.environment.apiKey][i] = 0), t.evaluationEvent[t.evaluationContext.environment.apiKey][i] += 1;
320
+ }
321
+ t.updateEventStorage();
322
+ }, this._onChange = function(i, n, r) {
323
+ var o, u;
324
+ t.setLoadingState(r), (o = t.onChange) === null || o === void 0 || o.call(t, i, n, t.loadingState), (u = t._trigger) === null || u === void 0 || u.call(t);
325
+ }, f = e.fetch ? e.fetch : typeof fetch < "u" ? fetch : lt === null || lt === void 0 ? void 0 : lt.fetch, this.canUseStorage = typeof window < "u" || !!e.browserlessStorage, this.log("Constructing flagsmith instance " + e), e.eventSource && (ht = e.eventSource), e.AsyncStorage && (O = e.AsyncStorage);
326
+ }
327
+ return a.prototype.init = function(e) {
328
+ var t, i, n;
329
+ return F(this, void 0, void 0, function() {
330
+ var r, o, u, h, p, l, y, x, U, L, P, A, j, K, W, tt, q, E, m, dt, et, Xt, X, gt, Yt, Zt, ft, Qt, pt, nt, Y, Wt, w = this;
331
+ return I(this, function(R) {
332
+ switch (R.label) {
333
+ case 0:
334
+ r = ct(e.evaluationContext || this.evaluationContext), R.label = 1;
335
+ case 1:
336
+ if (R.trys.push([1, 13, , 14]), o = e.environmentID, u = e.api, h = u === void 0 ? Dt : u, p = e.headers, l = e.onChange, y = e.cacheFlags, x = e.datadogRum, U = e.onError, L = e.defaultFlags, P = e.fetch, A = e.preventFetch, j = e.enableLogs, K = e.enableDynatrace, W = e.enableAnalytics, tt = e.realtime, q = e.eventSourceUrl, E = q === void 0 ? "https://realtime.flagsmith.com/" : q, m = e.AsyncStorage, dt = e.identity, et = e.traits, Xt = e.state, X = e.cacheOptions, gt = e.angularHttpClient, Yt = e._trigger, Zt = e._triggerLoadingState, r.environment = o ? { apiKey: o } : r.environment, !r.environment || !r.environment.apiKey) throw new Error("Please provide `evaluationContext.environment` with non-empty `apiKey`");
337
+ if (r.identity = dt || et ? { identifier: dt, traits: et ? Object.fromEntries(Object.entries(et).map(function(T) {
338
+ return [T[0], { value: T[1] }];
339
+ })) : {} } : r.identity, this.evaluationContext = r, this.api = h, this.headers = p, this.getFlagInterval = null, this.analyticsInterval = null, this.onChange = l, ft = "Wrong Flagsmith Configuration: preventFetch is true and no defaulFlags provided", this._trigger = Yt || this._trigger, this._triggerLoadingState = Zt || this._triggerLoadingState, this.onError = function(T) {
340
+ w.setLoadingState(s(s({}, w.loadingState), { isFetching: !1, isLoading: !1, error: T })), U == null || U(T);
341
+ }, this.enableLogs = j || !1, this.cacheOptions = X ? { skipAPI: !!X.skipAPI, ttl: X.ttl || 0, storageKey: X.storageKey, loadStale: !!X.loadStale } : this.cacheOptions, !this.cacheOptions.ttl && this.cacheOptions.skipAPI && console.warn("Flagsmith: you have set a cache ttl of 0 and are skipping API calls, this means the API will not be hit unless you clear local storage."), P && (f = P), this.enableAnalytics = W || !1, this.flags = Object.assign({}, L) || {}, this.datadogRum = x || null, this.initialised = !0, this.ticks = 1e4, this.timer = this.enableLogs ? (/* @__PURE__ */ new Date()).valueOf() : null, this.cacheFlags = O !== void 0 && !!y, rt = "FLAGSMITH_EVENT_" + r.environment.apiKey, m && (O = m), tt && typeof window < "u" && this.setupRealtime(E, r.environment.apiKey), Object.keys(this.flags).length && (this.loadingState = s(s({}, this.loadingState), { isLoading: !1, source: d.DEFAULT_FLAGS })), this.setState(Xt), this.log("Initialising with properties", e, this), K && (typeof dtrum > "u" ? console.error("You have attempted to enable dynatrace but dtrum is undefined, please check you have the Dynatrace RUM JavaScript API installed.") : this.dtrum = dtrum), gt && (f = /* @__PURE__ */ function(T) {
342
+ return function(D, G) {
343
+ var z = G.headers, S = G.method, Z = G.body;
344
+ return new Promise(function(B) {
345
+ switch (S) {
346
+ case "GET":
347
+ return T.get(D, { headers: z }).subscribe(function(M) {
348
+ B({ ok: !0, text: function() {
349
+ return Promise.resolve(M);
350
+ } });
351
+ });
352
+ case "POST":
353
+ case "PUT":
354
+ return T.post(D, Z, { headers: z }).subscribe(function(M) {
355
+ B({ ok: !0, text: function() {
356
+ return Promise.resolve(M);
357
+ } });
358
+ });
359
+ }
360
+ });
361
+ };
362
+ }(gt)), O && this.canUseStorage && O.getItem(rt).then(function(T) {
363
+ try {
364
+ w.evaluationEvent = JSON.parse(T) || {};
365
+ } catch {
366
+ w.evaluationEvent = {};
367
+ }
368
+ w.analyticsInterval = setInterval(w.analyticsFlags, w.ticks);
369
+ }), this.enableAnalytics && (this.analyticsInterval && clearInterval(this.analyticsInterval), O && this.canUseStorage && O.getItem(rt, function(T, D) {
370
+ if (D && w.evaluationContext.environment) {
371
+ var G = JSON.parse(D);
372
+ if (G[w.evaluationContext.environment.apiKey]) {
373
+ var z = w.getState();
374
+ w.log("Retrieved events from cache", D), w.setState(s(s({}, z), { evaluationEvent: G[w.evaluationContext.environment.apiKey] }));
375
+ }
376
+ }
377
+ })), !y) return [3, 9];
378
+ if (!O || !this.canUseStorage) return [3, 8];
379
+ Qt = function(T, D) {
380
+ return F(w, void 0, void 0, function() {
381
+ var G, z, S, Z, B, M, yt, te, mt, St, Ct, _t, bt, Ft, xt, Et, wt, Ot, It, Lt, At, jt, Tt, Nt, ee = this;
382
+ return I(this, function(H) {
383
+ switch (H.label) {
384
+ case 0:
385
+ if (!D) return [3, 7];
386
+ G = null, z = null, H.label = 1;
387
+ case 1:
388
+ return H.trys.push([1, 5, , 6]), S = JSON.parse(D), Z = !1, B = !1, S && S.api === this.api && ((St = (mt = S.evaluationContext) === null || mt === void 0 ? void 0 : mt.environment) === null || St === void 0 ? void 0 : St.apiKey) === ((Ct = this.evaluationContext.environment) === null || Ct === void 0 ? void 0 : Ct.apiKey) && (M = !0, this.evaluationContext.identity && ((bt = (_t = S.evaluationContext) === null || _t === void 0 ? void 0 : _t.identity) === null || bt === void 0 ? void 0 : bt.identifier) !== this.evaluationContext.identity.identifier && (this.log("Ignoring cache, identity has changed from " + ((xt = (Ft = S.evaluationContext) === null || Ft === void 0 ? void 0 : Ft.identity) === null || xt === void 0 ? void 0 : xt.identifier) + " to " + this.evaluationContext.identity.identifier), M = !1), this.cacheOptions.ttl && (!S.ts || (/* @__PURE__ */ new Date()).valueOf() - S.ts > this.cacheOptions.ttl) && (S.ts && !this.cacheOptions.loadStale ? (this.log("Ignoring cache, timestamp is too old ts:" + S.ts + " ttl: " + this.cacheOptions.ttl + " time elapsed since cache: " + ((/* @__PURE__ */ new Date()).valueOf() - S.ts) + "ms"), M = !1) : S.ts && this.cacheOptions.loadStale && (this.log("Loading stale cache, timestamp ts:" + S.ts + " ttl: " + this.cacheOptions.ttl + " time elapsed since cache: " + ((/* @__PURE__ */ new Date()).valueOf() - S.ts) + "ms"), B = !0, M = !0)), M && (Z = !0, z = _((Et = this.evaluationContext.identity) === null || Et === void 0 ? void 0 : Et.traits, (Ot = (wt = S.evaluationContext) === null || wt === void 0 ? void 0 : wt.identity) === null || Ot === void 0 ? void 0 : Ot.traits), G = _(this.flags, S.flags), this.setState(s(s({}, S), { evaluationContext: ct(s(s({}, S.evaluationContext), { identity: !((It = S.evaluationContext) === null || It === void 0) && It.identity ? s(s({}, (Lt = S.evaluationContext) === null || Lt === void 0 ? void 0 : Lt.identity), { traits: s(s({}, ((jt = (At = S.evaluationContext) === null || At === void 0 ? void 0 : At.identity) === null || jt === void 0 ? void 0 : jt.traits) || {}), et || {}) }) : void 0 })) })), this.log("Retrieved flags from cache", S))), Z ? (yt = !A && (!this.cacheOptions.skipAPI || B), this._onChange(null, { isFromServer: !1, flagsChanged: G, traitsChanged: z }, this._loadedState(null, d.CACHE, yt)), this.oldFlags = this.flags, this.cacheOptions.skipAPI && Z && !B && this.log("Skipping API, using cache"), yt && this.getFlags().catch(function(le) {
389
+ var kt;
390
+ (kt = ee.onError) === null || kt === void 0 || kt.call(ee, le);
391
+ }), [3, 4]) : [3, 2];
392
+ case 2:
393
+ return A ? [3, 4] : [4, this.getFlags()];
394
+ case 3:
395
+ H.sent(), H.label = 4;
396
+ case 4:
397
+ return [3, 6];
398
+ case 5:
399
+ return te = H.sent(), this.log("Exception fetching cached logs", te), [3, 6];
400
+ case 6:
401
+ return [3, 10];
402
+ case 7:
403
+ return A ? [3, 9] : [4, this.getFlags()];
404
+ case 8:
405
+ return H.sent(), [3, 10];
406
+ case 9:
407
+ if (L) this._onChange(null, { isFromServer: !1, flagsChanged: _({}, this.flags), traitsChanged: _({}, (Tt = this.evaluationContext.identity) === null || Tt === void 0 ? void 0 : Tt.traits) }, this._loadedState(null, d.DEFAULT_FLAGS));
408
+ else {
409
+ if (!this.flags) throw new Error(ft);
410
+ this._onChange(null, { isFromServer: !1, flagsChanged: _({}, this.flags), traitsChanged: _({}, (Nt = this.evaluationContext.identity) === null || Nt === void 0 ? void 0 : Nt.traits) }, this._loadedState(null, d.DEFAULT_FLAGS));
411
+ }
412
+ H.label = 10;
413
+ case 10:
414
+ return [2];
415
+ }
416
+ });
417
+ });
418
+ }, R.label = 2;
419
+ case 2:
420
+ return R.trys.push([2, 7, , 8]), O.getItemSync ? (pt = O.getItemSync(this.getStorageKey()), [3, 5]) : [3, 3];
421
+ case 3:
422
+ return [4, O.getItem(this.getStorageKey())];
423
+ case 4:
424
+ pt = R.sent(), R.label = 5;
425
+ case 5:
426
+ return [4, Qt(null, pt)];
427
+ case 6:
428
+ case 7:
429
+ return R.sent(), [3, 8];
430
+ case 8:
431
+ return [3, 12];
432
+ case 9:
433
+ return A ? [3, 11] : [4, this.getFlags()];
434
+ case 10:
435
+ return R.sent(), [3, 12];
436
+ case 11:
437
+ if (L) this._onChange(null, { isFromServer: !1, flagsChanged: _({}, L), traitsChanged: _({}, (t = r.identity) === null || t === void 0 ? void 0 : t.traits) }, this._loadedState(null, d.DEFAULT_FLAGS));
438
+ else if (this.flags && (nt = null, Object.keys(this.flags).length === 0 && (nt = ft), this._onChange(null, { isFromServer: !1, flagsChanged: _({}, this.flags), traitsChanged: _({}, (i = r.identity) === null || i === void 0 ? void 0 : i.traits) }, this._loadedState(nt, d.DEFAULT_FLAGS)), nt)) throw new Error(nt);
439
+ R.label = 12;
440
+ case 12:
441
+ return [3, 14];
442
+ case 13:
443
+ throw Y = R.sent(), this.log("Error during initialisation ", Y), Wt = Y instanceof Error ? Y : new Error("".concat(Y)), (n = this.onError) === null || n === void 0 || n.call(this, Wt), Y;
444
+ case 14:
445
+ return [2];
446
+ }
447
+ });
448
+ });
449
+ }, a.prototype.getAllFlags = function() {
450
+ return this.flags;
451
+ }, a.prototype.identify = function(e, t, i) {
452
+ return this.evaluationContext.identity = { identifier: e, transient: i, traits: this.evaluationContext.identity && this.evaluationContext.identity.identifier == e ? this.evaluationContext.identity.traits : {} }, this.evaluationContext.identity.identifier = e, this.log("Identify: " + this.evaluationContext.identity.identifier), t && (this.evaluationContext.identity.traits = Object.fromEntries(Object.entries(t).map(function(n) {
453
+ var r = n[0], o = n[1];
454
+ return [r, V(o) ? o : { value: o }];
455
+ }))), this.initialised ? this.getFlags() : Promise.resolve();
456
+ }, a.prototype.getState = function() {
457
+ return { api: this.api, flags: this.flags, ts: this.ts, evaluationContext: this.evaluationContext, evaluationEvent: this.evaluationEvent };
458
+ }, a.prototype.setState = function(e) {
459
+ e && (this.initialised = !0, this.api = e.api || this.api || Dt, this.flags = e.flags || this.flags, this.evaluationContext = e.evaluationContext || this.evaluationContext, this.evaluationEvent = e.evaluationEvent || this.evaluationEvent, this.log("setState called", this));
460
+ }, a.prototype.logout = function() {
461
+ return this.evaluationContext.identity = null, this.initialised ? this.getFlags() : Promise.resolve();
462
+ }, a.prototype.startListening = function(e) {
463
+ e === void 0 && (e = 1e3), this.getFlagInterval && clearInterval(this.getFlagInterval), this.getFlagInterval = setInterval(this.getFlags, e);
464
+ }, a.prototype.stopListening = function() {
465
+ this.getFlagInterval && (clearInterval(this.getFlagInterval), this.getFlagInterval = null);
466
+ }, a.prototype._loadedState = function(e, t, i) {
467
+ return e === void 0 && (e = null), i === void 0 && (i = !1), { error: e, isFetching: i, isLoading: !1, source: t };
468
+ }, a.prototype.log = function() {
469
+ for (var e = [], t = 0; t < arguments.length; t++) e[t] = arguments[t];
470
+ this.enableLogs && console.log.apply(this, N(["FLAGSMITH:", (/* @__PURE__ */ new Date()).valueOf() - (this.timer || 0), "ms"], e));
471
+ }, a.prototype.updateStorage = function() {
472
+ if (this.cacheFlags) {
473
+ this.ts = (/* @__PURE__ */ new Date()).valueOf();
474
+ var e = JSON.stringify(this.getState());
475
+ this.log("Setting storage", e), O.setItem(this.getStorageKey(), e);
476
+ }
477
+ }, a.prototype.updateEventStorage = function() {
478
+ if (this.enableAnalytics) {
479
+ var e = JSON.stringify(this.getState().evaluationEvent);
480
+ O.setItem(rt, e).catch(function(t) {
481
+ return console.error("Flagsmith: Error setting item in async storage", t);
482
+ });
483
+ }
484
+ }, a.prototype.setLoadingState = function(e) {
485
+ var t;
486
+ k(e, this.loadingState) || (this.loadingState = s({}, e), this.log("Loading state changed", e), (t = this._triggerLoadingState) === null || t === void 0 || t.call(this));
487
+ }, a.prototype.setupRealtime = function(e, t) {
488
+ var i = this, n = e + "sse/environments/" + t + "/stream";
489
+ ht ? this.eventSource || (this.log("Creating event source with url " + n), this.eventSource = new ht(n), this.eventSource.addEventListener("environment_updated", function(r) {
490
+ var o;
491
+ try {
492
+ o = JSON.parse(r.data).updated_at;
493
+ } catch (u) {
494
+ i.log("Could not parse sse event", u);
495
+ }
496
+ o ? !i.timestamp || o > i.timestamp ? i.isLoading ? i.log("updated_at is new, but flags are loading", r.data, i.timestamp) : (i.log("updated_at is new, fetching flags", r.data, i.timestamp), i.getFlags()) : i.log("updated_at is outdated, skipping get flags", r.data, i.timestamp) : i.log("No updated_at received, fetching flags", r);
497
+ })) : this.log("Error, EventSource is undefined");
498
+ }, a;
499
+ }();
500
+ function Mt(a) {
501
+ var e = a.fetch, t = a.AsyncStorage, i = a.eventSource;
502
+ return new re({ fetch: e, AsyncStorage: t, eventSource: i });
503
+ }
504
+ var ot, oe = (ot = function(a, e) {
505
+ return ot = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, i) {
506
+ t.__proto__ = i;
507
+ } || function(t, i) {
508
+ for (var n in i) Object.prototype.hasOwnProperty.call(i, n) && (t[n] = i[n]);
509
+ }, ot(a, e);
510
+ }, function(a, e) {
511
+ if (typeof e != "function" && e !== null) throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
512
+ function t() {
513
+ this.constructor = a;
514
+ }
515
+ ot(a, e), a.prototype = e === null ? Object.create(e) : (t.prototype = e.prototype, new t());
516
+ }), zt = function(a) {
517
+ var e = typeof Symbol == "function" && Symbol.iterator, t = e && a[e], i = 0;
518
+ if (t) return t.call(a);
519
+ if (a && typeof a.length == "number") return { next: function() {
520
+ return a && i >= a.length && (a = void 0), { value: a && a[i++], done: !a };
521
+ } };
522
+ throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined.");
523
+ }, Ht = function(a, e) {
524
+ var t = typeof Symbol == "function" && a[Symbol.iterator];
525
+ if (!t) return a;
526
+ var i, n, r = t.call(a), o = [];
527
+ try {
528
+ for (; (e === void 0 || e-- > 0) && !(i = r.next()).done; ) o.push(i.value);
529
+ } catch (u) {
530
+ n = { error: u };
531
+ } finally {
532
+ try {
533
+ i && !i.done && (t = r.return) && t.call(r);
534
+ } finally {
535
+ if (n) throw n.error;
536
+ }
537
+ }
538
+ return o;
539
+ }, vt = function(a, e, t) {
540
+ if (arguments.length === 2) for (var i, n = 0, r = e.length; n < r; n++) !i && n in e || (i || (i = Array.prototype.slice.call(e, 0, n)), i[n] = e[n]);
541
+ return a.concat(i || Array.prototype.slice.call(e));
542
+ }, se = function(a) {
543
+ function e() {
544
+ return a.call(this, `EventSource not available.
545
+ Consider loading an EventSource polyfill and making it available globally as EventSource, or passing one in as eventSourceClass to the ReconnectingEventSource constructor.`) || this;
546
+ }
547
+ return oe(e, a), e;
548
+ }(Error), Bt = function() {
549
+ function a(e, t) {
550
+ var i = this;
551
+ if (this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, this._configuration = t != null ? Object.assign({}, t) : void 0, this.withCredentials = !1, this._eventSource = null, this._lastEventId = null, this._timer = null, this._listeners = { open: [], error: [], message: [] }, this.url = e.toString(), this.readyState = this.CONNECTING, this.max_retry_time = 3e3, this.eventSourceClass = globalThis.FlagsmithEventSource, this._configuration != null && (this._configuration.lastEventId && (this._lastEventId = this._configuration.lastEventId, delete this._configuration.lastEventId), this._configuration.max_retry_time && (this.max_retry_time = this._configuration.max_retry_time, delete this._configuration.max_retry_time), this._configuration.eventSourceClass && (this.eventSourceClass = this._configuration.eventSourceClass, delete this._configuration.eventSourceClass)), this.eventSourceClass == null || typeof this.eventSourceClass != "function") throw new se();
552
+ this._onevent_wrapped = function(n) {
553
+ i._onevent(n);
554
+ }, this._start();
555
+ }
556
+ return a.prototype.dispatchEvent = function(e) {
557
+ throw new Error("Method not implemented.");
558
+ }, a.prototype._start = function() {
559
+ var e, t, i = this, n = this.url;
560
+ this._lastEventId && (n.indexOf("?") === -1 ? n += "?" : n += "&", n += "lastEventId=" + encodeURIComponent(this._lastEventId)), this._eventSource = new this.eventSourceClass(n, this._configuration), this._eventSource.onopen = function(h) {
561
+ i._onopen(h);
562
+ }, this._eventSource.onerror = function(h) {
563
+ i._onerror(h);
564
+ }, this._eventSource.onmessage = function(h) {
565
+ i.onmessage(h);
566
+ };
567
+ try {
568
+ for (var r = zt(Object.keys(this._listeners)), o = r.next(); !o.done; o = r.next()) {
569
+ var u = o.value;
570
+ this._eventSource.addEventListener(u, this._onevent_wrapped);
571
+ }
572
+ } catch (h) {
573
+ e = { error: h };
574
+ } finally {
575
+ try {
576
+ o && !o.done && (t = r.return) && t.call(r);
577
+ } finally {
578
+ if (e) throw e.error;
579
+ }
580
+ }
581
+ }, a.prototype._onopen = function(e) {
582
+ this.readyState === 0 && (this.readyState = 1, this.onopen(e));
583
+ }, a.prototype._onerror = function(e) {
584
+ var t = this;
585
+ if (this.readyState === 1 && (this.readyState = 0, this.onerror(e)), this._eventSource) {
586
+ this._eventSource.close(), this._eventSource = null;
587
+ var i = Math.round(this.max_retry_time * Math.random());
588
+ this._timer = setTimeout(function() {
589
+ return t._start();
590
+ }, i);
591
+ }
592
+ }, a.prototype._onevent = function(e) {
593
+ var t, i;
594
+ e && e.lastEventId && (this._lastEventId = e.lastEventId);
595
+ var n = this._listeners[e.type];
596
+ if (n != null) try {
597
+ for (var r = zt(vt([], Ht(n), !1)), o = r.next(); !o.done; o = r.next())
598
+ o.value.call(this, e);
599
+ } catch (u) {
600
+ t = { error: u };
601
+ } finally {
602
+ try {
603
+ o && !o.done && (i = r.return) && i.call(r);
604
+ } finally {
605
+ if (t) throw t.error;
606
+ }
607
+ }
608
+ e.type === "message" && this.onmessage(e);
609
+ }, a.prototype.onopen = function(e) {
610
+ }, a.prototype.onerror = function(e) {
611
+ }, a.prototype.onmessage = function(e) {
612
+ }, a.prototype.close = function() {
613
+ this._timer && (clearTimeout(this._timer), this._timer = null), this._eventSource && (this._eventSource.close(), this._eventSource = null), this.readyState = 2;
614
+ }, a.prototype.addEventListener = function(e, t, i) {
615
+ this._listeners[e] == null && (this._listeners[e] = [], this._eventSource != null && this._eventSource.addEventListener(e, this._onevent_wrapped));
616
+ var n = this._listeners[e];
617
+ n.includes(t) || (this._listeners[e] = vt(vt([], Ht(n), !1), [t], !1));
618
+ }, a.prototype.removeEventListener = function(e, t, i) {
619
+ var n = this._listeners[e];
620
+ this._listeners[e] = n.filter(function(r) {
621
+ return r !== t;
622
+ });
623
+ }, a;
624
+ }();
625
+ globalThis.FlagsmithEventSource = typeof EventSource < "u" ? EventSource : null;
626
+ var $t = function(a, e) {
627
+ return e = e || {}, new Promise(function(t, i) {
628
+ var n = new XMLHttpRequest(), r = [], o = [], u = {}, h = function() {
629
+ return { ok: (n.status / 100 | 0) == 2, statusText: n.statusText, status: n.status, url: n.responseURL, text: function() {
630
+ return Promise.resolve(n.responseText);
631
+ }, json: function() {
632
+ return Promise.resolve(n.responseText).then(JSON.parse);
633
+ }, blob: function() {
634
+ return Promise.resolve(new Blob([n.response]));
635
+ }, clone: h, headers: { keys: function() {
636
+ return r;
637
+ }, entries: function() {
638
+ return o;
639
+ }, get: function(l) {
640
+ return u[l.toLowerCase()];
641
+ }, has: function(l) {
642
+ return l.toLowerCase() in u;
643
+ } } };
644
+ };
645
+ for (var p in n.open(e.method || "get", a, !0), n.onload = function() {
646
+ n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, function(l, y, x) {
647
+ r.push(y = y.toLowerCase()), o.push([y, x]), u[y] = u[y] ? u[y] + "," + x : x;
648
+ }), t(h());
649
+ }, n.onerror = i, n.withCredentials = e.credentials == "include", e.headers) n.setRequestHeader(p, e.headers[p]);
650
+ n.send(e.body || null);
651
+ });
652
+ }, qt = Mt({ AsyncStorage: g, fetch: $t, eventSource: Bt });
653
+ typeof window < "u" && (window.flagsmith = qt), v.createFlagsmithInstance = function() {
654
+ return Mt({ AsyncStorage: g, fetch: $t, eventSource: Bt });
655
+ }, v.default = qt, Object.defineProperty(v, "__esModule", { value: !0 });
656
+ });
657
+ })(Ut, Ut.exports);
658
+ var de = Ut.exports, ge = {
659
+ NOT_INITIALIZED: "FeatureFlag not initialized. Call init() first."
660
+ }, ne = "business", J, fe = (J = class {
661
+ constructor() {
662
+ st(this, "flagsmithClient", null);
663
+ st(this, "userContext", null);
664
+ }
665
+ static getInstance() {
666
+ return J.instance || (J.instance = new J()), J.instance;
667
+ }
668
+ ensureInitialized() {
669
+ if (!this.flagsmithClient)
670
+ throw new Error(ge.NOT_INITIALIZED);
671
+ }
672
+ async init(c, v = []) {
673
+ if (!this.flagsmithClient)
674
+ try {
675
+ this.flagsmithClient = de.createFlagsmithInstance();
676
+ const g = v.reduce((s, F) => (s[F.feature.name] = F, s), {});
677
+ await this.flagsmithClient.init({
678
+ environmentID: c.apiKey,
679
+ api: (c == null ? void 0 : c.url) ?? "https://feature-flag-proxy.feedme.farm/api/v1/",
680
+ enableAnalytics: (c == null ? void 0 : c.enableAnalytics) ?? !0,
681
+ defaultFlags: g,
682
+ cacheFlags: (c == null ? void 0 : c.cacheFlags) ?? !0
683
+ });
684
+ } catch (g) {
685
+ throw console.error("Failed to initialize FeatureFlag:", g), g;
686
+ }
687
+ }
688
+ async setUser(c) {
689
+ this.ensureInitialized(), this.userContext = { identifier: c }, await this.updateContext();
690
+ }
691
+ async updateContext() {
692
+ try {
693
+ if (!this.userContext) return;
694
+ await this.flagsmithClient.setContext({
695
+ identity: {
696
+ identifier: this.userContext.identifier
697
+ }
698
+ });
699
+ } catch (c) {
700
+ throw console.error("Failed to update user context:", c), c;
701
+ }
702
+ }
703
+ async getFlags() {
704
+ this.ensureInitialized();
705
+ const c = this.flagsmithClient.getAllFlags();
706
+ return Object.entries(c).map(([v, g]) => {
707
+ var s;
708
+ return {
709
+ feature: {
710
+ name: v,
711
+ id: (g == null ? void 0 : g.id) ?? 0
712
+ },
713
+ enabled: g.enabled,
714
+ value: ((s = g.value) == null ? void 0 : s.toString()) ?? null
715
+ };
716
+ });
717
+ }
718
+ getFlagValue(c, v) {
719
+ this.ensureInitialized();
720
+ const g = this.flagsmithClient.getValue(c);
721
+ if (g == null)
722
+ return null;
723
+ try {
724
+ const s = g.toString();
725
+ return v ? v(s) : typeof {} == "number" ? isNaN(Number(s)) ? null : Number(s) : typeof {} == "boolean" ? s.toLowerCase() === "true" : s;
726
+ } catch (s) {
727
+ return console.error("Error transforming flag value:", s), null;
728
+ }
729
+ }
730
+ getFlag(c) {
731
+ this.ensureInitialized();
732
+ const v = this.flagsmithClient.getValue(c);
733
+ if (v == null) return null;
734
+ const g = this.flagsmithClient.hasFeature(c);
735
+ return {
736
+ feature: {
737
+ name: c,
738
+ id: 0
739
+ },
740
+ enabled: g,
741
+ value: v.toString()
742
+ };
743
+ }
744
+ async getUserFlagValue(c, v, g = null, s) {
745
+ var I;
746
+ const F = this.userContext;
747
+ try {
748
+ return await this.setUser(c), this.getFlagValue(v, s) ?? g;
749
+ } catch (N) {
750
+ return console.error(`Error getting user flag value for ${v}:`, N), g;
751
+ } finally {
752
+ try {
753
+ await ((I = this.flagsmithClient) == null ? void 0 : I.logout()), this.userContext = null, F && await this.setUser(F.identifier);
754
+ } catch (N) {
755
+ console.error("Error during cleanup:", N);
756
+ }
757
+ }
758
+ }
759
+ reset() {
760
+ this.flagsmithClient = null, this.userContext = null;
761
+ }
762
+ }, st(J, "instance"), J), pe = fe.getInstance(), it = $(!1), ut = $([]), Q = $(null);
763
+ function ye(C = pe) {
764
+ const c = () => it.value ? !0 : (console.warn("FeatureFlag is not initialized. Using default values."), !1), v = async (d, f = []) => {
765
+ if (it.value) {
766
+ console.warn("FeatureFlag is already initialized.");
767
+ return;
768
+ }
769
+ try {
770
+ await C.init(d, f), ut.value = await C.getFlags(), it.value = !0, Q.value = null;
771
+ } catch (b) {
772
+ console.error("Failed to initialize feature flags:", b), Q.value = b;
773
+ }
774
+ }, g = async (d) => {
775
+ if (c())
776
+ try {
777
+ await C.setUser(d), ut.value = await C.getFlags(), Q.value = null;
778
+ } catch (f) {
779
+ console.error("Failed to set user:", f), Q.value = f;
780
+ }
781
+ }, s = async (d) => g(`${ne}-${d}`), F = (d, f, b = null) => {
782
+ if (!c()) return b;
783
+ try {
784
+ return C.getFlagValue(d, f) ?? b;
785
+ } catch (V) {
786
+ return console.error(`Error getting flag value for ${d}:`, V), b;
787
+ }
788
+ }, I = (d, f) => {
789
+ if (!c()) return f ?? null;
790
+ try {
791
+ return C.getFlag(d) ?? f ?? null;
792
+ } catch (b) {
793
+ return console.error(`Error getting flag for ${d}:`, b), f ?? null;
794
+ }
795
+ }, N = async (d, f, b = null, V) => {
796
+ if (!c()) return b;
797
+ try {
798
+ return await C.getUserFlagValue(d, f, b, V);
799
+ } catch (at) {
800
+ return console.error(`Error getting user flag value for ${f}:`, at), b;
801
+ }
802
+ }, k = async (d, f, b = null, V) => N(`${ne}-${d}`, f, b, V), _ = () => {
803
+ try {
804
+ C.reset();
805
+ } catch (d) {
806
+ console.error("Error resetting feature flags:", d);
807
+ } finally {
808
+ ut.value = [], it.value = !1, Q.value = null;
809
+ }
810
+ };
811
+ return {
812
+ flags: Pt(ut),
813
+ isInitialized: Pt(it),
814
+ error: Pt(Q),
815
+ init: v,
816
+ setUser: g,
817
+ setBusiness: s,
818
+ getFlagValue: F,
819
+ getFlag: I,
820
+ getUserFlagValue: N,
821
+ getBusinessFlagValue: k,
822
+ reset: _
823
+ };
824
+ }
825
+ var ie = () => ye();
826
+ const Kt = $(!1), Rt = $({});
827
+ async function be(C) {
828
+ const { init: c } = ie();
829
+ await c({ apiKey: C === "prod" ? "6GhcttsJ9Rj9cTevcdrpin" : "MaGoXrEWuEJNpWgKTqseee" }), Kt.value = !0;
830
+ }
831
+ function Fe(C, c, v) {
832
+ const g = ve(), { getBusinessFlagValue: s } = ie(), F = $(c), I = $(!0), N = async () => {
833
+ var d;
834
+ const k = (d = g.currentBusiness.value) == null ? void 0 : d._id;
835
+ if (!k || !Kt.value)
836
+ return;
837
+ const _ = `${k}:${C}`;
838
+ if (_ in Rt.value) {
839
+ const f = Rt.value[_];
840
+ F.value = v ? v(f) : f, I.value = !1;
841
+ return;
842
+ }
843
+ try {
844
+ const f = await s(k, C, c);
845
+ Rt.value[_] = f, F.value = v ? v(f) : f;
846
+ } catch {
847
+ F.value = c;
848
+ } finally {
849
+ I.value = !1;
850
+ }
851
+ };
852
+ return he(
853
+ [() => {
854
+ var k;
855
+ return (k = g.currentBusiness.value) == null ? void 0 : k._id;
856
+ }, Kt],
857
+ () => {
858
+ I.value = !0, N();
859
+ },
860
+ { immediate: !0 }
861
+ ), { value: F, loading: I };
862
+ }
863
+ export {
864
+ be as i,
865
+ Fe as u
866
+ };