@rocksky/sdk 0.6.0 → 0.7.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/src/client.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Client, simpleFetchHandler } from "@atcute/client";
2
2
 
3
3
  import { RockskyError } from "./errors.js";
4
+ import { RockskyLibrary } from "./library.js";
4
5
  import type {
5
6
  ActorProfileViewBasic,
6
7
  ActorProfileViewDetailed,
@@ -58,14 +59,16 @@ export const DEFAULT_APPVIEW = "https://api.rocksky.app";
58
59
  /** Unauthenticated read client over the public Rocksky AppView XRPC. */
59
60
  export class RockskyClient {
60
61
  private rpc: Client;
62
+ private token?: string;
61
63
 
62
64
  /**
63
65
  * Build a read client against an AppView base URL (defaults to
64
66
  * {@link DEFAULT_APPVIEW}). Pass `token` to send it as
65
67
  * `Authorization: Bearer <token>` on every read — needed only for auth-gated
66
- * queries.
68
+ * queries and the whole {@link RockskyClient.library} surface.
67
69
  */
68
70
  constructor(appview: string = DEFAULT_APPVIEW, token?: string) {
71
+ this.token = token;
69
72
  let handler = simpleFetchHandler({ service: appview });
70
73
  if (token) {
71
74
  const inner = handler;
@@ -78,6 +81,20 @@ export class RockskyClient {
78
81
  this.rpc = new Client({ handler });
79
82
  }
80
83
 
84
+ /**
85
+ * The authenticated `app.rocksky.library.*` (uploaded-music) API. Every
86
+ * library method requires auth, so this throws unless the client was built
87
+ * with a token.
88
+ */
89
+ library(): RockskyLibrary {
90
+ if (!this.token) {
91
+ throw new Error(
92
+ "app.rocksky.library.* requires an access token; construct RockskyClient(appview, token) first",
93
+ );
94
+ }
95
+ return new RockskyLibrary(this.rpc);
96
+ }
97
+
81
98
  private async query<T>(nsid: string, params: Record<string, unknown>): Promise<T> {
82
99
  const clean: Record<string, unknown> = {};
83
100
  for (const [k, v] of Object.entries(params)) {