ru

SDK Axios

streamvi-sdk provides a TypeScript client for the StreamVi API using Axios. It fits a server application that already uses Axios. For an alternative transport, see SDK Fetch.

Installation

You need Git, npm and a supported Node.js release compatible with engines in package.json. Install the library from GitHub:

npm install git+https://github.com/StreamVi/streamvi-sdk.git

During installation from Git, npm runs the library build. The repository's example/ directory belongs to a separate demonstration server; its OAuth environment variables are not required for every API request.

First request

Obtain access_token and the internal numeric project_id after an OAuth connection. Reading project information requires project:read. Pass these values to this server function:

import { ProjectApi, StreamViSdkConfig } from 'streamvi-sdk';

export async function getProjectInfo(accessToken: string, projectId: number) {
  const config = new StreamViSdkConfig({
    accessToken,
    basePath: 'https://api-v2.streamvi.io',
  });
  const api = new ProjectApi(config.configuration);
  const response = await api.userProjectGetProjectInfoV1({
    language: 'en',
    project_id: projectId,
  });
  return response.data;
}

You do not need to pass v in this call: the SDK adds v=1 to the HTTP request automatically. The generated type retains this parameter from the API schema, but it is optional.

The client sends GET /method/project/get_project_info. response is an Axios response and response.data contains the StreamVi response body.

Pass the token without a prefix: StreamViSdkConfig adds the Authorization: oauth ... header. The API address is explicit because the configuration defaults to a different address, https://napi.streamvi.io. Do not substitute an external project ID for the internal one.

Upgrading

Read the release notes and check your application’s TypeScript build before upgrading. Keep package-lock.json in your project to record the installed revision.

Errors and reconnection

Handle rejected Promises in your application. For an Axios HTTP error, the status is in error.response?.status; a network failure may have no response. Do not write the entire error object to a public log: the request configuration contains the token.

The SDK does not perform OAuth or refresh the token automatically. After reconnecting, assign the new token to config.accessToken: subsequent requests from existing clients using this configuration use it. Create separate configurations for different connections. Keep the application secret and server OAuth token on the server.

For a full server launch, see OAuth application. Generated classes and their parameters are listed in the SDK repository; access to each method depends on its contract and permissions.