@odynn/awayz-flights 0.10.16 → 0.10.17

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.
@@ -3,30 +3,30 @@ import "react/jsx-runtime";
3
3
  import { d as q } from "../dateUtils-Cb9VQiIL.js";
4
4
  import "../arrayExtensions-Ce8YopTP.js";
5
5
  import "react";
6
- import { h as C } from "../moment-BGjjqtLQ.js";
6
+ import { h as y } from "../moment-BGjjqtLQ.js";
7
7
  import { EFlightEndpoint as V } from "../constants/endpoints.js";
8
8
  import { mapBaggageType as W } from "../hooks/useFlightSearch/useFlightSearch.types.js";
9
- import { WalletService as J } from "../services/wallet/WalletService.js";
10
- import { ERewardProgramCategories as X } from "../services/wallet/WalletService.types.js";
11
- const f = "https://assets.duffel.com/img/airlines/for-light-background/full-color-lockup/", ye = (s) => s == null ? void 0 : s.map((e) => {
12
- var l, n, c, a, i, u, d, r, o, p, m, g, y, b, F, A, L, w, T, D, P, I, k, O, R, _, v, E, M, N, $, z, G, Z, S, U;
13
- const t = ae(e);
9
+ import { WalletService as f } from "../services/wallet/WalletService.js";
10
+ import { ERewardProgramCategories as J } from "../services/wallet/WalletService.types.js";
11
+ const X = "https://assets.duffel.com/img/airlines/for-light-background/full-color-lockup/", ye = (s) => s == null ? void 0 : s.map((e) => {
12
+ var l, n, c, a, t, u, d, r, o, p, m, C, g, b, F, A, L, T, w, D, P, I, k, O, R, _, v, E, M, N, $, z, G, Z, S, U;
13
+ const i = ae(e);
14
14
  return {
15
15
  id: e.id,
16
16
  points: (e == null ? void 0 : e.points) >= 0 ? e.points : -1,
17
17
  partial: e == null ? void 0 : e.partial,
18
18
  origin: {
19
19
  city: ((l = e.slices[0].segments[0].origin) == null ? void 0 : l.cityName) || ((c = (n = e.slices[0].segments[0].origin) == null ? void 0 : n.city) == null ? void 0 : c.name) || "",
20
- country: ((a = e.slices[0].segments[0].origin) == null ? void 0 : a.iataCountryCode) || ((u = (i = e.slices[0].segments[0].origin) == null ? void 0 : i.city) == null ? void 0 : u.iataCountryCode) || "",
20
+ country: ((a = e.slices[0].segments[0].origin) == null ? void 0 : a.iataCountryCode) || ((u = (t = e.slices[0].segments[0].origin) == null ? void 0 : t.city) == null ? void 0 : u.iataCountryCode) || "",
21
21
  airportCode: ((d = e.slices[0].segments[0].origin) == null ? void 0 : d.iataCode) || ((o = (r = e.slices[0].segments[0].origin) == null ? void 0 : r.city) == null ? void 0 : o.iataCode) || "",
22
22
  coordinates: {
23
23
  latitude: ((m = (p = e.slices[0].segments[0].origin) == null ? void 0 : p.city) == null ? void 0 : m.latitude) || 0,
24
- longitude: ((y = (g = e.slices[0].segments[0].origin) == null ? void 0 : g.city) == null ? void 0 : y.longitude) || 0
24
+ longitude: ((g = (C = e.slices[0].segments[0].origin) == null ? void 0 : C.city) == null ? void 0 : g.longitude) || 0
25
25
  }
26
26
  },
27
27
  destination: {
28
- city: ((F = (b = e.slices[0].segments.getLast()) == null ? void 0 : b.destination) == null ? void 0 : F.cityName) || ((w = (L = (A = e.slices[0].segments.getLast()) == null ? void 0 : A.destination) == null ? void 0 : L.city) == null ? void 0 : w.name) || "",
29
- country: ((D = (T = e.slices[0].segments.getLast()) == null ? void 0 : T.destination) == null ? void 0 : D.iataCountryCode) || ((k = (I = (P = e.slices[0].segments.getLast()) == null ? void 0 : P.destination) == null ? void 0 : I.city) == null ? void 0 : k.iataCountryCode) || "",
28
+ city: ((F = (b = e.slices[0].segments.getLast()) == null ? void 0 : b.destination) == null ? void 0 : F.cityName) || ((T = (L = (A = e.slices[0].segments.getLast()) == null ? void 0 : A.destination) == null ? void 0 : L.city) == null ? void 0 : T.name) || "",
29
+ country: ((D = (w = e.slices[0].segments.getLast()) == null ? void 0 : w.destination) == null ? void 0 : D.iataCountryCode) || ((k = (I = (P = e.slices[0].segments.getLast()) == null ? void 0 : P.destination) == null ? void 0 : I.city) == null ? void 0 : k.iataCountryCode) || "",
30
30
  airportCode: ((R = (O = e.slices[0].segments.getLast()) == null ? void 0 : O.destination) == null ? void 0 : R.iataCode) || ((E = (v = (_ = e.slices[0].segments.getLast()) == null ? void 0 : _.destination) == null ? void 0 : v.city) == null ? void 0 : E.iataCode) || "",
31
31
  coordinates: {
32
32
  latitude: (($ = (N = (M = e.slices[0].segments.getLast()) == null ? void 0 : M.destination) == null ? void 0 : N.city) == null ? void 0 : $.latitude) || 0,
@@ -34,15 +34,15 @@ const f = "https://assets.duffel.com/img/airlines/for-light-background/full-colo
34
34
  }
35
35
  },
36
36
  // `airline` is an existing unqualified field; semantics are display-primary carrier.
37
- airline: (t == null ? void 0 : t.name) ?? "",
38
- airlineLogo: h((t == null ? void 0 : t.iataCode) ?? ""),
39
- displayAirlineIataCode: (t == null ? void 0 : t.iataCode) ?? "",
37
+ airline: (i == null ? void 0 : i.name) ?? "",
38
+ airlineLogo: h((i == null ? void 0 : i.iataCode) ?? ""),
39
+ displayAirlineIataCode: (i == null ? void 0 : i.iataCode) ?? "",
40
40
  cash: e.totalAmount ? parseFloat(e.totalAmount) : 0,
41
41
  currency: e.baseCurrency,
42
42
  flightNumber: ee(e.slices[0].segments[0]),
43
43
  awayzGroupId: e.slices[0].comparisonKey || e.awayzRouteId || e.awayzGroupId || e.id,
44
- departureTime: C(e.slices[0].segments[0].departingAt).toDate(),
45
- arrivalTime: C(
44
+ departureTime: y(e.slices[0].segments[0].departingAt).toDate(),
45
+ arrivalTime: y(
46
46
  e.slices[0].segments[e.slices[0].segments.length - 1].arrivingAt
47
47
  ).toDate(),
48
48
  numberOfStops: e.slices[0].segments.length - 1,
@@ -51,8 +51,8 @@ const f = "https://assets.duffel.com/img/airlines/for-light-background/full-colo
51
51
  airlineProgram: e.airlineProgram,
52
52
  paymentOptions: [],
53
53
  durationMinutes: q({
54
- departureTime: C(e.slices[0].segments[0].departingAt),
55
- arrivalTime: C((S = e.slices[0].segments.getLast()) == null ? void 0 : S.arrivingAt),
54
+ departureTime: y(e.slices[0].segments[0].departingAt),
55
+ arrivalTime: y((S = e.slices[0].segments.getLast()) == null ? void 0 : S.arrivingAt),
56
56
  originTimeZone: e.slices[0].segments[0].origin.timeZone,
57
57
  destinationTimeZone: (U = e.slices[0].segments.getLast()) == null ? void 0 : U.destination.timeZone,
58
58
  duration: e.slices[0].duration
@@ -65,11 +65,11 @@ const f = "https://assets.duffel.com/img/airlines/for-light-background/full-colo
65
65
  lastCachedTime: e.lastCachedTime
66
66
  };
67
67
  }), ee = (s) => {
68
- const e = s.marketingCarrier ?? s.operatingCarrier, t = s.marketingCarrierFlightNumber ?? s.operatingCarrierFlightNumber;
69
- return e.iataCode + " " + H(t);
68
+ const e = s.marketingCarrier ?? s.operatingCarrier, i = s.marketingCarrierFlightNumber ?? s.operatingCarrierFlightNumber;
69
+ return e.iataCode + " " + H(i);
70
70
  }, se = (s) => {
71
- var t;
72
- const e = (t = s == null ? void 0 : s.segments) == null ? void 0 : t[0];
71
+ var i;
72
+ const e = (i = s == null ? void 0 : s.segments) == null ? void 0 : i[0];
73
73
  return (e == null ? void 0 : e.marketingCarrier) ?? (e == null ? void 0 : e.operatingCarrier);
74
74
  }, ae = (s) => {
75
75
  var e;
@@ -77,29 +77,33 @@ const f = "https://assets.duffel.com/img/airlines/for-light-background/full-colo
77
77
  }, he = (s) => !s.operatingCarrier || !s.marketingCarrier ? "" : s.operatingCarrier.iataCode !== s.marketingCarrier.iataCode ? s.operatingCarrier.name : "", be = ({
78
78
  originCode: s,
79
79
  destinationCode: e,
80
- dates: t,
80
+ dates: i,
81
81
  cabinClass: l,
82
82
  passengerCount: n,
83
83
  paymentType: c
84
84
  }) => {
85
85
  let a = `${V.CASH_POINTS_FLIGHT_SEARCH}?`;
86
- return a += `origin=${s}`, a += `&destination=${e}`, a += `&departure_dates=[${t.map((i) => `"${i}"`).join(",")}]`, a += `&cabin_class=${l}`, a += `&adults=${n}`, a += `&cash_or_points=[${c}]`, a;
87
- }, te = (s) => s.flightDetails.slices[0].segments.map((t) => ie(t)).join("_") + "_" + C(s.departureTime).format("YYYYMMDD"), ie = (s) => {
88
- const e = s.operatingCarrier ?? s.marketingCarrier, t = s.operatingCarrierFlightNumber ?? s.marketingCarrierFlightNumber;
89
- return e.iataCode + " " + H(t);
86
+ return a += `origin=${s}`, a += `&destination=${e}`, a += `&departure_dates=[${i.map((t) => `"${t}"`).join(",")}]`, a += `&cabin_class=${l}`, a += `&adults=${n}`, a += `&cash_or_points=[${c}]`, a;
87
+ }, te = (s) => s.flightDetails.slices[0].segments.map((i) => ie(i)).join("_") + "_" + y(s.departureTime).format("YYYYMMDD"), ie = (s) => {
88
+ const e = s.operatingCarrier ?? s.marketingCarrier, i = s.operatingCarrierFlightNumber ?? s.marketingCarrierFlightNumber;
89
+ return e.iataCode + " " + H(i);
90
90
  }, Fe = (s) => s ? s.replace(/[_-]/g, " ").split(" ").map((e) => e.charAt(0).toUpperCase() + e.slice(1).toLowerCase()).join(" ") : "", Ae = (s) => {
91
91
  const e = {};
92
92
  s.forEach((a) => {
93
93
  var u, d;
94
- const i = te(a);
95
- if (e[i]) {
94
+ const t = te(a);
95
+ if (e[t]) {
96
96
  const r = K(a);
97
- e[i].flight.paymentOptions.push(r);
98
- const { lowestCash: o, currency: p, lowestPoints: m, cashFee: g, cacheData: y } = j(e[i].flight.paymentOptions);
99
- e[i].flight.points = m, e[i].flight.cashFee = g, e[i].flight.cash = o, p && (e[i].flight.currency = p), e[i].flight.isCached = y.isCached, e[i].flight.lastCachedTime = y.lastCachedTime;
97
+ e[t].flight.paymentOptions.push(r);
98
+ const { lowestCash: o, currency: p, lowestPoints: m, cashFee: C, cacheData: g } = j(e[t].flight.paymentOptions);
99
+ e[t].flight.points = m, e[t].flight.cashFee = C, e[t].flight.cash = o, p && (e[t].flight.currency = p), e[t].flight.isCached = g.isCached, e[t].flight.lastCachedTime = g.lastCachedTime, g.isCached && !e[t].flight.flightDetails.isCached && (e[t].flight.flightDetails = {
100
+ ...e[t].flight.flightDetails,
101
+ isCached: g.isCached,
102
+ lastCachedTime: g.lastCachedTime
103
+ });
100
104
  } else {
101
105
  const { origin: r, destination: o } = a, p = [K(a)], m = j(p);
102
- e[i] = {
106
+ e[t] = {
103
107
  programs: [],
104
108
  flight: {
105
109
  id: a.awayzGroupId,
@@ -124,14 +128,14 @@ const f = "https://assets.duffel.com/img/airlines/for-light-background/full-colo
124
128
  numberOfStops: a.numberOfStops,
125
129
  departureTime: a.departureTime,
126
130
  arrivalTime: a.arrivalTime,
127
- awayzGroupId: i,
131
+ awayzGroupId: t,
128
132
  duration: a.duration,
129
133
  airlineProgram: a.airlineProgram,
130
134
  durationMinutes: q({
131
- departureTime: C(
135
+ departureTime: y(
132
136
  a.flightDetails.slices[0].segments[0].departingAt
133
137
  ),
134
- arrivalTime: C(
138
+ arrivalTime: y(
135
139
  (u = a.flightDetails.slices[0].segments.getLast()) == null ? void 0 : u.arrivingAt
136
140
  ),
137
141
  originTimeZone: a.flightDetails.slices[0].segments[0].origin.timeZone,
@@ -151,40 +155,40 @@ const f = "https://assets.duffel.com/img/airlines/for-light-background/full-colo
151
155
  }
152
156
  };
153
157
  }
154
- a.airlineProgram && !e[i].programs.includes(a.airlineProgram) && e[i].programs.push(a.airlineProgram);
158
+ a.airlineProgram && !e[t].programs.includes(a.airlineProgram) && e[t].programs.push(a.airlineProgram);
155
159
  });
156
- const t = [];
160
+ const i = [];
157
161
  Object.values(e).forEach((a) => {
158
- const i = a.flight.paymentOptions.filter((r) => r.cash > 0).reduce(
162
+ const t = a.flight.paymentOptions.filter((r) => r.cash > 0).reduce(
159
163
  (r, o) => o.cash < r.cash ? o : r,
160
164
  { cash: 1 / 0, carrier: { name: "", iataCode: "" } }
161
165
  ), u = {
162
166
  iataCode: a.flight.displayAirlineIataCode,
163
167
  name: a.flight.airline
164
- }, d = i.cash !== 1 / 0 ? i.carrier : u;
168
+ }, d = t.cash !== 1 / 0 ? t.carrier : u;
165
169
  a.programs.length > 0 ? a.programs.forEach((r) => {
166
170
  const o = a.flight.paymentOptions.filter(
167
171
  (m) => m.program === r && m.points > 0
168
172
  ), p = o.length > 0 ? Math.min(...o.map((m) => m.points)) : -1;
169
- t.push({
173
+ i.push({
170
174
  ...a.flight,
171
175
  airline: d.name,
172
176
  airlineLogo: h(d.iataCode),
173
177
  displayAirlineIataCode: d.iataCode,
174
178
  airlineProgram: r,
175
- cash: i.cash !== 1 / 0 ? i.cash : -1,
179
+ cash: t.cash !== 1 / 0 ? t.cash : -1,
176
180
  points: p
177
181
  });
178
- }) : t.push({
182
+ }) : i.push({
179
183
  ...a.flight,
180
184
  airline: d.name,
181
185
  airlineLogo: h(d.iataCode),
182
186
  displayAirlineIataCode: d.iataCode,
183
- cash: i.cash !== 1 / 0 ? i.cash : -1
187
+ cash: t.cash !== 1 / 0 ? t.cash : -1
184
188
  });
185
189
  });
186
- const { cashlessResults: l, otherResults: n } = t.reduce(
187
- (a, i) => (i.cash <= 0 && i.points > 0 ? a.cashlessResults.push(i) : i.cash > 0 && a.otherResults.push(i), a),
190
+ const { cashlessResults: l, otherResults: n } = i.reduce(
191
+ (a, t) => (t.cash <= 0 && t.points > 0 ? a.cashlessResults.push(t) : t.cash > 0 && a.otherResults.push(t), a),
188
192
  { cashlessResults: [], otherResults: [] }
189
193
  ), c = [...n];
190
194
  return l.forEach((a) => {
@@ -192,7 +196,7 @@ const f = "https://assets.duffel.com/img/airlines/for-light-background/full-colo
192
196
  (u) => u.awayzGroupId === a.awayzGroupId
193
197
  ) || n.length === 0) && c.push(a);
194
198
  }), c;
195
- }, H = (s) => s ? s.replace(/^0+/, "") : "", Le = (s) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${s}.svg`, h = (s) => `${f}${s}.svg`, B = Y.logoFallbackImageUrl, x = {
199
+ }, H = (s) => s ? s.replace(/^0+/, "") : "", Le = (s) => `https://assets.duffel.com/img/airlines/for-light-background/full-color-logo/${s}.svg`, h = (s) => `${X}${s}.svg`, B = Y.logoFallbackImageUrl, x = {
196
200
  categoryLogo: B,
197
201
  programLogo: B,
198
202
  awayzActive: [],
@@ -200,35 +204,35 @@ const f = "https://assets.duffel.com/img/airlines/for-light-background/full-colo
200
204
  displayProgram: "Unknown",
201
205
  id: "Unknown",
202
206
  totalAccumulatedPoints: 0,
203
- category: X.Airline,
207
+ category: J.Airline,
204
208
  colour: "#fff",
205
209
  // Using App Foreground Colour
206
210
  url: "https://www.odynn.com"
207
- }, we = async (s) => {
211
+ }, Te = async (s) => {
208
212
  const { airlines: e } = await Q.ensureQueryData({
209
213
  queryKey: ["walletAwards"],
210
- queryFn: J.getAwards,
214
+ queryFn: f.getAwards,
211
215
  staleTime: 864e5
212
216
  // 24 hours
213
217
  });
214
- let t = e.find(
218
+ let i = e.find(
215
219
  (l) => {
216
- var n, c, a, i;
217
- return ((c = (n = l.mainProgram) == null ? void 0 : n.toLowerCase()) == null ? void 0 : c.includes(s == null ? void 0 : s.toLowerCase())) || ((i = (a = l.displayProgram) == null ? void 0 : a.toLowerCase()) == null ? void 0 : i.includes(s == null ? void 0 : s.toLowerCase()));
220
+ var n, c, a, t;
221
+ return ((c = (n = l.mainProgram) == null ? void 0 : n.toLowerCase()) == null ? void 0 : c.includes(s == null ? void 0 : s.toLowerCase())) || ((t = (a = l.displayProgram) == null ? void 0 : a.toLowerCase()) == null ? void 0 : t.includes(s == null ? void 0 : s.toLowerCase()));
218
222
  }
219
223
  ) ?? x;
220
- return t || (t = {
224
+ return i || (i = {
221
225
  ...x,
222
226
  mainProgram: s,
223
227
  displayProgram: s,
224
228
  id: s
225
- }), t;
229
+ }), i;
226
230
  }, K = (s) => {
227
- var n, c, a, i, u, d, r, o, p, m;
228
- const e = ((a = (c = (n = s.flightDetails.slices.getFirst()) == null ? void 0 : n.segments.getFirst()) == null ? void 0 : c.passengers.getFirst()) == null ? void 0 : a.baggages) ?? [], t = ((d = (u = (i = s.flightDetails.slices.getFirst()) == null ? void 0 : i.segments.getFirst()) == null ? void 0 : u.passengers.getFirst()) == null ? void 0 : d.cabinClassMarketingName) ?? ((p = (o = (r = s.flightDetails.slices.getFirst()) == null ? void 0 : r.segments.getFirst()) == null ? void 0 : o.passengers.getFirst()) == null ? void 0 : p.cabinClass), l = e.map(
229
- (g) => ({
230
- type: W(g.type),
231
- quantity: g.quantity
231
+ var n, c, a, t, u, d, r, o, p, m;
232
+ const e = ((a = (c = (n = s.flightDetails.slices.getFirst()) == null ? void 0 : n.segments.getFirst()) == null ? void 0 : c.passengers.getFirst()) == null ? void 0 : a.baggages) ?? [], i = ((d = (u = (t = s.flightDetails.slices.getFirst()) == null ? void 0 : t.segments.getFirst()) == null ? void 0 : u.passengers.getFirst()) == null ? void 0 : d.cabinClassMarketingName) ?? ((p = (o = (r = s.flightDetails.slices.getFirst()) == null ? void 0 : r.segments.getFirst()) == null ? void 0 : o.passengers.getFirst()) == null ? void 0 : p.cabinClass), l = e.map(
233
+ (C) => ({
234
+ type: W(C.type),
235
+ quantity: C.quantity
232
236
  })
233
237
  );
234
238
  return {
@@ -238,7 +242,7 @@ const f = "https://assets.duffel.com/img/airlines/for-light-background/full-colo
238
242
  program: s.airlineProgram,
239
243
  baseCurrency: s.flightDetails.baseCurrency,
240
244
  fareBrandName: ((m = s.flightDetails.slices.getFirst()) == null ? void 0 : m.fareBrandName) ?? "",
241
- cabinClass: t,
245
+ cabinClass: i,
242
246
  cashFee: s.cashFee,
243
247
  conditions: s.flightDetails.conditions,
244
248
  baggages: l,
@@ -252,9 +256,9 @@ const f = "https://assets.duffel.com/img/airlines/for-light-background/full-colo
252
256
  };
253
257
  }, j = (s) => {
254
258
  const e = s.filter((a) => a.cash > 0);
255
- let t = { cash: 1 / 0, baseCurrency: "" };
259
+ let i = { cash: 1 / 0, baseCurrency: "" };
256
260
  for (const a of e)
257
- a.cash < t.cash && (t = a);
261
+ a.cash < i.cash && (i = a);
258
262
  const l = [...s].filter(
259
263
  (a) => a.points > 0
260
264
  );
@@ -266,12 +270,12 @@ const f = "https://assets.duffel.com/img/airlines/for-light-background/full-colo
266
270
  };
267
271
  for (const a of l)
268
272
  a.points < n.points && (n = a);
269
- const c = t.cash;
273
+ const c = i.cash;
270
274
  return {
271
275
  lowestCash: c === 1 / 0 ? -1 : c,
272
276
  lowestPoints: n.points === 1 / 0 ? -1 : n.points,
273
277
  cashFee: n.cashFee,
274
- currency: t.baseCurrency === "" ? null : t.baseCurrency,
278
+ currency: i.baseCurrency === "" ? null : i.baseCurrency,
275
279
  cacheData: {
276
280
  isCached: n.isCached ?? !1,
277
281
  lastCachedTime: n.lastCachedTime ?? ""
@@ -286,13 +290,13 @@ const f = "https://assets.duffel.com/img/airlines/for-light-background/full-colo
286
290
  type: "child"
287
291
  /* CHILD */
288
292
  }))
289
- ], Te = (s) => {
290
- const t = {
293
+ ], we = (s) => {
294
+ const i = {
291
295
  adults: (s == null ? void 0 : s.adults) ?? 1,
292
296
  children: (s == null ? void 0 : s.children) ?? 0
293
- }, l = ne(t);
297
+ }, l = ne(i);
294
298
  return {
295
- passengerCount: t.adults + t.children,
299
+ passengerCount: i.adults + i.children,
296
300
  passengerList: l
297
301
  };
298
302
  };
@@ -301,7 +305,7 @@ export {
301
305
  be as buildFlightSearchQuery,
302
306
  ne as buildPassengerArray,
303
307
  Fe as formatCabinClass,
304
- we as getAirlineProgram,
308
+ Te as getAirlineProgram,
305
309
  ee as getFlightNumber,
306
310
  h as getFullLogoPath,
307
311
  Le as getLogoPath,
@@ -310,6 +314,6 @@ export {
310
314
  se as getPrimaryDisplayCarrierForSlice,
311
315
  Ae as groupFlightResults,
312
316
  ye as mapDataToFlightDetails,
313
- Te as passengerValues,
317
+ we as passengerValues,
314
318
  H as removeLeadingZeros
315
319
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.10.16",
3
+ "version": "0.10.17",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"