@odynn/awayz-flights 0.1.17 → 0.1.19

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
  };
@@ -87,6 +87,10 @@ export interface IFlightPaymentOption {
87
87
  refundBeforeDeparture?: boolean;
88
88
  changeBeforeDeparture?: boolean;
89
89
  };
90
+ carrier: {
91
+ iataCode: string;
92
+ name: string;
93
+ };
90
94
  }
91
95
  export interface IFlightResult {
92
96
  id: string;
@@ -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";
6
+ import { ERewardProgramCategories as _ } from "../services/wallet/WalletService.types.js";
7
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;
8
+ var n, a, i, l, t, s, o, h, u, L, M, A, N, F, w, d, p, c, y, C, b, m, g, 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 || ((a = (n = e.slices[0].segments[0].origin) == null ? void 0 : n.city) == null ? void 0 : a.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,9 +20,9 @@ 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 = (l = e.slices[0].segments.getLast()) == null ? void 0 : l.destination) == null ? void 0 : t.cityName) || ((h = (o = (s = e.slices[0].segments.getLast()) == null ? void 0 : s.destination) == null ? void 0 : o.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 = (A = (M = e.slices[0].segments.getLast()) == null ? void 0 : M.destination) == null ? void 0 : A.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 = (d = e.slices[0].segments.getLast()) == null ? void 0 : d.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
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
@@ -30,10 +30,10 @@ const T = (r) => r == null ? void 0 : r.map((e) => {
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,8 +42,8 @@ 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
@@ -53,179 +53,191 @@ const T = (r) => r == null ? void 0 : r.map((e) => {
53
53
  if (!(e != null && e.length))
54
54
  return T(r);
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 = {
60
- iataCode: l.operatingCarrier.iataCode,
56
+ let a = [];
57
+ const i = {};
58
+ for (const t of r) {
59
+ const s = t.slices[0].segments, o = s[0], h = {
60
+ iataCode: o.operatingCarrier.iataCode,
61
61
  flightNumber: I(
62
- l.operatingCarrierFlightNumber
62
+ o.operatingCarrierFlightNumber
63
63
  )
64
64
  }, u = {
65
- iataCode: l.marketingCarrier.iataCode,
65
+ iataCode: o.marketingCarrier.iataCode,
66
66
  flightNumber: I(
67
- l.marketingCarrierFlightNumber
67
+ o.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, M = `${h.iataCode}_${u.iataCode}-${u.flightNumber}`, A = t.awayzMarketerMatchId, N = !!h.flightNumber && h.flightNumber != "", F = !!u.flightNumber && u.flightNumber != "", w = n.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
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 === (s == null ? void 0 : s.length) && !c.slices[0].segments.find(
73
+ (g, f) => g.departingAt !== s[f].departingAt || g.arrivingAt !== s[f].arrivingAt || g.duration !== s[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 === M || N && !F && c.awayzMarketerMatchId === A) && (m = !0), m && (i[c.id] = p), m;
78
78
  });
79
79
  if (w.length) {
80
- i.slices[0].comparisonKey = w[0].awayzGroupId;
80
+ t.slices[0].comparisonKey = w[0].awayzGroupId;
81
81
  const d = w.find((p) => {
82
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
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]) === ((g = c.split(" ")) == null ? void 0 : g[0]);
87
87
  });
88
88
  if (d) {
89
- const p = t[d.id], o = {
90
- ...i,
89
+ const p = i[d.id], c = {
90
+ ...t,
91
91
  ...d,
92
- points: i.points,
93
- airlineProgram: i.airlineProgram,
92
+ points: t.points,
93
+ airlineProgram: t.airlineProgram,
94
94
  flightDetails: {
95
- ...i,
95
+ ...t,
96
96
  ...d.flightDetails,
97
- points: i.points,
98
- airlineProgram: i.airlineProgram
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
+ a.push(t);
104
104
  } else
105
- s.push(i);
105
+ a.push(t);
106
106
  }
107
107
  return [
108
108
  ...n,
109
- ...T(s) ?? []
109
+ ...T(a) ?? []
110
110
  ];
111
- }, $ = (r) => {
111
+ }, v = (r) => {
112
112
  const e = r.operatingCarrierFlightNumber ? r.operatingCarrier : r.marketingCarrier, n = r.operatingCarrierFlightNumber ?? r.marketingCarrierFlightNumber;
113
113
  return e.iataCode + " " + I(n);
114
114
  }, K = ({
115
115
  originCode: r,
116
116
  destinationCode: e,
117
117
  departureDate: n,
118
- cabinClass: s,
119
- passengerCount: t,
120
- paymentType: c
118
+ cabinClass: a,
119
+ passengerCount: i,
120
+ paymentType: l
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=${r}`, t += `&destination=${e}`, t += `&departure_date=${n}`, t += `&cabin_class=${a}`, t += `&adults=${i}`, t += `&cash_or_points=[${l}]`, t;
124
+ }, j = (r) => {
125
+ const e = r.reduce((a, i) => {
126
+ const l = i.flightDetails.slices[0].segments.map((t) => I(v(t))).join("_");
127
+ return a[l] || (a[l] = []), a[l].push(i), a;
128
128
  }, {});
129
129
  return Object.values(e).map(
130
- (s) => {
131
- const t = s[0], { origin: c, destination: i } = t;
130
+ (a) => {
131
+ const i = a[0], { origin: l, 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: l.city,
137
+ country: l.country,
138
+ airportCode: l.airportCode,
139
+ coordinates: l.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(
150
- (a, l) => Math.min(a, l.cash),
147
+ airline: i.airline,
148
+ flightNumber: i.flightNumber,
149
+ lowestCash: a.reduce(
150
+ (s, o) => Math.min(s, o.cash),
151
151
  1 / 0
152
152
  ),
153
- lowestPoints: s.reduce(
154
- (a, l) => Math.min(a, l.points),
153
+ lowestPoints: a.reduce(
154
+ (s, o) => Math.min(s, o.points),
155
155
  1 / 0
156
156
  ),
157
- paymentOptions: s.map((a) => ({
158
- id: a.id,
159
- cash: a.cash,
160
- points: a.points,
161
- cashFeeCurrency: a.flightDetails.baseCurrency,
157
+ paymentOptions: a.map((s) => ({
158
+ id: s.id,
159
+ cash: s.cash,
160
+ points: s.points,
161
+ cashFeeCurrency: s.flightDetails.baseCurrency,
162
+ //TODO: Add Cash Fee Amount
162
163
  cashFeeAmount: 0,
163
- baseCurrency: a.flightDetails.baseCurrency,
164
- fareBrandName: a.flightDetails.slices[0].fareBrandName,
164
+ baseCurrency: s.flightDetails.baseCurrency,
165
+ fareBrandName: s.flightDetails.slices[0].fareBrandName,
165
166
  conditions: {
167
+ //TODO: Add Refund and Change Conditions
166
168
  refundBeforeDeparture: !0,
167
169
  changeBeforeDeparture: !0
170
+ },
171
+ carrier: {
172
+ iataCode: s.flightDetails.slices[0].segments[0].marketingCarrier.iataCode,
173
+ name: s.flightDetails.slices[0].segments[0].marketingCarrier.name
168
174
  }
169
175
  })),
170
- numberOfStops: t.numberOfStops,
171
- departureTime: t.departureTime,
172
- arrivalTime: t.arrivalTime,
173
- awayzGroupId: t.awayzGroupId,
174
- duration: t.duration,
175
- airlineProgram: t.airlineProgram,
176
+ numberOfStops: i.numberOfStops,
177
+ departureTime: i.departureTime,
178
+ arrivalTime: i.arrivalTime,
179
+ awayzGroupId: i.awayzGroupId,
180
+ duration: i.duration,
181
+ airlineProgram: i.airlineProgram,
176
182
  durationMinutes: z({
177
- departureTime: N(
178
- t.flightDetails.slices[0].segments[0].departingAt
183
+ departureTime: D(
184
+ i.flightDetails.slices[0].segments[0].departingAt
179
185
  ),
180
- arrivalTime: N(
181
- t.flightDetails.slices[0].segments.getLast().arrivingAt
186
+ arrivalTime: D(
187
+ i.flightDetails.slices[0].segments.getLast().arrivingAt
182
188
  ),
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
189
+ originTimeZone: i.flightDetails.slices[0].segments[0].origin.timeZone,
190
+ destinationTimeZone: i.flightDetails.slices[0].segments.getLast().destination.timeZone,
191
+ duration: i.flightDetails.slices[0].duration
186
192
  }),
187
- cash: t.cash,
188
- points: t.points,
189
- flightDetails: t.flightDetails
193
+ cash: a.reduce(
194
+ (s, o) => Math.min(s, o.cash),
195
+ 1 / 0
196
+ ),
197
+ points: a.reduce(
198
+ (s, o) => Math.min(s, o.points),
199
+ 1 / 0
200
+ ),
201
+ flightDetails: i.flightDetails
190
202
  };
191
203
  }
192
204
  );
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 = {
194
- categoryLogo: P,
195
- programLogo: P,
205
+ }, I = (r) => r.replace(/^0+/, ""), q = (r) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${r}.svg`, k = "/img/logo/odynn-eye.svg", P = {
206
+ categoryLogo: k,
207
+ programLogo: k,
196
208
  awayzActive: [],
197
209
  mainProgram: "Unknown",
198
210
  displayProgram: "Unknown",
199
211
  id: "Unknown",
200
212
  totalAccumulatedPoints: 0,
201
- category: O.Airline,
213
+ category: _.Airline,
202
214
  colour: "#fff",
203
215
  // Using App Foreground Colour
204
216
  url: "https://www.odynn.com"
205
- }, Y = async (r) => {
206
- const { airlines: e } = await v.ensureQueryData({
217
+ }, Q = async (r) => {
218
+ const { airlines: e } = await O.ensureQueryData({
207
219
  queryKey: ["walletAwards"],
208
220
  queryFn: G.getAwards,
209
221
  staleTime: 864e5
210
222
  // 24 hours
211
223
  });
212
224
  let n = e.find(
213
- (s) => s.mainProgram.toLowerCase().includes(r.toLowerCase()) || s.displayProgram.toLowerCase().includes(r.toLowerCase())
214
- ) ?? k;
225
+ (a) => a.mainProgram.toLowerCase().includes(r.toLowerCase()) || a.displayProgram.toLowerCase().includes(r.toLowerCase())
226
+ ) ?? P;
215
227
  return n || (n = {
216
- ...k,
228
+ ...P,
217
229
  mainProgram: r,
218
230
  displayProgram: r,
219
231
  id: r
220
232
  }), n;
221
233
  };
222
234
  export {
223
- k as DEFAULT_AIRLINE_PROGRAM,
235
+ P as DEFAULT_AIRLINE_PROGRAM,
224
236
  K as buildFlightSearchQuery,
225
- Y as getAirlineProgram,
226
- $ as getFlightNumber,
227
- Q as getLogoPath,
228
- q as groupFlightResults,
237
+ Q as getAirlineProgram,
238
+ v as getFlightNumber,
239
+ q as getLogoPath,
240
+ j as groupFlightResults,
229
241
  T as mapFlightDetailsToResults,
230
242
  U as parseFlightDetails,
231
243
  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.19",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"