Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

1.1 KB
Raw Blame
import { api } from '@/lib/apiClient';
import type { UsageInfo } from '@/data/remote/usageApi';

type StripeSessionResponse = {
  url: string;
  provider: 'stripe';
};

function isStripeSessionResponse(response: unknown): response is StripeSessionResponse {
  return (
    response !== null &&
    typeof response === 'object' &&
    'url' in response &&
    typeof response.url === 'string' &&
    response.url.trim().length > 0 &&
    'provider' in response &&
    response.provider === 'stripe'
  );
}

export async function createStripeBillingPortalSession(): Promise<string> {
  const response = await api.post<unknown>('/api/stripe/portal');
  if (!isStripeSessionResponse(response)) {
    throw new Error('Invalid Stripe billing portal response');
  }
  return response.url;
}

export async function reconcileMobileBilling(
  platform: 'ios' | 'android',
  sessionCookie?: string,
): Promise<UsageInfo> {
  return api.post<UsageInfo>(
    '/api/billing/reconcile',
    { platform },
    sessionCookie ? { authenticated: false, headers: { Cookie: sessionCookie } } : undefined,
  );
}