@rivi-software/radiotools-sdk-next 0.2.0 → 0.2.2
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/README.md +44 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @rivi-software/radiotools-sdk-next
|
|
2
|
+
|
|
3
|
+
Next.js App Router server helpers for the RadioTools listener API, wrapping [`@rivi-software/radiotools-sdk`](../sdk-typescript). Generated from `@rivi-software/radiotools-contract`; do not edit `src/server.generated.ts` by hand.
|
|
4
|
+
|
|
5
|
+
The package imports `server-only`, so it can only be used in Server Components, Route Handlers and Server Actions. Your API token never reaches the browser.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @rivi-software/radiotools-sdk-next @rivi-software/radiotools-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Next.js 14.2 or newer. Set `RADIOTOOLS_BASE_URL`, `RADIOTOOLS_STATION_SLUG` and `RADIOTOOLS_API_TOKEN` in the server environment.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Server Component with caching (30 s revalidation by default):
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { cachedGetNowPlaying } from "@rivi-software/radiotools-sdk-next";
|
|
21
|
+
|
|
22
|
+
export default async function Page() {
|
|
23
|
+
const nowPlaying = await cachedGetNowPlaying();
|
|
24
|
+
return <p>{nowPlaying.track?.title}</p>;
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Route Handler:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { createRadioToolsServerClient, jsonResponseNowPlaying } from "@rivi-software/radiotools-sdk-next";
|
|
32
|
+
|
|
33
|
+
export async function GET() {
|
|
34
|
+
return jsonResponseNowPlaying(createRadioToolsServerClient());
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Exports
|
|
39
|
+
|
|
40
|
+
- `createRadioToolsServerClient(overrides?)`: client built from environment variables.
|
|
41
|
+
- `createCachedRadioToolsReader(key, read, revalidateSeconds?)`: wrap any read in `unstable_cache`.
|
|
42
|
+
- `cachedGetStation`, `cachedGetNowPlaying`, `cachedGetCurrentBroadcast`: ready-made cached readers.
|
|
43
|
+
- `fetchGet*` and `fetchRecommendedPollIntervalMs`: plain reads for a given client.
|
|
44
|
+
- `jsonResponse*`: `NextResponse` wrappers for Route Handlers.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivi-software/radiotools-sdk-next",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Next.js App Router server helpers for @rivi-software/radiotools-sdk (generated)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
33
|
-
"url": "https://github.com/
|
|
33
|
+
"url": "https://github.com/rivi-software/radiotools-sdk.git",
|
|
34
34
|
"directory": "packages/sdk-next"
|
|
35
35
|
}
|
|
36
36
|
}
|