@useinsider/guido 3.19.0-beta.acb00a2 → 3.19.0-beta.b73a570
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/components/Guido.vue.js +8 -8
- package/dist/components/Guido.vue2.js +67 -72
- package/dist/components/organisms/base/AuthErrorModal.vue.js +18 -0
- package/dist/components/organisms/base/AuthErrorModal.vue2.js +42 -0
- package/dist/components/organisms/header/EditorActions.vue.js +4 -4
- package/dist/components/organisms/header/EditorActions.vue2.js +23 -25
- package/dist/components/wrappers/WpModal.vue.js +1 -1
- package/dist/components/wrappers/WpModal.vue2.js +4 -3
- package/dist/composables/useActionsApi.js +44 -43
- package/dist/composables/useAuthError.js +52 -0
- package/dist/composables/useCodeEditorApi.js +23 -9
- package/dist/composables/useCortexBlueprintBridge.js +54 -122
- package/dist/composables/useEmailTemplateApplier.js +52 -108
- package/dist/composables/useHttp.js +64 -54
- package/dist/composables/useToaster.js +17 -15
- package/dist/composables/useTranslations.js +3 -2
- package/dist/composables/useVersionHistoryApi.js +33 -24
- package/dist/composables/validators/useLiquidValidator.js +15 -15
- package/dist/guido.css +1 -1
- package/dist/src/components/organisms/base/AuthErrorModal.vue.d.ts +2 -0
- package/dist/src/components/wrappers/WpModal.vue.d.ts +5 -1
- package/dist/src/composables/useAuthError.d.ts +12 -0
- package/dist/src/composables/useCortexBlueprintBridge.d.ts +3 -2
- package/dist/src/composables/useEmailTemplateApplier.d.ts +5 -18
- package/dist/src/composables/useHttp.d.ts +2 -0
- package/dist/src/stores/guido-email-editor.d.ts +10 -20
- package/dist/src/utils/stripoEditorApi.d.ts +4 -0
- package/dist/stores/guido-email-editor.js +1 -3
- package/dist/stores/unsubscribe.js +3 -3
- package/dist/utils/stripoEditorApi.js +11 -0
- package/package.json +2 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ToasterTypeOptions as l } from "../enums/toaster.js";
|
|
2
|
+
import { ref as p } from "vue";
|
|
3
|
+
import { useToaster as u } from "./useToaster.js";
|
|
4
|
+
import { useTranslations as f } from "./useTranslations.js";
|
|
5
|
+
const d = ["accessExpired", "domainRestricted", "ipRestricted", "insiderAccessRestricted"], n = p(null), a = (e) => {
|
|
6
|
+
try {
|
|
7
|
+
return new URL(e, window.location.href).origin === window.location.origin;
|
|
8
|
+
} catch {
|
|
9
|
+
return !0;
|
|
10
|
+
}
|
|
11
|
+
}, g = (e) => {
|
|
12
|
+
try {
|
|
13
|
+
const o = new URL(e, window.location.href);
|
|
14
|
+
return o.origin === window.location.origin ? o.href : "";
|
|
15
|
+
} catch {
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
}, w = (e) => {
|
|
19
|
+
try {
|
|
20
|
+
const o = JSON.parse(e);
|
|
21
|
+
return o && typeof o == "object" && Object.keys(o).length ? o : null;
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}, y = (e) => typeof (e == null ? void 0 : e.message) == "string" ? e.message : "", s = (e) => y(e) || f()("user-management.collaborate-forbidden-action"), c = (e) => {
|
|
26
|
+
u().showToaster({ type: l.Error, message: e });
|
|
27
|
+
}, R = (e, o, t) => {
|
|
28
|
+
if (t && !a(t))
|
|
29
|
+
return;
|
|
30
|
+
const r = w(o);
|
|
31
|
+
if (e === 403) {
|
|
32
|
+
c(s(r));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (e === 401 && (r == null ? void 0 : r.type) === "groupLevelAccess") {
|
|
36
|
+
c(s(r));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (e === 401 && typeof (r == null ? void 0 : r.type) == "string" && d.includes(r.type)) {
|
|
40
|
+
const i = typeof r.redirect == "string" ? g(r.redirect) : "";
|
|
41
|
+
if (i) {
|
|
42
|
+
window.location.replace(i);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
e !== 401 && e !== 419 || n.value || (window.isSessionExpired = !0, n.value = { status: e, data: r });
|
|
47
|
+
}, T = () => ({ authError: n });
|
|
48
|
+
export {
|
|
49
|
+
a as isPanelOrigin,
|
|
50
|
+
R as reportAuthError,
|
|
51
|
+
T as useAuthError
|
|
52
|
+
};
|
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ToasterTypeOptions as d } from "../enums/toaster.js";
|
|
2
|
+
import { findEditorApi as s, EDITOR_NOT_READY_MESSAGE as p } from "../utils/stripoEditorApi.js";
|
|
3
|
+
import { useToaster as E } from "./useToaster.js";
|
|
4
|
+
const T = () => {
|
|
5
|
+
const { showToaster: i } = E(), t = (o) => {
|
|
6
|
+
var r;
|
|
7
|
+
const e = (r = s()) == null ? void 0 : r.codeEditorApi;
|
|
8
|
+
if (!e) {
|
|
9
|
+
i({ type: d.Error, message: p });
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
o(e);
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
openCodeEditor: () => {
|
|
16
|
+
t((o) => o.openCodeEditor());
|
|
17
|
+
},
|
|
18
|
+
closeCodeEditor: () => {
|
|
19
|
+
t((o) => o.closeCodeEditor());
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
9
23
|
export {
|
|
10
|
-
|
|
24
|
+
T as useCodeEditorApi
|
|
11
25
|
};
|
|
@@ -1,138 +1,70 @@
|
|
|
1
|
-
import { useEmailTemplateApplier as
|
|
2
|
-
import { useToaster as
|
|
3
|
-
import { useTranslations as
|
|
4
|
-
import { ToasterTypeOptions as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
const rt = "email_template", nt = "chat", ot = "guido:debug:ai", it = 2, lt = 500, ct = (b, p) => `${b}:${p ?? 1}`;
|
|
9
|
-
let S = null;
|
|
10
|
-
const at = () => {
|
|
1
|
+
import { useEmailTemplateApplier as w, resetEmailTemplateApplier as _ } from "./useEmailTemplateApplier.js";
|
|
2
|
+
import { useToaster as I } from "./useToaster.js";
|
|
3
|
+
import { useTranslations as P } from "./useTranslations.js";
|
|
4
|
+
import { ToasterTypeOptions as S } from "../enums/toaster.js";
|
|
5
|
+
import { getActivePinia as v } from "pinia";
|
|
6
|
+
import { watch as B, onUnmounted as D } from "vue";
|
|
7
|
+
const x = "email_template", L = "chat", M = "guido:debug:ai", R = () => {
|
|
11
8
|
if (typeof window > "u")
|
|
12
9
|
return !1;
|
|
13
10
|
try {
|
|
14
|
-
return window.localStorage.getItem(
|
|
11
|
+
return window.localStorage.getItem(M) === "1";
|
|
15
12
|
} catch {
|
|
16
13
|
return !1;
|
|
17
14
|
}
|
|
18
|
-
},
|
|
19
|
-
const
|
|
20
|
-
if (!
|
|
15
|
+
}, H = () => {
|
|
16
|
+
const c = v();
|
|
17
|
+
if (!c)
|
|
21
18
|
return;
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}, U = () => new Set((A == null ? void 0 : A.appliedBlueprintKeys) ?? []), Y = (t) => t instanceof Error ? t.message : String(t), D = (t, r, n, e) => {
|
|
33
|
-
if (S !== M)
|
|
34
|
-
return;
|
|
35
|
-
const o = p.applyAcks[t], c = Math.max(Date.now(), ((o == null ? void 0 : o.ackAt) ?? 0) + 1), a = { status: r, requestedAt: n, ackAt: c };
|
|
36
|
-
e !== void 0 && (a.error = Y(e)), p.$patch((l) => {
|
|
37
|
-
l.applyAcks = { ...l.applyAcks, [t]: a };
|
|
38
|
-
});
|
|
39
|
-
}, I = (t) => (d.get(t) ?? 0) > 0, P = (t) => (s == null ? void 0 : s.key) === t, v = async (t, r, n) => {
|
|
40
|
-
var a, l, h;
|
|
41
|
-
const e = ((a = r.blueprintData) == null ? void 0 : a.html) ?? "", o = ((l = r.blueprintData) == null ? void 0 : l.css) ?? "", c = r.applyRequestedAt ?? 0;
|
|
42
|
-
d.set(t, (d.get(t) ?? 0) + 1);
|
|
43
|
-
try {
|
|
44
|
-
const i = n === "debounced" ? await O(t, { html: e, css: o }) : await H(t, { html: e, css: o });
|
|
45
|
-
if (i.status === "superseded")
|
|
46
|
-
return;
|
|
47
|
-
if (i.status === "applied") {
|
|
48
|
-
E.set(t, e), u.delete(t), D(t, "applied", c);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const y = u.get(t), j = (y == null ? void 0 : y.html) === e ? y.count + 1 : 1;
|
|
52
|
-
u.set(t, { html: e, count: j }), D(t, "failed", c, i.error);
|
|
53
|
-
} catch (i) {
|
|
54
|
-
console.error("[guido:apply] apply threw before it could settle", i), D(t, "failed", c, i);
|
|
55
|
-
} finally {
|
|
56
|
-
d.set(t, (d.get(t) ?? 1) - 1);
|
|
57
|
-
const i = T.get(t);
|
|
58
|
-
i && !I(t) && (T.delete(t), P(t) && (((h = i.blueprintData) == null ? void 0 : h.html) ?? "") !== e && v(t, i, n));
|
|
59
|
-
}
|
|
60
|
-
}, N = (t) => {
|
|
61
|
-
var h;
|
|
62
|
-
if (t.blueprintType !== rt)
|
|
63
|
-
return;
|
|
64
|
-
const { blueprintId: r } = t, n = (h = t.blueprintData) == null ? void 0 : h.html;
|
|
65
|
-
if (!r || !n)
|
|
66
|
-
return;
|
|
67
|
-
const e = ct(r, t.version);
|
|
68
|
-
if (!t.applyRequested) {
|
|
69
|
-
F(e);
|
|
19
|
+
const l = c._s, p = l == null ? void 0 : l.get(L);
|
|
20
|
+
if (!p)
|
|
21
|
+
return;
|
|
22
|
+
const { markPending: d, applyTemplate: f, applyTemplateDebounced: T } = w(), { showToaster: E } = I(), h = P(), y = (r, t) => {
|
|
23
|
+
const e = h(r);
|
|
24
|
+
return e === r ? t : e;
|
|
25
|
+
}, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), u = R(), A = (r, t) => {
|
|
26
|
+
u && console.debug(`[guido:cortex] msg=${r ?? "?"} type=${(t == null ? void 0 : t.type) ?? "?"}`, t);
|
|
27
|
+
}, b = (r) => {
|
|
28
|
+
if (r.blueprintType !== x)
|
|
70
29
|
return;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (c === void 0 || o > c) {
|
|
74
|
-
const i = c === void 0;
|
|
75
|
-
if (_.set(e, o), u.delete(e), (!s || o >= s.requestedAt) && (s = { key: e, requestedAt: o }), i && U().has(e)) {
|
|
76
|
-
E.set(e, n);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
v(e, t, "immediate");
|
|
30
|
+
const t = r.blueprintId, e = r.blueprintData;
|
|
31
|
+
if (!t || !(e != null && e.html))
|
|
80
32
|
return;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (a === n || !P(e))
|
|
33
|
+
if (!r.applyRequested) {
|
|
34
|
+
d(t);
|
|
84
35
|
return;
|
|
85
|
-
const l = u.get(e);
|
|
86
|
-
if (!((l == null ? void 0 : l.html) === n && l.count >= it)) {
|
|
87
|
-
if (a === void 0) {
|
|
88
|
-
if (I(e)) {
|
|
89
|
-
T.set(e, t);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
v(e, t, "immediate");
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
f.get(e) !== n && (f.set(e, n), v(e, t, "debounced").finally(() => {
|
|
96
|
-
f.get(e) === n && f.delete(e);
|
|
97
|
-
}));
|
|
98
36
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
Array.isArray(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
37
|
+
const o = i.get(t);
|
|
38
|
+
o === void 0 ? (i.set(t, e.html), f(t, e)) : o !== e.html && (i.set(t, e.html), T(t, e));
|
|
39
|
+
}, s = (r) => r === void 0 || a.has(r) ? !1 : (a.add(r), E({
|
|
40
|
+
type: S.Error,
|
|
41
|
+
message: y("newsletter.ai-template-failed", "AI couldn't generate the template. Please try again.")
|
|
42
|
+
}), !0), m = B(
|
|
43
|
+
() => p.messages,
|
|
44
|
+
(r) => {
|
|
45
|
+
Array.isArray(r) && r.forEach((t) => {
|
|
46
|
+
const e = t == null ? void 0 : t.id;
|
|
47
|
+
(t == null ? void 0 : t.isError) === !0 && s(e) && u && console.debug(`[guido:cortex] message-level error id=${e}`, t);
|
|
48
|
+
const o = t == null ? void 0 : t.segments;
|
|
49
|
+
Array.isArray(o) && o.forEach((n) => {
|
|
50
|
+
if (n)
|
|
51
|
+
switch (A(e, n), n.type) {
|
|
52
|
+
case "blueprint":
|
|
53
|
+
b(n);
|
|
54
|
+
break;
|
|
55
|
+
case "error":
|
|
56
|
+
s(e);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
117
60
|
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return (t = b._s) == null ? void 0 : t.get(nt);
|
|
124
|
-
}, L = (t) => {
|
|
125
|
-
A = t, m = et(() => t.messages, X, { deep: !0, immediate: !0 });
|
|
126
|
-
}, x = q();
|
|
127
|
-
x ? L(x) : w = setInterval(() => {
|
|
128
|
-
const t = q();
|
|
129
|
-
t && ($(), L(t));
|
|
130
|
-
}, lt), tt(() => {
|
|
131
|
-
$(), m == null || m(), A = void 0, E.clear(), f.clear(), _.clear(), u.clear(), s = null, d.clear(), T.clear(), g.clear(), S === M && (S = null, p.$patch((t) => {
|
|
132
|
-
t.bridgeActive = !1, t.applyAcks = {};
|
|
133
|
-
}), J());
|
|
61
|
+
},
|
|
62
|
+
{ deep: !0, immediate: !0 }
|
|
63
|
+
);
|
|
64
|
+
D(() => {
|
|
65
|
+
m(), i.clear(), a.clear(), _();
|
|
134
66
|
});
|
|
135
67
|
};
|
|
136
68
|
export {
|
|
137
|
-
|
|
69
|
+
H as useCortexBlueprintBridge
|
|
138
70
|
};
|
|
@@ -1,115 +1,59 @@
|
|
|
1
|
-
import { useActionsApi as
|
|
2
|
-
import { useConfig as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
type: U.Error,
|
|
20
|
-
message: w("newsletter.ai-template-failed-apply")
|
|
21
|
-
}));
|
|
22
|
-
}, C = () => {
|
|
23
|
-
var e, t;
|
|
24
|
-
return g.isStripoInitialized && typeof ((t = (e = window.StripoEditorApi) == null ? void 0 : e.actionsApi) == null ? void 0 : t.updateHtmlAndCss) == "function";
|
|
25
|
-
}, L = (e) => {
|
|
26
|
-
a.value[e] === void 0 && (a.value = { ...a.value, [e]: "pending" });
|
|
27
|
-
}, l = (e, t) => {
|
|
28
|
-
a.value = { ...a.value, [e]: t };
|
|
29
|
-
}, Q = (e) => {
|
|
30
|
-
var t;
|
|
1
|
+
import { useActionsApi as C } from "./useActionsApi.js";
|
|
2
|
+
import { useConfig as h } from "./useConfig.js";
|
|
3
|
+
import { useToaster as D } from "./useToaster.js";
|
|
4
|
+
import { useTranslations as E } from "./useTranslations.js";
|
|
5
|
+
import { ToasterTypeOptions as f } from "../enums/toaster.js";
|
|
6
|
+
import { useDynamicContentStore as A } from "../stores/dynamic-content.js";
|
|
7
|
+
import { flattenDynamicContentList as w } from "../utils/genericUtil.js";
|
|
8
|
+
import { extractUsedDynamicContent as S } from "../utils/registerUsedDynamicContent.js";
|
|
9
|
+
import { ref as O } from "vue";
|
|
10
|
+
const U = 250, o = O({}), s = {}, u = /* @__PURE__ */ new Map(), z = () => {
|
|
11
|
+
const { updateHtmlAndCss: r } = C(), { showToaster: m } = D(), y = E(), { template: T } = h(), d = A(), g = (e, t) => {
|
|
12
|
+
const a = y(e);
|
|
13
|
+
return a === e ? t : a;
|
|
14
|
+
}, v = (e) => {
|
|
15
|
+
o.value[e] === void 0 && (o.value = { ...o.value, [e]: "pending" });
|
|
16
|
+
}, l = (e, t, a) => {
|
|
17
|
+
var c;
|
|
18
|
+
o.value = { ...o.value, [e]: "applying" };
|
|
31
19
|
try {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
return u.get(e) !== n ? p : (l(e, "applied"), Q(t), H(e, t), { status: "applied" });
|
|
50
|
-
}, I = (e) => {
|
|
51
|
-
const t = s.get(e);
|
|
52
|
-
t && (clearTimeout(t.timer), s.delete(e), t.settle(p));
|
|
53
|
-
}, S = (e) => {
|
|
54
|
-
const t = c.get(e);
|
|
55
|
-
t && (clearTimeout(t.timer), c.delete(e), t.settle(p));
|
|
56
|
-
}, B = () => {
|
|
57
|
-
[...c.keys()].forEach(S);
|
|
58
|
-
}, h = async () => {
|
|
59
|
-
if (s.size === 0) {
|
|
60
|
-
E();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (!C())
|
|
64
|
-
return;
|
|
65
|
-
E();
|
|
66
|
-
const e = [...s.entries()];
|
|
67
|
-
s.clear(), e.forEach(([, o]) => clearTimeout(o.timer));
|
|
68
|
-
const t = e.pop();
|
|
69
|
-
if (e.forEach(([o, f]) => {
|
|
70
|
-
l(o, "failed"), f.settle({ status: "failed", error: new Error("Displaced by a newer apply") });
|
|
71
|
-
}), !t)
|
|
72
|
-
return;
|
|
73
|
-
const [r, n] = t;
|
|
74
|
-
n.settle(await D(r, n.html, n.css));
|
|
75
|
-
}, q = (e, t, r) => new Promise((n) => {
|
|
76
|
-
I(e);
|
|
77
|
-
const o = setTimeout(() => {
|
|
78
|
-
s.delete(e), l(e, "failed"), y(e, t), n({
|
|
79
|
-
status: "failed",
|
|
80
|
-
error: new Error(`Editor did not become ready within ${M}ms`)
|
|
20
|
+
r(t, a).catch((n) => {
|
|
21
|
+
console.warn("Editor did not acknowledge the template apply.", n);
|
|
22
|
+
}), o.value = { ...o.value, [e]: "applied" };
|
|
23
|
+
try {
|
|
24
|
+
const n = w((c = T.value) == null ? void 0 : c.dynamicContentList), i = S(t, n);
|
|
25
|
+
i.length > 0 && d.registerDynamicContent(i);
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
u.get(e) !== t && (u.set(e, t), m({
|
|
29
|
+
type: f.Success,
|
|
30
|
+
message: g("newsletter.ai-template-applied", "Template applied to the editor")
|
|
31
|
+
}));
|
|
32
|
+
} catch (n) {
|
|
33
|
+
o.value = { ...o.value, [e]: "failed" }, m({
|
|
34
|
+
type: f.Error,
|
|
35
|
+
message: n instanceof Error ? n.message : "Failed to apply template"
|
|
81
36
|
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
}, { immediate: !0 }), { applyStatus: a, markPending: L, applyTemplate: (e, t) => {
|
|
90
|
-
const { html: r } = t;
|
|
91
|
-
return r ? (B(), v(e, r, t.css ?? "")) : Promise.resolve(A);
|
|
37
|
+
}
|
|
38
|
+
}, p = (e) => {
|
|
39
|
+
const t = s[e];
|
|
40
|
+
t && (clearTimeout(t), delete s[e]);
|
|
41
|
+
};
|
|
42
|
+
return { applyStatus: o, markPending: v, applyTemplate: (e, t) => {
|
|
43
|
+
t.html && (p(e), l(e, t.html, t.css ?? ""));
|
|
92
44
|
}, applyTemplateDebounced: (e, t) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
c.delete(e), v(e, r, n).then(o);
|
|
101
|
-
}, W);
|
|
102
|
-
c.set(e, { timer: f, settle: o });
|
|
103
|
-
});
|
|
45
|
+
if (!t.html)
|
|
46
|
+
return;
|
|
47
|
+
p(e);
|
|
48
|
+
const { html: a } = t, c = t.css ?? "";
|
|
49
|
+
s[e] = setTimeout(() => {
|
|
50
|
+
delete s[e], l(e, a, c);
|
|
51
|
+
}, U);
|
|
104
52
|
} };
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
clearTimeout(i.timer), i.settle(p);
|
|
108
|
-
}), c.clear(), s.forEach((i) => {
|
|
109
|
-
clearTimeout(i.timer), i.settle(p);
|
|
110
|
-
}), s.clear(), E(), m.clear(), a.value = {};
|
|
53
|
+
}, G = () => {
|
|
54
|
+
Object.values(s).forEach(clearTimeout), Object.keys(s).forEach((r) => delete s[r]), o.value = {};
|
|
111
55
|
};
|
|
112
56
|
export {
|
|
113
|
-
|
|
114
|
-
|
|
57
|
+
G as resetEmailTemplateApplier,
|
|
58
|
+
z as useEmailTemplateApplier
|
|
115
59
|
};
|
|
@@ -1,88 +1,98 @@
|
|
|
1
|
-
import { getCsrfToken as
|
|
2
|
-
import { ref as
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { getCsrfToken as D } from "../utils/genericUtil.js";
|
|
2
|
+
import { ref as T, computed as w } from "vue";
|
|
3
|
+
import { isPanelOrigin as j, reportAuthError as X } from "./useAuthError.js";
|
|
4
|
+
const k = [401, 403, 419], _ = (g = {}) => {
|
|
5
|
+
const f = T(!1), n = T(null), c = T(null), b = w(() => f.value), y = w(() => n.value !== null), E = {
|
|
5
6
|
baseURL: "",
|
|
6
7
|
timeout: 1e4,
|
|
7
8
|
retry: 0,
|
|
8
9
|
retryDelay: 1e3,
|
|
9
10
|
headers: {
|
|
10
11
|
"Content-Type": "application/json",
|
|
11
|
-
"X-CSRF-TOKEN":
|
|
12
|
+
"X-CSRF-TOKEN": D(),
|
|
12
13
|
Accept: "application/json",
|
|
14
|
+
// Without this a guest fetch gets a 302 to the login page, never 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 || E.baseURL || "";
|
|
20
22
|
return t.endsWith("/") && e.startsWith("/") ? `${t}${e.slice(1)}` : t.endsWith("/") || e.startsWith("/") ? `${t}${e}` : `${t}/${e}`;
|
|
21
|
-
},
|
|
23
|
+
}, R = (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
|
+
}), P = (e) => new Promise((r) => {
|
|
28
|
+
setTimeout(r, e);
|
|
29
|
+
}), i = async (e, r, t, W = {}) => {
|
|
30
|
+
n.value = null, f.value = !0, c.value = new AbortController();
|
|
31
|
+
const a = { ...E, ...W }, p = x(r, a.baseURL), d = {
|
|
30
32
|
method: e,
|
|
31
|
-
headers: { ...
|
|
32
|
-
signal:
|
|
33
|
-
...
|
|
33
|
+
headers: { ...a.headers },
|
|
34
|
+
signal: c.value.signal,
|
|
35
|
+
...a
|
|
34
36
|
};
|
|
35
|
-
t && ["POST", "PUT", "PATCH"].includes(e) && (t instanceof FormData ? (delete
|
|
36
|
-
const
|
|
37
|
+
t && ["POST", "PUT", "PATCH"].includes(e) && (t instanceof FormData ? (delete d.headers["Content-Type"], d.body = t) : d.body = JSON.stringify(t));
|
|
38
|
+
const v = async (m = 0) => {
|
|
39
|
+
if (window.isSessionExpired) {
|
|
40
|
+
n.value = { message: "Session expired", authReported: !0 };
|
|
41
|
+
const o = new Error("Session expired");
|
|
42
|
+
throw o.authReported = !0, o;
|
|
43
|
+
}
|
|
37
44
|
try {
|
|
38
|
-
const o = [fetch(
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
if (!
|
|
42
|
-
const H = `HTTP Error: ${
|
|
43
|
-
throw
|
|
45
|
+
const o = [fetch(p, d)];
|
|
46
|
+
a.timeout && o.push(R(a.timeout));
|
|
47
|
+
const s = await Promise.race(o);
|
|
48
|
+
if (!s.ok) {
|
|
49
|
+
const H = `HTTP Error: ${s.status} ${s.statusText}`, l = new Error(H);
|
|
50
|
+
throw l.status = s.status, l.statusText = s.statusText, l.response = s, l.authReported = k.includes(s.status) && j(p), l.authReported && Promise.resolve().then(() => s.clone().text().catch(() => "")).then((O) => X(
|
|
51
|
+
s.status,
|
|
52
|
+
O,
|
|
53
|
+
new URL(p, window.location.href).href
|
|
54
|
+
)).catch(() => {
|
|
55
|
+
}), l;
|
|
44
56
|
}
|
|
45
|
-
let
|
|
46
|
-
const
|
|
47
|
-
return
|
|
48
|
-
data:
|
|
49
|
-
status:
|
|
50
|
-
statusText:
|
|
51
|
-
headers:
|
|
57
|
+
let h;
|
|
58
|
+
const u = s.headers.get("content-type");
|
|
59
|
+
return u != null && u.includes("application/json") ? h = await s.json() : u != null && u.includes("text/") ? h = await s.text() : h = await s.blob(), {
|
|
60
|
+
data: h,
|
|
61
|
+
status: s.status,
|
|
62
|
+
statusText: s.statusText,
|
|
63
|
+
headers: s.headers
|
|
52
64
|
};
|
|
53
65
|
} catch (o) {
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
return await
|
|
57
|
-
throw o instanceof Error ? o.name === "AbortError" ?
|
|
66
|
+
const s = o instanceof Error && o.name === "AbortError";
|
|
67
|
+
if (m < (a.retry || 0) && !s)
|
|
68
|
+
return await P(a.retryDelay || 1e3), v(m + 1);
|
|
69
|
+
throw o instanceof Error ? o.name === "AbortError" ? n.value = { message: "Request was cancelled" } : n.value = { message: o.message } : n.value = o, o;
|
|
58
70
|
}
|
|
59
71
|
};
|
|
60
72
|
try {
|
|
61
|
-
return await
|
|
73
|
+
return await v();
|
|
62
74
|
} finally {
|
|
63
|
-
|
|
75
|
+
f.value = !1, c.value = null;
|
|
64
76
|
}
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
|
|
77
|
+
}, A = (e, r) => i("GET", e, void 0, r), S = (e, r, t) => i("POST", e, r, t), U = (e, r, t) => i("PUT", e, r, t), C = (e, r, t) => i("PATCH", e, r, t), $ = (e, r) => i("DELETE", e, void 0, r), q = (e) => {
|
|
78
|
+
c.value && c.value.abort(e);
|
|
79
|
+
}, L = () => {
|
|
80
|
+
n.value = null;
|
|
69
81
|
};
|
|
70
82
|
return {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
error: T(() => a.value),
|
|
83
|
+
loading: b,
|
|
84
|
+
error: w(() => n.value),
|
|
74
85
|
hasError: y,
|
|
75
|
-
// Methods
|
|
76
86
|
request: i,
|
|
77
|
-
get:
|
|
78
|
-
post:
|
|
79
|
-
put:
|
|
80
|
-
patch:
|
|
81
|
-
delete:
|
|
82
|
-
cancel:
|
|
83
|
-
clearError:
|
|
87
|
+
get: A,
|
|
88
|
+
post: S,
|
|
89
|
+
put: U,
|
|
90
|
+
patch: C,
|
|
91
|
+
delete: $,
|
|
92
|
+
cancel: q,
|
|
93
|
+
clearError: L
|
|
84
94
|
};
|
|
85
95
|
};
|
|
86
96
|
export {
|
|
87
|
-
|
|
97
|
+
_ as useHttp
|
|
88
98
|
};
|