@h-ai/iam 0.1.0-alpha.40 → 0.1.0-alpha.42
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 +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -375,7 +375,14 @@ await iam.user.updateCurrentUser(accessToken, { displayName: '新名称' })
|
|
|
375
375
|
await iam.user.changeCurrentUserPassword(accessToken, 'oldPass', 'newPass')
|
|
376
376
|
|
|
377
377
|
// 管理操作
|
|
378
|
-
const users = await iam.user.listUsers({
|
|
378
|
+
const users = await iam.user.listUsers({
|
|
379
|
+
page: 1,
|
|
380
|
+
pageSize: 20,
|
|
381
|
+
search: 'alice',
|
|
382
|
+
sortBy: 'createdAt',
|
|
383
|
+
sortDirection: 'desc',
|
|
384
|
+
include: ['roles'],
|
|
385
|
+
})
|
|
379
386
|
await iam.user.updateUser(userId, { enabled: false }) // 禁用用户 → 自动清除会话
|
|
380
387
|
await iam.user.deleteUser(userId) // 删除用户 → 事务清除角色关联
|
|
381
388
|
|
|
@@ -395,6 +402,7 @@ const valid = iam.user.validatePassword('weak')
|
|
|
395
402
|
- **防枚举攻击**:`requestPasswordReset` 对不存在的邮箱返回 `ok(undefined)` 而非错误
|
|
396
403
|
- **validatePassword 是同步方法**:这是 `UserOperations` 中唯一的同步方法,其余均为异步
|
|
397
404
|
- **搜索模糊匹配**:`listUsers` 支持按用户名、邮箱、手机号、显示名称模糊搜索,LIKE 通配符已转义
|
|
405
|
+
- **服务端排序**:`listUsers` 仅允许 `username`、`email`、`displayName`、`enabled`、`createdAt` 排序;字段经白名单映射,未指定时默认按创建时间倒序
|
|
398
406
|
|
|
399
407
|
---
|
|
400
408
|
|
package/dist/index.d.ts
CHANGED
|
@@ -601,6 +601,10 @@ interface AuthzOperations {
|
|
|
601
601
|
* @module iam-user-types
|
|
602
602
|
*/
|
|
603
603
|
|
|
604
|
+
/** 用户列表允许的服务端排序字段。 */
|
|
605
|
+
type UserSortField = 'username' | 'email' | 'displayName' | 'enabled' | 'createdAt';
|
|
606
|
+
/** 用户列表排序方向。 */
|
|
607
|
+
type UserSortDirection = 'asc' | 'desc';
|
|
604
608
|
/**
|
|
605
609
|
* 用户列表查询选项
|
|
606
610
|
*/
|
|
@@ -609,6 +613,10 @@ interface ListUsersOptions extends PaginationOptionsInput {
|
|
|
609
613
|
search?: string;
|
|
610
614
|
/** 按启用状态过滤,不传则返回全部 */
|
|
611
615
|
enabled?: boolean;
|
|
616
|
+
/** 服务端排序字段;未指定时保持按创建时间倒序的历史行为。 */
|
|
617
|
+
sortBy?: UserSortField;
|
|
618
|
+
/** 服务端排序方向;仅在指定 sortBy 时生效,默认 desc。 */
|
|
619
|
+
sortDirection?: UserSortDirection;
|
|
612
620
|
/** 包含关联数据(如 'roles' 表示同时返回用户角色列表) */
|
|
613
621
|
include?: ('roles')[];
|
|
614
622
|
}
|
|
@@ -1489,4 +1497,4 @@ interface IamFunctions {
|
|
|
1489
1497
|
|
|
1490
1498
|
declare const iam: IamFunctions;
|
|
1491
1499
|
|
|
1492
|
-
export { type AgreementConfig, AgreementConfigSchema, type AgreementDisplay, type ApiKey, type ApiKeyConfig, ApiKeyConfigSchema, type ApiKeyCredentials, type ApiKeyOperations, type AuthResult, type AuthStrategy, type AuthStrategyType, AuthStrategyTypeSchema, type AuthnOperations, type AuthzOperations, type ConsumeTicketOptions, type ConsumedTicket, type CreateApiKeyOptions, type CreateApiKeyResult, type CreateSessionOptions, type Credentials, HaiIamError, type IamConfig, type IamConfigInput, IamConfigSchema, type IamConfigSettingsInput, type IamFunctions, type IssueTicketOptions, type IssuedTicket, type LdapClientFactory, type LdapConfig, LdapConfigSchema, type LdapCredentials, type ListUsersOptions, type LoginConfig, LoginConfigSchema, type OtpConfig, OtpConfigSchema, type OtpCredentials, type PasswordConfig, PasswordConfigSchema, type PasswordCredentials, type PasswordResetConfig, PasswordResetConfigSchema, type Permission, type PermissionQueryOptions, type PermissionType, type RbacConfig, RbacConfigSchema, type RegisterConfig, RegisterConfigSchema, type RegisterOptions, type RegisterResult, type Role, type SecurityConfig, SecurityConfigSchema, type Session, type SessionConfig, SessionConfigSchema, type SessionData, type SessionFieldUpdates, type SessionOperations, type StoredUser, type TicketGrant, type TicketOperations, type TokenPair, type UpdateCurrentUserInput, type User, type UserOperations, iam };
|
|
1500
|
+
export { type AgreementConfig, AgreementConfigSchema, type AgreementDisplay, type ApiKey, type ApiKeyConfig, ApiKeyConfigSchema, type ApiKeyCredentials, type ApiKeyOperations, type AuthResult, type AuthStrategy, type AuthStrategyType, AuthStrategyTypeSchema, type AuthnOperations, type AuthzOperations, type ConsumeTicketOptions, type ConsumedTicket, type CreateApiKeyOptions, type CreateApiKeyResult, type CreateSessionOptions, type Credentials, HaiIamError, type IamConfig, type IamConfigInput, IamConfigSchema, type IamConfigSettingsInput, type IamFunctions, type IssueTicketOptions, type IssuedTicket, type LdapClientFactory, type LdapConfig, LdapConfigSchema, type LdapCredentials, type ListUsersOptions, type LoginConfig, LoginConfigSchema, type OtpConfig, OtpConfigSchema, type OtpCredentials, type PasswordConfig, PasswordConfigSchema, type PasswordCredentials, type PasswordResetConfig, PasswordResetConfigSchema, type Permission, type PermissionQueryOptions, type PermissionType, type RbacConfig, RbacConfigSchema, type RegisterConfig, RegisterConfigSchema, type RegisterOptions, type RegisterResult, type Role, type SecurityConfig, SecurityConfigSchema, type Session, type SessionConfig, SessionConfigSchema, type SessionData, type SessionFieldUpdates, type SessionOperations, type StoredUser, type TicketGrant, type TicketOperations, type TokenPair, type UpdateCurrentUserInput, type User, type UserOperations, type UserSortDirection, type UserSortField, iam };
|
package/dist/index.js
CHANGED
|
@@ -4247,6 +4247,18 @@ function createCacheResetTokenRepository() {
|
|
|
4247
4247
|
|
|
4248
4248
|
// src/user/iam-user-functions.ts
|
|
4249
4249
|
var logger10 = core.logger.child({ module: "iam", scope: "user" });
|
|
4250
|
+
var USER_SORT_COLUMNS = {
|
|
4251
|
+
/** 用户名列。 */
|
|
4252
|
+
username: "username",
|
|
4253
|
+
/** 邮箱列。 */
|
|
4254
|
+
email: "email",
|
|
4255
|
+
/** 用户显示名称列。 */
|
|
4256
|
+
displayName: "display_name",
|
|
4257
|
+
/** 账号启用状态列。 */
|
|
4258
|
+
enabled: "enabled",
|
|
4259
|
+
/** 用户创建时间列。 */
|
|
4260
|
+
createdAt: "created_at"
|
|
4261
|
+
};
|
|
4250
4262
|
async function createUserOperations(deps) {
|
|
4251
4263
|
try {
|
|
4252
4264
|
const { config, passwordStrategyResult, sessionFunctions, authzFunctions, onPasswordResetRequest } = deps;
|
|
@@ -4472,10 +4484,12 @@ function buildUserQueryOps(ctx) {
|
|
|
4472
4484
|
params.push(options.enabled ? 1 : 0);
|
|
4473
4485
|
}
|
|
4474
4486
|
const where = conditions.length > 0 ? conditions.join(" AND ") : void 0;
|
|
4487
|
+
const sortColumn = options?.sortBy ? USER_SORT_COLUMNS[options.sortBy] : USER_SORT_COLUMNS.createdAt;
|
|
4488
|
+
const sortDirection = options?.sortBy && options.sortDirection === "asc" ? "ASC" : "DESC";
|
|
4475
4489
|
const usersResult = await userRepository.findPage({
|
|
4476
4490
|
where,
|
|
4477
4491
|
params: params.length > 0 ? params : void 0,
|
|
4478
|
-
orderBy:
|
|
4492
|
+
orderBy: `${sortColumn} ${sortDirection}`,
|
|
4479
4493
|
pagination: options ? { page: options.page, pageSize: options.pageSize } : void 0
|
|
4480
4494
|
});
|
|
4481
4495
|
if (!usersResult.success) {
|