"exports" gains "import" and "types" next to "require": import "alex2node" failed with ERR_PACKAGE_PATH_NOT_EXPORTED. scripts/build.mjs compiles src/ to dist/cjs, dist/esm and dist/types in a staging directory and swaps them in only when both compiler runs passed. "main" and "types" follow for resolvers that do not read "exports". Target ES6 -> ES2020, "engines": node >= 18, relative imports carry ".js" for Node's ESM loader. uuid gives way to crypto.randomUUID(); mqtt is the only runtime dependency left. Tests load the package by name. New: both entry points, the modules the builds import, dist/ equal to a fresh build, a round trip on the ES module build, and two compiled type fixtures in place of the .d.ts regexes. 22 tests pass in 5.7 s. dist/: 16 files, 79,711 B -> 25 files, 132,291 B; the npm tarball is 25,125 B. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
62 lines
3.2 KiB
TypeScript
62 lines
3.2 KiB
TypeScript
import { AlexaInterface } from "./AlexaInterface.js";
|
|
import type { AlexaInterfaceType } from "./AlexaInterface.js";
|
|
import { DisplayCategory } from "./DisplayCategory.js";
|
|
import { EventEmitter } from "events";
|
|
import type { MqttClient } from "mqtt";
|
|
import { AlexaStatusMessage } from "./AlexaStatusMessage.js";
|
|
import type { ChangeCause } from "./AlexaStatusMessage.js";
|
|
import { AlexaErrorResponse } from "./AlexaErrorResponse.js";
|
|
declare class Device extends EventEmitter {
|
|
private mqttClient;
|
|
private rootTopic;
|
|
name: string;
|
|
endpointId: string;
|
|
displayCategory: Array<DisplayCategory> | null;
|
|
description: string;
|
|
manufacturerName: string;
|
|
manufacturer: string;
|
|
model: string;
|
|
protected softwareVersion: string;
|
|
private capabilities;
|
|
/** Where a failed publish from this device or a message it built is reported; Alex2MQTT sets it (1.5.2). */
|
|
onPublishError?: (err: Error) => void;
|
|
constructor(mqttClient: MqttClient, rootTopic: string, name: string, endpointId: string, displayCategory: Array<DisplayCategory> | null, description?: string, manufacturerName?: string, manufacturer?: string, model?: string);
|
|
/** Internal (1.5.2): Alex2MQTT.connect() re-binds every registered device to its new broker client after a disconnect(). */
|
|
setMqttClient(client: MqttClient): void;
|
|
getName(): string;
|
|
setName(name: string): void;
|
|
getEndpointId(): string;
|
|
setDisplayCategory(category: DisplayCategory | DisplayCategory[]): void;
|
|
getDisplayCategory(): Array<DisplayCategory>;
|
|
setDescription(description: string): void;
|
|
getDescription(): string;
|
|
getErrorMessage(correlationToken: string): AlexaErrorResponse;
|
|
getStatusMessage(correlationToken: string, isResponse?: boolean, isDeferred?: boolean): AlexaStatusMessage;
|
|
/**
|
|
* A proactive Alexa.ChangeReport (1.5.1): add the changed properties (the default target), optionally
|
|
* .unchanged() then the others, and .send() - it goes to <root>/changeReport, which Alex2MQTT forwards to the Alexa
|
|
* event gateway with the user's token. Alexa only accepts it for capabilities registered with proactivelyReported.
|
|
*/
|
|
getChangeReport(cause?: ChangeCause): AlexaStatusMessage;
|
|
/**
|
|
* Alexa.SceneController: answer an Activate / Deactivate directive with ActivationStarted / DeactivationStarted
|
|
* (1.5.1). Resolves with the topic published to, or "" when the publish failed (never rejects, 1.5.2).
|
|
*/
|
|
sendSceneResponse(correlationToken: string, activated: boolean, cause?: ChangeCause, sendAsync?: boolean): Promise<string>;
|
|
getCapabilities(): AlexaInterface[];
|
|
setManufacturerName(name: string): void;
|
|
getManufacturerName(): string;
|
|
setManufacturer(manufacturer: string): void;
|
|
getManufacturer(): string;
|
|
setModel(model: string): void;
|
|
getModel(): string;
|
|
getSoftwareVersion(): string;
|
|
/** Add a capability. 1.5.1: options.retrievable / proactivelyReported / instance (a change report needs proactivelyReported). */
|
|
addCapability(type: AlexaInterfaceType, options?: {
|
|
retrievable?: boolean;
|
|
proactivelyReported?: boolean;
|
|
instance?: string;
|
|
}): AlexaInterface;
|
|
getJSON(): Record<string, any>;
|
|
}
|
|
export default Device;
|