@sendelius/vue 0.4.3 → 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/api/api.d.ts +2 -2
- package/dist/api/index.d.ts +1 -1
- package/dist/api/requests.d.ts +8 -6
- package/dist/config/config.d.ts +26 -10
- package/dist/index.js +94 -76
- package/package.json +1 -1
package/dist/api/api.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export function initApi():
|
|
2
|
-
export function getClient(): any;
|
|
1
|
+
export function initApi(): {};
|
|
2
|
+
export function getClient(name?: string): any;
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/requests.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export function useApi(client?: string): {
|
|
2
|
+
get: (url: any, body?: {}, config?: {}) => Promise<any>;
|
|
3
|
+
post: (url: any, body?: {}, config?: {}) => Promise<any>;
|
|
4
|
+
put: (url: any, body?: {}, config?: {}) => Promise<any>;
|
|
5
|
+
patch: (url: any, body?: {}, config?: {}) => Promise<any>;
|
|
6
|
+
remove: (url: any, body?: {}, config?: {}) => Promise<any>;
|
|
7
|
+
request: (method: any, url: any, data?: {}, config?: {}) => Promise<any>;
|
|
8
|
+
};
|
package/dist/config/config.d.ts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
export function configure(options?: {}): void;
|
|
2
2
|
export function getConfig(): {
|
|
3
3
|
router: any;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
api: {
|
|
5
|
+
default: string;
|
|
6
|
+
};
|
|
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
|
+
};
|
|
14
30
|
};
|
package/dist/index.js
CHANGED
|
@@ -20,31 +20,53 @@ import { ref as y } from "vue";
|
|
|
20
20
|
// src/config/config.js
|
|
21
21
|
var b = {
|
|
22
22
|
router: null,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
api: { default: "" },
|
|
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,
|
|
36
50
|
...e
|
|
37
51
|
};
|
|
38
|
-
}, S = () => b, C =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
}, S = () => b, C = {}, w = () => {
|
|
53
|
+
let e = S(), t = {
|
|
54
|
+
withCredentials: !0,
|
|
55
|
+
headers: {
|
|
56
|
+
"Content-Type": "application/json",
|
|
57
|
+
Accept: "application/json"
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return Object.entries(e.api).forEach(([e, n]) => {
|
|
61
|
+
C[e] = _.create({
|
|
62
|
+
...t,
|
|
63
|
+
baseURL: n
|
|
64
|
+
});
|
|
65
|
+
}), C;
|
|
66
|
+
}, T = (e = "default") => {
|
|
67
|
+
let t = C[e] || C.default;
|
|
68
|
+
if (!t) throw Error("@sendelius/vue: API-клиенты не инициализированы. Вызови initApi().");
|
|
69
|
+
return t;
|
|
48
70
|
}, E = class extends Error {
|
|
49
71
|
constructor({ status: e = null, data: t = null } = {}) {
|
|
50
72
|
let n = t?.error, r = {
|
|
@@ -56,46 +78,41 @@ var b = {
|
|
|
56
78
|
}
|
|
57
79
|
};
|
|
58
80
|
// src/api/requests.js
|
|
59
|
-
async function D(e, t = {},
|
|
60
|
-
|
|
61
|
-
params: t,
|
|
62
|
-
...n
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
async function O(e, t = {}, n = {}) {
|
|
66
|
-
return M("post", e, t, n);
|
|
67
|
-
}
|
|
68
|
-
async function k(e, t = {}, n = {}) {
|
|
69
|
-
return M("put", e, t, n);
|
|
70
|
-
}
|
|
71
|
-
async function A(e, t = {}, n = {}) {
|
|
72
|
-
return M("patch", e, t, n);
|
|
73
|
-
}
|
|
74
|
-
async function j(e, t = {}, n = {}) {
|
|
75
|
-
return M("delete", e, t, n);
|
|
76
|
-
}
|
|
77
|
-
async function M(e, t, n = {}, r = {}) {
|
|
78
|
-
let i;
|
|
81
|
+
async function D(e, t, n = {}, r = {}, i = "default") {
|
|
82
|
+
let a = T(i), o;
|
|
79
83
|
try {
|
|
80
|
-
|
|
84
|
+
o = e === "get" ? await a.get(t, {
|
|
85
|
+
params: n,
|
|
86
|
+
...r
|
|
87
|
+
}) : e === "delete" ? await a.delete(t, {
|
|
81
88
|
data: n,
|
|
82
89
|
...r
|
|
83
|
-
}) : await
|
|
90
|
+
}) : await a[e](t, n, r);
|
|
84
91
|
} catch (e) {
|
|
85
|
-
throw e.response?.status === 401 && S().onUnauthorized?.(), new E({
|
|
92
|
+
throw e.response?.status === 401 && S().callbacks.onUnauthorized?.(), new E({
|
|
86
93
|
status: e.response?.status ?? null,
|
|
87
94
|
data: e.response?.data ?? null
|
|
88
95
|
});
|
|
89
96
|
}
|
|
90
|
-
let
|
|
91
|
-
if (
|
|
92
|
-
status:
|
|
93
|
-
data:
|
|
97
|
+
let s = o.data;
|
|
98
|
+
if (s?.status !== "success") throw new E({
|
|
99
|
+
status: o.status,
|
|
100
|
+
data: s
|
|
94
101
|
});
|
|
95
|
-
return
|
|
102
|
+
return s;
|
|
103
|
+
}
|
|
104
|
+
function O(e = "default") {
|
|
105
|
+
return {
|
|
106
|
+
get: (t, n = {}, r = {}) => D("get", t, n, r, e),
|
|
107
|
+
post: (t, n = {}, r = {}) => D("post", t, n, r, e),
|
|
108
|
+
put: (t, n = {}, r = {}) => D("put", t, n, r, e),
|
|
109
|
+
patch: (t, n = {}, r = {}) => D("patch", t, n, r, e),
|
|
110
|
+
remove: (t, n = {}, r = {}) => D("delete", t, n, r, e),
|
|
111
|
+
request: (t, n, r = {}, i = {}) => D(t, n, r, i, e)
|
|
112
|
+
};
|
|
96
113
|
}
|
|
97
114
|
// src/auth/auth.js
|
|
98
|
-
var
|
|
115
|
+
var { get: k, post: A, remove: j } = O("auth"), M = v("auth", {
|
|
99
116
|
state: () => ({
|
|
100
117
|
user: {},
|
|
101
118
|
avatar: {
|
|
@@ -110,7 +127,7 @@ var N = v("auth", {
|
|
|
110
127
|
async init(e = !0) {
|
|
111
128
|
if (this.isInit && e) return this.isAuth;
|
|
112
129
|
try {
|
|
113
|
-
let e = await
|
|
130
|
+
let e = await k(S().endpoints.auth.me);
|
|
114
131
|
e?.user ? (this.user = e.user, this.avatar = e.user.avatar ?? this.avatar, this.isAuth = !0) : this.clear();
|
|
115
132
|
} catch {
|
|
116
133
|
this.clear();
|
|
@@ -122,24 +139,24 @@ var N = v("auth", {
|
|
|
122
139
|
async login(e, t, n) {
|
|
123
140
|
n ||= "";
|
|
124
141
|
try {
|
|
125
|
-
await
|
|
142
|
+
await A(S().endpoints.auth.login, {
|
|
126
143
|
login: e,
|
|
127
144
|
password: t,
|
|
128
145
|
captcha: n
|
|
129
146
|
}), await this.init(!1);
|
|
130
147
|
let r = S().router;
|
|
131
|
-
return r && await r.push(S().
|
|
148
|
+
return r && await r.push(S().redirects.afterLogin), !0;
|
|
132
149
|
} catch (e) {
|
|
133
150
|
throw e;
|
|
134
151
|
}
|
|
135
152
|
},
|
|
136
153
|
async logout() {
|
|
137
154
|
try {
|
|
138
|
-
await j(S().
|
|
155
|
+
await j(S().endpoints.auth.logout);
|
|
139
156
|
} finally {
|
|
140
|
-
this.clear(), S().onLogout?.();
|
|
157
|
+
this.clear(), S().callbacks.onLogout?.();
|
|
141
158
|
let e = S().router;
|
|
142
|
-
e && await e.push(S().
|
|
159
|
+
e && await e.push(S().redirects.afterLogout);
|
|
143
160
|
}
|
|
144
161
|
},
|
|
145
162
|
clear() {
|
|
@@ -151,60 +168,61 @@ var N = v("auth", {
|
|
|
151
168
|
}
|
|
152
169
|
}
|
|
153
170
|
});
|
|
154
|
-
function
|
|
155
|
-
return
|
|
171
|
+
function N() {
|
|
172
|
+
return M();
|
|
156
173
|
}
|
|
157
174
|
// src/captcha/captcha.js
|
|
158
|
-
|
|
159
|
-
let e = await I(), t = await R(e.challenge);
|
|
160
|
-
return L(e.id, t);
|
|
161
|
-
}
|
|
175
|
+
var { get: P, post: F } = O("auth");
|
|
162
176
|
async function I() {
|
|
163
|
-
|
|
177
|
+
let e = await L(), t = await z(e.challenge);
|
|
178
|
+
return R(e.id, t);
|
|
179
|
+
}
|
|
180
|
+
async function L() {
|
|
181
|
+
return P(S().endpoints.captcha.challenge);
|
|
164
182
|
}
|
|
165
|
-
async function
|
|
166
|
-
return (await
|
|
183
|
+
async function R(e, t) {
|
|
184
|
+
return (await F(S().endpoints.captcha.verify, {
|
|
167
185
|
id: e,
|
|
168
186
|
nonce: t
|
|
169
187
|
}))?.token;
|
|
170
188
|
}
|
|
171
|
-
async function
|
|
189
|
+
async function z(e) {
|
|
172
190
|
let t = "0".repeat(4), n = 0;
|
|
173
191
|
for (;;) {
|
|
174
|
-
if ((await
|
|
192
|
+
if ((await B(`${e}:${n}`)).startsWith(t)) return n;
|
|
175
193
|
n++;
|
|
176
194
|
}
|
|
177
195
|
}
|
|
178
|
-
async function
|
|
196
|
+
async function B(e) {
|
|
179
197
|
let t = new TextEncoder().encode(e), n = await crypto.subtle.digest("SHA-256", t);
|
|
180
198
|
return Array.from(new Uint8Array(n)).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
181
199
|
}
|
|
182
200
|
// src/captcha/store.js
|
|
183
|
-
var
|
|
201
|
+
var V = v("captcha", () => {
|
|
184
202
|
let e = y(""), t = y(!1), n = y(!1), r = null;
|
|
185
203
|
return {
|
|
186
204
|
token: e,
|
|
187
205
|
isInit: t,
|
|
188
206
|
isLoading: n,
|
|
189
|
-
init: async () => t.value ? e.value : r || (n.value = !0, r =
|
|
207
|
+
init: async () => t.value ? e.value : r || (n.value = !0, r = I().then((n) => (e.value = n, t.value = !0, n)).finally(() => {
|
|
190
208
|
n.value = !1, r = null;
|
|
191
209
|
}), r)
|
|
192
210
|
};
|
|
193
211
|
});
|
|
194
|
-
function
|
|
195
|
-
return
|
|
212
|
+
function H() {
|
|
213
|
+
return V();
|
|
196
214
|
}
|
|
197
215
|
// src/helpers/declension.js
|
|
198
|
-
function
|
|
216
|
+
function U(e, t, n, r) {
|
|
199
217
|
let i = Math.abs(e) % 100, a = i % 10, o;
|
|
200
218
|
return o = i >= 11 && i <= 19 ? r : a === 1 ? t : a >= 2 && a <= 4 ? n : r, `${e} ${o}`;
|
|
201
219
|
}
|
|
202
220
|
// src/helpers/title.js
|
|
203
|
-
function
|
|
204
|
-
t ??= S().
|
|
221
|
+
function W(e, t, n) {
|
|
222
|
+
t ??= S().title.default, n ??= S().title.separator, t || (n = ""), document.title = e ? `${e}${n}${t}` : t;
|
|
205
223
|
}
|
|
206
224
|
// src/helpers/objects.js
|
|
207
|
-
function
|
|
225
|
+
function G(e) {
|
|
208
226
|
return Array.isArray(e) ? e.length === 0 : e && typeof e == "object" ? Object.keys(e).length === 0 : !0;
|
|
209
227
|
}
|
|
210
|
-
export { E as ApiError, i as SndAutocomplete, t as SndBtn, u as SndCheckbox, n as SndCookie, f as SndError, r as SndInput, s as SndInputCity, c as SndInputDate, l as SndInputPassword, a as SndInputPhone, h as SndPopup, e as SndProgress, o as SndSelect, p as SndSuccess, g as SndTable, d as SndWarning, x as configure,
|
|
228
|
+
export { E as ApiError, i as SndAutocomplete, t as SndBtn, u as SndCheckbox, n as SndCookie, f as SndError, r as SndInput, s as SndInputCity, c as SndInputDate, l as SndInputPassword, a as SndInputPhone, h as SndPopup, e as SndProgress, o as SndSelect, p as SndSuccess, g as SndTable, d as SndWarning, x as configure, U as declension, T as getClient, S as getConfig, w as initApi, G as isEmpty, W as setTitle, O as useApi, N as useAuth, H as useCaptcha, m as usePopup };
|
package/package.json
CHANGED