package
Library to connect to XO-Server
npm install xo-libGitHub-flavored package documentation.
Across all versions, last 30 days.
1,547 in 30 days
Runtime metadata.
Tagged topics.
Library to connect to XO-Server
Installation of the npm package:
npm install --save xo-libIf the URL is not provided and the current environment is a web browser, the location of the current page will be used.
import Xo from 'xo-lib'
// Connect to XO.
const xo = new Xo({ url: 'https://xo.company.tld' })
// Let's start by opening the connection.
await xo.open()
// Must sign in before being able to call any methods (all calls will
// be buffered until signed in).
await xo.signIn({
email: 'admin@admin.net',
password: 'admin',
})
console('signed as', xo.user)The credentials can also be passed directly to the constructor:
const xo = Xo({
url: 'https://xo.company.tld',
credentials: {
email: 'admin@admin.net',
password: 'admin',
},
})
xo.open()
xo.on('authenticated', () => {
console.log(xo.user)
})If the URL is not provided and the current environment is a web browser, the location of the current page will be used.
await xo.open()
console.log('connected')xo.close()
console.log('disconnected')const token = await xo.call('token.create')
console.log('Token created', token)The connection status is available through the status property which is open, connecting or closed.
console.log('%s to xo-server', xo.status)Information about the user account used to sign in is available
through the user property.
console.log('Current user is', xo.user)This property is null when the status is not connected.
xo.on('open', () => {
console.log('connected')
})xo.on('closed', () => {
console.log('disconnected')
})xo.on('notification', function (notif) {
console.log('notification:', notif.method, notif.params)
})xo.on('authenticated', () => {
console.log('authenticated as', xo.user)
})
xo.on('authenticationFailure', () => {
console.log('failed to authenticate')
})Contributions are very welcomed, either on the documentation or on the code.
You may:
julien-f
julien.fontanet@isonoe.net
Estimated unpacked size across 11 packages.
1.8 MB
Includes dependencies.
3 direct dependencies.