@tapcart/mobile-components 0.7.27 → 0.7.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.
- package/dist/components/hooks/use-customer.d.ts +10 -0
- package/dist/components/hooks/use-customer.d.ts.map +1 -0
- package/dist/components/hooks/use-customer.js +24 -0
- package/dist/components/hooks/use-nosto-recommendation.d.ts +9 -1
- package/dist/components/hooks/use-nosto-recommendation.d.ts.map +1 -1
- package/dist/components/hooks/use-nosto-recommendation.js +138 -53
- package/dist/components/hooks/use-nosto-recommendation.queries.d.ts +48 -0
- package/dist/components/hooks/use-nosto-recommendation.queries.d.ts.map +1 -0
- package/dist/components/hooks/use-nosto-recommendation.queries.js +143 -0
- package/dist/components/hooks/use-nosto-recommendation.test.d.ts +2 -0
- package/dist/components/hooks/use-nosto-recommendation.test.d.ts.map +1 -0
- package/dist/components/hooks/use-nosto-recommendation.test.js +248 -0
- package/dist/components/hooks/use-recommendations.d.ts.map +1 -1
- package/dist/components/hooks/use-recommendations.js +1 -2
- package/dist/components/ui/apple-pay-button.d.ts +24 -0
- package/dist/components/ui/apple-pay-button.d.ts.map +1 -0
- package/dist/components/ui/apple-pay-button.js +121 -0
- package/dist/components/ui/drawer.js +1 -1
- package/dist/components/ui/price.js +1 -1
- package/dist/styles.css +3 -3
- package/package.json +4 -2
- package/dist/components/contexts/translationContext.d.ts +0 -9
- package/dist/components/contexts/translationContext.d.ts.map +0 -1
- package/dist/components/contexts/translationContext.js +0 -5
- package/dist/components/hooks/use-destination.d.ts +0 -23
- package/dist/components/hooks/use-destination.d.ts.map +0 -1
- package/dist/components/hooks/use-destination.js +0 -13
- package/dist/components/ui/use-tap.d.ts +0 -8
- package/dist/components/ui/use-tap.d.ts.map +0 -1
- package/dist/components/ui/use-tap.js +0 -100
- package/dist/components/ui/video copy.d.ts +0 -18
- package/dist/components/ui/video copy.d.ts.map +0 -1
- package/dist/components/ui/video copy.js +0 -70
- package/dist/components/ui/video.v2.d.ts +0 -18
- package/dist/components/ui/video.v2.d.ts.map +0 -1
- package/dist/components/ui/video.v2.js +0 -70
- package/dist/index copy.d.ts +0 -59
- package/dist/index copy.d.ts.map +0 -1
- package/dist/index copy.js +0 -59
- package/dist/lib/utils/destination.d.ts +0 -17
- package/dist/lib/utils/destination.d.ts.map +0 -1
- package/dist/lib/utils/destination.js +0 -15
- package/dist/lib/utils/id.d.ts +0 -5
- package/dist/lib/utils/id.d.ts.map +0 -1
- package/dist/lib/utils/id.js +0 -29
- package/dist/lib/utils/index.d.ts +0 -18
- package/dist/lib/utils/index.d.ts.map +0 -1
- package/dist/lib/utils/index.js +0 -55
- package/dist/lib/utils/misc.d.ts +0 -1
- package/dist/lib/utils/misc.d.ts.map +0 -1
- package/dist/lib/utils/misc.js +0 -1
- package/dist/lib/utils/style.d.ts +0 -154
- package/dist/lib/utils/style.d.ts.map +0 -1
- package/dist/lib/utils/style.js +0 -148
- package/dist/lib/utils.deprecated.d.ts +0 -181
- package/dist/lib/utils.deprecated.d.ts.map +0 -1
- package/dist/lib/utils.deprecated.js +0 -222
- package/dist/v2.d.ts +0 -59
- package/dist/v2.d.ts.map +0 -1
- package/dist/v2.js +0 -59
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Customer = {
|
|
2
|
+
isAuthenticated: boolean;
|
|
3
|
+
};
|
|
4
|
+
type UseCustomerProps = {};
|
|
5
|
+
type UseCustomerReturn = {
|
|
6
|
+
customer: Customer;
|
|
7
|
+
};
|
|
8
|
+
export declare const useCustomer: (props: UseCustomerProps | null) => UseCustomerReturn;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=use-customer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-customer.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-customer.ts"],"names":[],"mappings":"AAWA,KAAK,QAAQ,GAAG;IACd,eAAe,EAAE,OAAO,CAAA;CACzB,CAAA;AAGD,KAAK,gBAAgB,GAAG,EAAE,CAAA;AAE1B,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,WAAW,UACf,gBAAgB,GAAG,IAAI,KAC7B,iBAuBF,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
// @ts-ignore -- webbridge-react is not typed (yet)
|
|
4
|
+
import { useActions } from "@tapcart/webbridge-react";
|
|
5
|
+
export const useCustomer = (props) => {
|
|
6
|
+
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
7
|
+
const [customer, setCustomer] = useState({});
|
|
8
|
+
const actions = useActions();
|
|
9
|
+
// verify customer
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
try {
|
|
12
|
+
// webbridge method to get customerIdentity
|
|
13
|
+
actions.getCustomerIdentity(null, {
|
|
14
|
+
onSuccess: (user) => setIsAuthenticated(!!(user === null || user === void 0 ? void 0 : user.email)),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
console.log("unable to get customer identity ", e);
|
|
19
|
+
}
|
|
20
|
+
}, [actions]);
|
|
21
|
+
return {
|
|
22
|
+
customer: Object.assign({ isAuthenticated }, customer),
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { Integrations } from "app-studio-types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare enum NostoRecommendationsType {
|
|
3
|
+
BOUGHT_TOGETHER = "BOUGHT_TOGETHER",
|
|
4
|
+
VIEWED_TOGETHER = "VIEWED_TOGETHER",
|
|
5
|
+
VIEWED_TOGETHER_SMART = "VIEWED_TOGETHER_SMART",
|
|
6
|
+
DEFAULT_SUM = "DEFAULT_SUM",
|
|
7
|
+
BEST_SELLERS = "BEST_SELLERS",
|
|
8
|
+
VIEWED_CATEGORY = "VIEWED_CATEGORY"
|
|
9
|
+
}
|
|
10
|
+
export declare function useNostoRecommendations(integrations: Integrations, baseURL: string, slotId?: string, recommendationsType?: NostoRecommendationsType | "", productIds?: string[], skip?: boolean): {
|
|
3
11
|
recommendations: import("app-studio-types").Product[];
|
|
4
12
|
isLoading: boolean;
|
|
5
13
|
error: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-nosto-recommendation.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-nosto-recommendation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"use-nosto-recommendation.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-nosto-recommendation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAe/C,oBAAY,wBAAwB;IAClC,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;IACnC,qBAAqB,0BAA0B;IAC/C,WAAW,gBAAgB;IAC3B,YAAY,iBAAiB;IAC7B,eAAe,oBAAoB;CACpC;AAyRD,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,MAAM,EACf,MAAM,SAAK,EACX,mBAAmB,CAAC,EAAE,wBAAwB,GAAG,EAAE,EACnD,UAAU,CAAC,EAAE,MAAM,EAAE,EACrB,IAAI,CAAC,EAAE,OAAO;;;;;EAiCf"}
|
|
@@ -10,74 +10,147 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
import { useState, useEffect } from "react";
|
|
12
12
|
import { useProducts } from "./use-products";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
import { bestSellersRecommendationsQuery, categoryPageRecommendationsQuery, getFrontPageRecommendationsQuery, getProductPageRecommendationsQuery, getRelatedProductsRecommendationsQuery, newSessionQuery, } from "./use-nosto-recommendation.queries";
|
|
14
|
+
export var NostoRecommendationsType;
|
|
15
|
+
(function (NostoRecommendationsType) {
|
|
16
|
+
NostoRecommendationsType["BOUGHT_TOGETHER"] = "BOUGHT_TOGETHER";
|
|
17
|
+
NostoRecommendationsType["VIEWED_TOGETHER"] = "VIEWED_TOGETHER";
|
|
18
|
+
NostoRecommendationsType["VIEWED_TOGETHER_SMART"] = "VIEWED_TOGETHER_SMART";
|
|
19
|
+
NostoRecommendationsType["DEFAULT_SUM"] = "DEFAULT_SUM";
|
|
20
|
+
NostoRecommendationsType["BEST_SELLERS"] = "BEST_SELLERS";
|
|
21
|
+
NostoRecommendationsType["VIEWED_CATEGORY"] = "VIEWED_CATEGORY";
|
|
22
|
+
})(NostoRecommendationsType || (NostoRecommendationsType = {}));
|
|
23
|
+
const fetchNosto = (nostoKey, graphqlBody, mode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
24
|
const url = "https://api.nosto.com/v1/graphql";
|
|
18
25
|
const headers = new Headers({
|
|
19
26
|
"Content-Type": "application/json",
|
|
20
|
-
Authorization: "Basic " + btoa(":" +
|
|
21
|
-
});
|
|
22
|
-
// Fetch sessionId
|
|
23
|
-
const sessionBody = JSON.stringify({
|
|
24
|
-
query: `mutation { newSession }`,
|
|
27
|
+
Authorization: "Basic " + btoa(":" + nostoKey),
|
|
25
28
|
});
|
|
26
|
-
const
|
|
29
|
+
const response = yield fetch(url, {
|
|
27
30
|
method: "POST",
|
|
28
31
|
headers: headers,
|
|
29
|
-
|
|
32
|
+
mode: mode,
|
|
33
|
+
body: graphqlBody,
|
|
30
34
|
});
|
|
31
|
-
const
|
|
35
|
+
const json = yield response.json();
|
|
36
|
+
return json;
|
|
37
|
+
});
|
|
38
|
+
const getProductIdsFromPageResponse = (pageResponse) => {
|
|
39
|
+
return ((pageResponse === null || pageResponse === void 0 ? void 0 : pageResponse.flatMap((page) => page.primary).filter((item) => item && item.productId).map((item) => item.productId)) || []);
|
|
40
|
+
};
|
|
41
|
+
const fetchFrontPageRecommendations = (nostoKey, slotId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
var _a, _b, _c;
|
|
43
|
+
// Fetch sessionId
|
|
44
|
+
const sessionData = yield fetchNosto(nostoKey, newSessionQuery);
|
|
32
45
|
const sessionId = sessionData.data.newSession;
|
|
33
46
|
// Main recommendation query
|
|
34
|
-
const body =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
const body = getFrontPageRecommendationsQuery(sessionId, slotId);
|
|
48
|
+
const response = yield fetchNosto(nostoKey, body, "cors");
|
|
49
|
+
return getProductIdsFromPageResponse((_c = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.updateSession) === null || _b === void 0 ? void 0 : _b.pages) === null || _c === void 0 ? void 0 : _c.forFrontPage);
|
|
50
|
+
});
|
|
51
|
+
const fetchProductPageRecommendations = (nostoKey, productId, slotId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
var _d, _e, _f;
|
|
53
|
+
const sessionData = yield fetchNosto(nostoKey, newSessionQuery);
|
|
54
|
+
const sessionId = sessionData.data.newSession;
|
|
55
|
+
const body = getProductPageRecommendationsQuery(sessionId, productId, slotId);
|
|
56
|
+
const response = yield fetchNosto(nostoKey, body, "cors");
|
|
57
|
+
return getProductIdsFromPageResponse((_f = (_e = (_d = response.data) === null || _d === void 0 ? void 0 : _d.updateSession) === null || _e === void 0 ? void 0 : _e.pages) === null || _f === void 0 ? void 0 : _f.forProductPage);
|
|
58
|
+
});
|
|
59
|
+
const fetchCategoryPageRecommendations = (nostoKey, sourceCollectionTitle) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
var _g, _h, _j;
|
|
61
|
+
const sessionData = yield fetchNosto(nostoKey, newSessionQuery);
|
|
62
|
+
const sessionId = sessionData.data.newSession;
|
|
63
|
+
const body = categoryPageRecommendationsQuery(sessionId, sourceCollectionTitle);
|
|
64
|
+
const response = yield fetchNosto(nostoKey, body, "cors");
|
|
65
|
+
return getProductIdsFromPageResponse((_j = (_h = (_g = response.data) === null || _g === void 0 ? void 0 : _g.updateSession) === null || _h === void 0 ? void 0 : _h.pages) === null || _j === void 0 ? void 0 : _j.forCategoryPage);
|
|
66
|
+
});
|
|
67
|
+
const fetchBestSellersRecommendations = (nostoKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
var _k, _l, _m, _o;
|
|
69
|
+
const body = bestSellersRecommendationsQuery;
|
|
70
|
+
const response = yield fetchNosto(nostoKey, body, "cors");
|
|
71
|
+
const productIds = ((_o = (_m = (_l = (_k = response === null || response === void 0 ? void 0 : response.data) === null || _k === void 0 ? void 0 : _k.recos) === null || _l === void 0 ? void 0 : _l.toplist) === null || _m === void 0 ? void 0 : _m.primary) === null || _o === void 0 ? void 0 : _o.map((item) => item.productId)) || [];
|
|
72
|
+
return productIds;
|
|
73
|
+
});
|
|
74
|
+
const fetchRelatedProductsRecommendations = (nostoKey, recommendationsType, productIds) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
var _p, _q, _r, _s;
|
|
76
|
+
const body = getRelatedProductsRecommendationsQuery(recommendationsType, productIds);
|
|
77
|
+
const response = yield fetchNosto(nostoKey, body, "cors");
|
|
78
|
+
const recommendedProductIds = ((_s = (_r = (_q = (_p = response === null || response === void 0 ? void 0 : response.data) === null || _p === void 0 ? void 0 : _p.recos) === null || _q === void 0 ? void 0 : _q.related) === null || _r === void 0 ? void 0 : _r.primary) === null || _s === void 0 ? void 0 : _s.map((item) => item.productId)) || [];
|
|
79
|
+
return recommendedProductIds;
|
|
80
|
+
});
|
|
81
|
+
const fetchPDPFallbackRecommendations = (nostoKey, productId, recommendationsType = NostoRecommendationsType.BOUGHT_TOGETHER) => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
+
switch (recommendationsType) {
|
|
83
|
+
case NostoRecommendationsType.VIEWED_CATEGORY:
|
|
84
|
+
return fetchCategoryPageRecommendations(nostoKey, productId);
|
|
85
|
+
case NostoRecommendationsType.BEST_SELLERS:
|
|
86
|
+
return fetchBestSellersRecommendations(nostoKey);
|
|
87
|
+
default:
|
|
88
|
+
return fetchRelatedProductsRecommendations(nostoKey, recommendationsType, [productId]);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
const fetchHomeRecommendations = (nostoKey, slotId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
let productIdRecommendations = [];
|
|
93
|
+
if (slotId) {
|
|
94
|
+
try {
|
|
95
|
+
productIdRecommendations = yield fetchFrontPageRecommendations(nostoKey, slotId);
|
|
96
|
+
if (productIdRecommendations.length === 0) {
|
|
97
|
+
productIdRecommendations = yield fetchBestSellersRecommendations(nostoKey);
|
|
55
98
|
}
|
|
56
|
-
}
|
|
57
99
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
const json = yield response.json();
|
|
68
|
-
return json;
|
|
100
|
+
catch (error) {
|
|
101
|
+
productIdRecommendations = yield fetchBestSellersRecommendations(nostoKey);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
productIdRecommendations = yield fetchBestSellersRecommendations(nostoKey);
|
|
106
|
+
}
|
|
107
|
+
return productIdRecommendations;
|
|
69
108
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
109
|
+
const fetchPDPRecommendations = (nostoKey, productId, slotId, recommendationsType = NostoRecommendationsType.BOUGHT_TOGETHER) => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
+
let productIdRecommendations = [];
|
|
111
|
+
if (slotId) {
|
|
112
|
+
try {
|
|
113
|
+
productIdRecommendations = yield fetchProductPageRecommendations(nostoKey, productId, slotId);
|
|
114
|
+
if (productIdRecommendations.length === 0) {
|
|
115
|
+
productIdRecommendations = yield fetchPDPFallbackRecommendations(nostoKey, productId, recommendationsType);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
productIdRecommendations = yield fetchPDPFallbackRecommendations(nostoKey, productId, recommendationsType);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
productIdRecommendations = yield fetchPDPFallbackRecommendations(nostoKey, productId, recommendationsType);
|
|
124
|
+
}
|
|
125
|
+
return productIdRecommendations;
|
|
126
|
+
});
|
|
127
|
+
const getProductIdRecommendations = (nostoKey, slotId = "", recommendationsType, productIds, skip) => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
if (skip) {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
const isPDP = productIds && productIds.length > 0;
|
|
132
|
+
if (isPDP) {
|
|
133
|
+
return fetchPDPRecommendations(nostoKey, productIds[0], slotId, recommendationsType);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
return fetchHomeRecommendations(nostoKey, slotId);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
function useNostoRecommendationsProductIds(nostoKey, slotId = "", recommendationsType, productIds, skip) {
|
|
140
|
+
const [recommendedProductIds, setRecommendedProductIds] = useState([]);
|
|
73
141
|
const [isLoading, setIsLoading] = useState(true);
|
|
74
142
|
const [error, setError] = useState(null);
|
|
75
143
|
useEffect(() => {
|
|
76
144
|
function fetchNostoData() {
|
|
77
145
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
146
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
147
|
+
if (!nostoKey) {
|
|
148
|
+
setRecommendedProductIds([]);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const productIdRecommendations = yield getProductIdRecommendations(nostoKey, slotId, recommendationsType, productIds, skip);
|
|
152
|
+
setRecommendedProductIds(productIdRecommendations);
|
|
153
|
+
}
|
|
81
154
|
}
|
|
82
155
|
catch (err) {
|
|
83
156
|
console.error("Error fetching recommendations:", err);
|
|
@@ -89,10 +162,22 @@ export function useNostoRecommendations(integrations, baseURL, slotId = null) {
|
|
|
89
162
|
});
|
|
90
163
|
}
|
|
91
164
|
fetchNostoData();
|
|
92
|
-
}, [
|
|
93
|
-
|
|
165
|
+
}, [nostoKey, slotId, recommendationsType, productIds, skip]);
|
|
166
|
+
return {
|
|
167
|
+
recommendedProductIds,
|
|
168
|
+
isLoading,
|
|
169
|
+
error,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
export function useNostoRecommendations(integrations, baseURL, slotId = "", recommendationsType, productIds, skip) {
|
|
173
|
+
var _a;
|
|
174
|
+
if (recommendationsType === "") {
|
|
175
|
+
recommendationsType = NostoRecommendationsType.BOUGHT_TOGETHER;
|
|
176
|
+
}
|
|
177
|
+
const nostoKey = (_a = integrations.find((integration) => integration.name === "nosto")) === null || _a === void 0 ? void 0 : _a.key;
|
|
178
|
+
const { recommendedProductIds, isLoading, error } = useNostoRecommendationsProductIds(nostoKey, slotId, recommendationsType, productIds, skip);
|
|
94
179
|
const { products, error: productsError, isLoading: productsLoading, } = useProducts({
|
|
95
|
-
productIds,
|
|
180
|
+
productIds: recommendedProductIds,
|
|
96
181
|
baseURL,
|
|
97
182
|
productHandles: [],
|
|
98
183
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NostoRecommendationsType } from "./use-nosto-recommendation";
|
|
2
|
+
type NostoPageResponse<T extends string> = {
|
|
3
|
+
data?: {
|
|
4
|
+
updateSession?: {
|
|
5
|
+
pages?: {
|
|
6
|
+
[K in T]: Array<{
|
|
7
|
+
primary: Array<{
|
|
8
|
+
productId: string;
|
|
9
|
+
}>;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export type NostoFrontPageResponse = NostoPageResponse<"forFrontPage">;
|
|
16
|
+
export type NostoProductPageResponse = NostoPageResponse<"forProductPage">;
|
|
17
|
+
export type NostoCategoryPageResponse = NostoPageResponse<"forCategoryPage">;
|
|
18
|
+
export type NostoBestSellersResponse = {
|
|
19
|
+
data?: {
|
|
20
|
+
recos?: {
|
|
21
|
+
toplist?: {
|
|
22
|
+
primary: Array<{
|
|
23
|
+
name: string;
|
|
24
|
+
productId: string;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export type NostoRelatedProductsResponse = {
|
|
31
|
+
data?: {
|
|
32
|
+
recos?: {
|
|
33
|
+
related?: {
|
|
34
|
+
primary: Array<{
|
|
35
|
+
productId: string;
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export declare const getFrontPageRecommendationsQuery: (sessionId: string, slotId?: string) => string;
|
|
42
|
+
export declare const getProductPageRecommendationsQuery: (sessionId: string, productId: string, slotId?: string) => string;
|
|
43
|
+
export declare const categoryPageRecommendationsQuery: (sessionId: string, sourceCollectionTitle: string) => string;
|
|
44
|
+
export declare const bestSellersRecommendationsQuery: string;
|
|
45
|
+
export declare const getRelatedProductsRecommendationsQuery: (recommendationsType: NostoRecommendationsType, productIds: string[]) => string;
|
|
46
|
+
export declare const newSessionQuery: string;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=use-nosto-recommendation.queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-nosto-recommendation.queries.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-nosto-recommendation.queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAErE,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,IAAI;IACzC,IAAI,CAAC,EAAE;QACL,aAAa,CAAC,EAAE;YACd,KAAK,CAAC,EAAE;iBACL,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;oBACd,OAAO,EAAE,KAAK,CAAC;wBAAE,SAAS,EAAE,MAAM,CAAA;qBAAE,CAAC,CAAA;iBACtC,CAAC;aACH,CAAA;SACF,CAAA;KACF,CAAA;CACF,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG,iBAAiB,CAAC,cAAc,CAAC,CAAA;AACtE,MAAM,MAAM,wBAAwB,GAAG,iBAAiB,CAAC,gBAAgB,CAAC,CAAA;AAC1E,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAAA;AAE5E,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,CAAC,EAAE;QACL,KAAK,CAAC,EAAE;YACN,OAAO,CAAC,EAAE;gBACR,OAAO,EAAE,KAAK,CAAC;oBAAE,IAAI,EAAE,MAAM,CAAC;oBAAC,SAAS,EAAE,MAAM,CAAA;iBAAE,CAAC,CAAA;aACpD,CAAA;SACF,CAAA;KACF,CAAA;CACF,CAAA;AACD,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,CAAC,EAAE;QACL,KAAK,CAAC,EAAE;YACN,OAAO,CAAC,EAAE;gBACR,OAAO,EAAE,KAAK,CAAC;oBAAE,SAAS,EAAE,MAAM,CAAA;iBAAE,CAAC,CAAA;aACtC,CAAA;SACF,CAAA;KACF,CAAA;CACF,CAAA;AAGD,eAAO,MAAM,gCAAgC,cAAe,MAAM,WAAW,MAAM,WAiC3E,CAAA;AAER,eAAO,MAAM,kCAAkC,cAAe,MAAM,aAAa,MAAM,WAAW,MAAM,WAqChG,CAAA;AAER,eAAO,MAAM,gCAAgC,cAAe,MAAM,yBAAyB,MAAM,WAqCzF,CAAA;AAGR,eAAO,MAAM,+BAA+B,QAe1C,CAAA;AAEF,eAAO,MAAM,sCAAsC,wBAAyB,wBAAwB,cAAc,MAAM,EAAE,WAqBlH,CAAA;AAGR,eAAO,MAAM,eAAe,QAE1B,CAAA"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
export const getFrontPageRecommendationsQuery = (sessionId, slotId) => JSON.stringify({
|
|
2
|
+
query: `
|
|
3
|
+
mutation GetFrontPageRecommendations($sessionId: String!${slotId ? `, $slotId: String` : ""} ) {
|
|
4
|
+
updateSession(
|
|
5
|
+
by: BY_CID
|
|
6
|
+
id: $sessionId
|
|
7
|
+
params: {
|
|
8
|
+
event: { type: VIEWED_PAGE, target: "home" }
|
|
9
|
+
}
|
|
10
|
+
) {
|
|
11
|
+
pages {
|
|
12
|
+
forFrontPage(
|
|
13
|
+
params: {
|
|
14
|
+
isPreview: false
|
|
15
|
+
imageVersion: VERSION_8_400_400
|
|
16
|
+
${slotId ? `slotIds: [$slotId]` : ""}
|
|
17
|
+
}
|
|
18
|
+
) {
|
|
19
|
+
primary {
|
|
20
|
+
productId
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
`,
|
|
27
|
+
variables: {
|
|
28
|
+
sessionId,
|
|
29
|
+
slotId,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
export const getProductPageRecommendationsQuery = (sessionId, productId, slotId) => JSON.stringify({
|
|
33
|
+
query: `
|
|
34
|
+
mutation GetProductPageRecommendations($sessionId: String!, $productId: String!${slotId ? `, $slotId: String` : ""} ) {
|
|
35
|
+
updateSession(
|
|
36
|
+
by: BY_CID
|
|
37
|
+
id: $sessionId
|
|
38
|
+
params: {
|
|
39
|
+
event: { type: VIEWED_PRODUCT, target: $productId }
|
|
40
|
+
}
|
|
41
|
+
) {
|
|
42
|
+
id
|
|
43
|
+
pages {
|
|
44
|
+
forProductPage(
|
|
45
|
+
product: $productId
|
|
46
|
+
params: {
|
|
47
|
+
isPreview: false
|
|
48
|
+
${slotId ? `slotIds: [$slotId]` : ""}
|
|
49
|
+
}
|
|
50
|
+
) {
|
|
51
|
+
resultId
|
|
52
|
+
primary {
|
|
53
|
+
name
|
|
54
|
+
productId
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
`,
|
|
61
|
+
variables: {
|
|
62
|
+
sessionId,
|
|
63
|
+
productId,
|
|
64
|
+
slotId,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
export const categoryPageRecommendationsQuery = (sessionId, sourceCollectionTitle) => JSON.stringify({
|
|
68
|
+
query: `
|
|
69
|
+
mutation CategoryPageRecommendations($sessionId: String!, $sourceCollectionTitle: String!) {
|
|
70
|
+
updateSession(
|
|
71
|
+
by: BY_CID
|
|
72
|
+
id: $sessionId
|
|
73
|
+
params: {
|
|
74
|
+
event: {
|
|
75
|
+
type: VIEWED_CATEGORY
|
|
76
|
+
target: $sourceCollectionTitle
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
) {
|
|
80
|
+
id
|
|
81
|
+
pages {
|
|
82
|
+
forCategoryPage(
|
|
83
|
+
params: {
|
|
84
|
+
isPreview: false
|
|
85
|
+
imageVersion: VERSION_8_400_400
|
|
86
|
+
}
|
|
87
|
+
category: $sourceCollectionTitle
|
|
88
|
+
) {
|
|
89
|
+
resultId
|
|
90
|
+
primary {
|
|
91
|
+
name
|
|
92
|
+
productId
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
`,
|
|
99
|
+
variables: {
|
|
100
|
+
sessionId,
|
|
101
|
+
sourceCollectionTitle,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
export const bestSellersRecommendationsQuery = JSON.stringify({
|
|
105
|
+
query: `query GetBestSellersRecommendations {
|
|
106
|
+
recos(preview: false, image: VERSION_7_200_200) {
|
|
107
|
+
toplist(hours: 168, sort: BUYS, params: {
|
|
108
|
+
minProducts: 1
|
|
109
|
+
maxProducts: 10
|
|
110
|
+
}) {
|
|
111
|
+
resultId
|
|
112
|
+
primary {
|
|
113
|
+
name
|
|
114
|
+
productId
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}`,
|
|
119
|
+
});
|
|
120
|
+
export const getRelatedProductsRecommendationsQuery = (recommendationsType, productIds) => JSON.stringify({
|
|
121
|
+
query: `
|
|
122
|
+
query GetRelatedProductsRecommendations($relationship: RelationModeEntity!, $productIds: [String!]!) {
|
|
123
|
+
recos(preview: false, image: VERSION_7_200_200) {
|
|
124
|
+
related(
|
|
125
|
+
relationship: $relationship
|
|
126
|
+
productIds: $productIds
|
|
127
|
+
params: { minProducts: 1, maxProducts: 10 }
|
|
128
|
+
) {
|
|
129
|
+
primary {
|
|
130
|
+
productId
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
`,
|
|
136
|
+
variables: {
|
|
137
|
+
relationship: recommendationsType,
|
|
138
|
+
productIds: productIds,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
export const newSessionQuery = JSON.stringify({
|
|
142
|
+
query: `mutation { newSession }`,
|
|
143
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-nosto-recommendation.test.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-nosto-recommendation.test.ts"],"names":[],"mappings":""}
|