tearex
v0.1.9
Published
This package provides a NodeJS SDK for the [tearex.ai](https://tearex.ai) Recommendation Engine API. If you don't have a tearex.ai account, you can request one here: [tearex.ai](https://tearex.ai/#contact).
Downloads
33
Maintainers
Readme
TeaRex AI NodeJS SDK
This package provides a NodeJS SDK for the tearex.ai Recommendation Engine API. If you don't have a tearex.ai account, you can request one here: tearex.ai.
Documentation
For more information about the API, please refer to the documentation.
Installation
To install the SDK, run the following command:
npm install --save tearex
Usage
Import the SDK:
const trx = require('tearex');
Initialize the SDK
Provide the url of the API and your API KE as an environment variable TEAREX_URL
and TEAREX_API_KEY
, or pass them as an argument to the init
function:
trx.init({uri: 'YOUR_TEAREX_API_URL', apiKey: 'YOUR_TEAREX_API_KEY'});
Example
import trx from 'tearex';
// Initialize the tearex
trx.init()
const alice = {id: 'user-1', label: 'User', properties: {name: 'Alice'}}
const kale = {id: 'product-2', label: 'Product', properties: {name: 'Kale'}}
// Create Alice since she is a new user
(async () => {
await trx.createEntity(alice)
// Alice purchases Kale, so we create the "Purchased" event
await trx.createEvent(alice, "Purchased", kale)
// Recommend Alice the next "Product" to purchase
await trx.recommend(alice, "Product")
})()