The aim here is to create a client sdk for the cattle grid account api. This package is autogenerated using @hey-api/openapi-ts.
For background on cattle_grid, see here.
This API does not support event sources directly. For how to use them see Event Sources
Import the relevant methods and configure the client with
the baseUrl.
import { signin, accountInfo } from "@bovine/account-api";
import { client } from "@bovine/account-api/client";
client.setConfig({
baseUrl: "http://localhost:3001/fe",
});
One can sign in into an account with the account name and the corresponding password. For further requests, you will need the bearer token.
let result = await signin({ body: { name: "js", password: "js" } });
const bearerToken = result.data.token;
This is done via:
client.interceptors.request.use(async (request) => {
request.headers.set("Authorization", "Bearer " + bearerToken);
return request;
});
This can be done via
const result = await accountInfo();
The response data is in result.data the status code
can be retrieved from result.response.status.
Furthermore methods can be discovered via sdk.gen.
We are unfortunately dealing with many things called stream, so
we start with
import { type EventType, stream as apiStream } from "@bovine/account-api";
Now, we can subscribe to the stream via
const { stream } = await apiStream({
path: { event_type: 'incoming' as EventType },
});
for await (const event of stream) {
console.log(event);
}
We note that the heart beat is passed as an event, so you will want
to only examine event, when it is of type object.