@useinsider/guido 3.19.0-beta.3e599a9 → 3.19.0-beta.87e26c0
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 +55 -44
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getCsrfToken as O } from "../utils/genericUtil.js";
|
|
2
|
-
import { ref as m, computed as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
2
|
+
import { ref as m, computed as w } from "vue";
|
|
3
|
+
const k = (g = {}) => {
|
|
4
|
+
const h = m(!1), n = m(null), u = m(null), b = w(() => h.value), y = w(() => n.value !== null), v = {
|
|
5
5
|
baseURL: "",
|
|
6
6
|
timeout: 1e4,
|
|
7
7
|
retry: 0,
|
|
@@ -10,79 +10,90 @@ const X = (b = {}) => {
|
|
|
10
10
|
"Content-Type": "application/json",
|
|
11
11
|
"X-CSRF-TOKEN": O(),
|
|
12
12
|
Accept: "application/json",
|
|
13
|
+
// The panel backend only answers 401/419 to ajax requests; without this a guest
|
|
14
|
+
// fetch gets a 302 to the login page and never sees an auth status.
|
|
13
15
|
"X-Requested-With": "XMLHttpRequest"
|
|
14
16
|
},
|
|
15
|
-
...
|
|
16
|
-
},
|
|
17
|
+
...g
|
|
18
|
+
}, x = (e, r) => {
|
|
17
19
|
if (e.startsWith("http://") || e.startsWith("https://"))
|
|
18
20
|
return e;
|
|
19
|
-
const t =
|
|
21
|
+
const t = r || v.baseURL || "";
|
|
20
22
|
return t.endsWith("/") && e.startsWith("/") ? `${t}${e.slice(1)}` : t.endsWith("/") || e.startsWith("/") ? `${t}${e}` : `${t}/${e}`;
|
|
21
|
-
}, P = (e) => new Promise((
|
|
23
|
+
}, P = (e) => new Promise((r, t) => {
|
|
22
24
|
setTimeout(() => {
|
|
23
25
|
t(new Error("Request timeout"));
|
|
24
26
|
}, e);
|
|
25
|
-
}),
|
|
26
|
-
setTimeout(
|
|
27
|
-
}), i = async (e,
|
|
28
|
-
|
|
29
|
-
const
|
|
27
|
+
}), C = (e) => new Promise((r) => {
|
|
28
|
+
setTimeout(r, e);
|
|
29
|
+
}), i = async (e, r, t, W = {}) => {
|
|
30
|
+
n.value = null, h.value = !0, u.value = new AbortController();
|
|
31
|
+
const a = { ...v, ...W }, E = x(r, a.baseURL), c = {
|
|
30
32
|
method: e,
|
|
31
|
-
headers: { ...
|
|
33
|
+
headers: { ...a.headers },
|
|
32
34
|
signal: u.value.signal,
|
|
33
|
-
...
|
|
35
|
+
...a
|
|
34
36
|
};
|
|
35
37
|
t && ["POST", "PUT", "PATCH"].includes(e) && (t instanceof FormData ? (delete c.headers["Content-Type"], c.body = t) : c.body = JSON.stringify(t));
|
|
36
|
-
const
|
|
38
|
+
const T = async (p = 0) => {
|
|
39
|
+
if (window.isSessionExpired)
|
|
40
|
+
throw n.value = { message: "Session expired" }, new Error("Session expired");
|
|
37
41
|
try {
|
|
38
|
-
const o = [fetch(
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
if (!
|
|
42
|
-
const
|
|
43
|
-
throw
|
|
42
|
+
const o = [fetch(E, c)];
|
|
43
|
+
a.timeout && o.push(P(a.timeout));
|
|
44
|
+
const s = await Promise.race(o);
|
|
45
|
+
if (!s.ok) {
|
|
46
|
+
const D = `HTTP Error: ${s.status} ${s.statusText}`, f = new Error(D);
|
|
47
|
+
throw f.status = s.status, f.statusText = s.statusText, f.response = s, [401, 403, 419].includes(s.status) && Promise.resolve().then(() => s.clone().text().catch(() => "")).then((H) => window.dispatchEvent(new CustomEvent("insider:http-auth-error", {
|
|
48
|
+
detail: {
|
|
49
|
+
status: s.status,
|
|
50
|
+
body: H,
|
|
51
|
+
url: new URL(E, window.location.href).href
|
|
52
|
+
}
|
|
53
|
+
}))).catch(() => {
|
|
54
|
+
}), f;
|
|
44
55
|
}
|
|
45
|
-
let
|
|
46
|
-
const l =
|
|
47
|
-
return l != null && l.includes("application/json") ?
|
|
48
|
-
data:
|
|
49
|
-
status:
|
|
50
|
-
statusText:
|
|
51
|
-
headers:
|
|
56
|
+
let d;
|
|
57
|
+
const l = s.headers.get("content-type");
|
|
58
|
+
return l != null && l.includes("application/json") ? d = await s.json() : l != null && l.includes("text/") ? d = await s.text() : d = await s.blob(), {
|
|
59
|
+
data: d,
|
|
60
|
+
status: s.status,
|
|
61
|
+
statusText: s.statusText,
|
|
62
|
+
headers: s.headers
|
|
52
63
|
};
|
|
53
64
|
} catch (o) {
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
return await
|
|
57
|
-
throw o instanceof Error ? o.name === "AbortError" ?
|
|
65
|
+
const s = o instanceof Error && o.name === "AbortError";
|
|
66
|
+
if (p < (a.retry || 0) && !s)
|
|
67
|
+
return await C(a.retryDelay || 1e3), T(p + 1);
|
|
68
|
+
throw o instanceof Error ? o.name === "AbortError" ? n.value = { message: "Request was cancelled" } : n.value = { message: o.message } : n.value = o, o;
|
|
58
69
|
}
|
|
59
70
|
};
|
|
60
71
|
try {
|
|
61
|
-
return await
|
|
72
|
+
return await T();
|
|
62
73
|
} finally {
|
|
63
|
-
|
|
74
|
+
h.value = !1, u.value = null;
|
|
64
75
|
}
|
|
65
|
-
},
|
|
76
|
+
}, R = (e, r) => i("GET", e, void 0, r), U = (e, r, t) => i("POST", e, r, t), $ = (e, r, t) => i("PUT", e, r, t), q = (e, r, t) => i("PATCH", e, r, t), A = (e, r) => i("DELETE", e, void 0, r), L = (e) => {
|
|
66
77
|
u.value && u.value.abort(e);
|
|
67
|
-
},
|
|
68
|
-
|
|
78
|
+
}, S = () => {
|
|
79
|
+
n.value = null;
|
|
69
80
|
};
|
|
70
81
|
return {
|
|
71
82
|
// State
|
|
72
|
-
loading:
|
|
73
|
-
error:
|
|
83
|
+
loading: b,
|
|
84
|
+
error: w(() => n.value),
|
|
74
85
|
hasError: y,
|
|
75
86
|
// Methods
|
|
76
87
|
request: i,
|
|
77
|
-
get:
|
|
78
|
-
post:
|
|
88
|
+
get: R,
|
|
89
|
+
post: U,
|
|
79
90
|
put: $,
|
|
80
91
|
patch: q,
|
|
81
92
|
delete: A,
|
|
82
|
-
cancel:
|
|
83
|
-
clearError:
|
|
93
|
+
cancel: L,
|
|
94
|
+
clearError: S
|
|
84
95
|
};
|
|
85
96
|
};
|
|
86
97
|
export {
|
|
87
|
-
|
|
98
|
+
k as useHttp
|
|
88
99
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "3.19.0-beta.
|
|
3
|
+
"version": "3.19.0-beta.87e26c0",
|
|
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",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@stripoinc/ui-editor-extensions": "3.10.0",
|
|
55
55
|
"@useinsider/design-system-organisms": "0.0.3-beta.d816f06",
|
|
56
|
-
"@useinsider/design-system-vue": "
|
|
56
|
+
"@useinsider/design-system-vue": "1.5.0",
|
|
57
57
|
"@vueuse/core": "11.3.0",
|
|
58
58
|
"lodash-es": "4.17.21",
|
|
59
59
|
"pinia": "2.3.1",
|