@temboplus/afloat 0.1.77-beta.5 → 0.1.77-beta.7

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.
@@ -213,6 +213,7 @@ declare const PayoutFiltersSchema: z.ZodObject<{
213
213
  id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
214
214
  partnerReference: z.ZodOptional<z.ZodNullable<z.ZodString>>;
215
215
  channel: z.ZodOptional<z.ZodNullable<z.ZodString>>;
216
+ currencyCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
216
217
  status: z.ZodOptional<z.ZodNullable<z.ZodNativeEnum<typeof PayoutStatus>>>;
217
218
  approvalStatus: z.ZodOptional<z.ZodNullable<z.ZodNativeEnum<typeof PayoutApprovalStatus>>>;
218
219
  minAmount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
@@ -230,6 +231,7 @@ declare const PayoutFiltersSchema: z.ZodObject<{
230
231
  startDate?: string | null | undefined;
231
232
  endDate?: string | null | undefined;
232
233
  channel?: string | null | undefined;
234
+ currencyCode?: string | null | undefined;
233
235
  msisdn?: string | null | undefined;
234
236
  payeeName?: string | null | undefined;
235
237
  partnerReference?: string | null | undefined;
@@ -246,6 +248,7 @@ declare const PayoutFiltersSchema: z.ZodObject<{
246
248
  page?: number | undefined;
247
249
  limit?: number | undefined;
248
250
  channel?: string | null | undefined;
251
+ currencyCode?: string | null | undefined;
249
252
  msisdn?: string | null | undefined;
250
253
  payeeName?: string | null | undefined;
251
254
  partnerReference?: string | null | undefined;
@@ -494,6 +497,7 @@ export declare const PayoutDTOSchemas: {
494
497
  id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
495
498
  partnerReference: z.ZodOptional<z.ZodNullable<z.ZodString>>;
496
499
  channel: z.ZodOptional<z.ZodNullable<z.ZodString>>;
500
+ currencyCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
497
501
  status: z.ZodOptional<z.ZodNullable<z.ZodNativeEnum<typeof PayoutStatus>>>;
498
502
  approvalStatus: z.ZodOptional<z.ZodNullable<z.ZodNativeEnum<typeof PayoutApprovalStatus>>>;
499
503
  minAmount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
@@ -511,6 +515,7 @@ export declare const PayoutDTOSchemas: {
511
515
  startDate?: string | null | undefined;
512
516
  endDate?: string | null | undefined;
513
517
  channel?: string | null | undefined;
518
+ currencyCode?: string | null | undefined;
514
519
  msisdn?: string | null | undefined;
515
520
  payeeName?: string | null | undefined;
516
521
  partnerReference?: string | null | undefined;
@@ -527,6 +532,7 @@ export declare const PayoutDTOSchemas: {
527
532
  page?: number | undefined;
528
533
  limit?: number | undefined;
529
534
  channel?: string | null | undefined;
535
+ currencyCode?: string | null | undefined;
530
536
  msisdn?: string | null | undefined;
531
537
  payeeName?: string | null | undefined;
532
538
  partnerReference?: string | null | undefined;
@@ -47,6 +47,7 @@ export declare class PayoutQuery extends QueryBuilder {
47
47
  whereProfileId(profileId: string): this;
48
48
  wherePartnerReference(partnerReference: string): this;
49
49
  whereSearch(searchTerm: string): this;
50
+ whereCurrencyCode(currencyCode: string): this;
50
51
  /**
51
52
  * Apply all filters from PayoutFilters object
52
53
  */
@@ -0,0 +1,95 @@
1
+ import { QueryBuilder } from "@/lib/query/index.js";
2
+ import { WalletQueryDTO } from "./wallet.dtos.js";
3
+ /**
4
+ * Wallet-specific query builder that extends the base QueryBuilder
5
+ * and handles all possible input conversions (DTOs, URL params, etc.)
6
+ */
7
+ export declare class WalletQuery extends QueryBuilder {
8
+ /**
9
+ * Create empty wallet query with defaults
10
+ */
11
+ static create(): WalletQuery;
12
+ /**
13
+ * Create from typed DTO/filters object
14
+ */
15
+ static fromFilters(filters: WalletQueryDTO): WalletQuery;
16
+ /**
17
+ * Create from URL search parameters (strings)
18
+ */
19
+ static fromUrlParams(params: Record<string, string>): WalletQuery;
20
+ /**
21
+ * Create from URLSearchParams object
22
+ */
23
+ static fromSearchParams(searchParams: URLSearchParams): WalletQuery;
24
+ /**
25
+ * Create from Next.js Request object
26
+ */
27
+ static fromRequest(request: Request): WalletQuery;
28
+ /**
29
+ * Create from any supported input type
30
+ */
31
+ static from(input: QueryBuilder | WalletQueryDTO | Record<string, string> | URLSearchParams | null | undefined): WalletQuery;
32
+ /**
33
+ * Type guard for string records
34
+ */
35
+ private static isStringRecord;
36
+ whereId(id: string): this;
37
+ whereProfileId(profileId: string): this;
38
+ whereAccountNo(accountNo: string): this;
39
+ whereAccountName(accountName: string): this;
40
+ whereChannel(channel: string): this;
41
+ whereCountryCode(countryCode: string): this;
42
+ whereCurrencyCode(currencyCode: string): this;
43
+ /**
44
+ * Apply all filters from WalletQueryDTO object
45
+ */
46
+ private applyFilters;
47
+ /**
48
+ * Convert to WalletQueryDTO
49
+ */
50
+ toFilters(): WalletQueryDTO;
51
+ /**
52
+ * Convert to URL-safe string parameters
53
+ */
54
+ toUrlParams(): Record<string, string>;
55
+ /**
56
+ * Convert to URLSearchParams
57
+ */
58
+ toSearchParams(): URLSearchParams;
59
+ /**
60
+ * Convert to query string
61
+ */
62
+ toQueryString(): string;
63
+ /**
64
+ * Create new instance with wallet ID filter
65
+ */
66
+ withId(id: string): WalletQuery;
67
+ /**
68
+ * Create new instance with profile ID filter
69
+ */
70
+ withProfileId(profileId: string): WalletQuery;
71
+ /**
72
+ * Create new instance with account number filter
73
+ */
74
+ withAccountNo(accountNo: string): WalletQuery;
75
+ /**
76
+ * Create new instance with country code filter
77
+ */
78
+ withCountryCode(countryCode: string): WalletQuery;
79
+ /**
80
+ * Create new instance with currency code filter
81
+ */
82
+ withCurrencyCode(currencyCode: string): WalletQuery;
83
+ /**
84
+ * Check if any filters are applied
85
+ */
86
+ hasFilters(): boolean;
87
+ /**
88
+ * Get human-readable filter descriptions
89
+ */
90
+ getActiveFilters(): string[];
91
+ /**
92
+ * Extract filter values from QueryBuilder options
93
+ */
94
+ private extractFilterValues;
95
+ }
@@ -1,10 +1,14 @@
1
1
  import { Amount } from "@temboplus/frontend-core";
2
2
  import { WalletStatementEntry } from "./statement-entry.model.js";
3
3
  import { Wallet } from "./wallet.model.js";
4
- import { WalletDTOSchemas } from "./wallet.dtos.js";
5
- import { z } from "zod";
6
4
  import { contract } from "./wallet.contract.js";
7
5
  import { BaseRepository } from "@/lib/api/base-repository.js";
6
+ import { WalletQuery } from "./wallet.query.js";
7
+ import { WalletQueryDTO } from "./wallet.dtos.js";
8
+ /**
9
+ * Flexible query input type - supports the class, filters interface, URL params, etc.
10
+ */
11
+ export type WalletQueryInput = WalletQuery | WalletQueryDTO | Record<string, string> | URLSearchParams | null | undefined;
8
12
  /**
9
13
  * Repository class for managing wallet operations including balance checking,
10
14
  * statement generation, and wallet information retrieval.
@@ -87,13 +91,9 @@ export declare class WalletRepository extends BaseRepository<typeof contract> {
87
91
  /**
88
92
  * Retrieves all wallets associated with the authenticated user.
89
93
  *
90
- * Supports optional filtering through query parameters such as accountNo,
91
- * status, or currency filtering.
94
+ * Supports flexible filtering through WalletQuery or plain filter objects.
92
95
  *
93
96
  * @param query - Optional query parameters for filtering wallets
94
- * @param query.accountNo - Filter by specific account number
95
- * @param query.status - Filter by wallet status (active, inactive, etc.)
96
- * @param query.currencyCode - Filter by currency code
97
97
  * @returns Promise that resolves to an array of validated Wallet instances
98
98
  * @throws {Error} If the wallet fetch operation fails or data is invalid
99
99
  *
@@ -105,14 +105,38 @@ export declare class WalletRepository extends BaseRepository<typeof contract> {
105
105
  * // Get specific wallet by account number
106
106
  * const specificWallet = await repo.getWallets({ accountNo: '123456789' });
107
107
  *
108
- * // Get wallets with multiple filters
109
- * const activeUSDWallets = await repo.getWallets({
110
- * status: 'active',
111
- * currencyCode: 'USD'
112
- * });
108
+ * // Get wallets with multiple filters using WalletQuery
109
+ * const query = WalletQuery.create()
110
+ * .whereCountryCode('TZ')
111
+ * .whereCurrencyCode('TZS');
112
+ * const tzWallets = await repo.getWallets(query);
113
+ *
114
+ * // Get wallets with filters object
115
+ * const usdWallets = await repo.getWallets({ currencyCode: 'USD' });
113
116
  * ```
114
117
  */
115
- getWallets(query?: z.infer<typeof WalletDTOSchemas.walletQuery>): Promise<Wallet[]>;
118
+ getWallets(query?: WalletQueryInput): Promise<Wallet[]>;
119
+ /**
120
+ * Retrieves a single wallet by its ID.
121
+ *
122
+ * Since the API doesn't have a dedicated /id endpoint, this method queries
123
+ * the list endpoint with the ID filter and returns the first result.
124
+ *
125
+ * @param id - The unique identifier of the wallet to retrieve
126
+ * @returns Promise that resolves to the wallet if found, undefined otherwise
127
+ * @throws {Error} If the fetch operation fails
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * const wallet = await repo.getByID("wallet-id");
132
+ * if (wallet) {
133
+ * console.log(`Wallet: ${wallet.accountName}`);
134
+ * } else {
135
+ * console.log('Wallet not found');
136
+ * }
137
+ * ```
138
+ */
139
+ getByID(id: string): Promise<Wallet | undefined>;
116
140
  /**
117
141
  * Retrieves wallet statement entries for a specified date range.
118
142
  *
@@ -170,4 +194,12 @@ export declare class WalletRepository extends BaseRepository<typeof contract> {
170
194
  wallet?: Wallet;
171
195
  accountNo?: string;
172
196
  }): Promise<WalletStatementEntry[]>;
197
+ /**
198
+ * Check if a wallet exists with the given query
199
+ */
200
+ exists(query?: WalletQueryInput): Promise<boolean>;
201
+ /**
202
+ * Get count of wallets matching a query
203
+ */
204
+ count(query?: WalletQueryInput): Promise<number>;
173
205
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temboplus/afloat",
3
- "version": "0.1.77-beta.5",
3
+ "version": "0.1.77-beta.7",
4
4
  "description": "A foundational library for Temboplus-Afloat projects.",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",