@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.
- package/README.md +259 -0
- package/dist/chunk-4H4RACSE.js +335 -0
- package/dist/chunk-4H4RACSE.js.map +1 -0
- package/dist/chunk-IHAAKFEJ.js +219 -0
- package/dist/chunk-IHAAKFEJ.js.map +1 -0
- package/dist/chunk-JR4HYYQI.cjs +221 -0
- package/dist/chunk-JR4HYYQI.cjs.map +1 -0
- package/dist/chunk-MD4O7FWT.js +46 -0
- package/dist/chunk-MD4O7FWT.js.map +1 -0
- package/dist/chunk-NS3DJP2O.cjs +349 -0
- package/dist/chunk-NS3DJP2O.cjs.map +1 -0
- package/dist/chunk-Y3UJVC2L.cjs +48 -0
- package/dist/chunk-Y3UJVC2L.cjs.map +1 -0
- package/dist/client-CAjIQKPm.d.cts +193 -0
- package/dist/client-CwNikk7i.d.ts +193 -0
- package/dist/common/index.cjs +65 -0
- package/dist/common/index.cjs.map +1 -0
- package/dist/common/index.d.cts +422 -0
- package/dist/common/index.d.ts +422 -0
- package/dist/common/index.js +4 -0
- package/dist/common/index.js.map +1 -0
- package/dist/core-77EbLgbp.d.cts +97 -0
- package/dist/core-77EbLgbp.d.ts +97 -0
- package/dist/index.cjs +350 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +98 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.js +306 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/agent/index.cjs +21 -0
- package/dist/modules/agent/index.cjs.map +1 -0
- package/dist/modules/agent/index.d.cts +71 -0
- package/dist/modules/agent/index.d.ts +71 -0
- package/dist/modules/agent/index.js +19 -0
- package/dist/modules/agent/index.js.map +1 -0
- package/dist/modules/billing/index.cjs +413 -0
- package/dist/modules/billing/index.cjs.map +1 -0
- package/dist/modules/billing/index.d.cts +538 -0
- package/dist/modules/billing/index.d.ts +538 -0
- package/dist/modules/billing/index.js +411 -0
- package/dist/modules/billing/index.js.map +1 -0
- package/dist/modules/chat/index.cjs +20 -0
- package/dist/modules/chat/index.cjs.map +1 -0
- package/dist/modules/chat/index.d.cts +68 -0
- package/dist/modules/chat/index.d.ts +68 -0
- package/dist/modules/chat/index.js +18 -0
- package/dist/modules/chat/index.js.map +1 -0
- package/dist/modules/psych/index.cjs +20 -0
- package/dist/modules/psych/index.cjs.map +1 -0
- package/dist/modules/psych/index.d.cts +69 -0
- package/dist/modules/psych/index.d.ts +69 -0
- package/dist/modules/psych/index.js +18 -0
- package/dist/modules/psych/index.js.map +1 -0
- package/dist/modules/rbac/index.cjs +197 -0
- package/dist/modules/rbac/index.cjs.map +1 -0
- package/dist/modules/rbac/index.d.cts +293 -0
- package/dist/modules/rbac/index.d.ts +293 -0
- package/dist/modules/rbac/index.js +195 -0
- package/dist/modules/rbac/index.js.map +1 -0
- package/dist/modules/team/index.cjs +54 -0
- package/dist/modules/team/index.cjs.map +1 -0
- package/dist/modules/team/index.d.cts +91 -0
- package/dist/modules/team/index.d.ts +91 -0
- package/dist/modules/team/index.js +52 -0
- package/dist/modules/team/index.js.map +1 -0
- package/dist/modules/virtual-account/index.cjs +293 -0
- package/dist/modules/virtual-account/index.cjs.map +1 -0
- package/dist/modules/virtual-account/index.d.cts +366 -0
- package/dist/modules/virtual-account/index.d.ts +366 -0
- package/dist/modules/virtual-account/index.js +291 -0
- package/dist/modules/virtual-account/index.js.map +1 -0
- package/dist/poller-BlIRbwL4.d.cts +201 -0
- package/dist/poller-DWKZjuSw.d.ts +201 -0
- package/dist/shared-6ZepUSPW.d.cts +31 -0
- package/dist/shared-6ZepUSPW.d.ts +31 -0
- package/package.json +96 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkY3UJVC2L_cjs = require('../../chunk-Y3UJVC2L.cjs');
|
|
4
|
+
|
|
5
|
+
// src/modules/virtual-account/index.ts
|
|
6
|
+
var VirtualAccount = class {
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 创建虚拟账号
|
|
12
|
+
*
|
|
13
|
+
* @description
|
|
14
|
+
* 支持两种模式:
|
|
15
|
+
* - EXISTING_TEAM: 绑定到已有团队(需要是团队管理员)
|
|
16
|
+
* - NEW_TEAM: 创建新团队(当前用户成为团队管理员)
|
|
17
|
+
*
|
|
18
|
+
* 支持预置多个角色,每个角色可以有不同的数据范围配置
|
|
19
|
+
*
|
|
20
|
+
* @param params - 创建参数
|
|
21
|
+
* @returns 创建结果,包含虚拟账号信息和初始 API Key(明文)
|
|
22
|
+
* @throws {PlolinkError} 当参数无效、权限不足或创建失败时抛出
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // 绑定已有团队模式
|
|
27
|
+
* const result = await virtualAccount.createVirtualAccount({
|
|
28
|
+
* mode: 'EXISTING_TEAM',
|
|
29
|
+
* teamId: 'team-123',
|
|
30
|
+
* virtualAccountName: 'API Service',
|
|
31
|
+
* apiKeyName: 'production',
|
|
32
|
+
* presetRoles: [
|
|
33
|
+
* {
|
|
34
|
+
* roleType: 'SYSTEM',
|
|
35
|
+
* roleCode: 'TEAM_MEMBER',
|
|
36
|
+
* scopeType: 'TEAM'
|
|
37
|
+
* },
|
|
38
|
+
* {
|
|
39
|
+
* roleType: 'CUSTOM',
|
|
40
|
+
* roleId: 'role-456',
|
|
41
|
+
* scopeType: 'CUSTOM',
|
|
42
|
+
* scopeValue: { talent: { companyIds: ['company-1', 'company-2'] } }
|
|
43
|
+
* }
|
|
44
|
+
* ]
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // 创建新团队模式
|
|
48
|
+
* const result = await virtualAccount.createVirtualAccount({
|
|
49
|
+
* mode: 'NEW_TEAM',
|
|
50
|
+
* teamName: 'My API Team',
|
|
51
|
+
* virtualAccountName: 'Bot Account'
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* console.log(`虚拟账号 ID: ${result.virtualAccount.id}`);
|
|
55
|
+
* console.log(`API Key: ${result.apiKey.apiKey}`);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
async createVirtualAccount(params) {
|
|
59
|
+
if (params.mode === "EXISTING_TEAM" && !params.teamId) {
|
|
60
|
+
throw new chunkY3UJVC2L_cjs.PlolinkError(
|
|
61
|
+
"teamId is required when mode is EXISTING_TEAM",
|
|
62
|
+
"INVALID_PARAMS"
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return this.client.axiosInstance.post("/api/v1/virtual-accounts", params);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 列出虚拟账号
|
|
69
|
+
*
|
|
70
|
+
* @description
|
|
71
|
+
* 列出当前团队下的所有虚拟账号,支持关键词搜索。
|
|
72
|
+
* 结果按创建时间倒序排列。
|
|
73
|
+
*
|
|
74
|
+
* @param keyword - 可选的搜索关键词(按名称模糊匹配)
|
|
75
|
+
* @returns 虚拟账号列表
|
|
76
|
+
* @throws {PlolinkError} 当请求失败或权限不足时抛出
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // 获取所有虚拟账号
|
|
81
|
+
* const accounts = await virtualAccount.listVirtualAccounts();
|
|
82
|
+
* accounts.forEach(acc => {
|
|
83
|
+
* console.log(`${acc.name} (ID: ${acc.id})`);
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* // 搜索特定名称的虚拟账号
|
|
87
|
+
* const filtered = await virtualAccount.listVirtualAccounts('API');
|
|
88
|
+
* console.log(`找到 ${filtered.length} 个包含 "API" 的虚拟账号`);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
async listVirtualAccounts(keyword) {
|
|
92
|
+
const params = keyword ? { keyword } : void 0;
|
|
93
|
+
return this.client.axiosInstance.get("/api/v1/virtual-accounts", { params });
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 获取虚拟账号详情
|
|
97
|
+
*
|
|
98
|
+
* @param virtualAccountId - 虚拟账号 ID
|
|
99
|
+
* @returns 虚拟账号详细信息
|
|
100
|
+
* @throws {PlolinkError} 当虚拟账号不存在、不属于当前团队或权限不足时抛出
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const detail = await virtualAccount.getVirtualAccountDetail('va-123');
|
|
105
|
+
* console.log(`名称: ${detail.name}`);
|
|
106
|
+
* console.log(`创建者: ${detail.virtualAccountCreatorId}`);
|
|
107
|
+
* console.log(`所属团队: ${detail.virtualAccountTeamId}`);
|
|
108
|
+
* console.log(`创建时间: ${new Date(detail.createdAt * 1000).toLocaleString()}`);
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
async getVirtualAccountDetail(virtualAccountId) {
|
|
112
|
+
if (!virtualAccountId) {
|
|
113
|
+
throw new chunkY3UJVC2L_cjs.PlolinkError("virtualAccountId is required", "INVALID_PARAMS");
|
|
114
|
+
}
|
|
115
|
+
return this.client.axiosInstance.get(`/api/v1/virtual-accounts/${virtualAccountId}`);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 列出虚拟账号的 API Keys(明文)
|
|
119
|
+
*
|
|
120
|
+
* @description
|
|
121
|
+
* 获取指定虚拟账号的所有 API Key,包含明文密钥。
|
|
122
|
+
* 此操作会被记录审计日志。
|
|
123
|
+
*
|
|
124
|
+
* ⚠️ 安全提示: API Key 为敏感信息,请谨慎处理和存储
|
|
125
|
+
*
|
|
126
|
+
* @param virtualAccountId - 虚拟账号 ID
|
|
127
|
+
* @returns API Key 列表(包含明文)
|
|
128
|
+
* @throws {PlolinkError} 当虚拟账号不存在、不属于当前团队或权限不足时抛出
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const keys = await virtualAccount.listVirtualAccountApiKeys('va-123');
|
|
133
|
+
* keys.forEach(key => {
|
|
134
|
+
* console.log(`名称: ${key.name}`);
|
|
135
|
+
* console.log(`密钥: ${key.apiKey}`);
|
|
136
|
+
* console.log(`最后使用: ${key.lastUsage ? new Date(key.lastUsage * 1000).toLocaleString() : '从未使用'}`);
|
|
137
|
+
* });
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
async listVirtualAccountApiKeys(virtualAccountId) {
|
|
141
|
+
if (!virtualAccountId) {
|
|
142
|
+
throw new chunkY3UJVC2L_cjs.PlolinkError("virtualAccountId is required", "INVALID_PARAMS");
|
|
143
|
+
}
|
|
144
|
+
return this.client.axiosInstance.get(
|
|
145
|
+
`/api/v1/virtual-accounts/${virtualAccountId}/api-keys`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 为虚拟账号创建新的 API Key
|
|
150
|
+
*
|
|
151
|
+
* @description
|
|
152
|
+
* 为指定虚拟账号创建新的 API Key。
|
|
153
|
+
* 返回的密钥为明文,建议立即保存到安全位置。
|
|
154
|
+
*
|
|
155
|
+
* ⚠️ 安全提示:
|
|
156
|
+
* - API Key 创建后可随时查看明文,但请妥善保管
|
|
157
|
+
* - 建议为不同用途创建不同的 API Key,便于管理和吊销
|
|
158
|
+
*
|
|
159
|
+
* @param virtualAccountId - 虚拟账号 ID
|
|
160
|
+
* @param params - 创建参数
|
|
161
|
+
* @returns 创建的 API Key 信息(包含明文密钥)
|
|
162
|
+
* @throws {PlolinkError} 当参数无效、权限不足或创建失败时抛出
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const newKey = await virtualAccount.createVirtualAccountApiKey('va-123', {
|
|
167
|
+
* name: 'Production API Key'
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* console.log(`API Key ID: ${newKey.id}`);
|
|
171
|
+
* console.log(`API Key: ${newKey.apiKey}`);
|
|
172
|
+
* // 请妥善保存此密钥
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
async createVirtualAccountApiKey(virtualAccountId, params) {
|
|
176
|
+
if (!virtualAccountId) {
|
|
177
|
+
throw new chunkY3UJVC2L_cjs.PlolinkError("virtualAccountId is required", "INVALID_PARAMS");
|
|
178
|
+
}
|
|
179
|
+
if (!params.name || params.name.trim().length === 0) {
|
|
180
|
+
throw new chunkY3UJVC2L_cjs.PlolinkError("name is required and cannot be empty", "INVALID_PARAMS");
|
|
181
|
+
}
|
|
182
|
+
return this.client.axiosInstance.post(
|
|
183
|
+
`/api/v1/virtual-accounts/${virtualAccountId}/api-keys`,
|
|
184
|
+
params
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* 编辑虚拟账号 API Key(仅改名)
|
|
189
|
+
*
|
|
190
|
+
* @description
|
|
191
|
+
* 修改 API Key 的名称,不影响密钥本身。
|
|
192
|
+
* 用于更好地识别和管理 API Key。
|
|
193
|
+
*
|
|
194
|
+
* @param virtualAccountId - 虚拟账号 ID
|
|
195
|
+
* @param params - 更新参数
|
|
196
|
+
* @throws {PlolinkError} 当参数无效、API Key 不存在或权限不足时抛出
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* await virtualAccount.updateVirtualAccountApiKey('va-123', {
|
|
201
|
+
* apiKeyId: 'key-456',
|
|
202
|
+
* name: 'Production API Key (v2)'
|
|
203
|
+
* });
|
|
204
|
+
* console.log('API Key 名称已更新');
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
async updateVirtualAccountApiKey(virtualAccountId, params) {
|
|
208
|
+
if (!virtualAccountId) {
|
|
209
|
+
throw new chunkY3UJVC2L_cjs.PlolinkError("virtualAccountId is required", "INVALID_PARAMS");
|
|
210
|
+
}
|
|
211
|
+
if (!params.apiKeyId) {
|
|
212
|
+
throw new chunkY3UJVC2L_cjs.PlolinkError("apiKeyId is required", "INVALID_PARAMS");
|
|
213
|
+
}
|
|
214
|
+
if (!params.name || params.name.trim().length === 0) {
|
|
215
|
+
throw new chunkY3UJVC2L_cjs.PlolinkError("name is required and cannot be empty", "INVALID_PARAMS");
|
|
216
|
+
}
|
|
217
|
+
await this.client.axiosInstance.post(
|
|
218
|
+
`/api/v1/virtual-accounts/${virtualAccountId}/api-keys/edit`,
|
|
219
|
+
params
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* 删除虚拟账号 API Key
|
|
224
|
+
*
|
|
225
|
+
* @description
|
|
226
|
+
* 永久删除指定的 API Key,此操作不可恢复。
|
|
227
|
+
* 删除后使用该密钥的请求将立即失效。
|
|
228
|
+
*
|
|
229
|
+
* ⚠️ 警告: 此操作不可逆,请确认后再执行
|
|
230
|
+
*
|
|
231
|
+
* @param virtualAccountId - 虚拟账号 ID
|
|
232
|
+
* @param apiKeyId - API Key ID
|
|
233
|
+
* @throws {PlolinkError} 当参数无效、API Key 不存在或权限不足时抛出
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* await virtualAccount.deleteVirtualAccountApiKey('va-123', 'key-456');
|
|
238
|
+
* console.log('API Key 已删除');
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
async deleteVirtualAccountApiKey(virtualAccountId, apiKeyId) {
|
|
242
|
+
if (!virtualAccountId) {
|
|
243
|
+
throw new chunkY3UJVC2L_cjs.PlolinkError("virtualAccountId is required", "INVALID_PARAMS");
|
|
244
|
+
}
|
|
245
|
+
if (!apiKeyId) {
|
|
246
|
+
throw new chunkY3UJVC2L_cjs.PlolinkError("apiKeyId is required", "INVALID_PARAMS");
|
|
247
|
+
}
|
|
248
|
+
await this.client.axiosInstance.post(
|
|
249
|
+
`/api/v1/virtual-accounts/${virtualAccountId}/api-keys/delete`,
|
|
250
|
+
{ apiKeyId }
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* 删除虚拟账号
|
|
255
|
+
*
|
|
256
|
+
* @description
|
|
257
|
+
* 永久删除指定的虚拟账号,包括其所有关联的 API Keys、团队成员关系和角色分配。
|
|
258
|
+
* 此操作不可恢复。
|
|
259
|
+
*
|
|
260
|
+
* 删除后将会清理:
|
|
261
|
+
* - 虚拟账号用户(User)
|
|
262
|
+
* - 所有 API Keys(UserApiKey)
|
|
263
|
+
* - 团队成员关系(TeamMember)
|
|
264
|
+
* - 成员角色(MemberRole)
|
|
265
|
+
*
|
|
266
|
+
* 注意:虚拟账号所属的团队不会被删除。
|
|
267
|
+
*
|
|
268
|
+
* ⚠️ 警告:
|
|
269
|
+
* - 此操作不可逆,请确认后再执行
|
|
270
|
+
* - 删除后该虚拟账号的所有 API Keys 将立即失效
|
|
271
|
+
*
|
|
272
|
+
* @param virtualAccountId - 虚拟账号 ID
|
|
273
|
+
* @throws {PlolinkError} 当参数无效、虚拟账号不存在或权限不足时抛出
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* await virtualAccount.deleteVirtualAccount('va-123');
|
|
278
|
+
* console.log('虚拟账号已删除');
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
async deleteVirtualAccount(virtualAccountId) {
|
|
282
|
+
if (!virtualAccountId) {
|
|
283
|
+
throw new chunkY3UJVC2L_cjs.PlolinkError("virtualAccountId is required", "INVALID_PARAMS");
|
|
284
|
+
}
|
|
285
|
+
await this.client.axiosInstance.post(
|
|
286
|
+
`/api/v1/virtual-accounts/${virtualAccountId}/delete`
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
exports.VirtualAccount = VirtualAccount;
|
|
292
|
+
//# sourceMappingURL=index.cjs.map
|
|
293
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/modules/virtual-account/index.ts"],"names":["PlolinkError"],"mappings":";;;;;AAuEO,IAAM,iBAAN,MAAqB;AAAA,EAG1B,YA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A,MAC5C,EAAE,QAAA;AAAS,KACb;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA8BA,MAAa,qBAAqB,gBAAA,EAAyC;AACzE,IAAA,IAAI,CAAC,gBAAA,EAAkB;AACrB,MAAA,MAAM,IAAIA,8BAAA,CAAa,8BAAA,EAAgC,gBAAgB,CAAA;AAAA,IACzE;AAEA,IAAA,MAAM,IAAA,CAAK,OAAO,aAAA,CAAc,IAAA;AAAA,MAC9B,4BAA4B,gBAAgB,CAAA,OAAA;AAAA,KAC9C;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["/**\n * 虚拟账号管理模块\n * \n * @description\n * 提供完整的虚拟账号管理功能,包括:\n * - 虚拟账号创建(支持绑定已有团队或创建新团队)\n * - 虚拟账号列表查询(支持关键词搜索)\n * - 虚拟账号详情查询\n * - API Key 管理(列表/创建/编辑/删除)\n * - 支持多角色预置\n * \n * @example\n * ```typescript\n * import { PlolinkClient } from '@plolink/sdk';\n * import { VirtualAccount } from '@plolink/sdk/virtual-account';\n * \n * const client = new PlolinkClient({\n * token: 'your-session-id-or-api-key'\n * });\n * \n * const virtualAccount = new VirtualAccount(client);\n * \n * // 创建虚拟账号(绑定已有团队)\n * const result = await virtualAccount.createVirtualAccount({\n * mode: 'EXISTING_TEAM',\n * teamId: 'team-123',\n * virtualAccountName: 'API Service Account',\n * presetRoles: [{\n * roleType: 'SYSTEM',\n * roleCode: 'TEAM_MEMBER',\n * scopeType: 'TEAM'\n * }]\n * });\n * console.log(`虚拟账号创建成功: ${result.virtualAccount.name}`);\n * console.log(`API Key: ${result.apiKey.apiKey}`);\n * \n * // 列出虚拟账号\n * const accounts = await virtualAccount.listVirtualAccounts();\n * console.log(`共 ${accounts.length} 个虚拟账号`);\n * ```\n * \n * @module virtual-account\n */\n\nimport { PlolinkClient } from '../../core/client';\nimport { PlolinkError } from '../../core/error';\nimport type {\n CreateVirtualAccountParams,\n CreateVirtualAccountResponse,\n VirtualAccountListItem,\n VirtualAccountInfo,\n VirtualAccountApiKeyItem,\n CreateVirtualAccountApiKeyParams,\n UpdateVirtualAccountApiKeyParams,\n} from '../../types/virtual-account';\n\nexport type {\n CreateVirtualAccountParams,\n CreateVirtualAccountResponse,\n VirtualAccountListItem,\n VirtualAccountInfo,\n VirtualAccountApiKeyItem,\n CreateVirtualAccountApiKeyParams,\n UpdateVirtualAccountApiKeyParams,\n} from '../../types/virtual-account';\n\nexport type { AssignRoleParams } from '../../types/shared';\n\n/**\n * 虚拟账号管理模块\n */\nexport class VirtualAccount {\n private client: PlolinkClient;\n\n constructor(client: PlolinkClient) {\n this.client = client;\n }\n\n /**\n * 创建虚拟账号\n * \n * @description\n * 支持两种模式:\n * - EXISTING_TEAM: 绑定到已有团队(需要是团队管理员)\n * - NEW_TEAM: 创建新团队(当前用户成为团队管理员)\n * \n * 支持预置多个角色,每个角色可以有不同的数据范围配置\n * \n * @param params - 创建参数\n * @returns 创建结果,包含虚拟账号信息和初始 API Key(明文)\n * @throws {PlolinkError} 当参数无效、权限不足或创建失败时抛出\n * \n * @example\n * ```typescript\n * // 绑定已有团队模式\n * const result = await virtualAccount.createVirtualAccount({\n * mode: 'EXISTING_TEAM',\n * teamId: 'team-123',\n * virtualAccountName: 'API Service',\n * apiKeyName: 'production',\n * presetRoles: [\n * {\n * roleType: 'SYSTEM',\n * roleCode: 'TEAM_MEMBER',\n * scopeType: 'TEAM'\n * },\n * {\n * roleType: 'CUSTOM',\n * roleId: 'role-456',\n * scopeType: 'CUSTOM',\n * scopeValue: { talent: { companyIds: ['company-1', 'company-2'] } }\n * }\n * ]\n * });\n * \n * // 创建新团队模式\n * const result = await virtualAccount.createVirtualAccount({\n * mode: 'NEW_TEAM',\n * teamName: 'My API Team',\n * virtualAccountName: 'Bot Account'\n * });\n * \n * console.log(`虚拟账号 ID: ${result.virtualAccount.id}`);\n * console.log(`API Key: ${result.apiKey.apiKey}`);\n * ```\n */\n public async createVirtualAccount(\n params: CreateVirtualAccountParams\n ): Promise<CreateVirtualAccountResponse> {\n // 参数验证\n if (params.mode === 'EXISTING_TEAM' && !params.teamId) {\n throw new PlolinkError(\n 'teamId is required when mode is EXISTING_TEAM',\n 'INVALID_PARAMS'\n );\n }\n\n return this.client.axiosInstance.post('/api/v1/virtual-accounts', params);\n }\n\n /**\n * 列出虚拟账号\n * \n * @description\n * 列出当前团队下的所有虚拟账号,支持关键词搜索。\n * 结果按创建时间倒序排列。\n * \n * @param keyword - 可选的搜索关键词(按名称模糊匹配)\n * @returns 虚拟账号列表\n * @throws {PlolinkError} 当请求失败或权限不足时抛出\n * \n * @example\n * ```typescript\n * // 获取所有虚拟账号\n * const accounts = await virtualAccount.listVirtualAccounts();\n * accounts.forEach(acc => {\n * console.log(`${acc.name} (ID: ${acc.id})`);\n * });\n * \n * // 搜索特定名称的虚拟账号\n * const filtered = await virtualAccount.listVirtualAccounts('API');\n * console.log(`找到 ${filtered.length} 个包含 \"API\" 的虚拟账号`);\n * ```\n */\n public async listVirtualAccounts(keyword?: string): Promise<VirtualAccountListItem[]> {\n const params = keyword ? { keyword } : undefined;\n return this.client.axiosInstance.get('/api/v1/virtual-accounts', { params });\n }\n\n /**\n * 获取虚拟账号详情\n * \n * @param virtualAccountId - 虚拟账号 ID\n * @returns 虚拟账号详细信息\n * @throws {PlolinkError} 当虚拟账号不存在、不属于当前团队或权限不足时抛出\n * \n * @example\n * ```typescript\n * const detail = await virtualAccount.getVirtualAccountDetail('va-123');\n * console.log(`名称: ${detail.name}`);\n * console.log(`创建者: ${detail.virtualAccountCreatorId}`);\n * console.log(`所属团队: ${detail.virtualAccountTeamId}`);\n * console.log(`创建时间: ${new Date(detail.createdAt * 1000).toLocaleString()}`);\n * ```\n */\n public async getVirtualAccountDetail(virtualAccountId: string): Promise<VirtualAccountInfo> {\n if (!virtualAccountId) {\n throw new PlolinkError('virtualAccountId is required', 'INVALID_PARAMS');\n }\n\n return this.client.axiosInstance.get(`/api/v1/virtual-accounts/${virtualAccountId}`);\n }\n\n /**\n * 列出虚拟账号的 API Keys(明文)\n * \n * @description\n * 获取指定虚拟账号的所有 API Key,包含明文密钥。\n * 此操作会被记录审计日志。\n * \n * ⚠️ 安全提示: API Key 为敏感信息,请谨慎处理和存储\n * \n * @param virtualAccountId - 虚拟账号 ID\n * @returns API Key 列表(包含明文)\n * @throws {PlolinkError} 当虚拟账号不存在、不属于当前团队或权限不足时抛出\n * \n * @example\n * ```typescript\n * const keys = await virtualAccount.listVirtualAccountApiKeys('va-123');\n * keys.forEach(key => {\n * console.log(`名称: ${key.name}`);\n * console.log(`密钥: ${key.apiKey}`);\n * console.log(`最后使用: ${key.lastUsage ? new Date(key.lastUsage * 1000).toLocaleString() : '从未使用'}`);\n * });\n * ```\n */\n public async listVirtualAccountApiKeys(\n virtualAccountId: string\n ): Promise<VirtualAccountApiKeyItem[]> {\n if (!virtualAccountId) {\n throw new PlolinkError('virtualAccountId is required', 'INVALID_PARAMS');\n }\n\n return this.client.axiosInstance.get(\n `/api/v1/virtual-accounts/${virtualAccountId}/api-keys`\n );\n }\n\n /**\n * 为虚拟账号创建新的 API Key\n * \n * @description\n * 为指定虚拟账号创建新的 API Key。\n * 返回的密钥为明文,建议立即保存到安全位置。\n * \n * ⚠️ 安全提示: \n * - API Key 创建后可随时查看明文,但请妥善保管\n * - 建议为不同用途创建不同的 API Key,便于管理和吊销\n * \n * @param virtualAccountId - 虚拟账号 ID\n * @param params - 创建参数\n * @returns 创建的 API Key 信息(包含明文密钥)\n * @throws {PlolinkError} 当参数无效、权限不足或创建失败时抛出\n * \n * @example\n * ```typescript\n * const newKey = await virtualAccount.createVirtualAccountApiKey('va-123', {\n * name: 'Production API Key'\n * });\n * \n * console.log(`API Key ID: ${newKey.id}`);\n * console.log(`API Key: ${newKey.apiKey}`);\n * // 请妥善保存此密钥\n * ```\n */\n public async createVirtualAccountApiKey(\n virtualAccountId: string,\n params: CreateVirtualAccountApiKeyParams\n ): Promise<{ id: string; apiKey: string }> {\n if (!virtualAccountId) {\n throw new PlolinkError('virtualAccountId is required', 'INVALID_PARAMS');\n }\n\n if (!params.name || params.name.trim().length === 0) {\n throw new PlolinkError('name is required and cannot be empty', 'INVALID_PARAMS');\n }\n\n return this.client.axiosInstance.post(\n `/api/v1/virtual-accounts/${virtualAccountId}/api-keys`,\n params\n );\n }\n\n /**\n * 编辑虚拟账号 API Key(仅改名)\n * \n * @description\n * 修改 API Key 的名称,不影响密钥本身。\n * 用于更好地识别和管理 API Key。\n * \n * @param virtualAccountId - 虚拟账号 ID\n * @param params - 更新参数\n * @throws {PlolinkError} 当参数无效、API Key 不存在或权限不足时抛出\n * \n * @example\n * ```typescript\n * await virtualAccount.updateVirtualAccountApiKey('va-123', {\n * apiKeyId: 'key-456',\n * name: 'Production API Key (v2)'\n * });\n * console.log('API Key 名称已更新');\n * ```\n */\n public async updateVirtualAccountApiKey(\n virtualAccountId: string,\n params: UpdateVirtualAccountApiKeyParams\n ): Promise<void> {\n if (!virtualAccountId) {\n throw new PlolinkError('virtualAccountId is required', 'INVALID_PARAMS');\n }\n\n if (!params.apiKeyId) {\n throw new PlolinkError('apiKeyId is required', 'INVALID_PARAMS');\n }\n\n if (!params.name || params.name.trim().length === 0) {\n throw new PlolinkError('name is required and cannot be empty', 'INVALID_PARAMS');\n }\n\n await this.client.axiosInstance.post(\n `/api/v1/virtual-accounts/${virtualAccountId}/api-keys/edit`,\n params\n );\n }\n\n /**\n * 删除虚拟账号 API Key\n * \n * @description\n * 永久删除指定的 API Key,此操作不可恢复。\n * 删除后使用该密钥的请求将立即失效。\n * \n * ⚠️ 警告: 此操作不可逆,请确认后再执行\n * \n * @param virtualAccountId - 虚拟账号 ID\n * @param apiKeyId - API Key ID\n * @throws {PlolinkError} 当参数无效、API Key 不存在或权限不足时抛出\n * \n * @example\n * ```typescript\n * await virtualAccount.deleteVirtualAccountApiKey('va-123', 'key-456');\n * console.log('API Key 已删除');\n * ```\n */\n public async deleteVirtualAccountApiKey(\n virtualAccountId: string,\n apiKeyId: string\n ): Promise<void> {\n if (!virtualAccountId) {\n throw new PlolinkError('virtualAccountId is required', 'INVALID_PARAMS');\n }\n\n if (!apiKeyId) {\n throw new PlolinkError('apiKeyId is required', 'INVALID_PARAMS');\n }\n\n await this.client.axiosInstance.post(\n `/api/v1/virtual-accounts/${virtualAccountId}/api-keys/delete`,\n { apiKeyId }\n );\n }\n\n /**\n * 删除虚拟账号\n * \n * @description\n * 永久删除指定的虚拟账号,包括其所有关联的 API Keys、团队成员关系和角色分配。\n * 此操作不可恢复。\n * \n * 删除后将会清理:\n * - 虚拟账号用户(User)\n * - 所有 API Keys(UserApiKey)\n * - 团队成员关系(TeamMember)\n * - 成员角色(MemberRole)\n * \n * 注意:虚拟账号所属的团队不会被删除。\n * \n * ⚠️ 警告: \n * - 此操作不可逆,请确认后再执行\n * - 删除后该虚拟账号的所有 API Keys 将立即失效\n * \n * @param virtualAccountId - 虚拟账号 ID\n * @throws {PlolinkError} 当参数无效、虚拟账号不存在或权限不足时抛出\n * \n * @example\n * ```typescript\n * await virtualAccount.deleteVirtualAccount('va-123');\n * console.log('虚拟账号已删除');\n * ```\n */\n public async deleteVirtualAccount(virtualAccountId: string): Promise<void> {\n if (!virtualAccountId) {\n throw new PlolinkError('virtualAccountId is required', 'INVALID_PARAMS');\n }\n\n await this.client.axiosInstance.post(\n `/api/v1/virtual-accounts/${virtualAccountId}/delete`\n );\n }\n}\n\n"]}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { P as PlolinkClient } from '../../client-CAjIQKPm.cjs';
|
|
2
|
+
import { A as AssignRoleParams } from '../../shared-6ZepUSPW.cjs';
|
|
3
|
+
import '../../core-77EbLgbp.cjs';
|
|
4
|
+
import 'axios';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* VirtualAccount 模块类型
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 创建虚拟账号参数(绑定已有团队模式)
|
|
12
|
+
*/
|
|
13
|
+
interface CreateVirtualAccountWithExistingTeam {
|
|
14
|
+
mode: 'EXISTING_TEAM';
|
|
15
|
+
/** 团队ID */
|
|
16
|
+
teamId: string;
|
|
17
|
+
/** 虚拟账号名称(可选,不填自动生成) */
|
|
18
|
+
virtualAccountName?: string;
|
|
19
|
+
/** API Key 名称(可选,默认 'default') */
|
|
20
|
+
apiKeyName?: string;
|
|
21
|
+
/** 预置角色列表(支持多个) */
|
|
22
|
+
presetRoles?: AssignRoleParams[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 创建虚拟账号参数(创建新团队模式)
|
|
26
|
+
*/
|
|
27
|
+
interface CreateVirtualAccountWithNewTeam {
|
|
28
|
+
mode: 'NEW_TEAM';
|
|
29
|
+
/** 新团队名称(可选,不填自动生成) */
|
|
30
|
+
teamName?: string;
|
|
31
|
+
/** 虚拟账号名称(可选,不填自动生成) */
|
|
32
|
+
virtualAccountName?: string;
|
|
33
|
+
/** API Key 名称(可选,默认 'default') */
|
|
34
|
+
apiKeyName?: string;
|
|
35
|
+
/** 预置角色列表(支持多个) */
|
|
36
|
+
presetRoles?: AssignRoleParams[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 创建虚拟账号参数(联合类型)
|
|
40
|
+
*/
|
|
41
|
+
type CreateVirtualAccountParams = CreateVirtualAccountWithExistingTeam | CreateVirtualAccountWithNewTeam;
|
|
42
|
+
/**
|
|
43
|
+
* 虚拟账号信息
|
|
44
|
+
*/
|
|
45
|
+
interface VirtualAccountInfo {
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
isVirtualAccount: true;
|
|
49
|
+
virtualAccountCreatorId: string;
|
|
50
|
+
virtualAccountTeamId: string;
|
|
51
|
+
createdAt: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 创建虚拟账号响应
|
|
55
|
+
*/
|
|
56
|
+
interface CreateVirtualAccountResponse {
|
|
57
|
+
virtualAccount: VirtualAccountInfo;
|
|
58
|
+
apiKey: {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
apiKey: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 虚拟账号列表项
|
|
66
|
+
*/
|
|
67
|
+
interface VirtualAccountListItem {
|
|
68
|
+
id: string;
|
|
69
|
+
name: string;
|
|
70
|
+
virtualAccountCreatorId: string;
|
|
71
|
+
virtualAccountTeamId: string;
|
|
72
|
+
createdAt: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 虚拟账号 API Key 列表项
|
|
76
|
+
*/
|
|
77
|
+
interface VirtualAccountApiKeyItem {
|
|
78
|
+
id: string;
|
|
79
|
+
name: string;
|
|
80
|
+
apiKey: string;
|
|
81
|
+
createdAt: number;
|
|
82
|
+
lastUsage: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 创建虚拟账号 API Key 参数
|
|
86
|
+
*/
|
|
87
|
+
interface CreateVirtualAccountApiKeyParams {
|
|
88
|
+
name: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 更新虚拟账号 API Key 参数
|
|
92
|
+
*/
|
|
93
|
+
interface UpdateVirtualAccountApiKeyParams {
|
|
94
|
+
apiKeyId: string;
|
|
95
|
+
name: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 虚拟账号管理模块
|
|
100
|
+
*
|
|
101
|
+
* @description
|
|
102
|
+
* 提供完整的虚拟账号管理功能,包括:
|
|
103
|
+
* - 虚拟账号创建(支持绑定已有团队或创建新团队)
|
|
104
|
+
* - 虚拟账号列表查询(支持关键词搜索)
|
|
105
|
+
* - 虚拟账号详情查询
|
|
106
|
+
* - API Key 管理(列表/创建/编辑/删除)
|
|
107
|
+
* - 支持多角色预置
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* import { PlolinkClient } from '@plolink/sdk';
|
|
112
|
+
* import { VirtualAccount } from '@plolink/sdk/virtual-account';
|
|
113
|
+
*
|
|
114
|
+
* const client = new PlolinkClient({
|
|
115
|
+
* token: 'your-session-id-or-api-key'
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* const virtualAccount = new VirtualAccount(client);
|
|
119
|
+
*
|
|
120
|
+
* // 创建虚拟账号(绑定已有团队)
|
|
121
|
+
* const result = await virtualAccount.createVirtualAccount({
|
|
122
|
+
* mode: 'EXISTING_TEAM',
|
|
123
|
+
* teamId: 'team-123',
|
|
124
|
+
* virtualAccountName: 'API Service Account',
|
|
125
|
+
* presetRoles: [{
|
|
126
|
+
* roleType: 'SYSTEM',
|
|
127
|
+
* roleCode: 'TEAM_MEMBER',
|
|
128
|
+
* scopeType: 'TEAM'
|
|
129
|
+
* }]
|
|
130
|
+
* });
|
|
131
|
+
* console.log(`虚拟账号创建成功: ${result.virtualAccount.name}`);
|
|
132
|
+
* console.log(`API Key: ${result.apiKey.apiKey}`);
|
|
133
|
+
*
|
|
134
|
+
* // 列出虚拟账号
|
|
135
|
+
* const accounts = await virtualAccount.listVirtualAccounts();
|
|
136
|
+
* console.log(`共 ${accounts.length} 个虚拟账号`);
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @module virtual-account
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 虚拟账号管理模块
|
|
144
|
+
*/
|
|
145
|
+
declare class VirtualAccount {
|
|
146
|
+
private client;
|
|
147
|
+
constructor(client: PlolinkClient);
|
|
148
|
+
/**
|
|
149
|
+
* 创建虚拟账号
|
|
150
|
+
*
|
|
151
|
+
* @description
|
|
152
|
+
* 支持两种模式:
|
|
153
|
+
* - EXISTING_TEAM: 绑定到已有团队(需要是团队管理员)
|
|
154
|
+
* - NEW_TEAM: 创建新团队(当前用户成为团队管理员)
|
|
155
|
+
*
|
|
156
|
+
* 支持预置多个角色,每个角色可以有不同的数据范围配置
|
|
157
|
+
*
|
|
158
|
+
* @param params - 创建参数
|
|
159
|
+
* @returns 创建结果,包含虚拟账号信息和初始 API Key(明文)
|
|
160
|
+
* @throws {PlolinkError} 当参数无效、权限不足或创建失败时抛出
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // 绑定已有团队模式
|
|
165
|
+
* const result = await virtualAccount.createVirtualAccount({
|
|
166
|
+
* mode: 'EXISTING_TEAM',
|
|
167
|
+
* teamId: 'team-123',
|
|
168
|
+
* virtualAccountName: 'API Service',
|
|
169
|
+
* apiKeyName: 'production',
|
|
170
|
+
* presetRoles: [
|
|
171
|
+
* {
|
|
172
|
+
* roleType: 'SYSTEM',
|
|
173
|
+
* roleCode: 'TEAM_MEMBER',
|
|
174
|
+
* scopeType: 'TEAM'
|
|
175
|
+
* },
|
|
176
|
+
* {
|
|
177
|
+
* roleType: 'CUSTOM',
|
|
178
|
+
* roleId: 'role-456',
|
|
179
|
+
* scopeType: 'CUSTOM',
|
|
180
|
+
* scopeValue: { talent: { companyIds: ['company-1', 'company-2'] } }
|
|
181
|
+
* }
|
|
182
|
+
* ]
|
|
183
|
+
* });
|
|
184
|
+
*
|
|
185
|
+
* // 创建新团队模式
|
|
186
|
+
* const result = await virtualAccount.createVirtualAccount({
|
|
187
|
+
* mode: 'NEW_TEAM',
|
|
188
|
+
* teamName: 'My API Team',
|
|
189
|
+
* virtualAccountName: 'Bot Account'
|
|
190
|
+
* });
|
|
191
|
+
*
|
|
192
|
+
* console.log(`虚拟账号 ID: ${result.virtualAccount.id}`);
|
|
193
|
+
* console.log(`API Key: ${result.apiKey.apiKey}`);
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
createVirtualAccount(params: CreateVirtualAccountParams): Promise<CreateVirtualAccountResponse>;
|
|
197
|
+
/**
|
|
198
|
+
* 列出虚拟账号
|
|
199
|
+
*
|
|
200
|
+
* @description
|
|
201
|
+
* 列出当前团队下的所有虚拟账号,支持关键词搜索。
|
|
202
|
+
* 结果按创建时间倒序排列。
|
|
203
|
+
*
|
|
204
|
+
* @param keyword - 可选的搜索关键词(按名称模糊匹配)
|
|
205
|
+
* @returns 虚拟账号列表
|
|
206
|
+
* @throws {PlolinkError} 当请求失败或权限不足时抛出
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* // 获取所有虚拟账号
|
|
211
|
+
* const accounts = await virtualAccount.listVirtualAccounts();
|
|
212
|
+
* accounts.forEach(acc => {
|
|
213
|
+
* console.log(`${acc.name} (ID: ${acc.id})`);
|
|
214
|
+
* });
|
|
215
|
+
*
|
|
216
|
+
* // 搜索特定名称的虚拟账号
|
|
217
|
+
* const filtered = await virtualAccount.listVirtualAccounts('API');
|
|
218
|
+
* console.log(`找到 ${filtered.length} 个包含 "API" 的虚拟账号`);
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
listVirtualAccounts(keyword?: string): Promise<VirtualAccountListItem[]>;
|
|
222
|
+
/**
|
|
223
|
+
* 获取虚拟账号详情
|
|
224
|
+
*
|
|
225
|
+
* @param virtualAccountId - 虚拟账号 ID
|
|
226
|
+
* @returns 虚拟账号详细信息
|
|
227
|
+
* @throws {PlolinkError} 当虚拟账号不存在、不属于当前团队或权限不足时抛出
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const detail = await virtualAccount.getVirtualAccountDetail('va-123');
|
|
232
|
+
* console.log(`名称: ${detail.name}`);
|
|
233
|
+
* console.log(`创建者: ${detail.virtualAccountCreatorId}`);
|
|
234
|
+
* console.log(`所属团队: ${detail.virtualAccountTeamId}`);
|
|
235
|
+
* console.log(`创建时间: ${new Date(detail.createdAt * 1000).toLocaleString()}`);
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
getVirtualAccountDetail(virtualAccountId: string): Promise<VirtualAccountInfo>;
|
|
239
|
+
/**
|
|
240
|
+
* 列出虚拟账号的 API Keys(明文)
|
|
241
|
+
*
|
|
242
|
+
* @description
|
|
243
|
+
* 获取指定虚拟账号的所有 API Key,包含明文密钥。
|
|
244
|
+
* 此操作会被记录审计日志。
|
|
245
|
+
*
|
|
246
|
+
* ⚠️ 安全提示: API Key 为敏感信息,请谨慎处理和存储
|
|
247
|
+
*
|
|
248
|
+
* @param virtualAccountId - 虚拟账号 ID
|
|
249
|
+
* @returns API Key 列表(包含明文)
|
|
250
|
+
* @throws {PlolinkError} 当虚拟账号不存在、不属于当前团队或权限不足时抛出
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* const keys = await virtualAccount.listVirtualAccountApiKeys('va-123');
|
|
255
|
+
* keys.forEach(key => {
|
|
256
|
+
* console.log(`名称: ${key.name}`);
|
|
257
|
+
* console.log(`密钥: ${key.apiKey}`);
|
|
258
|
+
* console.log(`最后使用: ${key.lastUsage ? new Date(key.lastUsage * 1000).toLocaleString() : '从未使用'}`);
|
|
259
|
+
* });
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
listVirtualAccountApiKeys(virtualAccountId: string): Promise<VirtualAccountApiKeyItem[]>;
|
|
263
|
+
/**
|
|
264
|
+
* 为虚拟账号创建新的 API Key
|
|
265
|
+
*
|
|
266
|
+
* @description
|
|
267
|
+
* 为指定虚拟账号创建新的 API Key。
|
|
268
|
+
* 返回的密钥为明文,建议立即保存到安全位置。
|
|
269
|
+
*
|
|
270
|
+
* ⚠️ 安全提示:
|
|
271
|
+
* - API Key 创建后可随时查看明文,但请妥善保管
|
|
272
|
+
* - 建议为不同用途创建不同的 API Key,便于管理和吊销
|
|
273
|
+
*
|
|
274
|
+
* @param virtualAccountId - 虚拟账号 ID
|
|
275
|
+
* @param params - 创建参数
|
|
276
|
+
* @returns 创建的 API Key 信息(包含明文密钥)
|
|
277
|
+
* @throws {PlolinkError} 当参数无效、权限不足或创建失败时抛出
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* const newKey = await virtualAccount.createVirtualAccountApiKey('va-123', {
|
|
282
|
+
* name: 'Production API Key'
|
|
283
|
+
* });
|
|
284
|
+
*
|
|
285
|
+
* console.log(`API Key ID: ${newKey.id}`);
|
|
286
|
+
* console.log(`API Key: ${newKey.apiKey}`);
|
|
287
|
+
* // 请妥善保存此密钥
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
createVirtualAccountApiKey(virtualAccountId: string, params: CreateVirtualAccountApiKeyParams): Promise<{
|
|
291
|
+
id: string;
|
|
292
|
+
apiKey: string;
|
|
293
|
+
}>;
|
|
294
|
+
/**
|
|
295
|
+
* 编辑虚拟账号 API Key(仅改名)
|
|
296
|
+
*
|
|
297
|
+
* @description
|
|
298
|
+
* 修改 API Key 的名称,不影响密钥本身。
|
|
299
|
+
* 用于更好地识别和管理 API Key。
|
|
300
|
+
*
|
|
301
|
+
* @param virtualAccountId - 虚拟账号 ID
|
|
302
|
+
* @param params - 更新参数
|
|
303
|
+
* @throws {PlolinkError} 当参数无效、API Key 不存在或权限不足时抛出
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```typescript
|
|
307
|
+
* await virtualAccount.updateVirtualAccountApiKey('va-123', {
|
|
308
|
+
* apiKeyId: 'key-456',
|
|
309
|
+
* name: 'Production API Key (v2)'
|
|
310
|
+
* });
|
|
311
|
+
* console.log('API Key 名称已更新');
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
updateVirtualAccountApiKey(virtualAccountId: string, params: UpdateVirtualAccountApiKeyParams): Promise<void>;
|
|
315
|
+
/**
|
|
316
|
+
* 删除虚拟账号 API Key
|
|
317
|
+
*
|
|
318
|
+
* @description
|
|
319
|
+
* 永久删除指定的 API Key,此操作不可恢复。
|
|
320
|
+
* 删除后使用该密钥的请求将立即失效。
|
|
321
|
+
*
|
|
322
|
+
* ⚠️ 警告: 此操作不可逆,请确认后再执行
|
|
323
|
+
*
|
|
324
|
+
* @param virtualAccountId - 虚拟账号 ID
|
|
325
|
+
* @param apiKeyId - API Key ID
|
|
326
|
+
* @throws {PlolinkError} 当参数无效、API Key 不存在或权限不足时抛出
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* ```typescript
|
|
330
|
+
* await virtualAccount.deleteVirtualAccountApiKey('va-123', 'key-456');
|
|
331
|
+
* console.log('API Key 已删除');
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
deleteVirtualAccountApiKey(virtualAccountId: string, apiKeyId: string): Promise<void>;
|
|
335
|
+
/**
|
|
336
|
+
* 删除虚拟账号
|
|
337
|
+
*
|
|
338
|
+
* @description
|
|
339
|
+
* 永久删除指定的虚拟账号,包括其所有关联的 API Keys、团队成员关系和角色分配。
|
|
340
|
+
* 此操作不可恢复。
|
|
341
|
+
*
|
|
342
|
+
* 删除后将会清理:
|
|
343
|
+
* - 虚拟账号用户(User)
|
|
344
|
+
* - 所有 API Keys(UserApiKey)
|
|
345
|
+
* - 团队成员关系(TeamMember)
|
|
346
|
+
* - 成员角色(MemberRole)
|
|
347
|
+
*
|
|
348
|
+
* 注意:虚拟账号所属的团队不会被删除。
|
|
349
|
+
*
|
|
350
|
+
* ⚠️ 警告:
|
|
351
|
+
* - 此操作不可逆,请确认后再执行
|
|
352
|
+
* - 删除后该虚拟账号的所有 API Keys 将立即失效
|
|
353
|
+
*
|
|
354
|
+
* @param virtualAccountId - 虚拟账号 ID
|
|
355
|
+
* @throws {PlolinkError} 当参数无效、虚拟账号不存在或权限不足时抛出
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```typescript
|
|
359
|
+
* await virtualAccount.deleteVirtualAccount('va-123');
|
|
360
|
+
* console.log('虚拟账号已删除');
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
deleteVirtualAccount(virtualAccountId: string): Promise<void>;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export { AssignRoleParams, type CreateVirtualAccountApiKeyParams, type CreateVirtualAccountParams, type CreateVirtualAccountResponse, type UpdateVirtualAccountApiKeyParams, VirtualAccount, type VirtualAccountApiKeyItem, type VirtualAccountInfo, type VirtualAccountListItem };
|