@develit-services/bank 0.0.18 → 0.0.20
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/export/worker.cjs +118 -121
- package/dist/export/worker.d.cts +21 -9
- package/dist/export/worker.d.mts +21 -9
- package/dist/export/worker.d.ts +21 -9
- package/dist/export/worker.mjs +118 -121
- package/dist/export/wrangler.cjs +2 -1
- package/dist/export/wrangler.d.cts +2 -1
- package/dist/export/wrangler.d.mts +2 -1
- package/dist/export/wrangler.d.ts +2 -1
- package/dist/export/wrangler.mjs +2 -1
- package/dist/shared/{bank.CJFy17-g.d.cts → bank.CEZKAEiY.d.cts} +1 -0
- package/dist/shared/{bank.CJFy17-g.d.mts → bank.CEZKAEiY.d.mts} +1 -0
- package/dist/shared/{bank.CJFy17-g.d.ts → bank.CEZKAEiY.d.ts} +1 -0
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/export/worker.cjs
CHANGED
|
@@ -73,6 +73,11 @@ const getBatchesInputSchema = zod.z.object({
|
|
|
73
73
|
offset: zod.z.number().min(0).optional().default(0)
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
+
const processBatchInputSchema = zod.z.object({
|
|
77
|
+
connectorKey: zod.z.enum(database_schema.CONNECTOR_KEYS),
|
|
78
|
+
batch: zod.z.custom()
|
|
79
|
+
});
|
|
80
|
+
|
|
76
81
|
const createPaymentCommand = (db$1, { payment }) => {
|
|
77
82
|
return {
|
|
78
83
|
command: db$1.insert(db.tables.payment).values(payment).returning()
|
|
@@ -135,10 +140,6 @@ const getOpenBatchByAccountIdQuery = async (db$1, { accountId }) => {
|
|
|
135
140
|
return batch;
|
|
136
141
|
};
|
|
137
142
|
|
|
138
|
-
const getAllOpenBatchesQuery = async (db$1) => {
|
|
139
|
-
return await db$1.select().from(db.tables.batch).where(drizzleOrm.eq(db.tables.batch.status, "OPEN"));
|
|
140
|
-
};
|
|
141
|
-
|
|
142
143
|
const getPaymentsByBankRefIdsQuery = async (db$1, { ids }) => {
|
|
143
144
|
return await db$1.select().from(db.tables.payment).where(drizzleOrm.inArray(db.tables.payment.bankRefId, ids));
|
|
144
145
|
};
|
|
@@ -331,28 +332,6 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
331
332
|
});
|
|
332
333
|
}
|
|
333
334
|
async scheduled(controller) {
|
|
334
|
-
if (controller.cron === this.env.CRON_BATCHES_PROCESSING) {
|
|
335
|
-
console.log("Scheduled CRON batches processing");
|
|
336
|
-
const openBatches = await getAllOpenBatchesQuery(this.db);
|
|
337
|
-
if (!openBatches.length) return;
|
|
338
|
-
for (const batch of openBatches) {
|
|
339
|
-
const connectorKey = this.accounts.find(
|
|
340
|
-
(acc) => acc.id === batch.accountId
|
|
341
|
-
)?.connectorKey;
|
|
342
|
-
if (!connectorKey) {
|
|
343
|
-
this.logError({
|
|
344
|
-
message: "Failed to find connector key",
|
|
345
|
-
batch,
|
|
346
|
-
connectorKey
|
|
347
|
-
});
|
|
348
|
-
continue;
|
|
349
|
-
}
|
|
350
|
-
await this.processBatch({
|
|
351
|
-
batch,
|
|
352
|
-
connectorKey
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
335
|
if (controller.cron === this.env.CRON_PAYMENTS_PROCESSING) {
|
|
357
336
|
console.log("Scheduled CRON payments processing");
|
|
358
337
|
await this.syncAccounts();
|
|
@@ -467,108 +446,126 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
467
446
|
}
|
|
468
447
|
});
|
|
469
448
|
}
|
|
470
|
-
async processBatch({
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
449
|
+
async processBatch(input) {
|
|
450
|
+
return this.handleAction(
|
|
451
|
+
{ data: input, schema: processBatchInputSchema },
|
|
452
|
+
{},
|
|
453
|
+
async ({ batch, connectorKey }) => {
|
|
454
|
+
await upsertBatchCommand(this.db, {
|
|
455
|
+
batch: {
|
|
456
|
+
...batch,
|
|
457
|
+
status: "PROCESSING"
|
|
458
|
+
}
|
|
459
|
+
}).command.execute();
|
|
460
|
+
await this.initiateBankConnector({ connectorKey });
|
|
461
|
+
if (!this.bankConnector) {
|
|
462
|
+
await upsertBatchCommand(this.db, {
|
|
463
|
+
batch: {
|
|
464
|
+
...batch,
|
|
465
|
+
status: "FAILED"
|
|
466
|
+
}
|
|
467
|
+
}).command.execute();
|
|
468
|
+
throw backendSdk.createInternalError(null, {
|
|
469
|
+
message: `\u274C Failed to initialize ${connectorKey} bank connector`
|
|
470
|
+
});
|
|
480
471
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
if (!this.bankConnector) {
|
|
484
|
-
throw backendSdk.createInternalError(null, {
|
|
485
|
-
message: `\u274C Failed to initialize ${connectorKey} bank connector`
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
this.log({
|
|
489
|
-
message: `\u2705 Bank connector initialized successfully for account ${connectorKey}`
|
|
490
|
-
});
|
|
491
|
-
const preparedBatch = {
|
|
492
|
-
retriedPayments: [],
|
|
493
|
-
newlyPreparedPayments: [],
|
|
494
|
-
failedPayments: []
|
|
495
|
-
};
|
|
496
|
-
for (const payment of batch.payments) {
|
|
497
|
-
const existingPayment = await getPaymentByRefIdQuery(this.db, {
|
|
498
|
-
refId: payment.refId
|
|
472
|
+
this.log({
|
|
473
|
+
message: `\u2705 Bank connector initialized successfully for account ${connectorKey}`
|
|
499
474
|
});
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
475
|
+
const preparedBatch = {
|
|
476
|
+
retriedPayments: [],
|
|
477
|
+
newlyPreparedPayments: [],
|
|
478
|
+
failedPayments: []
|
|
479
|
+
};
|
|
480
|
+
for (const payment of batch.payments) {
|
|
481
|
+
const existingPayment = await getPaymentByRefIdQuery(this.db, {
|
|
482
|
+
refId: payment.refId
|
|
507
483
|
});
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
484
|
+
if (existingPayment) {
|
|
485
|
+
preparedBatch.retriedPayments.push({
|
|
486
|
+
...existingPayment,
|
|
487
|
+
status: "PREPARED"
|
|
488
|
+
});
|
|
489
|
+
this.log({
|
|
490
|
+
message: `\u2705 Payment ${existingPayment.id} already exists`
|
|
491
|
+
});
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
const newlyPreparedPayment = await this.bankConnector.preparePayment(payment);
|
|
495
|
+
if (!newlyPreparedPayment) {
|
|
496
|
+
preparedBatch.failedPayments.push({ ...payment, status: "FAILED" });
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
preparedBatch.newlyPreparedPayments.push(newlyPreparedPayment);
|
|
514
500
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
501
|
+
await Promise.all([
|
|
502
|
+
[
|
|
503
|
+
...preparedBatch.failedPayments,
|
|
504
|
+
...preparedBatch.newlyPreparedPayments
|
|
505
|
+
].map(
|
|
506
|
+
(p) => createPaymentCommand(this.db, { payment: p }).command.execute()
|
|
507
|
+
)
|
|
508
|
+
]);
|
|
509
|
+
await upsertBatchCommand(this.db, {
|
|
510
|
+
batch: {
|
|
511
|
+
...batch,
|
|
512
|
+
status: "PREPARED"
|
|
513
|
+
}
|
|
514
|
+
}).command.execute();
|
|
515
|
+
const { authorizationUrls, payments, metadata } = await this.bankConnector.initiateBatchFromPayments({
|
|
516
|
+
payments: [
|
|
517
|
+
...preparedBatch.newlyPreparedPayments,
|
|
518
|
+
...preparedBatch.retriedPayments
|
|
519
|
+
]
|
|
520
|
+
});
|
|
521
|
+
if (!authorizationUrls) {
|
|
522
|
+
this.logError({ message: "Failed to retrieve signing URI" });
|
|
523
|
+
await upsertBatchCommand(this.db, {
|
|
524
|
+
batch: {
|
|
525
|
+
...batch,
|
|
526
|
+
status: "FAILED"
|
|
527
|
+
}
|
|
528
|
+
}).command.execute();
|
|
529
|
+
return;
|
|
543
530
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
message: "Authorization Urls for batch to create",
|
|
553
|
-
authorizationUrl: authorizationUrls[0]
|
|
554
|
-
});
|
|
555
|
-
await this.pushToQueue(this.env.NOTIFICATIONS_QUEUE, {
|
|
556
|
-
type: "email",
|
|
557
|
-
payload: {
|
|
558
|
-
email: {
|
|
559
|
-
to: ["petr@develit.io"],
|
|
560
|
-
subject: "Payment Authorization",
|
|
561
|
-
text: authorizationUrls[0] || "No Authorization Url"
|
|
531
|
+
const { command: upsertBatch } = upsertBatchCommand(this.db, {
|
|
532
|
+
batch: {
|
|
533
|
+
...batch,
|
|
534
|
+
payments,
|
|
535
|
+
metadata,
|
|
536
|
+
status: "READY_TO_SIGN",
|
|
537
|
+
authorizationUrls,
|
|
538
|
+
batchPaymentInitiatedAt: /* @__PURE__ */ new Date()
|
|
562
539
|
}
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
540
|
+
});
|
|
541
|
+
const updatePayments = payments.map(
|
|
542
|
+
(payment) => updatePaymentCommand(this.db, {
|
|
543
|
+
payment: { ...payment, status: "INITIALIZED" }
|
|
544
|
+
}).command
|
|
545
|
+
);
|
|
546
|
+
await this.db.batch([upsertBatch, ...updatePayments]);
|
|
547
|
+
this.log({
|
|
548
|
+
message: "Authorization Urls for batch to create",
|
|
549
|
+
authorizationUrl: authorizationUrls[0]
|
|
550
|
+
});
|
|
551
|
+
await this.pushToQueue(this.env.NOTIFICATIONS_QUEUE, {
|
|
552
|
+
type: "email",
|
|
553
|
+
payload: {
|
|
554
|
+
email: {
|
|
555
|
+
to: [this.env.BANK_AUTH_RECIPIENT],
|
|
556
|
+
subject: "Payment Authorization",
|
|
557
|
+
text: authorizationUrls[0] || "No Authorization Url"
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
metadata: {
|
|
561
|
+
initiator: {
|
|
562
|
+
service: this.name
|
|
563
|
+
}
|
|
567
564
|
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
565
|
+
});
|
|
566
|
+
this.logOutput({ message: "Batch successfully processed" });
|
|
567
|
+
}
|
|
568
|
+
);
|
|
572
569
|
}
|
|
573
570
|
async queue(b) {
|
|
574
571
|
await this.handleAction(
|
package/dist/export/worker.d.cts
CHANGED
|
@@ -212,6 +212,21 @@ interface GetBatchesOutput {
|
|
|
212
212
|
totalCount: number;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
declare const processBatchInputSchema: z.ZodObject<{
|
|
216
|
+
connectorKey: z.ZodEnum<{
|
|
217
|
+
ERSTE: "ERSTE";
|
|
218
|
+
FINBRICKS: "FINBRICKS";
|
|
219
|
+
MOCK: "MOCK";
|
|
220
|
+
CREDITAS: "CREDITAS";
|
|
221
|
+
MOCK_COBS: "MOCK_COBS";
|
|
222
|
+
FIO: "FIO";
|
|
223
|
+
MONETA: "MONETA";
|
|
224
|
+
}>;
|
|
225
|
+
batch: z.ZodCustom<BatchSelectType, BatchSelectType>;
|
|
226
|
+
}, z.core.$strip>;
|
|
227
|
+
interface ProcessBatchInput extends z.infer<typeof processBatchInputSchema> {
|
|
228
|
+
}
|
|
229
|
+
|
|
215
230
|
declare const BankServiceBase_base: (abstract new (ctx: ExecutionContext, env: BankEnv) => WorkerEntrypoint<BankEnv, {}>) & (abstract new (...args: any[]) => _develit_io_backend_sdk.DevelitWorkerMethods);
|
|
216
231
|
declare class BankServiceBase extends BankServiceBase_base {
|
|
217
232
|
readonly configAccounts: ConfigEnvironmentBankAccount;
|
|
@@ -226,21 +241,18 @@ declare class BankServiceBase extends BankServiceBase_base {
|
|
|
226
241
|
addPaymentsToBatch({ paymentsToBatch, }: {
|
|
227
242
|
paymentsToBatch: SendPaymentInput[];
|
|
228
243
|
}): Promise<IRPCResponse<{
|
|
229
|
-
status: "PREPARED" | "FAILED" | "COMPLETED" | "OPEN" | "WAITING_FOR_PROCESSING" | "PROCESSING" | "READY_TO_SIGN" | null;
|
|
230
|
-
batchPaymentInitiatedAt: Date | null;
|
|
231
|
-
authorizationUrls: string | string[] | null;
|
|
232
244
|
accountId: string | null;
|
|
233
|
-
payments: PaymentInsertType[];
|
|
234
|
-
metadata: object | null;
|
|
235
245
|
id: string;
|
|
236
246
|
createdAt: Date | null;
|
|
237
247
|
updatedAt: Date | null;
|
|
238
248
|
deletedAt: Date | null;
|
|
249
|
+
status: "PREPARED" | "FAILED" | "COMPLETED" | "OPEN" | "WAITING_FOR_PROCESSING" | "PROCESSING" | "READY_TO_SIGN" | null;
|
|
250
|
+
batchPaymentInitiatedAt: Date | null;
|
|
251
|
+
authorizationUrls: string | string[] | null;
|
|
252
|
+
payments: PaymentInsertType[];
|
|
253
|
+
metadata: object | null;
|
|
239
254
|
}[] | undefined>>;
|
|
240
|
-
processBatch(
|
|
241
|
-
batch: BatchSelectType;
|
|
242
|
-
connectorKey: ConnectorKey;
|
|
243
|
-
}): Promise<IRPCResponse<void>>;
|
|
255
|
+
processBatch(input: ProcessBatchInput): Promise<IRPCResponse<void>>;
|
|
244
256
|
queue(b: MessageBatch<SendPaymentInput>): Promise<void>;
|
|
245
257
|
getAuthUri(input: GetAuthUriInput): Promise<IRPCResponse<GetAuthUriOutput>>;
|
|
246
258
|
authorizeAccount(input: AuthorizeAccountInput): Promise<IRPCResponse<AuthorizeAccountOutput>>;
|
package/dist/export/worker.d.mts
CHANGED
|
@@ -212,6 +212,21 @@ interface GetBatchesOutput {
|
|
|
212
212
|
totalCount: number;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
declare const processBatchInputSchema: z.ZodObject<{
|
|
216
|
+
connectorKey: z.ZodEnum<{
|
|
217
|
+
ERSTE: "ERSTE";
|
|
218
|
+
FINBRICKS: "FINBRICKS";
|
|
219
|
+
MOCK: "MOCK";
|
|
220
|
+
CREDITAS: "CREDITAS";
|
|
221
|
+
MOCK_COBS: "MOCK_COBS";
|
|
222
|
+
FIO: "FIO";
|
|
223
|
+
MONETA: "MONETA";
|
|
224
|
+
}>;
|
|
225
|
+
batch: z.ZodCustom<BatchSelectType, BatchSelectType>;
|
|
226
|
+
}, z.core.$strip>;
|
|
227
|
+
interface ProcessBatchInput extends z.infer<typeof processBatchInputSchema> {
|
|
228
|
+
}
|
|
229
|
+
|
|
215
230
|
declare const BankServiceBase_base: (abstract new (ctx: ExecutionContext, env: BankEnv) => WorkerEntrypoint<BankEnv, {}>) & (abstract new (...args: any[]) => _develit_io_backend_sdk.DevelitWorkerMethods);
|
|
216
231
|
declare class BankServiceBase extends BankServiceBase_base {
|
|
217
232
|
readonly configAccounts: ConfigEnvironmentBankAccount;
|
|
@@ -226,21 +241,18 @@ declare class BankServiceBase extends BankServiceBase_base {
|
|
|
226
241
|
addPaymentsToBatch({ paymentsToBatch, }: {
|
|
227
242
|
paymentsToBatch: SendPaymentInput[];
|
|
228
243
|
}): Promise<IRPCResponse<{
|
|
229
|
-
status: "PREPARED" | "FAILED" | "COMPLETED" | "OPEN" | "WAITING_FOR_PROCESSING" | "PROCESSING" | "READY_TO_SIGN" | null;
|
|
230
|
-
batchPaymentInitiatedAt: Date | null;
|
|
231
|
-
authorizationUrls: string | string[] | null;
|
|
232
244
|
accountId: string | null;
|
|
233
|
-
payments: PaymentInsertType[];
|
|
234
|
-
metadata: object | null;
|
|
235
245
|
id: string;
|
|
236
246
|
createdAt: Date | null;
|
|
237
247
|
updatedAt: Date | null;
|
|
238
248
|
deletedAt: Date | null;
|
|
249
|
+
status: "PREPARED" | "FAILED" | "COMPLETED" | "OPEN" | "WAITING_FOR_PROCESSING" | "PROCESSING" | "READY_TO_SIGN" | null;
|
|
250
|
+
batchPaymentInitiatedAt: Date | null;
|
|
251
|
+
authorizationUrls: string | string[] | null;
|
|
252
|
+
payments: PaymentInsertType[];
|
|
253
|
+
metadata: object | null;
|
|
239
254
|
}[] | undefined>>;
|
|
240
|
-
processBatch(
|
|
241
|
-
batch: BatchSelectType;
|
|
242
|
-
connectorKey: ConnectorKey;
|
|
243
|
-
}): Promise<IRPCResponse<void>>;
|
|
255
|
+
processBatch(input: ProcessBatchInput): Promise<IRPCResponse<void>>;
|
|
244
256
|
queue(b: MessageBatch<SendPaymentInput>): Promise<void>;
|
|
245
257
|
getAuthUri(input: GetAuthUriInput): Promise<IRPCResponse<GetAuthUriOutput>>;
|
|
246
258
|
authorizeAccount(input: AuthorizeAccountInput): Promise<IRPCResponse<AuthorizeAccountOutput>>;
|
package/dist/export/worker.d.ts
CHANGED
|
@@ -212,6 +212,21 @@ interface GetBatchesOutput {
|
|
|
212
212
|
totalCount: number;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
declare const processBatchInputSchema: z.ZodObject<{
|
|
216
|
+
connectorKey: z.ZodEnum<{
|
|
217
|
+
ERSTE: "ERSTE";
|
|
218
|
+
FINBRICKS: "FINBRICKS";
|
|
219
|
+
MOCK: "MOCK";
|
|
220
|
+
CREDITAS: "CREDITAS";
|
|
221
|
+
MOCK_COBS: "MOCK_COBS";
|
|
222
|
+
FIO: "FIO";
|
|
223
|
+
MONETA: "MONETA";
|
|
224
|
+
}>;
|
|
225
|
+
batch: z.ZodCustom<BatchSelectType, BatchSelectType>;
|
|
226
|
+
}, z.core.$strip>;
|
|
227
|
+
interface ProcessBatchInput extends z.infer<typeof processBatchInputSchema> {
|
|
228
|
+
}
|
|
229
|
+
|
|
215
230
|
declare const BankServiceBase_base: (abstract new (ctx: ExecutionContext, env: BankEnv) => WorkerEntrypoint<BankEnv, {}>) & (abstract new (...args: any[]) => _develit_io_backend_sdk.DevelitWorkerMethods);
|
|
216
231
|
declare class BankServiceBase extends BankServiceBase_base {
|
|
217
232
|
readonly configAccounts: ConfigEnvironmentBankAccount;
|
|
@@ -226,21 +241,18 @@ declare class BankServiceBase extends BankServiceBase_base {
|
|
|
226
241
|
addPaymentsToBatch({ paymentsToBatch, }: {
|
|
227
242
|
paymentsToBatch: SendPaymentInput[];
|
|
228
243
|
}): Promise<IRPCResponse<{
|
|
229
|
-
status: "PREPARED" | "FAILED" | "COMPLETED" | "OPEN" | "WAITING_FOR_PROCESSING" | "PROCESSING" | "READY_TO_SIGN" | null;
|
|
230
|
-
batchPaymentInitiatedAt: Date | null;
|
|
231
|
-
authorizationUrls: string | string[] | null;
|
|
232
244
|
accountId: string | null;
|
|
233
|
-
payments: PaymentInsertType[];
|
|
234
|
-
metadata: object | null;
|
|
235
245
|
id: string;
|
|
236
246
|
createdAt: Date | null;
|
|
237
247
|
updatedAt: Date | null;
|
|
238
248
|
deletedAt: Date | null;
|
|
249
|
+
status: "PREPARED" | "FAILED" | "COMPLETED" | "OPEN" | "WAITING_FOR_PROCESSING" | "PROCESSING" | "READY_TO_SIGN" | null;
|
|
250
|
+
batchPaymentInitiatedAt: Date | null;
|
|
251
|
+
authorizationUrls: string | string[] | null;
|
|
252
|
+
payments: PaymentInsertType[];
|
|
253
|
+
metadata: object | null;
|
|
239
254
|
}[] | undefined>>;
|
|
240
|
-
processBatch(
|
|
241
|
-
batch: BatchSelectType;
|
|
242
|
-
connectorKey: ConnectorKey;
|
|
243
|
-
}): Promise<IRPCResponse<void>>;
|
|
255
|
+
processBatch(input: ProcessBatchInput): Promise<IRPCResponse<void>>;
|
|
244
256
|
queue(b: MessageBatch<SendPaymentInput>): Promise<void>;
|
|
245
257
|
getAuthUri(input: GetAuthUriInput): Promise<IRPCResponse<GetAuthUriOutput>>;
|
|
246
258
|
authorizeAccount(input: AuthorizeAccountInput): Promise<IRPCResponse<AuthorizeAccountOutput>>;
|
package/dist/export/worker.mjs
CHANGED
|
@@ -65,6 +65,11 @@ const getBatchesInputSchema = z.object({
|
|
|
65
65
|
offset: z.number().min(0).optional().default(0)
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
+
const processBatchInputSchema = z.object({
|
|
69
|
+
connectorKey: z.enum(CONNECTOR_KEYS),
|
|
70
|
+
batch: z.custom()
|
|
71
|
+
});
|
|
72
|
+
|
|
68
73
|
const createPaymentCommand = (db, { payment }) => {
|
|
69
74
|
return {
|
|
70
75
|
command: db.insert(tables.payment).values(payment).returning()
|
|
@@ -127,10 +132,6 @@ const getOpenBatchByAccountIdQuery = async (db, { accountId }) => {
|
|
|
127
132
|
return batch;
|
|
128
133
|
};
|
|
129
134
|
|
|
130
|
-
const getAllOpenBatchesQuery = async (db) => {
|
|
131
|
-
return await db.select().from(tables.batch).where(eq(tables.batch.status, "OPEN"));
|
|
132
|
-
};
|
|
133
|
-
|
|
134
135
|
const getPaymentsByBankRefIdsQuery = async (db, { ids }) => {
|
|
135
136
|
return await db.select().from(tables.payment).where(inArray(tables.payment.bankRefId, ids));
|
|
136
137
|
};
|
|
@@ -323,28 +324,6 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
323
324
|
});
|
|
324
325
|
}
|
|
325
326
|
async scheduled(controller) {
|
|
326
|
-
if (controller.cron === this.env.CRON_BATCHES_PROCESSING) {
|
|
327
|
-
console.log("Scheduled CRON batches processing");
|
|
328
|
-
const openBatches = await getAllOpenBatchesQuery(this.db);
|
|
329
|
-
if (!openBatches.length) return;
|
|
330
|
-
for (const batch of openBatches) {
|
|
331
|
-
const connectorKey = this.accounts.find(
|
|
332
|
-
(acc) => acc.id === batch.accountId
|
|
333
|
-
)?.connectorKey;
|
|
334
|
-
if (!connectorKey) {
|
|
335
|
-
this.logError({
|
|
336
|
-
message: "Failed to find connector key",
|
|
337
|
-
batch,
|
|
338
|
-
connectorKey
|
|
339
|
-
});
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
await this.processBatch({
|
|
343
|
-
batch,
|
|
344
|
-
connectorKey
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
327
|
if (controller.cron === this.env.CRON_PAYMENTS_PROCESSING) {
|
|
349
328
|
console.log("Scheduled CRON payments processing");
|
|
350
329
|
await this.syncAccounts();
|
|
@@ -459,108 +438,126 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
459
438
|
}
|
|
460
439
|
});
|
|
461
440
|
}
|
|
462
|
-
async processBatch({
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
441
|
+
async processBatch(input) {
|
|
442
|
+
return this.handleAction(
|
|
443
|
+
{ data: input, schema: processBatchInputSchema },
|
|
444
|
+
{},
|
|
445
|
+
async ({ batch, connectorKey }) => {
|
|
446
|
+
await upsertBatchCommand(this.db, {
|
|
447
|
+
batch: {
|
|
448
|
+
...batch,
|
|
449
|
+
status: "PROCESSING"
|
|
450
|
+
}
|
|
451
|
+
}).command.execute();
|
|
452
|
+
await this.initiateBankConnector({ connectorKey });
|
|
453
|
+
if (!this.bankConnector) {
|
|
454
|
+
await upsertBatchCommand(this.db, {
|
|
455
|
+
batch: {
|
|
456
|
+
...batch,
|
|
457
|
+
status: "FAILED"
|
|
458
|
+
}
|
|
459
|
+
}).command.execute();
|
|
460
|
+
throw createInternalError(null, {
|
|
461
|
+
message: `\u274C Failed to initialize ${connectorKey} bank connector`
|
|
462
|
+
});
|
|
472
463
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
if (!this.bankConnector) {
|
|
476
|
-
throw createInternalError(null, {
|
|
477
|
-
message: `\u274C Failed to initialize ${connectorKey} bank connector`
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
this.log({
|
|
481
|
-
message: `\u2705 Bank connector initialized successfully for account ${connectorKey}`
|
|
482
|
-
});
|
|
483
|
-
const preparedBatch = {
|
|
484
|
-
retriedPayments: [],
|
|
485
|
-
newlyPreparedPayments: [],
|
|
486
|
-
failedPayments: []
|
|
487
|
-
};
|
|
488
|
-
for (const payment of batch.payments) {
|
|
489
|
-
const existingPayment = await getPaymentByRefIdQuery(this.db, {
|
|
490
|
-
refId: payment.refId
|
|
464
|
+
this.log({
|
|
465
|
+
message: `\u2705 Bank connector initialized successfully for account ${connectorKey}`
|
|
491
466
|
});
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
467
|
+
const preparedBatch = {
|
|
468
|
+
retriedPayments: [],
|
|
469
|
+
newlyPreparedPayments: [],
|
|
470
|
+
failedPayments: []
|
|
471
|
+
};
|
|
472
|
+
for (const payment of batch.payments) {
|
|
473
|
+
const existingPayment = await getPaymentByRefIdQuery(this.db, {
|
|
474
|
+
refId: payment.refId
|
|
499
475
|
});
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
476
|
+
if (existingPayment) {
|
|
477
|
+
preparedBatch.retriedPayments.push({
|
|
478
|
+
...existingPayment,
|
|
479
|
+
status: "PREPARED"
|
|
480
|
+
});
|
|
481
|
+
this.log({
|
|
482
|
+
message: `\u2705 Payment ${existingPayment.id} already exists`
|
|
483
|
+
});
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
const newlyPreparedPayment = await this.bankConnector.preparePayment(payment);
|
|
487
|
+
if (!newlyPreparedPayment) {
|
|
488
|
+
preparedBatch.failedPayments.push({ ...payment, status: "FAILED" });
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
preparedBatch.newlyPreparedPayments.push(newlyPreparedPayment);
|
|
506
492
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
493
|
+
await Promise.all([
|
|
494
|
+
[
|
|
495
|
+
...preparedBatch.failedPayments,
|
|
496
|
+
...preparedBatch.newlyPreparedPayments
|
|
497
|
+
].map(
|
|
498
|
+
(p) => createPaymentCommand(this.db, { payment: p }).command.execute()
|
|
499
|
+
)
|
|
500
|
+
]);
|
|
501
|
+
await upsertBatchCommand(this.db, {
|
|
502
|
+
batch: {
|
|
503
|
+
...batch,
|
|
504
|
+
status: "PREPARED"
|
|
505
|
+
}
|
|
506
|
+
}).command.execute();
|
|
507
|
+
const { authorizationUrls, payments, metadata } = await this.bankConnector.initiateBatchFromPayments({
|
|
508
|
+
payments: [
|
|
509
|
+
...preparedBatch.newlyPreparedPayments,
|
|
510
|
+
...preparedBatch.retriedPayments
|
|
511
|
+
]
|
|
512
|
+
});
|
|
513
|
+
if (!authorizationUrls) {
|
|
514
|
+
this.logError({ message: "Failed to retrieve signing URI" });
|
|
515
|
+
await upsertBatchCommand(this.db, {
|
|
516
|
+
batch: {
|
|
517
|
+
...batch,
|
|
518
|
+
status: "FAILED"
|
|
519
|
+
}
|
|
520
|
+
}).command.execute();
|
|
521
|
+
return;
|
|
535
522
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
message: "Authorization Urls for batch to create",
|
|
545
|
-
authorizationUrl: authorizationUrls[0]
|
|
546
|
-
});
|
|
547
|
-
await this.pushToQueue(this.env.NOTIFICATIONS_QUEUE, {
|
|
548
|
-
type: "email",
|
|
549
|
-
payload: {
|
|
550
|
-
email: {
|
|
551
|
-
to: ["petr@develit.io"],
|
|
552
|
-
subject: "Payment Authorization",
|
|
553
|
-
text: authorizationUrls[0] || "No Authorization Url"
|
|
523
|
+
const { command: upsertBatch } = upsertBatchCommand(this.db, {
|
|
524
|
+
batch: {
|
|
525
|
+
...batch,
|
|
526
|
+
payments,
|
|
527
|
+
metadata,
|
|
528
|
+
status: "READY_TO_SIGN",
|
|
529
|
+
authorizationUrls,
|
|
530
|
+
batchPaymentInitiatedAt: /* @__PURE__ */ new Date()
|
|
554
531
|
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
532
|
+
});
|
|
533
|
+
const updatePayments = payments.map(
|
|
534
|
+
(payment) => updatePaymentCommand(this.db, {
|
|
535
|
+
payment: { ...payment, status: "INITIALIZED" }
|
|
536
|
+
}).command
|
|
537
|
+
);
|
|
538
|
+
await this.db.batch([upsertBatch, ...updatePayments]);
|
|
539
|
+
this.log({
|
|
540
|
+
message: "Authorization Urls for batch to create",
|
|
541
|
+
authorizationUrl: authorizationUrls[0]
|
|
542
|
+
});
|
|
543
|
+
await this.pushToQueue(this.env.NOTIFICATIONS_QUEUE, {
|
|
544
|
+
type: "email",
|
|
545
|
+
payload: {
|
|
546
|
+
email: {
|
|
547
|
+
to: [this.env.BANK_AUTH_RECIPIENT],
|
|
548
|
+
subject: "Payment Authorization",
|
|
549
|
+
text: authorizationUrls[0] || "No Authorization Url"
|
|
550
|
+
}
|
|
551
|
+
},
|
|
552
|
+
metadata: {
|
|
553
|
+
initiator: {
|
|
554
|
+
service: this.name
|
|
555
|
+
}
|
|
559
556
|
}
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
557
|
+
});
|
|
558
|
+
this.logOutput({ message: "Batch successfully processed" });
|
|
559
|
+
}
|
|
560
|
+
);
|
|
564
561
|
}
|
|
565
562
|
async queue(b) {
|
|
566
563
|
await this.handleAction(
|
package/dist/export/wrangler.cjs
CHANGED
|
@@ -26,7 +26,8 @@ function defineBankServiceWrangler(config) {
|
|
|
26
26
|
FINBRICKS_BASE_URI: "https://api.sandbox.finbricks.com",
|
|
27
27
|
FINBRICKS_MERCHANT_ID: "10435c82-84b4-4efa-b5bf-ae6cd723e653",
|
|
28
28
|
CRON_BATCHES_PROCESSING: "* * * * *",
|
|
29
|
-
CRON_PAYMENTS_PROCESSING: "* * * * *"
|
|
29
|
+
CRON_PAYMENTS_PROCESSING: "* * * * *",
|
|
30
|
+
BANK_AUTH_RECIPIENT: "petr@develit.io"
|
|
30
31
|
},
|
|
31
32
|
triggers: envs.local.triggers,
|
|
32
33
|
kv_namespaces: [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BankServiceWranglerConfig } from '../shared/bank.
|
|
1
|
+
import { B as BankServiceWranglerConfig } from '../shared/bank.CEZKAEiY.cjs';
|
|
2
2
|
|
|
3
3
|
declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
|
|
4
4
|
vars: {
|
|
@@ -12,6 +12,7 @@ declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
|
|
|
12
12
|
FINBRICKS_MERCHANT_ID: string;
|
|
13
13
|
CRON_BATCHES_PROCESSING: string;
|
|
14
14
|
CRON_PAYMENTS_PROCESSING: string;
|
|
15
|
+
BANK_AUTH_RECIPIENT: string;
|
|
15
16
|
ERSTE_REDIRECT_URI: string;
|
|
16
17
|
FINBRICKS_PRIVATE_KEY_PEM: string;
|
|
17
18
|
ERSTE_API_KEY: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BankServiceWranglerConfig } from '../shared/bank.
|
|
1
|
+
import { B as BankServiceWranglerConfig } from '../shared/bank.CEZKAEiY.mjs';
|
|
2
2
|
|
|
3
3
|
declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
|
|
4
4
|
vars: {
|
|
@@ -12,6 +12,7 @@ declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
|
|
|
12
12
|
FINBRICKS_MERCHANT_ID: string;
|
|
13
13
|
CRON_BATCHES_PROCESSING: string;
|
|
14
14
|
CRON_PAYMENTS_PROCESSING: string;
|
|
15
|
+
BANK_AUTH_RECIPIENT: string;
|
|
15
16
|
ERSTE_REDIRECT_URI: string;
|
|
16
17
|
FINBRICKS_PRIVATE_KEY_PEM: string;
|
|
17
18
|
ERSTE_API_KEY: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BankServiceWranglerConfig } from '../shared/bank.
|
|
1
|
+
import { B as BankServiceWranglerConfig } from '../shared/bank.CEZKAEiY.js';
|
|
2
2
|
|
|
3
3
|
declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
|
|
4
4
|
vars: {
|
|
@@ -12,6 +12,7 @@ declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
|
|
|
12
12
|
FINBRICKS_MERCHANT_ID: string;
|
|
13
13
|
CRON_BATCHES_PROCESSING: string;
|
|
14
14
|
CRON_PAYMENTS_PROCESSING: string;
|
|
15
|
+
BANK_AUTH_RECIPIENT: string;
|
|
15
16
|
ERSTE_REDIRECT_URI: string;
|
|
16
17
|
FINBRICKS_PRIVATE_KEY_PEM: string;
|
|
17
18
|
ERSTE_API_KEY: string;
|
package/dist/export/wrangler.mjs
CHANGED
|
@@ -24,7 +24,8 @@ function defineBankServiceWrangler(config) {
|
|
|
24
24
|
FINBRICKS_BASE_URI: "https://api.sandbox.finbricks.com",
|
|
25
25
|
FINBRICKS_MERCHANT_ID: "10435c82-84b4-4efa-b5bf-ae6cd723e653",
|
|
26
26
|
CRON_BATCHES_PROCESSING: "* * * * *",
|
|
27
|
-
CRON_PAYMENTS_PROCESSING: "* * * * *"
|
|
27
|
+
CRON_PAYMENTS_PROCESSING: "* * * * *",
|
|
28
|
+
BANK_AUTH_RECIPIENT: "petr@develit.io"
|
|
28
29
|
},
|
|
29
30
|
triggers: envs.local.triggers,
|
|
30
31
|
kv_namespaces: [
|
package/dist/types.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ import { t as tables, a as PaymentInsertType, P as PaymentSelectType } from './s
|
|
|
4
4
|
export { b as BatchInsertType, B as BatchSelectType, p as paymentInsertTypeZod } from './shared/bank.BuNG2S8h.cjs';
|
|
5
5
|
import { Environment, BaseEvent } from '@develit-io/backend-sdk';
|
|
6
6
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
7
|
-
export { b as BankServiceEnv, a as BankServiceEnvironmentConfig, B as BankServiceWranglerConfig } from './shared/bank.
|
|
7
|
+
export { b as BankServiceEnv, a as BankServiceEnvironmentConfig, B as BankServiceWranglerConfig } from './shared/bank.CEZKAEiY.cjs';
|
|
8
8
|
export { BANK_CODES, CURRENCY_CODES } from '@develit-io/general-codes';
|
|
9
9
|
import 'drizzle-orm/sqlite-core';
|
|
10
10
|
import 'drizzle-orm';
|
package/dist/types.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { t as tables, a as PaymentInsertType, P as PaymentSelectType } from './s
|
|
|
4
4
|
export { b as BatchInsertType, B as BatchSelectType, p as paymentInsertTypeZod } from './shared/bank.BuNG2S8h.mjs';
|
|
5
5
|
import { Environment, BaseEvent } from '@develit-io/backend-sdk';
|
|
6
6
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
7
|
-
export { b as BankServiceEnv, a as BankServiceEnvironmentConfig, B as BankServiceWranglerConfig } from './shared/bank.
|
|
7
|
+
export { b as BankServiceEnv, a as BankServiceEnvironmentConfig, B as BankServiceWranglerConfig } from './shared/bank.CEZKAEiY.mjs';
|
|
8
8
|
export { BANK_CODES, CURRENCY_CODES } from '@develit-io/general-codes';
|
|
9
9
|
import 'drizzle-orm/sqlite-core';
|
|
10
10
|
import 'drizzle-orm';
|
package/dist/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { t as tables, a as PaymentInsertType, P as PaymentSelectType } from './s
|
|
|
4
4
|
export { b as BatchInsertType, B as BatchSelectType, p as paymentInsertTypeZod } from './shared/bank.BuNG2S8h.js';
|
|
5
5
|
import { Environment, BaseEvent } from '@develit-io/backend-sdk';
|
|
6
6
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
7
|
-
export { b as BankServiceEnv, a as BankServiceEnvironmentConfig, B as BankServiceWranglerConfig } from './shared/bank.
|
|
7
|
+
export { b as BankServiceEnv, a as BankServiceEnvironmentConfig, B as BankServiceWranglerConfig } from './shared/bank.CEZKAEiY.js';
|
|
8
8
|
export { BANK_CODES, CURRENCY_CODES } from '@develit-io/general-codes';
|
|
9
9
|
import 'drizzle-orm/sqlite-core';
|
|
10
10
|
import 'drizzle-orm';
|