torqvoice-com.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * The torqvoice.com stand-in, from a spec's side: what the app asked it and
  3. * whether it is currently accepting the app at all.
  4. */
  5. const STANDIN_URL = `http://127.0.0.1:${process.env.E2E_TORQVOICE_COM_PORT ?? '8028'}`
  6. export interface StandinCall {
  7. path: string
  8. body: Record<string, unknown>
  9. authorized: boolean
  10. at: number
  11. }
  12. export interface StandinState {
  13. linked: boolean
  14. calls: StandinCall[]
  15. }
  16. export async function torqvoiceComState(): Promise<StandinState> {
  17. const res = await fetch(`${STANDIN_URL}/state`)
  18. return (await res.json()) as StandinState
  19. }
  20. /** Accept or refuse the app, as the site does with a right or wrong secret. */
  21. export async function setTorqvoiceComLinked(linked: boolean): Promise<void> {
  22. await fetch(`${STANDIN_URL}/state`, {
  23. method: 'POST',
  24. headers: { 'content-type': 'application/json' },
  25. body: JSON.stringify({ linked }),
  26. })
  27. }
  28. export async function clearTorqvoiceComCalls(): Promise<void> {
  29. await fetch(`${STANDIN_URL}/state`, {
  30. method: 'POST',
  31. headers: { 'content-type': 'application/json' },
  32. body: JSON.stringify({ reset: true }),
  33. })
  34. }
  35. export function torqvoiceComUrl(): string {
  36. return STANDIN_URL
  37. }