@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.
@@ -4,13 +4,27 @@ export function getConfig(): {
4
4
  api: {
5
5
  default: string;
6
6
  };
7
- baseTitle: string;
8
- baseTitleSeparator: string;
9
- routeAfterLogin: string;
10
- routeAfterLogout: string;
11
- urlUserInfo: string;
12
- urlLogin: string;
13
- urlLogout: string;
14
- onUnauthorized: any;
15
- onLogout: any;
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
- baseTitle: "",
25
- baseTitleSeparator: " - ",
26
- routeAfterLogin: "/",
27
- routeAfterLogout: "/",
28
- urlUserInfo: "/auth/me",
29
- urlLogin: "/auth/login",
30
- urlLogout: "/auth/logout",
31
- onUnauthorized: null,
32
- onLogout: null
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().urlUserInfo);
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().urlLogin, {
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().routeAfterLogin), !0;
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().urlLogout);
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().routeAfterLogout);
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("/captcha/challenge");
181
+ return P(S().endpoints.captcha.challenge);
168
182
  }
169
183
  async function R(e, t) {
170
- return (await F("/captcha/verify", {
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().baseTitle, n ??= S().baseTitleSeparator, t || (n = ""), document.title = e ? `${e}${n}${t}` : t;
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
@@ -48,5 +48,5 @@
48
48
  "@parcel/watcher@2.6.0": true,
49
49
  "vue-demi@0.14.10": true
50
50
  },
51
- "version": "0.5.0"
51
+ "version": "0.5.1"
52
52
  }