qing-client 0.0.7 → 0.0.9

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.
@@ -1,8 +1,32 @@
1
1
  import { BaseClient } from "../client/BaseClient";
2
2
  import { ClientConfig, RequestOptions } from "../types";
3
- import { LoginResponse } from "../types/user";
3
+ import { LoginResponse, User } from "../types/user";
4
+ export interface WechatLoginCredentials {
5
+ code: string;
6
+ phone_code?: string;
7
+ }
8
+ export interface TemporaryTokenRequest {
9
+ expires_in?: number;
10
+ }
11
+ export interface TemporaryTokenResponse {
12
+ temporary_token: string;
13
+ expires_at: string;
14
+ expires_in: number;
15
+ }
16
+ export interface VerifyTemporaryTokenRequest {
17
+ token: string;
18
+ project_id?: number;
19
+ }
20
+ export interface VerifyTemporaryTokenResponse {
21
+ user: User;
22
+ token_valid: boolean;
23
+ project_id: number;
24
+ }
4
25
  export declare class AuthService extends BaseClient {
5
26
  constructor(config: ClientConfig);
6
27
  login(identifier: string, password: string, projectId?: number, options?: RequestOptions): Promise<LoginResponse>;
28
+ wechatMiniProgramLogin(credentials: WechatLoginCredentials, projectId?: number, options?: RequestOptions): Promise<LoginResponse>;
29
+ createTemporaryToken(request?: TemporaryTokenRequest, options?: RequestOptions): Promise<TemporaryTokenResponse>;
30
+ verifyTemporaryToken(request: VerifyTemporaryTokenRequest, options?: RequestOptions): Promise<VerifyTemporaryTokenResponse>;
7
31
  logout(token: string, options?: RequestOptions): Promise<void>;
8
32
  }
@@ -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', {
@@ -1,8 +1,22 @@
1
1
  import { BaseClient } from "../client/BaseClient";
2
2
  import { ClientConfig, RequestOptions } from "../types";
3
- import { FeishuMessage, MailRequest } from "../types/msg";
3
+ import { BatchCreateMessageRequest, BatchMarkAsReadRequest, CategoryInfo, CreateMessageRequest, FeishuMessage, MailRequest, MarkAsReadRequest, Message, MessageQueryParams, MessageStats } from "../types/msg";
4
4
  export declare class MsgService extends BaseClient {
5
5
  constructor(config: ClientConfig);
6
6
  sendMail(request: MailRequest, options?: RequestOptions): Promise<void>;
7
7
  sendFeishuMessage(message: FeishuMessage, options?: RequestOptions): Promise<void>;
8
+ getMessages(params?: MessageQueryParams, options?: RequestOptions): Promise<Message[]>;
9
+ getAdminMessages(params?: MessageQueryParams, options?: RequestOptions): Promise<Message[]>;
10
+ markAsRead(messageId: string, request?: MarkAsReadRequest, options?: RequestOptions): Promise<Message>;
11
+ markManyAsRead(request: BatchMarkAsReadRequest, options?: RequestOptions): Promise<{
12
+ modifiedCount: number;
13
+ }>;
14
+ deleteMessage(messageId: string, request?: MarkAsReadRequest, options?: RequestOptions): Promise<Message>;
15
+ getUnreadStats(userId?: string, options?: RequestOptions): Promise<MessageStats>;
16
+ getCategories(options?: RequestOptions): Promise<CategoryInfo[]>;
17
+ createMessage(request: CreateMessageRequest, options?: RequestOptions): Promise<Message>;
18
+ createManyMessages(request: BatchCreateMessageRequest, options?: RequestOptions): Promise<{
19
+ createdCount: number;
20
+ messages: Message[];
21
+ }>;
8
22
  }
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MsgService = void 0;
4
+ // client/npm/src/srvice/MsgService.ts
4
5
  const BaseClient_1 = require("../client/BaseClient");
5
6
  class MsgService extends BaseClient_1.BaseClient {
6
7
  constructor(config) {
7
8
  super(config, 'msg');
8
9
  }
9
- // 发送邮件 - 返回实际结果
10
+ // 发送邮件
10
11
  async sendMail(request, options) {
11
12
  return this.request('/mail/send', {
12
13
  ...options,
@@ -14,7 +15,7 @@ class MsgService extends BaseClient_1.BaseClient {
14
15
  body: request
15
16
  });
16
17
  }
17
- // 发送飞书消息 - 返回实际结果
18
+ // 发送飞书消息
18
19
  async sendFeishuMessage(message, options) {
19
20
  return this.request('/webhook/feishu/send', {
20
21
  ...options,
@@ -22,5 +23,77 @@ class MsgService extends BaseClient_1.BaseClient {
22
23
  body: message
23
24
  });
24
25
  }
26
+ // === 消息中心相关接口 ===
27
+ // 获取用户消息列表
28
+ async getMessages(params, options) {
29
+ return this.request('/message/list', {
30
+ ...options,
31
+ method: 'GET',
32
+ params: params // 使用 params 而不是 query
33
+ });
34
+ }
35
+ // 管理员获取消息列表(需要管理员权限)
36
+ async getAdminMessages(params, options) {
37
+ return this.request('/message/admin/list', {
38
+ ...options,
39
+ method: 'GET',
40
+ params: params // 使用 params 而不是 query
41
+ });
42
+ }
43
+ // 标记单条消息为已读
44
+ async markAsRead(messageId, request, options) {
45
+ return this.request(`/message/${messageId}/read`, {
46
+ ...options,
47
+ method: 'PATCH',
48
+ body: request
49
+ });
50
+ }
51
+ // 批量标记消息为已读
52
+ async markManyAsRead(request, options) {
53
+ return this.request('/message/batch/read', {
54
+ ...options,
55
+ method: 'PATCH',
56
+ body: request
57
+ });
58
+ }
59
+ // 删除消息(软删除)
60
+ async deleteMessage(messageId, request, options) {
61
+ return this.request(`/message/${messageId}`, {
62
+ ...options,
63
+ method: 'DELETE',
64
+ body: request
65
+ });
66
+ }
67
+ // 获取未读消息统计
68
+ async getUnreadStats(userId, options) {
69
+ return this.request('/message/stats', {
70
+ ...options,
71
+ method: 'GET',
72
+ params: userId ? { userId } : undefined // 使用 params 而不是 query
73
+ });
74
+ }
75
+ // 获取用户消息分类
76
+ async getCategories(options) {
77
+ return this.request('/message/categories', {
78
+ ...options,
79
+ method: 'GET'
80
+ });
81
+ }
82
+ // 创建消息(需要管理员权限)
83
+ async createMessage(request, options) {
84
+ return this.request('/message', {
85
+ ...options,
86
+ method: 'POST',
87
+ body: request
88
+ });
89
+ }
90
+ // 批量创建消息(需要管理员权限)
91
+ async createManyMessages(request, options) {
92
+ return this.request('/message/batch', {
93
+ ...options,
94
+ method: 'POST',
95
+ body: request
96
+ });
97
+ }
25
98
  }
26
99
  exports.MsgService = MsgService;
@@ -1,14 +1,16 @@
1
1
  export interface MailRequest {
2
- to: string[];
3
- subject: string;
4
- text?: string;
5
- html?: string;
6
2
  from?: string;
3
+ sender?: string;
4
+ to: string[];
7
5
  cc?: string[];
8
6
  bcc?: string[];
7
+ replyTo?: string;
8
+ subject?: string;
9
+ text?: string;
10
+ html?: string;
9
11
  attachments?: Array<{
10
12
  filename: string;
11
- content: string;
13
+ content: string | Buffer;
12
14
  contentType?: string;
13
15
  }>;
14
16
  }
@@ -27,5 +29,68 @@ export interface FeishuMessage {
27
29
  actions?: Array<{
28
30
  text: string;
29
31
  url: string;
32
+ type?: string;
33
+ }>;
34
+ }
35
+ export interface Message {
36
+ _id: string;
37
+ pid: string;
38
+ aid: string;
39
+ userId: string;
40
+ title: string;
41
+ content: string;
42
+ type: 'system' | 'business' | 'notice';
43
+ category: string;
44
+ isRead: boolean;
45
+ readAt?: string;
46
+ metadata?: Record<string, any>;
47
+ createdAt: string;
48
+ updatedAt: string;
49
+ }
50
+ export interface MessageQueryParams {
51
+ type?: 'system' | 'business' | 'notice';
52
+ category?: string;
53
+ isRead?: boolean;
54
+ page?: number;
55
+ limit?: number;
56
+ userId?: string;
57
+ pid?: string;
58
+ aid?: string;
59
+ }
60
+ export interface MessageStats {
61
+ total: number;
62
+ byCategory: Record<string, number>;
63
+ }
64
+ export interface CreateMessageRequest {
65
+ userId?: string;
66
+ title: string;
67
+ content: string;
68
+ type: 'system' | 'business' | 'notice';
69
+ category: string;
70
+ metadata?: Record<string, any>;
71
+ }
72
+ export interface BatchCreateMessageRequest {
73
+ messages: Array<{
74
+ userId: string;
75
+ title: string;
76
+ content: string;
77
+ type: 'system' | 'business' | 'notice';
78
+ category: string;
79
+ metadata?: Record<string, any>;
30
80
  }>;
31
81
  }
82
+ export interface MarkAsReadRequest {
83
+ userId?: string;
84
+ }
85
+ export interface BatchMarkAsReadRequest {
86
+ messageIds: string[];
87
+ userId?: string;
88
+ }
89
+ export interface CategoryInfo {
90
+ category: string;
91
+ unreadCount: number;
92
+ latestMessage?: {
93
+ title: string;
94
+ createdAt: string;
95
+ };
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qing-client",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
@@ -1,8 +1,35 @@
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 { LoginResponse } from "../types/user";
5
+ import { LoginResponse, User } from "../types/user";
5
6
 
7
+ // 新增接口类型定义
8
+ export interface WechatLoginCredentials {
9
+ code: string;
10
+ phone_code?: string;
11
+ }
12
+
13
+ export interface TemporaryTokenRequest {
14
+ expires_in?: number; // 令牌有效期(秒),范围60-3600,默认300
15
+ }
16
+
17
+ export interface TemporaryTokenResponse {
18
+ temporary_token: string;
19
+ expires_at: string;
20
+ expires_in: number;
21
+ }
22
+
23
+ export interface VerifyTemporaryTokenRequest {
24
+ token: string;
25
+ project_id?: number;
26
+ }
27
+
28
+ export interface VerifyTemporaryTokenResponse {
29
+ user: User;
30
+ token_valid: boolean;
31
+ project_id: number;
32
+ }
6
33
 
7
34
  export class AuthService extends BaseClient {
8
35
  constructor(config: ClientConfig) {
@@ -36,6 +63,56 @@ export class AuthService extends BaseClient {
36
63
  });
37
64
  }
38
65
 
66
+ // 微信小程序登录 - 新增接口
67
+ async wechatMiniProgramLogin(
68
+ credentials: WechatLoginCredentials,
69
+ projectId: number = 0,
70
+ options?: RequestOptions
71
+ ): Promise<LoginResponse> {
72
+ return this.request<LoginResponse>('/wxmp/login', {
73
+ ...options,
74
+ method: 'POST',
75
+ headers: {
76
+ ...options?.headers,
77
+ "Content-Type": "application/json",
78
+ "x-project-id": projectId.toString()
79
+ },
80
+ body: JSON.stringify(credentials)
81
+ });
82
+ }
83
+
84
+ // 签发临时令牌 - 新增接口
85
+ async createTemporaryToken(
86
+ request: TemporaryTokenRequest = { expires_in: 300 },
87
+ options?: RequestOptions
88
+ ): Promise<TemporaryTokenResponse> {
89
+ return this.request<TemporaryTokenResponse>('/temporary-token', {
90
+ ...options,
91
+ method: 'POST',
92
+ headers: {
93
+ ...options?.headers,
94
+ "Content-Type": "application/json"
95
+ },
96
+ body: JSON.stringify(request)
97
+ });
98
+ }
99
+
100
+ // 验证临时令牌 - 新增接口(业务系统调用)
101
+ async verifyTemporaryToken(
102
+ request: VerifyTemporaryTokenRequest,
103
+ options?: RequestOptions
104
+ ): Promise<VerifyTemporaryTokenResponse> {
105
+ return this.request<VerifyTemporaryTokenResponse>('/verify-temporary-token', {
106
+ ...options,
107
+ method: 'POST',
108
+ headers: {
109
+ ...options?.headers,
110
+ "Content-Type": "application/json"
111
+ },
112
+ body: JSON.stringify(request)
113
+ });
114
+ }
115
+
39
116
  // 用户登出 - 匹配后端请求格式
40
117
  async logout(token: string, options?: RequestOptions): Promise<void> {
41
118
  return this.request<void>('/logout', {
@@ -1,14 +1,14 @@
1
+ // client/npm/src/srvice/MsgService.ts
1
2
  import { BaseClient } from "../client/BaseClient";
2
3
  import { ClientConfig, RequestOptions } from "../types";
3
- import { FeishuMessage, MailRequest } from "../types/msg";
4
-
4
+ import { BatchCreateMessageRequest, BatchMarkAsReadRequest, CategoryInfo, CreateMessageRequest, FeishuMessage, MailRequest, MarkAsReadRequest, Message, MessageQueryParams, MessageStats } from "../types/msg";
5
5
 
6
6
  export class MsgService extends BaseClient {
7
7
  constructor(config: ClientConfig) {
8
8
  super(config, 'msg');
9
9
  }
10
10
 
11
- // 发送邮件 - 返回实际结果
11
+ // 发送邮件
12
12
  async sendMail(request: MailRequest, options?: RequestOptions): Promise<void> {
13
13
  return this.request<void>('/mail/send', {
14
14
  ...options,
@@ -17,7 +17,7 @@ export class MsgService extends BaseClient {
17
17
  });
18
18
  }
19
19
 
20
- // 发送飞书消息 - 返回实际结果
20
+ // 发送飞书消息
21
21
  async sendFeishuMessage(message: FeishuMessage, options?: RequestOptions): Promise<void> {
22
22
  return this.request<void>('/webhook/feishu/send', {
23
23
  ...options,
@@ -25,4 +25,86 @@ export class MsgService extends BaseClient {
25
25
  body: message
26
26
  });
27
27
  }
28
+
29
+ // === 消息中心相关接口 ===
30
+
31
+ // 获取用户消息列表
32
+ async getMessages(params?: MessageQueryParams, options?: RequestOptions): Promise<Message[]> {
33
+ return this.request<Message[]>('/message/list', {
34
+ ...options,
35
+ method: 'GET',
36
+ params: params // 使用 params 而不是 query
37
+ });
38
+ }
39
+
40
+ // 管理员获取消息列表(需要管理员权限)
41
+ async getAdminMessages(params?: MessageQueryParams, options?: RequestOptions): Promise<Message[]> {
42
+ return this.request<Message[]>('/message/admin/list', {
43
+ ...options,
44
+ method: 'GET',
45
+ params: params // 使用 params 而不是 query
46
+ });
47
+ }
48
+
49
+ // 标记单条消息为已读
50
+ async markAsRead(messageId: string, request?: MarkAsReadRequest, options?: RequestOptions): Promise<Message> {
51
+ return this.request<Message>(`/message/${messageId}/read`, {
52
+ ...options,
53
+ method: 'PATCH',
54
+ body: request
55
+ });
56
+ }
57
+
58
+ // 批量标记消息为已读
59
+ async markManyAsRead(request: BatchMarkAsReadRequest, options?: RequestOptions): Promise<{ modifiedCount: number }> {
60
+ return this.request<{ modifiedCount: number }>('/message/batch/read', {
61
+ ...options,
62
+ method: 'PATCH',
63
+ body: request
64
+ });
65
+ }
66
+
67
+ // 删除消息(软删除)
68
+ async deleteMessage(messageId: string, request?: MarkAsReadRequest, options?: RequestOptions): Promise<Message> {
69
+ return this.request<Message>(`/message/${messageId}`, {
70
+ ...options,
71
+ method: 'DELETE',
72
+ body: request
73
+ });
74
+ }
75
+
76
+ // 获取未读消息统计
77
+ async getUnreadStats(userId?: string, options?: RequestOptions): Promise<MessageStats> {
78
+ return this.request<MessageStats>('/message/stats', {
79
+ ...options,
80
+ method: 'GET',
81
+ params: userId ? { userId } : undefined // 使用 params 而不是 query
82
+ });
83
+ }
84
+
85
+ // 获取用户消息分类
86
+ async getCategories(options?: RequestOptions): Promise<CategoryInfo[]> {
87
+ return this.request<CategoryInfo[]>('/message/categories', {
88
+ ...options,
89
+ method: 'GET'
90
+ });
91
+ }
92
+
93
+ // 创建消息(需要管理员权限)
94
+ async createMessage(request: CreateMessageRequest, options?: RequestOptions): Promise<Message> {
95
+ return this.request<Message>('/message', {
96
+ ...options,
97
+ method: 'POST',
98
+ body: request
99
+ });
100
+ }
101
+
102
+ // 批量创建消息(需要管理员权限)
103
+ async createManyMessages(request: BatchCreateMessageRequest, options?: RequestOptions): Promise<{ createdCount: number, messages: Message[] }> {
104
+ return this.request<{ createdCount: number, messages: Message[] }>('/message/batch', {
105
+ ...options,
106
+ method: 'POST',
107
+ body: request
108
+ });
109
+ }
28
110
  }
@@ -1,3 +1,4 @@
1
+ // npm/src/types/index.ts
1
2
  // 统一API响应格式
2
3
  export interface ApiResponse<T = any> {
3
4
  success: boolean;
package/src/types/msg.ts CHANGED
@@ -1,14 +1,16 @@
1
1
  export interface MailRequest {
2
- to: string[];
3
- subject: string;
4
- text?: string;
5
- html?: string;
6
2
  from?: string;
3
+ sender?: string;
4
+ to: string[];
7
5
  cc?: string[];
8
6
  bcc?: string[];
7
+ replyTo?: string;
8
+ subject?: string;
9
+ text?: string;
10
+ html?: string;
9
11
  attachments?: Array<{
10
12
  filename: string;
11
- content: string; // base64编码
13
+ content: string | Buffer;
12
14
  contentType?: string;
13
15
  }>;
14
16
  }
@@ -28,5 +30,77 @@ export interface FeishuMessage {
28
30
  actions?: Array<{
29
31
  text: string;
30
32
  url: string;
33
+ type?: string;
34
+ }>;
35
+ }
36
+
37
+ // 消息相关类型定义
38
+ export interface Message {
39
+ _id: string;
40
+ pid: string;
41
+ aid: string;
42
+ userId: string;
43
+ title: string;
44
+ content: string;
45
+ type: 'system' | 'business' | 'notice';
46
+ category: string;
47
+ isRead: boolean;
48
+ readAt?: string;
49
+ metadata?: Record<string, any>;
50
+ createdAt: string;
51
+ updatedAt: string;
52
+ }
53
+
54
+ export interface MessageQueryParams {
55
+ type?: 'system' | 'business' | 'notice';
56
+ category?: string;
57
+ isRead?: boolean;
58
+ page?: number;
59
+ limit?: number;
60
+ userId?: string; // 管理员查询特定用户的消息
61
+ pid?: string; // 管理员查询特定项目
62
+ aid?: string; // 管理员查询特定应用
63
+ }
64
+
65
+ export interface MessageStats {
66
+ total: number;
67
+ byCategory: Record<string, number>;
68
+ }
69
+
70
+ export interface CreateMessageRequest {
71
+ userId?: string; // 管理员可指定用户ID,不指定则使用当前用户
72
+ title: string;
73
+ content: string;
74
+ type: 'system' | 'business' | 'notice';
75
+ category: string;
76
+ metadata?: Record<string, any>;
77
+ }
78
+
79
+ export interface BatchCreateMessageRequest {
80
+ messages: Array<{
81
+ userId: string;
82
+ title: string;
83
+ content: string;
84
+ type: 'system' | 'business' | 'notice';
85
+ category: string;
86
+ metadata?: Record<string, any>;
31
87
  }>;
32
88
  }
89
+
90
+ export interface MarkAsReadRequest {
91
+ userId?: string; // 管理员可指定用户ID
92
+ }
93
+
94
+ export interface BatchMarkAsReadRequest {
95
+ messageIds: string[];
96
+ userId?: string; // 管理员可指定用户ID
97
+ }
98
+
99
+ export interface CategoryInfo {
100
+ category: string;
101
+ unreadCount: number;
102
+ latestMessage?: {
103
+ title: string;
104
+ createdAt: string;
105
+ };
106
+ }
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
  // 用户创建请求
@@ -40,4 +41,4 @@ export interface LoginResponse {
40
41
  token_type: string;
41
42
  expires_at: string;
42
43
  project_id: number;
43
- }
44
+ }