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

@j2inn/haystack-client

v2.0.13

Published

Project Haystack Client

Readme

Haystack Client

A client haystack implementation written in TypeScript. Currently this API is specifically targeted to work with the FIN Framework's web server.

This library uses haystack-core.

Installation

Use the following npm command to install haystack client...

npm install @j2inn/haystack-core @j2inn/haystack-client

Note how haystack-core must be installed as a peer dependency.

Client

A set of useful high level of APIs for working with Haystack data in the FIN framework's server.

// Query all the available sites server side...
const grid = await client.read('site')

Unless you're building your own APIs, it's recommended to use the Client APIs. These APIs build on top of the fetchGrid API.

Watch

Watches are used to watch for live events on records...

// Resolve a grid with ids.
const grid = await hs.client.read('point and navName == "SAT"')

// Create a watch and give it a display name.
const watch = hs.client.watch('All SAT points', grid)

// Add event handlers. We're only interested in 'curVal' changes.
watch.changed({
  interests: ['curVal'],
  callback: (event) => console.log(event)
})

...

// Always close a watch after using it.
await watch.close()

Haystack filters can also be used to watch for specific conditions...

// Add event handlers. We're only interested in changes to curVal when it's above a certain value.
watch.changed({
	interests: ['curVal'],
	condition: 'curVal > 50°F',
	callback: (event) => console.log(event),
})

fetchVal

The fetchVal API builds on top of hsFetch. It adds all the necessary encoding and decoding of a haystack value in one API call.

const dict = await fetchVal<HDict>('/api/demo/somethingnew')

For backwards compatibility, there is also a fetchGrid that calls fetchVal.

Hayson

Decoding values from Hayson will happen transparently when the server responds with the correct MIME type.

To send Hayson, consider the following code...

const dict = await fetchVal<HDict>('/api/demo/somethingnew', {
	method: 'POST',
	headers: { 'Content-Type': HAYSON_MIME_TYPE },
	body: JSON.stringify(hval.toJSON()),
})

hsFetch

The fetch API is used by web developers to make network calls.

The hsFetch API wraps fetch and adds some additional useful behaviors...

  • Automatic background management of CSRF tokens (a.k.a. Attest Keys).
  • Additional methods to make it easier for working with Haystack data. For example, a response has a toGrid method.

This API is designed as low level. The fetchVal API builds on top of this API.

Use this API if you want to work with the web server but aren't going to work with grids.

// Call a JSON REST API...
const resp = await hsFetch('/someApi')
const someJson = await resp.json()

CSRF protection

By default, haystack-client is designed to work with FIN's web server. When used the library attempts to automatically resolve a CSRF token (attest key).

To change this behavior, implement a requestHaystackAttestKey function on globalThis to change how the attest key is acquired...

window.requestHaystackAttestKey = async (resource: string, options: RequestInit): Promise<string> {
	// TODO: request the attest key. Return a promise with an empty string when no attest key is to be used.
}