Typescript Axios Client SDK for trivium
SDK Development Documentation
To use SDK:
import { Configuration, UserApi, CashApi, FixedDepositApi, TransactionsApi } from '@triviumcapital/trivium-ts-sdk';
const TriviumService = (() => {
const triviumUrl = 'https://staging.api.triviumcapital.tech';
const configuration = new Configuration({
apiKey: '<your-api-key>',
accessToken: '<your-api-secret>'
});
const userApi = new UserApi(configuration, triviumUrl);
const cashApi = new CashApi(configuration, triviumUrl);
const fixedDepositApi = new FixedDepositApi(configuration, triviumUrl);
const transactionsApi = new TransactionsApi(configuration, triviumUrl);
return {
userApi,
cashApi,
fixedDepositApi,
transactionsApi
};
})();
const companyDetails = ...
const user = await TriviumService.userApi.postApiV1User(companyDetails);
Example server to verify callback requests from Trivium:
import express from "express";
import { verifyTriviumCallbackRequest } from "@triviumcapital/trivium-ts-sdk/security";
const app = express();
app.use(
express.json({
limit: "5mb",
verify: (req, res, buf) => {
req.rawBody = buf.toString();
},
})
);
const port = 3000;
const publicKey = "<public key retrieved from Trivium API>";
app.put("/webhook", (req, res) => {
const { rawBody } = req;
const timestamp = req.header("Trivium-Timestamp");
const signature = req.header("Trivium-Signature");
const isVerified = verifyTriviumCallbackRequest(
signature,
rawBody,
timestamp,
publicKey
);
console.log(`timestamp: ${timestamp}`);
console.log(`signature: ${signature}`);
console.log(`body: ${rawBody}`);
console.log(`isVerified: ${isVerified}`);
if (isVerified) {
res.sendStatus(200);
} else {
res.sendStatus(500);
}
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});