<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/29f866cc-2863-49c8-aa00-9fffdcccc696/icons8-space-shuttle-64.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/29f866cc-2863-49c8-aa00-9fffdcccc696/icons8-space-shuttle-64.png" width="40px" /> v0.1.0-beta
</aside>
JavaScript/TypeScript library for building a referral campaign with Alphaseek SDK.
Read the latest doc on Github repo.
npm install alphaseek
In your project, authenticate (login) in the appropriate module to retain the access token, which will be used later.
import {Auth} from 'alphaseek';
async function init() {
const auth = new Auth();
await auth.login('[email protected]', 'secretpass1234');
// Now we can use auth instead of raw token, which
// atomically keeps track of the signed-in state.
let product = new Product('alphaseek.io', {auth});
// Save product
product = await prod.create();
// Note that from field is the referral code of another referring user.
const user = await new User('[email protected]', {product, from: '916hqpB7'})
.create();
// Get user's unique referral link and code
const {url, moniker, score, referrer} = user.referral;
console.log(url); // <https://alphaseek.me/i/99PpQrh7>
console.log(moniker); // 99PpQrh7
console.log(score); // 1
console.log(referrer.referral.moniker); // 916hqpB7
}
To log into your account, use Auth
class. It is a single source of truth for your account identity as Alphaseek customer.
import {Auth} from 'alphaseek';
const token = await Auth.login('[email protected]', 'secretPassword');
The token will be stored in the browser's localStorage
if it's available and also in-memory as a static variable.
You can opt-out of storing the token in the browser's localStorage by setting Auth.useLocalStorage = false
before calling login()
.
To log out (invalidate the access token):
const ok = await Auth.logout();
This also clears old token from the localStorage if Auth.useLocalStorage
is set to true
.
You can also create an Auth
singleton instance so you could pass it around in other calls.
const auth = new Auth();
const tok = await auth.login('[email protected]', 'secretPassword');
// Create a new product.
const prod = new Product('awesome.app', {auth});