mirror of
https://github.com/bourquep/mysa-js-sdk.git
synced 2026-02-04 09:41:07 +00:00
feat: Added getDeviceFirmwares API (#10)
This commit is contained in:
@@ -92,4 +92,6 @@ async function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch(rootLogger.error);
|
main().catch((error) => {
|
||||||
|
rootLogger.error(error, 'Error in main');
|
||||||
|
});
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
8
src/types/rest/Firmwares.ts
Normal file
8
src/types/rest/Firmwares.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export interface FirmwareDevice {
|
||||||
|
Device: string;
|
||||||
|
InstalledVersion: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Firmwares {
|
||||||
|
Firmware: Record<string, FirmwareDevice>;
|
||||||
|
}
|
||||||
@@ -1 +1,2 @@
|
|||||||
export * from './Devices';
|
export * from './Devices';
|
||||||
|
export * from './Firmwares';
|
||||||
|
|||||||
Reference in New Issue
Block a user