@develit-services/bank 0.7.8 → 0.7.10

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.
@@ -2,8 +2,8 @@ import { bankAccount, base } from '@develit-io/backend-sdk';
2
2
  import { relations } from 'drizzle-orm/relations';
3
3
  import { sqliteTable, text, integer, unique, real } from 'drizzle-orm/sqlite-core';
4
4
  import 'date-fns';
5
- import { COUNTRY_CODES_2, BANK_CODES } from '@develit-io/general-codes';
6
5
  import 'jose';
6
+ import { COUNTRY_CODES_2, BANK_CODES } from '@develit-io/general-codes';
7
7
  import 'drizzle-orm';
8
8
  import 'node:crypto';
9
9
  import { createInsertSchema, createUpdateSchema, createSelectSchema } from 'drizzle-zod';
@@ -41,7 +41,8 @@ const CONNECTOR_KEYS = [
41
41
  "DBU",
42
42
  "CSAS",
43
43
  "AIRBANK",
44
- "KB"
44
+ "KB",
45
+ "CSOB"
45
46
  ];
46
47
  const CREDENTIALS_TYPES = [
47
48
  "AUTH_TOKEN",
@@ -2,12 +2,12 @@
2
2
 
3
3
  const backendSdk = require('@develit-io/backend-sdk');
4
4
  const drizzleOrm = require('drizzle-orm');
5
- const database_schema = require('./bank.Bz8-M6O4.cjs');
5
+ require('./bank.IVhZ_RlH.cjs');
6
6
  require('date-fns');
7
- require('@develit-io/general-codes');
8
7
  require('jose');
9
- require('./bank.DgGri2Wr.cjs');
8
+ require('@develit-io/general-codes');
10
9
  const node_crypto = require('node:crypto');
10
+ const database_schema = require('./bank.Cp0yvOdq.cjs');
11
11
 
12
12
  const createPaymentCommand = (db, { payment }) => {
13
13
  return {
@@ -101,14 +101,23 @@ function checksum(input) {
101
101
  return node_crypto.createHash("sha256").update(json).digest("hex");
102
102
  }
103
103
 
104
+ const createCredentialsResolver = async (db, env) => {
105
+ const encryptionKey = await importAesKey(
106
+ (await env.SECRETS_STORE.get({
107
+ secretName: "BANK_SERVICE_ENCRYPTION_KEY"
108
+ })).data?.secretValue || ""
109
+ );
110
+ return (accountId) => getCredentialsByAccountId(db, encryptionKey, { accountId });
111
+ };
112
+
104
113
  const tables = database_schema.schema;
105
114
 
106
115
  exports.checksum = checksum;
116
+ exports.createCredentialsResolver = createCredentialsResolver;
107
117
  exports.createPaymentCommand = createPaymentCommand;
108
118
  exports.encrypt = encrypt;
109
119
  exports.getAccountByIdQuery = getAccountByIdQuery;
110
120
  exports.getBatchByIdQuery = getBatchByIdQuery;
111
- exports.getCredentialsByAccountId = getCredentialsByAccountId;
112
121
  exports.importAesKey = importAesKey;
113
122
  exports.tables = tables;
114
123
  exports.upsertBatchCommand = upsertBatchCommand;
@@ -1,11 +1,11 @@
1
1
  import { uuidv4 } from '@develit-io/backend-sdk';
2
2
  import { eq } from 'drizzle-orm';
3
- import { s as schema } from './bank.I0pR4Me2.mjs';
3
+ import './bank.993UA65l.mjs';
4
4
  import 'date-fns';
5
- import '@develit-io/general-codes';
6
5
  import 'jose';
7
- import './bank.PB07ttj3.mjs';
6
+ import '@develit-io/general-codes';
8
7
  import { createHash } from 'node:crypto';
8
+ import { s as schema } from './bank.fIGTiPnp.mjs';
9
9
 
10
10
  const createPaymentCommand = (db, { payment }) => {
11
11
  return {
@@ -99,6 +99,15 @@ function checksum(input) {
99
99
  return createHash("sha256").update(json).digest("hex");
100
100
  }
101
101
 
102
+ const createCredentialsResolver = async (db, env) => {
103
+ const encryptionKey = await importAesKey(
104
+ (await env.SECRETS_STORE.get({
105
+ secretName: "BANK_SERVICE_ENCRYPTION_KEY"
106
+ })).data?.secretValue || ""
107
+ );
108
+ return (accountId) => getCredentialsByAccountId(db, encryptionKey, { accountId });
109
+ };
110
+
102
111
  const tables = schema;
103
112
 
104
- export { getAccountByIdQuery as a, getCredentialsByAccountId as b, checksum as c, createPaymentCommand as d, encrypt as e, getBatchByIdQuery as g, importAesKey as i, tables as t, upsertBatchCommand as u };
113
+ export { getAccountByIdQuery as a, createCredentialsResolver as b, checksum as c, createPaymentCommand as d, encrypt as e, getBatchByIdQuery as g, importAesKey as i, tables as t, upsertBatchCommand as u };
@@ -3,11 +3,69 @@
3
3
  const backendSdk = require('@develit-io/backend-sdk');
4
4
  const dateFns = require('date-fns');
5
5
  const generalCodes = require('@develit-io/general-codes');
6
- require('./bank.DgGri2Wr.cjs');
6
+ require('./bank.IVhZ_RlH.cjs');
7
7
  require('drizzle-orm');
8
8
  const jose = require('jose');
9
9
  require('node:crypto');
10
10
 
11
+ function toIncomingPayment(input) {
12
+ return {
13
+ id: backendSdk.uuidv4(),
14
+ correlationId: input.correlationId,
15
+ refId: input.refId,
16
+ amount: input.amount,
17
+ direction: "OUTGOING",
18
+ paymentType: input.paymentType,
19
+ currency: input.currency,
20
+ status: "CREATED",
21
+ statusReason: null,
22
+ batchId: null,
23
+ initiatedAt: null,
24
+ // Will be set in preparePayment when sent to bank
25
+ processedAt: null,
26
+ vs: input.vs || null,
27
+ ss: input.ss || null,
28
+ ks: input.ks || null,
29
+ message: input.message || null,
30
+ creditor: input.creditor,
31
+ creditorIban: input.creditor.iban || null,
32
+ debtor: input.debtor,
33
+ debtorIban: input.debtor.iban || null,
34
+ sendAsSinglePayment: input.sendAsSinglePayment,
35
+ chargeBearer: input.chargeBearer,
36
+ instructionPriority: input.instructionPriority
37
+ };
38
+ }
39
+ function assignAccount(payment, account) {
40
+ return {
41
+ ...payment,
42
+ accountId: account.id,
43
+ connectorKey: account.connectorKey
44
+ };
45
+ }
46
+ function toBatchedPayment(payment) {
47
+ return payment;
48
+ }
49
+ function toPreparedPayment(payment, bankRefId, initiatedAt) {
50
+ return {
51
+ ...payment,
52
+ status: "PREPARED",
53
+ bankRefId,
54
+ initiatedAt: initiatedAt ?? /* @__PURE__ */ new Date()
55
+ };
56
+ }
57
+ function toCompletedPayment(payment, status, bankRefId, processedAt) {
58
+ return {
59
+ ...payment,
60
+ bankRefId,
61
+ status,
62
+ processedAt: processedAt ?? /* @__PURE__ */ new Date()
63
+ };
64
+ }
65
+ function batchTransform(payments, transformer) {
66
+ return payments.map(transformer);
67
+ }
68
+
11
69
  class IBankConnector {
12
70
  // ── Deprecated methods (backward compatibility) ────────────────────
13
71
  /**
@@ -96,64 +154,6 @@ class IBankConnector {
96
154
  }
97
155
  }
98
156
 
99
- function toIncomingPayment(input) {
100
- return {
101
- id: backendSdk.uuidv4(),
102
- correlationId: input.correlationId,
103
- refId: input.refId,
104
- amount: input.amount,
105
- direction: "OUTGOING",
106
- paymentType: input.paymentType,
107
- currency: input.currency,
108
- status: "CREATED",
109
- statusReason: null,
110
- batchId: null,
111
- initiatedAt: null,
112
- // Will be set in preparePayment when sent to bank
113
- processedAt: null,
114
- vs: input.vs || null,
115
- ss: input.ss || null,
116
- ks: input.ks || null,
117
- message: input.message || null,
118
- creditor: input.creditor,
119
- creditorIban: input.creditor.iban || null,
120
- debtor: input.debtor,
121
- debtorIban: input.debtor.iban || null,
122
- sendAsSinglePayment: input.sendAsSinglePayment,
123
- chargeBearer: input.chargeBearer,
124
- instructionPriority: input.instructionPriority
125
- };
126
- }
127
- function assignAccount(payment, account) {
128
- return {
129
- ...payment,
130
- accountId: account.id,
131
- connectorKey: account.connectorKey
132
- };
133
- }
134
- function toBatchedPayment(payment) {
135
- return payment;
136
- }
137
- function toPreparedPayment(payment, bankRefId, initiatedAt) {
138
- return {
139
- ...payment,
140
- status: "PREPARED",
141
- bankRefId,
142
- initiatedAt: initiatedAt ?? /* @__PURE__ */ new Date()
143
- };
144
- }
145
- function toCompletedPayment(payment, status, bankRefId, processedAt) {
146
- return {
147
- ...payment,
148
- bankRefId,
149
- status,
150
- processedAt: processedAt ?? /* @__PURE__ */ new Date()
151
- };
152
- }
153
- function batchTransform(payments, transformer) {
154
- return payments.map(transformer);
155
- }
156
-
157
157
  async function signFinbricksJws({
158
158
  privateKeyPem,
159
159
  merchantId,
@@ -388,7 +388,8 @@ class FinbricksConnector extends IBankConnector {
388
388
  MERCHANT_ID,
389
389
  PRIVATE_KEY_PEM,
390
390
  REDIRECT_URI,
391
- connectedAccounts
391
+ connectedAccounts,
392
+ resolveCredentials
392
393
  }) {
393
394
  super();
394
395
  this.connectorKey = "FINBRICKS";
@@ -401,6 +402,26 @@ class FinbricksConnector extends IBankConnector {
401
402
  REDIRECT_URI
402
403
  );
403
404
  this.connectedAccounts = connectedAccounts;
405
+ this.resolveCredentials = resolveCredentials;
406
+ }
407
+ async getClientId(accountId) {
408
+ if (!this.resolveCredentials) {
409
+ throw backendSdk.createInternalError(null, {
410
+ message: "Credentials resolver not provided"
411
+ });
412
+ }
413
+ const credentials = await this.resolveCredentials(accountId);
414
+ if (!credentials) {
415
+ throw backendSdk.createInternalError(null, {
416
+ message: `No credentials found for account: ${accountId}`
417
+ });
418
+ }
419
+ if (credentials.expiresAt < /* @__PURE__ */ new Date()) {
420
+ throw backendSdk.createInternalError(null, {
421
+ message: `Credentials have expired for account: ${accountId}`
422
+ });
423
+ }
424
+ return credentials.value;
404
425
  }
405
426
  async getAuthUri({ ott }) {
406
427
  const clientId = backendSdk.uuidv4();
@@ -460,8 +481,7 @@ class FinbricksConnector extends IBankConnector {
460
481
  connectorKey: this.PROVIDER,
461
482
  currency: acc.currency,
462
483
  iban: acc.identification.iban,
463
- id: acc.id,
464
- token: clientId
484
+ id: acc.id
465
485
  }))
466
486
  );
467
487
  return {
@@ -556,6 +576,7 @@ class FinbricksConnector extends IBankConnector {
556
576
  throw backendSdk.createInternalError(null, {
557
577
  message: `Batch for unauthorized client with iban: ${payments[0].debtor.iban}`
558
578
  });
579
+ const clientId = await this.getClientId(authorizedClient.id);
559
580
  const [response, error] = await backendSdk.useResult(
560
581
  this.finbricks.request({
561
582
  endpoint: FINBRICKS_ENDPOINTS.TRANSACTION_BATCH_INIT,
@@ -564,7 +585,7 @@ class FinbricksConnector extends IBankConnector {
564
585
  batchPaymentIdentification: {
565
586
  merchantId: this.finbricks.MERCHANT_ID,
566
587
  debtorAccountIban: payments[0].debtor.iban,
567
- clientId: authorizedClient.token,
588
+ clientId,
568
589
  callbackUrl: `${this.finbricks.REDIRECT_URI}?type=batch&batchId=${batchId}`,
569
590
  merchantBatchId: batchId
570
591
  },
@@ -601,6 +622,10 @@ class FinbricksConnector extends IBankConnector {
601
622
  throw new Error("Finbricks: Foreign batch not implemented");
602
623
  }
603
624
  async initiateForeignPayment(payment) {
625
+ const debtorAccount = this.connectedAccounts.find(
626
+ (acc) => acc.iban === payment.debtorIban
627
+ );
628
+ const clientId = await this.getClientId(debtorAccount.id);
604
629
  const bankRefId = backendSdk.uuidv4();
605
630
  const [response, error] = await backendSdk.useResult(
606
631
  this.finbricks.request({
@@ -609,9 +634,7 @@ class FinbricksConnector extends IBankConnector {
609
634
  body: {
610
635
  merchantIdentification: {
611
636
  merchantId: this.finbricks.MERCHANT_ID,
612
- clientId: this.connectedAccounts.find(
613
- (acc) => acc.iban === payment.debtorIban
614
- ).token
637
+ clientId
615
638
  },
616
639
  paymentIdentification: {
617
640
  merchantTransactionId: bankRefId
@@ -662,6 +685,10 @@ class FinbricksConnector extends IBankConnector {
662
685
  };
663
686
  }
664
687
  async initiateSEPAPayment(payment) {
688
+ const debtorAccount = this.connectedAccounts.find(
689
+ (acc) => acc.iban === payment.debtorIban
690
+ );
691
+ const clientId = await this.getClientId(debtorAccount.id);
665
692
  const bankRefId = backendSdk.uuidv4();
666
693
  const [response, error] = await backendSdk.useResult(
667
694
  this.finbricks.request({
@@ -670,9 +697,7 @@ class FinbricksConnector extends IBankConnector {
670
697
  body: {
671
698
  merchantIdentification: {
672
699
  merchantId: this.finbricks.MERCHANT_ID,
673
- clientId: this.connectedAccounts.find(
674
- (acc) => acc.iban === payment.debtorIban
675
- ).token
700
+ clientId
676
701
  },
677
702
  paymentIdentification: {
678
703
  merchantTransactionId: bankRefId
@@ -751,6 +776,10 @@ class FinbricksConnector extends IBankConnector {
751
776
  account,
752
777
  filter
753
778
  }) {
779
+ const connectedAccount = this.connectedAccounts.find(
780
+ (acc) => acc.iban === account.iban
781
+ );
782
+ const clientId = await this.getClientId(connectedAccount.id);
754
783
  let cursor = null;
755
784
  const allPayments = [];
756
785
  const dateFormat = "yyyy-MM-dd";
@@ -763,9 +792,7 @@ class FinbricksConnector extends IBankConnector {
763
792
  endpoint: FINBRICKS_ENDPOINTS.ACCOUNT_TRANSACTIONS,
764
793
  query: {
765
794
  merchantId: this.finbricks.MERCHANT_ID,
766
- clientId: this.connectedAccounts.find(
767
- (acc) => acc.iban === account.iban
768
- ).token,
795
+ clientId,
769
796
  paymentProvider: this.PROVIDER,
770
797
  bankAccountId: account.bankRefId,
771
798
  dateFrom,
@@ -846,6 +873,15 @@ class FinbricksConnector extends IBankConnector {
846
873
  }
847
874
  }
848
875
 
876
+ class CsobConnector extends FinbricksConnector {
877
+ constructor(config) {
878
+ super("CSOB", config);
879
+ }
880
+ supportsBatch(paymentType) {
881
+ return paymentType === "DOMESTIC";
882
+ }
883
+ }
884
+
849
885
  class AirBankConnector extends FinbricksConnector {
850
886
  constructor(config) {
851
887
  super("AIRBANK", config);
@@ -922,7 +958,8 @@ const getPaymentDirection = (payment, iban) => {
922
958
  const initiateConnector = async ({
923
959
  bank,
924
960
  env,
925
- connectedAccounts
961
+ connectedAccounts,
962
+ resolveCredentials
926
963
  }) => {
927
964
  switch (bank) {
928
965
  case "ERSTE":
@@ -940,7 +977,8 @@ const initiateConnector = async ({
940
977
  AUTH_URI: env.ERSTE_AUTH_URI,
941
978
  PAYMENTS_URI: env.ERSTE_PAYMENTS_URI,
942
979
  ACCOUNTS_URI: env.ERSTE_ACCOUNTS_URI,
943
- connectedAccounts
980
+ connectedAccounts,
981
+ resolveCredentials
944
982
  });
945
983
  case "CREDITAS":
946
984
  return new CreditasConnector({
@@ -950,7 +988,8 @@ const initiateConnector = async ({
950
988
  secretName: "BANK_SERVICE_FINBRICKS_PRIVATE_KEY_PEM"
951
989
  })).data?.secretValue || "",
952
990
  REDIRECT_URI: env.REDIRECT_URI,
953
- connectedAccounts
991
+ connectedAccounts,
992
+ resolveCredentials
954
993
  });
955
994
  case "MOCK_COBS":
956
995
  return new MockCobsConnector({
@@ -960,7 +999,8 @@ const initiateConnector = async ({
960
999
  secretName: "BANK_SERVICE_FINBRICKS_PRIVATE_KEY_PEM"
961
1000
  })).data?.secretValue || "",
962
1001
  REDIRECT_URI: env.REDIRECT_URI,
963
- connectedAccounts
1002
+ connectedAccounts,
1003
+ resolveCredentials
964
1004
  });
965
1005
  case "FIO":
966
1006
  return new FioConnector({
@@ -970,7 +1010,8 @@ const initiateConnector = async ({
970
1010
  secretName: "BANK_SERVICE_FINBRICKS_PRIVATE_KEY_PEM"
971
1011
  })).data?.secretValue || "",
972
1012
  REDIRECT_URI: env.REDIRECT_URI,
973
- connectedAccounts
1013
+ connectedAccounts,
1014
+ resolveCredentials
974
1015
  });
975
1016
  case "MONETA":
976
1017
  return new MonetaConnector({
@@ -980,7 +1021,8 @@ const initiateConnector = async ({
980
1021
  secretName: "BANK_SERVICE_FINBRICKS_PRIVATE_KEY_PEM"
981
1022
  })).data?.secretValue || "",
982
1023
  REDIRECT_URI: env.REDIRECT_URI,
983
- connectedAccounts
1024
+ connectedAccounts,
1025
+ resolveCredentials
984
1026
  });
985
1027
  case "AIRBANK":
986
1028
  return new AirBankConnector({
@@ -990,7 +1032,8 @@ const initiateConnector = async ({
990
1032
  secretName: "BANK_SERVICE_FINBRICKS_PRIVATE_KEY_PEM"
991
1033
  })).data?.secretValue || "",
992
1034
  REDIRECT_URI: env.REDIRECT_URI,
993
- connectedAccounts
1035
+ connectedAccounts,
1036
+ resolveCredentials
994
1037
  });
995
1038
  case "CSAS":
996
1039
  return new CSASConnector({
@@ -1000,7 +1043,8 @@ const initiateConnector = async ({
1000
1043
  secretName: "BANK_SERVICE_FINBRICKS_PRIVATE_KEY_PEM"
1001
1044
  })).data?.secretValue || "",
1002
1045
  REDIRECT_URI: env.REDIRECT_URI,
1003
- connectedAccounts
1046
+ connectedAccounts,
1047
+ resolveCredentials
1004
1048
  });
1005
1049
  case "KB":
1006
1050
  return new KBConnector({
@@ -1010,7 +1054,19 @@ const initiateConnector = async ({
1010
1054
  secretName: "BANK_SERVICE_FINBRICKS_PRIVATE_KEY_PEM"
1011
1055
  })).data?.secretValue || "",
1012
1056
  REDIRECT_URI: env.REDIRECT_URI,
1013
- connectedAccounts
1057
+ connectedAccounts,
1058
+ resolveCredentials
1059
+ });
1060
+ case "CSOB":
1061
+ return new CsobConnector({
1062
+ BASE_URI: env.FINBRICKS_BASE_URI,
1063
+ MERCHANT_ID: env.FINBRICKS_MERCHANT_ID,
1064
+ PRIVATE_KEY_PEM: (await env.SECRETS_STORE.get({
1065
+ secretName: "BANK_SERVICE_FINBRICKS_PRIVATE_KEY_PEM"
1066
+ })).data?.secretValue || "",
1067
+ REDIRECT_URI: env.REDIRECT_URI,
1068
+ connectedAccounts,
1069
+ resolveCredentials
1014
1070
  });
1015
1071
  case "DBU":
1016
1072
  return new DbuConnector({
@@ -1297,17 +1353,7 @@ class DbuConnector extends IBankConnector {
1297
1353
  bankRefId: idAccount,
1298
1354
  currency: "CZK"
1299
1355
  };
1300
- const credentials = [
1301
- {
1302
- accountId: id,
1303
- connectorKey: "DBU",
1304
- type: "API_KEY",
1305
- value: "dbu-tunnel-auth",
1306
- expiresAt: new Date(Date.now() + 10 * 365 * 24 * 60 * 60 * 1e3)
1307
- // 10 years
1308
- }
1309
- ];
1310
- return { credentials, accounts: [account] };
1356
+ return { credentials: [], accounts: [account] };
1311
1357
  }
1312
1358
  async listAccounts() {
1313
1359
  return [];
@@ -1532,6 +1578,7 @@ class ErsteConnector extends IBankConnector {
1532
1578
  this.PAYMENTS_URI = config.PAYMENTS_URI;
1533
1579
  this.ACCOUNTS_URI = config.ACCOUNTS_URI;
1534
1580
  this.connectedAccounts = config.connectedAccounts;
1581
+ this.resolveCredentials = config.resolveCredentials;
1535
1582
  }
1536
1583
  initiateDomesticPayment(_payment) {
1537
1584
  throw new Error("Method not implemented.");
@@ -1928,6 +1975,7 @@ class MockConnector extends IBankConnector {
1928
1975
  }
1929
1976
  }
1930
1977
 
1978
+ exports.CsobConnector = CsobConnector;
1931
1979
  exports.DbuConnector = DbuConnector;
1932
1980
  exports.ErsteConnector = ErsteConnector;
1933
1981
  exports.FINBRICKS_ENDPOINTS = FINBRICKS_ENDPOINTS;