librelinkup-api-client
Version:
An unofficial API for Libre Link Up (glucose monitoring system/CGM)
108 lines (107 loc) • 3.66 kB
TypeScript
import { GlucoseReading } from "./reading";
import { LibreLoginResponse, LibreUser, LibreConnectionResponse, LibreLogbookResponse } from "./types";
/**
* A class for interacting with the Libre Link Up API.
*/
export declare class LibreLinkClient {
private apiUrl;
private accessToken;
private patientId;
private lluVersion;
private credentials;
private options;
private cache;
constructor(options: LibreLinkClientOptions);
/**
* @description Get the user data. Only available after logging in.
*/
get me(): LibreUser | null;
/**
* @description Log into the Libre Link Up API using the provided credentials.
*/
login(): Promise<LibreLoginResponse>;
/**
* @description Read the data from the Libre Link Up API.
* @returns The latest glucose measurement from the Libre Link Up API.
*/
read(): Promise<GlucoseReading>;
/**
* @description Read the history data from the Libre Link Up API.
*/
history(): Promise<GlucoseReading[]>;
/**
* @description Read the logbook data from manual scans from the Libre Link Up API.
*/
logbook(): Promise<GlucoseReading[]>;
/**
* @description Stream the readings from the Libre Link Up API.
* @param intervalMs The interval between each reading. Default is 90 seconds.
*/
stream(intervalMs?: number): AsyncGenerator<GlucoseReading, void, unknown>;
/**
* @description Fetch the reading from the Libre Link Up API. Use to obtain the raw reading and more.
* @returns The response from the Libre Link Up API.
*/
fetchReading(): Promise<LibreConnectionResponse>;
/**
* @description Fetch the logbook from the Libre Link Up API. Use to obtain the list of manual scanned readings.
* @returns The response from the Libre Link Up API.
*/
fetchLogbook(): Promise<LibreLogbookResponse>;
/**
* @description Get the connections from the Libre Link Up API.
*/
fetchConnections(): Promise<any>;
/**
* @description Get the patient ID from the connections.
*/
private getPatientId;
/**
* @description Find the region in the Libre Link Up API. This is used when the API returns a redirect.
* @param region The region to find.
* @returns The server URL for the region.
*/
private findRegion;
/**
* @description A generic fetcher for the Libre Link Up API.
* @param endpoint
* @param options
* @param isRetry Internal flag to prevent infinite retry loops
*/
private _fetcher;
/**
* @description Check if an error indicates that the authentication token has expired.
* @param statusCode The HTTP status code from the response
* @param errorMessage The error message from the response
* @returns True if the error indicates token expiration
*/
private isTokenExpiredError;
/**
* @description Cache a value, if caching is enabled.
* @param key The key to cache the value under.
* @param value The value to cache.
*/
private setCache;
/**
* @description Clear the cache.
*/
clearCache(): void;
/**
* @description Debug method to check if the client has a valid access token
* @returns Information about the current authentication state
*/
getAuthStatus(): {
hasToken: boolean;
tokenLength: number;
hasUser: boolean;
userId: string | null;
};
}
export interface LibreLinkClientOptions {
email: string;
password: string;
apiUrl?: string;
patientId?: string;
cache?: boolean;
lluVersion?: string;
}