@sendelius/vue 0.4.3 → 0.5.0
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 +3 -1
- package/dist/index.js +66 -62
- 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
package/dist/index.js
CHANGED
|
@@ -20,10 +20,10 @@ import { ref as y } from "vue";
|
|
|
20
20
|
// src/config/config.js
|
|
21
21
|
var b = {
|
|
22
22
|
router: null,
|
|
23
|
-
|
|
23
|
+
api: { default: "" },
|
|
24
24
|
baseTitle: "",
|
|
25
25
|
baseTitleSeparator: " - ",
|
|
26
|
-
routeAfterLogin: "/
|
|
26
|
+
routeAfterLogin: "/",
|
|
27
27
|
routeAfterLogout: "/",
|
|
28
28
|
urlUserInfo: "/auth/me",
|
|
29
29
|
urlLogin: "/auth/login",
|
|
@@ -35,16 +35,24 @@ var b = {
|
|
|
35
35
|
...b,
|
|
36
36
|
...e
|
|
37
37
|
};
|
|
38
|
-
}, S = () => b, C =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
}, S = () => b, C = {}, w = () => {
|
|
39
|
+
let e = S(), t = {
|
|
40
|
+
withCredentials: !0,
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
Accept: "application/json"
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return Object.entries(e.api).forEach(([e, n]) => {
|
|
47
|
+
C[e] = _.create({
|
|
48
|
+
...t,
|
|
49
|
+
baseURL: n
|
|
50
|
+
});
|
|
51
|
+
}), C;
|
|
52
|
+
}, T = (e = "default") => {
|
|
53
|
+
let t = C[e] || C.default;
|
|
54
|
+
if (!t) throw Error("@sendelius/vue: API-клиенты не инициализированы. Вызови initApi().");
|
|
55
|
+
return t;
|
|
48
56
|
}, E = class extends Error {
|
|
49
57
|
constructor({ status: e = null, data: t = null } = {}) {
|
|
50
58
|
let n = t?.error, r = {
|
|
@@ -56,46 +64,41 @@ var b = {
|
|
|
56
64
|
}
|
|
57
65
|
};
|
|
58
66
|
// 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;
|
|
67
|
+
async function D(e, t, n = {}, r = {}, i = "default") {
|
|
68
|
+
let a = T(i), o;
|
|
79
69
|
try {
|
|
80
|
-
|
|
70
|
+
o = e === "get" ? await a.get(t, {
|
|
71
|
+
params: n,
|
|
72
|
+
...r
|
|
73
|
+
}) : e === "delete" ? await a.delete(t, {
|
|
81
74
|
data: n,
|
|
82
75
|
...r
|
|
83
|
-
}) : await
|
|
76
|
+
}) : await a[e](t, n, r);
|
|
84
77
|
} catch (e) {
|
|
85
78
|
throw e.response?.status === 401 && S().onUnauthorized?.(), new E({
|
|
86
79
|
status: e.response?.status ?? null,
|
|
87
80
|
data: e.response?.data ?? null
|
|
88
81
|
});
|
|
89
82
|
}
|
|
90
|
-
let
|
|
91
|
-
if (
|
|
92
|
-
status:
|
|
93
|
-
data:
|
|
83
|
+
let s = o.data;
|
|
84
|
+
if (s?.status !== "success") throw new E({
|
|
85
|
+
status: o.status,
|
|
86
|
+
data: s
|
|
94
87
|
});
|
|
95
|
-
return
|
|
88
|
+
return s;
|
|
89
|
+
}
|
|
90
|
+
function O(e = "default") {
|
|
91
|
+
return {
|
|
92
|
+
get: (t, n = {}, r = {}) => D("get", t, n, r, e),
|
|
93
|
+
post: (t, n = {}, r = {}) => D("post", t, n, r, e),
|
|
94
|
+
put: (t, n = {}, r = {}) => D("put", t, n, r, e),
|
|
95
|
+
patch: (t, n = {}, r = {}) => D("patch", t, n, r, e),
|
|
96
|
+
remove: (t, n = {}, r = {}) => D("delete", t, n, r, e),
|
|
97
|
+
request: (t, n, r = {}, i = {}) => D(t, n, r, i, e)
|
|
98
|
+
};
|
|
96
99
|
}
|
|
97
100
|
// src/auth/auth.js
|
|
98
|
-
var
|
|
101
|
+
var { get: k, post: A, remove: j } = O("auth"), M = v("auth", {
|
|
99
102
|
state: () => ({
|
|
100
103
|
user: {},
|
|
101
104
|
avatar: {
|
|
@@ -110,7 +113,7 @@ var N = v("auth", {
|
|
|
110
113
|
async init(e = !0) {
|
|
111
114
|
if (this.isInit && e) return this.isAuth;
|
|
112
115
|
try {
|
|
113
|
-
let e = await
|
|
116
|
+
let e = await k(S().urlUserInfo);
|
|
114
117
|
e?.user ? (this.user = e.user, this.avatar = e.user.avatar ?? this.avatar, this.isAuth = !0) : this.clear();
|
|
115
118
|
} catch {
|
|
116
119
|
this.clear();
|
|
@@ -122,7 +125,7 @@ var N = v("auth", {
|
|
|
122
125
|
async login(e, t, n) {
|
|
123
126
|
n ||= "";
|
|
124
127
|
try {
|
|
125
|
-
await
|
|
128
|
+
await A(S().urlLogin, {
|
|
126
129
|
login: e,
|
|
127
130
|
password: t,
|
|
128
131
|
captcha: n
|
|
@@ -151,60 +154,61 @@ var N = v("auth", {
|
|
|
151
154
|
}
|
|
152
155
|
}
|
|
153
156
|
});
|
|
154
|
-
function
|
|
155
|
-
return
|
|
157
|
+
function N() {
|
|
158
|
+
return M();
|
|
156
159
|
}
|
|
157
160
|
// src/captcha/captcha.js
|
|
158
|
-
|
|
159
|
-
let e = await I(), t = await R(e.challenge);
|
|
160
|
-
return L(e.id, t);
|
|
161
|
-
}
|
|
161
|
+
var { get: P, post: F } = O("auth");
|
|
162
162
|
async function I() {
|
|
163
|
-
|
|
163
|
+
let e = await L(), t = await z(e.challenge);
|
|
164
|
+
return R(e.id, t);
|
|
165
|
+
}
|
|
166
|
+
async function L() {
|
|
167
|
+
return P("/captcha/challenge");
|
|
164
168
|
}
|
|
165
|
-
async function
|
|
166
|
-
return (await
|
|
169
|
+
async function R(e, t) {
|
|
170
|
+
return (await F("/captcha/verify", {
|
|
167
171
|
id: e,
|
|
168
172
|
nonce: t
|
|
169
173
|
}))?.token;
|
|
170
174
|
}
|
|
171
|
-
async function
|
|
175
|
+
async function z(e) {
|
|
172
176
|
let t = "0".repeat(4), n = 0;
|
|
173
177
|
for (;;) {
|
|
174
|
-
if ((await
|
|
178
|
+
if ((await B(`${e}:${n}`)).startsWith(t)) return n;
|
|
175
179
|
n++;
|
|
176
180
|
}
|
|
177
181
|
}
|
|
178
|
-
async function
|
|
182
|
+
async function B(e) {
|
|
179
183
|
let t = new TextEncoder().encode(e), n = await crypto.subtle.digest("SHA-256", t);
|
|
180
184
|
return Array.from(new Uint8Array(n)).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
181
185
|
}
|
|
182
186
|
// src/captcha/store.js
|
|
183
|
-
var
|
|
187
|
+
var V = v("captcha", () => {
|
|
184
188
|
let e = y(""), t = y(!1), n = y(!1), r = null;
|
|
185
189
|
return {
|
|
186
190
|
token: e,
|
|
187
191
|
isInit: t,
|
|
188
192
|
isLoading: n,
|
|
189
|
-
init: async () => t.value ? e.value : r || (n.value = !0, r =
|
|
193
|
+
init: async () => t.value ? e.value : r || (n.value = !0, r = I().then((n) => (e.value = n, t.value = !0, n)).finally(() => {
|
|
190
194
|
n.value = !1, r = null;
|
|
191
195
|
}), r)
|
|
192
196
|
};
|
|
193
197
|
});
|
|
194
|
-
function
|
|
195
|
-
return
|
|
198
|
+
function H() {
|
|
199
|
+
return V();
|
|
196
200
|
}
|
|
197
201
|
// src/helpers/declension.js
|
|
198
|
-
function
|
|
202
|
+
function U(e, t, n, r) {
|
|
199
203
|
let i = Math.abs(e) % 100, a = i % 10, o;
|
|
200
204
|
return o = i >= 11 && i <= 19 ? r : a === 1 ? t : a >= 2 && a <= 4 ? n : r, `${e} ${o}`;
|
|
201
205
|
}
|
|
202
206
|
// src/helpers/title.js
|
|
203
|
-
function
|
|
207
|
+
function W(e, t, n) {
|
|
204
208
|
t ??= S().baseTitle, n ??= S().baseTitleSeparator, t || (n = ""), document.title = e ? `${e}${n}${t}` : t;
|
|
205
209
|
}
|
|
206
210
|
// src/helpers/objects.js
|
|
207
|
-
function
|
|
211
|
+
function G(e) {
|
|
208
212
|
return Array.isArray(e) ? e.length === 0 : e && typeof e == "object" ? Object.keys(e).length === 0 : !0;
|
|
209
213
|
}
|
|
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,
|
|
214
|
+
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