IndigoTrace SDK
This javascript module exposes functions to communicate with the Indigo Trace API. You will first need to sign up for an account at indigotrace.com. Once you have created an input, you will need its private key to interact with the API.
Usage
import TraceSdk from "indigotrace-sdk";
const myKey = {
type: "ed25519",
secret:
"VD6zmq068l1EhaWfpRQxnlpTjGbwSN2q2XcgriBmo3Mco+7GK+BPLO49yxuQzbQ1dzd/6B+3YQb2c3BhqEaTsA=="
};
const url = 'https://api.indigotrace.com';
const sdk = TraceSdk(myKey, url);
const data = {
type: "test",
data: "data",
name: "name"
};
const payload = sdk.create(data);
const payload = sdk.create(data, {
traceID: 'db255d6d-8e7f-45e6-99f8-cf9f1084ba9b',
refs: ['event-id-1', 'event-id-2']
});
const signedPayload = sdk.sign(payload);
sdk.send(payload).then(rsp => {
const {data, event_id, trace_id, update_at, action } = rsp;
console.log(trace_id);
...
});
Head over to indigotrace.com and have a look at your workflow to see the new event in the traces section. You can inspect the content of the payload from there.
Retrieve traces
The SDK can also retrieve existing traces and events:
sdk.getTrace("db255d6d-8e7f-45e6-99f8-cf9f1084ba9b").then(rsp => {
const { trace_id, events } = rsp;
events.forEach(e => {
const { data, event_id, action, updated_at } = e;
console.log(data);
});
});
sdk.getTraces().then(rsp => {
const { workflow_id, traces } = rsp;
traces.forEach(trace => {
const { trace_id, events } = trace;
events.forEach(e => {
const { data, event_id, action, updated_at } = e;
console.log(data);
});
});
});
Verify payload signatures
Given a signed payload, it is possible to veify that the signatures are correct:
if (!sdk.verify(signedPayload)) {
throw new Error("Cannot verify this signature...");
}