Skip to content

PURISTA API / Modules / @purista/dapr-sdk / DaprClient

Class: DaprClient

@purista/dapr-sdk.DaprClient

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

Hierarchy

Implements

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new DaprClient(config): DaprClient

Parameters

NameTypeDescription
configObject-
config.apiPrefix?stringthe 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
config.baseUrlstringthe 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
config.basicAuth?ObjectBasic-Auth information
config.basicAuth.passwordstringBasic-Auth password
config.basicAuth.usernamestringBasic-Auth username
config.bearerToken?stringAuth-Bearer token
config.clientConfig?DaprClientConfig-
config.commandPayloadAsCloudEvent?booleancommand invocations are wrapped in CloudEvent Link https://github.com/cloudevents/spec/tree/v1.0 Default ts false
config.defaultCommandTimeout?numberOverwrite the hardcoded default timeout of command invocations
config.defaultHeaders?Record<string, string>Add your default headers here These headers will be part of every request. They can be overwritten per request option
config.defaultTimeout?numberset global timeout for requests in ms Default ts 30000
config.enableHttpCompression?booleanenable HTTP compression in web server Default ts true
config.enableOpentelemetry?booleanenable Opentelemetry tracing. The client will be handled as own ressource.
config.enableRestApiExpose?booleanexpose commands as regular REST endpoints when they are configured as endpoints Default ts true
config.instanceId?stringThe 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.
config.isKeepAlive?booleanIf set to false, the HTTP client will not reuse the same connection for multiple requests. Default is true.
config.logLevel?LogLevelNamethe loglevel if no logger instance is given
config.logger?LoggerA logger instance
config.name?stringName of the client
config.pathPrefix?stringthe prefix to be used for exposing commands as endpoints expecting a event bus message Default ts purista
config.serve(options: { fetch: (request: Request) => unknown ; hostname?: string ; port?: number }) => Server<typeof IncomingMessage, typeof ServerResponse> | Http2Server | Http2SecureServerThe 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
config.serverHost?stringHost of the server. Default ts 127.0.0.1
config.serverPort?numberPort of the server. Default ts 8080
config.spanProcessor?SpanProcessorOpentelemetry span processor
config.subscriptionPayloadAsCloudEvent?booleansubscription invocations are wrapped in CloudEvent Link https://github.com/cloudevents/spec/tree/v1.0 Default ts false
config.traceId?stringCustom trace Id

Returns

DaprClient

Inherited from

HttpClient.constructor

Defined in

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

Properties

auth

Protected auth: AuthCredentials

Inherited from

HttpClient.auth

Defined in

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


baseUrl

baseUrl: URL

Inherited from

HttpClient.baseUrl

Defined in

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


config

config: Object

Type declaration

NameTypeDescription
apiPrefix?stringthe 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
baseUrlstringthe 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.passwordstringBasic-Auth password
basicAuth.usernamestringBasic-Auth username
bearerToken?stringAuth-Bearer token
clientConfig?DaprClientConfig-
commandPayloadAsCloudEvent?booleancommand invocations are wrapped in CloudEvent Link https://github.com/cloudevents/spec/tree/v1.0 Default ts false
defaultCommandTimeout?numberOverwrite 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?numberset global timeout for requests in ms Default ts 30000
enableHttpCompression?booleanenable HTTP compression in web server Default ts true
enableOpentelemetry?booleanenable Opentelemetry tracing. The client will be handled as own ressource.
enableRestApiExpose?booleanexpose commands as regular REST endpoints when they are configured as endpoints Default ts true
instanceId?stringThe 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?booleanIf set to false, the HTTP client will not reuse the same connection for multiple requests. Default is true.
logLevel?LogLevelNamethe loglevel if no logger instance is given
logger?LoggerA logger instance
name?stringName of the client
pathPrefix?stringthe prefix to be used for exposing commands as endpoints expecting a event bus message Default ts purista
serve(options: { fetch: (request: Request) => unknown ; hostname?: string ; port?: number }) => Server<typeof IncomingMessage, typeof ServerResponse> | Http2Server | Http2SecureServerThe 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?stringHost of the server. Default ts 127.0.0.1
serverPort?numberPort of the server. Default ts 8080
spanProcessor?SpanProcessorOpentelemetry span processor
subscriptionPayloadAsCloudEvent?booleansubscription invocations are wrapped in CloudEvent Link https://github.com/cloudevents/spec/tree/v1.0 Default ts false
traceId?stringCustom trace Id

Inherited from

HttpClient.config

Defined in

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


logger

logger: Logger

Inherited from

HttpClient.logger

Defined in

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


name

name: string

Inherited from

HttpClient.name

Defined in

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


spanProcessor

spanProcessor: undefined | SpanProcessor

Inherited from

HttpClient.spanProcessor

Defined in

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


timeout

timeout: number

Inherited from

HttpClient.timeout

Defined in

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


traceProvider

traceProvider: NodeTracerProvider

Inherited from

HttpClient.traceProvider

Defined in

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

Methods

delete

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

DELETE request

Type parameters

Name
T

Parameters

NameType
pathstring
options?HttpClientRequestOptions
payload?unknown

Returns

Promise<T>

Inherited from

HttpClient.delete

Defined in

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


execute

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

Helper method

Parameters

NameType
methodstring
pathstring
options?HttpClientRequestOptions
payload?unknown

Returns

Promise<any>

Throws

UnhandledError

Inherited from

HttpClient.execute

Defined in

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


get

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

GET request

Type parameters

Name
T

Parameters

NameType
pathstring
options?HttpClientRequestOptions

Returns

Promise<T>

Inherited from

HttpClient.get

Defined in

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


getApiPathForCommand

getApiPathForCommand(addess, metadata): string

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

NameType
addessEBMessageAddress
metadataObject
metadata.expose{ contentEncodingRequest?: string ; contentEncodingResponse?: string ; contentTypeRequest?: string ; contentTypeResponse?: string ; deprecated?: boolean ; inputPayload?: SchemaObject ; outputPayload?: SchemaObject ; parameter?: SchemaObject } & { http: { method: "POST" | "GET" | "PATCH" | "PUT" | "DELETE" ; openApi?: { additionalStatusCodes?: StatusCode[] ; description: string ; isSecure: boolean ; operationId?: string ; query?: QueryParameter<{}>[] ; summary: string ; tags?: string[] } ; path: string } }

Returns

string

url path of endpoint

Implementation of

HttpEventBridgeClient.getApiPathForCommand

Defined in

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


getInternalPathForCommand

getInternalPathForCommand(address): string

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

Parameters

NameType
addressEBMessageAddress

Returns

string

url path of endpoint

Implementation of

HttpEventBridgeClient.getInternalPathForCommand

Defined in

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


getInternalPathForSubscription

getInternalPathForSubscription(address): string

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

NameType
addressEBMessageAddress

Returns

string

url path of endpoint

Implementation of

HttpEventBridgeClient.getInternalPathForSubscription

Defined in

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


getTracer

getTracer(): Tracer

Returns open telemetry tracer of this service

Returns

Tracer

Tracer

Inherited from

HttpClient.getTracer

Defined in

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


getUrlAndHeader

getUrlAndHeader(path, options?): Object

Parameters

NameType
pathstring
options?HttpClientRequestOptions

Returns

Object

NameType
headersRecord<string, string>
urlURL

Inherited from

HttpClient.getUrlAndHeader

Defined in

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


invoke

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

Invoke a command

Parameters

NameTypeDescription
commandObjectCommand
command.contentEncodingstringcontent encoding of message payload
command.contentTypestringcontent type of message payload
command.correlationIdstringcorrelation id to know which command response referrs to which command
command.eventName?stringevent name for this message
command.idstringglobal unique id of message
command.messageTypeCommand-
command.otp?stringstringified Opentelemetry parent trace id
command.payloadObject-
command.payload.parameterunknown-
command.payload.payloadunknown-
command.principalId?stringprincipal id
command.receiverEBMessageAddress-
command.senderObject-
command.sender.instanceIdstringinstance id of eventbridge
command.sender.serviceNamestringthe name of the service
command.sender.serviceTargetstringthe name of the command or subscription
command.sender.serviceVersionstringthe version of the service
command.tenantId?stringprincipal id
command.timestampnumbertimestamp of message creation time
command.traceId?stringtrace id of message
headers?Record<string, string>optional HTTP header
timeout?numberthe command timeout

Returns

Promise<CommandResponse>

Implementation of

HttpEventBridgeClient.invoke

Defined in

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


isSidecarAvailable

isSidecarAvailable(): Promise<boolean>

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

Returns

Promise<boolean>

boolean

Implementation of

HttpEventBridgeClient.isSidecarAvailable

Defined in

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


patch

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

PATCH request

Type parameters

Name
T

Parameters

NameType
pathstring
payloadunknown
options?HttpClientRequestOptions

Returns

Promise<T>

Inherited from

HttpClient.patch

Defined in

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


post

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

POST request

Type parameters

Name
T

Parameters

NameType
pathstring
payloadunknown
options?HttpClientRequestOptions

Returns

Promise<T>

Inherited from

HttpClient.post

Defined in

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


put

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

PUT request

Type parameters

Name
T

Parameters

NameType
pathstring
payloadunknown
options?HttpClientRequestOptions

Returns

Promise<T>

Inherited from

HttpClient.put

Defined in

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


sendEvent

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

Send a EBMessage as event to the underlaying message infrastructure.

Parameters

NameType
messageEBMessage
headers?Record<string, string>

Returns

Promise<void>

Implementation of

HttpEventBridgeClient.sendEvent

Defined in

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


setBearerToken

setBearerToken(token): void

Set the bearer token for all following requests.

Parameters

NameTypeDescription
tokenundefined | stringthe bearer token

Returns

void

Inherited from

HttpClient.setBearerToken

Defined in

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


startActiveSpan

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

Start a child span for opentelemetry tracking

Type parameters

Name
F

Parameters

NameTypeDescription
namestringname of span
optsSpanOptionsspan options
contextundefined | Contextoptional context
fn(span: Span) => Promise<F>function to be executed within the span

Returns

Promise<F>

return value of fn

Inherited from

HttpClient.startActiveSpan

Defined in

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