Replace legacy checkBodyType with Zod

Start matchmaking integration
Start rooms API
Move existing room scene locations to roomtypes file
Auth checkExpired util for client refreshing
This commit is contained in:
2025-03-25 21:54:08 -04:00
parent de3d653446
commit 463e3ef71b
14 changed files with 287 additions and 110 deletions

View File

@@ -4,6 +4,7 @@ import Profile from "../../data/profiles.ts";
import { decode } from "@gz/jwt";
import { Config } from "../../config.ts";
import Logging from "@proxnet/undead-logging";
import { z } from "zod";
const config = Config.getConfig();
@@ -35,6 +36,35 @@ interface RefreshRequest extends AuthBodyBase {
type TokenRequestBody = TokenRequest | RefreshRequest;
const AuthBodyBaseSchema = z.object({
grant_type: z.string(),
client_id: z.string(),
client_secret: z.string(),
platform: z.string(),
platform_id: z.string(),
device_id: z.string(),
device_class: z.string(),
time: z.string(),
ver: z.string(),
asid: z.string(),
platform_auth: z.string(),
});
const TokenRequestSchema = AuthBodyBaseSchema.extend({
grant_type: z.literal('cached_login'),
account_id: z.string(),
});
const RefreshRequestSchema = AuthBodyBaseSchema.extend({
grant_type: z.literal('refresh_token'),
refresh_token: z.string(),
});
const TokenRequestBodySchema = z.discriminatedUnion('grant_type', [
TokenRequestSchema,
RefreshRequestSchema,
]);
interface TokenResponseBody {
error?: string;
error_description?: string;
@@ -47,19 +77,7 @@ route.router.post("/token",
APIUtils.Authentication,
express.urlencoded({ extended: true }),
APIUtils.logBody,
APIUtils.checkBodyTypes<AuthBodyBase>({
grant_type: "",
client_id: "",
client_secret: "",
platform: "",
platform_id: "",
device_id: "",
device_class: "",
time: "",
ver: "",
asid: "",
platform_auth: ""
}),
APIUtils.validateRequestBody<AuthBodyBase>(TokenRequestBodySchema),
async (
rq: express.Request<NoBody, NoBody, TokenRequestBody>,