@develit-services/bank 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/database/schema.cjs +2 -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 +2 -1
- package/dist/export/worker.cjs +204 -162
- package/dist/export/worker.d.cts +135 -27
- package/dist/export/worker.d.mts +135 -27
- package/dist/export/worker.d.ts +135 -27
- package/dist/export/worker.mjs +196 -154
- package/dist/export/workflows.cjs +12 -14
- package/dist/export/workflows.d.cts +10 -3
- package/dist/export/workflows.d.mts +10 -3
- package/dist/export/workflows.d.ts +10 -3
- package/dist/export/workflows.mjs +7 -9
- package/dist/export/wrangler.cjs +7 -2
- package/dist/export/wrangler.mjs +7 -2
- package/dist/shared/{bank.CyinOg3r.cjs → bank.BGuS_o9V.cjs} +1 -1
- package/dist/shared/bank.CIJDq7GL.cjs +401 -0
- package/dist/shared/{bank.NdqOkgpd.cjs → bank.CpcK1Dse.cjs} +12 -8
- package/dist/shared/{bank.DKtu6cfY.mjs → bank.CthUj-ff.mjs} +1 -1
- package/dist/shared/{bank.DXn9jD0Q.mjs → bank.lZMrqjVR.mjs} +12 -8
- package/dist/shared/bank.mZtcXaJo.mjs +391 -0
- package/dist/shared/{bank.Cfz44GPA.d.ts → bank.xrXNjWCo.d.cts} +109 -14
- package/dist/shared/{bank.Cfz44GPA.d.cts → bank.xrXNjWCo.d.mts} +109 -14
- package/dist/shared/{bank.Cfz44GPA.d.mts → bank.xrXNjWCo.d.ts} +109 -14
- package/dist/types.cjs +3 -2
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/types.mjs +3 -2
- package/package.json +1 -1
- package/dist/shared/bank.BvUtf1S3.mjs +0 -130
- package/dist/shared/bank.CHS79KTx.cjs +0 -136
package/dist/database/schema.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const database_schema = require('../shared/bank.
|
|
3
|
+
const database_schema = require('../shared/bank.CpcK1Dse.cjs');
|
|
4
4
|
require('@develit-io/backend-sdk');
|
|
5
5
|
require('drizzle-orm/sqlite-core');
|
|
6
6
|
require('date-fns');
|
|
@@ -9,6 +9,7 @@ require('jose');
|
|
|
9
9
|
require('@develit-io/general-codes');
|
|
10
10
|
require('drizzle-zod');
|
|
11
11
|
require('drizzle-orm/relations');
|
|
12
|
+
require('node:crypto');
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a9 as account, aa as accountCredentials, a5 as batch, a8 as ott, a6 as payment, a7 as paymentRelations } from '../shared/bank.
|
|
1
|
+
export { a9 as account, aa as accountCredentials, a5 as batch, a8 as ott, a6 as payment, a7 as paymentRelations } from '../shared/bank.xrXNjWCo.cjs';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import 'drizzle-zod';
|
|
4
4
|
import 'drizzle-orm/sqlite-core';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a9 as account, aa as accountCredentials, a5 as batch, a8 as ott, a6 as payment, a7 as paymentRelations } from '../shared/bank.
|
|
1
|
+
export { a9 as account, aa as accountCredentials, a5 as batch, a8 as ott, a6 as payment, a7 as paymentRelations } from '../shared/bank.xrXNjWCo.mjs';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import 'drizzle-zod';
|
|
4
4
|
import 'drizzle-orm/sqlite-core';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a9 as account, aa as accountCredentials, a5 as batch, a8 as ott, a6 as payment, a7 as paymentRelations } from '../shared/bank.
|
|
1
|
+
export { a9 as account, aa as accountCredentials, a5 as batch, a8 as ott, a6 as payment, a7 as paymentRelations } from '../shared/bank.xrXNjWCo.js';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import 'drizzle-zod';
|
|
4
4
|
import 'drizzle-orm/sqlite-core';
|
package/dist/database/schema.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { y as account, z as accountCredentials, r as batch, x as ott, v as payment, w as paymentRelations } from '../shared/bank.
|
|
1
|
+
export { y as account, z as accountCredentials, r as batch, x as ott, v as payment, w as paymentRelations } from '../shared/bank.lZMrqjVR.mjs';
|
|
2
2
|
import '@develit-io/backend-sdk';
|
|
3
3
|
import 'drizzle-orm/sqlite-core';
|
|
4
4
|
import 'date-fns';
|
|
@@ -7,3 +7,4 @@ import 'jose';
|
|
|
7
7
|
import '@develit-io/general-codes';
|
|
8
8
|
import 'drizzle-zod';
|
|
9
9
|
import 'drizzle-orm/relations';
|
|
10
|
+
import 'node:crypto';
|
package/dist/export/worker.cjs
CHANGED
|
@@ -3,17 +3,19 @@
|
|
|
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.CpcK1Dse.cjs');
|
|
7
7
|
require('jose');
|
|
8
8
|
const generalCodes = require('@develit-io/general-codes');
|
|
9
9
|
const zod = require('zod');
|
|
10
|
-
const
|
|
10
|
+
const processBatch_workflow = require('../shared/bank.CIJDq7GL.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('
|
|
16
|
+
require('node:crypto');
|
|
17
|
+
require('cloudflare:workflows');
|
|
18
|
+
require('../shared/bank.BGuS_o9V.cjs');
|
|
17
19
|
|
|
18
20
|
const upsertAccountCommand = (db, { account }) => {
|
|
19
21
|
const id = account.id || backendSdk.uuidv4();
|
|
@@ -29,29 +31,6 @@ const upsertAccountCommand = (db, { account }) => {
|
|
|
29
31
|
};
|
|
30
32
|
};
|
|
31
33
|
|
|
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
|
-
|
|
38
|
-
const upsertBatchCommand = (db, { batch }) => {
|
|
39
|
-
const id = batch.id || backendSdk.uuidv4();
|
|
40
|
-
const command = db.insert(database_schema.tables.batch).values({
|
|
41
|
-
...batch,
|
|
42
|
-
id
|
|
43
|
-
}).onConflictDoUpdate({
|
|
44
|
-
target: database_schema.tables.batch.id,
|
|
45
|
-
set: {
|
|
46
|
-
...batch
|
|
47
|
-
}
|
|
48
|
-
}).returning();
|
|
49
|
-
return {
|
|
50
|
-
id,
|
|
51
|
-
command
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
|
|
55
34
|
const createOneTimeTokenCommand = (db, {
|
|
56
35
|
ott,
|
|
57
36
|
refId,
|
|
@@ -69,6 +48,12 @@ const createOneTimeTokenCommand = (db, {
|
|
|
69
48
|
return { id, command };
|
|
70
49
|
};
|
|
71
50
|
|
|
51
|
+
const updateAccountCommand = (db, { account }) => {
|
|
52
|
+
return {
|
|
53
|
+
command: db.update(database_schema.tables.account).set({ ...account }).where(drizzleOrm.eq(database_schema.tables.account.id, account.id)).returning()
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
72
57
|
const expireOneTimeTokenCommand = (db, {
|
|
73
58
|
ott
|
|
74
59
|
}) => {
|
|
@@ -81,7 +66,7 @@ const expireOneTimeTokenCommand = (db, {
|
|
|
81
66
|
|
|
82
67
|
const createAccountCredentialsCommand = async (db, encryptionKey, { credentials }) => {
|
|
83
68
|
const id = credentials.id || backendSdk.uuidv4();
|
|
84
|
-
const encryptedValue = await
|
|
69
|
+
const encryptedValue = await processBatch_workflow.encrypt(credentials.value, encryptionKey);
|
|
85
70
|
const command = db.insert(database_schema.tables.accountCredentials).values({
|
|
86
71
|
...credentials,
|
|
87
72
|
id,
|
|
@@ -100,6 +85,15 @@ const deleteAccountCredentialsCommand = (db, { accountId }) => {
|
|
|
100
85
|
};
|
|
101
86
|
};
|
|
102
87
|
|
|
88
|
+
const deletePaymentsByAccountCommand = (db, { accountId }) => {
|
|
89
|
+
const command = db.update(database_schema.tables.payment).set({
|
|
90
|
+
deletedAt: /* @__PURE__ */ new Date()
|
|
91
|
+
}).where(drizzleOrm.eq(database_schema.tables.payment.accountId, accountId));
|
|
92
|
+
return {
|
|
93
|
+
command
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
103
97
|
const getAccountByIbanQuery = async (db, { iban }) => {
|
|
104
98
|
return await db.select().from(database_schema.tables.account).where(drizzleOrm.eq(database_schema.tables.account.iban, iban)).get();
|
|
105
99
|
};
|
|
@@ -118,13 +112,7 @@ const getAllAccountsQuery = async (db) => {
|
|
|
118
112
|
};
|
|
119
113
|
|
|
120
114
|
const getAllPendingBatchesQuery = (db) => {
|
|
121
|
-
return db.select().from(database_schema.tables.batch).where(
|
|
122
|
-
drizzleOrm.inArray(database_schema.tables.batch.status, [
|
|
123
|
-
"PROCESSING",
|
|
124
|
-
"READY_TO_SIGN",
|
|
125
|
-
"WAITING_FOR_PROCESSING"
|
|
126
|
-
])
|
|
127
|
-
);
|
|
115
|
+
return db.select().from(database_schema.tables.batch).where(drizzleOrm.inArray(database_schema.tables.batch.status, ["READY_TO_SIGN"]));
|
|
128
116
|
};
|
|
129
117
|
|
|
130
118
|
const buildMultiFilterConditions = (column, value) => {
|
|
@@ -154,6 +142,7 @@ const getPaymentsWithPaginationQuery = async (db, {
|
|
|
154
142
|
limit,
|
|
155
143
|
page,
|
|
156
144
|
sort,
|
|
145
|
+
ids,
|
|
157
146
|
filterPaymentAccountId,
|
|
158
147
|
filterPaymentAmount,
|
|
159
148
|
filterPaymentCurrency,
|
|
@@ -178,7 +167,8 @@ const getPaymentsWithPaginationQuery = async (db, {
|
|
|
178
167
|
buildMultiFilterConditions(
|
|
179
168
|
database_schema.tables.payment.direction,
|
|
180
169
|
filterPaymentyDirection
|
|
181
|
-
)
|
|
170
|
+
),
|
|
171
|
+
buildMultiFilterConditions(database_schema.tables.payment.id, ids)
|
|
182
172
|
);
|
|
183
173
|
const sortColumn = resolveColumn(database_schema.tables.payment, sort.column);
|
|
184
174
|
const [{ totalCount }] = await db.select({
|
|
@@ -226,11 +216,6 @@ const getOttQuery = async (db, { ott }) => {
|
|
|
226
216
|
return await db.select().from(database_schema.tables.ott).where(drizzleOrm.eq(database_schema.tables.ott.oneTimeToken, ott)).get();
|
|
227
217
|
};
|
|
228
218
|
|
|
229
|
-
const getPaymentByRefIdQuery = async (db, { refId }) => {
|
|
230
|
-
const payment = await db.select().from(database_schema.tables.payment).where(drizzleOrm.eq(database_schema.tables.payment.refId, refId)).limit(1).get();
|
|
231
|
-
return payment;
|
|
232
|
-
};
|
|
233
|
-
|
|
234
219
|
const seperateSupportedPayments = (mappedPayments, accounts) => {
|
|
235
220
|
const [supportedPayments, unsupportedPayments] = mappedPayments.reduce(
|
|
236
221
|
([valid, invalid], payment) => {
|
|
@@ -307,8 +292,43 @@ const getBatchesInputSchema = zod.z.object({
|
|
|
307
292
|
});
|
|
308
293
|
|
|
309
294
|
const processBatchInputSchema = zod.z.object({
|
|
310
|
-
|
|
311
|
-
|
|
295
|
+
batchId: zod.z.uuid()
|
|
296
|
+
});
|
|
297
|
+
zod.z.object({
|
|
298
|
+
instanceId: zod.z.string(),
|
|
299
|
+
details: backendSdk.workflowInstanceStatusSchema
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
const processBatchStatusInputSchema = zod.z.object({
|
|
303
|
+
batchId: zod.z.uuid()
|
|
304
|
+
});
|
|
305
|
+
zod.z.object({
|
|
306
|
+
instanceId: zod.z.string(),
|
|
307
|
+
details: backendSdk.workflowInstanceStatusSchema
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
const processBatchRestartInputSchema = zod.z.object({
|
|
311
|
+
batchId: zod.z.uuid()
|
|
312
|
+
});
|
|
313
|
+
zod.z.object({
|
|
314
|
+
instanceId: zod.z.string(),
|
|
315
|
+
details: backendSdk.workflowInstanceStatusSchema
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const batchAuthorizedEventPayloadSchema = zod.z.object({
|
|
319
|
+
authorized: zod.z.boolean()
|
|
320
|
+
});
|
|
321
|
+
const processBatchEventInputSchema = zod.z.discriminatedUnion("eventType", [
|
|
322
|
+
zod.z.object({
|
|
323
|
+
batchId: zod.z.uuid(),
|
|
324
|
+
eventType: zod.z.literal(processBatch_workflow.PROCESS_BATCH_WORKFLOW_EVENTS.batchAuthorized),
|
|
325
|
+
payload: batchAuthorizedEventPayloadSchema
|
|
326
|
+
})
|
|
327
|
+
// Future event types can be added here as new objects in the array
|
|
328
|
+
]);
|
|
329
|
+
zod.z.object({
|
|
330
|
+
success: zod.z.boolean(),
|
|
331
|
+
message: zod.z.string()
|
|
312
332
|
});
|
|
313
333
|
|
|
314
334
|
const ALLOWED_PAYMENT_FILTERS = {
|
|
@@ -327,6 +347,7 @@ const getPaymentsInputSchema = zod.z.object({
|
|
|
327
347
|
column: zod.z.enum(["createdAt", "updatedAt", "amount"]),
|
|
328
348
|
direction: zod.z.enum(["asc", "desc"])
|
|
329
349
|
}),
|
|
350
|
+
ids: zod.z.array(zod.z.uuid()).optional(),
|
|
330
351
|
[ALLOWED_PAYMENT_FILTERS.ACCOUNT_ID]: zod.z.union([zod.z.uuid(), zod.z.uuid().array()]).optional(),
|
|
331
352
|
[ALLOWED_PAYMENT_FILTERS.AMOUNT]: zod.z.union([zod.z.number(), zod.z.number().array()]).optional(),
|
|
332
353
|
[ALLOWED_PAYMENT_FILTERS.CURRENCY]: zod.z.union([zod.z.enum(generalCodes.CURRENCY_CODES), zod.z.enum(generalCodes.CURRENCY_CODES).array()]).optional(),
|
|
@@ -371,6 +392,10 @@ const updateAccountInputSchema = zod.z.object({
|
|
|
371
392
|
account: database_schema.accountInsertSchema
|
|
372
393
|
});
|
|
373
394
|
|
|
395
|
+
const disconnectAccountInputSchema = zod.z.object({
|
|
396
|
+
accountId: zod.z.uuid()
|
|
397
|
+
});
|
|
398
|
+
|
|
374
399
|
var __defProp = Object.defineProperty;
|
|
375
400
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
376
401
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
@@ -404,10 +429,10 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
404
429
|
const accountsForConnector = accounts.filter(
|
|
405
430
|
(acc) => acc.connectorKey === connectorKey
|
|
406
431
|
);
|
|
407
|
-
const encryptionKey = await
|
|
432
|
+
const encryptionKey = await processBatch_workflow.importAesKey(this.env.ENCRYPTION_KEY);
|
|
408
433
|
const accountsWithCredentials = await Promise.all(
|
|
409
434
|
accountsForConnector.map(async (acc) => {
|
|
410
|
-
const credentials = await
|
|
435
|
+
const credentials = await processBatch_workflow.getCredentialsByAccountId(
|
|
411
436
|
this.db,
|
|
412
437
|
encryptionKey,
|
|
413
438
|
{
|
|
@@ -428,7 +453,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
428
453
|
};
|
|
429
454
|
})
|
|
430
455
|
);
|
|
431
|
-
this.bankConnector =
|
|
456
|
+
this.bankConnector = processBatch_workflow.initiateConnector({
|
|
432
457
|
bank: connectorKey,
|
|
433
458
|
connectedAccounts: accountsWithCredentials,
|
|
434
459
|
env: this.env
|
|
@@ -562,18 +587,34 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
562
587
|
finalBatches.push(...updatedBatches);
|
|
563
588
|
}
|
|
564
589
|
const updateBatchesCommands = finalBatches.map((batch) => {
|
|
565
|
-
const { command } = upsertBatchCommand(this.db, {
|
|
590
|
+
const { command } = processBatch_workflow.upsertBatchCommand(this.db, {
|
|
566
591
|
batch: {
|
|
567
592
|
...batch
|
|
568
593
|
}
|
|
569
594
|
});
|
|
570
595
|
return command;
|
|
571
596
|
});
|
|
572
|
-
console.log("Updated batches", finalBatches);
|
|
573
597
|
await this.db.batch([
|
|
574
598
|
updateBatchesCommands[0],
|
|
575
599
|
...updateBatchesCommands.slice(1)
|
|
576
600
|
]);
|
|
601
|
+
for (const batch of finalBatches) {
|
|
602
|
+
try {
|
|
603
|
+
const instance = await this.env.PROCESS_BATCH_WORKFLOW.get(batch.id);
|
|
604
|
+
if (batch.status === "SIGNED" || batch.status === "SIGNATURE_FAILED") {
|
|
605
|
+
instance.sendEvent({
|
|
606
|
+
type: processBatch_workflow.PROCESS_BATCH_WORKFLOW_EVENTS.batchAuthorized,
|
|
607
|
+
payload: {
|
|
608
|
+
authorized: batch.status === "SIGNED"
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
} catch (_) {
|
|
613
|
+
console.log(
|
|
614
|
+
`No workflow instance found for batch ${batch.id}, skipping.`
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
577
618
|
console.log("Batch update completed");
|
|
578
619
|
}
|
|
579
620
|
async addPaymentsToBatch({
|
|
@@ -652,7 +693,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
652
693
|
this.log({
|
|
653
694
|
message: availableBatch ? `\u{1F504} Found existing OPEN batches for account ${acc.id}, merging ${availableBatch.payments.length} existing + ${newPayments.length} new payments` : `\u2728 Creating new batch for account ${acc.id} with ${newPayments.length} payments`
|
|
654
695
|
});
|
|
655
|
-
const { command } = upsertBatchCommand(this.db, {
|
|
696
|
+
const { command } = processBatch_workflow.upsertBatchCommand(this.db, {
|
|
656
697
|
batch: availableBatch ? {
|
|
657
698
|
...availableBatch,
|
|
658
699
|
payments: [...availableBatch.payments, ...newPayments]
|
|
@@ -675,122 +716,62 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
675
716
|
async processBatch(input) {
|
|
676
717
|
return this.handleAction(
|
|
677
718
|
{ data: input, schema: processBatchInputSchema },
|
|
678
|
-
{},
|
|
679
|
-
async ({
|
|
680
|
-
await
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
719
|
+
{ successMessage: "Batch processing workflow started" },
|
|
720
|
+
async ({ batchId }) => {
|
|
721
|
+
const instance = await this.env.PROCESS_BATCH_WORKFLOW.create({
|
|
722
|
+
id: batchId,
|
|
723
|
+
params: {
|
|
724
|
+
batchId
|
|
684
725
|
}
|
|
685
|
-
}).command.execute();
|
|
686
|
-
await this._initiateBankConnector({ connectorKey });
|
|
687
|
-
if (!this.bankConnector) {
|
|
688
|
-
await upsertBatchCommand(this.db, {
|
|
689
|
-
batch: {
|
|
690
|
-
...batch,
|
|
691
|
-
status: "FAILED"
|
|
692
|
-
}
|
|
693
|
-
}).command.execute();
|
|
694
|
-
throw backendSdk.createInternalError(null, {
|
|
695
|
-
message: `\u274C Failed to initialize ${connectorKey} bank connector`
|
|
696
|
-
});
|
|
697
|
-
}
|
|
698
|
-
this.log({
|
|
699
|
-
message: `\u2705 Bank connector initialized successfully for account ${connectorKey}`
|
|
700
726
|
});
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
failedPayments: []
|
|
727
|
+
return {
|
|
728
|
+
instanceId: instance.id,
|
|
729
|
+
details: await instance.status()
|
|
705
730
|
};
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
await
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
]
|
|
746
|
-
});
|
|
747
|
-
console.log(authorizationUrls, "AUTH URIS FROM BANK");
|
|
748
|
-
if (!authorizationUrls.length) {
|
|
749
|
-
this.logError({ message: "Failed to retrieve signing URI" });
|
|
750
|
-
await upsertBatchCommand(this.db, {
|
|
751
|
-
batch: {
|
|
752
|
-
...batch,
|
|
753
|
-
status: "FAILED"
|
|
754
|
-
}
|
|
755
|
-
}).command.execute();
|
|
756
|
-
return;
|
|
757
|
-
}
|
|
758
|
-
const { command: upsertBatch } = upsertBatchCommand(this.db, {
|
|
759
|
-
batch: {
|
|
760
|
-
...batch,
|
|
761
|
-
payments,
|
|
762
|
-
metadata,
|
|
763
|
-
status: "READY_TO_SIGN",
|
|
764
|
-
authorizationUrls,
|
|
765
|
-
batchPaymentInitiatedAt: /* @__PURE__ */ new Date()
|
|
766
|
-
}
|
|
767
|
-
});
|
|
768
|
-
const updatePayments = payments.map(
|
|
769
|
-
(payment) => updatePaymentCommand(this.db, {
|
|
770
|
-
payment: { ...payment, status: "INITIALIZED" }
|
|
771
|
-
}).command
|
|
772
|
-
);
|
|
773
|
-
await this.db.batch([upsertBatch, ...updatePayments]);
|
|
774
|
-
this.log({
|
|
775
|
-
message: "Authorization Urls for batch to create",
|
|
776
|
-
authorizationUrl: authorizationUrls[0]
|
|
777
|
-
});
|
|
778
|
-
await this.pushToQueue(this.env.NOTIFICATIONS_QUEUE, {
|
|
779
|
-
type: "email",
|
|
780
|
-
payload: {
|
|
781
|
-
email: {
|
|
782
|
-
to: [this.env.BANK_AUTH_RECIPIENT],
|
|
783
|
-
subject: "Payment Authorization",
|
|
784
|
-
text: authorizationUrls[0] || "No Authorization Url"
|
|
785
|
-
}
|
|
786
|
-
},
|
|
787
|
-
metadata: {
|
|
788
|
-
initiator: {
|
|
789
|
-
service: this.name
|
|
790
|
-
}
|
|
791
|
-
}
|
|
731
|
+
}
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
async processBatchStatus(input) {
|
|
735
|
+
return this.handleAction(
|
|
736
|
+
{ data: input, schema: processBatchStatusInputSchema },
|
|
737
|
+
{ successMessage: "Batch processing workflow status retrieved" },
|
|
738
|
+
async ({ batchId }) => {
|
|
739
|
+
const instance = await this.env.PROCESS_BATCH_WORKFLOW.get(batchId);
|
|
740
|
+
return {
|
|
741
|
+
instanceId: instance.id,
|
|
742
|
+
details: await instance.status()
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
async processBatchRestart(input) {
|
|
748
|
+
return this.handleAction(
|
|
749
|
+
{ data: input, schema: processBatchRestartInputSchema },
|
|
750
|
+
{ successMessage: "Batch processing workflow restarted" },
|
|
751
|
+
async ({ batchId }) => {
|
|
752
|
+
const instance = await this.env.PROCESS_BATCH_WORKFLOW.get(batchId);
|
|
753
|
+
await instance.restart();
|
|
754
|
+
return {
|
|
755
|
+
instanceId: instance.id,
|
|
756
|
+
details: await instance.status()
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
);
|
|
760
|
+
}
|
|
761
|
+
async processBatchEvent(input) {
|
|
762
|
+
return this.handleAction(
|
|
763
|
+
{ data: input, schema: processBatchEventInputSchema },
|
|
764
|
+
{ successMessage: "Event sent to batch processing workflow" },
|
|
765
|
+
async ({ batchId, eventType, payload }) => {
|
|
766
|
+
const instance = await this.env.PROCESS_BATCH_WORKFLOW.get(batchId);
|
|
767
|
+
await instance.sendEvent({
|
|
768
|
+
type: eventType,
|
|
769
|
+
payload
|
|
792
770
|
});
|
|
793
|
-
|
|
771
|
+
return {
|
|
772
|
+
success: true,
|
|
773
|
+
message: `Event '${eventType}' sent to workflow instance ${batchId}`
|
|
774
|
+
};
|
|
794
775
|
}
|
|
795
776
|
);
|
|
796
777
|
}
|
|
@@ -870,7 +851,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
870
851
|
accountId: acc.id
|
|
871
852
|
}).command
|
|
872
853
|
);
|
|
873
|
-
const encryptionKey = await
|
|
854
|
+
const encryptionKey = await processBatch_workflow.importAesKey(this.env.ENCRYPTION_KEY);
|
|
874
855
|
const createAccountCredentials = (await Promise.all(
|
|
875
856
|
credentials.map(
|
|
876
857
|
async (cr) => createAccountCredentialsCommand(this.db, encryptionKey, {
|
|
@@ -947,7 +928,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
947
928
|
debtor,
|
|
948
929
|
debtorIban: debtor.iban
|
|
949
930
|
};
|
|
950
|
-
const { command } =
|
|
931
|
+
const { command } = processBatch_workflow.createPaymentCommand(this.db, { payment });
|
|
951
932
|
const createdPayment = await command.execute().then(backendSdk.first);
|
|
952
933
|
this.logQueuePush({ payment, isPaymentExecuted: true });
|
|
953
934
|
await this.pushToQueue(this.env.QUEUE_BUS_QUEUE, {
|
|
@@ -1029,6 +1010,64 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
1029
1010
|
}
|
|
1030
1011
|
);
|
|
1031
1012
|
}
|
|
1013
|
+
async disconnectAccount(input) {
|
|
1014
|
+
return this.handleAction(
|
|
1015
|
+
{ data: input, schema: disconnectAccountInputSchema },
|
|
1016
|
+
{ successMessage: "Account disconnected successfully" },
|
|
1017
|
+
async ({ accountId }) => {
|
|
1018
|
+
const account = await processBatch_workflow.getAccountByIdQuery(this.db, { accountId });
|
|
1019
|
+
if (!account) {
|
|
1020
|
+
throw backendSdk.createInternalError(null, {
|
|
1021
|
+
message: "Account not found",
|
|
1022
|
+
code: "ACCOUNT_NOT_FOUND",
|
|
1023
|
+
status: 404
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
try {
|
|
1027
|
+
const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(accountId);
|
|
1028
|
+
await instance.terminate();
|
|
1029
|
+
} catch (error) {
|
|
1030
|
+
this.log({
|
|
1031
|
+
message: "No workflow instance found for account, skipping termination.",
|
|
1032
|
+
error
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
const { command: updateAccount } = updateAccountCommand(this.db, {
|
|
1036
|
+
account: {
|
|
1037
|
+
...account,
|
|
1038
|
+
id: accountId,
|
|
1039
|
+
status: "DISABLED"
|
|
1040
|
+
}
|
|
1041
|
+
});
|
|
1042
|
+
const { command: deleteCredentials } = deleteAccountCredentialsCommand(
|
|
1043
|
+
this.db,
|
|
1044
|
+
{
|
|
1045
|
+
accountId
|
|
1046
|
+
}
|
|
1047
|
+
);
|
|
1048
|
+
const { command: deletePayments } = deletePaymentsByAccountCommand(
|
|
1049
|
+
this.db,
|
|
1050
|
+
{
|
|
1051
|
+
accountId
|
|
1052
|
+
}
|
|
1053
|
+
);
|
|
1054
|
+
const [updatedAccountResult] = await this.db.batch([
|
|
1055
|
+
updateAccount,
|
|
1056
|
+
deleteCredentials,
|
|
1057
|
+
deletePayments
|
|
1058
|
+
]);
|
|
1059
|
+
const updatedAccount = backendSdk.first(updatedAccountResult);
|
|
1060
|
+
if (!updatedAccount) {
|
|
1061
|
+
throw backendSdk.createInternalError(null, {
|
|
1062
|
+
message: "Account not updated",
|
|
1063
|
+
code: "DB-B-0?",
|
|
1064
|
+
status: 404
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
return updatedAccount;
|
|
1068
|
+
}
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1032
1071
|
async getBatches(input) {
|
|
1033
1072
|
return this.handleAction(
|
|
1034
1073
|
{ data: input, schema: getBatchesInputSchema },
|
|
@@ -1081,6 +1120,9 @@ __decorateClass([
|
|
|
1081
1120
|
__decorateClass([
|
|
1082
1121
|
backendSdk.action("update-account")
|
|
1083
1122
|
], BankServiceBase.prototype, "updateAccount", 1);
|
|
1123
|
+
__decorateClass([
|
|
1124
|
+
backendSdk.action("disconnectAccount")
|
|
1125
|
+
], BankServiceBase.prototype, "disconnectAccount", 1);
|
|
1084
1126
|
__decorateClass([
|
|
1085
1127
|
backendSdk.action("getBatches")
|
|
1086
1128
|
], BankServiceBase.prototype, "getBatches", 1);
|