qing-client 0.0.8 → 0.0.10
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/lib/srvice/AuthService.d.ts +4 -1
- package/lib/srvice/AuthService.js +38 -0
- package/lib/srvice/UserService.d.ts +9 -1
- package/lib/srvice/UserService.js +45 -11
- package/lib/types/user.d.ts +28 -0
- package/package.json +1 -1
- package/src/srvice/AuthService.ts +55 -2
- package/src/srvice/UserService.ts +51 -10
- package/src/types/user.ts +42 -3
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { BaseClient } from "../client/BaseClient";
|
|
2
2
|
import { ClientConfig, RequestOptions } from "../types";
|
|
3
|
-
import { LoginResponse } from "../types/user";
|
|
3
|
+
import { LoginResponse, TemporaryTokenRequest, TemporaryTokenResponse, VerifyTemporaryTokenRequest, VerifyTemporaryTokenResponse, WechatLoginCredentials } from "../types/user";
|
|
4
4
|
export declare class AuthService extends BaseClient {
|
|
5
5
|
constructor(config: ClientConfig);
|
|
6
6
|
login(identifier: string, password: string, projectId?: number, options?: RequestOptions): Promise<LoginResponse>;
|
|
7
|
+
wechatMiniProgramLogin(credentials: WechatLoginCredentials, projectId?: number, options?: RequestOptions): Promise<LoginResponse>;
|
|
8
|
+
createTemporaryToken(request?: TemporaryTokenRequest, options?: RequestOptions): Promise<TemporaryTokenResponse>;
|
|
9
|
+
verifyTemporaryToken(request: VerifyTemporaryTokenRequest, options?: RequestOptions): Promise<VerifyTemporaryTokenResponse>;
|
|
7
10
|
logout(token: string, options?: RequestOptions): Promise<void>;
|
|
8
11
|
}
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.AuthService = void 0;
|
|
7
|
+
// client/npm/src/service/AuthService.ts
|
|
7
8
|
const BaseClient_1 = require("../client/BaseClient");
|
|
8
9
|
const qs_1 = __importDefault(require("qs"));
|
|
9
10
|
class AuthService extends BaseClient_1.BaseClient {
|
|
@@ -30,6 +31,43 @@ class AuthService extends BaseClient_1.BaseClient {
|
|
|
30
31
|
body: body
|
|
31
32
|
});
|
|
32
33
|
}
|
|
34
|
+
// 微信小程序登录 - 新增接口
|
|
35
|
+
async wechatMiniProgramLogin(credentials, projectId = 0, options) {
|
|
36
|
+
return this.request('/wxmp/login', {
|
|
37
|
+
...options,
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: {
|
|
40
|
+
...options?.headers,
|
|
41
|
+
"Content-Type": "application/json",
|
|
42
|
+
"x-project-id": projectId.toString()
|
|
43
|
+
},
|
|
44
|
+
body: JSON.stringify(credentials)
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// 签发临时令牌 - 新增接口
|
|
48
|
+
async createTemporaryToken(request = { expires_in: 300 }, options) {
|
|
49
|
+
return this.request('/temporary-token', {
|
|
50
|
+
...options,
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: {
|
|
53
|
+
...options?.headers,
|
|
54
|
+
"Content-Type": "application/json"
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify(request)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// 验证临时令牌 - 新增接口(业务系统调用)
|
|
60
|
+
async verifyTemporaryToken(request, options) {
|
|
61
|
+
return this.request('/verify-temporary-token', {
|
|
62
|
+
...options,
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: {
|
|
65
|
+
...options?.headers,
|
|
66
|
+
"Content-Type": "application/json"
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify(request)
|
|
69
|
+
});
|
|
70
|
+
}
|
|
33
71
|
// 用户登出 - 匹配后端请求格式
|
|
34
72
|
async logout(token, options) {
|
|
35
73
|
return this.request('/logout', {
|
|
@@ -4,7 +4,15 @@ import { User, UserCreateRequest, UserUpdateRequest } from "../types/user";
|
|
|
4
4
|
export declare class UserService extends BaseClient {
|
|
5
5
|
constructor(config: ClientConfig);
|
|
6
6
|
getCurrentUser(options?: RequestOptions): Promise<User>;
|
|
7
|
+
getUserById(userId: number, options?: RequestOptions): Promise<User>;
|
|
7
8
|
createUser(userData: UserCreateRequest, options?: RequestOptions): Promise<User>;
|
|
8
9
|
updateUser(userId: number, updateData: UserUpdateRequest, options?: RequestOptions): Promise<User>;
|
|
9
|
-
listUsers(includeInactive?: boolean, page?: number, perPage?: number, options?: RequestOptions): Promise<PaginatedResponse<User>>;
|
|
10
|
+
listUsers(includeInactive?: boolean, page?: number, perPage?: number, projectId?: number, options?: RequestOptions): Promise<PaginatedResponse<User>>;
|
|
11
|
+
deactivateUser(userId: number, options?: RequestOptions): Promise<{
|
|
12
|
+
id: number;
|
|
13
|
+
}>;
|
|
14
|
+
restoreUser(userId: number, options?: RequestOptions): Promise<User>;
|
|
15
|
+
resetPassword(userId: number, newPassword: string, options?: RequestOptions): Promise<{
|
|
16
|
+
id: number;
|
|
17
|
+
}>;
|
|
10
18
|
}
|
|
@@ -6,14 +6,21 @@ class UserService extends BaseClient_1.BaseClient {
|
|
|
6
6
|
constructor(config) {
|
|
7
7
|
super(config, 'users');
|
|
8
8
|
}
|
|
9
|
-
// 获取当前用户信息
|
|
9
|
+
// 获取当前用户信息
|
|
10
10
|
async getCurrentUser(options) {
|
|
11
11
|
return this.request('/me', {
|
|
12
12
|
...options,
|
|
13
13
|
method: 'GET'
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
//
|
|
16
|
+
// 获取用户详情(管理员)
|
|
17
|
+
async getUserById(userId, options) {
|
|
18
|
+
return this.request(`/${userId}`, {
|
|
19
|
+
...options,
|
|
20
|
+
method: 'GET'
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// 创建用户(管理员)
|
|
17
24
|
async createUser(userData, options) {
|
|
18
25
|
return this.request('', {
|
|
19
26
|
...options,
|
|
@@ -29,7 +36,7 @@ class UserService extends BaseClient_1.BaseClient {
|
|
|
29
36
|
}
|
|
30
37
|
});
|
|
31
38
|
}
|
|
32
|
-
// 更新用户信息
|
|
39
|
+
// 更新用户信息
|
|
33
40
|
async updateUser(userId, updateData, options) {
|
|
34
41
|
return this.request(`/${userId}`, {
|
|
35
42
|
...options,
|
|
@@ -43,19 +50,46 @@ class UserService extends BaseClient_1.BaseClient {
|
|
|
43
50
|
}
|
|
44
51
|
});
|
|
45
52
|
}
|
|
46
|
-
//
|
|
47
|
-
async listUsers(includeInactive = false, page = 1, perPage = 10, options) {
|
|
53
|
+
// 获取用户列表(支持项目过滤)
|
|
54
|
+
async listUsers(includeInactive = false, page = 1, perPage = 10, projectId, options) {
|
|
55
|
+
const params = {
|
|
56
|
+
include_inactive: includeInactive,
|
|
57
|
+
page,
|
|
58
|
+
per_page: perPage
|
|
59
|
+
};
|
|
60
|
+
if (projectId !== undefined) {
|
|
61
|
+
params.project_id = projectId;
|
|
62
|
+
}
|
|
48
63
|
const response = await this.paginatedRequest('', {
|
|
49
64
|
...options,
|
|
50
65
|
method: 'GET',
|
|
51
|
-
params
|
|
52
|
-
include_inactive: includeInactive,
|
|
53
|
-
page,
|
|
54
|
-
per_page: perPage
|
|
55
|
-
}
|
|
66
|
+
params
|
|
56
67
|
});
|
|
57
|
-
// 直接返回分页响应
|
|
58
68
|
return response;
|
|
59
69
|
}
|
|
70
|
+
// 停用用户(管理员)
|
|
71
|
+
async deactivateUser(userId, options) {
|
|
72
|
+
return this.request(`/${userId}`, {
|
|
73
|
+
...options,
|
|
74
|
+
method: 'DELETE'
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
// 恢复用户(管理员)
|
|
78
|
+
async restoreUser(userId, options) {
|
|
79
|
+
return this.request(`/${userId}/restore`, {
|
|
80
|
+
...options,
|
|
81
|
+
method: 'POST'
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
// 重置密码(管理员)
|
|
85
|
+
async resetPassword(userId, newPassword, options) {
|
|
86
|
+
return this.request(`/${userId}/password`, {
|
|
87
|
+
...options,
|
|
88
|
+
method: 'PUT',
|
|
89
|
+
body: {
|
|
90
|
+
new_password: newPassword
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
60
94
|
}
|
|
61
95
|
exports.UserService = UserService;
|
package/lib/types/user.d.ts
CHANGED
|
@@ -35,3 +35,31 @@ export interface LoginResponse {
|
|
|
35
35
|
expires_at: string;
|
|
36
36
|
project_id: number;
|
|
37
37
|
}
|
|
38
|
+
export interface PasswordResetRequest {
|
|
39
|
+
new_password: string;
|
|
40
|
+
}
|
|
41
|
+
export interface UserOperationResponse {
|
|
42
|
+
id: number;
|
|
43
|
+
message?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface WechatLoginCredentials {
|
|
46
|
+
code: string;
|
|
47
|
+
phone_code?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface TemporaryTokenRequest {
|
|
50
|
+
expires_in?: number;
|
|
51
|
+
}
|
|
52
|
+
export interface TemporaryTokenResponse {
|
|
53
|
+
temporary_token: string;
|
|
54
|
+
expires_at: string;
|
|
55
|
+
expires_in: number;
|
|
56
|
+
}
|
|
57
|
+
export interface VerifyTemporaryTokenRequest {
|
|
58
|
+
token: string;
|
|
59
|
+
project_id?: number;
|
|
60
|
+
}
|
|
61
|
+
export interface VerifyTemporaryTokenResponse {
|
|
62
|
+
user: User;
|
|
63
|
+
token_valid: boolean;
|
|
64
|
+
project_id: number;
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
// client/npm/src/service/AuthService.ts
|
|
1
2
|
import { BaseClient } from "../client/BaseClient";
|
|
2
3
|
import { ClientConfig, RequestOptions } from "../types";
|
|
3
4
|
import qs from 'qs'
|
|
4
|
-
import {
|
|
5
|
-
|
|
5
|
+
import {
|
|
6
|
+
LoginResponse, TemporaryTokenRequest, TemporaryTokenResponse,
|
|
7
|
+
VerifyTemporaryTokenRequest, VerifyTemporaryTokenResponse, WechatLoginCredentials
|
|
8
|
+
} from "../types/user";
|
|
6
9
|
|
|
7
10
|
export class AuthService extends BaseClient {
|
|
8
11
|
constructor(config: ClientConfig) {
|
|
@@ -36,6 +39,56 @@ export class AuthService extends BaseClient {
|
|
|
36
39
|
});
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
// 微信小程序登录 - 新增接口
|
|
43
|
+
async wechatMiniProgramLogin(
|
|
44
|
+
credentials: WechatLoginCredentials,
|
|
45
|
+
projectId: number = 0,
|
|
46
|
+
options?: RequestOptions
|
|
47
|
+
): Promise<LoginResponse> {
|
|
48
|
+
return this.request<LoginResponse>('/wxmp/login', {
|
|
49
|
+
...options,
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: {
|
|
52
|
+
...options?.headers,
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
"x-project-id": projectId.toString()
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify(credentials)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 签发临时令牌 - 新增接口
|
|
61
|
+
async createTemporaryToken(
|
|
62
|
+
request: TemporaryTokenRequest = { expires_in: 300 },
|
|
63
|
+
options?: RequestOptions
|
|
64
|
+
): Promise<TemporaryTokenResponse> {
|
|
65
|
+
return this.request<TemporaryTokenResponse>('/temporary-token', {
|
|
66
|
+
...options,
|
|
67
|
+
method: 'POST',
|
|
68
|
+
headers: {
|
|
69
|
+
...options?.headers,
|
|
70
|
+
"Content-Type": "application/json"
|
|
71
|
+
},
|
|
72
|
+
body: JSON.stringify(request)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 验证临时令牌 - 新增接口(业务系统调用)
|
|
77
|
+
async verifyTemporaryToken(
|
|
78
|
+
request: VerifyTemporaryTokenRequest,
|
|
79
|
+
options?: RequestOptions
|
|
80
|
+
): Promise<VerifyTemporaryTokenResponse> {
|
|
81
|
+
return this.request<VerifyTemporaryTokenResponse>('/verify-temporary-token', {
|
|
82
|
+
...options,
|
|
83
|
+
method: 'POST',
|
|
84
|
+
headers: {
|
|
85
|
+
...options?.headers,
|
|
86
|
+
"Content-Type": "application/json"
|
|
87
|
+
},
|
|
88
|
+
body: JSON.stringify(request)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
39
92
|
// 用户登出 - 匹配后端请求格式
|
|
40
93
|
async logout(token: string, options?: RequestOptions): Promise<void> {
|
|
41
94
|
return this.request<void>('/logout', {
|
|
@@ -11,7 +11,7 @@ export class UserService extends BaseClient {
|
|
|
11
11
|
super(config, 'users');
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// 获取当前用户信息
|
|
14
|
+
// 获取当前用户信息
|
|
15
15
|
async getCurrentUser(options?: RequestOptions): Promise<User> {
|
|
16
16
|
return this.request<User>('/me', {
|
|
17
17
|
...options,
|
|
@@ -19,7 +19,15 @@ export class UserService extends BaseClient {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
//
|
|
22
|
+
// 获取用户详情(管理员)
|
|
23
|
+
async getUserById(userId: number, options?: RequestOptions): Promise<User> {
|
|
24
|
+
return this.request<User>(`/${userId}`, {
|
|
25
|
+
...options,
|
|
26
|
+
method: 'GET'
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 创建用户(管理员)
|
|
23
31
|
async createUser(userData: UserCreateRequest, options?: RequestOptions): Promise<User> {
|
|
24
32
|
return this.request<User>('', {
|
|
25
33
|
...options,
|
|
@@ -36,7 +44,7 @@ export class UserService extends BaseClient {
|
|
|
36
44
|
});
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
// 更新用户信息
|
|
47
|
+
// 更新用户信息
|
|
40
48
|
async updateUser(userId: number, updateData: UserUpdateRequest, options?: RequestOptions): Promise<User> {
|
|
41
49
|
return this.request<User>(`/${userId}`, {
|
|
42
50
|
...options,
|
|
@@ -51,24 +59,57 @@ export class UserService extends BaseClient {
|
|
|
51
59
|
});
|
|
52
60
|
}
|
|
53
61
|
|
|
54
|
-
//
|
|
62
|
+
// 获取用户列表(支持项目过滤)
|
|
55
63
|
async listUsers(
|
|
56
64
|
includeInactive: boolean = false,
|
|
57
65
|
page: number = 1,
|
|
58
66
|
perPage: number = 10,
|
|
67
|
+
projectId?: number,
|
|
59
68
|
options?: RequestOptions
|
|
60
69
|
): Promise<PaginatedResponse<User>> {
|
|
70
|
+
const params: any = {
|
|
71
|
+
include_inactive: includeInactive,
|
|
72
|
+
page,
|
|
73
|
+
per_page: perPage
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
if (projectId !== undefined) {
|
|
77
|
+
params.project_id = projectId;
|
|
78
|
+
}
|
|
79
|
+
|
|
61
80
|
const response = await this.paginatedRequest<User>('', {
|
|
62
81
|
...options,
|
|
63
82
|
method: 'GET',
|
|
64
|
-
params
|
|
65
|
-
include_inactive: includeInactive,
|
|
66
|
-
page,
|
|
67
|
-
per_page: perPage
|
|
68
|
-
}
|
|
83
|
+
params
|
|
69
84
|
});
|
|
70
85
|
|
|
71
|
-
// 直接返回分页响应
|
|
72
86
|
return response;
|
|
73
87
|
}
|
|
88
|
+
|
|
89
|
+
// 停用用户(管理员)
|
|
90
|
+
async deactivateUser(userId: number, options?: RequestOptions): Promise<{ id: number }> {
|
|
91
|
+
return this.request<{ id: number }>(`/${userId}`, {
|
|
92
|
+
...options,
|
|
93
|
+
method: 'DELETE'
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 恢复用户(管理员)
|
|
98
|
+
async restoreUser(userId: number, options?: RequestOptions): Promise<User> {
|
|
99
|
+
return this.request<User>(`/${userId}/restore`, {
|
|
100
|
+
...options,
|
|
101
|
+
method: 'POST'
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 重置密码(管理员)
|
|
106
|
+
async resetPassword(userId: number, newPassword: string, options?: RequestOptions): Promise<{ id: number }> {
|
|
107
|
+
return this.request<{ id: number }>(`/${userId}/password`, {
|
|
108
|
+
...options,
|
|
109
|
+
method: 'PUT',
|
|
110
|
+
body: {
|
|
111
|
+
new_password: newPassword
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
74
115
|
}
|
package/src/types/user.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// client/npm/src/types/user.ts
|
|
1
2
|
// 用户模型
|
|
2
3
|
export interface User {
|
|
3
4
|
id: number;
|
|
@@ -10,9 +11,9 @@ export interface User {
|
|
|
10
11
|
project_id: number;
|
|
11
12
|
is_active: boolean;
|
|
12
13
|
last_login_ip?: string;
|
|
13
|
-
last_login?: string;
|
|
14
|
-
created_at: string;
|
|
15
|
-
updated_at: string;
|
|
14
|
+
last_login?: string;
|
|
15
|
+
created_at: string;
|
|
16
|
+
updated_at: string;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
// 用户创建请求
|
|
@@ -41,3 +42,41 @@ export interface LoginResponse {
|
|
|
41
42
|
expires_at: string;
|
|
42
43
|
project_id: number;
|
|
43
44
|
}
|
|
45
|
+
|
|
46
|
+
// 密码重置请求
|
|
47
|
+
export interface PasswordResetRequest {
|
|
48
|
+
new_password: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 用户操作响应
|
|
52
|
+
export interface UserOperationResponse {
|
|
53
|
+
id: number;
|
|
54
|
+
message?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// auth相关
|
|
58
|
+
export interface WechatLoginCredentials {
|
|
59
|
+
code: string;
|
|
60
|
+
phone_code?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface TemporaryTokenRequest {
|
|
64
|
+
expires_in?: number; // 令牌有效期(秒),范围60-3600,默认300
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface TemporaryTokenResponse {
|
|
68
|
+
temporary_token: string;
|
|
69
|
+
expires_at: string;
|
|
70
|
+
expires_in: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface VerifyTemporaryTokenRequest {
|
|
74
|
+
token: string;
|
|
75
|
+
project_id?: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface VerifyTemporaryTokenResponse {
|
|
79
|
+
user: User;
|
|
80
|
+
token_valid: boolean;
|
|
81
|
+
project_id: number;
|
|
82
|
+
}
|