@promakeai/cli 0.0.5 → 0.1.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/dist/index.js +214 -135
- package/dist/registry/about-page.json +5 -3
- package/dist/registry/about-section.json +2 -2
- package/dist/registry/announcement-bar.json +43 -0
- package/dist/registry/api.json +55 -0
- package/dist/registry/auth-core.json +43 -0
- package/dist/registry/auth.json +70 -0
- package/dist/registry/bento-grid-section.json +1 -1
- package/dist/registry/blog-list-page.json +3 -2
- package/dist/registry/blog-section.json +2 -2
- package/dist/registry/cart-drawer.json +1 -1
- package/dist/registry/cart-page.json +5 -4
- package/dist/registry/case-study-page.json +48 -0
- package/dist/registry/category-section.json +1 -1
- package/dist/registry/checkout-page.json +7 -5
- package/dist/registry/coming-soon-page-minimal.json +45 -0
- package/dist/registry/coming-soon-page.json +47 -0
- package/dist/registry/contact-info-grid.json +2 -2
- package/dist/registry/contact-page-centered.json +2 -2
- package/dist/registry/contact-page-map-overlay.json +4 -3
- package/dist/registry/contact-page-map-split.json +4 -3
- package/dist/registry/contact-page-split.json +3 -3
- package/dist/registry/contact-page.json +5 -3
- package/dist/registry/cookie-consent.json +43 -0
- package/dist/registry/cookies-page.json +4 -2
- package/dist/registry/cta-section.json +2 -2
- package/dist/registry/db.json +129 -0
- package/dist/registry/docs/about-page.md +5 -0
- package/dist/registry/docs/announcement-bar.md +38 -0
- package/dist/registry/docs/auth-core.md +64 -0
- package/dist/registry/docs/blog-list-page.md +1 -0
- package/dist/registry/docs/cart-page.md +1 -0
- package/dist/registry/docs/case-study-page.md +39 -0
- package/dist/registry/docs/checkout-page.md +3 -1
- package/dist/registry/docs/coming-soon-page-minimal.md +32 -0
- package/dist/registry/docs/coming-soon-page.md +37 -0
- package/dist/registry/docs/contact-page-map-overlay.md +2 -2
- package/dist/registry/docs/contact-page-map-split.md +2 -2
- package/dist/registry/docs/contact-page.md +5 -0
- package/dist/registry/docs/cookie-consent.md +37 -0
- package/dist/registry/docs/cookies-page.md +5 -0
- package/dist/registry/docs/ecommerce-core.md +4 -3
- package/dist/registry/docs/forgot-password-page-split.md +45 -0
- package/dist/registry/docs/forgot-password-page.md +46 -0
- package/dist/registry/docs/header-ecommerce.md +2 -0
- package/dist/registry/docs/hero-carousel.md +37 -0
- package/dist/registry/docs/landing-page-app.md +43 -0
- package/dist/registry/docs/landing-page-saas.md +41 -0
- package/dist/registry/docs/login-page-split.md +13 -4
- package/dist/registry/docs/login-page.md +17 -4
- package/dist/registry/docs/logo-cloud.md +33 -0
- package/dist/registry/docs/masonry-grid.md +37 -0
- package/dist/registry/docs/my-orders-page.md +44 -0
- package/dist/registry/docs/order-confirmation-page.md +41 -0
- package/dist/registry/docs/portfolio-page.md +38 -0
- package/dist/registry/docs/pricing-page.md +38 -0
- package/dist/registry/docs/privacy-page.md +5 -0
- package/dist/registry/docs/product-quick-view.md +37 -0
- package/dist/registry/docs/products-page.md +1 -0
- package/dist/registry/docs/reading-progress.md +31 -0
- package/dist/registry/docs/register-page-split.md +45 -0
- package/dist/registry/docs/register-page.md +46 -0
- package/dist/registry/docs/reset-password-page-split.md +45 -0
- package/dist/registry/docs/reset-password-page.md +36 -0
- package/dist/registry/docs/share-buttons.md +37 -0
- package/dist/registry/docs/team-page.md +38 -0
- package/dist/registry/docs/terms-page.md +5 -0
- package/dist/registry/docs/timeline-section.md +37 -0
- package/dist/registry/docs/video-hero.md +41 -0
- package/dist/registry/ecommerce-core.json +18 -2
- package/dist/registry/empty-page.json +1 -1
- package/dist/registry/faq-categorized.json +2 -2
- package/dist/registry/faq-simple.json +2 -2
- package/dist/registry/favorites-blog-block.json +1 -1
- package/dist/registry/favorites-ecommerce-block.json +1 -1
- package/dist/registry/feature-section.json +2 -2
- package/dist/registry/featured-products.json +1 -1
- package/dist/registry/footer-detailed.json +1 -1
- package/dist/registry/footer-minimal.json +3 -3
- package/dist/registry/footer.json +2 -2
- package/dist/registry/forgot-password-page-split.json +50 -0
- package/dist/registry/forgot-password-page.json +51 -0
- package/dist/registry/header-ecommerce.json +4 -2
- package/dist/registry/header-mega.json +2 -2
- package/dist/registry/header-minimal.json +1 -1
- package/dist/registry/header-simple.json +1 -1
- package/dist/registry/hero-carousel.json +45 -0
- package/dist/registry/hero-cta.json +2 -2
- package/dist/registry/hero-gradient.json +2 -2
- package/dist/registry/hero-profile.json +1 -1
- package/dist/registry/hero.json +2 -2
- package/dist/registry/index.json +24 -1
- package/dist/registry/landing-page-app.json +47 -0
- package/dist/registry/landing-page-saas.json +47 -0
- package/dist/registry/login-page-split.json +11 -7
- package/dist/registry/login-page.json +4 -4
- package/dist/registry/logo-cloud.json +41 -0
- package/dist/registry/masonry-grid.json +43 -0
- package/dist/registry/my-orders-page.json +52 -0
- package/dist/registry/order-confirmation-page.json +49 -0
- package/dist/registry/orders-list-block.json +1 -1
- package/dist/registry/payment-success-block.json +1 -1
- package/dist/registry/portfolio-page.json +45 -0
- package/dist/registry/post-detail-block.json +1 -1
- package/dist/registry/pricing-page.json +47 -0
- package/dist/registry/pricing-section.json +2 -2
- package/dist/registry/privacy-page.json +4 -2
- package/dist/registry/product-detail-block.json +1 -1
- package/dist/registry/product-quick-view.json +46 -0
- package/dist/registry/products-page.json +5 -4
- package/dist/registry/reading-progress.json +43 -0
- package/dist/registry/register-page-split.json +50 -0
- package/dist/registry/register-page.json +51 -0
- package/dist/registry/related-posts-block.json +1 -1
- package/dist/registry/reset-password-page-split.json +50 -0
- package/dist/registry/reset-password-page.json +39 -0
- package/dist/registry/share-buttons.json +46 -0
- package/dist/registry/team-page.json +47 -0
- package/dist/registry/terms-page.json +4 -2
- package/dist/registry/testimonials-carousel.json +2 -2
- package/dist/registry/testimonials-grid.json +2 -2
- package/dist/registry/timeline-section.json +43 -0
- package/dist/registry/video-hero.json +42 -0
- package/package.json +1 -1
- package/template/index.html +5 -5
- package/template/src/App.tsx +7 -24
- package/template/src/components/GoogleAnalytics.tsx +34 -0
- package/template/src/components/Layout.tsx +1 -5
- package/template/src/components/ScriptInjector.tsx +62 -0
- package/template/src/constants/constants.json +8 -2
- package/template/src/index.css +1 -0
- package/template/src/lang/en/index.json +1 -28
- package/template/src/lang/tr/index.json +1 -28
- package/template/src/pages/Index.tsx +1 -98
- package/template/src/components/Footer.tsx +0 -100
- package/template/src/components/Header.tsx +0 -79
- package/template/src/components/Hero.tsx +0 -69
- package/template/src/modules/api/USAGE.md +0 -515
- package/template/src/modules/api/customer-client.ts +0 -20
- package/template/src/modules/api/get-error-message.ts +0 -18
- package/template/src/modules/api/validation/en.json +0 -29
- package/template/src/modules/api/validation/tr.json +0 -29
- package/template/src/modules/auth/USAGE.md +0 -248
- package/template/src/modules/auth/auth-header-menu.tsx +0 -123
- package/template/src/modules/auth/auth-store.ts +0 -57
- package/template/src/modules/auth/forgot-password-page.tsx +0 -371
- package/template/src/modules/auth/login-page.tsx +0 -183
- package/template/src/modules/auth/register-page.tsx +0 -252
- package/template/src/modules/auth/use-auth.ts +0 -273
- package/template/src/modules/db/adapters/IDataAdapter.ts +0 -26
- package/template/src/modules/db/adapters/SqliteAdapter.ts +0 -364
- package/template/src/modules/db/adapters/index.ts +0 -2
- package/template/src/modules/db/config.ts +0 -59
- package/template/src/modules/db/core/DataManager.ts +0 -125
- package/template/src/modules/db/core/types.ts +0 -101
- package/template/src/modules/db/index.ts +0 -42
- package/template/src/modules/db/react/QueryProvider.tsx +0 -16
- package/template/src/modules/db/react/index.ts +0 -23
- package/template/src/modules/db/react/queryClient.ts +0 -64
- package/template/src/modules/db/react/useRepository.ts +0 -400
- package/template/src/modules/db/utils/parsers.ts +0 -96
|
@@ -1,515 +0,0 @@
|
|
|
1
|
-
# API Module Usage Guide
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
Central API communication layer using `@promakeai/customer-backend-client`. Provides type-safe API calls and error handling utilities.
|
|
6
|
-
|
|
7
|
-
**Important**: The API client configuration and error utilities are core infrastructure and should NOT be modified. UI components consuming the API are customizable.
|
|
8
|
-
|
|
9
|
-
## Module Structure
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
src/modules/api/
|
|
13
|
-
├── customer-client.ts # [CORE] API client instance - DO NOT MODIFY
|
|
14
|
-
└── get-error-message.ts # [CORE] Error utility - DO NOT MODIFY
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Requirements & Dependencies
|
|
18
|
-
|
|
19
|
-
### Required NPM Packages
|
|
20
|
-
|
|
21
|
-
```json
|
|
22
|
-
{
|
|
23
|
-
"@promakeai/customer-backend-client": "^1.0.7" // CORE - API client
|
|
24
|
-
}
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Note: `axios` is included as a dependency of the customer backend client.
|
|
28
|
-
|
|
29
|
-
### Required Environment Variables
|
|
30
|
-
|
|
31
|
-
```env
|
|
32
|
-
# Option 1: Direct API URL
|
|
33
|
-
VITE_API_CUSTOMER=https://your-api.example.com/
|
|
34
|
-
|
|
35
|
-
# Option 2: Tenant-based URL (auto-generated)
|
|
36
|
-
VITE_TENANT_UUID=your-tenant-uuid-here
|
|
37
|
-
# Generates: https://{VITE_TENANT_UUID}.backend.promake.ai/
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
**At least ONE of these must be set** in your `.env` file.
|
|
41
|
-
|
|
42
|
-
### Optional Project Dependencies
|
|
43
|
-
|
|
44
|
-
**For Error Display** (Recommended):
|
|
45
|
-
|
|
46
|
-
- `sonner` - For `toast.error()` in UI components
|
|
47
|
-
|
|
48
|
-
**For Type Checking**:
|
|
49
|
-
|
|
50
|
-
- `typescript` - For type safety
|
|
51
|
-
|
|
52
|
-
**For React Query Integration** (Optional):
|
|
53
|
-
|
|
54
|
-
- `@tanstack/react-query` - For query/mutation hooks
|
|
55
|
-
|
|
56
|
-
### Project Integration Points
|
|
57
|
-
|
|
58
|
-
**Required by**:
|
|
59
|
-
|
|
60
|
-
- `@/modules/auth/use-auth` - Uses this client for authentication
|
|
61
|
-
- Any page/component making API calls
|
|
62
|
-
|
|
63
|
-
**Uses**:
|
|
64
|
-
|
|
65
|
-
- Environment variables (Vite)
|
|
66
|
-
|
|
67
|
-
## Customer Client Setup
|
|
68
|
-
|
|
69
|
-
```tsx
|
|
70
|
-
import { createClient } from "@promakeai/customer-backend-client";
|
|
71
|
-
import enValidation from "./validation/en.json";
|
|
72
|
-
import trValidation from "./validation/tr.json";
|
|
73
|
-
|
|
74
|
-
const customerClient = createClient({
|
|
75
|
-
baseURL:
|
|
76
|
-
import.meta.env.VITE_API_CUSTOMER ||
|
|
77
|
-
`https://${import.meta.env.VITE_TENANT_UUID}.backend.promake.ai/`,
|
|
78
|
-
messages: {
|
|
79
|
-
en: enValidation,
|
|
80
|
-
tr: trValidation,
|
|
81
|
-
},
|
|
82
|
-
defaultLanguage: "tr",
|
|
83
|
-
});
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Multi-language Validation
|
|
87
|
-
|
|
88
|
-
The API client includes automatic multi-language validation error messages that sync with your app's language setting.
|
|
89
|
-
|
|
90
|
-
### How It Works
|
|
91
|
-
|
|
92
|
-
1. **Validation messages** are defined in `src/modules/api/validation/{language}.json`
|
|
93
|
-
2. **All languages** are passed to the client at initialization
|
|
94
|
-
3. **Language sync** happens automatically in `App.tsx` via `useEffect`
|
|
95
|
-
4. **Runtime switching** updates validation errors immediately
|
|
96
|
-
|
|
97
|
-
### Validation Message Files
|
|
98
|
-
|
|
99
|
-
Validation messages are stored in the API module for better modularity:
|
|
100
|
-
|
|
101
|
-
**English** (`src/modules/api/validation/en.json`):
|
|
102
|
-
|
|
103
|
-
```json
|
|
104
|
-
{
|
|
105
|
-
"username_required": "Username is required",
|
|
106
|
-
"password_required": "Password is required",
|
|
107
|
-
"email_invalid": "Invalid email address",
|
|
108
|
-
"password_min_length": "Password must be at least 8 characters"
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
**Turkish** (`src/modules/api/validation/tr.json`):
|
|
113
|
-
|
|
114
|
-
```json
|
|
115
|
-
{
|
|
116
|
-
"username_required": "Kullanıcı adı zorunludur",
|
|
117
|
-
"password_required": "Şifre zorunludur",
|
|
118
|
-
"email_invalid": "Geçersiz e-posta adresi",
|
|
119
|
-
"password_min_length": "Şifre en az 8 karakter olmalıdır"
|
|
120
|
-
}
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
**Why in `modules/api/validation/`?**
|
|
124
|
-
|
|
125
|
-
- ✅ **Modular**: API module contains its own validation messages
|
|
126
|
-
- ✅ **Portable**: When copying the API module, validation comes with it
|
|
127
|
-
- ✅ **Clear separation**: UI texts in `lang/`, API validation in `modules/api/`
|
|
128
|
-
|
|
129
|
-
### Available Validation Keys
|
|
130
|
-
|
|
131
|
-
The following validation message keys are supported:
|
|
132
|
-
|
|
133
|
-
**Auth Validation**:
|
|
134
|
-
|
|
135
|
-
- `username_required`, `username_min_length`
|
|
136
|
-
- `email_required`, `email_invalid`
|
|
137
|
-
- `password_required`, `password_min_length`
|
|
138
|
-
- `password_letter_required`, `password_number_required`
|
|
139
|
-
- `code_required`, `reset_code_required`
|
|
140
|
-
|
|
141
|
-
**Payment Validation**:
|
|
142
|
-
|
|
143
|
-
- `session_id_required`
|
|
144
|
-
- `quantity_positive`, `amount_positive`
|
|
145
|
-
- `product_name_required`, `product_description_required`
|
|
146
|
-
- `image_required`
|
|
147
|
-
- `currency_required`, `tax_amount_non_negative`
|
|
148
|
-
- `at_least_one_product`, `payment_type_invalid`
|
|
149
|
-
|
|
150
|
-
**Contact/Shipping Validation**:
|
|
151
|
-
|
|
152
|
-
- `firstname_required`, `lastname_required`
|
|
153
|
-
- `phone_required`, `address_required`
|
|
154
|
-
- `country_required`, `city_required`, `zip_required`
|
|
155
|
-
|
|
156
|
-
### Language Synchronization
|
|
157
|
-
|
|
158
|
-
The client automatically syncs with your app's language setting:
|
|
159
|
-
|
|
160
|
-
```tsx
|
|
161
|
-
// In App.tsx
|
|
162
|
-
import { customerClient } from "@/modules/api/customer-client";
|
|
163
|
-
import { useSiteConfig } from "@/hooks/useSiteConfig";
|
|
164
|
-
|
|
165
|
-
const AppContent = () => {
|
|
166
|
-
const { getSetting } = useSiteConfig();
|
|
167
|
-
const currentLang = getSetting("site.defaultLanguage", "en");
|
|
168
|
-
|
|
169
|
-
useEffect(() => {
|
|
170
|
-
customerClient.setLanguage(currentLang);
|
|
171
|
-
}, [currentLang]);
|
|
172
|
-
};
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### Example Error Messages
|
|
176
|
-
|
|
177
|
-
**Login with empty username (English)**:
|
|
178
|
-
|
|
179
|
-
```tsx
|
|
180
|
-
try {
|
|
181
|
-
await customerClient.auth.login({ username: "", password: "test" });
|
|
182
|
-
} catch (error) {
|
|
183
|
-
// Error: "Username is required"
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
**Login with empty username (Turkish)**:
|
|
188
|
-
|
|
189
|
-
```tsx
|
|
190
|
-
// After user switches language to Turkish
|
|
191
|
-
try {
|
|
192
|
-
await customerClient.auth.login({ username: "", password: "test" });
|
|
193
|
-
} catch (error) {
|
|
194
|
-
// Error: "Kullanıcı adı zorunludur"
|
|
195
|
-
}
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
**Registration with invalid email (English)**:
|
|
199
|
-
|
|
200
|
-
```tsx
|
|
201
|
-
try {
|
|
202
|
-
await customerClient.auth.register({
|
|
203
|
-
username: "john",
|
|
204
|
-
email: "invalid-email",
|
|
205
|
-
password: "pass123",
|
|
206
|
-
});
|
|
207
|
-
} catch (error) {
|
|
208
|
-
// Error: "Invalid email address"
|
|
209
|
-
}
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
### Adding New Languages
|
|
213
|
-
|
|
214
|
-
To add support for a new language:
|
|
215
|
-
|
|
216
|
-
1. Create `src/modules/api/validation/{language-code}.json` with all validation keys
|
|
217
|
-
2. Import it in `customer-client.ts`:
|
|
218
|
-
```tsx
|
|
219
|
-
import deValidation from "./validation/de.json";
|
|
220
|
-
```
|
|
221
|
-
3. Add to messages object:
|
|
222
|
-
```tsx
|
|
223
|
-
const customerClient = createClient({
|
|
224
|
-
messages: {
|
|
225
|
-
en: enValidation,
|
|
226
|
-
tr: trValidation,
|
|
227
|
-
de: deValidation, // New language
|
|
228
|
-
},
|
|
229
|
-
});
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
The language will automatically be available when users set `site.defaultLanguage` to `"de"` in settings.
|
|
233
|
-
|
|
234
|
-
### Manual Language Override
|
|
235
|
-
|
|
236
|
-
You can also manually change the validation language:
|
|
237
|
-
|
|
238
|
-
```tsx
|
|
239
|
-
customerClient.setLanguage("tr"); // Switch to Turkish
|
|
240
|
-
customerClient.setLanguage("en"); // Switch to English
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
This is useful for testing or special use cases where you need to override the automatic sync.
|
|
244
|
-
|
|
245
|
-
## Basic Usage
|
|
246
|
-
|
|
247
|
-
### Direct Client Usage
|
|
248
|
-
|
|
249
|
-
```tsx
|
|
250
|
-
import { customerClient } from "@/modules/api/customer-client";
|
|
251
|
-
|
|
252
|
-
const response = await customerClient.auth.login({ username, password });
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
### With Auth Hook (Recommended)
|
|
256
|
-
|
|
257
|
-
```tsx
|
|
258
|
-
import { useAuth } from "@/modules/auth/use-auth";
|
|
259
|
-
|
|
260
|
-
function MyComponent() {
|
|
261
|
-
const { api, isAuthenticated } = useAuth();
|
|
262
|
-
|
|
263
|
-
if (isAuthenticated) {
|
|
264
|
-
const orders = await api.orders.getMyOrders(); // Token auto-added
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
## Available API Methods
|
|
270
|
-
|
|
271
|
-
### Auth Operations
|
|
272
|
-
|
|
273
|
-
```tsx
|
|
274
|
-
// Login
|
|
275
|
-
await customerClient.auth.login({ username, password });
|
|
276
|
-
|
|
277
|
-
// Register
|
|
278
|
-
await customerClient.auth.register({ username, email, password });
|
|
279
|
-
|
|
280
|
-
// Confirm email
|
|
281
|
-
await customerClient.auth.confirm({ username, code });
|
|
282
|
-
|
|
283
|
-
// Password reset flow
|
|
284
|
-
await customerClient.auth.forgotPassword({ username });
|
|
285
|
-
await customerClient.auth.resetPassword({ username, code, newPassword });
|
|
286
|
-
|
|
287
|
-
// Token refresh (handled automatically by useAuth)
|
|
288
|
-
await customerClient.axios.post("/auth/refresh", { refreshToken });
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
### Order Operations
|
|
292
|
-
|
|
293
|
-
```tsx
|
|
294
|
-
// Get user's orders (requires auth)
|
|
295
|
-
const orders = await customerClient.orders.getMyOrders();
|
|
296
|
-
|
|
297
|
-
// Get order by payment session
|
|
298
|
-
const order = await customerClient.orders.getBySessionId({ sessionId });
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
### Payment Operations
|
|
302
|
-
|
|
303
|
-
```tsx
|
|
304
|
-
// Create checkout session
|
|
305
|
-
const session = await customerClient.payment.createCheckout(checkoutData);
|
|
306
|
-
|
|
307
|
-
// Verify payment
|
|
308
|
-
const result = await customerClient.payment.verify({ sessionId });
|
|
309
|
-
|
|
310
|
-
// Check payment status
|
|
311
|
-
const status = await customerClient.payment.status({ sessionId });
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
### Token Management
|
|
315
|
-
|
|
316
|
-
```tsx
|
|
317
|
-
customerClient.setToken("access-token"); // Set token
|
|
318
|
-
customerClient.setToken(null); // Clear token
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
### Direct Axios Access
|
|
322
|
-
|
|
323
|
-
```tsx
|
|
324
|
-
// For custom endpoints not in client API
|
|
325
|
-
const response = await customerClient.axios.get("/custom-endpoint");
|
|
326
|
-
const data = await customerClient.axios.post("/custom", { data });
|
|
327
|
-
|
|
328
|
-
// Add interceptors
|
|
329
|
-
customerClient.axios.interceptors.request.use((config) => {
|
|
330
|
-
console.log("Request:", config);
|
|
331
|
-
return config;
|
|
332
|
-
});
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
## Error Handling
|
|
336
|
-
|
|
337
|
-
### getErrorMessage Utility
|
|
338
|
-
|
|
339
|
-
Extracts user-friendly messages from API errors:
|
|
340
|
-
|
|
341
|
-
```tsx
|
|
342
|
-
import { getErrorMessage } from "@/modules/api/get-error-message";
|
|
343
|
-
|
|
344
|
-
try {
|
|
345
|
-
await customerClient.auth.login({ username, password });
|
|
346
|
-
} catch (err) {
|
|
347
|
-
const message = getErrorMessage(err, "Login failed");
|
|
348
|
-
toast.error(message); // "Invalid credentials" or fallback
|
|
349
|
-
}
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
**Priority Order**:
|
|
353
|
-
|
|
354
|
-
1. `error.response.data.message` (backend message)
|
|
355
|
-
2. `error.response.data.error` (backend error)
|
|
356
|
-
3. `error.message` (axios error)
|
|
357
|
-
4. Fallback message
|
|
358
|
-
|
|
359
|
-
## React Query Integration
|
|
360
|
-
|
|
361
|
-
```tsx
|
|
362
|
-
import { useQuery, useMutation } from "@tanstack/react-query";
|
|
363
|
-
import { customerClient } from "@/modules/api/customer-client";
|
|
364
|
-
|
|
365
|
-
// Query
|
|
366
|
-
function useMyOrders() {
|
|
367
|
-
return useQuery({
|
|
368
|
-
queryKey: ["orders"],
|
|
369
|
-
queryFn: () => customerClient.orders.getMyOrders(),
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// Mutation
|
|
374
|
-
function useCreateCheckout() {
|
|
375
|
-
return useMutation({
|
|
376
|
-
mutationFn: (data) => customerClient.payment.createCheckout(data),
|
|
377
|
-
onError: (err) => toast.error(getErrorMessage(err)),
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
## Type Safety
|
|
383
|
-
|
|
384
|
-
```tsx
|
|
385
|
-
import type { ApiClient } from "@/modules/api/customer-client";
|
|
386
|
-
|
|
387
|
-
// Use client type
|
|
388
|
-
function service(client: ApiClient) {
|
|
389
|
-
return client.orders.getMyOrders();
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// Extract response types
|
|
393
|
-
type Order = Awaited<ReturnType<typeof customerClient.orders.getMyOrders>>;
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
## Best Practices
|
|
397
|
-
|
|
398
|
-
### Error Handling Pattern
|
|
399
|
-
|
|
400
|
-
```tsx
|
|
401
|
-
import { getErrorMessage } from "@/modules/api/get-error-message";
|
|
402
|
-
|
|
403
|
-
async function handleApiCall() {
|
|
404
|
-
try {
|
|
405
|
-
const result = await customerClient.auth.login(credentials);
|
|
406
|
-
toast.success("Success!");
|
|
407
|
-
return result;
|
|
408
|
-
} catch (err) {
|
|
409
|
-
const message = getErrorMessage(err, "Operation failed");
|
|
410
|
-
toast.error(message);
|
|
411
|
-
console.error("API Error:", err); // Debug
|
|
412
|
-
throw err; // Optional
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
### With Loading State
|
|
418
|
-
|
|
419
|
-
```tsx
|
|
420
|
-
const [loading, setLoading] = useState(false);
|
|
421
|
-
|
|
422
|
-
async function fetchData() {
|
|
423
|
-
setLoading(true);
|
|
424
|
-
try {
|
|
425
|
-
const data = await customerClient.orders.getMyOrders();
|
|
426
|
-
return data;
|
|
427
|
-
} catch (err) {
|
|
428
|
-
toast.error(getErrorMessage(err));
|
|
429
|
-
} finally {
|
|
430
|
-
setLoading(false);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
```
|
|
434
|
-
|
|
435
|
-
## Customization
|
|
436
|
-
|
|
437
|
-
### Timeout Configuration
|
|
438
|
-
|
|
439
|
-
```tsx
|
|
440
|
-
// customer-client.ts
|
|
441
|
-
const customerClient = createClient({
|
|
442
|
-
baseURL: import.meta.env.VITE_API_CUSTOMER,
|
|
443
|
-
timeout: 10000, // 10 seconds
|
|
444
|
-
});
|
|
445
|
-
```
|
|
446
|
-
|
|
447
|
-
### Global Error Handler
|
|
448
|
-
|
|
449
|
-
```tsx
|
|
450
|
-
customerClient.axios.interceptors.response.use(
|
|
451
|
-
(response) => response,
|
|
452
|
-
(error) => {
|
|
453
|
-
if (error.response?.status === 500) {
|
|
454
|
-
toast.error("Server error");
|
|
455
|
-
}
|
|
456
|
-
return Promise.reject(error);
|
|
457
|
-
},
|
|
458
|
-
);
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
## Debugging
|
|
462
|
-
|
|
463
|
-
```tsx
|
|
464
|
-
// Log all requests/responses
|
|
465
|
-
customerClient.axios.interceptors.request.use((config) => {
|
|
466
|
-
console.log("📤", config.method?.toUpperCase(), config.url);
|
|
467
|
-
return config;
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
customerClient.axios.interceptors.response.use(
|
|
471
|
-
(response) => {
|
|
472
|
-
console.log("📥", response.status, response.config.url);
|
|
473
|
-
return response;
|
|
474
|
-
},
|
|
475
|
-
(error) => {
|
|
476
|
-
console.error("❌", error.config?.url, error.response?.status);
|
|
477
|
-
return Promise.reject(error);
|
|
478
|
-
},
|
|
479
|
-
);
|
|
480
|
-
```
|
|
481
|
-
|
|
482
|
-
## Module Integration Checklist
|
|
483
|
-
|
|
484
|
-
Before using this module, ensure:
|
|
485
|
-
|
|
486
|
-
- ✅ `@promakeai/customer-backend-client` package installed
|
|
487
|
-
- ✅ Environment variables configured (`.env` file)
|
|
488
|
-
- ✅ At least ONE of: `VITE_API_CUSTOMER` or `VITE_TENANT_UUID` is set
|
|
489
|
-
- ✅ `sonner` installed for toast notifications (optional but recommended)
|
|
490
|
-
|
|
491
|
-
## Architecture Notes
|
|
492
|
-
|
|
493
|
-
- **Singleton Instance**: Entire app uses one client instance
|
|
494
|
-
- **Token Management**: Handled automatically by auth module
|
|
495
|
-
- **Auto Retry**: 401 errors trigger token refresh and retry (via auth module)
|
|
496
|
-
- **Type Safety**: Full TypeScript support with auto-completion
|
|
497
|
-
- **JSON Parsing**: Responses automatically parsed
|
|
498
|
-
|
|
499
|
-
## Dependencies Summary
|
|
500
|
-
|
|
501
|
-
**Core** (Must not modify):
|
|
502
|
-
|
|
503
|
-
- `@promakeai/customer-backend-client` - API client package
|
|
504
|
-
- `customer-client.ts` - Client instance configuration
|
|
505
|
-
- `get-error-message.ts` - Error extraction utility
|
|
506
|
-
|
|
507
|
-
**Environment**:
|
|
508
|
-
|
|
509
|
-
- `VITE_API_CUSTOMER` or `VITE_TENANT_UUID` - API URL configuration
|
|
510
|
-
|
|
511
|
-
**Optional Integration**:
|
|
512
|
-
|
|
513
|
-
- `sonner` - Toast notifications (UI layer)
|
|
514
|
-
- `@tanstack/react-query` - Query management (UI layer)
|
|
515
|
-
- `@/modules/auth/use-auth` - Token management (auth layer)
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createClient,
|
|
3
|
-
type ApiClient,
|
|
4
|
-
} from "@promakeai/customer-backend-client";
|
|
5
|
-
import enValidation from "./validation/en.json";
|
|
6
|
-
import trValidation from "./validation/tr.json";
|
|
7
|
-
|
|
8
|
-
const customerClient = createClient({
|
|
9
|
-
baseURL:
|
|
10
|
-
import.meta.env.VITE_API_CUSTOMER ||
|
|
11
|
-
`https://${import.meta.env.VITE_TENANT_UUID}.backend.promake.ai/`,
|
|
12
|
-
messages: {
|
|
13
|
-
en: enValidation,
|
|
14
|
-
tr: trValidation,
|
|
15
|
-
},
|
|
16
|
-
defaultLanguage: "en",
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export { customerClient };
|
|
20
|
-
export type { ApiClient };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export function getErrorMessage(
|
|
2
|
-
err: unknown,
|
|
3
|
-
fallback: string = "An error occurred",
|
|
4
|
-
): string {
|
|
5
|
-
if (err && typeof err === "object") {
|
|
6
|
-
const e = err as {
|
|
7
|
-
response?: { data?: { error?: string; message?: string } };
|
|
8
|
-
message?: string;
|
|
9
|
-
};
|
|
10
|
-
return (
|
|
11
|
-
e.response?.data?.message ||
|
|
12
|
-
e.response?.data?.error ||
|
|
13
|
-
e.message ||
|
|
14
|
-
fallback
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
return fallback;
|
|
18
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"username_required": "Username is required",
|
|
3
|
-
"username_min_length": "Username must be at least 3 characters",
|
|
4
|
-
"email_invalid": "Invalid email address",
|
|
5
|
-
"email_required": "Email is required",
|
|
6
|
-
"password_required": "Password is required",
|
|
7
|
-
"password_min_length": "Password must be at least 8 characters",
|
|
8
|
-
"password_letter_required": "Password must contain at least 1 letter",
|
|
9
|
-
"password_number_required": "Password must contain at least 1 number",
|
|
10
|
-
"code_required": "Verification code is required",
|
|
11
|
-
"reset_code_required": "Reset code is required",
|
|
12
|
-
"session_id_required": "Session ID is required",
|
|
13
|
-
"quantity_positive": "Quantity must be a positive integer",
|
|
14
|
-
"product_name_required": "Product name is required",
|
|
15
|
-
"product_description_required": "Product description is required",
|
|
16
|
-
"amount_positive": "Amount must be a positive integer",
|
|
17
|
-
"image_required": "Image URL is required",
|
|
18
|
-
"firstname_required": "First name is required",
|
|
19
|
-
"lastname_required": "Last name is required",
|
|
20
|
-
"phone_required": "Phone number is required",
|
|
21
|
-
"address_required": "Address is required",
|
|
22
|
-
"country_required": "Country is required",
|
|
23
|
-
"city_required": "City is required",
|
|
24
|
-
"zip_required": "Zip code is required",
|
|
25
|
-
"currency_required": "Currency is required",
|
|
26
|
-
"tax_amount_non_negative": "Tax amount must be non-negative",
|
|
27
|
-
"at_least_one_product": "At least one product is required",
|
|
28
|
-
"payment_type_invalid": "Payment type must be 'stripe', 'iyzico', 'bank_transfer', or 'cash_on_delivery'"
|
|
29
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"username_required": "Kullanıcı adı zorunludur",
|
|
3
|
-
"username_min_length": "Kullanıcı adı en az 3 karakter olmalıdır",
|
|
4
|
-
"email_invalid": "Geçersiz e-posta adresi",
|
|
5
|
-
"email_required": "E-posta zorunludur",
|
|
6
|
-
"password_required": "Şifre zorunludur",
|
|
7
|
-
"password_min_length": "Şifre en az 8 karakter olmalıdır",
|
|
8
|
-
"password_letter_required": "Şifre en az 1 harf içermelidir",
|
|
9
|
-
"password_number_required": "Şifre en az 1 rakam içermelidir",
|
|
10
|
-
"code_required": "Doğrulama kodu zorunludur",
|
|
11
|
-
"reset_code_required": "Sıfırlama kodu zorunludur",
|
|
12
|
-
"session_id_required": "Oturum ID zorunludur",
|
|
13
|
-
"quantity_positive": "Miktar pozitif bir tam sayı olmalıdır",
|
|
14
|
-
"product_name_required": "Ürün adı zorunludur",
|
|
15
|
-
"product_description_required": "Ürün açıklaması zorunludur",
|
|
16
|
-
"amount_positive": "Tutar pozitif bir tam sayı olmalıdır",
|
|
17
|
-
"image_required": "Görsel URL zorunludur",
|
|
18
|
-
"firstname_required": "Ad zorunludur",
|
|
19
|
-
"lastname_required": "Soyad zorunludur",
|
|
20
|
-
"phone_required": "Telefon numarası zorunludur",
|
|
21
|
-
"address_required": "Adres zorunludur",
|
|
22
|
-
"country_required": "Ülke zorunludur",
|
|
23
|
-
"city_required": "Şehir zorunludur",
|
|
24
|
-
"zip_required": "Posta kodu zorunludur",
|
|
25
|
-
"currency_required": "Para birimi zorunludur",
|
|
26
|
-
"tax_amount_non_negative": "Vergi tutarı negatif olamaz",
|
|
27
|
-
"at_least_one_product": "En az bir ürün gereklidir",
|
|
28
|
-
"payment_type_invalid": "Ödeme tipi 'stripe', 'iyzico', 'bank_transfer' veya 'cash_on_delivery' olmalıdır"
|
|
29
|
-
}
|