@commerce-blocks/sdk 1.3.0 → 2.0.0-alpha.1

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 (4) hide show
  1. package/README.md +103 -64
  2. package/dist/index.d.ts +176 -109
  3. package/dist/index.js +1300 -1146
  4. package/package.json +8 -3
package/dist/index.d.ts CHANGED
@@ -28,7 +28,7 @@ export declare interface ApiError {
28
28
 
29
29
  declare type ApiErrorCode = 'UNAUTHORIZED' | 'FORBIDDEN' | 'NOT_FOUND' | 'RATE_LIMITED' | 'SERVICE_UNAVAILABLE' | 'GRAPHQL_ERROR' | 'PARSE_ERROR' | 'UNKNOWN';
30
30
 
31
- declare type ApiSource = 'layers' | 'shopify';
31
+ declare type ApiSource = 'layers' | 'storefront';
32
32
 
33
33
  export declare interface AutocompleteController {
34
34
  execute: (query: string) => void;
@@ -52,14 +52,8 @@ declare interface BaseProduct {
52
52
  description: string;
53
53
  availableForSale: boolean;
54
54
  images: Image_2[];
55
- priceRange: {
56
- min: Price;
57
- max: Price;
58
- };
59
- compareAtPriceRange?: {
60
- min: Price;
61
- max: Price;
62
- };
55
+ priceRange: PriceRange;
56
+ compareAtPriceRange?: PriceRange;
63
57
  options: RichProductOption[];
64
58
  tags: string[];
65
59
  variants: ProductVariant[];
@@ -67,9 +61,19 @@ declare interface BaseProduct {
67
61
  metafields: Record<string, Record<string, unknown>> | unknown[];
68
62
  calculated?: Record<string, unknown>;
69
63
  isGiftCard: boolean;
70
- onlineStoreUrl: string | null;
71
- /** @deprecated Use variant `inventoryLevels` for location-specific inventory */
72
- totalInventory: number;
64
+ category: ProductCategory | null;
65
+ createdAt: string | null;
66
+ publishedAt: string | null;
67
+ updatedAt: string | null;
68
+ featuredMedia: FeaturedMedia | null;
69
+ namedTags?: NamedTag[];
70
+ combinedListingParentProductId: number | null;
71
+ combinedListingRole: string | null;
72
+ hasVariantsThatRequireComponents: boolean;
73
+ originalOptions: Record<string, string[]>;
74
+ selectedVariant: ProductVariant | null;
75
+ breakoutOptions?: ProductOption[];
76
+ breakoutVariantId?: number;
73
77
  }
74
78
 
75
79
  declare type BaseResult<P extends Product = Product> = QueryResult<P>;
@@ -115,6 +119,7 @@ export declare type BlocksExtender<P extends Product = Product> = (result: Block
115
119
 
116
120
  declare interface BlocksInfo {
117
121
  id: string;
122
+ label: string;
118
123
  title: string;
119
124
  anchor_type: 'product' | 'collection' | 'cart' | 'none';
120
125
  strategy_type: 'interaction' | 'similar_products' | 'manual';
@@ -184,7 +189,7 @@ export declare interface CollectionOptions {
184
189
  }
185
190
 
186
191
  export declare interface CollectionResult<P extends Product = Product> extends BaseResult<P> {
187
- collection?: ShopifyCollection;
192
+ collection?: StorefrontCollection;
188
193
  }
189
194
 
190
195
  declare type Collections = Record<string, Omit<CollectionMeta, 'handle'>>;
@@ -207,6 +212,14 @@ export declare interface ConfigError {
207
212
 
208
213
  declare type ConfigErrorCode = 'MISSING_CONFIG' | 'INVALID_CONFIG';
209
214
 
215
+ export declare function createProductCard({ product, selectedOptions: initialSelectedOptions, breakoutOptions: initialBreakoutOptions, }: CreateProductCardParams): ProductCardController;
216
+
217
+ export declare interface CreateProductCardParams {
218
+ product: Product | ExtendedProduct;
219
+ selectedOptions?: ProductOption[];
220
+ breakoutOptions?: ProductOption[];
221
+ }
222
+
210
223
  export declare function createSdk<P extends Product = Product>(config: SdkConfig<P>): Result<Sdk<P>, ConfigError>;
211
224
 
212
225
  declare type CustomFetch = (url: string, init?: RequestInit) => Promise<Response>;
@@ -235,7 +248,24 @@ export declare function eq(property: string, value: FilterValue): FilterExpressi
235
248
 
236
249
  export declare function exists(property: string): FilterExpression;
237
250
 
251
+ declare interface ExtendedProduct extends BaseProduct {
252
+ _base: BaseProduct;
253
+ }
254
+
255
+ declare interface Facet {
256
+ name: string;
257
+ code: string;
258
+ }
259
+
238
260
  declare interface FeaturedMedia {
261
+ mediaContentType: string | null;
262
+ url: string;
263
+ alt: string;
264
+ width: number;
265
+ height: number;
266
+ }
267
+
268
+ declare interface FeaturedMedia_2 {
239
269
  mediaContentType?: string;
240
270
  alt: string;
241
271
  src: string;
@@ -250,7 +280,7 @@ declare interface FileSystem_2 {
250
280
  }
251
281
  export { FileSystem_2 as FileSystem }
252
282
 
253
- export declare function filter(expression: FilterExpression | FilterGroup): FilterGroupParam;
283
+ export declare function filter(expression: FilterExpression | FilterGroup): FilterGroup;
254
284
 
255
285
  declare enum FilterConditional {
256
286
  And = "AND",
@@ -268,10 +298,6 @@ export declare interface FilterGroup {
268
298
  expressions: (FilterExpression | FilterGroup)[];
269
299
  }
270
300
 
271
- declare interface FilterGroupParam {
272
- filter_group: FilterGroup;
273
- }
274
-
275
301
  export declare type FilterMap = Record<string, FilterMapEntry>;
276
302
 
277
303
  export declare type FilterMapEntry = string | {
@@ -344,6 +370,8 @@ declare interface Image_2 {
344
370
  alt: string;
345
371
  width: number;
346
372
  height: number;
373
+ position: number;
374
+ variantIds: number[];
347
375
  }
348
376
  export { Image_2 as Image }
349
377
 
@@ -382,7 +410,7 @@ export declare function jsonFileAdapter(filePath: string, fs: FileSystem_2): Sto
382
410
 
383
411
  declare interface LayersClientConfig extends LayersFetchConfig {
384
412
  sorts: Sort[];
385
- facets: string[];
413
+ facets: Facet[];
386
414
  attributes?: string[];
387
415
  }
388
416
 
@@ -406,7 +434,9 @@ declare interface LayersMeta {
406
434
  group: 'control' | 'variation';
407
435
  }[];
408
436
  appliedRules?: string[];
409
- variantBreakouts?: Record<string, string | number>[];
437
+ variantBreakouts?: {
438
+ optionCode: string;
439
+ }[];
410
440
  }
411
441
 
412
442
  declare interface LayersPagination {
@@ -416,15 +446,15 @@ declare interface LayersPagination {
416
446
  resultsPerPage?: number;
417
447
  }
418
448
 
419
- declare type LayersProduct = ProductResult;
420
-
421
449
  declare interface LayersResponse extends LayersPagination, LayersFacets {
422
- results: (ProductResult | VariantResult_2)[];
450
+ results: (ProductResult | VariantResult)[];
423
451
  attributionToken?: string;
424
452
  _meta?: LayersMeta;
425
453
  _workflow?: unknown;
426
454
  }
427
455
 
456
+ declare type LayersResult = ProductResult | VariantResult;
457
+
428
458
  declare interface LayersTuning {
429
459
  textualWeight?: number;
430
460
  visualWeight?: number;
@@ -448,7 +478,7 @@ declare interface LayersVariant {
448
478
  };
449
479
  }[];
450
480
  position: number;
451
- featured_media?: FeaturedMedia | null;
481
+ featured_media?: FeaturedMedia_2 | null;
452
482
  created_at?: string;
453
483
  updated_at?: string;
454
484
  requires_selling_plan?: boolean;
@@ -500,6 +530,11 @@ declare interface MoneyResult {
500
530
  currencyCode: string;
501
531
  }
502
532
 
533
+ declare interface NamedTag {
534
+ name: string;
535
+ value: string | number | boolean | string[];
536
+ }
537
+
503
538
  export declare interface NetworkError {
504
539
  readonly _tag: 'NetworkError';
505
540
  readonly code: NetworkErrorCode;
@@ -519,6 +554,8 @@ export declare function notExists(property: string): FilterExpression;
519
554
 
520
555
  export declare function notIn(property: string, values: FilterValue[]): FilterExpression;
521
556
 
557
+ declare type OptionAvailabilityStatus = 'available' | 'backorderable' | 'sold-out' | 'unavailable';
558
+
522
559
  declare type OptionSegment = `${string}:${string}`;
523
560
 
524
561
  declare interface OptionV2 {
@@ -553,14 +590,10 @@ declare interface PageMeta {
553
590
  lastFetched: number;
554
591
  }
555
592
 
556
- export declare type ParamDefinition<T = unknown> = (input: ParamInput) => T | undefined | null;
593
+ export declare type ParamDefinition = (key: string) => unknown | undefined | null;
557
594
 
558
595
  export declare type ParamDefinitions = Record<string, ParamDefinition>;
559
596
 
560
- export declare interface ParamInput {
561
- key: string;
562
- }
563
-
564
597
  declare interface PredictiveSearchResponse {
565
598
  matchedQueries: {
566
599
  query_text: string;
@@ -591,6 +624,11 @@ export declare interface Price {
591
624
  formatted: string;
592
625
  }
593
626
 
627
+ export declare interface PriceRange {
628
+ min: Price;
629
+ max: Price;
630
+ }
631
+
594
632
  declare interface PriceRangeResult {
595
633
  minVariantPrice: MoneyResult;
596
634
  maxVariantPrice: MoneyResult;
@@ -598,7 +636,40 @@ declare interface PriceRangeResult {
598
636
 
599
637
  export declare type Product = BaseProduct;
600
638
 
639
+ export declare interface ProductCardController {
640
+ product: Product;
641
+ variants: ReadonlySignal<ProductVariant[]>;
642
+ selectedVariant: ReadonlySignal<ProductVariant | null>;
643
+ selectedOptions: ReadonlySignal<ProductOption[]>;
644
+ options: ReadonlySignal<RichProductOption[]>;
645
+ optionNames: ReadonlySignal<string[]>;
646
+ swatchOptionName: ReadonlySignal<string | null>;
647
+ images: ReadonlySignal<Image_2[]>;
648
+ allImages: ReadonlySignal<Image_2[]>;
649
+ carouselIndex: ReadonlySignal<number>;
650
+ isSelectionComplete: ReadonlySignal<boolean>;
651
+ selectOption(name: string, value: string): void;
652
+ setSelectedOptions(options: ProductOption[]): void;
653
+ setBreakoutOptions(options: ProductOption[]): void;
654
+ getOptionValues(name: string): string[];
655
+ getSwatches(name: string): Swatch[];
656
+ getVariantByOptions(options: ProductOption[]): ProductVariant | null;
657
+ getCarouselIndexForVariant(variant: ProductVariant): number;
658
+ isOptionAvailable(name: string, value: string): boolean;
659
+ isVariantAvailable(variant: ProductVariant): boolean;
660
+ getOptionAvailabilityStatus(name: string, value: string): OptionAvailabilityStatus;
661
+ dispose(): void;
662
+ }
663
+
601
664
  declare interface ProductCategory {
665
+ id: string;
666
+ name: string;
667
+ fullName: string;
668
+ isLeaf: boolean;
669
+ isRoot: boolean;
670
+ }
671
+
672
+ declare interface ProductCategory_2 {
602
673
  id: string;
603
674
  name: string;
604
675
  full_name: string;
@@ -610,8 +681,8 @@ declare type ProductExtender<P extends Product = Product> = (input: ProductExten
610
681
 
611
682
  declare interface ProductExtenderInput {
612
683
  base: Product;
613
- raw: LayersProduct;
614
- shopify: ShopifyProduct | null;
684
+ raw: LayersResult;
685
+ storefront: StorefrontProduct | null;
615
686
  }
616
687
 
617
688
  declare type ProductGID = ShopifyGID<'Product'>;
@@ -653,9 +724,9 @@ declare interface ProductResult {
653
724
  images?: ProductImage[];
654
725
  metafields?: Record<string, Record<string, unknown>> | unknown[];
655
726
  calculated?: Record<string, unknown> | unknown[];
656
- category?: ProductCategory | null;
727
+ category?: ProductCategory_2 | null;
657
728
  first_or_matched_variant?: MatchedVariant;
658
- featured_media?: FeaturedMedia | null;
729
+ featured_media?: FeaturedMedia_2 | null;
659
730
  available?: boolean;
660
731
  price_range?: {
661
732
  from: number;
@@ -678,20 +749,18 @@ export declare interface ProductVariant {
678
749
  title: string;
679
750
  availableForSale: boolean;
680
751
  currentlyNotInStock: boolean;
681
- /** @deprecated Use `inventoryLevels` for location-specific inventory */
682
- quantityAvailable: number;
683
752
  sku: string | null;
684
- barcode: string | null;
685
- weight: number | null;
686
- weightUnit: 'KILOGRAMS' | 'GRAMS' | 'POUNDS' | 'OUNCES' | null;
687
- requiresShipping: boolean;
753
+ position: number;
688
754
  price: Price;
689
755
  compareAtPrice: Price | null;
690
756
  image: Image_2 | null;
691
757
  selectedOptions: ProductOption[];
692
758
  metafields: Metafield[];
693
759
  inventoryLevels: InventoryLevels;
760
+ inventoryPolicy: 'DENY' | 'CONTINUE' | null;
694
761
  inStockLocationIds: number[];
762
+ requiresSellingPlan: boolean;
763
+ hasSellingPlan: boolean;
695
764
  }
696
765
 
697
766
  declare type Queries<P extends Product = Product> = Record<string, QueryResult<P>>;
@@ -707,6 +776,7 @@ declare interface QueryResult<P extends Product = Product> {
707
776
  min: number;
708
777
  max: number;
709
778
  }>;
779
+ priceRange?: PriceRange;
710
780
  attributionToken?: string;
711
781
  _meta?: LayersMeta;
712
782
  _workflow?: unknown;
@@ -839,63 +909,8 @@ declare interface SeoResult {
839
909
  description: string | null;
840
910
  }
841
911
 
842
- declare interface ShopifyCollection {
843
- id: string;
844
- handle: string;
845
- title: string;
846
- description: string;
847
- descriptionHtml: string;
848
- image: ImageResult | null;
849
- seo: SeoResult;
850
- updatedAt: string;
851
- metafields?: (MetafieldResult | null)[];
852
- products?: {
853
- filters: FilterResult[];
854
- };
855
- }
856
-
857
912
  declare type ShopifyGID<T extends ShopifyType> = `gid://shopify/${T}/${number}`;
858
913
 
859
- declare interface ShopifyPage {
860
- id: string;
861
- handle: string;
862
- title: string;
863
- body: string;
864
- bodySummary: string;
865
- seo: SeoResult;
866
- createdAt: string;
867
- updatedAt: string;
868
- onlineStoreUrl: string | null;
869
- metafields?: (MetafieldResult | null)[];
870
- }
871
-
872
- declare interface ShopifyProduct {
873
- id: string;
874
- title: string;
875
- handle: string;
876
- description: string;
877
- descriptionHtml: string;
878
- vendor: string;
879
- productType: string;
880
- tags: string[];
881
- availableForSale: boolean;
882
- isGiftCard: boolean;
883
- totalInventory: number;
884
- onlineStoreUrl: string | null;
885
- featuredImage: ImageResult | null;
886
- images: {
887
- nodes: ImageResult[];
888
- };
889
- priceRange: PriceRangeResult;
890
- compareAtPriceRange: PriceRangeResult;
891
- options: ProductOptionResult[];
892
- variants: {
893
- nodes: VariantResult[];
894
- };
895
- selectedOrFirstAvailableVariant: VariantResult | null;
896
- metafields?: (MetafieldResult | null)[];
897
- }
898
-
899
914
  declare type ShopifyType = 'Product' | 'ProductVariant' | 'Collection';
900
915
 
901
916
  export { Signal }
@@ -903,10 +918,14 @@ export { Signal }
903
918
  export { signal }
904
919
 
905
920
  declare interface Sort {
906
- label: string;
921
+ name: string;
907
922
  code: string;
923
+ scope?: SortScope[];
924
+ order?: number;
908
925
  }
909
926
 
927
+ declare type SortScope = 'search' | 'collection';
928
+
910
929
  export declare interface StorageAdapter {
911
930
  read(): string | null;
912
931
  write(data: string): void;
@@ -957,6 +976,59 @@ declare interface StorefrontClientConfig {
957
976
  fetch?: CustomFetch;
958
977
  }
959
978
 
979
+ declare interface StorefrontCollection {
980
+ id: string;
981
+ handle: string;
982
+ title: string;
983
+ description: string;
984
+ descriptionHtml: string;
985
+ image: ImageResult | null;
986
+ seo: SeoResult;
987
+ updatedAt: string;
988
+ metafields?: (MetafieldResult | null)[];
989
+ products?: {
990
+ filters: FilterResult[];
991
+ };
992
+ }
993
+
994
+ declare interface StorefrontPage {
995
+ id: string;
996
+ handle: string;
997
+ title: string;
998
+ body: string;
999
+ bodySummary: string;
1000
+ seo: SeoResult;
1001
+ createdAt: string;
1002
+ updatedAt: string;
1003
+ onlineStoreUrl: string | null;
1004
+ metafields?: (MetafieldResult | null)[];
1005
+ }
1006
+
1007
+ declare interface StorefrontProduct {
1008
+ id: string;
1009
+ title: string;
1010
+ handle: string;
1011
+ description: string;
1012
+ descriptionHtml: string;
1013
+ vendor: string;
1014
+ productType: string;
1015
+ tags: string[];
1016
+ availableForSale: boolean;
1017
+ isGiftCard: boolean;
1018
+ featuredImage: ImageResult | null;
1019
+ images: {
1020
+ nodes: ImageResult[];
1021
+ };
1022
+ priceRange: PriceRangeResult;
1023
+ compareAtPriceRange: PriceRangeResult;
1024
+ options: ProductOptionResult[];
1025
+ variants: {
1026
+ nodes: VariantResult_2[];
1027
+ };
1028
+ selectedOrFirstAvailableVariant: VariantResult_2 | null;
1029
+ metafields?: (MetafieldResult | null)[];
1030
+ }
1031
+
960
1032
  export declare interface StorefrontQuery {
961
1033
  ids: string[];
962
1034
  meta?: {
@@ -985,8 +1057,8 @@ export declare interface StorefrontQuery {
985
1057
 
986
1058
  export declare interface StorefrontResult<P extends Product = Product> {
987
1059
  products: P[];
988
- collection?: ShopifyCollection;
989
- page?: ShopifyPage;
1060
+ collection?: StorefrontCollection;
1061
+ page?: StorefrontPage;
990
1062
  }
991
1063
 
992
1064
  export declare interface StoreOptions {
@@ -1064,17 +1136,18 @@ declare interface VariantMetafield {
1064
1136
  compare_digest: string;
1065
1137
  }
1066
1138
 
1067
- declare interface VariantResult {
1139
+ declare interface VariantResult extends Omit<ProductResult, '__typename'> {
1140
+ __typename: 'Variant';
1141
+ product_id: number;
1142
+ variant_id: number;
1143
+ }
1144
+
1145
+ declare interface VariantResult_2 {
1068
1146
  id: string;
1069
1147
  title: string;
1070
1148
  availableForSale: boolean;
1071
1149
  currentlyNotInStock: boolean;
1072
- quantityAvailable: number;
1073
1150
  sku: string | null;
1074
- barcode: string | null;
1075
- weight: number | null;
1076
- weightUnit: 'KILOGRAMS' | 'GRAMS' | 'POUNDS' | 'OUNCES' | null;
1077
- requiresShipping: boolean;
1078
1151
  price: MoneyResult;
1079
1152
  compareAtPrice: MoneyResult | null;
1080
1153
  selectedOptions: SelectedOptionResult[];
@@ -1082,10 +1155,4 @@ declare interface VariantResult {
1082
1155
  metafields?: (MetafieldResult | null)[];
1083
1156
  }
1084
1157
 
1085
- declare interface VariantResult_2 extends Omit<ProductResult, '__typename'> {
1086
- __typename: 'Variant';
1087
- product_id: number;
1088
- variant_id: number;
1089
- }
1090
-
1091
1158
  export { }