@tesouro/embedded-components-react 0.7.0 → 0.7.3

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.css CHANGED
@@ -4910,6 +4910,9 @@
4910
4910
  .ttw\:hover\:bg-purple-50:hover {
4911
4911
  background-color: var(--ttw-color-purple-50);
4912
4912
  }
4913
+ .ttw\:hover\:bg-purple-100:hover {
4914
+ background-color: var(--ttw-color-purple-100);
4915
+ }
4913
4916
  .ttw\:hover\:bg-red-50:hover {
4914
4917
  background-color: var(--ttw-color-red-50);
4915
4918
  }
package/dist/index.d.ts CHANGED
@@ -3256,6 +3256,7 @@ interface TransactionDetailsLabels {
3256
3256
  acceptedFileTypes: string;
3257
3257
  uploadingReceipt: string;
3258
3258
  uploadingReceiptBody: string;
3259
+ readingReceipt: string;
3259
3260
  loadFailed: string;
3260
3261
  }
3261
3262
 
@@ -141,6 +141,7 @@ interface TransactionDetailsLabels {
141
141
  acceptedFileTypes: string;
142
142
  uploadingReceipt: string;
143
143
  uploadingReceiptBody: string;
144
+ readingReceipt: string;
144
145
  loadFailed: string;
145
146
  }
146
147
 
@@ -2325,6 +2325,7 @@ interface TransactionDetailsLabels {
2325
2325
  acceptedFileTypes: string;
2326
2326
  uploadingReceipt: string;
2327
2327
  uploadingReceiptBody: string;
2328
+ readingReceipt: string;
2328
2329
  loadFailed: string;
2329
2330
  }
2330
2331
 
@@ -7,14 +7,14 @@ import { invalidateAllClients as t } from "../../../../shared/data-access/dist/l
7
7
  import { useEmbedApi as n } from "../../../../shared/data-access/dist/lib/EmbedApiContext.js";
8
8
  import { organizationHeaders as r } from "../../../../shared/data-access/dist/lib/organizationHeaders.js";
9
9
  import "../../../../shared/data-access/dist/index.js";
10
- import { analyticsReceiptsInvalidationKey as i, analyticsTransactionsInvalidationKey as a, receiptsIdInvalidationKey as o, receiptsInvalidationKey as s, transactionsIdInvalidationKey as c, transactionsInvalidationKey as l } from "./queryKeys.js";
11
- import { useCallback as u, useEffect as d, useRef as f } from "react";
10
+ import { analyticsReceiptsInvalidationKey as i, analyticsTransactionsInvalidationKey as a, receiptsIdInvalidationKey as o, receiptsInvalidationKey as s, transactionsIdExpenseHistoryInvalidationKey as c, transactionsIdInvalidationKey as l, transactionsInvalidationKey as u } from "./queryKeys.js";
11
+ import { useCallback as d, useEffect as f, useRef as p } from "react";
12
12
  //#region ../../libs/tesouro-embedded-components-react/expense-management-widget/data-access/dist/lib/useTrackReceiptMatching.js
13
- var p = 3e3, m = 30, h = 10;
14
- function g(e) {
13
+ var m = 3e3, h = 30, g = 10;
14
+ function _(e) {
15
15
  return e.transaction_id ? "matched" : e.ocr_status === "processing" ? null : e.ocr_status === "error" ? "unreadable" : "unmatched";
16
16
  }
17
- function _(e, t) {
17
+ function v(e, t) {
18
18
  return new Promise((n, r) => {
19
19
  if (t.aborted) {
20
20
  r(new DOMException("Aborted", "AbortError"));
@@ -28,83 +28,136 @@ function _(e, t) {
28
28
  t.addEventListener("abort", i, { once: !0 });
29
29
  });
30
30
  }
31
- function v({ intervalMs: v = p, maxAttempts: y = m } = {}) {
32
- let { client: b, organizationId: x } = n(), S = f(null);
33
- d(() => {
31
+ function y({ intervalMs: y = m, maxAttempts: b = h } = {}) {
32
+ let { client: x, organizationId: S } = n(), C = p(null);
33
+ f(() => {
34
34
  let e = new AbortController();
35
- return S.current = e, () => e.abort();
35
+ return C.current = e, () => e.abort();
36
36
  }, []);
37
- let C = u(() => Promise.all([
37
+ let w = d(() => Promise.all([
38
38
  t(s({
39
- client: b,
40
- organizationId: x
39
+ client: x,
40
+ organizationId: S
41
41
  })),
42
- t(l({
43
- client: b,
44
- organizationId: x
42
+ t(u({
43
+ client: x,
44
+ organizationId: S
45
45
  })),
46
46
  t(i({
47
- client: b,
48
- organizationId: x
47
+ client: x,
48
+ organizationId: S
49
49
  })),
50
50
  t(a({
51
- client: b,
52
- organizationId: x
51
+ client: x,
52
+ organizationId: S
53
53
  }))
54
- ]), [b, x]);
55
- return { trackBatch: u(async (n) => {
56
- let i = {
57
- total: n.length,
58
- matched: 0,
59
- unmatched: 0,
60
- unreadable: 0,
61
- stillProcessing: 0
62
- };
63
- if (n.length === 0) return i;
64
- let a = new Set(n), s = S.current?.signal ?? new AbortController().signal;
65
- await C();
66
- for (let n = 0; n < y && a.size > 0; n++) {
67
- if (s.aborted) throw new DOMException("Aborted", "AbortError");
68
- let { data: l } = await e({
69
- client: b,
70
- headers: r(x),
71
- query: {
72
- id__in: [...a],
73
- limit: h
74
- },
75
- signal: s,
76
- throwOnError: !0
77
- }), u = [], d = [];
78
- for (let e of l?.data ?? []) {
79
- if (!a.has(e.id)) continue;
80
- let t = g(e);
81
- t && (a.delete(e.id), i[t] += 1, u.push(e.id), t === "matched" && e.transaction_id && d.push(e.transaction_id));
54
+ ]), [x, S]);
55
+ return {
56
+ trackBatch: d(async (n) => {
57
+ let i = {
58
+ total: n.length,
59
+ matched: 0,
60
+ unmatched: 0,
61
+ unreadable: 0,
62
+ stillProcessing: 0
63
+ };
64
+ if (n.length === 0) return i;
65
+ let a = new Set(n), s = C.current?.signal ?? new AbortController().signal;
66
+ await w();
67
+ for (let n = 0; n < b && a.size > 0; n++) {
68
+ if (s.aborted) throw new DOMException("Aborted", "AbortError");
69
+ let { data: c } = await e({
70
+ client: x,
71
+ headers: r(S),
72
+ query: {
73
+ id__in: [...a],
74
+ limit: g
75
+ },
76
+ signal: s,
77
+ throwOnError: !0
78
+ }), u = [], d = [];
79
+ for (let e of c?.data ?? []) {
80
+ if (!a.has(e.id)) continue;
81
+ let t = _(e);
82
+ t && (a.delete(e.id), i[t] += 1, u.push(e.id), t === "matched" && e.transaction_id && d.push(e.transaction_id));
83
+ }
84
+ u.length > 0 && await Promise.all([
85
+ w(),
86
+ ...u.map((e) => t(o({
87
+ client: x,
88
+ organizationId: S,
89
+ receiptId: e
90
+ }))),
91
+ ...d.map((e) => t(l({
92
+ client: x,
93
+ organizationId: S,
94
+ transactionId: e
95
+ })))
96
+ ]), a.size > 0 && n < b - 1 && await v(y, s);
82
97
  }
83
- u.length > 0 && await Promise.all([
84
- C(),
85
- ...u.map((e) => t(o({
86
- client: b,
87
- organizationId: x,
88
- receiptId: e
89
- }))),
90
- ...d.map((e) => t(c({
91
- client: b,
92
- organizationId: x,
93
- transactionId: e
94
- })))
95
- ]), a.size > 0 && n < y - 1 && await _(v, s);
96
- }
97
- return {
98
- ...i,
99
- stillProcessing: a.size
100
- };
101
- }, [
102
- b,
103
- v,
104
- y,
105
- x,
106
- C
107
- ]) };
98
+ return {
99
+ ...i,
100
+ stillProcessing: a.size
101
+ };
102
+ }, [
103
+ x,
104
+ y,
105
+ b,
106
+ S,
107
+ w
108
+ ]),
109
+ trackAttachedReceipt: d(async ({ receiptId: n, transactionId: i }) => {
110
+ let a = C.current?.signal ?? new AbortController().signal;
111
+ for (let s = 0; s < b; s++) {
112
+ if (a.aborted) throw new DOMException("Aborted", "AbortError");
113
+ let u, d = !1;
114
+ try {
115
+ let { data: t } = await e({
116
+ client: x,
117
+ headers: r(S),
118
+ query: {
119
+ id__in: [n],
120
+ limit: 1
121
+ },
122
+ signal: a,
123
+ throwOnError: !0
124
+ });
125
+ u = t?.data?.find((e) => e.id === n);
126
+ } catch (e) {
127
+ if (a.aborted) throw e;
128
+ d = !0;
129
+ }
130
+ if (!d && u?.ocr_status !== "processing") {
131
+ await Promise.all([
132
+ w(),
133
+ t(o({
134
+ client: x,
135
+ organizationId: S,
136
+ receiptId: n
137
+ })),
138
+ t(l({
139
+ client: x,
140
+ organizationId: S,
141
+ transactionId: i
142
+ })),
143
+ t(c({
144
+ client: x,
145
+ organizationId: S,
146
+ transactionId: i
147
+ }))
148
+ ]);
149
+ return;
150
+ }
151
+ s < b - 1 && await v(y, a);
152
+ }
153
+ }, [
154
+ x,
155
+ y,
156
+ b,
157
+ S,
158
+ w
159
+ ])
160
+ };
108
161
  }
109
162
  //#endregion
110
- export { g as classifyReceipt, v as useTrackReceiptMatching };
163
+ export { _ as classifyReceipt, y as useTrackReceiptMatching };