API client for interacting with the Virtufin Gateway service. Provides service discovery, method invocation, and event subscription capabilities.

Constructors

Methods

  • Gets the schema for a specific method.

    Parameters

    • service: string

      The name of the service.

    • method: string

      The name of the method.

    • type: string

      The type of schema to retrieve (e.g., "request" or "response").

    Returns Promise<GetMethodSchemaResponse>

    A promise resolving to the GetMethodSchemaResponse.

  • Invokes a method on a backend service using raw protobuf bytes.

    Parameters

    • service: string

      The name of the target service.

    • method: string

      The name of the method to invoke.

    • requestData: Uint8Array

      The serialized protobuf request data as Uint8Array.

    Returns Promise<InvokeResponse>

    A promise resolving to the InvokeResponse.

  • Invokes a method on a backend service using JSON request/response data. This is the recommended method for most use cases.

    Parameters

    • service: string

      The name of the target service.

    • method: string

      The name of the method to invoke.

    • requestData: string

      The JSON serialized request data as string.

    Returns Promise<InvokeJsonResponse>

    A promise resolving to the InvokeJsonResponse.

  • Lists all methods available for a specific service.

    Parameters

    • service: string

      The name of the service to query.

    Returns Promise<ListMethodsResponse>

    A promise resolving to the ListMethodsResponse containing method information.

  • Lists all available services registered with the gateway.

    Returns Promise<ListServicesResponse>

    A promise resolving to the ListServicesResponse containing service names.

  • Publishes an event to a topic via the Pubsub service.

    Parameters

    • topic: string

      The topic name.

    • data: Uint8Array

      The event data as Uint8Array.

    • Optionalmetadata: Record<string, string>

      Optional metadata key-value pairs (CloudEvents extensions).

    Returns Promise<PublishResponse>

    A promise resolving to the PublishResponse.

  • Publishes to a topic and waits for a correlated response on a reply topic. Implements the request-reply pattern over pub/sub using correlation IDs.

    The Subscribe RPC is initiated and the server's response headers are awaited BEFORE the publish, so that the server-side PubsubService.Subscribe handler is running and the Dapr subscription is registered with daprd by the time we publish. The server sends its gRPC initial metadata eagerly via WriteResponseHeadersAsync once the dapr subscription is registered, so the onHeader callback is the readiness signal we use here.

    Without this, a fast worker (e.g. WSM controller in virtufin-examples) can publish the response to the reply topic before the server-side subscription chain is established, causing the response to be dropped after the client has already torn down the gRPC stream on timeout — the "Error processing Redis message ...: context canceled" race that broke Run 2 of the Binance example.

    Parameters

    • topic: string

      The topic to publish the request to.

    • data: Uint8Array

      The event data as Uint8Array.

    • replyTopic: string

      The topic to listen for responses on.

    • Optionalopts: { correlationId?: string; metadata?: Record<string, string>; timeout?: number }

      Options: timeout (ms, default 30000), metadata, correlationId.

    Returns Promise<PubsubSubscribeResponse>

    A promise resolving to the matching PubsubSubscribeResponse.

    TimeoutError if no response arrives within the timeout.

  • Subscribes to events from specified services and topics.

    Parameters

    • services: string[]

      List of service names to subscribe to (empty for all).

    • topics: string[]

      List of topics to subscribe to (empty for all).

    • eventTypes: string[]

      List of event types to subscribe to (empty for all).

    Returns AsyncIterable<TopicEventRequest>

    An async iterable yielding TopicEventRequest messages.

  • Subscribes to a pub/sub topic via the Pubsub service.

    Parameters

    • topic: string

      The topic name.

    Returns AsyncIterable<PubsubSubscribeResponse>

    An async iterable yielding PubsubSubscribeResponse messages.