Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
trac-web-api
Advanced tools
TRAC is a next-generation data and analytics platform for use in highly regulated environments
The TRAC web API provides a structured interface for developing web applications to run on the TRAC platform. It is based on the popular protobuf.js framework and uses the highly optimised gRPC-Web protocol for transport. The package supports both JavaScript and TypeScript and provides everything needed to communicate with the TRAC platform directly from a web browser, no additional development tooling, setup or middleware is required. Inline documentation is available for IDEs that support it.
Documentation for the TRAC platform is available at trac-platform.readthedocs.io.
To install the web API package in your project:
npm install --save trac-web-api
Each of the TRAC services has a single public API class, which can be instantiated with just two lines of code.
import {trac} from 'trac-web-api';
class Example1 {
constructor() {
// Use trac.setup to create an RPC instance, you need one for each API class
// This instance is for use in the browser, it will direct calls to the page origin server
const metaApiRpcImpl = trac.setup.rpcImplForBrowser(trac.api.TracMetadataApi);
// Then create the API
this.metaApi = new trac.api.TracMetadataApi(metaApiRpcImpl);
}
...
The API methods can be called as JavaScript methods on the API classes, both futures and callbacks are supported.
exampleSearchWithFutures(tenant, searchParams) {
const searchRequest = {
tenant: tenant,
searchParams: searchParams
};
// API call using JavaScript futures
return this.metaApi.search(searchRequest)
.then(response => {
// handle response
console.log(response);
})
.catch(err => {
// handle error
console.log(err.message)
});
}
exampleSearcWithCallbacks(tenant, searchParams) {
const searchRequest = {
tenant: tenant,
searchParams: searchParams
};
// API call using Node-style callbcks
this.metaApi.search(searchRequest, (err, response) => {
if (err) {
// handle error
console.log(err.message);
}
else {
// handle response
console.log(response);
}
});
}
buildSearchParams() {
// An example search that could be used for the above calls
const exampleSearchParams = {
objectType: trac.ObjectType.MODEL,
search: { logical: {
operator: trac.LogicalOperator.AND,
expr: [
{ term: {
attrName: "model_type",
attrType: trac.STRING,
operator: trac.SearchOperator.EQ,
searchValue: { stringValue: "acme_widget_model" }
}},
{ term: {
attrName: "model_owner",
attrType: trac.STRING,
operator: trac.SearchOperator.EQ,
searchValue: { stringValue: "wile.e.cyote" }
}},
]
}}
}
const err = trac.metadata.SearchParameters.verify(exampleSearchParams);
if (err)
throw err;
return trac.metadata.SearchParameters.create(exampleSearchParams);
}
To learn how to build applications on TRAC, check out the application development section in our online documentation. It may also be helpful to look at the documentation of protobuf.js, which is used to generate the TRAC API classes for the web API package.
Often it will be helpful to run a local instance of TRAC when developing against the web API, to test your API calls against a real implementation without needing to run your full build pipeline and push to a dev/test server.
There are no pre-built packages (yet!) for the TRAC platform services. To build and run the platform from source, follow the instructions in the main README file in the root of the TRAC source code repository. To avoid any compatibility issues, make sure you check out the version tag that matches your version of the web API.
For a local dev setup, you can use the TRAC gateway to route both your app content and API calls. Look in the main code repo under etc/ for an example configuration file for the gateway, which includes an example of pointing a route at your local dev server, whether that's the one in your IDE or WebPack or whatever your favourite dev server tool is. Once your you dev server running and the gateway is configured, access your app through the gateway. You will see API calls redirected to the appropriate TRAC services.
The simplest way to mock the API classes is to extend the API class you want to mock and just override the methods you are interested in to return your test data. Some simple scaffolding will allow for support of both futures and callbacks (if you are sticking to one pattern this may not be necessary). It is also probably helpful to throw an error for methods that are not available in the mock implementation.
Here is a quick example of one way this could be done.
class LocalImpl extends trac.api.TracMetadataApi {
// Set an RPC impl to throw an error for methods that have not been mocked
constructor() {
super(() => { throw new Error("Not implemented locally")});
}
// Helper function to handle both future and callback patterns
callbackOrFuture(callback, err, response) {
if (callback)
callback(err, response);
else if (err)
return Promise.reject(err);
else
return Promise.resolve(response);
}
// Add mock implementations for whichever methods are needed...
search(request, callback) {
try {
// Some logic here, optionally using the contents of request
const dummyResponse = {searchResult: []};
return this.callbackOrFuture(callback, null, dummyResponse);
}
catch (err) {
return this.callbackOrFuture(callback, err, null);
}
}
}
This is not normally necessary for app development, but if you want to do it here are the commands.
cd trac-api/packagegs/web
npm install
npm run tracVersion:windows # For Windows platforms, requires PowerShell
npm run tracVersion:posix # For macOS or Linux
npm run buildApi
FAQs
API package for building web applications on the TRAC platform
We found that trac-web-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.