@develit-services/bank 2.3.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 +115 -451
  8. package/dist/export/worker.d.mts +115 -451
  9. package/dist/export/worker.d.ts +115 -451
  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 +7 -12
  14. package/dist/export/wrangler.d.cts +11 -3
  15. package/dist/export/wrangler.d.mts +11 -3
  16. package/dist/export/wrangler.d.ts +11 -3
  17. package/dist/export/wrangler.mjs +7 -12
  18. package/dist/shared/bank.9Yw4KHyl.cjs +275 -0
  19. package/dist/shared/{bank.CxAHQOwW.d.cts → bank.BanqNaZK.d.cts} +9 -9
  20. package/dist/shared/{bank.BSiA1m0B.mjs → bank.ByesVuDp.mjs} +2 -1
  21. package/dist/shared/bank.BzDNLxB_.mjs +254 -0
  22. package/dist/shared/{bank.gVOunsjq.mjs → bank.CTFqGRuY.mjs} +227 -447
  23. package/dist/shared/{bank.CC4p6Jf-.d.cts → bank.CVCyY-qU.d.cts} +1225 -3788
  24. package/dist/shared/{bank.CC4p6Jf-.d.mts → bank.CVCyY-qU.d.mts} +1225 -3788
  25. package/dist/shared/{bank.CC4p6Jf-.d.ts → bank.CVCyY-qU.d.ts} +1225 -3788
  26. package/dist/shared/{bank.Dl3mNNS2.d.mts → bank.DOlM7clW.d.mts} +9 -9
  27. package/dist/shared/{bank.DICdNw3T.cjs → bank.OSj3Smwv.cjs} +17 -16
  28. package/dist/shared/{bank.C5NCnZWS.d.ts → bank.SoKDxQxH.d.ts} +9 -9
  29. package/dist/shared/{bank.avgw-IRO.cjs → bank.pU2vSCUr.cjs} +234 -474
  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
@@ -0,0 +1,275 @@
1
+ 'use strict';
2
+
3
+ const backendSdk = require('@develit-io/backend-sdk');
4
+ const sqliteCore = require('drizzle-orm/sqlite-core');
5
+ const generalCodes = require('@develit-io/general-codes');
6
+
7
+ const PAYMENT_TYPES = ["SEPA", "SWIFT", "DOMESTIC", "UNKNOWN"];
8
+ const CHARGE_BEARERS = ["SHA", "OUR", "BEN"];
9
+ const INSTRUCTION_PRIORITIES = ["NORM", "HIGH", "INST"];
10
+ const PAYMENT_REQUEST_STATUSES = [
11
+ "OPENED",
12
+ "AUTHORIZED",
13
+ "COMPLETED",
14
+ "BOOKED",
15
+ "SETTLED",
16
+ "REJECTED",
17
+ "CLOSED"
18
+ ];
19
+ const PAYMENT_STATUSES = [
20
+ "PENDING",
21
+ "PROCESSING",
22
+ "BOOKED",
23
+ "CANCELLED",
24
+ "REJECTED",
25
+ "SCHEDULED",
26
+ "HOLD",
27
+ "INFO"
28
+ ];
29
+ const PAYMENT_DIRECTIONS = ["INCOMING", "OUTGOING"];
30
+ const BATCH_STATUSES = [
31
+ "PROCESSING",
32
+ "READY_TO_SIGN",
33
+ "AUTHORIZED",
34
+ "COMPLETED",
35
+ "FAILED"
36
+ ];
37
+ const BATCH_MODES = ["NATIVE", "SINGLE"];
38
+ const ACCOUNT_STATUSES = ["AUTHORIZED", "DISABLED", "EXPIRED"];
39
+ const COUNTRY_CODES = generalCodes.COUNTRY_CODES_2;
40
+
41
+ const CONNECTOR_KEYS = [
42
+ "ERSTE",
43
+ "FINBRICKS",
44
+ "MOCK",
45
+ "CREDITAS",
46
+ "MOCK_COBS",
47
+ "FIO",
48
+ "MONETA",
49
+ "DBU",
50
+ "CSAS",
51
+ "AIRBANK",
52
+ "KB",
53
+ "CSOB"
54
+ ];
55
+ const CREDENTIALS_TYPES = [
56
+ "AUTH_TOKEN",
57
+ "REFRESH_TOKEN",
58
+ "CLIENT_ID",
59
+ "API_KEY"
60
+ ];
61
+ const TOKEN_TYPES = ["ACCOUNT_AUTHORIZATION"];
62
+
63
+ const account = sqliteCore.sqliteTable(
64
+ "account",
65
+ {
66
+ ...backendSdk.base,
67
+ ...backendSdk.bankAccount,
68
+ // countryCode is temporary until bankAccount is update to include US country code
69
+ countryCode: sqliteCore.text("country_code", { enum: COUNTRY_CODES }).$type().notNull(),
70
+ number: sqliteCore.text("number").notNull(),
71
+ name: sqliteCore.text("name"),
72
+ iban: sqliteCore.text("iban").notNull(),
73
+ bankCode: sqliteCore.text("bank_code", { enum: generalCodes.BANK_CODES }).notNull(),
74
+ connectorKey: sqliteCore.text("connector_key", {
75
+ enum: CONNECTOR_KEYS
76
+ }).$type().notNull(),
77
+ status: sqliteCore.text("status", { enum: ACCOUNT_STATUSES }).$type().notNull(),
78
+ bankRefId: sqliteCore.text("bank_ref_id").notNull(),
79
+ batchSizeLimit: sqliteCore.integer("batch_size_limit").notNull().default(50),
80
+ syncIntervalS: sqliteCore.integer("sync_interval_s").notNull().default(600),
81
+ lastSyncAt: sqliteCore.integer("last_sync_at", { mode: "timestamp_ms" }),
82
+ lastSyncMetadata: sqliteCore.text("last_sync_metadata", {
83
+ mode: "json"
84
+ }).$type(),
85
+ connectorConfig: sqliteCore.text("connector_config", {
86
+ mode: "json"
87
+ }).$type()
88
+ },
89
+ (t) => [sqliteCore.unique().on(t.iban)]
90
+ );
91
+
92
+ const batch = sqliteCore.sqliteTable("batch", {
93
+ ...backendSdk.base,
94
+ batchPaymentInitiatedAt: sqliteCore.integer("batch_payment_initiated_at", {
95
+ mode: "timestamp_ms"
96
+ }),
97
+ authorizationUrls: sqliteCore.text("authorization_urls", { mode: "json" }).$type(),
98
+ accountId: sqliteCore.text("account_id").references(() => account.id, {
99
+ onDelete: "restrict",
100
+ onUpdate: "cascade"
101
+ }),
102
+ status: sqliteCore.text("status", { enum: BATCH_STATUSES }).$type(),
103
+ statusReason: sqliteCore.text("status_reason"),
104
+ statusResponse: sqliteCore.text("status_response", { mode: "json" }).$type(),
105
+ metadata: sqliteCore.text("metadata", { mode: "json" }).$type(),
106
+ paymentType: sqliteCore.text("payment_type", {
107
+ enum: PAYMENT_TYPES
108
+ }).$type(),
109
+ paymentsChecksum: sqliteCore.text("payments_checksum"),
110
+ batchMode: sqliteCore.text("batch_mode", { enum: BATCH_MODES }).$type()
111
+ });
112
+
113
+ const payment = sqliteCore.sqliteTable(
114
+ "payment",
115
+ {
116
+ ...backendSdk.base,
117
+ correlationId: sqliteCore.text("correlation_id").notNull(),
118
+ refId: sqliteCore.text("ref_id"),
119
+ bankRefId: sqliteCore.text("bank_ref_id").notNull(),
120
+ accountId: sqliteCore.text("account_id").references(() => account.id, {
121
+ onDelete: "restrict",
122
+ onUpdate: "cascade"
123
+ }).notNull(),
124
+ connectorKey: sqliteCore.text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
125
+ amount: sqliteCore.real("amount").notNull(),
126
+ direction: sqliteCore.text("direction").$type().notNull(),
127
+ paymentType: sqliteCore.text("payment_type").$type().notNull(),
128
+ currency: sqliteCore.text("currency").$type().notNull(),
129
+ status: sqliteCore.text("status", { enum: PAYMENT_STATUSES }).$type().notNull(),
130
+ statusReason: sqliteCore.text("status_reason"),
131
+ batchId: sqliteCore.text("bank_execution_batch_id"),
132
+ initiatedAt: sqliteCore.integer("initiated_at", {
133
+ mode: "timestamp_ms"
134
+ }),
135
+ vs: sqliteCore.text("vs"),
136
+ ss: sqliteCore.text("ss"),
137
+ ks: sqliteCore.text("ks"),
138
+ message: sqliteCore.text("message"),
139
+ chargeBearer: sqliteCore.text("charge_bearer", {
140
+ enum: CHARGE_BEARERS
141
+ }).$type(),
142
+ instructionPriority: sqliteCore.text("instruction_priority", {
143
+ enum: INSTRUCTION_PRIORITIES
144
+ }).$type(),
145
+ processedAt: sqliteCore.integer("processed_at", {
146
+ mode: "timestamp_ms"
147
+ }),
148
+ creditor: sqliteCore.text("creditor", { mode: "json" }).$type().notNull(),
149
+ creditorIban: sqliteCore.text("creditor_iban"),
150
+ debtor: sqliteCore.text("debtor", { mode: "json" }).$type().notNull(),
151
+ debtorIban: sqliteCore.text("debtor_iban")
152
+ },
153
+ (t) => [
154
+ sqliteCore.unique().on(t.connectorKey, t.accountId, t.bankRefId),
155
+ sqliteCore.index("payment_account_id_idx").on(t.accountId),
156
+ sqliteCore.index("payment_account_id_status_idx").on(t.accountId, t.status),
157
+ sqliteCore.index("payment_account_id_created_at_idx").on(t.accountId, t.createdAt),
158
+ sqliteCore.index("payment_created_at_idx").on(t.createdAt),
159
+ sqliteCore.index("payment_direction_idx").on(t.direction),
160
+ sqliteCore.index("payment_batch_id_idx").on(t.batchId),
161
+ sqliteCore.index("payment_creditor_iban_idx").on(t.creditorIban),
162
+ sqliteCore.index("payment_debtor_iban_idx").on(t.debtorIban)
163
+ ]
164
+ );
165
+
166
+ const paymentRequest = sqliteCore.sqliteTable(
167
+ "payment_request",
168
+ {
169
+ ...backendSdk.base,
170
+ batchId: sqliteCore.text("batch_id").references(() => batch.id, {
171
+ onDelete: "restrict",
172
+ onUpdate: "cascade"
173
+ }),
174
+ accountId: sqliteCore.text("account_id").references(() => account.id, {
175
+ onDelete: "restrict",
176
+ onUpdate: "cascade"
177
+ }).notNull(),
178
+ correlationId: sqliteCore.text("correlation_id").notNull(),
179
+ refId: sqliteCore.text("ref_id"),
180
+ bankRefId: sqliteCore.text("bank_ref_id"),
181
+ connectorKey: sqliteCore.text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
182
+ amount: sqliteCore.real("amount").notNull(),
183
+ paymentType: sqliteCore.text("payment_type", { enum: PAYMENT_TYPES }).$type().notNull(),
184
+ currency: sqliteCore.text("currency").$type().notNull(),
185
+ status: sqliteCore.text("status", { enum: PAYMENT_REQUEST_STATUSES }).$type().notNull(),
186
+ statusReason: sqliteCore.text("status_reason"),
187
+ authorizationUrl: sqliteCore.text("authorization_url"),
188
+ initiatedAt: sqliteCore.integer("initiated_at", { mode: "timestamp_ms" }),
189
+ processedAt: sqliteCore.integer("processed_at", { mode: "timestamp_ms" }),
190
+ vs: sqliteCore.text("vs"),
191
+ ss: sqliteCore.text("ss"),
192
+ ks: sqliteCore.text("ks"),
193
+ message: sqliteCore.text("message"),
194
+ chargeBearer: sqliteCore.text("charge_bearer", {
195
+ enum: CHARGE_BEARERS
196
+ }).$type(),
197
+ instructionPriority: sqliteCore.text("instruction_priority", {
198
+ enum: INSTRUCTION_PRIORITIES
199
+ }).$type(),
200
+ creditor: sqliteCore.text("creditor", { mode: "json" }).$type().notNull(),
201
+ creditorIban: sqliteCore.text("creditor_iban"),
202
+ debtor: sqliteCore.text("debtor", { mode: "json" }).$type().notNull(),
203
+ debtorIban: sqliteCore.text("debtor_iban"),
204
+ sendAsSinglePayment: sqliteCore.integer("send_as_single_payment", {
205
+ mode: "boolean"
206
+ })
207
+ },
208
+ (t) => [
209
+ sqliteCore.index("payment_request_batch_id_idx").on(t.batchId),
210
+ sqliteCore.index("payment_request_account_id_idx").on(t.accountId),
211
+ sqliteCore.index("payment_request_creditor_iban_idx").on(t.creditorIban),
212
+ sqliteCore.index("payment_request_debtor_iban_idx").on(t.debtorIban),
213
+ sqliteCore.index("payment_request_status_idx").on(t.status),
214
+ sqliteCore.index("payment_request_created_at_idx").on(t.createdAt),
215
+ sqliteCore.index("payment_request_account_status_idx").on(t.accountId, t.status),
216
+ sqliteCore.index("payment_request_status_created_at_idx").on(t.status, t.createdAt),
217
+ sqliteCore.index("payment_request_account_status_created_at_idx").on(
218
+ t.accountId,
219
+ t.status,
220
+ t.createdAt
221
+ )
222
+ ]
223
+ );
224
+
225
+ const ott = sqliteCore.sqliteTable("ott", {
226
+ ...backendSdk.base,
227
+ oneTimeToken: sqliteCore.text("one_time_token").notNull(),
228
+ refId: sqliteCore.text("ref_id").notNull(),
229
+ tokenType: sqliteCore.text("token_type", { enum: TOKEN_TYPES }).$type().notNull(),
230
+ expiresAt: sqliteCore.integer("expires_at", { mode: "timestamp_ms" }).notNull()
231
+ });
232
+
233
+ const accountCredentials = sqliteCore.sqliteTable("account_credentials", {
234
+ ...backendSdk.base,
235
+ accountId: sqliteCore.text("account_id").references(() => account.id, { onDelete: "restrict", onUpdate: "cascade" }).notNull(),
236
+ connectorKey: sqliteCore.text("connector_key", {
237
+ enum: CONNECTOR_KEYS
238
+ }).$type().notNull(),
239
+ type: sqliteCore.text("type", {
240
+ enum: CREDENTIALS_TYPES
241
+ }).$type().notNull(),
242
+ value: sqliteCore.text("value").notNull(),
243
+ expiresAt: sqliteCore.integer("expires_at", { mode: "timestamp_ms" }).notNull()
244
+ });
245
+
246
+ const schema = {
247
+ __proto__: null,
248
+ account: account,
249
+ accountCredentials: accountCredentials,
250
+ batch: batch,
251
+ ott: ott,
252
+ payment: payment,
253
+ paymentRequest: paymentRequest
254
+ };
255
+
256
+ exports.ACCOUNT_STATUSES = ACCOUNT_STATUSES;
257
+ exports.BATCH_MODES = BATCH_MODES;
258
+ exports.BATCH_STATUSES = BATCH_STATUSES;
259
+ exports.CHARGE_BEARERS = CHARGE_BEARERS;
260
+ exports.CONNECTOR_KEYS = CONNECTOR_KEYS;
261
+ exports.COUNTRY_CODES = COUNTRY_CODES;
262
+ exports.CREDENTIALS_TYPES = CREDENTIALS_TYPES;
263
+ exports.INSTRUCTION_PRIORITIES = INSTRUCTION_PRIORITIES;
264
+ exports.PAYMENT_DIRECTIONS = PAYMENT_DIRECTIONS;
265
+ exports.PAYMENT_REQUEST_STATUSES = PAYMENT_REQUEST_STATUSES;
266
+ exports.PAYMENT_STATUSES = PAYMENT_STATUSES;
267
+ exports.PAYMENT_TYPES = PAYMENT_TYPES;
268
+ exports.TOKEN_TYPES = TOKEN_TYPES;
269
+ exports.account = account;
270
+ exports.accountCredentials = accountCredentials;
271
+ exports.batch = batch;
272
+ exports.ott = ott;
273
+ exports.payment = payment;
274
+ exports.paymentRequest = paymentRequest;
275
+ exports.schema = schema;
@@ -1,4 +1,4 @@
1
- import { e as CurrencyCode, Q as BankCode, a0 as CountryCode, P as PaymentRequestSelectType } from './bank.CC4p6Jf-.cjs';
1
+ import { e as CurrencyCode, Q as BankCode, a0 as CountryCode, P as PaymentRequestSelectType } from './bank.CVCyY-qU.cjs';
2
2
  import { z } from 'zod';
3
3
 
4
4
  type ReferenceType = `${'VS' | 'SS' | 'KS'}:${number}`;
@@ -364,7 +364,6 @@ declare const sendPaymentInputSchema: z.ZodObject<{
364
364
  city: z.ZodOptional<z.ZodString>;
365
365
  postalCode: z.ZodOptional<z.ZodString>;
366
366
  countryCode: z.ZodOptional<z.ZodEnum<{
367
- IM: "IM";
368
367
  AF: "AF";
369
368
  AL: "AL";
370
369
  DZ: "DZ";
@@ -453,6 +452,7 @@ declare const sendPaymentInputSchema: z.ZodObject<{
453
452
  IR: "IR";
454
453
  IQ: "IQ";
455
454
  IE: "IE";
455
+ IM: "IM";
456
456
  IL: "IL";
457
457
  IT: "IT";
458
458
  CI: "CI";
@@ -635,7 +635,6 @@ declare const sendPaymentInputSchema: z.ZodObject<{
635
635
  AVAX: "AVAX";
636
636
  }>>;
637
637
  countryCode: z.ZodOptional<z.ZodEnum<{
638
- IM: "IM";
639
638
  AF: "AF";
640
639
  AL: "AL";
641
640
  DZ: "DZ";
@@ -724,6 +723,7 @@ declare const sendPaymentInputSchema: z.ZodObject<{
724
723
  IR: "IR";
725
724
  IQ: "IQ";
726
725
  IE: "IE";
726
+ IM: "IM";
727
727
  IL: "IL";
728
728
  IT: "IT";
729
729
  CI: "CI";
@@ -927,7 +927,6 @@ declare const sendPaymentInputSchema: z.ZodObject<{
927
927
  city: z.ZodOptional<z.ZodString>;
928
928
  postalCode: z.ZodOptional<z.ZodString>;
929
929
  countryCode: z.ZodOptional<z.ZodEnum<{
930
- IM: "IM";
931
930
  AF: "AF";
932
931
  AL: "AL";
933
932
  DZ: "DZ";
@@ -1016,6 +1015,7 @@ declare const sendPaymentInputSchema: z.ZodObject<{
1016
1015
  IR: "IR";
1017
1016
  IQ: "IQ";
1018
1017
  IE: "IE";
1018
+ IM: "IM";
1019
1019
  IL: "IL";
1020
1020
  IT: "IT";
1021
1021
  CI: "CI";
@@ -1198,7 +1198,6 @@ declare const sendPaymentInputSchema: z.ZodObject<{
1198
1198
  AVAX: "AVAX";
1199
1199
  }>>;
1200
1200
  countryCode: z.ZodOptional<z.ZodEnum<{
1201
- IM: "IM";
1202
1201
  AF: "AF";
1203
1202
  AL: "AL";
1204
1203
  DZ: "DZ";
@@ -1287,6 +1286,7 @@ declare const sendPaymentInputSchema: z.ZodObject<{
1287
1286
  IR: "IR";
1288
1287
  IQ: "IQ";
1289
1288
  IE: "IE";
1289
+ IM: "IM";
1290
1290
  IL: "IL";
1291
1291
  IT: "IT";
1292
1292
  CI: "CI";
@@ -1578,7 +1578,6 @@ declare const sendPaymentSyncInputSchema: z.ZodObject<{
1578
1578
  city: z.ZodOptional<z.ZodString>;
1579
1579
  postalCode: z.ZodOptional<z.ZodString>;
1580
1580
  countryCode: z.ZodOptional<z.ZodEnum<{
1581
- IM: "IM";
1582
1581
  AF: "AF";
1583
1582
  AL: "AL";
1584
1583
  DZ: "DZ";
@@ -1667,6 +1666,7 @@ declare const sendPaymentSyncInputSchema: z.ZodObject<{
1667
1666
  IR: "IR";
1668
1667
  IQ: "IQ";
1669
1668
  IE: "IE";
1669
+ IM: "IM";
1670
1670
  IL: "IL";
1671
1671
  IT: "IT";
1672
1672
  CI: "CI";
@@ -1849,7 +1849,6 @@ declare const sendPaymentSyncInputSchema: z.ZodObject<{
1849
1849
  AVAX: "AVAX";
1850
1850
  }>>;
1851
1851
  countryCode: z.ZodOptional<z.ZodEnum<{
1852
- IM: "IM";
1853
1852
  AF: "AF";
1854
1853
  AL: "AL";
1855
1854
  DZ: "DZ";
@@ -1938,6 +1937,7 @@ declare const sendPaymentSyncInputSchema: z.ZodObject<{
1938
1937
  IR: "IR";
1939
1938
  IQ: "IQ";
1940
1939
  IE: "IE";
1940
+ IM: "IM";
1941
1941
  IL: "IL";
1942
1942
  IT: "IT";
1943
1943
  CI: "CI";
@@ -2141,7 +2141,6 @@ declare const sendPaymentSyncInputSchema: z.ZodObject<{
2141
2141
  city: z.ZodOptional<z.ZodString>;
2142
2142
  postalCode: z.ZodOptional<z.ZodString>;
2143
2143
  countryCode: z.ZodOptional<z.ZodEnum<{
2144
- IM: "IM";
2145
2144
  AF: "AF";
2146
2145
  AL: "AL";
2147
2146
  DZ: "DZ";
@@ -2230,6 +2229,7 @@ declare const sendPaymentSyncInputSchema: z.ZodObject<{
2230
2229
  IR: "IR";
2231
2230
  IQ: "IQ";
2232
2231
  IE: "IE";
2232
+ IM: "IM";
2233
2233
  IL: "IL";
2234
2234
  IT: "IT";
2235
2235
  CI: "CI";
@@ -2412,7 +2412,6 @@ declare const sendPaymentSyncInputSchema: z.ZodObject<{
2412
2412
  AVAX: "AVAX";
2413
2413
  }>>;
2414
2414
  countryCode: z.ZodOptional<z.ZodEnum<{
2415
- IM: "IM";
2416
2415
  AF: "AF";
2417
2416
  AL: "AL";
2418
2417
  DZ: "DZ";
@@ -2501,6 +2500,7 @@ declare const sendPaymentSyncInputSchema: z.ZodObject<{
2501
2500
  IR: "IR";
2502
2501
  IQ: "IQ";
2503
2502
  IE: "IE";
2503
+ IM: "IM";
2504
2504
  IL: "IL";
2505
2505
  IT: "IT";
2506
2506
  CI: "CI";
@@ -1,6 +1,7 @@
1
1
  import { sql, and, eq, isNull } from 'drizzle-orm';
2
- import { V as tables } from './bank.gVOunsjq.mjs';
2
+ import { B as tables } from './bank.CTFqGRuY.mjs';
3
3
  import { uuidv4 } from '@develit-io/backend-sdk';
4
+ import './bank.BzDNLxB_.mjs';
4
5
  import 'date-fns';
5
6
  import 'jose';
6
7
  import '@develit-io/general-codes';
@@ -0,0 +1,254 @@
1
+ import { bankAccount, base } from '@develit-io/backend-sdk';
2
+ import { sqliteTable, text, integer, unique, real, index } from 'drizzle-orm/sqlite-core';
3
+ import { COUNTRY_CODES_2, BANK_CODES } from '@develit-io/general-codes';
4
+
5
+ const PAYMENT_TYPES = ["SEPA", "SWIFT", "DOMESTIC", "UNKNOWN"];
6
+ const CHARGE_BEARERS = ["SHA", "OUR", "BEN"];
7
+ const INSTRUCTION_PRIORITIES = ["NORM", "HIGH", "INST"];
8
+ const PAYMENT_REQUEST_STATUSES = [
9
+ "OPENED",
10
+ "AUTHORIZED",
11
+ "COMPLETED",
12
+ "BOOKED",
13
+ "SETTLED",
14
+ "REJECTED",
15
+ "CLOSED"
16
+ ];
17
+ const PAYMENT_STATUSES = [
18
+ "PENDING",
19
+ "PROCESSING",
20
+ "BOOKED",
21
+ "CANCELLED",
22
+ "REJECTED",
23
+ "SCHEDULED",
24
+ "HOLD",
25
+ "INFO"
26
+ ];
27
+ const PAYMENT_DIRECTIONS = ["INCOMING", "OUTGOING"];
28
+ const BATCH_STATUSES = [
29
+ "PROCESSING",
30
+ "READY_TO_SIGN",
31
+ "AUTHORIZED",
32
+ "COMPLETED",
33
+ "FAILED"
34
+ ];
35
+ const BATCH_MODES = ["NATIVE", "SINGLE"];
36
+ const ACCOUNT_STATUSES = ["AUTHORIZED", "DISABLED", "EXPIRED"];
37
+ const COUNTRY_CODES = COUNTRY_CODES_2;
38
+
39
+ const CONNECTOR_KEYS = [
40
+ "ERSTE",
41
+ "FINBRICKS",
42
+ "MOCK",
43
+ "CREDITAS",
44
+ "MOCK_COBS",
45
+ "FIO",
46
+ "MONETA",
47
+ "DBU",
48
+ "CSAS",
49
+ "AIRBANK",
50
+ "KB",
51
+ "CSOB"
52
+ ];
53
+ const CREDENTIALS_TYPES = [
54
+ "AUTH_TOKEN",
55
+ "REFRESH_TOKEN",
56
+ "CLIENT_ID",
57
+ "API_KEY"
58
+ ];
59
+ const TOKEN_TYPES = ["ACCOUNT_AUTHORIZATION"];
60
+
61
+ const account = sqliteTable(
62
+ "account",
63
+ {
64
+ ...base,
65
+ ...bankAccount,
66
+ // countryCode is temporary until bankAccount is update to include US country code
67
+ countryCode: text("country_code", { enum: COUNTRY_CODES }).$type().notNull(),
68
+ number: text("number").notNull(),
69
+ name: text("name"),
70
+ iban: text("iban").notNull(),
71
+ bankCode: text("bank_code", { enum: BANK_CODES }).notNull(),
72
+ connectorKey: text("connector_key", {
73
+ enum: CONNECTOR_KEYS
74
+ }).$type().notNull(),
75
+ status: text("status", { enum: ACCOUNT_STATUSES }).$type().notNull(),
76
+ bankRefId: text("bank_ref_id").notNull(),
77
+ batchSizeLimit: integer("batch_size_limit").notNull().default(50),
78
+ syncIntervalS: integer("sync_interval_s").notNull().default(600),
79
+ lastSyncAt: integer("last_sync_at", { mode: "timestamp_ms" }),
80
+ lastSyncMetadata: text("last_sync_metadata", {
81
+ mode: "json"
82
+ }).$type(),
83
+ connectorConfig: text("connector_config", {
84
+ mode: "json"
85
+ }).$type()
86
+ },
87
+ (t) => [unique().on(t.iban)]
88
+ );
89
+
90
+ const batch = sqliteTable("batch", {
91
+ ...base,
92
+ batchPaymentInitiatedAt: integer("batch_payment_initiated_at", {
93
+ mode: "timestamp_ms"
94
+ }),
95
+ authorizationUrls: text("authorization_urls", { mode: "json" }).$type(),
96
+ accountId: text("account_id").references(() => account.id, {
97
+ onDelete: "restrict",
98
+ onUpdate: "cascade"
99
+ }),
100
+ status: text("status", { enum: BATCH_STATUSES }).$type(),
101
+ statusReason: text("status_reason"),
102
+ statusResponse: text("status_response", { mode: "json" }).$type(),
103
+ metadata: text("metadata", { mode: "json" }).$type(),
104
+ paymentType: text("payment_type", {
105
+ enum: PAYMENT_TYPES
106
+ }).$type(),
107
+ paymentsChecksum: text("payments_checksum"),
108
+ batchMode: text("batch_mode", { enum: BATCH_MODES }).$type()
109
+ });
110
+
111
+ const payment = sqliteTable(
112
+ "payment",
113
+ {
114
+ ...base,
115
+ correlationId: text("correlation_id").notNull(),
116
+ refId: text("ref_id"),
117
+ bankRefId: text("bank_ref_id").notNull(),
118
+ accountId: text("account_id").references(() => account.id, {
119
+ onDelete: "restrict",
120
+ onUpdate: "cascade"
121
+ }).notNull(),
122
+ connectorKey: text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
123
+ amount: real("amount").notNull(),
124
+ direction: text("direction").$type().notNull(),
125
+ paymentType: text("payment_type").$type().notNull(),
126
+ currency: text("currency").$type().notNull(),
127
+ status: text("status", { enum: PAYMENT_STATUSES }).$type().notNull(),
128
+ statusReason: text("status_reason"),
129
+ batchId: text("bank_execution_batch_id"),
130
+ initiatedAt: integer("initiated_at", {
131
+ mode: "timestamp_ms"
132
+ }),
133
+ vs: text("vs"),
134
+ ss: text("ss"),
135
+ ks: text("ks"),
136
+ message: text("message"),
137
+ chargeBearer: text("charge_bearer", {
138
+ enum: CHARGE_BEARERS
139
+ }).$type(),
140
+ instructionPriority: text("instruction_priority", {
141
+ enum: INSTRUCTION_PRIORITIES
142
+ }).$type(),
143
+ processedAt: integer("processed_at", {
144
+ mode: "timestamp_ms"
145
+ }),
146
+ creditor: text("creditor", { mode: "json" }).$type().notNull(),
147
+ creditorIban: text("creditor_iban"),
148
+ debtor: text("debtor", { mode: "json" }).$type().notNull(),
149
+ debtorIban: text("debtor_iban")
150
+ },
151
+ (t) => [
152
+ unique().on(t.connectorKey, t.accountId, t.bankRefId),
153
+ index("payment_account_id_idx").on(t.accountId),
154
+ index("payment_account_id_status_idx").on(t.accountId, t.status),
155
+ index("payment_account_id_created_at_idx").on(t.accountId, t.createdAt),
156
+ index("payment_created_at_idx").on(t.createdAt),
157
+ index("payment_direction_idx").on(t.direction),
158
+ index("payment_batch_id_idx").on(t.batchId),
159
+ index("payment_creditor_iban_idx").on(t.creditorIban),
160
+ index("payment_debtor_iban_idx").on(t.debtorIban)
161
+ ]
162
+ );
163
+
164
+ const paymentRequest = sqliteTable(
165
+ "payment_request",
166
+ {
167
+ ...base,
168
+ batchId: text("batch_id").references(() => batch.id, {
169
+ onDelete: "restrict",
170
+ onUpdate: "cascade"
171
+ }),
172
+ accountId: text("account_id").references(() => account.id, {
173
+ onDelete: "restrict",
174
+ onUpdate: "cascade"
175
+ }).notNull(),
176
+ correlationId: text("correlation_id").notNull(),
177
+ refId: text("ref_id"),
178
+ bankRefId: text("bank_ref_id"),
179
+ connectorKey: text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
180
+ amount: real("amount").notNull(),
181
+ paymentType: text("payment_type", { enum: PAYMENT_TYPES }).$type().notNull(),
182
+ currency: text("currency").$type().notNull(),
183
+ status: text("status", { enum: PAYMENT_REQUEST_STATUSES }).$type().notNull(),
184
+ statusReason: text("status_reason"),
185
+ authorizationUrl: text("authorization_url"),
186
+ initiatedAt: integer("initiated_at", { mode: "timestamp_ms" }),
187
+ processedAt: integer("processed_at", { mode: "timestamp_ms" }),
188
+ vs: text("vs"),
189
+ ss: text("ss"),
190
+ ks: text("ks"),
191
+ message: text("message"),
192
+ chargeBearer: text("charge_bearer", {
193
+ enum: CHARGE_BEARERS
194
+ }).$type(),
195
+ instructionPriority: text("instruction_priority", {
196
+ enum: INSTRUCTION_PRIORITIES
197
+ }).$type(),
198
+ creditor: text("creditor", { mode: "json" }).$type().notNull(),
199
+ creditorIban: text("creditor_iban"),
200
+ debtor: text("debtor", { mode: "json" }).$type().notNull(),
201
+ debtorIban: text("debtor_iban"),
202
+ sendAsSinglePayment: integer("send_as_single_payment", {
203
+ mode: "boolean"
204
+ })
205
+ },
206
+ (t) => [
207
+ index("payment_request_batch_id_idx").on(t.batchId),
208
+ index("payment_request_account_id_idx").on(t.accountId),
209
+ index("payment_request_creditor_iban_idx").on(t.creditorIban),
210
+ index("payment_request_debtor_iban_idx").on(t.debtorIban),
211
+ index("payment_request_status_idx").on(t.status),
212
+ index("payment_request_created_at_idx").on(t.createdAt),
213
+ index("payment_request_account_status_idx").on(t.accountId, t.status),
214
+ index("payment_request_status_created_at_idx").on(t.status, t.createdAt),
215
+ index("payment_request_account_status_created_at_idx").on(
216
+ t.accountId,
217
+ t.status,
218
+ t.createdAt
219
+ )
220
+ ]
221
+ );
222
+
223
+ const ott = sqliteTable("ott", {
224
+ ...base,
225
+ oneTimeToken: text("one_time_token").notNull(),
226
+ refId: text("ref_id").notNull(),
227
+ tokenType: text("token_type", { enum: TOKEN_TYPES }).$type().notNull(),
228
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull()
229
+ });
230
+
231
+ const accountCredentials = sqliteTable("account_credentials", {
232
+ ...base,
233
+ accountId: text("account_id").references(() => account.id, { onDelete: "restrict", onUpdate: "cascade" }).notNull(),
234
+ connectorKey: text("connector_key", {
235
+ enum: CONNECTOR_KEYS
236
+ }).$type().notNull(),
237
+ type: text("type", {
238
+ enum: CREDENTIALS_TYPES
239
+ }).$type().notNull(),
240
+ value: text("value").notNull(),
241
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull()
242
+ });
243
+
244
+ const schema = {
245
+ __proto__: null,
246
+ account: account,
247
+ accountCredentials: accountCredentials,
248
+ batch: batch,
249
+ ott: ott,
250
+ payment: payment,
251
+ paymentRequest: paymentRequest
252
+ };
253
+
254
+ export { ACCOUNT_STATUSES as A, BATCH_MODES as B, CHARGE_BEARERS as C, INSTRUCTION_PRIORITIES as I, PAYMENT_DIRECTIONS as P, TOKEN_TYPES as T, BATCH_STATUSES as a, CONNECTOR_KEYS as b, COUNTRY_CODES as c, CREDENTIALS_TYPES as d, PAYMENT_REQUEST_STATUSES as e, PAYMENT_STATUSES as f, PAYMENT_TYPES as g, account as h, accountCredentials as i, batch as j, paymentRequest as k, ott as o, payment as p, schema as s };