@develit-services/bank 0.2.3 → 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 +223 -168
- package/dist/export/worker.d.cts +136 -28
- package/dist/export/worker.d.mts +136 -28
- package/dist/export/worker.d.ts +136 -28
- package/dist/export/worker.mjs +219 -164
- package/dist/export/workflows.cjs +27 -24
- 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 +24 -21
- package/dist/export/wrangler.cjs +8 -2
- 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 +8 -2
- package/dist/shared/{bank.Bz_9Rd77.cjs → bank.BGuS_o9V.cjs} +1 -1
- package/dist/shared/bank.CIJDq7GL.cjs +401 -0
- package/dist/shared/{bank.AJrHfGNj.cjs → bank.CpcK1Dse.cjs} +13 -10
- package/dist/shared/{bank.6g3WuMht.mjs → bank.CthUj-ff.mjs} +1 -1
- package/dist/shared/{bank.CsAnzmYN.mjs → bank.lZMrqjVR.mjs} +13 -10
- package/dist/shared/bank.mZtcXaJo.mjs +391 -0
- package/dist/shared/{bank.eVSSL0hq.d.cts → bank.xrXNjWCo.d.cts} +113 -18
- package/dist/shared/{bank.eVSSL0hq.d.mts → bank.xrXNjWCo.d.mts} +113 -18
- package/dist/shared/{bank.eVSSL0hq.d.ts → bank.xrXNjWCo.d.ts} +113 -18
- 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 +2 -1
- package/dist/shared/bank.B8vgpVU6.cjs +0 -98
- package/dist/shared/bank.jhJ4j7UB.mjs +0 -94
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
|
}) => {
|
|
@@ -79,9 +64,14 @@ const expireOneTimeTokenCommand = (db, {
|
|
|
79
64
|
};
|
|
80
65
|
};
|
|
81
66
|
|
|
82
|
-
const createAccountCredentialsCommand = (db, { credentials }) => {
|
|
67
|
+
const createAccountCredentialsCommand = async (db, encryptionKey, { credentials }) => {
|
|
83
68
|
const id = credentials.id || backendSdk.uuidv4();
|
|
84
|
-
const
|
|
69
|
+
const encryptedValue = await processBatch_workflow.encrypt(credentials.value, encryptionKey);
|
|
70
|
+
const command = db.insert(database_schema.tables.accountCredentials).values({
|
|
71
|
+
...credentials,
|
|
72
|
+
id,
|
|
73
|
+
value: encryptedValue
|
|
74
|
+
}).returning();
|
|
85
75
|
return {
|
|
86
76
|
id,
|
|
87
77
|
command
|
|
@@ -95,6 +85,15 @@ const deleteAccountCredentialsCommand = (db, { accountId }) => {
|
|
|
95
85
|
};
|
|
96
86
|
};
|
|
97
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
|
+
|
|
98
97
|
const getAccountByIbanQuery = async (db, { iban }) => {
|
|
99
98
|
return await db.select().from(database_schema.tables.account).where(drizzleOrm.eq(database_schema.tables.account.iban, iban)).get();
|
|
100
99
|
};
|
|
@@ -113,13 +112,7 @@ const getAllAccountsQuery = async (db) => {
|
|
|
113
112
|
};
|
|
114
113
|
|
|
115
114
|
const getAllPendingBatchesQuery = (db) => {
|
|
116
|
-
return db.select().from(database_schema.tables.batch).where(
|
|
117
|
-
drizzleOrm.inArray(database_schema.tables.batch.status, [
|
|
118
|
-
"PROCESSING",
|
|
119
|
-
"READY_TO_SIGN",
|
|
120
|
-
"WAITING_FOR_PROCESSING"
|
|
121
|
-
])
|
|
122
|
-
);
|
|
115
|
+
return db.select().from(database_schema.tables.batch).where(drizzleOrm.inArray(database_schema.tables.batch.status, ["READY_TO_SIGN"]));
|
|
123
116
|
};
|
|
124
117
|
|
|
125
118
|
const buildMultiFilterConditions = (column, value) => {
|
|
@@ -149,6 +142,7 @@ const getPaymentsWithPaginationQuery = async (db, {
|
|
|
149
142
|
limit,
|
|
150
143
|
page,
|
|
151
144
|
sort,
|
|
145
|
+
ids,
|
|
152
146
|
filterPaymentAccountId,
|
|
153
147
|
filterPaymentAmount,
|
|
154
148
|
filterPaymentCurrency,
|
|
@@ -173,7 +167,8 @@ const getPaymentsWithPaginationQuery = async (db, {
|
|
|
173
167
|
buildMultiFilterConditions(
|
|
174
168
|
database_schema.tables.payment.direction,
|
|
175
169
|
filterPaymentyDirection
|
|
176
|
-
)
|
|
170
|
+
),
|
|
171
|
+
buildMultiFilterConditions(database_schema.tables.payment.id, ids)
|
|
177
172
|
);
|
|
178
173
|
const sortColumn = resolveColumn(database_schema.tables.payment, sort.column);
|
|
179
174
|
const [{ totalCount }] = await db.select({
|
|
@@ -221,11 +216,6 @@ const getOttQuery = async (db, { ott }) => {
|
|
|
221
216
|
return await db.select().from(database_schema.tables.ott).where(drizzleOrm.eq(database_schema.tables.ott.oneTimeToken, ott)).get();
|
|
222
217
|
};
|
|
223
218
|
|
|
224
|
-
const getPaymentByRefIdQuery = async (db, { refId }) => {
|
|
225
|
-
const payment = await db.select().from(database_schema.tables.payment).where(drizzleOrm.eq(database_schema.tables.payment.refId, refId)).limit(1).get();
|
|
226
|
-
return payment;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
219
|
const seperateSupportedPayments = (mappedPayments, accounts) => {
|
|
230
220
|
const [supportedPayments, unsupportedPayments] = mappedPayments.reduce(
|
|
231
221
|
([valid, invalid], payment) => {
|
|
@@ -302,8 +292,43 @@ const getBatchesInputSchema = zod.z.object({
|
|
|
302
292
|
});
|
|
303
293
|
|
|
304
294
|
const processBatchInputSchema = zod.z.object({
|
|
305
|
-
|
|
306
|
-
|
|
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()
|
|
307
332
|
});
|
|
308
333
|
|
|
309
334
|
const ALLOWED_PAYMENT_FILTERS = {
|
|
@@ -322,6 +347,7 @@ const getPaymentsInputSchema = zod.z.object({
|
|
|
322
347
|
column: zod.z.enum(["createdAt", "updatedAt", "amount"]),
|
|
323
348
|
direction: zod.z.enum(["asc", "desc"])
|
|
324
349
|
}),
|
|
350
|
+
ids: zod.z.array(zod.z.uuid()).optional(),
|
|
325
351
|
[ALLOWED_PAYMENT_FILTERS.ACCOUNT_ID]: zod.z.union([zod.z.uuid(), zod.z.uuid().array()]).optional(),
|
|
326
352
|
[ALLOWED_PAYMENT_FILTERS.AMOUNT]: zod.z.union([zod.z.number(), zod.z.number().array()]).optional(),
|
|
327
353
|
[ALLOWED_PAYMENT_FILTERS.CURRENCY]: zod.z.union([zod.z.enum(generalCodes.CURRENCY_CODES), zod.z.enum(generalCodes.CURRENCY_CODES).array()]).optional(),
|
|
@@ -366,6 +392,10 @@ const updateAccountInputSchema = zod.z.object({
|
|
|
366
392
|
account: database_schema.accountInsertSchema
|
|
367
393
|
});
|
|
368
394
|
|
|
395
|
+
const disconnectAccountInputSchema = zod.z.object({
|
|
396
|
+
accountId: zod.z.uuid()
|
|
397
|
+
});
|
|
398
|
+
|
|
369
399
|
var __defProp = Object.defineProperty;
|
|
370
400
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
371
401
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
@@ -399,11 +429,16 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
399
429
|
const accountsForConnector = accounts.filter(
|
|
400
430
|
(acc) => acc.connectorKey === connectorKey
|
|
401
431
|
);
|
|
432
|
+
const encryptionKey = await processBatch_workflow.importAesKey(this.env.ENCRYPTION_KEY);
|
|
402
433
|
const accountsWithCredentials = await Promise.all(
|
|
403
434
|
accountsForConnector.map(async (acc) => {
|
|
404
|
-
const credentials = await
|
|
405
|
-
|
|
406
|
-
|
|
435
|
+
const credentials = await processBatch_workflow.getCredentialsByAccountId(
|
|
436
|
+
this.db,
|
|
437
|
+
encryptionKey,
|
|
438
|
+
{
|
|
439
|
+
accountId: acc.id
|
|
440
|
+
}
|
|
441
|
+
);
|
|
407
442
|
if (!credentials) {
|
|
408
443
|
throw backendSdk.createInternalError(null, {
|
|
409
444
|
message: `No credentials found for account ${acc.id}`
|
|
@@ -418,7 +453,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
418
453
|
};
|
|
419
454
|
})
|
|
420
455
|
);
|
|
421
|
-
this.bankConnector =
|
|
456
|
+
this.bankConnector = processBatch_workflow.initiateConnector({
|
|
422
457
|
bank: connectorKey,
|
|
423
458
|
connectedAccounts: accountsWithCredentials,
|
|
424
459
|
env: this.env
|
|
@@ -552,18 +587,34 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
552
587
|
finalBatches.push(...updatedBatches);
|
|
553
588
|
}
|
|
554
589
|
const updateBatchesCommands = finalBatches.map((batch) => {
|
|
555
|
-
const { command } = upsertBatchCommand(this.db, {
|
|
590
|
+
const { command } = processBatch_workflow.upsertBatchCommand(this.db, {
|
|
556
591
|
batch: {
|
|
557
592
|
...batch
|
|
558
593
|
}
|
|
559
594
|
});
|
|
560
595
|
return command;
|
|
561
596
|
});
|
|
562
|
-
console.log("Updated batches", finalBatches);
|
|
563
597
|
await this.db.batch([
|
|
564
598
|
updateBatchesCommands[0],
|
|
565
599
|
...updateBatchesCommands.slice(1)
|
|
566
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
|
+
}
|
|
567
618
|
console.log("Batch update completed");
|
|
568
619
|
}
|
|
569
620
|
async addPaymentsToBatch({
|
|
@@ -642,7 +693,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
642
693
|
this.log({
|
|
643
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`
|
|
644
695
|
});
|
|
645
|
-
const { command } = upsertBatchCommand(this.db, {
|
|
696
|
+
const { command } = processBatch_workflow.upsertBatchCommand(this.db, {
|
|
646
697
|
batch: availableBatch ? {
|
|
647
698
|
...availableBatch,
|
|
648
699
|
payments: [...availableBatch.payments, ...newPayments]
|
|
@@ -665,122 +716,62 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
665
716
|
async processBatch(input) {
|
|
666
717
|
return this.handleAction(
|
|
667
718
|
{ data: input, schema: processBatchInputSchema },
|
|
668
|
-
{},
|
|
669
|
-
async ({
|
|
670
|
-
await
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
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
|
|
674
725
|
}
|
|
675
|
-
}).command.execute();
|
|
676
|
-
await this._initiateBankConnector({ connectorKey });
|
|
677
|
-
if (!this.bankConnector) {
|
|
678
|
-
await upsertBatchCommand(this.db, {
|
|
679
|
-
batch: {
|
|
680
|
-
...batch,
|
|
681
|
-
status: "FAILED"
|
|
682
|
-
}
|
|
683
|
-
}).command.execute();
|
|
684
|
-
throw backendSdk.createInternalError(null, {
|
|
685
|
-
message: `\u274C Failed to initialize ${connectorKey} bank connector`
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
this.log({
|
|
689
|
-
message: `\u2705 Bank connector initialized successfully for account ${connectorKey}`
|
|
690
726
|
});
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
failedPayments: []
|
|
727
|
+
return {
|
|
728
|
+
instanceId: instance.id,
|
|
729
|
+
details: await instance.status()
|
|
695
730
|
};
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
await
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
]
|
|
736
|
-
});
|
|
737
|
-
console.log(authorizationUrls, "AUTH URIS FROM BANK");
|
|
738
|
-
if (!authorizationUrls.length) {
|
|
739
|
-
this.logError({ message: "Failed to retrieve signing URI" });
|
|
740
|
-
await upsertBatchCommand(this.db, {
|
|
741
|
-
batch: {
|
|
742
|
-
...batch,
|
|
743
|
-
status: "FAILED"
|
|
744
|
-
}
|
|
745
|
-
}).command.execute();
|
|
746
|
-
return;
|
|
747
|
-
}
|
|
748
|
-
const { command: upsertBatch } = upsertBatchCommand(this.db, {
|
|
749
|
-
batch: {
|
|
750
|
-
...batch,
|
|
751
|
-
payments,
|
|
752
|
-
metadata,
|
|
753
|
-
status: "READY_TO_SIGN",
|
|
754
|
-
authorizationUrls,
|
|
755
|
-
batchPaymentInitiatedAt: /* @__PURE__ */ new Date()
|
|
756
|
-
}
|
|
757
|
-
});
|
|
758
|
-
const updatePayments = payments.map(
|
|
759
|
-
(payment) => updatePaymentCommand(this.db, {
|
|
760
|
-
payment: { ...payment, status: "INITIALIZED" }
|
|
761
|
-
}).command
|
|
762
|
-
);
|
|
763
|
-
await this.db.batch([upsertBatch, ...updatePayments]);
|
|
764
|
-
this.log({
|
|
765
|
-
message: "Authorization Urls for batch to create",
|
|
766
|
-
authorizationUrl: authorizationUrls[0]
|
|
767
|
-
});
|
|
768
|
-
await this.pushToQueue(this.env.NOTIFICATIONS_QUEUE, {
|
|
769
|
-
type: "email",
|
|
770
|
-
payload: {
|
|
771
|
-
email: {
|
|
772
|
-
to: [this.env.BANK_AUTH_RECIPIENT],
|
|
773
|
-
subject: "Payment Authorization",
|
|
774
|
-
text: authorizationUrls[0] || "No Authorization Url"
|
|
775
|
-
}
|
|
776
|
-
},
|
|
777
|
-
metadata: {
|
|
778
|
-
initiator: {
|
|
779
|
-
service: this.name
|
|
780
|
-
}
|
|
781
|
-
}
|
|
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
|
|
782
770
|
});
|
|
783
|
-
|
|
771
|
+
return {
|
|
772
|
+
success: true,
|
|
773
|
+
message: `Event '${eventType}' sent to workflow instance ${batchId}`
|
|
774
|
+
};
|
|
784
775
|
}
|
|
785
776
|
);
|
|
786
777
|
}
|
|
@@ -860,11 +851,14 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
860
851
|
accountId: acc.id
|
|
861
852
|
}).command
|
|
862
853
|
);
|
|
863
|
-
const
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
854
|
+
const encryptionKey = await processBatch_workflow.importAesKey(this.env.ENCRYPTION_KEY);
|
|
855
|
+
const createAccountCredentials = (await Promise.all(
|
|
856
|
+
credentials.map(
|
|
857
|
+
async (cr) => createAccountCredentialsCommand(this.db, encryptionKey, {
|
|
858
|
+
credentials: cr
|
|
859
|
+
})
|
|
860
|
+
)
|
|
861
|
+
)).map((cmd) => cmd.command);
|
|
868
862
|
const { command: updateOtt } = expireOneTimeTokenCommand(this.db, {
|
|
869
863
|
ott
|
|
870
864
|
});
|
|
@@ -934,7 +928,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
934
928
|
debtor,
|
|
935
929
|
debtorIban: debtor.iban
|
|
936
930
|
};
|
|
937
|
-
const { command } =
|
|
931
|
+
const { command } = processBatch_workflow.createPaymentCommand(this.db, { payment });
|
|
938
932
|
const createdPayment = await command.execute().then(backendSdk.first);
|
|
939
933
|
this.logQueuePush({ payment, isPaymentExecuted: true });
|
|
940
934
|
await this.pushToQueue(this.env.QUEUE_BUS_QUEUE, {
|
|
@@ -1016,6 +1010,64 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
1016
1010
|
}
|
|
1017
1011
|
);
|
|
1018
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
|
+
}
|
|
1019
1071
|
async getBatches(input) {
|
|
1020
1072
|
return this.handleAction(
|
|
1021
1073
|
{ data: input, schema: getBatchesInputSchema },
|
|
@@ -1068,6 +1120,9 @@ __decorateClass([
|
|
|
1068
1120
|
__decorateClass([
|
|
1069
1121
|
backendSdk.action("update-account")
|
|
1070
1122
|
], BankServiceBase.prototype, "updateAccount", 1);
|
|
1123
|
+
__decorateClass([
|
|
1124
|
+
backendSdk.action("disconnectAccount")
|
|
1125
|
+
], BankServiceBase.prototype, "disconnectAccount", 1);
|
|
1071
1126
|
__decorateClass([
|
|
1072
1127
|
backendSdk.action("getBatches")
|
|
1073
1128
|
], BankServiceBase.prototype, "getBatches", 1);
|