@texturehq/device
TypeScript icon, indicating that this package has built-in type declarations

1.5.2 • Public • Published

@texturehq/device

npm version

A type-safe TypeScript client for working with device data in the Texture platform. This package provides strongly-typed interfaces and utilities for querying and validating device information, manufacturers, and device models.

Features

  • Type-safe API for querying device data
  • Comprehensive TypeScript definitions for all device-related entities
  • Built-in validation for device data structures
  • Utilities for working with manufacturers and device models
  • Full TypeScript support

Installation

npm install @texturehq/device
# or
yarn add @texturehq/device

Usage

Querying Manufacturers

import { getManufacturers, getManufacturer, Manufacturer } from "@texturehq/device";

// Get all manufacturers
const listManufacturers = async () => {
  const response = await getManufacturers();
  const manufacturers: Manufacturer[] = response.manufacturers;

  // Work with strongly-typed manufacturer data
  manufacturers.forEach(manufacturer => {
    console.log(manufacturer.name, manufacturer.slug);
  });
};

// Get a specific manufacturer
const getSpecificManufacturer = async () => {
  const manufacturer = await getManufacturer({ slug: "bmw" });
  console.log(manufacturer.name, manufacturer.supportedRegions);
};

Working with Device Models

import { getDeviceModels, getDeviceModel, DeviceModel } from "@texturehq/device";

// Get all device models
const listDeviceModels = async () => {
  const response = await getDeviceModels();
  const models: DeviceModel[] = response.deviceModels;

  // Access strongly-typed model information
  models.forEach(model => {
    console.log(model.name, model.manufacturer, model.capabilities);
  });
};

// Get a specific device model
const getSpecificModel = async () => {
  const model = await getDeviceModel({ slug: "i4-edrive40" });
  console.log(model.name, model.specifications);
};

Available Types

The package exports several TypeScript interfaces for working with device data:

Core Types

  • Manufacturer - Represents a device manufacturer
  • DeviceModel - Represents a specific model from a manufacturer
  • Device - Represents an individual device instance
  • DeviceCapability - Describes what a device can do
  • Region - Represents supported geographical regions

API Response Types

  • ManufacturersResponse - Response structure for manufacturer queries
  • DeviceModelsResponse - Response structure for device model queries

Error Handling

All API methods can throw the following errors:

import { DeviceError } from "@texturehq/device";

try {
  const manufacturer = await getManufacturer({ slug: "invalid-slug" });
} catch (error) {
  if (error instanceof DeviceError) {
    // Handle device-specific errors
    console.error(error.message, error.code);
  } else {
    // Handle other errors
    console.error("Unexpected error", error);
  }
}

For more details on using this package and integrating with Texture's device ecosystem, consult our documentation or contact us.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @texturehq/device

Weekly Downloads

1

Version

1.5.2

License

MIT

Unpacked Size

274 kB

Total Files

186

Last publish

Collaborators

  • texture-sam
  • wlaeri
  • victorquinn
  • rcasto