@choiceform/shared-auth 0.1.13 → 0.1.15
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/README.md +106 -450
- package/dist/api/auth-api.d.ts +28 -0
- package/dist/api/auth-api.d.ts.map +1 -0
- package/dist/api/auth-api.js +133 -0
- package/dist/api/client.d.ts +34 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +104 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +7 -0
- package/dist/api/organization-api.d.ts +96 -0
- package/dist/api/organization-api.d.ts.map +1 -0
- package/dist/api/organization-api.js +228 -0
- package/dist/api/team-api.d.ts +57 -0
- package/dist/api/team-api.d.ts.map +1 -0
- package/dist/api/team-api.js +118 -0
- package/dist/config.d.ts +4 -50
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -6
- package/dist/core.d.ts +307 -1717
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +35 -17
- package/dist/index.d.ts +11 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -12
- package/dist/init.d.ts +326 -1732
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +13 -14
- package/dist/lib/auth-client.d.ts +232 -1689
- package/dist/lib/auth-client.d.ts.map +1 -1
- package/dist/lib/auth-client.js +10 -16
- package/dist/services/companion-team.d.ts +16 -0
- package/dist/services/companion-team.d.ts.map +1 -0
- package/dist/services/companion-team.js +73 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +4 -0
- package/dist/store/actions.d.ts +45 -30
- package/dist/store/actions.d.ts.map +1 -1
- package/dist/store/actions.js +139 -103
- package/dist/store/index.d.ts +8 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +7 -0
- package/dist/store/state.d.ts +10 -7
- package/dist/store/state.d.ts.map +1 -1
- package/dist/store/state.js +31 -23
- package/dist/store/utils.d.ts +22 -71
- package/dist/store/utils.d.ts.map +1 -1
- package/dist/store/utils.js +28 -146
- package/dist/types/auth.d.ts +107 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +4 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/organization.d.ts +111 -0
- package/dist/types/organization.d.ts.map +1 -0
- package/dist/types/organization.js +4 -0
- package/dist/types/team.d.ts +52 -0
- package/dist/types/team.d.ts.map +1 -0
- package/dist/types/team.js +4 -0
- package/dist/types/user.d.ts +44 -0
- package/dist/types/user.d.ts.map +1 -0
- package/dist/types/user.js +4 -0
- package/dist/utils/date.d.ts +10 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +13 -0
- package/dist/utils/env.d.ts +20 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +23 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/user-mapper.d.ts +21 -0
- package/dist/utils/user-mapper.d.ts.map +1 -0
- package/dist/utils/user-mapper.js +55 -0
- package/package.json +3 -4
- package/dist/components/auth-sync.d.ts +0 -25
- package/dist/components/auth-sync.d.ts.map +0 -1
- package/dist/components/auth-sync.js +0 -346
- package/dist/components/protected-route.d.ts +0 -18
- package/dist/components/protected-route.d.ts.map +0 -1
- package/dist/components/protected-route.js +0 -34
- package/dist/components/sign-in-page.d.ts +0 -21
- package/dist/components/sign-in-page.d.ts.map +0 -1
- package/dist/components/sign-in-page.js +0 -31
- package/dist/core/init-auth-sync.d.ts +0 -7
- package/dist/core/init-auth-sync.d.ts.map +0 -1
- package/dist/core/init-auth-sync.js +0 -34
- package/dist/types.d.ts +0 -87
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"team-api.d.ts","sourceRoot":"","sources":["../../src/api/team-api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,oBAAoB,EACpB,IAAI,EACJ,UAAU,EACV,iBAAiB,EAClB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS;IAQ9C;;OAEG;oBACmB,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQvD;;OAEG;YACW,OAAO,CAAC,IAAI,EAAE,CAAC;IAQ7B;;OAEG;oBACmB,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQvD;;OAEG;oBACmB,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOvD;;OAEG;uBACsB,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAO7D;;OAEG;qBACoB,OAAO,CAAC,IAAI,EAAE,CAAC;IAYtC;;OAEG;wBACuB,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAUxD;;OAEG;uBACsB,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC;IAQnE;;OAEG;0BACyB,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOnE;;OAEG;sBACqB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;EAOjD;AAED,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAA"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 团队相关 API
|
|
3
|
+
*
|
|
4
|
+
* 封装所有团队管理的 API 调用
|
|
5
|
+
* 基于 Core AI Auth API 文档
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 创建团队 API
|
|
9
|
+
*
|
|
10
|
+
* @param apiClient - API 客户端实例
|
|
11
|
+
*/
|
|
12
|
+
export function createTeamApi(apiClient) {
|
|
13
|
+
const basePath = "/v1/auth/organization";
|
|
14
|
+
return {
|
|
15
|
+
// ============================================================
|
|
16
|
+
// 团队 CRUD
|
|
17
|
+
// ============================================================
|
|
18
|
+
/**
|
|
19
|
+
* 创建团队
|
|
20
|
+
*/
|
|
21
|
+
async create(request) {
|
|
22
|
+
const response = await apiClient.post(`${basePath}/create-team`, request);
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
throw new Error(`Failed to create team: ${response.status}`);
|
|
25
|
+
}
|
|
26
|
+
return response.data;
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* 获取团队列表
|
|
30
|
+
*/
|
|
31
|
+
async list() {
|
|
32
|
+
const response = await apiClient.get(`${basePath}/list-teams`);
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
throw new Error(`Failed to list teams: ${response.status}`);
|
|
35
|
+
}
|
|
36
|
+
return response.data || [];
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* 更新团队
|
|
40
|
+
*/
|
|
41
|
+
async update(request) {
|
|
42
|
+
const response = await apiClient.post(`${basePath}/update-team`, request);
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new Error(`Failed to update team: ${response.status}`);
|
|
45
|
+
}
|
|
46
|
+
return response.data;
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* 删除团队
|
|
50
|
+
*/
|
|
51
|
+
async delete(request) {
|
|
52
|
+
const response = await apiClient.post(`${basePath}/remove-team`, request);
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
throw new Error(`Failed to delete team: ${response.status}`);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* 设置活跃团队
|
|
59
|
+
*/
|
|
60
|
+
async setActive(request) {
|
|
61
|
+
const response = await apiClient.post(`${basePath}/set-active-team`, request);
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
throw new Error(`Failed to set active team: ${response.status}`);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* 获取用户所属的团队列表
|
|
68
|
+
*/
|
|
69
|
+
async listUserTeams() {
|
|
70
|
+
const response = await apiClient.get(`${basePath}/list-user-teams`);
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
throw new Error(`Failed to list user teams: ${response.status}`);
|
|
73
|
+
}
|
|
74
|
+
return response.data || [];
|
|
75
|
+
},
|
|
76
|
+
// ============================================================
|
|
77
|
+
// 团队成员管理
|
|
78
|
+
// ============================================================
|
|
79
|
+
/**
|
|
80
|
+
* 获取团队成员列表
|
|
81
|
+
*/
|
|
82
|
+
async listMembers(teamId) {
|
|
83
|
+
const response = await apiClient.get(`${basePath}/list-team-members?teamId=${encodeURIComponent(teamId)}`);
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
throw new Error(`Failed to list team members: ${response.status}`);
|
|
86
|
+
}
|
|
87
|
+
return response.data || [];
|
|
88
|
+
},
|
|
89
|
+
/**
|
|
90
|
+
* 添加团队成员
|
|
91
|
+
*/
|
|
92
|
+
async addMember(request) {
|
|
93
|
+
const response = await apiClient.post(`${basePath}/add-team-member`, request);
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
throw new Error(`Failed to add team member: ${response.status}`);
|
|
96
|
+
}
|
|
97
|
+
return response.data;
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* 移除团队成员(需要管理员权限)
|
|
101
|
+
*/
|
|
102
|
+
async removeMember(request) {
|
|
103
|
+
const response = await apiClient.post(`${basePath}/remove-team-member`, request);
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
throw new Error(`Failed to remove team member: ${response.status}`);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
/**
|
|
109
|
+
* 离开团队(普通成员可自行调用)
|
|
110
|
+
*/
|
|
111
|
+
async leaveTeam(teamId) {
|
|
112
|
+
const response = await apiClient.post(`${basePath}/leave-team`, { teamId });
|
|
113
|
+
if (!response.ok) {
|
|
114
|
+
throw new Error(`Failed to leave team: ${response.status}`);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,56 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* 使用更通用的类型定义,兼容 better-auth 的所有插件
|
|
2
|
+
* 认证配置
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* 认证配置接口
|
|
8
|
-
*/
|
|
9
|
-
export interface AuthConfig {
|
|
10
|
-
/**
|
|
11
|
-
* Better Auth API 基础 URL
|
|
12
|
-
*/
|
|
13
|
-
baseURL: string;
|
|
14
|
-
/**
|
|
15
|
-
* 自定义回调 URL 构建函数
|
|
16
|
-
*/
|
|
17
|
-
callbackURLBuilder?: (redirectTo: string, baseURL: string) => string;
|
|
18
|
-
/**
|
|
19
|
-
* OAuth 重定向后的默认跳转地址(可选)
|
|
20
|
-
* 推荐在组件层面通过 props 传入,而不是在配置中设置
|
|
21
|
-
* @default undefined
|
|
22
|
-
* @deprecated 建议在 SignInPage 组件中通过 redirectUrl prop 传入
|
|
23
|
-
*/
|
|
24
|
-
defaultRedirectAfterLogin?: string;
|
|
25
|
-
/**
|
|
26
|
-
* 获取 session 的端点路径
|
|
27
|
-
* @default '/v1/auth/get-session'
|
|
28
|
-
*/
|
|
29
|
-
getSessionEndpoint?: string;
|
|
30
|
-
/**
|
|
31
|
-
* Better Auth 插件列表
|
|
32
|
-
*/
|
|
33
|
-
plugins?: BetterAuthPlugin[];
|
|
34
|
-
/**
|
|
35
|
-
* 登录页面的路由路径(可选)
|
|
36
|
-
* 推荐在组件层面通过回调传入,而不是在配置中设置
|
|
37
|
-
* @default undefined
|
|
38
|
-
* @deprecated 建议在 ProtectedRoute 组件中通过 onUnauthorized 回调处理导航
|
|
39
|
-
*/
|
|
40
|
-
signInPath?: string;
|
|
41
|
-
/**
|
|
42
|
-
* Token 存储的 localStorage key
|
|
43
|
-
* @default 'auth-token'
|
|
44
|
-
*/
|
|
45
|
-
tokenStorageKey?: string;
|
|
46
|
-
}
|
|
4
|
+
import type { AuthConfig, DefaultAuthConfig, BetterAuthPlugin } from "./types";
|
|
5
|
+
export type { AuthConfig, BetterAuthPlugin };
|
|
47
6
|
/**
|
|
48
7
|
* 默认配置
|
|
49
8
|
*/
|
|
50
|
-
export declare const defaultAuthConfig:
|
|
51
|
-
callbackURLBuilder: (redirectTo: string, baseURL: string) => string;
|
|
52
|
-
defaultRedirectAfterLogin: undefined;
|
|
53
|
-
plugins: BetterAuthPlugin[];
|
|
54
|
-
signInPath: undefined;
|
|
55
|
-
};
|
|
9
|
+
export declare const defaultAuthConfig: DefaultAuthConfig;
|
|
56
10
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE9E,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAA;AAE5C;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,iBAM/B,CAAA"}
|
package/dist/config.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 认证配置
|
|
3
|
+
*/
|
|
1
4
|
/**
|
|
2
5
|
* 默认配置
|
|
3
6
|
*/
|
|
4
7
|
export const defaultAuthConfig = {
|
|
5
|
-
baseURL: "",
|
|
6
|
-
callbackURLBuilder: (redirectTo, baseURL) => {
|
|
7
|
-
return `${baseURL}/v1/auth/redirect?to=${encodeURIComponent(redirectTo)}`;
|
|
8
|
-
},
|
|
9
|
-
defaultRedirectAfterLogin: undefined,
|
|
8
|
+
baseURL: "https://oneauth.choiceform.io",
|
|
10
9
|
getSessionEndpoint: "/v1/auth/get-session",
|
|
11
10
|
plugins: [],
|
|
12
|
-
|
|
11
|
+
skipTokenCleanupOnError: false,
|
|
13
12
|
tokenStorageKey: "auth-token",
|
|
14
13
|
};
|