@odynn/awayz-core 0.4.6 → 0.4.8
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.
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import "../../arrayExtensions-DlcBOj5a.js";
|
|
2
|
-
import { f as
|
|
3
|
-
import { useState as E, useCallback as
|
|
4
|
-
import { awayzClient as
|
|
5
|
-
import { PreferencesService as
|
|
6
|
-
import { EAuthFlow as
|
|
2
|
+
import { f as v, d as n, A as o, E as K } from "../../AccountService-DdcBI9BS.js";
|
|
3
|
+
import { useState as E, useCallback as O, useEffect as w } from "react";
|
|
4
|
+
import { awayzClient as R } from "../../configs/awayzClient.js";
|
|
5
|
+
import { PreferencesService as C } from "../../services/preferences/PreferencesService.js";
|
|
6
|
+
import { EAuthFlow as h } from "../../types/EAuthFlow.js";
|
|
7
7
|
const P = (t, r) => {
|
|
8
8
|
var g, y;
|
|
9
9
|
let c = "", m = r;
|
|
10
|
-
typeof r == "string" ? c = r : r instanceof
|
|
10
|
+
typeof r == "string" ? c = r : r instanceof v ? (c = r.message, m = {
|
|
11
11
|
message: r.message,
|
|
12
12
|
cause: r.cause,
|
|
13
13
|
status: r.status,
|
|
@@ -19,20 +19,20 @@ const P = (t, r) => {
|
|
|
19
19
|
},
|
|
20
20
|
"*"
|
|
21
21
|
);
|
|
22
|
-
},
|
|
23
|
-
const [r, c] = E(!0), [m, g] = E(!1), [y,
|
|
22
|
+
}, W = (t) => {
|
|
23
|
+
const [r, c] = E(!0), [m, g] = E(!1), [y, A] = E(), [d, T] = E(), [I, N] = E([]), S = O(
|
|
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), A(s.token), T(s.user), R.invalidateQueries();
|
|
26
26
|
},
|
|
27
27
|
[t]
|
|
28
|
-
), i =
|
|
28
|
+
), i = O(
|
|
29
29
|
async (s, e) => {
|
|
30
|
-
if (t.authFlow !==
|
|
30
|
+
if (t.authFlow !== h.POST_MESSAGE)
|
|
31
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
|
+
), k = async (s) => {
|
|
36
36
|
try {
|
|
37
37
|
const { success: e, data: a, message: u } = await o.authenticateWithToken(s);
|
|
38
38
|
if (!e) {
|
|
@@ -44,16 +44,16 @@ const P = (t, r) => {
|
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
localStorage.setItem(n.TOKEN, a.token), await S(a);
|
|
47
|
-
const { data:
|
|
48
|
-
if (!
|
|
49
|
-
console.error({ reqLimitError:
|
|
47
|
+
const { data: f, ...l } = await o.getRequestLimit();
|
|
48
|
+
if (!l.success) {
|
|
49
|
+
console.error({ reqLimitError: l });
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
(
|
|
52
|
+
f == null || f.forEach(
|
|
53
|
+
(U) => window.parent.postMessage(
|
|
54
54
|
{
|
|
55
55
|
type: "request_limit",
|
|
56
|
-
limit:
|
|
56
|
+
limit: U
|
|
57
57
|
},
|
|
58
58
|
"*"
|
|
59
59
|
)
|
|
@@ -63,9 +63,9 @@ const P = (t, r) => {
|
|
|
63
63
|
} finally {
|
|
64
64
|
c(!1);
|
|
65
65
|
}
|
|
66
|
-
},
|
|
66
|
+
}, F = async () => {
|
|
67
67
|
try {
|
|
68
|
-
const { success: s, data: e } = await
|
|
68
|
+
const { success: s, data: e } = await R.ensureQueryData({
|
|
69
69
|
queryKey: [K.CHECK_USER],
|
|
70
70
|
queryFn: o.checkUser
|
|
71
71
|
});
|
|
@@ -84,47 +84,47 @@ const P = (t, r) => {
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
w(() => {
|
|
87
|
-
if (t.authFlow !==
|
|
87
|
+
if (t.authFlow !== h.STANDARD) return;
|
|
88
88
|
const s = localStorage.getItem(n.TOKEN), e = localStorage.getItem(n.REFRESH_TOKEN);
|
|
89
|
-
s && e ?
|
|
89
|
+
s && e ? F() : c(!1);
|
|
90
90
|
}, []);
|
|
91
|
-
const
|
|
91
|
+
const _ = async () => {
|
|
92
92
|
const s = await o.getRegions();
|
|
93
|
-
|
|
93
|
+
N(s);
|
|
94
94
|
};
|
|
95
95
|
return w(() => {
|
|
96
|
-
|
|
96
|
+
_();
|
|
97
97
|
}, []), w(() => {
|
|
98
|
-
if (t.authFlow !==
|
|
98
|
+
if (t.authFlow !== h.QUERY) return;
|
|
99
99
|
const e = new URLSearchParams(window.location.search).get(n.TOKEN);
|
|
100
|
-
e &&
|
|
100
|
+
e && k(e);
|
|
101
101
|
}, []), w(() => {
|
|
102
|
-
if (t.authFlow !==
|
|
102
|
+
if (t.authFlow !== h.POST_MESSAGE) return;
|
|
103
103
|
const s = async (e) => {
|
|
104
|
-
var
|
|
104
|
+
var f;
|
|
105
105
|
if (e.data.type !== "auth") return;
|
|
106
|
-
const a = (
|
|
106
|
+
const a = (f = e.data) == null ? void 0 : f.idToken, u = e.data.refreshToken;
|
|
107
107
|
if (!a) {
|
|
108
|
-
const
|
|
108
|
+
const l = `received message ${JSON.stringify(
|
|
109
109
|
e.data
|
|
110
110
|
)}
|
|
111
111
|
no idToken in body`;
|
|
112
|
-
i(
|
|
112
|
+
i(l);
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
if (!u) {
|
|
116
|
-
const
|
|
116
|
+
const l = `received message: ${JSON.stringify(
|
|
117
117
|
e.data
|
|
118
118
|
)}
|
|
119
119
|
no refreshToken in body`;
|
|
120
120
|
i(
|
|
121
|
-
|
|
121
|
+
l,
|
|
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 k(a);
|
|
128
128
|
};
|
|
129
129
|
return window.addEventListener("message", s), window.parent && window.parent.postMessage(
|
|
130
130
|
{
|
|
@@ -140,7 +140,7 @@ const P = (t, r) => {
|
|
|
140
140
|
isAuthenticated: m,
|
|
141
141
|
token: y,
|
|
142
142
|
user: d,
|
|
143
|
-
supportedRegions:
|
|
143
|
+
supportedRegions: I,
|
|
144
144
|
signIn: async (s) => {
|
|
145
145
|
var a;
|
|
146
146
|
const e = await o.login(s);
|
|
@@ -164,14 +164,14 @@ const P = (t, r) => {
|
|
|
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), A(void 0), T(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), k(s);
|
|
172
172
|
},
|
|
173
173
|
setPreferredCurrency: async (s) => {
|
|
174
|
-
const e = await
|
|
174
|
+
const e = await C.setCurrency(s);
|
|
175
175
|
if (!e.success || !e.data)
|
|
176
176
|
return console.error("Failed to set preferred currency:", e), !1;
|
|
177
177
|
if (d) {
|
|
@@ -182,9 +182,7 @@ const P = (t, r) => {
|
|
|
182
182
|
currency: e.data.currency || d.preferences.currency
|
|
183
183
|
}
|
|
184
184
|
};
|
|
185
|
-
|
|
186
|
-
queryKey: [K.CONVERT_CURRENCY]
|
|
187
|
-
}), h.invalidateQueries({
|
|
185
|
+
T(a), R.invalidateQueries({
|
|
188
186
|
queryKey: [K.CHECK_USER]
|
|
189
187
|
});
|
|
190
188
|
}
|
|
@@ -194,5 +192,5 @@ const P = (t, r) => {
|
|
|
194
192
|
};
|
|
195
193
|
export {
|
|
196
194
|
P as authFailurePostMessage,
|
|
197
|
-
|
|
195
|
+
W as useAwayzAuth
|
|
198
196
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useQuery as n, useMutation as
|
|
1
|
+
import { useQuery as n, useMutation as i } from "@tanstack/react-query";
|
|
2
2
|
import "../../arrayExtensions-DlcBOj5a.js";
|
|
3
3
|
import { E as t, a as u } from "../../AccountService-DdcBI9BS.js";
|
|
4
4
|
import "react";
|
|
5
5
|
import "react/jsx-runtime";
|
|
6
6
|
import "../../context/AwayzContext.js";
|
|
7
|
-
import { awayzClient as
|
|
8
|
-
import { useAwayzContext as
|
|
7
|
+
import { awayzClient as s } from "../../configs/awayzClient.js";
|
|
8
|
+
import { useAwayzContext as w } from "../useAwayzContext.js";
|
|
9
9
|
import "../../services/noRetryInstance.js";
|
|
10
10
|
import '../../assets/_styles5.css';import '../../assets/_styles4.css';import '../../assets/_styles3.css';import '../../assets/_styles2.css';import '../../assets/_styles.css';/* empty css */
|
|
11
11
|
/* empty css */
|
|
@@ -14,25 +14,25 @@ import '../../assets/_styles5.css';import '../../assets/_styles4.css';import '..
|
|
|
14
14
|
/* empty css */
|
|
15
15
|
import { WalletService as o } from "../../services/wallet/WalletService.js";
|
|
16
16
|
const I = () => {
|
|
17
|
-
const { user: r } =
|
|
17
|
+
const { user: r } = w(), { data: e } = n({
|
|
18
18
|
queryKey: [t.PROGRAMS],
|
|
19
19
|
queryFn: o.getAwards,
|
|
20
20
|
placeholderData: []
|
|
21
|
-
}), { data:
|
|
21
|
+
}), { data: l } = n({
|
|
22
22
|
queryKey: [t.USER_PROGRAMS, r == null ? void 0 : r.id],
|
|
23
23
|
queryFn: () => r != null && r.id ? o.getUserAwards(r.id) : [],
|
|
24
24
|
placeholderData: [],
|
|
25
25
|
enabled: !!(r != null && r.id)
|
|
26
|
-
}), { data:
|
|
26
|
+
}), { data: y } = n({
|
|
27
27
|
queryKey: [t.LINKED_USER_PROGRAMS, r == null ? void 0 : r.id],
|
|
28
28
|
queryFn: () => r != null && r.id ? o.getLinkedUserAwards(r.id) : [],
|
|
29
29
|
placeholderData: [],
|
|
30
30
|
enabled: !!(r != null && r.id)
|
|
31
|
-
}), { data:
|
|
31
|
+
}), { data: R } = n({
|
|
32
32
|
queryKey: [t.BANKS],
|
|
33
33
|
queryFn: o.getBanks,
|
|
34
34
|
placeholderData: []
|
|
35
|
-
}), { data:
|
|
35
|
+
}), { data: g } = n({
|
|
36
36
|
queryKey: [t.CARDS],
|
|
37
37
|
queryFn: o.getCards,
|
|
38
38
|
placeholderData: []
|
|
@@ -40,56 +40,58 @@ const I = () => {
|
|
|
40
40
|
queryKey: [t.USER_CARDS],
|
|
41
41
|
queryFn: o.getUserCards,
|
|
42
42
|
placeholderData: []
|
|
43
|
-
}), { mutate: S } =
|
|
43
|
+
}), { mutate: S } = i({
|
|
44
44
|
mutationFn: async (a) => {
|
|
45
45
|
const { mainProgram: d, awardsAmount: m } = typeof a == "string" ? { mainProgram: a, awardsAmount: 0 } : a;
|
|
46
46
|
await o.addAwardProgram(d, m);
|
|
47
47
|
},
|
|
48
48
|
onSuccess: () => {
|
|
49
|
-
|
|
49
|
+
s.invalidateQueries({
|
|
50
50
|
queryKey: [t.LINKED_USER_PROGRAMS]
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
}), { mutate: P } =
|
|
53
|
+
}), { mutate: P } = i({
|
|
54
54
|
mutationFn: async (a) => {
|
|
55
55
|
await o.removeAwardProgram(a);
|
|
56
56
|
},
|
|
57
57
|
onSuccess: () => {
|
|
58
|
-
|
|
58
|
+
s.invalidateQueries({
|
|
59
59
|
queryKey: [t.LINKED_USER_PROGRAMS]
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
}), { mutate: p } =
|
|
62
|
+
}), { mutate: p } = i({
|
|
63
63
|
mutationFn: async (a) => {
|
|
64
|
-
const { mainProgram: d, awardsAmount: m } = a,
|
|
64
|
+
const { mainProgram: d, awardsAmount: m } = a, c = e == null ? void 0 : e.find(
|
|
65
65
|
(C) => C.mainProgram === d
|
|
66
66
|
);
|
|
67
|
-
if (!
|
|
67
|
+
if (!c)
|
|
68
68
|
throw new Error("Program not found");
|
|
69
|
-
await o.setAwardPoints(
|
|
69
|
+
await o.setAwardPoints(c.mainProgram, m);
|
|
70
70
|
},
|
|
71
71
|
onSuccess: () => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
[
|
|
73
|
+
t.LINKED_USER_PROGRAMS,
|
|
74
|
+
t.USER_PROGRAMS,
|
|
75
|
+
t.PROGRAMS
|
|
76
|
+
].forEach((a) => {
|
|
77
|
+
s.invalidateQueries({ queryKey: [a] });
|
|
76
78
|
});
|
|
77
79
|
}
|
|
78
|
-
}), { mutate: E } =
|
|
80
|
+
}), { mutate: E } = i({
|
|
79
81
|
mutationFn: async (a) => {
|
|
80
82
|
await o.addCardsToWallet(a);
|
|
81
83
|
},
|
|
82
84
|
onSuccess: () => {
|
|
83
|
-
|
|
85
|
+
s.invalidateQueries({
|
|
84
86
|
queryKey: [t.USER_CARDS]
|
|
85
87
|
});
|
|
86
88
|
}
|
|
87
|
-
}), { mutate: K } =
|
|
89
|
+
}), { mutate: K } = i({
|
|
88
90
|
mutationFn: async (a) => {
|
|
89
91
|
await o.removeCardsFromWallet(a);
|
|
90
92
|
},
|
|
91
93
|
onSuccess: () => {
|
|
92
|
-
|
|
94
|
+
s.invalidateQueries({
|
|
93
95
|
queryKey: [t.USER_CARDS]
|
|
94
96
|
});
|
|
95
97
|
}
|
|
@@ -97,8 +99,8 @@ const I = () => {
|
|
|
97
99
|
return {
|
|
98
100
|
// Program Management
|
|
99
101
|
allPrograms: e || [],
|
|
100
|
-
userPrograms:
|
|
101
|
-
linkedUserPrograms:
|
|
102
|
+
userPrograms: l || [],
|
|
103
|
+
linkedUserPrograms: y || [],
|
|
102
104
|
hotelPrograms: (e == null ? void 0 : e.filter(
|
|
103
105
|
(a) => a.category.includes(u.HOTEL)
|
|
104
106
|
)) || [],
|
|
@@ -112,8 +114,8 @@ const I = () => {
|
|
|
112
114
|
addAwardProgram: S,
|
|
113
115
|
removeAwardProgram: P,
|
|
114
116
|
// Car Management
|
|
115
|
-
banks:
|
|
116
|
-
allCards:
|
|
117
|
+
banks: R || [],
|
|
118
|
+
allCards: g || [],
|
|
117
119
|
userCards: A || [],
|
|
118
120
|
addCards: E,
|
|
119
121
|
removeCards: K
|