@tesouro/embedded-components-react 0.5.298 → 0.5.300

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.
@@ -27,11 +27,16 @@ function m({ initialCounterpartId: m, messages: g, statusLabels: _, filterLabels
27
27
  labels: v
28
28
  });
29
29
  l(() => {
30
+ if (O === A) return;
30
31
  let e = setTimeout(() => {
31
32
  j(O), M();
32
33
  }, 300);
33
34
  return () => clearTimeout(e);
34
- }, [M, O]);
35
+ }, [
36
+ A,
37
+ M,
38
+ O
39
+ ]);
35
40
  let P = S[0]?.id, F = P ? h[P] : void 0, I = S[0] ? S[0].desc ? "desc" : "asc" : void 0, L = e({
36
41
  enabled: b,
37
42
  type: "invoice",
@@ -28,10 +28,16 @@ var e = { scenarios: {
28
28
  error: "The invoices read fails with a 500, so the table shows Failed to load receivables. Try again re-issues the read, which fails again.",
29
29
  paginated: "Sixteen invoices at ten a page. The next and previous arrows follow the pagination token; a search, status filter or new page size starts again from page one."
30
30
  },
31
- scenarios: { "no-customers": {
32
- label: "No customers yet",
33
- blurb: "No invoices and no customers. Press Create, open the Customer picker and choose to create one, give it a name, email and address, and it is selected for the invoice; add an item and create."
34
- } }
31
+ scenarios: {
32
+ "no-customers": {
33
+ label: "No customers yet",
34
+ blurb: "No invoices and no customers. Press Create, open the Customer picker and choose to create one, give it a name, email and address, and it is selected for the invoice; add an item and create."
35
+ },
36
+ "writes-failing": {
37
+ label: "Actions fail",
38
+ blurb: "The same eight invoices, but the API refuses to issue, send, record a payment or cancel, each with its own reason. Every other write still works, so a draft saved on the way to issuing is kept."
39
+ }
40
+ }
35
41
  };
36
42
  //#endregion
37
43
  export { e as INVOICING_LABELS, t as RECEIVABLES_LABELS };
@@ -1,17 +1,17 @@
1
1
  import { Scope as e } from "../../../../shared/data-access/dist/lib/scopes.js";
2
2
  import "../../../../shared/data-access/dist/index.js";
3
3
  import { AN_EXTERNAL_BANK_ACCOUNT as t, AN_OUTSTANDING_INVOICE as n, A_BANK_ACCOUNT as r } from "../../../../shared/data-access-mocks/dist/lib/fixtures.js";
4
- import { AN_ENTITY_BANK_ACCOUNT as i, AN_OVERDUE_REMINDER as a, A_FILE as o, A_PAYMENT_REMINDER as s, A_PAYMENT_TERMS as c, A_RECEIVABLE_HISTORY_ENTRY as l, A_RECEIVABLE_MAIL as u } from "./fixtures.js";
5
- import { RECEIVABLES_LABELS as d } from "./labels.js";
6
- import { SCENARIO_LABELS as f } from "../../../../shared/data-access-mocks/dist/mocks/scenarios/labels.js";
7
- import { EMBEDDED_PAGING as p, FINOPS as m, PROXY as h, bodyOf as g, endpoint as _, initRoute as v, json as y, noContent as b, problem as x } from "../../../../shared/data-access-mocks/dist/mocks/scenarios/scenario.js";
8
- import { MintKind as S, finopsOffsetPage as C, listOverride as w, minter as T, notFound as E } from "../../../../shared/data-access-mocks/dist/mocks/scenarios/worlds.js";
9
- import { CUSTOMERS as D, CUSTOMER_ADDRESSES as O, CUSTOMER_INVOICES as k, billTo as A, customerRoutes as j, customerWorld as ee, filterInvoices as te, id as M, invoice as N, lineItem as P } from "../../../../counterparts-widget/feature/dist/mocks/counterparts.js";
4
+ import { AN_ENTITY_BANK_ACCOUNT as i, AN_OVERDUE_REMINDER as a, A_FILE as o, A_PAYMENT_RECORD as s, A_PAYMENT_REMINDER as c, A_PAYMENT_TERMS as l, A_RECEIVABLE_HISTORY_ENTRY as u, A_RECEIVABLE_MAIL as d } from "./fixtures.js";
5
+ import { RECEIVABLES_LABELS as f } from "./labels.js";
6
+ import { SCENARIO_LABELS as p } from "../../../../shared/data-access-mocks/dist/mocks/scenarios/labels.js";
7
+ import { EMBEDDED_PAGING as m, FINOPS as h, PROXY as g, bodyOf as _, endpoint as v, initRoute as y, json as b, noContent as x, problem as S } from "../../../../shared/data-access-mocks/dist/mocks/scenarios/scenario.js";
8
+ import { MintKind as C, finopsOffsetPage as w, listOverride as ee, minter as T, notFound as E } from "../../../../shared/data-access-mocks/dist/mocks/scenarios/worlds.js";
9
+ import { CUSTOMERS as D, CUSTOMER_ADDRESSES as te, CUSTOMER_INVOICES as O, billTo as ne, customerRoutes as re, customerWorld as ie, filterInvoices as ae, id as k, invoice as A, lineItem as j } from "../../../../counterparts-widget/feature/dist/mocks/counterparts.js";
10
10
  import "../../../../counterparts-widget/feature/dist/scenarios.js";
11
- import { productRoutes as F, productWorld as I } from "../../../../products-widget/feature/dist/mocks/products.js";
11
+ import { productRoutes as oe, productWorld as se } from "../../../../products-widget/feature/dist/mocks/products.js";
12
12
  import "../../../../products-widget/feature/dist/scenarios.js";
13
13
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/mocks/receivables.js
14
- var L = [
14
+ var M = [
15
15
  e.InvoiceReadOrg,
16
16
  e.InvoiceWriteOrg,
17
17
  e.CounterpartReadOrg,
@@ -22,16 +22,16 @@ var L = [
22
22
  e.BankAccountWriteOrg,
23
23
  e.ExternalBankAccountReadOrg,
24
24
  e.PaymentRecordWriteOrg
25
- ], R = {
26
- ...c,
27
- id: M(350)
28
- }, z = [{
29
- ...R,
30
- id: M(351),
25
+ ], N = {
26
+ ...l,
27
+ id: k(350)
28
+ }, P = [{
29
+ ...N,
30
+ id: k(351),
31
31
  name: "Net 15",
32
32
  description: "Payment due 15 days after the issue date.",
33
33
  term_final: { number_of_days: 15 }
34
- }, R], B = [
34
+ }, N], F = [
35
35
  "Copywriting",
36
36
  "Photo retouching",
37
37
  "Event staffing",
@@ -42,7 +42,7 @@ var L = [
42
42
  "Signage install"
43
43
  ].map((e, t) => {
44
44
  let n = D[t % D.length];
45
- return N(352 + t, n, [P(352 + t, e, 4 + t, 8e3, "hour")], {
45
+ return A(352 + t, n, [j(352 + t, e, 4 + t, 8e3, "hour")], {
46
46
  document_id: `INV-10${String(10 + t)}`,
47
47
  status: "paid",
48
48
  amount_paid: (4 + t) * 8e3,
@@ -50,31 +50,90 @@ var L = [
50
50
  due_date: `2026-04-${String(2 + t * 3).padStart(2, "0")}`,
51
51
  created_at: `2026-03-${String(2 + t * 3).padStart(2, "0")}T09:00:00.000Z`
52
52
  });
53
- }), V = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10), H = (e, t) => {
53
+ }), I = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10), L = (e, t) => {
54
54
  let n = /* @__PURE__ */ new Date(`${e}T00:00:00.000Z`);
55
55
  return n.setUTCDate(n.getUTCDate() + t), n.toISOString().slice(0, 10);
56
+ }, R = 12, z = {
57
+ month: 1,
58
+ quarter: 3,
59
+ year: 12
60
+ }, B = {
61
+ day: 1,
62
+ week: 7
56
63
  };
57
- function U(e, t) {
64
+ function V(e, t, n) {
65
+ let r = /* @__PURE__ */ new Date(`${e}T00:00:00.000Z`), i = z[t];
66
+ if (!i) return r.setUTCDate(r.getUTCDate() + (B[t] ?? 1) * n), r.toISOString().slice(0, 10);
67
+ let a = r.getUTCFullYear(), o = r.getUTCMonth() + i * n, s = new Date(Date.UTC(a, o + 1, 0)).getUTCDate();
68
+ return new Date(Date.UTC(a, o, Math.min(r.getUTCDate(), s))).toISOString().slice(0, 10);
69
+ }
70
+ function H(e) {
71
+ let { start_date: t, frequency: n, interval: r, max_occurrences: i, end_date: a } = e, o = i ?? (a ? Infinity : R), s = [];
72
+ for (let e = 0; e < o; e += 1) {
73
+ let i = V(t, n, e * r);
74
+ if (a && i > a) break;
75
+ s.push({
76
+ iteration: e + 1,
77
+ issue_at: i,
78
+ issued_invoice_id: null,
79
+ status: "pending"
80
+ });
81
+ }
82
+ return s;
83
+ }
84
+ function ce(e, t) {
58
85
  return e.flatMap((e) => {
59
86
  let n = {
60
- ...l,
61
- id: t(S.HistoryEvent),
87
+ ...u,
88
+ id: t(C.HistoryEvent),
62
89
  receivable_id: e.id,
63
90
  timestamp: e.created_at
64
91
  };
65
- return e.status === "draft" ? [n] : [n, {
66
- ...n,
67
- id: t(S.HistoryEvent),
68
- event_type: "status_changed",
69
- event_data: {
70
- old_status: "draft",
71
- new_status: e.status
92
+ return e.status === "draft" ? [n] : [
93
+ n,
94
+ {
95
+ ...n,
96
+ id: t(C.HistoryEvent),
97
+ event_type: "status_changed",
98
+ event_data: {
99
+ old_status: "draft",
100
+ new_status: e.status
101
+ },
102
+ timestamp: e.updated_at
72
103
  },
73
- timestamp: e.updated_at
74
- }];
104
+ {
105
+ ...n,
106
+ id: t(C.HistoryEvent),
107
+ event_type: "mail_sent",
108
+ event_data: { mail_status: "sent" },
109
+ timestamp: e.updated_at
110
+ }
111
+ ];
112
+ });
113
+ }
114
+ function le(e, t) {
115
+ return e.filter((e) => e.amount_paid > 0).map((e) => {
116
+ let n = e.paid_at ?? e.updated_at;
117
+ return {
118
+ ...s,
119
+ id: t(C.PaymentRecord),
120
+ amount: e.amount_paid,
121
+ currency: e.currency,
122
+ paid_at: n,
123
+ history: [{
124
+ status: "succeeded",
125
+ timestamp: n
126
+ }],
127
+ object: {
128
+ id: e.id,
129
+ type: "receivable",
130
+ old_status: "issued",
131
+ new_status: e.status
132
+ }
133
+ };
75
134
  });
76
135
  }
77
- function W(e) {
136
+ function U(e) {
78
137
  let t = e.line_items.filter((e) => e.tax_status === "taxable"), n = (e) => e.reduce((e, t) => e + t.total_before_tax, 0), r = n(e.line_items), i = n(t), a = e.discount, o = a ? Math.min(r, a.type === "amount" ? a.amount : Math.round(r * a.amount / 1e4)) : 0, s = i - (r > 0 ? Math.round(i / r * o) : 0), c = t.reduce((e, t) => e + t.total_before_tax * (t.product.tax_rate?.value ?? 0), 0), l = a ? i > 0 ? Math.round(c * s / i / 1e4) : 0 : e.line_items.reduce((e, t) => e + t.total_after_tax - t.total_before_tax, 0), u = r - o + l;
79
138
  return {
80
139
  ...e,
@@ -90,24 +149,24 @@ function W(e) {
90
149
  amount_due: Math.max(0, u - e.amount_paid)
91
150
  };
92
151
  }
93
- function G(e, t, n) {
152
+ function W(e, t, n) {
94
153
  return {
95
- ...P(n ?? e.mint(S.LineItem), t.product?.name ?? "", t.quantity ?? 1, t.product?.price?.value ?? 0, t.product?.measure_unit?.name, t.tax_rate_value ?? 0),
154
+ ...j(n ?? e.mint(C.LineItem), t.product?.name ?? "", t.quantity ?? 1, t.product?.price?.value ?? 0, t.product?.measure_unit?.name, t.tax_rate_value ?? 0),
96
155
  ...t.tax_status ? { tax_status: t.tax_status } : {},
97
156
  ...t.discount ? { discount: t.discount } : {}
98
157
  };
99
158
  }
100
- function K(e) {
101
- let t = z.find((t) => t.id === e.payment_terms_id);
159
+ function G(e) {
160
+ let t = P.find((t) => t.id === e.payment_terms_id);
102
161
  if (t) return t;
103
162
  if (e.payment_terms?.term_final) return { term_final: e.payment_terms.term_final };
104
163
  if (e.payment_terms_id === null || e.payment_terms === null) return null;
105
164
  }
106
- function q(e, t) {
107
- let n = K(e)?.term_final;
108
- return n?.end_date ? n.end_date : n?.number_of_days !== void 0 && n.number_of_days !== null ? H(t, n.number_of_days) : e.due_date ?? null;
165
+ function K(e, t) {
166
+ let n = G(e)?.term_final;
167
+ return n?.end_date ? n.end_date : n?.number_of_days !== void 0 && n.number_of_days !== null ? L(t, n.number_of_days) : e.due_date ?? null;
109
168
  }
110
- function J(e, t) {
169
+ function q(e, t) {
111
170
  return (t ?? []).flatMap((t) => {
112
171
  let n = e.files.find((e) => e.id === t.id);
113
172
  return n ? [{
@@ -116,71 +175,117 @@ function J(e, t) {
116
175
  }] : [];
117
176
  });
118
177
  }
119
- var Y = `${m}/receivables`;
178
+ var J = `${h}/receivables`, ue = `${h}/analytics/receivables`, Y = {
179
+ issue: "The customer has no billing address on file.",
180
+ send: "The mail server rejected the message.",
181
+ payment: "The payment date falls in a closed accounting period.",
182
+ cancel: "The invoice has a payment in progress."
183
+ };
184
+ function de() {
185
+ let e = (e) => () => S(422, "Unprocessable Entity", e);
186
+ return [
187
+ v("POST", `${J}/:id/issue`, e(Y.issue)),
188
+ v("POST", `${J}/:id/send`, e(Y.send)),
189
+ v("POST", `${h}/payment-records`, e(Y.payment)),
190
+ v("POST", `${J}/:id/cancel`, e(Y.cancel))
191
+ ];
192
+ }
193
+ function fe(e, t) {
194
+ let n = t.get("type"), r = t.getAll("status__in"), i = t.get("aggregation_function") === "count", a = /* @__PURE__ */ new Map();
195
+ for (let t of e) {
196
+ if (n && t.type !== n || r.length && !r.includes(t.status)) continue;
197
+ let e = i ? 1 : t.total_amount ?? 0;
198
+ a.set(t.status, (a.get(t.status) ?? 0) + e);
199
+ }
200
+ return { data: [...a].map(([e, t]) => ({
201
+ dimension_value: e,
202
+ metric_value: t
203
+ })) };
204
+ }
120
205
  function X(e) {
121
- let t = g(e);
206
+ let t = _(e);
122
207
  return {
123
208
  paid_at: t.paid_at ?? (/* @__PURE__ */ new Date()).toISOString(),
124
209
  ...t.comment ? { comment: t.comment } : {},
125
210
  ...t.is_external == null ? {} : { is_external: t.is_external }
126
211
  };
127
212
  }
128
- function Z({ invoices: e = k, customers: c = D, list: d }) {
129
- let f = T(), v = {
213
+ function Z({ invoices: e = O, customers: l = D, list: f, writes: p }) {
214
+ let y = T(), k = {
130
215
  invoices: [...e],
131
- history: U(e, f),
216
+ history: ce(e, y),
132
217
  mails: e.some((e) => e.id === n.id) ? [{
133
218
  receivable_id: n.id,
134
- mail: u
219
+ mail: d
135
220
  }] : [],
136
221
  bankDetails: [i],
137
222
  files: [],
138
- paymentReminders: [s],
223
+ paymentRecords: le(e, y),
224
+ recurrences: [],
225
+ paymentReminders: [c],
139
226
  overdueReminders: [a],
140
- mint: f,
227
+ mint: y,
141
228
  nextNumber: 1050
142
- }, M = ee(c, O.filter((e) => c.some((t) => t.id === e.counterpart_id)), () => v.invoices, f), P = I(void 0, void 0, f), L = (e) => v.invoices.find((t) => t.id === e), R = (e) => (v.invoices = v.invoices.map((t) => t.id === e.id ? e : t), e), B = (e, t, n) => v.history.push({
143
- ...l,
144
- id: f(S.HistoryEvent),
229
+ }, j = ie(l, te.filter((e) => l.some((t) => t.id === e.counterpart_id)), () => k.invoices, y), M = se(void 0, void 0, y), N = (e) => k.invoices.find((t) => t.id === e), F = (e) => (k.invoices = k.invoices.map((t) => t.id === e.id ? e : t), e), R = (e, t, n) => k.history.push({
230
+ ...u,
231
+ id: y(C.HistoryEvent),
145
232
  receivable_id: e.id,
146
233
  event_type: t,
147
234
  event_data: n,
148
235
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
149
- }), Z = (e, t) => (B(e, "status_changed", {
236
+ }), z = (e, t) => (R(e, "status_changed", {
150
237
  old_status: e.status,
151
238
  new_status: t
152
- }), R({
239
+ }), F({
153
240
  ...e,
154
241
  status: t,
155
242
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
156
- })), Q = (e, t, n) => _(e, `${Y}/:id${t}`, (e, { id: t }) => {
157
- let r = L(t);
243
+ })), B = (e, t, n) => {
244
+ let r = Math.min(e.total_amount ?? 0, e.amount_paid + t), i = U({
245
+ ...e,
246
+ amount_paid: r
247
+ });
248
+ return R(e, "payment_received", {
249
+ amount_paid: t,
250
+ amount_due: i.amount_due,
251
+ ...n
252
+ }), F({
253
+ ...z(e, i.amount_due === 0 ? "paid" : "partially_paid"),
254
+ amount_paid: i.amount_paid,
255
+ amount_due: i.amount_due
256
+ });
257
+ }, V = (e) => (k.recurrences = k.recurrences.map((t) => t.id === e.id ? e : t), b(e)), Y = (e, t, n) => v(e, `${h}/recurrences/:id${t}`, (e, { id: t }) => {
258
+ let r = k.recurrences.find((e) => e.id === t);
259
+ return r ? n(r, e) : E();
260
+ }), Z = (e, t, n) => v(e, `${J}/:id${t}`, (e, { id: t }) => {
261
+ let r = N(t);
158
262
  return r ? n(r, e) : E();
159
263
  });
160
264
  return [
161
- ...d ? [w(d, Y, () => v.invoices)] : [],
162
- _("GET", `${m}/payment-terms`, () => y({ data: z })),
163
- _("GET", `${m}/bank-details`, () => y({
164
- data: v.bankDetails,
265
+ ...f ? [ee(f, J, () => k.invoices)] : [],
266
+ ...p === "failing" ? de() : [],
267
+ v("GET", `${h}/payment-terms`, () => b({ data: P })),
268
+ v("GET", `${h}/bank-details`, () => b({
269
+ data: k.bankDetails,
165
270
  next_pagination_token: null
166
271
  })),
167
- _("POST", `${m}/bank-details`, (e) => {
168
- let t = g(e), n = {
272
+ v("POST", `${h}/bank-details`, (e) => {
273
+ let t = _(e), n = {
169
274
  ...i,
170
- id: f(S.BankDetails),
275
+ id: y(C.BankDetails),
171
276
  account_holder_name: t.account_holder_name ?? null,
172
277
  account_number: null,
173
278
  account_number_last4: t.account_number?.slice(-4) ?? null,
174
279
  display_name: t.display_name ?? null,
175
280
  routing_number: t.routing_number ?? null
176
281
  };
177
- return v.bankDetails.push(n), y(n, 201);
282
+ return k.bankDetails.push(n), b(n, 201);
178
283
  }),
179
- _("GET", `${m}/payment-reminders`, () => y({ data: v.paymentReminders })),
180
- _("POST", `${m}/payment-reminders`, (e) => {
181
- let t = g(e), n = (/* @__PURE__ */ new Date()).toISOString(), r = {
182
- ...s,
183
- id: f(S.PaymentReminder),
284
+ v("GET", `${h}/payment-reminders`, () => b({ data: k.paymentReminders })),
285
+ v("POST", `${h}/payment-reminders`, (e) => {
286
+ let t = _(e), n = (/* @__PURE__ */ new Date()).toISOString(), r = {
287
+ ...c,
288
+ id: y(C.PaymentReminder),
184
289
  created_at: n,
185
290
  updated_at: n,
186
291
  name: t.name ?? "",
@@ -189,143 +294,156 @@ function Z({ invoices: e = k, customers: c = D, list: d }) {
189
294
  term_2_reminder: t.term_2_reminder ?? null,
190
295
  term_final_reminder: t.term_final_reminder ?? null
191
296
  };
192
- return v.paymentReminders.push(r), y(r, 201);
297
+ return k.paymentReminders.push(r), b(r, 201);
193
298
  }),
194
- _("GET", `${m}/overdue-reminders`, () => y({ data: v.overdueReminders })),
195
- _("POST", `${m}/overdue-reminders`, (e) => {
196
- let t = g(e), n = (/* @__PURE__ */ new Date()).toISOString(), r = {
299
+ v("GET", `${h}/overdue-reminders`, () => b({ data: k.overdueReminders })),
300
+ v("POST", `${h}/overdue-reminders`, (e) => {
301
+ let t = _(e), n = (/* @__PURE__ */ new Date()).toISOString(), r = {
197
302
  ...a,
198
- id: f(S.OverdueReminder),
303
+ id: y(C.OverdueReminder),
199
304
  created_at: n,
200
305
  updated_at: n,
201
306
  name: t.name ?? "",
202
307
  recipients: t.recipients ?? null,
203
308
  terms: t.terms ?? null
204
309
  };
205
- return v.overdueReminders.push(r), y(r, 201);
310
+ return k.overdueReminders.push(r), b(r, 201);
206
311
  }),
207
- _("GET", `${h}/bank-accounts`, () => y({
312
+ v("GET", `${g}/bank-accounts`, () => b({
208
313
  data: [r],
209
- [p.next]: null
314
+ [m.next]: null
210
315
  })),
211
- _("GET", `${h}/external-bank-accounts`, () => y({
316
+ v("GET", `${g}/external-bank-accounts`, () => b({
212
317
  data: [t],
213
- [p.next]: null
318
+ [m.next]: null
214
319
  })),
215
- _("GET", Y, ({ query: e }) => y(C(te(v.invoices, e), e))),
216
- _("POST", Y, (e) => {
217
- let t = g(e), n = M.customers.find((e) => e.id === t.counterpart_id);
218
- if (!n) return x(422, "Unprocessable Entity", "Unknown customer.");
219
- let r = (/* @__PURE__ */ new Date()).toISOString(), i = W(N(f(S.Invoice), n, (t.line_items ?? []).map((e) => G(v, e)), {
320
+ v("GET", J, ({ query: e }) => b(w(ae(k.invoices, e), e))),
321
+ v("POST", J, (e) => {
322
+ let t = _(e), n = j.customers.find((e) => e.id === t.counterpart_id);
323
+ if (!n) return S(422, "Unprocessable Entity", "Unknown customer.");
324
+ let r = (/* @__PURE__ */ new Date()).toISOString(), i = U(A(y(C.Invoice), n, (t.line_items ?? []).map((e) => W(k, e)), {
220
325
  document_id: null,
221
326
  status: "draft",
222
327
  currency: t.currency ?? "USD",
223
328
  issue_date: null,
224
- due_date: q(t, V()),
329
+ due_date: K(t, I()),
225
330
  memo: t.memo || null,
226
331
  footer: t.footer || null,
227
- payment_terms: K(t) ?? null,
332
+ payment_terms: G(t) ?? null,
228
333
  discount: t.discount ?? null,
229
334
  bank_account_id: t.bank_account_id ?? null,
230
335
  bank_account_type: t.bank_account_type ?? null,
231
336
  payment_reminder_id: t.payment_reminder_id ?? null,
232
337
  overdue_reminder_id: t.overdue_reminder_id ?? null,
233
- attachments: J(v, t.attachments),
338
+ attachments: q(k, t.attachments),
234
339
  created_at: r,
235
340
  updated_at: r
236
341
  }));
237
- return v.invoices.unshift(i), B(i, "receivable_created", {
342
+ return k.invoices.unshift(i), R(i, "receivable_created", {
238
343
  source: "manual",
239
344
  status: "draft"
240
- }), y(i, 201);
345
+ }), b(i, 201);
241
346
  }),
242
- Q("GET", "", (e) => y(e)),
243
- Q("PATCH", "", (e, t) => {
244
- let { line_items: n, ...r } = g(t).invoice ?? {}, i = M.customers.find((t) => t.id === (r.counterpart_id ?? e.counterpart_id)), a = new Set(n?.remove ?? []), o = [...e.line_items.filter((e) => !a.has(e.id)).map((e) => {
347
+ Z("GET", "", (e) => b(e)),
348
+ Z("PATCH", "", (e, t) => {
349
+ let { line_items: n, ...r } = _(t).invoice ?? {}, i = j.customers.find((t) => t.id === (r.counterpart_id ?? e.counterpart_id)), a = new Set(n?.remove ?? []), o = [...e.line_items.filter((e) => !a.has(e.id)).map((e) => {
245
350
  let t = n?.replace?.find((t) => t.id === e.id);
246
- return t ? G(v, t.data, e.id) : e;
247
- }), ...(n?.add ?? []).map((e) => G(v, e))];
248
- B(e, "receivable_updated", {});
351
+ return t ? W(k, t.data, e.id) : e;
352
+ }), ...(n?.add ?? []).map((e) => W(k, e))];
353
+ R(e, "receivable_updated", {});
249
354
  let s = r.issue_date ?? e.issue_date;
250
- return y(R(W({
355
+ return b(F(U({
251
356
  ...e,
252
- ...i ? A(i) : {},
357
+ ...i ? ne(i) : {},
253
358
  currency: r.currency ?? e.currency,
254
359
  issue_date: s,
255
360
  memo: r.memo ?? e.memo,
256
361
  ..."discount" in r ? { discount: r.discount ?? null } : {},
257
362
  footer: r.footer ?? e.footer,
258
- due_date: q(r, s ?? V()) ?? e.due_date,
259
- payment_terms: K(r) === void 0 ? e.payment_terms : K(r),
363
+ due_date: K(r, s ?? I()) ?? e.due_date,
364
+ payment_terms: G(r) === void 0 ? e.payment_terms : G(r),
260
365
  ...r.bank_account_id === void 0 ? {} : {
261
366
  bank_account_id: r.bank_account_id,
262
367
  bank_account_type: r.bank_account_type ?? null
263
368
  },
264
369
  ...r.payment_reminder_id === void 0 ? {} : { payment_reminder_id: r.payment_reminder_id },
265
370
  ...r.overdue_reminder_id === void 0 ? {} : { overdue_reminder_id: r.overdue_reminder_id },
266
- ...r.attachments === void 0 ? {} : { attachments: J(v, r.attachments) },
371
+ ...r.attachments === void 0 ? {} : { attachments: q(k, r.attachments) },
267
372
  line_items: o,
268
373
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
269
374
  })));
270
375
  }),
271
- _("DELETE", `${Y}/:id`, (e, { id: t }) => (v.invoices = v.invoices.filter((e) => e.id !== t), b())),
272
- _("GET", `${Y}/:id/history`, ({ query: e }, { id: t }) => y(C(v.history.filter((e) => e.receivable_id === t).sort((e, t) => t.timestamp.localeCompare(e.timestamp)), e))),
273
- _("GET", `${Y}/:id/mails`, ({ query: e }, { id: t }) => y(C(v.mails.filter((e) => e.receivable_id === t).map((e) => e.mail), e))),
274
- _("GET", `${Y}/:id/pdf-link`, () => y({
376
+ v("DELETE", `${J}/:id`, (e, { id: t }) => (k.invoices = k.invoices.filter((e) => e.id !== t), x())),
377
+ v("GET", `${J}/:id/history`, ({ query: e }, { id: t }) => b(w(k.history.filter((e) => e.receivable_id === t).sort((e, t) => t.timestamp.localeCompare(e.timestamp)), e))),
378
+ v("GET", `${J}/:id/mails`, ({ query: e }, { id: t }) => b(w(k.mails.filter((e) => e.receivable_id === t).map((e) => e.mail), e))),
379
+ v("GET", `${J}/:id/pdf-link`, () => b({
275
380
  file_url: null,
276
381
  original_file_url: null
277
382
  })),
278
- Q("POST", "/issue", (e) => {
279
- let t = Z(e, "issued"), n = e.issue_date ?? V();
280
- return y(R({
383
+ Z("POST", "/issue", (e) => {
384
+ let t = z(e, "issued"), n = e.issue_date ?? I();
385
+ return b(F({
281
386
  ...t,
282
- document_id: `INV-${v.nextNumber++}`,
387
+ document_id: `INV-${k.nextNumber++}`,
283
388
  issue_date: n,
284
- due_date: e.due_date ?? H(n, 30)
389
+ due_date: e.due_date ?? L(n, 30)
285
390
  }));
286
391
  }),
287
- Q("POST", "/cancel", (e) => y(Z(e, "canceled"))),
288
- Q("POST", "/mark-as-uncollectible", (e, t) => {
289
- let { comment: n } = g(t);
290
- return y(Z(n ? {
392
+ Z("POST", "/cancel", (e) => b(z(e, "canceled"))),
393
+ Z("POST", "/mark-as-uncollectible", (e, t) => {
394
+ let { comment: n } = _(t);
395
+ return b(z(n ? {
291
396
  ...e,
292
397
  comment: n
293
398
  } : e, "uncollectible"));
294
399
  }),
295
- Q("POST", "/mark-as-paid", (e, t) => {
400
+ Z("POST", "/mark-as-paid", (e, t) => {
296
401
  let n = X(t), r = e.total_amount ?? 0;
297
- B(e, "payment_received", {
402
+ R(e, "payment_received", {
298
403
  amount_paid: r - e.amount_paid,
299
404
  amount_due: 0,
300
405
  ...n
301
406
  });
302
- let i = Z(e, "paid");
303
- return y(R({
407
+ let i = z(e, "paid");
408
+ return b(F({
304
409
  ...i,
305
410
  amount_paid: r,
306
411
  amount_due: 0,
307
412
  paid_at: n.paid_at
308
413
  }));
309
414
  }),
310
- Q("POST", "/mark-as-partially-paid", (e, t) => {
311
- let n = g(t).amount_paid ?? 0, r = Math.min(e.total_amount ?? 0, e.amount_paid + n), i = W({
312
- ...e,
313
- amount_paid: r
314
- });
315
- return B(e, "payment_received", {
316
- amount_paid: n,
317
- amount_due: i.amount_due,
318
- ...X(t)
319
- }), y(R({
320
- ...Z(e, i.amount_due === 0 ? "paid" : "partially_paid"),
321
- amount_paid: i.amount_paid,
322
- amount_due: i.amount_due
323
- }));
415
+ Z("POST", "/mark-as-partially-paid", (e, t) => {
416
+ let n = _(t).amount_paid ?? 0;
417
+ return b(B(e, n, X(t)));
418
+ }),
419
+ v("GET", `${h}/payment-records`, ({ query: e }) => b(w(k.paymentRecords.filter((t) => t.object.id === e.get("object_id")), e))),
420
+ v("POST", `${h}/payment-records`, (e) => {
421
+ let t = _(e), n = N(t.object?.id ?? "");
422
+ if (!n) return E();
423
+ let r = X(e), i = B(n, t.amount ?? 0, r), a = {
424
+ ...s,
425
+ id: y(C.PaymentRecord),
426
+ amount: t.amount ?? 0,
427
+ currency: t.currency ?? n.currency,
428
+ is_external: t.is_external ?? !0,
429
+ paid_at: r.paid_at,
430
+ history: [{
431
+ status: "succeeded",
432
+ timestamp: r.paid_at
433
+ }],
434
+ object: {
435
+ id: n.id,
436
+ type: "receivable",
437
+ old_status: n.status,
438
+ new_status: i.status
439
+ }
440
+ };
441
+ return k.paymentRecords.push(a), b(a, 201);
324
442
  }),
325
- Q("POST", "/clone", (e) => {
443
+ Z("POST", "/clone", (e) => {
326
444
  let t = (/* @__PURE__ */ new Date()).toISOString(), n = {
327
445
  ...e,
328
- id: f(S.Invoice),
446
+ id: y(C.Invoice),
329
447
  document_id: null,
330
448
  status: "draft",
331
449
  issue_date: null,
@@ -335,15 +453,15 @@ function Z({ invoices: e = k, customers: c = D, list: d }) {
335
453
  created_at: t,
336
454
  updated_at: t
337
455
  };
338
- return v.invoices.unshift(n), B(n, "receivable_created", {
456
+ return k.invoices.unshift(n), R(n, "receivable_created", {
339
457
  source: "based_on",
340
458
  status: "draft"
341
- }), y(n, 201);
459
+ }), b(n, 201);
342
460
  }),
343
- Q("POST", "/send", (e, t) => {
344
- let n = g(t), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
345
- ...u,
346
- id: f(S.Mail),
461
+ Z("POST", "/send", (e, t) => {
462
+ let n = _(t), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
463
+ ...d,
464
+ id: y(C.Mail),
347
465
  created_at: r,
348
466
  updated_at: r,
349
467
  recipients: { to: (n.recipients?.to ?? []).map((e) => ({
@@ -351,60 +469,119 @@ function Z({ invoices: e = k, customers: c = D, list: d }) {
351
469
  is_success: !0
352
470
  })) }
353
471
  };
354
- return v.mails.push({
472
+ return k.mails.push({
355
473
  receivable_id: e.id,
356
474
  mail: i
357
- }), B(e, "mail_sent", {
475
+ }), R(e, "mail_sent", {
358
476
  mail_id: i.id,
359
477
  mail_status: "sent"
360
- }), y({ mail_id: i.id });
478
+ }), b({ mail_id: i.id });
479
+ }),
480
+ v("GET", `${h}/recurrences`, () => b({ data: k.recurrences })),
481
+ v("POST", `${h}/recurrences`, (e) => {
482
+ let t = _(e), n = N(t.invoice_id ?? "");
483
+ if (!n) return E();
484
+ let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
485
+ start_date: t.start_date ?? I(),
486
+ frequency: t.frequency ?? "month",
487
+ interval: t.interval ?? 1,
488
+ max_occurrences: t.max_occurrences ?? null,
489
+ end_date: t.end_date ?? null
490
+ }, a = {
491
+ ...i,
492
+ id: y(C.Recurrence),
493
+ created_at: r,
494
+ updated_at: r,
495
+ invoice_id: n.id,
496
+ automation_level: t.automation_level ?? "issue",
497
+ subject_text: t.subject_text ?? null,
498
+ body_text: t.body_text ?? null,
499
+ recipients: t.recipients ?? null,
500
+ current_iteration: 0,
501
+ status: "active",
502
+ iterations: H(i)
503
+ };
504
+ return k.recurrences.push(a), F({
505
+ ...z(n, "recurring"),
506
+ recurrence_id: a.id
507
+ }), b(a, 201);
361
508
  }),
362
- _("POST", `${m}/files`, (e) => {
363
- let { file: t } = g(e), n = {
364
- id: f(S.File),
509
+ Y("GET", "", (e) => b(e)),
510
+ Y("PATCH", "", (e, t) => {
511
+ let n = {
512
+ ...e,
513
+ ..._(t),
514
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
515
+ };
516
+ return V({
517
+ ...n,
518
+ iterations: H(n)
519
+ });
520
+ }),
521
+ Y("POST", "/pause", (e) => V({
522
+ ...e,
523
+ status: "paused"
524
+ })),
525
+ Y("POST", "/resume", (e) => V({
526
+ ...e,
527
+ status: "active"
528
+ })),
529
+ Y("POST", "/cancel", (e) => V({
530
+ ...e,
531
+ status: "canceled",
532
+ iterations: e.iterations.map((e) => e.status === "pending" ? {
533
+ ...e,
534
+ status: "canceled"
535
+ } : e)
536
+ })),
537
+ v("POST", `${h}/files`, (e) => {
538
+ let { file: t } = _(e), n = {
539
+ id: y(C.File),
365
540
  name: t?.name ?? "attachment",
366
541
  size: t?.size ?? 0,
367
542
  mimetype: t?.type || "application/octet-stream",
368
543
  url: `https://example.com/attachments/${encodeURIComponent(t?.name ?? "attachment")}`
369
544
  };
370
- return v.files.push(n), y({
545
+ return k.files.push(n), b({
371
546
  ...o,
372
547
  ...n,
373
548
  file_type: "attachments"
374
549
  }, 201);
375
550
  }),
376
- _("GET", `${m}/files`, ({ query: e }) => {
551
+ v("GET", `${h}/files`, ({ query: e }) => {
377
552
  let t = e.getAll("id__in");
378
- return y({ data: v.files.filter((e) => t.includes(e.id)).map((e) => ({
553
+ return b({ data: k.files.filter((e) => t.includes(e.id)).map((e) => ({
379
554
  ...o,
380
555
  ...e
381
556
  })) });
382
557
  }),
383
- _("DELETE", `${m}/files/:id`, (e, { id: t }) => (v.files = v.files.filter((e) => e.id !== t), b())),
384
- ...j(M),
385
- ...F(P)
558
+ v("DELETE", `${h}/files/:id`, (e, { id: t }) => (k.files = k.files.filter((e) => e.id !== t), x())),
559
+ (e) => e.method === "GET" && e.path === ue && e.query.get("dimension") === "status" ? b(fe(k.invoices, e.query)) : void 0,
560
+ ...re(j),
561
+ ...oe(M)
386
562
  ];
387
563
  }
388
564
  function Q(e, t, n = {}) {
389
565
  return {
390
566
  key: e,
391
567
  ...t,
392
- routes: () => [v(L), ...Z(n)]
568
+ routes: () => [y(M), ...Z(n)]
393
569
  };
394
570
  }
395
571
  var $ = (e, t = {}) => Q(e, {
396
- label: f[e].label,
397
- blurb: d.blurbs[e]
398
- }, t), ne = [
572
+ label: p[e].label,
573
+ blurb: f.blurbs[e]
574
+ }, t), pe = [
399
575
  $("populated"),
400
576
  $("empty", { invoices: [] }),
401
577
  $("loading", { list: "held" }),
402
578
  $("error", { list: "failing" }),
403
- $("paginated", { invoices: [...k, ...B] }),
404
- Q("no-customers", d.scenarios["no-customers"], {
579
+ $("paginated", { invoices: [...O, ...F] }),
580
+ Q("no-customers", f.scenarios["no-customers"], {
405
581
  invoices: [],
406
582
  customers: []
407
- })
583
+ }),
584
+ Q("writes-failing", f.scenarios["writes-failing"], { writes: "failing" })
408
585
  ];
409
586
  //#endregion
410
- export { ne as receivablesScenarios };
587
+ export { Y as REFUSED_WRITE_REASONS, pe as receivablesScenarios };
@@ -35,7 +35,9 @@ var u = (e, t) => (e ?? "").toLowerCase().includes(t.toLowerCase()), d = () => a
35
35
  PaymentReminder: "a",
36
36
  OverdueReminder: "b",
37
37
  BankAccount: "c",
38
- ExternalAccount: "d"
38
+ ExternalAccount: "d",
39
+ PaymentRecord: "e",
40
+ Recurrence: "f"
39
41
  };
40
42
  function h() {
41
43
  let e = 0;
@@ -1,5 +1,5 @@
1
1
  //#region ../../libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js
2
- var e = "@tesouro/embedded-components-react", t = "0.5.298", n = "d92815559b211a2b13703877b83e8b03b7480d48", r = Object.freeze({
2
+ var e = "@tesouro/embedded-components-react", t = "0.5.300", n = "7475f80ff3e4d108ae108bdfaa7d95124502ed00", r = Object.freeze({
3
3
  library_name: e,
4
4
  library_version: t,
5
5
  library_sha: n
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tesouro/embedded-components-react",
3
- "version": "0.5.298",
3
+ "version": "0.5.300",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": [