@hshp/pawtm1js
v1.1.1
Published
Cliente TypeScript para la API REST de TM1 (Planning Analytics Workspace).
Readme
@hshp/pawtm1js
Cliente TypeScript para la API REST de TM1 a través de Planning Analytics Workspace (PAW).
Instalación
npm install @hshp/pawtm1js axios
axioses una peerDependency (^1.7.2): instalalo junto al paquete.
Uso básico
import { getApi } from '@hshp/pawtm1js'
const api = getApi({
pawUrl: 'https://mi-paw.example.com',
serverName: 'Planning Sample',
Timeout: 30000,
})
// Autenticación
await api.connection.login({ username: '<usuario>', password: '<password>' })
// ¿Conectado? -> devuelve el nombre del servidor
console.log(await api.isConnected)
// Usuario actual
const me = await api.whoami
console.log(me.name, me.isAdmin)
// Servicios disponibles
await api.cells.getValue({ /* ... */ })
await api.cubes.get({ /* ... */ })
await api.processes.get({ /* ... */ })
await api.views.get({ /* ... */ })
await api.subsets.get({ /* ... */ })
await api.security.getAllUsers()
await api.connection.logout()Interceptores
getApi(config, options) acepta interceptores de request/response/error de axios:
import { getApi, type RequestInterceptor, type ErrorInterceptor } from '@hshp/pawtm1js'
const addAuthHeader: RequestInterceptor = (req) => {
req.headers.set('X-Custom', 'valor')
return req
}
const logErrors: ErrorInterceptor = (err) => {
console.error('PAW error:', err?.message)
}
const api = getApi(
{ pawUrl: 'https://mi-paw.example.com', serverName: 'Planning Sample' },
{ requestInterceptors: [addAuthHeader], errorInterceptors: [logErrors] }
)