0.1.20 • Published 2 years ago

@dashx/web v0.1.20

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@dashx/web

DashX JS SDK for the browser

Install

# via npm
$ npm install @dashx/web

# via yarn
$ yarn add @dashx/web

Usage

import DashX from '@dashx/web';

const dx = DashX({ publicKey: 'your_public_key' });

DashX constructor accepts following properties:

NameType
publicKeystring (Required)
baseUristring

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:

NameType
firstNamestring
lastNamestring
emailstring
phonestring

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:

NameTypeExample
languagestring'en_US'
includearray['character.createdBy', 'character.birthDate']
excludearray['directors']
fieldsarray['character', 'cast']
previewboolean
returnType'all' or 'one'
filterobject{ name_eq: 'John' }
orderobject{ created_at: 'DESC' }
limitnumber
pagenumber

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:

NameTypeExample
languagestring'en_US'
includearray['character.createdBy', 'character.birthDate']
excludearray['directors']
fieldsarray['character', 'cast']
previewboolean
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 start

This 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 master
0.1.20

2 years ago

0.1.17

2 years ago

0.1.18

2 years ago

0.1.19

2 years ago

0.1.15

2 years ago

0.1.16

2 years ago

0.1.14

2 years ago

0.1.13-alpha

2 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.9

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago