@odynn/awayz-flights 0.2.1 → 0.2.3

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,60 +1,56 @@
1
- import { jsx as r, jsxs as e } from "react/jsx-runtime";
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";
5
- import { h as u } from "../../arrayExtensions-DWKenJCh.js";
6
- import { g as $ } from "../../dateUtils-DeNLG5hw.js";
7
- import { EPaymentType as v } from "../../enums/EPaymentType.js";
8
- import '../../assets/FlightResult.css';function b(i) {
1
+ import { jsx as r, jsxs as e, Fragment as E } from "react/jsx-runtime";
2
+ import I, { useState as f, useMemo as T } from "react";
3
+ import { g as N, E as u, F as R, a as B } from "../../FlightItinerary-DgpK1LYF.js";
4
+ import { DEFAULT_AIRLINE_PROGRAM as L, getFlightNumber as $, getLogoPath as x, getAirlineProgram as M } from "../../utils/flightUtils.js";
5
+ import { h as v } from "../../arrayExtensions-DWKenJCh.js";
6
+ import { g as b } from "../../dateUtils-DeNLG5hw.js";
7
+ import { EPaymentType as o } from "../../enums/EPaymentType.js";
8
+ import { CashValue as F } from "@odynn/awayz-core";
9
+ import '../../assets/FlightResult.css';function j(i) {
9
10
  if (!i || isNaN(i) || i < 0) return "N/A";
10
- let n = i == null ? void 0 : i.toString().split(".")[0];
11
- return n == null ? void 0 : n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
11
+ let a = i == null ? void 0 : i.toString().split(".")[0];
12
+ return a == null ? void 0 : a.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 = [];
26
- 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),
14
+ const K = ({ details: i, onClick: a }) => {
15
+ const [g, y] = f(!1), c = i.origin, l = i.destination, p = i.flightDetails, C = !i.paymentOptions || i.paymentOptions.length === 1, [D, S] = f(L), P = async () => {
16
+ const n = await M(i.airlineProgram);
17
+ S(n);
18
+ }, { flightNumbers: h, airlines: A } = T(() => {
19
+ const n = [], t = [];
20
+ return i.flightDetails.slices.forEach((O) => {
21
+ O.segments.forEach((s) => {
22
+ const d = $(s);
23
+ n.includes(d) || n.push(d);
24
+ const m = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier;
25
+ t.some((k) => k.airline === m.name) || t.push({
26
+ logo: x(m.iataCode),
33
27
  airline: m.name
34
28
  });
35
29
  });
36
- }), C(), { flightNumbers: t, airlines: a };
30
+ }), P(), { flightNumbers: n, airlines: t };
37
31
  }, [i.flightDetails.slices]);
38
- return /* @__PURE__ */ r("div", { className: "flight-result", onClick: () => n(i), children: /* @__PURE__ */ e("div", { className: "content", children: [
32
+ return /* @__PURE__ */ r("div", { className: "flight-result", onClick: () => {
33
+ i.cash > 0 ? a(i, o.CASH) : a(i, o.POINTS);
34
+ }, children: /* @__PURE__ */ e("div", { className: "content", children: [
39
35
  /* @__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)) }),
36
+ /* @__PURE__ */ r("div", { className: "airlines", children: A.map((n, t) => /* @__PURE__ */ r(I.Fragment, { children: /* @__PURE__ */ r("div", { className: "tip", children: /* @__PURE__ */ r("img", { src: n.logo, alt: n.airline }) }, t) }, t)) }),
41
37
  /* @__PURE__ */ e("div", { className: "flight-location", children: [
42
38
  /* @__PURE__ */ e("p", { children: [
43
- o.city,
39
+ c.city,
44
40
  ",",
45
- f(o.country)
41
+ N(c.country)
46
42
  ] }),
47
- /* @__PURE__ */ r("p", { children: u(i.departureTime).format(
43
+ /* @__PURE__ */ r("p", { children: v(i.departureTime).format(
48
44
  // isMobile
49
45
  // ? EDateFormats.FlightTime
50
46
  // :
51
- N.FlightShortDate
47
+ u.FlightShortDate
52
48
  ) })
53
49
  ] }),
54
50
  /* @__PURE__ */ e("div", { className: "flight-duration", children: [
55
51
  /* @__PURE__ */ r("span", { className: "line" }),
56
52
  /* @__PURE__ */ e("p", { children: [
57
- $(g.slices[0].duration),
53
+ b(p.slices[0].duration),
58
54
  " ",
59
55
  " - ",
60
56
  i.numberOfStops > 0 ? `${i.numberOfStops} Stop${i.numberOfStops > 1 ? "s" : ""}` : "Direct"
@@ -63,16 +59,16 @@ const x = (i, n) => {
63
59
  ] }),
64
60
  /* @__PURE__ */ e("div", { children: [
65
61
  /* @__PURE__ */ e("p", { children: [
66
- c.city,
62
+ l.city,
67
63
  ", ",
68
- f(c.country)
64
+ N(l.country)
69
65
  ] }),
70
66
  /* @__PURE__ */ e("p", { children: [
71
- u(i.arrivalTime).format(
67
+ v(i.arrivalTime).format(
72
68
  // isMobile
73
69
  // ? EDateFormats.FlightTime
74
70
  // :
75
- N.FlightShortDate
71
+ u.FlightShortDate
76
72
  ),
77
73
  " "
78
74
  ] })
@@ -84,13 +80,13 @@ const x = (i, n) => {
84
80
  "div",
85
81
  {
86
82
  className: "flight-detail",
87
- onClick: (t) => {
88
- t.stopPropagation(), y(!s);
83
+ onClick: (n) => {
84
+ n.stopPropagation(), y(!g);
89
85
  },
90
86
  children: [
91
87
  /* @__PURE__ */ r("p", { children: "Aircraft" }),
92
88
  /* @__PURE__ */ e("p", { className: "chevron-text", children: [
93
- /* @__PURE__ */ r(I, {}),
89
+ /* @__PURE__ */ r(R, {}),
94
90
  /* @__PURE__ */ e("span", { children: [
95
91
  h[0],
96
92
  h.length > 1 && /* @__PURE__ */ e("sup", { children: [
@@ -117,12 +113,18 @@ const x = (i, n) => {
117
113
  "div",
118
114
  {
119
115
  className: "cash-value",
120
- onClick: (t) => {
121
- t.stopPropagation(), n(i, v.CASH);
116
+ onClick: (n) => {
117
+ n.stopPropagation(), a(i, o.CASH);
122
118
  },
123
119
  children: [
124
- /* @__PURE__ */ r("p", { children: D ? "Book For" : "From" }),
125
- /* @__PURE__ */ r("p", { children: x(i.cash, "USD") })
120
+ /* @__PURE__ */ r("p", { children: C ? "Book For" : "From" }),
121
+ /* @__PURE__ */ r("p", { children: /* @__PURE__ */ r(
122
+ F,
123
+ {
124
+ amount: i.cash,
125
+ currency: i.currency
126
+ }
127
+ ) })
126
128
  ]
127
129
  }
128
130
  ),
@@ -130,27 +132,39 @@ const x = (i, n) => {
130
132
  "div",
131
133
  {
132
134
  className: "points-value",
133
- onClick: (t) => {
134
- t.stopPropagation(), n(i, v.POINTS);
135
+ onClick: (n) => {
136
+ n.stopPropagation(), a(i, o.POINTS);
135
137
  },
136
138
  children: [
137
- /* @__PURE__ */ r("img", { src: S.programLogo }),
138
- /* @__PURE__ */ r("p", { children: `${b(i.points)} miles` })
139
+ /* @__PURE__ */ r("img", { src: D.programLogo }),
140
+ /* @__PURE__ */ e("p", { children: [
141
+ `${j(i.points)} miles`,
142
+ i.cashFee.amount > 0 && /* @__PURE__ */ e(E, { children: [
143
+ " + ",
144
+ /* @__PURE__ */ r(
145
+ F,
146
+ {
147
+ amount: i.cashFee.amount,
148
+ currency: i.cashFee.currency
149
+ }
150
+ )
151
+ ] })
152
+ ] })
139
153
  ]
140
154
  }
141
155
  )
142
156
  ] })
143
157
  ] }),
144
- /* @__PURE__ */ r("div", { className: `flight-details ${s ? "is-open" : ""}`, children: /* @__PURE__ */ r("div", { className: "inner", children: /* @__PURE__ */ r(
145
- M,
158
+ /* @__PURE__ */ r("div", { className: `flight-details ${g ? "is-open" : ""}`, children: /* @__PURE__ */ r("div", { className: "inner", children: /* @__PURE__ */ r(
159
+ B,
146
160
  {
147
- itinerary: g.slices[0].segments,
148
- origin: o,
149
- destination: c
161
+ itinerary: p.slices[0].segments,
162
+ origin: c,
163
+ destination: l
150
164
  }
151
165
  ) }) })
152
166
  ] }) });
153
167
  };
154
168
  export {
155
- z as FlightResult
169
+ K as FlightResult
156
170
  };
@@ -60,8 +60,8 @@ function oe(o, t, r) {
60
60
  o(n.id = g);
61
61
  break;
62
62
  case "retry":
63
- const b = parseInt(g, 10);
64
- isNaN(b) || t(n.retry = b);
63
+ const m = parseInt(g, 10);
64
+ isNaN(m) || t(n.retry = m);
65
65
  break;
66
66
  }
67
67
  }
@@ -90,34 +90,34 @@ var ae = function(o, t) {
90
90
  const x = "text/event-stream", ie = 1e3, z = "last-event-id";
91
91
  function ue(o, t) {
92
92
  var { signal: r, headers: n, onopen: s, onmessage: v, onclose: c, onerror: u, openWhenHidden: a, fetch: d } = t, g = ae(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
93
- return new Promise((b, _) => {
93
+ return new Promise((m, _) => {
94
94
  const p = Object.assign({}, n);
95
95
  p.accept || (p.accept = x);
96
- let m;
96
+ let y;
97
97
  function w() {
98
- m.abort(), document.hidden || T();
98
+ y.abort(), document.hidden || T();
99
99
  }
100
100
  a || document.addEventListener("visibilitychange", w);
101
101
  let F = ie, E = 0;
102
102
  function S() {
103
- document.removeEventListener("visibilitychange", w), window.clearTimeout(E), m.abort();
103
+ document.removeEventListener("visibilitychange", w), window.clearTimeout(E), y.abort();
104
104
  }
105
105
  r == null || r.addEventListener("abort", () => {
106
- S(), b();
106
+ S(), m();
107
107
  });
108
108
  const q = d ?? window.fetch, P = s ?? ce;
109
109
  async function T() {
110
110
  var C;
111
- m = new AbortController();
111
+ y = new AbortController();
112
112
  try {
113
- const O = await q(o, Object.assign(Object.assign({}, g), { headers: p, signal: m.signal }));
113
+ const O = await q(o, Object.assign(Object.assign({}, g), { headers: p, signal: y.signal }));
114
114
  await P(O), await ne(O.body, re(oe((h) => {
115
115
  h ? p[z] = h : delete p[z];
116
116
  }, (h) => {
117
117
  F = h;
118
- }, v))), c == null || c(), S(), b();
118
+ }, v))), c == null || c(), S(), m();
119
119
  } catch (O) {
120
- if (!m.signal.aborted)
120
+ if (!y.signal.aborted)
121
121
  try {
122
122
  const h = (C = u == null ? void 0 : u(O)) !== null && C !== void 0 ? C : F;
123
123
  window.clearTimeout(E), E = window.setTimeout(T, h);
@@ -147,17 +147,17 @@ const de = 3 * 60 * 1e3, $ = (o) => {
147
147
  const { token: o, config: t } = ee(), [r, n] = N(""), [s, v] = N([]), [c, u] = N(!1), a = K(null), {
148
148
  inboundResults: d,
149
149
  outboundResults: g,
150
- setInboundResults: b,
150
+ setInboundResults: m,
151
151
  setOutboundResults: _,
152
152
  partialOfferRequestId: p,
153
- setPartialOfferRequestId: m
153
+ setPartialOfferRequestId: y
154
154
  } = Z(), w = ({
155
155
  data: e,
156
156
  previousResults: l,
157
157
  inbound: f
158
158
  }) => {
159
159
  const i = V(e, l);
160
- return (f ? b : _)(G(i)), i;
160
+ return (f ? m : _)(G(i)), i;
161
161
  }, {
162
162
  mutate: F,
163
163
  status: E,
@@ -197,13 +197,12 @@ const de = 3 * 60 * 1e3, $ = (o) => {
197
197
  }
198
198
  },
199
199
  onSuccess: (e) => {
200
- console.log({ result: e });
201
200
  const { success: l, data: f, partialOfferRequestId: i } = e;
202
201
  if (!l) {
203
202
  console.log("oh lol, it didn't work");
204
203
  return;
205
204
  }
206
- w({ data: f }), i && m(i);
205
+ w({ data: f }), i && y(i);
207
206
  },
208
207
  onError: (e) => {
209
208
  console.error("Error in outbound flight search:", e);
@@ -278,19 +277,19 @@ const de = 3 * 60 * 1e3, $ = (o) => {
278
277
  signal: j.signal,
279
278
  onmessage(A) {
280
279
  try {
281
- const y = W(JSON.parse(A.data));
282
- if (y.success === !1)
280
+ const b = W(JSON.parse(A.data));
281
+ if (b.success === !1)
283
282
  return;
284
- if (y.close === !0) {
283
+ if (b.close === !0) {
285
284
  R();
286
285
  return;
287
286
  }
288
- y.flights && (I = 0, i = w({
289
- data: y.flights,
287
+ b.flights && (console.log({ parsed: b.flights }), I = 0, i = w({
288
+ data: b.flights,
290
289
  previousResults: i
291
- })), y.ping && (I++, I >= t.flightsConfig.streamTimeoutPingCount && R());
292
- } catch (y) {
293
- console.error("Error parsing message:", y), R();
290
+ })), b.ping && (I++, I >= t.flightsConfig.streamTimeoutPingCount && R());
291
+ } catch (b) {
292
+ console.error("Error parsing message:", b), R();
294
293
  }
295
294
  },
296
295
  onerror(A) {
@@ -75,10 +75,13 @@ export interface IFlightPaymentOption {
75
75
  id: string;
76
76
  cash: number;
77
77
  points: number;
78
- cashFeeCurrency: string;
79
- cashFeeAmount: number;
78
+ cashFee: {
79
+ amount: number;
80
+ currency: string;
81
+ };
80
82
  baseCurrency: string;
81
83
  fareBrandName: string;
84
+ program: string;
82
85
  baggages?: {
83
86
  type: EBaggage | null;
84
87
  quantity: number;
@@ -101,6 +104,10 @@ export interface IFlightResult {
101
104
  destination: IAirportLocation;
102
105
  cash: number;
103
106
  points: number;
107
+ cashFee: {
108
+ amount: number;
109
+ currency: string;
110
+ };
104
111
  numberOfStops: number;
105
112
  departureTime: Date;
106
113
  arrivalTime: Date;
@@ -110,6 +117,7 @@ export interface IFlightResult {
110
117
  durationMinutes: number;
111
118
  flightDetails: IFlightOffer;
112
119
  paymentOptions: IFlightPaymentOption[];
120
+ currency: string;
113
121
  }
114
122
  export interface IAirportLocation {
115
123
  city: string;
@@ -149,6 +157,10 @@ export interface IFlightOffer {
149
157
  partial: boolean;
150
158
  owner: IOwner;
151
159
  id: string;
160
+ cashFee: {
161
+ amount: number;
162
+ currency: string;
163
+ };
152
164
  }
153
165
  export interface IPaymentRequirements {
154
166
  requiresInstantPayment: boolean;
@@ -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 F } 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, w, g, M, P, N, A, L, h, d, p, c, y, C, b, l, u, D, k, O, z, v, f, _, $, 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 = (w = e.slices[0].segments[0].origin) == null ? void 0 : w.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: (A = (N = e.slices[0].segments[0].origin) == null ? void 0 : N.city) == null ? void 0 : A.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: ((h = (L = e.slices[0].segments.getLast()) == null ? void 0 : L.destination) == null ? void 0 : h.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) || ((v = (z = (O = e.slices[0].segments.getLast()) == null ? void 0 : O.destination) == null ? void 0 : z.city) == null ? void 0 : v.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: ($ = (_ = (f = e.slices[0].segments.getLast()) == null ? void 0 : f.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
- cash: parseFloat(e.totalAmount),
33
- flightNumber: U(e.slices[0].segments[0]),
32
+ cash: e.totalAmount ? parseFloat(e.totalAmount) : 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: F(e.slices[0].segments[0].departingAt).toDate(),
37
+ arrivalTime: F(
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: F(e.slices[0].segments[0].departingAt),
47
+ arrivalTime: F(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
+ }),
52
+ cashFee: e.cashFee
51
53
  };
52
- }), J = (i, e) => {
54
+ }), ee = (s, e) => {
53
55
  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
56
+ return B(s);
57
+ const r = [...e], t = [], a = {};
58
+ for (const i of s) {
59
+ const o = i.slices[0].segments, m = o[0], w = {
60
+ iataCode: m.operatingCarrier.iataCode,
61
+ flightNumber: T(
62
+ m.operatingCarrierFlightNumber
61
63
  )
62
- }, d = {
63
- iataCode: g.marketingCarrier.iataCode,
64
- flightNumber: N(
65
- g.marketingCarrierFlightNumber
64
+ }, g = {
65
+ iataCode: m.marketingCarrier.iataCode,
66
+ flightNumber: T(
67
+ m.marketingCarrierFlightNumber
66
68
  )
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
69
+ }, M = i.awayzMatchId, P = `${w.iataCode}_${g.iataCode}-${g.flightNumber}`, N = i.awayzMarketerMatchId, A = !!w.flightNumber && w.flightNumber != "", L = !!g.flightNumber && g.flightNumber != "", h = r.filter((d, p) => {
70
+ 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
71
+ !!y && y !== "";
72
+ if (!(c.slices[0].segments.length === (o == null ? void 0 : o.length) && !c.slices[0].segments.find(
73
+ (u, D) => u.departingAt !== o[D].departingAt || u.arrivingAt !== o[D].arrivingAt || u.duration !== o[D].duration
72
74
  )))
73
75
  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;
76
+ let l = !1;
77
+ return (L && A && c.awayzMatchId === M || !C && c.awayzMatchId === P || A && !L && c.awayzMarketerMatchId === N) && (l = !0), l && (a[c.id] = p), l;
76
78
  });
77
- 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
+ if (h.length) {
80
+ i.slices[0].comparisonKey = h[0].awayzGroupId;
81
+ const d = h.find((p) => {
82
+ var C, b, l, u;
83
+ const c = (C = p.flightDetails.slices[0].fareBrandName) == null ? void 0 : C.toLowerCase(), y = (b = i.slices[0].fareBrandName) == null ? void 0 : b.toLowerCase();
84
+ return y === c || // Special Case for AC Only match on first word
83
85
  // 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]);
86
+ g.iataCode === "AC" && ((l = y.split(" ")) == null ? void 0 : l[0]) === ((u = c.split(" ")) == null ? void 0 : u[0]);
85
87
  });
86
- if (u) {
87
- const y = s[u.id], l = {
88
- ...t,
89
- ...u,
90
- points: t.points,
91
- airlineProgram: t.airlineProgram,
88
+ if (d) {
89
+ const p = a[d.id], c = {
90
+ ...i,
91
+ ...d,
92
+ points: i.points,
93
+ airlineProgram: i.airlineProgram,
92
94
  flightDetails: {
93
- ...t,
94
- ...u.flightDetails,
95
- points: t.points,
96
- airlineProgram: t.airlineProgram
95
+ ...i,
96
+ ...d.flightDetails,
97
+ points: i.points,
98
+ airlineProgram: i.airlineProgram
97
99
  }
98
100
  };
99
- c[y] = l;
101
+ r[p] = c;
100
102
  } else
101
- a.push(t);
103
+ t.push(i);
102
104
  } else
103
- a.push(t);
105
+ t.push(i);
104
106
  }
105
107
  return [
106
- ...c,
107
- ...B(a) ?? []
108
+ ...r,
109
+ ...B(t) ?? []
108
110
  ];
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,
111
+ }, j = (s) => {
112
+ const e = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier, r = s.operatingCarrierFlightNumber ?? s.marketingCarrierFlightNumber;
113
+ return e.iataCode + " " + T(r);
114
+ }, te = ({
115
+ originCode: s,
114
116
  destinationCode: e,
115
- departureDate: c,
116
- cabinClass: a,
117
- passengerCount: s,
117
+ departureDate: r,
118
+ cabinClass: t,
119
+ passengerCount: a,
118
120
  paymentType: n
119
121
  }) => {
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
122
+ let i = "/flights/search/one-way/points-cash?";
123
+ return i += `origin=${s}`, i += `&destination=${e}`, i += `&departure_date=${r}`, i += `&cabin_class=${t}`, i += `&adults=${a}`, i += `&cash_or_points=[${n}]`, i;
124
+ }, se = (s) => {
125
+ const e = {};
126
+ s.forEach((t) => {
127
+ const a = t.flightDetails.slices[0].segments.map((n) => j(n)).join("_");
128
+ if (e[a]) {
129
+ const n = U(t);
130
+ e[a].flight.paymentOptions.push(n);
131
+ const i = I(
132
+ e[a].flight.paymentOptions
133
+ );
134
+ e[a].flight.cash = i.lowestCash, e[a].flight.points = i.lowestPoints;
135
+ } else {
136
+ const { origin: n, destination: i } = t, o = [U(t)], m = I(o);
137
+ e[a] = {
138
+ programs: [],
139
+ flight: {
140
+ id: t.awayzGroupId,
141
+ partial: t.partial,
142
+ origin: {
143
+ city: n.city,
144
+ country: n.country,
145
+ airportCode: n.airportCode,
146
+ coordinates: n.coordinates
160
147
  },
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
148
+ destination: {
149
+ city: i.city,
150
+ country: i.country,
151
+ airportCode: i.airportCode,
152
+ coordinates: i.coordinates
153
+ },
154
+ airline: t.airline,
155
+ flightNumber: t.flightNumber,
156
+ paymentOptions: o,
157
+ numberOfStops: t.numberOfStops,
158
+ departureTime: t.departureTime,
159
+ arrivalTime: t.arrivalTime,
160
+ awayzGroupId: t.awayzGroupId,
161
+ duration: t.duration,
162
+ airlineProgram: t.airlineProgram,
163
+ durationMinutes: K({
164
+ departureTime: F(
165
+ t.flightDetails.slices[0].segments[0].departingAt
166
+ ),
167
+ arrivalTime: F(
168
+ t.flightDetails.slices[0].segments.getLast().arrivingAt
169
+ ),
170
+ originTimeZone: t.flightDetails.slices[0].segments[0].origin.timeZone,
171
+ destinationTimeZone: t.flightDetails.slices[0].segments.getLast().destination.timeZone,
172
+ duration: t.flightDetails.slices[0].duration
173
+ }),
174
+ cash: m.lowestCash,
175
+ points: m.lowestPoints,
176
+ flightDetails: t.flightDetails,
177
+ currency: t.flightDetails.baseCurrency,
178
+ cashFee: t.cashFee
179
+ }
186
180
  };
187
181
  }
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,
182
+ t.airlineProgram && !e[a].programs.includes(t.airlineProgram) && e[a].programs.push(t.airlineProgram);
183
+ });
184
+ const r = [];
185
+ return Object.values(e).forEach((t) => {
186
+ t.programs.length > 0 ? t.programs.forEach((a) => {
187
+ const n = I(
188
+ t.flight.paymentOptions.filter(
189
+ (i) => i.program === a || i.cash > 0
190
+ )
191
+ );
192
+ r.push({
193
+ ...t.flight,
194
+ airlineProgram: a,
195
+ cash: n.lowestCash,
196
+ points: n.lowestPoints
197
+ });
198
+ }) : r.push(t.flight);
199
+ }), r;
200
+ }, 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 = {
201
+ categoryLogo: R,
202
+ programLogo: R,
192
203
  awayzActive: [],
193
204
  mainProgram: "Unknown",
194
205
  displayProgram: "Unknown",
195
206
  id: "Unknown",
196
207
  totalAccumulatedPoints: 0,
197
- category: q.Airline,
208
+ category: V.Airline,
198
209
  colour: "#fff",
199
210
  // Using App Foreground Colour
200
211
  url: "https://www.odynn.com"
201
- }, ie = async (i) => {
202
- const { airlines: e } = await K.ensureQueryData({
212
+ }, ae = async (s) => {
213
+ const { airlines: e } = await q.ensureQueryData({
203
214
  queryKey: ["walletAwards"],
204
- queryFn: j.getAwards,
215
+ queryFn: Q.getAwards,
205
216
  staleTime: 864e5
206
217
  // 24 hours
207
218
  });
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()));
219
+ let r = e.find(
220
+ (t) => {
221
+ var a, n, i, o;
222
+ 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
223
  }
213
- ) ?? E;
214
- return c || (c = {
215
- ...E,
216
- mainProgram: i,
217
- displayProgram: i,
218
- id: i
219
- }), c;
224
+ ) ?? S;
225
+ return r || (r = {
226
+ ...S,
227
+ mainProgram: s,
228
+ displayProgram: s,
229
+ id: s
230
+ }), r;
231
+ }, U = (s) => (console.log({ flight: s }), {
232
+ id: s.id,
233
+ cash: s.cash,
234
+ points: s.points,
235
+ program: s.airlineProgram,
236
+ baseCurrency: s.flightDetails.baseCurrency,
237
+ fareBrandName: s.flightDetails.slices[0].fareBrandName,
238
+ cashFee: s.cashFee,
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.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"