@odynn/awayz-flights 0.1.12 → 0.1.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.
@@ -0,0 +1,141 @@
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
+ import "./arrayExtensions-DWKenJCh.js";
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
+ }
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
+ constructor() {
16
+ u(this, "getAirports", async (s) => {
17
+ try {
18
+ const { data: t } = await i.get(
19
+ `${d.GET_AIRPORTS}?search_term=${s}`
20
+ );
21
+ return t.data.map((e) => {
22
+ var o;
23
+ return {
24
+ city: {
25
+ name: e.city_name,
26
+ code: e.iata_city_code
27
+ },
28
+ coordinates: {
29
+ latitude: e.latitude,
30
+ longitude: e.longitude
31
+ },
32
+ country: {
33
+ code: e.iata_country_code,
34
+ name: (o = e.country) == null ? void 0 : o.name
35
+ },
36
+ name: e.name,
37
+ iataCode: e.iata_code,
38
+ id: e.id,
39
+ type: e.type,
40
+ label: `${e.iata_code} - ${e.name}`
41
+ };
42
+ });
43
+ } catch {
44
+ return [];
45
+ }
46
+ });
47
+ u(this, "cashOnlySearch", async (s) => {
48
+ var t, c, e, o;
49
+ try {
50
+ const { data: n } = await i.post(
51
+ d.CASH_FLIGHT_SEARCH,
52
+ s
53
+ );
54
+ return n.success ? {
55
+ success: !0,
56
+ data: r(
57
+ n.data.offers
58
+ )
59
+ } : {
60
+ success: !1,
61
+ message: n.message
62
+ };
63
+ } catch (n) {
64
+ return console.error(JSON.stringify(n)), n.message === "canceled" ? {
65
+ success: !1,
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
+ } : {
68
+ success: !1,
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
+ };
71
+ }
72
+ });
73
+ u(this, "roundTripOutboundSearch", async (s) => {
74
+ var t, c;
75
+ try {
76
+ const { data: e } = await i.post(
77
+ d.CASH_OUTBOUND_SEARCH,
78
+ { ...s, to: s.return_date, from: s.departure_date }
79
+ );
80
+ if (!e.success) throw e;
81
+ return {
82
+ success: e.success,
83
+ data: r(e.data)
84
+ };
85
+ } catch (e) {
86
+ return {
87
+ success: !1,
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
+ };
90
+ }
91
+ });
92
+ u(this, "roundTripInboundSearch", async (s) => {
93
+ var t, c;
94
+ try {
95
+ const { data: e } = await i.get(
96
+ d.CASH_INBOUND_SEARCH,
97
+ {
98
+ params: {
99
+ outbound_offer_id: s.outboundOfferId,
100
+ outbound_offer_request_id: s.outboundOfferRequestId
101
+ }
102
+ }
103
+ );
104
+ if (!e.success) throw e;
105
+ return r(e);
106
+ } catch (e) {
107
+ return {
108
+ success: !1,
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)
132
+ };
133
+ }
134
+ });
135
+ }
136
+ }
137
+ const O = new l();
138
+ export {
139
+ O as F,
140
+ r as c
141
+ };
@@ -1,6 +1,6 @@
1
1
  import { useQuery as t } from "@tanstack/react-query";
2
- import { FlightService as a } from "../../services/flights/FlightsService.js";
3
- const s = (r) => {
2
+ import { F as a } from "../../FlightsService-DDCgYDB9.js";
3
+ const n = (r) => {
4
4
  const { data: o, isLoading: e, error: i } = t({
5
5
  queryKey: ["airports", r],
6
6
  queryFn: () => a.getAirports(r),
@@ -13,5 +13,5 @@ const s = (r) => {
13
13
  };
14
14
  };
15
15
  export {
16
- s as useAirportSearch
16
+ n as useAirportSearch
17
17
  };
@@ -1,41 +1,42 @@
1
1
  import { useState as n } from "react";
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) => {
2
+ import { useMutation as u } from "@tanstack/react-query";
3
+ import { ECabinClass as C, EFlightType as d } from "../../types/enums.js";
4
+ import { F as a, c as D } from "../../FlightsService-DDCgYDB9.js";
5
+ import { parseFlightDetails as _, groupFlightResults as N } from "../../utils/flightUtils.js";
6
+ import "../../arrayExtensions-DWKenJCh.js";
7
+ const P = 1, v = C.ECONOMY, A = (t) => {
7
8
  if (!t.origin || !t.destination)
8
9
  throw new Error("Origin and destination are required.");
9
10
  if (!t.departureDate)
10
11
  throw new Error("Departure date is required.");
11
12
  if (t.flightType === d.ROUND_TRIP && !t.returnDate)
12
13
  throw new Error("Return date is required for round-trip flights.");
13
- }, j = () => {
14
- const [t, c] = n(""), [f, l] = n(""), [p, h] = n([]), [b, R] = n([]), [g, O] = n([]), i = ({
14
+ }, z = () => {
15
+ const [t, c] = n(""), [f, l] = n(""), [p, h] = n([]), [b, R] = n([]), [g, m] = n([]), i = ({
15
16
  data: r,
16
17
  previousResults: s,
17
18
  inbound: o
18
19
  }) => {
19
- const e = C(r, s);
20
- return (o ? R : h)(_(e)), e;
20
+ const e = _(r, s);
21
+ return (o ? R : h)(N(e)), e;
21
22
  }, {
22
- mutate: m,
23
+ mutate: O,
23
24
  status: E,
24
25
  error: F
25
- } = a({
26
+ } = u({
26
27
  mutationFn: async (r) => {
27
28
  A(r);
28
29
  const o = {
29
30
  passengers: Array.from(
30
- { length: r.passengers ?? N },
31
+ { length: r.passengers ?? P },
31
32
  () => ({ type: "adult" })
32
33
  ),
33
34
  origin: r.origin || "",
34
35
  destination: r.destination || "",
35
- cabin_class: r.cabinClass || P
36
+ cabin_class: r.cabinClass || v
36
37
  };
37
38
  if (r.flightType === d.ONE_WAY) {
38
- const e = await u.cashOnlySearch({
39
+ const e = await a.cashOnlySearch({
39
40
  ...o,
40
41
  departure_date: r.departureDate
41
42
  });
@@ -44,7 +45,7 @@ const N = 1, P = D.ECONOMY, A = (t) => {
44
45
  data: e.data
45
46
  };
46
47
  } else {
47
- const e = await u.roundTripOutboundSearch({
48
+ const e = await a.roundTripOutboundSearch({
48
49
  ...o,
49
50
  departure_date: r.departureDate,
50
51
  return_date: r.returnDate
@@ -72,11 +73,11 @@ const N = 1, P = D.ECONOMY, A = (t) => {
72
73
  mutate: w,
73
74
  status: I,
74
75
  error: S
75
- } = a({
76
+ } = u({
76
77
  mutationFn: async (r) => {
77
78
  if (!t)
78
79
  throw new Error("No partialOfferRequestId found for inbound search.");
79
- return l(r), await u.roundTripInboundSearch({
80
+ return l(r), await a.roundTripInboundSearch({
80
81
  outboundOfferId: r,
81
82
  outboundOfferRequestId: t
82
83
  });
@@ -92,14 +93,14 @@ const N = 1, P = D.ECONOMY, A = (t) => {
92
93
  console.error("Error in inbound flight search:", r);
93
94
  }
94
95
  }), {
95
- mutate: q,
96
- status: T,
96
+ mutate: T,
97
+ status: q,
97
98
  error: y
98
- } = a({
99
+ } = u({
99
100
  mutationFn: async (r) => {
100
101
  if (!t)
101
102
  throw new Error("No partialOfferRequestId found for round-trip fares.");
102
- return await u.getRoundTripFares({
103
+ return await a.getRoundTripFares({
103
104
  outboundOfferId: f,
104
105
  outboundOfferRequestId: t,
105
106
  inboundOfferId: r
@@ -107,7 +108,7 @@ const N = 1, P = D.ECONOMY, A = (t) => {
107
108
  },
108
109
  onSuccess: (r) => {
109
110
  const { success: s, data: o } = r;
110
- s && O(o.offers);
111
+ s && m(D(o.offers));
111
112
  },
112
113
  onError: (r) => {
113
114
  console.error("Error in round-trip fare search:", r);
@@ -115,7 +116,7 @@ const N = 1, P = D.ECONOMY, A = (t) => {
115
116
  });
116
117
  return {
117
118
  loading: E === "pending" || I === "pending",
118
- loadingFares: T === "pending",
119
+ loadingFares: q === "pending",
119
120
  outboundError: F,
120
121
  inboundError: S,
121
122
  roundTripFaresError: y,
@@ -124,11 +125,11 @@ const N = 1, P = D.ECONOMY, A = (t) => {
124
125
  inboundResults: b,
125
126
  roundTripFares: g,
126
127
  // Mutation triggers
127
- searchOutboundFlights: m,
128
+ searchOutboundFlights: O,
128
129
  searchInboundFlights: w,
129
- getRoundTripFares: q
130
+ getRoundTripFares: T
130
131
  };
131
132
  };
132
133
  export {
133
- j as useFlightSearch
134
+ z as useFlightSearch
134
135
  };
@@ -1,140 +1,7 @@
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
1
  import "../../arrayExtensions-DWKenJCh.js";
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
- }
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
- constructor() {
16
- u(this, "getAirports", async (s) => {
17
- try {
18
- const { data: t } = await i.get(
19
- `${d.GET_AIRPORTS}?search_term=${s}`
20
- );
21
- return t.data.map((e) => {
22
- var o;
23
- return {
24
- city: {
25
- name: e.city_name,
26
- code: e.iata_city_code
27
- },
28
- coordinates: {
29
- latitude: e.latitude,
30
- longitude: e.longitude
31
- },
32
- country: {
33
- code: e.iata_country_code,
34
- name: (o = e.country) == null ? void 0 : o.name
35
- },
36
- name: e.name,
37
- iataCode: e.iata_code,
38
- id: e.id,
39
- type: e.type,
40
- label: `${e.iata_code} - ${e.name}`
41
- };
42
- });
43
- } catch {
44
- return [];
45
- }
46
- });
47
- u(this, "cashOnlySearch", async (s) => {
48
- var t, c, e, o;
49
- try {
50
- const { data: n } = await i.post(
51
- d.CASH_FLIGHT_SEARCH,
52
- s
53
- );
54
- return n.success ? {
55
- success: !0,
56
- data: r(
57
- n.data.offers
58
- )
59
- } : {
60
- success: !1,
61
- message: n.message
62
- };
63
- } catch (n) {
64
- return console.error(JSON.stringify(n)), n.message === "canceled" ? {
65
- success: !1,
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
- } : {
68
- success: !1,
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
- };
71
- }
72
- });
73
- u(this, "roundTripOutboundSearch", async (s) => {
74
- var t, c;
75
- try {
76
- const { data: e } = await i.post(
77
- d.CASH_OUTBOUND_SEARCH,
78
- { ...s, to: s.return_date, from: s.departure_date }
79
- );
80
- if (!e.success) throw e;
81
- return {
82
- success: e.success,
83
- data: r(e.data)
84
- };
85
- } catch (e) {
86
- return {
87
- success: !1,
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
- };
90
- }
91
- });
92
- u(this, "roundTripInboundSearch", async (s) => {
93
- var t, c;
94
- try {
95
- const { data: e } = await i.get(
96
- d.CASH_INBOUND_SEARCH,
97
- {
98
- params: {
99
- outbound_offer_id: s.outboundOfferId,
100
- outbound_offer_request_id: s.outboundOfferRequestId
101
- }
102
- }
103
- );
104
- if (!e.success) throw e;
105
- return r(e);
106
- } catch (e) {
107
- return {
108
- success: !1,
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)
132
- };
133
- }
134
- });
135
- }
136
- }
137
- const O = new l();
2
+ import { F as p } from "../../FlightsService-DDCgYDB9.js";
3
+ import "../../constants/endpoints.js";
4
+ import "@odynn/awayz-auth";
138
5
  export {
139
- O as FlightService
6
+ p as FlightService
140
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"