playsout-web-sdk 1.0.6 → 1.0.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ 'use strict';var chunkZ2CIDSTP_cjs=require('./chunk-Z2CIDSTP.cjs');var N=(m=>(m.NOT_INITIALIZED="NOT_INITIALIZED",m.ALREADY_INITIALIZED="ALREADY_INITIALIZED",m.NOT_LOGGED_IN="NOT_LOGGED_IN",m.TOKEN_EXPIRED="TOKEN_EXPIRED",m.INVALID_TOKEN="INVALID_TOKEN",m.NETWORK_ERROR="NETWORK_ERROR",m.TIMEOUT="TIMEOUT",m.SERVER_ERROR="SERVER_ERROR",m.API_ERROR="API_ERROR",m.INVALID_PARAMS="INVALID_PARAMS",m.MISSING_PARAMS="MISSING_PARAMS",m.FEATURE_NOT_SUPPORTED="FEATURE_NOT_SUPPORTED",m.UNKNOWN="UNKNOWN",m.PAYMENT_FAILED="PAYMENT_FAILED",m.SHARE_FAILED="SHARE_FAILED",m))(N||{}),E=class extends Error{constructor(t,r,a){super(r);this.code=t;this.details=a;this.name="SDKError";}toJSON(){return {name:this.name,code:this.code,message:this.message,details:this.details}}},$={NOT_INITIALIZED:"SDK not initialized. Please call PlaysoutSDK.init() first.",ALREADY_INITIALIZED:"SDK already initialized. Please do not call init() more than once.",NOT_LOGGED_IN:"User not logged in. Please log in first.",TOKEN_EXPIRED:"Login token has expired. Please log in again.",INVALID_TOKEN:"Invalid login token. Please log in again.",NETWORK_ERROR:"Network connection failed. Please check your network.",TIMEOUT:"Request timed out. Please try again later.",SERVER_ERROR:"Server is busy. Please try again later.",API_ERROR:"API request failed.",INVALID_PARAMS:"Invalid parameter(s).",MISSING_PARAMS:"Missing required parameter(s).",FEATURE_NOT_SUPPORTED:"This feature is not supported in the current environment.",UNKNOWN:"An unknown error occurred.",PAYMENT_FAILED:"Payment failed.",SHARE_FAILED:"Share failed."};function n(o,e){return new E(o,$[o],e)}var P="playsout_",R=class{constructor(e){this.storage=e;}get(e){try{return this.storage.getItem(P+e)}catch{return null}}set(e,t){try{this.storage.setItem(P+e,t);}catch(r){console.warn("[PlaysoutSDK] Storage set failed:",r);}}remove(e){try{this.storage.removeItem(P+e);}catch{}}clear(){try{let e=[];for(let t=0;t<this.storage.length;t++){let r=this.storage.key(t);r&&r.startsWith(P)&&e.push(r);}e.forEach(t=>this.storage.removeItem(t));}catch{}}},_=class{constructor(){this.store=new Map;}get(e){return this.store.get(e)??null}set(e,t){this.store.set(e,t);}remove(e){this.store.delete(e);}clear(){this.store.clear();}};function G(o="localStorage"){return typeof window>"u"||o==="memory"?new _:o==="sessionStorage"?new R(sessionStorage):new R(localStorage)}var S=G(),l={get:o=>S.get(o),set:(o,e)=>{S.set(o,e);},remove:o=>{S.remove(o);},clear:()=>{S.clear();},getJSON:o=>{let e=S.get(o);if(!e)return null;try{return JSON.parse(e)}catch{return null}},setJSON:(o,e)=>{S.set(o,JSON.stringify(e));},configure(o){S=G(o);}},g={TOKEN_DATA:"token_data",USER:"user",LOGIN_PARAMS:"login_params",LOCALE:"locale",CONFIG:"config"};var V=o=>{if(!o)return o;try{let e=new URL(o);if(e.hostname==="games.playsout.com"){let t=e.pathname,r=t.endsWith("/"),a=/\.[a-z0-9]+$/i.test(t);!r&&!a&&(e.pathname=`${t}/`);}return e.toString()}catch{return o}},X=o=>o.map(e=>{if(!e.externalUrl)return e;let t=V(e.externalUrl);return t===e.externalUrl?e:{...e,externalUrl:t}}),Y=[{id:"BlockCrushFun",title:"Block Crush Fun",category:"Puzzle",image:chunkZ2CIDSTP_cjs.c("./games/BlockCrushFun.png"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/BlockCrushFun/"},{id:"KittyEscape",title:"Kitty Escape",category:"Puzzle",image:chunkZ2CIDSTP_cjs.c("./games/KittyEscape.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/KittyEscape/"},{id:"ProjectGarden",title:"Project: Garden",category:"Adventure",image:chunkZ2CIDSTP_cjs.c("./games/SimulatedAdventures.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/simulated/"},{id:"ProjectIDLE",title:"Project: IDLE",category:"Simulation",image:chunkZ2CIDSTP_cjs.c("./games/ProjectIDLE.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/idle/"},{id:"SoccerDASH",title:"Soccer Dash",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/Soccer Dash.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SoccerDASH/"},{id:"SoccerSurvivor",title:"Soccer Survivor",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/SoccerSurvivor.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SoccerSurvivors/"},{id:"CulinaryStarWeb",title:"Culinary Star",category:"Casual",image:chunkZ2CIDSTP_cjs.c("./games/CulinaryStar.webp"),description:"Cooking game",isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CulinaryStar/"},{id:"PickaxeQuest",title:"Pickaxe Quest",category:"Adventure",image:chunkZ2CIDSTP_cjs.c("./games/PickaxeQuest.jpg"),description:"Mining and adventure game",isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/PickaxeQuest/",apiGameId:73},{id:"MonsterSurvivors",title:"Monster Survivors",category:"Adventure",image:chunkZ2CIDSTP_cjs.c("./games/MonsterSurvivors.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/MonsterSurvivors/"},{id:"IdleTowerDefense",title:"Idle Tower Defense",category:"RPG",image:chunkZ2CIDSTP_cjs.c("./games/IdleTowerDefense.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/IdleTowerDefense/"},{id:"MushroomWarriors",title:"Mushroom Warriors",category:"RPG",image:chunkZ2CIDSTP_cjs.c("./games/MushroomWarriors.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/MushroomWarriors/"},{id:"FollowThePath",title:"Follow The Path",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/FollowThePath.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/FollowThePath/"},{id:"SoccerCascade",title:"Soccer Cascade",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/Soccer Cascade.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SoccerCascade/"},{id:"CatDelta",title:"Cat Delta",category:"Adventure",image:chunkZ2CIDSTP_cjs.c("./games/CatDelta.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/CatDelta/"},{id:"ColorRun",title:"Color Run",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/ColorRun.jpg"),isNew:false,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/ColorRun/"},{id:"SoccerZombies",title:"Soccer vs. Zombies",category:"Tower Defense",image:chunkZ2CIDSTP_cjs.c("./games/Soccer vs. Zombies.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SoccerZombies/"},{id:"MiniSoccer",title:"Mini Soccer",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/minisoccer.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/minisoccer/"},{id:"SoccerMaze",title:"Soccer Maze",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/Soccer Maze.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SoccerMaze/"},{id:"StupidArrow",title:"Stupid Arrow",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/StupidArrow.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/StupidArrow/"},{id:"ZigZag",title:"Zig Zag",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/ZigZag.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/ZigZag/"},{id:"SpikesEverywhere",title:"Spikes Everywhere",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/SpikesEverywhere.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SpikesEverywhere/"},{id:"ArrowRacer",title:"Arrow Racer",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/ArrowRacer.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/ArrowRacer/"},{id:"CircleLeap",title:"Circle Leap",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/CircleLeap.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/CircleLeap/"},{id:"ColorMatcher",title:"Color Matcher",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/ColorMatcher.jpg"),isNew:false,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/ColorMatcher/"},{id:"EndlessMaze",title:"Endless Maze",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/EndlessMaze.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/EndlessMaze/"},{id:"SpinningAround",title:"Spinning Around",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/SpinningAround.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SpinningAround/"},{id:"BoomBallz",title:"Boom Ballz",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/BoomBallz.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/BoomBallz/"},{id:"CubeHead",title:"Cube Head",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/CubeHead.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/CubeHead/"},{id:"CapybaraLink",title:"Capybara Link",category:"Puzzle",image:chunkZ2CIDSTP_cjs.c("./games/CapybaraLink.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CapybaraLink/"},{id:"Snake2048",title:"Snake 2048",category:"Puzzle",image:chunkZ2CIDSTP_cjs.c("./games/Snake2048.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Snake2048/"},{id:"FishTankFury",title:"Fish Tank Fury",category:"Puzzle",image:chunkZ2CIDSTP_cjs.c("./games/FishTankFury.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/FishTankFury/"},{id:"ConnectBalls",title:"Connect Balls",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/ConnectBalls.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/ConnectBalls/"},{id:"CircularBreaker",title:"Circular Breaker",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/CircularBreaker.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/CircularBreaker/"},{id:"OneDoor",title:"One Door",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/OneDoor.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/OneDoor/"},{id:"CatchtheFruits",title:"Catch the Fruits",category:"Casual",image:chunkZ2CIDSTP_cjs.c("./games/CatchtheFruits.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CatchtheFruits/"},{id:"Falling2048",title:"Falling 2048",category:"Casual",image:chunkZ2CIDSTP_cjs.c("./games/Falling2048.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/Falling2048/"}],K=X(Y),h=()=>K.filter(o=>o.enable);({Adventure:h().filter(o=>o.category==="Adventure"),Moba:h().filter(o=>o.category==="Moba")});var M=o=>K.find(e=>e.id===o);var z=()=>Array.from(new Set(h().map(o=>o.category)));var C="https://api.playsout.com",x=3e4;function Q(o){let e=String(o?.platform||"").toLowerCase();if(e==="tiktok"){let t=o.authorizationCode;if(typeof t!="string"||!t.trim())throw n("MISSING_PARAMS","authorizationCode is required for TikTok login");return {platform:e,authorizationCode:t}}if(e==="grab"||e==="eros"){let t=o;if(typeof t.platformUserId!="string"||!t.platformUserId.trim())throw n("MISSING_PARAMS","platformUserId is required for Grab/Eros login");if(typeof t.platformToken!="string"||!t.platformToken.trim())throw n("MISSING_PARAMS","platformToken is required for Grab/Eros login");if(typeof t.username!="string"||!t.username.trim())throw n("MISSING_PARAMS","username is required for Grab/Eros login");return {platform:e,platformUserId:t.platformUserId,platformToken:t.platformToken,username:t.username,inviteCode:typeof t.inviteCode=="string"?t.inviteCode:void 0}}throw n("INVALID_PARAMS","Unsupported platform. Expected grab, eros, or tiktok")}var I=null,L=null,v=null,O=null;function B(o){L=o;}function q(o){v=o;}function W(o){O=o;}function H(){if(O)try{O();}catch{}}async function ee(o){if(!v)throw H(),o instanceof E?o:n("TOKEN_EXPIRED",o);try{return await v()}catch(e){throw H(),e instanceof E?e:n("TOKEN_EXPIRED",e)}}async function j(o,e={},t,r=false,a=r){let u=t?.apiBaseUrl||C,p=o.startsWith("http")?o:`${u}${o}`,c=new AbortController,f=setTimeout(()=>c.abort(),x);try{let d=l.getJSON(g.TOKEN_DATA),A={"Content-Type":"application/json",...e.headers};r&&d?.accessToken&&!A.token&&(A.token=d.accessToken);let T=await fetch(p,{...e,signal:c.signal,headers:A});if(clearTimeout(f),!T.ok){if(T.status===401&&r&&a)return await F(o,e,t);throw n(T.status>=500?"SERVER_ERROR":"API_ERROR",`HTTP ${T.status}: ${T.statusText}`)}let k=await T.json();if(k.code!==1e4){if(r&&a)return await F(o,e,t);throw n("API_ERROR",k.msg||"API request failed")}return k.data}catch(d){throw clearTimeout(f),d instanceof E?d:d instanceof Error?d.name==="AbortError"?n("TIMEOUT"):n("NETWORK_ERROR",d.message):n("UNKNOWN")}}async function F(o,e,t){await Z(t);let r=t?.apiBaseUrl||C,a=o.startsWith("http")?o:`${r}${o}`,u=new AbortController,p=setTimeout(()=>u.abort(),x);try{let c=l.getJSON(g.TOKEN_DATA),f={"Content-Type":"application/json",...e.headers};c?.accessToken&&(f.token=c.accessToken);let d=await fetch(a,{...e,signal:u.signal,headers:f});if(clearTimeout(p),!d.ok)throw n(d.status>=500?"SERVER_ERROR":"API_ERROR",`HTTP ${d.status}: ${d.statusText}`);let A=await d.json();if(A.code!==1e4)throw n("API_ERROR",A.msg||"API request failed");return A.data}catch(c){throw clearTimeout(p),c instanceof E?c:c instanceof Error&&c.name==="AbortError"?n("TIMEOUT"):n("NETWORK_ERROR",c?.message||"Request failed")}}async function Z(o){if(I)return I;let e=(async()=>{try{let t=l.getJSON(g.TOKEN_DATA),r=Math.floor(Date.now()/1e3);if(!t?.refreshToken||t.refreshExpiresAt<=r)throw n("TOKEN_EXPIRED","Refresh token has expired");let a=o?.apiBaseUrl||C,u=new AbortController,p=setTimeout(()=>u.abort(),x);try{let c=await fetch(`${a}/platform/refreshToken`,{method:"POST",signal:u.signal,headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:t.refreshToken})});if(clearTimeout(p),!c.ok)throw c.status>=500?n("SERVER_ERROR",`HTTP ${c.status}: ${c.statusText}`):n("TOKEN_EXPIRED",`HTTP ${c.status}: ${c.statusText}`);let f=await c.json();if(f.code!==1e4||!f.data)throw n("TOKEN_EXPIRED",f.msg||"Failed to refresh token");let d=f.data;if(l.setJSON(g.TOKEN_DATA,d),L)try{L(d);}catch{}return d}catch(c){throw clearTimeout(p),c instanceof E?c:c instanceof Error&&c.name==="AbortError"?n("TIMEOUT"):n("NETWORK_ERROR",c?.message||"Refresh token failed")}}catch(t){return await ee(t)}})();I=e;try{return await e}finally{I===e&&(I=null);}}var U=class{constructor(){this.config=null;}configure(e){this.config=e;}async refreshToken(){return await Z(this.config||void 0)}async getGames(e){let t=h();if(e?.category&&(t=t.filter(r=>r.category===e.category)),e?.search){let r=e.search.toLowerCase();t=t.filter(a=>a.title.toLowerCase().includes(r)||a.category.toLowerCase().includes(r)||a.description&&a.description.toLowerCase().includes(r));}if(e?.sortBy)switch(e.sortBy){case "newest":t=t.filter(r=>r.isNew).concat(t.filter(r=>!r.isNew));break;case "rating":t=t.filter(r=>r.isHot).concat(t.filter(r=>!r.isHot));break}if(e?.page&&e?.pageSize){let r=(e.page-1)*e.pageSize;t=t.slice(r,r+e.pageSize);}return t}async getCategories(){let e=h(),t=new Map;return e.forEach(r=>{let a=t.get(r.category)||0;t.set(r.category,a+1);}),Array.from(t.entries()).map(([r,a],u)=>({id:`category_${u}`,name:r,count:a}))}async getGameById(e){return M(e)}async getCategoryNames(){return z()}async loginOnly(e){let t=Q(e);return await j("/platform/login",{method:"POST",body:JSON.stringify(t)},this.config??void 0)}async Login(e){let t=await this.loginOnly(e);l.setJSON(g.TOKEN_DATA,t);try{let r=await this.getUserInfo(!1);return {tokenData:t,user:r}}catch(r){throw l.remove(g.TOKEN_DATA),l.remove(g.USER),r}}async getUserInfo(e=true){return await j("/platform/user",{method:"GET"},this.config??void 0,true,e)}async getUser(){return l.getJSON(g.USER)}async validateToken(e){return !!e}},D=null;function b(){return D||(D=new U),D}var te="https://api.playsout.com",J="zh",w=class o{constructor(){this.config=null;this._isInitialized=false;this._user=null;this._token=null;this._locale=J;this._widget=null;}clearAuthState(){let e=!!(this._token||l.get(g.TOKEN_DATA)||l.get(g.USER));return this._user=null,this._token=null,l.remove(g.TOKEN_DATA),l.remove(g.USER),l.remove(g.LOGIN_PARAMS),e}updateUser(e){this._user={userId:String(e.id),username:e.username},l.setJSON(g.USER,this._user);}saveLoginParams(e){if(e.platform==="grab"||e.platform==="eros"){l.setJSON(g.LOGIN_PARAMS,{...e});return}l.remove(g.LOGIN_PARAMS);}async performLogin(e,t){let r=b();r.configure(this.config);let a=await r.loginOnly(e);l.setJSON(g.TOKEN_DATA,a);let u=await r.getUserInfo(false);return this._token=a.accessToken,this.updateUser(u),t&&this.saveLoginParams(e),chunkZ2CIDSTP_cjs.b.emit("login",{user:this._user,token:this._token}),{tokenData:a,user:u}}async recoverAuthentication(){let e=l.getJSON(g.LOGIN_PARAMS);if(!e||e.platform!=="grab"&&e.platform!=="eros")throw n("TOKEN_EXPIRED","No reusable login parameters available");return (await this.performLogin(e,false)).tokenData}handleAuthExpired(){this.clearAuthState()&&chunkZ2CIDSTP_cjs.b.emit("authExpired"),this.config?.debug&&console.warn("[PlaysoutSDK] Auth expired, logged out");}static getInstance(){return o.instance||(o.instance=new o),o.instance}async init(e={}){if(this._isInitialized)throw n("ALREADY_INITIALIZED");this.config={apiBaseUrl:e.apiBaseUrl||te,debug:e.debug||false,storage:e.storage||"localStorage",locale:e.locale||J,appId:e.appId||""},l.configure(this.config.storage),B(a=>{this._token=a.accessToken;}),q(()=>this.recoverAuthentication()),W(()=>{this.handleAuthExpired();});let t=l.getJSON(g.TOKEN_DATA);this._user=l.getJSON(g.USER),this._locale=l.get(g.LOCALE)||this.config.locale;let r=Math.floor(Date.now()/1e3);if(t){let a=b();if(a.configure(this.config),t.accessToken&&t.expiresAt>r?this._token=t.accessToken:await a.refreshToken(),this._token&&!this._user){let u=await a.getUserInfo();this.updateUser(u);}}else this._user&&(this._user=null,l.remove(g.USER));this._isInitialized=true,this.config.debug&&(console.log("[PlaysoutSDK] Initialized with config:",this.config),console.log("[PlaysoutSDK] Restored token:",this._token?this._token.substring(0,20)+"...":"(none)")),chunkZ2CIDSTP_cjs.b.emit("initialized");}destroy(){this.config=null,this._isInitialized=false,this._user=null,this._token=null,l.clear(),chunkZ2CIDSTP_cjs.b.clear();}get isInitialized(){return this._isInitialized}get isLoggedIn(){return !!(this._token&&this._user)}get user(){return this._user}get token(){return this._token}get locale(){return this._locale}get sdkConfig(){return this.config}async Login(e){this.ensureInitialized(),this.config?.debug&&console.log("[PlaysoutSDK] Login with params:",e);try{let t=await this.performLogin(e,!0);return this.config?.debug&&console.log("[PlaysoutSDK] Login success, user:",t.user),t}catch(t){throw this.clearAuthState(),t}}async getUserInfo(){if(this.ensureInitialized(),!this.isLoggedIn)throw n("NOT_LOGGED_IN","Please login first");let e=b();e.configure(this.config);let t=await e.getUserInfo();return this.config?.debug&&console.log("[PlaysoutSDK] getUserInfo result:",t),t&&this.updateUser(t),t}logout(){this.clearAuthState(),chunkZ2CIDSTP_cjs.b.emit("logout");}getToken(){return this.ensureInitialized(),this._token}getUser(){return this.ensureInitialized(),this._user}setLocale(e){if(this.ensureInitialized(),!["zh","en","ja","ko","vi","th","id","ms"].includes(e))throw n("INVALID_PARAMS",`Unsupported locale: ${e}`);this._locale=e,l.set(g.LOCALE,e),this.config?.debug&&console.log("[PlaysoutSDK] Locale changed to:",e);let t=this._widget||document.querySelector("playsout-widget");t&&t.getAttribute("locale")!==e&&t.setAttribute("locale",e),chunkZ2CIDSTP_cjs.b.emit("localeChange",e);}getLocale(){return this.ensureInitialized(),this._locale}async getGames(e){this.ensureInitialized();let t=h();if(e?.category&&(t=t.filter(r=>r.category===e.category)),e?.search){let r=e.search.toLowerCase();t=t.filter(a=>a.title.toLowerCase().includes(r)||a.category.toLowerCase().includes(r)||a.description&&a.description.toLowerCase().includes(r));}if(e?.sortBy)switch(e.sortBy){case "newest":t=t.filter(r=>r.isNew).concat(t.filter(r=>!r.isNew));break;case "rating":t=t.filter(r=>r.isHot).concat(t.filter(r=>!r.isHot));break}if(e?.page&&e?.pageSize){let r=(e.page-1)*e.pageSize;t=t.slice(r,r+e.pageSize);}return t}async getCategories(){this.ensureInitialized();let e=h(),t=new Map;return e.forEach(r=>{let a=t.get(r.category)||0;t.set(r.category,a+1);}),Array.from(t.entries()).map(([r,a],u)=>({id:`category_${u}`,name:r,count:a}))}async getGameById(e){return this.ensureInitialized(),h().find(t=>t.id===e)}mount(e,t){if(this.ensureInitialized(),typeof document>"u")throw n("FEATURE_NOT_SUPPORTED","mount requires DOM environment");let r=document.querySelector(e);if(!r)throw n("INVALID_PARAMS",`Container not found: ${e}`);let a=document.createElement("playsout-widget");this.config?.appId&&a.setAttribute("app-id",this.config.appId),a.setAttribute("locale",t?.locale||this._locale),t?.detailMode&&a.setAttribute("detail-mode",t.detailMode),this._widget=a,t?.onGameClick&&a.addEventListener("game-click",u=>{let p=u;t.onGameClick(p.detail);}),t?.onLoginRequired&&a.addEventListener("login-required",t.onLoginRequired),t?.onLocaleChange&&a.addEventListener("locale-change",u=>{let p=u;t.onLocaleChange(p.detail);}),r.appendChild(a),this.config?.debug&&console.log("[PlaysoutSDK] Widget mounted to:",e);}unmount(){let e=document.querySelector("playsout-widget");e&&e.remove(),this._widget=null;}on(e,t){return this.ensureInitialized(),chunkZ2CIDSTP_cjs.b.on(e,t)}off(e,t){this.ensureInitialized(),chunkZ2CIDSTP_cjs.b.off(e,t);}ensureInitialized(){if(!this._isInitialized)throw n("NOT_INITIALIZED")}},s=w.getInstance(),Se=s;typeof window<"u"&&(window.__playsout_sdk_instance=s);var we=Object.freeze({init:s.init.bind(s),mount:s.mount.bind(s),unmount:s.unmount.bind(s),destroy:s.destroy.bind(s),Login:s.Login.bind(s),logout:s.logout.bind(s),getToken:s.getToken.bind(s),getUserInfo:s.getUserInfo.bind(s),getUser:s.getUser.bind(s),setLocale:s.setLocale.bind(s),getLocale:s.getLocale.bind(s),getGames:s.getGames.bind(s),getCategories:s.getCategories.bind(s),on:s.on.bind(s),off:s.off.bind(s),get isInitialized(){return s.isInitialized},get isLoggedIn(){return s.isLoggedIn},instance:s,PlaysoutSDKClass:w});
2
+ exports.a=N;exports.b=E;exports.c=l;exports.d=g;exports.e=w;exports.f=s;exports.g=Se;exports.h=we;
@@ -0,0 +1,2 @@
1
+ import {c,b as b$1}from'./chunk-EZLO3WY6.js';var N=(m=>(m.NOT_INITIALIZED="NOT_INITIALIZED",m.ALREADY_INITIALIZED="ALREADY_INITIALIZED",m.NOT_LOGGED_IN="NOT_LOGGED_IN",m.TOKEN_EXPIRED="TOKEN_EXPIRED",m.INVALID_TOKEN="INVALID_TOKEN",m.NETWORK_ERROR="NETWORK_ERROR",m.TIMEOUT="TIMEOUT",m.SERVER_ERROR="SERVER_ERROR",m.API_ERROR="API_ERROR",m.INVALID_PARAMS="INVALID_PARAMS",m.MISSING_PARAMS="MISSING_PARAMS",m.FEATURE_NOT_SUPPORTED="FEATURE_NOT_SUPPORTED",m.UNKNOWN="UNKNOWN",m.PAYMENT_FAILED="PAYMENT_FAILED",m.SHARE_FAILED="SHARE_FAILED",m))(N||{}),E=class extends Error{constructor(t,r,a){super(r);this.code=t;this.details=a;this.name="SDKError";}toJSON(){return {name:this.name,code:this.code,message:this.message,details:this.details}}},$={NOT_INITIALIZED:"SDK not initialized. Please call PlaysoutSDK.init() first.",ALREADY_INITIALIZED:"SDK already initialized. Please do not call init() more than once.",NOT_LOGGED_IN:"User not logged in. Please log in first.",TOKEN_EXPIRED:"Login token has expired. Please log in again.",INVALID_TOKEN:"Invalid login token. Please log in again.",NETWORK_ERROR:"Network connection failed. Please check your network.",TIMEOUT:"Request timed out. Please try again later.",SERVER_ERROR:"Server is busy. Please try again later.",API_ERROR:"API request failed.",INVALID_PARAMS:"Invalid parameter(s).",MISSING_PARAMS:"Missing required parameter(s).",FEATURE_NOT_SUPPORTED:"This feature is not supported in the current environment.",UNKNOWN:"An unknown error occurred.",PAYMENT_FAILED:"Payment failed.",SHARE_FAILED:"Share failed."};function n(o,e){return new E(o,$[o],e)}var P="playsout_",R=class{constructor(e){this.storage=e;}get(e){try{return this.storage.getItem(P+e)}catch{return null}}set(e,t){try{this.storage.setItem(P+e,t);}catch(r){console.warn("[PlaysoutSDK] Storage set failed:",r);}}remove(e){try{this.storage.removeItem(P+e);}catch{}}clear(){try{let e=[];for(let t=0;t<this.storage.length;t++){let r=this.storage.key(t);r&&r.startsWith(P)&&e.push(r);}e.forEach(t=>this.storage.removeItem(t));}catch{}}},_=class{constructor(){this.store=new Map;}get(e){return this.store.get(e)??null}set(e,t){this.store.set(e,t);}remove(e){this.store.delete(e);}clear(){this.store.clear();}};function G(o="localStorage"){return typeof window>"u"||o==="memory"?new _:o==="sessionStorage"?new R(sessionStorage):new R(localStorage)}var S=G(),l={get:o=>S.get(o),set:(o,e)=>{S.set(o,e);},remove:o=>{S.remove(o);},clear:()=>{S.clear();},getJSON:o=>{let e=S.get(o);if(!e)return null;try{return JSON.parse(e)}catch{return null}},setJSON:(o,e)=>{S.set(o,JSON.stringify(e));},configure(o){S=G(o);}},g={TOKEN_DATA:"token_data",USER:"user",LOGIN_PARAMS:"login_params",LOCALE:"locale",CONFIG:"config"};var V=o=>{if(!o)return o;try{let e=new URL(o);if(e.hostname==="games.playsout.com"){let t=e.pathname,r=t.endsWith("/"),a=/\.[a-z0-9]+$/i.test(t);!r&&!a&&(e.pathname=`${t}/`);}return e.toString()}catch{return o}},X=o=>o.map(e=>{if(!e.externalUrl)return e;let t=V(e.externalUrl);return t===e.externalUrl?e:{...e,externalUrl:t}}),Y=[{id:"BlockCrushFun",title:"Block Crush Fun",category:"Puzzle",image:c("./games/BlockCrushFun.png"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/BlockCrushFun/"},{id:"KittyEscape",title:"Kitty Escape",category:"Puzzle",image:c("./games/KittyEscape.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/KittyEscape/"},{id:"ProjectGarden",title:"Project: Garden",category:"Adventure",image:c("./games/SimulatedAdventures.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/simulated/"},{id:"ProjectIDLE",title:"Project: IDLE",category:"Simulation",image:c("./games/ProjectIDLE.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/idle/"},{id:"SoccerDASH",title:"Soccer Dash",category:"Arcade",image:c("./games/Soccer Dash.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SoccerDASH/"},{id:"SoccerSurvivor",title:"Soccer Survivor",category:"Arcade",image:c("./games/SoccerSurvivor.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SoccerSurvivors/"},{id:"CulinaryStarWeb",title:"Culinary Star",category:"Casual",image:c("./games/CulinaryStar.webp"),description:"Cooking game",isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CulinaryStar/"},{id:"PickaxeQuest",title:"Pickaxe Quest",category:"Adventure",image:c("./games/PickaxeQuest.jpg"),description:"Mining and adventure game",isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/PickaxeQuest/",apiGameId:73},{id:"MonsterSurvivors",title:"Monster Survivors",category:"Adventure",image:c("./games/MonsterSurvivors.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/MonsterSurvivors/"},{id:"IdleTowerDefense",title:"Idle Tower Defense",category:"RPG",image:c("./games/IdleTowerDefense.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/IdleTowerDefense/"},{id:"MushroomWarriors",title:"Mushroom Warriors",category:"RPG",image:c("./games/MushroomWarriors.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/MushroomWarriors/"},{id:"FollowThePath",title:"Follow The Path",category:"Arcade",image:c("./games/FollowThePath.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/FollowThePath/"},{id:"SoccerCascade",title:"Soccer Cascade",category:"Arcade",image:c("./games/Soccer Cascade.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SoccerCascade/"},{id:"CatDelta",title:"Cat Delta",category:"Adventure",image:c("./games/CatDelta.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/CatDelta/"},{id:"ColorRun",title:"Color Run",category:"Arcade",image:c("./games/ColorRun.jpg"),isNew:false,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/ColorRun/"},{id:"SoccerZombies",title:"Soccer vs. Zombies",category:"Tower Defense",image:c("./games/Soccer vs. Zombies.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SoccerZombies/"},{id:"MiniSoccer",title:"Mini Soccer",category:"Arcade",image:c("./games/minisoccer.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/minisoccer/"},{id:"SoccerMaze",title:"Soccer Maze",category:"Arcade",image:c("./games/Soccer Maze.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SoccerMaze/"},{id:"StupidArrow",title:"Stupid Arrow",category:"Arcade",image:c("./games/StupidArrow.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/StupidArrow/"},{id:"ZigZag",title:"Zig Zag",category:"Arcade",image:c("./games/ZigZag.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/ZigZag/"},{id:"SpikesEverywhere",title:"Spikes Everywhere",category:"Arcade",image:c("./games/SpikesEverywhere.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SpikesEverywhere/"},{id:"ArrowRacer",title:"Arrow Racer",category:"Arcade",image:c("./games/ArrowRacer.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/ArrowRacer/"},{id:"CircleLeap",title:"Circle Leap",category:"Arcade",image:c("./games/CircleLeap.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/CircleLeap/"},{id:"ColorMatcher",title:"Color Matcher",category:"Arcade",image:c("./games/ColorMatcher.jpg"),isNew:false,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/ColorMatcher/"},{id:"EndlessMaze",title:"Endless Maze",category:"Arcade",image:c("./games/EndlessMaze.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/EndlessMaze/"},{id:"SpinningAround",title:"Spinning Around",category:"Arcade",image:c("./games/SpinningAround.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/SpinningAround/"},{id:"BoomBallz",title:"Boom Ballz",category:"Arcade",image:c("./games/BoomBallz.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/BoomBallz/"},{id:"CubeHead",title:"Cube Head",category:"Arcade",image:c("./games/CubeHead.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/CubeHead/"},{id:"CapybaraLink",title:"Capybara Link",category:"Puzzle",image:c("./games/CapybaraLink.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CapybaraLink/"},{id:"Snake2048",title:"Snake 2048",category:"Puzzle",image:c("./games/Snake2048.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Snake2048/"},{id:"FishTankFury",title:"Fish Tank Fury",category:"Puzzle",image:c("./games/FishTankFury.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/FishTankFury/"},{id:"ConnectBalls",title:"Connect Balls",category:"Arcade",image:c("./games/ConnectBalls.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/ConnectBalls/"},{id:"CircularBreaker",title:"Circular Breaker",category:"Arcade",image:c("./games/CircularBreaker.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/CircularBreaker/"},{id:"OneDoor",title:"One Door",category:"Arcade",image:c("./games/OneDoor.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/OneDoor/"},{id:"CatchtheFruits",title:"Catch the Fruits",category:"Casual",image:c("./games/CatchtheFruits.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CatchtheFruits/"},{id:"Falling2048",title:"Falling 2048",category:"Casual",image:c("./games/Falling2048.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/grab/Falling2048/"}],K=X(Y),h=()=>K.filter(o=>o.enable);({Adventure:h().filter(o=>o.category==="Adventure"),Moba:h().filter(o=>o.category==="Moba")});var M=o=>K.find(e=>e.id===o);var z=()=>Array.from(new Set(h().map(o=>o.category)));var C="https://api.playsout.com",x=3e4;function Q(o){let e=String(o?.platform||"").toLowerCase();if(e==="tiktok"){let t=o.authorizationCode;if(typeof t!="string"||!t.trim())throw n("MISSING_PARAMS","authorizationCode is required for TikTok login");return {platform:e,authorizationCode:t}}if(e==="grab"||e==="eros"){let t=o;if(typeof t.platformUserId!="string"||!t.platformUserId.trim())throw n("MISSING_PARAMS","platformUserId is required for Grab/Eros login");if(typeof t.platformToken!="string"||!t.platformToken.trim())throw n("MISSING_PARAMS","platformToken is required for Grab/Eros login");if(typeof t.username!="string"||!t.username.trim())throw n("MISSING_PARAMS","username is required for Grab/Eros login");return {platform:e,platformUserId:t.platformUserId,platformToken:t.platformToken,username:t.username,inviteCode:typeof t.inviteCode=="string"?t.inviteCode:void 0}}throw n("INVALID_PARAMS","Unsupported platform. Expected grab, eros, or tiktok")}var I=null,L=null,v=null,O=null;function B(o){L=o;}function q(o){v=o;}function W(o){O=o;}function H(){if(O)try{O();}catch{}}async function ee(o){if(!v)throw H(),o instanceof E?o:n("TOKEN_EXPIRED",o);try{return await v()}catch(e){throw H(),e instanceof E?e:n("TOKEN_EXPIRED",e)}}async function j(o,e={},t,r=false,a=r){let u=t?.apiBaseUrl||C,p=o.startsWith("http")?o:`${u}${o}`,c=new AbortController,f=setTimeout(()=>c.abort(),x);try{let d=l.getJSON(g.TOKEN_DATA),A={"Content-Type":"application/json",...e.headers};r&&d?.accessToken&&!A.token&&(A.token=d.accessToken);let T=await fetch(p,{...e,signal:c.signal,headers:A});if(clearTimeout(f),!T.ok){if(T.status===401&&r&&a)return await F(o,e,t);throw n(T.status>=500?"SERVER_ERROR":"API_ERROR",`HTTP ${T.status}: ${T.statusText}`)}let k=await T.json();if(k.code!==1e4){if(r&&a)return await F(o,e,t);throw n("API_ERROR",k.msg||"API request failed")}return k.data}catch(d){throw clearTimeout(f),d instanceof E?d:d instanceof Error?d.name==="AbortError"?n("TIMEOUT"):n("NETWORK_ERROR",d.message):n("UNKNOWN")}}async function F(o,e,t){await Z(t);let r=t?.apiBaseUrl||C,a=o.startsWith("http")?o:`${r}${o}`,u=new AbortController,p=setTimeout(()=>u.abort(),x);try{let c=l.getJSON(g.TOKEN_DATA),f={"Content-Type":"application/json",...e.headers};c?.accessToken&&(f.token=c.accessToken);let d=await fetch(a,{...e,signal:u.signal,headers:f});if(clearTimeout(p),!d.ok)throw n(d.status>=500?"SERVER_ERROR":"API_ERROR",`HTTP ${d.status}: ${d.statusText}`);let A=await d.json();if(A.code!==1e4)throw n("API_ERROR",A.msg||"API request failed");return A.data}catch(c){throw clearTimeout(p),c instanceof E?c:c instanceof Error&&c.name==="AbortError"?n("TIMEOUT"):n("NETWORK_ERROR",c?.message||"Request failed")}}async function Z(o){if(I)return I;let e=(async()=>{try{let t=l.getJSON(g.TOKEN_DATA),r=Math.floor(Date.now()/1e3);if(!t?.refreshToken||t.refreshExpiresAt<=r)throw n("TOKEN_EXPIRED","Refresh token has expired");let a=o?.apiBaseUrl||C,u=new AbortController,p=setTimeout(()=>u.abort(),x);try{let c=await fetch(`${a}/platform/refreshToken`,{method:"POST",signal:u.signal,headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:t.refreshToken})});if(clearTimeout(p),!c.ok)throw c.status>=500?n("SERVER_ERROR",`HTTP ${c.status}: ${c.statusText}`):n("TOKEN_EXPIRED",`HTTP ${c.status}: ${c.statusText}`);let f=await c.json();if(f.code!==1e4||!f.data)throw n("TOKEN_EXPIRED",f.msg||"Failed to refresh token");let d=f.data;if(l.setJSON(g.TOKEN_DATA,d),L)try{L(d);}catch{}return d}catch(c){throw clearTimeout(p),c instanceof E?c:c instanceof Error&&c.name==="AbortError"?n("TIMEOUT"):n("NETWORK_ERROR",c?.message||"Refresh token failed")}}catch(t){return await ee(t)}})();I=e;try{return await e}finally{I===e&&(I=null);}}var U=class{constructor(){this.config=null;}configure(e){this.config=e;}async refreshToken(){return await Z(this.config||void 0)}async getGames(e){let t=h();if(e?.category&&(t=t.filter(r=>r.category===e.category)),e?.search){let r=e.search.toLowerCase();t=t.filter(a=>a.title.toLowerCase().includes(r)||a.category.toLowerCase().includes(r)||a.description&&a.description.toLowerCase().includes(r));}if(e?.sortBy)switch(e.sortBy){case "newest":t=t.filter(r=>r.isNew).concat(t.filter(r=>!r.isNew));break;case "rating":t=t.filter(r=>r.isHot).concat(t.filter(r=>!r.isHot));break}if(e?.page&&e?.pageSize){let r=(e.page-1)*e.pageSize;t=t.slice(r,r+e.pageSize);}return t}async getCategories(){let e=h(),t=new Map;return e.forEach(r=>{let a=t.get(r.category)||0;t.set(r.category,a+1);}),Array.from(t.entries()).map(([r,a],u)=>({id:`category_${u}`,name:r,count:a}))}async getGameById(e){return M(e)}async getCategoryNames(){return z()}async loginOnly(e){let t=Q(e);return await j("/platform/login",{method:"POST",body:JSON.stringify(t)},this.config??void 0)}async Login(e){let t=await this.loginOnly(e);l.setJSON(g.TOKEN_DATA,t);try{let r=await this.getUserInfo(!1);return {tokenData:t,user:r}}catch(r){throw l.remove(g.TOKEN_DATA),l.remove(g.USER),r}}async getUserInfo(e=true){return await j("/platform/user",{method:"GET"},this.config??void 0,true,e)}async getUser(){return l.getJSON(g.USER)}async validateToken(e){return !!e}},D=null;function b(){return D||(D=new U),D}var te="https://api.playsout.com",J="zh",w=class o{constructor(){this.config=null;this._isInitialized=false;this._user=null;this._token=null;this._locale=J;this._widget=null;}clearAuthState(){let e=!!(this._token||l.get(g.TOKEN_DATA)||l.get(g.USER));return this._user=null,this._token=null,l.remove(g.TOKEN_DATA),l.remove(g.USER),l.remove(g.LOGIN_PARAMS),e}updateUser(e){this._user={userId:String(e.id),username:e.username},l.setJSON(g.USER,this._user);}saveLoginParams(e){if(e.platform==="grab"||e.platform==="eros"){l.setJSON(g.LOGIN_PARAMS,{...e});return}l.remove(g.LOGIN_PARAMS);}async performLogin(e,t){let r=b();r.configure(this.config);let a=await r.loginOnly(e);l.setJSON(g.TOKEN_DATA,a);let u=await r.getUserInfo(false);return this._token=a.accessToken,this.updateUser(u),t&&this.saveLoginParams(e),b$1.emit("login",{user:this._user,token:this._token}),{tokenData:a,user:u}}async recoverAuthentication(){let e=l.getJSON(g.LOGIN_PARAMS);if(!e||e.platform!=="grab"&&e.platform!=="eros")throw n("TOKEN_EXPIRED","No reusable login parameters available");return (await this.performLogin(e,false)).tokenData}handleAuthExpired(){this.clearAuthState()&&b$1.emit("authExpired"),this.config?.debug&&console.warn("[PlaysoutSDK] Auth expired, logged out");}static getInstance(){return o.instance||(o.instance=new o),o.instance}async init(e={}){if(this._isInitialized)throw n("ALREADY_INITIALIZED");this.config={apiBaseUrl:e.apiBaseUrl||te,debug:e.debug||false,storage:e.storage||"localStorage",locale:e.locale||J,appId:e.appId||""},l.configure(this.config.storage),B(a=>{this._token=a.accessToken;}),q(()=>this.recoverAuthentication()),W(()=>{this.handleAuthExpired();});let t=l.getJSON(g.TOKEN_DATA);this._user=l.getJSON(g.USER),this._locale=l.get(g.LOCALE)||this.config.locale;let r=Math.floor(Date.now()/1e3);if(t){let a=b();if(a.configure(this.config),t.accessToken&&t.expiresAt>r?this._token=t.accessToken:await a.refreshToken(),this._token&&!this._user){let u=await a.getUserInfo();this.updateUser(u);}}else this._user&&(this._user=null,l.remove(g.USER));this._isInitialized=true,this.config.debug&&(console.log("[PlaysoutSDK] Initialized with config:",this.config),console.log("[PlaysoutSDK] Restored token:",this._token?this._token.substring(0,20)+"...":"(none)")),b$1.emit("initialized");}destroy(){this.config=null,this._isInitialized=false,this._user=null,this._token=null,l.clear(),b$1.clear();}get isInitialized(){return this._isInitialized}get isLoggedIn(){return !!(this._token&&this._user)}get user(){return this._user}get token(){return this._token}get locale(){return this._locale}get sdkConfig(){return this.config}async Login(e){this.ensureInitialized(),this.config?.debug&&console.log("[PlaysoutSDK] Login with params:",e);try{let t=await this.performLogin(e,!0);return this.config?.debug&&console.log("[PlaysoutSDK] Login success, user:",t.user),t}catch(t){throw this.clearAuthState(),t}}async getUserInfo(){if(this.ensureInitialized(),!this.isLoggedIn)throw n("NOT_LOGGED_IN","Please login first");let e=b();e.configure(this.config);let t=await e.getUserInfo();return this.config?.debug&&console.log("[PlaysoutSDK] getUserInfo result:",t),t&&this.updateUser(t),t}logout(){this.clearAuthState(),b$1.emit("logout");}getToken(){return this.ensureInitialized(),this._token}getUser(){return this.ensureInitialized(),this._user}setLocale(e){if(this.ensureInitialized(),!["zh","en","ja","ko","vi","th","id","ms"].includes(e))throw n("INVALID_PARAMS",`Unsupported locale: ${e}`);this._locale=e,l.set(g.LOCALE,e),this.config?.debug&&console.log("[PlaysoutSDK] Locale changed to:",e);let t=this._widget||document.querySelector("playsout-widget");t&&t.getAttribute("locale")!==e&&t.setAttribute("locale",e),b$1.emit("localeChange",e);}getLocale(){return this.ensureInitialized(),this._locale}async getGames(e){this.ensureInitialized();let t=h();if(e?.category&&(t=t.filter(r=>r.category===e.category)),e?.search){let r=e.search.toLowerCase();t=t.filter(a=>a.title.toLowerCase().includes(r)||a.category.toLowerCase().includes(r)||a.description&&a.description.toLowerCase().includes(r));}if(e?.sortBy)switch(e.sortBy){case "newest":t=t.filter(r=>r.isNew).concat(t.filter(r=>!r.isNew));break;case "rating":t=t.filter(r=>r.isHot).concat(t.filter(r=>!r.isHot));break}if(e?.page&&e?.pageSize){let r=(e.page-1)*e.pageSize;t=t.slice(r,r+e.pageSize);}return t}async getCategories(){this.ensureInitialized();let e=h(),t=new Map;return e.forEach(r=>{let a=t.get(r.category)||0;t.set(r.category,a+1);}),Array.from(t.entries()).map(([r,a],u)=>({id:`category_${u}`,name:r,count:a}))}async getGameById(e){return this.ensureInitialized(),h().find(t=>t.id===e)}mount(e,t){if(this.ensureInitialized(),typeof document>"u")throw n("FEATURE_NOT_SUPPORTED","mount requires DOM environment");let r=document.querySelector(e);if(!r)throw n("INVALID_PARAMS",`Container not found: ${e}`);let a=document.createElement("playsout-widget");this.config?.appId&&a.setAttribute("app-id",this.config.appId),a.setAttribute("locale",t?.locale||this._locale),t?.detailMode&&a.setAttribute("detail-mode",t.detailMode),this._widget=a,t?.onGameClick&&a.addEventListener("game-click",u=>{let p=u;t.onGameClick(p.detail);}),t?.onLoginRequired&&a.addEventListener("login-required",t.onLoginRequired),t?.onLocaleChange&&a.addEventListener("locale-change",u=>{let p=u;t.onLocaleChange(p.detail);}),r.appendChild(a),this.config?.debug&&console.log("[PlaysoutSDK] Widget mounted to:",e);}unmount(){let e=document.querySelector("playsout-widget");e&&e.remove(),this._widget=null;}on(e,t){return this.ensureInitialized(),b$1.on(e,t)}off(e,t){this.ensureInitialized(),b$1.off(e,t);}ensureInitialized(){if(!this._isInitialized)throw n("NOT_INITIALIZED")}},s=w.getInstance(),Se=s;typeof window<"u"&&(window.__playsout_sdk_instance=s);var we=Object.freeze({init:s.init.bind(s),mount:s.mount.bind(s),unmount:s.unmount.bind(s),destroy:s.destroy.bind(s),Login:s.Login.bind(s),logout:s.logout.bind(s),getToken:s.getToken.bind(s),getUserInfo:s.getUserInfo.bind(s),getUser:s.getUser.bind(s),setLocale:s.setLocale.bind(s),getLocale:s.getLocale.bind(s),getGames:s.getGames.bind(s),getCategories:s.getCategories.bind(s),on:s.on.bind(s),off:s.off.bind(s),get isInitialized(){return s.isInitialized},get isLoggedIn(){return s.isLoggedIn},instance:s,PlaysoutSDKClass:w});
2
+ export{N as a,E as b,l as c,g as d,w as e,s as f,Se as g,we as h};
@@ -1 +1 @@
1
- {"version":3,"file":"games.d.ts","sourceRoot":"","sources":["../../src/data/games.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAgYD,eAAO,MAAM,KAAK,EAAE,IAAI,EAA6B,CAAC;AAGtD,eAAO,MAAM,eAAe,QAAO,IAAI,EAEtC,CAAC;AAGF,eAAO,MAAM,eAAe;;;CAG3B,CAAC;AAGF,eAAO,MAAM,WAAW,QAAO,IAAI,EAElC,CAAC;AAGF,eAAO,MAAM,WAAW,QAAO,IAAI,EAElC,CAAC;AAGF,eAAO,MAAM,iBAAiB,QAAO,IAAI,EAExC,CAAC;AAGF,eAAO,MAAM,cAAc,QAAO,IAAI,EAErC,CAAC;AAGF,eAAO,MAAM,WAAW,GAAI,IAAI,MAAM,KAAG,IAAI,GAAG,SAE/C,CAAC;AAGF,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,KAAG,MAAM,GAAG,SAGlD,CAAC;AAGF,eAAO,MAAM,kBAAkB,GAAI,IAAI,MAAM,KAAG,IAAI,GAAG,SAEtD,CAAC;AAGF,eAAO,MAAM,gBAAgB,QAAO,MAAM,EAEzC,CAAC;AAGF,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,IAAI,EAO/C,CAAC"}
1
+ {"version":3,"file":"games.d.ts","sourceRoot":"","sources":["../../src/data/games.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA+aD,eAAO,MAAM,KAAK,EAAE,IAAI,EAA6B,CAAC;AAGtD,eAAO,MAAM,eAAe,QAAO,IAAI,EAEtC,CAAC;AAGF,eAAO,MAAM,eAAe;;;CAG3B,CAAC;AAGF,eAAO,MAAM,WAAW,QAAO,IAAI,EAElC,CAAC;AAGF,eAAO,MAAM,WAAW,QAAO,IAAI,EAElC,CAAC;AAGF,eAAO,MAAM,iBAAiB,QAAO,IAAI,EAExC,CAAC;AAGF,eAAO,MAAM,cAAc,QAAO,IAAI,EAErC,CAAC;AAGF,eAAO,MAAM,WAAW,GAAI,IAAI,MAAM,KAAG,IAAI,GAAG,SAE/C,CAAC;AAGF,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,KAAG,MAAM,GAAG,SAGlD,CAAC;AAGF,eAAO,MAAM,kBAAkB,GAAI,IAAI,MAAM,KAAG,IAAI,GAAG,SAEtD,CAAC;AAGF,eAAO,MAAM,gBAAgB,QAAO,MAAM,EAEzC,CAAC;AAGF,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,IAAI,EAO/C,CAAC"}
package/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var chunkNHFWJCNJ_cjs=require('./chunk-NHFWJCNJ.cjs'),chunkZ2CIDSTP_cjs=require('./chunk-Z2CIDSTP.cjs');Object.defineProperty(exports,"ErrorCode",{enumerable:true,get:function(){return chunkNHFWJCNJ_cjs.a}});Object.defineProperty(exports,"Playsout",{enumerable:true,get:function(){return chunkNHFWJCNJ_cjs.h}});Object.defineProperty(exports,"PlaysoutSDK",{enumerable:true,get:function(){return chunkNHFWJCNJ_cjs.e}});Object.defineProperty(exports,"SDKError",{enumerable:true,get:function(){return chunkNHFWJCNJ_cjs.b}});Object.defineProperty(exports,"STORAGE_KEYS",{enumerable:true,get:function(){return chunkNHFWJCNJ_cjs.d}});Object.defineProperty(exports,"default",{enumerable:true,get:function(){return chunkNHFWJCNJ_cjs.g}});Object.defineProperty(exports,"sdk",{enumerable:true,get:function(){return chunkNHFWJCNJ_cjs.f}});Object.defineProperty(exports,"storage",{enumerable:true,get:function(){return chunkNHFWJCNJ_cjs.c}});Object.defineProperty(exports,"SDKEvent",{enumerable:true,get:function(){return chunkZ2CIDSTP_cjs.a}});Object.defineProperty(exports,"eventEmitter",{enumerable:true,get:function(){return chunkZ2CIDSTP_cjs.b}});
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var chunkMDSUYVLI_cjs=require('./chunk-MDSUYVLI.cjs'),chunkZ2CIDSTP_cjs=require('./chunk-Z2CIDSTP.cjs');Object.defineProperty(exports,"ErrorCode",{enumerable:true,get:function(){return chunkMDSUYVLI_cjs.a}});Object.defineProperty(exports,"Playsout",{enumerable:true,get:function(){return chunkMDSUYVLI_cjs.h}});Object.defineProperty(exports,"PlaysoutSDK",{enumerable:true,get:function(){return chunkMDSUYVLI_cjs.e}});Object.defineProperty(exports,"SDKError",{enumerable:true,get:function(){return chunkMDSUYVLI_cjs.b}});Object.defineProperty(exports,"STORAGE_KEYS",{enumerable:true,get:function(){return chunkMDSUYVLI_cjs.d}});Object.defineProperty(exports,"default",{enumerable:true,get:function(){return chunkMDSUYVLI_cjs.g}});Object.defineProperty(exports,"sdk",{enumerable:true,get:function(){return chunkMDSUYVLI_cjs.f}});Object.defineProperty(exports,"storage",{enumerable:true,get:function(){return chunkMDSUYVLI_cjs.c}});Object.defineProperty(exports,"SDKEvent",{enumerable:true,get:function(){return chunkZ2CIDSTP_cjs.a}});Object.defineProperty(exports,"eventEmitter",{enumerable:true,get:function(){return chunkZ2CIDSTP_cjs.b}});