@faststore/api 2.0.105-alpha.0 → 2.0.118-alpha.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.
@@ -57,7 +57,7 @@ export declare const VtexCommerce: ({ account, environment }: Options, ctx: Cont
57
57
  key: string;
58
58
  value: string;
59
59
  }) => Promise<OrderForm>;
60
- region: ({ postalCode, country, salesChannel, }: RegionInput) => Promise<Region[]>;
60
+ region: ({ postalCode, geoCoordinates, country, salesChannel, }: RegionInput) => Promise<Region[]>;
61
61
  address: ({ postalCode, country, }: AddressInput) => Promise<Address>;
62
62
  };
63
63
  session: (search: string) => Promise<Session>;
@@ -1,5 +1,6 @@
1
1
  export interface RegionInput {
2
2
  postalCode: string;
3
+ geoCoordinates: GeoCoordinates | null;
3
4
  country: string;
4
5
  salesChannel?: string | null;
5
6
  }
@@ -8,6 +9,10 @@ export interface Seller {
8
9
  name: string;
9
10
  logo: string;
10
11
  }
12
+ export interface GeoCoordinates {
13
+ latitude: GLfloat;
14
+ longitude: GLfloat;
15
+ }
11
16
  export interface Region {
12
17
  id: string;
13
18
  sellers: Seller[];
@@ -51,7 +51,7 @@ export declare const getClients: (options: Options, ctx: Context) => {
51
51
  key: string;
52
52
  value: string;
53
53
  }) => Promise<import("./commerce/types/OrderForm").OrderForm>;
54
- region: ({ postalCode, country, salesChannel, }: import("./commerce/types/Region").RegionInput) => Promise<import("./commerce/types/Region").Region[]>;
54
+ region: ({ postalCode, geoCoordinates, country, salesChannel, }: import("./commerce/types/Region").RegionInput) => Promise<import("./commerce/types/Region").Region[]>;
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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "2.0.105-alpha.0",
3
+ "version": "2.0.118-alpha.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -49,5 +49,5 @@
49
49
  "peerDependencies": {
50
50
  "graphql": "^15.6.0"
51
51
  },
52
- "gitHead": "24de7852ae4d01eaeb19c11731a6b131483cd947"
52
+ "gitHead": "e39696d0990df21098a6249c50963690bb2104a2"
53
53
  }
@@ -144,6 +144,13 @@ export type IStoreCurrency = {
144
144
  symbol: Scalars['String'];
145
145
  };
146
146
 
147
+ export type IStoreGeoCoordinates = {
148
+ /** The latitude of the geographic coordinates. */
149
+ latitude: Scalars['Float'];
150
+ /** The longitude of the geographic coordinates. */
151
+ longitude: Scalars['Float'];
152
+ };
153
+
147
154
  /** Image input. */
148
155
  export type IStoreImage = {
149
156
  /** Alias for the input image. */
@@ -233,9 +240,11 @@ export type IStoreSession = {
233
240
  country: Scalars['String'];
234
241
  /** Session input currency. */
235
242
  currency: IStoreCurrency;
243
+ /** Session input geoCoordinates. */
244
+ geoCoordinates?: Maybe<IStoreGeoCoordinates>;
236
245
  /** Session input locale. */
237
246
  locale: Scalars['String'];
238
- /** Session input postal code. */
247
+ /** Session input person. */
239
248
  person?: Maybe<IStorePerson>;
240
249
  /** Session input postal code. */
241
250
  postalCode?: Maybe<Scalars['String']>;
@@ -724,6 +733,15 @@ export type StoreFacetValueRange = {
724
733
  selected: Scalars['Float'];
725
734
  };
726
735
 
736
+ /** Geographic coordinates information. */
737
+ export type StoreGeoCoordinates = {
738
+ __typename?: 'StoreGeoCoordinates';
739
+ /** The latitude of the geographic coordinates. */
740
+ latitude: Scalars['Float'];
741
+ /** The longitude of the geographic coordinates. */
742
+ longitude: Scalars['Float'];
743
+ };
744
+
727
745
  /** Image. */
728
746
  export type StoreImage = {
729
747
  __typename?: 'StoreImage';
@@ -953,9 +971,11 @@ export type StoreSession = {
953
971
  country: Scalars['String'];
954
972
  /** Session currency. */
955
973
  currency: StoreCurrency;
974
+ /** Session input geoCoordinates. */
975
+ geoCoordinates?: Maybe<StoreGeoCoordinates>;
956
976
  /** Session locale. */
957
977
  locale: Scalars['String'];
958
- /** Session postal code. */
978
+ /** Session input person. */
959
979
  person?: Maybe<StorePerson>;
960
980
  /** Session postal code. */
961
981
  postalCode?: Maybe<Scalars['String']>;
@@ -176,14 +176,24 @@ export const VtexCommerce = (
176
176
  },
177
177
  region: async ({
178
178
  postalCode,
179
+ geoCoordinates,
179
180
  country,
180
181
  salesChannel,
181
182
  }: RegionInput): Promise<Region[]> => {
182
- return fetchAPI(
183
- `${base}/api/checkout/pub/regions/?postalCode=${postalCode}&country=${country}&sc=${
184
- salesChannel ?? ''
185
- }`
186
- )
183
+ const params = new URLSearchParams({
184
+ country: country,
185
+ sc: salesChannel ?? '',
186
+ })
187
+
188
+ postalCode
189
+ ? params.append('postalCode', postalCode)
190
+ : params.append(
191
+ 'geoCoordinates',
192
+ `${geoCoordinates?.longitude};${geoCoordinates?.latitude}`
193
+ )
194
+
195
+ const url = `${base}/api/checkout/pub/regions/?${params.toString()}`
196
+ return fetchAPI(url)
187
197
  },
188
198
  address: async ({
189
199
  postalCode,
@@ -1,16 +1,22 @@
1
1
  export interface RegionInput {
2
- postalCode: string;
3
- country: string;
4
- salesChannel?: string | null;
2
+ postalCode: string
3
+ geoCoordinates: GeoCoordinates | null
4
+ country: string
5
+ salesChannel?: string | null
5
6
  }
6
7
 
7
8
  export interface Seller {
8
- id: string; // storeframework01
9
- name: string; // My Awsome Seller
10
- logo: string;
9
+ id: string // storeframework01
10
+ name: string // My Awsome Seller
11
+ logo: string
12
+ }
13
+
14
+ export interface GeoCoordinates {
15
+ latitude: GLfloat
16
+ longitude: GLfloat
11
17
  }
12
18
 
13
19
  export interface Region {
14
- id: string;
15
- sellers: Seller[];
20
+ id: string
21
+ sellers: Seller[]
16
22
  }
@@ -14,6 +14,8 @@ export const validateSession = async (
14
14
  ): Promise<StoreSession | null> => {
15
15
  const channel = ChannelMarshal.parse(oldSession.channel ?? '')
16
16
  const postalCode = String(oldSession.postalCode ?? '').replace(/\D/g, '')
17
+ const geoCoordinates = oldSession.geoCoordinates ?? null
18
+
17
19
  const country = oldSession.country ?? ''
18
20
 
19
21
  const params = new URLSearchParams(search)
@@ -22,8 +24,13 @@ export const validateSession = async (
22
24
  params.set('sc', salesChannel)
23
25
 
24
26
  const [regionData, sessionData] = await Promise.all([
25
- postalCode
26
- ? clients.commerce.checkout.region({ postalCode, country, salesChannel })
27
+ postalCode || geoCoordinates
28
+ ? clients.commerce.checkout.region({
29
+ postalCode,
30
+ geoCoordinates,
31
+ country,
32
+ salesChannel,
33
+ })
27
34
  : Promise.resolve(null),
28
35
  clients.commerce.session(params.toString()).catch(() => null),
29
36
  ])
@@ -32,7 +39,7 @@ export const validateSession = async (
32
39
  const store = sessionData?.namespaces.store ?? null
33
40
  const region = regionData?.[0]
34
41
  // Set seller only if it's inside a region
35
- const seller = region?.sellers.find(seller => channel.seller === seller.id)
42
+ const seller = region?.sellers.find((seller) => channel.seller === seller.id)
36
43
 
37
44
  const newSession = {
38
45
  ...oldSession,
@@ -44,7 +51,7 @@ export const validateSession = async (
44
51
  channel: ChannelMarshal.stringify({
45
52
  salesChannel: store?.channel?.value ?? channel.salesChannel,
46
53
  regionId: region?.id ?? channel.regionId,
47
- seller: seller?.id
54
+ seller: seller?.id,
48
55
  }),
49
56
  person: profile?.id
50
57
  ? {
@@ -23,6 +23,31 @@ input IStoreCurrency {
23
23
  symbol: String!
24
24
  }
25
25
 
26
+ """
27
+ Geographic coordinates information.
28
+ """
29
+ type StoreGeoCoordinates {
30
+ """
31
+ The latitude of the geographic coordinates.
32
+ """
33
+ latitude: Float!
34
+ """
35
+ The longitude of the geographic coordinates.
36
+ """
37
+ longitude: Float!
38
+ }
39
+
40
+ input IStoreGeoCoordinates {
41
+ """
42
+ The latitude of the geographic coordinates.
43
+ """
44
+ latitude: Float!
45
+ """
46
+ The longitude of the geographic coordinates.
47
+ """
48
+ longitude: Float!
49
+ }
50
+
26
51
  """
27
52
  Session information.
28
53
  """
@@ -48,7 +73,11 @@ type StoreSession {
48
73
  """
49
74
  postalCode: String
50
75
  """
51
- Session postal code.
76
+ Session input geoCoordinates.
77
+ """
78
+ geoCoordinates: StoreGeoCoordinates
79
+ """
80
+ Session input person.
52
81
  """
53
82
  person: StorePerson
54
83
  }
@@ -78,7 +107,11 @@ input IStoreSession {
78
107
  """
79
108
  postalCode: String
80
109
  """
81
- Session input postal code.
110
+ Session input geoCoordinates.
111
+ """
112
+ geoCoordinates: IStoreGeoCoordinates
113
+ """
114
+ Session input person.
82
115
  """
83
116
  person: IStorePerson
84
117
  }