@odynn/awayz-flights 0.1.14 → 0.1.15

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,41 +1,49 @@
1
- import { useState as n } from "react";
1
+ import { useState as d } from "react";
2
2
  import { useMutation as u } from "@tanstack/react-query";
3
- import { ECabinClass as C, EFlightType as d } from "../../types/enums.js";
3
+ import { ECabinClass as C, EFlightType as c } from "../../types/enums.js";
4
4
  import { F as a, c as D } from "../../FlightsService-DddArKLm.js";
5
5
  import { parseFlightDetails as _, groupFlightResults as N } from "../../utils/flightUtils.js";
6
6
  import "../../arrayExtensions-DWKenJCh.js";
7
- const P = 1, v = C.ECONOMY, A = (t) => {
8
- if (!t.origin || !t.destination)
7
+ import P from "../../stores/useFlightStore.js";
8
+ const v = 1, A = C.ECONOMY, M = (s) => {
9
+ if (!s.origin || !s.destination)
9
10
  throw new Error("Origin and destination are required.");
10
- if (!t.departureDate)
11
+ if (!s.departureDate)
11
12
  throw new Error("Departure date is required.");
12
- if (t.flightType === d.ROUND_TRIP && !t.returnDate)
13
+ if (s.flightType === c.ROUND_TRIP && !s.returnDate)
13
14
  throw new Error("Return date is required for round-trip flights.");
14
- }, z = () => {
15
- const [t, c] = n(""), [f, l] = n(""), [p, h] = n([]), [b, R] = n([]), [g, m] = n([]), i = ({
15
+ }, G = () => {
16
+ const [s, f] = d(""), [l, p] = d([]), {
17
+ inboundResults: h,
18
+ outboundResults: b,
19
+ setInboundResults: g,
20
+ setOutboundResults: m,
21
+ partialOfferRequestId: n,
22
+ setPartialOfferRequestId: R
23
+ } = P(), i = ({
16
24
  data: r,
17
- previousResults: s,
25
+ previousResults: t,
18
26
  inbound: o
19
27
  }) => {
20
- const e = _(r, s);
21
- return (o ? R : h)(N(e)), e;
28
+ const e = _(r, t);
29
+ return (o ? g : m)(N(e)), e;
22
30
  }, {
23
31
  mutate: O,
24
- status: E,
25
- error: F
32
+ status: F,
33
+ error: E
26
34
  } = u({
27
35
  mutationFn: async (r) => {
28
- A(r);
36
+ M(r);
29
37
  const o = {
30
38
  passengers: Array.from(
31
- { length: r.passengers ?? P },
39
+ { length: r.passengers ?? v },
32
40
  () => ({ type: "adult" })
33
41
  ),
34
42
  origin: r.origin || "",
35
43
  destination: r.destination || "",
36
- cabin_class: r.cabinClass || v
44
+ cabin_class: r.cabinClass || A
37
45
  };
38
- if (r.flightType === d.ONE_WAY) {
46
+ if (r.flightType === c.ONE_WAY) {
39
47
  const e = await a.cashOnlySearch({
40
48
  ...o,
41
49
  departure_date: r.departureDate
@@ -59,12 +67,12 @@ const P = 1, v = C.ECONOMY, A = (t) => {
59
67
  },
60
68
  onSuccess: (r) => {
61
69
  console.log({ result: r });
62
- const { success: s, data: o, partialOfferRequestId: e } = r;
63
- if (!s) {
70
+ const { success: t, data: o, partialOfferRequestId: e } = r;
71
+ if (!t) {
64
72
  console.log("oh lol, it didn't work");
65
73
  return;
66
74
  }
67
- i({ data: o }), e && c(e);
75
+ i({ data: o }), e && R(e);
68
76
  },
69
77
  onError: (r) => {
70
78
  console.error("Error in outbound flight search:", r);
@@ -75,16 +83,16 @@ const P = 1, v = C.ECONOMY, A = (t) => {
75
83
  error: S
76
84
  } = u({
77
85
  mutationFn: async (r) => {
78
- if (!t)
86
+ if (!n)
79
87
  throw new Error("No partialOfferRequestId found for inbound search.");
80
- return l(r), await a.roundTripInboundSearch({
88
+ return f(r), await a.roundTripInboundSearch({
81
89
  outboundOfferId: r,
82
- outboundOfferRequestId: t
90
+ outboundOfferRequestId: n
83
91
  });
84
92
  },
85
93
  onSuccess: (r) => {
86
- const { success: s, data: o } = r;
87
- s && i({
94
+ const { success: t, data: o } = r;
95
+ t && i({
88
96
  data: o.offers,
89
97
  inbound: !0
90
98
  });
@@ -98,34 +106,34 @@ const P = 1, v = C.ECONOMY, A = (t) => {
98
106
  error: y
99
107
  } = u({
100
108
  mutationFn: async (r) => {
101
- if (!t)
109
+ if (!n)
102
110
  throw new Error("No partialOfferRequestId found for round-trip fares.");
103
111
  return await a.getRoundTripFares({
104
- outboundOfferId: f,
105
- outboundOfferRequestId: t,
112
+ outboundOfferId: s,
113
+ outboundOfferRequestId: n,
106
114
  inboundOfferId: r
107
115
  });
108
116
  },
109
117
  onSuccess: (r) => {
110
- const { success: s, data: o } = r;
111
- if (!s) return;
118
+ const { success: t, data: o } = r;
119
+ if (!t) return;
112
120
  const e = o.offers;
113
- m(D(e));
121
+ p(D(e));
114
122
  },
115
123
  onError: (r) => {
116
124
  console.error("Error in round-trip fare search:", r);
117
125
  }
118
126
  });
119
127
  return {
120
- loading: E === "pending" || I === "pending",
128
+ loading: F === "pending" || I === "pending",
121
129
  loadingFares: q === "pending",
122
- outboundError: F,
130
+ outboundError: E,
123
131
  inboundError: S,
124
132
  roundTripFaresError: y,
125
133
  // Results
126
- outboundResults: p,
127
- inboundResults: b,
128
- roundTripFares: g,
134
+ outboundResults: b,
135
+ inboundResults: h,
136
+ roundTripFares: l,
129
137
  // Mutation triggers
130
138
  searchOutboundFlights: O,
131
139
  searchInboundFlights: w,
@@ -133,5 +141,5 @@ const P = 1, v = C.ECONOMY, A = (t) => {
133
141
  };
134
142
  };
135
143
  export {
136
- z as useFlightSearch
144
+ G as useFlightSearch
137
145
  };
@@ -0,0 +1,11 @@
1
+ import { IFlightResult } from '../hooks/useFlightSearch/useFlightSearch.types';
2
+ interface IFlightStore {
3
+ outboundResults: IFlightResult[];
4
+ inboundResults: IFlightResult[];
5
+ setOutboundResults: (outboundResults: IFlightResult[]) => void;
6
+ setInboundResults: (inboundResults: IFlightResult[]) => void;
7
+ partialOfferRequestId: string;
8
+ setPartialOfferRequestId: (partialOfferRequestId: string) => void;
9
+ }
10
+ declare const useFlightStore: import('zustand').UseBoundStore<import('zustand').StoreApi<IFlightStore>>;
11
+ export default useFlightStore;
@@ -0,0 +1,34 @@
1
+ import i from "react";
2
+ const d = (e) => {
3
+ let t;
4
+ const s = /* @__PURE__ */ new Set(), c = (n, a) => {
5
+ const o = typeof n == "function" ? n(t) : n;
6
+ if (!Object.is(o, t)) {
7
+ const S = t;
8
+ t = a ?? (typeof o != "object" || o === null) ? o : Object.assign({}, t, o), s.forEach((b) => b(t, S));
9
+ }
10
+ }, u = () => t, r = { setState: c, getState: u, getInitialState: () => l, subscribe: (n) => (s.add(n), () => s.delete(n)) }, l = t = e(c, u, r);
11
+ return r;
12
+ }, f = (e) => d(e), g = (e) => e;
13
+ function I(e, t = g) {
14
+ const s = i.useSyncExternalStore(
15
+ e.subscribe,
16
+ () => t(e.getState()),
17
+ () => t(e.getInitialState())
18
+ );
19
+ return i.useDebugValue(s), s;
20
+ }
21
+ const R = (e) => {
22
+ const t = f(e), s = (c) => I(t, c);
23
+ return Object.assign(s, t), s;
24
+ }, O = (e) => R(e), y = O((e) => ({
25
+ outboundResults: [],
26
+ inboundResults: [],
27
+ setOutboundResults: (t) => e({ outboundResults: t }),
28
+ setInboundResults: (t) => e({ inboundResults: t }),
29
+ partialOfferRequestId: "",
30
+ setPartialOfferRequestId: (t) => e({ partialOfferRequestId: t })
31
+ }));
32
+ export {
33
+ y as default
34
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odynn/awayz-flights",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -55,7 +55,8 @@
55
55
  "typescript-eslint": "^8.18.2",
56
56
  "vite": "^6.0.5",
57
57
  "vite-plugin-dts": "^4.5.0",
58
- "vite-plugin-lib-inject-css": "^2.2.1"
58
+ "vite-plugin-lib-inject-css": "^2.2.1",
59
+ "zustand": "^5.0.3"
59
60
  },
60
61
  "sideEffects": [
61
62
  "**/*.css"