@scorehub/auth-sdk 1.2.0 → 1.4.0
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 +47 -0
- package/dist/auth-client.d.ts +17 -0
- package/dist/auth-client.js +45 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -259,6 +259,53 @@ const user = await authClient.adminCreateUser({
|
|
|
259
259
|
await authClient.adminResetPassword('user-uuid', 'NewPassword123');
|
|
260
260
|
```
|
|
261
261
|
|
|
262
|
+
### 设置用户状态
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
// 将用户状态设为 DISABLED(禁用)
|
|
266
|
+
await authClient.setUserStatus('user-uuid', 'DISABLED');
|
|
267
|
+
|
|
268
|
+
// 将用户状态恢复为 ACTIVE(启用)
|
|
269
|
+
await authClient.setUserStatus('user-uuid', 'ACTIVE');
|
|
270
|
+
|
|
271
|
+
// 将用户状态设为 DELETED(软删除)
|
|
272
|
+
await authClient.setUserStatus('user-uuid', 'DELETED');
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
> 状态枚举:`ACTIVE`(正常)、`DISABLED`(禁用)、`DELETED`(已删除)。
|
|
276
|
+
> 使用 service token 鉴权,适合后台管理系统调用。
|
|
277
|
+
|
|
278
|
+
### 删除用户(软删除)
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
await authClient.deleteUser('user-uuid');
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
> 软删除:将用户状态设为 `DELETED`,保留数据用于审计,不物理删除。等效于 `setUserStatus(userId, 'DELETED')`。
|
|
285
|
+
|
|
286
|
+
### 管理端修改用户信息
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
// 修改用户名
|
|
290
|
+
await authClient.adminUpdateUser('user-uuid', { username: 'new_username' });
|
|
291
|
+
|
|
292
|
+
// 修改手机号
|
|
293
|
+
await authClient.adminUpdateUser('user-uuid', { mobile: '13900139001' });
|
|
294
|
+
|
|
295
|
+
// 修改真实姓名
|
|
296
|
+
await authClient.adminUpdateUser('user-uuid', { realname: '张三' });
|
|
297
|
+
|
|
298
|
+
// 同时修改多个字段
|
|
299
|
+
await authClient.adminUpdateUser('user-uuid', {
|
|
300
|
+
username: 'new_username',
|
|
301
|
+
mobile: '13900139001',
|
|
302
|
+
realname: '张三',
|
|
303
|
+
});
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
> 使用 service token 鉴权,无需短信验证码,适合后台管理系统调用。
|
|
307
|
+
> `username` 和 `mobile` 唯一,冲突时抛出 409 错误(`err.authCode` 对应业务错误码)。
|
|
308
|
+
|
|
262
309
|
---
|
|
263
310
|
|
|
264
311
|
## 框架中间件
|
package/dist/auth-client.d.ts
CHANGED
|
@@ -155,4 +155,21 @@ export declare class AuthClient {
|
|
|
155
155
|
* 发送短信验证码
|
|
156
156
|
*/
|
|
157
157
|
sendSmsCode(mobile: string, type?: number): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* 更新用户状态 (service token 鉴权)
|
|
160
|
+
*/
|
|
161
|
+
setUserStatus(userId: string, status: 'ACTIVE' | 'DISABLED' | 'DELETED'): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* 软删除用户 (将状态设为 DELETED,保留数据用于审计)
|
|
164
|
+
*/
|
|
165
|
+
deleteUser(userId: string): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* 管理端修改用户信息 (service token 鉴权,无需短信验证码)
|
|
168
|
+
* 支持修改 username、mobile、realname,字段均可选
|
|
169
|
+
*/
|
|
170
|
+
adminUpdateUser(userId: string, data: {
|
|
171
|
+
username?: string;
|
|
172
|
+
mobile?: string;
|
|
173
|
+
realname?: string;
|
|
174
|
+
}): Promise<void>;
|
|
158
175
|
}
|
package/dist/auth-client.js
CHANGED
|
@@ -308,5 +308,50 @@ class AuthClient {
|
|
|
308
308
|
throw err;
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* 更新用户状态 (service token 鉴权)
|
|
313
|
+
*/
|
|
314
|
+
async setUserStatus(userId, status) {
|
|
315
|
+
const token = await this.getServiceToken();
|
|
316
|
+
const response = await fetch(`${this.serviceUrl}/users/${userId}/status`, {
|
|
317
|
+
method: 'PATCH',
|
|
318
|
+
headers: {
|
|
319
|
+
'Content-Type': 'application/json',
|
|
320
|
+
Authorization: `Bearer ${token}`,
|
|
321
|
+
},
|
|
322
|
+
body: JSON.stringify({ status }),
|
|
323
|
+
});
|
|
324
|
+
if (!response.ok) {
|
|
325
|
+
const result = await response.json();
|
|
326
|
+
const err = new Error(result.message || 'Set user status failed');
|
|
327
|
+
err.authCode = result.code;
|
|
328
|
+
throw err;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* 软删除用户 (将状态设为 DELETED,保留数据用于审计)
|
|
333
|
+
*/
|
|
334
|
+
async deleteUser(userId) {
|
|
335
|
+
return this.setUserStatus(userId, 'DELETED');
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* 管理端修改用户信息 (service token 鉴权,无需短信验证码)
|
|
339
|
+
* 支持修改 username、mobile、realname,字段均可选
|
|
340
|
+
*/
|
|
341
|
+
async adminUpdateUser(userId, data) {
|
|
342
|
+
var _a;
|
|
343
|
+
const token = await this.getServiceToken();
|
|
344
|
+
const response = await fetch(`${this.serviceUrl}/users/${userId}/profile`, {
|
|
345
|
+
method: 'PATCH',
|
|
346
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
|
347
|
+
body: JSON.stringify(data),
|
|
348
|
+
});
|
|
349
|
+
if (!response.ok) {
|
|
350
|
+
const body = await response.json().catch(() => ({}));
|
|
351
|
+
const err = new Error((_a = body.message) !== null && _a !== void 0 ? _a : '修改用户信息失败');
|
|
352
|
+
err.authCode = body.code;
|
|
353
|
+
throw err;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
311
356
|
}
|
|
312
357
|
exports.AuthClient = AuthClient;
|