@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
package/vtex/types.ts CHANGED
@@ -5,244 +5,244 @@
5
5
  */
6
6
 
7
7
  export interface OrderFormItem {
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
- };
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
- id: string;
76
- name: string;
77
- value: number;
75
+ id: string;
76
+ name: string;
77
+ value: number;
78
78
  }
79
79
 
80
80
  export interface Message {
81
- code: string;
82
- text: string;
83
- status: string;
84
- fields?: Record<string, string>;
81
+ code: string;
82
+ text: string;
83
+ status: string;
84
+ fields?: Record<string, string>;
85
85
  }
86
86
 
87
87
  export interface MarketingData {
88
- utmSource?: string;
89
- utmMedium?: string;
90
- utmCampaign?: string;
91
- utmiPage?: string;
92
- utmiPart?: string;
93
- utmiCampaign?: string;
94
- coupon?: string;
95
- marketingTags?: string[];
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
- 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;
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
- 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
- };
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
- locale: string;
126
- optinNewsLetter?: boolean;
125
+ locale: string;
126
+ optinNewsLetter?: boolean;
127
127
  }
128
128
 
129
129
  export interface ShippingData {
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
- }>;
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
- updateStatus?: string;
157
- installmentOptions?: unknown[];
158
- paymentSystems?: unknown[];
159
- payments?: unknown[];
160
- giftCards?: unknown[];
161
- availableAccounts?: unknown[];
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
- 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;
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
- 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
- };
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
- id: string;
228
- name: string;
229
- price: number;
230
- shippingEstimate: string;
231
- deliveryChannel?: string;
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
- id: string;
236
- seller: string;
237
- quantity: number;
235
+ id: string;
236
+ seller: string;
237
+ quantity: number;
238
238
  }
239
239
 
240
240
  export interface VtexProduct {
241
- productId: string;
242
- productName: string;
243
- brand: string;
244
- categoryId: string;
245
- categories: string[];
246
- items: any[];
247
- [key: string]: any;
241
+ productId: string;
242
+ productName: string;
243
+ brand: string;
244
+ categoryId: string;
245
+ categories: string[];
246
+ items: any[];
247
+ [key: string]: any;
248
248
  }
@@ -1,21 +1,18 @@
1
- export const batch = <T>(
2
- iterable: IterableIterator<T> | T[],
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
- let current = 0;
8
- for (const item of iterable) {
9
- if (batches[current]?.length === size) {
10
- current++;
11
- }
4
+ let current = 0;
5
+ for (const item of iterable) {
6
+ if (batches[current]?.length === size) {
7
+ current++;
8
+ }
12
9
 
13
- if (!batches[current]) {
14
- batches[current] = [];
15
- }
10
+ if (!batches[current]) {
11
+ batches[current] = [];
12
+ }
16
13
 
17
- batches[current].push(item);
18
- }
14
+ batches[current].push(item);
15
+ }
19
16
 
20
- return batches;
17
+ return batches;
21
18
  };
@@ -1,34 +1,34 @@
1
1
  interface Cookie {
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";
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
- 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;
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
- const rawCookies: string[] =
44
- typeof headers.getSetCookie === "function"
45
- ? headers.getSetCookie()
46
- : getRawSetCookiesFallback(headers);
43
+ const rawCookies: string[] =
44
+ typeof headers.getSetCookie === "function"
45
+ ? headers.getSetCookie()
46
+ : getRawSetCookiesFallback(headers);
47
47
 
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;
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
- 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;
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
- 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);
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
- Object.entries(cookies)
94
- .map(([key, value]) => `${key}=${value}`)
95
- .join("; ");
93
+ Object.entries(cookies)
94
+ .map(([key, value]) => `${key}=${value}`)
95
+ .join("; ");
96
96
 
97
- export const proxySetCookie = (
98
- from: Headers,
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
- for (const cookie of getSetCookies(from)) {
105
- const newCookie = newDomain
106
- ? {
107
- ...cookie,
108
- domain: newDomain.hostname,
109
- }
110
- : cookie;
100
+ for (const cookie of getSetCookies(from)) {
101
+ const newCookie = newDomain
102
+ ? {
103
+ ...cookie,
104
+ domain: newDomain.hostname,
105
+ }
106
+ : cookie;
111
107
 
112
- setCookie(to, newCookie);
113
- }
108
+ setCookie(to, newCookie);
109
+ }
114
110
  };
115
111
 
116
112
  export const CHECKOUT_DATA_ACCESS_COOKIE = "CheckoutDataAccess";