ru

SDK Fetch

streamvi-sdk-fetch provides a TypeScript client for the StreamVi API using native fetch. The client itself does not require Axios. An Axios SDK is available separately.

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-fetch.git

During installation from Git, npm runs the library build. The repository's server example has its own dependencies, which the Fetch client itself does not require.

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-fetch';

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);
  return api.userProjectGetProjectInfoV1({
    language: 'en',
    project_id: projectId,
  });
}

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 and returns the parsed StreamVi response body. There is no Axios wrapper: do not add .data just to extract the HTTP response body. A data field inside the API response itself, if defined by that method, remains present.

Pass the token without a prefix: the configuration adds Authorization: oauth .... The API address is explicit because the configuration defaults to https://napi.streamvi.io.

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

An unsuccessful HTTP response produces a ResponseError with a response object; its status contains the HTTP code. Network errors and missing required parameters have different types, so a handler must not treat every error as an HTTP response.

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 server launch, see OAuth application. Method signatures are available in the SDK source; check current permissions and parameters in the API reference.