0.0.32 • Published 2 years ago

@getevy/stately v0.0.32

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Evy Stately

Stately is a headless library to help you build your Evy UI in Javascript or Typescript.

Stately provides methods for key actions in the lifecycle of insurance in the UI:

  • getting offers
  • attaching offers
  • retrieving offers from the cart (stored in local storage)

Installation

npm i @getevy/stately

Initialization

import { Evy as Stately } from '@getevy/stately';

const stately = new Stately({ apiKey, apiURL });

The configuration is an object.

KeyRequiredDescription
apiKeyyesyour API key
apiURLnothe URL of the API to target

stately is an EventEmitter. The methods are used to modify the state and request values from the Evy API. Once the data are up to date, events are triggered to allow you to update the UI.

During the initialization, stately will retrieve previous data from the local storage.

Methods

addProduct

Fetches offers for a specific product.

Parameters

stately.addProduct(productId: string, price: number) => Promise<void>
ParameterRequiredDescription
productIdyesID of the product as provided to Evy
priceyesPrice of the product

This method will emit OFFERS_LOADED when the offer data is retrieved from the server.

setAttachedOffer

Attaches an offer to a product.

stately.setAttachedOffer(offerId: string, productId: string, quantity: number) => void

Parameters

ParameterRequiredDescription
offerIdyesID of the offer
productIdyesID of the product as provided to Evy
quantityyesPrice of the product

This method will emit ATTACH_OFFER when the offer data is attached and synchronized with the local storage.

getAttachedOffers

Provides all the offers attached to products.

stately.getAttachedOffers() => Record<AttachedOfferIdentifier, AttachedOffer>

AttachedOffer

KeytypeDescription
offerIOfferThe complete offer object
quantitynumberThe number of times the offer is attached to the product

clearOffers

Removes the offers attached on all the products.

stately.clearOffers() => void

cancelAttachedOffer

Removes the offers for a single product.

stately.cancelAttachedOffer(productId: string) => void

Events

OFFERS_LOADED

This event is triggered when the offers are updated.

ATTACH_OFFER

This event is triggered when an offer is attached to a product.

0.0.32

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.27

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.19

2 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.3-0

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.2

3 years ago

0.0.15

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.7

3 years ago

0.0.1-0

3 years ago