@develit-services/bank 2.2.3 → 2.4.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 (35) hide show
  1. package/dist/database/schema.cjs +2 -1
  2. package/dist/database/schema.d.cts +1 -1
  3. package/dist/database/schema.d.mts +1 -1
  4. package/dist/database/schema.d.ts +1 -1
  5. package/dist/database/schema.mjs +2 -1
  6. package/dist/export/worker.cjs +15 -15
  7. package/dist/export/worker.d.cts +23 -2
  8. package/dist/export/worker.d.mts +23 -2
  9. package/dist/export/worker.d.ts +23 -2
  10. package/dist/export/worker.mjs +4 -4
  11. package/dist/export/workflows.cjs +11 -9
  12. package/dist/export/workflows.mjs +7 -5
  13. package/dist/export/wrangler.cjs +4 -1
  14. package/dist/export/wrangler.d.cts +10 -2
  15. package/dist/export/wrangler.d.mts +10 -2
  16. package/dist/export/wrangler.d.ts +10 -2
  17. package/dist/export/wrangler.mjs +4 -1
  18. package/dist/shared/{bank.B0EWZbAs.cjs → bank.B0I6H6AT.cjs} +1 -1
  19. package/dist/shared/{bank.Cw3K7nIh.d.cts → bank.BI2OxQsM.d.mts} +1 -1
  20. package/dist/shared/{bank.COez_hEH.d.mts → bank.BJ_vbyUT.d.cts} +80 -2
  21. package/dist/shared/{bank.COez_hEH.d.ts → bank.BJ_vbyUT.d.mts} +80 -2
  22. package/dist/shared/{bank.COez_hEH.d.cts → bank.BJ_vbyUT.d.ts} +80 -2
  23. package/dist/shared/{bank.t019WQuV.d.mts → bank.Bs0isbAY.d.ts} +1 -1
  24. package/dist/shared/{bank.VB_ZSWGd.d.ts → bank.Ca0iWjhb.d.cts} +1 -1
  25. package/dist/shared/{bank.CmgGdN-q.mjs → bank.IlVbIEuM.mjs} +389 -31
  26. package/dist/shared/{bank.CQfKMyzc.cjs → bank.c1sHv5v_.cjs} +425 -29
  27. package/dist/shared/{bank.UBWdag5k.mjs → bank.fZkUcrn9.mjs} +1 -1
  28. package/dist/types.cjs +25 -24
  29. package/dist/types.d.cts +30 -8
  30. package/dist/types.d.mts +30 -8
  31. package/dist/types.d.ts +30 -8
  32. package/dist/types.mjs +5 -5
  33. package/package.json +1 -1
  34. package/dist/shared/bank.C7MA33AX.mjs +0 -325
  35. package/dist/shared/bank.CIWYI18z.cjs +0 -363
@@ -1,10 +1,13 @@
1
- import { uuidv4, createInternalError, useResult } from '@develit-io/backend-sdk';
1
+ import { uuidv4, createInternalError, useResult, bankAccount, base, structuredAddressSchema } from '@develit-io/backend-sdk';
2
+ import { sqliteTable, text, integer, unique, real, index } from 'drizzle-orm/sqlite-core';
2
3
  import { format, parseISO } from 'date-fns';
3
- import { CURRENCY_CODES } from '@develit-io/general-codes';
4
- import './bank.C7MA33AX.mjs';
5
- import 'drizzle-orm';
6
4
  import { importPKCS8, SignJWT } from 'jose';
5
+ import { z } from 'zod';
6
+ import { COUNTRY_CODES_2, CURRENCY_CODES, BANK_CODES } from '@develit-io/general-codes';
7
+ import { relations } from 'drizzle-orm/relations';
8
+ import { and, not, inArray, isNull } from 'drizzle-orm';
7
9
  import 'node:crypto';
10
+ import { createInsertSchema, createUpdateSchema, createSelectSchema } from 'drizzle-zod';
8
11
 
9
12
  function toIncomingPayment(input) {
10
13
  return {
@@ -474,6 +477,26 @@ const SEPA_COUNTRIES = /* @__PURE__ */ new Set([
474
477
  "GI",
475
478
  "XK"
476
479
  ]);
480
+ function parseOtherIdentification(value) {
481
+ if (!value) return {};
482
+ const [first, second] = value.split("/");
483
+ if (!first) return {};
484
+ const looksLikeIban = first.length >= 15 && /^[A-Z]{2}\d{2}[A-Z0-9]+$/.test(first);
485
+ if (looksLikeIban) {
486
+ const iban = first;
487
+ const swiftBic = second || void 0;
488
+ if (iban.startsWith("CZ") && iban.length === 24) {
489
+ const bankCode = iban.slice(4, 8);
490
+ const number = iban.slice(14, 24).replace(/^0+/, "") || iban.slice(14, 24);
491
+ return { iban, swiftBic, bankCode, number };
492
+ }
493
+ return { iban, swiftBic };
494
+ }
495
+ return {
496
+ number: first,
497
+ bankCode: second || void 0
498
+ };
499
+ }
477
500
  function detectPaymentType(tx, isIncoming) {
478
501
  const related = tx.entryDetails?.transactionDetails?.relatedParties;
479
502
  const otherParty = isIncoming ? related?.debtorAccount : related?.creditorAccount;
@@ -495,6 +518,12 @@ const mapFinbricksTransactionToPayment = (tx, account) => {
495
518
  const related = tx.entryDetails?.transactionDetails?.relatedParties;
496
519
  const endToEndId = tx.entryDetails.transactionDetails?.references?.endToEndIdentification;
497
520
  const symbolsRegex = /^\/?VS\d+/;
521
+ const debtorParsed = parseOtherIdentification(
522
+ related?.debtorAccount?.identification?.other?.identification
523
+ );
524
+ const creditorParsed = parseOtherIdentification(
525
+ related?.creditorAccount?.identification?.other?.identification
526
+ );
498
527
  const base = {
499
528
  id: uuidv4(),
500
529
  correlationId: uuidv4(),
@@ -512,13 +541,10 @@ const mapFinbricksTransactionToPayment = (tx, account) => {
512
541
  ),
513
542
  creditor: {
514
543
  holderName: related?.creditorAccount?.name || related?.creditor?.name || "Unknown",
515
- iban: isIncoming ? account.iban || void 0 : related?.creditorAccount?.identification?.iban || account.iban || void 0,
516
- number: isIncoming ? account.number || void 0 : related?.creditorAccount?.identification?.other?.identification ? related.creditorAccount.identification.other.identification.split(
517
- "/"
518
- )[0] : account.number || void 0,
519
- bankCode: isIncoming ? account.bankCode || void 0 : related?.creditorAccount?.identification?.other?.identification ? related.creditorAccount.identification.other.identification.split(
520
- "/"
521
- )[1] : account.bankCode || void 0,
544
+ iban: isIncoming ? account.iban || void 0 : related?.creditorAccount?.identification?.iban || creditorParsed.iban || void 0,
545
+ number: isIncoming ? account.number || void 0 : creditorParsed.number || void 0,
546
+ bankCode: isIncoming ? account.bankCode || void 0 : creditorParsed.bankCode || void 0,
547
+ swiftBic: isIncoming ? void 0 : creditorParsed.swiftBic,
522
548
  address: related?.creditor?.postalAddress ? {
523
549
  streetName: related.creditor.postalAddress.streetName,
524
550
  buildingNumber: related.creditor.postalAddress.buildingNumber,
@@ -529,13 +555,10 @@ const mapFinbricksTransactionToPayment = (tx, account) => {
529
555
  },
530
556
  debtor: {
531
557
  holderName: related?.debtorAccount?.name || related?.debtor?.name || "Unknown",
532
- iban: isIncoming ? related?.debtorAccount?.identification?.iban || account.iban || void 0 : account.iban ?? void 0,
533
- number: isIncoming ? related?.debtorAccount?.identification?.other?.identification ? related.debtorAccount.identification.other.identification.split(
534
- "/"
535
- )[0] : account.number || void 0 : account.number || void 0,
536
- bankCode: isIncoming ? related?.debtorAccount?.identification?.other?.identification ? related.debtorAccount.identification.other.identification.split(
537
- "/"
538
- )[1] : account.bankCode || void 0 : account.bankCode || void 0,
558
+ iban: isIncoming ? related?.debtorAccount?.identification?.iban || debtorParsed.iban || void 0 : account.iban ?? void 0,
559
+ number: isIncoming ? debtorParsed.number || void 0 : account.number || void 0,
560
+ bankCode: isIncoming ? debtorParsed.bankCode || void 0 : account.bankCode || void 0,
561
+ swiftBic: isIncoming ? debtorParsed.swiftBic : void 0,
539
562
  address: related?.debtor?.postalAddress ? {
540
563
  streetName: related.debtor.postalAddress.streetName,
541
564
  buildingNumber: related.debtor.postalAddress.buildingNumber,
@@ -667,7 +690,8 @@ class FinbricksConnector extends IBankConnector {
667
690
  connectorKey: this.PROVIDER,
668
691
  currency: acc.currency,
669
692
  iban: acc.identification.iban,
670
- id: acc.id
693
+ id: acc.id,
694
+ config: null
671
695
  }))
672
696
  );
673
697
  return {
@@ -1074,6 +1098,40 @@ class CsobConnector extends FinbricksConnector {
1074
1098
  }
1075
1099
  }
1076
1100
 
1101
+ const PAYMENT_TYPES = ["SEPA", "SWIFT", "DOMESTIC", "UNKNOWN"];
1102
+ const CHARGE_BEARERS = ["SHA", "OUR", "BEN"];
1103
+ const INSTRUCTION_PRIORITIES = ["NORM", "HIGH", "INST"];
1104
+ const PAYMENT_REQUEST_STATUSES = [
1105
+ "OPENED",
1106
+ "AUTHORIZED",
1107
+ "COMPLETED",
1108
+ "BOOKED",
1109
+ "SETTLED",
1110
+ "REJECTED",
1111
+ "CLOSED"
1112
+ ];
1113
+ const PAYMENT_STATUSES = [
1114
+ "PENDING",
1115
+ "PROCESSING",
1116
+ "BOOKED",
1117
+ "CANCELLED",
1118
+ "REJECTED",
1119
+ "SCHEDULED",
1120
+ "HOLD",
1121
+ "INFO"
1122
+ ];
1123
+ const PAYMENT_DIRECTIONS = ["INCOMING", "OUTGOING"];
1124
+ const BATCH_STATUSES = [
1125
+ "PROCESSING",
1126
+ "READY_TO_SIGN",
1127
+ "AUTHORIZED",
1128
+ "COMPLETED",
1129
+ "FAILED"
1130
+ ];
1131
+ const BATCH_MODES = ["NATIVE", "SINGLE"];
1132
+ const ACCOUNT_STATUSES = ["AUTHORIZED", "DISABLED", "EXPIRED"];
1133
+ const COUNTRY_CODES = COUNTRY_CODES_2;
1134
+
1077
1135
  class AirBankConnector extends FinbricksConnector {
1078
1136
  constructor(config) {
1079
1137
  super("AIRBANK", config);
@@ -1332,6 +1390,14 @@ const calculateCzechIban = (accountNumber, bankCode) => {
1332
1390
  return `CZ${checkDigits}${basicIban}`;
1333
1391
  };
1334
1392
 
1393
+ const dbuAccountConfigSchema = z.object({
1394
+ with4EyeApproval: z.enum(["Y", "N"]).default("Y"),
1395
+ channelCode: z.string().default("WWW"),
1396
+ actionTypeCode: z.string().default("TRANSFER"),
1397
+ transactionTypeCode: z.string().default("TRANSFER"),
1398
+ partialRealization: z.enum(["Y", "N"]).default("N"),
1399
+ forceRealization: z.enum(["Y", "N"]).default("N")
1400
+ });
1335
1401
  class DbuConnector extends IBankConnector {
1336
1402
  constructor({
1337
1403
  BASE_URL,
@@ -1353,7 +1419,10 @@ class DbuConnector extends IBankConnector {
1353
1419
  this.api = API;
1354
1420
  this.redirectUri = REDIRECT_URI;
1355
1421
  this.txAuthUri = TX_AUTH_URI;
1356
- this.connectedAccounts = connectedAccounts;
1422
+ this.connectedAccounts = connectedAccounts.map((acc) => ({
1423
+ ...acc,
1424
+ config: dbuAccountConfigSchema.parse(acc.config ?? {})
1425
+ }));
1357
1426
  this.sessionId = uuidv4();
1358
1427
  this.allowedPostEndpoints = [
1359
1428
  "/required-transactions",
@@ -1608,7 +1677,7 @@ class DbuConnector extends IBankConnector {
1608
1677
  return [];
1609
1678
  }
1610
1679
  // ── Single payment methods ──────────────────────────────────────────
1611
- resolveIdAccountDebit(payment) {
1680
+ resolveAccount(payment) {
1612
1681
  const account = this.connectedAccounts.find(
1613
1682
  (acc) => acc.id === payment.accountId
1614
1683
  );
@@ -1618,7 +1687,10 @@ class DbuConnector extends IBankConnector {
1618
1687
  code: "DBU_ACCOUNT_NOT_FOUND"
1619
1688
  });
1620
1689
  }
1621
- return Number(account.bankRefId);
1690
+ return account;
1691
+ }
1692
+ resolveIdAccountDebit(payment) {
1693
+ return Number(this.resolveAccount(payment).bankRefId);
1622
1694
  }
1623
1695
  resolveAccountDetails(account) {
1624
1696
  if (account.number && account.bankCode) {
@@ -1635,13 +1707,15 @@ class DbuConnector extends IBankConnector {
1635
1707
  }
1636
1708
  async initiateInstantPayment(payment) {
1637
1709
  const creditor = this.resolveAccountDetails(payment.creditor);
1710
+ const debtorAccount = this.resolveAccount(payment);
1711
+ const cfg = debtorAccount.config;
1638
1712
  const body = {
1639
1713
  accountNumberCredit: creditor.number,
1640
- idAccountDebit: this.resolveIdAccountDebit(payment),
1714
+ idAccountDebit: Number(debtorAccount.bankRefId),
1641
1715
  bankCodeCredit: creditor.bankCode,
1642
1716
  amount: payment.amount,
1643
1717
  currencyCode: "CZK",
1644
- channelCode: "WWW",
1718
+ channelCode: cfg.channelCode,
1645
1719
  textMessage: payment.message,
1646
1720
  varSymbol: payment.vs,
1647
1721
  specSymbol: payment.ss,
@@ -1675,6 +1749,7 @@ class DbuConnector extends IBankConnector {
1675
1749
  }
1676
1750
  const debtor = this.resolveAccountDetails(payment.debtor);
1677
1751
  const creditor = this.resolveAccountDetails(payment.creditor);
1752
+ const cfg = this.resolveAccount(payment).config;
1678
1753
  const body = {
1679
1754
  accountNumberDebit: debtor.number,
1680
1755
  accountNumberCredit: creditor.number,
@@ -1682,20 +1757,20 @@ class DbuConnector extends IBankConnector {
1682
1757
  bankCodeCredit: creditor.bankCode,
1683
1758
  amount: payment.amount,
1684
1759
  currencyCode: "CZK",
1685
- actionTypeCode: "TRANSFER",
1686
- channelCode: "WWW",
1760
+ actionTypeCode: cfg.actionTypeCode,
1761
+ channelCode: cfg.channelCode,
1687
1762
  textMessage: payment.message,
1688
- transactionTypeCode: "TRANSFER",
1763
+ transactionTypeCode: cfg.transactionTypeCode,
1689
1764
  validFrom: format(/* @__PURE__ */ new Date(), "yyyy-MM-dd"),
1690
1765
  validTo: null,
1691
1766
  subEntity: "DOMESTIC",
1692
- partialRealization: "N",
1693
- forceRealization: "N",
1767
+ partialRealization: cfg.partialRealization,
1768
+ forceRealization: cfg.forceRealization,
1694
1769
  varSymbol: payment.vs,
1695
1770
  specSymbol: payment.ss,
1696
1771
  constSymbol: payment.ks,
1697
1772
  uniqueExternalId: payment.id,
1698
- with4EyeApproval: "Y",
1773
+ with4EyeApproval: cfg.with4EyeApproval,
1699
1774
  applicationCode: this.applicationCode
1700
1775
  };
1701
1776
  const response = await this.makeRequest(
@@ -1891,6 +1966,39 @@ class DbuConnector extends IBankConnector {
1891
1966
  }
1892
1967
  }
1893
1968
 
1969
+ const TERMINAL_STATUSES$1 = /* @__PURE__ */ new Set([
1970
+ "SETTLED",
1971
+ "REJECTED",
1972
+ "CLOSED"
1973
+ ]);
1974
+ const PENDING_STATUSES = /* @__PURE__ */ new Set([
1975
+ "OPENED",
1976
+ "AUTHORIZED"
1977
+ ]);
1978
+ function isTerminalStatus(status) {
1979
+ return TERMINAL_STATUSES$1.has(status);
1980
+ }
1981
+ function isPendingStatus(status) {
1982
+ return PENDING_STATUSES.has(status);
1983
+ }
1984
+ function isProcessedStatus(status) {
1985
+ return !isPendingStatus(status);
1986
+ }
1987
+ function hasPaymentAccountAssigned(payment) {
1988
+ return "accountId" in payment && "connectorKey" in payment && payment.accountId !== void 0 && payment.connectorKey !== void 0;
1989
+ }
1990
+ function isPaymentCompleted(payment) {
1991
+ return (payment.status === "COMPLETED" || payment.status === "BOOKED" || payment.status === "SETTLED" || payment.status === "REJECTED" || payment.status === "CLOSED") && "bankRefId" in payment && typeof payment.bankRefId === "string";
1992
+ }
1993
+
1994
+ const TERMINAL_STATUSES = PAYMENT_REQUEST_STATUSES.filter(isTerminalStatus);
1995
+ const getNonTerminalPaymentRequestsQuery = (db) => db.select().from(tables.paymentRequest).where(
1996
+ and(
1997
+ not(inArray(tables.paymentRequest.status, TERMINAL_STATUSES)),
1998
+ isNull(tables.paymentRequest.deletedAt)
1999
+ )
2000
+ );
2001
+
1894
2002
  class ErsteConnector extends IBankConnector {
1895
2003
  constructor(config) {
1896
2004
  super();
@@ -2305,4 +2413,254 @@ class MockConnector extends IBankConnector {
2305
2413
  }
2306
2414
  }
2307
2415
 
2308
- export { CsobConnector as C, DbuConnector as D, ErsteConnector as E, FINBRICKS_ENDPOINTS as F, IBankConnector as I, KBConnector as K, MockCobsConnector as M, FinbricksClient as a, FinbricksConnector as b, MockConnector as c, assignAccount as d, toBatchedPaymentFromPaymentRequest as e, toCompletedPayment as f, toIncomingPayment as g, toPaymentRequestInsert as h, toPreparedPayment as i, initiateConnector as j, signFinbricksJws as s, toBatchedPayment as t, useFinbricksFetch as u };
2416
+ const CONNECTOR_KEYS = [
2417
+ "ERSTE",
2418
+ "FINBRICKS",
2419
+ "MOCK",
2420
+ "CREDITAS",
2421
+ "MOCK_COBS",
2422
+ "FIO",
2423
+ "MONETA",
2424
+ "DBU",
2425
+ "CSAS",
2426
+ "AIRBANK",
2427
+ "KB",
2428
+ "CSOB"
2429
+ ];
2430
+ const CREDENTIALS_TYPES = [
2431
+ "AUTH_TOKEN",
2432
+ "REFRESH_TOKEN",
2433
+ "CLIENT_ID",
2434
+ "API_KEY"
2435
+ ];
2436
+ const TOKEN_TYPES = ["ACCOUNT_AUTHORIZATION"];
2437
+
2438
+ const account = sqliteTable(
2439
+ "account",
2440
+ {
2441
+ ...base,
2442
+ ...bankAccount,
2443
+ // countryCode is temporary until bankAccount is update to include US country code
2444
+ countryCode: text("country_code", { enum: COUNTRY_CODES }).$type().notNull(),
2445
+ number: text("number").notNull(),
2446
+ name: text("name"),
2447
+ iban: text("iban").notNull(),
2448
+ bankCode: text("bank_code", { enum: BANK_CODES }).notNull(),
2449
+ connectorKey: text("connector_key", {
2450
+ enum: CONNECTOR_KEYS
2451
+ }).$type().notNull(),
2452
+ status: text("status", { enum: ACCOUNT_STATUSES }).$type().notNull(),
2453
+ bankRefId: text("bank_ref_id").notNull(),
2454
+ batchSizeLimit: integer("batch_size_limit").notNull().default(50),
2455
+ syncIntervalS: integer("sync_interval_s").notNull().default(600),
2456
+ lastSyncAt: integer("last_sync_at", { mode: "timestamp_ms" }),
2457
+ lastSyncMetadata: text("last_sync_metadata", {
2458
+ mode: "json"
2459
+ }).$type(),
2460
+ connectorConfig: text("connector_config", {
2461
+ mode: "json"
2462
+ }).$type()
2463
+ },
2464
+ (t) => [unique().on(t.iban)]
2465
+ );
2466
+
2467
+ const accountInsertSchema = createInsertSchema(account, {
2468
+ address: () => structuredAddressSchema.optional()
2469
+ });
2470
+ const accountUpdateSchema = createUpdateSchema(account, {
2471
+ address: () => structuredAddressSchema.optional()
2472
+ });
2473
+ const accountSelectSchema = createSelectSchema(account, {
2474
+ address: () => structuredAddressSchema.nullable()
2475
+ });
2476
+
2477
+ const accountCredentials = sqliteTable("account_credentials", {
2478
+ ...base,
2479
+ accountId: text("account_id").references(() => account.id, { onDelete: "restrict", onUpdate: "cascade" }).notNull(),
2480
+ connectorKey: text("connector_key", {
2481
+ enum: CONNECTOR_KEYS
2482
+ }).$type().notNull(),
2483
+ type: text("type", {
2484
+ enum: CREDENTIALS_TYPES
2485
+ }).$type().notNull(),
2486
+ value: text("value").notNull(),
2487
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull()
2488
+ });
2489
+
2490
+ const accountCredentialsInsertSchema = createInsertSchema(accountCredentials);
2491
+ const accountCredentialsUpdateSchema = createUpdateSchema(accountCredentials);
2492
+ const accountCredentialsSelectSchema = createSelectSchema(accountCredentials);
2493
+
2494
+ const ott = sqliteTable("ott", {
2495
+ ...base,
2496
+ oneTimeToken: text("one_time_token").notNull(),
2497
+ refId: text("ref_id").notNull(),
2498
+ tokenType: text("token_type", { enum: TOKEN_TYPES }).$type().notNull(),
2499
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull()
2500
+ });
2501
+
2502
+ const ottInsertSchema = createInsertSchema(ott);
2503
+ const ottUpdateSchema = createUpdateSchema(ott);
2504
+ const ottSelectSchema = createSelectSchema(ott);
2505
+
2506
+ const batch = sqliteTable("batch", {
2507
+ ...base,
2508
+ batchPaymentInitiatedAt: integer("batch_payment_initiated_at", {
2509
+ mode: "timestamp_ms"
2510
+ }),
2511
+ authorizationUrls: text("authorization_urls", { mode: "json" }).$type(),
2512
+ accountId: text("account_id").references(() => account.id, {
2513
+ onDelete: "restrict",
2514
+ onUpdate: "cascade"
2515
+ }),
2516
+ status: text("status", { enum: BATCH_STATUSES }).$type(),
2517
+ statusReason: text("status_reason"),
2518
+ statusResponse: text("status_response", { mode: "json" }).$type(),
2519
+ metadata: text("metadata", { mode: "json" }).$type(),
2520
+ paymentType: text("payment_type", {
2521
+ enum: PAYMENT_TYPES
2522
+ }).$type(),
2523
+ paymentsChecksum: text("payments_checksum"),
2524
+ batchMode: text("batch_mode", { enum: BATCH_MODES }).$type()
2525
+ });
2526
+
2527
+ const payment = sqliteTable(
2528
+ "payment",
2529
+ {
2530
+ ...base,
2531
+ correlationId: text("correlation_id").notNull(),
2532
+ refId: text("ref_id"),
2533
+ bankRefId: text("bank_ref_id").notNull(),
2534
+ accountId: text("account_id").references(() => account.id, {
2535
+ onDelete: "restrict",
2536
+ onUpdate: "cascade"
2537
+ }).notNull(),
2538
+ connectorKey: text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
2539
+ amount: real("amount").notNull(),
2540
+ direction: text("direction").$type().notNull(),
2541
+ paymentType: text("payment_type").$type().notNull(),
2542
+ currency: text("currency").$type().notNull(),
2543
+ status: text("status", { enum: PAYMENT_STATUSES }).$type().notNull(),
2544
+ statusReason: text("status_reason"),
2545
+ batchId: text("bank_execution_batch_id"),
2546
+ initiatedAt: integer("initiated_at", {
2547
+ mode: "timestamp_ms"
2548
+ }),
2549
+ vs: text("vs"),
2550
+ ss: text("ss"),
2551
+ ks: text("ks"),
2552
+ message: text("message"),
2553
+ chargeBearer: text("charge_bearer", {
2554
+ enum: CHARGE_BEARERS
2555
+ }).$type(),
2556
+ instructionPriority: text("instruction_priority", {
2557
+ enum: INSTRUCTION_PRIORITIES
2558
+ }).$type(),
2559
+ processedAt: integer("processed_at", {
2560
+ mode: "timestamp_ms"
2561
+ }),
2562
+ creditor: text("creditor", { mode: "json" }).$type().notNull(),
2563
+ creditorIban: text("creditor_iban"),
2564
+ debtor: text("debtor", { mode: "json" }).$type().notNull(),
2565
+ debtorIban: text("debtor_iban")
2566
+ },
2567
+ (t) => [
2568
+ unique().on(t.connectorKey, t.accountId, t.bankRefId),
2569
+ index("payment_account_id_idx").on(t.accountId),
2570
+ index("payment_account_id_status_idx").on(t.accountId, t.status),
2571
+ index("payment_account_id_created_at_idx").on(t.accountId, t.createdAt),
2572
+ index("payment_created_at_idx").on(t.createdAt),
2573
+ index("payment_direction_idx").on(t.direction),
2574
+ index("payment_batch_id_idx").on(t.batchId),
2575
+ index("payment_creditor_iban_idx").on(t.creditorIban),
2576
+ index("payment_debtor_iban_idx").on(t.debtorIban)
2577
+ ]
2578
+ );
2579
+ const paymentRelations = relations(payment, ({ one }) => ({
2580
+ batch: one(batch, { fields: [payment.batchId], references: [batch.id] })
2581
+ }));
2582
+
2583
+ const paymentRequest = sqliteTable(
2584
+ "payment_request",
2585
+ {
2586
+ ...base,
2587
+ batchId: text("batch_id").references(() => batch.id, {
2588
+ onDelete: "restrict",
2589
+ onUpdate: "cascade"
2590
+ }),
2591
+ accountId: text("account_id").references(() => account.id, {
2592
+ onDelete: "restrict",
2593
+ onUpdate: "cascade"
2594
+ }).notNull(),
2595
+ correlationId: text("correlation_id").notNull(),
2596
+ refId: text("ref_id"),
2597
+ bankRefId: text("bank_ref_id"),
2598
+ connectorKey: text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
2599
+ amount: real("amount").notNull(),
2600
+ paymentType: text("payment_type", { enum: PAYMENT_TYPES }).$type().notNull(),
2601
+ currency: text("currency").$type().notNull(),
2602
+ status: text("status", { enum: PAYMENT_REQUEST_STATUSES }).$type().notNull(),
2603
+ statusReason: text("status_reason"),
2604
+ authorizationUrl: text("authorization_url"),
2605
+ initiatedAt: integer("initiated_at", { mode: "timestamp_ms" }),
2606
+ processedAt: integer("processed_at", { mode: "timestamp_ms" }),
2607
+ vs: text("vs"),
2608
+ ss: text("ss"),
2609
+ ks: text("ks"),
2610
+ message: text("message"),
2611
+ chargeBearer: text("charge_bearer", {
2612
+ enum: CHARGE_BEARERS
2613
+ }).$type(),
2614
+ instructionPriority: text("instruction_priority", {
2615
+ enum: INSTRUCTION_PRIORITIES
2616
+ }).$type(),
2617
+ creditor: text("creditor", { mode: "json" }).$type().notNull(),
2618
+ creditorIban: text("creditor_iban"),
2619
+ debtor: text("debtor", { mode: "json" }).$type().notNull(),
2620
+ debtorIban: text("debtor_iban"),
2621
+ sendAsSinglePayment: integer("send_as_single_payment", {
2622
+ mode: "boolean"
2623
+ })
2624
+ },
2625
+ (t) => [
2626
+ index("payment_request_batch_id_idx").on(t.batchId),
2627
+ index("payment_request_account_id_idx").on(t.accountId),
2628
+ index("payment_request_creditor_iban_idx").on(t.creditorIban),
2629
+ index("payment_request_debtor_iban_idx").on(t.debtorIban),
2630
+ index("payment_request_status_idx").on(t.status),
2631
+ index("payment_request_created_at_idx").on(t.createdAt),
2632
+ index("payment_request_account_status_idx").on(t.accountId, t.status),
2633
+ index("payment_request_status_created_at_idx").on(t.status, t.createdAt),
2634
+ index("payment_request_account_status_created_at_idx").on(
2635
+ t.accountId,
2636
+ t.status,
2637
+ t.createdAt
2638
+ )
2639
+ ]
2640
+ );
2641
+ const paymentRequestRelations = relations(paymentRequest, ({ one }) => ({
2642
+ batch: one(batch, {
2643
+ fields: [paymentRequest.batchId],
2644
+ references: [batch.id]
2645
+ }),
2646
+ account: one(account, {
2647
+ fields: [paymentRequest.accountId],
2648
+ references: [account.id]
2649
+ })
2650
+ }));
2651
+
2652
+ const schema = {
2653
+ __proto__: null,
2654
+ account: account,
2655
+ accountCredentials: accountCredentials,
2656
+ batch: batch,
2657
+ ott: ott,
2658
+ payment: payment,
2659
+ paymentRelations: paymentRelations,
2660
+ paymentRequest: paymentRequest,
2661
+ paymentRequestRelations: paymentRequestRelations
2662
+ };
2663
+
2664
+ const tables = schema;
2665
+
2666
+ export { ott as $, ACCOUNT_STATUSES as A, BATCH_MODES as B, CHARGE_BEARERS as C, DbuConnector as D, ErsteConnector as E, FINBRICKS_ENDPOINTS as F, ottSelectSchema as G, ottUpdateSchema as H, IBankConnector as I, signFinbricksJws as J, KBConnector as K, toBatchedPayment as L, MockCobsConnector as M, toBatchedPaymentFromPaymentRequest as N, toCompletedPayment as O, PAYMENT_DIRECTIONS as P, toIncomingPayment as Q, toPaymentRequestInsert as R, toPreparedPayment as S, TOKEN_TYPES as T, useFinbricksFetch as U, tables as V, initiateConnector as W, getNonTerminalPaymentRequestsQuery as X, account as Y, accountCredentials as Z, batch as _, BATCH_STATUSES as a, payment as a0, paymentRelations as a1, paymentRequest as a2, paymentRequestRelations as a3, CONNECTOR_KEYS as b, COUNTRY_CODES as c, CREDENTIALS_TYPES as d, CsobConnector as e, FinbricksClient as f, FinbricksConnector as g, INSTRUCTION_PRIORITIES as h, MockConnector as i, PAYMENT_REQUEST_STATUSES as j, PAYMENT_STATUSES as k, PAYMENT_TYPES as l, accountCredentialsInsertSchema as m, accountCredentialsSelectSchema as n, accountCredentialsUpdateSchema as o, accountInsertSchema as p, accountSelectSchema as q, accountUpdateSchema as r, assignAccount as s, dbuAccountConfigSchema as t, hasPaymentAccountAssigned as u, isPaymentCompleted as v, isPendingStatus as w, isProcessedStatus as x, isTerminalStatus as y, ottInsertSchema as z };