vue-api-kit 1.10.1 → 1.10.3

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 +58 -58
  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 P = !1, b = null;
24
+ let M = !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 n = `{${d}}`;
52
- r.url.includes(n) && (r.url = r.url.replace(
53
- n,
51
+ const o = `{${d}}`;
52
+ r.url.includes(o) && (r.url = r.url.replace(
53
+ o,
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 P && b ? await b : (P = !0, b = y.get(e.csrfRefreshEndpoint).then(() => {
69
- P = !1, b = null;
68
+ return M && b ? await b : (M = !0, b = y.get(e.csrfRefreshEndpoint).then(() => {
69
+ M = !1, b = null;
70
70
  }), await b), y.request(i);
71
71
  } catch (m) {
72
- return P = !1, b = null, Promise.reject(m);
72
+ return M = !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] = (n) => {
91
- let a;
92
- n && typeof n == "object" && ("loadOnMount" in n || "debounce" in n || "onResult" in n || "onError" in n || "onZodError" in n || "onBeforeRequest" in n || "data" in n ? a = n : a = { params: n });
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 });
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 && a?.params && t.params.parse(a.params);
101
- let s = a?.data;
102
- t.data && s && t.data.parse(s);
100
+ t.params && s?.params && t.params.parse(s.params);
101
+ let a = s?.data;
102
+ t.data && a && t.data.parse(a);
103
103
  const c = {
104
104
  method: t.method ?? "GET",
105
105
  url: t.path,
106
- params: a?.params,
106
+ params: s?.params,
107
107
  signal: w.signal
108
108
  };
109
- if (t.method === "POST" && s && (c.data = s), t.onBeforeRequest) {
109
+ if (t.method === "POST" && a && (c.data = a), t.onBeforeRequest) {
110
110
  const f = await t.onBeforeRequest(c);
111
111
  f !== void 0 && Object.assign(c, f);
112
112
  }
113
- if (a?.onBeforeRequest) {
114
- const f = await a.onBeforeRequest(c);
113
+ if (s?.onBeforeRequest) {
114
+ const f = await s.onBeforeRequest(c);
115
115
  f !== void 0 && Object.assign(c, f);
116
116
  }
117
- const h = await y.request(c), o = t.response ? t.response.parse(h.data) : h.data;
118
- C.value = o, a?.onResult?.(o);
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", o = s.response?.status, f = s.code, v = s.response?.data;
123
- g.value = h, a?.onError?.(s), e.onErrorRequest?.({ message: h, status: o, code: f, data: v, url: c });
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 });
124
124
  }
125
- } else if (s instanceof S) {
126
- q.value = s.issues || [];
125
+ } else if (a instanceof S) {
126
+ q.value = a.issues || [];
127
127
  const h = `Validation error: ${q.value.map(
128
- (o) => `${o.path.join(".")}: ${o.message}`
128
+ (n) => `${n.path.join(".")}: ${n.message}`
129
129
  ).join(", ")}`;
130
- g.value = h, a?.onError?.(s), a?.onZodError?.(q.value), e.onErrorRequest?.({ message: h, code: "VALIDATION_ERROR" }), e.onZodError && e.onZodError(q.value);
130
+ g.value = h, s?.onError?.(a), s?.onZodError?.(q.value), e.onErrorRequest?.({ message: h, code: "VALIDATION_ERROR" }), e.onZodError && e.onZodError(q.value);
131
131
  } else {
132
- const c = s.message || "An error occurred";
133
- g.value = c, a?.onError?.(c), e.onErrorRequest?.({ message: c });
132
+ const c = a.message || "An error occurred";
133
+ g.value = c, s?.onError?.(c), e.onErrorRequest?.({ message: c });
134
134
  }
135
135
  } finally {
136
136
  j.value = !1, A.value = !0;
137
137
  }
138
- }, E = a?.debounce ? Q(l, a.debounce) : l;
138
+ }, E = s?.debounce ? Q(l, s.debounce) : l;
139
139
  let p = null;
140
- return (a?.params || a?.data) && (U(() => {
140
+ return (s?.params || s?.data) && (U(() => {
141
141
  p && p(), p = _(
142
- () => JSON.stringify({ params: a.params, data: a.data }),
142
+ () => JSON.stringify({ params: s.params, data: s.data }),
143
143
  () => {
144
144
  E();
145
145
  },
146
- { immediate: !1 }
146
+ { immediate: s?.loadOnMount !== !1 }
147
147
  );
148
148
  }), I(() => {
149
149
  p && p(), w?.abort();
150
- })), (a?.loadOnMount === void 0 || a.loadOnMount) && !A.value && (B.value ? (B.value = !1, l()) : E()), { result: C, errorMessage: g, zodErrors: q, isLoading: j, isDone: A, refetch: l };
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 };
151
151
  };
152
152
  } else typeof d == "object" && (i[m] = D(d));
153
153
  }
@@ -161,59 +161,59 @@ function K(e) {
161
161
  if (d)
162
162
  if (V(d)) {
163
163
  const t = d;
164
- i[m] = (n) => {
165
- const a = R(), C = R(), g = R(), q = R(!1), j = R(!1), A = R(0);
166
- return { result: a, errorMessage: C, zodErrors: g, isLoading: q, isDone: j, uploadProgress: A, mutate: async (w) => {
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) => {
167
167
  if (!q.value) {
168
168
  q.value = !0, C.value = void 0, A.value = 0;
169
169
  try {
170
170
  const { data: u = {}, params: l } = w ?? {};
171
171
  let E = u ?? {}, p = {};
172
172
  if (t.isMultipart) {
173
- const o = new FormData();
173
+ const n = new FormData();
174
174
  for (const [f, v] of Object.entries(u))
175
- v instanceof File || v instanceof Blob ? o.append(f, v) : Array.isArray(v) ? v.forEach((M) => {
176
- M instanceof File || M instanceof Blob ? o.append(f, M) : o.append(f, JSON.stringify(M));
177
- }) : typeof v == "object" && v !== null ? o.append(f, JSON.stringify(v)) : o.append(f, String(v));
178
- E = o, p["Content-Type"] = "multipart/form-data";
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));
177
+ }) : typeof v == "object" && v !== null ? n.append(f, JSON.stringify(v)) : n.append(f, String(v));
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 s = {
181
+ const a = {
182
182
  method: t.method,
183
183
  url: t.path,
184
184
  data: E,
185
185
  params: l,
186
186
  headers: p,
187
- onUploadProgress: (o) => {
188
- if (o.total) {
189
- const f = Math.round(o.loaded * 100 / o.total);
190
- A.value = f, n?.onUploadProgress?.(f);
187
+ onUploadProgress: (n) => {
188
+ if (n.total) {
189
+ const f = Math.round(n.loaded * 100 / n.total);
190
+ A.value = f, o?.onUploadProgress?.(f);
191
191
  }
192
192
  }
193
193
  };
194
194
  if (t.onBeforeRequest) {
195
- const o = await t.onBeforeRequest(s);
196
- o !== void 0 && Object.assign(s, o);
195
+ const n = await t.onBeforeRequest(a);
196
+ n !== void 0 && Object.assign(a, n);
197
197
  }
198
- if (n?.onBeforeRequest) {
199
- const o = await n.onBeforeRequest(s);
200
- o !== void 0 && Object.assign(s, o);
198
+ if (o?.onBeforeRequest) {
199
+ const n = await o.onBeforeRequest(a);
200
+ n !== void 0 && Object.assign(a, n);
201
201
  }
202
- const c = await y.request(s), h = t.response ? t.response.parse(c.data) : c.data;
203
- a.value = h, n?.onResult?.(h);
202
+ const c = await y.request(a), h = t.response ? t.response.parse(c.data) : c.data;
203
+ s.value = h, o?.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, n?.onError?.(u), e.onErrorRequest?.({ message: l, status: E, code: p });
207
+ C.value = l, o?.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, n?.onError?.(u), n?.onZodError?.(g.value), e.onErrorRequest?.({ message: E, code: "VALIDATION_ERROR" }), e.onZodError && e.onZodError(g.value);
213
+ C.value = E, o?.onError?.(u), o?.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, n?.onError?.(u), e.onErrorRequest?.({ message: l });
216
+ C.value = l, o?.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.1",
4
+ "version": "1.10.3",
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",