@teincfood/core 0.7.6 → 0.7.7

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.
@@ -7,9 +7,7 @@ export declare function setActiveBusiness(b: {
7
7
  export declare function getActiveBusiness(): {
8
8
  id: string;
9
9
  } | null;
10
- export declare function subscribeBusiness(listener: (b: {
11
- id: string;
12
- } | null) => void): () => void;
10
+ export declare function subscribeBusiness(listener: () => void): () => void;
13
11
  export declare const useBusinessStore: {
14
12
  getState: () => {
15
13
  activeBusiness: {
@@ -4,8 +4,10 @@
4
4
  let activeBusiness = null;
5
5
  const listeners = new Set();
6
6
  export function setActiveBusiness(b) {
7
+ if ((b?.id ?? null) === (activeBusiness?.id ?? null))
8
+ return;
7
9
  activeBusiness = b;
8
- listeners.forEach((l) => l(b));
10
+ listeners.forEach((l) => l());
9
11
  }
10
12
  export function getActiveBusiness() {
11
13
  return activeBusiness;
@@ -11,7 +11,7 @@ export declare function getConnectivityState(): ConnectivityState;
11
11
  export declare function setConnectivityState(patch: Partial<ConnectivityState>): void;
12
12
  export declare function setCloudReachable(value: CloudReachable): void;
13
13
  export declare function setOnline(value: boolean): void;
14
- export declare function subscribeConnectivity(listener: (s: ConnectivityState) => void): () => void;
14
+ export declare function subscribeConnectivity(listener: () => void): () => void;
15
15
  export declare const connectivityStoreShim: {
16
16
  getState: typeof getConnectivityState;
17
17
  };
@@ -8,11 +8,14 @@ let state = {
8
8
  };
9
9
  const listeners = new Set();
10
10
  export function getConnectivityState() {
11
- return { ...state };
11
+ return state;
12
12
  }
13
13
  export function setConnectivityState(patch) {
14
- state = { ...state, ...patch };
15
- listeners.forEach((l) => l({ ...state }));
14
+ const next = { ...state, ...patch };
15
+ if (next.isOnline === state.isOnline && next.isCloudReachable === state.isCloudReachable)
16
+ return;
17
+ state = next;
18
+ listeners.forEach((l) => l());
16
19
  }
17
20
  export function setCloudReachable(value) {
18
21
  setConnectivityState({ isCloudReachable: value });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Kiosk hooks shim — delegates to order lifecycle hooks for offline-first.
3
+ * Kiosk is just a filtered view of seller orders; transitions use the same outbox.
4
+ */
5
+ export { useAcceptOrderMutation as useAcceptKioskOrderMutation, useRejectOrderMutation as useRejectKioskOrderMutation, useStartPreparingOrderMutation as useStartPreparingKioskOrderMutation, useMarkOrderReadyMutation as useMarkKioskOrderReadyMutation, } from "./orders.hooks";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Kiosk hooks shim — delegates to order lifecycle hooks for offline-first.
3
+ * Kiosk is just a filtered view of seller orders; transitions use the same outbox.
4
+ */
5
+ export { useAcceptOrderMutation as useAcceptKioskOrderMutation, useRejectOrderMutation as useRejectKioskOrderMutation, useStartPreparingOrderMutation as useStartPreparingKioskOrderMutation, useMarkOrderReadyMutation as useMarkKioskOrderReadyMutation, } from "./orders.hooks";
@@ -13,7 +13,7 @@ import { insertCommand, getPendingCommands, markCommandInFlight, updateCommandSt
13
13
  import { syncLogger } from "../utils/sync-logger";
14
14
  import { generateEventId } from "../utils/uuid";
15
15
  import { generateLocalCalloutNumber, generateOrderNumberForBusiness, } from "./order-number";
16
- import { subscribeConnectivity } from "../adapters/connectivity";
16
+ import { getConnectivityState, subscribeConnectivity } from "../adapters/connectivity";
17
17
  const MAX_RETRIES = 5;
18
18
  const QUEUED_STATUS_BY_COMMAND = {
19
19
  "order:accept": "accepted",
@@ -65,6 +65,10 @@ function buildOptimisticEvent(command) {
65
65
  function buildOptimisticOrder(command, payload) {
66
66
  const items = payload.items ?? [];
67
67
  const totalMinor = payload.total_minor ?? 0;
68
+ const subtotalMinor = payload.subtotal_minor ?? totalMinor;
69
+ const taxMinor = payload.tax_minor ?? 0;
70
+ const taxLines = payload.tax_lines ?? [];
71
+ const currencyCode = payload.currency_code ?? "GHS";
68
72
  const now = new Date().toISOString();
69
73
  const orderNumber = payload.order_number ?? generateOrderNumberForBusiness(command.business_id);
70
74
  return {
@@ -85,20 +89,20 @@ function buildOptimisticOrder(command, payload) {
85
89
  is_paid: payload.pos_payment_method === "cash",
86
90
  reference: null,
87
91
  amount_minor: totalMinor,
88
- currency: "GHS",
92
+ currency: currencyCode,
89
93
  paid_at: payload.pos_payment_method === "cash" ? now : null,
90
94
  },
91
95
  payment_mode: "pos_cash",
92
96
  total_minor: totalMinor,
93
- subtotal_minor: totalMinor,
94
- delivery_fee_minor: 0,
95
- tax_minor: 0,
96
- tip_minor: null,
97
- discount_minor: 0,
98
- promo_code: null,
99
- tax_lines: [],
100
- currency: "GHS",
101
- currency_code: "GHS",
97
+ subtotal_minor: subtotalMinor,
98
+ delivery_fee_minor: payload.delivery_fee_minor ?? 0,
99
+ tax_minor: taxMinor,
100
+ tip_minor: payload.tip_minor ?? null,
101
+ discount_minor: payload.discount_minor ?? 0,
102
+ promo_code: payload.promo_code ?? null,
103
+ tax_lines: taxLines,
104
+ currency: currencyCode,
105
+ currency_code: currencyCode,
102
106
  business_id: command.business_id,
103
107
  business: null,
104
108
  delivery_address: null,
@@ -147,7 +151,8 @@ class CommandQueueService {
147
151
  // timeout-induced `unreachable` flip, then the next successful probe sets
148
152
  // `reachable`). No polling — event-driven via connectivity state.
149
153
  try {
150
- subscribeConnectivity((s) => {
154
+ subscribeConnectivity(() => {
155
+ const s = getConnectivityState();
151
156
  if (s.isCloudReachable === "reachable" && s.isOnline) {
152
157
  this.replay().catch(() => { });
153
158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teincfood/core",
3
- "version": "0.7.6",
3
+ "version": "0.7.7",
4
4
  "description": "TeincFood shared offline-first core — types, sync engine, local DB, reference data, and repositories for mobile + desktop",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",