@odynn/awayz-flights 0.1.12 → 0.1.14

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,142 @@
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 "react";
6
+ import { EFlightEndpoint as d } from "./constants/endpoints.js";
7
+ import { clientInstance as i } from "@odynn/awayz-auth";
8
+ function _(a) {
9
+ return a = a.replace(/^_+/, ""), a.replace(/_([a-z])/g, (s, t) => t.toUpperCase());
10
+ }
11
+ const r = (a) => Array.isArray(a) ? a.map((s) => r(s)) : typeof a == "object" && a !== null ? Object.keys(a).reduce((s, t) => {
12
+ const c = _(t);
13
+ return s[c] = r(a[t]), s;
14
+ }, {}) : a;
15
+ class l {
16
+ constructor() {
17
+ u(this, "getAirports", async (s) => {
18
+ try {
19
+ const { data: t } = await i.get(
20
+ `${d.GET_AIRPORTS}?search_term=${s}`
21
+ );
22
+ return t.data.map((e) => {
23
+ var o;
24
+ return {
25
+ city: {
26
+ name: e.city_name,
27
+ code: e.iata_city_code
28
+ },
29
+ coordinates: {
30
+ latitude: e.latitude,
31
+ longitude: e.longitude
32
+ },
33
+ country: {
34
+ code: e.iata_country_code,
35
+ name: (o = e.country) == null ? void 0 : o.name
36
+ },
37
+ name: e.name,
38
+ iataCode: e.iata_code,
39
+ id: e.id,
40
+ type: e.type,
41
+ label: `${e.iata_code} - ${e.name}`
42
+ };
43
+ });
44
+ } catch {
45
+ return [];
46
+ }
47
+ });
48
+ u(this, "cashOnlySearch", async (s) => {
49
+ var t, c, e, o;
50
+ try {
51
+ const { data: n } = await i.post(
52
+ d.CASH_FLIGHT_SEARCH,
53
+ s
54
+ );
55
+ return n.success ? {
56
+ success: !0,
57
+ data: r(
58
+ n.data.offers
59
+ )
60
+ } : {
61
+ success: !1,
62
+ message: n.message
63
+ };
64
+ } catch (n) {
65
+ return console.error(JSON.stringify(n)), n.message === "canceled" ? {
66
+ success: !1,
67
+ 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)
68
+ } : {
69
+ success: !1,
70
+ 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)
71
+ };
72
+ }
73
+ });
74
+ u(this, "roundTripOutboundSearch", async (s) => {
75
+ var t, c;
76
+ try {
77
+ const { data: e } = await i.post(
78
+ d.CASH_OUTBOUND_SEARCH,
79
+ { ...s, to: s.return_date, from: s.departure_date }
80
+ );
81
+ if (!e.success) throw e;
82
+ return {
83
+ success: e.success,
84
+ data: r(e.data)
85
+ };
86
+ } catch (e) {
87
+ return {
88
+ success: !1,
89
+ 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)
90
+ };
91
+ }
92
+ });
93
+ u(this, "roundTripInboundSearch", async (s) => {
94
+ var t, c;
95
+ try {
96
+ const { data: e } = await i.get(
97
+ d.CASH_INBOUND_SEARCH,
98
+ {
99
+ params: {
100
+ outbound_offer_id: s.outboundOfferId,
101
+ outbound_offer_request_id: s.outboundOfferRequestId
102
+ }
103
+ }
104
+ );
105
+ if (!e.success) throw e;
106
+ return r(e);
107
+ } catch (e) {
108
+ return {
109
+ success: !1,
110
+ 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)
111
+ };
112
+ }
113
+ });
114
+ u(this, "getRoundTripFares", async (s) => {
115
+ var t, c;
116
+ try {
117
+ const { data: e } = await i.get(
118
+ d.ROUND_TRIP_FARES,
119
+ {
120
+ params: {
121
+ outbound_offer_id: s.outboundOfferId,
122
+ outbound_offer_request_id: s.outboundOfferRequestId,
123
+ inbound_offer_id: s.inboundOfferId
124
+ }
125
+ }
126
+ );
127
+ if (!e.success) throw e;
128
+ return e;
129
+ } catch (e) {
130
+ return console.error(JSON.stringify(e)), {
131
+ success: !1,
132
+ 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)
133
+ };
134
+ }
135
+ });
136
+ }
137
+ }
138
+ const R = new l();
139
+ export {
140
+ R as F,
141
+ r as c
142
+ };
@@ -1,17 +1,29 @@
1
- import { useQuery as t } from "@tanstack/react-query";
2
- import { FlightService as a } from "../../services/flights/FlightsService.js";
3
- const s = (r) => {
4
- const { data: o, isLoading: e, error: i } = t({
5
- queryKey: ["airports", r],
6
- queryFn: () => a.getAirports(r),
7
- enabled: !!r && r.length > 2
1
+ import { useQuery as i } from "@tanstack/react-query";
2
+ import { F as n } from "../../FlightsService-DddArKLm.js";
3
+ import "../../arrayExtensions-DWKenJCh.js";
4
+ import { useState as a, useEffect as m } from "react";
5
+ const c = 500, u = (t, e = c) => {
6
+ const [r, o] = a(t);
7
+ return m(() => {
8
+ const s = setTimeout(() => {
9
+ o(t);
10
+ }, e);
11
+ return () => {
12
+ clearTimeout(s);
13
+ };
14
+ }, [t, e]), r;
15
+ }, E = (t) => {
16
+ const e = u(t), { data: r, isLoading: o, error: s } = i({
17
+ queryKey: ["airports", e],
18
+ queryFn: () => n.getAirports(t),
19
+ enabled: !!t && t.length > 2
8
20
  });
9
21
  return {
10
- airports: o ?? [],
11
- loading: e,
12
- error: i
22
+ airports: r ?? [],
23
+ loading: o,
24
+ error: s
13
25
  };
14
26
  };
15
27
  export {
16
- s as useAirportSearch
28
+ E as useAirportSearch
17
29
  };
@@ -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-DddArKLm.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,9 @@ 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
+ if (!s) return;
112
+ const e = o.offers;
113
+ m(D(e));
111
114
  },
112
115
  onError: (r) => {
113
116
  console.error("Error in round-trip fare search:", r);
@@ -115,7 +118,7 @@ const N = 1, P = D.ECONOMY, A = (t) => {
115
118
  });
116
119
  return {
117
120
  loading: E === "pending" || I === "pending",
118
- loadingFares: T === "pending",
121
+ loadingFares: q === "pending",
119
122
  outboundError: F,
120
123
  inboundError: S,
121
124
  roundTripFaresError: y,
@@ -124,11 +127,11 @@ const N = 1, P = D.ECONOMY, A = (t) => {
124
127
  inboundResults: b,
125
128
  roundTripFares: g,
126
129
  // Mutation triggers
127
- searchOutboundFlights: m,
130
+ searchOutboundFlights: O,
128
131
  searchInboundFlights: w,
129
- getRoundTripFares: q
132
+ getRoundTripFares: T
130
133
  };
131
134
  };
132
135
  export {
133
- j as useFlightSearch
136
+ z as useFlightSearch
134
137
  };
@@ -1,140 +1,8 @@
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 e } from "../../FlightsService-DddArKLm.js";
3
+ import "react";
4
+ import "../../constants/endpoints.js";
5
+ import "@odynn/awayz-auth";
138
6
  export {
139
- O as FlightService
7
+ e as FlightService
140
8
  };
@@ -1,5 +1,6 @@
1
1
  import { h as F } from "../arrayExtensions-DWKenJCh.js";
2
2
  import { c as z } from "../dateUtils-DeNLG5hw.js";
3
+ import "react";
3
4
  const L = (r) => r == null ? void 0 : r.map((e) => {
4
5
  var c, a, t, o, i, s, l, h, g, I, T, f, M, w, b, d, p, n, y, C, N, m, u, D;
5
6
  return {
@@ -45,7 +46,7 @@ const L = (r) => r == null ? void 0 : r.map((e) => {
45
46
  duration: e.slices[0].duration
46
47
  })
47
48
  };
48
- }), O = (r, e) => {
49
+ }), P = (r, e) => {
49
50
  if (!(e != null && e.length))
50
51
  return L(r);
51
52
  const c = [...e];
@@ -103,7 +104,7 @@ const L = (r) => r == null ? void 0 : r.map((e) => {
103
104
  }, A = (r) => {
104
105
  const e = r.operatingCarrierFlightNumber ? r.operatingCarrier : r.marketingCarrier, c = r.operatingCarrierFlightNumber ?? r.marketingCarrierFlightNumber;
105
106
  return e.iataCode + " " + c;
106
- }, P = ({
107
+ }, $ = ({
107
108
  originCode: r,
108
109
  destinationCode: e,
109
110
  departureDate: c,
@@ -113,7 +114,7 @@ const L = (r) => r == null ? void 0 : r.map((e) => {
113
114
  }) => {
114
115
  let i = "/flights/search/one-way/points-cash?";
115
116
  return i += `origin=${r}`, i += `&destination=${e}`, i += `&departure_date=${c}`, i += `&cabin_class=${a}`, i += `&adults=${t}`, i += `&cash_or_points=[${o}]`, i;
116
- }, $ = (r) => {
117
+ }, Z = (r) => {
117
118
  const e = r.reduce((a, t) => {
118
119
  const o = t.awayzGroupId;
119
120
  return a[o] || (a[o] = []), a[o].push(t), a;
@@ -184,9 +185,9 @@ const L = (r) => r == null ? void 0 : r.map((e) => {
184
185
  );
185
186
  };
186
187
  export {
187
- P as buildFlightSearchQuery,
188
+ $ as buildFlightSearchQuery,
188
189
  A as getFlightNumber,
189
- $ as groupFlightResults,
190
+ Z as groupFlightResults,
190
191
  L as mapFlightDetailsToResults,
191
- O as parseFlightDetails
192
+ P as parseFlightDetails
192
193
  };
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.14",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -67,7 +67,7 @@
67
67
  },
68
68
  "dependencies": {
69
69
  "@microsoft/fetch-event-source": "^2.0.1",
70
- "@odynn/awayz-auth": "^0.1.8",
70
+ "@odynn/awayz-auth": "^0.1.17",
71
71
  "@tanstack/react-query": "^5.67.1"
72
72
  }
73
73
  }