@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
package/dist/index.d.ts CHANGED
@@ -78,6 +78,12 @@ export declare const getResolvers: (options: Options) => {
78
78
  } & {
79
79
  attachmentsValues?: import("./platforms/vtex/clients/commerce/types/OrderForm").Attachment[] | undefined;
80
80
  }, unknown, any>>;
81
+ ShippingSLA: Record<string, import("./platforms/vtex").Resolver<{
82
+ name?: string | undefined;
83
+ friendlyName?: string | undefined;
84
+ price?: number | undefined;
85
+ shippingEstimate?: string | undefined;
86
+ }, unknown, any>>;
81
87
  ObjectOrString: import("graphql").GraphQLScalarType;
82
88
  Query: {
83
89
  product: (_: unknown, { locator }: import("./__generated__/schema").QueryProductArgs, ctx: import("./platforms/vtex").Context) => Promise<import("./platforms/vtex/utils/enhanceSku").EnhancedSku>;
@@ -128,6 +134,23 @@ export declare const getResolvers: (options: Options) => {
128
134
  cursor: string;
129
135
  }[];
130
136
  }>;
137
+ shipping: (_: unknown, { country, items, postalCode }: import("./__generated__/schema").QueryShippingArgs, ctx: import("./platforms/vtex").Context) => Promise<{
138
+ address: import("./platforms/vtex/clients/commerce/types/Address").Address;
139
+ items: import("./platforms/vtex/clients/commerce/types/Simulation").Item[];
140
+ ratesAndBenefitsData: import("./platforms/vtex/clients/commerce/types/Simulation").RatesAndBenefitsData;
141
+ paymentData: import("./platforms/vtex/clients/commerce/types/Simulation").PaymentData;
142
+ selectableGifts: any[];
143
+ marketingData: import("./platforms/vtex/clients/commerce/types/Simulation").MarketingData;
144
+ postalCode: null;
145
+ country: null;
146
+ logisticsInfo: import("./platforms/vtex/clients/commerce/types/Simulation").LogisticsInfo[];
147
+ messages: any[];
148
+ purchaseConditions: import("./platforms/vtex/clients/commerce/types/Simulation").PurchaseConditions;
149
+ pickupPoints: any[];
150
+ subscriptionData: null;
151
+ totals: import("./platforms/vtex/clients/commerce/types/Simulation").Total[];
152
+ itemMetadata: null;
153
+ }>;
131
154
  };
132
155
  Mutation: {
133
156
  validateCart: (_: unknown, { cart: { order }, session }: import("./__generated__/schema").MutationValidateCartArgs, ctx: import("./platforms/vtex").Context) => Promise<{
@@ -11,6 +11,7 @@ import type { Session } from './types/Session';
11
11
  import type { Channel } from '../../utils/channel';
12
12
  import type { SalesChannel } from './types/SalesChannel';
13
13
  import { MasterDataResponse } from './types/Newsletter';
14
+ import type { Address, AddressInput } from './types/Address';
14
15
  declare type ValueOf<T> = T extends Record<string, infer K> ? K : never;
15
16
  export declare const VtexCommerce: ({ account, environment }: Options, ctx: Context) => {
16
17
  catalog: {
@@ -56,6 +57,7 @@ export declare const VtexCommerce: ({ account, environment }: Options, ctx: Cont
56
57
  value: string;
57
58
  }) => Promise<OrderForm>;
58
59
  region: ({ postalCode, country, salesChannel, }: RegionInput) => Promise<Region>;
60
+ address: ({ postalCode, country, }: AddressInput) => Promise<Address>;
59
61
  };
60
62
  session: (search: string) => Promise<Session>;
61
63
  subscribeToNewsletter: (data: {
@@ -0,0 +1,16 @@
1
+ export interface AddressInput {
2
+ postalCode: string;
3
+ country: string;
4
+ }
5
+ export interface Address {
6
+ postalCode: string;
7
+ city: string;
8
+ state: string;
9
+ country: string;
10
+ street: string;
11
+ number: string;
12
+ neighborhood: string;
13
+ complement: string;
14
+ reference: string;
15
+ geoCoordinates: [number];
16
+ }
@@ -1,4 +1,4 @@
1
- export interface PayloadItem {
1
+ export interface ShippingItem {
2
2
  id: string;
3
3
  quantity: number;
4
4
  seller: string;
@@ -12,7 +12,7 @@ export interface ShippingData {
12
12
  }
13
13
  export interface SimulationArgs {
14
14
  country?: string;
15
- items: PayloadItem[];
15
+ items: ShippingItem[];
16
16
  postalCode?: string;
17
17
  isCheckedIn?: boolean;
18
18
  priceTables?: string[];
@@ -51,6 +51,7 @@ export declare const getClients: (options: Options, ctx: Context) => {
51
51
  value: string;
52
52
  }) => Promise<import("./commerce/types/OrderForm").OrderForm>;
53
53
  region: ({ postalCode, country, salesChannel, }: import("./commerce/types/Region").RegionInput) => Promise<import("./commerce/types/Region").Region>;
54
+ address: ({ postalCode, country, }: import("./commerce/types/Address").AddressInput) => Promise<import("./commerce/types/Address").Address>;
54
55
  };
55
56
  session: (search: string) => Promise<import("./commerce/types/Session").Session>;
56
57
  subscribeToNewsletter: (data: {
@@ -106,6 +106,12 @@ export declare const getResolvers: (_: Options) => {
106
106
  } & {
107
107
  attachmentsValues?: import("./clients/commerce/types/OrderForm").Attachment[] | undefined;
108
108
  }, unknown, any>>;
109
+ ShippingSLA: Record<string, Resolver<{
110
+ name?: string | undefined;
111
+ friendlyName?: string | undefined;
112
+ price?: number | undefined;
113
+ shippingEstimate?: string | undefined;
114
+ }, unknown, any>>;
109
115
  ObjectOrString: import("graphql").GraphQLScalarType;
110
116
  Query: {
111
117
  product: (_: unknown, { locator }: import("../..").QueryProductArgs, ctx: Context) => Promise<import("./utils/enhanceSku").EnhancedSku>;
@@ -156,6 +162,23 @@ export declare const getResolvers: (_: Options) => {
156
162
  cursor: string;
157
163
  }[];
158
164
  }>;
165
+ shipping: (_: unknown, { country, items, postalCode }: import("../..").QueryShippingArgs, ctx: Context) => Promise<{
166
+ address: import("./clients/commerce/types/Address").Address;
167
+ items: import("./clients/commerce/types/Simulation").Item[];
168
+ ratesAndBenefitsData: import("./clients/commerce/types/Simulation").RatesAndBenefitsData;
169
+ paymentData: import("./clients/commerce/types/Simulation").PaymentData;
170
+ selectableGifts: any[];
171
+ marketingData: import("./clients/commerce/types/Simulation").MarketingData;
172
+ postalCode: null;
173
+ country: null;
174
+ logisticsInfo: import("./clients/commerce/types/Simulation").LogisticsInfo[];
175
+ messages: any[];
176
+ purchaseConditions: import("./clients/commerce/types/Simulation").PurchaseConditions;
177
+ pickupPoints: any[];
178
+ subscriptionData: null;
179
+ totals: import("./clients/commerce/types/Simulation").Total[];
180
+ itemMetadata: null;
181
+ }>;
159
182
  };
160
183
  Mutation: {
161
184
  validateCart: (_: unknown, { cart: { order }, session }: import("../..").MutationValidateCartArgs, ctx: Context) => Promise<{
@@ -2,7 +2,7 @@ import type { Context, Options } from '..';
2
2
  export declare type Loaders = ReturnType<typeof getLoaders>;
3
3
  export declare const getLoaders: (options: Options, { clients }: Context) => {
4
4
  skuLoader: import("dataloader")<string, import("../utils/enhanceSku").EnhancedSku, string>;
5
- simulationLoader: import("dataloader")<import("../clients/commerce/types/Simulation").PayloadItem[], import("../clients/commerce/types/Simulation").Simulation, import("../clients/commerce/types/Simulation").PayloadItem[]>;
5
+ simulationLoader: import("dataloader")<import("../clients/commerce/types/Simulation").SimulationArgs, import("../clients/commerce/types/Simulation").Simulation, import("../clients/commerce/types/Simulation").SimulationArgs>;
6
6
  collectionLoader: import("dataloader")<string, import("../clients/commerce/types/Portal").CollectionPageType, string>;
7
7
  salesChannelLoader: import("dataloader")<string, import("../clients/commerce/types/SalesChannel").SalesChannel, string>;
8
8
  };
@@ -1,5 +1,5 @@
1
1
  import DataLoader from 'dataloader';
2
- import type { PayloadItem, Simulation } from '../clients/commerce/types/Simulation';
3
2
  import type { Options } from '..';
4
3
  import type { Clients } from '../clients';
5
- export declare const getSimulationLoader: (_: Options, clients: Clients) => DataLoader<PayloadItem[], Simulation, PayloadItem[]>;
4
+ import type { Simulation, SimulationArgs } from '../clients/commerce/types/Simulation';
5
+ export declare const getSimulationLoader: (_: Options, clients: Clients) => DataLoader<SimulationArgs, Simulation, SimulationArgs>;
@@ -1,4 +1,4 @@
1
- import type { QueryAllCollectionsArgs, QueryAllProductsArgs, QueryCollectionArgs, QueryProductArgs, QuerySearchArgs } from "../../../__generated__/schema";
1
+ import type { QueryAllCollectionsArgs, QueryAllProductsArgs, QueryCollectionArgs, QueryProductArgs, QuerySearchArgs, QueryShippingArgs } from "../../../__generated__/schema";
2
2
  import type { CategoryTree } from "../clients/commerce/types/CategoryTree";
3
3
  import type { Context } from "../index";
4
4
  export declare const Query: {
@@ -50,4 +50,21 @@ export declare const Query: {
50
50
  cursor: string;
51
51
  }[];
52
52
  }>;
53
+ shipping: (_: unknown, { country, items, postalCode }: QueryShippingArgs, ctx: Context) => Promise<{
54
+ address: import("../clients/commerce/types/Address").Address;
55
+ items: import("../clients/commerce/types/Simulation").Item[];
56
+ ratesAndBenefitsData: import("../clients/commerce/types/Simulation").RatesAndBenefitsData;
57
+ paymentData: import("../clients/commerce/types/Simulation").PaymentData;
58
+ selectableGifts: any[];
59
+ marketingData: import("../clients/commerce/types/Simulation").MarketingData;
60
+ postalCode: null;
61
+ country: null;
62
+ logisticsInfo: import("../clients/commerce/types/Simulation").LogisticsInfo[];
63
+ messages: any[];
64
+ purchaseConditions: import("../clients/commerce/types/Simulation").PurchaseConditions;
65
+ pickupPoints: any[];
66
+ subscriptionData: null;
67
+ totals: import("../clients/commerce/types/Simulation").Total[];
68
+ itemMetadata: null;
69
+ }>;
53
70
  };
@@ -0,0 +1,14 @@
1
+ import type { Resolver } from '..';
2
+ /**
3
+ * Transforms estimate (e.g 3bd) into friendly format (e.g Up to 3 business days)
4
+ * based on https://github.com/vtex-apps/shipping-estimate-translator/blob/13e17055d6353dd3f3f4c31bae77ab049002809b/messages/en.json
5
+ */
6
+ export declare const getLocalizedEstimates: (estimate: string) => string;
7
+ declare type Root = {
8
+ name?: string;
9
+ friendlyName?: string;
10
+ price?: number;
11
+ shippingEstimate?: string;
12
+ };
13
+ export declare const ShippingSLA: Record<string, Resolver<Root>>;
14
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "1.12.20",
3
+ "version": "1.12.29",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -46,5 +46,5 @@
46
46
  "peerDependencies": {
47
47
  "graphql": "^15.6.0"
48
48
  },
49
- "gitHead": "829d49bfc8d8ce7e37a0fdd9233ac68c8a3cf7b9"
49
+ "gitHead": "6027c3d8b855417e543ed9f46a97a6659b75a6eb"
50
50
  }
@@ -74,6 +74,45 @@ export type Scalars = {
74
74
  VariantsByName: any;
75
75
  };
76
76
 
77
+ /** Address information. */
78
+ export type Address = {
79
+ __typename?: 'Address';
80
+ /** Address city */
81
+ city?: Maybe<Scalars['String']>;
82
+ /** Address complement */
83
+ complement?: Maybe<Scalars['String']>;
84
+ /** Address country */
85
+ country?: Maybe<Scalars['String']>;
86
+ /** Address geoCoordinates */
87
+ geoCoordinates?: Maybe<Array<Maybe<Scalars['Float']>>>;
88
+ /** Address neighborhood */
89
+ neighborhood?: Maybe<Scalars['String']>;
90
+ /** Address number */
91
+ number?: Maybe<Scalars['String']>;
92
+ /** Address postal code */
93
+ postalCode?: Maybe<Scalars['String']>;
94
+ /** Address reference */
95
+ reference?: Maybe<Scalars['String']>;
96
+ /** Address state */
97
+ state?: Maybe<Scalars['String']>;
98
+ /** Address street */
99
+ street?: Maybe<Scalars['String']>;
100
+ };
101
+
102
+ export type DeliveryIds = {
103
+ __typename?: 'DeliveryIds';
104
+ /** DeliveryIds courier id */
105
+ courierId?: Maybe<Scalars['String']>;
106
+ /** DeliveryIds courier name */
107
+ courierName?: Maybe<Scalars['String']>;
108
+ /** DeliveryIds dock id */
109
+ dockId?: Maybe<Scalars['String']>;
110
+ /** DeliveryIds quantity */
111
+ quantity?: Maybe<Scalars['Int']>;
112
+ /** DeliveryIds warehouse id */
113
+ warehouseId?: Maybe<Scalars['String']>;
114
+ };
115
+
77
116
  /** Person data input to the newsletter. */
78
117
  export type IPersonNewsletter = {
79
118
  /** Person's email. */
@@ -82,6 +121,16 @@ export type IPersonNewsletter = {
82
121
  name: Scalars['String'];
83
122
  };
84
123
 
124
+ /** Shipping Simulation item input. */
125
+ export type IShippingItem = {
126
+ /** ShippingItem ID / Sku. */
127
+ id: Scalars['String'];
128
+ /** Number of items. */
129
+ quantity: Scalars['Int'];
130
+ /** Seller responsible for the ShippingItem. */
131
+ seller: Scalars['String'];
132
+ };
133
+
85
134
  /** Shopping cart input. */
86
135
  export type IStoreCart = {
87
136
  /** Order information, including `orderNumber` and `acceptedOffer`. */
@@ -190,6 +239,70 @@ export type IStoreSession = {
190
239
  postalCode?: Maybe<Scalars['String']>;
191
240
  };
192
241
 
242
+ export type LogisticsInfo = {
243
+ __typename?: 'LogisticsInfo';
244
+ /** LogisticsInfo itemIndex. */
245
+ itemIndex?: Maybe<Scalars['String']>;
246
+ /** LogisticsInfo selectedSla. */
247
+ selectedSla?: Maybe<Scalars['String']>;
248
+ /** List of LogisticsInfo ShippingSLA. */
249
+ slas?: Maybe<Array<Maybe<ShippingSla>>>;
250
+ };
251
+
252
+ /** Shipping Simulation Logistic Item. */
253
+ export type LogisticsItem = {
254
+ __typename?: 'LogisticsItem';
255
+ /** LogisticsItem availability. */
256
+ availability?: Maybe<Scalars['String']>;
257
+ /** LogisticsItem ID / Sku. */
258
+ id?: Maybe<Scalars['String']>;
259
+ /** LogisticsItem listPrice. */
260
+ listPrice?: Maybe<Scalars['Int']>;
261
+ /** LogisticsItem measurementUnit. */
262
+ measurementUnit?: Maybe<Scalars['String']>;
263
+ /** LogisticsItem price. */
264
+ price?: Maybe<Scalars['Int']>;
265
+ /** 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. */
266
+ priceValidUntil?: Maybe<Scalars['String']>;
267
+ /** Number of items. */
268
+ quantity?: Maybe<Scalars['Int']>;
269
+ requestIndex?: Maybe<Scalars['Int']>;
270
+ /** LogisticsItem rewardValue. */
271
+ rewardValue?: Maybe<Scalars['Int']>;
272
+ /** Seller responsible for the ShippingItem. */
273
+ seller?: Maybe<Scalars['String']>;
274
+ /** List of Sellers. */
275
+ sellerChain?: Maybe<Array<Maybe<Scalars['String']>>>;
276
+ /** LogisticsItem sellingPrice. */
277
+ sellingPrice?: Maybe<Scalars['Int']>;
278
+ /** LogisticsItem tax. */
279
+ tax?: Maybe<Scalars['Int']>;
280
+ /** LogisticsItem unitMultiplier. */
281
+ unitMultiplier?: Maybe<Scalars['Int']>;
282
+ };
283
+
284
+ export type MessageFields = {
285
+ __typename?: 'MessageFields';
286
+ /** MessageFields ean. */
287
+ ean?: Maybe<Scalars['String']>;
288
+ /** MessageFields item index. */
289
+ itemIndex?: Maybe<Scalars['String']>;
290
+ /** MessageFields sku name. */
291
+ skuName?: Maybe<Scalars['String']>;
292
+ };
293
+
294
+ export type MessageInfo = {
295
+ __typename?: 'MessageInfo';
296
+ /** MessageInfo code. */
297
+ code?: Maybe<Scalars['String']>;
298
+ /** MessageInfo fields. */
299
+ fields?: Maybe<MessageFields>;
300
+ /** MessageInfo status. */
301
+ status?: Maybe<Scalars['String']>;
302
+ /** MessageInfo text. */
303
+ text?: Maybe<Scalars['String']>;
304
+ };
305
+
193
306
  export type Mutation = {
194
307
  __typename?: 'Mutation';
195
308
  /** Subscribes a new person to the newsletter list. */
@@ -224,6 +337,50 @@ export type PersonNewsletter = {
224
337
  id: Scalars['String'];
225
338
  };
226
339
 
340
+ export type PickupAddress = {
341
+ __typename?: 'PickupAddress';
342
+ /** PickupAddress address id. */
343
+ addressId?: Maybe<Scalars['String']>;
344
+ /** PickupAddress address type. */
345
+ addressType?: Maybe<Scalars['String']>;
346
+ /** PickupAddress city. */
347
+ city?: Maybe<Scalars['String']>;
348
+ /** PickupAddress complement. */
349
+ complement?: Maybe<Scalars['String']>;
350
+ /** PickupAddress country. */
351
+ country?: Maybe<Scalars['String']>;
352
+ /** PickupAddress geo coordinates. */
353
+ geoCoordinates?: Maybe<Array<Maybe<Scalars['Float']>>>;
354
+ /** PickupAddress neighborhood. */
355
+ neighborhood?: Maybe<Scalars['String']>;
356
+ /** PickupAddress number. */
357
+ number?: Maybe<Scalars['String']>;
358
+ /** PickupAddress postal code. */
359
+ postalCode?: Maybe<Scalars['String']>;
360
+ /** PickupAddress receiver name. */
361
+ receiverName?: Maybe<Scalars['String']>;
362
+ /** PickupAddress reference. */
363
+ reference?: Maybe<Scalars['String']>;
364
+ /** PickupAddress state. */
365
+ state?: Maybe<Scalars['String']>;
366
+ /** PickupAddress street. */
367
+ street?: Maybe<Scalars['String']>;
368
+ };
369
+
370
+ export type PickupStoreInfo = {
371
+ __typename?: 'PickupStoreInfo';
372
+ /** PickupStoreInfo additional information. */
373
+ additionalInfo?: Maybe<Scalars['String']>;
374
+ /** PickupStoreInfo address. */
375
+ address?: Maybe<PickupAddress>;
376
+ /** PickupStoreInfo dock id. */
377
+ dockId?: Maybe<Scalars['String']>;
378
+ /** PickupStoreInfo friendly name. */
379
+ friendlyName?: Maybe<Scalars['String']>;
380
+ /** Information if the store has pickup enable. */
381
+ isPickupStore?: Maybe<Scalars['Boolean']>;
382
+ };
383
+
227
384
  export type Query = {
228
385
  __typename?: 'Query';
229
386
  /** Returns information about all collections. */
@@ -236,6 +393,8 @@ export type Query = {
236
393
  product: StoreProduct;
237
394
  /** Returns the result of a product, facet, or suggestion search. */
238
395
  search: StoreSearchResult;
396
+ /** Returns information about shipping simulation. */
397
+ shipping?: Maybe<ShippingData>;
239
398
  };
240
399
 
241
400
 
@@ -269,6 +428,59 @@ export type QuerySearchArgs = {
269
428
  term?: Maybe<Scalars['String']>;
270
429
  };
271
430
 
431
+
432
+ export type QueryShippingArgs = {
433
+ country: Scalars['String'];
434
+ items: Array<IShippingItem>;
435
+ postalCode: Scalars['String'];
436
+ };
437
+
438
+ /** Shipping Simulation information. */
439
+ export type ShippingData = {
440
+ __typename?: 'ShippingData';
441
+ /** Address information. */
442
+ address?: Maybe<Address>;
443
+ /** List of LogisticsItem. */
444
+ items?: Maybe<Array<Maybe<LogisticsItem>>>;
445
+ /** List of LogisticsInfo. */
446
+ logisticsInfo?: Maybe<Array<Maybe<LogisticsInfo>>>;
447
+ /** List of MessageInfo. */
448
+ messages?: Maybe<Array<Maybe<MessageInfo>>>;
449
+ };
450
+
451
+ export type ShippingSla = {
452
+ __typename?: 'ShippingSLA';
453
+ /** ShippingSLA carrier. */
454
+ carrier?: Maybe<Scalars['String']>;
455
+ /** ShippingSLA delivery channel. */
456
+ deliveryChannel?: Maybe<Scalars['String']>;
457
+ /** List of ShippingSLA delivery ids. */
458
+ deliveryIds?: Maybe<Array<Maybe<DeliveryIds>>>;
459
+ /** ShippingSLA friendly name. */
460
+ friendlyName?: Maybe<Scalars['String']>;
461
+ /** ShippingSLA id. */
462
+ id?: Maybe<Scalars['String']>;
463
+ /**
464
+ * ShippingSLA localized shipping estimate.
465
+ * Note: this will always return a localized string for locale `en-US`.
466
+ */
467
+ localizedEstimates?: Maybe<Scalars['String']>;
468
+ /** ShippingSLA name. */
469
+ name?: Maybe<Scalars['String']>;
470
+ /** ShippingSLA pickup distance. */
471
+ pickupDistance?: Maybe<Scalars['Float']>;
472
+ /** ShippingSLA pickup point id. */
473
+ pickupPointId?: Maybe<Scalars['String']>;
474
+ /** ShippingSLA pickup store info. */
475
+ pickupStoreInfo?: Maybe<PickupStoreInfo>;
476
+ /** ShippingSLA price. */
477
+ price?: Maybe<Scalars['Float']>;
478
+ /** ShippingSLA shipping estimate. */
479
+ shippingEstimate?: Maybe<Scalars['String']>;
480
+ /** ShippingSLA shipping estimate date. */
481
+ shippingEstimateDate?: Maybe<Scalars['String']>;
482
+ };
483
+
272
484
  export type SkuVariants = {
273
485
  __typename?: 'SkuVariants';
274
486
  /** SKU property values for the current SKU. */
@@ -17,6 +17,7 @@ import type { Session } from './types/Session'
17
17
  import type { Channel } from '../../utils/channel'
18
18
  import type { SalesChannel } from './types/SalesChannel'
19
19
  import { MasterDataResponse } from './types/Newsletter'
20
+ import type { Address, AddressInput } from './types/Address'
20
21
 
21
22
  type ValueOf<T> = T extends Record<string, infer K> ? K : never
22
23
 
@@ -172,6 +173,14 @@ export const VtexCommerce = (
172
173
  }`
173
174
  )
174
175
  },
176
+ address: async ({
177
+ postalCode,
178
+ country,
179
+ }: AddressInput): Promise<Address> => {
180
+ return fetchAPI(
181
+ `${base}/api/checkout/pub/postal-code/${country}/${postalCode}`
182
+ )
183
+ },
175
184
  },
176
185
  session: (search: string): Promise<Session> => {
177
186
  const params = new URLSearchParams(search)
@@ -0,0 +1,17 @@
1
+ export interface AddressInput {
2
+ postalCode: string
3
+ country: string
4
+ }
5
+
6
+ export interface Address {
7
+ postalCode: string
8
+ city: string
9
+ state: string
10
+ country: string
11
+ street: string
12
+ number: string
13
+ neighborhood: string
14
+ complement: string
15
+ reference: string
16
+ geoCoordinates: [number]
17
+ }
@@ -1,4 +1,4 @@
1
- export interface PayloadItem {
1
+ export interface ShippingItem {
2
2
  id: string
3
3
  quantity: number
4
4
  seller: string
@@ -12,7 +12,7 @@ export interface ShippingData {
12
12
 
13
13
  export interface SimulationArgs {
14
14
  country?: string
15
- items: PayloadItem[]
15
+ items: ShippingItem[]
16
16
  postalCode?: string
17
17
  isCheckedIn?: boolean
18
18
  priceTables?: string[]
@@ -19,6 +19,7 @@ import { Query } from './resolvers/query'
19
19
  import { StoreReview } from './resolvers/review'
20
20
  import { StoreSearchResult } from './resolvers/searchResult'
21
21
  import { StoreSeo } from './resolvers/seo'
22
+ import { ShippingSLA } from './resolvers/shippingSLA'
22
23
  import { SkuVariants } from './resolvers/skuVariations'
23
24
  import ChannelMarshal from './utils/channel'
24
25
  import type { Loaders } from './loaders'
@@ -82,6 +83,7 @@ const Resolvers = {
82
83
  StoreSearchResult,
83
84
  StorePropertyValue,
84
85
  SkuVariants,
86
+ ShippingSLA,
85
87
  ObjectOrString,
86
88
  Query,
87
89
  Mutation,
@@ -1,12 +1,13 @@
1
1
  import DataLoader from 'dataloader'
2
2
  import pLimit from 'p-limit'
3
3
 
4
+ import type { Options } from '..'
5
+ import type { Clients } from '../clients'
4
6
  import type {
5
- PayloadItem,
7
+ ShippingItem,
6
8
  Simulation,
9
+ SimulationArgs,
7
10
  } from '../clients/commerce/types/Simulation'
8
- import type { Options } from '..'
9
- import type { Clients } from '../clients'
10
11
 
11
12
  // Limits concurrent requests to the API per request cycle
12
13
  const CONCURRENT_REQUESTS_MAX = 1
@@ -14,9 +15,15 @@ const CONCURRENT_REQUESTS_MAX = 1
14
15
  export const getSimulationLoader = (_: Options, clients: Clients) => {
15
16
  const limit = pLimit(CONCURRENT_REQUESTS_MAX)
16
17
 
17
- const loader = async (allItems: readonly PayloadItem[][]) => {
18
+ const loader = async (simulationArgs: readonly SimulationArgs[]) => {
19
+ const allItems = simulationArgs.reduce((acc, { items }: SimulationArgs) => {
20
+ return [...acc, items]
21
+ }, [] as ShippingItem[][])
22
+
18
23
  const items = [...allItems.flat()]
19
24
  const simulation = await clients.commerce.checkout.simulation({
25
+ country: simulationArgs[0].country,
26
+ postalCode: simulationArgs[0].postalCode,
20
27
  items,
21
28
  })
22
29
 
@@ -45,10 +52,10 @@ export const getSimulationLoader = (_: Options, clients: Clients) => {
45
52
  }))
46
53
  }
47
54
 
48
- const limited = async (allItems: readonly PayloadItem[][]) =>
55
+ const limited = async (allItems: readonly SimulationArgs[]) =>
49
56
  limit(loader, allItems)
50
57
 
51
- return new DataLoader<PayloadItem[], Simulation>(limited, {
58
+ return new DataLoader<SimulationArgs, Simulation>(limited, {
52
59
  maxBatchSize: 50,
53
60
  })
54
61
  }
@@ -18,6 +18,7 @@ import type {
18
18
  QueryCollectionArgs,
19
19
  QueryProductArgs,
20
20
  QuerySearchArgs,
21
+ QueryShippingArgs,
21
22
  } from "../../../__generated__/schema"
22
23
  import type { CategoryTree } from "../clients/commerce/types/CategoryTree"
23
24
  import type { Context } from "../index"
@@ -249,4 +250,24 @@ export const Query = {
249
250
  })),
250
251
  }
251
252
  },
253
+ shipping: async (
254
+ _: unknown,
255
+ { country, items, postalCode }: QueryShippingArgs,
256
+ ctx: Context
257
+ ) => {
258
+ const {
259
+ loaders: { simulationLoader },
260
+ clients: { commerce },
261
+ } = ctx
262
+
263
+ const [simulation, address] = await Promise.all([
264
+ simulationLoader.load({ country, items, postalCode }),
265
+ commerce.checkout.address({ postalCode, country }),
266
+ ])
267
+
268
+ return {
269
+ ...simulation,
270
+ address,
271
+ }
272
+ },
252
273
  }