@develit-services/bank 0.3.43 → 0.3.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/database/schema.cjs +4 -4
- package/dist/database/schema.d.cts +1 -1
- package/dist/database/schema.d.mts +1 -1
- package/dist/database/schema.d.ts +1 -1
- package/dist/database/schema.mjs +4 -4
- package/dist/export/worker.cjs +166 -183
- package/dist/export/worker.d.cts +43 -22
- package/dist/export/worker.d.mts +43 -22
- package/dist/export/worker.d.ts +43 -22
- package/dist/export/worker.mjs +126 -143
- package/dist/export/workflows.cjs +214 -18
- package/dist/export/workflows.mjs +207 -12
- package/dist/export/wrangler.d.cts +1 -2
- package/dist/export/wrangler.d.mts +1 -2
- package/dist/export/wrangler.d.ts +1 -2
- package/dist/shared/{bank.YiArmBW2.mjs → bank.B1Gpn3ht.mjs} +12 -174
- package/dist/shared/{bank.xrXNjWCo.d.cts → bank.BEL1HIxZ.d.cts} +21 -1
- package/dist/shared/{bank.xrXNjWCo.d.mts → bank.BEL1HIxZ.d.mts} +21 -1
- package/dist/shared/{bank.xrXNjWCo.d.ts → bank.BEL1HIxZ.d.ts} +21 -1
- package/dist/shared/bank.BUEmFxS8.mjs +174 -0
- package/dist/shared/{bank.CLF9wee9.cjs → bank.CPYfE-Ei.cjs} +12 -199
- package/dist/shared/bank.CpwLFudl.cjs +198 -0
- package/dist/shared/bank.D-3fzX63.mjs +170 -0
- package/dist/shared/bank.D0a-MZon.cjs +184 -0
- package/dist/shared/{bank.BchnXQDL.d.cts → bank.Dh_H_5rC.d.cts} +0 -1
- package/dist/shared/{bank.BchnXQDL.d.mts → bank.Dh_H_5rC.d.mts} +0 -1
- package/dist/shared/{bank.BchnXQDL.d.ts → bank.Dh_H_5rC.d.ts} +0 -1
- package/dist/types.cjs +14 -14
- package/dist/types.d.cts +9 -9
- package/dist/types.d.mts +9 -9
- package/dist/types.d.ts +9 -9
- package/dist/types.mjs +5 -5
- package/package.json +1 -1
- package/dist/shared/bank.CNtiZSem.mjs +0 -9
- package/dist/shared/bank.CUU0Daxj.mjs +0 -391
- package/dist/shared/bank.ChffLgyT.cjs +0 -401
- package/dist/shared/bank.DfE0M5H3.cjs +0 -11
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { t as tables, F as FinbricksConnector, M as MockConnector, a as MockCobsConnector, E as ErsteConnector } from './bank.B1Gpn3ht.mjs';
|
|
2
|
+
import { uuidv4 } from '@develit-io/backend-sdk';
|
|
3
|
+
import { eq } from 'drizzle-orm';
|
|
4
|
+
import 'date-fns';
|
|
5
|
+
import 'jose';
|
|
6
|
+
import '@develit-io/general-codes';
|
|
7
|
+
import './bank.D-3fzX63.mjs';
|
|
8
|
+
import { createHash } from 'node:crypto';
|
|
9
|
+
|
|
10
|
+
const createPaymentCommand = (db, { payment }) => {
|
|
11
|
+
return {
|
|
12
|
+
command: db.insert(tables.payment).values({
|
|
13
|
+
...payment,
|
|
14
|
+
creditorIban: payment.creditor.iban,
|
|
15
|
+
debtorIban: payment.debtor.iban
|
|
16
|
+
}).returning()
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const upsertBatchCommand = (db, { batch }) => {
|
|
21
|
+
const id = batch.id || uuidv4();
|
|
22
|
+
const command = db.insert(tables.batch).values({
|
|
23
|
+
...batch,
|
|
24
|
+
id
|
|
25
|
+
}).onConflictDoUpdate({
|
|
26
|
+
target: tables.batch.id,
|
|
27
|
+
set: {
|
|
28
|
+
...batch
|
|
29
|
+
}
|
|
30
|
+
}).returning();
|
|
31
|
+
return {
|
|
32
|
+
id,
|
|
33
|
+
command
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const getAccountByIdQuery = async (db, { accountId }) => {
|
|
38
|
+
return await db.select().from(tables.account).where(eq(tables.account.id, accountId)).get();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getBatchByIdQuery = async (db, { batchId }) => {
|
|
42
|
+
return await db.select().from(tables.batch).where(eq(tables.batch.id, batchId)).get();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const getCredentialsByAccountId = async (db, encryptionKey, { accountId }) => {
|
|
46
|
+
const cred = await db.select().from(tables.accountCredentials).where(eq(tables.accountCredentials.accountId, accountId)).get();
|
|
47
|
+
return cred ? {
|
|
48
|
+
...cred,
|
|
49
|
+
value: await decrypt(cred.value, encryptionKey)
|
|
50
|
+
} : void 0;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
class CreditasConnector extends FinbricksConnector {
|
|
54
|
+
constructor(config) {
|
|
55
|
+
super("CREDITAS", config);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class FioConnector extends FinbricksConnector {
|
|
60
|
+
constructor(config) {
|
|
61
|
+
super("FIO", config);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
class MonetaConnector extends FinbricksConnector {
|
|
66
|
+
constructor(config) {
|
|
67
|
+
super("MONETA", config);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const initiateConnector = ({
|
|
72
|
+
bank,
|
|
73
|
+
env,
|
|
74
|
+
connectedAccounts
|
|
75
|
+
}) => {
|
|
76
|
+
switch (bank) {
|
|
77
|
+
case "ERSTE":
|
|
78
|
+
return new ErsteConnector({
|
|
79
|
+
API_KEY: env.ERSTE_API_KEY,
|
|
80
|
+
CLIENT_ID: env.ERSTE_CLIENT_ID,
|
|
81
|
+
CLIENT_SECRET: env.ERSTE_CLIENT_SECRET,
|
|
82
|
+
REDIRECT_URI: env.REDIRECT_URI,
|
|
83
|
+
AUTH_URI: env.ERSTE_AUTH_URI,
|
|
84
|
+
PAYMENTS_URI: env.ERSTE_PAYMENTS_URI,
|
|
85
|
+
ACCOUNTS_URI: env.ERSTE_ACCOUNTS_URI,
|
|
86
|
+
connectedAccounts
|
|
87
|
+
});
|
|
88
|
+
case "CREDITAS":
|
|
89
|
+
return new CreditasConnector({
|
|
90
|
+
BASE_URI: env.FINBRICKS_BASE_URI,
|
|
91
|
+
MERCHANT_ID: env.FINBRICKS_MERCHANT_ID,
|
|
92
|
+
PRIVATE_KEY_PEM: env.FINBRICKS_PRIVATE_KEY_PEM,
|
|
93
|
+
REDIRECT_URI: env.REDIRECT_URI,
|
|
94
|
+
connectedAccounts
|
|
95
|
+
});
|
|
96
|
+
case "MOCK_COBS":
|
|
97
|
+
return new MockCobsConnector({
|
|
98
|
+
BASE_URI: env.FINBRICKS_BASE_URI,
|
|
99
|
+
MERCHANT_ID: env.FINBRICKS_MERCHANT_ID,
|
|
100
|
+
PRIVATE_KEY_PEM: env.FINBRICKS_PRIVATE_KEY_PEM,
|
|
101
|
+
REDIRECT_URI: env.REDIRECT_URI,
|
|
102
|
+
connectedAccounts
|
|
103
|
+
});
|
|
104
|
+
case "FIO":
|
|
105
|
+
return new FioConnector({
|
|
106
|
+
BASE_URI: env.FINBRICKS_BASE_URI,
|
|
107
|
+
MERCHANT_ID: env.FINBRICKS_MERCHANT_ID,
|
|
108
|
+
PRIVATE_KEY_PEM: env.FINBRICKS_PRIVATE_KEY_PEM,
|
|
109
|
+
REDIRECT_URI: env.REDIRECT_URI,
|
|
110
|
+
connectedAccounts
|
|
111
|
+
});
|
|
112
|
+
case "MONETA":
|
|
113
|
+
return new MonetaConnector({
|
|
114
|
+
BASE_URI: env.FINBRICKS_BASE_URI,
|
|
115
|
+
MERCHANT_ID: env.FINBRICKS_MERCHANT_ID,
|
|
116
|
+
PRIVATE_KEY_PEM: env.FINBRICKS_PRIVATE_KEY_PEM,
|
|
117
|
+
REDIRECT_URI: env.REDIRECT_URI,
|
|
118
|
+
connectedAccounts
|
|
119
|
+
});
|
|
120
|
+
default:
|
|
121
|
+
return new MockConnector();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
async function importAesKey(base64Key) {
|
|
126
|
+
const raw = Uint8Array.from(atob(base64Key), (c) => c.charCodeAt(0));
|
|
127
|
+
return await crypto.subtle.importKey("raw", raw, { name: "AES-GCM" }, false, [
|
|
128
|
+
"encrypt",
|
|
129
|
+
"decrypt"
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
async function encrypt(value, key) {
|
|
133
|
+
const encoder = new TextEncoder();
|
|
134
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
135
|
+
const ciphertext = await crypto.subtle.encrypt(
|
|
136
|
+
{ name: "AES-GCM", iv },
|
|
137
|
+
key,
|
|
138
|
+
encoder.encode(value)
|
|
139
|
+
);
|
|
140
|
+
const combined = new Uint8Array(iv.length + ciphertext.byteLength);
|
|
141
|
+
combined.set(iv, 0);
|
|
142
|
+
combined.set(new Uint8Array(ciphertext), iv.length);
|
|
143
|
+
return btoa(String.fromCharCode(...combined));
|
|
144
|
+
}
|
|
145
|
+
async function decrypt(base64, key) {
|
|
146
|
+
const raw = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
147
|
+
const iv = raw.slice(0, 12);
|
|
148
|
+
const ciphertext = raw.slice(12);
|
|
149
|
+
const decrypted = await crypto.subtle.decrypt(
|
|
150
|
+
{ name: "AES-GCM", iv },
|
|
151
|
+
key,
|
|
152
|
+
ciphertext
|
|
153
|
+
);
|
|
154
|
+
return new TextDecoder().decode(decrypted);
|
|
155
|
+
}
|
|
156
|
+
function canonicalize(value) {
|
|
157
|
+
if (value === null || typeof value !== "object") return value;
|
|
158
|
+
if (Array.isArray(value)) {
|
|
159
|
+
return value.map(canonicalize);
|
|
160
|
+
}
|
|
161
|
+
const obj = value;
|
|
162
|
+
const sorted = Object.keys(obj).sort().reduce((acc, key) => {
|
|
163
|
+
acc[key] = canonicalize(obj[key]);
|
|
164
|
+
return acc;
|
|
165
|
+
}, {});
|
|
166
|
+
return sorted;
|
|
167
|
+
}
|
|
168
|
+
function checksum(input) {
|
|
169
|
+
const canonical = canonicalize(input);
|
|
170
|
+
const json = JSON.stringify(canonical);
|
|
171
|
+
return createHash("sha256").update(json).digest("hex");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export { getCredentialsByAccountId as a, initiateConnector as b, createPaymentCommand as c, getBatchByIdQuery as d, checksum as e, encrypt as f, getAccountByIdQuery as g, importAesKey as i, upsertBatchCommand as u };
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const backendSdk = require('@develit-io/backend-sdk');
|
|
4
|
-
const sqliteCore = require('drizzle-orm/sqlite-core');
|
|
5
4
|
const dateFns = require('date-fns');
|
|
5
|
+
const database_schema = require('./bank.CpwLFudl.cjs');
|
|
6
6
|
const drizzleOrm = require('drizzle-orm');
|
|
7
7
|
const jose = require('jose');
|
|
8
|
-
|
|
9
|
-
const drizzleZod = require('drizzle-zod');
|
|
10
|
-
const relations = require('drizzle-orm/relations');
|
|
8
|
+
require('@develit-io/general-codes');
|
|
11
9
|
require('node:crypto');
|
|
12
10
|
|
|
13
11
|
class IBankConnector {
|
|
@@ -261,9 +259,6 @@ class FinbricksConnector extends IBankConnector {
|
|
|
261
259
|
);
|
|
262
260
|
this.connectedAccounts = connectedAccounts;
|
|
263
261
|
}
|
|
264
|
-
static {
|
|
265
|
-
this.FETCH_INTERVAL = 60 * 60 * 5;
|
|
266
|
-
}
|
|
267
262
|
async getAuthUri({ ott }) {
|
|
268
263
|
const clientId = backendSdk.uuidv4();
|
|
269
264
|
const body = {
|
|
@@ -446,9 +441,9 @@ class FinbricksConnector extends IBankConnector {
|
|
|
446
441
|
};
|
|
447
442
|
}
|
|
448
443
|
async initiateBatchFromPayments({
|
|
444
|
+
batchId,
|
|
449
445
|
payments
|
|
450
446
|
}) {
|
|
451
|
-
const batchId = backendSdk.uuidv4();
|
|
452
447
|
const authorizedClient = this.connectedAccounts.find(
|
|
453
448
|
(acc) => acc.iban === payments[0].debtorIban
|
|
454
449
|
);
|
|
@@ -738,9 +733,6 @@ class ErsteConnector extends IBankConnector {
|
|
|
738
733
|
initiateSEPAPayment(payment) {
|
|
739
734
|
throw new Error("Method not implemented.");
|
|
740
735
|
}
|
|
741
|
-
static {
|
|
742
|
-
this.FETCH_INTERVAL = 60 * 60 * 5;
|
|
743
|
-
}
|
|
744
736
|
async getAuthUri({ ott }) {
|
|
745
737
|
const params = new URLSearchParams({
|
|
746
738
|
redirect_uri: `${this.REDIRECT_URI}?&ott=${ott}`,
|
|
@@ -858,10 +850,10 @@ class ErsteConnector extends IBankConnector {
|
|
|
858
850
|
};
|
|
859
851
|
}
|
|
860
852
|
async initiateBatchFromPayments({
|
|
853
|
+
batchId,
|
|
861
854
|
payments
|
|
862
855
|
}) {
|
|
863
856
|
const allRefIds = payments.map((payment) => payment.bankRefId);
|
|
864
|
-
const batchId = backendSdk.uuidv4();
|
|
865
857
|
if (allRefIds.length === 0) {
|
|
866
858
|
throw backendSdk.createInternalError(null, {
|
|
867
859
|
message: "No valid payments to include in batch",
|
|
@@ -1030,9 +1022,6 @@ class MockConnector extends IBankConnector {
|
|
|
1030
1022
|
initiateSEPAPayment(payment) {
|
|
1031
1023
|
throw new Error("Method not implemented.");
|
|
1032
1024
|
}
|
|
1033
|
-
static {
|
|
1034
|
-
this.FETCH_INTERVAL = 60 * 60 * 5;
|
|
1035
|
-
}
|
|
1036
1025
|
async authenticate() {
|
|
1037
1026
|
return "";
|
|
1038
1027
|
}
|
|
@@ -1076,6 +1065,7 @@ class MockConnector extends IBankConnector {
|
|
|
1076
1065
|
};
|
|
1077
1066
|
}
|
|
1078
1067
|
async initiateBatchFromPayments({
|
|
1068
|
+
batchId,
|
|
1079
1069
|
payments
|
|
1080
1070
|
}) {
|
|
1081
1071
|
return {
|
|
@@ -1114,198 +1104,21 @@ class MockConnector extends IBankConnector {
|
|
|
1114
1104
|
}
|
|
1115
1105
|
}
|
|
1116
1106
|
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
"INITIALIZED",
|
|
1123
|
-
"FAILED",
|
|
1124
|
-
"PENDING",
|
|
1125
|
-
"COMPLETED",
|
|
1126
|
-
"CREATED"
|
|
1127
|
-
];
|
|
1128
|
-
const PAYMENT_DIRECTIONS = ["INCOMING", "OUTGOING"];
|
|
1129
|
-
const BATCH_STATUSES = [
|
|
1130
|
-
"OPEN",
|
|
1131
|
-
"FULL",
|
|
1132
|
-
"PROCESSING",
|
|
1133
|
-
"READY_TO_SIGN",
|
|
1134
|
-
"SIGNED",
|
|
1135
|
-
"SIGNATURE_FAILED",
|
|
1136
|
-
"FAILED"
|
|
1137
|
-
];
|
|
1138
|
-
const ACCOUNT_STATUSES = ["AUTHORIZED", "DISABLED", "EXPIRED"];
|
|
1139
|
-
const COUNTRY_CODES = generalCodes.COUNTRY_CODES_2;
|
|
1140
|
-
|
|
1141
|
-
const CONNECTOR_KEYS = [
|
|
1142
|
-
"ERSTE",
|
|
1143
|
-
"FINBRICKS",
|
|
1144
|
-
"MOCK",
|
|
1145
|
-
"CREDITAS",
|
|
1146
|
-
"MOCK_COBS",
|
|
1147
|
-
"FIO",
|
|
1148
|
-
"MONETA"
|
|
1149
|
-
];
|
|
1150
|
-
const CREDENTIALS_TYPES = [
|
|
1151
|
-
"AUTH_TOKEN",
|
|
1152
|
-
"REFRESH_TOKEN",
|
|
1153
|
-
"CLIENT_ID",
|
|
1154
|
-
"API_KEY"
|
|
1155
|
-
];
|
|
1156
|
-
const TOKEN_TYPES = ["ACCOUNT_AUTHORIZATION"];
|
|
1157
|
-
|
|
1158
|
-
const account = sqliteCore.sqliteTable(
|
|
1159
|
-
"account",
|
|
1160
|
-
{
|
|
1161
|
-
...backendSdk.base,
|
|
1162
|
-
...backendSdk.bankAccount,
|
|
1163
|
-
number: sqliteCore.text("number").notNull(),
|
|
1164
|
-
name: sqliteCore.text("name"),
|
|
1165
|
-
iban: sqliteCore.text("iban").notNull(),
|
|
1166
|
-
bankCode: sqliteCore.text("bank_code", { enum: generalCodes.BANK_CODES }).notNull(),
|
|
1167
|
-
connectorKey: sqliteCore.text("connector_key", {
|
|
1168
|
-
enum: CONNECTOR_KEYS
|
|
1169
|
-
}).$type().notNull(),
|
|
1170
|
-
status: sqliteCore.text("status", { enum: ACCOUNT_STATUSES }).$type().notNull(),
|
|
1171
|
-
bankRefId: sqliteCore.text("bank_ref_id").notNull(),
|
|
1172
|
-
batchSizeLimit: sqliteCore.integer("batch_size_limit").notNull().default(50),
|
|
1173
|
-
syncIntervalS: sqliteCore.integer("sync_interval_s").notNull().default(600),
|
|
1174
|
-
lastSyncAt: sqliteCore.integer("last_sync_at", { mode: "timestamp_ms" }),
|
|
1175
|
-
lastSyncMetadata: sqliteCore.text("last_sync_metadata", {
|
|
1176
|
-
mode: "json"
|
|
1177
|
-
}).$type()
|
|
1178
|
-
},
|
|
1179
|
-
(t) => [sqliteCore.unique().on(t.iban)]
|
|
1180
|
-
);
|
|
1181
|
-
|
|
1182
|
-
const accountInsertSchema = drizzleZod.createInsertSchema(account);
|
|
1183
|
-
const accountUpdateSchema = drizzleZod.createUpdateSchema(account);
|
|
1184
|
-
const accountSelectSchema = drizzleZod.createSelectSchema(account);
|
|
1185
|
-
|
|
1186
|
-
const accountCredentials = sqliteCore.sqliteTable("account_credentials", {
|
|
1187
|
-
...backendSdk.base,
|
|
1188
|
-
accountId: sqliteCore.text("account_id").references(() => account.id).notNull(),
|
|
1189
|
-
connectorKey: sqliteCore.text("connector_key", {
|
|
1190
|
-
enum: CONNECTOR_KEYS
|
|
1191
|
-
}).$type().notNull(),
|
|
1192
|
-
type: sqliteCore.text("type", {
|
|
1193
|
-
enum: CREDENTIALS_TYPES
|
|
1194
|
-
}).$type().notNull(),
|
|
1195
|
-
value: sqliteCore.text("value").notNull(),
|
|
1196
|
-
expiresAt: sqliteCore.integer("expires_at", { mode: "timestamp_ms" }).notNull()
|
|
1197
|
-
});
|
|
1198
|
-
|
|
1199
|
-
const accountCredentialsInsertSchema = drizzleZod.createInsertSchema(accountCredentials);
|
|
1200
|
-
const accountCredentialsUpdateSchema = drizzleZod.createUpdateSchema(accountCredentials);
|
|
1201
|
-
const accountCredentialsSelectSchema = drizzleZod.createSelectSchema(accountCredentials);
|
|
1202
|
-
|
|
1203
|
-
const ott = sqliteCore.sqliteTable("ott", {
|
|
1204
|
-
...backendSdk.base,
|
|
1205
|
-
oneTimeToken: sqliteCore.text("one_time_token").notNull(),
|
|
1206
|
-
refId: sqliteCore.text("ref_id").notNull(),
|
|
1207
|
-
tokenType: sqliteCore.text("token_type", { enum: TOKEN_TYPES }).$type().notNull(),
|
|
1208
|
-
expiresAt: sqliteCore.integer("expires_at", { mode: "timestamp_ms" }).notNull()
|
|
1209
|
-
});
|
|
1210
|
-
|
|
1211
|
-
const ottInsertSchema = drizzleZod.createInsertSchema(ott);
|
|
1212
|
-
const ottUpdateSchema = drizzleZod.createUpdateSchema(ott);
|
|
1213
|
-
const ottSelectSchema = drizzleZod.createSelectSchema(ott);
|
|
1214
|
-
|
|
1215
|
-
const batch = sqliteCore.sqliteTable("batch", {
|
|
1216
|
-
...backendSdk.base,
|
|
1217
|
-
batchPaymentInitiatedAt: sqliteCore.integer("batch_payment_initiated_at", {
|
|
1218
|
-
mode: "timestamp_ms"
|
|
1219
|
-
}),
|
|
1220
|
-
authorizationUrls: sqliteCore.text("authorization_urls", { mode: "json" }).$type(),
|
|
1221
|
-
accountId: sqliteCore.text("account_id").references(() => account.id),
|
|
1222
|
-
status: sqliteCore.text("status", { enum: BATCH_STATUSES }).$type(),
|
|
1223
|
-
payments: sqliteCore.text("payments", { mode: "json" }).$type().notNull(),
|
|
1224
|
-
metadata: sqliteCore.text("metadata", { mode: "json" }).$type(),
|
|
1225
|
-
paymentsChecksum: sqliteCore.text("payments_checksum")
|
|
1226
|
-
});
|
|
1227
|
-
|
|
1228
|
-
const payment = sqliteCore.sqliteTable(
|
|
1229
|
-
"payment",
|
|
1230
|
-
{
|
|
1231
|
-
...backendSdk.base,
|
|
1232
|
-
correlationId: sqliteCore.text("correlation_id").notNull(),
|
|
1233
|
-
refId: sqliteCore.text("ref_id"),
|
|
1234
|
-
bankRefId: sqliteCore.text("bank_ref_id").notNull(),
|
|
1235
|
-
accountId: sqliteCore.text("account_id").references(() => account.id).notNull(),
|
|
1236
|
-
connectorKey: sqliteCore.text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
|
|
1237
|
-
amount: sqliteCore.real("amount").notNull(),
|
|
1238
|
-
direction: sqliteCore.text("direction").$type().notNull(),
|
|
1239
|
-
paymentType: sqliteCore.text("payment_type").$type().notNull(),
|
|
1240
|
-
currency: sqliteCore.text("currency").$type().notNull(),
|
|
1241
|
-
status: sqliteCore.text("status").$type().notNull(),
|
|
1242
|
-
statusReason: sqliteCore.text("status_reason"),
|
|
1243
|
-
batchId: sqliteCore.text("bank_execution_batch_id"),
|
|
1244
|
-
initiatedAt: sqliteCore.integer("initiated_at", {
|
|
1245
|
-
mode: "timestamp_ms"
|
|
1246
|
-
}),
|
|
1247
|
-
vs: sqliteCore.text("vs"),
|
|
1248
|
-
ss: sqliteCore.text("ss"),
|
|
1249
|
-
ks: sqliteCore.text("ks"),
|
|
1250
|
-
message: sqliteCore.text("message"),
|
|
1251
|
-
processedAt: sqliteCore.integer("processed_at", {
|
|
1252
|
-
mode: "timestamp_ms"
|
|
1253
|
-
}),
|
|
1254
|
-
creditor: sqliteCore.text("creditor", { mode: "json" }).$type().notNull(),
|
|
1255
|
-
creditorIban: sqliteCore.text("creditor_iban"),
|
|
1256
|
-
debtor: sqliteCore.text("debtor", { mode: "json" }).$type().notNull(),
|
|
1257
|
-
debtorIban: sqliteCore.text("debtor_iban")
|
|
1258
|
-
},
|
|
1259
|
-
(t) => [sqliteCore.unique().on(t.connectorKey, t.bankRefId)]
|
|
1260
|
-
);
|
|
1261
|
-
const paymentRelations = relations.relations(payment, ({ one }) => ({
|
|
1262
|
-
batch: one(batch, { fields: [payment.batchId], references: [batch.id] })
|
|
1263
|
-
}));
|
|
1264
|
-
|
|
1265
|
-
const schema = {
|
|
1266
|
-
__proto__: null,
|
|
1267
|
-
account: account,
|
|
1268
|
-
accountCredentials: accountCredentials,
|
|
1269
|
-
batch: batch,
|
|
1270
|
-
ott: ott,
|
|
1271
|
-
payment: payment,
|
|
1272
|
-
paymentRelations: paymentRelations
|
|
1273
|
-
};
|
|
1107
|
+
class MockCobsConnector extends FinbricksConnector {
|
|
1108
|
+
constructor(config) {
|
|
1109
|
+
super("MOCK_COBS", config);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1274
1112
|
|
|
1275
|
-
const tables = schema;
|
|
1113
|
+
const tables = database_schema.schema;
|
|
1276
1114
|
|
|
1277
|
-
exports.ACCOUNT_STATUSES = ACCOUNT_STATUSES;
|
|
1278
|
-
exports.BATCH_STATUSES = BATCH_STATUSES;
|
|
1279
|
-
exports.CHARGE_BEARERS = CHARGE_BEARERS;
|
|
1280
|
-
exports.CONNECTOR_KEYS = CONNECTOR_KEYS;
|
|
1281
|
-
exports.COUNTRY_CODES = COUNTRY_CODES;
|
|
1282
|
-
exports.CREDENTIALS_TYPES = CREDENTIALS_TYPES;
|
|
1283
1115
|
exports.ErsteConnector = ErsteConnector;
|
|
1284
1116
|
exports.FINBRICKS_ENDPOINTS = FINBRICKS_ENDPOINTS;
|
|
1285
1117
|
exports.FinbricksClient = FinbricksClient;
|
|
1286
1118
|
exports.FinbricksConnector = FinbricksConnector;
|
|
1287
1119
|
exports.IBankConnector = IBankConnector;
|
|
1288
|
-
exports.
|
|
1120
|
+
exports.MockCobsConnector = MockCobsConnector;
|
|
1289
1121
|
exports.MockConnector = MockConnector;
|
|
1290
|
-
exports.PAYMENT_DIRECTIONS = PAYMENT_DIRECTIONS;
|
|
1291
|
-
exports.PAYMENT_STATUSES = PAYMENT_STATUSES;
|
|
1292
|
-
exports.PAYMENT_TYPES = PAYMENT_TYPES;
|
|
1293
|
-
exports.TOKEN_TYPES = TOKEN_TYPES;
|
|
1294
|
-
exports.account = account;
|
|
1295
|
-
exports.accountCredentials = accountCredentials;
|
|
1296
|
-
exports.accountCredentialsInsertSchema = accountCredentialsInsertSchema;
|
|
1297
|
-
exports.accountCredentialsSelectSchema = accountCredentialsSelectSchema;
|
|
1298
|
-
exports.accountCredentialsUpdateSchema = accountCredentialsUpdateSchema;
|
|
1299
|
-
exports.accountInsertSchema = accountInsertSchema;
|
|
1300
|
-
exports.accountSelectSchema = accountSelectSchema;
|
|
1301
|
-
exports.accountUpdateSchema = accountUpdateSchema;
|
|
1302
|
-
exports.batch = batch;
|
|
1303
|
-
exports.ott = ott;
|
|
1304
|
-
exports.ottInsertSchema = ottInsertSchema;
|
|
1305
|
-
exports.ottSelectSchema = ottSelectSchema;
|
|
1306
|
-
exports.ottUpdateSchema = ottUpdateSchema;
|
|
1307
|
-
exports.payment = payment;
|
|
1308
|
-
exports.paymentRelations = paymentRelations;
|
|
1309
1122
|
exports.signFinbricksJws = signFinbricksJws;
|
|
1310
1123
|
exports.tables = tables;
|
|
1311
1124
|
exports.useFinbricksFetch = useFinbricksFetch;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const backendSdk = require('@develit-io/backend-sdk');
|
|
4
|
+
const sqliteCore = require('drizzle-orm/sqlite-core');
|
|
5
|
+
require('date-fns');
|
|
6
|
+
const relations = require('drizzle-orm/relations');
|
|
7
|
+
const generalCodes = require('@develit-io/general-codes');
|
|
8
|
+
require('drizzle-orm');
|
|
9
|
+
require('jose');
|
|
10
|
+
require('node:crypto');
|
|
11
|
+
const drizzleZod = require('drizzle-zod');
|
|
12
|
+
|
|
13
|
+
const PAYMENT_TYPES = ["SEPA", "SWIFT", "DOMESTIC", "UNKNOWN"];
|
|
14
|
+
const CHARGE_BEARERS = ["SHA", "OUR", "BEN"];
|
|
15
|
+
const INSTRUCTION_PRIORITIES = ["NORM", "HIGH", "INST"];
|
|
16
|
+
const PAYMENT_STATUSES = [
|
|
17
|
+
"PREPARED",
|
|
18
|
+
"INITIALIZED",
|
|
19
|
+
"FAILED",
|
|
20
|
+
"PENDING",
|
|
21
|
+
"COMPLETED",
|
|
22
|
+
"CREATED"
|
|
23
|
+
];
|
|
24
|
+
const PAYMENT_DIRECTIONS = ["INCOMING", "OUTGOING"];
|
|
25
|
+
const BATCH_STATUSES = [
|
|
26
|
+
"OPEN",
|
|
27
|
+
"FULL",
|
|
28
|
+
"PROCESSING",
|
|
29
|
+
"READY_TO_SIGN",
|
|
30
|
+
"SIGNED",
|
|
31
|
+
"SIGNATURE_FAILED",
|
|
32
|
+
"FAILED"
|
|
33
|
+
];
|
|
34
|
+
const ACCOUNT_STATUSES = ["AUTHORIZED", "DISABLED", "EXPIRED"];
|
|
35
|
+
const COUNTRY_CODES = generalCodes.COUNTRY_CODES_2;
|
|
36
|
+
|
|
37
|
+
const CONNECTOR_KEYS = [
|
|
38
|
+
"ERSTE",
|
|
39
|
+
"FINBRICKS",
|
|
40
|
+
"MOCK",
|
|
41
|
+
"CREDITAS",
|
|
42
|
+
"MOCK_COBS",
|
|
43
|
+
"FIO",
|
|
44
|
+
"MONETA"
|
|
45
|
+
];
|
|
46
|
+
const CREDENTIALS_TYPES = [
|
|
47
|
+
"AUTH_TOKEN",
|
|
48
|
+
"REFRESH_TOKEN",
|
|
49
|
+
"CLIENT_ID",
|
|
50
|
+
"API_KEY"
|
|
51
|
+
];
|
|
52
|
+
const TOKEN_TYPES = ["ACCOUNT_AUTHORIZATION"];
|
|
53
|
+
|
|
54
|
+
const account = sqliteCore.sqliteTable(
|
|
55
|
+
"account",
|
|
56
|
+
{
|
|
57
|
+
...backendSdk.base,
|
|
58
|
+
...backendSdk.bankAccount,
|
|
59
|
+
number: sqliteCore.text("number").notNull(),
|
|
60
|
+
name: sqliteCore.text("name"),
|
|
61
|
+
iban: sqliteCore.text("iban").notNull(),
|
|
62
|
+
bankCode: sqliteCore.text("bank_code", { enum: generalCodes.BANK_CODES }).notNull(),
|
|
63
|
+
connectorKey: sqliteCore.text("connector_key", {
|
|
64
|
+
enum: CONNECTOR_KEYS
|
|
65
|
+
}).$type().notNull(),
|
|
66
|
+
status: sqliteCore.text("status", { enum: ACCOUNT_STATUSES }).$type().notNull(),
|
|
67
|
+
bankRefId: sqliteCore.text("bank_ref_id").notNull(),
|
|
68
|
+
batchSizeLimit: sqliteCore.integer("batch_size_limit").notNull().default(50),
|
|
69
|
+
syncIntervalS: sqliteCore.integer("sync_interval_s").notNull().default(600),
|
|
70
|
+
lastSyncAt: sqliteCore.integer("last_sync_at", { mode: "timestamp_ms" }),
|
|
71
|
+
lastSyncMetadata: sqliteCore.text("last_sync_metadata", {
|
|
72
|
+
mode: "json"
|
|
73
|
+
}).$type()
|
|
74
|
+
},
|
|
75
|
+
(t) => [sqliteCore.unique().on(t.iban)]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const accountInsertSchema = drizzleZod.createInsertSchema(account);
|
|
79
|
+
const accountUpdateSchema = drizzleZod.createUpdateSchema(account);
|
|
80
|
+
const accountSelectSchema = drizzleZod.createSelectSchema(account);
|
|
81
|
+
|
|
82
|
+
const accountCredentials = sqliteCore.sqliteTable("account_credentials", {
|
|
83
|
+
...backendSdk.base,
|
|
84
|
+
accountId: sqliteCore.text("account_id").references(() => account.id).notNull(),
|
|
85
|
+
connectorKey: sqliteCore.text("connector_key", {
|
|
86
|
+
enum: CONNECTOR_KEYS
|
|
87
|
+
}).$type().notNull(),
|
|
88
|
+
type: sqliteCore.text("type", {
|
|
89
|
+
enum: CREDENTIALS_TYPES
|
|
90
|
+
}).$type().notNull(),
|
|
91
|
+
value: sqliteCore.text("value").notNull(),
|
|
92
|
+
expiresAt: sqliteCore.integer("expires_at", { mode: "timestamp_ms" }).notNull()
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const accountCredentialsInsertSchema = drizzleZod.createInsertSchema(accountCredentials);
|
|
96
|
+
const accountCredentialsUpdateSchema = drizzleZod.createUpdateSchema(accountCredentials);
|
|
97
|
+
const accountCredentialsSelectSchema = drizzleZod.createSelectSchema(accountCredentials);
|
|
98
|
+
|
|
99
|
+
const ott = sqliteCore.sqliteTable("ott", {
|
|
100
|
+
...backendSdk.base,
|
|
101
|
+
oneTimeToken: sqliteCore.text("one_time_token").notNull(),
|
|
102
|
+
refId: sqliteCore.text("ref_id").notNull(),
|
|
103
|
+
tokenType: sqliteCore.text("token_type", { enum: TOKEN_TYPES }).$type().notNull(),
|
|
104
|
+
expiresAt: sqliteCore.integer("expires_at", { mode: "timestamp_ms" }).notNull()
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const ottInsertSchema = drizzleZod.createInsertSchema(ott);
|
|
108
|
+
const ottUpdateSchema = drizzleZod.createUpdateSchema(ott);
|
|
109
|
+
const ottSelectSchema = drizzleZod.createSelectSchema(ott);
|
|
110
|
+
|
|
111
|
+
const batch = sqliteCore.sqliteTable("batch", {
|
|
112
|
+
...backendSdk.base,
|
|
113
|
+
batchPaymentInitiatedAt: sqliteCore.integer("batch_payment_initiated_at", {
|
|
114
|
+
mode: "timestamp_ms"
|
|
115
|
+
}),
|
|
116
|
+
authorizationUrls: sqliteCore.text("authorization_urls", { mode: "json" }).$type(),
|
|
117
|
+
accountId: sqliteCore.text("account_id").references(() => account.id),
|
|
118
|
+
status: sqliteCore.text("status", { enum: BATCH_STATUSES }).$type(),
|
|
119
|
+
statusReason: sqliteCore.text("status_reason"),
|
|
120
|
+
payments: sqliteCore.text("payments", { mode: "json" }).$type().notNull(),
|
|
121
|
+
metadata: sqliteCore.text("metadata", { mode: "json" }).$type(),
|
|
122
|
+
paymentsChecksum: sqliteCore.text("payments_checksum")
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const payment = sqliteCore.sqliteTable(
|
|
126
|
+
"payment",
|
|
127
|
+
{
|
|
128
|
+
...backendSdk.base,
|
|
129
|
+
correlationId: sqliteCore.text("correlation_id").notNull(),
|
|
130
|
+
refId: sqliteCore.text("ref_id"),
|
|
131
|
+
bankRefId: sqliteCore.text("bank_ref_id").notNull(),
|
|
132
|
+
accountId: sqliteCore.text("account_id").references(() => account.id).notNull(),
|
|
133
|
+
connectorKey: sqliteCore.text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
|
|
134
|
+
amount: sqliteCore.real("amount").notNull(),
|
|
135
|
+
direction: sqliteCore.text("direction").$type().notNull(),
|
|
136
|
+
paymentType: sqliteCore.text("payment_type").$type().notNull(),
|
|
137
|
+
currency: sqliteCore.text("currency").$type().notNull(),
|
|
138
|
+
status: sqliteCore.text("status").$type().notNull(),
|
|
139
|
+
statusReason: sqliteCore.text("status_reason"),
|
|
140
|
+
batchId: sqliteCore.text("bank_execution_batch_id"),
|
|
141
|
+
initiatedAt: sqliteCore.integer("initiated_at", {
|
|
142
|
+
mode: "timestamp_ms"
|
|
143
|
+
}),
|
|
144
|
+
vs: sqliteCore.text("vs"),
|
|
145
|
+
ss: sqliteCore.text("ss"),
|
|
146
|
+
ks: sqliteCore.text("ks"),
|
|
147
|
+
message: sqliteCore.text("message"),
|
|
148
|
+
processedAt: sqliteCore.integer("processed_at", {
|
|
149
|
+
mode: "timestamp_ms"
|
|
150
|
+
}),
|
|
151
|
+
creditor: sqliteCore.text("creditor", { mode: "json" }).$type().notNull(),
|
|
152
|
+
creditorIban: sqliteCore.text("creditor_iban"),
|
|
153
|
+
debtor: sqliteCore.text("debtor", { mode: "json" }).$type().notNull(),
|
|
154
|
+
debtorIban: sqliteCore.text("debtor_iban")
|
|
155
|
+
},
|
|
156
|
+
(t) => [sqliteCore.unique().on(t.connectorKey, t.bankRefId)]
|
|
157
|
+
);
|
|
158
|
+
const paymentRelations = relations.relations(payment, ({ one }) => ({
|
|
159
|
+
batch: one(batch, { fields: [payment.batchId], references: [batch.id] })
|
|
160
|
+
}));
|
|
161
|
+
|
|
162
|
+
const schema = {
|
|
163
|
+
__proto__: null,
|
|
164
|
+
account: account,
|
|
165
|
+
accountCredentials: accountCredentials,
|
|
166
|
+
batch: batch,
|
|
167
|
+
ott: ott,
|
|
168
|
+
payment: payment,
|
|
169
|
+
paymentRelations: paymentRelations
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
exports.ACCOUNT_STATUSES = ACCOUNT_STATUSES;
|
|
173
|
+
exports.BATCH_STATUSES = BATCH_STATUSES;
|
|
174
|
+
exports.CHARGE_BEARERS = CHARGE_BEARERS;
|
|
175
|
+
exports.CONNECTOR_KEYS = CONNECTOR_KEYS;
|
|
176
|
+
exports.COUNTRY_CODES = COUNTRY_CODES;
|
|
177
|
+
exports.CREDENTIALS_TYPES = CREDENTIALS_TYPES;
|
|
178
|
+
exports.INSTRUCTION_PRIORITIES = INSTRUCTION_PRIORITIES;
|
|
179
|
+
exports.PAYMENT_DIRECTIONS = PAYMENT_DIRECTIONS;
|
|
180
|
+
exports.PAYMENT_STATUSES = PAYMENT_STATUSES;
|
|
181
|
+
exports.PAYMENT_TYPES = PAYMENT_TYPES;
|
|
182
|
+
exports.TOKEN_TYPES = TOKEN_TYPES;
|
|
183
|
+
exports.account = account;
|
|
184
|
+
exports.accountCredentials = accountCredentials;
|
|
185
|
+
exports.accountCredentialsInsertSchema = accountCredentialsInsertSchema;
|
|
186
|
+
exports.accountCredentialsSelectSchema = accountCredentialsSelectSchema;
|
|
187
|
+
exports.accountCredentialsUpdateSchema = accountCredentialsUpdateSchema;
|
|
188
|
+
exports.accountInsertSchema = accountInsertSchema;
|
|
189
|
+
exports.accountSelectSchema = accountSelectSchema;
|
|
190
|
+
exports.accountUpdateSchema = accountUpdateSchema;
|
|
191
|
+
exports.batch = batch;
|
|
192
|
+
exports.ott = ott;
|
|
193
|
+
exports.ottInsertSchema = ottInsertSchema;
|
|
194
|
+
exports.ottSelectSchema = ottSelectSchema;
|
|
195
|
+
exports.ottUpdateSchema = ottUpdateSchema;
|
|
196
|
+
exports.payment = payment;
|
|
197
|
+
exports.paymentRelations = paymentRelations;
|
|
198
|
+
exports.schema = schema;
|