@ysgroup/core 0.1.3 → 0.1.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ysgroup/core",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
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
  }
@@ -211,11 +211,11 @@ export class YsRest {
211
211
  return this.request("DELETE", `/api/users/${id}`);
212
212
  }
213
213
  getUserApps(id: string) {
214
- return this.request<string[]>("GET", `/api/users/${id}/apps`);
214
+ return this.request<{ app_id: string; admin: boolean }[]>("GET", `/api/users/${id}/apps`);
215
215
  }
216
- setUserApps(id: string, appIds: string[]) {
217
- return this.request<{ app_ids: string[] }>("PUT", `/api/users/${id}/apps`, {
218
- app_ids: appIds,
216
+ setUserApps(id: string, grants: { app_id: string; admin: boolean }[]) {
217
+ return this.request<{ grants: { app_id: string; admin: boolean }[] }>("PUT", `/api/users/${id}/apps`, {
218
+ grants,
219
219
  });
220
220
  }
221
221
  uploadOpenAccountConfirmation(ownerId: string, file: File) {
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 ?? "").trim().toLowerCase() === "root"
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, accessToken, refreshToken, connected, isLoggedIn, sessionMessage, tables,
211
- tableList, connect, login, loginByCode, waitUntilConnected, changeMyPassword, renew, logout,
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
  });