> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hoplynk.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript SDK

> Official TypeScript/JavaScript SDK for the Hoplynk API.

## Install

```bash theme={null}
npm install @hoplynk/sdk
```

## Initialize

```typescript theme={null}
import { HoplynkClient } from '@hoplynk/sdk'

const client = new HoplynkClient({ apiKey: process.env.HOPLYNK_API_KEY })
```

***

## Kits

```typescript theme={null}
// List all kits
const kits = await client.getAssets(kitId)

// GPS
const loc = await client.getLocation(kitId)
console.log(loc.lat, loc.lon, loc.source)

// Full telemetry
const snap = await client.getTelemetry(kitId, assetId)
```

***

## Pushing locations (partner assets)

Register a partner-managed asset once, then push GPS fixes as often as you like.

```typescript theme={null}
// 1. Create the asset (once)
const asset = await client.createAsset(kitId, {
  name: 'Skydio X10',
  type: 'drone',
  vendor: 'Skydio',
})

// 2. Push location whenever you have a fix
await client.pushLocation(kitId, asset.id as string, {
  lat: 31.1234,
  lon: -93.4567,
  alt_m: 120.5,
  bearing: 245.0,
})

// Continuous loop at 1 Hz
setInterval(async () => {
  const { lat, lon } = gps.read()
  await client.pushLocation(kitId, asset.id as string, { lat, lon })
}, 1000)
```

***

## Streaming

```typescript theme={null}
// Kit-level stream
const stream = client.stream({ kitId, feeds: ['gps', 'starlink'], interval: 1 })

stream.on('ready', ({ feeds }) => console.log('streaming', feeds))
stream.on('data', ({ feed, payload, ts }) => {
  if (feed === 'gps') console.log(payload.lat, payload.lon)
})
stream.on('error', ({ message }) => console.error(message))
stream.on('close', () => console.log('disconnected'))

// Stop:
stream.close()
```

***

## TypeScript types

```typescript theme={null}
import type {
  GpsPayload,
  StatusPayload,
  TelemetrySnapshot,
  StreamEvent,
} from '@hoplynk/sdk'
```

### `GpsPayload`

| Field       | Type             | Description                                            |
| ----------- | ---------------- | ------------------------------------------------------ |
| `lat`       | `number`         | Latitude (degrees)                                     |
| `lon`       | `number`         | Longitude (degrees)                                    |
| `alt_m`     | `number \| null` | Altitude (meters)                                      |
| `source`    | `string`         | `starlink` · `starlink_cached` · `cellular` · `manual` |
| `stale`     | `boolean`        | `true` if fix is older than 30s                        |
| `timestamp` | `string \| null` | ISO 8601 UTC                                           |

### `StatusPayload`

| Field                 | Type             | Description             |
| --------------------- | ---------------- | ----------------------- |
| `downlink_mbps`       | `number \| null` | Download throughput     |
| `uplink_mbps`         | `number \| null` | Upload throughput       |
| `pop_ping_latency_ms` | `number \| null` | Latency to Starlink POP |
| `alerts`              | `string[]`       | Active alerts           |
