Skip to content

Envelope Types

These are the TypeScript interfaces for the message envelopes that make up Strata's wire protocol. For conceptual background on the protocol, see The Protocol.

All envelope types are exported from the main package:

typescript
import type {
    MessageEnvelope,
    RequestEnvelope,
    PostEnvelope,
    ResponseEnvelope,
    ResponseMessage,
} from '@strata-js/strata';

MessageEnvelope

The base interface shared by all envelope types.

typescript
interface MessageEnvelope<PayloadType = Record<string, unknown>>
{
    id : string;
    messageType : 'request' | 'response' | 'post';
    context : string;
    operation : string;
    timestamp : string;
    payload : PayloadType;
}
FieldTypeDescription
idstringUnique message identifier (nanoid, 20 chars).
messageTypestringDiscriminator: 'request', 'response', or 'post'.
contextstringTarget context name.
operationstringTarget operation name.
timestampstringISO 8601 datetime.
payloadobjectApplication-specific data. Opaque to the framework.

RequestEnvelope

Sent by a client when it expects a response. Extends MessageEnvelope with messageType: 'request'.

typescript
interface RequestEnvelope<
    PayloadType = Record<string, unknown>,
    MetadataType = Record<string, unknown>,
> extends MessageEnvelope<PayloadType>
{
    messageType : 'request';
    responseQueue ?: string;
    timeout ?: number;
    metadata : MetadataType;
    auth ?: string;
    priorRequest ?: string;
    client ?: string;
    requestChain ?: string[];
}
FieldTypeRequiredDescription
responseQueuestringnoQueue where the service should send the response. Set by the backend.
timeoutnumbernoMilliseconds the client will wait. 0 or omitted uses service default.
metadataobjectyesAdditional metadata. Opaque to the framework.
authstringnoAuthentication data (typically a JWT). Passed through, never inspected.
priorRequeststringnoID of the request that triggered this one (for tracing).
clientstringnoHuman-readable client identifier.
requestChainstring[]noChain of request IDs for distributed tracing.

PostEnvelope

Sent by a client when no response is needed. Extends MessageEnvelope with messageType: 'post'.

typescript
interface PostEnvelope<
    PayloadType = Record<string, unknown>,
    MetadataType = Record<string, unknown>,
> extends MessageEnvelope<PayloadType>
{
    messageType : 'post';
    metadata : MetadataType;
    auth ?: string;
    priorRequest ?: string;
    client ?: string;
    requestChain ?: string[];
}

Same fields as RequestEnvelope, minus responseQueue and timeout.

RequestOrPostEnvelope

Union type used internally when handling either type of incoming message.

typescript
type RequestOrPostEnvelope<
    P = Record<string, unknown>,
    M = Record<string, unknown>
> = RequestEnvelope<P, M> | PostEnvelope<P, M>;

ResponseEnvelope

Sent by a service back to the client after processing a request. Extends MessageEnvelope with messageType: 'response'.

typescript
interface ResponseEnvelope<PayloadType = Record<string, unknown>>
    extends MessageEnvelope<PayloadType>
{
    id : string;
    messageType : 'response';
    context : string;
    operation : string;
    timestamp : string;
    payload : PayloadType;
    status : 'succeeded' | 'failed' | 'pending';
    messages : ResponseMessage[];
    service : string;
}
FieldTypeDescription
statusstring'succeeded', 'failed', or 'pending'.
messagesResponseMessage[]Array of structured messages generated during processing.
servicestringHuman-readable service identifier (e.g. 'UserService v1.0').

ResponseMessage

Structured messages generated during request processing. Useful for returning warnings, informational messages, or detailed error information alongside the response payload.

typescript
interface ResponseMessage<DetailsType = Record<string, unknown>>
{
    severity : ResponseMessageSeverity;
    message : string;
    code ?: string;
    type ?: string;
    details ?: DetailsType;
    stack ?: string;
}
FieldTypeRequiredDescription
severitystringyes'error', 'warning', 'info', or 'debug'.
messagestringyesHuman-readable message text.
codestringnoMachine-readable message code.
typestringnoMessage type name (typically the error class name).
detailsobjectnoAdditional structured data.
stackstringnoStack trace, if applicable. Never expose to end users.

ResponseMessageSeverity

typescript
const ResponseMessageSeverity = [ 'error', 'warning', 'info', 'debug' ] as const;
type ResponseMessageSeverity = typeof ResponseMessageSeverity[number];

Command Types

Commands are a separate messaging mechanism from requests. They control service behavior at runtime.

ServiceCommand

typescript
interface ServiceCommand<Payload = Record<string, unknown>>
{
    id : string;
    command : ValidCommandName;
    payload ?: Payload;
}

ValidCommandName

typescript
type ValidCommandName = 'info' | 'concurrency' | 'shutdown' | 'toobusy';

ServiceCommandResponse

typescript
interface ServiceCommandResponse<Payload = Record<string, unknown>>
{
    id : string;
    payload ?: Payload;
}

Specific Command Types

typescript
// Info command -- the only command with a response
interface StrataInfoCommand extends ServiceCommand<undefined>
{
    command : 'info';
    responseChannel : string;
}

// Concurrency command
interface StrataConcurrencyCommand extends ServiceCommand<StrataConcurrencyCommandPayload>
{
    command : 'concurrency';
    payload : { concurrency : number };
}

// Shutdown command
interface StrataShutdownCommand extends ServiceCommand<StrataShutdownCommandPayload>
{
    command : 'shutdown';
    payload ?: { graceful ?: boolean; exitCode ?: number };
}

// TooBusy command
interface StrataToobusyCommand extends ServiceCommand<StrataTooBusyCommandPayload>
{
    command : 'toobusy';
    payload : TooBusyConfig;
}