Skip to content

@purista/dapr-sdk v2.0.5


PURISTA API / @purista/dapr-sdk / DaprClient

Class: DaprClient

Defined in: dapr-sdk/src/DaprClient/DaprClient.impl.ts:17

The HttpEventBridgeClient connects the HTTPEventBridge with the sidecar service. This client is responsible for the communication to the sidecar service.

Extends

Implements

Constructors

new DaprClient()

new DaprClient(config): DaprClient

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:28

Parameters

config
apiPrefix?

string

the prefix to be used if the command is configured as REST api endpoint according to the OpenAPI defintion needs to enableRestApiExpose set to true

Default

ts
/api
baseUrl

string

the base url to be used

Example

typescript
const config = {
  baseUrl: 'http://localhost/api`
}
// each request will be below http://localhost/api
// get('v1/orders') will call http://localhost/api/v1/orders
basicAuth?

{ password: string; username: string; }

Basic-Auth information

basicAuth.password

string

Basic-Auth password

basicAuth.username

string

Basic-Auth username

bearerToken?

string

Auth-Bearer token

clientConfig?

DaprClientConfig

commandPayloadAsCloudEvent?

boolean

command invocations are wrapped in CloudEvent

Link

https://github.com/cloudevents/spec/tree/v1.0

Default

ts
false
defaultCommandTimeout?

number

Overwrite the hardcoded default timeout of command invocations

defaultHeaders?

Record<string, string>

Add your default headers here These headers will be part of every request. They can be overwritten per request option

defaultTimeout?

number

set global timeout for requests in ms

Default

ts
30000
enableHttpCompression?

boolean

enable HTTP compression in web server

Default

ts
true
enableOpentelemetry?

boolean

enable Opentelemetry tracing. The client will be handled as own resource.

enableRestApiExpose?

boolean

expose commands as regular REST endpoints when they are configured as endpoints

Default

ts
true
instanceId?

string

The instance id of the event bridge. If not set, a id will generated each time a instance is created. Use this if there is a need to always have the same instance id.

isKeepAlive?

boolean

If set to false, the HTTP client will not reuse the same connection for multiple requests. Default is true.

logger?

Logger

A logger instance

logLevel?

LogLevelName

the loglevel if no logger instance is given

name?

string

Name of the client

pathPrefix?

string

the prefix to be used for exposing commands as endpoints expecting a event bus message

Default

ts
purista
serve

(options) => Server<typeof IncomingMessage, typeof ServerResponse> | Http2Server<typeof IncomingMessage, typeof ServerResponse, typeof Http2ServerRequest, typeof Http2ServerResponse> | Http2SecureServer<typeof IncomingMessage, typeof ServerResponse, typeof Http2ServerRequest, typeof Http2ServerResponse>

The serve function is depending on the runtime.

  • Bun: Bun.serve
  • Node.js: serve function from additional package @hono/hono-node-server
  • Deno: serve function from package https://deno.land/std/http/server.ts

See

https://hono.dev

serverHost?

string

Host of the server.

Default

ts
127.0.0.1
serverPort?

number

Port of the server.

Default

ts
8080
spanProcessor?

SpanProcessor

Opentelemetry span processor

subscriptionPayloadAsCloudEvent?

boolean

subscription invocations are wrapped in CloudEvent

Link

https://github.com/cloudevents/spec/tree/v1.0

Default

ts
false
traceId?

string

Custom trace Id

Returns

DaprClient

Inherited from

HttpClient.constructor

Properties

auth

protected auth: AuthCredentials

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:27

Inherited from

HttpClient.auth


baseUrl

baseUrl: URL

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:24

Inherited from

HttpClient.baseUrl


config

config: object

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:22

apiPrefix?

optional apiPrefix: string

the prefix to be used if the command is configured as REST api endpoint according to the OpenAPI defintion needs to enableRestApiExpose set to true

Default
ts
/api

baseUrl

baseUrl: string

the base url to be used

Example
typescript
const config = {
  baseUrl: 'http://localhost/api`
}
// each request will be below http://localhost/api
// get('v1/orders') will call http://localhost/api/v1/orders

basicAuth?

optional basicAuth: object

Basic-Auth information

basicAuth.password

basicAuth.password: string

Basic-Auth password

basicAuth.username

basicAuth.username: string

Basic-Auth username

bearerToken?

optional bearerToken: string

Auth-Bearer token

clientConfig?

optional clientConfig: DaprClientConfig

commandPayloadAsCloudEvent?

optional commandPayloadAsCloudEvent: boolean

command invocations are wrapped in CloudEvent

https://github.com/cloudevents/spec/tree/v1.0

Default
ts
false

defaultCommandTimeout?

optional defaultCommandTimeout: number

Overwrite the hardcoded default timeout of command invocations

defaultHeaders?

optional defaultHeaders: Record<string, string>

Add your default headers here These headers will be part of every request. They can be overwritten per request option

defaultTimeout?

optional defaultTimeout: number

set global timeout for requests in ms

Default
ts
30000

enableHttpCompression?

optional enableHttpCompression: boolean

enable HTTP compression in web server

Default
ts
true

enableOpentelemetry?

optional enableOpentelemetry: boolean

enable Opentelemetry tracing. The client will be handled as own resource.

enableRestApiExpose?

optional enableRestApiExpose: boolean

expose commands as regular REST endpoints when they are configured as endpoints

Default
ts
true

instanceId?

optional instanceId: string

The instance id of the event bridge. If not set, a id will generated each time a instance is created. Use this if there is a need to always have the same instance id.

isKeepAlive?

optional isKeepAlive: boolean

If set to false, the HTTP client will not reuse the same connection for multiple requests. Default is true.

logger?

optional logger: Logger

A logger instance

logLevel?

optional logLevel: LogLevelName

the loglevel if no logger instance is given

name?

optional name: string

Name of the client

pathPrefix?

optional pathPrefix: string

the prefix to be used for exposing commands as endpoints expecting a event bus message

Default
ts
purista

serve()

serve: (options) => Server<typeof IncomingMessage, typeof ServerResponse> | Http2Server<typeof IncomingMessage, typeof ServerResponse, typeof Http2ServerRequest, typeof Http2ServerResponse> | Http2SecureServer<typeof IncomingMessage, typeof ServerResponse, typeof Http2ServerRequest, typeof Http2ServerResponse>

The serve function is depending on the runtime.

  • Bun: Bun.serve
  • Node.js: serve function from additional package @hono/hono-node-server
  • Deno: serve function from package https://deno.land/std/http/server.ts
Parameters
options
fetch

(request) => unknown

hostname?

string

port?

number

Returns

Server<typeof IncomingMessage, typeof ServerResponse> | Http2Server<typeof IncomingMessage, typeof ServerResponse, typeof Http2ServerRequest, typeof Http2ServerResponse> | Http2SecureServer<typeof IncomingMessage, typeof ServerResponse, typeof Http2ServerRequest, typeof Http2ServerResponse>

See

https://hono.dev

serverHost?

optional serverHost: string

Host of the server.

Default
ts
127.0.0.1

serverPort?

optional serverPort: number

Port of the server.

Default
ts
8080

spanProcessor?

optional spanProcessor: SpanProcessor

Opentelemetry span processor

subscriptionPayloadAsCloudEvent?

optional subscriptionPayloadAsCloudEvent: boolean

subscription invocations are wrapped in CloudEvent

https://github.com/cloudevents/spec/tree/v1.0

Default
ts
false

traceId?

optional traceId: string

Custom trace Id

Inherited from

HttpClient.config


logger

logger: Logger

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:21

Inherited from

HttpClient.logger


name

name: string

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:20

Inherited from

HttpClient.name


spanProcessor

spanProcessor: undefined | SpanProcessor

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:25

Inherited from

HttpClient.spanProcessor


timeout

timeout: number

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:23

Inherited from

HttpClient.timeout


traceProvider

traceProvider: NodeTracerProvider

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:26

Inherited from

HttpClient.traceProvider

Methods

delete()

delete<T>(path, options?, payload?): Promise<T>

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:97

DELETE request

Type Parameters

T

Parameters

path

string

options?

HttpClientRequestOptions

payload?

unknown

Returns

Promise<T>

Inherited from

HttpClient.delete


execute()

protected execute(method, path, options?, payload?): Promise<any>

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:62

Helper method

Parameters

method

string

path

string

options?

HttpClientRequestOptions

payload?

unknown

Returns

Promise<any>

Throws

UnhandledError

Inherited from

HttpClient.execute


get()

get<T>(path, options?): Promise<T>

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:69

GET request

Type Parameters

T

Parameters

path

string

options?

HttpClientRequestOptions

Returns

Promise<T>

Inherited from

HttpClient.get


getApiPathForCommand()

getApiPathForCommand(addess, metadata): string

Defined in: dapr-sdk/src/DaprClient/DaprClient.impl.ts:28

Generate the url path of the command based on the command builder exposeAsHttpEndpoint settings. This url is a POST endpoint and expects the payload and parameter as defined for exposing.

Parameters

addess

EBMessageAddress

metadata
expose

object & object

Returns

string

url path of endpoint

Implementation of

HttpEventBridgeClient.getApiPathForCommand


getInternalPathForCommand()

getInternalPathForCommand(address): string

Defined in: dapr-sdk/src/DaprClient/DaprClient.impl.ts:23

Generate the url path of the command. This url is a POST endpoint and expects a command message as payload

Parameters

address

EBMessageAddress

Returns

string

url path of endpoint

Implementation of

HttpEventBridgeClient.getInternalPathForCommand


getInternalPathForSubscription()

getInternalPathForSubscription(address): string

Defined in: dapr-sdk/src/DaprClient/DaprClient.impl.ts:18

Generate the url path of the subscription. This url is a POST endpoint. The expected payload is a EBMessage or an CloudEvent with an EBMessage as data depending on config settings

Parameters

address

EBMessageAddress

Returns

string

url path of endpoint

Implementation of

HttpEventBridgeClient.getInternalPathForSubscription


getTracer()

getTracer(): Tracer

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:34

Returns open telemetry tracer of this service

Returns

Tracer

Tracer

Inherited from

HttpClient.getTracer


getUrlAndHeader()

protected getUrlAndHeader(path, options?): object

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:44

Parameters

path

string

options?

HttpClientRequestOptions

Returns

object

headers

headers: Record<string, string>

url

url: URL

Inherited from

HttpClient.getUrlAndHeader


invoke()

invoke(command, headers?, timeout?): Promise<CommandResponse>

Defined in: dapr-sdk/src/DaprClient/DaprClient.impl.ts:33

Invoke a command

Parameters

command

Command

contentEncoding

string

content encoding of message payload

contentType

string

content type of message payload

correlationId

string

correlation id to know which command response referrs to which command

eventName?

string

event name for this message

id

string

global unique id of message

messageType

Command

otp?

string

stringified Opentelemetry parent trace id

payload

{ parameter: unknown; payload: unknown; }

payload.parameter

unknown

payload.payload

unknown

principalId?

string

principal id

receiver

EBMessageAddress

sender

{ instanceId: string; serviceName: string; serviceTarget: string; serviceVersion: string; }

sender.instanceId

string

instance id of eventbridge

sender.serviceName

string

the name of the service

sender.serviceTarget

string

the name of the command or subscription

sender.serviceVersion

string

the version of the service

tenantId?

string

principal id

timestamp

number

timestamp of message creation time

traceId?

string

trace id of message

headers?

Record<string, string>

optional HTTP header

timeout?

number

the command timeout

Returns

Promise<CommandResponse>

Implementation of

HttpEventBridgeClient.invoke


isSidecarAvailable()

isSidecarAvailable(): Promise<boolean>

Defined in: dapr-sdk/src/DaprClient/DaprClient.impl.ts:63

Checks if the sidecar container is available to be able to send events and invoke commands

Returns

Promise<boolean>

boolean

Implementation of

HttpEventBridgeClient.isSidecarAvailable


patch()

patch<T>(path, payload, options?): Promise<T>

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:90

PATCH request

Type Parameters

T

Parameters

path

string

payload

unknown

options?

HttpClientRequestOptions

Returns

Promise<T>

Inherited from

HttpClient.patch


post()

post<T>(path, payload, options?): Promise<T>

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:76

POST request

Type Parameters

T

Parameters

path

string

payload

unknown

options?

HttpClientRequestOptions

Returns

Promise<T>

Inherited from

HttpClient.post


put()

put<T>(path, payload, options?): Promise<T>

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:83

PUT request

Type Parameters

T

Parameters

path

string

payload

unknown

options?

HttpClientRequestOptions

Returns

Promise<T>

Inherited from

HttpClient.put


sendEvent()

sendEvent(message, headers?): Promise<void>

Defined in: dapr-sdk/src/DaprClient/DaprClient.impl.ts:48

Send a EBMessage as event to the underlaying message infrastructure.

Parameters

message

EBMessage

headers?

Record<string, string>

Returns

Promise<void>

Implementation of

HttpEventBridgeClient.sendEvent


setBearerToken()

setBearerToken(token): void

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:52

Set the bearer token for all following requests.

Parameters

token

the bearer token

undefined | string

Returns

void

Inherited from

HttpClient.setBearerToken


startActiveSpan()

startActiveSpan<F>(name, opts, context, fn): Promise<F>

Defined in: core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:43

Start a child span for opentelemetry tracking

Type Parameters

F

Parameters

name

string

name of span

opts

SpanOptions

span options

context

optional context

undefined | Context

fn

(span) => Promise<F>

function to be executed within the span

Returns

Promise<F>

return value of fn

Inherited from

HttpClient.startActiveSpan