@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/vtex/types.ts
CHANGED
|
@@ -5,244 +5,244 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
export interface OrderFormItem {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
8
|
+
id: string;
|
|
9
|
+
productId: string;
|
|
10
|
+
productRefId?: string;
|
|
11
|
+
refId?: string;
|
|
12
|
+
ean?: string | null;
|
|
13
|
+
name: string;
|
|
14
|
+
skuName: string;
|
|
15
|
+
imageUrl: string;
|
|
16
|
+
detailUrl: string;
|
|
17
|
+
price: number;
|
|
18
|
+
listPrice: number;
|
|
19
|
+
manualPrice?: number | null;
|
|
20
|
+
quantity: number;
|
|
21
|
+
sellingPrice: number;
|
|
22
|
+
rewardValue?: number;
|
|
23
|
+
isGift?: boolean;
|
|
24
|
+
tax?: number;
|
|
25
|
+
seller: string;
|
|
26
|
+
sellerChain?: string[];
|
|
27
|
+
uniqueId: string;
|
|
28
|
+
parentItemIndex?: number | null;
|
|
29
|
+
parentAssemblyBinding?: string | null;
|
|
30
|
+
availability?: string;
|
|
31
|
+
measurementUnit?: string;
|
|
32
|
+
unitMultiplier?: number;
|
|
33
|
+
productCategoryIds?: string;
|
|
34
|
+
productCategories?: Record<string, string>;
|
|
35
|
+
additionalInfo?: {
|
|
36
|
+
brandName?: string;
|
|
37
|
+
brandId?: string;
|
|
38
|
+
dimension?: Record<string, string> | null;
|
|
39
|
+
offeringInfo?: unknown | null;
|
|
40
|
+
offeringType?: unknown | null;
|
|
41
|
+
offeringTypeId?: unknown | null;
|
|
42
|
+
};
|
|
43
|
+
attachments?: unknown[];
|
|
44
|
+
attachmentOfferings?: Array<{
|
|
45
|
+
name: string;
|
|
46
|
+
required: boolean;
|
|
47
|
+
schema: Record<string, unknown>;
|
|
48
|
+
}>;
|
|
49
|
+
offerings?: Array<{
|
|
50
|
+
type: string;
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
price: number;
|
|
54
|
+
}>;
|
|
55
|
+
priceTags?: Array<{
|
|
56
|
+
name: string;
|
|
57
|
+
value: number;
|
|
58
|
+
rawValue: number;
|
|
59
|
+
isPercentual: boolean;
|
|
60
|
+
identifier: string | null;
|
|
61
|
+
}>;
|
|
62
|
+
components?: unknown[];
|
|
63
|
+
bundleItems?: unknown[];
|
|
64
|
+
priceDefinition?: {
|
|
65
|
+
calculatedSellingPrice: number;
|
|
66
|
+
total: number;
|
|
67
|
+
sellingPrices: Array<{
|
|
68
|
+
value: number;
|
|
69
|
+
quantity: number;
|
|
70
|
+
}>;
|
|
71
|
+
};
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export interface Totalizer {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
id: string;
|
|
76
|
+
name: string;
|
|
77
|
+
value: number;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export interface Message {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
code: string;
|
|
82
|
+
text: string;
|
|
83
|
+
status: string;
|
|
84
|
+
fields?: Record<string, string>;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
export interface MarketingData {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
utmSource?: string;
|
|
89
|
+
utmMedium?: string;
|
|
90
|
+
utmCampaign?: string;
|
|
91
|
+
utmiPage?: string;
|
|
92
|
+
utmiPart?: string;
|
|
93
|
+
utmiCampaign?: string;
|
|
94
|
+
coupon?: string;
|
|
95
|
+
marketingTags?: string[];
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
export interface ClientProfileData {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
email: string;
|
|
100
|
+
firstName?: string | null;
|
|
101
|
+
lastName?: string | null;
|
|
102
|
+
document?: string | null;
|
|
103
|
+
phone?: string | null;
|
|
104
|
+
corporateName?: string | null;
|
|
105
|
+
isCorporate?: boolean;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
export interface StorePreferencesData {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
109
|
+
countryCode: string;
|
|
110
|
+
saveUserData?: boolean;
|
|
111
|
+
timeZone?: string;
|
|
112
|
+
currencyCode: string;
|
|
113
|
+
currencyLocale?: number;
|
|
114
|
+
currencySymbol: string;
|
|
115
|
+
currencyFormatInfo?: {
|
|
116
|
+
currencyDecimalDigits: number;
|
|
117
|
+
currencyDecimalSeparator: string;
|
|
118
|
+
currencyGroupSeparator: string;
|
|
119
|
+
currencyGroupSize: number;
|
|
120
|
+
startsWithCurrencySymbol: boolean;
|
|
121
|
+
};
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
export interface ClientPreferencesData {
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
locale: string;
|
|
126
|
+
optinNewsLetter?: boolean;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
export interface ShippingData {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
130
|
+
address?: {
|
|
131
|
+
postalCode?: string;
|
|
132
|
+
city?: string;
|
|
133
|
+
state?: string;
|
|
134
|
+
country?: string;
|
|
135
|
+
street?: string;
|
|
136
|
+
number?: string;
|
|
137
|
+
neighborhood?: string;
|
|
138
|
+
complement?: string;
|
|
139
|
+
reference?: string;
|
|
140
|
+
} | null;
|
|
141
|
+
selectedAddresses?: Array<{
|
|
142
|
+
postalCode?: string;
|
|
143
|
+
city?: string;
|
|
144
|
+
state?: string;
|
|
145
|
+
country?: string;
|
|
146
|
+
}>;
|
|
147
|
+
logisticsInfo?: Array<{
|
|
148
|
+
itemIndex: number;
|
|
149
|
+
selectedSla?: string;
|
|
150
|
+
selectedDeliveryChannel?: string;
|
|
151
|
+
slas?: Sla[];
|
|
152
|
+
}>;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
export interface PaymentData {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
156
|
+
updateStatus?: string;
|
|
157
|
+
installmentOptions?: unknown[];
|
|
158
|
+
paymentSystems?: unknown[];
|
|
159
|
+
payments?: unknown[];
|
|
160
|
+
giftCards?: unknown[];
|
|
161
|
+
availableAccounts?: unknown[];
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
export interface OrderForm {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
165
|
+
orderFormId: string;
|
|
166
|
+
salesChannel: string;
|
|
167
|
+
loggedIn: boolean;
|
|
168
|
+
isCheckedIn: boolean;
|
|
169
|
+
storeId?: unknown | null;
|
|
170
|
+
checkedInPickupPointId?: unknown | null;
|
|
171
|
+
allowManualPrice: boolean;
|
|
172
|
+
canEditData: boolean;
|
|
173
|
+
userProfileId?: unknown | null;
|
|
174
|
+
userType?: unknown | null;
|
|
175
|
+
ignoreProfileData: boolean;
|
|
176
|
+
value: number;
|
|
177
|
+
messages: Message[];
|
|
178
|
+
items: OrderFormItem[];
|
|
179
|
+
selectableGifts?: unknown[];
|
|
180
|
+
totalizers: Totalizer[];
|
|
181
|
+
shippingData: ShippingData | null;
|
|
182
|
+
clientProfileData: ClientProfileData | null;
|
|
183
|
+
paymentData: PaymentData | null;
|
|
184
|
+
marketingData: MarketingData | null;
|
|
185
|
+
sellers?: Array<{ id: string; name: string; logo?: string }>;
|
|
186
|
+
clientPreferencesData?: ClientPreferencesData | null;
|
|
187
|
+
commercialConditionData?: unknown | null;
|
|
188
|
+
storePreferencesData?: StorePreferencesData | null;
|
|
189
|
+
giftRegistryData?: unknown | null;
|
|
190
|
+
openTextField?: unknown | null;
|
|
191
|
+
invoiceData?: unknown | null;
|
|
192
|
+
customData?: unknown | null;
|
|
193
|
+
itemMetadata?: unknown | null;
|
|
194
|
+
hooksData?: unknown | null;
|
|
195
|
+
ratesAndBenefitsData?: {
|
|
196
|
+
rateAndBenefitsIdentifiers?: unknown[];
|
|
197
|
+
teaser?: unknown[];
|
|
198
|
+
} | null;
|
|
199
|
+
subscriptionData?: unknown | null;
|
|
200
|
+
merchantContextData?: unknown | null;
|
|
201
|
+
itemsOrdination?: unknown | null;
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
export interface SimulationOrderForm {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
205
|
+
items: Array<{
|
|
206
|
+
id: string;
|
|
207
|
+
quantity: number;
|
|
208
|
+
seller: string;
|
|
209
|
+
price?: number;
|
|
210
|
+
listPrice?: number;
|
|
211
|
+
offerings?: any[];
|
|
212
|
+
priceTags?: any[];
|
|
213
|
+
availability?: string;
|
|
214
|
+
}>;
|
|
215
|
+
logisticsInfo?: Array<{
|
|
216
|
+
itemIndex: number;
|
|
217
|
+
slas: Sla[];
|
|
218
|
+
selectedSla?: string;
|
|
219
|
+
selectedDeliveryChannel?: string;
|
|
220
|
+
}>;
|
|
221
|
+
paymentData?: {
|
|
222
|
+
installmentOptions?: any[];
|
|
223
|
+
};
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
export interface Sla {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
227
|
+
id: string;
|
|
228
|
+
name: string;
|
|
229
|
+
price: number;
|
|
230
|
+
shippingEstimate: string;
|
|
231
|
+
deliveryChannel?: string;
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
export interface SKU {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
id: string;
|
|
236
|
+
seller: string;
|
|
237
|
+
quantity: number;
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
export interface VtexProduct {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
241
|
+
productId: string;
|
|
242
|
+
productName: string;
|
|
243
|
+
brand: string;
|
|
244
|
+
categoryId: string;
|
|
245
|
+
categories: string[];
|
|
246
|
+
items: any[];
|
|
247
|
+
[key: string]: any;
|
|
248
248
|
}
|
package/vtex/utils/batch.ts
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
export const batch = <T>(
|
|
2
|
-
|
|
3
|
-
size: number,
|
|
4
|
-
): T[][] => {
|
|
5
|
-
const batches: T[][] = [];
|
|
1
|
+
export const batch = <T>(iterable: IterableIterator<T> | T[], size: number): T[][] => {
|
|
2
|
+
const batches: T[][] = [];
|
|
6
3
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
let current = 0;
|
|
5
|
+
for (const item of iterable) {
|
|
6
|
+
if (batches[current]?.length === size) {
|
|
7
|
+
current++;
|
|
8
|
+
}
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
if (!batches[current]) {
|
|
11
|
+
batches[current] = [];
|
|
12
|
+
}
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
batches[current].push(item);
|
|
15
|
+
}
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
return batches;
|
|
21
18
|
};
|
package/vtex/utils/cookies.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
interface Cookie {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
domain?: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
expires?: Date;
|
|
7
|
+
maxAge?: number;
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
httpOnly?: boolean;
|
|
10
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
function parseSingleSetCookie(raw: string): Cookie | null {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
14
|
+
const parts = raw.split(";").map((p) => p.trim());
|
|
15
|
+
const [nameValue, ...attrs] = parts;
|
|
16
|
+
const eqIdx = nameValue.indexOf("=");
|
|
17
|
+
if (eqIdx < 0) return null;
|
|
18
|
+
const cookie: Cookie = {
|
|
19
|
+
name: nameValue.slice(0, eqIdx),
|
|
20
|
+
value: nameValue.slice(eqIdx + 1),
|
|
21
|
+
};
|
|
22
|
+
for (const attr of attrs) {
|
|
23
|
+
const [k, v] = attr.split("=").map((s) => s.trim());
|
|
24
|
+
const lower = k.toLowerCase();
|
|
25
|
+
if (lower === "domain") cookie.domain = v;
|
|
26
|
+
else if (lower === "path") cookie.path = v;
|
|
27
|
+
else if (lower === "secure") cookie.secure = true;
|
|
28
|
+
else if (lower === "httponly") cookie.httpOnly = true;
|
|
29
|
+
else if (lower === "samesite") cookie.sameSite = v as Cookie["sameSite"];
|
|
30
|
+
}
|
|
31
|
+
return cookie;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -40,17 +40,17 @@ function parseSingleSetCookie(raw: string): Cookie | null {
|
|
|
40
40
|
* cookie strings that contain commas in Expires dates.
|
|
41
41
|
*/
|
|
42
42
|
function getSetCookies(headers: Headers): Cookie[] {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
const rawCookies: string[] =
|
|
44
|
+
typeof headers.getSetCookie === "function"
|
|
45
|
+
? headers.getSetCookie()
|
|
46
|
+
: getRawSetCookiesFallback(headers);
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
const cookies: Cookie[] = [];
|
|
49
|
+
for (const raw of rawCookies) {
|
|
50
|
+
const cookie = parseSingleSetCookie(raw);
|
|
51
|
+
if (cookie) cookies.push(cookie);
|
|
52
|
+
}
|
|
53
|
+
return cookies;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/**
|
|
@@ -59,58 +59,54 @@ function getSetCookies(headers: Headers): Cookie[] {
|
|
|
59
59
|
* with Expires containing commas, but better than the old approach.
|
|
60
60
|
*/
|
|
61
61
|
function getRawSetCookiesFallback(headers: Headers): string[] {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
62
|
+
const joined = headers.get("set-cookie");
|
|
63
|
+
if (!joined) return [];
|
|
64
|
+
const results: string[] = [];
|
|
65
|
+
let current = "";
|
|
66
|
+
for (const segment of joined.split(",")) {
|
|
67
|
+
const trimmed = segment.trimStart();
|
|
68
|
+
const looksLikeNewCookie = /^[^=;]+=[^;]/.test(trimmed) && current.length > 0;
|
|
69
|
+
if (looksLikeNewCookie) {
|
|
70
|
+
results.push(current.trim());
|
|
71
|
+
current = trimmed;
|
|
72
|
+
} else {
|
|
73
|
+
current += (current ? "," : "") + segment;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (current.trim()) results.push(current.trim());
|
|
77
|
+
return results;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
function setCookie(headers: Headers, cookie: Cookie): void {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
81
|
+
let str = `${cookie.name}=${cookie.value}`;
|
|
82
|
+
if (cookie.domain) str += `; Domain=${cookie.domain}`;
|
|
83
|
+
if (cookie.path) str += `; Path=${cookie.path}`;
|
|
84
|
+
if (cookie.secure) str += "; Secure";
|
|
85
|
+
if (cookie.httpOnly) str += "; HttpOnly";
|
|
86
|
+
if (cookie.sameSite) str += `; SameSite=${cookie.sameSite}`;
|
|
87
|
+
if (cookie.maxAge != null) str += `; Max-Age=${cookie.maxAge}`;
|
|
88
|
+
if (cookie.expires) str += `; Expires=${cookie.expires.toUTCString()}`;
|
|
89
|
+
headers.append("Set-Cookie", str);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
export const stringify = (cookies: Record<string, string>) =>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
Object.entries(cookies)
|
|
94
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
95
|
+
.join("; ");
|
|
96
96
|
|
|
97
|
-
export const proxySetCookie = (
|
|
98
|
-
|
|
99
|
-
to: Headers,
|
|
100
|
-
toDomain?: URL | string,
|
|
101
|
-
) => {
|
|
102
|
-
const newDomain = toDomain && new URL(toDomain);
|
|
97
|
+
export const proxySetCookie = (from: Headers, to: Headers, toDomain?: URL | string) => {
|
|
98
|
+
const newDomain = toDomain && new URL(toDomain);
|
|
103
99
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
100
|
+
for (const cookie of getSetCookies(from)) {
|
|
101
|
+
const newCookie = newDomain
|
|
102
|
+
? {
|
|
103
|
+
...cookie,
|
|
104
|
+
domain: newDomain.hostname,
|
|
105
|
+
}
|
|
106
|
+
: cookie;
|
|
111
107
|
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
setCookie(to, newCookie);
|
|
109
|
+
}
|
|
114
110
|
};
|
|
115
111
|
|
|
116
112
|
export const CHECKOUT_DATA_ACCESS_COOKIE = "CheckoutDataAccess";
|