@feedmepos/mf-miniprogram-v2 0.2.10 → 0.2.11-dev.2

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