Skip to content

Commit

Permalink
chore: imporove pkce example
Browse files Browse the repository at this point in the history
  • Loading branch information
MellKam committed Mar 5, 2024
1 parent 6574631 commit 428231d
Show file tree
Hide file tree
Showing 18 changed files with 4,988 additions and 123 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ authorization.
import { getCurrentUser, SpotifyClient } from "@soundify/web-api";

// if you don't have access token yet, you can pass null to first argument
const client = new SpotifyClient(null, {
const client = new SpotifyClient(null, {
// but you have to provide a function that will return a new access token
refresher: () => {
return Promise.resolve("YOUR_NEW_ACCESS_TOKEN");
}
return Promise.resolve("YOUR_NEW_ACCESS_TOKEN");
},
});

const me = await getCurrentUser(client);
// client will call your refresher to get the token
// client will call your refresher to get the token
// and only then make the request
console.log(me);

Expand Down
8 changes: 4 additions & 4 deletions client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ type SearchParams = Record<string, SearchParam>;
/**
* @see https://developer.spotify.com/documentation/web-api/concepts/api-calls#regular-error-object
*/
export type RegularErrorObject = {
export interface RegularErrorObject {
error: {
message: string;
status: number;
reason?: string;
};
};
}

const isRegularErrorObject = (
obj: unknown,
Expand Down Expand Up @@ -132,7 +132,7 @@ const isPlainObject = (obj: unknown): obj is Record<PropertyKey, unknown> => {
);
};

export type SpotifyClinetOptions = {
export interface SpotifyClinetOptions {
/**
* Use this option to provide a custom fetch function.
*/
Expand Down Expand Up @@ -168,7 +168,7 @@ export type SpotifyClinetOptions = {
* ```
*/
middlewares?: Middleware[];
};
}

const createFailedToAuthorizeError = () =>
new Error(
Expand Down
2 changes: 2 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"oak": "https://deno.land/x/[email protected]/mod.ts",
"std/": "https://deno.land/[email protected]/",
"@soundify/web-api": "./mod.ts",
"@soundify/web-api/pagination": "./pagination.ts",
"@soundify/web-api/auth": "./auth.ts",
"mock_fetch": "https://deno.land/x/[email protected]/mod.ts"
},
"fmt": { "useTabs": true }
Expand Down
4 changes: 2 additions & 2 deletions endpoints/album/album.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ export interface Album extends AlbumBase {
tracks: PagingObject<SimplifiedTrack>;
}

export type SavedAlbum = {
export interface SavedAlbum {
/**
* The date and time the album was saved.
* Timestamps are returned in ISO 8601 format as Coordinated Universal Time (UTC) with a zero offset: YYYY-MM-DDTHH:MM:SSZ.
*/
added_at: string;
album: Album;
};
}
4 changes: 2 additions & 2 deletions endpoints/audiobook/audiobook.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface Audiobook extends SimplifiedAudiobook {
chapters: PagingObject<SimplifiedChapter>;
}

export type SavedAudiobook = {
export interface SavedAudiobook {
/**
* The date and time the audiobook was saved Timestamps are returned in ISO 8601 format as Coordinated Universal Time (UTC) with a zero offset: YYYY-MM-DDTHH:MM:SSZ.
*/
Expand All @@ -100,4 +100,4 @@ export type SavedAudiobook = {
* Information about the audiobook.
*/
audiobook: SimplifiedAudiobook;
};
}
4 changes: 2 additions & 2 deletions endpoints/category/category.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NonNullableObject } from "../../shared.ts";
import type { Image } from "../general.types.ts";

export type Category = {
export interface Category {
/**
* A link to the Web API endpoint returning full details of the category.
*/
Expand All @@ -18,4 +18,4 @@ export type Category = {
* The name of the category.
*/
name: string;
};
}
4 changes: 2 additions & 2 deletions endpoints/episode/episode.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface Episode extends SimplifiedEpisode {
show: SimplifiedShow;
}

export type SavedEpisode = {
export interface SavedEpisode {
/**
* The date and time the episode was saved Timestamps are returned in ISO 8601 format as Coordinated Universal Time (UTC) with a zero offset: YYYY-MM-DDTHH:MM:SSZ.
*/
Expand All @@ -105,4 +105,4 @@ export type SavedEpisode = {
* Information about the episode.
*/
episode: Episode;
};
}
20 changes: 10 additions & 10 deletions endpoints/general.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type PagingObject<TItem> = {
export interface PagingObject<TItem> {
/**
* A link to the Web API endpoint returning the full result of the request.
*/
Expand All @@ -24,9 +24,9 @@ export type PagingObject<TItem> = {
*/
total: number;
items: TItem[];
};
}

export type CursorPagingObject<TItem> = {
export interface CursorPagingObject<TItem> {
/**
* A link to the Web API endpoint returning the full result of the request.
*/
Expand Down Expand Up @@ -57,9 +57,9 @@ export type CursorPagingObject<TItem> = {
*/
total: number;
items: TItem[];
};
}

export type PagingOptions = {
export interface PagingOptions {
/**
* The maximum number of items to return. Minimum: 1. Maximum: 50.
* @default 20
Expand All @@ -70,7 +70,7 @@ export type PagingOptions = {
* @default 0 (the first item)
*/
offset?: number;
};
}

/**
* The reason for the restriction.
Expand All @@ -95,7 +95,7 @@ export type Restrictions = {
*/
export type ReleaseDatePrecision = "year" | "month" | "day";

export type Image = {
export interface Image {
/**
* The image height in pixels.
*/
Expand All @@ -108,7 +108,7 @@ export type Image = {
* The image width in pixels.
*/
width: number | null;
};
}

export type ResumePoint = {
/**
Expand Down Expand Up @@ -150,7 +150,7 @@ export type ExternalUrls = {
spotify: string;
};

export type ExternalIds = {
export interface ExternalIds {
/**
* [International Standard Recording Code](https://en.wikipedia.org/wiki/International_Standard_Recording_Code).
*/
Expand All @@ -163,7 +163,7 @@ export type ExternalIds = {
* [Universal Product Code](http://en.wikipedia.org/wiki/Universal_Product_Code).
*/
upc?: string;
};
}

/**
* The copyright object contains the type and the name of copyright.
Expand Down
31 changes: 15 additions & 16 deletions endpoints/player/player.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ExternalUrls } from "../general.types.ts";
import type { Track } from "../track/track.types.ts";
import type { Episode } from "../episode/episode.types.ts";

export type Device = {
export interface Device {
/**
* The device ID. This ID is unique and persistent to some extent. However, this is not guaranteed and any cached device_id should periodically be cleared out and refetched as necessary.
*/
Expand All @@ -17,6 +17,7 @@ export type Device = {
is_restricted: boolean;
/**
* A human-readable name for the device. Some devices have a name that the user can configure (e.g. "Loudest speaker") and some devices have a generic name associated with the manufacturer or device model.
* @example Kitchen speaker
*/
name: string;
/**
Expand All @@ -31,9 +32,9 @@ export type Device = {
* If this device can be used to set the volume.
*/
supports_volume: boolean;
};
}

export type Actions = {
export interface Disallows {
/** Interrupting playback. */
interrupting_playback?: boolean;
/** Pausing. */
Expand All @@ -54,20 +55,18 @@ export type Actions = {
toggling_repeat_track?: boolean;
/** Transfering playback between devices. */
transferring_playback?: boolean;
};
}

export type Context = {
/**
* The object type, e.g. "artist", "playlist", "album", "show".
*/
export interface Context {
/** The object type, e.g. "artist", "playlist", "album", "show". */
type: string;
/** A link to the Web API endpoint providing full details of the track. */
href: string;
/** External URLs for this context. */
external_urls: ExternalUrls;
/** The Spotify URI for the context. */
uri: string;
};
}

/**
* "track" - repeat the current track. \
Expand All @@ -76,7 +75,7 @@ export type Context = {
*/
export type RepeatMode = "off" | "track" | "context";

export type PlaybackState = {
export interface PlaybackState {
/** The device that is currently active. */
device: Device;
repeat_state: RepeatMode;
Expand All @@ -96,22 +95,22 @@ export type PlaybackState = {
* Allows to update the user interface based on which playback actions are available within the current context.
*/
actions: {
disallows: Actions;
disallows: Disallows;
};
};
}

export type Queue = {
export interface Queue {
/** The currently playing track or episode. */
currently_playing: Track | Episode | null;
/** The tracks or episodes in the queue. Can be empty. */
queue: (Track | Episode)[];
};
}

export type PlayHistoryObject = {
export interface PlayHistoryObject {
/** The track the user listened to. */
track: Track;
/** The date and time the track was played. */
played_at: string;
/** The context the track was played from. */
context: Context;
};
}
9 changes: 4 additions & 5 deletions endpoints/playlist/playlist.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface SimplifiedPlaylist {
* Known external URLs for this playlist.
*/
external_urls: ExternalUrls;

/**
* A link to the Web API endpoint providing full details of the playlist.
*/
Expand Down Expand Up @@ -62,14 +61,14 @@ export interface SimplifiedPlaylist {
tracks: TracksReference;
}

export type TracksReference = {
export interface TracksReference {
/**
* A link to the Web API endpoint where full details of the playlist’s tracks can be retrieved.
*/
href: string;
/** The total number of tracks in playlist. */
total: number;
};
}

/**
* The structure containing the details of the Spotify Track in the playlist.
Expand Down Expand Up @@ -122,11 +121,11 @@ export interface Playlist extends SimplifiedPlaylist {
tracks: PagingObject<PlaylistTrack>;
}

export type FeaturedPlaylists = {
export interface FeaturedPlaylists {
/** The message from the featured playlists. */
message: string;
/**
* The list of the featured playlists wrapped in Paging object.
*/
playlists: PagingObject<SimplifiedPlaylist>;
};
}
Loading

0 comments on commit 428231d

Please sign in to comment.