Skip to content

Commit 2243e38

Browse files
committed
feat: add PasswordlessLogin
1 parent 7375fd2 commit 2243e38

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

src/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { createClient } from "./client.js";
22
export type { Client, ClientOptions } from "./client.js";
3+
export { PrivilegeLevel } from "./v1/common.js";
34
export type {
45
ApiRequest,
56
ApiSuccessResponse,
@@ -17,6 +18,9 @@ export type {
1718
InsufficientScopeErrorResponse,
1819
InvalidTokenErrorResponse,
1920
MissingParamsErrorResponse,
21+
PasswordlessLoginRequest,
22+
PasswordlessLoginResponse,
23+
PasswordlessLoginResponseData,
2024
QueryServerStateRequest,
2125
QueryServerStateResponse,
2226
QueryServerStateResponseData,

src/v1/PasswordlessLogin.ts

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

src/v1/common.ts

+23
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,26 @@ export interface InternalClientOptions {
4949
*/
5050
accessToken: string;
5151
}
52+
53+
export enum PrivilegeLevel {
54+
/**
55+
* The client is not Authenticated.
56+
*/
57+
NotAuthenticated = "NotAuthenticated",
58+
/**
59+
* Client is Authenticated with Client privileges.
60+
*/
61+
Client = "Client",
62+
/**
63+
* Client is Authenticated with Admin privileges.
64+
*/
65+
Administrator = "Administrator",
66+
/**
67+
* Client is Authenticated as Initial Admin with privileges to Claim the server.
68+
*/
69+
InitialAdmin = "InitialAdmin",
70+
/**
71+
* Client is Authenticated as Third Party Application.
72+
*/
73+
APIToken = "APIToken",
74+
}

src/v1/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { InternalClientOptions } from "./common.js";
22
import { buildGetAdvancedGameSettings } from "./GetAdvancedGameSettings.js";
33
import { buildGetServerOptions } from "./GetServerOptions.js";
44
import { buildHealthCheck } from "./HealthCheck.js";
5+
import { buildPasswordlessLogin } from "./PasswordlessLogin.js";
56
import { buildQueryServerState } from "./QueryServerState.js";
67
import { buildVerifyAuthenticationToken } from "./VerifyAuthenticationToken.js";
78

@@ -19,6 +20,14 @@ export function buildV1(options: InternalClientOptions) {
1920
* This function does not require input parameters and does not return any data.
2021
*/
2122
VerifyAuthenticationToken: buildVerifyAuthenticationToken(options),
23+
/**
24+
* Attempts to perform a passwordless login to the Dedicated Server as a player.
25+
*
26+
* Passwordless login is possible if the Dedicated Server is not claimed, or if Client Protection Password is not set for the Dedicated Server.
27+
*
28+
* This function requires no Authentication.
29+
*/
30+
PasswordlessLogin: buildPasswordlessLogin(options),
2231
/**
2332
* Retrieves the current state of the Dedicated Server.
2433
*/
@@ -39,5 +48,6 @@ export type * from "./error.js";
3948
export type * from "./GetAdvancedGameSettings.js";
4049
export type * from "./GetServerOptions.js";
4150
export type * from "./HealthCheck.js";
51+
export type * from "./PasswordlessLogin.js";
4252
export type * from "./QueryServerState.js";
4353
export type * from "./VerifyAuthenticationToken.js";

test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22
import { env } from "node:process";
3-
import { createClient } from "./dist/index.js";
3+
import { createClient, PrivilegeLevel } from "./dist/index.js";
44

55
env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
66

@@ -33,3 +33,13 @@ client.v1.GetServerOptions().then((response) => {
3333
client.v1.GetAdvancedGameSettings().then((response) => {
3434
console.log("GetAdvancedGameSettings Response:", response);
3535
});
36+
37+
client.v1
38+
.PasswordlessLogin({
39+
data: {
40+
minimumPrivilegeLevel: PrivilegeLevel.NotAuthenticated,
41+
},
42+
})
43+
.then((response) => {
44+
console.log("PasswordlessLogin Response:", response);
45+
});

0 commit comments

Comments
 (0)