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

@saasquatch/integration-boilerplate-react

v2.0.4

Published

Utilities for building SaaSquatch integration frontends in React

Downloads

38

Readme

SaaSquatch is a platform for managing referral and rewards programs for digital businesses. Integrations with SaaSquatch are typically built as microservices which respond to webhooks and form handler triggers from SaaSquatch's forms platform.

Integrations also typically have a configuration interface where a user can configure the integration for a tenant and various responses to form handlers.

This package currently contains a single hook, usePenpal which sets up the environment for an integration frontend and provides the methods required to communicate with the SaaSquatch portal to save configuration (amongst other actions).

Getting Started

Here's an example of a fully functional integration frontend:

function Index() {
  const penpal = usePenpal();

  if (penpal.mode === ConfigMode.IntegrationsPage) {
    return <P>This will be shown on the Integrations page.</P>;
  }

  if (penpal.mode === ConfigMode.FormConfigInitialDataActions) {
    return (
      <P>
        This will be shown when configuring integration initial data actions for
        a form.
      </P>
    );
  }

  if (penpal.mode === ConfigMode.FormConfigSubmitActions) {
    return (
      <P>
        This will be shown when configuring integration submit actions for a
        form.
      </P>
    );
  }

  return null;
}

function App() {
  return (
    <PenpalContextProvider
      loading={
        <p>This will be shown while the Penpal connection is being made.</p>
      }
      fallback={
        <p>
          This will be shown if this frontend is accessed from outside the
          portal.
        </p>
      }
    >
      <Index />
    </PenpalContextProvider>
  );
}

PenpalContextProvider

The PenpalContextProvider is the main workhorse of connecting your frontend with the SaaSquatch portal. It takes care of:

  • Connecting to the Penpal API
  • Automatically handling the resizing of the iframe in which the frontend is rendered
  • Managing the state for the usePenpal hook

Wrap the top level of your React application in the provider to get access to usePenpal in any descendants:

function App() {
  return (
    <PenpalContextProvider
      <Index />
    </PenpalContextProvider>
  );
}

The provider takes two optional props:

  • loading: JSX to render while the Penpal connection is being established
  • fallback: JSX to render if the Penpal connection fails (i.e the frontend is not being rendered in the SaaSquatch portal)

usePenpal

In your components, you can usePenpal to get access to the state and the Penpal API.

It consists of the following properties:

  • mode: Which context is the frontend being rendered in - this is either ConfigMode.IntegrationsPage for main integration config on the Integrations page, or ConfigMode.FormConfigInitialDataActions/ConfigMode.FormConfigSubmitActions for configuration pages within the configuration of a form.
  • tenantScopedToken: A tenant-scoped JWT can be passed to your integration backend via fetch or equivalent for authenticating requests from your frontend to the integration backend.
  • tenantAlias: The tenant alias of the current tenant
  • integrationConfig: The configuration of the integration currently stored on the tenant
  • formConfig: The integration-specific configuration for a form

You can call the following methods to interact with the portal:

  • saveIntegrationConfig(newConfig): Asks the portal to save new integration configuration for the tenant
  • patchIntegrationConfig(newConfig): Asks the portal to patch the integration configuration for the tenant
  • saveFormConfig(newConfig): Asks the portal to save new integration-specific config for the form
  • navigatePortal(url): Ask the portal to navigate to a portal-relative URL
  • closeFormConfig(): Ask the portal to close the form config modal (useful for Dismiss/Discard buttons in form config frontends)
  • getFileStackConfig(): Ask the portal to return the FileStack configuration