@useinsider/guido 3.18.0-beta.d542b1f → 3.18.0-beta.fda7e92
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/composables/useHttp.js +40 -47
- package/dist/package.json.js +1 -1
- package/package.json +2 -2
|
@@ -1,93 +1,86 @@
|
|
|
1
|
-
import { getCsrfToken as
|
|
2
|
-
import { ref as p, computed as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
1
|
+
import { getCsrfToken as H } from "../utils/genericUtil.js";
|
|
2
|
+
import { ref as p, computed as T } from "vue";
|
|
3
|
+
const k = (b = {}) => {
|
|
4
|
+
const h = p(!1), a = p(null), u = p(null), g = T(() => h.value), y = T(() => a.value !== null), v = {
|
|
5
5
|
baseURL: "",
|
|
6
6
|
timeout: 1e4,
|
|
7
7
|
retry: 0,
|
|
8
8
|
retryDelay: 1e3,
|
|
9
9
|
headers: {
|
|
10
10
|
"Content-Type": "application/json",
|
|
11
|
-
"X-CSRF-TOKEN":
|
|
11
|
+
"X-CSRF-TOKEN": H()
|
|
12
12
|
},
|
|
13
13
|
...b
|
|
14
|
-
},
|
|
14
|
+
}, w = (e, s) => {
|
|
15
15
|
if (e.startsWith("http://") || e.startsWith("https://"))
|
|
16
16
|
return e;
|
|
17
|
-
const t =
|
|
17
|
+
const t = s || v.baseURL || "";
|
|
18
18
|
return t.endsWith("/") && e.startsWith("/") ? `${t}${e.slice(1)}` : t.endsWith("/") || e.startsWith("/") ? `${t}${e}` : `${t}/${e}`;
|
|
19
|
-
},
|
|
19
|
+
}, P = (e) => new Promise((s, t) => {
|
|
20
20
|
setTimeout(() => {
|
|
21
21
|
t(new Error("Request timeout"));
|
|
22
22
|
}, e);
|
|
23
|
-
}),
|
|
24
|
-
setTimeout(
|
|
25
|
-
}), i = async (e,
|
|
26
|
-
|
|
27
|
-
const
|
|
23
|
+
}), x = (e) => new Promise((s) => {
|
|
24
|
+
setTimeout(s, e);
|
|
25
|
+
}), i = async (e, s, t, D = {}) => {
|
|
26
|
+
a.value = null, h.value = !0, u.value = new AbortController();
|
|
27
|
+
const n = { ...v, ...D }, L = w(s, n.baseURL), c = {
|
|
28
28
|
method: e,
|
|
29
|
-
headers: { ...
|
|
29
|
+
headers: { ...n.headers },
|
|
30
30
|
signal: u.value.signal,
|
|
31
|
-
...
|
|
31
|
+
...n
|
|
32
32
|
};
|
|
33
33
|
t && ["POST", "PUT", "PATCH"].includes(e) && (t instanceof FormData ? (delete c.headers["Content-Type"], c.body = t) : c.body = JSON.stringify(t));
|
|
34
34
|
const E = async (m = 0) => {
|
|
35
35
|
try {
|
|
36
|
-
const o = [fetch(
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
40
|
-
const O = `HTTP Error: ${
|
|
41
|
-
throw
|
|
42
|
-
detail: {
|
|
43
|
-
status: s.status,
|
|
44
|
-
body: H,
|
|
45
|
-
url: new URL(T, window.location.href).href
|
|
46
|
-
}
|
|
47
|
-
}))).catch(() => {
|
|
48
|
-
}), h;
|
|
36
|
+
const o = [fetch(L, c)];
|
|
37
|
+
n.timeout && o.push(P(n.timeout));
|
|
38
|
+
const r = await Promise.race(o);
|
|
39
|
+
if (!r.ok) {
|
|
40
|
+
const O = `HTTP Error: ${r.status} ${r.statusText}`, d = new Error(O);
|
|
41
|
+
throw d.status = r.status, d.statusText = r.statusText, d.response = r, d;
|
|
49
42
|
}
|
|
50
43
|
let f;
|
|
51
|
-
const l =
|
|
52
|
-
return l != null && l.includes("application/json") ? f = await
|
|
44
|
+
const l = r.headers.get("content-type");
|
|
45
|
+
return l != null && l.includes("application/json") ? f = await r.json() : l != null && l.includes("text/") ? f = await r.text() : f = await r.blob(), {
|
|
53
46
|
data: f,
|
|
54
|
-
status:
|
|
55
|
-
statusText:
|
|
56
|
-
headers:
|
|
47
|
+
status: r.status,
|
|
48
|
+
statusText: r.statusText,
|
|
49
|
+
headers: r.headers
|
|
57
50
|
};
|
|
58
51
|
} catch (o) {
|
|
59
|
-
const
|
|
60
|
-
if (m < (
|
|
61
|
-
return await
|
|
62
|
-
throw o instanceof Error ? o.name === "AbortError" ?
|
|
52
|
+
const r = o instanceof Error && o.name === "AbortError";
|
|
53
|
+
if (m < (n.retry || 0) && !r)
|
|
54
|
+
return await x(n.retryDelay || 1e3), E(m + 1);
|
|
55
|
+
throw o instanceof Error ? o.name === "AbortError" ? a.value = { message: "Request was cancelled" } : a.value = { message: o.message } : a.value = o, o;
|
|
63
56
|
}
|
|
64
57
|
};
|
|
65
58
|
try {
|
|
66
59
|
return await E();
|
|
67
60
|
} finally {
|
|
68
|
-
|
|
61
|
+
h.value = !1, u.value = null;
|
|
69
62
|
}
|
|
70
|
-
},
|
|
63
|
+
}, C = (e, s) => i("GET", e, void 0, s), $ = (e, s, t) => i("POST", e, s, t), R = (e, s, t) => i("PUT", e, s, t), U = (e, s, t) => i("PATCH", e, s, t), A = (e, s) => i("DELETE", e, void 0, s), W = (e) => {
|
|
71
64
|
u.value && u.value.abort(e);
|
|
72
65
|
}, q = () => {
|
|
73
|
-
|
|
66
|
+
a.value = null;
|
|
74
67
|
};
|
|
75
68
|
return {
|
|
76
69
|
// State
|
|
77
70
|
loading: g,
|
|
78
|
-
error:
|
|
71
|
+
error: T(() => a.value),
|
|
79
72
|
hasError: y,
|
|
80
73
|
// Methods
|
|
81
74
|
request: i,
|
|
82
|
-
get:
|
|
83
|
-
post:
|
|
84
|
-
put:
|
|
85
|
-
patch:
|
|
86
|
-
delete:
|
|
75
|
+
get: C,
|
|
76
|
+
post: $,
|
|
77
|
+
put: R,
|
|
78
|
+
patch: U,
|
|
79
|
+
delete: A,
|
|
87
80
|
cancel: W,
|
|
88
81
|
clearError: q
|
|
89
82
|
};
|
|
90
83
|
};
|
|
91
84
|
export {
|
|
92
|
-
|
|
85
|
+
k as useHttp
|
|
93
86
|
};
|
package/dist/package.json.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "3.18.0-beta.
|
|
3
|
+
"version": "3.18.0-beta.fda7e92",
|
|
4
4
|
"description": "Guido is a Vue + TypeScript wrapper for Email Plugin. Easily embed the email editor in your Vue applications.",
|
|
5
5
|
"main": "./dist/guido.umd.cjs",
|
|
6
6
|
"module": "./dist/library.js",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
},
|
|
119
119
|
"guido": {
|
|
120
120
|
"stripo": {
|
|
121
|
-
"version": "2.
|
|
121
|
+
"version": "2.73.0"
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
}
|