@develit-services/bank 6.2.0 → 6.2.1

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.
@@ -33,6 +33,10 @@ declare const BANK_SERVICE_BINDINGS: {
33
33
  readonly kind: "d1";
34
34
  readonly suffix: "bank";
35
35
  };
36
+ readonly BANK_SYNC_R2: {
37
+ readonly kind: "r2";
38
+ readonly suffix: "bank-sync-payloads";
39
+ };
36
40
  readonly QUEUE_BUS_QUEUE: {
37
41
  readonly kind: "queueProducer";
38
42
  readonly suffix: "queue-bus";
@@ -73,6 +77,10 @@ declare const baseBankServiceConfig: (project: string, version: string, options?
73
77
  readonly kind: "d1";
74
78
  readonly suffix: "bank";
75
79
  };
80
+ readonly BANK_SYNC_R2: {
81
+ readonly kind: "r2";
82
+ readonly suffix: "bank-sync-payloads";
83
+ };
76
84
  readonly QUEUE_BUS_QUEUE: {
77
85
  readonly kind: "queueProducer";
78
86
  readonly suffix: "queue-bus";
@@ -112,6 +120,10 @@ declare const baseBankServiceConfig: (project: string, version: string, options?
112
120
  readonly kind: "d1";
113
121
  readonly suffix: "bank";
114
122
  };
123
+ readonly BANK_SYNC_R2: {
124
+ readonly kind: "r2";
125
+ readonly suffix: "bank-sync-payloads";
126
+ };
115
127
  readonly QUEUE_BUS_QUEUE: {
116
128
  readonly kind: "queueProducer";
117
129
  readonly suffix: "queue-bus";
@@ -155,6 +167,10 @@ declare function bankServiceConfig(project: string, version: string, options?: P
155
167
  readonly kind: "d1";
156
168
  readonly suffix: "bank";
157
169
  };
170
+ readonly BANK_SYNC_R2: {
171
+ readonly kind: "r2";
172
+ readonly suffix: "bank-sync-payloads";
173
+ };
158
174
  readonly QUEUE_BUS_QUEUE: {
159
175
  readonly kind: "queueProducer";
160
176
  readonly suffix: "queue-bus";
@@ -196,6 +212,10 @@ declare function bankServiceConfig(project: string, version: string, options?: P
196
212
  readonly kind: "d1";
197
213
  readonly suffix: "bank";
198
214
  };
215
+ readonly BANK_SYNC_R2: {
216
+ readonly kind: "r2";
217
+ readonly suffix: "bank-sync-payloads";
218
+ };
199
219
  readonly QUEUE_BUS_QUEUE: {
200
220
  readonly kind: "queueProducer";
201
221
  readonly suffix: "queue-bus";
@@ -33,6 +33,10 @@ declare const BANK_SERVICE_BINDINGS: {
33
33
  readonly kind: "d1";
34
34
  readonly suffix: "bank";
35
35
  };
36
+ readonly BANK_SYNC_R2: {
37
+ readonly kind: "r2";
38
+ readonly suffix: "bank-sync-payloads";
39
+ };
36
40
  readonly QUEUE_BUS_QUEUE: {
37
41
  readonly kind: "queueProducer";
38
42
  readonly suffix: "queue-bus";
@@ -73,6 +77,10 @@ declare const baseBankServiceConfig: (project: string, version: string, options?
73
77
  readonly kind: "d1";
74
78
  readonly suffix: "bank";
75
79
  };
80
+ readonly BANK_SYNC_R2: {
81
+ readonly kind: "r2";
82
+ readonly suffix: "bank-sync-payloads";
83
+ };
76
84
  readonly QUEUE_BUS_QUEUE: {
77
85
  readonly kind: "queueProducer";
78
86
  readonly suffix: "queue-bus";
@@ -112,6 +120,10 @@ declare const baseBankServiceConfig: (project: string, version: string, options?
112
120
  readonly kind: "d1";
113
121
  readonly suffix: "bank";
114
122
  };
123
+ readonly BANK_SYNC_R2: {
124
+ readonly kind: "r2";
125
+ readonly suffix: "bank-sync-payloads";
126
+ };
115
127
  readonly QUEUE_BUS_QUEUE: {
116
128
  readonly kind: "queueProducer";
117
129
  readonly suffix: "queue-bus";
@@ -155,6 +167,10 @@ declare function bankServiceConfig(project: string, version: string, options?: P
155
167
  readonly kind: "d1";
156
168
  readonly suffix: "bank";
157
169
  };
170
+ readonly BANK_SYNC_R2: {
171
+ readonly kind: "r2";
172
+ readonly suffix: "bank-sync-payloads";
173
+ };
158
174
  readonly QUEUE_BUS_QUEUE: {
159
175
  readonly kind: "queueProducer";
160
176
  readonly suffix: "queue-bus";
@@ -196,6 +212,10 @@ declare function bankServiceConfig(project: string, version: string, options?: P
196
212
  readonly kind: "d1";
197
213
  readonly suffix: "bank";
198
214
  };
215
+ readonly BANK_SYNC_R2: {
216
+ readonly kind: "r2";
217
+ readonly suffix: "bank-sync-payloads";
218
+ };
199
219
  readonly QUEUE_BUS_QUEUE: {
200
220
  readonly kind: "queueProducer";
201
221
  readonly suffix: "queue-bus";
package/dist/service.d.ts CHANGED
@@ -33,6 +33,10 @@ declare const BANK_SERVICE_BINDINGS: {
33
33
  readonly kind: "d1";
34
34
  readonly suffix: "bank";
35
35
  };
36
+ readonly BANK_SYNC_R2: {
37
+ readonly kind: "r2";
38
+ readonly suffix: "bank-sync-payloads";
39
+ };
36
40
  readonly QUEUE_BUS_QUEUE: {
37
41
  readonly kind: "queueProducer";
38
42
  readonly suffix: "queue-bus";
@@ -73,6 +77,10 @@ declare const baseBankServiceConfig: (project: string, version: string, options?
73
77
  readonly kind: "d1";
74
78
  readonly suffix: "bank";
75
79
  };
80
+ readonly BANK_SYNC_R2: {
81
+ readonly kind: "r2";
82
+ readonly suffix: "bank-sync-payloads";
83
+ };
76
84
  readonly QUEUE_BUS_QUEUE: {
77
85
  readonly kind: "queueProducer";
78
86
  readonly suffix: "queue-bus";
@@ -112,6 +120,10 @@ declare const baseBankServiceConfig: (project: string, version: string, options?
112
120
  readonly kind: "d1";
113
121
  readonly suffix: "bank";
114
122
  };
123
+ readonly BANK_SYNC_R2: {
124
+ readonly kind: "r2";
125
+ readonly suffix: "bank-sync-payloads";
126
+ };
115
127
  readonly QUEUE_BUS_QUEUE: {
116
128
  readonly kind: "queueProducer";
117
129
  readonly suffix: "queue-bus";
@@ -155,6 +167,10 @@ declare function bankServiceConfig(project: string, version: string, options?: P
155
167
  readonly kind: "d1";
156
168
  readonly suffix: "bank";
157
169
  };
170
+ readonly BANK_SYNC_R2: {
171
+ readonly kind: "r2";
172
+ readonly suffix: "bank-sync-payloads";
173
+ };
158
174
  readonly QUEUE_BUS_QUEUE: {
159
175
  readonly kind: "queueProducer";
160
176
  readonly suffix: "queue-bus";
@@ -196,6 +212,10 @@ declare function bankServiceConfig(project: string, version: string, options?: P
196
212
  readonly kind: "d1";
197
213
  readonly suffix: "bank";
198
214
  };
215
+ readonly BANK_SYNC_R2: {
216
+ readonly kind: "r2";
217
+ readonly suffix: "bank-sync-payloads";
218
+ };
199
219
  readonly QUEUE_BUS_QUEUE: {
200
220
  readonly kind: "queueProducer";
201
221
  readonly suffix: "queue-bus";
package/dist/service.mjs CHANGED
@@ -4,6 +4,9 @@ const BANK_SERVICE_BINDINGS = {
4
4
  SECRETS_STORE: { kind: "service", target: "secrets-store", bare: true },
5
5
  BANK_KV: { kind: "kv", suffix: "bank" },
6
6
  BANK_D1: { kind: "d1", suffix: "bank" },
7
+ // Spillover for `fetch bank payments` results too large to return from a
8
+ // Workflow step directly — see sync-payments-store.ts.
9
+ BANK_SYNC_R2: { kind: "r2", suffix: "bank-sync-payloads" },
7
10
  QUEUE_BUS_QUEUE: { kind: "queueProducer", suffix: "queue-bus" },
8
11
  NOTIFICATIONS_QUEUE: { kind: "queueProducer", suffix: "notifications" },
9
12
  SYNC_ACCOUNT_PAYMENTS_WORKFLOW: {
@@ -3656,7 +3656,7 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
3656
3656
  name: string;
3657
3657
  tableName: "payment";
3658
3658
  dataType: "string enum";
3659
- data: "PROCESSING" | "BOOKED" | "REJECTED" | "PENDING" | "CANCELLED" | "SCHEDULED" | "HOLD" | "INFO";
3659
+ data: "PROCESSING" | "PENDING" | "BOOKED" | "CANCELLED" | "REJECTED" | "SCHEDULED" | "HOLD" | "INFO";
3660
3660
  driverParam: string;
3661
3661
  notNull: true;
3662
3662
  hasDefault: false;
@@ -4160,7 +4160,7 @@ declare const paymentRequest: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
4160
4160
  name: string;
4161
4161
  tableName: "payment_request";
4162
4162
  dataType: "string enum";
4163
- data: "AUTHORIZED" | "COMPLETED" | "OPENED" | "BOOKED" | "SETTLED" | "REJECTED" | "CLOSED";
4163
+ data: "AUTHORIZED" | "COMPLETED" | "BOOKED" | "REJECTED" | "OPENED" | "SETTLED" | "CLOSED";
4164
4164
  driverParam: string;
4165
4165
  notNull: true;
4166
4166
  hasDefault: false;
@@ -3656,7 +3656,7 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
3656
3656
  name: string;
3657
3657
  tableName: "payment";
3658
3658
  dataType: "string enum";
3659
- data: "PROCESSING" | "BOOKED" | "REJECTED" | "PENDING" | "CANCELLED" | "SCHEDULED" | "HOLD" | "INFO";
3659
+ data: "PROCESSING" | "PENDING" | "BOOKED" | "CANCELLED" | "REJECTED" | "SCHEDULED" | "HOLD" | "INFO";
3660
3660
  driverParam: string;
3661
3661
  notNull: true;
3662
3662
  hasDefault: false;
@@ -4160,7 +4160,7 @@ declare const paymentRequest: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
4160
4160
  name: string;
4161
4161
  tableName: "payment_request";
4162
4162
  dataType: "string enum";
4163
- data: "AUTHORIZED" | "COMPLETED" | "OPENED" | "BOOKED" | "SETTLED" | "REJECTED" | "CLOSED";
4163
+ data: "AUTHORIZED" | "COMPLETED" | "BOOKED" | "REJECTED" | "OPENED" | "SETTLED" | "CLOSED";
4164
4164
  driverParam: string;
4165
4165
  notNull: true;
4166
4166
  hasDefault: false;
@@ -3656,7 +3656,7 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
3656
3656
  name: string;
3657
3657
  tableName: "payment";
3658
3658
  dataType: "string enum";
3659
- data: "PROCESSING" | "BOOKED" | "REJECTED" | "PENDING" | "CANCELLED" | "SCHEDULED" | "HOLD" | "INFO";
3659
+ data: "PROCESSING" | "PENDING" | "BOOKED" | "CANCELLED" | "REJECTED" | "SCHEDULED" | "HOLD" | "INFO";
3660
3660
  driverParam: string;
3661
3661
  notNull: true;
3662
3662
  hasDefault: false;
@@ -4160,7 +4160,7 @@ declare const paymentRequest: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
4160
4160
  name: string;
4161
4161
  tableName: "payment_request";
4162
4162
  dataType: "string enum";
4163
- data: "AUTHORIZED" | "COMPLETED" | "OPENED" | "BOOKED" | "SETTLED" | "REJECTED" | "CLOSED";
4163
+ data: "AUTHORIZED" | "COMPLETED" | "BOOKED" | "REJECTED" | "OPENED" | "SETTLED" | "CLOSED";
4164
4164
  driverParam: string;
4165
4165
  notNull: true;
4166
4166
  hasDefault: false;
@@ -1,4 +1,4 @@
1
- import { e as CurrencyCode, R as BankCode, a1 as CountryCode, P as PaymentRequestSelectType } from './bank.r1xIlFBl.js';
1
+ import { e as CurrencyCode, R as BankCode, a1 as CountryCode, P as PaymentRequestSelectType } from './bank.B5yr_YIB.js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  type ReferenceType = `${'VS' | 'SS' | 'KS'}:${number}`;
@@ -1,4 +1,4 @@
1
- import { e as CurrencyCode, R as BankCode, a1 as CountryCode, P as PaymentRequestSelectType } from './bank.r1xIlFBl.mjs';
1
+ import { e as CurrencyCode, R as BankCode, a1 as CountryCode, P as PaymentRequestSelectType } from './bank.B5yr_YIB.cjs';
2
2
  import { z } from 'zod';
3
3
 
4
4
  type ReferenceType = `${'VS' | 'SS' | 'KS'}:${number}`;
@@ -1,4 +1,4 @@
1
- import { uuidv4, createInternalError, bicSchema, useResult, structuredAddressSchema } from '@develit-io/backend-sdk';
1
+ import { uuidv4, createInternalError, bicSchema, useResult, isInternalError, structuredAddressSchema } from '@develit-io/backend-sdk';
2
2
  import { format, parseISO } from 'date-fns';
3
3
  import { s as schema, h as account, i as accountCredentials, o as ott } from './bank.BT7HayCV.mjs';
4
4
  import { defineRelations, and, not, inArray, isNull } from 'drizzle-orm';
@@ -1520,6 +1520,19 @@ class CsobConnector extends FinbricksConnector {
1520
1520
  }
1521
1521
  }
1522
1522
 
1523
+ function extractErrorDetails(err) {
1524
+ if (err instanceof Error) return { message: err.message };
1525
+ if (typeof err === "object" && err !== null && "message" in err) {
1526
+ const obj = err;
1527
+ return {
1528
+ message: String(obj.message),
1529
+ status: typeof obj.status === "number" ? obj.status : void 0,
1530
+ code: typeof obj.code === "string" ? obj.code : void 0
1531
+ };
1532
+ }
1533
+ return { message: JSON.stringify(err) };
1534
+ }
1535
+
1523
1536
  const dbuAccountConfigSchema = z.object({
1524
1537
  with4EyeApproval: z.enum(["Y", "N"]).default("Y"),
1525
1538
  realizeImmediate: z.enum(["Y", "N"]).default("Y"),
@@ -1529,6 +1542,42 @@ const dbuAccountConfigSchema = z.object({
1529
1542
  partialRealization: z.enum(["Y", "N"]).default("N"),
1530
1543
  forceRealization: z.enum(["Y", "N"]).default("N")
1531
1544
  });
1545
+ const LOG_PREVIEW_BYTES = 500;
1546
+ function previewForLog(value) {
1547
+ const json = JSON.stringify(value);
1548
+ if (json === void 0 || json.length <= LOG_PREVIEW_BYTES) return value;
1549
+ return {
1550
+ preview: json.slice(0, LOG_PREVIEW_BYTES),
1551
+ truncated: true,
1552
+ fullLength: json.length
1553
+ };
1554
+ }
1555
+ const FETCH_RETRY_ATTEMPTS = 3;
1556
+ const FETCH_RETRY_BASE_DELAY_MS = 250;
1557
+ async function fetchWithRetry(fetcher, url, init, requestId) {
1558
+ for (let attempt = 1; attempt <= FETCH_RETRY_ATTEMPTS; attempt++) {
1559
+ try {
1560
+ return await fetcher.fetch(url, init);
1561
+ } catch (error) {
1562
+ const isLastAttempt = attempt === FETCH_RETRY_ATTEMPTS;
1563
+ console.warn(
1564
+ JSON.stringify({
1565
+ event: "[DBU] fetch failed",
1566
+ requestId,
1567
+ attempt,
1568
+ maxAttempts: FETCH_RETRY_ATTEMPTS,
1569
+ willRetry: !isLastAttempt,
1570
+ error: extractErrorDetails(error).message
1571
+ })
1572
+ );
1573
+ if (isLastAttempt) throw error;
1574
+ await new Promise(
1575
+ (resolve) => setTimeout(resolve, FETCH_RETRY_BASE_DELAY_MS * attempt)
1576
+ );
1577
+ }
1578
+ }
1579
+ throw new Error("fetchWithRetry: exhausted attempts without a result");
1580
+ }
1532
1581
  class DbuConnector extends IBankConnector {
1533
1582
  constructor({
1534
1583
  BASE_URL,
@@ -1598,20 +1647,21 @@ class DbuConnector extends IBankConnector {
1598
1647
  fetchOptions.body = JSON.stringify(body);
1599
1648
  }
1600
1649
  console.log(
1601
- "[DBU] request",
1602
- JSON.stringify(
1603
- {
1604
- method,
1605
- url: url.toString(),
1606
- requestId,
1607
- headers: defaultHeaders,
1608
- body: body ?? null
1609
- },
1610
- null,
1611
- 2
1612
- )
1650
+ JSON.stringify({
1651
+ event: "[DBU] request",
1652
+ method,
1653
+ url: url.toString(),
1654
+ requestId,
1655
+ headers: defaultHeaders,
1656
+ body: previewForLog(body ?? null)
1657
+ })
1658
+ );
1659
+ response = await fetchWithRetry(
1660
+ this.api,
1661
+ url.toString(),
1662
+ fetchOptions,
1663
+ requestId
1613
1664
  );
1614
- response = await this.api.fetch(url.toString(), fetchOptions);
1615
1665
  const responseText = await response.text().catch(() => "unable to read response");
1616
1666
  if (!response.ok) {
1617
1667
  let parsedBody = responseText;
@@ -1646,21 +1696,18 @@ class DbuConnector extends IBankConnector {
1646
1696
  parseError: parseError instanceof Error ? parseError.message : String(parseError)
1647
1697
  });
1648
1698
  throw createInternalError(parseError, {
1649
- message: "Failed to parse DBU response as JSON"
1699
+ message: `Failed to parse DBU response as JSON: ${parseError instanceof Error ? parseError.message : String(parseError)} (preview: ${responseText.substring(0, 500)})`
1650
1700
  });
1651
1701
  }
1652
1702
  console.log(
1653
- "[DBU] response",
1654
- JSON.stringify(
1655
- {
1656
- status: response.status,
1657
- url: url.toString(),
1658
- requestId,
1659
- body: data
1660
- },
1661
- null,
1662
- 2
1663
- )
1703
+ JSON.stringify({
1704
+ event: "[DBU] response",
1705
+ status: response.status,
1706
+ url: url.toString(),
1707
+ requestId,
1708
+ bytes: responseText.length,
1709
+ body: previewForLog(data)
1710
+ })
1664
1711
  );
1665
1712
  return data;
1666
1713
  } catch (error) {
@@ -1677,7 +1724,10 @@ class DbuConnector extends IBankConnector {
1677
1724
  stack: error instanceof Error ? error.stack : void 0
1678
1725
  }
1679
1726
  });
1680
- throw error;
1727
+ if (isInternalError(error)) throw error;
1728
+ throw createInternalError(error, {
1729
+ message: `DBU ${method} ${endpoint} (requestId=${requestId}) failed: ${extractErrorDetails(error).message}`
1730
+ });
1681
1731
  }
1682
1732
  }
1683
1733
  mapDbuCurrencyCode(dbuCurrency) {
@@ -1990,14 +2040,14 @@ class DbuConnector extends IBankConnector {
1990
2040
  account,
1991
2041
  filter
1992
2042
  }) {
2043
+ let offset = 0;
2044
+ let pageNumber = 1;
1993
2045
  try {
1994
2046
  const dateFrom = format(filter.dateFrom, "yyyy-MM-dd");
1995
2047
  const dateTo = format(filter.dateTo || /* @__PURE__ */ new Date(), "yyyy-MM-dd");
1996
2048
  const allPayments = [];
1997
- let offset = 0;
1998
- const limit = 10;
2049
+ const limit = 50;
1999
2050
  let hasMoreData = true;
2000
- let pageNumber = 1;
2001
2051
  const baseRequestId = uuidv4().replace(/-/g, "");
2002
2052
  while (hasMoreData) {
2003
2053
  const response = await this.makeRequest(
@@ -2047,8 +2097,10 @@ class DbuConnector extends IBankConnector {
2047
2097
  }
2048
2098
  return allPayments;
2049
2099
  } catch (error) {
2100
+ const details = extractErrorDetails(error);
2050
2101
  throw createInternalError(error, {
2051
- message: "Failed to fetch payments from DBU API"
2102
+ message: `Failed to fetch payments from DBU API (page ${pageNumber}, offset ${offset}): ${details.message}`,
2103
+ code: details.code
2052
2104
  });
2053
2105
  }
2054
2106
  }
@@ -2615,4 +2667,4 @@ const getPaymentDirection = (payment, iban) => {
2615
2667
  return "OUTGOING";
2616
2668
  };
2617
2669
 
2618
- export { useFinbricksFetch as A, BASE_TERMINAL_STATUSES as B, CsobConnector as C, DbuConnector as D, ErsteConnector as E, FINBRICKS_ENDPOINTS as F, tables as G, relations as H, IBankConnector as I, buildEndToEndId as J, KBConnector as K, getNonTerminalPaymentRequestsQuery as L, MockCobsConnector as M, calculateCzechIban as N, FinbricksClient as a, FinbricksConnector as b, MockConnector as c, accountCredentialsInsertSchema as d, accountCredentialsSelectSchema as e, accountCredentialsUpdateSchema as f, accountInsertSchema as g, accountSelectSchema as h, accountUpdateSchema as i, assignAccount as j, dbuAccountConfigSchema as k, hasPaymentAccountAssigned as l, isPaymentCompleted as m, isPendingStatus as n, isProcessedStatus as o, isTerminalStatus as p, ottInsertSchema as q, ottSelectSchema as r, ottUpdateSchema as s, signFinbricksJws as t, toBatchedPayment as u, toBatchedPaymentFromPaymentRequest as v, toCompletedPayment as w, toIncomingPayment as x, toPaymentRequestInsert as y, toPreparedPayment as z };
2670
+ export { useFinbricksFetch as A, BASE_TERMINAL_STATUSES as B, CsobConnector as C, DbuConnector as D, ErsteConnector as E, FINBRICKS_ENDPOINTS as F, tables as G, relations as H, IBankConnector as I, extractErrorDetails as J, KBConnector as K, buildEndToEndId as L, MockCobsConnector as M, getNonTerminalPaymentRequestsQuery as N, calculateCzechIban as O, FinbricksClient as a, FinbricksConnector as b, MockConnector as c, accountCredentialsInsertSchema as d, accountCredentialsSelectSchema as e, accountCredentialsUpdateSchema as f, accountInsertSchema as g, accountSelectSchema as h, accountUpdateSchema as i, assignAccount as j, dbuAccountConfigSchema as k, hasPaymentAccountAssigned as l, isPaymentCompleted as m, isPendingStatus as n, isProcessedStatus as o, isTerminalStatus as p, ottInsertSchema as q, ottSelectSchema as r, ottUpdateSchema as s, signFinbricksJws as t, toBatchedPayment as u, toBatchedPaymentFromPaymentRequest as v, toCompletedPayment as w, toIncomingPayment as x, toPaymentRequestInsert as y, toPreparedPayment as z };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const drizzleOrm = require('drizzle-orm');
4
- const paymentDirection = require('./bank.BrZjHUNG.cjs');
4
+ const paymentDirection = require('./bank.CeQZODQ2.cjs');
5
5
  const backendSdk = require('@develit-io/backend-sdk');
6
6
  require('./bank.Ca3jzmIb.cjs');
7
7
  require('date-fns');
@@ -1522,6 +1522,19 @@ class CsobConnector extends FinbricksConnector {
1522
1522
  }
1523
1523
  }
1524
1524
 
1525
+ function extractErrorDetails(err) {
1526
+ if (err instanceof Error) return { message: err.message };
1527
+ if (typeof err === "object" && err !== null && "message" in err) {
1528
+ const obj = err;
1529
+ return {
1530
+ message: String(obj.message),
1531
+ status: typeof obj.status === "number" ? obj.status : void 0,
1532
+ code: typeof obj.code === "string" ? obj.code : void 0
1533
+ };
1534
+ }
1535
+ return { message: JSON.stringify(err) };
1536
+ }
1537
+
1525
1538
  const dbuAccountConfigSchema = zod.z.object({
1526
1539
  with4EyeApproval: zod.z.enum(["Y", "N"]).default("Y"),
1527
1540
  realizeImmediate: zod.z.enum(["Y", "N"]).default("Y"),
@@ -1531,6 +1544,42 @@ const dbuAccountConfigSchema = zod.z.object({
1531
1544
  partialRealization: zod.z.enum(["Y", "N"]).default("N"),
1532
1545
  forceRealization: zod.z.enum(["Y", "N"]).default("N")
1533
1546
  });
1547
+ const LOG_PREVIEW_BYTES = 500;
1548
+ function previewForLog(value) {
1549
+ const json = JSON.stringify(value);
1550
+ if (json === void 0 || json.length <= LOG_PREVIEW_BYTES) return value;
1551
+ return {
1552
+ preview: json.slice(0, LOG_PREVIEW_BYTES),
1553
+ truncated: true,
1554
+ fullLength: json.length
1555
+ };
1556
+ }
1557
+ const FETCH_RETRY_ATTEMPTS = 3;
1558
+ const FETCH_RETRY_BASE_DELAY_MS = 250;
1559
+ async function fetchWithRetry(fetcher, url, init, requestId) {
1560
+ for (let attempt = 1; attempt <= FETCH_RETRY_ATTEMPTS; attempt++) {
1561
+ try {
1562
+ return await fetcher.fetch(url, init);
1563
+ } catch (error) {
1564
+ const isLastAttempt = attempt === FETCH_RETRY_ATTEMPTS;
1565
+ console.warn(
1566
+ JSON.stringify({
1567
+ event: "[DBU] fetch failed",
1568
+ requestId,
1569
+ attempt,
1570
+ maxAttempts: FETCH_RETRY_ATTEMPTS,
1571
+ willRetry: !isLastAttempt,
1572
+ error: extractErrorDetails(error).message
1573
+ })
1574
+ );
1575
+ if (isLastAttempt) throw error;
1576
+ await new Promise(
1577
+ (resolve) => setTimeout(resolve, FETCH_RETRY_BASE_DELAY_MS * attempt)
1578
+ );
1579
+ }
1580
+ }
1581
+ throw new Error("fetchWithRetry: exhausted attempts without a result");
1582
+ }
1534
1583
  class DbuConnector extends IBankConnector {
1535
1584
  constructor({
1536
1585
  BASE_URL,
@@ -1600,20 +1649,21 @@ class DbuConnector extends IBankConnector {
1600
1649
  fetchOptions.body = JSON.stringify(body);
1601
1650
  }
1602
1651
  console.log(
1603
- "[DBU] request",
1604
- JSON.stringify(
1605
- {
1606
- method,
1607
- url: url.toString(),
1608
- requestId,
1609
- headers: defaultHeaders,
1610
- body: body ?? null
1611
- },
1612
- null,
1613
- 2
1614
- )
1652
+ JSON.stringify({
1653
+ event: "[DBU] request",
1654
+ method,
1655
+ url: url.toString(),
1656
+ requestId,
1657
+ headers: defaultHeaders,
1658
+ body: previewForLog(body ?? null)
1659
+ })
1660
+ );
1661
+ response = await fetchWithRetry(
1662
+ this.api,
1663
+ url.toString(),
1664
+ fetchOptions,
1665
+ requestId
1615
1666
  );
1616
- response = await this.api.fetch(url.toString(), fetchOptions);
1617
1667
  const responseText = await response.text().catch(() => "unable to read response");
1618
1668
  if (!response.ok) {
1619
1669
  let parsedBody = responseText;
@@ -1648,21 +1698,18 @@ class DbuConnector extends IBankConnector {
1648
1698
  parseError: parseError instanceof Error ? parseError.message : String(parseError)
1649
1699
  });
1650
1700
  throw backendSdk.createInternalError(parseError, {
1651
- message: "Failed to parse DBU response as JSON"
1701
+ message: `Failed to parse DBU response as JSON: ${parseError instanceof Error ? parseError.message : String(parseError)} (preview: ${responseText.substring(0, 500)})`
1652
1702
  });
1653
1703
  }
1654
1704
  console.log(
1655
- "[DBU] response",
1656
- JSON.stringify(
1657
- {
1658
- status: response.status,
1659
- url: url.toString(),
1660
- requestId,
1661
- body: data
1662
- },
1663
- null,
1664
- 2
1665
- )
1705
+ JSON.stringify({
1706
+ event: "[DBU] response",
1707
+ status: response.status,
1708
+ url: url.toString(),
1709
+ requestId,
1710
+ bytes: responseText.length,
1711
+ body: previewForLog(data)
1712
+ })
1666
1713
  );
1667
1714
  return data;
1668
1715
  } catch (error) {
@@ -1679,7 +1726,10 @@ class DbuConnector extends IBankConnector {
1679
1726
  stack: error instanceof Error ? error.stack : void 0
1680
1727
  }
1681
1728
  });
1682
- throw error;
1729
+ if (backendSdk.isInternalError(error)) throw error;
1730
+ throw backendSdk.createInternalError(error, {
1731
+ message: `DBU ${method} ${endpoint} (requestId=${requestId}) failed: ${extractErrorDetails(error).message}`
1732
+ });
1683
1733
  }
1684
1734
  }
1685
1735
  mapDbuCurrencyCode(dbuCurrency) {
@@ -1992,14 +2042,14 @@ class DbuConnector extends IBankConnector {
1992
2042
  account,
1993
2043
  filter
1994
2044
  }) {
2045
+ let offset = 0;
2046
+ let pageNumber = 1;
1995
2047
  try {
1996
2048
  const dateFrom = dateFns.format(filter.dateFrom, "yyyy-MM-dd");
1997
2049
  const dateTo = dateFns.format(filter.dateTo || /* @__PURE__ */ new Date(), "yyyy-MM-dd");
1998
2050
  const allPayments = [];
1999
- let offset = 0;
2000
- const limit = 10;
2051
+ const limit = 50;
2001
2052
  let hasMoreData = true;
2002
- let pageNumber = 1;
2003
2053
  const baseRequestId = backendSdk.uuidv4().replace(/-/g, "");
2004
2054
  while (hasMoreData) {
2005
2055
  const response = await this.makeRequest(
@@ -2049,8 +2099,10 @@ class DbuConnector extends IBankConnector {
2049
2099
  }
2050
2100
  return allPayments;
2051
2101
  } catch (error) {
2102
+ const details = extractErrorDetails(error);
2052
2103
  throw backendSdk.createInternalError(error, {
2053
- message: "Failed to fetch payments from DBU API"
2104
+ message: `Failed to fetch payments from DBU API (page ${pageNumber}, offset ${offset}): ${details.message}`,
2105
+ code: details.code
2054
2106
  });
2055
2107
  }
2056
2108
  }
@@ -2638,6 +2690,7 @@ exports.assignAccount = assignAccount;
2638
2690
  exports.buildEndToEndId = buildEndToEndId;
2639
2691
  exports.calculateCzechIban = calculateCzechIban;
2640
2692
  exports.dbuAccountConfigSchema = dbuAccountConfigSchema;
2693
+ exports.extractErrorDetails = extractErrorDetails;
2641
2694
  exports.getNonTerminalPaymentRequestsQuery = getNonTerminalPaymentRequestsQuery;
2642
2695
  exports.hasPaymentAccountAssigned = hasPaymentAccountAssigned;
2643
2696
  exports.isPaymentCompleted = isPaymentCompleted;
@@ -1,4 +1,4 @@
1
- import { e as CurrencyCode, R as BankCode, a1 as CountryCode, P as PaymentRequestSelectType } from './bank.r1xIlFBl.cjs';
1
+ import { e as CurrencyCode, R as BankCode, a1 as CountryCode, P as PaymentRequestSelectType } from './bank.B5yr_YIB.mjs';
2
2
  import { z } from 'zod';
3
3
 
4
4
  type ReferenceType = `${'VS' | 'SS' | 'KS'}:${number}`;
@@ -1,5 +1,5 @@
1
1
  import { sql, and, eq, isNull } from 'drizzle-orm';
2
- import { G as tables, b as FinbricksConnector, J as buildEndToEndId, c as MockConnector, D as DbuConnector, C as CsobConnector, K as KBConnector, M as MockCobsConnector, E as ErsteConnector } from './bank.BTysRSoT.mjs';
2
+ import { G as tables, b as FinbricksConnector, L as buildEndToEndId, c as MockConnector, D as DbuConnector, C as CsobConnector, K as KBConnector, M as MockCobsConnector, E as ErsteConnector } from './bank.CGuCPc4G.mjs';
3
3
  import { uuidv4 } from '@develit-io/backend-sdk';
4
4
  import './bank.BT7HayCV.mjs';
5
5
  import 'date-fns';
package/dist/types.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const paymentDirection = require('./shared/bank.BrZjHUNG.cjs');
3
+ const paymentDirection = require('./shared/bank.CeQZODQ2.cjs');
4
4
  const database_schema = require('./shared/bank.Ca3jzmIb.cjs');
5
5
  const batchLifecycle = require('./shared/bank.NF8bZBy0.cjs');
6
6
  const generalCodes = require('@develit-io/general-codes');