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.
@@ -0,0 +1,582 @@
1
+ /**
2
+ * OAuth 2.1 token response returned by SoundCloud's `/oauth/token` endpoint.
3
+ *
4
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/oauth2/post_oauth2_token
5
+ */
6
+ interface SoundCloudToken {
7
+ /** The OAuth 2.1 access token used to authenticate API requests */
8
+ access_token: string;
9
+ /** Number of seconds until the access token expires */
10
+ expires_in: number;
11
+ /** Token used to obtain a new access token when the current one expires */
12
+ refresh_token: string;
13
+ /** OAuth scope granted (e.g. "*" for full access) */
14
+ scope: string;
15
+ /** Token type, typically "bearer" */
16
+ token_type: string;
17
+ }
18
+ /**
19
+ * Represents a SoundCloud user profile.
20
+ *
21
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/users/get_users__user_id_
22
+ */
23
+ interface SoundCloudUser {
24
+ /** URL to the user's avatar image */
25
+ avatar_url: string;
26
+ /** The user's city (may be empty string if not set) */
27
+ city: string;
28
+ /** The user's country (may be empty string if not set) */
29
+ country: string;
30
+ /** ISO 8601 timestamp of when the user account was created */
31
+ created_at: string;
32
+ /** The user's profile description / bio */
33
+ description: string;
34
+ /** The user's Discogs username, or null if not set */
35
+ discogs_name: string | null;
36
+ /** The user's first name */
37
+ first_name: string;
38
+ /** Total number of followers */
39
+ followers_count: number;
40
+ /** Total number of users this user is following */
41
+ followings_count: number;
42
+ /** The user's full name (first + last) */
43
+ full_name: string;
44
+ /** The user's unique numeric ID on SoundCloud */
45
+ id: number;
46
+ /** URN identifier (e.g. "soundcloud:users:123") */
47
+ urn: string;
48
+ /** Resource type, always "user" */
49
+ kind: string;
50
+ /** ISO 8601 timestamp of the last profile modification */
51
+ last_modified: string;
52
+ /** The user's last name */
53
+ last_name: string;
54
+ /** Total number of public likes (favorites) */
55
+ likes_count: number;
56
+ /** Whether the user is currently online */
57
+ online: boolean;
58
+ /** URL-friendly slug for the user's profile (e.g. "artist-name") */
59
+ permalink: string;
60
+ /** Full URL to the user's SoundCloud profile page */
61
+ permalink_url: string;
62
+ /** The user's subscription plan (e.g. "Free", "Pro") */
63
+ plan: string;
64
+ /** Total number of public playlists */
65
+ playlist_count: number;
66
+ /** Total number of public favorites */
67
+ public_favorites_count: number;
68
+ /** Total number of reposts */
69
+ reposts_count: number;
70
+ /** The user's active subscriptions */
71
+ subscriptions: SoundCloudSubscription[];
72
+ /** Total number of public tracks */
73
+ track_count: number;
74
+ /** API resource URI for this user */
75
+ uri: string;
76
+ /** The user's display name */
77
+ username: string;
78
+ /** The user's website URL, or null if not set */
79
+ website: string | null;
80
+ /** Display title for the user's website, or null if not set */
81
+ website_title: string | null;
82
+ /**
83
+ * Comment count for this user.
84
+ * @deprecated Always returns 0 in current API responses.
85
+ */
86
+ comments_count: number;
87
+ /** The user's Myspace username, or null if not set */
88
+ myspace_name: string | null;
89
+ }
90
+ /**
91
+ * Extended user profile returned by the `/me` endpoint, including private account details.
92
+ *
93
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/me/get_me
94
+ */
95
+ interface SoundCloudMe extends SoundCloudUser {
96
+ /** The user's locale setting (e.g. "en"), or null if not set */
97
+ locale: string | null;
98
+ /** Whether the user's primary email address has been confirmed */
99
+ primary_email_confirmed: boolean;
100
+ /** Number of private (unlisted) playlists */
101
+ private_playlists_count: number;
102
+ /** Number of private (unlisted) tracks */
103
+ private_tracks_count: number;
104
+ /** Upload quota information for the authenticated user */
105
+ quota: SoundCloudQuota;
106
+ /** Remaining upload time in seconds, or null if unlimited */
107
+ upload_seconds_left: number | null;
108
+ }
109
+ /**
110
+ * Upload quota details for the authenticated user.
111
+ *
112
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/me/get_me
113
+ */
114
+ interface SoundCloudQuota {
115
+ /** Whether the user has an unlimited upload quota (e.g. Pro plan) */
116
+ unlimited_upload_quota: boolean;
117
+ /** Total upload time consumed in seconds */
118
+ upload_seconds_used: number;
119
+ /** Remaining upload time in seconds, or null if unlimited */
120
+ upload_seconds_left: number | null;
121
+ }
122
+ /**
123
+ * A subscription associated with a SoundCloud user account.
124
+ *
125
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/users
126
+ */
127
+ interface SoundCloudSubscription {
128
+ /** The subscription product details */
129
+ product: SoundCloudSubscriptionProduct;
130
+ /** Whether the subscription auto-renews (may be absent) */
131
+ recurring?: boolean;
132
+ }
133
+ /**
134
+ * Product details for a SoundCloud subscription.
135
+ *
136
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/users
137
+ */
138
+ interface SoundCloudSubscriptionProduct {
139
+ /** Unique product identifier (e.g. "creator-pro-unlimited") */
140
+ id: string;
141
+ /** Human-readable product name (e.g. "Pro Unlimited") */
142
+ name: string;
143
+ }
144
+ /**
145
+ * Represents a SoundCloud track (audio upload).
146
+ *
147
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/tracks/get_tracks__track_id_
148
+ */
149
+ interface SoundCloudTrack {
150
+ /** Access level for the track (e.g. "playable", "preview", "blocked") */
151
+ access: string;
152
+ /** URL to the track's artwork image (may be empty string if none) */
153
+ artwork_url: string;
154
+ /** ISO country codes where the track is available, or null if unrestricted */
155
+ available_country_codes: string[] | null;
156
+ /** Beats per minute of the track (0 if not set) */
157
+ bpm: number;
158
+ /** Total number of comments on this track */
159
+ comment_count: number;
160
+ /** Whether commenting is enabled on this track */
161
+ commentable: boolean;
162
+ /** ISO 8601 timestamp of when the track was uploaded */
163
+ created_at: string;
164
+ /** The track's description text */
165
+ description: string;
166
+ /** Total number of downloads */
167
+ download_count: number;
168
+ /** URL to download the original file (requires authentication) */
169
+ download_url: string;
170
+ /** Whether the track is downloadable */
171
+ downloadable: boolean;
172
+ /** Duration of the track in milliseconds */
173
+ duration: number;
174
+ /** Who can embed this track (e.g. "all", "me", "none") */
175
+ embeddable_by: string;
176
+ /** Total number of favorites/likes */
177
+ favoritings_count: number;
178
+ /** Music genre of the track (e.g. "Electronic") */
179
+ genre: string;
180
+ /** The track's unique numeric ID on SoundCloud */
181
+ id: number;
182
+ /** International Standard Recording Code, or null if not set */
183
+ isrc: string | null;
184
+ /** Musical key signature (e.g. "C major"), or null if not set */
185
+ key_signature: string | null;
186
+ /** Resource type, always "track" */
187
+ kind: string;
188
+ /** Record label name */
189
+ label_name: string;
190
+ /** Creative Commons license type (e.g. "all-rights-reserved", "cc-by") */
191
+ license: string;
192
+ /** Artist name when different from the uploader, or null */
193
+ metadata_artist: string | null;
194
+ /** Monetization model applied to this track, or null */
195
+ monetization_model: string | null;
196
+ /** Full URL to the track's SoundCloud page */
197
+ permalink_url: string;
198
+ /** Total number of plays */
199
+ playback_count: number;
200
+ /** Content policy applied to this track, or null */
201
+ policy: string | null;
202
+ /** Label for the purchase/buy button */
203
+ purchase_title: string;
204
+ /** External purchase URL */
205
+ purchase_url: string;
206
+ /** Release identifier string, or null */
207
+ release: string | null;
208
+ /** Day of the release date (1-31) */
209
+ release_day: number;
210
+ /** Month of the release date (1-12) */
211
+ release_month: number;
212
+ /** Year of the release date */
213
+ release_year: number;
214
+ /** Total number of reposts */
215
+ reposts_count: number;
216
+ /** Secret URI for private tracks, or null for public tracks */
217
+ secret_uri: string | null;
218
+ /** Sharing setting: "public" or "private" */
219
+ sharing: string;
220
+ /** URL to the audio stream (requires authentication) */
221
+ stream_url: string;
222
+ /** Whether the track is streamable */
223
+ streamable: boolean;
224
+ /** Space-separated list of tags (tags with spaces are wrapped in quotes) */
225
+ tag_list: string;
226
+ /** The track's title */
227
+ title: string;
228
+ /** API resource URI for this track */
229
+ uri: string;
230
+ /** URN identifier (e.g. "soundcloud:tracks:123") */
231
+ urn: string;
232
+ /** The user who uploaded this track */
233
+ user: SoundCloudUser;
234
+ /** Whether the authenticated user has liked this track */
235
+ user_favorite: boolean;
236
+ /** Number of times the authenticated user has played this track, or null */
237
+ user_playback_count: number | null;
238
+ /** URL to the track's waveform image data */
239
+ waveform_url: string;
240
+ }
241
+ /**
242
+ * Represents a SoundCloud playlist (also known as a "set").
243
+ *
244
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/playlists/get_playlists__playlist_id_
245
+ */
246
+ interface SoundCloudPlaylist {
247
+ /** URL to the playlist's artwork image */
248
+ artwork_url: string;
249
+ /** ISO 8601 timestamp of when the playlist was created */
250
+ created_at: string;
251
+ /** The playlist's description text */
252
+ description: string;
253
+ /** Whether tracks in the playlist are downloadable */
254
+ downloadable: boolean;
255
+ /** Total duration of all tracks in the playlist in milliseconds */
256
+ duration: number;
257
+ /** European Article Number (barcode) for the release */
258
+ ean: string;
259
+ /** Who can embed this playlist (e.g. "all", "me", "none") */
260
+ embeddable_by: string;
261
+ /** Music genre of the playlist */
262
+ genre: string;
263
+ /** The playlist's unique numeric ID on SoundCloud */
264
+ id: number;
265
+ /** Resource type, always "playlist" */
266
+ kind: string;
267
+ /** Label user object, or null if no label is associated */
268
+ label: SoundCloudUser | null;
269
+ /** Numeric ID of the associated label, or null */
270
+ label_id: number | null;
271
+ /** Name of the associated record label */
272
+ label_name: string;
273
+ /** ISO 8601 timestamp of the last modification */
274
+ last_modified: string;
275
+ /** Creative Commons license type */
276
+ license: string;
277
+ /** Total number of likes on this playlist */
278
+ likes_count: number;
279
+ /** URL-friendly slug for the playlist */
280
+ permalink: string;
281
+ /** Full URL to the playlist's SoundCloud page */
282
+ permalink_url: string;
283
+ /** Type of playlist (e.g. "album", "ep", "compilation") */
284
+ playlist_type: string;
285
+ /** Label for the purchase/buy button */
286
+ purchase_title: string;
287
+ /** External purchase URL */
288
+ purchase_url: string;
289
+ /** Release identifier string */
290
+ release: string;
291
+ /** Day of the release date (1-31) */
292
+ release_day: number;
293
+ /** Month of the release date (1-12) */
294
+ release_month: number;
295
+ /** Year of the release date */
296
+ release_year: number;
297
+ /** Sharing setting: "public" or "private" */
298
+ sharing: string;
299
+ /** Whether the playlist contains streamable tracks */
300
+ streamable: boolean;
301
+ /** Space-separated list of tags */
302
+ tag_list: string;
303
+ /** Comma-separated tags string, or null */
304
+ tags: string | null;
305
+ /** The playlist's title */
306
+ title: string;
307
+ /** Total number of tracks in the playlist */
308
+ track_count: number;
309
+ /** Array of tracks in the playlist (may be empty if not fetched) */
310
+ tracks: SoundCloudTrack[];
311
+ /** API URI to fetch the playlist's tracks, or null */
312
+ tracks_uri: string | null;
313
+ /** Playlist set type (e.g. "album", "playlist") */
314
+ type: string;
315
+ /** API resource URI for this playlist */
316
+ uri: string;
317
+ /** URN identifier (e.g. "soundcloud:playlists:123") */
318
+ urn: string;
319
+ /** The user who created this playlist */
320
+ user: SoundCloudUser;
321
+ /** Numeric ID of the playlist creator */
322
+ user_id: number;
323
+ /** URN of the playlist creator */
324
+ user_urn: string;
325
+ }
326
+ /**
327
+ * Represents a comment on a SoundCloud track.
328
+ *
329
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/tracks/get_tracks__track_id__comments
330
+ */
331
+ interface SoundCloudComment {
332
+ /** The comment text body */
333
+ body: string;
334
+ /** ISO 8601 timestamp of when the comment was posted */
335
+ created_at: string;
336
+ /** The comment's unique numeric ID */
337
+ id: number;
338
+ /** Resource type, always "comment" */
339
+ kind: string;
340
+ /** Position in the track's waveform in milliseconds where the comment was placed */
341
+ timestamp: number;
342
+ /** URN of the track this comment belongs to */
343
+ track_urn: string;
344
+ /** API resource URI for this comment */
345
+ uri: string;
346
+ /** URN identifier for this comment */
347
+ urn: string;
348
+ /** The user who posted this comment */
349
+ user: SoundCloudCommentUser;
350
+ /** URN of the user who posted this comment */
351
+ user_urn: string;
352
+ }
353
+ /**
354
+ * Minimal user object embedded in comment responses.
355
+ *
356
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/tracks/get_tracks__track_id__comments
357
+ */
358
+ interface SoundCloudCommentUser {
359
+ /** URL to the user's avatar image */
360
+ avatar_url: string;
361
+ /** Total number of followers */
362
+ followers_count: number;
363
+ /** Total number of users this user is following */
364
+ followings_count: number;
365
+ /** Resource type, always "user" */
366
+ kind: string;
367
+ /** ISO 8601 timestamp of the last profile modification */
368
+ last_modified: string;
369
+ /** URL-friendly slug for the user's profile */
370
+ permalink: string;
371
+ /** Full URL to the user's SoundCloud profile page */
372
+ permalink_url: string;
373
+ /** Total number of reposts */
374
+ reposts_count: number;
375
+ /** API resource URI for this user */
376
+ uri: string;
377
+ /** URN identifier for this user */
378
+ urn: string;
379
+ /** The user's display name */
380
+ username: string;
381
+ }
382
+ /**
383
+ * Stream URLs for a SoundCloud track, containing various format options.
384
+ *
385
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/tracks/get_tracks__track_id__streams
386
+ */
387
+ interface SoundCloudStreams {
388
+ /** HLS stream URL for AAC at 160kbps (may be undefined if unavailable) */
389
+ hls_aac_160_url?: string;
390
+ /** HLS stream URL for MP3 at 128kbps (may be undefined if unavailable) */
391
+ hls_mp3_128_url?: string;
392
+ /**
393
+ * Direct HTTP MP3 stream URL at 128kbps.
394
+ * @deprecated Use HLS URLs instead; this field may not be available for all tracks.
395
+ */
396
+ http_mp3_128_url?: string;
397
+ /** Preview MP3 stream URL at 128kbps for non-full-access tracks (may be undefined) */
398
+ preview_mp3_128_url?: string;
399
+ }
400
+ /**
401
+ * An external web profile / link displayed on a user's SoundCloud page.
402
+ *
403
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/users/get_users__user_id__web_profiles
404
+ */
405
+ interface SoundCloudWebProfile {
406
+ /** ISO 8601 timestamp of when the web profile link was created */
407
+ created_at: string;
408
+ /** Resource type, always "web-profile" */
409
+ kind: string;
410
+ /** Service name (e.g. "twitter", "instagram", "personal") */
411
+ service: string;
412
+ /** Display title for this link */
413
+ title: string;
414
+ /** The external URL */
415
+ url: string;
416
+ /** URN identifier for this web profile entry */
417
+ urn: string;
418
+ /** Username on the external service */
419
+ username: string;
420
+ }
421
+ /**
422
+ * A single activity item from the user's activity feed.
423
+ *
424
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/me/get_me_activities
425
+ */
426
+ interface SoundCloudActivity {
427
+ /** Type of activity (e.g. "track", "track-repost", "playlist") */
428
+ type: string;
429
+ /** ISO 8601 timestamp of when the activity occurred */
430
+ created_at: string;
431
+ /** The track or playlist that is the subject of this activity */
432
+ origin: SoundCloudTrack | SoundCloudPlaylist;
433
+ }
434
+ /**
435
+ * Response from the activities endpoints, with polling support via `future_href`.
436
+ *
437
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/me/get_me_activities
438
+ */
439
+ interface SoundCloudActivitiesResponse {
440
+ /** Array of activity items in this page */
441
+ collection: SoundCloudActivity[];
442
+ /** URL to fetch the next page of older activities */
443
+ next_href: string;
444
+ /** URL to poll for new activities since this response */
445
+ future_href: string;
446
+ }
447
+ /**
448
+ * Generic cursor-paginated response from the SoundCloud API.
449
+ * Most list endpoints return this shape with `collection` and `next_href`.
450
+ *
451
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api
452
+ */
453
+ interface SoundCloudPaginatedResponse<T> {
454
+ /** Array of items in this page */
455
+ collection: T[];
456
+ /** URL to fetch the next page, or null/empty when there are no more pages */
457
+ next_href: string;
458
+ }
459
+ /**
460
+ * A connected external social account linked to the authenticated user's profile.
461
+ *
462
+ * @remarks This endpoint may require elevated API access or app approval.
463
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api#/me/get_me_connections
464
+ */
465
+ interface SoundCloudConnection {
466
+ /** ISO 8601 timestamp of when the connection was created */
467
+ created_at: string;
468
+ /** Unique numeric ID of this connection */
469
+ id: number;
470
+ /** Resource type, always "connection" */
471
+ kind: string;
472
+ /** Display name for this connection */
473
+ display_name: string;
474
+ /**
475
+ * External service name (e.g. "twitter", "facebook", "instagram",
476
+ * "youtube", "tumblr", "pinterest", "myspace", "flickr")
477
+ */
478
+ service: string;
479
+ /** API resource URI for this connection */
480
+ uri: string;
481
+ /** Whether posts to this service are enabled */
482
+ post_publish?: boolean;
483
+ /** Whether favorites to this service are enabled */
484
+ post_favorite?: boolean;
485
+ }
486
+
487
+ /**
488
+ * Shape of error response bodies returned by the SoundCloud API.
489
+ *
490
+ * The API returns varying combinations of these fields depending on the endpoint
491
+ * and error type. All fields are optional.
492
+ *
493
+ * @example
494
+ * ```json
495
+ * {
496
+ * "code": 401,
497
+ * "message": "invalid_client",
498
+ * "link": "https://developers.soundcloud.com/docs/api/explorer/open-api",
499
+ * "status": "401 - Unauthorized",
500
+ * "errors": [{"error_message": "invalid_client"}],
501
+ * "error": null,
502
+ * "error_code": "invalid_client"
503
+ * }
504
+ * ```
505
+ *
506
+ * @see https://developers.soundcloud.com/docs/api/explorer/open-api
507
+ */
508
+ interface SoundCloudErrorBody {
509
+ /** HTTP status code echoed in the response body */
510
+ code?: number;
511
+ /** Error message from SoundCloud (e.g. "invalid_client", "404 - Not Found") */
512
+ message?: string;
513
+ /** Human-readable status string (e.g. "401 - Unauthorized") */
514
+ status?: string;
515
+ /** Link to SoundCloud API documentation */
516
+ link?: string;
517
+ /** Array of individual error detail objects */
518
+ errors?: Array<{
519
+ error_message?: string;
520
+ }>;
521
+ /** Generic error field — typically null in SoundCloud responses */
522
+ error?: string | null;
523
+ /** Machine-readable error code (e.g. "invalid_client") */
524
+ error_code?: string;
525
+ /** OAuth error description, present in `/oauth/token` error responses */
526
+ error_description?: string;
527
+ }
528
+ /**
529
+ * Error class thrown when a SoundCloud API request fails.
530
+ *
531
+ * Provides structured access to HTTP status, error codes, and convenience
532
+ * getters for common error categories.
533
+ *
534
+ * @example
535
+ * ```ts
536
+ * import { SoundCloudError } from 'soundcloud-api-ts';
537
+ *
538
+ * try {
539
+ * await sc.tracks.getTrack(999999999);
540
+ * } catch (err) {
541
+ * if (err instanceof SoundCloudError) {
542
+ * if (err.isNotFound) console.log('Track not found');
543
+ * if (err.isRateLimited) console.log('Rate limited, retry later');
544
+ * console.log(err.status, err.message);
545
+ * }
546
+ * }
547
+ * ```
548
+ */
549
+ declare class SoundCloudError extends Error {
550
+ /** HTTP status code of the failed response (e.g. 401, 404, 429) */
551
+ readonly status: number;
552
+ /** HTTP status text of the failed response (e.g. "Unauthorized", "Not Found") */
553
+ readonly statusText: string;
554
+ /** Machine-readable error code from SoundCloud (e.g. "invalid_client"), if present */
555
+ readonly errorCode?: string;
556
+ /** Link to SoundCloud API documentation, if included in the error response */
557
+ readonly docsLink?: string;
558
+ /** Individual error messages extracted from the response body's `errors` array */
559
+ readonly errors: string[];
560
+ /** The full parsed error response body, if available */
561
+ readonly body?: SoundCloudErrorBody;
562
+ /**
563
+ * Creates a new SoundCloudError.
564
+ *
565
+ * @param status - HTTP status code
566
+ * @param statusText - HTTP status text
567
+ * @param body - Parsed JSON error response body from SoundCloud, if available
568
+ */
569
+ constructor(status: number, statusText: string, body?: SoundCloudErrorBody);
570
+ /** True if status is 401 Unauthorized (invalid or expired token) */
571
+ get isUnauthorized(): boolean;
572
+ /** True if status is 403 Forbidden (insufficient permissions) */
573
+ get isForbidden(): boolean;
574
+ /** True if status is 404 Not Found (resource does not exist) */
575
+ get isNotFound(): boolean;
576
+ /** True if status is 429 Too Many Requests (rate limit exceeded) */
577
+ get isRateLimited(): boolean;
578
+ /** True if status is 5xx (SoundCloud server error) */
579
+ get isServerError(): boolean;
580
+ }
581
+
582
+ export { type SoundCloudTrack as S, type SoundCloudPlaylist as a, type SoundCloudToken as b, type SoundCloudPaginatedResponse as c, type SoundCloudMe as d, type SoundCloudActivitiesResponse as e, type SoundCloudUser as f, type SoundCloudConnection as g, type SoundCloudWebProfile as h, type SoundCloudStreams as i, type SoundCloudComment as j, type SoundCloudActivity as k, type SoundCloudCommentUser as l, SoundCloudError as m, type SoundCloudQuota as n, type SoundCloudSubscription as o, type SoundCloudSubscriptionProduct as p };