diff --git a/src/api/coral.ts b/src/api/coral.ts index e2b4120..40b9db9 100644 --- a/src/api/coral.ts +++ b/src/api/coral.ts @@ -240,8 +240,8 @@ export default class CoralApi { nintendoAccountToken, // user, f: fdata, - nsoAccount: data.result, - credential: data.result.webApiServerCredential, + nsoAccount: data, + credential: data.webApiServerCredential, }; } diff --git a/src/api/nooklink.ts b/src/api/nooklink.ts index d27afea..dd3fda8 100644 --- a/src/api/nooklink.ts +++ b/src/api/nooklink.ts @@ -83,7 +83,7 @@ export default class NooklinkApi { static async loginWithCoral(nso: CoralApi, user: NintendoAccountUser) { const webserviceToken = await nso.getWebServiceToken(NOOKLINK_WEBSERVICE_ID); - return this.loginWithWebServiceToken(webserviceToken.result, user); + return this.loginWithWebServiceToken(webserviceToken, user); } static async loginWithWebServiceToken( diff --git a/src/api/splatnet2.ts b/src/api/splatnet2.ts index d6aa6a8..54aae0c 100644 --- a/src/api/splatnet2.ts +++ b/src/api/splatnet2.ts @@ -262,7 +262,7 @@ ${colour} static async loginWithCoral(nso: CoralApi, user: NintendoAccountUser) { const webserviceToken = await nso.getWebServiceToken(SPLATNET2_WEBSERVICE_ID); - return this.loginWithWebServiceToken(webserviceToken.result, user); + return this.loginWithWebServiceToken(webserviceToken, user); } static async loginWithWebServiceToken( diff --git a/src/app/main/ipc.ts b/src/app/main/ipc.ts index 662530d..b70a21c 100644 --- a/src/app/main/ipc.ts +++ b/src/app/main/ipc.ts @@ -15,8 +15,8 @@ import { getDiscordRpcClients } from '../../discord/rpc.js'; import { defaultTitle } from '../../discord/titles.js'; import type { FriendProps } from '../browser/friend/index.js'; import type { DiscordSetupProps } from '../browser/discord/index.js'; +import type { AddFriendProps } from '../browser/add-friend/index.js'; import { EmbeddedPresenceMonitor } from './monitor.js'; -import { AddFriendProps } from '../browser/add-friend/index.js'; const debug = createDebug('app:main:ipc'); @@ -79,8 +79,8 @@ export function setupIpc(appinstance: App, ipcMain: IpcMain) { }, {compact: true}), })))); ipcMain.handle('nxapi:coral:activeevent', (e, token: string) => store.users.get(token).then(u => u.getActiveEvent())); - ipcMain.handle('nxapi:coral:friendcodeurl', (e, token: string) => store.users.get(token).then(u => u.nso.getFriendCodeUrl()).then(r => r.result)); - ipcMain.handle('nxapi:coral:friendcode', (e, token: string, friendcode: string, hash?: string) => store.users.get(token).then(u => u.nso.getUserByFriendCode(friendcode, hash)).then(r => r.result)); + ipcMain.handle('nxapi:coral:friendcodeurl', (e, token: string) => store.users.get(token).then(u => u.nso.getFriendCodeUrl())); + ipcMain.handle('nxapi:coral:friendcode', (e, token: string, friendcode: string, hash?: string) => store.users.get(token).then(u => u.nso.getUserByFriendCode(friendcode, hash))); ipcMain.handle('nxapi:coral:addfriend', (e, token: string, nsaid: string) => store.users.get(token).then(u => u.addFriend(nsaid))); ipcMain.handle('nxapi:window:showpreferences', () => appinstance.showPreferencesWindow().id); diff --git a/src/app/main/menu.ts b/src/app/main/menu.ts index d2551b2..5209ce5 100644 --- a/src/app/main/menu.ts +++ b/src/app/main/menu.ts @@ -162,7 +162,7 @@ export default class MenuApp { const {nso, data} = await this.app.store.users.get(token); const webservices = await nso.getWebServices(); - return this.webservices = webservices.result; + return this.webservices = webservices; } async getWebServiceItems(token: string) { diff --git a/src/app/main/webservices.ts b/src/app/main/webservices.ts index 1ac93c1..eab4d11 100644 --- a/src/app/main/webservices.ts +++ b/src/app/main/webservices.ts @@ -103,7 +103,7 @@ export default async function openWebService( window.loadURL(url.toString(), { extraHeaders: Object.entries({ 'x-appcolorscheme': nativeTheme.shouldUseDarkColors ? 'DARK' : 'LIGHT', - 'x-gamewebtoken': webserviceToken.result.accessToken, + 'x-gamewebtoken': webserviceToken.accessToken, 'dnt': '1', 'X-Requested-With': 'com.nintendo.znca', }).map(([key, value]) => key + ': ' + value).join('\n'), @@ -283,7 +283,7 @@ export class WebServiceIpc { const webserviceToken = await nso.getWebServiceToken('' + webservice.id); - return webserviceToken.result.accessToken; + return webserviceToken.accessToken; } async restorePersistentData(event: IpcMainInvokeEvent): Promise { diff --git a/src/cli/nso/active-event.ts b/src/cli/nso/active-event.ts index c68a7ee..1ad0722 100644 --- a/src/cli/nso/active-event.ts +++ b/src/cli/nso/active-event.ts @@ -43,17 +43,17 @@ export async function handler(argv: ArgumentsCamelCase) { const friends = await nso.getFriendList(); const activeevent = await nso.getActiveEvent(); - if ('id' in activeevent.result) { + if ('id' in activeevent) { if (argv.jsonPrettyPrint) { - console.log(JSON.stringify(activeevent.result, null, 4)); + console.log(JSON.stringify(activeevent, null, 4)); return; } if (argv.json) { - console.log(JSON.stringify(activeevent.result)); + console.log(JSON.stringify(activeevent)); return; } - console.log('Active event', activeevent.result); + console.log('Active event', activeevent); } else { if (argv.json || argv.jsonPrettyPrint) { console.log('null'); diff --git a/src/cli/nso/add-friend.ts b/src/cli/nso/add-friend.ts index 43716ea..e81e0cd 100644 --- a/src/cli/nso/add-friend.ts +++ b/src/cli/nso/add-friend.ts @@ -39,9 +39,9 @@ export async function handler(argv: ArgumentsCamelCase) { // Friend code const user = await nso.getUserByFriendCode(argv.id); - nsa_id = user.result.nsaId; + nsa_id = user.nsaId; - console.log('User', user.result); + console.log('User', user); } else if (/^[0-9a-f]{16}$/.test(argv.id)) { // NSA ID nsa_id = argv.id; diff --git a/src/cli/nso/announcements.ts b/src/cli/nso/announcements.ts index 03ab741..0384de4 100644 --- a/src/cli/nso/announcements.ts +++ b/src/cli/nso/announcements.ts @@ -44,11 +44,11 @@ export async function handler(argv: ArgumentsCamelCase) { const activeevent = await nso.getActiveEvent(); if (argv.jsonPrettyPrint) { - console.log(JSON.stringify(announcements.result, null, 4)); + console.log(JSON.stringify(announcements, null, 4)); return; } if (argv.json) { - console.log(JSON.stringify(announcements.result)); + console.log(JSON.stringify(announcements)); return; } @@ -62,7 +62,7 @@ export async function handler(argv: ArgumentsCamelCase) { ], }); - for (const announcement of announcements.result) { + for (const announcement of announcements) { table.push([ announcement.announcementId, announcement.title.substr(0, 60), diff --git a/src/cli/nso/friendcode.ts b/src/cli/nso/friendcode.ts index 37835fe..65734d4 100644 --- a/src/cli/nso/friendcode.ts +++ b/src/cli/nso/friendcode.ts @@ -45,14 +45,14 @@ export async function handler(argv: ArgumentsCamelCase) { const friendcodeurl = await nso.getFriendCodeUrl(); if (argv.jsonPrettyPrint) { - console.log(JSON.stringify(friendcodeurl.result, null, 4)); + console.log(JSON.stringify(friendcodeurl, null, 4)); return; } if (argv.json) { - console.log(JSON.stringify(friendcodeurl.result)); + console.log(JSON.stringify(friendcodeurl)); return; } - console.warn('Friend code', friendcodeurl.result); - console.log(friendcodeurl.result.url); + console.warn('Friend code', friendcodeurl); + console.log(friendcodeurl.url); } diff --git a/src/cli/nso/friends.ts b/src/cli/nso/friends.ts index 8345b96..5b88496 100644 --- a/src/cli/nso/friends.ts +++ b/src/cli/nso/friends.ts @@ -49,17 +49,17 @@ export async function handler(argv: ArgumentsCamelCase) { const friends = await nso.getFriendList(); if (argv.jsonPrettyPrint) { - console.log(JSON.stringify(friends.result.friends, null, 4)); + console.log(JSON.stringify(friends.friends, null, 4)); return; } if (argv.json) { - console.log(JSON.stringify(friends.result.friends)); + console.log(JSON.stringify(friends.friends)); return; } const table = new Table({ head: [ - 'ID', + 'Coral ID', 'NSA ID', 'Name', 'Status', @@ -68,7 +68,7 @@ export async function handler(argv: ArgumentsCamelCase) { ], }); - for (const friend of friends.result.friends) { + for (const friend of friends.friends) { const online = friend.presence.state === PresenceState.ONLINE || friend.presence.state === PresenceState.PLAYING; diff --git a/src/cli/nso/http-server.ts b/src/cli/nso/http-server.ts index abe8b88..50ab798 100644 --- a/src/cli/nso/http-server.ts +++ b/src/cli/nso/http-server.ts @@ -279,12 +279,10 @@ function createApp( try { const announcements = await req.znc!.getAnnouncements(); - cached_announcements = announcements.result; + cached_announcements = announcements; res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify({ - announcements: announcements.result, - })); + res.end(JSON.stringify({announcements})); } catch (err) { res.statusCode = 500; res.setHeader('Content-Type', 'application/json'); @@ -313,7 +311,7 @@ function createApp( try { const promise = user_data_promise.get(req.zncAuth!.user.id) ?? req.znc!.getCurrentUser().then(user => { - cached_userdata.set(req.zncAuth!.user.id, [user.result, Date.now()]); + cached_userdata.set(req.zncAuth!.user.id, [user, Date.now()]); }).finally(() => { user_data_promise.delete(req.zncAuth!.user.id); }); @@ -375,7 +373,7 @@ function createApp( try { const promise = friends_data_promise.get(req.zncAuth!.user.id) ?? req.znc!.getFriendList().then(friends => { - cached_friendsdata.set(req.zncAuth!.user.id, [friends.result.friends, Date.now()]); + cached_friendsdata.set(req.zncAuth!.user.id, [friends.friends, Date.now()]); }).finally(() => { friends_data_promise.delete(req.zncAuth!.user.id); }); @@ -403,7 +401,7 @@ function createApp( try { const friends_promise = friends_data_promise.get(req.zncAuth!.user.id) ?? req.znc!.getFriendList().then(friends => { - cached_friendsdata.set(req.zncAuth!.user.id, [friends.result.friends, Date.now()]); + cached_friendsdata.set(req.zncAuth!.user.id, [friends.friends, Date.now()]); }).finally(() => { friends_data_promise.delete(req.zncAuth!.user.id); }); @@ -415,7 +413,7 @@ function createApp( req.znc!.getActiveEvent(), ]).then(([friends, webservices, activeevent]) => { // Friends list was already added to cache - cached_appdata.set(req.zncAuth!.user.id, [webservices.result, activeevent.result, Date.now()]); + cached_appdata.set(req.zncAuth!.user.id, [webservices, activeevent, Date.now()]); }).finally(() => { app_data_promise.delete(req.zncAuth!.user.id); }); @@ -629,12 +627,10 @@ function createApp( app.get('/api/znc/webservice/:id/token', nsoAuth, async (req, res) => { try { - const response = await req.znc!.getWebServiceToken(req.params.id); + const token = await req.znc!.getWebServiceToken(req.params.id); res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify({ - token: response.result, - })); + res.end(JSON.stringify({token})); } catch (err) { res.statusCode = 500; res.setHeader('Content-Type', 'application/json'); @@ -659,12 +655,10 @@ function createApp( app.get('/api/znc/event/:id', nsoAuth, async (req, res) => { try { - const response = await req.znc!.getEvent(parseInt(req.params.id)); + const event = await req.znc!.getEvent(parseInt(req.params.id)); res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify({ - event: response.result, - })); + res.end(JSON.stringify({event})); } catch (err) { res.statusCode = 500; res.setHeader('Content-Type', 'application/json'); @@ -681,12 +675,10 @@ function createApp( throw new Error('Invalid user ID'); } - const response = await req.znc!.getUser(parseInt(req.params.id)); + const user = await req.znc!.getUser(parseInt(req.params.id)); res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify({ - user: response.result, - })); + res.end(JSON.stringify({user})); } catch (err) { res.statusCode = 500; res.setHeader('Content-Type', 'application/json'); @@ -735,7 +727,7 @@ function createApp( throw err; }).then(user => { const cache = cached_friendcode_data.get(req.zncAuth!.user.id) ?? new Map(); - cache.set(req.params.friendcode, [user?.result ?? null, Date.now()]); + cache.set(req.params.friendcode, [user ?? null, Date.now()]); cached_friendcode_data.set(req.zncAuth!.user.id, cache); }).finally(() => { const promises = friendcode_data_promise.get(req.zncAuth!.user.id); @@ -787,7 +779,7 @@ function createApp( try { const promise = user_friendcodeurl_promise.get(req.zncAuth!.user.id) ?? req.znc!.getFriendCodeUrl().then(user => { - cached_friendcodeurl.set(req.zncAuth!.user.id, [user.result, Date.now()]); + cached_friendcodeurl.set(req.zncAuth!.user.id, [user, Date.now()]); }).finally(() => { user_friendcodeurl_promise.delete(req.zncAuth!.user.id); }); diff --git a/src/cli/nso/lookup.ts b/src/cli/nso/lookup.ts index 2dc3f1d..6d8943a 100644 --- a/src/cli/nso/lookup.ts +++ b/src/cli/nso/lookup.ts @@ -49,13 +49,13 @@ export async function handler(argv: ArgumentsCamelCase) { const user = await nso.getUserByFriendCode(argv.id); if (argv.jsonPrettyPrint) { - console.log(JSON.stringify(user.result, null, 4)); + console.log(JSON.stringify(user, null, 4)); return; } if (argv.json) { - console.log(JSON.stringify(user.result)); + console.log(JSON.stringify(user)); return; } - console.log('User', user.result); + console.log('User', user); } diff --git a/src/cli/nso/permissions.ts b/src/cli/nso/permissions.ts index 108426a..6a131f8 100644 --- a/src/cli/nso/permissions.ts +++ b/src/cli/nso/permissions.ts @@ -54,17 +54,17 @@ export async function handler(argv: ArgumentsCamelCase) { if (argv.presence) { await nso.updateCurrentUserPermissions(argv.presence as PresencePermissions, - permissions.result.permissions.presence, permissions.result.etag); + permissions.permissions.presence, permissions.etag); } else { if (argv.jsonPrettyPrint) { - console.log(JSON.stringify(permissions.result, null, 4)); + console.log(JSON.stringify(permissions, null, 4)); return; } if (argv.json) { - console.log(JSON.stringify(permissions.result)); + console.log(JSON.stringify(permissions)); return; } - console.log('Presence is visible to %s', permissions.result.permissions.presence); + console.log('Presence is visible to %s', permissions.permissions.presence); } } diff --git a/src/cli/nso/user.ts b/src/cli/nso/user.ts index 516b7c7..dfce6b2 100644 --- a/src/cli/nso/user.ts +++ b/src/cli/nso/user.ts @@ -44,7 +44,7 @@ export async function handler(argv: ArgumentsCamelCase) { const user = await nso.getCurrentUser(); console.log('Nintendo Account', data.user); - console.log('Nintendo Switch user', user.result); + console.log('Nintendo Switch user', user); } else { console.log('Nintendo Account', data.user); console.log('Nintendo Switch user', data.nsoAccount.user); diff --git a/src/cli/nso/webservices.ts b/src/cli/nso/webservices.ts index 155254a..4417181 100644 --- a/src/cli/nso/webservices.ts +++ b/src/cli/nso/webservices.ts @@ -47,11 +47,11 @@ export async function handler(argv: ArgumentsCamelCase) { const activeevent = await nso.getActiveEvent(); if (argv.jsonPrettyPrint) { - console.log(JSON.stringify(webservices.result, null, 4)); + console.log(JSON.stringify(webservices, null, 4)); return; } if (argv.json) { - console.log(JSON.stringify(webservices.result)); + console.log(JSON.stringify(webservices)); return; } @@ -63,7 +63,7 @@ export async function handler(argv: ArgumentsCamelCase) { ], }); - for (const webservice of webservices.result) { + for (const webservice of webservices) { table.push([ webservice.id, webservice.name, diff --git a/src/cli/nso/webservicetoken.ts b/src/cli/nso/webservicetoken.ts index fd0eed8..8eadd91 100644 --- a/src/cli/nso/webservicetoken.ts +++ b/src/cli/nso/webservicetoken.ts @@ -47,7 +47,7 @@ export async function handler(argv: ArgumentsCamelCase) { const webservices = await nso.getWebServices(); const activeevent = await nso.getActiveEvent(); - const webservice = webservices.result.find(w => '' + w.id === argv.id); + const webservice = webservices.find(w => '' + w.id === argv.id); if (!webservice) { throw new Error('Invalid web service'); @@ -74,14 +74,14 @@ export async function handler(argv: ArgumentsCamelCase) { if (argv.jsonPrettyPrint) { console.log(JSON.stringify({ webservice, - token: webserviceToken.result, + token: webserviceToken, }, null, 4)); return; } if (argv.json) { console.log(JSON.stringify({ webservice, - token: webserviceToken.result, + token: webserviceToken, })); return; } @@ -89,5 +89,5 @@ export async function handler(argv: ArgumentsCamelCase) { console.log('Web service', { name: webservice.name, url: url.toString(), - }, webserviceToken.result); + }, webserviceToken); } diff --git a/src/cli/util/discord-activity.ts b/src/cli/util/discord-activity.ts index 0d9d3fc..a546b50 100644 --- a/src/cli/util/discord-activity.ts +++ b/src/cli/util/discord-activity.ts @@ -152,10 +152,10 @@ async function getPresenceFromCoral(argv: ArgumentsCamelCase) { const friends = await nso.getFriendList(); const webservices = await nso.getWebServices(); const activeevent = await nso.getActiveEvent(); - const user = 'expires_at' in data ? (await nso.getCurrentUser()).result : data.nsoAccount.user; + const user = 'expires_at' in data ? await nso.getCurrentUser() : data.nsoAccount.user; if (argv.friendNsaid) { - const friend = friends.result.friends.find(f => f.nsaId === argv.friendNsaid); + const friend = friends.friends.find(f => f.nsaId === argv.friendNsaid); if (!friend) { throw new Error('User "' + argv.friendNsaid + '" is not friends with this user'); @@ -164,7 +164,7 @@ async function getPresenceFromCoral(argv: ArgumentsCamelCase) { return [friend.presence, friend] as const; } else { return [user.presence, user, user.links.friendCode, - 'id' in activeevent.result ? activeevent.result : undefined] as const; + 'id' in activeevent ? activeevent : undefined] as const; } } diff --git a/src/common/notify.ts b/src/common/notify.ts index 06c2fa2..9b15929 100644 --- a/src/common/notify.ts +++ b/src/common/notify.ts @@ -1,7 +1,7 @@ import createDebug from 'debug'; import persist from 'node-persist'; import CoralApi from '../api/coral.js'; -import { ActiveEvent, Announcements, CurrentUser, Friend, Game, Presence, PresenceState, WebServices, CoralErrorResponse } from '../api/coral-types.js'; +import { ActiveEvent, Announcements, CurrentUser, Friend, Game, Presence, PresenceState, WebServices, CoralErrorResponse, GetActiveEventResult } from '../api/coral-types.js'; import ZncProxyApi from '../api/znc-proxy.js'; import { ErrorResponse } from '../api/util.js'; import { SavedToken } from './auth/coral.js'; @@ -54,13 +54,13 @@ export class ZncNotifications extends Loop { if (req.includes('announcements')) { result.announcements = this.user ? - (await this.user?.getAnnouncements()) : - (await this.nso.getAnnouncements()).result; + await this.user?.getAnnouncements() : + await this.nso.getAnnouncements(); } if (req.includes('friends') || (friends && !(this.nso instanceof ZncProxyApi))) { result.friends = this.user ? - (await this.user.getFriends()) : - (await this.nso.getFriendList()).result.friends; + await this.user.getFriends() : + (await this.nso.getFriendList()).friends; } else if (friends && this.nso instanceof ZncProxyApi) { result.friends = await Promise.all(friends.map(async r => { const nso = this.nso as unknown as ZncProxyApi; @@ -86,17 +86,17 @@ export class ZncNotifications extends Loop { } if (req.includes('webservices')) { result.webservices = this.user ? - (await this.user.getWebServices()) : - (await this.nso.getWebServices()).result; + await this.user.getWebServices() : + await this.nso.getWebServices(); } if (req.includes('event')) { - const activeevent = this.user ? - (await this.user.getActiveEvent()) : - (await this.nso.getActiveEvent()).result; + const activeevent: GetActiveEventResult = this.user ? + await this.user.getActiveEvent() : + await this.nso.getActiveEvent(); result.activeevent = 'id' in activeevent ? activeevent : undefined; } if (req.includes('user')) { - result.user = (await this.nso.getCurrentUser()).result; + result.user = await this.nso.getCurrentUser(); } return result;