Update CurrentUser type

This commit is contained in:
Ellie
2025-12-10 00:25:07 +00:00
parent 8cae29d035
commit 10dbc366eb
18 changed files with 90 additions and 85 deletions

View File

@@ -67,7 +67,7 @@ export interface AccountLoginParameter {
/** /v3/Account/Login */
export interface AccountLogin {
user: CurrentUser;
user: CurrentUser<true>;
webApiServerCredential: {
accessToken: string;
expiresIn: number;
@@ -83,9 +83,7 @@ export type AccountToken = AccountLogin;
/** /v4/Account/Login */
export interface AccountLogin_4 {
user: Exclude<CurrentUser, 'links'> & {
links: Exclude<CurrentUser['links'], 'nintendoAccount'>;
};
user: CurrentUser<false>;
webApiServerCredential: {
accessToken: string;
expiresIn: number;
@@ -377,7 +375,7 @@ export interface User {
}
/** /v4/User/ShowSelf */
export interface CurrentUser {
export interface CurrentUser<WithNintendoAccount extends boolean = true> {
id: number;
nsaId: string;
imageUri: string;
@@ -386,17 +384,12 @@ export interface CurrentUser {
supportId: string;
isChildRestricted: boolean;
etag: string;
links: {
nintendoAccount: {
membership: {
active: boolean;
};
};
friendCode: {
regenerable: boolean;
regenerableAt: number;
id: string;
};
links: (boolean extends WithNintendoAccount ? {
nintendoAccount?: CurrentUserNintendoAccountLink;
} : true extends WithNintendoAccount ? {
nintendoAccount: CurrentUserNintendoAccountLink;
} : {}) & {
friendCode: CurrentUserFriendCodeLink;
};
permissions: {
playLog: PlayLogPermissions;
@@ -406,6 +399,17 @@ export interface CurrentUser {
presence: PresenceOnline_4 | PresenceOffline;
}
export interface CurrentUserNintendoAccountLink {
membership: {
active: boolean;
};
}
export interface CurrentUserFriendCodeLink {
regenerable: boolean;
regenerableAt: number;
id: string;
}
export enum PlayLogPermissions {
EVERYONE = 'EVERYONE',
FRIENDS = 'FRIENDS',

View File

@@ -63,7 +63,7 @@ export interface CoralApiInterface {
getEvent(id: number): Promise<Result<Event>>;
getUser(id: number): Promise<Result<User>>;
getUserByFriendCode(friend_code: string, hash?: string): Promise<Result<FriendCodeUser>>;
getCurrentUser(): Promise<Result<CurrentUser>>;
getCurrentUser(): Promise<Result<CurrentUser<true> | CurrentUser<false>>>;
getReceivedFriendRequests(): Promise<Result<ReceivedFriendRequests>>;
getSentFriendRequests(): Promise<Result<SentFriendRequests>>;
getFriendCodeUrl(): Promise<Result<FriendCodeUrl>>;
@@ -260,7 +260,7 @@ export abstract class AbstractCoralApi {
});
}
abstract getCurrentUser(): Promise<Result<CurrentUser>>;
abstract getCurrentUser(): Promise<Result<CurrentUser<true> | CurrentUser<false>>>;
async getFriendCodeUrl() {
return this.call<FriendCodeUrl>('/v3/Friend/CreateFriendCodeUrl', {
@@ -502,7 +502,7 @@ export default class CoralApi extends AbstractCoralApi implements CoralApiInterf
}
async getCurrentUser() {
return this.call<CurrentUser, {id: number}>('/v4/User/ShowSelf', {
return this.call<CurrentUser<true>, {id: number}>('/v4/User/ShowSelf', {
id: this[CoralUserIdSymbol],
});
}

View File

@@ -175,7 +175,7 @@ export default class ZncProxyApi extends AbstractCoralApi implements CoralApiInt
// }
async getCurrentUser() {
const result = await this.fetchProxyApi<{user: CurrentUser}>('user');
const result = await this.fetchProxyApi<{user: CurrentUser<true> | CurrentUser<false>}>('user');
return createResult(result, result.user);
}
@@ -338,7 +338,7 @@ export async function getPresenceFromUrl(presence_url: string, useragent?: strin
const data = await response.json() as PresenceUrlResponse;
const user: CurrentUser | Friend | Friend_4 | undefined =
const user: CurrentUser<true> | CurrentUser<false> | Friend | Friend_4 | undefined =
'user' in data ? data.user :
'friend' in data ? data.friend :
'nsaId' in data ? data :