/** * Business API - Resources and Users */ import apiClient from './client'; import { User, Resource, BusinessOAuthSettings, BusinessOAuthSettingsResponse, BusinessOAuthCredentialsResponse } from '../types'; /** * Get all resources for the current business */ export const getResources = async (): Promise => { const response = await apiClient.get('/api/resources/'); return response.data; }; /** * Get all users for the current business */ export const getBusinessUsers = async (): Promise => { const response = await apiClient.get('/api/business/users/'); return response.data; }; /** * Get business OAuth settings and available platform providers */ export const getBusinessOAuthSettings = async (): Promise => { const response = await apiClient.get<{ settings: { enabled_providers: string[]; allow_registration: boolean; auto_link_by_email: boolean; use_custom_credentials: boolean; }; available_providers: Array<{ id: string; name: string; icon: string; description: string; }>; }>('/api/business/oauth-settings/'); // Transform snake_case to camelCase return { settings: { enabledProviders: response.data.settings.enabled_providers || [], allowRegistration: response.data.settings.allow_registration, autoLinkByEmail: response.data.settings.auto_link_by_email, useCustomCredentials: response.data.settings.use_custom_credentials, }, availableProviders: response.data.available_providers || [], }; }; /** * Update business OAuth settings */ export const updateBusinessOAuthSettings = async ( settings: Partial ): Promise => { // Transform camelCase to snake_case for backend const backendData: Record = {}; if (settings.enabledProviders !== undefined) { backendData.enabled_providers = settings.enabledProviders; } if (settings.allowRegistration !== undefined) { backendData.allow_registration = settings.allowRegistration; } if (settings.autoLinkByEmail !== undefined) { backendData.auto_link_by_email = settings.autoLinkByEmail; } if (settings.useCustomCredentials !== undefined) { backendData.use_custom_credentials = settings.useCustomCredentials; } const response = await apiClient.patch<{ settings: { enabled_providers: string[]; allow_registration: boolean; auto_link_by_email: boolean; use_custom_credentials: boolean; }; available_providers: Array<{ id: string; name: string; icon: string; description: string; }>; }>('/api/business/oauth-settings/', backendData); // Transform snake_case to camelCase return { settings: { enabledProviders: response.data.settings.enabled_providers || [], allowRegistration: response.data.settings.allow_registration, autoLinkByEmail: response.data.settings.auto_link_by_email, useCustomCredentials: response.data.settings.use_custom_credentials, }, availableProviders: response.data.available_providers || [], }; }; /** * Get business OAuth credentials (custom credentials for paid tiers) */ export const getBusinessOAuthCredentials = async (): Promise => { const response = await apiClient.get<{ credentials: Record; use_custom_credentials: boolean; }>('/api/business/oauth-credentials/'); return { credentials: response.data.credentials || {}, useCustomCredentials: response.data.use_custom_credentials, }; }; /** * Update business OAuth credentials (custom credentials for paid tiers) */ export const updateBusinessOAuthCredentials = async ( data: { credentials?: Record; useCustomCredentials?: boolean; } ): Promise => { const backendData: Record = {}; if (data.credentials !== undefined) { backendData.credentials = data.credentials; } if (data.useCustomCredentials !== undefined) { backendData.use_custom_credentials = data.useCustomCredentials; } const response = await apiClient.patch<{ credentials: Record; use_custom_credentials: boolean; }>('/api/business/oauth-credentials/', backendData); return { credentials: response.data.credentials || {}, useCustomCredentials: response.data.use_custom_credentials, }; };