From a7cf0c660d98aaeeaf7deb7213e59587561135cf Mon Sep 17 00:00:00 2001 From: jaydenfyi <213395523+jaydenfyi@users.noreply.github.com> Date: Sun, 25 Jan 2026 11:02:53 +0800 Subject: [PATCH] await authProvider setup --- .claude/settings.local.json | 4 +- extensions/twitch/src/cli/test-connect.ts | 98 ----------------------- extensions/twitch/src/twitch-client.ts | 8 +- 3 files changed, 7 insertions(+), 103 deletions(-) delete mode 100644 extensions/twitch/src/cli/test-connect.ts diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 715e55ea3..d68b8894d 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -1,7 +1,9 @@ { "permissions": { "allow": [ - "Bash(pnpm build:*)" + "Bash(pnpm build:*)", + "Bash(pnpm test:*)", + "Bash(pnpm -w run test:*)" ] } } diff --git a/extensions/twitch/src/cli/test-connect.ts b/extensions/twitch/src/cli/test-connect.ts deleted file mode 100644 index 212812047..000000000 --- a/extensions/twitch/src/cli/test-connect.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { StaticAuthProvider } from "@twurple/auth"; -import { ChatClient } from "@twurple/chat"; - -type Args = { - token?: string; - clientId?: string; - username?: string; - channel?: string; - message?: string; - timeoutMs: number; -}; - -function parseArgs(argv: string[]): Args { - const args: Args = { timeoutMs: 10000 }; - for (let i = 0; i < argv.length; i += 1) { - const key = argv[i]; - const value = argv[i + 1]; - if (!key?.startsWith("--")) continue; - switch (key) { - case "--token": - args.token = value; - i += 1; - break; - case "--client-id": - args.clientId = value; - i += 1; - break; - case "--username": - args.username = value; - i += 1; - break; - case "--channel": - args.channel = value; - i += 1; - break; - case "--message": - args.message = value; - i += 1; - break; - case "--timeout-ms": - args.timeoutMs = Number(value ?? 10000); - i += 1; - break; - default: - break; - } - } - return args; -} - -async function run(): Promise { - const args = parseArgs(process.argv.slice(2)); - const token = args.token; - const clientId = args.clientId; - const username = args.username; - const channel = args.channel ?? username; - - if (!token || !clientId || !username || !channel) { - console.error( - "Usage: npx tsx src/cli/test-connect.ts --token --client-id --username --channel [--timeout-ms 10000]", - ); - process.exit(2); - } - - const normalizedToken = token.startsWith("oauth:") ? token.slice(6) : token; - - const authProvider = new StaticAuthProvider(clientId, normalizedToken); - const client = new ChatClient({ - authProvider, - requestMembershipEvents: true, - }); - - const timeout = setTimeout( - () => { - console.error("Timed out waiting for connection."); - process.exit(1); - }, - Number.isFinite(args.timeoutMs) ? args.timeoutMs : 10000, - ); - - try { - await Promise.resolve(client.connect()); - await Promise.resolve(client.join(channel)); - console.log(`Connected as ${username} and joined #${channel}`); - if (args.message) { - await Promise.resolve(client.say(channel, args.message)); - console.log("Message sent."); - } - } finally { - clearTimeout(timeout); - client.quit(); - } -} - -run().catch((error) => { - console.error(error instanceof Error ? error.message : String(error)); - process.exit(1); -}); diff --git a/extensions/twitch/src/twitch-client.ts b/extensions/twitch/src/twitch-client.ts index 1588afe92..c0ba7d7b3 100644 --- a/extensions/twitch/src/twitch-client.ts +++ b/extensions/twitch/src/twitch-client.ts @@ -17,10 +17,10 @@ export class TwitchClientManager { /** * Create an auth provider for the account. */ - private createAuthProvider( + private async createAuthProvider( account: TwitchAccountConfig, normalizedToken: string, - ): StaticAuthProvider | RefreshingAuthProvider { + ): Promise { if (!account.clientId) { throw new Error("Missing Twitch client ID"); } @@ -34,7 +34,7 @@ export class TwitchClientManager { // Use addUserForToken to figure out the user ID from the token // This works whether we have a refresh token or not - authProvider + await authProvider .addUserForToken({ accessToken: normalizedToken, refreshToken: account.refreshToken ?? null, @@ -123,7 +123,7 @@ export class TwitchClientManager { const normalizedToken = normalizeToken(tokenResolution.token); // Create auth provider - const authProvider = this.createAuthProvider(account, normalizedToken); + const authProvider = await this.createAuthProvider(account, normalizedToken); const channel = account.channel ?? account.username;