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

@petscreening/embedded-flow-sdk

v1.0.10

Published

A library for embedding PetScreening's flow into your application

Downloads

311

Readme

embedded-flow-sdk

This library was generated with Nx.

Building

Run nx build embedded-flow-sdk to build the library.

Installation

To install the @petscreening/embedded-flow-sdk package, run:

npm install @petscreening/embedded-flow-sdk

or with Yarn:

yarn add @petscreening/embedded-flow-sdk

Environment URLs

The SDK supports different environments with the following base URLs:

  • Production: https://embedded.petscreening.com
  • Release Candidate (RC): https://embedded.rc.petscreening.com
  • QA: https://embedded.qa.petscreening.com

You can specify the environment by setting the overrideUrl option accordingly:

ps.initEmbeddedFlow('#your-button-selector', {
  overrideUrl: 'https://embedded.qa.petscreening.com', // For QA environment
  queryParams: {
    serviceProviderId: 5126,
    userFirstName: 'John',
    userLastName: 'Doe',
    userEmail: '[email protected]',
    userPhone: '1234567890',
    userAddress: '1234 Main St',
    userAddressContinued: 'Apt 2B',
    userCity: 'North Carolina',
    userState: 'NC',
    userZip: '27617',
    userMovingTime: 'not_moving',
  },
  callbacks: {
    onEvent: (data) => {
      console.log('Event received:', data);
    },
    petProfilesCompleted: () => {
      console.log('Pet profiles completed:');
      // Here you can trigger the API call to Parent
      sendProfileCompletionToParent();
    },
  },
});

Callbacks

The SDK supports several callbacks to handle different events:

petProfilesCompleted

This callback is triggered when all pet profiles have been successfully completed in the flow. It's particularly useful for integrating with parent applications or triggering follow-up actions.

ps.initEmbeddedFlow('#your-button-selector', {
  callbacks: {
    petProfilesCompleted: (data) => {
      console.log('Pet profiles completed:', data);
      // Here you can trigger follow-up actions like:
      // - Updating your application state
      // - Making API calls to your backend
      // - Redirecting the user
      sendProfileCompletionToParent();
    },
    onEvent: (data) => {
      console.log('Event received:', data);
    },
  },
});

Usage

Here is an example of how to use the @petscreening/embedded-flow-sdk in your React project:

import React, { useEffect } from 'react';
import { ps } from '@petscreening/embedded-flow-sdk';

const YourComponent = () => {
  useEffect(() => {
    ps.initEmbeddedFlow('#your-button-selector', {
      queryParams: {
        serviceProviderId: 5126,
        userFirstName: 'John',
        userLastName: 'Doe',
        userEmail: '[email protected]',
        userPhone: '1234567890',
        userAddress: '1234 Main St',
        userAddressContinued: 'Apt 2B',
        userCity: 'North Carolina',
        userState: 'NC',
        userZip: '27617',
        userMovingTime: 'not_moving',
      },
      callbacks: {
        onEvent: (data) => {
          console.log('Event received:', data);
        },
        petProfilesCompleted: () => {
          console.log('Pet profiles completed:');
          // Here you can trigger the API call to Parent
          sendProfileCompletionToParent();
        },
      },
    });
  }, []);

  const sendProfileCompletionToParent = async () => {
    try {
      const response = await fetch('https://your-parent-api-endpoint.com', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({ profilesCompleted: true }),
      });
      if (!response.ok) {
        throw new Error('Failed to send profile completion to Parent');
      }
      console.log('Profile completion sent to Parent successfully');
    } catch (error) {
      console.error('Error sending profile completion to Parent:', error);
    }
  };

  return (
    <div>
      <button id="your-button-selector">Open Embedded Flow</button>
    </div>
  );
};

export default YourComponent;

Using in HTML

You can also use the library directly in an HTML file. Here is an example:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Embedded Flow SDK Example</title>
    <script src="https://cdn.qa.petscreening.com/index.cjs.js"></script>
  </head>
  <body>
    <button id="open-embedded-flow">Open Embedded Flow</button>
    <script>
      document.addEventListener('DOMContentLoaded', function () {
        const ps = window.ps;
        ps.initEmbeddedFlow('#open-embedded-flow', {
          queryParams: {
            serviceProviderId: 5126,
            userFirstName: 'John',
            userLastName: 'Doe',
            userEmail: '[email protected]',
            userPhone: '1234567890',
            userAddress: '1234 Main St',
            userAddressContinued: 'Apt 2B',
            userCity: 'North Carolina',
            userState: 'NC',
            userZip: '27617',
            userMovingTime: 'not_moving',
          },
          callbacks: {
            onEvent: (data) => {
              console.log('Event received:', data);
            },
            close: () => {
              document.body.style.overflowY = 'auto';
            },
          },
        });
      });
    </script>
  </body>
</html>

API

initEmbeddedFlow(selector: string, options?: Options): void

Initializes the embedded flow by attaching a click event listener to the specified button.

  • selector: The CSS selector for the button.
  • options: Optional configuration options.

openIframe(options?: Options): void

Opens the embedded iframe with the specified options.

  • options: Optional configuration options.

buildUrl(options?: Options): string

Builds the URL for the embedded iframe.

  • options: Optional configuration options.
  • Returns: The URL as a string.

setupMessageListener(options?: Options): void

Sets up a message listener for communication between the parent window and the iframe.

  • options: Optional configuration options.

closeIframe(): void

Closes the embedded iframe.

Options

The Options interface allows you to customize the behavior of the embedded flow.

interface Options {
  overrideUrl?: string;
  queryParams?: {
    serviceProviderId?: number;
    userFirstName?: string;
    userLastName?: string;
    userEmail?: string;
    userPhone?: string;
    userAddress?: string;
    userAddressContinued?: string;
    userCity?: string;
    userState?: string;
    userZip?: string;
    userMovingTime?: string;
    [key: string]: string | number | undefined;
  };
  callbacks?: {
    onEvent?: (data: any) => void;
    close?: () => void;
    petProfilesCompleted?: (data: any) => void;
  };
}
  • overrideUrl: A custom URL to override the default URL.
  • queryParams: A record of query parameters to include in the URL, including user information.
  • callbacks: A record of callback functions to handle events and closing the iframe.