@djust-b2b/djust-front-sdk 2.16.1 → 3.0.0-beta.1
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 +581 -26
- package/dist/djust-b2b-djust-front-sdk-3.0.0-beta.1.tgz +0 -0
- package/package.json +30 -8
- package/lib/helpers/parameters-validation.d.ts +0 -2
- package/lib/helpers/parameters-validation.js +0 -21
- package/lib/helpers/utils.d.ts +0 -4
- package/lib/helpers/utils.js +0 -29
- package/lib/index.d.ts +0 -183
- package/lib/index.js +0 -77
- package/lib/interfaces/index.d.ts +0 -10
- package/lib/interfaces/index.js +0 -26
- package/lib/interfaces/models/address.d.ts +0 -60
- package/lib/interfaces/models/address.js +0 -2
- package/lib/interfaces/models/attribute.d.ts +0 -30
- package/lib/interfaces/models/attribute.js +0 -2
- package/lib/interfaces/models/auth.d.ts +0 -17
- package/lib/interfaces/models/auth.js +0 -2
- package/lib/interfaces/models/cart.d.ts +0 -63
- package/lib/interfaces/models/cart.js +0 -2
- package/lib/interfaces/models/common.d.ts +0 -67
- package/lib/interfaces/models/common.js +0 -2
- package/lib/interfaces/models/custom-field.d.ts +0 -56
- package/lib/interfaces/models/custom-field.js +0 -2
- package/lib/interfaces/models/customer-account.d.ts +0 -47
- package/lib/interfaces/models/customer-account.js +0 -2
- package/lib/interfaces/models/customer-organisation.d.ts +0 -13
- package/lib/interfaces/models/customer-organisation.js +0 -2
- package/lib/interfaces/models/customer-user.d.ts +0 -109
- package/lib/interfaces/models/customer-user.js +0 -2
- package/lib/interfaces/models/incident.d.ts +0 -36
- package/lib/interfaces/models/incident.js +0 -2
- package/lib/interfaces/models/navigation-category.d.ts +0 -21
- package/lib/interfaces/models/navigation-category.js +0 -2
- package/lib/interfaces/models/offer.d.ts +0 -150
- package/lib/interfaces/models/offer.js +0 -2
- package/lib/interfaces/models/order.d.ts +0 -593
- package/lib/interfaces/models/order.js +0 -2
- package/lib/interfaces/models/payment.d.ts +0 -19
- package/lib/interfaces/models/payment.js +0 -2
- package/lib/interfaces/models/price.d.ts +0 -5
- package/lib/interfaces/models/price.js +0 -2
- package/lib/interfaces/models/product.d.ts +0 -223
- package/lib/interfaces/models/product.js +0 -2
- package/lib/interfaces/models/quote.d.ts +0 -76
- package/lib/interfaces/models/quote.js +0 -2
- package/lib/interfaces/models/searchProduct.d.ts +0 -127
- package/lib/interfaces/models/searchProduct.js +0 -2
- package/lib/interfaces/models/supplier.d.ts +0 -71
- package/lib/interfaces/models/supplier.js +0 -2
- package/lib/services/attributes/definitions.d.ts +0 -27
- package/lib/services/attributes/definitions.js +0 -2
- package/lib/services/attributes/index.d.ts +0 -32
- package/lib/services/attributes/index.js +0 -49
- package/lib/services/auth/__mocks__/auth.mocks.d.ts +0 -248
- package/lib/services/auth/__mocks__/auth.mocks.js +0 -220
- package/lib/services/auth/definitions.d.ts +0 -68
- package/lib/services/auth/definitions.js +0 -2
- package/lib/services/auth/definitions.requests.d.ts +0 -24
- package/lib/services/auth/definitions.requests.js +0 -5
- package/lib/services/auth/index.d.ts +0 -231
- package/lib/services/auth/index.js +0 -309
- package/lib/services/cart/definitions.d.ts +0 -83
- package/lib/services/cart/definitions.js +0 -2
- package/lib/services/cart/index.d.ts +0 -329
- package/lib/services/cart/index.js +0 -463
- package/lib/services/commercial-order/definitions.d.ts +0 -168
- package/lib/services/commercial-order/definitions.js +0 -2
- package/lib/services/commercial-order/index.d.ts +0 -709
- package/lib/services/commercial-order/index.js +0 -972
- package/lib/services/custom-field/definitions.d.ts +0 -106
- package/lib/services/custom-field/definitions.js +0 -60
- package/lib/services/custom-field/index.d.ts +0 -114
- package/lib/services/custom-field/index.js +0 -143
- package/lib/services/customer-account/definitions.d.ts +0 -163
- package/lib/services/customer-account/definitions.js +0 -2
- package/lib/services/customer-account/index.d.ts +0 -655
- package/lib/services/customer-account/index.js +0 -933
- package/lib/services/customer-user/definitions.d.ts +0 -83
- package/lib/services/customer-user/definitions.js +0 -2
- package/lib/services/customer-user/index.d.ts +0 -393
- package/lib/services/customer-user/index.js +0 -527
- package/lib/services/incident/definitions.d.ts +0 -84
- package/lib/services/incident/definitions.js +0 -2
- package/lib/services/incident/index.d.ts +0 -269
- package/lib/services/incident/index.js +0 -387
- package/lib/services/logistic-order/definitions.d.ts +0 -292
- package/lib/services/logistic-order/definitions.js +0 -2
- package/lib/services/logistic-order/index.d.ts +0 -1299
- package/lib/services/logistic-order/index.js +0 -1720
- package/lib/services/navigation-category/definitions.d.ts +0 -30
- package/lib/services/navigation-category/definitions.js +0 -2
- package/lib/services/navigation-category/index.d.ts +0 -113
- package/lib/services/navigation-category/index.js +0 -159
- package/lib/services/offer-inventories/definitions.d.ts +0 -72
- package/lib/services/offer-inventories/definitions.js +0 -2
- package/lib/services/offer-inventories/index.d.ts +0 -119
- package/lib/services/offer-inventories/index.js +0 -174
- package/lib/services/offer-prices/__mocks__/offer-prices.mocks.d.ts +0 -108
- package/lib/services/offer-prices/__mocks__/offer-prices.mocks.js +0 -200
- package/lib/services/offer-prices/definitions.d.ts +0 -23
- package/lib/services/offer-prices/definitions.js +0 -2
- package/lib/services/offer-prices/index.d.ts +0 -35
- package/lib/services/offer-prices/index.js +0 -52
- package/lib/services/operation/definitions.d.ts +0 -279
- package/lib/services/operation/definitions.js +0 -17
- package/lib/services/operation/index.d.ts +0 -519
- package/lib/services/operation/index.js +0 -703
- package/lib/services/payment/definitions.d.ts +0 -78
- package/lib/services/payment/definitions.js +0 -2
- package/lib/services/payment/index.d.ts +0 -149
- package/lib/services/payment/index.js +0 -219
- package/lib/services/product/definitions.d.ts +0 -148
- package/lib/services/product/definitions.js +0 -8
- package/lib/services/product/index.d.ts +0 -386
- package/lib/services/product/index.js +0 -561
- package/lib/services/product-variant/definitions.d.ts +0 -171
- package/lib/services/product-variant/definitions.js +0 -7
- package/lib/services/product-variant/index.d.ts +0 -122
- package/lib/services/product-variant/index.js +0 -171
- package/lib/services/quote/definitions.d.ts +0 -99
- package/lib/services/quote/definitions.js +0 -2
- package/lib/services/quote/index.d.ts +0 -376
- package/lib/services/quote/index.js +0 -503
- package/lib/services/supplier/__mocks__/supplier-mocks.d.ts +0 -48
- package/lib/services/supplier/__mocks__/supplier-mocks.js +0 -167
- package/lib/services/supplier/definitions.d.ts +0 -29
- package/lib/services/supplier/definitions.js +0 -2
- package/lib/services/supplier/index.d.ts +0 -101
- package/lib/services/supplier/index.js +0 -145
- package/lib/settings/fetch-instance.d.ts +0 -28
- package/lib/settings/fetch-instance.js +0 -227
package/README.md
CHANGED
|
@@ -1,50 +1,605 @@
|
|
|
1
|
-
#
|
|
1
|
+
# DJUST Front SDK
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
> **Universal TypeScript SDK for DJUST B2B API**
|
|
4
|
+
> SSR-safe, type-safe, production-ready.
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/@djust-b2b/djust-front-sdk)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
|
|
10
|
+
**DJUST Front SDK** is a comprehensive JavaScript/TypeScript development kit designed to simplify and optimize API calls to the DJUST backend. It offers a secure, high-performance, and ready-to-use solution for integration partners, facilitating the implementation of robust B2B e-commerce solutions.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## ✨ Features
|
|
15
|
+
|
|
16
|
+
### 🔒 **Security First**
|
|
17
|
+
- Secure token management with HTTP-only cookies support
|
|
18
|
+
- SSR-safe architecture prevents state leakage
|
|
19
|
+
- Built-in authentication lifecycle hooks
|
|
20
|
+
- Comprehensive error handling with typed exceptions
|
|
21
|
+
|
|
22
|
+
### ⚡ **Performance Optimized**
|
|
23
|
+
- **Request deduplication** - Automatic duplicate request prevention
|
|
24
|
+
- **Response caching** - Configurable TTL with stale-while-revalidate
|
|
25
|
+
- **Request batching** - Automatic batching of parallel requests
|
|
26
|
+
- **Performance monitoring** - Built-in metrics and monitoring
|
|
27
|
+
|
|
28
|
+
### 🎯 **Type-Safe**
|
|
29
|
+
- Full TypeScript support with strict typing
|
|
30
|
+
- Auto-completion in IDEs
|
|
31
|
+
- Request/Response interfaces for all operations
|
|
32
|
+
- Type guards and runtime validation
|
|
33
|
+
|
|
34
|
+
### 🧩 **Universal Compatibility**
|
|
35
|
+
- Works in **Node.js**, **Browser**, and **SSR** environments
|
|
36
|
+
- Compatible with **Vue.js**, **React**, **Nuxt**, **Next.js**, **Angular**
|
|
37
|
+
- Framework-agnostic design
|
|
38
|
+
- Tree-shakeable modules
|
|
39
|
+
|
|
40
|
+
### 🔧 **Developer Experience**
|
|
41
|
+
- Modular service architecture
|
|
42
|
+
- Comprehensive documentation
|
|
43
|
+
- Extensive examples and guides
|
|
44
|
+
- Production-ready error handling
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 📦 Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# npm
|
|
52
|
+
npm install @djust-b2b/djust-front-sdk
|
|
53
|
+
|
|
54
|
+
# yarn
|
|
55
|
+
yarn add @djust-b2b/djust-front-sdk
|
|
56
|
+
|
|
57
|
+
# pnpm
|
|
58
|
+
pnpm add @djust-b2b/djust-front-sdk
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 🚀 Quick Start
|
|
64
|
+
|
|
65
|
+
### Basic Usage
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { createDjustClient } from '@djust-b2b/djust-front-sdk';
|
|
69
|
+
|
|
70
|
+
// Create client instance
|
|
71
|
+
const client = createDjustClient({
|
|
72
|
+
baseUrl: 'https://api.djust.io',
|
|
73
|
+
clientId: 'your-client-id',
|
|
74
|
+
apiKey: 'your-api-key',
|
|
75
|
+
locale: 'fr-FR',
|
|
76
|
+
storeId: 'store-123',
|
|
77
|
+
storeViewId: 'view-456',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Create scoped client with authentication
|
|
81
|
+
const sdk = client.withContext({
|
|
82
|
+
accessToken: 'your-access-token',
|
|
83
|
+
customerAccountId: 'account-123',
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Use the SDK
|
|
87
|
+
const cart = await sdk.getCart({
|
|
88
|
+
cartId: 'cart-123',
|
|
89
|
+
currency: 'EUR',
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const products = await sdk.getProductsList({
|
|
93
|
+
locale: 'fr-FR',
|
|
94
|
+
pageable: { page: 0, size: 20 },
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### SSR Usage (Nuxt/Next.js)
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
// server/api/cart.get.ts (Nuxt)
|
|
102
|
+
import { useDjustSDK } from '~/server/utils/djust-sdk';
|
|
103
|
+
|
|
104
|
+
export default defineEventHandler(async (event) => {
|
|
105
|
+
const sdk = useDjustSDK(event); // Automatically reads cookies
|
|
106
|
+
|
|
107
|
+
const cart = await sdk.getCart({
|
|
108
|
+
cartId: 'cart-123',
|
|
109
|
+
currency: 'EUR',
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return cart;
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Client-Side Usage
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
// app/composables/useCart.ts (Nuxt)
|
|
120
|
+
import { createDjustClient } from '@djust-b2b/djust-front-sdk';
|
|
121
|
+
|
|
122
|
+
export const useCart = () => {
|
|
123
|
+
const { $config } = useNuxtApp();
|
|
124
|
+
const { token } = useAuth(); // Your auth composable
|
|
125
|
+
|
|
126
|
+
const client = createDjustClient({
|
|
127
|
+
baseUrl: $config.public.apiBaseUrl,
|
|
128
|
+
clientId: $config.public.apiClientId,
|
|
129
|
+
apiKey: $config.public.apiKey,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const sdk = client.withContext({
|
|
133
|
+
accessToken: token.value,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
getCart: (cartId: string) => sdk.getCart({ cartId, currency: 'EUR' }),
|
|
138
|
+
updateCart: (params: UpdateCartParams) => sdk.updateCart(params),
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 📚 Documentation
|
|
146
|
+
|
|
147
|
+
### For Users
|
|
148
|
+
|
|
149
|
+
- **[Getting Started Guide](https://djust-sdk-docs.vercel.app/docs/getting-started/introduction)** - Complete setup guide
|
|
150
|
+
- **[API Reference](https://djust-sdk-docs.vercel.app/docs/api)** - Full API documentation
|
|
151
|
+
- **[Guides](https://djust-sdk-docs.vercel.app/docs/guides)** - Performance, SSR, error handling
|
|
152
|
+
- **[Examples](https://djust-sdk-docs.vercel.app/docs/examples)** - Code examples and patterns
|
|
153
|
+
|
|
154
|
+
### For Developers
|
|
155
|
+
|
|
156
|
+
All development documentation is located in [`doc/development/`](./doc/development/):
|
|
157
|
+
|
|
158
|
+
- **[Guidelines Index](./doc/development/GUIDELINES_INDEX.md)** - 📖 Quick reference to all guidelines
|
|
159
|
+
- **[Developer Guide](./doc/development/DEVELOPER_GUIDE.md)** - Architecture and development patterns
|
|
160
|
+
- **[Development Guidelines](./doc/development/GUIDELINES.md)** - Coding standards and best practices
|
|
161
|
+
- **[Code Review Guidelines](./doc/development/GUIDELINES_CODE_REVIEW.md)** - Review process and checklist
|
|
162
|
+
- **[Contributing Guide](./doc/development/CONTRIBUTING.md)** - How to contribute
|
|
163
|
+
- **[Service Templates](./doc/development/.templates/)** - Templates for creating services
|
|
164
|
+
|
|
165
|
+
> 📁 See [doc/development/README.md](./doc/development/README.md) for documentation structure
|
|
166
|
+
|
|
167
|
+
### Quick Links
|
|
168
|
+
|
|
169
|
+
| Topic | Link |
|
|
170
|
+
|-------|------|
|
|
171
|
+
| Architecture | [Architecture Overview](./doc/development/DEVELOPER_GUIDE.md#architecture-overview) |
|
|
172
|
+
| Creating Services | [Creating a New Service](./doc/development/DEVELOPER_GUIDE.md#creating-a-new-service) |
|
|
173
|
+
| Code Style | [Code Style Guidelines](./doc/development/GUIDELINES.md#code-style-guidelines) |
|
|
174
|
+
| TypeScript | [TypeScript Guidelines](./doc/development/GUIDELINES.md#typescript-guidelines) |
|
|
175
|
+
| Error Handling | [Error Handling Guidelines](./doc/development/GUIDELINES.md#error-handling-guidelines) |
|
|
176
|
+
| Testing | [Testing Guidelines](./doc/development/GUIDELINES.md#testing-guidelines) |
|
|
177
|
+
| Code Review | [Review Checklist](./doc/development/GUIDELINES_CODE_REVIEW.md#review-checklist) |
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 🎯 Key Features in Detail
|
|
182
|
+
|
|
183
|
+
### SSR-Safe Architecture
|
|
184
|
+
|
|
185
|
+
The SDK uses request-scoped instances to prevent state leakage in SSR environments:
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
// Each request gets its own scoped client
|
|
189
|
+
const sdk = client.withContext({
|
|
190
|
+
accessToken: getCookie(event, 'token'),
|
|
191
|
+
customerAccountId: getCookie(event, 'customer-account-id'),
|
|
192
|
+
requestId: `ssr-${Date.now()}`,
|
|
193
|
+
});
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Performance Optimizations
|
|
197
|
+
|
|
198
|
+
Enable performance features in client configuration:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
const client = createDjustClient({
|
|
202
|
+
// ... base config
|
|
203
|
+
performance: {
|
|
204
|
+
deduplication: true, // Prevent duplicate requests
|
|
205
|
+
cache: true, // Enable response caching
|
|
206
|
+
cacheTTL: 30000, // 30 seconds TTL
|
|
207
|
+
staleWhileRevalidate: true, // Serve stale while revalidating
|
|
208
|
+
compression: true, // Enable compression
|
|
209
|
+
keepAlive: true, // HTTP keep-alive
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Error Handling
|
|
215
|
+
|
|
216
|
+
Structured error model with typed exceptions:
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import {
|
|
220
|
+
ValidationError,
|
|
221
|
+
NotFoundError,
|
|
222
|
+
ForbiddenError,
|
|
223
|
+
} from '@djust-b2b/djust-front-sdk';
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
const cart = await sdk.getCart({ cartId: 'invalid' });
|
|
227
|
+
} catch (error) {
|
|
228
|
+
if (error instanceof ValidationError) {
|
|
229
|
+
console.error('Invalid parameters:', error.message);
|
|
230
|
+
} else if (error instanceof NotFoundError) {
|
|
231
|
+
console.error('Cart not found');
|
|
232
|
+
} else if (error instanceof ForbiddenError) {
|
|
233
|
+
console.error('Access denied');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Authentication Hooks
|
|
239
|
+
|
|
240
|
+
Subscribe to authentication lifecycle events:
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
const client = createDjustClient({
|
|
244
|
+
// ... config
|
|
245
|
+
authHooks: {
|
|
246
|
+
onLogin: async (ctx) => {
|
|
247
|
+
console.log('User logged in:', ctx.userId);
|
|
248
|
+
// Update your app state
|
|
249
|
+
},
|
|
250
|
+
onTokenRefresh: async (ctx) => {
|
|
251
|
+
console.log('Token refreshed:', ctx.requestId);
|
|
252
|
+
// Update token in your store
|
|
253
|
+
},
|
|
254
|
+
onLogout: async () => {
|
|
255
|
+
console.log('User logged out');
|
|
256
|
+
// Clear app state
|
|
257
|
+
},
|
|
258
|
+
onAuthFailure: async (ctx) => {
|
|
259
|
+
console.error('Auth failed:', ctx.endpoint);
|
|
260
|
+
// Handle auth failure
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## 🏗️ Architecture
|
|
269
|
+
|
|
270
|
+
The SDK follows a modular, service-based architecture:
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
┌─────────────────────────────────────┐
|
|
274
|
+
│ createDjustClient() │
|
|
275
|
+
│ (Client Factory) │
|
|
276
|
+
└──────────────┬──────────────────────┘
|
|
277
|
+
│
|
|
278
|
+
┌──────────┴──────────┐
|
|
279
|
+
│ │
|
|
280
|
+
┌───▼──────┐ ┌───────▼────────┐
|
|
281
|
+
│ Transport│ │ Service Factory│
|
|
282
|
+
│ (HTTP) │ │ (Registry) │
|
|
283
|
+
└───┬──────┘ └───────┬────────┘
|
|
284
|
+
│ │
|
|
285
|
+
└──────────┬──────────┘
|
|
286
|
+
│
|
|
287
|
+
┌──────────▼──────────┐
|
|
288
|
+
│ Services │
|
|
289
|
+
│ (Auth, Cart, │
|
|
290
|
+
│ Product, etc.) │
|
|
291
|
+
└────────────────────┘
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Available Services
|
|
295
|
+
|
|
296
|
+
- **Auth** - Authentication and user management
|
|
297
|
+
- **Cart** - Shopping cart operations
|
|
298
|
+
- **Product** - Product catalog and search
|
|
299
|
+
- **Commercial Order** - Order management
|
|
300
|
+
- **Logistic Order** - Shipping and logistics
|
|
301
|
+
- **Quote** - B2B quote management
|
|
302
|
+
- **Customer Account** - Account management
|
|
303
|
+
- **Customer User** - User profile management
|
|
304
|
+
- **Supplier** - Supplier information
|
|
305
|
+
- **Payment** - Payment processing
|
|
306
|
+
- **Navigation** - Category navigation
|
|
307
|
+
- And more...
|
|
308
|
+
|
|
309
|
+
See [Services Reference](./doc/docs/guides/services.mdx) for complete list.
|
|
4
310
|
|
|
5
311
|
---
|
|
6
312
|
|
|
7
|
-
##
|
|
313
|
+
## 🔧 Configuration
|
|
314
|
+
|
|
315
|
+
### Client Configuration
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
interface DjustClientConfig {
|
|
319
|
+
baseUrl: string; // DJUST API base URL
|
|
320
|
+
clientId: string; // Client ID (dj-client header)
|
|
321
|
+
apiKey: string; // API Key (dj-api-key header)
|
|
322
|
+
timeout?: number; // Request timeout (default: 30000)
|
|
323
|
+
locale?: string; // Default locale
|
|
324
|
+
storeId?: string; // Default store ID
|
|
325
|
+
storeViewId?: string; // Default store view ID
|
|
326
|
+
strictErrors?: boolean; // Use SDKError (default: false)
|
|
327
|
+
retry?: RetryConfig; // Retry configuration
|
|
328
|
+
performance?: PerformanceConfig; // Performance options
|
|
329
|
+
authHooks?: AuthHooks; // Authentication hooks
|
|
330
|
+
debug?: boolean; // Debug mode
|
|
331
|
+
}
|
|
332
|
+
```
|
|
8
333
|
|
|
9
|
-
###
|
|
10
|
-
Ensure secure communications between your frontend applications and the DJUST backend through integrated mechanisms for managing requests and responses.
|
|
334
|
+
### Performance Configuration
|
|
11
335
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
336
|
+
```typescript
|
|
337
|
+
interface PerformanceConfig {
|
|
338
|
+
deduplication?: boolean; // Request deduplication
|
|
339
|
+
cache?: boolean; // Response caching
|
|
340
|
+
cacheTTL?: number; // Cache TTL in ms
|
|
341
|
+
staleWhileRevalidate?: boolean; // SWR strategy
|
|
342
|
+
compression?: boolean; // Enable compression
|
|
343
|
+
keepAlive?: boolean; // HTTP keep-alive
|
|
344
|
+
}
|
|
345
|
+
```
|
|
16
346
|
|
|
17
|
-
###
|
|
18
|
-
- **Easy to configure** : A clear and documented API for a quick start.
|
|
19
|
-
- **Universal** : Compatible with all JavaScript environments (Vue.js, React, Nuxt, Angular, etc.).
|
|
347
|
+
### Retry Configuration
|
|
20
348
|
|
|
21
|
-
|
|
22
|
-
|
|
349
|
+
```typescript
|
|
350
|
+
interface RetryConfig {
|
|
351
|
+
enabled?: boolean; // Enable retries
|
|
352
|
+
maxAttempts?: number; // Max retry attempts
|
|
353
|
+
retryableStatuses?: number[]; // Status codes to retry
|
|
354
|
+
}
|
|
355
|
+
```
|
|
23
356
|
|
|
24
357
|
---
|
|
25
358
|
|
|
26
|
-
##
|
|
359
|
+
## 📖 Examples
|
|
360
|
+
|
|
361
|
+
### Authentication
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
// Login
|
|
365
|
+
const { token, refreshToken, user } = await sdk.login({
|
|
366
|
+
username: 'user@example.com',
|
|
367
|
+
password: 'password',
|
|
368
|
+
withUser: true,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// Refresh token
|
|
372
|
+
const newToken = await sdk.refreshToken({
|
|
373
|
+
refreshToken: refreshToken,
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
// Get authenticated user
|
|
377
|
+
const user = await sdk.getAuthenticatedUser();
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
### Shopping Cart
|
|
381
|
+
|
|
382
|
+
```typescript
|
|
383
|
+
// Get cart
|
|
384
|
+
const cart = await sdk.getCart({
|
|
385
|
+
cartId: 'cart-123',
|
|
386
|
+
currency: 'EUR',
|
|
387
|
+
nbFirstLines: 10,
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
// Update cart lines
|
|
391
|
+
await sdk.updateCartLines({
|
|
392
|
+
cartId: 'cart-123',
|
|
393
|
+
linesToAdd: [
|
|
394
|
+
{ offerPriceId: 'price-1', quantity: 5 },
|
|
395
|
+
],
|
|
396
|
+
linesToUpdate: [
|
|
397
|
+
{ lineId: 'line-1', quantity: 10 },
|
|
398
|
+
],
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
// Convert to order
|
|
402
|
+
const order = await sdk.initializeOrders({
|
|
403
|
+
cartId: 'cart-123',
|
|
404
|
+
shippingAddressId: 'addr-123',
|
|
405
|
+
});
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### Products
|
|
409
|
+
|
|
410
|
+
```typescript
|
|
411
|
+
// Search products
|
|
412
|
+
const results = await sdk.getProductsList({
|
|
413
|
+
locale: 'fr-FR',
|
|
414
|
+
filters: { categoryId: 'cat-123' },
|
|
415
|
+
pageable: { page: 0, size: 20 },
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
// Get product details
|
|
419
|
+
const product = await sdk.getProduct({
|
|
420
|
+
productIdentifier: 'SKU-123',
|
|
421
|
+
productIdType: 'SKU',
|
|
422
|
+
locale: 'fr-FR',
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
// Get product offers
|
|
426
|
+
const offers = await sdk.getProductPaginatedOffers({
|
|
427
|
+
productVariantId: 'variant-123',
|
|
428
|
+
pageable: { page: 0, size: 20 },
|
|
429
|
+
});
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### Orders
|
|
433
|
+
|
|
434
|
+
```typescript
|
|
435
|
+
// Get orders
|
|
436
|
+
const orders = await sdk.getCommercialOrders({
|
|
437
|
+
locale: 'fr-FR',
|
|
438
|
+
pageable: { page: 0, size: 10 },
|
|
439
|
+
});
|
|
27
440
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
441
|
+
// Get order details
|
|
442
|
+
const order = await sdk.getCommercialOrder({
|
|
443
|
+
commercialOrderId: 'order-123',
|
|
444
|
+
locale: 'fr-FR',
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
// Create order from cart
|
|
448
|
+
const newOrder = await sdk.createCommercialOrder({
|
|
449
|
+
channel: 'DESKTOP',
|
|
450
|
+
locale: 'fr-FR',
|
|
451
|
+
origin: 'CART',
|
|
452
|
+
originId: 'cart-123',
|
|
453
|
+
});
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
## 🛡️ Security Best Practices
|
|
459
|
+
|
|
460
|
+
### Token Management
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
// ✅ Good - Use HTTP-only cookies in SSR
|
|
464
|
+
// Server-side
|
|
465
|
+
setCookie(event, 'token', token, {
|
|
466
|
+
httpOnly: true,
|
|
467
|
+
secure: true,
|
|
468
|
+
sameSite: 'strict',
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
// ✅ Good - Don't log tokens
|
|
472
|
+
// Never do this:
|
|
473
|
+
console.log('Token:', token); // ❌
|
|
474
|
+
|
|
475
|
+
// ✅ Good - Validate tokens
|
|
476
|
+
if (!isValidToken(token)) {
|
|
477
|
+
throw new Error('Invalid token');
|
|
478
|
+
}
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
### Input Validation
|
|
482
|
+
|
|
483
|
+
```typescript
|
|
484
|
+
// ✅ Good - Validate before sending
|
|
485
|
+
async getCart(params: GetCartParams) {
|
|
486
|
+
this.required(params, ['cartId', 'currency']);
|
|
487
|
+
|
|
488
|
+
// Additional validation
|
|
489
|
+
if (!/^[a-zA-Z0-9-]+$/.test(params.cartId)) {
|
|
490
|
+
throw ValidationError.invalidParameter('cartId');
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return this.request(...);
|
|
494
|
+
}
|
|
495
|
+
```
|
|
32
496
|
|
|
33
497
|
---
|
|
34
498
|
|
|
35
|
-
##
|
|
499
|
+
## 🧪 Testing
|
|
500
|
+
|
|
501
|
+
The SDK includes comprehensive test coverage:
|
|
502
|
+
|
|
503
|
+
```bash
|
|
504
|
+
# Run tests
|
|
505
|
+
npm test
|
|
36
506
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
507
|
+
# Run tests in watch mode
|
|
508
|
+
npm run test:ui
|
|
509
|
+
|
|
510
|
+
# Run tests with coverage
|
|
511
|
+
npm run coverage
|
|
512
|
+
```
|
|
40
513
|
|
|
41
514
|
---
|
|
42
515
|
|
|
43
|
-
##
|
|
516
|
+
## 📊 Performance Monitoring
|
|
517
|
+
|
|
518
|
+
Access performance metrics:
|
|
44
519
|
|
|
45
|
-
|
|
520
|
+
```typescript
|
|
521
|
+
const metrics = client.getMetrics();
|
|
46
522
|
|
|
523
|
+
console.log('Total requests:', metrics.totalRequests);
|
|
524
|
+
console.log('Cache hits:', metrics.cacheHits);
|
|
525
|
+
console.log('Cache misses:', metrics.cacheMisses);
|
|
526
|
+
console.log('Average response time:', metrics.avgResponseTime);
|
|
527
|
+
```
|
|
47
528
|
|
|
48
529
|
---
|
|
49
530
|
|
|
50
|
-
|
|
531
|
+
## 🤝 Contributing
|
|
532
|
+
|
|
533
|
+
We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
|
|
534
|
+
|
|
535
|
+
### Quick Start for Contributors
|
|
536
|
+
|
|
537
|
+
1. Fork the repository
|
|
538
|
+
2. Create a feature branch: `git checkout -b feat/your-feature`
|
|
539
|
+
3. Make your changes following our [Guidelines](./doc/development/GUIDELINES.md)
|
|
540
|
+
4. Write tests for your changes
|
|
541
|
+
5. Commit using conventional commits: `npm run commit`
|
|
542
|
+
6. Push and create a Merge Request
|
|
543
|
+
|
|
544
|
+
### Development Setup
|
|
545
|
+
|
|
546
|
+
```bash
|
|
547
|
+
# Clone repository
|
|
548
|
+
git clone https://gitlab.com/djustlab/front/djust-front-sdk.git
|
|
549
|
+
cd djust-front-sdk
|
|
550
|
+
|
|
551
|
+
# Install dependencies
|
|
552
|
+
npm install
|
|
553
|
+
|
|
554
|
+
# Run tests
|
|
555
|
+
npm test
|
|
556
|
+
|
|
557
|
+
# Build
|
|
558
|
+
npm run build
|
|
559
|
+
|
|
560
|
+
# Format code
|
|
561
|
+
npm run format
|
|
562
|
+
|
|
563
|
+
# Lint
|
|
564
|
+
npm run lint
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
---
|
|
568
|
+
|
|
569
|
+
## 📝 Changelog
|
|
570
|
+
|
|
571
|
+
See [CHANGELOG.md](./CHANGELOG.md) for a detailed list of changes.
|
|
572
|
+
|
|
573
|
+
---
|
|
574
|
+
|
|
575
|
+
## 🐛 Reporting Issues
|
|
576
|
+
|
|
577
|
+
Found a bug or have a feature request? Please open an issue on [GitLab Issues](https://gitlab.com/djustlab/front/djust-front-sdk/issues).
|
|
578
|
+
|
|
579
|
+
---
|
|
580
|
+
|
|
581
|
+
## 📄 License
|
|
582
|
+
|
|
583
|
+
DJUST Front SDK is distributed under the **MIT License**. See [LICENSE](./LICENSE) for details.
|
|
584
|
+
|
|
585
|
+
---
|
|
586
|
+
|
|
587
|
+
## 🔗 Links
|
|
588
|
+
|
|
589
|
+
- **Documentation**: [https://djust-sdk-docs.vercel.app](https://djust-sdk-docs.vercel.app)
|
|
590
|
+
- **GitLab Repository**: [https://gitlab.com/djustlab/front/djust-front-sdk](https://gitlab.com/djustlab/front/djust-front-sdk)
|
|
591
|
+
- **Issues**: [https://gitlab.com/djustlab/front/djust-front-sdk/issues](https://gitlab.com/djustlab/front/djust-front-sdk/issues)
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
## 💬 Support
|
|
596
|
+
|
|
597
|
+
- **Documentation**: Check our [documentation site](https://djust-sdk-docs.vercel.app)
|
|
598
|
+
- **Issues**: Open an issue on [GitLab](https://gitlab.com/djustlab/front/djust-front-sdk/issues)
|
|
599
|
+
- **Team Chat**: Contact the development team
|
|
600
|
+
|
|
601
|
+
---
|
|
602
|
+
|
|
603
|
+
**Built with ❤️ by the DJUST team**
|
|
604
|
+
|
|
605
|
+
With **DJUST Front SDK**, simplify your backend integrations, ensure exceptional performance, and provide reliable and secure e-commerce solutions for your clients.
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,21 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djust-b2b/djust-front-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "DJUST Front SDK
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
|
+
"description": "DJUST Front SDK - Universal TypeScript SDK for DJUST B2B API. SSR-safe, type-safe, production-ready.",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"sideEffects": false,
|
|
7
16
|
"scripts": {
|
|
8
17
|
"test": "vitest",
|
|
9
18
|
"test:ui": "vitest --ui",
|
|
10
19
|
"test:run": "vitest run",
|
|
11
20
|
"coverage": "vitest run --coverage",
|
|
12
|
-
"
|
|
21
|
+
"clean": "rm -rf lib",
|
|
22
|
+
"build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:types",
|
|
23
|
+
"build:cjs": "tsc --project tsconfig.json",
|
|
24
|
+
"build:esm": "tsc --project tsconfig.esm.json",
|
|
25
|
+
"build:types": "tsc --project tsconfig.json --emitDeclarationOnly --declaration --declarationMap",
|
|
26
|
+
"build:fast": "esbuild src/index.ts --bundle --platform=node --target=es2020 --outfile=lib/index.js --external:@sentry/browser --external:query-string --external:isomorphic-fetch",
|
|
27
|
+
"build:analyze": "esbuild src/index.ts --bundle --metafile=meta.json && cat meta.json | esbuild-visualizer --metadata ./meta.json --filename stats.html",
|
|
13
28
|
"prepare": "npm run build",
|
|
14
29
|
"format": "prettier --write src",
|
|
30
|
+
"lint": "tsc --noEmit",
|
|
15
31
|
"version": "npm run format && git add -A src",
|
|
16
32
|
"semantic-release": "semantic-release",
|
|
33
|
+
"semantic-release:dry-run": "semantic-release --dry-run",
|
|
34
|
+
"semantic-release:debug": "semantic-release --debug",
|
|
35
|
+
"verify-version": "node scripts/verify-version.js",
|
|
36
|
+
"preversion": "npm run verify-version",
|
|
17
37
|
"commit": "cz",
|
|
18
|
-
"prepack": "npmignore --auto"
|
|
38
|
+
"prepack": "npmignore --auto",
|
|
39
|
+
"perf:test": "node --expose-gc scripts/perf-test.js"
|
|
19
40
|
},
|
|
20
41
|
"keywords": [],
|
|
21
42
|
"author": "sami@djust.io",
|
|
@@ -29,6 +50,7 @@
|
|
|
29
50
|
"@types/node": "^18.7.16",
|
|
30
51
|
"@vitest/coverage-v8": "3.0.9",
|
|
31
52
|
"@vitest/ui": "3.0.9",
|
|
53
|
+
"conventional-changelog-conventionalcommits": "^6.0.0",
|
|
32
54
|
"cz-conventional-changelog": "^3.3.0",
|
|
33
55
|
"dotenv": "^16.0.2",
|
|
34
56
|
"esbuild": "^0.20.1",
|
|
@@ -44,11 +66,11 @@
|
|
|
44
66
|
"typedoc": "0.27.3",
|
|
45
67
|
"typedoc-plugin-markdown": "4.3.1",
|
|
46
68
|
"typescript": "^5.6.3",
|
|
69
|
+
"unbuild": "^3.6.1",
|
|
47
70
|
"vitest": "3.0.9"
|
|
48
71
|
},
|
|
49
72
|
"files": [
|
|
50
|
-
"
|
|
51
|
-
"lib/**/**.d.ts"
|
|
73
|
+
"dist"
|
|
52
74
|
],
|
|
53
75
|
"dependencies": {
|
|
54
76
|
"@sentry/browser": "^9.2.0",
|