@faststore/api 1.9.9 → 1.9.11
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 +11 -0
- package/dist/__generated__/schema.d.ts +23 -8
- package/dist/api.cjs.development.js +254 -194
- 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 +254 -194
- package/dist/api.esm.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/platforms/vtex/clients/search/index.d.ts +2 -1
- package/dist/platforms/vtex/clients/search/types/FacetSearchResult.d.ts +8 -8
- package/dist/platforms/vtex/index.d.ts +7 -3
- package/dist/platforms/vtex/resolvers/faceValue.d.ts +3 -0
- package/dist/platforms/vtex/resolvers/facet.d.ts +3 -1
- package/dist/platforms/vtex/utils/facets.d.ts +1 -0
- package/package.json +2 -2
- package/src/__generated__/schema.ts +26 -8
- package/src/platforms/vtex/clients/search/index.ts +9 -1
- package/src/platforms/vtex/clients/search/types/FacetSearchResult.ts +9 -8
- package/src/platforms/vtex/index.ts +14 -6
- package/src/platforms/vtex/resolvers/faceValue.ts +12 -0
- package/src/platforms/vtex/resolvers/facet.ts +66 -5
- package/src/platforms/vtex/resolvers/offer.ts +1 -1
- package/src/platforms/vtex/resolvers/searchResult.ts +9 -26
- package/src/platforms/vtex/utils/facets.ts +18 -0
- package/src/typeDefs/facet.graphql +28 -6
- package/dist/platforms/vtex/resolvers/facetValue.d.ts +0 -5
- package/src/platforms/vtex/resolvers/facetValue.ts +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.9.11](https://github.com/vtex/faststore/compare/v1.9.10...v1.9.11) (2022-06-19)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Price range filter on PLP ([#1364](https://github.com/vtex/faststore/issues/1364)) ([a4c3fa7](https://github.com/vtex/faststore/commit/a4c3fa79c32d1db7bc737f5221479e6db1488866))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## 1.9.9 (2022-06-17)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -287,17 +287,27 @@ export declare type StoreCurrency = {
|
|
|
287
287
|
/** Currency symbol (e.g: $). */
|
|
288
288
|
symbol: Scalars['String'];
|
|
289
289
|
};
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
290
|
+
export declare type StoreFacet = StoreFacetBoolean | StoreFacetRange;
|
|
291
|
+
/** Search facet boolean information. */
|
|
292
|
+
export declare type StoreFacetBoolean = {
|
|
293
|
+
__typename?: 'StoreFacetBoolean';
|
|
293
294
|
/** Facet key. */
|
|
294
295
|
key: Scalars['String'];
|
|
295
296
|
/** Facet label. */
|
|
296
297
|
label: Scalars['String'];
|
|
297
|
-
/** Facet type. Possible values are `BOOLEAN` and `RANGE`. */
|
|
298
|
-
type: StoreFacetType;
|
|
299
298
|
/** Array with information on each facet value. */
|
|
300
|
-
values: Array<
|
|
299
|
+
values: Array<StoreFacetValueBoolean>;
|
|
300
|
+
};
|
|
301
|
+
/** Search facet range information. */
|
|
302
|
+
export declare type StoreFacetRange = {
|
|
303
|
+
__typename?: 'StoreFacetRange';
|
|
304
|
+
/** Facet key. */
|
|
305
|
+
key: Scalars['String'];
|
|
306
|
+
/** Facet label. */
|
|
307
|
+
label: Scalars['String'];
|
|
308
|
+
max: StoreFacetValueRange;
|
|
309
|
+
/** Array with information on each facet value. */
|
|
310
|
+
min: StoreFacetValueRange;
|
|
301
311
|
};
|
|
302
312
|
/** Search facet type. */
|
|
303
313
|
export declare const enum StoreFacetType {
|
|
@@ -307,8 +317,8 @@ export declare const enum StoreFacetType {
|
|
|
307
317
|
Range = "RANGE"
|
|
308
318
|
}
|
|
309
319
|
/** Information of a specific facet value. */
|
|
310
|
-
export declare type
|
|
311
|
-
__typename?: '
|
|
320
|
+
export declare type StoreFacetValueBoolean = {
|
|
321
|
+
__typename?: 'StoreFacetValueBoolean';
|
|
312
322
|
/** Facet value label. */
|
|
313
323
|
label: Scalars['String'];
|
|
314
324
|
/** Number of items with this facet. */
|
|
@@ -318,6 +328,11 @@ export declare type StoreFacetValue = {
|
|
|
318
328
|
/** Facet value. */
|
|
319
329
|
value: Scalars['String'];
|
|
320
330
|
};
|
|
331
|
+
export declare type StoreFacetValueRange = {
|
|
332
|
+
__typename?: 'StoreFacetValueRange';
|
|
333
|
+
absolute: Scalars['Float'];
|
|
334
|
+
selected: Scalars['Float'];
|
|
335
|
+
};
|
|
321
336
|
/** Image. */
|
|
322
337
|
export declare type StoreImage = {
|
|
323
338
|
__typename?: 'StoreImage';
|
|
@@ -621,30 +621,199 @@ const StoreCollection = {
|
|
|
621
621
|
}
|
|
622
622
|
};
|
|
623
623
|
|
|
624
|
+
class ChannelMarshal {
|
|
625
|
+
static parse(channelString) {
|
|
626
|
+
try {
|
|
627
|
+
var _parsedChannel$region, _parsedChannel$salesC;
|
|
628
|
+
|
|
629
|
+
const parsedChannel = JSON.parse(channelString);
|
|
630
|
+
return {
|
|
631
|
+
regionId: (_parsedChannel$region = parsedChannel.regionId) != null ? _parsedChannel$region : '',
|
|
632
|
+
salesChannel: (_parsedChannel$salesC = parsedChannel.salesChannel) != null ? _parsedChannel$salesC : ''
|
|
633
|
+
};
|
|
634
|
+
} catch (error) {
|
|
635
|
+
console.error(error);
|
|
636
|
+
throw new Error('Malformed channel string');
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
static stringify(channel) {
|
|
641
|
+
return JSON.stringify(channel);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Transform facets from the store to VTEX platform facets.
|
|
648
|
+
* For instance, the channel in Store becomes trade-policy and regionId in VTEX's realm
|
|
649
|
+
* */
|
|
650
|
+
|
|
651
|
+
const transformSelectedFacet = ({
|
|
652
|
+
key,
|
|
653
|
+
value
|
|
654
|
+
}) => {
|
|
655
|
+
switch (key) {
|
|
656
|
+
case 'channel':
|
|
657
|
+
{
|
|
658
|
+
const channel = ChannelMarshal.parse(value);
|
|
659
|
+
const channelFacets = [{
|
|
660
|
+
key: 'trade-policy',
|
|
661
|
+
value: channel.salesChannel
|
|
662
|
+
}];
|
|
663
|
+
|
|
664
|
+
if (channel.regionId) {
|
|
665
|
+
channelFacets.push({
|
|
666
|
+
key: 'region-id',
|
|
667
|
+
value: channel.regionId
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
return channelFacets;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
case 'locale':
|
|
675
|
+
{
|
|
676
|
+
return []; // remove this facet from search
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
case 'price':
|
|
680
|
+
{
|
|
681
|
+
return {
|
|
682
|
+
key,
|
|
683
|
+
value: value.replace('-to-', ':')
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
default:
|
|
688
|
+
return {
|
|
689
|
+
key,
|
|
690
|
+
value
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
const parseRange = range => {
|
|
695
|
+
const splitted = range.split(':').map(Number);
|
|
696
|
+
|
|
697
|
+
if (splitted.length !== 2 || Number.isNaN(splitted[0]) || Number.isNaN(splitted[1])) {
|
|
698
|
+
return null;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
return splitted;
|
|
702
|
+
};
|
|
703
|
+
const findSlug = facets => {
|
|
704
|
+
var _facets$find$value, _facets$find;
|
|
705
|
+
|
|
706
|
+
return (_facets$find$value = facets == null ? void 0 : (_facets$find = facets.find(x => x.key === 'slug')) == null ? void 0 : _facets$find.value) != null ? _facets$find$value : null;
|
|
707
|
+
};
|
|
708
|
+
const findSkuId = facets => {
|
|
709
|
+
var _facets$find$value2, _facets$find2;
|
|
710
|
+
|
|
711
|
+
return (_facets$find$value2 = facets == null ? void 0 : (_facets$find2 = facets.find(x => x.key === 'id')) == null ? void 0 : _facets$find2.value) != null ? _facets$find$value2 : null;
|
|
712
|
+
};
|
|
713
|
+
const findLocale = facets => {
|
|
714
|
+
var _facets$find$value3, _facets$find3;
|
|
715
|
+
|
|
716
|
+
return (_facets$find$value3 = facets == null ? void 0 : (_facets$find3 = facets.find(x => x.key === 'locale')) == null ? void 0 : _facets$find3.value) != null ? _facets$find$value3 : null;
|
|
717
|
+
};
|
|
718
|
+
const findChannel = facets => {
|
|
719
|
+
var _facets$find$value4, _facets$find4;
|
|
720
|
+
|
|
721
|
+
return (_facets$find$value4 = facets == null ? void 0 : (_facets$find4 = facets.find(facet => facet.key === 'channel')) == null ? void 0 : _facets$find4.value) != null ? _facets$find$value4 : null;
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* More info at: https://en.wikipedia.org/wiki/Order_statistic
|
|
726
|
+
*/
|
|
727
|
+
// O(n) search to find the max of an array
|
|
728
|
+
const min = (array, cmp) => {
|
|
729
|
+
let best = 0;
|
|
730
|
+
|
|
731
|
+
for (let curr = 1; curr < array.length; curr++) {
|
|
732
|
+
if (cmp(array[best], array[curr]) > 0) {
|
|
733
|
+
best = curr;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
return array[best];
|
|
738
|
+
};
|
|
739
|
+
|
|
624
740
|
const StoreFacet = {
|
|
741
|
+
__resolveType: ({
|
|
742
|
+
type
|
|
743
|
+
}) => type === 'TEXT' ? 'StoreFacetBoolean' : 'StoreFacetRange'
|
|
744
|
+
};
|
|
745
|
+
const StoreFacetBoolean = {
|
|
625
746
|
key: ({
|
|
626
747
|
key
|
|
627
|
-
}) => key
|
|
748
|
+
}) => key,
|
|
628
749
|
label: ({
|
|
629
750
|
name
|
|
630
|
-
}) => name
|
|
751
|
+
}) => name,
|
|
631
752
|
values: ({
|
|
632
753
|
values
|
|
633
|
-
}) => values,
|
|
634
|
-
type: ({
|
|
635
|
-
type
|
|
636
|
-
}) => type === 'TEXT' ? 'BOOLEAN' : 'RANGE'
|
|
754
|
+
}) => values.sort((a, b) => a.name.localeCompare(b.name))
|
|
637
755
|
};
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
756
|
+
const StoreFacetRange = {
|
|
757
|
+
key: ({
|
|
758
|
+
key
|
|
759
|
+
}) => key,
|
|
760
|
+
label: ({
|
|
761
|
+
name
|
|
762
|
+
}) => name,
|
|
763
|
+
min: ({
|
|
764
|
+
values,
|
|
765
|
+
key
|
|
766
|
+
}, _, {
|
|
767
|
+
storage: {
|
|
768
|
+
searchArgs
|
|
769
|
+
}
|
|
643
770
|
}) => {
|
|
644
|
-
var
|
|
771
|
+
var _searchArgs$selectedF, _searchArgs$selectedF2, _searchArgs$selectedF3, _facet$range$from, _selectedRange$;
|
|
645
772
|
|
|
646
|
-
|
|
773
|
+
/**
|
|
774
|
+
* Fetch the selected range the user queried.
|
|
775
|
+
*
|
|
776
|
+
* This is necessary because, differently from boolean facets, Search API does
|
|
777
|
+
* not return the selected values, making us have to implement it in here
|
|
778
|
+
*/
|
|
779
|
+
const selectedRange = parseRange((_searchArgs$selectedF = searchArgs == null ? void 0 : (_searchArgs$selectedF2 = searchArgs.selectedFacets) == null ? void 0 : (_searchArgs$selectedF3 = _searchArgs$selectedF2.find(facet => facet.key === key)) == null ? void 0 : _searchArgs$selectedF3.value) != null ? _searchArgs$selectedF : '');
|
|
780
|
+
const facet = min(values, (a, b) => a.range.from - b.range.from);
|
|
781
|
+
const globalMin = (_facet$range$from = facet == null ? void 0 : facet.range.from) != null ? _facet$range$from : 0;
|
|
782
|
+
return {
|
|
783
|
+
selected: (_selectedRange$ = selectedRange == null ? void 0 : selectedRange[0]) != null ? _selectedRange$ : globalMin,
|
|
784
|
+
absolute: globalMin
|
|
785
|
+
};
|
|
647
786
|
},
|
|
787
|
+
max: ({
|
|
788
|
+
values,
|
|
789
|
+
key
|
|
790
|
+
}, _, {
|
|
791
|
+
storage: {
|
|
792
|
+
searchArgs
|
|
793
|
+
}
|
|
794
|
+
}) => {
|
|
795
|
+
var _searchArgs$selectedF4, _searchArgs$selectedF5, _searchArgs$selectedF6, _facet$range$to, _selectedRange$2;
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Fetch the selected range the user queried.
|
|
799
|
+
*
|
|
800
|
+
* This is necessary because, differently from boolean facets, Search API does
|
|
801
|
+
* not return the selected values, making us have to implement it in here
|
|
802
|
+
*/
|
|
803
|
+
const selectedRange = parseRange((_searchArgs$selectedF4 = searchArgs == null ? void 0 : (_searchArgs$selectedF5 = searchArgs.selectedFacets) == null ? void 0 : (_searchArgs$selectedF6 = _searchArgs$selectedF5.find(facet => facet.key === key)) == null ? void 0 : _searchArgs$selectedF6.value) != null ? _searchArgs$selectedF4 : '');
|
|
804
|
+
const facet = min(values, (a, b) => b.range.to - a.range.to);
|
|
805
|
+
const globalMax = (_facet$range$to = facet == null ? void 0 : facet.range.to) != null ? _facet$range$to : 0;
|
|
806
|
+
return {
|
|
807
|
+
selected: (_selectedRange$2 = selectedRange == null ? void 0 : selectedRange[1]) != null ? _selectedRange$2 : globalMax,
|
|
808
|
+
absolute: globalMax
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
const StoreFacetValueBoolean = {
|
|
814
|
+
value: ({
|
|
815
|
+
value
|
|
816
|
+
}) => value,
|
|
648
817
|
label: ({
|
|
649
818
|
name
|
|
650
819
|
}) => name || 'unknown',
|
|
@@ -894,28 +1063,6 @@ const validateCart = async (_, {
|
|
|
894
1063
|
return orderFormToCart(updatedOrderForm, skuLoader);
|
|
895
1064
|
};
|
|
896
1065
|
|
|
897
|
-
class ChannelMarshal {
|
|
898
|
-
static parse(channelString) {
|
|
899
|
-
try {
|
|
900
|
-
var _parsedChannel$region, _parsedChannel$salesC;
|
|
901
|
-
|
|
902
|
-
const parsedChannel = JSON.parse(channelString);
|
|
903
|
-
return {
|
|
904
|
-
regionId: (_parsedChannel$region = parsedChannel.regionId) != null ? _parsedChannel$region : '',
|
|
905
|
-
salesChannel: (_parsedChannel$salesC = parsedChannel.salesChannel) != null ? _parsedChannel$salesC : ''
|
|
906
|
-
};
|
|
907
|
-
} catch (error) {
|
|
908
|
-
console.error(error);
|
|
909
|
-
throw new Error('Malformed channel string');
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
static stringify(channel) {
|
|
914
|
-
return JSON.stringify(channel);
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
}
|
|
918
|
-
|
|
919
1066
|
const validateSession = async (_, {
|
|
920
1067
|
session: oldSession,
|
|
921
1068
|
search
|
|
@@ -965,6 +1112,50 @@ const Mutation = {
|
|
|
965
1112
|
validateSession
|
|
966
1113
|
};
|
|
967
1114
|
|
|
1115
|
+
const ObjectOrString = /*#__PURE__*/new graphql.GraphQLScalarType({
|
|
1116
|
+
name: 'ObjectOrString',
|
|
1117
|
+
description: 'A string or the string representation of an object (a stringified object).',
|
|
1118
|
+
parseValue: toObjectOrString,
|
|
1119
|
+
serialize: stringify,
|
|
1120
|
+
|
|
1121
|
+
parseLiteral(ast) {
|
|
1122
|
+
if (ast.kind === language.Kind.STRING) {
|
|
1123
|
+
return getValueAsObjectOrString(ast.value);
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
return null;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
function toObjectOrString(value) {
|
|
1132
|
+
if (typeof value === 'string') {
|
|
1133
|
+
return getValueAsObjectOrString(value);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
return null;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
function getValueAsObjectOrString(value) {
|
|
1140
|
+
try {
|
|
1141
|
+
return JSON.parse(value);
|
|
1142
|
+
} catch (e) {
|
|
1143
|
+
return value;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
function stringify(value) {
|
|
1148
|
+
if (typeof value === 'object') {
|
|
1149
|
+
return JSON.stringify(value);
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
if (typeof value === 'string') {
|
|
1153
|
+
return value;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
return null;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
968
1159
|
const isSearchItem = item => 'Price' in item && 'seller' in item && 'product' in item;
|
|
969
1160
|
|
|
970
1161
|
const isOrderFormItem = item => 'skuName' in item;
|
|
@@ -1039,7 +1230,9 @@ const StoreOffer = {
|
|
|
1039
1230
|
},
|
|
1040
1231
|
listPrice: root => {
|
|
1041
1232
|
if (isSearchItem(root)) {
|
|
1042
|
-
|
|
1233
|
+
var _root$ListPrice;
|
|
1234
|
+
|
|
1235
|
+
return (_root$ListPrice = root.ListPrice) != null ? _root$ListPrice : 0;
|
|
1043
1236
|
}
|
|
1044
1237
|
|
|
1045
1238
|
if (isOrderFormItem(root)) {
|
|
@@ -1235,6 +1428,19 @@ const StoreProductGroup = {
|
|
|
1235
1428
|
}))))
|
|
1236
1429
|
};
|
|
1237
1430
|
|
|
1431
|
+
const StorePropertyValue = {
|
|
1432
|
+
propertyID: root => getPropertyId(root),
|
|
1433
|
+
name: ({
|
|
1434
|
+
name
|
|
1435
|
+
}) => name,
|
|
1436
|
+
value: ({
|
|
1437
|
+
value
|
|
1438
|
+
}) => value,
|
|
1439
|
+
valueReference: ({
|
|
1440
|
+
valueReference
|
|
1441
|
+
}) => valueReference
|
|
1442
|
+
};
|
|
1443
|
+
|
|
1238
1444
|
const mutateChannelContext = (ctx, channelString) => {
|
|
1239
1445
|
ctx.storage.channel = ChannelMarshal.parse(channelString);
|
|
1240
1446
|
};
|
|
@@ -1242,67 +1448,6 @@ const mutateLocaleContext = (ctx, locale) => {
|
|
|
1242
1448
|
ctx.storage.locale = locale;
|
|
1243
1449
|
};
|
|
1244
1450
|
|
|
1245
|
-
/**
|
|
1246
|
-
* Transform facets from the store to VTEX platform facets.
|
|
1247
|
-
* For instance, the channel in Store becomes trade-policy and regionId in VTEX's realm
|
|
1248
|
-
* */
|
|
1249
|
-
|
|
1250
|
-
const transformSelectedFacet = ({
|
|
1251
|
-
key,
|
|
1252
|
-
value
|
|
1253
|
-
}) => {
|
|
1254
|
-
switch (key) {
|
|
1255
|
-
case 'channel':
|
|
1256
|
-
{
|
|
1257
|
-
const channel = ChannelMarshal.parse(value);
|
|
1258
|
-
const channelFacets = [{
|
|
1259
|
-
key: 'trade-policy',
|
|
1260
|
-
value: channel.salesChannel
|
|
1261
|
-
}];
|
|
1262
|
-
|
|
1263
|
-
if (channel.regionId) {
|
|
1264
|
-
channelFacets.push({
|
|
1265
|
-
key: 'region-id',
|
|
1266
|
-
value: channel.regionId
|
|
1267
|
-
});
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
return channelFacets;
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
case 'locale':
|
|
1274
|
-
{
|
|
1275
|
-
return []; // remove this facet from search
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
default:
|
|
1279
|
-
return {
|
|
1280
|
-
key,
|
|
1281
|
-
value
|
|
1282
|
-
};
|
|
1283
|
-
}
|
|
1284
|
-
};
|
|
1285
|
-
const findSlug = facets => {
|
|
1286
|
-
var _facets$find$value, _facets$find;
|
|
1287
|
-
|
|
1288
|
-
return (_facets$find$value = facets == null ? void 0 : (_facets$find = facets.find(x => x.key === 'slug')) == null ? void 0 : _facets$find.value) != null ? _facets$find$value : null;
|
|
1289
|
-
};
|
|
1290
|
-
const findSkuId = facets => {
|
|
1291
|
-
var _facets$find$value2, _facets$find2;
|
|
1292
|
-
|
|
1293
|
-
return (_facets$find$value2 = facets == null ? void 0 : (_facets$find2 = facets.find(x => x.key === 'id')) == null ? void 0 : _facets$find2.value) != null ? _facets$find$value2 : null;
|
|
1294
|
-
};
|
|
1295
|
-
const findLocale = facets => {
|
|
1296
|
-
var _facets$find$value3, _facets$find3;
|
|
1297
|
-
|
|
1298
|
-
return (_facets$find$value3 = facets == null ? void 0 : (_facets$find3 = facets.find(x => x.key === 'locale')) == null ? void 0 : _facets$find3.value) != null ? _facets$find$value3 : null;
|
|
1299
|
-
};
|
|
1300
|
-
const findChannel = facets => {
|
|
1301
|
-
var _facets$find$value4, _facets$find4;
|
|
1302
|
-
|
|
1303
|
-
return (_facets$find$value4 = facets == null ? void 0 : (_facets$find4 = facets.find(facet => facet.key === 'channel')) == null ? void 0 : _facets$find4.value) != null ? _facets$find$value4 : null;
|
|
1304
|
-
};
|
|
1305
|
-
|
|
1306
1451
|
const SORT_MAP = {
|
|
1307
1452
|
price_desc: 'price:desc',
|
|
1308
1453
|
price_asc: 'price:asc',
|
|
@@ -1314,22 +1459,6 @@ const SORT_MAP = {
|
|
|
1314
1459
|
score_desc: ''
|
|
1315
1460
|
};
|
|
1316
1461
|
|
|
1317
|
-
/**
|
|
1318
|
-
* More info at: https://en.wikipedia.org/wiki/Order_statistic
|
|
1319
|
-
*/
|
|
1320
|
-
// O(n) search to find the max of an array
|
|
1321
|
-
const min = (array, cmp) => {
|
|
1322
|
-
let best = 0;
|
|
1323
|
-
|
|
1324
|
-
for (let curr = 1; curr < array.length; curr++) {
|
|
1325
|
-
if (cmp(array[best], array[curr]) > 0) {
|
|
1326
|
-
best = curr;
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
return array[best];
|
|
1331
|
-
};
|
|
1332
|
-
|
|
1333
1462
|
/**
|
|
1334
1463
|
* This function implements Portal heuristics for returning the best sku for a product.
|
|
1335
1464
|
*
|
|
@@ -1545,7 +1674,8 @@ const StoreReview = {
|
|
|
1545
1674
|
})
|
|
1546
1675
|
};
|
|
1547
1676
|
|
|
1548
|
-
const
|
|
1677
|
+
const isRootFacet = facet => facet.key === 'category-1';
|
|
1678
|
+
|
|
1549
1679
|
const StoreSearchResult = {
|
|
1550
1680
|
suggestions: async (searchArgs, _, ctx) => {
|
|
1551
1681
|
const {
|
|
@@ -1626,29 +1756,14 @@ const StoreSearchResult = {
|
|
|
1626
1756
|
search: is
|
|
1627
1757
|
}
|
|
1628
1758
|
} = ctx;
|
|
1759
|
+
ctx.storage.searchArgs = searchArgs;
|
|
1629
1760
|
const {
|
|
1630
|
-
facets
|
|
1761
|
+
facets = []
|
|
1631
1762
|
} = await is.facets(searchArgs);
|
|
1632
1763
|
const isCollectionPage = !searchArgs.query;
|
|
1633
|
-
const filteredFacets = facets
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
if (shouldRemoveFacetFromCollectionPage) {
|
|
1638
|
-
return acc;
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1641
|
-
currentFacet.values.sort((a, b) => {
|
|
1642
|
-
var _a$name, _b$name;
|
|
1643
|
-
|
|
1644
|
-
const firstItemLabel = (_a$name = a.name) != null ? _a$name : '';
|
|
1645
|
-
const secondItemLabel = (_b$name = b.name) != null ? _b$name : '';
|
|
1646
|
-
return firstItemLabel.localeCompare(secondItemLabel);
|
|
1647
|
-
});
|
|
1648
|
-
acc.push(currentFacet);
|
|
1649
|
-
return acc;
|
|
1650
|
-
}, []);
|
|
1651
|
-
return filteredFacets != null ? filteredFacets : [];
|
|
1764
|
+
const filteredFacets = facets // Remove root facet on category pages
|
|
1765
|
+
.filter(facet => !isCollectionPage || !isRootFacet(facet));
|
|
1766
|
+
return filteredFacets;
|
|
1652
1767
|
}
|
|
1653
1768
|
};
|
|
1654
1769
|
|
|
@@ -1665,70 +1780,15 @@ const StoreSeo = {
|
|
|
1665
1780
|
titleTemplate: () => ''
|
|
1666
1781
|
};
|
|
1667
1782
|
|
|
1668
|
-
const ObjectOrString = /*#__PURE__*/new graphql.GraphQLScalarType({
|
|
1669
|
-
name: 'ObjectOrString',
|
|
1670
|
-
description: 'A string or the string representation of an object (a stringified object).',
|
|
1671
|
-
parseValue: toObjectOrString,
|
|
1672
|
-
serialize: stringify,
|
|
1673
|
-
|
|
1674
|
-
parseLiteral(ast) {
|
|
1675
|
-
if (ast.kind === language.Kind.STRING) {
|
|
1676
|
-
return getValueAsObjectOrString(ast.value);
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
|
-
return null;
|
|
1680
|
-
}
|
|
1681
|
-
|
|
1682
|
-
});
|
|
1683
|
-
|
|
1684
|
-
function toObjectOrString(value) {
|
|
1685
|
-
if (typeof value === 'string') {
|
|
1686
|
-
return getValueAsObjectOrString(value);
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
|
-
return null;
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
function getValueAsObjectOrString(value) {
|
|
1693
|
-
try {
|
|
1694
|
-
return JSON.parse(value);
|
|
1695
|
-
} catch (e) {
|
|
1696
|
-
return value;
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
|
|
1700
|
-
function stringify(value) {
|
|
1701
|
-
if (typeof value === 'object') {
|
|
1702
|
-
return JSON.stringify(value);
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
if (typeof value === 'string') {
|
|
1706
|
-
return value;
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
return null;
|
|
1710
|
-
}
|
|
1711
|
-
|
|
1712
|
-
const StorePropertyValue = {
|
|
1713
|
-
propertyID: root => getPropertyId(root),
|
|
1714
|
-
name: ({
|
|
1715
|
-
name
|
|
1716
|
-
}) => name,
|
|
1717
|
-
value: ({
|
|
1718
|
-
value
|
|
1719
|
-
}) => value,
|
|
1720
|
-
valueReference: ({
|
|
1721
|
-
valueReference
|
|
1722
|
-
}) => valueReference
|
|
1723
|
-
};
|
|
1724
|
-
|
|
1725
1783
|
const Resolvers = {
|
|
1726
1784
|
StoreCollection,
|
|
1727
1785
|
StoreAggregateOffer,
|
|
1728
1786
|
StoreProduct,
|
|
1729
1787
|
StoreSeo,
|
|
1730
1788
|
StoreFacet,
|
|
1731
|
-
|
|
1789
|
+
StoreFacetBoolean,
|
|
1790
|
+
StoreFacetRange,
|
|
1791
|
+
StoreFacetValueBoolean,
|
|
1732
1792
|
StoreOffer,
|
|
1733
1793
|
StoreAggregateRating,
|
|
1734
1794
|
StoreReview,
|
|
@@ -1771,8 +1831,8 @@ var doc$4 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","de
|
|
|
1771
1831
|
var doc$5 = {"kind":"Document","definitions":[{"kind":"EnumTypeDefinition","description":{"kind":"StringValue","value":"Product collection type. Possible values are `Department`, `Category`, `Brand` or `Cluster`.","block":true},"name":{"kind":"Name","value":"StoreCollectionType"},"directives":[],"values":[{"kind":"EnumValueDefinition","description":{"kind":"StringValue","value":"First level of product categorization.","block":true},"name":{"kind":"Name","value":"Department"},"directives":[]},{"kind":"EnumValueDefinition","description":{"kind":"StringValue","value":"Second level of product categorization.","block":true},"name":{"kind":"Name","value":"Category"},"directives":[]},{"kind":"EnumValueDefinition","description":{"kind":"StringValue","value":"Product brand.","block":true},"name":{"kind":"Name","value":"Brand"},"directives":[]},{"kind":"EnumValueDefinition","description":{"kind":"StringValue","value":"Product cluster.","block":true},"name":{"kind":"Name","value":"Cluster"},"directives":[]}]},{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Product collection facet, used for search.","block":true},"name":{"kind":"Name","value":"StoreCollectionFacet"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Facet key.","block":true},"name":{"kind":"Name","value":"key"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Facet value.","block":true},"name":{"kind":"Name","value":"value"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]},{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Collection meta information. Used for search.","block":true},"name":{"kind":"Name","value":"StoreCollectionMeta"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"List of selected collection facets.","block":true},"name":{"kind":"Name","value":"selectedFacets"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreCollectionFacet"}}}}},"directives":[]}]},{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Product collection information.","block":true},"name":{"kind":"Name","value":"StoreCollection"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Meta tag data.","block":true},"name":{"kind":"Name","value":"seo"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreSeo"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"List of items consisting of chain linked web pages, ending with the current page.","block":true},"name":{"kind":"Name","value":"breadcrumbList"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreBreadcrumbList"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Collection meta information. Used for search.","block":true},"name":{"kind":"Name","value":"meta"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreCollectionMeta"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Collection ID.","block":true},"name":{"kind":"Name","value":"id"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Corresponding collection URL slug, with which to retrieve this entity.","block":true},"name":{"kind":"Name","value":"slug"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Collection type.","block":true},"name":{"kind":"Name","value":"type"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreCollectionType"}}},"directives":[]}]}],"loc":{"start":0,"end":1218}};
|
|
1772
1832
|
doc$5.loc.source = {"body":"\"\"\"\nProduct collection type. Possible values are `Department`, `Category`, `Brand` or `Cluster`.\n\"\"\"\nenum StoreCollectionType {\n \"\"\"\n First level of product categorization.\n \"\"\"\n Department\n \"\"\"\n Second level of product categorization.\n \"\"\"\n Category\n \"\"\"\n Product brand.\n \"\"\"\n Brand\n \"\"\"\n Product cluster.\n \"\"\"\n Cluster\n}\n\n\"\"\"\nProduct collection facet, used for search.\n\"\"\"\ntype StoreCollectionFacet {\n \"\"\"\n Facet key.\n \"\"\"\n key: String!\n \"\"\"\n Facet value.\n \"\"\"\n value: String!\n}\n\n\"\"\"\nCollection meta information. Used for search.\n\"\"\"\ntype StoreCollectionMeta {\n \"\"\"\n List of selected collection facets.\n \"\"\"\n selectedFacets: [StoreCollectionFacet!]!\n}\n\n\"\"\"\nProduct collection information.\n\"\"\"\ntype StoreCollection {\n \"\"\"\n Meta tag data.\n \"\"\"\n seo: StoreSeo!\n \"\"\"\n List of items consisting of chain linked web pages, ending with the current page.\n \"\"\"\n breadcrumbList: StoreBreadcrumbList!\n \"\"\"\n Collection meta information. Used for search.\n \"\"\"\n meta: StoreCollectionMeta!\n \"\"\"\n Collection ID.\n \"\"\"\n id: ID!\n \"\"\"\n Corresponding collection URL slug, with which to retrieve this entity.\n \"\"\"\n slug: String!\n \"\"\"\n Collection type.\n \"\"\"\n type: StoreCollectionType!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
|
|
1773
1833
|
|
|
1774
|
-
var doc$6 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Search facet information.","block":true},"name":{"kind":"Name","value":"
|
|
1775
|
-
doc$6.loc.source = {"body":"\"\"\"\nSearch facet information.\n\"\"\"\ntype
|
|
1834
|
+
var doc$6 = {"kind":"Document","definitions":[{"kind":"UnionTypeDefinition","name":{"kind":"Name","value":"StoreFacet"},"directives":[],"types":[{"kind":"NamedType","name":{"kind":"Name","value":"StoreFacetRange"}},{"kind":"NamedType","name":{"kind":"Name","value":"StoreFacetBoolean"}}]},{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Search facet range information.","block":true},"name":{"kind":"Name","value":"StoreFacetRange"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Facet key.","block":true},"name":{"kind":"Name","value":"key"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Facet label.","block":true},"name":{"kind":"Name","value":"label"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Array with information on each facet value.","block":true},"name":{"kind":"Name","value":"min"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreFacetValueRange"}}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"max"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreFacetValueRange"}}},"directives":[]}]},{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Search facet boolean information.","block":true},"name":{"kind":"Name","value":"StoreFacetBoolean"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Facet key.","block":true},"name":{"kind":"Name","value":"key"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Facet label.","block":true},"name":{"kind":"Name","value":"label"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Array with information on each facet value.","block":true},"name":{"kind":"Name","value":"values"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreFacetValueBoolean"}}}}},"directives":[]}]},{"kind":"ObjectTypeDefinition","name":{"kind":"Name","value":"StoreFacetValueRange"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","name":{"kind":"Name","value":"absolute"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"FieldDefinition","name":{"kind":"Name","value":"selected"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]}]},{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Information of a specific facet value.","block":true},"name":{"kind":"Name","value":"StoreFacetValueBoolean"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Facet value.","block":true},"name":{"kind":"Name","value":"value"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Facet value label.","block":true},"name":{"kind":"Name","value":"label"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Indicates whether facet is selected.","block":true},"name":{"kind":"Name","value":"selected"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Boolean"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Number of items with this facet.","block":true},"name":{"kind":"Name","value":"quantity"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},"directives":[]}]}],"loc":{"start":0,"end":949}};
|
|
1835
|
+
doc$6.loc.source = {"body":"union StoreFacet = StoreFacetRange | StoreFacetBoolean\n\n\"\"\"\nSearch facet range information.\n\"\"\"\ntype StoreFacetRange {\n \"\"\"\n Facet key.\n \"\"\"\n key: String!\n \"\"\"\n Facet label.\n \"\"\"\n label: String!\n \"\"\"\n Array with information on each facet value.\n \"\"\"\n min: StoreFacetValueRange!\n max: StoreFacetValueRange!\n}\n\n\"\"\"\nSearch facet boolean information.\n\"\"\"\ntype StoreFacetBoolean {\n \"\"\"\n Facet key.\n \"\"\"\n key: String!\n \"\"\"\n Facet label.\n \"\"\"\n label: String!\n \"\"\"\n Array with information on each facet value.\n \"\"\"\n values: [StoreFacetValueBoolean!]!\n}\n\ntype StoreFacetValueRange {\n absolute: Float!\n selected: Float!\n}\n\n\"\"\"\nInformation of a specific facet value.\n\"\"\"\ntype StoreFacetValueBoolean {\n \"\"\"\n Facet value.\n \"\"\"\n value: String!\n \"\"\"\n Facet value label.\n \"\"\"\n label: String!\n \"\"\"\n Indicates whether facet is selected.\n \"\"\"\n selected: Boolean!\n \"\"\"\n Number of items with this facet.\n \"\"\"\n quantity: Int!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
|
|
1776
1836
|
|
|
1777
1837
|
var doc$7 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Image.","block":true},"name":{"kind":"Name","value":"StoreImage"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Image URL.","block":true},"name":{"kind":"Name","value":"url"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Alias for the image.","block":true},"name":{"kind":"Name","value":"alternateName"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]},{"kind":"InputObjectTypeDefinition","description":{"kind":"StringValue","value":"Image input.","block":true},"name":{"kind":"Name","value":"IStoreImage"},"directives":[],"fields":[{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Image input URL.","block":true},"name":{"kind":"Name","value":"url"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Alias for the input image.","block":true},"name":{"kind":"Name","value":"alternateName"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]}],"loc":{"start":0,"end":291}};
|
|
1778
1838
|
doc$7.loc.source = {"body":"\"\"\"\nImage.\n\"\"\"\ntype StoreImage {\n \"\"\"\n Image URL.\n \"\"\"\n url: String!\n \"\"\"\n Alias for the image.\n \"\"\"\n alternateName: String!\n}\n\n\"\"\"\nImage input.\n\"\"\"\ninput IStoreImage {\n \"\"\"\n Image input URL.\n \"\"\"\n url: String!\n \"\"\"\n Alias for the input image.\n \"\"\"\n alternateName: String!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
|