vue-api-kit 1.10.3 → 1.10.4

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 +50 -50
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ function K(e) {
21
21
  withCredentials: e.withCredentials ?? !1,
22
22
  withXSRFToken: e.withXSRFToken ?? !1
23
23
  });
24
- let M = !1, b = null;
24
+ let P = !1, b = null;
25
25
  e.onBeforeRequest && y.interceptors.request.use(
26
26
  async (r) => {
27
27
  try {
@@ -48,9 +48,9 @@ function K(e) {
48
48
  const i = (m) => {
49
49
  if (m)
50
50
  for (const [d, t] of Object.entries(m)) {
51
- const o = `{${d}}`;
52
- r.url.includes(o) && (r.url = r.url.replace(
53
- o,
51
+ const a = `{${d}}`;
52
+ r.url.includes(a) && (r.url = r.url.replace(
53
+ a,
54
54
  encodeURIComponent(String(t))
55
55
  ), delete m[d]);
56
56
  }
@@ -65,11 +65,11 @@ function K(e) {
65
65
  if (r.response && (r.response.status === 403 || r.response.status === 419) && !i?._retry) {
66
66
  i._retry = !0;
67
67
  try {
68
- return M && b ? await b : (M = !0, b = y.get(e.csrfRefreshEndpoint).then(() => {
69
- M = !1, b = null;
68
+ return P && b ? await b : (P = !0, b = y.get(e.csrfRefreshEndpoint).then(() => {
69
+ P = !1, b = null;
70
70
  }), await b), y.request(i);
71
71
  } catch (m) {
72
- return M = !1, b = null, Promise.reject(m);
72
+ return P = !1, b = null, Promise.reject(m);
73
73
  }
74
74
  }
75
75
  return Promise.reject(r);
@@ -87,9 +87,9 @@ function K(e) {
87
87
  if (d)
88
88
  if (z(d)) {
89
89
  const t = d;
90
- i[m] = (o) => {
91
- let s;
92
- o && typeof o == "object" && ("loadOnMount" in o || "debounce" in o || "onResult" in o || "onError" in o || "onZodError" in o || "onBeforeRequest" in o || "params" in o || "data" in o ? s = o : s = { params: o });
90
+ i[m] = (a) => {
91
+ let o;
92
+ a && typeof a == "object" && ("loadOnMount" in a || "debounce" in a || "onResult" in a || "onError" in a || "onZodError" in a || "onBeforeRequest" in a || "params" in a || "data" in a ? o = a : o = { params: a });
93
93
  const C = R(), g = R(), q = R(), j = R(!1), A = R(!1), B = R(!0);
94
94
  let w = new AbortController();
95
95
  const u = () => {
@@ -97,57 +97,57 @@ function K(e) {
97
97
  }, l = async () => {
98
98
  j.value && u(), j.value = !0, g.value = void 0;
99
99
  try {
100
- t.params && s?.params && t.params.parse(s.params);
101
- let a = s?.data;
102
- t.data && a && t.data.parse(a);
100
+ t.params && o?.params && t.params.parse(o.params);
101
+ let s = o?.data;
102
+ t.data && s && t.data.parse(s);
103
103
  const c = {
104
104
  method: t.method ?? "GET",
105
105
  url: t.path,
106
- params: s?.params,
106
+ params: o?.params,
107
107
  signal: w.signal
108
108
  };
109
- if (t.method === "POST" && a && (c.data = a), t.onBeforeRequest) {
109
+ if (t.method === "POST" && s && (c.data = s), t.onBeforeRequest) {
110
110
  const f = await t.onBeforeRequest(c);
111
111
  f !== void 0 && Object.assign(c, f);
112
112
  }
113
- if (s?.onBeforeRequest) {
114
- const f = await s.onBeforeRequest(c);
113
+ if (o?.onBeforeRequest) {
114
+ const f = await o.onBeforeRequest(c);
115
115
  f !== void 0 && Object.assign(c, f);
116
116
  }
117
117
  const h = await y.request(c), n = t.response ? t.response.parse(h.data) : h.data;
118
- C.value = n, s?.onResult?.(n);
119
- } catch (a) {
120
- if (a instanceof F) {
121
- if (a.code !== "ERR_CANCELED") {
122
- const c = a.config?.url, h = a.response?.data?.message || a.message || "An error occurred", n = a.response?.status, f = a.code, v = a.response?.data;
123
- g.value = h, s?.onError?.(a), e.onErrorRequest?.({ message: h, status: n, code: f, data: v, url: c });
118
+ C.value = n, o?.onResult?.(n);
119
+ } catch (s) {
120
+ if (s instanceof F) {
121
+ if (s.code !== "ERR_CANCELED") {
122
+ const c = s.config?.url, h = s.response?.data?.message || s.message || "An error occurred", n = s.response?.status, f = s.code, v = s.response?.data;
123
+ g.value = h, o?.onError?.(s), e.onErrorRequest?.({ message: h, status: n, code: f, data: v, url: c });
124
124
  }
125
- } else if (a instanceof S) {
126
- q.value = a.issues || [];
125
+ } else if (s instanceof S) {
126
+ q.value = s.issues || [];
127
127
  const h = `Validation error: ${q.value.map(
128
128
  (n) => `${n.path.join(".")}: ${n.message}`
129
129
  ).join(", ")}`;
130
- g.value = h, s?.onError?.(a), s?.onZodError?.(q.value), e.onErrorRequest?.({ message: h, code: "VALIDATION_ERROR" }), e.onZodError && e.onZodError(q.value);
130
+ g.value = h, o?.onError?.(s), o?.onZodError?.(q.value), e.onErrorRequest?.({ message: h, code: "VALIDATION_ERROR" }), e.onZodError && e.onZodError(q.value);
131
131
  } else {
132
- const c = a.message || "An error occurred";
133
- g.value = c, s?.onError?.(c), e.onErrorRequest?.({ message: c });
132
+ const c = s.message || "An error occurred";
133
+ g.value = c, o?.onError?.(c), e.onErrorRequest?.({ message: c });
134
134
  }
135
135
  } finally {
136
136
  j.value = !1, A.value = !0;
137
137
  }
138
- }, E = s?.debounce ? Q(l, s.debounce) : l;
138
+ }, E = o?.debounce ? Q(l, o.debounce) : l;
139
139
  let p = null;
140
- return (s?.params || s?.data) && (U(() => {
140
+ return (o?.params || o?.data) && (U(() => {
141
141
  p && p(), p = _(
142
- () => JSON.stringify({ params: s.params, data: s.data }),
142
+ () => JSON.stringify({ params: o.params, data: o.data }),
143
143
  () => {
144
144
  E();
145
145
  },
146
- { immediate: s?.loadOnMount !== !1 }
146
+ { immediate: !1 }
147
147
  );
148
148
  }), I(() => {
149
149
  p && p(), w?.abort();
150
- })), (s?.loadOnMount === void 0 || s.loadOnMount) && !A.value && (B.value ? (B.value = !1, l()) : E()), { result: C, errorMessage: g, zodErrors: q, isLoading: j, isDone: A, refetch: l };
150
+ })), (o?.loadOnMount === void 0 || o.loadOnMount) && !A.value && (B.value ? (B.value = !1, l()) : E()), { result: C, errorMessage: g, zodErrors: q, isLoading: j, isDone: A, refetch: l };
151
151
  };
152
152
  } else typeof d == "object" && (i[m] = D(d));
153
153
  }
@@ -161,9 +161,9 @@ function K(e) {
161
161
  if (d)
162
162
  if (V(d)) {
163
163
  const t = d;
164
- i[m] = (o) => {
165
- const s = R(), C = R(), g = R(), q = R(!1), j = R(!1), A = R(0);
166
- return { result: s, errorMessage: C, zodErrors: g, isLoading: q, isDone: j, uploadProgress: A, mutate: async (w) => {
164
+ i[m] = (a) => {
165
+ const o = R(), C = R(), g = R(), q = R(!1), j = R(!1), A = R(0);
166
+ return { result: o, errorMessage: C, zodErrors: g, isLoading: q, isDone: j, uploadProgress: A, mutate: async (w) => {
167
167
  if (!q.value) {
168
168
  q.value = !0, C.value = void 0, A.value = 0;
169
169
  try {
@@ -172,13 +172,13 @@ function K(e) {
172
172
  if (t.isMultipart) {
173
173
  const n = new FormData();
174
174
  for (const [f, v] of Object.entries(u))
175
- v instanceof File || v instanceof Blob ? n.append(f, v) : Array.isArray(v) ? v.forEach((P) => {
176
- P instanceof File || P instanceof Blob ? n.append(f, P) : n.append(f, JSON.stringify(P));
175
+ v instanceof File || v instanceof Blob ? n.append(f, v) : Array.isArray(v) ? v.forEach((M) => {
176
+ M instanceof File || M instanceof Blob ? n.append(f, M) : n.append(f, JSON.stringify(M));
177
177
  }) : typeof v == "object" && v !== null ? n.append(f, JSON.stringify(v)) : n.append(f, String(v));
178
178
  E = n, p["Content-Type"] = "multipart/form-data";
179
179
  } else t.data && t.data.parse(u);
180
180
  t.params && l && t.params.parse(l);
181
- const a = {
181
+ const s = {
182
182
  method: t.method,
183
183
  url: t.path,
184
184
  data: E,
@@ -187,33 +187,33 @@ function K(e) {
187
187
  onUploadProgress: (n) => {
188
188
  if (n.total) {
189
189
  const f = Math.round(n.loaded * 100 / n.total);
190
- A.value = f, o?.onUploadProgress?.(f);
190
+ A.value = f, a?.onUploadProgress?.(f);
191
191
  }
192
192
  }
193
193
  };
194
194
  if (t.onBeforeRequest) {
195
- const n = await t.onBeforeRequest(a);
196
- n !== void 0 && Object.assign(a, n);
195
+ const n = await t.onBeforeRequest(s);
196
+ n !== void 0 && Object.assign(s, n);
197
197
  }
198
- if (o?.onBeforeRequest) {
199
- const n = await o.onBeforeRequest(a);
200
- n !== void 0 && Object.assign(a, n);
198
+ if (a?.onBeforeRequest) {
199
+ const n = await a.onBeforeRequest(s);
200
+ n !== void 0 && Object.assign(s, n);
201
201
  }
202
- const c = await y.request(a), h = t.response ? t.response.parse(c.data) : c.data;
203
- s.value = h, o?.onResult?.(h);
202
+ const c = await y.request(s), h = t.response ? t.response.parse(c.data) : c.data;
203
+ o.value = h, a?.onResult?.(h);
204
204
  } catch (u) {
205
205
  if (u instanceof F) {
206
206
  const l = u.response?.data?.message || u.message || "An error occurred", E = u.response?.status, p = u.code;
207
- C.value = l, o?.onError?.(u), e.onErrorRequest?.({ message: l, status: E, code: p });
207
+ C.value = l, a?.onError?.(u), e.onErrorRequest?.({ message: l, status: E, code: p });
208
208
  } else if (u instanceof S) {
209
209
  g.value = u.issues || [];
210
210
  const E = `Validation error: ${g.value.map(
211
211
  (p) => `${p.path.join(".")}: ${p.message}`
212
212
  ).join(", ")}`;
213
- C.value = E, o?.onError?.(u), o?.onZodError?.(g.value), e.onErrorRequest?.({ message: E, code: "VALIDATION_ERROR" }), e.onZodError && e.onZodError(g.value);
213
+ C.value = E, a?.onError?.(u), a?.onZodError?.(g.value), e.onErrorRequest?.({ message: E, code: "VALIDATION_ERROR" }), e.onZodError && e.onZodError(g.value);
214
214
  } else {
215
215
  const l = u.message || "An error occurred";
216
- C.value = l, o?.onError?.(u), e.onErrorRequest?.({ message: l });
216
+ C.value = l, a?.onError?.(u), e.onErrorRequest?.({ message: l });
217
217
  }
218
218
  } finally {
219
219
  q.value = !1, j.value = !0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vue-api-kit",
3
3
  "type": "module",
4
- "version": "1.10.3",
4
+ "version": "1.10.4",
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",