feat: Added getDeviceFirmwares API (#10)

This commit is contained in:
Pascal Bourque
2025-06-02 07:04:45 -04:00
committed by GitHub
parent 5ae54dd05d
commit 9df5030228
4 changed files with 33 additions and 4 deletions

View File

@@ -92,4 +92,6 @@ async function main() {
} }
} }
main().catch(rootLogger.error); main().catch((error) => {
rootLogger.error(error, 'Error in main');
});

View File

@@ -6,7 +6,7 @@ import { ChangeDeviceState } from '@/types/mqtt/in/ChangeDeviceState';
import { InMessageType } from '@/types/mqtt/in/InMessageType'; import { InMessageType } from '@/types/mqtt/in/InMessageType';
import { StartPublishingDeviceStatus } from '@/types/mqtt/in/StartPublishingDeviceStatus'; import { StartPublishingDeviceStatus } from '@/types/mqtt/in/StartPublishingDeviceStatus';
import { OutMessageType } from '@/types/mqtt/out/OutMessageType'; import { OutMessageType } from '@/types/mqtt/out/OutMessageType';
import { Devices } from '@/types/rest/Devices'; import { Devices, Firmwares } from '@/types/rest';
import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers'; import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers';
import { import {
AuthenticationDetails, AuthenticationDetails,
@@ -184,7 +184,25 @@ export class MysaApiClient {
const response = await this._fetcher(`${MysaApiBaseUrl}/devices`, { const response = await this._fetcher(`${MysaApiBaseUrl}/devices`, {
headers: { headers: {
Authorization: `${session.getAccessToken().getJwtToken()}` Authorization: `${session.getIdToken().getJwtToken()}`
}
});
if (!response.ok) {
throw new MysaApiError(response);
}
return response.json();
}
async getDeviceFirmwares(): Promise<Firmwares> {
this._logger.debug(`Fetching device firmwares...`);
const session = await this.getFreshSession();
const response = await this._fetcher(`${MysaApiBaseUrl}/devices/firmware`, {
headers: {
Authorization: `${session.getIdToken().getJwtToken()}`
} }
}); });
@@ -320,7 +338,7 @@ export class MysaApiClient {
if ( if (
this._cognitoUserSession.isValid() && this._cognitoUserSession.isValid() &&
dayjs.unix(this._cognitoUserSession.getAccessToken().getExpiration()).isAfter() dayjs.unix(this._cognitoUserSession.getIdToken().getExpiration()).isAfter()
) { ) {
this._logger.info('Session is valid, no need to refresh'); this._logger.info('Session is valid, no need to refresh');
return Promise.resolve(this._cognitoUserSession); return Promise.resolve(this._cognitoUserSession);

View File

@@ -0,0 +1,8 @@
export interface FirmwareDevice {
Device: string;
InstalledVersion: string;
}
export interface Firmwares {
Firmware: Record<string, FirmwareDevice>;
}

View File

@@ -1 +1,2 @@
export * from './Devices'; export * from './Devices';
export * from './Firmwares';