@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.
- package/dist/database/schema.cjs +1 -10
- package/dist/database/schema.d.cts +3 -3
- package/dist/database/schema.d.mts +3 -3
- package/dist/database/schema.d.ts +3 -3
- package/dist/database/schema.mjs +1 -8
- package/dist/export/worker.cjs +137 -137
- package/dist/export/worker.d.cts +115 -451
- package/dist/export/worker.d.mts +115 -451
- package/dist/export/worker.d.ts +115 -451
- package/dist/export/worker.mjs +40 -40
- package/dist/export/workflows.cjs +29 -23
- package/dist/export/workflows.mjs +18 -12
- package/dist/export/wrangler.cjs +7 -12
- package/dist/export/wrangler.d.cts +11 -3
- package/dist/export/wrangler.d.mts +11 -3
- package/dist/export/wrangler.d.ts +11 -3
- package/dist/export/wrangler.mjs +7 -12
- package/dist/shared/bank.9Yw4KHyl.cjs +275 -0
- package/dist/shared/{bank.CxAHQOwW.d.cts → bank.BanqNaZK.d.cts} +9 -9
- package/dist/shared/{bank.BSiA1m0B.mjs → bank.ByesVuDp.mjs} +2 -1
- package/dist/shared/bank.BzDNLxB_.mjs +254 -0
- package/dist/shared/{bank.gVOunsjq.mjs → bank.CTFqGRuY.mjs} +227 -447
- package/dist/shared/{bank.CC4p6Jf-.d.cts → bank.CVCyY-qU.d.cts} +1225 -3788
- package/dist/shared/{bank.CC4p6Jf-.d.mts → bank.CVCyY-qU.d.mts} +1225 -3788
- package/dist/shared/{bank.CC4p6Jf-.d.ts → bank.CVCyY-qU.d.ts} +1225 -3788
- package/dist/shared/{bank.Dl3mNNS2.d.mts → bank.DOlM7clW.d.mts} +9 -9
- package/dist/shared/{bank.DICdNw3T.cjs → bank.OSj3Smwv.cjs} +17 -16
- package/dist/shared/{bank.C5NCnZWS.d.ts → bank.SoKDxQxH.d.ts} +9 -9
- package/dist/shared/{bank.avgw-IRO.cjs → bank.pU2vSCUr.cjs} +234 -474
- package/dist/types.cjs +38 -38
- package/dist/types.d.cts +57 -450
- package/dist/types.d.mts +57 -450
- package/dist/types.d.ts +57 -450
- package/dist/types.mjs +4 -4
- package/package.json +6 -5
- package/dist/shared/{bank.Bz4DIxJL.d.cts → bank.C6sLje8B.d.cts} +3 -3
- package/dist/shared/{bank.Bz4DIxJL.d.mts → bank.C6sLje8B.d.mts} +3 -3
- package/dist/shared/{bank.Bz4DIxJL.d.ts → bank.C6sLje8B.d.ts} +3 -3
package/dist/database/schema.cjs
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const database_schema = require('../shared/bank.
|
|
3
|
+
const database_schema = require('../shared/bank.9Yw4KHyl.cjs');
|
|
4
4
|
require('@develit-io/backend-sdk');
|
|
5
5
|
require('drizzle-orm/sqlite-core');
|
|
6
|
-
require('date-fns');
|
|
7
|
-
require('jose');
|
|
8
|
-
require('zod');
|
|
9
6
|
require('@develit-io/general-codes');
|
|
10
|
-
require('drizzle-orm/relations');
|
|
11
|
-
require('drizzle-orm');
|
|
12
|
-
require('node:crypto');
|
|
13
|
-
require('drizzle-zod');
|
|
14
7
|
|
|
15
8
|
|
|
16
9
|
|
|
@@ -19,6 +12,4 @@ exports.accountCredentials = database_schema.accountCredentials;
|
|
|
19
12
|
exports.batch = database_schema.batch;
|
|
20
13
|
exports.ott = database_schema.ott;
|
|
21
14
|
exports.payment = database_schema.payment;
|
|
22
|
-
exports.paymentRelations = database_schema.paymentRelations;
|
|
23
15
|
exports.paymentRequest = database_schema.paymentRequest;
|
|
24
|
-
exports.paymentRequestRelations = database_schema.paymentRequestRelations;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { aA as account, aB as accountCredentials, aC as batch, aD as ott, aE as payment, aF as
|
|
2
|
-
import 'drizzle-orm/sqlite-core';
|
|
1
|
+
export { aA as account, aB as accountCredentials, aC as batch, aD as ott, aE as payment, aF as paymentRequest } from '../shared/bank.CVCyY-qU.cjs';
|
|
3
2
|
import 'drizzle-orm';
|
|
4
|
-
import '
|
|
3
|
+
import 'drizzle-orm/sqlite-core';
|
|
5
4
|
import '@develit-io/general-codes';
|
|
6
5
|
import 'zod';
|
|
7
6
|
import 'drizzle-zod';
|
|
8
7
|
import 'zod/v4/core';
|
|
8
|
+
import '@develit-io/backend-sdk';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { aA as account, aB as accountCredentials, aC as batch, aD as ott, aE as payment, aF as
|
|
2
|
-
import 'drizzle-orm/sqlite-core';
|
|
1
|
+
export { aA as account, aB as accountCredentials, aC as batch, aD as ott, aE as payment, aF as paymentRequest } from '../shared/bank.CVCyY-qU.mjs';
|
|
3
2
|
import 'drizzle-orm';
|
|
4
|
-
import '
|
|
3
|
+
import 'drizzle-orm/sqlite-core';
|
|
5
4
|
import '@develit-io/general-codes';
|
|
6
5
|
import 'zod';
|
|
7
6
|
import 'drizzle-zod';
|
|
8
7
|
import 'zod/v4/core';
|
|
8
|
+
import '@develit-io/backend-sdk';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { aA as account, aB as accountCredentials, aC as batch, aD as ott, aE as payment, aF as
|
|
2
|
-
import 'drizzle-orm/sqlite-core';
|
|
1
|
+
export { aA as account, aB as accountCredentials, aC as batch, aD as ott, aE as payment, aF as paymentRequest } from '../shared/bank.CVCyY-qU.js';
|
|
3
2
|
import 'drizzle-orm';
|
|
4
|
-
import '
|
|
3
|
+
import 'drizzle-orm/sqlite-core';
|
|
5
4
|
import '@develit-io/general-codes';
|
|
6
5
|
import 'zod';
|
|
7
6
|
import 'drizzle-zod';
|
|
8
7
|
import 'zod/v4/core';
|
|
8
|
+
import '@develit-io/backend-sdk';
|
package/dist/database/schema.mjs
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { h as account, i as accountCredentials, j as batch, o as ott, p as payment, k as paymentRequest } from '../shared/bank.BzDNLxB_.mjs';
|
|
2
2
|
import '@develit-io/backend-sdk';
|
|
3
3
|
import 'drizzle-orm/sqlite-core';
|
|
4
|
-
import 'date-fns';
|
|
5
|
-
import 'jose';
|
|
6
|
-
import 'zod';
|
|
7
4
|
import '@develit-io/general-codes';
|
|
8
|
-
import 'drizzle-orm/relations';
|
|
9
|
-
import 'drizzle-orm';
|
|
10
|
-
import 'node:crypto';
|
|
11
|
-
import 'drizzle-zod';
|
package/dist/export/worker.cjs
CHANGED
|
@@ -1,25 +1,59 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const backendSdk = require('@develit-io/backend-sdk');
|
|
4
|
-
const
|
|
4
|
+
const ott_zod = require('../shared/bank.pU2vSCUr.cjs');
|
|
5
5
|
const drizzleOrm = require('drizzle-orm');
|
|
6
6
|
const cloudflare_workers = require('cloudflare:workers');
|
|
7
7
|
const d1 = require('drizzle-orm/d1');
|
|
8
8
|
require('jose');
|
|
9
9
|
const zod = require('zod');
|
|
10
|
+
const database_schema = require('../shared/bank.9Yw4KHyl.cjs');
|
|
10
11
|
const generalCodes = require('@develit-io/general-codes');
|
|
11
12
|
require('date-fns');
|
|
12
13
|
require('node:crypto');
|
|
13
|
-
const credentialsResolver = require('../shared/bank.
|
|
14
|
-
require('drizzle-orm/sqlite-core');
|
|
15
|
-
require('drizzle-orm/relations');
|
|
14
|
+
const credentialsResolver = require('../shared/bank.OSj3Smwv.cjs');
|
|
16
15
|
require('drizzle-zod');
|
|
16
|
+
require('drizzle-orm/sqlite-core');
|
|
17
|
+
|
|
18
|
+
const sendPaymentInputSchema = zod.z.object({
|
|
19
|
+
correlationId: zod.z.string().min(1),
|
|
20
|
+
refId: zod.z.string().optional(),
|
|
21
|
+
amount: zod.z.number().positive(),
|
|
22
|
+
paymentType: zod.z.enum(database_schema.PAYMENT_TYPES),
|
|
23
|
+
chargeBearer: zod.z.enum(database_schema.CHARGE_BEARERS).optional(),
|
|
24
|
+
instructionPriority: zod.z.enum(database_schema.INSTRUCTION_PRIORITIES).optional(),
|
|
25
|
+
currency: zod.z.enum(generalCodes.CURRENCY_CODES),
|
|
26
|
+
vs: zod.z.string().optional(),
|
|
27
|
+
ss: zod.z.string().optional(),
|
|
28
|
+
ks: zod.z.string().optional(),
|
|
29
|
+
message: zod.z.string().optional(),
|
|
30
|
+
creditor: backendSdk.bankAccountMetadataSchema,
|
|
31
|
+
debtor: backendSdk.bankAccountMetadataSchema,
|
|
32
|
+
sendAsSinglePayment: zod.z.boolean().optional()
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const sendBatchInputSchema = zod.z.object({
|
|
36
|
+
payments: zod.z.array(sendPaymentInputSchema).min(1)
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const getAuthUriInputSchema = zod.z.object({
|
|
40
|
+
connectorKey: zod.z.enum(database_schema.CONNECTOR_KEYS)
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const authorizeAccountInputSchema = zod.z.object({
|
|
44
|
+
ott: zod.z.string(),
|
|
45
|
+
urlParams: zod.z.string(),
|
|
46
|
+
syncIntervalS: zod.z.number().int().positive().optional(),
|
|
47
|
+
startSync: zod.z.boolean().optional(),
|
|
48
|
+
lastSyncAt: zod.z.date().optional(),
|
|
49
|
+
address: backendSdk.structuredAddressSchema.optional()
|
|
50
|
+
});
|
|
17
51
|
|
|
18
52
|
const upsertAccountCommand = (db, { account }) => {
|
|
19
53
|
const id = account.id || backendSdk.uuidv4();
|
|
20
54
|
const { id: _id, ...accountWithoutId } = account;
|
|
21
|
-
const command = db.insert(
|
|
22
|
-
target:
|
|
55
|
+
const command = db.insert(ott_zod.tables.account).values({ ...account, id }).onConflictDoUpdate({
|
|
56
|
+
target: ott_zod.tables.account.iban,
|
|
23
57
|
set: accountWithoutId
|
|
24
58
|
// preserve existing id on re-auth
|
|
25
59
|
}).returning();
|
|
@@ -36,7 +70,7 @@ const createOneTimeTokenCommand = (db, {
|
|
|
36
70
|
}) => {
|
|
37
71
|
const id = backendSdk.uuidv4();
|
|
38
72
|
const expiresAt = new Date(Date.now() + 1e3 * 60 * 60) ;
|
|
39
|
-
const command = db.insert(
|
|
73
|
+
const command = db.insert(ott_zod.tables.ott).values({
|
|
40
74
|
id,
|
|
41
75
|
oneTimeToken: ott,
|
|
42
76
|
tokenType,
|
|
@@ -48,7 +82,7 @@ const createOneTimeTokenCommand = (db, {
|
|
|
48
82
|
|
|
49
83
|
const updateAccountCommand = (db, { account }) => {
|
|
50
84
|
return {
|
|
51
|
-
command: db.update(
|
|
85
|
+
command: db.update(ott_zod.tables.account).set({ ...account }).where(drizzleOrm.eq(ott_zod.tables.account.id, account.id)).returning()
|
|
52
86
|
};
|
|
53
87
|
};
|
|
54
88
|
|
|
@@ -56,16 +90,16 @@ const expireOneTimeTokenCommand = (db, {
|
|
|
56
90
|
ott
|
|
57
91
|
}) => {
|
|
58
92
|
return {
|
|
59
|
-
command: db.update(
|
|
93
|
+
command: db.update(ott_zod.tables.ott).set({
|
|
60
94
|
expiresAt: /* @__PURE__ */ new Date()
|
|
61
|
-
}).where(drizzleOrm.eq(
|
|
95
|
+
}).where(drizzleOrm.eq(ott_zod.tables.ott.oneTimeToken, ott))
|
|
62
96
|
};
|
|
63
97
|
};
|
|
64
98
|
|
|
65
99
|
const createAccountCredentialsCommand = async (db, encryptionKey, { credentials }) => {
|
|
66
100
|
const id = credentials.id || backendSdk.uuidv4();
|
|
67
101
|
const encryptedValue = await credentialsResolver.encrypt(credentials.value, encryptionKey);
|
|
68
|
-
const command = db.insert(
|
|
102
|
+
const command = db.insert(ott_zod.tables.accountCredentials).values({
|
|
69
103
|
...credentials,
|
|
70
104
|
id,
|
|
71
105
|
value: encryptedValue
|
|
@@ -77,16 +111,16 @@ const createAccountCredentialsCommand = async (db, encryptionKey, { credentials
|
|
|
77
111
|
};
|
|
78
112
|
|
|
79
113
|
const deleteAccountCredentialsCommand = (db, { accountId }) => {
|
|
80
|
-
const command = db.delete(
|
|
114
|
+
const command = db.delete(ott_zod.tables.accountCredentials).where(drizzleOrm.eq(ott_zod.tables.accountCredentials.accountId, accountId));
|
|
81
115
|
return {
|
|
82
116
|
command
|
|
83
117
|
};
|
|
84
118
|
};
|
|
85
119
|
|
|
86
120
|
const deletePaymentsByAccountCommand = (db, { accountId }) => {
|
|
87
|
-
const command = db.update(
|
|
121
|
+
const command = db.update(ott_zod.tables.payment).set({
|
|
88
122
|
deletedAt: /* @__PURE__ */ new Date()
|
|
89
|
-
}).where(drizzleOrm.eq(
|
|
123
|
+
}).where(drizzleOrm.eq(ott_zod.tables.payment.accountId, accountId));
|
|
90
124
|
return {
|
|
91
125
|
command
|
|
92
126
|
};
|
|
@@ -94,7 +128,7 @@ const deletePaymentsByAccountCommand = (db, { accountId }) => {
|
|
|
94
128
|
|
|
95
129
|
const createPaymentRequestCommand = (db, { paymentRequest }) => {
|
|
96
130
|
return {
|
|
97
|
-
command: db.insert(
|
|
131
|
+
command: db.insert(ott_zod.tables.paymentRequest).values({
|
|
98
132
|
...paymentRequest,
|
|
99
133
|
creditorIban: paymentRequest.creditor.iban,
|
|
100
134
|
debtorIban: paymentRequest.debtor.iban
|
|
@@ -105,16 +139,16 @@ const createPaymentRequestCommand = (db, { paymentRequest }) => {
|
|
|
105
139
|
const getAccountBatchCountsQuery = async (db, { accountId }) => {
|
|
106
140
|
const result = await db.select({
|
|
107
141
|
totalCount: drizzleOrm.sql`COUNT(*)`.as("totalCount"),
|
|
108
|
-
processingCount: drizzleOrm.sql`SUM(CASE WHEN ${
|
|
142
|
+
processingCount: drizzleOrm.sql`SUM(CASE WHEN ${ott_zod.tables.batch.status} = 'PROCESSING' THEN 1 ELSE 0 END)`.as(
|
|
109
143
|
"processingCount"
|
|
110
144
|
),
|
|
111
|
-
readyToSignCount: drizzleOrm.sql`SUM(CASE WHEN ${
|
|
145
|
+
readyToSignCount: drizzleOrm.sql`SUM(CASE WHEN ${ott_zod.tables.batch.status} = 'READY_TO_SIGN' THEN 1 ELSE 0 END)`.as(
|
|
112
146
|
"readyToSignCount"
|
|
113
147
|
),
|
|
114
|
-
failedCount: drizzleOrm.sql`SUM(CASE WHEN ${
|
|
148
|
+
failedCount: drizzleOrm.sql`SUM(CASE WHEN ${ott_zod.tables.batch.status} = 'FAILED' THEN 1 ELSE 0 END)`.as(
|
|
115
149
|
"failedCount"
|
|
116
150
|
)
|
|
117
|
-
}).from(
|
|
151
|
+
}).from(ott_zod.tables.batch).where(drizzleOrm.eq(ott_zod.tables.batch.accountId, accountId)).then(backendSdk.first);
|
|
118
152
|
return result || {
|
|
119
153
|
totalCount: 0,
|
|
120
154
|
processingCount: 0,
|
|
@@ -124,18 +158,18 @@ const getAccountBatchCountsQuery = async (db, { accountId }) => {
|
|
|
124
158
|
};
|
|
125
159
|
|
|
126
160
|
const getAccountByIbanQuery = async (db, { iban }) => {
|
|
127
|
-
return await db.select().from(
|
|
161
|
+
return await db.select().from(ott_zod.tables.account).where(drizzleOrm.eq(ott_zod.tables.account.iban, iban)).get();
|
|
128
162
|
};
|
|
129
163
|
|
|
130
164
|
const getAllAccountsQuery = async (db, filters) => {
|
|
131
165
|
const whereConditions = drizzleOrm.and(
|
|
132
|
-
backendSdk.buildMultiFilterConditions(
|
|
166
|
+
backendSdk.buildMultiFilterConditions(ott_zod.tables.account.iban, filters?.filterIbans),
|
|
133
167
|
backendSdk.buildMultiFilterConditions(
|
|
134
|
-
|
|
168
|
+
ott_zod.tables.account.currency,
|
|
135
169
|
filters?.filterCurrencies
|
|
136
170
|
),
|
|
137
171
|
backendSdk.buildMultiFilterConditions(
|
|
138
|
-
|
|
172
|
+
ott_zod.tables.account.bankRefId,
|
|
139
173
|
filters?.filterBankRefIds
|
|
140
174
|
)
|
|
141
175
|
);
|
|
@@ -143,11 +177,11 @@ const getAllAccountsQuery = async (db, filters) => {
|
|
|
143
177
|
const limit = filters?.limit ?? 20;
|
|
144
178
|
const offset = (page - 1) * limit;
|
|
145
179
|
const [accountsWithExpiration, countResult] = await Promise.all([
|
|
146
|
-
db.select().from(
|
|
147
|
-
|
|
148
|
-
drizzleOrm.eq(
|
|
180
|
+
db.select().from(ott_zod.tables.account).leftJoin(
|
|
181
|
+
ott_zod.tables.accountCredentials,
|
|
182
|
+
drizzleOrm.eq(ott_zod.tables.accountCredentials.accountId, ott_zod.tables.account.id)
|
|
149
183
|
).where(whereConditions).limit(limit).offset(offset),
|
|
150
|
-
db.select({ count: drizzleOrm.sql`count(*)` }).from(
|
|
184
|
+
db.select({ count: drizzleOrm.sql`count(*)` }).from(ott_zod.tables.account).where(whereConditions)
|
|
151
185
|
]);
|
|
152
186
|
return {
|
|
153
187
|
accounts: accountsWithExpiration.map(
|
|
@@ -209,42 +243,42 @@ const getPaymentsWithPaginationQuery = async (db, {
|
|
|
209
243
|
}) => {
|
|
210
244
|
const whereConditions = drizzleOrm.and(
|
|
211
245
|
buildMultiFilterConditions(
|
|
212
|
-
|
|
246
|
+
ott_zod.tables.payment.accountId,
|
|
213
247
|
filterPaymentAccountId
|
|
214
248
|
),
|
|
215
|
-
buildMultiFilterConditions(
|
|
216
|
-
buildMultiFilterConditions(
|
|
249
|
+
buildMultiFilterConditions(ott_zod.tables.payment.amount, filterPaymentAmount),
|
|
250
|
+
buildMultiFilterConditions(ott_zod.tables.payment.currency, filterPaymentCurrency),
|
|
217
251
|
buildRangeFilterConditions(
|
|
218
|
-
|
|
252
|
+
ott_zod.tables.payment.createdAt,
|
|
219
253
|
filterPaymentDateFrom,
|
|
220
254
|
filterPaymentDateTo
|
|
221
255
|
),
|
|
222
|
-
buildMultiFilterConditions(
|
|
256
|
+
buildMultiFilterConditions(ott_zod.tables.payment.status, filterPaymentStatus),
|
|
223
257
|
buildMultiFilterConditions(
|
|
224
|
-
|
|
258
|
+
ott_zod.tables.payment.direction,
|
|
225
259
|
filterPaymentDirection
|
|
226
260
|
),
|
|
227
|
-
buildMultiFilterConditions(
|
|
228
|
-
buildMultiFilterConditions(
|
|
261
|
+
buildMultiFilterConditions(ott_zod.tables.payment.id, ids),
|
|
262
|
+
buildMultiFilterConditions(ott_zod.tables.payment.paymentType, filterPaymentType),
|
|
229
263
|
buildRangeFilterConditions(
|
|
230
|
-
|
|
264
|
+
ott_zod.tables.payment.amount,
|
|
231
265
|
filterPaymentMinAmount,
|
|
232
266
|
filterPaymentMaxAmount
|
|
233
267
|
),
|
|
234
|
-
filterPaymentVariableSymbol !== void 0 ? drizzleOrm.eq(
|
|
235
|
-
filterPaymentSpecificSymbol !== void 0 ? drizzleOrm.eq(
|
|
236
|
-
filterPaymentConstantSymbol !== void 0 ? drizzleOrm.eq(
|
|
237
|
-
filterPaymentMessage !== void 0 ? drizzleOrm.like(
|
|
238
|
-
filterPaymentCreditorIban !== void 0 ? drizzleOrm.eq(
|
|
239
|
-
filterPaymentDebtorIban !== void 0 ? drizzleOrm.eq(
|
|
240
|
-
filterPaymentBatchId !== void 0 ? drizzleOrm.eq(
|
|
241
|
-
filterPaymentBankRefId !== void 0 ? drizzleOrm.eq(
|
|
268
|
+
filterPaymentVariableSymbol !== void 0 ? drizzleOrm.eq(ott_zod.tables.payment.vs, filterPaymentVariableSymbol) : void 0,
|
|
269
|
+
filterPaymentSpecificSymbol !== void 0 ? drizzleOrm.eq(ott_zod.tables.payment.ss, filterPaymentSpecificSymbol) : void 0,
|
|
270
|
+
filterPaymentConstantSymbol !== void 0 ? drizzleOrm.eq(ott_zod.tables.payment.ks, filterPaymentConstantSymbol) : void 0,
|
|
271
|
+
filterPaymentMessage !== void 0 ? drizzleOrm.like(ott_zod.tables.payment.message, `%${filterPaymentMessage}%`) : void 0,
|
|
272
|
+
filterPaymentCreditorIban !== void 0 ? drizzleOrm.eq(ott_zod.tables.payment.creditorIban, filterPaymentCreditorIban) : void 0,
|
|
273
|
+
filterPaymentDebtorIban !== void 0 ? drizzleOrm.eq(ott_zod.tables.payment.debtorIban, filterPaymentDebtorIban) : void 0,
|
|
274
|
+
filterPaymentBatchId !== void 0 ? drizzleOrm.eq(ott_zod.tables.payment.batchId, filterPaymentBatchId) : void 0,
|
|
275
|
+
filterPaymentBankRefId !== void 0 ? drizzleOrm.eq(ott_zod.tables.payment.bankRefId, filterPaymentBankRefId) : void 0
|
|
242
276
|
);
|
|
243
|
-
const sortColumn = resolveColumn(
|
|
277
|
+
const sortColumn = resolveColumn(ott_zod.tables.payment, sort.column);
|
|
244
278
|
const [{ totalCount }] = await db.select({
|
|
245
279
|
totalCount: drizzleOrm.sql`count(*)`
|
|
246
|
-
}).from(
|
|
247
|
-
const payments = await db.select().from(
|
|
280
|
+
}).from(ott_zod.tables.payment).where(whereConditions);
|
|
281
|
+
const payments = await db.select().from(ott_zod.tables.payment).where(whereConditions).limit(limit).offset((page - 1) * limit).orderBy(sort.direction === "asc" ? drizzleOrm.asc(sortColumn) : drizzleOrm.desc(sortColumn));
|
|
248
282
|
return {
|
|
249
283
|
payments,
|
|
250
284
|
totalCount
|
|
@@ -259,20 +293,20 @@ const getBatchesQuery = async (db, {
|
|
|
259
293
|
filterBatchStatus
|
|
260
294
|
}) => {
|
|
261
295
|
const whereConditions = drizzleOrm.and(
|
|
262
|
-
drizzleOrm.isNull(
|
|
263
|
-
buildMultiFilterConditions(
|
|
264
|
-
buildMultiFilterConditions(
|
|
296
|
+
drizzleOrm.isNull(ott_zod.tables.batch.deletedAt),
|
|
297
|
+
buildMultiFilterConditions(ott_zod.tables.batch.accountId, filterBatchAccountId),
|
|
298
|
+
buildMultiFilterConditions(ott_zod.tables.batch.status, filterBatchStatus)
|
|
265
299
|
);
|
|
266
|
-
const sortColumn = resolveColumn(
|
|
300
|
+
const sortColumn = resolveColumn(ott_zod.tables.batch, sort.column);
|
|
267
301
|
const [{ totalCount }] = await db.select({
|
|
268
302
|
totalCount: drizzleOrm.sql`count(*)`
|
|
269
|
-
}).from(
|
|
270
|
-
const batches = await db.select().from(
|
|
303
|
+
}).from(ott_zod.tables.batch).where(whereConditions);
|
|
304
|
+
const batches = await db.select().from(ott_zod.tables.batch).where(whereConditions).limit(limit).offset((page - 1) * limit).orderBy(sort.direction === "asc" ? drizzleOrm.asc(sortColumn) : drizzleOrm.desc(sortColumn));
|
|
271
305
|
const batchIds = batches.map((b) => b.id);
|
|
272
|
-
const paymentRequests = batchIds.length > 0 ? await db.select().from(
|
|
306
|
+
const paymentRequests = batchIds.length > 0 ? await db.select().from(ott_zod.tables.paymentRequest).where(
|
|
273
307
|
drizzleOrm.and(
|
|
274
|
-
drizzleOrm.inArray(
|
|
275
|
-
drizzleOrm.isNull(
|
|
308
|
+
drizzleOrm.inArray(ott_zod.tables.paymentRequest.batchId, batchIds),
|
|
309
|
+
drizzleOrm.isNull(ott_zod.tables.paymentRequest.deletedAt)
|
|
276
310
|
)
|
|
277
311
|
) : [];
|
|
278
312
|
const paymentRequestsByBatchId = Map.groupBy(
|
|
@@ -290,14 +324,14 @@ const getBatchesQuery = async (db, {
|
|
|
290
324
|
};
|
|
291
325
|
|
|
292
326
|
const getOttQuery = async (db, { ott }) => {
|
|
293
|
-
return await db.select().from(
|
|
327
|
+
return await db.select().from(ott_zod.tables.ott).where(drizzleOrm.eq(ott_zod.tables.ott.oneTimeToken, ott)).get();
|
|
294
328
|
};
|
|
295
329
|
|
|
296
330
|
const getPaymentRequestByIdQuery = async (db, { paymentRequestId }) => {
|
|
297
|
-
const result = await db.select().from(
|
|
331
|
+
const result = await db.select().from(ott_zod.tables.paymentRequest).where(
|
|
298
332
|
drizzleOrm.and(
|
|
299
|
-
drizzleOrm.eq(
|
|
300
|
-
drizzleOrm.isNull(
|
|
333
|
+
drizzleOrm.eq(ott_zod.tables.paymentRequest.id, paymentRequestId),
|
|
334
|
+
drizzleOrm.isNull(ott_zod.tables.paymentRequest.deletedAt)
|
|
301
335
|
)
|
|
302
336
|
).limit(1);
|
|
303
337
|
return backendSdk.first(result);
|
|
@@ -307,30 +341,30 @@ const getPaymentRequestsQuery = async (db, params) => {
|
|
|
307
341
|
const limit = params.limit;
|
|
308
342
|
const offset = (params.page - 1) * params.limit;
|
|
309
343
|
const orderDir = params.sort.direction === "asc" ? drizzleOrm.asc : drizzleOrm.desc;
|
|
310
|
-
const orderCol = params.sort.column === "amount" ?
|
|
344
|
+
const orderCol = params.sort.column === "amount" ? ott_zod.tables.paymentRequest.amount : params.sort.column === "updatedAt" ? ott_zod.tables.paymentRequest.updatedAt : ott_zod.tables.paymentRequest.createdAt;
|
|
311
345
|
const where = drizzleOrm.and(
|
|
312
|
-
drizzleOrm.isNull(
|
|
313
|
-
params.filterAccountId ? Array.isArray(params.filterAccountId) ? drizzleOrm.inArray(
|
|
314
|
-
params.filterStatus ? Array.isArray(params.filterStatus) ? drizzleOrm.inArray(
|
|
315
|
-
params.filterPaymentType ? Array.isArray(params.filterPaymentType) ? drizzleOrm.inArray(
|
|
316
|
-
params.filterCurrency ? Array.isArray(params.filterCurrency) ? drizzleOrm.inArray(
|
|
317
|
-
params.filterBatchId ? drizzleOrm.eq(
|
|
318
|
-
params.filterDateFrom ? drizzleOrm.gte(
|
|
319
|
-
params.filterDateTo ? drizzleOrm.lte(
|
|
320
|
-
params.filterMinAmount !== void 0 ? drizzleOrm.gte(
|
|
321
|
-
params.filterMaxAmount !== void 0 ? drizzleOrm.lte(
|
|
322
|
-
params.filterVariableSymbol ? drizzleOrm.eq(
|
|
323
|
-
params.filterSpecificSymbol ? drizzleOrm.eq(
|
|
324
|
-
params.filterConstantSymbol ? drizzleOrm.eq(
|
|
325
|
-
params.filterMessage ? drizzleOrm.like(
|
|
326
|
-
params.filterBankRefId ? drizzleOrm.eq(
|
|
327
|
-
params.filterCreditorIban ? drizzleOrm.eq(
|
|
328
|
-
params.filterDebtorIban ? drizzleOrm.eq(
|
|
329
|
-
params.ids?.length ? drizzleOrm.inArray(
|
|
346
|
+
drizzleOrm.isNull(ott_zod.tables.paymentRequest.deletedAt),
|
|
347
|
+
params.filterAccountId ? Array.isArray(params.filterAccountId) ? drizzleOrm.inArray(ott_zod.tables.paymentRequest.accountId, params.filterAccountId) : drizzleOrm.eq(ott_zod.tables.paymentRequest.accountId, params.filterAccountId) : void 0,
|
|
348
|
+
params.filterStatus ? Array.isArray(params.filterStatus) ? drizzleOrm.inArray(ott_zod.tables.paymentRequest.status, params.filterStatus) : drizzleOrm.eq(ott_zod.tables.paymentRequest.status, params.filterStatus) : void 0,
|
|
349
|
+
params.filterPaymentType ? Array.isArray(params.filterPaymentType) ? drizzleOrm.inArray(ott_zod.tables.paymentRequest.paymentType, params.filterPaymentType) : drizzleOrm.eq(ott_zod.tables.paymentRequest.paymentType, params.filterPaymentType) : void 0,
|
|
350
|
+
params.filterCurrency ? Array.isArray(params.filterCurrency) ? drizzleOrm.inArray(ott_zod.tables.paymentRequest.currency, params.filterCurrency) : drizzleOrm.eq(ott_zod.tables.paymentRequest.currency, params.filterCurrency) : void 0,
|
|
351
|
+
params.filterBatchId ? drizzleOrm.eq(ott_zod.tables.paymentRequest.batchId, params.filterBatchId) : void 0,
|
|
352
|
+
params.filterDateFrom ? drizzleOrm.gte(ott_zod.tables.paymentRequest.createdAt, params.filterDateFrom) : void 0,
|
|
353
|
+
params.filterDateTo ? drizzleOrm.lte(ott_zod.tables.paymentRequest.createdAt, params.filterDateTo) : void 0,
|
|
354
|
+
params.filterMinAmount !== void 0 ? drizzleOrm.gte(ott_zod.tables.paymentRequest.amount, params.filterMinAmount) : void 0,
|
|
355
|
+
params.filterMaxAmount !== void 0 ? drizzleOrm.lte(ott_zod.tables.paymentRequest.amount, params.filterMaxAmount) : void 0,
|
|
356
|
+
params.filterVariableSymbol ? drizzleOrm.eq(ott_zod.tables.paymentRequest.vs, params.filterVariableSymbol) : void 0,
|
|
357
|
+
params.filterSpecificSymbol ? drizzleOrm.eq(ott_zod.tables.paymentRequest.ss, params.filterSpecificSymbol) : void 0,
|
|
358
|
+
params.filterConstantSymbol ? drizzleOrm.eq(ott_zod.tables.paymentRequest.ks, params.filterConstantSymbol) : void 0,
|
|
359
|
+
params.filterMessage ? drizzleOrm.like(ott_zod.tables.paymentRequest.message, `%${params.filterMessage}%`) : void 0,
|
|
360
|
+
params.filterBankRefId ? drizzleOrm.eq(ott_zod.tables.paymentRequest.bankRefId, params.filterBankRefId) : void 0,
|
|
361
|
+
params.filterCreditorIban ? drizzleOrm.eq(ott_zod.tables.paymentRequest.creditorIban, params.filterCreditorIban) : void 0,
|
|
362
|
+
params.filterDebtorIban ? drizzleOrm.eq(ott_zod.tables.paymentRequest.debtorIban, params.filterDebtorIban) : void 0,
|
|
363
|
+
params.ids?.length ? drizzleOrm.inArray(ott_zod.tables.paymentRequest.id, params.ids) : void 0
|
|
330
364
|
);
|
|
331
365
|
const [paymentRequests, [{ value: totalCount }]] = await Promise.all([
|
|
332
|
-
db.select().from(
|
|
333
|
-
db.select({ value: drizzleOrm.count() }).from(
|
|
366
|
+
db.select().from(ott_zod.tables.paymentRequest).where(where).orderBy(orderDir(orderCol)).limit(limit).offset(offset),
|
|
367
|
+
db.select({ value: drizzleOrm.count() }).from(ott_zod.tables.paymentRequest).where(where)
|
|
334
368
|
]);
|
|
335
369
|
return { paymentRequests, totalCount };
|
|
336
370
|
};
|
|
@@ -357,40 +391,6 @@ function buildPaymentRequestEvent(pr) {
|
|
|
357
391
|
};
|
|
358
392
|
}
|
|
359
393
|
|
|
360
|
-
const sendPaymentInputSchema = zod.z.object({
|
|
361
|
-
correlationId: zod.z.string().min(1),
|
|
362
|
-
refId: zod.z.string().optional(),
|
|
363
|
-
amount: zod.z.number().positive(),
|
|
364
|
-
paymentType: zod.z.enum(database_schema.PAYMENT_TYPES),
|
|
365
|
-
chargeBearer: zod.z.enum(database_schema.CHARGE_BEARERS).optional(),
|
|
366
|
-
instructionPriority: zod.z.enum(database_schema.INSTRUCTION_PRIORITIES).optional(),
|
|
367
|
-
currency: zod.z.enum(generalCodes.CURRENCY_CODES),
|
|
368
|
-
vs: zod.z.string().optional(),
|
|
369
|
-
ss: zod.z.string().optional(),
|
|
370
|
-
ks: zod.z.string().optional(),
|
|
371
|
-
message: zod.z.string().optional(),
|
|
372
|
-
creditor: backendSdk.bankAccountMetadataSchema,
|
|
373
|
-
debtor: backendSdk.bankAccountMetadataSchema,
|
|
374
|
-
sendAsSinglePayment: zod.z.boolean().optional()
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
const sendBatchInputSchema = zod.z.object({
|
|
378
|
-
payments: zod.z.array(sendPaymentInputSchema).min(1)
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
const getAuthUriInputSchema = zod.z.object({
|
|
382
|
-
connectorKey: zod.z.enum(database_schema.CONNECTOR_KEYS)
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
const authorizeAccountInputSchema = zod.z.object({
|
|
386
|
-
ott: zod.z.string(),
|
|
387
|
-
urlParams: zod.z.string(),
|
|
388
|
-
syncIntervalS: zod.z.number().int().positive().optional(),
|
|
389
|
-
startSync: zod.z.boolean().optional(),
|
|
390
|
-
lastSyncAt: zod.z.date().optional(),
|
|
391
|
-
address: backendSdk.structuredAddressSchema.optional()
|
|
392
|
-
});
|
|
393
|
-
|
|
394
394
|
const simulateDepositInputSchema = zod.z.object({
|
|
395
395
|
amount: zod.z.number(),
|
|
396
396
|
currency: zod.z.enum(generalCodes.CURRENCY_CODES),
|
|
@@ -522,7 +522,7 @@ zod.z.object({
|
|
|
522
522
|
});
|
|
523
523
|
|
|
524
524
|
const updateAccountInputSchema = zod.z.object({
|
|
525
|
-
account:
|
|
525
|
+
account: ott_zod.accountInsertSchema
|
|
526
526
|
});
|
|
527
527
|
|
|
528
528
|
const getBankAccountsInputSchema = zod.z.object({
|
|
@@ -598,7 +598,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
598
598
|
// 14 days
|
|
599
599
|
this.COMPLETED_POLLING_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
600
600
|
this.allowedProviders = config.allowedProviders;
|
|
601
|
-
this.db = d1.drizzle(this.env.BANK_D1, { schema:
|
|
601
|
+
this.db = d1.drizzle(this.env.BANK_D1, { schema: ott_zod.tables, relations: ott_zod.relations });
|
|
602
602
|
}
|
|
603
603
|
async _getAccounts(filters) {
|
|
604
604
|
return await getAllAccountsQuery(this.db, filters);
|
|
@@ -634,7 +634,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
634
634
|
}));
|
|
635
635
|
resolveCredentials = await credentialsResolver.createCredentialsResolver(this.db, this.env);
|
|
636
636
|
}
|
|
637
|
-
return
|
|
637
|
+
return ott_zod.initiateConnector({
|
|
638
638
|
bank: connectorKey,
|
|
639
639
|
connectedAccounts,
|
|
640
640
|
resolveCredentials,
|
|
@@ -776,7 +776,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
776
776
|
await credentialsResolver.updatePaymentRequestStatusCommand(this.db, {
|
|
777
777
|
id: pr.id,
|
|
778
778
|
status: newStatus,
|
|
779
|
-
processedAt:
|
|
779
|
+
processedAt: ott_zod.isProcessedStatus(newStatus) ? /* @__PURE__ */ new Date() : void 0
|
|
780
780
|
}).command.execute();
|
|
781
781
|
statusChanged++;
|
|
782
782
|
eventsToEmit.push(
|
|
@@ -819,7 +819,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
819
819
|
return;
|
|
820
820
|
if (allPRs.length === 0) return;
|
|
821
821
|
const allTerminal = allPRs.every(
|
|
822
|
-
(pr) =>
|
|
822
|
+
(pr) => ott_zod.isTerminalStatus(pr.status)
|
|
823
823
|
);
|
|
824
824
|
const allAuthorizedOrHigher = allPRs.every((pr) => pr.status !== "OPENED");
|
|
825
825
|
if (allTerminal) {
|
|
@@ -840,7 +840,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
840
840
|
null,
|
|
841
841
|
{ successMessage: "Payment request statuses updated" },
|
|
842
842
|
async () => {
|
|
843
|
-
const nonTerminalPRs = await
|
|
843
|
+
const nonTerminalPRs = await ott_zod.getNonTerminalPaymentRequestsQuery(this.db);
|
|
844
844
|
if (nonTerminalPRs.length === 0) {
|
|
845
845
|
return { processed: 0, statusChanged: 0 };
|
|
846
846
|
}
|
|
@@ -1205,7 +1205,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
1205
1205
|
{ data: input, schema: sendPaymentInputSchema },
|
|
1206
1206
|
{ successMessage: "Payment initiated successfully" },
|
|
1207
1207
|
async (data) => {
|
|
1208
|
-
const incomingPayment =
|
|
1208
|
+
const incomingPayment = ott_zod.toIncomingPayment(data);
|
|
1209
1209
|
this._validatePaymentTypeAndCurrency(
|
|
1210
1210
|
data.paymentType,
|
|
1211
1211
|
data.currency,
|
|
@@ -1246,11 +1246,11 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
1246
1246
|
status: 422
|
|
1247
1247
|
});
|
|
1248
1248
|
}
|
|
1249
|
-
const accountAssigned =
|
|
1250
|
-
const batchedPayment =
|
|
1249
|
+
const accountAssigned = ott_zod.assignAccount(incomingPayment, account);
|
|
1250
|
+
const batchedPayment = ott_zod.toBatchedPayment(accountAssigned);
|
|
1251
1251
|
const { command: insertPaymentRequest } = createPaymentRequestCommand(
|
|
1252
1252
|
this.db,
|
|
1253
|
-
{ paymentRequest:
|
|
1253
|
+
{ paymentRequest: ott_zod.toPaymentRequestInsert(accountAssigned, null) }
|
|
1254
1254
|
);
|
|
1255
1255
|
await insertPaymentRequest.execute();
|
|
1256
1256
|
const initiate = () => {
|
|
@@ -1285,7 +1285,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
1285
1285
|
bankRefId: initiated.payment.bankRefId,
|
|
1286
1286
|
initiatedAt: initiated.payment.initiatedAt,
|
|
1287
1287
|
authorizationUrl: initiated.authorizationUrl,
|
|
1288
|
-
processedAt:
|
|
1288
|
+
processedAt: ott_zod.isProcessedStatus(initiated.payment.status) ? /* @__PURE__ */ new Date() : void 0
|
|
1289
1289
|
}).command.execute();
|
|
1290
1290
|
const paymentRequest = await getPaymentRequestByIdQuery(this.db, {
|
|
1291
1291
|
paymentRequestId: incomingPayment.id
|
|
@@ -1391,9 +1391,9 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
1391
1391
|
status: 422
|
|
1392
1392
|
});
|
|
1393
1393
|
}
|
|
1394
|
-
const incomingPayments = paymentInputs.map(
|
|
1394
|
+
const incomingPayments = paymentInputs.map(ott_zod.toIncomingPayment);
|
|
1395
1395
|
const batchedPayments = incomingPayments.map(
|
|
1396
|
-
(p) =>
|
|
1396
|
+
(p) => ott_zod.toBatchedPayment(ott_zod.assignAccount(p, account))
|
|
1397
1397
|
);
|
|
1398
1398
|
const batchId = backendSdk.uuidv4();
|
|
1399
1399
|
const batchMode = connector.supportsBatch(paymentType) ? "NATIVE" : "SINGLE";
|
|
@@ -1410,8 +1410,8 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
1410
1410
|
}).command;
|
|
1411
1411
|
const prCmds = incomingPayments.map(
|
|
1412
1412
|
(p) => createPaymentRequestCommand(this.db, {
|
|
1413
|
-
paymentRequest:
|
|
1414
|
-
|
|
1413
|
+
paymentRequest: ott_zod.toPaymentRequestInsert(
|
|
1414
|
+
ott_zod.assignAccount(p, account),
|
|
1415
1415
|
batchId
|
|
1416
1416
|
)
|
|
1417
1417
|
}).command
|
|
@@ -1460,7 +1460,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
1460
1460
|
bankRefId: pp.bankRefId,
|
|
1461
1461
|
initiatedAt: pp.initiatedAt,
|
|
1462
1462
|
authorizationUrl: isPerPaymentFallback ? authorizationUrls[i] : authorizationUrls[0],
|
|
1463
|
-
processedAt:
|
|
1463
|
+
processedAt: ott_zod.isProcessedStatus(pp.status) ? /* @__PURE__ */ new Date() : void 0
|
|
1464
1464
|
}).command
|
|
1465
1465
|
);
|
|
1466
1466
|
const updateBatchCmd = credentialsResolver.upsertBatchCommand(this.db, {
|
|
@@ -1549,11 +1549,11 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
1549
1549
|
if (includePendingPaymentRequestCount) {
|
|
1550
1550
|
const [row] = await this.db.select({
|
|
1551
1551
|
count: drizzleOrm.sql`count(*)`
|
|
1552
|
-
}).from(
|
|
1552
|
+
}).from(ott_zod.tables.paymentRequest).where(
|
|
1553
1553
|
drizzleOrm.and(
|
|
1554
|
-
drizzleOrm.eq(
|
|
1555
|
-
drizzleOrm.eq(
|
|
1556
|
-
drizzleOrm.isNull(
|
|
1554
|
+
drizzleOrm.eq(ott_zod.tables.paymentRequest.accountId, a.id),
|
|
1555
|
+
drizzleOrm.eq(ott_zod.tables.paymentRequest.status, "OPENED"),
|
|
1556
|
+
drizzleOrm.isNull(ott_zod.tables.paymentRequest.deletedAt)
|
|
1557
1557
|
)
|
|
1558
1558
|
);
|
|
1559
1559
|
result.pendingPaymentRequestCount = row?.count ?? 0;
|
|
@@ -1744,14 +1744,14 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
1744
1744
|
const privateKeyPem = (await this.env.SECRETS_STORE.get({
|
|
1745
1745
|
secretName: "BANK_SERVICE_FINBRICKS_PRIVATE_KEY_PEM"
|
|
1746
1746
|
})).data?.secretValue || "";
|
|
1747
|
-
const client = new
|
|
1747
|
+
const client = new ott_zod.FinbricksClient(
|
|
1748
1748
|
this.env.FINBRICKS_BASE_URI,
|
|
1749
1749
|
this.env.FINBRICKS_MERCHANT_ID,
|
|
1750
1750
|
privateKeyPem,
|
|
1751
1751
|
this.env.REDIRECT_URI
|
|
1752
1752
|
);
|
|
1753
1753
|
return client.request({
|
|
1754
|
-
endpoint:
|
|
1754
|
+
endpoint: ott_zod.FINBRICKS_ENDPOINTS.BANK_INFO,
|
|
1755
1755
|
method: "GET",
|
|
1756
1756
|
query: {
|
|
1757
1757
|
merchantId: this.env.FINBRICKS_MERCHANT_ID
|