Skip to content

ThirstieClient

ThirstieClient provides a service layer for using the Thirstie ECommerce API which can be imported as a CommonJS or ES module.

Installation

  • npm install @thirstie/thirstieclient

Minimum Requirements

  • Node.js: v18+

Usage

You must have an Thirstie API Client Key (provided by your Thirstie representative) to initialize ThirstieClient. Optionally, you can also provide a Google API key to enable location services using Google's Maps / Places API.

js
async function main (apiKey, mapsKey) {
  const thirstieapp = new ThirstieClient({ apiKey, mapsKey });
  const res = await thirstieapp.initSession();
}

main();

DataStore

ThirstieClient manages the e-commerce application state in a reactive data store. Dispatching an action (see below) updates state, and ThirstieClient exposes getters and a watch method which you will use to access application state.

The DataStore state object contains the following attributes:

attributetypedescription
paymentProviderobjectPayment provider details
userProfileobjectUser details
userWalletobjectuserWallet
userSelectedPaymentMethodobjectuserSelectedPaymentMethod
userCartHistoryobjectuserCartHistory
userAddressBookobjectuserAddressBook
userFavoritesobjectuserFavorites
locationobjectlocation
catalogProductLinesobjectcurrently active collection (PCP/PLP content)
hasOfferingsbooleandoes catalog include offerings? (false if no location is set)
productLineOfferingsobjectproductLineOfferings
cartobjectUser's shopping cart
ageGatePassedbooleanHas user passed an age gate?
ageGateTypestringType of age gate: 'dob', 'yesno', 'confirm'
ageGateDOBdateDOB if provided in age gate
isInCoveragebooleanIf location exists, is that location in coverage?
isGiftbooleanCart is flagged as a gift by consumer
locationHashstringHash of location, use to determine if location has changed
isFetchingbooleanAPI service is waiting on response
errorMessageobject
warningMessageobject
infoMessageobject
errorobject

Invoking API Actions

Use the dispatch on ThirstieClient to invoke API calls and other services to update application state. You will never update application state directly.