PageSourceSearch

https://masky.ai/assets/twitch-ByYV1eV5.js

js masky.ai collected 2026-10-05 12:15:08 UTC 4,855 bytes, 1 lines download raw bytes

1import{_ as g}from"./preload-helper-BXl3LOEh.js";import{b as w,c as I,s as E}from"./firebase-iu_Ea38d.js";const y="https://api.twitch.tv/helix",_={channelPointsRewards:["channel:read:redemptions"]};let d=()=>{};function U(t=""){return t?t.startsWith("/")?t.slice(1):t:""}function R(t,e={}){const i=new URL(`${y}/${U(t)}`);return Object.entries(e||{}).forEach(([o,n])=>{n!=null&&n!==""&&i.searchParams.append(o,n)}),i}async function m({forceRefresh:t=!1}={}){const e=w();if(!e)throw new Error("User is not authenticated with Twitch");const o=(await e.getIdTokenResult(t))?.claims?.twitchAccessToken;if(!o)throw new Error("Missing Twitch access token. Please reconnect your Twitch account.");return o}function A(t){if(!t)return null;const{uid:e}=t;return typeof e=="string"&&e.startsWith("twitch:")?e.slice(7):null}async function b(){const t=w();if(t)try{await t.getIdToken(!0)}catch(e){console.warn("[twitch] Failed to refresh ID token after login:",e)}}async function p(t=[]){const e=Array.isArray(t)?t:[];await E(e),await b();try{d?.()}catch(i){console.error("[twitch] Error running twitchFinishedLogin callback:",i)}}function k(t,e){return!t||e?!1:t.status===401||t.status===403}function D(t){const e=d;return typeof t=="function"?d=t:d=()=>{},e}async function P(t=[]){await p(t)}async function T(t,{query:e,method:i="GET",body:o,headers:n={},requiredScopes:r=[]}={},a=!1){if(!w())throw new Error("User must be logged in with Twitch to use this feature.");let c;try{c=await m({forceRefresh:!1})}catch(f){console.warn("[twitch] Unable to obtain access token, attempting login...",f),await p(r),c=await m({forceRefresh:!0})}const h=R(t,e),l={Authorization:`Bearer ${c}`,"Client-Id":I.twitch.clientId,...n};o&&!l["Content-Type"]&&(l["Content-Type"]="application/json");const u=await fetch(h.toString(),{method:i,headers:l,body:o?JSON.stringify(o):void 0,cache:"no-store"});return k(u,a)?(console.warn("[twitch] Twitch API returned unauthorized. Initiating re-auth..."),await p(r),T(t,{query:e,method:i,body:o,headers:n,requiredScopes:r},!0)):u}async function $(){const t=w();if(!t)throw new Error("You must be signed in with Twitch to view channel rewards.");const e=A(t);if(!e)throw new Error("Unable to determine Twitch broadcaster ID for the current user.");const i=await T("channel_points/custom_rewards",{query:{broadcaster_id:e},requiredScopes:_.channelPointsRewards});if(!i.ok){if(i.status===403){const s=new Error("Twitch only exposes custom rewards to Affiliate or Partner broadcasters. Your rewards will appear here once Twitch unlocks them for your channel.");throw s.code="TWITCH_REWARDS_FORBIDDEN",s}const r=await i.text().catch(()=>"Unknown error"),a=new Error(`Failed to load channel point rewards (${i.status}): ${r}`);throw a.code="TWITCH_REWARDS_ERROR",a}const o=await i.json().catch(()=>({data:[]}));return(Array.isArray(o?.data)?o.data:[]).map(r=>({id:r.id,title:r.title,cost:r.cost,prompt:r.prompt,isEnabled:r.is_enabled!==!1}))}async function L(){const t=w();if(!t)throw new Error("User must be logged in with Twitch to use this feature.");try{const{db:e,doc:i,getDoc:o}=await g(async()=>{const{db:a,doc:s,getDoc:c}=await import("./firebase-iu_Ea38d.js").then(h=>h.$);return{db:a,doc:s,getDoc:c}},[]),n=i(e,"users",t.uid),r=await o(n);if(r.exists()){const a=r.data(),s=a.twitchUserInfo,c=a.twitchUserInfoUpdatedAt;if(s&&c){const h=Date.now()-c.toMillis(),l=1440*60*1e3;if(h<l)return{id:s.id,login:s.login,displayName:s.displayName,profileImageUrl:s.profileImageUrl}}}}catch(e){console.warn("[getBroadcasterInfo] Error checking Firestore cache:",e)}try{const e=await t.getIdToken(),{config:i}=await g(async()=>{const{config:r}=await import("./firebase-iu_Ea38d.js").then(a=>a.Z);return{config:r}},[]),o=await fetch(`${i.api.baseUrl}/api/twitch/user-info`,{method:"GET",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!o.ok){const r=await o.text().catch(()=>"Unknown error");throw new Error(`Failed to load broadcaster info (${o.status}): ${r}`)}const n=await o.json();try{const{db:r,doc:a,setDoc:s}=await g(async()=>{const{db:h,doc:l,setDoc:u}=await import("./firebase-iu_Ea38d.js").then(f=>f.$);return{db:h,doc:l,setDoc:u}},[]),c=a(r,"users",t.uid);await s(c,{twitchUserInfo:{id:n.id,login:n.login,displayName:n.displayName,profileImageUrl:n.profileImageUrl},twitchUserInfoUpdatedAt:new Date},{merge:!0})}catch(r){console.warn("[getBroadcasterInfo] Error updating cache:",r)}return{id:n.id,login:n.login,displayName:n.displayName,profileImageUrl:n.profileImageUrl}}catch(e){throw console.error("[getBroadcasterInfo] Error fetching from API:",e),e}}
1const C={getRedemptionTitles:$,twitchLogin:P,setTwitchFinishedLogin:D,callTwitchUserApi:T,getBroadcasterInfo:L};export{T as callTwitchUserApi,L as getBroadcasterInfo,$ as getRedemptionTitles,D as setTwitchFinishedLogin,C as twitchHelpers,P as twitchLogin};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.