@ekwoka/spotify-api
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -0,4 +1,6 @@ | ||
export { fetchOptions } from './fetchOptions'; | ||
export { refreshToken } from './refreshToken'; | ||
export { tokensFromCode } from './tokensFromCode'; | ||
export type { RefreshedToken } from './refreshToken'; | ||
export type { SpotifyTokens } from './tokensFromCode'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,2 +1,3 @@ | ||
export { fetchOptions } from './fetchOptions'; | ||
export { refreshToken } from './refreshToken'; | ||
export { tokensFromCode } from './tokensFromCode'; |
@@ -1,2 +0,3 @@ | ||
import { toBase64 } from '../utils'; | ||
import { SPOTIFY_AUTH } from '../constants'; | ||
import { fetchOptions } from './fetchOptions'; | ||
/** | ||
@@ -10,17 +11,9 @@ * refreshToken accepts a 'refresh_token' issued by Spotify and returns a new | ||
export const refreshToken = async (refreshToken) => { | ||
const response = await fetch('https://accounts.spotify.com/api/token', fetchOptions(refreshToken)); | ||
const response = await fetch(SPOTIFY_AUTH, fetchOptions({ | ||
refresh_token: refreshToken, | ||
grant_type: 'refresh_token', | ||
})); | ||
if (!response.ok) | ||
throw new Error('Error fetching token'); | ||
throw new Error('Error refreshing token'); | ||
return (await response.json()); | ||
}; | ||
const fetchOptions = (refreshToken) => ({ | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Basic ${toBase64(`${process.env.SPOTIFY_CLIENT}:${process.env.SPOTIFY_SECRET}`)}`, | ||
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', | ||
}, | ||
body: new URLSearchParams({ | ||
refresh_token: refreshToken, | ||
grant_type: 'refresh_token', | ||
}), | ||
}); |
@@ -1,2 +0,3 @@ | ||
import { toBase64 } from '../utils'; | ||
import { SPOTIFY_AUTH } from '../constants'; | ||
import { fetchOptions } from './fetchOptions'; | ||
/** | ||
@@ -10,3 +11,7 @@ * This accepts a 'code' provided by the Spotify Auth Portal, trades it with | ||
export const tokensFromCode = async (code) => { | ||
const response = await fetch('https://accounts.spotify.com/api/token', fetchOptions(code)); | ||
const response = await fetch(SPOTIFY_AUTH, fetchOptions({ | ||
code, | ||
redirect_uri: process.env.REDIRECT, | ||
grant_type: 'authorization_code', | ||
})); | ||
if (!response.ok) | ||
@@ -16,13 +21,1 @@ throw new Error('Error fetching token'); | ||
}; | ||
const fetchOptions = (code) => ({ | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Basic ${toBase64(`${process.env.SPOTIFY_CLIENT}:${process.env.SPOTIFY_SECRET}`)}`, | ||
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', | ||
}, | ||
body: new URLSearchParams({ | ||
code, | ||
redirect_uri: process.env.REDIRECT, | ||
grant_type: 'authorization_code', | ||
}), | ||
}); |
export declare const SPOTIFY_URL = "https://api.spotify.com/v1"; | ||
export declare const SPOTIFY_AUTH = "https://accounts.spotify.com/api/token"; | ||
//# sourceMappingURL=constants.d.ts.map |
export const SPOTIFY_URL = 'https://api.spotify.com/v1'; | ||
export const SPOTIFY_AUTH = 'https://accounts.spotify.com/api/token'; |
export function spotifyApiClient(token) { | ||
if (!token) | ||
throw 'Token is required at Spotify API Initialization'; | ||
throw new TypeError('Token is required at Spotify API Initialization'); | ||
const ApiClient = { | ||
@@ -5,0 +5,0 @@ token, |
export { refreshToken } from './auth/refreshToken'; | ||
export { tokensFromCode } from './auth/tokensFromCode'; | ||
export { SPOTIFY_URL } from './constants'; | ||
export { resetCache } from './core/resetCache'; | ||
export { setToken } from './core/setToken'; | ||
@@ -9,6 +10,8 @@ export { spotifyApiClient } from './core/spotifyApiClient'; | ||
export { isBrowser, isNode } from './utils/isBrowserOrNode'; | ||
export { sleep } from './utils/sleep'; | ||
export { spotifyFetch } from './utils/spotifyFetch'; | ||
export { toBase64 } from './utils/toBase64'; | ||
export type { RefreshedToken } from './auth/refreshToken'; | ||
export type { SpotifyTokens } from './auth/tokensFromCode'; | ||
export type { PersistentApiProperties, SpotifyApiClient, QueryFunction, QueryConstructor, } from './core/types'; | ||
//# sourceMappingURL=index.d.ts.map |
export { refreshToken } from './auth/refreshToken'; | ||
export { tokensFromCode } from './auth/tokensFromCode'; | ||
export { SPOTIFY_URL } from './constants'; | ||
export { resetCache } from './core/resetCache'; | ||
export { setToken } from './core/setToken'; | ||
@@ -9,3 +10,4 @@ export { spotifyApiClient } from './core/spotifyApiClient'; | ||
export { isBrowser, isNode } from './utils/isBrowserOrNode'; | ||
export { sleep } from './utils/sleep'; | ||
export { spotifyFetch } from './utils/spotifyFetch'; | ||
export { toBase64 } from './utils/toBase64'; |
/** | ||
* TODO: Add Tests | ||
*/ | ||
/** | ||
* Wrapper for fetching data from Spotify's API Endpoints with sensible and | ||
* consistent error handling for the common application failure points. | ||
* TODO: Decide on auto-resume implementation and invalid token. | ||
* When rate limited, the request is delayed and reattempted. | ||
* @param endpoint string | ||
@@ -13,3 +10,3 @@ * @param token string | ||
*/ | ||
export declare const spotifyFetch: <T>(endpoint: string, token: string, data?: {}) => Promise<T>; | ||
export declare const spotifyFetch: <T>(endpoint: string, token: string, data?: Record<string, unknown>) => Promise<T>; | ||
//# sourceMappingURL=spotifyFetch.d.ts.map |
import { SPOTIFY_URL } from '../constants'; | ||
/** | ||
* TODO: Add Tests | ||
*/ | ||
/** | ||
* Wrapper for fetching data from Spotify's API Endpoints with sensible and | ||
* consistent error handling for the common application failure points. | ||
* TODO: Decide on auto-resume implementation and invalid token. | ||
* When rate limited, the request is delayed and reattempted. | ||
* @param endpoint string | ||
@@ -10,0 +7,0 @@ * @param token string |
@@ -7,2 +7,3 @@ { | ||
], | ||
"sideEffects": false, | ||
"main": "dist/", | ||
@@ -12,3 +13,3 @@ "types": "dist/", | ||
"license": "MIT", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Composable Wrapper for the Spotify Web Api and Spotify Web Playback SDK", | ||
@@ -31,5 +32,7 @@ "keywords": [ | ||
"eslint": "^8.21.0", | ||
"gzip-size": "^7.0.0", | ||
"husky": "^8.0.1", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.7.1", | ||
"pretty-bytes": "^6.0.0", | ||
"typescript": "^4.7.4", | ||
@@ -45,8 +48,8 @@ "undici": "^5.8.1", | ||
"scripts": { | ||
"build": "node scripts/esbuild.js", | ||
"build:tsc": "tsc", | ||
"size": "node scripts/esbuild.js", | ||
"build": "tsc", | ||
"lint": "eslint --fix ./src; prettier --write ./src --loglevel error", | ||
"patch": "run-s test:run build:tsc && pnpm version patch && pnpm publish", | ||
"minor": "run-s test:run build:tsc && pnpm version minor && pnpm publish", | ||
"major": "run-s test:run build:tsc && pnpm version major && pnpm publish", | ||
"patch": "run-s test:run build && pnpm version patch && pnpm publish", | ||
"minor": "run-s test:run build && pnpm version minor && pnpm publish", | ||
"major": "run-s test:run build && pnpm version major && pnpm publish", | ||
"test": "vitest", | ||
@@ -53,0 +56,0 @@ "test:run": "vitest run", |
@@ -6,2 +6,3 @@ # ⚡️A tree-shakable, composable, lightweight wrapper for the multiple Spotify APIs🔥 | ||
<img src="https://badgen.net/npm/dt/@ekwoka/spotify-api" > | ||
<img src="https://badgen.net/bundlephobia/minzip/@ekwoka/spotify-api"> | ||
@@ -8,0 +9,0 @@ Born from my own difficulties using other wrapper libraries for Spotify, this library seeks to be the best possible API wrapper. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28250
62
396
136
4
15