shopoflex-types 1.0.59 → 1.0.60

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/filters.d.ts CHANGED
@@ -45,12 +45,12 @@ export interface ProductFilters extends BaseFilters {
45
45
  minQuantityRange?: [number, number] | string;
46
46
  }
47
47
  export interface OrderFilters extends BaseFilters {
48
- status?: 'pending' | 'confirmed' | 'preparing' | 'ready' | 'delivered' | 'cancelled' | 'completed' | string;
48
+ status?: string;
49
49
  paid?: boolean;
50
50
  vendorId?: string;
51
51
  customerId?: string;
52
52
  branchId?: string;
53
- paymentMethod?: 'cash' | 'card' | 'transfer' | 'wallet' | 'cod' | string;
53
+ paymentMethod?: string;
54
54
  orderNumber?: string;
55
55
  customerPhone?: string;
56
56
  customerDialCode?: string;
@@ -74,7 +74,7 @@ export interface CustomerFilters extends BaseFilters {
74
74
  registeredBefore?: Date | string;
75
75
  }
76
76
  export interface DiscountFilters extends BaseFilters {
77
- status?: 'active' | 'paused' | 'expired' | 'exhausted' | string;
77
+ status?: string;
78
78
  type?: 'fixed' | 'percentage' | string;
79
79
  vendorId?: string;
80
80
  isAutomatic?: boolean;
@@ -88,159 +88,7 @@ export interface DiscountFilters extends BaseFilters {
88
88
  expired?: boolean;
89
89
  expiringSoon?: boolean;
90
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
91
  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
92
  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
93
  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
94
  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 CHANGED
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
2
  // =====================================================
3
- // TYPE DEFINITIONS
3
+ // FILTER INTERFACES - Clean & Minimal
4
4
  // =====================================================
5
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;
6
+ exports.buildDiscountQuery = exports.buildCustomerQuery = exports.buildOrderQuery = exports.buildProductQuery = void 0;
7
7
  // =====================================================
8
- // CORE UTILITIES
8
+ // SINGLE QUERY BUILDER FUNCTION
9
9
  // =====================================================
10
10
  /**
11
- * Converts filter object to URL query string
12
- * Handles arrays, dates, and nested values automatically
11
+ * Convert any filter object to URL query parameters string
12
+ * @param filters - Any filter object
13
+ * @returns Query parameters string (without ?)
13
14
  */
14
- const buildQueryString = (filters) => {
15
+ const buildQuery = (filters) => {
15
16
  const parts = [];
16
17
  Object.entries(filters).forEach(([key, value]) => {
17
18
  if (value === undefined || value === null || value === '')
@@ -34,285 +35,43 @@ const buildQueryString = (filters) => {
34
35
  }
35
36
  // Handle primitives
36
37
  else {
37
- parts.push(`${key}=${value}`);
38
+ parts.push(`${key}=${encodeURIComponent(value)}`);
38
39
  }
39
40
  });
40
41
  return parts.join('&');
41
42
  };
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
43
  // =====================================================
129
- // QUERY BUILDERS - Main Functions
44
+ // TYPE-SAFE ALIASES (Optional - for convenience)
130
45
  // =====================================================
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
- };
46
+ const buildProductQuery = (filters) => buildQuery(filters);
148
47
  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
- };
48
+ const buildOrderQuery = (filters) => buildQuery(filters);
157
49
  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
- };
50
+ const buildCustomerQuery = (filters) => buildQuery(filters);
166
51
  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
- };
52
+ const buildDiscountQuery = (filters) => buildQuery(filters);
175
53
  exports.buildDiscountQuery = buildDiscountQuery;
176
54
  // =====================================================
177
- // URL BUILDERS - Convenience Functions
55
+ // USAGE EXAMPLES
178
56
  // =====================================================
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
57
  /*
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);
58
+ // Simple usage:
59
+ const filters: ProductFilters = {
60
+ minStock: 10,
61
+ variantColor: 'red',
62
+ priceRange: [50, 200],
63
+ isActive: true,
64
+ page: 1,
65
+ limit: 50
66
+ };
306
67
 
307
- // Method 2: Grouped objects
308
- const query2 = QueryBuilder.buildProduct(filters);
309
- const url = UrlBuilder.buildProduct('/api/products', filters);
68
+ const queryString = buildQuery(filters);
69
+ // Result: "minStock=10&variantColor=red&priceRange=50,200&isActive=true&page=1&limit=50"
310
70
 
311
- // Method 3: Default import
312
- const query3 = FilterAPI.QueryBuilder.buildProduct(filters);
313
- const url2 = FilterAPI.UrlBuilder.buildProduct('/api/products', filters);
71
+ // Use with API:
72
+ const url = `/api/products?${buildQuery(filters)}`;
73
+ fetch(url).then(res => res.json());
314
74
 
315
- // Method 4: Namespace import
316
- const query4 = Filters.buildProductQuery(filters);
317
- const url3 = Filters.buildProductUrl('/api/products', filters);
75
+ // Or with type-safe alias:
76
+ const queryString = buildProductQuery(filters);
318
77
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shopoflex-types",
3
- "version": "1.0.59",
3
+ "version": "1.0.60",
4
4
  "description": "Shared TypeScript types for Shopoflex applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",