@develit-services/bank 0.7.3 → 0.7.5

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,
@@ -287,7 +298,8 @@ const authorizeAccountInputSchema = zod.z.object({
287
298
  urlParams: zod.z.string(),
288
299
  syncIntervalS: zod.z.number().int().positive().optional(),
289
300
  startSync: zod.z.boolean().optional(),
290
- lastSyncAt: zod.z.date().optional()
301
+ lastSyncAt: zod.z.date().optional(),
302
+ address: zod.z.string().optional()
291
303
  });
292
304
 
293
305
  const simulateDepositInputSchema = zod.z.object({
@@ -412,7 +424,10 @@ const updateAccountInputSchema = zod.z.object({
412
424
 
413
425
  const getBankAccountsInputSchema = zod.z.object({
414
426
  includeWorkflow: zod.z.boolean().optional(),
415
- includeBatchCounts: zod.z.boolean().optional()
427
+ includeBatchCounts: zod.z.boolean().optional(),
428
+ filterIbans: zod.z.array(zod.z.string()).optional(),
429
+ filterCurrencies: zod.z.array(zod.z.string()).optional(),
430
+ filterBankRefIds: zod.z.array(zod.z.string()).optional()
416
431
  });
417
432
 
418
433
  const disconnectAccountInputSchema = zod.z.object({
@@ -436,8 +451,8 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
436
451
  this.allowedProviders = config.allowedProviders;
437
452
  this.db = d1.drizzle(this.env.BANK_D1, { schema: drizzle.tables });
438
453
  }
439
- async _getAccounts() {
440
- return await getAllAccountsQuery(this.db);
454
+ async _getAccounts(filters) {
455
+ return await getAllAccountsQuery(this.db, filters);
441
456
  }
442
457
  async _getConnectedAccounts() {
443
458
  const accounts = await this._getAccounts();
@@ -447,6 +462,7 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
447
462
  connectorKey,
448
463
  skipAccounts
449
464
  }) {
465
+ this.env.DBU_CBS_BACKOFFICE_DEV.fetch("/status");
450
466
  if (!this.allowedProviders.includes(connectorKey)) {
451
467
  throw backendSdk.createInternalError(null, {
452
468
  message: `Invalid connector key: ${connectorKey}`,
@@ -870,7 +886,14 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
870
886
  return this.handleAction(
871
887
  { data: input, schema: authorizeAccountInputSchema },
872
888
  { successMessage: "Account connected" },
873
- async ({ ott, urlParams, syncIntervalS, startSync, lastSyncAt }) => {
889
+ async ({
890
+ ott,
891
+ urlParams,
892
+ syncIntervalS,
893
+ startSync,
894
+ lastSyncAt,
895
+ address
896
+ }) => {
874
897
  const ottRow = await getOttQuery(this.db, {
875
898
  ott
876
899
  });
@@ -912,7 +935,8 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
912
935
  return upsertAccountCommand(this.db, {
913
936
  account: {
914
937
  ...base,
915
- ...existingPart
938
+ ...existingPart,
939
+ ...address && { address }
916
940
  }
917
941
  }).command;
918
942
  });
@@ -1048,8 +1072,18 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
1048
1072
  return this.handleAction(
1049
1073
  { data: input, schema: getBankAccountsInputSchema },
1050
1074
  { successMessage: "Bank accounts retrieved successfully" },
1051
- async ({ includeWorkflow, includeBatchCounts }) => {
1052
- const accounts = await this._getAccounts();
1075
+ async ({
1076
+ includeWorkflow,
1077
+ includeBatchCounts,
1078
+ filterIbans,
1079
+ filterCurrencies,
1080
+ filterBankRefIds
1081
+ }) => {
1082
+ const accounts = await this._getAccounts({
1083
+ filterIbans,
1084
+ filterCurrencies,
1085
+ filterBankRefIds
1086
+ });
1053
1087
  const accountsWithOptionalFields = await Promise.all(
1054
1088
  accounts.map(async (a) => {
1055
1089
  const result = {
@@ -35,6 +35,7 @@ declare const authorizeAccountInputSchema: z.ZodObject<{
35
35
  syncIntervalS: z.ZodOptional<z.ZodNumber>;
36
36
  startSync: z.ZodOptional<z.ZodBoolean>;
37
37
  lastSyncAt: z.ZodOptional<z.ZodDate>;
38
+ address: z.ZodOptional<z.ZodString>;
38
39
  }, z.core.$strip>;
39
40
  interface AuthorizeAccountInput extends z.infer<typeof authorizeAccountInputSchema> {
40
41
  }
@@ -1716,6 +1717,9 @@ type UpdateAccountOutput = AccountSelectType;
1716
1717
  declare const getBankAccountsInputSchema: z.ZodObject<{
1717
1718
  includeWorkflow: z.ZodOptional<z.ZodBoolean>;
1718
1719
  includeBatchCounts: z.ZodOptional<z.ZodBoolean>;
1720
+ filterIbans: z.ZodOptional<z.ZodArray<z.ZodString>>;
1721
+ filterCurrencies: z.ZodOptional<z.ZodArray<z.ZodString>>;
1722
+ filterBankRefIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
1719
1723
  }, z.core.$strip>;
1720
1724
  type GetBankAccountsInput = z.infer<typeof getBankAccountsInputSchema>;
1721
1725
  type WorkflowInfo = {
@@ -1751,7 +1755,11 @@ declare class BankServiceBase extends BankServiceBase_base {
1751
1755
  readonly db: DrizzleD1Database<typeof tables>;
1752
1756
  protected allowedProviders: ConnectorKey[];
1753
1757
  constructor(ctx: ExecutionContext, env: BankEnv, config: ConfigEnvironmentBank);
1754
- _getAccounts(): Promise<{
1758
+ _getAccounts(filters?: {
1759
+ filterIbans?: string[];
1760
+ filterCurrencies?: string[];
1761
+ filterBankRefIds?: string[];
1762
+ }): Promise<{
1755
1763
  expiresAt: Date | undefined;
1756
1764
  number: string;
1757
1765
  name: string | null;
@@ -1844,7 +1852,7 @@ declare class BankServiceBase extends BankServiceBase_base {
1844
1852
  /**
1845
1853
  * Authorizes and connects a bank account using one-time token.
1846
1854
  *
1847
- * @param input - Authorization input including ott, urlParams, syncIntervalS, startSync, and lastSyncAt
1855
+ * @param input - Authorization input including ott, urlParams, syncIntervalS, startSync, lastSyncAt, and address
1848
1856
  *
1849
1857
  * @remarks
1850
1858
  * For new accounts:
@@ -35,6 +35,7 @@ declare const authorizeAccountInputSchema: z.ZodObject<{
35
35
  syncIntervalS: z.ZodOptional<z.ZodNumber>;
36
36
  startSync: z.ZodOptional<z.ZodBoolean>;
37
37
  lastSyncAt: z.ZodOptional<z.ZodDate>;
38
+ address: z.ZodOptional<z.ZodString>;
38
39
  }, z.core.$strip>;
39
40
  interface AuthorizeAccountInput extends z.infer<typeof authorizeAccountInputSchema> {
40
41
  }
@@ -1716,6 +1717,9 @@ type UpdateAccountOutput = AccountSelectType;
1716
1717
  declare const getBankAccountsInputSchema: z.ZodObject<{
1717
1718
  includeWorkflow: z.ZodOptional<z.ZodBoolean>;
1718
1719
  includeBatchCounts: z.ZodOptional<z.ZodBoolean>;
1720
+ filterIbans: z.ZodOptional<z.ZodArray<z.ZodString>>;
1721
+ filterCurrencies: z.ZodOptional<z.ZodArray<z.ZodString>>;
1722
+ filterBankRefIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
1719
1723
  }, z.core.$strip>;
1720
1724
  type GetBankAccountsInput = z.infer<typeof getBankAccountsInputSchema>;
1721
1725
  type WorkflowInfo = {
@@ -1751,7 +1755,11 @@ declare class BankServiceBase extends BankServiceBase_base {
1751
1755
  readonly db: DrizzleD1Database<typeof tables>;
1752
1756
  protected allowedProviders: ConnectorKey[];
1753
1757
  constructor(ctx: ExecutionContext, env: BankEnv, config: ConfigEnvironmentBank);
1754
- _getAccounts(): Promise<{
1758
+ _getAccounts(filters?: {
1759
+ filterIbans?: string[];
1760
+ filterCurrencies?: string[];
1761
+ filterBankRefIds?: string[];
1762
+ }): Promise<{
1755
1763
  expiresAt: Date | undefined;
1756
1764
  number: string;
1757
1765
  name: string | null;
@@ -1844,7 +1852,7 @@ declare class BankServiceBase extends BankServiceBase_base {
1844
1852
  /**
1845
1853
  * Authorizes and connects a bank account using one-time token.
1846
1854
  *
1847
- * @param input - Authorization input including ott, urlParams, syncIntervalS, startSync, and lastSyncAt
1855
+ * @param input - Authorization input including ott, urlParams, syncIntervalS, startSync, lastSyncAt, and address
1848
1856
  *
1849
1857
  * @remarks
1850
1858
  * For new accounts:
@@ -35,6 +35,7 @@ declare const authorizeAccountInputSchema: z.ZodObject<{
35
35
  syncIntervalS: z.ZodOptional<z.ZodNumber>;
36
36
  startSync: z.ZodOptional<z.ZodBoolean>;
37
37
  lastSyncAt: z.ZodOptional<z.ZodDate>;
38
+ address: z.ZodOptional<z.ZodString>;
38
39
  }, z.core.$strip>;
39
40
  interface AuthorizeAccountInput extends z.infer<typeof authorizeAccountInputSchema> {
40
41
  }
@@ -1716,6 +1717,9 @@ type UpdateAccountOutput = AccountSelectType;
1716
1717
  declare const getBankAccountsInputSchema: z.ZodObject<{
1717
1718
  includeWorkflow: z.ZodOptional<z.ZodBoolean>;
1718
1719
  includeBatchCounts: z.ZodOptional<z.ZodBoolean>;
1720
+ filterIbans: z.ZodOptional<z.ZodArray<z.ZodString>>;
1721
+ filterCurrencies: z.ZodOptional<z.ZodArray<z.ZodString>>;
1722
+ filterBankRefIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
1719
1723
  }, z.core.$strip>;
1720
1724
  type GetBankAccountsInput = z.infer<typeof getBankAccountsInputSchema>;
1721
1725
  type WorkflowInfo = {
@@ -1751,7 +1755,11 @@ declare class BankServiceBase extends BankServiceBase_base {
1751
1755
  readonly db: DrizzleD1Database<typeof tables>;
1752
1756
  protected allowedProviders: ConnectorKey[];
1753
1757
  constructor(ctx: ExecutionContext, env: BankEnv, config: ConfigEnvironmentBank);
1754
- _getAccounts(): Promise<{
1758
+ _getAccounts(filters?: {
1759
+ filterIbans?: string[];
1760
+ filterCurrencies?: string[];
1761
+ filterBankRefIds?: string[];
1762
+ }): Promise<{
1755
1763
  expiresAt: Date | undefined;
1756
1764
  number: string;
1757
1765
  name: string | null;
@@ -1844,7 +1852,7 @@ declare class BankServiceBase extends BankServiceBase_base {
1844
1852
  /**
1845
1853
  * Authorizes and connects a bank account using one-time token.
1846
1854
  *
1847
- * @param input - Authorization input including ott, urlParams, syncIntervalS, startSync, and lastSyncAt
1855
+ * @param input - Authorization input including ott, urlParams, syncIntervalS, startSync, lastSyncAt, and address
1848
1856
  *
1849
1857
  * @remarks
1850
1858
  * For new accounts:
@@ -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,
@@ -285,7 +296,8 @@ const authorizeAccountInputSchema = z.object({
285
296
  urlParams: z.string(),
286
297
  syncIntervalS: z.number().int().positive().optional(),
287
298
  startSync: z.boolean().optional(),
288
- lastSyncAt: z.date().optional()
299
+ lastSyncAt: z.date().optional(),
300
+ address: z.string().optional()
289
301
  });
290
302
 
291
303
  const simulateDepositInputSchema = z.object({
@@ -410,7 +422,10 @@ const updateAccountInputSchema = z.object({
410
422
 
411
423
  const getBankAccountsInputSchema = z.object({
412
424
  includeWorkflow: z.boolean().optional(),
413
- includeBatchCounts: z.boolean().optional()
425
+ includeBatchCounts: z.boolean().optional(),
426
+ filterIbans: z.array(z.string()).optional(),
427
+ filterCurrencies: z.array(z.string()).optional(),
428
+ filterBankRefIds: z.array(z.string()).optional()
414
429
  });
415
430
 
416
431
  const disconnectAccountInputSchema = z.object({
@@ -434,8 +449,8 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
434
449
  this.allowedProviders = config.allowedProviders;
435
450
  this.db = drizzle(this.env.BANK_D1, { schema: tables });
436
451
  }
437
- async _getAccounts() {
438
- return await getAllAccountsQuery(this.db);
452
+ async _getAccounts(filters) {
453
+ return await getAllAccountsQuery(this.db, filters);
439
454
  }
440
455
  async _getConnectedAccounts() {
441
456
  const accounts = await this._getAccounts();
@@ -445,6 +460,7 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
445
460
  connectorKey,
446
461
  skipAccounts
447
462
  }) {
463
+ this.env.DBU_CBS_BACKOFFICE_DEV.fetch("/status");
448
464
  if (!this.allowedProviders.includes(connectorKey)) {
449
465
  throw createInternalError(null, {
450
466
  message: `Invalid connector key: ${connectorKey}`,
@@ -868,7 +884,14 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
868
884
  return this.handleAction(
869
885
  { data: input, schema: authorizeAccountInputSchema },
870
886
  { successMessage: "Account connected" },
871
- async ({ ott, urlParams, syncIntervalS, startSync, lastSyncAt }) => {
887
+ async ({
888
+ ott,
889
+ urlParams,
890
+ syncIntervalS,
891
+ startSync,
892
+ lastSyncAt,
893
+ address
894
+ }) => {
872
895
  const ottRow = await getOttQuery(this.db, {
873
896
  ott
874
897
  });
@@ -910,7 +933,8 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
910
933
  return upsertAccountCommand(this.db, {
911
934
  account: {
912
935
  ...base,
913
- ...existingPart
936
+ ...existingPart,
937
+ ...address && { address }
914
938
  }
915
939
  }).command;
916
940
  });
@@ -1046,8 +1070,18 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1046
1070
  return this.handleAction(
1047
1071
  { data: input, schema: getBankAccountsInputSchema },
1048
1072
  { successMessage: "Bank accounts retrieved successfully" },
1049
- async ({ includeWorkflow, includeBatchCounts }) => {
1050
- const accounts = await this._getAccounts();
1073
+ async ({
1074
+ includeWorkflow,
1075
+ includeBatchCounts,
1076
+ filterIbans,
1077
+ filterCurrencies,
1078
+ filterBankRefIds
1079
+ }) => {
1080
+ const accounts = await this._getAccounts({
1081
+ filterIbans,
1082
+ filterCurrencies,
1083
+ filterBankRefIds
1084
+ });
1051
1085
  const accountsWithOptionalFields = await Promise.all(
1052
1086
  accounts.map(async (a) => {
1053
1087
  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.5",
4
4
  "author": "Develit.io s.r.o.",
5
5
  "type": "module",
6
6
  "exports": {