@ysgroup/core 0.1.3 → 0.1.4
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/package.json +1 -1
- package/src/index.ts +1 -9
- package/src/rest.ts +4 -4
- package/src/store.ts +24 -3
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,12 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
export { YsWsClient, type Envelope } from "./ws";
|
|
4
4
|
export { useYsStore } from "./store";
|
|
5
|
-
export {
|
|
6
|
-
YsRest,
|
|
7
|
-
YsRestError,
|
|
8
|
-
type YsAdminRpcCall,
|
|
9
|
-
type DeleteBlocker,
|
|
10
|
-
type DeleteImpact,
|
|
11
|
-
type RevealedCredential,
|
|
12
|
-
type TopologyNode,
|
|
13
|
-
} from "./rest";
|
|
5
|
+
export { YsRest, YsRestError, type YsAdminRpcCall, type DeleteBlocker, type DeleteImpact, type RevealedCredential, type TopologyNode } from "./rest";
|
package/src/rest.ts
CHANGED
|
@@ -48,13 +48,13 @@ export class YsRest {
|
|
|
48
48
|
private async request<T>(method: string, path: string, body?: unknown): Promise<T> {
|
|
49
49
|
if (this.rpcCall) {
|
|
50
50
|
try {
|
|
51
|
-
return await this.rpcCall({
|
|
51
|
+
return (await this.rpcCall({
|
|
52
52
|
method,
|
|
53
53
|
path,
|
|
54
54
|
access_token: this.getToken(),
|
|
55
55
|
body,
|
|
56
56
|
user_agent: navigator.userAgent,
|
|
57
|
-
}) as T;
|
|
57
|
+
})) as T;
|
|
58
58
|
} catch (error) {
|
|
59
59
|
throw rpcError(error);
|
|
60
60
|
}
|
|
@@ -84,7 +84,7 @@ export class YsRest {
|
|
|
84
84
|
private async upload<T>(path: string, file: File): Promise<T> {
|
|
85
85
|
if (this.rpcCall) {
|
|
86
86
|
try {
|
|
87
|
-
return await this.rpcCall({
|
|
87
|
+
return (await this.rpcCall({
|
|
88
88
|
method: "POST",
|
|
89
89
|
path,
|
|
90
90
|
access_token: this.getToken(),
|
|
@@ -94,7 +94,7 @@ export class YsRest {
|
|
|
94
94
|
base64: await fileToBase64(file),
|
|
95
95
|
},
|
|
96
96
|
user_agent: navigator.userAgent,
|
|
97
|
-
}) as T;
|
|
97
|
+
})) as T;
|
|
98
98
|
} catch (error) {
|
|
99
99
|
throw rpcError(error);
|
|
100
100
|
}
|
package/src/store.ts
CHANGED
|
@@ -139,7 +139,9 @@ export const useYsStore = defineStore("ys", () => {
|
|
|
139
139
|
if (!ws || !accessToken.value) throw new Error("未登录");
|
|
140
140
|
if (
|
|
141
141
|
String(user.value?.role ?? "") === "Root" ||
|
|
142
|
-
String(user.value?.username ?? "")
|
|
142
|
+
String(user.value?.username ?? "")
|
|
143
|
+
.trim()
|
|
144
|
+
.toLowerCase() === "root"
|
|
143
145
|
) {
|
|
144
146
|
throw new Error("Root 不允许修改登录密码");
|
|
145
147
|
}
|
|
@@ -196,6 +198,11 @@ export const useYsStore = defineStore("ys", () => {
|
|
|
196
198
|
clearSession();
|
|
197
199
|
}
|
|
198
200
|
|
|
201
|
+
function forceLogout(message = "") {
|
|
202
|
+
clearSession();
|
|
203
|
+
sessionMessage.value = message;
|
|
204
|
+
}
|
|
205
|
+
|
|
199
206
|
function clearSession() {
|
|
200
207
|
user.value = null;
|
|
201
208
|
accessToken.value = "";
|
|
@@ -207,8 +214,22 @@ export const useYsStore = defineStore("ys", () => {
|
|
|
207
214
|
}
|
|
208
215
|
|
|
209
216
|
return {
|
|
210
|
-
user,
|
|
211
|
-
|
|
217
|
+
user,
|
|
218
|
+
accessToken,
|
|
219
|
+
refreshToken,
|
|
220
|
+
connected,
|
|
221
|
+
isLoggedIn,
|
|
222
|
+
sessionMessage,
|
|
223
|
+
tables,
|
|
224
|
+
tableList,
|
|
225
|
+
connect,
|
|
226
|
+
login,
|
|
227
|
+
loginByCode,
|
|
228
|
+
waitUntilConnected,
|
|
229
|
+
changeMyPassword,
|
|
230
|
+
renew,
|
|
231
|
+
logout,
|
|
232
|
+
forceLogout,
|
|
212
233
|
client: () => ws,
|
|
213
234
|
};
|
|
214
235
|
});
|