Skip to content

SWU Forge Deck Stats Integration#2309

Draft
acousineau wants to merge 10 commits intoSWU-Karabast:mainfrom
acousineau:swuforge-deck-stats-integration
Draft

SWU Forge Deck Stats Integration#2309
acousineau wants to merge 10 commits intoSWU-Karabast:mainfrom
acousineau:swuforge-deck-stats-integration

Conversation

@acousineau
Copy link
Copy Markdown

Summary

Adds SWU Forge (swuforge.com) as a new stat tracking destination, following the same pattern as the existing SWUBase integration. When a game ends, results and per-card metrics are sent to SWU Forge for players who have linked their
accounts.

  • New SwuForgeHandler — handles OAuth2 token exchange, refresh, revocation, and game result delivery
  • Standard OAuth2 flow (authorization code grant + refresh tokens), with SWU Forge acting as the OAuth provider
  • Game results include leader/base as {set}_{number} card keys and per-card metrics (played, resourced, activated, drawn, discarded)
  • Link/unlink endpoints follow the same intraservice auth pattern as SWUBase

Changes

  • SwuForgeHandler.ts — New stat handler with sendGameResultAsync, linkAccountAsync, unlinkAccountAsync, token management
  • StatHandlerTypes.ts — Added SwuForge to RefreshTokenSource enum
  • DeckInterfaces.ts — Added SwuForge to DeckSource enum
  • Deck.ts — Added swuforge.com URL detection in determineDeckSource()
  • DynamoDBInterfaces.ts — Added swuforgeRefreshToken field to IUserDataEntity
  • UserFactory.ts — Added refresh token field mapping + new user default
  • statsMessages.ts — Added SwuForge source, SwuForgeSuccess message key
  • GameServer.ts — Handler instantiation, token mapping, /api/user/:userId/swuforgeLink check endpoint, /api/link-swuforge and /api/unlink-swuforge endpoints, token cleanup
  • Lobby.tsupdatePlayerSwuForgeAsync() method, wired into endGameUpdateStatsAsync() with status messages
  • env.ts — Added SWUFORGE_CLIENT_ID, SWUFORGE_CLIENT_SECRET, SWUFORGE_API_URL env vars

Environment Variables

Variable Required Description
SWUFORGE_CLIENT_ID Yes OAuth client ID for SWU Forge
SWUFORGE_CLIENT_SECRET Yes OAuth client secret for SWU Forge
SWUFORGE_API_URL No Defaults to https://swuforge.com

Test Plan

  • Verify TypeScript compilation passes (tsc --noEmit)
  • Confirm existing SWUBase and SWUStats flows are unaffected
  • Test link flow: POST /api/link-swuforge with valid authorization code
  • Test unlink flow: POST /api/unlink-swuforge as authenticated user
  • Test link status check: GET /api/user/:userId/swuforgeLink
  • Test game result delivery with linked SWU Forge player using a swuforge.com deck link
  • Verify token cleanup includes SWU Forge tokens
  • E2E: play a game to round 2+, confirm result appears in SWU Forge

@AMMayberry1 AMMayberry1 marked this pull request as draft March 28, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant