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

@rssa-project/api

v1.2.3

Published

[![npm version](https://img.shields.io/npm/v/@rssa-project/api.svg)](https://www.npmjs.com/package/@rssa-project/api) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Downloads

114

Readme

RSSA React API (@rssa-project/api)

npm version License: MIT

A React library for interacting with the RSSA Platform API. This library provides a typed client, hooks for accessing study configuration, and context providers for participant management.

Installation

Install via npm or yarn from the GitHub Package Registry. Ensure your project is configured to look for @rssa-project packages in the GitHub registry.

npm install @rssa-project/api

Setup

Wrap your application (or the suitable part of your component tree) with ParticipantProvider and StudyProvider.

1. ParticipantProvider

Manages the participant's JWT. It persists the token to localStorage and provides it to the rest of the app.

  • storageKeyPrefix (optional): A string to prefix the local storage key. Useful if hosting multiple studies on the same domain to prevent session collision.

2. StudyProvider

Initializes the RssaClient with your study's credentials.

  • config: An object containing apiUrlBase, apiKeyId, apiKeySecret, and studyId.

Example

import { ParticipantProvider, StudyProvider } from '@rssa-project/api';

const config = {
	apiUrlBase: 'https://api.rssa-project.org', // Replace with your API URL
	apiKeyId: 'input-your-api-key-id',
	apiKeySecret: 'input-your-api-key-secret',
	studyId: 'input-your-study-id',
};

function App() {
	return (
		<ParticipantProvider storageKeyPrefix={config.studyId}>
			<StudyProvider config={config}>
				<YourAppContent />
			</StudyProvider>
		</ParticipantProvider>
	);
}

Usage

useStudy Hook

Access the studentApi instance (the RssaClient) to make authenticated requests.

import { useStudy } from '@rssa-project/api';
import { useEffect, useState } from 'react';

const MyComponent = () => {
	const { studyApi } = useStudy();
	const [data, setData] = useState(null);

	useEffect(() => {
		// Example: Fetch strict typed data
		studyApi.get('/some/endpoint').then(setData).catch(console.error);
	}, [studyApi]);

	return <div>{JSON.stringify(data)}</div>;
};

useParticipant Hook

Access or modify the current participant's session token directly.

import { useParticipant } from '@rssa-project/api';

const LogoutButton = () => {
	const { setJwt } = useParticipant();
	return <button onClick={() => setJwt(null)}>Logout</button>;
};

useStudyConfig Hook

Fetch the full configuration for the current study, including steps, pages, and conditions.

import { useStudyConfig } from '@rssa-project/api';

const ConfigDisplay = () => {
	const { data: studyConfig, isLoading, error } = useStudyConfig();

	if (isLoading) return <p>Loading config...</p>;
	if (error) return <p>Error loading config</p>;

	return <h1>{studyConfig.name}</h1>;
};

Error Handling

The library exports an ApiError class that extends the standard Error object. It includes the HTTP status code and the response body.

import { ApiError } from '@rssa-project/api/api/RssaClient'; // Or import from index if exported

try {
	await studyApi.get('/protected-resource');
} catch (error) {
	if (error instanceof ApiError) {
		console.log(`Status: ${error.status}`);
		console.log('Body:', error.body);
	}
}

Type Definitions

The library exports core types for the RSSA platform ecosystem, including:

  • Study, StudyStep, Page
  • Participant, NewParticipant
  • SurveyResponse, Feedback, Demographic

Import them directly from the package:

import { Study, Participant } from '@rssa-project/api';