@faststore/api 1.12.45 → 1.12.46

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.
@@ -62,7 +62,6 @@ export declare const VtexCommerce: ({ account, environment }: Options, ctx: Cont
62
62
  address: ({ postalCode, country, }: AddressInput) => Promise<Address>;
63
63
  };
64
64
  session: (search: string) => Promise<Session>;
65
- getSessionOrder: () => Promise<Session>;
66
65
  subscribeToNewsletter: (data: {
67
66
  name: string;
68
67
  email: string;
@@ -55,7 +55,6 @@ export declare const getClients: (options: Options, ctx: Context) => {
55
55
  address: ({ postalCode, country, }: import("./commerce/types/Address").AddressInput) => Promise<import("./commerce/types/Address").Address>;
56
56
  };
57
57
  session: (search: string) => Promise<import("./commerce/types/Session").Session>;
58
- getSessionOrder: () => Promise<import("./commerce/types/Session").Session>;
59
58
  subscribeToNewsletter: (data: {
60
59
  name: string;
61
60
  email: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "1.12.45",
3
+ "version": "1.12.46",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -53,5 +53,5 @@
53
53
  "@envelop/core": "^1 || ^2",
54
54
  "graphql": "^15.6.0"
55
55
  },
56
- "gitHead": "121360b0bdbc8eac7c71d660e3e6b3604bda7703"
56
+ "gitHead": "0a4c5ea1e23c7d867cdc3212369b95f5406f0425"
57
57
  }
@@ -15,7 +15,6 @@ import type {
15
15
  } from './types/Simulation'
16
16
  import type { Session } from './types/Session'
17
17
  import type { Channel } from '../../utils/channel'
18
- import { getCookie } from '../../utils/getCookies'
19
18
  import type { SalesChannel } from './types/SalesChannel'
20
19
  import { MasterDataResponse } from './types/Newsletter'
21
20
  import type { Address, AddressInput } from './types/Address'
@@ -100,9 +99,9 @@ export const VtexCommerce = (
100
99
  if (body.selectedAddresses) {
101
100
  body.selectedAddresses.forEach((address) => {
102
101
  if (address.geoCoordinates === null) {
103
- address.geoCoordinates = [];
102
+ address.geoCoordinates = []
104
103
  }
105
- });
104
+ })
106
105
  }
107
106
  return fetchAPI(
108
107
  `${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`,
@@ -188,7 +187,8 @@ export const VtexCommerce = (
188
187
  salesChannel,
189
188
  }: RegionInput): Promise<Region> => {
190
189
  return fetchAPI(
191
- `${base}/api/checkout/pub/regions/?postalCode=${postalCode}&country=${country}&sc=${salesChannel ?? ''
190
+ `${base}/api/checkout/pub/regions/?postalCode=${postalCode}&country=${country}&sc=${
191
+ salesChannel ?? ''
192
192
  }`
193
193
  )
194
194
  },
@@ -208,34 +208,13 @@ export const VtexCommerce = (
208
208
  'items',
209
209
  'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol'
210
210
  )
211
- if (getCookie('vtex_session', ctx.headers.cookie)) {
212
- // cookie set
213
- return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
214
- method: 'GET',
215
- headers: {
216
- 'content-type': 'application/json',
217
- cookie: ctx.headers.cookie,
218
- },
219
- })
220
- } else {
221
- // cookie unset -> create session
222
- return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
223
- method: 'POST',
224
- headers: {
225
- 'content-type': 'application/json',
226
- cookie: ctx.headers.cookie,
227
- },
228
- body: '{}',
229
- })
230
- }
231
- },
232
- getSessionOrder: (): Promise<Session> => {
233
- return fetchAPI(`${base}/api/sessions?items=checkout.orderFormId`, {
234
- method: 'GET',
211
+ return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
212
+ method: 'POST',
235
213
  headers: {
236
214
  'content-type': 'application/json',
237
215
  cookie: ctx.headers.cookie,
238
216
  },
217
+ body: '{}',
239
218
  })
240
219
  },
241
220
  subscribeToNewsletter: (data: {
@@ -1,25 +1,26 @@
1
1
  import deepEquals from 'fast-deep-equal'
2
2
 
3
3
  import { mutateChannelContext, mutateLocaleContext } from '../utils/contex'
4
- import { getCookie } from '../utils/getCookies'
5
4
  import { md5 } from '../utils/md5'
6
5
  import {
7
6
  attachmentToPropertyValue,
8
7
  getPropertyId,
9
- VALUE_REFERENCES
8
+ VALUE_REFERENCES,
10
9
  } from '../utils/propertyValue'
11
10
 
12
11
  import type { Context } from '..'
13
12
  import type {
14
13
  IStoreOffer,
15
14
  IStoreOrder,
16
- IStorePropertyValue, IStoreSession, Maybe,
17
- MutationValidateCartArgs
15
+ IStorePropertyValue,
16
+ IStoreSession,
17
+ Maybe,
18
+ MutationValidateCartArgs,
18
19
  } from '../../../__generated__/schema'
19
20
  import type {
20
21
  OrderForm,
21
22
  OrderFormInputItem,
22
- OrderFormItem
23
+ OrderFormItem,
23
24
  } from '../clients/commerce/types/OrderForm'
24
25
 
25
26
  type Indexed<T> = T & { index?: number }
@@ -199,20 +200,6 @@ const isOrderFormStale = (form: OrderForm) => {
199
200
  return newEtag !== oldEtag
200
201
  }
201
202
 
202
- async function getOrderNumberFromSession(
203
- headers: Record<string, string> = {},
204
- commerce: Context['clients']['commerce']
205
- ) {
206
-
207
- const cookieSession = getCookie('vtex_session', headers.cookie)
208
-
209
- if (cookieSession) {
210
- const { namespaces } = await commerce.getSessionOrder()
211
- return namespaces.checkout?.orderFormId?.value
212
- }
213
- return ;
214
- }
215
-
216
203
  // Returns the regionalized orderForm
217
204
  const getOrderForm = async (
218
205
  id: string,
@@ -266,11 +253,10 @@ export const validateCart = async (
266
253
  { cart: { order }, session }: MutationValidateCartArgs,
267
254
  ctx: Context
268
255
  ) => {
269
- const { orderNumber: orderNumberFromCart, acceptedOffer, shouldSplitItem } = order
256
+ const { orderNumber, acceptedOffer, shouldSplitItem } = order
270
257
  const {
271
258
  clients: { commerce },
272
259
  loaders: { skuLoader },
273
- headers,
274
260
  } = ctx
275
261
 
276
262
  const channel = session?.channel
@@ -284,13 +270,6 @@ export const validateCart = async (
284
270
  mutateLocaleContext(ctx, locale)
285
271
  }
286
272
 
287
- const orderNumberFromSession = await getOrderNumberFromSession(
288
- headers,
289
- commerce
290
- )
291
-
292
- const orderNumber = orderNumberFromSession ?? orderNumberFromCart ?? ''
293
-
294
273
  // Step1: Get OrderForm from VTEX Commerce
295
274
  const orderForm = await getOrderForm(orderNumber, session, ctx)
296
275
 
@@ -298,11 +277,11 @@ export const validateCart = async (
298
277
  // If so, this means the user interacted with this cart elsewhere and expects
299
278
  // to see this new cart state instead of what's stored on the user's browser.
300
279
  const isStale = isOrderFormStale(orderForm)
301
-
280
+
302
281
  if (isStale && orderNumber) {
303
282
  const newOrderForm = await setOrderFormEtag(orderForm, commerce).then(
304
283
  joinItems
305
- )
284
+ )
306
285
  return orderFormToCart(newOrderForm, skuLoader)
307
286
  }
308
287
 
@@ -366,9 +345,7 @@ export const validateCart = async (
366
345
  shouldSplitItem,
367
346
  })
368
347
  // update orderForm etag so we know last time we touched this orderForm
369
- .then((form) =>
370
- setOrderFormEtag(form, commerce)
371
- )
348
+ .then((form) => setOrderFormEtag(form, commerce))
372
349
  .then(joinItems)
373
350
 
374
351
  // Step5: If no changes detected before/after updating orderForm, the order is validated
@@ -1 +0,0 @@
1
- export declare const getCookie: (name: string, cookie: string) => string;
@@ -1,8 +0,0 @@
1
- export const getCookie = (name: string, cookie: string): string => {
2
- const value = `; ${cookie}`
3
- const parts = value.split(`; ${name}=`)
4
- if (parts.length === 2) {
5
- return parts?.pop()?.split(';').shift() ?? ''
6
- }
7
- return ''
8
- }