@scorehub/auth-sdk 1.2.0 → 1.3.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 CHANGED
@@ -259,6 +259,30 @@ 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
+
262
286
  ---
263
287
 
264
288
  ## 框架中间件
@@ -155,4 +155,12 @@ 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>;
158
166
  }
@@ -308,5 +308,31 @@ 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
+ }
311
337
  }
312
338
  exports.AuthClient = AuthClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scorehub/auth-sdk",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Auth-Service SDK for Node.js applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",