shopoflex-types 1.0.56 → 1.0.59
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.
- package/dist/common.d.ts +4 -4
- package/dist/filters.d.ts +246 -0
- package/dist/filters.js +318 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/package.json +1 -1
package/dist/common.d.ts
CHANGED
|
@@ -595,12 +595,12 @@ export interface PaginationOptions {
|
|
|
595
595
|
export interface PaginatedResponse<T> {
|
|
596
596
|
data: T[];
|
|
597
597
|
pagination: {
|
|
598
|
-
|
|
599
|
-
|
|
598
|
+
page: number;
|
|
599
|
+
limit: number;
|
|
600
600
|
totalItems: number;
|
|
601
|
+
totalPages: number;
|
|
601
602
|
hasNextPage: boolean;
|
|
602
603
|
hasPrevPage: boolean;
|
|
603
|
-
limit: number;
|
|
604
604
|
};
|
|
605
605
|
filters?: Record<string, any>;
|
|
606
606
|
sort?: {
|
|
@@ -627,7 +627,7 @@ export interface SearchConfig {
|
|
|
627
627
|
export interface successResponse {
|
|
628
628
|
data: any[];
|
|
629
629
|
totalPages: number;
|
|
630
|
-
|
|
630
|
+
page: number;
|
|
631
631
|
count: number;
|
|
632
632
|
hasNextPage: boolean;
|
|
633
633
|
hasPrevPage: boolean;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
export interface BaseFilters {
|
|
2
|
+
search?: string;
|
|
3
|
+
page?: number;
|
|
4
|
+
limit?: number;
|
|
5
|
+
sortBy?: string;
|
|
6
|
+
sortOrder?: 'asc' | 'desc';
|
|
7
|
+
}
|
|
8
|
+
export interface ProductFilters extends BaseFilters {
|
|
9
|
+
isActive?: boolean;
|
|
10
|
+
hasVariants?: boolean;
|
|
11
|
+
hasModifiers?: boolean;
|
|
12
|
+
featured?: boolean;
|
|
13
|
+
vendorId?: string;
|
|
14
|
+
categoriesIds?: string | string[];
|
|
15
|
+
branchesIds?: string | string[];
|
|
16
|
+
tags?: string | string[];
|
|
17
|
+
inStock?: boolean;
|
|
18
|
+
minStock?: number;
|
|
19
|
+
maxStock?: number;
|
|
20
|
+
exactStock?: number;
|
|
21
|
+
branchId?: string;
|
|
22
|
+
variantPrice?: number;
|
|
23
|
+
minPrice?: number;
|
|
24
|
+
maxPrice?: number;
|
|
25
|
+
priceRange?: [number, number] | string;
|
|
26
|
+
costRange?: [number, number] | string;
|
|
27
|
+
discountedPriceRange?: [number, number] | string;
|
|
28
|
+
variantColor?: string;
|
|
29
|
+
variantSize?: string;
|
|
30
|
+
variantMaterial?: string;
|
|
31
|
+
variantAttribute?: string;
|
|
32
|
+
variantAttributeValue?: string;
|
|
33
|
+
variantIndex?: number;
|
|
34
|
+
variantSku?: string;
|
|
35
|
+
variantBarcode?: string;
|
|
36
|
+
hasBarcode?: boolean;
|
|
37
|
+
hasVariantFiles?: boolean;
|
|
38
|
+
variantActive?: boolean;
|
|
39
|
+
allowDecimal?: boolean;
|
|
40
|
+
unit?: string;
|
|
41
|
+
stockBehavior?: 'showOutOfStock' | 'allowOrdering' | 'hideFromStore';
|
|
42
|
+
dateRange?: [Date, Date] | [string, string] | string;
|
|
43
|
+
anyVariantPrice?: number;
|
|
44
|
+
anyVariantMinStock?: number;
|
|
45
|
+
minQuantityRange?: [number, number] | string;
|
|
46
|
+
}
|
|
47
|
+
export interface OrderFilters extends BaseFilters {
|
|
48
|
+
status?: 'pending' | 'confirmed' | 'preparing' | 'ready' | 'delivered' | 'cancelled' | 'completed' | string;
|
|
49
|
+
paid?: boolean;
|
|
50
|
+
vendorId?: string;
|
|
51
|
+
customerId?: string;
|
|
52
|
+
branchId?: string;
|
|
53
|
+
paymentMethod?: 'cash' | 'card' | 'transfer' | 'wallet' | 'cod' | string;
|
|
54
|
+
orderNumber?: string;
|
|
55
|
+
customerPhone?: string;
|
|
56
|
+
customerDialCode?: string;
|
|
57
|
+
amountRange?: [number, number] | string;
|
|
58
|
+
cartItemCount?: number;
|
|
59
|
+
minCartItems?: number;
|
|
60
|
+
dateRange?: [Date, Date] | [string, string] | string;
|
|
61
|
+
today?: boolean;
|
|
62
|
+
yesterday?: boolean;
|
|
63
|
+
thisWeek?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface CustomerFilters extends BaseFilters {
|
|
66
|
+
isAnonymos?: boolean;
|
|
67
|
+
vendors?: string | string[];
|
|
68
|
+
hasAddresses?: boolean;
|
|
69
|
+
uid?: string;
|
|
70
|
+
phoneNumber?: string;
|
|
71
|
+
fullPhone?: string;
|
|
72
|
+
phoneDialCode?: string;
|
|
73
|
+
registeredAfter?: Date | string;
|
|
74
|
+
registeredBefore?: Date | string;
|
|
75
|
+
}
|
|
76
|
+
export interface DiscountFilters extends BaseFilters {
|
|
77
|
+
status?: 'active' | 'paused' | 'expired' | 'exhausted' | string;
|
|
78
|
+
type?: 'fixed' | 'percentage' | string;
|
|
79
|
+
vendorId?: string;
|
|
80
|
+
isAutomatic?: boolean;
|
|
81
|
+
combinable?: boolean;
|
|
82
|
+
firstTimeUsersOnly?: boolean;
|
|
83
|
+
discountCategory?: string;
|
|
84
|
+
valueRange?: [number, number] | string;
|
|
85
|
+
startDateRange?: [Date, Date] | [string, string] | string;
|
|
86
|
+
endDateRange?: [Date, Date] | [string, string] | string;
|
|
87
|
+
activeNow?: boolean;
|
|
88
|
+
expired?: boolean;
|
|
89
|
+
expiringSoon?: boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parse URL query string back to filter object
|
|
93
|
+
* @param queryString - URL query string
|
|
94
|
+
* @returns Parsed filter object
|
|
95
|
+
*/
|
|
96
|
+
export declare const parseQuery: (queryString: string) => Record<string, any>;
|
|
97
|
+
/**
|
|
98
|
+
* Validate and clean filter object
|
|
99
|
+
* Removes undefined/null values and validates types
|
|
100
|
+
*/
|
|
101
|
+
export declare const cleanFilters: <T extends Record<string, any>>(filters: T) => Partial<T>;
|
|
102
|
+
/**
|
|
103
|
+
* Merge multiple filter objects
|
|
104
|
+
* Later objects override earlier ones
|
|
105
|
+
*/
|
|
106
|
+
export declare const mergeFilters: <T extends Record<string, any>>(...filterObjects: Partial<T>[]) => Partial<T>;
|
|
107
|
+
/**
|
|
108
|
+
* Build query string for any filter object
|
|
109
|
+
* @param filters - Any filter object
|
|
110
|
+
* @returns URL query string
|
|
111
|
+
*/
|
|
112
|
+
export declare const buildQuery: (filters: Record<string, any>) => string;
|
|
113
|
+
/**
|
|
114
|
+
* Build query string for product filtering
|
|
115
|
+
* @param filters - Typed product filter object
|
|
116
|
+
* @returns URL query string
|
|
117
|
+
*/
|
|
118
|
+
export declare const buildProductQuery: (filters: ProductFilters) => string;
|
|
119
|
+
/**
|
|
120
|
+
* Build query string for order filtering
|
|
121
|
+
* @param filters - Typed order filter object
|
|
122
|
+
* @returns URL query string
|
|
123
|
+
*/
|
|
124
|
+
export declare const buildOrderQuery: (filters: OrderFilters) => string;
|
|
125
|
+
/**
|
|
126
|
+
* Build query string for customer filtering
|
|
127
|
+
* @param filters - Typed customer filter object
|
|
128
|
+
* @returns URL query string
|
|
129
|
+
*/
|
|
130
|
+
export declare const buildCustomerQuery: (filters: CustomerFilters) => string;
|
|
131
|
+
/**
|
|
132
|
+
* Build query string for discount filtering
|
|
133
|
+
* @param filters - Typed discount filter object
|
|
134
|
+
* @returns URL query string
|
|
135
|
+
*/
|
|
136
|
+
export declare const buildDiscountQuery: (filters: DiscountFilters) => string;
|
|
137
|
+
/**
|
|
138
|
+
* Create a complete API URL with typed filters
|
|
139
|
+
* @param baseUrl - Base API URL
|
|
140
|
+
* @param filters - Typed filter object
|
|
141
|
+
* @returns Complete URL with query string
|
|
142
|
+
*/
|
|
143
|
+
export declare const buildUrl: (baseUrl: string, filters: Record<string, any>) => string;
|
|
144
|
+
/**
|
|
145
|
+
* Create product API URL
|
|
146
|
+
* @param baseUrl - Base API URL
|
|
147
|
+
* @param filters - Product filters
|
|
148
|
+
* @returns Complete URL
|
|
149
|
+
*/
|
|
150
|
+
export declare const buildProductUrl: (baseUrl: string, filters: ProductFilters) => string;
|
|
151
|
+
/**
|
|
152
|
+
* Create order API URL
|
|
153
|
+
* @param baseUrl - Base API URL
|
|
154
|
+
* @param filters - Order filters
|
|
155
|
+
* @returns Complete URL
|
|
156
|
+
*/
|
|
157
|
+
export declare const buildOrderUrl: (baseUrl: string, filters: OrderFilters) => string;
|
|
158
|
+
/**
|
|
159
|
+
* Create customer API URL
|
|
160
|
+
* @param baseUrl - Base API URL
|
|
161
|
+
* @param filters - Customer filters
|
|
162
|
+
* @returns Complete URL
|
|
163
|
+
*/
|
|
164
|
+
export declare const buildCustomerUrl: (baseUrl: string, filters: CustomerFilters) => string;
|
|
165
|
+
/**
|
|
166
|
+
* Create discount API URL
|
|
167
|
+
* @param baseUrl - Base API URL
|
|
168
|
+
* @param filters - Discount filters
|
|
169
|
+
* @returns Complete URL
|
|
170
|
+
*/
|
|
171
|
+
export declare const buildDiscountUrl: (baseUrl: string, filters: DiscountFilters) => string;
|
|
172
|
+
export declare const QueryBuilder: {
|
|
173
|
+
readonly build: (filters: Record<string, any>) => string;
|
|
174
|
+
readonly buildProduct: (filters: ProductFilters) => string;
|
|
175
|
+
readonly buildOrder: (filters: OrderFilters) => string;
|
|
176
|
+
readonly buildCustomer: (filters: CustomerFilters) => string;
|
|
177
|
+
readonly buildDiscount: (filters: DiscountFilters) => string;
|
|
178
|
+
readonly parse: (queryString: string) => Record<string, any>;
|
|
179
|
+
};
|
|
180
|
+
export declare const UrlBuilder: {
|
|
181
|
+
readonly build: (baseUrl: string, filters: Record<string, any>) => string;
|
|
182
|
+
readonly buildProduct: (baseUrl: string, filters: ProductFilters) => string;
|
|
183
|
+
readonly buildOrder: (baseUrl: string, filters: OrderFilters) => string;
|
|
184
|
+
readonly buildCustomer: (baseUrl: string, filters: CustomerFilters) => string;
|
|
185
|
+
readonly buildDiscount: (baseUrl: string, filters: DiscountFilters) => string;
|
|
186
|
+
};
|
|
187
|
+
export declare const FilterUtils: {
|
|
188
|
+
readonly clean: <T extends Record<string, any>>(filters: T) => Partial<T>;
|
|
189
|
+
readonly merge: <T extends Record<string, any>>(...filterObjects: Partial<T>[]) => Partial<T>;
|
|
190
|
+
};
|
|
191
|
+
export declare const FilterAPI: {
|
|
192
|
+
readonly QueryBuilder: {
|
|
193
|
+
readonly build: (filters: Record<string, any>) => string;
|
|
194
|
+
readonly buildProduct: (filters: ProductFilters) => string;
|
|
195
|
+
readonly buildOrder: (filters: OrderFilters) => string;
|
|
196
|
+
readonly buildCustomer: (filters: CustomerFilters) => string;
|
|
197
|
+
readonly buildDiscount: (filters: DiscountFilters) => string;
|
|
198
|
+
readonly parse: (queryString: string) => Record<string, any>;
|
|
199
|
+
};
|
|
200
|
+
readonly UrlBuilder: {
|
|
201
|
+
readonly build: (baseUrl: string, filters: Record<string, any>) => string;
|
|
202
|
+
readonly buildProduct: (baseUrl: string, filters: ProductFilters) => string;
|
|
203
|
+
readonly buildOrder: (baseUrl: string, filters: OrderFilters) => string;
|
|
204
|
+
readonly buildCustomer: (baseUrl: string, filters: CustomerFilters) => string;
|
|
205
|
+
readonly buildDiscount: (baseUrl: string, filters: DiscountFilters) => string;
|
|
206
|
+
};
|
|
207
|
+
readonly FilterUtils: {
|
|
208
|
+
readonly clean: <T extends Record<string, any>>(filters: T) => Partial<T>;
|
|
209
|
+
readonly merge: <T extends Record<string, any>>(...filterObjects: Partial<T>[]) => Partial<T>;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
declare const _default: {
|
|
213
|
+
buildQuery: (filters: Record<string, any>) => string;
|
|
214
|
+
buildProductQuery: (filters: ProductFilters) => string;
|
|
215
|
+
buildOrderQuery: (filters: OrderFilters) => string;
|
|
216
|
+
buildCustomerQuery: (filters: CustomerFilters) => string;
|
|
217
|
+
buildDiscountQuery: (filters: DiscountFilters) => string;
|
|
218
|
+
buildUrl: (baseUrl: string, filters: Record<string, any>) => string;
|
|
219
|
+
buildProductUrl: (baseUrl: string, filters: ProductFilters) => string;
|
|
220
|
+
buildOrderUrl: (baseUrl: string, filters: OrderFilters) => string;
|
|
221
|
+
buildCustomerUrl: (baseUrl: string, filters: CustomerFilters) => string;
|
|
222
|
+
buildDiscountUrl: (baseUrl: string, filters: DiscountFilters) => string;
|
|
223
|
+
parseQuery: (queryString: string) => Record<string, any>;
|
|
224
|
+
cleanFilters: <T extends Record<string, any>>(filters: T) => Partial<T>;
|
|
225
|
+
mergeFilters: <T extends Record<string, any>>(...filterObjects: Partial<T>[]) => Partial<T>;
|
|
226
|
+
QueryBuilder: {
|
|
227
|
+
readonly build: (filters: Record<string, any>) => string;
|
|
228
|
+
readonly buildProduct: (filters: ProductFilters) => string;
|
|
229
|
+
readonly buildOrder: (filters: OrderFilters) => string;
|
|
230
|
+
readonly buildCustomer: (filters: CustomerFilters) => string;
|
|
231
|
+
readonly buildDiscount: (filters: DiscountFilters) => string;
|
|
232
|
+
readonly parse: (queryString: string) => Record<string, any>;
|
|
233
|
+
};
|
|
234
|
+
UrlBuilder: {
|
|
235
|
+
readonly build: (baseUrl: string, filters: Record<string, any>) => string;
|
|
236
|
+
readonly buildProduct: (baseUrl: string, filters: ProductFilters) => string;
|
|
237
|
+
readonly buildOrder: (baseUrl: string, filters: OrderFilters) => string;
|
|
238
|
+
readonly buildCustomer: (baseUrl: string, filters: CustomerFilters) => string;
|
|
239
|
+
readonly buildDiscount: (baseUrl: string, filters: DiscountFilters) => string;
|
|
240
|
+
};
|
|
241
|
+
FilterUtils: {
|
|
242
|
+
readonly clean: <T extends Record<string, any>>(filters: T) => Partial<T>;
|
|
243
|
+
readonly merge: <T extends Record<string, any>>(...filterObjects: Partial<T>[]) => Partial<T>;
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
export default _default;
|
package/dist/filters.js
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// =====================================================
|
|
3
|
+
// TYPE DEFINITIONS
|
|
4
|
+
// =====================================================
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FilterAPI = exports.FilterUtils = exports.UrlBuilder = exports.QueryBuilder = exports.buildDiscountUrl = exports.buildCustomerUrl = exports.buildOrderUrl = exports.buildProductUrl = exports.buildUrl = exports.buildDiscountQuery = exports.buildCustomerQuery = exports.buildOrderQuery = exports.buildProductQuery = exports.buildQuery = exports.mergeFilters = exports.cleanFilters = exports.parseQuery = void 0;
|
|
7
|
+
// =====================================================
|
|
8
|
+
// CORE UTILITIES
|
|
9
|
+
// =====================================================
|
|
10
|
+
/**
|
|
11
|
+
* Converts filter object to URL query string
|
|
12
|
+
* Handles arrays, dates, and nested values automatically
|
|
13
|
+
*/
|
|
14
|
+
const buildQueryString = (filters) => {
|
|
15
|
+
const parts = [];
|
|
16
|
+
Object.entries(filters).forEach(([key, value]) => {
|
|
17
|
+
if (value === undefined || value === null || value === '')
|
|
18
|
+
return;
|
|
19
|
+
// Handle arrays (convert to comma-separated string)
|
|
20
|
+
if (Array.isArray(value)) {
|
|
21
|
+
if (value.length === 2 && (key.includes('Range') || key.includes('range'))) {
|
|
22
|
+
// Range values like [min, max] or [startDate, endDate]
|
|
23
|
+
const rangeString = value.map(v => v instanceof Date ? v.toISOString().split('T')[0] : v).join(',');
|
|
24
|
+
parts.push(`${key}=${rangeString}`);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// Regular arrays like tags, categories
|
|
28
|
+
parts.push(`${key}=${value.join(',')}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Handle dates
|
|
32
|
+
else if (value instanceof Date) {
|
|
33
|
+
parts.push(`${key}=${value.toISOString().split('T')[0]}`);
|
|
34
|
+
}
|
|
35
|
+
// Handle primitives
|
|
36
|
+
else {
|
|
37
|
+
parts.push(`${key}=${value}`);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return parts.join('&');
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Parse URL query string back to filter object
|
|
44
|
+
* @param queryString - URL query string
|
|
45
|
+
* @returns Parsed filter object
|
|
46
|
+
*/
|
|
47
|
+
const parseQuery = (queryString) => {
|
|
48
|
+
const result = {};
|
|
49
|
+
if (!queryString)
|
|
50
|
+
return result;
|
|
51
|
+
// Remove leading ? if present
|
|
52
|
+
const cleanQuery = queryString.startsWith('?') ? queryString.slice(1) : queryString;
|
|
53
|
+
// Split by & to get key=value pairs
|
|
54
|
+
const pairs = cleanQuery.split('&');
|
|
55
|
+
pairs.forEach(pair => {
|
|
56
|
+
const [key, value] = pair.split('=');
|
|
57
|
+
if (!key || value === undefined)
|
|
58
|
+
return;
|
|
59
|
+
// Handle comma-separated values
|
|
60
|
+
if (value.includes(',')) {
|
|
61
|
+
const parts = value.split(',');
|
|
62
|
+
// Check if it's a range (2 items) or array (multiple items)
|
|
63
|
+
if (parts.length === 2 && (key.includes('Range') || key.includes('range'))) {
|
|
64
|
+
// Try to parse as numbers for ranges
|
|
65
|
+
const [first, second] = parts;
|
|
66
|
+
const firstNum = parseFloat(first);
|
|
67
|
+
const secondNum = parseFloat(second);
|
|
68
|
+
if (!isNaN(firstNum) && !isNaN(secondNum)) {
|
|
69
|
+
result[key] = [firstNum, secondNum];
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Date range or string range
|
|
73
|
+
result[key] = parts;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// Regular array
|
|
78
|
+
result[key] = parts;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Handle boolean strings
|
|
82
|
+
else if (value === 'true' || value === 'false') {
|
|
83
|
+
result[key] = value === 'true';
|
|
84
|
+
}
|
|
85
|
+
// Handle numbers
|
|
86
|
+
else if (!isNaN(Number(value)) && value !== '') {
|
|
87
|
+
result[key] = Number(value);
|
|
88
|
+
}
|
|
89
|
+
// Handle strings
|
|
90
|
+
else {
|
|
91
|
+
result[key] = value;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return result;
|
|
95
|
+
};
|
|
96
|
+
exports.parseQuery = parseQuery;
|
|
97
|
+
/**
|
|
98
|
+
* Validate and clean filter object
|
|
99
|
+
* Removes undefined/null values and validates types
|
|
100
|
+
*/
|
|
101
|
+
const cleanFilters = (filters) => {
|
|
102
|
+
const cleaned = {};
|
|
103
|
+
Object.entries(filters).forEach(([key, value]) => {
|
|
104
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
105
|
+
// Handle arrays - remove empty values
|
|
106
|
+
if (Array.isArray(value)) {
|
|
107
|
+
const cleanedArray = value.filter(v => v !== undefined && v !== null && v !== '');
|
|
108
|
+
if (cleanedArray.length > 0) {
|
|
109
|
+
cleaned[key] = cleanedArray;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
cleaned[key] = value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return cleaned;
|
|
118
|
+
};
|
|
119
|
+
exports.cleanFilters = cleanFilters;
|
|
120
|
+
/**
|
|
121
|
+
* Merge multiple filter objects
|
|
122
|
+
* Later objects override earlier ones
|
|
123
|
+
*/
|
|
124
|
+
const mergeFilters = (...filterObjects) => {
|
|
125
|
+
return Object.assign({}, ...filterObjects.map(exports.cleanFilters));
|
|
126
|
+
};
|
|
127
|
+
exports.mergeFilters = mergeFilters;
|
|
128
|
+
// =====================================================
|
|
129
|
+
// QUERY BUILDERS - Main Functions
|
|
130
|
+
// =====================================================
|
|
131
|
+
/**
|
|
132
|
+
* Build query string for any filter object
|
|
133
|
+
* @param filters - Any filter object
|
|
134
|
+
* @returns URL query string
|
|
135
|
+
*/
|
|
136
|
+
const buildQuery = (filters) => {
|
|
137
|
+
return buildQueryString(filters);
|
|
138
|
+
};
|
|
139
|
+
exports.buildQuery = buildQuery;
|
|
140
|
+
/**
|
|
141
|
+
* Build query string for product filtering
|
|
142
|
+
* @param filters - Typed product filter object
|
|
143
|
+
* @returns URL query string
|
|
144
|
+
*/
|
|
145
|
+
const buildProductQuery = (filters) => {
|
|
146
|
+
return buildQueryString(filters);
|
|
147
|
+
};
|
|
148
|
+
exports.buildProductQuery = buildProductQuery;
|
|
149
|
+
/**
|
|
150
|
+
* Build query string for order filtering
|
|
151
|
+
* @param filters - Typed order filter object
|
|
152
|
+
* @returns URL query string
|
|
153
|
+
*/
|
|
154
|
+
const buildOrderQuery = (filters) => {
|
|
155
|
+
return buildQueryString(filters);
|
|
156
|
+
};
|
|
157
|
+
exports.buildOrderQuery = buildOrderQuery;
|
|
158
|
+
/**
|
|
159
|
+
* Build query string for customer filtering
|
|
160
|
+
* @param filters - Typed customer filter object
|
|
161
|
+
* @returns URL query string
|
|
162
|
+
*/
|
|
163
|
+
const buildCustomerQuery = (filters) => {
|
|
164
|
+
return buildQueryString(filters);
|
|
165
|
+
};
|
|
166
|
+
exports.buildCustomerQuery = buildCustomerQuery;
|
|
167
|
+
/**
|
|
168
|
+
* Build query string for discount filtering
|
|
169
|
+
* @param filters - Typed discount filter object
|
|
170
|
+
* @returns URL query string
|
|
171
|
+
*/
|
|
172
|
+
const buildDiscountQuery = (filters) => {
|
|
173
|
+
return buildQueryString(filters);
|
|
174
|
+
};
|
|
175
|
+
exports.buildDiscountQuery = buildDiscountQuery;
|
|
176
|
+
// =====================================================
|
|
177
|
+
// URL BUILDERS - Convenience Functions
|
|
178
|
+
// =====================================================
|
|
179
|
+
/**
|
|
180
|
+
* Create a complete API URL with typed filters
|
|
181
|
+
* @param baseUrl - Base API URL
|
|
182
|
+
* @param filters - Typed filter object
|
|
183
|
+
* @returns Complete URL with query string
|
|
184
|
+
*/
|
|
185
|
+
const buildUrl = (baseUrl, filters) => {
|
|
186
|
+
const queryString = (0, exports.buildQuery)(filters);
|
|
187
|
+
return queryString ? `${baseUrl}?${queryString}` : baseUrl;
|
|
188
|
+
};
|
|
189
|
+
exports.buildUrl = buildUrl;
|
|
190
|
+
/**
|
|
191
|
+
* Create product API URL
|
|
192
|
+
* @param baseUrl - Base API URL
|
|
193
|
+
* @param filters - Product filters
|
|
194
|
+
* @returns Complete URL
|
|
195
|
+
*/
|
|
196
|
+
const buildProductUrl = (baseUrl, filters) => {
|
|
197
|
+
return (0, exports.buildUrl)(baseUrl, filters);
|
|
198
|
+
};
|
|
199
|
+
exports.buildProductUrl = buildProductUrl;
|
|
200
|
+
/**
|
|
201
|
+
* Create order API URL
|
|
202
|
+
* @param baseUrl - Base API URL
|
|
203
|
+
* @param filters - Order filters
|
|
204
|
+
* @returns Complete URL
|
|
205
|
+
*/
|
|
206
|
+
const buildOrderUrl = (baseUrl, filters) => {
|
|
207
|
+
return (0, exports.buildUrl)(baseUrl, filters);
|
|
208
|
+
};
|
|
209
|
+
exports.buildOrderUrl = buildOrderUrl;
|
|
210
|
+
/**
|
|
211
|
+
* Create customer API URL
|
|
212
|
+
* @param baseUrl - Base API URL
|
|
213
|
+
* @param filters - Customer filters
|
|
214
|
+
* @returns Complete URL
|
|
215
|
+
*/
|
|
216
|
+
const buildCustomerUrl = (baseUrl, filters) => {
|
|
217
|
+
return (0, exports.buildUrl)(baseUrl, filters);
|
|
218
|
+
};
|
|
219
|
+
exports.buildCustomerUrl = buildCustomerUrl;
|
|
220
|
+
/**
|
|
221
|
+
* Create discount API URL
|
|
222
|
+
* @param baseUrl - Base API URL
|
|
223
|
+
* @param filters - Discount filters
|
|
224
|
+
* @returns Complete URL
|
|
225
|
+
*/
|
|
226
|
+
const buildDiscountUrl = (baseUrl, filters) => {
|
|
227
|
+
return (0, exports.buildUrl)(baseUrl, filters);
|
|
228
|
+
};
|
|
229
|
+
exports.buildDiscountUrl = buildDiscountUrl;
|
|
230
|
+
// =====================================================
|
|
231
|
+
// GROUPED EXPORTS - For Better DX
|
|
232
|
+
// =====================================================
|
|
233
|
+
// Main query builders (most commonly used)
|
|
234
|
+
exports.QueryBuilder = {
|
|
235
|
+
build: exports.buildQuery,
|
|
236
|
+
buildProduct: exports.buildProductQuery,
|
|
237
|
+
buildOrder: exports.buildOrderQuery,
|
|
238
|
+
buildCustomer: exports.buildCustomerQuery,
|
|
239
|
+
buildDiscount: exports.buildDiscountQuery,
|
|
240
|
+
parse: exports.parseQuery
|
|
241
|
+
};
|
|
242
|
+
// URL builders
|
|
243
|
+
exports.UrlBuilder = {
|
|
244
|
+
build: exports.buildUrl,
|
|
245
|
+
buildProduct: exports.buildProductUrl,
|
|
246
|
+
buildOrder: exports.buildOrderUrl,
|
|
247
|
+
buildCustomer: exports.buildCustomerUrl,
|
|
248
|
+
buildDiscount: exports.buildDiscountUrl
|
|
249
|
+
};
|
|
250
|
+
// Filter utilities
|
|
251
|
+
exports.FilterUtils = {
|
|
252
|
+
clean: exports.cleanFilters,
|
|
253
|
+
merge: exports.mergeFilters
|
|
254
|
+
};
|
|
255
|
+
// All-in-one object for comprehensive access
|
|
256
|
+
exports.FilterAPI = {
|
|
257
|
+
QueryBuilder: exports.QueryBuilder,
|
|
258
|
+
UrlBuilder: exports.UrlBuilder,
|
|
259
|
+
FilterUtils: exports.FilterUtils
|
|
260
|
+
};
|
|
261
|
+
// =====================================================
|
|
262
|
+
// DEFAULT EXPORT - Most Common Use Case
|
|
263
|
+
// =====================================================
|
|
264
|
+
exports.default = {
|
|
265
|
+
// Types (re-exported for convenience)
|
|
266
|
+
buildQuery: exports.buildQuery,
|
|
267
|
+
buildProductQuery: exports.buildProductQuery,
|
|
268
|
+
buildOrderQuery: exports.buildOrderQuery,
|
|
269
|
+
buildCustomerQuery: exports.buildCustomerQuery,
|
|
270
|
+
buildDiscountQuery: exports.buildDiscountQuery,
|
|
271
|
+
buildUrl: exports.buildUrl,
|
|
272
|
+
buildProductUrl: exports.buildProductUrl,
|
|
273
|
+
buildOrderUrl: exports.buildOrderUrl,
|
|
274
|
+
buildCustomerUrl: exports.buildCustomerUrl,
|
|
275
|
+
buildDiscountUrl: exports.buildDiscountUrl,
|
|
276
|
+
parseQuery: exports.parseQuery,
|
|
277
|
+
cleanFilters: exports.cleanFilters,
|
|
278
|
+
mergeFilters: exports.mergeFilters,
|
|
279
|
+
// Grouped objects
|
|
280
|
+
QueryBuilder: exports.QueryBuilder,
|
|
281
|
+
UrlBuilder: exports.UrlBuilder,
|
|
282
|
+
FilterUtils: exports.FilterUtils
|
|
283
|
+
};
|
|
284
|
+
/*
|
|
285
|
+
==============================================
|
|
286
|
+
USAGE EXAMPLES - Multiple Import Patterns
|
|
287
|
+
==============================================
|
|
288
|
+
|
|
289
|
+
// 1. Import specific functions (tree-shakable)
|
|
290
|
+
import { buildProductQuery, ProductFilters } from 'your-package';
|
|
291
|
+
|
|
292
|
+
// 2. Import grouped objects
|
|
293
|
+
import { QueryBuilder, UrlBuilder } from 'your-package';
|
|
294
|
+
|
|
295
|
+
// 3. Import default (all-in-one)
|
|
296
|
+
import FilterAPI from 'your-package';
|
|
297
|
+
|
|
298
|
+
// 4. Import everything
|
|
299
|
+
import * as Filters from 'your-package';
|
|
300
|
+
|
|
301
|
+
// Usage examples:
|
|
302
|
+
|
|
303
|
+
// Method 1: Direct imports
|
|
304
|
+
const filters: ProductFilters = { minStock: 10, isActive: true };
|
|
305
|
+
const query = buildProductQuery(filters);
|
|
306
|
+
|
|
307
|
+
// Method 2: Grouped objects
|
|
308
|
+
const query2 = QueryBuilder.buildProduct(filters);
|
|
309
|
+
const url = UrlBuilder.buildProduct('/api/products', filters);
|
|
310
|
+
|
|
311
|
+
// Method 3: Default import
|
|
312
|
+
const query3 = FilterAPI.QueryBuilder.buildProduct(filters);
|
|
313
|
+
const url2 = FilterAPI.UrlBuilder.buildProduct('/api/products', filters);
|
|
314
|
+
|
|
315
|
+
// Method 4: Namespace import
|
|
316
|
+
const query4 = Filters.buildProductQuery(filters);
|
|
317
|
+
const url3 = Filters.buildProductUrl('/api/products', filters);
|
|
318
|
+
*/
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// index.ts
|
|
2
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
4
|
if (k2 === undefined) k2 = k;
|
|
4
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -14,4 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
16
|
};
|
|
16
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
// Export everything from existing common file
|
|
17
19
|
__exportStar(require("./common"), exports);
|
|
20
|
+
// Export everything from new filters file
|
|
21
|
+
__exportStar(require("./filters"), exports);
|