UNPKG

@remcostoeten/fync

Version:

A unified TypeScript library for easy access to popular APIs (GitHub, Spotify, GitLab, etc.)

51 lines 1.83 kB
import { createChainableClient, } from "../../core/chainable"; import { createHttpClient } from "../utils/http"; function createSpotifyChainableClient(config) { const spotifyHttpClient = createHttpClient({ clientId: "", clientSecret: "", accessToken: config.token, baseUrl: config.baseUrl || "https://api.spotify.com/v1", cache: config.cache, cacheTTL: config.cacheTTL, }); async function getMethod(path, params) { return { data: await spotifyHttpClient.get(path) }; } async function postMethod(path, data) { return { data: await spotifyHttpClient.post(path, data) }; } async function putMethod(path, data) { return { data: await spotifyHttpClient.put(path, data) }; } async function patchMethod(path, data) { return { data: await spotifyHttpClient.put(path, data) }; } async function deleteMethod(path, data) { return { data: await spotifyHttpClient.delete(path, data) }; } const adaptedHttpClient = { get: getMethod, post: postMethod, put: putMethod, patch: patchMethod, delete: deleteMethod, }; return createChainableClient(config, adaptedHttpClient, { cacheKeyPrefix: "spotify", supportsPagination: false, defaultOptions: { params: { ...(config.limit && { limit: config.limit }), ...(config.after && { after: config.after }), ...(config.before && { before: config.before }), ...(config.immediate && { immediate: config.immediate }), }, }, }); } function createSpotifyClient(config = {}) { return createSpotifyChainableClient(config); } export { createSpotifyClient }; //# sourceMappingURL=spotify-client.js.map