function s(r){const e=r.replace(/-/g,"+").replace(/_/g,"/"),t=e.padEnd(e.length+(4-e.length%4)%4,"="),n=atob(t),o=Uint8Array.from(n,a=>a.charCodeAt(0));return new TextDecoder().decode(o)}export function parseToken(r){const e=String(r||"").split(".");if(e.length<2)throw new Error("Invalid JWT");return{payload:JSON.parse(s(e[1]))}}export function hasEntitlement(r,e){if(!e)return!0;if(Array.isArray(r))return r.includes(e);try{const t=parseToken(r).payload||{};return Array.isArray(t.entitlements)&&t.entitlements.includes(e)}catch{return!1}}export function resolveEntitlementNames(r,e=[]){const t=Array.isArray(r)?r:[r];return[...new Set([...t,...e||[]].filter(Boolean))]}export function hasAnyEntitlement(r,e,t=[]){const n=resolveEntitlementNames(e,t);return n.length?n.some(o=>hasEntitlement(r,o)):!0}export function isTokenFresh(r){if(!r)return!1;const e=Date.parse(r);return Number.isNaN(e)?!1:e>Date.now()}
