@sofya-sdk/api-client
v1.0.0
Published
HTTP client for Sofya backend SDK API
Maintainers
Readme
@sofya-sdk/api-client
HTTP client for Sofya backend SDK API.
Installation
pnpm add @sofya-sdk/api-clientUsage
import { BackendApiClient } from '@sofya-sdk/api-client';
const client = new BackendApiClient({
baseUrl: 'https://api.sofya.app',
authToken: 'your-auth-token', // optional
timeout: 10000, // optional, default: 10000ms
});
// Create a canal
const canal = await client.createCanal();
console.log(canal.canalId);
console.log(canal.qrCodeUrl ?? 'no-pwa-url');
console.log(canal.qrCodeBucketLink ?? 'no-image');
console.log(canal.messagingEndpoint);
console.log(canal.contract?.eventRoom.roomLink);
// Get canal configuration
const config = await client.getCanalConfig('CANAL123');
console.log(config.sttEndpoint);
console.log(config.messagingEndpoint);API
new BackendApiClient(config)
Create a new API client instance.
Config:
baseUrl(string, required) - Backend API base URLauthToken(string, optional) - Authentication tokentimeout(number, optional) - Request timeout in ms (default: 10000)
createCanal()
Create a new canal (room).
Returns: Promise<CreateCanalResponse>
interface CreateCanalResponse {
canalId: string;
qrCodeUrl: string | null;
qrCodeBucketLink: string | null;
messagingEndpoint: string | null;
sttEndpoint: string | null;
contract: CanalContract | null;
}getCanalConfig(canalId)
Get canal configuration.
Parameters:
canalId(string) - Canal ID
Returns: Promise<CanalConfig>
interface CanalConfig {
canalId: string;
sttEndpoint: string | null;
messagingEndpoint: string | null;
contract: CanalContract | null;
}Error Handling
import { BackendApiClient, BackendApiError } from '@sofya-sdk/api-client';
try {
const canal = await client.createCanal();
} catch (error) {
if (error instanceof BackendApiError) {
console.error('API Error:', error.code, error.message);
console.error('Details:', error.details);
}
}License
ISC
