jellyfin-sdk-typescript/README.md

142 lines
5.4 KiB
Markdown
Raw Normal View History

2021-09-20 18:25:35 +00:00
<h1 align="center">jellyfin-sdk-typescript</h1>
2022-06-28 14:37:11 +00:00
<h3 align="center">Part of the <a href="https://jellyfin.org">Jellyfin Project</a></h3>
---
2021-09-20 18:25:35 +00:00
<p align="center">
2022-06-28 14:37:11 +00:00
<img alt="Logo Banner" src="https://raw.githubusercontent.com/jellyfin/jellyfin-ux/master/branding/SVG/banner-logo-solid.svg?sanitize=true"/>
<br/>
<br/>
<a href="https://github.com/jellyfin/jellyfin-sdk-typescript/blob/master/LICENSE"><img alt="MPL-2.0 license" src="https://img.shields.io/github/license/jellyfin/jellyfin-sdk-typescript"></a>
<a href="https://github.com/jellyfin/jellyfin-sdk-typescript/releases"><img alt="Current Release" src="https://img.shields.io/github/release/jellyfin/jellyfin-sdk-typescript.svg"/></a>
2022-09-15 04:36:44 +00:00
<a href="https://www.npmjs.com/package/@jellyfin/sdk"><img alt="npm" src="https://img.shields.io/npm/v/@jellyfin/sdk"></a>
2022-06-28 14:42:55 +00:00
<a href="https://codecov.io/gh/jellyfin/jellyfin-sdk-typescript">
<img alt="Codecov" src="https://img.shields.io/codecov/c/github/jellyfin/jellyfin-sdk-typescript?token=eFF0jvWiyq">
2021-09-20 18:25:35 +00:00
</a>
</p>
2021-09-14 05:20:14 +00:00
2021-09-14 05:44:53 +00:00
A TypeScript SDK for Jellyfin.
> Warning: This project is under active development, so API changes may occur.
2021-09-14 05:44:53 +00:00
2021-09-20 18:29:00 +00:00
## Install
```sh
2022-09-15 04:36:44 +00:00
npm i --save @jellyfin/sdk
2021-09-20 18:29:00 +00:00
```
or
```sh
2022-09-15 04:36:44 +00:00
yarn add @jellyfin/sdk
2021-09-20 18:29:00 +00:00
```
### Supported Jellyfin Versions
| SDK Version | Jellyfin Version |
|:-:|:-:|
| 0.7.0 | 10.8.1+ |
2022-07-14 17:46:51 +00:00
| 0.6.0 | 10.8.1 |
| 0.5.0 | 10.8.0 |
| <0.5.0 | 10.7.x |
> Note: Versions prior to 0.7.0 were published as `@thornbill/jellyfin-sdk`.
### React Native
The generated Axios client used in this library depends on `URL` and `URLSearchParams` to be available on the global scope.
React Native only includes incomplete implementations for these classes, so a polyfill is required.
2021-10-15 20:46:40 +00:00
[React Native URL Polyfill](https://github.com/charpeni/react-native-url-polyfill) seems like a good solution for this.
2021-09-14 05:20:14 +00:00
## Usage
```js
// Create a new instance of the SDK
2021-09-16 21:32:35 +00:00
const jellyfin = new Jellyfin({
clientInfo: {
name: 'My Client Application',
version: '1.0.0'
},
deviceInfo: {
name: 'Device Name',
id: 'unique-device-id'
}
});
2021-09-22 02:55:05 +00:00
// Find a valid server by trying to connect using common protocols and ports.
// Each server receives a score based on security, speed, and other criteria.
const servers = await jellyfin.discovery.getRecommendedServerCandidates('demo.jellyfin.org/stable');
// A utility function for finding the best result is available.
// If there is no "best" server, an error message should be displayed.
const best = jellyfin.discovery.findBestServer(servers);
// Create an API instance
const api = jellyfin.createApi(best.address);
2021-09-14 05:20:14 +00:00
// Each API endpoint is exposed via a getter on the SDK instance using
// a shared Configuration and Axios instance. For example the /System APIs
2021-09-15 05:30:55 +00:00
// are available as api.systemApi.
2021-09-14 05:20:14 +00:00
// Fetch the public system info
const info = await getSystemApi(api).getPublicSystemInfo();
2021-09-14 05:20:14 +00:00
console.log('Info =>', info.data);
// Fetch the list of public users
const users = await getUserApi(api).getPublicUsers();
2021-09-14 05:20:14 +00:00
console.log('Users =>', users.data);
// A helper method for authentication has been added to the SDK because
// the default method exposed in the generated Axios client is rather
// cumbersome to use.
2021-09-21 14:30:24 +00:00
const auth = await api.authenticateUserByName('demo', '');
2021-09-14 05:20:14 +00:00
console.log('Auth =>', auth.data);
2021-09-16 21:41:17 +00:00
// Authentication state is stored internally in the Api class, so now
// requests that require authentication can be made normally
const libraries = await getLibraryApi(api).getMediaFolders();
2021-09-16 21:41:17 +00:00
console.log('Libraries =>', libraries.data);
2021-09-21 14:18:49 +00:00
// A helper method for logging out the current user has been added to the
// SDK so the internal state is updated correctly.
await api.logout();
2021-09-14 05:20:14 +00:00
```
2021-10-18 15:00:27 +00:00
2022-06-17 18:33:08 +00:00
## Breaking Changes
### v0.7.0
* Renamed package to @jellyfin/sdk.
[#262](https://github.com/jellyfin/jellyfin-sdk-typescript/pull/262)
2022-07-14 17:46:51 +00:00
### v0.6.0
* Updated OpenAPI spec for Jellyfin 10.8.1.
[#208](https://github.com/jellyfin/jellyfin-sdk-typescript/pull/208)
2022-06-17 18:33:08 +00:00
### v0.5.0
* Build directory is now `lib` instead of `dist`.
Any imports used that were previously in `dist` will need updated.
2022-06-28 14:37:11 +00:00
[#147](https://github.com/jellyfin/jellyfin-sdk-typescript/pull/147)
2022-06-17 18:33:08 +00:00
* Duplicated exports were removed.
Any imports may need updated if you referenced one of the duplicates.
2022-06-28 14:37:11 +00:00
[#148](https://github.com/jellyfin/jellyfin-sdk-typescript/pull/148)
2022-06-17 18:33:08 +00:00
* API classes are no longer exposed via getters.
Instead you need to call a function passing the `Api` instance as a parameter.
For example: `getSystemApi(api)`.
While I do feel this is a slightly worse developer experience, it was a necessary change to support tree-shaking.
2022-06-28 14:37:11 +00:00
[#149](https://github.com/jellyfin/jellyfin-sdk-typescript/pull/149)
2022-06-17 18:33:08 +00:00
* `BaseItemKind` is now included in the generated client.
Imports will need updated.
2022-06-28 14:37:11 +00:00
[#187](https://github.com/jellyfin/jellyfin-sdk-typescript/pull/187)
2022-06-17 18:33:08 +00:00
2021-10-18 15:00:27 +00:00
## Roadmap to 1.0
* [ ] More complete device profile generation utilities
* [x] Use custom generator templates for API versions [#231](https://github.com/jellyfin/jellyfin-sdk-typescript/pull/231) (Currently uses sed to update the value could be improved.)
* [x] Automate OpenAPI spec updates using GitHub
* [ ] Create branch tracking unstable Jellyfin builds with automated builds
* [ ] Fix authentication header escaping
* [ ] Add exmple projects for different ecosystems [#186](https://github.com/jellyfin/jellyfin-sdk-typescript/issues/186)
* [ ] Add utility function for `getFile` [#164](https://github.com/jellyfin/jellyfin-sdk-typescript/issues/164)