@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.
Files changed (131) hide show
  1. package/README.md +581 -26
  2. package/dist/djust-b2b-djust-front-sdk-3.0.0-beta.1.tgz +0 -0
  3. package/package.json +30 -8
  4. package/lib/helpers/parameters-validation.d.ts +0 -2
  5. package/lib/helpers/parameters-validation.js +0 -21
  6. package/lib/helpers/utils.d.ts +0 -4
  7. package/lib/helpers/utils.js +0 -29
  8. package/lib/index.d.ts +0 -183
  9. package/lib/index.js +0 -77
  10. package/lib/interfaces/index.d.ts +0 -10
  11. package/lib/interfaces/index.js +0 -26
  12. package/lib/interfaces/models/address.d.ts +0 -60
  13. package/lib/interfaces/models/address.js +0 -2
  14. package/lib/interfaces/models/attribute.d.ts +0 -30
  15. package/lib/interfaces/models/attribute.js +0 -2
  16. package/lib/interfaces/models/auth.d.ts +0 -17
  17. package/lib/interfaces/models/auth.js +0 -2
  18. package/lib/interfaces/models/cart.d.ts +0 -63
  19. package/lib/interfaces/models/cart.js +0 -2
  20. package/lib/interfaces/models/common.d.ts +0 -67
  21. package/lib/interfaces/models/common.js +0 -2
  22. package/lib/interfaces/models/custom-field.d.ts +0 -56
  23. package/lib/interfaces/models/custom-field.js +0 -2
  24. package/lib/interfaces/models/customer-account.d.ts +0 -47
  25. package/lib/interfaces/models/customer-account.js +0 -2
  26. package/lib/interfaces/models/customer-organisation.d.ts +0 -13
  27. package/lib/interfaces/models/customer-organisation.js +0 -2
  28. package/lib/interfaces/models/customer-user.d.ts +0 -109
  29. package/lib/interfaces/models/customer-user.js +0 -2
  30. package/lib/interfaces/models/incident.d.ts +0 -36
  31. package/lib/interfaces/models/incident.js +0 -2
  32. package/lib/interfaces/models/navigation-category.d.ts +0 -21
  33. package/lib/interfaces/models/navigation-category.js +0 -2
  34. package/lib/interfaces/models/offer.d.ts +0 -150
  35. package/lib/interfaces/models/offer.js +0 -2
  36. package/lib/interfaces/models/order.d.ts +0 -593
  37. package/lib/interfaces/models/order.js +0 -2
  38. package/lib/interfaces/models/payment.d.ts +0 -19
  39. package/lib/interfaces/models/payment.js +0 -2
  40. package/lib/interfaces/models/price.d.ts +0 -5
  41. package/lib/interfaces/models/price.js +0 -2
  42. package/lib/interfaces/models/product.d.ts +0 -223
  43. package/lib/interfaces/models/product.js +0 -2
  44. package/lib/interfaces/models/quote.d.ts +0 -76
  45. package/lib/interfaces/models/quote.js +0 -2
  46. package/lib/interfaces/models/searchProduct.d.ts +0 -127
  47. package/lib/interfaces/models/searchProduct.js +0 -2
  48. package/lib/interfaces/models/supplier.d.ts +0 -71
  49. package/lib/interfaces/models/supplier.js +0 -2
  50. package/lib/services/attributes/definitions.d.ts +0 -27
  51. package/lib/services/attributes/definitions.js +0 -2
  52. package/lib/services/attributes/index.d.ts +0 -32
  53. package/lib/services/attributes/index.js +0 -49
  54. package/lib/services/auth/__mocks__/auth.mocks.d.ts +0 -248
  55. package/lib/services/auth/__mocks__/auth.mocks.js +0 -220
  56. package/lib/services/auth/definitions.d.ts +0 -68
  57. package/lib/services/auth/definitions.js +0 -2
  58. package/lib/services/auth/definitions.requests.d.ts +0 -24
  59. package/lib/services/auth/definitions.requests.js +0 -5
  60. package/lib/services/auth/index.d.ts +0 -231
  61. package/lib/services/auth/index.js +0 -309
  62. package/lib/services/cart/definitions.d.ts +0 -83
  63. package/lib/services/cart/definitions.js +0 -2
  64. package/lib/services/cart/index.d.ts +0 -329
  65. package/lib/services/cart/index.js +0 -463
  66. package/lib/services/commercial-order/definitions.d.ts +0 -168
  67. package/lib/services/commercial-order/definitions.js +0 -2
  68. package/lib/services/commercial-order/index.d.ts +0 -709
  69. package/lib/services/commercial-order/index.js +0 -972
  70. package/lib/services/custom-field/definitions.d.ts +0 -106
  71. package/lib/services/custom-field/definitions.js +0 -60
  72. package/lib/services/custom-field/index.d.ts +0 -114
  73. package/lib/services/custom-field/index.js +0 -143
  74. package/lib/services/customer-account/definitions.d.ts +0 -163
  75. package/lib/services/customer-account/definitions.js +0 -2
  76. package/lib/services/customer-account/index.d.ts +0 -655
  77. package/lib/services/customer-account/index.js +0 -933
  78. package/lib/services/customer-user/definitions.d.ts +0 -83
  79. package/lib/services/customer-user/definitions.js +0 -2
  80. package/lib/services/customer-user/index.d.ts +0 -393
  81. package/lib/services/customer-user/index.js +0 -527
  82. package/lib/services/incident/definitions.d.ts +0 -84
  83. package/lib/services/incident/definitions.js +0 -2
  84. package/lib/services/incident/index.d.ts +0 -269
  85. package/lib/services/incident/index.js +0 -387
  86. package/lib/services/logistic-order/definitions.d.ts +0 -292
  87. package/lib/services/logistic-order/definitions.js +0 -2
  88. package/lib/services/logistic-order/index.d.ts +0 -1299
  89. package/lib/services/logistic-order/index.js +0 -1720
  90. package/lib/services/navigation-category/definitions.d.ts +0 -30
  91. package/lib/services/navigation-category/definitions.js +0 -2
  92. package/lib/services/navigation-category/index.d.ts +0 -113
  93. package/lib/services/navigation-category/index.js +0 -159
  94. package/lib/services/offer-inventories/definitions.d.ts +0 -72
  95. package/lib/services/offer-inventories/definitions.js +0 -2
  96. package/lib/services/offer-inventories/index.d.ts +0 -119
  97. package/lib/services/offer-inventories/index.js +0 -174
  98. package/lib/services/offer-prices/__mocks__/offer-prices.mocks.d.ts +0 -108
  99. package/lib/services/offer-prices/__mocks__/offer-prices.mocks.js +0 -200
  100. package/lib/services/offer-prices/definitions.d.ts +0 -23
  101. package/lib/services/offer-prices/definitions.js +0 -2
  102. package/lib/services/offer-prices/index.d.ts +0 -35
  103. package/lib/services/offer-prices/index.js +0 -52
  104. package/lib/services/operation/definitions.d.ts +0 -279
  105. package/lib/services/operation/definitions.js +0 -17
  106. package/lib/services/operation/index.d.ts +0 -519
  107. package/lib/services/operation/index.js +0 -703
  108. package/lib/services/payment/definitions.d.ts +0 -78
  109. package/lib/services/payment/definitions.js +0 -2
  110. package/lib/services/payment/index.d.ts +0 -149
  111. package/lib/services/payment/index.js +0 -219
  112. package/lib/services/product/definitions.d.ts +0 -148
  113. package/lib/services/product/definitions.js +0 -8
  114. package/lib/services/product/index.d.ts +0 -386
  115. package/lib/services/product/index.js +0 -561
  116. package/lib/services/product-variant/definitions.d.ts +0 -171
  117. package/lib/services/product-variant/definitions.js +0 -7
  118. package/lib/services/product-variant/index.d.ts +0 -122
  119. package/lib/services/product-variant/index.js +0 -171
  120. package/lib/services/quote/definitions.d.ts +0 -99
  121. package/lib/services/quote/definitions.js +0 -2
  122. package/lib/services/quote/index.d.ts +0 -376
  123. package/lib/services/quote/index.js +0 -503
  124. package/lib/services/supplier/__mocks__/supplier-mocks.d.ts +0 -48
  125. package/lib/services/supplier/__mocks__/supplier-mocks.js +0 -167
  126. package/lib/services/supplier/definitions.d.ts +0 -29
  127. package/lib/services/supplier/definitions.js +0 -2
  128. package/lib/services/supplier/index.d.ts +0 -101
  129. package/lib/services/supplier/index.js +0 -145
  130. package/lib/settings/fetch-instance.d.ts +0 -28
  131. package/lib/settings/fetch-instance.js +0 -227
package/README.md CHANGED
@@ -1,50 +1,605 @@
1
- # Introduction
1
+ # DJUST Front SDK
2
2
 
3
- **DJUST Front SDK** is a JavaScript 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, thus facilitating the implementation of robust e-commerce solutions for your clients.
3
+ > **Universal TypeScript SDK for DJUST B2B API**
4
+ > SSR-safe, type-safe, production-ready.
5
+
6
+ [![npm version](https://img.shields.io/npm/v/@djust-b2b/djust-front-sdk)](https://www.npmjs.com/package/@djust-b2b/djust-front-sdk)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.6-blue.svg)](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
- ## 🚀 **Why use DJUST Front SDK ?**
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
- ### **🔒 Secure API Calls**
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
- ### **⚡ Performance Optimization**
13
- DJUST Front SDK is designed to:
14
- - Minimize response times through optimized methods.
15
- - Efficiently manage API calls by avoiding redundancies.
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
- ### **🧩 A Simplified Integration**
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
- ### **🔧 Flexibility and Modularity**
22
- Use only the methods you need for your projects. The SDK is modular, allowing you to tailor the integration according to your clients' requirements.
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
- ## 🛡️ **Security and Compliance**
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
- The SDK incorporates best practices to ensure :
29
- - A **secure management of authentication tokens**.
30
- - Compliance with security standards to protect data exchanges.
31
- - A **reliability** in requests through centralized error handling.
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
- ## 📈 **Benefits for Partners**
499
+ ## 🧪 Testing
500
+
501
+ The SDK includes comprehensive test coverage:
502
+
503
+ ```bash
504
+ # Run tests
505
+ npm test
36
506
 
37
- - **Accelerate your integrations** : Save time by using a ready-to-use SDK.
38
- - **Secure your projects** : Assure your clients with robust and secure backend calls.
39
- - **Maximize performance** : Provide smooth experiences with fast and optimized interactions.
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
- ## 📄 **Licence**
516
+ ## 📊 Performance Monitoring
517
+
518
+ Access performance metrics:
44
519
 
45
- DJUST Front SDK is distributed under the **MIT license**, providing you with complete freedom to use it in your projects.
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
- With **DJUST Front SDK**, simplify your backend integrations, ensure exceptional performance, and provide reliable and secure e-commerce solutions for your clients.
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.
package/package.json CHANGED
@@ -1,21 +1,42 @@
1
1
  {
2
2
  "name": "@djust-b2b/djust-front-sdk",
3
- "version": "2.16.1",
4
- "description": "DJUST Front SDK is a versatile JavaScript Software Development Kit (SDK)",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
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
- "build": "tsc",
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
- "lib/**/**.js",
51
- "lib/**/**.d.ts"
73
+ "dist"
52
74
  ],
53
75
  "dependencies": {
54
76
  "@sentry/browser": "^9.2.0",