@odynn/awayz-core 0.2.16 → 0.2.18

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,32 +1,32 @@
1
- import { A as _, E as r, a as o, b as U } from "../../AccountService--d4c37gO.js";
1
+ import { A as U, E as r, a as o, b as v } from "../../AccountService--d4c37gO.js";
2
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 H } from "../../configs/awayzClient.js";
5
- const M = (s, t) => {
6
- var f, d;
7
- let c = "", m = t;
8
- typeof t == "string" ? c = t : t instanceof _ ? (c = t.message, m = {
4
+ import { awayzClient as A } from "../../configs/awayzClient.js";
5
+ const H = (s, t) => {
6
+ var f, m;
7
+ let c = "", d = t;
8
+ typeof t == "string" ? c = t : t instanceof U ? (c = t.message, d = {
9
9
  message: t.message,
10
10
  cause: t.cause,
11
11
  status: t.status,
12
12
  data: (f = t == null ? void 0 : t.response) == null ? void 0 : f.data
13
- }) : c = t.message, (d = window.parent) == null || d.postMessage(
13
+ }) : c = t.message, (m = window.parent) == null || m.postMessage(
14
14
  {
15
15
  type: "auth_error",
16
- details: { message: c, action: s, info: m }
16
+ details: { message: c, action: s, info: d }
17
17
  },
18
18
  "*"
19
19
  );
20
20
  }, V = (s) => {
21
- const [t, c] = E(!0), [m, f] = E(!1), [d, T] = E(), [A, k] = E(), [O, I] = E([]), w = R(
21
+ const [t, c] = E(!0), [d, f] = E(!1), [m, T] = E(), [O, k] = E(), [I, K] = E([]), w = R(
22
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);
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), A.invalidateQueries();
24
24
  },
25
25
  [s]
26
26
  ), i = R(
27
27
  async (a, e) => {
28
28
  if (s.authFlow !== S.POST_MESSAGE)
29
- return M(e ?? "exchange_token", a);
29
+ return H(e ?? "exchange_token", a);
30
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
32
  [s]
@@ -48,10 +48,10 @@ const M = (s, t) => {
48
48
  return;
49
49
  }
50
50
  l == null || l.forEach(
51
- (F) => window.parent.postMessage(
51
+ (_) => window.parent.postMessage(
52
52
  {
53
53
  type: "request_limit",
54
- limit: F
54
+ limit: _
55
55
  },
56
56
  "*"
57
57
  )
@@ -61,10 +61,10 @@ const M = (s, t) => {
61
61
  } finally {
62
62
  c(!1);
63
63
  }
64
- }, K = async () => {
64
+ }, N = async () => {
65
65
  try {
66
- const { success: a, data: e } = await H.ensureQueryData({
67
- queryKey: [U.CHECK_USER],
66
+ const { success: a, data: e } = await A.ensureQueryData({
67
+ queryKey: [v.CHECK_USER],
68
68
  queryFn: o.checkUser
69
69
  });
70
70
  if (!a) {
@@ -84,14 +84,14 @@ const M = (s, t) => {
84
84
  y(() => {
85
85
  if (s.authFlow !== S.STANDARD) return;
86
86
  const a = localStorage.getItem(r.TOKEN), e = localStorage.getItem(r.REFRESH_TOKEN);
87
- a && e ? K() : c(!1);
87
+ a && e ? N() : c(!1);
88
88
  }, []);
89
- const N = async () => {
89
+ const F = async () => {
90
90
  const a = await o.getRegions();
91
- I(a);
91
+ K(a);
92
92
  };
93
93
  return y(() => {
94
- N();
94
+ F();
95
95
  }, []), y(() => {
96
96
  if (s.authFlow !== S.QUERY) return;
97
97
  const e = new URLSearchParams(window.location.search).get(r.TOKEN);
@@ -135,10 +135,10 @@ const M = (s, t) => {
135
135
  };
136
136
  }, []), {
137
137
  isAuthenticating: t,
138
- isAuthenticated: m,
139
- token: d,
140
- user: A,
141
- supportedRegions: O,
138
+ isAuthenticated: d,
139
+ token: m,
140
+ user: O,
141
+ supportedRegions: I,
142
142
  signIn: async (a) => {
143
143
  var n;
144
144
  const e = await o.login(a);
@@ -171,6 +171,6 @@ const M = (s, t) => {
171
171
  };
172
172
  };
173
173
  export {
174
- M as authFailurePostMessage,
174
+ H as authFailurePostMessage,
175
175
  V as useAwayzAuth
176
176
  };
@@ -1,22 +1,10 @@
1
1
  import { ISearchLimit } from '../services/account/AccountServices.types';
2
- export declare const useSearchLimit: () => [ISearchLimit, ISearchLimit] | [undefined, undefined];
3
2
  /**
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
- ],
3
+ * @description
4
+ * useSearchLimit is a custom hook that fetches the search limits for Flight and Hotel searches.
5
+ * The hook returns an array of two ISearchLimit objects, one for Flights and one for Hotels.
6
+ *
7
+ * @returns [FlightSearchLimit, HotelSearchLimit]
8
+ * @returns [undefined, undefined] if the data is not available
22
9
  */
10
+ export declare const useSearchLimit: () => [ISearchLimit, ISearchLimit] | [undefined, undefined];
@@ -1,6 +1,15 @@
1
1
  import { IConvertCurrencyArgs } from './CurrencyService.types';
2
2
  declare class _CurrencyService {
3
3
  convertCurrency: ({ baseCurrency }: IConvertCurrencyArgs) => Promise<number>;
4
+ /**
5
+ * Convert from base currency to target currency for the amount provided
6
+ * @param param0 IConvertCurrencyArgs
7
+ * @param baseCurrency the base currency to convert from
8
+ * @param targetCurrency the target currency to convert to
9
+ * @parm amount the amount to be converted from the base to the target currency
10
+ * @returns the converted amount
11
+ */
12
+ convertToCurrency: ({ baseCurrency, targetCurrency, amount }: IConvertCurrencyArgs) => Promise<number>;
4
13
  }
5
14
  export declare const CurrencyService: _CurrencyService;
6
15
  export {};
@@ -1,5 +1,6 @@
1
1
  export interface IConvertCurrencyArgs {
2
2
  baseCurrency: string;
3
+ targetCurrency?: string;
3
4
  amount?: number;
4
5
  }
5
6
  export interface IConvertCurrencyResult {
@@ -1,40 +1,66 @@
1
- import '../../assets/_styles.css';var s = Object.defineProperty;
2
- var i = (t, r, e) => r in t ? s(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
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--d4c37gO.js";
1
+ import '../../assets/_styles.css';var i = Object.defineProperty;
2
+ var y = (t, r, e) => r in t ? i(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
3
+ var o = (t, r, e) => y(t, typeof r != "symbol" ? r + "" : r, e);
4
+ import { a as p, b as C, c as a } from "../../AccountService--d4c37gO.js";
5
5
  import "react";
6
- import { ECurrencyEndpoints as m } from "../../configs/endpoints.js";
6
+ import { ECurrencyEndpoints as s } from "../../configs/endpoints.js";
7
7
  import "react/jsx-runtime";
8
8
  import "../../context/AwayzContext.js";
9
- import { awayzClient as C } from "../../configs/awayzClient.js";
9
+ import { awayzClient as m } from "../../configs/awayzClient.js";
10
10
  import "@tanstack/react-query";
11
11
  /* empty css */
12
12
  class E {
13
13
  constructor() {
14
- c(this, "convertCurrency", async ({
14
+ o(this, "convertCurrency", async ({
15
15
  baseCurrency: r
16
16
  }) => {
17
17
  try {
18
- const { success: e, data: n } = await C.ensureQueryData({
19
- queryKey: [y.CHECK_USER],
20
- queryFn: u.checkUser
18
+ const { success: e, data: n } = await m.ensureQueryData({
19
+ queryKey: [C.CHECK_USER],
20
+ queryFn: p.checkUser
21
21
  });
22
22
  if (!e)
23
23
  throw new Error("Failed to fetch user data");
24
- const { userRegion: o } = n, { data: a } = await p.post(m.CURRENCY_CONVERSION, {
25
- target_currency: o.currency,
24
+ const { userRegion: c } = n, { data: u } = await a.post(s.CURRENCY_CONVERSION, {
25
+ target_currency: c.currency,
26
26
  base_currency: r
27
27
  });
28
28
  if (e)
29
- return a.data.conversion_rate;
29
+ return u.data.conversion_rate;
30
30
  } catch (e) {
31
31
  console.error(e);
32
32
  }
33
33
  return 0;
34
34
  });
35
+ /**
36
+ * Convert from base currency to target currency for the amount provided
37
+ * @param param0 IConvertCurrencyArgs
38
+ * @param baseCurrency the base currency to convert from
39
+ * @param targetCurrency the target currency to convert to
40
+ * @parm amount the amount to be converted from the base to the target currency
41
+ * @returns the converted amount
42
+ */
43
+ o(this, "convertToCurrency", async ({
44
+ baseCurrency: r,
45
+ targetCurrency: e,
46
+ amount: n
47
+ }) => {
48
+ try {
49
+ const { data: c } = await a.post(s.CURRENCY_CONVERSION, {
50
+ target_currency: e,
51
+ base_currency: r,
52
+ amount: n
53
+ });
54
+ if (c.success)
55
+ return c.data.conversion_result;
56
+ } catch (c) {
57
+ console.error(c);
58
+ }
59
+ return 0;
60
+ });
35
61
  }
36
62
  }
37
- const K = new E();
63
+ const h = new E();
38
64
  export {
39
- K as CurrencyService
65
+ h as CurrencyService
40
66
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-core",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"