@develit-services/bank 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/base.d.cts CHANGED
@@ -2817,9 +2817,9 @@ declare const getPaymentsInputSchema: z.ZodObject<{
2817
2817
  limit: z.ZodNumber;
2818
2818
  sort: z.ZodObject<{
2819
2819
  column: z.ZodEnum<{
2820
+ amount: "amount";
2820
2821
  createdAt: "createdAt";
2821
2822
  updatedAt: "updatedAt";
2822
- amount: "amount";
2823
2823
  }>;
2824
2824
  direction: z.ZodEnum<{
2825
2825
  asc: "asc";
@@ -2994,6 +2994,30 @@ type GetPaymentsOutput = {
2994
2994
  totalCount: number;
2995
2995
  };
2996
2996
 
2997
+ declare const getPaymentsByRequestIdsInputSchema: z.ZodObject<{
2998
+ paymentRequestIds: z.ZodArray<z.ZodString>;
2999
+ }, z.core.$strip>;
3000
+ interface GetPaymentsByRequestIdsInput extends z.infer<typeof getPaymentsByRequestIdsInputSchema> {
3001
+ }
3002
+ interface GetPaymentsByRequestIdsOutput {
3003
+ payments: Array<{
3004
+ paymentRequestId: string;
3005
+ payment: {
3006
+ id: string;
3007
+ correlationId: string;
3008
+ status: string;
3009
+ amount: number;
3010
+ currency: string;
3011
+ creditor: {
3012
+ iban?: string;
3013
+ holderName?: string;
3014
+ };
3015
+ createdAt: number;
3016
+ updatedAt?: number;
3017
+ } | null;
3018
+ }>;
3019
+ }
3020
+
2997
3021
  declare const syncAccountInputSchema: z.ZodObject<{
2998
3022
  accountId: z.ZodUUID;
2999
3023
  }, z.core.$strip>;
@@ -3585,9 +3609,9 @@ declare const getPaymentRequestsInputSchema: z.ZodObject<{
3585
3609
  limit: z.ZodNumber;
3586
3610
  sort: z.ZodObject<{
3587
3611
  column: z.ZodEnum<{
3612
+ amount: "amount";
3588
3613
  createdAt: "createdAt";
3589
3614
  updatedAt: "updatedAt";
3590
- amount: "amount";
3591
3615
  }>;
3592
3616
  direction: z.ZodEnum<{
3593
3617
  asc: "asc";
@@ -3858,6 +3882,13 @@ declare class BankServiceBase extends BankServiceBase_base {
3858
3882
  iban?: string | null;
3859
3883
  }): void;
3860
3884
  getPayments(input: GetPaymentsInput): Promise<IRPCResponse<GetPaymentsOutput>>;
3885
+ /**
3886
+ * Get payments by payment request IDs (batch query for sweep history)
3887
+ *
3888
+ * @connector DBU - Fully supported
3889
+ * @connector FIO - Not yet implemented (will return empty for FIO payments)
3890
+ */
3891
+ getPaymentsByRequestIds(input: GetPaymentsByRequestIdsInput): Promise<IRPCResponse<GetPaymentsByRequestIdsOutput>>;
3861
3892
  syncAccount(input: SyncAccountInput): Promise<IRPCResponse<SyncAccountOutput>>;
3862
3893
  syncAccountStatus(input: SyncAccountStatusInput): Promise<IRPCResponse<SyncAccountStatusOutput>>;
3863
3894
  syncAccountRestart(input: SyncAccountRestartInput): Promise<IRPCResponse<SyncAccountRestartOutput>>;
package/dist/base.d.mts CHANGED
@@ -2817,9 +2817,9 @@ declare const getPaymentsInputSchema: z.ZodObject<{
2817
2817
  limit: z.ZodNumber;
2818
2818
  sort: z.ZodObject<{
2819
2819
  column: z.ZodEnum<{
2820
+ amount: "amount";
2820
2821
  createdAt: "createdAt";
2821
2822
  updatedAt: "updatedAt";
2822
- amount: "amount";
2823
2823
  }>;
2824
2824
  direction: z.ZodEnum<{
2825
2825
  asc: "asc";
@@ -2994,6 +2994,30 @@ type GetPaymentsOutput = {
2994
2994
  totalCount: number;
2995
2995
  };
2996
2996
 
2997
+ declare const getPaymentsByRequestIdsInputSchema: z.ZodObject<{
2998
+ paymentRequestIds: z.ZodArray<z.ZodString>;
2999
+ }, z.core.$strip>;
3000
+ interface GetPaymentsByRequestIdsInput extends z.infer<typeof getPaymentsByRequestIdsInputSchema> {
3001
+ }
3002
+ interface GetPaymentsByRequestIdsOutput {
3003
+ payments: Array<{
3004
+ paymentRequestId: string;
3005
+ payment: {
3006
+ id: string;
3007
+ correlationId: string;
3008
+ status: string;
3009
+ amount: number;
3010
+ currency: string;
3011
+ creditor: {
3012
+ iban?: string;
3013
+ holderName?: string;
3014
+ };
3015
+ createdAt: number;
3016
+ updatedAt?: number;
3017
+ } | null;
3018
+ }>;
3019
+ }
3020
+
2997
3021
  declare const syncAccountInputSchema: z.ZodObject<{
2998
3022
  accountId: z.ZodUUID;
2999
3023
  }, z.core.$strip>;
@@ -3585,9 +3609,9 @@ declare const getPaymentRequestsInputSchema: z.ZodObject<{
3585
3609
  limit: z.ZodNumber;
3586
3610
  sort: z.ZodObject<{
3587
3611
  column: z.ZodEnum<{
3612
+ amount: "amount";
3588
3613
  createdAt: "createdAt";
3589
3614
  updatedAt: "updatedAt";
3590
- amount: "amount";
3591
3615
  }>;
3592
3616
  direction: z.ZodEnum<{
3593
3617
  asc: "asc";
@@ -3858,6 +3882,13 @@ declare class BankServiceBase extends BankServiceBase_base {
3858
3882
  iban?: string | null;
3859
3883
  }): void;
3860
3884
  getPayments(input: GetPaymentsInput): Promise<IRPCResponse<GetPaymentsOutput>>;
3885
+ /**
3886
+ * Get payments by payment request IDs (batch query for sweep history)
3887
+ *
3888
+ * @connector DBU - Fully supported
3889
+ * @connector FIO - Not yet implemented (will return empty for FIO payments)
3890
+ */
3891
+ getPaymentsByRequestIds(input: GetPaymentsByRequestIdsInput): Promise<IRPCResponse<GetPaymentsByRequestIdsOutput>>;
3861
3892
  syncAccount(input: SyncAccountInput): Promise<IRPCResponse<SyncAccountOutput>>;
3862
3893
  syncAccountStatus(input: SyncAccountStatusInput): Promise<IRPCResponse<SyncAccountStatusOutput>>;
3863
3894
  syncAccountRestart(input: SyncAccountRestartInput): Promise<IRPCResponse<SyncAccountRestartOutput>>;
package/dist/base.d.ts CHANGED
@@ -2817,9 +2817,9 @@ declare const getPaymentsInputSchema: z.ZodObject<{
2817
2817
  limit: z.ZodNumber;
2818
2818
  sort: z.ZodObject<{
2819
2819
  column: z.ZodEnum<{
2820
+ amount: "amount";
2820
2821
  createdAt: "createdAt";
2821
2822
  updatedAt: "updatedAt";
2822
- amount: "amount";
2823
2823
  }>;
2824
2824
  direction: z.ZodEnum<{
2825
2825
  asc: "asc";
@@ -2994,6 +2994,30 @@ type GetPaymentsOutput = {
2994
2994
  totalCount: number;
2995
2995
  };
2996
2996
 
2997
+ declare const getPaymentsByRequestIdsInputSchema: z.ZodObject<{
2998
+ paymentRequestIds: z.ZodArray<z.ZodString>;
2999
+ }, z.core.$strip>;
3000
+ interface GetPaymentsByRequestIdsInput extends z.infer<typeof getPaymentsByRequestIdsInputSchema> {
3001
+ }
3002
+ interface GetPaymentsByRequestIdsOutput {
3003
+ payments: Array<{
3004
+ paymentRequestId: string;
3005
+ payment: {
3006
+ id: string;
3007
+ correlationId: string;
3008
+ status: string;
3009
+ amount: number;
3010
+ currency: string;
3011
+ creditor: {
3012
+ iban?: string;
3013
+ holderName?: string;
3014
+ };
3015
+ createdAt: number;
3016
+ updatedAt?: number;
3017
+ } | null;
3018
+ }>;
3019
+ }
3020
+
2997
3021
  declare const syncAccountInputSchema: z.ZodObject<{
2998
3022
  accountId: z.ZodUUID;
2999
3023
  }, z.core.$strip>;
@@ -3585,9 +3609,9 @@ declare const getPaymentRequestsInputSchema: z.ZodObject<{
3585
3609
  limit: z.ZodNumber;
3586
3610
  sort: z.ZodObject<{
3587
3611
  column: z.ZodEnum<{
3612
+ amount: "amount";
3588
3613
  createdAt: "createdAt";
3589
3614
  updatedAt: "updatedAt";
3590
- amount: "amount";
3591
3615
  }>;
3592
3616
  direction: z.ZodEnum<{
3593
3617
  asc: "asc";
@@ -3858,6 +3882,13 @@ declare class BankServiceBase extends BankServiceBase_base {
3858
3882
  iban?: string | null;
3859
3883
  }): void;
3860
3884
  getPayments(input: GetPaymentsInput): Promise<IRPCResponse<GetPaymentsOutput>>;
3885
+ /**
3886
+ * Get payments by payment request IDs (batch query for sweep history)
3887
+ *
3888
+ * @connector DBU - Fully supported
3889
+ * @connector FIO - Not yet implemented (will return empty for FIO payments)
3890
+ */
3891
+ getPaymentsByRequestIds(input: GetPaymentsByRequestIdsInput): Promise<IRPCResponse<GetPaymentsByRequestIdsOutput>>;
3861
3892
  syncAccount(input: SyncAccountInput): Promise<IRPCResponse<SyncAccountOutput>>;
3862
3893
  syncAccountStatus(input: SyncAccountStatusInput): Promise<IRPCResponse<SyncAccountStatusOutput>>;
3863
3894
  syncAccountRestart(input: SyncAccountRestartInput): Promise<IRPCResponse<SyncAccountRestartOutput>>;
package/dist/base.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { bankAccountMetadataSchema, structuredAddressSchema, uuidv4, first, buildMultiFilterConditions as buildMultiFilterConditions$1, workflowInstanceStatusSchema, develitWorker, createInternalError, action, service } from '@develit-io/backend-sdk';
2
- import { G as tables, g as accountInsertSchema, H as relations, J as initiateConnector, o as isProcessedStatus, p as isTerminalStatus, L as getNonTerminalPaymentRequestsQuery, x as toIncomingPayment, j as assignAccount, u as toBatchedPayment, y as toPaymentRequestInsert, a as FinbricksClient, F as FINBRICKS_ENDPOINTS } from './shared/bank.CZ8MQDPa.mjs';
1
+ import { uuidv4, first, buildMultiFilterConditions as buildMultiFilterConditions$1, bankAccountMetadataSchema, structuredAddressSchema, workflowInstanceStatusSchema, develitWorker, createInternalError, action, service } from '@develit-io/backend-sdk';
2
+ import { G as tables, g as accountInsertSchema, H as relations, J as initiateConnector, o as isProcessedStatus, p as isTerminalStatus, L as getNonTerminalPaymentRequestsQuery, x as toIncomingPayment, N as calculateCzechIban, j as assignAccount, u as toBatchedPayment, y as toPaymentRequestInsert, a as FinbricksClient, F as FINBRICKS_ENDPOINTS } from './shared/bank.D5skCz3H.mjs';
3
3
  import { eq, sql, and, like, asc, desc, inArray, gte, lte, isNull, count } from 'drizzle-orm';
4
4
  import { WorkerEntrypoint } from 'cloudflare:workers';
5
5
  import { drizzle } from 'drizzle-orm/d1';
@@ -9,7 +9,7 @@ import { I as INSTRUCTION_PRIORITIES, C as CHARGE_BEARERS, g as PAYMENT_TYPES, b
9
9
  import { CURRENCY_CODES } from '@develit-io/general-codes';
10
10
  import 'date-fns';
11
11
  import 'node:crypto';
12
- import { h as encrypt, d as createCredentialsResolver, e as updatePaymentRequestStatusCommand, a as getPaymentRequestsByBatchIdQuery, g as getBatchByIdQuery, u as upsertBatchCommand, i as importAesKey, f as createPaymentCommand, b as getAccountByIdQuery } from './shared/bank.BdTj54NO.mjs';
12
+ import { h as encrypt, d as createCredentialsResolver, e as updatePaymentRequestStatusCommand, a as getPaymentRequestsByBatchIdQuery, g as getBatchByIdQuery, u as upsertBatchCommand, i as importAesKey, f as createPaymentCommand, b as getAccountByIdQuery } from './shared/bank.C_JpNoSI.mjs';
13
13
  import 'drizzle-orm/zod';
14
14
  import 'drizzle-orm/sqlite-core';
15
15
 
@@ -71,77 +71,6 @@ async function heartbeatSyncWorkflows({
71
71
  );
72
72
  }
73
73
 
74
- const sendPaymentInputSchema = z.object({
75
- correlationId: z.string().min(1),
76
- refId: z.string().optional(),
77
- amount: z.number().positive(),
78
- paymentType: z.enum(PAYMENT_TYPES),
79
- chargeBearer: z.enum(CHARGE_BEARERS).optional(),
80
- instructionPriority: z.enum(INSTRUCTION_PRIORITIES).optional(),
81
- currency: z.enum(CURRENCY_CODES),
82
- vs: z.string().optional(),
83
- ss: z.string().optional(),
84
- ks: z.string().optional(),
85
- message: z.string().optional(),
86
- creditor: bankAccountMetadataSchema,
87
- debtor: bankAccountMetadataSchema,
88
- sendAsSinglePayment: z.boolean().optional()
89
- }).superRefine((data, ctx) => {
90
- if (data.paymentType === "UNKNOWN") {
91
- ctx.addIssue({
92
- code: "custom",
93
- message: "paymentType=UNKNOWN is not supported. Use DOMESTIC, SEPA, or SWIFT.",
94
- path: ["paymentType"]
95
- });
96
- return;
97
- }
98
- if (!data.debtor.iban) {
99
- ctx.addIssue({
100
- code: "custom",
101
- message: "debtor.iban is required",
102
- path: ["debtor", "iban"]
103
- });
104
- }
105
- if (data.paymentType === "DOMESTIC" || data.paymentType === "SEPA") {
106
- if (!data.creditor.iban) {
107
- ctx.addIssue({
108
- code: "custom",
109
- message: `creditor.iban is required for ${data.paymentType} payments`,
110
- path: ["creditor", "iban"]
111
- });
112
- }
113
- return;
114
- }
115
- if (data.paymentType === "SWIFT") {
116
- const hasIban = !!data.creditor.iban;
117
- const hasBban = !!data.creditor.number && !!(data.creditor.swiftBic ?? data.creditor.bicCor);
118
- if (!hasIban && !hasBban) {
119
- ctx.addIssue({
120
- code: "custom",
121
- message: "SWIFT creditor requires either iban OR (number + swiftBic/bicCor)",
122
- path: ["creditor"]
123
- });
124
- }
125
- }
126
- });
127
-
128
- const sendBatchInputSchema = z.object({
129
- payments: z.array(sendPaymentInputSchema).min(1)
130
- });
131
-
132
- const getAuthUriInputSchema = z.object({
133
- connectorKey: z.enum(CONNECTOR_KEYS)
134
- });
135
-
136
- const authorizeAccountInputSchema = z.object({
137
- ott: z.string(),
138
- urlParams: z.string(),
139
- syncIntervalS: z.number().int().positive().optional(),
140
- startSync: z.boolean().optional(),
141
- lastSyncAt: z.date().optional(),
142
- address: structuredAddressSchema.optional()
143
- });
144
-
145
74
  const upsertAccountCommand = (db, { account }) => {
146
75
  const id = account.id || uuidv4();
147
76
  const { id: _id, ...accountWithoutId } = account;
@@ -420,6 +349,42 @@ const getOttQuery = async (db, { ott }) => {
420
349
  return await db.select().from(tables.ott).where(eq(tables.ott.oneTimeToken, ott)).get();
421
350
  };
422
351
 
352
+ const CHUNK_SIZE = 90;
353
+ const getPaymentsByPaymentRequestIdsQuery = async (db, { paymentRequestIds }) => {
354
+ if (paymentRequestIds.length === 0) return [];
355
+ const paymentRequests = [];
356
+ for (let i = 0; i < paymentRequestIds.length; i += CHUNK_SIZE) {
357
+ const chunkIds = paymentRequestIds.slice(i, i + CHUNK_SIZE);
358
+ const rows = await db.select({
359
+ id: tables.paymentRequest.id,
360
+ correlationId: tables.paymentRequest.correlationId,
361
+ status: tables.paymentRequest.status,
362
+ amount: tables.paymentRequest.amount,
363
+ currency: tables.paymentRequest.currency,
364
+ creditor: tables.paymentRequest.creditor,
365
+ createdAt: tables.paymentRequest.createdAt,
366
+ updatedAt: tables.paymentRequest.updatedAt
367
+ }).from(tables.paymentRequest).where(inArray(tables.paymentRequest.id, chunkIds));
368
+ paymentRequests.push(...rows);
369
+ }
370
+ return paymentRequests.map((pr) => {
371
+ const creditor = typeof pr.creditor === "string" ? JSON.parse(pr.creditor) : pr.creditor || {};
372
+ return {
373
+ paymentRequestId: pr.id,
374
+ payment: {
375
+ id: pr.id,
376
+ correlationId: pr.correlationId,
377
+ status: pr.status,
378
+ amount: pr.amount,
379
+ currency: pr.currency,
380
+ creditor,
381
+ createdAt: pr.createdAt,
382
+ updatedAt: pr.updatedAt
383
+ }
384
+ };
385
+ });
386
+ };
387
+
423
388
  const getPaymentRequestByIdQuery = async (db, { paymentRequestId }) => {
424
389
  const result = await db.select().from(tables.paymentRequest).where(
425
390
  and(
@@ -484,6 +449,79 @@ function buildPaymentRequestEvent(pr) {
484
449
  };
485
450
  }
486
451
 
452
+ const sendPaymentInputSchema = z.object({
453
+ correlationId: z.string().min(1),
454
+ refId: z.string().optional(),
455
+ amount: z.number().positive(),
456
+ paymentType: z.enum(PAYMENT_TYPES),
457
+ chargeBearer: z.enum(CHARGE_BEARERS).optional(),
458
+ instructionPriority: z.enum(INSTRUCTION_PRIORITIES).optional(),
459
+ currency: z.enum(CURRENCY_CODES),
460
+ vs: z.string().optional(),
461
+ ss: z.string().optional(),
462
+ ks: z.string().optional(),
463
+ message: z.string().optional(),
464
+ creditor: bankAccountMetadataSchema,
465
+ debtor: bankAccountMetadataSchema,
466
+ sendAsSinglePayment: z.boolean().optional()
467
+ }).superRefine((data, ctx) => {
468
+ if (data.paymentType === "UNKNOWN") {
469
+ ctx.addIssue({
470
+ code: "custom",
471
+ message: "paymentType=UNKNOWN is not supported. Use DOMESTIC, SEPA, or SWIFT.",
472
+ path: ["paymentType"]
473
+ });
474
+ return;
475
+ }
476
+ if (!data.debtor.iban) {
477
+ ctx.addIssue({
478
+ code: "custom",
479
+ message: "debtor.iban is required",
480
+ path: ["debtor", "iban"]
481
+ });
482
+ }
483
+ if (data.paymentType === "DOMESTIC" || data.paymentType === "SEPA") {
484
+ const hasIban = !!data.creditor.iban;
485
+ const hasAccountNumber = !!data.creditor.number && !!data.creditor.bankCode;
486
+ if (!hasIban && !hasAccountNumber) {
487
+ ctx.addIssue({
488
+ code: "custom",
489
+ message: `creditor must have either iban OR (number + bankCode) for ${data.paymentType} payments`,
490
+ path: ["creditor"]
491
+ });
492
+ }
493
+ return;
494
+ }
495
+ if (data.paymentType === "SWIFT") {
496
+ const hasIban = !!data.creditor.iban;
497
+ const hasBban = !!data.creditor.number && !!(data.creditor.swiftBic ?? data.creditor.bicCor);
498
+ if (!hasIban && !hasBban) {
499
+ ctx.addIssue({
500
+ code: "custom",
501
+ message: "SWIFT creditor requires either iban OR (number + swiftBic/bicCor)",
502
+ path: ["creditor"]
503
+ });
504
+ }
505
+ }
506
+ });
507
+
508
+ const sendBatchInputSchema = z.object({
509
+ payments: z.array(sendPaymentInputSchema).min(1)
510
+ });
511
+
512
+ const getAuthUriInputSchema = z.object({
513
+ connectorKey: z.enum(CONNECTOR_KEYS)
514
+ });
515
+
516
+ const authorizeAccountInputSchema = z.object({
517
+ ott: z.string(),
518
+ urlParams: z.string(),
519
+ syncIntervalS: z.number().int().positive().optional(),
520
+ startSync: z.boolean().optional(),
521
+ lastSyncAt: z.date().optional(),
522
+ address: structuredAddressSchema.optional()
523
+ });
524
+
487
525
  const simulateDepositInputSchema = z.object({
488
526
  amount: z.number(),
489
527
  currency: z.enum(CURRENCY_CODES),
@@ -583,6 +621,10 @@ const getPaymentsInputSchema = z.object({
583
621
  [ALLOWED_PAYMENT_FILTERS.BANK_REF_ID]: z.string().optional()
584
622
  });
585
623
 
624
+ const getPaymentsByRequestIdsInputSchema = z.object({
625
+ paymentRequestIds: z.array(z.string().uuid()).min(1, "At least one payment request ID is required").max(100, "Maximum 100 payment request IDs per request")
626
+ });
627
+
586
628
  const syncAccountInputSchema = z.object({
587
629
  accountId: z.uuid()
588
630
  });
@@ -764,6 +806,18 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
764
806
  }
765
807
  );
766
808
  }
809
+ async getPaymentsByRequestIds(input) {
810
+ return this.handleAction(
811
+ { data: input, schema: getPaymentsByRequestIdsInputSchema },
812
+ { successMessage: "Payments retrieved successfully" },
813
+ async (validated) => {
814
+ const payments = await getPaymentsByPaymentRequestIdsQuery(this.db, {
815
+ paymentRequestIds: validated.paymentRequestIds
816
+ });
817
+ return { payments };
818
+ }
819
+ );
820
+ }
767
821
  async syncAccount(input) {
768
822
  return this.handleAction(
769
823
  { data: input, schema: syncAccountInputSchema },
@@ -1445,6 +1499,15 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1445
1499
  data.currency,
1446
1500
  data.creditor
1447
1501
  );
1502
+ if (data.creditor.bankCode?.length === 4 && !data.creditor.iban && data.creditor.number) {
1503
+ try {
1504
+ data.creditor.iban = calculateCzechIban(
1505
+ data.creditor.number,
1506
+ data.creditor.bankCode
1507
+ );
1508
+ } catch (_error) {
1509
+ }
1510
+ }
1448
1511
  const { accounts } = await this._getAccounts({
1449
1512
  filterIbans: [incomingPayment.debtorIban]
1450
1513
  });
@@ -1996,6 +2059,9 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1996
2059
  __decorateClass([
1997
2060
  action("get-payments")
1998
2061
  ], BankServiceBase.prototype, "getPayments", 1);
2062
+ __decorateClass([
2063
+ action("get-payments-by-request-ids")
2064
+ ], BankServiceBase.prototype, "getPaymentsByRequestIds", 1);
1999
2065
  __decorateClass([
2000
2066
  action("sync-account")
2001
2067
  ], BankServiceBase.prototype, "syncAccount", 1);