Model a Track
This guide shows how to model a Track object that matches the shared contract.
1) Start with required fields
Section titled “1) Start with required fields”Track requires only id and url.
import type { Track } from '@ddgutierrezc/legato-contract';
const minimalTrack: Track = { id: 'episode-001', url: 'https://cdn.example.com/audio/episode-001.mp3',};2) Add optional display metadata
Section titled “2) Add optional display metadata”Add metadata only when your product surface needs it.
const withMetadata: Track = { id: 'episode-001', url: 'https://cdn.example.com/audio/episode-001.mp3', title: 'Episode 1', artist: 'Legato Team', album: 'Release Notes', artwork: 'https://cdn.example.com/artwork/episode-001.jpg', duration: 1840,};3) Declare media semantics with type
Section titled “3) Declare media semantics with type”When known, set type to one of the supported literals exported by the contract (file, progressive, hls, dash).
const typedTrack: Track = { id: 'episode-001', url: 'https://cdn.example.com/audio/episode-001.mp3', type: 'progressive',};4) Add per-track transport headers when needed
Section titled “4) Add per-track transport headers when needed”Use headers for static per-track HTTP request headers.
const protectedTrack: Track = { id: 'episode-001', url: 'https://cdn.example.com/audio/episode-001.mp3', type: 'progressive', headers: { Authorization: 'Bearer demo-token', 'X-Client-Version': '1.0.0', },};5) Reference setup-scoped shared headers when reuse is needed
Section titled “5) Reference setup-scoped shared headers when reuse is needed”Use headerGroupId when many tracks share static headers registered during setup.
const groupedTrack: Track = { id: 'episode-002', url: 'https://cdn.example.com/audio/episode-002.mp3', type: 'progressive', headerGroupId: 'premium-us',};If you include both fields, headers overrides group keys per header name.
Expected result
Section titled “Expected result”You can now construct Track values that satisfy the contract using required fields first, then optional metadata, type, and either per-track headers, shared group references, or both.