@babylonjs-toolkit/server 0.0.0-stage → 9.35.1
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/CUSTOM.md +1690 -0
- package/DEPLOY.md +2012 -0
- package/README.md +1081 -2
- package/lib/AbuseLimits.d.ts +64 -0
- package/lib/AbuseLimits.js +121 -0
- package/lib/Authentication.d.ts +86 -0
- package/lib/Authentication.js +272 -0
- package/lib/BootSessionOwner.d.ts +86 -0
- package/lib/BootSessionOwner.js +116 -0
- package/lib/ColyseusLoggerAdapter.d.ts +32 -0
- package/lib/ColyseusLoggerAdapter.js +73 -0
- package/lib/DedicatedSceneRegistry.d.ts +52 -0
- package/lib/DedicatedSceneRegistry.js +74 -0
- package/lib/DedicatedSession.d.ts +152 -0
- package/lib/DedicatedSession.js +173 -0
- package/lib/DualTransport.d.ts +112 -0
- package/lib/DualTransport.js +197 -0
- package/lib/GameServer.d.ts +64 -0
- package/lib/GameServer.js +647 -0
- package/lib/GameServerConfig.d.ts +387 -0
- package/lib/GameServerConfig.js +1059 -0
- package/lib/GameServerLobbyRoom.d.ts +33 -0
- package/lib/GameServerLobbyRoom.js +56 -0
- package/lib/GameServerLogger.d.ts +111 -0
- package/lib/GameServerLogger.js +190 -0
- package/lib/GameServerMetrics.d.ts +158 -0
- package/lib/GameServerMetrics.js +276 -0
- package/lib/GameServerState.d.ts +164 -0
- package/lib/GameServerState.js +26 -0
- package/lib/HeadlessRuntime.d.ts +316 -0
- package/lib/HeadlessRuntime.js +380 -0
- package/lib/JoinGate.d.ts +34 -0
- package/lib/JoinGate.js +221 -0
- package/lib/NetworkAddresses.d.ts +33 -0
- package/lib/NetworkAddresses.js +90 -0
- package/lib/PlayerTokens.d.ts +17 -0
- package/lib/PlayerTokens.js +24 -0
- package/lib/RoomServerTransport.d.ts +73 -0
- package/lib/RoomServerTransport.js +90 -0
- package/lib/ServerEndpoints.d.ts +133 -0
- package/lib/ServerEndpoints.js +247 -0
- package/lib/ServerInit.d.ts +28 -0
- package/lib/ServerInit.js +113 -0
- package/lib/SessionRoom.d.ts +391 -0
- package/lib/SessionRoom.js +930 -0
- package/lib/TlsCertificates.d.ts +35 -0
- package/lib/TlsCertificates.js +130 -0
- package/lib/admin/AccountRoutes.d.ts +8 -0
- package/lib/admin/AccountRoutes.js +502 -0
- package/lib/admin/AdminAccounts.d.ts +329 -0
- package/lib/admin/AdminAccounts.js +607 -0
- package/lib/admin/AdminApiRouter.d.ts +202 -0
- package/lib/admin/AdminApiRouter.js +465 -0
- package/lib/admin/AdminApiTypes.d.ts +1782 -0
- package/lib/admin/AdminApiTypes.js +4 -0
- package/lib/admin/AdminAudit.d.ts +113 -0
- package/lib/admin/AdminAudit.js +266 -0
- package/lib/admin/AdminCli.d.ts +7 -0
- package/lib/admin/AdminCli.js +351 -0
- package/lib/admin/AdminClock.d.ts +51 -0
- package/lib/admin/AdminClock.js +10 -0
- package/lib/admin/AdminConsole.d.ts +39 -0
- package/lib/admin/AdminConsole.js +325 -0
- package/lib/admin/AdminConstants.d.ts +147 -0
- package/lib/admin/AdminConstants.js +167 -0
- package/lib/admin/AdminCrypto.d.ts +19 -0
- package/lib/admin/AdminCrypto.js +29 -0
- package/lib/admin/AdminExtensionsHost.d.ts +176 -0
- package/lib/admin/AdminExtensionsHost.js +307 -0
- package/lib/admin/AdminPasswords.d.ts +33 -0
- package/lib/admin/AdminPasswords.js +92 -0
- package/lib/admin/AdminPermissions.d.ts +28 -0
- package/lib/admin/AdminPermissions.js +74 -0
- package/lib/admin/AdminRecords.d.ts +196 -0
- package/lib/admin/AdminRecords.js +3 -0
- package/lib/admin/AdminRequestBodies.d.ts +47 -0
- package/lib/admin/AdminRequestBodies.js +84 -0
- package/lib/admin/AdminRequestGate.d.ts +38 -0
- package/lib/admin/AdminRequestGate.js +59 -0
- package/lib/admin/AdminResponses.d.ts +103 -0
- package/lib/admin/AdminResponses.js +164 -0
- package/lib/admin/AdminServices.d.ts +99 -0
- package/lib/admin/AdminServices.js +4 -0
- package/lib/admin/AdminStaticFiles.d.ts +29 -0
- package/lib/admin/AdminStaticFiles.js +97 -0
- package/lib/admin/AdminStore.d.ts +152 -0
- package/lib/admin/AdminStore.js +46 -0
- package/lib/admin/AlertChannels.d.ts +43 -0
- package/lib/admin/AlertChannels.js +120 -0
- package/lib/admin/AlertEngine.d.ts +231 -0
- package/lib/admin/AlertEngine.js +681 -0
- package/lib/admin/AlertRoutes.d.ts +8 -0
- package/lib/admin/AlertRoutes.js +180 -0
- package/lib/admin/ApiKeyRoutes.d.ts +8 -0
- package/lib/admin/ApiKeyRoutes.js +53 -0
- package/lib/admin/ApiKeys.d.ts +63 -0
- package/lib/admin/ApiKeys.js +167 -0
- package/lib/admin/AuditRoutes.d.ts +8 -0
- package/lib/admin/AuditRoutes.js +106 -0
- package/lib/admin/AuthToolRoutes.d.ts +13 -0
- package/lib/admin/AuthToolRoutes.js +164 -0
- package/lib/admin/BanList.d.ts +87 -0
- package/lib/admin/BanList.js +152 -0
- package/lib/admin/CborDecoder.d.ts +18 -0
- package/lib/admin/CborDecoder.js +201 -0
- package/lib/admin/ColyseusCloudClient.d.ts +313 -0
- package/lib/admin/ColyseusCloudClient.js +272 -0
- package/lib/admin/ColyseusCloudRoutes.d.ts +8 -0
- package/lib/admin/ColyseusCloudRoutes.js +91 -0
- package/lib/admin/ColyseusCloudService.d.ts +180 -0
- package/lib/admin/ColyseusCloudService.js +476 -0
- package/lib/admin/ColyseusCloudSettings.d.ts +16 -0
- package/lib/admin/ColyseusCloudSettings.js +29 -0
- package/lib/admin/ColyseusCloudViews.d.ts +105 -0
- package/lib/admin/ColyseusCloudViews.js +371 -0
- package/lib/admin/CommonPasswords.d.ts +6 -0
- package/lib/admin/CommonPasswords.js +19 -0
- package/lib/admin/ConfigOverrides.d.ts +174 -0
- package/lib/admin/ConfigOverrides.js +406 -0
- package/lib/admin/ConfigRoutes.d.ts +8 -0
- package/lib/admin/ConfigRoutes.js +91 -0
- package/lib/admin/ConsoleSessions.d.ts +112 -0
- package/lib/admin/ConsoleSessions.js +201 -0
- package/lib/admin/DedicatedRoutes.d.ts +21 -0
- package/lib/admin/DedicatedRoutes.js +254 -0
- package/lib/admin/ExtensionRoutes.d.ts +8 -0
- package/lib/admin/ExtensionRoutes.js +145 -0
- package/lib/admin/FileAdminStore.d.ts +157 -0
- package/lib/admin/FileAdminStore.js +349 -0
- package/lib/admin/FleetDirectory.d.ts +323 -0
- package/lib/admin/FleetDirectory.js +489 -0
- package/lib/admin/FleetLeader.d.ts +43 -0
- package/lib/admin/FleetLeader.js +89 -0
- package/lib/admin/FleetRoutes.d.ts +55 -0
- package/lib/admin/FleetRoutes.js +465 -0
- package/lib/admin/HealthWarnings.d.ts +10 -0
- package/lib/admin/HealthWarnings.js +95 -0
- package/lib/admin/LeaderboardRoutes.d.ts +8 -0
- package/lib/admin/LeaderboardRoutes.js +569 -0
- package/lib/admin/LogBuffer.d.ts +60 -0
- package/lib/admin/LogBuffer.js +92 -0
- package/lib/admin/LogRedaction.d.ts +15 -0
- package/lib/admin/LogRedaction.js +72 -0
- package/lib/admin/LogRoutes.d.ts +45 -0
- package/lib/admin/LogRoutes.js +307 -0
- package/lib/admin/MaintenanceMode.d.ts +41 -0
- package/lib/admin/MaintenanceMode.js +74 -0
- package/lib/admin/MaintenanceWindows.d.ts +91 -0
- package/lib/admin/MaintenanceWindows.js +207 -0
- package/lib/admin/MetricsRoutes.d.ts +8 -0
- package/lib/admin/MetricsRoutes.js +209 -0
- package/lib/admin/MetricsSampler.d.ts +124 -0
- package/lib/admin/MetricsSampler.js +211 -0
- package/lib/admin/OneTimeCodes.d.ts +60 -0
- package/lib/admin/OneTimeCodes.js +162 -0
- package/lib/admin/OpenIdConnect.d.ts +146 -0
- package/lib/admin/OpenIdConnect.js +335 -0
- package/lib/admin/Passkeys.d.ts +130 -0
- package/lib/admin/Passkeys.js +432 -0
- package/lib/admin/PlayerRoutes.d.ts +20 -0
- package/lib/admin/PlayerRoutes.js +676 -0
- package/lib/admin/RedisAdminStore.d.ts +114 -0
- package/lib/admin/RedisAdminStore.js +258 -0
- package/lib/admin/RolloutCoordinator.d.ts +99 -0
- package/lib/admin/RolloutCoordinator.js +321 -0
- package/lib/admin/ServerEvents.d.ts +57 -0
- package/lib/admin/ServerEvents.js +89 -0
- package/lib/admin/SessionRoutes.d.ts +113 -0
- package/lib/admin/SessionRoutes.js +386 -0
- package/lib/admin/UserRoutes.d.ts +8 -0
- package/lib/admin/UserRoutes.js +214 -0
- package/lib/cli.d.ts +2 -0
- package/lib/cli.js +221 -0
- package/lib/console/assets/index-CI5N7c-T.js +21 -0
- package/lib/console/assets/index-DPitvzLp.css +1 -0
- package/lib/console/favicon.svg +1 -0
- package/lib/console/index.html +16 -0
- package/lib/discord/DiscordOAuth.d.ts +57 -0
- package/lib/discord/DiscordOAuth.js +127 -0
- package/lib/discord/DiscordSessions.d.ts +79 -0
- package/lib/discord/DiscordSessions.js +135 -0
- package/lib/discord/DiscordSignInConstants.d.ts +54 -0
- package/lib/discord/DiscordSignInConstants.js +55 -0
- package/lib/discord/DiscordSignInRoutes.d.ts +51 -0
- package/lib/discord/DiscordSignInRoutes.js +359 -0
- package/lib/index.d.ts +24 -0
- package/lib/index.js +18 -0
- package/lib/leaderboards/FileLeaderboardRankStore.d.ts +293 -0
- package/lib/leaderboards/FileLeaderboardRankStore.js +808 -0
- package/lib/leaderboards/LeaderboardConstants.d.ts +63 -0
- package/lib/leaderboards/LeaderboardConstants.js +70 -0
- package/lib/leaderboards/LeaderboardError.d.ts +15 -0
- package/lib/leaderboards/LeaderboardError.js +20 -0
- package/lib/leaderboards/LeaderboardIdentity.d.ts +44 -0
- package/lib/leaderboards/LeaderboardIdentity.js +72 -0
- package/lib/leaderboards/LeaderboardPublicApi.d.ts +17 -0
- package/lib/leaderboards/LeaderboardPublicApi.js +389 -0
- package/lib/leaderboards/LeaderboardRankStore.d.ts +296 -0
- package/lib/leaderboards/LeaderboardRankStore.js +18 -0
- package/lib/leaderboards/LeaderboardRules.d.ts +122 -0
- package/lib/leaderboards/LeaderboardRules.js +472 -0
- package/lib/leaderboards/LeaderboardScheduler.d.ts +43 -0
- package/lib/leaderboards/LeaderboardScheduler.js +103 -0
- package/lib/leaderboards/LeaderboardService.d.ts +669 -0
- package/lib/leaderboards/LeaderboardService.js +1667 -0
- package/lib/leaderboards/LeaderboardTransfer.d.ts +35 -0
- package/lib/leaderboards/LeaderboardTransfer.js +580 -0
- package/lib/leaderboards/RedisLeaderboardRankStore.d.ts +282 -0
- package/lib/leaderboards/RedisLeaderboardRankStore.js +691 -0
- package/package.json +64 -4
- package/templates/init/Caddyfile +6 -0
- package/templates/init/DEPLOY.md +233 -0
- package/templates/init/Dockerfile +12 -0
- package/templates/init/app.json +21 -0
- package/templates/init/aws/README.md +118 -0
- package/templates/init/aws/ecs-fargate-alb.yml +207 -0
- package/templates/init/aws/ecs-fargate-nlb-quic.yml +210 -0
- package/templates/init/babylon-game-server.config.mjs +158 -0
- package/templates/init/colyseus-cloud/README.md +133 -0
- package/templates/init/colyseus-cloud/babylon-game-server.config.mjs +36 -0
- package/templates/init/colyseus-cloud/ecosystem.config.cjs +35 -0
- package/templates/init/colyseus-cloud/gitignore +6 -0
- package/templates/init/colyseus-cloud/package.json +15 -0
- package/templates/init/digitalocean-app.yaml +30 -0
- package/templates/init/docker-compose.full.yml +45 -0
- package/templates/init/docker-compose.websocket.yml +41 -0
- package/templates/init/fly.toml +56 -0
- package/templates/init/heroku.yml +11 -0
- package/templates/init/kubernetes/deployment.yaml +71 -0
- package/templates/init/kubernetes/redis.yaml +73 -0
- package/templates/init/kubernetes/service.yaml +24 -0
- package/templates/init/monitoring/grafana-dashboard.json +539 -0
- package/templates/init/monitoring/prometheus-alerts.yml +51 -0
- package/templates/init/monitoring/prometheus-scrape.yml +17 -0
- package/templates/init/railway.json +13 -0
- package/templates/init/render.yaml +19 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import type { GameServerUrls } from "../GameServer.js";
|
|
2
|
+
import { type AdminCaller } from "./AdminApiRouter.js";
|
|
3
|
+
import type { AdminPreferences, AdminRole, AdminUserView, SetupOwnerRequest, SignInRequest, SignInStepView, TotpEnrolmentView } from "./AdminApiTypes.js";
|
|
4
|
+
import type { AdminClock } from "./AdminClock.js";
|
|
5
|
+
import type { AdminUserRecord, ConsoleSessionRecord } from "./AdminRecords.js";
|
|
6
|
+
import type { AdminStore, StoredDocument } from "./AdminStore.js";
|
|
7
|
+
import type { ConsoleSessions, SignInContext } from "./ConsoleSessions.js";
|
|
8
|
+
/** A new account (R32). */
|
|
9
|
+
export interface NewAdminUserInput {
|
|
10
|
+
username: string;
|
|
11
|
+
displayName: string;
|
|
12
|
+
email: string | null;
|
|
13
|
+
role: AdminRole;
|
|
14
|
+
/** The first password, or null for an SSO-only account. */
|
|
15
|
+
password: string | null;
|
|
16
|
+
oidcSubject: string | null;
|
|
17
|
+
}
|
|
18
|
+
/** A second factor: an authenticator code or a recovery code (R32). */
|
|
19
|
+
export type SecondFactorProof = {
|
|
20
|
+
code: string;
|
|
21
|
+
} | {
|
|
22
|
+
recoveryCode: string;
|
|
23
|
+
};
|
|
24
|
+
/** A finished sign-in. */
|
|
25
|
+
export interface SignInResult {
|
|
26
|
+
/** The new console session. */
|
|
27
|
+
session: ConsoleSessionRecord;
|
|
28
|
+
/** Its cookie value (sent once in Set-Cookie). */
|
|
29
|
+
cookieValue: string;
|
|
30
|
+
/** New recovery codes after an enrolment; empty otherwise. */
|
|
31
|
+
recoveryCodes: string[];
|
|
32
|
+
/** The account. */
|
|
33
|
+
user: AdminUserRecord;
|
|
34
|
+
}
|
|
35
|
+
/** Called after an account is locked, so it can be audited (T3). */
|
|
36
|
+
export type AccountLockoutListener = (user: AdminUserRecord, clientAddress: string) => void;
|
|
37
|
+
/** The admin accounts of the store. */
|
|
38
|
+
export declare class AdminAccounts {
|
|
39
|
+
/** The admin store. */
|
|
40
|
+
private readonly store;
|
|
41
|
+
/** The clock of expiries and lockouts. */
|
|
42
|
+
private readonly clock;
|
|
43
|
+
/** The console sessions. */
|
|
44
|
+
private readonly sessions;
|
|
45
|
+
/** Whether the console is on (a setup link is offered only then). */
|
|
46
|
+
private readonly consoleEnabled;
|
|
47
|
+
/** The pending first-owner setup, or null. */
|
|
48
|
+
private setupLink;
|
|
49
|
+
/** Told when an account is locked. */
|
|
50
|
+
private lockoutListener;
|
|
51
|
+
/**
|
|
52
|
+
* Creates the account service.
|
|
53
|
+
* @param store The admin store.
|
|
54
|
+
* @param clock The clock.
|
|
55
|
+
* @param sessions The console sessions.
|
|
56
|
+
* @param consoleEnabled admin.console.
|
|
57
|
+
*/
|
|
58
|
+
constructor(store: AdminStore, clock: AdminClock, sessions: ConsoleSessions, consoleEnabled: boolean);
|
|
59
|
+
/**
|
|
60
|
+
* Sets who is told when an account is locked (the audit log).
|
|
61
|
+
* @param listener The listener.
|
|
62
|
+
*/
|
|
63
|
+
onLockout(listener: AccountLockoutListener): void;
|
|
64
|
+
/**
|
|
65
|
+
* Offers a one-time first-owner setup link when no account exists (D30, DR §7.1): the link is logged once at warn
|
|
66
|
+
* level and only its hash is kept. On Redis the hash is stored as well as held here, because behind a load balancer
|
|
67
|
+
* the request that uses the link can reach any process, and on Colyseus Cloud there is no shell to create an owner
|
|
68
|
+
* from. A file store has one process, so a first start writes nothing to the data folder.
|
|
69
|
+
* @param urls Where the server is reached.
|
|
70
|
+
*/
|
|
71
|
+
ensureSetupLink(urls: GameServerUrls): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Whether a first-owner setup link is waiting to be used.
|
|
74
|
+
* @returns True until it is used or expires.
|
|
75
|
+
*/
|
|
76
|
+
hasPendingSetup(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Whether any account exists.
|
|
79
|
+
* @returns True when the users collection is not empty.
|
|
80
|
+
*/
|
|
81
|
+
hasUsers(): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Whether an enabled owner other than this account exists (DR §5: the last enabled owner is never removed, demoted
|
|
84
|
+
* or disabled — by the users routes or by a single sign-on role mapping).
|
|
85
|
+
* @param ownerId The owner that would lose the role.
|
|
86
|
+
* @returns True when another enabled owner remains.
|
|
87
|
+
*/
|
|
88
|
+
hasAnotherEnabledOwner(ownerId: string): Promise<boolean>;
|
|
89
|
+
/**
|
|
90
|
+
* Creates the first owner from the setup link (single use, DR §7.1).
|
|
91
|
+
* @param request The setup token and the owner's details.
|
|
92
|
+
* @returns The enrolment step of the owner's first sign-in.
|
|
93
|
+
* @throws AdminRequestError 404 for a used, expired or wrong token; 400 for an invalid username or password.
|
|
94
|
+
*/
|
|
95
|
+
createOwnerFromSetup(request: SetupOwnerRequest): Promise<SignInStepView>;
|
|
96
|
+
/**
|
|
97
|
+
* Whether a token hash names a live setup link of this process or, in the store, of any other. The store is looked
|
|
98
|
+
* up by the hash, so a wrong token finds nothing.
|
|
99
|
+
* @param tokenHash The hash of the token offered.
|
|
100
|
+
* @returns True for a live link.
|
|
101
|
+
*/
|
|
102
|
+
private isSetupLinkLive;
|
|
103
|
+
/** Removes every process's setup link once the first owner exists: one owner ends them all. */
|
|
104
|
+
private forgetSetupLinks;
|
|
105
|
+
/**
|
|
106
|
+
* Creates an account (setup, the CLI and the users routes).
|
|
107
|
+
* @param input The account.
|
|
108
|
+
* @returns The stored account.
|
|
109
|
+
* @throws AdminRequestError 400 for an invalid username or password, 409 when the username is taken.
|
|
110
|
+
*/
|
|
111
|
+
createUser(input: NewAdminUserInput): Promise<AdminUserRecord>;
|
|
112
|
+
/**
|
|
113
|
+
* Reads an account.
|
|
114
|
+
* @param userId The account id.
|
|
115
|
+
* @returns The stored account, or null.
|
|
116
|
+
*/
|
|
117
|
+
getUser(userId: string): Promise<StoredDocument<AdminUserRecord> | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Finds an account by username.
|
|
120
|
+
* @param username The username (any case).
|
|
121
|
+
* @returns The stored account, or null.
|
|
122
|
+
*/
|
|
123
|
+
findByUsername(username: string): Promise<StoredDocument<AdminUserRecord> | null>;
|
|
124
|
+
/**
|
|
125
|
+
* The first sign-in step (DR §7.2 step 1): the address limit, the account state and the password.
|
|
126
|
+
* @param request The username and password.
|
|
127
|
+
* @param context Where the sign-in comes from.
|
|
128
|
+
* @returns The next step (second factor or enrolment).
|
|
129
|
+
* @throws AdminRequestError 429 for a noisy address, 423 for a locked account, 401 for wrong credentials.
|
|
130
|
+
*/
|
|
131
|
+
beginSignIn(request: SignInRequest, context: SignInContext): Promise<SignInStepView>;
|
|
132
|
+
/**
|
|
133
|
+
* Offers an authenticator secret to a sign-in that must enrol one (the only answer that shows a secret).
|
|
134
|
+
* @param pendingToken The pending sign-in.
|
|
135
|
+
* @returns The secret and its otpauth URI.
|
|
136
|
+
* @throws AdminRequestError 401 for an unknown or expired sign-in.
|
|
137
|
+
*/
|
|
138
|
+
beginEnrolment(pendingToken: string): Promise<TotpEnrolmentView>;
|
|
139
|
+
/**
|
|
140
|
+
* Confirms an enrolment with a code from the new secret and signs in (DR §7.2 step 3).
|
|
141
|
+
* @param pendingToken The pending sign-in.
|
|
142
|
+
* @param code The authenticator code.
|
|
143
|
+
* @param context Where the sign-in comes from.
|
|
144
|
+
* @returns The session and the account's new recovery codes.
|
|
145
|
+
* @throws AdminRequestError 401 for an unknown sign-in or a wrong code.
|
|
146
|
+
*/
|
|
147
|
+
completeEnrolment(pendingToken: string, code: string, context: SignInContext): Promise<SignInResult>;
|
|
148
|
+
/**
|
|
149
|
+
* Checks the second factor of a sign-in and signs in (DR §7.2 step 3).
|
|
150
|
+
* @param pendingToken The pending sign-in.
|
|
151
|
+
* @param proof An authenticator code or a recovery code.
|
|
152
|
+
* @param context Where the sign-in comes from.
|
|
153
|
+
* @returns The session.
|
|
154
|
+
* @throws AdminRequestError 401 for an unknown sign-in or a wrong, reused code.
|
|
155
|
+
*/
|
|
156
|
+
completeSecondFactor(pendingToken: string, proof: SecondFactorProof, context: SignInContext): Promise<SignInResult>;
|
|
157
|
+
/**
|
|
158
|
+
* Starts the second-factor step of a single sign-on whose provider gave no multi-factor proof (D26): the account's
|
|
159
|
+
* authenticator code is asked, or enrolled when it has none.
|
|
160
|
+
* @param user The account the provider signed in.
|
|
161
|
+
* @returns The step answer with its pending token.
|
|
162
|
+
*/
|
|
163
|
+
startSingleSignOnSecondFactor(user: AdminUserRecord): Promise<SignInStepView>;
|
|
164
|
+
/**
|
|
165
|
+
* Signs in an account whose sign-in already proved both factors: a single sign-on with a multi-factor proof (D26) or
|
|
166
|
+
* a user-verified passkey (D31).
|
|
167
|
+
* @param userId The account.
|
|
168
|
+
* @param context Where the sign-in comes from.
|
|
169
|
+
* @returns The session.
|
|
170
|
+
* @throws AdminRequestError 404 for an unknown account, 423 for a locked one, 401 for a disabled one.
|
|
171
|
+
*/
|
|
172
|
+
signInVerified(userId: string, context: SignInContext): Promise<SignInResult>;
|
|
173
|
+
/**
|
|
174
|
+
* Completes a password sign-in with a passkey as its second factor (D31).
|
|
175
|
+
* @param pendingToken The pending sign-in of the password step.
|
|
176
|
+
* @param userId The account the passkey belongs to.
|
|
177
|
+
* @param context Where the sign-in comes from.
|
|
178
|
+
* @returns The session.
|
|
179
|
+
* @throws AdminRequestError 401 for an unknown or expired sign-in or a passkey of another account.
|
|
180
|
+
*/
|
|
181
|
+
completeSecondFactorWithPasskey(pendingToken: string, userId: string, context: SignInContext): Promise<SignInResult>;
|
|
182
|
+
/**
|
|
183
|
+
* Re-checks the second factor of a signed-in admin, so dangerous actions are allowed for STEP_UP_WINDOW_MS.
|
|
184
|
+
* @param caller The signed-in caller.
|
|
185
|
+
* @param proof An authenticator code or a recovery code.
|
|
186
|
+
* @returns The session with its new secondFactorAt.
|
|
187
|
+
* @throws AdminRequestError 401 for a wrong code or a caller without a session.
|
|
188
|
+
*/
|
|
189
|
+
stepUp(caller: AdminCaller, proof: SecondFactorProof): Promise<ConsoleSessionRecord>;
|
|
190
|
+
/**
|
|
191
|
+
* Changes a signed-in admin's password.
|
|
192
|
+
* @param userId The account.
|
|
193
|
+
* @param currentPassword The current password.
|
|
194
|
+
* @param newPassword The new password.
|
|
195
|
+
* @throws AdminRequestError 401 for a wrong current password, 400 for a weak new one.
|
|
196
|
+
*/
|
|
197
|
+
changePassword(userId: string, currentPassword: string, newPassword: string): Promise<void>;
|
|
198
|
+
/**
|
|
199
|
+
* Sets a new password without the old one (CLI recovery, admin reset).
|
|
200
|
+
* @param stored The account.
|
|
201
|
+
* @param newPassword The new password.
|
|
202
|
+
* @throws AdminRequestError 400 for a weak password.
|
|
203
|
+
*/
|
|
204
|
+
setPassword(stored: StoredDocument<AdminUserRecord>, newPassword: string): Promise<void>;
|
|
205
|
+
/**
|
|
206
|
+
* Replaces an account's recovery codes.
|
|
207
|
+
* @param userId The account.
|
|
208
|
+
* @returns The new codes (shown once).
|
|
209
|
+
*/
|
|
210
|
+
regenerateRecoveryCodes(userId: string): Promise<string[]>;
|
|
211
|
+
/**
|
|
212
|
+
* Saves an account's console preferences.
|
|
213
|
+
* @param userId The account.
|
|
214
|
+
* @param preferences The preferences.
|
|
215
|
+
* @returns The stored account.
|
|
216
|
+
*/
|
|
217
|
+
updatePreferences(userId: string, preferences: AdminPreferences): Promise<StoredDocument<AdminUserRecord>>;
|
|
218
|
+
/**
|
|
219
|
+
* Clears an account's lock and failure count.
|
|
220
|
+
* @param userId The account.
|
|
221
|
+
*/
|
|
222
|
+
unlock(userId: string): Promise<void>;
|
|
223
|
+
/**
|
|
224
|
+
* Removes an account's authenticator and recovery codes; its next sign-in enrols a new one.
|
|
225
|
+
* @param userId The account.
|
|
226
|
+
*/
|
|
227
|
+
resetSecondFactor(userId: string): Promise<void>;
|
|
228
|
+
/**
|
|
229
|
+
* The console's view of an account (never its secrets).
|
|
230
|
+
* @param stored The stored account.
|
|
231
|
+
* @returns The view.
|
|
232
|
+
*/
|
|
233
|
+
toUserView(stored: StoredDocument<AdminUserRecord>): AdminUserView;
|
|
234
|
+
/**
|
|
235
|
+
* Whether an account is locked now.
|
|
236
|
+
* @param user The account.
|
|
237
|
+
* @returns True while lockedUntil is in the future.
|
|
238
|
+
*/
|
|
239
|
+
isLocked(user: AdminUserRecord): boolean;
|
|
240
|
+
/**
|
|
241
|
+
* Checks a second factor against an account.
|
|
242
|
+
* @param user The account.
|
|
243
|
+
* @param proof A code (its step must be newer than lastUsedTotpStep) or a recovery code (used up).
|
|
244
|
+
* @returns The account with the code recorded as used, or null when the proof is wrong.
|
|
245
|
+
*/
|
|
246
|
+
private applySecondFactor;
|
|
247
|
+
/**
|
|
248
|
+
* Ends a sign-in: stores the account, creates the session, deletes the pending record and clears the failures.
|
|
249
|
+
* @param pendingId The pending sign-in document id, or null for a sign-in without one.
|
|
250
|
+
* @param stored The account as read.
|
|
251
|
+
* @param updated The account with the used code recorded.
|
|
252
|
+
* @param context Where the sign-in comes from.
|
|
253
|
+
* @param recoveryCodes New recovery codes to show, or none.
|
|
254
|
+
* @returns The session.
|
|
255
|
+
*/
|
|
256
|
+
private finishSignIn;
|
|
257
|
+
/**
|
|
258
|
+
* Stores a sign-in waiting for its second factor.
|
|
259
|
+
* @param user The account.
|
|
260
|
+
* @param stage What it waits for.
|
|
261
|
+
* @param viaSingleSignOn True when the first factor was a single sign-on.
|
|
262
|
+
* @returns The step answer with the pending token.
|
|
263
|
+
*/
|
|
264
|
+
private startPendingSignIn;
|
|
265
|
+
/**
|
|
266
|
+
* Reads a live pending sign-in of a stage.
|
|
267
|
+
* @param pendingToken The token.
|
|
268
|
+
* @param stage The stage the call needs, or null for either stage.
|
|
269
|
+
* @returns The stored pending sign-in.
|
|
270
|
+
* @throws AdminRequestError 401 when it is unknown, expired or at another stage.
|
|
271
|
+
*/
|
|
272
|
+
private requirePendingSignIn;
|
|
273
|
+
/**
|
|
274
|
+
* Reads an account that must exist.
|
|
275
|
+
* @param userId The account id.
|
|
276
|
+
* @returns The stored account.
|
|
277
|
+
* @throws AdminRequestError 404 when it does not exist.
|
|
278
|
+
*/
|
|
279
|
+
private requireUser;
|
|
280
|
+
/**
|
|
281
|
+
* Reads an account that may sign in now.
|
|
282
|
+
* @param userId The account id.
|
|
283
|
+
* @returns The stored account.
|
|
284
|
+
* @throws AdminRequestError 404 when it does not exist, 401 when it is disabled, 423 while it is locked.
|
|
285
|
+
*/
|
|
286
|
+
private requireUsableUser;
|
|
287
|
+
/**
|
|
288
|
+
* Counts a failed sign-in for the address and the account, locks the account at ACCOUNT_LOCKOUT_FAILURES, then waits
|
|
289
|
+
* the growing failure delay (DR §7.2).
|
|
290
|
+
* @param user The account, or null for an unknown username.
|
|
291
|
+
* @param clientAddress The client address.
|
|
292
|
+
*/
|
|
293
|
+
private recordFailure;
|
|
294
|
+
/**
|
|
295
|
+
* Locks an account for ACCOUNT_LOCKOUT_WINDOW_MS and tells the lockout listener.
|
|
296
|
+
* @param user The account.
|
|
297
|
+
* @param clientAddress The address of the last failure.
|
|
298
|
+
*/
|
|
299
|
+
private lock;
|
|
300
|
+
/**
|
|
301
|
+
* Adds one failure to a counter, dropping failures older than the lockout window.
|
|
302
|
+
* @param failureId "account:<userId>" or "address:<address>".
|
|
303
|
+
* @returns The failures within the window, this one included.
|
|
304
|
+
*/
|
|
305
|
+
private addFailure;
|
|
306
|
+
/**
|
|
307
|
+
* The failures of a counter within the lockout window.
|
|
308
|
+
* @param failureId The counter.
|
|
309
|
+
* @returns How many.
|
|
310
|
+
*/
|
|
311
|
+
private recentFailures;
|
|
312
|
+
/**
|
|
313
|
+
* Keeps the failure times within ACCOUNT_LOCKOUT_WINDOW_MS.
|
|
314
|
+
* @param failures ISO times.
|
|
315
|
+
* @param now The current time, in milliseconds.
|
|
316
|
+
* @returns The recent ones.
|
|
317
|
+
*/
|
|
318
|
+
private withinWindow;
|
|
319
|
+
/**
|
|
320
|
+
* Waits on the admin clock.
|
|
321
|
+
* @param milliseconds How long.
|
|
322
|
+
* @returns Resolves after the wait.
|
|
323
|
+
*/
|
|
324
|
+
private delay;
|
|
325
|
+
/**
|
|
326
|
+
* @returns The clock's now as an ISO time.
|
|
327
|
+
*/
|
|
328
|
+
private nowIso;
|
|
329
|
+
}
|