vue-api-kit 1.10.1 → 1.10.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.
- package/dist/index.js +40 -40
- 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
|
|
24
|
+
let M = !1, b = null;
|
|
25
25
|
e.onBeforeRequest && y.interceptors.request.use(
|
|
26
26
|
async (r) => {
|
|
27
27
|
try {
|
|
@@ -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
|
|
69
|
-
|
|
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
|
|
72
|
+
return M = !1, b = null, Promise.reject(m);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
return Promise.reject(r);
|
|
@@ -88,8 +88,8 @@ function K(e) {
|
|
|
88
88
|
if (z(d)) {
|
|
89
89
|
const t = d;
|
|
90
90
|
i[m] = (n) => {
|
|
91
|
-
let
|
|
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 ?
|
|
91
|
+
let s;
|
|
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 ? s = n : s = { params: n });
|
|
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 &&
|
|
101
|
-
let
|
|
102
|
-
t.data &&
|
|
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:
|
|
106
|
+
params: s?.params,
|
|
107
107
|
signal: w.signal
|
|
108
108
|
};
|
|
109
|
-
if (t.method === "POST" &&
|
|
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 (
|
|
114
|
-
const f = await
|
|
113
|
+
if (s?.onBeforeRequest) {
|
|
114
|
+
const f = await s.onBeforeRequest(c);
|
|
115
115
|
f !== void 0 && Object.assign(c, f);
|
|
116
116
|
}
|
|
117
117
|
const h = await y.request(c), o = t.response ? t.response.parse(h.data) : h.data;
|
|
118
|
-
C.value = o,
|
|
119
|
-
} catch (
|
|
120
|
-
if (
|
|
121
|
-
if (
|
|
122
|
-
const c =
|
|
123
|
-
g.value = h,
|
|
118
|
+
C.value = o, s?.onResult?.(o);
|
|
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", o = a.response?.status, f = a.code, v = a.response?.data;
|
|
123
|
+
g.value = h, s?.onError?.(a), e.onErrorRequest?.({ message: h, status: o, code: f, data: v, url: c });
|
|
124
124
|
}
|
|
125
|
-
} else if (
|
|
126
|
-
q.value =
|
|
125
|
+
} else if (a instanceof S) {
|
|
126
|
+
q.value = a.issues || [];
|
|
127
127
|
const h = `Validation error: ${q.value.map(
|
|
128
128
|
(o) => `${o.path.join(".")}: ${o.message}`
|
|
129
129
|
).join(", ")}`;
|
|
130
|
-
g.value = h,
|
|
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 =
|
|
133
|
-
g.value = 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 =
|
|
138
|
+
}, E = s?.debounce ? Q(l, s.debounce) : l;
|
|
139
139
|
let p = null;
|
|
140
|
-
return (
|
|
140
|
+
return (s?.params || s?.data) && (U(() => {
|
|
141
141
|
p && p(), p = _(
|
|
142
|
-
() => JSON.stringify({ params:
|
|
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
|
-
})), (
|
|
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
|
}
|
|
@@ -162,8 +162,8 @@ function K(e) {
|
|
|
162
162
|
if (V(d)) {
|
|
163
163
|
const t = d;
|
|
164
164
|
i[m] = (n) => {
|
|
165
|
-
const
|
|
166
|
-
return { result:
|
|
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 {
|
|
@@ -172,13 +172,13 @@ function K(e) {
|
|
|
172
172
|
if (t.isMultipart) {
|
|
173
173
|
const o = 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((
|
|
176
|
-
|
|
175
|
+
v instanceof File || v instanceof Blob ? o.append(f, v) : Array.isArray(v) ? v.forEach((P) => {
|
|
176
|
+
P instanceof File || P instanceof Blob ? o.append(f, P) : o.append(f, JSON.stringify(P));
|
|
177
177
|
}) : typeof v == "object" && v !== null ? o.append(f, JSON.stringify(v)) : o.append(f, String(v));
|
|
178
178
|
E = o, 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
|
|
181
|
+
const a = {
|
|
182
182
|
method: t.method,
|
|
183
183
|
url: t.path,
|
|
184
184
|
data: E,
|
|
@@ -192,15 +192,15 @@ function K(e) {
|
|
|
192
192
|
}
|
|
193
193
|
};
|
|
194
194
|
if (t.onBeforeRequest) {
|
|
195
|
-
const o = await t.onBeforeRequest(
|
|
196
|
-
o !== void 0 && Object.assign(
|
|
195
|
+
const o = await t.onBeforeRequest(a);
|
|
196
|
+
o !== void 0 && Object.assign(a, o);
|
|
197
197
|
}
|
|
198
198
|
if (n?.onBeforeRequest) {
|
|
199
|
-
const o = await n.onBeforeRequest(
|
|
200
|
-
o !== void 0 && Object.assign(
|
|
199
|
+
const o = await n.onBeforeRequest(a);
|
|
200
|
+
o !== void 0 && Object.assign(a, o);
|
|
201
201
|
}
|
|
202
|
-
const c = await y.request(
|
|
203
|
-
|
|
202
|
+
const c = await y.request(a), h = t.response ? t.response.parse(c.data) : c.data;
|
|
203
|
+
s.value = h, n?.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;
|
package/package.json
CHANGED