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

react-sprie-sdk

v1.1.2033

Published

`Version : 1.1.2031`

Downloads

12

Readme

Sprie SDK

Version : 1.1.2031

Quick Start

Make sure you acquire apikey from Sprie and have a product registered and catalogued by Sprie beforehand.

<!-- STEP 1. Load React CDN Scripts -->
<script crossorigin="" src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
<script crossorigin="" src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.8.0/prop-types.min.js" integrity="sha512-M1OTu9xD1JPdXo2cOeJI+Z/f8P6E/pqK9ug3G8PRNLw1caUePewEmpFYKSYh4LEz483qnyB/UTlgX1Q4VCEsKg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>


<!-- STEP 2. Load Sprie SDK -->
<script src="https://cdn.jsdelivr.net/npm/react-sprie-sdk"> </script>


<!-- STEP 3. Intialize  -->
<script>
SprieSDK.Loader.Init({ apiKey:"xxx-xxx-xxx" });
</script>


<!-- STEP 6. Trigger -->
<button onclick="SprieSDK.Loader.Load('product-sku');"> Preview </button>

SDK Reference

Sprie SDK is built on React and is released as umd library which depends on react libs (must be loaded from external cdn). To support both react projects and vanilla JS projects, SprieSDK lib has a Loader object which has following methods to run the react SDK as native vanilla SDK.

Methods

  1. Init ({apiKey})
  2. Load (sku)
  3. Check (sku)
  4. CheckBatch (skuArray)
  5. UnmountAll ( )
  6. GetSprieLink ( sku )
  7. HideWidget ( )

Init ( {apiKey } )

SprieSDK.Loader.Init( {apiKey:'xxx-xxx-xxx'} ); Must be called only once for apikey authentication. N.B. Must not be called every time product is loaded.

Params
  1. apiKey : string - apiKey received from Sprie Cloud

Load ( sku )

SprieSDK.Loader.Load( 'your-product-sku' ); Call everytime you want to load a new asset on AR on Sprie. Only SKU should be provided.

CheckSKU ( sku )

SprieSDK.Check( 'your-product-sku' ); (optional). Can be called to check if the product is registered with Sprie or not. For bulk assets, refer to CheckBatch. Should be used after authentication is done. Response : {<sku>:<boolean>}
Response Example : {"centena-bert-stone":true}

CheckSKUBatch ( skuArray )

SprieSDK.CheckSKUBatch( ['your-product-sku', 'your-product-sku2'] ); (optional). Can be called to check if an array of product skus is registered with Sprie or not. Should be used after authentication is done. Response : [{<sku>:<boolean>]}
Response Example :

[
    { "your-product-sku":true }, // this sku exists
    { "your-product-sku2": false} // this doesn't
]

UnmountAll ( )

SprieSDK.Loader.UnmountAll( ); Removes current instance of SprieSDK from website. This action is stateless, which means, refreshing the page will re-mount it again.

GetSprieLink (sku)

SprieSDK.GetSprieLink (sku)
Fetches the share link of the product (with the product page), typically to share it via an app, or show a QR code. this link appends sprie-sku query param with the given sku which helps sprie-widget to open automatically.

HideWidget ( )

SprieSDK.HideWidget ( );
Hides the widget as well as the widget icon.

Events

All Events are based on CustomEvent or Event. You can find the respective data for particular event by standard event.detail.[field].

Auth

  1. SprieEvent:onAuthLoading ({isLoading: boolean}) - ✅
  2. SprieEvent:onAuthOk () - ✅
  3. SprieEvent:onAuthErr ({err: string}) - ✅
  4. SprieEvent:onSDKReady () - ✅
  5. SprieEvent:onSDKErr ({err: string}) - ✅

IO

  1. SprieEvent:onCameraAllowed ( ) - ✅
  2. SprieEvent:onCameraDenied ( ) - ✅
  3. SprieEvent:onCameraError ({err: string}) - ✅

Assets

  1. SprieEvent:onAssetCart ({sku: string}) - ✅
  2. SprieEvent:onAssetWishlist ({sku : string}) - ✅
  3. SprieEvent:onAssetLoading ({sku: string, isLoading: boolean}) - ✅
  4. SprieEvent:onAssetLoadOk ({sku: string}) - ✅
  5. SprieEvent:onAssetLoadErr ({sku: string, err: string}) - ✅
  6. SprieEvent:onCheckAssetSKU ({[sku]:boolean}) - ✅ . e.g. Response : {'your-product-sku':true} // if it already exists
  7. SprieEvent:onCheckAssetSKUBatch ({[sku]:boolean, ...}) - ✅ . e.g. Response : {'your-product-sku':true, 'sku-2':false}

Widget

  1. SprieEvent:onWidgetMinimised ( ) - ✅

Events Example

<script>
    SprieSDK.Loader.Init({ apiKey:"xxx-xxx-xxx" });
    document.addEventListener("SprieEvent:onAssetCart", function (e) {
        alert("Added to cart " + e.detail.sku);
    });

    document.addEventListener("SprieEvent:onCameraDenied", function (e) {
        alert("Camera Denied!");
    });

    document.addEventListener("SprieEvent:onCameraError", function (e) {
        alert("Camera Error : " + e.detail.err);
    });
</script>

Advanced Examples

Check particular SKU before rendering the preview trigger button

This code checks the sku with Sprie Network and hides/shows a preview button based on the result. The checking code can return a promise and triggers a convinient event as well (where promises are not supported). This check method must be called only after authentication is successful otherwise unauthenticated API calls will return inconsistent result.

<script>
    const sku = 'my-precious-sku'; 
    let showPreviewButton = false;
    const onAuthDone = function (){
        SprieSDK.CheckSKU(sku);
    }

    const onCheckSKU = function (e){
        const result = e.detail; // {'my-precious-sku':true}
        if(result && Object.keys(result)[0]===sku){
            showPreviewButton = result[sku];
        }
    }

    document.addEventListener("SprieEvent:onAuthOk", onAuthDone);
    document.addEventListener("SprieEvent:onCheckAssetSKU", onCheckSKU);

    SprieSDK.Loader.Init({ apiKey:"xxx-xxx-xxx" });
</script>

Check array of SKUs on product list page

Similar to CheckSKU method. but takes an array of skus. This method is in alpha. Expect future changes.

<script>
    const arrSku = ['my-precious-sku','my-secondary-sku']; 
    let validSkus = [];
    const onAuthDone = function (){
        SprieSDK.CheckSKUBatch(arrSku);
    }

    const onCheckSKUBatch = function (e){
        const result = e.detail; // [{ 'my-precious-sku':true, 'my-secondary-sku':false }]
        validSkus = Object.keys(result).map(x=>x).filter(x=>result[x]).map(x=>x); // validSkus=['my-precious-sku'];
    }

    document.addEventListener("SprieEvent:onAuthOk", onAuthDone);
    document.addEventListener("SprieEvent:onCheckAssetSKUBatch", onCheckSKUBatch);

    SprieSDK.Loader.Init({ apiKey:"xxx-xxx-xxx" });
</script>

Hide widget on minimise

This code hides the widget on receiving the onWidgetMinimised event callback

<script>
     document.addEventListener("SprieEvent:onWidgetMinimised", function () {
        SprieSDK.Loader.HideWidget();
     });
</script>

Reset CDN cache

https://purge.jsdelivr.net/npm/react-sprie-sdk@latest

Test update version

https://cdn.jsdelivr.net/npm/react-sprie-sdk@latest