@develit-services/bank 0.3.44 → 0.3.46
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 +201 -183
- package/dist/export/worker.d.cts +51 -20
- package/dist/export/worker.d.mts +51 -20
- package/dist/export/worker.d.ts +51 -20
- package/dist/export/worker.mjs +161 -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.DFRS9oN5.mjs → bank.B1Gpn3ht.mjs} +9 -172
- package/dist/shared/{bank.D8wUOeOK.d.cts → bank.BEL1HIxZ.d.cts} +20 -1
- package/dist/shared/{bank.D8wUOeOK.d.mts → bank.BEL1HIxZ.d.mts} +20 -1
- package/dist/shared/{bank.D8wUOeOK.d.ts → bank.BEL1HIxZ.d.ts} +20 -1
- package/dist/shared/bank.BUEmFxS8.mjs +174 -0
- package/dist/shared/{bank.C335-raZ.cjs → bank.CPYfE-Ei.cjs} +9 -197
- 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 +3 -6
- package/dist/types.d.mts +3 -6
- package/dist/types.d.ts +3 -6
- package/dist/types.mjs +5 -5
- package/package.json +1 -1
- package/dist/shared/bank.Cj-oB02_.mjs +0 -392
- package/dist/shared/bank.ClRIj2Ma.cjs +0 -11
- package/dist/shared/bank.DhPfZ6b_.mjs +0 -9
- package/dist/shared/bank.DwyrLcKu.cjs +0 -402
|
@@ -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 = {
|
|
@@ -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}`,
|
|
@@ -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
|
}
|
|
@@ -1115,198 +1104,21 @@ class MockConnector extends IBankConnector {
|
|
|
1115
1104
|
}
|
|
1116
1105
|
}
|
|
1117
1106
|
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
"INITIALIZED",
|
|
1124
|
-
"FAILED",
|
|
1125
|
-
"PENDING",
|
|
1126
|
-
"COMPLETED",
|
|
1127
|
-
"CREATED"
|
|
1128
|
-
];
|
|
1129
|
-
const PAYMENT_DIRECTIONS = ["INCOMING", "OUTGOING"];
|
|
1130
|
-
const BATCH_STATUSES = [
|
|
1131
|
-
"OPEN",
|
|
1132
|
-
"FULL",
|
|
1133
|
-
"PROCESSING",
|
|
1134
|
-
"READY_TO_SIGN",
|
|
1135
|
-
"SIGNED",
|
|
1136
|
-
"SIGNATURE_FAILED",
|
|
1137
|
-
"FAILED"
|
|
1138
|
-
];
|
|
1139
|
-
const ACCOUNT_STATUSES = ["AUTHORIZED", "DISABLED", "EXPIRED"];
|
|
1140
|
-
const COUNTRY_CODES = generalCodes.COUNTRY_CODES_2;
|
|
1141
|
-
|
|
1142
|
-
const CONNECTOR_KEYS = [
|
|
1143
|
-
"ERSTE",
|
|
1144
|
-
"FINBRICKS",
|
|
1145
|
-
"MOCK",
|
|
1146
|
-
"CREDITAS",
|
|
1147
|
-
"MOCK_COBS",
|
|
1148
|
-
"FIO",
|
|
1149
|
-
"MONETA"
|
|
1150
|
-
];
|
|
1151
|
-
const CREDENTIALS_TYPES = [
|
|
1152
|
-
"AUTH_TOKEN",
|
|
1153
|
-
"REFRESH_TOKEN",
|
|
1154
|
-
"CLIENT_ID",
|
|
1155
|
-
"API_KEY"
|
|
1156
|
-
];
|
|
1157
|
-
const TOKEN_TYPES = ["ACCOUNT_AUTHORIZATION"];
|
|
1158
|
-
|
|
1159
|
-
const account = sqliteCore.sqliteTable(
|
|
1160
|
-
"account",
|
|
1161
|
-
{
|
|
1162
|
-
...backendSdk.base,
|
|
1163
|
-
...backendSdk.bankAccount,
|
|
1164
|
-
number: sqliteCore.text("number").notNull(),
|
|
1165
|
-
name: sqliteCore.text("name"),
|
|
1166
|
-
iban: sqliteCore.text("iban").notNull(),
|
|
1167
|
-
bankCode: sqliteCore.text("bank_code", { enum: generalCodes.BANK_CODES }).notNull(),
|
|
1168
|
-
connectorKey: sqliteCore.text("connector_key", {
|
|
1169
|
-
enum: CONNECTOR_KEYS
|
|
1170
|
-
}).$type().notNull(),
|
|
1171
|
-
status: sqliteCore.text("status", { enum: ACCOUNT_STATUSES }).$type().notNull(),
|
|
1172
|
-
bankRefId: sqliteCore.text("bank_ref_id").notNull(),
|
|
1173
|
-
batchSizeLimit: sqliteCore.integer("batch_size_limit").notNull().default(50),
|
|
1174
|
-
syncIntervalS: sqliteCore.integer("sync_interval_s").notNull().default(600),
|
|
1175
|
-
lastSyncAt: sqliteCore.integer("last_sync_at", { mode: "timestamp_ms" }),
|
|
1176
|
-
lastSyncMetadata: sqliteCore.text("last_sync_metadata", {
|
|
1177
|
-
mode: "json"
|
|
1178
|
-
}).$type()
|
|
1179
|
-
},
|
|
1180
|
-
(t) => [sqliteCore.unique().on(t.iban)]
|
|
1181
|
-
);
|
|
1182
|
-
|
|
1183
|
-
const accountInsertSchema = drizzleZod.createInsertSchema(account);
|
|
1184
|
-
const accountUpdateSchema = drizzleZod.createUpdateSchema(account);
|
|
1185
|
-
const accountSelectSchema = drizzleZod.createSelectSchema(account);
|
|
1186
|
-
|
|
1187
|
-
const accountCredentials = sqliteCore.sqliteTable("account_credentials", {
|
|
1188
|
-
...backendSdk.base,
|
|
1189
|
-
accountId: sqliteCore.text("account_id").references(() => account.id).notNull(),
|
|
1190
|
-
connectorKey: sqliteCore.text("connector_key", {
|
|
1191
|
-
enum: CONNECTOR_KEYS
|
|
1192
|
-
}).$type().notNull(),
|
|
1193
|
-
type: sqliteCore.text("type", {
|
|
1194
|
-
enum: CREDENTIALS_TYPES
|
|
1195
|
-
}).$type().notNull(),
|
|
1196
|
-
value: sqliteCore.text("value").notNull(),
|
|
1197
|
-
expiresAt: sqliteCore.integer("expires_at", { mode: "timestamp_ms" }).notNull()
|
|
1198
|
-
});
|
|
1199
|
-
|
|
1200
|
-
const accountCredentialsInsertSchema = drizzleZod.createInsertSchema(accountCredentials);
|
|
1201
|
-
const accountCredentialsUpdateSchema = drizzleZod.createUpdateSchema(accountCredentials);
|
|
1202
|
-
const accountCredentialsSelectSchema = drizzleZod.createSelectSchema(accountCredentials);
|
|
1203
|
-
|
|
1204
|
-
const ott = sqliteCore.sqliteTable("ott", {
|
|
1205
|
-
...backendSdk.base,
|
|
1206
|
-
oneTimeToken: sqliteCore.text("one_time_token").notNull(),
|
|
1207
|
-
refId: sqliteCore.text("ref_id").notNull(),
|
|
1208
|
-
tokenType: sqliteCore.text("token_type", { enum: TOKEN_TYPES }).$type().notNull(),
|
|
1209
|
-
expiresAt: sqliteCore.integer("expires_at", { mode: "timestamp_ms" }).notNull()
|
|
1210
|
-
});
|
|
1211
|
-
|
|
1212
|
-
const ottInsertSchema = drizzleZod.createInsertSchema(ott);
|
|
1213
|
-
const ottUpdateSchema = drizzleZod.createUpdateSchema(ott);
|
|
1214
|
-
const ottSelectSchema = drizzleZod.createSelectSchema(ott);
|
|
1215
|
-
|
|
1216
|
-
const batch = sqliteCore.sqliteTable("batch", {
|
|
1217
|
-
...backendSdk.base,
|
|
1218
|
-
batchPaymentInitiatedAt: sqliteCore.integer("batch_payment_initiated_at", {
|
|
1219
|
-
mode: "timestamp_ms"
|
|
1220
|
-
}),
|
|
1221
|
-
authorizationUrls: sqliteCore.text("authorization_urls", { mode: "json" }).$type(),
|
|
1222
|
-
accountId: sqliteCore.text("account_id").references(() => account.id),
|
|
1223
|
-
status: sqliteCore.text("status", { enum: BATCH_STATUSES }).$type(),
|
|
1224
|
-
payments: sqliteCore.text("payments", { mode: "json" }).$type().notNull(),
|
|
1225
|
-
metadata: sqliteCore.text("metadata", { mode: "json" }).$type(),
|
|
1226
|
-
paymentsChecksum: sqliteCore.text("payments_checksum")
|
|
1227
|
-
});
|
|
1228
|
-
|
|
1229
|
-
const payment = sqliteCore.sqliteTable(
|
|
1230
|
-
"payment",
|
|
1231
|
-
{
|
|
1232
|
-
...backendSdk.base,
|
|
1233
|
-
correlationId: sqliteCore.text("correlation_id").notNull(),
|
|
1234
|
-
refId: sqliteCore.text("ref_id"),
|
|
1235
|
-
bankRefId: sqliteCore.text("bank_ref_id").notNull(),
|
|
1236
|
-
accountId: sqliteCore.text("account_id").references(() => account.id).notNull(),
|
|
1237
|
-
connectorKey: sqliteCore.text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
|
|
1238
|
-
amount: sqliteCore.real("amount").notNull(),
|
|
1239
|
-
direction: sqliteCore.text("direction").$type().notNull(),
|
|
1240
|
-
paymentType: sqliteCore.text("payment_type").$type().notNull(),
|
|
1241
|
-
currency: sqliteCore.text("currency").$type().notNull(),
|
|
1242
|
-
status: sqliteCore.text("status").$type().notNull(),
|
|
1243
|
-
statusReason: sqliteCore.text("status_reason"),
|
|
1244
|
-
batchId: sqliteCore.text("bank_execution_batch_id"),
|
|
1245
|
-
initiatedAt: sqliteCore.integer("initiated_at", {
|
|
1246
|
-
mode: "timestamp_ms"
|
|
1247
|
-
}),
|
|
1248
|
-
vs: sqliteCore.text("vs"),
|
|
1249
|
-
ss: sqliteCore.text("ss"),
|
|
1250
|
-
ks: sqliteCore.text("ks"),
|
|
1251
|
-
message: sqliteCore.text("message"),
|
|
1252
|
-
processedAt: sqliteCore.integer("processed_at", {
|
|
1253
|
-
mode: "timestamp_ms"
|
|
1254
|
-
}),
|
|
1255
|
-
creditor: sqliteCore.text("creditor", { mode: "json" }).$type().notNull(),
|
|
1256
|
-
creditorIban: sqliteCore.text("creditor_iban"),
|
|
1257
|
-
debtor: sqliteCore.text("debtor", { mode: "json" }).$type().notNull(),
|
|
1258
|
-
debtorIban: sqliteCore.text("debtor_iban")
|
|
1259
|
-
},
|
|
1260
|
-
(t) => [sqliteCore.unique().on(t.connectorKey, t.bankRefId)]
|
|
1261
|
-
);
|
|
1262
|
-
const paymentRelations = relations.relations(payment, ({ one }) => ({
|
|
1263
|
-
batch: one(batch, { fields: [payment.batchId], references: [batch.id] })
|
|
1264
|
-
}));
|
|
1265
|
-
|
|
1266
|
-
const schema = {
|
|
1267
|
-
__proto__: null,
|
|
1268
|
-
account: account,
|
|
1269
|
-
accountCredentials: accountCredentials,
|
|
1270
|
-
batch: batch,
|
|
1271
|
-
ott: ott,
|
|
1272
|
-
payment: payment,
|
|
1273
|
-
paymentRelations: paymentRelations
|
|
1274
|
-
};
|
|
1107
|
+
class MockCobsConnector extends FinbricksConnector {
|
|
1108
|
+
constructor(config) {
|
|
1109
|
+
super("MOCK_COBS", config);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1275
1112
|
|
|
1276
|
-
const tables = schema;
|
|
1113
|
+
const tables = database_schema.schema;
|
|
1277
1114
|
|
|
1278
|
-
exports.ACCOUNT_STATUSES = ACCOUNT_STATUSES;
|
|
1279
|
-
exports.BATCH_STATUSES = BATCH_STATUSES;
|
|
1280
|
-
exports.CHARGE_BEARERS = CHARGE_BEARERS;
|
|
1281
|
-
exports.CONNECTOR_KEYS = CONNECTOR_KEYS;
|
|
1282
|
-
exports.COUNTRY_CODES = COUNTRY_CODES;
|
|
1283
|
-
exports.CREDENTIALS_TYPES = CREDENTIALS_TYPES;
|
|
1284
1115
|
exports.ErsteConnector = ErsteConnector;
|
|
1285
1116
|
exports.FINBRICKS_ENDPOINTS = FINBRICKS_ENDPOINTS;
|
|
1286
1117
|
exports.FinbricksClient = FinbricksClient;
|
|
1287
1118
|
exports.FinbricksConnector = FinbricksConnector;
|
|
1288
1119
|
exports.IBankConnector = IBankConnector;
|
|
1289
|
-
exports.
|
|
1120
|
+
exports.MockCobsConnector = MockCobsConnector;
|
|
1290
1121
|
exports.MockConnector = MockConnector;
|
|
1291
|
-
exports.PAYMENT_DIRECTIONS = PAYMENT_DIRECTIONS;
|
|
1292
|
-
exports.PAYMENT_STATUSES = PAYMENT_STATUSES;
|
|
1293
|
-
exports.PAYMENT_TYPES = PAYMENT_TYPES;
|
|
1294
|
-
exports.TOKEN_TYPES = TOKEN_TYPES;
|
|
1295
|
-
exports.account = account;
|
|
1296
|
-
exports.accountCredentials = accountCredentials;
|
|
1297
|
-
exports.accountCredentialsInsertSchema = accountCredentialsInsertSchema;
|
|
1298
|
-
exports.accountCredentialsSelectSchema = accountCredentialsSelectSchema;
|
|
1299
|
-
exports.accountCredentialsUpdateSchema = accountCredentialsUpdateSchema;
|
|
1300
|
-
exports.accountInsertSchema = accountInsertSchema;
|
|
1301
|
-
exports.accountSelectSchema = accountSelectSchema;
|
|
1302
|
-
exports.accountUpdateSchema = accountUpdateSchema;
|
|
1303
|
-
exports.batch = batch;
|
|
1304
|
-
exports.ott = ott;
|
|
1305
|
-
exports.ottInsertSchema = ottInsertSchema;
|
|
1306
|
-
exports.ottSelectSchema = ottSelectSchema;
|
|
1307
|
-
exports.ottUpdateSchema = ottUpdateSchema;
|
|
1308
|
-
exports.payment = payment;
|
|
1309
|
-
exports.paymentRelations = paymentRelations;
|
|
1310
1122
|
exports.signFinbricksJws = signFinbricksJws;
|
|
1311
1123
|
exports.tables = tables;
|
|
1312
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;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { bankAccount, base } from '@develit-io/backend-sdk';
|
|
2
|
+
import { sqliteTable, text, integer, unique, real } from 'drizzle-orm/sqlite-core';
|
|
3
|
+
import 'date-fns';
|
|
4
|
+
import { relations } from 'drizzle-orm/relations';
|
|
5
|
+
import { COUNTRY_CODES_2, BANK_CODES } from '@develit-io/general-codes';
|
|
6
|
+
import 'drizzle-orm';
|
|
7
|
+
import 'jose';
|
|
8
|
+
import 'node:crypto';
|
|
9
|
+
import { createInsertSchema, createUpdateSchema, createSelectSchema } from 'drizzle-zod';
|
|
10
|
+
|
|
11
|
+
const PAYMENT_TYPES = ["SEPA", "SWIFT", "DOMESTIC", "UNKNOWN"];
|
|
12
|
+
const CHARGE_BEARERS = ["SHA", "OUR", "BEN"];
|
|
13
|
+
const INSTRUCTION_PRIORITIES = ["NORM", "HIGH", "INST"];
|
|
14
|
+
const PAYMENT_STATUSES = [
|
|
15
|
+
"PREPARED",
|
|
16
|
+
"INITIALIZED",
|
|
17
|
+
"FAILED",
|
|
18
|
+
"PENDING",
|
|
19
|
+
"COMPLETED",
|
|
20
|
+
"CREATED"
|
|
21
|
+
];
|
|
22
|
+
const PAYMENT_DIRECTIONS = ["INCOMING", "OUTGOING"];
|
|
23
|
+
const BATCH_STATUSES = [
|
|
24
|
+
"OPEN",
|
|
25
|
+
"FULL",
|
|
26
|
+
"PROCESSING",
|
|
27
|
+
"READY_TO_SIGN",
|
|
28
|
+
"SIGNED",
|
|
29
|
+
"SIGNATURE_FAILED",
|
|
30
|
+
"FAILED"
|
|
31
|
+
];
|
|
32
|
+
const ACCOUNT_STATUSES = ["AUTHORIZED", "DISABLED", "EXPIRED"];
|
|
33
|
+
const COUNTRY_CODES = COUNTRY_CODES_2;
|
|
34
|
+
|
|
35
|
+
const CONNECTOR_KEYS = [
|
|
36
|
+
"ERSTE",
|
|
37
|
+
"FINBRICKS",
|
|
38
|
+
"MOCK",
|
|
39
|
+
"CREDITAS",
|
|
40
|
+
"MOCK_COBS",
|
|
41
|
+
"FIO",
|
|
42
|
+
"MONETA"
|
|
43
|
+
];
|
|
44
|
+
const CREDENTIALS_TYPES = [
|
|
45
|
+
"AUTH_TOKEN",
|
|
46
|
+
"REFRESH_TOKEN",
|
|
47
|
+
"CLIENT_ID",
|
|
48
|
+
"API_KEY"
|
|
49
|
+
];
|
|
50
|
+
const TOKEN_TYPES = ["ACCOUNT_AUTHORIZATION"];
|
|
51
|
+
|
|
52
|
+
const account = sqliteTable(
|
|
53
|
+
"account",
|
|
54
|
+
{
|
|
55
|
+
...base,
|
|
56
|
+
...bankAccount,
|
|
57
|
+
number: text("number").notNull(),
|
|
58
|
+
name: text("name"),
|
|
59
|
+
iban: text("iban").notNull(),
|
|
60
|
+
bankCode: text("bank_code", { enum: BANK_CODES }).notNull(),
|
|
61
|
+
connectorKey: text("connector_key", {
|
|
62
|
+
enum: CONNECTOR_KEYS
|
|
63
|
+
}).$type().notNull(),
|
|
64
|
+
status: text("status", { enum: ACCOUNT_STATUSES }).$type().notNull(),
|
|
65
|
+
bankRefId: text("bank_ref_id").notNull(),
|
|
66
|
+
batchSizeLimit: integer("batch_size_limit").notNull().default(50),
|
|
67
|
+
syncIntervalS: integer("sync_interval_s").notNull().default(600),
|
|
68
|
+
lastSyncAt: integer("last_sync_at", { mode: "timestamp_ms" }),
|
|
69
|
+
lastSyncMetadata: text("last_sync_metadata", {
|
|
70
|
+
mode: "json"
|
|
71
|
+
}).$type()
|
|
72
|
+
},
|
|
73
|
+
(t) => [unique().on(t.iban)]
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const accountInsertSchema = createInsertSchema(account);
|
|
77
|
+
const accountUpdateSchema = createUpdateSchema(account);
|
|
78
|
+
const accountSelectSchema = createSelectSchema(account);
|
|
79
|
+
|
|
80
|
+
const accountCredentials = sqliteTable("account_credentials", {
|
|
81
|
+
...base,
|
|
82
|
+
accountId: text("account_id").references(() => account.id).notNull(),
|
|
83
|
+
connectorKey: text("connector_key", {
|
|
84
|
+
enum: CONNECTOR_KEYS
|
|
85
|
+
}).$type().notNull(),
|
|
86
|
+
type: text("type", {
|
|
87
|
+
enum: CREDENTIALS_TYPES
|
|
88
|
+
}).$type().notNull(),
|
|
89
|
+
value: text("value").notNull(),
|
|
90
|
+
expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull()
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const accountCredentialsInsertSchema = createInsertSchema(accountCredentials);
|
|
94
|
+
const accountCredentialsUpdateSchema = createUpdateSchema(accountCredentials);
|
|
95
|
+
const accountCredentialsSelectSchema = createSelectSchema(accountCredentials);
|
|
96
|
+
|
|
97
|
+
const ott = sqliteTable("ott", {
|
|
98
|
+
...base,
|
|
99
|
+
oneTimeToken: text("one_time_token").notNull(),
|
|
100
|
+
refId: text("ref_id").notNull(),
|
|
101
|
+
tokenType: text("token_type", { enum: TOKEN_TYPES }).$type().notNull(),
|
|
102
|
+
expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull()
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const ottInsertSchema = createInsertSchema(ott);
|
|
106
|
+
const ottUpdateSchema = createUpdateSchema(ott);
|
|
107
|
+
const ottSelectSchema = createSelectSchema(ott);
|
|
108
|
+
|
|
109
|
+
const batch = sqliteTable("batch", {
|
|
110
|
+
...base,
|
|
111
|
+
batchPaymentInitiatedAt: integer("batch_payment_initiated_at", {
|
|
112
|
+
mode: "timestamp_ms"
|
|
113
|
+
}),
|
|
114
|
+
authorizationUrls: text("authorization_urls", { mode: "json" }).$type(),
|
|
115
|
+
accountId: text("account_id").references(() => account.id),
|
|
116
|
+
status: text("status", { enum: BATCH_STATUSES }).$type(),
|
|
117
|
+
statusReason: text("status_reason"),
|
|
118
|
+
payments: text("payments", { mode: "json" }).$type().notNull(),
|
|
119
|
+
metadata: text("metadata", { mode: "json" }).$type(),
|
|
120
|
+
paymentsChecksum: text("payments_checksum")
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const payment = sqliteTable(
|
|
124
|
+
"payment",
|
|
125
|
+
{
|
|
126
|
+
...base,
|
|
127
|
+
correlationId: text("correlation_id").notNull(),
|
|
128
|
+
refId: text("ref_id"),
|
|
129
|
+
bankRefId: text("bank_ref_id").notNull(),
|
|
130
|
+
accountId: text("account_id").references(() => account.id).notNull(),
|
|
131
|
+
connectorKey: text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
|
|
132
|
+
amount: real("amount").notNull(),
|
|
133
|
+
direction: text("direction").$type().notNull(),
|
|
134
|
+
paymentType: text("payment_type").$type().notNull(),
|
|
135
|
+
currency: text("currency").$type().notNull(),
|
|
136
|
+
status: text("status").$type().notNull(),
|
|
137
|
+
statusReason: text("status_reason"),
|
|
138
|
+
batchId: text("bank_execution_batch_id"),
|
|
139
|
+
initiatedAt: integer("initiated_at", {
|
|
140
|
+
mode: "timestamp_ms"
|
|
141
|
+
}),
|
|
142
|
+
vs: text("vs"),
|
|
143
|
+
ss: text("ss"),
|
|
144
|
+
ks: text("ks"),
|
|
145
|
+
message: text("message"),
|
|
146
|
+
processedAt: integer("processed_at", {
|
|
147
|
+
mode: "timestamp_ms"
|
|
148
|
+
}),
|
|
149
|
+
creditor: text("creditor", { mode: "json" }).$type().notNull(),
|
|
150
|
+
creditorIban: text("creditor_iban"),
|
|
151
|
+
debtor: text("debtor", { mode: "json" }).$type().notNull(),
|
|
152
|
+
debtorIban: text("debtor_iban")
|
|
153
|
+
},
|
|
154
|
+
(t) => [unique().on(t.connectorKey, t.bankRefId)]
|
|
155
|
+
);
|
|
156
|
+
const paymentRelations = relations(payment, ({ one }) => ({
|
|
157
|
+
batch: one(batch, { fields: [payment.batchId], references: [batch.id] })
|
|
158
|
+
}));
|
|
159
|
+
|
|
160
|
+
const schema = {
|
|
161
|
+
__proto__: null,
|
|
162
|
+
account: account,
|
|
163
|
+
accountCredentials: accountCredentials,
|
|
164
|
+
batch: batch,
|
|
165
|
+
ott: ott,
|
|
166
|
+
payment: payment,
|
|
167
|
+
paymentRelations: paymentRelations
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export { ACCOUNT_STATUSES as A, BATCH_STATUSES as B, CHARGE_BEARERS as C, INSTRUCTION_PRIORITIES as I, PAYMENT_TYPES as P, TOKEN_TYPES as T, PAYMENT_STATUSES as a, PAYMENT_DIRECTIONS as b, COUNTRY_CODES as c, CONNECTOR_KEYS as d, CREDENTIALS_TYPES as e, accountInsertSchema as f, accountUpdateSchema as g, accountSelectSchema as h, accountCredentialsInsertSchema as i, accountCredentialsUpdateSchema as j, accountCredentialsSelectSchema as k, ottUpdateSchema as l, ottSelectSchema as m, batch as n, ottInsertSchema as o, payment as p, paymentRelations as q, ott as r, schema as s, account as t, accountCredentials as u };
|