New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@justeattakeaway/cc-stampcards-adapter

Package Overview
Dependencies
Maintainers
9
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@justeattakeaway/cc-stampcards-adapter

The stamp cards adapter

  • 0.7.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
9
Created
Source

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

Keywords

FAQs

Package last updated on 23 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc