@develit-services/bank 0.0.31 → 0.0.32
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 -2
- 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 -2
- package/dist/export/worker.cjs +58 -69
- package/dist/export/worker.d.cts +21 -10
- package/dist/export/worker.d.mts +21 -10
- package/dist/export/worker.d.ts +21 -10
- package/dist/export/worker.mjs +59 -66
- package/dist/shared/{bank.D8o86NLF.d.mts → bank.-qiBc98X.d.mts} +63 -11
- package/dist/shared/{bank.DbNuuGvb.mjs → bank.A5zjotaU.mjs} +1 -1
- package/dist/shared/{bank.CtUeOz8i.d.ts → bank.BRiDHyNf.d.ts} +63 -11
- package/dist/shared/{bank.DuY4d2y_.cjs → bank.BiZtZWed.cjs} +1 -1
- package/dist/shared/{bank.BMRBXGF1.cjs → bank.Dx7kRjFL.cjs} +18 -10
- package/dist/shared/{bank.DUalSuEK.d.cts → bank._5C74-4K.d.cts} +63 -11
- package/dist/shared/{bank.Nf6oaNfB.d.cts → bank.e_XSg9KV.d.cts} +25 -6
- package/dist/shared/{bank.Nf6oaNfB.d.mts → bank.e_XSg9KV.d.mts} +25 -6
- package/dist/shared/{bank.Nf6oaNfB.d.ts → bank.e_XSg9KV.d.ts} +25 -6
- package/dist/shared/{bank.YCUhOduX.mjs → bank.uJ3YtInA.mjs} +18 -10
- package/dist/types.cjs +2 -3
- package/dist/types.d.cts +66 -68
- package/dist/types.d.mts +66 -68
- package/dist/types.d.ts +66 -68
- package/dist/types.mjs +2 -3
- package/package.json +1 -1
package/dist/export/worker.mjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { uuidv4,
|
|
2
|
-
import { t as tables, F as FinbricksConnector, M as MockConnector, E as ErsteConnector, P as PAYMENT_TYPES, e as CONNECTOR_KEYS, c as PAYMENT_STATUSES, d as PAYMENT_DIRECTIONS, q as getPaymentDirection } from '../shared/bank.
|
|
1
|
+
import { uuidv4, develitWorker, createInternalError, first, RPCResponse, action, service } from '@develit-io/backend-sdk';
|
|
2
|
+
import { t as tables, F as FinbricksConnector, M as MockConnector, E as ErsteConnector, P as PAYMENT_TYPES, e as CONNECTOR_KEYS, c as PAYMENT_STATUSES, d as PAYMENT_DIRECTIONS, q as getPaymentDirection } from '../shared/bank.uJ3YtInA.mjs';
|
|
3
3
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
4
4
|
import { drizzle } from 'drizzle-orm/d1';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { CURRENCY_CODES } from '@develit-io/general-codes';
|
|
7
7
|
import 'jose';
|
|
8
8
|
import { eq, and, inArray, sql, asc, desc, gte, lte } from 'drizzle-orm';
|
|
9
|
-
import { M as MockCobsConnector } from '../shared/bank.
|
|
10
|
-
import superjson from 'superjson';
|
|
9
|
+
import { M as MockCobsConnector } from '../shared/bank.A5zjotaU.mjs';
|
|
11
10
|
import 'drizzle-zod';
|
|
12
11
|
import 'drizzle-orm/sqlite-core';
|
|
13
12
|
import 'date-fns';
|
|
@@ -99,6 +98,15 @@ const deleteAccountCredentialsCommand = (db, { accountId }) => {
|
|
|
99
98
|
};
|
|
100
99
|
};
|
|
101
100
|
|
|
101
|
+
const updateAccountLastSyncCommand = (db, { lastSyncedAt, accountId }) => {
|
|
102
|
+
const command = db.update(tables.account).set({
|
|
103
|
+
lastSyncedAt
|
|
104
|
+
}).where(eq(tables.account.id, accountId)).returning();
|
|
105
|
+
return {
|
|
106
|
+
command
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
102
110
|
const getPaymentByRefIdQuery = async (db, { refId }) => {
|
|
103
111
|
const payment = await db.select().from(tables.payment).where(eq(tables.payment.refId, refId)).limit(1).get();
|
|
104
112
|
return payment;
|
|
@@ -132,6 +140,10 @@ const getAllPendingBatchesQuery = (db) => {
|
|
|
132
140
|
);
|
|
133
141
|
};
|
|
134
142
|
|
|
143
|
+
const getAccountByIdQuery = async (db, { accountId }) => {
|
|
144
|
+
return await db.select().from(tables.account).where(eq(tables.account.id, accountId)).get();
|
|
145
|
+
};
|
|
146
|
+
|
|
135
147
|
const getCredentialsByAccountId = async (db, { accountId }) => {
|
|
136
148
|
const cred = await db.select().from(tables.accountCredentials).where(eq(tables.accountCredentials.accountId, accountId)).get();
|
|
137
149
|
return cred;
|
|
@@ -290,35 +302,6 @@ const initiateConnector = ({
|
|
|
290
302
|
}
|
|
291
303
|
};
|
|
292
304
|
|
|
293
|
-
const useSync = (kv) => {
|
|
294
|
-
const getLastSync = async ({
|
|
295
|
-
account
|
|
296
|
-
}) => {
|
|
297
|
-
const [rawSync, rawSyncError] = await useResult(
|
|
298
|
-
kv.get(`sync-log:${account.iban}:${account.currency}`)
|
|
299
|
-
);
|
|
300
|
-
if (rawSyncError) throw createInternalError(rawSyncError);
|
|
301
|
-
if (!rawSync) return null;
|
|
302
|
-
return superjson.parse(rawSync);
|
|
303
|
-
};
|
|
304
|
-
const setLastSync = async ({
|
|
305
|
-
account,
|
|
306
|
-
log
|
|
307
|
-
}) => {
|
|
308
|
-
const [_, error] = await useResult(
|
|
309
|
-
kv.put(
|
|
310
|
-
`sync-log:${account.iban}:${account.currency}`,
|
|
311
|
-
superjson.stringify(log)
|
|
312
|
-
)
|
|
313
|
-
);
|
|
314
|
-
if (error) throw error;
|
|
315
|
-
};
|
|
316
|
-
return {
|
|
317
|
-
getLastSync,
|
|
318
|
-
setLastSync
|
|
319
|
-
};
|
|
320
|
-
};
|
|
321
|
-
|
|
322
305
|
const seperateSupportedPayments = (mappedPayments, accounts) => {
|
|
323
306
|
const [supportedPayments, unsupportedPayments] = mappedPayments.reduce(
|
|
324
307
|
([valid, invalid], payment) => {
|
|
@@ -425,6 +408,10 @@ const getPaymentsInputSchema = z.object({
|
|
|
425
408
|
[ALLOWED_PAYMENT_FILTERS.STATUS]: z.union([z.enum(PAYMENT_STATUSES), z.enum(PAYMENT_STATUSES).array()]).optional()
|
|
426
409
|
});
|
|
427
410
|
|
|
411
|
+
const syncAccountInputSchema = z.object({
|
|
412
|
+
accountId: z.uuid()
|
|
413
|
+
});
|
|
414
|
+
|
|
428
415
|
var __defProp = Object.defineProperty;
|
|
429
416
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
430
417
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
@@ -469,35 +456,46 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
469
456
|
return 0;
|
|
470
457
|
}
|
|
471
458
|
}
|
|
472
|
-
async
|
|
459
|
+
async syncAccount(input) {
|
|
460
|
+
return this.handleAction(
|
|
461
|
+
{ data: input, schema: syncAccountInputSchema },
|
|
462
|
+
{ successMessage: "" },
|
|
463
|
+
async ({ accountId }) => {
|
|
464
|
+
const account = await getAccountByIdQuery(this.db, {
|
|
465
|
+
accountId
|
|
466
|
+
});
|
|
467
|
+
if (!account)
|
|
468
|
+
throw createInternalError(null, {
|
|
469
|
+
code: "NOT_FOUND",
|
|
470
|
+
message: "Account not found",
|
|
471
|
+
status: 404
|
|
472
|
+
});
|
|
473
|
+
await this.syncAccounts({
|
|
474
|
+
accounts: [account]
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
async syncAccounts(options) {
|
|
473
480
|
return this.handleAction(null, {}, async () => {
|
|
474
481
|
const accountsToSync = [];
|
|
475
|
-
|
|
476
|
-
|
|
482
|
+
let accounts = options?.accounts || [];
|
|
483
|
+
if (!accounts.length) {
|
|
484
|
+
accounts = await this.getAccounts();
|
|
485
|
+
}
|
|
477
486
|
for (const account of accounts.filter(
|
|
478
487
|
(acc) => !!!acc.connectorKey.includes("MOCK")
|
|
479
488
|
)) {
|
|
480
|
-
let lastSync = await getLastSync({ account: { ...account, token: "" } });
|
|
481
|
-
if (!lastSync) {
|
|
482
|
-
await this.setLastSyncAt({
|
|
483
|
-
iban: account.iban,
|
|
484
|
-
lastSyncedAt: account.lastSyncedAt || /* @__PURE__ */ new Date()
|
|
485
|
-
});
|
|
486
|
-
lastSync = await getLastSync({ account: { ...account, token: "" } });
|
|
487
|
-
if (!lastSync) continue;
|
|
488
|
-
}
|
|
489
489
|
const accountFetchInterval = this.accountFetchInterval(
|
|
490
490
|
account.connectorKey
|
|
491
491
|
);
|
|
492
492
|
const now = Date.now();
|
|
493
|
-
const lastSyncTime =
|
|
493
|
+
const lastSyncTime = account.lastSyncedAt.getTime();
|
|
494
494
|
const intervalMs = accountFetchInterval * 1e3;
|
|
495
495
|
const shouldFetch = now - lastSyncTime >= intervalMs;
|
|
496
496
|
if (!shouldFetch) continue;
|
|
497
497
|
accountsToSync.push({
|
|
498
|
-
...account
|
|
499
|
-
lastSyncAt: lastSync,
|
|
500
|
-
token: ""
|
|
498
|
+
...account
|
|
501
499
|
});
|
|
502
500
|
}
|
|
503
501
|
console.log("ACCS TO SYNC", accountsToSync.length);
|
|
@@ -933,7 +931,6 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
933
931
|
);
|
|
934
932
|
}
|
|
935
933
|
async saveOrUpdatePayments(accounts) {
|
|
936
|
-
const { setLastSync } = useSync(this.env.BANK_KV);
|
|
937
934
|
return this.handleAction(null, {}, async () => {
|
|
938
935
|
const allFetchedPayments = [];
|
|
939
936
|
const connectorKeys = new Set(
|
|
@@ -944,12 +941,10 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
944
941
|
for (const account of accounts.filter(
|
|
945
942
|
(acc) => acc.connectorKey === connectorKey
|
|
946
943
|
)) {
|
|
947
|
-
const { lastSyncAt } = account;
|
|
948
944
|
const payments = await this.bankConnector.getAllAccountPayments({
|
|
949
945
|
db: this.db,
|
|
950
946
|
env: this.env.ENVIRONMENT,
|
|
951
|
-
account
|
|
952
|
-
lastSync: lastSyncAt
|
|
947
|
+
account
|
|
953
948
|
});
|
|
954
949
|
if (!payments || payments.length === 0) continue;
|
|
955
950
|
this.log(payments);
|
|
@@ -989,12 +984,10 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
989
984
|
)[0];
|
|
990
985
|
}
|
|
991
986
|
if (lastSyncPayment.createdAt) {
|
|
992
|
-
await
|
|
993
|
-
account,
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
}
|
|
997
|
-
});
|
|
987
|
+
await updateAccountLastSyncCommand(this.db, {
|
|
988
|
+
accountId: account.id,
|
|
989
|
+
lastSyncedAt: lastSyncPayment.createdAt
|
|
990
|
+
}).command.execute();
|
|
998
991
|
}
|
|
999
992
|
}
|
|
1000
993
|
await this.pushToQueue(
|
|
@@ -1077,7 +1070,6 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
1077
1070
|
{ data: input, schema: setLastSyncAtInputSchema },
|
|
1078
1071
|
{ successMessage: "Last sync set." },
|
|
1079
1072
|
async ({ iban, lastSyncedAt }) => {
|
|
1080
|
-
const { setLastSync } = useSync(this.env.BANK_KV);
|
|
1081
1073
|
const account = await getAccountByIbanQuery(this.db, {
|
|
1082
1074
|
iban
|
|
1083
1075
|
});
|
|
@@ -1087,12 +1079,10 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
1087
1079
|
message: "Account for this organization does not exist."
|
|
1088
1080
|
});
|
|
1089
1081
|
}
|
|
1090
|
-
await
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
account: { ...account, token: "" }
|
|
1095
|
-
});
|
|
1082
|
+
await updateAccountLastSyncCommand(this.db, {
|
|
1083
|
+
accountId: account.id,
|
|
1084
|
+
lastSyncedAt
|
|
1085
|
+
}).command.execute();
|
|
1096
1086
|
return {};
|
|
1097
1087
|
}
|
|
1098
1088
|
);
|
|
@@ -1135,6 +1125,9 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
1135
1125
|
__decorateClass([
|
|
1136
1126
|
action("get-payments")
|
|
1137
1127
|
], BankServiceBase.prototype, "getPayments", 1);
|
|
1128
|
+
__decorateClass([
|
|
1129
|
+
action("sync-account")
|
|
1130
|
+
], BankServiceBase.prototype, "syncAccount", 1);
|
|
1138
1131
|
__decorateClass([
|
|
1139
1132
|
action("synchronize-accounts")
|
|
1140
1133
|
], BankServiceBase.prototype, "syncAccounts", 1);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Environment } from '@develit-io/backend-sdk';
|
|
2
2
|
import { CURRENCY_CODES, BANK_CODES, CODES } from '@develit-io/general-codes';
|
|
3
|
-
import { a as PaymentInsertType, t as tables } from './bank.
|
|
3
|
+
import { a as PaymentInsertType, t as tables } from './bank.e_XSg9KV.mjs';
|
|
4
4
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import * as drizzle_zod from 'drizzle-zod';
|
|
@@ -34,7 +34,7 @@ declare const COUNTRY_CODES: ["AF" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AG" | "
|
|
|
34
34
|
type CountryCode = (typeof COUNTRY_CODES)[number];
|
|
35
35
|
|
|
36
36
|
interface BankAccountWithLastSync extends ConnectedAccount {
|
|
37
|
-
|
|
37
|
+
lastSyncedAt: Date;
|
|
38
38
|
}
|
|
39
39
|
declare const CONNECTOR_KEYS: readonly ["ERSTE", "FINBRICKS", "MOCK", "CREDITAS", "MOCK_COBS", "FIO", "MONETA"];
|
|
40
40
|
type ConnectorKey = (typeof CONNECTOR_KEYS)[number];
|
|
@@ -46,10 +46,6 @@ interface ConfigEnvironmentBank {
|
|
|
46
46
|
allowedProviders: ConnectorKey[];
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
interface SyncLog {
|
|
50
|
-
lastSyncedAt: Date;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
49
|
type WithStatus<T extends {
|
|
54
50
|
status: PaymentStatus;
|
|
55
51
|
}, S extends PaymentStatus> = Omit<T, 'status'> & {
|
|
@@ -106,9 +102,8 @@ declare abstract class IBankConnector {
|
|
|
106
102
|
}): Promise<InitiatedBatch>;
|
|
107
103
|
abstract initiateSEPAPayment(payment: IncomingPaymentMessage): Promise<InitiatedPayment>;
|
|
108
104
|
abstract initiateSinglePayment(payment: PaymentPreparedInsertType): Promise<InitiatedPayment>;
|
|
109
|
-
abstract getAllAccountPayments({ account,
|
|
110
|
-
account:
|
|
111
|
-
lastSync: SyncLog;
|
|
105
|
+
abstract getAllAccountPayments({ account, db, env, }: {
|
|
106
|
+
account: AccountSelectType;
|
|
112
107
|
db: DrizzleD1Database<typeof tables>;
|
|
113
108
|
env: Environment;
|
|
114
109
|
}): Promise<PaymentInsertType[]>;
|
|
@@ -166,6 +161,25 @@ declare const accountInsertSchema: drizzle_zod.BuildSchema<"insert", {
|
|
|
166
161
|
length: number | undefined;
|
|
167
162
|
$type: "AUTHORIZED" | "DISABLED" | "EXPIRED";
|
|
168
163
|
}>;
|
|
164
|
+
bankRefId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
165
|
+
name: "bank_ref_id";
|
|
166
|
+
tableName: "account";
|
|
167
|
+
dataType: "string";
|
|
168
|
+
columnType: "SQLiteText";
|
|
169
|
+
data: string;
|
|
170
|
+
driverParam: string;
|
|
171
|
+
notNull: true;
|
|
172
|
+
hasDefault: false;
|
|
173
|
+
isPrimaryKey: false;
|
|
174
|
+
isAutoincrement: false;
|
|
175
|
+
hasRuntimeDefault: false;
|
|
176
|
+
enumValues: [string, ...string[]];
|
|
177
|
+
baseColumn: never;
|
|
178
|
+
identity: undefined;
|
|
179
|
+
generated: undefined;
|
|
180
|
+
}, {}, {
|
|
181
|
+
length: number | undefined;
|
|
182
|
+
}>;
|
|
169
183
|
sync: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
170
184
|
name: "sync";
|
|
171
185
|
tableName: "account";
|
|
@@ -500,6 +514,25 @@ declare const accountUpdateSchema: drizzle_zod.BuildSchema<"update", {
|
|
|
500
514
|
length: number | undefined;
|
|
501
515
|
$type: "AUTHORIZED" | "DISABLED" | "EXPIRED";
|
|
502
516
|
}>;
|
|
517
|
+
bankRefId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
518
|
+
name: "bank_ref_id";
|
|
519
|
+
tableName: "account";
|
|
520
|
+
dataType: "string";
|
|
521
|
+
columnType: "SQLiteText";
|
|
522
|
+
data: string;
|
|
523
|
+
driverParam: string;
|
|
524
|
+
notNull: true;
|
|
525
|
+
hasDefault: false;
|
|
526
|
+
isPrimaryKey: false;
|
|
527
|
+
isAutoincrement: false;
|
|
528
|
+
hasRuntimeDefault: false;
|
|
529
|
+
enumValues: [string, ...string[]];
|
|
530
|
+
baseColumn: never;
|
|
531
|
+
identity: undefined;
|
|
532
|
+
generated: undefined;
|
|
533
|
+
}, {}, {
|
|
534
|
+
length: number | undefined;
|
|
535
|
+
}>;
|
|
503
536
|
sync: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
504
537
|
name: "sync";
|
|
505
538
|
tableName: "account";
|
|
@@ -834,6 +867,25 @@ declare const accountSelectSchema: drizzle_zod.BuildSchema<"select", {
|
|
|
834
867
|
length: number | undefined;
|
|
835
868
|
$type: "AUTHORIZED" | "DISABLED" | "EXPIRED";
|
|
836
869
|
}>;
|
|
870
|
+
bankRefId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
871
|
+
name: "bank_ref_id";
|
|
872
|
+
tableName: "account";
|
|
873
|
+
dataType: "string";
|
|
874
|
+
columnType: "SQLiteText";
|
|
875
|
+
data: string;
|
|
876
|
+
driverParam: string;
|
|
877
|
+
notNull: true;
|
|
878
|
+
hasDefault: false;
|
|
879
|
+
isPrimaryKey: false;
|
|
880
|
+
isAutoincrement: false;
|
|
881
|
+
hasRuntimeDefault: false;
|
|
882
|
+
enumValues: [string, ...string[]];
|
|
883
|
+
baseColumn: never;
|
|
884
|
+
identity: undefined;
|
|
885
|
+
generated: undefined;
|
|
886
|
+
}, {}, {
|
|
887
|
+
length: number | undefined;
|
|
888
|
+
}>;
|
|
837
889
|
sync: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
838
890
|
name: "sync";
|
|
839
891
|
tableName: "account";
|
|
@@ -1644,5 +1696,5 @@ type AccountCredentialsUpdateType = z.infer<typeof accountCredentialsInsertSchem
|
|
|
1644
1696
|
type AccountCredentialsPatchType = z.infer<typeof accountCredentialsUpdateSchema>;
|
|
1645
1697
|
type AccountCredentialsSelectType = z.infer<typeof accountCredentialsSelectSchema>;
|
|
1646
1698
|
|
|
1647
|
-
export { CONNECTOR_KEYS as D, CREDENTIALS_TYPES as E, accountInsertSchema as H, IBankConnector as I, accountUpdateSchema as J, accountSelectSchema as K, accountCredentialsInsertSchema as N, accountCredentialsUpdateSchema as Q, accountCredentialsSelectSchema as R, TOKEN_TYPES as T, BATCH_STATUSES as
|
|
1648
|
-
export type { AccountSelectType as A,
|
|
1699
|
+
export { CONNECTOR_KEYS as D, CREDENTIALS_TYPES as E, accountInsertSchema as H, IBankConnector as I, accountUpdateSchema as J, accountSelectSchema as K, accountCredentialsInsertSchema as N, accountCredentialsUpdateSchema as Q, accountCredentialsSelectSchema as R, TOKEN_TYPES as T, BATCH_STATUSES as q, PAYMENT_TYPES as r, PAYMENT_STATUSES as t, PAYMENT_DIRECTIONS as u, ACCOUNT_STATUSES as w, COUNTRY_CODES as y };
|
|
1700
|
+
export type { AccountSelectType as A, BatchMetadata as B, ConfigEnvironmentBank as C, CredentialsType as F, TokenType as G, AccountUpdateType as L, AccountPatchType as M, OutgoingPaymentMessage as O, PaymentPreparedInsertType as P, AccountCredentialsUpdateType as S, AccountCredentialsPatchType as U, AccountCredentialsSelectType as V, ConnectorKey as a, IncomingPaymentMessage as b, InitiatedPayment as c, ConnectedAccount as d, AccountCredentialsInsertType as e, AccountInsertType as f, InitiatedBatch as g, PaymentStatus as h, BatchStatus as i, CurrencyCode as j, BankCode as k, CountryCode as l, AuthInput as m, Currency as n, PaymentFailedInsertType as o, paymentInitializedInsertType as p, PaymentType as s, PaymentDirection as v, AccountStatus as x, BankAccountWithLastSync as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Environment } from '@develit-io/backend-sdk';
|
|
2
2
|
import { CURRENCY_CODES, BANK_CODES, CODES } from '@develit-io/general-codes';
|
|
3
|
-
import { a as PaymentInsertType, t as tables } from './bank.
|
|
3
|
+
import { a as PaymentInsertType, t as tables } from './bank.e_XSg9KV.js';
|
|
4
4
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import * as drizzle_zod from 'drizzle-zod';
|
|
@@ -34,7 +34,7 @@ declare const COUNTRY_CODES: ["AF" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AG" | "
|
|
|
34
34
|
type CountryCode = (typeof COUNTRY_CODES)[number];
|
|
35
35
|
|
|
36
36
|
interface BankAccountWithLastSync extends ConnectedAccount {
|
|
37
|
-
|
|
37
|
+
lastSyncedAt: Date;
|
|
38
38
|
}
|
|
39
39
|
declare const CONNECTOR_KEYS: readonly ["ERSTE", "FINBRICKS", "MOCK", "CREDITAS", "MOCK_COBS", "FIO", "MONETA"];
|
|
40
40
|
type ConnectorKey = (typeof CONNECTOR_KEYS)[number];
|
|
@@ -46,10 +46,6 @@ interface ConfigEnvironmentBank {
|
|
|
46
46
|
allowedProviders: ConnectorKey[];
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
interface SyncLog {
|
|
50
|
-
lastSyncedAt: Date;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
49
|
type WithStatus<T extends {
|
|
54
50
|
status: PaymentStatus;
|
|
55
51
|
}, S extends PaymentStatus> = Omit<T, 'status'> & {
|
|
@@ -106,9 +102,8 @@ declare abstract class IBankConnector {
|
|
|
106
102
|
}): Promise<InitiatedBatch>;
|
|
107
103
|
abstract initiateSEPAPayment(payment: IncomingPaymentMessage): Promise<InitiatedPayment>;
|
|
108
104
|
abstract initiateSinglePayment(payment: PaymentPreparedInsertType): Promise<InitiatedPayment>;
|
|
109
|
-
abstract getAllAccountPayments({ account,
|
|
110
|
-
account:
|
|
111
|
-
lastSync: SyncLog;
|
|
105
|
+
abstract getAllAccountPayments({ account, db, env, }: {
|
|
106
|
+
account: AccountSelectType;
|
|
112
107
|
db: DrizzleD1Database<typeof tables>;
|
|
113
108
|
env: Environment;
|
|
114
109
|
}): Promise<PaymentInsertType[]>;
|
|
@@ -166,6 +161,25 @@ declare const accountInsertSchema: drizzle_zod.BuildSchema<"insert", {
|
|
|
166
161
|
length: number | undefined;
|
|
167
162
|
$type: "AUTHORIZED" | "DISABLED" | "EXPIRED";
|
|
168
163
|
}>;
|
|
164
|
+
bankRefId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
165
|
+
name: "bank_ref_id";
|
|
166
|
+
tableName: "account";
|
|
167
|
+
dataType: "string";
|
|
168
|
+
columnType: "SQLiteText";
|
|
169
|
+
data: string;
|
|
170
|
+
driverParam: string;
|
|
171
|
+
notNull: true;
|
|
172
|
+
hasDefault: false;
|
|
173
|
+
isPrimaryKey: false;
|
|
174
|
+
isAutoincrement: false;
|
|
175
|
+
hasRuntimeDefault: false;
|
|
176
|
+
enumValues: [string, ...string[]];
|
|
177
|
+
baseColumn: never;
|
|
178
|
+
identity: undefined;
|
|
179
|
+
generated: undefined;
|
|
180
|
+
}, {}, {
|
|
181
|
+
length: number | undefined;
|
|
182
|
+
}>;
|
|
169
183
|
sync: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
170
184
|
name: "sync";
|
|
171
185
|
tableName: "account";
|
|
@@ -500,6 +514,25 @@ declare const accountUpdateSchema: drizzle_zod.BuildSchema<"update", {
|
|
|
500
514
|
length: number | undefined;
|
|
501
515
|
$type: "AUTHORIZED" | "DISABLED" | "EXPIRED";
|
|
502
516
|
}>;
|
|
517
|
+
bankRefId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
518
|
+
name: "bank_ref_id";
|
|
519
|
+
tableName: "account";
|
|
520
|
+
dataType: "string";
|
|
521
|
+
columnType: "SQLiteText";
|
|
522
|
+
data: string;
|
|
523
|
+
driverParam: string;
|
|
524
|
+
notNull: true;
|
|
525
|
+
hasDefault: false;
|
|
526
|
+
isPrimaryKey: false;
|
|
527
|
+
isAutoincrement: false;
|
|
528
|
+
hasRuntimeDefault: false;
|
|
529
|
+
enumValues: [string, ...string[]];
|
|
530
|
+
baseColumn: never;
|
|
531
|
+
identity: undefined;
|
|
532
|
+
generated: undefined;
|
|
533
|
+
}, {}, {
|
|
534
|
+
length: number | undefined;
|
|
535
|
+
}>;
|
|
503
536
|
sync: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
504
537
|
name: "sync";
|
|
505
538
|
tableName: "account";
|
|
@@ -834,6 +867,25 @@ declare const accountSelectSchema: drizzle_zod.BuildSchema<"select", {
|
|
|
834
867
|
length: number | undefined;
|
|
835
868
|
$type: "AUTHORIZED" | "DISABLED" | "EXPIRED";
|
|
836
869
|
}>;
|
|
870
|
+
bankRefId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
871
|
+
name: "bank_ref_id";
|
|
872
|
+
tableName: "account";
|
|
873
|
+
dataType: "string";
|
|
874
|
+
columnType: "SQLiteText";
|
|
875
|
+
data: string;
|
|
876
|
+
driverParam: string;
|
|
877
|
+
notNull: true;
|
|
878
|
+
hasDefault: false;
|
|
879
|
+
isPrimaryKey: false;
|
|
880
|
+
isAutoincrement: false;
|
|
881
|
+
hasRuntimeDefault: false;
|
|
882
|
+
enumValues: [string, ...string[]];
|
|
883
|
+
baseColumn: never;
|
|
884
|
+
identity: undefined;
|
|
885
|
+
generated: undefined;
|
|
886
|
+
}, {}, {
|
|
887
|
+
length: number | undefined;
|
|
888
|
+
}>;
|
|
837
889
|
sync: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
838
890
|
name: "sync";
|
|
839
891
|
tableName: "account";
|
|
@@ -1644,5 +1696,5 @@ type AccountCredentialsUpdateType = z.infer<typeof accountCredentialsInsertSchem
|
|
|
1644
1696
|
type AccountCredentialsPatchType = z.infer<typeof accountCredentialsUpdateSchema>;
|
|
1645
1697
|
type AccountCredentialsSelectType = z.infer<typeof accountCredentialsSelectSchema>;
|
|
1646
1698
|
|
|
1647
|
-
export { CONNECTOR_KEYS as D, CREDENTIALS_TYPES as E, accountInsertSchema as H, IBankConnector as I, accountUpdateSchema as J, accountSelectSchema as K, accountCredentialsInsertSchema as N, accountCredentialsUpdateSchema as Q, accountCredentialsSelectSchema as R, TOKEN_TYPES as T, BATCH_STATUSES as
|
|
1648
|
-
export type { AccountSelectType as A,
|
|
1699
|
+
export { CONNECTOR_KEYS as D, CREDENTIALS_TYPES as E, accountInsertSchema as H, IBankConnector as I, accountUpdateSchema as J, accountSelectSchema as K, accountCredentialsInsertSchema as N, accountCredentialsUpdateSchema as Q, accountCredentialsSelectSchema as R, TOKEN_TYPES as T, BATCH_STATUSES as q, PAYMENT_TYPES as r, PAYMENT_STATUSES as t, PAYMENT_DIRECTIONS as u, ACCOUNT_STATUSES as w, COUNTRY_CODES as y };
|
|
1700
|
+
export type { AccountSelectType as A, BatchMetadata as B, ConfigEnvironmentBank as C, CredentialsType as F, TokenType as G, AccountUpdateType as L, AccountPatchType as M, OutgoingPaymentMessage as O, PaymentPreparedInsertType as P, AccountCredentialsUpdateType as S, AccountCredentialsPatchType as U, AccountCredentialsSelectType as V, ConnectorKey as a, IncomingPaymentMessage as b, InitiatedPayment as c, ConnectedAccount as d, AccountCredentialsInsertType as e, AccountInsertType as f, InitiatedBatch as g, PaymentStatus as h, BatchStatus as i, CurrencyCode as j, BankCode as k, CountryCode as l, AuthInput as m, Currency as n, PaymentFailedInsertType as o, paymentInitializedInsertType as p, PaymentType as s, PaymentDirection as v, AccountStatus as x, BankAccountWithLastSync as z };
|
|
@@ -9,7 +9,6 @@ const drizzleZod = require('drizzle-zod');
|
|
|
9
9
|
const sqliteCore = require('drizzle-orm/sqlite-core');
|
|
10
10
|
const dateFns = require('date-fns');
|
|
11
11
|
const relations = require('drizzle-orm/relations');
|
|
12
|
-
require('superjson');
|
|
13
12
|
|
|
14
13
|
class IBankConnector {
|
|
15
14
|
}
|
|
@@ -184,6 +183,7 @@ const mapFinbricksTransactionToPayment = (tx, account) => {
|
|
|
184
183
|
const base = {
|
|
185
184
|
id: backendSdk.uuidv4(),
|
|
186
185
|
connectorKey: account.connectorKey,
|
|
186
|
+
accountId: account.id,
|
|
187
187
|
bankRefId: tx.entryReference || tx.fbxReference,
|
|
188
188
|
amount: tx.amount?.value || 0,
|
|
189
189
|
currency: tx.amount?.currency || "CZK",
|
|
@@ -211,6 +211,7 @@ const mapFinbricksAccountInsert = ({
|
|
|
211
211
|
status
|
|
212
212
|
}) => ({
|
|
213
213
|
id: account.id,
|
|
214
|
+
bankRefId: account.bankRefId,
|
|
214
215
|
connectorKey,
|
|
215
216
|
status,
|
|
216
217
|
sync: false,
|
|
@@ -285,14 +286,20 @@ class FinbricksConnector extends IBankConnector {
|
|
|
285
286
|
status: 401
|
|
286
287
|
});
|
|
287
288
|
}
|
|
288
|
-
const accounts = await this.getAccountsForClient({ clientId })
|
|
289
|
+
const accounts = (await this.getAccountsForClient({ clientId })).map(
|
|
290
|
+
(acc) => ({
|
|
291
|
+
...acc,
|
|
292
|
+
bankRefId: acc.id,
|
|
293
|
+
id: backendSdk.uuidv4()
|
|
294
|
+
})
|
|
295
|
+
);
|
|
289
296
|
console.log(accounts, "accs finbricks");
|
|
290
297
|
const credentials = accounts.map((acc) => ({
|
|
291
|
-
accountId: acc.id,
|
|
292
298
|
connectorKey: this.PROVIDER,
|
|
293
299
|
expiresAt: new Date(Date.now() + 36e5),
|
|
294
300
|
type: "CLIENT_ID",
|
|
295
|
-
value: clientId
|
|
301
|
+
value: clientId,
|
|
302
|
+
accountId: acc.id
|
|
296
303
|
}));
|
|
297
304
|
this.connectedAccounts.push(
|
|
298
305
|
...accounts.map((acc) => ({
|
|
@@ -394,6 +401,7 @@ class FinbricksConnector extends IBankConnector {
|
|
|
394
401
|
);
|
|
395
402
|
return uniqueAccounts.map((acc) => ({
|
|
396
403
|
connectorKey: this.connectorKey,
|
|
404
|
+
bankRefId: acc.id,
|
|
397
405
|
currency: acc.currency,
|
|
398
406
|
sync: false,
|
|
399
407
|
status: "AUTHORIZED",
|
|
@@ -531,11 +539,10 @@ class FinbricksConnector extends IBankConnector {
|
|
|
531
539
|
};
|
|
532
540
|
}
|
|
533
541
|
async getAllAccountPayments({
|
|
534
|
-
account
|
|
535
|
-
lastSync
|
|
542
|
+
account
|
|
536
543
|
}) {
|
|
537
544
|
const dateFormat = "yyyy-MM-dd";
|
|
538
|
-
const dateFrom = dateFns.format(
|
|
545
|
+
const dateFrom = dateFns.format(account.lastSyncedAt, dateFormat);
|
|
539
546
|
const dateTo = dateFns.format(/* @__PURE__ */ new Date(), dateFormat);
|
|
540
547
|
let cursor = null;
|
|
541
548
|
const allPayments = [];
|
|
@@ -838,12 +845,11 @@ class ErsteConnector extends IBankConnector {
|
|
|
838
845
|
return (await data.json()).signingUrl;
|
|
839
846
|
}
|
|
840
847
|
async getAllAccountPayments({
|
|
841
|
-
account
|
|
842
|
-
lastSync
|
|
848
|
+
account
|
|
843
849
|
}) {
|
|
844
850
|
const erstePayments = [];
|
|
845
851
|
const dateFormat = "yyyy-MM-dd";
|
|
846
|
-
const fromDate = dateFns.format(
|
|
852
|
+
const fromDate = dateFns.format(account.lastSyncedAt, dateFormat);
|
|
847
853
|
const toDate = dateFns.format(/* @__PURE__ */ new Date(), dateFormat);
|
|
848
854
|
let page = 0;
|
|
849
855
|
const pageSize = 200;
|
|
@@ -868,6 +874,7 @@ class ErsteConnector extends IBankConnector {
|
|
|
868
874
|
const paymentInsert = {
|
|
869
875
|
id: backendSdk.uuidv4(),
|
|
870
876
|
connectorKey: "ERSTE",
|
|
877
|
+
accountId: account.id,
|
|
871
878
|
bankRefId: payment.entryReference,
|
|
872
879
|
amount: payment.amount.value,
|
|
873
880
|
currency: payment.amount.currency.code,
|
|
@@ -1054,6 +1061,7 @@ const account = sqliteCore.sqliteTable(
|
|
|
1054
1061
|
enum: CONNECTOR_KEYS
|
|
1055
1062
|
}).$type().notNull(),
|
|
1056
1063
|
status: sqliteCore.text("status", { enum: ACCOUNT_STATUSES }).$type().notNull(),
|
|
1064
|
+
bankRefId: sqliteCore.text("bank_ref_id").notNull(),
|
|
1057
1065
|
sync: sqliteCore.integer("sync", { mode: "boolean" }).default(false).notNull(),
|
|
1058
1066
|
syncPeriod: sqliteCore.integer("sync_period"),
|
|
1059
1067
|
lastSyncedAt: sqliteCore.integer("last_synced_at", { mode: "timestamp_ms" })
|