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

@justeattakeaway/cc-stampcards-adapter

v0.7.1

Published

The stamp cards adapter

Downloads

68

Readme

StampCards Adapter

This package is used to supply the frontend with users stampcards. It connects with the stampcards API and returns the transformed data into cards. The package is built in typescript and is a replacement method for getting users stampcards via braze.

The entry point for the package is index.ts with the function stampCardsAdapter being the method supplied by the package. The function accepts 3 parameters token, tenant and url. Here the token is the users JWT, the tenant is the users selected tenant and the url is the API URL for the stampcards API.

The stampCardsAdapter function returns an object with 3 functions (initialise, handleCardClick, handleCardView) and the source string. It also implements the Adapter interface like the braze adapter.

The initialise method requires 3 parameters filters which is an array of filter functions that take an array of cards and return a modified array of cards. The callback which is supplied to the adapter by the consuming application and returns formatted cards. The errorCallback which is called upon any errors occurring during the retrieval of users stampcard data.

Inside the initialise method we call fetch with the provided url and attach the token to the authorization header. If successful the fetch returns response.ok true. The conversationId is then retrieved from the response headers, and we call the .json() method to get the json body response.

Cards are then transformed using the transformIntoCards method, taking the response from the api and creating cards from the inProgress and rewards response attributes and flat mapping them into one array. Filters are then applied to the transformed cards. Cards are then returned via the callback function. After this the createApiSuccessEvent is fired.

Installing the Adapter

To install the package run one of the following:

yarn add @justeattakeaway/cc-stampcards-adapter

npm install @justeattakeaway/cc-stampcards-adapter

Instantiating the Adapter

To use the adapter you first have to call the function with an Object containing following parameters

{
    token: () => '<THIS WOULD BE THE TOKEN>',
    tenant: '<USERS TENANT>',
    url: '<API_URL>'
}

Example adapter call:

import stampcardsAdapter from "@justeattakeaway/cc-stampcards-adapter";

const adapter = stampcardsAdapter({
  token: () => '<THIS WOULD BE THE TOKEN>',
  tenant: '<USERS TENANT>',
  url: '<API_URL>'
});

Using the adapter

Getting Cards

Once the adapter function has been called you then need to do the following to use the adapter.

adapter.initalise(
  [], // filters
  (cards) => {
  // do somthing with cards
  }, (error) => {
  // do somthing with errors
  }
)

Getting Adapter Source

The adapter source can get obtained by using the source attribute on adapter. This is useful when looping over multiple adapters

adapter.source