@odynn/awayz-core 0.2.12 → 0.2.13

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.
@@ -5708,7 +5708,7 @@ function Rc() {
5708
5708
  return k0.countries = z, k0;
5709
5709
  }
5710
5710
  Rc();
5711
- var e1 = /* @__PURE__ */ ((M) => (M.CHECK_USER = "CHECK_USER", M.USER_REGIONS = "USER_REGIONS", M.CONVERT_CURRENCY = "CONVERT_CURRENCY", M.CLIENT_COMPONENT_KEY = "CLIENT_COMPONENT_KEY", M))(e1 || {}), f0 = /* @__PURE__ */ ((M) => (M.TOKEN = "token", M.REFRESH_TOKEN = "refreshToken", M.CLIENT_ID = "clientId", M.AUTH_FLOW = "authFlow", M))(f0 || {});
5711
+ var e1 = /* @__PURE__ */ ((M) => (M.CHECK_USER = "CHECK_USER", M.USER_REGIONS = "USER_REGIONS", M.CONVERT_CURRENCY = "CONVERT_CURRENCY", M.CLIENT_COMPONENT_KEY = "CLIENT_COMPONENT_KEY", M.SEARCH_LIMIT = "SEARCH_LIMIT", M))(e1 || {}), f0 = /* @__PURE__ */ ((M) => (M.TOKEN = "token", M.REFRESH_TOKEN = "refreshToken", M.CLIENT_ID = "clientId", M.AUTH_FLOW = "authFlow", M))(f0 || {});
5712
5712
  Array.prototype.getLast || (Array.prototype.getLast = function() {
5713
5713
  return this[this.length - 1];
5714
5714
  });
@@ -7710,12 +7710,12 @@ class bA {
7710
7710
  }
7711
7711
  const gM = new bA();
7712
7712
  export {
7713
- Zo as A,
7713
+ gM as A,
7714
7714
  f0 as E,
7715
- gM as a,
7716
- e1 as b,
7715
+ e1 as a,
7716
+ E0 as b,
7717
7717
  Z as c,
7718
- E0 as d,
7718
+ Zo as d,
7719
7719
  nA as g,
7720
7720
  $o as i
7721
7721
  };
@@ -1,7 +1,7 @@
1
1
  import { jsx as Fe, Fragment as GO, jsxs as Jo } from "react/jsx-runtime";
2
2
  import * as Q from "react";
3
3
  import Jl, { useLayoutEffect as XO, useEffect as qO, useMemo as KO } from "react";
4
- import { g as ZO, b as JO } from "../../AccountService-CKYH_7VT.js";
4
+ import { g as ZO, a as JO } from "../../AccountService-Dt2-k7CN.js";
5
5
  import { useQuery as e_ } from "@tanstack/react-query";
6
6
  import { CurrencyService as t_ } from "../../services/currency/CurrencyService.js";
7
7
  import '../../assets/_styles.css';/* empty css */
@@ -9,8 +9,6 @@ const t = s({
9
9
  },
10
10
  resendVerificationEmail: async () => !1,
11
11
  setTokens: () => {
12
- },
13
- getRequestLimits: async () => {
14
12
  }
15
13
  });
16
14
  export {
@@ -1,47 +1,47 @@
1
- import { A as _, E as n, a as o, b as q, d as L } from "../../AccountService-CKYH_7VT.js";
2
- import { useState as m, useCallback as R, useEffect as w } from "react";
1
+ import { d as _, E as r, A as o, a as U } from "../../AccountService-Dt2-k7CN.js";
2
+ import { useState as E, useCallback as R, useEffect as y } from "react";
3
3
  import { EAuthFlow as S } from "../../types/EAuthFlow.js";
4
- import { awayzClient as U } from "../../configs/awayzClient.js";
5
- const v = (t, a) => {
6
- var f, d;
7
- let c = "", E = a;
8
- typeof a == "string" ? c = a : a instanceof _ ? (c = a.message, E = {
9
- message: a.message,
10
- cause: a.cause,
11
- status: a.status,
12
- data: (f = a == null ? void 0 : a.response) == null ? void 0 : f.data
13
- }) : c = a.message, (d = window.parent) == null || d.postMessage(
4
+ import { awayzClient as H } from "../../configs/awayzClient.js";
5
+ const M = (s, t) => {
6
+ var f, m;
7
+ let c = "", d = t;
8
+ typeof t == "string" ? c = t : t instanceof _ ? (c = t.message, d = {
9
+ message: t.message,
10
+ cause: t.cause,
11
+ status: t.status,
12
+ data: (f = t == null ? void 0 : t.response) == null ? void 0 : f.data
13
+ }) : c = t.message, (m = window.parent) == null || m.postMessage(
14
14
  {
15
15
  type: "auth_error",
16
- details: { message: c, action: t, info: E }
16
+ details: { message: c, action: s, info: d }
17
17
  },
18
18
  "*"
19
19
  );
20
- }, J = (t) => {
21
- const [a, c] = m(!0), [E, f] = m(!1), [d, T] = m(), [A, k] = m(), [O, K] = m([]), y = R(
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), T(s.token), k(s.user);
20
+ }, V = (s) => {
21
+ const [t, c] = E(!0), [d, f] = E(!1), [m, T] = E(), [A, k] = E(), [O, I] = E([]), w = R(
22
+ async (a) => {
23
+ s != null && s.onSuccess && (s == null || s.onSuccess(a)), s != null && s.onSuccessAsync && await (s == null ? void 0 : s.onSuccessAsync(a)), c(!1), f(!0), T(a.token), k(a.user);
24
24
  },
25
- [t]
25
+ [s]
26
26
  ), i = R(
27
- async (s, e) => {
28
- if (t.authFlow !== S.POST_MESSAGE)
29
- return v(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);
27
+ async (a, e) => {
28
+ if (s.authFlow !== S.POST_MESSAGE)
29
+ return M(e ?? "exchange_token", a);
30
+ s != null && s.onError && (s == null || s.onError(a)), s != null && s.onErrorAsync && await (s == null ? void 0 : s.onErrorAsync(a)), c(!1);
31
31
  },
32
- [t]
33
- ), h = async (s) => {
32
+ [s]
33
+ ), h = async (a) => {
34
34
  try {
35
- const { success: e, data: r, message: u } = await o.authenticateWithToken(s);
35
+ const { success: e, data: n, message: u } = await o.authenticateWithToken(a);
36
36
  if (!e) {
37
37
  i(u);
38
38
  return;
39
39
  }
40
- if (!(r != null && r.token)) {
40
+ if (!(n != null && n.token)) {
41
41
  i("no awayz token returned after exchanging id token");
42
42
  return;
43
43
  }
44
- localStorage.setItem(n.TOKEN, r.token), await y(r);
44
+ localStorage.setItem(r.TOKEN, n.token), await w(n);
45
45
  const { data: l, ...g } = await o.getRequestLimit();
46
46
  if (!g.success) {
47
47
  console.error({ reqLimitError: g });
@@ -61,48 +61,48 @@ const v = (t, a) => {
61
61
  } finally {
62
62
  c(!1);
63
63
  }
64
- }, I = async () => {
64
+ }, K = async () => {
65
65
  try {
66
- const { success: s, data: e } = await U.ensureQueryData({
67
- queryKey: [q.CHECK_USER],
66
+ const { success: a, data: e } = await H.ensureQueryData({
67
+ queryKey: [U.CHECK_USER],
68
68
  queryFn: o.checkUser
69
69
  });
70
- if (!s) {
70
+ if (!a) {
71
71
  i(e);
72
72
  return;
73
73
  }
74
- await y({
74
+ await w({
75
75
  user: e,
76
- token: localStorage.getItem(n.TOKEN)
76
+ token: localStorage.getItem(r.TOKEN)
77
77
  });
78
- } catch (s) {
79
- i(s);
78
+ } catch (a) {
79
+ i(a);
80
80
  } finally {
81
81
  c(!1);
82
82
  }
83
83
  };
84
- w(() => {
85
- if (t.authFlow !== S.STANDARD) return;
86
- const s = localStorage.getItem(n.TOKEN), e = localStorage.getItem(n.REFRESH_TOKEN);
87
- s && e ? I() : c(!1);
84
+ y(() => {
85
+ if (s.authFlow !== S.STANDARD) return;
86
+ const a = localStorage.getItem(r.TOKEN), e = localStorage.getItem(r.REFRESH_TOKEN);
87
+ a && e ? K() : c(!1);
88
88
  }, []);
89
89
  const N = async () => {
90
- const s = await o.getRegions();
91
- K(s);
90
+ const a = await o.getRegions();
91
+ I(a);
92
92
  };
93
- return w(() => {
93
+ return y(() => {
94
94
  N();
95
- }, []), w(() => {
96
- if (t.authFlow !== S.QUERY) return;
97
- const e = new URLSearchParams(window.location.search).get(n.TOKEN);
95
+ }, []), y(() => {
96
+ if (s.authFlow !== S.QUERY) return;
97
+ const e = new URLSearchParams(window.location.search).get(r.TOKEN);
98
98
  e && h(e);
99
- }, []), w(() => {
100
- if (t.authFlow !== S.POST_MESSAGE) return;
101
- const s = async (e) => {
99
+ }, []), y(() => {
100
+ if (s.authFlow !== S.POST_MESSAGE) return;
101
+ const a = async (e) => {
102
102
  var l;
103
103
  if (e.data.type !== "auth") return;
104
- const r = (l = e.data) == null ? void 0 : l.idToken, u = e.data.refreshToken;
105
- if (!r) {
104
+ const n = (l = e.data) == null ? void 0 : l.idToken, u = e.data.refreshToken;
105
+ if (!n) {
106
106
  const g = `received message ${JSON.stringify(
107
107
  e.data
108
108
  )}
@@ -122,63 +122,55 @@ const v = (t, a) => {
122
122
  );
123
123
  return;
124
124
  }
125
- localStorage.setItem(n.REFRESH_TOKEN, u), await h(r);
125
+ localStorage.setItem(r.REFRESH_TOKEN, u), await h(n);
126
126
  };
127
- return window.addEventListener("message", s), window.parent && window.parent.postMessage(
127
+ return window.addEventListener("message", a), window.parent && window.parent.postMessage(
128
128
  {
129
129
  type: "ready"
130
130
  /* READY */
131
131
  },
132
132
  "*"
133
133
  ), () => {
134
- window.removeEventListener("message", s);
134
+ window.removeEventListener("message", a);
135
135
  };
136
136
  }, []), {
137
- isAuthenticating: a,
138
- isAuthenticated: E,
139
- token: d,
137
+ isAuthenticating: t,
138
+ isAuthenticated: d,
139
+ token: m,
140
140
  user: A,
141
141
  supportedRegions: O,
142
- signIn: async (s) => {
143
- var r;
144
- const e = await o.login(s);
142
+ signIn: async (a) => {
143
+ var n;
144
+ const e = await o.login(a);
145
145
  if (!e.success)
146
146
  i(e.message);
147
147
  else {
148
- const u = (r = e.data) == null ? void 0 : r.refreshToken;
149
- localStorage.setItem(n.REFRESH_TOKEN, u), await y(e.data);
148
+ const u = (n = e.data) == null ? void 0 : n.refreshToken;
149
+ localStorage.setItem(r.REFRESH_TOKEN, u), await w(e.data);
150
150
  }
151
151
  return e;
152
152
  },
153
- signUp: async (s) => {
154
- var r;
155
- const e = await o.signUp(s);
153
+ signUp: async (a) => {
154
+ var n;
155
+ const e = await o.signUp(a);
156
156
  if (!e.success)
157
157
  i(e.message);
158
158
  else {
159
- const u = (r = e.data) == null ? void 0 : r.refreshToken;
160
- localStorage.setItem(n.REFRESH_TOKEN, u), await y(e.data);
159
+ const u = (n = e.data) == null ? void 0 : n.refreshToken;
160
+ localStorage.setItem(r.REFRESH_TOKEN, u), await w(e.data);
161
161
  }
162
162
  return e;
163
163
  },
164
164
  signOut: () => {
165
- localStorage.removeItem(n.TOKEN), localStorage.removeItem(n.REFRESH_TOKEN), f(!1), T(void 0), k(void 0);
165
+ localStorage.removeItem(r.TOKEN), localStorage.removeItem(r.REFRESH_TOKEN), f(!1), T(void 0), k(void 0);
166
166
  },
167
- resendVerificationEmail: async (s) => (await o.resendVerificationEmail(s)).success,
168
- setTokens: (s, e) => {
169
- localStorage.setItem(n.TOKEN, s), localStorage.setItem(n.REFRESH_TOKEN, e), h(s);
170
- },
171
- getRequestLimits: async () => {
172
- const { data: s, ...e } = await o.getRequestLimit();
173
- if (!e.success) {
174
- console.error({ reqLimitError: e });
175
- return;
176
- }
177
- return L(s);
167
+ resendVerificationEmail: async (a) => (await o.resendVerificationEmail(a)).success,
168
+ setTokens: (a, e) => {
169
+ localStorage.setItem(r.TOKEN, a), localStorage.setItem(r.REFRESH_TOKEN, e), h(a);
178
170
  }
179
171
  };
180
172
  };
181
173
  export {
182
- v as authFailurePostMessage,
183
- J as useAwayzAuth
174
+ M as authFailurePostMessage,
175
+ V as useAwayzAuth
184
176
  };
@@ -0,0 +1,22 @@
1
+ import { a as s, A as a, b as i } from "../AccountService-Dt2-k7CN.js";
2
+ import { useQuery as o } from "@tanstack/react-query";
3
+ import "react";
4
+ const n = () => {
5
+ const { data: r } = o({
6
+ queryKey: [s.SEARCH_LIMIT],
7
+ queryFn: async () => {
8
+ const { data: t, ...e } = await a.getRequestLimit();
9
+ if (!e.success) {
10
+ console.error({ reqLimitError: e });
11
+ return;
12
+ }
13
+ return i(t);
14
+ },
15
+ staleTime: 3e5
16
+ // 5 minutes
17
+ });
18
+ return r;
19
+ };
20
+ export {
21
+ n as useSearchLimit
22
+ };
@@ -1,4 +1,4 @@
1
- import { IRegion, IResendVerificationEmailParams, ISearchLimit, IUser } from '../services/account/AccountServices.types';
1
+ import { IRegion, IResendVerificationEmailParams, IUser } from '../services/account/AccountServices.types';
2
2
  import { ISignInParams, ISignUpParams, TAuthResponse } from '../types/auth';
3
3
  import { IAwayzConfig } from '../configs/awayzConfig';
4
4
  export interface IAwayzContext {
@@ -13,6 +13,5 @@ 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>;
17
16
  }
18
17
  export declare const AwayzContext: import('react').Context<IAwayzContext>;
@@ -1,5 +1,5 @@
1
1
  import { TEmbeddedAuthOptions } from './useAwayzAuth.types';
2
- import { IAuthData, IRegion, IResendVerificationEmailParams, ISearchLimit, IUser } from '../../services/account/AccountServices.types';
2
+ import { IAuthData, IRegion, IResendVerificationEmailParams, IUser } from '../../services/account/AccountServices.types';
3
3
  import { ISignInParams, ISignUpParams } from '../../types/auth';
4
4
  declare enum ETokenType {
5
5
  EXCHANGE = "exchange_token",
@@ -33,6 +33,5 @@ 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>;
37
36
  };
38
37
  export {};
@@ -0,0 +1,22 @@
1
+ import { ISearchLimit } from '../services/account/AccountServices.types';
2
+ export declare const useSearchLimit: () => ISearchLimit[] | undefined;
3
+ /**
4
+ * "data": [
5
+ {
6
+ "search_type": "Flight",
7
+ "subscription": "free",
8
+ "is_admin": false,
9
+ "search_limit": 5,
10
+ "number_of_calls": 1,
11
+ "remaining_calls": 4
12
+ },
13
+ {
14
+ "search_type": "Hotel",
15
+ "subscription": "free",
16
+ "is_admin": false,
17
+ "search_limit": 5,
18
+ "number_of_calls": 1,
19
+ "remaining_calls": 4
20
+ }
21
+ ],
22
+ */
package/dist/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AwayzProvider as r } from "./providers/AwayzProvider.js";
2
2
  import { useAwayzContext as a } from "./hooks/useAwayzContext.js";
3
3
  import { EAuthFlow as n } from "./types/EAuthFlow.js";
4
- import { c as s, i as x } from "./AccountService-CKYH_7VT.js";
4
+ import { c as s, i as x } from "./AccountService-Dt2-k7CN.js";
5
5
  import { awayzClient as m } from "./configs/awayzClient.js";
6
6
  import { CashValue as c, EToolTipPosition as w } from "./components/CashValue/CashValue.js";
7
7
  import { getBaseUrl as y } from "./configs/baseUrl.js";
@@ -1,7 +1,7 @@
1
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
- import { E as e } from "../AccountService-CKYH_7VT.js";
4
+ import { E as e } from "../AccountService-Dt2-k7CN.js";
5
5
  import { useAwayzAuth as s } from "../hooks/useAwayzAuth/useAwayzAuth.js";
6
6
  import { setBaseUrl as l } from "../configs/baseUrl.js";
7
7
  import { QueryClientProvider as u } from "@tanstack/react-query";
@@ -1,4 +1,4 @@
1
- import { a as p } from "../../AccountService-CKYH_7VT.js";
1
+ import { A as p } from "../../AccountService-Dt2-k7CN.js";
2
2
  import "react";
3
3
  import "../../configs/endpoints.js";
4
4
  import "../../configs/awayzClient.js";
@@ -1,7 +1,7 @@
1
1
  import '../../assets/_styles.css';var s = Object.defineProperty;
2
2
  var i = (t, r, e) => r in t ? s(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
3
3
  var c = (t, r, e) => i(t, typeof r != "symbol" ? r + "" : r, e);
4
- import { a as u, b as y, c as p } from "../../AccountService-CKYH_7VT.js";
4
+ import { A as u, a as y, c as p } from "../../AccountService-Dt2-k7CN.js";
5
5
  import "react";
6
6
  import { ECurrencyEndpoints as m } from "../../configs/endpoints.js";
7
7
  import "react/jsx-runtime";
@@ -1,4 +1,4 @@
1
- import { c as p, i as a } from "../AccountService-CKYH_7VT.js";
1
+ import { c as p, i as a } from "../AccountService-Dt2-k7CN.js";
2
2
  import "react";
3
3
  import "../configs/endpoints.js";
4
4
  import "../configs/baseUrl.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-core",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"