@ancon/wildcat-utils 1.50.10 → 1.50.12

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.
@@ -1,2 +1,9 @@
1
- import { CheckoutDetailsV2 } from '@ancon/wildcat-types';
2
- export default function isGiftCardCheckout(checkout: CheckoutDetailsV2 | undefined | null): boolean;
1
+ import { AttendeeWithItems, CheckoutItem, NonEmptyArray, OrderFormat } from '@ancon/wildcat-types';
2
+ declare type Checkout = {
3
+ orderFormat: OrderFormat;
4
+ /** Checkout summary includes items */
5
+ items?: CheckoutItem[];
6
+ attendees?: NonEmptyArray<AttendeeWithItems>;
7
+ };
8
+ export default function isGiftCardCheckout<T extends Checkout>(checkout: T | null | undefined): boolean;
9
+ export {};
@@ -1 +1 @@
1
- "use strict";const s=require("@ancon/wildcat-types"),i=require("./isGiftCardCheckoutItem.js");function m(e){var t,r;return!e||e.orderFormat!==s.OrderFormat.System?!1:(e.items??((r=(t=e.attendees)==null?void 0:t[0])==null?void 0:r.items)??[]).some(i)}module.exports=m;
1
+ "use strict";const c=require("@ancon/wildcat-types"),u=require("./isGiftCardCheckoutItem.js");function m(e){var r;if(e){const{orderFormat:s,items:o,attendees:t}=e,i=o??((r=t==null?void 0:t[0])==null?void 0:r.items)??[];return s===c.OrderFormat.System&&i.some(u)}return!1}module.exports=m;
@@ -1,9 +1,17 @@
1
- import { OrderFormat as i } from "@ancon/wildcat-types";
2
- import m from "./isGiftCardCheckoutItem.mjs";
3
- function a(t) {
4
- var r, e;
5
- return !t || t.orderFormat !== i.System ? !1 : (t.items ?? ((e = (r = t.attendees) == null ? void 0 : r[0]) == null ? void 0 : e.items) ?? []).some(m);
1
+ import { OrderFormat as s } from "@ancon/wildcat-types";
2
+ import f from "./isGiftCardCheckoutItem.mjs";
3
+ function c(r) {
4
+ var o;
5
+ if (r) {
6
+ const { orderFormat: e, items: m, attendees: t } = r, i = m ?? ((o = t == null ? void 0 : t[0]) == null ? void 0 : o.items) ?? [];
7
+ return (
8
+ // Must be system order format
9
+ e === s.System && // Must have gift card item
10
+ i.some(f)
11
+ );
12
+ }
13
+ return !1;
6
14
  }
7
15
  export {
8
- a as default
16
+ c as default
9
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.50.10",
3
+ "version": "1.50.12",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -9,7 +9,20 @@ declare type ReduxHooksArg<RootState = unknown> = {
9
9
  };
10
10
  useStarPrinterDiscover: () => (timeout: number) => Promise<DiscoveredStarPrinter[]>;
11
11
  };
12
- declare function createUseStarCloudScanHook<RootState = unknown>(initialStatus: StarCloudScanStatus, hooks: ReduxHooksArg<RootState>, selectors: ReduxSelectorsArg<RootState>, initialReading?: string, shouldSanitizeRawOutput?: boolean): () => {
12
+ export declare type SanitizeRawOutputOptions = {
13
+ /** Enable or disable sanitization of raw output */
14
+ sanitizeEnabled: boolean;
15
+ /**
16
+ * Custom regex to sanitize raw output. Default removes all non-digit characters.
17
+ * @default /[\D]/gi
18
+ */
19
+ sanitizeRegex?: RegExp;
20
+ };
21
+ declare function createUseStarCloudScanHook<RootState = unknown>(initialStatus: StarCloudScanStatus, hooks: ReduxHooksArg<RootState>, selectors: ReduxSelectorsArg<RootState>, initialReading?: string,
22
+ /**
23
+ * @deprecated Use `sanitizeRawOutputOptions` instead
24
+ */
25
+ shouldSanitizeRawOutput?: boolean, sanitizeRawOutputOptions?: SanitizeRawOutputOptions): () => {
13
26
  startScan: () => Promise<void>;
14
27
  changeDeviceStatus: (nextStatus: StarCloudScanStatus) => void;
15
28
  scanStatus: StarCloudScanStatus;
@@ -1 +1 @@
1
- "use strict";const o=require("react"),k=require("dayjs"),R=require("@ancon/wildcat-printing"),j=require("../shared/hooks/usePrevious.js"),G=require("../shared/hooks/useMountedRef.js"),e=require("./types.js"),I=["TSP654"],V=1;function z(b,q,L,O,T=!1){const{useAppStore:N,useStarPrinterDiscover:_}=q,{selectedClientPrinterSelector:F}=L;function M(){const n=G(),v=N(),D=_(),f=o.useRef(void 0),[s,x]=o.useState(b),[a,l]=o.useState(),[S,P]=o.useState(),g=j(S),[A,p]=o.useState(),[U,w]=o.useState(O),r=o.useCallback(c=>{n!=null&&n.current&&x(c)},[n]),y=o.useCallback(async c=>{var i;(i=f.current)==null||i.stop(),r(e.StarCloudScanStatus.ScanningComplete);const u=String.fromCharCode(...c).trim();w(T?u.replace(/[\D]/gi,""):u)},[r]),h=o.useCallback(async({macAddress:c,ipAddress:u})=>{function i(t){r(e.StarCloudScanStatus.CommunicationError),n!=null&&n.current&&p(t==null?void 0:t.message)}const C={onStarted:t=>{if(t&&t.inputDevicesCount>0){const{inputDevicesCount:d}=t;r(e.StarCloudScanStatus.ReadyToScan),l({inputDeviceCount:d,lastConnectedOn:new Date})}},onStopped:t=>{t&&i(t),l(void 0)},inputDevice:{onConnected:()=>{const t=((a==null?void 0:a.inputDeviceCount)||0)+1;r(t>0?e.StarCloudScanStatus.ReadyToScan:e.StarCloudScanStatus.PrinterDetected),l({inputDeviceCount:t,lastConnectedOn:new Date})},onDisconnected:()=>{const t=((a==null?void 0:a.inputDeviceCount)||0)-1>=0?((a==null?void 0:a.inputDeviceCount)||0)-1:0;r(t>0?e.StarCloudScanStatus.ReadyToScan:e.StarCloudScanStatus.PrinterDetected),l({inputDeviceCount:t})},onCommunicationError:i,onDataReceived:t=>P({data:t,lastReceivedOn:new Date})}};if(f.current=R.monitor(u||c,C),n!=null&&n.current)try{await f.current.start()}catch(t){r(e.StarCloudScanStatus.CommunicationError),n!=null&&n.current&&p(t==null?void 0:t.message)}},[a,r,n]),m=o.useCallback(async()=>{n!=null&&n.current&&(r(e.StarCloudScanStatus.WaitingForPrinter),p(void 0),P(void 0),l(void 0),w(void 0));const c=F(v.getState()),{macAddress:u,serialNumber:i}=c;try{const t=(await D(2e3)).find(d=>u&&d.macAddress.toLowerCase()===u.toLowerCase()||i&&d.serialNumber===i);if(n!=null&&n.current){if(t){if(I.some(d=>{var E;return(E=t.model)==null?void 0:E.toLowerCase().includes(d.toLowerCase())})){r(e.StarCloudScanStatus.UnsupportedPrinter);return}h(t)}r(t?e.StarCloudScanStatus.PrinterDetected:e.StarCloudScanStatus.PrinterNotDetected)}}catch{n!=null&&n.current&&r(e.StarCloudScanStatus.PrinterNotDetected)}},[n,v,r,D,h]),W=s===e.StarCloudScanStatus.WaitingForPrinter||s===e.StarCloudScanStatus.PrinterDetected||s===e.StarCloudScanStatus.ReadyToScan||s===e.StarCloudScanStatus.ScanningComplete,H=s===e.StarCloudScanStatus.PrinterNotDetected||s===e.StarCloudScanStatus.ScanFailed||s===e.StarCloudScanStatus.CommunicationError||s===e.StarCloudScanStatus.UnsupportedPrinter;return o.useEffect(()=>{if(!g&&(S==null?void 0:S.data)&&a&&(a!=null&&a.lastConnectedOn)){const{lastConnectedOn:u}=a,{lastReceivedOn:i,data:C}=S;k(i).diff(k(u),"second",!0)>V?y(C):P(void 0)}},[S,g,a,y]),o.useEffect(()=>(s===e.StarCloudScanStatus.WaitingForPrinter&&m(),()=>{var c;(c=f.current)==null||c.stop()}),[]),{startScan:m,changeDeviceStatus:r,scanStatus:s,reading:U,connectionError:A,isLoading:W,isError:H}}return M}module.exports=z;
1
+ "use strict";const o=require("react"),L=require("dayjs"),B=require("@ancon/wildcat-printing"),J=require("../shared/hooks/usePrevious.js"),K=require("../shared/hooks/useMountedRef.js"),n=require("./types.js"),Q=["TSP654"],V=1;function X(T,p,x,N,_=!1,d){const{useAppStore:F,useStarPrinterDiscover:M}=p,{selectedClientPrinterSelector:w}=x;function A(){const e=K(),D=F(),h=M(),P=o.useRef(void 0),[i,U]=o.useState(T),[r,f]=o.useState(),[l,v]=o.useState(),y=J(l),[W,g]=o.useState(),[H,E]=o.useState(N),a=o.useCallback(c=>{e!=null&&e.current&&U(c)},[e]),j=c=>{if((d==null?void 0:d.sanitizeEnabled)??_){const s=(d==null?void 0:d.sanitizeRegex)??/[\D]/gi;return c.replace(s,"")}return c},m=o.useCallback(async c=>{var u;(u=P.current)==null||u.stop(),a(n.StarCloudScanStatus.ScanningComplete);const S=String.fromCharCode(...c).trim(),s=j(S);E(s)},[a]),k=o.useCallback(async({macAddress:c,ipAddress:S})=>{function s(t){a(n.StarCloudScanStatus.CommunicationError),e!=null&&e.current&&g(t==null?void 0:t.message)}const u={onStarted:t=>{if(t&&t.inputDevicesCount>0){const{inputDevicesCount:C}=t;a(n.StarCloudScanStatus.ReadyToScan),f({inputDeviceCount:C,lastConnectedOn:new Date})}},onStopped:t=>{t&&s(t),f(void 0)},inputDevice:{onConnected:()=>{const t=((r==null?void 0:r.inputDeviceCount)||0)+1;a(t>0?n.StarCloudScanStatus.ReadyToScan:n.StarCloudScanStatus.PrinterDetected),f({inputDeviceCount:t,lastConnectedOn:new Date})},onDisconnected:()=>{const t=((r==null?void 0:r.inputDeviceCount)||0)-1>=0?((r==null?void 0:r.inputDeviceCount)||0)-1:0;a(t>0?n.StarCloudScanStatus.ReadyToScan:n.StarCloudScanStatus.PrinterDetected),f({inputDeviceCount:t})},onCommunicationError:s,onDataReceived:t=>v({data:t,lastReceivedOn:new Date})}};if(P.current=B.monitor(S||c,u),e!=null&&e.current)try{await P.current.start()}catch(t){a(n.StarCloudScanStatus.CommunicationError),e!=null&&e.current&&g(t==null?void 0:t.message)}},[r,a,e]),b=o.useCallback(async()=>{e!=null&&e.current&&(a(n.StarCloudScanStatus.WaitingForPrinter),g(void 0),v(void 0),f(void 0),E(void 0));const c=w(D.getState()),{macAddress:S,serialNumber:s}=c;try{const t=(await h(2e3)).find(C=>S&&C.macAddress.toLowerCase()===S.toLowerCase()||s&&C.serialNumber===s);if(e!=null&&e.current){if(t){if(Q.some(C=>{var q;return(q=t.model)==null?void 0:q.toLowerCase().includes(C.toLowerCase())})){a(n.StarCloudScanStatus.UnsupportedPrinter);return}k(t)}a(t?n.StarCloudScanStatus.PrinterDetected:n.StarCloudScanStatus.PrinterNotDetected)}}catch{e!=null&&e.current&&a(n.StarCloudScanStatus.PrinterNotDetected)}},[e,D,a,h,k]),G=i===n.StarCloudScanStatus.WaitingForPrinter||i===n.StarCloudScanStatus.PrinterDetected||i===n.StarCloudScanStatus.ReadyToScan||i===n.StarCloudScanStatus.ScanningComplete,I=i===n.StarCloudScanStatus.PrinterNotDetected||i===n.StarCloudScanStatus.ScanFailed||i===n.StarCloudScanStatus.CommunicationError||i===n.StarCloudScanStatus.UnsupportedPrinter;return o.useEffect(()=>{if(!y&&(l==null?void 0:l.data)&&r&&(r!=null&&r.lastConnectedOn)){const{lastConnectedOn:S}=r,{lastReceivedOn:s,data:u}=l;L(s).diff(L(S),"second",!0)>V?m(u):v(void 0)}},[l,y,r,m]),o.useEffect(()=>(i===n.StarCloudScanStatus.WaitingForPrinter&&b(),()=>{var c;(c=P.current)==null||c.stop()}),[]),{startScan:b,changeDeviceStatus:a,scanStatus:i,reading:H,connectionError:W,isLoading:G,isError:I}}return A}module.exports=X;
@@ -1,134 +1,138 @@
1
- import { useRef as V, useState as S, useCallback as p, useEffect as O } from "react";
2
- import T from "dayjs";
3
- import { monitor as q } from "@ancon/wildcat-printing";
4
- import z from "../shared/hooks/usePrevious.mjs";
5
- import B from "../shared/hooks/useMountedRef.mjs";
6
- import { StarCloudScanStatus as e } from "./types.mjs";
7
- const J = ["TSP654"], K = 1;
8
- function tt(N, k, F, M, b = !1) {
9
- const { useAppStore: x, useStarPrinterDiscover: A } = k, { selectedClientPrinterSelector: U } = F;
10
- function W() {
11
- const n = B(), P = x(), D = A(), f = V(void 0), [i, H] = S(N), [o, C] = S(), [d, m] = S(), g = z(d), [R, v] = S(), [j, w] = S(M), r = p(
1
+ import { useRef as Q, useState as f, useCallback as v, useEffect as N } from "react";
2
+ import b from "dayjs";
3
+ import { monitor as V } from "@ancon/wildcat-printing";
4
+ import X from "../shared/hooks/usePrevious.mjs";
5
+ import Y from "../shared/hooks/useMountedRef.mjs";
6
+ import { StarCloudScanStatus as t } from "./types.mjs";
7
+ const Z = ["TSP654"], _ = 1;
8
+ function te(k, F, M, A, U = !1, u) {
9
+ const { useAppStore: W, useStarPrinterDiscover: w } = F, { selectedClientPrinterSelector: H } = M;
10
+ function j() {
11
+ const n = Y(), g = W(), y = w(), m = Q(void 0), [s, G] = f(k), [r, C] = f(), [l, P] = f(), E = X(l), [I, D] = f(), [q, p] = f(A), o = v(
12
12
  (c) => {
13
- n != null && n.current && H(c);
13
+ n != null && n.current && G(c);
14
14
  },
15
15
  [n]
16
- ), y = p(
16
+ ), B = (c) => {
17
+ if ((u == null ? void 0 : u.sanitizeEnabled) ?? U) {
18
+ const i = (u == null ? void 0 : u.sanitizeRegex) ?? /[\D]/gi;
19
+ return c.replace(i, "");
20
+ }
21
+ return c;
22
+ }, h = v(
17
23
  async (c) => {
18
- var s;
19
- (s = f.current) == null || s.stop(), r(e.ScanningComplete);
20
- const a = String.fromCharCode(...c).trim();
21
- w(
22
- b ? a.replace(/[\D]/gi, "") : a
23
- );
24
+ var d;
25
+ (d = m.current) == null || d.stop(), o(t.ScanningComplete);
26
+ const a = String.fromCharCode(...c).trim(), i = B(a);
27
+ p(i);
24
28
  },
25
- [r]
26
- ), E = p(
29
+ [o]
30
+ ), L = v(
27
31
  async ({ macAddress: c, ipAddress: a }) => {
28
- function s(t) {
29
- r(e.CommunicationError), n != null && n.current && v(t == null ? void 0 : t.message);
32
+ function i(e) {
33
+ o(t.CommunicationError), n != null && n.current && D(e == null ? void 0 : e.message);
30
34
  }
31
- const l = {
32
- onStarted: (t) => {
33
- if (t && t.inputDevicesCount > 0) {
34
- const { inputDevicesCount: u } = t;
35
- r(e.ReadyToScan), C({
36
- inputDeviceCount: u,
35
+ const d = {
36
+ onStarted: (e) => {
37
+ if (e && e.inputDevicesCount > 0) {
38
+ const { inputDevicesCount: S } = e;
39
+ o(t.ReadyToScan), C({
40
+ inputDeviceCount: S,
37
41
  lastConnectedOn: /* @__PURE__ */ new Date()
38
42
  });
39
43
  }
40
44
  },
41
- onStopped: (t) => {
42
- t && s(t), C(void 0);
45
+ onStopped: (e) => {
46
+ e && i(e), C(void 0);
43
47
  },
44
48
  inputDevice: {
45
49
  onConnected: () => {
46
- const t = ((o == null ? void 0 : o.inputDeviceCount) || 0) + 1;
47
- r(
48
- t > 0 ? e.ReadyToScan : e.PrinterDetected
50
+ const e = ((r == null ? void 0 : r.inputDeviceCount) || 0) + 1;
51
+ o(
52
+ e > 0 ? t.ReadyToScan : t.PrinterDetected
49
53
  ), C({
50
- inputDeviceCount: t,
54
+ inputDeviceCount: e,
51
55
  lastConnectedOn: /* @__PURE__ */ new Date()
52
56
  });
53
57
  },
54
58
  onDisconnected: () => {
55
- const t = ((o == null ? void 0 : o.inputDeviceCount) || 0) - 1 >= 0 ? ((o == null ? void 0 : o.inputDeviceCount) || 0) - 1 : 0;
56
- r(
57
- t > 0 ? e.ReadyToScan : e.PrinterDetected
59
+ const e = ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 >= 0 ? ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 : 0;
60
+ o(
61
+ e > 0 ? t.ReadyToScan : t.PrinterDetected
58
62
  ), C({
59
- inputDeviceCount: t
63
+ inputDeviceCount: e
60
64
  });
61
65
  },
62
- onCommunicationError: s,
63
- onDataReceived: (t) => m({ data: t, lastReceivedOn: /* @__PURE__ */ new Date() })
66
+ onCommunicationError: i,
67
+ onDataReceived: (e) => P({ data: e, lastReceivedOn: /* @__PURE__ */ new Date() })
64
68
  }
65
69
  };
66
- if (f.current = q(a || c, l), n != null && n.current)
70
+ if (m.current = V(a || c, d), n != null && n.current)
67
71
  try {
68
- await f.current.start();
69
- } catch (t) {
70
- r(e.CommunicationError), n != null && n.current && v(t == null ? void 0 : t.message);
72
+ await m.current.start();
73
+ } catch (e) {
74
+ o(t.CommunicationError), n != null && n.current && D(e == null ? void 0 : e.message);
71
75
  }
72
76
  },
73
- [o, r, n]
74
- ), h = p(async () => {
75
- n != null && n.current && (r(e.WaitingForPrinter), v(void 0), m(void 0), C(void 0), w(void 0));
76
- const c = U(P.getState()), { macAddress: a, serialNumber: s } = c;
77
+ [r, o, n]
78
+ ), T = v(async () => {
79
+ n != null && n.current && (o(t.WaitingForPrinter), D(void 0), P(void 0), C(void 0), p(void 0));
80
+ const c = H(g.getState()), { macAddress: a, serialNumber: i } = c;
77
81
  try {
78
- const t = (await D(2e3)).find(
79
- (u) => a && u.macAddress.toLowerCase() === a.toLowerCase() || s && u.serialNumber === s
82
+ const e = (await y(2e3)).find(
83
+ (S) => a && S.macAddress.toLowerCase() === a.toLowerCase() || i && S.serialNumber === i
80
84
  );
81
85
  if (n != null && n.current) {
82
- if (t) {
83
- if (J.some(
84
- (u) => {
85
- var L;
86
- return (L = t.model) == null ? void 0 : L.toLowerCase().includes(u.toLowerCase());
86
+ if (e) {
87
+ if (Z.some(
88
+ (S) => {
89
+ var x;
90
+ return (x = e.model) == null ? void 0 : x.toLowerCase().includes(S.toLowerCase());
87
91
  }
88
92
  )) {
89
- r(e.UnsupportedPrinter);
93
+ o(t.UnsupportedPrinter);
90
94
  return;
91
95
  }
92
- E(t);
96
+ L(e);
93
97
  }
94
- r(
95
- t ? e.PrinterDetected : e.PrinterNotDetected
98
+ o(
99
+ e ? t.PrinterDetected : t.PrinterNotDetected
96
100
  );
97
101
  }
98
102
  } catch {
99
- n != null && n.current && r(e.PrinterNotDetected);
103
+ n != null && n.current && o(t.PrinterNotDetected);
100
104
  }
101
105
  }, [
102
106
  n,
103
- P,
104
- r,
105
- D,
106
- E
107
- ]), G = i === e.WaitingForPrinter || i === e.PrinterDetected || i === e.ReadyToScan || i === e.ScanningComplete, I = i === e.PrinterNotDetected || i === e.ScanFailed || i === e.CommunicationError || i === e.UnsupportedPrinter;
108
- return O(() => {
109
- if (!g && (d == null ? void 0 : d.data) && o && (o != null && o.lastConnectedOn)) {
110
- const { lastConnectedOn: a } = o, { lastReceivedOn: s, data: l } = d;
111
- T(s).diff(
112
- T(a),
107
+ g,
108
+ o,
109
+ y,
110
+ L
111
+ ]), J = s === t.WaitingForPrinter || s === t.PrinterDetected || s === t.ReadyToScan || s === t.ScanningComplete, K = s === t.PrinterNotDetected || s === t.ScanFailed || s === t.CommunicationError || s === t.UnsupportedPrinter;
112
+ return N(() => {
113
+ if (!E && (l == null ? void 0 : l.data) && r && (r != null && r.lastConnectedOn)) {
114
+ const { lastConnectedOn: a } = r, { lastReceivedOn: i, data: d } = l;
115
+ b(i).diff(
116
+ b(a),
113
117
  "second",
114
118
  !0
115
- ) > K ? y(l) : m(void 0);
119
+ ) > _ ? h(d) : P(void 0);
116
120
  }
117
- }, [d, g, o, y]), O(() => (i === e.WaitingForPrinter && h(), () => {
121
+ }, [l, E, r, h]), N(() => (s === t.WaitingForPrinter && T(), () => {
118
122
  var c;
119
- (c = f.current) == null || c.stop();
123
+ (c = m.current) == null || c.stop();
120
124
  }), []), {
121
- startScan: h,
122
- changeDeviceStatus: r,
123
- scanStatus: i,
124
- reading: j,
125
- connectionError: R,
126
- isLoading: G,
127
- isError: I
125
+ startScan: T,
126
+ changeDeviceStatus: o,
127
+ scanStatus: s,
128
+ reading: q,
129
+ connectionError: I,
130
+ isLoading: J,
131
+ isError: K
128
132
  };
129
133
  }
130
- return W;
134
+ return j;
131
135
  }
132
136
  export {
133
- tt as default
137
+ te as default
134
138
  };