TypeScript-first API client for the DAMEN Triton REST API.
fetch)npm install damen-triton
fetchImpl)Api-Keysubscription-keyimport client from "damen-triton";
const triton = client({
apiKey: process.env.TRITON_API_KEY!,
subscriptionKey: process.env.TRITON_SUBSCRIPTION_KEY!,
yardNumber: process.env.TRITON_YARD_NUMBER!,
clientConfig: {
clientId: process.env.TRITON_CLIENT_ID!,
clientSecret: process.env.TRITON_CLIENT_SECRET!,
scope: process.env.TRITON_API_SCOPE!,
},
});
const metadata = await triton.metadata();
console.log(metadata.vesselInfo.id);
const latest = await triton.sensors().sensor("1000").latest_reading({
isManualInput: false,
});
console.log(latest);
type ClientConfig = {
baseURL?: string | URL; // default: https://tritonservices.azure-api.net
apiKey: string;
subscriptionKey?: string;
yardNumber?: string;
clientConfig?: {
grantType?: string; // default: "client_credentials"
clientId: string;
clientSecret: string;
scope: string;
renewSkewMs?: number; // default: 30000
};
fetchImpl?: typeof fetch;
};
Use triton.token.create(...) or pass your own Authorization header in low-level requests.
Provide clientConfig. The client renews token automatically before requests that use withAuth.
triton.sensors(<vessel_id>) uses explicit vessel idtriton.sensors() resolves vessel id lazily through api.metadata() using:
subscriptionKeyyardNumberIf these are missing, methods that require vessel context throw an error.
triton.metadata(options?)
/api/v1/metadata/vesselsvessel_id in client contexttriton.sensors(vesselId?).list()triton.sensors(vesselId?).sensor(sensorId).latest_reading(query?)triton.sensors(vesselId?).sensor(sensorId).readings(query?)triton.sensors(vesselId?).latest_readings(query?)triton.sensors(vesselId?).virtualsensors.latest_reading(query?)triton.sensors(vesselId?).data(query?)triton.token.create(body, query?)triton.token.renew(force?)triton.token.valid()triton.request(path, method, args, requestInit?)Use this only when you need direct access to typed route-level calls.
Project examples are in examples/:
examples/01_bootstrap_and_metadata.tsexamples/02_sensor_latest_auto_vessel.tsexamples/03_sensor_readings_explicit_vessel.tsexamples/04_virtual_and_data.tsexamples/05_token_manual_control.tsexamples/06_get_all_sensors.tsRun one example (from this repository):
npx tsx --env-file=.env examples/06_get_all_sensors.ts
Non-2xx responses throw an Error with a message from the JSON response (when available), otherwise:
HTTP <status> <statusText>: <response text>
npm run build
npm test
Apache-2.0