@sazito/client-sdk 1.2.1 → 1.2.3

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 CHANGED
@@ -2,12 +2,14 @@
2
2
 
3
3
  Official JavaScript/TypeScript SDK for Sazito storefronts.
4
4
 
5
+ Read the full developer documentation at [developers.sazito.com](https://developers.sazito.com).
6
+
5
7
  This SDK is built for application developers who want a typed, framework-agnostic client with:
6
8
  - automatic request/response key transformation
7
9
  - unified response objects (`{ data, error }`)
8
10
  - configurable retry/timeout/cache behavior
9
11
  - guest checkout credential handling
10
- - modular API access for products, checkout, user, CMS, analytics, and more
12
+ - modular API access for products, cart, invoices, shipping, payments, user, CMS, analytics, and more
11
13
 
12
14
  ## Package
13
15
 
@@ -56,6 +58,54 @@ if (res.error) {
56
58
  }
57
59
  ```
58
60
 
61
+ ## Checkout component
62
+
63
+ For a ready-made React/Next.js checkout UI, install the companion package:
64
+
65
+ ```bash
66
+ pnpm add @sazito/client-sdk @sazito/checkout
67
+ ```
68
+
69
+ Create one SDK client, provide it to the checkout, and import the checkout
70
+ stylesheet once:
71
+
72
+ ```tsx
73
+ 'use client';
74
+
75
+ import '@sazito/checkout/styles.css';
76
+ import { createSazitoClient } from '@sazito/client-sdk';
77
+ import { SazitoCheckoutPage, SazitoProvider } from '@sazito/checkout/next';
78
+
79
+ const sazito = createSazitoClient({ domain: 'mystore.sazito.com' });
80
+
81
+ export default function CheckoutPage() {
82
+ return (
83
+ <SazitoProvider client={sazito}>
84
+ <SazitoCheckoutPage
85
+ credentials={{ cart: { identifier: 'cart-identifier' } }}
86
+ config={{
87
+ locale: 'fa',
88
+ continueShoppingUrl: '/',
89
+ theme: {
90
+ accent: '#4f46e5',
91
+ accentForeground: '#ffffff',
92
+ radius: 16
93
+ }
94
+ }}
95
+ />
96
+ </SazitoProvider>
97
+ );
98
+ }
99
+ ```
100
+
101
+ The component provides a typed, RTL-first flow for `cart → shipping → payment → result`,
102
+ including cart editing, address and shipping-rate selection, discounts, payment
103
+ gateway redirects, and pending-payment polling. It reuses the credentials stored
104
+ by the SDK client, so credentials created through `sazito.cart` and
105
+ `sazito.invoices` can be used by the component. For theming, custom buttons,
106
+ analytics, payment returns, and a fully custom layout, see the
107
+ [checkout guide](https://developers.sazito.com/docs/guides/checkout).
108
+
59
109
  ## Core Response Model
60
110
 
61
111
  All SDK methods return a `SazitoResponse<T>`:
@@ -198,6 +248,8 @@ The client instance exposes:
198
248
  - `entityRoutes`
199
249
  - `menu`
200
250
  - `general`
251
+ - `dynamicForms`
252
+ - `regions`
201
253
 
202
254
  ### Methods by Module
203
255
 
@@ -205,14 +257,14 @@ The client instance exposes:
205
257
  |---|---|
206
258
  | `products` | `get`, `list`, `search` |
207
259
  | `categories` | `get`, `list` |
208
- | `cart` | `get`, `create`, `addItem`, `updateItem`, `removeItem`, `clearCart` |
260
+ | `cart` | `get`, `create`, `addItem`, `addItemWithAttributes`, `updateItem`, `updateItemWithAttributes`, `removeItem`, `clearCart` |
209
261
  | `orders` | `list`, `get` |
210
- | `invoices` | `get`, `create`, `refresh`, `addShippingAddress`, `addDiscountCode`, `assignShippingMethod`, `addDetails`, `getApplicableShippingMethods`, `clearInvoice` |
211
- | `shipping` | `createAddress`, `updateAddress`, `getAddress`, `getMethods`, `clearAddress` |
212
- | `payments` | `getMethods`, `create`, `initialize`, `processStep`, `clearPayment` |
262
+ | `invoices` | `get`, `create`, `refresh`, `addShippingAddress`, `addDiscountCode`, `assignShippingMethod`, `addDetails`, `addForm`, `addCredit`, `removeCredit`, `toggleCredit`, `getApplicableShippingMethods`, `clearInvoice` |
263
+ | `shipping` | `createAddress`, `updateAddress` (legacy), `listAddresses`, `getAddress`, `getMethods`, `clearAddress` |
264
+ | `payments` | `getMethods`, `create`, `initialize`, `verify`, `processStep`, `processStepForm`, `pollUntilSettled`, `clearPayment` |
213
265
  | `users` | `login`, `requestMobileOTP`, `verifyMobileOTP`, `requestEmailLogin`, `register`, `getCurrentUser`, `updateProfile`, `requestMobilePhoneUpdate`, `verifyMobilePhoneUpdate`, `forgotPassword`, `revivePassword`, `mergeUser` |
214
- | `search` | `search` |
215
- | `feedbacks` | `list`, `create`, `get` |
266
+ | `search` | `query` |
267
+ | `feedbacks` | `getSeed`, `createOrderRating`, `submitProductReview`, `getProductStatistics`, `getProductReviews`, `uploadReviewImages`, `list`, `create`, `get` |
216
268
  | `wallet` | `getBalance`, `applyCredit`, `removeCredit`, `listTransactions` |
217
269
  | `cms` | `getPage`, `listPages`, `getBlogPost`, `listBlogPosts`, `listAll` |
218
270
  | `images` | `upload`, `delete` |
@@ -221,6 +273,8 @@ The client instance exposes:
221
273
  | `entityRoutes` | `resolve` |
222
274
  | `menu` | `getHeaderMenu` |
223
275
  | `general` | `getInfo`, `getFeatures`, `getCheckoutConfig`, `getWalletConfig`, `getTajrobeConfig` |
276
+ | `dynamicForms` | `getForm`, `uploadProductFormFile` |
277
+ | `regions` | `list` |
224
278
 
225
279
  ## Usage Examples
226
280
 
@@ -249,11 +303,12 @@ const search = await sazito.search.query('shoes', {
249
303
  });
250
304
  ```
251
305
 
252
- ### Guest Checkout Flow
306
+ ### Checkout Modules Flow
253
307
 
254
308
  ```ts
255
- // 1) Add product to cart (creates guest cart automatically if needed)
256
- await sazito.cart.addItem(12345, 2);
309
+ // 1) Add product to cart
310
+ const cartRes = await sazito.cart.addItemWithAttributes(12345, 2);
311
+ if (cartRes.error) throw new Error(cartRes.error.message);
257
312
 
258
313
  // 2) Create invoice from cart
259
314
  const invoiceRes = await sazito.invoices.create();
@@ -272,29 +327,31 @@ const addrRes = await sazito.shipping.createAddress({
272
327
  if (addrRes.error) throw new Error(addrRes.error.message);
273
328
 
274
329
  // 4) Attach shipping address to invoice
275
- await sazito.invoices.addShippingAddress(addrRes.data.id, addrRes.data.identifier);
330
+ const attachRes = await sazito.invoices.addShippingAddress(addrRes.data.id, addrRes.data.identifier);
331
+ if (attachRes.error) throw new Error(attachRes.error.message);
276
332
 
277
333
  // 5) Fetch methods and assign shipping
278
334
  const methodsRes = await sazito.invoices.getApplicableShippingMethods();
279
- if (methodsRes.data?.length) {
280
- const firstRate = methodsRes.data[0]?.rates?.[0];
281
- const currentInvoice = await sazito.invoices.get();
282
-
283
- if (firstRate && currentInvoice.data) {
284
- await sazito.invoices.assignShippingMethod([
285
- {
286
- rateId: firstRate.id,
287
- invoiceItemIds: currentInvoice.data.items.map(i => i.id)
288
- }
289
- ]);
290
- }
335
+ if (methodsRes.error) throw new Error(methodsRes.error.message);
336
+ if (methodsRes.data?.itemsShippingRate?.length) {
337
+ const assignments = methodsRes.data.itemsShippingRate.map((entry) => ({
338
+ rateId: entry.shippingRate.id,
339
+ invoiceItemIds: [entry.invoiceItemId],
340
+ }));
341
+
342
+ const assignRes = await sazito.invoices.assignShippingMethod(assignments);
343
+ if (assignRes.error) throw new Error(assignRes.error.message);
291
344
  }
292
345
 
293
346
  // 6) Payment
294
347
  const paymentMethods = await sazito.payments.getMethods();
348
+ if (paymentMethods.error) throw new Error(paymentMethods.error.message);
295
349
  if (paymentMethods.data?.length) {
296
- await sazito.payments.create(paymentMethods.data[0].id);
350
+ const paymentCreateRes = await sazito.payments.create(paymentMethods.data[0].id);
351
+ if (paymentCreateRes.error) throw new Error(paymentCreateRes.error.message);
352
+
297
353
  const action = await sazito.payments.initialize();
354
+ if (action.error) throw new Error(action.error.message);
298
355
  console.log(action.data);
299
356
  }
300
357
  ```
@@ -357,7 +414,7 @@ Notes:
357
414
  Run the local visual playground:
358
415
 
359
416
  ```bash
360
- yarn visual:apis
417
+ pnpm visual:apis
361
418
  ```
362
419
 
363
420
  Then open:
@@ -374,11 +431,11 @@ Files:
374
431
  Project scripts:
375
432
 
376
433
  ```bash
377
- yarn build # Build dist outputs
378
- yarn dev # Rollup watch mode
379
- yarn typecheck # TypeScript check (no emit)
380
- yarn lint # ESLint on src/
381
- yarn validate # typecheck + lint
434
+ pnpm build # Build dist outputs
435
+ pnpm dev # Rollup watch mode
436
+ pnpm typecheck # TypeScript check (no emit)
437
+ pnpm lint # ESLint on src/
438
+ pnpm validate # typecheck + lint
382
439
  ```
383
440
 
384
441
  ## Fumadocs Documentation Site
@@ -388,15 +445,15 @@ SDK docs are implemented as a separate Fumadocs app in `docs/`.
388
445
  Run docs locally from the repository root:
389
446
 
390
447
  ```bash
391
- yarn docs:install
392
- yarn docs:dev
448
+ pnpm docs:install
449
+ pnpm docs:dev
393
450
  ```
394
451
 
395
452
  Build/start docs:
396
453
 
397
454
  ```bash
398
- yarn docs:build
399
- yarn docs:start
455
+ pnpm docs:build
456
+ pnpm docs:start
400
457
  ```
401
458
 
402
459
  This docs app is tracked in GitHub, but it is not included in the published npm package.