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 🙏

© 2024 – Pkg Stats / Ryan Hefner

stytch

v11.4.2

Published

A wrapper for the Stytch API

Downloads

134,492

Readme

Stytch Node.js Library

The Stytch Node library makes it easy to use the Stytch user infrastructure API in server-side JavaScript applications.

It pairs well with the Stytch Web SDK or your own custom authentication flow.

This library is tested with all current LTS versions of Node - 18, and 20.

Install

npm install stytch
# or
yarn add stytch

Usage

You can find your API credentials in the Stytch Dashboard.

This client library supports all of Stytch's live products:

B2C

B2B

Shared

Example B2C usage

Create an API client:

const stytch = require("stytch");
// Or as an ES6 module:
// import * as stytch from "stytch";

const client = new stytch.Client({
  project_id: "project-live-c60c0abe-c25a-4472-a9ed-320c6667d317",
  secret: "secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=",
});

Send a magic link by email:

client.magicLinks.email
  .loginOrCreate({
    email: "[email protected]",
    login_magic_link_url: "https://example.com/authenticate",
    signup_magic_link_url: "https://example.com/authenticate",
  })
  .then((res) => console.log(res))
  .catch((err) => console.error(err));

Authenticate the token from the magic link:

client.magicLinks
  .authenticate({ token: "DOYoip3rvIMMW5lgItikFK-Ak1CfMsgjuiCyI7uuU94=" })
  .then((res) => console.log(res))
  .catch((err) => console.error(err));

Example B2B usage

Create an API client:

const stytch = require("stytch");
// Or as an ES6 module:
// import * as stytch from "stytch";

const client = new stytch.B2BClient({
  project_id: "project-live-c60c0abe-c25a-4472-a9ed-320c6667d317",
  secret: "secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=",
});

Create an organization

client.organizations
  .create({
    organization_name: "Acme Co",
    organization_slug: "acme-co",
    email_allowed_domains: ["acme.co"],
  })
  .then((res) => console.log(res))
  .catch((err) => console.error(err));

Log the first user into the organization

client.magicLinks
  .loginOrSignup({
    organization_id: "organization-id-from-create-response-...",
    email_address: "[email protected]",
  })
  .then((res) => console.log(res))
  .catch((err) => console.error(err));

TypeScript support

This package includes TypeScript declarations for the Stytch API.

Request and response types will always follow the format $Vertical$Product$Method(Request|Response) - for example the B2BMagicLinksAuthenticateRequest maps to the B2B Authenticate Magic Link endpoint, while the B2CMagicLinksAuthenticateRequest maps to the B2C Authenticate Magic Link endpoint.

Handling Errors

Stytch errors always include an error_type field you can use to identify them:

client.magicLinks
  .authenticate({ token: "not-a-token!" })
  .then((res) => console.log(res))
  .catch((err) => {
    if (err.error_type === "invalid_token") {
      console.log("Whoops! Try again?");
    }
  });

Learn more about errors in the docs.

Customizing the HTTPS Agent

The Stytch client uses undici, the Node fetch implementation. You can pass a custom undici Dispatcher to the client for use in requests. For example, you can enable HTTPS Keep-Alive to avoid the cost of establishing a new connection with the Stytch servers on every request.

const dispatcher = new undici.Agent({
  keepAliveTimeout: 6e6, // 10 minutes in MS
  keepAliveMaxTimeout: 6e6, // 10 minutes in MS
});

const client = new stytch.Client({
  project_id: "project-live-c60c0abe-c25a-4472-a9ed-320c6667d317",
  secret: "secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=",
  dispatcher,
});

Documentation

See example requests and responses for all the endpoints in the Stytch API Reference.

Follow one of the integration guides or start with one of our example apps.

Support

If you've found a bug, open an issue!

If you have questions or want help troubleshooting, join us in Slack or email [email protected].

If you've found a security vulnerability, please follow our responsible disclosure instructions.

Development

See DEVELOPMENT.md

Code of Conduct

Everyone interacting in the Stytch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.