Skip to content

Commit bae7550

Browse files
committed
feat: add PasswordLogin
1 parent 813bec0 commit bae7550

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,15 @@ client.v1
6262
.then((response) => {
6363
console.log("PasswordlessLogin Response:", response);
6464
});
65+
66+
client.v1
67+
.PasswordLogin({
68+
data: {
69+
minimumPrivilegeLevel: PrivilegeLevel.NotAuthenticated,
70+
password: "your-password",
71+
},
72+
})
73+
.then((response) => {
74+
console.log("PasswordLogin Response:", response);
75+
});
6576
```

src/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export type {
1818
InsufficientScopeErrorResponse,
1919
InvalidTokenErrorResponse,
2020
MissingParamsErrorResponse,
21+
PasswordLoginRequest,
22+
PasswordLoginResponse,
23+
PasswordLoginResponseData,
2124
PasswordlessLoginRequest,
2225
PasswordlessLoginResponse,
2326
PasswordlessLoginResponseData,
@@ -26,4 +29,5 @@ export type {
2629
QueryServerStateResponseData,
2730
VerifyAuthenticationTokenRequest,
2831
VerifyAuthenticationTokenResponse,
32+
WrongPasswordErrorResponse,
2933
} from "./v1/index.js";

src/v1/PasswordLogin.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type {
2+
ApiRequest,
3+
ApiSuccessResponse,
4+
PrivilegeLevel,
5+
} from "./common.js";
6+
import { buildApiRequest } from "./common.js";
7+
8+
export type PasswordLoginRequest = ApiRequest<
9+
"PasswordLogin",
10+
{
11+
/**
12+
* Minimum privilege level to attempt to acquire by logging in.
13+
*/
14+
minimumPrivilegeLevel: `${PrivilegeLevel}`;
15+
/**
16+
* Password to attempt to log in with, in plaintext.
17+
*/
18+
password: string;
19+
}
20+
>;
21+
22+
export type PasswordLoginResponseData = {
23+
/**
24+
* Authentication Token in case login is successful.
25+
*/
26+
authenticationToken: string;
27+
};
28+
29+
export type PasswordLoginResponse =
30+
ApiSuccessResponse<PasswordLoginResponseData>;
31+
32+
export const buildPasswordLogin = buildApiRequest<
33+
PasswordLoginRequest,
34+
PasswordLoginResponse
35+
>("v1", {
36+
function: "PasswordLogin",
37+
});

src/v1/error.ts

+5
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ export interface MissingParamsErrorResponse extends ErrorResponse {
3030
invalidParameters: Record<string, unknown>;
3131
};
3232
}
33+
34+
export interface WrongPasswordErrorResponse extends ErrorResponse {
35+
errorCode: "wrong_password";
36+
errorMessage: string;
37+
}

src/v1/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { buildGetAdvancedGameSettings } from "./GetAdvancedGameSettings.js";
33
import { buildGetServerOptions } from "./GetServerOptions.js";
44
import { buildHealthCheck } from "./HealthCheck.js";
55
import { buildPasswordlessLogin } from "./PasswordlessLogin.js";
6+
import { buildPasswordLogin } from "./PasswordLogin.js";
67
import { buildQueryServerState } from "./QueryServerState.js";
78
import { buildVerifyAuthenticationToken } from "./VerifyAuthenticationToken.js";
89

@@ -28,6 +29,12 @@ export function buildV1(options: InternalClientOptions) {
2829
* This function requires no Authentication.
2930
*/
3031
PasswordlessLogin: buildPasswordlessLogin(options),
32+
/**
33+
* Attempts to log in to the Dedicated Server as a player using either Admin Password or Client Protection Password.
34+
*
35+
* This function requires no Authentication.
36+
*/
37+
PasswordLogin: buildPasswordLogin(options),
3138
/**
3239
* Retrieves the current state of the Dedicated Server.
3340
*/
@@ -49,5 +56,6 @@ export type * from "./GetAdvancedGameSettings.js";
4956
export type * from "./GetServerOptions.js";
5057
export type * from "./HealthCheck.js";
5158
export type * from "./PasswordlessLogin.js";
59+
export type * from "./PasswordLogin.js";
5260
export type * from "./QueryServerState.js";
5361
export type * from "./VerifyAuthenticationToken.js";

test.js

+11
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,14 @@ client.v1
4343
.then((response) => {
4444
console.log("PasswordlessLogin Response:", response);
4545
});
46+
47+
client.v1
48+
.PasswordLogin({
49+
data: {
50+
minimumPrivilegeLevel: PrivilegeLevel.NotAuthenticated,
51+
password: "your-password",
52+
},
53+
})
54+
.then((response) => {
55+
console.log("PasswordLogin Response:", response);
56+
});

0 commit comments

Comments
 (0)