@faststore/api 1.12.20 → 1.12.29

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 (32) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/__generated__/schema.d.ts +199 -0
  3. package/dist/api.cjs.development.js +156 -54
  4. package/dist/api.cjs.development.js.map +1 -1
  5. package/dist/api.cjs.production.min.js +1 -1
  6. package/dist/api.cjs.production.min.js.map +1 -1
  7. package/dist/api.esm.js +156 -54
  8. package/dist/api.esm.js.map +1 -1
  9. package/dist/index.d.ts +23 -0
  10. package/dist/platforms/vtex/clients/commerce/index.d.ts +2 -0
  11. package/dist/platforms/vtex/clients/commerce/types/Address.d.ts +16 -0
  12. package/dist/platforms/vtex/clients/commerce/types/Simulation.d.ts +2 -2
  13. package/dist/platforms/vtex/clients/index.d.ts +1 -0
  14. package/dist/platforms/vtex/index.d.ts +23 -0
  15. package/dist/platforms/vtex/loaders/index.d.ts +1 -1
  16. package/dist/platforms/vtex/loaders/simulation.d.ts +2 -2
  17. package/dist/platforms/vtex/resolvers/query.d.ts +18 -1
  18. package/dist/platforms/vtex/resolvers/shippingSLA.d.ts +14 -0
  19. package/package.json +2 -2
  20. package/src/__generated__/schema.ts +212 -0
  21. package/src/platforms/vtex/clients/commerce/index.ts +9 -0
  22. package/src/platforms/vtex/clients/commerce/types/Address.ts +17 -0
  23. package/src/platforms/vtex/clients/commerce/types/Simulation.ts +2 -2
  24. package/src/platforms/vtex/index.ts +2 -0
  25. package/src/platforms/vtex/loaders/simulation.ts +13 -6
  26. package/src/platforms/vtex/resolvers/query.ts +21 -0
  27. package/src/platforms/vtex/resolvers/shippingSLA.ts +64 -0
  28. package/src/platforms/vtex/resolvers/validateSession.ts +3 -2
  29. package/src/typeDefs/address.graphql +45 -0
  30. package/src/typeDefs/index.ts +10 -6
  31. package/src/typeDefs/query.graphql +19 -0
  32. package/src/typeDefs/shipping.graphql +304 -0
@@ -0,0 +1,64 @@
1
+ import type { Resolver } from '..'
2
+
3
+ type Unit = 'bd' | 'd' | 'h' | 'm'
4
+ const units = ['bd', 'd', 'h', 'm'] as const
5
+
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ const isUnit = (x: any): x is Unit => units.includes(x)
8
+
9
+ const localizedEstimates: Record<string, Record<string, string>> = {
10
+ bd: {
11
+ 0: 'Today',
12
+ 1: 'In 1 business day',
13
+ other: `Up to # business days`,
14
+ },
15
+ d: {
16
+ 0: 'Today',
17
+ 1: 'In 1 day',
18
+ other: 'Up to # days',
19
+ },
20
+ h: {
21
+ 0: 'Now',
22
+ 1: 'In 1 hour',
23
+ other: 'Up to # hours',
24
+ },
25
+ m: {
26
+ 0: 'Now',
27
+ 1: 'In 1 minute',
28
+ other: 'Up to # minutes',
29
+ },
30
+ }
31
+
32
+ /**
33
+ * Transforms estimate (e.g 3bd) into friendly format (e.g Up to 3 business days)
34
+ * based on https://github.com/vtex-apps/shipping-estimate-translator/blob/13e17055d6353dd3f3f4c31bae77ab049002809b/messages/en.json
35
+ */
36
+
37
+ export const getLocalizedEstimates = (estimate: string): string => {
38
+ const [amount, unit] = [estimate.split(/\D+/)[0], estimate.split(/[0-9]+/)[1]]
39
+
40
+ const isAmountNumber = amount !== '' && !Number.isNaN(Number(amount))
41
+ const isUnitValid = isUnit(unit)
42
+
43
+ if (!isAmountNumber || !isUnitValid) {
44
+ return ''
45
+ }
46
+
47
+ const amountKey = Number(amount) < 2 ? Number(amount) : 'other'
48
+
49
+ return localizedEstimates[unit][amountKey].replace('#', amount) ?? ''
50
+ }
51
+
52
+ type Root = {
53
+ name?: string
54
+ friendlyName?: string
55
+ price?: number
56
+ shippingEstimate?: string
57
+ }
58
+
59
+ export const ShippingSLA: Record<string, Resolver<Root>> = {
60
+ carrier: (root) => root?.friendlyName ?? root?.name ?? '',
61
+ price: (root) => (root?.price ? root.price / 100 : root?.price),
62
+ localizedEstimates: (root) =>
63
+ root?.shippingEstimate ? getLocalizedEstimates(root.shippingEstimate) : '',
64
+ }
@@ -17,12 +17,13 @@ export const validateSession = async (
17
17
  const country = oldSession.country ?? ''
18
18
 
19
19
  const params = new URLSearchParams(search)
20
+ const salesChannel = params.get('sc') ?? channel.salesChannel
20
21
 
21
- params.set('sc', params.get('sc') ?? channel.salesChannel)
22
+ params.set('sc', salesChannel)
22
23
 
23
24
  const [regionData, sessionData] = await Promise.all([
24
25
  postalCode
25
- ? clients.commerce.checkout.region({ postalCode, country })
26
+ ? clients.commerce.checkout.region({ postalCode, country, salesChannel })
26
27
  : Promise.resolve(null),
27
28
  clients.commerce.session(params.toString()).catch(() => null),
28
29
  ])
@@ -0,0 +1,45 @@
1
+ """
2
+ Address information.
3
+ """
4
+ type Address {
5
+ """
6
+ Address postal code
7
+ """
8
+ postalCode: String
9
+ """
10
+ Address city
11
+ """
12
+ city: String
13
+ """
14
+ Address state
15
+ """
16
+ state: String
17
+ """
18
+ Address country
19
+ """
20
+ country: String
21
+ """
22
+ Address street
23
+ """
24
+ street: String
25
+ """
26
+ Address number
27
+ """
28
+ number: String
29
+ """
30
+ Address neighborhood
31
+ """
32
+ neighborhood: String
33
+ """
34
+ Address complement
35
+ """
36
+ complement: String
37
+ """
38
+ Address reference
39
+ """
40
+ reference: String
41
+ """
42
+ Address geoCoordinates
43
+ """
44
+ geoCoordinates: [Float]
45
+ }
@@ -1,35 +1,38 @@
1
1
  import { print } from 'graphql'
2
2
 
3
+ import Address from './address.graphql'
3
4
  import AggregateOffer from './aggregateOffer.graphql'
4
5
  import AggregateRating from './aggregateRating.graphql'
5
6
  import Author from './author.graphql'
6
7
  import Brand from './brand.graphql'
7
8
  import Breadcrumb from './breadcrumb.graphql'
9
+ import Cart from './cart.graphql'
8
10
  import Collection from './collection.graphql'
9
11
  import Facet from './facet.graphql'
10
12
  import Image from './image.graphql'
11
13
  import Mutation from './mutation.graphql'
14
+ import Newsletter from './newsletter.graphql'
15
+ import ObjectOrString from './objectOrString.graphql'
12
16
  import Offer from './offer.graphql'
13
17
  import Order from './order.graphql'
14
18
  import Organization from './organization.graphql'
15
19
  import PageInfo from './pageInfo.graphql'
20
+ import Person from './person.graphql'
16
21
  import Product from './product.graphql'
17
22
  import ProductGroup from './productGroup.graphql'
23
+ import PropertyValue from './propertyValue.graphql'
18
24
  import Query from './query.graphql'
19
25
  import Review from './review.graphql'
20
26
  import Seo from './seo.graphql'
21
- import Cart from './cart.graphql'
22
- import Status from './status.graphql'
23
- import PropertyValue from './propertyValue.graphql'
24
- import Person from './person.graphql'
25
- import ObjectOrString from './objectOrString.graphql'
26
27
  import Session from './session.graphql'
27
- import Newsletter from './newsletter.graphql'
28
+ import ShippingSimulation from './shipping.graphql'
28
29
  import SkuVariants from './skuVariants.graphql'
30
+ import Status from './status.graphql'
29
31
 
30
32
  export const typeDefs = [
31
33
  Query,
32
34
  Mutation,
35
+ Address,
33
36
  Brand,
34
37
  Breadcrumb,
35
38
  Collection,
@@ -54,6 +57,7 @@ export const typeDefs = [
54
57
  Session,
55
58
  Newsletter,
56
59
  SkuVariants,
60
+ ShippingSimulation,
57
61
  ]
58
62
  .map(print)
59
63
  .join('\n')
@@ -245,4 +245,23 @@ type Query {
245
245
  after: String
246
246
  ): StoreCollectionConnection!
247
247
  @cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)
248
+
249
+ """
250
+ Returns information about shipping simulation.
251
+ """
252
+ shipping(
253
+ """
254
+ List of SKU products
255
+ """
256
+ items: [IShippingItem!]!
257
+ """
258
+ Postal code to freight calculator
259
+ """
260
+ postalCode: String!
261
+ """
262
+ Country of postal code
263
+ """
264
+ country: String!
265
+ ): ShippingData
266
+ @cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)
248
267
  }
@@ -0,0 +1,304 @@
1
+ """
2
+ Shipping Simulation item input.
3
+ """
4
+ input IShippingItem {
5
+ """
6
+ ShippingItem ID / Sku.
7
+ """
8
+ id: String!
9
+ """
10
+ Number of items.
11
+ """
12
+ quantity: Int!
13
+ """
14
+ Seller responsible for the ShippingItem.
15
+ """
16
+ seller: String!
17
+ }
18
+
19
+ """
20
+ Shipping Simulation information.
21
+ """
22
+ type ShippingData {
23
+ """
24
+ List of LogisticsItem.
25
+ """
26
+ items: [LogisticsItem]
27
+ """
28
+ List of LogisticsInfo.
29
+ """
30
+ logisticsInfo: [LogisticsInfo]
31
+ """
32
+ List of MessageInfo.
33
+ """
34
+ messages: [MessageInfo]
35
+ """
36
+ Address information.
37
+ """
38
+ address: Address
39
+ }
40
+
41
+ """
42
+ Shipping Simulation Logistic Item.
43
+ """
44
+ type LogisticsItem {
45
+ """
46
+ LogisticsItem ID / Sku.
47
+ """
48
+ id: String
49
+ requestIndex: Int
50
+ """
51
+ Number of items.
52
+ """
53
+ quantity: Int
54
+ """
55
+ Seller responsible for the ShippingItem.
56
+ """
57
+ seller: String
58
+ """
59
+ List of Sellers.
60
+ """
61
+ sellerChain: [String]
62
+ """
63
+ LogisticsItem tax.
64
+ """
65
+ tax: Int
66
+ """
67
+ Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time.
68
+ """
69
+ priceValidUntil: String
70
+ """
71
+ LogisticsItem price.
72
+ """
73
+ price: Int
74
+ """
75
+ LogisticsItem listPrice.
76
+ """
77
+ listPrice: Int
78
+ """
79
+ LogisticsItem rewardValue.
80
+ """
81
+ rewardValue: Int
82
+ """
83
+ LogisticsItem sellingPrice.
84
+ """
85
+ sellingPrice: Int
86
+ """
87
+ LogisticsItem measurementUnit.
88
+ """
89
+ measurementUnit: String
90
+ """
91
+ LogisticsItem unitMultiplier.
92
+ """
93
+ unitMultiplier: Int
94
+ """
95
+ LogisticsItem availability.
96
+ """
97
+ availability: String
98
+ }
99
+
100
+ type LogisticsInfo {
101
+ """
102
+ LogisticsInfo itemIndex.
103
+ """
104
+ itemIndex: String
105
+ """
106
+ LogisticsInfo selectedSla.
107
+ """
108
+ selectedSla: String
109
+ """
110
+ List of LogisticsInfo ShippingSLA.
111
+ """
112
+ slas: [ShippingSLA]
113
+ }
114
+
115
+ type ShippingSLA {
116
+ """
117
+ ShippingSLA id.
118
+ """
119
+ id: String
120
+ """
121
+ ShippingSLA name.
122
+ """
123
+ name: String
124
+ """
125
+ ShippingSLA price.
126
+ """
127
+ price: Float
128
+ """
129
+ ShippingSLA shipping estimate.
130
+ """
131
+ shippingEstimate: String
132
+ """
133
+ ShippingSLA localized shipping estimate.
134
+ Note: this will always return a localized string for locale `en-US`.
135
+ """
136
+ localizedEstimates: String
137
+ """
138
+ ShippingSLA shipping estimate date.
139
+ """
140
+ shippingEstimateDate: String
141
+ """
142
+ List of ShippingSLA delivery ids.
143
+ """
144
+ deliveryIds: [DeliveryIds]
145
+ """
146
+ ShippingSLA delivery channel.
147
+ """
148
+ deliveryChannel: String
149
+ """
150
+ ShippingSLA friendly name.
151
+ """
152
+ friendlyName: String
153
+ """
154
+ ShippingSLA carrier.
155
+ """
156
+ carrier: String
157
+ """
158
+ ShippingSLA pickup point id.
159
+ """
160
+ pickupPointId: String
161
+ """
162
+ ShippingSLA pickup store info.
163
+ """
164
+ pickupStoreInfo: PickupStoreInfo
165
+ """
166
+ ShippingSLA pickup distance.
167
+ """
168
+ pickupDistance: Float
169
+ }
170
+
171
+ type DeliveryIds {
172
+ """
173
+ DeliveryIds courier id
174
+ """
175
+ courierId: String
176
+ """
177
+ DeliveryIds warehouse id
178
+ """
179
+ warehouseId: String
180
+ """
181
+ DeliveryIds dock id
182
+ """
183
+ dockId: String
184
+ """
185
+ DeliveryIds courier name
186
+ """
187
+ courierName: String
188
+ """
189
+ DeliveryIds quantity
190
+ """
191
+ quantity: Int
192
+ }
193
+
194
+ type PickupStoreInfo {
195
+ """
196
+ PickupStoreInfo friendly name.
197
+ """
198
+ friendlyName: String
199
+ """
200
+ PickupStoreInfo address.
201
+ """
202
+ address: PickupAddress
203
+ """
204
+ PickupStoreInfo additional information.
205
+ """
206
+ additionalInfo: String
207
+ """
208
+ PickupStoreInfo dock id.
209
+ """
210
+ dockId: String
211
+ """
212
+ Information if the store has pickup enable.
213
+ """
214
+ isPickupStore: Boolean
215
+ }
216
+
217
+ type PickupAddress {
218
+ """
219
+ PickupAddress address type.
220
+ """
221
+ addressType: String
222
+ """
223
+ PickupAddress receiver name.
224
+ """
225
+ receiverName: String
226
+ """
227
+ PickupAddress address id.
228
+ """
229
+ addressId: String
230
+ """
231
+ PickupAddress postal code.
232
+ """
233
+ postalCode: String
234
+ """
235
+ PickupAddress city.
236
+ """
237
+ city: String
238
+ """
239
+ PickupAddress state.
240
+ """
241
+ state: String
242
+ """
243
+ PickupAddress country.
244
+ """
245
+ country: String
246
+ """
247
+ PickupAddress street.
248
+ """
249
+ street: String
250
+ """
251
+ PickupAddress number.
252
+ """
253
+ number: String
254
+ """
255
+ PickupAddress neighborhood.
256
+ """
257
+ neighborhood: String
258
+ """
259
+ PickupAddress complement.
260
+ """
261
+ complement: String
262
+ """
263
+ PickupAddress reference.
264
+ """
265
+ reference: String
266
+ """
267
+ PickupAddress geo coordinates.
268
+ """
269
+ geoCoordinates: [Float]
270
+ }
271
+
272
+ type MessageInfo {
273
+ """
274
+ MessageInfo code.
275
+ """
276
+ code: String
277
+ """
278
+ MessageInfo text.
279
+ """
280
+ text: String
281
+ """
282
+ MessageInfo status.
283
+ """
284
+ status: String
285
+ """
286
+ MessageInfo fields.
287
+ """
288
+ fields: MessageFields
289
+ }
290
+
291
+ type MessageFields {
292
+ """
293
+ MessageFields item index.
294
+ """
295
+ itemIndex: String
296
+ """
297
+ MessageFields ean.
298
+ """
299
+ ean: String
300
+ """
301
+ MessageFields sku name.
302
+ """
303
+ skuName: String
304
+ }