@texturehq/events
v1.10.1
Published
The library of Texture events.
Readme
@texturehq/events
This package contains the official TypeScript definitions and Zod schemas for all Texture webhook events. It's designed to help you build type-safe integrations with Texture's webhook system.
Features
- Type definitions and Zod schemas for all Texture webhook events
- Version-controlled event schemas with access to all historical versions
- Runtime validation using Zod
- Full TypeScript support
Available Events
The following webhook events are supported:
Device Events
device.connected- Emitted when a device connects to Texturedevice.disconnected- Emitted when a device disconnectsdevice.discovered- Emitted when a new device is discovereddevice.updated- Emitted when device properties are updated
Command Events
command.succeeded- Emitted when a device command completes successfullycommand.failed- Emitted when a device command fails
Connection Events
connection.failed- Emitted when a device connection attempt fails
Customer Events
customer.created- Emitted when a new customer is createdcustomer.updated- Emitted when customer information is updatedcustomer.deleted- Emitted when a customer is deleted
Site Events
site.created- Emitted when a new site is createdsite.updated- Emitted when site information is updatedsite.deleted- Emitted when a site is deleted
Enrollment Events
enrollment.submitted- Emitted when a new enrollment is submittedenrollment.approved- Emitted when an enrollment is approvedenrollment.rejected- Emitted when an enrollment is rejected
Installation
npm install @texturehq/events
# or
yarn add @texturehq/eventsUsage
Latest Version
Each event type has a named export that always points to its latest version. This is the recommended way to use the package:
import { DeviceConnectedEventSchema, DeviceConnectedEvent } from "@texturehq/events";
// Example webhook handler
const handleWebhook = (event: unknown) => {
try {
// Validate and type the event using latest version
const parsedEvent = DeviceConnectedEventSchema.parse(event);
// TypeScript knows this is a DeviceConnectedEvent
console.log(parsedEvent.data.deviceId);
} catch (error) {
// Handle validation error
console.error("Invalid event format", error);
}
};Version-Specific Usage
All event schemas are versioned, and you can access any specific version directly. This is useful if you need to maintain compatibility with older event versions:
import {
DeviceConnectedEventSchema_1_0_0, // Specific version
DeviceConnectedEvent_1_0_0 // Type for specific version
} from "@texturehq/events";
// Use a specific version of the schema
const handleLegacyWebhook = (event: unknown) => {
const parsedEvent = DeviceConnectedEventSchema_1_0_0.parse(event);
// TypeScript knows this is specifically a DeviceConnectedEvent_1_0_0
};When we make changes to an event schema, we:
- Create a new versioned schema (e.g.,
DeviceConnectedEventSchema_1_1_0) - Update the main export (
DeviceConnectedEventSchema) to point to the latest version - Maintain all previous versions for backwards compatibility
Event Structure
All events follow a consistent structure:
{
type: string; // The event type (e.g., "device.connected")
version: string; // The schema version (e.g., "1.0.0")
data: { // Event-specific payload
// ... event specific fields
}
}For more details on these events and webhook integration, consult our docs or contact us.
License
MIT
