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.
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:
attribute | type | description |
---|---|---|
paymentProvider | object | Payment provider details |
userProfile | object | User details |
userWallet | object | userWallet |
userSelectedPaymentMethod | object | userSelectedPaymentMethod |
userCartHistory | object | userCartHistory |
userAddressBook | object | userAddressBook |
userFavorites | object | userFavorites |
location | object | location |
catalogProductLines | object | currently active collection (PCP/PLP content) |
hasOfferings | boolean | does catalog include offerings? (false if no location is set) |
productLineOfferings | object | productLineOfferings |
cart | object | User's shopping cart |
ageGatePassed | boolean | Has user passed an age gate? |
ageGateType | string | Type of age gate: 'dob', 'yesno', 'confirm' |
ageGateDOB | date | DOB if provided in age gate |
isInCoverage | boolean | If location exists, is that location in coverage? |
isGift | boolean | Cart is flagged as a gift by consumer |
locationHash | string | Hash of location, use to determine if location has changed |
isFetching | boolean | API service is waiting on response |
errorMessage | object | |
warningMessage | object | |
infoMessage | object | |
error | object |
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.