@sendelius/vue 0.5.0 → 0.5.1
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/config/config.d.ts +23 -9
- package/dist/index.js +33 -19
- package/package.json +1 -1
package/dist/config/config.d.ts
CHANGED
|
@@ -4,13 +4,27 @@ export function getConfig(): {
|
|
|
4
4
|
api: {
|
|
5
5
|
default: string;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
endpoints: {
|
|
8
|
+
auth: {
|
|
9
|
+
me: string;
|
|
10
|
+
login: string;
|
|
11
|
+
logout: string;
|
|
12
|
+
};
|
|
13
|
+
captcha: {
|
|
14
|
+
challenge: string;
|
|
15
|
+
verify: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
title: {
|
|
19
|
+
default: string;
|
|
20
|
+
separator: string;
|
|
21
|
+
};
|
|
22
|
+
redirects: {
|
|
23
|
+
afterLogin: string;
|
|
24
|
+
afterLogout: string;
|
|
25
|
+
};
|
|
26
|
+
callbacks: {
|
|
27
|
+
onUnauthorized: any;
|
|
28
|
+
onLogout: any;
|
|
29
|
+
};
|
|
16
30
|
};
|
package/dist/index.js
CHANGED
|
@@ -21,15 +21,29 @@ import { ref as y } from "vue";
|
|
|
21
21
|
var b = {
|
|
22
22
|
router: null,
|
|
23
23
|
api: { default: "" },
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
endpoints: {
|
|
25
|
+
auth: {
|
|
26
|
+
me: "/v1/auth/me",
|
|
27
|
+
login: "/v1/auth/login",
|
|
28
|
+
logout: "/v1/auth/logout"
|
|
29
|
+
},
|
|
30
|
+
captcha: {
|
|
31
|
+
challenge: "/v1/captcha/challenge",
|
|
32
|
+
verify: "/v1/captcha/verify"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
title: {
|
|
36
|
+
default: "",
|
|
37
|
+
separator: " - "
|
|
38
|
+
},
|
|
39
|
+
redirects: {
|
|
40
|
+
afterLogin: "/",
|
|
41
|
+
afterLogout: "/"
|
|
42
|
+
},
|
|
43
|
+
callbacks: {
|
|
44
|
+
onUnauthorized: null,
|
|
45
|
+
onLogout: null
|
|
46
|
+
}
|
|
33
47
|
}, x = (e = {}) => {
|
|
34
48
|
b = {
|
|
35
49
|
...b,
|
|
@@ -75,7 +89,7 @@ async function D(e, t, n = {}, r = {}, i = "default") {
|
|
|
75
89
|
...r
|
|
76
90
|
}) : await a[e](t, n, r);
|
|
77
91
|
} catch (e) {
|
|
78
|
-
throw e.response?.status === 401 && S().onUnauthorized?.(), new E({
|
|
92
|
+
throw e.response?.status === 401 && S().callbacks.onUnauthorized?.(), new E({
|
|
79
93
|
status: e.response?.status ?? null,
|
|
80
94
|
data: e.response?.data ?? null
|
|
81
95
|
});
|
|
@@ -113,7 +127,7 @@ var { get: k, post: A, remove: j } = O("auth"), M = v("auth", {
|
|
|
113
127
|
async init(e = !0) {
|
|
114
128
|
if (this.isInit && e) return this.isAuth;
|
|
115
129
|
try {
|
|
116
|
-
let e = await k(S().
|
|
130
|
+
let e = await k(S().endpoints.auth.me);
|
|
117
131
|
e?.user ? (this.user = e.user, this.avatar = e.user.avatar ?? this.avatar, this.isAuth = !0) : this.clear();
|
|
118
132
|
} catch {
|
|
119
133
|
this.clear();
|
|
@@ -125,24 +139,24 @@ var { get: k, post: A, remove: j } = O("auth"), M = v("auth", {
|
|
|
125
139
|
async login(e, t, n) {
|
|
126
140
|
n ||= "";
|
|
127
141
|
try {
|
|
128
|
-
await A(S().
|
|
142
|
+
await A(S().endpoints.auth.login, {
|
|
129
143
|
login: e,
|
|
130
144
|
password: t,
|
|
131
145
|
captcha: n
|
|
132
146
|
}), await this.init(!1);
|
|
133
147
|
let r = S().router;
|
|
134
|
-
return r && await r.push(S().
|
|
148
|
+
return r && await r.push(S().redirects.afterLogin), !0;
|
|
135
149
|
} catch (e) {
|
|
136
150
|
throw e;
|
|
137
151
|
}
|
|
138
152
|
},
|
|
139
153
|
async logout() {
|
|
140
154
|
try {
|
|
141
|
-
await j(S().
|
|
155
|
+
await j(S().endpoints.auth.logout);
|
|
142
156
|
} finally {
|
|
143
|
-
this.clear(), S().onLogout?.();
|
|
157
|
+
this.clear(), S().callbacks.onLogout?.();
|
|
144
158
|
let e = S().router;
|
|
145
|
-
e && await e.push(S().
|
|
159
|
+
e && await e.push(S().redirects.afterLogout);
|
|
146
160
|
}
|
|
147
161
|
},
|
|
148
162
|
clear() {
|
|
@@ -164,10 +178,10 @@ async function I() {
|
|
|
164
178
|
return R(e.id, t);
|
|
165
179
|
}
|
|
166
180
|
async function L() {
|
|
167
|
-
return P(
|
|
181
|
+
return P(S().endpoints.captcha.challenge);
|
|
168
182
|
}
|
|
169
183
|
async function R(e, t) {
|
|
170
|
-
return (await F(
|
|
184
|
+
return (await F(S().endpoints.captcha.verify, {
|
|
171
185
|
id: e,
|
|
172
186
|
nonce: t
|
|
173
187
|
}))?.token;
|
|
@@ -205,7 +219,7 @@ function U(e, t, n, r) {
|
|
|
205
219
|
}
|
|
206
220
|
// src/helpers/title.js
|
|
207
221
|
function W(e, t, n) {
|
|
208
|
-
t ??= S().
|
|
222
|
+
t ??= S().title.default, n ??= S().title.separator, t || (n = ""), document.title = e ? `${e}${n}${t}` : t;
|
|
209
223
|
}
|
|
210
224
|
// src/helpers/objects.js
|
|
211
225
|
function G(e) {
|
package/package.json
CHANGED