UNPKG

lunify.js

Version:

A basic api wrapper for the spotify api covering the oauth routes.

45 lines (44 loc) 1.42 kB
import type { ApiRefreshTokenResponse, ApiTokenResponse } from "../../../interfaces/oauth"; import type { Lunify } from "../.."; import { Scopes } from "../.."; export declare class UserOauth { client: Lunify; accessToken: string; refreshToken: string | null; tokenType: string; scope: Scopes[]; expiresIn: number; expiresTimestamp: number; createdTimestamp: number; revoked: boolean; constructor(client: Lunify, data: ApiTokenResponse | ApiRefreshTokenResponse); private convertScopesToStringArray; /** * Refresh a spotify access token * @param {string} refreshToken - oauth refresh token * @example ```ts * await access.refresh(); * ``` * Or if you want to use a specific refresh token, like from a database * @example ```ts * const refreshToken = ...; // from the database for example * await access.refresh(refreshToken); * ``` */ refresh(refreshToken?: string): Promise<string>; /** * Generates a authorization token header */ getAuthorization(): Promise<string>; /** * Check if the access token is still valid (expires after 1 hour of creating, usually) */ isValid(): boolean; /** * Fetch the user accociated with this access token * @example ```ts * const user = await access.fetchUser(); * ``` */ fetchUser(): Promise<import(".").User>; }