vue-api-kit 1.5.0 → 1.5.1

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.
Files changed (2) hide show
  1. package/dist/index.js +75 -79
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,44 +1,40 @@
1
1
  import { ZodError as L } from "zod";
2
- import * as $ from "zod";
2
+ import * as T from "zod";
3
3
  import k, { AxiosError as S } from "axios";
4
4
  import { AxiosError as K } from "axios";
5
- import { nextTick as x, ref as m, onMounted as F, watch as N, onBeforeUnmount as T } from "vue";
6
- import { debounce as Z } from "lodash-es";
7
- function z(s) {
5
+ import { nextTick as x, ref as m, onMounted as F, watch as N, onBeforeUnmount as Z } from "vue";
6
+ import { debounce as _ } from "lodash-es";
7
+ function z(r) {
8
8
  const h = k.create({
9
- baseURL: s.baseURL,
10
- headers: {
11
- "Content-Type": "application/json",
12
- Accept: "application/json",
13
- ...s.headers
14
- },
15
- withCredentials: s.withCredentials ?? !1
9
+ baseURL: r.baseURL,
10
+ ...r.headers && { headers: r.headers },
11
+ withCredentials: r.withCredentials ?? !1
16
12
  });
17
- let b = !1, q = null;
18
- s.onBeforeRequest && h.interceptors.request.use(
13
+ let P = !1, q = null;
14
+ r.onBeforeRequest && h.interceptors.request.use(
19
15
  async (e) => {
20
16
  try {
21
- return await s.onBeforeRequest(e) || e;
22
- } catch (r) {
23
- return Promise.reject(r);
17
+ return await r.onBeforeRequest(e) || e;
18
+ } catch (s) {
19
+ return Promise.reject(s);
24
20
  }
25
21
  },
26
22
  (e) => Promise.reject(e)
27
- ), s.onStartRequest && h.interceptors.request.use(
23
+ ), r.onStartRequest && h.interceptors.request.use(
28
24
  async (e) => {
29
25
  try {
30
- return await s.onStartRequest(), e;
31
- } catch (r) {
32
- return Promise.reject(r);
26
+ return await r.onStartRequest(), e;
27
+ } catch (s) {
28
+ return Promise.reject(s);
33
29
  }
34
30
  },
35
31
  (e) => Promise.reject(e)
36
- ), s.onFinishRequest && h.interceptors.response.use(
37
- (e) => (s.onFinishRequest(), e),
38
- (e) => (s.onFinishRequest(), Promise.reject(e))
32
+ ), r.onFinishRequest && h.interceptors.response.use(
33
+ (e) => (r.onFinishRequest(), e),
34
+ (e) => (r.onFinishRequest(), Promise.reject(e))
39
35
  ), h.interceptors.request.use((e) => {
40
36
  if (!e.url) return e;
41
- const r = (a) => {
37
+ const s = (a) => {
42
38
  if (a)
43
39
  for (const [t, v] of Object.entries(a)) {
44
40
  const l = `{${t}}`;
@@ -48,24 +44,24 @@ function z(s) {
48
44
  ), delete a[t]);
49
45
  }
50
46
  };
51
- return e.method !== "get" && e.data?.params && r(e.data.params), r(e.params), e;
52
- }), s.csrfRefreshEndpoint && h.interceptors.response.use(
47
+ return e.method !== "get" && e.data?.params && s(e.data.params), s(e.params), e;
48
+ }), r.csrfRefreshEndpoint && h.interceptors.response.use(
53
49
  (e) => e,
54
50
  async (e) => {
55
- const r = e.config;
56
- if (r.url === s.csrfRefreshEndpoint)
51
+ const s = e.config;
52
+ if (s.url === r.csrfRefreshEndpoint)
57
53
  return Promise.reject(e);
58
- if (e.response && (e.response.status === 403 || e.response.status === 419) && !r._retry) {
59
- r._retry = !0;
54
+ if (e.response && (e.response.status === 403 || e.response.status === 419) && !s._retry) {
55
+ s._retry = !0;
60
56
  try {
61
- return b && q ? await q : (b = !0, q = h.get(s.csrfRefreshEndpoint, {
57
+ return P && q ? await q : (P = !0, q = h.get(r.csrfRefreshEndpoint, {
62
58
  // Mark this request to prevent retry
63
59
  _skipRetry: !0
64
60
  }).then(() => {
65
- b = !1, q = null;
66
- }), await q), h(r);
61
+ P = !1, q = null;
62
+ }), await q), h(s);
67
63
  } catch (a) {
68
- return b = !1, q = null, Promise.reject(a);
64
+ return P = !1, q = null, Promise.reject(a);
69
65
  }
70
66
  }
71
67
  return Promise.reject(e);
@@ -76,51 +72,51 @@ function z(s) {
76
72
  e.code;
77
73
  }), Promise.reject(e))
78
74
  );
79
- const C = s.queries ?? {}, M = {};
75
+ const C = r.queries ?? {}, M = {};
80
76
  for (const e in C) {
81
- const r = C[e];
82
- r && (M[e] = (a) => {
77
+ const s = C[e];
78
+ s && (M[e] = (a) => {
83
79
  let t;
84
80
  a && typeof a == "object" && ("loadOnMount" in a || "debounce" in a || "onResult" in a || "onError" in a || "data" in a ? t = a : t = { params: a });
85
- const v = m(), l = m(), R = m(), g = m(!1), y = m(!1), P = m(!0);
86
- let j = new AbortController();
81
+ const v = m(), l = m(), R = m(), g = m(!1), y = m(!1), A = m(!0);
82
+ let b = new AbortController();
87
83
  const u = () => {
88
- j?.abort(), j = new AbortController();
84
+ b?.abort(), b = new AbortController();
89
85
  }, c = async () => {
90
86
  g.value && u(), g.value = !0, l.value = void 0;
91
87
  try {
92
- r.params && t?.params && r.params.parse(t.params);
88
+ s.params && t?.params && s.params.parse(t.params);
93
89
  let o = t?.data;
94
- r.data && o && r.data.parse(o);
90
+ s.data && o && s.data.parse(o);
95
91
  const f = {
96
- method: r.method ?? "GET",
97
- url: r.path,
92
+ method: s.method ?? "GET",
93
+ url: s.path,
98
94
  params: t?.params,
99
- signal: j.signal
95
+ signal: b.signal
100
96
  };
101
- r.method === "POST" && o && (f.data = o);
102
- const n = await h.request(f), i = r.response ? r.response.parse(n.data) : n.data;
97
+ s.method === "POST" && o && (f.data = o);
98
+ const n = await h.request(f), i = s.response ? s.response.parse(n.data) : n.data;
103
99
  v.value = i, t?.onResult?.(i);
104
100
  } catch (o) {
105
101
  if (o instanceof S) {
106
102
  if (o.code !== "ERR_CANCELED") {
107
103
  const f = o.response?.data?.message || o.message || "An error occurred", n = o.response?.status, i = o.code, p = o.response?.data;
108
- l.value = f, t?.onError?.(o), s.onErrorRequest?.({ message: f, status: n, code: i, data: p });
104
+ l.value = f, t?.onError?.(o), r.onErrorRequest?.({ message: f, status: n, code: i, data: p });
109
105
  }
110
106
  } else if (o instanceof L) {
111
107
  R.value = o.issues || [];
112
108
  const n = `Validation error: ${R.value.map(
113
109
  (i) => `${i.path.join(".")}: ${i.message}`
114
110
  ).join(", ")}`;
115
- l.value = n, t?.onError?.(o), t?.onZodError?.(R.value), s.onErrorRequest?.({ message: n, code: "VALIDATION_ERROR" }), s.onZodError && s.onZodError(R.value);
111
+ l.value = n, t?.onError?.(o), t?.onZodError?.(R.value), r.onErrorRequest?.({ message: n, code: "VALIDATION_ERROR" }), r.onZodError && r.onZodError(R.value);
116
112
  } else {
117
113
  const f = o.message || "An error occurred";
118
- l.value = f, t?.onError?.(f), s.onErrorRequest?.({ message: f });
114
+ l.value = f, t?.onError?.(f), r.onErrorRequest?.({ message: f });
119
115
  }
120
116
  } finally {
121
117
  g.value = !1, y.value = !0;
122
118
  }
123
- }, E = t?.debounce ? Z(c, t.debounce) : c;
119
+ }, E = t?.debounce ? _(c, t.debounce) : c;
124
120
  let d = null;
125
121
  return (t?.params || t?.data) && (F(() => {
126
122
  d && d(), d = N(
@@ -130,34 +126,34 @@ function z(s) {
130
126
  },
131
127
  { immediate: !1 }
132
128
  );
133
- }), T(() => {
134
- d && d(), j?.abort();
135
- })), (t?.loadOnMount === void 0 || t.loadOnMount) && !y.value && (P.value ? (P.value = !1, c()) : E()), { result: v, errorMessage: l, zodErrors: R, isLoading: g, isDone: y, refetch: c };
129
+ }), Z(() => {
130
+ d && d(), b?.abort();
131
+ })), (t?.loadOnMount === void 0 || t.loadOnMount) && !y.value && (A.value ? (A.value = !1, c()) : E()), { result: v, errorMessage: l, zodErrors: R, isLoading: g, isDone: y, refetch: c };
136
132
  });
137
133
  }
138
- const D = s.mutations ?? {}, w = {};
134
+ const D = r.mutations ?? {}, w = {};
139
135
  for (const e in D) {
140
- const r = D[e];
141
- r && (w[e] = (a) => {
136
+ const s = D[e];
137
+ s && (w[e] = (a) => {
142
138
  const t = m(), v = m(), l = m(), R = m(!1), g = m(!1), y = m(0);
143
- return { result: t, errorMessage: v, zodErrors: l, isLoading: R, isDone: g, uploadProgress: y, mutate: async (j) => {
139
+ return { result: t, errorMessage: v, zodErrors: l, isLoading: R, isDone: g, uploadProgress: y, mutate: async (b) => {
144
140
  if (!R.value) {
145
141
  R.value = !0, v.value = void 0, y.value = 0;
146
142
  try {
147
- const { data: u = {}, params: c } = j ?? {};
143
+ const { data: u = {}, params: c } = b ?? {};
148
144
  let E = u ?? {}, d = {};
149
- if (r.isMultipart) {
145
+ if (s.isMultipart) {
150
146
  const n = new FormData();
151
147
  for (const [i, p] of Object.entries(u))
152
- p instanceof File || p instanceof Blob ? n.append(i, p) : Array.isArray(p) ? p.forEach((A) => {
153
- A instanceof File || A instanceof Blob ? n.append(i, A) : n.append(i, JSON.stringify(A));
148
+ p instanceof File || p instanceof Blob ? n.append(i, p) : Array.isArray(p) ? p.forEach((j) => {
149
+ j instanceof File || j instanceof Blob ? n.append(i, j) : n.append(i, JSON.stringify(j));
154
150
  }) : typeof p == "object" && p !== null ? n.append(i, JSON.stringify(p)) : n.append(i, String(p));
155
151
  E = n, d["Content-Type"] = "multipart/form-data";
156
- } else r.data && r.data.parse(u);
157
- r.params && c && r.params.parse(c);
152
+ } else s.data && s.data.parse(u);
153
+ s.params && c && s.params.parse(c);
158
154
  const o = await h.request({
159
- method: r.method,
160
- url: r.path,
155
+ method: s.method,
156
+ url: s.path,
161
157
  data: E,
162
158
  params: c,
163
159
  headers: d,
@@ -167,21 +163,21 @@ function z(s) {
167
163
  y.value = i, a?.onUploadProgress?.(i);
168
164
  }
169
165
  }
170
- }), f = r.response ? r.response.parse(o.data) : o.data;
166
+ }), f = s.response ? s.response.parse(o.data) : o.data;
171
167
  t.value = f, a?.onResult?.(f);
172
168
  } catch (u) {
173
169
  if (u instanceof S) {
174
170
  const c = u.response?.data?.message || u.message || "An error occurred", E = u.response?.status, d = u.code;
175
- v.value = c, a?.onError?.(u), s.onErrorRequest?.({ message: c, status: E, code: d });
171
+ v.value = c, a?.onError?.(u), r.onErrorRequest?.({ message: c, status: E, code: d });
176
172
  } else if (u instanceof L) {
177
173
  l.value = u.issues || [];
178
174
  const E = `Validation error: ${l.value.map(
179
175
  (d) => `${d.path.join(".")}: ${d.message}`
180
176
  ).join(", ")}`;
181
- v.value = E, a?.onError?.(u), a?.onZodError?.(l.value), s.onErrorRequest?.({ message: E, code: "VALIDATION_ERROR" }), s.onZodError && s.onZodError(l.value);
177
+ v.value = E, a?.onError?.(u), a?.onZodError?.(l.value), r.onErrorRequest?.({ message: E, code: "VALIDATION_ERROR" }), r.onZodError && r.onZodError(l.value);
182
178
  } else {
183
179
  const c = u.message || "An error occurred";
184
- v.value = c, a?.onError?.(u), s.onErrorRequest?.({ message: c });
180
+ v.value = c, a?.onError?.(u), r.onErrorRequest?.({ message: c });
185
181
  }
186
182
  } finally {
187
183
  R.value = !1, g.value = !0;
@@ -195,17 +191,17 @@ function z(s) {
195
191
  mutation: w
196
192
  };
197
193
  }
198
- function V(s) {
199
- return s;
194
+ function V(r) {
195
+ return r;
200
196
  }
201
- function J(s) {
202
- return s;
197
+ function J(r) {
198
+ return r;
203
199
  }
204
- function Q(...s) {
205
- return Object.assign({}, ...s);
200
+ function Q(...r) {
201
+ return Object.assign({}, ...r);
206
202
  }
207
- function W(...s) {
208
- return Object.assign({}, ...s);
203
+ function W(...r) {
204
+ return Object.assign({}, ...r);
209
205
  }
210
206
  export {
211
207
  K as AxiosError,
@@ -214,5 +210,5 @@ export {
214
210
  V as defineQuery,
215
211
  W as mergeMutations,
216
212
  Q as mergeQueries,
217
- $ as z
213
+ T as z
218
214
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vue-api-kit",
3
3
  "type": "module",
4
- "version": "1.5.0",
4
+ "version": "1.5.1",
5
5
  "description": "A powerful and flexible API client for Vue 3 applications, built with TypeScript and Zod for type-safe API interactions.",
6
6
  "keywords": [
7
7
  "vue3",