soundcloud-api-ts 1.13.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.
- package/AGENTS.md +11 -1
- package/README.md +2 -1
- package/dist/{chunk-JH7TLL2C.mjs → chunk-CCHK5S6S.mjs} +38 -15
- package/dist/chunk-CCHK5S6S.mjs.map +1 -0
- package/dist/{chunk-VBDIRSOG.js → chunk-RS2J5LTS.js} +38 -15
- package/dist/chunk-RS2J5LTS.js.map +1 -0
- package/dist/cli.js +6 -6
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +68 -68
- package/dist/index.mjs +1 -1
- package/llms.txt +33 -1
- package/package.json +2 -2
- package/dist/chunk-JH7TLL2C.mjs.map +0 -1
- package/dist/chunk-VBDIRSOG.js.map +0 -1
|
@@ -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 =
|
|
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
|
})
|
|
@@ -1073,6 +1081,11 @@ exports.SoundCloudClient = class _SoundCloudClient {
|
|
|
1073
1081
|
* @param options - Optional token override
|
|
1074
1082
|
* @returns Array of track objects (may be shorter than `ids` if some tracks are unavailable)
|
|
1075
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.
|
|
1076
1089
|
*
|
|
1077
1090
|
* @example
|
|
1078
1091
|
* ```ts
|
|
@@ -1083,6 +1096,9 @@ exports.SoundCloudClient = class _SoundCloudClient {
|
|
|
1083
1096
|
* @see https://developers.soundcloud.com/docs/api/explorer/open-api#/tracks/get_tracks
|
|
1084
1097
|
*/
|
|
1085
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
|
+
}
|
|
1086
1102
|
const t = resolveToken(this.getToken, options?.token);
|
|
1087
1103
|
return this.fetch({ path: `/tracks?ids=${ids.join(",")}`, method: "GET", token: t });
|
|
1088
1104
|
}
|
|
@@ -1727,7 +1743,7 @@ var IMPLEMENTED_OPERATIONS = [
|
|
|
1727
1743
|
|
|
1728
1744
|
// src/auth/getClientToken.ts
|
|
1729
1745
|
var getClientToken = (clientId, clientSecret) => {
|
|
1730
|
-
const basicAuth =
|
|
1746
|
+
const basicAuth = toBase64(`${clientId}:${clientSecret}`);
|
|
1731
1747
|
return scFetch({
|
|
1732
1748
|
path: "/oauth/token",
|
|
1733
1749
|
method: "POST",
|
|
@@ -1759,13 +1775,15 @@ var getUserToken = (clientId, clientSecret, redirectUri, code, codeVerifier) =>
|
|
|
1759
1775
|
|
|
1760
1776
|
// src/auth/refreshUserToken.ts
|
|
1761
1777
|
var refreshUserToken = (clientId, clientSecret, redirectUri, refreshToken) => {
|
|
1778
|
+
const basicAuth = toBase64(`${clientId}:${clientSecret}`);
|
|
1762
1779
|
return scFetch({
|
|
1763
1780
|
path: "/oauth/token",
|
|
1764
1781
|
method: "POST",
|
|
1782
|
+
headers: {
|
|
1783
|
+
Authorization: `Basic ${basicAuth}`
|
|
1784
|
+
},
|
|
1765
1785
|
body: new URLSearchParams({
|
|
1766
1786
|
grant_type: "refresh_token",
|
|
1767
|
-
client_id: clientId,
|
|
1768
|
-
client_secret: clientSecret,
|
|
1769
1787
|
redirect_uri: redirectUri,
|
|
1770
1788
|
refresh_token: refreshToken
|
|
1771
1789
|
})
|
|
@@ -1845,11 +1863,16 @@ var getUserWebProfiles = (token, userId) => scFetch({ path: `/users/${userId}/we
|
|
|
1845
1863
|
var getTrack = (token, trackId) => scFetch({ path: `/tracks/${trackId}`, method: "GET", token });
|
|
1846
1864
|
|
|
1847
1865
|
// src/tracks/getTracks.ts
|
|
1848
|
-
var getTracks = (token, ids) =>
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
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
|
+
};
|
|
1853
1876
|
|
|
1854
1877
|
// src/tracks/getComments.ts
|
|
1855
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 });
|
|
@@ -2093,5 +2116,5 @@ exports.unrepostPlaylist = unrepostPlaylist;
|
|
|
2093
2116
|
exports.unrepostTrack = unrepostTrack;
|
|
2094
2117
|
exports.updatePlaylist = updatePlaylist;
|
|
2095
2118
|
exports.updateTrack = updateTrack;
|
|
2096
|
-
//# sourceMappingURL=chunk-
|
|
2097
|
-
//# sourceMappingURL=chunk-
|
|
2119
|
+
//# sourceMappingURL=chunk-RS2J5LTS.js.map
|
|
2120
|
+
//# sourceMappingURL=chunk-RS2J5LTS.js.map
|