@h-ai/iam 0.1.0-alpha7 → 0.1.0-alpha9
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/dist/index.d.ts +2 -3
- package/dist/index.js +38 -28
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -331,7 +331,6 @@ interface ApiKeyOperations {
|
|
|
331
331
|
/**
|
|
332
332
|
* @h-ai/iam — 授权子功能类型定义(RBAC)
|
|
333
333
|
*
|
|
334
|
-
* @h-ai/iam — 授权子功能类型定义(RBAC)
|
|
335
334
|
* @module iam-authz-types
|
|
336
335
|
*/
|
|
337
336
|
|
|
@@ -1250,7 +1249,7 @@ declare const HaiIamError: {
|
|
|
1250
1249
|
readonly PASSWORD_EXPIRED: _h_ai_core.HaiErrorDef;
|
|
1251
1250
|
readonly PASSWORD_POLICY_VIOLATION: _h_ai_core.HaiErrorDef;
|
|
1252
1251
|
readonly OTP_INVALID: _h_ai_core.HaiErrorDef;
|
|
1253
|
-
readonly
|
|
1252
|
+
readonly NOT_INITIALIZED: _h_ai_core.HaiErrorDef;
|
|
1254
1253
|
readonly OTP_RESEND_TOO_FAST: _h_ai_core.HaiErrorDef;
|
|
1255
1254
|
readonly LOGIN_DISABLED: _h_ai_core.HaiErrorDef;
|
|
1256
1255
|
readonly REGISTER_DISABLED: _h_ai_core.HaiErrorDef;
|
|
@@ -1262,6 +1261,7 @@ declare const HaiIamError: {
|
|
|
1262
1261
|
readonly RESET_TOKEN_INVALID: _h_ai_core.HaiErrorDef;
|
|
1263
1262
|
readonly RESET_TOKEN_EXPIRED: _h_ai_core.HaiErrorDef;
|
|
1264
1263
|
readonly RESET_TOKEN_MAX_ATTEMPTS: _h_ai_core.HaiErrorDef;
|
|
1264
|
+
readonly OTP_EXPIRED: _h_ai_core.HaiErrorDef;
|
|
1265
1265
|
readonly SESSION_NOT_FOUND: _h_ai_core.HaiErrorDef;
|
|
1266
1266
|
readonly SESSION_EXPIRED: _h_ai_core.HaiErrorDef;
|
|
1267
1267
|
readonly SESSION_INVALID: _h_ai_core.HaiErrorDef;
|
|
@@ -1283,7 +1283,6 @@ declare const HaiIamError: {
|
|
|
1283
1283
|
readonly FORBIDDEN: _h_ai_core.HaiErrorDef;
|
|
1284
1284
|
readonly INVALID_ARGUMENT: _h_ai_core.HaiErrorDef;
|
|
1285
1285
|
readonly CONFIG_ERROR: _h_ai_core.HaiErrorDef;
|
|
1286
|
-
readonly NOT_INITIALIZED: _h_ai_core.HaiErrorDef;
|
|
1287
1286
|
readonly INTERNAL_ERROR: _h_ai_core.HaiErrorDef;
|
|
1288
1287
|
};
|
|
1289
1288
|
/**
|
package/dist/index.js
CHANGED
|
@@ -540,7 +540,7 @@ var IamErrorInfo = {
|
|
|
540
540
|
PASSWORD_EXPIRED: "007:401",
|
|
541
541
|
PASSWORD_POLICY_VIOLATION: "008:400",
|
|
542
542
|
OTP_INVALID: "009:400",
|
|
543
|
-
|
|
543
|
+
NOT_INITIALIZED: "010:500",
|
|
544
544
|
OTP_RESEND_TOO_FAST: "011:429",
|
|
545
545
|
LOGIN_DISABLED: "012:400",
|
|
546
546
|
REGISTER_DISABLED: "013:403",
|
|
@@ -552,6 +552,7 @@ var IamErrorInfo = {
|
|
|
552
552
|
RESET_TOKEN_INVALID: "019:400",
|
|
553
553
|
RESET_TOKEN_EXPIRED: "020:400",
|
|
554
554
|
RESET_TOKEN_MAX_ATTEMPTS: "021:429",
|
|
555
|
+
OTP_EXPIRED: "022:400",
|
|
555
556
|
SESSION_NOT_FOUND: "101:401",
|
|
556
557
|
SESSION_EXPIRED: "102:401",
|
|
557
558
|
SESSION_INVALID: "103:401",
|
|
@@ -573,7 +574,6 @@ var IamErrorInfo = {
|
|
|
573
574
|
FORBIDDEN: "501:403",
|
|
574
575
|
INVALID_ARGUMENT: "502:400",
|
|
575
576
|
CONFIG_ERROR: "901:500",
|
|
576
|
-
NOT_INITIALIZED: "910:500",
|
|
577
577
|
INTERNAL_ERROR: "999:500"
|
|
578
578
|
};
|
|
579
579
|
var HaiIamError = core.error.buildHaiErrorsDef("iam", IamErrorInfo);
|
|
@@ -3048,9 +3048,9 @@ function createRbacManager(config) {
|
|
|
3048
3048
|
if (ownTx) {
|
|
3049
3049
|
const affectedUsersResult = await userRoleRepository.getUserIdsByRoleId(roleId);
|
|
3050
3050
|
if (affectedUsersResult.success) {
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3051
|
+
await Promise.allSettled(
|
|
3052
|
+
affectedUsersResult.data.map((userId) => syncUserSessionAfterRoleChange(userId))
|
|
3053
|
+
);
|
|
3054
3054
|
} else {
|
|
3055
3055
|
logger6.error("Failed to query affected users after updateRole", { roleId, error: affectedUsersResult.error.message });
|
|
3056
3056
|
}
|
|
@@ -3123,9 +3123,9 @@ function createRbacManager(config) {
|
|
|
3123
3123
|
);
|
|
3124
3124
|
}
|
|
3125
3125
|
if (ownTx) {
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3126
|
+
await Promise.allSettled(
|
|
3127
|
+
affectedUserIds.map((userId) => syncUserSessionAfterRoleChange(userId))
|
|
3128
|
+
);
|
|
3129
3129
|
}
|
|
3130
3130
|
superAdminRoleId = void 0;
|
|
3131
3131
|
logger6.info("Role deleted", { roleId });
|
|
@@ -3275,9 +3275,9 @@ function createRbacManager(config) {
|
|
|
3275
3275
|
);
|
|
3276
3276
|
}
|
|
3277
3277
|
if (ownTx) {
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3278
|
+
await Promise.allSettled(
|
|
3279
|
+
affectedRoleIds.map((roleId) => syncSessionPermissionsForRole(roleId))
|
|
3280
|
+
);
|
|
3281
3281
|
}
|
|
3282
3282
|
logger6.info("Permission deleted", { permissionId });
|
|
3283
3283
|
void audit.helper.crud({ action: "delete", resource: "iam_permission", resourceId: permissionId });
|
|
@@ -3668,28 +3668,38 @@ function createCacheSessionRepository(sessionMaxAge, refreshTokenMaxAge) {
|
|
|
3668
3668
|
tokensResult.error
|
|
3669
3669
|
);
|
|
3670
3670
|
}
|
|
3671
|
+
const tokens = tokensResult.data;
|
|
3672
|
+
const readResults = await Promise.allSettled(
|
|
3673
|
+
tokens.map(async (token) => {
|
|
3674
|
+
const sessionKey = buildTokenKey(token);
|
|
3675
|
+
const [sessionResult, ttlResult] = await Promise.all([
|
|
3676
|
+
cache.kv.get(sessionKey),
|
|
3677
|
+
cache.kv.ttl(sessionKey)
|
|
3678
|
+
]);
|
|
3679
|
+
return { token, sessionKey, sessionResult, ttlResult };
|
|
3680
|
+
})
|
|
3681
|
+
);
|
|
3671
3682
|
const staleTokens = [];
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
if (!sessionResult.success || !sessionResult.data) {
|
|
3676
|
-
staleTokens.push(token);
|
|
3683
|
+
const writeOps = [];
|
|
3684
|
+
for (const entry of readResults) {
|
|
3685
|
+
if (entry.status === "rejected")
|
|
3677
3686
|
continue;
|
|
3678
|
-
}
|
|
3679
|
-
|
|
3680
|
-
if (!ttlResult.success || ttlResult.data <= 0) {
|
|
3687
|
+
const { token, sessionKey, sessionResult, ttlResult } = entry.value;
|
|
3688
|
+
if (!sessionResult.success || !sessionResult.data || !ttlResult.success || ttlResult.data <= 0) {
|
|
3681
3689
|
staleTokens.push(token);
|
|
3682
3690
|
continue;
|
|
3683
3691
|
}
|
|
3684
3692
|
const updated = { ...sessionResult.data, ...updates };
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
+
writeOps.push(cache.kv.set(sessionKey, updated, { ex: ttlResult.data }));
|
|
3694
|
+
}
|
|
3695
|
+
const writeResults = await Promise.allSettled(writeOps);
|
|
3696
|
+
const failedWrite = writeResults.find((r) => r.status === "fulfilled" && !r.value.success);
|
|
3697
|
+
if (failedWrite) {
|
|
3698
|
+
const failedResult = failedWrite.value;
|
|
3699
|
+
return err(
|
|
3700
|
+
HaiIamError.REPOSITORY_ERROR,
|
|
3701
|
+
iamM("iam_saveUserSessionCacheFailed", { params: { message: failedResult.error.message } })
|
|
3702
|
+
);
|
|
3693
3703
|
}
|
|
3694
3704
|
if (staleTokens.length > 0) {
|
|
3695
3705
|
await cache.set_.srem(buildUserTokensKey(userId), ...staleTokens);
|
|
@@ -4499,7 +4509,7 @@ function buildPasswordResetOps(ctx) {
|
|
|
4499
4509
|
return ok(void 0);
|
|
4500
4510
|
}
|
|
4501
4511
|
const user = toUser(userResult.data);
|
|
4502
|
-
const token =
|
|
4512
|
+
const token = generateToken();
|
|
4503
4513
|
const expiresAt = new Date(Date.now() + resetConfig.tokenExpiresIn * 1e3);
|
|
4504
4514
|
const saveResult = await resetTokenRepository.saveToken(token, user.id, expiresAt);
|
|
4505
4515
|
if (!saveResult.success) {
|