@decocms/apps 0.23.3 → 0.24.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.
- package/LICENSE +21 -0
- package/commerce/components/Image.tsx +129 -143
- package/commerce/components/JsonLd.tsx +192 -201
- package/commerce/components/Picture.tsx +65 -75
- package/commerce/sdk/analytics.ts +15 -15
- package/commerce/sdk/formatPrice.ts +13 -16
- package/commerce/sdk/url.ts +7 -7
- package/commerce/sdk/useOffer.ts +46 -57
- package/commerce/sdk/useVariantPossibilities.ts +25 -25
- package/commerce/types/commerce.ts +868 -875
- package/commerce/utils/canonical.ts +5 -8
- package/commerce/utils/constants.ts +5 -6
- package/commerce/utils/filters.ts +4 -4
- package/commerce/utils/productToAnalyticsItem.ts +52 -56
- package/commerce/utils/stateByZip.ts +42 -42
- package/package.json +23 -4
- package/shopify/actions/cart/addItems.ts +24 -25
- package/shopify/actions/cart/updateCoupons.ts +19 -20
- package/shopify/actions/cart/updateItems.ts +19 -20
- package/shopify/actions/user/signIn.ts +25 -30
- package/shopify/actions/user/signUp.ts +19 -24
- package/shopify/client.ts +24 -24
- package/shopify/index.ts +20 -18
- package/shopify/init.ts +18 -21
- package/shopify/loaders/ProductDetailsPage.ts +16 -20
- package/shopify/loaders/ProductList.ts +66 -69
- package/shopify/loaders/ProductListingPage.ts +150 -158
- package/shopify/loaders/RelatedProducts.ts +24 -27
- package/shopify/loaders/cart.ts +53 -52
- package/shopify/loaders/shop.ts +22 -27
- package/shopify/loaders/user.ts +27 -32
- package/shopify/utils/admin/admin.ts +33 -34
- package/shopify/utils/admin/queries.ts +2 -2
- package/shopify/utils/cart.ts +18 -14
- package/shopify/utils/cookies.ts +62 -65
- package/shopify/utils/enums.ts +424 -424
- package/shopify/utils/graphql.ts +44 -55
- package/shopify/utils/storefront/queries.ts +24 -29
- package/shopify/utils/storefront/storefront.graphql.gen.ts +55 -55
- package/shopify/utils/transform.ts +370 -376
- package/shopify/utils/types.ts +118 -118
- package/shopify/utils/user.ts +11 -11
- package/shopify/utils/utils.ts +135 -140
- package/vtex/actions/address.ts +86 -86
- package/vtex/actions/auth.ts +14 -27
- package/vtex/actions/checkout.ts +36 -49
- package/vtex/actions/masterData.ts +10 -27
- package/vtex/actions/misc.ts +101 -111
- package/vtex/actions/newsletter.ts +48 -52
- package/vtex/actions/orders.ts +13 -16
- package/vtex/actions/profile.ts +55 -55
- package/vtex/actions/session.ts +36 -35
- package/vtex/actions/trigger.ts +25 -25
- package/vtex/actions/wishlist.ts +51 -53
- package/vtex/client.ts +14 -42
- package/vtex/hooks/index.ts +4 -4
- package/vtex/hooks/useAutocomplete.ts +42 -48
- package/vtex/hooks/useCart.ts +153 -165
- package/vtex/hooks/useUser.ts +40 -40
- package/vtex/hooks/useWishlist.ts +70 -70
- package/vtex/inline-loaders/productDetailsPage.ts +1 -3
- package/vtex/inline-loaders/productList.ts +121 -127
- package/vtex/inline-loaders/productListingPage.ts +10 -34
- package/vtex/inline-loaders/relatedProducts.ts +1 -3
- package/vtex/inline-loaders/suggestions.ts +36 -39
- package/vtex/inline-loaders/workflowProducts.ts +45 -49
- package/vtex/invoke.ts +159 -194
- package/vtex/loaders/address.ts +49 -54
- package/vtex/loaders/brands.ts +19 -26
- package/vtex/loaders/cart.ts +24 -21
- package/vtex/loaders/catalog.ts +51 -53
- package/vtex/loaders/collections.ts +25 -27
- package/vtex/loaders/legacy.ts +487 -534
- package/vtex/loaders/logistics.ts +33 -37
- package/vtex/loaders/navbar.ts +5 -8
- package/vtex/loaders/orders.ts +28 -39
- package/vtex/loaders/pageType.ts +41 -35
- package/vtex/loaders/payment.ts +27 -37
- package/vtex/loaders/profile.ts +38 -38
- package/vtex/loaders/promotion.ts +5 -8
- package/vtex/loaders/search.ts +56 -59
- package/vtex/loaders/session.ts +22 -30
- package/vtex/loaders/user.ts +39 -41
- package/vtex/loaders/wishlist.ts +35 -35
- package/vtex/loaders/wishlistProducts.ts +3 -15
- package/vtex/loaders/workflow.ts +220 -227
- package/vtex/middleware.ts +116 -119
- package/vtex/types.ts +201 -201
- package/vtex/utils/batch.ts +13 -16
- package/vtex/utils/cookies.ts +76 -80
- package/vtex/utils/enrichment.ts +62 -42
- package/vtex/utils/fetchCache.ts +1 -4
- package/vtex/utils/index.ts +6 -6
- package/vtex/utils/intelligentSearch.ts +48 -57
- package/vtex/utils/legacy.ts +108 -124
- package/vtex/utils/pickAndOmit.ts +15 -20
- package/vtex/utils/proxy.ts +136 -146
- package/vtex/utils/resourceRange.ts +3 -3
- package/vtex/utils/segment.ts +100 -111
- package/vtex/utils/similars.ts +1 -2
- package/vtex/utils/sitemap.ts +91 -91
- package/vtex/utils/slugCache.ts +2 -6
- package/vtex/utils/slugify.ts +9 -9
- package/vtex/utils/transform.ts +1012 -1105
- package/vtex/utils/types.ts +1381 -1381
- package/vtex/utils/vtexId.ts +44 -47
- package/.github/workflows/release.yml +0 -34
- package/.releaserc.json +0 -28
- package/knip.json +0 -19
- package/tsconfig.json +0 -11
package/shopify/utils/types.ts
CHANGED
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type {
|
|
2
|
+
CountryCode,
|
|
3
|
+
CurrencyCode,
|
|
4
|
+
OrderCancelReason,
|
|
5
|
+
OrderFinancialStatus,
|
|
6
|
+
OrderFulfillmentStatus,
|
|
7
7
|
} from "./enums";
|
|
8
8
|
|
|
9
9
|
type Attribute = {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
key: string;
|
|
11
|
+
value?: string;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
type MailingAddress = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
36
|
-
|
|
35
|
+
amount: number;
|
|
36
|
+
currencyCode: CurrencyCode;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
type AppliedGiftCard = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
amountUsed: MoneyV2;
|
|
41
|
+
balance: MoneyV2;
|
|
42
|
+
id: string;
|
|
43
|
+
lastCharacters: string;
|
|
44
|
+
presentmentAmountUsed: MoneyV2;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
type ShippingRate = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
handle: string;
|
|
49
|
+
price: MoneyV2;
|
|
50
|
+
title: string;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
type AvailableShippingRates = {
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
ready: boolean;
|
|
55
|
+
shippingRates?: ShippingRate[];
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
type CheckoutBuyerIdentity = {
|
|
59
|
-
|
|
59
|
+
countryCode: CountryCode;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
type Order = {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
121
|
-
|
|
120
|
+
countryCode: string;
|
|
121
|
+
customer: Customer;
|
|
122
122
|
};
|
|
123
123
|
|
|
124
124
|
export type OldCart = {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
attribute?: Attribute;
|
|
126
|
+
attributes?: Attribute[];
|
|
127
|
+
buyerIdentity?: CartBuyerIdentity;
|
|
128
|
+
id: string;
|
|
129
129
|
};
|
|
130
130
|
|
|
131
131
|
export interface Money {
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
amount: number;
|
|
133
|
+
currencyCode: string;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
export interface Image {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
url: string;
|
|
138
|
+
width: number;
|
|
139
|
+
height: number;
|
|
140
|
+
altText: string;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
export interface Media {
|
|
144
|
-
|
|
144
|
+
nodes: Media[];
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
export interface Media {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
alt: string;
|
|
149
|
+
previewImage: Image;
|
|
150
|
+
mediaContentType: string;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
export interface Option {
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
name: string;
|
|
155
|
+
values: string[];
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
export interface PriceRange {
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
minVariantPrice: Price;
|
|
160
|
+
maxVariantPrice: Price;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
export interface Price {
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
amount: string;
|
|
165
|
+
currencyCode: string;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
export interface SEO {
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
title: string;
|
|
170
|
+
description: string;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
export interface SelectedOption {
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
name: string;
|
|
175
|
+
value: string;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
export interface UnitPriceMeasurement {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
190
|
-
|
|
189
|
+
namespace: string;
|
|
190
|
+
key: string;
|
|
191
191
|
}
|
package/shopify/utils/user.ts
CHANGED
|
@@ -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
|
-
|
|
8
|
+
const cookies = getCookies(headers);
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
return cookies[CUSTOMER_COOKIE];
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export const setUserCookie = (headers: Headers, accessToken: string) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
};
|
package/shopify/utils/utils.ts
CHANGED
|
@@ -1,164 +1,159 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
41
|
-
|
|
37
|
+
string,
|
|
38
|
+
{ sortKey: SearchSortKeysShopify; reverse: boolean }
|
|
42
39
|
> = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
string,
|
|
56
|
+
{
|
|
57
|
+
sortKey: ProductCollectionSortKeys | SearchSortKeysShopify;
|
|
58
|
+
reverse: boolean;
|
|
59
|
+
}
|
|
63
60
|
> = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
};
|