@develit-services/bank 2.4.0 → 3.0.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 (38) hide show
  1. package/dist/database/schema.cjs +1 -10
  2. package/dist/database/schema.d.cts +3 -3
  3. package/dist/database/schema.d.mts +3 -3
  4. package/dist/database/schema.d.ts +3 -3
  5. package/dist/database/schema.mjs +1 -8
  6. package/dist/export/worker.cjs +137 -137
  7. package/dist/export/worker.d.cts +113 -449
  8. package/dist/export/worker.d.mts +113 -449
  9. package/dist/export/worker.d.ts +113 -449
  10. package/dist/export/worker.mjs +40 -40
  11. package/dist/export/workflows.cjs +29 -23
  12. package/dist/export/workflows.mjs +18 -12
  13. package/dist/export/wrangler.cjs +3 -11
  14. package/dist/export/wrangler.d.cts +1 -1
  15. package/dist/export/wrangler.d.mts +1 -1
  16. package/dist/export/wrangler.d.ts +1 -1
  17. package/dist/export/wrangler.mjs +3 -11
  18. package/dist/shared/bank.9Yw4KHyl.cjs +275 -0
  19. package/dist/shared/{bank.BI2OxQsM.d.mts → bank.BanqNaZK.d.cts} +9 -9
  20. package/dist/shared/{bank.fZkUcrn9.mjs → bank.ByesVuDp.mjs} +2 -1
  21. package/dist/shared/bank.BzDNLxB_.mjs +254 -0
  22. package/dist/shared/{bank.IlVbIEuM.mjs → bank.CTFqGRuY.mjs} +193 -433
  23. package/dist/shared/{bank.BJ_vbyUT.d.ts → bank.CVCyY-qU.d.cts} +1225 -3788
  24. package/dist/shared/{bank.BJ_vbyUT.d.cts → bank.CVCyY-qU.d.mts} +1225 -3788
  25. package/dist/shared/{bank.BJ_vbyUT.d.mts → bank.CVCyY-qU.d.ts} +1225 -3788
  26. package/dist/shared/{bank.Ca0iWjhb.d.cts → bank.DOlM7clW.d.mts} +9 -9
  27. package/dist/shared/{bank.B0I6H6AT.cjs → bank.OSj3Smwv.cjs} +17 -16
  28. package/dist/shared/{bank.Bs0isbAY.d.ts → bank.SoKDxQxH.d.ts} +9 -9
  29. package/dist/shared/{bank.c1sHv5v_.cjs → bank.pU2vSCUr.cjs} +200 -460
  30. package/dist/types.cjs +38 -38
  31. package/dist/types.d.cts +57 -450
  32. package/dist/types.d.mts +57 -450
  33. package/dist/types.d.ts +57 -450
  34. package/dist/types.mjs +4 -4
  35. package/package.json +6 -5
  36. package/dist/shared/{bank.Bz4DIxJL.d.cts → bank.C6sLje8B.d.cts} +3 -3
  37. package/dist/shared/{bank.Bz4DIxJL.d.mts → bank.C6sLje8B.d.mts} +3 -3
  38. package/dist/shared/{bank.Bz4DIxJL.d.ts → bank.C6sLje8B.d.ts} +3 -3
@@ -1,15 +1,193 @@
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');
6
5
  const jose = require('jose');
7
6
  const zod = require('zod');
8
7
  const generalCodes = require('@develit-io/general-codes');
9
- const relations = require('drizzle-orm/relations');
8
+ const database_schema = require('./bank.9Yw4KHyl.cjs');
10
9
  const drizzleOrm = require('drizzle-orm');
11
- require('node:crypto');
12
10
  const drizzleZod = require('drizzle-zod');
11
+ require('node:crypto');
12
+
13
+ const relations = drizzleOrm.defineRelations(database_schema.schema, (r) => ({
14
+ payment: {
15
+ batch: r.one.batch({
16
+ from: r.payment.batchId,
17
+ to: r.batch.id
18
+ })
19
+ },
20
+ paymentRequest: {
21
+ batch: r.one.batch({
22
+ from: r.paymentRequest.batchId,
23
+ to: r.batch.id
24
+ }),
25
+ account: r.one.account({
26
+ from: r.paymentRequest.accountId,
27
+ to: r.account.id
28
+ })
29
+ }
30
+ }));
31
+
32
+ const tables = database_schema.schema;
33
+
34
+ async function signFinbricksJws({
35
+ privateKeyPem,
36
+ merchantId,
37
+ jwsData
38
+ }) {
39
+ const privateKey = await jose.importPKCS8(privateKeyPem, "RS256");
40
+ const payload = JSON.stringify(jwsData);
41
+ const jws = await new jose.SignJWT(JSON.parse(payload)).setProtectedHeader({
42
+ alg: "RS256",
43
+ kid: merchantId,
44
+ typ: "JWT"
45
+ }).sign(privateKey);
46
+ const [header, , signature] = jws.split(".");
47
+ return `${header}..${signature}`;
48
+ }
49
+
50
+ const useFinbricksFetch = async (config, init) => {
51
+ const {
52
+ baseUrl,
53
+ endpoint,
54
+ method = "GET",
55
+ merchantId,
56
+ privateKeyPem,
57
+ query,
58
+ body,
59
+ correlationId,
60
+ psuIp = "88.205.47.1",
61
+ psuAgent = "Develit/BankService"
62
+ } = config;
63
+ const url = new URL(`${baseUrl}${endpoint}`);
64
+ if (query) {
65
+ for (const [k, v] of Object.entries(query)) {
66
+ if (v !== void 0 && v !== null)
67
+ url.searchParams.append(k, v.toString());
68
+ }
69
+ }
70
+ const uriWithQuery = `${endpoint}${url.search ? `?${url.searchParams.toString()}` : ""}`;
71
+ const bodyString = body ? JSON.stringify(body) : "";
72
+ const jwsSignature = await signFinbricksJws({
73
+ privateKeyPem,
74
+ merchantId,
75
+ jwsData: {
76
+ uri: uriWithQuery,
77
+ body: bodyString
78
+ }
79
+ });
80
+ const headers = {
81
+ "Content-Type": "application/json",
82
+ "JWS-Signature": jwsSignature,
83
+ "PSU-IP-Address": psuIp,
84
+ "PSU-User-Agent": psuAgent,
85
+ ...init?.headers
86
+ };
87
+ if (correlationId) {
88
+ headers["Correlation-ID"] = correlationId;
89
+ }
90
+ console.log(
91
+ "[Finbricks] request",
92
+ JSON.stringify(
93
+ {
94
+ method,
95
+ url: url.toString(),
96
+ body: body ?? null
97
+ },
98
+ null,
99
+ 2
100
+ )
101
+ );
102
+ const res = await fetch(url.toString(), {
103
+ method,
104
+ headers,
105
+ body: method !== "GET" ? bodyString : void 0
106
+ });
107
+ if (!res.ok) {
108
+ const text = await res.text().catch(() => "unknown error");
109
+ console.error("[Finbricks] error response", {
110
+ status: res.status,
111
+ statusText: res.statusText,
112
+ url: url.toString(),
113
+ body: text
114
+ });
115
+ throw new Error(
116
+ `Finbricks API error: ${res.status} ${res.statusText} \u2013 ${text}`
117
+ );
118
+ }
119
+ const json = await res.json();
120
+ console.log(
121
+ "[Finbricks] response",
122
+ JSON.stringify(
123
+ {
124
+ status: res.status,
125
+ url: url.toString(),
126
+ body: json
127
+ },
128
+ null,
129
+ 2
130
+ )
131
+ );
132
+ return json;
133
+ };
134
+ class FinbricksClient {
135
+ constructor(baseUrl, merchantId, privateKeyPem, redirectUri) {
136
+ this.BASE_URL = baseUrl;
137
+ this.MERCHANT_ID = merchantId;
138
+ this.PRIVATE_KEY_PEM = privateKeyPem;
139
+ this.REDIRECT_URI = redirectUri;
140
+ }
141
+ async request(params) {
142
+ return useFinbricksFetch({
143
+ baseUrl: this.BASE_URL,
144
+ merchantId: this.MERCHANT_ID,
145
+ privateKeyPem: this.PRIVATE_KEY_PEM,
146
+ ...params
147
+ });
148
+ }
149
+ }
150
+
151
+ const FINBRICKS_ENDPOINTS = {
152
+ AUTHENTICATE_V2: "/v2/auth/authenticate",
153
+ AUTH_TOKEN_STATUS: "/auth/token",
154
+ AUTH_TOKEN_REVOKE: "/auth/revoke",
155
+ ACCOUNT_LIST: "/account/list",
156
+ ACCOUNT_BALANCE: "/account/balance",
157
+ ACCOUNT_TRANSACTIONS: "/account/transactions",
158
+ TRANSACTION_INIT: "/transaction/platform/init",
159
+ TRANSACTION_STATUS: "/transaction/platform/status",
160
+ TRANSACTION_SEPA_INIT: "/transaction/platform/sepa/init",
161
+ TRANSACTION_FOREIGN_INIT: "/transaction/platform/foreign/init",
162
+ TRANSACTION_BATCH_INIT: "/transaction/platform/batchPayment/init",
163
+ BATCH_STATUS: "/transaction/platform/batchPayment/status",
164
+ BANK_INFO: "/status/bankInfo"
165
+ };
166
+
167
+ const TERMINAL_STATUSES$1 = /* @__PURE__ */ new Set([
168
+ "SETTLED",
169
+ "REJECTED",
170
+ "CLOSED"
171
+ ]);
172
+ const PENDING_STATUSES = /* @__PURE__ */ new Set([
173
+ "OPENED",
174
+ "AUTHORIZED"
175
+ ]);
176
+ function isTerminalStatus(status) {
177
+ return TERMINAL_STATUSES$1.has(status);
178
+ }
179
+ function isPendingStatus(status) {
180
+ return PENDING_STATUSES.has(status);
181
+ }
182
+ function isProcessedStatus(status) {
183
+ return !isPendingStatus(status);
184
+ }
185
+ function hasPaymentAccountAssigned(payment) {
186
+ return "accountId" in payment && "connectorKey" in payment && payment.accountId !== void 0 && payment.connectorKey !== void 0;
187
+ }
188
+ function isPaymentCompleted(payment) {
189
+ return (payment.status === "COMPLETED" || payment.status === "BOOKED" || payment.status === "SETTLED" || payment.status === "REJECTED" || payment.status === "CLOSED") && "bankRefId" in payment && typeof payment.bankRefId === "string";
190
+ }
13
191
 
14
192
  function toIncomingPayment(input) {
15
193
  return {
@@ -241,139 +419,6 @@ class IBankConnector {
241
419
  }
242
420
  }
243
421
 
244
- async function signFinbricksJws({
245
- privateKeyPem,
246
- merchantId,
247
- jwsData
248
- }) {
249
- const privateKey = await jose.importPKCS8(privateKeyPem, "RS256");
250
- const payload = JSON.stringify(jwsData);
251
- const jws = await new jose.SignJWT(JSON.parse(payload)).setProtectedHeader({
252
- alg: "RS256",
253
- kid: merchantId,
254
- typ: "JWT"
255
- }).sign(privateKey);
256
- const [header, , signature] = jws.split(".");
257
- return `${header}..${signature}`;
258
- }
259
-
260
- const useFinbricksFetch = async (config, init) => {
261
- const {
262
- baseUrl,
263
- endpoint,
264
- method = "GET",
265
- merchantId,
266
- privateKeyPem,
267
- query,
268
- body,
269
- correlationId,
270
- psuIp = "88.205.47.1",
271
- psuAgent = "Develit/BankService"
272
- } = config;
273
- const url = new URL(`${baseUrl}${endpoint}`);
274
- if (query) {
275
- for (const [k, v] of Object.entries(query)) {
276
- if (v !== void 0 && v !== null)
277
- url.searchParams.append(k, v.toString());
278
- }
279
- }
280
- const uriWithQuery = `${endpoint}${url.search ? `?${url.searchParams.toString()}` : ""}`;
281
- const bodyString = body ? JSON.stringify(body) : "";
282
- const jwsSignature = await signFinbricksJws({
283
- privateKeyPem,
284
- merchantId,
285
- jwsData: {
286
- uri: uriWithQuery,
287
- body: bodyString
288
- }
289
- });
290
- const headers = {
291
- "Content-Type": "application/json",
292
- "JWS-Signature": jwsSignature,
293
- "PSU-IP-Address": psuIp,
294
- "PSU-User-Agent": psuAgent,
295
- ...init?.headers
296
- };
297
- if (correlationId) {
298
- headers["Correlation-ID"] = correlationId;
299
- }
300
- console.log(
301
- "[Finbricks] request",
302
- JSON.stringify(
303
- {
304
- method,
305
- url: url.toString(),
306
- body: body ?? null
307
- },
308
- null,
309
- 2
310
- )
311
- );
312
- const res = await fetch(url.toString(), {
313
- method,
314
- headers,
315
- body: method !== "GET" ? bodyString : void 0
316
- });
317
- if (!res.ok) {
318
- const text = await res.text().catch(() => "unknown error");
319
- console.error("[Finbricks] error response", {
320
- status: res.status,
321
- statusText: res.statusText,
322
- url: url.toString(),
323
- body: text
324
- });
325
- throw new Error(
326
- `Finbricks API error: ${res.status} ${res.statusText} \u2013 ${text}`
327
- );
328
- }
329
- const json = await res.json();
330
- console.log(
331
- "[Finbricks] response",
332
- JSON.stringify(
333
- {
334
- status: res.status,
335
- url: url.toString(),
336
- body: json
337
- },
338
- null,
339
- 2
340
- )
341
- );
342
- return json;
343
- };
344
- class FinbricksClient {
345
- constructor(baseUrl, merchantId, privateKeyPem, redirectUri) {
346
- this.BASE_URL = baseUrl;
347
- this.MERCHANT_ID = merchantId;
348
- this.PRIVATE_KEY_PEM = privateKeyPem;
349
- this.REDIRECT_URI = redirectUri;
350
- }
351
- async request(params) {
352
- return useFinbricksFetch({
353
- baseUrl: this.BASE_URL,
354
- merchantId: this.MERCHANT_ID,
355
- privateKeyPem: this.PRIVATE_KEY_PEM,
356
- ...params
357
- });
358
- }
359
- }
360
-
361
- const FINBRICKS_ENDPOINTS = {
362
- AUTHENTICATE_V2: "/v2/auth/authenticate",
363
- AUTH_TOKEN_STATUS: "/auth/token",
364
- AUTH_TOKEN_REVOKE: "/auth/revoke",
365
- ACCOUNT_LIST: "/account/list",
366
- ACCOUNT_BALANCE: "/account/balance",
367
- ACCOUNT_TRANSACTIONS: "/account/transactions",
368
- TRANSACTION_INIT: "/transaction/platform/init",
369
- TRANSACTION_STATUS: "/transaction/platform/status",
370
- TRANSACTION_SEPA_INIT: "/transaction/platform/sepa/init",
371
- TRANSACTION_FOREIGN_INIT: "/transaction/platform/foreign/init",
372
- TRANSACTION_BATCH_INIT: "/transaction/platform/batchPayment/init",
373
- BATCH_STATUS: "/transaction/platform/batchPayment/status",
374
- BANK_INFO: "/status/bankInfo"
375
- };
376
-
377
422
  const mapFinbricksStatus = (status, hasBookingDate) => {
378
423
  switch (status) {
379
424
  case "BOOK":
@@ -918,7 +963,10 @@ class FinbricksConnector extends IBankConnector {
918
963
  },
919
964
  paymentIdentification: {
920
965
  merchantTransactionId: bankRefId,
921
- endToEndIdentification: this.buildEndToEndId(payment)
966
+ endToEndIdentification: this.buildEndToEndId({
967
+ ...payment,
968
+ id: payment.id
969
+ })
922
970
  },
923
971
  amount: payment.amount,
924
972
  debtor: {
@@ -1100,40 +1148,6 @@ class CsobConnector extends FinbricksConnector {
1100
1148
  }
1101
1149
  }
1102
1150
 
1103
- const PAYMENT_TYPES = ["SEPA", "SWIFT", "DOMESTIC", "UNKNOWN"];
1104
- const CHARGE_BEARERS = ["SHA", "OUR", "BEN"];
1105
- const INSTRUCTION_PRIORITIES = ["NORM", "HIGH", "INST"];
1106
- const PAYMENT_REQUEST_STATUSES = [
1107
- "OPENED",
1108
- "AUTHORIZED",
1109
- "COMPLETED",
1110
- "BOOKED",
1111
- "SETTLED",
1112
- "REJECTED",
1113
- "CLOSED"
1114
- ];
1115
- const PAYMENT_STATUSES = [
1116
- "PENDING",
1117
- "PROCESSING",
1118
- "BOOKED",
1119
- "CANCELLED",
1120
- "REJECTED",
1121
- "SCHEDULED",
1122
- "HOLD",
1123
- "INFO"
1124
- ];
1125
- const PAYMENT_DIRECTIONS = ["INCOMING", "OUTGOING"];
1126
- const BATCH_STATUSES = [
1127
- "PROCESSING",
1128
- "READY_TO_SIGN",
1129
- "AUTHORIZED",
1130
- "COMPLETED",
1131
- "FAILED"
1132
- ];
1133
- const BATCH_MODES = ["NATIVE", "SINGLE"];
1134
- const ACCOUNT_STATUSES = ["AUTHORIZED", "DISABLED", "EXPIRED"];
1135
- const COUNTRY_CODES = generalCodes.COUNTRY_CODES_2;
1136
-
1137
1151
  class AirBankConnector extends FinbricksConnector {
1138
1152
  constructor(config) {
1139
1153
  super("AIRBANK", config);
@@ -1968,32 +1982,7 @@ class DbuConnector extends IBankConnector {
1968
1982
  }
1969
1983
  }
1970
1984
 
1971
- const TERMINAL_STATUSES$1 = /* @__PURE__ */ new Set([
1972
- "SETTLED",
1973
- "REJECTED",
1974
- "CLOSED"
1975
- ]);
1976
- const PENDING_STATUSES = /* @__PURE__ */ new Set([
1977
- "OPENED",
1978
- "AUTHORIZED"
1979
- ]);
1980
- function isTerminalStatus(status) {
1981
- return TERMINAL_STATUSES$1.has(status);
1982
- }
1983
- function isPendingStatus(status) {
1984
- return PENDING_STATUSES.has(status);
1985
- }
1986
- function isProcessedStatus(status) {
1987
- return !isPendingStatus(status);
1988
- }
1989
- function hasPaymentAccountAssigned(payment) {
1990
- return "accountId" in payment && "connectorKey" in payment && payment.accountId !== void 0 && payment.connectorKey !== void 0;
1991
- }
1992
- function isPaymentCompleted(payment) {
1993
- return (payment.status === "COMPLETED" || payment.status === "BOOKED" || payment.status === "SETTLED" || payment.status === "REJECTED" || payment.status === "CLOSED") && "bankRefId" in payment && typeof payment.bankRefId === "string";
1994
- }
1995
-
1996
- const TERMINAL_STATUSES = PAYMENT_REQUEST_STATUSES.filter(isTerminalStatus);
1985
+ const TERMINAL_STATUSES = database_schema.PAYMENT_REQUEST_STATUSES.filter(isTerminalStatus);
1997
1986
  const getNonTerminalPaymentRequestsQuery = (db) => db.select().from(tables.paymentRequest).where(
1998
1987
  drizzleOrm.and(
1999
1988
  drizzleOrm.not(drizzleOrm.inArray(tables.paymentRequest.status, TERMINAL_STATUSES)),
@@ -2110,7 +2099,10 @@ class ErsteConnector extends IBankConnector {
2110
2099
  }
2111
2100
  const paymentBody = {
2112
2101
  paymentIdentification: {
2113
- endToEndIdentification: this.buildEndToEndId(payment),
2102
+ endToEndIdentification: this.buildEndToEndId({
2103
+ ...payment,
2104
+ id: payment.id
2105
+ }),
2114
2106
  instructionIdentification: payment.id
2115
2107
  },
2116
2108
  paymentTypeInformation: { instructionPriority: "NORM" },
@@ -2415,263 +2407,24 @@ class MockConnector extends IBankConnector {
2415
2407
  }
2416
2408
  }
2417
2409
 
2418
- const CONNECTOR_KEYS = [
2419
- "ERSTE",
2420
- "FINBRICKS",
2421
- "MOCK",
2422
- "CREDITAS",
2423
- "MOCK_COBS",
2424
- "FIO",
2425
- "MONETA",
2426
- "DBU",
2427
- "CSAS",
2428
- "AIRBANK",
2429
- "KB",
2430
- "CSOB"
2431
- ];
2432
- const CREDENTIALS_TYPES = [
2433
- "AUTH_TOKEN",
2434
- "REFRESH_TOKEN",
2435
- "CLIENT_ID",
2436
- "API_KEY"
2437
- ];
2438
- const TOKEN_TYPES = ["ACCOUNT_AUTHORIZATION"];
2439
-
2440
- const account = sqliteCore.sqliteTable(
2441
- "account",
2442
- {
2443
- ...backendSdk.base,
2444
- ...backendSdk.bankAccount,
2445
- // countryCode is temporary until bankAccount is update to include US country code
2446
- countryCode: sqliteCore.text("country_code", { enum: COUNTRY_CODES }).$type().notNull(),
2447
- number: sqliteCore.text("number").notNull(),
2448
- name: sqliteCore.text("name"),
2449
- iban: sqliteCore.text("iban").notNull(),
2450
- bankCode: sqliteCore.text("bank_code", { enum: generalCodes.BANK_CODES }).notNull(),
2451
- connectorKey: sqliteCore.text("connector_key", {
2452
- enum: CONNECTOR_KEYS
2453
- }).$type().notNull(),
2454
- status: sqliteCore.text("status", { enum: ACCOUNT_STATUSES }).$type().notNull(),
2455
- bankRefId: sqliteCore.text("bank_ref_id").notNull(),
2456
- batchSizeLimit: sqliteCore.integer("batch_size_limit").notNull().default(50),
2457
- syncIntervalS: sqliteCore.integer("sync_interval_s").notNull().default(600),
2458
- lastSyncAt: sqliteCore.integer("last_sync_at", { mode: "timestamp_ms" }),
2459
- lastSyncMetadata: sqliteCore.text("last_sync_metadata", {
2460
- mode: "json"
2461
- }).$type(),
2462
- connectorConfig: sqliteCore.text("connector_config", {
2463
- mode: "json"
2464
- }).$type()
2465
- },
2466
- (t) => [sqliteCore.unique().on(t.iban)]
2467
- );
2468
-
2469
- const accountInsertSchema = drizzleZod.createInsertSchema(account, {
2410
+ const accountInsertSchema = drizzleZod.createInsertSchema(database_schema.account, {
2470
2411
  address: () => backendSdk.structuredAddressSchema.optional()
2471
2412
  });
2472
- const accountUpdateSchema = drizzleZod.createUpdateSchema(account, {
2413
+ const accountUpdateSchema = drizzleZod.createUpdateSchema(database_schema.account, {
2473
2414
  address: () => backendSdk.structuredAddressSchema.optional()
2474
2415
  });
2475
- const accountSelectSchema = drizzleZod.createSelectSchema(account, {
2416
+ const accountSelectSchema = drizzleZod.createSelectSchema(database_schema.account, {
2476
2417
  address: () => backendSdk.structuredAddressSchema.nullable()
2477
2418
  });
2478
2419
 
2479
- const accountCredentials = sqliteCore.sqliteTable("account_credentials", {
2480
- ...backendSdk.base,
2481
- accountId: sqliteCore.text("account_id").references(() => account.id, { onDelete: "restrict", onUpdate: "cascade" }).notNull(),
2482
- connectorKey: sqliteCore.text("connector_key", {
2483
- enum: CONNECTOR_KEYS
2484
- }).$type().notNull(),
2485
- type: sqliteCore.text("type", {
2486
- enum: CREDENTIALS_TYPES
2487
- }).$type().notNull(),
2488
- value: sqliteCore.text("value").notNull(),
2489
- expiresAt: sqliteCore.integer("expires_at", { mode: "timestamp_ms" }).notNull()
2490
- });
2491
-
2492
- const accountCredentialsInsertSchema = drizzleZod.createInsertSchema(accountCredentials);
2493
- const accountCredentialsUpdateSchema = drizzleZod.createUpdateSchema(accountCredentials);
2494
- const accountCredentialsSelectSchema = drizzleZod.createSelectSchema(accountCredentials);
2495
-
2496
- const ott = sqliteCore.sqliteTable("ott", {
2497
- ...backendSdk.base,
2498
- oneTimeToken: sqliteCore.text("one_time_token").notNull(),
2499
- refId: sqliteCore.text("ref_id").notNull(),
2500
- tokenType: sqliteCore.text("token_type", { enum: TOKEN_TYPES }).$type().notNull(),
2501
- expiresAt: sqliteCore.integer("expires_at", { mode: "timestamp_ms" }).notNull()
2502
- });
2503
-
2504
- const ottInsertSchema = drizzleZod.createInsertSchema(ott);
2505
- const ottUpdateSchema = drizzleZod.createUpdateSchema(ott);
2506
- const ottSelectSchema = drizzleZod.createSelectSchema(ott);
2507
-
2508
- const batch = sqliteCore.sqliteTable("batch", {
2509
- ...backendSdk.base,
2510
- batchPaymentInitiatedAt: sqliteCore.integer("batch_payment_initiated_at", {
2511
- mode: "timestamp_ms"
2512
- }),
2513
- authorizationUrls: sqliteCore.text("authorization_urls", { mode: "json" }).$type(),
2514
- accountId: sqliteCore.text("account_id").references(() => account.id, {
2515
- onDelete: "restrict",
2516
- onUpdate: "cascade"
2517
- }),
2518
- status: sqliteCore.text("status", { enum: BATCH_STATUSES }).$type(),
2519
- statusReason: sqliteCore.text("status_reason"),
2520
- statusResponse: sqliteCore.text("status_response", { mode: "json" }).$type(),
2521
- metadata: sqliteCore.text("metadata", { mode: "json" }).$type(),
2522
- paymentType: sqliteCore.text("payment_type", {
2523
- enum: PAYMENT_TYPES
2524
- }).$type(),
2525
- paymentsChecksum: sqliteCore.text("payments_checksum"),
2526
- batchMode: sqliteCore.text("batch_mode", { enum: BATCH_MODES }).$type()
2527
- });
2528
-
2529
- const payment = sqliteCore.sqliteTable(
2530
- "payment",
2531
- {
2532
- ...backendSdk.base,
2533
- correlationId: sqliteCore.text("correlation_id").notNull(),
2534
- refId: sqliteCore.text("ref_id"),
2535
- bankRefId: sqliteCore.text("bank_ref_id").notNull(),
2536
- accountId: sqliteCore.text("account_id").references(() => account.id, {
2537
- onDelete: "restrict",
2538
- onUpdate: "cascade"
2539
- }).notNull(),
2540
- connectorKey: sqliteCore.text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
2541
- amount: sqliteCore.real("amount").notNull(),
2542
- direction: sqliteCore.text("direction").$type().notNull(),
2543
- paymentType: sqliteCore.text("payment_type").$type().notNull(),
2544
- currency: sqliteCore.text("currency").$type().notNull(),
2545
- status: sqliteCore.text("status", { enum: PAYMENT_STATUSES }).$type().notNull(),
2546
- statusReason: sqliteCore.text("status_reason"),
2547
- batchId: sqliteCore.text("bank_execution_batch_id"),
2548
- initiatedAt: sqliteCore.integer("initiated_at", {
2549
- mode: "timestamp_ms"
2550
- }),
2551
- vs: sqliteCore.text("vs"),
2552
- ss: sqliteCore.text("ss"),
2553
- ks: sqliteCore.text("ks"),
2554
- message: sqliteCore.text("message"),
2555
- chargeBearer: sqliteCore.text("charge_bearer", {
2556
- enum: CHARGE_BEARERS
2557
- }).$type(),
2558
- instructionPriority: sqliteCore.text("instruction_priority", {
2559
- enum: INSTRUCTION_PRIORITIES
2560
- }).$type(),
2561
- processedAt: sqliteCore.integer("processed_at", {
2562
- mode: "timestamp_ms"
2563
- }),
2564
- creditor: sqliteCore.text("creditor", { mode: "json" }).$type().notNull(),
2565
- creditorIban: sqliteCore.text("creditor_iban"),
2566
- debtor: sqliteCore.text("debtor", { mode: "json" }).$type().notNull(),
2567
- debtorIban: sqliteCore.text("debtor_iban")
2568
- },
2569
- (t) => [
2570
- sqliteCore.unique().on(t.connectorKey, t.accountId, t.bankRefId),
2571
- sqliteCore.index("payment_account_id_idx").on(t.accountId),
2572
- sqliteCore.index("payment_account_id_status_idx").on(t.accountId, t.status),
2573
- sqliteCore.index("payment_account_id_created_at_idx").on(t.accountId, t.createdAt),
2574
- sqliteCore.index("payment_created_at_idx").on(t.createdAt),
2575
- sqliteCore.index("payment_direction_idx").on(t.direction),
2576
- sqliteCore.index("payment_batch_id_idx").on(t.batchId),
2577
- sqliteCore.index("payment_creditor_iban_idx").on(t.creditorIban),
2578
- sqliteCore.index("payment_debtor_iban_idx").on(t.debtorIban)
2579
- ]
2580
- );
2581
- const paymentRelations = relations.relations(payment, ({ one }) => ({
2582
- batch: one(batch, { fields: [payment.batchId], references: [batch.id] })
2583
- }));
2584
-
2585
- const paymentRequest = sqliteCore.sqliteTable(
2586
- "payment_request",
2587
- {
2588
- ...backendSdk.base,
2589
- batchId: sqliteCore.text("batch_id").references(() => batch.id, {
2590
- onDelete: "restrict",
2591
- onUpdate: "cascade"
2592
- }),
2593
- accountId: sqliteCore.text("account_id").references(() => account.id, {
2594
- onDelete: "restrict",
2595
- onUpdate: "cascade"
2596
- }).notNull(),
2597
- correlationId: sqliteCore.text("correlation_id").notNull(),
2598
- refId: sqliteCore.text("ref_id"),
2599
- bankRefId: sqliteCore.text("bank_ref_id"),
2600
- connectorKey: sqliteCore.text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
2601
- amount: sqliteCore.real("amount").notNull(),
2602
- paymentType: sqliteCore.text("payment_type", { enum: PAYMENT_TYPES }).$type().notNull(),
2603
- currency: sqliteCore.text("currency").$type().notNull(),
2604
- status: sqliteCore.text("status", { enum: PAYMENT_REQUEST_STATUSES }).$type().notNull(),
2605
- statusReason: sqliteCore.text("status_reason"),
2606
- authorizationUrl: sqliteCore.text("authorization_url"),
2607
- initiatedAt: sqliteCore.integer("initiated_at", { mode: "timestamp_ms" }),
2608
- processedAt: sqliteCore.integer("processed_at", { mode: "timestamp_ms" }),
2609
- vs: sqliteCore.text("vs"),
2610
- ss: sqliteCore.text("ss"),
2611
- ks: sqliteCore.text("ks"),
2612
- message: sqliteCore.text("message"),
2613
- chargeBearer: sqliteCore.text("charge_bearer", {
2614
- enum: CHARGE_BEARERS
2615
- }).$type(),
2616
- instructionPriority: sqliteCore.text("instruction_priority", {
2617
- enum: INSTRUCTION_PRIORITIES
2618
- }).$type(),
2619
- creditor: sqliteCore.text("creditor", { mode: "json" }).$type().notNull(),
2620
- creditorIban: sqliteCore.text("creditor_iban"),
2621
- debtor: sqliteCore.text("debtor", { mode: "json" }).$type().notNull(),
2622
- debtorIban: sqliteCore.text("debtor_iban"),
2623
- sendAsSinglePayment: sqliteCore.integer("send_as_single_payment", {
2624
- mode: "boolean"
2625
- })
2626
- },
2627
- (t) => [
2628
- sqliteCore.index("payment_request_batch_id_idx").on(t.batchId),
2629
- sqliteCore.index("payment_request_account_id_idx").on(t.accountId),
2630
- sqliteCore.index("payment_request_creditor_iban_idx").on(t.creditorIban),
2631
- sqliteCore.index("payment_request_debtor_iban_idx").on(t.debtorIban),
2632
- sqliteCore.index("payment_request_status_idx").on(t.status),
2633
- sqliteCore.index("payment_request_created_at_idx").on(t.createdAt),
2634
- sqliteCore.index("payment_request_account_status_idx").on(t.accountId, t.status),
2635
- sqliteCore.index("payment_request_status_created_at_idx").on(t.status, t.createdAt),
2636
- sqliteCore.index("payment_request_account_status_created_at_idx").on(
2637
- t.accountId,
2638
- t.status,
2639
- t.createdAt
2640
- )
2641
- ]
2642
- );
2643
- const paymentRequestRelations = relations.relations(paymentRequest, ({ one }) => ({
2644
- batch: one(batch, {
2645
- fields: [paymentRequest.batchId],
2646
- references: [batch.id]
2647
- }),
2648
- account: one(account, {
2649
- fields: [paymentRequest.accountId],
2650
- references: [account.id]
2651
- })
2652
- }));
2653
-
2654
- const schema = {
2655
- __proto__: null,
2656
- account: account,
2657
- accountCredentials: accountCredentials,
2658
- batch: batch,
2659
- ott: ott,
2660
- payment: payment,
2661
- paymentRelations: paymentRelations,
2662
- paymentRequest: paymentRequest,
2663
- paymentRequestRelations: paymentRequestRelations
2664
- };
2420
+ const accountCredentialsInsertSchema = drizzleZod.createInsertSchema(database_schema.accountCredentials);
2421
+ const accountCredentialsUpdateSchema = drizzleZod.createUpdateSchema(database_schema.accountCredentials);
2422
+ const accountCredentialsSelectSchema = drizzleZod.createSelectSchema(database_schema.accountCredentials);
2665
2423
 
2666
- const tables = schema;
2424
+ const ottInsertSchema = drizzleZod.createInsertSchema(database_schema.ott);
2425
+ const ottUpdateSchema = drizzleZod.createUpdateSchema(database_schema.ott);
2426
+ const ottSelectSchema = drizzleZod.createSelectSchema(database_schema.ott);
2667
2427
 
2668
- exports.ACCOUNT_STATUSES = ACCOUNT_STATUSES;
2669
- exports.BATCH_MODES = BATCH_MODES;
2670
- exports.BATCH_STATUSES = BATCH_STATUSES;
2671
- exports.CHARGE_BEARERS = CHARGE_BEARERS;
2672
- exports.CONNECTOR_KEYS = CONNECTOR_KEYS;
2673
- exports.COUNTRY_CODES = COUNTRY_CODES;
2674
- exports.CREDENTIALS_TYPES = CREDENTIALS_TYPES;
2675
2428
  exports.CsobConnector = CsobConnector;
2676
2429
  exports.DbuConnector = DbuConnector;
2677
2430
  exports.ErsteConnector = ErsteConnector;
@@ -2679,17 +2432,9 @@ exports.FINBRICKS_ENDPOINTS = FINBRICKS_ENDPOINTS;
2679
2432
  exports.FinbricksClient = FinbricksClient;
2680
2433
  exports.FinbricksConnector = FinbricksConnector;
2681
2434
  exports.IBankConnector = IBankConnector;
2682
- exports.INSTRUCTION_PRIORITIES = INSTRUCTION_PRIORITIES;
2683
2435
  exports.KBConnector = KBConnector;
2684
2436
  exports.MockCobsConnector = MockCobsConnector;
2685
2437
  exports.MockConnector = MockConnector;
2686
- exports.PAYMENT_DIRECTIONS = PAYMENT_DIRECTIONS;
2687
- exports.PAYMENT_REQUEST_STATUSES = PAYMENT_REQUEST_STATUSES;
2688
- exports.PAYMENT_STATUSES = PAYMENT_STATUSES;
2689
- exports.PAYMENT_TYPES = PAYMENT_TYPES;
2690
- exports.TOKEN_TYPES = TOKEN_TYPES;
2691
- exports.account = account;
2692
- exports.accountCredentials = accountCredentials;
2693
2438
  exports.accountCredentialsInsertSchema = accountCredentialsInsertSchema;
2694
2439
  exports.accountCredentialsSelectSchema = accountCredentialsSelectSchema;
2695
2440
  exports.accountCredentialsUpdateSchema = accountCredentialsUpdateSchema;
@@ -2697,7 +2442,6 @@ exports.accountInsertSchema = accountInsertSchema;
2697
2442
  exports.accountSelectSchema = accountSelectSchema;
2698
2443
  exports.accountUpdateSchema = accountUpdateSchema;
2699
2444
  exports.assignAccount = assignAccount;
2700
- exports.batch = batch;
2701
2445
  exports.dbuAccountConfigSchema = dbuAccountConfigSchema;
2702
2446
  exports.getNonTerminalPaymentRequestsQuery = getNonTerminalPaymentRequestsQuery;
2703
2447
  exports.hasPaymentAccountAssigned = hasPaymentAccountAssigned;
@@ -2706,14 +2450,10 @@ exports.isPaymentCompleted = isPaymentCompleted;
2706
2450
  exports.isPendingStatus = isPendingStatus;
2707
2451
  exports.isProcessedStatus = isProcessedStatus;
2708
2452
  exports.isTerminalStatus = isTerminalStatus;
2709
- exports.ott = ott;
2710
2453
  exports.ottInsertSchema = ottInsertSchema;
2711
2454
  exports.ottSelectSchema = ottSelectSchema;
2712
2455
  exports.ottUpdateSchema = ottUpdateSchema;
2713
- exports.payment = payment;
2714
- exports.paymentRelations = paymentRelations;
2715
- exports.paymentRequest = paymentRequest;
2716
- exports.paymentRequestRelations = paymentRequestRelations;
2456
+ exports.relations = relations;
2717
2457
  exports.signFinbricksJws = signFinbricksJws;
2718
2458
  exports.tables = tables;
2719
2459
  exports.toBatchedPayment = toBatchedPayment;