@ancon/wildcat-utils 1.54.0-check-optimizations.5 → 1.54.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.
Files changed (41) hide show
  1. package/api/generateBackoffWithFullJitter.d.ts +15 -0
  2. package/api/generateBackoffWithFullJitter.js +1 -0
  3. package/api/generateBackoffWithFullJitter.mjs +7 -0
  4. package/api/generateBackoffWithVariableJitter.d.ts +3 -1
  5. package/api/generateBackoffWithVariableJitter.js +1 -1
  6. package/api/generateBackoffWithVariableJitter.mjs +12 -9
  7. package/api/getRateLimitRetryDelay.d.ts +18 -0
  8. package/api/getRateLimitRetryDelay.js +1 -0
  9. package/api/getRateLimitRetryDelay.mjs +14 -0
  10. package/api/index.d.ts +3 -1
  11. package/api/index.js +1 -1
  12. package/api/index.mjs +20 -14
  13. package/check/getOrganizedCheckItemModifications.d.ts +2 -2
  14. package/check/getOrganizedCheckItemModifications.js +1 -1
  15. package/check/getOrganizedCheckItemModifications.mjs +68 -74
  16. package/check/getUniqueCheckItemModificationId.d.ts +2 -2
  17. package/check/getUniqueCheckItemModificationId.js +1 -1
  18. package/check/getUniqueCheckItemModificationId.mjs +5 -5
  19. package/error/getRateLimit.d.ts +31 -0
  20. package/error/getRateLimit.js +1 -0
  21. package/error/getRateLimit.mjs +60 -0
  22. package/error/index.d.ts +4 -2
  23. package/error/index.js +1 -1
  24. package/error/index.mjs +34 -28
  25. package/error/isRateLimitError.d.ts +7 -0
  26. package/error/isRateLimitError.js +1 -0
  27. package/error/isRateLimitError.mjs +8 -0
  28. package/index.js +1 -1
  29. package/index.mjs +375 -362
  30. package/multilingual/createLocalizedCheckDetails.d.ts +2 -2
  31. package/multilingual/createLocalizedCheckDetails.js +1 -1
  32. package/multilingual/createLocalizedCheckDetails.mjs +27 -31
  33. package/package.json +26 -1
  34. package/printing/StarScanConnection.d.ts +64 -0
  35. package/printing/StarScanConnection.js +1 -0
  36. package/printing/StarScanConnection.mjs +93 -0
  37. package/printing/createStarCloudScanHook.d.ts +10 -0
  38. package/printing/createStarCloudScanHook.js +1 -1
  39. package/printing/createStarCloudScanHook.mjs +131 -93
  40. package/printing/index.js +1 -1
  41. package/printing/index.mjs +15 -14
@@ -1,138 +1,176 @@
1
- import { useRef as K, useState as f, useCallback as v, useEffect as N } from "react";
2
- import b from "dayjs";
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
- import { StarCloudScanStatus as t } from "./types.mjs";
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
- (c) => {
13
- n != null && n.current && j(c);
1
+ import { useRef as k, useState as D, useCallback as h, useEffect as L } from "react";
2
+ import W from "dayjs";
3
+ import { monitor as nn } from "@ancon/wildcat-printing";
4
+ import en from "../shared/hooks/usePrevious.mjs";
5
+ import tn from "../shared/hooks/useMountedRef.mjs";
6
+ import { StarCloudScanStatus as e } from "./types.mjs";
7
+ import rn, { StarScanReleaseReason as B } from "./StarScanConnection.mjs";
8
+ const on = ["TSP654"], cn = 1, sn = [
9
+ e.WaitingForPrinter,
10
+ e.PrinterDetected,
11
+ e.ReadyToScan
12
+ ];
13
+ function an() {
14
+ return !1;
15
+ }
16
+ function mn(H, R, j, G, f) {
17
+ const {
18
+ useAppStore: q,
19
+ useStarPrinterDiscover: J,
20
+ useIsAppInBackground: K = an,
21
+ logger: Q
22
+ } = R, { selectedClientPrinterSelector: V } = j;
23
+ function X() {
24
+ const n = tn(), T = q(), F = J(), b = K(), p = k(null);
25
+ p.current || (p.current = new rn(Q));
26
+ const c = p.current, [s, Y] = D(H), [r, m] = D(), [C, y] = D(), w = en(C), [Z, A] = D(), [_, x] = D(G), o = h(
27
+ (i) => {
28
+ n != null && n.current && Y(i);
14
29
  },
15
30
  [n]
16
- ), q = (c) => {
17
- if ((u == null ? void 0 : u.sanitizeEnabled) ?? !1) {
18
- const i = (u == null ? void 0 : u.sanitizeRegex) ?? /[\D]/gi;
19
- return c.replace(i, "");
31
+ ), $ = (i) => {
32
+ if ((f == null ? void 0 : f.sanitizeEnabled) ?? !1) {
33
+ const a = (f == null ? void 0 : f.sanitizeRegex) ?? /[\D]/gi;
34
+ return i.replace(a, "");
20
35
  }
21
- return c;
22
- }, h = v(
23
- async (c) => {
24
- var d;
25
- (d = m.current) == null || d.stop(), o(t.ScanningComplete);
26
- const a = String.fromCharCode(...c).trim(), i = q(a);
27
- p(i);
36
+ return i;
37
+ }, I = h(
38
+ async (i) => {
39
+ c.release(B.CardRead), o(e.ScanningComplete);
40
+ const u = String.fromCharCode(...i).trim(), a = $(u);
41
+ x(a);
28
42
  },
29
- [o]
30
- ), L = v(
31
- async ({ macAddress: c, ipAddress: a }) => {
32
- function i(e) {
33
- o(t.CommunicationError), n != null && n.current && D(e == null ? void 0 : e.message);
43
+ [o, c]
44
+ ), M = h(
45
+ async ({ macAddress: i, ipAddress: u }) => {
46
+ let a;
47
+ function d(t) {
48
+ return (...E) => {
49
+ a && c.isAttached(a) && t(...E);
50
+ };
51
+ }
52
+ function P(t) {
53
+ o(e.CommunicationError), n != null && n.current && A(t == null ? void 0 : t.message);
34
54
  }
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,
55
+ const g = {
56
+ onStarted: d((t) => {
57
+ if (t && t.inputDevicesCount > 0) {
58
+ const { inputDevicesCount: E } = t;
59
+ o(e.ReadyToScan), m({
60
+ inputDeviceCount: E,
41
61
  lastConnectedOn: /* @__PURE__ */ new Date()
42
62
  });
43
63
  }
44
- },
45
- onStopped: (e) => {
46
- e && i(e), C(void 0);
47
- },
64
+ }),
65
+ onStopped: d((t) => {
66
+ t && P(t), m(void 0);
67
+ }),
48
68
  inputDevice: {
49
- onConnected: () => {
50
- const e = ((r == null ? void 0 : r.inputDeviceCount) || 0) + 1;
69
+ onConnected: d(() => {
70
+ const t = ((r == null ? void 0 : r.inputDeviceCount) || 0) + 1;
51
71
  o(
52
- e > 0 ? t.ReadyToScan : t.PrinterDetected
53
- ), C({
54
- inputDeviceCount: e,
72
+ t > 0 ? e.ReadyToScan : e.PrinterDetected
73
+ ), m({
74
+ inputDeviceCount: t,
55
75
  lastConnectedOn: /* @__PURE__ */ new Date()
56
76
  });
57
- },
58
- onDisconnected: () => {
59
- const e = ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 >= 0 ? ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 : 0;
77
+ }),
78
+ onDisconnected: d(() => {
79
+ const t = ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 >= 0 ? ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 : 0;
60
80
  o(
61
- e > 0 ? t.ReadyToScan : t.PrinterDetected
62
- ), C({
63
- inputDeviceCount: e
81
+ t > 0 ? e.ReadyToScan : e.PrinterDetected
82
+ ), m({
83
+ inputDeviceCount: t
64
84
  });
65
- },
66
- onCommunicationError: i,
67
- onDataReceived: (e) => P({ data: e, lastReceivedOn: /* @__PURE__ */ new Date() })
85
+ }),
86
+ onCommunicationError: d(P),
87
+ onDataReceived: d(
88
+ (t) => y({ data: t, lastReceivedOn: /* @__PURE__ */ new Date() })
89
+ )
68
90
  }
69
- };
70
- if (m.current = Q(a || c, d), n != null && n.current)
91
+ }, l = u || i, S = nn(l, g);
92
+ if (a = S, c.attach(S, l), n != null && n.current)
71
93
  try {
72
- await m.current.start();
73
- } catch (e) {
74
- o(t.CommunicationError), n != null && n.current && D(e == null ? void 0 : e.message);
94
+ await S.start();
95
+ } catch (t) {
96
+ if (!c.isAttached(S))
97
+ return;
98
+ o(e.CommunicationError), n != null && n.current && A(t == null ? void 0 : t.message);
75
99
  }
76
100
  },
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 = w(g.getState()), { macAddress: a, serialNumber: i } = c;
101
+ [r, o, n, c]
102
+ ), v = h(async () => {
103
+ const i = c.beginScan();
104
+ n != null && n.current && (o(e.WaitingForPrinter), A(void 0), y(void 0), m(void 0), x(void 0));
105
+ const u = V(T.getState()), { macAddress: a, serialNumber: d } = u;
81
106
  try {
82
- const e = (await y(2e3)).find(
83
- (S) => a && S.macAddress.toLowerCase() === a.toLowerCase() || i && S.serialNumber === i
107
+ const g = (await F(2e3)).find(
108
+ (l) => a && l.macAddress.toLowerCase() === a.toLowerCase() || d && l.serialNumber === d
84
109
  );
110
+ if (!c.mayConnect(i))
111
+ return;
85
112
  if (n != null && n.current) {
86
- if (e) {
87
- if (Y.some(
88
- (S) => {
89
- var x;
90
- return (x = e.model) == null ? void 0 : x.toLowerCase().includes(S.toLowerCase());
113
+ if (g) {
114
+ if (on.some(
115
+ (l) => {
116
+ var S;
117
+ return (S = g.model) == null ? void 0 : S.toLowerCase().includes(l.toLowerCase());
91
118
  }
92
119
  )) {
93
- o(t.UnsupportedPrinter);
120
+ o(e.UnsupportedPrinter);
94
121
  return;
95
122
  }
96
- L(e);
123
+ M(g);
97
124
  }
98
125
  o(
99
- e ? t.PrinterDetected : t.PrinterNotDetected
126
+ g ? e.PrinterDetected : e.PrinterNotDetected
100
127
  );
101
128
  }
102
129
  } catch {
103
- n != null && n.current && o(t.PrinterNotDetected);
130
+ if (!c.isLatest(i))
131
+ return;
132
+ n != null && n.current && o(e.PrinterNotDetected);
104
133
  }
105
134
  }, [
106
135
  n,
107
- g,
136
+ T,
108
137
  o,
109
- y,
110
- L
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
- 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),
138
+ F,
139
+ M,
140
+ c
141
+ ]), N = k(s);
142
+ N.current = s;
143
+ const U = k(v);
144
+ U.current = v, L(() => {
145
+ c.setBackground(
146
+ b,
147
+ sn.includes(N.current)
148
+ ) && (n != null && n.current) && U.current();
149
+ }, [b, c, n]);
150
+ const z = s === e.WaitingForPrinter || s === e.PrinterDetected || s === e.ReadyToScan || s === e.ScanningComplete, O = s === e.PrinterNotDetected || s === e.ScanFailed || s === e.CommunicationError || s === e.UnsupportedPrinter;
151
+ return L(() => {
152
+ if (!w && (C == null ? void 0 : C.data) && r && (r != null && r.lastConnectedOn)) {
153
+ const { lastConnectedOn: u } = r, { lastReceivedOn: a, data: d } = C;
154
+ W(a).diff(
155
+ W(u),
117
156
  "second",
118
157
  !0
119
- ) > Z ? h(d) : P(void 0);
158
+ ) > cn ? I(d) : y(void 0);
120
159
  }
121
- }, [l, E, r, h]), N(() => (s === t.WaitingForPrinter && T(), () => {
122
- var c;
123
- (c = m.current) == null || c.stop();
160
+ }, [C, w, r, I]), L(() => (s === e.WaitingForPrinter && v(), () => {
161
+ c.release(B.Unmount);
124
162
  }), []), {
125
- startScan: T,
163
+ startScan: v,
126
164
  changeDeviceStatus: o,
127
165
  scanStatus: s,
128
- reading: I,
129
- connectionError: G,
130
- isLoading: B,
131
- isError: J
166
+ reading: _,
167
+ connectionError: Z,
168
+ isLoading: z,
169
+ isError: O
132
170
  };
133
171
  }
134
- return H;
172
+ return X;
135
173
  }
136
174
  export {
137
- ne as default
175
+ mn as default
138
176
  };
package/printing/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./getPrinterType.js"),e=require("./isValidPrinter.js"),i=require("./isValidNetworkPrinter.js"),t=require("./isValidStarCloudPrinter.js"),n=require("./isTerminalPrinter.js"),o=require("./isCloudPrintModeEnabled.js"),u=require("./createStarCloudScanHook.js");require("@ancon/wildcat-types");require("react");require("dayjs");require("@ancon/wildcat-printing");require("../shared/hooks/usePrevious.js");require("../shared/hooks/useMountedRef.js");require("./types.js");exports.getPrinterType=r;exports.isValidPrinter=e;exports.isValidNetworkPrinter=i;exports.isValidStarCloudPrinter=t;exports.isTerminalPrinter=n;exports.isCloudPrintModeEnabled=o;exports.createUseStarCloudScanHook=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./getPrinterType.js"),e=require("./isValidPrinter.js"),i=require("./isValidNetworkPrinter.js"),t=require("./isValidStarCloudPrinter.js"),n=require("./isTerminalPrinter.js"),o=require("./isCloudPrintModeEnabled.js"),u=require("./createStarCloudScanHook.js");require("@ancon/wildcat-types");require("react");require("dayjs");require("@ancon/wildcat-printing");require("../shared/hooks/usePrevious.js");require("../shared/hooks/useMountedRef.js");require("./types.js");require("./StarScanConnection.js");exports.getPrinterType=r;exports.isValidPrinter=e;exports.isValidNetworkPrinter=i;exports.isValidStarCloudPrinter=t;exports.isTerminalPrinter=n;exports.isCloudPrintModeEnabled=o;exports.createUseStarCloudScanHook=u;
@@ -1,10 +1,10 @@
1
- import { default as p } from "./getPrinterType.mjs";
2
- import { default as s } from "./isValidPrinter.mjs";
3
- import { default as n } from "./isValidNetworkPrinter.mjs";
4
- import { default as P } from "./isValidStarCloudPrinter.mjs";
5
- import { default as S } from "./isTerminalPrinter.mjs";
6
- import { default as c } from "./isCloudPrintModeEnabled.mjs";
7
- import { default as T } from "./createStarCloudScanHook.mjs";
1
+ import { default as f } from "./getPrinterType.mjs";
2
+ import { default as u } from "./isValidPrinter.mjs";
3
+ import { default as x } from "./isValidNetworkPrinter.mjs";
4
+ import { default as C } from "./isValidStarCloudPrinter.mjs";
5
+ import { default as V } from "./isTerminalPrinter.mjs";
6
+ import { default as k } from "./isCloudPrintModeEnabled.mjs";
7
+ import { default as b } from "./createStarCloudScanHook.mjs";
8
8
  import "@ancon/wildcat-types";
9
9
  import "react";
10
10
  import "dayjs";
@@ -12,12 +12,13 @@ import "@ancon/wildcat-printing";
12
12
  import "../shared/hooks/usePrevious.mjs";
13
13
  import "../shared/hooks/useMountedRef.mjs";
14
14
  import "./types.mjs";
15
+ import "./StarScanConnection.mjs";
15
16
  export {
16
- T as createUseStarCloudScanHook,
17
- p as getPrinterType,
18
- c as isCloudPrintModeEnabled,
19
- S as isTerminalPrinter,
20
- n as isValidNetworkPrinter,
21
- s as isValidPrinter,
22
- P as isValidStarCloudPrinter
17
+ b as createUseStarCloudScanHook,
18
+ f as getPrinterType,
19
+ k as isCloudPrintModeEnabled,
20
+ V as isTerminalPrinter,
21
+ x as isValidNetworkPrinter,
22
+ u as isValidPrinter,
23
+ C as isValidStarCloudPrinter
23
24
  };