@develit-services/bank 0.2.2 → 0.2.4
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 +2 -3
- package/dist/database/schema.d.cts +6 -3
- package/dist/database/schema.d.mts +6 -3
- package/dist/database/schema.d.ts +6 -3
- package/dist/database/schema.mjs +2 -3
- package/dist/export/worker.cjs +39 -46
- package/dist/export/worker.d.cts +25 -15
- package/dist/export/worker.d.mts +25 -15
- package/dist/export/worker.d.ts +25 -15
- package/dist/export/worker.mjs +35 -42
- package/dist/export/workflows.cjs +92 -94
- package/dist/export/workflows.mjs +92 -94
- package/dist/export/wrangler.cjs +1 -0
- package/dist/export/wrangler.d.cts +1 -0
- package/dist/export/wrangler.d.mts +1 -0
- package/dist/export/wrangler.d.ts +1 -0
- package/dist/export/wrangler.mjs +1 -0
- package/dist/shared/{bank.CXUMEJH4.mjs → bank.BvUtf1S3.mjs} +41 -20
- package/dist/shared/{bank.CEraaQIT.cjs → bank.CHS79KTx.cjs} +42 -21
- package/dist/shared/{bank.2BgwPCw_.d.ts → bank.Cfz44GPA.d.cts} +1598 -12
- package/dist/shared/{bank.BOe_Qmuw.d.mts → bank.Cfz44GPA.d.mts} +1598 -12
- package/dist/shared/{bank.RD4xwHFf.d.cts → bank.Cfz44GPA.d.ts} +1598 -12
- package/dist/shared/{bank.B8QzFnJl.cjs → bank.CyinOg3r.cjs} +1 -1
- package/dist/shared/{bank.CjZRgRoJ.mjs → bank.DKtu6cfY.mjs} +1 -1
- package/dist/shared/{bank.B0uSWeRe.mjs → bank.DXn9jD0Q.mjs} +43 -60
- package/dist/shared/{bank.CWAToo_g.cjs → bank.NdqOkgpd.cjs} +41 -59
- package/dist/types.cjs +2 -4
- package/dist/types.d.cts +3 -5
- package/dist/types.d.mts +3 -5
- package/dist/types.d.ts +3 -5
- package/dist/types.mjs +2 -3
- package/package.json +2 -1
- package/dist/shared/bank.BGZYksmV.d.cts +0 -1598
- package/dist/shared/bank.BGZYksmV.d.mts +0 -1598
- package/dist/shared/bank.BGZYksmV.d.ts +0 -1598
package/dist/database/schema.cjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const database_schema = require('../shared/bank.
|
|
3
|
+
const database_schema = require('../shared/bank.NdqOkgpd.cjs');
|
|
4
4
|
require('@develit-io/backend-sdk');
|
|
5
5
|
require('drizzle-orm/sqlite-core');
|
|
6
6
|
require('date-fns');
|
|
7
7
|
require('drizzle-orm');
|
|
8
|
-
require('@develit-io/general-codes');
|
|
9
|
-
require('zod');
|
|
10
8
|
require('jose');
|
|
9
|
+
require('@develit-io/general-codes');
|
|
11
10
|
require('drizzle-zod');
|
|
12
11
|
require('drizzle-orm/relations');
|
|
13
12
|
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import 'drizzle-orm/sqlite-core';
|
|
3
|
-
import 'drizzle-orm';
|
|
1
|
+
export { a9 as account, aa as accountCredentials, a5 as batch, a8 as ott, a6 as payment, a7 as paymentRelations } from '../shared/bank.Cfz44GPA.cjs';
|
|
4
2
|
import 'zod';
|
|
3
|
+
import 'drizzle-zod';
|
|
4
|
+
import 'drizzle-orm/sqlite-core';
|
|
5
5
|
import '@develit-io/backend-sdk';
|
|
6
|
+
import 'drizzle-orm/d1';
|
|
7
|
+
import 'drizzle-orm';
|
|
8
|
+
import '@develit-io/general-codes';
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import 'drizzle-orm/sqlite-core';
|
|
3
|
-
import 'drizzle-orm';
|
|
1
|
+
export { a9 as account, aa as accountCredentials, a5 as batch, a8 as ott, a6 as payment, a7 as paymentRelations } from '../shared/bank.Cfz44GPA.mjs';
|
|
4
2
|
import 'zod';
|
|
3
|
+
import 'drizzle-zod';
|
|
4
|
+
import 'drizzle-orm/sqlite-core';
|
|
5
5
|
import '@develit-io/backend-sdk';
|
|
6
|
+
import 'drizzle-orm/d1';
|
|
7
|
+
import 'drizzle-orm';
|
|
8
|
+
import '@develit-io/general-codes';
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import 'drizzle-orm/sqlite-core';
|
|
3
|
-
import 'drizzle-orm';
|
|
1
|
+
export { a9 as account, aa as accountCredentials, a5 as batch, a8 as ott, a6 as payment, a7 as paymentRelations } from '../shared/bank.Cfz44GPA.js';
|
|
4
2
|
import 'zod';
|
|
3
|
+
import 'drizzle-zod';
|
|
4
|
+
import 'drizzle-orm/sqlite-core';
|
|
5
5
|
import '@develit-io/backend-sdk';
|
|
6
|
+
import 'drizzle-orm/d1';
|
|
7
|
+
import 'drizzle-orm';
|
|
8
|
+
import '@develit-io/general-codes';
|
package/dist/database/schema.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { y as account, z as accountCredentials, r as batch, x as ott, v as payment, w as paymentRelations } from '../shared/bank.DXn9jD0Q.mjs';
|
|
2
2
|
import '@develit-io/backend-sdk';
|
|
3
3
|
import 'drizzle-orm/sqlite-core';
|
|
4
4
|
import 'date-fns';
|
|
5
5
|
import 'drizzle-orm';
|
|
6
|
-
import '@develit-io/general-codes';
|
|
7
|
-
import 'zod';
|
|
8
6
|
import 'jose';
|
|
7
|
+
import '@develit-io/general-codes';
|
|
9
8
|
import 'drizzle-zod';
|
|
10
9
|
import 'drizzle-orm/relations';
|
package/dist/export/worker.cjs
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
const backendSdk = require('@develit-io/backend-sdk');
|
|
4
4
|
const cloudflare_workers = require('cloudflare:workers');
|
|
5
5
|
const d1 = require('drizzle-orm/d1');
|
|
6
|
-
const database_schema = require('../shared/bank.
|
|
6
|
+
const database_schema = require('../shared/bank.NdqOkgpd.cjs');
|
|
7
7
|
require('jose');
|
|
8
8
|
const generalCodes = require('@develit-io/general-codes');
|
|
9
9
|
const zod = require('zod');
|
|
10
|
-
const
|
|
10
|
+
const encryption = require('../shared/bank.CHS79KTx.cjs');
|
|
11
11
|
const drizzleOrm = require('drizzle-orm');
|
|
12
12
|
require('drizzle-orm/sqlite-core');
|
|
13
13
|
require('date-fns');
|
|
14
14
|
require('drizzle-zod');
|
|
15
15
|
require('drizzle-orm/relations');
|
|
16
|
-
require('../shared/bank.
|
|
16
|
+
require('../shared/bank.CyinOg3r.cjs');
|
|
17
17
|
|
|
18
18
|
const upsertAccountCommand = (db, { account }) => {
|
|
19
19
|
const id = account.id || backendSdk.uuidv4();
|
|
@@ -29,6 +29,12 @@ const upsertAccountCommand = (db, { account }) => {
|
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
const updatePaymentCommand = (db, { payment }) => {
|
|
33
|
+
return {
|
|
34
|
+
command: db.update(database_schema.tables.payment).set(payment).where(drizzleOrm.eq(database_schema.tables.payment.id, payment.id)).returning()
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
32
38
|
const upsertBatchCommand = (db, { batch }) => {
|
|
33
39
|
const id = batch.id || backendSdk.uuidv4();
|
|
34
40
|
const command = db.insert(database_schema.tables.batch).values({
|
|
@@ -73,9 +79,14 @@ const expireOneTimeTokenCommand = (db, {
|
|
|
73
79
|
};
|
|
74
80
|
};
|
|
75
81
|
|
|
76
|
-
const createAccountCredentialsCommand = (db, { credentials }) => {
|
|
82
|
+
const createAccountCredentialsCommand = async (db, encryptionKey, { credentials }) => {
|
|
77
83
|
const id = credentials.id || backendSdk.uuidv4();
|
|
78
|
-
const
|
|
84
|
+
const encryptedValue = await encryption.encrypt(credentials.value, encryptionKey);
|
|
85
|
+
const command = db.insert(database_schema.tables.accountCredentials).values({
|
|
86
|
+
...credentials,
|
|
87
|
+
id,
|
|
88
|
+
value: encryptedValue
|
|
89
|
+
}).returning();
|
|
79
90
|
return {
|
|
80
91
|
id,
|
|
81
92
|
command
|
|
@@ -280,11 +291,6 @@ const simulateDepositInputSchema = zod.z.object({
|
|
|
280
291
|
connectorKey: zod.z.enum(database_schema.CONNECTOR_KEYS)
|
|
281
292
|
});
|
|
282
293
|
|
|
283
|
-
const setLastSyncAtInputSchema = zod.z.object({
|
|
284
|
-
iban: zod.z.string(),
|
|
285
|
-
lastSyncedAt: zod.z.coerce.date()
|
|
286
|
-
});
|
|
287
|
-
|
|
288
294
|
const ALLOWED_BATCH_FILTERS = {
|
|
289
295
|
ACCOUNT_ID: "filterBatchAccountId",
|
|
290
296
|
STATUS: "filterBatchStatus"
|
|
@@ -398,11 +404,16 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
398
404
|
const accountsForConnector = accounts.filter(
|
|
399
405
|
(acc) => acc.connectorKey === connectorKey
|
|
400
406
|
);
|
|
407
|
+
const encryptionKey = await encryption.importAesKey(this.env.ENCRYPTION_KEY);
|
|
401
408
|
const accountsWithCredentials = await Promise.all(
|
|
402
409
|
accountsForConnector.map(async (acc) => {
|
|
403
|
-
const credentials = await
|
|
404
|
-
|
|
405
|
-
|
|
410
|
+
const credentials = await encryption.getCredentialsByAccountId(
|
|
411
|
+
this.db,
|
|
412
|
+
encryptionKey,
|
|
413
|
+
{
|
|
414
|
+
accountId: acc.id
|
|
415
|
+
}
|
|
416
|
+
);
|
|
406
417
|
if (!credentials) {
|
|
407
418
|
throw backendSdk.createInternalError(null, {
|
|
408
419
|
message: `No credentials found for account ${acc.id}`
|
|
@@ -417,7 +428,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
417
428
|
};
|
|
418
429
|
})
|
|
419
430
|
);
|
|
420
|
-
this.bankConnector =
|
|
431
|
+
this.bankConnector = encryption.initiateConnector({
|
|
421
432
|
bank: connectorKey,
|
|
422
433
|
connectedAccounts: accountsWithCredentials,
|
|
423
434
|
env: this.env
|
|
@@ -574,6 +585,8 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
574
585
|
(payment) => {
|
|
575
586
|
return {
|
|
576
587
|
id: backendSdk.uuidv4(),
|
|
588
|
+
bankRefId: backendSdk.uuidv4(),
|
|
589
|
+
//TODO(kleinpetr): we won't create payment here (only via sync script)
|
|
577
590
|
correlationId: payment.correlationId,
|
|
578
591
|
refId: payment.refId,
|
|
579
592
|
amount: payment.amount,
|
|
@@ -716,7 +729,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
716
729
|
...preparedBatch.failedPayments,
|
|
717
730
|
...preparedBatch.newlyPreparedPayments
|
|
718
731
|
].map(
|
|
719
|
-
(p) =>
|
|
732
|
+
(p) => encryption.createPaymentCommand(this.db, { payment: p }).command.execute()
|
|
720
733
|
)
|
|
721
734
|
]);
|
|
722
735
|
await upsertBatchCommand(this.db, {
|
|
@@ -753,7 +766,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
753
766
|
}
|
|
754
767
|
});
|
|
755
768
|
const updatePayments = payments.map(
|
|
756
|
-
(payment) =>
|
|
769
|
+
(payment) => updatePaymentCommand(this.db, {
|
|
757
770
|
payment: { ...payment, status: "INITIALIZED" }
|
|
758
771
|
}).command
|
|
759
772
|
);
|
|
@@ -857,11 +870,14 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
857
870
|
accountId: acc.id
|
|
858
871
|
}).command
|
|
859
872
|
);
|
|
860
|
-
const
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
873
|
+
const encryptionKey = await encryption.importAesKey(this.env.ENCRYPTION_KEY);
|
|
874
|
+
const createAccountCredentials = (await Promise.all(
|
|
875
|
+
credentials.map(
|
|
876
|
+
async (cr) => createAccountCredentialsCommand(this.db, encryptionKey, {
|
|
877
|
+
credentials: cr
|
|
878
|
+
})
|
|
879
|
+
)
|
|
880
|
+
)).map((cmd) => cmd.command);
|
|
865
881
|
const { command: updateOtt } = expireOneTimeTokenCommand(this.db, {
|
|
866
882
|
ott
|
|
867
883
|
});
|
|
@@ -910,6 +926,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
910
926
|
});
|
|
911
927
|
const payment = {
|
|
912
928
|
id: backendSdk.uuidv4(),
|
|
929
|
+
bankRefId: backendSdk.uuidv4(),
|
|
913
930
|
correlationId: backendSdk.uuidv4(),
|
|
914
931
|
amount,
|
|
915
932
|
connectorKey,
|
|
@@ -930,7 +947,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
930
947
|
debtor,
|
|
931
948
|
debtorIban: debtor.iban
|
|
932
949
|
};
|
|
933
|
-
const { command } =
|
|
950
|
+
const { command } = encryption.createPaymentCommand(this.db, { payment });
|
|
934
951
|
const createdPayment = await command.execute().then(backendSdk.first);
|
|
935
952
|
this.logQueuePush({ payment, isPaymentExecuted: true });
|
|
936
953
|
await this.pushToQueue(this.env.QUEUE_BUS_QUEUE, {
|
|
@@ -947,27 +964,6 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
947
964
|
}
|
|
948
965
|
);
|
|
949
966
|
}
|
|
950
|
-
async setLastSyncAt(input) {
|
|
951
|
-
return this.handleAction(
|
|
952
|
-
{ data: input, schema: setLastSyncAtInputSchema },
|
|
953
|
-
{ successMessage: "Last sync set." },
|
|
954
|
-
async ({ iban, lastSyncedAt }) => {
|
|
955
|
-
const account = await getAccountByIbanQuery(this.db, {
|
|
956
|
-
iban
|
|
957
|
-
});
|
|
958
|
-
if (!account) {
|
|
959
|
-
throw backendSdk.createInternalError(null, {
|
|
960
|
-
status: 404,
|
|
961
|
-
message: "Account for this organization does not exist."
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
|
-
await bank.updateAccountLastSyncCommand(this.db, {
|
|
965
|
-
accountId: account.id,
|
|
966
|
-
lastSyncedAt
|
|
967
|
-
}).command.execute();
|
|
968
|
-
}
|
|
969
|
-
);
|
|
970
|
-
}
|
|
971
967
|
async sendPayment(input) {
|
|
972
968
|
return this.handleAction(
|
|
973
969
|
{ data: input, schema: sendPaymentInputSchema },
|
|
@@ -1076,9 +1072,6 @@ __decorateClass([
|
|
|
1076
1072
|
__decorateClass([
|
|
1077
1073
|
backendSdk.action("simulate-deposit")
|
|
1078
1074
|
], BankServiceBase.prototype, "simulateDeposit", 1);
|
|
1079
|
-
__decorateClass([
|
|
1080
|
-
backendSdk.action("set-last-sync-at")
|
|
1081
|
-
], BankServiceBase.prototype, "setLastSyncAt", 1);
|
|
1082
1075
|
__decorateClass([
|
|
1083
1076
|
backendSdk.action("send-payment")
|
|
1084
1077
|
], BankServiceBase.prototype, "sendPayment", 1);
|
package/dist/export/worker.d.cts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { A as AccountSelectType, P as PaymentSelectType, B as BatchSelectType, L as LastSyncMetadata, C as ConfigEnvironmentBank, t as tables, I as IBankConnector, a as ConnectorKey, b as PaymentInsertType } from '../shared/bank.Cfz44GPA.cjs';
|
|
1
2
|
import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
|
|
2
3
|
import { WorkflowInstanceStatus, IRPCResponse } from '@develit-io/backend-sdk';
|
|
3
|
-
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
4
4
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
5
|
-
import {
|
|
6
|
-
import { A as AccountSelectType, C as ConfigEnvironmentBank, I as IBankConnector, a as ConnectorKey } from '../shared/bank.RD4xwHFf.cjs';
|
|
5
|
+
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
7
6
|
import { z } from 'zod';
|
|
8
7
|
import * as drizzle_zod from 'drizzle-zod';
|
|
9
8
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
@@ -1514,14 +1513,6 @@ interface SimulateDepositInput extends z.infer<typeof simulateDepositInputSchema
|
|
|
1514
1513
|
interface SimulateDepositOutput extends PaymentSelectType {
|
|
1515
1514
|
}
|
|
1516
1515
|
|
|
1517
|
-
declare const setLastSyncAtInputSchema: z.ZodObject<{
|
|
1518
|
-
iban: z.ZodString;
|
|
1519
|
-
lastSyncedAt: z.ZodCoercedDate<unknown>;
|
|
1520
|
-
}, z.core.$strip>;
|
|
1521
|
-
interface SetLastSyncAtInput extends z.infer<typeof setLastSyncAtInputSchema> {
|
|
1522
|
-
}
|
|
1523
|
-
type SetLastSyncAtOutput = void;
|
|
1524
|
-
|
|
1525
1516
|
declare const getBatchesInputSchema: z.ZodObject<{
|
|
1526
1517
|
page: z.ZodNumber;
|
|
1527
1518
|
limit: z.ZodNumber;
|
|
@@ -1969,8 +1960,8 @@ declare const updateAccountInputSchema: z.ZodObject<{
|
|
|
1969
1960
|
identity: undefined;
|
|
1970
1961
|
generated: undefined;
|
|
1971
1962
|
}, {}, {}>;
|
|
1972
|
-
|
|
1973
|
-
name: "
|
|
1963
|
+
lastSyncAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1964
|
+
name: "last_sync_at";
|
|
1974
1965
|
tableName: "account";
|
|
1975
1966
|
dataType: "date";
|
|
1976
1967
|
columnType: "SQLiteTimestamp";
|
|
@@ -1986,6 +1977,25 @@ declare const updateAccountInputSchema: z.ZodObject<{
|
|
|
1986
1977
|
identity: undefined;
|
|
1987
1978
|
generated: undefined;
|
|
1988
1979
|
}, {}, {}>;
|
|
1980
|
+
lastSyncMetadata: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1981
|
+
name: "last_sync_metadata";
|
|
1982
|
+
tableName: "account";
|
|
1983
|
+
dataType: "json";
|
|
1984
|
+
columnType: "SQLiteTextJson";
|
|
1985
|
+
data: LastSyncMetadata;
|
|
1986
|
+
driverParam: string;
|
|
1987
|
+
notNull: false;
|
|
1988
|
+
hasDefault: false;
|
|
1989
|
+
isPrimaryKey: false;
|
|
1990
|
+
isAutoincrement: false;
|
|
1991
|
+
hasRuntimeDefault: false;
|
|
1992
|
+
enumValues: undefined;
|
|
1993
|
+
baseColumn: never;
|
|
1994
|
+
identity: undefined;
|
|
1995
|
+
generated: undefined;
|
|
1996
|
+
}, {}, {
|
|
1997
|
+
$type: LastSyncMetadata;
|
|
1998
|
+
}>;
|
|
1989
1999
|
holderName: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1990
2000
|
name: "holder_name";
|
|
1991
2001
|
tableName: "account";
|
|
@@ -2297,7 +2307,8 @@ declare class BankServiceBase extends BankServiceBase_base {
|
|
|
2297
2307
|
bankRefId: string;
|
|
2298
2308
|
batchSizeLimit: number;
|
|
2299
2309
|
syncIntervalS: number;
|
|
2300
|
-
|
|
2310
|
+
lastSyncAt: Date | null;
|
|
2311
|
+
lastSyncMetadata: LastSyncMetadata | null;
|
|
2301
2312
|
holderName: string;
|
|
2302
2313
|
address: string | null;
|
|
2303
2314
|
swiftBic: string | null;
|
|
@@ -2346,7 +2357,6 @@ declare class BankServiceBase extends BankServiceBase_base {
|
|
|
2346
2357
|
getAuthUri(input: GetAuthUriInput): Promise<IRPCResponse<GetAuthUriOutput>>;
|
|
2347
2358
|
authorizeAccount(input: AuthorizeAccountInput): Promise<IRPCResponse<AuthorizeAccountOutput>>;
|
|
2348
2359
|
simulateDeposit(input: SimulateDepositInput): Promise<IRPCResponse<SimulateDepositOutput>>;
|
|
2349
|
-
setLastSyncAt(input: SetLastSyncAtInput): Promise<IRPCResponse<SetLastSyncAtOutput>>;
|
|
2350
2360
|
sendPayment(input: SendPaymentInput): Promise<IRPCResponse<SendPaymentOutput>>;
|
|
2351
2361
|
getBankAccounts(): Promise<IRPCResponse<GetAccountsOutput>>;
|
|
2352
2362
|
updateAccount(input: UpdateAccountInput): Promise<IRPCResponse<UpdateAccountOutput>>;
|
package/dist/export/worker.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { A as AccountSelectType, P as PaymentSelectType, B as BatchSelectType, L as LastSyncMetadata, C as ConfigEnvironmentBank, t as tables, I as IBankConnector, a as ConnectorKey, b as PaymentInsertType } from '../shared/bank.Cfz44GPA.mjs';
|
|
1
2
|
import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
|
|
2
3
|
import { WorkflowInstanceStatus, IRPCResponse } from '@develit-io/backend-sdk';
|
|
3
|
-
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
4
4
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
5
|
-
import {
|
|
6
|
-
import { A as AccountSelectType, C as ConfigEnvironmentBank, I as IBankConnector, a as ConnectorKey } from '../shared/bank.BOe_Qmuw.mjs';
|
|
5
|
+
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
7
6
|
import { z } from 'zod';
|
|
8
7
|
import * as drizzle_zod from 'drizzle-zod';
|
|
9
8
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
@@ -1514,14 +1513,6 @@ interface SimulateDepositInput extends z.infer<typeof simulateDepositInputSchema
|
|
|
1514
1513
|
interface SimulateDepositOutput extends PaymentSelectType {
|
|
1515
1514
|
}
|
|
1516
1515
|
|
|
1517
|
-
declare const setLastSyncAtInputSchema: z.ZodObject<{
|
|
1518
|
-
iban: z.ZodString;
|
|
1519
|
-
lastSyncedAt: z.ZodCoercedDate<unknown>;
|
|
1520
|
-
}, z.core.$strip>;
|
|
1521
|
-
interface SetLastSyncAtInput extends z.infer<typeof setLastSyncAtInputSchema> {
|
|
1522
|
-
}
|
|
1523
|
-
type SetLastSyncAtOutput = void;
|
|
1524
|
-
|
|
1525
1516
|
declare const getBatchesInputSchema: z.ZodObject<{
|
|
1526
1517
|
page: z.ZodNumber;
|
|
1527
1518
|
limit: z.ZodNumber;
|
|
@@ -1969,8 +1960,8 @@ declare const updateAccountInputSchema: z.ZodObject<{
|
|
|
1969
1960
|
identity: undefined;
|
|
1970
1961
|
generated: undefined;
|
|
1971
1962
|
}, {}, {}>;
|
|
1972
|
-
|
|
1973
|
-
name: "
|
|
1963
|
+
lastSyncAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1964
|
+
name: "last_sync_at";
|
|
1974
1965
|
tableName: "account";
|
|
1975
1966
|
dataType: "date";
|
|
1976
1967
|
columnType: "SQLiteTimestamp";
|
|
@@ -1986,6 +1977,25 @@ declare const updateAccountInputSchema: z.ZodObject<{
|
|
|
1986
1977
|
identity: undefined;
|
|
1987
1978
|
generated: undefined;
|
|
1988
1979
|
}, {}, {}>;
|
|
1980
|
+
lastSyncMetadata: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1981
|
+
name: "last_sync_metadata";
|
|
1982
|
+
tableName: "account";
|
|
1983
|
+
dataType: "json";
|
|
1984
|
+
columnType: "SQLiteTextJson";
|
|
1985
|
+
data: LastSyncMetadata;
|
|
1986
|
+
driverParam: string;
|
|
1987
|
+
notNull: false;
|
|
1988
|
+
hasDefault: false;
|
|
1989
|
+
isPrimaryKey: false;
|
|
1990
|
+
isAutoincrement: false;
|
|
1991
|
+
hasRuntimeDefault: false;
|
|
1992
|
+
enumValues: undefined;
|
|
1993
|
+
baseColumn: never;
|
|
1994
|
+
identity: undefined;
|
|
1995
|
+
generated: undefined;
|
|
1996
|
+
}, {}, {
|
|
1997
|
+
$type: LastSyncMetadata;
|
|
1998
|
+
}>;
|
|
1989
1999
|
holderName: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1990
2000
|
name: "holder_name";
|
|
1991
2001
|
tableName: "account";
|
|
@@ -2297,7 +2307,8 @@ declare class BankServiceBase extends BankServiceBase_base {
|
|
|
2297
2307
|
bankRefId: string;
|
|
2298
2308
|
batchSizeLimit: number;
|
|
2299
2309
|
syncIntervalS: number;
|
|
2300
|
-
|
|
2310
|
+
lastSyncAt: Date | null;
|
|
2311
|
+
lastSyncMetadata: LastSyncMetadata | null;
|
|
2301
2312
|
holderName: string;
|
|
2302
2313
|
address: string | null;
|
|
2303
2314
|
swiftBic: string | null;
|
|
@@ -2346,7 +2357,6 @@ declare class BankServiceBase extends BankServiceBase_base {
|
|
|
2346
2357
|
getAuthUri(input: GetAuthUriInput): Promise<IRPCResponse<GetAuthUriOutput>>;
|
|
2347
2358
|
authorizeAccount(input: AuthorizeAccountInput): Promise<IRPCResponse<AuthorizeAccountOutput>>;
|
|
2348
2359
|
simulateDeposit(input: SimulateDepositInput): Promise<IRPCResponse<SimulateDepositOutput>>;
|
|
2349
|
-
setLastSyncAt(input: SetLastSyncAtInput): Promise<IRPCResponse<SetLastSyncAtOutput>>;
|
|
2350
2360
|
sendPayment(input: SendPaymentInput): Promise<IRPCResponse<SendPaymentOutput>>;
|
|
2351
2361
|
getBankAccounts(): Promise<IRPCResponse<GetAccountsOutput>>;
|
|
2352
2362
|
updateAccount(input: UpdateAccountInput): Promise<IRPCResponse<UpdateAccountOutput>>;
|
package/dist/export/worker.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { A as AccountSelectType, P as PaymentSelectType, B as BatchSelectType, L as LastSyncMetadata, C as ConfigEnvironmentBank, t as tables, I as IBankConnector, a as ConnectorKey, b as PaymentInsertType } from '../shared/bank.Cfz44GPA.js';
|
|
1
2
|
import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
|
|
2
3
|
import { WorkflowInstanceStatus, IRPCResponse } from '@develit-io/backend-sdk';
|
|
3
|
-
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
4
4
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
5
|
-
import {
|
|
6
|
-
import { A as AccountSelectType, C as ConfigEnvironmentBank, I as IBankConnector, a as ConnectorKey } from '../shared/bank.2BgwPCw_.js';
|
|
5
|
+
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
7
6
|
import { z } from 'zod';
|
|
8
7
|
import * as drizzle_zod from 'drizzle-zod';
|
|
9
8
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
@@ -1514,14 +1513,6 @@ interface SimulateDepositInput extends z.infer<typeof simulateDepositInputSchema
|
|
|
1514
1513
|
interface SimulateDepositOutput extends PaymentSelectType {
|
|
1515
1514
|
}
|
|
1516
1515
|
|
|
1517
|
-
declare const setLastSyncAtInputSchema: z.ZodObject<{
|
|
1518
|
-
iban: z.ZodString;
|
|
1519
|
-
lastSyncedAt: z.ZodCoercedDate<unknown>;
|
|
1520
|
-
}, z.core.$strip>;
|
|
1521
|
-
interface SetLastSyncAtInput extends z.infer<typeof setLastSyncAtInputSchema> {
|
|
1522
|
-
}
|
|
1523
|
-
type SetLastSyncAtOutput = void;
|
|
1524
|
-
|
|
1525
1516
|
declare const getBatchesInputSchema: z.ZodObject<{
|
|
1526
1517
|
page: z.ZodNumber;
|
|
1527
1518
|
limit: z.ZodNumber;
|
|
@@ -1969,8 +1960,8 @@ declare const updateAccountInputSchema: z.ZodObject<{
|
|
|
1969
1960
|
identity: undefined;
|
|
1970
1961
|
generated: undefined;
|
|
1971
1962
|
}, {}, {}>;
|
|
1972
|
-
|
|
1973
|
-
name: "
|
|
1963
|
+
lastSyncAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1964
|
+
name: "last_sync_at";
|
|
1974
1965
|
tableName: "account";
|
|
1975
1966
|
dataType: "date";
|
|
1976
1967
|
columnType: "SQLiteTimestamp";
|
|
@@ -1986,6 +1977,25 @@ declare const updateAccountInputSchema: z.ZodObject<{
|
|
|
1986
1977
|
identity: undefined;
|
|
1987
1978
|
generated: undefined;
|
|
1988
1979
|
}, {}, {}>;
|
|
1980
|
+
lastSyncMetadata: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1981
|
+
name: "last_sync_metadata";
|
|
1982
|
+
tableName: "account";
|
|
1983
|
+
dataType: "json";
|
|
1984
|
+
columnType: "SQLiteTextJson";
|
|
1985
|
+
data: LastSyncMetadata;
|
|
1986
|
+
driverParam: string;
|
|
1987
|
+
notNull: false;
|
|
1988
|
+
hasDefault: false;
|
|
1989
|
+
isPrimaryKey: false;
|
|
1990
|
+
isAutoincrement: false;
|
|
1991
|
+
hasRuntimeDefault: false;
|
|
1992
|
+
enumValues: undefined;
|
|
1993
|
+
baseColumn: never;
|
|
1994
|
+
identity: undefined;
|
|
1995
|
+
generated: undefined;
|
|
1996
|
+
}, {}, {
|
|
1997
|
+
$type: LastSyncMetadata;
|
|
1998
|
+
}>;
|
|
1989
1999
|
holderName: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
1990
2000
|
name: "holder_name";
|
|
1991
2001
|
tableName: "account";
|
|
@@ -2297,7 +2307,8 @@ declare class BankServiceBase extends BankServiceBase_base {
|
|
|
2297
2307
|
bankRefId: string;
|
|
2298
2308
|
batchSizeLimit: number;
|
|
2299
2309
|
syncIntervalS: number;
|
|
2300
|
-
|
|
2310
|
+
lastSyncAt: Date | null;
|
|
2311
|
+
lastSyncMetadata: LastSyncMetadata | null;
|
|
2301
2312
|
holderName: string;
|
|
2302
2313
|
address: string | null;
|
|
2303
2314
|
swiftBic: string | null;
|
|
@@ -2346,7 +2357,6 @@ declare class BankServiceBase extends BankServiceBase_base {
|
|
|
2346
2357
|
getAuthUri(input: GetAuthUriInput): Promise<IRPCResponse<GetAuthUriOutput>>;
|
|
2347
2358
|
authorizeAccount(input: AuthorizeAccountInput): Promise<IRPCResponse<AuthorizeAccountOutput>>;
|
|
2348
2359
|
simulateDeposit(input: SimulateDepositInput): Promise<IRPCResponse<SimulateDepositOutput>>;
|
|
2349
|
-
setLastSyncAt(input: SetLastSyncAtInput): Promise<IRPCResponse<SetLastSyncAtOutput>>;
|
|
2350
2360
|
sendPayment(input: SendPaymentInput): Promise<IRPCResponse<SendPaymentOutput>>;
|
|
2351
2361
|
getBankAccounts(): Promise<IRPCResponse<GetAccountsOutput>>;
|
|
2352
2362
|
updateAccount(input: UpdateAccountInput): Promise<IRPCResponse<UpdateAccountOutput>>;
|
package/dist/export/worker.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { uuidv4, bankAccountMetadataSchema, workflowInstanceStatusSchema, develitWorker, createInternalError, first, action, service } from '@develit-io/backend-sdk';
|
|
2
2
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
3
3
|
import { drizzle } from 'drizzle-orm/d1';
|
|
4
|
-
import { t as tables, c as INSTRUCTION_PRIORITIES, C as CHARGE_BEARERS, P as PAYMENT_TYPES, g as CONNECTOR_KEYS, B as BATCH_STATUSES, d as PAYMENT_STATUSES, e as PAYMENT_DIRECTIONS, i as accountInsertSchema, M as MockConnector, F as FinbricksConnector, E as ErsteConnector } from '../shared/bank.
|
|
4
|
+
import { t as tables, c as INSTRUCTION_PRIORITIES, C as CHARGE_BEARERS, P as PAYMENT_TYPES, g as CONNECTOR_KEYS, B as BATCH_STATUSES, d as PAYMENT_STATUSES, e as PAYMENT_DIRECTIONS, i as accountInsertSchema, M as MockConnector, F as FinbricksConnector, E as ErsteConnector } from '../shared/bank.DXn9jD0Q.mjs';
|
|
5
5
|
import 'jose';
|
|
6
6
|
import { CURRENCY_CODES } from '@develit-io/general-codes';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import {
|
|
8
|
+
import { e as encrypt, i as importAesKey, g as getCredentialsByAccountId, a as initiateConnector, c as createPaymentCommand } from '../shared/bank.BvUtf1S3.mjs';
|
|
9
9
|
import { eq, inArray, and, sql, asc, desc, gte, lte } from 'drizzle-orm';
|
|
10
10
|
import 'drizzle-orm/sqlite-core';
|
|
11
11
|
import 'date-fns';
|
|
12
12
|
import 'drizzle-zod';
|
|
13
13
|
import 'drizzle-orm/relations';
|
|
14
|
-
import '../shared/bank.
|
|
14
|
+
import '../shared/bank.DKtu6cfY.mjs';
|
|
15
15
|
|
|
16
16
|
const upsertAccountCommand = (db, { account }) => {
|
|
17
17
|
const id = account.id || uuidv4();
|
|
@@ -27,6 +27,12 @@ const upsertAccountCommand = (db, { account }) => {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
const updatePaymentCommand = (db, { payment }) => {
|
|
31
|
+
return {
|
|
32
|
+
command: db.update(tables.payment).set(payment).where(eq(tables.payment.id, payment.id)).returning()
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
30
36
|
const upsertBatchCommand = (db, { batch }) => {
|
|
31
37
|
const id = batch.id || uuidv4();
|
|
32
38
|
const command = db.insert(tables.batch).values({
|
|
@@ -71,9 +77,14 @@ const expireOneTimeTokenCommand = (db, {
|
|
|
71
77
|
};
|
|
72
78
|
};
|
|
73
79
|
|
|
74
|
-
const createAccountCredentialsCommand = (db, { credentials }) => {
|
|
80
|
+
const createAccountCredentialsCommand = async (db, encryptionKey, { credentials }) => {
|
|
75
81
|
const id = credentials.id || uuidv4();
|
|
76
|
-
const
|
|
82
|
+
const encryptedValue = await encrypt(credentials.value, encryptionKey);
|
|
83
|
+
const command = db.insert(tables.accountCredentials).values({
|
|
84
|
+
...credentials,
|
|
85
|
+
id,
|
|
86
|
+
value: encryptedValue
|
|
87
|
+
}).returning();
|
|
77
88
|
return {
|
|
78
89
|
id,
|
|
79
90
|
command
|
|
@@ -278,11 +289,6 @@ const simulateDepositInputSchema = z.object({
|
|
|
278
289
|
connectorKey: z.enum(CONNECTOR_KEYS)
|
|
279
290
|
});
|
|
280
291
|
|
|
281
|
-
const setLastSyncAtInputSchema = z.object({
|
|
282
|
-
iban: z.string(),
|
|
283
|
-
lastSyncedAt: z.coerce.date()
|
|
284
|
-
});
|
|
285
|
-
|
|
286
292
|
const ALLOWED_BATCH_FILTERS = {
|
|
287
293
|
ACCOUNT_ID: "filterBatchAccountId",
|
|
288
294
|
STATUS: "filterBatchStatus"
|
|
@@ -396,11 +402,16 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
396
402
|
const accountsForConnector = accounts.filter(
|
|
397
403
|
(acc) => acc.connectorKey === connectorKey
|
|
398
404
|
);
|
|
405
|
+
const encryptionKey = await importAesKey(this.env.ENCRYPTION_KEY);
|
|
399
406
|
const accountsWithCredentials = await Promise.all(
|
|
400
407
|
accountsForConnector.map(async (acc) => {
|
|
401
|
-
const credentials = await getCredentialsByAccountId(
|
|
402
|
-
|
|
403
|
-
|
|
408
|
+
const credentials = await getCredentialsByAccountId(
|
|
409
|
+
this.db,
|
|
410
|
+
encryptionKey,
|
|
411
|
+
{
|
|
412
|
+
accountId: acc.id
|
|
413
|
+
}
|
|
414
|
+
);
|
|
404
415
|
if (!credentials) {
|
|
405
416
|
throw createInternalError(null, {
|
|
406
417
|
message: `No credentials found for account ${acc.id}`
|
|
@@ -572,6 +583,8 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
572
583
|
(payment) => {
|
|
573
584
|
return {
|
|
574
585
|
id: uuidv4(),
|
|
586
|
+
bankRefId: uuidv4(),
|
|
587
|
+
//TODO(kleinpetr): we won't create payment here (only via sync script)
|
|
575
588
|
correlationId: payment.correlationId,
|
|
576
589
|
refId: payment.refId,
|
|
577
590
|
amount: payment.amount,
|
|
@@ -855,11 +868,14 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
855
868
|
accountId: acc.id
|
|
856
869
|
}).command
|
|
857
870
|
);
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
871
|
+
const encryptionKey = await importAesKey(this.env.ENCRYPTION_KEY);
|
|
872
|
+
const createAccountCredentials = (await Promise.all(
|
|
873
|
+
credentials.map(
|
|
874
|
+
async (cr) => createAccountCredentialsCommand(this.db, encryptionKey, {
|
|
875
|
+
credentials: cr
|
|
876
|
+
})
|
|
877
|
+
)
|
|
878
|
+
)).map((cmd) => cmd.command);
|
|
863
879
|
const { command: updateOtt } = expireOneTimeTokenCommand(this.db, {
|
|
864
880
|
ott
|
|
865
881
|
});
|
|
@@ -908,6 +924,7 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
908
924
|
});
|
|
909
925
|
const payment = {
|
|
910
926
|
id: uuidv4(),
|
|
927
|
+
bankRefId: uuidv4(),
|
|
911
928
|
correlationId: uuidv4(),
|
|
912
929
|
amount,
|
|
913
930
|
connectorKey,
|
|
@@ -945,27 +962,6 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
945
962
|
}
|
|
946
963
|
);
|
|
947
964
|
}
|
|
948
|
-
async setLastSyncAt(input) {
|
|
949
|
-
return this.handleAction(
|
|
950
|
-
{ data: input, schema: setLastSyncAtInputSchema },
|
|
951
|
-
{ successMessage: "Last sync set." },
|
|
952
|
-
async ({ iban, lastSyncedAt }) => {
|
|
953
|
-
const account = await getAccountByIbanQuery(this.db, {
|
|
954
|
-
iban
|
|
955
|
-
});
|
|
956
|
-
if (!account) {
|
|
957
|
-
throw createInternalError(null, {
|
|
958
|
-
status: 404,
|
|
959
|
-
message: "Account for this organization does not exist."
|
|
960
|
-
});
|
|
961
|
-
}
|
|
962
|
-
await updateAccountLastSyncCommand(this.db, {
|
|
963
|
-
accountId: account.id,
|
|
964
|
-
lastSyncedAt
|
|
965
|
-
}).command.execute();
|
|
966
|
-
}
|
|
967
|
-
);
|
|
968
|
-
}
|
|
969
965
|
async sendPayment(input) {
|
|
970
966
|
return this.handleAction(
|
|
971
967
|
{ data: input, schema: sendPaymentInputSchema },
|
|
@@ -1074,9 +1070,6 @@ __decorateClass([
|
|
|
1074
1070
|
__decorateClass([
|
|
1075
1071
|
action("simulate-deposit")
|
|
1076
1072
|
], BankServiceBase.prototype, "simulateDeposit", 1);
|
|
1077
|
-
__decorateClass([
|
|
1078
|
-
action("set-last-sync-at")
|
|
1079
|
-
], BankServiceBase.prototype, "setLastSyncAt", 1);
|
|
1080
1073
|
__decorateClass([
|
|
1081
1074
|
action("send-payment")
|
|
1082
1075
|
], BankServiceBase.prototype, "sendPayment", 1);
|