@develit-services/bank 0.8.9 → 0.8.12

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 (43) hide show
  1. package/README.md +150 -275
  2. package/dist/database/schema.cjs +1 -1
  3. package/dist/database/schema.d.cts +2 -2
  4. package/dist/database/schema.d.mts +2 -2
  5. package/dist/database/schema.d.ts +2 -2
  6. package/dist/database/schema.mjs +1 -1
  7. package/dist/export/worker.cjs +425 -557
  8. package/dist/export/worker.d.cts +848 -84
  9. package/dist/export/worker.d.mts +848 -84
  10. package/dist/export/worker.d.ts +848 -84
  11. package/dist/export/worker.mjs +425 -557
  12. package/dist/export/workflows.cjs +16 -16
  13. package/dist/export/workflows.mjs +16 -16
  14. package/dist/export/wrangler.cjs +0 -12
  15. package/dist/export/wrangler.d.cts +1 -8
  16. package/dist/export/wrangler.d.mts +1 -8
  17. package/dist/export/wrangler.d.ts +1 -8
  18. package/dist/export/wrangler.mjs +0 -12
  19. package/dist/shared/{bank.JVlyPAAb.cjs → bank.BBXoZ5QU.cjs} +26 -13
  20. package/dist/shared/{bank.CHQ3VSEh.d.ts → bank.BCop1cDT.d.mts} +4 -15
  21. package/dist/shared/{bank.Bg3Pdwm4.cjs → bank.BsIiXsFH.cjs} +5 -13
  22. package/dist/shared/{bank.BoZtXQpG.mjs → bank.CR0UlyRi.mjs} +1 -1
  23. package/dist/shared/{bank.CtnsGHM8.cjs → bank.CUvVxlHy.cjs} +126 -152
  24. package/dist/shared/{bank.DJnDSYqE.cjs → bank.CVi6R7fr.cjs} +1 -1
  25. package/dist/shared/{bank.C6jjS1Pl.mjs → bank.CXBeULUL.mjs} +25 -14
  26. package/dist/shared/{bank.DT6bg8k5.cjs → bank.Cev1E9sk.cjs} +2 -2
  27. package/dist/shared/{bank.pgyk4j94.d.cts → bank.Cj2Goq7s.d.cts} +104 -176
  28. package/dist/shared/{bank.pgyk4j94.d.mts → bank.Cj2Goq7s.d.mts} +104 -176
  29. package/dist/shared/{bank.pgyk4j94.d.ts → bank.Cj2Goq7s.d.ts} +104 -176
  30. package/dist/shared/{bank.vPWD7Ce4.d.cts → bank.CjTfEd1Q.d.cts} +4 -15
  31. package/dist/shared/{bank.BtszLapg.mjs → bank.D-O_gmmZ.mjs} +127 -152
  32. package/dist/shared/{bank.BP_3WMIF.d.cts → bank.DMjtitKo.d.cts} +0 -1
  33. package/dist/shared/{bank.BP_3WMIF.d.mts → bank.DMjtitKo.d.mts} +0 -1
  34. package/dist/shared/{bank.BP_3WMIF.d.ts → bank.DMjtitKo.d.ts} +0 -1
  35. package/dist/shared/{bank.CwuH4spB.d.mts → bank.OlDt7dpb.d.ts} +4 -15
  36. package/dist/shared/{bank.CbAwwIhZ.mjs → bank.vz1uqEYa.mjs} +5 -11
  37. package/dist/shared/{bank.B5bZRvgq.mjs → bank.xB9eTN77.mjs} +2 -2
  38. package/dist/types.cjs +6 -6
  39. package/dist/types.d.cts +26 -45
  40. package/dist/types.d.mts +26 -45
  41. package/dist/types.d.ts +26 -45
  42. package/dist/types.mjs +3 -3
  43. package/package.json +1 -1
@@ -3,8 +3,8 @@ import * as drizzle_orm from 'drizzle-orm';
3
3
  import { InferInsertModel, InferSelectModel } from 'drizzle-orm';
4
4
  import { BankAccountMetadata } from '@develit-io/backend-sdk';
5
5
  import { CURRENCY_CODES, BANK_CODES, CODES } from '@develit-io/general-codes';
6
- import * as drizzle_zod from 'drizzle-zod';
7
6
  import { z } from 'zod';
7
+ import * as drizzle_zod from 'drizzle-zod';
8
8
 
9
9
  interface BankAccountWithLastSync extends ConnectedAccount {
10
10
  lastSyncedAt: Date;
@@ -33,7 +33,9 @@ declare const CHARGE_BEARERS: readonly ["SHA", "OUR", "BEN"];
33
33
  type ChargeBearer = (typeof CHARGE_BEARERS)[number];
34
34
  declare const INSTRUCTION_PRIORITIES: readonly ["NORM", "HIGH", "INST"];
35
35
  type InstructionPriority = (typeof INSTRUCTION_PRIORITIES)[number];
36
- declare const PAYMENT_STATUSES: readonly ["CREATED", "PREPARED", "SIGNED", "PENDING", "COMPLETED", "FAILED"];
36
+ declare const PAYMENT_REQUEST_STATUSES: readonly ["OPENED", "AUTHORIZED", "COMPLETED", "BOOKED", "SETTLED", "REJECTED", "CLOSED"];
37
+ type PaymentRequestStatus = (typeof PAYMENT_REQUEST_STATUSES)[number];
38
+ declare const PAYMENT_STATUSES: readonly ["PENDING", "PROCESSING", "BOOKED", "CANCELLED", "REJECTED", "SCHEDULED", "HOLD", "INFO"];
37
39
  type PaymentStatus = (typeof PAYMENT_STATUSES)[number];
38
40
  declare const PAYMENT_DIRECTIONS: readonly ["INCOMING", "OUTGOING"];
39
41
  type PaymentDirection = (typeof PAYMENT_DIRECTIONS)[number];
@@ -42,11 +44,13 @@ type CurrencyCode = (typeof CURRENCY_CODES)[number];
42
44
  /**
43
45
  * Batch status constants
44
46
  */
45
- declare const BATCH_STATUSES: readonly ["OPEN", "PROCESSING", "READY_TO_SIGN", "SIGNED", "SIGNATURE_FAILED", "FAILED", "COMPLETED"];
47
+ declare const BATCH_STATUSES: readonly ["PROCESSING", "READY_TO_SIGN", "AUTHORIZED", "COMPLETED", "FAILED"];
46
48
  /**
47
49
  * Type definition for batch status
48
50
  */
49
51
  type BatchStatus = (typeof BATCH_STATUSES)[number];
52
+ declare const BATCH_MODES: readonly ["NATIVE", "SINGLE"];
53
+ type BatchMode = (typeof BATCH_MODES)[number];
50
54
  declare const ACCOUNT_STATUSES: readonly ["AUTHORIZED", "DISABLED", "EXPIRED"];
51
55
  /**
52
56
  * Type definition for account status
@@ -58,12 +62,36 @@ type BankCode = (typeof BANK_CODES)[number];
58
62
  declare const COUNTRY_CODES: ["AF" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AG" | "AR" | "AM" | "AW" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BO" | "BQ" | "BA" | "BW" | "BR" | "IO" | "VG" | "BG" | "BF" | "BI" | "KH" | "CM" | "CA" | "CV" | "CF" | "TD" | "CL" | "CN" | "CO" | "KM" | "CK" | "CR" | "HR" | "CW" | "CY" | "CZ" | "CD" | "DK" | "DJ" | "DM" | "DO" | "TL" | "EC" | "EG" | "SV" | "GQ" | "ER" | "EE" | "ET" | "FO" | "FJ" | "FI" | "FR" | "GF" | "PF" | "GA" | "GM" | "GE" | "DE" | "GH" | "GR" | "GD" | "GP" | "GU" | "GT" | "GN" | "GW" | "GY" | "HT" | "HN" | "HU" | "IS" | "IN" | "ID" | "IR" | "IQ" | "IE" | "IM" | "IL" | "IT" | "CI" | "JM" | "JP" | "JE" | "JO" | "KZ" | "KE" | "KI" | "XK" | "KW" | "KG" | "LA" | "LV" | "LB" | "LS" | "LR" | "LI" | "LT" | "LU" | "MK" | "MG" | "MW" | "MY" | "MV" | "ML" | "MT" | "MQ" | "MR" | "MU" | "MX" | "FM" | "MD" | "MC" | "MN" | "ME" | "MS" | "MA" | "MZ" | "NA" | "NP" | "NL" | "NZ" | "NI" | "NE" | "NG" | "NU" | "NF" | "KP" | "NO" | "OM" | "PK" | "PS" | "PA" | "PG" | "PY" | "PE" | "PH" | "PL" | "PT" | "PR" | "QA" | "CG" | "RE" | "RO" | "RU" | "RW" | "BL" | "KN" | "LC" | "MF" | "VC" | "WS" | "SM" | "SA" | "SN" | "RS" | "SC" | "SL" | "SG" | "SX" | "SK" | "SI" | "SO" | "ZA" | "KR" | "SS" | "ES" | "LK" | "SD" | "SR" | "SJ" | "SZ" | "SE" | "CH" | "TW" | "TJ" | "TZ" | "TH" | "TG" | "TO" | "TT" | "TN" | "TR" | "TM" | "UM" | "VI" | "UG" | "UA" | "AE" | "GB" | "US" | "UZ" | "VU" | "VE" | "VN" | "WF" | "EH" | "YE" | "ZM" | "ZW", ...("AF" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AG" | "AR" | "AM" | "AW" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BO" | "BQ" | "BA" | "BW" | "BR" | "IO" | "VG" | "BG" | "BF" | "BI" | "KH" | "CM" | "CA" | "CV" | "CF" | "TD" | "CL" | "CN" | "CO" | "KM" | "CK" | "CR" | "HR" | "CW" | "CY" | "CZ" | "CD" | "DK" | "DJ" | "DM" | "DO" | "TL" | "EC" | "EG" | "SV" | "GQ" | "ER" | "EE" | "ET" | "FO" | "FJ" | "FI" | "FR" | "GF" | "PF" | "GA" | "GM" | "GE" | "DE" | "GH" | "GR" | "GD" | "GP" | "GU" | "GT" | "GN" | "GW" | "GY" | "HT" | "HN" | "HU" | "IS" | "IN" | "ID" | "IR" | "IQ" | "IE" | "IM" | "IL" | "IT" | "CI" | "JM" | "JP" | "JE" | "JO" | "KZ" | "KE" | "KI" | "XK" | "KW" | "KG" | "LA" | "LV" | "LB" | "LS" | "LR" | "LI" | "LT" | "LU" | "MK" | "MG" | "MW" | "MY" | "MV" | "ML" | "MT" | "MQ" | "MR" | "MU" | "MX" | "FM" | "MD" | "MC" | "MN" | "ME" | "MS" | "MA" | "MZ" | "NA" | "NP" | "NL" | "NZ" | "NI" | "NE" | "NG" | "NU" | "NF" | "KP" | "NO" | "OM" | "PK" | "PS" | "PA" | "PG" | "PY" | "PE" | "PH" | "PL" | "PT" | "PR" | "QA" | "CG" | "RE" | "RO" | "RU" | "RW" | "BL" | "KN" | "LC" | "MF" | "VC" | "WS" | "SM" | "SA" | "SN" | "RS" | "SC" | "SL" | "SG" | "SX" | "SK" | "SI" | "SO" | "ZA" | "KR" | "SS" | "ES" | "LK" | "SD" | "SR" | "SJ" | "SZ" | "SE" | "CH" | "TW" | "TJ" | "TZ" | "TH" | "TG" | "TO" | "TT" | "TN" | "TR" | "TM" | "UM" | "VI" | "UG" | "UA" | "AE" | "GB" | "US" | "UZ" | "VU" | "VE" | "VN" | "WF" | "EH" | "YE" | "ZM" | "ZW")[]];
59
63
  type CountryCode = (typeof COUNTRY_CODES)[number];
60
64
 
65
+ declare const handleAuthorizationCallbackInputSchema: z.ZodObject<{
66
+ callbackUrl: z.ZodString;
67
+ }, z.core.$strip>;
68
+ type HandleAuthorizationCallbackInput = z.infer<typeof handleAuthorizationCallbackInputSchema>;
69
+ type AuthorizationCallbackResult = {
70
+ success: true;
71
+ type: 'paymentRequest';
72
+ paymentRequestId: string;
73
+ } | {
74
+ success: true;
75
+ type: 'batch';
76
+ batchId: string;
77
+ } | {
78
+ success: false;
79
+ error: string;
80
+ code: string | null;
81
+ };
82
+ type HandleAuthorizationCallbackOutput = {
83
+ paymentsUpdated: number;
84
+ batchId: string | null;
85
+ batchAuthorized: boolean;
86
+ error: string | null;
87
+ };
88
+
61
89
  type WithStatus<T extends {
62
90
  status: PaymentStatus;
63
91
  }, S extends PaymentStatus> = Omit<T, 'status'> & {
64
92
  status: S;
65
93
  };
66
- type PaymentFailedInsertType = WithStatus<PaymentInsertType, 'FAILED'>;
94
+ type PaymentFailedInsertType = WithStatus<PaymentInsertType, 'REJECTED'>;
67
95
  /**
68
96
  * @deprecated Use PreparedPayment from '~/types/payment-lifecycle' instead
69
97
  */
@@ -90,12 +118,6 @@ type ConnectedAccount = {
90
118
  declare abstract class IBankConnector {
91
119
  /** Unique identifier for this bank connector (e.g., 'ERSTE', 'FINBRICKS', 'MOCK') */
92
120
  abstract connectorKey: ConnectorKey;
93
- /**
94
- * Lifecycle mode for payment status resolution:
95
- * - 'batch': statuses are resolved via updateBatchStatuses (getBatchStatus polling)
96
- * - 'per-payment': statuses are resolved via updatePaymentStatuses (getPaymentStatus polling per payment)
97
- */
98
- abstract readonly lifecycleMode: 'batch' | 'per-payment';
99
121
  /** List of bank accounts connected through this connector instance */
100
122
  abstract connectedAccounts: ConnectedAccount[];
101
123
  /** Optional resolver for loading credentials on demand */
@@ -232,24 +254,20 @@ declare abstract class IBankConnector {
232
254
  };
233
255
  }): Promise<ParsedBankPayment[]>;
234
256
  /**
235
- * Retrieves current status of a payment from the bank.
236
- * @param paymentId - Bank's payment identifier
237
- * @returns Current payment status (PREPARED, COMPLETED, FAILED, etc.)
257
+ * Retrieves current status of a payment request from the bank.
258
+ * @param paymentId - Bank's payment identifier (bankRefId or PR id)
259
+ * @returns Current payment request status
238
260
  */
239
261
  abstract getPaymentStatus({ paymentId, }: {
240
262
  paymentId: string;
241
- }): Promise<PaymentStatus>;
263
+ }): Promise<PaymentRequestStatus>;
242
264
  /**
243
- * Retrieves current status of a batch from the bank.
244
- * @param batchId - Bank's batch identifier
245
- * @returns Batch status and raw API response for debugging
265
+ * Parses a bank authorization callback URL and extracts the result.
266
+ * Each connector knows its own callback URL format.
267
+ * @param callbackUrl - The full callback URL received from the bank
268
+ * @returns Parsed result — either success (with paymentRequestId or batchId) or error
246
269
  */
247
- abstract getBatchStatus({ batchId, }: {
248
- batchId: string;
249
- }): Promise<{
250
- status: BatchStatus;
251
- apiResponse: object;
252
- }>;
270
+ abstract parseAuthorizationCallback(callbackUrl: string): AuthorizationCallbackResult;
253
271
  }
254
272
 
255
273
  declare const accountCredentialsInsertSchema: drizzle_zod.BuildSchema<"insert", {
@@ -2636,20 +2654,20 @@ declare const batch: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
2636
2654
  tableName: "batch";
2637
2655
  dataType: "string";
2638
2656
  columnType: "SQLiteText";
2639
- data: "SIGNED" | "COMPLETED" | "FAILED" | "OPEN" | "PROCESSING" | "READY_TO_SIGN" | "SIGNATURE_FAILED";
2657
+ data: "AUTHORIZED" | "COMPLETED" | "PROCESSING" | "READY_TO_SIGN" | "FAILED";
2640
2658
  driverParam: string;
2641
2659
  notNull: false;
2642
2660
  hasDefault: false;
2643
2661
  isPrimaryKey: false;
2644
2662
  isAutoincrement: false;
2645
2663
  hasRuntimeDefault: false;
2646
- enumValues: ["OPEN", "PROCESSING", "READY_TO_SIGN", "SIGNED", "SIGNATURE_FAILED", "FAILED", "COMPLETED"];
2664
+ enumValues: ["PROCESSING", "READY_TO_SIGN", "AUTHORIZED", "COMPLETED", "FAILED"];
2647
2665
  baseColumn: never;
2648
2666
  identity: undefined;
2649
2667
  generated: undefined;
2650
2668
  }, {}, {
2651
2669
  length: number | undefined;
2652
- $type: "SIGNED" | "COMPLETED" | "FAILED" | "OPEN" | "PROCESSING" | "READY_TO_SIGN" | "SIGNATURE_FAILED";
2670
+ $type: "AUTHORIZED" | "COMPLETED" | "PROCESSING" | "READY_TO_SIGN" | "FAILED";
2653
2671
  }>;
2654
2672
  statusReason: drizzle_orm_sqlite_core.SQLiteColumn<{
2655
2673
  name: "status_reason";
@@ -2747,6 +2765,26 @@ declare const batch: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
2747
2765
  }, {}, {
2748
2766
  length: number | undefined;
2749
2767
  }>;
2768
+ batchMode: drizzle_orm_sqlite_core.SQLiteColumn<{
2769
+ name: "batch_mode";
2770
+ tableName: "batch";
2771
+ dataType: "string";
2772
+ columnType: "SQLiteText";
2773
+ data: "NATIVE" | "SINGLE";
2774
+ driverParam: string;
2775
+ notNull: false;
2776
+ hasDefault: false;
2777
+ isPrimaryKey: false;
2778
+ isAutoincrement: false;
2779
+ hasRuntimeDefault: false;
2780
+ enumValues: ["NATIVE", "SINGLE"];
2781
+ baseColumn: never;
2782
+ identity: undefined;
2783
+ generated: undefined;
2784
+ }, {}, {
2785
+ length: number | undefined;
2786
+ $type: "NATIVE" | "SINGLE";
2787
+ }>;
2750
2788
  id: drizzle_orm_sqlite_core.SQLiteColumn<{
2751
2789
  name: "id";
2752
2790
  tableName: "batch";
@@ -3060,20 +3098,20 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
3060
3098
  tableName: "payment";
3061
3099
  dataType: "string";
3062
3100
  columnType: "SQLiteText";
3063
- data: "CREATED" | "PREPARED" | "SIGNED" | "PENDING" | "COMPLETED" | "FAILED";
3101
+ data: "BOOKED" | "REJECTED" | "PENDING" | "PROCESSING" | "CANCELLED" | "SCHEDULED" | "HOLD" | "INFO";
3064
3102
  driverParam: string;
3065
3103
  notNull: true;
3066
3104
  hasDefault: false;
3067
3105
  isPrimaryKey: false;
3068
3106
  isAutoincrement: false;
3069
3107
  hasRuntimeDefault: false;
3070
- enumValues: [string, ...string[]];
3108
+ enumValues: ["PENDING", "PROCESSING", "BOOKED", "CANCELLED", "REJECTED", "SCHEDULED", "HOLD", "INFO"];
3071
3109
  baseColumn: never;
3072
3110
  identity: undefined;
3073
3111
  generated: undefined;
3074
3112
  }, {}, {
3075
3113
  length: number | undefined;
3076
- $type: "CREATED" | "PREPARED" | "SIGNED" | "PENDING" | "COMPLETED" | "FAILED";
3114
+ $type: "BOOKED" | "REJECTED" | "PENDING" | "PROCESSING" | "CANCELLED" | "SCHEDULED" | "HOLD" | "INFO";
3077
3115
  }>;
3078
3116
  statusReason: drizzle_orm_sqlite_core.SQLiteColumn<{
3079
3117
  name: "status_reason";
@@ -3654,20 +3692,20 @@ declare const paymentRequest: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
3654
3692
  tableName: "payment_request";
3655
3693
  dataType: "string";
3656
3694
  columnType: "SQLiteText";
3657
- data: "CREATED" | "PREPARED" | "SIGNED" | "PENDING" | "COMPLETED" | "FAILED";
3695
+ data: "AUTHORIZED" | "OPENED" | "COMPLETED" | "BOOKED" | "SETTLED" | "REJECTED" | "CLOSED";
3658
3696
  driverParam: string;
3659
3697
  notNull: true;
3660
3698
  hasDefault: false;
3661
3699
  isPrimaryKey: false;
3662
3700
  isAutoincrement: false;
3663
3701
  hasRuntimeDefault: false;
3664
- enumValues: ["CREATED", "PREPARED", "SIGNED", "PENDING", "COMPLETED", "FAILED"];
3702
+ enumValues: ["OPENED", "AUTHORIZED", "COMPLETED", "BOOKED", "SETTLED", "REJECTED", "CLOSED"];
3665
3703
  baseColumn: never;
3666
3704
  identity: undefined;
3667
3705
  generated: undefined;
3668
3706
  }, {}, {
3669
3707
  length: number | undefined;
3670
- $type: "CREATED" | "PREPARED" | "SIGNED" | "PENDING" | "COMPLETED" | "FAILED";
3708
+ $type: "AUTHORIZED" | "OPENED" | "COMPLETED" | "BOOKED" | "SETTLED" | "REJECTED" | "CLOSED";
3671
3709
  }>;
3672
3710
  statusReason: drizzle_orm_sqlite_core.SQLiteColumn<{
3673
3711
  name: "status_reason";
@@ -5099,102 +5137,60 @@ declare namespace schema {
5099
5137
  declare const tables: typeof schema;
5100
5138
 
5101
5139
  /**
5102
- * Payment lifecycle types
5103
- *
5104
- * This file defines explicit types for each stage of payment processing.
5105
- * Each type represents a specific phase in the payment journey from API input to bank completion.
5140
+ * Payment request lifecycle types
5106
5141
  *
5107
5142
  * Lifecycle flow:
5108
- * 1. IncomingPayment - Initial payment from API (status: CREATED, no account/connector/bankRef)
5109
- * 2. AccountAssignedPayment - Payment assigned to specific account (status: CREATED, has account/connector)
5110
- * 3. BatchedPayment - Payment stored in batch (same as AccountAssignedPayment but semantically in batch)
5111
- * 4. PreparedPayment - Payment prepared and sent to bank, waiting for authorization (status: PREPARED, may have bankRefId)
5112
- * 5. CompletedPayment - Payment fully processed (status: COMPLETED/PENDING/FAILED, has bankRefId)
5143
+ * 1. IncomingPayment - Initial payment from API (status: OPENED, no account/connector/bankRef)
5144
+ * 2. AccountAssignedPayment - Payment assigned to specific account (status: OPENED, has account/connector)
5145
+ * 3. BatchedPayment - Payment in batch (same as AccountAssignedPayment, semantically in batch)
5146
+ * 4. PreparedPayment - Sent to bank, waiting for authorization (status: OPENED, may have bankRefId)
5147
+ * 5. CompletedPayment - Fully processed (status: COMPLETED/BOOKED/SETTLED/REJECTED/CLOSED, has bankRefId)
5113
5148
  */
5114
5149
 
5115
5150
  /**
5116
5151
  * Stage 1: Incoming Payment
5117
- *
5118
- * Initial payment received from API via SendPaymentInput.
5119
- * Missing: accountId, connectorKey, bankRefId (not yet assigned to account or sent to bank)
5120
- * Status: Always 'CREATED'
5121
- *
5122
- * Used in: addPaymentsToBatch after mapping from SendPaymentInput
5123
5152
  */
5124
- type IncomingPayment = Omit<PaymentInsertType, 'accountId' | 'connectorKey' | 'bankRefId' | 'status'> & {
5125
- status: 'CREATED';
5153
+ type IncomingPayment = Omit<PaymentRequestInsertType, 'accountId' | 'connectorKey' | 'bankRefId' | 'status'> & {
5154
+ status: 'OPENED';
5126
5155
  sendAsSinglePayment?: boolean;
5127
5156
  };
5128
5157
  /**
5129
5158
  * Stage 2: Account Assigned Payment
5130
- *
5131
- * Payment that has been matched to a specific bank account and connector.
5132
- * Missing: bankRefId (not yet sent to bank)
5133
- * Status: Still 'CREATED'
5134
- *
5135
- * Used in: addPaymentsToBatch after filtering and assigning account
5136
5159
  */
5137
- type AccountAssignedPayment = Omit<PaymentInsertType, 'bankRefId' | 'status'> & {
5138
- status: 'CREATED';
5160
+ type AccountAssignedPayment = Omit<PaymentRequestInsertType, 'bankRefId' | 'status'> & {
5161
+ status: 'OPENED';
5139
5162
  accountId: string;
5140
5163
  connectorKey: ConnectorKey;
5141
5164
  sendAsSinglePayment?: boolean;
5142
5165
  };
5143
5166
  /**
5144
5167
  * Stage 3: Batched Payment
5145
- *
5146
- * Payment assigned to a batch, ready for processing.
5147
- * Semantically same as AccountAssignedPayment but linked to a batch via payment_request table.
5148
- * Missing: bankRefId (batch not yet processed)
5149
- * Status: Still 'CREATED'
5150
5168
  */
5151
- type BatchedPayment = Omit<PaymentInsertType, 'bankRefId' | 'status'> & {
5152
- status: 'CREATED';
5169
+ type BatchedPayment = Omit<PaymentRequestInsertType, 'bankRefId' | 'status'> & {
5170
+ status: 'OPENED';
5153
5171
  accountId: string;
5154
5172
  connectorKey: ConnectorKey;
5155
5173
  sendAsSinglePayment?: boolean;
5156
5174
  };
5157
5175
  /**
5158
5176
  * Stage 4: Prepared Payment
5159
- *
5160
- * Payment prepared and sent to bank, waiting for authorization.
5161
- * May have bankRefId if connector assigns it during batch initiation.
5162
- * Status: 'PREPARED'
5163
- *
5164
- * Used in: BankProcessBatch workflow after connector.initiateBatch()
5165
5177
  */
5166
- type PreparedPayment = Omit<PaymentInsertType, 'status' | 'bankRefId'> & {
5167
- status: 'PREPARED';
5178
+ type PreparedPayment = Omit<PaymentRequestInsertType, 'status' | 'bankRefId'> & {
5179
+ status: 'OPENED';
5168
5180
  bankRefId?: string;
5169
5181
  };
5170
5182
  /**
5171
5183
  * Stage 5: Completed Payment
5172
- *
5173
- * Payment fully processed by bank.
5174
- * Always has bankRefId from bank.
5175
- * Status: 'COMPLETED', 'PENDING', or 'FAILED'
5176
- *
5177
- * Used in: Final state after bank processing
5178
5184
  */
5179
- type CompletedPayment = PaymentInsertType & {
5180
- status: 'COMPLETED' | 'PENDING' | 'FAILED';
5185
+ type CompletedPayment = PaymentRequestInsertType & {
5186
+ status: 'COMPLETED' | 'BOOKED' | 'SETTLED' | 'REJECTED' | 'CLOSED';
5181
5187
  bankRefId: string;
5182
5188
  };
5183
5189
  /**
5184
5190
  * Union type of all payment lifecycle stages
5185
5191
  */
5186
5192
  type PaymentLifecycle = IncomingPayment | AccountAssignedPayment | BatchedPayment | PreparedPayment | CompletedPayment;
5187
- /**
5188
- * Type guard to check if payment has account assigned
5189
- */
5190
5193
  declare function hasPaymentAccountAssigned(payment: IncomingPayment | AccountAssignedPayment): payment is AccountAssignedPayment;
5191
- /**
5192
- * Type guard to check if payment is prepared
5193
- */
5194
- declare function isPaymentPrepared(payment: PaymentLifecycle): payment is PreparedPayment;
5195
- /**
5196
- * Type guard to check if payment is completed
5197
- */
5198
5194
  declare function isPaymentCompleted(payment: PaymentLifecycle | PaymentInsertType): payment is CompletedPayment;
5199
5195
 
5200
5196
  interface PaymentSelectType extends InferSelectModel<typeof tables.payment> {
@@ -5222,21 +5218,16 @@ type BatchPayment = Omit<PaymentInsertType, 'bankRefId'>;
5222
5218
  /**
5223
5219
  * Batch lifecycle types
5224
5220
  *
5225
- * This file defines explicit types for each stage of batch processing.
5226
- * Each type represents a specific phase in the batch journey from creation to completion.
5227
- *
5228
5221
  * Lifecycle flow:
5229
- * 1. CreatedBatch - Initial batch with payments (status: OPEN)
5230
- * 2. InitiatedBatch - Batch sent to bank API, waiting for authorization (response from connector)
5231
- * 3. ReadyToSignBatch - Batch stored in DB, waiting for signature (status: READY_TO_SIGN)
5232
- * 4. SignedBatch - Batch authorized/signed by user (status: SIGNED)
5233
- * 5. ProcessingBatch - Batch being processed by bank (status: PROCESSING)
5234
- * 6. CompletedBatch - Batch fully processed (status: COMPLETED/FAILED/SIGNATURE_FAILED)
5222
+ * 1. InitiatedBatch - Batch sent to bank API (response from connector)
5223
+ * 2. ReadyToSignBatch - Batch stored in DB, waiting for signature (status: READY_TO_SIGN)
5224
+ * 3. AuthorizedBatch - Batch authorized by user (status: AUTHORIZED)
5225
+ * 4. ProcessingBatch - Batch being processed by bank (status: PROCESSING)
5226
+ * 5. CompletedBatch - Batch fully processed (status: COMPLETED/FAILED)
5235
5227
  */
5236
5228
 
5237
5229
  /**
5238
5230
  * Batch metadata from bank connectors
5239
- * Used for tracking batch state in bank systems (e.g., Erste sign hash/ID)
5240
5231
  */
5241
5232
  type BatchMetadata = {
5242
5233
  signHash?: string;
@@ -5244,26 +5235,7 @@ type BatchMetadata = {
5244
5235
  sizeLimit?: number;
5245
5236
  };
5246
5237
  /**
5247
- * Stage 1: Created Batch
5248
- *
5249
- * Initial batch with payments ready to be sent to bank.
5250
- * Contains BatchedPayment[] - payments assigned to account but not yet sent to bank.
5251
- * Status: 'OPEN'
5252
- *
5253
- * Used in: After addPaymentsToBatch, stored in database
5254
- */
5255
- type CreatedBatch = Omit<BatchInsertType, 'status'> & {
5256
- status: 'OPEN';
5257
- payments: BatchedPayment[];
5258
- };
5259
- /**
5260
- * Stage 2: Initiated Batch
5261
- *
5262
- * Batch sent to bank API, waiting for user authorization.
5263
- * Contains PreparedPayment[] - payments sent to bank, may have bankRefId.
5264
- *
5265
- * Used in: Return type of connector.initiateBatch()
5266
- * Note: This is the response from bank connector, not stored in DB directly
5238
+ * Initiated Batch - response from connector.initiateBatch()
5267
5239
  */
5268
5240
  type InitiatedBatch = {
5269
5241
  id: string;
@@ -5272,99 +5244,55 @@ type InitiatedBatch = {
5272
5244
  metadata?: BatchMetadata | null;
5273
5245
  };
5274
5246
  /**
5275
- * Stage 3: Ready to Sign Batch
5276
- *
5277
- * Batch initiated with bank, waiting for user signature/authorization.
5278
- * Status: 'READY_TO_SIGN'
5279
- *
5280
- * Used in: After storing InitiatedBatch response to database
5247
+ * Ready to Sign Batch (status: READY_TO_SIGN)
5281
5248
  */
5282
5249
  type ReadyToSignBatch = Omit<BatchInsertType, 'status' | 'payments'> & {
5283
5250
  status: 'READY_TO_SIGN';
5284
5251
  payments: PreparedPayment[];
5285
5252
  };
5286
5253
  /**
5287
- * Stage 4: Signed Batch
5288
- *
5289
- * Batch authorized/signed by user, ready for bank processing.
5290
- * Status: 'SIGNED'
5291
- *
5292
- * Used in: After user completes authorization
5254
+ * Authorized Batch (status: AUTHORIZED)
5293
5255
  */
5294
- type SignedBatch = Omit<BatchInsertType, 'status' | 'payments'> & {
5295
- status: 'SIGNED';
5256
+ type AuthorizedBatch = Omit<BatchInsertType, 'status' | 'payments'> & {
5257
+ status: 'AUTHORIZED';
5296
5258
  payments: PreparedPayment[];
5297
5259
  };
5298
5260
  /**
5299
- * Stage 5: Processing Batch
5300
- *
5301
- * Batch being processed by bank.
5302
- * Status: 'PROCESSING'
5303
- *
5304
- * Used in: During bank processing workflow
5261
+ * Processing Batch (status: PROCESSING)
5305
5262
  */
5306
5263
  type ProcessingBatch = Omit<BatchInsertType, 'status' | 'payments'> & {
5307
5264
  status: 'PROCESSING';
5308
5265
  payments: PreparedPayment[];
5309
5266
  };
5310
5267
  /**
5311
- * Stage 6: Completed Batch
5312
- *
5313
- * Batch fully processed by bank.
5314
- * Status: 'COMPLETED', 'FAILED', 'SIGNATURE_FAILED'
5315
- *
5316
- * Used in: Final state after bank processing
5268
+ * Completed Batch (status: COMPLETED/FAILED)
5317
5269
  */
5318
5270
  type CompletedBatch = Omit<BatchInsertType, 'status' | 'payments'> & {
5319
- status: 'COMPLETED' | 'FAILED' | 'SIGNATURE_FAILED';
5271
+ status: 'COMPLETED' | 'FAILED';
5320
5272
  payments: PreparedPayment[];
5321
5273
  };
5322
5274
  /**
5323
5275
  * Union type of all batch lifecycle stages
5324
5276
  */
5325
- type BatchLifecycle = CreatedBatch | InitiatedBatch | ReadyToSignBatch | SignedBatch | ProcessingBatch | CompletedBatch;
5326
- /**
5327
- * Type guard to check if batch is initiated
5328
- */
5277
+ type BatchLifecycle = InitiatedBatch | ReadyToSignBatch | AuthorizedBatch | ProcessingBatch | CompletedBatch;
5329
5278
  declare function isBatchInitiated(batch: {
5330
5279
  authorizationUrls?: string[] | null;
5331
5280
  }): batch is InitiatedBatch;
5332
- /**
5333
- * Type guard to check if batch is ready to sign
5334
- */
5335
5281
  declare function isBatchReadyToSign(batch: {
5336
5282
  status?: string | null;
5337
5283
  }): batch is ReadyToSignBatch;
5338
- /**
5339
- * Type guard to check if batch is signed
5340
- */
5341
- declare function isBatchSigned(batch: {
5284
+ declare function isBatchAuthorized(batch: {
5342
5285
  status?: string | null;
5343
- }): batch is SignedBatch;
5344
- /**
5345
- * Type guard to check if batch is processing
5346
- */
5286
+ }): batch is AuthorizedBatch;
5347
5287
  declare function isBatchProcessing(batch: {
5348
5288
  status?: string | null;
5349
5289
  }): batch is ProcessingBatch;
5350
- /**
5351
- * Type guard to check if batch is completed
5352
- */
5353
5290
  declare function isBatchCompleted(batch: {
5354
5291
  status?: string | null;
5355
5292
  }): batch is CompletedBatch;
5356
- /**
5357
- * Type guard to check if batch is open
5358
- */
5359
- declare function isBatchOpen(batch: {
5360
- status?: string | null;
5361
- }): batch is CreatedBatch;
5362
- /**
5363
- * Type guard to check if batch has failed
5364
- */
5365
5293
  declare function isBatchFailed(batch: {
5366
5294
  status?: string | null;
5367
5295
  }): batch is CompletedBatch;
5368
5296
 
5369
- export { PAYMENT_STATUSES as $, BATCH_STATUSES as G, IBankConnector as I, CHARGE_BEARERS as O, CONNECTOR_KEYS as Q, COUNTRY_CODES as R, CREDENTIALS_TYPES as S, INSTRUCTION_PRIORITIES as Y, PAYMENT_DIRECTIONS as _, PAYMENT_TYPES as a0, TOKEN_TYPES as aa, accountCredentialsInsertSchema as ac, accountCredentialsSelectSchema as ad, accountCredentialsUpdateSchema as ae, accountInsertSchema as af, accountSelectSchema as ag, accountUpdateSchema as ah, hasPaymentAccountAssigned as ai, isBatchCompleted as aj, isBatchFailed as ak, isBatchInitiated as al, isBatchOpen as am, isBatchProcessing as an, isBatchReadyToSign as ao, isBatchSigned as ap, isPaymentCompleted as aq, isPaymentPrepared as ar, account as as, accountCredentials as at, batch as au, ott as av, payment as aw, paymentRelations as ax, paymentRequest as ay, paymentRequestRelations as az, tables as t, ACCOUNT_STATUSES as w };
5370
- export type { AccountSelectType as A, BatchSelectType as B, ConfigEnvironmentBank as C, AccountPatchType as D, AccountStatus as E, AccountUpdateType as F, BankAccountWithLastSync as H, BankCode as J, BatchInsertType as K, LastSyncMetadata as L, BatchLifecycle as M, BatchPayment as N, PaymentSelectType as P, ChargeBearer as T, CompletedBatch as U, CountryCode as V, CreatedBatch as W, CredentialsType as X, InstructionPriority as Z, PaymentRequestSelectType as a, PaymentDirection as a1, PaymentFailedInsertType as a2, PaymentInsertType as a3, PaymentLifecycle as a4, PaymentPreparedInsertType as a5, ProcessingBatch as a6, ReadyToSignBatch as a7, ResolvedCredentials as a8, SignedBatch as a9, TokenType as ab, ConnectorKey as b, PaymentType as c, CurrencyCode as d, ConnectedAccount as e, CredentialsResolver as f, AccountCredentialsInsertType as g, AccountInsertType as h, BatchedPayment as i, InitiatedBatch as j, IncomingPayment as k, InitiatedPayment as l, ParsedBankPayment as m, PaymentStatus as n, BatchStatus as o, BatchMetadata as p, Currency as q, AccountAssignedPayment as r, PreparedPayment as s, CompletedPayment as u, PaymentRequestInsertType as v, AccountCredentialsPatchType as x, AccountCredentialsSelectType as y, AccountCredentialsUpdateType as z };
5297
+ export { IBankConnector as I, BATCH_MODES as K, BATCH_STATUSES as M, CHARGE_BEARERS as V, CONNECTOR_KEYS as W, COUNTRY_CODES as X, CREDENTIALS_TYPES as Y, INSTRUCTION_PRIORITIES as a1, PAYMENT_DIRECTIONS as a3, PAYMENT_REQUEST_STATUSES as a4, PAYMENT_STATUSES as a5, PAYMENT_TYPES as a6, payment as aA, paymentRelations as aB, paymentRequest as aC, paymentRequestRelations as aD, TOKEN_TYPES as ag, accountCredentialsInsertSchema as ai, accountCredentialsSelectSchema as aj, accountCredentialsUpdateSchema as ak, accountInsertSchema as al, accountSelectSchema as am, accountUpdateSchema as an, hasPaymentAccountAssigned as ao, isBatchAuthorized as ap, isBatchCompleted as aq, isBatchFailed as ar, isBatchInitiated as as, isBatchProcessing as at, isBatchReadyToSign as au, isPaymentCompleted as av, account as aw, accountCredentials as ax, batch as ay, ott as az, tables as t, ACCOUNT_STATUSES as x };
5298
+ export type { CountryCode as $, AccountSelectType as A, BatchSelectType as B, ConfigEnvironmentBank as C, AccountCredentialsUpdateType as D, AccountPatchType as E, AccountStatus as F, AccountUpdateType as G, HandleAuthorizationCallbackInput as H, AuthorizedBatch as J, LastSyncMetadata as L, BankAccountWithLastSync as N, BankCode as O, PaymentSelectType as P, BatchInsertType as Q, BatchLifecycle as R, BatchMode as S, BatchPayment as T, BatchStatus as U, ChargeBearer as Z, CompletedBatch as _, PaymentRequestSelectType as a, CredentialsType as a0, InstructionPriority as a2, PaymentDirection as a7, PaymentFailedInsertType as a8, PaymentInsertType as a9, PaymentLifecycle as aa, PaymentPreparedInsertType as ab, PaymentStatus as ac, ProcessingBatch as ad, ReadyToSignBatch as ae, ResolvedCredentials as af, TokenType as ah, ConnectorKey as b, PaymentType as c, CurrencyCode as d, HandleAuthorizationCallbackOutput as e, ConnectedAccount as f, CredentialsResolver as g, AccountCredentialsInsertType as h, AccountInsertType as i, BatchedPayment as j, InitiatedBatch as k, IncomingPayment as l, InitiatedPayment as m, ParsedBankPayment as n, PaymentRequestStatus as o, AuthorizationCallbackResult as p, BatchMetadata as q, Currency as r, AccountAssignedPayment as s, PreparedPayment as u, CompletedPayment as v, PaymentRequestInsertType as w, AccountCredentialsPatchType as y, AccountCredentialsSelectType as z };