deezer-ts
Version:
Deezer API wrapper for Node.js
1,103 lines (1,086 loc) • 36 kB
text/typescript
/**
* Base class for all Deezer resources.
* All resource classes inherit from this class.
*
* @category Resources
*/
declare class Resource {
protected readonly client: Client;
protected _fields: string[];
protected _fetched: boolean;
id: number;
type: string;
constructor(client: Client, json: Record<string, any>);
toJSON(): Record<string, any>;
getRelation<T>(relation: string, resourceType?: new (client: Client, json: Record<string, any>) => Resource, params?: Record<string, string>, fwdParent?: boolean): Promise<T>;
getPaginatedList<T extends Resource>(relation: string, params?: Record<string, string>): PaginatedList<T>;
/**
* Ensures a field is loaded, fetching the full resource if necessary.
*
* @param fieldName The name of the field to ensure
* @returns The value of the field
* @throws Error if the field cannot be loaded
*/
protected ensureField<T>(fieldName: string): Promise<T>;
/**
* Get the resource from the API.
*
* @returns {Promise<this>}
*/
get(): Promise<this>;
}
/**
* To work with Deezer track objects.
*
* @see the {@link https://developers.deezer.com/api/track | Deezer Track API Documentation}
* for more details about each field.
*
* @extends Resource
* @category Resources
*/
declare class Track extends Resource {
readable: boolean;
title: string;
title_short: string;
title_version: string;
unseen?: boolean;
isrc?: string;
link?: string;
share?: string;
duration: number;
track_position?: number;
disk_number?: number;
rank: number;
release_date?: Date | null;
explicit_lyrics: boolean;
explicit_content_lyrics: number;
explicit_content_cover: number;
preview: string;
bpm?: number;
gain?: number;
available_countries?: string[];
alternative?: Track;
contributors?: Artist[];
md5_image: string;
artist: Artist;
album: Album;
/**
* @internal
*/
private _parse_release_date;
/**
* @internal
*/
private _parse_contributors;
/**
* Get the artist of the Track.
*
* @returns {Promise<Artist>} - the class {@link Artist} of the Track.
*/
getArtist(): Promise<Artist>;
/**
* Get the album of the Track.
*
* @returns {Promise<Album>} - the class {@link Album} of the Track.
*/
getAlbum(): Promise<Album>;
}
/**
* To work with Deezer user objects.
*
* @see the {@link https://developers.deezer.com/api/user | Deezer User API Documentation}
* for more details about each field.
*
* @extends Resource
* @category Resources
*/
declare class User extends Resource {
name: string;
lastname?: string;
firstname?: string;
email?: string;
status?: number;
birthday?: string;
inscription_date?: string;
gender?: string;
link?: string;
picture?: string;
picture_small?: string;
picture_medium?: string;
picture_big?: string;
picture_xl?: string;
country?: string;
lang?: string;
is_kid?: boolean;
explicit_content_level?: string;
explicit_content_levels_available?: string[];
tracklist: string;
/**
* Get user's favorite albums.
*
* @returns {Promise<PaginatedList<Album>>} - a {@link PaginatedList} of {@link Album} instances.
*/
getAlbums(params?: Record<string, string>): Promise<PaginatedList<Album>>;
/**
* Get user's favorite artists.
*
* @returns {Promise<PaginatedList<Artist>>} - a {@link PaginatedList} of {@link Artist} instances.
*/
getArtists(params?: Record<string, string>): Promise<PaginatedList<Artist>>;
/**
* Get user's followings.
*
* @returns {Promise<PaginatedList<User>>} - a {@link PaginatedList} of {@link User} instances.
*/
getFollowers(params?: Record<string, string>): Promise<PaginatedList<User>>;
/**
* Get user's followers.
*
* @returns {Promise<PaginatedList<User>>} - a {@link PaginatedList} of {@link User} instances.
*/
getFollowings(params?: Record<string, string>): Promise<PaginatedList<User>>;
/**
* Get user's public playlists.
*
* @returns {Promise<PaginatedList<Playlist>>} - a {@link PaginatedList} of {@link Playlist} instances.
*/
getPlaylists(params?: Record<string, string>): Promise<PaginatedList<Playlist>>;
}
/**
* To work with Deezer playlist objects.
*
* @see the {@link https://developers.deezer.com/api/playlist | Deezer Playlist API Documentation}
* for more details about each field.
*
* @extends Resource
* @category Resources
*/
declare class Playlist extends Resource {
title: string;
description: string;
duration: number;
public: boolean;
is_loved_track: boolean;
collaborative: boolean;
nb_tracks: number;
unseen_track_count: number;
fans: number;
link: string;
share: string;
picture: string;
picture_small: string;
picture_medium: string;
picture_big: string;
picture_xl: string;
checksum: string;
creator: User;
tracks?: Track[];
/**
* Get tracks from a playlist.
*
* @returns {Promise<PaginatedList<Track>>} - a {@link PaginatedList} of {@link Track} instances.
*/
getTracks(params?: Record<string, string>): Promise<PaginatedList<Track>>;
/**
* Get fans from a playlist.
*
* @returns {Promise<PaginatedList<User>>} - a {@link PaginatedList} of {@link User} instances.
*/
getFans(params?: Record<string, string>): Promise<PaginatedList<User>>;
}
/**
* To work with Deezer artist objects.
*
* @see the {@link https://developers.deezer.com/api/artist | Deezer Artist API Documentation}
* for more details about each field.
*
* @extends Resource
* @category Resources
*/
declare class Artist extends Resource {
name: string;
link?: string;
share?: string;
picture: string;
picture_small: string;
picture_medium: string;
picture_big: string;
picture_xl: string;
nb_album?: number;
nb_fan?: number;
radio?: boolean;
tracklist: string;
role?: string;
/**
* Get the top tracks of an artist.
*
* @returns {Promise<PaginatedList<Track>>} - a {@link PaginatedList} of {@link Track} instances.
*/
getTop(params?: Record<string, string>): Promise<PaginatedList<Track>>;
/**
* Get a list of related artists.
*
* @returns {Promise<PaginatedList<Artist>>} - a {@link PaginatedList} of {@link Artist} instances.
*/
getRelated(params?: Record<string, string>): Promise<PaginatedList<Artist>>;
/**
* Get a list of tracks.
*
* @returns {Promise<Track[]>} - list of {@link Track} instances.
*/
getRadio(params?: Record<string, string>): Promise<Track[]>;
/**
* Get a list of artist's albums.
*
* @returns {Promise<PaginatedList<Album>>} - a {@link PaginatedList} of {@link Album} instances.
*/
getAlbums(params?: Record<string, string>): Promise<PaginatedList<Album>>;
/**
* Get a list of artist's playlists.
*
* @returns {Promise<PaginatedList<Playlist>>} - a {@link PaginatedList} of {@link Playlist} instances.
*/
getPlaylists(params?: Record<string, string>): Promise<PaginatedList<Playlist>>;
}
/**
* To work with Deezer episode objects.
*
* @see the {@link https://developers.deezer.com/api/episode | Deezer Episode API Documentation}
* for more details about each field.
*
* @extends Resource
* @category Resources
*/
declare class Episode extends Resource {
title: string;
description: string;
available: boolean;
release_date: Date | null;
duration: number;
link: string;
share: string;
picture: string;
picture_small: string;
picture_medium: string;
picture_big: string;
picture_xl: string;
podcast: Podcast;
/**
* @internal
*/
private _parse_release_date;
}
/**
* To work with Deezer podcast objects.
*
* @see the {@link https://developers.deezer.com/api/podcast | Deezer Podcast API Documentation}
* for more details about each field.
*
* @extends Resource
* @category Resources
*/
declare class Podcast extends Resource {
title: string;
description: string;
available: boolean;
fans: number;
link: string;
share: string;
picture: string;
picture_small: string;
picture_medium: string;
picture_big: string;
picture_xl: string;
/**
* Get episodes from a podcast.
*
* @returns {Promise<PaginatedList<Episode>>} - a {@link PaginatedList} of {@link Episode} instances.
*/
getEpisodes(params?: Record<string, string>): Promise<PaginatedList<Episode>>;
}
/**
* To work with Deezer radio objects.
*
* @see the {@link https://developers.deezer.com/api/radio | Deezer Radio API Documentation}
* for more details about each field.
*
* @extends Resource
* @category Resources
*/
declare class Radio extends Resource {
title: string;
description: string;
share: string;
picture: string;
picture_small: string;
picture_medium: string;
picture_big: string;
picture_xl: string;
tracklist: string;
md5_image: string;
/**
* Get first 40 tracks in the radio.
*
* Note that this endpoint is NOT paginated.
*
* @returns {Promise<Track[]>} - list of {@link Track} instances.
*/
getTracks(): Promise<Track[]>;
}
/**
* To work with Deezer genre objects.
*
* @see the {@link https://developers.deezer.com/api/genre | Deezer Genre API Documentation}
* for more details about each field.
*
* @extends Resource
* @category Resources
*/
declare class Genre extends Resource {
name: string;
picture: string;
picture_small: string;
picture_medium: string;
picture_big: string;
picture_xl: string;
/**
* Get all artists for a genre.
*
* @returns {Promise<Artist[]>} - list of {@link Artist} instances.
*/
getArtists(params?: Record<string, string>): Promise<Artist[]>;
/**
* Get all podcasts for a genre.
*
* @returns {Promise<PaginatedList<Podcast>>} - a {@link PaginatedList} of {@link Podcast} instances.
*/
getPodcasts(params?: Record<string, string>): Promise<PaginatedList<Podcast>>;
/**
* Get all radios for a genre.
*
* @returns {Promise<Radio[]>} - list of {@link Artist} instances.
*/
getRadios(params?: Record<string, string>): Promise<Radio[]>;
}
/**
* To work with Deezer album objects.
*
* @see the {@link https://developers.deezer.com/api/album | Deezer Album API Documentation}
* for more details about each field.
*
* @extends Resource
* @category Resources
*/
declare class Album extends Resource {
title: string;
upc?: string;
link?: string;
share?: string;
cover: string;
cover_small: string;
cover_medium: string;
cover_big: string;
cover_xl: string;
md5_image: string;
genre_id?: number;
genres?: Genre[];
label?: string;
nb_tracks?: number;
duration?: number;
fans?: number;
release_date?: Date | null;
record_type?: string;
available?: boolean;
alternative?: Album;
tracklist: string;
explicit_lyrics?: boolean;
explicit_content_lyrics?: number;
explicit_content_cover?: number;
contributors?: Artist[];
artist?: Artist;
tracks?: Track[];
role?: string;
/**
* @internal
*/
private _parse_release_date;
/**
* @internal
*/
private _parse_contributors;
/**
* Get the artist of the Album.
*
* @returns {Promise<Artist>} - the class {@link Artist} of the Album.
*/
getArtist(): Promise<Artist>;
/**
* Get a list of album's tracks.
*
* @returns {Promise<PaginatedList<Track>>} - a {@link PaginatedList} of {@link Track}.
*/
getTracks(params?: Record<string, string>): Promise<PaginatedList<Track>>;
}
/**
* To work with Deezer chart objects.
*
* @see the {@link https://developers.deezer.com/api/chart | Deezer Chart API Documentation}
* for more details about each field.
*
* @extends Resource
* @category Resources
*/
declare class Chart extends Resource {
tracks: Track[] | [];
albums: Album[] | [];
artists: Artist[] | [];
playlists: Playlist[] | [];
podcasts: Podcast[] | [];
type: string;
/**
* Return the chart for tracks.
*
* @returns {Promise<PaginatedList<Track>>} - a {@link PaginatedList} of {@link Track} instances.
*/
getTracks(params?: Record<string, string>): Promise<PaginatedList<Track>>;
/**
* Return the chart for albums.
*
* @returns {Promise<PaginatedList<Album>>} - a {@link PaginatedList} of {@link Album} instances.
*/
getAlbums(params?: Record<string, string>): Promise<PaginatedList<Album>>;
/**
* Return the chart for artists.
*
* @returns {Promise<PaginatedList<Artist>>} - a {@link PaginatedList} of {@link Artist} instances.
*/
getArtists(params?: Record<string, string>): Promise<PaginatedList<Artist>>;
/**
* Return the chart for playlists.
*
* @returns {Promise<PaginatedList<Playlist>>} - a {@link PaginatedList} of {@link Playlist} instances.
*/
getPlaylists(params?: Record<string, string>): Promise<PaginatedList<Playlist>>;
/**
* Return the chart for podcasts.
*
* @returns {Promise<PaginatedList<Podcast>>} - a {@link PaginatedList} of {@link Podcast} instances.
*/
getPodcasts(params?: Record<string, string>): Promise<PaginatedList<Podcast>>;
}
/**
* To work with Deezer editorial objects.
*
* @see the {@link https://developers.deezer.com/api/editorial | Deezer Editorial API Documentation}
* for more details about each field.
*
* @extends Resource
* @category Resources
*/
declare class Editorial extends Resource {
name: string;
picture: string;
picture_small: string;
picture_medium: string;
picture_big: string;
picture_xl: string;
/**
* Get a list of albums selected every week by the Deezer Team.
*
* @returns {Promise<Album[]>} - list of {@link Album} instances.
*/
getSelection(): Promise<Album[]>;
/**
* Get top charts for tracks, albums, artists and playlists.
*
* @returns {Promise<Chart>} - a {@link Chart} instances.
*/
getChart(): Promise<Chart>;
/**
* Get the new releases per genre for the current country.
*
* @returns {Promise<PaginatedList<Album>>} - a {@link PaginatedList} of {@link Album} instances.
*/
getReleases(params: Record<string, string>): Promise<PaginatedList<Album>>;
}
/**
* A paginated list of resources from the Deezer API.
* This class implements AsyncIterable to allow for easy iteration over all items.
*
* @category PaginatedList
*/
declare class PaginatedList<T extends Resource> implements AsyncIterable<T> {
private readonly client;
private readonly basePath;
private readonly parent?;
private readonly params?;
private elements;
private nextPath;
private nextParams;
private totalItems;
constructor(client: Client, basePath: string, parent?: Resource | undefined, params?: Record<string, string> | undefined);
[Symbol.asyncIterator](): AsyncIterator<T>;
/**
* The total number of items in the list, mirroring what Deezer returns.
*
* @returns {Promise<number | null>} - The total number of items in the list.
*/
total(): Promise<number | null>;
/**
* Returns a slice of the list.
*
* @param {number} start - The index to start the slice at.
* @param {number} end - The index to end the slice at.
*
* @returns {Promise<T[]>} - The slice of the list.
*/
slice(start?: number, end?: number): Promise<T[]>;
/**
* Returns the item at the given index.
*
* @param {number} index - The index of the item to return.
*
* @returns {Promise<T>} - The item at the given index.
*/
get(index: number): Promise<T>;
/**
* Returns the list as an array.
*
* This method is not recommended for large lists, as it will fetch all items at once.
*
* @returns {Promise<T[]>} - The list as an array.
*/
toArray(): Promise<T[]>;
private couldGrow;
private grow;
private fetchNextPage;
}
/**
* Constructor type for Resource classes.
* Used to create new instances of resources from JSON responses.
*
* @category Core
*/
type ResourceConstructor = new (client: Client, json: JsonResponse) => Resource;
/**
* Interface for paginated responses from the Deezer API.
* Contains an array of items and pagination information.
*
* @template T - The type of items in the data array
* @category Core
*/
type GenericPaginatedList<T> = {
/** Array of items in the current page */
data: T[];
/** Total number of items available */
total: number;
/** URL to the previous page, if available */
prev?: string;
/** URL to the next page, if available */
next?: string;
};
type JsonResponse = {
id?: number;
type?: string;
data?: JsonResponse[];
next?: string;
prev?: string;
total?: number;
[key: string]: any;
};
/**
* A client to retrieve some basic infos about Deezer resources.
*
* Create a client instance with the given options.
* Options should be passed in to the constructor as kwargs.
*
* @example
* ```ts
* import { Client } from "deezer-ts";
* client = new Client();
* ```
* This client provides several methods to retrieve the content
* most kinds of Deezer objects, based on their json structure.
*
* Headers can be forced by using the `headers` kwarg.
* For example, use `Accept-Language` header to force the output language.
*
* @example
* ```ts
* import { Client } from "deezer-ts";
* client = new Client({ headers: { "Accept-Language": "en" } });
* ```
* @param {Record<string, string>} headers - Additional headers to pass.
*
* @category Client
*/
declare class Client {
private headers?;
/**
* @internal
*/
private baseUrl;
private static requestQueue;
private static readonly QUOTA_WINDOW;
private static readonly QUOTA_LIMIT;
/**
* Create a new client instance.
*
* @param {Record<string, string>} [headers] - Additional headers to pass.
*/
constructor(headers?: Record<string, string> | undefined);
/**
* @internal
*/
private readonly objectsTypes;
/**
* @internal
* Ensures we don't exceed Deezer's rate limit of 50 requests per 5 seconds
*/
private enforceRateLimit;
/**
* @internal
* Retries an operation with exponential backoff when encountering retryable errors.
*
* This method implements an exponential backoff strategy for retrying failed operations:
* - Initial delay is baseDelay (default 2000ms)
* - Each retry doubles the delay
* - Adds random jitter (75-125% of calculated delay) to prevent thundering herd
* - Only retries on quota exceeded or other retryable errors
*
* @param {() => Promise<T>} operation - The async operation to retry
* @param {number} maxRetries - Maximum number of retry attempts (default: 3)
* @param {number} baseDelay - Base delay in milliseconds before first retry (default: 2000)
* @returns {Promise<T>} The result of the operation if successful
* @throws {Error} The last error encountered if all retries fail
* @throws {Error} Non-retryable errors immediately without retry
* @template T - The return type of the operation
*/
private retryWithBackoff;
/**
* @internal
*
* Recursively convert dictionary to Resource object.
*
* @param item - the JSON response as object.
* @param parent - A reference to the parent resource, to avoid fetching again.
* @param resourceType - The resource class to use as top level.
* @param resourceId - The resource id to use as top level.
* @param paginateList - Whether to wrap list into a pagination object.
* @returns instance of Resource
* @throws DeezerUnknownResource
*/
private _processJson;
/**
* Make a request to the API and parse the response.
*
* @template T - The type of the response.
* @param {string} method - The HTTP method to use.
* @param {string} path - The path to request.
* @param {boolean} paginateList - Whether to paginate the response.
* @param {Resource} [parent] - The parent resource.
* @param {ResourceConstructor} [resourceType] - The resource type.
* @param {number} [resourceId] - The resource id.
* @param {Record<string, string>} [params] - Additional parameters to pass.
* @returns {Promise<T>} - The response.
*/
request<T>(method: string, path: string, paginateList: false, parent?: Resource, resourceType?: ResourceConstructor, resourceId?: number, params?: Record<string, string>): Promise<T>;
/**
* Make a request to the API and parse the response.
*
* @template T - The type of the response.
* @param {string} method - The HTTP method to use.
* @param {string} path - The path to request.
* @param {boolean} paginateList - Whether to paginate the response.
* @param {Resource} [parent] - The parent resource.
* @param {ResourceConstructor} [resourceType] - The resource type.
* @param {number} [resourceId] - The resource id.
* @param {Record<string, string>} [params] - Additional parameters to pass.
* @returns {GenericPaginatedList<T>} - The response.
*/
request<T>(method: string, path: string, paginateList: true, parent?: Resource, resourceType?: ResourceConstructor, resourceId?: number, params?: Record<string, string>): Promise<GenericPaginatedList<T>>;
/**
* @internal
* @private
*/
private getPaginatedList;
/**
* Get the album with the given id.
*
* @param {number} albumId - The id of the album to get.
* @returns {@link Album} - An album object.
*/
getAlbum(albumId: number): Promise<Album>;
/**
* Get the artist with the given id.
*
* @param {number} artistId - The id of the artist to get.
* @returns {@link Artist} - An artist object.
*/
getArtist(artistId: number): Promise<Artist>;
/**
* Get overall charts for tracks, albums, artists and playlists for the given genre ID.
*
* Combine charts of several resources in one endpoint.
*
* @param {number} genreId - The genre id, default to `All` genre (genreId = 0).
* @returns {@link Chart} - A chart instance.
*/
getChart(genreId?: number): Promise<Chart>;
/**
* Get top tracks for the given genre id.
*
* @param {number} genreId - The genre id, default to `All` genre (genreId = 0).
* @returns A list of {@link Track} instances.
*/
getTracksChart(genreId?: number): Promise<Track[]>;
/**
* Get top albums for the given genre id.
*
* @param {number} genreId - The genre id, default to `All` genre (genreId = 0).
* @returns A list of {@link Album} instances.
*/
getAlbumsChart(genreId?: number): Promise<Album[]>;
/**
* Get top artists for the given genre id.
*
* @param {number} genreId - The genre id, default to `All` genre (genreId = 0).
* @returns A list of {@link Artist} instances.
*/
getArtistsChart(genreId?: number): Promise<Artist[]>;
/**
* Get top playlists for the given genre id.
*
* @param {number} genreId - The genre id, default to `All` genre (genreId = 0).
* @returns A list of {@link Playlist} instances.
*/
getPlaylistsChart(genreId?: number): Promise<Playlist[]>;
/**
* Get top podcasts for the given genre id.
*
* @param {number} genreId - The genre id, default to `All` genre (genreId = 0).
* @returns A list of {@link Podcast} instances.
*/
getPodcastsChart(genreId?: number): Promise<Podcast[]>;
/**
* Get the editorial with the given id.
*
* @param {number} editorialId - The id of the editorial to get.
* @returns a {@link Editorial} object.
*/
getEditorial(editorialId: number): Promise<Editorial>;
/**
* List editorials.
*
* @returns {@link PaginatedList} of {@link Editorial} - An editorial object.
*/
listEditorials(): Promise<PaginatedList<Editorial>>;
/**
* Get the episode with the given id.
*
* @param {number} episodeId - The id of the episode to get.
* @returns {@link Episode} - An episode object.
*/
getEpisode(episodeId: number): Promise<Episode>;
/**
* Get the genre with the given id.
*
* @param {number} genreId - The id of the genre to get.
* @returns {@link Genre} - A genre object.
*/
getGenre(genreId: number): Promise<Genre>;
/**
* Get the playlist with the given id.
*
* @param {number} playlistId - The id of the playlist to get.
* @returns {@link Playlist} - A playlist object.
*/
getPlaylist(playlistId: number): Promise<Playlist>;
/**
* Get the podcast with the given id.
*
* @param {number} podcastId - The id of the podcast to get.
* @returns {@link Podcast} - A podcast object.
*/
getPodcast(podcastId: number): Promise<Podcast>;
/**
* Get the radio with the given id.
*
* @param {number} radioId - The id of the radio to get.
* @returns {@link Radio} - A radio object.
*/
getRadio(radioId: number): Promise<Radio>;
/**
* List radios.
*
* @returns A list of {@link Radio} instances.
*/
listRadios(): Promise<Radio[]>;
/**
* Get the top radios.
*
* @returns {@link PaginatedList} of {@link Radio} objects.
*/
getRadioTop(): Promise<PaginatedList<Radio>>;
/**
* Get the track with the given id.
*
* @param {number} trackId - The id of the track to get.
* @returns {@link Track} - A track object.
*/
getTrack(trackId: number): Promise<Track>;
/**
* Get the user with the given id.
*
* @param {number} userId - The id of the user to get.
* @returns {@link User} - A user object.
*/
getUser(userId: number): Promise<User>;
/**
* Get the flow of the user with the given id.
*
* @param {number} userId - The id of the user to get.
* @param {Record<string, string>} [params] - Additional parameters to pass.
* @returns {@link PaginatedList} of {@link Track} - A list of tracks.
*/
getUserFlow(userId: number, params?: Record<string, string>): Promise<PaginatedList<Track>>;
/**
* Get the favourites albums for the given userId.
*
* @param {number} userId - The user id to get the favourite albums.
* @returns {@link PaginatedList} of {@link Album} - A list of albums.
*/
getUserAlbums(userId: number): Promise<PaginatedList<Album>>;
/**
* Get the favourite artists for the given userId.
*
* @param {number} userId - The user id to get the favourite artists.
* @returns {@link PaginatedList} of {@link Artist} - A list of artists.
*/
getUserArtists(userId: number): Promise<PaginatedList<Artist>>;
/**
* Get the followers for the given userId.
*
* @param {number} userId - The user id to get followers.
* @returns {@link PaginatedList} of {@link User} - A list of followers.
*/
getUserFollowers(userId: number): Promise<PaginatedList<User>>;
/**
* Get the followings for the given userId.
*
* @param {number} userId - The user id to get followings.
* @returns {@link PaginatedList} of {@link User} - A list of followings.
*/
getUserFollowings(userId: number): Promise<PaginatedList<User>>;
/**
* Get the favourites tracks for the given userId.
*
* @param {number} userId - The user id to get the favourite tracks.
* @returns {@link PaginatedList} of {@link Track} - A list of tracks.
*/
getUserTracks(userId: number): Promise<PaginatedList<Track>>;
/**
* Get the playlists for the given userId.
*
* @param {number} userId - The user id to get the playlists.
* @returns {@link PaginatedList} of {@link Playlist} - A list of playlists.
*/
getUserPlaylists(userId: number): Promise<PaginatedList<Playlist>>;
/**
* Get the podcasts for the given userId.
*
* @param {number} userId - The user id to get the podcasts.
* @returns {@link PaginatedList} of {@link Podcast} - A list of podcasts.
*/
getUserPodcasts(userId: number): Promise<PaginatedList<Podcast>>;
/**
* Get the radios for the given userId.
*
* @param {number} userId - The user id to get the radios.
* @returns {@link PaginatedList} of {@link Radio} - A list of radios.
*/
getUserRadios(userId: number): Promise<PaginatedList<Radio>>;
/**
* Get the charts for the given userId.
*
* @param {number} userId - The user id to get the charts.
* @returns {@link PaginatedList} of {@link Chart} - A list of charts.
*/
getUserCharts(userId: number): Promise<PaginatedList<Chart>>;
/**
* @internal
*/
private _search;
/**
* Search tracks.
*
* Advanced search is available by either formatting the query yourself or
* by using the dedicated keywords arguments.
*
* @param {string} query - the query to search for, this is directly passed as q query.
* @param {boolean} strict - whether to disable fuzzy search and enable strict mode.
* @param {string} ordering - see Deezer API docs for possible values..
* @param {Object} advancedParams - Additional parameters to pass.
* @param {string} advancedParams.artist - The artist to search for
* @param {string} advancedParams.album - The album to search for
* @param {string} advancedParams.track - The track to search for
* @param {string} advancedParams.label - The label to search for
* @param {number} advancedParams.dur_min - The minimum duration of the track
* @param {number} advancedParams.dur_max - The maximum duration of the track
* @param {number} advancedParams.bpm_min - The minimum BPM of the track
* @param {number} advancedParams.bpm_max - The maximum BPM of the track
*
* @returns {@link PaginatedList} of {@link Track} - A list of tracks.
*/
search(query?: string, strict?: boolean, ordering?: string, advancedParams?: {
artist?: string;
album?: string;
track?: string;
label?: string;
dur_min?: number;
dur_max?: number;
bpm_min?: number;
bpm_max?: number;
}): Promise<PaginatedList<Track>>;
/**
* Search albums matching the given query.
*
* @param query - the query to search for, this is directly passed as q query.
* @param strict - whether to disable fuzzy search and enable strict mode.
* @param ordering - see Deezer API docs for possible values.
*/
searchAlbums(query?: string, strict?: boolean, ordering?: string): Promise<PaginatedList<Album>>;
/**
* Search artists matching the given query.
*
* @param query - the query to search for, this is directly passed as q query.
* @param strict - whether to disable fuzzy search and enable strict mode.
* @param ordering - see Deezer API docs for possible values.
*/
searchArtists(query?: string, strict?: boolean, ordering?: string): Promise<PaginatedList<Artist>>;
/**
* Search playlists matching the given query.
*
* @param query - the query to search for, this is directly passed as q query.
* @param strict - whether to disable fuzzy search and enable strict mode.
* @param ordering - see Deezer API docs for possible values.
*/
searchPlaylists(query?: string, strict?: boolean, ordering?: string): Promise<PaginatedList<Playlist>>;
}
/**
* Base class for all Deezer API exceptions.
* This is the parent class of all exceptions thrown by the library.
*
* @category Errors
*/
declare class DeezerAPIException extends Error {
constructor(message: string);
}
/**
* Represents errors that are temporary and can be retried.
* These errors occur when a request fails but might succeed if retried.
* Common scenarios include network issues or temporary service unavailability.
*
* @category Errors
* @extends DeezerAPIException
*/
declare class DeezerRetryableException extends DeezerAPIException {
constructor(message: string);
}
/**
* Thrown when the API rate limit is exceeded.
* Deezer imposes a limit of 50 requests per 5 seconds.
* When this error occurs, you should wait before making new requests.
*
* @category Errors
* @extends DeezerRetryableException
*
* @example
* ```typescript
* try {
* await client.getArtist(27);
* } catch (error) {
* if (error instanceof DeezerQuotaExceededError) {
* // Wait for 5 seconds before retrying
* await new Promise(resolve => setTimeout(resolve, 5000));
* await client.getArtist(27);
* }
* }
* ```
*/
declare class DeezerQuotaExceededError extends DeezerRetryableException {
constructor();
}
/**
* Base class for HTTP-related errors.
* Wraps HTTP errors returned by the Deezer API.
*
* @category Errors
* @extends DeezerAPIException
*/
declare class DeezerHTTPError extends DeezerAPIException {
constructor(response: Response);
/**
* Creates the appropriate HTTP error based on the response status code.
*
* @param response - The HTTP response object
* @returns A specific HTTP error instance
* @internal
*/
static fromResponse(response: Response): DeezerHTTPError;
}
/**
* Represents temporary HTTP errors that can be retried.
* This includes server errors (5xx) that might be temporary.
*
* @category Errors
* @extends DeezerRetryableException
*/
declare class DeezerRetryableHTTPError extends DeezerRetryableException {
constructor(response: Response);
}
/**
* Thrown when access to a resource is forbidden.
* This typically occurs when trying to access private resources
* without proper authentication.
*
* @category Errors
* @extends DeezerHTTPError
*/
declare class DeezerForbiddenError extends DeezerHTTPError {
constructor(response: Response);
}
/**
* Thrown when a requested resource is not found (404).
* This occurs when trying to access a resource that doesn't exist,
* such as an invalid track ID or deleted content.
*
* @category Errors
* @extends DeezerHTTPError
*/
declare class DeezerNotFoundError extends DeezerHTTPError {
constructor(response: Response);
}
/**
* Represents errors returned by the Deezer API in its response body.
* These are functional errors where the request was valid but the
* API couldn't process it for business logic reasons.
*
* @category Errors
* @extends DeezerAPIException
*/
declare class DeezerErrorResponse extends DeezerAPIException {
constructor(error: any);
}
/**
* Thrown when trying to access an unknown or invalid resource type.
* This error occurs when the requested resource type is not supported
* by the Deezer API or this library.
*
* @category Errors
* @extends DeezerAPIException
*/
declare class DeezerUnknownResource extends DeezerAPIException {
constructor(message: string);
}
export { Album, Artist, Chart, Client, DeezerAPIException, DeezerErrorResponse, DeezerForbiddenError, DeezerHTTPError, DeezerNotFoundError, DeezerQuotaExceededError, DeezerRetryableException, DeezerRetryableHTTPError, DeezerUnknownResource, Editorial, Episode, Genre, PaginatedList, Playlist, Podcast, Radio, Resource, Track, User };