Skip to content

feat(flashnet): add @mbga/flashnet package with API-key auth#7

Merged
Quantumlyy merged 8 commits intomainfrom
Quantumlyy/flashnet-auth
Mar 29, 2026
Merged

feat(flashnet): add @mbga/flashnet package with API-key auth#7
Quantumlyy merged 8 commits intomainfrom
Quantumlyy/flashnet-auth

Conversation

@Quantumlyy
Copy link
Copy Markdown
Member

Summary

  • Adds @mbga/flashnet package with API-key authentication for the Flashnet orchestration API
  • Implements createFlashnetClient() factory, verifyAuth() action, FlashnetProvider context, and useFlashnetAuth() hook
  • Separates React exports into @mbga/flashnet/react subpath so non-React consumers can import from the root without needing React/TanStack peers
  • Includes client identity in the useFlashnetAuth query key (client.baseUrl) so switching clients properly busts the cache
  • Uses a discriminated union for FlashnetProviderProps so either client or apiKey is required (not both)
  • Adds the package to the root build pipeline and vitest config

Test plan

  • pnpm test — all flashnet and flashnet-react vitest projects pass
  • pnpm build@mbga/flashnet builds with tsup (CJS/ESM + DTS)
  • pnpm check:types — no type errors
  • Verify non-React import (import { createFlashnetClient } from '@mbga/flashnet') works without React installed
  • Verify client-switching scenario re-fetches auth status

🤖 Generated with Claude Code

Quantumlyy and others added 3 commits March 29, 2026 10:54
New package providing Flashnet authentication for MBGA apps:
- createFlashnetClient() with bearer token API-key auth
- FlashnetProvider React context + useFlashnetClient hook
- verifyAuth action to check auth status
- useFlashnetAuth hook with TanStack Query integration
- Typed error classes (FlashnetAuthError, FlashnetRequestError, etc.)
- Full test coverage (37 tests)

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
- Move React context and hooks to @mbga/flashnet/react entrypoint so
  non-React consumers importing from @mbga/flashnet don't need react
  or @tanstack/react-query installed (finding 1)
- Add @mbga/flashnet to root build script so pnpm build/release
  produces its artifacts (finding 2)
- Include client.baseUrl in useFlashnetAuth query key so switching
  clients busts the TanStack Query cache (finding 3)
- Make FlashnetProviderProps a discriminated union: apiKey is only
  required when client is absent, so <FlashnetProvider client={c} />
  is type-safe without a dummy apiKey (finding 4)
- Add test for client-switching cache scenario

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mbga-site Ready Ready Preview, Comment Mar 29, 2026 10:52am

- Add packages/flashnet/README.md with vanilla and React quick start
- Add root README entry for @mbga/flashnet
- Add site/pages/flashnet/ with overview and authentication docs
- Add Flashnet section to sidebar and vocs config
- Add FlashnetAuth component + page to vite-react example
- Add Flashnet snippet to playground page
- Update getting-started, API index, and landing page to mention Flashnet

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…pattern

Replace the incorrect API-key auth with the real Flashnet challenge-response
flow (POST /v1/auth/challenge -> sign -> POST /v1/auth/verify -> access token).

- Add createFlashnetExtension() factory with .plugin for MBGA config
- Add FlashnetSigner interface + createSignerFromConfig() adapter
- Add challengeResponse() implementing the full auth flow
- Add signIntent() for intent-based operation signing
- Add sha256() and toHex() crypto utilities (Web Crypto API)
- Rewrite FlashnetProvider to accept an extension prop
- Replace useFlashnetAuth with useSyncExternalStore-based hook
- Add useFlashnetAuthenticate mutation hook
- Remove old createFlashnetClient, verifyAuth, API-key types
- Rewrite all tests, docs, example app, and playground snippet

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ors, wire up example auth

- Clear accessToken/publicKey when re-authentication starts and on failure,
  preventing stale tokens from being used after a failed re-auth
- Wrap fetch() calls in auth.ts with try/catch so network-level failures
  (offline, DNS, CORS) surface as FlashnetChallengeError/FlashnetAuthError
  instead of raw TypeError
- Add Authenticate button to the vite-react example so the demo actually
  triggers the challenge-response flow when a wallet is connected
- Add tests for stale token clearing and network error wrapping

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…integration

Add an `extensions` field to `createConfig()` that stores typed extensions on
the config object and auto-runs their plugins. This eliminates the need for
separate providers and manual config passing.

Core changes:
- createConfig is now generic over TExtensions
- Config<TExtensions> carries the extensions type through ResolvedRegister
- Extension plugins are auto-invoked when registered via extensions field

Flashnet changes:
- Extension captures configRef in its plugin, making authenticate() callable
  without arguments
- useFlashnetExtension falls back to config.extensions.flashnet via MbgaContext
- useFlashnetAuthenticate no longer requires a config parameter
- FlashnetProvider becomes optional when using the extensions pattern

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

…ons feature

The extensions field on Config adds ~166 bytes brotlied to @mbga/core — this
is the auto-run loop for extension plugins. Consolidated the loop to avoid
duplicate evaluations and bumped the size limit from 4 kB to 4.5 kB.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Quantumlyy Quantumlyy merged commit ecd0d0a into main Mar 29, 2026
9 of 10 checks passed
@Quantumlyy Quantumlyy deleted the Quantumlyy/flashnet-auth branch March 29, 2026 11:05
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