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

@stillfront-paymenthub/canvas-agent

v1.5.0

Published

An agent to initialize and manage Canvas storefront instances.

Downloads

199

Readme

canvas-agent

An agent to initialize and manage Canvas storefront instances.

Usage

Using import

npm i @stillfront-paymenthub/canvas-agent
import CanvasAgent from '@stillfront-paymenthub/canvas-agent'

... or HTML <script> before JS

<script src="https://cdn.jsdelivr.net/npm/@stillfront-paymenthub/canvas-agent" type="text/javascript"></script>

Initiate a Canvas instance

This example will initiate a Canvas instance in fullscreen mode and open it once a session could be successfully created.

let canvasInstance

const handleCanvasEvent = (event) => {
    const actions = {
        ready: () => canvasInstance.show()
        error: () => //... handle failure, e.g. 'could not load shop'
        expired: () => //... handle expired token, e.g. get new token and recreate instance
    }

    actions[event.eventType]?.()
} 

canvasInstance = await CanvasAgent.create({
    canvasAppId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    token: 'ey0ab76c9d823e645ff0....',
    eventListener: handleCanvasEvent,
    locale: 'de-DE',
    customContext: {
        playerSegment: 1 // e.g. A/B test
    }
})

Parameters

| Parameter | Type | Required | Description | | --------------- | ----------- | -------- | ----------- | | canvasAppId | string | Yes | Application Id from the Canvas client customization store, e.g. 1a70cd16-7ff2-48ad-bbcf-bf509072132e | | token | string | Yes | Your authentication token that will be validated against your identity backend by Hydra, e.g. a JWT. | | forceAuth | boolean | No | Force Canvas authentication flow, ignoring a client-cached session. Default: false | | eventListener | function | No | Provide a function reference that will be called on each Canvas event. | | frameParent | HTMLElement | No | The DOM node used to attach the Canvas client iframe, default: document.body | | fullScreen | boolean | No | Embed type; whether the storefront should open in full screen or become part of the host page. Default: true | | locale | string | No | Pass the locale as the country with the region designator, e.g. en-US, default: navigator.language() | | sessionId | string | No | Pass a specific session id, e.g. for cross channel tracking purposes. Default: nanoid() | | customContext | object | No | Pass an object of custom context parameters that be will merged by override with your custom context from the Canvas client customization.

Instance methods

create(parameters)

Create a new Canvas client instance. Hidden after initation.

show()

Show the canvas instance. Needs to be called after initiation to display the storefront.

hide()

Hide the canvas instance

destroy()

Destroy a canvas instance

getAppState()

Inspect current app instance state: initializing | ready | error

getState()

Inspect current agent state including passed parameters and app state.

reward(offerId)

Fire reward dialog for a specific offer.

navigate(collectionId, offerId?)

Navigate to a specific collection, and optionally to a specific offer detail page.

checkout(offerId)

Force checkout of a specific offer.

Events reference

The provided eventListener will be called with the event object as single argument eventListener(event).

Error

A blocking error occured, halting the application. ⚠ Needs to be handled.

{
    eventType: 'error',
    message: 'Authentication failed to retrieve token'
}

Expired

The token has expired, keeping the application from getting fresh data or creating checkout sessions. ⚠ Needs to be handled.

{
    eventType: 'expired'
}

Ready

The application has successfully initialized and is ready to be opened.

{
    eventType: 'ready'
}

Close

The player has closed the application.

{
    eventType: 'close'
}

Navigate

The player has navigated.

{
    eventType: 'navigate',
    fromPath: '/collection/6f440ba6-9028-49b2-9e94-aac3603b7f3a',
    toPath: '/collection/eacd5674-e9cc-4c50-aec2-59bfcb693744'
}

Checkout

The player has started a checkout.

{
    eventType: 'checkout',
    offerId: 'f4a6...'
}