@faststore/api 3.66.0 → 3.68.1

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 (81) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/__generated__/schema.d.ts +51 -0
  3. package/dist/cjs/src/__generated__/schema.d.ts.map +1 -1
  4. package/dist/cjs/src/__generated__/schema.js.map +1 -1
  5. package/dist/cjs/src/index.d.ts +1 -0
  6. package/dist/cjs/src/index.d.ts.map +1 -1
  7. package/dist/cjs/src/platforms/vtex/clients/commerce/index.d.ts +2 -0
  8. package/dist/cjs/src/platforms/vtex/clients/commerce/index.d.ts.map +1 -1
  9. package/dist/cjs/src/platforms/vtex/clients/commerce/index.js +16 -2
  10. package/dist/cjs/src/platforms/vtex/clients/commerce/index.js.map +1 -1
  11. package/dist/cjs/src/platforms/vtex/clients/commerce/types/PickupPoints.d.ts +37 -0
  12. package/dist/cjs/src/platforms/vtex/clients/commerce/types/PickupPoints.d.ts.map +1 -0
  13. package/dist/cjs/src/platforms/vtex/clients/commerce/types/PickupPoints.js +3 -0
  14. package/dist/cjs/src/platforms/vtex/clients/commerce/types/PickupPoints.js.map +1 -0
  15. package/dist/cjs/src/platforms/vtex/clients/commerce/types/Session.d.ts +1 -0
  16. package/dist/cjs/src/platforms/vtex/clients/commerce/types/Session.d.ts.map +1 -1
  17. package/dist/cjs/src/platforms/vtex/clients/index.d.ts +1 -0
  18. package/dist/cjs/src/platforms/vtex/clients/index.d.ts.map +1 -1
  19. package/dist/cjs/src/platforms/vtex/clients/search/index.d.ts.map +1 -1
  20. package/dist/cjs/src/platforms/vtex/clients/search/index.js +12 -0
  21. package/dist/cjs/src/platforms/vtex/clients/search/index.js.map +1 -1
  22. package/dist/cjs/src/platforms/vtex/index.d.ts +1 -0
  23. package/dist/cjs/src/platforms/vtex/index.d.ts.map +1 -1
  24. package/dist/cjs/src/platforms/vtex/resolvers/facet.d.ts +1 -1
  25. package/dist/cjs/src/platforms/vtex/resolvers/facet.d.ts.map +1 -1
  26. package/dist/cjs/src/platforms/vtex/resolvers/facet.js.map +1 -1
  27. package/dist/cjs/src/platforms/vtex/resolvers/query.d.ts +2 -1
  28. package/dist/cjs/src/platforms/vtex/resolvers/query.d.ts.map +1 -1
  29. package/dist/cjs/src/platforms/vtex/resolvers/query.js +8 -1
  30. package/dist/cjs/src/platforms/vtex/resolvers/query.js.map +1 -1
  31. package/dist/cjs/src/platforms/vtex/resolvers/validateSession.d.ts.map +1 -1
  32. package/dist/cjs/src/platforms/vtex/resolvers/validateSession.js +12 -6
  33. package/dist/cjs/src/platforms/vtex/resolvers/validateSession.js.map +1 -1
  34. package/dist/cjs/src/typeDefs/pickupPoints.graphql +79 -0
  35. package/dist/cjs/src/typeDefs/query.graphql +11 -0
  36. package/dist/esm/package.json +1 -1
  37. package/dist/esm/src/__generated__/schema.d.ts +51 -0
  38. package/dist/esm/src/__generated__/schema.d.ts.map +1 -1
  39. package/dist/esm/src/__generated__/schema.js.map +1 -1
  40. package/dist/esm/src/index.d.ts +1 -0
  41. package/dist/esm/src/index.d.ts.map +1 -1
  42. package/dist/esm/src/platforms/vtex/clients/commerce/index.d.ts +2 -0
  43. package/dist/esm/src/platforms/vtex/clients/commerce/index.d.ts.map +1 -1
  44. package/dist/esm/src/platforms/vtex/clients/commerce/index.js +16 -2
  45. package/dist/esm/src/platforms/vtex/clients/commerce/index.js.map +1 -1
  46. package/dist/esm/src/platforms/vtex/clients/commerce/types/PickupPoints.d.ts +37 -0
  47. package/dist/esm/src/platforms/vtex/clients/commerce/types/PickupPoints.d.ts.map +1 -0
  48. package/dist/esm/src/platforms/vtex/clients/commerce/types/PickupPoints.js +2 -0
  49. package/dist/esm/src/platforms/vtex/clients/commerce/types/PickupPoints.js.map +1 -0
  50. package/dist/esm/src/platforms/vtex/clients/commerce/types/Session.d.ts +1 -0
  51. package/dist/esm/src/platforms/vtex/clients/commerce/types/Session.d.ts.map +1 -1
  52. package/dist/esm/src/platforms/vtex/clients/index.d.ts +1 -0
  53. package/dist/esm/src/platforms/vtex/clients/index.d.ts.map +1 -1
  54. package/dist/esm/src/platforms/vtex/clients/search/index.d.ts.map +1 -1
  55. package/dist/esm/src/platforms/vtex/clients/search/index.js +12 -0
  56. package/dist/esm/src/platforms/vtex/clients/search/index.js.map +1 -1
  57. package/dist/esm/src/platforms/vtex/index.d.ts +1 -0
  58. package/dist/esm/src/platforms/vtex/index.d.ts.map +1 -1
  59. package/dist/esm/src/platforms/vtex/resolvers/facet.d.ts +1 -1
  60. package/dist/esm/src/platforms/vtex/resolvers/facet.d.ts.map +1 -1
  61. package/dist/esm/src/platforms/vtex/resolvers/facet.js.map +1 -1
  62. package/dist/esm/src/platforms/vtex/resolvers/query.d.ts +2 -1
  63. package/dist/esm/src/platforms/vtex/resolvers/query.d.ts.map +1 -1
  64. package/dist/esm/src/platforms/vtex/resolvers/query.js +8 -1
  65. package/dist/esm/src/platforms/vtex/resolvers/query.js.map +1 -1
  66. package/dist/esm/src/platforms/vtex/resolvers/validateSession.d.ts.map +1 -1
  67. package/dist/esm/src/platforms/vtex/resolvers/validateSession.js +12 -6
  68. package/dist/esm/src/platforms/vtex/resolvers/validateSession.js.map +1 -1
  69. package/dist/esm/src/typeDefs/pickupPoints.graphql +79 -0
  70. package/dist/esm/src/typeDefs/query.graphql +11 -0
  71. package/package.json +2 -2
  72. package/src/__generated__/schema.ts +57 -0
  73. package/src/platforms/vtex/clients/commerce/index.ts +27 -2
  74. package/src/platforms/vtex/clients/commerce/types/PickupPoints.ts +40 -0
  75. package/src/platforms/vtex/clients/commerce/types/Session.ts +1 -0
  76. package/src/platforms/vtex/clients/search/index.ts +20 -0
  77. package/src/platforms/vtex/resolvers/facet.ts +4 -4
  78. package/src/platforms/vtex/resolvers/query.ts +17 -1
  79. package/src/platforms/vtex/resolvers/validateSession.ts +13 -6
  80. package/src/typeDefs/pickupPoints.graphql +79 -0
  81. package/src/typeDefs/query.graphql +11 -0
@@ -14,6 +14,7 @@ import type {
14
14
  UserOrderListResult,
15
15
  } from '../../../..'
16
16
  import type { Context, Options } from '../../index'
17
+ import { buildFormData } from '../../utils/buildFormData'
17
18
  import type { Channel } from '../../utils/channel'
18
19
  import {
19
20
  getStoreCookie,
@@ -26,6 +27,7 @@ import type { Brand } from './types/Brand'
26
27
  import type { CategoryTree } from './types/CategoryTree'
27
28
  import type { MasterDataResponse } from './types/Newsletter'
28
29
  import type { OrderForm, OrderFormInputItem } from './types/OrderForm'
30
+ import type { PickupPoints, PickupPointsInput } from './types/PickupPoints'
29
31
  import type { PortalPagetype } from './types/Portal'
30
32
  import type { PortalProduct } from './types/Product'
31
33
  import type { Region, RegionInput } from './types/Region'
@@ -39,7 +41,6 @@ import type {
39
41
  } from './types/Simulation'
40
42
  import type { ScopesByUnit, UnitResponse } from './types/Unit'
41
43
  import type { VtexIdResponse } from './types/VtexId'
42
- import { buildFormData } from '../../utils/buildFormData'
43
44
 
44
45
  type ValueOf<T> = T extends Record<string, infer K> ? K : never
45
46
 
@@ -393,13 +394,37 @@ export const VtexCommerce = (
393
394
  {}
394
395
  )
395
396
  },
397
+ pickupPoints: ({
398
+ geoCoordinates,
399
+ }: PickupPointsInput): Promise<PickupPoints> => {
400
+ if (!geoCoordinates) {
401
+ throw new Error(
402
+ 'Missing required parameter for listing pickup points.'
403
+ )
404
+ }
405
+
406
+ const headers: HeadersInit = withCookie({
407
+ 'content-type': 'application/json',
408
+ 'X-FORWARDED-HOST': forwardedHost,
409
+ })
410
+
411
+ return fetchAPI(
412
+ `${base}/api/logistics-shipping/pickuppoints/_search`,
413
+ {
414
+ method: 'POST',
415
+ headers,
416
+ body: JSON.stringify({ coordinate: geoCoordinates }),
417
+ },
418
+ { storeCookies }
419
+ )
420
+ },
396
421
  },
397
422
  session: (search: string): Promise<Session> => {
398
423
  const params = new URLSearchParams(search)
399
424
 
400
425
  params.set(
401
426
  'items',
402
- 'profile.id,profile.email,profile.firstName,profile.lastName,shopper.firstName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol,authentication.customerId,authentication.storeUserId,authentication.storeUserEmail,authentication.unitId,authentication.unitName,checkout.regionId,public.postalCode'
427
+ 'profile.id,profile.email,profile.firstName,profile.lastName,shopper.firstName,shopper.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol,authentication.customerId,authentication.storeUserId,authentication.storeUserEmail,authentication.unitId,authentication.unitName,checkout.regionId,public.postalCode'
403
428
  )
404
429
 
405
430
  const headers: HeadersInit = withCookie({
@@ -0,0 +1,40 @@
1
+ interface GeoCoordinates {
2
+ latitude: number
3
+ longitude: number
4
+ }
5
+
6
+ export interface PickupPointsInput {
7
+ country?: string | null
8
+ geoCoordinates?: GeoCoordinates | null
9
+ postalCode?: string | null
10
+ }
11
+
12
+ interface Address {
13
+ city: string
14
+ geoCoordinates: [number, number] // [longitude, latitude]
15
+ neighborhood: string
16
+ number: string
17
+ postalCode: string
18
+ street: string
19
+ state: string
20
+ }
21
+
22
+ interface BusinessHour {
23
+ dayOfWeek: number
24
+ openingTime: string
25
+ closingTime: string
26
+ }
27
+
28
+ interface PickupPointDistance {
29
+ pickupId: string
30
+ distance: number
31
+ pickupName: string
32
+ isActive: boolean
33
+ address: Address
34
+ businessHours: BusinessHour[]
35
+ }
36
+
37
+ export interface PickupPoints {
38
+ pickupPointDistances: PickupPointDistance[]
39
+ pickupPointsHash: string
40
+ }
@@ -41,6 +41,7 @@ export interface Profile {
41
41
 
42
42
  export interface Shopper {
43
43
  firstName?: Value
44
+ lastName?: Value
44
45
  }
45
46
 
46
47
  export interface Checkout {
@@ -52,12 +52,16 @@ const POLICY_KEY = 'trade-policy'
52
52
  const REGION_KEY = 'region-id'
53
53
  const FUZZY_KEY = 'fuzzy'
54
54
  const OPERATOR_KEY = 'operator'
55
+ const PICKUP_POINT_KEY = 'pickupPoint'
56
+ const SHIPPING_KEY = 'shipping'
55
57
 
56
58
  const EXTRA_FACETS_KEYS = new Set([
57
59
  POLICY_KEY,
58
60
  REGION_KEY,
59
61
  FUZZY_KEY,
60
62
  OPERATOR_KEY,
63
+ PICKUP_POINT_KEY,
64
+ SHIPPING_KEY,
61
65
  ])
62
66
 
63
67
  export const isFacetBoolean = (
@@ -142,12 +146,22 @@ export const IntelligentSearch = (
142
146
  ({ key }) => !EXTRA_FACETS_KEYS.has(key)
143
147
  )
144
148
 
149
+ const shippingFacet =
150
+ facets.find(
151
+ ({ key, value }) =>
152
+ key === SHIPPING_KEY && value !== 'all-delivery-methods'
153
+ ) ?? null
154
+
145
155
  const policyFacet =
146
156
  facets.find(({ key }) => key === POLICY_KEY) ?? getPolicyFacet()
147
157
 
148
158
  const regionFacet =
149
159
  facets.find(({ key }) => key === REGION_KEY) ?? getRegionFacet()
150
160
 
161
+ if (shippingFacet !== null) {
162
+ withDefaultFacets.push(shippingFacet)
163
+ }
164
+
151
165
  if (policyFacet !== null) {
152
166
  withDefaultFacets.push(policyFacet)
153
167
  }
@@ -165,6 +179,8 @@ export const IntelligentSearch = (
165
179
  ) => {
166
180
  const fuzzyFacet = facets.find(({ key }) => key === FUZZY_KEY) ?? null
167
181
  const operatorFacet = facets.find(({ key }) => key === OPERATOR_KEY) ?? null
182
+ const pickupPointFacet =
183
+ facets.find(({ key }) => key === PICKUP_POINT_KEY) ?? null
168
184
 
169
185
  if (fuzzyFacet && isFuzzyFacet(fuzzyFacet)) {
170
186
  params.append(FUZZY_KEY, fuzzyFacet.value)
@@ -173,6 +189,10 @@ export const IntelligentSearch = (
173
189
  if (operatorFacet && isOperatorFacet(operatorFacet)) {
174
190
  params.append(OPERATOR_KEY, operatorFacet.value)
175
191
  }
192
+
193
+ if (pickupPointFacet) {
194
+ params.append(PICKUP_POINT_KEY, pickupPointFacet.value)
195
+ }
176
196
  }
177
197
 
178
198
  const search = <T>({
@@ -1,11 +1,11 @@
1
- import { parseRange } from '../utils/facets'
2
- import { min } from '../utils/orderStatistics'
1
+ import type { Resolver } from '..'
3
2
  import type {
4
- FacetValueBoolean,
5
3
  Facet,
4
+ FacetValueBoolean,
6
5
  FacetValueRange,
7
6
  } from '../clients/search/types/FacetSearchResult'
8
- import type { Resolver } from '..'
7
+ import { parseRange } from '../utils/facets'
8
+ import { min } from '../utils/orderStatistics'
9
9
 
10
10
  export type Root = Facet
11
11
 
@@ -4,6 +4,7 @@ import type {
4
4
  QueryAllProductsArgs,
5
5
  QueryCollectionArgs,
6
6
  QueryListUserOrdersArgs,
7
+ QueryPickupPointsArgs,
7
8
  QueryProductArgs,
8
9
  QueryProductCountArgs,
9
10
  QueryProfileArgs,
@@ -19,6 +20,7 @@ import type { CategoryTree } from '../clients/commerce/types/CategoryTree'
19
20
  import type { ProfileAddress } from '../clients/commerce/types/Profile'
20
21
  import type { SearchArgs } from '../clients/search'
21
22
  import type { Context } from '../index'
23
+ import { extractRuleForAuthorization } from '../utils/commercialAuth'
22
24
  import { mutateChannelContext, mutateLocaleContext } from '../utils/contex'
23
25
  import { getAuthCookie, parseJwt } from '../utils/cookies'
24
26
  import { enhanceSku } from '../utils/enhanceSku'
@@ -33,7 +35,6 @@ import {
33
35
  import { isValidSkuId, pickBestSku } from '../utils/sku'
34
36
  import { SORT_MAP } from '../utils/sort'
35
37
  import { FACET_CROSS_SELLING_MAP } from './../utils/facets'
36
- import { extractRuleForAuthorization } from '../utils/commercialAuth'
37
38
  import { StoreCollection } from './collection'
38
39
 
39
40
  export const Query = {
@@ -601,4 +602,19 @@ export const Query = {
601
602
  // createdAt: '',
602
603
  }
603
604
  },
605
+ pickupPoints: async (
606
+ _: unknown,
607
+ { geoCoordinates }: QueryPickupPointsArgs,
608
+ ctx: Context
609
+ ) => {
610
+ const {
611
+ clients: { commerce },
612
+ } = ctx
613
+
614
+ const result = await commerce.checkout.pickupPoints({
615
+ geoCoordinates,
616
+ })
617
+
618
+ return result
619
+ },
604
620
  }
@@ -132,15 +132,22 @@ export const validateSession = async (
132
132
  seller: seller?.id,
133
133
  hasOnlyDefaultSalesChannel: !store?.channel?.value,
134
134
  }),
135
+ /**
136
+ * B2B data structure in Session:
137
+ * - Logged user data (shopper): `shopper` namespace
138
+ * - Unit data: `authentication` namespace
139
+ * - Contract data: `profile` namespace (those info will be available inside Faststore's Session `person` object)
140
+ */
135
141
  b2b: isRepresentative
136
142
  ? {
137
143
  isRepresentative: isRepresentative ?? false,
138
- customerId: authentication?.customerId?.value ?? customerId ?? '', //contract
139
- unitName: authentication?.unitName?.value ?? '', // organization name
140
- unitId: authentication?.unitId?.value ?? unitId ?? '', // organization id
141
- firstName: profile?.firstName?.value ?? '', // contract name for b2b
142
- lastName: profile?.lastName?.value ?? '',
143
- userName: shopper?.firstName?.value ?? '', // shopper
144
+ customerId: authentication?.customerId?.value ?? customerId ?? '',
145
+ unitName: authentication?.unitName?.value ?? '',
146
+ unitId: authentication?.unitId?.value ?? unitId ?? '',
147
+ firstName: shopper?.firstName?.value ?? '',
148
+ lastName: shopper?.lastName?.value ?? '',
149
+ userName:
150
+ `${shopper?.firstName?.value ?? ''} ${shopper?.lastName?.value ?? ''}`.trim(),
144
151
  userEmail: authentication?.storeUserEmail.value ?? '',
145
152
  savedPostalCode: publicData?.postalCode?.value ?? '',
146
153
  }
@@ -0,0 +1,79 @@
1
+ type PickupPointAddress {
2
+ """
3
+ Address city.
4
+ """
5
+ city: String
6
+ """
7
+ Address neighborhood.
8
+ """
9
+ neighborhood: String
10
+ """
11
+ Address number.
12
+ """
13
+ number: String
14
+ """
15
+ Address postal code.
16
+ """
17
+ postalCode: String
18
+ """
19
+ Address street.
20
+ """
21
+ street: String
22
+ """
23
+ Address state.
24
+ """
25
+ state: String
26
+ }
27
+
28
+ type BusinessHour {
29
+ """
30
+ Number that represents the day of the week.
31
+ """
32
+ dayOfWeek: Int
33
+ """
34
+ Business hour opening time.
35
+ """
36
+ openingTime: String
37
+ """
38
+ Business hour closing time.
39
+ """
40
+ closingTime: String
41
+ }
42
+
43
+ type PickupPointDistance {
44
+ """
45
+ Pickup point ID.
46
+ """
47
+ pickupId: String
48
+ """
49
+ Pickup point distance.
50
+ """
51
+ distance: Float
52
+ """
53
+ Pickup point name.
54
+ """
55
+ pickupName: String
56
+ """
57
+ Whether the pickup point is active.
58
+ """
59
+ isActive: Boolean
60
+ """
61
+ Pickup point address.
62
+ """
63
+ address: PickupPointAddress
64
+ """
65
+ Pickup point business hours.
66
+ """
67
+ businessHours: [BusinessHour]
68
+ }
69
+
70
+ type PickupPoints {
71
+ """
72
+ List of pickup point distances for the given location.
73
+ """
74
+ pickupPointDistances: [PickupPointDistance]
75
+ """
76
+ Hash of the pickup points data.
77
+ """
78
+ pickupPointsHash: String
79
+ }
@@ -437,6 +437,17 @@ type Query {
437
437
  """
438
438
  validateUser: ValidateUserData
439
439
  @cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)
440
+
441
+ """
442
+ Returns a list of pickup points near to the given geo coordinates.
443
+ """
444
+ pickupPoints(
445
+ """
446
+ Geo coordinates input.
447
+ """
448
+ geoCoordinates: IStoreGeoCoordinates
449
+ ): PickupPoints
450
+ @cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)
440
451
  }
441
452
 
442
453
  type ValidateUserData {