vue-api-kit 1.5.0 → 1.5.2

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 +33 -36
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { ZodError as L } from "zod";
2
- import * as $ from "zod";
3
- import k, { AxiosError as S } from "axios";
2
+ import * as U from "zod";
3
+ import x, { 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";
5
+ import { nextTick as F, ref as m, onMounted as N, watch as T, onBeforeUnmount as Z } from "vue";
6
+ import { debounce as $ } from "lodash-es";
7
7
  function z(s) {
8
- const h = k.create({
8
+ const h = x.create({
9
9
  baseURL: s.baseURL,
10
10
  headers: {
11
11
  "Content-Type": "application/json",
@@ -53,17 +53,14 @@ function z(s) {
53
53
  (e) => e,
54
54
  async (e) => {
55
55
  const r = e.config;
56
- if (r.url === s.csrfRefreshEndpoint)
56
+ if (r?.url === s.csrfRefreshEndpoint)
57
57
  return Promise.reject(e);
58
- if (e.response && (e.response.status === 403 || e.response.status === 419) && !r._retry) {
58
+ if (e.response && (e.response.status === 403 || e.response.status === 419) && !r?._retry) {
59
59
  r._retry = !0;
60
60
  try {
61
- return b && q ? await q : (b = !0, q = h.get(s.csrfRefreshEndpoint, {
62
- // Mark this request to prevent retry
63
- _skipRetry: !0
64
- }).then(() => {
61
+ return b && q ? await q : (b = !0, q = h.get(s.csrfRefreshEndpoint).then(() => {
65
62
  b = !1, q = null;
66
- }), await q), h(r);
63
+ }), await q), h.request(r);
67
64
  } catch (a) {
68
65
  return b = !1, q = null, Promise.reject(a);
69
66
  }
@@ -72,7 +69,7 @@ function z(s) {
72
69
  }
73
70
  ), h.interceptors.response.use(
74
71
  (e) => e,
75
- (e) => (x(() => {
72
+ (e) => (F(() => {
76
73
  e.code;
77
74
  }), Promise.reject(e))
78
75
  );
@@ -82,7 +79,7 @@ function z(s) {
82
79
  r && (M[e] = (a) => {
83
80
  let t;
84
81
  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);
82
+ const v = m(), l = m(), E = m(), g = m(!1), y = m(!1), P = m(!0);
86
83
  let j = new AbortController();
87
84
  const u = () => {
88
85
  j?.abort(), j = new AbortController();
@@ -108,11 +105,11 @@ function z(s) {
108
105
  l.value = f, t?.onError?.(o), s.onErrorRequest?.({ message: f, status: n, code: i, data: p });
109
106
  }
110
107
  } else if (o instanceof L) {
111
- R.value = o.issues || [];
112
- const n = `Validation error: ${R.value.map(
108
+ E.value = o.issues || [];
109
+ const n = `Validation error: ${E.value.map(
113
110
  (i) => `${i.path.join(".")}: ${i.message}`
114
111
  ).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);
112
+ l.value = n, t?.onError?.(o), t?.onZodError?.(E.value), s.onErrorRequest?.({ message: n, code: "VALIDATION_ERROR" }), s.onZodError && s.onZodError(E.value);
116
113
  } else {
117
114
  const f = o.message || "An error occurred";
118
115
  l.value = f, t?.onError?.(f), s.onErrorRequest?.({ message: f });
@@ -120,45 +117,45 @@ function z(s) {
120
117
  } finally {
121
118
  g.value = !1, y.value = !0;
122
119
  }
123
- }, E = t?.debounce ? Z(c, t.debounce) : c;
120
+ }, R = t?.debounce ? $(c, t.debounce) : c;
124
121
  let d = null;
125
- return (t?.params || t?.data) && (F(() => {
126
- d && d(), d = N(
122
+ return (t?.params || t?.data) && (N(() => {
123
+ d && d(), d = T(
127
124
  () => JSON.stringify({ params: t.params, data: t.data }),
128
125
  () => {
129
- E();
126
+ R();
130
127
  },
131
128
  { immediate: !1 }
132
129
  );
133
- }), T(() => {
130
+ }), Z(() => {
134
131
  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 };
132
+ })), (t?.loadOnMount === void 0 || t.loadOnMount) && !y.value && (P.value ? (P.value = !1, c()) : R()), { result: v, errorMessage: l, zodErrors: E, isLoading: g, isDone: y, refetch: c };
136
133
  });
137
134
  }
138
135
  const D = s.mutations ?? {}, w = {};
139
136
  for (const e in D) {
140
137
  const r = D[e];
141
138
  r && (w[e] = (a) => {
142
- 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) => {
144
- if (!R.value) {
145
- R.value = !0, v.value = void 0, y.value = 0;
139
+ const t = m(), v = m(), l = m(), E = m(!1), g = m(!1), y = m(0);
140
+ return { result: t, errorMessage: v, zodErrors: l, isLoading: E, isDone: g, uploadProgress: y, mutate: async (j) => {
141
+ if (!E.value) {
142
+ E.value = !0, v.value = void 0, y.value = 0;
146
143
  try {
147
144
  const { data: u = {}, params: c } = j ?? {};
148
- let E = u ?? {}, d = {};
145
+ let R = u ?? {}, d = {};
149
146
  if (r.isMultipart) {
150
147
  const n = new FormData();
151
148
  for (const [i, p] of Object.entries(u))
152
149
  p instanceof File || p instanceof Blob ? n.append(i, p) : Array.isArray(p) ? p.forEach((A) => {
153
150
  A instanceof File || A instanceof Blob ? n.append(i, A) : n.append(i, JSON.stringify(A));
154
151
  }) : typeof p == "object" && p !== null ? n.append(i, JSON.stringify(p)) : n.append(i, String(p));
155
- E = n, d["Content-Type"] = "multipart/form-data";
152
+ R = n, d["Content-Type"] = "multipart/form-data";
156
153
  } else r.data && r.data.parse(u);
157
154
  r.params && c && r.params.parse(c);
158
155
  const o = await h.request({
159
156
  method: r.method,
160
157
  url: r.path,
161
- data: E,
158
+ data: R,
162
159
  params: c,
163
160
  headers: d,
164
161
  onUploadProgress: (n) => {
@@ -171,20 +168,20 @@ function z(s) {
171
168
  t.value = f, a?.onResult?.(f);
172
169
  } catch (u) {
173
170
  if (u instanceof S) {
174
- 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
+ const c = u.response?.data?.message || u.message || "An error occurred", R = u.response?.status, d = u.code;
172
+ v.value = c, a?.onError?.(u), s.onErrorRequest?.({ message: c, status: R, code: d });
176
173
  } else if (u instanceof L) {
177
174
  l.value = u.issues || [];
178
- const E = `Validation error: ${l.value.map(
175
+ const R = `Validation error: ${l.value.map(
179
176
  (d) => `${d.path.join(".")}: ${d.message}`
180
177
  ).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);
178
+ v.value = R, a?.onError?.(u), a?.onZodError?.(l.value), s.onErrorRequest?.({ message: R, code: "VALIDATION_ERROR" }), s.onZodError && s.onZodError(l.value);
182
179
  } else {
183
180
  const c = u.message || "An error occurred";
184
181
  v.value = c, a?.onError?.(u), s.onErrorRequest?.({ message: c });
185
182
  }
186
183
  } finally {
187
- R.value = !1, g.value = !0;
184
+ E.value = !1, g.value = !0;
188
185
  }
189
186
  }
190
187
  } };
@@ -214,5 +211,5 @@ export {
214
211
  V as defineQuery,
215
212
  W as mergeMutations,
216
213
  Q as mergeQueries,
217
- $ as z
214
+ U as z
218
215
  };
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.2",
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",