najm-auth 1.1.42 → 1.1.44
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 +33 -2
- package/dist/index.js +44 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1050,6 +1050,19 @@ type UserIdInParam = z.infer<typeof userIdInParam>;
|
|
|
1050
1050
|
type AssignRoleParams = z.infer<typeof assignRoleParams>;
|
|
1051
1051
|
type UserListQuery = z.infer<typeof userListQuery>;
|
|
1052
1052
|
|
|
1053
|
+
/**
|
|
1054
|
+
* Identity fields for creating a user behind a person record (parent, student,
|
|
1055
|
+
* teacher, staff…). Role can be given by name (`role`) or id (`roleId`).
|
|
1056
|
+
*/
|
|
1057
|
+
type ProvisionUserInput = {
|
|
1058
|
+
id?: string;
|
|
1059
|
+
name?: string;
|
|
1060
|
+
email: string;
|
|
1061
|
+
role?: string;
|
|
1062
|
+
roleId?: string;
|
|
1063
|
+
image?: string | null;
|
|
1064
|
+
status?: 'active' | 'inactive' | 'pending';
|
|
1065
|
+
};
|
|
1053
1066
|
declare class AuthService {
|
|
1054
1067
|
private tokenService;
|
|
1055
1068
|
private userService;
|
|
@@ -1077,7 +1090,18 @@ declare class AuthService {
|
|
|
1077
1090
|
* Email is best-effort: a send failure logs a warning but never rolls back
|
|
1078
1091
|
* account creation (and with the console provider, nothing is actually sent).
|
|
1079
1092
|
*/
|
|
1080
|
-
inviteUser(body:
|
|
1093
|
+
inviteUser(body: ProvisionUserInput): Promise<SanitizedUser>;
|
|
1094
|
+
/**
|
|
1095
|
+
* Create a login for a person record. The branch is intentional and is the
|
|
1096
|
+
* single rule callers rely on:
|
|
1097
|
+
* - password provided → set it directly, NO email (seeding / imports)
|
|
1098
|
+
* - no password → random password + emailed set-password invite
|
|
1099
|
+
*
|
|
1100
|
+
* Returns the created (sanitized) user so the caller can link `userId`.
|
|
1101
|
+
*/
|
|
1102
|
+
provisionUser(body: ProvisionUserInput & {
|
|
1103
|
+
password?: string | null;
|
|
1104
|
+
}): Promise<SanitizedUser>;
|
|
1081
1105
|
loginUser(body: LoginDto): Promise<TokenPair & {
|
|
1082
1106
|
user: SanitizedUser;
|
|
1083
1107
|
}>;
|
|
@@ -1175,6 +1199,13 @@ declare class AuthResolver {
|
|
|
1175
1199
|
private container;
|
|
1176
1200
|
private app;
|
|
1177
1201
|
private log;
|
|
1202
|
+
/**
|
|
1203
|
+
* Missing/stale/invalid credentials (4xx) are an expected client state on
|
|
1204
|
+
* these resolve paths — e.g. a refresh cookie that outlived its DB row
|
|
1205
|
+
* after a reseed or rotation. Log those at debug; reserve warn for
|
|
1206
|
+
* unexpected (5xx/non-HTTP) failures.
|
|
1207
|
+
*/
|
|
1208
|
+
private logResolveMiss;
|
|
1178
1209
|
resolve(token: string): Promise<{
|
|
1179
1210
|
user: any;
|
|
1180
1211
|
role?: string;
|
|
@@ -2100,4 +2131,4 @@ declare const authSeed: (config: AuthSeedConfig) => Record<string, SeedEntry>;
|
|
|
2100
2131
|
*/
|
|
2101
2132
|
declare function seedAuthData(config: SeedAuthDataConfig): Promise<SeedAuthDataResult>;
|
|
2102
2133
|
|
|
2103
|
-
export { AUTH_CONFIG, en as AUTH_EN, AUTH_LOCALES, AUTH_MODULE, AUTH_PERMISSIONS, AUTH_ROLE, AUTH_SCHEMA, AUTH_SUPPORTED_LANGUAGES, AUTH_USER, type AssignPermissionDto, type AssignRoleDto, type AssignRoleParams, type AuthConfig, AuthController, AuthGuard, type AuthPluginConfig, AuthQueries, AuthResolver, type AuthSchema, type AuthSeedConfig, AuthService, type AuthUser, Can, CanCreate, CanDelete, CanList, CanRead, CanUpdate, type ChainableGuard, type ChangePasswordDto, type CheckPermissionDto, type ConfiguredOwnership, type ConfirmResetPasswordDto, CookieManager, type CreatePermissionDto, type CreateRoleDto, type CreateTokenDto, type CreateUserDto, type DefineRolesOptions, type EmailParam, EncryptionService, type InviteUserDto, type JwtConfig, type JwtPayload, type LanguageParam, type LoginDto, NewPermission, NewRoleEntity, NewUser, Owned, type OwnedMethods, type OwnershipConfig, type OwnershipProvider, type OwnershipRule, OwnershipToken, type OwnershipTokenOptions, Permission, PermissionController, PermissionGuard, type PermissionIdParam, PermissionRepository, PermissionService, PermissionValidator, Policy, ROLES, ROLE_GROUPS, type RefreshTokenDto, type ResetPasswordDto, type ResourceAccessor, type ResourceGuards, type ResourceGuardsOptions, type RevokeTokenDto, Role, RoleController, RoleEntity, RoleGuard, type RoleIdParam, type RoleInput, RolePermission, RoleRepository, RoleService, type RoleType, RoleValidator, type RunAsUser, type SanitizedUser, ScopeContext, type ScopeResult, type SeedAuthDataConfig, type SeedAuthDataResult, type SeedUserConfig, type SessionCookieData, TOKEN_STATUS, TOKEN_TYPE, type TokenIdParam, type TokenPair, TokenRepository, TokenService, USER_STATUS, type UpdatePermissionDto, type UpdateRoleDto, type UpdateTokenDto, type UpdateUserDto, User, UserController, type UserIdInParam, type UserIdParam, type UserListQuery, UserRepository, UserService, UserValidator, type UserWithPermissions, type VerifyTokenDto, assignPermissionDto, assignRoleDto, assignRoleParams, auth$1 as auth, authSeed, avatarsPath, calculateAge, calculateYearsOfExperience, changePasswordDto, checkPermissionDto, clean, configureOwnership, confirmResetPasswordDto, createPermissionDto, createRoleDto, createTokenDto, createUserDto, defineRoles, emailParam, formatDate, getAuthLocale, getAvatarFile, inviteUserDto, isAdmin, isAdministrator, isAuth, isEmpty, isFile, isPath, join, languageParam, loginDto, own, parseSchema, permissionIdParam, pickProps, refreshTokenDto, resetPasswordDto, revokeTokenDto, roleIdParam, runAsUser, seedAuthData, tokenIdParam, updatePermissionDto, updateRoleDto, updateTokenDto, updateUserDto, userIdInParam, userIdParam, userListQuery, verifyTokenDto, where };
|
|
2134
|
+
export { AUTH_CONFIG, en as AUTH_EN, AUTH_LOCALES, AUTH_MODULE, AUTH_PERMISSIONS, AUTH_ROLE, AUTH_SCHEMA, AUTH_SUPPORTED_LANGUAGES, AUTH_USER, type AssignPermissionDto, type AssignRoleDto, type AssignRoleParams, type AuthConfig, AuthController, AuthGuard, type AuthPluginConfig, AuthQueries, AuthResolver, type AuthSchema, type AuthSeedConfig, AuthService, type AuthUser, Can, CanCreate, CanDelete, CanList, CanRead, CanUpdate, type ChainableGuard, type ChangePasswordDto, type CheckPermissionDto, type ConfiguredOwnership, type ConfirmResetPasswordDto, CookieManager, type CreatePermissionDto, type CreateRoleDto, type CreateTokenDto, type CreateUserDto, type DefineRolesOptions, type EmailParam, EncryptionService, type InviteUserDto, type JwtConfig, type JwtPayload, type LanguageParam, type LoginDto, NewPermission, NewRoleEntity, NewUser, Owned, type OwnedMethods, type OwnershipConfig, type OwnershipProvider, type OwnershipRule, OwnershipToken, type OwnershipTokenOptions, Permission, PermissionController, PermissionGuard, type PermissionIdParam, PermissionRepository, PermissionService, PermissionValidator, Policy, type ProvisionUserInput, ROLES, ROLE_GROUPS, type RefreshTokenDto, type ResetPasswordDto, type ResourceAccessor, type ResourceGuards, type ResourceGuardsOptions, type RevokeTokenDto, Role, RoleController, RoleEntity, RoleGuard, type RoleIdParam, type RoleInput, RolePermission, RoleRepository, RoleService, type RoleType, RoleValidator, type RunAsUser, type SanitizedUser, ScopeContext, type ScopeResult, type SeedAuthDataConfig, type SeedAuthDataResult, type SeedUserConfig, type SessionCookieData, TOKEN_STATUS, TOKEN_TYPE, type TokenIdParam, type TokenPair, TokenRepository, TokenService, USER_STATUS, type UpdatePermissionDto, type UpdateRoleDto, type UpdateTokenDto, type UpdateUserDto, User, UserController, type UserIdInParam, type UserIdParam, type UserListQuery, UserRepository, UserService, UserValidator, type UserWithPermissions, type VerifyTokenDto, assignPermissionDto, assignRoleDto, assignRoleParams, auth$1 as auth, authSeed, avatarsPath, calculateAge, calculateYearsOfExperience, changePasswordDto, checkPermissionDto, clean, configureOwnership, confirmResetPasswordDto, createPermissionDto, createRoleDto, createTokenDto, createUserDto, defineRoles, emailParam, formatDate, getAuthLocale, getAvatarFile, inviteUserDto, isAdmin, isAdministrator, isAuth, isEmpty, isFile, isPath, join, languageParam, loginDto, own, parseSchema, permissionIdParam, pickProps, refreshTokenDto, resetPasswordDto, revokeTokenDto, roleIdParam, runAsUser, seedAuthData, tokenIdParam, updatePermissionDto, updateRoleDto, updateTokenDto, updateUserDto, userIdInParam, userIdParam, userListQuery, verifyTokenDto, where };
|
package/dist/index.js
CHANGED
|
@@ -2007,12 +2007,14 @@ var AuthService = class AuthService2 {
|
|
|
2007
2007
|
async inviteUser(body) {
|
|
2008
2008
|
const randomPassword = `${nanoid5(24)}Aa1!`;
|
|
2009
2009
|
const user = await this.userService.create({
|
|
2010
|
+
id: body.id,
|
|
2010
2011
|
name: body.name,
|
|
2011
2012
|
email: body.email,
|
|
2013
|
+
role: body.role,
|
|
2012
2014
|
roleId: body.roleId,
|
|
2013
2015
|
image: body.image,
|
|
2014
2016
|
password: randomPassword,
|
|
2015
|
-
status: "active",
|
|
2017
|
+
status: body.status ?? "active",
|
|
2016
2018
|
emailVerified: false
|
|
2017
2019
|
});
|
|
2018
2020
|
const { token } = await this.tokenService.generateInviteToken(user.id);
|
|
@@ -2027,6 +2029,30 @@ var AuthService = class AuthService2 {
|
|
|
2027
2029
|
}
|
|
2028
2030
|
return user;
|
|
2029
2031
|
}
|
|
2032
|
+
/**
|
|
2033
|
+
* Create a login for a person record. The branch is intentional and is the
|
|
2034
|
+
* single rule callers rely on:
|
|
2035
|
+
* - password provided → set it directly, NO email (seeding / imports)
|
|
2036
|
+
* - no password → random password + emailed set-password invite
|
|
2037
|
+
*
|
|
2038
|
+
* Returns the created (sanitized) user so the caller can link `userId`.
|
|
2039
|
+
*/
|
|
2040
|
+
async provisionUser(body) {
|
|
2041
|
+
const password = typeof body.password === "string" ? body.password.trim() : "";
|
|
2042
|
+
if (password) {
|
|
2043
|
+
return this.userService.create({
|
|
2044
|
+
id: body.id,
|
|
2045
|
+
name: body.name,
|
|
2046
|
+
email: body.email,
|
|
2047
|
+
role: body.role,
|
|
2048
|
+
roleId: body.roleId,
|
|
2049
|
+
image: body.image,
|
|
2050
|
+
password,
|
|
2051
|
+
status: body.status ?? "active"
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
return this.inviteUser(body);
|
|
2055
|
+
}
|
|
2030
2056
|
async loginUser(body) {
|
|
2031
2057
|
const { email: email2, password } = body;
|
|
2032
2058
|
const user = await this.userService.findByEmail(email2);
|
|
@@ -2713,6 +2739,20 @@ var AuthResolver = class AuthResolver2 {
|
|
|
2713
2739
|
container;
|
|
2714
2740
|
app;
|
|
2715
2741
|
log;
|
|
2742
|
+
/**
|
|
2743
|
+
* Missing/stale/invalid credentials (4xx) are an expected client state on
|
|
2744
|
+
* these resolve paths — e.g. a refresh cookie that outlived its DB row
|
|
2745
|
+
* after a reseed or rotation. Log those at debug; reserve warn for
|
|
2746
|
+
* unexpected (5xx/non-HTTP) failures.
|
|
2747
|
+
*/
|
|
2748
|
+
logResolveMiss(message, error) {
|
|
2749
|
+
const status = error?.status;
|
|
2750
|
+
if (typeof status === "number" && status < 500) {
|
|
2751
|
+
this.log.debug(message, error);
|
|
2752
|
+
} else {
|
|
2753
|
+
this.log.warn(message, error);
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2716
2756
|
async resolve(token) {
|
|
2717
2757
|
if (!token)
|
|
2718
2758
|
return false;
|
|
@@ -2728,7 +2768,7 @@ var AuthResolver = class AuthResolver2 {
|
|
|
2728
2768
|
permissions: user.permissions
|
|
2729
2769
|
};
|
|
2730
2770
|
} catch (error) {
|
|
2731
|
-
this.
|
|
2771
|
+
this.logResolveMiss("Token verification failed", error);
|
|
2732
2772
|
return false;
|
|
2733
2773
|
}
|
|
2734
2774
|
}
|
|
@@ -2744,7 +2784,7 @@ var AuthResolver = class AuthResolver2 {
|
|
|
2744
2784
|
permissions: session.permissions
|
|
2745
2785
|
};
|
|
2746
2786
|
} catch (error) {
|
|
2747
|
-
this.
|
|
2787
|
+
this.logResolveMiss("Session cookie verification failed", error);
|
|
2748
2788
|
return false;
|
|
2749
2789
|
}
|
|
2750
2790
|
}
|
|
@@ -2768,7 +2808,7 @@ var AuthResolver = class AuthResolver2 {
|
|
|
2768
2808
|
permissions: user.permissions
|
|
2769
2809
|
};
|
|
2770
2810
|
} catch (error) {
|
|
2771
|
-
this.
|
|
2811
|
+
this.logResolveMiss("Cookie verification failed", error);
|
|
2772
2812
|
return false;
|
|
2773
2813
|
}
|
|
2774
2814
|
}
|