@plolink/sdk 0.0.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.
Files changed (76) hide show
  1. package/README.md +259 -0
  2. package/dist/chunk-4H4RACSE.js +335 -0
  3. package/dist/chunk-4H4RACSE.js.map +1 -0
  4. package/dist/chunk-IHAAKFEJ.js +219 -0
  5. package/dist/chunk-IHAAKFEJ.js.map +1 -0
  6. package/dist/chunk-JR4HYYQI.cjs +221 -0
  7. package/dist/chunk-JR4HYYQI.cjs.map +1 -0
  8. package/dist/chunk-MD4O7FWT.js +46 -0
  9. package/dist/chunk-MD4O7FWT.js.map +1 -0
  10. package/dist/chunk-NS3DJP2O.cjs +349 -0
  11. package/dist/chunk-NS3DJP2O.cjs.map +1 -0
  12. package/dist/chunk-Y3UJVC2L.cjs +48 -0
  13. package/dist/chunk-Y3UJVC2L.cjs.map +1 -0
  14. package/dist/client-CAjIQKPm.d.cts +193 -0
  15. package/dist/client-CwNikk7i.d.ts +193 -0
  16. package/dist/common/index.cjs +65 -0
  17. package/dist/common/index.cjs.map +1 -0
  18. package/dist/common/index.d.cts +422 -0
  19. package/dist/common/index.d.ts +422 -0
  20. package/dist/common/index.js +4 -0
  21. package/dist/common/index.js.map +1 -0
  22. package/dist/core-77EbLgbp.d.cts +97 -0
  23. package/dist/core-77EbLgbp.d.ts +97 -0
  24. package/dist/index.cjs +350 -0
  25. package/dist/index.cjs.map +1 -0
  26. package/dist/index.d.cts +98 -0
  27. package/dist/index.d.ts +98 -0
  28. package/dist/index.js +306 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/modules/agent/index.cjs +21 -0
  31. package/dist/modules/agent/index.cjs.map +1 -0
  32. package/dist/modules/agent/index.d.cts +71 -0
  33. package/dist/modules/agent/index.d.ts +71 -0
  34. package/dist/modules/agent/index.js +19 -0
  35. package/dist/modules/agent/index.js.map +1 -0
  36. package/dist/modules/billing/index.cjs +413 -0
  37. package/dist/modules/billing/index.cjs.map +1 -0
  38. package/dist/modules/billing/index.d.cts +538 -0
  39. package/dist/modules/billing/index.d.ts +538 -0
  40. package/dist/modules/billing/index.js +411 -0
  41. package/dist/modules/billing/index.js.map +1 -0
  42. package/dist/modules/chat/index.cjs +20 -0
  43. package/dist/modules/chat/index.cjs.map +1 -0
  44. package/dist/modules/chat/index.d.cts +68 -0
  45. package/dist/modules/chat/index.d.ts +68 -0
  46. package/dist/modules/chat/index.js +18 -0
  47. package/dist/modules/chat/index.js.map +1 -0
  48. package/dist/modules/psych/index.cjs +20 -0
  49. package/dist/modules/psych/index.cjs.map +1 -0
  50. package/dist/modules/psych/index.d.cts +69 -0
  51. package/dist/modules/psych/index.d.ts +69 -0
  52. package/dist/modules/psych/index.js +18 -0
  53. package/dist/modules/psych/index.js.map +1 -0
  54. package/dist/modules/rbac/index.cjs +197 -0
  55. package/dist/modules/rbac/index.cjs.map +1 -0
  56. package/dist/modules/rbac/index.d.cts +293 -0
  57. package/dist/modules/rbac/index.d.ts +293 -0
  58. package/dist/modules/rbac/index.js +195 -0
  59. package/dist/modules/rbac/index.js.map +1 -0
  60. package/dist/modules/team/index.cjs +54 -0
  61. package/dist/modules/team/index.cjs.map +1 -0
  62. package/dist/modules/team/index.d.cts +91 -0
  63. package/dist/modules/team/index.d.ts +91 -0
  64. package/dist/modules/team/index.js +52 -0
  65. package/dist/modules/team/index.js.map +1 -0
  66. package/dist/modules/virtual-account/index.cjs +293 -0
  67. package/dist/modules/virtual-account/index.cjs.map +1 -0
  68. package/dist/modules/virtual-account/index.d.cts +366 -0
  69. package/dist/modules/virtual-account/index.d.ts +366 -0
  70. package/dist/modules/virtual-account/index.js +291 -0
  71. package/dist/modules/virtual-account/index.js.map +1 -0
  72. package/dist/poller-BlIRbwL4.d.cts +201 -0
  73. package/dist/poller-DWKZjuSw.d.ts +201 -0
  74. package/dist/shared-6ZepUSPW.d.cts +31 -0
  75. package/dist/shared-6ZepUSPW.d.ts +31 -0
  76. package/package.json +96 -0
@@ -0,0 +1,201 @@
1
+ import { P as PollerOptions, a as PollerSnapshot } from './core-77EbLgbp.cjs';
2
+
3
+ /**
4
+ * 指数退避轮询器
5
+ *
6
+ * @description
7
+ * 实现了智能轮询机制,具有以下特性:
8
+ * - **指数退避**:失败时按配置的退避因子增加轮询间隔
9
+ * - **自动停止**:通过 shouldStop 判断终态自动停止
10
+ * - **状态快照**:支持导出和恢复轮询状态
11
+ * - **挂载恢复**:适用于组件卸载后重新挂载的场景
12
+ *
13
+ * @template T - 轮询任务返回值的类型
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // 创建轮询器
18
+ * const poller = new Poller({
19
+ * task: () => fetch('/api/order/123').then(r => r.json()),
20
+ * onResult: (data) => {
21
+ * console.log('Order status:', data.status);
22
+ * },
23
+ * shouldStop: (data) => data.status === 'success' || data.status === 'failed',
24
+ * initialInterval: 1000,
25
+ * maxInterval: 30000,
26
+ * backoffFactor: 1.5,
27
+ * onError: (error) => {
28
+ * console.error('Polling error:', error);
29
+ * }
30
+ * });
31
+ *
32
+ * // 启动轮询
33
+ * poller.start();
34
+ *
35
+ * // 停止轮询
36
+ * poller.stop();
37
+ *
38
+ * // 导出状态快照(用于恢复)
39
+ * const snapshot = poller.getSnapshot();
40
+ *
41
+ * // 从快照恢复
42
+ * poller.restoreFromSnapshot(snapshot);
43
+ * ```
44
+ */
45
+ declare class Poller<T> {
46
+ /**
47
+ * 轮询配置选项
48
+ */
49
+ private readonly options;
50
+ /**
51
+ * 定时器引用
52
+ */
53
+ private timer;
54
+ /**
55
+ * 当前轮询间隔(毫秒)
56
+ */
57
+ private currentInterval;
58
+ /**
59
+ * 当前重试次数
60
+ */
61
+ private retryCount;
62
+ /**
63
+ * 是否正在运行
64
+ */
65
+ private isRunning;
66
+ /**
67
+ * 是否正在执行任务
68
+ */
69
+ private isExecuting;
70
+ /**
71
+ * 创建一个 Poller 实例
72
+ *
73
+ * @param options - 轮询器配置选项
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const poller = new Poller({
78
+ * task: async () => {
79
+ * const response = await fetch('/api/status');
80
+ * return response.json();
81
+ * },
82
+ * onResult: (data) => console.log(data),
83
+ * shouldStop: (data) => data.completed === true
84
+ * });
85
+ * ```
86
+ */
87
+ constructor(options: PollerOptions<T>);
88
+ /**
89
+ * 启动或恢复轮询
90
+ *
91
+ * @description
92
+ * 如果轮询器已经在运行,此方法不会有任何效果。
93
+ * 首次调用会立即执行一次任务。
94
+ *
95
+ * @returns Promise,在首次任务执行完成后 resolve
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * await poller.start();
100
+ * console.log('Polling started');
101
+ * ```
102
+ */
103
+ start(): Promise<void>;
104
+ /**
105
+ * 停止轮询
106
+ *
107
+ * @description
108
+ * 停止后可以通过再次调用 start() 恢复轮询。
109
+ * 如果有正在执行的任务,会等待其完成。
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * poller.stop();
114
+ * console.log('Polling stopped');
115
+ * ```
116
+ */
117
+ stop(): void;
118
+ /**
119
+ * 执行轮询任务
120
+ *
121
+ * @private
122
+ */
123
+ private execute;
124
+ /**
125
+ * 获取当前状态快照
126
+ *
127
+ * @description
128
+ * 用于保存轮询器的当前状态,以便后续恢复。
129
+ * 这在组件卸载/重新挂载场景中非常有用。
130
+ *
131
+ * @returns 状态快照对象
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const snapshot = poller.getSnapshot();
136
+ * localStorage.setItem('poller-state', JSON.stringify(snapshot));
137
+ *
138
+ * // 恢复时
139
+ * const snapshot = JSON.parse(localStorage.getItem('poller-state'));
140
+ * poller.restoreFromSnapshot(snapshot);
141
+ * ```
142
+ */
143
+ getSnapshot(): PollerSnapshot;
144
+ /**
145
+ * 从状态快照恢复
146
+ *
147
+ * @description
148
+ * 从之前保存的快照中恢复轮询器状态。
149
+ * 注意:此方法不会自动启动轮询,需要手动调用 start()。
150
+ *
151
+ * @param snapshot - 状态快照对象
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const snapshot = {
156
+ * retryCount: 3,
157
+ * currentInterval: 3375,
158
+ * isRunning: false
159
+ * };
160
+ * poller.restoreFromSnapshot(snapshot);
161
+ *
162
+ * // 如果需要继续轮询
163
+ * if (snapshot.isRunning) {
164
+ * poller.start();
165
+ * }
166
+ * ```
167
+ */
168
+ restoreFromSnapshot(snapshot: PollerSnapshot): void;
169
+ /**
170
+ * 重置轮询器状态
171
+ *
172
+ * @description
173
+ * 将轮询器重置到初始状态(重试次数归零,间隔重置)。
174
+ * 不会停止正在运行的轮询。
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * poller.reset();
179
+ * ```
180
+ */
181
+ reset(): void;
182
+ /**
183
+ * 获取当前状态信息
184
+ *
185
+ * @returns 包含当前状态的对象
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * const status = poller.getStatus();
190
+ * console.log(`Running: ${status.isRunning}, Retry: ${status.retryCount}`);
191
+ * ```
192
+ */
193
+ getStatus(): {
194
+ isRunning: boolean;
195
+ isExecuting: boolean;
196
+ retryCount: number;
197
+ currentInterval: number;
198
+ };
199
+ }
200
+
201
+ export { Poller as P };
@@ -0,0 +1,201 @@
1
+ import { P as PollerOptions, a as PollerSnapshot } from './core-77EbLgbp.js';
2
+
3
+ /**
4
+ * 指数退避轮询器
5
+ *
6
+ * @description
7
+ * 实现了智能轮询机制,具有以下特性:
8
+ * - **指数退避**:失败时按配置的退避因子增加轮询间隔
9
+ * - **自动停止**:通过 shouldStop 判断终态自动停止
10
+ * - **状态快照**:支持导出和恢复轮询状态
11
+ * - **挂载恢复**:适用于组件卸载后重新挂载的场景
12
+ *
13
+ * @template T - 轮询任务返回值的类型
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // 创建轮询器
18
+ * const poller = new Poller({
19
+ * task: () => fetch('/api/order/123').then(r => r.json()),
20
+ * onResult: (data) => {
21
+ * console.log('Order status:', data.status);
22
+ * },
23
+ * shouldStop: (data) => data.status === 'success' || data.status === 'failed',
24
+ * initialInterval: 1000,
25
+ * maxInterval: 30000,
26
+ * backoffFactor: 1.5,
27
+ * onError: (error) => {
28
+ * console.error('Polling error:', error);
29
+ * }
30
+ * });
31
+ *
32
+ * // 启动轮询
33
+ * poller.start();
34
+ *
35
+ * // 停止轮询
36
+ * poller.stop();
37
+ *
38
+ * // 导出状态快照(用于恢复)
39
+ * const snapshot = poller.getSnapshot();
40
+ *
41
+ * // 从快照恢复
42
+ * poller.restoreFromSnapshot(snapshot);
43
+ * ```
44
+ */
45
+ declare class Poller<T> {
46
+ /**
47
+ * 轮询配置选项
48
+ */
49
+ private readonly options;
50
+ /**
51
+ * 定时器引用
52
+ */
53
+ private timer;
54
+ /**
55
+ * 当前轮询间隔(毫秒)
56
+ */
57
+ private currentInterval;
58
+ /**
59
+ * 当前重试次数
60
+ */
61
+ private retryCount;
62
+ /**
63
+ * 是否正在运行
64
+ */
65
+ private isRunning;
66
+ /**
67
+ * 是否正在执行任务
68
+ */
69
+ private isExecuting;
70
+ /**
71
+ * 创建一个 Poller 实例
72
+ *
73
+ * @param options - 轮询器配置选项
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const poller = new Poller({
78
+ * task: async () => {
79
+ * const response = await fetch('/api/status');
80
+ * return response.json();
81
+ * },
82
+ * onResult: (data) => console.log(data),
83
+ * shouldStop: (data) => data.completed === true
84
+ * });
85
+ * ```
86
+ */
87
+ constructor(options: PollerOptions<T>);
88
+ /**
89
+ * 启动或恢复轮询
90
+ *
91
+ * @description
92
+ * 如果轮询器已经在运行,此方法不会有任何效果。
93
+ * 首次调用会立即执行一次任务。
94
+ *
95
+ * @returns Promise,在首次任务执行完成后 resolve
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * await poller.start();
100
+ * console.log('Polling started');
101
+ * ```
102
+ */
103
+ start(): Promise<void>;
104
+ /**
105
+ * 停止轮询
106
+ *
107
+ * @description
108
+ * 停止后可以通过再次调用 start() 恢复轮询。
109
+ * 如果有正在执行的任务,会等待其完成。
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * poller.stop();
114
+ * console.log('Polling stopped');
115
+ * ```
116
+ */
117
+ stop(): void;
118
+ /**
119
+ * 执行轮询任务
120
+ *
121
+ * @private
122
+ */
123
+ private execute;
124
+ /**
125
+ * 获取当前状态快照
126
+ *
127
+ * @description
128
+ * 用于保存轮询器的当前状态,以便后续恢复。
129
+ * 这在组件卸载/重新挂载场景中非常有用。
130
+ *
131
+ * @returns 状态快照对象
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const snapshot = poller.getSnapshot();
136
+ * localStorage.setItem('poller-state', JSON.stringify(snapshot));
137
+ *
138
+ * // 恢复时
139
+ * const snapshot = JSON.parse(localStorage.getItem('poller-state'));
140
+ * poller.restoreFromSnapshot(snapshot);
141
+ * ```
142
+ */
143
+ getSnapshot(): PollerSnapshot;
144
+ /**
145
+ * 从状态快照恢复
146
+ *
147
+ * @description
148
+ * 从之前保存的快照中恢复轮询器状态。
149
+ * 注意:此方法不会自动启动轮询,需要手动调用 start()。
150
+ *
151
+ * @param snapshot - 状态快照对象
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const snapshot = {
156
+ * retryCount: 3,
157
+ * currentInterval: 3375,
158
+ * isRunning: false
159
+ * };
160
+ * poller.restoreFromSnapshot(snapshot);
161
+ *
162
+ * // 如果需要继续轮询
163
+ * if (snapshot.isRunning) {
164
+ * poller.start();
165
+ * }
166
+ * ```
167
+ */
168
+ restoreFromSnapshot(snapshot: PollerSnapshot): void;
169
+ /**
170
+ * 重置轮询器状态
171
+ *
172
+ * @description
173
+ * 将轮询器重置到初始状态(重试次数归零,间隔重置)。
174
+ * 不会停止正在运行的轮询。
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * poller.reset();
179
+ * ```
180
+ */
181
+ reset(): void;
182
+ /**
183
+ * 获取当前状态信息
184
+ *
185
+ * @returns 包含当前状态的对象
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * const status = poller.getStatus();
190
+ * console.log(`Running: ${status.isRunning}, Retry: ${status.retryCount}`);
191
+ * ```
192
+ */
193
+ getStatus(): {
194
+ isRunning: boolean;
195
+ isExecuting: boolean;
196
+ retryCount: number;
197
+ currentInterval: number;
198
+ };
199
+ }
200
+
201
+ export { Poller as P };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 跨模块共享类型
3
+ *
4
+ * @description
5
+ * 这些类型会被多个模块复用(例如 VirtualAccount 与 RBAC),放在 shared 里避免循环依赖与重复定义。
6
+ */
7
+ /**
8
+ * 角色类型
9
+ */
10
+ type RoleType = 'SYSTEM' | 'CUSTOM';
11
+ /**
12
+ * 数据范围类型
13
+ */
14
+ type ScopeType = 'TEAM' | 'SELF' | 'CUSTOM';
15
+ /**
16
+ * 角色分配参数(用于创建虚拟账号预置角色、以及成员角色分配)
17
+ */
18
+ interface AssignRoleParams {
19
+ /** 角色类型 */
20
+ roleType: RoleType;
21
+ /** 系统角色代码(roleType=SYSTEM时使用) */
22
+ roleCode?: string;
23
+ /** 自定义角色ID(roleType=CUSTOM时使用) */
24
+ roleId?: string;
25
+ /** 数据范围类型 */
26
+ scopeType: ScopeType;
27
+ /** 数据范围值(scopeType=CUSTOM时使用) */
28
+ scopeValue?: Record<string, unknown>;
29
+ }
30
+
31
+ export type { AssignRoleParams as A, RoleType as R, ScopeType as S };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 跨模块共享类型
3
+ *
4
+ * @description
5
+ * 这些类型会被多个模块复用(例如 VirtualAccount 与 RBAC),放在 shared 里避免循环依赖与重复定义。
6
+ */
7
+ /**
8
+ * 角色类型
9
+ */
10
+ type RoleType = 'SYSTEM' | 'CUSTOM';
11
+ /**
12
+ * 数据范围类型
13
+ */
14
+ type ScopeType = 'TEAM' | 'SELF' | 'CUSTOM';
15
+ /**
16
+ * 角色分配参数(用于创建虚拟账号预置角色、以及成员角色分配)
17
+ */
18
+ interface AssignRoleParams {
19
+ /** 角色类型 */
20
+ roleType: RoleType;
21
+ /** 系统角色代码(roleType=SYSTEM时使用) */
22
+ roleCode?: string;
23
+ /** 自定义角色ID(roleType=CUSTOM时使用) */
24
+ roleId?: string;
25
+ /** 数据范围类型 */
26
+ scopeType: ScopeType;
27
+ /** 数据范围值(scopeType=CUSTOM时使用) */
28
+ scopeValue?: Record<string, unknown>;
29
+ }
30
+
31
+ export type { AssignRoleParams as A, RoleType as R, ScopeType as S };
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@plolink/sdk",
3
+ "version": "0.0.4",
4
+ "description": "Plolink 开放平台官方 SDK",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "sideEffects": false,
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js",
17
+ "require": "./dist/index.cjs"
18
+ },
19
+ "./billing": {
20
+ "types": "./dist/modules/billing/index.d.ts",
21
+ "import": "./dist/modules/billing/index.js",
22
+ "require": "./dist/modules/billing/index.cjs"
23
+ },
24
+ "./agent": {
25
+ "types": "./dist/modules/agent/index.d.ts",
26
+ "import": "./dist/modules/agent/index.js",
27
+ "require": "./dist/modules/agent/index.cjs"
28
+ },
29
+ "./psych": {
30
+ "types": "./dist/modules/psych/index.d.ts",
31
+ "import": "./dist/modules/psych/index.js",
32
+ "require": "./dist/modules/psych/index.cjs"
33
+ },
34
+ "./chat": {
35
+ "types": "./dist/modules/chat/index.d.ts",
36
+ "import": "./dist/modules/chat/index.js",
37
+ "require": "./dist/modules/chat/index.cjs"
38
+ },
39
+ "./virtual-account": {
40
+ "types": "./dist/modules/virtual-account/index.d.ts",
41
+ "import": "./dist/modules/virtual-account/index.js",
42
+ "require": "./dist/modules/virtual-account/index.cjs"
43
+ },
44
+ "./rbac": {
45
+ "types": "./dist/modules/rbac/index.d.ts",
46
+ "import": "./dist/modules/rbac/index.js",
47
+ "require": "./dist/modules/rbac/index.cjs"
48
+ },
49
+ "./team": {
50
+ "types": "./dist/modules/team/index.d.ts",
51
+ "import": "./dist/modules/team/index.js",
52
+ "require": "./dist/modules/team/index.cjs"
53
+ },
54
+ "./common": {
55
+ "types": "./dist/common/index.d.ts",
56
+ "import": "./dist/common/index.js",
57
+ "require": "./dist/common/index.cjs"
58
+ }
59
+ },
60
+ "scripts": {
61
+ "dev": "tsup --watch",
62
+ "build": "tsup",
63
+ "lint": "eslint src --ext .ts",
64
+ "test": "jest --coverage --testPathIgnorePatterns tests/integration",
65
+ "test:integration": "PLOLINK_JEST_DISABLE_COVERAGE_THRESHOLD=true jest --coverage tests/integration",
66
+ "test:watch": "jest --watch",
67
+ "docs": "typedoc",
68
+ "typecheck": "tsc --noEmit"
69
+ },
70
+ "keywords": [
71
+ "plolink",
72
+ "sdk",
73
+ "api-client"
74
+ ],
75
+ "author": "Plolink Team",
76
+ "license": "MIT",
77
+ "peerDependencies": {
78
+ "axios": "^1.0.0"
79
+ },
80
+ "devDependencies": {
81
+ "@types/jest": "^29.5.12",
82
+ "@types/node": "^20.11.19",
83
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
84
+ "@typescript-eslint/parser": "^7.0.0",
85
+ "axios": "^1.9.0",
86
+ "axios-mock-adapter": "^1.22.0",
87
+ "eslint": "^8.56.0",
88
+ "jest": "^29.7.0",
89
+ "ts-jest": "^29.1.2",
90
+ "tslib": "^2.8.1",
91
+ "tsup": "^8.0.2",
92
+ "typedoc": "^0.25.8",
93
+ "typedoc-plugin-markdown": "^3.17.1",
94
+ "typescript": "^5.3.3"
95
+ }
96
+ }