zSoulweaver / kient

TypeScript-First Client Library for Kick.com
https://kient.pages.dev/
MIT License
28 stars 10 forks source link

ValidationError: Validation error for type any | null #4

Closed 0xHal closed 8 months ago

0xHal commented 8 months ago

Hello,

I tried to use the getLivestream(channel: string) function on my channel instance but i'm receiving this error and i don't know how to fix (sorry to bother you)

It seems that it cannot correctly parse the response but i can be wrong..

errors: [ ValidationErrorItem { path: '', code: 'type', message: 'No valid union member found. Valid: any | null', value: { id: 22166273, slug: '46347792-watch-blind-dating-free-therapy-for-viewer-calls-s-my-links', session_title: 'WATCH BLIND DATING + FREE THERAPY FOR VIEWER CALLS šŸ‘ !s --> my links', created_at: '2024-01-21T17:12:57.000000Z', language: 'English', is_mature: false, viewers: 4981, category: { id: 15, name: 'Just Chatting', slug: 'just-chatting', tags: [ 'IRL' ], parent_category: { id: 2, slug: 'irl' } }, playback_url: 'https://fa723fc1b171.us-west-2.playback.live-video.net/api/video/v1/us-west-2.196233775518.channel.phlvZbvP2gwW.m3u8?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzM4NCJ9.eyJhd3M6Y2hhbm5lbC1hcm4iOiJhcm46YXdzOml2czp1cy13ZXN0LTI6MTk2MjMzNzc1NTE4OmNoYW5uZWwvcGhsdlpidlAyZ3dXIiwiYXdzOmFjY2Vzcy1jb250cm9sLWFsbG93LW9yaWdpbiI6Imh0dHBzOi8va2ljay5jb20saHR0cHM6Ly9wbGF5ZXIua2ljay5jb20saHR0cHM6Ly9hZG1pbi5raWNrLmNvbSxodHRwczovL3d3dy5nc3RhdGljLmNvbSIsImF3czpzdHJpY3Qtb3JpZ2luLWVuZm9yY2VtZW50IjpmYWxzZSwiZXhwIjoxNzA1OTAzODc1fQ.7UQg7eC6l8lFS3ScsQ44CYUpMdkFCgui70omNXvX9ljv68e2GnQW-Cu--5Q3KS1fM9q6Oj6JAy3NOsMRdMegr2gfB-NjEcZExPbWFH2QtQDoQ7Pwa9YuzkxLQj8aFklh', thumbnail: { src: 'https://images.kick.com/video_thumbnails/phlvZbvP2gwW/rZTzXpK0yoLQ/720.webp', srcset: 'https://images.kick.com/video_thumbnails/phlvZbvP2gwW/rZTzXpK0yoLQ/1080.webp 1920w, https://images.kick.com/video_thumbnails/phlvZbvP2gwW/rZTzXpK0yoLQ/720.webp 1280w, https://images.kick.com/video_thumbnails/phlvZbvP2gwW/rZTzXpK0yoLQ/360.webp 480w, https://images.kick.com/video_thumbnails/phlvZbvP2gwW/rZTzXpK0yoLQ/160.webp 284w, https://images.kick.com/video_thumbnails/phlvZbvP2gwW/rZTzXpK0yoLQ/480.webp 640w' } } } ] }

zSoulweaver commented 8 months ago

Hi @0xHal,

Thanks for the report. Not sure what could be happening, but it looks like @deepkit/type isn't getting any type information. I've had a few refactors internally and I don't have any issues with my current codebase.

I've published version to 1.0.1-9, could you let me know how it goes?

I've somewhat stopped working on Kient until the full API releases, hopefully very soon.

0xHal commented 8 months ago

It works fine now! Thanks man. This problem seems to happen elsewhere too:

errors: [
      ValidationErrorItem {
        path: 'data.livestream.thumbnail',
        code: 'type',
        message: 'Not an object',
        value: undefined
      }
    ]
  }

This problem only happen on the following kick channel: roshtein When i try with other channel it works fine.

I can't wait for their API to be released but i'm very happy to work with your custom API.

Thanks a lot for your work!

0xHal commented 8 months ago

If you could teach me how you deal with these validation maybe i could help you with PR instead of asking and maybe bother you.

zSoulweaver commented 8 months ago

It works fine now! Thanks man. This problem seems to happen elsewhere too:

errors: [
      ValidationErrorItem {
        path: 'data.livestream.thumbnail',
        code: 'type',
        message: 'Not an object',
        value: undefined
      }
    ]
  }

This problem only happen on the following kick channel: roshtein When i try with other channel it works fine.

I can't wait for their API to be released but i'm very happy to work with your custom API.

Thanks a lot for your work!

So essentially the issue is that in get-livestream.response.ts we are expecting that the thumbnail be in an object that contains src and srcset, in this circumstance there is no thumbnail object and it is instead returning undefined.

So, to fix this, we would need to mark the thumbnail property as optional and deepkit/type will figure out the rest.

0xHal commented 8 months ago

It works fine now! Thanks man. This problem seems to happen elsewhere too:

errors: [
      ValidationErrorItem {
        path: 'data.livestream.thumbnail',
        code: 'type',
        message: 'Not an object',
        value: undefined
      }
    ]
  }

This problem only happen on the following kick channel: roshtein When i try with other channel it works fine. I can't wait for their API to be released but i'm very happy to work with your custom API. Thanks a lot for your work!

So essentially the issue is that in get-livestream.response.ts we are expecting that the thumbnail be in an object that contains src and srcset, in this circumstance there is no thumbnail object and it is instead returning undefined.

So, to fix this, we would need to mark the thumbnail property as optional and deepkit/type will figure out the rest.

Thank again for your time and your explanations.

I took a look on the index.js but it seems that i will not be able to fix this problem following this path.

I made a change is it correct? image

0xHal commented 8 months ago

Maybe thumbnail {...} | undefined was enought

zSoulweaver commented 8 months ago

Published version 1.0.1-10 to npm to fix above issue.

Any further validation issues, let me know. Due to how deepkit/type works, the types are compiled into the build, unfortunately just editing the type declarations isn't enough.

0xHal commented 8 months ago

Nice, yes i had another bug too [KientSomethingWentWrong: Unknown error has occured] { [cause]: ValidationError: Validation error for type BannedUserInstance: data.expires_at(type): Not a Date errors: [ ValidationErrorItem { path: 'data.expires_at', code: 'type', message: 'Not a Date', value: undefined } ] } }

Thanks for all the updates you'r making!

0xHal commented 8 months ago

I don't know which type is returned but maybe it's an number so here my change i'll test it image

zSoulweaver commented 8 months ago

Pushed another fix for the validation issues, @0xHal. Kient version 1.0.1-11 has been published.

I didn't realise that Kick sent over different responses depending on permanent bans and timeouts. I've also added a helper function on the instance, isPermanent, to return a boolean depending on the ban type.