UNPKG

lunify.js

Version:

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

44 lines (43 loc) 1.57 kB
import { EventEmitter } from "node:events"; import type { Lunify, Scopes } from "../.."; import { UserOauth } from "../../structures/user"; interface OauthEvents { /** * Emitted when a oauth token is refreshed. * @event OauthManager#refresh */ refresh: (oauth: UserOauth) => void; } export declare interface OauthManager { on: <T extends keyof OauthEvents>(event: T, callback: OauthEvents[T]) => this; emit: <T extends keyof OauthEvents>(event: T, ...args: Parameters<OauthEvents[T]>) => boolean; } export declare class OauthManager extends EventEmitter { client: Lunify; constructor(client: Lunify); /** * Create a oAuth url for users to authorize * @param {Scopes[]} scopes - A list of spotify scopes {@link https://developer.spotify.com/documentation/web-api/concepts/scopes} * @param {?string} state - If you want to use your own state use this */ generateUrl(scopes: Scopes[], state?: string): string; /** * Get a spotify access token from a oAuth code * @param {string} code - oauth response query code * @example ```ts * const code = req.query.code; * const access = await api.oauth.fetchToken(code); * ``` */ fetchToken(code: string): Promise<UserOauth>; /** * Refresh a spotify access token * @param {string} refreshToken - oauth refresh token * @example ```ts * const refreshToken = ...; * await api.oauth.refreshToken(refreshToken); * ``` */ refreshToken(refreshToken: string): Promise<UserOauth>; } export {};