@tmlmobilidade/external 20260722.1043.2 → 20260723.1350.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UnirVehicleLocationResponse } from './types.js';
|
|
2
|
+
export declare const UnirClient: Readonly<{
|
|
3
|
+
/**
|
|
4
|
+
* Fetches vehicle locations from the Unir API.
|
|
5
|
+
*
|
|
6
|
+
* @returns {Promise<UnirVehicleLocationResponse>} A promise that resolves with the vehicle locations response.
|
|
7
|
+
*/
|
|
8
|
+
vehiclePositions: () => Promise<UnirVehicleLocationResponse>;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
/* * */
|
|
3
|
+
const BASE_URL = process.env.UNIR_API_URL;
|
|
4
|
+
const API_KEY = process.env.UNIR_API_KEY;
|
|
5
|
+
async function fetcher(endpoint) {
|
|
6
|
+
if (!BASE_URL) {
|
|
7
|
+
throw new Error('Missing UNIR_API_URL environment variable.');
|
|
8
|
+
}
|
|
9
|
+
if (!API_KEY) {
|
|
10
|
+
throw new Error('Missing UNIR_API_KEY environment variable.');
|
|
11
|
+
}
|
|
12
|
+
const response = await fetch(`${BASE_URL}${endpoint}`, {
|
|
13
|
+
headers: {
|
|
14
|
+
'api-key': API_KEY,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
throw new Error(`Request failed (${response.status}): ${response.statusText}`);
|
|
19
|
+
}
|
|
20
|
+
return response;
|
|
21
|
+
}
|
|
22
|
+
/* * */
|
|
23
|
+
const endpoints = {
|
|
24
|
+
vehiclePositions: '/amp/api-sa/localizacoes-veiculos-direto',
|
|
25
|
+
};
|
|
26
|
+
export const UnirClient = Object.freeze({
|
|
27
|
+
/**
|
|
28
|
+
* Fetches vehicle locations from the Unir API.
|
|
29
|
+
*
|
|
30
|
+
* @returns {Promise<UnirVehicleLocationResponse>} A promise that resolves with the vehicle locations response.
|
|
31
|
+
*/
|
|
32
|
+
vehiclePositions: async () => {
|
|
33
|
+
const response = await fetcher(endpoints.vehiclePositions);
|
|
34
|
+
return await response.json();
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @see GET /amp/api-sa/localizacoes-veiculos-direto
|
|
3
|
+
*/
|
|
4
|
+
export interface UnirVehicleLocationResponse {
|
|
5
|
+
code: number;
|
|
6
|
+
message: UnirVehicleLocation[];
|
|
7
|
+
timestamp: string;
|
|
8
|
+
}
|
|
9
|
+
export interface UnirVehicleLocation {
|
|
10
|
+
atrasoMaximo: number;
|
|
11
|
+
atrasoMedio: number;
|
|
12
|
+
avancoMaximo: number;
|
|
13
|
+
avancoMedio: number;
|
|
14
|
+
codigoPublicoLinha: string;
|
|
15
|
+
codigoServico: string;
|
|
16
|
+
codigoUltimaParagem: string;
|
|
17
|
+
estado: string;
|
|
18
|
+
estadoCumprimento: string;
|
|
19
|
+
estaNaParagem: boolean;
|
|
20
|
+
horaUltimoEvento: string;
|
|
21
|
+
id: string;
|
|
22
|
+
instanteAtualizacao: string;
|
|
23
|
+
latitude: number;
|
|
24
|
+
longitude: number;
|
|
25
|
+
nomeLinha: string;
|
|
26
|
+
nomeOperador: string;
|
|
27
|
+
numAtrasos: number;
|
|
28
|
+
numAvancos: number;
|
|
29
|
+
numeroIdentificacaoVeiculo: string;
|
|
30
|
+
numEventos: number;
|
|
31
|
+
numExcessosLatenciaChegadaPartidaParagem: number;
|
|
32
|
+
numExcessosLatenciaInicioFimServico: number;
|
|
33
|
+
numExcessosLatenciaLocalizacao: number;
|
|
34
|
+
numTotalSaidasRota: number;
|
|
35
|
+
operadorId: number;
|
|
36
|
+
recordedAtTime: string;
|
|
37
|
+
recordedProcessAtTime: string;
|
|
38
|
+
stopPointRef: string;
|
|
39
|
+
temDadosCompletos: boolean;
|
|
40
|
+
vehicleAtStop: boolean;
|
|
41
|
+
vehicleRef: string;
|
|
42
|
+
velocity: number;
|
|
43
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -58,4 +58,7 @@ export declare const externalClients: Readonly<{
|
|
|
58
58
|
ttsl: Readonly<{
|
|
59
59
|
vehiclePositions: () => Promise<import("@tmlmobilidade/go-types-gtfs-rt").GtfsRtFeedMessage>;
|
|
60
60
|
}>;
|
|
61
|
+
unir: Readonly<{
|
|
62
|
+
vehiclePositions: () => Promise<import("./clients/unir/types.js").UnirVehicleLocationResponse>;
|
|
63
|
+
}>;
|
|
61
64
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { MlClient } from './clients/ml/index.js';
|
|
|
8
8
|
import { MobiClient } from './clients/mobi/index.js';
|
|
9
9
|
import { TcbClient } from './clients/tcb/index.js';
|
|
10
10
|
import { TtslClient } from './clients/ttsl/index.js';
|
|
11
|
+
import { UnirClient } from './clients/unir/index.js';
|
|
11
12
|
/**
|
|
12
13
|
* Collection of external transport agency clients.
|
|
13
14
|
*
|
|
@@ -34,4 +35,5 @@ export const externalClients = Object.freeze({
|
|
|
34
35
|
mobi: MobiClient,
|
|
35
36
|
tcb: TcbClient,
|
|
36
37
|
ttsl: TtslClient,
|
|
38
|
+
unir: UnirClient,
|
|
37
39
|
});
|