@lana-commerce/core 12.0.0 → 13.0.0-alpha.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/CHANGELOG.md CHANGED
@@ -7,9 +7,15 @@ This project adheres to [Semantic Versioning][semantic versioning].
7
7
  ## [Unreleased]
8
8
 
9
9
  ### Major Changes
10
+
11
+ - Autocomplete APIs are removed in favor of "suggest" APIs.
12
+ - Search API pagination no longer supports keyset pagination, offset-based pagination becomes the only option.
13
+
10
14
  ### Minor Changes
11
15
  ### Patch Changes
12
16
 
17
+ - Update how "productFiltering" converts variant options to API search requests.
18
+
13
19
  ## [Released]
14
20
 
15
21
  ## 12.0.0 (2024-07-18)
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = "fragment ProductSearchResult on StorefrontProductSearchResult{last_key count items{...SearchProduct}options{...ProductSearchOptionAgg}price_max price_min}\n";
3
+ exports.default = "fragment ProductSearchResult on StorefrontProductSearchResult{count items{...SearchProduct}options{...ProductSearchOptionAgg}price_max price_min}\n";
@@ -21,4 +21,4 @@ exports.default = (CommonCartVariant_js_1.default +
21
21
  TieredPricing_js_1.default +
22
22
  TieredPricingTier_js_1.default +
23
23
  VariantOption_js_1.default +
24
- "query SearchProductsAdvanced($shopID:String!$data:[SearchOption!]!$lastKey:String!$limit:Int!$sortBy:SearchProductsSortBy!$sortDesc:Boolean!$aggregations:Boolean!){search:storefrontSearchProducts(shop_id:$shopID data:$data last_key:$lastKey limit:$limit sort_by:$sortBy sort_desc:$sortDesc aggregations:$aggregations){...ProductSearchResult}}");
24
+ "query SearchProductsAdvanced($shopID:String!$data:[SearchOption!]!$offset:Int!$limit:Int!$sortBy:SearchProductsSortBy!$sortDesc:Boolean!$aggregations:Boolean!){search:storefrontSearchProducts(shop_id:$shopID data:$data offset:$offset limit:$limit sort_by:$sortBy sort_desc:$sortDesc aggregations:$aggregations){...ProductSearchResult}}");
@@ -16,7 +16,7 @@ exports.defaultSearchData = {
16
16
  options: [],
17
17
  priceRange: null,
18
18
  count: 0,
19
- lastKey: "",
19
+ nextOffset: 0,
20
20
  hasMore: false,
21
21
  params: null,
22
22
  };
@@ -44,12 +44,12 @@ function createAdvancedSearch(config) {
44
44
  const loadProducts = (0, effector_1.createEvent)();
45
45
  const loadProductsFx = (0, effector_1.createEffect)((params) => tslib_1.__awaiter(this, void 0, void 0, function* () {
46
46
  // reset products iteration?
47
- const lastKey = (0, dequal_1.dequal)(params.params, params.currentParams) ? params.lastKey : "";
47
+ const offset = (0, dequal_1.dequal)(params.params, params.currentParams) ? params.offset : 0;
48
48
  const p = params.params;
49
49
  const data = (0, hierarchicalSearchOption_js_1.flattenHierarchicalSearchOptions)([...p.baseFilter, ...p.filter]);
50
50
  const agg = p.filter.length === 0; // do we need options aggregation?
51
51
  return (0, mapResponseData_js_1.mapResponseData)(yield (0, request_js_1.request)(config.graphql.searchProductsQuery)({
52
- lastKey,
52
+ offset,
53
53
  data,
54
54
  limit: p.limit,
55
55
  shopID: p.shopID,
@@ -57,6 +57,7 @@ function createAdvancedSearch(config) {
57
57
  sortDesc: p.sortDesc,
58
58
  aggregations: agg,
59
59
  }, config.opts), (d) => {
60
+ var _a, _b;
60
61
  const options = d.options.sort((a, b) => {
61
62
  return a.name.localeCompare(b.name);
62
63
  });
@@ -71,10 +72,10 @@ function createAdvancedSearch(config) {
71
72
  options: agg ? options : "keep",
72
73
  priceRange: agg ? { min: d.price_min, max: d.price_max } : "keep",
73
74
  count: d.count,
74
- lastKey: d.last_key,
75
- hasMore: lastKey && products.length === 0 ? false : true,
75
+ nextOffset: offset + ((_b = (_a = d.items) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0),
76
+ hasMore: offset > 0 && products.length === 0 ? false : true,
76
77
  params: p,
77
- mode: lastKey ? "append" : "replace",
78
+ mode: offset > 0 ? "append" : "replace",
78
79
  };
79
80
  });
80
81
  }));
@@ -88,7 +89,7 @@ function createAdvancedSearch(config) {
88
89
  return {
89
90
  products,
90
91
  count: r.count,
91
- lastKey: r.lastKey,
92
+ nextOffset: r.nextOffset,
92
93
  hasMore: r.hasMore && products.length < r.count,
93
94
  options: r.options === "keep" ? prevData.options : r.options,
94
95
  priceRange: r.priceRange === "keep" ? prevData.priceRange : r.priceRange,
@@ -101,7 +102,7 @@ function createAdvancedSearch(config) {
101
102
  const somethingIsPending = (0, combineSome_js_1.combineSome)(loadProductsFx.pending);
102
103
  const everythingIdle = somethingIsPending.map((pending) => !pending);
103
104
  (0, effector_1.guard)({
104
- source: (0, effector_1.sample)((0, effector_1.combine)(configWithJWTAndLocale, data), loadProducts, ([config, data], ev) => (Object.assign({ config, lastKey: data.lastKey, currentParams: data.params }, ev))),
105
+ source: (0, effector_1.sample)((0, effector_1.combine)(configWithJWTAndLocale, data), loadProducts, ([config, data], ev) => (Object.assign({ config, offset: data.nextOffset, currentParams: data.params }, ev))),
105
106
  filter: everythingIdle,
106
107
  target: loadProductsFx,
107
108
  });
@@ -109,7 +110,7 @@ function createAdvancedSearch(config) {
109
110
  (0, effector_1.guard)({
110
111
  source: (0, effector_1.sample)((0, effector_1.combine)(configWithJWTAndLocale, data), config.locale, ([config, data]) => ({
111
112
  config,
112
- lastKey: "",
113
+ offset: 0,
113
114
  currentParams: null,
114
115
  params: data.params,
115
116
  })),
@@ -102,11 +102,8 @@ function makeOptionFilter(optionID) {
102
102
  return {
103
103
  kind: "or",
104
104
  opts: vals.map((val) => ({
105
- kind: "and",
106
- opts: [
107
- { kind: "opt", opt: { op: "eq", name: "variants.options.option_id", text: optionID } },
108
- { kind: "opt", opt: { op: "eq", name: "variants.options.option_value_id", text: val } },
109
- ],
105
+ kind: "opt",
106
+ opt: { op: "eq", name: "variants.options", text: `${optionID}:${val}` },
110
107
  })),
111
108
  };
112
109
  },
@@ -1 +1 @@
1
- export default "fragment ProductSearchResult on StorefrontProductSearchResult{last_key count items{...SearchProduct}options{...ProductSearchOptionAgg}price_max price_min}\n";
1
+ export default "fragment ProductSearchResult on StorefrontProductSearchResult{count items{...SearchProduct}options{...ProductSearchOptionAgg}price_max price_min}\n";
@@ -18,4 +18,4 @@ export default (CommonCartVariant +
18
18
  TieredPricing +
19
19
  TieredPricingTier +
20
20
  VariantOption +
21
- "query SearchProductsAdvanced($shopID:String!$data:[SearchOption!]!$lastKey:String!$limit:Int!$sortBy:SearchProductsSortBy!$sortDesc:Boolean!$aggregations:Boolean!){search:storefrontSearchProducts(shop_id:$shopID data:$data last_key:$lastKey limit:$limit sort_by:$sortBy sort_desc:$sortDesc aggregations:$aggregations){...ProductSearchResult}}");
21
+ "query SearchProductsAdvanced($shopID:String!$data:[SearchOption!]!$offset:Int!$limit:Int!$sortBy:SearchProductsSortBy!$sortDesc:Boolean!$aggregations:Boolean!){search:storefrontSearchProducts(shop_id:$shopID data:$data offset:$offset limit:$limit sort_by:$sortBy sort_desc:$sortDesc aggregations:$aggregations){...ProductSearchResult}}");
@@ -12,7 +12,7 @@ export const defaultSearchData = {
12
12
  options: [],
13
13
  priceRange: null,
14
14
  count: 0,
15
- lastKey: "",
15
+ nextOffset: 0,
16
16
  hasMore: false,
17
17
  params: null,
18
18
  };
@@ -45,12 +45,12 @@ export function createAdvancedSearch(config) {
45
45
  const loadProducts = createEvent();
46
46
  const loadProductsFx = createEffect(async (params) => {
47
47
  // reset products iteration?
48
- const lastKey = dequal(params.params, params.currentParams) ? params.lastKey : "";
48
+ const offset = dequal(params.params, params.currentParams) ? params.offset : 0;
49
49
  const p = params.params;
50
50
  const data = flattenHierarchicalSearchOptions([...p.baseFilter, ...p.filter]);
51
51
  const agg = p.filter.length === 0; // do we need options aggregation?
52
52
  return mapResponseData(await request(config.graphql.searchProductsQuery)({
53
- lastKey,
53
+ offset,
54
54
  data,
55
55
  limit: p.limit,
56
56
  shopID: p.shopID,
@@ -72,10 +72,10 @@ export function createAdvancedSearch(config) {
72
72
  options: agg ? options : "keep",
73
73
  priceRange: agg ? { min: d.price_min, max: d.price_max } : "keep",
74
74
  count: d.count,
75
- lastKey: d.last_key,
76
- hasMore: lastKey && products.length === 0 ? false : true,
75
+ nextOffset: offset + (d.items?.length ?? 0),
76
+ hasMore: offset > 0 && products.length === 0 ? false : true,
77
77
  params: p,
78
- mode: lastKey ? "append" : "replace",
78
+ mode: offset > 0 ? "append" : "replace",
79
79
  };
80
80
  });
81
81
  });
@@ -89,7 +89,7 @@ export function createAdvancedSearch(config) {
89
89
  return {
90
90
  products,
91
91
  count: r.count,
92
- lastKey: r.lastKey,
92
+ nextOffset: r.nextOffset,
93
93
  hasMore: r.hasMore && products.length < r.count,
94
94
  options: r.options === "keep" ? prevData.options : r.options,
95
95
  priceRange: r.priceRange === "keep" ? prevData.priceRange : r.priceRange,
@@ -104,7 +104,7 @@ export function createAdvancedSearch(config) {
104
104
  guard({
105
105
  source: sample(combine(configWithJWTAndLocale, data), loadProducts, ([config, data], ev) => ({
106
106
  config,
107
- lastKey: data.lastKey,
107
+ offset: data.nextOffset,
108
108
  currentParams: data.params,
109
109
  ...ev,
110
110
  })),
@@ -115,7 +115,7 @@ export function createAdvancedSearch(config) {
115
115
  guard({
116
116
  source: sample(combine(configWithJWTAndLocale, data), config.locale, ([config, data]) => ({
117
117
  config,
118
- lastKey: "",
118
+ offset: 0,
119
119
  currentParams: null,
120
120
  params: data.params,
121
121
  })),
@@ -96,11 +96,8 @@ export function makeOptionFilter(optionID) {
96
96
  return {
97
97
  kind: "or",
98
98
  opts: vals.map((val) => ({
99
- kind: "and",
100
- opts: [
101
- { kind: "opt", opt: { op: "eq", name: "variants.options.option_id", text: optionID } },
102
- { kind: "opt", opt: { op: "eq", name: "variants.options.option_value_id", text: val } },
103
- ],
99
+ kind: "opt",
100
+ opt: { op: "eq", name: "variants.options", text: `${optionID}:${val}` },
104
101
  })),
105
102
  };
106
103
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lana-commerce/core",
3
- "version": "12.0.0",
3
+ "version": "13.0.0-alpha.2",
4
4
  "description": "Lana JS Core",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -1,2 +1,2 @@
1
- declare const _default: "fragment ProductSearchResult on StorefrontProductSearchResult{last_key count items{...SearchProduct}options{...ProductSearchOptionAgg}price_max price_min}\n";
1
+ declare const _default: "fragment ProductSearchResult on StorefrontProductSearchResult{count items{...SearchProduct}options{...ProductSearchOptionAgg}price_max price_min}\n";
2
2
  export default _default;
@@ -1177,7 +1177,6 @@ export interface ProductSearchOptionAggFragment {
1177
1177
  export interface ProductSearchResultFragment {
1178
1178
  count: number;
1179
1179
  items: Array<SearchProductFragment | null> | null;
1180
- last_key: string;
1181
1180
  options: Array<ProductSearchOptionAggFragment>;
1182
1181
  price_max: number;
1183
1182
  price_min: number;
@@ -2236,8 +2235,8 @@ export interface SearchProductsAdvancedQuery {
2236
2235
  export interface SearchProductsAdvancedQueryVariables {
2237
2236
  aggregations: boolean;
2238
2237
  data: Array<SearchOption>;
2239
- lastKey: string;
2240
2238
  limit: number;
2239
+ offset: number;
2241
2240
  shopID: string;
2242
2241
  sortBy: SearchProductsSortBy;
2243
2242
  sortDesc: boolean;
@@ -5172,8 +5172,6 @@ export interface ProductSearchResult {
5172
5172
  items: Array<{
5173
5173
  id: string;
5174
5174
  } | Product | null>;
5175
- /** Key of the last item for keyset based iteration */
5176
- last_key: string;
5177
5175
  /** Options aggregation */
5178
5176
  options: Array<ProductSearchOptionAgg>;
5179
5177
  /** Maximum price for given search conditions */
@@ -9838,24 +9836,6 @@ export interface EndpointAuthRefresh extends Endpoint<EndpointAuthRefresh, Token
9838
9836
  data(v: Token): EndpointAuthRefresh;
9839
9837
  extract(v: Extractor<TokenAndUserID>): EndpointAuthRefresh;
9840
9838
  }
9841
- export interface EndpointAutocompleteCustomers extends Endpoint<EndpointAutocompleteCustomers, CustomerExpandableItems> {
9842
- /** Unique shop identifier. See also: [Unique Identifiers](/overview/concepts/unique-identifiers) */
9843
- shop_id(v: string): EndpointAutocompleteCustomers;
9844
- data(v: Query): EndpointAutocompleteCustomers;
9845
- expand(v: CustomerExpandableItemsExpansionMap): EndpointAutocompleteCustomers;
9846
- extract(v: Extractor<CustomerExpandableItems>): EndpointAutocompleteCustomers;
9847
- }
9848
- export interface EndpointAutocompleteProducts extends Endpoint<EndpointAutocompleteProducts, ProductExpandableItems> {
9849
- /** Ignore bundle variant types */
9850
- ignore_bundles(v: boolean): EndpointAutocompleteProducts;
9851
- /** Unique shop identifier. See also: [Unique Identifiers](/overview/concepts/unique-identifiers) */
9852
- shop_id(v: string): EndpointAutocompleteProducts;
9853
- /** Filter output by variant type */
9854
- type(v: VariantTypeFilter): EndpointAutocompleteProducts;
9855
- data(v: Query): EndpointAutocompleteProducts;
9856
- expand(v: ProductExpandableItemsExpansionMap): EndpointAutocompleteProducts;
9857
- extract(v: Extractor<ProductExpandableItems>): EndpointAutocompleteProducts;
9858
- }
9859
9839
  export interface EndpointBlogs extends Endpoint<EndpointBlogs, Array<Blog>> {
9860
9840
  /** Output filtering */
9861
9841
  fields(v: Array<string>): EndpointBlogs;
@@ -13506,8 +13486,6 @@ export interface EndpointSearchOrders extends Endpoint<EndpointSearchOrders, Ord
13506
13486
  export interface EndpointSearchProducts extends Endpoint<EndpointSearchProducts, ProductSearchResult> {
13507
13487
  /** Whether to include aggregations into results or not */
13508
13488
  aggregations(v: boolean): EndpointSearchProducts;
13509
- /** Key of the last item from previous page. See also: [Pagination](/overview/concepts/pagination) */
13510
- last_key(v: string): EndpointSearchProducts;
13511
13489
  /** Return up to N entries (pagination). See also: [Pagination](/overview/concepts/pagination) */
13512
13490
  limit(v: number): EndpointSearchProducts;
13513
13491
  /** Skip N entries (pagination). See also: [Pagination](/overview/concepts/pagination) */
@@ -14027,6 +14005,8 @@ export interface EndpointSuggestProducts extends Endpoint<EndpointSuggestProduct
14027
14005
  ignore_bundles(v: boolean): EndpointSuggestProducts;
14028
14006
  /** Unique shop identifier. See also: [Unique Identifiers](/overview/concepts/unique-identifiers) */
14029
14007
  shop_id(v: string): EndpointSuggestProducts;
14008
+ /** Filter output by variant type */
14009
+ type(v: VariantTypeFilter): EndpointSuggestProducts;
14030
14010
  data(v: Query): EndpointSuggestProducts;
14031
14011
  expand(v: ProductExpandableItemsExpansionMap): EndpointSuggestProducts;
14032
14012
  extract(v: Extractor<ProductExpandableItems>): EndpointSuggestProducts;
@@ -14906,8 +14886,6 @@ export interface ReqFunction {
14906
14886
  (ctx: Context, v: "POST:auth/password/reset.json"): EndpointAuthPasswordReset;
14907
14887
  (ctx: Context, v: "POST:auth/password/verify.json"): EndpointAuthPasswordVerify;
14908
14888
  (ctx: Context, v: "POST:auth/refresh.json"): EndpointAuthRefresh;
14909
- (ctx: Context, v: "POST:autocomplete/customers.json"): EndpointAutocompleteCustomers;
14910
- (ctx: Context, v: "POST:autocomplete/products.json"): EndpointAutocompleteProducts;
14911
14889
  (ctx: Context, v: "GET:blogs.json"): EndpointBlogs;
14912
14890
  (ctx: Context, v: "GET:blogs/page.json"): EndpointBlogsPage;
14913
14891
  (ctx: Context, v: "GET:branding.json"): EndpointBranding;
@@ -2390,8 +2390,6 @@ export interface StorefrontProductSearchResult {
2390
2390
  items: Array<{
2391
2391
  id: string;
2392
2392
  } | StorefrontProduct | null>;
2393
- /** Key of the last item for keyset based iteration */
2394
- last_key: string;
2395
2393
  /** Options aggregation */
2396
2394
  options: Array<ProductSearchOptionAgg>;
2397
2395
  /** Maximum price for given search conditions */
@@ -3047,7 +3045,6 @@ export interface VariantOption {
3047
3045
  option_value_name: string;
3048
3046
  }
3049
3047
  export type VariantType = "bundle" | "digital_good" | "gift_card" | "physical" | "service";
3050
- export type VariantTypeFilter = "bundle" | "digital_good" | "gift_card" | "physical" | "service";
3051
3048
  export interface AddressShortExpansionMap {
3052
3049
  country?: true;
3053
3050
  province?: true;
@@ -3508,15 +3505,6 @@ export interface EndpointStorefrontAuthRequest extends Endpoint<EndpointStorefro
3508
3505
  shop_id(v: string): EndpointStorefrontAuthRequest;
3509
3506
  extract(v: Extractor<FileURL>): EndpointStorefrontAuthRequest;
3510
3507
  }
3511
- export interface EndpointStorefrontAutocompleteProducts extends Endpoint<EndpointStorefrontAutocompleteProducts, StorefrontProductExpandableItems> {
3512
- /** Unique shop identifier. See also: [Unique Identifiers](/overview/concepts/unique-identifiers) */
3513
- shop_id(v: string): EndpointStorefrontAutocompleteProducts;
3514
- /** Filter output by variant type */
3515
- type(v: VariantTypeFilter): EndpointStorefrontAutocompleteProducts;
3516
- data(v: Query): EndpointStorefrontAutocompleteProducts;
3517
- expand(v: StorefrontProductExpandableItemsExpansionMap): EndpointStorefrontAutocompleteProducts;
3518
- extract(v: Extractor<StorefrontProductExpandableItems>): EndpointStorefrontAutocompleteProducts;
3519
- }
3520
3508
  export interface EndpointStorefrontBranding extends Endpoint<EndpointStorefrontBranding, StorefrontBranding> {
3521
3509
  /** Output filtering */
3522
3510
  fields(v: Array<string>): EndpointStorefrontBranding;
@@ -4669,8 +4657,6 @@ export interface EndpointStorefrontReviewDimensions extends Endpoint<EndpointSto
4669
4657
  export interface EndpointStorefrontSearchProducts extends Endpoint<EndpointStorefrontSearchProducts, StorefrontProductSearchResult> {
4670
4658
  /** Whether to include aggregations into results or not */
4671
4659
  aggregations(v: boolean): EndpointStorefrontSearchProducts;
4672
- /** Key of the last item from previous page. See also: [Pagination](/overview/concepts/pagination) */
4673
- last_key(v: string): EndpointStorefrontSearchProducts;
4674
4660
  /** Return up to N entries (pagination). See also: [Pagination](/overview/concepts/pagination) */
4675
4661
  limit(v: number): EndpointStorefrontSearchProducts;
4676
4662
  /** Skip N entries (pagination). See also: [Pagination](/overview/concepts/pagination) */
@@ -4915,7 +4901,6 @@ export interface ReqFunction {
4915
4901
  (ctx: Context, v: "POST:storefront/auth/password/verify.json"): EndpointStorefrontAuthPasswordVerify;
4916
4902
  (ctx: Context, v: "POST:storefront/auth/refresh.json"): EndpointStorefrontAuthRefresh;
4917
4903
  (ctx: Context, v: "POST:storefront/auth/request.json"): EndpointStorefrontAuthRequest;
4918
- (ctx: Context, v: "POST:storefront/autocomplete/products.json"): EndpointStorefrontAutocompleteProducts;
4919
4904
  (ctx: Context, v: "GET:storefront/branding.json"): EndpointStorefrontBranding;
4920
4905
  (ctx: Context, v: "GET:storefront/branding/default.json"): EndpointStorefrontBrandingDefault;
4921
4906
  (ctx: Context, v: "GET:storefront/brands.json"): EndpointStorefrontBrands;
@@ -20,7 +20,7 @@ export interface SearchData<Product> {
20
20
  max: number;
21
21
  } | null;
22
22
  count: number;
23
- lastKey: string;
23
+ nextOffset: number;
24
24
  hasMore: boolean;
25
25
  params: ProductsPageQueryParameters | null;
26
26
  }
@@ -45,7 +45,6 @@ export interface AdvancedSearchConfig<Product> {
45
45
  search: {
46
46
  count: number;
47
47
  items: Array<Product | null> | null;
48
- last_key: string;
49
48
  options: Array<OptionAgg>;
50
49
  price_max: number;
51
50
  price_min: number;
@@ -53,7 +52,7 @@ export interface AdvancedSearchConfig<Product> {
53
52
  }, {
54
53
  aggregations: boolean;
55
54
  data: Array<SearchOption>;
56
- lastKey: string;
55
+ offset: number;
57
56
  limit: number;
58
57
  shopID: string;
59
58
  sortBy: SearchProductsSortBy;