@faststore/api 2.0.157-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 +86 -2
- package/dist/api.cjs.development.js +113 -21
- 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 +113 -21
- package/dist/api.esm.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/platforms/vtex/clients/commerce/index.d.ts +10 -2
- 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 +9 -0
- package/dist/platforms/vtex/clients/index.d.ts +9 -1
- 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 +112 -19
- package/src/platforms/vtex/clients/commerce/index.ts +108 -36
- 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 +11 -0
- package/src/platforms/vtex/resolvers/query.ts +22 -3
- package/src/platforms/vtex/resolvers/validateCart.ts +56 -26
- package/src/typeDefs/query.graphql +66 -0
- package/src/typeDefs/session.graphql +71 -2
- package/src/typeDefs/shipping.graphql +27 -0
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
QueryCollectionArgs,
|
|
19
19
|
QueryProductArgs,
|
|
20
20
|
QuerySearchArgs,
|
|
21
|
+
QuerySellersArgs,
|
|
21
22
|
QueryShippingArgs,
|
|
22
23
|
} from "../../../__generated__/schema"
|
|
23
24
|
import type { CategoryTree } from "../clients/commerce/types/CategoryTree"
|
|
@@ -142,9 +143,8 @@ export const Query = {
|
|
|
142
143
|
productId: crossSelling.value,
|
|
143
144
|
})
|
|
144
145
|
|
|
145
|
-
query = `product:${
|
|
146
|
-
|
|
147
|
-
}`
|
|
146
|
+
query = `product:${products.map((x) => x.productId).slice(0, first).join(";")
|
|
147
|
+
}`
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
const after = maybeAfter ? Number(maybeAfter) : 0
|
|
@@ -273,4 +273,23 @@ export const Query = {
|
|
|
273
273
|
address,
|
|
274
274
|
}
|
|
275
275
|
},
|
|
276
|
+
|
|
277
|
+
sellers: async (
|
|
278
|
+
_: unknown,
|
|
279
|
+
{ postalCode, geoCoordinates, country, salesChannel }: QuerySellersArgs,
|
|
280
|
+
ctx: Context
|
|
281
|
+
) => {
|
|
282
|
+
const {
|
|
283
|
+
clients: { commerce },
|
|
284
|
+
} = ctx
|
|
285
|
+
|
|
286
|
+
const regionData = await commerce.checkout.region({ postalCode, geoCoordinates, country, salesChannel })
|
|
287
|
+
const region = regionData?.[0]
|
|
288
|
+
const { id, sellers } = region
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
id,
|
|
292
|
+
sellers
|
|
293
|
+
}
|
|
294
|
+
},
|
|
276
295
|
}
|
|
@@ -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,28 +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
|
|
250
|
+
|
|
249
251
|
if (session.postalCode) {
|
|
250
|
-
incrementedAddress = await commerce.checkout.incrementAddress(
|
|
251
|
-
|
|
252
|
+
incrementedAddress = await commerce.checkout.incrementAddress(
|
|
253
|
+
session.country,
|
|
254
|
+
session.postalCode
|
|
255
|
+
)
|
|
252
256
|
}
|
|
253
|
-
|
|
254
|
-
|
|
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
|
+
)
|
|
274
|
+
}
|
|
275
|
+
|
|
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
|
+
},
|
|
257
284
|
},
|
|
258
|
-
|
|
285
|
+
incrementedAddress
|
|
286
|
+
)
|
|
259
287
|
}
|
|
260
288
|
|
|
261
289
|
return orderForm
|
|
@@ -279,7 +307,11 @@ export const validateCart = async (
|
|
|
279
307
|
{ cart: { order }, session }: MutationValidateCartArgs,
|
|
280
308
|
ctx: Context
|
|
281
309
|
) => {
|
|
282
|
-
const {
|
|
310
|
+
const {
|
|
311
|
+
orderNumber: orderNumberFromCart,
|
|
312
|
+
acceptedOffer,
|
|
313
|
+
shouldSplitItem,
|
|
314
|
+
} = order
|
|
283
315
|
const {
|
|
284
316
|
clients: { commerce },
|
|
285
317
|
loaders: { skuLoader },
|
|
@@ -379,9 +411,7 @@ export const validateCart = async (
|
|
|
379
411
|
shouldSplitItem,
|
|
380
412
|
})
|
|
381
413
|
// update orderForm etag so we know last time we touched this orderForm
|
|
382
|
-
.then((form) =>
|
|
383
|
-
setOrderFormEtag(form, commerce)
|
|
384
|
-
)
|
|
414
|
+
.then((form) => setOrderFormEtag(form, commerce))
|
|
385
415
|
.then(joinItems)
|
|
386
416
|
|
|
387
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,6 +48,67 @@ 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
|
+
|
|
79
|
+
"""
|
|
80
|
+
Delivery mode information.
|
|
81
|
+
"""
|
|
82
|
+
type StoreDeliveryMode {
|
|
83
|
+
"""
|
|
84
|
+
The delivery channel information of the session.
|
|
85
|
+
"""
|
|
86
|
+
deliveryChannel: String!
|
|
87
|
+
"""
|
|
88
|
+
The delivery method information of the session.
|
|
89
|
+
"""
|
|
90
|
+
deliveryMethod: String!
|
|
91
|
+
"""
|
|
92
|
+
The delivery window information of the session.
|
|
93
|
+
"""
|
|
94
|
+
deliveryWindow: StoreDeliveryWindow
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
input IStoreDeliveryMode {
|
|
98
|
+
"""
|
|
99
|
+
The delivery channel information of the session.
|
|
100
|
+
"""
|
|
101
|
+
deliveryChannel: String!
|
|
102
|
+
"""
|
|
103
|
+
The delivery method information of the session.
|
|
104
|
+
"""
|
|
105
|
+
deliveryMethod: String!
|
|
106
|
+
"""
|
|
107
|
+
The delivery window information of the session.
|
|
108
|
+
"""
|
|
109
|
+
deliveryWindow: IStoreDeliveryWindow
|
|
110
|
+
}
|
|
111
|
+
|
|
51
112
|
"""
|
|
52
113
|
Session information.
|
|
53
114
|
"""
|
|
@@ -69,7 +130,11 @@ type StoreSession {
|
|
|
69
130
|
"""
|
|
70
131
|
channel: String
|
|
71
132
|
"""
|
|
72
|
-
Session
|
|
133
|
+
Session delivery mode.
|
|
134
|
+
"""
|
|
135
|
+
deliveryMode: StoreDeliveryMode
|
|
136
|
+
"""
|
|
137
|
+
Session address type.
|
|
73
138
|
"""
|
|
74
139
|
addressType: String
|
|
75
140
|
"""
|
|
@@ -107,7 +172,11 @@ input IStoreSession {
|
|
|
107
172
|
"""
|
|
108
173
|
channel: String
|
|
109
174
|
"""
|
|
110
|
-
Session input
|
|
175
|
+
Session input delivery mode.
|
|
176
|
+
"""
|
|
177
|
+
deliveryMode: IStoreDeliveryMode
|
|
178
|
+
"""
|
|
179
|
+
Session input address type.
|
|
111
180
|
"""
|
|
112
181
|
addressType: String
|
|
113
182
|
"""
|
|
@@ -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
|