@sonic-equipment/ui 0.0.83 → 0.0.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,12 @@ import * as algoliasearch from 'algoliasearch';
|
|
|
6
6
|
import { SearchClient } from 'algoliasearch';
|
|
7
7
|
import { AutocompleteApi, AutocompleteState as AutocompleteState$1, AutocompleteCollection, InternalAutocompleteSource, BaseItem } from '@algolia/autocomplete-core';
|
|
8
8
|
|
|
9
|
-
declare const environments = [
|
|
9
|
+
declare const environments = [
|
|
10
|
+
'sandbox',
|
|
11
|
+
'production',
|
|
12
|
+
'local',
|
|
13
|
+
'storybook',
|
|
14
|
+
] as const
|
|
10
15
|
type Environment = (typeof environments)[number]
|
|
11
16
|
|
|
12
17
|
declare const environment = getEnvironment()
|
|
@@ -4193,6 +4198,7 @@ interface AlgoliaProduct$1 {
|
|
|
4193
4198
|
slug: string
|
|
4194
4199
|
storefrontId: string
|
|
4195
4200
|
storefrontSlug: string
|
|
4201
|
+
type: 'promo' | 'product'
|
|
4196
4202
|
weight: number
|
|
4197
4203
|
width: number
|
|
4198
4204
|
}
|
|
@@ -4894,6 +4900,7 @@ interface AlgoliaProduct {
|
|
|
4894
4900
|
slug: string;
|
|
4895
4901
|
storefrontId: string;
|
|
4896
4902
|
storefrontSlug: string;
|
|
4903
|
+
type: 'promo' | 'product';
|
|
4897
4904
|
weight: number;
|
|
4898
4905
|
width: number;
|
|
4899
4906
|
}
|
package/dist/index.js
CHANGED
|
@@ -18,8 +18,14 @@ import { getAlgoliaResults, parseAlgoliaHitHighlight } from '@algolia/autocomple
|
|
|
18
18
|
import { createQuerySuggestionsPlugin } from '@algolia/autocomplete-plugin-query-suggestions';
|
|
19
19
|
import { createLocalStorageRecentSearchesPlugin, search } from '@algolia/autocomplete-plugin-recent-searches';
|
|
20
20
|
|
|
21
|
-
const environments = [
|
|
22
|
-
|
|
21
|
+
const environments = [
|
|
22
|
+
'sandbox',
|
|
23
|
+
'production',
|
|
24
|
+
'local',
|
|
25
|
+
'storybook',
|
|
26
|
+
];
|
|
27
|
+
const storybookUrls = /localhost:6006/i;
|
|
28
|
+
const localUrls = /sonic.local.com/i;
|
|
23
29
|
const sandboxUrls = /local|insitesandbox.com|azurestaticapps|ui.sonic-equipment.com|sandbox|accept|test/i;
|
|
24
30
|
const productionUrls = /sonic-equipment.com|production/i;
|
|
25
31
|
let environmentUrl;
|
|
@@ -38,7 +44,10 @@ function getEnvironment() {
|
|
|
38
44
|
console.error('Unable to detect environment url');
|
|
39
45
|
}
|
|
40
46
|
let environment;
|
|
41
|
-
if (environmentUrl.match(
|
|
47
|
+
if (environmentUrl.match(storybookUrls)) {
|
|
48
|
+
environment = 'storybook';
|
|
49
|
+
}
|
|
50
|
+
else if (environmentUrl.match(localUrls)) {
|
|
42
51
|
environment = 'local';
|
|
43
52
|
}
|
|
44
53
|
else if (environmentUrl.match(sandboxUrls)) {
|
|
@@ -61,10 +70,10 @@ const configPerEnvironment = {
|
|
|
61
70
|
ALGOLIA_API_KEY: 'e0edf30798a6b2e4e44fd25f0f2f9646',
|
|
62
71
|
ALGOLIA_APP_ID: 'testing9VXJ0U4GSV',
|
|
63
72
|
ALGOLIA_HOST: 'sonicequipment.commerce.insitesandbox.com',
|
|
64
|
-
BFF_API_URL: 'https://
|
|
73
|
+
BFF_API_URL: 'https://localhost:8000/api/v1/bff',
|
|
65
74
|
SHOP_API_URL:
|
|
66
75
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
67
|
-
'
|
|
76
|
+
'',
|
|
68
77
|
},
|
|
69
78
|
production: {
|
|
70
79
|
ALGOLIA_API_KEY: 'e31a3a53449eceb4d0f9273b9bcd9759',
|
|
@@ -83,6 +92,15 @@ const configPerEnvironment = {
|
|
|
83
92
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
84
93
|
'https://sonicequipment.commerce.insitesandbox.com',
|
|
85
94
|
},
|
|
95
|
+
storybook: {
|
|
96
|
+
ALGOLIA_API_KEY: 'e0edf30798a6b2e4e44fd25f0f2f9646',
|
|
97
|
+
ALGOLIA_APP_ID: 'testing9VXJ0U4GSV',
|
|
98
|
+
ALGOLIA_HOST: 'sonicequipment.commerce.insitesandbox.com',
|
|
99
|
+
BFF_API_URL: 'https://sonicequipment.commerce.insitesandbox.com/api/v1/bff',
|
|
100
|
+
SHOP_API_URL:
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
102
|
+
'https://sonic.local.com:4443',
|
|
103
|
+
},
|
|
86
104
|
};
|
|
87
105
|
const config = configPerEnvironment[environment];
|
|
88
106
|
|
|
@@ -599,13 +617,23 @@ async function getWishListItemsByWishListId({ wishListId, }) {
|
|
|
599
617
|
return body;
|
|
600
618
|
}
|
|
601
619
|
|
|
620
|
+
var TIME;
|
|
621
|
+
(function (TIME) {
|
|
622
|
+
TIME[TIME["SECOND"] = 1000] = "SECOND";
|
|
623
|
+
TIME[TIME["MINUTE"] = 60000] = "MINUTE";
|
|
624
|
+
TIME[TIME["HOUR"] = 3600000] = "HOUR";
|
|
625
|
+
TIME[TIME["DAY"] = 86400000] = "DAY";
|
|
626
|
+
})(TIME || (TIME = {}));
|
|
627
|
+
|
|
602
628
|
function useSession({ enabled = true } = {}) {
|
|
603
629
|
return useQuery({
|
|
604
630
|
enabled,
|
|
631
|
+
gcTime: 15 * TIME.MINUTE,
|
|
605
632
|
queryFn: async () => {
|
|
606
633
|
return await getSession();
|
|
607
634
|
},
|
|
608
635
|
queryKey: ['session'],
|
|
636
|
+
staleTime: 15 * TIME.MINUTE,
|
|
609
637
|
});
|
|
610
638
|
}
|
|
611
639
|
|
|
@@ -695,10 +723,12 @@ function useDeleteCartLineById() {
|
|
|
695
723
|
|
|
696
724
|
function useFetchCurrentCartLines() {
|
|
697
725
|
return useQuery({
|
|
726
|
+
gcTime: 15 * TIME.MINUTE,
|
|
698
727
|
queryFn: async () => {
|
|
699
728
|
return fetchCurrentCartLines();
|
|
700
729
|
},
|
|
701
730
|
queryKey: ['carts', 'current', 'cartlines'],
|
|
731
|
+
staleTime: 15 * TIME.MINUTE,
|
|
702
732
|
});
|
|
703
733
|
}
|
|
704
734
|
|
|
@@ -728,14 +758,6 @@ function useUpdateCartLineById() {
|
|
|
728
758
|
});
|
|
729
759
|
}
|
|
730
760
|
|
|
731
|
-
var TIME;
|
|
732
|
-
(function (TIME) {
|
|
733
|
-
TIME[TIME["SECOND"] = 1000] = "SECOND";
|
|
734
|
-
TIME[TIME["MINUTE"] = 60000] = "MINUTE";
|
|
735
|
-
TIME[TIME["HOUR"] = 3600000] = "HOUR";
|
|
736
|
-
TIME[TIME["DAY"] = 86400000] = "DAY";
|
|
737
|
-
})(TIME || (TIME = {}));
|
|
738
|
-
|
|
739
761
|
function useFetchTranslations(languagCode) {
|
|
740
762
|
return useQuery({
|
|
741
763
|
gcTime: 1 * TIME.DAY,
|
|
@@ -837,6 +859,7 @@ function useFetchAllWishListsItems({ enabled = true } = { enabled: true }) {
|
|
|
837
859
|
const queryClient = useQueryClient();
|
|
838
860
|
return useQuery({
|
|
839
861
|
enabled,
|
|
862
|
+
gcTime: 15 * TIME.MINUTE,
|
|
840
863
|
queryFn: async () => {
|
|
841
864
|
let wishLists =
|
|
842
865
|
// Reuse existing data if available
|
|
@@ -858,13 +881,16 @@ function useFetchAllWishListsItems({ enabled = true } = { enabled: true }) {
|
|
|
858
881
|
return wishListLines.flatMap(wishListDetails => wishListDetails);
|
|
859
882
|
},
|
|
860
883
|
queryKey: ['wishlistlines'],
|
|
884
|
+
staleTime: 15 * TIME.MINUTE,
|
|
861
885
|
});
|
|
862
886
|
}
|
|
863
887
|
|
|
864
888
|
function useFetchWishLists() {
|
|
865
889
|
return useQuery({
|
|
890
|
+
gcTime: 15 * TIME.MINUTE,
|
|
866
891
|
queryFn: getWishLists,
|
|
867
892
|
queryKey: ['wishlists'],
|
|
893
|
+
staleTime: 15 * TIME.MINUTE,
|
|
868
894
|
});
|
|
869
895
|
}
|
|
870
896
|
|
|
@@ -8087,9 +8113,7 @@ function useFetchProductDetailsPageData({ languageCode, pageUrl, }) {
|
|
|
8087
8113
|
queryFn: async () => {
|
|
8088
8114
|
const { body } = await request({
|
|
8089
8115
|
headers: { 'Current-Language-Id': languageCode },
|
|
8090
|
-
url:
|
|
8091
|
-
? `${config.SHOP_API_URL}/pdp/?pageUrl=${pageUrl}`
|
|
8092
|
-
: `${config.BFF_API_URL}/pdp/?pageUrl=${pageUrl}`,
|
|
8116
|
+
url: `${config.BFF_API_URL}/pdp/?pageUrl=${pageUrl}`,
|
|
8093
8117
|
});
|
|
8094
8118
|
body.usps = [
|
|
8095
8119
|
{
|
|
@@ -8626,14 +8650,34 @@ const algoliaIndexesPerEnvironment = {
|
|
|
8626
8650
|
],
|
|
8627
8651
|
suggestions: 'dev_sonic_products_<languageCode>_query_suggestions',
|
|
8628
8652
|
},
|
|
8653
|
+
storybook: {
|
|
8654
|
+
default: 'dev_sonic_products_<languageCode>',
|
|
8655
|
+
sort: [
|
|
8656
|
+
{
|
|
8657
|
+
index: 'dev_sonic_products_<languageCode>',
|
|
8658
|
+
name: 'relevance',
|
|
8659
|
+
},
|
|
8660
|
+
{
|
|
8661
|
+
index: 'dev_sonic_products_<languageCode>_is-new_desc',
|
|
8662
|
+
name: 'newest',
|
|
8663
|
+
},
|
|
8664
|
+
{
|
|
8665
|
+
index: 'dev_sonic_products_<languageCode>_price_asc',
|
|
8666
|
+
name: 'price_asc',
|
|
8667
|
+
},
|
|
8668
|
+
{
|
|
8669
|
+
index: 'dev_sonic_products_<languageCode>_price_desc',
|
|
8670
|
+
name: 'price_desc',
|
|
8671
|
+
},
|
|
8672
|
+
],
|
|
8673
|
+
suggestions: 'dev_sonic_products_<languageCode>_query_suggestions',
|
|
8674
|
+
},
|
|
8629
8675
|
};
|
|
8630
8676
|
const getAlgoliaIndex = (environment, languageCode) => {
|
|
8631
8677
|
const environmentIndex = algoliaIndexesPerEnvironment[environment];
|
|
8632
8678
|
const shortLanguageCode = languageCode.split('-')[0];
|
|
8633
8679
|
if (!shortLanguageCode)
|
|
8634
8680
|
throw new Error('Language code not detected');
|
|
8635
|
-
if (!environmentIndex)
|
|
8636
|
-
throw new Error('Environment not detected');
|
|
8637
8681
|
const language = getLanguageForAlgoliaIndex(shortLanguageCode);
|
|
8638
8682
|
return {
|
|
8639
8683
|
default: environmentIndex.default.replace(/<languageCode>/, language),
|
|
@@ -8709,7 +8753,9 @@ function useAlgoliaProductHits() {
|
|
|
8709
8753
|
const [isLoading] = useAlgoliaProductHitsLoading();
|
|
8710
8754
|
return {
|
|
8711
8755
|
isLoading,
|
|
8712
|
-
products: items
|
|
8756
|
+
products: items
|
|
8757
|
+
.map(transformAlgoliaProductHitToProductHit)
|
|
8758
|
+
.filter(product => product.hit.type === 'product'),
|
|
8713
8759
|
};
|
|
8714
8760
|
}
|
|
8715
8761
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const environments: readonly ["sandbox", "production", "local"];
|
|
1
|
+
export declare const environments: readonly ["sandbox", "production", "local", "storybook"];
|
|
2
2
|
export type Environment = (typeof environments)[number];
|
|
3
|
-
export declare const environment: "sandbox" | "production" | "local";
|
|
3
|
+
export declare const environment: "sandbox" | "production" | "local" | "storybook";
|