@veap/auth 0.1.0 → 0.1.2
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 +3 -2
- package/dist/actions/auth.actions.d.ts +2 -2
- package/dist/actions/auth.actions.js +1 -1
- package/dist/actions/index.d.ts +1 -1
- package/dist/actions/index.js +1 -1
- package/dist/client/auth.context.d.ts +2 -2
- package/dist/client/auth.context.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/common/augment.d.ts +2 -2
- package/dist/common/augment.js +1 -1
- package/dist/common/context.d.ts +6 -5
- package/dist/common/context.js +7 -5
- package/dist/common/index.d.ts +7 -6
- package/dist/common/index.js +7 -6
- package/dist/common/logic.d.ts +3 -3
- package/dist/common/logic.js +3 -3
- package/dist/common/routes.d.ts +3 -2
- package/dist/common/routes.js +2 -1
- package/dist/common/tokens.d.ts +10 -0
- package/dist/common/tokens.js +8 -0
- package/dist/crypto/aes-cipher.d.ts +1 -1
- package/dist/crypto/aes-cipher.js +1 -1
- package/dist/crypto/bcrypt-hasher.d.ts +1 -1
- package/dist/crypto/index.d.ts +6 -6
- package/dist/crypto/index.js +6 -6
- package/dist/crypto/token-generator.d.ts +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.js +11 -11
- package/dist/migrations/index.d.ts +1 -1
- package/dist/migrations/index.js +1 -1
- package/dist/models/EmailVerification.d.ts +1 -1
- package/dist/models/EmailVerification.js +1 -1
- package/dist/models/PasswordResetSession.d.ts +1 -1
- package/dist/models/PasswordResetSession.js +1 -1
- package/dist/models/Permission.d.ts +2 -2
- package/dist/models/Permission.js +2 -2
- package/dist/models/Role.d.ts +2 -2
- package/dist/models/Role.js +2 -2
- package/dist/models/Session.d.ts +1 -1
- package/dist/models/Session.js +1 -1
- package/dist/models/User.d.ts +3 -3
- package/dist/models/User.js +3 -3
- package/dist/models/index.d.ts +6 -6
- package/dist/models/index.js +6 -6
- package/dist/models.d.ts +1 -1
- package/dist/models.js +1 -1
- package/dist/passwords/contracts.d.ts +1 -1
- package/dist/passwords/index.d.ts +4 -4
- package/dist/passwords/index.js +4 -4
- package/dist/passwords/password-reset.facade.d.ts +1 -1
- package/dist/passwords/password-reset.facade.js +9 -2
- package/dist/passwords/password-reset.repository.d.ts +2 -2
- package/dist/passwords/password-reset.repository.js +1 -1
- package/dist/passwords/password-reset.service.d.ts +3 -3
- package/dist/passwords/password-reset.service.js +4 -4
- package/dist/providers/auth.provider.d.ts +1 -1
- package/dist/providers/auth.provider.js +32 -29
- package/dist/providers/index.d.ts +2 -2
- package/dist/providers/index.js +2 -2
- package/dist/providers/setup.js +1 -1
- package/dist/rbac/contracts.d.ts +1 -1
- package/dist/rbac/index.d.ts +4 -4
- package/dist/rbac/index.js +4 -4
- package/dist/rbac/rbac.facade.d.ts +9 -9
- package/dist/rbac/rbac.facade.js +9 -2
- package/dist/rbac/rbac.repository.d.ts +1 -1
- package/dist/rbac/rbac.repository.js +3 -3
- package/dist/rbac/rbac.service.d.ts +2 -2
- package/dist/rbac/rbac.service.js +1 -1
- package/dist/server.d.ts +3 -3
- package/dist/server.js +3 -3
- package/dist/session/auth.service.d.ts +6 -6
- package/dist/session/auth.service.js +7 -8
- package/dist/session/contracts.d.ts +1 -1
- package/dist/session/index.d.ts +5 -5
- package/dist/session/index.js +5 -5
- package/dist/session/session.facade.d.ts +1 -1
- package/dist/session/session.facade.js +2 -2
- package/dist/session/session.repository.d.ts +2 -2
- package/dist/session/session.repository.js +1 -1
- package/dist/session/session.service.d.ts +3 -3
- package/dist/session/session.service.js +7 -5
- package/dist/users/contracts.d.ts +2 -1
- package/dist/users/index.d.ts +4 -4
- package/dist/users/index.js +4 -4
- package/dist/users/user.facade.d.ts +15 -1
- package/dist/users/user.facade.js +36 -6
- package/dist/users/user.repository.d.ts +3 -2
- package/dist/users/user.repository.js +6 -1
- package/dist/users/user.service.d.ts +17 -5
- package/dist/users/user.service.js +24 -6
- package/dist/validation/index.d.ts +0 -5
- package/dist/validation/index.js +0 -9
- package/dist/verification/index.d.ts +4 -4
- package/dist/verification/index.js +4 -4
- package/dist/verification/verification.facade.d.ts +4 -4
- package/dist/verification/verification.facade.js +9 -2
- package/dist/verification/verification.repository.d.ts +1 -1
- package/dist/verification/verification.repository.js +1 -1
- package/dist/verification/verification.service.d.ts +3 -3
- package/dist/verification/verification.service.js +7 -5
- package/package.json +9 -9
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { isDatabaseInitialized } from "@veap/database";
|
|
2
|
-
import {
|
|
3
|
-
import { bindAuthContext } from "../common/context";
|
|
4
|
-
import { DEFAULT_AUTH_ROUTES, } from "../common/routes";
|
|
5
|
-
import { AesSecretCipher } from "../crypto/aes-cipher";
|
|
6
|
-
import { BcryptPasswordHasher } from "../crypto/bcrypt-hasher";
|
|
7
|
-
import { PASSWORD_HASHER, SECRET_CIPHER, TOKEN_GENERATOR, } from "../crypto/contracts";
|
|
8
|
-
import { OsloTokenGenerator } from "../crypto/token-generator";
|
|
9
|
-
import { runAuthMigrations } from "../migrations";
|
|
10
|
-
import { PASSWORD_RESET_REPOSITORY } from "../passwords/contracts";
|
|
11
|
-
import { ActiveRecordPasswordResetRepository } from "../passwords/password-reset.repository";
|
|
12
|
-
import { PasswordResetService } from "../passwords/password-reset.service";
|
|
13
|
-
import { PERMISSION_REPOSITORY, ROLE_REPOSITORY } from "../rbac/contracts";
|
|
14
|
-
import { ActiveRecordPermissionRepository, ActiveRecordRoleRepository, } from "../rbac/rbac.repository";
|
|
15
|
-
import { RbacService } from "../rbac/rbac.service";
|
|
16
|
-
import { AuthService } from "../session/auth.service";
|
|
17
|
-
import { SESSION_REPOSITORY } from "../session/contracts";
|
|
18
|
-
import { ActiveRecordSessionRepository } from "../session/session.repository";
|
|
19
|
-
import { SessionService } from "../session/session.service";
|
|
20
|
-
import { USER_REPOSITORY } from "../users/contracts";
|
|
21
|
-
import { ActiveRecordUserRepository } from "../users/user.repository";
|
|
22
|
-
import { UserService } from "../users/user.service";
|
|
23
|
-
import { EMAIL_VERIFICATION_REPOSITORY } from "../verification/contracts";
|
|
24
|
-
import { ActiveRecordEmailVerificationRepository } from "../verification/verification.repository";
|
|
25
|
-
import { EmailVerificationService } from "../verification/verification.service";
|
|
26
|
-
import { isSystemInstalled } from "./setup";
|
|
2
|
+
import { ConfigService, Container, container as defaultContainer, logger, ServiceProvider, } from "@veap/kernel";
|
|
3
|
+
import { bindAuthContext } from "../common/context.js";
|
|
4
|
+
import { AUTH_ROUTES, DEFAULT_AUTH_ROUTES, ROUTER_SERVICE, } from "../common/routes.js";
|
|
5
|
+
import { AesSecretCipher } from "../crypto/aes-cipher.js";
|
|
6
|
+
import { BcryptPasswordHasher } from "../crypto/bcrypt-hasher.js";
|
|
7
|
+
import { PASSWORD_HASHER, SECRET_CIPHER, TOKEN_GENERATOR, } from "../crypto/contracts.js";
|
|
8
|
+
import { OsloTokenGenerator } from "../crypto/token-generator.js";
|
|
9
|
+
import { runAuthMigrations } from "../migrations/index.js";
|
|
10
|
+
import { PASSWORD_RESET_REPOSITORY } from "../passwords/contracts.js";
|
|
11
|
+
import { ActiveRecordPasswordResetRepository } from "../passwords/password-reset.repository.js";
|
|
12
|
+
import { PasswordResetService } from "../passwords/password-reset.service.js";
|
|
13
|
+
import { PERMISSION_REPOSITORY, ROLE_REPOSITORY } from "../rbac/contracts.js";
|
|
14
|
+
import { ActiveRecordPermissionRepository, ActiveRecordRoleRepository, } from "../rbac/rbac.repository.js";
|
|
15
|
+
import { RbacService } from "../rbac/rbac.service.js";
|
|
16
|
+
import { AuthService } from "../session/auth.service.js";
|
|
17
|
+
import { SESSION_REPOSITORY } from "../session/contracts.js";
|
|
18
|
+
import { ActiveRecordSessionRepository } from "../session/session.repository.js";
|
|
19
|
+
import { SessionService } from "../session/session.service.js";
|
|
20
|
+
import { USER_REPOSITORY } from "../users/contracts.js";
|
|
21
|
+
import { ActiveRecordUserRepository } from "../users/user.repository.js";
|
|
22
|
+
import { UserService } from "../users/user.service.js";
|
|
23
|
+
import { EMAIL_VERIFICATION_REPOSITORY } from "../verification/contracts.js";
|
|
24
|
+
import { ActiveRecordEmailVerificationRepository } from "../verification/verification.repository.js";
|
|
25
|
+
import { EmailVerificationService } from "../verification/verification.service.js";
|
|
26
|
+
import { isSystemInstalled } from "./setup.js";
|
|
27
27
|
export class AuthServiceProvider extends ServiceProvider {
|
|
28
28
|
config;
|
|
29
29
|
constructor(container, config) {
|
|
@@ -103,7 +103,7 @@ export class AuthServiceProvider extends ServiceProvider {
|
|
|
103
103
|
useClass: ActiveRecordEmailVerificationRepository,
|
|
104
104
|
singleton: true,
|
|
105
105
|
});
|
|
106
|
-
//
|
|
106
|
+
// Services
|
|
107
107
|
this.container.register({
|
|
108
108
|
token: UserService,
|
|
109
109
|
useClass: UserService,
|
|
@@ -136,7 +136,12 @@ export class AuthServiceProvider extends ServiceProvider {
|
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
async boot() {
|
|
139
|
-
//
|
|
139
|
+
// 0. Auto-bootstrap setup state
|
|
140
|
+
try {
|
|
141
|
+
isSystemInstalled();
|
|
142
|
+
}
|
|
143
|
+
catch { }
|
|
144
|
+
// 1. Resolve domain services and bind singleton auth context
|
|
140
145
|
const user = await this.container.resolve(UserService);
|
|
141
146
|
const session = await this.container.resolve(SessionService);
|
|
142
147
|
const rbac = await this.container.resolve(RbacService);
|
|
@@ -190,7 +195,5 @@ export class AuthServiceProvider extends ServiceProvider {
|
|
|
190
195
|
logger.error("veap:auth", "Failed to run auth database migrations during boot:", error.message);
|
|
191
196
|
}
|
|
192
197
|
}
|
|
193
|
-
// 4. Publish system:not-installed if no users exist
|
|
194
|
-
await isSystemInstalled();
|
|
195
198
|
}
|
|
196
199
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./auth.provider";
|
|
2
|
-
export * from "./setup";
|
|
1
|
+
export * from "./auth.provider.js";
|
|
2
|
+
export * from "./setup.js";
|
package/dist/providers/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./auth.provider";
|
|
2
|
-
export * from "./setup";
|
|
1
|
+
export * from "./auth.provider.js";
|
|
2
|
+
export * from "./setup.js";
|
package/dist/providers/setup.js
CHANGED
package/dist/rbac/contracts.d.ts
CHANGED
package/dist/rbac/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./contracts";
|
|
2
|
-
export * from "./rbac.facade";
|
|
3
|
-
export * from "./rbac.repository";
|
|
4
|
-
export * from "./rbac.service";
|
|
1
|
+
export * from "./contracts.js";
|
|
2
|
+
export * from "./rbac.facade.js";
|
|
3
|
+
export * from "./rbac.repository.js";
|
|
4
|
+
export * from "./rbac.service.js";
|
package/dist/rbac/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./contracts";
|
|
2
|
-
export * from "./rbac.facade";
|
|
3
|
-
export * from "./rbac.repository";
|
|
4
|
-
export * from "./rbac.service";
|
|
1
|
+
export * from "./contracts.js";
|
|
2
|
+
export * from "./rbac.facade.js";
|
|
3
|
+
export * from "./rbac.repository.js";
|
|
4
|
+
export * from "./rbac.service.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export declare function getRoles(): Promise<import("./contracts").RoleRecord[]>;
|
|
2
|
-
export declare function getRoleById(roleId: string): Promise<import("./contracts").RoleRecord | undefined>;
|
|
3
|
-
export declare function createRole(name: string, description?: string): Promise<import("./contracts").RoleRecord[]>;
|
|
1
|
+
export declare function getRoles(): Promise<import("./contracts.js").RoleRecord[]>;
|
|
2
|
+
export declare function getRoleById(roleId: string): Promise<import("./contracts.js").RoleRecord | undefined>;
|
|
3
|
+
export declare function createRole(name: string, description?: string): Promise<import("./contracts.js").RoleRecord[]>;
|
|
4
4
|
export declare function deleteRole(roleId: string): Promise<void>;
|
|
5
|
-
export declare function getPermissions(): Promise<import("./contracts").PermissionRecord[]>;
|
|
6
|
-
export declare function getPermissionById(permissionId: string): Promise<import("./contracts").PermissionRecord | undefined>;
|
|
7
|
-
export declare function createPermission(name: string, description?: string): Promise<import("./contracts").PermissionRecord[]>;
|
|
5
|
+
export declare function getPermissions(): Promise<import("./contracts.js").PermissionRecord[]>;
|
|
6
|
+
export declare function getPermissionById(permissionId: string): Promise<import("./contracts.js").PermissionRecord | undefined>;
|
|
7
|
+
export declare function createPermission(name: string, description?: string): Promise<import("./contracts.js").PermissionRecord[]>;
|
|
8
8
|
export declare function deletePermission(permissionId: string): Promise<void>;
|
|
9
|
-
export declare function getRolePermissions(roleId: string): Promise<import("./contracts").AccessGrant[]>;
|
|
9
|
+
export declare function getRolePermissions(roleId: string): Promise<import("./contracts.js").AccessGrant[]>;
|
|
10
10
|
export declare function assignPermissionToRole(roleId: string, permissionId: string): Promise<void>;
|
|
11
11
|
export declare function revokePermissionFromRole(roleId: string, permissionId: string): Promise<void>;
|
|
12
12
|
export declare function assignRoleToUser(userId: string, roleId: string): Promise<void>;
|
|
@@ -18,6 +18,6 @@ export declare function getUserRbacData(userId: string): Promise<{
|
|
|
18
18
|
id: string;
|
|
19
19
|
name: string;
|
|
20
20
|
}[];
|
|
21
|
-
directPermissions: import("./contracts").AccessGrant[];
|
|
22
|
-
effectivePermissions: import("./contracts").AccessGrant[];
|
|
21
|
+
directPermissions: import("./contracts.js").AccessGrant[];
|
|
22
|
+
effectivePermissions: import("./contracts.js").AccessGrant[];
|
|
23
23
|
}>;
|
package/dist/rbac/rbac.facade.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { app } from "@veap/kernel";
|
|
3
|
-
import { authContext, isAuthContextBound } from "../common/context";
|
|
4
|
-
import { RbacService } from "./rbac.service";
|
|
3
|
+
import { authContext, isAuthContextBound } from "../common/context.js";
|
|
4
|
+
import { RbacService } from "./rbac.service.js";
|
|
5
5
|
async function resolveRbacService() {
|
|
6
|
+
const g = globalThis;
|
|
7
|
+
if (g.__VEAP_BOOTSTRAPPING_PROMISE__) {
|
|
8
|
+
try {
|
|
9
|
+
await g.__VEAP_BOOTSTRAPPING_PROMISE__;
|
|
10
|
+
}
|
|
11
|
+
catch { }
|
|
12
|
+
}
|
|
6
13
|
if (isAuthContextBound()) {
|
|
7
14
|
return authContext().rbac;
|
|
8
15
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AccessGrant, CreatePermissionRecord, CreateRoleRecord, IPermissionRepository, IRoleRepository, PermissionRecord, RoleRecord, UserAccess } from "./contracts";
|
|
1
|
+
import type { AccessGrant, CreatePermissionRecord, CreateRoleRecord, IPermissionRepository, IRoleRepository, PermissionRecord, RoleRecord, UserAccess } from "./contracts.js";
|
|
2
2
|
/**
|
|
3
3
|
* `IRoleRepository` adapter backed by the `Role` ActiveRecord model and the
|
|
4
4
|
* `users_to_roles` pivot table.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getKnex } from "@veap/database";
|
|
2
|
-
import { Permission } from "../models/Permission";
|
|
3
|
-
import { Role } from "../models/Role";
|
|
4
|
-
import { User } from "../models/User";
|
|
2
|
+
import { Permission } from "../models/Permission.js";
|
|
3
|
+
import { Role } from "../models/Role.js";
|
|
4
|
+
import { User } from "../models/User.js";
|
|
5
5
|
/**
|
|
6
6
|
* `IRoleRepository` adapter backed by the `Role` ActiveRecord model and the
|
|
7
7
|
* `users_to_roles` pivot table.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { User } from "../common";
|
|
2
|
-
import { type AccessGrant, type IPermissionRepository, type IRoleRepository, type PermissionRecord, type RoleRecord } from "./contracts";
|
|
1
|
+
import type { User } from "../common/index.js";
|
|
2
|
+
import { type AccessGrant, type IPermissionRepository, type IRoleRepository, type PermissionRecord, type RoleRecord } from "./contracts.js";
|
|
3
3
|
/**
|
|
4
4
|
* Core RBAC use cases. Persistence lives behind the role/permission
|
|
5
5
|
* repositories, so this service stays framework-free and testable.
|
|
@@ -11,7 +11,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
13
|
import { Inject, Injectable } from "@veap/kernel";
|
|
14
|
-
import { PERMISSION_REPOSITORY, ROLE_REPOSITORY, } from "./contracts";
|
|
14
|
+
import { PERMISSION_REPOSITORY, ROLE_REPOSITORY, } from "./contracts.js";
|
|
15
15
|
/**
|
|
16
16
|
* Core RBAC use cases. Persistence lives behind the role/permission
|
|
17
17
|
* repositories, so this service stays framework-free and testable.
|
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./actions";
|
|
2
|
-
export * from "./crypto";
|
|
3
|
-
export * from "./index";
|
|
1
|
+
export * from "./actions/index.js";
|
|
2
|
+
export * from "./crypto/index.js";
|
|
3
|
+
export * from "./index.js";
|
package/dist/server.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./actions";
|
|
2
|
-
export * from "./crypto";
|
|
3
|
-
export * from "./index";
|
|
1
|
+
export * from "./actions/index.js";
|
|
2
|
+
export * from "./crypto/index.js";
|
|
3
|
+
export * from "./index.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type ICacheProvider } from "@veap/kernel";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { UserService } from "../users/user.service";
|
|
5
|
-
import type { LoginInput, RegisterInput } from "../validation";
|
|
6
|
-
import { EmailVerificationService } from "../verification/verification.service";
|
|
7
|
-
import { SessionService } from "./session.service";
|
|
2
|
+
import type { AuthResponse, SessionFlags } from "../common/index.js";
|
|
3
|
+
import { type IPasswordHasher } from "../crypto/contracts.js";
|
|
4
|
+
import { UserService } from "../users/user.service.js";
|
|
5
|
+
import type { LoginInput, RegisterInput } from "../validation/index.js";
|
|
6
|
+
import { EmailVerificationService } from "../verification/verification.service.js";
|
|
7
|
+
import { SessionService } from "./session.service.js";
|
|
8
8
|
export declare class AuthService {
|
|
9
9
|
private userService;
|
|
10
10
|
private sessionService;
|
|
@@ -11,12 +11,12 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
13
|
import { CACHE_PROVIDER, eventBus, Inject, Injectable, } from "@veap/kernel";
|
|
14
|
-
import { authValidators, performFullUserAugmentation } from "../common/logic";
|
|
15
|
-
import { PASSWORD_HASHER } from "../crypto/contracts";
|
|
16
|
-
import { UserService } from "../users/user.service";
|
|
17
|
-
import { loginSchema, registerSchema } from "../validation";
|
|
18
|
-
import { EmailVerificationService } from "../verification/verification.service";
|
|
19
|
-
import { SessionService } from "./session.service";
|
|
14
|
+
import { authValidators, performFullUserAugmentation, } from "../common/logic.js";
|
|
15
|
+
import { PASSWORD_HASHER } from "../crypto/contracts.js";
|
|
16
|
+
import { UserService } from "../users/user.service.js";
|
|
17
|
+
import { loginSchema, registerSchema } from "../validation/index.js";
|
|
18
|
+
import { EmailVerificationService } from "../verification/verification.service.js";
|
|
19
|
+
import { SessionService } from "./session.service.js";
|
|
20
20
|
let AuthService = class AuthService {
|
|
21
21
|
userService;
|
|
22
22
|
sessionService;
|
|
@@ -143,8 +143,7 @@ let AuthService = class AuthService {
|
|
|
143
143
|
message: "Email address is already registered",
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
|
-
const
|
|
147
|
-
const user = await this.userService.createUser(normalizedEmail, username, passwordHash);
|
|
146
|
+
const user = await this.userService.createUser(normalizedEmail, username, password);
|
|
148
147
|
const sessionFlags = {};
|
|
149
148
|
const sessionToken = await this.sessionService.generateSessionToken();
|
|
150
149
|
const session = await this.sessionService.createSession(sessionToken, user.id, sessionFlags);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AuthSession, FullUser, Session, SessionFlags, UserSession } from "../common";
|
|
1
|
+
import type { AuthSession, FullUser, Session, SessionFlags, UserSession } from "../common/index.js";
|
|
2
2
|
export type { AuthSession, FullUser, Session, SessionFlags, UserSession };
|
|
3
3
|
/** A session together with its owner, as loaded by `findWithUser`. */
|
|
4
4
|
export interface SessionWithUser {
|
package/dist/session/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from "./auth.service";
|
|
2
|
-
export * from "./contracts";
|
|
3
|
-
export * from "./session.facade";
|
|
4
|
-
export * from "./session.repository";
|
|
5
|
-
export * from "./session.service";
|
|
1
|
+
export * from "./auth.service.js";
|
|
2
|
+
export * from "./contracts.js";
|
|
3
|
+
export * from "./session.facade.js";
|
|
4
|
+
export * from "./session.repository.js";
|
|
5
|
+
export * from "./session.service.js";
|
package/dist/session/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from "./auth.service";
|
|
2
|
-
export * from "./contracts";
|
|
3
|
-
export * from "./session.facade";
|
|
4
|
-
export * from "./session.repository";
|
|
5
|
-
export * from "./session.service";
|
|
1
|
+
export * from "./auth.service.js";
|
|
2
|
+
export * from "./contracts.js";
|
|
3
|
+
export * from "./session.facade.js";
|
|
4
|
+
export * from "./session.repository.js";
|
|
5
|
+
export * from "./session.service.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AuthSession, SessionFlags, Session as SessionType, UserSession } from "../common";
|
|
1
|
+
import type { AuthSession, SessionFlags, Session as SessionType, UserSession } from "../common/index.js";
|
|
2
2
|
export declare function getIPAddress(): Promise<string | null>;
|
|
3
3
|
export declare function validateSessionToken(token: string): Promise<AuthSession>;
|
|
4
4
|
export declare const getCurrentSession: () => Promise<AuthSession>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { app } from "@veap/kernel";
|
|
3
3
|
import { cache } from "react";
|
|
4
|
-
import { authContext, isAuthContextBound } from "../common/context";
|
|
5
|
-
import { SessionService } from "./session.service";
|
|
4
|
+
import { authContext, isAuthContextBound } from "../common/context.js";
|
|
5
|
+
import { SessionService } from "./session.service.js";
|
|
6
6
|
async function resolveSessionService() {
|
|
7
7
|
const g = globalThis;
|
|
8
8
|
if (g.__VEAP_BOOTSTRAPPING_PROMISE__) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Session as SessionEntity } from "../common";
|
|
2
|
-
import type { CreateSessionRecord, ISessionRepository, SessionWithUser } from "./contracts";
|
|
1
|
+
import type { Session as SessionEntity } from "../common/index.js";
|
|
2
|
+
import type { CreateSessionRecord, ISessionRepository, SessionWithUser } from "./contracts.js";
|
|
3
3
|
/**
|
|
4
4
|
* `ISessionRepository` adapter backed by the `Session` ActiveRecord model.
|
|
5
5
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ICookieStore, type IHttpRequestContext } from "@veap/kernel";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { type ISessionRepository } from "./contracts";
|
|
2
|
+
import type { AuthSession, SessionFlags, Session as SessionType, UserSession } from "../common/index.js";
|
|
3
|
+
import { type ITokenGenerator } from "../crypto/contracts.js";
|
|
4
|
+
import { type ISessionRepository } from "./contracts.js";
|
|
5
5
|
export declare class SessionService {
|
|
6
6
|
private readonly sessions;
|
|
7
7
|
private readonly tokens;
|
|
@@ -13,10 +13,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
import { isIP } from "node:net";
|
|
14
14
|
import { COOKIE_STORE, Inject, Injectable, REQUEST_CONTEXT, } from "@veap/kernel";
|
|
15
15
|
import { addDays } from "date-fns";
|
|
16
|
-
import { augmentSession } from "../common/augment";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
16
|
+
import { augmentSession } from "../common/augment.js";
|
|
17
|
+
import { getAuthRoutes } from "../common/context.js";
|
|
18
|
+
import { performFullUserAugmentation } from "../common/logic.js";
|
|
19
|
+
import { TOKEN_GENERATOR } from "../crypto/contracts.js";
|
|
20
|
+
import { SESSION_REPOSITORY } from "./contracts.js";
|
|
20
21
|
let SessionService = class SessionService {
|
|
21
22
|
sessions;
|
|
22
23
|
tokens;
|
|
@@ -175,7 +176,8 @@ let SessionService = class SessionService {
|
|
|
175
176
|
await this.invalidateSession(session.id);
|
|
176
177
|
await this.deleteSessionTokenCookie();
|
|
177
178
|
}
|
|
178
|
-
|
|
179
|
+
const routes = getAuthRoutes();
|
|
180
|
+
await this.requestContext.redirect(routes.signIn);
|
|
179
181
|
}
|
|
180
182
|
/**
|
|
181
183
|
* Get all active sessions for a user.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FullUser, User } from "../common";
|
|
1
|
+
import type { FullUser, User } from "../common/index.js";
|
|
2
2
|
export type { FullUser, User };
|
|
3
3
|
export interface CreateUserRecord {
|
|
4
4
|
email: string;
|
|
@@ -27,6 +27,7 @@ export interface IUserRepository {
|
|
|
27
27
|
update(id: string, changes: UpdateUserRecord): Promise<void>;
|
|
28
28
|
setRecoveryCode(id: string, encrypted: Uint8Array): Promise<void>;
|
|
29
29
|
setEmailVerifiedIfEmailMatches(id: string, email: string): Promise<boolean>;
|
|
30
|
+
isEmailAvailable(email: string): Promise<boolean>;
|
|
30
31
|
}
|
|
31
32
|
/** Injection token for the user repository port. */
|
|
32
33
|
export declare const USER_REPOSITORY: unique symbol;
|
package/dist/users/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./contracts";
|
|
2
|
-
export * from "./user.facade";
|
|
3
|
-
export * from "./user.repository";
|
|
4
|
-
export * from "./user.service";
|
|
1
|
+
export * from "./contracts.js";
|
|
2
|
+
export * from "./user.facade.js";
|
|
3
|
+
export * from "./user.repository.js";
|
|
4
|
+
export * from "./user.service.js";
|
package/dist/users/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./contracts";
|
|
2
|
-
export * from "./user.facade";
|
|
3
|
-
export * from "./user.repository";
|
|
4
|
-
export * from "./user.service";
|
|
1
|
+
export * from "./contracts.js";
|
|
2
|
+
export * from "./user.facade.js";
|
|
3
|
+
export * from "./user.repository.js";
|
|
4
|
+
export * from "./user.service.js";
|
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
import type { User } from "../common";
|
|
1
|
+
import type { User } from "../common/index.js";
|
|
2
2
|
export declare function verifyUsernameInput(username: string): Promise<boolean>;
|
|
3
|
+
export declare function isEmailAvailable(email: string): Promise<boolean>;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if an email address is available for registration.
|
|
6
|
+
* Compatible with legacy imports.
|
|
7
|
+
*/
|
|
8
|
+
export declare function checkEmailAvailability(email: string): Promise<boolean>;
|
|
3
9
|
export declare function createUser(email: string, username: string, password: string): Promise<User>;
|
|
4
10
|
export declare function createOAuthUser(email: string, name: string, image?: string): Promise<User>;
|
|
5
11
|
export declare function getUserById(userId: string): Promise<User | null>;
|
|
12
|
+
export declare function getUserRecoveryCode(userId: string): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use `getUserRecoveryCode` instead.
|
|
15
|
+
*/
|
|
6
16
|
export declare function getUserRecoverCode(userId: string): Promise<string>;
|
|
7
17
|
export declare function resetUserRecoveryCode(userId: string): Promise<string>;
|
|
8
18
|
export declare function updateUserPassword(userId: string, password: string): Promise<void>;
|
|
9
19
|
export declare function updateUserName(userId: string, name: string): Promise<void>;
|
|
20
|
+
export declare function updateUserAvatar(userId: string, image: string): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use `updateUserAvatar` instead.
|
|
23
|
+
*/
|
|
10
24
|
export declare function updateUserAwatar(userId: string, image: string): Promise<void>;
|
|
11
25
|
export declare function updateUserEmailAndSetEmailAsVerified(userId: string, email: string): Promise<void>;
|
|
12
26
|
export declare function setUserAsEmailVerifiedIfEmailMatches(userId: string, email: string): Promise<boolean>;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { app } from "@veap/kernel";
|
|
3
|
-
import { authContext, isAuthContextBound } from "../common/context";
|
|
4
|
-
import { UserService } from "./user.service";
|
|
3
|
+
import { authContext, isAuthContextBound } from "../common/context.js";
|
|
4
|
+
import { UserService } from "./user.service.js";
|
|
5
5
|
async function resolveUserService() {
|
|
6
|
+
const g = globalThis;
|
|
7
|
+
if (g.__VEAP_BOOTSTRAPPING_PROMISE__) {
|
|
8
|
+
try {
|
|
9
|
+
await g.__VEAP_BOOTSTRAPPING_PROMISE__;
|
|
10
|
+
}
|
|
11
|
+
catch { }
|
|
12
|
+
}
|
|
6
13
|
if (isAuthContextBound()) {
|
|
7
14
|
return authContext().user;
|
|
8
15
|
}
|
|
@@ -12,6 +19,17 @@ export async function verifyUsernameInput(username) {
|
|
|
12
19
|
const service = await resolveUserService();
|
|
13
20
|
return service.verifyUsernameInput(username);
|
|
14
21
|
}
|
|
22
|
+
export async function isEmailAvailable(email) {
|
|
23
|
+
const service = await resolveUserService();
|
|
24
|
+
return service.isEmailAvailable(email);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks if an email address is available for registration.
|
|
28
|
+
* Compatible with legacy imports.
|
|
29
|
+
*/
|
|
30
|
+
export async function checkEmailAvailability(email) {
|
|
31
|
+
return isEmailAvailable(email);
|
|
32
|
+
}
|
|
15
33
|
export async function createUser(email, username, password) {
|
|
16
34
|
const service = await resolveUserService();
|
|
17
35
|
return service.createUser(email, username, password);
|
|
@@ -24,9 +42,15 @@ export async function getUserById(userId) {
|
|
|
24
42
|
const service = await resolveUserService();
|
|
25
43
|
return service.getUserById(userId);
|
|
26
44
|
}
|
|
27
|
-
export async function
|
|
45
|
+
export async function getUserRecoveryCode(userId) {
|
|
28
46
|
const service = await resolveUserService();
|
|
29
|
-
return service.
|
|
47
|
+
return service.getUserRecoveryCode(userId);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated Use `getUserRecoveryCode` instead.
|
|
51
|
+
*/
|
|
52
|
+
export async function getUserRecoverCode(userId) {
|
|
53
|
+
return getUserRecoveryCode(userId);
|
|
30
54
|
}
|
|
31
55
|
export async function resetUserRecoveryCode(userId) {
|
|
32
56
|
const service = await resolveUserService();
|
|
@@ -40,9 +64,15 @@ export async function updateUserName(userId, name) {
|
|
|
40
64
|
const service = await resolveUserService();
|
|
41
65
|
return service.updateUserName(userId, name);
|
|
42
66
|
}
|
|
43
|
-
export async function
|
|
67
|
+
export async function updateUserAvatar(userId, image) {
|
|
44
68
|
const service = await resolveUserService();
|
|
45
|
-
return service.
|
|
69
|
+
return service.updateUserAvatar(userId, image);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Use `updateUserAvatar` instead.
|
|
73
|
+
*/
|
|
74
|
+
export async function updateUserAwatar(userId, image) {
|
|
75
|
+
return updateUserAvatar(userId, image);
|
|
46
76
|
}
|
|
47
77
|
export async function updateUserEmailAndSetEmailAsVerified(userId, email) {
|
|
48
78
|
const service = await resolveUserService();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { User as UserEntity } from "../common";
|
|
2
|
-
import type { CreateUserRecord, IUserRepository, UpdateUserRecord } from "./contracts";
|
|
1
|
+
import type { User as UserEntity } from "../common/index.js";
|
|
2
|
+
import type { CreateUserRecord, IUserRepository, UpdateUserRecord } from "./contracts.js";
|
|
3
3
|
/**
|
|
4
4
|
* `IUserRepository` adapter backed by the `User` ActiveRecord model.
|
|
5
5
|
*/
|
|
@@ -12,4 +12,5 @@ export declare class ActiveRecordUserRepository implements IUserRepository {
|
|
|
12
12
|
update(id: string, changes: UpdateUserRecord): Promise<void>;
|
|
13
13
|
setRecoveryCode(id: string, encrypted: Uint8Array): Promise<void>;
|
|
14
14
|
setEmailVerifiedIfEmailMatches(id: string, email: string): Promise<boolean>;
|
|
15
|
+
isEmailAvailable(email: string): Promise<boolean>;
|
|
15
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { User } from "../models/User";
|
|
1
|
+
import { User } from "../models/User.js";
|
|
2
2
|
/**
|
|
3
3
|
* `IUserRepository` adapter backed by the `User` ActiveRecord model.
|
|
4
4
|
*/
|
|
@@ -52,4 +52,9 @@ export class ActiveRecordUserRepository {
|
|
|
52
52
|
});
|
|
53
53
|
return updated > 0;
|
|
54
54
|
}
|
|
55
|
+
async isEmailAvailable(email) {
|
|
56
|
+
const normalized = email.toLowerCase().trim();
|
|
57
|
+
const exists = await User.where("email", normalized).exists();
|
|
58
|
+
return !exists;
|
|
59
|
+
}
|
|
55
60
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type
|
|
3
|
-
import { type IRoleRepository } from "../rbac/contracts";
|
|
4
|
-
import { type IUserRepository } from "./contracts";
|
|
1
|
+
import type { User } from "../common/index.js";
|
|
2
|
+
import { type IPasswordHasher, type ISecretCipher, type ITokenGenerator } from "../crypto/contracts.js";
|
|
3
|
+
import { type IRoleRepository } from "../rbac/contracts.js";
|
|
4
|
+
import { type IUserRepository } from "./contracts.js";
|
|
5
5
|
export declare class UserService {
|
|
6
6
|
private readonly users;
|
|
7
7
|
private readonly roles;
|
|
@@ -13,6 +13,10 @@ export declare class UserService {
|
|
|
13
13
|
* Validates the username input.
|
|
14
14
|
*/
|
|
15
15
|
verifyUsernameInput(username: string): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Checks whether the specified email is available for registration.
|
|
18
|
+
*/
|
|
19
|
+
isEmailAvailable(email: string): Promise<boolean>;
|
|
16
20
|
/**
|
|
17
21
|
* Creates a new user with an initial recovery code and default 'user' role.
|
|
18
22
|
*/
|
|
@@ -28,6 +32,10 @@ export declare class UserService {
|
|
|
28
32
|
/**
|
|
29
33
|
* Decrypts and returns the user's recovery code.
|
|
30
34
|
*/
|
|
35
|
+
getUserRecoveryCode(userId: string): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use `getUserRecoveryCode` instead.
|
|
38
|
+
*/
|
|
31
39
|
getUserRecoverCode(userId: string): Promise<string>;
|
|
32
40
|
/**
|
|
33
41
|
* Generates and sets a new recovery code for the user.
|
|
@@ -42,7 +50,11 @@ export declare class UserService {
|
|
|
42
50
|
*/
|
|
43
51
|
updateUserName(userId: string, name: string): Promise<void>;
|
|
44
52
|
/**
|
|
45
|
-
* Updates the user's image.
|
|
53
|
+
* Updates the user's avatar image.
|
|
54
|
+
*/
|
|
55
|
+
updateUserAvatar(userId: string, image: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Use `updateUserAvatar` instead.
|
|
46
58
|
*/
|
|
47
59
|
updateUserAwatar(userId: string, image: string): Promise<void>;
|
|
48
60
|
/**
|