@rocksky/sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +279 -0
- package/dist/client.d.ts +107 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/http.d.ts +28 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1492 -0
- package/dist/namespaces/_helpers.d.ts +9 -0
- package/dist/namespaces/_helpers.d.ts.map +1 -0
- package/dist/namespaces/actor.d.ts +30 -0
- package/dist/namespaces/actor.d.ts.map +1 -0
- package/dist/namespaces/album.d.ts +18 -0
- package/dist/namespaces/album.d.ts.map +1 -0
- package/dist/namespaces/apikey.d.ts +27 -0
- package/dist/namespaces/apikey.d.ts.map +1 -0
- package/dist/namespaces/artist.d.ts +31 -0
- package/dist/namespaces/artist.d.ts.map +1 -0
- package/dist/namespaces/charts.d.ts +25 -0
- package/dist/namespaces/charts.d.ts.map +1 -0
- package/dist/namespaces/dropbox.d.ts +19 -0
- package/dist/namespaces/dropbox.d.ts.map +1 -0
- package/dist/namespaces/feed.d.ts +38 -0
- package/dist/namespaces/feed.d.ts.map +1 -0
- package/dist/namespaces/googledrive.d.ts +16 -0
- package/dist/namespaces/googledrive.d.ts.map +1 -0
- package/dist/namespaces/graph.d.ts +28 -0
- package/dist/namespaces/graph.d.ts.map +1 -0
- package/dist/namespaces/like.d.ts +14 -0
- package/dist/namespaces/like.d.ts.map +1 -0
- package/dist/namespaces/mirror.d.ts +15 -0
- package/dist/namespaces/mirror.d.ts.map +1 -0
- package/dist/namespaces/player.d.ts +41 -0
- package/dist/namespaces/player.d.ts.map +1 -0
- package/dist/namespaces/playlist.d.ts +40 -0
- package/dist/namespaces/playlist.d.ts.map +1 -0
- package/dist/namespaces/scrobble.d.ts +43 -0
- package/dist/namespaces/scrobble.d.ts.map +1 -0
- package/dist/namespaces/shout.d.ts +38 -0
- package/dist/namespaces/shout.d.ts.map +1 -0
- package/dist/namespaces/song.d.ts +48 -0
- package/dist/namespaces/song.d.ts.map +1 -0
- package/dist/namespaces/spotify.d.ts +17 -0
- package/dist/namespaces/spotify.d.ts.map +1 -0
- package/dist/namespaces/stats.d.ts +14 -0
- package/dist/namespaces/stats.d.ts.map +1 -0
- package/dist/paginate.d.ts +38 -0
- package/dist/paginate.d.ts.map +1 -0
- package/dist/pipe.d.ts +36 -0
- package/dist/pipe.d.ts.map +1 -0
- package/dist/realtime.d.ts +144 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +65 -0
- package/src/client.ts +235 -0
- package/src/errors.ts +47 -0
- package/src/http.ts +195 -0
- package/src/index.ts +85 -0
- package/src/namespaces/_helpers.ts +17 -0
- package/src/namespaces/actor.ts +89 -0
- package/src/namespaces/album.ts +34 -0
- package/src/namespaces/apikey.ts +50 -0
- package/src/namespaces/artist.ts +74 -0
- package/src/namespaces/charts.ts +47 -0
- package/src/namespaces/dropbox.ts +47 -0
- package/src/namespaces/feed.ts +106 -0
- package/src/namespaces/googledrive.ts +36 -0
- package/src/namespaces/graph.ts +63 -0
- package/src/namespaces/like.ts +40 -0
- package/src/namespaces/mirror.ts +31 -0
- package/src/namespaces/player.ts +127 -0
- package/src/namespaces/playlist.ts +85 -0
- package/src/namespaces/scrobble.ts +67 -0
- package/src/namespaces/shout.ts +90 -0
- package/src/namespaces/song.ts +81 -0
- package/src/namespaces/spotify.ts +52 -0
- package/src/namespaces/stats.ts +23 -0
- package/src/paginate.ts +90 -0
- package/src/pipe.ts +146 -0
- package/src/realtime.ts +408 -0
- package/src/types.ts +41 -0
package/src/http.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RockskyAuthError,
|
|
3
|
+
RockskyHttpError,
|
|
4
|
+
RockskyTimeoutError,
|
|
5
|
+
} from "./errors";
|
|
6
|
+
import {
|
|
7
|
+
type AuthProvider,
|
|
8
|
+
DEFAULT_BASE_URL,
|
|
9
|
+
type FetchLike,
|
|
10
|
+
type RequestOptions,
|
|
11
|
+
} from "./types";
|
|
12
|
+
|
|
13
|
+
export type XrpcCallOptions = RequestOptions & {
|
|
14
|
+
params?: Record<string, unknown>;
|
|
15
|
+
body?: unknown;
|
|
16
|
+
requireAuth?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type HttpClientConfig = {
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
auth?: AuthProvider;
|
|
22
|
+
fetch: FetchLike;
|
|
23
|
+
headers: Record<string, string>;
|
|
24
|
+
timeoutMs: number;
|
|
25
|
+
retries: number;
|
|
26
|
+
retryDelayMs: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function buildConfig(opts: {
|
|
30
|
+
baseUrl?: string;
|
|
31
|
+
auth?: AuthProvider;
|
|
32
|
+
fetch?: FetchLike;
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
retries?: number;
|
|
36
|
+
retryDelayMs?: number;
|
|
37
|
+
userAgent?: string;
|
|
38
|
+
}): HttpClientConfig {
|
|
39
|
+
const headers: Record<string, string> = {
|
|
40
|
+
accept: "application/json",
|
|
41
|
+
...(opts.userAgent ? { "user-agent": opts.userAgent } : {}),
|
|
42
|
+
...(opts.headers ?? {}),
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
baseUrl: stripTrailingSlash(opts.baseUrl ?? DEFAULT_BASE_URL),
|
|
46
|
+
auth: opts.auth,
|
|
47
|
+
fetch: opts.fetch ?? globalThis.fetch.bind(globalThis),
|
|
48
|
+
headers,
|
|
49
|
+
timeoutMs: opts.timeoutMs ?? 30_000,
|
|
50
|
+
retries: opts.retries ?? 0,
|
|
51
|
+
retryDelayMs: opts.retryDelayMs ?? 300,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function stripTrailingSlash(url: string): string {
|
|
56
|
+
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function resolveAuth(
|
|
60
|
+
provider: AuthProvider | undefined | null,
|
|
61
|
+
): Promise<string | undefined> {
|
|
62
|
+
if (provider == null) return undefined;
|
|
63
|
+
if (typeof provider === "string") return provider;
|
|
64
|
+
return await provider();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function serializeParams(
|
|
68
|
+
params: Record<string, unknown> | undefined,
|
|
69
|
+
): string {
|
|
70
|
+
if (!params) return "";
|
|
71
|
+
const usp = new URLSearchParams();
|
|
72
|
+
for (const [k, v] of Object.entries(params)) {
|
|
73
|
+
if (v == null) continue;
|
|
74
|
+
if (Array.isArray(v)) {
|
|
75
|
+
for (const item of v) {
|
|
76
|
+
if (item == null) continue;
|
|
77
|
+
usp.append(k, String(item));
|
|
78
|
+
}
|
|
79
|
+
} else if (typeof v === "boolean") {
|
|
80
|
+
usp.append(k, v ? "true" : "false");
|
|
81
|
+
} else {
|
|
82
|
+
usp.append(k, String(v));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const s = usp.toString();
|
|
86
|
+
return s ? `?${s}` : "";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function xrpcCall<T>(
|
|
90
|
+
config: HttpClientConfig,
|
|
91
|
+
nsid: string,
|
|
92
|
+
method: "GET" | "POST",
|
|
93
|
+
opts: XrpcCallOptions = {},
|
|
94
|
+
): Promise<T> {
|
|
95
|
+
const url =
|
|
96
|
+
`${config.baseUrl}/xrpc/${nsid}` + serializeParams(opts.params);
|
|
97
|
+
|
|
98
|
+
const timeoutMs = opts.timeoutMs ?? config.timeoutMs;
|
|
99
|
+
const retries = opts.retries ?? config.retries;
|
|
100
|
+
|
|
101
|
+
const headers: Record<string, string> = {
|
|
102
|
+
...config.headers,
|
|
103
|
+
...(opts.headers ?? {}),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const authProvider = opts.auth === undefined ? config.auth : opts.auth;
|
|
107
|
+
const token = await resolveAuth(authProvider);
|
|
108
|
+
if (token) {
|
|
109
|
+
headers.authorization = `Bearer ${token}`;
|
|
110
|
+
} else if (opts.requireAuth) {
|
|
111
|
+
throw new RockskyAuthError(
|
|
112
|
+
`${nsid} requires authentication — provide an "auth" token`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const init: RequestInit = {
|
|
117
|
+
method,
|
|
118
|
+
headers,
|
|
119
|
+
signal: opts.signal,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
if (method === "POST" && opts.body !== undefined) {
|
|
123
|
+
headers["content-type"] = "application/json";
|
|
124
|
+
init.body = JSON.stringify(opts.body);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let lastErr: unknown;
|
|
128
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
129
|
+
try {
|
|
130
|
+
return await runOnce<T>(config.fetch, url, init, timeoutMs);
|
|
131
|
+
} catch (err) {
|
|
132
|
+
lastErr = err;
|
|
133
|
+
if (!isRetryable(err) || attempt === retries) throw err;
|
|
134
|
+
await sleep(config.retryDelayMs * Math.pow(2, attempt));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
throw lastErr;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function runOnce<T>(
|
|
141
|
+
fetchImpl: FetchLike,
|
|
142
|
+
url: string,
|
|
143
|
+
init: RequestInit,
|
|
144
|
+
timeoutMs: number,
|
|
145
|
+
): Promise<T> {
|
|
146
|
+
const controller = new AbortController();
|
|
147
|
+
const upstream = init.signal;
|
|
148
|
+
const onAbort = () => controller.abort(upstream?.reason);
|
|
149
|
+
upstream?.addEventListener("abort", onAbort, { once: true });
|
|
150
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
151
|
+
try {
|
|
152
|
+
const res = await fetchImpl(url, { ...init, signal: controller.signal });
|
|
153
|
+
const text = await res.text();
|
|
154
|
+
const body = parseMaybeJson(text);
|
|
155
|
+
if (!res.ok) {
|
|
156
|
+
throw new RockskyHttpError({
|
|
157
|
+
status: res.status,
|
|
158
|
+
statusText: res.statusText,
|
|
159
|
+
url,
|
|
160
|
+
body,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return body as T;
|
|
164
|
+
} catch (err) {
|
|
165
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
166
|
+
if (upstream?.aborted) throw err;
|
|
167
|
+
throw new RockskyTimeoutError(timeoutMs);
|
|
168
|
+
}
|
|
169
|
+
throw err;
|
|
170
|
+
} finally {
|
|
171
|
+
clearTimeout(timer);
|
|
172
|
+
upstream?.removeEventListener("abort", onAbort);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function parseMaybeJson(text: string): unknown {
|
|
177
|
+
if (!text) return null;
|
|
178
|
+
try {
|
|
179
|
+
return JSON.parse(text);
|
|
180
|
+
} catch {
|
|
181
|
+
return text;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function isRetryable(err: unknown): boolean {
|
|
186
|
+
if (err instanceof RockskyTimeoutError) return true;
|
|
187
|
+
if (err instanceof RockskyHttpError) {
|
|
188
|
+
return err.status >= 500 || err.status === 429;
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function sleep(ms: number): Promise<void> {
|
|
194
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
195
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export {
|
|
2
|
+
RockskyClient,
|
|
3
|
+
RockskyClientBuilder,
|
|
4
|
+
createClient,
|
|
5
|
+
} from "./client";
|
|
6
|
+
export {
|
|
7
|
+
RockskyError,
|
|
8
|
+
RockskyHttpError,
|
|
9
|
+
RockskyTimeoutError,
|
|
10
|
+
RockskyAuthError,
|
|
11
|
+
} from "./errors";
|
|
12
|
+
export {
|
|
13
|
+
pipe,
|
|
14
|
+
map,
|
|
15
|
+
tap,
|
|
16
|
+
withRetry,
|
|
17
|
+
withTimeout,
|
|
18
|
+
withFallback,
|
|
19
|
+
catchError,
|
|
20
|
+
type Op,
|
|
21
|
+
} from "./pipe";
|
|
22
|
+
export {
|
|
23
|
+
DEFAULT_BASE_URL,
|
|
24
|
+
type AuthProvider,
|
|
25
|
+
type ClientOptions,
|
|
26
|
+
type FetchLike,
|
|
27
|
+
type Json,
|
|
28
|
+
type Pagination,
|
|
29
|
+
type RequestOptions,
|
|
30
|
+
} from "./types";
|
|
31
|
+
export {
|
|
32
|
+
paginate,
|
|
33
|
+
type PageOpts,
|
|
34
|
+
type PageResult,
|
|
35
|
+
type PaginateArgs,
|
|
36
|
+
} from "./paginate";
|
|
37
|
+
export {
|
|
38
|
+
RealtimeClient,
|
|
39
|
+
RealtimeClientBuilder,
|
|
40
|
+
createRealtimeClient,
|
|
41
|
+
type RealtimeOptions,
|
|
42
|
+
type RealtimeEvent,
|
|
43
|
+
type RealtimeEventMap,
|
|
44
|
+
type ReconnectOptions,
|
|
45
|
+
type WebSocketCtor,
|
|
46
|
+
type WebSocketLike,
|
|
47
|
+
} from "./realtime";
|
|
48
|
+
|
|
49
|
+
export type {
|
|
50
|
+
GetProfileParams,
|
|
51
|
+
ActorPagedParams,
|
|
52
|
+
ActorRangeParams,
|
|
53
|
+
} from "./namespaces/actor";
|
|
54
|
+
export type {
|
|
55
|
+
CreateScrobbleInput,
|
|
56
|
+
GetScrobblesParams,
|
|
57
|
+
} from "./namespaces/scrobble";
|
|
58
|
+
export type {
|
|
59
|
+
GetSongParams,
|
|
60
|
+
GetSongsParams,
|
|
61
|
+
MatchSongParams,
|
|
62
|
+
CreateSongInput,
|
|
63
|
+
} from "./namespaces/song";
|
|
64
|
+
export type { GetAlbumsParams } from "./namespaces/album";
|
|
65
|
+
export type {
|
|
66
|
+
GetArtistsParams,
|
|
67
|
+
ArtistListenersParams,
|
|
68
|
+
GetArtistTracksParams,
|
|
69
|
+
} from "./namespaces/artist";
|
|
70
|
+
export type {
|
|
71
|
+
ListApikeysParams,
|
|
72
|
+
CreateApikeyInput,
|
|
73
|
+
UpdateApikeyInput,
|
|
74
|
+
} from "./namespaces/apikey";
|
|
75
|
+
export type {
|
|
76
|
+
ScrobblesChartParams,
|
|
77
|
+
TopChartParams,
|
|
78
|
+
} from "./namespaces/charts";
|
|
79
|
+
export type {
|
|
80
|
+
FollowListParams,
|
|
81
|
+
KnownFollowersParams,
|
|
82
|
+
} from "./namespaces/graph";
|
|
83
|
+
export type { RecommendParams } from "./namespaces/feed";
|
|
84
|
+
export type { LikeInput } from "./namespaces/like";
|
|
85
|
+
export type { PutMirrorSourceInput } from "./namespaces/mirror";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type HttpClientConfig, xrpcCall } from "../http";
|
|
2
|
+
import type { RequestOptions } from "../types";
|
|
3
|
+
|
|
4
|
+
export type Call = <T>(
|
|
5
|
+
nsid: string,
|
|
6
|
+
method: "GET" | "POST",
|
|
7
|
+
opts?: {
|
|
8
|
+
params?: Record<string, unknown>;
|
|
9
|
+
body?: unknown;
|
|
10
|
+
requireAuth?: boolean;
|
|
11
|
+
} & RequestOptions,
|
|
12
|
+
) => Promise<T>;
|
|
13
|
+
|
|
14
|
+
export function makeCall(config: HttpClientConfig): Call {
|
|
15
|
+
return (nsid, method, opts) =>
|
|
16
|
+
xrpcCall(config, nsid, method, opts ?? {});
|
|
17
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Call } from "./_helpers";
|
|
2
|
+
import type { RequestOptions } from "../types";
|
|
3
|
+
|
|
4
|
+
export type GetProfileParams = { did?: string };
|
|
5
|
+
export type DidParam = { did: string };
|
|
6
|
+
export type ActorPagedParams = DidParam & {
|
|
7
|
+
limit?: number;
|
|
8
|
+
offset?: number;
|
|
9
|
+
};
|
|
10
|
+
export type ActorRangeParams = ActorPagedParams & {
|
|
11
|
+
startDate?: string;
|
|
12
|
+
endDate?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export class ActorNamespace {
|
|
16
|
+
constructor(private readonly call: Call) {}
|
|
17
|
+
|
|
18
|
+
getProfile<T = unknown>(params: GetProfileParams = {}, opts?: RequestOptions) {
|
|
19
|
+
return this.call<T>("app.rocksky.actor.getProfile", "GET", {
|
|
20
|
+
params,
|
|
21
|
+
...opts,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getActorAlbums<T = unknown>(params: ActorRangeParams, opts?: RequestOptions) {
|
|
26
|
+
return this.call<T>("app.rocksky.actor.getActorAlbums", "GET", {
|
|
27
|
+
params,
|
|
28
|
+
...opts,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getActorArtists<T = unknown>(params: ActorRangeParams, opts?: RequestOptions) {
|
|
33
|
+
return this.call<T>("app.rocksky.actor.getActorArtists", "GET", {
|
|
34
|
+
params,
|
|
35
|
+
...opts,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getActorSongs<T = unknown>(params: ActorRangeParams, opts?: RequestOptions) {
|
|
40
|
+
return this.call<T>("app.rocksky.actor.getActorSongs", "GET", {
|
|
41
|
+
params,
|
|
42
|
+
...opts,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getActorScrobbles<T = unknown>(
|
|
47
|
+
params: ActorPagedParams,
|
|
48
|
+
opts?: RequestOptions,
|
|
49
|
+
) {
|
|
50
|
+
return this.call<T>("app.rocksky.actor.getActorScrobbles", "GET", {
|
|
51
|
+
params,
|
|
52
|
+
...opts,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getActorLovedSongs<T = unknown>(
|
|
57
|
+
params: ActorPagedParams,
|
|
58
|
+
opts?: RequestOptions,
|
|
59
|
+
) {
|
|
60
|
+
return this.call<T>("app.rocksky.actor.getActorLovedSongs", "GET", {
|
|
61
|
+
params,
|
|
62
|
+
...opts,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getActorPlaylists<T = unknown>(
|
|
67
|
+
params: ActorPagedParams,
|
|
68
|
+
opts?: RequestOptions,
|
|
69
|
+
) {
|
|
70
|
+
return this.call<T>("app.rocksky.actor.getActorPlaylists", "GET", {
|
|
71
|
+
params,
|
|
72
|
+
...opts,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getActorNeighbours<T = unknown>(params: DidParam, opts?: RequestOptions) {
|
|
77
|
+
return this.call<T>("app.rocksky.actor.getActorNeighbours", "GET", {
|
|
78
|
+
params,
|
|
79
|
+
...opts,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getActorCompatibility<T = unknown>(params: DidParam, opts?: RequestOptions) {
|
|
84
|
+
return this.call<T>("app.rocksky.actor.getActorCompatibility", "GET", {
|
|
85
|
+
params,
|
|
86
|
+
...opts,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Call } from "./_helpers";
|
|
2
|
+
import type { RequestOptions } from "../types";
|
|
3
|
+
|
|
4
|
+
export type UriParam = { uri: string };
|
|
5
|
+
export type GetAlbumsParams = {
|
|
6
|
+
limit?: number;
|
|
7
|
+
offset?: number;
|
|
8
|
+
genre?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export class AlbumNamespace {
|
|
12
|
+
constructor(private readonly call: Call) {}
|
|
13
|
+
|
|
14
|
+
getAlbum<T = unknown>(params: UriParam, opts?: RequestOptions) {
|
|
15
|
+
return this.call<T>("app.rocksky.album.getAlbum", "GET", {
|
|
16
|
+
params,
|
|
17
|
+
...opts,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getAlbums<T = unknown>(params: GetAlbumsParams = {}, opts?: RequestOptions) {
|
|
22
|
+
return this.call<T>("app.rocksky.album.getAlbums", "GET", {
|
|
23
|
+
params,
|
|
24
|
+
...opts,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getAlbumTracks<T = unknown>(params: UriParam, opts?: RequestOptions) {
|
|
29
|
+
return this.call<T>("app.rocksky.album.getAlbumTracks", "GET", {
|
|
30
|
+
params,
|
|
31
|
+
...opts,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Call } from "./_helpers";
|
|
2
|
+
import type { RequestOptions } from "../types";
|
|
3
|
+
|
|
4
|
+
export type ListApikeysParams = { limit?: number; offset?: number };
|
|
5
|
+
export type CreateApikeyInput = { name: string; description?: string };
|
|
6
|
+
export type UpdateApikeyInput = {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
};
|
|
11
|
+
export type RemoveApikeyParams = { id: string };
|
|
12
|
+
|
|
13
|
+
export class ApikeyNamespace {
|
|
14
|
+
constructor(private readonly call: Call) {}
|
|
15
|
+
|
|
16
|
+
getApikeys<T = unknown>(
|
|
17
|
+
params: ListApikeysParams = {},
|
|
18
|
+
opts?: RequestOptions,
|
|
19
|
+
) {
|
|
20
|
+
return this.call<T>("app.rocksky.apikey.getApikeys", "GET", {
|
|
21
|
+
params,
|
|
22
|
+
requireAuth: true,
|
|
23
|
+
...opts,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
createApikey<T = unknown>(input: CreateApikeyInput, opts?: RequestOptions) {
|
|
28
|
+
return this.call<T>("app.rocksky.apikey.createApikey", "POST", {
|
|
29
|
+
body: input,
|
|
30
|
+
requireAuth: true,
|
|
31
|
+
...opts,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
updateApikey<T = unknown>(input: UpdateApikeyInput, opts?: RequestOptions) {
|
|
36
|
+
return this.call<T>("app.rocksky.apikey.updateApikey", "POST", {
|
|
37
|
+
body: input,
|
|
38
|
+
requireAuth: true,
|
|
39
|
+
...opts,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
removeApikey<T = unknown>(params: RemoveApikeyParams, opts?: RequestOptions) {
|
|
44
|
+
return this.call<T>("app.rocksky.apikey.removeApikey", "POST", {
|
|
45
|
+
params,
|
|
46
|
+
requireAuth: true,
|
|
47
|
+
...opts,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Call } from "./_helpers";
|
|
2
|
+
import type { RequestOptions } from "../types";
|
|
3
|
+
|
|
4
|
+
export type UriParam = { uri: string };
|
|
5
|
+
export type ArtistListenersParams = UriParam & {
|
|
6
|
+
limit?: number;
|
|
7
|
+
offset?: number;
|
|
8
|
+
};
|
|
9
|
+
export type GetArtistsParams = {
|
|
10
|
+
limit?: number;
|
|
11
|
+
offset?: number;
|
|
12
|
+
names?: string;
|
|
13
|
+
genre?: string;
|
|
14
|
+
};
|
|
15
|
+
export type GetArtistTracksParams = {
|
|
16
|
+
uri?: string;
|
|
17
|
+
limit?: number;
|
|
18
|
+
offset?: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export class ArtistNamespace {
|
|
22
|
+
constructor(private readonly call: Call) {}
|
|
23
|
+
|
|
24
|
+
getArtist<T = unknown>(params: UriParam, opts?: RequestOptions) {
|
|
25
|
+
return this.call<T>("app.rocksky.artist.getArtist", "GET", {
|
|
26
|
+
params,
|
|
27
|
+
...opts,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getArtists<T = unknown>(params: GetArtistsParams = {}, opts?: RequestOptions) {
|
|
32
|
+
return this.call<T>("app.rocksky.artist.getArtists", "GET", {
|
|
33
|
+
params,
|
|
34
|
+
...opts,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getArtistAlbums<T = unknown>(params: UriParam, opts?: RequestOptions) {
|
|
39
|
+
return this.call<T>("app.rocksky.artist.getArtistAlbums", "GET", {
|
|
40
|
+
params,
|
|
41
|
+
...opts,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getArtistTracks<T = unknown>(
|
|
46
|
+
params: GetArtistTracksParams = {},
|
|
47
|
+
opts?: RequestOptions,
|
|
48
|
+
) {
|
|
49
|
+
return this.call<T>("app.rocksky.artist.getArtistTracks", "GET", {
|
|
50
|
+
params,
|
|
51
|
+
...opts,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getArtistListeners<T = unknown>(
|
|
56
|
+
params: ArtistListenersParams,
|
|
57
|
+
opts?: RequestOptions,
|
|
58
|
+
) {
|
|
59
|
+
return this.call<T>("app.rocksky.artist.getArtistListeners", "GET", {
|
|
60
|
+
params,
|
|
61
|
+
...opts,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getArtistRecentListeners<T = unknown>(
|
|
66
|
+
params: ArtistListenersParams,
|
|
67
|
+
opts?: RequestOptions,
|
|
68
|
+
) {
|
|
69
|
+
return this.call<T>("app.rocksky.artist.getArtistRecentListeners", "GET", {
|
|
70
|
+
params,
|
|
71
|
+
...opts,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Call } from "./_helpers";
|
|
2
|
+
import type { RequestOptions } from "../types";
|
|
3
|
+
|
|
4
|
+
export type ScrobblesChartParams = {
|
|
5
|
+
did?: string;
|
|
6
|
+
artisturi?: string;
|
|
7
|
+
albumuri?: string;
|
|
8
|
+
songuri?: string;
|
|
9
|
+
genre?: string;
|
|
10
|
+
from?: string;
|
|
11
|
+
to?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type TopChartParams = {
|
|
15
|
+
limit?: number;
|
|
16
|
+
offset?: number;
|
|
17
|
+
startDate?: string;
|
|
18
|
+
endDate?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export class ChartsNamespace {
|
|
22
|
+
constructor(private readonly call: Call) {}
|
|
23
|
+
|
|
24
|
+
getScrobblesChart<T = unknown>(
|
|
25
|
+
params: ScrobblesChartParams = {},
|
|
26
|
+
opts?: RequestOptions,
|
|
27
|
+
) {
|
|
28
|
+
return this.call<T>("app.rocksky.charts.getScrobblesChart", "GET", {
|
|
29
|
+
params,
|
|
30
|
+
...opts,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getTopArtists<T = unknown>(params: TopChartParams = {}, opts?: RequestOptions) {
|
|
35
|
+
return this.call<T>("app.rocksky.charts.getTopArtists", "GET", {
|
|
36
|
+
params,
|
|
37
|
+
...opts,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getTopTracks<T = unknown>(params: TopChartParams = {}, opts?: RequestOptions) {
|
|
42
|
+
return this.call<T>("app.rocksky.charts.getTopTracks", "GET", {
|
|
43
|
+
params,
|
|
44
|
+
...opts,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Call } from "./_helpers";
|
|
2
|
+
import type { RequestOptions } from "../types";
|
|
3
|
+
|
|
4
|
+
export class DropboxNamespace {
|
|
5
|
+
constructor(private readonly call: Call) {}
|
|
6
|
+
|
|
7
|
+
getFiles<T = unknown>(
|
|
8
|
+
params: { at?: string } = {},
|
|
9
|
+
opts?: RequestOptions,
|
|
10
|
+
) {
|
|
11
|
+
return this.call<T>("app.rocksky.dropbox.getFiles", "GET", {
|
|
12
|
+
params,
|
|
13
|
+
requireAuth: true,
|
|
14
|
+
...opts,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getMetadata<T = unknown>(params: { path: string }, opts?: RequestOptions) {
|
|
19
|
+
return this.call<T>("app.rocksky.dropbox.getMetadata", "GET", {
|
|
20
|
+
params,
|
|
21
|
+
requireAuth: true,
|
|
22
|
+
...opts,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getTemporaryLink<T = unknown>(
|
|
27
|
+
params: { path: string },
|
|
28
|
+
opts?: RequestOptions,
|
|
29
|
+
) {
|
|
30
|
+
return this.call<T>("app.rocksky.dropbox.getTemporaryLink", "GET", {
|
|
31
|
+
params,
|
|
32
|
+
requireAuth: true,
|
|
33
|
+
...opts,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
downloadFile<T = unknown>(
|
|
38
|
+
params: { fileId: string },
|
|
39
|
+
opts?: RequestOptions,
|
|
40
|
+
) {
|
|
41
|
+
return this.call<T>("app.rocksky.dropbox.downloadFile", "GET", {
|
|
42
|
+
params,
|
|
43
|
+
requireAuth: true,
|
|
44
|
+
...opts,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|