@odynn/awayz-flights 0.1.22 → 0.1.24

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.
@@ -5,15 +5,15 @@ import { awayzClient as Z } from "@odynn/awayz-auth";
5
5
  import { WalletService as B } from "../services/wallet/WalletService.js";
6
6
  import { ERewardProgramCategories as S } from "../services/wallet/WalletService.types.js";
7
7
  const v = (s) => s == null ? void 0 : s.map((e) => {
8
- var n, a, i, c, t, l, d, r, m, L, A, M, N, F, w, u, y, o, C, h, b, g, p, f, T, k, P, z;
8
+ var o, a, t, n, i, l, d, r, m, L, A, M, N, F, w, u, y, c, C, h, b, g, p, f, T, k, P, z;
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 || ((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 || ((c = (i = e.slices[0].segments[0].origin) == null ? void 0 : i.city) == null ? void 0 : c.iataCountryCode),
16
- airportCode: e.slices[0].segments[0].origin.iataCityCode || ((t = e.slices[0].segments[0].origin.city) == null ? void 0 : t.iataCode),
14
+ city: e.slices[0].segments[0].origin.cityName || ((a = (o = e.slices[0].segments[0].origin) == null ? void 0 : o.city) == null ? void 0 : a.name),
15
+ country: e.slices[0].segments[0].origin.iataCountryCode || ((n = (t = e.slices[0].segments[0].origin) == null ? void 0 : t.city) == null ? void 0 : n.iataCountryCode),
16
+ airportCode: e.slices[0].segments[0].origin.iataCityCode || ((i = e.slices[0].segments[0].origin.city) == null ? void 0 : i.iataCode),
17
17
  coordinates: {
18
18
  latitude: (l = e.slices[0].segments[0].origin.city) == null ? void 0 : l.latitude,
19
19
  longitude: (d = e.slices[0].segments[0].origin.city) == null ? void 0 : d.longitude
@@ -22,7 +22,7 @@ const v = (s) => s == null ? void 0 : s.map((e) => {
22
22
  destination: {
23
23
  city: ((m = (r = e.slices[0].segments.getLast()) == null ? void 0 : r.destination) == null ? void 0 : m.cityName) || ((M = (A = (L = e.slices[0].segments.getLast()) == null ? void 0 : L.destination) == null ? void 0 : A.city) == null ? void 0 : M.name),
24
24
  country: ((F = (N = e.slices[0].segments.getLast()) == null ? void 0 : N.destination) == null ? void 0 : F.iataCountryCode) || ((y = (u = (w = e.slices[0].segments.getLast()) == null ? void 0 : w.destination) == null ? void 0 : u.city) == null ? void 0 : y.iataCountryCode),
25
- airportCode: ((C = (o = e.slices[0].segments.getLast()) == null ? void 0 : o.destination) == null ? void 0 : C.iataCityCode) || ((g = (b = (h = e.slices[0].segments.getLast()) == null ? void 0 : h.destination) == null ? void 0 : b.city) == null ? void 0 : g.iataCode),
25
+ airportCode: ((C = (c = e.slices[0].segments.getLast()) == null ? void 0 : c.destination) == null ? void 0 : C.iataCityCode) || ((g = (b = (h = e.slices[0].segments.getLast()) == null ? void 0 : h.destination) == null ? void 0 : b.city) == null ? void 0 : g.iataCode),
26
26
  coordinates: {
27
27
  latitude: (T = (f = (p = e.slices[0].segments.getLast()) == null ? void 0 : p.destination) == null ? void 0 : f.city) == null ? void 0 : T.latitude,
28
28
  longitude: (z = (P = (k = e.slices[0].segments.getLast()) == null ? void 0 : k.destination) == null ? void 0 : P.city) == null ? void 0 : z.longitude
@@ -52,11 +52,11 @@ const v = (s) => s == null ? void 0 : s.map((e) => {
52
52
  }), Q = (s, e) => {
53
53
  if (!(e != null && e.length))
54
54
  return v(s);
55
- const n = [...e];
55
+ const o = [...e];
56
56
  let a = [];
57
- const i = {};
58
- for (const t of s) {
59
- const l = t.slices[0].segments, d = l[0], r = {
57
+ const t = {};
58
+ for (const i of s) {
59
+ const l = i.slices[0].segments, d = l[0], r = {
60
60
  iataCode: d.operatingCarrier.iataCode,
61
61
  flightNumber: I(
62
62
  d.operatingCarrierFlightNumber
@@ -66,86 +66,86 @@ const v = (s) => s == null ? void 0 : s.map((e) => {
66
66
  flightNumber: I(
67
67
  d.marketingCarrierFlightNumber
68
68
  )
69
- }, L = t.awayzMatchId, A = `${r.iataCode}_${m.iataCode}-${m.flightNumber}`, M = t.awayzMarketerMatchId, N = !!r.flightNumber && r.flightNumber != "", F = !!m.flightNumber && m.flightNumber != "", w = n.filter((u, y) => {
70
- const o = u.flightDetails, C = u.flightDetails.slices[0].segments[0].operatingCarrierFlightNumber, h = o.id && // TODO: Maybe expand on this - Id check ensures it is a duffel flight
69
+ }, L = i.awayzMatchId, A = `${r.iataCode}_${m.iataCode}-${m.flightNumber}`, M = i.awayzMarketerMatchId, N = !!r.flightNumber && r.flightNumber != "", F = !!m.flightNumber && m.flightNumber != "", w = o.filter((u, y) => {
70
+ const c = u.flightDetails, C = u.flightDetails.slices[0].segments[0].operatingCarrierFlightNumber, h = c.id && // TODO: Maybe expand on this - Id check ensures it is a duffel flight
71
71
  !!C && C !== "";
72
- if (!(o.slices[0].segments.length === (l == null ? void 0 : l.length) && !o.slices[0].segments.find(
72
+ if (!(c.slices[0].segments.length === (l == null ? void 0 : l.length) && !c.slices[0].segments.find(
73
73
  (p, f) => p.departingAt !== l[f].departingAt || p.arrivingAt !== l[f].arrivingAt || p.duration !== l[f].duration
74
74
  )))
75
75
  return !1;
76
76
  let g = !1;
77
- return (F && N && o.awayzMatchId === L || !h && o.awayzMatchId === A || N && !F && o.awayzMarketerMatchId === M) && (g = !0), g && (i[o.id] = y), g;
77
+ return (F && N && c.awayzMatchId === L || !h && c.awayzMatchId === A || N && !F && c.awayzMarketerMatchId === M) && (g = !0), g && (t[c.id] = y), g;
78
78
  });
79
79
  if (w.length) {
80
- t.slices[0].comparisonKey = w[0].awayzGroupId;
80
+ i.slices[0].comparisonKey = w[0].awayzGroupId;
81
81
  const u = w.find((y) => {
82
82
  var h, b, g, p;
83
- const o = (h = y.flightDetails.slices[0].fareBrandName) == null ? void 0 : h.toLowerCase(), C = (b = t.slices[0].fareBrandName) == null ? void 0 : b.toLowerCase();
84
- return C === o || // Special Case for AC Only match on first word
83
+ const c = (h = y.flightDetails.slices[0].fareBrandName) == null ? void 0 : h.toLowerCase(), C = (b = i.slices[0].fareBrandName) == null ? void 0 : b.toLowerCase();
84
+ return C === c || // Special Case for AC Only match on first word
85
85
  // Due to differences in scraped points data and Duffel format
86
- m.iataCode === "AC" && ((g = C.split(" ")) == null ? void 0 : g[0]) === ((p = o.split(" ")) == null ? void 0 : p[0]);
86
+ m.iataCode === "AC" && ((g = C.split(" ")) == null ? void 0 : g[0]) === ((p = c.split(" ")) == null ? void 0 : p[0]);
87
87
  });
88
88
  if (u) {
89
- const y = i[u.id], o = {
90
- ...t,
89
+ const y = t[u.id], c = {
90
+ ...i,
91
91
  ...u,
92
- points: t.points,
93
- airlineProgram: t.airlineProgram,
92
+ points: i.points,
93
+ airlineProgram: i.airlineProgram,
94
94
  flightDetails: {
95
- ...t,
95
+ ...i,
96
96
  ...u.flightDetails,
97
- points: t.points,
98
- airlineProgram: t.airlineProgram
97
+ points: i.points,
98
+ airlineProgram: i.airlineProgram
99
99
  }
100
100
  };
101
- n[y] = o;
101
+ o[y] = c;
102
102
  } else
103
- a.push(t);
103
+ a.push(i);
104
104
  } else
105
- a.push(t);
105
+ a.push(i);
106
106
  }
107
107
  return [
108
- ...n,
108
+ ...o,
109
109
  ...v(a) ?? []
110
110
  ];
111
111
  }, $ = (s) => {
112
- const e = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier, n = s.operatingCarrierFlightNumber ?? s.marketingCarrierFlightNumber;
113
- return e.iataCode + " " + I(n);
112
+ const e = s.operatingCarrierFlightNumber ? s.operatingCarrier : s.marketingCarrier, o = s.operatingCarrierFlightNumber ?? s.marketingCarrierFlightNumber;
113
+ return e.iataCode + " " + I(o);
114
114
  }, Y = ({
115
115
  originCode: s,
116
116
  destinationCode: e,
117
- departureDate: n,
117
+ departureDate: o,
118
118
  cabinClass: a,
119
- passengerCount: i,
120
- paymentType: c
119
+ passengerCount: t,
120
+ paymentType: n
121
121
  }) => {
122
- let t = "/flights/search/one-way/points-cash?";
123
- return t += `origin=${s}`, t += `&destination=${e}`, t += `&departure_date=${n}`, t += `&cabin_class=${a}`, t += `&adults=${i}`, t += `&cash_or_points=[${c}]`, t;
122
+ let i = "/flights/search/one-way/points-cash?";
123
+ return i += `origin=${s}`, i += `&destination=${e}`, i += `&departure_date=${o}`, i += `&cabin_class=${a}`, i += `&adults=${t}`, i += `&cash_or_points=[${n}]`, i;
124
124
  }, x = (s) => {
125
- const e = s.reduce((a, i) => {
126
- const c = i.flightDetails.slices[0].segments.map((t) => I($(t))).join("_");
127
- return a[c] || (a[c] = []), a[c].push(i), a;
125
+ const e = s.reduce((a, t) => {
126
+ const n = t.flightDetails.slices[0].segments.map((i) => I($(i))).join("_");
127
+ return a[n] || (a[n] = []), a[n].push(t), a;
128
128
  }, {});
129
129
  return Object.values(e).map(
130
130
  (a) => {
131
- const i = a[0], { origin: c, destination: t } = i, l = a.filter((r) => r.cash > 0).reduce((r, m) => Math.min(r, m.cash), 1 / 0), d = a.filter((r) => r.points > 0).reduce((r, m) => Math.min(r, m.points), 1 / 0);
131
+ const t = a[0], { origin: n, destination: i } = t, l = a.filter((r) => r.cash > 0).reduce((r, m) => Math.min(r, m.cash), 1 / 0), d = a.filter((r) => r.points > 0).reduce((r, m) => Math.min(r, m.points), 1 / 0);
132
132
  return {
133
- id: i.awayzGroupId,
134
- partial: i.partial,
133
+ id: t.awayzGroupId,
134
+ partial: t.partial,
135
135
  origin: {
136
- city: c.city,
137
- country: c.country,
138
- airportCode: c.airportCode,
139
- coordinates: c.coordinates
136
+ city: n.city,
137
+ country: n.country,
138
+ airportCode: n.airportCode,
139
+ coordinates: n.coordinates
140
140
  },
141
141
  destination: {
142
- city: t.city,
143
- country: t.country,
144
- airportCode: t.airportCode,
145
- coordinates: t.coordinates
142
+ city: i.city,
143
+ country: i.country,
144
+ airportCode: i.airportCode,
145
+ coordinates: i.coordinates
146
146
  },
147
- airline: i.airline,
148
- flightNumber: i.flightNumber,
147
+ airline: t.airline,
148
+ flightNumber: t.flightNumber,
149
149
  paymentOptions: a.map((r) => ({
150
150
  id: r.id,
151
151
  cash: r.cash,
@@ -165,26 +165,26 @@ const v = (s) => s == null ? void 0 : s.map((e) => {
165
165
  name: r.flightDetails.slices[0].segments[0].marketingCarrier.name
166
166
  }
167
167
  })),
168
- numberOfStops: i.numberOfStops,
169
- departureTime: i.departureTime,
170
- arrivalTime: i.arrivalTime,
171
- awayzGroupId: i.awayzGroupId,
172
- duration: i.duration,
173
- airlineProgram: i.airlineProgram,
168
+ numberOfStops: t.numberOfStops,
169
+ departureTime: t.departureTime,
170
+ arrivalTime: t.arrivalTime,
171
+ awayzGroupId: t.awayzGroupId,
172
+ duration: t.duration,
173
+ airlineProgram: t.airlineProgram,
174
174
  durationMinutes: _({
175
175
  departureTime: D(
176
- i.flightDetails.slices[0].segments[0].departingAt
176
+ t.flightDetails.slices[0].segments[0].departingAt
177
177
  ),
178
178
  arrivalTime: D(
179
- i.flightDetails.slices[0].segments.getLast().arrivingAt
179
+ t.flightDetails.slices[0].segments.getLast().arrivingAt
180
180
  ),
181
- originTimeZone: i.flightDetails.slices[0].segments[0].origin.timeZone,
182
- destinationTimeZone: i.flightDetails.slices[0].segments.getLast().destination.timeZone,
183
- duration: i.flightDetails.slices[0].duration
181
+ originTimeZone: t.flightDetails.slices[0].segments[0].origin.timeZone,
182
+ destinationTimeZone: t.flightDetails.slices[0].segments.getLast().destination.timeZone,
183
+ duration: t.flightDetails.slices[0].duration
184
184
  }),
185
185
  cash: l === 1 / 0 ? -1 : l,
186
186
  points: d === 1 / 0 ? -1 : d,
187
- flightDetails: i.flightDetails
187
+ flightDetails: t.flightDetails
188
188
  };
189
189
  }
190
190
  );
@@ -207,15 +207,18 @@ const v = (s) => s == null ? void 0 : s.map((e) => {
207
207
  staleTime: 864e5
208
208
  // 24 hours
209
209
  });
210
- let n = e.find(
211
- (a) => a.mainProgram.toLowerCase().includes(s.toLowerCase()) || a.displayProgram.toLowerCase().includes(s.toLowerCase())
210
+ let o = e.find(
211
+ (a) => {
212
+ var t, n;
213
+ return ((t = a.mainProgram) == null ? void 0 : t.toLowerCase().includes(s.toLowerCase())) || ((n = a.displayProgram) == null ? void 0 : n.toLowerCase().includes(s.toLowerCase()));
214
+ }
212
215
  ) ?? G;
213
- return n || (n = {
216
+ return o || (o = {
214
217
  ...G,
215
218
  mainProgram: s,
216
219
  displayProgram: s,
217
220
  id: s
218
- }), n;
221
+ }), o;
219
222
  };
220
223
  export {
221
224
  G as DEFAULT_AIRLINE_PROGRAM,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"