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

@innerworks-me/iw-auth-sdk

v1.3.7

Published

Communication with innerworks API requires the configuration of a project with a project ID and secret. Currently the product is still in early private beta, contact us via our website at innerworks.me for assistance with setup and to receive your project

Downloads

671

Readme

Innerworks Fraud Detection Suite SDK

Communication with innerworks API requires the configuration of a project with a project ID and secret. Currently the product is still in early private beta, contact us via our website at innerworks.me for assistance with setup and to receive your project credentials.

For a full interactive example of how to install and use the SDK, please visit this repo

Installation

We host our SDK through npm, so to install it for your project simply run the following in the command line

npm i @innerworks-me/iw-auth-sdk --save

Innerworks Fraud Detection with Authentication - React Integration

Our flagship product is a wrapper over Google Sign-On with invisible fraud detection acting in the background.

Setup

First import the SDK and necessary react hooks

import { InnerworksAuth } from "@innerworks-me/iw-auth-sdk";
import { useEffect, useRef, useState } from 'react';

Then initialize it

const [innerworksAuth, setInnerworksAuth] = useState<InnerworksAuth | null>(null);

useEffect(() => {
    setInnerworksAuth(new InnerworksAuth("{your project id}", "{your redirect url}"));
}, [setInnerworksAuth]);

Render Button

You can use the useRef hook to allow the innerworks SDK to create a dynamically render a signIn button

"use client"

import { useEffect, useRef, useState } from 'react';
import { InnerworksAuth } from "@innerworks-me/iw-auth-sdk";

export default function FrontendFlowDemoPage() {

    const [innerworksAuth, setInnerworksAuth] = useState<InnerworksAuth | null>(null);
    const buttonContainerRef = useRef<HTMLDivElement>(null);

    useEffect(() => {
        setInnerworksAuth(new InnerworksAuth("{your project id}", "{your redirect url}"));
    }, [setInnerworksAuth]);

    useEffect(() => {
        if(innerworksAuth && buttonContainerRef.current) {
            // Generate the button and append it to the buttonContainerRef
            const button = innerworksAuth.getInnerworksSignInButton();
            buttonContainerRef.current.appendChild(button);
        }
    }, [innerworksAuth]);
    
    return (
        <div id="sign-in-button" ref={buttonContainerRef}/></div>
    );
}

Handling Redirects

This will redirect the user to a sign-on page, prompt for their authentication, and finally redirect to the page you specified. Depending on the success of the authentication the URL parameters will either contain an id or error field. These will need to be parsed depending on your framework and whether your redirect page is server or client side, for example - here's how we do it in NextJS

"use client"

import { useSearchParams } from 'next/navigation';

export default function Callback() {
  const searchParams = useSearchParams();
  const params = Object.fromEntries(searchParams);
  const error = params.error;
  const id = params.id;

  return (
    <Layout>
      <div>
        {!id && (
          <div>
            Error: {error ?? "An error has occurred on our end..."}
          </div>
        )}
        {id && !error && (
          <div>
            Authentication Successful!
          </div>
        )}
      </div>
    </Layout>
  );
}

Innerworks Fraud Detection (No Authentication) - React Integration

If you prefer to retain your existing authentication provider, or you do not wish to protect a login but something else instead (maybe an email sign up for example), the Innerworks Fraud Detection Suite can be installed and sit invisibly in the background to perform bot detection and user coherence for your use case.

Setup

First, in your frontend page, import the InnerworksMetrics object to collect metrics.

import { InnerworksMetrics } from "@innerworks/iw-auth-sdk";

Initialise the InnerworksMetrics object in your page as follows

const [innerworksMetrics, setInnerworksMetrics] = useState<InnerworksMetrics>();

useEffect(() => {
    setInnerworksMetrics(new InnerworksMetrics(<yourAppID>));
}, [setInnnerworksMetrics]);

recommended: if you want to collect button UI metrics, pass a css selector to collect metrics on the already exiting button that is meant to trigger Innerworksʼ fraud detection (css selector accepted are ID, Class, Tag, Attribute, pseudo-class, etc).

const [innerworksMetrics, setInnerworksMetrics] = useState<InnerworksMetrics>();

useEffect(() => {
    setInnerworksMetrics(new InnerworksMetrics(<yourAppID>, #signin-button));
}, [setInnnerworksMetrics]);

Send Metrics On Submission

In the webpage, where the user submits a form, signs in or submits a tx, call send(<unique-id>) on the innerworksMetrics object, passing a unique identifier for the user (i.e. email, username or wallet address). This returns a boolean indicating the success of the request - which you can optionally use.

i.e:

const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
	e.preventDefault();

	/*
	handle form submission here e.g. authentication
	*/
	
	if (innerworksMetrics) { // necessary if using typescript
		const metricsSendSuccess = await innerworksMetrics.send(<unique-id>);
	}
	// optionally handle based on metricsSendSuccess
}

Full Integration

Overall the integration code would look like:

import { InnerworksMetrics } from "@innerworks-me/iw-auth-sdk";
import { useEffect } from "react";

export default function YourPage() {
	const [innerworksMetrics, setInnerworksMetrics] = useState<InnerworksMetrics>();
	
	useEffect(() => {
		setInnerworksMetrics(new InnerworksMetrics(<yourAppId>, "#signin-button"));
	}, [setInnerworksMetrics]);
	
	const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
		e.preventDefault();
	
		/*
		handle form submission here e.g. authentication
		*/
		
		if (innerworksMetrics) { // necessary if using typescript
			const metricsSendSuccess = await innerworksMetrics.send(<unique-id>);
		}
		// optionally handle based on metricsSendSuccess
	}
	
	return (
		// ... rest of elements
        	<form onSubmit={handleSubmit}>

			/* ...
			your form elements here
			... */

			<button type="submit" id="signin-button">
		</form>
	)
}