Skip to content

ShardlensHttp

Defined in: packages/http/src/index.ts:90

flush(): Promise<void>

Defined in: packages/http/src/index.ts:123

Waits for hashing to finish, then sends queued events. A wrapped handler given a waitUntil does this itself; use it on a platform without one, before you return.

Promise<void>


forgetUser(userId): Promise<{ erased: number; } | undefined>

Defined in: packages/http/src/index.ts:118

Deletes everything the collector stored about a user. Never throws.

string

Promise<{ erased: number; } | undefined>


isOptedOut(userId): boolean

Defined in: packages/http/src/index.ts:116

string

boolean


on(event, listener): () => void

Defined in: packages/http/src/index.ts:129

Listens for the SDK’s internal errors (tokens and request bodies removed). Returns a function that unsubscribes.

"error"

(name, error) => void

() => void


optIn(userId): void

Defined in: packages/http/src/index.ts:115

Records this user’s events again.

string

void


optOut(userId): void

Defined in: packages/http/src/index.ts:113

Drops this user’s events from now on (for example after /privacy opt-out). Persist the choice yourself.

string

void


shutdown(options?): Promise<void>

Defined in: packages/http/src/index.ts:125

Sends what is queued and stops. Call it when a long-running server stops; Workers don’t need it.

number

Promise<void>


stats(): ClientStats

Defined in: packages/http/src/index.ts:127

The SDK’s own health: queue depth, drops and internal errors.

ClientStats


track<N>(name, props?, context?, waitUntil?): void

Defined in: packages/http/src/index.ts:106

Records a custom event. Invalid events are dropped and counted, never thrown. On serverless runtimes pass the request’s ctx as waitUntil, or the event waits for the next interaction.

N extends string

N

CustomEventProps<N>

TrackContext

WaitUntilContext

void


wrapInteractionHandler<I, A, R>(handler): (interaction, …args) => Promise<Awaited<R>>

Defined in: packages/http/src/index.ts:99

Wraps the function that answers an interaction. The wrapped function records the interaction, how long your response took against Discord’s 3-second deadline, and any error (re-thrown unchanged). Return the interaction response body (or a Response) from your handler as usual.

If any argument has a waitUntil method (a Workers ExecutionContext, for example), events are sent through it after your response, so the runtime doesn’t stop before they leave. PING interactions are not recorded.

I extends RawInteraction

A extends unknown[]

R

(interaction, …args) => R | Promise<R>

(interaction, …args) => Promise<Awaited<R>>