npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@obniz/obniz-now-sdk

v0.1.10

Published

TypeScript/JavaScript SDK for obniz Now API

Readme

Obniz SDK

TypeScript/JavaScript SDK for Obniz Now API

Installation

npm install @obniz/obniz-now-sdk-js

Authentication

The SDK supports authentication using an API token (Bearer token). You can obtain your API token from your Obniz account settings.

Using API Token

import { ObnizNow } from '@obniz/sdk';

const client = new ObnizNow({ 
  token: 'your-api-token-here'
});

Using Environment Variables (Recommended)

const client = new ObnizNow({ 
  token: process.env.OBNIZ_NOW_TOKEN
});

Basic Usage

List Machines

import { ObnizNow } from '@obniz/obniz-now-sdk-js';

const client = new ObnizNow({ token: process.env.OBNIZ_TOKEN });

// Get list of machines
const response = await client.machines.listMachines({ 
  limit: 10,
  offset: 0 
});

console.log(`Found ${response.count} machines`);
response.items.forEach((item) => {
  console.log(`- ${item.machine.name} (${item.machine.id})`);
});

Get Machine Details

// Get specific machine
const machine = await client.machine.getMachine({ 
  machineId: 'machine-id' 
});

console.log(`Name: ${machine.name}`);
console.log(`Created: ${machine.createdAt}`);

Get Events

// Get recent events
const events = await client.events.listEvents({
  from: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
  to: new Date().toISOString(),
  limit: 20
});

console.log(`Found ${events.count} events`);

Error Handling

All API errors are automatically converted to ObnizNowApiError with parsed response data.

import { ObnizNow, ObnizNowApiError } from '@obniz/obniz-now-sdk-js';

try {
  const machine = await client.machine.getMachine({ machineId: 'invalid-id' });
} catch (error) {
  if (error instanceof ObnizNowApiError) {
    console.error(`Error ${error.status}: ${error.message}`);
    console.error('Details:', error.data);
    
    // Access response headers
    const headers = error.getResponseHeaders();
    const rateLimit = headers.get('x-ratelimit-remaining');
    
    // Get request URL for debugging
    console.error('Failed request:', error.getRequestUrl());
  }
}

Browser Usage (Svelte)

⚠️ Security Warning

Never expose your API token in client-side code! Use one of these safe approaches:

Option 1: Cookie-based Authentication (Recommended)

// In your Svelte component
import { ObnizNow } from '@obniz/obniz-now-sdk-js';

const client = new ObnizNow({
  cookies: {
    token: getCookie('token'),
    accountId: getCookie('account_id'),
  },
});

function getCookie(name: string): string {
  const value = `; ${document.cookie}`;
  const parts = value.split(`; ${name}=`);
  if (parts.length === 2) return parts.pop()?.split(';').shift() || '';
  return '';
}

Your backend should set httpOnly cookies after user authentication.

Option 2: Backend Proxy

// Frontend - call your backend API
const machines = await fetch('/api/obniz/machines').then(r => r.json());

// Backend (Node.js) - proxy to Obniz API
app.get('/api/obniz/machines', async (req, res) => {
  const client = new ObnizNow({ token: process.env.OBNIZ_TOKEN });
  const data = await client.machines.listMachines({ limit: 20 });
  res.json(data);
});

SvelteKit Server-Side Example

// src/routes/+page.server.ts
import { ObnizNow } from '@obniz/sdk';

export async function load() {
  const client = new ObnizNow({ token: process.env.OBNIZ_TOKEN });
  const machines = await client.machines.listMachines({ limit: 20 });
  
  return { machines: machines.items };
}
<!-- src/routes/+page.svelte -->
<script lang="ts">
  export let data;
</script>

<h1>Machines</h1>
<ul>
  {#each data.machines as item}
    <li>{item.machine.name}</li>
  {/each}
</ul>

Examples

See the examples/ directory for more detailed examples:

basic-usage.ts - SDK initialization and basic operations

analytics.ts - Working with analytics

events.ts - Retrieving and filtering events

machine-management.ts - CRUD operations

custom-config.ts - Advanced configuration (retry, logging)

advanced-error-handling.ts - Error inspection and debugging

Run any example:

npx tsx examples/basic-usage.ts

Requirements

Node.js >= 18.0.0

Links

Website: https://iot.obniz.com

API documentation: https://now.obniz.com/api/1/docs/