diff --git a/src/api/znc-types.ts b/src/api/coral-types.ts similarity index 94% rename from src/api/znc-types.ts rename to src/api/coral-types.ts index 0bad9ab..f694d5d 100644 --- a/src/api/znc-types.ts +++ b/src/api/coral-types.ts @@ -1,16 +1,16 @@ -export interface ZncSuccessResponse { - status: ZncStatus.OK; +export interface CoralSuccessResponse { + status: CoralStatus.OK; result: T; correlationId: string; } -export interface ZncErrorResponse { - status: ZncStatus | number; +export interface CoralErrorResponse { + status: CoralStatus | number; errorMessage: string; correlationId: string; } -export enum ZncStatus { +export enum CoralStatus { OK = 0, BAD_REQUEST = 9400, @@ -43,7 +43,7 @@ export enum ZncStatus { // UNKNOWN = -1, } -export type ZncResponse = ZncSuccessResponse | ZncErrorResponse; +export type CoralResponse = CoralSuccessResponse | CoralErrorResponse; /** /v3/Account/Login */ export interface AccountLogin { diff --git a/src/api/znc.ts b/src/api/coral.ts similarity index 89% rename from src/api/znc.ts rename to src/api/coral.ts index f5585fe..e411468 100644 --- a/src/api/znc.ts +++ b/src/api/coral.ts @@ -2,12 +2,12 @@ import fetch, { Response } from 'node-fetch'; import { v4 as uuidgen } from 'uuid'; import createDebug from 'debug'; import { f, FlapgIid } from './f.js'; -import { AccountLogin, AccountToken, Announcements, CurrentUser, CurrentUserPermissions, Event, Friends, GetActiveEventResult, PresencePermissions, User, WebServices, WebServiceToken, ZncErrorResponse, ZncResponse, ZncStatus, ZncSuccessResponse } from './znc-types.js'; +import { AccountLogin, AccountToken, Announcements, CurrentUser, CurrentUserPermissions, Event, Friends, GetActiveEventResult, PresencePermissions, User, WebServices, WebServiceToken, CoralErrorResponse, CoralResponse, CoralStatus, CoralSuccessResponse } from './coral-types.js'; import { getNintendoAccountToken, getNintendoAccountUser, NintendoAccountUser } from './na.js'; import { ErrorResponse } from './util.js'; import { JwtPayload } from '../util/jwt.js'; -const debug = createDebug('nxapi:api:znc'); +const debug = createDebug('nxapi:api:coral'); const ZNCA_PLATFORM = 'Android'; const ZNCA_PLATFORM_VERSION = '8.0.0'; @@ -17,23 +17,23 @@ const ZNCA_USER_AGENT = `com.nintendo.znca/${ZNCA_VERSION}(${ZNCA_PLATFORM}/${ZN const ZNC_URL = 'https://api-lp1.znc.srv.nintendo.net'; export const ZNCA_CLIENT_ID = '71b963c1b7b6d119'; -export default class ZncApi { +export default class CoralApi { static useragent: string | null = null; - onTokenExpired: ((data: ZncErrorResponse, res: Response) => Promise) | null = null; + onTokenExpired: ((data: CoralErrorResponse, res: Response) => Promise) | null = null; /** @internal */ _renewToken: Promise | null = null; constructor( public token: string, - public useragent: string | null = ZncApi.useragent + public useragent: string | null = CoralApi.useragent ) {} async fetch( url: string, method = 'GET', body?: string, headers?: object, /** @internal */ _autoRenewToken = true, /** @internal */ _attempt = 0 - ): Promise> { + ): Promise> { if (this._renewToken && _autoRenewToken) { await this._renewToken; } @@ -52,9 +52,9 @@ export default class ZncApi { debug('fetch %s %s, response %s', method, url, response.status); - const data = await response.json() as ZncResponse; + const data = await response.json() as CoralResponse; - if (data.status === ZncStatus.TOKEN_EXPIRED && _autoRenewToken && !_attempt && this.onTokenExpired) { + if (data.status === CoralStatus.TOKEN_EXPIRED && _autoRenewToken && !_attempt && this.onTokenExpired) { // _renewToken will be awaited when calling fetch this._renewToken = this._renewToken ?? this.onTokenExpired.call(null, data, response).finally(() => { this._renewToken = null; @@ -65,7 +65,7 @@ export default class ZncApi { if ('errorMessage' in data) { throw new ErrorResponse('[znc] ' + data.errorMessage, response, data); } - if (data.status !== ZncStatus.OK) { + if (data.status !== CoralStatus.OK) { throw new ErrorResponse('[znc] Unknown error', response, data); } @@ -194,7 +194,7 @@ export default class ZncApi { }; } - static async createWithSessionToken(token: string, useragent = ZncApi.useragent) { + static async createWithSessionToken(token: string, useragent = CoralApi.useragent) { const data = await this.loginWithSessionToken(token, useragent); return { @@ -211,7 +211,7 @@ export default class ZncApi { return data; } - static async loginWithSessionToken(token: string, useragent = ZncApi.useragent) { + static async loginWithSessionToken(token: string, useragent = CoralApi.useragent) { const uuid = uuidgen(); const timestamp = '' + Math.floor(Date.now() / 1000); @@ -248,7 +248,7 @@ export default class ZncApi { }); debug('fetch %s %s, response %s', 'POST', '/v3/Account/Login', response.status); - const data = await response.json() as ZncResponse; + const data = await response.json() as CoralResponse; if ('errorMessage' in data) { throw new ErrorResponse('[znc] ' + data.errorMessage, response, data); @@ -271,7 +271,7 @@ export default class ZncApi { } } -export interface ZncJwtPayload extends JwtPayload { +export interface CoralJwtPayload extends JwtPayload { isChildRestricted: boolean; membership: { active: boolean; @@ -280,18 +280,18 @@ export interface ZncJwtPayload extends JwtPayload { exp: number; iat: number; iss: 'api-lp1.znc.srv.nintendo.net'; - /** User ID (CurrentUser.id, not CurrentUser.nsaID) */ + /** Coral user ID (CurrentUser.id, not CurrentUser.nsaID) */ sub: number; typ: 'id_token'; } -export interface ZncWebServiceJwtPayload extends JwtPayload { +export interface CoralWebServiceJwtPayload extends JwtPayload { isChildRestricted: boolean; aud: string; exp: number; iat: number; iss: 'api-lp1.znc.srv.nintendo.net'; jti: string; - /** User ID (CurrentUser.id, not CurrentUser.nsaID) */ + /** Coral user ID (CurrentUser.id, not CurrentUser.nsaID) */ sub: number; links: { networkServiceAccount: { diff --git a/src/api/f.ts b/src/api/f.ts index 1193a5b..6243912 100644 --- a/src/api/f.ts +++ b/src/api/f.ts @@ -10,6 +10,14 @@ const debugFlapg = createDebug('nxapi:api:flapg'); const debugImink = createDebug('nxapi:api:imink'); const debugZncaApi = createDebug('nxapi:api:znca-api'); +abstract class ZncaApi { + constructor( + public useragent?: string + ) {} + + abstract genf(token: string, timestamp: string, uuid: string, type: FlapgIid): Promise; +} + // // splatnet2statink + flapg // @@ -96,6 +104,23 @@ export interface FlapgApiResponse { }; } +export class ZncaApiFlapg extends ZncaApi { + async getLoginHash(id_token: string, timestamp: string) { + return getLoginHash(id_token, timestamp, this.useragent); + } + + async genf(token: string, timestamp: string, uuid: string, type: FlapgIid) { + const result = await flapg(token, timestamp, uuid, type, this.useragent); + + return { + provider: 'flapg' as const, + token, timestamp, uuid, type, + f: result.result.f, + result, + }; + } +} + // // imink // @@ -151,6 +176,19 @@ export interface IminkFError { error: true; } +export class ZncaApiImink extends ZncaApi { + async genf(token: string, timestamp: string, uuid: string, type: FlapgIid) { + const result = await iminkf(token, timestamp, uuid, type === FlapgIid.APP ? '2' : '1', this.useragent); + + return { + provider: 'imink' as const, + token, timestamp, uuid, type, + f: result.f, + result, + }; + } +} + // // nxapi znca API server // @@ -206,43 +244,32 @@ export interface AndroidZncaFError { error: string; } -export async function f( - token: string, timestamp: string | number, uuid: string, type: FlapgIid, - useragent?: string, - provider: FApi = getEnvApi() -): Promise { - if (provider === 'flapg') { - const result = await flapg(token, timestamp, uuid, type, useragent); - return { - provider: 'flapg', - token, timestamp: '' + timestamp, uuid, type, - f: result.result.f, result, - }; - } - if (provider === 'imink') { - const result = await iminkf(token, timestamp, uuid, type === FlapgIid.APP ? '2' : '1', useragent); - return { - provider: 'imink', - token, timestamp: '' + timestamp, uuid, type, - f: result.f, result, - }; - } - if (provider[0] === 'nxapi') { - const result = await genf(provider[1], token, timestamp, uuid, type, useragent); - return { - provider: 'nxapi', url: provider[1], - token, timestamp: '' + timestamp, uuid, type, - f: result.f, result, - }; +export class ZncaApiNxapi extends ZncaApi { + constructor(readonly url: string, useragent?: string) { + super(useragent); } - throw new Error('Unknown znca API provider'); + async genf(token: string, timestamp: string, uuid: string, type: FlapgIid) { + const result = await genf(this.url + '/f', token, timestamp, uuid, type, this.useragent); + + return { + provider: 'nxapi' as const, + url: this.url + '/f', + token, timestamp, uuid, type, + f: result.f, + result, + }; + } } -export type FApi = - 'flapg' | - 'imink' | - ['nxapi', string]; +export async function f( + token: string, timestamp: string | number, uuid: string, type: FlapgIid, + useragent?: string +): Promise { + const provider = getZncaApiFromEnvironment(useragent); + + return provider.genf(token, '' + timestamp, uuid, type); +} export type FResult = { provider: string; @@ -264,21 +291,21 @@ export type FResult = { result: AndroidZncaFResponse; }); -function getEnvApi(): FApi { +function getZncaApiFromEnvironment(useragent?: string): ZncaApi { if (process.env.NXAPI_ZNCA_API) { if (process.env.NXAPI_ZNCA_API === 'flapg') { - return 'flapg'; + return new ZncaApiFlapg(useragent); } if (process.env.NXAPI_ZNCA_API === 'imink') { - return 'imink'; + return new ZncaApiImink(useragent); } throw new Error('Unknown znca API provider'); } if (process.env.ZNCA_API_URL) { - return ['nxapi', process.env.ZNCA_API_URL + '/f']; + return new ZncaApiNxapi(process.env.ZNCA_API_URL, useragent); } - return 'flapg'; + return new ZncaApiFlapg(useragent); } diff --git a/src/api/nooklink.ts b/src/api/nooklink.ts index e233672..c9cefa3 100644 --- a/src/api/nooklink.ts +++ b/src/api/nooklink.ts @@ -1,9 +1,9 @@ import fetch from 'node-fetch'; import createDebug from 'debug'; -import { WebServiceToken } from './znc-types.js'; +import { WebServiceToken } from './coral-types.js'; import { NintendoAccountUser } from './na.js'; import { ErrorResponse } from './util.js'; -import ZncApi from './znc.js'; +import CoralApi from './coral.js'; import { WebServiceError, Users, AuthToken, UserProfile, Newspapers, Newspaper, Emoticons, Reaction, IslandProfile } from './nooklink-types.js'; import { timeoutSignal } from '../util/misc.js'; @@ -76,8 +76,8 @@ export default class NooklinkApi { }; } - static async createWithZnc(nso: ZncApi, user: NintendoAccountUser) { - const data = await this.loginWithZnc(nso, user); + static async createWithCoral(nso: CoralApi, user: NintendoAccountUser) { + const data = await this.loginWithCoral(nso, user); return { nooklink: new this(data.gtoken, data.useragent), @@ -85,7 +85,7 @@ export default class NooklinkApi { }; } - static async loginWithZnc(nso: ZncApi, user: NintendoAccountUser) { + static async loginWithCoral(nso: CoralApi, user: NintendoAccountUser) { const webserviceToken = await nso.getWebServiceToken(NOOKLINK_WEBSERVICE_ID); return this.loginWithWebServiceToken(webserviceToken.result, user); diff --git a/src/api/splatnet2.ts b/src/api/splatnet2.ts index 9ff8ea7..2b03a96 100644 --- a/src/api/splatnet2.ts +++ b/src/api/splatnet2.ts @@ -1,10 +1,10 @@ import fetch from 'node-fetch'; import createDebug from 'debug'; import { v4 as uuidgen } from 'uuid'; -import { WebServiceToken } from './znc-types.js'; +import { WebServiceToken } from './coral-types.js'; import { NintendoAccountUser } from './na.js'; import { ErrorResponse } from './util.js'; -import ZncApi from './znc.js'; +import CoralApi from './coral.js'; import { ActiveFestivals, CoopResult, CoopResults, CoopSchedules, HeroRecords, NicknameAndIcons, PastFestivals, Records, Result, Results, Schedules, ShareResponse, ShopMerchandises, Stages, Timeline, WebServiceError, XPowerRankingSummary } from './splatnet2-types.js'; import { timeoutSignal } from '../util/misc.js'; import { toSeasonId, Rule as XPowerRankingRule } from './splatnet2-xrank.js'; @@ -211,8 +211,8 @@ ${colour} }); } - static async createWithZnc(nso: ZncApi, user: NintendoAccountUser) { - const data = await this.loginWithZnc(nso, user); + static async createWithCoral(nso: CoralApi, user: NintendoAccountUser) { + const data = await this.loginWithCoral(nso, user); return { splatnet: new this(data.iksm_session, data.useragent), @@ -220,7 +220,7 @@ ${colour} }; } - static async loginWithZnc(nso: ZncApi, user: NintendoAccountUser) { + static async loginWithCoral(nso: CoralApi, user: NintendoAccountUser) { const webserviceToken = await nso.getWebServiceToken(SPLATNET2_WEBSERVICE_ID); return this.loginWithWebServiceToken(webserviceToken.result, user); diff --git a/src/api/znc-proxy.ts b/src/api/znc-proxy.ts index af78fdf..feefb65 100644 --- a/src/api/znc-proxy.ts +++ b/src/api/znc-proxy.ts @@ -1,8 +1,8 @@ import fetch, { Response } from 'node-fetch'; import createDebug from 'debug'; -import { ActiveEvent, Announcements, CurrentUser, Event, Friend, Presence, PresencePermissions, User, WebService, WebServiceToken, ZncErrorResponse, ZncStatus, ZncSuccessResponse } from './znc-types.js'; +import { ActiveEvent, Announcements, CurrentUser, Event, Friend, Presence, PresencePermissions, User, WebService, WebServiceToken, CoralErrorResponse, CoralStatus, CoralSuccessResponse } from './coral-types.js'; import { ErrorResponse } from './util.js'; -import ZncApi from './znc.js'; +import CoralApi from './coral.js'; import { version } from '../util/product.js'; import { NintendoAccountUser } from './na.js'; import { SavedToken } from '../common/auth/nso.js'; @@ -10,11 +10,11 @@ import { timeoutSignal } from '../util/misc.js'; const debug = createDebug('nxapi:api:znc-proxy'); -export default class ZncProxyApi implements ZncApi { +export default class ZncProxyApi implements CoralApi { static useragent: string | null = null; // Not used by ZncProxyApi - onTokenExpired: ((data: ZncErrorResponse, res: Response) => Promise) | null = null; + onTokenExpired: ((data: CoralErrorResponse, res: Response) => Promise) | null = null; /** @internal */ _renewToken: Promise | null = null; @@ -51,64 +51,64 @@ export default class ZncProxyApi implements ZncApi { return data; } - async call(url: string, parameter = {}): Promise> { + async call(url: string, parameter = {}): Promise> { throw new Error('Not supported in ZncProxyApi'); } async getAnnouncements() { const response = await this.fetch<{announcements: Announcements}>('/announcements'); - return {status: ZncStatus.OK as const, result: response.announcements, correlationId: ''}; + return {status: CoralStatus.OK as const, result: response.announcements, correlationId: ''}; } async getFriendList() { const response = await this.fetch<{friends: Friend[]}>('/friends'); - return {status: ZncStatus.OK as const, result: response, correlationId: ''}; + return {status: CoralStatus.OK as const, result: response, correlationId: ''}; } async addFavouriteFriend(nsaid: string) { await this.fetch('/friend/' + nsaid, 'POST', JSON.stringify({ isFavoriteFriend: true, })); - return {status: ZncStatus.OK as const, result: {}, correlationId: ''}; + return {status: CoralStatus.OK as const, result: {}, correlationId: ''}; } async removeFavouriteFriend(nsaid: string) { await this.fetch('/friend/' + nsaid, 'POST', JSON.stringify({ isFavoriteFriend: false, })); - return {status: ZncStatus.OK as const, result: {}, correlationId: ''}; + return {status: CoralStatus.OK as const, result: {}, correlationId: ''}; } async getWebServices() { const response = await this.fetch<{webservices: WebService[]}>('/webservices'); - return {status: ZncStatus.OK as const, result: response.webservices, correlationId: ''}; + return {status: CoralStatus.OK as const, result: response.webservices, correlationId: ''}; } async getActiveEvent() { const response = await this.fetch<{activeevent: ActiveEvent}>('/activeevent'); - return {status: ZncStatus.OK as const, result: response.activeevent, correlationId: ''}; + return {status: CoralStatus.OK as const, result: response.activeevent, correlationId: ''}; } async getEvent(id: number) { const response = await this.fetch<{event: Event}>('/event/' + id); - return {status: ZncStatus.OK as const, result: response.event, correlationId: ''}; + return {status: CoralStatus.OK as const, result: response.event, correlationId: ''}; } async getUser(id: number) { const response = await this.fetch<{user: User}>('/user/' + id); - return {status: ZncStatus.OK as const, result: response.user, correlationId: ''}; + return {status: CoralStatus.OK as const, result: response.user, correlationId: ''}; } async getCurrentUser() { const response = await this.fetch<{user: CurrentUser}>('/user'); - return {status: ZncStatus.OK as const, result: response.user, correlationId: ''}; + return {status: CoralStatus.OK as const, result: response.user, correlationId: ''}; } async getCurrentUserPermissions() { const user = await this.getCurrentUser(); return { - status: ZncStatus.OK as const, + status: CoralStatus.OK as const, result: { etag: user.result.etag, permissions: user.result.permissions, @@ -119,16 +119,16 @@ export default class ZncProxyApi implements ZncApi { async updateCurrentUserPermissions( to: PresencePermissions, from: PresencePermissions, etag: string - ): Promise> { + ): Promise> { throw new Error('Not supported in ZncProxyApi'); } async getWebServiceToken(id: string) { const response = await this.fetch<{token: WebServiceToken}>('/webservice/' + id + '/token'); - return {status: ZncStatus.OK as const, result: response.token, correlationId: ''}; + return {status: CoralStatus.OK as const, result: response.token, correlationId: ''}; } - async getToken(token: string, user: NintendoAccountUser): ReturnType { + async getToken(token: string, user: NintendoAccountUser): ReturnType { throw new Error('Not supported in ZncProxyApi'); } diff --git a/src/app/browser/discord/index.tsx b/src/app/browser/discord/index.tsx index 3ad7779..68fea61 100644 --- a/src/app/browser/discord/index.tsx +++ b/src/app/browser/discord/index.tsx @@ -12,7 +12,7 @@ export interface DiscordSetupProps { } enum DiscordSourceType { - ZNC, + CORAL, URL, NONE, } @@ -30,7 +30,7 @@ export default function DiscordSetup(props: DiscordSetupProps) { const [discord_presence_source, discord_presence_source_state] = useDiscordPresenceSource(); const [selectedMode, setSelectedMode] = useState(props.users?.length && props.friend_nsa_id ? - DiscordSourceType.ZNC : DiscordSourceType.NONE); + DiscordSourceType.CORAL : DiscordSourceType.NONE); const [selectedUserId, setSelectedUserId] = useState(null); const [selectedFriendNsaId, setSelectedFriendNsaId] = useState(props.friend_nsa_id ?? null); const [presenceUrl, setPresenceUrl] = useState(''); @@ -38,9 +38,9 @@ export default function DiscordSetup(props: DiscordSetupProps) { useEffect(() => { if (!discord_presence_source) { setSelectedMode(props.users?.length && props.friend_nsa_id ? - DiscordSourceType.ZNC : DiscordSourceType.NONE); + DiscordSourceType.CORAL : DiscordSourceType.NONE); } else if ('na_id' in discord_presence_source) { - setSelectedMode(DiscordSourceType.ZNC); + setSelectedMode(DiscordSourceType.CORAL); setSelectedUserId(discord_presence_source.na_id); setSelectedFriendNsaId(discord_presence_source.friend_nsa_id ?? null); } else if ('url' in discord_presence_source) { @@ -72,7 +72,7 @@ export default function DiscordSetup(props: DiscordSetupProps) { }, [friends, user]); const save = useCallback(async () => { - if (selectedMode === DiscordSourceType.ZNC) { + if (selectedMode === DiscordSourceType.CORAL) { if (!selectedUserId?.match(/^[0-9a-f]{16}$/)) throw new Error('Invalid Nintendo Account ID'); if (!selectedFriendNsaId?.match(/^[0-9a-f]{16}$/)) throw new Error('Invalid friend Network Service Account ID'); @@ -106,13 +106,13 @@ export default function DiscordSetup(props: DiscordSetupProps) { style={[styles.picker, theme.picker]} > + value={DiscordSourceType.CORAL} /> - {selectedMode === DiscordSourceType.ZNC ? <> + {selectedMode === DiscordSourceType.CORAL ? <> 2. Select user This user must be friends with the user you want to share. diff --git a/src/app/browser/friend/index.tsx b/src/app/browser/friend/index.tsx index c1f93f8..364c4c7 100644 --- a/src/app/browser/friend/index.tsx +++ b/src/app/browser/friend/index.tsx @@ -3,7 +3,7 @@ import React, { useCallback, useEffect } from 'react'; import { ActivityIndicator, Image, StyleSheet, Text, TouchableOpacity, useColorScheme, View } from 'react-native'; import { CheckBox } from 'react-native-web'; -import { Game, Presence, PresencePermissions, PresenceState } from '../../../api/znc-types.js'; +import { Game, Presence, PresencePermissions, PresenceState } from '../../../api/coral-types.js'; import { getTitleIdFromEcUrl, hrduration } from '../../../util/misc.js'; import { Button } from '../components/index.js'; import { DEFAULT_ACCENT_COLOUR, TEXT_COLOUR_ACTIVE, TEXT_COLOUR_DARK, TEXT_COLOUR_LIGHT } from '../constants.js'; diff --git a/src/app/browser/main/discord-setup.tsx b/src/app/browser/main/discord-setup.tsx index 7580196..5396fa8 100644 --- a/src/app/browser/main/discord-setup.tsx +++ b/src/app/browser/main/discord-setup.tsx @@ -2,7 +2,7 @@ import React, { useCallback, useMemo } from 'react'; import { Image, StyleSheet, Text, View } from 'react-native'; import ipc, { events } from '../ipc.js'; import { getAccounts, RequestState, useAccentColour, useAsync, useColourScheme, useDiscordPresenceSource, useEventListener, User } from '../util.js'; -import { Friend, PresencePermissions } from '../../../api/znc-types.js'; +import { Friend, PresencePermissions } from '../../../api/coral-types.js'; import { TEXT_COLOUR_DARK, TEXT_COLOUR_LIGHT } from '../constants.js'; import Section from './section.js'; import { Button } from '../components/index.js'; diff --git a/src/app/browser/main/discord.tsx b/src/app/browser/main/discord.tsx index 190d57d..7138c1f 100644 --- a/src/app/browser/main/discord.tsx +++ b/src/app/browser/main/discord.tsx @@ -3,7 +3,7 @@ import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import { User } from 'discord-rpc'; import ipc, { events } from '../ipc.js'; import { RequestState, useAsync, useEventListener } from '../util.js'; -import { DiscordPresenceSource, DiscordPresenceSourceUrl, DiscordPresenceSourceZnc } from '../../common/types.js'; +import { DiscordPresenceSource, DiscordPresenceSourceUrl, DiscordPresenceSourceCoral } from '../../common/types.js'; import { DiscordPresence } from '../../../discord/util.js'; import { DISCORD_COLOUR, TEXT_COLOUR_DARK } from '../constants.js'; @@ -24,7 +24,7 @@ export default function DiscordPresenceSource(props: { function renderDiscordPresenceSource(source: DiscordPresenceSource | null) { if (source && 'na_id' in source) { - return ; + return ; } else if (source && 'url' in source) { return ; } else { @@ -32,8 +32,8 @@ function renderDiscordPresenceSource(source: DiscordPresenceSource | null) { } } -function DiscordPresenceSourceZnc(props: { - source: DiscordPresenceSourceZnc; +function DiscordPresenceSourceCoral(props: { + source: DiscordPresenceSourceCoral; }) { const [token] = useAsync(useCallback(() => ipc.getNintendoAccountNsoToken(props.source.na_id), [ipc, props.source.na_id])); diff --git a/src/app/browser/main/event.tsx b/src/app/browser/main/event.tsx index ce7253b..e334ba4 100644 --- a/src/app/browser/main/event.tsx +++ b/src/app/browser/main/event.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Image, StyleSheet, Text, View } from 'react-native'; import ipc from '../ipc.js'; import { useAccentColour, useColourScheme, User } from '../util.js'; -import { ActiveEvent } from '../../../api/znc-types.js'; +import { ActiveEvent } from '../../../api/coral-types.js'; import { TEXT_COLOUR_DARK, TEXT_COLOUR_LIGHT } from '../constants.js'; import Section from './section.js'; import { Button } from '../components/index.js'; diff --git a/src/app/browser/main/friends.tsx b/src/app/browser/main/friends.tsx index 99311b9..17ffbc9 100644 --- a/src/app/browser/main/friends.tsx +++ b/src/app/browser/main/friends.tsx @@ -2,7 +2,7 @@ import React, { useCallback } from 'react'; import { Image, ImageStyle, Platform, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import ipc from '../ipc.js'; import { useColourScheme, User } from '../util.js'; -import { Friend, Presence, PresenceState } from '../../../api/znc-types.js'; +import { Friend, Presence, PresenceState } from '../../../api/coral-types.js'; import { TEXT_COLOUR_ACTIVE, TEXT_COLOUR_DARK, TEXT_COLOUR_LIGHT } from '../constants.js'; import Section from './section.js'; diff --git a/src/app/browser/main/webservices.tsx b/src/app/browser/main/webservices.tsx index 3b01248..72366e7 100644 --- a/src/app/browser/main/webservices.tsx +++ b/src/app/browser/main/webservices.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Image, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import ipc from '../ipc.js'; import { useColourScheme, User } from '../util.js'; -import { WebService } from '../../../api/znc-types.js'; +import { WebService } from '../../../api/coral-types.js'; import { TEXT_COLOUR_DARK, TEXT_COLOUR_LIGHT } from '../constants.js'; import Section from './section.js'; diff --git a/src/app/common/types.ts b/src/app/common/types.ts index 38e89bd..079d6e5 100644 --- a/src/app/common/types.ts +++ b/src/app/common/types.ts @@ -28,8 +28,8 @@ export interface DiscordPresenceConfiguration { show_play_time?: DiscordPresencePlayTime; } -export type DiscordPresenceSource = DiscordPresenceSourceZnc | DiscordPresenceSourceUrl; -export interface DiscordPresenceSourceZnc { +export type DiscordPresenceSource = DiscordPresenceSourceCoral | DiscordPresenceSourceUrl; +export interface DiscordPresenceSourceCoral { na_id: string; friend_nsa_id?: string; } diff --git a/src/app/main/ipc.ts b/src/app/main/ipc.ts index 2d6e11c..abd6eec 100644 --- a/src/app/main/ipc.ts +++ b/src/app/main/ipc.ts @@ -5,7 +5,7 @@ import { User } from 'discord-rpc'; import openWebService, { WebServiceIpc } from './webservices.js'; import { createWindow, getWindowConfiguration } from './windows.js'; import { DiscordPresenceConfiguration, DiscordPresenceSource, WindowType } from '../common/types.js'; -import { CurrentUser, Friend, Game, PresenceState, WebService } from '../../api/znc-types.js'; +import { CurrentUser, Friend, Game, PresenceState, WebService } from '../../api/coral-types.js'; import { addNsoAccount, addPctlAccount } from './na-auth.js'; import { App } from './index.js'; import { NintendoAccountUser } from '../../api/na.js'; diff --git a/src/app/main/menu.ts b/src/app/main/menu.ts index b2acfef..7e2b4d9 100644 --- a/src/app/main/menu.ts +++ b/src/app/main/menu.ts @@ -2,7 +2,7 @@ import { app, dialog, Menu, Tray, nativeImage, MenuItem } from './electron.js'; import createDebug from 'debug'; import { addNsoAccount, addPctlAccount } from './na-auth.js'; import { App } from './index.js'; -import { WebService } from '../../api/znc-types.js'; +import { WebService } from '../../api/coral-types.js'; import openWebService from './webservices.js'; import { SavedToken } from '../../common/auth/nso.js'; import { SavedMoonToken } from '../../common/auth/moon.js'; diff --git a/src/app/main/monitor.ts b/src/app/main/monitor.ts index e401a4e..29e35aa 100644 --- a/src/app/main/monitor.ts +++ b/src/app/main/monitor.ts @@ -1,6 +1,6 @@ import { dialog, Notification } from './electron.js'; import createDebug from 'debug'; -import { CurrentUser, Friend, Game, ZncErrorResponse } from '../../api/znc-types.js'; +import { CurrentUser, Friend, Game, CoralErrorResponse } from '../../api/coral-types.js'; import { ErrorResponse } from '../../api/util.js'; import { ZncDiscordPresence, ZncProxyDiscordPresence } from '../../common/presence.js'; import { NotificationManager } from '../../common/notify.js'; @@ -295,7 +295,7 @@ export class EmbeddedPresenceMonitor extends ZncDiscordPresence { } } - async handleError(err: ErrorResponse | NodeJS.ErrnoException): Promise { + async handleError(err: ErrorResponse | NodeJS.ErrnoException): Promise { try { return await super.handleError(err); } catch (err) { @@ -361,7 +361,7 @@ export class EmbeddedProxyPresenceMonitor extends ZncProxyDiscordPresence { } } - async handleError(err: ErrorResponse | NodeJS.ErrnoException): Promise { + async handleError(err: ErrorResponse | NodeJS.ErrnoException): Promise { try { return await super.handleError(err); } catch (err) { diff --git a/src/app/main/na-auth.ts b/src/app/main/na-auth.ts index dd3bcf2..263bc30 100644 --- a/src/app/main/na-auth.ts +++ b/src/app/main/na-auth.ts @@ -4,7 +4,7 @@ import createDebug from 'debug'; import * as persist from 'node-persist'; import { BrowserWindow, dialog, MessageBoxOptions, Notification, session, shell } from './electron.js'; import { getNintendoAccountSessionToken, NintendoAccountSessionToken } from '../../api/na.js'; -import { ZNCA_CLIENT_ID } from '../../api/znc.js'; +import { ZNCA_CLIENT_ID } from '../../api/coral.js'; import { ZNMA_CLIENT_ID } from '../../api/moon.js'; import { getToken, SavedToken } from '../../common/auth/nso.js'; import { getPctlToken, SavedMoonToken } from '../../common/auth/moon.js'; diff --git a/src/app/main/webservices.ts b/src/app/main/webservices.ts index dc29af2..9cea0f3 100644 --- a/src/app/main/webservices.ts +++ b/src/app/main/webservices.ts @@ -5,9 +5,9 @@ import { Buffer } from 'node:buffer'; import createDebug from 'debug'; import { app, BrowserWindow, dialog, IpcMainInvokeEvent, Menu, MenuItem, nativeTheme, ShareMenu, shell, WebContents } from './electron.js'; import fetch from 'node-fetch'; -import ZncApi from '../../api/znc.js'; +import CoralApi from '../../api/coral.js'; import { dev } from '../../util/product.js'; -import { WebService } from '../../api/znc-types.js'; +import { WebService } from '../../api/coral-types.js'; import { Store } from './index.js'; import type { NativeShareRequest, NativeShareUrlRequest } from '../preload-webservice/znca-js-api.js'; import { SavedToken } from '../../common/auth/nso.js'; @@ -16,10 +16,10 @@ import { createWebServiceWindow } from './windows.js'; const debug = createDebug('app:main:webservices'); const windows = new Map(); -const windowapi = new WeakMap(); +const windowapi = new WeakMap(); export default async function openWebService( - store: Store, token: string, nso: ZncApi, data: SavedToken, + store: Store, token: string, nso: CoralApi, data: SavedToken, webservice: WebService, qs?: string ) { const windowid = data.nsoAccount.user.nsaId + ':' + webservice.id; diff --git a/src/app/main/windows.ts b/src/app/main/windows.ts index 06afb54..5356f5c 100644 --- a/src/app/main/windows.ts +++ b/src/app/main/windows.ts @@ -4,7 +4,7 @@ import { dev } from '../../util/product.js'; import { WindowConfiguration, WindowType } from '../common/types.js'; import { bundlepath } from './util.js'; import { app_menu, createWindowMenu } from './app-menu.js'; -import { WebService } from '../../api/znc-types.js'; +import { WebService } from '../../api/coral-types.js'; const windows = new WeakMap(); const menus = new WeakMap(); diff --git a/src/app/preload/index.ts b/src/app/preload/index.ts index 183ec35..e226a2d 100644 --- a/src/app/preload/index.ts +++ b/src/app/preload/index.ts @@ -8,7 +8,7 @@ import type { DiscordPresenceConfiguration, DiscordPresenceSource, WindowConfigu import type { SavedToken } from '../../common/auth/nso.js'; import type { SavedMoonToken } from '../../common/auth/moon.js'; import type { UpdateCacheData } from '../../common/update.js'; -import type { Announcements, CurrentUser, Friend, GetActiveEventResult, WebService, WebServices } from '../../api/znc-types.js'; +import type { Announcements, CurrentUser, Friend, GetActiveEventResult, WebService, WebServices } from '../../api/coral-types.js'; import type { DiscordPresence } from '../../discord/util.js'; import type { NintendoAccountUser } from '../../api/na.js'; import type { DiscordSetupProps } from '../browser/discord/index.js'; diff --git a/src/cli/android-znca-api-server-frida.ts b/src/cli/android-znca-api-server-frida.ts index 253fd46..ed032da 100644 --- a/src/cli/android-znca-api-server-frida.ts +++ b/src/cli/android-znca-api-server-frida.ts @@ -10,7 +10,7 @@ import bodyParser from 'body-parser'; import mkdirp from 'mkdirp'; import type { Arguments as ParentArguments } from '../cli.js'; import { NintendoAccountIdTokenJwtPayload } from '../api/na.js'; -import { ZNCA_CLIENT_ID, ZncJwtPayload } from '../api/znc.js'; +import { CoralJwtPayload, ZNCA_CLIENT_ID } from '../api/coral.js'; import { ArgumentsCamelCase, Argv, YargsArguments } from '../util/yargs.js'; import { initStorage, paths } from '../util/storage.js'; import { getJwks, Jwt } from '../util/jwt.js'; @@ -139,7 +139,7 @@ export async function handler(argv: ArgumentsCamelCase) { } try { - const [jwt, sig] = Jwt.decode(data.token); + const [jwt, sig] = Jwt.decode(data.token); const check_signature = jwt.payload.iss === 'https://accounts.nintendo.com'; diff --git a/src/cli/nso/auth.ts b/src/cli/nso/auth.ts index 9e4b60f..61abce0 100644 --- a/src/cli/nso/auth.ts +++ b/src/cli/nso/auth.ts @@ -5,7 +5,7 @@ import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js'; import { initStorage } from '../../util/storage.js'; import { getToken } from '../../common/auth/nso.js'; import { getNintendoAccountSessionToken } from '../../api/na.js'; -import { ZNCA_CLIENT_ID } from '../../api/znc.js'; +import { ZNCA_CLIENT_ID } from '../../api/coral.js'; import prompt from '../util/prompt.js'; const debug = createDebug('cli:nso:auth'); diff --git a/src/cli/nso/friends.ts b/src/cli/nso/friends.ts index 6fcc27e..c23dce0 100644 --- a/src/cli/nso/friends.ts +++ b/src/cli/nso/friends.ts @@ -1,6 +1,6 @@ import createDebug from 'debug'; import Table from '../util/table.js'; -import { PresenceState } from '../../api/znc-types.js'; +import { PresenceState } from '../../api/coral-types.js'; import type { Arguments as ParentArguments } from '../nso.js'; import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js'; import { initStorage } from '../../util/storage.js'; diff --git a/src/cli/nso/http-server.ts b/src/cli/nso/http-server.ts index d5b7b20..b873f03 100644 --- a/src/cli/nso/http-server.ts +++ b/src/cli/nso/http-server.ts @@ -4,8 +4,8 @@ import * as persist from 'node-persist'; import express, { Request, Response } from 'express'; import bodyParser from 'body-parser'; import { v4 as uuidgen } from 'uuid'; -import { Announcement, CurrentUser, Friend, GetActiveEventResult, Presence, WebService } from '../../api/znc-types.js'; -import ZncApi from '../../api/znc.js'; +import { Announcement, CurrentUser, Friend, GetActiveEventResult, Presence, WebService } from '../../api/coral-types.js'; +import CoralApi from '../../api/coral.js'; import type { Arguments as ParentArguments } from '../nso.js'; import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js'; import { initStorage } from '../../util/storage.js'; @@ -18,7 +18,7 @@ import { AuthPolicy, AuthToken, ZncPresenceEventStreamEvent } from '../../api/zn declare global { namespace Express { interface Request { - znc?: ZncApi; + znc?: CoralApi; zncAuth?: SavedToken; zncAuthPolicy?: AuthPolicy; @@ -126,7 +126,7 @@ function createApp( })); } - const znc_auth_promise = new Map>(); + const znc_auth_promise = new Map>(); const znc_auth_timeout = new Map(); const nsoAuth: express.RequestHandler = async (req, res, next) => { diff --git a/src/cli/nso/notify.ts b/src/cli/nso/notify.ts index 2e9552a..84e92c4 100644 --- a/src/cli/nso/notify.ts +++ b/src/cli/nso/notify.ts @@ -7,7 +7,7 @@ import { initStorage } from '../../util/storage.js'; import { getToken } from '../../common/auth/nso.js'; import { getIksmToken } from '../../common/auth/splatnet2.js'; import { EmbeddedSplatNet2Monitor, NotificationManager, ZncNotifications } from '../../common/notify.js'; -import { CurrentUser, Friend, Game } from '../../api/znc-types.js'; +import { CurrentUser, Friend, Game } from '../../api/coral-types.js'; const debug = createDebug('cli:nso:notify'); diff --git a/src/cli/nso/permissions.ts b/src/cli/nso/permissions.ts index c55a8cb..f7c3a35 100644 --- a/src/cli/nso/permissions.ts +++ b/src/cli/nso/permissions.ts @@ -1,5 +1,5 @@ import createDebug from 'debug'; -import { PresencePermissions } from '../../api/znc-types.js'; +import { PresencePermissions } from '../../api/coral-types.js'; import type { Arguments as ParentArguments } from '../nso.js'; import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js'; import { initStorage } from '../../util/storage.js'; diff --git a/src/cli/util/discord-activity.ts b/src/cli/util/discord-activity.ts index 9451f0a..9e08f78 100644 --- a/src/cli/util/discord-activity.ts +++ b/src/cli/util/discord-activity.ts @@ -2,7 +2,7 @@ import process from 'node:process'; import createDebug from 'debug'; import fetch from 'node-fetch'; import { getPresenceFromUrl } from '../../api/znc-proxy.js'; -import { ActiveEvent, CurrentUser, Friend, Game, Presence, PresenceState } from '../../api/znc-types.js'; +import { ActiveEvent, CurrentUser, Friend, Game, Presence, PresenceState } from '../../api/coral-types.js'; import type { Arguments as ParentArguments } from '../util.js'; import { DiscordPresenceContext, DiscordPresencePlayTime, getDiscordPresence, getInactiveDiscordPresence } from '../../discord/util.js'; import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js'; @@ -84,7 +84,7 @@ export async function handler(argv: ArgumentsCamelCase) { const [presence, user, friendcode, activeevent] = argv.presenceJson ? await getPresenceFromJson(argv.presenceJson) : argv.presenceUrl ? await getPresenceFromUrl(argv.presenceUrl) : - await getPresenceFromZnc(argv); + await getPresenceFromCoral(argv); const discordpresence = getActivityFromPresence(argv, presence, user, friendcode, activeevent); const application = argv.showDiscordApplication ? @@ -137,7 +137,7 @@ async function getPresenceFromJson(json: string) { return [presence] as const; } -async function getPresenceFromZnc(argv: ArgumentsCamelCase) { +async function getPresenceFromCoral(argv: ArgumentsCamelCase) { const storage = await initStorage(argv.dataPath); const usernsid = argv.user ?? await storage.getItem('SelectedUser'); diff --git a/src/common/auth/nooklink.ts b/src/common/auth/nooklink.ts index 67937b8..9b91ab3 100644 --- a/src/common/auth/nooklink.ts +++ b/src/common/auth/nooklink.ts @@ -3,7 +3,7 @@ import persist from 'node-persist'; import { getToken } from './nso.js'; import NooklinkApi, { NooklinkUserApi } from '../../api/nooklink.js'; import { AuthToken, Users } from '../../api/nooklink-types.js'; -import { WebServiceToken } from '../../api/znc-types.js'; +import { WebServiceToken } from '../../api/coral-types.js'; const debug = createDebug('nxapi:auth:nooklink'); @@ -38,7 +38,7 @@ export async function getWebServiceToken( const {nso, data} = await getToken(storage, token, proxy_url); - const existingToken: SavedToken = await NooklinkApi.loginWithZnc(nso, data.user); + const existingToken: SavedToken = await NooklinkApi.loginWithCoral(nso, data.user); await storage.setItem('NookToken.' + token, existingToken); diff --git a/src/common/auth/nso.ts b/src/common/auth/nso.ts index ab6a049..12aaecb 100644 --- a/src/common/auth/nso.ts +++ b/src/common/auth/nso.ts @@ -4,8 +4,8 @@ import { Response } from 'node-fetch'; import { FlapgApiResponse, FResult } from '../../api/f.js'; import { NintendoAccountSessionTokenJwtPayload, NintendoAccountToken, NintendoAccountUser } from '../../api/na.js'; import { Jwt } from '../../util/jwt.js'; -import { AccountLogin, ZncErrorResponse } from '../../api/znc-types.js'; -import ZncApi, { ZNCA_CLIENT_ID } from '../../api/znc.js'; +import { AccountLogin, CoralErrorResponse } from '../../api/coral-types.js'; +import CoralApi, { ZNCA_CLIENT_ID } from '../../api/coral.js'; import ZncProxyApi from '../../api/znc-proxy.js'; const debug = createDebug('nxapi:auth:nso'); @@ -29,7 +29,7 @@ export async function getToken(storage: persist.LocalStorage, token: string, pro data: SavedToken; }> export async function getToken(storage: persist.LocalStorage, token: string, proxy_url?: string): Promise<{ - nso: ZncApi; + nso: CoralApi; data: SavedToken; }> export async function getToken(storage: persist.LocalStorage, token: string, proxy_url?: string) { @@ -63,7 +63,7 @@ export async function getToken(storage: persist.LocalStorage, token: string, pro const {nso, data} = proxy_url ? await ZncProxyApi.createWithSessionToken(proxy_url, token) : - await ZncApi.createWithSessionToken(token); + await CoralApi.createWithSessionToken(token); const existingToken: SavedToken = { ...data, @@ -83,7 +83,7 @@ export async function getToken(storage: persist.LocalStorage, token: string, pro const nso = proxy_url ? new ZncProxyApi(proxy_url, token) : - new ZncApi(existingToken.credential.accessToken); + new CoralApi(existingToken.credential.accessToken); nso.onTokenExpired = createTokenExpiredHandler(storage, token, nso, existingToken); @@ -91,16 +91,16 @@ export async function getToken(storage: persist.LocalStorage, token: string, pro } function createTokenExpiredHandler( - storage: persist.LocalStorage, token: string, nso: ZncApi, existingToken: SavedToken + storage: persist.LocalStorage, token: string, nso: CoralApi, existingToken: SavedToken ) { - return (data: ZncErrorResponse, response: Response) => { + return (data: CoralErrorResponse, response: Response) => { debug('Token expired', existingToken.user.id, data); return renewToken(storage, token, nso, existingToken); }; } async function renewToken( - storage: persist.LocalStorage, token: string, nso: ZncApi, previousToken: SavedToken + storage: persist.LocalStorage, token: string, nso: CoralApi, previousToken: SavedToken ) { const data = await nso.renewToken(token, previousToken.user); diff --git a/src/common/auth/splatnet2.ts b/src/common/auth/splatnet2.ts index 26d4f17..827517e 100644 --- a/src/common/auth/splatnet2.ts +++ b/src/common/auth/splatnet2.ts @@ -4,7 +4,7 @@ import createDebug from 'debug'; import persist from 'node-persist'; import { getToken } from './nso.js'; import SplatNet2Api, { updateIksmSessionLastUsed } from '../../api/splatnet2.js'; -import { WebServiceToken } from '../../api/znc-types.js'; +import { WebServiceToken } from '../../api/coral-types.js'; const debug = createDebug('nxapi:auth:splatnet2'); @@ -49,7 +49,7 @@ export async function getIksmToken(storage: persist.LocalStorage, token: string, const {nso, data} = await getToken(storage, token, proxy_url); - const existingToken: SavedIksmSessionToken = await SplatNet2Api.loginWithZnc(nso, data.user); + const existingToken: SavedIksmSessionToken = await SplatNet2Api.loginWithCoral(nso, data.user); await storage.setItem('IksmToken.' + token, existingToken); @@ -81,7 +81,7 @@ export async function renewIksmToken(splatnet: SplatNet2Api, storage: persist.Lo const {nso, data} = await getToken(storage, token, proxy_url); - const existingToken: SavedIksmSessionToken = await SplatNet2Api.loginWithZnc(nso, data.user); + const existingToken: SavedIksmSessionToken = await SplatNet2Api.loginWithCoral(nso, data.user); await storage.setItem('IksmToken.' + token, existingToken); diff --git a/src/common/notify.ts b/src/common/notify.ts index eb99563..ab2f029 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 ZncApi from '../api/znc.js'; -import { ActiveEvent, Announcements, CurrentUser, Friend, Game, Presence, PresenceState, WebServices, ZncErrorResponse } from '../api/znc-types.js'; +import CoralApi from '../api/coral.js'; +import { ActiveEvent, Announcements, CurrentUser, Friend, Game, Presence, PresenceState, WebServices, CoralErrorResponse } from '../api/coral-types.js'; import ZncProxyApi from '../api/znc-proxy.js'; import { ErrorResponse } from '../api/util.js'; import { SavedToken } from './auth/nso.js'; @@ -25,7 +25,7 @@ export class ZncNotifications extends Loop { constructor( public storage: persist.LocalStorage, public token: string, - public nso: ZncApi, + public nso: CoralApi, public data: Omit, public user?: CoralUser, ) { @@ -178,7 +178,7 @@ export class ZncNotifications extends Loop { if (user) await this.updatePresenceForSplatNet2Monitors([user]); } - async handleError(err: ErrorResponse | NodeJS.ErrnoException): Promise { + async handleError(err: ErrorResponse | NodeJS.ErrnoException): Promise { if ('code' in err && (err as any).type === 'system' && err.code === 'ETIMEDOUT') { debug('Request timed out, waiting %ds before retrying', this.update_interval, err); diff --git a/src/common/presence.ts b/src/common/presence.ts index 41a1194..32b209c 100644 --- a/src/common/presence.ts +++ b/src/common/presence.ts @@ -3,7 +3,7 @@ import { DiscordRpcClient, findDiscordRpcClient } from '../discord/rpc.js'; import { DiscordPresencePlayTime, DiscordPresenceContext, getDiscordPresence, getInactiveDiscordPresence, DiscordPresence } from '../discord/util.js'; import { EmbeddedSplatNet2Monitor, ZncNotifications } from './notify.js'; import { getPresenceFromUrl } from '../api/znc-proxy.js'; -import { ActiveEvent, CurrentUser, Friend, Game, Presence, PresenceState, ZncErrorResponse } from '../api/znc-types.js'; +import { ActiveEvent, CurrentUser, Friend, Game, Presence, PresenceState, CoralErrorResponse } from '../api/coral-types.js'; import { ErrorResponse } from '../api/util.js'; import Loop, { LoopResult } from '../util/loop.js'; import { getTitleIdFromEcUrl } from '../index.js'; @@ -302,7 +302,7 @@ export class ZncDiscordPresence extends ZncNotifications { if (user) await this.updatePresenceForSplatNet2Monitors([user]); } - async handleError(err: ErrorResponse | NodeJS.ErrnoException): Promise { + async handleError(err: ErrorResponse | NodeJS.ErrnoException): Promise { this.discord.onError(err); return super.handleError(err); diff --git a/src/common/users.ts b/src/common/users.ts index 5df3d36..4e1f305 100644 --- a/src/common/users.ts +++ b/src/common/users.ts @@ -1,8 +1,8 @@ import createDebug from 'debug'; import * as persist from 'node-persist'; -import ZncApi from '../api/znc.js'; +import CoralApi from '../api/coral.js'; import ZncProxyApi from '../api/znc-proxy.js'; -import { Announcements, Friends, GetActiveEventResult, WebServices, ZncSuccessResponse } from '../api/znc-types.js'; +import { Announcements, Friends, GetActiveEventResult, WebServices, CoralSuccessResponse } from '../api/coral-types.js'; import { getToken, SavedToken } from './auth/nso.js'; import { Jwt } from '../util/jwt.js'; import { NintendoAccountSessionTokenJwtPayload } from '../api/na.js'; @@ -65,16 +65,16 @@ export default class Users { } } -export interface CoralUserData extends UserData { +export interface CoralUserData extends UserData { nso: T; data: SavedToken; - announcements: ZncSuccessResponse; - friends: ZncSuccessResponse; - webservices: ZncSuccessResponse; - active_event: ZncSuccessResponse; + announcements: CoralSuccessResponse; + friends: CoralSuccessResponse; + webservices: CoralSuccessResponse; + active_event: CoralSuccessResponse; } -export class CoralUser implements CoralUserData { +export class CoralUser implements CoralUserData { created_at = Date.now(); expires_at = Infinity; @@ -90,10 +90,10 @@ export class CoralUser implements CoralUserData { constructor( public nso: T, public data: SavedToken, - public announcements: ZncSuccessResponse, - public friends: ZncSuccessResponse, - public webservices: ZncSuccessResponse, - public active_event: ZncSuccessResponse, + public announcements: CoralSuccessResponse, + public friends: CoralSuccessResponse, + public webservices: CoralSuccessResponse, + public active_event: CoralSuccessResponse, ) {} private async update(key: keyof CoralUser['updated'], callback: () => Promise, ttl: number) { diff --git a/src/discord/titles/README.md b/src/discord/titles/README.md index 2d4578f..3762925 100644 --- a/src/discord/titles/README.md +++ b/src/discord/titles/README.md @@ -28,6 +28,8 @@ https://ec.nintendo.com/apps/0100f8f0000a2000/GB?lang=en-GB In this link, the title ID is `0100f8f0000a2000`. +The title ID of friends games can also be found using the Electron app, by pressing a friend's name. + ### 2. Nintendo Switch Parental Controls title download notifications The title ID of any applications you download are recorded in daily summaries in the Nintendo Switch Parental Controls app. The title doesn't need to be used and the download can be cancelled immediately - it only needs to be queued. This is recorded when queuing downloads of application titles and does not include addon content or update data titles, so the application must be archived or deleted for this to be recorded again. diff --git a/src/discord/util.ts b/src/discord/util.ts index f134635..4b6ab79 100644 --- a/src/discord/util.ts +++ b/src/discord/util.ts @@ -1,5 +1,5 @@ import DiscordRPC from 'discord-rpc'; -import { ActiveEvent, CurrentUser, Friend, Game, PresenceState } from '../api/znc-types.js'; +import { ActiveEvent, CurrentUser, Friend, Game, PresenceState } from '../api/coral-types.js'; import { defaultTitle, titles } from './titles.js'; import { product } from '../util/product.js'; import { getTitleIdFromEcUrl, hrduration } from '../util/misc.js'; diff --git a/src/index.ts b/src/index.ts index e229c06..c5c19ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,9 @@ -export { default as ZncApi } from './api/znc.js'; +export { default as CoralApi } from './api/coral.js'; +export { /** @deprecated */ default as ZncApi } from './api/coral.js'; export { default as ZncProxyApi } from './api/znc-proxy.js'; -export * as znc from './api/znc-types.js'; +export * as coral from './api/coral-types.js'; +/** @deprecated */ +export * as znc from './api/coral-types.js'; export { default as MoonApi } from './api/moon.js'; export * as moon from './api/moon-types.js'; export * as na from './api/na.js';