@odynn/awayz-core 0.2.7 → 0.2.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.
@@ -7717,6 +7717,7 @@ export {
7717
7717
  gM as a,
7718
7718
  e1 as b,
7719
7719
  Z as c,
7720
+ E0 as d,
7720
7721
  nA as g,
7721
7722
  $o as i
7722
7723
  };
@@ -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-Bn0h1CSa.js";
4
+ import { g as ZO, b as JO } from "../../AccountService-CKQ3VzVx.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,6 +9,8 @@ const t = s({
9
9
  },
10
10
  resendVerificationEmail: async () => !1,
11
11
  setTokens: () => {
12
+ },
13
+ getRequestLimits: async () => {
12
14
  }
13
15
  });
14
16
  export {
@@ -1,8 +1,8 @@
1
- import { A as N, E as r, a as u, b as F } from "../../AccountService-Bn0h1CSa.js";
2
- import { useState as m, useCallback as x, useEffect as w } from "react";
1
+ import { A as N, E as r, a as i, b as F, d as x } from "../../AccountService-CKQ3VzVx.js";
2
+ import { useState as m, useCallback as U, useEffect as w } from "react";
3
3
  import { EAuthFlow as k } from "../../types/EAuthFlow.js";
4
- import { awayzClient as U } from "../../configs/awayzClient.js";
5
- const i = (t, a) => {
4
+ import { awayzClient as p } from "../../configs/awayzClient.js";
5
+ const u = (t, a) => {
6
6
  var f, E;
7
7
  let c = "", d = a;
8
8
  typeof a == "string" ? c = a : a instanceof N ? (c = a.message, d = {
@@ -17,28 +17,28 @@ const i = (t, a) => {
17
17
  },
18
18
  "*"
19
19
  );
20
- }, L = (t) => {
21
- const [a, c] = m(!0), [d, f] = m(!1), [E, S] = m(), [R, T] = m(), [O, _] = m([]), h = x(
20
+ }, V = (t) => {
21
+ const [a, c] = m(!0), [d, f] = m(!1), [E, S] = m(), [R, T] = m(), [O, _] = m([]), h = U(
22
22
  async (s) => {
23
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), S(s.token), T(s.user);
24
24
  },
25
25
  [t]
26
26
  ), y = async (s) => {
27
27
  try {
28
- const { success: e, data: n, message: o } = await u.authenticateWithToken(s);
28
+ const { success: e, data: n, message: o } = await i.authenticateWithToken(s);
29
29
  if (!e) {
30
- i("exchange_token", o);
30
+ u("exchange_token", o);
31
31
  return;
32
32
  }
33
33
  if (!(n != null && n.token)) {
34
- i(
34
+ u(
35
35
  "exchange_token",
36
36
  "no awayz token returned after exchanging id token"
37
37
  );
38
38
  return;
39
39
  }
40
40
  localStorage.setItem(r.TOKEN, n.token), await h(n);
41
- const { data: g, ...l } = await u.getRequestLimit();
41
+ const { data: g, ...l } = await i.getRequestLimit();
42
42
  if (!l.success) {
43
43
  console.error({ reqLimitError: l });
44
44
  return;
@@ -57,14 +57,14 @@ const i = (t, a) => {
57
57
  } finally {
58
58
  c(!1);
59
59
  }
60
- }, I = async () => {
60
+ }, K = async () => {
61
61
  try {
62
- const { success: s, data: e } = await U.ensureQueryData({
62
+ const { success: s, data: e } = await p.ensureQueryData({
63
63
  queryKey: [F.CHECK_USER],
64
- queryFn: u.checkUser
64
+ queryFn: i.checkUser
65
65
  });
66
66
  if (!s) {
67
- i("exchange_token", e);
67
+ u("exchange_token", e);
68
68
  return;
69
69
  }
70
70
  await h({
@@ -72,7 +72,7 @@ const i = (t, a) => {
72
72
  token: localStorage.getItem(r.TOKEN)
73
73
  });
74
74
  } catch (s) {
75
- i("exchange_token", s);
75
+ u("exchange_token", s);
76
76
  } finally {
77
77
  c(!1);
78
78
  }
@@ -80,14 +80,14 @@ const i = (t, a) => {
80
80
  w(() => {
81
81
  if (t.authFlow !== k.OAUTH) return;
82
82
  const s = localStorage.getItem(r.TOKEN), e = localStorage.getItem(r.REFRESH_TOKEN);
83
- s && e ? I() : c(!1);
83
+ s && e ? K() : c(!1);
84
84
  }, []);
85
- const K = async () => {
86
- const s = await u.getRegions();
85
+ const I = async () => {
86
+ const s = await i.getRegions();
87
87
  _(s);
88
88
  };
89
89
  return w(() => {
90
- K();
90
+ I();
91
91
  }, []), w(() => {
92
92
  if (t.authFlow !== k.QUERY) return;
93
93
  const e = new URLSearchParams(window.location.search).get(r.TOKEN);
@@ -103,7 +103,7 @@ const i = (t, a) => {
103
103
  e.data
104
104
  )}
105
105
  no idToken in body`;
106
- i("exchange_token", l);
106
+ u("exchange_token", l);
107
107
  return;
108
108
  }
109
109
  if (!o) {
@@ -111,7 +111,7 @@ const i = (t, a) => {
111
111
  e.data
112
112
  )}
113
113
  no refreshToken in body`;
114
- i("refresh_token", l);
114
+ u("refresh_token", l);
115
115
  return;
116
116
  }
117
117
  localStorage.setItem(r.REFRESH_TOKEN, o), await y(n);
@@ -133,9 +133,9 @@ const i = (t, a) => {
133
133
  supportedRegions: O,
134
134
  signIn: async (s) => {
135
135
  var n;
136
- const e = await u.login(s);
136
+ const e = await i.login(s);
137
137
  if (!e.success)
138
- i("exchange_token", e.message);
138
+ u("exchange_token", e.message);
139
139
  else {
140
140
  const o = (n = e.data) == null ? void 0 : n.refreshToken;
141
141
  localStorage.setItem(r.REFRESH_TOKEN, o), await h(e.data);
@@ -144,9 +144,9 @@ const i = (t, a) => {
144
144
  },
145
145
  signUp: async (s) => {
146
146
  var n;
147
- const e = await u.signUp(s);
147
+ const e = await i.signUp(s);
148
148
  if (!e.success)
149
- i("exchange_token", e.message);
149
+ u("exchange_token", e.message);
150
150
  else {
151
151
  const o = (n = e.data) == null ? void 0 : n.refreshToken;
152
152
  localStorage.setItem(r.REFRESH_TOKEN, o), await h(e.data);
@@ -156,13 +156,21 @@ const i = (t, a) => {
156
156
  signOut: () => {
157
157
  localStorage.removeItem(r.TOKEN), localStorage.removeItem(r.REFRESH_TOKEN), f(!1), S(void 0), T(void 0);
158
158
  },
159
- resendVerificationEmail: async (s) => (await u.resendVerificationEmail(s)).success,
159
+ resendVerificationEmail: async (s) => (await i.resendVerificationEmail(s)).success,
160
160
  setTokens: (s, e) => {
161
161
  localStorage.setItem(r.TOKEN, s), localStorage.setItem(r.REFRESH_TOKEN, e), y(s);
162
+ },
163
+ getRequestLimits: async () => {
164
+ const { data: s, ...e } = await i.getRequestLimit();
165
+ if (!e.success) {
166
+ console.error({ reqLimitError: e });
167
+ return;
168
+ }
169
+ return x(s);
162
170
  }
163
171
  };
164
172
  };
165
173
  export {
166
- i as authFailurePostMessage,
167
- L as useAwayzAuth
174
+ u as authFailurePostMessage,
175
+ V as useAwayzAuth
168
176
  };
@@ -1,4 +1,4 @@
1
- import { IRegion, IResendVerificationEmailParams, IUser } from '../services/account/AccountServices.types';
1
+ import { IRegion, IResendVerificationEmailParams, ISearchLimit, 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,5 +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
17
  }
17
18
  export declare const AwayzContext: import('react').Context<IAwayzContext>;
@@ -1,5 +1,5 @@
1
1
  import { TEmbeddedAuthOptions } from './useAwayzAuth.types';
2
- import { IAuthData, IRegion, IResendVerificationEmailParams, IUser } from '../../services/account/AccountServices.types';
2
+ import { IAuthData, IRegion, IResendVerificationEmailParams, ISearchLimit, 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,5 +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
37
  };
37
38
  export {};
@@ -41,6 +41,14 @@ interface IFeature {
41
41
  text: string;
42
42
  included: boolean;
43
43
  }
44
+ export interface ISearchLimit {
45
+ isAdmin: boolean;
46
+ numberOfCalls: number;
47
+ remainingCalls: number;
48
+ searchLimit: number;
49
+ searchType: string;
50
+ subscription: string;
51
+ }
44
52
  export interface IResetPasswordParams {
45
53
  email: string;
46
54
  password: string;
@@ -86,13 +94,6 @@ export interface IUserResponse {
86
94
  email_verified: boolean;
87
95
  _id: string;
88
96
  }
89
- export interface ISubscription {
90
- tier: string;
91
- flight_search_limit: number;
92
- hotel_search_limit: number;
93
- is_paid: boolean;
94
- _id: string;
95
- }
96
97
  export interface ISpendingBreakdown {
97
98
  Internet: number;
98
99
  Restaurants: number;
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-Bn0h1CSa.js";
4
+ import { c as s, i as x } from "./AccountService-CKQ3VzVx.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 r } 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-Bn0h1CSa.js";
4
+ import { E as e } from "../AccountService-CKQ3VzVx.js";
5
5
  import { useAwayzAuth as l } from "../hooks/useAwayzAuth/useAwayzAuth.js";
6
6
  import { setBaseUrl as s } 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-Bn0h1CSa.js";
1
+ import { a as p } from "../../AccountService-CKQ3VzVx.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-Bn0h1CSa.js";
4
+ import { a as u, b as y, c as p } from "../../AccountService-CKQ3VzVx.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-Bn0h1CSa.js";
1
+ import { c as p, i as a } from "../AccountService-CKQ3VzVx.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.7",
3
+ "version": "0.2.8",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"