jwplayer / ott-web-app

Reference implementation for JWP-powered apps
Apache License 2.0
69 stars 52 forks source link

AdSchedule type doesn't match actual data type #472

Open ChristiaanScheermeijer opened 3 months ago

ChristiaanScheermeijer commented 3 months ago

In the Player.tsx, an adsData prop uses the AdSchedule type. This type is defined as follows:

export type AdSchedule = {
  adscheduleid?: string;
  client: string;
  schedule: string;
};

However, the data seems to differ from the type above:

{
    "rules": {
        "startOnSeek": "pre",
        "timeBetweenAds": 0
    },
    "client": "vast",
    "schedule": [
        {
            "tag": [
                "https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_preroll_skippable&sz=640x480&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=__random-number__"
            ],
            "type": "linear",
            "offset": "pre",
            "skipoffset": 5
        }
    ],
    "adscheduleid": "S2FKhc4J"
}
ChristiaanScheermeijer commented 3 months ago

@AntonLantukh @dbudzins

I think this is caused due to the type casting in the ApiService:

https://github.com/jwplayer/ott-web-app/blob/f52a0f3377ed1c0d22e47f27995c597d7ec71e55/packages/common/src/services/ApiService.ts#L238-L247

Do we want to verify the data using yup instead of assuming the type? 🤔

AntonLantukh commented 3 months ago

@ChristiaanScheermeijer I would just modify the AdSchedule type not including yup in checks. yup looks like a good choice for some complex checks we have for AppConfig , but here I would just rely on the api docs (something we need to update):

https://docs.jwplayer.com/platform/reference/get_v2-advertising-schedules-ad-schedule-id-ad-schedule-extension