Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ekwoka/spotify-api

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ekwoka/spotify-api - npm Package Compare versions

Comparing version 0.11.2 to 0.11.3

2

dist/auth/fetchOptions.d.ts

@@ -1,2 +0,2 @@

export declare const fetchOptions: (data: Record<string, string>) => {
export declare const fetchOptions: (data: Record<string, string>, client: string, secret: string) => {
method: string;

@@ -3,0 +3,0 @@ headers: {

import { toBase64 } from '../utils';
export const fetchOptions = (data) => ({
export const fetchOptions = (data, client, secret) => ({
method: 'POST',
headers: {
Authorization: `Basic ${toBase64(`${process.env.SPOTIFY_CLIENT}:${process.env.SPOTIFY_SECRET}`)}`,
Authorization: `Basic ${toBase64(`${client}:${secret}`)}`,
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',

@@ -7,0 +7,0 @@ },

@@ -1,3 +0,3 @@

export declare const makeAuthURL: (scopes: scope[]) => string;
export declare const makeAuthURL: (scopes: scope[], clientId?: string, redirectUri?: string) => string;
export declare type scope = 'ugc-image-upload' | 'user-modify-playback-state' | 'user-read-playback-state' | 'user-read-currently-playing' | 'user-library-modify' | 'user-follow-read' | 'user-read-recently-played' | 'user-read-playback-position' | 'user-top-read' | 'playlist-read-collaborative' | 'playlist-modify-public' | 'playlist-read-private' | 'playlist-modify-private' | 'app-remote-control' | 'streaming' | 'user-read-email' | 'user-read-private' | 'user-library-modify' | 'user-library-read';
//# sourceMappingURL=makeAuthURL.d.ts.map
import { toURLString } from '../utils';
export const makeAuthURL = (scopes) => `https://accounts.spotify.com/authorize?${toURLString({
export const makeAuthURL = (scopes, clientId, redirectUri) => `https://accounts.spotify.com/authorize?${toURLString({
response_type: 'code',
client_id: process.env.SPOTIFY_CLIENT,
client_id: clientId ?? process.env.SPOTIFY_CLIENT,
scope: scopes.join(' '),
redirect_uri: process.env.REDIRECT,
redirect_uri: redirectUri ?? process.env.REDIRECT,
})}`;

@@ -8,3 +8,3 @@ /**

*/
export declare const refreshToken: (refreshToken: string) => Promise<RefreshedToken>;
export declare const refreshToken: (refreshToken: string, client?: string, secret?: string) => Promise<RefreshedToken>;
export declare type RefreshedToken = {

@@ -11,0 +11,0 @@ access_token: string;

@@ -10,7 +10,7 @@ import { SPOTIFY_AUTH } from '../constants';

*/
export const refreshToken = async (refreshToken) => {
export const refreshToken = async (refreshToken, client = process.env.SPOTIFY_CLIENT, secret = process.env.SPOTIFY_SECRET) => {
const response = await fetch(SPOTIFY_AUTH, fetchOptions({
refresh_token: refreshToken,
grant_type: 'refresh_token',
}));
}, client, secret));
if (!response.ok)

@@ -17,0 +17,0 @@ throw new Error('Error refreshing token');

@@ -8,3 +8,3 @@ /**

*/
export declare const tokensFromCode: (code: string) => Promise<SpotifyTokens>;
export declare const tokensFromCode: (code: string, client?: string, secret?: string) => Promise<SpotifyTokens>;
export declare type SpotifyTokens = {

@@ -11,0 +11,0 @@ access_token: string;

@@ -10,3 +10,3 @@ import { SPOTIFY_AUTH } from '../constants';

*/
export const tokensFromCode = async (code) => {
export const tokensFromCode = async (code, client = process.env.SPOTIFY_CLIENT, secret = process.env.SPOTIFY_SECRET) => {
const response = await fetch(SPOTIFY_AUTH, fetchOptions({

@@ -16,3 +16,3 @@ code,

grant_type: 'authorization_code',
}));
}, client, secret));
if (!response.ok)

@@ -19,0 +19,0 @@ throw new Error('Error fetching token');

@@ -16,3 +16,3 @@ {

"license": "MIT",
"version": "0.11.2",
"version": "0.11.3",
"description": "Composable Wrapper for the Spotify Web Api and Spotify Web Playback SDK",

@@ -30,7 +30,7 @@ "repository": "github:ekwoka/spotify-api",

"devDependencies": {
"@types/node": "^18.8.4",
"@types/node": "^18.11.0",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"@vitest/coverage-c8": "^0.24.1",
"esbuild": "^0.15.10",
"@vitest/coverage-c8": "^0.24.3",
"esbuild": "^0.15.11",
"eslint": "^8.25.0",

@@ -45,4 +45,4 @@ "gzip-size": "^7.0.0",

"undici": "^5.11.0",
"vite": "^3.1.7",
"vitest": "^0.24.1"
"vite": "^3.1.8",
"vitest": "^0.24.3"
},

@@ -49,0 +49,0 @@ "prettier": {

@@ -67,3 +67,3 @@ # ⚡️A tree-shakable, composable, lightweight wrapper for the multiple Spotify APIs🔥

These currently depend on you setting up and exposing certain environment variables for the functions to access on the `process.env` object:
While these functions do allow passing in the valid parameters, you can also depend on evironment variables by setting up and exposing the following on the `process.env` object:

@@ -86,3 +86,3 @@ - `SPOTIFY_CLIENT`: Client id from Spotify Developer Dashboard.

const loginHandler = async (req, res) => {
const url = makeAuthURL(['user-read-email']);
const url = makeAuthURL(['user-read-email'], CLIENT, REDIRECT);
res.redirect(302, url);

@@ -94,3 +94,7 @@ };

const { code } = JSON.parse(req.body);
const { access_token, refresh_token } = await getTokenFromCode(code);
const { access_token, refresh_token } = await getTokenFromCode(
code,
CLIENT,
SECRET
);
res.cookie('refresh_token', refresh_token);

@@ -106,3 +110,3 @@ res.status(200).json({ access_token });

const { refresh_token } = req.cookies;
const { access_token } = await refreshToken(refresh_token);
const { access_token } = await refreshToken(refresh_token, CLIENT, SECRET);
res.status(200).json({ access_token });

@@ -109,0 +113,0 @@ } catch (err) {

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc