tobogganSe connecter

starfleet-ui

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

369 lignes · 7085 octetsBrut · Historique
1/** Starfleet API types, hand-written from https://starfleet.glo.quebec/docs */
2
3export interface Link {
4 href: string;
5}
6
7export interface ActionField {
8 name: string;
9 type: string;
10 required: boolean;
11 options?: string[];
12}
13
14export interface GameAction {
15 name: string;
16 method: string;
17 href: string;
18 fields: ActionField[];
19}
20
21export interface Envelope<T> {
22 data: T;
23 links: Record<string, Link>;
24 actions: GameAction[];
25}
26
27export interface ApiErrorBody {
28 status: number;
29 code: string;
30 message: string;
31 /** JSON path of the offending request field, e.g. `$.waypoint`. */
32 path?: string;
33}
34
35export interface ErrorEnvelope {
36 error: ApiErrorBody;
37 links: Record<string, Link>;
38 actions: GameAction[];
39}
40
41// --- Captain ---
42
43export interface EntryPoint {
44 captain: string;
45 credits: number;
46}
47
48export interface Captain {
49 symbol: string;
50 credits: number;
51 headquarters: string;
52 founded_at: string;
53}
54
55export interface CaptainProfile {
56 callsign: string;
57 founded: string;
58 headquarters: string;
59 ships: number;
60 first_charters: number;
61 contracts_fulfilled: number;
62 federation: string | null;
63 badges: string[];
64 /** Systems this captain charted first. */
65 charted_first: string[];
66}
67
68// --- Ships ---
69
70/** Statuses of a ship that is inside the lanes and fully observable. */
71export type ActiveShipStatus = 'docked' | 'in_orbit' | 'in_transit';
72/** 0.2.0: a ship sent on a voyage leaves the lanes and only reports its return time. */
73export type ShipStatus = ActiveShipStatus | 'beyond_the_lanes';
74
75export interface ShipRoute {
76 from: string;
77 to: string;
78 departed: string;
79 arrives: string;
80}
81
82export interface CargoItem {
83 good: string;
84 units: number;
85}
86
87export interface FittedModule {
88 module: string;
89 bonus: number | null;
90}
91
92/** A ship in the lanes. `hull: 0` means it is disabled (stranded) until rescued. */
93export interface ActiveShip {
94 symbol: string;
95 status: ActiveShipStatus;
96 waypoint: string | null;
97 route: ShipRoute | null;
98 speed: number;
99 fuel: { current: number; capacity: number };
100 cargo: { units: number; capacity: number; items: CargoItem[] };
101 modules: FittedModule[];
102 hull: number;
103 insured_until: string | null;
104 ready: string | null;
105 trade: unknown | null;
106 as_of?: string;
107}
108
109/** A ship on a voyage (`POST /v1/ships/{ship}/voyage`): nothing but its return time is known. */
110export interface VoyagingShip {
111 symbol: string;
112 status: 'beyond_the_lanes';
113 returns: string;
114}
115
116export type Ship = ActiveShip | VoyagingShip;
117
118export function isActive(ship: Ship): ship is ActiveShip {
119 return ship.status !== 'beyond_the_lanes';
120}
121
122/** Hull at zero: the ship can't act until towed or tugged (error `ship_disabled`). */
123export function isDisabled(ship: Ship): boolean {
124 return isActive(ship) && ship.hull <= 0;
125}
126
127/** System symbol a waypoint belongs to: `ABC-12-D` → `ABC-12`. */
128export function systemOf(waypoint: string): string {
129 return waypoint.replace(/-[A-Z]$/, '');
130}
131
132// --- Galaxy ---
133
134export type WaypointKind =
135 | 'planet'
136 | 'moon'
137 | 'asteroid_field'
138 | 'gas_giant'
139 | 'station'
140 | 'jump_gate'
141 | 'wormhole'
142 | 'derelict';
143
144export interface Waypoint {
145 symbol: string;
146 system: string;
147 kind: WaypointKind;
148 x: number;
149 y: number;
150}
151
152export interface SystemSummary {
153 symbol: string;
154 x: number;
155 y: number;
156 charted: boolean;
157 waypoints: number | null;
158 first_charter: string | null;
159}
160
161export interface Lane {
162 system: string;
163 distance: number;
164 href: string;
165}
166
167export interface SystemDetail {
168 symbol: string;
169 x: number;
170 y: number;
171 charted: boolean;
172 nebula: boolean;
173 first_charter: string | null;
174 lanes: Lane[];
175 waypoints: Envelope<Waypoint>[];
176}
177
178// --- Market ---
179
180export interface MarketGood {
181 good: string;
182 buy: number;
183 sell: number;
184 supply: number;
185 baseline: number;
186}
187
188export interface Market {
189 station: string;
190 goods: MarketGood[];
191}
192
193export interface ModuleInfo {
194 module: string;
195 price: number;
196 bonus: number | null;
197}
198
199// --- Log & events ---
200
201export interface LogEntry {
202 number: number;
203 at: string;
204 kind: string;
205 ship: string | null;
206 waypoint: string | null;
207 text: string;
208}
209
210export type LogEntryEnvelope = Envelope<LogEntry>;
211
212export interface GalaxyEvent {
213 kind: 'storm' | 'boom' | 'surge';
214 system: string;
215 starts: string;
216 ends: string;
217 effect: string;
218}
219
220// --- Contracts & postings ---
221
222export interface ContractOffer {
223 id: string;
224 station: string;
225 good: string;
226 units: number;
227 reward: number;
228 hours: number;
229 accepted: boolean;
230}
231
232export interface CaptainContract {
233 id: string;
234 station: string;
235 good: string;
236 units: number;
237 reward: number;
238 hours: number;
239 status: 'open' | 'fulfilled' | 'lapsed';
240 delivered: number;
241 accepted_at: string;
242 due: string;
243}
244
245export interface Posting {
246 id: string;
247 station: string;
248 good: string;
249 units: number;
250 delivered: number;
251 reward: number;
252 paid: number;
253 due: string;
254 standing: 'open' | 'taken' | 'fulfilled' | 'lapsed' | 'withdrawn';
255 role: 'poster' | 'taker' | null;
256}
257
258export interface Warehouse {
259 station: string;
260 goods: CargoItem[];
261}
262
263// --- Federations & factions ---
264
265export interface FederationSummary {
266 tag: string;
267 name: string;
268 leader: string;
269 members: number;
270}
271
272export interface Federation {
273 tag: string;
274 name: string;
275 status: string;
276 leader: string;
277 members: { captain: string; since: string }[];
278 invited: string[];
279 treasury?: number;
280}
281
282export interface Faction {
283 faction: string;
284 name: string;
285 rival: string;
286 standing: number;
287 stance: string;
288 stations: string[];
289}
290
291export interface Influence {
292 system: string;
293 controller: string | null;
294 control_points: number;
295 tariff_percent: number;
296 standings: { federation: string; points: number }[];
297}
298
299export interface Message {
300 from: string;
301 text: string;
302 at: string;
303}
304
305export interface Explorer {
306 rank: number;
307 captain: string;
308 charters: number;
309 latest: string;
310}
311
312export interface ScanFragment {
313 number: number;
314 of: number;
315 encoding: 'plain' | 'base64' | 'shifted';
316 hint: string;
317 text: string;
318}
319
320export type FederationStance = 'ally' | 'embargo' | 'neutral';
321
322export interface Relations {
323 federation: string;
324 stances: { federation: string; stance: FederationStance }[];
325}
326
327// --- 0.2.0 additions (typed for compatibility; no dedicated UI yet) ---
328
329export interface GalaxySummary {
330 systems: number;
331 frontier: number;
332 /** Frontier systems nobody has reached yet. */
333 hum: number;
334 /** Describes what wakes at the first gate once `hum` reaches 0. */
335 keeper: string | null;
336}
337
338export interface CaptainCharts {
339 surveyed: string[];
340 bought: string[];
341}
342
343export interface ChartOffer {
344 id: string;
345 system: string;
346 price: number;
347 yours: boolean;
348 for_you_only: boolean;
349 expires: string;
350 status: string;
351}
352
353export interface ChartPurchase {
354 system: string;
355 price: number;
356 offer: string;
357 at: string;
358}
359
360export interface Webhook {
361 url: string;
362 delivered_through: number | null;
363 failures: number;
364 last_failure: string | null;
365 /** Set only in the response to `PUT /v1/captain/webhook`; `GET` answers null. */
366 secret?: string | null;
367}
368
369// `GET /v1/distress` entries are not typed yet: the docs only show an empty list.