messages: pure builders for every event the bridge sends
src/messages builds Response, StateReport, DeferredResponse, ErrorResponse, ChangeReport and the scene, doorbell and simple events from plain values; messageId and times are parameters, so a test compares whole objects. StateBuilder collects properties checked by the descriptors, AlexaError and AlexaErrors carry the payload fields of an error type. AlexaStatusMessage and AlexaErrorResponse move to src/compat and are written on the builders. On the wire, against 1.5.2: a DeferredResponse has no context key, a ChangeReport has no correlationToken, the namespace of an ErrorResponse follows its type, and a ChangeReport without a changed property is not published: send() resolves "" and the bridge reports an error that names the endpoint. 143 tests pass (108 before). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
2558e21787
commit
46fa06728c
68 changed files with 3410 additions and 1208 deletions
97
dist/esm/messages/build.d.ts
vendored
Normal file
97
dist/esm/messages/build.d.ts
vendored
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
import type { ChangeCause, ChangeReportMessage, DeferredResponseMessage, ErrorResponseMessage, ProactiveEventMessage, Property, ResponseMessage, SceneEventMessage } from "./types.js";
|
||||
/** A message that would be dropped on its way to Alexa, refused where it is built. */
|
||||
export declare class MessageError extends Error {
|
||||
readonly endpointId: string;
|
||||
readonly problem: string;
|
||||
constructor(endpointId: string, problem: string);
|
||||
}
|
||||
interface Envelope {
|
||||
endpointId: string;
|
||||
/** Default: a new version 4 UUID, which is what Alexa recommends (message-guide.html, "Header object"). */
|
||||
messageId?: string;
|
||||
}
|
||||
interface Answer extends Envelope {
|
||||
/** The correlationToken of the directive that is answered. */
|
||||
correlationToken: string;
|
||||
}
|
||||
export interface ResponseFields extends Answer {
|
||||
/** Default: "Response". */
|
||||
name?: string;
|
||||
/** Default: "Alexa". An interface with a response of its own names it: Alexa.SecurityPanelController, Arm.Response. */
|
||||
namespace?: string;
|
||||
payload?: Record<string, unknown>;
|
||||
/** The state of the endpoint after the directive. */
|
||||
context?: readonly Property[];
|
||||
}
|
||||
/**
|
||||
* The answer to a directive (alexa-response.html, "Synchronous response"). An endpoint with nothing to report
|
||||
* answers with an empty list of properties, not without a context (state-reporting-for-smart-home-addons.html,
|
||||
* "Directive response example for a property that isn't retrievable").
|
||||
*/
|
||||
export declare function response(fields: ResponseFields): ResponseMessage;
|
||||
/** The answer to ReportState: every retrievable property of the endpoint. */
|
||||
export declare function stateReport(fields: Answer & {
|
||||
context?: readonly Property[];
|
||||
}): ResponseMessage;
|
||||
/**
|
||||
* "The directive arrived, the answer follows": no context, the state is in the Response that follows
|
||||
* (alexa-response.html, "Deferred response example").
|
||||
*/
|
||||
export declare function deferredResponse(fields: Answer & {
|
||||
estimatedDeferralInSeconds?: number;
|
||||
}): DeferredResponseMessage;
|
||||
export interface ErrorResponseFields extends Answer {
|
||||
/** "ENDPOINT_UNREACHABLE" */
|
||||
type: string;
|
||||
/** For the log of the skill. */
|
||||
message: string;
|
||||
/** The fields a type adds to the payload: validRange, currentDeviceMode. */
|
||||
extra?: Record<string, unknown>;
|
||||
/** Default: the namespace the type is documented under, see errorNamespace(). */
|
||||
namespace?: string;
|
||||
}
|
||||
/** The answer to a directive the endpoint could not follow (alexa-errorresponse.html). */
|
||||
export declare function errorResponse(fields: ErrorResponseFields): ErrorResponseMessage;
|
||||
export interface ChangeReportFields extends Envelope {
|
||||
/** Default: "PHYSICAL_INTERACTION". */
|
||||
cause?: ChangeCause;
|
||||
/** The properties that changed, at least one. */
|
||||
changed: readonly Property[];
|
||||
/** The other properties of the endpoint, as they are now. */
|
||||
context?: readonly Property[];
|
||||
}
|
||||
/**
|
||||
* A change of state nobody asked for. The header has no correlationToken (message-guide.html, "Header object").
|
||||
* A property that changed is left out of the context: it is reported in one of the two (same page, "Context
|
||||
* object"). Throws MessageError when nothing changed: Alex2MQTT drops such a report without a word.
|
||||
*/
|
||||
export declare function changeReport(fields: ChangeReportFields): ChangeReportMessage;
|
||||
export interface SceneEventFields extends Answer {
|
||||
/** true: ActivationStarted. false: DeactivationStarted. */
|
||||
activated: boolean;
|
||||
/** Default: "VOICE_INTERACTION", a scene is started by a directive. */
|
||||
cause?: ChangeCause;
|
||||
/** When the scene started. Default: now. */
|
||||
timestamp?: string | Date;
|
||||
}
|
||||
/** The answer to Activate and Deactivate of a scene (alexa-scenecontroller.html). */
|
||||
export declare function sceneEvent(fields: SceneEventFields): SceneEventMessage;
|
||||
export interface DoorbellPressFields extends Envelope {
|
||||
/** Default: "PHYSICAL_INTERACTION", somebody pressed the button. */
|
||||
cause?: ChangeCause;
|
||||
/** When the button was pressed. Default: now. */
|
||||
timestamp?: string | Date;
|
||||
}
|
||||
/** Somebody rang (alexa-doorbelleventsource.html). */
|
||||
export declare function doorbellPress(fields: DoorbellPressFields): ProactiveEventMessage;
|
||||
export interface SimpleEventFields extends Envelope {
|
||||
/** The instance of Alexa.SimpleEventSource that raises the event. */
|
||||
instance: string;
|
||||
/** The id of the event as discovery listed it: "Button.SinglePush.1". */
|
||||
id: string;
|
||||
/** When the event happened. Default: now. */
|
||||
timestamp?: string | Date;
|
||||
}
|
||||
/** An event of a button or a sensor that routines start on (alexa-simpleeventsource.html). */
|
||||
export declare function simpleEvent(fields: SimpleEventFields): ProactiveEventMessage;
|
||||
export {};
|
||||
Loading…
Add table
Add a link
Reference in a new issue