@sazito/client-sdk 1.2.1 → 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 +31 -28
- package/dist/index.d.ts +592 -187
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ 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,
|
|
10
|
+
- modular API access for products, cart, invoices, shipping, payments, user, CMS, analytics, and more
|
|
11
11
|
|
|
12
12
|
## Package
|
|
13
13
|
|
|
@@ -249,11 +249,12 @@ const search = await sazito.search.query('shoes', {
|
|
|
249
249
|
});
|
|
250
250
|
```
|
|
251
251
|
|
|
252
|
-
###
|
|
252
|
+
### Checkout Modules Flow
|
|
253
253
|
|
|
254
254
|
```ts
|
|
255
|
-
// 1) Add product to cart
|
|
256
|
-
await sazito.cart.
|
|
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.
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
-
|
|
392
|
-
|
|
394
|
+
pnpm docs:install
|
|
395
|
+
pnpm docs:dev
|
|
393
396
|
```
|
|
394
397
|
|
|
395
398
|
Build/start docs:
|
|
396
399
|
|
|
397
400
|
```bash
|
|
398
|
-
|
|
399
|
-
|
|
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.
|