@dashx/web v0.1.20
@dashx/web
DashX JS SDK for the browser
Install
# via npm
$ npm install @dashx/web
# via yarn
$ yarn add @dashx/webUsage
import DashX from '@dashx/web';
const dx = DashX({ publicKey: 'your_public_key' });DashX constructor accepts following properties:
| Name | Type |
|---|---|
publicKey | string (Required) |
baseUri | string |
By default the value of baseUri is https://api.dashx.com/v1
Identify User
- Existing user
dx.identify('uid_of_user');- New user
dx.identify({
firstName: 'John',
lastName: 'Doe',
email: 'john@example.com',
phone: '+1-234-567-8910'
});For new user identify() accepts following properties:
| Name | Type |
|---|---|
firstName | string |
lastName | string |
email | string |
phone | string |
Please note that identify() should not be called with null or undefined
Search Content
dx.searchContent('content_type', { returnType: 'all', limit: 10 } /* Content Options */)
.then(data => console.log(data));Content Options can include following properties:
| Name | Type | Example | |
|---|---|---|---|
language | string | 'en_US' | |
include | array | ['character.createdBy', 'character.birthDate'] | |
exclude | array | ['directors'] | |
fields | array | ['character', 'cast'] | |
preview | boolean | ||
returnType | 'all' or 'one' | ||
filter | object | { name_eq: 'John' } | |
order | object | { created_at: 'DESC' } | |
limit | number | ||
page | number |
For example, to get latest contacts with name 'John' you can do:
dx.searchContent('contacts')
.filter({ name_eq: 'John' })
.order({ created_at: 'DESC' })
.preview() // Sets preview to true
.limit(10)
.all() /* returnType */This code is lazy by default and will not be executed until .all() or .one() is called.
Hence .all() or .one() should be used at the end of chain.
The above code can also be written as:
dx.searchContent('contacts', {
returnType: 'all',
filter: {
name_eq: 'John'
},
order: {
created_at: 'DESC'
},
preview: true,
limit: 10
});Fetch Content
dx.fetchContent('content_type/content', { language: 'en_US' } /* Fetch Content Options */)
.then(data => console.log(data));Fetch Content Options can include following properties:
| Name | Type | Example | |
|---|---|---|---|
language | string | 'en_US' | |
include | array | ['character.createdBy', 'character.birthDate'] | |
exclude | array | ['directors'] | |
fields | array | ['character', 'cast'] | |
preview | boolean |
dx.fetchContent('movies/avengers', {
language: 'en_US',
include: ['character.created_by'],
exclude: ['directors'],
fields: ['character', 'release_date'],
preview: true
});Track Events
dx.track('event_name', { hello: 'world' } /* Event data */);Reset User
reset() clears out the information associated with a user. Must be called after a user logs out.
dx.reset();Development
- Make sure all the dependencies are installed:
$ lerna bootstrap- To start dev server with hot reload:
$ yarn startThis will run a dev server that logs out errors and warnings and reloads itself on any file save.
- To create production build:
yarn build- To publish package, make sure to login on npm cli and commit all the changes before running this:
yarn publish
git push origin master3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago