apiKeyQr.ts 845 B

1234567891011121314151617181920212223242526
  1. /**
  2. * Helpers for the API-key QR code.
  3. *
  4. * The QR encodes the Bambuddy base URL and the freshly-created API key together
  5. * so a mobile client can scan one code to configure both.
  6. *
  7. * Payload contract (fixed — bump `v` if it changes):
  8. * bambuddy://config?v=1&url=<encodeURIComponent(baseUrl)>&key=<encodeURIComponent(apiKey)>
  9. */
  10. /** Current payload schema version. */
  11. export const API_KEY_QR_VERSION = 1;
  12. /**
  13. * Build the QR payload string encoding the base URL + API key.
  14. *
  15. * @param baseUrl Origin a client uses to reach Bambuddy (origin only, no path).
  16. * @param apiKey Raw API key string.
  17. */
  18. export function buildApiKeyQrPayload(baseUrl: string, apiKey: string): string {
  19. return (
  20. `bambuddy://config?v=${API_KEY_QR_VERSION}` +
  21. `&url=${encodeURIComponent(baseUrl)}` +
  22. `&key=${encodeURIComponent(apiKey)}`
  23. );
  24. }