@odynn/awayz-flights 0.1.9 → 0.1.11

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,4 +1,4 @@
1
- var s = /* @__PURE__ */ ((r) => (r.GET_AIRPORTS = "/flights/search/airports", r.CASH_FLIGHT_SEARCH = "/flights/search/one-way/cash", r.CASH_OUTBOUND_SEARCH = "flights/search/multi/outbound", r.CASH_INBOUND_SEARCH = "flights/search/multi/inbound", r))(s || {});
1
+ var r = /* @__PURE__ */ ((s) => (s.GET_AIRPORTS = "/flights/search/airports", s.CASH_FLIGHT_SEARCH = "/flights/search/one-way/cash", s.CASH_OUTBOUND_SEARCH = "/flights/search/multi/outbound", s.CASH_INBOUND_SEARCH = "/flights/search/multi/inbound", s.ROUND_TRIP_FARES = "/flights/search/multi/fares", s))(r || {});
2
2
  export {
3
- s as EFlightEndpoint
3
+ r as EFlightEndpoint
4
4
  };
@@ -1,53 +1,53 @@
1
1
  import { useState as n } from "react";
2
- import { useMutation as i } from "@tanstack/react-query";
3
- import { ECabinClass as w, EFlightType as d } from "../../types/enums.js";
4
- import { FlightService as a } from "../../services/flights/FlightsService.js";
5
- import { parseFlightDetails as S, groupFlightResults as _ } from "../../utils/flightUtils.js";
6
- const q = 1, F = w.ECONOMY, I = (r) => {
7
- if (!r.origin || !r.destination)
2
+ import { useMutation as a } from "@tanstack/react-query";
3
+ import { ECabinClass as D, EFlightType as d } from "../../types/enums.js";
4
+ import { FlightService as u } from "../../services/flights/FlightsService.js";
5
+ import { parseFlightDetails as C, groupFlightResults as _ } from "../../utils/flightUtils.js";
6
+ const N = 1, P = D.ECONOMY, A = (t) => {
7
+ if (!t.origin || !t.destination)
8
8
  throw new Error("Origin and destination are required.");
9
- if (!r.departureDate)
9
+ if (!t.departureDate)
10
10
  throw new Error("Departure date is required.");
11
- if (r.flightType === d.ROUND_TRIP && !r.returnDate)
11
+ if (t.flightType === d.ROUND_TRIP && !t.returnDate)
12
12
  throw new Error("Return date is required for round-trip flights.");
13
- }, v = () => {
14
- const [r, c] = n(""), [l, f] = n([]), [p, h] = n([]), u = ({
15
- data: t,
16
- previousResults: o,
17
- inbound: s
13
+ }, j = () => {
14
+ const [t, c] = n(""), [f, l] = n(""), [p, h] = n([]), [b, R] = n([]), [g, O] = n([]), i = ({
15
+ data: r,
16
+ previousResults: s,
17
+ inbound: o
18
18
  }) => {
19
- const e = S(t, o);
20
- return (s ? h : f)(_(e)), e;
19
+ const e = C(r, s);
20
+ return (o ? R : h)(_(e)), e;
21
21
  }, {
22
- mutate: b,
23
- status: g,
24
- error: m
25
- } = i({
26
- mutationFn: async (t) => {
27
- I(t);
28
- const s = {
22
+ mutate: m,
23
+ status: E,
24
+ error: F
25
+ } = a({
26
+ mutationFn: async (r) => {
27
+ A(r);
28
+ const o = {
29
29
  passengers: Array.from(
30
- { length: t.passengers ?? q },
30
+ { length: r.passengers ?? N },
31
31
  () => ({ type: "adult" })
32
32
  ),
33
- origin: t.origin || "",
34
- destination: t.destination || "",
35
- cabin_class: t.cabinClass || F
33
+ origin: r.origin || "",
34
+ destination: r.destination || "",
35
+ cabin_class: r.cabinClass || P
36
36
  };
37
- if (t.flightType === d.ONE_WAY) {
38
- const e = await a.cashOnlySearch({
39
- ...s,
40
- departure_date: t.departureDate
37
+ if (r.flightType === d.ONE_WAY) {
38
+ const e = await u.cashOnlySearch({
39
+ ...o,
40
+ departure_date: r.departureDate
41
41
  });
42
42
  return {
43
43
  success: e.success,
44
44
  data: e.data
45
45
  };
46
46
  } else {
47
- const e = await a.roundTripOutboundSearch({
48
- ...s,
49
- departure_date: t.departureDate,
50
- return_date: t.returnDate
47
+ const e = await u.roundTripOutboundSearch({
48
+ ...o,
49
+ departure_date: r.departureDate,
50
+ return_date: r.returnDate
51
51
  });
52
52
  return {
53
53
  success: e.success,
@@ -56,54 +56,79 @@ const q = 1, F = w.ECONOMY, I = (r) => {
56
56
  };
57
57
  }
58
58
  },
59
- onSuccess: (t) => {
60
- console.log({ result: t });
61
- const { success: o, data: s, partialOfferRequestId: e } = t;
62
- if (!o) {
59
+ onSuccess: (r) => {
60
+ console.log({ result: r });
61
+ const { success: s, data: o, partialOfferRequestId: e } = r;
62
+ if (!s) {
63
63
  console.log("oh lol, it didn't work");
64
64
  return;
65
65
  }
66
- u({ data: s }), e && c(e);
66
+ i({ data: o }), e && c(e);
67
67
  },
68
- onError: (t) => {
69
- console.error("Error in outbound flight search:", t);
68
+ onError: (r) => {
69
+ console.error("Error in outbound flight search:", r);
70
70
  }
71
71
  }), {
72
- mutate: R,
73
- status: O,
74
- error: E
75
- } = i({
76
- mutationFn: async (t) => {
77
- if (!r)
72
+ mutate: w,
73
+ status: I,
74
+ error: S
75
+ } = a({
76
+ mutationFn: async (r) => {
77
+ if (!t)
78
78
  throw new Error("No partialOfferRequestId found for inbound search.");
79
- return await a.roundTripInboundSearch({
80
- outbound_offer_id: t,
81
- outbound_offer_request_id: r
79
+ return l(r), await u.roundTripInboundSearch({
80
+ outboundOfferId: r,
81
+ outboundOfferRequestId: t
82
82
  });
83
83
  },
84
- onSuccess: (t) => {
85
- const { success: o, data: s } = t;
86
- o && u({
87
- data: s.offers,
84
+ onSuccess: (r) => {
85
+ const { success: s, data: o } = r;
86
+ s && i({
87
+ data: o.offers,
88
88
  inbound: !0
89
89
  });
90
90
  },
91
- onError: (t) => {
92
- console.error("Error in inbound flight search:", t);
91
+ onError: (r) => {
92
+ console.error("Error in inbound flight search:", r);
93
+ }
94
+ }), {
95
+ mutate: q,
96
+ status: T,
97
+ error: y
98
+ } = a({
99
+ mutationFn: async (r) => {
100
+ if (!t)
101
+ throw new Error("No partialOfferRequestId found for round-trip fares.");
102
+ return await u.getRoundTripFares({
103
+ outboundOfferId: f,
104
+ outboundOfferRequestId: t,
105
+ inboundOfferId: r
106
+ });
107
+ },
108
+ onSuccess: (r) => {
109
+ const { success: s, data: o } = r;
110
+ s && O(o);
111
+ },
112
+ onError: (r) => {
113
+ console.error("Error in round-trip fare search:", r);
93
114
  }
94
115
  });
95
116
  return {
96
- loading: g === "pending" || O === "pending",
97
- outboundError: m,
98
- inboundError: E,
117
+ loading: E === "pending" || I === "pending",
118
+ loadingFares: T === "pending",
119
+ outboundError: F,
120
+ inboundError: S,
121
+ roundTripFaresError: y,
99
122
  // Results
100
- outboundResults: l,
101
- inboundResults: p,
123
+ outboundResults: p,
124
+ inboundResults: b,
125
+ roundTripFares: g,
102
126
  // Mutation triggers
103
- searchOutboundFlights: b,
104
- searchInboundFlights: R
127
+ searchOutboundFlights: m,
128
+ searchInboundFlights: w,
129
+ getRoundTripFares: q
105
130
  };
106
131
  };
107
132
  export {
108
- v as useFlightSearch
133
+ j as useFlightSearch
109
134
  };
@@ -1,6 +1,7 @@
1
1
  export declare enum EFlightEndpoint {
2
2
  GET_AIRPORTS = "/flights/search/airports",
3
3
  CASH_FLIGHT_SEARCH = "/flights/search/one-way/cash",
4
- CASH_OUTBOUND_SEARCH = "flights/search/multi/outbound",
5
- CASH_INBOUND_SEARCH = "flights/search/multi/inbound"
4
+ CASH_OUTBOUND_SEARCH = "/flights/search/multi/outbound",
5
+ CASH_INBOUND_SEARCH = "/flights/search/multi/inbound",
6
+ ROUND_TRIP_FARES = "/flights/search/multi/fares"
6
7
  }
@@ -1,10 +1,13 @@
1
1
  import { IFlightOffer, IFlightResult, ISearchFlightArgs } from './useFlightSearch.types';
2
2
  export declare const useFlightSearch: () => {
3
3
  loading: boolean;
4
+ loadingFares: boolean;
4
5
  outboundError: Error | null;
5
6
  inboundError: Error | null;
7
+ roundTripFaresError: Error | null;
6
8
  outboundResults: IFlightResult[];
7
9
  inboundResults: IFlightResult[];
10
+ roundTripFares: IFlightOffer[];
8
11
  searchOutboundFlights: import('@tanstack/react-query').UseMutateFunction<{
9
12
  success: boolean;
10
13
  data: [] | IFlightOffer[] | undefined;
@@ -15,4 +18,5 @@ export declare const useFlightSearch: () => {
15
18
  partialOfferRequestId: any;
16
19
  }, Error, ISearchFlightArgs, unknown>;
17
20
  searchInboundFlights: import('@tanstack/react-query').UseMutateFunction<any, Error, string, unknown>;
21
+ getRoundTripFares: import('@tanstack/react-query').UseMutateFunction<any, Error, string, unknown>;
18
22
  };
@@ -1,5 +1,5 @@
1
1
  import { TServiceResponse } from '@type-op/shared';
2
- import { IOneWayCashOnlyFlightSearchArgs, IRoundCashOnlyFlightSearchArgs } from './FlightsService.types';
2
+ import { IOneWayCashOnlyFlightSearchArgs, IRoundCashOnlyFlightSearchArgs, IRoundTripFareSearchArgs, IRoundTripInboundSearchArgs } from './FlightsService.types';
3
3
  import { IFlightOffer } from '../../hooks/useFlightSearch/useFlightSearch.types';
4
4
  import { IAirport } from '../../hooks/useAirportSearch/useAirportSearch.types';
5
5
  declare class _FlightService {
@@ -14,7 +14,8 @@ declare class _FlightService {
14
14
  message: any;
15
15
  data?: undefined;
16
16
  }>;
17
- roundTripInboundSearch: (args: any) => Promise<any>;
17
+ roundTripInboundSearch: (args: IRoundTripInboundSearchArgs) => Promise<any>;
18
+ getRoundTripFares: (args: IRoundTripFareSearchArgs) => Promise<any>;
18
19
  }
19
20
  export declare const FlightService: _FlightService;
20
21
  export {};
@@ -198,4 +198,11 @@ export interface IOwnerResponse {
198
198
  name: string;
199
199
  id: string;
200
200
  }
201
+ export interface IRoundTripInboundSearchArgs {
202
+ outboundOfferRequestId: string;
203
+ outboundOfferId: string;
204
+ }
205
+ export interface IRoundTripFareSearchArgs extends IRoundTripInboundSearchArgs {
206
+ inboundOfferId: string;
207
+ }
201
208
  export {};
@@ -1,25 +1,25 @@
1
- var r = Object.defineProperty;
2
- var l = (t, s, a) => s in t ? r(t, s, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[s] = a;
3
- var d = (t, s, a) => l(t, typeof s != "symbol" ? s + "" : s, a);
1
+ var f = Object.defineProperty;
2
+ var m = (a, s, t) => s in a ? f(a, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[s] = t;
3
+ var u = (a, s, t) => m(a, typeof s != "symbol" ? s + "" : s, t);
4
4
  import "../../arrayExtensions-DWKenJCh.js";
5
- import { EFlightEndpoint as o } from "../../constants/endpoints.js";
6
- import { clientInstance as m } from "@odynn/awayz-auth";
7
- function y(t) {
8
- return t = t.replace(/^_+/, ""), t.replace(/_([a-z])/g, (s, a) => a.toUpperCase());
5
+ import { EFlightEndpoint as d } from "../../constants/endpoints.js";
6
+ import { clientInstance as i } from "@odynn/awayz-auth";
7
+ function _(a) {
8
+ return a = a.replace(/^_+/, ""), a.replace(/_([a-z])/g, (s, t) => t.toUpperCase());
9
9
  }
10
- const i = (t) => Array.isArray(t) ? t.map((s) => i(s)) : typeof t == "object" && t !== null ? Object.keys(t).reduce((s, a) => {
11
- const n = y(a);
12
- return s[n] = i(t[a]), s;
13
- }, {}) : t;
14
- class g {
10
+ const r = (a) => Array.isArray(a) ? a.map((s) => r(s)) : typeof a == "object" && a !== null ? Object.keys(a).reduce((s, t) => {
11
+ const c = _(t);
12
+ return s[c] = r(a[t]), s;
13
+ }, {}) : a;
14
+ class l {
15
15
  constructor() {
16
- d(this, "getAirports", async (s) => {
16
+ u(this, "getAirports", async (s) => {
17
17
  try {
18
- const { data: a } = await m.get(
19
- `${o.GET_AIRPORTS}?search_term=${s}`
18
+ const { data: t } = await i.get(
19
+ `${d.GET_AIRPORTS}?search_term=${s}`
20
20
  );
21
- return a.data.map((e) => {
22
- var u;
21
+ return t.data.map((e) => {
22
+ var o;
23
23
  return {
24
24
  city: {
25
25
  name: e.city_name,
@@ -31,7 +31,7 @@ class g {
31
31
  },
32
32
  country: {
33
33
  code: e.iata_country_code,
34
- name: (u = e.country) == null ? void 0 : u.name
34
+ name: (o = e.country) == null ? void 0 : o.name
35
35
  },
36
36
  name: e.name,
37
37
  iataCode: e.iata_code,
@@ -44,72 +44,97 @@ class g {
44
44
  return [];
45
45
  }
46
46
  });
47
- d(this, "cashOnlySearch", async (s) => {
48
- var a, n, e, u;
47
+ u(this, "cashOnlySearch", async (s) => {
48
+ var t, c, e, o;
49
49
  try {
50
- const { data: c } = await m.post(
51
- o.CASH_FLIGHT_SEARCH,
50
+ const { data: n } = await i.post(
51
+ d.CASH_FLIGHT_SEARCH,
52
52
  s
53
53
  );
54
- return c.success ? {
54
+ return n.success ? {
55
55
  success: !0,
56
- data: i(
57
- c.data.offers
56
+ data: r(
57
+ n.data.offers
58
58
  )
59
59
  } : {
60
60
  success: !1,
61
- message: c.message
61
+ message: n.message
62
62
  };
63
- } catch (c) {
64
- return console.error(JSON.stringify(c)), c.message === "canceled" ? {
63
+ } catch (n) {
64
+ return console.error(JSON.stringify(n)), n.message === "canceled" ? {
65
65
  success: !1,
66
- message: ((n = (a = c == null ? void 0 : c.response) == null ? void 0 : a.data) == null ? void 0 : n.message) || (c == null ? void 0 : c.message)
66
+ message: ((c = (t = n == null ? void 0 : n.response) == null ? void 0 : t.data) == null ? void 0 : c.message) || (n == null ? void 0 : n.message)
67
67
  } : {
68
68
  success: !1,
69
- message: ((u = (e = c == null ? void 0 : c.response) == null ? void 0 : e.data) == null ? void 0 : u.message) || (c == null ? void 0 : c.message)
69
+ message: ((o = (e = n == null ? void 0 : n.response) == null ? void 0 : e.data) == null ? void 0 : o.message) || (n == null ? void 0 : n.message)
70
70
  };
71
71
  }
72
72
  });
73
- d(this, "roundTripOutboundSearch", async (s) => {
74
- var a, n;
73
+ u(this, "roundTripOutboundSearch", async (s) => {
74
+ var t, c;
75
75
  try {
76
- const { data: e } = await m.post(
77
- o.CASH_OUTBOUND_SEARCH,
76
+ const { data: e } = await i.post(
77
+ d.CASH_OUTBOUND_SEARCH,
78
78
  { ...s, to: s.return_date, from: s.departure_date }
79
79
  );
80
80
  if (!e.success) throw e;
81
81
  return {
82
82
  success: e.success,
83
- data: i(e.data)
83
+ data: r(e.data)
84
84
  };
85
85
  } catch (e) {
86
86
  return {
87
87
  success: !1,
88
- message: ((n = (a = e == null ? void 0 : e.response) == null ? void 0 : a.data) == null ? void 0 : n.message) || (e == null ? void 0 : e.message)
88
+ message: ((c = (t = e == null ? void 0 : e.response) == null ? void 0 : t.data) == null ? void 0 : c.message) || (e == null ? void 0 : e.message)
89
89
  };
90
90
  }
91
91
  });
92
- d(this, "roundTripInboundSearch", async (s) => {
93
- var a, n;
92
+ u(this, "roundTripInboundSearch", async (s) => {
93
+ var t, c;
94
94
  try {
95
- const { data: e } = await m.get(
96
- o.CASH_INBOUND_SEARCH,
95
+ const { data: e } = await i.get(
96
+ d.CASH_INBOUND_SEARCH,
97
97
  {
98
- params: s
98
+ params: {
99
+ outbound_offer_id: s.outboundOfferId,
100
+ outbound_offer_request_id: s.outboundOfferRequestId
101
+ }
99
102
  }
100
103
  );
101
104
  if (!e.success) throw e;
102
- return e;
105
+ return r(e);
103
106
  } catch (e) {
104
107
  return {
105
108
  success: !1,
106
- message: ((n = (a = e == null ? void 0 : e.response) == null ? void 0 : a.data) == null ? void 0 : n.message) || (e == null ? void 0 : e.message)
109
+ message: ((c = (t = e == null ? void 0 : e.response) == null ? void 0 : t.data) == null ? void 0 : c.message) || (e == null ? void 0 : e.message)
110
+ };
111
+ }
112
+ });
113
+ u(this, "getRoundTripFares", async (s) => {
114
+ var t, c;
115
+ try {
116
+ const { data: e } = await i.get(
117
+ d.ROUND_TRIP_FARES,
118
+ {
119
+ params: {
120
+ outbound_offer_id: s.outboundOfferId,
121
+ outbound_offer_request_id: s.outboundOfferRequestId,
122
+ inbound_offer_id: s.inboundOfferId
123
+ }
124
+ }
125
+ );
126
+ if (!e.success) throw e;
127
+ return e;
128
+ } catch (e) {
129
+ return console.error(JSON.stringify(e)), {
130
+ success: !1,
131
+ message: ((c = (t = e == null ? void 0 : e.response) == null ? void 0 : t.data) == null ? void 0 : c.message) || (e == null ? void 0 : e.message)
107
132
  };
108
133
  }
109
134
  });
110
135
  }
111
136
  }
112
- const C = new g();
137
+ const O = new l();
113
138
  export {
114
- C as FlightService
139
+ O as FlightService
115
140
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"