Spotify API Service

A unified interface to all Spotify API functionality. This module serves as the main entry point for interacting with the Spotify Web API throughout the application.

Features:

  • API constants and configuration management
  • Credentials management (client ID and secret)
  • Access and refresh token management
  • OAuth 2.0 authentication flows
  • User profile information retrieval
  • Playback control and monitoring
  • Library management (saved tracks, etc.)

Usage:

import { getCurrentPlayback, likeTrack, getAuthorizationUrl } from '@/services/spotify';

// Use any exported function to interact with Spotify API
const playbackState = await getCurrentPlayback();
export * from "./constants";

// Export credentials management
export {
ensureCredentialsSet,
getCredentials,
hasCredentials,
setCredentials,
} from "./credentials";

// Export token management
export {
clearTokens,
ensureValidToken,
getAccessToken,
getRefreshToken,
getTokenInfo,
isTokenValid,
refreshAccessToken,
setTokens,
} from "./token";

// Export authentication
export { exchangeCodeForTokens, getAuthorizationUrl } from "./auth";

// Export user profile
export { getCurrentUser } from "./user";

// Export playback controls
export {
getCurrentPlayback,
getRecentlyPlayedTracks,
getTrack,
pause,
play,
skipToNext,
skipToPrevious,
} from "./playback";

// Export library management
export { isTrackInLibrary, likeTrack, unlikeTrack } from "./library";

References

AUTH_URL → AUTH_URL
TOKEN_URL → TOKEN_URL
API_BASE_URL → API_BASE_URL
DEFAULT_RETRY_COUNT → DEFAULT_RETRY_COUNT
DEFAULT_RETRY_DELAY → DEFAULT_RETRY_DELAY
SPOTIFY_SCOPES → SPOTIFY_SCOPES
ensureCredentialsSet → ensureCredentialsSet
getCredentials → getCredentials
hasCredentials → hasCredentials
setCredentials → setCredentials
clearTokens → clearTokens
ensureValidToken → ensureValidToken
getAccessToken → getAccessToken
getRefreshToken → getRefreshToken
getTokenInfo → getTokenInfo
isTokenValid → isTokenValid
refreshAccessToken → refreshAccessToken
setTokens → setTokens
exchangeCodeForTokens → exchangeCodeForTokens
getAuthorizationUrl → getAuthorizationUrl
getCurrentUser → getCurrentUser
getCurrentPlayback → getCurrentPlayback
getRecentlyPlayedTracks → getRecentlyPlayedTracks
getTrack → getTrack
pause → pause
play → play
skipToNext → skipToNext
skipToPrevious → skipToPrevious
isTrackInLibrary → isTrackInLibrary
likeTrack → likeTrack
unlikeTrack → unlikeTrack