@sazito/client-sdk 1.2.0 → 1.2.2

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
@@ -7,12 +7,12 @@ This SDK is built for application developers who want a typed, framework-agnosti
7
7
  - unified response objects (`{ data, error }`)
8
8
  - configurable retry/timeout/cache behavior
9
9
  - guest checkout credential handling
10
- - modular API access for products, checkout, user, CMS, analytics, and more
10
+ - modular API access for products, cart, invoices, shipping, payments, user, CMS, analytics, and more
11
11
 
12
12
  ## Package
13
13
 
14
14
  - Name: `@sazito/client-sdk`
15
- - Version: `1.0.0`
15
+ - Version: See `package.json`
16
16
  - License: `MIT`
17
17
 
18
18
  ## Requirements
@@ -149,7 +149,7 @@ Supported request options:
149
149
  ## Authentication
150
150
 
151
151
  ```ts
152
- sazito.setAuthToken('<jwt>');
152
+ sazito.setAuthToken('YOUR_JWT');
153
153
 
154
154
  const isLoggedIn = sazito.isAuthenticated();
155
155
  const token = sazito.getAuthToken();
@@ -249,11 +249,12 @@ const search = await sazito.search.query('shoes', {
249
249
  });
250
250
  ```
251
251
 
252
- ### Guest Checkout Flow
252
+ ### Checkout Modules Flow
253
253
 
254
254
  ```ts
255
- // 1) Add product to cart (creates guest cart automatically if needed)
256
- await sazito.cart.addItem(12345, 2);
255
+ // 1) Add product to cart
256
+ const cartRes = await sazito.cart.addItemWithAttributes(12345, 2);
257
+ if (cartRes.error) throw new Error(cartRes.error.message);
257
258
 
258
259
  // 2) Create invoice from cart
259
260
  const invoiceRes = await sazito.invoices.create();
@@ -272,29 +273,31 @@ const addrRes = await sazito.shipping.createAddress({
272
273
  if (addrRes.error) throw new Error(addrRes.error.message);
273
274
 
274
275
  // 4) Attach shipping address to invoice
275
- await sazito.invoices.addShippingAddress(addrRes.data.id, addrRes.data.identifier);
276
+ const attachRes = await sazito.invoices.addShippingAddress(addrRes.data.id, addrRes.data.identifier);
277
+ if (attachRes.error) throw new Error(attachRes.error.message);
276
278
 
277
279
  // 5) Fetch methods and assign shipping
278
280
  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
- }
281
+ if (methodsRes.error) throw new Error(methodsRes.error.message);
282
+ if (methodsRes.data?.itemsShippingRate?.length) {
283
+ const assignments = methodsRes.data.itemsShippingRate.map((entry) => ({
284
+ rateId: entry.shippingRate.id,
285
+ invoiceItemIds: [entry.invoiceItemId],
286
+ }));
287
+
288
+ const assignRes = await sazito.invoices.assignShippingMethod(assignments);
289
+ if (assignRes.error) throw new Error(assignRes.error.message);
291
290
  }
292
291
 
293
292
  // 6) Payment
294
293
  const paymentMethods = await sazito.payments.getMethods();
294
+ if (paymentMethods.error) throw new Error(paymentMethods.error.message);
295
295
  if (paymentMethods.data?.length) {
296
- await sazito.payments.create(paymentMethods.data[0].id);
296
+ const paymentCreateRes = await sazito.payments.create(paymentMethods.data[0].id);
297
+ if (paymentCreateRes.error) throw new Error(paymentCreateRes.error.message);
298
+
297
299
  const action = await sazito.payments.initialize();
300
+ if (action.error) throw new Error(action.error.message);
298
301
  console.log(action.data);
299
302
  }
300
303
  ```
@@ -357,7 +360,7 @@ Notes:
357
360
  Run the local visual playground:
358
361
 
359
362
  ```bash
360
- yarn visual:apis
363
+ pnpm visual:apis
361
364
  ```
362
365
 
363
366
  Then open:
@@ -374,11 +377,11 @@ Files:
374
377
  Project scripts:
375
378
 
376
379
  ```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
380
+ pnpm build # Build dist outputs
381
+ pnpm dev # Rollup watch mode
382
+ pnpm typecheck # TypeScript check (no emit)
383
+ pnpm lint # ESLint on src/
384
+ pnpm validate # typecheck + lint
382
385
  ```
383
386
 
384
387
  ## Fumadocs Documentation Site
@@ -388,15 +391,15 @@ SDK docs are implemented as a separate Fumadocs app in `docs/`.
388
391
  Run docs locally from the repository root:
389
392
 
390
393
  ```bash
391
- yarn docs:install
392
- yarn docs:dev
394
+ pnpm docs:install
395
+ pnpm docs:dev
393
396
  ```
394
397
 
395
398
  Build/start docs:
396
399
 
397
400
  ```bash
398
- yarn docs:build
399
- yarn docs:start
401
+ pnpm docs:build
402
+ pnpm docs:start
400
403
  ```
401
404
 
402
405
  This docs app is tracked in GitHub, but it is not included in the published npm package.