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 🙏

© 2025 – Pkg Stats / Ryan Hefner

knack-ts-client

v0.0.4

Published

A TypeScript SDK for an external API

Readme

Knack TypeScript SDK

A TypeScript SDK for interacting with the Knack API. This SDK provides two clients for different authentication methods:

  • KnackApiClient: For server-side applications using an API key for authentication.
  • KnackViewClient: For client-side applications using a user token for view-based requests.

Installation

npm install knack-ts-sdk

KnackApiClient (for Server-Side Use)

This client is designed for server-side applications where you can securely store your API key. It provides direct access to your Knack objects.

Usage

import { KnackApiClient } from 'knack-ts-sdk';

const client = new KnackApiClient({
  apiKey: 'YOUR_API_KEY',
  applicationId: 'YOUR_APPLICATION_ID',
});

async function main() {
  try {
    // Get all records
    const allRecords = await client.getRecords('object_1');
    console.log('All Records:', allRecords);

    // Get a single record
    const singleRecord = await client.getRecord('object_1', 'RECORD_ID');
    console.log('Single Record:', singleRecord);

    // Get records with sorting, pagination, and filtering
    const options = {
      sorting: {
        sort_field: 'field_1',
        sort_order: 'asc' as const,
      },
      pagination: {
        rows_per_page: 10,
        page: 1,
      },
      filters: {
        match: 'and' as const,
        rules: [{ field: 'field_1', operator: 'is', value: 'test' }],
      },
    };
    const filteredRecords = await client.getRecords('object_1', options);
    console.log('Filtered Records:', filteredRecords);

  } catch (error) {
    console.error(error);
  }
}

main();

API

KnackApiClient

  • constructor(config: KnackApiClientConfig)
  • getRecords<T>(objectKey: string, options?: Options): Promise<T>
  • getRecord<T>(objectKey: string, recordId: string): Promise<T>
  • createRecord<T>(objectKey: string, record: any): Promise<T>
  • updateRecord<T>(objectKey: string, recordId: string, record: any): Promise<T>
  • deleteRecord<T>(objectKey: string, recordId: string): Promise<T>

KnackApiClientConfig

  • apiKey: string
  • applicationId: string
  • apiBaseUrl?: string

KnackViewClient (for Client-Side Use)

This client is designed for client-side applications where you need to make requests on behalf of a logged-in user. It uses a user token for authentication and is limited to the permissions of the user.

Usage

import { KnackViewClient } from 'knack-ts-sdk';

// You can get the user token using Knack.getUserToken() in your app
const token = 'YOUR_USER_TOKEN';

const client = new KnackViewClient({
  token: token,
  applicationId: 'YOUR_APPLICATION_ID',
});

async function main() {
  try {
    // Get all records from a view
    const allRecords = await client.getRecords('scene_1', 'view_1');
    console.log('All Records:', allRecords);

    // Get a single record from a view
    const singleRecord = await client.getRecord('scene_1', 'view_1', 'RECORD_ID');
    console.log('Single Record:', singleRecord);

    // Get records from a view with sorting, pagination, and filtering
    const options = {
      sorting: {
        sort_field: 'field_1',
        sort_order: 'asc' as const,
      },
      pagination: {
        rows_per_page: 10,
        page: 1,
      },
      filters: {
        match: 'and' as const,
        rules: [{ field: 'field_1', operator: 'is', value: 'test' }],
      },
    };
    const filteredRecords = await client.getRecords('scene_1', 'view_1', options);
    console.log('Filtered Records:', filteredRecords);

  } catch (error) {
    console.error(error);
  }
}

main();

API

KnackViewClient

  • constructor(config: KnackViewClientConfig)
  • getRecords<T>(sceneKey: string, viewKey: string, options?: Options): Promise<T>
  • getRecord<T>(sceneKey: string, viewKey: string, recordId: string): Promise<T>
  • createRecord<T>(sceneKey: string, viewKey: string, record: any): Promise<T>
  • updateRecord<T>(sceneKey: string, viewKey: string, recordId: string, record: any): Promise<T>
  • deleteRecord<T>(sceneKey: string, viewKey: string, recordId: string): Promise<T>

KnackViewClientConfig

  • token: string
  • applicationId: string
  • apiBaseUrl?: string

Query Options

The optional options parameter can be used to enhance queries and enable pagination. They are constrained with the following types.

export interface SortOptions {
  sort_field: string;
  sort_order: 'asc' | 'desc';
}

export interface PaginationOptions {
  rows_per_page: number;
  page: number;
}

export interface FilterRule {
  field: string;
  operator: string;
  value: any;
}

export interface FilterOptions {
  match: 'and' | 'or';
  rules: FilterRule[];
}

export interface Options {
  pagination?: PaginationOptions;
  filters?: FilterOptions;
  sorting?: SortOptions;
}