@feedmepos/mf-inventory-portal 0.0.25-dev.2 → 0.0.25-dev.21

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 (115) hide show
  1. package/dist/App-D6WBVERc.js +278 -0
  2. package/dist/ApprovalView-BIBoagE8.js +146 -0
  3. package/dist/{BindingsDialog-qeGh3ND8.js → BindingsDialog-DHRRkK1Z.js} +6 -6
  4. package/dist/{BindingsPicker-SfiA8fmD.js → BindingsPicker-DohvMDDF.js} +3 -3
  5. package/dist/{BindingsTable-BjW-eJr6.js → BindingsTable-C_JwU9ei.js} +6 -6
  6. package/dist/ClosingDraftView-BBebhUj-.js +1308 -0
  7. package/dist/ClosingTemplateView-CXRN19-D.js +1859 -0
  8. package/dist/FmCustomAttribute.vue_vue_type_script_setup_true_lang-D-IWRjRD.js +34 -0
  9. package/dist/FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-BJufUQNE.js +215 -0
  10. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-5rldKjyh.js → FmUnitInput.vue_vue_type_script_setup_true_lang-C5Xk19jY.js} +52 -52
  11. package/dist/IngredientBindedItem.vue_vue_type_script_setup_true_lang-7HNI82u-.js +51 -0
  12. package/dist/{IngredientGroupView-CGyyFyvj.js → IngredientGroupView-l2bAc1Kj.js} +1 -1
  13. package/dist/{IngredientsView-BLKk-VxQ.js → IngredientsView-zDXt7KEx.js} +394 -382
  14. package/dist/{IntegrationView-C6gwvZ9b.js → IntegrationView-BYnlAPrP.js} +660 -623
  15. package/dist/{InventoryBindingForm-BB3ZN3Lx.js → InventoryBindingForm-BuweG4Vl.js} +1 -1
  16. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-PT7Quw7j.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-DgxN0U4N.js} +99 -99
  17. package/dist/{InventoryBindingSummary-yr0oie3c.js → InventoryBindingSummary-BpEo0JsK.js} +1 -1
  18. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-DjJGUE9a.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-CcjzkzCt.js} +1 -1
  19. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-O1mYRa5W.js → PremiumBadge.vue_vue_type_script_setup_true_lang-Ej20iSHA.js} +15 -15
  20. package/dist/PublishView-DCZ0zIaP.js +222 -0
  21. package/dist/{PurchaseOrderPrintPreview-Q_9-KVNj.js → PurchaseOrderPrintPreview-Cag7UEvz.js} +1 -1
  22. package/dist/ReceiveRequestView-ChIJGA98.js +2319 -0
  23. package/dist/{RecipeView-DBfugmRY.js → RecipeView-bBshe0eF.js} +32 -31
  24. package/dist/{index-CgspzSQi.js → StockView-D6-oKpAC.js} +3577 -1764
  25. package/dist/{SupplierView-BQViPyfj.js → SupplierView-dyIcGp9Q.js} +12 -11
  26. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-C_7wbQow.js +1771 -0
  27. package/dist/TransferTemplateView-D2rxV0k_.js +1660 -0
  28. package/dist/{UnitView-CrbFeWaB.js → UnitView-DVS5Az5c.js} +14 -14
  29. package/dist/{WarehouseView-Dy5GljxY.js → WarehouseView-CR03TpnA.js} +332 -314
  30. package/dist/api/closing-draft.d.ts +1 -0
  31. package/dist/api/inventory.d.ts +9 -6
  32. package/dist/api/purchase-order.d.ts +2 -1
  33. package/dist/{app-D0O4wr2X.js → app-oV9ISfFL.js} +28343 -28141
  34. package/dist/app.js +1 -1
  35. package/dist/components/FmAutocompleteTextField.vue.d.ts +31 -0
  36. package/dist/components/FmCustomAttribute.vue.d.ts +3 -8
  37. package/dist/components/FmLockableField.vue.d.ts +3 -0
  38. package/dist/components/FmMultiselectDialog.d.ts +46 -0
  39. package/dist/components/FmMultiselectDialog.vue.d.ts +20 -3
  40. package/dist/components/FmMultiselectDialogProps.d.ts +2 -0
  41. package/dist/components/MountListener.vue.d.ts +15 -0
  42. package/dist/components/inventory-binding/InventoryBinding.vue.d.ts +1 -1
  43. package/dist/components/shell/inventory/binding-ui.vue.d.ts +1 -1
  44. package/dist/{decimal-CPGmj9BT.js → decimal-C7zgfr5G.js} +1 -1
  45. package/dist/feature-CDQQ-mV9.js +1003 -0
  46. package/dist/{format-unit-display-CMM6DZJj.js → format-unit-display-CVBzrNQ4.js} +334 -327
  47. package/dist/helper/fuzzy.d.ts +10 -0
  48. package/dist/index-0VS4cuk3.js +35546 -0
  49. package/dist/{stock-9nTT4Amy.js → stock-BIP_NIK_.js} +3 -3
  50. package/dist/stores/feature.d.ts +4 -7
  51. package/dist/stores/integration/netsuite.d.ts +5 -0
  52. package/dist/stores/inventory.d.ts +135 -8
  53. package/dist/stores/location.d.ts +100 -0
  54. package/dist/stores/warehouse.d.ts +1 -0
  55. package/dist/style.css +1 -1
  56. package/dist/{supplier-CH4EwBZM.js → supplier-DUQ2VSMg.js} +1 -1
  57. package/dist/tsconfig.app.tsbuildinfo +1 -1
  58. package/dist/use-ingredient-select-dialog-VkU5_Aaj.js +51 -0
  59. package/dist/{use-inventory-binding-dialog-Dli3xtq4.js → use-inventory-binding-dialog-BXp0z3v_.js} +1 -1
  60. package/dist/views/adjustment-template/wastage-template/actions.d.ts +24 -0
  61. package/dist/views/adjustment-template/wastage-template/table.d.ts +24 -0
  62. package/dist/views/closing-draft/components/closing-draft-dialog/ClosingDraftDialog.vue.d.ts +8 -4
  63. package/dist/views/closing-draft/composables/use-closing-draft-actions.d.ts +4 -1
  64. package/dist/views/closing-draft/composables/use-closing-draft-table.d.ts +48 -24
  65. package/dist/views/closing-draft/helpers/export-draft.helper.d.ts +1 -1
  66. package/dist/views/closing-template/components/closing-template-form/composables/use-closing-template-items.d.ts +1 -1
  67. package/dist/views/closing-template/composables/use-closing-template-actions.d.ts +36 -12
  68. package/dist/views/closing-template/composables/use-closing-template-table.d.ts +36 -12
  69. package/dist/views/dev/components/AutocompleteTextField.vue.d.ts +2 -0
  70. package/dist/views/ingredient-group/composables/use-ingredient-group-table.d.ts +3 -3
  71. package/dist/views/ingredients/components/ingredient-form/IngredientForm.vue.d.ts +2 -2
  72. package/dist/views/ingredients/composables/use-ingredient-select-dialog.d.ts +16 -0
  73. package/dist/views/ingredients/composables/use-ingredient-table.d.ts +1 -1
  74. package/dist/views/receive-request/components/netsuite/NetSuiteProps.d.ts +2 -0
  75. package/dist/views/receive-request/components/transfer-details/TransferDetails.vue.d.ts +1387 -0
  76. package/dist/views/receive-request/components/transfer-details/TransferDetailsProps.d.ts +5 -1
  77. package/dist/views/receive-request/components/transfer-dialog/TransferDialogProps.d.ts +3 -0
  78. package/dist/views/receive-request/components/transfer-form/TransferFormProps.d.ts +1 -2
  79. package/dist/views/receive-request/components/transfer-form/components/ForecastStock.vue.d.ts +48 -2
  80. package/dist/views/receive-request/components/transfer-form/components/TransferItemTable.vue.d.ts +490 -2
  81. package/dist/views/receive-request/components/transfer-form/components/TransferSubItemTable.vue.d.ts +72 -0
  82. package/dist/views/receive-request/components/transfer-form/composables/use-transfer-items.d.ts +25 -2
  83. package/dist/views/receive-request/components/transfer-form/helpers/calculate-sub-item-total.helper.d.ts +4 -0
  84. package/dist/views/receive-request/composables/use-receive-request-form.d.ts +693 -35
  85. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +684 -35
  86. package/dist/views/receive-request/helper/po-to-po-template.util.d.ts +1 -0
  87. package/dist/views/receive-request/helper/print-po.d.ts +9 -2
  88. package/dist/views/stock/components/dialog/AdjustedItemForm.vue.d.ts +2 -2
  89. package/dist/views/transfer-template/components/transfer-template-form/components/TransferTemplateItem.vue.d.ts +270 -2
  90. package/dist/views/transfer-template/components/transfer-template-form/components/TransferTemplateItemTable.vue.d.ts +286 -0
  91. package/dist/views/transfer-template/components/transfer-template-form/components/TransferTemplateSubItem.vue.d.ts +74 -0
  92. package/dist/views/transfer-template/components/transfer-template-form/components/TransferTemplateSubItemTable.vue.d.ts +92 -0
  93. package/dist/views/transfer-template/components/transfer-template-form/composables/use-template-enabled-locations-2.d.ts +8 -0
  94. package/dist/views/transfer-template/components/transfer-template-form/composables/use-template-enabled-locations.d.ts +1 -0
  95. package/dist/views/transfer-template/components/transfer-template-form/composables/use-transfer-template-items.d.ts +36 -2
  96. package/dist/views/transfer-template/composables/use-transfer-template-actions.d.ts +456 -12
  97. package/dist/views/transfer-template/composables/use-transfer-template-table.d.ts +456 -12
  98. package/dist/views/transfer-template/helpers/location-to-po-supplier.util.d.ts +75 -0
  99. package/dist/views/warehouse/components/WarehouseForm.vue.d.ts +2 -0
  100. package/dist/{vue-i18n-BcYt8MNZ.js → vue-i18n-CCd5_SRR.js} +212 -212
  101. package/package.json +3 -3
  102. package/dist/App-oKNdl2la.js +0 -276
  103. package/dist/ApprovalView-hDGkcBDy.js +0 -138
  104. package/dist/ClosingDraftView-CEeeL7W4.js +0 -1225
  105. package/dist/ClosingTemplateView-CkS9e0MV.js +0 -1819
  106. package/dist/FmCustomAttribute.vue_vue_type_script_setup_true_lang-CIBSvY0s.js +0 -142
  107. package/dist/FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-Dg_7ELeT.js +0 -286
  108. package/dist/PublishView-ByXdmuJL.js +0 -192
  109. package/dist/ReceiveRequestView-CApg7LGM.js +0 -1876
  110. package/dist/StockView-D6o_oUlz.js +0 -1817
  111. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-D2skLe2M.js +0 -1327
  112. package/dist/TransferTemplateView-DVesObTd.js +0 -1284
  113. package/dist/components/FmCustomAttribute2.vue.d.ts +0 -18
  114. package/dist/index-P5iEcRw3.js +0 -29202
  115. package/dist/views/receive-request/components/transfer-form/TransferForm.vue.d.ts +0 -2628
@@ -0,0 +1,1003 @@
1
+ var fe = Object.defineProperty;
2
+ var pe = (S, u, v) => u in S ? fe(S, u, { enumerable: !0, configurable: !0, writable: !0, value: v }) : S[u] = v;
3
+ var ct = (S, u, v) => pe(S, typeof u != "symbol" ? u + "" : u, v);
4
+ import { useCoreStore as ht } from "@feedmepos/mf-common";
5
+ import { a4 as vt, u as Dt, ax as ae, a as ye } from "./app-oV9ISfFL.js";
6
+ import { ref as gt, readonly as Kt } from "vue";
7
+ var Gt = { exports: {} };
8
+ (function(S, u) {
9
+ (function(v, d) {
10
+ d(u);
11
+ })(vt, function(v) {
12
+ var d = { getItemSync: function(a) {
13
+ try {
14
+ return localStorage.getItem(a) || null;
15
+ } catch {
16
+ return null;
17
+ }
18
+ }, getItem: function(a, e) {
19
+ var t = this;
20
+ return new Promise(function(i, n) {
21
+ try {
22
+ var r = t.getItemSync(a);
23
+ e == null || e(null, r), i(r);
24
+ } catch (s) {
25
+ e && e(s, null), n(s);
26
+ }
27
+ });
28
+ }, setItem: function(a, e, t) {
29
+ return new Promise(function(i, n) {
30
+ try {
31
+ localStorage.setItem(a, e), t && t(null, e), i(e);
32
+ } catch (r) {
33
+ t && t(r, null), n(r);
34
+ }
35
+ });
36
+ } }, o = function() {
37
+ return o = Object.assign || function(a) {
38
+ for (var e, t = 1, i = arguments.length; t < i; t++) for (var n in e = arguments[t]) Object.prototype.hasOwnProperty.call(e, n) && (a[n] = e[n]);
39
+ return a;
40
+ }, o.apply(this, arguments);
41
+ };
42
+ function E(a, e, t, i) {
43
+ return new (t || (t = Promise))(function(n, r) {
44
+ function s(f) {
45
+ try {
46
+ h(i.next(f));
47
+ } catch (l) {
48
+ r(l);
49
+ }
50
+ }
51
+ function c(f) {
52
+ try {
53
+ h(i.throw(f));
54
+ } catch (l) {
55
+ r(l);
56
+ }
57
+ }
58
+ function h(f) {
59
+ var l;
60
+ f.done ? n(f.value) : (l = f.value, l instanceof t ? l : new t(function(y) {
61
+ y(l);
62
+ })).then(s, c);
63
+ }
64
+ h((i = i.apply(a, [])).next());
65
+ });
66
+ }
67
+ function M(a, e) {
68
+ var t, i, n, r, s = { label: 0, sent: function() {
69
+ if (1 & n[0]) throw n[1];
70
+ return n[1];
71
+ }, trys: [], ops: [] };
72
+ return r = { next: c(0), throw: c(1), return: c(2) }, typeof Symbol == "function" && (r[Symbol.iterator] = function() {
73
+ return this;
74
+ }), r;
75
+ function c(h) {
76
+ return function(f) {
77
+ return function(l) {
78
+ if (t) throw new TypeError("Generator is already executing.");
79
+ for (; s; ) try {
80
+ if (t = 1, i && (n = 2 & l[0] ? i.return : l[0] ? i.throw || ((n = i.return) && n.call(i), 0) : i.next) && !(n = n.call(i, l[1])).done) return n;
81
+ switch (i = 0, n && (l = [2 & l[0], n.value]), l[0]) {
82
+ case 0:
83
+ case 1:
84
+ n = l;
85
+ break;
86
+ case 4:
87
+ return s.label++, { value: l[1], done: !1 };
88
+ case 5:
89
+ s.label++, i = l[1], l = [0];
90
+ continue;
91
+ case 7:
92
+ l = s.ops.pop(), s.trys.pop();
93
+ continue;
94
+ default:
95
+ if (n = s.trys, !((n = n.length > 0 && n[n.length - 1]) || l[0] !== 6 && l[0] !== 2)) {
96
+ s = 0;
97
+ continue;
98
+ }
99
+ if (l[0] === 3 && (!n || l[1] > n[0] && l[1] < n[3])) {
100
+ s.label = l[1];
101
+ break;
102
+ }
103
+ if (l[0] === 6 && s.label < n[1]) {
104
+ s.label = n[1], n = l;
105
+ break;
106
+ }
107
+ if (n && s.label < n[2]) {
108
+ s.label = n[2], s.ops.push(l);
109
+ break;
110
+ }
111
+ n[2] && s.ops.pop(), s.trys.pop();
112
+ continue;
113
+ }
114
+ l = e.call(a, s);
115
+ } catch (y) {
116
+ l = [6, y], i = 0;
117
+ } finally {
118
+ t = n = 0;
119
+ }
120
+ if (5 & l[0]) throw l[1];
121
+ return { value: l[0] ? l[1] : void 0, done: !0 };
122
+ }([h, f]);
123
+ };
124
+ }
125
+ }
126
+ function T(a, e, t) {
127
+ for (var i, n = 0, r = e.length; n < r; n++) !i && n in e || (i || (i = Array.prototype.slice.call(e, 0, n)), i[n] = e[n]);
128
+ return a.concat(i || Array.prototype.slice.call(e));
129
+ }
130
+ var X = function a(e, t) {
131
+ if (e === t) return !0;
132
+ if (e && t && typeof e == "object" && typeof t == "object") {
133
+ if (e.constructor !== t.constructor) return !1;
134
+ var i, n, r;
135
+ if (Array.isArray(e)) {
136
+ if ((i = e.length) != t.length) return !1;
137
+ for (n = i; n-- != 0; ) if (!a(e[n], t[n])) return !1;
138
+ return !0;
139
+ }
140
+ if (e.constructor === RegExp) return e.source === t.source && e.flags === t.flags;
141
+ if (e.valueOf !== Object.prototype.valueOf) return e.valueOf() === t.valueOf();
142
+ if (e.toString !== Object.prototype.toString) return e.toString() === t.toString();
143
+ if ((i = (r = Object.keys(e)).length) !== Object.keys(t).length) return !1;
144
+ for (n = i; n-- != 0; ) if (!Object.prototype.hasOwnProperty.call(t, r[n])) return !1;
145
+ for (n = i; n-- != 0; ) {
146
+ var s = r[n];
147
+ if (!a(e[s], t[s])) return !1;
148
+ }
149
+ return !0;
150
+ }
151
+ return e != e && t != t;
152
+ };
153
+ function _(a, e) {
154
+ var t = Object.keys(e || {}).filter(function(i) {
155
+ var n = a == null ? void 0 : a[i], r = e == null ? void 0 : e[i];
156
+ return !X(n, r);
157
+ });
158
+ return Object.keys(a || {}).filter(function(i) {
159
+ Object.keys(e || {}).includes(i) || t.push(i);
160
+ }), Object.keys(t).length ? t : null;
161
+ }
162
+ var F, g;
163
+ function p(a, e, t) {
164
+ var i = "shortString", n = !0;
165
+ typeof t == "number" && (i = "javaDouble", n = !1), a[i] = a[i] || {}, a[i][e] = n ? t + "" : t;
166
+ }
167
+ function C(a) {
168
+ return !!a && typeof a == "object" && a.value !== void 0;
169
+ }
170
+ function k(a) {
171
+ return Object.fromEntries(Object.entries(a).map(function(e) {
172
+ var t = e[0], i = e[1];
173
+ return [t, C(i) ? i : { value: i }];
174
+ }));
175
+ }
176
+ function z(a) {
177
+ return o(o({}, a), { identity: a.identity ? o(o({}, a.identity), { traits: k(a.identity.traits || {}) }) : void 0 });
178
+ }
179
+ (function(a) {
180
+ a.NONE = "NONE", a.DEFAULT_FLAGS = "DEFAULT_FLAGS", a.CACHE = "CACHE", a.SERVER = "SERVER";
181
+ })(F || (F = {}));
182
+ var Y, L = null, ce = "FLAGSMITH_EVENT", lt = ce, Jt = "https://edge.api.flagsmith.com/api/v1/", Vt = "flagsmith_value_", Mt = "flagsmith_enabled_", Bt = "flagsmith_trait_", he = function() {
183
+ function a(e) {
184
+ var t = this;
185
+ this._trigger = null, this._triggerLoadingState = null, this.timestamp = null, this.isLoading = !1, this.eventSource = null, this.getFlags = function() {
186
+ var i = t, n = i.api, r = i.evaluationContext;
187
+ t.log("Get Flags"), t.isLoading = !0, t.loadingState.isFetching || t.setLoadingState(o(o({}, t.loadingState), { isFetching: !0 }));
188
+ var s = "".concat(t.getContext().identity), c = function(h) {
189
+ var f, l, y, x;
190
+ if (h && s === "".concat(t.getContext().identity)) {
191
+ var D = h.flags, A = h.traits, R = h.identifier;
192
+ t.isLoading = !1;
193
+ var j = {}, P = {};
194
+ A = A || [], (D = D || []).forEach(function(m) {
195
+ j[m.feature.name.toLowerCase().replace(/ /g, "_")] = { id: m.feature.id, enabled: m.enabled, value: m.feature_state_value };
196
+ }), A.forEach(function(m) {
197
+ P[m.trait_key.toLowerCase().replace(/ /g, "_")] = { transient: m.transient, value: m.trait_value };
198
+ }), t.oldFlags = o({}, t.flags);
199
+ var K = _(t.oldFlags, j), nt = _((f = t.evaluationContext.identity) === null || f === void 0 ? void 0 : f.traits, P);
200
+ if ((R || Object.keys(P).length) && (t.evaluationContext.identity = o(o({}, t.evaluationContext.identity), { traits: P }), R && (t.evaluationContext.identity.identifier = R)), t.flags = j, t.updateStorage(), t._onChange(t.oldFlags, { isFromServer: !0, flagsChanged: K, traitsChanged: nt }, t._loadedState(null, F.SERVER)), t.datadogRum) try {
201
+ if (t.datadogRum.trackTraits) {
202
+ var it = {};
203
+ Object.keys(((l = t.evaluationContext.identity) === null || l === void 0 ? void 0 : l.traits) || {}).map(function(m) {
204
+ it[Bt + m] = t.getTrait(m);
205
+ });
206
+ var Z = o(o(o({}, t.datadogRum.client.getUser()), { id: t.datadogRum.client.getUser().id || ((y = t.evaluationContext.identity) === null || y === void 0 ? void 0 : y.identifier) }), it);
207
+ t.log("Setting Datadog user", Z), t.datadogRum.client.setUser(Z);
208
+ }
209
+ } catch (m) {
210
+ console.error(m);
211
+ }
212
+ if (t.dtrum) try {
213
+ var w = { javaDouble: {}, date: {}, shortString: {}, javaLongOrObject: {} };
214
+ Object.keys(t.flags).map(function(m) {
215
+ p(w, Vt + m, t.getValue(m, { skipAnalytics: !0 })), p(w, Mt + m, t.hasFeature(m, { skipAnalytics: !0 }));
216
+ }), Object.keys(((x = t.evaluationContext.identity) === null || x === void 0 ? void 0 : x.traits) || {}).map(function(m) {
217
+ p(w, Bt + m, t.getTrait(m));
218
+ }), 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);
219
+ } catch (m) {
220
+ console.error(m);
221
+ }
222
+ }
223
+ };
224
+ return r.identity ? Promise.all([r.identity.traits && Object.keys(r.identity.traits).length || !r.identity.identifier ? t.getJSON(n + "identities/", "POST", JSON.stringify({ identifier: r.identity.identifier, transient: r.identity.transient, traits: Object.entries(r.identity.traits).map(function(h) {
225
+ var f = h[0], l = h[1];
226
+ return { trait_key: f, trait_value: l == null ? void 0 : l.value, transient: l == null ? void 0 : l.transient };
227
+ }).filter(function(h) {
228
+ return h.trait_value !== void 0 || (t.log("Warning - attempted to set an undefined trait value for key", h.trait_key), !1);
229
+ }) })) : t.getJSON(n + "identities/?identifier=" + encodeURIComponent(r.identity.identifier) + (r.identity.transient ? "&transient=true" : ""))]).then(function(h) {
230
+ return t.evaluationContext.identity = o(o({}, t.evaluationContext.identity), { traits: {} }), c(h == null ? void 0 : h[0]);
231
+ }).catch(function(h) {
232
+ var f = h.message, l = new Error(f);
233
+ return Promise.reject(l);
234
+ }) : t.getJSON(n + "flags/").then(function(h) {
235
+ return c({ flags: h, traits: void 0 });
236
+ });
237
+ }, this.analyticsFlags = function() {
238
+ var i = t.api;
239
+ if (t.evaluationEvent && t.evaluationContext.environment && t.evaluationEvent[t.evaluationContext.environment.apiKey]) return t.evaluationEvent && Object.getOwnPropertyNames(t.evaluationEvent).length !== 0 && Object.getOwnPropertyNames(t.evaluationEvent[t.evaluationContext.environment.apiKey]).length !== 0 ? t.getJSON(i + "analytics/flags/", "POST", JSON.stringify(t.evaluationEvent[t.evaluationContext.environment.apiKey])).then(function(n) {
240
+ if (t.evaluationContext.environment) {
241
+ var r = t.getState();
242
+ t.evaluationEvent || (t.evaluationEvent = {}), t.evaluationEvent[t.evaluationContext.environment.apiKey] = {}, t.setState(o(o({}, r), { evaluationEvent: t.evaluationEvent })), t.updateEventStorage();
243
+ }
244
+ }).catch(function(n) {
245
+ t.log("Exception fetching evaluationEvent", n);
246
+ }) : void 0;
247
+ }, this.datadogRum = null, this.loadingState = { isLoading: !0, isFetching: !0, error: null, source: F.NONE }, this.canUseStorage = !1, this.analyticsInterval = null, this.api = null, this.cacheFlags = !1, this.ts = null, this.enableAnalytics = !1, this.enableLogs = !1, this.evaluationContext = {}, this.evaluationEvent = null, this.flags = null, this.getFlagInterval = null, this.headers = null, this.initialised = !1, this.oldFlags = null, this.onChange = null, this.onError = null, this.ticks = null, this.timer = null, this.dtrum = null, this.withTraits = null, this.cacheOptions = { ttl: 0, skipAPI: !1, loadStale: !1, storageKey: void 0 }, this.getValue = function(i, n, r) {
248
+ var s = t.flags && t.flags[i.toLowerCase().replace(/ /g, "_")], c = null;
249
+ if (s && (c = s.value), n != null && n.skipAnalytics || r || t.evaluateFlag(i, "VALUE"), c === null && (n == null ? void 0 : n.fallback) !== void 0) return n.fallback;
250
+ if (n != null && n.json) try {
251
+ return c === null ? (t.log("Tried to parse null flag as JSON: " + i), null) : JSON.parse(c);
252
+ } catch {
253
+ return n.fallback;
254
+ }
255
+ return c;
256
+ }, this.getTrait = function(i) {
257
+ var n, r;
258
+ return ((n = t.evaluationContext.identity) === null || n === void 0 ? void 0 : n.traits) && ((r = t.evaluationContext.identity.traits[i.toLowerCase().replace(/ /g, "_")]) === null || r === void 0 ? void 0 : r.value);
259
+ }, this.getAllTraits = function() {
260
+ var i;
261
+ return Object.fromEntries(Object.entries(((i = t.evaluationContext.identity) === null || i === void 0 ? void 0 : i.traits) || {}).map(function(n) {
262
+ var r = n[0], s = n[1];
263
+ return [r, s == null ? void 0 : s.value];
264
+ }));
265
+ }, this.setContext = function(i) {
266
+ var n = z(i);
267
+ return t.evaluationContext = o(o({}, n), { environment: n.environment || t.evaluationContext.environment }), t.initialised ? t.getFlags() : Promise.resolve();
268
+ }, this.getContext = function() {
269
+ return t.evaluationContext;
270
+ }, this.updateContext = function(i) {
271
+ return t.setContext(o(o({}, t.getContext()), i));
272
+ }, this.setTrait = function(i, n) {
273
+ var r;
274
+ if (t.api) return t.setContext(o(o({}, t.evaluationContext), { identity: o(o({}, t.evaluationContext.identity), { traits: o(o({}, (r = t.evaluationContext.identity) === null || r === void 0 ? void 0 : r.traits), k(Object.fromEntries([[i, n]]))) }) }));
275
+ }, this.setTraits = function(i) {
276
+ var n;
277
+ if (t.api) return t.setContext(o(o({}, t.evaluationContext), { identity: o(o({}, t.evaluationContext.identity), { traits: o(o({}, (n = t.evaluationContext.identity) === null || n === void 0 ? void 0 : n.traits), Object.fromEntries(Object.entries(i).map(function(r) {
278
+ var s = r[0], c = r[1];
279
+ return [s, C(c) ? c : { value: c }];
280
+ }))) }) }));
281
+ console.error("Attempted to setTraits a user before calling flagsmith.init. Call flagsmith.init first, if you wish to prevent it sending a request for flags, call init with preventFetch:true.");
282
+ }, this.hasFeature = function(i, n) {
283
+ var r = typeof n == "object", s = t.flags && t.flags[i.toLowerCase().replace(/ /g, "_")], c = !1;
284
+ return !s && r && n.fallback !== void 0 ? c = n == null ? void 0 : n.fallback : s && s.enabled && (c = !0), (r && !n.skipAnalytics || !n) && t.evaluateFlag(i, "ENABLED"), c;
285
+ }, this.getStorageKey = function() {
286
+ var i, n;
287
+ return ((i = t.cacheOptions) === null || i === void 0 ? void 0 : i.storageKey) || "FLAGSMITH_DB_" + ((n = t.evaluationContext.environment) === null || n === void 0 ? void 0 : n.apiKey);
288
+ }, this.getJSON = function(i, n, r) {
289
+ var s, c = t;
290
+ c.evaluationContext;
291
+ var h = c.headers, f = { method: n || "GET", body: r, cache: "no-cache", headers: {} };
292
+ 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), g || console.error("Flagsmith: fetch is undefined, please specify a fetch implementation into flagsmith.init to support SSR.");
293
+ var l = "".concat((s = t.evaluationContext.identity) === null || s === void 0 ? void 0 : s.identifier);
294
+ return g(i, f).then(function(y) {
295
+ var x, D, A = "".concat((x = t.evaluationContext.identity) === null || x === void 0 ? void 0 : x.identifier);
296
+ if (l === A) {
297
+ var R = (D = y.headers) === null || D === void 0 ? void 0 : D.get("x-flagsmith-document-updated-at");
298
+ if (R) try {
299
+ var j = parseFloat(R);
300
+ if (isNaN(j)) return Promise.reject("Failed to parse x-flagsmith-document-updated-at");
301
+ t.timestamp = j;
302
+ } catch (P) {
303
+ t.log(P, "Failed to parse x-flagsmith-document-updated-at", R);
304
+ }
305
+ return t.log("Fetch response: " + y.status + " " + (n || "GET") + 0 + i), y.text().then(function(P) {
306
+ var K = P;
307
+ try {
308
+ K = JSON.parse(P);
309
+ } catch {
310
+ }
311
+ return !K && y.status && (K = "API Response: ".concat(y.status)), y.status && y.status >= 200 && y.status < 300 ? K : Promise.reject(new Error(K));
312
+ });
313
+ }
314
+ t.log("Received response with identity mismatch, ignoring response. Requested: ".concat(l, ", Current: ").concat(A));
315
+ });
316
+ }, this.evaluateFlag = function(i, n) {
317
+ if (t.datadogRum && (t.datadogRum.client.addFeatureFlagEvaluation ? n === "VALUE" ? t.datadogRum.client.addFeatureFlagEvaluation(Vt + 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) {
318
+ if (!t.evaluationEvent || !t.evaluationContext.environment) return;
319
+ t.evaluationEvent[t.evaluationContext.environment.apiKey] || (t.evaluationEvent[t.evaluationContext.environment.apiKey] = {}), t.evaluationEvent[t.evaluationContext.environment.apiKey][i] === void 0 && (t.evaluationEvent[t.evaluationContext.environment.apiKey][i] = 0), t.evaluationEvent[t.evaluationContext.environment.apiKey][i] += 1;
320
+ }
321
+ t.updateEventStorage();
322
+ }, this._onChange = function(i, n, r) {
323
+ var s, c;
324
+ t.setLoadingState(r), (s = t.onChange) === null || s === void 0 || s.call(t, i, n, t.loadingState), (c = t._trigger) === null || c === void 0 || c.call(t);
325
+ }, g = e.fetch ? e.fetch : typeof fetch < "u" ? fetch : vt === null || vt === void 0 ? void 0 : vt.fetch, this.canUseStorage = typeof window < "u" || !!e.browserlessStorage, this.log("Constructing flagsmith instance " + e), e.eventSource && (Y = e.eventSource), e.AsyncStorage && (L = e.AsyncStorage);
326
+ }
327
+ return a.prototype.init = function(e) {
328
+ var t, i, n;
329
+ return E(this, void 0, void 0, function() {
330
+ var r, s, c, h, f, l, y, x, D, A, R, j, P, K, nt, it, Z, w, m, pt, at, Yt, Q, yt, Zt, Qt, mt, te, St, rt, tt, ee, O = this;
331
+ return M(this, function(U) {
332
+ switch (U.label) {
333
+ case 0:
334
+ r = z(e.evaluationContext || this.evaluationContext), U.label = 1;
335
+ case 1:
336
+ if (U.trys.push([1, 13, , 14]), s = e.environmentID, c = e.api, h = c === void 0 ? Jt : c, f = e.headers, l = e.onChange, y = e.cacheFlags, x = e.datadogRum, D = e.onError, A = e.defaultFlags, R = e.fetch, j = e.preventFetch, P = e.enableLogs, K = e.enableDynatrace, nt = e.enableAnalytics, it = e.realtime, Z = e.eventSourceUrl, w = Z === void 0 ? "https://realtime.flagsmith.com/" : Z, m = e.AsyncStorage, pt = e.identity, at = e.traits, Yt = e.state, Q = e.cacheOptions, yt = 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`");
337
+ if (r.identity = pt || at ? { identifier: pt, traits: at ? Object.fromEntries(Object.entries(at).map(function(N) {
338
+ return [N[0], { value: N[1] }];
339
+ })) : {} } : r.identity, this.evaluationContext = r, this.api = h, this.headers = f, this.getFlagInterval = null, this.analyticsInterval = null, this.onChange = l, mt = "Wrong Flagsmith Configuration: preventFetch is true and no defaulFlags provided", this._trigger = Zt || this._trigger, this._triggerLoadingState = Qt || this._triggerLoadingState, this.onError = function(N) {
340
+ O.setLoadingState(o(o({}, O.loadingState), { isFetching: !1, isLoading: !1, error: N })), D == null || D(N);
341
+ }, this.enableLogs = P || !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."), R && (g = R), this.enableAnalytics = nt || !1, this.flags = Object.assign({}, A) || {}, this.datadogRum = x || null, this.initialised = !0, this.ticks = 1e4, this.timer = this.enableLogs ? (/* @__PURE__ */ new Date()).valueOf() : null, this.cacheFlags = L !== void 0 && !!y, lt = "FLAGSMITH_EVENT_" + r.environment.apiKey, m && (L = m), it && typeof window < "u" && this.setupRealtime(w, r.environment.apiKey), Object.keys(this.flags).length && (this.loadingState = o(o({}, this.loadingState), { isLoading: !1, source: F.DEFAULT_FLAGS })), this.setState(Yt), this.log("Initialising with properties", e, this), K && (typeof dtrum > "u" ? console.error("You have attempted to enable dynatrace but dtrum is undefined, please check you have the Dynatrace RUM JavaScript API installed.") : this.dtrum = dtrum), yt && (g = /* @__PURE__ */ function(N) {
342
+ return function(G, J) {
343
+ var H = J.headers, b = J.method, et = J.body;
344
+ return new Promise(function(W) {
345
+ switch (b) {
346
+ case "GET":
347
+ return N.get(G, { headers: H }).subscribe(function(B) {
348
+ W({ ok: !0, text: function() {
349
+ return Promise.resolve(B);
350
+ } });
351
+ });
352
+ case "POST":
353
+ case "PUT":
354
+ return N.post(G, et, { headers: H }).subscribe(function(B) {
355
+ W({ ok: !0, text: function() {
356
+ return Promise.resolve(B);
357
+ } });
358
+ });
359
+ }
360
+ });
361
+ };
362
+ }(yt)), L && this.canUseStorage && L.getItem(lt).then(function(N) {
363
+ try {
364
+ O.evaluationEvent = JSON.parse(N) || {};
365
+ } catch {
366
+ O.evaluationEvent = {};
367
+ }
368
+ O.analyticsInterval = setInterval(O.analyticsFlags, O.ticks);
369
+ }), this.enableAnalytics && (this.analyticsInterval && clearInterval(this.analyticsInterval), L && this.canUseStorage && L.getItem(lt, function(N, G) {
370
+ if (G && O.evaluationContext.environment) {
371
+ var J = JSON.parse(G);
372
+ if (J[O.evaluationContext.environment.apiKey]) {
373
+ var H = O.getState();
374
+ O.log("Retrieved events from cache", G), O.setState(o(o({}, H), { evaluationEvent: J[O.evaluationContext.environment.apiKey] }));
375
+ }
376
+ }
377
+ })), !y) return [3, 9];
378
+ if (!L || !this.canUseStorage) return [3, 8];
379
+ te = function(N, G) {
380
+ return E(O, void 0, void 0, function() {
381
+ var J, H, b, et, W, B, bt, ne, Ct, _t, Et, Ft, xt, wt, Ot, It, Lt, Tt, At, jt, Pt, Nt, kt, Rt, ie = this;
382
+ return M(this, function($) {
383
+ switch ($.label) {
384
+ case 0:
385
+ if (!G) return [3, 7];
386
+ J = null, H = null, $.label = 1;
387
+ case 1:
388
+ return $.trys.push([1, 5, , 6]), b = JSON.parse(G), et = !1, W = !1, b && b.api === this.api && ((_t = (Ct = b.evaluationContext) === null || Ct === void 0 ? void 0 : Ct.environment) === null || _t === void 0 ? void 0 : _t.apiKey) === ((Et = this.evaluationContext.environment) === null || Et === void 0 ? void 0 : Et.apiKey) && (B = !0, this.evaluationContext.identity && ((xt = (Ft = b.evaluationContext) === null || Ft === void 0 ? void 0 : Ft.identity) === null || xt === void 0 ? void 0 : xt.identifier) !== this.evaluationContext.identity.identifier && (this.log("Ignoring cache, identity has changed from " + ((Ot = (wt = b.evaluationContext) === null || wt === void 0 ? void 0 : wt.identity) === null || Ot === void 0 ? void 0 : Ot.identifier) + " to " + this.evaluationContext.identity.identifier), B = !1), this.cacheOptions.ttl && (!b.ts || (/* @__PURE__ */ new Date()).valueOf() - b.ts > this.cacheOptions.ttl) && (b.ts && !this.cacheOptions.loadStale ? (this.log("Ignoring cache, timestamp is too old ts:" + b.ts + " ttl: " + this.cacheOptions.ttl + " time elapsed since cache: " + ((/* @__PURE__ */ new Date()).valueOf() - b.ts) + "ms"), B = !1) : b.ts && this.cacheOptions.loadStale && (this.log("Loading stale cache, timestamp ts:" + b.ts + " ttl: " + this.cacheOptions.ttl + " time elapsed since cache: " + ((/* @__PURE__ */ new Date()).valueOf() - b.ts) + "ms"), W = !0, B = !0)), B && (et = !0, H = _((It = this.evaluationContext.identity) === null || It === void 0 ? void 0 : It.traits, (Tt = (Lt = b.evaluationContext) === null || Lt === void 0 ? void 0 : Lt.identity) === null || Tt === void 0 ? void 0 : Tt.traits), J = _(this.flags, b.flags), this.setState(o(o({}, b), { evaluationContext: z(o(o({}, b.evaluationContext), { identity: !((At = b.evaluationContext) === null || At === void 0) && At.identity ? o(o({}, (jt = b.evaluationContext) === null || jt === void 0 ? void 0 : jt.identity), { traits: o(o({}, ((Nt = (Pt = b.evaluationContext) === null || Pt === void 0 ? void 0 : Pt.identity) === null || Nt === void 0 ? void 0 : Nt.traits) || {}), at || {}) }) : void 0 })) })), this.log("Retrieved flags from cache", b))), et ? (bt = !j && (!this.cacheOptions.skipAPI || W), this._onChange(null, { isFromServer: !1, flagsChanged: J, traitsChanged: H }, this._loadedState(null, F.CACHE, bt)), this.oldFlags = this.flags, this.cacheOptions.skipAPI && et && !W && this.log("Skipping API, using cache"), bt && this.getFlags().catch(function(ge) {
389
+ var Ut;
390
+ (Ut = ie.onError) === null || Ut === void 0 || Ut.call(ie, ge);
391
+ }), [3, 4]) : [3, 2];
392
+ case 2:
393
+ return j ? [3, 4] : [4, this.getFlags()];
394
+ case 3:
395
+ $.sent(), $.label = 4;
396
+ case 4:
397
+ return [3, 6];
398
+ case 5:
399
+ return ne = $.sent(), this.log("Exception fetching cached logs", ne), [3, 6];
400
+ case 6:
401
+ return [3, 10];
402
+ case 7:
403
+ return j ? [3, 9] : [4, this.getFlags()];
404
+ case 8:
405
+ return $.sent(), [3, 10];
406
+ case 9:
407
+ if (A) this._onChange(null, { isFromServer: !1, flagsChanged: _({}, this.flags), traitsChanged: _({}, (kt = this.evaluationContext.identity) === null || kt === void 0 ? void 0 : kt.traits) }, this._loadedState(null, F.DEFAULT_FLAGS));
408
+ else {
409
+ if (!this.flags) throw new Error(mt);
410
+ this._onChange(null, { isFromServer: !1, flagsChanged: _({}, this.flags), traitsChanged: _({}, (Rt = this.evaluationContext.identity) === null || Rt === void 0 ? void 0 : Rt.traits) }, this._loadedState(null, F.DEFAULT_FLAGS));
411
+ }
412
+ $.label = 10;
413
+ case 10:
414
+ return [2];
415
+ }
416
+ });
417
+ });
418
+ }, U.label = 2;
419
+ case 2:
420
+ return U.trys.push([2, 7, , 8]), L.getItemSync ? (St = L.getItemSync(this.getStorageKey()), [3, 5]) : [3, 3];
421
+ case 3:
422
+ return [4, L.getItem(this.getStorageKey())];
423
+ case 4:
424
+ St = U.sent(), U.label = 5;
425
+ case 5:
426
+ return [4, te(null, St)];
427
+ case 6:
428
+ case 7:
429
+ return U.sent(), [3, 8];
430
+ case 8:
431
+ return [3, 12];
432
+ case 9:
433
+ return j ? [3, 11] : [4, this.getFlags()];
434
+ case 10:
435
+ return U.sent(), [3, 12];
436
+ case 11:
437
+ if (A) this._onChange(null, { isFromServer: !1, flagsChanged: _({}, A), traitsChanged: _({}, (t = r.identity) === null || t === void 0 ? void 0 : t.traits) }, this._loadedState(null, F.DEFAULT_FLAGS));
438
+ else if (this.flags && (rt = null, Object.keys(this.flags).length === 0 && (rt = mt), this._onChange(null, { isFromServer: !1, flagsChanged: _({}, this.flags), traitsChanged: _({}, (i = r.identity) === null || i === void 0 ? void 0 : i.traits) }, this._loadedState(rt, F.DEFAULT_FLAGS)), rt)) throw new Error(rt);
439
+ U.label = 12;
440
+ case 12:
441
+ return [3, 14];
442
+ case 13:
443
+ throw tt = U.sent(), this.log("Error during initialisation ", tt), ee = tt instanceof Error ? tt : new Error("".concat(tt)), (n = this.onError) === null || n === void 0 || n.call(this, ee), tt;
444
+ case 14:
445
+ return [2];
446
+ }
447
+ });
448
+ });
449
+ }, a.prototype.getAllFlags = function() {
450
+ return this.flags;
451
+ }, a.prototype.identify = function(e, t, i) {
452
+ return this.evaluationContext.identity = { identifier: e, transient: i, traits: this.evaluationContext.identity && this.evaluationContext.identity.identifier == e ? this.evaluationContext.identity.traits : {} }, this.evaluationContext.identity.identifier = e, this.log("Identify: " + this.evaluationContext.identity.identifier), t && (this.evaluationContext.identity.traits = Object.fromEntries(Object.entries(t).map(function(n) {
453
+ var r = n[0], s = n[1];
454
+ return [r, C(s) ? s : { value: s }];
455
+ }))), this.initialised ? this.getFlags() : Promise.resolve();
456
+ }, a.prototype.getState = function() {
457
+ return { api: this.api, flags: this.flags, ts: this.ts, evaluationContext: this.evaluationContext, evaluationEvent: this.evaluationEvent };
458
+ }, a.prototype.setState = function(e) {
459
+ e && (this.initialised = !0, this.api = e.api || this.api || Jt, this.flags = e.flags || this.flags, this.evaluationContext = e.evaluationContext || this.evaluationContext, this.evaluationEvent = e.evaluationEvent || this.evaluationEvent, this.log("setState called", this));
460
+ }, a.prototype.logout = function() {
461
+ return this.evaluationContext.identity = null, this.initialised ? this.getFlags() : Promise.resolve();
462
+ }, a.prototype.startListening = function(e) {
463
+ e === void 0 && (e = 1e3), this.getFlagInterval && clearInterval(this.getFlagInterval), this.getFlagInterval = setInterval(this.getFlags, e);
464
+ }, a.prototype.stopListening = function() {
465
+ this.getFlagInterval && (clearInterval(this.getFlagInterval), this.getFlagInterval = null);
466
+ }, a.prototype._loadedState = function(e, t, i) {
467
+ return e === void 0 && (e = null), i === void 0 && (i = !1), { error: e, isFetching: i, isLoading: !1, source: t };
468
+ }, a.prototype.log = function() {
469
+ for (var e = [], t = 0; t < arguments.length; t++) e[t] = arguments[t];
470
+ this.enableLogs && console.log.apply(this, T(["FLAGSMITH:", (/* @__PURE__ */ new Date()).valueOf() - (this.timer || 0), "ms"], e));
471
+ }, a.prototype.updateStorage = function() {
472
+ if (this.cacheFlags) {
473
+ this.ts = (/* @__PURE__ */ new Date()).valueOf();
474
+ var e = JSON.stringify(this.getState());
475
+ this.log("Setting storage", e), L.setItem(this.getStorageKey(), e);
476
+ }
477
+ }, a.prototype.updateEventStorage = function() {
478
+ if (this.enableAnalytics) {
479
+ var e = JSON.stringify(this.getState().evaluationEvent);
480
+ L.setItem(lt, e).catch(function(t) {
481
+ return console.error("Flagsmith: Error setting item in async storage", t);
482
+ });
483
+ }
484
+ }, a.prototype.setLoadingState = function(e) {
485
+ var t;
486
+ X(e, this.loadingState) || (this.loadingState = o({}, e), this.log("Loading state changed", e), (t = this._triggerLoadingState) === null || t === void 0 || t.call(this));
487
+ }, a.prototype.setupRealtime = function(e, t) {
488
+ var i = this, n = e + "sse/environments/" + t + "/stream";
489
+ Y ? this.eventSource || (this.log("Creating event source with url " + n), this.eventSource = new Y(n), this.eventSource.addEventListener("environment_updated", function(r) {
490
+ var s;
491
+ try {
492
+ s = JSON.parse(r.data).updated_at;
493
+ } catch (c) {
494
+ i.log("Could not parse sse event", c);
495
+ }
496
+ 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);
497
+ })) : this.log("Error, EventSource is undefined");
498
+ }, a;
499
+ }();
500
+ function zt(a) {
501
+ var e = a.fetch, t = a.AsyncStorage, i = a.eventSource;
502
+ return new he({ fetch: e, AsyncStorage: t, eventSource: i });
503
+ }
504
+ var ut, ve = (ut = function(a, e) {
505
+ return ut = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, i) {
506
+ t.__proto__ = i;
507
+ } || function(t, i) {
508
+ for (var n in i) Object.prototype.hasOwnProperty.call(i, n) && (t[n] = i[n]);
509
+ }, ut(a, e);
510
+ }, function(a, e) {
511
+ if (typeof e != "function" && e !== null) throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
512
+ function t() {
513
+ this.constructor = a;
514
+ }
515
+ ut(a, e), a.prototype = e === null ? Object.create(e) : (t.prototype = e.prototype, new t());
516
+ }), Ht = function(a) {
517
+ var e = typeof Symbol == "function" && Symbol.iterator, t = e && a[e], i = 0;
518
+ if (t) return t.call(a);
519
+ if (a && typeof a.length == "number") return { next: function() {
520
+ return a && i >= a.length && (a = void 0), { value: a && a[i++], done: !a };
521
+ } };
522
+ throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined.");
523
+ }, $t = function(a, e) {
524
+ var t = typeof Symbol == "function" && a[Symbol.iterator];
525
+ if (!t) return a;
526
+ var i, n, r = t.call(a), s = [];
527
+ try {
528
+ for (; (e === void 0 || e-- > 0) && !(i = r.next()).done; ) s.push(i.value);
529
+ } catch (c) {
530
+ n = { error: c };
531
+ } finally {
532
+ try {
533
+ i && !i.done && (t = r.return) && t.call(r);
534
+ } finally {
535
+ if (n) throw n.error;
536
+ }
537
+ }
538
+ return s;
539
+ }, ft = function(a, e, t) {
540
+ if (arguments.length === 2) for (var i, n = 0, r = e.length; n < r; n++) !i && n in e || (i || (i = Array.prototype.slice.call(e, 0, n)), i[n] = e[n]);
541
+ return a.concat(i || Array.prototype.slice.call(e));
542
+ }, de = function(a) {
543
+ function e() {
544
+ return a.call(this, `EventSource not available.
545
+ Consider loading an EventSource polyfill and making it available globally as EventSource, or passing one in as eventSourceClass to the ReconnectingEventSource constructor.`) || this;
546
+ }
547
+ return ve(e, a), e;
548
+ }(Error), qt = function() {
549
+ function a(e, t) {
550
+ var i = this;
551
+ if (this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, this._configuration = t != null ? Object.assign({}, t) : void 0, this.withCredentials = !1, this._eventSource = null, this._lastEventId = null, this._timer = null, this._listeners = { open: [], error: [], message: [] }, this.url = e.toString(), this.readyState = this.CONNECTING, this.max_retry_time = 3e3, this.eventSourceClass = globalThis.FlagsmithEventSource, this._configuration != null && (this._configuration.lastEventId && (this._lastEventId = this._configuration.lastEventId, delete this._configuration.lastEventId), this._configuration.max_retry_time && (this.max_retry_time = this._configuration.max_retry_time, delete this._configuration.max_retry_time), this._configuration.eventSourceClass && (this.eventSourceClass = this._configuration.eventSourceClass, delete this._configuration.eventSourceClass)), this.eventSourceClass == null || typeof this.eventSourceClass != "function") throw new de();
552
+ this._onevent_wrapped = function(n) {
553
+ i._onevent(n);
554
+ }, this._start();
555
+ }
556
+ return a.prototype.dispatchEvent = function(e) {
557
+ throw new Error("Method not implemented.");
558
+ }, a.prototype._start = function() {
559
+ var e, t, i = this, n = this.url;
560
+ this._lastEventId && (n.indexOf("?") === -1 ? n += "?" : n += "&", n += "lastEventId=" + encodeURIComponent(this._lastEventId)), this._eventSource = new this.eventSourceClass(n, this._configuration), this._eventSource.onopen = function(h) {
561
+ i._onopen(h);
562
+ }, this._eventSource.onerror = function(h) {
563
+ i._onerror(h);
564
+ }, this._eventSource.onmessage = function(h) {
565
+ i.onmessage(h);
566
+ };
567
+ try {
568
+ for (var r = Ht(Object.keys(this._listeners)), s = r.next(); !s.done; s = r.next()) {
569
+ var c = s.value;
570
+ this._eventSource.addEventListener(c, this._onevent_wrapped);
571
+ }
572
+ } catch (h) {
573
+ e = { error: h };
574
+ } finally {
575
+ try {
576
+ s && !s.done && (t = r.return) && t.call(r);
577
+ } finally {
578
+ if (e) throw e.error;
579
+ }
580
+ }
581
+ }, a.prototype._onopen = function(e) {
582
+ this.readyState === 0 && (this.readyState = 1, this.onopen(e));
583
+ }, a.prototype._onerror = function(e) {
584
+ var t = this;
585
+ if (this.readyState === 1 && (this.readyState = 0, this.onerror(e)), this._eventSource) {
586
+ this._eventSource.close(), this._eventSource = null;
587
+ var i = Math.round(this.max_retry_time * Math.random());
588
+ this._timer = setTimeout(function() {
589
+ return t._start();
590
+ }, i);
591
+ }
592
+ }, a.prototype._onevent = function(e) {
593
+ var t, i;
594
+ e && e.lastEventId && (this._lastEventId = e.lastEventId);
595
+ var n = this._listeners[e.type];
596
+ if (n != null) try {
597
+ for (var r = Ht(ft([], $t(n), !1)), s = r.next(); !s.done; s = r.next())
598
+ s.value.call(this, e);
599
+ } catch (c) {
600
+ t = { error: c };
601
+ } finally {
602
+ try {
603
+ s && !s.done && (i = r.return) && i.call(r);
604
+ } finally {
605
+ if (t) throw t.error;
606
+ }
607
+ }
608
+ e.type === "message" && this.onmessage(e);
609
+ }, a.prototype.onopen = function(e) {
610
+ }, a.prototype.onerror = function(e) {
611
+ }, a.prototype.onmessage = function(e) {
612
+ }, a.prototype.close = function() {
613
+ this._timer && (clearTimeout(this._timer), this._timer = null), this._eventSource && (this._eventSource.close(), this._eventSource = null), this.readyState = 2;
614
+ }, a.prototype.addEventListener = function(e, t, i) {
615
+ this._listeners[e] == null && (this._listeners[e] = [], this._eventSource != null && this._eventSource.addEventListener(e, this._onevent_wrapped));
616
+ var n = this._listeners[e];
617
+ n.includes(t) || (this._listeners[e] = ft(ft([], $t(n), !1), [t], !1));
618
+ }, a.prototype.removeEventListener = function(e, t, i) {
619
+ var n = this._listeners[e];
620
+ this._listeners[e] = n.filter(function(r) {
621
+ return r !== t;
622
+ });
623
+ }, a;
624
+ }();
625
+ globalThis.FlagsmithEventSource = typeof EventSource < "u" ? EventSource : null;
626
+ var Wt = function(a, e) {
627
+ return e = e || {}, new Promise(function(t, i) {
628
+ var n = new XMLHttpRequest(), r = [], s = [], c = {}, h = function() {
629
+ return { ok: (n.status / 100 | 0) == 2, statusText: n.statusText, status: n.status, url: n.responseURL, text: function() {
630
+ return Promise.resolve(n.responseText);
631
+ }, json: function() {
632
+ return Promise.resolve(n.responseText).then(JSON.parse);
633
+ }, blob: function() {
634
+ return Promise.resolve(new Blob([n.response]));
635
+ }, clone: h, headers: { keys: function() {
636
+ return r;
637
+ }, entries: function() {
638
+ return s;
639
+ }, get: function(l) {
640
+ return c[l.toLowerCase()];
641
+ }, has: function(l) {
642
+ return l.toLowerCase() in c;
643
+ } } };
644
+ };
645
+ for (var f in n.open(e.method || "get", a, !0), n.onload = function() {
646
+ n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, function(l, y, x) {
647
+ r.push(y = y.toLowerCase()), s.push([y, x]), c[y] = c[y] ? c[y] + "," + x : x;
648
+ }), t(h());
649
+ }, n.onerror = i, n.withCredentials = e.credentials == "include", e.headers) n.setRequestHeader(f, e.headers[f]);
650
+ n.send(e.body || null);
651
+ });
652
+ }, Xt = zt({ AsyncStorage: d, fetch: Wt, eventSource: qt });
653
+ typeof window < "u" && (window.flagsmith = Xt), v.createFlagsmithInstance = function() {
654
+ return zt({ AsyncStorage: d, fetch: Wt, eventSource: qt });
655
+ }, v.default = Xt, Object.defineProperty(v, "__esModule", { value: !0 });
656
+ });
657
+ })(Gt, Gt.exports);
658
+ var me = Gt.exports, re = {
659
+ NOT_INITIALIZED: "FeatureFlag not initialized. Call init() first.",
660
+ INVALID_CONFIG: "Invalid Flagsmith configuration",
661
+ FETCH_FAILED: "Failed to fetch Flagsmith configuration",
662
+ NO_USER_CONTEXT: "User context not set. Call setUser() first.",
663
+ ALREADY_INITIALIZED: "FeatureFlag is already initialized."
664
+ }, se = "business", V, Se = (V = class {
665
+ constructor() {
666
+ ct(this, "flagsmithClient", null);
667
+ ct(this, "userContext", null);
668
+ }
669
+ static getInstance() {
670
+ return V.instance || (V.instance = new V()), V.instance;
671
+ }
672
+ ensureInitialized() {
673
+ if (!this.flagsmithClient)
674
+ throw new Error(re.NOT_INITIALIZED);
675
+ }
676
+ async init(u, v = []) {
677
+ if (!this.flagsmithClient)
678
+ try {
679
+ this.flagsmithClient = me.createFlagsmithInstance();
680
+ const d = v.reduce((o, E) => (o[E.feature.name] = E, o), {});
681
+ await this.flagsmithClient.init({
682
+ environmentID: u.apiKey,
683
+ api: (u == null ? void 0 : u.url) ?? "https://flag.feedme.farm/api/v1/",
684
+ enableAnalytics: (u == null ? void 0 : u.enableAnalytics) ?? !0,
685
+ defaultFlags: d,
686
+ cacheFlags: (u == null ? void 0 : u.cacheFlags) ?? !0
687
+ });
688
+ } catch (d) {
689
+ throw console.error("Failed to initialize FeatureFlag:", d), d;
690
+ }
691
+ }
692
+ async setUser(u, v) {
693
+ this.ensureInitialized(), this.userContext = { identifier: u, traits: v }, await this.updateContext();
694
+ }
695
+ async addTraits(u) {
696
+ if (this.ensureInitialized(), !this.userContext)
697
+ throw new Error(re.NO_USER_CONTEXT);
698
+ this.userContext.traits = { ...this.userContext.traits, ...u }, await this.updateContext();
699
+ }
700
+ async updateContext() {
701
+ try {
702
+ if (!this.userContext) return;
703
+ await this.flagsmithClient.setContext({
704
+ identity: {
705
+ identifier: this.userContext.identifier,
706
+ traits: this.userContext.traits || {}
707
+ }
708
+ });
709
+ } catch (u) {
710
+ throw console.error("Failed to update user context:", u), u;
711
+ }
712
+ }
713
+ async getFlags() {
714
+ this.ensureInitialized();
715
+ const u = this.flagsmithClient.getAllFlags();
716
+ return Object.entries(u).map(([v, d]) => {
717
+ var o;
718
+ return {
719
+ feature: {
720
+ name: v,
721
+ id: (d == null ? void 0 : d.id) ?? 0
722
+ },
723
+ enabled: d.enabled,
724
+ value: ((o = d.value) == null ? void 0 : o.toString()) ?? null
725
+ };
726
+ });
727
+ }
728
+ getFlagValue(u, v) {
729
+ this.ensureInitialized();
730
+ const d = this.flagsmithClient.getValue(u);
731
+ if (d == null)
732
+ return null;
733
+ try {
734
+ const o = d.toString();
735
+ return v ? v(o) : typeof {} == "number" ? isNaN(Number(o)) ? null : Number(o) : typeof {} == "boolean" ? o.toLowerCase() === "true" : o;
736
+ } catch (o) {
737
+ return console.error("Error transforming flag value:", o), null;
738
+ }
739
+ }
740
+ getFlag(u) {
741
+ this.ensureInitialized();
742
+ const v = this.flagsmithClient.getValue(u);
743
+ if (v == null) return null;
744
+ const d = this.flagsmithClient.hasFeature(u);
745
+ return {
746
+ feature: {
747
+ name: u,
748
+ id: 0
749
+ },
750
+ enabled: d,
751
+ value: v.toString()
752
+ };
753
+ }
754
+ async getUserFlagValue(u, v, d = null, o) {
755
+ var M;
756
+ const E = this.userContext;
757
+ try {
758
+ return await this.setUser(u), this.getFlagValue(v, o) ?? d;
759
+ } catch (T) {
760
+ return console.error(`Error getting user flag value for ${v}:`, T), d;
761
+ } finally {
762
+ try {
763
+ await ((M = this.flagsmithClient) == null ? void 0 : M.logout()), this.userContext = null, E && await this.setUser(E.identifier, E.traits);
764
+ } catch (T) {
765
+ console.error("Error during cleanup:", T);
766
+ }
767
+ }
768
+ }
769
+ reset() {
770
+ this.flagsmithClient = null, this.userContext = null;
771
+ }
772
+ }, ct(V, "instance"), V), be = Se.getInstance(), st = gt(!1), ot = gt([]), q = gt(null);
773
+ function Ce(S = be) {
774
+ const u = () => st.value ? !0 : (console.warn("FeatureFlag is not initialized. Using default values."), !1), v = async (g, p = []) => {
775
+ if (st.value) {
776
+ console.warn("FeatureFlag is already initialized.");
777
+ return;
778
+ }
779
+ try {
780
+ await S.init(g, p), ot.value = await S.getFlags(), st.value = !0, q.value = null;
781
+ } catch (C) {
782
+ console.error("Failed to initialize feature flags:", C), q.value = C;
783
+ }
784
+ }, d = async (g, p) => {
785
+ if (u())
786
+ try {
787
+ await S.setUser(g, p), ot.value = await S.getFlags(), q.value = null;
788
+ } catch (C) {
789
+ console.error("Failed to set user:", C), q.value = C;
790
+ }
791
+ }, o = async (g, p) => d(`${se}-${g}`, p), E = async (g) => {
792
+ if (u())
793
+ try {
794
+ await S.addTraits(g), ot.value = await S.getFlags(), q.value = null;
795
+ } catch (p) {
796
+ console.error("Failed to add traits:", p), q.value = p;
797
+ }
798
+ }, M = (g, p, C = null) => {
799
+ if (!u()) return C;
800
+ try {
801
+ return S.getFlagValue(g, p) ?? C;
802
+ } catch (k) {
803
+ return console.error(`Error getting flag value for ${g}:`, k), C;
804
+ }
805
+ }, T = (g, p) => {
806
+ if (!u()) return p ?? null;
807
+ try {
808
+ return S.getFlag(g) ?? p ?? null;
809
+ } catch (C) {
810
+ return console.error(`Error getting flag for ${g}:`, C), p ?? null;
811
+ }
812
+ }, X = async (g, p, C = null, k) => {
813
+ if (!u()) return C;
814
+ try {
815
+ return await S.getUserFlagValue(g, p, C, k);
816
+ } catch (z) {
817
+ return console.error(`Error getting user flag value for ${p}:`, z), C;
818
+ }
819
+ }, _ = async (g, p, C = null, k) => X(`${se}-${g}`, p, C, k), F = () => {
820
+ try {
821
+ S.reset();
822
+ } catch (g) {
823
+ console.error("Error resetting feature flags:", g);
824
+ } finally {
825
+ ot.value = [], st.value = !1, q.value = null;
826
+ }
827
+ };
828
+ return {
829
+ flags: Kt(ot),
830
+ isInitialized: Kt(st),
831
+ error: Kt(q),
832
+ init: v,
833
+ setUser: d,
834
+ setBusiness: o,
835
+ addTraits: E,
836
+ getFlagValue: M,
837
+ getFlag: T,
838
+ getUserFlagValue: X,
839
+ getBusinessFlagValue: _,
840
+ reset: F
841
+ };
842
+ }
843
+ var le = () => Ce();
844
+ const _e = /* @__PURE__ */ new Set([
845
+ // vivo pizza prod
846
+ "business_6687e91fa7240b001ba3f4c2",
847
+ // vivo dev
848
+ "business_669a1d2efc050a001cfbb5a2"
849
+ ]), Ee = /* @__PURE__ */ new Set([
850
+ // vivo pizza prod
851
+ "business_6687e91fa7240b001ba3f4c2",
852
+ // vivo dev
853
+ "business_669a1d2efc050a001cfbb5a2",
854
+ // kfc dev
855
+ "business_655b25254fe3be001b123f0b",
856
+ // King Menu V4
857
+ "business_646ee00ebffa92001b84c4c7"
858
+ ]), oe = /* @__PURE__ */ new Set([
859
+ // zus dev
860
+ "business_671005de24a7f4001c87e25e",
861
+ // zus prod
862
+ "business_6776a1fe205a52001c516efa"
863
+ ]), Fe = /* @__PURE__ */ new Set([
864
+ // zus dev
865
+ "business_671005de24a7f4001c87e25e",
866
+ // zus prod
867
+ "business_6776a1fe205a52001c516efa"
868
+ ]), xe = /* @__PURE__ */ new Set([
869
+ // zus dev
870
+ "business_671005de24a7f4001c87e25e",
871
+ // zus prod
872
+ "business_6776a1fe205a52001c516efa"
873
+ ]);
874
+ function ue() {
875
+ return {
876
+ autoReceiveWarehouse: !1,
877
+ businessSupplierOnly: !1,
878
+ enableBackdatePo: !1,
879
+ enableClosingTemplate: !1,
880
+ enableIngredientGroup: !1,
881
+ enablePoTemplate: !1,
882
+ enableSupplierMasterList: !1,
883
+ enableTotalCost: !1,
884
+ enableWastageTemplate: !1,
885
+ manualReceive: !1,
886
+ mustUsePoTemplate: !1,
887
+ enableReturnStocks: !1
888
+ };
889
+ }
890
+ const I = gt(ue()), Te = () => ({
891
+ get businessDbName() {
892
+ var v;
893
+ return `business_${((v = ht().currentBusiness.value) == null ? void 0 : v._id) ?? ""}`;
894
+ },
895
+ get isWarehouse() {
896
+ var u;
897
+ return ((u = Dt()._currentLocation) == null ? void 0 : u.type) === ae.enum.warehouse;
898
+ },
899
+ get restaurantPosVersion() {
900
+ var v;
901
+ const S = Dt();
902
+ return (v = ht().restaurants.value.find(
903
+ (d) => {
904
+ var o;
905
+ return d._id === ((o = S._currentLocation) == null ? void 0 : o.doc._id);
906
+ }
907
+ )) == null ? void 0 : v.posVersion;
908
+ },
909
+ get enableTotalCost() {
910
+ return I.value.enableTotalCost;
911
+ },
912
+ get enableBackdatePo() {
913
+ return I.value.enableBackdatePo;
914
+ },
915
+ /** @deprecated TODO: remove */
916
+ get autoReceiveWarehouse() {
917
+ return I.value.autoReceiveWarehouse;
918
+ },
919
+ /** @deprecated TODO: remove */
920
+ get manualReceive() {
921
+ return I.value.manualReceive;
922
+ },
923
+ get enablePoTemplate() {
924
+ return I.value.enablePoTemplate;
925
+ },
926
+ get enableClosingTemplate() {
927
+ return I.value.enableClosingTemplate;
928
+ },
929
+ get enableWastageTemplate() {
930
+ return I.value.enableWastageTemplate;
931
+ },
932
+ get enableIngredientGroup() {
933
+ return I.value.enableIngredientGroup;
934
+ },
935
+ get mustUsePoTemplate() {
936
+ return I.value.mustUsePoTemplate;
937
+ },
938
+ get enableSupplierMasterList() {
939
+ return I.value.enableSupplierMasterList;
940
+ },
941
+ get businessSupplierOnly() {
942
+ return I.value.businessSupplierOnly;
943
+ },
944
+ get enableReturnStocks() {
945
+ return I.value.enableReturnStocks;
946
+ },
947
+ async init() {
948
+ const S = ht(), { init: u, setUser: v } = le(), d = S.namespace.value === "prod";
949
+ await u({
950
+ apiKey: d ? "6GhcttsJ9Rj9cTevcdrpin" : "MaGoXrEWuEJNpWgKTqseee"
951
+ // url: 'https://flag.feedme.farm/api/v1/', // optional -> this is a default URL value
952
+ // enableAnalytics: true, // optional, defaults to true
953
+ // cacheFlags: true // optional, defaults to true
954
+ }), Dt().watchLocation(async (E) => {
955
+ var k, z, Y;
956
+ if (!E) {
957
+ I.value = ue();
958
+ return;
959
+ }
960
+ await v(E.doc._id);
961
+ const M = ye(), T = ht(), _ = `business_${((k = T.currentBusiness.value) == null ? void 0 : k._id) ?? ""}`, F = E.type === ae.enum.warehouse, g = (
962
+ // if menu v4, must manual receive && must use outlet app
963
+ ((z = T.currentBusiness.value) == null ? void 0 : z.menuVersion) === "v4" && // more guard for businesses using menu v4, only those listed for manual receive will be included
964
+ // TODO: may be removed to use menu version only
965
+ _e.has(this.businessDbName)
966
+ ), p = oe.has(_) || dt(
967
+ "inventory_portal_must_use_transfer_template"
968
+ /* inventory_portal_must_use_transfer_template */
969
+ ), C = Ee.has(this.businessDbName) && (this.isWarehouse || M.state.closing !== null);
970
+ I.value = {
971
+ enableTotalCost: ((Y = T.currentBusiness.value) == null ? void 0 : Y.menuVersion) === "v4",
972
+ enableBackdatePo: C,
973
+ autoReceiveWarehouse: F && !g,
974
+ manualReceive: g,
975
+ enablePoTemplate: p,
976
+ enableClosingTemplate: Fe.has(_) && dt(
977
+ "inventory_pos_closing_v2"
978
+ /* inventory_pos_closing_v2 */
979
+ ),
980
+ enableWastageTemplate: xe.has(_) && dt(
981
+ "inventory_pos_adjust_v2_wastage"
982
+ /* inventory_pos_adjust_v2_wastage */
983
+ ),
984
+ enableIngredientGroup: !1,
985
+ mustUsePoTemplate: p,
986
+ businessSupplierOnly: p,
987
+ enableSupplierMasterList: oe.has(_),
988
+ enableReturnStocks: dt(
989
+ "inventory_portal_stock_return"
990
+ /* inventory_portal_stock_return */
991
+ )
992
+ };
993
+ }, "feature");
994
+ }
995
+ });
996
+ function dt(S, u) {
997
+ u = u === void 0 ? null : u;
998
+ const { getFlagValue: v } = le();
999
+ return v(S, (d) => d === "true") ?? u;
1000
+ }
1001
+ export {
1002
+ Te as u
1003
+ };