tspotify
Advanced tools
Comparing version 0.0.6 to 0.0.7
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import type { DefaultClientOptionsInterface } from '../util/Constants.js'; | ||
import type { ClientOptions } from '../interfaces/Interfaces.js'; | ||
/** | ||
* Base class for client | ||
*/ | ||
export default class BaseClient extends EventEmitter { | ||
options: DefaultClientOptionsInterface; | ||
/** | ||
* Options to pass when initiating the client | ||
*/ | ||
options: ClientOptions; | ||
constructor(options?: {}); | ||
} |
import { EventEmitter } from 'events'; | ||
import { mergeDefault } from '../util/Util.js'; | ||
import { DefaultClientOptions } from '../util/Constants.js'; | ||
/** | ||
* Base class for client | ||
*/ | ||
export default class BaseClient extends EventEmitter { | ||
@@ -5,0 +8,0 @@ constructor(options = {}) { |
import BaseClient from './BaseClient.js'; | ||
import type { httpInterface } from '../util/Constants.js'; | ||
interface ClientOptions { | ||
http: httpInterface | null; | ||
} | ||
interface ClientCredentials { | ||
clientID: string; | ||
clientSecret: string; | ||
} | ||
import RESTManager from '../rest/RESTManager.js'; | ||
import { AccessTokenDetails } from '../structures/Misc.js'; | ||
import AlbumManager from '../managers/AlbumManager.js'; | ||
import ArtistManager from '../managers/ArtistManager.js'; | ||
import TrackManager from '../managers/TrackManager.js'; | ||
import EpisodeManager from '../managers/EpisodeManager.js'; | ||
import ShowManager from '../managers/ShowManager.js'; | ||
import UserManager from '../managers/UserManager.js'; | ||
import PlaylistManager from '../managers/PlaylistManager.js'; | ||
import CategoryManager from '../managers/CategoryManager.js'; | ||
import type { ClientCredentials, ClientOptions } from '../interfaces/Interfaces.js'; | ||
/** | ||
* The core of the library | ||
*/ | ||
export default class Client extends BaseClient { | ||
/** | ||
* The credentials for the client to login with | ||
*/ | ||
credentials: ClientCredentials | null; | ||
/** | ||
* The details about the access token returned by the API after authorization | ||
*/ | ||
accessTokenDetails: AccessTokenDetails | null; | ||
/** | ||
* The rest manager class that holds the methods for API calls | ||
*/ | ||
rest: RESTManager; | ||
/** | ||
* The album nanager class that holds the cache of albums and their methods | ||
*/ | ||
albums: AlbumManager; | ||
/** | ||
* Time at which the client became `READY` | ||
*/ | ||
readyAt: Date | null; | ||
/** | ||
* The manager class that holds cache and API methods of artists | ||
*/ | ||
artists: ArtistManager; | ||
/** | ||
* The manager class that holds cache and API methods of tracks | ||
*/ | ||
tracks: TrackManager; | ||
/** | ||
* The manager class that holds cache and API methods of episodes | ||
*/ | ||
episodes: EpisodeManager; | ||
/** | ||
* The manager class that holds cache and API methods of shows | ||
*/ | ||
shows: ShowManager; | ||
/** | ||
* The manager class that holds cache and API methods of users | ||
*/ | ||
users: UserManager; | ||
/** | ||
* The manager class that holds cache and API methods of playlists | ||
*/ | ||
playlists: PlaylistManager; | ||
/** | ||
* The manager class that holds cache and API methods of categories | ||
*/ | ||
categories: CategoryManager; | ||
constructor(options?: ClientOptions); | ||
get _api(): any; | ||
/** | ||
* Logs the client in and emits the `ready` event on success | ||
*/ | ||
login(credentials: ClientCredentials): Promise<AccessTokenDetails>; | ||
/** | ||
* Fetch the list of markets where Spotify is available | ||
*/ | ||
fetchAvailableMarkets(): Promise<Array<string>>; | ||
/** | ||
* Fetches a list of available genres | ||
* @returns An array containing genres as a Promise | ||
*/ | ||
fetchRecommendationGenres(): Promise<Array<string>>; | ||
} | ||
declare class AccessTokenDetails { | ||
accessToken: string; | ||
tokenType: string; | ||
expiresIn: number; | ||
constructor(data: any); | ||
} | ||
export {}; |
@@ -11,38 +11,78 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import BaseClient from './BaseClient.js'; | ||
import fetch from 'node-fetch'; | ||
import RESTManager from '../rest/RESTManager.js'; | ||
import { RequestData, AccessTokenDetails } from '../structures/Misc.js'; | ||
import AlbumManager from '../managers/AlbumManager.js'; | ||
import ArtistManager from '../managers/ArtistManager.js'; | ||
import TrackManager from '../managers/TrackManager.js'; | ||
import EpisodeManager from '../managers/EpisodeManager.js'; | ||
import ShowManager from '../managers/ShowManager.js'; | ||
import UserManager from '../managers/UserManager.js'; | ||
import PlaylistManager from '../managers/PlaylistManager.js'; | ||
import { Events } from '../util/Constants.js'; | ||
import CategoryManager from '../managers/CategoryManager.js'; | ||
/** | ||
* The core of the library | ||
*/ | ||
export default class Client extends BaseClient { | ||
constructor(options) { | ||
super(options); | ||
Object.defineProperty(this, 'credentials', { writable: true }); | ||
this.credentials = null; | ||
Object.defineProperty(this, 'accessTokenDetails', { writable: true }); | ||
this.accessTokenDetails = null; | ||
this.rest = new RESTManager(this); | ||
this.albums = new AlbumManager(this); | ||
this.readyAt = null; | ||
this.artists = new ArtistManager(this); | ||
this.tracks = new TrackManager(this); | ||
this.episodes = new EpisodeManager(this); | ||
this.shows = new ShowManager(this); | ||
this.users = new UserManager(this); | ||
this.playlists = new PlaylistManager(this); | ||
this.categories = new CategoryManager(this); | ||
} | ||
get _api() { | ||
return this.rest.routeBuilder; | ||
} | ||
/** | ||
* Logs the client in and emits the `ready` event on success | ||
*/ | ||
login(credentials) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.credentials = credentials; | ||
const { clientID, clientSecret } = this.credentials; | ||
const authString = Buffer.from(`${clientID}:${clientSecret}`).toString('base64'); | ||
const bodyContent = new URLSearchParams(); | ||
bodyContent.append('grant_type', 'client_credentials'); | ||
const res = yield fetch('https://accounts.spotify.com/api/token', { | ||
headers: { | ||
Authorization: `Basic ${authString}`, | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
body: bodyContent, | ||
method: 'post', | ||
const requestData = new RequestData('account', null, { | ||
grant_type: 'client_credentials', | ||
}); | ||
const data = yield res.json(); | ||
const data = yield this._api.api.token.post(requestData); | ||
this.accessTokenDetails = new AccessTokenDetails(data); | ||
if (!this.accessTokenDetails) | ||
throw new Error('Invalid client credentials'); | ||
this.readyAt = new Date(); | ||
this.emit(Events.READY); | ||
return this.accessTokenDetails; | ||
}); | ||
} | ||
} | ||
class AccessTokenDetails { | ||
/* eslint-disable */ | ||
constructor(data) { | ||
var _a, _b, _c; | ||
this.accessToken = (_a = data === null || data === void 0 ? void 0 : data.access_token) !== null && _a !== void 0 ? _a : null; | ||
this.tokenType = (_b = data === null || data === void 0 ? void 0 : data.token_type) !== null && _b !== void 0 ? _b : null; | ||
this.expiresIn = (_c = data === null || data === void 0 ? void 0 : data.expires_in) !== null && _c !== void 0 ? _c : null; | ||
/** | ||
* Fetch the list of markets where Spotify is available | ||
*/ | ||
fetchAvailableMarkets() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const requestData = new RequestData('api', null, null); | ||
const data = yield this._api.markets.get(requestData); | ||
return data.markets; | ||
}); | ||
} | ||
/** | ||
* Fetches a list of available genres | ||
* @returns An array containing genres as a Promise | ||
*/ | ||
fetchRecommendationGenres() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const requestData = new RequestData('api', null, null); | ||
const data = yield this._api | ||
.recommendations('available-genre-seeds') | ||
.get(requestData); | ||
return data.genres; | ||
}); | ||
} | ||
} |
@@ -0,2 +1,38 @@ | ||
import BaseClient from './client/BaseClient.js'; | ||
import Client from './client/Client.js'; | ||
export { Client }; | ||
export * from './interfaces/Interfaces.js'; | ||
export * from './interfaces/Types.js'; | ||
export * from './interfaces/Util.js'; | ||
import AlbumManager from './managers/AlbumManager.js'; | ||
import ArtistManager from './managers/ArtistManager.js'; | ||
import BaseManager from './managers/BaseManager.js'; | ||
import CategoryManager from './managers/CategoryManager.js'; | ||
import EpisodeManager from './managers/EpisodeManager.js'; | ||
import PlaylistManager from './managers/PlaylistManager.js'; | ||
import ShowManager from './managers/ShowManager.js'; | ||
import TrackManager from './managers/TrackManager.js'; | ||
import Album from './structures/Album.js'; | ||
import Artist from './structures/Artist.js'; | ||
import AudioFeatures from './structures/AudioFeatures.js'; | ||
import BaseAlbum from './structures/BaseAlbum.js'; | ||
import BasePlaylist from './structures/BasePlaylist.js'; | ||
import BaseStructure from './structures/BaseStructure.js'; | ||
import Category from './structures/Category.js'; | ||
import Episode from './structures/Episode.js'; | ||
import LinkedTrack from './structures/LinkedTrack.js'; | ||
export * from './structures/Misc.js'; | ||
import Playlist from './structures/Playlist.js'; | ||
import PrivateUser from './structures/PrivateUser.js'; | ||
import PublicUser from './structures/PublicUser.js'; | ||
import Show from './structures/Show.js'; | ||
import SimplifiedAlbum from './structures/SimplifiedAlbum.js'; | ||
import SimplifiedArtist from './structures/SimplifiedArtist.js'; | ||
import SimplifiedEpisode from './structures/SimplifiedEpisode.js'; | ||
import SimplifiedPlaylist from './structures/SimplifiedPlaylist.js'; | ||
import SimplifiedShow from './structures/SimplifiedShow.js'; | ||
import SimplifiedTrack from './structures/SimplifiedTrack.js'; | ||
import Track from './structures/Track.js'; | ||
import Collection from './util/Collection.js'; | ||
export * from './util/Constants.js'; | ||
export * from './util/Util.js'; | ||
export { BaseClient, Client, AlbumManager, ArtistManager, BaseManager, CategoryManager, EpisodeManager, PlaylistManager, ShowManager, TrackManager, Album, Artist, AudioFeatures, BaseAlbum, BasePlaylist, BaseStructure, Category, Episode, LinkedTrack, Playlist, PrivateUser, PublicUser, Show, SimplifiedAlbum, SimplifiedArtist, SimplifiedEpisode, SimplifiedPlaylist, SimplifiedShow, SimplifiedTrack, Track, Collection, }; |
@@ -0,2 +1,38 @@ | ||
import BaseClient from './client/BaseClient.js'; | ||
import Client from './client/Client.js'; | ||
export { Client }; | ||
export * from './interfaces/Interfaces.js'; | ||
export * from './interfaces/Types.js'; | ||
export * from './interfaces/Util.js'; | ||
import AlbumManager from './managers/AlbumManager.js'; | ||
import ArtistManager from './managers/ArtistManager.js'; | ||
import BaseManager from './managers/BaseManager.js'; | ||
import CategoryManager from './managers/CategoryManager.js'; | ||
import EpisodeManager from './managers/EpisodeManager.js'; | ||
import PlaylistManager from './managers/PlaylistManager.js'; | ||
import ShowManager from './managers/ShowManager.js'; | ||
import TrackManager from './managers/TrackManager.js'; | ||
import Album from './structures/Album.js'; | ||
import Artist from './structures/Artist.js'; | ||
import AudioFeatures from './structures/AudioFeatures.js'; | ||
import BaseAlbum from './structures/BaseAlbum.js'; | ||
import BasePlaylist from './structures/BasePlaylist.js'; | ||
import BaseStructure from './structures/BaseStructure.js'; | ||
import Category from './structures/Category.js'; | ||
import Episode from './structures/Episode.js'; | ||
import LinkedTrack from './structures/LinkedTrack.js'; | ||
export * from './structures/Misc.js'; | ||
import Playlist from './structures/Playlist.js'; | ||
import PrivateUser from './structures/PrivateUser.js'; | ||
import PublicUser from './structures/PublicUser.js'; | ||
import Show from './structures/Show.js'; | ||
import SimplifiedAlbum from './structures/SimplifiedAlbum.js'; | ||
import SimplifiedArtist from './structures/SimplifiedArtist.js'; | ||
import SimplifiedEpisode from './structures/SimplifiedEpisode.js'; | ||
import SimplifiedPlaylist from './structures/SimplifiedPlaylist.js'; | ||
import SimplifiedShow from './structures/SimplifiedShow.js'; | ||
import SimplifiedTrack from './structures/SimplifiedTrack.js'; | ||
import Track from './structures/Track.js'; | ||
import Collection from './util/Collection.js'; | ||
export * from './util/Constants.js'; | ||
export * from './util/Util.js'; | ||
export { BaseClient, Client, AlbumManager, ArtistManager, BaseManager, CategoryManager, EpisodeManager, PlaylistManager, ShowManager, TrackManager, Album, Artist, AudioFeatures, BaseAlbum, BasePlaylist, BaseStructure, Category, Episode, LinkedTrack, Playlist, PrivateUser, PublicUser, Show, SimplifiedAlbum, SimplifiedArtist, SimplifiedEpisode, SimplifiedPlaylist, SimplifiedShow, SimplifiedTrack, Track, Collection, }; |
@@ -1,8 +0,11 @@ | ||
export interface DefaultClientOptionsInterface { | ||
http: httpInterface; | ||
} | ||
export interface httpInterface { | ||
version: number; | ||
api: string; | ||
} | ||
export declare const DefaultClientOptions: DefaultClientOptionsInterface; | ||
import type { ClientOptions } from '../interfaces/Interfaces'; | ||
/** | ||
* The default options with which the client gets initiated | ||
*/ | ||
export declare const DefaultClientOptions: ClientOptions; | ||
/** | ||
* Object that holds all the client events | ||
*/ | ||
export declare const Events: { | ||
READY: string; | ||
}; |
@@ -0,6 +1,16 @@ | ||
/** | ||
* The default options with which the client gets initiated | ||
*/ | ||
export const DefaultClientOptions = { | ||
http: { | ||
api: { | ||
version: 1, | ||
api: 'https://api.spotify.com', | ||
baseURL: 'https://api.spotify.com', | ||
baseAccountServiceURL: 'https://accounts.spotify.com', | ||
}, | ||
}; | ||
/** | ||
* Object that holds all the client events | ||
*/ | ||
export const Events = { | ||
READY: 'ready', | ||
}; |
@@ -1,2 +0,2 @@ | ||
import type { DefaultClientOptionsInterface } from './Constants'; | ||
export declare function mergeDefault(defaultObject: any, given: any): DefaultClientOptionsInterface; | ||
import type { ClientOptions } from '../interfaces/Interfaces.js'; | ||
export declare function mergeDefault(defaultObject: any, given: any): ClientOptions; |
{ | ||
"name": "tspotify", | ||
"version": "0.0.6", | ||
"description": "A TypeScript library for interacting with Spotify API", | ||
"version": "0.0.7", | ||
"description": "A nodejs library for interacting with Spotify API, written in TypeScript", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "npx tsc" | ||
"build": "npx tsc", | ||
"doc": "npx typedoc", | ||
"test": "node test/test.js" | ||
}, | ||
@@ -20,4 +22,6 @@ "repository": { | ||
"dependencies": { | ||
"@discordjs/collection": "^0.1.6", | ||
"@types/node-fetch": "^2.5.8", | ||
"node-fetch": "^2.6.1" | ||
"node-fetch": "^2.6.1", | ||
"spotify-api-types": "^0.4.1" | ||
}, | ||
@@ -32,2 +36,3 @@ "devDependencies": { | ||
"prettier": "^2.2.1", | ||
"typedoc": "^0.20.34", | ||
"typescript": "^4.2.3" | ||
@@ -34,0 +39,0 @@ }, |
@@ -0,3 +1,20 @@ | ||
<div align="center"> | ||
<br /> | ||
<p> | ||
<a href="#"><img src="https://i.imgur.com/doGPCO5.png" alt="tspotify" /></a> | ||
</p> | ||
<br /> | ||
<p> | ||
<a href="https://discord.com/invite/87gFS5ZeC3"><img src="https://img.shields.io/discord/828250237130244126?color=%237289da&label=discord&logo=discord&logoColor=white&style=flat-square" alt="TSpotify Discord server" /></a> | ||
<a href="https://www.npmjs.com/package/tspotify"><img src="https://img.shields.io/npm/v/tspotify?color=%23ec1d1d&style=flat-square" alt="NPM version" /></a> | ||
<a href="https://www.npmjs.com/package/tspotify"><img src="https://img.shields.io/npm/dt/tspotify?color=%231DA1F2&style=flat-square" alt="NPM downloads" /></a> | ||
<a href="https://david-dm.org/tspotify/tspotify"><img src="https://img.shields.io/david/tspotify/tspotify?style=flat-square" alt="Dependencies" /></a> | ||
</p> | ||
<p> | ||
<a href="https://nodei.co/npm/tspotify/"><img src="https://nodei.co/npm/tspotify.png?downloads=true&stars=true" alt="npm installinfo" /></a> | ||
</p> | ||
</div> | ||
# tspotify (WIP) | ||
A TypeScript library for interacting with Spotify API. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
198897
95
4423
20
4
9
2
+ Added@discordjs/collection@^0.1.6
+ Addedspotify-api-types@^0.4.1
+ Added@discordjs/collection@0.1.6(transitive)
+ Addedspotify-api-types@0.4.5(transitive)