UNPKG

kodikwrapper

Version:
2 lines (1 loc) 1.04 kB
import{a as s}from"./chunk-GBMXW5DT.mjs";const l="https://kodikapi.com",d=["countries","genres","list","qualities","search","translations","years","qualitiesV2","translationsV2"],h={qualitiesV2:"qualities/v2",translationsV2:"translations/v2"};class i extends Error{static{s(this,"ClientError")}name="ClientError"}class a{static{s(this,"Client")}KODIK_API_URL;constructor({token:e,kodikApiUrl:n}){this.KODIK_API_URL=n??l;for(const o of d){const c=h[o]??o;this[o]=p=>fetch(new URL(`${c}?${new URLSearchParams({token:e,...p}).toString()}`,this.KODIK_API_URL),{method:"POST"}).then(async t=>{if(t.headers.get("content-type")!=="application/json")throw new i(`invalid response (expected content-type application/json, but got ${t.headers.get("content-type")})`);const r=await t.json();if(typeof r!="object")throw new i(`expected json as an object, but got a ${typeof r}`);return r}).then(t=>{if("error"in t)throw new i(t.error);return t})}}static fromToken(e,n){return new a({...n,token:e})}}export{a as Client,i as ClientError,l as KODIK_API_URL};