@ancon/wildcat-utils 1.50.12 → 1.50.14
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/checkout/getCheckoutRequestItemFromCheckoutItem.js +1 -1
- package/checkout/getCheckoutRequestItemFromCheckoutItem.mjs +11 -11
- package/package.json +1 -1
- package/printing/createStarCloudScanHook.d.ts +1 -5
- package/printing/createStarCloudScanHook.js +1 -1
- package/printing/createStarCloudScanHook.mjs +24 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const y=require("./isWalletTopUpCheckoutItem.js"),I=require("./isGiftCardCheckoutItem.js");require("@ancon/wildcat-types");function i(u,a){const{product:r,quantity:n,modifications:
|
|
1
|
+
"use strict";const y=require("./isWalletTopUpCheckoutItem.js"),I=require("./isGiftCardCheckoutItem.js");require("@ancon/wildcat-types");function i(u,a){const{product:r,quantity:n,modifications:l,upsellGroupId:c,totalPriceInclTax:d,addOnProducts:s,itemType:p}=u;if(y(u)){let e=null;if(a){const t=a;e=JSON.stringify({id:t.id,prepaidWalletNumber:t.prepaidWalletNumber})}return{productType:r.productType,variantType:r.variantType,price:{unitPrice:d.amount},metaData:e,quantity:n,modifications:[],addOnProducts:[],itemType:p}}if(I(u)){let e=null;if(a){const t=a;e=JSON.stringify({draftGiftCardId:t.draftGiftCardId,amount:t.amount,email:t.email,externalPurchase:t.externalPurchase,greetingMessage:t.greetingMessage,id:t.id,receivedBy:t.receivedBy,senderEmail:t.senderEmail,sendingBy:t.sendingBy,sms:t.sms})}return{productType:r.productType,variantType:r.variantType,price:{unitPrice:d.amount},metaData:e,quantity:n,modifications:[],addOnProducts:[],itemType:p}}return{variantId:r.variantId,quantity:n,modifications:l.map(e=>({modification:e.modification,ingredientId:e.ingredientId,quantity:e==null?void 0:e.quantity,freeAmount:e==null?void 0:e.freeAmount,addOnGroupId:(e==null?void 0:e.groupId)||void 0,replaceId:e.replaceId||void 0,description:e==null?void 0:e.description})),addOnProducts:(s==null?void 0:s.map(e=>({quantity:e.quantity,freeAmount:e.addOnFreeAmount,variantId:e.product.variantId,unitQuantity:e.quantity,addOnGroupId:e.addOnGroupId})))??[],upsellGroupId:c,itemType:p}}module.exports=i;
|
|
@@ -5,11 +5,11 @@ function v(u, a) {
|
|
|
5
5
|
const {
|
|
6
6
|
product: r,
|
|
7
7
|
quantity: n,
|
|
8
|
-
modifications:
|
|
9
|
-
upsellGroupId:
|
|
8
|
+
modifications: l,
|
|
9
|
+
upsellGroupId: y,
|
|
10
10
|
totalPriceInclTax: d,
|
|
11
|
-
addOnProducts:
|
|
12
|
-
itemType:
|
|
11
|
+
addOnProducts: p,
|
|
12
|
+
itemType: s
|
|
13
13
|
} = u;
|
|
14
14
|
if (I(u)) {
|
|
15
15
|
let e = null;
|
|
@@ -28,7 +28,7 @@ function v(u, a) {
|
|
|
28
28
|
quantity: n,
|
|
29
29
|
modifications: [],
|
|
30
30
|
addOnProducts: [],
|
|
31
|
-
itemType:
|
|
31
|
+
itemType: s
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
if (i(u)) {
|
|
@@ -56,13 +56,13 @@ function v(u, a) {
|
|
|
56
56
|
quantity: n,
|
|
57
57
|
modifications: [],
|
|
58
58
|
addOnProducts: [],
|
|
59
|
-
itemType:
|
|
59
|
+
itemType: s
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
return {
|
|
63
63
|
variantId: r.variantId,
|
|
64
64
|
quantity: n,
|
|
65
|
-
modifications:
|
|
65
|
+
modifications: l.map((e) => ({
|
|
66
66
|
modification: e.modification,
|
|
67
67
|
ingredientId: e.ingredientId,
|
|
68
68
|
quantity: e == null ? void 0 : e.quantity,
|
|
@@ -71,15 +71,15 @@ function v(u, a) {
|
|
|
71
71
|
replaceId: e.replaceId || void 0,
|
|
72
72
|
description: e == null ? void 0 : e.description
|
|
73
73
|
})),
|
|
74
|
-
addOnProducts:
|
|
74
|
+
addOnProducts: (p == null ? void 0 : p.map((e) => ({
|
|
75
75
|
quantity: e.quantity,
|
|
76
76
|
freeAmount: e.addOnFreeAmount,
|
|
77
77
|
variantId: e.product.variantId,
|
|
78
78
|
unitQuantity: e.quantity,
|
|
79
79
|
addOnGroupId: e.addOnGroupId
|
|
80
|
-
})),
|
|
81
|
-
upsellGroupId:
|
|
82
|
-
itemType:
|
|
80
|
+
}))) ?? [],
|
|
81
|
+
upsellGroupId: y,
|
|
82
|
+
itemType: s
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
export {
|
package/package.json
CHANGED
|
@@ -18,11 +18,7 @@ export declare type SanitizeRawOutputOptions = {
|
|
|
18
18
|
*/
|
|
19
19
|
sanitizeRegex?: RegExp;
|
|
20
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): () => {
|
|
21
|
+
declare function createUseStarCloudScanHook<RootState = unknown>(initialStatus: StarCloudScanStatus, hooks: ReduxHooksArg<RootState>, selectors: ReduxSelectorsArg<RootState>, initialReading?: string, sanitizeRawOutputOptions?: SanitizeRawOutputOptions): () => {
|
|
26
22
|
startScan: () => Promise<void>;
|
|
27
23
|
changeDeviceStatus: (nextStatus: StarCloudScanStatus) => void;
|
|
28
24
|
scanStatus: StarCloudScanStatus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const o=require("react"),L=require("dayjs"),
|
|
1
|
+
"use strict";const o=require("react"),L=require("dayjs"),I=require("@ancon/wildcat-printing"),B=require("../shared/hooks/usePrevious.js"),J=require("../shared/hooks/useMountedRef.js"),n=require("./types.js"),K=["TSP654"],Q=1;function V(T,p,x,N,d){const{useAppStore:_,useStarPrinterDiscover:F}=p,{selectedClientPrinterSelector:M}=x;function w(){const e=J(),D=_(),h=F(),P=o.useRef(void 0),[i,A]=o.useState(T),[r,f]=o.useState(),[l,v]=o.useState(),y=B(l),[U,g]=o.useState(),[W,E]=o.useState(N),a=o.useCallback(c=>{e!=null&&e.current&&A(c)},[e]),H=c=>{if((d==null?void 0:d.sanitizeEnabled)??!1){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=H(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=I.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=M(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(K.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]),j=i===n.StarCloudScanStatus.WaitingForPrinter||i===n.StarCloudScanStatus.PrinterDetected||i===n.StarCloudScanStatus.ReadyToScan||i===n.StarCloudScanStatus.ScanningComplete,G=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)>Q?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:W,connectionError:U,isLoading:j,isError:G}}return w}module.exports=V;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { useRef as
|
|
1
|
+
import { useRef as K, useState as f, useCallback as v, useEffect as N } from "react";
|
|
2
2
|
import b from "dayjs";
|
|
3
|
-
import { monitor as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import { monitor as Q } from "@ancon/wildcat-printing";
|
|
4
|
+
import V from "../shared/hooks/usePrevious.mjs";
|
|
5
|
+
import X from "../shared/hooks/useMountedRef.mjs";
|
|
6
6
|
import { StarCloudScanStatus as t } from "./types.mjs";
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
const { useAppStore:
|
|
10
|
-
function
|
|
11
|
-
const n =
|
|
7
|
+
const Y = ["TSP654"], Z = 1;
|
|
8
|
+
function ne(k, F, M, A, u) {
|
|
9
|
+
const { useAppStore: U, useStarPrinterDiscover: W } = F, { selectedClientPrinterSelector: w } = M;
|
|
10
|
+
function H() {
|
|
11
|
+
const n = X(), g = U(), y = W(), m = K(void 0), [s, j] = f(k), [r, C] = f(), [l, P] = f(), E = V(l), [G, D] = f(), [I, p] = f(A), o = v(
|
|
12
12
|
(c) => {
|
|
13
|
-
n != null && n.current &&
|
|
13
|
+
n != null && n.current && j(c);
|
|
14
14
|
},
|
|
15
15
|
[n]
|
|
16
|
-
),
|
|
17
|
-
if ((u == null ? void 0 : u.sanitizeEnabled) ??
|
|
16
|
+
), q = (c) => {
|
|
17
|
+
if ((u == null ? void 0 : u.sanitizeEnabled) ?? !1) {
|
|
18
18
|
const i = (u == null ? void 0 : u.sanitizeRegex) ?? /[\D]/gi;
|
|
19
19
|
return c.replace(i, "");
|
|
20
20
|
}
|
|
@@ -23,7 +23,7 @@ function te(k, F, M, A, U = !1, u) {
|
|
|
23
23
|
async (c) => {
|
|
24
24
|
var d;
|
|
25
25
|
(d = m.current) == null || d.stop(), o(t.ScanningComplete);
|
|
26
|
-
const a = String.fromCharCode(...c).trim(), i =
|
|
26
|
+
const a = String.fromCharCode(...c).trim(), i = q(a);
|
|
27
27
|
p(i);
|
|
28
28
|
},
|
|
29
29
|
[o]
|
|
@@ -67,7 +67,7 @@ function te(k, F, M, A, U = !1, u) {
|
|
|
67
67
|
onDataReceived: (e) => P({ data: e, lastReceivedOn: /* @__PURE__ */ new Date() })
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
|
-
if (m.current =
|
|
70
|
+
if (m.current = Q(a || c, d), n != null && n.current)
|
|
71
71
|
try {
|
|
72
72
|
await m.current.start();
|
|
73
73
|
} catch (e) {
|
|
@@ -77,14 +77,14 @@ function te(k, F, M, A, U = !1, u) {
|
|
|
77
77
|
[r, o, n]
|
|
78
78
|
), T = v(async () => {
|
|
79
79
|
n != null && n.current && (o(t.WaitingForPrinter), D(void 0), P(void 0), C(void 0), p(void 0));
|
|
80
|
-
const c =
|
|
80
|
+
const c = w(g.getState()), { macAddress: a, serialNumber: i } = c;
|
|
81
81
|
try {
|
|
82
82
|
const e = (await y(2e3)).find(
|
|
83
83
|
(S) => a && S.macAddress.toLowerCase() === a.toLowerCase() || i && S.serialNumber === i
|
|
84
84
|
);
|
|
85
85
|
if (n != null && n.current) {
|
|
86
86
|
if (e) {
|
|
87
|
-
if (
|
|
87
|
+
if (Y.some(
|
|
88
88
|
(S) => {
|
|
89
89
|
var x;
|
|
90
90
|
return (x = e.model) == null ? void 0 : x.toLowerCase().includes(S.toLowerCase());
|
|
@@ -108,7 +108,7 @@ function te(k, F, M, A, U = !1, u) {
|
|
|
108
108
|
o,
|
|
109
109
|
y,
|
|
110
110
|
L
|
|
111
|
-
]),
|
|
111
|
+
]), B = s === t.WaitingForPrinter || s === t.PrinterDetected || s === t.ReadyToScan || s === t.ScanningComplete, J = s === t.PrinterNotDetected || s === t.ScanFailed || s === t.CommunicationError || s === t.UnsupportedPrinter;
|
|
112
112
|
return N(() => {
|
|
113
113
|
if (!E && (l == null ? void 0 : l.data) && r && (r != null && r.lastConnectedOn)) {
|
|
114
114
|
const { lastConnectedOn: a } = r, { lastReceivedOn: i, data: d } = l;
|
|
@@ -116,7 +116,7 @@ function te(k, F, M, A, U = !1, u) {
|
|
|
116
116
|
b(a),
|
|
117
117
|
"second",
|
|
118
118
|
!0
|
|
119
|
-
) >
|
|
119
|
+
) > Z ? h(d) : P(void 0);
|
|
120
120
|
}
|
|
121
121
|
}, [l, E, r, h]), N(() => (s === t.WaitingForPrinter && T(), () => {
|
|
122
122
|
var c;
|
|
@@ -125,14 +125,14 @@ function te(k, F, M, A, U = !1, u) {
|
|
|
125
125
|
startScan: T,
|
|
126
126
|
changeDeviceStatus: o,
|
|
127
127
|
scanStatus: s,
|
|
128
|
-
reading:
|
|
129
|
-
connectionError:
|
|
130
|
-
isLoading:
|
|
131
|
-
isError:
|
|
128
|
+
reading: I,
|
|
129
|
+
connectionError: G,
|
|
130
|
+
isLoading: B,
|
|
131
|
+
isError: J
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
|
-
return
|
|
134
|
+
return H;
|
|
135
135
|
}
|
|
136
136
|
export {
|
|
137
|
-
|
|
137
|
+
ne as default
|
|
138
138
|
};
|