wineater-bot 4.5.12 → 4.7.0
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/package.json +1 -1
- package/src/services/api/api.ts +19 -4
package/package.json
CHANGED
package/src/services/api/api.ts
CHANGED
|
@@ -36,14 +36,19 @@ export type RecommendedWine = Omit<Wine, "shortDescription" | "producer" | "pair
|
|
|
36
36
|
class WineaterApi {
|
|
37
37
|
#baseUrl = 'http://localhost:3000/';
|
|
38
38
|
#token: string;
|
|
39
|
+
#apiVersion: string;
|
|
39
40
|
|
|
40
|
-
constructor(token: string) {
|
|
41
|
+
constructor(token: string, apiVersion: string = '1') {
|
|
41
42
|
this.#token = token;
|
|
43
|
+
this.#apiVersion = apiVersion;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
async getInstantRecommendations(): Promise<Wine[]> {
|
|
45
47
|
try {
|
|
46
|
-
const
|
|
48
|
+
const endpoint = this.#apiVersion === '2'
|
|
49
|
+
? 'dish/recommendations/instant/v2'
|
|
50
|
+
: 'dish/recommendations/instant';
|
|
51
|
+
const response = await fetch(`${this.#baseUrl}${endpoint}`, {
|
|
47
52
|
method: 'POST',
|
|
48
53
|
headers: {
|
|
49
54
|
'Content-Type': 'application/json',
|
|
@@ -66,7 +71,10 @@ class WineaterApi {
|
|
|
66
71
|
|
|
67
72
|
async getWineRecommendationsSearch(text): Promise<RecommendedWine[]> {
|
|
68
73
|
try {
|
|
69
|
-
const
|
|
74
|
+
const endpoint = this.#apiVersion === '2'
|
|
75
|
+
? 'dish/recommendations/search/v2'
|
|
76
|
+
: 'dish/recommendations/search';
|
|
77
|
+
const response = await fetch(`${this.#baseUrl}${endpoint}`, {
|
|
70
78
|
method: 'POST',
|
|
71
79
|
headers: {
|
|
72
80
|
'Content-Type': 'application/json',
|
|
@@ -107,6 +115,13 @@ class WineaterApi {
|
|
|
107
115
|
}
|
|
108
116
|
}
|
|
109
117
|
|
|
118
|
+
function getApiVersion(): string {
|
|
119
|
+
const scriptTag = (document.currentScript as HTMLScriptElement | null)
|
|
120
|
+
|| document.querySelector('script[src*="embed.js"]');
|
|
121
|
+
return scriptTag?.getAttribute('api-version') || '1';
|
|
122
|
+
}
|
|
123
|
+
|
|
110
124
|
const DEMO_TOKEN = 'HeUw6IXuhvz6tRuXdPEGEbj3SGQ3Q2YtEc1Z8jd41Kg9LtyPb4Epu0to31SYIadG';
|
|
111
125
|
const token = window?.wineaterData?.CLIENT_TOKEN || DEMO_TOKEN;
|
|
112
|
-
|
|
126
|
+
const apiVersion = getApiVersion();
|
|
127
|
+
export const wineaterApi = new WineaterApi(token, apiVersion)
|