@develit-services/bank 0.7.3 → 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.
@@ -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,7 +7,7 @@ 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
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';
@@ -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 = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-services/bank",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "author": "Develit.io s.r.o.",
5
5
  "type": "module",
6
6
  "exports": {