@feedmepos/mf-order-setting 0.0.91 → 0.0.93

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