@odynn/awayz-flights 0.2.3 → 0.2.4

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,56 +1,57 @@
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";
1
+ import { jsx as r, jsxs as e, Fragment as I } from "react/jsx-runtime";
2
+ import T, { useState as N, useMemo as R } from "react";
3
+ import { g as u, E as v, F as B, a as L } from "../../FlightItinerary-DgpK1LYF.js";
4
+ import { DEFAULT_AIRLINE_PROGRAM as $, getFlightNumber as x, getLogoPath as M, getAirlineProgram as b } from "../../utils/flightUtils.js";
5
+ import { h as F } from "../../arrayExtensions-DWKenJCh.js";
6
+ import { g as j } from "../../dateUtils-DeNLG5hw.js";
7
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) {
8
+ import { CashValue as y } from "@odynn/awayz-core";
9
+ import '../../assets/FlightResult.css';function H(i) {
10
10
  if (!i || isNaN(i) || i < 0) return "N/A";
11
11
  let a = i == null ? void 0 : i.toString().split(".")[0];
12
12
  return a == null ? void 0 : a.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
13
13
  }
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(() => {
14
+ const Q = ({ details: i, onClick: a }) => {
15
+ var d;
16
+ const [g, C] = N(!1), c = i.origin, l = i.destination, p = i.flightDetails, D = !i.paymentOptions || i.paymentOptions.length === 1, [S, P] = N($), A = async () => {
17
+ const n = await b(i.airlineProgram);
18
+ P(n);
19
+ }, { flightNumbers: h, airlines: O } = R(() => {
19
20
  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);
21
+ return i.flightDetails.slices.forEach((k) => {
22
+ k.segments.forEach((s) => {
23
+ const f = x(s);
24
+ n.includes(f) || n.push(f);
24
25
  const m = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier;
25
- t.some((k) => k.airline === m.name) || t.push({
26
- logo: x(m.iataCode),
26
+ t.some((E) => E.airline === m.name) || t.push({
27
+ logo: M(m.iataCode),
27
28
  airline: m.name
28
29
  });
29
30
  });
30
- }), P(), { flightNumbers: n, airlines: t };
31
+ }), A(), { flightNumbers: n, airlines: t };
31
32
  }, [i.flightDetails.slices]);
32
33
  return /* @__PURE__ */ r("div", { className: "flight-result", onClick: () => {
33
34
  i.cash > 0 ? a(i, o.CASH) : a(i, o.POINTS);
34
35
  }, children: /* @__PURE__ */ e("div", { className: "content", children: [
35
36
  /* @__PURE__ */ r("div", { className: "flight-info", children: /* @__PURE__ */ e("div", { className: "flight-locations", children: [
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)) }),
37
+ /* @__PURE__ */ r("div", { className: "airlines", children: O.map((n, t) => /* @__PURE__ */ r(T.Fragment, { children: /* @__PURE__ */ r("div", { className: "tip", children: /* @__PURE__ */ r("img", { src: n.logo, alt: n.airline }) }, t) }, t)) }),
37
38
  /* @__PURE__ */ e("div", { className: "flight-location", children: [
38
39
  /* @__PURE__ */ e("p", { children: [
39
40
  c.city,
40
41
  ",",
41
- N(c.country)
42
+ u(c.country)
42
43
  ] }),
43
- /* @__PURE__ */ r("p", { children: v(i.departureTime).format(
44
+ /* @__PURE__ */ r("p", { children: F(i.departureTime).format(
44
45
  // isMobile
45
46
  // ? EDateFormats.FlightTime
46
47
  // :
47
- u.FlightShortDate
48
+ v.FlightShortDate
48
49
  ) })
49
50
  ] }),
50
51
  /* @__PURE__ */ e("div", { className: "flight-duration", children: [
51
52
  /* @__PURE__ */ r("span", { className: "line" }),
52
53
  /* @__PURE__ */ e("p", { children: [
53
- b(p.slices[0].duration),
54
+ j(p.slices[0].duration),
54
55
  " ",
55
56
  " - ",
56
57
  i.numberOfStops > 0 ? `${i.numberOfStops} Stop${i.numberOfStops > 1 ? "s" : ""}` : "Direct"
@@ -61,14 +62,14 @@ const K = ({ details: i, onClick: a }) => {
61
62
  /* @__PURE__ */ e("p", { children: [
62
63
  l.city,
63
64
  ", ",
64
- N(l.country)
65
+ u(l.country)
65
66
  ] }),
66
67
  /* @__PURE__ */ e("p", { children: [
67
- v(i.arrivalTime).format(
68
+ F(i.arrivalTime).format(
68
69
  // isMobile
69
70
  // ? EDateFormats.FlightTime
70
71
  // :
71
- u.FlightShortDate
72
+ v.FlightShortDate
72
73
  ),
73
74
  " "
74
75
  ] })
@@ -81,12 +82,12 @@ const K = ({ details: i, onClick: a }) => {
81
82
  {
82
83
  className: "flight-detail",
83
84
  onClick: (n) => {
84
- n.stopPropagation(), y(!g);
85
+ n.stopPropagation(), C(!g);
85
86
  },
86
87
  children: [
87
88
  /* @__PURE__ */ r("p", { children: "Aircraft" }),
88
89
  /* @__PURE__ */ e("p", { className: "chevron-text", children: [
89
- /* @__PURE__ */ r(R, {}),
90
+ /* @__PURE__ */ r(B, {}),
90
91
  /* @__PURE__ */ e("span", { children: [
91
92
  h[0],
92
93
  h.length > 1 && /* @__PURE__ */ e("sup", { children: [
@@ -117,9 +118,9 @@ const K = ({ details: i, onClick: a }) => {
117
118
  n.stopPropagation(), a(i, o.CASH);
118
119
  },
119
120
  children: [
120
- /* @__PURE__ */ r("p", { children: C ? "Book For" : "From" }),
121
+ /* @__PURE__ */ r("p", { children: D ? "Book For" : "From" }),
121
122
  /* @__PURE__ */ r("p", { children: /* @__PURE__ */ r(
122
- F,
123
+ y,
123
124
  {
124
125
  amount: i.cash,
125
126
  currency: i.currency
@@ -136,13 +137,13 @@ const K = ({ details: i, onClick: a }) => {
136
137
  n.stopPropagation(), a(i, o.POINTS);
137
138
  },
138
139
  children: [
139
- /* @__PURE__ */ r("img", { src: D.programLogo }),
140
+ /* @__PURE__ */ r("img", { src: S.programLogo }),
140
141
  /* @__PURE__ */ e("p", { children: [
141
- `${j(i.points)} miles`,
142
- i.cashFee.amount > 0 && /* @__PURE__ */ e(E, { children: [
142
+ `${H(i.points)} miles`,
143
+ ((d = i.cashFee) == null ? void 0 : d.amount) > 0 && /* @__PURE__ */ e(I, { children: [
143
144
  " + ",
144
145
  /* @__PURE__ */ r(
145
- F,
146
+ y,
146
147
  {
147
148
  amount: i.cashFee.amount,
148
149
  currency: i.cashFee.currency
@@ -156,7 +157,7 @@ const K = ({ details: i, onClick: a }) => {
156
157
  ] })
157
158
  ] }),
158
159
  /* @__PURE__ */ r("div", { className: `flight-details ${g ? "is-open" : ""}`, children: /* @__PURE__ */ r("div", { className: "inner", children: /* @__PURE__ */ r(
159
- B,
160
+ L,
160
161
  {
161
162
  itinerary: p.slices[0].segments,
162
163
  origin: c,
@@ -166,5 +167,5 @@ const K = ({ details: i, onClick: a }) => {
166
167
  ] }) });
167
168
  };
168
169
  export {
169
- K as FlightResult
170
+ Q as FlightResult
170
171
  };
@@ -47,21 +47,21 @@ function oe(o, t, r) {
47
47
  if (c.length === 0)
48
48
  r == null || r(n), n = U();
49
49
  else if (u > 0) {
50
- const a = s.decode(c.subarray(0, u)), d = u + (c[u + 1] === 32 ? 2 : 1), g = s.decode(c.subarray(d));
50
+ const a = s.decode(c.subarray(0, u)), d = u + (c[u + 1] === 32 ? 2 : 1), b = s.decode(c.subarray(d));
51
51
  switch (a) {
52
52
  case "data":
53
53
  n.data = n.data ? n.data + `
54
- ` + g : g;
54
+ ` + b : b;
55
55
  break;
56
56
  case "event":
57
- n.event = g;
57
+ n.event = b;
58
58
  break;
59
59
  case "id":
60
- o(n.id = g);
60
+ o(n.id = b);
61
61
  break;
62
62
  case "retry":
63
- const m = parseInt(g, 10);
64
- isNaN(m) || t(n.retry = m);
63
+ const g = parseInt(b, 10);
64
+ isNaN(g) || t(n.retry = g);
65
65
  break;
66
66
  }
67
67
  }
@@ -89,35 +89,35 @@ var ae = function(o, t) {
89
89
  };
90
90
  const x = "text/event-stream", ie = 1e3, z = "last-event-id";
91
91
  function ue(o, t) {
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((m, _) => {
92
+ var { signal: r, headers: n, onopen: s, onmessage: v, onclose: c, onerror: u, openWhenHidden: a, fetch: d } = t, b = ae(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
93
+ return new Promise((g, _) => {
94
94
  const p = Object.assign({}, n);
95
95
  p.accept || (p.accept = x);
96
- let y;
96
+ let m;
97
97
  function w() {
98
- y.abort(), document.hidden || T();
98
+ m.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), y.abort();
103
+ document.removeEventListener("visibilitychange", w), window.clearTimeout(E), m.abort();
104
104
  }
105
105
  r == null || r.addEventListener("abort", () => {
106
- S(), m();
106
+ S(), g();
107
107
  });
108
108
  const q = d ?? window.fetch, P = s ?? ce;
109
109
  async function T() {
110
110
  var C;
111
- y = new AbortController();
111
+ m = new AbortController();
112
112
  try {
113
- const O = await q(o, Object.assign(Object.assign({}, g), { headers: p, signal: y.signal }));
113
+ const O = await q(o, Object.assign(Object.assign({}, b), { headers: p, signal: m.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(), m();
118
+ }, v))), c == null || c(), S(), g();
119
119
  } catch (O) {
120
- if (!y.signal.aborted)
120
+ if (!m.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);
@@ -146,18 +146,18 @@ const de = 3 * 60 * 1e3, $ = (o) => {
146
146
  }, Ee = () => {
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
- outboundResults: g,
150
- setInboundResults: m,
149
+ outboundResults: b,
150
+ setInboundResults: g,
151
151
  setOutboundResults: _,
152
152
  partialOfferRequestId: p,
153
- setPartialOfferRequestId: y
153
+ setPartialOfferRequestId: m
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 ? m : _)(G(i)), i;
160
+ return (f ? g : _)(G(i)), i;
161
161
  }, {
162
162
  mutate: F,
163
163
  status: E,
@@ -202,7 +202,7 @@ const de = 3 * 60 * 1e3, $ = (o) => {
202
202
  console.log("oh lol, it didn't work");
203
203
  return;
204
204
  }
205
- w({ data: f }), i && y(i);
205
+ w({ data: f }), i && m(i);
206
206
  },
207
207
  onError: (e) => {
208
208
  console.error("Error in outbound flight search:", e);
@@ -277,19 +277,19 @@ const de = 3 * 60 * 1e3, $ = (o) => {
277
277
  signal: j.signal,
278
278
  onmessage(A) {
279
279
  try {
280
- const b = W(JSON.parse(A.data));
281
- if (b.success === !1)
280
+ const y = W(JSON.parse(A.data));
281
+ if (y.success === !1)
282
282
  return;
283
- if (b.close === !0) {
283
+ if (y.close === !0) {
284
284
  R();
285
285
  return;
286
286
  }
287
- b.flights && (console.log({ parsed: b.flights }), I = 0, i = w({
288
- data: b.flights,
287
+ y.flights && (I = 0, i = w({
288
+ data: y.flights,
289
289
  previousResults: i
290
- })), b.ping && (I++, I >= t.flightsConfig.streamTimeoutPingCount && R());
291
- } catch (b) {
292
- console.error("Error parsing message:", b), R();
290
+ })), y.ping && (I++, I >= t.flightsConfig.streamTimeoutPingCount && R());
291
+ } catch (y) {
292
+ console.error("Error parsing message:", y), R();
293
293
  }
294
294
  },
295
295
  onerror(A) {
@@ -320,7 +320,7 @@ const de = 3 * 60 * 1e3, $ = (o) => {
320
320
  inboundError: T,
321
321
  roundTripFaresError: h,
322
322
  // Results
323
- outboundResults: g,
323
+ outboundResults: b,
324
324
  inboundResults: d,
325
325
  roundTripFares: s,
326
326
  // Mutation triggers
@@ -5,7 +5,7 @@ import { awayzClient as q } from "@odynn/awayz-core";
5
5
  import { WalletService as Q } from "../services/wallet/WalletService.js";
6
6
  import { ERewardProgramCategories as V } from "../services/wallet/WalletService.types.js";
7
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;
8
+ var r, t, a, n, i, o, m, h, g, M, P, N, A, L, w, d, p, c, y, C, b, l, u, D, k, O, z, f, 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,
@@ -13,18 +13,18 @@ const B = (s) => s == null ? void 0 : s.map((e) => {
13
13
  origin: {
14
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
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),
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
18
  latitude: (P = (M = e.slices[0].segments[0].origin) == null ? void 0 : M.city) == null ? void 0 : P.latitude,
19
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: ((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),
23
+ city: ((w = (L = e.slices[0].segments.getLast()) == null ? void 0 : L.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
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),
25
+ airportCode: ((k = (D = e.slices[0].segments.getLast()) == null ? void 0 : D.destination) == null ? void 0 : k.iataCityCode) || ((f = (z = (O = e.slices[0].segments.getLast()) == null ? void 0 : O.destination) == null ? void 0 : z.city) == null ? void 0 : f.iataCode),
26
26
  coordinates: {
27
- latitude: ($ = (_ = (f = e.slices[0].segments.getLast()) == null ? void 0 : f.destination) == null ? void 0 : _.city) == null ? void 0 : $.latitude,
27
+ latitude: ($ = (_ = (v = e.slices[0].segments.getLast()) == null ? void 0 : v.destination) == null ? void 0 : _.city) == null ? void 0 : $.latitude,
28
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
  },
@@ -56,7 +56,7 @@ const B = (s) => s == null ? void 0 : s.map((e) => {
56
56
  return B(s);
57
57
  const r = [...e], t = [], a = {};
58
58
  for (const i of s) {
59
- const o = i.slices[0].segments, m = o[0], w = {
59
+ const o = i.slices[0].segments, m = o[0], h = {
60
60
  iataCode: m.operatingCarrier.iataCode,
61
61
  flightNumber: T(
62
62
  m.operatingCarrierFlightNumber
@@ -66,7 +66,7 @@ const B = (s) => s == null ? void 0 : s.map((e) => {
66
66
  flightNumber: T(
67
67
  m.marketingCarrierFlightNumber
68
68
  )
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) => {
69
+ }, M = i.awayzMatchId, P = `${h.iataCode}_${g.iataCode}-${g.flightNumber}`, N = i.awayzMarketerMatchId, A = !!h.flightNumber && h.flightNumber != "", L = !!g.flightNumber && g.flightNumber != "", w = r.filter((d, p) => {
70
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
71
  !!y && y !== "";
72
72
  if (!(c.slices[0].segments.length === (o == null ? void 0 : o.length) && !c.slices[0].segments.find(
@@ -76,9 +76,9 @@ const B = (s) => s == null ? void 0 : s.map((e) => {
76
76
  let l = !1;
77
77
  return (L && A && c.awayzMatchId === M || !C && c.awayzMatchId === P || A && !L && c.awayzMarketerMatchId === N) && (l = !0), l && (a[c.id] = p), l;
78
78
  });
79
- if (h.length) {
80
- i.slices[0].comparisonKey = h[0].awayzGroupId;
81
- const d = h.find((p) => {
79
+ if (w.length) {
80
+ i.slices[0].comparisonKey = w[0].awayzGroupId;
81
+ const d = w.find((p) => {
82
82
  var C, b, l, u;
83
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
84
  return y === c || // Special Case for AC Only match on first word
@@ -228,7 +228,7 @@ const B = (s) => s == null ? void 0 : s.map((e) => {
228
228
  displayProgram: s,
229
229
  id: s
230
230
  }), r;
231
- }, U = (s) => (console.log({ flight: s }), {
231
+ }, U = (s) => ({
232
232
  id: s.id,
233
233
  cash: s.cash,
234
234
  points: s.points,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"