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

@statebacked/client

v0.1.40

Published

The API client for the StateBacked.dev XState backend as a service

Downloads

85

Readme

StateBacked.dev client for web, Node, and Deno

GitHub license npm version CI Docs API Docs

Deploy invincible workflows and real-time, multiplayer backends with StateBacked.dev.

Check out the full State Backed docs for more detailed information and deploy your own state machine backend in just a few minutes.

This is the client library for interacting with the State Backed API. You can find the API docs for the State Backed client here.

The StateBacked.dev client provides an easy interface to interact with the State Backed API to create machines and machine versions, create machine instances, read the state of instances, and send events to instances.

Generally, you will want to use the web dashboard or smply, the State Backed CLI for administrative operations like creating machines and machine versions (smply machines create and smply machine-versions create) and use the API client for production operations like creating machine instances, subscribing to real-time state updates, and sending events.

Use the @statebacked/react package to connect to your machine instances from React.

Example

import { StateBackedClient } from "@statebacked/client";

const sessionId = crypto.randomUUID();

// you can create anonymous State Backed sessions or fully authenticated
// sessions to securely pass end-user claims to your machine authorizers
const client = new StateBackedClient({
  anonymous: {
    orgId: "org-YOUR_STATE_BACKED_ORG_ID",
    getSessionId() {
      return sessionId;
    }
  }
});

// create a new machine instance or get its current state if it already exists
// your machine's allowWrite authorizer will determine whether the request with
// the given authorization claims (in this case of anonymous access, just a session ID)
// will be allowed to create an instance with this name and initial context.

const { state, publicContext, tags, done } = await client.machineInstances.getOrCreate(
  "user-onboarding", // machine name
  sessionId, // machine instance name
  () => ({
    context: {
      your: "optional initial context",
    }
  })
);

// we can send an event to the `user-onboarding` machine instance
// for our current sesion and use the updated machine state and any
// public context. The event will only be accepted if your
// allowWrite machine authorizer allows the request with the given authorization
// claims (in this case of anonymous access, just a session ID) to
// send this event to this machine instance.

const { state, publicContext, tags, done } = await client.machineInstances.sendEvent(
  "user-onboarding", // machine name
  sessionId, // machine instance name
  {
    event: {
      type: "completed-tutorial",
      role: "engineer",
      preferredChannel: "email",
    }
  }
);

// we can also subscribe to state updates for any machine instance
// as long as your allowRead machine authorizer allows the request with
// our authorization claims to read its state

const unsubscribe = client.machineInstances.subscribe(
  "user-onboarding", // machine name
  sessionId, // machine instance name
  ({ state, publicContext, tags, done }) => {
    // react to new state
  }
);

// when you're done:
unsubscribe();