@commerce-blocks/sdk 2.0.0 → 2.0.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
@@ -58,10 +58,30 @@ collection.dispose()
58
58
  | `storage` | `StorageAdapter` | No | Custom storage adapter |
59
59
  | `initialData` | `CacheData` | No | Pre-populate cache at init |
60
60
  | `restoreCache` | `boolean` | No | Restore from storage (default: true) |
61
+ | `flags` | `Flags` | No | Feature flags (see below) |
62
+
63
+ ### Flags
64
+
65
+ Control which product data the SDK requests from the API.
66
+
67
+ ```typescript
68
+ createClient({
69
+ // ...config
70
+ flags: { variants: true }, // opt-in for full variants array
71
+ })
72
+ ```
73
+
74
+ | Flag | Default | Description |
75
+ | ---------- | ------- | ----------------------------------------------------------------------------- |
76
+ | `variants` | `false` | Request full variants array per product. Enable for PDPs or option selectors. |
77
+
78
+ By default, products are **shallow** — `variants` contains only the matched variant, and `price`/`compareAtPrice`/`featuredMedia`/`availableForSale` are sourced from `first_or_matched_variant`. This significantly reduces API payload size.
79
+
80
+ When `flags.variants` is `true`, the full `variants` array is requested and `selectedVariant` is looked up from it. Use this for product detail pages or cards with variant/option selectors.
61
81
 
62
82
  ## Controllers
63
83
 
64
- All controllers (`collection`, `blocks`, `search`, `suggest`) follow the same pattern:
84
+ All controllers (`collection`, `blocks`, `search`, `suggest`, `searchContent`) follow the same pattern:
65
85
 
66
86
  - **`state`** — a `ReadonlySignal<QueryState<T>>` with `{ data, error, isFetching }`
67
87
  - **`execute()`** — runs the query, returns `Result<T, ClientError>`
@@ -207,6 +227,56 @@ suggest.dispose()
207
227
  | `excludeQueries` | `string[]` | Custom strings to filter from suggestions |
208
228
  | `signal` | `AbortSignal` | Shared abort signal (acts like `dispose()`) |
209
229
 
230
+ ### Content Search
231
+
232
+ Search articles and other content types.
233
+
234
+ ```typescript
235
+ const content = client.searchContent({ query: 'styling tips' })
236
+
237
+ const { data } = await content.execute()
238
+ // data.articles, data.totalResults, data.page
239
+
240
+ await content.execute({ query: 'new arrivals', contentType: 'blog' })
241
+ await content.execute({ page: 2, temporary: true })
242
+
243
+ content.dispose()
244
+ ```
245
+
246
+ | Option | Type | Description |
247
+ | ------------------ | ---------------- | ----------------------------------------- |
248
+ | `query` | `string` | Search query |
249
+ | `contentType` | `string` | Filter by content type |
250
+ | `page` | `number` | Page number |
251
+ | `limit` | `number` | Results per page |
252
+ | `tuning` | `SearchTuning` | Matching weight configuration |
253
+ | `signal` | `AbortSignal` | Abort signal |
254
+ | `transformRequest` | `(body) => body` | Custom request body transformation |
255
+ | `temporary` | `boolean` | Override without persisting for next call |
256
+
257
+ Result shape:
258
+
259
+ ```typescript
260
+ interface SearchContentResult {
261
+ articles: Article[]
262
+ query: string
263
+ contentType: string | null
264
+ totalResults: number
265
+ page: number
266
+ resultsPerPage: number
267
+ }
268
+
269
+ interface Article {
270
+ title: string
271
+ handle: string
272
+ summary: string
273
+ author: string
274
+ tags: string[]
275
+ image: { url: string; width: number; height: number } | null
276
+ publishedAt: string
277
+ }
278
+ ```
279
+
210
280
  ### Image Search
211
281
 
212
282
  Upload an image, then search by it.
package/dist/index.d.ts CHANGED
@@ -108,6 +108,7 @@ declare type CacheData = Record<string, CacheValue>;
108
108
  declare interface CacheEntry<T> {
109
109
  data: T;
110
110
  timestamp: number;
111
+ createdAt: number;
111
112
  }
112
113
 
113
114
  export declare interface CacheOptions {
@@ -512,8 +513,8 @@ export declare interface ProductBase {
512
513
  tags: string[];
513
514
  images: Image_2[];
514
515
  featuredMedia: FeaturedMedia | null;
515
- priceRange: PriceRange;
516
- compareAtPriceRange: PriceRange | null;
516
+ price: Price;
517
+ compareAtPrice: Price | null;
517
518
  options: RichProductOption[];
518
519
  selectedOptions: ProductOption[];
519
520
  variants: ProductVariant[];
@@ -615,16 +616,18 @@ declare interface ProductResult {
615
616
  featured_media: FeaturedMedia_2 | null;
616
617
  category: ProductCategory_2 | null;
617
618
  tags: string[];
618
- images: ProductImage[];
619
+ images?: ProductImage[];
619
620
  collection_titles: string[];
620
621
  metafields: Record<string, Record<string, unknown>>;
621
622
  calculated: Record<string, unknown>;
622
- price_range: {
623
+ options_v2: OptionV2[];
624
+ first_or_matched_variant: MatchedVariant;
625
+ price_range?: {
623
626
  from: number;
624
627
  to: number;
625
628
  compare_at_price: number;
626
629
  };
627
- options_v2: OptionV2[];
630
+ variants?: LayersVariant[];
628
631
  body_html?: string | null;
629
632
  is_gift_card?: boolean | null;
630
633
  has_variants_that_require_components?: boolean | null;
@@ -633,8 +636,6 @@ declare interface ProductResult {
633
636
  created_at?: string;
634
637
  updated_at?: string;
635
638
  published_at?: string;
636
- first_or_matched_variant?: MatchedVariant;
637
- variants: LayersVariant[];
638
639
  }
639
640
 
640
641
  export declare interface ProductVariant {