@odynn/awayz-core 0.4.5 → 0.4.6
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/CashValue/CashValue.js +4 -1
- package/dist/hooks/useAwayzAuth/useAwayzAuth.js +55 -51
- package/dist/hooks/useBookingManagement/useBookingManagement.test.js +1 -1
- package/dist/lib/services/currency/CurrencyService.d.ts +1 -1
- package/dist/services/currency/CurrencyService.js +28 -27
- package/package.json +1 -1
|
@@ -792,7 +792,10 @@ const Pr = 1e3 * 60 * 60, Vr = ({
|
|
|
792
792
|
var f, v;
|
|
793
793
|
const { user: s } = wt(), a = ((f = s == null ? void 0 : s.preferences) == null ? void 0 : f.currency) ?? ((v = s == null ? void 0 : s.userRegion) == null ? void 0 : v.currency), u = a !== t, { data: l, isPending: p } = Ct({
|
|
794
794
|
queryKey: [Et.CONVERT_CURRENCY, t, a],
|
|
795
|
-
queryFn: () => Pt.convertCurrency({
|
|
795
|
+
queryFn: () => Pt.convertCurrency({
|
|
796
|
+
baseCurrency: t,
|
|
797
|
+
targetCurrency: a
|
|
798
|
+
}),
|
|
796
799
|
enabled: u,
|
|
797
800
|
staleTime: Pr
|
|
798
801
|
}), d = nt(() => {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import "../../arrayExtensions-DlcBOj5a.js";
|
|
2
|
-
import { f as
|
|
3
|
-
import { useState as
|
|
4
|
-
import { awayzClient as
|
|
2
|
+
import { f as U, d as n, A as o, E as K } from "../../AccountService-DdcBI9BS.js";
|
|
3
|
+
import { useState as E, useCallback as A, useEffect as w } from "react";
|
|
4
|
+
import { awayzClient as h } from "../../configs/awayzClient.js";
|
|
5
5
|
import { PreferencesService as v } from "../../services/preferences/PreferencesService.js";
|
|
6
|
-
import { EAuthFlow as
|
|
7
|
-
const
|
|
6
|
+
import { EAuthFlow as T } from "../../types/EAuthFlow.js";
|
|
7
|
+
const P = (t, r) => {
|
|
8
8
|
var g, y;
|
|
9
|
-
let c = "",
|
|
10
|
-
typeof r == "string" ? c = r : r instanceof
|
|
9
|
+
let c = "", m = r;
|
|
10
|
+
typeof r == "string" ? c = r : r instanceof U ? (c = r.message, m = {
|
|
11
11
|
message: r.message,
|
|
12
12
|
cause: r.cause,
|
|
13
13
|
status: r.status,
|
|
@@ -15,24 +15,24 @@ const C = (t, r) => {
|
|
|
15
15
|
}) : c = r.message, (y = window.parent) == null || y.postMessage(
|
|
16
16
|
{
|
|
17
17
|
type: "auth_error",
|
|
18
|
-
details: { message: c, action: t, info:
|
|
18
|
+
details: { message: c, action: t, info: m }
|
|
19
19
|
},
|
|
20
20
|
"*"
|
|
21
21
|
);
|
|
22
|
-
},
|
|
23
|
-
const [r, c] =
|
|
22
|
+
}, $ = (t) => {
|
|
23
|
+
const [r, c] = E(!0), [m, g] = E(!1), [y, O] = E(), [d, k] = E(), [N, I] = E([]), S = A(
|
|
24
24
|
async (s) => {
|
|
25
|
-
t != null && t.onSuccess && (t == null || t.onSuccess(s)), t != null && t.onSuccessAsync && await (t == null ? void 0 : t.onSuccessAsync(s)), c(!1), g(!0),
|
|
25
|
+
t != null && t.onSuccess && (t == null || t.onSuccess(s)), t != null && t.onSuccessAsync && await (t == null ? void 0 : t.onSuccessAsync(s)), c(!1), g(!0), O(s.token), k(s.user), h.invalidateQueries();
|
|
26
26
|
},
|
|
27
27
|
[t]
|
|
28
28
|
), i = A(
|
|
29
29
|
async (s, e) => {
|
|
30
|
-
if (t.authFlow !==
|
|
31
|
-
return
|
|
30
|
+
if (t.authFlow !== T.POST_MESSAGE)
|
|
31
|
+
return P(e ?? "exchange_token", s);
|
|
32
32
|
t != null && t.onError && (t == null || t.onError(s)), t != null && t.onErrorAsync && await (t == null ? void 0 : t.onErrorAsync(s)), c(!1);
|
|
33
33
|
},
|
|
34
34
|
[t]
|
|
35
|
-
),
|
|
35
|
+
), R = async (s) => {
|
|
36
36
|
try {
|
|
37
37
|
const { success: e, data: a, message: u } = await o.authenticateWithToken(s);
|
|
38
38
|
if (!e) {
|
|
@@ -43,17 +43,17 @@ const C = (t, r) => {
|
|
|
43
43
|
i("no awayz token returned after exchanging id token");
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
|
-
localStorage.setItem(n.TOKEN, a.token), await
|
|
47
|
-
const { data:
|
|
48
|
-
if (!
|
|
49
|
-
console.error({ reqLimitError:
|
|
46
|
+
localStorage.setItem(n.TOKEN, a.token), await S(a);
|
|
47
|
+
const { data: l, ...f } = await o.getRequestLimit();
|
|
48
|
+
if (!f.success) {
|
|
49
|
+
console.error({ reqLimitError: f });
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
(
|
|
52
|
+
l == null || l.forEach(
|
|
53
|
+
(C) => window.parent.postMessage(
|
|
54
54
|
{
|
|
55
55
|
type: "request_limit",
|
|
56
|
-
limit:
|
|
56
|
+
limit: C
|
|
57
57
|
},
|
|
58
58
|
"*"
|
|
59
59
|
)
|
|
@@ -63,17 +63,17 @@ const C = (t, r) => {
|
|
|
63
63
|
} finally {
|
|
64
64
|
c(!1);
|
|
65
65
|
}
|
|
66
|
-
},
|
|
66
|
+
}, _ = async () => {
|
|
67
67
|
try {
|
|
68
|
-
const { success: s, data: e } = await
|
|
69
|
-
queryKey: [
|
|
68
|
+
const { success: s, data: e } = await h.ensureQueryData({
|
|
69
|
+
queryKey: [K.CHECK_USER],
|
|
70
70
|
queryFn: o.checkUser
|
|
71
71
|
});
|
|
72
72
|
if (!s) {
|
|
73
73
|
i(e);
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
await
|
|
76
|
+
await S({
|
|
77
77
|
user: e,
|
|
78
78
|
token: localStorage.getItem(n.TOKEN)
|
|
79
79
|
});
|
|
@@ -83,48 +83,48 @@ const C = (t, r) => {
|
|
|
83
83
|
c(!1);
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
|
-
|
|
87
|
-
if (t.authFlow !==
|
|
86
|
+
w(() => {
|
|
87
|
+
if (t.authFlow !== T.STANDARD) return;
|
|
88
88
|
const s = localStorage.getItem(n.TOKEN), e = localStorage.getItem(n.REFRESH_TOKEN);
|
|
89
|
-
s && e ?
|
|
89
|
+
s && e ? _() : c(!1);
|
|
90
90
|
}, []);
|
|
91
91
|
const F = async () => {
|
|
92
92
|
const s = await o.getRegions();
|
|
93
|
-
|
|
93
|
+
I(s);
|
|
94
94
|
};
|
|
95
|
-
return
|
|
95
|
+
return w(() => {
|
|
96
96
|
F();
|
|
97
|
-
}, []),
|
|
98
|
-
if (t.authFlow !==
|
|
97
|
+
}, []), w(() => {
|
|
98
|
+
if (t.authFlow !== T.QUERY) return;
|
|
99
99
|
const e = new URLSearchParams(window.location.search).get(n.TOKEN);
|
|
100
|
-
e &&
|
|
101
|
-
}, []),
|
|
102
|
-
if (t.authFlow !==
|
|
100
|
+
e && R(e);
|
|
101
|
+
}, []), w(() => {
|
|
102
|
+
if (t.authFlow !== T.POST_MESSAGE) return;
|
|
103
103
|
const s = async (e) => {
|
|
104
|
-
var
|
|
104
|
+
var l;
|
|
105
105
|
if (e.data.type !== "auth") return;
|
|
106
|
-
const a = (
|
|
106
|
+
const a = (l = e.data) == null ? void 0 : l.idToken, u = e.data.refreshToken;
|
|
107
107
|
if (!a) {
|
|
108
|
-
const
|
|
108
|
+
const f = `received message ${JSON.stringify(
|
|
109
109
|
e.data
|
|
110
110
|
)}
|
|
111
111
|
no idToken in body`;
|
|
112
|
-
i(
|
|
112
|
+
i(f);
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
if (!u) {
|
|
116
|
-
const
|
|
116
|
+
const f = `received message: ${JSON.stringify(
|
|
117
117
|
e.data
|
|
118
118
|
)}
|
|
119
119
|
no refreshToken in body`;
|
|
120
120
|
i(
|
|
121
|
-
|
|
121
|
+
f,
|
|
122
122
|
"refresh_token"
|
|
123
123
|
/* REFRESH */
|
|
124
124
|
);
|
|
125
125
|
return;
|
|
126
126
|
}
|
|
127
|
-
localStorage.setItem(n.REFRESH_TOKEN, u), await
|
|
127
|
+
localStorage.setItem(n.REFRESH_TOKEN, u), await R(a);
|
|
128
128
|
};
|
|
129
129
|
return window.addEventListener("message", s), window.parent && window.parent.postMessage(
|
|
130
130
|
{
|
|
@@ -137,10 +137,10 @@ const C = (t, r) => {
|
|
|
137
137
|
};
|
|
138
138
|
}, []), {
|
|
139
139
|
isAuthenticating: r,
|
|
140
|
-
isAuthenticated:
|
|
140
|
+
isAuthenticated: m,
|
|
141
141
|
token: y,
|
|
142
142
|
user: d,
|
|
143
|
-
supportedRegions:
|
|
143
|
+
supportedRegions: N,
|
|
144
144
|
signIn: async (s) => {
|
|
145
145
|
var a;
|
|
146
146
|
const e = await o.login(s);
|
|
@@ -148,7 +148,7 @@ const C = (t, r) => {
|
|
|
148
148
|
i(e.message);
|
|
149
149
|
else {
|
|
150
150
|
const u = (a = e.data) == null ? void 0 : a.refreshToken;
|
|
151
|
-
localStorage.setItem(n.REFRESH_TOKEN, u), await
|
|
151
|
+
localStorage.setItem(n.REFRESH_TOKEN, u), await S(e.data);
|
|
152
152
|
}
|
|
153
153
|
return e;
|
|
154
154
|
},
|
|
@@ -159,16 +159,16 @@ const C = (t, r) => {
|
|
|
159
159
|
i(e.message);
|
|
160
160
|
else {
|
|
161
161
|
const u = (a = e.data) == null ? void 0 : a.refreshToken;
|
|
162
|
-
localStorage.setItem(n.REFRESH_TOKEN, u), await
|
|
162
|
+
localStorage.setItem(n.REFRESH_TOKEN, u), await S(e.data);
|
|
163
163
|
}
|
|
164
164
|
return e;
|
|
165
165
|
},
|
|
166
166
|
signOut: () => {
|
|
167
|
-
localStorage.removeItem(n.TOKEN), localStorage.removeItem(n.REFRESH_TOKEN), g(!1),
|
|
167
|
+
localStorage.removeItem(n.TOKEN), localStorage.removeItem(n.REFRESH_TOKEN), g(!1), O(void 0), k(void 0);
|
|
168
168
|
},
|
|
169
169
|
resendVerificationEmail: async (s) => (await o.resendVerificationEmail(s)).success,
|
|
170
170
|
setTokens: (s, e) => {
|
|
171
|
-
localStorage.setItem(n.TOKEN, s), localStorage.setItem(n.REFRESH_TOKEN, e),
|
|
171
|
+
localStorage.setItem(n.TOKEN, s), localStorage.setItem(n.REFRESH_TOKEN, e), R(s);
|
|
172
172
|
},
|
|
173
173
|
setPreferredCurrency: async (s) => {
|
|
174
174
|
const e = await v.setCurrency(s);
|
|
@@ -182,13 +182,17 @@ const C = (t, r) => {
|
|
|
182
182
|
currency: e.data.currency || d.preferences.currency
|
|
183
183
|
}
|
|
184
184
|
};
|
|
185
|
-
|
|
185
|
+
k(a), h.invalidateQueries({
|
|
186
|
+
queryKey: [K.CONVERT_CURRENCY]
|
|
187
|
+
}), h.invalidateQueries({
|
|
188
|
+
queryKey: [K.CHECK_USER]
|
|
189
|
+
});
|
|
186
190
|
}
|
|
187
191
|
return !0;
|
|
188
192
|
}
|
|
189
193
|
};
|
|
190
194
|
};
|
|
191
195
|
export {
|
|
192
|
-
|
|
193
|
-
|
|
196
|
+
P as authFailurePostMessage,
|
|
197
|
+
$ as useAwayzAuth
|
|
194
198
|
};
|
|
@@ -5,9 +5,9 @@ import "../../services/noRetryInstance.js";
|
|
|
5
5
|
import "../../arrayExtensions-DlcBOj5a.js";
|
|
6
6
|
import "react";
|
|
7
7
|
import { EBookingEndpoints as c } from "../../configs/endpoints.js";
|
|
8
|
-
import "../../configs/awayzClient.js";
|
|
9
8
|
import "react/jsx-runtime";
|
|
10
9
|
import "../../context/AwayzContext.js";
|
|
10
|
+
import "../../configs/awayzClient.js";
|
|
11
11
|
import "@tanstack/react-query";
|
|
12
12
|
import { EBookingType as n } from "../../services/trips/TripService.types.js";
|
|
13
13
|
import '../../assets/_styles5.css';import '../../assets/_styles4.css';import '../../assets/_styles3.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';/* empty css */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IConvertCurrencyArgs } from './CurrencyService.types';
|
|
2
2
|
declare class _CurrencyService {
|
|
3
|
-
convertCurrency: ({ baseCurrency }: IConvertCurrencyArgs) => Promise<number>;
|
|
3
|
+
convertCurrency: ({ baseCurrency, targetCurrency }: IConvertCurrencyArgs) => Promise<number>;
|
|
4
4
|
/**
|
|
5
5
|
* Convert from base currency to target currency for the amount provided
|
|
6
6
|
* @param param0 IConvertCurrencyArgs
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import '../../assets/_styles5.css';import '../../assets/_styles4.css';import '../../assets/_styles3.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';var
|
|
2
|
-
var
|
|
3
|
-
var n = (t, r, e) =>
|
|
1
|
+
import '../../assets/_styles5.css';import '../../assets/_styles4.css';import '../../assets/_styles3.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';var p = Object.defineProperty;
|
|
2
|
+
var m = (t, r, e) => r in t ? p(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
|
|
3
|
+
var n = (t, r, e) => m(t, typeof r != "symbol" ? r + "" : r, e);
|
|
4
4
|
import "../../arrayExtensions-DlcBOj5a.js";
|
|
5
|
-
import { A as
|
|
5
|
+
import { A as C, E, c as s } from "../../AccountService-DdcBI9BS.js";
|
|
6
6
|
import "react";
|
|
7
|
-
import { ECurrencyEndpoints as
|
|
7
|
+
import { ECurrencyEndpoints as a } from "../../configs/endpoints.js";
|
|
8
8
|
import "react/jsx-runtime";
|
|
9
9
|
import "../../context/AwayzContext.js";
|
|
10
|
-
import { awayzClient as
|
|
10
|
+
import { awayzClient as _ } from "../../configs/awayzClient.js";
|
|
11
11
|
import "@tanstack/react-query";
|
|
12
12
|
import "../noRetryInstance.js";
|
|
13
13
|
/* empty css */
|
|
@@ -15,26 +15,27 @@ import "../noRetryInstance.js";
|
|
|
15
15
|
/* empty css */
|
|
16
16
|
/* empty css */
|
|
17
17
|
/* empty css */
|
|
18
|
-
class
|
|
18
|
+
class d {
|
|
19
19
|
constructor() {
|
|
20
20
|
n(this, "convertCurrency", async ({
|
|
21
|
-
baseCurrency: r
|
|
21
|
+
baseCurrency: r,
|
|
22
|
+
targetCurrency: e
|
|
22
23
|
}) => {
|
|
23
24
|
try {
|
|
24
|
-
const { success:
|
|
25
|
-
queryKey: [
|
|
26
|
-
queryFn:
|
|
25
|
+
const { success: c, data: o } = await _.ensureQueryData({
|
|
26
|
+
queryKey: [E.CHECK_USER],
|
|
27
|
+
queryFn: C.checkUser
|
|
27
28
|
});
|
|
28
|
-
if (!
|
|
29
|
+
if (!c)
|
|
29
30
|
throw new Error("Failed to fetch user data");
|
|
30
|
-
const { userRegion:
|
|
31
|
-
target_currency:
|
|
31
|
+
const { userRegion: i, preferences: u } = o, { data: y } = await s.post(a.CURRENCY_CONVERSION, {
|
|
32
|
+
target_currency: e ?? u.currency ?? i.currency,
|
|
32
33
|
base_currency: r
|
|
33
34
|
});
|
|
34
|
-
if (
|
|
35
|
-
return
|
|
36
|
-
} catch (
|
|
37
|
-
console.error(
|
|
35
|
+
if (c)
|
|
36
|
+
return y.data.conversion_rate;
|
|
37
|
+
} catch (c) {
|
|
38
|
+
console.error(c);
|
|
38
39
|
}
|
|
39
40
|
return 0;
|
|
40
41
|
});
|
|
@@ -49,24 +50,24 @@ class E {
|
|
|
49
50
|
n(this, "convertToCurrency", async ({
|
|
50
51
|
baseCurrency: r,
|
|
51
52
|
targetCurrency: e,
|
|
52
|
-
amount:
|
|
53
|
+
amount: c
|
|
53
54
|
}) => {
|
|
54
55
|
try {
|
|
55
|
-
const { data:
|
|
56
|
+
const { data: o } = await s.post(a.CURRENCY_CONVERSION, {
|
|
56
57
|
target_currency: e,
|
|
57
58
|
base_currency: r,
|
|
58
|
-
amount:
|
|
59
|
+
amount: c
|
|
59
60
|
});
|
|
60
|
-
if (
|
|
61
|
-
return
|
|
62
|
-
} catch (
|
|
63
|
-
console.error(
|
|
61
|
+
if (o.success)
|
|
62
|
+
return o.data.conversion_result;
|
|
63
|
+
} catch (o) {
|
|
64
|
+
console.error(o);
|
|
64
65
|
}
|
|
65
66
|
return 0;
|
|
66
67
|
});
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
|
-
const
|
|
70
|
+
const A = new d();
|
|
70
71
|
export {
|
|
71
|
-
|
|
72
|
+
A as CurrencyService
|
|
72
73
|
};
|