0.1.8 • Published 1 year ago
@otrs/client-lib
Licence
MIT
Version
0.1.8
Deps
2
Size
328 kB
Vulns
0
Weekly
0
otrs-client-lib
Disclaimer
This is a library used by OTRS to facilitate frontend clients to interact with the backend.
Currently this is an active work in progress, with lots more to be added.
Usage
Install the library using npm install @otrs/client-lib in a Javascript or Typescript application.
Next, register the client with the correct configuration
const client = createClient({
testMode: false // optional (default = false),
})
Listening to events
client.eventBus.on('translation-switch-success', (language) => {
console.log('Language switched to: ', language)
})
client.eventBus.on('addUserLoaded', (user) => {
console.log('User signed in: ', user)
})
client.eventBus.on('addUserSignedOut', () => {
console.log('User signed out')
})
Using authentication
// first, register the module
client.auth.init({
clientId: '',
authority: '',
// Other options are automatically suggested
})
client.auth.signIn().then(
res => console.log('result =', res)
)
Loading translations
// Using aync/await
const language = 'en'
const hash = '<hash-value>'
// ... Error handling omitted
const res = await client.locale.loadLanguage(language, hash)
const { Locale, Translations } = res.data
Logging
Most function calls are automatically logged, you can pass your own custom logger through the createClient options.