sealjs

1.1.0 • Public • Published

sealjs

JavaScript library for the Sealax backend.

User Client

import { userClient } from 'sealjs'

// Request validation token via email
const resp = await userClient.createUserToken(email)

// Create user with email, password and emailed validation token
const user = await userClient.createUser(resp.token, email, pw)

// Request auth token for API requests
let authResp
try {
  authResp = await userClient.authenticate(email, pw)

  if (authResp.tfa) {
    authResp = await userClient.authenticateWithTFA(authResp, 'YUBIKEY_CODE_HERE')
  }
} catch (e) {
  // Handle error
}

Item Channel

import { ItemChannel } from 'sealjs'

const channel = new ItemChannel()

channel.on('all_items', (items) => {
  // Handling all items here!
})

channel.on('add_item', (item) => {
  // Handling single new item
})

channel.on('update_item', (item) => {
  // Handling single updated item
})

channel.on('add_item', (id) => {
  // Handling single deleted item
})

// Connect to backend with authResp from userClient.authenticate
await channel.connect(authResp)

try {
  const result = await channel.create({
    new: 'item'
  })

  // handle new item with id: result.id
} catch (e) {
  console.error('Oh no!', e)
}

try {
  const result = await channel.update(ItemID, {
    updated: 'item'
  })

  // handle updated item
} catch (e) {
  console.error('Oh no!', e)
}

try {
  const result = await channel.delete(ItemID)

  // handle deleted item
} catch (e) {
  console.error('Oh no!', e)
}

Readme

Keywords

none

Package Sidebar

Install

npm i sealjs

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

23 kB

Total Files

11

Last publish

Collaborators

  • dask