@faststore/api 2.1.0 → 2.1.8

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.
@@ -15,7 +15,7 @@ export interface SelectedAddress {
15
15
  neighborhood?: string | null;
16
16
  complement?: string | null;
17
17
  reference?: string | null;
18
- geoCoordinates?: GeoCoordinates | null | [];
18
+ geoCoordinates?: GeoCoordinates | GLfloat[] | null | [];
19
19
  }
20
20
  export interface GeoCoordinates {
21
21
  latitude: GLfloat;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "2.1.0",
3
+ "version": "2.1.8",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -36,8 +36,8 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@envelop/core": "^2.6.0",
39
- "@faststore/eslint-config": "^2.1.0",
40
- "@faststore/shared": "^2.1.0",
39
+ "@faststore/eslint-config": "^2.1.1",
40
+ "@faststore/shared": "^2.1.1",
41
41
  "@graphql-codegen/cli": "2.2.0",
42
42
  "@graphql-codegen/typescript": "2.2.2",
43
43
  "@types/express": "^4.17.16",
@@ -56,5 +56,5 @@
56
56
  "@envelop/core": "^1 || ^2",
57
57
  "graphql": "^15.6.0"
58
58
  },
59
- "gitHead": "74ae411fa1f628ae68c2cdcacfb63b1383a86490"
59
+ "gitHead": "13a1fc9bb15b846d705fbc5ab3bc19cb9b8c400c"
60
60
  }
@@ -19,7 +19,11 @@ import { getCookie } from '../../utils/getCookies'
19
19
  import type { SalesChannel } from './types/SalesChannel'
20
20
  import { MasterDataResponse } from './types/Newsletter'
21
21
  import type { Address, AddressInput } from './types/Address'
22
- import { DeliveryMode, ShippingDataBody } from './types/ShippingData'
22
+ import {
23
+ DeliveryMode,
24
+ ShippingDataBody,
25
+ SelectedAddress,
26
+ } from './types/ShippingData'
23
27
  import { IncrementedAddress } from './types/IncrementedAddress'
24
28
 
25
29
  type ValueOf<T> = T extends Record<string, infer K> ? K : never
@@ -126,27 +130,43 @@ export const VtexCommerce = (
126
130
  const mappedBody = {
127
131
  logisticsInfo: Array.from({ length: index }, (_, itemIndex) => ({
128
132
  itemIndex,
129
- selectedDeliveryChannel: deliveryMode?.deliveryChannel,
130
- selectedSla: deliveryMode?.deliveryMethod,
131
- })),
132
- selectedAddresses: body?.selectedAddresses?.map((address) => ({
133
- addressType: address.addressType || null,
134
- receiverName: address.receiverName || null,
135
- postalCode:
136
- address.postalCode || incrementedAddress?.postalCode || null,
137
- city: incrementedAddress?.city || null,
138
- state: incrementedAddress?.state || null,
139
- country: address.country || incrementedAddress?.country || null,
140
- street: incrementedAddress?.street || null,
141
- number: incrementedAddress?.number || null,
142
- neighborhood: incrementedAddress?.neighborhood || null,
143
- complement: incrementedAddress?.complement || null,
144
- reference: incrementedAddress?.reference || null,
145
- geoCoordinates:
146
- address.geoCoordinates ||
147
- incrementedAddress?.geoCoordinates ||
148
- [],
133
+ selectedDeliveryChannel: deliveryMode?.deliveryChannel || null,
134
+ selectedSla: deliveryMode?.deliveryMethod || null,
149
135
  })),
136
+ selectedAddresses: body?.selectedAddresses?.map((address) => {
137
+ const selectedAddress: SelectedAddress = {
138
+ addressType: address.addressType || null,
139
+ receiverName: address.receiverName || null,
140
+ postalCode:
141
+ address.postalCode || incrementedAddress?.postalCode || null,
142
+ city: incrementedAddress?.city || null,
143
+ state: incrementedAddress?.state || null,
144
+ country: address.country || incrementedAddress?.country || null,
145
+ street: incrementedAddress?.street || null,
146
+ number: incrementedAddress?.number || null,
147
+ neighborhood: incrementedAddress?.neighborhood || null,
148
+ complement: incrementedAddress?.complement || null,
149
+ reference: incrementedAddress?.reference || null,
150
+ geoCoordinates: [], // Initialize with default value
151
+ }
152
+
153
+ const longitude =
154
+ address?.geoCoordinates instanceof Array
155
+ ? null
156
+ : address?.geoCoordinates?.longitude || null
157
+
158
+ const latitude =
159
+ address?.geoCoordinates instanceof Array
160
+ ? null
161
+ : address?.geoCoordinates?.latitude || null
162
+
163
+ selectedAddress.geoCoordinates =
164
+ longitude && latitude
165
+ ? { longitude, latitude }
166
+ : incrementedAddress?.geoCoordinates || []
167
+
168
+ return selectedAddress
169
+ }),
150
170
  }
151
171
 
152
172
  return fetchAPI(
@@ -184,28 +204,44 @@ export const VtexCommerce = (
184
204
  const mappedBody = {
185
205
  logisticsInfo: Array.from({ length: index }, (_, itemIndex) => ({
186
206
  itemIndex,
187
- selectedDeliveryChannel: deliveryMode?.deliveryChannel,
188
- selectedSla: deliveryMode?.deliveryMethod,
207
+ selectedDeliveryChannel: deliveryMode?.deliveryChannel || null,
208
+ selectedSla: deliveryMode?.deliveryMethod || null,
189
209
  deliveryWindow: deliveryWindow,
190
210
  })),
191
- selectedAddresses: body?.selectedAddresses?.map((address) => ({
192
- addressType: address.addressType || null,
193
- receiverName: address.receiverName || null,
194
- postalCode:
195
- address.postalCode || incrementedAddress?.postalCode || null,
196
- city: incrementedAddress?.city || null,
197
- state: incrementedAddress?.state || null,
198
- country: address.country || incrementedAddress?.country || null,
199
- street: incrementedAddress?.street || null,
200
- number: incrementedAddress?.number || null,
201
- neighborhood: incrementedAddress?.neighborhood || null,
202
- complement: incrementedAddress?.complement || null,
203
- reference: incrementedAddress?.reference || null,
204
- geoCoordinates:
205
- address.geoCoordinates ||
206
- incrementedAddress?.geoCoordinates ||
207
- [],
208
- })),
211
+ selectedAddresses: body?.selectedAddresses?.map((address) => {
212
+ const selectedAddress: SelectedAddress = {
213
+ addressType: address.addressType || null,
214
+ receiverName: address.receiverName || null,
215
+ postalCode:
216
+ address.postalCode || incrementedAddress?.postalCode || null,
217
+ city: incrementedAddress?.city || null,
218
+ state: incrementedAddress?.state || null,
219
+ country: address.country || incrementedAddress?.country || null,
220
+ street: incrementedAddress?.street || null,
221
+ number: incrementedAddress?.number || null,
222
+ neighborhood: incrementedAddress?.neighborhood || null,
223
+ complement: incrementedAddress?.complement || null,
224
+ reference: incrementedAddress?.reference || null,
225
+ geoCoordinates: [], // Initialize with default value
226
+ }
227
+
228
+ const longitude =
229
+ address?.geoCoordinates instanceof Array
230
+ ? null
231
+ : address?.geoCoordinates?.longitude || null
232
+
233
+ const latitude =
234
+ address?.geoCoordinates instanceof Array
235
+ ? null
236
+ : address?.geoCoordinates?.latitude || null
237
+
238
+ selectedAddress.geoCoordinates =
239
+ longitude && latitude
240
+ ? [longitude, latitude]
241
+ : incrementedAddress?.geoCoordinates || []
242
+
243
+ return selectedAddress
244
+ }),
209
245
  }
210
246
 
211
247
  return fetchAPI(
@@ -1,42 +1,42 @@
1
1
  export interface ShippingDataBody {
2
- clearAddressIfPostalCodeNotFound?: boolean;
3
- selectedAddresses?: SelectedAddress[];
4
- logisticsInfo?: LogisticsInfo[];
2
+ clearAddressIfPostalCodeNotFound?: boolean
3
+ selectedAddresses?: SelectedAddress[]
4
+ logisticsInfo?: LogisticsInfo[]
5
5
  }
6
6
 
7
7
  export interface SelectedAddress {
8
- addressType?: string | null;
9
- receiverName?: string | null;
10
- postalCode?: string | null;
11
- city?: string | null;
12
- state?: string | null;
13
- country?: string | null;
14
- street?: string | null;
15
- number?: string | null;
16
- neighborhood?: string | null;
17
- complement?: string | null;
18
- reference?: string | null;
19
- geoCoordinates?: GeoCoordinates | null | [];
8
+ addressType?: string | null
9
+ receiverName?: string | null
10
+ postalCode?: string | null
11
+ city?: string | null
12
+ state?: string | null
13
+ country?: string | null
14
+ street?: string | null
15
+ number?: string | null
16
+ neighborhood?: string | null
17
+ complement?: string | null
18
+ reference?: string | null
19
+ geoCoordinates?: GeoCoordinates | GLfloat[] | null | []
20
20
  }
21
21
 
22
22
  export interface GeoCoordinates {
23
- latitude: GLfloat;
24
- longitude: GLfloat;
23
+ latitude: GLfloat
24
+ longitude: GLfloat
25
25
  }
26
26
 
27
27
  export interface DeliveryWindow {
28
- startDate: string;
29
- endDate: string;
28
+ startDate: string
29
+ endDate: string
30
30
  }
31
31
 
32
32
  export interface LogisticsInfo {
33
- itemIndex?: number;
34
- selectedDeliveryChannel?: string;
35
- selectedSla?: string;
33
+ itemIndex?: number
34
+ selectedDeliveryChannel?: string
35
+ selectedSla?: string
36
36
  }
37
37
 
38
38
  export interface DeliveryMode {
39
- deliveryChannel?: string;
40
- deliveryMethod?: string;
41
- deliveryWindow?: DeliveryWindow | null ;
39
+ deliveryChannel?: string
40
+ deliveryMethod?: string
41
+ deliveryWindow?: DeliveryWindow | null
42
42
  }
@@ -235,6 +235,7 @@ const getOrderForm = async (
235
235
  }
236
236
 
237
237
  const shouldUpdateShippingData =
238
+ orderForm.items.length > 0 &&
238
239
  (typeof session.postalCode === 'string' &&
239
240
  orderForm.shippingData?.address?.postalCode !== session.postalCode) ||
240
241
  (typeof session.geoCoordinates === 'object' &&
@@ -243,11 +244,11 @@ const getOrderForm = async (
243
244
  (orderForm.shippingData?.address?.geoCoordinates[0] !==
244
245
  session.geoCoordinates.longitude ||
245
246
  orderForm.shippingData?.address?.geoCoordinates[1] !==
246
- session.geoCoordinates.latitude))
247
+ session.geoCoordinates.latitude))
247
248
 
248
249
  if (shouldUpdateShippingData) {
249
250
  let incrementedAddress: IncrementedAddress | undefined
250
-
251
+
251
252
  if (session.postalCode) {
252
253
  incrementedAddress = await commerce.checkout.incrementAddress(
253
254
  session.country,
@@ -272,7 +273,7 @@ const getOrderForm = async (
272
273
  incrementedAddress
273
274
  )
274
275
  }
275
-
276
+
276
277
  return commerce.checkout.shippingData(
277
278
  {
278
279
  id: orderForm.orderFormId,