@temboplus/tembo-dashboard 0.0.5 → 0.0.6

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.
@@ -133,6 +133,58 @@ export declare const CollectionDTOSchemas: {
133
133
  minAmount?: number | undefined;
134
134
  maxAmount?: number | undefined;
135
135
  }>;
136
+ collectionURLQueryParams: z.ZodObject<{
137
+ page: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
138
+ limit: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
139
+ sortBy: z.ZodDefault<z.ZodString>;
140
+ sortOrder: z.ZodDefault<z.ZodEnum<["asc", "desc"]>>;
141
+ startDate: z.ZodOptional<z.ZodString>;
142
+ endDate: z.ZodOptional<z.ZodString>;
143
+ msisdn: z.ZodOptional<z.ZodString>;
144
+ id: z.ZodOptional<z.ZodString>;
145
+ reference: z.ZodOptional<z.ZodString>;
146
+ accountNo: z.ZodOptional<z.ZodString>;
147
+ partnerReference: z.ZodOptional<z.ZodString>;
148
+ channel: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, COLLECTION_CHANNEL, string>>;
149
+ status: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, COLLECTION_STATUS, string>>;
150
+ minAmount: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
151
+ maxAmount: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
152
+ search: z.ZodOptional<z.ZodString>;
153
+ }, "strip", z.ZodTypeAny, {
154
+ sortBy: string;
155
+ sortOrder: "asc" | "desc";
156
+ status?: COLLECTION_STATUS | undefined;
157
+ startDate?: string | undefined;
158
+ endDate?: string | undefined;
159
+ page?: number | undefined;
160
+ limit?: number | undefined;
161
+ search?: string | undefined;
162
+ id?: string | undefined;
163
+ accountNo?: string | undefined;
164
+ msisdn?: string | undefined;
165
+ channel?: COLLECTION_CHANNEL | undefined;
166
+ reference?: string | undefined;
167
+ partnerReference?: string | undefined;
168
+ minAmount?: number | undefined;
169
+ maxAmount?: number | undefined;
170
+ }, {
171
+ status?: string | undefined;
172
+ startDate?: string | undefined;
173
+ endDate?: string | undefined;
174
+ page?: string | undefined;
175
+ limit?: string | undefined;
176
+ search?: string | undefined;
177
+ id?: string | undefined;
178
+ accountNo?: string | undefined;
179
+ msisdn?: string | undefined;
180
+ channel?: string | undefined;
181
+ reference?: string | undefined;
182
+ partnerReference?: string | undefined;
183
+ sortBy?: string | undefined;
184
+ sortOrder?: "asc" | "desc" | undefined;
185
+ minAmount?: string | undefined;
186
+ maxAmount?: string | undefined;
187
+ }>;
136
188
  pagination: z.ZodObject<{
137
189
  page: z.ZodNumber;
138
190
  limit: z.ZodNumber;
@@ -176,3 +228,4 @@ export declare const CollectionDTOSchemas: {
176
228
  };
177
229
  export type CollectionDTO = z.infer<typeof CollectionDTOSchemas.collection>;
178
230
  export type CollectionQueryParamsDTO = z.infer<typeof CollectionDTOSchemas.collectionQueryParams>;
231
+ export type CollectionURLQueryParamsDTO = z.infer<typeof CollectionDTOSchemas.collectionURLQueryParams>;
@@ -0,0 +1,91 @@
1
+ import { CollectionQueryParamsDTO } from "./collection.dtos";
2
+ /**
3
+ * Converts URL search parameters (string-based) to properly typed CollectionQueryParamsDTO.
4
+ *
5
+ * This function handles the conversion from URL search parameters (which are always strings)
6
+ * to the typed DTO used internally. It performs validation and type conversion for:
7
+ * - Numbers (page, limit, amounts)
8
+ * - Enums (status, channel)
9
+ * - Dates (startDate, endDate)
10
+ * - Optional string fields
11
+ *
12
+ * @param urlParams - Raw URL search parameters as key-value string pairs
13
+ * @returns Validated and typed CollectionQueryParamsDTO object
14
+ *
15
+ * @throws {ZodError} When URL parameters fail validation (invalid enum values, malformed numbers, etc.)
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const urlParams = {
20
+ * page: "1",
21
+ * limit: "20",
22
+ * status: "PAYMENT_ACCEPTED",
23
+ * minAmount: "100.50"
24
+ * };
25
+ *
26
+ * const queryParams = urlParamsToQueryParams(urlParams);
27
+ * // Result: { page: 1, limit: 20, status: COLLECTION_STATUS.PAYMENT_ACCEPTED, minAmount: 100.5 }
28
+ * ```
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * // Usage in API route
33
+ * export async function GET(req: NextRequest) {
34
+ * const searchParams = Object.fromEntries(req.nextUrl.searchParams.entries());
35
+ * const queryParams = urlParamsToQueryParams(searchParams);
36
+ * // Now you have properly typed parameters
37
+ * }
38
+ * ```
39
+ */
40
+ export declare function urlParamsToQueryParams(urlParams: Record<string, string>): CollectionQueryParamsDTO;
41
+ /**
42
+ * Converts typed CollectionQueryParamsDTO to URL-safe string parameters.
43
+ *
44
+ * This function transforms the typed DTO back into string-based key-value pairs
45
+ * suitable for URL search parameters or form submission. It:
46
+ * - Filters out undefined and null values
47
+ * - Converts all values to strings
48
+ * - Preserves the original parameter names
49
+ *
50
+ * @param queryParams - Typed collection query parameters
51
+ * @returns Object with string values suitable for URLSearchParams or query string construction
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const queryParams: CollectionQueryParamsDTO = {
56
+ * page: 1,
57
+ * limit: 20,
58
+ * status: COLLECTION_STATUS.PAYMENT_ACCEPTED,
59
+ * minAmount: 100.50,
60
+ * search: "test query"
61
+ * };
62
+ *
63
+ * const urlParams = queryParamsToURLParams(queryParams);
64
+ * // Result: {
65
+ * // page: "1",
66
+ * // limit: "20",
67
+ * // status: "PAYMENT_ACCEPTED",
68
+ * // minAmount: "100.5",
69
+ * // search: "test query"
70
+ * // }
71
+ * ```
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * // Usage with URLSearchParams
76
+ * const queryParams = { page: 1, limit: 20, status: COLLECTION_STATUS.PAYMENT_ACCEPTED };
77
+ * const urlParams = queryParamsToURLParams(queryParams);
78
+ * const searchParams = new URLSearchParams(urlParams);
79
+ * const queryString = searchParams.toString();
80
+ * // Result: "page=1&limit=20&status=PAYMENT_ACCEPTED"
81
+ * ```
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * // Usage in client-side API calls
86
+ * const filters = { status: COLLECTION_STATUS.PENDING_ACK, minAmount: 50 };
87
+ * const urlParams = queryParamsToURLParams(filters);
88
+ * const response = await fetch(`/api/collections?${new URLSearchParams(urlParams)}`);
89
+ * ```
90
+ */
91
+ export declare function queryParamsToURLParams(queryParams: CollectionQueryParamsDTO): Record<string, string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temboplus/tembo-dashboard",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "A foundational library for Temboplus-Dashboard projects providing type-safe data layer abstraction with API contracts, domain models, and repositories.",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",