@develit-services/bank 0.2.4 → 0.3.1
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 +218 -170
- package/dist/export/worker.d.cts +133 -25
- package/dist/export/worker.d.mts +133 -25
- package/dist/export/worker.d.ts +133 -25
- package/dist/export/worker.mjs +210 -162
- 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) => {
|
|
@@ -397,17 +422,19 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
397
422
|
}) {
|
|
398
423
|
if (!this.allowedProviders.includes(connectorKey)) {
|
|
399
424
|
throw backendSdk.createInternalError(null, {
|
|
400
|
-
message: `Invalid connector key: ${connectorKey}
|
|
425
|
+
message: `Invalid connector key: ${connectorKey}`,
|
|
426
|
+
code: "VALID-B-001",
|
|
427
|
+
status: 400
|
|
401
428
|
});
|
|
402
429
|
}
|
|
403
430
|
const accounts = await this._getAccounts();
|
|
404
431
|
const accountsForConnector = accounts.filter(
|
|
405
432
|
(acc) => acc.connectorKey === connectorKey
|
|
406
433
|
);
|
|
407
|
-
const encryptionKey = await
|
|
434
|
+
const encryptionKey = await processBatch_workflow.importAesKey(this.env.ENCRYPTION_KEY);
|
|
408
435
|
const accountsWithCredentials = await Promise.all(
|
|
409
436
|
accountsForConnector.map(async (acc) => {
|
|
410
|
-
const credentials = await
|
|
437
|
+
const credentials = await processBatch_workflow.getCredentialsByAccountId(
|
|
411
438
|
this.db,
|
|
412
439
|
encryptionKey,
|
|
413
440
|
{
|
|
@@ -416,7 +443,9 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
416
443
|
);
|
|
417
444
|
if (!credentials) {
|
|
418
445
|
throw backendSdk.createInternalError(null, {
|
|
419
|
-
message: `No credentials found for account ${acc.id}
|
|
446
|
+
message: `No credentials found for account ${acc.id}`,
|
|
447
|
+
code: "DB-B-001",
|
|
448
|
+
status: 404
|
|
420
449
|
});
|
|
421
450
|
}
|
|
422
451
|
return {
|
|
@@ -428,7 +457,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
428
457
|
};
|
|
429
458
|
})
|
|
430
459
|
);
|
|
431
|
-
this.bankConnector =
|
|
460
|
+
this.bankConnector = processBatch_workflow.initiateConnector({
|
|
432
461
|
bank: connectorKey,
|
|
433
462
|
connectedAccounts: accountsWithCredentials,
|
|
434
463
|
env: this.env
|
|
@@ -521,7 +550,9 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
521
550
|
{ successMessage: "Accounts synchronized successfully" },
|
|
522
551
|
async () => {
|
|
523
552
|
throw backendSdk.createInternalError(null, {
|
|
524
|
-
message: "Not implemented yet"
|
|
553
|
+
message: "Not implemented yet",
|
|
554
|
+
code: "SYS-B-001",
|
|
555
|
+
status: 501
|
|
525
556
|
});
|
|
526
557
|
}
|
|
527
558
|
);
|
|
@@ -562,18 +593,34 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
562
593
|
finalBatches.push(...updatedBatches);
|
|
563
594
|
}
|
|
564
595
|
const updateBatchesCommands = finalBatches.map((batch) => {
|
|
565
|
-
const { command } = upsertBatchCommand(this.db, {
|
|
596
|
+
const { command } = processBatch_workflow.upsertBatchCommand(this.db, {
|
|
566
597
|
batch: {
|
|
567
598
|
...batch
|
|
568
599
|
}
|
|
569
600
|
});
|
|
570
601
|
return command;
|
|
571
602
|
});
|
|
572
|
-
console.log("Updated batches", finalBatches);
|
|
573
603
|
await this.db.batch([
|
|
574
604
|
updateBatchesCommands[0],
|
|
575
605
|
...updateBatchesCommands.slice(1)
|
|
576
606
|
]);
|
|
607
|
+
for (const batch of finalBatches) {
|
|
608
|
+
try {
|
|
609
|
+
const instance = await this.env.PROCESS_BATCH_WORKFLOW.get(batch.id);
|
|
610
|
+
if (batch.status === "SIGNED" || batch.status === "SIGNATURE_FAILED") {
|
|
611
|
+
instance.sendEvent({
|
|
612
|
+
type: processBatch_workflow.PROCESS_BATCH_WORKFLOW_EVENTS.batchAuthorized,
|
|
613
|
+
payload: {
|
|
614
|
+
authorized: batch.status === "SIGNED"
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
} catch (_) {
|
|
619
|
+
console.log(
|
|
620
|
+
`No workflow instance found for batch ${batch.id}, skipping.`
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
577
624
|
console.log("Batch update completed");
|
|
578
625
|
}
|
|
579
626
|
async addPaymentsToBatch({
|
|
@@ -652,7 +699,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
652
699
|
this.log({
|
|
653
700
|
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
701
|
});
|
|
655
|
-
const { command } = upsertBatchCommand(this.db, {
|
|
702
|
+
const { command } = processBatch_workflow.upsertBatchCommand(this.db, {
|
|
656
703
|
batch: availableBatch ? {
|
|
657
704
|
...availableBatch,
|
|
658
705
|
payments: [...availableBatch.payments, ...newPayments]
|
|
@@ -675,122 +722,62 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
675
722
|
async processBatch(input) {
|
|
676
723
|
return this.handleAction(
|
|
677
724
|
{ data: input, schema: processBatchInputSchema },
|
|
678
|
-
{},
|
|
679
|
-
async ({
|
|
680
|
-
await
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
725
|
+
{ successMessage: "Batch processing workflow started" },
|
|
726
|
+
async ({ batchId }) => {
|
|
727
|
+
const instance = await this.env.PROCESS_BATCH_WORKFLOW.create({
|
|
728
|
+
id: batchId,
|
|
729
|
+
params: {
|
|
730
|
+
batchId
|
|
684
731
|
}
|
|
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
732
|
});
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
failedPayments: []
|
|
733
|
+
return {
|
|
734
|
+
instanceId: instance.id,
|
|
735
|
+
details: await instance.status()
|
|
705
736
|
};
|
|
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
|
-
}
|
|
737
|
+
}
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
async processBatchStatus(input) {
|
|
741
|
+
return this.handleAction(
|
|
742
|
+
{ data: input, schema: processBatchStatusInputSchema },
|
|
743
|
+
{ successMessage: "Batch processing workflow status retrieved" },
|
|
744
|
+
async ({ batchId }) => {
|
|
745
|
+
const instance = await this.env.PROCESS_BATCH_WORKFLOW.get(batchId);
|
|
746
|
+
return {
|
|
747
|
+
instanceId: instance.id,
|
|
748
|
+
details: await instance.status()
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
async processBatchRestart(input) {
|
|
754
|
+
return this.handleAction(
|
|
755
|
+
{ data: input, schema: processBatchRestartInputSchema },
|
|
756
|
+
{ successMessage: "Batch processing workflow restarted" },
|
|
757
|
+
async ({ batchId }) => {
|
|
758
|
+
const instance = await this.env.PROCESS_BATCH_WORKFLOW.get(batchId);
|
|
759
|
+
await instance.restart();
|
|
760
|
+
return {
|
|
761
|
+
instanceId: instance.id,
|
|
762
|
+
details: await instance.status()
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
async processBatchEvent(input) {
|
|
768
|
+
return this.handleAction(
|
|
769
|
+
{ data: input, schema: processBatchEventInputSchema },
|
|
770
|
+
{ successMessage: "Event sent to batch processing workflow" },
|
|
771
|
+
async ({ batchId, eventType, payload }) => {
|
|
772
|
+
const instance = await this.env.PROCESS_BATCH_WORKFLOW.get(batchId);
|
|
773
|
+
await instance.sendEvent({
|
|
774
|
+
type: eventType,
|
|
775
|
+
payload
|
|
792
776
|
});
|
|
793
|
-
|
|
777
|
+
return {
|
|
778
|
+
success: true,
|
|
779
|
+
message: `Event '${eventType}' sent to workflow instance ${batchId}`
|
|
780
|
+
};
|
|
794
781
|
}
|
|
795
782
|
);
|
|
796
783
|
}
|
|
@@ -839,14 +826,14 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
839
826
|
if (!ottRow) {
|
|
840
827
|
throw backendSdk.createInternalError(null, {
|
|
841
828
|
message: "One-time token not found",
|
|
842
|
-
code: "
|
|
829
|
+
code: "DB-B-002",
|
|
843
830
|
status: 404
|
|
844
831
|
});
|
|
845
832
|
}
|
|
846
833
|
if (ottRow.expiresAt.getTime() < Date.now()) {
|
|
847
834
|
throw backendSdk.createInternalError(null, {
|
|
848
835
|
message: "One time token has expired",
|
|
849
|
-
code: "
|
|
836
|
+
code: "VALID-B-002",
|
|
850
837
|
status: 400
|
|
851
838
|
});
|
|
852
839
|
}
|
|
@@ -870,7 +857,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
870
857
|
accountId: acc.id
|
|
871
858
|
}).command
|
|
872
859
|
);
|
|
873
|
-
const encryptionKey = await
|
|
860
|
+
const encryptionKey = await processBatch_workflow.importAesKey(this.env.ENCRYPTION_KEY);
|
|
874
861
|
const createAccountCredentials = (await Promise.all(
|
|
875
862
|
credentials.map(
|
|
876
863
|
async (cr) => createAccountCredentialsCommand(this.db, encryptionKey, {
|
|
@@ -891,7 +878,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
891
878
|
if (!fetchedAccounts)
|
|
892
879
|
throw backendSdk.createInternalError(null, {
|
|
893
880
|
message: "Account not found",
|
|
894
|
-
code: "
|
|
881
|
+
code: "DB-B-003",
|
|
895
882
|
status: 404
|
|
896
883
|
});
|
|
897
884
|
return {
|
|
@@ -921,7 +908,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
921
908
|
if (!account)
|
|
922
909
|
throw backendSdk.createInternalError(null, {
|
|
923
910
|
message: "Unsupported account",
|
|
924
|
-
code: "
|
|
911
|
+
code: "VALID-B-003",
|
|
925
912
|
status: 422
|
|
926
913
|
});
|
|
927
914
|
const payment = {
|
|
@@ -947,7 +934,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
947
934
|
debtor,
|
|
948
935
|
debtorIban: debtor.iban
|
|
949
936
|
};
|
|
950
|
-
const { command } =
|
|
937
|
+
const { command } = processBatch_workflow.createPaymentCommand(this.db, { payment });
|
|
951
938
|
const createdPayment = await command.execute().then(backendSdk.first);
|
|
952
939
|
this.logQueuePush({ payment, isPaymentExecuted: true });
|
|
953
940
|
await this.pushToQueue(this.env.QUEUE_BUS_QUEUE, {
|
|
@@ -1021,7 +1008,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
1021
1008
|
if (!updatedAccount) {
|
|
1022
1009
|
throw backendSdk.createInternalError(null, {
|
|
1023
1010
|
message: "Account not found",
|
|
1024
|
-
code: "
|
|
1011
|
+
code: "DB-B-004",
|
|
1025
1012
|
status: 404
|
|
1026
1013
|
});
|
|
1027
1014
|
}
|
|
@@ -1029,6 +1016,64 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
1029
1016
|
}
|
|
1030
1017
|
);
|
|
1031
1018
|
}
|
|
1019
|
+
async disconnectAccount(input) {
|
|
1020
|
+
return this.handleAction(
|
|
1021
|
+
{ data: input, schema: disconnectAccountInputSchema },
|
|
1022
|
+
{ successMessage: "Account disconnected successfully" },
|
|
1023
|
+
async ({ accountId }) => {
|
|
1024
|
+
const account = await processBatch_workflow.getAccountByIdQuery(this.db, { accountId });
|
|
1025
|
+
if (!account) {
|
|
1026
|
+
throw backendSdk.createInternalError(null, {
|
|
1027
|
+
message: "Account not found",
|
|
1028
|
+
code: "DB-B-005",
|
|
1029
|
+
status: 404
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
try {
|
|
1033
|
+
const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(accountId);
|
|
1034
|
+
await instance.terminate();
|
|
1035
|
+
} catch (error) {
|
|
1036
|
+
this.log({
|
|
1037
|
+
message: "No workflow instance found for account, skipping termination.",
|
|
1038
|
+
error
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
const { command: updateAccount } = updateAccountCommand(this.db, {
|
|
1042
|
+
account: {
|
|
1043
|
+
...account,
|
|
1044
|
+
id: accountId,
|
|
1045
|
+
status: "DISABLED"
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
const { command: deleteCredentials } = deleteAccountCredentialsCommand(
|
|
1049
|
+
this.db,
|
|
1050
|
+
{
|
|
1051
|
+
accountId
|
|
1052
|
+
}
|
|
1053
|
+
);
|
|
1054
|
+
const { command: deletePayments } = deletePaymentsByAccountCommand(
|
|
1055
|
+
this.db,
|
|
1056
|
+
{
|
|
1057
|
+
accountId
|
|
1058
|
+
}
|
|
1059
|
+
);
|
|
1060
|
+
const [updatedAccountResult] = await this.db.batch([
|
|
1061
|
+
updateAccount,
|
|
1062
|
+
deleteCredentials,
|
|
1063
|
+
deletePayments
|
|
1064
|
+
]);
|
|
1065
|
+
const updatedAccount = backendSdk.first(updatedAccountResult);
|
|
1066
|
+
if (!updatedAccount) {
|
|
1067
|
+
throw backendSdk.createInternalError(null, {
|
|
1068
|
+
message: "Account not updated",
|
|
1069
|
+
code: "DB-B-006",
|
|
1070
|
+
status: 500
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
return updatedAccount;
|
|
1074
|
+
}
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1032
1077
|
async getBatches(input) {
|
|
1033
1078
|
return this.handleAction(
|
|
1034
1079
|
{ data: input, schema: getBatchesInputSchema },
|
|
@@ -1081,6 +1126,9 @@ __decorateClass([
|
|
|
1081
1126
|
__decorateClass([
|
|
1082
1127
|
backendSdk.action("update-account")
|
|
1083
1128
|
], BankServiceBase.prototype, "updateAccount", 1);
|
|
1129
|
+
__decorateClass([
|
|
1130
|
+
backendSdk.action("disconnectAccount")
|
|
1131
|
+
], BankServiceBase.prototype, "disconnectAccount", 1);
|
|
1084
1132
|
__decorateClass([
|
|
1085
1133
|
backendSdk.action("getBatches")
|
|
1086
1134
|
], BankServiceBase.prototype, "getBatches", 1);
|