damen-triton
v1.0.3
Published
A TypeScript-first, dependency-free API client for the DAMEN Triton REST API
Maintainers
Readme
damen-triton
TypeScript-first API client for the DAMEN Triton REST API.
- Dependency-free runtime (uses
fetch) - Typed request/response surface
- Built-in token renewal flow (optional)
- Automatic vessel resolution from metadata (optional)
Installation
npm install damen-tritonRequirements
- Node.js 18+ (or provide a custom
fetchImpl) - Triton credentials:
Api-Keysubscription-key- Azure AD app credentials (if using token auto-renew)
Quick Start
import 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);Client Configuration
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;
};Authentication Modes
1) Api-Key + manual token handling
Use triton.token.create(...) or pass your own Authorization header in low-level requests.
2) Api-Key + auto token renewal (recommended)
Provide clientConfig. The client renews token automatically before requests that use withAuth.
Vessel Resolution
triton.sensors(<vessel_id>)uses explicit vessel idtriton.sensors()resolves vessel id lazily throughapi.metadata()using:subscriptionKeyyardNumber
If these are missing, methods that require vessel context throw an error.
API Surface
Metadata
triton.metadata(options?)- Fetches
/api/v1/metadata/vessels - Caches
vessel_idin client context
- Fetches
Sensors
triton.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?)
Tokens
triton.token.create(body, query?)triton.token.renew(force?)triton.token.valid()
Low-level request
triton.request(path, method, args, requestInit?)
Use this only when you need direct access to typed route-level calls.
Examples
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.ts
Run one example (from this repository):
npx tsx --env-file=.env examples/06_get_all_sensors.tsError Handling
Non-2xx responses throw an Error with a message from the JSON response (when available), otherwise:
HTTP <status> <statusText>: <response text>
Development
npm run build
npm testLicense
Apache-2.0
