soundcloud-wrapper 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/client.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SoundCloudClient = void 0;
4
+ class SoundCloudClient {
5
+ constructor(clientId, clientSecret, redirectUri, PKCECodeVerifier) {
6
+ this.baseUrl = "https://api.soundcloud.com";
7
+ this.clientId = clientId;
8
+ this.clientSecret = clientSecret;
9
+ this.redirectUri = redirectUri;
10
+ this.PKCECodeVerifier = PKCECodeVerifier;
11
+ }
12
+ }
13
+ exports.SoundCloudClient = SoundCloudClient;
14
+ exports.default = SoundCloudClient;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Likes = void 0;
16
+ const client_1 = __importDefault(require("../client"));
17
+ const axios_1 = __importDefault(require("axios"));
18
+ class Likes extends client_1.default {
19
+ // likes a specific track
20
+ likeTrack(authToken, trackId) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return this.likeRequest(authToken, "/tracks", trackId);
23
+ });
24
+ }
25
+ // likes a specific playlist
26
+ likePlaylist(authToken, playlistId) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ return this.likeRequest(authToken, "/playlists", playlistId);
29
+ });
30
+ }
31
+ // unlikes a specific track
32
+ unlikeTrack(authToken, trackId) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return this.unlikeRequest(authToken, "/tracks", trackId);
35
+ });
36
+ }
37
+ // unlikes a specific playlist
38
+ unlikePlaylist(authToken, playlistId) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return this.unlikeRequest(authToken, "/playlists", playlistId);
41
+ });
42
+ }
43
+ // --- REQUESTS ---
44
+ likeRequest(authToken, endpoint, id) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ var _a;
47
+ try {
48
+ const config = {
49
+ method: "POST",
50
+ maxBodyLength: Infinity,
51
+ url: `${this.baseUrl}/likes${endpoint}/${id}`,
52
+ headers: {
53
+ accept: "application/json; charset=utf-8",
54
+ "Content-Type": "application/json; charset=utf-8",
55
+ Authorization: `OAuth ${authToken}`,
56
+ },
57
+ };
58
+ const response = yield axios_1.default
59
+ .request(config)
60
+ .then((response) => {
61
+ return response.data;
62
+ })
63
+ .catch((error) => {
64
+ console.log(error);
65
+ throw new Error("Failed to get me");
66
+ });
67
+ return response;
68
+ }
69
+ catch (error) {
70
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
71
+ throw error;
72
+ }
73
+ });
74
+ }
75
+ unlikeRequest(authToken, endpoint, id) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ var _a;
78
+ try {
79
+ const config = {
80
+ method: "DELETE",
81
+ maxBodyLength: Infinity,
82
+ url: `${this.baseUrl}/likes${endpoint}/${id}`,
83
+ headers: {
84
+ accept: "application/json; charset=utf-8",
85
+ "Content-Type": "application/json; charset=utf-8",
86
+ Authorization: `OAuth ${authToken}`,
87
+ },
88
+ };
89
+ const response = yield axios_1.default
90
+ .request(config)
91
+ .then((response) => {
92
+ return response.data;
93
+ })
94
+ .catch((error) => {
95
+ console.log(error);
96
+ throw new Error("Failed to get me");
97
+ });
98
+ return response;
99
+ }
100
+ catch (error) {
101
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
102
+ throw error;
103
+ }
104
+ });
105
+ }
106
+ }
107
+ exports.Likes = Likes;
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Me = void 0;
16
+ const client_1 = __importDefault(require("../client"));
17
+ const axios_1 = __importDefault(require("axios"));
18
+ class Me extends client_1.default {
19
+ // Returns authenticated users info
20
+ me(authToken) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return this.getRequest(authToken, "/me");
23
+ });
24
+ }
25
+ // Returns authenticated users activity
26
+ getActivity(authToken) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ return this.getRequest(authToken, "/me/activities");
29
+ });
30
+ }
31
+ // Returns authenticated users track activity
32
+ getTrackActivity(authToken) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return this.getRequest(authToken, "/me/activities/tracks");
35
+ });
36
+ }
37
+ // Returns authenticated users track likes activity
38
+ getTrackLikes(authToken) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return this.getRequest(authToken, "/me/likes/tracks");
41
+ });
42
+ }
43
+ // Returns authenticated users playlist likes activity
44
+ getPlaylistLikes(authToken) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ return this.getRequest(authToken, "/me/likes/playlists");
47
+ });
48
+ }
49
+ // Returns people authenticated user is following
50
+ getFollowings(authToken) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ return this.getRequest(authToken, "/me/followings");
53
+ });
54
+ }
55
+ // Returns peoples tracks authenticated user is following
56
+ getFollowingsTracks(authToken) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ return this.getRequest(authToken, "/me/followings/tracks");
59
+ });
60
+ }
61
+ // Follows the specified user
62
+ followUser(authToken, userId) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ return this.followRequest(authToken, "/me/followings", userId);
65
+ });
66
+ }
67
+ // Unfollows the specified user
68
+ unfollowUser(authToken, userId) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ return this.unfollowRequest(authToken, "/me/followings", userId);
71
+ });
72
+ }
73
+ // TODO: bind authToken to object so it does not need to be passed everytime
74
+ // --- REQUESTS ---
75
+ getRequest(authToken, endpoint) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ var _a;
78
+ try {
79
+ const config = {
80
+ method: "GET",
81
+ maxBodyLength: Infinity,
82
+ url: `${this.baseUrl}${endpoint}`,
83
+ headers: {
84
+ accept: "application/json; charset=utf-8",
85
+ "Content-Type": "application/json; charset=utf-8",
86
+ Authorization: `OAuth ${authToken}`,
87
+ },
88
+ };
89
+ const response = yield axios_1.default
90
+ .request(config)
91
+ .then((response) => {
92
+ return response.data;
93
+ })
94
+ .catch((error) => {
95
+ console.log(error);
96
+ throw new Error("Failed to get me");
97
+ });
98
+ return response;
99
+ }
100
+ catch (error) {
101
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
102
+ throw error;
103
+ }
104
+ });
105
+ }
106
+ followRequest(authToken, endpoint, userId) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ var _a;
109
+ try {
110
+ const config = {
111
+ method: "PUT",
112
+ maxBodyLength: Infinity,
113
+ url: `${this.baseUrl}${endpoint}/${userId}`,
114
+ headers: {
115
+ accept: "application/json; charset=utf-8",
116
+ "Content-Type": "application/json; charset=utf-8",
117
+ Authorization: `OAuth ${authToken}`,
118
+ },
119
+ data: {
120
+ user_id: userId,
121
+ },
122
+ };
123
+ const response = yield axios_1.default
124
+ .request(config)
125
+ .then((response) => {
126
+ return response.data;
127
+ })
128
+ .catch((error) => {
129
+ console.log(error);
130
+ throw new Error("Failed to get me");
131
+ });
132
+ return response;
133
+ }
134
+ catch (error) {
135
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
136
+ throw error;
137
+ }
138
+ });
139
+ }
140
+ unfollowRequest(authToken, endpoint, userId) {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ var _a;
143
+ try {
144
+ const config = {
145
+ method: "DELETE",
146
+ maxBodyLength: Infinity,
147
+ url: `${this.baseUrl}${endpoint}/${userId}`,
148
+ headers: {
149
+ accept: "application/json; charset=utf-8",
150
+ "Content-Type": "application/json; charset=utf-8",
151
+ Authorization: `OAuth ${authToken}`,
152
+ },
153
+ data: {
154
+ user_id: userId,
155
+ },
156
+ };
157
+ const response = yield axios_1.default
158
+ .request(config)
159
+ .then((response) => {
160
+ return response.data;
161
+ })
162
+ .catch((error) => {
163
+ console.log(error);
164
+ throw new Error("Failed to get me");
165
+ });
166
+ return response;
167
+ }
168
+ catch (error) {
169
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
170
+ throw error;
171
+ }
172
+ });
173
+ }
174
+ }
175
+ exports.Me = Me;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Misc = void 0;
16
+ const client_1 = __importDefault(require("../client"));
17
+ const axios_1 = __importDefault(require("axios"));
18
+ class Misc extends client_1.default {
19
+ resolveUrl(authToken, url) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ return this.resolveRequest(authToken, url);
22
+ });
23
+ }
24
+ // --- REQUESTS ---
25
+ resolveRequest(authToken, url) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ var _a;
28
+ try {
29
+ const config = {
30
+ method: "GET",
31
+ maxBodyLength: Infinity,
32
+ url: `${this.baseUrl}/resolve?url=${url}`,
33
+ headers: {
34
+ "Content-Type": "application/json; charset=utf-8",
35
+ Authorization: `OAuth ${authToken}`,
36
+ },
37
+ };
38
+ const response = yield axios_1.default.request(config);
39
+ return response.data;
40
+ }
41
+ catch (error) {
42
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
43
+ throw error;
44
+ }
45
+ });
46
+ }
47
+ }
48
+ exports.Misc = Misc;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Playlist = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const client_1 = __importDefault(require("../client"));
18
+ class Playlist extends client_1.default {
19
+ // gets a specific playlist
20
+ getPlaylist(authToken, playlistId) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return this.getPlaylistRequest(authToken, "", playlistId);
23
+ });
24
+ }
25
+ // gets the tracks of a specific playlist
26
+ getPlaylistTracks(authToken, playlistId) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ return this.getPlaylistRequest(authToken, "/tracks", playlistId);
29
+ });
30
+ }
31
+ // gets the reposters of a specific playlist
32
+ getPlaylistReposters(authToken, playlistId) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return this.getPlaylistRequest(authToken, "/reposters", playlistId);
35
+ });
36
+ }
37
+ // creates a new playlist
38
+ createPlaylist(authToken, playlistData) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return this.createPlaylistRequest(authToken, playlistData);
41
+ });
42
+ }
43
+ // updates a specific playlist
44
+ updatePlaylist(authToken, playlistId, playlistData) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ return this.updatePlaylistRequest(authToken, playlistId, playlistData);
47
+ });
48
+ }
49
+ // deletes a specific playlist
50
+ deletePlaylist(authToken, playlistId) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ return this.deletePlaylistRequest(authToken, playlistId);
53
+ });
54
+ }
55
+ // --- REQUESTS ---
56
+ getPlaylistRequest(authToken, endpoint, playlistId) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ var _a;
59
+ try {
60
+ const config = {
61
+ method: "GET",
62
+ maxBodyLength: Infinity,
63
+ url: `${this.baseUrl}/playlists/${playlistId}${endpoint}`,
64
+ headers: {
65
+ "Content-Type": "application/json; charset=utf-8",
66
+ Authorization: `OAuth ${authToken}`,
67
+ },
68
+ };
69
+ const response = yield axios_1.default.request(config);
70
+ return response.data;
71
+ }
72
+ catch (error) {
73
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
74
+ throw error;
75
+ }
76
+ });
77
+ }
78
+ createPlaylistRequest(authToken, playlistData) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ var _a;
81
+ try {
82
+ const config = {
83
+ method: "POST",
84
+ maxBodyLength: Infinity,
85
+ url: `${this.baseUrl}/playlists`,
86
+ headers: {
87
+ "Content-Type": "application/json; charset=utf-8",
88
+ Authorization: `OAuth ${authToken}`,
89
+ },
90
+ data: playlistData,
91
+ };
92
+ const response = yield axios_1.default.request(config);
93
+ return response.data;
94
+ }
95
+ catch (error) {
96
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
97
+ throw error;
98
+ }
99
+ });
100
+ }
101
+ updatePlaylistRequest(authToken, playlistId, playlistData) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ var _a;
104
+ try {
105
+ const config = {
106
+ method: "PUT",
107
+ maxBodyLength: Infinity,
108
+ url: `${this.baseUrl}/playlists/${playlistId}`,
109
+ headers: {
110
+ "Content-Type": "application/json; charset=utf-8",
111
+ Authorization: `OAuth ${authToken}`,
112
+ },
113
+ data: playlistData,
114
+ };
115
+ const response = yield axios_1.default.request(config);
116
+ return response.data;
117
+ }
118
+ catch (error) {
119
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
120
+ throw error;
121
+ }
122
+ });
123
+ }
124
+ deletePlaylistRequest(authToken, playlistId) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ var _a;
127
+ try {
128
+ const config = {
129
+ method: "DELETE",
130
+ maxBodyLength: Infinity,
131
+ url: `${this.baseUrl}/playlists/${playlistId}`,
132
+ headers: {
133
+ "Content-Type": "application/json; charset=utf-8",
134
+ Authorization: `OAuth ${authToken}`,
135
+ },
136
+ };
137
+ const response = yield axios_1.default.request(config);
138
+ return response.data;
139
+ }
140
+ catch (error) {
141
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
142
+ throw error;
143
+ }
144
+ });
145
+ }
146
+ }
147
+ exports.Playlist = Playlist;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Reposts = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const client_1 = __importDefault(require("../client"));
18
+ class Reposts extends client_1.default {
19
+ // reposts a specific track
20
+ repostTrack(authToken, trackId) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return this.repostRequest(authToken, "/tracks", trackId);
23
+ });
24
+ }
25
+ // removes a repost of a specific track
26
+ removeRepostTrack(authToken, trackId) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ return this.removeRepostRequest(authToken, "/tracks", trackId);
29
+ });
30
+ }
31
+ // reposts a specific playlist
32
+ repostPlaylist(authToken, playlistId) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return this.repostRequest(authToken, "/playlists", playlistId);
35
+ });
36
+ }
37
+ // removes a repost of a specific playlist
38
+ removeRepostPlaylist(authToken, playlistId) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return this.removeRepostRequest(authToken, "/playlists", playlistId);
41
+ });
42
+ }
43
+ // --- REQUESTS ---
44
+ repostRequest(authToken, endpoint, id) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ var _a;
47
+ try {
48
+ const config = {
49
+ method: "POST",
50
+ maxBodyLength: Infinity,
51
+ url: `${this.baseUrl}/reposts${endpoint}/${id}`,
52
+ headers: {
53
+ accept: "application/json; charset=utf-8",
54
+ "Content-Type": "application/json; charset=utf-8",
55
+ Authorization: `OAuth ${authToken}`,
56
+ },
57
+ };
58
+ const response = yield axios_1.default
59
+ .request(config)
60
+ .then((response) => {
61
+ return response.data;
62
+ })
63
+ .catch((error) => {
64
+ console.log(error);
65
+ throw new Error("Failed to get me");
66
+ });
67
+ return response;
68
+ }
69
+ catch (error) {
70
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
71
+ throw error;
72
+ }
73
+ });
74
+ }
75
+ removeRepostRequest(authToken, endpoint, id) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ var _a;
78
+ try {
79
+ const config = {
80
+ method: "DELETE",
81
+ maxBodyLength: Infinity,
82
+ url: `${this.baseUrl}/reposts${endpoint}/${id}`,
83
+ headers: {
84
+ accept: "application/json; charset=utf-8",
85
+ "Content-Type": "application/json; charset=utf-8",
86
+ Authorization: `OAuth ${authToken}`,
87
+ },
88
+ };
89
+ const response = yield axios_1.default
90
+ .request(config)
91
+ .then((response) => {
92
+ return response.data;
93
+ })
94
+ .catch((error) => {
95
+ console.log(error);
96
+ throw new Error("Failed to get me");
97
+ });
98
+ return response;
99
+ }
100
+ catch (error) {
101
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
102
+ throw error;
103
+ }
104
+ });
105
+ }
106
+ }
107
+ exports.Reposts = Reposts;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Search = void 0;
16
+ const client_1 = __importDefault(require("../client"));
17
+ const axios_1 = __importDefault(require("axios"));
18
+ // TODO: full query support
19
+ class Search extends client_1.default {
20
+ // searches for tracks
21
+ tracks(authToken, query) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ return this.searchRequest(authToken, `/tracks?q=${query}`);
24
+ });
25
+ }
26
+ // searches for playlists
27
+ playlists(authToken, query) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ return this.searchRequest(authToken, `/playlists?q=${query}`);
30
+ });
31
+ }
32
+ // searches for users
33
+ users(authToken, query) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return this.searchRequest(authToken, `/users?q=${query}`);
36
+ });
37
+ }
38
+ // --- REQUESTS ---
39
+ searchRequest(authToken, endpoint) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ var _a;
42
+ try {
43
+ const config = {
44
+ method: "GET",
45
+ maxBodyLength: Infinity,
46
+ url: `${this.baseUrl}${endpoint}`,
47
+ headers: {
48
+ accept: "application/json; charset=utf-8",
49
+ "Content-Type": "application/json; charset=utf-8",
50
+ Authorization: `OAuth ${authToken}`,
51
+ },
52
+ };
53
+ const response = yield axios_1.default
54
+ .request(config)
55
+ .then((response) => {
56
+ return response.data;
57
+ })
58
+ .catch((error) => {
59
+ console.log(error);
60
+ throw new Error("Failed to get me");
61
+ });
62
+ return response;
63
+ }
64
+ catch (error) {
65
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
66
+ throw error;
67
+ }
68
+ });
69
+ }
70
+ }
71
+ exports.Search = Search;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Token = void 0;
16
+ const client_1 = __importDefault(require("../client"));
17
+ const axios_1 = __importDefault(require("axios"));
18
+ const qs_1 = __importDefault(require("qs"));
19
+ class Token extends client_1.default {
20
+ // Returns access token for logged in user
21
+ getToken(PKCECodeChallenge) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ return this.getAccessToken(this.clientId, this.clientSecret, this.redirectUri, this.PKCECodeVerifier, PKCECodeChallenge);
24
+ });
25
+ }
26
+ // --- REQUESTS ---
27
+ getAccessToken(clientId, clientSecret, redirectUri, PKCECodeVerifier, PKCECodeChallenge) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const data = qs_1.default.stringify({
30
+ grant_type: "authorization_code",
31
+ client_id: clientId,
32
+ client_secret: clientSecret,
33
+ redirect_uri: redirectUri,
34
+ code_verifier: PKCECodeVerifier,
35
+ code: PKCECodeChallenge,
36
+ });
37
+ const config = {
38
+ method: "post",
39
+ url: "https://secure.soundcloud.com/oauth/token",
40
+ headers: {
41
+ accept: "application/json; charset=utf-8",
42
+ "Content-Type": "application/x-www-form-urlencoded",
43
+ },
44
+ data: data,
45
+ };
46
+ const response = yield axios_1.default.request(config);
47
+ return response.data;
48
+ });
49
+ }
50
+ }
51
+ exports.Token = Token;
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Tracks = void 0;
16
+ const client_1 = __importDefault(require("../client"));
17
+ const axios_1 = __importDefault(require("axios"));
18
+ // TODO: add upload support
19
+ class Tracks extends client_1.default {
20
+ // gets a specific track
21
+ getTrack(authToken, trackId) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ return this.getTrackRequest(authToken, "", trackId);
24
+ });
25
+ }
26
+ // gets the streams of a specific track
27
+ getTrackStreams(authToken, trackId) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ return this.getTrackRequest(authToken, "/streams", trackId);
30
+ });
31
+ }
32
+ // gets the comments of a specific track
33
+ getTrackComments(authToken, trackId) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return this.getTrackRequest(authToken, "/comments", trackId);
36
+ });
37
+ }
38
+ // gets the people who liked a specific track
39
+ getTrackLikers(authToken, trackId) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return this.getTrackRequest(authToken, "/favoriters", trackId);
42
+ });
43
+ }
44
+ // gets the people who reposted a specific track
45
+ getTrackReposters(authToken, trackId) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ return this.getTrackRequest(authToken, "/reposters", trackId);
48
+ });
49
+ }
50
+ // gets the related tracks of a specific track
51
+ getRelatedTracks(authToken, trackId) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ return this.getTrackRequest(authToken, "/related", trackId);
54
+ });
55
+ }
56
+ // creates a comment on a specific track
57
+ addComment(authToken, trackId, comment) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ return this.addCommentRequest(authToken, trackId, comment);
60
+ });
61
+ }
62
+ // updates a specific track
63
+ updateTrack(authToken, trackId, data) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ return this.updateTrackRequest(authToken, trackId, data);
66
+ });
67
+ }
68
+ // deletes a specific track
69
+ deleteTrack(authToken, trackId) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ return this.deleteTrackRequest(authToken, trackId);
72
+ });
73
+ }
74
+ // --- REQUESTS ---
75
+ getTrackRequest(authToken, endpoint, trackId) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ var _a;
78
+ try {
79
+ const config = {
80
+ method: "GET",
81
+ maxBodyLength: Infinity,
82
+ url: `${this.baseUrl}/tracks/${trackId}${endpoint}`,
83
+ headers: {
84
+ accept: "application/json; charset=utf-8",
85
+ "Content-Type": "application/json; charset=utf-8",
86
+ Authorization: `OAuth ${authToken}`,
87
+ },
88
+ };
89
+ const response = yield axios_1.default
90
+ .request(config)
91
+ .then((response) => {
92
+ return response.data;
93
+ })
94
+ .catch((error) => {
95
+ console.log(error);
96
+ throw new Error("Failed to get me");
97
+ });
98
+ return response;
99
+ }
100
+ catch (error) {
101
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
102
+ throw error;
103
+ }
104
+ });
105
+ }
106
+ addCommentRequest(authToken, trackId, commentData) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ var _a;
109
+ try {
110
+ const config = {
111
+ method: "POST",
112
+ maxBodyLength: Infinity,
113
+ url: `${this.baseUrl}/tracks/${trackId}/comments`,
114
+ headers: {
115
+ accept: "application/json; charset=utf-8",
116
+ "Content-Type": "application/json; charset=utf-8",
117
+ Authorization: `OAuth ${authToken}`,
118
+ },
119
+ data: commentData,
120
+ };
121
+ const response = yield axios_1.default
122
+ .request(config)
123
+ .then((response) => {
124
+ return response.data;
125
+ })
126
+ .catch((error) => {
127
+ console.log(error);
128
+ throw new Error("Failed to get me");
129
+ });
130
+ return response;
131
+ }
132
+ catch (error) {
133
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
134
+ throw error;
135
+ }
136
+ });
137
+ }
138
+ updateTrackRequest(authToken, trackId, trackData) {
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ var _a;
141
+ try {
142
+ const config = {
143
+ method: "PUT",
144
+ maxBodyLength: Infinity,
145
+ url: `${this.baseUrl}/tracks/${trackId}`,
146
+ headers: {
147
+ accept: "application/json; charset=utf-8",
148
+ "Content-Type": "application/json; charset=utf-8",
149
+ Authorization: `OAuth ${authToken}`,
150
+ },
151
+ data: trackData,
152
+ };
153
+ const response = yield axios_1.default
154
+ .request(config)
155
+ .then((response) => {
156
+ return response.data;
157
+ })
158
+ .catch((error) => {
159
+ console.log(error);
160
+ throw new Error("Failed to get me");
161
+ });
162
+ return response;
163
+ }
164
+ catch (error) {
165
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
166
+ throw error;
167
+ }
168
+ });
169
+ }
170
+ deleteTrackRequest(authToken, trackId) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ var _a;
173
+ try {
174
+ const config = {
175
+ method: "DELETE",
176
+ maxBodyLength: Infinity,
177
+ url: `${this.baseUrl}/tracks/${trackId}`,
178
+ headers: {
179
+ accept: "application/json; charset=utf-8",
180
+ "Content-Type": "application/json; charset=utf-8",
181
+ Authorization: `OAuth ${authToken}`,
182
+ },
183
+ };
184
+ const response = yield axios_1.default
185
+ .request(config)
186
+ .then((response) => {
187
+ return response.data;
188
+ })
189
+ .catch((error) => {
190
+ console.log(error);
191
+ throw new Error("Failed to get me");
192
+ });
193
+ return response;
194
+ }
195
+ catch (error) {
196
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
197
+ throw error;
198
+ }
199
+ });
200
+ }
201
+ }
202
+ exports.Tracks = Tracks;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Users = void 0;
16
+ const client_1 = __importDefault(require("../client"));
17
+ const axios_1 = __importDefault(require("axios"));
18
+ class Users extends client_1.default {
19
+ // gets a specific user
20
+ getUser(authToken, userId) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return this.getUserRequest(authToken, "", userId);
23
+ });
24
+ }
25
+ // gets the followers of a specific user
26
+ getUserFollowers(authToken, userId) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ return this.getUserRequest(authToken, "/followers", userId);
29
+ });
30
+ }
31
+ // gets the people a specific user follows
32
+ getUserFollowings(authToken, userId) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return this.getUserRequest(authToken, "/followings", userId);
35
+ });
36
+ }
37
+ // gets the playlists of a specific user
38
+ getUserPlaylists(authToken, userId) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return this.getUserRequest(authToken, "/playlists", userId);
41
+ });
42
+ }
43
+ // gets the tracks of a specific user
44
+ getUserTracks(authToken, userId) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ return this.getUserRequest(authToken, "/tracks", userId);
47
+ });
48
+ }
49
+ // gets the web profiles of a specific user
50
+ getUserWebProfiles(authToken, userId) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ return this.getUserRequest(authToken, "/web-profiles", userId);
53
+ });
54
+ }
55
+ // gets the tracks a specific user liked
56
+ getUserLikedTracks(authToken, userId) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ return this.getUserRequest(authToken, "/likes/tracks", userId);
59
+ });
60
+ }
61
+ // gets the playlists a specific user liked
62
+ getUserLikedPlaylists(authToken, userId) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ return this.getUserRequest(authToken, "/likes/playlists", userId);
65
+ });
66
+ }
67
+ getUserRequest(authToken, endpoint, userId) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ var _a;
70
+ try {
71
+ const config = {
72
+ method: "GET",
73
+ maxBodyLength: Infinity,
74
+ url: `${this.baseUrl}/users/${userId}${endpoint}`,
75
+ headers: {
76
+ accept: "application/json; charset=utf-8",
77
+ "Content-Type": "application/json; charset=utf-8",
78
+ Authorization: `OAuth ${authToken}`,
79
+ },
80
+ };
81
+ const response = yield axios_1.default
82
+ .request(config)
83
+ .then((response) => {
84
+ return response.data;
85
+ })
86
+ .catch((error) => {
87
+ console.log(error);
88
+ throw new Error("Failed to get me");
89
+ });
90
+ return response;
91
+ }
92
+ catch (error) {
93
+ console.error("SoundCloud API Error:", ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error);
94
+ throw error;
95
+ }
96
+ });
97
+ }
98
+ }
99
+ exports.Users = Users;
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const me_1 = require("./endpoints/me");
4
+ const token_1 = require("./endpoints/token");
5
+ const search_1 = require("./endpoints/search");
6
+ const playlists_1 = require("./endpoints/playlists");
7
+ const tracks_1 = require("./endpoints/tracks");
8
+ const users_1 = require("./endpoints/users");
9
+ const likes_1 = require("./endpoints/likes");
10
+ const reposts_1 = require("./endpoints/reposts");
11
+ const misc_1 = require("./endpoints/misc");
12
+ class SoundCloud {
13
+ constructor(clientId, clientSecret, redirectUri, PKCECodeVerifier) {
14
+ this.token = new token_1.Token(clientId, clientSecret, redirectUri, PKCECodeVerifier);
15
+ this.me = new me_1.Me(clientId, clientSecret, redirectUri, PKCECodeVerifier);
16
+ this.search = new search_1.Search(clientId, clientSecret, redirectUri, PKCECodeVerifier);
17
+ this.playlists = new playlists_1.Playlist(clientId, clientSecret, redirectUri, PKCECodeVerifier);
18
+ this.tracks = new tracks_1.Tracks(clientId, clientSecret, redirectUri, PKCECodeVerifier);
19
+ this.users = new users_1.Users(clientId, clientSecret, redirectUri, PKCECodeVerifier);
20
+ this.likes = new likes_1.Likes(clientId, clientSecret, redirectUri, PKCECodeVerifier);
21
+ this.reposts = new reposts_1.Reposts(clientId, clientSecret, redirectUri, PKCECodeVerifier);
22
+ this.misc = new misc_1.Misc(clientId, clientSecret, redirectUri, PKCECodeVerifier);
23
+ }
24
+ }
25
+ exports.default = SoundCloud;
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "soundcloud-wrapper",
3
+ "version": "0.9.0",
4
+ "description": "Node wrapper for the SoundCloud API",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "repository": "https://github.com/18-28/soundcloud-api",
11
+ "homepage": "https://github.com/18-28/soundcloud-api",
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "prepare": "npm run build"
15
+ },
16
+ "keywords": [
17
+ "soundcloud",
18
+ "api",
19
+ "wrapper",
20
+ "node"
21
+ ],
22
+ "author": "developer_1828",
23
+ "license": "ISC",
24
+ "dependencies": {
25
+ "@types/qs": "^6.9.18",
26
+ "axios": "^1.7.9",
27
+ "qs": "^6.14.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^22.13.0",
31
+ "typescript": "^5.7.3"
32
+ }
33
+ }