@faststore/api 2.1.83 → 2.1.90

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.
@@ -64,7 +64,6 @@ export declare const VtexCommerce: ({ account, environment, incrementAddress }:
64
64
  address: ({ postalCode, country, }: AddressInput) => Promise<Address>;
65
65
  };
66
66
  session: (search: string) => Promise<Session>;
67
- getSessionOrder: () => Promise<Session>;
68
67
  subscribeToNewsletter: (data: {
69
68
  name: string;
70
69
  email: string;
@@ -57,7 +57,6 @@ export declare const getClients: (options: Options, ctx: Context) => {
57
57
  address: ({ postalCode, country, }: import("./commerce/types/Address").AddressInput) => Promise<import("./commerce/types/Address").Address>;
58
58
  };
59
59
  session: (search: string) => Promise<import("./commerce/types/Session").Session>;
60
- getSessionOrder: () => Promise<import("./commerce/types/Session").Session>;
61
60
  subscribeToNewsletter: (data: {
62
61
  name: string;
63
62
  email: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "2.1.83",
3
+ "version": "2.1.90",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -56,5 +56,5 @@
56
56
  "@envelop/core": "^1 || ^2",
57
57
  "graphql": "^15.6.0"
58
58
  },
59
- "gitHead": "a55301974a0ab1894b32414d372091d956fbc17b"
59
+ "gitHead": "be6117a519217458b14ae3e2c5151a329e47e759"
60
60
  }
@@ -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'
@@ -131,7 +130,7 @@ export const VtexCommerce = (
131
130
  headers: {
132
131
  'content-type': 'application/json',
133
132
  cookie: ctx.headers.cookie,
134
- }
133
+ },
135
134
  }
136
135
  )
137
136
  },
@@ -243,34 +242,13 @@ export const VtexCommerce = (
243
242
  'items',
244
243
  'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol'
245
244
  )
246
- if (getCookie('vtex_session', ctx.headers.cookie)) {
247
- // cookie set
248
- return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
249
- method: 'GET',
250
- headers: {
251
- 'content-type': 'application/json',
252
- cookie: ctx.headers.cookie,
253
- },
254
- })
255
- } else {
256
- // cookie unset -> create session
257
- return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
258
- method: 'POST',
259
- headers: {
260
- 'content-type': 'application/json',
261
- cookie: ctx.headers.cookie,
262
- },
263
- body: '{}',
264
- })
265
- }
266
- },
267
- getSessionOrder: (): Promise<Session> => {
268
- return fetchAPI(`${base}/api/sessions?items=public.orderFormId`, {
269
- method: 'GET',
245
+ return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
246
+ method: 'POST',
270
247
  headers: {
271
248
  'content-type': 'application/json',
272
249
  cookie: ctx.headers.cookie,
273
250
  },
251
+ body: '{}',
274
252
  })
275
253
  },
276
254
  subscribeToNewsletter: (data: {
@@ -1,7 +1,6 @@
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,
@@ -130,7 +129,8 @@ const joinItems = (form: OrderForm) => {
130
129
  const totalPrice = items.reduce(
131
130
  (acc, i) =>
132
131
  acc +
133
- (i?.priceDefinition?.total ?? (i?.quantity ?? 0) * (i?.sellingPrice ?? 0)),
132
+ (i?.priceDefinition?.total ??
133
+ (i?.quantity ?? 0) * (i?.sellingPrice ?? 0)),
134
134
  0
135
135
  )
136
136
 
@@ -207,19 +207,6 @@ const isOrderFormStale = (form: OrderForm) => {
207
207
  return newEtag !== oldEtag
208
208
  }
209
209
 
210
- async function getOrderNumberFromSession(
211
- headers: Record<string, string> = {},
212
- commerce: Context['clients']['commerce']
213
- ) {
214
- const cookieSession = getCookie('vtex_session', headers.cookie)
215
-
216
- if (cookieSession) {
217
- const { namespaces } = await commerce.getSessionOrder()
218
- return namespaces.public?.orderFormId?.value ?? undefined
219
- }
220
- return
221
- }
222
-
223
210
  // Returns the regionalized orderForm
224
211
  const getOrderForm = async (id: string, { clients: { commerce } }: Context) => {
225
212
  return commerce.checkout.orderForm({
@@ -303,15 +290,10 @@ export const validateCart = async (
303
290
  { cart: { order }, session }: MutationValidateCartArgs,
304
291
  ctx: Context
305
292
  ) => {
306
- const {
307
- orderNumber: orderNumberFromCart,
308
- acceptedOffer,
309
- shouldSplitItem,
310
- } = order
293
+ const { orderNumber, acceptedOffer, shouldSplitItem } = order
311
294
  const {
312
295
  clients: { commerce },
313
296
  loaders: { skuLoader },
314
- headers,
315
297
  } = ctx
316
298
 
317
299
  const channel = session?.channel
@@ -325,25 +307,10 @@ export const validateCart = async (
325
307
  mutateLocaleContext(ctx, locale)
326
308
  }
327
309
 
328
- const orderNumberFromSession = await getOrderNumberFromSession(
329
- headers,
330
- commerce
331
- )
332
- const orderNumber = orderNumberFromSession ?? orderNumberFromCart ?? ''
333
-
334
310
  // Step1: Get OrderForm from VTEX Commerce
335
311
  const orderForm = await getOrderForm(orderNumber, ctx)
336
312
 
337
- // Step1.1: Checks if the orderForm id has changed. There are three cases for this:
338
- // Social Selling: the vtex_session cookie contains a new orderForm id with Social Selling data
339
- // My Orders: the customer clicks on reordering through generating a new cart and when returning to the faststore, this information needs to be returned by vtex_session cookie.
340
- // New session: a new user enters the website and has no orderForm attributed to it (has no relation to the vtex_session cookie).
341
- // In all cases, the origin orderForm should replace the copy that's in the browser
342
- if (orderForm.orderFormId != orderNumberFromCart) {
343
- return orderFormToCart(orderForm, skuLoader)
344
- }
345
-
346
- // Step1.2: Check if another system changed the orderForm with this orderNumber
313
+ // Step1.5: Check if another system changed the orderForm with this orderNumber
347
314
  // If so, this means the user interacted with this cart elsewhere and expects
348
315
  // to see this new cart state instead of what's stored on the user's browser.
349
316
  const isStale = isOrderFormStale(orderForm)
@@ -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
- }