@odynn/awayz-core 0.2.8 → 0.2.10
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/context/AwayzContext.js +1 -1
- package/dist/hooks/useAwayzAuth/useAwayzAuth.js +85 -77
- package/dist/lib/configs/awayzConfig.d.ts +11 -0
- package/dist/lib/context/AwayzContext.d.ts +1 -1
- package/dist/lib/hooks/useAwayzAuth/useAwayzAuth.d.ts +1 -1
- package/dist/lib/hooks/useAwayzAuth/useAwayzAuth.types.d.ts +5 -1
- package/dist/providers/AwayzProvider.js +13 -13
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ const t = s({
|
|
|
4
4
|
isAuthenticating: !1,
|
|
5
5
|
supportedRegions: [],
|
|
6
6
|
signIn: async () => ({ success: !1, message: "No Awayz Context" }),
|
|
7
|
-
signUp: async () => ({ success: !1, message: "
|
|
7
|
+
signUp: async () => ({ success: !1, message: "No Awayz Context" }),
|
|
8
8
|
signOut: () => {
|
|
9
9
|
},
|
|
10
10
|
resendVerificationEmail: async () => !1,
|
|
@@ -1,53 +1,57 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { useState as m, useCallback as
|
|
3
|
-
import { EAuthFlow as
|
|
4
|
-
import { awayzClient as
|
|
5
|
-
const
|
|
6
|
-
var f,
|
|
7
|
-
let c = "",
|
|
8
|
-
typeof a == "string" ? c = a : a instanceof
|
|
1
|
+
import { A as _, E as n, a as o, b as U, d as q } from "../../AccountService-CKQ3VzVx.js";
|
|
2
|
+
import { useState as m, useCallback as R, useEffect as w } from "react";
|
|
3
|
+
import { EAuthFlow as S } from "../../types/EAuthFlow.js";
|
|
4
|
+
import { awayzClient as H } from "../../configs/awayzClient.js";
|
|
5
|
+
const L = (t, a) => {
|
|
6
|
+
var f, d;
|
|
7
|
+
let c = "", E = a;
|
|
8
|
+
typeof a == "string" ? c = a : a instanceof _ ? (c = a.message, E = {
|
|
9
9
|
message: a.message,
|
|
10
10
|
cause: a.cause,
|
|
11
11
|
status: a.status,
|
|
12
12
|
data: (f = a == null ? void 0 : a.response) == null ? void 0 : f.data
|
|
13
|
-
}) : c = a.message, (
|
|
13
|
+
}) : c = a.message, (d = window.parent) == null || d.postMessage(
|
|
14
14
|
{
|
|
15
15
|
type: "auth_error",
|
|
16
|
-
details: { message: c, action: t, info:
|
|
16
|
+
details: { message: c, action: t, info: E }
|
|
17
17
|
},
|
|
18
18
|
"*"
|
|
19
19
|
);
|
|
20
|
-
},
|
|
21
|
-
const [a, c] = m(!0), [
|
|
20
|
+
}, J = (t) => {
|
|
21
|
+
const [a, c] = m(!0), [E, f] = m(!1), [d, T] = m(), [O, k] = m(), [A, K] = m([]), y = R(
|
|
22
22
|
async (s) => {
|
|
23
|
-
t != null && t.onSuccess && (t == null || t.onSuccess(s)), t != null && t.onSuccessAsync && await (t == null ? void 0 : t.onSuccessAsync(s)), c(!1), f(!0),
|
|
23
|
+
t != null && t.onSuccess && (t == null || t.onSuccess(s)), t != null && t.onSuccessAsync && await (t == null ? void 0 : t.onSuccessAsync(s)), c(!1), f(!0), T(s.token), k(s.user);
|
|
24
24
|
},
|
|
25
25
|
[t]
|
|
26
|
-
),
|
|
26
|
+
), i = R(
|
|
27
|
+
async (s, e) => {
|
|
28
|
+
if (t.authFlow !== S.POST_MESSAGE)
|
|
29
|
+
return L(e ?? "exchange_token", s);
|
|
30
|
+
t != null && t.onError && (t == null || t.onError(s)), t != null && t.onErrorAsync && await (t == null ? void 0 : t.onErrorAsync(s)), c(!1);
|
|
31
|
+
},
|
|
32
|
+
[t]
|
|
33
|
+
), h = async (s) => {
|
|
27
34
|
try {
|
|
28
|
-
const { success: e, data:
|
|
35
|
+
const { success: e, data: r, message: u } = await o.authenticateWithToken(s);
|
|
29
36
|
if (!e) {
|
|
30
|
-
u
|
|
37
|
+
i(u);
|
|
31
38
|
return;
|
|
32
39
|
}
|
|
33
|
-
if (!(
|
|
34
|
-
|
|
35
|
-
"exchange_token",
|
|
36
|
-
"no awayz token returned after exchanging id token"
|
|
37
|
-
);
|
|
40
|
+
if (!(r != null && r.token)) {
|
|
41
|
+
i("no awayz token returned after exchanging id token");
|
|
38
42
|
return;
|
|
39
43
|
}
|
|
40
|
-
localStorage.setItem(
|
|
41
|
-
const { data:
|
|
42
|
-
if (!
|
|
43
|
-
console.error({ reqLimitError:
|
|
44
|
+
localStorage.setItem(n.TOKEN, r.token), await y(r);
|
|
45
|
+
const { data: l, ...g } = await o.getRequestLimit();
|
|
46
|
+
if (!g.success) {
|
|
47
|
+
console.error({ reqLimitError: g });
|
|
44
48
|
return;
|
|
45
49
|
}
|
|
46
|
-
|
|
47
|
-
(
|
|
50
|
+
l == null || l.forEach(
|
|
51
|
+
(F) => window.parent.postMessage(
|
|
48
52
|
{
|
|
49
53
|
type: "request_limit",
|
|
50
|
-
limit:
|
|
54
|
+
limit: F
|
|
51
55
|
},
|
|
52
56
|
"*"
|
|
53
57
|
)
|
|
@@ -57,64 +61,68 @@ const u = (t, a) => {
|
|
|
57
61
|
} finally {
|
|
58
62
|
c(!1);
|
|
59
63
|
}
|
|
60
|
-
},
|
|
64
|
+
}, I = async () => {
|
|
61
65
|
try {
|
|
62
|
-
const { success: s, data: e } = await
|
|
63
|
-
queryKey: [
|
|
64
|
-
queryFn:
|
|
66
|
+
const { success: s, data: e } = await H.ensureQueryData({
|
|
67
|
+
queryKey: [U.CHECK_USER],
|
|
68
|
+
queryFn: o.checkUser
|
|
65
69
|
});
|
|
66
70
|
if (!s) {
|
|
67
|
-
|
|
71
|
+
i(e);
|
|
68
72
|
return;
|
|
69
73
|
}
|
|
70
|
-
await
|
|
74
|
+
await y({
|
|
71
75
|
user: e,
|
|
72
|
-
token: localStorage.getItem(
|
|
76
|
+
token: localStorage.getItem(n.TOKEN)
|
|
73
77
|
});
|
|
74
78
|
} catch (s) {
|
|
75
|
-
|
|
79
|
+
i(s);
|
|
76
80
|
} finally {
|
|
77
81
|
c(!1);
|
|
78
82
|
}
|
|
79
83
|
};
|
|
80
84
|
w(() => {
|
|
81
|
-
if (t.authFlow !==
|
|
82
|
-
const s = localStorage.getItem(
|
|
83
|
-
s && e ?
|
|
85
|
+
if (t.authFlow !== S.OAUTH) return;
|
|
86
|
+
const s = localStorage.getItem(n.TOKEN), e = localStorage.getItem(n.REFRESH_TOKEN);
|
|
87
|
+
s && e ? I() : c(!1);
|
|
84
88
|
}, []);
|
|
85
|
-
const
|
|
86
|
-
const s = await
|
|
87
|
-
|
|
89
|
+
const N = async () => {
|
|
90
|
+
const s = await o.getRegions();
|
|
91
|
+
K(s);
|
|
88
92
|
};
|
|
89
93
|
return w(() => {
|
|
90
|
-
|
|
94
|
+
N();
|
|
91
95
|
}, []), w(() => {
|
|
92
|
-
if (t.authFlow !==
|
|
93
|
-
const e = new URLSearchParams(window.location.search).get(
|
|
94
|
-
e &&
|
|
96
|
+
if (t.authFlow !== S.QUERY) return;
|
|
97
|
+
const e = new URLSearchParams(window.location.search).get(n.TOKEN);
|
|
98
|
+
e && h(e);
|
|
95
99
|
}, []), w(() => {
|
|
96
|
-
if (t.authFlow !==
|
|
100
|
+
if (t.authFlow !== S.POST_MESSAGE) return;
|
|
97
101
|
const s = async (e) => {
|
|
98
|
-
var
|
|
102
|
+
var l;
|
|
99
103
|
if (e.data.type !== "auth") return;
|
|
100
|
-
const
|
|
101
|
-
if (!
|
|
102
|
-
const
|
|
104
|
+
const r = (l = e.data) == null ? void 0 : l.idToken, u = e.data.refreshToken;
|
|
105
|
+
if (!r) {
|
|
106
|
+
const g = `received message ${JSON.stringify(
|
|
103
107
|
e.data
|
|
104
108
|
)}
|
|
105
109
|
no idToken in body`;
|
|
106
|
-
|
|
110
|
+
i(g);
|
|
107
111
|
return;
|
|
108
112
|
}
|
|
109
|
-
if (!
|
|
110
|
-
const
|
|
113
|
+
if (!u) {
|
|
114
|
+
const g = `received message: ${JSON.stringify(
|
|
111
115
|
e.data
|
|
112
116
|
)}
|
|
113
117
|
no refreshToken in body`;
|
|
114
|
-
|
|
118
|
+
i(
|
|
119
|
+
g,
|
|
120
|
+
"refresh_token"
|
|
121
|
+
/* REFRESH */
|
|
122
|
+
);
|
|
115
123
|
return;
|
|
116
124
|
}
|
|
117
|
-
localStorage.setItem(
|
|
125
|
+
localStorage.setItem(n.REFRESH_TOKEN, u), await h(r);
|
|
118
126
|
};
|
|
119
127
|
return window.addEventListener("message", s), window.parent && window.parent.postMessage(
|
|
120
128
|
{
|
|
@@ -127,50 +135,50 @@ const u = (t, a) => {
|
|
|
127
135
|
};
|
|
128
136
|
}, []), {
|
|
129
137
|
isAuthenticating: a,
|
|
130
|
-
isAuthenticated:
|
|
131
|
-
token:
|
|
132
|
-
user:
|
|
133
|
-
supportedRegions:
|
|
138
|
+
isAuthenticated: E,
|
|
139
|
+
token: d,
|
|
140
|
+
user: O,
|
|
141
|
+
supportedRegions: A,
|
|
134
142
|
signIn: async (s) => {
|
|
135
|
-
var
|
|
136
|
-
const e = await
|
|
143
|
+
var r;
|
|
144
|
+
const e = await o.login(s);
|
|
137
145
|
if (!e.success)
|
|
138
|
-
|
|
146
|
+
i(e.message);
|
|
139
147
|
else {
|
|
140
|
-
const
|
|
141
|
-
localStorage.setItem(
|
|
148
|
+
const u = (r = e.data) == null ? void 0 : r.refreshToken;
|
|
149
|
+
localStorage.setItem(n.REFRESH_TOKEN, u), await y(e.data);
|
|
142
150
|
}
|
|
143
151
|
return e;
|
|
144
152
|
},
|
|
145
153
|
signUp: async (s) => {
|
|
146
|
-
var
|
|
147
|
-
const e = await
|
|
154
|
+
var r;
|
|
155
|
+
const e = await o.signUp(s);
|
|
148
156
|
if (!e.success)
|
|
149
|
-
|
|
157
|
+
i(e.message);
|
|
150
158
|
else {
|
|
151
|
-
const
|
|
152
|
-
localStorage.setItem(
|
|
159
|
+
const u = (r = e.data) == null ? void 0 : r.refreshToken;
|
|
160
|
+
localStorage.setItem(n.REFRESH_TOKEN, u), await y(e.data);
|
|
153
161
|
}
|
|
154
162
|
return e;
|
|
155
163
|
},
|
|
156
164
|
signOut: () => {
|
|
157
|
-
localStorage.removeItem(
|
|
165
|
+
localStorage.removeItem(n.TOKEN), localStorage.removeItem(n.REFRESH_TOKEN), f(!1), T(void 0), k(void 0);
|
|
158
166
|
},
|
|
159
|
-
resendVerificationEmail: async (s) => (await
|
|
167
|
+
resendVerificationEmail: async (s) => (await o.resendVerificationEmail(s)).success,
|
|
160
168
|
setTokens: (s, e) => {
|
|
161
|
-
localStorage.setItem(
|
|
169
|
+
localStorage.setItem(n.TOKEN, s), localStorage.setItem(n.REFRESH_TOKEN, e), h(s);
|
|
162
170
|
},
|
|
163
171
|
getRequestLimits: async () => {
|
|
164
|
-
const { data: s, ...e } = await
|
|
172
|
+
const { data: s, ...e } = await o.getRequestLimit();
|
|
165
173
|
if (!e.success) {
|
|
166
174
|
console.error({ reqLimitError: e });
|
|
167
175
|
return;
|
|
168
176
|
}
|
|
169
|
-
return
|
|
177
|
+
return q(s);
|
|
170
178
|
}
|
|
171
179
|
};
|
|
172
180
|
};
|
|
173
181
|
export {
|
|
174
|
-
|
|
175
|
-
|
|
182
|
+
L as authFailurePostMessage,
|
|
183
|
+
J as useAwayzAuth
|
|
176
184
|
};
|
|
@@ -21,6 +21,9 @@ export interface IAwayzConfig {
|
|
|
21
21
|
* @default false
|
|
22
22
|
*/
|
|
23
23
|
externalInventory?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Config for the flights stream
|
|
26
|
+
*/
|
|
24
27
|
flightsConfig?: {
|
|
25
28
|
/**
|
|
26
29
|
* The maximum number of ping events before the flight search times out
|
|
@@ -33,4 +36,12 @@ export interface IAwayzConfig {
|
|
|
33
36
|
*/
|
|
34
37
|
streamTimeoutTotalSeconds?: number;
|
|
35
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Gets called when the authentication flow failed for any reason
|
|
41
|
+
*/
|
|
42
|
+
onAuthFailure?: () => void;
|
|
43
|
+
/**
|
|
44
|
+
* Gets called when the authentication flow succeeded
|
|
45
|
+
*/
|
|
46
|
+
onAuthSuccess?: () => void;
|
|
36
47
|
}
|
|
@@ -13,6 +13,6 @@ export interface IAwayzContext {
|
|
|
13
13
|
signOut: () => void;
|
|
14
14
|
resendVerificationEmail: (params: IResendVerificationEmailParams) => Promise<boolean>;
|
|
15
15
|
setTokens: (accessToken: string, refreshToken: string) => void;
|
|
16
|
-
getRequestLimits: () => Promise<ISearchLimit | undefined>;
|
|
16
|
+
getRequestLimits: () => Promise<ISearchLimit[] | undefined>;
|
|
17
17
|
}
|
|
18
18
|
export declare const AwayzContext: import('react').Context<IAwayzContext>;
|
|
@@ -33,6 +33,6 @@ export declare const useAwayzAuth: (options: TEmbeddedAuthOptions) => {
|
|
|
33
33
|
signOut: () => void;
|
|
34
34
|
resendVerificationEmail: (params: IResendVerificationEmailParams) => Promise<any>;
|
|
35
35
|
setTokens: (accessToken: string, refreshToken: string) => void;
|
|
36
|
-
getRequestLimits: () => Promise<ISearchLimit | undefined>;
|
|
36
|
+
getRequestLimits: () => Promise<ISearchLimit[] | undefined>;
|
|
37
37
|
};
|
|
38
38
|
export {};
|
|
@@ -6,12 +6,16 @@ interface IEmbeddedAuthOptionsBase {
|
|
|
6
6
|
includeDebugLogs?: boolean;
|
|
7
7
|
}
|
|
8
8
|
interface IEmbeddedAuthWithSyncSuccess extends IEmbeddedAuthOptionsBase {
|
|
9
|
-
onSuccess
|
|
9
|
+
onSuccess?: (authData: IAuthData) => void;
|
|
10
10
|
onSuccessAsync?: never;
|
|
11
|
+
onError?: (error: any) => void;
|
|
12
|
+
onErrorAsync?: never;
|
|
11
13
|
}
|
|
12
14
|
interface IEmbeddedAuthWithAsyncSuccess extends IEmbeddedAuthOptionsBase {
|
|
13
15
|
onSuccess?: never;
|
|
14
16
|
onSuccessAsync: (authData: IAuthData) => Promise<void>;
|
|
17
|
+
onError?: never;
|
|
18
|
+
onErrorAsync: (error: any) => Promise<void>;
|
|
15
19
|
}
|
|
16
20
|
export type TEmbeddedAuthOptions = IEmbeddedAuthWithSyncSuccess | IEmbeddedAuthWithAsyncSuccess;
|
|
17
21
|
export {};
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect as i } from "react";
|
|
3
3
|
import { AwayzContext as m } from "../context/AwayzContext.js";
|
|
4
4
|
import { E as e } from "../AccountService-CKQ3VzVx.js";
|
|
5
|
-
import { useAwayzAuth as
|
|
6
|
-
import { setBaseUrl as
|
|
5
|
+
import { useAwayzAuth as s } from "../hooks/useAwayzAuth/useAwayzAuth.js";
|
|
6
|
+
import { setBaseUrl as l } from "../configs/baseUrl.js";
|
|
7
7
|
import { QueryClientProvider as u } from "@tanstack/react-query";
|
|
8
8
|
import { awayzClient as d } from "../configs/awayzClient.js";
|
|
9
9
|
import '../assets/_styles.css';/* empty css */
|
|
10
10
|
import { defaultAwayzConfig as n } from "../configs/defaultAwayzConfig.js";
|
|
11
|
-
const C = ({ children: o, config:
|
|
12
|
-
const a =
|
|
13
|
-
authFlow:
|
|
14
|
-
onSuccess:
|
|
15
|
-
|
|
16
|
-
trustedOrigins:
|
|
11
|
+
const C = ({ children: o, config: r }) => {
|
|
12
|
+
const a = s({
|
|
13
|
+
authFlow: r.authFlow,
|
|
14
|
+
onSuccess: r.onAuthSuccess,
|
|
15
|
+
onError: r.onAuthFailure,
|
|
16
|
+
trustedOrigins: r.trustedOrigins
|
|
17
17
|
});
|
|
18
18
|
return i(() => {
|
|
19
|
-
if (!
|
|
19
|
+
if (!r.clientId) {
|
|
20
20
|
console.error("You need to provide a client ID to the AwayzProvider");
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
localStorage.setItem(e.CLIENT_ID,
|
|
24
|
-
}, [
|
|
23
|
+
localStorage.setItem(e.CLIENT_ID, r.clientId), localStorage.setItem(e.AUTH_FLOW, r.authFlow), l(r.testMode ?? !1);
|
|
24
|
+
}, [r]), /* @__PURE__ */ t(u, { client: d, children: /* @__PURE__ */ t(
|
|
25
25
|
m.Provider,
|
|
26
26
|
{
|
|
27
27
|
value: {
|
|
28
28
|
...a,
|
|
29
29
|
config: {
|
|
30
30
|
...n,
|
|
31
|
-
...
|
|
31
|
+
...r
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
children: o
|