@odynn/awayz-core 0.9.10 → 0.9.12
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.
|
@@ -9,7 +9,7 @@ import "react-i18next";
|
|
|
9
9
|
import '../../assets/_styles3.css';import '../../assets/_styles.css';import '../../assets/_styles2.css';/* empty css */
|
|
10
10
|
import "../../_styles.flight-booking-DEUJthTJ.js";
|
|
11
11
|
/* empty css */
|
|
12
|
-
import { EInvalidAmountDisplayOption as
|
|
12
|
+
import { EInvalidAmountDisplayOption as t, EToolTipPosition as T } from "./CashValueTypes.js";
|
|
13
13
|
import { useAwayzContext as D } from "../../hooks/useAwayzContext.js";
|
|
14
14
|
import "../../configs/awayzClient.js";
|
|
15
15
|
/* empty css */
|
|
@@ -17,49 +17,49 @@ import "../../context/AwayzContext.js";
|
|
|
17
17
|
import { CurrencyService as I } from "../../services/currency/CurrencyService.js";
|
|
18
18
|
import { Tooltip as M } from "../Tooltip/Tooltip.js";
|
|
19
19
|
const O = 1e3 * 60 * 60, G = ({
|
|
20
|
-
amount:
|
|
20
|
+
amount: o,
|
|
21
21
|
currency: n,
|
|
22
|
-
position:
|
|
23
|
-
zeroDisplayOption:
|
|
24
|
-
customDisplay:
|
|
25
|
-
decimalPlaces:
|
|
22
|
+
position: A = T.RIGHT,
|
|
23
|
+
zeroDisplayOption: v = t.NA,
|
|
24
|
+
customDisplay: y,
|
|
25
|
+
decimalPlaces: p = 0,
|
|
26
26
|
showConversion: g = !0
|
|
27
27
|
}) => {
|
|
28
28
|
var h, C;
|
|
29
|
-
const { user: i } = D(), e = ((h = i == null ? void 0 : i.preferences) == null ? void 0 : h.currency) ?? ((C = i == null ? void 0 : i.userRegion) == null ? void 0 : C.currency), s = e !== n, { data: c, isPending:
|
|
29
|
+
const { user: i } = D(), e = ((h = i == null ? void 0 : i.preferences) == null ? void 0 : h.currency) ?? ((C = i == null ? void 0 : i.userRegion) == null ? void 0 : C.currency), s = e !== n, { data: c, isPending: m } = E({
|
|
30
30
|
queryKey: [_.CONVERT_CURRENCY, n, e],
|
|
31
31
|
queryFn: () => I.convertCurrency({
|
|
32
32
|
baseCurrency: n,
|
|
33
33
|
targetCurrency: e
|
|
34
34
|
}),
|
|
35
|
-
enabled: s,
|
|
35
|
+
enabled: s && !!n && !!o,
|
|
36
36
|
staleTime: O
|
|
37
37
|
}), a = S(() => {
|
|
38
38
|
if (!i)
|
|
39
39
|
return null;
|
|
40
|
-
let d = typeof
|
|
40
|
+
let d = typeof o == "string" ? parseFloat(o) : o;
|
|
41
41
|
if (s) {
|
|
42
|
-
if (
|
|
42
|
+
if (m || !c) return null;
|
|
43
43
|
d = d * c;
|
|
44
44
|
}
|
|
45
45
|
return d;
|
|
46
|
-
}, [
|
|
47
|
-
if (
|
|
48
|
-
return /* @__PURE__ */ r("span", { className: "currency-conversion loading", children:
|
|
46
|
+
}, [o, i, m, s, c]);
|
|
47
|
+
if (m && s)
|
|
48
|
+
return /* @__PURE__ */ r("span", { className: "currency-conversion loading", children: o });
|
|
49
49
|
if (!e || !a || a < 0)
|
|
50
|
-
switch (
|
|
51
|
-
case
|
|
50
|
+
switch (v) {
|
|
51
|
+
case t.NA:
|
|
52
52
|
return /* @__PURE__ */ r("span", { children: "N/A" });
|
|
53
|
-
case
|
|
53
|
+
case t.HIDDEN:
|
|
54
54
|
return /* @__PURE__ */ r("span", { className: "hidden", children: "N/A" });
|
|
55
|
-
case
|
|
55
|
+
case t.DISPLAY_AS_ZERO:
|
|
56
56
|
return /* @__PURE__ */ r("span", { children: "0" });
|
|
57
|
-
case
|
|
57
|
+
case t.DISPLAY_AS_ZERO_WITH_CURRENCY:
|
|
58
58
|
return /* @__PURE__ */ r("span", { children: N(0, e ?? n) });
|
|
59
|
-
case
|
|
59
|
+
case t.DISPLAY_AS_ZERO_WITH_CURRENCY_NO_DECIMAL:
|
|
60
60
|
return /* @__PURE__ */ r("span", { children: R(0, e ?? n) });
|
|
61
|
-
case
|
|
62
|
-
return /* @__PURE__ */ r("span", { children: a == 0 ?
|
|
61
|
+
case t.CUSTOM:
|
|
62
|
+
return /* @__PURE__ */ r("span", { children: a == 0 ? y : "N/A" });
|
|
63
63
|
default:
|
|
64
64
|
return /* @__PURE__ */ r("span", { children: "N/A" });
|
|
65
65
|
}
|
|
@@ -67,13 +67,13 @@ const O = 1e3 * 60 * 60, G = ({
|
|
|
67
67
|
u(
|
|
68
68
|
a,
|
|
69
69
|
e,
|
|
70
|
-
|
|
70
|
+
p
|
|
71
71
|
),
|
|
72
72
|
s && g && /* @__PURE__ */ r(
|
|
73
73
|
M,
|
|
74
74
|
{
|
|
75
75
|
trigger: /* @__PURE__ */ r("sup", { children: /* @__PURE__ */ r(f, {}) }),
|
|
76
|
-
position:
|
|
76
|
+
position: A,
|
|
77
77
|
children: /* @__PURE__ */ l("div", { className: "currency-conversion-container", children: [
|
|
78
78
|
/* @__PURE__ */ l("p", { children: [
|
|
79
79
|
"Converted from ",
|
|
@@ -82,11 +82,11 @@ const O = 1e3 * 60 * 60, G = ({
|
|
|
82
82
|
e
|
|
83
83
|
] }),
|
|
84
84
|
/* @__PURE__ */ l("div", { className: "currency-conversion-amounts", children: [
|
|
85
|
-
/* @__PURE__ */ r("div", { children: /* @__PURE__ */ r("p", { children: u(
|
|
85
|
+
/* @__PURE__ */ r("div", { children: /* @__PURE__ */ r("p", { children: u(o, n, p) }) }),
|
|
86
86
|
/* @__PURE__ */ r("div", { children: /* @__PURE__ */ r("p", { children: u(
|
|
87
87
|
a,
|
|
88
88
|
e,
|
|
89
|
-
|
|
89
|
+
p
|
|
90
90
|
) }) }),
|
|
91
91
|
/* @__PURE__ */ r("span", { className: "conversion-icon", children: /* @__PURE__ */ r(f, {}) })
|
|
92
92
|
] }),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "../../arrayExtensions-DlcBOj5a.js";
|
|
2
|
-
import { c as
|
|
3
|
-
import { e as
|
|
4
|
-
import { a as
|
|
5
|
-
import { useState as f, useCallback as I, useEffect as
|
|
2
|
+
import { c as M } from "../../cashUtils-sBirmFfL.js";
|
|
3
|
+
import { e as P, A as l, E as N } from "../../noRetryInstance-C2dRPIQf.js";
|
|
4
|
+
import { a as o } from "../../_styles.flight-booking-DEUJthTJ.js";
|
|
5
|
+
import { useState as f, useCallback as I, useEffect as h } from "react";
|
|
6
6
|
import { awayzClient as O } from "../../configs/awayzClient.js";
|
|
7
7
|
import { PreferencesService as q } from "../../services/preferences/PreferencesService.js";
|
|
8
8
|
import "@tanstack/react-query";
|
|
@@ -13,57 +13,57 @@ import '../../assets/_styles3.css';import '../../assets/_styles4.css';import '..
|
|
|
13
13
|
/* empty css */
|
|
14
14
|
import "../../context/AwayzContext.js";
|
|
15
15
|
/* empty css */
|
|
16
|
-
import { EAuthFlow as
|
|
17
|
-
const
|
|
18
|
-
var g,
|
|
19
|
-
let
|
|
20
|
-
typeof c == "string" ?
|
|
16
|
+
import { EAuthFlow as T } from "../../types/EAuthFlow.js";
|
|
17
|
+
const x = (s, c) => {
|
|
18
|
+
var g, S;
|
|
19
|
+
let i = "", y = c;
|
|
20
|
+
typeof c == "string" ? i = c : c instanceof P ? (i = c.message, y = {
|
|
21
21
|
message: c.message,
|
|
22
22
|
cause: c.cause,
|
|
23
23
|
status: c.status,
|
|
24
24
|
data: (g = c == null ? void 0 : c.response) == null ? void 0 : g.data
|
|
25
|
-
}) :
|
|
25
|
+
}) : i = c.message, (S = window.parent) == null || S.postMessage(
|
|
26
26
|
{
|
|
27
27
|
type: "auth_error",
|
|
28
|
-
details: { message:
|
|
28
|
+
details: { message: i, action: s, info: y }
|
|
29
29
|
},
|
|
30
30
|
"*"
|
|
31
31
|
);
|
|
32
|
-
},
|
|
33
|
-
const [c,
|
|
34
|
-
async (
|
|
35
|
-
|
|
32
|
+
}, ie = (s) => {
|
|
33
|
+
const [c, i] = f(!0), [y, g] = f(!1), [S, A] = f(), [m, k] = f(), [C, _] = f([]), [F, p] = f([]), E = I(
|
|
34
|
+
async (t) => {
|
|
35
|
+
s != null && s.onSuccess && (s == null || s.onSuccess(t)), s != null && s.onSuccessAsync && await (s == null ? void 0 : s.onSuccessAsync(t)), i(!1), g(!0), A(t.token), k(t.user), O.invalidateQueries();
|
|
36
36
|
},
|
|
37
|
-
[
|
|
37
|
+
[s]
|
|
38
38
|
), u = I(
|
|
39
|
-
async (
|
|
40
|
-
if (
|
|
41
|
-
return
|
|
42
|
-
|
|
39
|
+
async (t, e) => {
|
|
40
|
+
if (s.authFlow !== T.POST_MESSAGE)
|
|
41
|
+
return x(e ?? "exchange_token", t);
|
|
42
|
+
s != null && s.onError && (s == null || s.onError(t)), s != null && s.onErrorAsync && await (s == null ? void 0 : s.onErrorAsync(t)), i(!1);
|
|
43
43
|
},
|
|
44
|
-
[
|
|
45
|
-
),
|
|
44
|
+
[s]
|
|
45
|
+
), R = async (t, e, r) => {
|
|
46
46
|
try {
|
|
47
|
-
const { success: a, data: n, message:
|
|
48
|
-
|
|
47
|
+
const { success: a, data: n, message: w } = await l.authenticateWithToken(
|
|
48
|
+
t,
|
|
49
49
|
e,
|
|
50
50
|
r
|
|
51
51
|
);
|
|
52
52
|
if (!a) {
|
|
53
|
-
u(
|
|
53
|
+
u(w);
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
if (!(n != null && n.token)) {
|
|
57
57
|
u("no awayz token returned after exchanging id token");
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
-
localStorage.setItem(
|
|
61
|
-
const { data:
|
|
60
|
+
localStorage.setItem(o.TOKEN, n.token), await E(n);
|
|
61
|
+
const { data: d, ...K } = await l.getRequestLimit();
|
|
62
62
|
if (!K.success) {
|
|
63
63
|
console.error({ reqLimitError: K });
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
d == null || d.forEach(
|
|
67
67
|
(H) => window.parent.postMessage(
|
|
68
68
|
{
|
|
69
69
|
type: "request_limit",
|
|
@@ -75,125 +75,125 @@ const G = (t, c) => {
|
|
|
75
75
|
} catch (a) {
|
|
76
76
|
console.error("error handling message", a);
|
|
77
77
|
} finally {
|
|
78
|
-
|
|
78
|
+
i(!1);
|
|
79
79
|
}
|
|
80
80
|
}, v = async () => {
|
|
81
81
|
try {
|
|
82
|
-
const { success:
|
|
82
|
+
const { success: t, data: e } = await O.ensureQueryData({
|
|
83
83
|
queryKey: [N.CHECK_USER],
|
|
84
84
|
queryFn: l.checkUser
|
|
85
85
|
});
|
|
86
|
-
if (!
|
|
86
|
+
if (!t) {
|
|
87
87
|
u(e);
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
await E({
|
|
91
91
|
user: e,
|
|
92
|
-
token: localStorage.getItem(
|
|
92
|
+
token: localStorage.getItem(o.TOKEN)
|
|
93
93
|
});
|
|
94
|
-
} catch (
|
|
95
|
-
u(
|
|
94
|
+
} catch (t) {
|
|
95
|
+
u(t);
|
|
96
96
|
} finally {
|
|
97
|
-
|
|
97
|
+
i(!1);
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
localStorage.getItem(
|
|
100
|
+
h(() => {
|
|
101
|
+
if (s.authFlow !== T.STANDARD) return;
|
|
102
|
+
localStorage.getItem(o.TOKEN) ? v() : i(!1);
|
|
103
103
|
}, []);
|
|
104
104
|
const U = async () => {
|
|
105
|
-
const
|
|
106
|
-
_(
|
|
107
|
-
const e =
|
|
105
|
+
const t = await l.getRegions();
|
|
106
|
+
_(t);
|
|
107
|
+
const e = t.map((n) => n.currency), a = Array.from(new Set(e)).map((n) => ({
|
|
108
108
|
code: n,
|
|
109
|
-
symbol:
|
|
109
|
+
symbol: M(n) || n
|
|
110
110
|
}));
|
|
111
111
|
p(a);
|
|
112
112
|
};
|
|
113
|
-
return
|
|
113
|
+
return h(() => {
|
|
114
114
|
U();
|
|
115
|
-
}, []),
|
|
116
|
-
if (
|
|
117
|
-
const
|
|
118
|
-
let a = (
|
|
119
|
-
e &&
|
|
120
|
-
}, []),
|
|
121
|
-
if (
|
|
122
|
-
const
|
|
123
|
-
var
|
|
115
|
+
}, []), h(() => {
|
|
116
|
+
if (s.authFlow !== T.QUERY) return;
|
|
117
|
+
const t = new URLSearchParams(window.location.search), e = t.get(o.TOKEN), r = t.get(o.REFRESH_TOKEN);
|
|
118
|
+
let a = (s.isTestMode ? t.get(o.OVERRIDE_TOKEN_EXCHANGE_ENDPOINT) : void 0) || void 0;
|
|
119
|
+
e && R(e, r ?? "", a);
|
|
120
|
+
}, []), h(() => {
|
|
121
|
+
if (s.authFlow !== T.POST_MESSAGE) return;
|
|
122
|
+
const t = async (e) => {
|
|
123
|
+
var w;
|
|
124
124
|
if (e.data.type !== "auth") return;
|
|
125
|
-
const r = (
|
|
125
|
+
const r = (w = e.data) == null ? void 0 : w.idToken, a = e.data.refreshToken, n = s.isTestMode ? e.data.overrideTokenExchangeEndpoint : void 0;
|
|
126
126
|
if (!r) {
|
|
127
|
-
const
|
|
127
|
+
const d = `received message ${JSON.stringify(
|
|
128
128
|
e.data
|
|
129
129
|
)}
|
|
130
130
|
no idToken in body`;
|
|
131
|
-
u(
|
|
131
|
+
u(d);
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
|
-
localStorage.setItem(
|
|
134
|
+
localStorage.setItem(o.REFRESH_TOKEN, a), await R(r, a, n);
|
|
135
135
|
};
|
|
136
|
-
return window.addEventListener("message",
|
|
136
|
+
return window.addEventListener("message", t), window.parent && window.parent.postMessage(
|
|
137
137
|
{
|
|
138
138
|
type: "ready"
|
|
139
139
|
/* READY */
|
|
140
140
|
},
|
|
141
141
|
"*"
|
|
142
142
|
), () => {
|
|
143
|
-
window.removeEventListener("message",
|
|
143
|
+
window.removeEventListener("message", t);
|
|
144
144
|
};
|
|
145
145
|
}, []), {
|
|
146
146
|
isAuthenticating: c,
|
|
147
|
-
isAuthenticated:
|
|
148
|
-
token:
|
|
147
|
+
isAuthenticated: y,
|
|
148
|
+
token: S,
|
|
149
149
|
user: m,
|
|
150
150
|
supportedRegions: C,
|
|
151
151
|
supportedCurrencies: F,
|
|
152
|
-
signIn: async (
|
|
152
|
+
signIn: async (t) => {
|
|
153
153
|
var r;
|
|
154
|
-
const e = await l.login(
|
|
154
|
+
const e = await l.login(t);
|
|
155
155
|
if (!e.success)
|
|
156
156
|
u(e.message);
|
|
157
157
|
else {
|
|
158
158
|
const a = (r = e.data) == null ? void 0 : r.refreshToken;
|
|
159
|
-
localStorage.setItem(
|
|
159
|
+
localStorage.setItem(o.REFRESH_TOKEN, a), await E(e.data);
|
|
160
160
|
}
|
|
161
161
|
return e;
|
|
162
162
|
},
|
|
163
|
-
signUp: async (
|
|
163
|
+
signUp: async (t) => {
|
|
164
164
|
var r;
|
|
165
|
-
const e = await l.signUp(
|
|
165
|
+
const e = await l.signUp(t);
|
|
166
166
|
if (!e.success)
|
|
167
167
|
u(e.message);
|
|
168
168
|
else {
|
|
169
169
|
const a = (r = e.data) == null ? void 0 : r.refreshToken;
|
|
170
|
-
localStorage.setItem(
|
|
170
|
+
localStorage.setItem(o.REFRESH_TOKEN, a), await E(e.data);
|
|
171
171
|
}
|
|
172
172
|
return e;
|
|
173
173
|
},
|
|
174
174
|
signOut: () => {
|
|
175
|
-
localStorage.removeItem(
|
|
175
|
+
localStorage.removeItem(o.TOKEN), localStorage.removeItem(o.REFRESH_TOKEN), g(!1), A(void 0), k(void 0);
|
|
176
176
|
},
|
|
177
|
-
continueWithGoogle: async (
|
|
177
|
+
continueWithGoogle: async (t, e) => {
|
|
178
178
|
var a;
|
|
179
179
|
const r = await l.getOrCreateGoogleUser(
|
|
180
|
-
|
|
180
|
+
t,
|
|
181
181
|
e
|
|
182
182
|
);
|
|
183
183
|
if (!r.success)
|
|
184
184
|
u(r.message);
|
|
185
185
|
else {
|
|
186
186
|
const n = (a = r.data) == null ? void 0 : a.refreshToken;
|
|
187
|
-
localStorage.setItem(
|
|
187
|
+
localStorage.setItem(o.REFRESH_TOKEN, n), await E(r.data);
|
|
188
188
|
}
|
|
189
189
|
return r;
|
|
190
190
|
},
|
|
191
|
-
resendVerificationEmail: async (
|
|
192
|
-
setTokens: (
|
|
193
|
-
localStorage.setItem(
|
|
191
|
+
resendVerificationEmail: async (t) => (await l.resendVerificationEmail(t)).success,
|
|
192
|
+
setTokens: (t, e) => {
|
|
193
|
+
localStorage.setItem(o.TOKEN, t), localStorage.setItem(o.REFRESH_TOKEN, e), R(t, e);
|
|
194
194
|
},
|
|
195
|
-
setPreferredCurrency: async (
|
|
196
|
-
const e = await q.setCurrency(
|
|
195
|
+
setPreferredCurrency: async (t) => {
|
|
196
|
+
const e = await q.setCurrency(t);
|
|
197
197
|
if (!e.success || !e.data)
|
|
198
198
|
return console.error("Failed to set preferred currency:", e), !1;
|
|
199
199
|
if (m) {
|
|
@@ -204,7 +204,7 @@ const G = (t, c) => {
|
|
|
204
204
|
currency: e.data.currency || m.preferences.currency
|
|
205
205
|
}
|
|
206
206
|
};
|
|
207
|
-
|
|
207
|
+
k(r), O.invalidateQueries({
|
|
208
208
|
queryKey: [N.CHECK_USER]
|
|
209
209
|
});
|
|
210
210
|
}
|
|
@@ -213,6 +213,6 @@ const G = (t, c) => {
|
|
|
213
213
|
};
|
|
214
214
|
};
|
|
215
215
|
export {
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
x as authFailurePostMessage,
|
|
217
|
+
ie as useAwayzAuth
|
|
218
218
|
};
|