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

@safercity/sdk

v0.0.1

Published

Official SaferCity API client for TypeScript/JavaScript

Downloads

70

Readme

@safercity/sdk

Official SaferCity API client for TypeScript/JavaScript.

Installation

npm install @safercity/sdk
# or
bun add @safercity/sdk
# or
yarn add @safercity/sdk

Quick Start

import { createSaferCityClient } from '@safercity/sdk';

const client = createSaferCityClient({
  baseUrl: 'https://api.safercity.com',
  token: 'your-jwt-token',
  tenantId: 'your-tenant-id',
});

// Health check
const { data: health } = await client.health.check();
console.log('API Status:', health.status);

// Get user
const { data: user } = await client.users.get('user-123');
console.log('User:', user);

// Create panic
const { data: panic } = await client.panics.create({
  userId: 'user-123',
  latitude: -26.2041,
  longitude: 28.0473,
});
console.log('Panic created:', panic.id);

Authentication

JWT Token

const client = createSaferCityClient({
  baseUrl: 'https://api.safercity.com',
  token: jwtToken, // Your JWT token
});

// Update token later
client.setToken(newToken);

OAuth Token Flow

const client = createSaferCityClient({
  baseUrl: 'https://api.safercity.com',
});

// Get access token
const { data: tokens } = await client.oauth.token({
  grant_type: 'client_credentials',
  tenantId: 'your-tenant-id',
});

// Set token on client
client.setToken(tokens.access_token);

Streaming (SSE)

Stream real-time panic updates:

for await (const event of client.panics.streamUpdates('panic-123')) {
  console.log('Update:', JSON.parse(event.data));
}

API Reference

Health

  • client.health.check() - Check API status

Authentication

  • client.auth.whoami() - Get current auth context
  • client.oauth.token(body) - Get access token
  • client.oauth.refresh(body) - Refresh token
  • client.oauth.introspect(body) - Introspect token
  • client.oauth.revoke(body) - Revoke token

Users

  • client.users.create(body) - Create user
  • client.users.list(query?) - List users
  • client.users.get(userId) - Get user by ID
  • client.users.update(userId, body) - Update user
  • client.users.delete(userId) - Delete user

Panics

  • client.panics.create(body) - Create panic
  • client.panics.get(panicId, query?) - Get panic
  • client.panics.list(query?) - List panics
  • client.panics.updateLocation(panicId, body) - Update location
  • client.panics.cancel(panicId, body) - Cancel panic
  • client.panics.streamUpdates(panicId) - Stream updates (SSE)

Subscriptions

  • client.subscriptions.listTypes() - List subscription types
  • client.subscriptions.create(body) - Create subscription
  • client.subscriptions.list(query?) - List subscriptions
  • client.subscriptions.stats() - Get stats

Location Safety

  • client.locationSafety.check(query) - Check location safety

Crimes

  • client.crimes.list(query?) - List crimes
  • client.crimes.categories() - Get crime categories
  • client.crimes.types() - Get crime types

Error Handling

import { SaferCityApiError } from '@safercity/sdk';

try {
  await client.users.get('invalid-id');
} catch (error) {
  if (error instanceof SaferCityApiError) {
    console.log('API Error:', error.error);
    console.log('Message:', error.message);
    console.log('Status:', error.status);
  }
}

Custom Fetch

For environments with custom fetch requirements:

import { createSaferCityClient } from '@safercity/sdk';

const client = createSaferCityClient({
  baseUrl: 'https://api.safercity.com',
  fetch: customFetchImplementation,
});

Related Packages

  • @safercity/sdk-react - React hooks with TanStack Query
  • @safercity/sdk-react-native - React Native support with expo-fetch

License

MIT