@behio/storefront-sdk 0.1.5 → 0.1.7

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 (2) hide show
  1. package/README.md +71 -21
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -121,7 +121,6 @@ export function Providers({ children }: { children: React.ReactNode }) {
121
121
  return (
122
122
  <BehioProvider
123
123
  apiKey={process.env.NEXT_PUBLIC_BEHIO_API_KEY!} // e.g. "pk_live_6d3f255..."
124
- baseUrl={process.env.NEXT_PUBLIC_BEHIO_API_URL} // optional — defaults to https://api.behio.com
125
124
  locale="cs"
126
125
  currency="CZK"
127
126
  storage="cookies" // "cookies" | "localStorage" | "memory"
@@ -154,19 +153,9 @@ Set your env variables:
154
153
  ```bash
155
154
  # .env.local
156
155
  NEXT_PUBLIC_BEHIO_API_KEY=pk_live_xxxxxxxxxxxx
157
- NEXT_PUBLIC_BEHIO_API_URL=https://api.behio.com # production
158
- # NEXT_PUBLIC_BEHIO_API_URL=http://localhost:7007 # local dev
159
156
 
160
157
  # For server-side (Server Actions, RSC) — NEVER expose to client
161
158
  BEHIO_API_KEY=sk_live_xxxxxxxxxxxx
162
- BEHIO_API_URL=https://api.behio.com
163
- ```
164
-
165
- **Optional:** Hide the backend URL behind a proxy. Add a Next.js rewrite in `next.config.ts` and set `baseUrl="/api"`:
166
- ```typescript
167
- async rewrites() {
168
- return [{ source: '/api/:path*', destination: 'https://api.behio.com/:path*' }];
169
- }
170
159
  ```
171
160
 
172
161
  ## 2. Fetch data with hooks
@@ -212,7 +201,6 @@ export default async function ProductPage({ params }: { params: Promise<{ slug:
212
201
  const { slug } = await params;
213
202
  const shop = new BehioStorefront({
214
203
  apiKey: process.env.BEHIO_API_KEY!,
215
- baseUrl: process.env.BEHIO_API_URL,
216
204
  });
217
205
  const initialData = await shop.catalog.getProduct(slug);
218
206
  return <ProductDetail slug={slug} initialData={initialData} />;
@@ -361,7 +349,6 @@ import { BehioStorefront } from '@behio/storefront-sdk';
361
349
  export default async function ProductsPage() {
362
350
  const shop = new BehioStorefront({
363
351
  apiKey: process.env.BEHIO_API_KEY!, // ← private, server-only
364
- baseUrl: process.env.BEHIO_API_URL,
365
352
  });
366
353
 
367
354
  const products = await shop.catalog.getProducts({ limit: 24 });
@@ -390,7 +377,6 @@ import { cookies } from 'next/headers';
390
377
  function getShop() {
391
378
  return new BehioStorefront({
392
379
  apiKey: process.env.BEHIO_API_KEY!,
393
- baseUrl: process.env.BEHIO_API_URL,
394
380
  });
395
381
  }
396
382
 
@@ -466,7 +452,6 @@ import { BehioStorefront } from '@behio/storefront-sdk';
466
452
 
467
453
  const shop = new BehioStorefront({
468
454
  apiKey: 'pk_live_xxx',
469
- baseUrl: 'https://api.behio.com', // optional
470
455
  locale: 'cs', // optional
471
456
  currency: 'CZK', // optional
472
457
  timeout: 30000, // optional — request timeout (ms)
@@ -480,7 +465,12 @@ Every API method returns a Promise. Types are fully auto-completed.
480
465
 
481
466
  ```typescript
482
467
  // Catalog
483
- const products = await shop.catalog.getProducts({ limit: 20, sort: 'newest' });
468
+ const products = await shop.catalog.getProducts({
469
+ limit: 20,
470
+ sort: 'newest',
471
+ categories: ['electronics', 'books'], // array filters sent as repeated query params
472
+ hasDiscount: true,
473
+ });
484
474
  const product = await shop.catalog.getProduct('my-product-slug');
485
475
  const { categories } = await shop.catalog.getCategories();
486
476
 
@@ -545,20 +535,80 @@ const { data, isLoading, error } = useShopInfo();
545
535
  ```
546
536
 
547
537
  ### useProducts
538
+
539
+ Supports **both** traditional pagination and infinite scroll from one hook.
540
+
548
541
  ```typescript
549
- const { data, isLoading, error } = useProducts({
542
+ const {
543
+ items, // flat array (all pages merged) — for infinite scroll
544
+ data, // PaginatedResponse (current page) — for traditional pagination
545
+ total, totalPages, currentPage, limit,
546
+
547
+ // Traditional pagination
548
+ page, setPage,
549
+
550
+ // Infinite scroll
551
+ loadMore, hasMore, isLoadingMore,
552
+
553
+ // State
554
+ isLoading, isFetching, error, isError, refetch,
555
+ } = useProducts({
550
556
  page: 1,
551
557
  limit: 24,
552
- category: 'electronics',
553
- label: 'new',
558
+
559
+ // Scalar filters
560
+ category: 'electronics', // single category slug
561
+ label: 'new', // single label slug
554
562
  priceMin: 100,
555
563
  priceMax: 5000,
556
- sort: 'price_asc',
564
+ currency: 'CZK',
565
+ locale: 'cs',
566
+ sort: 'price_asc', // or ProductSort.PRICE_ASC
557
567
  inStock: true,
558
568
  search: 'keyboard',
559
569
  customFields: { material: 'aluminum' },
570
+
571
+ // Array filters — sent as repeated query params (?ids=a&ids=b)
572
+ ids: ['prod_1', 'prod_2'], // filter to specific IDs
573
+ slugs: ['red-shoes', 'blue-hat'], // filter to specific slugs
574
+ categories: ['electronics', 'books'], // OR logic (in ANY of these)
575
+ labels: ['sale', 'new'], // AND logic (must have ALL)
576
+ excludeIds: ['prod_999'], // exclude specific IDs (e.g. related products)
577
+ excludeCategories: ['archive'], // exclude products in these categories
578
+
579
+ // Boolean / time filters
580
+ hasDiscount: true, // only products with compareAtPrice
581
+ isFeatured: true, // only featured products
582
+ createdAfter: Date.now() - 7 * 864e5, // created in last 7 days (epoch ms)
583
+
584
+ // Hook options
585
+ enabled: true, // skip fetch until true
586
+ initialData: prefetchedData, // SSR hydration
560
587
  });
561
- // data: PaginatedResponse<ProductListItem>
588
+ ```
589
+
590
+ **Infinite scroll example:**
591
+ ```tsx
592
+ const { items, loadMore, hasMore, isLoadingMore } = useProducts({ limit: 24 });
593
+
594
+ return (
595
+ <>
596
+ {items.map(p => <ProductCard key={p.id} product={p} />)}
597
+ {hasMore && <button onClick={loadMore} disabled={isLoadingMore}>Load more</button>}
598
+ </>
599
+ );
600
+ ```
601
+
602
+ **Traditional pagination example:**
603
+ ```tsx
604
+ const { data, page, setPage, totalPages } = useProducts({ limit: 24 });
605
+
606
+ return (
607
+ <>
608
+ {data?.items.map(p => <ProductCard key={p.id} product={p} />)}
609
+ <Pagination page={page} total={totalPages} onChange={setPage} />
610
+ </>
611
+ );
562
612
  ```
563
613
 
564
614
  ### useProduct
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@behio/storefront-sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "TypeScript SDK for Behio Headless E-Shop — core client + React hooks",
5
5
  "author": "Behio",
6
6
  "license": "MIT",