@faststore/api 1.6.15 → 1.6.18
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/CHANGELOG.md +30 -0
- package/dist/__generated__/schema.d.ts +15 -0
- package/dist/api.cjs.development.js +76 -8
- 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 +76 -8
- package/dist/api.esm.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/platforms/vtex/clients/commerce/index.d.ts +2 -0
- package/dist/platforms/vtex/clients/commerce/types/Region.d.ts +8 -0
- package/dist/platforms/vtex/clients/index.d.ts +1 -0
- package/dist/platforms/vtex/index.d.ts +3 -2
- package/dist/platforms/vtex/resolvers/aggregateOffer.d.ts +1 -0
- package/dist/platforms/vtex/resolvers/mutation.d.ts +1 -0
- package/dist/platforms/vtex/resolvers/updateSession.d.ts +3 -0
- package/dist/platforms/vtex/utils/channel.d.ts +8 -0
- package/dist/typings/index.d.ts +1 -0
- package/package.json +2 -2
- package/src/__generated__/schema.ts +19 -0
- package/src/index.ts +1 -1
- package/src/platforms/vtex/clients/commerce/index.ts +12 -0
- package/src/platforms/vtex/clients/commerce/types/Region.ts +7 -0
- package/src/platforms/vtex/resolvers/aggregateOffer.ts +31 -10
- package/src/platforms/vtex/resolvers/mutation.ts +2 -0
- package/src/platforms/vtex/resolvers/product.ts +7 -2
- package/src/platforms/vtex/resolvers/updateSession.ts +26 -0
- package/src/platforms/vtex/utils/channel.ts +25 -0
- package/src/typeDefs/mutation.graphql +14 -0
- package/src/typings/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,36 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 1.6.18 (2022-03-24)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **api:** Add session mutation ([#1176](https://github.com/vtex/faststore/issues/1176)) ([0306167](https://github.com/vtex/faststore/commit/030616739cc62d9b5aa55cdf532ee6dea0bd793c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## 1.6.17 (2022-03-23)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **UI:** Add dropdown component ([#1178](https://github.com/vtex/faststore/issues/1178)) ([e5153a6](https://github.com/vtex/faststore/commit/e5153a674c37bd2a8b4c65ae6f56eb5cabaf3fc8))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## 1.6.16 (2022-03-23)
|
|
29
|
+
|
|
30
|
+
**Note:** Version bump only for package @faststore/api
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
6
36
|
## 1.6.15 (2022-03-22)
|
|
7
37
|
|
|
8
38
|
|
|
@@ -48,10 +48,19 @@ export declare type IStoreSelectedFacet = {
|
|
|
48
48
|
key: Scalars['String'];
|
|
49
49
|
value: Scalars['String'];
|
|
50
50
|
};
|
|
51
|
+
export declare type IStoreSession = {
|
|
52
|
+
channel?: Maybe<Scalars['String']>;
|
|
53
|
+
country?: Maybe<Scalars['String']>;
|
|
54
|
+
postalCode?: Maybe<Scalars['String']>;
|
|
55
|
+
};
|
|
51
56
|
export declare type Mutation = {
|
|
52
57
|
__typename?: 'Mutation';
|
|
58
|
+
updateSession: StoreSession;
|
|
53
59
|
validateCart?: Maybe<StoreCart>;
|
|
54
60
|
};
|
|
61
|
+
export declare type MutationUpdateSessionArgs = {
|
|
62
|
+
session: IStoreSession;
|
|
63
|
+
};
|
|
55
64
|
export declare type MutationValidateCartArgs = {
|
|
56
65
|
cart: IStoreCart;
|
|
57
66
|
};
|
|
@@ -283,6 +292,12 @@ export declare type StoreSeo = {
|
|
|
283
292
|
title: Scalars['String'];
|
|
284
293
|
titleTemplate: Scalars['String'];
|
|
285
294
|
};
|
|
295
|
+
export declare type StoreSession = {
|
|
296
|
+
__typename?: 'StoreSession';
|
|
297
|
+
channel?: Maybe<Scalars['String']>;
|
|
298
|
+
country?: Maybe<Scalars['String']>;
|
|
299
|
+
postalCode?: Maybe<Scalars['String']>;
|
|
300
|
+
};
|
|
286
301
|
export declare const enum StoreSort {
|
|
287
302
|
DiscountDesc = "discount_desc",
|
|
288
303
|
NameAsc = "name_asc",
|
|
@@ -87,6 +87,13 @@ const VtexCommerce = ({
|
|
|
87
87
|
}),
|
|
88
88
|
method: 'PATCH'
|
|
89
89
|
});
|
|
90
|
+
},
|
|
91
|
+
region: async ({
|
|
92
|
+
postalCode,
|
|
93
|
+
country,
|
|
94
|
+
salesChannel
|
|
95
|
+
}) => {
|
|
96
|
+
return fetchAPI(`${base}/api/checkout/pub/regions/?postalCode=${postalCode}&country=${country}&sc=${salesChannel != null ? salesChannel : ''}`);
|
|
90
97
|
}
|
|
91
98
|
},
|
|
92
99
|
session: () => fetchAPI(`${base}/api/sessions?items=profile.id,profile.email,profile.firstName,profile.lastName`, {
|
|
@@ -305,20 +312,38 @@ const getLoaders = (options, {
|
|
|
305
312
|
};
|
|
306
313
|
};
|
|
307
314
|
|
|
315
|
+
const inStock = item => item.availability === 'available'; // Smallest Available Selling Price First
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
const sortOfferByPrice = items => items.sort((a, b) => {
|
|
319
|
+
if (inStock(a) && !inStock(b)) {
|
|
320
|
+
return -1;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (!inStock(a) && inStock(b)) {
|
|
324
|
+
return 1;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return a.sellingPrice - b.sellingPrice;
|
|
328
|
+
});
|
|
308
329
|
const StoreAggregateOffer = {
|
|
309
330
|
highPrice: ({
|
|
310
331
|
items
|
|
311
332
|
}) => {
|
|
312
|
-
var
|
|
333
|
+
var _availableItems$pop;
|
|
313
334
|
|
|
314
|
-
|
|
335
|
+
const availableItems = items.filter(inStock);
|
|
336
|
+
const highPrice = (_availableItems$pop = availableItems.pop()) == null ? void 0 : _availableItems$pop.sellingPrice;
|
|
337
|
+
return (highPrice != null ? highPrice : 0) / 1e2;
|
|
315
338
|
},
|
|
316
339
|
lowPrice: ({
|
|
317
340
|
items
|
|
318
341
|
}) => {
|
|
319
|
-
var
|
|
342
|
+
var _availableItems$;
|
|
320
343
|
|
|
321
|
-
|
|
344
|
+
const availableItems = items.filter(inStock);
|
|
345
|
+
const lowPrice = (_availableItems$ = availableItems[0]) == null ? void 0 : _availableItems$.sellingPrice;
|
|
346
|
+
return (lowPrice != null ? lowPrice : 0) / 1e2;
|
|
322
347
|
},
|
|
323
348
|
offerCount: ({
|
|
324
349
|
items
|
|
@@ -590,8 +615,50 @@ const validateCart = async (_, {
|
|
|
590
615
|
};
|
|
591
616
|
};
|
|
592
617
|
|
|
618
|
+
class ChannelMarshal {
|
|
619
|
+
static parse(channelString) {
|
|
620
|
+
try {
|
|
621
|
+
var _parsedChannel$region, _parsedChannel$salesC;
|
|
622
|
+
|
|
623
|
+
const parsedChannel = JSON.parse(channelString);
|
|
624
|
+
return {
|
|
625
|
+
regionId: (_parsedChannel$region = parsedChannel.regionId) != null ? _parsedChannel$region : '',
|
|
626
|
+
salesChannel: (_parsedChannel$salesC = parsedChannel.salesChannel) != null ? _parsedChannel$salesC : ''
|
|
627
|
+
};
|
|
628
|
+
} catch (error) {
|
|
629
|
+
console.error(error);
|
|
630
|
+
throw new Error('Malformed channel string');
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
static stringify(channel) {
|
|
635
|
+
return JSON.stringify(channel);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
const updateSession = async (_, {
|
|
641
|
+
session
|
|
642
|
+
}, {
|
|
643
|
+
clients
|
|
644
|
+
}) => {
|
|
645
|
+
var _session$channel, _session$postalCode, _session$country, _regionData$;
|
|
646
|
+
|
|
647
|
+
const channel = ChannelMarshal.parse((_session$channel = session.channel) != null ? _session$channel : '');
|
|
648
|
+
const regionData = await clients.commerce.checkout.region({
|
|
649
|
+
postalCode: String((_session$postalCode = session.postalCode) != null ? _session$postalCode : '').replace(/\D/g, ''),
|
|
650
|
+
country: (_session$country = session.country) != null ? _session$country : ''
|
|
651
|
+
});
|
|
652
|
+
return { ...session,
|
|
653
|
+
channel: ChannelMarshal.stringify({ ...channel,
|
|
654
|
+
regionId: regionData == null ? void 0 : (_regionData$ = regionData[0]) == null ? void 0 : _regionData$.id
|
|
655
|
+
})
|
|
656
|
+
};
|
|
657
|
+
};
|
|
658
|
+
|
|
593
659
|
const Mutation = {
|
|
594
|
-
validateCart
|
|
660
|
+
validateCart,
|
|
661
|
+
updateSession
|
|
595
662
|
};
|
|
596
663
|
|
|
597
664
|
const StoreOffer = {
|
|
@@ -746,6 +813,7 @@ const StoreProduct = {
|
|
|
746
813
|
}));
|
|
747
814
|
const simulation = await simulationLoader.load(items);
|
|
748
815
|
return { ...simulation,
|
|
816
|
+
items: sortOfferByPrice(simulation.items),
|
|
749
817
|
product
|
|
750
818
|
};
|
|
751
819
|
},
|
|
@@ -1091,8 +1159,8 @@ var doc$6 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","na
|
|
|
1091
1159
|
var doc$7 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","name":{"kind":"Name","value":"StoreImage"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","name":{"kind":"Name","value":"url"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"alternateName"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]},{"kind":"InputObjectTypeDefinition","name":{"kind":"Name","value":"IStoreImage"},"directives":[],"fields":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"url"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"alternateName"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]}],"loc":{"start":0,"end":123}};
|
|
1092
1160
|
doc$7.loc.source = {"body":"type StoreImage {\n url: String!\n alternateName: String!\n}\n\ninput IStoreImage {\n url: String!\n alternateName: String!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
|
|
1093
1161
|
|
|
1094
|
-
var doc$8 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","name":{"kind":"Name","value":"Mutation"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","name":{"kind":"Name","value":"validateCart"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"cart"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreCart"}}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreCart"}},"directives":[]}]}],"loc":{"start":0,"end":
|
|
1095
|
-
doc$8.loc.source = {"body":"type Mutation {\n # Returns the order if anything changed with the order. Null if the order is valid\n validateCart(cart: IStoreCart!): StoreCart\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
|
|
1162
|
+
var doc$8 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","name":{"kind":"Name","value":"StoreSession"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","name":{"kind":"Name","value":"channel"},"arguments":[],"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"country"},"arguments":[],"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"postalCode"},"arguments":[],"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}},"directives":[]}]},{"kind":"InputObjectTypeDefinition","name":{"kind":"Name","value":"IStoreSession"},"directives":[],"fields":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"channel"},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"country"},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"postalCode"},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}},"directives":[]}]},{"kind":"ObjectTypeDefinition","name":{"kind":"Name","value":"Mutation"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","name":{"kind":"Name","value":"validateCart"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"cart"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreCart"}}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreCart"}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"updateSession"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"session"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreSession"}}},"directives":[]}],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreSession"}}},"directives":[]}]}],"loc":{"start":0,"end":367}};
|
|
1163
|
+
doc$8.loc.source = {"body":"type StoreSession {\n channel: String\n country: String\n postalCode: String\n}\n\ninput IStoreSession {\n channel: String\n country: String\n postalCode: String\n}\n\ntype Mutation {\n # Returns the order if anything changed with the order. Null if the order is valid\n validateCart(cart: IStoreCart!): StoreCart\n\n updateSession(session: IStoreSession!): StoreSession!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
|
|
1096
1164
|
|
|
1097
1165
|
var doc$9 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","name":{"kind":"Name","value":"StoreOffer"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","name":{"kind":"Name","value":"listPrice"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"sellingPrice"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"priceCurrency"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"price"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"priceValidUntil"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"itemCondition"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"availability"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"seller"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreOrganization"}}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"itemOffered"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreProduct"}}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"quantity"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},"directives":[]}]},{"kind":"InputObjectTypeDefinition","name":{"kind":"Name","value":"IStoreOffer"},"directives":[],"fields":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"price"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"listPrice"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"seller"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreOrganization"}}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"itemOffered"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreProduct"}}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"quantity"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},"directives":[]}]}],"loc":{"start":0,"end":419}};
|
|
1098
1166
|
doc$9.loc.source = {"body":"type StoreOffer {\n listPrice: Float!\n sellingPrice: Float!\n priceCurrency: String!\n # Also known as spotPrice\n price: Float!\n priceValidUntil: String!\n itemCondition: String!\n availability: String!\n seller: StoreOrganization!\n itemOffered: StoreProduct!\n quantity: Int!\n}\n\ninput IStoreOffer {\n price: Float!\n listPrice: Float!\n seller: IStoreOrganization!\n itemOffered: IStoreProduct!\n quantity: Int!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
|
|
@@ -1143,7 +1211,7 @@ const getResolvers$1 = options => platforms[options.platform].getResolvers(optio
|
|
|
1143
1211
|
const getContextFactory$1 = options => platforms[options.platform].getContextFactory(options);
|
|
1144
1212
|
const getSchema = async options => schema.makeExecutableSchema({
|
|
1145
1213
|
resolvers: getResolvers$1(options),
|
|
1146
|
-
typeDefs
|
|
1214
|
+
typeDefs
|
|
1147
1215
|
});
|
|
1148
1216
|
|
|
1149
1217
|
exports.getContextFactory = getContextFactory$1;
|