soundcloud-api-ts 1.12.0 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -355,6 +355,14 @@ var RawClient = class {
355
355
  }
356
356
  };
357
357
 
358
+ // src/utils/base64.ts
359
+ var toBase64 = (value) => {
360
+ if (typeof Buffer !== "undefined") {
361
+ return Buffer.from(value).toString("base64");
362
+ }
363
+ return btoa(value);
364
+ };
365
+
358
366
  // src/client/SoundCloudClient.ts
359
367
  function resolveToken(tokenGetter, explicit) {
360
368
  const t = explicit ?? tokenGetter();
@@ -561,9 +569,7 @@ exports.SoundCloudClient = class _SoundCloudClient {
561
569
  * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/oauth2/post_oauth2_token
562
570
  */
563
571
  async getClientToken() {
564
- const basicAuth = Buffer.from(
565
- `${this.config.clientId}:${this.config.clientSecret}`
566
- ).toString("base64");
572
+ const basicAuth = toBase64(`${this.config.clientId}:${this.config.clientSecret}`);
567
573
  return this.fetch({
568
574
  path: "/oauth/token",
569
575
  method: "POST",
@@ -622,13 +628,15 @@ exports.SoundCloudClient = class _SoundCloudClient {
622
628
  * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/oauth2/post_oauth2_token
623
629
  */
624
630
  async refreshUserToken(refreshToken) {
631
+ const basicAuth = toBase64(`${this.config.clientId}:${this.config.clientSecret}`);
625
632
  return this.fetch({
626
633
  path: "/oauth/token",
627
634
  method: "POST",
635
+ headers: {
636
+ Authorization: `Basic ${basicAuth}`
637
+ },
628
638
  body: new URLSearchParams({
629
639
  grant_type: "refresh_token",
630
- client_id: this.config.clientId,
631
- client_secret: this.config.clientSecret,
632
640
  redirect_uri: this.config.redirectUri,
633
641
  refresh_token: refreshToken
634
642
  })
@@ -874,6 +882,27 @@ exports.SoundCloudClient = class _SoundCloudClient {
874
882
  const t = resolveToken(this.getToken, options?.token);
875
883
  return this.fetch({ path: `/me/tracks?${limit ? `limit=${limit}&` : ""}linked_partitioning=true`, method: "GET", token: t });
876
884
  }
885
+ /**
886
+ * List the authenticated user's connected external social accounts.
887
+ *
888
+ * @param options - Optional token override
889
+ * @returns Array of connection objects for linked social services (Twitter, Facebook, etc.)
890
+ * @throws {SoundCloudError} When the API returns an error
891
+ *
892
+ * @remarks This endpoint may require elevated API access or app approval.
893
+ *
894
+ * @example
895
+ * ```ts
896
+ * const connections = await sc.me.getConnections();
897
+ * connections.forEach(c => console.log(c.service, c.display_name));
898
+ * ```
899
+ *
900
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/me/get_me_connections
901
+ */
902
+ async getConnections(options) {
903
+ const t = resolveToken(this.getToken, options?.token);
904
+ return this.fetch({ path: "/me/connections", method: "GET", token: t });
905
+ }
877
906
  }
878
907
  SoundCloudClient2.Me = Me;
879
908
  class Users {
@@ -1045,6 +1074,34 @@ exports.SoundCloudClient = class _SoundCloudClient {
1045
1074
  const t = resolveToken(this.getToken, options?.token);
1046
1075
  return this.fetch({ path: `/tracks/${trackId}`, method: "GET", token: t });
1047
1076
  }
1077
+ /**
1078
+ * Fetch multiple tracks by their IDs in a single request.
1079
+ *
1080
+ * @param ids - Array of track IDs (numeric or string URNs)
1081
+ * @param options - Optional token override
1082
+ * @returns Array of track objects (may be shorter than `ids` if some tracks are unavailable)
1083
+ * @throws {SoundCloudError} When the API returns an error
1084
+ * @throws {Error} When more than 200 IDs are provided
1085
+ *
1086
+ * @remarks
1087
+ * SoundCloud's API likely caps at ~200 IDs per request. Passing more than 200 IDs
1088
+ * will throw immediately without making a network request.
1089
+ *
1090
+ * @example
1091
+ * ```ts
1092
+ * const tracks = await sc.tracks.getTracks([123456, 234567, 345678]);
1093
+ * tracks.forEach(t => console.log(t.title));
1094
+ * ```
1095
+ *
1096
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/tracks/get_tracks
1097
+ */
1098
+ async getTracks(ids, options) {
1099
+ if (ids.length > 200) {
1100
+ throw new Error("getTracks: SoundCloud API supports a maximum of 200 IDs per request");
1101
+ }
1102
+ const t = resolveToken(this.getToken, options?.token);
1103
+ return this.fetch({ path: `/tracks?ids=${ids.join(",")}`, method: "GET", token: t });
1104
+ }
1048
1105
  /**
1049
1106
  * Get stream URLs for a track.
1050
1107
  *
@@ -1641,6 +1698,7 @@ var IMPLEMENTED_OPERATIONS = [
1641
1698
  "get_me_followers",
1642
1699
  "get_me_playlists",
1643
1700
  "get_me_tracks",
1701
+ "get_me_connections",
1644
1702
  // Users
1645
1703
  "get_users_user_id",
1646
1704
  "get_users_user_id_followers",
@@ -1685,7 +1743,7 @@ var IMPLEMENTED_OPERATIONS = [
1685
1743
 
1686
1744
  // src/auth/getClientToken.ts
1687
1745
  var getClientToken = (clientId, clientSecret) => {
1688
- const basicAuth = Buffer.from(`${clientId}:${clientSecret}`).toString("base64");
1746
+ const basicAuth = toBase64(`${clientId}:${clientSecret}`);
1689
1747
  return scFetch({
1690
1748
  path: "/oauth/token",
1691
1749
  method: "POST",
@@ -1717,13 +1775,15 @@ var getUserToken = (clientId, clientSecret, redirectUri, code, codeVerifier) =>
1717
1775
 
1718
1776
  // src/auth/refreshUserToken.ts
1719
1777
  var refreshUserToken = (clientId, clientSecret, redirectUri, refreshToken) => {
1778
+ const basicAuth = toBase64(`${clientId}:${clientSecret}`);
1720
1779
  return scFetch({
1721
1780
  path: "/oauth/token",
1722
1781
  method: "POST",
1782
+ headers: {
1783
+ Authorization: `Basic ${basicAuth}`
1784
+ },
1723
1785
  body: new URLSearchParams({
1724
1786
  grant_type: "refresh_token",
1725
- client_id: clientId,
1726
- client_secret: clientSecret,
1727
1787
  redirect_uri: redirectUri,
1728
1788
  refresh_token: refreshToken
1729
1789
  })
@@ -1802,6 +1862,18 @@ var getUserWebProfiles = (token, userId) => scFetch({ path: `/users/${userId}/we
1802
1862
  // src/tracks/getTrack.ts
1803
1863
  var getTrack = (token, trackId) => scFetch({ path: `/tracks/${trackId}`, method: "GET", token });
1804
1864
 
1865
+ // src/tracks/getTracks.ts
1866
+ var getTracks = (token, ids) => {
1867
+ if (ids.length > 200) {
1868
+ throw new Error("getTracks: SoundCloud API supports a maximum of 200 IDs per request");
1869
+ }
1870
+ return scFetch({
1871
+ path: `/tracks?ids=${ids.join(",")}`,
1872
+ method: "GET",
1873
+ token
1874
+ });
1875
+ };
1876
+
1805
1877
  // src/tracks/getComments.ts
1806
1878
  var getTrackComments = (token, trackId, limit) => scFetch({ path: `/tracks/${trackId}/comments?threaded=1&filter_replies=0${limit ? `&limit=${limit}` : ""}&linked_partitioning=true`, method: "GET", token });
1807
1879
 
@@ -1920,6 +1992,9 @@ var getMePlaylists = (token, limit) => scFetch({ path: `/me/playlists?${limit ?
1920
1992
  // src/me/tracks.ts
1921
1993
  var getMeTracks = (token, limit) => scFetch({ path: `/me/tracks?${limit ? `limit=${limit}&` : ""}linked_partitioning=true`, method: "GET", token });
1922
1994
 
1995
+ // src/me/connections.ts
1996
+ var getMeConnections = (token) => scFetch({ path: "/me/connections", method: "GET", token });
1997
+
1923
1998
  // src/likes/index.ts
1924
1999
  var likePlaylist = async (token, playlistId) => {
1925
2000
  try {
@@ -1994,6 +2069,7 @@ exports.getMe = getMe;
1994
2069
  exports.getMeActivities = getMeActivities;
1995
2070
  exports.getMeActivitiesOwn = getMeActivitiesOwn;
1996
2071
  exports.getMeActivitiesTracks = getMeActivitiesTracks;
2072
+ exports.getMeConnections = getMeConnections;
1997
2073
  exports.getMeFollowers = getMeFollowers;
1998
2074
  exports.getMeFollowings = getMeFollowings;
1999
2075
  exports.getMeFollowingsTracks = getMeFollowingsTracks;
@@ -2011,6 +2087,7 @@ exports.getTrackComments = getTrackComments;
2011
2087
  exports.getTrackLikes = getTrackLikes;
2012
2088
  exports.getTrackReposts = getTrackReposts;
2013
2089
  exports.getTrackStreams = getTrackStreams;
2090
+ exports.getTracks = getTracks;
2014
2091
  exports.getUser = getUser;
2015
2092
  exports.getUserLikesPlaylists = getUserLikesPlaylists;
2016
2093
  exports.getUserLikesTracks = getUserLikesTracks;
@@ -2039,5 +2116,5 @@ exports.unrepostPlaylist = unrepostPlaylist;
2039
2116
  exports.unrepostTrack = unrepostTrack;
2040
2117
  exports.updatePlaylist = updatePlaylist;
2041
2118
  exports.updateTrack = updateTrack;
2042
- //# sourceMappingURL=chunk-D7AF372V.js.map
2043
- //# sourceMappingURL=chunk-D7AF372V.js.map
2119
+ //# sourceMappingURL=chunk-RS2J5LTS.js.map
2120
+ //# sourceMappingURL=chunk-RS2J5LTS.js.map