3a-ecommerce-utils 1.0.0
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/README.md +163 -0
- package/dist/chunk-PEAZVBSD.mjs +597 -0
- package/dist/client-DYGi_pyp.d.mts +87 -0
- package/dist/client-DYGi_pyp.d.ts +87 -0
- package/dist/index.d.mts +496 -0
- package/dist/index.d.ts +496 -0
- package/dist/index.js +17707 -0
- package/dist/index.mjs +17043 -0
- package/dist/validation/server.d.mts +50 -0
- package/dist/validation/server.d.ts +50 -0
- package/dist/validation/server.js +518 -0
- package/dist/validation/server.mjs +168 -0
- package/package.json +69 -0
- package/src/api/address.queries.ts +96 -0
- package/src/api/category.queries.ts +85 -0
- package/src/api/coupon.queries.ts +120 -0
- package/src/api/dashboard.queries.ts +35 -0
- package/src/api/errorHandler.ts +164 -0
- package/src/api/graphqlClient.ts +113 -0
- package/src/api/index.ts +10 -0
- package/src/api/logger.client.ts +89 -0
- package/src/api/logger.ts +135 -0
- package/src/api/order.queries.ts +211 -0
- package/src/api/product.queries.ts +144 -0
- package/src/api/review.queries.ts +56 -0
- package/src/api/user.queries.ts +232 -0
- package/src/assets/3A.png +0 -0
- package/src/assets/index.ts +1 -0
- package/src/assets.d.ts +29 -0
- package/src/auth.ts +176 -0
- package/src/config/jest.backend.config.js +42 -0
- package/src/config/jest.frontend.config.js +50 -0
- package/src/config/postcss.config.js +6 -0
- package/src/config/tailwind.config.ts +70 -0
- package/src/config/tsconfig.base.json +36 -0
- package/src/config/vite.config.ts +86 -0
- package/src/config/vitest.base.config.ts +74 -0
- package/src/config/webpack.base.config.ts +126 -0
- package/src/constants/index.ts +312 -0
- package/src/cookies.ts +104 -0
- package/src/helpers.ts +400 -0
- package/src/index.ts +32 -0
- package/src/validation/client.ts +287 -0
- package/src/validation/index.ts +3 -0
- package/src/validation/server.ts +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Utils Package
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Shared utility functions and helpers used across all frontend and backend applications in the e-commerce platform.
|
|
6
|
+
|
|
7
|
+
## Tech Stack
|
|
8
|
+
|
|
9
|
+
- **TypeScript 5** - Type-safe utilities
|
|
10
|
+
- **Vitest** - Testing
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
This package is consumed as a workspace dependency:
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@e-commerce/utils": "^1.0.0"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Exports
|
|
25
|
+
|
|
26
|
+
### Main Export (`@e-commerce/utils`)
|
|
27
|
+
|
|
28
|
+
For frontend applications - browser-safe utilities only.
|
|
29
|
+
|
|
30
|
+
### Server Export (`@e-commerce/utils/server`)
|
|
31
|
+
|
|
32
|
+
For backend services - includes file system Logger and Express middleware.
|
|
33
|
+
|
|
34
|
+
## Utility Categories
|
|
35
|
+
|
|
36
|
+
### String Utilities
|
|
37
|
+
|
|
38
|
+
- `capitalize` - Capitalize first letter
|
|
39
|
+
- `capitalizeWords` - Capitalize all words
|
|
40
|
+
- `toTitleCase` - Convert to title case
|
|
41
|
+
- `slugify` - Create URL-safe slug
|
|
42
|
+
- `truncate` - Truncate with ellipsis
|
|
43
|
+
- `generateRandomCode` - Generate random string
|
|
44
|
+
|
|
45
|
+
### Number Utilities
|
|
46
|
+
|
|
47
|
+
- `formatCurrency` - Format as currency
|
|
48
|
+
- `formatNumber` - Round to decimals
|
|
49
|
+
- `formatIndianCompact` - Format in Lakhs/Crores
|
|
50
|
+
- `formatPrice` - Format as Indian Rupees
|
|
51
|
+
- `calculatePercentage` - Calculate percentage
|
|
52
|
+
- `calculateDiscount` - Apply discount
|
|
53
|
+
- `calculateTax` - Calculate tax amount
|
|
54
|
+
|
|
55
|
+
### Array Utilities
|
|
56
|
+
|
|
57
|
+
- `chunk` - Split array into chunks
|
|
58
|
+
- `unique` - Remove duplicates
|
|
59
|
+
- `removeDuplicates` - Remove by key
|
|
60
|
+
- `groupBy` - Group by property
|
|
61
|
+
- `sortBy` - Sort by property
|
|
62
|
+
- `flatten` - Flatten nested arrays
|
|
63
|
+
- `difference` - Array difference
|
|
64
|
+
- `intersection` - Array intersection
|
|
65
|
+
|
|
66
|
+
### Object Utilities
|
|
67
|
+
|
|
68
|
+
- `pick` - Pick properties
|
|
69
|
+
- `omit` - Omit properties
|
|
70
|
+
- `deepClone` - Deep clone object
|
|
71
|
+
- `deepMerge` - Deep merge objects
|
|
72
|
+
- `isEmpty` - Check if empty
|
|
73
|
+
|
|
74
|
+
### Date Utilities
|
|
75
|
+
|
|
76
|
+
- `formatDate` - Format date
|
|
77
|
+
- `formatDateTime` - Format date + time
|
|
78
|
+
- `formatRelativeTime` - Relative time (e.g., "2 hours ago")
|
|
79
|
+
- `isToday` - Check if today
|
|
80
|
+
- `addDays` - Add days to date
|
|
81
|
+
- `daysBetween` - Days between dates
|
|
82
|
+
|
|
83
|
+
### Auth Utilities
|
|
84
|
+
|
|
85
|
+
- `storeAuth` - Store auth tokens
|
|
86
|
+
- `getStoredAuth` - Get stored auth
|
|
87
|
+
- `clearAuth` - Clear auth data
|
|
88
|
+
- `isTokenExpired` - Check token expiration
|
|
89
|
+
- `validateUserRole` - Role validation
|
|
90
|
+
- `setupAutoRefresh` - Auto token refresh
|
|
91
|
+
|
|
92
|
+
### Cookie Utilities
|
|
93
|
+
|
|
94
|
+
- `setCookie` - Set cookie
|
|
95
|
+
- `getCookie` - Get cookie
|
|
96
|
+
- `removeCookie` - Remove cookie
|
|
97
|
+
- `areCookiesEnabled` - Check cookie support
|
|
98
|
+
|
|
99
|
+
### Validation (Client)
|
|
100
|
+
|
|
101
|
+
- `validateEmail` - Email validation
|
|
102
|
+
- `validatePassword` - Password validation
|
|
103
|
+
- `validatePhone` - Phone validation
|
|
104
|
+
- `validateRequired` - Required field
|
|
105
|
+
|
|
106
|
+
### Validation (Server - Express)
|
|
107
|
+
|
|
108
|
+
- `validate` - Express validator middleware
|
|
109
|
+
|
|
110
|
+
### Logging
|
|
111
|
+
|
|
112
|
+
- `Logger` (Client) - Browser console logging
|
|
113
|
+
- `Logger` (Server) - File + console logging
|
|
114
|
+
|
|
115
|
+
## Logger Usage
|
|
116
|
+
|
|
117
|
+
### Frontend
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { Logger } from '@e-commerce/utils';
|
|
121
|
+
|
|
122
|
+
Logger.info('User logged in', { userId: '123' }, 'Auth');
|
|
123
|
+
Logger.error('API call failed', error, 'API');
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Backend
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { Logger } from '@e-commerce/utils/server';
|
|
130
|
+
|
|
131
|
+
Logger.configure({
|
|
132
|
+
enableFile: true,
|
|
133
|
+
logFilePath: './logs/app.log',
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
Logger.info('Server started', { port: 4000 }, 'Startup');
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Project Structure
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
src/
|
|
143
|
+
├── api/
|
|
144
|
+
│ ├── logger.ts # Server Logger
|
|
145
|
+
│ ├── logger.client.ts # Client Logger
|
|
146
|
+
│ └── *.queries.ts # API query builders
|
|
147
|
+
├── auth.ts # Auth utilities
|
|
148
|
+
├── cookies.ts # Cookie utilities
|
|
149
|
+
├── helpers.ts # General helpers
|
|
150
|
+
├── constants/ # Constants
|
|
151
|
+
├── config/ # Configuration
|
|
152
|
+
├── validation/
|
|
153
|
+
│ ├── client.ts # Client validation
|
|
154
|
+
│ └── server.ts # Server validation + middleware
|
|
155
|
+
└── index.ts # Main exports
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Scripts
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
yarn test # Run tests
|
|
162
|
+
yarn test:coverage # Run tests with coverage
|
|
163
|
+
```
|