@decocms/apps 0.23.3 → 0.25.0

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 (111) hide show
  1. package/LICENSE +21 -0
  2. package/commerce/components/Image.tsx +129 -143
  3. package/commerce/components/JsonLd.tsx +192 -201
  4. package/commerce/components/Picture.tsx +65 -75
  5. package/commerce/sdk/analytics.ts +15 -15
  6. package/commerce/sdk/formatPrice.ts +13 -16
  7. package/commerce/sdk/url.ts +7 -7
  8. package/commerce/sdk/useOffer.ts +46 -57
  9. package/commerce/sdk/useVariantPossibilities.ts +25 -25
  10. package/commerce/types/commerce.ts +868 -875
  11. package/commerce/utils/canonical.ts +5 -8
  12. package/commerce/utils/constants.ts +5 -6
  13. package/commerce/utils/filters.ts +4 -4
  14. package/commerce/utils/productToAnalyticsItem.ts +52 -56
  15. package/commerce/utils/stateByZip.ts +42 -42
  16. package/package.json +24 -4
  17. package/shopify/actions/cart/addItems.ts +24 -25
  18. package/shopify/actions/cart/updateCoupons.ts +19 -20
  19. package/shopify/actions/cart/updateItems.ts +19 -20
  20. package/shopify/actions/user/signIn.ts +25 -30
  21. package/shopify/actions/user/signUp.ts +19 -24
  22. package/shopify/client.ts +24 -24
  23. package/shopify/index.ts +20 -18
  24. package/shopify/init.ts +18 -21
  25. package/shopify/loaders/ProductDetailsPage.ts +16 -20
  26. package/shopify/loaders/ProductList.ts +66 -69
  27. package/shopify/loaders/ProductListingPage.ts +150 -158
  28. package/shopify/loaders/RelatedProducts.ts +24 -27
  29. package/shopify/loaders/cart.ts +53 -52
  30. package/shopify/loaders/shop.ts +22 -27
  31. package/shopify/loaders/user.ts +27 -32
  32. package/shopify/utils/admin/admin.ts +33 -34
  33. package/shopify/utils/admin/queries.ts +2 -2
  34. package/shopify/utils/cart.ts +18 -14
  35. package/shopify/utils/cookies.ts +62 -65
  36. package/shopify/utils/enums.ts +424 -424
  37. package/shopify/utils/graphql.ts +44 -55
  38. package/shopify/utils/storefront/queries.ts +24 -29
  39. package/shopify/utils/storefront/storefront.graphql.gen.ts +55 -55
  40. package/shopify/utils/transform.ts +370 -376
  41. package/shopify/utils/types.ts +118 -118
  42. package/shopify/utils/user.ts +11 -11
  43. package/shopify/utils/utils.ts +135 -140
  44. package/vtex/actions/address.ts +86 -86
  45. package/vtex/actions/auth.ts +14 -27
  46. package/vtex/actions/checkout.ts +36 -49
  47. package/vtex/actions/masterData.ts +10 -27
  48. package/vtex/actions/misc.ts +101 -111
  49. package/vtex/actions/newsletter.ts +48 -52
  50. package/vtex/actions/orders.ts +13 -16
  51. package/vtex/actions/profile.ts +55 -55
  52. package/vtex/actions/session.ts +36 -35
  53. package/vtex/actions/trigger.ts +25 -25
  54. package/vtex/actions/wishlist.ts +51 -53
  55. package/vtex/client.ts +14 -42
  56. package/vtex/hooks/index.ts +4 -4
  57. package/vtex/hooks/useAutocomplete.ts +42 -48
  58. package/vtex/hooks/useCart.ts +153 -165
  59. package/vtex/hooks/useUser.ts +40 -40
  60. package/vtex/hooks/useWishlist.ts +70 -70
  61. package/vtex/inline-loaders/productDetailsPage.ts +1 -3
  62. package/vtex/inline-loaders/productList.ts +121 -127
  63. package/vtex/inline-loaders/productListShelf.ts +159 -0
  64. package/vtex/inline-loaders/productListingPage.ts +10 -34
  65. package/vtex/inline-loaders/relatedProducts.ts +1 -3
  66. package/vtex/inline-loaders/suggestions.ts +36 -39
  67. package/vtex/inline-loaders/workflowProducts.ts +45 -49
  68. package/vtex/invoke.ts +159 -194
  69. package/vtex/loaders/address.ts +49 -54
  70. package/vtex/loaders/brands.ts +19 -26
  71. package/vtex/loaders/cart.ts +24 -21
  72. package/vtex/loaders/catalog.ts +51 -53
  73. package/vtex/loaders/collections.ts +25 -27
  74. package/vtex/loaders/legacy.ts +487 -534
  75. package/vtex/loaders/logistics.ts +33 -37
  76. package/vtex/loaders/navbar.ts +5 -8
  77. package/vtex/loaders/orders.ts +28 -39
  78. package/vtex/loaders/pageType.ts +41 -35
  79. package/vtex/loaders/payment.ts +27 -37
  80. package/vtex/loaders/profile.ts +38 -38
  81. package/vtex/loaders/promotion.ts +5 -8
  82. package/vtex/loaders/search.ts +56 -59
  83. package/vtex/loaders/session.ts +22 -30
  84. package/vtex/loaders/user.ts +39 -41
  85. package/vtex/loaders/wishlist.ts +35 -35
  86. package/vtex/loaders/wishlistProducts.ts +3 -15
  87. package/vtex/loaders/workflow.ts +220 -227
  88. package/vtex/middleware.ts +116 -119
  89. package/vtex/types.ts +201 -201
  90. package/vtex/utils/batch.ts +13 -16
  91. package/vtex/utils/cookies.ts +76 -80
  92. package/vtex/utils/enrichment.ts +62 -42
  93. package/vtex/utils/fetchCache.ts +1 -4
  94. package/vtex/utils/index.ts +6 -6
  95. package/vtex/utils/intelligentSearch.ts +48 -57
  96. package/vtex/utils/legacy.ts +108 -124
  97. package/vtex/utils/pickAndOmit.ts +15 -20
  98. package/vtex/utils/proxy.ts +136 -146
  99. package/vtex/utils/resourceRange.ts +3 -3
  100. package/vtex/utils/segment.ts +100 -111
  101. package/vtex/utils/similars.ts +1 -2
  102. package/vtex/utils/sitemap.ts +91 -91
  103. package/vtex/utils/slugCache.ts +2 -6
  104. package/vtex/utils/slugify.ts +9 -9
  105. package/vtex/utils/transform.ts +1178 -1105
  106. package/vtex/utils/types.ts +1381 -1381
  107. package/vtex/utils/vtexId.ts +44 -47
  108. package/.github/workflows/release.yml +0 -34
  109. package/.releaserc.json +0 -28
  110. package/knip.json +0 -19
  111. package/tsconfig.json +0 -11
@@ -1,191 +1,191 @@
1
- import {
2
- CountryCode,
3
- CurrencyCode,
4
- OrderCancelReason,
5
- OrderFinancialStatus,
6
- OrderFulfillmentStatus,
1
+ import type {
2
+ CountryCode,
3
+ CurrencyCode,
4
+ OrderCancelReason,
5
+ OrderFinancialStatus,
6
+ OrderFulfillmentStatus,
7
7
  } from "./enums";
8
8
 
9
9
  type Attribute = {
10
- key: string;
11
- value?: string;
10
+ key: string;
11
+ value?: string;
12
12
  };
13
13
 
14
14
  type MailingAddress = {
15
- address1?: string;
16
- address2?: string;
17
- city?: string;
18
- company?: string;
19
- country?: string;
20
- countryCodeV2?: CountryCode;
21
- firstName?: string;
22
- formattedArea?: string;
23
- id: string;
24
- lastName?: string;
25
- latitude?: number;
26
- longitude?: number;
27
- name?: string;
28
- phone?: string;
29
- province?: string;
30
- provinceCode?: string;
31
- zip?: string;
15
+ address1?: string;
16
+ address2?: string;
17
+ city?: string;
18
+ company?: string;
19
+ country?: string;
20
+ countryCodeV2?: CountryCode;
21
+ firstName?: string;
22
+ formattedArea?: string;
23
+ id: string;
24
+ lastName?: string;
25
+ latitude?: number;
26
+ longitude?: number;
27
+ name?: string;
28
+ phone?: string;
29
+ province?: string;
30
+ provinceCode?: string;
31
+ zip?: string;
32
32
  };
33
33
 
34
34
  type MoneyV2 = {
35
- amount: number;
36
- currencyCode: CurrencyCode;
35
+ amount: number;
36
+ currencyCode: CurrencyCode;
37
37
  };
38
38
 
39
39
  type AppliedGiftCard = {
40
- amountUsed: MoneyV2;
41
- balance: MoneyV2;
42
- id: string;
43
- lastCharacters: string;
44
- presentmentAmountUsed: MoneyV2;
40
+ amountUsed: MoneyV2;
41
+ balance: MoneyV2;
42
+ id: string;
43
+ lastCharacters: string;
44
+ presentmentAmountUsed: MoneyV2;
45
45
  };
46
46
 
47
47
  type ShippingRate = {
48
- handle: string;
49
- price: MoneyV2;
50
- title: string;
48
+ handle: string;
49
+ price: MoneyV2;
50
+ title: string;
51
51
  };
52
52
 
53
53
  type AvailableShippingRates = {
54
- ready: boolean;
55
- shippingRates?: ShippingRate[];
54
+ ready: boolean;
55
+ shippingRates?: ShippingRate[];
56
56
  };
57
57
 
58
58
  type CheckoutBuyerIdentity = {
59
- countryCode: CountryCode;
59
+ countryCode: CountryCode;
60
60
  };
61
61
 
62
62
  type Order = {
63
- billingAddress?: MailingAddress;
64
- cancelReason?: OrderCancelReason;
65
- canceledAt?: Date;
66
- currencyCode: CurrencyCode;
67
- currentSubtotalPrice: MoneyV2;
68
- currentTotalDuties?: MoneyV2;
69
- currentTotalPrice: MoneyV2;
70
- currentTotalTax: MoneyV2;
71
- customAttributes: Attribute[];
72
- customerLocale?: string;
73
- customerUrl?: string;
74
- edited: boolean;
75
- email?: string;
76
- financialStatus?: OrderFinancialStatus;
77
- fulfillmentStatus: OrderFulfillmentStatus;
78
- id: string;
79
- name: string;
80
- orderNumber: number;
81
- originalTotalDuties?: MoneyV2;
82
- originalTotalPrice: MoneyV2;
83
- phone?: string;
84
- processedAt: Date;
85
- shippingAddress?: MailingAddress;
63
+ billingAddress?: MailingAddress;
64
+ cancelReason?: OrderCancelReason;
65
+ canceledAt?: Date;
66
+ currencyCode: CurrencyCode;
67
+ currentSubtotalPrice: MoneyV2;
68
+ currentTotalDuties?: MoneyV2;
69
+ currentTotalPrice: MoneyV2;
70
+ currentTotalTax: MoneyV2;
71
+ customAttributes: Attribute[];
72
+ customerLocale?: string;
73
+ customerUrl?: string;
74
+ edited: boolean;
75
+ email?: string;
76
+ financialStatus?: OrderFinancialStatus;
77
+ fulfillmentStatus: OrderFulfillmentStatus;
78
+ id: string;
79
+ name: string;
80
+ orderNumber: number;
81
+ originalTotalDuties?: MoneyV2;
82
+ originalTotalPrice: MoneyV2;
83
+ phone?: string;
84
+ processedAt: Date;
85
+ shippingAddress?: MailingAddress;
86
86
  };
87
87
 
88
88
  type Checkout = {
89
- appliedGiftCards: AppliedGiftCard[];
90
- availableShippingRates?: AvailableShippingRates;
91
- buyerIdentity: CheckoutBuyerIdentity;
92
- completedAt?: Date;
93
- createdAt: Date;
94
- currencyCode: CurrencyCode;
95
- customAttributes: Attribute[];
96
- email?: string;
97
- id: string;
98
- lineItemsSubtotalPrice: MoneyV2;
99
- note: string;
100
- order: Order;
101
- orderStatusUrl: string;
102
- paymentDue: MoneyV2;
103
- ready: boolean;
104
- requireShipping: boolean;
105
- shippingAddress: MailingAddress;
89
+ appliedGiftCards: AppliedGiftCard[];
90
+ availableShippingRates?: AvailableShippingRates;
91
+ buyerIdentity: CheckoutBuyerIdentity;
92
+ completedAt?: Date;
93
+ createdAt: Date;
94
+ currencyCode: CurrencyCode;
95
+ customAttributes: Attribute[];
96
+ email?: string;
97
+ id: string;
98
+ lineItemsSubtotalPrice: MoneyV2;
99
+ note: string;
100
+ order: Order;
101
+ orderStatusUrl: string;
102
+ paymentDue: MoneyV2;
103
+ ready: boolean;
104
+ requireShipping: boolean;
105
+ shippingAddress: MailingAddress;
106
106
  };
107
107
 
108
108
  type Customer = {
109
- acceptsMarketing: boolean;
110
- createdAt: Date;
111
- defaultAddress: MailingAddress;
112
- displayName: string;
113
- email: string;
114
- firstName: string;
115
- id: string;
116
- checkout: Checkout;
109
+ acceptsMarketing: boolean;
110
+ createdAt: Date;
111
+ defaultAddress: MailingAddress;
112
+ displayName: string;
113
+ email: string;
114
+ firstName: string;
115
+ id: string;
116
+ checkout: Checkout;
117
117
  };
118
118
 
119
119
  type CartBuyerIdentity = {
120
- countryCode: string;
121
- customer: Customer;
120
+ countryCode: string;
121
+ customer: Customer;
122
122
  };
123
123
 
124
124
  export type OldCart = {
125
- attribute?: Attribute;
126
- attributes?: Attribute[];
127
- buyerIdentity?: CartBuyerIdentity;
128
- id: string;
125
+ attribute?: Attribute;
126
+ attributes?: Attribute[];
127
+ buyerIdentity?: CartBuyerIdentity;
128
+ id: string;
129
129
  };
130
130
 
131
131
  export interface Money {
132
- amount: number;
133
- currencyCode: string;
132
+ amount: number;
133
+ currencyCode: string;
134
134
  }
135
135
 
136
136
  export interface Image {
137
- url: string;
138
- width: number;
139
- height: number;
140
- altText: string;
137
+ url: string;
138
+ width: number;
139
+ height: number;
140
+ altText: string;
141
141
  }
142
142
 
143
143
  export interface Media {
144
- nodes: Media[];
144
+ nodes: Media[];
145
145
  }
146
146
 
147
147
  export interface Media {
148
- alt: string;
149
- previewImage: Image;
150
- mediaContentType: string;
148
+ alt: string;
149
+ previewImage: Image;
150
+ mediaContentType: string;
151
151
  }
152
152
 
153
153
  export interface Option {
154
- name: string;
155
- values: string[];
154
+ name: string;
155
+ values: string[];
156
156
  }
157
157
 
158
158
  export interface PriceRange {
159
- minVariantPrice: Price;
160
- maxVariantPrice: Price;
159
+ minVariantPrice: Price;
160
+ maxVariantPrice: Price;
161
161
  }
162
162
 
163
163
  export interface Price {
164
- amount: string;
165
- currencyCode: string;
164
+ amount: string;
165
+ currencyCode: string;
166
166
  }
167
167
 
168
168
  export interface SEO {
169
- title: string;
170
- description: string;
169
+ title: string;
170
+ description: string;
171
171
  }
172
172
 
173
173
  export interface SelectedOption {
174
- name: string;
175
- value: string;
174
+ name: string;
175
+ value: string;
176
176
  }
177
177
 
178
178
  export interface UnitPriceMeasurement {
179
- measuredType: null;
180
- quantityValue: number;
181
- referenceUnit: null;
182
- quantityUnit: null;
179
+ measuredType: null;
180
+ quantityValue: number;
181
+ referenceUnit: null;
182
+ quantityUnit: null;
183
183
  }
184
184
 
185
185
  /**
186
186
  * @title {{{key}}}
187
187
  */
188
188
  export interface Metafield {
189
- namespace: string;
190
- key: string;
189
+ namespace: string;
190
+ key: string;
191
191
  }
@@ -5,19 +5,19 @@ const CUSTOMER_COOKIE = "secure_customer_sig";
5
5
  const ONE_WEEK_MS = 7 * 24 * 3600 * 1_000;
6
6
 
7
7
  export const getUserCookie = (headers: Headers): string | undefined => {
8
- const cookies = getCookies(headers);
8
+ const cookies = getCookies(headers);
9
9
 
10
- return cookies[CUSTOMER_COOKIE];
10
+ return cookies[CUSTOMER_COOKIE];
11
11
  };
12
12
 
13
13
  export const setUserCookie = (headers: Headers, accessToken: string) => {
14
- setCookie(headers, {
15
- name: CUSTOMER_COOKIE,
16
- value: accessToken,
17
- path: "/",
18
- expires: new Date(Date.now() + ONE_WEEK_MS),
19
- httpOnly: true,
20
- secure: true,
21
- sameSite: "Lax",
22
- });
14
+ setCookie(headers, {
15
+ name: CUSTOMER_COOKIE,
16
+ value: accessToken,
17
+ path: "/",
18
+ expires: new Date(Date.now() + ONE_WEEK_MS),
19
+ httpOnly: true,
20
+ secure: true,
21
+ sameSite: "Lax",
22
+ });
23
23
  };
@@ -1,164 +1,159 @@
1
- import {
2
- InputMaybe,
3
- ProductCollectionSortKeys,
4
- ProductFilter,
5
- SearchSortKeys as SearchSortKeysShopify,
1
+ import type {
2
+ InputMaybe,
3
+ ProductCollectionSortKeys,
4
+ ProductFilter,
5
+ SearchSortKeys as SearchSortKeysShopify,
6
6
  } from "../utils/storefront/storefront.graphql.gen";
7
7
 
8
8
  export const sortOptions = [
9
- { value: "", label: "relevance:desc" },
10
- { value: "price-ascending", label: "price:asc" },
11
- { value: "price-descending", label: "price:desc" },
12
- { value: "best-selling", label: "orders:desc" },
13
- { value: "title-ascending", label: "name:asc" },
14
- { value: "title-descending", label: "name:desc" },
15
- { value: "created-descending", label: "release:desc" },
9
+ { value: "", label: "relevance:desc" },
10
+ { value: "price-ascending", label: "price:asc" },
11
+ { value: "price-descending", label: "price:desc" },
12
+ { value: "best-selling", label: "orders:desc" },
13
+ { value: "title-ascending", label: "name:asc" },
14
+ { value: "title-descending", label: "name:desc" },
15
+ { value: "created-descending", label: "release:desc" },
16
16
  ];
17
17
 
18
18
  // only these sorts work for search at shopify
19
19
  export const searchSortOptions = [
20
- { value: "", label: "relevance:desc" },
21
- { value: "price-ascending", label: "price:asc" },
22
- { value: "price-descending", label: "price:desc" },
20
+ { value: "", label: "relevance:desc" },
21
+ { value: "price-ascending", label: "price:asc" },
22
+ { value: "price-descending", label: "price:desc" },
23
23
  ];
24
24
 
25
25
  export type CollectionSortKeys =
26
- | ""
27
- | "price-descending"
28
- | "price-ascending"
29
- | "best-selling"
30
- | "title-descending"
31
- | "title-ascending"
32
- | "created-descending";
26
+ | ""
27
+ | "price-descending"
28
+ | "price-ascending"
29
+ | "best-selling"
30
+ | "title-descending"
31
+ | "title-ascending"
32
+ | "created-descending";
33
33
 
34
- export type SearchSortKeys =
35
- | ""
36
- | "price-descending"
37
- | "price-ascending";
34
+ export type SearchSortKeys = "" | "price-descending" | "price-ascending";
38
35
 
39
36
  export const searchSortShopify: Record<
40
- string,
41
- { sortKey: SearchSortKeysShopify; reverse: boolean }
37
+ string,
38
+ { sortKey: SearchSortKeysShopify; reverse: boolean }
42
39
  > = {
43
- "": {
44
- sortKey: "RELEVANCE",
45
- reverse: false,
46
- },
47
- "price-descending": {
48
- sortKey: "PRICE",
49
- reverse: true,
50
- },
51
- "price-ascending": {
52
- sortKey: "PRICE",
53
- reverse: false,
54
- },
40
+ "": {
41
+ sortKey: "RELEVANCE",
42
+ reverse: false,
43
+ },
44
+ "price-descending": {
45
+ sortKey: "PRICE",
46
+ reverse: true,
47
+ },
48
+ "price-ascending": {
49
+ sortKey: "PRICE",
50
+ reverse: false,
51
+ },
55
52
  };
56
53
 
57
54
  export const sortShopify: Record<
58
- string,
59
- {
60
- sortKey: ProductCollectionSortKeys | SearchSortKeysShopify;
61
- reverse: boolean;
62
- }
55
+ string,
56
+ {
57
+ sortKey: ProductCollectionSortKeys | SearchSortKeysShopify;
58
+ reverse: boolean;
59
+ }
63
60
  > = {
64
- "": {
65
- sortKey: "RELEVANCE",
66
- reverse: false,
67
- },
68
- "price-descending": {
69
- sortKey: "PRICE",
70
- reverse: true,
71
- },
72
- "price-ascending": {
73
- sortKey: "PRICE",
74
- reverse: false,
75
- },
76
- "best-selling": {
77
- sortKey: "BEST_SELLING",
78
- reverse: false,
79
- },
80
- "title-descending": {
81
- sortKey: "TITLE",
82
- reverse: true,
83
- },
84
- "title-ascending": {
85
- sortKey: "TITLE",
86
- reverse: false,
87
- },
88
- "created-descending": {
89
- sortKey: "CREATED",
90
- reverse: true,
91
- },
61
+ "": {
62
+ sortKey: "RELEVANCE",
63
+ reverse: false,
64
+ },
65
+ "price-descending": {
66
+ sortKey: "PRICE",
67
+ reverse: true,
68
+ },
69
+ "price-ascending": {
70
+ sortKey: "PRICE",
71
+ reverse: false,
72
+ },
73
+ "best-selling": {
74
+ sortKey: "BEST_SELLING",
75
+ reverse: false,
76
+ },
77
+ "title-descending": {
78
+ sortKey: "TITLE",
79
+ reverse: true,
80
+ },
81
+ "title-ascending": {
82
+ sortKey: "TITLE",
83
+ reverse: false,
84
+ },
85
+ "created-descending": {
86
+ sortKey: "CREATED",
87
+ reverse: true,
88
+ },
92
89
  };
93
90
 
94
- export const filterToObject = (
95
- type: string,
96
- filter: InputMaybe<ProductFilter>,
97
- ) => {
98
- if (type == "tag") {
99
- return { tag: filter?.tag };
100
- }
101
- if (type == "productType") {
102
- return { productType: filter?.productType };
103
- }
104
- if (type == "productVendor") {
105
- return { productVendor: filter?.productVendor };
106
- }
107
- if (type == "priceMin") {
108
- return { price: { min: filter?.price?.min } };
109
- }
110
- if (type == "priceMax") {
111
- return { price: { max: filter?.price?.max } };
112
- }
113
- if (type == "variantOption") {
114
- return { variantOption: filter?.variantOption };
115
- }
91
+ export const filterToObject = (type: string, filter: InputMaybe<ProductFilter>) => {
92
+ if (type === "tag") {
93
+ return { tag: filter?.tag };
94
+ }
95
+ if (type === "productType") {
96
+ return { productType: filter?.productType };
97
+ }
98
+ if (type === "productVendor") {
99
+ return { productVendor: filter?.productVendor };
100
+ }
101
+ if (type === "priceMin") {
102
+ return { price: { min: filter?.price?.min } };
103
+ }
104
+ if (type === "priceMax") {
105
+ return { price: { max: filter?.price?.max } };
106
+ }
107
+ if (type === "variantOption") {
108
+ return { variantOption: filter?.variantOption };
109
+ }
110
+ return undefined;
116
111
  };
117
112
 
118
113
  export const getFiltersByUrl = (url: URL) => {
119
- const filters: InputMaybe<ProductFilter[]> | undefined = [];
120
- url.searchParams.forEach((value, key) => {
121
- if (key.startsWith("filter.v.option")) {
122
- filters.push({
123
- variantOption: { name: key.split(".")[3], value: value },
124
- });
125
- } else if (key.startsWith("filter.p.tag")) {
126
- filters.push({ tag: value });
127
- } else if (key.startsWith("filter.p.type")) {
128
- filters.push({ productType: value });
129
- } else if (key.startsWith("filter.p.product_type")) {
130
- filters.push({ productType: value });
131
- } else if (key.startsWith("filter.p.vendor")) {
132
- filters.push({ productVendor: value });
133
- } else if (key.startsWith("filter.v.availability")) {
134
- filters.push({ available: value.toLowerCase() === "in stock" });
135
- } else if (key.startsWith("filter.v.price.gte")) {
136
- filters.push({ price: { min: Number(value) } });
137
- } else if (key.startsWith("filter.v.price.lte")) {
138
- filters.push({ price: { max: Number(value) } });
139
- } else if (key.startsWith("filter.p.m.custom")) {
140
- filters.push({
141
- productMetafield: {
142
- namespace: "custom",
143
- key: key.replace("filter.p.m.custom.", ""),
144
- value: value,
145
- },
146
- });
147
- } else if (key.startsWith("filter.v.t.shopify")) {
148
- filters.push({
149
- taxonomyMetafield: {
150
- namespace: "shopify",
151
- key: key.replace("filter.v.t.shopify.", ""),
152
- value: value,
153
- },
154
- });
155
- } else if (key.startsWith("filter.p.t.category")) {
156
- filters.push({
157
- category: {
158
- id: value,
159
- },
160
- });
161
- }
162
- });
163
- return filters;
114
+ const filters: InputMaybe<ProductFilter[]> | undefined = [];
115
+ url.searchParams.forEach((value, key) => {
116
+ if (key.startsWith("filter.v.option")) {
117
+ filters.push({
118
+ variantOption: { name: key.split(".")[3], value: value },
119
+ });
120
+ } else if (key.startsWith("filter.p.tag")) {
121
+ filters.push({ tag: value });
122
+ } else if (key.startsWith("filter.p.type")) {
123
+ filters.push({ productType: value });
124
+ } else if (key.startsWith("filter.p.product_type")) {
125
+ filters.push({ productType: value });
126
+ } else if (key.startsWith("filter.p.vendor")) {
127
+ filters.push({ productVendor: value });
128
+ } else if (key.startsWith("filter.v.availability")) {
129
+ filters.push({ available: value.toLowerCase() === "in stock" });
130
+ } else if (key.startsWith("filter.v.price.gte")) {
131
+ filters.push({ price: { min: Number(value) } });
132
+ } else if (key.startsWith("filter.v.price.lte")) {
133
+ filters.push({ price: { max: Number(value) } });
134
+ } else if (key.startsWith("filter.p.m.custom")) {
135
+ filters.push({
136
+ productMetafield: {
137
+ namespace: "custom",
138
+ key: key.replace("filter.p.m.custom.", ""),
139
+ value: value,
140
+ },
141
+ });
142
+ } else if (key.startsWith("filter.v.t.shopify")) {
143
+ filters.push({
144
+ taxonomyMetafield: {
145
+ namespace: "shopify",
146
+ key: key.replace("filter.v.t.shopify.", ""),
147
+ value: value,
148
+ },
149
+ });
150
+ } else if (key.startsWith("filter.p.t.category")) {
151
+ filters.push({
152
+ category: {
153
+ id: value,
154
+ },
155
+ });
156
+ }
157
+ });
158
+ return filters;
164
159
  };