@develit-services/bank 0.7.2 → 0.7.4

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.
@@ -11,7 +11,7 @@ require('date-fns');
11
11
  require('jose');
12
12
  const drizzleOrm = require('drizzle-orm');
13
13
  require('node:crypto');
14
- const mock_connector = require('../shared/bank.CNXTZfXB.cjs');
14
+ const mock_connector = require('../shared/bank.CBQJX5Zr.cjs');
15
15
  require('../shared/bank.DlW1XNug.cjs');
16
16
  require('drizzle-orm/relations');
17
17
  require('drizzle-orm/sqlite-core');
@@ -119,11 +119,22 @@ const getAccountByIbanQuery = async (db, { iban }) => {
119
119
  return await db.select().from(drizzle.tables.account).where(drizzleOrm.eq(drizzle.tables.account.iban, iban)).get();
120
120
  };
121
121
 
122
- const getAllAccountsQuery = async (db) => {
122
+ const getAllAccountsQuery = async (db, filters) => {
123
+ const whereConditions = drizzleOrm.and(
124
+ backendSdk.buildMultiFilterConditions(drizzle.tables.account.iban, filters?.filterIbans),
125
+ backendSdk.buildMultiFilterConditions(
126
+ drizzle.tables.account.currency,
127
+ filters?.filterCurrencies
128
+ ),
129
+ backendSdk.buildMultiFilterConditions(
130
+ drizzle.tables.account.bankRefId,
131
+ filters?.filterBankRefIds
132
+ )
133
+ );
123
134
  const accountsWithExpiration = await db.select().from(drizzle.tables.account).leftJoin(
124
135
  drizzle.tables.accountCredentials,
125
136
  drizzleOrm.eq(drizzle.tables.accountCredentials.accountId, drizzle.tables.account.id)
126
- );
137
+ ).where(whereConditions);
127
138
  return accountsWithExpiration.map(({ account, account_credentials }) => {
128
139
  return {
129
140
  ...account,
@@ -412,7 +423,10 @@ const updateAccountInputSchema = zod.z.object({
412
423
 
413
424
  const getBankAccountsInputSchema = zod.z.object({
414
425
  includeWorkflow: zod.z.boolean().optional(),
415
- includeBatchCounts: zod.z.boolean().optional()
426
+ includeBatchCounts: zod.z.boolean().optional(),
427
+ filterIbans: zod.z.array(zod.z.string()).optional(),
428
+ filterCurrencies: zod.z.array(zod.z.string()).optional(),
429
+ filterBankRefIds: zod.z.array(zod.z.string()).optional()
416
430
  });
417
431
 
418
432
  const disconnectAccountInputSchema = zod.z.object({
@@ -436,8 +450,8 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
436
450
  this.allowedProviders = config.allowedProviders;
437
451
  this.db = d1.drizzle(this.env.BANK_D1, { schema: drizzle.tables });
438
452
  }
439
- async _getAccounts() {
440
- return await getAllAccountsQuery(this.db);
453
+ async _getAccounts(filters) {
454
+ return await getAllAccountsQuery(this.db, filters);
441
455
  }
442
456
  async _getConnectedAccounts() {
443
457
  const accounts = await this._getAccounts();
@@ -447,6 +461,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
447
461
  connectorKey,
448
462
  skipAccounts
449
463
  }) {
464
+ this.env.DBU_CBS_BACKOFFICE_DEV.fetch("/status");
450
465
  if (!this.allowedProviders.includes(connectorKey)) {
451
466
  throw backendSdk.createInternalError(null, {
452
467
  message: `Invalid connector key: ${connectorKey}`,
@@ -1048,8 +1063,18 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
1048
1063
  return this.handleAction(
1049
1064
  { data: input, schema: getBankAccountsInputSchema },
1050
1065
  { successMessage: "Bank accounts retrieved successfully" },
1051
- async ({ includeWorkflow, includeBatchCounts }) => {
1052
- const accounts = await this._getAccounts();
1066
+ async ({
1067
+ includeWorkflow,
1068
+ includeBatchCounts,
1069
+ filterIbans,
1070
+ filterCurrencies,
1071
+ filterBankRefIds
1072
+ }) => {
1073
+ const accounts = await this._getAccounts({
1074
+ filterIbans,
1075
+ filterCurrencies,
1076
+ filterBankRefIds
1077
+ });
1053
1078
  const accountsWithOptionalFields = await Promise.all(
1054
1079
  accounts.map(async (a) => {
1055
1080
  const result = {
@@ -1716,6 +1716,9 @@ type UpdateAccountOutput = AccountSelectType;
1716
1716
  declare const getBankAccountsInputSchema: z.ZodObject<{
1717
1717
  includeWorkflow: z.ZodOptional<z.ZodBoolean>;
1718
1718
  includeBatchCounts: z.ZodOptional<z.ZodBoolean>;
1719
+ filterIbans: z.ZodOptional<z.ZodArray<z.ZodString>>;
1720
+ filterCurrencies: z.ZodOptional<z.ZodArray<z.ZodString>>;
1721
+ filterBankRefIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
1719
1722
  }, z.core.$strip>;
1720
1723
  type GetBankAccountsInput = z.infer<typeof getBankAccountsInputSchema>;
1721
1724
  type WorkflowInfo = {
@@ -1751,7 +1754,11 @@ declare class BankServiceBase extends BankServiceBase_base {
1751
1754
  readonly db: DrizzleD1Database<typeof tables>;
1752
1755
  protected allowedProviders: ConnectorKey[];
1753
1756
  constructor(ctx: ExecutionContext, env: BankEnv, config: ConfigEnvironmentBank);
1754
- _getAccounts(): Promise<{
1757
+ _getAccounts(filters?: {
1758
+ filterIbans?: string[];
1759
+ filterCurrencies?: string[];
1760
+ filterBankRefIds?: string[];
1761
+ }): Promise<{
1755
1762
  expiresAt: Date | undefined;
1756
1763
  number: string;
1757
1764
  name: string | null;
@@ -1716,6 +1716,9 @@ type UpdateAccountOutput = AccountSelectType;
1716
1716
  declare const getBankAccountsInputSchema: z.ZodObject<{
1717
1717
  includeWorkflow: z.ZodOptional<z.ZodBoolean>;
1718
1718
  includeBatchCounts: z.ZodOptional<z.ZodBoolean>;
1719
+ filterIbans: z.ZodOptional<z.ZodArray<z.ZodString>>;
1720
+ filterCurrencies: z.ZodOptional<z.ZodArray<z.ZodString>>;
1721
+ filterBankRefIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
1719
1722
  }, z.core.$strip>;
1720
1723
  type GetBankAccountsInput = z.infer<typeof getBankAccountsInputSchema>;
1721
1724
  type WorkflowInfo = {
@@ -1751,7 +1754,11 @@ declare class BankServiceBase extends BankServiceBase_base {
1751
1754
  readonly db: DrizzleD1Database<typeof tables>;
1752
1755
  protected allowedProviders: ConnectorKey[];
1753
1756
  constructor(ctx: ExecutionContext, env: BankEnv, config: ConfigEnvironmentBank);
1754
- _getAccounts(): Promise<{
1757
+ _getAccounts(filters?: {
1758
+ filterIbans?: string[];
1759
+ filterCurrencies?: string[];
1760
+ filterBankRefIds?: string[];
1761
+ }): Promise<{
1755
1762
  expiresAt: Date | undefined;
1756
1763
  number: string;
1757
1764
  name: string | null;
@@ -1716,6 +1716,9 @@ type UpdateAccountOutput = AccountSelectType;
1716
1716
  declare const getBankAccountsInputSchema: z.ZodObject<{
1717
1717
  includeWorkflow: z.ZodOptional<z.ZodBoolean>;
1718
1718
  includeBatchCounts: z.ZodOptional<z.ZodBoolean>;
1719
+ filterIbans: z.ZodOptional<z.ZodArray<z.ZodString>>;
1720
+ filterCurrencies: z.ZodOptional<z.ZodArray<z.ZodString>>;
1721
+ filterBankRefIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
1719
1722
  }, z.core.$strip>;
1720
1723
  type GetBankAccountsInput = z.infer<typeof getBankAccountsInputSchema>;
1721
1724
  type WorkflowInfo = {
@@ -1751,7 +1754,11 @@ declare class BankServiceBase extends BankServiceBase_base {
1751
1754
  readonly db: DrizzleD1Database<typeof tables>;
1752
1755
  protected allowedProviders: ConnectorKey[];
1753
1756
  constructor(ctx: ExecutionContext, env: BankEnv, config: ConfigEnvironmentBank);
1754
- _getAccounts(): Promise<{
1757
+ _getAccounts(filters?: {
1758
+ filterIbans?: string[];
1759
+ filterCurrencies?: string[];
1760
+ filterBankRefIds?: string[];
1761
+ }): Promise<{
1755
1762
  expiresAt: Date | undefined;
1756
1763
  number: string;
1757
1764
  name: string | null;
@@ -1,4 +1,4 @@
1
- import { uuidv4, first, bankAccountMetadataSchema, workflowInstanceStatusSchema, develitWorker, createInternalError, action, service } from '@develit-io/backend-sdk';
1
+ import { uuidv4, first, buildMultiFilterConditions as buildMultiFilterConditions$1, bankAccountMetadataSchema, workflowInstanceStatusSchema, develitWorker, createInternalError, action, service } from '@develit-io/backend-sdk';
2
2
  import { t as tables, e as encrypt, i as importAesKey, b as getCredentialsByAccountId, u as upsertBatchCommand, g as getBatchByIdQuery, d as createPaymentCommand, a as getAccountByIdQuery } from '../shared/bank.e8T8fQDG.mjs';
3
3
  import { WorkerEntrypoint } from 'cloudflare:workers';
4
4
  import { drizzle } from 'drizzle-orm/d1';
@@ -7,9 +7,9 @@ import { I as INSTRUCTION_PRIORITIES, C as CHARGE_BEARERS, e as PAYMENT_TYPES, a
7
7
  import { CURRENCY_CODES } from '@develit-io/general-codes';
8
8
  import 'date-fns';
9
9
  import 'jose';
10
- import { eq, sql, inArray, and, asc, desc, gte, lte } from 'drizzle-orm';
10
+ import { eq, sql, and, inArray, asc, desc, gte, lte } from 'drizzle-orm';
11
11
  import 'node:crypto';
12
- import { i as initiateConnector, g as toIncomingPayment, d as assignAccount, t as toBatchedPayment } from '../shared/bank.4MQtZVnP.mjs';
12
+ import { i as initiateConnector, g as toIncomingPayment, d as assignAccount, t as toBatchedPayment } from '../shared/bank.wq0LUeFW.mjs';
13
13
  import '../shared/bank.CTtFAN03.mjs';
14
14
  import 'drizzle-orm/relations';
15
15
  import 'drizzle-orm/sqlite-core';
@@ -117,11 +117,22 @@ const getAccountByIbanQuery = async (db, { iban }) => {
117
117
  return await db.select().from(tables.account).where(eq(tables.account.iban, iban)).get();
118
118
  };
119
119
 
120
- const getAllAccountsQuery = async (db) => {
120
+ const getAllAccountsQuery = async (db, filters) => {
121
+ const whereConditions = and(
122
+ buildMultiFilterConditions$1(tables.account.iban, filters?.filterIbans),
123
+ buildMultiFilterConditions$1(
124
+ tables.account.currency,
125
+ filters?.filterCurrencies
126
+ ),
127
+ buildMultiFilterConditions$1(
128
+ tables.account.bankRefId,
129
+ filters?.filterBankRefIds
130
+ )
131
+ );
121
132
  const accountsWithExpiration = await db.select().from(tables.account).leftJoin(
122
133
  tables.accountCredentials,
123
134
  eq(tables.accountCredentials.accountId, tables.account.id)
124
- );
135
+ ).where(whereConditions);
125
136
  return accountsWithExpiration.map(({ account, account_credentials }) => {
126
137
  return {
127
138
  ...account,
@@ -410,7 +421,10 @@ const updateAccountInputSchema = z.object({
410
421
 
411
422
  const getBankAccountsInputSchema = z.object({
412
423
  includeWorkflow: z.boolean().optional(),
413
- includeBatchCounts: z.boolean().optional()
424
+ includeBatchCounts: z.boolean().optional(),
425
+ filterIbans: z.array(z.string()).optional(),
426
+ filterCurrencies: z.array(z.string()).optional(),
427
+ filterBankRefIds: z.array(z.string()).optional()
414
428
  });
415
429
 
416
430
  const disconnectAccountInputSchema = z.object({
@@ -434,8 +448,8 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
434
448
  this.allowedProviders = config.allowedProviders;
435
449
  this.db = drizzle(this.env.BANK_D1, { schema: tables });
436
450
  }
437
- async _getAccounts() {
438
- return await getAllAccountsQuery(this.db);
451
+ async _getAccounts(filters) {
452
+ return await getAllAccountsQuery(this.db, filters);
439
453
  }
440
454
  async _getConnectedAccounts() {
441
455
  const accounts = await this._getAccounts();
@@ -445,6 +459,7 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
445
459
  connectorKey,
446
460
  skipAccounts
447
461
  }) {
462
+ this.env.DBU_CBS_BACKOFFICE_DEV.fetch("/status");
448
463
  if (!this.allowedProviders.includes(connectorKey)) {
449
464
  throw createInternalError(null, {
450
465
  message: `Invalid connector key: ${connectorKey}`,
@@ -1046,8 +1061,18 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1046
1061
  return this.handleAction(
1047
1062
  { data: input, schema: getBankAccountsInputSchema },
1048
1063
  { successMessage: "Bank accounts retrieved successfully" },
1049
- async ({ includeWorkflow, includeBatchCounts }) => {
1050
- const accounts = await this._getAccounts();
1064
+ async ({
1065
+ includeWorkflow,
1066
+ includeBatchCounts,
1067
+ filterIbans,
1068
+ filterCurrencies,
1069
+ filterBankRefIds
1070
+ }) => {
1071
+ const accounts = await this._getAccounts({
1072
+ filterIbans,
1073
+ filterCurrencies,
1074
+ filterBankRefIds
1075
+ });
1051
1076
  const accountsWithOptionalFields = await Promise.all(
1052
1077
  accounts.map(async (a) => {
1053
1078
  const result = {
@@ -3,7 +3,7 @@
3
3
  const backendSdk = require('@develit-io/backend-sdk');
4
4
  const drizzle = require('../shared/bank.CTqIXnHg.cjs');
5
5
  const batchLifecycle = require('../shared/bank.Bg3Pdwm4.cjs');
6
- const mock_connector = require('../shared/bank.CNXTZfXB.cjs');
6
+ const mock_connector = require('../shared/bank.CBQJX5Zr.cjs');
7
7
  const drizzleOrm = require('drizzle-orm');
8
8
  const cloudflare_workers = require('cloudflare:workers');
9
9
  const cloudflare_workflows = require('cloudflare:workflows');
@@ -144,7 +144,11 @@ class BankProcessBatch extends cloudflare_workers.WorkflowEntrypoint {
144
144
  result = await initiateBatchByType();
145
145
  } catch (err) {
146
146
  const message = err instanceof Error ? err.message : typeof err === "object" && err !== null && "message" in err ? String(err.message) : String(err);
147
- throw new cloudflare_workflows.NonRetryableError(message);
147
+ const status = typeof err === "object" && err !== null && "status" in err ? Number(err.status) : 0;
148
+ if (status >= 400 && status < 500) {
149
+ throw new cloudflare_workflows.NonRetryableError(message);
150
+ }
151
+ throw new Error(message);
148
152
  }
149
153
  const {
150
154
  authorizationUrls,
@@ -1,7 +1,7 @@
1
1
  import { first, uuidv4, asNonEmpty } from '@develit-io/backend-sdk';
2
2
  import { t as tables, g as getBatchByIdQuery, c as checksum, u as upsertBatchCommand, a as getAccountByIdQuery, i as importAesKey, b as getCredentialsByAccountId, d as createPaymentCommand } from '../shared/bank.e8T8fQDG.mjs';
3
3
  import { f as isBatchSigned, a as isBatchFailed, c as isBatchOpen, g as isPaymentCompleted } from '../shared/bank.CbAwwIhZ.mjs';
4
- import { h as toPreparedPayment, i as initiateConnector, f as toCompletedPayment } from '../shared/bank.4MQtZVnP.mjs';
4
+ import { h as toPreparedPayment, i as initiateConnector, f as toCompletedPayment } from '../shared/bank.wq0LUeFW.mjs';
5
5
  import { eq } from 'drizzle-orm';
6
6
  import { WorkflowEntrypoint } from 'cloudflare:workers';
7
7
  import { NonRetryableError } from 'cloudflare:workflows';
@@ -142,7 +142,11 @@ class BankProcessBatch extends WorkflowEntrypoint {
142
142
  result = await initiateBatchByType();
143
143
  } catch (err) {
144
144
  const message = err instanceof Error ? err.message : typeof err === "object" && err !== null && "message" in err ? String(err.message) : String(err);
145
- throw new NonRetryableError(message);
145
+ const status = typeof err === "object" && err !== null && "status" in err ? Number(err.status) : 0;
146
+ if (status >= 400 && status < 500) {
147
+ throw new NonRetryableError(message);
148
+ }
149
+ throw new Error(message);
146
150
  }
147
151
  const {
148
152
  authorizationUrls,
@@ -583,7 +583,7 @@ class FinbricksConnector extends IBankConnector {
583
583
  );
584
584
  if (error || !response) {
585
585
  console.error("FINBRICKS BATCH ERROR", error);
586
- throw backendSdk.createInternalError(error);
586
+ throw error ?? backendSdk.createInternalError(null);
587
587
  }
588
588
  const initiatedAt = /* @__PURE__ */ new Date();
589
589
  return {
@@ -781,7 +781,7 @@ class FinbricksConnector extends IBankConnector {
781
781
  const [response, error] = await fetchTransactions(cursor);
782
782
  if (error || !response) {
783
783
  console.error(error, "TRANSACTIONS GET ERROR");
784
- throw backendSdk.createInternalError(error);
784
+ throw error ?? backendSdk.createInternalError(null);
785
785
  }
786
786
  const { transactions, links } = response;
787
787
  cursor = links?.[0]?.value || null;
@@ -581,7 +581,7 @@ class FinbricksConnector extends IBankConnector {
581
581
  );
582
582
  if (error || !response) {
583
583
  console.error("FINBRICKS BATCH ERROR", error);
584
- throw createInternalError(error);
584
+ throw error ?? createInternalError(null);
585
585
  }
586
586
  const initiatedAt = /* @__PURE__ */ new Date();
587
587
  return {
@@ -779,7 +779,7 @@ class FinbricksConnector extends IBankConnector {
779
779
  const [response, error] = await fetchTransactions(cursor);
780
780
  if (error || !response) {
781
781
  console.error(error, "TRANSACTIONS GET ERROR");
782
- throw createInternalError(error);
782
+ throw error ?? createInternalError(null);
783
783
  }
784
784
  const { transactions, links } = response;
785
785
  cursor = links?.[0]?.value || null;
package/dist/types.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const mock_connector = require('./shared/bank.CNXTZfXB.cjs');
3
+ const mock_connector = require('./shared/bank.CBQJX5Zr.cjs');
4
4
  const payment_schema = require('./shared/bank.D7kwLMqF.cjs');
5
5
  const batchLifecycle = require('./shared/bank.Bg3Pdwm4.cjs');
6
6
  const generalCodes = require('@develit-io/general-codes');
package/dist/types.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { D as DbuConnector, E as ErsteConnector, F as FINBRICKS_ENDPOINTS, a as FinbricksClient, b as FinbricksConnector, I as IBankConnector, M as MockCobsConnector, c as MockConnector, d as assignAccount, e as batchTransform, s as signFinbricksJws, t as toBatchedPayment, f as toCompletedPayment, g as toIncomingPayment, h as toPreparedPayment, u as useFinbricksFetch } from './shared/bank.4MQtZVnP.mjs';
1
+ export { D as DbuConnector, E as ErsteConnector, F as FINBRICKS_ENDPOINTS, a as FinbricksClient, b as FinbricksConnector, I as IBankConnector, M as MockCobsConnector, c as MockConnector, d as assignAccount, e as batchTransform, s as signFinbricksJws, t as toBatchedPayment, f as toCompletedPayment, g as toIncomingPayment, h as toPreparedPayment, u as useFinbricksFetch } from './shared/bank.wq0LUeFW.mjs';
2
2
  export { A as ACCOUNT_STATUSES, B as BATCH_STATUES, B as BATCH_STATUSES, C as CHARGE_BEARERS, a as CONNECTOR_KEYS, b as COUNTRY_CODES, c as CREDENTIALS_TYPES, I as INSTRUCTION_PRIORITIES, P as PAYMENT_DIRECTIONS, d as PAYMENT_STATUSES, e as PAYMENT_TYPES, T as TOKEN_TYPES, f as accountCredentialsInsertSchema, g as accountCredentialsSelectSchema, h as accountCredentialsUpdateSchema, i as accountInsertSchema, j as accountSelectSchema, k as accountUpdateSchema, o as ottInsertSchema, l as ottSelectSchema, m as ottUpdateSchema } from './shared/bank.BnIYdBEF.mjs';
3
3
  export { h as hasPaymentAccountAssigned, i as isBatchCompleted, a as isBatchFailed, b as isBatchInitiated, c as isBatchOpen, d as isBatchProcessing, e as isBatchReadyToSign, f as isBatchSigned, g as isPaymentCompleted, j as isPaymentPrepared } from './shared/bank.CbAwwIhZ.mjs';
4
4
  export { BANK_CODES, CURRENCY_CODES } from '@develit-io/general-codes';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-services/bank",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "author": "Develit.io s.r.o.",
5
5
  "type": "module",
6
6
  "exports": {