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

Constructors

Methods

  • Adds the trigger to a group (the WorkManager's membership calls).

    Parameters

    • id: string
    • group: string

    Returns Promise<void>

  • Clears the trigger's owner worker without rescheduling it.

    Parameters

    • id: string

    Returns Promise<void>

  • Aborts all shared reply-topic readers. Call when the client is no longer needed; pending publishWithResult callers will time out.

    Returns void

  • Deletes many keys in one round trip. On partial failure it rejects (ABORTED, reason PARTIAL_FAILURE); errorDetail(errorInfo(err), DeleteBulkStateFailureSchema) names the keys that survived -- retry those rather than the whole batch.

    Parameters

    • service: string
    • keys: string[]
    • publishChange: boolean = false
    • Optionalchange: ChangeNotification

    Returns Promise<Message<"virtufin.DeleteBulkStateResponse">>

  • Deletes one state value; a failure rejects (see errorInfo).

    Parameters

    • service: string
    • key: string
    • Optionalopts: {
          change?: ChangeNotification;
          etag?: string;
          includeValue?: boolean;
          publishChange?: boolean;
      }

    Returns Promise<Message<"virtufin.DeleteStateResponse">>

  • Deletes a trigger, its tags and groups.

    Parameters

    • id: string

    Returns Promise<void>

  • Reads many keys in one round trip.

    Parameters

    • service: string
    • keys: string[]

    Returns Promise<GetBulkStateResponse>

  • Gets one service's configuration. Throws with NotFound if unregistered.

    Parameters

    • name: string

    Returns Promise<GetConfigServiceResponse>

  • 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.

  • A payload schema by content type (its current one) or by hash; rejects with NotFound when there is none.

    Parameters

    • key: { contentType: string } | { hash: string }

    Returns Promise<PayloadSchema>

  • Reads one state value. Throws with NotFound if the key does not exist.

    Parameters

    • service: string
    • key: string

    Returns Promise<GetStateResponse>

  • A trigger's details; rejects with NotFound (reason NOT_FOUND) when there is none.

    Parameters

    • id: string

    Returns Promise<TriggerDetail>

  • 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. A failed call has success false, the backend's status, and its ErrorInfo in statusDetails, read with invokeErrorInfo(response).

  • 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 (see invoke for a failure's details).

  • Lists every registered service, including non-dialable entries (those that exist only to resolve Dapr component names). Contrast listServices, which returns only the backends the gateway can invoke.

    Returns Promise<ListConfigServicesResponse>

  • 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.

  • Lists the topics seen at the gateway (published to or subscribed to), sorted by name, with when each was last seen. Topics unseen for 7 days drop out.

    Returns Promise<ListTopicsResponse>

  • Lists the triggers: all, or those matching the owner, every tag filter and the group.

    Parameters

    • Optionalfilter: { group?: string; ownerWorkerId?: string; tagFilters?: Record<string, string> }

    Returns Promise<TriggerDetail[]>

  • Publishes a CloudEvent to a topic via the Pubsub service.

    Parameters

    • topic: string

      The topic name.

    • cloudevent: CloudEvent

      The CloudEvent message to publish.

    Returns Promise<Message<"virtufin.PublishResponse">>

    Resolves once the event is published; a failure rejects (see errorInfo).

  • Publishes several events in one call: each topic's events in the given order, different topics in parallel. At most 1000 events; an invalid event rejects the whole call (InvalidArgument) before anything is published.

    Parameters

    • events: { cloudevent: CloudEvent; topic: string }[]

      The events, each with its topic.

    • pace: boolean = false

      Paced publishing: the gateway holds the call while a consumer of one of the topics is behind, so a source that can wait (a replay, a bulk publish) loses no event past the stream's retention. Never for live data. A call held for the gateway's whole wait ends with ResourceExhausted and publishes nothing.

    • retryHeld: boolean = false

      With pace, publish such a refused call again until it goes through, instead of throwing.

    Returns Promise<PublishEventsResponse>

    The count published (every event). A call that published only some rejects (ABORTED, reason PARTIAL_FAILURE); errorDetail(errorInfo(err), PublishEventsFailureSchema) lists the failed indexes.

  • 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, via the shared per-reply-topic reader started by ensureReplyReader (see its documentation for why the stream is shared rather than per call).

    Parameters

    • topic: string

      The topic to publish the request to. *

    • cloudevent: CloudEvent

      The CloudEvent message to publish. *

    • replyTopic: string

      The topic to listen for responses on. *

    • Optionalopts: { correlationId?: string; timeout?: number }

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

    Returns Promise<SubscribeResponse>

    A promise resolving to the matching SubscribeResponse. *

    TimeoutError if no response arrives within the timeout.

  • Queries state with Dapr's query-state DSL, e.g. {"filter":{}}. Values are stored as text, so filters cannot match fields inside a value: query everything and filter by key.

    Requires a store whose Dapr component implements the Query API; for Redis/Valkey that means RediSearch plus queryIndexes metadata. Without it every query fails, including Dapr's {} match-everything query -- use getBulkState against known keys instead.

    Parameters

    • service: string
    • query: string
    • limit: number = 0

    Returns Promise<QueryStateResponse>

  • Registers the schema of a binary payload this caller emits (openspec api-gateway, Payload Schema Registry). Registering the same schema again changes nothing.

    Parameters

    Returns Promise<RegisterPayloadSchemaResponse>

  • Removes the trigger from a group; resolves with the groups it still belongs to. With forGroupDeletion (a DeleteGroup), empty means it is marked deleting, for the caller to delete; without, empty means it is in no group and keeps running.

    Parameters

    • id: string
    • group: string
    • forGroupDeletion: boolean = false

    Returns Promise<string[]>

  • Saves a state value. value must be valid JSON. Resolves with the value's etag after the write; any failure rejects with a ConnectError whose ErrorInfo (errorInfo(err)) names the reason, field and key.

    With publishChange, a change notification is published after the write. By default that is the Tier 0 sys.api.state.saved/deleted topic, which is right for infra state. For domain state (positions, portfolios, orders) pass change with both a topic and a cloudevent: the API publishes your event verbatim to your topic and skips the Tier 0 topic. It cannot build that event itself -- it has the key and the bytes but not the scenario, world markers, clock type or your service identity.

    Tier 0 events carry no version, so a subscriber consuming value without a read-back is assuming writes to that key are serialized. Carry a monotonic token in your own event if you need ordering. Publication is at-most-once and not atomic with the write.

    Parameters

    • service: string
    • key: string
    • value: string
    • Optionalopts: {
          change?: ChangeNotification;
          createOnly?: boolean;
          etag?: string;
          includeValue?: boolean;
          publishChange?: boolean;
          ttlSeconds?: number;
      }
      • Optionalchange?: ChangeNotification

        Publish a domain (Tier 1) event instead of the default sys.api.state.saved/deleted notification. Set topic and cloudevent together; see saveState docs.

      • OptionalcreateOnly?: boolean
      • Optionaletag?: string
      • OptionalincludeValue?: boolean
      • OptionalpublishChange?: boolean
      • OptionalttlSeconds?: number

    Returns Promise<SaveStateResponse>

  • Schedules a trigger and resolves with its id: opts.id when given (a UUID of any version, lower-case and hyphenated; one found again by rule is a derived version 5), else a generated UUID of version 7. A given id that exists rejects with reason ID_EXISTS (errorInfo(err)). When it fires, the API publishes an empty CloudEvent to targetTopic.

    Parameters

    • targetTopic: string
    • Optionalopts: {
          dueTime?: string;
          groups?: string[];
          id?: string;
          ownerWorkerId?: string;
          repeats?: number;
          schedule?: string;
          tags?: Record<string, string>;
          ttl?: string;
      }
      • OptionaldueTime?: string
      • Optionalgroups?: string[]

        The groups the trigger belongs to.

      • Optionalid?: string
      • OptionalownerWorkerId?: string
      • Optionalrepeats?: number
      • Optionalschedule?: string

        A 6-field cron expression or an @every duration.

      • Optionaltags?: Record<string, string>

        Tags for people and scripts; the display name is name.

      • Optionalttl?: string

    Returns Promise<string>

  • Subscribes to one or more pub/sub topics. Resolves once the API confirms the subscription (its response headers: daprd holds the subscription), so a request published after the await cannot outrun it.

    Read the events with for await; a stream failure, or aborting options.signal, rejects the iteration. End the subscription with close() (or await using), which ends the iteration cleanly.

    Parameters

    • topics: string[]

      Topics to subscribe to. Filtering is by topic only; discriminate further on cloudevent.type. Name topics explicitly: an empty list is not "all topics" (the server defaults it to the state-change topics).

    • Optionaloptions: { signal?: AbortSignal }

      signal cancels the subscribe and, later, the stream.

    Returns Promise<Subscription>

    The live subscription, iterable once.

  • Sets and removes tags in one atomic step; the schedule and the next firing stay.

    Parameters

    • id: string
    • set: Record<string, string> = {}
    • remove: string[] = []

    Returns Promise<void>