@develit-services/bank 0.8.1 → 0.8.3

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.
Files changed (41) hide show
  1. package/README.md +82 -6
  2. package/dist/database/schema.cjs +9 -7
  3. package/dist/database/schema.d.cts +1 -1
  4. package/dist/database/schema.d.mts +1 -1
  5. package/dist/database/schema.d.ts +1 -1
  6. package/dist/database/schema.mjs +1 -1
  7. package/dist/export/worker.cjs +211 -43
  8. package/dist/export/worker.d.cts +23 -8
  9. package/dist/export/worker.d.mts +23 -8
  10. package/dist/export/worker.d.ts +23 -8
  11. package/dist/export/worker.mjs +202 -34
  12. package/dist/export/workflows.cjs +71 -52
  13. package/dist/export/workflows.mjs +71 -52
  14. package/dist/export/wrangler.d.cts +1 -2
  15. package/dist/export/wrangler.d.mts +1 -2
  16. package/dist/export/wrangler.d.ts +1 -2
  17. package/dist/shared/{bank.C0p-hLzn.d.mts → bank.BE9bK1n7.d.mts} +213 -3
  18. package/dist/shared/{bank.Bs7mkXbR.cjs → bank.BOnP9p9Y.cjs} +15 -2
  19. package/dist/shared/bank.C-T1FQxg.cjs +17 -0
  20. package/dist/shared/{bank.993UA65l.mjs → bank.C4VOdIx1.mjs} +57 -5
  21. package/dist/shared/{bank.BC06Rbrx.d.cts → bank.CQBfbG8u.d.cts} +0 -1
  22. package/dist/shared/{bank.BC06Rbrx.d.mts → bank.CQBfbG8u.d.mts} +0 -1
  23. package/dist/shared/{bank.BC06Rbrx.d.ts → bank.CQBfbG8u.d.ts} +0 -1
  24. package/dist/shared/{bank.Ce-NBBw1.cjs → bank.CQURey1E.cjs} +64 -7
  25. package/dist/shared/{bank.CGIeLo8U.mjs → bank.Cpy9PULF.mjs} +14 -3
  26. package/dist/shared/bank.DDHrdFgy.mjs +15 -0
  27. package/dist/shared/{bank.BJ7LqYtJ.d.cts → bank.DDveEfub.d.cts} +707 -126
  28. package/dist/shared/{bank.BJ7LqYtJ.d.mts → bank.DDveEfub.d.mts} +707 -126
  29. package/dist/shared/{bank.BJ7LqYtJ.d.ts → bank.DDveEfub.d.ts} +707 -126
  30. package/dist/shared/{bank.CeRbuycV.mjs → bank.DRrBrAdI.mjs} +62 -8
  31. package/dist/shared/{bank.IVhZ_RlH.cjs → bank.SQ4Mmr8u.cjs} +57 -3
  32. package/dist/shared/{bank.C0p-hLzn.d.ts → bank.gl4dlxWy.d.cts} +213 -3
  33. package/dist/shared/{bank.C0p-hLzn.d.cts → bank.pngKIcOl.d.ts} +213 -3
  34. package/dist/types.cjs +25 -23
  35. package/dist/types.d.cts +29 -180
  36. package/dist/types.d.mts +29 -180
  37. package/dist/types.d.ts +29 -180
  38. package/dist/types.mjs +2 -2
  39. package/package.json +1 -1
  40. package/dist/shared/bank.Cp0yvOdq.cjs +0 -15
  41. package/dist/shared/bank.fIGTiPnp.mjs +0 -13
@@ -1,7 +1,7 @@
1
- import { A as AccountSelectType, P as PaymentSelectType, B as BatchSelectType, L as LastSyncMetadata, C as ConfigEnvironmentBank, t as tables, a as ConnectorKey, I as IBankConnector } from '../shared/bank.BJ7LqYtJ.cjs';
1
+ import { A as AccountSelectType, P as PaymentSelectType, B as BatchSelectType, L as LastSyncMetadata, C as ConfigEnvironmentBank, t as tables, a as ConnectorKey, I as IBankConnector } from '../shared/bank.DDveEfub.cjs';
2
+ import { S as SendPaymentInput, a as SendPaymentOutput, b as SendPaymentSyncInput, c as SendPaymentSyncOutput, F as FinbricksSupportedBanksResponse } from '../shared/bank.gl4dlxWy.cjs';
2
3
  import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
3
4
  import { WorkflowInstanceStatus, IRPCResponse } from '@develit-io/backend-sdk';
4
- import { S as SendPaymentInput, a as SendPaymentOutput, b as SendPaymentSyncInput, c as SendPaymentSyncOutput } from '../shared/bank.C0p-hLzn.cjs';
5
5
  import { WorkerEntrypoint } from 'cloudflare:workers';
6
6
  import { DrizzleD1Database } from 'drizzle-orm/d1';
7
7
  import { z } from 'zod';
@@ -802,18 +802,18 @@ declare const getBatchesInputSchema: z.ZodObject<{
802
802
  }, z.core.$strip>;
803
803
  filterBatchAccountId: z.ZodOptional<z.ZodUnion<readonly [z.ZodUUID, z.ZodArray<z.ZodUUID>]>>;
804
804
  filterBatchStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
805
+ SIGNED: "SIGNED";
805
806
  FAILED: "FAILED";
806
807
  OPEN: "OPEN";
807
808
  PROCESSING: "PROCESSING";
808
809
  READY_TO_SIGN: "READY_TO_SIGN";
809
- SIGNED: "SIGNED";
810
810
  SIGNATURE_FAILED: "SIGNATURE_FAILED";
811
811
  }>, z.ZodArray<z.ZodEnum<{
812
+ SIGNED: "SIGNED";
812
813
  FAILED: "FAILED";
813
814
  OPEN: "OPEN";
814
815
  PROCESSING: "PROCESSING";
815
816
  READY_TO_SIGN: "READY_TO_SIGN";
816
- SIGNED: "SIGNED";
817
817
  SIGNATURE_FAILED: "SIGNATURE_FAILED";
818
818
  }>>]>>;
819
819
  }, z.core.$strip>;
@@ -1059,17 +1059,19 @@ declare const getPaymentsInputSchema: z.ZodObject<{
1059
1059
  filterPaymentDateFrom: z.ZodOptional<z.ZodDate>;
1060
1060
  filterPaymentDateTo: z.ZodOptional<z.ZodDate>;
1061
1061
  filterPaymentStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
1062
+ CREATED: "CREATED";
1062
1063
  PREPARED: "PREPARED";
1063
- FAILED: "FAILED";
1064
+ SIGNED: "SIGNED";
1064
1065
  PENDING: "PENDING";
1065
1066
  COMPLETED: "COMPLETED";
1066
- CREATED: "CREATED";
1067
+ FAILED: "FAILED";
1067
1068
  }>, z.ZodArray<z.ZodEnum<{
1069
+ CREATED: "CREATED";
1068
1070
  PREPARED: "PREPARED";
1069
- FAILED: "FAILED";
1071
+ SIGNED: "SIGNED";
1070
1072
  PENDING: "PENDING";
1071
1073
  COMPLETED: "COMPLETED";
1072
- CREATED: "CREATED";
1074
+ FAILED: "FAILED";
1073
1075
  }>>]>>;
1074
1076
  }, z.core.$strip>;
1075
1077
  type GetPaymentsInput = z.input<typeof getPaymentsInputSchema>;
@@ -1757,6 +1759,17 @@ interface DisconnectAccountInput extends z.infer<typeof disconnectAccountInputSc
1757
1759
  interface DisconnectAccountOutput extends AccountSelectType {
1758
1760
  }
1759
1761
 
1762
+ declare const handleAuthorizationCallbackInputSchema: z.ZodObject<{
1763
+ paymentId: z.ZodOptional<z.ZodString>;
1764
+ batchId: z.ZodOptional<z.ZodString>;
1765
+ }, z.core.$strip>;
1766
+ type HandleAuthorizationCallbackInput = z.infer<typeof handleAuthorizationCallbackInputSchema>;
1767
+ type HandleAuthorizationCallbackOutput = {
1768
+ paymentsUpdated: number;
1769
+ batchId: string | null;
1770
+ batchSigned: boolean;
1771
+ };
1772
+
1760
1773
  declare const BankServiceBase_base: (abstract new (ctx: ExecutionContext, env: BankEnv) => WorkerEntrypoint<BankEnv, {}>) & (abstract new (...args: any[]) => _develit_io_backend_sdk.DevelitWorkerMethods);
1761
1774
  declare class BankServiceBase extends BankServiceBase_base {
1762
1775
  readonly db: DrizzleD1Database<typeof tables>;
@@ -1848,6 +1861,7 @@ declare class BankServiceBase extends BankServiceBase_base {
1848
1861
  statusChanged: boolean;
1849
1862
  } | null>;
1850
1863
  updateBatchStatuses(input?: UpdateBatchStatusesInput): Promise<IRPCResponse<UpdateBatchStatusesOutput>>;
1864
+ handleAuthorizationCallback(input: HandleAuthorizationCallbackInput): Promise<IRPCResponse<HandleAuthorizationCallbackOutput>>;
1851
1865
  addPaymentsToBatch({ paymentsToBatch, }: {
1852
1866
  paymentsToBatch: SendPaymentInput[];
1853
1867
  }): Promise<IRPCResponse<void>>;
@@ -1899,6 +1913,7 @@ declare class BankServiceBase extends BankServiceBase_base {
1899
1913
  updateAccount(input: UpdateAccountInput): Promise<IRPCResponse<UpdateAccountOutput>>;
1900
1914
  disconnectAccount(input: DisconnectAccountInput): Promise<IRPCResponse<DisconnectAccountOutput>>;
1901
1915
  getBatches(input: GetBatchesInput): Promise<IRPCResponse<GetBatchesOutput>>;
1916
+ getFinbricksSupportedBanks(): Promise<FinbricksSupportedBanksResponse>;
1902
1917
  }
1903
1918
  declare function defineBankService({ config, }: {
1904
1919
  config: ConfigEnvironmentBank;
@@ -1,7 +1,7 @@
1
- import { A as AccountSelectType, P as PaymentSelectType, B as BatchSelectType, L as LastSyncMetadata, C as ConfigEnvironmentBank, t as tables, a as ConnectorKey, I as IBankConnector } from '../shared/bank.BJ7LqYtJ.mjs';
1
+ import { A as AccountSelectType, P as PaymentSelectType, B as BatchSelectType, L as LastSyncMetadata, C as ConfigEnvironmentBank, t as tables, a as ConnectorKey, I as IBankConnector } from '../shared/bank.DDveEfub.mjs';
2
+ import { S as SendPaymentInput, a as SendPaymentOutput, b as SendPaymentSyncInput, c as SendPaymentSyncOutput, F as FinbricksSupportedBanksResponse } from '../shared/bank.BE9bK1n7.mjs';
2
3
  import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
3
4
  import { WorkflowInstanceStatus, IRPCResponse } from '@develit-io/backend-sdk';
4
- import { S as SendPaymentInput, a as SendPaymentOutput, b as SendPaymentSyncInput, c as SendPaymentSyncOutput } from '../shared/bank.C0p-hLzn.mjs';
5
5
  import { WorkerEntrypoint } from 'cloudflare:workers';
6
6
  import { DrizzleD1Database } from 'drizzle-orm/d1';
7
7
  import { z } from 'zod';
@@ -802,18 +802,18 @@ declare const getBatchesInputSchema: z.ZodObject<{
802
802
  }, z.core.$strip>;
803
803
  filterBatchAccountId: z.ZodOptional<z.ZodUnion<readonly [z.ZodUUID, z.ZodArray<z.ZodUUID>]>>;
804
804
  filterBatchStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
805
+ SIGNED: "SIGNED";
805
806
  FAILED: "FAILED";
806
807
  OPEN: "OPEN";
807
808
  PROCESSING: "PROCESSING";
808
809
  READY_TO_SIGN: "READY_TO_SIGN";
809
- SIGNED: "SIGNED";
810
810
  SIGNATURE_FAILED: "SIGNATURE_FAILED";
811
811
  }>, z.ZodArray<z.ZodEnum<{
812
+ SIGNED: "SIGNED";
812
813
  FAILED: "FAILED";
813
814
  OPEN: "OPEN";
814
815
  PROCESSING: "PROCESSING";
815
816
  READY_TO_SIGN: "READY_TO_SIGN";
816
- SIGNED: "SIGNED";
817
817
  SIGNATURE_FAILED: "SIGNATURE_FAILED";
818
818
  }>>]>>;
819
819
  }, z.core.$strip>;
@@ -1059,17 +1059,19 @@ declare const getPaymentsInputSchema: z.ZodObject<{
1059
1059
  filterPaymentDateFrom: z.ZodOptional<z.ZodDate>;
1060
1060
  filterPaymentDateTo: z.ZodOptional<z.ZodDate>;
1061
1061
  filterPaymentStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
1062
+ CREATED: "CREATED";
1062
1063
  PREPARED: "PREPARED";
1063
- FAILED: "FAILED";
1064
+ SIGNED: "SIGNED";
1064
1065
  PENDING: "PENDING";
1065
1066
  COMPLETED: "COMPLETED";
1066
- CREATED: "CREATED";
1067
+ FAILED: "FAILED";
1067
1068
  }>, z.ZodArray<z.ZodEnum<{
1069
+ CREATED: "CREATED";
1068
1070
  PREPARED: "PREPARED";
1069
- FAILED: "FAILED";
1071
+ SIGNED: "SIGNED";
1070
1072
  PENDING: "PENDING";
1071
1073
  COMPLETED: "COMPLETED";
1072
- CREATED: "CREATED";
1074
+ FAILED: "FAILED";
1073
1075
  }>>]>>;
1074
1076
  }, z.core.$strip>;
1075
1077
  type GetPaymentsInput = z.input<typeof getPaymentsInputSchema>;
@@ -1757,6 +1759,17 @@ interface DisconnectAccountInput extends z.infer<typeof disconnectAccountInputSc
1757
1759
  interface DisconnectAccountOutput extends AccountSelectType {
1758
1760
  }
1759
1761
 
1762
+ declare const handleAuthorizationCallbackInputSchema: z.ZodObject<{
1763
+ paymentId: z.ZodOptional<z.ZodString>;
1764
+ batchId: z.ZodOptional<z.ZodString>;
1765
+ }, z.core.$strip>;
1766
+ type HandleAuthorizationCallbackInput = z.infer<typeof handleAuthorizationCallbackInputSchema>;
1767
+ type HandleAuthorizationCallbackOutput = {
1768
+ paymentsUpdated: number;
1769
+ batchId: string | null;
1770
+ batchSigned: boolean;
1771
+ };
1772
+
1760
1773
  declare const BankServiceBase_base: (abstract new (ctx: ExecutionContext, env: BankEnv) => WorkerEntrypoint<BankEnv, {}>) & (abstract new (...args: any[]) => _develit_io_backend_sdk.DevelitWorkerMethods);
1761
1774
  declare class BankServiceBase extends BankServiceBase_base {
1762
1775
  readonly db: DrizzleD1Database<typeof tables>;
@@ -1848,6 +1861,7 @@ declare class BankServiceBase extends BankServiceBase_base {
1848
1861
  statusChanged: boolean;
1849
1862
  } | null>;
1850
1863
  updateBatchStatuses(input?: UpdateBatchStatusesInput): Promise<IRPCResponse<UpdateBatchStatusesOutput>>;
1864
+ handleAuthorizationCallback(input: HandleAuthorizationCallbackInput): Promise<IRPCResponse<HandleAuthorizationCallbackOutput>>;
1851
1865
  addPaymentsToBatch({ paymentsToBatch, }: {
1852
1866
  paymentsToBatch: SendPaymentInput[];
1853
1867
  }): Promise<IRPCResponse<void>>;
@@ -1899,6 +1913,7 @@ declare class BankServiceBase extends BankServiceBase_base {
1899
1913
  updateAccount(input: UpdateAccountInput): Promise<IRPCResponse<UpdateAccountOutput>>;
1900
1914
  disconnectAccount(input: DisconnectAccountInput): Promise<IRPCResponse<DisconnectAccountOutput>>;
1901
1915
  getBatches(input: GetBatchesInput): Promise<IRPCResponse<GetBatchesOutput>>;
1916
+ getFinbricksSupportedBanks(): Promise<FinbricksSupportedBanksResponse>;
1902
1917
  }
1903
1918
  declare function defineBankService({ config, }: {
1904
1919
  config: ConfigEnvironmentBank;
@@ -1,7 +1,7 @@
1
- import { A as AccountSelectType, P as PaymentSelectType, B as BatchSelectType, L as LastSyncMetadata, C as ConfigEnvironmentBank, t as tables, a as ConnectorKey, I as IBankConnector } from '../shared/bank.BJ7LqYtJ.js';
1
+ import { A as AccountSelectType, P as PaymentSelectType, B as BatchSelectType, L as LastSyncMetadata, C as ConfigEnvironmentBank, t as tables, a as ConnectorKey, I as IBankConnector } from '../shared/bank.DDveEfub.js';
2
+ import { S as SendPaymentInput, a as SendPaymentOutput, b as SendPaymentSyncInput, c as SendPaymentSyncOutput, F as FinbricksSupportedBanksResponse } from '../shared/bank.pngKIcOl.js';
2
3
  import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
3
4
  import { WorkflowInstanceStatus, IRPCResponse } from '@develit-io/backend-sdk';
4
- import { S as SendPaymentInput, a as SendPaymentOutput, b as SendPaymentSyncInput, c as SendPaymentSyncOutput } from '../shared/bank.C0p-hLzn.js';
5
5
  import { WorkerEntrypoint } from 'cloudflare:workers';
6
6
  import { DrizzleD1Database } from 'drizzle-orm/d1';
7
7
  import { z } from 'zod';
@@ -802,18 +802,18 @@ declare const getBatchesInputSchema: z.ZodObject<{
802
802
  }, z.core.$strip>;
803
803
  filterBatchAccountId: z.ZodOptional<z.ZodUnion<readonly [z.ZodUUID, z.ZodArray<z.ZodUUID>]>>;
804
804
  filterBatchStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
805
+ SIGNED: "SIGNED";
805
806
  FAILED: "FAILED";
806
807
  OPEN: "OPEN";
807
808
  PROCESSING: "PROCESSING";
808
809
  READY_TO_SIGN: "READY_TO_SIGN";
809
- SIGNED: "SIGNED";
810
810
  SIGNATURE_FAILED: "SIGNATURE_FAILED";
811
811
  }>, z.ZodArray<z.ZodEnum<{
812
+ SIGNED: "SIGNED";
812
813
  FAILED: "FAILED";
813
814
  OPEN: "OPEN";
814
815
  PROCESSING: "PROCESSING";
815
816
  READY_TO_SIGN: "READY_TO_SIGN";
816
- SIGNED: "SIGNED";
817
817
  SIGNATURE_FAILED: "SIGNATURE_FAILED";
818
818
  }>>]>>;
819
819
  }, z.core.$strip>;
@@ -1059,17 +1059,19 @@ declare const getPaymentsInputSchema: z.ZodObject<{
1059
1059
  filterPaymentDateFrom: z.ZodOptional<z.ZodDate>;
1060
1060
  filterPaymentDateTo: z.ZodOptional<z.ZodDate>;
1061
1061
  filterPaymentStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
1062
+ CREATED: "CREATED";
1062
1063
  PREPARED: "PREPARED";
1063
- FAILED: "FAILED";
1064
+ SIGNED: "SIGNED";
1064
1065
  PENDING: "PENDING";
1065
1066
  COMPLETED: "COMPLETED";
1066
- CREATED: "CREATED";
1067
+ FAILED: "FAILED";
1067
1068
  }>, z.ZodArray<z.ZodEnum<{
1069
+ CREATED: "CREATED";
1068
1070
  PREPARED: "PREPARED";
1069
- FAILED: "FAILED";
1071
+ SIGNED: "SIGNED";
1070
1072
  PENDING: "PENDING";
1071
1073
  COMPLETED: "COMPLETED";
1072
- CREATED: "CREATED";
1074
+ FAILED: "FAILED";
1073
1075
  }>>]>>;
1074
1076
  }, z.core.$strip>;
1075
1077
  type GetPaymentsInput = z.input<typeof getPaymentsInputSchema>;
@@ -1757,6 +1759,17 @@ interface DisconnectAccountInput extends z.infer<typeof disconnectAccountInputSc
1757
1759
  interface DisconnectAccountOutput extends AccountSelectType {
1758
1760
  }
1759
1761
 
1762
+ declare const handleAuthorizationCallbackInputSchema: z.ZodObject<{
1763
+ paymentId: z.ZodOptional<z.ZodString>;
1764
+ batchId: z.ZodOptional<z.ZodString>;
1765
+ }, z.core.$strip>;
1766
+ type HandleAuthorizationCallbackInput = z.infer<typeof handleAuthorizationCallbackInputSchema>;
1767
+ type HandleAuthorizationCallbackOutput = {
1768
+ paymentsUpdated: number;
1769
+ batchId: string | null;
1770
+ batchSigned: boolean;
1771
+ };
1772
+
1760
1773
  declare const BankServiceBase_base: (abstract new (ctx: ExecutionContext, env: BankEnv) => WorkerEntrypoint<BankEnv, {}>) & (abstract new (...args: any[]) => _develit_io_backend_sdk.DevelitWorkerMethods);
1761
1774
  declare class BankServiceBase extends BankServiceBase_base {
1762
1775
  readonly db: DrizzleD1Database<typeof tables>;
@@ -1848,6 +1861,7 @@ declare class BankServiceBase extends BankServiceBase_base {
1848
1861
  statusChanged: boolean;
1849
1862
  } | null>;
1850
1863
  updateBatchStatuses(input?: UpdateBatchStatusesInput): Promise<IRPCResponse<UpdateBatchStatusesOutput>>;
1864
+ handleAuthorizationCallback(input: HandleAuthorizationCallbackInput): Promise<IRPCResponse<HandleAuthorizationCallbackOutput>>;
1851
1865
  addPaymentsToBatch({ paymentsToBatch, }: {
1852
1866
  paymentsToBatch: SendPaymentInput[];
1853
1867
  }): Promise<IRPCResponse<void>>;
@@ -1899,6 +1913,7 @@ declare class BankServiceBase extends BankServiceBase_base {
1899
1913
  updateAccount(input: UpdateAccountInput): Promise<IRPCResponse<UpdateAccountOutput>>;
1900
1914
  disconnectAccount(input: DisconnectAccountInput): Promise<IRPCResponse<DisconnectAccountOutput>>;
1901
1915
  getBatches(input: GetBatchesInput): Promise<IRPCResponse<GetBatchesOutput>>;
1916
+ getFinbricksSupportedBanks(): Promise<FinbricksSupportedBanksResponse>;
1902
1917
  }
1903
1918
  declare function defineBankService({ config, }: {
1904
1919
  config: ConfigEnvironmentBank;
@@ -1,16 +1,16 @@
1
1
  import { uuidv4, first, buildMultiFilterConditions as buildMultiFilterConditions$1, bankAccountMetadataSchema, workflowInstanceStatusSchema, develitWorker, createInternalError, action, service } from '@develit-io/backend-sdk';
2
- import { t as tables, e as encrypt, b as createCredentialsResolver, u as upsertBatchCommand, g as getBatchByIdQuery, i as importAesKey, d as createPaymentCommand, a as getAccountByIdQuery } from '../shared/bank.CGIeLo8U.mjs';
2
+ import { t as tables, h as encrypt, d as createCredentialsResolver, u as upsertBatchCommand, a as getPaymentRequestsByBatchIdQuery, e as updatePaymentRequestStatusCommand, g as getBatchByIdQuery, i as importAesKey, f as createPaymentCommand, b as getAccountByIdQuery } from '../shared/bank.Cpy9PULF.mjs';
3
3
  import { WorkerEntrypoint } from 'cloudflare:workers';
4
4
  import { drizzle } from 'drizzle-orm/d1';
5
+ import { k as initiateConnector, m as mapFinbricksTransactionStatus, h as toIncomingPayment, d as assignAccount, i as toPaymentRequestInsert, t as toBatchedPayment, a as FinbricksClient, F as FINBRICKS_ENDPOINTS } from '../shared/bank.DRrBrAdI.mjs';
6
+ import 'jose';
5
7
  import { z } from 'zod';
6
- import { I as INSTRUCTION_PRIORITIES, C as CHARGE_BEARERS, e as PAYMENT_TYPES, a as CONNECTOR_KEYS, B as BATCH_STATUSES, d as PAYMENT_STATUSES, P as PAYMENT_DIRECTIONS, i as accountInsertSchema } from '../shared/bank.993UA65l.mjs';
8
+ import { I as INSTRUCTION_PRIORITIES, C as CHARGE_BEARERS, e as PAYMENT_TYPES, a as CONNECTOR_KEYS, B as BATCH_STATUSES, d as PAYMENT_STATUSES, P as PAYMENT_DIRECTIONS, i as accountInsertSchema } from '../shared/bank.C4VOdIx1.mjs';
7
9
  import { CURRENCY_CODES } from '@develit-io/general-codes';
8
10
  import 'date-fns';
9
- import 'jose';
10
11
  import { eq, sql, and, inArray, asc, desc, gte, lte } from 'drizzle-orm';
11
12
  import 'node:crypto';
12
- import { i as initiateConnector, g as toIncomingPayment, d as assignAccount, t as toBatchedPayment } from '../shared/bank.CeRbuycV.mjs';
13
- import '../shared/bank.fIGTiPnp.mjs';
13
+ import '../shared/bank.DDHrdFgy.mjs';
14
14
  import 'drizzle-orm/relations';
15
15
  import 'drizzle-orm/sqlite-core';
16
16
  import 'drizzle-zod';
@@ -92,6 +92,16 @@ const deletePaymentsByAccountCommand = (db, { accountId }) => {
92
92
  };
93
93
  };
94
94
 
95
+ const createPaymentRequestCommand = (db, { paymentRequest }) => {
96
+ return {
97
+ command: db.insert(tables.paymentRequest).values({
98
+ ...paymentRequest,
99
+ creditorIban: paymentRequest.creditor.iban,
100
+ debtorIban: paymentRequest.debtor.iban
101
+ }).returning()
102
+ };
103
+ };
104
+
95
105
  const getAccountBatchCountsQuery = async (db, { accountId }) => {
96
106
  const result = await db.select({
97
107
  totalCount: sql`COUNT(*)`.as("totalCount"),
@@ -142,7 +152,7 @@ const getAllAccountsQuery = async (db, filters) => {
142
152
  };
143
153
 
144
154
  const getAllPendingBatchesQuery = (db) => {
145
- return db.select().from(tables.batch).where(inArray(tables.batch.status, ["READY_TO_SIGN"]));
155
+ return db.select().from(tables.batch).where(inArray(tables.batch.status, ["READY_TO_SIGN", "SIGNED"]));
146
156
  };
147
157
 
148
158
  const buildMultiFilterConditions = (column, value) => {
@@ -247,6 +257,11 @@ const getOttQuery = async (db, { ott }) => {
247
257
  return await db.select().from(tables.ott).where(eq(tables.ott.oneTimeToken, ott)).get();
248
258
  };
249
259
 
260
+ const getPaymentRequestByIdQuery = async (db, { paymentId }) => {
261
+ const results = await db.select().from(tables.paymentRequest).where(eq(tables.paymentRequest.id, paymentId)).limit(1);
262
+ return results[0] ?? null;
263
+ };
264
+
250
265
  const seperateSupportedPayments = (incomingPayments, accounts) => {
251
266
  const [supportedPayments, unsupportedPayments] = incomingPayments.reduce(
252
267
  ([valid, invalid], payment) => {
@@ -270,7 +285,7 @@ const seperateSupportedPayments = (incomingPayments, accounts) => {
270
285
 
271
286
  const sendPaymentInputSchema = z.object({
272
287
  correlationId: z.string().min(1),
273
- refId: z.string(),
288
+ refId: z.string().optional(),
274
289
  amount: z.number().positive(),
275
290
  paymentType: z.enum(PAYMENT_TYPES),
276
291
  chargeBearer: z.enum(CHARGE_BEARERS).optional(),
@@ -432,6 +447,13 @@ const disconnectAccountInputSchema = z.object({
432
447
  accountId: z.uuid()
433
448
  });
434
449
 
450
+ const handleAuthorizationCallbackInputSchema = z.object({
451
+ paymentId: z.string().uuid().optional(),
452
+ batchId: z.string().uuid().optional()
453
+ }).refine((data) => data.paymentId || data.batchId, {
454
+ message: "Either paymentId or batchId is required"
455
+ });
456
+
435
457
  const sendPaymentSyncInputSchema = sendPaymentInputSchema;
436
458
 
437
459
  var __defProp = Object.defineProperty;
@@ -591,12 +613,45 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
591
613
  }).command.execute();
592
614
  statusChanged = true;
593
615
  }
616
+ if (statusChanged) {
617
+ const paymentRequests = await getPaymentRequestsByBatchIdQuery(this.db, {
618
+ batchId: batch.id
619
+ });
620
+ const perPaymentStatuses = "payments" in apiResponse ? apiResponse.payments : null;
621
+ const batchStatusToPaymentStatus = {
622
+ SIGNED: "SIGNED",
623
+ COMPLETED: "COMPLETED",
624
+ FAILED: "FAILED",
625
+ SIGNATURE_FAILED: "FAILED"
626
+ };
627
+ for (const pr of paymentRequests) {
628
+ let newStatus = pr.status;
629
+ if (perPaymentStatuses) {
630
+ const match = perPaymentStatuses.find(
631
+ (p) => p.merchantTransactionId === pr.id
632
+ );
633
+ if (match) {
634
+ newStatus = mapFinbricksTransactionStatus(
635
+ match.resultCode
636
+ );
637
+ }
638
+ } else {
639
+ newStatus = batchStatusToPaymentStatus[currentStatus] ?? pr.status;
640
+ }
641
+ if (newStatus !== pr.status) {
642
+ await updatePaymentRequestStatusCommand(this.db, {
643
+ id: pr.id,
644
+ status: newStatus,
645
+ processedAt: newStatus === "COMPLETED" || newStatus === "FAILED" ? /* @__PURE__ */ new Date() : void 0
646
+ }).command.execute();
647
+ }
648
+ }
649
+ }
594
650
  return {
595
651
  batchId: batch.id,
596
652
  previousStatus,
597
653
  currentStatus,
598
654
  statusChanged
599
- // eventSent,
600
655
  };
601
656
  }
602
657
  async updateBatchStatuses(input) {
@@ -668,6 +723,77 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
668
723
  }
669
724
  );
670
725
  }
726
+ async handleAuthorizationCallback(input) {
727
+ return this.handleAction(
728
+ { data: input, schema: handleAuthorizationCallbackInputSchema },
729
+ { successMessage: "Authorization callback processed" },
730
+ async ({ paymentId, batchId }) => {
731
+ let targetBatchId = null;
732
+ let paymentsUpdated = 0;
733
+ if (paymentId) {
734
+ const pr = await getPaymentRequestByIdQuery(this.db, { paymentId });
735
+ if (!pr) {
736
+ throw createInternalError(null, {
737
+ message: `Payment request not found: ${paymentId}`,
738
+ code: "DB-B-008",
739
+ status: 404
740
+ });
741
+ }
742
+ if (pr.status !== "SIGNED" && pr.status !== "COMPLETED") {
743
+ await updatePaymentRequestStatusCommand(this.db, {
744
+ id: paymentId,
745
+ status: "SIGNED"
746
+ }).command.execute();
747
+ paymentsUpdated = 1;
748
+ }
749
+ targetBatchId = pr.batchId;
750
+ }
751
+ if (batchId) {
752
+ targetBatchId = batchId;
753
+ const batchPayments = await getPaymentRequestsByBatchIdQuery(
754
+ this.db,
755
+ {
756
+ batchId
757
+ }
758
+ );
759
+ for (const pr of batchPayments) {
760
+ if (pr.status !== "SIGNED" && pr.status !== "COMPLETED") {
761
+ await updatePaymentRequestStatusCommand(this.db, {
762
+ id: pr.id,
763
+ status: "SIGNED"
764
+ }).command.execute();
765
+ paymentsUpdated++;
766
+ }
767
+ }
768
+ }
769
+ let batchSigned = false;
770
+ if (targetBatchId) {
771
+ const allPayments = await getPaymentRequestsByBatchIdQuery(this.db, {
772
+ batchId: targetBatchId
773
+ });
774
+ const allDone = allPayments.every(
775
+ (p) => p.status === "SIGNED" || p.status === "COMPLETED"
776
+ );
777
+ if (allDone) {
778
+ const batch = await getBatchByIdQuery(this.db, {
779
+ batchId: targetBatchId
780
+ });
781
+ if (batch && batch.status !== "SIGNED") {
782
+ await upsertBatchCommand(this.db, {
783
+ batch: { ...batch, status: "SIGNED" }
784
+ }).command.execute();
785
+ batchSigned = true;
786
+ }
787
+ }
788
+ }
789
+ return {
790
+ paymentsUpdated,
791
+ batchId: targetBatchId,
792
+ batchSigned
793
+ };
794
+ }
795
+ );
796
+ }
671
797
  async addPaymentsToBatch({
672
798
  paymentsToBatch
673
799
  }) {
@@ -713,21 +839,24 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
713
839
  (p) => p.sendAsSinglePayment !== true
714
840
  );
715
841
  for (const singlePayment of singlePayments) {
716
- const batchedPayment = toBatchedPayment(singlePayment);
717
- const { command } = upsertBatchCommand(this.db, {
842
+ const batchId = uuidv4();
843
+ const { command: upsertBatch } = upsertBatchCommand(this.db, {
718
844
  batch: {
719
- id: uuidv4(),
845
+ id: batchId,
720
846
  authorizationUrls: [],
721
847
  accountId: acc.id,
722
848
  paymentType: singlePayment.paymentType,
723
- payments: [batchedPayment],
724
849
  status: "OPEN",
725
- metadata: {
726
- sizeLimit: 1
727
- }
850
+ metadata: { sizeLimit: 1 }
728
851
  }
729
852
  });
730
- await command.execute();
853
+ const { command: insertPaymentRequest } = createPaymentRequestCommand(
854
+ this.db,
855
+ {
856
+ paymentRequest: toPaymentRequestInsert(singlePayment, batchId)
857
+ }
858
+ );
859
+ await this.db.batch([upsertBatch, insertPaymentRequest]);
731
860
  this.log({
732
861
  message: `\u2728 Created single payment batch (${singlePayment.paymentType}) for account ${acc.id}`
733
862
  });
@@ -742,30 +871,48 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
742
871
  accountId: acc.id,
743
872
  paymentType
744
873
  });
745
- const availableBatch = openBatches.find(
746
- (batch) => batch.payments.length < (batch.metadata?.sizeLimit ?? acc.batchSizeLimit)
747
- );
748
- this.log({
749
- message: availableBatch ? `\u{1F504} Found existing OPEN batch (${paymentType}) for account ${acc.id}, merging ${availableBatch.payments.length} existing + ${paymentsOfType.length} new payments` : `\u2728 Creating new batch (${paymentType}) for account ${acc.id} with ${paymentsOfType.length} payments`
750
- });
751
- const batchedPayments = paymentsOfType.map(toBatchedPayment);
752
- const { command } = upsertBatchCommand(this.db, {
753
- batch: availableBatch ? {
754
- ...availableBatch,
755
- payments: [...availableBatch.payments, ...batchedPayments]
756
- } : {
757
- id: uuidv4(),
874
+ let batchId;
875
+ let availableCount = 0;
876
+ let availableBatch;
877
+ for (const ob of openBatches) {
878
+ const existingPayments = await getPaymentRequestsByBatchIdQuery(
879
+ this.db,
880
+ { batchId: ob.id }
881
+ );
882
+ const limit = ob.metadata?.sizeLimit ?? acc.batchSizeLimit;
883
+ if (existingPayments.length < limit) {
884
+ availableBatch = ob;
885
+ availableCount = existingPayments.length;
886
+ break;
887
+ }
888
+ }
889
+ if (availableBatch) {
890
+ batchId = availableBatch.id;
891
+ this.log({
892
+ message: `\u{1F504} Found existing OPEN batch (${paymentType}) for account ${acc.id}, merging ${availableCount} existing + ${paymentsOfType.length} new payments`
893
+ });
894
+ } else {
895
+ batchId = uuidv4();
896
+ this.log({
897
+ message: `\u2728 Creating new batch (${paymentType}) for account ${acc.id} with ${paymentsOfType.length} payments`
898
+ });
899
+ }
900
+ const { command: upsertBatch } = upsertBatchCommand(this.db, {
901
+ batch: availableBatch ? { ...availableBatch } : {
902
+ id: batchId,
758
903
  authorizationUrls: [],
759
904
  accountId: acc.id,
760
905
  paymentType,
761
- payments: batchedPayments,
762
906
  status: "OPEN",
763
- metadata: {
764
- sizeLimit: acc.batchSizeLimit
765
- }
907
+ metadata: { sizeLimit: acc.batchSizeLimit }
766
908
  }
767
909
  });
768
- await command.execute();
910
+ const paymentRequestCommands = paymentsOfType.map(
911
+ (p) => createPaymentRequestCommand(this.db, {
912
+ paymentRequest: toPaymentRequestInsert(p, batchId)
913
+ }).command
914
+ );
915
+ await this.db.batch([upsertBatch, ...paymentRequestCommands]);
769
916
  this.log({
770
917
  message: `\u2705 Batch (${paymentType}) upserted successfully for account ${acc.id}`
771
918
  });
@@ -1254,6 +1401,24 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1254
1401
  }
1255
1402
  );
1256
1403
  }
1404
+ async getFinbricksSupportedBanks() {
1405
+ const privateKeyPem = (await this.env.SECRETS_STORE.get({
1406
+ secretName: "BANK_SERVICE_FINBRICKS_PRIVATE_KEY_PEM"
1407
+ })).data?.secretValue || "";
1408
+ const client = new FinbricksClient(
1409
+ this.env.FINBRICKS_BASE_URI,
1410
+ this.env.FINBRICKS_MERCHANT_ID,
1411
+ privateKeyPem,
1412
+ this.env.REDIRECT_URI
1413
+ );
1414
+ return client.request({
1415
+ endpoint: FINBRICKS_ENDPOINTS.BANK_INFO,
1416
+ method: "GET",
1417
+ query: {
1418
+ merchantId: this.env.FINBRICKS_MERCHANT_ID
1419
+ }
1420
+ });
1421
+ }
1257
1422
  };
1258
1423
  __decorateClass([
1259
1424
  action("get-payments")
@@ -1270,6 +1435,9 @@ __decorateClass([
1270
1435
  __decorateClass([
1271
1436
  action("update-batch-statuses")
1272
1437
  ], BankServiceBase.prototype, "updateBatchStatuses", 1);
1438
+ __decorateClass([
1439
+ action("handle-authorization-callback")
1440
+ ], BankServiceBase.prototype, "handleAuthorizationCallback", 1);
1273
1441
  __decorateClass([
1274
1442
  action("add-payments-to-batch")
1275
1443
  ], BankServiceBase.prototype, "addPaymentsToBatch", 1);