Skip to content

TypeScript Examples

TypeScript examples demonstrate service connectivity using gRPC-web.

Service SDKs

Package Registry
@virtufin/api Gitea npm
@virtufin/websocketmanager Gitea npm
@virtufin/workmanager Gitea npm

These publish under the @virtufin scope, so ordinary version ranges work:

"dependencies": {
  "@virtufin/api": "^0.5.0",
  "@virtufin/websocketmanager": "^0.1.0",
  "@virtufin/workmanager": "^0.7.0"
}
npm install @virtufin/api

Scoping is what makes this possible. npm resolves a private registry per scope and has no per-package mechanism, so the previous unscoped names could not be installed by name at all -- a bare npm install virtufin-api went to registry.npmjs.org, where the name is unclaimed. Consumers had to pin direct Gitea tarball URLs. If you are upgrading from that form, replace the URLs with the ranges above and rename the imports.

Authentication

Configure .npmrc (see typescript/.npmrc for the worked version):

@virtufin:registry=https://gitea.haenerconsulting.com/api/packages/virtufin/npm/
//gitea.haenerconsulting.com/api/packages/virtufin/npm/:_authToken=<token>

The host is gitea.haenerconsulting.com, not the npm.* vanity alias. Gitea advertises dist.tarball on gitea.* whatever host you query, and npm matches auth tokens by URL prefix -- so the npm.* form fetches metadata authenticated and then follows an unauthenticated redirect for the payload. Keeping both under one host lets a single token line cover them.

Key Patterns

import { WebSocketManagerClient } from "@virtufin/websocketmanager";

const client = new WebSocketManagerClient({ url: "http://localhost:5002" });
const result = await client.connect(
    "wss://stream.binance.com:9443/ws/btcusdt@depth@100ms",
    true,  // autoReconnect
);

// State store via fetch
const saved = await fetch(`${apiUrl}/v1/state/save-state`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ service: "examples", key: "key", value: "value" }),
});