@useinsider/guido 3.19.0-beta.1821257 → 3.19.0-beta.21d256c

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