@tallyui/pos 4.0.1 → 4.2.0
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.
- package/dist/index.d.ts +123 -3
- package/dist/index.js +267 -84
- package/package.json +6 -6
- package/src/index.ts +7 -3
- package/src/order/order-builder.ts +5 -3
- package/src/order/order-drafts.ts +2 -0
- package/src/order/taken-at.ts +5 -0
- package/src/order/types.ts +2 -0
- package/src/pos-order/finalize.ts +2 -0
- package/src/pos-order/reopen.ts +2 -0
- package/src/pos-order/schema.ts +4 -2
- package/src/pos-order/types.ts +2 -0
- package/src/print/escpos/bluetooth-sink.ts +114 -0
- package/src/print/escpos/index.ts +4 -0
- package/src/print/escpos/sinks.test-d.ts +77 -0
- package/src/print/escpos/transport.ts +3 -2
- package/src/print/escpos/usb-sink.ts +84 -0
- package/src/print/index.ts +2 -2
- package/src/sale/use-sale.ts +16 -9
- package/src/store-orders/index.ts +2 -0
- package/src/store-orders/use-store-orders-in-range.ts +127 -0
- package/src/tax/index.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -898,6 +898,18 @@ function taxDerivation(settings, taxLocation) {
|
|
|
898
898
|
};
|
|
899
899
|
}
|
|
900
900
|
|
|
901
|
+
// src/tax/taxed-lines.ts
|
|
902
|
+
function taxedLinesFor(lines, charges, pricesIncludeTax, rounding) {
|
|
903
|
+
return [
|
|
904
|
+
...lines.map((line) => ({ ...line, taxInclusive: rounding?.granularity === "woocommerce" && line.netMicros !== void 0 ? pricesIncludeTax : line.taxInclusive ?? pricesIncludeTax })),
|
|
905
|
+
...charges.map((charge) => ({ ...charge, taxInclusive: rounding?.granularity === "woocommerce" ? pricesIncludeTax : charge.amountIncludesTax ?? pricesIncludeTax }))
|
|
906
|
+
];
|
|
907
|
+
}
|
|
908
|
+
function recordedTaxByRate(order) {
|
|
909
|
+
if (order.taxRounding?.granularity === "woocommerce" && order.lines.some((line) => line.netMicros !== void 0 && line.taxInclusive !== void 0)) return void 0;
|
|
910
|
+
return order.taxByRate;
|
|
911
|
+
}
|
|
912
|
+
|
|
901
913
|
// src/store-settings/resolve-store-settings.ts
|
|
902
914
|
import { StoreSettingsError } from "@tallyui/core";
|
|
903
915
|
function narrowInitial(tried, choices) {
|
|
@@ -2015,10 +2027,11 @@ function createOrderBuilder(options) {
|
|
|
2015
2027
|
emit();
|
|
2016
2028
|
return id2;
|
|
2017
2029
|
},
|
|
2018
|
-
setPaymentStatus(paymentId, status) {
|
|
2030
|
+
setPaymentStatus(paymentId, status, takenAt) {
|
|
2019
2031
|
const payment = payments.find((p) => p.id === paymentId);
|
|
2020
2032
|
if (!payment || payment.locked || !canMoveLeg(legStatus(payment), status)) return false;
|
|
2021
|
-
|
|
2033
|
+
const stamp2 = status === "captured" && takenAt !== void 0 ? { takenAt } : {};
|
|
2034
|
+
payments = payments.map((p) => p.id === paymentId ? { ...p, status, ...stamp2 } : p);
|
|
2022
2035
|
emit();
|
|
2023
2036
|
return true;
|
|
2024
2037
|
},
|
|
@@ -2113,6 +2126,13 @@ import { BehaviorSubject as BehaviorSubject2 } from "rxjs";
|
|
|
2113
2126
|
|
|
2114
2127
|
// src/order/order-drafts.ts
|
|
2115
2128
|
import { map as map3 } from "rxjs";
|
|
2129
|
+
|
|
2130
|
+
// src/order/taken-at.ts
|
|
2131
|
+
function isTakenAt(value) {
|
|
2132
|
+
return typeof value === "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(value) && Number.isFinite(Date.parse(value)) && new Date(value).toISOString() === value;
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
// src/order/order-drafts.ts
|
|
2116
2136
|
var orderDraftSchema = {
|
|
2117
2137
|
version: 0,
|
|
2118
2138
|
primaryKey: "id",
|
|
@@ -2220,7 +2240,8 @@ function restoreOrderDraft(saved, options) {
|
|
|
2220
2240
|
...payment.locked !== void 0 ? { locked: payment.locked } : {},
|
|
2221
2241
|
...payment.reopened !== void 0 ? { reopened: payment.reopened } : {},
|
|
2222
2242
|
...payment.methodId !== void 0 ? { methodId: payment.methodId } : {},
|
|
2223
|
-
...payment.units !== void 0 ? { units: payment.units } : {}
|
|
2243
|
+
...payment.units !== void 0 ? { units: payment.units } : {},
|
|
2244
|
+
...isTakenAt(payment.takenAt) ? { takenAt: payment.takenAt } : {}
|
|
2224
2245
|
});
|
|
2225
2246
|
}
|
|
2226
2247
|
if (saved.coupons?.some((c) => c.carried) && !saved.coupons.every((c) => c.carried)) throw new Error("restoreOrderDraft: a draft cannot mix carried and redeemable coupons");
|
|
@@ -2330,6 +2351,71 @@ function useParkedSales(drafts) {
|
|
|
2330
2351
|
return { parked, discard };
|
|
2331
2352
|
}
|
|
2332
2353
|
|
|
2354
|
+
// src/store-orders/use-store-orders-in-range.ts
|
|
2355
|
+
import { useEffect as useEffect5, useMemo as useMemo4, useState as useState5 } from "react";
|
|
2356
|
+
var PER_PAGE = 100;
|
|
2357
|
+
var STALLED = "listOrders answered hasMore: true with a page that added no new order";
|
|
2358
|
+
var IDLE = { orders: [], progress: null, unreadable: 0, error: null, complete: false };
|
|
2359
|
+
var STARTING = {
|
|
2360
|
+
orders: [],
|
|
2361
|
+
progress: { downloaded: 0, total: null },
|
|
2362
|
+
unreadable: 0,
|
|
2363
|
+
error: null,
|
|
2364
|
+
complete: false
|
|
2365
|
+
};
|
|
2366
|
+
async function readPages(connector, context, query, live, onPage) {
|
|
2367
|
+
for (let page = 1; ; page++) {
|
|
2368
|
+
await Promise.resolve();
|
|
2369
|
+
if (!live()) return;
|
|
2370
|
+
const result = await connector.listOrders(context, { ...query, page, perPage: PER_PAGE });
|
|
2371
|
+
if (!live()) return;
|
|
2372
|
+
onPage(result, page === 1);
|
|
2373
|
+
if (!result.hasMore) return;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
function useStoreOrdersInRange(connector, context, query) {
|
|
2377
|
+
const key = query ? JSON.stringify(query) : null;
|
|
2378
|
+
const [read, setRead] = useState5(null);
|
|
2379
|
+
useEffect5(() => {
|
|
2380
|
+
if (!connector?.listOrders || !context || key === null) return;
|
|
2381
|
+
let live = true;
|
|
2382
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2383
|
+
let current = { connector, context, key, orders: [], unreadable: 0, total: null, status: "reading" };
|
|
2384
|
+
const publish = (next) => {
|
|
2385
|
+
current = next;
|
|
2386
|
+
setRead(next);
|
|
2387
|
+
};
|
|
2388
|
+
readPages(connector, context, JSON.parse(key), () => live, (page, first) => {
|
|
2389
|
+
const fresh = page.orders.filter((order) => {
|
|
2390
|
+
if (seen.has(order.id)) return false;
|
|
2391
|
+
seen.add(order.id);
|
|
2392
|
+
return true;
|
|
2393
|
+
});
|
|
2394
|
+
if (page.hasMore && fresh.length === 0) throw new Error(STALLED);
|
|
2395
|
+
publish({
|
|
2396
|
+
...current,
|
|
2397
|
+
orders: [...current.orders, ...fresh],
|
|
2398
|
+
unreadable: current.unreadable + (first || fresh.length > 0 ? page.unreadable ?? 0 : 0),
|
|
2399
|
+
total: first ? page.total ?? null : current.total,
|
|
2400
|
+
status: page.hasMore ? "reading" : "complete"
|
|
2401
|
+
});
|
|
2402
|
+
}).catch((error) => {
|
|
2403
|
+
if (live) publish({ ...current, status: "error", error });
|
|
2404
|
+
});
|
|
2405
|
+
return () => {
|
|
2406
|
+
live = false;
|
|
2407
|
+
setRead(null);
|
|
2408
|
+
};
|
|
2409
|
+
}, [connector, context, key]);
|
|
2410
|
+
return useMemo4(() => {
|
|
2411
|
+
if (!connector?.listOrders || !context || key === null) return IDLE;
|
|
2412
|
+
if (!read || read.connector !== connector || read.context !== context || read.key !== key) return STARTING;
|
|
2413
|
+
const { orders, unreadable, total } = read;
|
|
2414
|
+
const progress = read.status === "reading" ? { downloaded: orders.length + unreadable, total } : null;
|
|
2415
|
+
return { orders, progress, unreadable, error: read.status === "error" ? read.error : null, complete: read.status === "complete" };
|
|
2416
|
+
}, [connector, context, key, read]);
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2333
2419
|
// src/pos-order/refund-due.ts
|
|
2334
2420
|
var sum = (amounts) => amounts.reduce((total, amount) => total + amount, 0);
|
|
2335
2421
|
function refundDueOf(order) {
|
|
@@ -2345,18 +2431,6 @@ function tillLegsTheStoreRefuses(order) {
|
|
|
2345
2431
|
return lockedMinor >= order.totalMinor ? captured.filter((payment) => !payment.locked).map((payment) => payment.id) : [];
|
|
2346
2432
|
}
|
|
2347
2433
|
|
|
2348
|
-
// src/tax/taxed-lines.ts
|
|
2349
|
-
function taxedLinesFor(lines, charges, pricesIncludeTax, rounding) {
|
|
2350
|
-
return [
|
|
2351
|
-
...lines.map((line) => ({ ...line, taxInclusive: rounding?.granularity === "woocommerce" && line.netMicros !== void 0 ? pricesIncludeTax : line.taxInclusive ?? pricesIncludeTax })),
|
|
2352
|
-
...charges.map((charge) => ({ ...charge, taxInclusive: rounding?.granularity === "woocommerce" ? pricesIncludeTax : charge.amountIncludesTax ?? pricesIncludeTax }))
|
|
2353
|
-
];
|
|
2354
|
-
}
|
|
2355
|
-
function recordedTaxByRate(order) {
|
|
2356
|
-
if (order.taxRounding?.granularity === "woocommerce" && order.lines.some((line) => line.netMicros !== void 0 && line.taxInclusive !== void 0)) return void 0;
|
|
2357
|
-
return order.taxByRate;
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
2434
|
// src/receipt/carried-rows.ts
|
|
2361
2435
|
var carriedCouponLabel = (code) => `coupon ${code} not accepted at send`;
|
|
2362
2436
|
var isCarriedCouponLabel = (label) => label.startsWith("coupon ") && label.endsWith(" not accepted at send");
|
|
@@ -4301,12 +4375,12 @@ function createDisplayLink(transport, options) {
|
|
|
4301
4375
|
}
|
|
4302
4376
|
|
|
4303
4377
|
// src/customer-display/use-customer-display.ts
|
|
4304
|
-
import { useEffect as
|
|
4378
|
+
import { useEffect as useEffect6, useState as useState6 } from "react";
|
|
4305
4379
|
var DISPLAY_TEMPLATE = { id: "default", version: 1 };
|
|
4306
4380
|
var HELLO_RETRY_MS = 2e3;
|
|
4307
4381
|
function useCustomerDisplay(transport) {
|
|
4308
|
-
const [state, setState] =
|
|
4309
|
-
|
|
4382
|
+
const [state, setState] = useState6(initialDisplayState);
|
|
4383
|
+
useEffect6(() => {
|
|
4310
4384
|
if (!transport) return;
|
|
4311
4385
|
const hello = makeEnvelope("display.hello", { template: DISPLAY_TEMPLATE });
|
|
4312
4386
|
let configured = false;
|
|
@@ -4409,14 +4483,14 @@ function createSaleDisplayPublisher(link, options = {}) {
|
|
|
4409
4483
|
}
|
|
4410
4484
|
|
|
4411
4485
|
// src/customer-display/use-sale-display.ts
|
|
4412
|
-
import { useEffect as
|
|
4486
|
+
import { useEffect as useEffect7, useRef as useRef2 } from "react";
|
|
4413
4487
|
function useSaleDisplay(link, sale, options) {
|
|
4414
4488
|
const latest = useRef2(options);
|
|
4415
|
-
|
|
4489
|
+
useEffect7(() => {
|
|
4416
4490
|
latest.current = options;
|
|
4417
4491
|
});
|
|
4418
4492
|
const held = useRef2(null);
|
|
4419
|
-
|
|
4493
|
+
useEffect7(() => {
|
|
4420
4494
|
if (!link) return;
|
|
4421
4495
|
if (held.current?.link !== link) {
|
|
4422
4496
|
const live = {
|
|
@@ -4434,7 +4508,7 @@ function useSaleDisplay(link, sale, options) {
|
|
|
4434
4508
|
}
|
|
4435
4509
|
held.current.publisher.update({ order: sale.order, stage: sale.stage });
|
|
4436
4510
|
}, [link, sale.order, sale.stage]);
|
|
4437
|
-
|
|
4511
|
+
useEffect7(() => () => {
|
|
4438
4512
|
held.current?.publisher.close();
|
|
4439
4513
|
held.current = null;
|
|
4440
4514
|
}, [link]);
|
|
@@ -4844,7 +4918,7 @@ function createDisplayClient(options) {
|
|
|
4844
4918
|
|
|
4845
4919
|
// src/customer-display/use-display-client.ts
|
|
4846
4920
|
import { useCallback as useCallback3, useSyncExternalStore } from "react";
|
|
4847
|
-
var
|
|
4921
|
+
var STARTING2 = { phase: { phase: "starting" }, state: initialDisplayState };
|
|
4848
4922
|
var views = /* @__PURE__ */ new WeakMap();
|
|
4849
4923
|
var noSubscription = () => () => {
|
|
4850
4924
|
};
|
|
@@ -4857,7 +4931,7 @@ function viewOf(client) {
|
|
|
4857
4931
|
}
|
|
4858
4932
|
function useDisplayClient(client) {
|
|
4859
4933
|
const subscribe = useCallback3((listener) => client ? client.onChange(listener) : noSubscription(), [client]);
|
|
4860
|
-
const getSnapshot = useCallback3(() => client ? viewOf(client) :
|
|
4934
|
+
const getSnapshot = useCallback3(() => client ? viewOf(client) : STARTING2, [client]);
|
|
4861
4935
|
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
4862
4936
|
}
|
|
4863
4937
|
|
|
@@ -5685,7 +5759,7 @@ function createScanSession(options) {
|
|
|
5685
5759
|
}
|
|
5686
5760
|
|
|
5687
5761
|
// src/scanner/use-barcode-scanner.ts
|
|
5688
|
-
import { useEffect as
|
|
5762
|
+
import { useEffect as useEffect9, useRef as useRef5 } from "react";
|
|
5689
5763
|
import { merge, Subject as Subject2 } from "rxjs";
|
|
5690
5764
|
|
|
5691
5765
|
// src/scanner/scan-dedup.ts
|
|
@@ -5717,7 +5791,7 @@ function scanTimeOf(event) {
|
|
|
5717
5791
|
}
|
|
5718
5792
|
|
|
5719
5793
|
// src/scanner/scan-hub-context.tsx
|
|
5720
|
-
import { createContext as createContext3, useCallback as useCallback5, useContext as useContext3, useEffect as
|
|
5794
|
+
import { createContext as createContext3, useCallback as useCallback5, useContext as useContext3, useEffect as useEffect8, useMemo as useMemo5, useRef as useRef4, useState as useState7, useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
5721
5795
|
|
|
5722
5796
|
// src/scanner/chooser-cancel.ts
|
|
5723
5797
|
function isChooserCancel(error) {
|
|
@@ -6225,7 +6299,7 @@ function useDeviceScanControl(scanner) {
|
|
|
6225
6299
|
);
|
|
6226
6300
|
const getState = useCallback5(() => scanner ? scanner.getState() : DISCONNECTED, [scanner]);
|
|
6227
6301
|
const state = useSyncExternalStore3(subscribe, getState, getState);
|
|
6228
|
-
return
|
|
6302
|
+
return useMemo5(
|
|
6229
6303
|
() => scanner ? {
|
|
6230
6304
|
available: scanner.available,
|
|
6231
6305
|
connect: scanner.connect,
|
|
@@ -6239,9 +6313,9 @@ function useDeviceScanControl(scanner) {
|
|
|
6239
6313
|
function ScanHubProvider({ children, ...props }) {
|
|
6240
6314
|
const latest = useRef4(props);
|
|
6241
6315
|
latest.current = props;
|
|
6242
|
-
const [hub] =
|
|
6243
|
-
const [controllers, setControllers] =
|
|
6244
|
-
|
|
6316
|
+
const [hub] = useState7(() => createScanHub());
|
|
6317
|
+
const [controllers, setControllers] = useState7(null);
|
|
6318
|
+
useEffect8(() => {
|
|
6245
6319
|
const nav2 = browserNavigator();
|
|
6246
6320
|
const shared = {
|
|
6247
6321
|
profiles: {
|
|
@@ -6266,7 +6340,7 @@ function ScanHubProvider({ children, ...props }) {
|
|
|
6266
6340
|
}, [hub]);
|
|
6267
6341
|
const serial = useDeviceScanControl(controllers?.serial ?? null);
|
|
6268
6342
|
const hid = useDeviceScanControl(controllers?.hid ?? null);
|
|
6269
|
-
const controls =
|
|
6343
|
+
const controls = useMemo5(() => ({ serial, hid }), [serial, hid]);
|
|
6270
6344
|
return /* @__PURE__ */ jsx3(ScanHubContext.Provider, { value: hub, children: /* @__PURE__ */ jsx3(DeviceScanControlsContext.Provider, { value: controls, children }) });
|
|
6271
6345
|
}
|
|
6272
6346
|
function useScanHub() {
|
|
@@ -6282,7 +6356,7 @@ function useBarcodeScanner(options) {
|
|
|
6282
6356
|
latest.current = options;
|
|
6283
6357
|
const enabled = options.enabled ?? true;
|
|
6284
6358
|
const hub = useScanHub();
|
|
6285
|
-
|
|
6359
|
+
useEffect9(() => {
|
|
6286
6360
|
if (!enabled) return;
|
|
6287
6361
|
const wedge$ = new Subject2();
|
|
6288
6362
|
const subscription = merge(wedge$, hub.events$).pipe(dedupeScans(SCAN_DEDUP_WINDOW_MS, scanTimeOf)).subscribe((event) => {
|
|
@@ -6485,15 +6559,15 @@ var CAMERA_CONSTRAINTS = {
|
|
|
6485
6559
|
};
|
|
6486
6560
|
|
|
6487
6561
|
// src/scanner/use-camera-scan.ts
|
|
6488
|
-
import { useMemo as
|
|
6562
|
+
import { useMemo as useMemo6, useRef as useRef6, useState as useState8 } from "react";
|
|
6489
6563
|
function useCameraScan(options = {}) {
|
|
6490
6564
|
const latest = useRef6(options);
|
|
6491
6565
|
latest.current = options;
|
|
6492
6566
|
const hub = useScanHub();
|
|
6493
6567
|
const hubRef = useRef6(hub);
|
|
6494
6568
|
hubRef.current = hub;
|
|
6495
|
-
const [scanCount, setScanCount] =
|
|
6496
|
-
const [session] =
|
|
6569
|
+
const [scanCount, setScanCount] = useState8(0);
|
|
6570
|
+
const [session] = useState8(() => createScanSession({
|
|
6497
6571
|
continuous: true,
|
|
6498
6572
|
now: () => (latest.current.now ?? Date.now)(),
|
|
6499
6573
|
onAccept: (code, symbology) => {
|
|
@@ -6501,7 +6575,7 @@ function useCameraScan(options = {}) {
|
|
|
6501
6575
|
setScanCount((count) => count + 1);
|
|
6502
6576
|
}
|
|
6503
6577
|
}));
|
|
6504
|
-
return
|
|
6578
|
+
return useMemo6(() => ({
|
|
6505
6579
|
offer: (code, symbology) => {
|
|
6506
6580
|
const { active = true, minChars = DEFAULT_MIN_SCAN_CHARS, onTooShort } = latest.current;
|
|
6507
6581
|
if (!active) return;
|
|
@@ -7088,7 +7162,7 @@ function createEscPosTransport({ sink, profile, format: format2 }) {
|
|
|
7088
7162
|
try {
|
|
7089
7163
|
await sink.write(bytes);
|
|
7090
7164
|
} catch (error) {
|
|
7091
|
-
throw
|
|
7165
|
+
throw toPrintError(error);
|
|
7092
7166
|
}
|
|
7093
7167
|
}
|
|
7094
7168
|
};
|
|
@@ -7184,6 +7258,104 @@ function networkSinkFor(profile, options = {}) {
|
|
|
7184
7258
|
return null;
|
|
7185
7259
|
}
|
|
7186
7260
|
|
|
7261
|
+
// src/print/escpos/usb-sink.ts
|
|
7262
|
+
var USB_CHUNK_SIZE = 4096;
|
|
7263
|
+
var USB_PRINTER_CLASS = 7;
|
|
7264
|
+
function bulkOut(device) {
|
|
7265
|
+
const candidates = (device.configuration?.interfaces ?? []).flatMap((usbInterface) => {
|
|
7266
|
+
const endpoint = usbInterface.alternate.endpoints.find(({ direction, type }) => direction === "out" && type === "bulk");
|
|
7267
|
+
return endpoint ? [{ usbInterface, endpointNumber: endpoint.endpointNumber }] : [];
|
|
7268
|
+
});
|
|
7269
|
+
return candidates.find(({ usbInterface }) => usbInterface.alternate.interfaceClass === USB_PRINTER_CLASS) ?? candidates[0] ?? null;
|
|
7270
|
+
}
|
|
7271
|
+
function createWebUsbSink({ device, chunkSize = USB_CHUNK_SIZE }) {
|
|
7272
|
+
if (!Number.isInteger(chunkSize) || chunkSize < 1) throw new RangeError(`chunkSize must be a positive integer, not ${chunkSize}`);
|
|
7273
|
+
const name = () => device.productName || "USB printer";
|
|
7274
|
+
async function step(label, run) {
|
|
7275
|
+
try {
|
|
7276
|
+
return await run();
|
|
7277
|
+
} catch (error) {
|
|
7278
|
+
throw new PrintError("failed", `${name()}: ${label} failed: ${error instanceof Error ? error.message : error}`, { cause: error });
|
|
7279
|
+
}
|
|
7280
|
+
}
|
|
7281
|
+
return {
|
|
7282
|
+
async write(bytes) {
|
|
7283
|
+
if (!device.opened) await step("open", () => device.open());
|
|
7284
|
+
if (device.configuration == null) await step("selectConfiguration(1)", () => device.selectConfiguration(1));
|
|
7285
|
+
const target = bulkOut(device);
|
|
7286
|
+
if (!target) throw new PrintError("unsupported", `${name()} has no bulk OUT endpoint to print to`);
|
|
7287
|
+
const { usbInterface: { interfaceNumber, claimed }, endpointNumber } = target;
|
|
7288
|
+
if (!claimed) await step(`claimInterface(${interfaceNumber})`, () => device.claimInterface(interfaceNumber));
|
|
7289
|
+
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
7290
|
+
const chunk = bytes.slice(i, i + chunkSize);
|
|
7291
|
+
const result = await step(`transferOut(${endpointNumber})`, () => device.transferOut(endpointNumber, chunk));
|
|
7292
|
+
if (result.status === "ok") continue;
|
|
7293
|
+
if (result.status === "stall") await device.clearHalt("out", endpointNumber).catch(() => void 0);
|
|
7294
|
+
throw new PrintError("failed", `${name()}: transferOut(${endpointNumber}) ended with status ${result.status}`);
|
|
7295
|
+
}
|
|
7296
|
+
}
|
|
7297
|
+
};
|
|
7298
|
+
}
|
|
7299
|
+
|
|
7300
|
+
// src/print/escpos/bluetooth-sink.ts
|
|
7301
|
+
var PRINT_PROFILES = [
|
|
7302
|
+
["000018f0-0000-1000-8000-00805f9b34fb", "00002af1-0000-1000-8000-00805f9b34fb"],
|
|
7303
|
+
["0000ff00-0000-1000-8000-00805f9b34fb", "0000ff02-0000-1000-8000-00805f9b34fb"],
|
|
7304
|
+
["49535343-fe7d-4ae5-8fa9-9fafd205e455", "49535343-8841-43f4-a8d4-ecbe34729bb3"],
|
|
7305
|
+
["e7810a71-73ae-499d-8c15-faa9aef0c3f2", "bef8d6c9-9c21-4c9e-b632-bd58c1009f9f"]
|
|
7306
|
+
];
|
|
7307
|
+
var BLUETOOTH_PRINT_SERVICES = PRINT_PROFILES.map(([service]) => service);
|
|
7308
|
+
var BLE_CHUNK_SIZE = 20;
|
|
7309
|
+
var BLE_CHUNK_PAUSE_MS = 20;
|
|
7310
|
+
var BLE_SETTLE_MS = 300;
|
|
7311
|
+
var pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
7312
|
+
async function printCharacteristic(gatt) {
|
|
7313
|
+
for (const [service, characteristic] of PRINT_PROFILES) {
|
|
7314
|
+
try {
|
|
7315
|
+
const found = await (await gatt.getPrimaryService(service)).getCharacteristic(characteristic);
|
|
7316
|
+
if (found.properties.write) return found;
|
|
7317
|
+
} catch {
|
|
7318
|
+
}
|
|
7319
|
+
}
|
|
7320
|
+
return null;
|
|
7321
|
+
}
|
|
7322
|
+
function createWebBluetoothSink({ device, chunkSize = BLE_CHUNK_SIZE }) {
|
|
7323
|
+
if (!Number.isInteger(chunkSize) || chunkSize < 1) throw new RangeError(`chunkSize must be a positive integer, not ${chunkSize}`);
|
|
7324
|
+
const name = () => device.name || "Bluetooth printer";
|
|
7325
|
+
async function step(label, run) {
|
|
7326
|
+
try {
|
|
7327
|
+
return await run();
|
|
7328
|
+
} catch (error) {
|
|
7329
|
+
throw new PrintError("failed", `${name()}: ${label} failed: ${error instanceof Error ? error.message : error}`, { cause: error });
|
|
7330
|
+
}
|
|
7331
|
+
}
|
|
7332
|
+
return {
|
|
7333
|
+
async write(bytes) {
|
|
7334
|
+
const { gatt } = device;
|
|
7335
|
+
if (!gatt) throw new PrintError("unsupported", `${name()} has no GATT server to print to`);
|
|
7336
|
+
if (!gatt.connected) await step("connect", () => gatt.connect());
|
|
7337
|
+
const target = await printCharacteristic(gatt);
|
|
7338
|
+
if (!target && !gatt.connected) {
|
|
7339
|
+
throw new PrintError("failed", `${name()}: the link dropped while finding the print service; nothing was written`);
|
|
7340
|
+
}
|
|
7341
|
+
if (!target) {
|
|
7342
|
+
throw new PrintError("unsupported", `${name()}: no known print service was found; nothing was written; is BLUETOOTH_PRINT_SERVICES in optionalServices?`);
|
|
7343
|
+
}
|
|
7344
|
+
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
7345
|
+
const chunk = bytes.slice(i, i + chunkSize);
|
|
7346
|
+
const last = i + chunkSize >= bytes.length;
|
|
7347
|
+
const chunkLabel = `chunk ${i / chunkSize + 1}`;
|
|
7348
|
+
if (last || !target.properties.writeWithoutResponse) {
|
|
7349
|
+
await step(`writeValueWithResponse (${chunkLabel})`, () => target.writeValueWithResponse(chunk));
|
|
7350
|
+
} else {
|
|
7351
|
+
await step(`writeValueWithoutResponse (${chunkLabel})`, () => target.writeValueWithoutResponse(chunk));
|
|
7352
|
+
}
|
|
7353
|
+
await pause(last ? BLE_SETTLE_MS : BLE_CHUNK_PAUSE_MS);
|
|
7354
|
+
}
|
|
7355
|
+
}
|
|
7356
|
+
};
|
|
7357
|
+
}
|
|
7358
|
+
|
|
7187
7359
|
// src/print/escpos/drawer.ts
|
|
7188
7360
|
function canOpenDrawer(profile) {
|
|
7189
7361
|
if (!profile || profile.connectionType === "system") return false;
|
|
@@ -7353,7 +7525,7 @@ var extractText = (nodes) => nodes.map((node) => node.type === "raw-text" ? node
|
|
|
7353
7525
|
var hasDrawer = (nodes) => nodes.some((node) => node.type === "drawer" || "children" in node && hasDrawer(node.children));
|
|
7354
7526
|
|
|
7355
7527
|
// src/sale/use-sale.ts
|
|
7356
|
-
import { useEffect as
|
|
7528
|
+
import { useEffect as useEffect11, useLayoutEffect, useMemo as useMemo8, useRef as useRef8, useState as useState10 } from "react";
|
|
7357
7529
|
import { ORDER_META_KEY_MAX as ORDER_META_KEY_MAX3, ORDER_META_MAX as ORDER_META_MAX2, paymentMethodOf as paymentMethodOf2 } from "@tallyui/core";
|
|
7358
7530
|
|
|
7359
7531
|
// src/tender/split-units.ts
|
|
@@ -7807,7 +7979,8 @@ function finalizeOrder(order, options = {}) {
|
|
|
7807
7979
|
amountMinor: payment.amountMinor,
|
|
7808
7980
|
...payment.tenderedMinor !== void 0 ? { tenderedMinor: payment.tenderedMinor } : {},
|
|
7809
7981
|
...payment.changeMinor !== void 0 ? { changeMinor: payment.changeMinor } : {},
|
|
7810
|
-
...payment.reference !== void 0 ? { reference: payment.reference } : {}
|
|
7982
|
+
...payment.reference !== void 0 ? { reference: payment.reference } : {},
|
|
7983
|
+
...isTakenAt(payment.takenAt) ? { takenAt: payment.takenAt } : {}
|
|
7811
7984
|
}));
|
|
7812
7985
|
const localWarnings = options.localWarnings?.flatMap((warning) => {
|
|
7813
7986
|
if (warning.code !== "payment_reference_dropped") return [{ ...warning }];
|
|
@@ -7944,7 +8117,7 @@ var orderAddressSchema = { type: "object", additionalProperties: false, properti
|
|
|
7944
8117
|
phone: { type: "string" }
|
|
7945
8118
|
} };
|
|
7946
8119
|
var posOrderSchema = {
|
|
7947
|
-
version:
|
|
8120
|
+
version: 20,
|
|
7948
8121
|
primaryKey: "id",
|
|
7949
8122
|
type: "object",
|
|
7950
8123
|
additionalProperties: false,
|
|
@@ -8070,7 +8243,8 @@ var posOrderSchema = {
|
|
|
8070
8243
|
amountMinor: { type: "integer" },
|
|
8071
8244
|
tenderedMinor: { type: "integer" },
|
|
8072
8245
|
changeMinor: { type: "integer" },
|
|
8073
|
-
reference: { type: "string" }
|
|
8246
|
+
reference: { type: "string" },
|
|
8247
|
+
takenAt: { type: "string", maxLength: 40 }
|
|
8074
8248
|
},
|
|
8075
8249
|
required: ["id", "method", "amountMinor"]
|
|
8076
8250
|
} },
|
|
@@ -8204,7 +8378,7 @@ function posOrderCollection() {
|
|
|
8204
8378
|
};
|
|
8205
8379
|
return {
|
|
8206
8380
|
schema: posOrderSchema,
|
|
8207
|
-
migrationStrategies: { 1: identity2, 2: identity2, 3: identity2, 4: identity2, 5: recordSent, 6: recordRounding, 7: identity2, 8: identity2, 9: identity2, 10: identity2, 11: identity2, 12: identity2, 13: identity2, 14: identity2, 15: identity2, 16: identity2, 17: identity2, 18: identity2, 19: identity2 }
|
|
8381
|
+
migrationStrategies: { 1: identity2, 2: identity2, 3: identity2, 4: identity2, 5: recordSent, 6: recordRounding, 7: identity2, 8: identity2, 9: identity2, 10: identity2, 11: identity2, 12: identity2, 13: identity2, 14: identity2, 15: identity2, 16: identity2, 17: identity2, 18: identity2, 19: identity2, 20: identity2 }
|
|
8208
8382
|
};
|
|
8209
8383
|
}
|
|
8210
8384
|
|
|
@@ -9382,7 +9556,8 @@ async function reopenRefusedOrder(orderId, deps, options) {
|
|
|
9382
9556
|
amountMinor: payment.amountMinor,
|
|
9383
9557
|
reopened: true,
|
|
9384
9558
|
...payment.reference !== void 0 ? { reference: payment.reference } : {},
|
|
9385
|
-
...payment.methodId !== void 0 ? { methodId: payment.methodId } : {}
|
|
9559
|
+
...payment.methodId !== void 0 ? { methodId: payment.methodId } : {},
|
|
9560
|
+
...isTakenAt(payment.takenAt) ? { takenAt: payment.takenAt } : {}
|
|
9386
9561
|
});
|
|
9387
9562
|
if (order.customer?.id && order.customer.name && customerRefusal(order.customer) === null) {
|
|
9388
9563
|
builder.setCustomer({
|
|
@@ -10113,7 +10288,7 @@ function buildXReportDocument(session, context) {
|
|
|
10113
10288
|
}
|
|
10114
10289
|
|
|
10115
10290
|
// src/register/use-register-session.ts
|
|
10116
|
-
import { useEffect as
|
|
10291
|
+
import { useEffect as useEffect10, useMemo as useMemo7, useRef as useRef7, useState as useState9, useSyncExternalStore as useSyncExternalStore4 } from "react";
|
|
10117
10292
|
import { combineLatest, map as map7, of, switchMap } from "rxjs";
|
|
10118
10293
|
|
|
10119
10294
|
// src/outbox/register-outbox.ts
|
|
@@ -11447,7 +11622,7 @@ function useRegisterSession(options) {
|
|
|
11447
11622
|
const { commands, refunds } = options;
|
|
11448
11623
|
const varianceThreshold = options.capabilities?.registerApproval?.thresholdMinor ?? options.varianceThreshold;
|
|
11449
11624
|
const commandEnabled = (options.capabilities?.register ?? 0) >= 1;
|
|
11450
|
-
const commandTarget =
|
|
11625
|
+
const commandTarget = useMemo7(
|
|
11451
11626
|
() => enabled && commandEnabled && commands && sessions && movements && closures && register && registerId ? { commands, sessions, movements, closures, host: register, storeKey, registerId, registerContract: options.capabilities?.register, deviceName: options.deviceName } : null,
|
|
11452
11627
|
[enabled, commandEnabled, commands, sessions, movements, closures, register, storeKey, registerId, options.capabilities?.register, options.deviceName]
|
|
11453
11628
|
);
|
|
@@ -11463,15 +11638,15 @@ function useRegisterSession(options) {
|
|
|
11463
11638
|
}
|
|
11464
11639
|
});
|
|
11465
11640
|
};
|
|
11466
|
-
|
|
11467
|
-
|
|
11641
|
+
useEffect10(reconcile, [commandTarget]);
|
|
11642
|
+
useEffect10(() => {
|
|
11468
11643
|
if (!commandTarget) return;
|
|
11469
11644
|
const subscription = commandTarget.commands.find({ selector: { registerId: commandTarget.registerId } }).$.subscribe(() => {
|
|
11470
11645
|
void adoptRegisterResults(commandTarget);
|
|
11471
11646
|
});
|
|
11472
11647
|
return () => subscription.unsubscribe();
|
|
11473
11648
|
}, [commandTarget]);
|
|
11474
|
-
const source =
|
|
11649
|
+
const source = useMemo7(() => {
|
|
11475
11650
|
if (!enabled || !sessions || !movements || !closures || !orders || !registerId || !register || refunds === null) return null;
|
|
11476
11651
|
return combineLatest([
|
|
11477
11652
|
watchFresh(sessions, { selector: { register_id: registerId } }),
|
|
@@ -11494,14 +11669,14 @@ function useRegisterSession(options) {
|
|
|
11494
11669
|
const tender = useRef7(tenderInProgress);
|
|
11495
11670
|
tender.current = tenderInProgress;
|
|
11496
11671
|
const closing = useSyncExternalStore4(subscribeClosing, () => closingByRegister.has(registerId ?? ""));
|
|
11497
|
-
const [observed, setObserved] =
|
|
11498
|
-
|
|
11672
|
+
const [observed, setObserved] = useState9(null);
|
|
11673
|
+
useEffect10(() => {
|
|
11499
11674
|
if (!source) return;
|
|
11500
11675
|
const subscription = source.subscribe((snapshot) => setObserved({ source, snapshot }));
|
|
11501
11676
|
return () => subscription.unsubscribe();
|
|
11502
11677
|
}, [source]);
|
|
11503
|
-
const [, setMinute] =
|
|
11504
|
-
|
|
11678
|
+
const [, setMinute] = useState9(0);
|
|
11679
|
+
useEffect10(() => {
|
|
11505
11680
|
if (!enabled || !expectedCloseTime) return;
|
|
11506
11681
|
const timer = setInterval(() => setMinute((value) => value + 1), 6e4);
|
|
11507
11682
|
return () => clearInterval(timer);
|
|
@@ -11533,7 +11708,7 @@ function useRegisterSession(options) {
|
|
|
11533
11708
|
return state.running = run;
|
|
11534
11709
|
};
|
|
11535
11710
|
const seen = useRef7(null);
|
|
11536
|
-
|
|
11711
|
+
useEffect10(() => {
|
|
11537
11712
|
if (!data) return;
|
|
11538
11713
|
const ids = data.closureRows.map((row) => row.id);
|
|
11539
11714
|
if (seen.current?.source !== source) {
|
|
@@ -11983,7 +12158,7 @@ function useSale(settings, opts) {
|
|
|
11983
12158
|
}
|
|
11984
12159
|
const defaultKey = opts.defaultCustomer ? JSON.stringify([opts.defaultCustomer.id, opts.defaultCustomer.name, opts.defaultCustomer.email]) : "";
|
|
11985
12160
|
const defaultSeen = useRef8(defaultKey);
|
|
11986
|
-
const [rendered, setBuilder] =
|
|
12161
|
+
const [rendered, setBuilder] = useState10(() => {
|
|
11987
12162
|
const customer = defaulted();
|
|
11988
12163
|
taxNow.current = contextFor(customer);
|
|
11989
12164
|
const first = createOrderBuilder({ currency: settings.currency, taxContext: taxNow.current.taxContext });
|
|
@@ -12000,18 +12175,18 @@ function useSale(settings, opts) {
|
|
|
12000
12175
|
function codesFor() {
|
|
12001
12176
|
return opts.capabilities?.coupons === true && (opts.capabilities?.orderCreate ?? 1) >= 6 && opts.discountCodes && opts.discountCodes.supports({ capabilities: opts.capabilities, rounding: taxContext.rounding }) ? opts.discountCodes : null;
|
|
12002
12177
|
}
|
|
12003
|
-
const [order, setOrder] =
|
|
12004
|
-
const [stage, setStage] =
|
|
12005
|
-
const [saleError, setError] =
|
|
12178
|
+
const [order, setOrder] = useState10(() => rendered.getSnapshot());
|
|
12179
|
+
const [stage, setStage] = useState10({ kind: "cart" });
|
|
12180
|
+
const [saleError, setError] = useState10(null);
|
|
12006
12181
|
const configError = referenceError("cashierRef", opts.cashierRef) ?? referenceError("registerId", opts.registerId);
|
|
12007
12182
|
const pending = useRef8(null);
|
|
12008
|
-
const [saving, setSaving] =
|
|
12183
|
+
const [saving, setSaving] = useState10(false);
|
|
12009
12184
|
const error = saving && saleError ? saleError : configError ?? saleError;
|
|
12010
12185
|
const tenderSession = useRef8(null);
|
|
12011
12186
|
const tenderGatePending = useRef8(false);
|
|
12012
12187
|
const droppedReferences = useRef8(/* @__PURE__ */ new Set());
|
|
12013
12188
|
const confirmed = useRef8(null);
|
|
12014
|
-
const [canContinue, setCanContinue] =
|
|
12189
|
+
const [canContinue, setCanContinue] = useState10(false);
|
|
12015
12190
|
const attempts = useRef8(0);
|
|
12016
12191
|
const hungSaveTimer = useRef8(null);
|
|
12017
12192
|
const checking = useRef8(null);
|
|
@@ -12049,7 +12224,7 @@ function useSale(settings, opts) {
|
|
|
12049
12224
|
return [...applied.current.values()].includes(KEPT);
|
|
12050
12225
|
}
|
|
12051
12226
|
const repricing = useRef8(null);
|
|
12052
|
-
const [couponsRepricing, setCouponsRepricing] =
|
|
12227
|
+
const [couponsRepricing, setCouponsRepricing] = useState10(false);
|
|
12053
12228
|
const generation = useRef8(0);
|
|
12054
12229
|
const saleEpoch = useRef8(0);
|
|
12055
12230
|
const stopped = useRef8(null);
|
|
@@ -12138,11 +12313,11 @@ function useSale(settings, opts) {
|
|
|
12138
12313
|
setStage(stageNow.current);
|
|
12139
12314
|
setError(null);
|
|
12140
12315
|
}
|
|
12141
|
-
|
|
12316
|
+
useEffect11(() => {
|
|
12142
12317
|
const subscription = rendered.order$.subscribe(setOrder);
|
|
12143
12318
|
return () => subscription.unsubscribe();
|
|
12144
12319
|
}, [rendered]);
|
|
12145
|
-
|
|
12320
|
+
useEffect11(() => {
|
|
12146
12321
|
if (order.couponPricesStale && applied.current.size > 0 && !repricing.current && stageNow.current.kind !== "receipt" && !busy() && !liveLeg() && stopped.current?.order !== order) void (appliedWith.current ? reprice() : dropKept());
|
|
12147
12322
|
});
|
|
12148
12323
|
function dropKept() {
|
|
@@ -12177,8 +12352,8 @@ function useSale(settings, opts) {
|
|
|
12177
12352
|
return true;
|
|
12178
12353
|
}
|
|
12179
12354
|
const liveCustomer = order.customer, taxContextFor = opts.taxContextFor;
|
|
12180
|
-
const taxLocation =
|
|
12181
|
-
|
|
12355
|
+
const taxLocation = useMemo8(() => taxContextFor ? { ...taxContextFor(liveCustomer).location, hasCustomer: liveCustomer !== null } : void 0, [liveCustomer, taxContextFor]);
|
|
12356
|
+
useEffect11(() => () => {
|
|
12182
12357
|
clearHungSaveTimer();
|
|
12183
12358
|
if (pending.current || inFlight2.current) {
|
|
12184
12359
|
saleLogger.error(
|
|
@@ -12187,18 +12362,20 @@ function useSale(settings, opts) {
|
|
|
12187
12362
|
);
|
|
12188
12363
|
}
|
|
12189
12364
|
}, []);
|
|
12190
|
-
function addOne(tender) {
|
|
12365
|
+
function addOne(tender, stamp2) {
|
|
12191
12366
|
const reason = referenceReason(tender.reference);
|
|
12192
12367
|
const dropped = reason && (reason === "nul" ? "it contains a NUL character" : `it is over ${PAYLOAD_STRING_MAX} characters`);
|
|
12368
|
+
const takenAt = stamp2 && legStatus({ status: tender.status }) === "captured" ? { takenAt: (/* @__PURE__ */ new Date()).toISOString() } : {};
|
|
12193
12369
|
const kept = dropped ? {
|
|
12194
12370
|
method: tender.method,
|
|
12195
12371
|
amountMinor: tender.amountMinor,
|
|
12372
|
+
...takenAt,
|
|
12196
12373
|
...tender.tenderedMinor !== void 0 ? { tenderedMinor: tender.tenderedMinor } : {},
|
|
12197
12374
|
...tender.changeMinor !== void 0 ? { changeMinor: tender.changeMinor } : {},
|
|
12198
12375
|
...tender.units !== void 0 ? { units: tender.units } : {},
|
|
12199
12376
|
...tender.methodId !== void 0 ? { methodId: tender.methodId } : {},
|
|
12200
12377
|
...tender.status !== void 0 ? { status: tender.status } : {}
|
|
12201
|
-
} : tender;
|
|
12378
|
+
} : { ...tender, ...takenAt };
|
|
12202
12379
|
const builder = builderNow.current;
|
|
12203
12380
|
const { units, ...payment } = kept;
|
|
12204
12381
|
const paymentId = builder.addPayment({ ...payment, ...units && Object.keys(units).length ? { units } : {} });
|
|
@@ -12226,7 +12403,7 @@ function useSale(settings, opts) {
|
|
|
12226
12403
|
for (const payment of builder.getSnapshot().payments) if (!heldLeg(payment)) builder.removePayment(payment.id);
|
|
12227
12404
|
droppedReferences.current.clear();
|
|
12228
12405
|
setError(null);
|
|
12229
|
-
if (tender) addOne(tender);
|
|
12406
|
+
if (tender) addOne(tender, false);
|
|
12230
12407
|
}
|
|
12231
12408
|
function clearStaleError() {
|
|
12232
12409
|
setError((current) => current?.startsWith(REFERENCE_DROPPED) ? current : null);
|
|
@@ -12705,10 +12882,10 @@ function useSale(settings, opts) {
|
|
|
12705
12882
|
const due = snapshot.balanceDueMinor - inMotionMinor(snapshot.payments);
|
|
12706
12883
|
if (due <= 0) return null;
|
|
12707
12884
|
clearStaleError();
|
|
12708
|
-
return addOne({ ...tender, amountMinor: Math.min(tender.amountMinor, due) });
|
|
12885
|
+
return addOne({ ...tender, amountMinor: Math.min(tender.amountMinor, due) }, true);
|
|
12709
12886
|
}
|
|
12710
12887
|
clearStaleError();
|
|
12711
|
-
return addOne({ ...tender, ...tender.tenderedMinor !== void 0 ? { changeMinor: tender.tenderedMinor - tender.amountMinor } : {} });
|
|
12888
|
+
return addOne({ ...tender, ...tender.tenderedMinor !== void 0 ? { changeMinor: tender.tenderedMinor - tender.amountMinor } : {} }, true);
|
|
12712
12889
|
},
|
|
12713
12890
|
setTenderStatus(paymentId, status) {
|
|
12714
12891
|
if (stageNow.current.kind === "receipt") {
|
|
@@ -12721,7 +12898,7 @@ function useSale(settings, opts) {
|
|
|
12721
12898
|
setError(AFTER_CLOSE_PAYMENTS_CHANGED);
|
|
12722
12899
|
return false;
|
|
12723
12900
|
}
|
|
12724
|
-
const changed = builderNow.current.setPaymentStatus(paymentId, status);
|
|
12901
|
+
const changed = builderNow.current.setPaymentStatus(paymentId, status, status === "captured" ? (/* @__PURE__ */ new Date()).toISOString() : void 0);
|
|
12725
12902
|
if (changed && status === "failed" && !liveLeg()) setError((current) => current === SALE_HAS_PAYMENT ? null : current);
|
|
12726
12903
|
return changed;
|
|
12727
12904
|
},
|
|
@@ -12796,7 +12973,8 @@ function useSale(settings, opts) {
|
|
|
12796
12973
|
setError(carriedCoupon() ? COUPON_CARRY_STALE : COUPONS_REPRICING);
|
|
12797
12974
|
return;
|
|
12798
12975
|
}
|
|
12799
|
-
const
|
|
12976
|
+
const completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
12977
|
+
const current = { ...snapshot, payments: snapshot.payments.filter(countsTowardPaid).map((payment) => payment.takenAt === void 0 && !payment.locked && !payment.reopened ? { ...payment, takenAt: completedAt } : payment) };
|
|
12800
12978
|
const localWarnings = current.payments.filter((payment) => droppedReferences.current.has(payment.id)).map((payment) => ({ code: "payment_reference_dropped", paymentId: payment.id }));
|
|
12801
12979
|
let posOrder;
|
|
12802
12980
|
try {
|
|
@@ -13442,15 +13620,15 @@ function createHttpCommandTransport(options) {
|
|
|
13442
13620
|
}
|
|
13443
13621
|
|
|
13444
13622
|
// src/outbox/use-register-outbox.ts
|
|
13445
|
-
import { useEffect as
|
|
13623
|
+
import { useEffect as useEffect12, useRef as useRef9, useState as useState11 } from "react";
|
|
13446
13624
|
var idle = { pending: 0, sending: false };
|
|
13447
13625
|
function useRegisterOutbox(options) {
|
|
13448
13626
|
const { commands, sessions, deviceId } = options;
|
|
13449
13627
|
const latest = useRef9(options);
|
|
13450
13628
|
latest.current = options;
|
|
13451
13629
|
const current = useRef9(null);
|
|
13452
|
-
const [state, setState] =
|
|
13453
|
-
|
|
13630
|
+
const [state, setState] = useState11(idle);
|
|
13631
|
+
useEffect12(() => {
|
|
13454
13632
|
setState(idle);
|
|
13455
13633
|
if (!commands) return;
|
|
13456
13634
|
const outbox = createRegisterOutbox({
|
|
@@ -13489,7 +13667,7 @@ function useRegisterOutbox(options) {
|
|
|
13489
13667
|
}
|
|
13490
13668
|
|
|
13491
13669
|
// src/outbox/use-order-outbox.ts
|
|
13492
|
-
import { useEffect as
|
|
13670
|
+
import { useEffect as useEffect13, useMemo as useMemo9, useRef as useRef10, useState as useState12 } from "react";
|
|
13493
13671
|
var idle2 = { pending: 0, sending: false };
|
|
13494
13672
|
var noneStuck = [];
|
|
13495
13673
|
function useOrderOutbox(options) {
|
|
@@ -13499,12 +13677,12 @@ function useOrderOutbox(options) {
|
|
|
13499
13677
|
const current = useRef10(null);
|
|
13500
13678
|
const openingError = useRef10(null);
|
|
13501
13679
|
const loggedMismatches = useRef10(/* @__PURE__ */ new Set());
|
|
13502
|
-
const [orders, setOrders] =
|
|
13503
|
-
const [state, setState] =
|
|
13504
|
-
const [recent, setRecent] =
|
|
13680
|
+
const [orders, setOrders] = useState12(null);
|
|
13681
|
+
const [state, setState] = useState12(idle2);
|
|
13682
|
+
const [recent, setRecent] = useState12([]);
|
|
13505
13683
|
const savesInFlight = useRef10(0);
|
|
13506
|
-
const [savesInFlightCount, setSavesInFlightCount] =
|
|
13507
|
-
|
|
13684
|
+
const [savesInFlightCount, setSavesInFlightCount] = useState12(0);
|
|
13685
|
+
useEffect13(() => {
|
|
13508
13686
|
let active = true;
|
|
13509
13687
|
let dispose;
|
|
13510
13688
|
openingError.current = null;
|
|
@@ -13547,13 +13725,13 @@ function useOrderOutbox(options) {
|
|
|
13547
13725
|
dispose?.();
|
|
13548
13726
|
};
|
|
13549
13727
|
}, [storeKey, deviceId]);
|
|
13550
|
-
|
|
13728
|
+
useEffect13(() => {
|
|
13551
13729
|
latest.current.onBusy?.(state.sending);
|
|
13552
13730
|
return () => latest.current.onBusy?.(false);
|
|
13553
13731
|
}, [state.sending]);
|
|
13554
13732
|
const ready = current.current?.storeKey === storeKey && !!storeKey;
|
|
13555
13733
|
const stuckKey = ready ? state.stuck?.commandIds.join(",") ?? "" : "";
|
|
13556
|
-
const stuckCommandIds =
|
|
13734
|
+
const stuckCommandIds = useMemo9(() => stuckKey ? stuckKey.split(",") : noneStuck, [stuckKey]);
|
|
13557
13735
|
return {
|
|
13558
13736
|
orders: ready ? orders : null,
|
|
13559
13737
|
state: ready ? state : idle2,
|
|
@@ -13634,10 +13812,10 @@ function watchOutboxHealth(sales$, tillUpdates$) {
|
|
|
13634
13812
|
}
|
|
13635
13813
|
|
|
13636
13814
|
// src/outbox/use-outbox-health.ts
|
|
13637
|
-
import { useMemo as
|
|
13815
|
+
import { useMemo as useMemo10 } from "react";
|
|
13638
13816
|
function useOutboxHealth(options) {
|
|
13639
13817
|
const { sales, tillUpdates } = options;
|
|
13640
|
-
const health =
|
|
13818
|
+
const health = useMemo10(() => summarizeOutboxHealth(sales.state, tillUpdates.state), [sales.state, tillUpdates.state]);
|
|
13641
13819
|
return { health, async flush() {
|
|
13642
13820
|
await Promise.all([sales.flush(), tillUpdates.flush()]);
|
|
13643
13821
|
} };
|
|
@@ -14629,6 +14807,7 @@ export {
|
|
|
14629
14807
|
ADDRESS_CHANGE_REFUSED,
|
|
14630
14808
|
AFTER_CLOSE_PAYMENTS_CHANGED,
|
|
14631
14809
|
APP_SETTING_DEFINITIONS,
|
|
14810
|
+
BLUETOOTH_PRINT_SERVICES,
|
|
14632
14811
|
CAMERA_BARCODE_TYPES,
|
|
14633
14812
|
CAMERA_CONSTRAINTS,
|
|
14634
14813
|
CART_COLUMN_IDS,
|
|
@@ -14828,6 +15007,8 @@ export {
|
|
|
14828
15007
|
createTillDisplayService,
|
|
14829
15008
|
createTillPairing,
|
|
14830
15009
|
createTillPeerLink,
|
|
15010
|
+
createWebBluetoothSink,
|
|
15011
|
+
createWebUsbSink,
|
|
14831
15012
|
createWedgeDetector,
|
|
14832
15013
|
createWedgeState,
|
|
14833
15014
|
csvCell,
|
|
@@ -15042,6 +15223,7 @@ export {
|
|
|
15042
15223
|
taxMicros,
|
|
15043
15224
|
taxProviderProps,
|
|
15044
15225
|
taxSettingsForLocation,
|
|
15226
|
+
taxedLinesFor,
|
|
15045
15227
|
templateColumns,
|
|
15046
15228
|
tenderFigures,
|
|
15047
15229
|
tenderReducer,
|
|
@@ -15076,6 +15258,7 @@ export {
|
|
|
15076
15258
|
useSale,
|
|
15077
15259
|
useSaleDisplay,
|
|
15078
15260
|
useScanHub,
|
|
15261
|
+
useStoreOrdersInRange,
|
|
15079
15262
|
useStoreSettings,
|
|
15080
15263
|
useTax,
|
|
15081
15264
|
useTillDisplays,
|