@faststore/api 2.0.158-alpha.0 → 2.0.162-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.
- package/dist/__generated__/schema.d.ts +70 -4
- package/dist/api.cjs.development.js +103 -22
- package/dist/api.cjs.development.js.map +1 -1
- package/dist/api.cjs.production.min.js +1 -1
- package/dist/api.cjs.production.min.js.map +1 -1
- package/dist/api.esm.js +103 -22
- package/dist/api.esm.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/platforms/vtex/clients/commerce/index.d.ts +6 -0
- package/dist/platforms/vtex/clients/commerce/types/OrderForm.d.ts +8 -1
- package/dist/platforms/vtex/clients/commerce/types/Region.d.ts +2 -2
- package/dist/platforms/vtex/clients/commerce/types/ShippingData.d.ts +5 -0
- package/dist/platforms/vtex/clients/index.d.ts +6 -0
- package/dist/platforms/vtex/index.d.ts +4 -0
- package/dist/platforms/vtex/resolvers/query.d.ts +5 -1
- package/package.json +2 -2
- package/src/__generated__/schema.ts +94 -21
- package/src/platforms/vtex/clients/commerce/index.ts +105 -40
- package/src/platforms/vtex/clients/commerce/types/OrderForm.ts +9 -1
- package/src/platforms/vtex/clients/commerce/types/Region.ts +2 -2
- package/src/platforms/vtex/clients/commerce/types/ShippingData.ts +6 -0
- package/src/platforms/vtex/resolvers/query.ts +22 -3
- package/src/platforms/vtex/resolvers/validateCart.ts +54 -27
- package/src/typeDefs/query.graphql +66 -0
- package/src/typeDefs/session.graphql +40 -6
- package/src/typeDefs/shipping.graphql +27 -0
|
@@ -6,20 +6,22 @@ import { md5 } from '../utils/md5'
|
|
|
6
6
|
import {
|
|
7
7
|
attachmentToPropertyValue,
|
|
8
8
|
getPropertyId,
|
|
9
|
-
VALUE_REFERENCES
|
|
9
|
+
VALUE_REFERENCES,
|
|
10
10
|
} from '../utils/propertyValue'
|
|
11
11
|
|
|
12
12
|
import type { Context } from '..'
|
|
13
13
|
import type {
|
|
14
14
|
IStoreOffer,
|
|
15
15
|
IStoreOrder,
|
|
16
|
-
IStorePropertyValue,
|
|
17
|
-
|
|
16
|
+
IStorePropertyValue,
|
|
17
|
+
IStoreSession,
|
|
18
|
+
Maybe,
|
|
19
|
+
MutationValidateCartArgs,
|
|
18
20
|
} from '../../../__generated__/schema'
|
|
19
21
|
import type {
|
|
20
22
|
OrderForm,
|
|
21
23
|
OrderFormInputItem,
|
|
22
|
-
OrderFormItem
|
|
24
|
+
OrderFormItem,
|
|
23
25
|
} from '../clients/commerce/types/OrderForm'
|
|
24
26
|
import { IncrementedAddress } from '../clients/commerce/types/IncrementedAddress'
|
|
25
27
|
|
|
@@ -204,21 +206,20 @@ async function getOrderNumberFromSession(
|
|
|
204
206
|
headers: Record<string, string> = {},
|
|
205
207
|
commerce: Context['clients']['commerce']
|
|
206
208
|
) {
|
|
207
|
-
|
|
208
209
|
const cookieSession = getCookie('vtex_session', headers.cookie)
|
|
209
210
|
|
|
210
211
|
if (cookieSession) {
|
|
211
212
|
const { namespaces } = await commerce.getSessionOrder()
|
|
212
213
|
return namespaces.checkout?.orderFormId?.value
|
|
213
214
|
}
|
|
214
|
-
return
|
|
215
|
+
return
|
|
215
216
|
}
|
|
216
217
|
|
|
217
218
|
// Returns the regionalized orderForm
|
|
218
219
|
const getOrderForm = async (
|
|
219
220
|
id: string,
|
|
220
221
|
session: Maybe<IStoreSession> | undefined,
|
|
221
|
-
{ clients: { commerce } }: Context
|
|
222
|
+
{ clients: { commerce } }: Context
|
|
222
223
|
) => {
|
|
223
224
|
const orderForm = await commerce.checkout.orderForm({
|
|
224
225
|
id,
|
|
@@ -234,31 +235,55 @@ const getOrderForm = async (
|
|
|
234
235
|
}
|
|
235
236
|
|
|
236
237
|
const shouldUpdateShippingData =
|
|
237
|
-
typeof session.postalCode === 'string' &&
|
|
238
|
-
|
|
239
|
-
(
|
|
240
|
-
typeof session.geoCoordinates === 'object' &&
|
|
238
|
+
(typeof session.postalCode === 'string' &&
|
|
239
|
+
orderForm.shippingData?.address?.postalCode !== session.postalCode) ||
|
|
240
|
+
(typeof session.geoCoordinates === 'object' &&
|
|
241
241
|
typeof session.geoCoordinates?.latitude === 'number' &&
|
|
242
242
|
typeof session.geoCoordinates.longitude === 'number' &&
|
|
243
|
-
(orderForm.shippingData?.address?.geoCoordinates[0] !==
|
|
244
|
-
|
|
245
|
-
|
|
243
|
+
(orderForm.shippingData?.address?.geoCoordinates[0] !==
|
|
244
|
+
session.geoCoordinates.longitude ||
|
|
245
|
+
orderForm.shippingData?.address?.geoCoordinates[1] !==
|
|
246
|
+
session.geoCoordinates.latitude))
|
|
246
247
|
|
|
247
248
|
if (shouldUpdateShippingData) {
|
|
248
|
-
let incrementedAddress: IncrementedAddress | undefined
|
|
249
|
+
let incrementedAddress: IncrementedAddress | undefined
|
|
249
250
|
|
|
250
251
|
if (session.postalCode) {
|
|
251
|
-
incrementedAddress = await commerce.checkout.incrementAddress(
|
|
252
|
+
incrementedAddress = await commerce.checkout.incrementAddress(
|
|
253
|
+
session.country,
|
|
254
|
+
session.postalCode
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
const hasDeliveryWindow = session.deliveryMode?.deliveryWindow
|
|
258
|
+
? true
|
|
259
|
+
: false
|
|
260
|
+
|
|
261
|
+
if (hasDeliveryWindow) {
|
|
262
|
+
// if you have a Delivery Window you have to first get the delivery window to set the desired after
|
|
263
|
+
await commerce.checkout.getDeliveryWindows(
|
|
264
|
+
{
|
|
265
|
+
id: orderForm.orderFormId,
|
|
266
|
+
index: orderForm.items.length,
|
|
267
|
+
deliveryMode: session.deliveryMode,
|
|
268
|
+
body: {
|
|
269
|
+
selectedAddresses: [session],
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
incrementedAddress
|
|
273
|
+
)
|
|
252
274
|
}
|
|
253
275
|
|
|
254
|
-
return commerce.checkout.shippingData(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
276
|
+
return commerce.checkout.shippingData(
|
|
277
|
+
{
|
|
278
|
+
id: orderForm.orderFormId,
|
|
279
|
+
index: orderForm.items.length,
|
|
280
|
+
deliveryMode: session.deliveryMode,
|
|
281
|
+
body: {
|
|
282
|
+
selectedAddresses: [session],
|
|
283
|
+
},
|
|
260
284
|
},
|
|
261
|
-
|
|
285
|
+
incrementedAddress
|
|
286
|
+
)
|
|
262
287
|
}
|
|
263
288
|
|
|
264
289
|
return orderForm
|
|
@@ -282,7 +307,11 @@ export const validateCart = async (
|
|
|
282
307
|
{ cart: { order }, session }: MutationValidateCartArgs,
|
|
283
308
|
ctx: Context
|
|
284
309
|
) => {
|
|
285
|
-
const {
|
|
310
|
+
const {
|
|
311
|
+
orderNumber: orderNumberFromCart,
|
|
312
|
+
acceptedOffer,
|
|
313
|
+
shouldSplitItem,
|
|
314
|
+
} = order
|
|
286
315
|
const {
|
|
287
316
|
clients: { commerce },
|
|
288
317
|
loaders: { skuLoader },
|
|
@@ -382,9 +411,7 @@ export const validateCart = async (
|
|
|
382
411
|
shouldSplitItem,
|
|
383
412
|
})
|
|
384
413
|
// update orderForm etag so we know last time we touched this orderForm
|
|
385
|
-
.then((form) =>
|
|
386
|
-
setOrderFormEtag(form, commerce)
|
|
387
|
-
)
|
|
414
|
+
.then((form) => setOrderFormEtag(form, commerce))
|
|
388
415
|
.then(joinItems)
|
|
389
416
|
|
|
390
417
|
// Step5: If no changes detected before/after updating orderForm, the order is validated
|
|
@@ -184,6 +184,17 @@ type StoreSearchResult {
|
|
|
184
184
|
metadata: SearchMetadata
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
input IGeoCoordinates {
|
|
188
|
+
"""
|
|
189
|
+
The latitude of the geographic coordinates.
|
|
190
|
+
"""
|
|
191
|
+
latitude: Float!
|
|
192
|
+
"""
|
|
193
|
+
The longitude of the geographic coordinates.
|
|
194
|
+
"""
|
|
195
|
+
longitude: Float!
|
|
196
|
+
}
|
|
197
|
+
|
|
187
198
|
type Query {
|
|
188
199
|
"""
|
|
189
200
|
Returns the details of a product based on the specified locator.
|
|
@@ -282,4 +293,59 @@ type Query {
|
|
|
282
293
|
country: String!
|
|
283
294
|
): ShippingData
|
|
284
295
|
@cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)
|
|
296
|
+
|
|
297
|
+
"""
|
|
298
|
+
Returns a list of sellers available for a specific localization.
|
|
299
|
+
"""
|
|
300
|
+
sellers(
|
|
301
|
+
"""
|
|
302
|
+
Postal code input to calculate sellers
|
|
303
|
+
"""
|
|
304
|
+
postalCode: String
|
|
305
|
+
"""
|
|
306
|
+
Geocoordinates input to calculate sellers
|
|
307
|
+
"""
|
|
308
|
+
geoCoordinates: IGeoCoordinates
|
|
309
|
+
"""
|
|
310
|
+
Country of localization
|
|
311
|
+
"""
|
|
312
|
+
country: String!
|
|
313
|
+
"""
|
|
314
|
+
Sales channel of the navigation
|
|
315
|
+
"""
|
|
316
|
+
salesChannel: String
|
|
317
|
+
): SellersData
|
|
318
|
+
@cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
"""
|
|
322
|
+
Regionalization with sellers information.
|
|
323
|
+
"""
|
|
324
|
+
type SellersData {
|
|
325
|
+
"""
|
|
326
|
+
Identification of region.
|
|
327
|
+
"""
|
|
328
|
+
id: String
|
|
329
|
+
"""
|
|
330
|
+
List of sellers.
|
|
331
|
+
"""
|
|
332
|
+
sellers: [SellerInfo]
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
"""
|
|
336
|
+
Information of sellers.
|
|
337
|
+
"""
|
|
338
|
+
type SellerInfo {
|
|
339
|
+
"""
|
|
340
|
+
Identification of the seller
|
|
341
|
+
"""
|
|
342
|
+
id: String
|
|
343
|
+
"""
|
|
344
|
+
Name of the seller
|
|
345
|
+
"""
|
|
346
|
+
name: String
|
|
347
|
+
"""
|
|
348
|
+
Logo of the seller
|
|
349
|
+
"""
|
|
350
|
+
logo: String
|
|
285
351
|
}
|
|
@@ -48,29 +48,65 @@ input IStoreGeoCoordinates {
|
|
|
48
48
|
longitude: Float!
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
"""
|
|
52
|
+
Delivery window information.
|
|
53
|
+
"""
|
|
54
|
+
type StoreDeliveryWindow {
|
|
55
|
+
"""
|
|
56
|
+
The delivery window start date information.
|
|
57
|
+
"""
|
|
58
|
+
startDate: String!
|
|
59
|
+
"""
|
|
60
|
+
The delivery window end date information.
|
|
61
|
+
"""
|
|
62
|
+
endDate: String!
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
"""
|
|
66
|
+
Delivery window information.
|
|
67
|
+
"""
|
|
68
|
+
input IStoreDeliveryWindow {
|
|
69
|
+
"""
|
|
70
|
+
The delivery window start date information.
|
|
71
|
+
"""
|
|
72
|
+
startDate: String!
|
|
73
|
+
"""
|
|
74
|
+
The delivery window end date information.
|
|
75
|
+
"""
|
|
76
|
+
endDate: String!
|
|
77
|
+
}
|
|
78
|
+
|
|
51
79
|
"""
|
|
52
80
|
Delivery mode information.
|
|
53
81
|
"""
|
|
54
82
|
type StoreDeliveryMode {
|
|
55
83
|
"""
|
|
56
|
-
The
|
|
84
|
+
The delivery channel information of the session.
|
|
57
85
|
"""
|
|
58
86
|
deliveryChannel: String!
|
|
59
87
|
"""
|
|
60
|
-
The
|
|
88
|
+
The delivery method information of the session.
|
|
61
89
|
"""
|
|
62
90
|
deliveryMethod: String!
|
|
91
|
+
"""
|
|
92
|
+
The delivery window information of the session.
|
|
93
|
+
"""
|
|
94
|
+
deliveryWindow: StoreDeliveryWindow
|
|
63
95
|
}
|
|
64
96
|
|
|
65
97
|
input IStoreDeliveryMode {
|
|
66
98
|
"""
|
|
67
|
-
The
|
|
99
|
+
The delivery channel information of the session.
|
|
68
100
|
"""
|
|
69
101
|
deliveryChannel: String!
|
|
70
102
|
"""
|
|
71
|
-
The
|
|
103
|
+
The delivery method information of the session.
|
|
72
104
|
"""
|
|
73
105
|
deliveryMethod: String!
|
|
106
|
+
"""
|
|
107
|
+
The delivery window information of the session.
|
|
108
|
+
"""
|
|
109
|
+
deliveryWindow: IStoreDeliveryWindow
|
|
74
110
|
}
|
|
75
111
|
|
|
76
112
|
"""
|
|
@@ -94,7 +130,6 @@ type StoreSession {
|
|
|
94
130
|
"""
|
|
95
131
|
channel: String
|
|
96
132
|
"""
|
|
97
|
-
|
|
98
133
|
Session delivery mode.
|
|
99
134
|
"""
|
|
100
135
|
deliveryMode: StoreDeliveryMode
|
|
@@ -137,7 +172,6 @@ input IStoreSession {
|
|
|
137
172
|
"""
|
|
138
173
|
channel: String
|
|
139
174
|
"""
|
|
140
|
-
|
|
141
175
|
Session input delivery mode.
|
|
142
176
|
"""
|
|
143
177
|
deliveryMode: IStoreDeliveryMode
|
|
@@ -135,6 +135,10 @@ type ShippingSLA {
|
|
|
135
135
|
"""
|
|
136
136
|
localizedEstimates: String
|
|
137
137
|
"""
|
|
138
|
+
ShippingSLA available delivery windows.
|
|
139
|
+
"""
|
|
140
|
+
availableDeliveryWindows: [AvailableDeliveryWindows]
|
|
141
|
+
"""
|
|
138
142
|
ShippingSLA shipping estimate date.
|
|
139
143
|
"""
|
|
140
144
|
shippingEstimateDate: String
|
|
@@ -168,6 +172,29 @@ type ShippingSLA {
|
|
|
168
172
|
pickupDistance: Float
|
|
169
173
|
}
|
|
170
174
|
|
|
175
|
+
type AvailableDeliveryWindows {
|
|
176
|
+
"""
|
|
177
|
+
Available delivery window start date in UTC
|
|
178
|
+
"""
|
|
179
|
+
startDateUtc: String
|
|
180
|
+
"""
|
|
181
|
+
Available delivery window end date in UTC
|
|
182
|
+
"""
|
|
183
|
+
endDateUtc: String
|
|
184
|
+
"""
|
|
185
|
+
Available delivery window price
|
|
186
|
+
"""
|
|
187
|
+
price: Int
|
|
188
|
+
"""
|
|
189
|
+
Available delivery window list price
|
|
190
|
+
"""
|
|
191
|
+
listPrice: Int
|
|
192
|
+
"""
|
|
193
|
+
Available delivery window tax
|
|
194
|
+
"""
|
|
195
|
+
tax: Int
|
|
196
|
+
}
|
|
197
|
+
|
|
171
198
|
type DeliveryIds {
|
|
172
199
|
"""
|
|
173
200
|
DeliveryIds courier id
|