@develit-services/bank 0.0.32 → 0.0.34

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.
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const database_schema = require('../shared/bank.Dx7kRjFL.cjs');
3
+ const database_schema = require('../shared/bank.D4BlThGx.cjs');
4
4
  require('@develit-io/backend-sdk');
5
+ require('drizzle-orm/sqlite-core');
5
6
  require('drizzle-orm');
6
7
  require('@develit-io/general-codes');
7
8
  require('zod');
8
9
  require('jose');
9
10
  require('drizzle-zod');
10
- require('drizzle-orm/sqlite-core');
11
11
  require('date-fns');
12
12
  require('drizzle-orm/relations');
13
13
 
@@ -1,10 +1,10 @@
1
- export { y as account, z as accountCredentials, r as batch, x as ott, v as payment, w as paymentRelations } from '../shared/bank.uJ3YtInA.mjs';
1
+ export { y as account, z as accountCredentials, r as batch, x as ott, v as payment, w as paymentRelations } from '../shared/bank.ClfukJ-T.mjs';
2
2
  import '@develit-io/backend-sdk';
3
+ import 'drizzle-orm/sqlite-core';
3
4
  import 'drizzle-orm';
4
5
  import '@develit-io/general-codes';
5
6
  import 'zod';
6
7
  import 'jose';
7
8
  import 'drizzle-zod';
8
- import 'drizzle-orm/sqlite-core';
9
9
  import 'date-fns';
10
10
  import 'drizzle-orm/relations';
@@ -3,16 +3,16 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const backendSdk = require('@develit-io/backend-sdk');
6
- const database_schema = require('../shared/bank.Dx7kRjFL.cjs');
7
6
  const cloudflare_workers = require('cloudflare:workers');
8
7
  const d1 = require('drizzle-orm/d1');
9
- const zod = require('zod');
10
- const generalCodes = require('@develit-io/general-codes');
8
+ const database_schema = require('../shared/bank.D4BlThGx.cjs');
11
9
  require('jose');
10
+ const generalCodes = require('@develit-io/general-codes');
11
+ const zod = require('zod');
12
12
  const drizzleOrm = require('drizzle-orm');
13
- const mockCobs_connector = require('../shared/bank.BiZtZWed.cjs');
14
- require('drizzle-zod');
13
+ const mockCobs_connector = require('../shared/bank.BVW0vOQS.cjs');
15
14
  require('drizzle-orm/sqlite-core');
15
+ require('drizzle-zod');
16
16
  require('date-fns');
17
17
  require('drizzle-orm/relations');
18
18
 
@@ -111,52 +111,14 @@ const updateAccountLastSyncCommand = (db, { lastSyncedAt, accountId }) => {
111
111
  };
112
112
  };
113
113
 
114
- const getPaymentByRefIdQuery = async (db, { refId }) => {
115
- const payment = await db.select().from(database_schema.tables.payment).where(drizzleOrm.eq(database_schema.tables.payment.refId, refId)).limit(1).get();
116
- return payment;
117
- };
118
-
119
- const getOpenBatchByAccountIdQuery = async (db, { accountId }) => {
120
- const batch = await db.select().from(database_schema.tables.batch).where(
121
- drizzleOrm.and(
122
- drizzleOrm.eq(database_schema.tables.batch.accountId, accountId),
123
- drizzleOrm.eq(database_schema.tables.batch.status, "OPEN")
124
- )
125
- ).limit(1).get();
126
- return batch;
127
- };
128
-
129
- const getPaymentsByBankRefIdsQuery = async (db, { ids }) => {
130
- return await db.select().from(database_schema.tables.payment).where(drizzleOrm.inArray(database_schema.tables.payment.bankRefId, ids));
131
- };
132
-
133
- const getOttQuery = async (db, { ott }) => {
134
- return await db.select().from(database_schema.tables.ott).where(drizzleOrm.eq(database_schema.tables.ott.oneTimeToken, ott)).get();
135
- };
136
-
137
- const getAllPendingBatchesQuery = (db) => {
138
- return db.select().from(database_schema.tables.batch).where(
139
- drizzleOrm.inArray(database_schema.tables.batch.status, [
140
- "PROCESSING",
141
- "READY_TO_SIGN",
142
- "WAITING_FOR_PROCESSING"
143
- ])
144
- );
114
+ const getAccountByIbanQuery = async (db, { iban }) => {
115
+ return await db.select().from(database_schema.tables.account).where(drizzleOrm.eq(database_schema.tables.account.iban, iban)).get();
145
116
  };
146
117
 
147
118
  const getAccountByIdQuery = async (db, { accountId }) => {
148
119
  return await db.select().from(database_schema.tables.account).where(drizzleOrm.eq(database_schema.tables.account.id, accountId)).get();
149
120
  };
150
121
 
151
- const getCredentialsByAccountId = async (db, { accountId }) => {
152
- const cred = await db.select().from(database_schema.tables.accountCredentials).where(drizzleOrm.eq(database_schema.tables.accountCredentials.accountId, accountId)).get();
153
- return cred;
154
- };
155
-
156
- const getAccountByIbanQuery = async (db, { iban }) => {
157
- return await db.select().from(database_schema.tables.account).where(drizzleOrm.eq(database_schema.tables.account.iban, iban)).get();
158
- };
159
-
160
122
  const getAllAccountsQuery = async (db) => {
161
123
  const accountsWithExpiration = await db.select().from(database_schema.tables.account).leftJoin(
162
124
  database_schema.tables.accountCredentials,
@@ -170,6 +132,16 @@ const getAllAccountsQuery = async (db) => {
170
132
  });
171
133
  };
172
134
 
135
+ const getAllPendingBatchesQuery = (db) => {
136
+ return db.select().from(database_schema.tables.batch).where(
137
+ drizzleOrm.inArray(database_schema.tables.batch.status, [
138
+ "PROCESSING",
139
+ "READY_TO_SIGN",
140
+ "WAITING_FOR_PROCESSING"
141
+ ])
142
+ );
143
+ };
144
+
173
145
  const buildMultiFilterConditions = (column, value) => {
174
146
  if (value === void 0) return void 0;
175
147
  if (Array.isArray(value)) {
@@ -234,6 +206,56 @@ const getPaymentsWithPaginationQuery = async (db, {
234
206
  };
235
207
  };
236
208
 
209
+ const getBatchesQuery = async (db, {
210
+ limit,
211
+ page,
212
+ sort,
213
+ filterBatchAccountId,
214
+ filterBatchStatus
215
+ }) => {
216
+ const whereConditions = drizzleOrm.and(
217
+ buildMultiFilterConditions(database_schema.tables.batch.accountId, filterBatchAccountId),
218
+ buildMultiFilterConditions(database_schema.tables.batch.status, filterBatchStatus)
219
+ );
220
+ const sortColumn = resolveColumn(database_schema.tables.batch, sort.column);
221
+ const [{ totalCount }] = await db.select({
222
+ totalCount: drizzleOrm.sql`count(*)`
223
+ }).from(database_schema.tables.batch).where(whereConditions);
224
+ const batches = await db.select().from(database_schema.tables.batch).where(whereConditions).limit(limit).offset((page - 1) * limit).orderBy(sort.direction === "asc" ? drizzleOrm.asc(sortColumn) : drizzleOrm.desc(sortColumn));
225
+ return {
226
+ batches,
227
+ totalCount
228
+ };
229
+ };
230
+
231
+ const getCredentialsByAccountId = async (db, { accountId }) => {
232
+ const cred = await db.select().from(database_schema.tables.accountCredentials).where(drizzleOrm.eq(database_schema.tables.accountCredentials.accountId, accountId)).get();
233
+ return cred;
234
+ };
235
+
236
+ const getOpenBatchByAccountIdQuery = async (db, { accountId }) => {
237
+ const batch = await db.select().from(database_schema.tables.batch).where(
238
+ drizzleOrm.and(
239
+ drizzleOrm.eq(database_schema.tables.batch.accountId, accountId),
240
+ drizzleOrm.eq(database_schema.tables.batch.status, "OPEN")
241
+ )
242
+ ).limit(1).get();
243
+ return batch;
244
+ };
245
+
246
+ const getOttQuery = async (db, { ott }) => {
247
+ return await db.select().from(database_schema.tables.ott).where(drizzleOrm.eq(database_schema.tables.ott.oneTimeToken, ott)).get();
248
+ };
249
+
250
+ const getPaymentByRefIdQuery = async (db, { refId }) => {
251
+ const payment = await db.select().from(database_schema.tables.payment).where(drizzleOrm.eq(database_schema.tables.payment.refId, refId)).limit(1).get();
252
+ return payment;
253
+ };
254
+
255
+ const getPaymentsByBankRefIdsQuery = async (db, { ids }) => {
256
+ return await db.select().from(database_schema.tables.payment).where(drizzleOrm.inArray(database_schema.tables.payment.bankRefId, ids));
257
+ };
258
+
237
259
  class CreditasConnector extends database_schema.FinbricksConnector {
238
260
  constructor(config) {
239
261
  super("CREDITAS", config);
@@ -377,9 +399,19 @@ const initiateConnectorInputSchema = zod.z.object({
377
399
  withAuth: zod.z.boolean().default(true).optional()
378
400
  });
379
401
 
402
+ const ALLOWED_BATCH_FILTERS = {
403
+ ACCOUNT_ID: "filterBatchAccountId",
404
+ STATUS: "filterBatchStatus"
405
+ };
380
406
  const getBatchesInputSchema = zod.z.object({
381
- limit: zod.z.number().positive().optional().default(100),
382
- offset: zod.z.number().min(0).optional().default(0)
407
+ page: zod.z.number().positive(),
408
+ limit: zod.z.number().positive(),
409
+ sort: zod.z.object({
410
+ column: zod.z.enum(["createdAt", "updatedAt", "batchPaymentInitiatedAt"]),
411
+ direction: zod.z.enum(["asc", "desc"])
412
+ }),
413
+ [ALLOWED_BATCH_FILTERS.ACCOUNT_ID]: zod.z.union([zod.z.uuid(), zod.z.uuid().array()]).optional(),
414
+ [ALLOWED_BATCH_FILTERS.STATUS]: zod.z.union([zod.z.enum(database_schema.BATCH_STATUSES), zod.z.enum(database_schema.BATCH_STATUSES).array()]).optional()
383
415
  });
384
416
 
385
417
  const processBatchInputSchema = zod.z.object({
@@ -1112,16 +1144,8 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
1112
1144
  return this.handleAction(
1113
1145
  { data: input, schema: getBatchesInputSchema },
1114
1146
  { successMessage: "Batches retrieved successfully" },
1115
- async ({ limit = 100, offset = 0 }) => {
1116
- const [batchesResult, countResult] = await Promise.all([
1117
- this.db.select().from(database_schema.tables.batch).limit(limit).offset(offset).orderBy(drizzleOrm.desc(database_schema.tables.batch.createdAt)),
1118
- this.db.select({ count: drizzleOrm.sql`count(*)`.as("count") }).from(database_schema.tables.batch)
1119
- ]);
1120
- const totalCount = Number(countResult[0]?.count) || 0;
1121
- return {
1122
- batches: batchesResult,
1123
- totalCount
1124
- };
1147
+ async (params) => {
1148
+ return await getBatchesQuery(this.db, params);
1125
1149
  }
1126
1150
  );
1127
1151
  }
@@ -1,10 +1,10 @@
1
1
  import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
2
2
  import { IRPCResponse } from '@develit-io/backend-sdk';
3
- import { P as PaymentSelectType, B as BatchSelectType, t as tables, a as PaymentInsertType } from '../shared/bank.e_XSg9KV.cjs';
4
3
  import { WorkerEntrypoint } from 'cloudflare:workers';
5
4
  import { DrizzleD1Database } from 'drizzle-orm/d1';
6
- import { z } from 'zod';
5
+ import { P as PaymentSelectType, B as BatchSelectType, t as tables, a as PaymentInsertType } from '../shared/bank.e_XSg9KV.cjs';
7
6
  import { A as AccountSelectType, C as ConfigEnvironmentBank, I as IBankConnector, a as ConnectorKey } from '../shared/bank._5C74-4K.cjs';
7
+ import { z } from 'zod';
8
8
  import 'drizzle-orm/sqlite-core';
9
9
  import 'drizzle-orm';
10
10
  import '@develit-io/general-codes';
@@ -221,15 +221,43 @@ interface initiateConnectorOutput {
221
221
  }
222
222
 
223
223
  declare const getBatchesInputSchema: z.ZodObject<{
224
- limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
225
- offset: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
224
+ page: z.ZodNumber;
225
+ limit: z.ZodNumber;
226
+ sort: z.ZodObject<{
227
+ column: z.ZodEnum<{
228
+ createdAt: "createdAt";
229
+ updatedAt: "updatedAt";
230
+ batchPaymentInitiatedAt: "batchPaymentInitiatedAt";
231
+ }>;
232
+ direction: z.ZodEnum<{
233
+ asc: "asc";
234
+ desc: "desc";
235
+ }>;
236
+ }, z.core.$strip>;
237
+ filterBatchAccountId: z.ZodOptional<z.ZodUnion<readonly [z.ZodUUID, z.ZodArray<z.ZodUUID>]>>;
238
+ filterBatchStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
239
+ OPEN: "OPEN";
240
+ PROCESSING: "PROCESSING";
241
+ READY_TO_SIGN: "READY_TO_SIGN";
242
+ WAITING_FOR_PROCESSING: "WAITING_FOR_PROCESSING";
243
+ PREPARED: "PREPARED";
244
+ COMPLETED: "COMPLETED";
245
+ FAILED: "FAILED";
246
+ }>, z.ZodArray<z.ZodEnum<{
247
+ OPEN: "OPEN";
248
+ PROCESSING: "PROCESSING";
249
+ READY_TO_SIGN: "READY_TO_SIGN";
250
+ WAITING_FOR_PROCESSING: "WAITING_FOR_PROCESSING";
251
+ PREPARED: "PREPARED";
252
+ COMPLETED: "COMPLETED";
253
+ FAILED: "FAILED";
254
+ }>>]>>;
226
255
  }, z.core.$strip>;
227
- interface GetBatchesInput extends z.infer<typeof getBatchesInputSchema> {
228
- }
229
- interface GetBatchesOutput {
256
+ type GetBatchesInput = z.input<typeof getBatchesInputSchema>;
257
+ type GetBatchesOutput = {
230
258
  batches: BatchSelectType[];
231
259
  totalCount: number;
232
- }
260
+ };
233
261
 
234
262
  declare const processBatchInputSchema: z.ZodObject<{
235
263
  connectorKey: z.ZodEnum<{
@@ -1,10 +1,10 @@
1
1
  import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
2
2
  import { IRPCResponse } from '@develit-io/backend-sdk';
3
- import { P as PaymentSelectType, B as BatchSelectType, t as tables, a as PaymentInsertType } from '../shared/bank.e_XSg9KV.mjs';
4
3
  import { WorkerEntrypoint } from 'cloudflare:workers';
5
4
  import { DrizzleD1Database } from 'drizzle-orm/d1';
6
- import { z } from 'zod';
5
+ import { P as PaymentSelectType, B as BatchSelectType, t as tables, a as PaymentInsertType } from '../shared/bank.e_XSg9KV.mjs';
7
6
  import { A as AccountSelectType, C as ConfigEnvironmentBank, I as IBankConnector, a as ConnectorKey } from '../shared/bank.-qiBc98X.mjs';
7
+ import { z } from 'zod';
8
8
  import 'drizzle-orm/sqlite-core';
9
9
  import 'drizzle-orm';
10
10
  import '@develit-io/general-codes';
@@ -221,15 +221,43 @@ interface initiateConnectorOutput {
221
221
  }
222
222
 
223
223
  declare const getBatchesInputSchema: z.ZodObject<{
224
- limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
225
- offset: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
224
+ page: z.ZodNumber;
225
+ limit: z.ZodNumber;
226
+ sort: z.ZodObject<{
227
+ column: z.ZodEnum<{
228
+ createdAt: "createdAt";
229
+ updatedAt: "updatedAt";
230
+ batchPaymentInitiatedAt: "batchPaymentInitiatedAt";
231
+ }>;
232
+ direction: z.ZodEnum<{
233
+ asc: "asc";
234
+ desc: "desc";
235
+ }>;
236
+ }, z.core.$strip>;
237
+ filterBatchAccountId: z.ZodOptional<z.ZodUnion<readonly [z.ZodUUID, z.ZodArray<z.ZodUUID>]>>;
238
+ filterBatchStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
239
+ OPEN: "OPEN";
240
+ PROCESSING: "PROCESSING";
241
+ READY_TO_SIGN: "READY_TO_SIGN";
242
+ WAITING_FOR_PROCESSING: "WAITING_FOR_PROCESSING";
243
+ PREPARED: "PREPARED";
244
+ COMPLETED: "COMPLETED";
245
+ FAILED: "FAILED";
246
+ }>, z.ZodArray<z.ZodEnum<{
247
+ OPEN: "OPEN";
248
+ PROCESSING: "PROCESSING";
249
+ READY_TO_SIGN: "READY_TO_SIGN";
250
+ WAITING_FOR_PROCESSING: "WAITING_FOR_PROCESSING";
251
+ PREPARED: "PREPARED";
252
+ COMPLETED: "COMPLETED";
253
+ FAILED: "FAILED";
254
+ }>>]>>;
226
255
  }, z.core.$strip>;
227
- interface GetBatchesInput extends z.infer<typeof getBatchesInputSchema> {
228
- }
229
- interface GetBatchesOutput {
256
+ type GetBatchesInput = z.input<typeof getBatchesInputSchema>;
257
+ type GetBatchesOutput = {
230
258
  batches: BatchSelectType[];
231
259
  totalCount: number;
232
- }
260
+ };
233
261
 
234
262
  declare const processBatchInputSchema: z.ZodObject<{
235
263
  connectorKey: z.ZodEnum<{
@@ -1,10 +1,10 @@
1
1
  import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
2
2
  import { IRPCResponse } from '@develit-io/backend-sdk';
3
- import { P as PaymentSelectType, B as BatchSelectType, t as tables, a as PaymentInsertType } from '../shared/bank.e_XSg9KV.js';
4
3
  import { WorkerEntrypoint } from 'cloudflare:workers';
5
4
  import { DrizzleD1Database } from 'drizzle-orm/d1';
6
- import { z } from 'zod';
5
+ import { P as PaymentSelectType, B as BatchSelectType, t as tables, a as PaymentInsertType } from '../shared/bank.e_XSg9KV.js';
7
6
  import { A as AccountSelectType, C as ConfigEnvironmentBank, I as IBankConnector, a as ConnectorKey } from '../shared/bank.BRiDHyNf.js';
7
+ import { z } from 'zod';
8
8
  import 'drizzle-orm/sqlite-core';
9
9
  import 'drizzle-orm';
10
10
  import '@develit-io/general-codes';
@@ -221,15 +221,43 @@ interface initiateConnectorOutput {
221
221
  }
222
222
 
223
223
  declare const getBatchesInputSchema: z.ZodObject<{
224
- limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
225
- offset: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
224
+ page: z.ZodNumber;
225
+ limit: z.ZodNumber;
226
+ sort: z.ZodObject<{
227
+ column: z.ZodEnum<{
228
+ createdAt: "createdAt";
229
+ updatedAt: "updatedAt";
230
+ batchPaymentInitiatedAt: "batchPaymentInitiatedAt";
231
+ }>;
232
+ direction: z.ZodEnum<{
233
+ asc: "asc";
234
+ desc: "desc";
235
+ }>;
236
+ }, z.core.$strip>;
237
+ filterBatchAccountId: z.ZodOptional<z.ZodUnion<readonly [z.ZodUUID, z.ZodArray<z.ZodUUID>]>>;
238
+ filterBatchStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
239
+ OPEN: "OPEN";
240
+ PROCESSING: "PROCESSING";
241
+ READY_TO_SIGN: "READY_TO_SIGN";
242
+ WAITING_FOR_PROCESSING: "WAITING_FOR_PROCESSING";
243
+ PREPARED: "PREPARED";
244
+ COMPLETED: "COMPLETED";
245
+ FAILED: "FAILED";
246
+ }>, z.ZodArray<z.ZodEnum<{
247
+ OPEN: "OPEN";
248
+ PROCESSING: "PROCESSING";
249
+ READY_TO_SIGN: "READY_TO_SIGN";
250
+ WAITING_FOR_PROCESSING: "WAITING_FOR_PROCESSING";
251
+ PREPARED: "PREPARED";
252
+ COMPLETED: "COMPLETED";
253
+ FAILED: "FAILED";
254
+ }>>]>>;
226
255
  }, z.core.$strip>;
227
- interface GetBatchesInput extends z.infer<typeof getBatchesInputSchema> {
228
- }
229
- interface GetBatchesOutput {
256
+ type GetBatchesInput = z.input<typeof getBatchesInputSchema>;
257
+ type GetBatchesOutput = {
230
258
  batches: BatchSelectType[];
231
259
  totalCount: number;
232
- }
260
+ };
233
261
 
234
262
  declare const processBatchInputSchema: z.ZodObject<{
235
263
  connectorKey: z.ZodEnum<{
@@ -1,14 +1,14 @@
1
1
  import { uuidv4, develitWorker, createInternalError, first, RPCResponse, action, service } from '@develit-io/backend-sdk';
2
- import { t as tables, F as FinbricksConnector, M as MockConnector, E as ErsteConnector, P as PAYMENT_TYPES, e as CONNECTOR_KEYS, c as PAYMENT_STATUSES, d as PAYMENT_DIRECTIONS, q as getPaymentDirection } from '../shared/bank.uJ3YtInA.mjs';
3
2
  import { WorkerEntrypoint } from 'cloudflare:workers';
4
3
  import { drizzle } from 'drizzle-orm/d1';
5
- import { z } from 'zod';
6
- import { CURRENCY_CODES } from '@develit-io/general-codes';
4
+ import { t as tables, F as FinbricksConnector, M as MockConnector, E as ErsteConnector, P as PAYMENT_TYPES, e as CONNECTOR_KEYS, B as BATCH_STATUSES, c as PAYMENT_STATUSES, d as PAYMENT_DIRECTIONS, q as getPaymentDirection } from '../shared/bank.ClfukJ-T.mjs';
7
5
  import 'jose';
8
- import { eq, and, inArray, sql, asc, desc, gte, lte } from 'drizzle-orm';
9
- import { M as MockCobsConnector } from '../shared/bank.A5zjotaU.mjs';
10
- import 'drizzle-zod';
6
+ import { CURRENCY_CODES } from '@develit-io/general-codes';
7
+ import { z } from 'zod';
8
+ import { eq, inArray, and, sql, asc, desc, gte, lte } from 'drizzle-orm';
9
+ import { M as MockCobsConnector } from '../shared/bank.De_ddIjl.mjs';
11
10
  import 'drizzle-orm/sqlite-core';
11
+ import 'drizzle-zod';
12
12
  import 'date-fns';
13
13
  import 'drizzle-orm/relations';
14
14
 
@@ -107,52 +107,14 @@ const updateAccountLastSyncCommand = (db, { lastSyncedAt, accountId }) => {
107
107
  };
108
108
  };
109
109
 
110
- const getPaymentByRefIdQuery = async (db, { refId }) => {
111
- const payment = await db.select().from(tables.payment).where(eq(tables.payment.refId, refId)).limit(1).get();
112
- return payment;
113
- };
114
-
115
- const getOpenBatchByAccountIdQuery = async (db, { accountId }) => {
116
- const batch = await db.select().from(tables.batch).where(
117
- and(
118
- eq(tables.batch.accountId, accountId),
119
- eq(tables.batch.status, "OPEN")
120
- )
121
- ).limit(1).get();
122
- return batch;
123
- };
124
-
125
- const getPaymentsByBankRefIdsQuery = async (db, { ids }) => {
126
- return await db.select().from(tables.payment).where(inArray(tables.payment.bankRefId, ids));
127
- };
128
-
129
- const getOttQuery = async (db, { ott }) => {
130
- return await db.select().from(tables.ott).where(eq(tables.ott.oneTimeToken, ott)).get();
131
- };
132
-
133
- const getAllPendingBatchesQuery = (db) => {
134
- return db.select().from(tables.batch).where(
135
- inArray(tables.batch.status, [
136
- "PROCESSING",
137
- "READY_TO_SIGN",
138
- "WAITING_FOR_PROCESSING"
139
- ])
140
- );
110
+ const getAccountByIbanQuery = async (db, { iban }) => {
111
+ return await db.select().from(tables.account).where(eq(tables.account.iban, iban)).get();
141
112
  };
142
113
 
143
114
  const getAccountByIdQuery = async (db, { accountId }) => {
144
115
  return await db.select().from(tables.account).where(eq(tables.account.id, accountId)).get();
145
116
  };
146
117
 
147
- const getCredentialsByAccountId = async (db, { accountId }) => {
148
- const cred = await db.select().from(tables.accountCredentials).where(eq(tables.accountCredentials.accountId, accountId)).get();
149
- return cred;
150
- };
151
-
152
- const getAccountByIbanQuery = async (db, { iban }) => {
153
- return await db.select().from(tables.account).where(eq(tables.account.iban, iban)).get();
154
- };
155
-
156
118
  const getAllAccountsQuery = async (db) => {
157
119
  const accountsWithExpiration = await db.select().from(tables.account).leftJoin(
158
120
  tables.accountCredentials,
@@ -166,6 +128,16 @@ const getAllAccountsQuery = async (db) => {
166
128
  });
167
129
  };
168
130
 
131
+ const getAllPendingBatchesQuery = (db) => {
132
+ return db.select().from(tables.batch).where(
133
+ inArray(tables.batch.status, [
134
+ "PROCESSING",
135
+ "READY_TO_SIGN",
136
+ "WAITING_FOR_PROCESSING"
137
+ ])
138
+ );
139
+ };
140
+
169
141
  const buildMultiFilterConditions = (column, value) => {
170
142
  if (value === void 0) return void 0;
171
143
  if (Array.isArray(value)) {
@@ -230,6 +202,56 @@ const getPaymentsWithPaginationQuery = async (db, {
230
202
  };
231
203
  };
232
204
 
205
+ const getBatchesQuery = async (db, {
206
+ limit,
207
+ page,
208
+ sort,
209
+ filterBatchAccountId,
210
+ filterBatchStatus
211
+ }) => {
212
+ const whereConditions = and(
213
+ buildMultiFilterConditions(tables.batch.accountId, filterBatchAccountId),
214
+ buildMultiFilterConditions(tables.batch.status, filterBatchStatus)
215
+ );
216
+ const sortColumn = resolveColumn(tables.batch, sort.column);
217
+ const [{ totalCount }] = await db.select({
218
+ totalCount: sql`count(*)`
219
+ }).from(tables.batch).where(whereConditions);
220
+ const batches = await db.select().from(tables.batch).where(whereConditions).limit(limit).offset((page - 1) * limit).orderBy(sort.direction === "asc" ? asc(sortColumn) : desc(sortColumn));
221
+ return {
222
+ batches,
223
+ totalCount
224
+ };
225
+ };
226
+
227
+ const getCredentialsByAccountId = async (db, { accountId }) => {
228
+ const cred = await db.select().from(tables.accountCredentials).where(eq(tables.accountCredentials.accountId, accountId)).get();
229
+ return cred;
230
+ };
231
+
232
+ const getOpenBatchByAccountIdQuery = async (db, { accountId }) => {
233
+ const batch = await db.select().from(tables.batch).where(
234
+ and(
235
+ eq(tables.batch.accountId, accountId),
236
+ eq(tables.batch.status, "OPEN")
237
+ )
238
+ ).limit(1).get();
239
+ return batch;
240
+ };
241
+
242
+ const getOttQuery = async (db, { ott }) => {
243
+ return await db.select().from(tables.ott).where(eq(tables.ott.oneTimeToken, ott)).get();
244
+ };
245
+
246
+ const getPaymentByRefIdQuery = async (db, { refId }) => {
247
+ const payment = await db.select().from(tables.payment).where(eq(tables.payment.refId, refId)).limit(1).get();
248
+ return payment;
249
+ };
250
+
251
+ const getPaymentsByBankRefIdsQuery = async (db, { ids }) => {
252
+ return await db.select().from(tables.payment).where(inArray(tables.payment.bankRefId, ids));
253
+ };
254
+
233
255
  class CreditasConnector extends FinbricksConnector {
234
256
  constructor(config) {
235
257
  super("CREDITAS", config);
@@ -373,9 +395,19 @@ const initiateConnectorInputSchema = z.object({
373
395
  withAuth: z.boolean().default(true).optional()
374
396
  });
375
397
 
398
+ const ALLOWED_BATCH_FILTERS = {
399
+ ACCOUNT_ID: "filterBatchAccountId",
400
+ STATUS: "filterBatchStatus"
401
+ };
376
402
  const getBatchesInputSchema = z.object({
377
- limit: z.number().positive().optional().default(100),
378
- offset: z.number().min(0).optional().default(0)
403
+ page: z.number().positive(),
404
+ limit: z.number().positive(),
405
+ sort: z.object({
406
+ column: z.enum(["createdAt", "updatedAt", "batchPaymentInitiatedAt"]),
407
+ direction: z.enum(["asc", "desc"])
408
+ }),
409
+ [ALLOWED_BATCH_FILTERS.ACCOUNT_ID]: z.union([z.uuid(), z.uuid().array()]).optional(),
410
+ [ALLOWED_BATCH_FILTERS.STATUS]: z.union([z.enum(BATCH_STATUSES), z.enum(BATCH_STATUSES).array()]).optional()
379
411
  });
380
412
 
381
413
  const processBatchInputSchema = z.object({
@@ -1108,16 +1140,8 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
1108
1140
  return this.handleAction(
1109
1141
  { data: input, schema: getBatchesInputSchema },
1110
1142
  { successMessage: "Batches retrieved successfully" },
1111
- async ({ limit = 100, offset = 0 }) => {
1112
- const [batchesResult, countResult] = await Promise.all([
1113
- this.db.select().from(tables.batch).limit(limit).offset(offset).orderBy(desc(tables.batch.createdAt)),
1114
- this.db.select({ count: sql`count(*)`.as("count") }).from(tables.batch)
1115
- ]);
1116
- const totalCount = Number(countResult[0]?.count) || 0;
1117
- return {
1118
- batches: batchesResult,
1119
- totalCount
1120
- };
1143
+ async (params) => {
1144
+ return await getBatchesQuery(this.db, params);
1121
1145
  }
1122
1146
  );
1123
1147
  }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const database_schema = require('./bank.Dx7kRjFL.cjs');
3
+ const database_schema = require('./bank.D4BlThGx.cjs');
4
4
 
5
5
  class MockCobsConnector extends database_schema.FinbricksConnector {
6
6
  constructor(config) {
@@ -1,10 +1,10 @@
1
1
  import { uuidv4, useResult, createInternalError, bankAccount, base } from '@develit-io/backend-sdk';
2
+ import { sqliteTable, integer, text, unique, real } from 'drizzle-orm/sqlite-core';
2
3
  import { and, eq } from 'drizzle-orm';
3
4
  import { COUNTRY_CODES_2, CURRENCY_CODES } from '@develit-io/general-codes';
4
5
  import { z } from 'zod';
5
6
  import { importPKCS8, SignJWT } from 'jose';
6
7
  import { createInsertSchema, createUpdateSchema, createSelectSchema } from 'drizzle-zod';
7
- import { sqliteTable, integer, text, unique, real } from 'drizzle-orm/sqlite-core';
8
8
  import { format, parseISO } from 'date-fns';
9
9
  import { relations } from 'drizzle-orm/relations';
10
10
 
@@ -1106,7 +1106,7 @@ const batch = sqliteTable("batch", {
1106
1106
  mode: "timestamp_ms"
1107
1107
  }),
1108
1108
  authorizationUrls: text("authorization_urls", { mode: "json" }).$type(),
1109
- accountId: text("account_id"),
1109
+ accountId: text("account_id").references(() => account.id),
1110
1110
  status: text("status", { enum: BATCH_STATUSES }).$type(),
1111
1111
  payments: text("payments", { mode: "json" }).$type().notNull(),
1112
1112
  metadata: text("metadata", { mode: "json" }).$type()
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  const backendSdk = require('@develit-io/backend-sdk');
4
+ const sqliteCore = require('drizzle-orm/sqlite-core');
4
5
  const drizzleOrm = require('drizzle-orm');
5
6
  const generalCodes = require('@develit-io/general-codes');
6
7
  const zod = require('zod');
7
8
  const jose = require('jose');
8
9
  const drizzleZod = require('drizzle-zod');
9
- const sqliteCore = require('drizzle-orm/sqlite-core');
10
10
  const dateFns = require('date-fns');
11
11
  const relations = require('drizzle-orm/relations');
12
12
 
@@ -1108,7 +1108,7 @@ const batch = sqliteCore.sqliteTable("batch", {
1108
1108
  mode: "timestamp_ms"
1109
1109
  }),
1110
1110
  authorizationUrls: sqliteCore.text("authorization_urls", { mode: "json" }).$type(),
1111
- accountId: sqliteCore.text("account_id"),
1111
+ accountId: sqliteCore.text("account_id").references(() => account.id),
1112
1112
  status: sqliteCore.text("status", { enum: BATCH_STATUSES }).$type(),
1113
1113
  payments: sqliteCore.text("payments", { mode: "json" }).$type().notNull(),
1114
1114
  metadata: sqliteCore.text("metadata", { mode: "json" }).$type()
@@ -1,4 +1,4 @@
1
- import { F as FinbricksConnector } from './bank.uJ3YtInA.mjs';
1
+ import { F as FinbricksConnector } from './bank.ClfukJ-T.mjs';
2
2
 
3
3
  class MockCobsConnector extends FinbricksConnector {
4
4
  constructor(config) {
package/dist/types.cjs CHANGED
@@ -1,14 +1,14 @@
1
1
  'use strict';
2
2
 
3
- const database_schema = require('./shared/bank.Dx7kRjFL.cjs');
4
- const mockCobs_connector = require('./shared/bank.BiZtZWed.cjs');
3
+ const database_schema = require('./shared/bank.D4BlThGx.cjs');
4
+ const mockCobs_connector = require('./shared/bank.BVW0vOQS.cjs');
5
5
  const generalCodes = require('@develit-io/general-codes');
6
6
  require('@develit-io/backend-sdk');
7
+ require('drizzle-orm/sqlite-core');
7
8
  require('drizzle-orm');
8
9
  require('zod');
9
10
  require('jose');
10
11
  require('drizzle-zod');
11
- require('drizzle-orm/sqlite-core');
12
12
  require('date-fns');
13
13
  require('drizzle-orm/relations');
14
14
 
package/dist/types.mjs CHANGED
@@ -1,11 +1,11 @@
1
- export { A as ACCOUNT_STATUSES, B as BATCH_STATUES, B as BATCH_STATUSES, e as CONNECTOR_KEYS, C as COUNTRY_CODES, f as CREDENTIALS_TYPES, E as ErsteConnector, b as FINBRICKS_ENDPOINTS, a as FinbricksClient, F as FinbricksConnector, I as IBankConnector, M as MockConnector, d as PAYMENT_DIRECTIONS, c as PAYMENT_STATUSES, P as PAYMENT_TYPES, T as TOKEN_TYPES, j as accountCredentialsInsertSchema, l as accountCredentialsSelectSchema, k as accountCredentialsUpdateSchema, g as accountInsertSchema, i as accountSelectSchema, h as accountUpdateSchema, o as ottInsertSchema, n as ottSelectSchema, m as ottUpdateSchema, p as paymentInsertTypeZod, s as signFinbricksJws, u as useFinbricksFetch } from './shared/bank.uJ3YtInA.mjs';
2
- export { M as MockCobsConnector } from './shared/bank.A5zjotaU.mjs';
1
+ export { A as ACCOUNT_STATUSES, B as BATCH_STATUES, B as BATCH_STATUSES, e as CONNECTOR_KEYS, C as COUNTRY_CODES, f as CREDENTIALS_TYPES, E as ErsteConnector, b as FINBRICKS_ENDPOINTS, a as FinbricksClient, F as FinbricksConnector, I as IBankConnector, M as MockConnector, d as PAYMENT_DIRECTIONS, c as PAYMENT_STATUSES, P as PAYMENT_TYPES, T as TOKEN_TYPES, j as accountCredentialsInsertSchema, l as accountCredentialsSelectSchema, k as accountCredentialsUpdateSchema, g as accountInsertSchema, i as accountSelectSchema, h as accountUpdateSchema, o as ottInsertSchema, n as ottSelectSchema, m as ottUpdateSchema, p as paymentInsertTypeZod, s as signFinbricksJws, u as useFinbricksFetch } from './shared/bank.ClfukJ-T.mjs';
2
+ export { M as MockCobsConnector } from './shared/bank.De_ddIjl.mjs';
3
3
  export { BANK_CODES, CURRENCY_CODES } from '@develit-io/general-codes';
4
4
  import '@develit-io/backend-sdk';
5
+ import 'drizzle-orm/sqlite-core';
5
6
  import 'drizzle-orm';
6
7
  import 'zod';
7
8
  import 'jose';
8
9
  import 'drizzle-zod';
9
- import 'drizzle-orm/sqlite-core';
10
10
  import 'date-fns';
11
11
  import 'drizzle-orm/relations';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-services/bank",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "author": "Develit.io s.r.o.",
5
5
  "type": "module",
6
6
  "exports": {