Options
All
  • Public
  • Public/Protected
  • All
Menu

This file (embed.js) is meant to be loaded via the <script/> tag into a web application that would like to embed Aiera modules. It exposes a global window.Aiera namespace with utilities for loading Aiera modules into iframes inside the web application and communicating with them.

See Module for more details.

Example usage

example

index.html

<html>
<head>
<script src="https://aiera-inc.github.io/aiera-client-sdk/embed.js"></script>
</head>
<body>
<iframe height="575" width="375" id="aiera-event-list"></iframe>
<script>
const eventList = new Aiera.Module(
'https://public.aiera.com/aiera-sdk/0.0.20/modules/EventList/index.html',
'aiera-event-list'
);

eventList.load().then(() => {
// If you want to bypass the login screen, you must get credentials
// via the API and then pass them here. This is optional.

// See [[web/embed#authenticate]] for examples of how to get tokens.

// eventList.authenticate({
// accessToken: '[accesstoken]',
// refreshToken: '[refreshToken]',
// });

// eventList.configure({
// hideSettings: true
// })
});

// Once authenticated, you can pass data to the module, such as setting
// up a watchlist
eventList.on('authenticated', () => {
// Set up a watchlist after authentication
// eventList.setWatchlist([
// { ticker: 'AAPL' },
// { ISIN: 'US02079K1079' },
// { ticker: 'TLSA' },
// { ticker: 'PTON' },
// ]);
});
</script>
</body>
</html>

Authentication

By default Aiera modules will display a login screen and ask for existing user credentials in order to login and gain access to the module. However, some applications may handle user creation on their own and would prefer to automatically log those users into the module. For that use case, you can exchange user credentials for auth tokens and then call Module.authenticate with the tokens to bypass the login screen.


To exchange credentials for auth tokens, you must make a request to Aiera's graphql endpoint with the following (skip to next section if logging in using an API key):


URL https://api.aiera.com/graphql
Method POST
Headers Content-Type: application/json
Body
 {
     "query":
         "mutation Login($email: String!, $password: String!) {
            login(email: $email, password: $password) {
                accessToken
                refreshToken
            }
        }",
     "variables": {
         "email": [email address],
         "password": [password]
     }
 }
        
Response
 {
     "data": {
         "login": {
             "accessToken": [access token],
             "refreshToken": [refresh token],
         }
     }
 }
        

Logging in using an API key

URL https://api.aiera.com/graphql
Method POST
Headers Content-Type: application/json
Body
 {
     "query":
         "mutation LoginWithApiKey($email: String!, $apiKey: String!) {
            loginWithApiKey(email: $email, apiKey: $apiKey) {
                accessToken
                refreshToken
            }
        }",
     "variables": {
         "email": [email address],
         "apiKey": [api key]
     }
 }
        
Response
 {
     "data": {
         "loginWithApiKey": {
             "accessToken": [access token],
             "refreshToken": [refresh token],
         }
     }
 }
        

Examples of getting user auth tokens

These are examples of how to exchange user credentials for tokens that can be passed to Module.authenticate.



example

bash

# Exchange username/password for auth tokens using curl
curl -v \
-X POST \
-H 'Content-Type: application/json' \
-d '{"query":"mutation Login($email: String!, $password: String!){login(email: $email, password: $password){accessToken,refreshToken}}","variables":{"email": "[email]", "password": "[password]"}}' \
https://api.aiera.com/graphql \
| jq '.data.login'


javascript

email = '';
password = '';

authTokens = await fetch(
'https://api.aiera.com/graphql',
{
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
query: `
mutation Login($email: String!, $password: String!) {
login(email: $email, password: $password) {
accessToken
refreshToken
}
}
`,
variables: {
email: email,
password: password
}
})
}
).then(resp => resp.json()).then(json => json.data.login);


python

import requests

query = """
mutation Login($email: String!, $password: String!) {
login(email: $email, password: $password) {
accessToken
refreshToken
}
}
"""
email = ""
password = ""

req = requests.post( "https://api.aiera.com/graphql", json={"query":query, "variables":{"email": email, "password": password}})
auth_tokens = tokens = req.json()['data']['login']

Index

Interfaces

Classes

Generated using TypeDoc