@faststore/api 1.12.47 → 1.12.48

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.
@@ -1 +1 @@
1
- export declare const fetchAPI: (info: RequestInfo, init?: RequestInit | undefined, getHeaders?: ((headers: Headers) => void) | undefined) => Promise<any>;
1
+ export declare const fetchAPI: (info: RequestInfo, init?: RequestInit | undefined) => Promise<any>;
@@ -28,7 +28,6 @@ export interface Context {
28
28
  locale: string;
29
29
  flags: FeatureFlags;
30
30
  searchArgs?: Omit<SearchArgs, 'type'>;
31
- cookies?: string | null;
32
31
  };
33
32
  headers: Record<string, string>;
34
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "1.12.47",
3
+ "version": "1.12.48",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@envelop/core": "^2.6.0",
39
- "@faststore/shared": "^1.12.43",
39
+ "@faststore/shared": "^1.12.48",
40
40
  "@graphql-codegen/cli": "2.2.0",
41
41
  "@graphql-codegen/typescript": "2.2.2",
42
42
  "concurrently": "^6.2.1",
@@ -53,5 +53,5 @@
53
53
  "@envelop/core": "^1 || ^2",
54
54
  "graphql": "^15.6.0"
55
55
  },
56
- "gitHead": "fb17d8b4870de83e2d738c99e2f46ff51209407d"
56
+ "gitHead": "9a273837d3afc05e1ef2c03d8aaee7eb90df1299"
57
57
  }
@@ -19,7 +19,6 @@ import type { SalesChannel } from './types/SalesChannel'
19
19
  import { MasterDataResponse } from './types/Newsletter'
20
20
  import type { Address, AddressInput } from './types/Address'
21
21
  import { ShippingDataBody } from './types/ShippingData'
22
- import getCookieByName from '../../../../utils/get-cookie-by-name'
23
22
 
24
23
  type ValueOf<T> = T extends Record<string, infer K> ? K : never
25
24
 
@@ -30,18 +29,6 @@ const BASE_INIT = {
30
29
  },
31
30
  }
32
31
 
33
- const setCheckoutOrderFormOwnershipCookie = (
34
- headers: Headers,
35
- ctx: Context
36
- ) => {
37
- if (headers) {
38
- ctx.storage.cookies = `CheckoutOrderFormOwnership=${getCookieByName(
39
- 'CheckoutOrderFormOwnership',
40
- headers.get('set-cookie') ?? ''
41
- )}`
42
- }
43
- }
44
-
45
32
  export const VtexCommerce = (
46
33
  { account, environment }: Options,
47
34
  ctx: Context
@@ -121,8 +108,7 @@ export const VtexCommerce = (
121
108
  {
122
109
  ...BASE_INIT,
123
110
  body: JSON.stringify(body),
124
- },
125
- (headers) => setCheckoutOrderFormOwnershipCookie(headers, ctx)
111
+ }
126
112
  )
127
113
  },
128
114
  orderForm: ({
@@ -142,8 +128,7 @@ export const VtexCommerce = (
142
128
 
143
129
  return fetchAPI(
144
130
  `${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`,
145
- BASE_INIT,
146
- (headers) => setCheckoutOrderFormOwnershipCookie(headers, ctx)
131
+ BASE_INIT
147
132
  )
148
133
  },
149
134
  updateOrderFormItems: ({
@@ -173,8 +158,7 @@ export const VtexCommerce = (
173
158
  noSplitItem: !shouldSplitItem,
174
159
  }),
175
160
  method: 'PATCH',
176
- },
177
- (headers) => setCheckoutOrderFormOwnershipCookie(headers, ctx)
161
+ }
178
162
  )
179
163
  },
180
164
  setCustomData: ({
@@ -194,8 +178,7 @@ export const VtexCommerce = (
194
178
  ...BASE_INIT,
195
179
  body: JSON.stringify({ value }),
196
180
  method: 'PUT',
197
- },
198
- (headers) => setCheckoutOrderFormOwnershipCookie(headers, ctx)
181
+ }
199
182
  )
200
183
  },
201
184
  region: async ({
@@ -225,18 +208,14 @@ export const VtexCommerce = (
225
208
  'items',
226
209
  'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol'
227
210
  )
228
- return fetchAPI(
229
- `${base}/api/sessions?${params.toString()}`,
230
- {
231
- method: 'POST',
232
- headers: {
233
- 'content-type': 'application/json',
234
- cookie: ctx.headers.cookie,
235
- },
236
- body: '{}',
211
+ return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
212
+ method: 'POST',
213
+ headers: {
214
+ 'content-type': 'application/json',
215
+ cookie: ctx.headers.cookie,
237
216
  },
238
- (headers) => setCheckoutOrderFormOwnershipCookie(headers, ctx)
239
- )
217
+ body: '{}',
218
+ })
240
219
  },
241
220
  subscribeToNewsletter: (data: {
242
221
  name: string
@@ -3,11 +3,7 @@ import packageJson from '../../../../package.json'
3
3
 
4
4
  const USER_AGENT = `${packageJson.name}@${packageJson.version}`
5
5
 
6
- export const fetchAPI = async (
7
- info: RequestInfo,
8
- init?: RequestInit,
9
- getHeaders?: (headers: Headers) => void
10
- ) => {
6
+ export const fetchAPI = async (info: RequestInfo, init?: RequestInit) => {
11
7
  const response = await fetch(info, {
12
8
  ...init,
13
9
  headers: {
@@ -17,10 +13,6 @@ export const fetchAPI = async (
17
13
  })
18
14
 
19
15
  if (response.ok) {
20
- if (getHeaders) {
21
- getHeaders(response.headers)
22
- }
23
-
24
16
  return response.status !== 204 ? response.json() : undefined
25
17
  }
26
18
 
@@ -56,7 +56,6 @@ export interface Context {
56
56
  locale: string
57
57
  flags: FeatureFlags
58
58
  searchArgs?: Omit<SearchArgs, 'type'>
59
- cookies?: string | null
60
59
  }
61
60
  headers: Record<string, string>
62
61
  }
@@ -3,7 +3,7 @@ import type { Resolver } from '..'
3
3
  import type { SearchArgs } from '../clients/search'
4
4
  import type { Facet } from '../clients/search/types/FacetSearchResult'
5
5
  import { ProductSearchResult } from '../clients/search/types/ProductSearchResult'
6
- import { inStock } from '../utils/productStock'
6
+ import { pickBestSku } from '../utils/sku'
7
7
 
8
8
  type Root = {
9
9
  searchArgs: Omit<SearchArgs, 'type'>
@@ -41,7 +41,9 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
41
41
 
42
42
  const skus = productSearchResult.products
43
43
  .map((product) => {
44
- const [maybeSku] = product.items
44
+ // What determines the presentation of the SKU is the price order
45
+ // https://help.vtex.com/pt/tutorial/ordenando-imagens-na-vitrine-e-na-pagina-de-produto--tutorials_278
46
+ const maybeSku = pickBestSku(product.items)
45
47
 
46
48
  return maybeSku && enhanceSku(maybeSku, product)
47
49
  })
@@ -59,9 +61,9 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
59
61
 
60
62
  const skus = productSearchResult.products
61
63
  .map((product) => {
62
- const maybeSku = product.items.find((item) =>
63
- item.sellers.some((item) => inStock(item.commertialOffer))
64
- )
64
+ // What determines the presentation of the SKU is the price order
65
+ // https://help.vtex.com/pt/tutorial/ordenando-imagens-na-vitrine-e-na-pagina-de-produto--tutorials_278
66
+ const maybeSku = pickBestSku(product.items)
65
67
 
66
68
  return maybeSku && enhanceSku(maybeSku, product)
67
69
  })
@@ -19,7 +19,7 @@ export const pickBestSku = (skus: Item[]) => {
19
19
  bestOfferFirst(o1, o2)
20
20
  )
21
21
 
22
- return best.sku
22
+ return best ? best.sku : skus[0]
23
23
  }
24
24
 
25
25
  export const isValidSkuId = (skuId: string) =>
@@ -1 +0,0 @@
1
- export default function getCookieByName(cookiename: string, source: string): string;
@@ -1,6 +0,0 @@
1
- export default function getCookieByName(cookiename: string, source: string) {
2
- var cookiestring = RegExp(cookiename + '=[^;]+').exec(source)
3
- return decodeURIComponent(
4
- !!cookiestring ? cookiestring.toString().replace(/^[^=]+./, '') : ''
5
- )
6
- }