@develit-services/bank 0.1.7 → 0.1.9
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 -1
- package/dist/database/schema.d.cts +1 -1
- package/dist/database/schema.d.mts +1 -1
- package/dist/database/schema.d.ts +1 -1
- package/dist/database/schema.mjs +1 -1
- package/dist/export/worker.cjs +13 -15
- package/dist/export/worker.d.cts +16 -17
- package/dist/export/worker.d.mts +16 -17
- package/dist/export/worker.d.ts +16 -17
- package/dist/export/worker.mjs +3 -5
- package/dist/export/workflows.cjs +160 -9
- package/dist/export/workflows.d.cts +10 -2
- package/dist/export/workflows.d.mts +10 -2
- package/dist/export/workflows.d.ts +10 -2
- package/dist/export/workflows.mjs +163 -8
- package/dist/shared/bank.-FurAs09.cjs +120 -0
- package/dist/shared/{bank.D2ZeOkyc.mjs → bank.BvXwHpBp.mjs} +1 -1
- package/dist/shared/{bank.DCTBX1dp.d.ts → bank.CRVH1wUH.d.cts} +7 -7
- package/dist/shared/{bank.CrRs_x0N.d.mts → bank.Ckn_klvT.d.ts} +7 -7
- package/dist/shared/{bank.BFGDv0oC.d.cts → bank.CsvBtQib.d.cts} +8 -8
- package/dist/shared/{bank.BFGDv0oC.d.mts → bank.CsvBtQib.d.mts} +8 -8
- package/dist/shared/{bank.BFGDv0oC.d.ts → bank.CsvBtQib.d.ts} +8 -8
- package/dist/shared/bank.DTdKHhGd.mjs +113 -0
- package/dist/shared/{bank.DSVzOCrh.d.cts → bank.DouutABZ.d.mts} +7 -7
- package/dist/shared/{bank.xIMAnZ4v.mjs → bank.W4h6Dlzi.mjs} +62 -2
- package/dist/shared/{bank.PDmcU0T-.cjs → bank.tLe0jhjo.cjs} +61 -1
- package/dist/shared/{bank.BcCfzRPi.cjs → bank.z4VxSea3.cjs} +1 -1
- package/dist/types.cjs +2 -2
- package/dist/types.d.cts +69 -5
- package/dist/types.d.mts +69 -5
- package/dist/types.d.ts +69 -5
- package/dist/types.mjs +2 -2
- package/package.json +1 -1
- package/dist/shared/bank.B3isylGM.cjs +0 -284
- package/dist/shared/bank.ChAGzUFo.d.cts +0 -18
- package/dist/shared/bank.ChAGzUFo.d.mts +0 -18
- package/dist/shared/bank.ChAGzUFo.d.ts +0 -18
- package/dist/shared/bank.JtGSu6eH.mjs +0 -275
|
@@ -1,21 +1,172 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
require('cloudflare:
|
|
5
|
-
require('
|
|
6
|
-
require('
|
|
7
|
-
require('
|
|
8
|
-
require('
|
|
3
|
+
const cloudflare_workers = require('cloudflare:workers');
|
|
4
|
+
const cloudflare_workflows = require('cloudflare:workflows');
|
|
5
|
+
const d1 = require('drizzle-orm/d1');
|
|
6
|
+
const database_schema = require('../shared/bank.tLe0jhjo.cjs');
|
|
7
|
+
const backendSdk = require('@develit-io/backend-sdk');
|
|
8
|
+
const bank = require('../shared/bank.-FurAs09.cjs');
|
|
9
|
+
const drizzleOrm = require('drizzle-orm');
|
|
9
10
|
require('drizzle-orm/sqlite-core');
|
|
10
11
|
require('date-fns');
|
|
11
|
-
require('drizzle-orm');
|
|
12
12
|
require('@develit-io/general-codes');
|
|
13
13
|
require('zod');
|
|
14
14
|
require('jose');
|
|
15
15
|
require('drizzle-zod');
|
|
16
16
|
require('drizzle-orm/relations');
|
|
17
|
-
require('../shared/bank.
|
|
17
|
+
require('../shared/bank.z4VxSea3.cjs');
|
|
18
18
|
|
|
19
|
+
const getAccountByIdQuery = async (db, { accountId }) => {
|
|
20
|
+
return await db.select().from(database_schema.tables.account).where(drizzleOrm.eq(database_schema.tables.account.id, accountId)).get();
|
|
21
|
+
};
|
|
19
22
|
|
|
23
|
+
function pushToQueue(queue, message) {
|
|
24
|
+
if (!Array.isArray(message)) return queue.send(message, { contentType: "v8" });
|
|
25
|
+
return queue.sendBatch(
|
|
26
|
+
message.map((m) => ({
|
|
27
|
+
body: m,
|
|
28
|
+
contentType: "v8"
|
|
29
|
+
}))
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
class SyncAccountPaymentsWorkflow extends cloudflare_workers.WorkflowEntrypoint {
|
|
33
|
+
async run(event, step) {
|
|
34
|
+
const { accountId } = event.payload;
|
|
35
|
+
const db = d1.drizzle(this.env.BANK_D1, { schema: database_schema.tables });
|
|
36
|
+
while (true) {
|
|
37
|
+
const account = await step.do("load account", async () => {
|
|
38
|
+
const account2 = await getAccountByIdQuery(db, { accountId });
|
|
39
|
+
if (!account2) {
|
|
40
|
+
throw new cloudflare_workflows.NonRetryableError(`Bank account not found: ${accountId}`);
|
|
41
|
+
}
|
|
42
|
+
return account2;
|
|
43
|
+
});
|
|
44
|
+
if (!account.lastSyncedAt) {
|
|
45
|
+
throw new Error(`lastSyncedAt is not set for account: ${accountId}`);
|
|
46
|
+
}
|
|
47
|
+
const credentials = await step.do(
|
|
48
|
+
"load account credentials",
|
|
49
|
+
async () => {
|
|
50
|
+
const credentials2 = await bank.getCredentialsByAccountId(db, { accountId });
|
|
51
|
+
if (!credentials2) {
|
|
52
|
+
throw new cloudflare_workflows.NonRetryableError(
|
|
53
|
+
`No credentials found for account: ${accountId}`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return credentials2;
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
const payments = await step.do(
|
|
60
|
+
"fetch bank payments",
|
|
61
|
+
{
|
|
62
|
+
retries: { limit: 5, delay: 2e3, backoff: "constant" },
|
|
63
|
+
timeout: "30 seconds"
|
|
64
|
+
},
|
|
65
|
+
async () => {
|
|
66
|
+
const connector = bank.initiateConnector({
|
|
67
|
+
env: this.env,
|
|
68
|
+
bank: account.connectorKey,
|
|
69
|
+
connectedAccounts: [
|
|
70
|
+
{
|
|
71
|
+
...account,
|
|
72
|
+
iban: account.iban,
|
|
73
|
+
token: credentials.value
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
const fetched = await connector.getAllAccountPayments({
|
|
78
|
+
environment: this.env.ENVIRONMENT,
|
|
79
|
+
db,
|
|
80
|
+
account,
|
|
81
|
+
filter: { dateFrom: account.lastSyncedAt }
|
|
82
|
+
});
|
|
83
|
+
return fetched.map((p) => ({
|
|
84
|
+
...p,
|
|
85
|
+
direction: database_schema.getPaymentDirection(p, account.iban)
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
if (payments.length) {
|
|
90
|
+
const bankRefIds = payments.map((payment) => payment.bankRefId).filter(Boolean);
|
|
91
|
+
const existing = await step.do("load existing payments", async () => {
|
|
92
|
+
return await bank.getPaymentsByBankRefIdsQuery(db, {
|
|
93
|
+
ids: bankRefIds
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
const paymentsToUpdate = payments.filter(
|
|
97
|
+
(p) => existing.some((e) => e.bankRefId === p.bankRefId)
|
|
98
|
+
);
|
|
99
|
+
const paymentsToCreate = payments.filter(
|
|
100
|
+
(p) => !existing.some((e) => e.bankRefId === p.bankRefId)
|
|
101
|
+
);
|
|
102
|
+
await step.do("process payments and update lastSyncAt", async () => {
|
|
103
|
+
const eventsToEmit = [];
|
|
104
|
+
const updateCommands = paymentsToUpdate.map(
|
|
105
|
+
(p) => bank.updatePaymentCommand(db, { payment: p }).command
|
|
106
|
+
);
|
|
107
|
+
eventsToEmit.push(
|
|
108
|
+
...paymentsToUpdate.map((p) => ({
|
|
109
|
+
eventType: "BANK_PAYMENT",
|
|
110
|
+
eventSignal: "paymentUpdated",
|
|
111
|
+
bankPayment: p,
|
|
112
|
+
metadata: {
|
|
113
|
+
correlationId: p.correlationId,
|
|
114
|
+
entityId: p.id,
|
|
115
|
+
idempotencySuffix: p.status,
|
|
116
|
+
timestamp: (/* @__PURE__ */ new Date()).toDateString()
|
|
117
|
+
}
|
|
118
|
+
}))
|
|
119
|
+
);
|
|
120
|
+
const createCommands = paymentsToCreate.map(
|
|
121
|
+
(p) => bank.createPaymentCommand(db, { payment: p }).command
|
|
122
|
+
);
|
|
123
|
+
eventsToEmit.push(
|
|
124
|
+
...paymentsToCreate.map((p) => ({
|
|
125
|
+
eventType: "BANK_PAYMENT",
|
|
126
|
+
eventSignal: "paymentCreated",
|
|
127
|
+
bankPayment: p,
|
|
128
|
+
metadata: {
|
|
129
|
+
correlationId: p.correlationId,
|
|
130
|
+
entityId: p.id,
|
|
131
|
+
timestamp: (/* @__PURE__ */ new Date()).toDateString()
|
|
132
|
+
}
|
|
133
|
+
}))
|
|
134
|
+
);
|
|
135
|
+
const latest = payments.reduce((current, p) => {
|
|
136
|
+
return new Date(p.processedAt).getTime() > new Date(current.processedAt).getTime() ? p : current;
|
|
137
|
+
}, payments[0]);
|
|
138
|
+
const updateLastSyncCommand = bank.updateAccountLastSyncCommand(db, {
|
|
139
|
+
accountId: account.id,
|
|
140
|
+
lastSyncedAt: latest.processedAt
|
|
141
|
+
}).command;
|
|
142
|
+
if (eventsToEmit.length) {
|
|
143
|
+
await db.batch(
|
|
144
|
+
backendSdk.asNonEmpty([
|
|
145
|
+
updateLastSyncCommand,
|
|
146
|
+
...updateCommands,
|
|
147
|
+
...createCommands
|
|
148
|
+
])
|
|
149
|
+
);
|
|
150
|
+
await pushToQueue(
|
|
151
|
+
this.env.QUEUE_BUS_QUEUE,
|
|
152
|
+
eventsToEmit
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
payments: payments.length,
|
|
157
|
+
updated: paymentsToUpdate.length,
|
|
158
|
+
created: paymentsToCreate.length,
|
|
159
|
+
eventsEmitted: eventsToEmit.length,
|
|
160
|
+
lastSyncedAt: latest?.createdAt
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
await step.sleep(
|
|
165
|
+
"Sleep for next sync",
|
|
166
|
+
`${account.syncIntervalS} seconds`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
20
171
|
|
|
21
|
-
exports.SyncAccountPaymentsWorkflow =
|
|
172
|
+
exports.SyncAccountPaymentsWorkflow = SyncAccountPaymentsWorkflow;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from 'cloudflare:workers';
|
|
2
|
+
|
|
3
|
+
type Params = {
|
|
4
|
+
accountId: string;
|
|
5
|
+
};
|
|
6
|
+
declare class SyncAccountPaymentsWorkflow extends WorkflowEntrypoint<BankEnv, Params> {
|
|
7
|
+
run(event: WorkflowEvent<Params>, step: WorkflowStep): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { SyncAccountPaymentsWorkflow };
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from 'cloudflare:workers';
|
|
2
|
+
|
|
3
|
+
type Params = {
|
|
4
|
+
accountId: string;
|
|
5
|
+
};
|
|
6
|
+
declare class SyncAccountPaymentsWorkflow extends WorkflowEntrypoint<BankEnv, Params> {
|
|
7
|
+
run(event: WorkflowEvent<Params>, step: WorkflowStep): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { SyncAccountPaymentsWorkflow };
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from 'cloudflare:workers';
|
|
2
|
+
|
|
3
|
+
type Params = {
|
|
4
|
+
accountId: string;
|
|
5
|
+
};
|
|
6
|
+
declare class SyncAccountPaymentsWorkflow extends WorkflowEntrypoint<BankEnv, Params> {
|
|
7
|
+
run(event: WorkflowEvent<Params>, step: WorkflowStep): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { SyncAccountPaymentsWorkflow };
|
|
@@ -1,15 +1,170 @@
|
|
|
1
|
-
|
|
2
|
-
import 'cloudflare:
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
5
|
-
import '
|
|
6
|
-
import '
|
|
1
|
+
import { WorkflowEntrypoint } from 'cloudflare:workers';
|
|
2
|
+
import { NonRetryableError } from 'cloudflare:workflows';
|
|
3
|
+
import { drizzle } from 'drizzle-orm/d1';
|
|
4
|
+
import { t as tables, v as getPaymentDirection } from '../shared/bank.W4h6Dlzi.mjs';
|
|
5
|
+
import { asNonEmpty } from '@develit-io/backend-sdk';
|
|
6
|
+
import { g as getCredentialsByAccountId, i as initiateConnector, a as getPaymentsByBankRefIdsQuery, u as updatePaymentCommand, c as createPaymentCommand, b as updateAccountLastSyncCommand } from '../shared/bank.DTdKHhGd.mjs';
|
|
7
|
+
import { eq } from 'drizzle-orm';
|
|
7
8
|
import 'drizzle-orm/sqlite-core';
|
|
8
9
|
import 'date-fns';
|
|
9
|
-
import 'drizzle-orm';
|
|
10
10
|
import '@develit-io/general-codes';
|
|
11
11
|
import 'zod';
|
|
12
12
|
import 'jose';
|
|
13
13
|
import 'drizzle-zod';
|
|
14
14
|
import 'drizzle-orm/relations';
|
|
15
|
-
import '../shared/bank.
|
|
15
|
+
import '../shared/bank.BvXwHpBp.mjs';
|
|
16
|
+
|
|
17
|
+
const getAccountByIdQuery = async (db, { accountId }) => {
|
|
18
|
+
return await db.select().from(tables.account).where(eq(tables.account.id, accountId)).get();
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function pushToQueue(queue, message) {
|
|
22
|
+
if (!Array.isArray(message)) return queue.send(message, { contentType: "v8" });
|
|
23
|
+
return queue.sendBatch(
|
|
24
|
+
message.map((m) => ({
|
|
25
|
+
body: m,
|
|
26
|
+
contentType: "v8"
|
|
27
|
+
}))
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
class SyncAccountPaymentsWorkflow extends WorkflowEntrypoint {
|
|
31
|
+
async run(event, step) {
|
|
32
|
+
const { accountId } = event.payload;
|
|
33
|
+
const db = drizzle(this.env.BANK_D1, { schema: tables });
|
|
34
|
+
while (true) {
|
|
35
|
+
const account = await step.do("load account", async () => {
|
|
36
|
+
const account2 = await getAccountByIdQuery(db, { accountId });
|
|
37
|
+
if (!account2) {
|
|
38
|
+
throw new NonRetryableError(`Bank account not found: ${accountId}`);
|
|
39
|
+
}
|
|
40
|
+
return account2;
|
|
41
|
+
});
|
|
42
|
+
if (!account.lastSyncedAt) {
|
|
43
|
+
throw new Error(`lastSyncedAt is not set for account: ${accountId}`);
|
|
44
|
+
}
|
|
45
|
+
const credentials = await step.do(
|
|
46
|
+
"load account credentials",
|
|
47
|
+
async () => {
|
|
48
|
+
const credentials2 = await getCredentialsByAccountId(db, { accountId });
|
|
49
|
+
if (!credentials2) {
|
|
50
|
+
throw new NonRetryableError(
|
|
51
|
+
`No credentials found for account: ${accountId}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return credentials2;
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
const payments = await step.do(
|
|
58
|
+
"fetch bank payments",
|
|
59
|
+
{
|
|
60
|
+
retries: { limit: 5, delay: 2e3, backoff: "constant" },
|
|
61
|
+
timeout: "30 seconds"
|
|
62
|
+
},
|
|
63
|
+
async () => {
|
|
64
|
+
const connector = initiateConnector({
|
|
65
|
+
env: this.env,
|
|
66
|
+
bank: account.connectorKey,
|
|
67
|
+
connectedAccounts: [
|
|
68
|
+
{
|
|
69
|
+
...account,
|
|
70
|
+
iban: account.iban,
|
|
71
|
+
token: credentials.value
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
const fetched = await connector.getAllAccountPayments({
|
|
76
|
+
environment: this.env.ENVIRONMENT,
|
|
77
|
+
db,
|
|
78
|
+
account,
|
|
79
|
+
filter: { dateFrom: account.lastSyncedAt }
|
|
80
|
+
});
|
|
81
|
+
return fetched.map((p) => ({
|
|
82
|
+
...p,
|
|
83
|
+
direction: getPaymentDirection(p, account.iban)
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
if (payments.length) {
|
|
88
|
+
const bankRefIds = payments.map((payment) => payment.bankRefId).filter(Boolean);
|
|
89
|
+
const existing = await step.do("load existing payments", async () => {
|
|
90
|
+
return await getPaymentsByBankRefIdsQuery(db, {
|
|
91
|
+
ids: bankRefIds
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
const paymentsToUpdate = payments.filter(
|
|
95
|
+
(p) => existing.some((e) => e.bankRefId === p.bankRefId)
|
|
96
|
+
);
|
|
97
|
+
const paymentsToCreate = payments.filter(
|
|
98
|
+
(p) => !existing.some((e) => e.bankRefId === p.bankRefId)
|
|
99
|
+
);
|
|
100
|
+
await step.do("process payments and update lastSyncAt", async () => {
|
|
101
|
+
const eventsToEmit = [];
|
|
102
|
+
const updateCommands = paymentsToUpdate.map(
|
|
103
|
+
(p) => updatePaymentCommand(db, { payment: p }).command
|
|
104
|
+
);
|
|
105
|
+
eventsToEmit.push(
|
|
106
|
+
...paymentsToUpdate.map((p) => ({
|
|
107
|
+
eventType: "BANK_PAYMENT",
|
|
108
|
+
eventSignal: "paymentUpdated",
|
|
109
|
+
bankPayment: p,
|
|
110
|
+
metadata: {
|
|
111
|
+
correlationId: p.correlationId,
|
|
112
|
+
entityId: p.id,
|
|
113
|
+
idempotencySuffix: p.status,
|
|
114
|
+
timestamp: (/* @__PURE__ */ new Date()).toDateString()
|
|
115
|
+
}
|
|
116
|
+
}))
|
|
117
|
+
);
|
|
118
|
+
const createCommands = paymentsToCreate.map(
|
|
119
|
+
(p) => createPaymentCommand(db, { payment: p }).command
|
|
120
|
+
);
|
|
121
|
+
eventsToEmit.push(
|
|
122
|
+
...paymentsToCreate.map((p) => ({
|
|
123
|
+
eventType: "BANK_PAYMENT",
|
|
124
|
+
eventSignal: "paymentCreated",
|
|
125
|
+
bankPayment: p,
|
|
126
|
+
metadata: {
|
|
127
|
+
correlationId: p.correlationId,
|
|
128
|
+
entityId: p.id,
|
|
129
|
+
timestamp: (/* @__PURE__ */ new Date()).toDateString()
|
|
130
|
+
}
|
|
131
|
+
}))
|
|
132
|
+
);
|
|
133
|
+
const latest = payments.reduce((current, p) => {
|
|
134
|
+
return new Date(p.processedAt).getTime() > new Date(current.processedAt).getTime() ? p : current;
|
|
135
|
+
}, payments[0]);
|
|
136
|
+
const updateLastSyncCommand = updateAccountLastSyncCommand(db, {
|
|
137
|
+
accountId: account.id,
|
|
138
|
+
lastSyncedAt: latest.processedAt
|
|
139
|
+
}).command;
|
|
140
|
+
if (eventsToEmit.length) {
|
|
141
|
+
await db.batch(
|
|
142
|
+
asNonEmpty([
|
|
143
|
+
updateLastSyncCommand,
|
|
144
|
+
...updateCommands,
|
|
145
|
+
...createCommands
|
|
146
|
+
])
|
|
147
|
+
);
|
|
148
|
+
await pushToQueue(
|
|
149
|
+
this.env.QUEUE_BUS_QUEUE,
|
|
150
|
+
eventsToEmit
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
payments: payments.length,
|
|
155
|
+
updated: paymentsToUpdate.length,
|
|
156
|
+
created: paymentsToCreate.length,
|
|
157
|
+
eventsEmitted: eventsToEmit.length,
|
|
158
|
+
lastSyncedAt: latest?.createdAt
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
await step.sleep(
|
|
163
|
+
"Sleep for next sync",
|
|
164
|
+
`${account.syncIntervalS} seconds`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { SyncAccountPaymentsWorkflow };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const database_schema = require('./bank.tLe0jhjo.cjs');
|
|
4
|
+
const drizzleOrm = require('drizzle-orm');
|
|
5
|
+
const mockCobs_connector = require('./bank.z4VxSea3.cjs');
|
|
6
|
+
require('jose');
|
|
7
|
+
require('@develit-io/general-codes');
|
|
8
|
+
|
|
9
|
+
const createPaymentCommand = (db, { payment }) => {
|
|
10
|
+
return {
|
|
11
|
+
command: db.insert(database_schema.tables.payment).values({
|
|
12
|
+
...payment,
|
|
13
|
+
creditorIban: payment.creditor.iban,
|
|
14
|
+
debtorIban: payment.debtor.iban
|
|
15
|
+
}).returning()
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const updatePaymentCommand = (db, { payment }) => {
|
|
20
|
+
return {
|
|
21
|
+
command: db.update(database_schema.tables.payment).set(payment).where(drizzleOrm.eq(database_schema.tables.payment.id, payment.id)).returning()
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const updateAccountLastSyncCommand = (db, { lastSyncedAt, accountId }) => {
|
|
26
|
+
const command = db.update(database_schema.tables.account).set({
|
|
27
|
+
lastSyncedAt
|
|
28
|
+
}).where(drizzleOrm.eq(database_schema.tables.account.id, accountId)).returning();
|
|
29
|
+
return {
|
|
30
|
+
command
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getCredentialsByAccountId = async (db, { accountId }) => {
|
|
35
|
+
const cred = await db.select().from(database_schema.tables.accountCredentials).where(drizzleOrm.eq(database_schema.tables.accountCredentials.accountId, accountId)).get();
|
|
36
|
+
return cred;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const getPaymentsByBankRefIdsQuery = async (db, { ids }) => {
|
|
40
|
+
return await db.select().from(database_schema.tables.payment).where(drizzleOrm.inArray(database_schema.tables.payment.bankRefId, ids));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
class CreditasConnector extends database_schema.FinbricksConnector {
|
|
44
|
+
constructor(config) {
|
|
45
|
+
super("CREDITAS", config);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class FioConnector extends database_schema.FinbricksConnector {
|
|
50
|
+
constructor(config) {
|
|
51
|
+
super("FIO", config);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
class MonetaConnector extends database_schema.FinbricksConnector {
|
|
56
|
+
constructor(config) {
|
|
57
|
+
super("MONETA", config);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const initiateConnector = ({
|
|
62
|
+
bank,
|
|
63
|
+
env,
|
|
64
|
+
connectedAccounts
|
|
65
|
+
}) => {
|
|
66
|
+
switch (bank) {
|
|
67
|
+
case "ERSTE":
|
|
68
|
+
return new database_schema.ErsteConnector({
|
|
69
|
+
API_KEY: env.ERSTE_API_KEY,
|
|
70
|
+
CLIENT_ID: env.ERSTE_CLIENT_ID,
|
|
71
|
+
CLIENT_SECRET: env.ERSTE_CLIENT_SECRET,
|
|
72
|
+
REDIRECT_URI: env.REDIRECT_URI,
|
|
73
|
+
AUTH_URI: env.ERSTE_AUTH_URI,
|
|
74
|
+
PAYMENTS_URI: env.ERSTE_PAYMENTS_URI,
|
|
75
|
+
ACCOUNTS_URI: env.ERSTE_ACCOUNTS_URI,
|
|
76
|
+
connectedAccounts
|
|
77
|
+
});
|
|
78
|
+
case "CREDITAS":
|
|
79
|
+
return new CreditasConnector({
|
|
80
|
+
BASE_URI: env.FINBRICKS_BASE_URI,
|
|
81
|
+
MERCHANT_ID: env.FINBRICKS_MERCHANT_ID,
|
|
82
|
+
PRIVATE_KEY_PEM: env.FINBRICKS_PRIVATE_KEY_PEM,
|
|
83
|
+
REDIRECT_URI: env.REDIRECT_URI,
|
|
84
|
+
connectedAccounts
|
|
85
|
+
});
|
|
86
|
+
case "MOCK_COBS":
|
|
87
|
+
return new mockCobs_connector.MockCobsConnector({
|
|
88
|
+
BASE_URI: env.FINBRICKS_BASE_URI,
|
|
89
|
+
MERCHANT_ID: env.FINBRICKS_MERCHANT_ID,
|
|
90
|
+
PRIVATE_KEY_PEM: env.FINBRICKS_PRIVATE_KEY_PEM,
|
|
91
|
+
REDIRECT_URI: env.REDIRECT_URI,
|
|
92
|
+
connectedAccounts
|
|
93
|
+
});
|
|
94
|
+
case "FIO":
|
|
95
|
+
return new FioConnector({
|
|
96
|
+
BASE_URI: env.FINBRICKS_BASE_URI,
|
|
97
|
+
MERCHANT_ID: env.FINBRICKS_MERCHANT_ID,
|
|
98
|
+
PRIVATE_KEY_PEM: env.FINBRICKS_PRIVATE_KEY_PEM,
|
|
99
|
+
REDIRECT_URI: env.REDIRECT_URI,
|
|
100
|
+
connectedAccounts
|
|
101
|
+
});
|
|
102
|
+
case "MONETA":
|
|
103
|
+
return new MonetaConnector({
|
|
104
|
+
BASE_URI: env.FINBRICKS_BASE_URI,
|
|
105
|
+
MERCHANT_ID: env.FINBRICKS_MERCHANT_ID,
|
|
106
|
+
PRIVATE_KEY_PEM: env.FINBRICKS_PRIVATE_KEY_PEM,
|
|
107
|
+
REDIRECT_URI: env.REDIRECT_URI,
|
|
108
|
+
connectedAccounts
|
|
109
|
+
});
|
|
110
|
+
default:
|
|
111
|
+
return new database_schema.MockConnector();
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
exports.createPaymentCommand = createPaymentCommand;
|
|
116
|
+
exports.getCredentialsByAccountId = getCredentialsByAccountId;
|
|
117
|
+
exports.getPaymentsByBankRefIdsQuery = getPaymentsByBankRefIdsQuery;
|
|
118
|
+
exports.initiateConnector = initiateConnector;
|
|
119
|
+
exports.updateAccountLastSyncCommand = updateAccountLastSyncCommand;
|
|
120
|
+
exports.updatePaymentCommand = updatePaymentCommand;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Environment } from '@develit-io/backend-sdk';
|
|
2
2
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
3
|
-
import { a as PaymentInsertType, t as tables } from './bank.
|
|
3
|
+
import { a as PaymentInsertType, t as tables } from './bank.CsvBtQib.cjs';
|
|
4
4
|
import { CURRENCY_CODES, BANK_CODES, CODES } from '@develit-io/general-codes';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import * as drizzle_zod from 'drizzle-zod';
|
|
@@ -171,14 +171,14 @@ declare const accountInsertSchema: drizzle_zod.BuildSchema<"insert", {
|
|
|
171
171
|
tableName: "account";
|
|
172
172
|
dataType: "string";
|
|
173
173
|
columnType: "SQLiteText";
|
|
174
|
-
data:
|
|
174
|
+
data: "5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500";
|
|
175
175
|
driverParam: string;
|
|
176
176
|
notNull: true;
|
|
177
177
|
hasDefault: false;
|
|
178
178
|
isPrimaryKey: false;
|
|
179
179
|
isAutoincrement: false;
|
|
180
180
|
hasRuntimeDefault: false;
|
|
181
|
-
enumValues: [
|
|
181
|
+
enumValues: ["5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500", ...("5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500")[]];
|
|
182
182
|
baseColumn: never;
|
|
183
183
|
identity: undefined;
|
|
184
184
|
generated: undefined;
|
|
@@ -619,14 +619,14 @@ declare const accountUpdateSchema: drizzle_zod.BuildSchema<"update", {
|
|
|
619
619
|
tableName: "account";
|
|
620
620
|
dataType: "string";
|
|
621
621
|
columnType: "SQLiteText";
|
|
622
|
-
data:
|
|
622
|
+
data: "5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500";
|
|
623
623
|
driverParam: string;
|
|
624
624
|
notNull: true;
|
|
625
625
|
hasDefault: false;
|
|
626
626
|
isPrimaryKey: false;
|
|
627
627
|
isAutoincrement: false;
|
|
628
628
|
hasRuntimeDefault: false;
|
|
629
|
-
enumValues: [
|
|
629
|
+
enumValues: ["5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500", ...("5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500")[]];
|
|
630
630
|
baseColumn: never;
|
|
631
631
|
identity: undefined;
|
|
632
632
|
generated: undefined;
|
|
@@ -1067,14 +1067,14 @@ declare const accountSelectSchema: drizzle_zod.BuildSchema<"select", {
|
|
|
1067
1067
|
tableName: "account";
|
|
1068
1068
|
dataType: "string";
|
|
1069
1069
|
columnType: "SQLiteText";
|
|
1070
|
-
data:
|
|
1070
|
+
data: "5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500";
|
|
1071
1071
|
driverParam: string;
|
|
1072
1072
|
notNull: true;
|
|
1073
1073
|
hasDefault: false;
|
|
1074
1074
|
isPrimaryKey: false;
|
|
1075
1075
|
isAutoincrement: false;
|
|
1076
1076
|
hasRuntimeDefault: false;
|
|
1077
|
-
enumValues: [
|
|
1077
|
+
enumValues: ["5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500", ...("5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500")[]];
|
|
1078
1078
|
baseColumn: never;
|
|
1079
1079
|
identity: undefined;
|
|
1080
1080
|
generated: undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Environment } from '@develit-io/backend-sdk';
|
|
2
2
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
3
|
-
import { a as PaymentInsertType, t as tables } from './bank.
|
|
3
|
+
import { a as PaymentInsertType, t as tables } from './bank.CsvBtQib.js';
|
|
4
4
|
import { CURRENCY_CODES, BANK_CODES, CODES } from '@develit-io/general-codes';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import * as drizzle_zod from 'drizzle-zod';
|
|
@@ -171,14 +171,14 @@ declare const accountInsertSchema: drizzle_zod.BuildSchema<"insert", {
|
|
|
171
171
|
tableName: "account";
|
|
172
172
|
dataType: "string";
|
|
173
173
|
columnType: "SQLiteText";
|
|
174
|
-
data:
|
|
174
|
+
data: "5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500";
|
|
175
175
|
driverParam: string;
|
|
176
176
|
notNull: true;
|
|
177
177
|
hasDefault: false;
|
|
178
178
|
isPrimaryKey: false;
|
|
179
179
|
isAutoincrement: false;
|
|
180
180
|
hasRuntimeDefault: false;
|
|
181
|
-
enumValues: [
|
|
181
|
+
enumValues: ["5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500", ...("5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500")[]];
|
|
182
182
|
baseColumn: never;
|
|
183
183
|
identity: undefined;
|
|
184
184
|
generated: undefined;
|
|
@@ -619,14 +619,14 @@ declare const accountUpdateSchema: drizzle_zod.BuildSchema<"update", {
|
|
|
619
619
|
tableName: "account";
|
|
620
620
|
dataType: "string";
|
|
621
621
|
columnType: "SQLiteText";
|
|
622
|
-
data:
|
|
622
|
+
data: "5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500";
|
|
623
623
|
driverParam: string;
|
|
624
624
|
notNull: true;
|
|
625
625
|
hasDefault: false;
|
|
626
626
|
isPrimaryKey: false;
|
|
627
627
|
isAutoincrement: false;
|
|
628
628
|
hasRuntimeDefault: false;
|
|
629
|
-
enumValues: [
|
|
629
|
+
enumValues: ["5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500", ...("5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500")[]];
|
|
630
630
|
baseColumn: never;
|
|
631
631
|
identity: undefined;
|
|
632
632
|
generated: undefined;
|
|
@@ -1067,14 +1067,14 @@ declare const accountSelectSchema: drizzle_zod.BuildSchema<"select", {
|
|
|
1067
1067
|
tableName: "account";
|
|
1068
1068
|
dataType: "string";
|
|
1069
1069
|
columnType: "SQLiteText";
|
|
1070
|
-
data:
|
|
1070
|
+
data: "5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500";
|
|
1071
1071
|
driverParam: string;
|
|
1072
1072
|
notNull: true;
|
|
1073
1073
|
hasDefault: false;
|
|
1074
1074
|
isPrimaryKey: false;
|
|
1075
1075
|
isAutoincrement: false;
|
|
1076
1076
|
hasRuntimeDefault: false;
|
|
1077
|
-
enumValues: [
|
|
1077
|
+
enumValues: ["5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500", ...("5051" | "0100" | "0300" | "0600" | "0710" | "0800" | "2010" | "2060" | "2070" | "2100" | "2200" | "2220" | "2250" | "2260" | "2600" | "2700" | "3030" | "3060" | "3500" | "4300" | "5500" | "5800" | "6000" | "6200" | "6210" | "6300" | "6363" | "6700" | "6800" | "7910" | "7950" | "7960" | "7970" | "7990" | "8030" | "8040" | "8060" | "8090" | "8150" | "8190" | "8198" | "8220" | "8250" | "8255" | "8265" | "8500")[]];
|
|
1078
1078
|
baseColumn: never;
|
|
1079
1079
|
identity: undefined;
|
|
1080
1080
|
generated: undefined;
|