Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow interaction with providers #13

Open
chrishoage opened this issue Apr 26, 2024 · 11 comments
Open

Allow interaction with providers #13

chrishoage opened this issue Apr 26, 2024 · 11 comments

Comments

@chrishoage
Copy link

Providers from Plex (Tidal Music Integration, Watchlist) expose an almost identical API as Plex Servers.

However restrictions in the schema prevent these sdks from using a provider as an input.

For example one can set up an instance like so:

const discoverProvider = new PlexAPI({ accessToken: "TOKEN", serverURL: "https://discover.provider.plex.tv" });

However trying to interact with the watchlist library section ID ends up with an error

> await discoverProvider.library.getLibraryItems("watchlist")
Uncaught SDKValidationError: Input validation failed
    at Object.parse (file:///home/chris/.cache/deno/npm/registry.npmjs.org/@lukehagar/plexjs/0.13.2/lib/schemas.js:43:19)
    at Library.getLibraryItems (file:///home/chris/.cache/deno/npm/registry.npmjs.org/@lukehagar/plexjs/0.13.2/sdk/library.js:512:35)
    at <anonymous>:1:41

Looking the schema, the input is restricted to a number. Taking a peek at the code relaxing this to be a number or string should allow reading these provider libraries, which otherwise return the same API shape

Would it be possible to update the schema to allow for this possibility?

LukeHagar added a commit that referenced this issue May 8, 2024
@LukeHagar
Copy link
Owner

Fantastic observation!
I just updated the specification to reflect both values as possible.

@LukeHagar
Copy link
Owner

The various SDKs should be regenerated shortly, please let me know if things work as you would expect.

@LukeHagar
Copy link
Owner

I would note that documenting the provider API is also something I would like to do, so if we want to create a list of the valid provider server endpoints, and what methods exactly the support that would be a great thing to include.

@LukeHagar
Copy link
Owner

Circling back around here, this change will have to wait for a feature to be implemented in the SDK package, I'm reverting this change for now.

@chrishoage
Copy link
Author

No problem I'll keep an eye on this issue to see.

Thank you!

Repository owner deleted a comment from speakeasybot Jun 14, 2024
@LukeHagar
Copy link
Owner

This is tentatively resolved in the newest release. Can you pull it down and validate it?

@chrishoage
Copy link
Author

So I noticed I had some user error in my original example

getLibraryItems appears to require two parameters, and I was only supplying one in my example code above. However I think the original issue was still an issue.

I updated my example to await watch.library.getLibraryItems("watchlist", "all") and I got a different error, but this time an error on the response.

It appears that this error is about the type of ibrarySectionID - similarly expecting a number and getting a string.

> try { await watch.library.getLibraryItems("watchlist", "all") } catch (e) { console.log(e.pretty()) }
Response validation failed
┌ 1 issue found:
│ • [<root>.object.MediaContainer.librarySectionID]: Expected number, received string (invalid_type)
│     Want: number
│      Got: string
└─*

@LukeHagar
Copy link
Owner

Can you confirm you updated the package? The newest NPM release should fix the type issue

@chrishoage
Copy link
Author

Yes, I can confirm I updated the package.

The type issue before was the getLibraryItems argument.

As I mentioned in my previous comment the issue now is the response shape, not the input validation.

https://github.com/LukeHagar/plexjs/blob/main/src/models/getlibraryitemsop.ts#L207

@LukeHagar
Copy link
Owner

Understood, I just updated the value to a type array
Package should be regenerated and published soon

@chrishoage
Copy link
Author

I noticed version 18 was published today. I can confirm everything works!

I tested using the following in Deno and I get the expected response back. Thank you!

import { PlexAPI } from "npm:@lukehagar/[email protected]";
let watch = new PlexAPI({ accessToken: "TOKEN", serverURL: "https://discover.provider.plex.tv" })
let watchlist = await watch.library.getLibraryItems("watchlist", "all")
console.log(watchlist.object.mediaContainer.metadata.length)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

No branches or pull requests

2 participants