@odynn/awayz-flights 0.1.17 → 0.1.18

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.
@@ -263,7 +263,9 @@ const U = 1, W = J.ECONOMY, z = new AbortController(), ue = 3 * 60 * 1e3, B = (o
263
263
  paymentType: l
264
264
  });
265
265
  let i = [];
266
- await ae(Z() + f, {
266
+ a.current = setTimeout(() => {
267
+ I();
268
+ }, ue), await ae(Z() + f, {
267
269
  headers: {
268
270
  "Content-Type": "application/json",
269
271
  Authorization: o || "",
@@ -296,9 +298,7 @@ const U = 1, W = J.ECONOMY, z = new AbortController(), ue = 3 * 60 * 1e3, B = (o
296
298
  console.log("EventSource closed"), u(!1);
297
299
  },
298
300
  keepalive: !1
299
- }), a.current = setTimeout(() => {
300
- I();
301
- }, ue);
301
+ });
302
302
  }, I = () => {
303
303
  c && (z.abort(), a.current && (clearTimeout(a.current), a.current = null), u(!1));
304
304
  };
@@ -1,18 +1,18 @@
1
- import { h as N } from "../arrayExtensions-DWKenJCh.js";
1
+ import { h as D } from "../arrayExtensions-DWKenJCh.js";
2
2
  import { c as z } from "../dateUtils-DeNLG5hw.js";
3
3
  import "react";
4
- import { awayzClient as v } from "@odynn/awayz-auth";
4
+ import { awayzClient as O } from "@odynn/awayz-auth";
5
5
  import { WalletService as G } from "../services/wallet/WalletService.js";
6
- import { ERewardProgramCategories as O } from "../services/wallet/WalletService.types.js";
7
- const T = (r) => r == null ? void 0 : r.map((e) => {
8
- var n, s, t, c, i, a, l, h, u, L, A, M, D, F, w, d, p, o, y, C, b, m, g, f;
6
+ import { ERewardProgramCategories as _ } from "../services/wallet/WalletService.types.js";
7
+ const T = (s) => s == null ? void 0 : s.map((e) => {
8
+ var n, r, i, o, t, a, l, h, u, L, A, M, N, F, w, g, p, c, y, C, b, m, d, f;
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.partial,
13
13
  origin: {
14
- city: e.slices[0].segments[0].origin.cityName || ((s = (n = e.slices[0].segments[0].origin) == null ? void 0 : n.city) == null ? void 0 : s.name),
15
- country: e.slices[0].segments[0].origin.iataCountryCode || ((t = e.slices[0].segments[0].origin) == null ? void 0 : t.city.iataCountryCode),
14
+ city: e.slices[0].segments[0].origin.cityName || ((r = (n = e.slices[0].segments[0].origin) == null ? void 0 : n.city) == null ? void 0 : r.name),
15
+ country: e.slices[0].segments[0].origin.iataCountryCode || ((i = e.slices[0].segments[0].origin) == null ? void 0 : i.city.iataCountryCode),
16
16
  airportCode: e.slices[0].segments[0].origin.iataCityCode || e.slices[0].segments[0].origin.city.iataCode,
17
17
  coordinates: {
18
18
  latitude: e.slices[0].segments[0].origin.city.latitude,
@@ -20,20 +20,20 @@ const T = (r) => r == null ? void 0 : r.map((e) => {
20
20
  }
21
21
  },
22
22
  destination: {
23
- city: ((i = (c = e.slices[0].segments.getLast()) == null ? void 0 : c.destination) == null ? void 0 : i.cityName) || ((h = (l = (a = e.slices[0].segments.getLast()) == null ? void 0 : a.destination) == null ? void 0 : l.city) == null ? void 0 : h.name),
24
- country: ((L = (u = e.slices[0].segments.getLast()) == null ? void 0 : u.destination) == null ? void 0 : L.iataCountryCode) || ((D = (M = (A = e.slices[0].segments.getLast()) == null ? void 0 : A.destination) == null ? void 0 : M.city) == null ? void 0 : D.iataCountryCode),
25
- airportCode: ((w = (F = e.slices[0].segments.getLast()) == null ? void 0 : F.destination) == null ? void 0 : w.iataCityCode) || ((o = (p = (d = e.slices[0].segments.getLast()) == null ? void 0 : d.destination) == null ? void 0 : p.city) == null ? void 0 : o.iataCode),
23
+ city: ((t = (o = e.slices[0].segments.getLast()) == null ? void 0 : o.destination) == null ? void 0 : t.cityName) || ((h = (l = (a = e.slices[0].segments.getLast()) == null ? void 0 : a.destination) == null ? void 0 : l.city) == null ? void 0 : h.name),
24
+ country: ((L = (u = e.slices[0].segments.getLast()) == null ? void 0 : u.destination) == null ? void 0 : L.iataCountryCode) || ((N = (M = (A = e.slices[0].segments.getLast()) == null ? void 0 : A.destination) == null ? void 0 : M.city) == null ? void 0 : N.iataCountryCode),
25
+ airportCode: ((w = (F = e.slices[0].segments.getLast()) == null ? void 0 : F.destination) == null ? void 0 : w.iataCityCode) || ((c = (p = (g = e.slices[0].segments.getLast()) == null ? void 0 : g.destination) == null ? void 0 : p.city) == null ? void 0 : c.iataCode),
26
26
  coordinates: {
27
27
  latitude: (b = (C = (y = e.slices[0].segments.getLast()) == null ? void 0 : y.destination) == null ? void 0 : C.city) == null ? void 0 : b.latitude,
28
- longitude: (f = (g = (m = e.slices[0].segments.getLast()) == null ? void 0 : m.destination) == null ? void 0 : g.city) == null ? void 0 : f.longitude
28
+ longitude: (f = (d = (m = e.slices[0].segments.getLast()) == null ? void 0 : m.destination) == null ? void 0 : d.city) == null ? void 0 : f.longitude
29
29
  }
30
30
  },
31
31
  airline: e.owner.name,
32
32
  cash: parseFloat(e.totalAmount),
33
- flightNumber: $(e.slices[0].segments[0]),
33
+ flightNumber: v(e.slices[0].segments[0]),
34
34
  awayzGroupId: e.slices[0].comparisonKey || e.awayzRouteId || e.awayzGroupId || e.id,
35
- departureTime: N(e.slices[0].segments[0].departingAt).toDate(),
36
- arrivalTime: N(
35
+ departureTime: D(e.slices[0].segments[0].departingAt).toDate(),
36
+ arrivalTime: D(
37
37
  e.slices[0].segments[e.slices[0].segments.length - 1].arrivingAt
38
38
  ).toDate(),
39
39
  numberOfStops: e.slices[0].segments.length - 1,
@@ -42,21 +42,21 @@ const T = (r) => r == null ? void 0 : r.map((e) => {
42
42
  airlineProgram: e.airlineProgram,
43
43
  paymentOptions: [],
44
44
  durationMinutes: z({
45
- departureTime: N(e.slices[0].segments[0].departingAt),
46
- arrivalTime: N(e.slices[0].segments.getLast().arrivingAt),
45
+ departureTime: D(e.slices[0].segments[0].departingAt),
46
+ arrivalTime: D(e.slices[0].segments.getLast().arrivingAt),
47
47
  originTimeZone: e.slices[0].segments[0].origin.timeZone,
48
48
  destinationTimeZone: e.slices[0].segments.getLast().destination.timeZone,
49
49
  duration: e.slices[0].duration
50
50
  })
51
51
  };
52
- }), U = (r, e) => {
52
+ }), U = (s, e) => {
53
53
  if (!(e != null && e.length))
54
- return T(r);
54
+ return T(s);
55
55
  const n = [...e];
56
- let s = [];
57
- const t = {};
58
- for (const i of r) {
59
- const a = i.slices[0].segments, l = a[0], h = {
56
+ let r = [];
57
+ const i = {};
58
+ for (const t of s) {
59
+ const a = t.slices[0].segments, l = a[0], h = {
60
60
  iataCode: l.operatingCarrier.iataCode,
61
61
  flightNumber: I(
62
62
  l.operatingCarrierFlightNumber
@@ -66,95 +66,95 @@ const T = (r) => r == null ? void 0 : r.map((e) => {
66
66
  flightNumber: I(
67
67
  l.marketingCarrierFlightNumber
68
68
  )
69
- }, L = i.awayzMatchId, A = `${h.iataCode}_${u.iataCode}-${u.flightNumber}`, M = i.awayzMarketerMatchId, D = !!h.flightNumber && h.flightNumber != "", F = !!u.flightNumber && u.flightNumber != "", w = n.filter((d, p) => {
70
- const o = d.flightDetails, y = d.flightDetails.slices[0].segments[0].operatingCarrierFlightNumber, C = o.id && // TODO: Maybe expand on this - Id check ensures it is a duffel flight
69
+ }, L = t.awayzMatchId, A = `${h.iataCode}_${u.iataCode}-${u.flightNumber}`, M = t.awayzMarketerMatchId, N = !!h.flightNumber && h.flightNumber != "", F = !!u.flightNumber && u.flightNumber != "", w = n.filter((g, p) => {
70
+ const c = g.flightDetails, y = g.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
- if (!(o.slices[0].segments.length === (a == null ? void 0 : a.length) && !o.slices[0].segments.find(
73
- (g, f) => g.departingAt !== a[f].departingAt || g.arrivingAt !== a[f].arrivingAt || g.duration !== a[f].duration
72
+ if (!(c.slices[0].segments.length === (a == null ? void 0 : a.length) && !c.slices[0].segments.find(
73
+ (d, f) => d.departingAt !== a[f].departingAt || d.arrivingAt !== a[f].arrivingAt || d.duration !== a[f].duration
74
74
  )))
75
75
  return !1;
76
76
  let m = !1;
77
- return (F && D && o.awayzMatchId === L || !C && o.awayzMatchId === A || D && !F && o.awayzMarketerMatchId === M) && (m = !0), m && (t[o.id] = p), m;
77
+ return (F && N && c.awayzMatchId === L || !C && c.awayzMatchId === A || N && !F && c.awayzMarketerMatchId === M) && (m = !0), m && (i[c.id] = p), m;
78
78
  });
79
79
  if (w.length) {
80
- i.slices[0].comparisonKey = w[0].awayzGroupId;
81
- const d = w.find((p) => {
82
- var C, b, m, g;
83
- const o = (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 === o || // Special Case for AC Only match on first word
80
+ t.slices[0].comparisonKey = w[0].awayzGroupId;
81
+ const g = w.find((p) => {
82
+ var C, b, m, d;
83
+ const c = (C = p.flightDetails.slices[0].fareBrandName) == null ? void 0 : C.toLowerCase(), y = (b = t.slices[0].fareBrandName) == null ? void 0 : b.toLowerCase();
84
+ return y === c || // Special Case for AC Only match on first word
85
85
  // Due to differences in scraped points data and Duffel format
86
- u.iataCode === "AC" && ((m = y.split(" ")) == null ? void 0 : m[0]) === ((g = o.split(" ")) == null ? void 0 : g[0]);
86
+ u.iataCode === "AC" && ((m = y.split(" ")) == null ? void 0 : m[0]) === ((d = c.split(" ")) == null ? void 0 : d[0]);
87
87
  });
88
- if (d) {
89
- const p = t[d.id], o = {
90
- ...i,
91
- ...d,
92
- points: i.points,
93
- airlineProgram: i.airlineProgram,
88
+ if (g) {
89
+ const p = i[g.id], c = {
90
+ ...t,
91
+ ...g,
92
+ points: t.points,
93
+ airlineProgram: t.airlineProgram,
94
94
  flightDetails: {
95
- ...i,
96
- ...d.flightDetails,
97
- points: i.points,
98
- airlineProgram: i.airlineProgram
95
+ ...t,
96
+ ...g.flightDetails,
97
+ points: t.points,
98
+ airlineProgram: t.airlineProgram
99
99
  }
100
100
  };
101
- n[p] = o;
101
+ n[p] = c;
102
102
  } else
103
- s.push(i);
103
+ r.push(t);
104
104
  } else
105
- s.push(i);
105
+ r.push(t);
106
106
  }
107
107
  return [
108
108
  ...n,
109
- ...T(s) ?? []
109
+ ...T(r) ?? []
110
110
  ];
111
- }, $ = (r) => {
112
- const e = r.operatingCarrierFlightNumber ? r.operatingCarrier : r.marketingCarrier, n = r.operatingCarrierFlightNumber ?? r.marketingCarrierFlightNumber;
111
+ }, v = (s) => {
112
+ const e = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier, n = s.operatingCarrierFlightNumber ?? s.marketingCarrierFlightNumber;
113
113
  return e.iataCode + " " + I(n);
114
114
  }, K = ({
115
- originCode: r,
115
+ originCode: s,
116
116
  destinationCode: e,
117
117
  departureDate: n,
118
- cabinClass: s,
119
- passengerCount: t,
120
- paymentType: c
118
+ cabinClass: r,
119
+ passengerCount: i,
120
+ paymentType: o
121
121
  }) => {
122
- let i = "/flights/search/one-way/points-cash?";
123
- return i += `origin=${r}`, i += `&destination=${e}`, i += `&departure_date=${n}`, i += `&cabin_class=${s}`, i += `&adults=${t}`, i += `&cash_or_points=[${c}]`, i;
124
- }, q = (r) => {
125
- const e = r.reduce((s, t) => {
126
- const c = t.awayzGroupId;
127
- return s[c] || (s[c] = []), s[c].push(t), s;
122
+ let t = "/flights/search/one-way/points-cash?";
123
+ return t += `origin=${s}`, t += `&destination=${e}`, t += `&departure_date=${n}`, t += `&cabin_class=${r}`, t += `&adults=${i}`, t += `&cash_or_points=[${o}]`, t;
124
+ }, j = (s) => {
125
+ const e = s.reduce((r, i) => {
126
+ const o = i.flightDetails.slices[0].segments.map((t) => I(v(t))).join("_");
127
+ return console.log(o), r[o] || (r[o] = []), r[o].push(i), r;
128
128
  }, {});
129
129
  return Object.values(e).map(
130
- (s) => {
131
- const t = s[0], { origin: c, destination: i } = t;
130
+ (r) => {
131
+ const i = r[0], { origin: o, destination: t } = i;
132
132
  return {
133
- id: t.awayzGroupId,
134
- partial: t.partial,
133
+ id: i.awayzGroupId,
134
+ partial: i.partial,
135
135
  origin: {
136
- city: c.city,
137
- country: c.country,
138
- airportCode: c.airportCode,
139
- coordinates: c.coordinates
136
+ city: o.city,
137
+ country: o.country,
138
+ airportCode: o.airportCode,
139
+ coordinates: o.coordinates
140
140
  },
141
141
  destination: {
142
- city: i.city,
143
- country: i.country,
144
- airportCode: i.airportCode,
145
- coordinates: i.coordinates
142
+ city: t.city,
143
+ country: t.country,
144
+ airportCode: t.airportCode,
145
+ coordinates: t.coordinates
146
146
  },
147
- airline: t.airline,
148
- flightNumber: t.flightNumber,
149
- lowestCash: s.reduce(
147
+ airline: i.airline,
148
+ flightNumber: i.flightNumber,
149
+ lowestCash: r.reduce(
150
150
  (a, l) => Math.min(a, l.cash),
151
151
  1 / 0
152
152
  ),
153
- lowestPoints: s.reduce(
153
+ lowestPoints: r.reduce(
154
154
  (a, l) => Math.min(a, l.points),
155
155
  1 / 0
156
156
  ),
157
- paymentOptions: s.map((a) => ({
157
+ paymentOptions: r.map((a) => ({
158
158
  id: a.id,
159
159
  cash: a.cash,
160
160
  points: a.points,
@@ -167,30 +167,30 @@ const T = (r) => r == null ? void 0 : r.map((e) => {
167
167
  changeBeforeDeparture: !0
168
168
  }
169
169
  })),
170
- numberOfStops: t.numberOfStops,
171
- departureTime: t.departureTime,
172
- arrivalTime: t.arrivalTime,
173
- awayzGroupId: t.awayzGroupId,
174
- duration: t.duration,
175
- airlineProgram: t.airlineProgram,
170
+ numberOfStops: i.numberOfStops,
171
+ departureTime: i.departureTime,
172
+ arrivalTime: i.arrivalTime,
173
+ awayzGroupId: i.awayzGroupId,
174
+ duration: i.duration,
175
+ airlineProgram: i.airlineProgram,
176
176
  durationMinutes: z({
177
- departureTime: N(
178
- t.flightDetails.slices[0].segments[0].departingAt
177
+ departureTime: D(
178
+ i.flightDetails.slices[0].segments[0].departingAt
179
179
  ),
180
- arrivalTime: N(
181
- t.flightDetails.slices[0].segments.getLast().arrivingAt
180
+ arrivalTime: D(
181
+ i.flightDetails.slices[0].segments.getLast().arrivingAt
182
182
  ),
183
- originTimeZone: t.flightDetails.slices[0].segments[0].origin.timeZone,
184
- destinationTimeZone: t.flightDetails.slices[0].segments.getLast().destination.timeZone,
185
- duration: t.flightDetails.slices[0].duration
183
+ originTimeZone: i.flightDetails.slices[0].segments[0].origin.timeZone,
184
+ destinationTimeZone: i.flightDetails.slices[0].segments.getLast().destination.timeZone,
185
+ duration: i.flightDetails.slices[0].duration
186
186
  }),
187
- cash: t.cash,
188
- points: t.points,
189
- flightDetails: t.flightDetails
187
+ cash: i.cash,
188
+ points: i.points,
189
+ flightDetails: i.flightDetails
190
190
  };
191
191
  }
192
192
  );
193
- }, I = (r) => r.replace(/^0+/, ""), Q = (r) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${r}.svg`, P = "/img/logo/odynn-eye.svg", k = {
193
+ }, I = (s) => s.replace(/^0+/, ""), q = (s) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${s}.svg`, P = "/img/logo/odynn-eye.svg", k = {
194
194
  categoryLogo: P,
195
195
  programLogo: P,
196
196
  awayzActive: [],
@@ -198,34 +198,34 @@ const T = (r) => r == null ? void 0 : r.map((e) => {
198
198
  displayProgram: "Unknown",
199
199
  id: "Unknown",
200
200
  totalAccumulatedPoints: 0,
201
- category: O.Airline,
201
+ category: _.Airline,
202
202
  colour: "#fff",
203
203
  // Using App Foreground Colour
204
204
  url: "https://www.odynn.com"
205
- }, Y = async (r) => {
206
- const { airlines: e } = await v.ensureQueryData({
205
+ }, Q = async (s) => {
206
+ const { airlines: e } = await O.ensureQueryData({
207
207
  queryKey: ["walletAwards"],
208
208
  queryFn: G.getAwards,
209
209
  staleTime: 864e5
210
210
  // 24 hours
211
211
  });
212
212
  let n = e.find(
213
- (s) => s.mainProgram.toLowerCase().includes(r.toLowerCase()) || s.displayProgram.toLowerCase().includes(r.toLowerCase())
213
+ (r) => r.mainProgram.toLowerCase().includes(s.toLowerCase()) || r.displayProgram.toLowerCase().includes(s.toLowerCase())
214
214
  ) ?? k;
215
215
  return n || (n = {
216
216
  ...k,
217
- mainProgram: r,
218
- displayProgram: r,
219
- id: r
217
+ mainProgram: s,
218
+ displayProgram: s,
219
+ id: s
220
220
  }), n;
221
221
  };
222
222
  export {
223
223
  k as DEFAULT_AIRLINE_PROGRAM,
224
224
  K as buildFlightSearchQuery,
225
- Y as getAirlineProgram,
226
- $ as getFlightNumber,
227
- Q as getLogoPath,
228
- q as groupFlightResults,
225
+ Q as getAirlineProgram,
226
+ v as getFlightNumber,
227
+ q as getLogoPath,
228
+ j as groupFlightResults,
229
229
  T as mapFlightDetailsToResults,
230
230
  U as parseFlightDetails,
231
231
  I as removeLeadingZeros
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"