@odynn/awayz-flights 0.2.1 → 0.2.2

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,48 +1,42 @@
1
1
  import { jsx as r, jsxs as e } from "react/jsx-runtime";
2
2
  import k, { useState as d, useMemo as E } from "react";
3
- import { g as f, E as N, F as I, a as M } from "../../FlightItinerary-DgpK1LYF.js";
4
- import { DEFAULT_AIRLINE_PROGRAM as R, getFlightNumber as T, getLogoPath as B, getAirlineProgram as L } from "../../utils/flightUtils.js";
3
+ import { g as f, E as N, F as I, a as R } from "../../FlightItinerary-DgpK1LYF.js";
4
+ import { DEFAULT_AIRLINE_PROGRAM as T, getFlightNumber as B, getLogoPath as L, getAirlineProgram as $ } from "../../utils/flightUtils.js";
5
5
  import { h as u } from "../../arrayExtensions-DWKenJCh.js";
6
- import { g as $ } from "../../dateUtils-DeNLG5hw.js";
6
+ import { g as x } from "../../dateUtils-DeNLG5hw.js";
7
7
  import { EPaymentType as v } from "../../enums/EPaymentType.js";
8
+ import { CashValue as M } from "@odynn/awayz-core";
8
9
  import '../../assets/FlightResult.css';function b(i) {
9
10
  if (!i || isNaN(i) || i < 0) return "N/A";
10
11
  let n = i == null ? void 0 : i.toString().split(".")[0];
11
12
  return n == null ? void 0 : n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
12
13
  }
13
- const x = (i, n) => {
14
- if (i <= 0) return "N/A";
15
- var s = new Intl.NumberFormat("en-US", {
16
- style: "currency",
17
- currency: n
18
- });
19
- return i ? s.format(Math.round(i)).toString().split(".")[0] : s.format(0);
20
- }, z = ({ details: i, onClick: n }) => {
21
- const [s, y] = d(!1), o = i.origin, c = i.destination, g = i.flightDetails, D = !i.paymentOptions || i.paymentOptions.length === 1, [S, F] = d(R), C = async () => {
22
- const t = await L(i.airlineProgram);
23
- F(t);
24
- }, { flightNumbers: h, airlines: P } = E(() => {
25
- const t = [], a = [];
14
+ const z = ({ details: i, onClick: n }) => {
15
+ const [m, y] = d(!1), l = i.origin, o = i.destination, g = i.flightDetails, C = !i.paymentOptions || i.paymentOptions.length === 1, [D, F] = d(T), S = async () => {
16
+ const a = await $(i.airlineProgram);
17
+ F(a);
18
+ }, { flightNumbers: c, airlines: P } = E(() => {
19
+ const a = [], t = [];
26
20
  return i.flightDetails.slices.forEach((A) => {
27
- A.segments.forEach((l) => {
28
- const p = T(l);
29
- t.includes(p) || t.push(p);
30
- const m = l.operatingCarrierFlightNumber ? l.operatingCarrier : l.marketingCarrier;
31
- a.some((O) => O.airline === m.name) || a.push({
32
- logo: B(m.iataCode),
33
- airline: m.name
21
+ A.segments.forEach((s) => {
22
+ const p = B(s);
23
+ a.includes(p) || a.push(p);
24
+ const h = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier;
25
+ t.some((O) => O.airline === h.name) || t.push({
26
+ logo: L(h.iataCode),
27
+ airline: h.name
34
28
  });
35
29
  });
36
- }), C(), { flightNumbers: t, airlines: a };
30
+ }), S(), { flightNumbers: a, airlines: t };
37
31
  }, [i.flightDetails.slices]);
38
32
  return /* @__PURE__ */ r("div", { className: "flight-result", onClick: () => n(i), children: /* @__PURE__ */ e("div", { className: "content", children: [
39
33
  /* @__PURE__ */ r("div", { className: "flight-info", children: /* @__PURE__ */ e("div", { className: "flight-locations", children: [
40
- /* @__PURE__ */ r("div", { className: "airlines", children: P.map((t, a) => /* @__PURE__ */ r(k.Fragment, { children: /* @__PURE__ */ r("div", { className: "tip", children: /* @__PURE__ */ r("img", { src: t.logo, alt: t.airline }) }, a) }, a)) }),
34
+ /* @__PURE__ */ r("div", { className: "airlines", children: P.map((a, t) => /* @__PURE__ */ r(k.Fragment, { children: /* @__PURE__ */ r("div", { className: "tip", children: /* @__PURE__ */ r("img", { src: a.logo, alt: a.airline }) }, t) }, t)) }),
41
35
  /* @__PURE__ */ e("div", { className: "flight-location", children: [
42
36
  /* @__PURE__ */ e("p", { children: [
43
- o.city,
37
+ l.city,
44
38
  ",",
45
- f(o.country)
39
+ f(l.country)
46
40
  ] }),
47
41
  /* @__PURE__ */ r("p", { children: u(i.departureTime).format(
48
42
  // isMobile
@@ -54,7 +48,7 @@ const x = (i, n) => {
54
48
  /* @__PURE__ */ e("div", { className: "flight-duration", children: [
55
49
  /* @__PURE__ */ r("span", { className: "line" }),
56
50
  /* @__PURE__ */ e("p", { children: [
57
- $(g.slices[0].duration),
51
+ x(g.slices[0].duration),
58
52
  " ",
59
53
  " - ",
60
54
  i.numberOfStops > 0 ? `${i.numberOfStops} Stop${i.numberOfStops > 1 ? "s" : ""}` : "Direct"
@@ -63,9 +57,9 @@ const x = (i, n) => {
63
57
  ] }),
64
58
  /* @__PURE__ */ e("div", { children: [
65
59
  /* @__PURE__ */ e("p", { children: [
66
- c.city,
60
+ o.city,
67
61
  ", ",
68
- f(c.country)
62
+ f(o.country)
69
63
  ] }),
70
64
  /* @__PURE__ */ e("p", { children: [
71
65
  u(i.arrivalTime).format(
@@ -84,18 +78,18 @@ const x = (i, n) => {
84
78
  "div",
85
79
  {
86
80
  className: "flight-detail",
87
- onClick: (t) => {
88
- t.stopPropagation(), y(!s);
81
+ onClick: (a) => {
82
+ a.stopPropagation(), y(!m);
89
83
  },
90
84
  children: [
91
85
  /* @__PURE__ */ r("p", { children: "Aircraft" }),
92
86
  /* @__PURE__ */ e("p", { className: "chevron-text", children: [
93
87
  /* @__PURE__ */ r(I, {}),
94
88
  /* @__PURE__ */ e("span", { children: [
95
- h[0],
96
- h.length > 1 && /* @__PURE__ */ e("sup", { children: [
89
+ c[0],
90
+ c.length > 1 && /* @__PURE__ */ e("sup", { children: [
97
91
  "+",
98
- h.length - 1
92
+ c.length - 1
99
93
  ] })
100
94
  ] })
101
95
  ] })
@@ -117,12 +111,18 @@ const x = (i, n) => {
117
111
  "div",
118
112
  {
119
113
  className: "cash-value",
120
- onClick: (t) => {
121
- t.stopPropagation(), n(i, v.CASH);
114
+ onClick: (a) => {
115
+ a.stopPropagation(), n(i, v.CASH);
122
116
  },
123
117
  children: [
124
- /* @__PURE__ */ r("p", { children: D ? "Book For" : "From" }),
125
- /* @__PURE__ */ r("p", { children: x(i.cash, "USD") })
118
+ /* @__PURE__ */ r("p", { children: C ? "Book For" : "From" }),
119
+ /* @__PURE__ */ r("p", { children: /* @__PURE__ */ r(
120
+ M,
121
+ {
122
+ amount: i.cash,
123
+ currency: i.currency
124
+ }
125
+ ) })
126
126
  ]
127
127
  }
128
128
  ),
@@ -130,23 +130,23 @@ const x = (i, n) => {
130
130
  "div",
131
131
  {
132
132
  className: "points-value",
133
- onClick: (t) => {
134
- t.stopPropagation(), n(i, v.POINTS);
133
+ onClick: (a) => {
134
+ a.stopPropagation(), n(i, v.POINTS);
135
135
  },
136
136
  children: [
137
- /* @__PURE__ */ r("img", { src: S.programLogo }),
137
+ /* @__PURE__ */ r("img", { src: D.programLogo }),
138
138
  /* @__PURE__ */ r("p", { children: `${b(i.points)} miles` })
139
139
  ]
140
140
  }
141
141
  )
142
142
  ] })
143
143
  ] }),
144
- /* @__PURE__ */ r("div", { className: `flight-details ${s ? "is-open" : ""}`, children: /* @__PURE__ */ r("div", { className: "inner", children: /* @__PURE__ */ r(
145
- M,
144
+ /* @__PURE__ */ r("div", { className: `flight-details ${m ? "is-open" : ""}`, children: /* @__PURE__ */ r("div", { className: "inner", children: /* @__PURE__ */ r(
145
+ R,
146
146
  {
147
147
  itinerary: g.slices[0].segments,
148
- origin: o,
149
- destination: c
148
+ origin: l,
149
+ destination: o
150
150
  }
151
151
  ) }) })
152
152
  ] }) });
@@ -79,6 +79,7 @@ export interface IFlightPaymentOption {
79
79
  cashFeeAmount: number;
80
80
  baseCurrency: string;
81
81
  fareBrandName: string;
82
+ program: string;
82
83
  baggages?: {
83
84
  type: EBaggage | null;
84
85
  quantity: number;
@@ -110,6 +111,7 @@ export interface IFlightResult {
110
111
  durationMinutes: number;
111
112
  flightDetails: IFlightOffer;
112
113
  paymentOptions: IFlightPaymentOption[];
114
+ currency: string;
113
115
  }
114
116
  export interface IAirportLocation {
115
117
  city: string;
@@ -1,39 +1,40 @@
1
- import { h as f } from "../arrayExtensions-DWKenJCh.js";
2
- import { c as R } from "../dateUtils-DeNLG5hw.js";
1
+ import { h as A } from "../arrayExtensions-DWKenJCh.js";
2
+ import { c as K } from "../dateUtils-DeNLG5hw.js";
3
3
  import "react";
4
- import { awayzClient as K } from "@odynn/awayz-core";
5
- import { WalletService as j } from "../services/wallet/WalletService.js";
6
- import { ERewardProgramCategories as q } from "../services/wallet/WalletService.types.js";
7
- const B = (i) => i == null ? void 0 : i.map((e) => {
8
- var c, a, s, n, t, o, g, r, d, A, M, I, F, L, w, u, y, l, C, h, b, m, p, D, T, k, z, v, O, G, _, $, Z, P;
4
+ import { awayzClient as q } from "@odynn/awayz-core";
5
+ import { WalletService as Q } from "../services/wallet/WalletService.js";
6
+ import { ERewardProgramCategories as V } from "../services/wallet/WalletService.types.js";
7
+ const B = (s) => s == null ? void 0 : s.map((e) => {
8
+ var r, t, a, n, i, o, m, h, g, M, P, N, L, F, w, d, p, c, y, C, b, l, u, D, k, O, f, z, v, _, $, Z, E, G;
9
9
  return {
10
10
  id: e.id,
11
11
  points: (e == null ? void 0 : e.points) >= 0 ? e.points : -1,
12
12
  partial: e == null ? void 0 : e.partial,
13
13
  origin: {
14
- city: ((c = e.slices[0].segments[0].origin) == null ? void 0 : c.cityName) || ((s = (a = e.slices[0].segments[0].origin) == null ? void 0 : a.city) == null ? void 0 : s.name),
15
- country: ((n = e.slices[0].segments[0].origin) == null ? void 0 : n.iataCountryCode) || ((o = (t = e.slices[0].segments[0].origin) == null ? void 0 : t.city) == null ? void 0 : o.iataCountryCode),
16
- airportCode: ((g = e.slices[0].segments[0].origin) == null ? void 0 : g.iataCityCode) || ((d = (r = e.slices[0].segments[0].origin) == null ? void 0 : r.city) == null ? void 0 : d.iataCode),
14
+ city: ((r = e.slices[0].segments[0].origin) == null ? void 0 : r.cityName) || ((a = (t = e.slices[0].segments[0].origin) == null ? void 0 : t.city) == null ? void 0 : a.name),
15
+ country: ((n = e.slices[0].segments[0].origin) == null ? void 0 : n.iataCountryCode) || ((o = (i = e.slices[0].segments[0].origin) == null ? void 0 : i.city) == null ? void 0 : o.iataCountryCode),
16
+ airportCode: ((m = e.slices[0].segments[0].origin) == null ? void 0 : m.iataCityCode) || ((g = (h = e.slices[0].segments[0].origin) == null ? void 0 : h.city) == null ? void 0 : g.iataCode),
17
17
  coordinates: {
18
- latitude: (M = (A = e.slices[0].segments[0].origin) == null ? void 0 : A.city) == null ? void 0 : M.latitude,
19
- longitude: (F = (I = e.slices[0].segments[0].origin) == null ? void 0 : I.city) == null ? void 0 : F.longitude
18
+ latitude: (P = (M = e.slices[0].segments[0].origin) == null ? void 0 : M.city) == null ? void 0 : P.latitude,
19
+ longitude: (L = (N = e.slices[0].segments[0].origin) == null ? void 0 : N.city) == null ? void 0 : L.longitude
20
20
  }
21
21
  },
22
22
  destination: {
23
- city: ((w = (L = e.slices[0].segments.getLast()) == null ? void 0 : L.destination) == null ? void 0 : w.cityName) || ((l = (y = (u = e.slices[0].segments.getLast()) == null ? void 0 : u.destination) == null ? void 0 : y.city) == null ? void 0 : l.name),
24
- country: ((h = (C = e.slices[0].segments.getLast()) == null ? void 0 : C.destination) == null ? void 0 : h.iataCountryCode) || ((p = (m = (b = e.slices[0].segments.getLast()) == null ? void 0 : b.destination) == null ? void 0 : m.city) == null ? void 0 : p.iataCountryCode),
25
- airportCode: ((T = (D = e.slices[0].segments.getLast()) == null ? void 0 : D.destination) == null ? void 0 : T.iataCityCode) || ((v = (z = (k = e.slices[0].segments.getLast()) == null ? void 0 : k.destination) == null ? void 0 : z.city) == null ? void 0 : v.iataCode),
23
+ city: ((w = (F = e.slices[0].segments.getLast()) == null ? void 0 : F.destination) == null ? void 0 : w.cityName) || ((c = (p = (d = e.slices[0].segments.getLast()) == null ? void 0 : d.destination) == null ? void 0 : p.city) == null ? void 0 : c.name),
24
+ country: ((C = (y = e.slices[0].segments.getLast()) == null ? void 0 : y.destination) == null ? void 0 : C.iataCountryCode) || ((u = (l = (b = e.slices[0].segments.getLast()) == null ? void 0 : b.destination) == null ? void 0 : l.city) == null ? void 0 : u.iataCountryCode),
25
+ airportCode: ((k = (D = e.slices[0].segments.getLast()) == null ? void 0 : D.destination) == null ? void 0 : k.iataCityCode) || ((z = (f = (O = e.slices[0].segments.getLast()) == null ? void 0 : O.destination) == null ? void 0 : f.city) == null ? void 0 : z.iataCode),
26
26
  coordinates: {
27
- latitude: (_ = (G = (O = e.slices[0].segments.getLast()) == null ? void 0 : O.destination) == null ? void 0 : G.city) == null ? void 0 : _.latitude,
28
- longitude: (P = (Z = ($ = e.slices[0].segments.getLast()) == null ? void 0 : $.destination) == null ? void 0 : Z.city) == null ? void 0 : P.longitude
27
+ latitude: ($ = (_ = (v = e.slices[0].segments.getLast()) == null ? void 0 : v.destination) == null ? void 0 : _.city) == null ? void 0 : $.latitude,
28
+ longitude: (G = (E = (Z = e.slices[0].segments.getLast()) == null ? void 0 : Z.destination) == null ? void 0 : E.city) == null ? void 0 : G.longitude
29
29
  }
30
30
  },
31
31
  airline: e.owner.name,
32
32
  cash: parseFloat(e.totalAmount),
33
- flightNumber: U(e.slices[0].segments[0]),
33
+ currency: e.baseCurrency,
34
+ flightNumber: j(e.slices[0].segments[0]),
34
35
  awayzGroupId: e.slices[0].comparisonKey || e.awayzRouteId || e.awayzGroupId || e.id,
35
- departureTime: f(e.slices[0].segments[0].departingAt).toDate(),
36
- arrivalTime: f(
36
+ departureTime: A(e.slices[0].segments[0].departingAt).toDate(),
37
+ arrivalTime: A(
37
38
  e.slices[0].segments[e.slices[0].segments.length - 1].arrivingAt
38
39
  ).toDate(),
39
40
  numberOfStops: e.slices[0].segments.length - 1,
@@ -41,191 +42,228 @@ const B = (i) => i == null ? void 0 : i.map((e) => {
41
42
  duration: e.slices[0].duration,
42
43
  airlineProgram: e.airlineProgram,
43
44
  paymentOptions: [],
44
- durationMinutes: R({
45
- departureTime: f(e.slices[0].segments[0].departingAt),
46
- arrivalTime: f(e.slices[0].segments.getLast().arrivingAt),
45
+ durationMinutes: K({
46
+ departureTime: A(e.slices[0].segments[0].departingAt),
47
+ arrivalTime: A(e.slices[0].segments.getLast().arrivingAt),
47
48
  originTimeZone: e.slices[0].segments[0].origin.timeZone,
48
49
  destinationTimeZone: e.slices[0].segments.getLast().destination.timeZone,
49
50
  duration: e.slices[0].duration
50
51
  })
51
52
  };
52
- }), J = (i, e) => {
53
+ }), ee = (s, e) => {
53
54
  if (!(e != null && e.length))
54
- return B(i);
55
- const c = [...e], a = [], s = {};
56
- for (const t of i) {
57
- const o = t.slices[0].segments, g = o[0], r = {
58
- iataCode: g.operatingCarrier.iataCode,
59
- flightNumber: N(
60
- g.operatingCarrierFlightNumber
55
+ return B(s);
56
+ const r = [...e], t = [], a = {};
57
+ for (const i of s) {
58
+ const o = i.slices[0].segments, m = o[0], h = {
59
+ iataCode: m.operatingCarrier.iataCode,
60
+ flightNumber: T(
61
+ m.operatingCarrierFlightNumber
61
62
  )
62
- }, d = {
63
- iataCode: g.marketingCarrier.iataCode,
64
- flightNumber: N(
65
- g.marketingCarrierFlightNumber
63
+ }, g = {
64
+ iataCode: m.marketingCarrier.iataCode,
65
+ flightNumber: T(
66
+ m.marketingCarrierFlightNumber
66
67
  )
67
- }, A = t.awayzMatchId, M = `${r.iataCode}_${d.iataCode}-${d.flightNumber}`, I = t.awayzMarketerMatchId, F = !!r.flightNumber && r.flightNumber != "", L = !!d.flightNumber && d.flightNumber != "", w = c.filter((u, y) => {
68
- const l = u.flightDetails, C = u.flightDetails.slices[0].segments[0].operatingCarrierFlightNumber, h = l.id && // TODO: Maybe expand on this - Id check ensures it is a duffel flight
69
- !!C && C !== "";
70
- if (!(l.slices[0].segments.length === (o == null ? void 0 : o.length) && !l.slices[0].segments.find(
71
- (p, D) => p.departingAt !== o[D].departingAt || p.arrivingAt !== o[D].arrivingAt || p.duration !== o[D].duration
68
+ }, M = i.awayzMatchId, P = `${h.iataCode}_${g.iataCode}-${g.flightNumber}`, N = i.awayzMarketerMatchId, L = !!h.flightNumber && h.flightNumber != "", F = !!g.flightNumber && g.flightNumber != "", w = r.filter((d, p) => {
69
+ const c = d.flightDetails, y = d.flightDetails.slices[0].segments[0].operatingCarrierFlightNumber, C = c.id && // TODO: Maybe expand on this - Id check ensures it is a duffel flight
70
+ !!y && y !== "";
71
+ if (!(c.slices[0].segments.length === (o == null ? void 0 : o.length) && !c.slices[0].segments.find(
72
+ (u, D) => u.departingAt !== o[D].departingAt || u.arrivingAt !== o[D].arrivingAt || u.duration !== o[D].duration
72
73
  )))
73
74
  return !1;
74
- let m = !1;
75
- return (L && F && l.awayzMatchId === A || !h && l.awayzMatchId === M || F && !L && l.awayzMarketerMatchId === I) && (m = !0), m && (s[l.id] = y), m;
75
+ let l = !1;
76
+ return (F && L && c.awayzMatchId === M || !C && c.awayzMatchId === P || L && !F && c.awayzMarketerMatchId === N) && (l = !0), l && (a[c.id] = p), l;
76
77
  });
77
78
  if (w.length) {
78
- t.slices[0].comparisonKey = w[0].awayzGroupId;
79
- const u = w.find((y) => {
80
- var h, b, m, p;
81
- const l = (h = y.flightDetails.slices[0].fareBrandName) == null ? void 0 : h.toLowerCase(), C = (b = t.slices[0].fareBrandName) == null ? void 0 : b.toLowerCase();
82
- return C === l || // Special Case for AC Only match on first word
79
+ i.slices[0].comparisonKey = w[0].awayzGroupId;
80
+ const d = w.find((p) => {
81
+ var C, b, l, u;
82
+ const c = (C = p.flightDetails.slices[0].fareBrandName) == null ? void 0 : C.toLowerCase(), y = (b = i.slices[0].fareBrandName) == null ? void 0 : b.toLowerCase();
83
+ return y === c || // Special Case for AC Only match on first word
83
84
  // Due to differences in scraped points data and Duffel format
84
- d.iataCode === "AC" && ((m = C.split(" ")) == null ? void 0 : m[0]) === ((p = l.split(" ")) == null ? void 0 : p[0]);
85
+ g.iataCode === "AC" && ((l = y.split(" ")) == null ? void 0 : l[0]) === ((u = c.split(" ")) == null ? void 0 : u[0]);
85
86
  });
86
- if (u) {
87
- const y = s[u.id], l = {
88
- ...t,
89
- ...u,
90
- points: t.points,
91
- airlineProgram: t.airlineProgram,
87
+ if (d) {
88
+ const p = a[d.id], c = {
89
+ ...i,
90
+ ...d,
91
+ points: i.points,
92
+ airlineProgram: i.airlineProgram,
92
93
  flightDetails: {
93
- ...t,
94
- ...u.flightDetails,
95
- points: t.points,
96
- airlineProgram: t.airlineProgram
94
+ ...i,
95
+ ...d.flightDetails,
96
+ points: i.points,
97
+ airlineProgram: i.airlineProgram
97
98
  }
98
99
  };
99
- c[y] = l;
100
+ r[p] = c;
100
101
  } else
101
- a.push(t);
102
+ t.push(i);
102
103
  } else
103
- a.push(t);
104
+ t.push(i);
104
105
  }
105
106
  return [
106
- ...c,
107
- ...B(a) ?? []
107
+ ...r,
108
+ ...B(t) ?? []
108
109
  ];
109
- }, U = (i) => {
110
- const e = i.operatingCarrierFlightNumber ? i.operatingCarrier : i.marketingCarrier, c = i.operatingCarrierFlightNumber ?? i.marketingCarrierFlightNumber;
111
- return e.iataCode + " " + N(c);
112
- }, X = ({
113
- originCode: i,
110
+ }, j = (s) => {
111
+ const e = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier, r = s.operatingCarrierFlightNumber ?? s.marketingCarrierFlightNumber;
112
+ return e.iataCode + " " + T(r);
113
+ }, te = ({
114
+ originCode: s,
114
115
  destinationCode: e,
115
- departureDate: c,
116
- cabinClass: a,
117
- passengerCount: s,
116
+ departureDate: r,
117
+ cabinClass: t,
118
+ passengerCount: a,
118
119
  paymentType: n
119
120
  }) => {
120
- let t = "/flights/search/one-way/points-cash?";
121
- return t += `origin=${i}`, t += `&destination=${e}`, t += `&departure_date=${c}`, t += `&cabin_class=${a}`, t += `&adults=${s}`, t += `&cash_or_points=[${n}]`, t;
122
- }, ee = (i) => {
123
- const e = i.reduce((a, s) => {
124
- const n = s.flightDetails.slices[0].segments.map((t) => N(U(t))).join("_");
125
- return a[n] || (a[n] = []), a[n].push(s), a;
126
- }, {});
127
- return Object.values(e).map(
128
- (a) => {
129
- const s = a[0], { origin: n, destination: t } = s, o = a.filter((r) => r.cash > 0).reduce((r, d) => Math.min(r, d.cash), 1 / 0), g = a.filter((r) => r.points > 0).reduce((r, d) => Math.min(r, d.points), 1 / 0);
130
- return {
131
- id: s.awayzGroupId,
132
- partial: s.partial,
133
- origin: {
134
- city: n.city,
135
- country: n.country,
136
- airportCode: n.airportCode,
137
- coordinates: n.coordinates
138
- },
139
- destination: {
140
- city: t.city,
141
- country: t.country,
142
- airportCode: t.airportCode,
143
- coordinates: t.coordinates
144
- },
145
- airline: s.airline,
146
- flightNumber: s.flightNumber,
147
- paymentOptions: a.map((r) => ({
148
- id: r.id,
149
- cash: r.cash,
150
- points: r.points,
151
- cashFeeCurrency: r.flightDetails.baseCurrency,
152
- //TODO: Add Cash Fee Amount
153
- cashFeeAmount: 0,
154
- baseCurrency: r.flightDetails.baseCurrency,
155
- fareBrandName: r.flightDetails.slices[0].fareBrandName,
156
- conditions: {
157
- //TODO: Add Refund and Change Conditions
158
- refundBeforeDeparture: !0,
159
- changeBeforeDeparture: !0
121
+ let i = "/flights/search/one-way/points-cash?";
122
+ return i += `origin=${s}`, i += `&destination=${e}`, i += `&departure_date=${r}`, i += `&cabin_class=${t}`, i += `&adults=${a}`, i += `&cash_or_points=[${n}]`, i;
123
+ }, se = (s) => {
124
+ const e = {};
125
+ s.forEach((t) => {
126
+ const a = t.flightDetails.slices[0].segments.map((n) => j(n)).join("_");
127
+ if (e[a]) {
128
+ const n = U(t);
129
+ e[a].flight.paymentOptions.push(n);
130
+ const i = I(
131
+ e[a].flight.paymentOptions
132
+ );
133
+ e[a].flight.cash = i.lowestCash, e[a].flight.points = i.lowestPoints;
134
+ } else {
135
+ const { origin: n, destination: i } = t, o = [U(t)], m = I(o);
136
+ e[a] = {
137
+ programs: [],
138
+ flight: {
139
+ id: t.awayzGroupId,
140
+ partial: t.partial,
141
+ origin: {
142
+ city: n.city,
143
+ country: n.country,
144
+ airportCode: n.airportCode,
145
+ coordinates: n.coordinates
160
146
  },
161
- carrier: {
162
- iataCode: r.flightDetails.slices[0].segments[0].marketingCarrier.iataCode,
163
- name: r.flightDetails.slices[0].segments[0].marketingCarrier.name
164
- }
165
- })),
166
- numberOfStops: s.numberOfStops,
167
- departureTime: s.departureTime,
168
- arrivalTime: s.arrivalTime,
169
- awayzGroupId: s.awayzGroupId,
170
- duration: s.duration,
171
- airlineProgram: s.airlineProgram,
172
- durationMinutes: R({
173
- departureTime: f(
174
- s.flightDetails.slices[0].segments[0].departingAt
175
- ),
176
- arrivalTime: f(
177
- s.flightDetails.slices[0].segments.getLast().arrivingAt
178
- ),
179
- originTimeZone: s.flightDetails.slices[0].segments[0].origin.timeZone,
180
- destinationTimeZone: s.flightDetails.slices[0].segments.getLast().destination.timeZone,
181
- duration: s.flightDetails.slices[0].duration
182
- }),
183
- cash: o === 1 / 0 ? -1 : o,
184
- points: g === 1 / 0 ? -1 : g,
185
- flightDetails: s.flightDetails
147
+ destination: {
148
+ city: i.city,
149
+ country: i.country,
150
+ airportCode: i.airportCode,
151
+ coordinates: i.coordinates
152
+ },
153
+ airline: t.airline,
154
+ flightNumber: t.flightNumber,
155
+ paymentOptions: o,
156
+ numberOfStops: t.numberOfStops,
157
+ departureTime: t.departureTime,
158
+ arrivalTime: t.arrivalTime,
159
+ awayzGroupId: t.awayzGroupId,
160
+ duration: t.duration,
161
+ airlineProgram: t.airlineProgram,
162
+ durationMinutes: K({
163
+ departureTime: A(
164
+ t.flightDetails.slices[0].segments[0].departingAt
165
+ ),
166
+ arrivalTime: A(
167
+ t.flightDetails.slices[0].segments.getLast().arrivingAt
168
+ ),
169
+ originTimeZone: t.flightDetails.slices[0].segments[0].origin.timeZone,
170
+ destinationTimeZone: t.flightDetails.slices[0].segments.getLast().destination.timeZone,
171
+ duration: t.flightDetails.slices[0].duration
172
+ }),
173
+ cash: m.lowestCash,
174
+ points: m.lowestPoints,
175
+ flightDetails: t.flightDetails,
176
+ currency: t.flightDetails.baseCurrency
177
+ }
186
178
  };
187
179
  }
188
- );
189
- }, N = (i) => i ? i.replace(/^0+/, "") : "", te = (i) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${i}.svg`, S = "/img/logo/odynn-eye.svg", E = {
190
- categoryLogo: S,
191
- programLogo: S,
180
+ t.airlineProgram && !e[a].programs.includes(t.airlineProgram) && e[a].programs.push(t.airlineProgram);
181
+ });
182
+ const r = [];
183
+ return Object.values(e).forEach((t) => {
184
+ t.programs.length > 0 ? t.programs.forEach((a) => {
185
+ const n = I(
186
+ t.flight.paymentOptions.filter(
187
+ (i) => i.program === a || i.cash > 0
188
+ )
189
+ );
190
+ r.push({
191
+ ...t.flight,
192
+ airlineProgram: a,
193
+ cash: n.lowestCash,
194
+ points: n.lowestPoints
195
+ });
196
+ }) : r.push(t.flight);
197
+ }), r;
198
+ }, T = (s) => s ? s.replace(/^0+/, "") : "", ie = (s) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${s}.svg`, R = "/img/logo/odynn-eye.svg", S = {
199
+ categoryLogo: R,
200
+ programLogo: R,
192
201
  awayzActive: [],
193
202
  mainProgram: "Unknown",
194
203
  displayProgram: "Unknown",
195
204
  id: "Unknown",
196
205
  totalAccumulatedPoints: 0,
197
- category: q.Airline,
206
+ category: V.Airline,
198
207
  colour: "#fff",
199
208
  // Using App Foreground Colour
200
209
  url: "https://www.odynn.com"
201
- }, ie = async (i) => {
202
- const { airlines: e } = await K.ensureQueryData({
210
+ }, ae = async (s) => {
211
+ const { airlines: e } = await q.ensureQueryData({
203
212
  queryKey: ["walletAwards"],
204
- queryFn: j.getAwards,
213
+ queryFn: Q.getAwards,
205
214
  staleTime: 864e5
206
215
  // 24 hours
207
216
  });
208
- let c = e.find(
209
- (a) => {
210
- var s, n, t, o;
211
- return ((n = (s = a.mainProgram) == null ? void 0 : s.toLowerCase()) == null ? void 0 : n.includes(i == null ? void 0 : i.toLowerCase())) || ((o = (t = a.displayProgram) == null ? void 0 : t.toLowerCase()) == null ? void 0 : o.includes(i == null ? void 0 : i.toLowerCase()));
217
+ let r = e.find(
218
+ (t) => {
219
+ var a, n, i, o;
220
+ return ((n = (a = t.mainProgram) == null ? void 0 : a.toLowerCase()) == null ? void 0 : n.includes(s == null ? void 0 : s.toLowerCase())) || ((o = (i = t.displayProgram) == null ? void 0 : i.toLowerCase()) == null ? void 0 : o.includes(s == null ? void 0 : s.toLowerCase()));
212
221
  }
213
- ) ?? E;
214
- return c || (c = {
215
- ...E,
216
- mainProgram: i,
217
- displayProgram: i,
218
- id: i
219
- }), c;
222
+ ) ?? S;
223
+ return r || (r = {
224
+ ...S,
225
+ mainProgram: s,
226
+ displayProgram: s,
227
+ id: s
228
+ }), r;
229
+ }, U = (s) => ({
230
+ id: s.id,
231
+ cash: s.cash,
232
+ points: s.points,
233
+ program: s.airlineProgram,
234
+ cashFeeCurrency: s.flightDetails.baseCurrency,
235
+ //TODO: Add Cash Fee Amount
236
+ cashFeeAmount: 0,
237
+ baseCurrency: s.flightDetails.baseCurrency,
238
+ fareBrandName: s.flightDetails.slices[0].fareBrandName,
239
+ conditions: {
240
+ //TODO: Add Refund and Change Conditions
241
+ refundBeforeDeparture: !0,
242
+ changeBeforeDeparture: !0
243
+ },
244
+ carrier: {
245
+ iataCode: s.flightDetails.slices[0].segments[0].marketingCarrier.iataCode,
246
+ name: s.flightDetails.slices[0].segments[0].marketingCarrier.name
247
+ }
248
+ }), I = (s) => {
249
+ const e = Math.min(
250
+ ...s.filter((t) => t.cash > 0).map((t) => t.cash)
251
+ ), r = Math.min(
252
+ ...s.filter((t) => t.points > 0).map((t) => t.points)
253
+ );
254
+ return {
255
+ lowestCash: e === 1 / 0 ? -1 : e,
256
+ lowestPoints: r === 1 / 0 ? -1 : r
257
+ };
220
258
  };
221
259
  export {
222
- E as DEFAULT_AIRLINE_PROGRAM,
223
- X as buildFlightSearchQuery,
224
- ie as getAirlineProgram,
225
- U as getFlightNumber,
226
- te as getLogoPath,
227
- ee as groupFlightResults,
260
+ S as DEFAULT_AIRLINE_PROGRAM,
261
+ te as buildFlightSearchQuery,
262
+ ae as getAirlineProgram,
263
+ j as getFlightNumber,
264
+ ie as getLogoPath,
265
+ se as groupFlightResults,
228
266
  B as mapFlightDetailsToResults,
229
- J as parseFlightDetails,
230
- N as removeLeadingZeros
267
+ ee as parseFlightDetails,
268
+ T as removeLeadingZeros
231
269
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"