playsout-web-sdk 1.0.4 → 1.0.6

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.
package/index.js CHANGED
@@ -1 +1 @@
1
- export{a as ErrorCode,h as Playsout,e as PlaysoutSDK,b as SDKError,d as STORAGE_KEYS,g as default,f as sdk,c as storage}from'./chunk-I2HADAGI.js';export{a as SDKEvent,b as eventEmitter}from'./chunk-EZLO3WY6.js';
1
+ export{a as ErrorCode,h as Playsout,e as PlaysoutSDK,b as SDKError,d as STORAGE_KEYS,g as default,f as sdk,c as storage}from'./chunk-XDBADNFW.js';export{a as SDKEvent,b as eventEmitter}from'./chunk-EZLO3WY6.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playsout-web-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Playsout WebGame SDK for game list, authentication, and internationalization",
5
5
  "type": "module",
6
6
  "main": "index.cjs",
package/react/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkR6BPBCQR_cjs=require('../chunk-R6BPBCQR.cjs');require('../chunk-Z2CIDSTP.cjs');var react=require('react'),jsxRuntime=require('react/jsx-runtime');var S=react.createContext(null);function H({children:a,config:n,locale:m}){let[l,p]=react.useState(false),[L,c]=react.useState(false),[G,i]=react.useState(null),[C,f]=react.useState(null),[x,v]=react.useState(m||"zh"),[k,w]=react.useState([]),[b,E]=react.useState([]),[U,r]=react.useState(false),[R,y]=react.useState(null),I=react.useCallback(async e=>{try{r(!0),y(null),await chunkR6BPBCQR_cjs.f.init(e),p(!0),c(chunkR6BPBCQR_cjs.f.isLoggedIn),i(chunkR6BPBCQR_cjs.f.user),f(chunkR6BPBCQR_cjs.f.token),v(chunkR6BPBCQR_cjs.f.locale);let[t,P]=await Promise.all([chunkR6BPBCQR_cjs.f.getGames(),chunkR6BPBCQR_cjs.f.getCategories()]);w(t),E(P);}catch(t){y(t instanceof Error?t:new Error("Initialization failed")),console.error("[PlaysoutProvider] Init error:",t);}finally{r(false);}},[]),z=react.useCallback(async e=>{try{r(!0),y(null);let t=await chunkR6BPBCQR_cjs.h.Login(e);return c(!0),i(chunkR6BPBCQR_cjs.f.user),f(chunkR6BPBCQR_cjs.f.token),t}catch(t){let P=t instanceof Error?t:new Error("Login failed");throw y(P),P}finally{r(false);}},[]),V=react.useCallback(()=>{chunkR6BPBCQR_cjs.f.logout(),c(false),i(null),f(null);},[]),D=react.useCallback(e=>{chunkR6BPBCQR_cjs.h.setLocale(e),v(e);},[]),K=react.useCallback(async e=>{try{return r(!0),await chunkR6BPBCQR_cjs.f.getGames(e)}finally{r(false);}},[]),T=react.useCallback(async()=>{try{return r(!0),await chunkR6BPBCQR_cjs.f.getCategories()}finally{r(false);}},[]),A=react.useCallback(async()=>{try{r(!0);let[e,t]=await Promise.all([chunkR6BPBCQR_cjs.f.getGames(),chunkR6BPBCQR_cjs.f.getCategories()]);w(e),E(t);}catch(e){y(e instanceof Error?e:new Error("Refresh failed"));}finally{r(false);}},[]),F=react.useCallback(async()=>{try{r(!0);let e=await chunkR6BPBCQR_cjs.f.getUserInfo();return i(chunkR6BPBCQR_cjs.f.user),e}finally{r(false);}},[]);react.useEffect(()=>{n&&!l&&I(n);},[n,l,I]),react.useEffect(()=>{if(!l)return;let e=()=>{c(chunkR6BPBCQR_cjs.f.isLoggedIn),i(chunkR6BPBCQR_cjs.f.user),f(chunkR6BPBCQR_cjs.f.token);},t=[chunkR6BPBCQR_cjs.h.on("login",e),chunkR6BPBCQR_cjs.h.on("logout",e),chunkR6BPBCQR_cjs.h.on("authExpired",e)];return ()=>{t.forEach(P=>P());}},[l]);let N={isInitialized:l,isLoggedIn:L,user:G,token:C,locale:x,games:k,categories:b,isLoading:U,error:R,init:I,Login:z,logout:V,setLocale:D,getGames:K,getCategories:T,refreshGames:A,getUserInfo:F};return jsxRuntime.jsx(S.Provider,{value:N,children:a})}function h(){let a=react.useContext(S);if(!a)throw new Error("usePlaysout must be used within PlaysoutProvider");return a}function J(a){let{games:n,getGames:m,isLoading:l,error:p}=h(),[L,c]=react.useState(n),[G,i]=react.useState(l);react.useEffect(()=>{c(n);},[n]),react.useEffect(()=>{i(l);},[l]);let C=react.useCallback(async f=>{i(true);try{let x=await m(f||a);c(x);}finally{i(false);}},[m,a]);return {games:L,isLoading:G,error:p,refresh:C}}function M(){let{categories:a,getCategories:n,isLoading:m}=h();return {categories:a,isLoading:m,refresh:n}}Object.defineProperty(exports,"Playsout",{enumerable:true,get:function(){return chunkR6BPBCQR_cjs.h}});exports.PlaysoutProvider=H;exports.useCategories=M;exports.useGames=J;exports.usePlaysout=h;
1
+ 'use strict';var chunkNHFWJCNJ_cjs=require('../chunk-NHFWJCNJ.cjs');require('../chunk-Z2CIDSTP.cjs');var react=require('react'),jsxRuntime=require('react/jsx-runtime');var S=react.createContext(null);function H({children:a,config:n,locale:m}){let[l,p]=react.useState(false),[L,c]=react.useState(false),[G,i]=react.useState(null),[C,f]=react.useState(null),[x,v]=react.useState(m||"zh"),[k,w]=react.useState([]),[b,E]=react.useState([]),[U,r]=react.useState(false),[R,y]=react.useState(null),I=react.useCallback(async o=>{try{r(!0),y(null),await chunkNHFWJCNJ_cjs.f.init(o),p(!0),c(chunkNHFWJCNJ_cjs.f.isLoggedIn),i(chunkNHFWJCNJ_cjs.f.user),f(chunkNHFWJCNJ_cjs.f.token),v(chunkNHFWJCNJ_cjs.f.locale);let[t,P]=await Promise.all([chunkNHFWJCNJ_cjs.f.getGames(),chunkNHFWJCNJ_cjs.f.getCategories()]);w(t),E(P);}catch(t){y(t instanceof Error?t:new Error("Initialization failed")),console.error("[PlaysoutProvider] Init error:",t);}finally{r(false);}},[]),z=react.useCallback(async o=>{try{r(!0),y(null);let t=await chunkNHFWJCNJ_cjs.h.Login(o);return c(chunkNHFWJCNJ_cjs.f.isLoggedIn),i(chunkNHFWJCNJ_cjs.f.user),f(chunkNHFWJCNJ_cjs.f.token),t}catch(t){let P=t instanceof Error?t:new Error("Login failed");throw y(P),P}finally{r(false);}},[]),V=react.useCallback(()=>{chunkNHFWJCNJ_cjs.f.logout(),c(false),i(null),f(null);},[]),D=react.useCallback(o=>{chunkNHFWJCNJ_cjs.h.setLocale(o),v(o);},[]),K=react.useCallback(async o=>{try{return r(!0),await chunkNHFWJCNJ_cjs.f.getGames(o)}finally{r(false);}},[]),T=react.useCallback(async()=>{try{return r(!0),await chunkNHFWJCNJ_cjs.f.getCategories()}finally{r(false);}},[]),A=react.useCallback(async()=>{try{r(!0);let[o,t]=await Promise.all([chunkNHFWJCNJ_cjs.f.getGames(),chunkNHFWJCNJ_cjs.f.getCategories()]);w(o),E(t);}catch(o){y(o instanceof Error?o:new Error("Refresh failed"));}finally{r(false);}},[]),F=react.useCallback(async()=>{try{r(!0);let o=await chunkNHFWJCNJ_cjs.f.getUserInfo();return i(chunkNHFWJCNJ_cjs.f.user),o}finally{r(false);}},[]);react.useEffect(()=>{n&&!l&&I(n);},[n,l,I]),react.useEffect(()=>{if(!l)return;let o=()=>{c(chunkNHFWJCNJ_cjs.f.isLoggedIn),i(chunkNHFWJCNJ_cjs.f.user),f(chunkNHFWJCNJ_cjs.f.token);},t=[chunkNHFWJCNJ_cjs.h.on("login",o),chunkNHFWJCNJ_cjs.h.on("logout",o),chunkNHFWJCNJ_cjs.h.on("authExpired",o)];return ()=>{t.forEach(P=>P());}},[l]);let N={isInitialized:l,isLoggedIn:L,user:G,token:C,locale:x,games:k,categories:b,isLoading:U,error:R,init:I,Login:z,logout:V,setLocale:D,getGames:K,getCategories:T,refreshGames:A,getUserInfo:F};return jsxRuntime.jsx(S.Provider,{value:N,children:a})}function h(){let a=react.useContext(S);if(!a)throw new Error("usePlaysout must be used within PlaysoutProvider");return a}function J(a){let{games:n,getGames:m,isLoading:l,error:p}=h(),[L,c]=react.useState(n),[G,i]=react.useState(l);react.useEffect(()=>{c(n);},[n]),react.useEffect(()=>{i(l);},[l]);let C=react.useCallback(async f=>{i(true);try{let x=await m(f||a);c(x);}finally{i(false);}},[m,a]);return {games:L,isLoading:G,error:p,refresh:C}}function M(){let{categories:a,getCategories:n,isLoading:m}=h();return {categories:a,isLoading:m,refresh:n}}Object.defineProperty(exports,"Playsout",{enumerable:true,get:function(){return chunkNHFWJCNJ_cjs.h}});exports.PlaysoutProvider=H;exports.useCategories=M;exports.useGames=J;exports.usePlaysout=h;
package/react/index.js CHANGED
@@ -1 +1 @@
1
- import {f,h as h$1}from'../chunk-I2HADAGI.js';export{h as Playsout}from'../chunk-I2HADAGI.js';import'../chunk-EZLO3WY6.js';import {createContext,useState,useCallback,useEffect,useContext}from'react';import {jsx}from'react/jsx-runtime';var S=createContext(null);function H({children:a,config:n,locale:m}){let[l,p]=useState(false),[L,c]=useState(false),[G,i]=useState(null),[C,f$1]=useState(null),[x,v]=useState(m||"zh"),[k,w]=useState([]),[b,E]=useState([]),[U,r]=useState(false),[R,y]=useState(null),I=useCallback(async e=>{try{r(!0),y(null),await f.init(e),p(!0),c(f.isLoggedIn),i(f.user),f$1(f.token),v(f.locale);let[t,P]=await Promise.all([f.getGames(),f.getCategories()]);w(t),E(P);}catch(t){y(t instanceof Error?t:new Error("Initialization failed")),console.error("[PlaysoutProvider] Init error:",t);}finally{r(false);}},[]),z=useCallback(async e=>{try{r(!0),y(null);let t=await h$1.Login(e);return c(!0),i(f.user),f$1(f.token),t}catch(t){let P=t instanceof Error?t:new Error("Login failed");throw y(P),P}finally{r(false);}},[]),V=useCallback(()=>{f.logout(),c(false),i(null),f$1(null);},[]),D=useCallback(e=>{h$1.setLocale(e),v(e);},[]),K=useCallback(async e=>{try{return r(!0),await f.getGames(e)}finally{r(false);}},[]),T=useCallback(async()=>{try{return r(!0),await f.getCategories()}finally{r(false);}},[]),A=useCallback(async()=>{try{r(!0);let[e,t]=await Promise.all([f.getGames(),f.getCategories()]);w(e),E(t);}catch(e){y(e instanceof Error?e:new Error("Refresh failed"));}finally{r(false);}},[]),F=useCallback(async()=>{try{r(!0);let e=await f.getUserInfo();return i(f.user),e}finally{r(false);}},[]);useEffect(()=>{n&&!l&&I(n);},[n,l,I]),useEffect(()=>{if(!l)return;let e=()=>{c(f.isLoggedIn),i(f.user),f$1(f.token);},t=[h$1.on("login",e),h$1.on("logout",e),h$1.on("authExpired",e)];return ()=>{t.forEach(P=>P());}},[l]);let N={isInitialized:l,isLoggedIn:L,user:G,token:C,locale:x,games:k,categories:b,isLoading:U,error:R,init:I,Login:z,logout:V,setLocale:D,getGames:K,getCategories:T,refreshGames:A,getUserInfo:F};return jsx(S.Provider,{value:N,children:a})}function h(){let a=useContext(S);if(!a)throw new Error("usePlaysout must be used within PlaysoutProvider");return a}function J(a){let{games:n,getGames:m,isLoading:l,error:p}=h(),[L,c]=useState(n),[G,i]=useState(l);useEffect(()=>{c(n);},[n]),useEffect(()=>{i(l);},[l]);let C=useCallback(async f=>{i(true);try{let x=await m(f||a);c(x);}finally{i(false);}},[m,a]);return {games:L,isLoading:G,error:p,refresh:C}}function M(){let{categories:a,getCategories:n,isLoading:m}=h();return {categories:a,isLoading:m,refresh:n}}export{H as PlaysoutProvider,M as useCategories,J as useGames,h as usePlaysout};
1
+ import {f,h as h$1}from'../chunk-XDBADNFW.js';export{h as Playsout}from'../chunk-XDBADNFW.js';import'../chunk-EZLO3WY6.js';import {createContext,useState,useCallback,useEffect,useContext}from'react';import {jsx}from'react/jsx-runtime';var S=createContext(null);function H({children:a,config:n,locale:m}){let[l,p]=useState(false),[L,c]=useState(false),[G,i]=useState(null),[C,f$1]=useState(null),[x,v]=useState(m||"zh"),[k,w]=useState([]),[b,E]=useState([]),[U,r]=useState(false),[R,y]=useState(null),I=useCallback(async o=>{try{r(!0),y(null),await f.init(o),p(!0),c(f.isLoggedIn),i(f.user),f$1(f.token),v(f.locale);let[t,P]=await Promise.all([f.getGames(),f.getCategories()]);w(t),E(P);}catch(t){y(t instanceof Error?t:new Error("Initialization failed")),console.error("[PlaysoutProvider] Init error:",t);}finally{r(false);}},[]),z=useCallback(async o=>{try{r(!0),y(null);let t=await h$1.Login(o);return c(f.isLoggedIn),i(f.user),f$1(f.token),t}catch(t){let P=t instanceof Error?t:new Error("Login failed");throw y(P),P}finally{r(false);}},[]),V=useCallback(()=>{f.logout(),c(false),i(null),f$1(null);},[]),D=useCallback(o=>{h$1.setLocale(o),v(o);},[]),K=useCallback(async o=>{try{return r(!0),await f.getGames(o)}finally{r(false);}},[]),T=useCallback(async()=>{try{return r(!0),await f.getCategories()}finally{r(false);}},[]),A=useCallback(async()=>{try{r(!0);let[o,t]=await Promise.all([f.getGames(),f.getCategories()]);w(o),E(t);}catch(o){y(o instanceof Error?o:new Error("Refresh failed"));}finally{r(false);}},[]),F=useCallback(async()=>{try{r(!0);let o=await f.getUserInfo();return i(f.user),o}finally{r(false);}},[]);useEffect(()=>{n&&!l&&I(n);},[n,l,I]),useEffect(()=>{if(!l)return;let o=()=>{c(f.isLoggedIn),i(f.user),f$1(f.token);},t=[h$1.on("login",o),h$1.on("logout",o),h$1.on("authExpired",o)];return ()=>{t.forEach(P=>P());}},[l]);let N={isInitialized:l,isLoggedIn:L,user:G,token:C,locale:x,games:k,categories:b,isLoading:U,error:R,init:I,Login:z,logout:V,setLocale:D,getGames:K,getCategories:T,refreshGames:A,getUserInfo:F};return jsx(S.Provider,{value:N,children:a})}function h(){let a=useContext(S);if(!a)throw new Error("usePlaysout must be used within PlaysoutProvider");return a}function J(a){let{games:n,getGames:m,isLoading:l,error:p}=h(),[L,c]=useState(n),[G,i]=useState(l);useEffect(()=>{c(n);},[n]),useEffect(()=>{i(l);},[l]);let C=useCallback(async f=>{i(true);try{let x=await m(f||a);c(x);}finally{i(false);}},[m,a]);return {games:L,isLoading:G,error:p,refresh:C}}function M(){let{categories:a,getCategories:n,isLoading:m}=h();return {categories:a,isLoading:m,refresh:n}}export{H as PlaysoutProvider,M as useCategories,J as useGames,h as usePlaysout};
package/vue/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkR6BPBCQR_cjs=require('../chunk-R6BPBCQR.cjs');require('../chunk-Z2CIDSTP.cjs');var vue=require('vue');var c=Symbol("PlaysoutSDK");function p(){let l=vue.ref(false),f=vue.ref(false),u=vue.ref(null),g=vue.ref(null),m=vue.ref("zh"),y=vue.ref([]),P=vue.ref([]),o=vue.ref(false),s=vue.ref(null),L=false,G=vue.computed(()=>s.value!==null);async function x(e){try{o.value=!0,s.value=null,await chunkR6BPBCQR_cjs.f.init(e),l.value=!0,i(),S(),await v();}catch(a){s.value=a instanceof Error?a:new Error("Initialization failed"),console.error("[usePlaysout] Init error:",a);}finally{o.value=false;}}function i(){f.value=chunkR6BPBCQR_cjs.f.isLoggedIn,u.value=chunkR6BPBCQR_cjs.f.user,g.value=chunkR6BPBCQR_cjs.f.token,m.value=chunkR6BPBCQR_cjs.f.locale;}function S(){L||(L=true,chunkR6BPBCQR_cjs.h.on("login",i),chunkR6BPBCQR_cjs.h.on("logout",i),chunkR6BPBCQR_cjs.h.on("authExpired",i));}async function b(e){try{o.value=!0,s.value=null;let a=await chunkR6BPBCQR_cjs.h.Login(e);return i(),a}catch(a){let d=a instanceof Error?a:new Error("Login failed");throw s.value=d,d}finally{o.value=false;}}function R(){chunkR6BPBCQR_cjs.f.logout(),i();}function E(e){chunkR6BPBCQR_cjs.h.setLocale(e),m.value=e;}async function h(e){try{return o.value=!0,await chunkR6BPBCQR_cjs.f.getGames(e)}finally{o.value=false;}}async function K(){try{return o.value=!0,await chunkR6BPBCQR_cjs.f.getCategories()}finally{o.value=false;}}async function v(){try{o.value=!0;let[e,a]=await Promise.all([chunkR6BPBCQR_cjs.f.getGames(),chunkR6BPBCQR_cjs.f.getCategories()]);y.value=e,P.value=a;}catch(e){s.value=e instanceof Error?e:new Error("Refresh failed");}finally{o.value=false;}}return {isInitialized:l,isLoggedIn:f,user:u,token:g,locale:m,games:y,categories:P,isLoading:o,error:s,hasError:G,init:x,Login:b,logout:R,setLocale:E,getGames:h,getCategories:K,refreshGames:v}}function C(){let l=vue.inject(c);if(!l)throw new Error("usePlaysout must be used after calling createPlaysout()");return l}function k(l={}){return {install(f){let u=p();f.provide(c,u),l.config&&u.init(l.config);}}}Object.defineProperty(exports,"Playsout",{enumerable:true,get:function(){return chunkR6BPBCQR_cjs.h}});exports.createPlaysout=p;exports.createPlaysoutPlugin=k;exports.usePlaysout=C;
1
+ 'use strict';var chunkNHFWJCNJ_cjs=require('../chunk-NHFWJCNJ.cjs');require('../chunk-Z2CIDSTP.cjs');var vue=require('vue');var c=Symbol("PlaysoutSDK");function p(){let l=vue.ref(false),f=vue.ref(false),u=vue.ref(null),g=vue.ref(null),m=vue.ref("zh"),y=vue.ref([]),P=vue.ref([]),o=vue.ref(false),s=vue.ref(null),L=false,G=vue.computed(()=>s.value!==null);async function x(e){try{o.value=!0,s.value=null,await chunkNHFWJCNJ_cjs.f.init(e),l.value=!0,i(),S(),await v();}catch(a){s.value=a instanceof Error?a:new Error("Initialization failed"),console.error("[usePlaysout] Init error:",a);}finally{o.value=false;}}function i(){f.value=chunkNHFWJCNJ_cjs.f.isLoggedIn,u.value=chunkNHFWJCNJ_cjs.f.user,g.value=chunkNHFWJCNJ_cjs.f.token,m.value=chunkNHFWJCNJ_cjs.f.locale;}function S(){L||(L=true,chunkNHFWJCNJ_cjs.h.on("login",i),chunkNHFWJCNJ_cjs.h.on("logout",i),chunkNHFWJCNJ_cjs.h.on("authExpired",i));}async function b(e){try{o.value=!0,s.value=null;let a=await chunkNHFWJCNJ_cjs.h.Login(e);return i(),a}catch(a){let d=a instanceof Error?a:new Error("Login failed");throw s.value=d,d}finally{o.value=false;}}function R(){chunkNHFWJCNJ_cjs.f.logout(),i();}function E(e){chunkNHFWJCNJ_cjs.h.setLocale(e),m.value=e;}async function h(e){try{return o.value=!0,await chunkNHFWJCNJ_cjs.f.getGames(e)}finally{o.value=false;}}async function K(){try{return o.value=!0,await chunkNHFWJCNJ_cjs.f.getCategories()}finally{o.value=false;}}async function v(){try{o.value=!0;let[e,a]=await Promise.all([chunkNHFWJCNJ_cjs.f.getGames(),chunkNHFWJCNJ_cjs.f.getCategories()]);y.value=e,P.value=a;}catch(e){s.value=e instanceof Error?e:new Error("Refresh failed");}finally{o.value=false;}}return {isInitialized:l,isLoggedIn:f,user:u,token:g,locale:m,games:y,categories:P,isLoading:o,error:s,hasError:G,init:x,Login:b,logout:R,setLocale:E,getGames:h,getCategories:K,refreshGames:v}}function C(){let l=vue.inject(c);if(!l)throw new Error("usePlaysout must be used after calling createPlaysout()");return l}function k(l={}){return {install(f){let u=p();f.provide(c,u),l.config&&u.init(l.config);}}}Object.defineProperty(exports,"Playsout",{enumerable:true,get:function(){return chunkNHFWJCNJ_cjs.h}});exports.createPlaysout=p;exports.createPlaysoutPlugin=k;exports.usePlaysout=C;
package/vue/index.js CHANGED
@@ -1 +1 @@
1
- import {f,h}from'../chunk-I2HADAGI.js';export{h as Playsout}from'../chunk-I2HADAGI.js';import'../chunk-EZLO3WY6.js';import {ref,computed,inject}from'vue';var c=Symbol("PlaysoutSDK");function p(){let l=ref(false),f$1=ref(false),u=ref(null),g=ref(null),m=ref("zh"),y=ref([]),P=ref([]),o=ref(false),s=ref(null),L=false,G=computed(()=>s.value!==null);async function x(e){try{o.value=!0,s.value=null,await f.init(e),l.value=!0,i(),S(),await v();}catch(a){s.value=a instanceof Error?a:new Error("Initialization failed"),console.error("[usePlaysout] Init error:",a);}finally{o.value=false;}}function i(){f$1.value=f.isLoggedIn,u.value=f.user,g.value=f.token,m.value=f.locale;}function S(){L||(L=true,h.on("login",i),h.on("logout",i),h.on("authExpired",i));}async function b(e){try{o.value=!0,s.value=null;let a=await h.Login(e);return i(),a}catch(a){let d=a instanceof Error?a:new Error("Login failed");throw s.value=d,d}finally{o.value=false;}}function R(){f.logout(),i();}function E(e){h.setLocale(e),m.value=e;}async function h$1(e){try{return o.value=!0,await f.getGames(e)}finally{o.value=false;}}async function K(){try{return o.value=!0,await f.getCategories()}finally{o.value=false;}}async function v(){try{o.value=!0;let[e,a]=await Promise.all([f.getGames(),f.getCategories()]);y.value=e,P.value=a;}catch(e){s.value=e instanceof Error?e:new Error("Refresh failed");}finally{o.value=false;}}return {isInitialized:l,isLoggedIn:f$1,user:u,token:g,locale:m,games:y,categories:P,isLoading:o,error:s,hasError:G,init:x,Login:b,logout:R,setLocale:E,getGames:h$1,getCategories:K,refreshGames:v}}function C(){let l=inject(c);if(!l)throw new Error("usePlaysout must be used after calling createPlaysout()");return l}function k(l={}){return {install(f){let u=p();f.provide(c,u),l.config&&u.init(l.config);}}}export{p as createPlaysout,k as createPlaysoutPlugin,C as usePlaysout};
1
+ import {f,h}from'../chunk-XDBADNFW.js';export{h as Playsout}from'../chunk-XDBADNFW.js';import'../chunk-EZLO3WY6.js';import {ref,computed,inject}from'vue';var c=Symbol("PlaysoutSDK");function p(){let l=ref(false),f$1=ref(false),u=ref(null),g=ref(null),m=ref("zh"),y=ref([]),P=ref([]),o=ref(false),s=ref(null),L=false,G=computed(()=>s.value!==null);async function x(e){try{o.value=!0,s.value=null,await f.init(e),l.value=!0,i(),S(),await v();}catch(a){s.value=a instanceof Error?a:new Error("Initialization failed"),console.error("[usePlaysout] Init error:",a);}finally{o.value=false;}}function i(){f$1.value=f.isLoggedIn,u.value=f.user,g.value=f.token,m.value=f.locale;}function S(){L||(L=true,h.on("login",i),h.on("logout",i),h.on("authExpired",i));}async function b(e){try{o.value=!0,s.value=null;let a=await h.Login(e);return i(),a}catch(a){let d=a instanceof Error?a:new Error("Login failed");throw s.value=d,d}finally{o.value=false;}}function R(){f.logout(),i();}function E(e){h.setLocale(e),m.value=e;}async function h$1(e){try{return o.value=!0,await f.getGames(e)}finally{o.value=false;}}async function K(){try{return o.value=!0,await f.getCategories()}finally{o.value=false;}}async function v(){try{o.value=!0;let[e,a]=await Promise.all([f.getGames(),f.getCategories()]);y.value=e,P.value=a;}catch(e){s.value=e instanceof Error?e:new Error("Refresh failed");}finally{o.value=false;}}return {isInitialized:l,isLoggedIn:f$1,user:u,token:g,locale:m,games:y,categories:P,isLoading:o,error:s,hasError:G,init:x,Login:b,logout:R,setLocale:E,getGames:h$1,getCategories:K,refreshGames:v}}function C(){let l=inject(c);if(!l)throw new Error("usePlaysout must be used after calling createPlaysout()");return l}function k(l={}){return {install(f){let u=p();f.provide(c,u),l.config&&u.init(l.config);}}}export{p as createPlaysout,k as createPlaysoutPlugin,C as usePlaysout};
package/chunk-I2HADAGI.js DELETED
@@ -1,2 +0,0 @@
1
- import {c as c$1,b as b$1}from'./chunk-EZLO3WY6.js';var k=(p=>(p.NOT_INITIALIZED="NOT_INITIALIZED",p.ALREADY_INITIALIZED="ALREADY_INITIALIZED",p.NOT_LOGGED_IN="NOT_LOGGED_IN",p.TOKEN_EXPIRED="TOKEN_EXPIRED",p.INVALID_TOKEN="INVALID_TOKEN",p.NETWORK_ERROR="NETWORK_ERROR",p.TIMEOUT="TIMEOUT",p.SERVER_ERROR="SERVER_ERROR",p.API_ERROR="API_ERROR",p.INVALID_PARAMS="INVALID_PARAMS",p.MISSING_PARAMS="MISSING_PARAMS",p.FEATURE_NOT_SUPPORTED="FEATURE_NOT_SUPPORTED",p.UNKNOWN="UNKNOWN",p.PAYMENT_FAILED="PAYMENT_FAILED",p.SHARE_FAILED="SHARE_FAILED",p))(k||{}),y=class extends Error{constructor(t,r,i){super(r);this.code=t;this.details=i;this.name="SDKError";}toJSON(){return {name:this.name,code:this.code,message:this.message,details:this.details}}},W={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 l(o,e){return new y(o,W[o],e)}var w="playsout_",R=class{constructor(e){this.storage=e;}get(e){try{return this.storage.getItem(w+e)}catch{return null}}set(e,t){try{this.storage.setItem(w+e,t);}catch(r){console.warn("[PlaysoutSDK] Storage set failed:",r);}}remove(e){try{this.storage.removeItem(w+e);}catch{}}clear(){try{let e=[];for(let t=0;t<this.storage.length;t++){let r=this.storage.key(t);r&&r.startsWith(w)&&e.push(r);}e.forEach(t=>this.storage.removeItem(t));}catch{}}},N=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 v(o="localStorage"){return typeof window>"u"||o==="memory"?new N:o==="sessionStorage"?new R(sessionStorage):new R(localStorage)}var I=v(),g={get:o=>I.get(o),set:(o,e)=>{I.set(o,e);},remove:o=>{I.remove(o);},clear:()=>{I.clear();},getJSON:o=>{let e=I.get(o);if(!e)return null;try{return JSON.parse(e)}catch{return null}},setJSON:(o,e)=>{I.set(o,JSON.stringify(e));},configure(o){I=v(o);}},c={TOKEN_DATA:"token_data",USER:"user",LOCALE:"locale",CONFIG:"config"};var $=o=>{if(!o)return o;try{let e=new URL(o);if(e.hostname==="games.playsout.com"){let t=e.pathname,r=t.endsWith("/"),i=/\.[a-z0-9]+$/i.test(t);!r&&!i&&(e.pathname=`${t}/`);}return e.toString()}catch{return o}},J=o=>o.map(e=>{if(!e.externalUrl)return e;let t=$(e.externalUrl);return t===e.externalUrl?e:{...e,externalUrl:t}}),Z=[{id:"BlockCrushFun",title:"Block Crush Fun",category:"Puzzle",image:c$1("./games/BlockCrushFun.png"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/BlockCrushFun"},{id:"DogeSurvivors",title:"Doge Survivors",category:"Doge OS",image:c$1("./games/DogeSurvivors.jpg"),isNew:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Doge/DogeSurvivors/"},{id:"DogeMaze",title:"Doge Maze",category:"Doge OS",image:c$1("./games/DogeMaze.jpg"),isNew:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Doge/DogeMaze/"},{id:"DogeMart",title:"Doge Mart",category:"Doge OS",image:c$1("./games/DogeMart.jpg"),isNew:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Doge/DogeMart/"},{id:"KittyEscape",title:"Kitty Escape",category:"Puzzle",image:c$1("./games/KittyEscape.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/KittyEscape/"},{id:"ProjectGarden",title:"Project: Garden",category:"Adventure",image:c$1("./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$1("./games/ProjectIDLE.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/idle/"},{id:"CulinaryStarWeb",title:"Culinary Star",category:"Casual",image:c$1("./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$1("./games/PickaxeQuest.jpg"),description:"Mining and adventure game",isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/PickaxeQuest/",apiGameId:73},{id:"MonsterSurvivors",title:"Monster Survivors",category:"Adventure",image:c$1("./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$1("./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$1("./games/MushroomWarriors.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/MushroomWarriors/"},{id:"FollowThePath",title:"Follow The Path",category:"Arcade",image:c$1("./games/FollowThePath.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/FollowThePath/"},{id:"ColorRun",title:"Color Run",category:"Arcade",image:c$1("./games/ColorRun.jpg"),isNew:false,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ColorRun/"},{id:"StupidArrow",title:"Stupid Arrow",category:"Arcade",image:c$1("./games/StupidArrow.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/StupidArrow/"},{id:"ZigZag",title:"Zig Zag",category:"Arcade",image:c$1("./games/ZigZag.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ZigZag/"},{id:"SpikesEverywhere",title:"Spikes Everywhere",category:"Arcade",image:c$1("./games/SpikesEverywhere.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/SpikesEverywhere/"},{id:"ArrowRacer",title:"Arrow Racer",category:"Arcade",image:c$1("./games/ArrowRacer.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ArrowRacer/"},{id:"CircleLeap",title:"Circle Leap",category:"Arcade",image:c$1("./games/CircleLeap.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CircleLeap/"},{id:"ColorMatcher",title:"Color Matcher",category:"Arcade",image:c$1("./games/ColorMatcher.jpg"),isNew:false,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ColorMatcher/"},{id:"EndlessMaze",title:"Endless Maze",category:"Arcade",image:c$1("./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$1("./games/SpinningAround.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/SpinningAround/"},{id:"BoomBallz",title:"Boom Ballz",category:"Arcade",image:c$1("./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$1("./games/CubeHead.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CubeHead/"},{id:"CapybaraLink",title:"Capybara Link",category:"Puzzle",image:c$1("./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$1("./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$1("./games/FishTankFury.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/FishTankFury/"},{id:"ConnectBalls",title:"Connect Balls",category:"Arcade",image:c$1("./games/ConnectBalls.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ConnectBalls/"},{id:"CircularBreaker",title:"Circular Breaker",category:"Arcade",image:c$1("./games/CircularBreaker.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CircularBreaker/"},{id:"OneDoor",title:"One Door",category:"Arcade",image:c$1("./games/OneDoor.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/OneDoor/"},{id:"CatchtheFruits",title:"Catch the Fruits",category:"Casual",image:c$1("./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$1("./games/Falling2048.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Falling2048/"}],x=J(Z),E=()=>x.filter(o=>o.enable);({Adventure:E().filter(o=>o.category==="Adventure"),Moba:E().filter(o=>o.category==="Moba")});var G=o=>x.find(e=>e.id===o);var K=()=>Array.from(new Set(E().map(o=>o.category)));var U="https://api.playsout.com",C=3e4;function V(o){let e=String(o?.platform||"").toLowerCase();if(e==="tiktok"){let t=o.authorizationCode;if(typeof t!="string"||!t.trim())throw l("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 l("MISSING_PARAMS","platformUserId is required for Grab/Eros login");if(typeof t.platformToken!="string"||!t.platformToken.trim())throw l("MISSING_PARAMS","platformToken is required for Grab/Eros login");return {platform:e,platformUserId:t.platformUserId,platformToken:t.platformToken,username:typeof t.username=="string"?t.username:void 0,inviteCode:typeof t.inviteCode=="string"?t.inviteCode:void 0}}throw l("INVALID_PARAMS","Unsupported platform. Expected grab, eros, or tiktok")}var A=null,O=null,L=null;function j(o){O=o;}function F(o){L=o;}function M(){if(L)try{L();}catch{}}async function z(o,e={},t,r=false){let i=t?.apiBaseUrl||U,d=o.startsWith("http")?o:`${i}${o}`,u=new AbortController,s=setTimeout(()=>u.abort(),C);try{let m=g.getJSON(c.TOKEN_DATA),f={"Content-Type":"application/json",...e.headers};m?.accessToken&&!f.token&&(f.token=m.accessToken);let h=await fetch(d,{...e,signal:u.signal,headers:f});if(clearTimeout(s),!h.ok){if(h.status===401&&r)return await H(o,e,t);throw l(h.status>=500?"SERVER_ERROR":"API_ERROR",`HTTP ${h.status}: ${h.statusText}`)}let D=await h.json();if(D.code!==1e4){if(r)return await H(o,e,t);throw l("API_ERROR",D.msg||"API request failed")}return D.data}catch(m){throw clearTimeout(s),m instanceof y?m:m instanceof Error?m.name==="AbortError"?l("TIMEOUT"):l("NETWORK_ERROR",m.message):l("UNKNOWN")}}async function H(o,e,t){await B(t);let r=t?.apiBaseUrl||U,i=o.startsWith("http")?o:`${r}${o}`,d=new AbortController,u=setTimeout(()=>d.abort(),C);try{let s=g.getJSON(c.TOKEN_DATA),m={"Content-Type":"application/json",...e.headers};s?.accessToken&&(m.token=s.accessToken);let f=await fetch(i,{...e,signal:d.signal,headers:m});if(clearTimeout(u),!f.ok)throw l(f.status>=500?"SERVER_ERROR":"API_ERROR",`HTTP ${f.status}: ${f.statusText}`);let h=await f.json();if(h.code!==1e4)throw l("API_ERROR",h.msg||"API request failed");return h.data}catch(s){throw clearTimeout(u),s instanceof y?s:s instanceof Error&&s.name==="AbortError"?l("TIMEOUT"):l("NETWORK_ERROR",s?.message||"Request failed")}}async function B(o){if(A)return A;let e=(async()=>{let t=g.getJSON(c.TOKEN_DATA),r=Math.floor(Date.now()/1e3);if(!t?.refreshToken||t.refreshExpiresAt<=r)throw M(),l("TOKEN_EXPIRED","Refresh token has expired");let i=o?.apiBaseUrl||U,d=new AbortController,u=setTimeout(()=>d.abort(),C);try{let s=await fetch(`${i}/platform/refreshToken`,{method:"POST",signal:d.signal,headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:t.refreshToken})});if(clearTimeout(u),!s.ok)throw s.status>=500?l("SERVER_ERROR",`HTTP ${s.status}: ${s.statusText}`):l("TOKEN_EXPIRED",`HTTP ${s.status}: ${s.statusText}`);let m=await s.json();if(m.code!==1e4||!m.data)throw l("TOKEN_EXPIRED",m.msg||"Failed to refresh token");let f=m.data;if(g.setJSON(c.TOKEN_DATA,f),O)try{O(f);}catch{}return f}catch(s){throw clearTimeout(u),s instanceof y?((s.code==="TOKEN_EXPIRED"||s.code==="NOT_LOGGED_IN")&&M(),s):s instanceof Error&&s.name==="AbortError"?l("TIMEOUT"):l("NETWORK_ERROR",s?.message||"Refresh token failed")}})();A=e;try{return await e}finally{A===e&&(A=null);}}var b=class{constructor(){this.config=null;}configure(e){this.config=e;}async refreshToken(){return await B(this.config||void 0)}async getGames(e){let t=E();if(e?.category&&(t=t.filter(r=>r.category===e.category)),e?.search){let r=e.search.toLowerCase();t=t.filter(i=>i.title.toLowerCase().includes(r)||i.category.toLowerCase().includes(r)||i.description&&i.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=E(),t=new Map;return e.forEach(r=>{let i=t.get(r.category)||0;t.set(r.category,i+1);}),Array.from(t.entries()).map(([r,i],d)=>({id:`category_${d}`,name:r,count:i}))}async getGameById(e){return G(e)}async getCategoryNames(){return K()}async loginOnly(e){let t=V(e);return await z("/platform/login",{method:"POST",body:JSON.stringify(t)},this.config??void 0)}async Login(e){let t=await this.loginOnly(e),r;try{r=await this.getUserInfo();}catch{}return {tokenData:t,user:r}}async getUserInfo(){return await z("/platform/user",{method:"GET"},this.config??void 0,true)}async getUser(){return g.getJSON(c.USER)}async validateToken(e){return !!e}},_=null;function P(){return _||(_=new b),_}var X="https://api.playsout.com",q="zh",S=class o{constructor(){this.config=null;this._isInitialized=false;this._user=null;this._token=null;this._locale=q;this._widget=null;}clearAuthState(){let e=!!(this._token||g.get(c.TOKEN_DATA)||g.get(c.USER));return this._user=null,this._token=null,g.remove(c.TOKEN_DATA),g.remove(c.USER),e}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 l("ALREADY_INITIALIZED");this.config={apiBaseUrl:e.apiBaseUrl||X,debug:e.debug||false,storage:e.storage||"localStorage",locale:e.locale||q,appId:e.appId||""},g.configure(this.config.storage),j(i=>{this._token=i.accessToken;}),F(()=>{this.handleAuthExpired();});let t=g.getJSON(c.TOKEN_DATA);this._user=g.getJSON(c.USER),this._locale=g.get(c.LOCALE)||this.config.locale;let r=Math.floor(Date.now()/1e3);if(t)if(!t.refreshToken||t.refreshExpiresAt<=r)this.handleAuthExpired();else if(t.accessToken&&t.expiresAt>r)this._token=t.accessToken;else try{let i=P();i.configure(this.config),await i.refreshToken();}catch(i){if(!(i instanceof y&&(i.code==="TOKEN_EXPIRED"||i.code==="NOT_LOGGED_IN")))throw i}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,g.clear(),b$1.clear();}get isInitialized(){return this._isInitialized}get isLoggedIn(){return !!this._token}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);let t=P();t.configure(this.config);let r=await t.loginOnly(e);g.setJSON(c.TOKEN_DATA,r),this.config?.debug&&console.log("[PlaysoutSDK] Token saved, expires at:",new Date(r.expiresAt*1e3).toISOString());let i;try{i=await t.getUserInfo();}catch(u){if(u instanceof y&&(u.code==="TOKEN_EXPIRED"||u.code==="NOT_LOGGED_IN"||u.code==="INVALID_TOKEN"))throw u;this.config?.debug&&console.log("[PlaysoutSDK] getUserInfo failed, login still success:",u);}let d=g.getJSON(c.TOKEN_DATA);return this._token=d?.accessToken||r.accessToken,i&&(this._user={userId:String(i.id),username:i.username},g.setJSON(c.USER,this._user)),this.config?.debug&&console.log("[PlaysoutSDK] Login success, user:",i),b$1.emit("login",{user:this._user,token:this._token}),{tokenData:r,user:i}}async getUserInfo(){if(this.ensureInitialized(),!this._token)throw l("NOT_LOGGED_IN","Please login first");let e=P();e.configure(this.config);let t=await e.getUserInfo();return this.config?.debug&&console.log("[PlaysoutSDK] getUserInfo result:",t),t&&(this._user={userId:String(t.id),username:t.username},g.setJSON(c.USER,this._user)),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 l("INVALID_PARAMS",`Unsupported locale: ${e}`);this._locale=e,g.set(c.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=E();if(e?.category&&(t=t.filter(r=>r.category===e.category)),e?.search){let r=e.search.toLowerCase();t=t.filter(i=>i.title.toLowerCase().includes(r)||i.category.toLowerCase().includes(r)||i.description&&i.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=E(),t=new Map;return e.forEach(r=>{let i=t.get(r.category)||0;t.set(r.category,i+1);}),Array.from(t.entries()).map(([r,i],d)=>({id:`category_${d}`,name:r,count:i}))}async getGameById(e){return this.ensureInitialized(),E().find(t=>t.id===e)}mount(e,t){if(this.ensureInitialized(),typeof document>"u")throw l("FEATURE_NOT_SUPPORTED","mount requires DOM environment");let r=document.querySelector(e);if(!r)throw l("INVALID_PARAMS",`Container not found: ${e}`);let i=document.createElement("playsout-widget");this.config?.appId&&i.setAttribute("app-id",this.config.appId),i.setAttribute("locale",t?.locale||this._locale),t?.detailMode&&i.setAttribute("detail-mode",t.detailMode),this._widget=i,t?.onGameClick&&i.addEventListener("game-click",d=>{let u=d;t.onGameClick(u.detail);}),t?.onLoginRequired&&i.addEventListener("login-required",t.onLoginRequired),t?.onLocaleChange&&i.addEventListener("locale-change",d=>{let u=d;t.onLocaleChange(u.detail);}),r.appendChild(i),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 l("NOT_INITIALIZED")}},a=S.getInstance(),fe=a;typeof window<"u"&&(window.__playsout_sdk_instance=a);var Ee=Object.freeze({init:a.init.bind(a),mount:a.mount.bind(a),unmount:a.unmount.bind(a),destroy:a.destroy.bind(a),Login:a.Login.bind(a),logout:a.logout.bind(a),getToken:a.getToken.bind(a),getUserInfo:a.getUserInfo.bind(a),getUser:a.getUser.bind(a),setLocale:a.setLocale.bind(a),getLocale:a.getLocale.bind(a),getGames:a.getGames.bind(a),getCategories:a.getCategories.bind(a),on:a.on.bind(a),off:a.off.bind(a),get isInitialized(){return a.isInitialized},get isLoggedIn(){return a.isLoggedIn},instance:a,PlaysoutSDKClass:S});
2
- export{k as a,y as b,g as c,c as d,S as e,a as f,fe as g,Ee as h};
@@ -1,2 +0,0 @@
1
- 'use strict';var chunkZ2CIDSTP_cjs=require('./chunk-Z2CIDSTP.cjs');var k=(p=>(p.NOT_INITIALIZED="NOT_INITIALIZED",p.ALREADY_INITIALIZED="ALREADY_INITIALIZED",p.NOT_LOGGED_IN="NOT_LOGGED_IN",p.TOKEN_EXPIRED="TOKEN_EXPIRED",p.INVALID_TOKEN="INVALID_TOKEN",p.NETWORK_ERROR="NETWORK_ERROR",p.TIMEOUT="TIMEOUT",p.SERVER_ERROR="SERVER_ERROR",p.API_ERROR="API_ERROR",p.INVALID_PARAMS="INVALID_PARAMS",p.MISSING_PARAMS="MISSING_PARAMS",p.FEATURE_NOT_SUPPORTED="FEATURE_NOT_SUPPORTED",p.UNKNOWN="UNKNOWN",p.PAYMENT_FAILED="PAYMENT_FAILED",p.SHARE_FAILED="SHARE_FAILED",p))(k||{}),y=class extends Error{constructor(t,r,i){super(r);this.code=t;this.details=i;this.name="SDKError";}toJSON(){return {name:this.name,code:this.code,message:this.message,details:this.details}}},W={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 l(o,e){return new y(o,W[o],e)}var w="playsout_",R=class{constructor(e){this.storage=e;}get(e){try{return this.storage.getItem(w+e)}catch{return null}}set(e,t){try{this.storage.setItem(w+e,t);}catch(r){console.warn("[PlaysoutSDK] Storage set failed:",r);}}remove(e){try{this.storage.removeItem(w+e);}catch{}}clear(){try{let e=[];for(let t=0;t<this.storage.length;t++){let r=this.storage.key(t);r&&r.startsWith(w)&&e.push(r);}e.forEach(t=>this.storage.removeItem(t));}catch{}}},N=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 v(o="localStorage"){return typeof window>"u"||o==="memory"?new N:o==="sessionStorage"?new R(sessionStorage):new R(localStorage)}var I=v(),g={get:o=>I.get(o),set:(o,e)=>{I.set(o,e);},remove:o=>{I.remove(o);},clear:()=>{I.clear();},getJSON:o=>{let e=I.get(o);if(!e)return null;try{return JSON.parse(e)}catch{return null}},setJSON:(o,e)=>{I.set(o,JSON.stringify(e));},configure(o){I=v(o);}},c={TOKEN_DATA:"token_data",USER:"user",LOCALE:"locale",CONFIG:"config"};var $=o=>{if(!o)return o;try{let e=new URL(o);if(e.hostname==="games.playsout.com"){let t=e.pathname,r=t.endsWith("/"),i=/\.[a-z0-9]+$/i.test(t);!r&&!i&&(e.pathname=`${t}/`);}return e.toString()}catch{return o}},J=o=>o.map(e=>{if(!e.externalUrl)return e;let t=$(e.externalUrl);return t===e.externalUrl?e:{...e,externalUrl:t}}),Z=[{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/BlockCrushFun"},{id:"DogeSurvivors",title:"Doge Survivors",category:"Doge OS",image:chunkZ2CIDSTP_cjs.c("./games/DogeSurvivors.jpg"),isNew:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Doge/DogeSurvivors/"},{id:"DogeMaze",title:"Doge Maze",category:"Doge OS",image:chunkZ2CIDSTP_cjs.c("./games/DogeMaze.jpg"),isNew:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Doge/DogeMaze/"},{id:"DogeMart",title:"Doge Mart",category:"Doge OS",image:chunkZ2CIDSTP_cjs.c("./games/DogeMart.jpg"),isNew:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Doge/DogeMart/"},{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/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:"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/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/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/FollowThePath/"},{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/ColorRun/"},{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/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/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/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/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/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/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/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/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/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/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/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/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/Falling2048/"}],x=J(Z),E=()=>x.filter(o=>o.enable);({Adventure:E().filter(o=>o.category==="Adventure"),Moba:E().filter(o=>o.category==="Moba")});var G=o=>x.find(e=>e.id===o);var K=()=>Array.from(new Set(E().map(o=>o.category)));var U="https://api.playsout.com",C=3e4;function V(o){let e=String(o?.platform||"").toLowerCase();if(e==="tiktok"){let t=o.authorizationCode;if(typeof t!="string"||!t.trim())throw l("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 l("MISSING_PARAMS","platformUserId is required for Grab/Eros login");if(typeof t.platformToken!="string"||!t.platformToken.trim())throw l("MISSING_PARAMS","platformToken is required for Grab/Eros login");return {platform:e,platformUserId:t.platformUserId,platformToken:t.platformToken,username:typeof t.username=="string"?t.username:void 0,inviteCode:typeof t.inviteCode=="string"?t.inviteCode:void 0}}throw l("INVALID_PARAMS","Unsupported platform. Expected grab, eros, or tiktok")}var A=null,O=null,L=null;function j(o){O=o;}function F(o){L=o;}function M(){if(L)try{L();}catch{}}async function z(o,e={},t,r=false){let i=t?.apiBaseUrl||U,d=o.startsWith("http")?o:`${i}${o}`,u=new AbortController,s=setTimeout(()=>u.abort(),C);try{let m=g.getJSON(c.TOKEN_DATA),f={"Content-Type":"application/json",...e.headers};m?.accessToken&&!f.token&&(f.token=m.accessToken);let h=await fetch(d,{...e,signal:u.signal,headers:f});if(clearTimeout(s),!h.ok){if(h.status===401&&r)return await H(o,e,t);throw l(h.status>=500?"SERVER_ERROR":"API_ERROR",`HTTP ${h.status}: ${h.statusText}`)}let D=await h.json();if(D.code!==1e4){if(r)return await H(o,e,t);throw l("API_ERROR",D.msg||"API request failed")}return D.data}catch(m){throw clearTimeout(s),m instanceof y?m:m instanceof Error?m.name==="AbortError"?l("TIMEOUT"):l("NETWORK_ERROR",m.message):l("UNKNOWN")}}async function H(o,e,t){await B(t);let r=t?.apiBaseUrl||U,i=o.startsWith("http")?o:`${r}${o}`,d=new AbortController,u=setTimeout(()=>d.abort(),C);try{let s=g.getJSON(c.TOKEN_DATA),m={"Content-Type":"application/json",...e.headers};s?.accessToken&&(m.token=s.accessToken);let f=await fetch(i,{...e,signal:d.signal,headers:m});if(clearTimeout(u),!f.ok)throw l(f.status>=500?"SERVER_ERROR":"API_ERROR",`HTTP ${f.status}: ${f.statusText}`);let h=await f.json();if(h.code!==1e4)throw l("API_ERROR",h.msg||"API request failed");return h.data}catch(s){throw clearTimeout(u),s instanceof y?s:s instanceof Error&&s.name==="AbortError"?l("TIMEOUT"):l("NETWORK_ERROR",s?.message||"Request failed")}}async function B(o){if(A)return A;let e=(async()=>{let t=g.getJSON(c.TOKEN_DATA),r=Math.floor(Date.now()/1e3);if(!t?.refreshToken||t.refreshExpiresAt<=r)throw M(),l("TOKEN_EXPIRED","Refresh token has expired");let i=o?.apiBaseUrl||U,d=new AbortController,u=setTimeout(()=>d.abort(),C);try{let s=await fetch(`${i}/platform/refreshToken`,{method:"POST",signal:d.signal,headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:t.refreshToken})});if(clearTimeout(u),!s.ok)throw s.status>=500?l("SERVER_ERROR",`HTTP ${s.status}: ${s.statusText}`):l("TOKEN_EXPIRED",`HTTP ${s.status}: ${s.statusText}`);let m=await s.json();if(m.code!==1e4||!m.data)throw l("TOKEN_EXPIRED",m.msg||"Failed to refresh token");let f=m.data;if(g.setJSON(c.TOKEN_DATA,f),O)try{O(f);}catch{}return f}catch(s){throw clearTimeout(u),s instanceof y?((s.code==="TOKEN_EXPIRED"||s.code==="NOT_LOGGED_IN")&&M(),s):s instanceof Error&&s.name==="AbortError"?l("TIMEOUT"):l("NETWORK_ERROR",s?.message||"Refresh token failed")}})();A=e;try{return await e}finally{A===e&&(A=null);}}var b=class{constructor(){this.config=null;}configure(e){this.config=e;}async refreshToken(){return await B(this.config||void 0)}async getGames(e){let t=E();if(e?.category&&(t=t.filter(r=>r.category===e.category)),e?.search){let r=e.search.toLowerCase();t=t.filter(i=>i.title.toLowerCase().includes(r)||i.category.toLowerCase().includes(r)||i.description&&i.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=E(),t=new Map;return e.forEach(r=>{let i=t.get(r.category)||0;t.set(r.category,i+1);}),Array.from(t.entries()).map(([r,i],d)=>({id:`category_${d}`,name:r,count:i}))}async getGameById(e){return G(e)}async getCategoryNames(){return K()}async loginOnly(e){let t=V(e);return await z("/platform/login",{method:"POST",body:JSON.stringify(t)},this.config??void 0)}async Login(e){let t=await this.loginOnly(e),r;try{r=await this.getUserInfo();}catch{}return {tokenData:t,user:r}}async getUserInfo(){return await z("/platform/user",{method:"GET"},this.config??void 0,true)}async getUser(){return g.getJSON(c.USER)}async validateToken(e){return !!e}},_=null;function P(){return _||(_=new b),_}var X="https://api.playsout.com",q="zh",S=class o{constructor(){this.config=null;this._isInitialized=false;this._user=null;this._token=null;this._locale=q;this._widget=null;}clearAuthState(){let e=!!(this._token||g.get(c.TOKEN_DATA)||g.get(c.USER));return this._user=null,this._token=null,g.remove(c.TOKEN_DATA),g.remove(c.USER),e}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 l("ALREADY_INITIALIZED");this.config={apiBaseUrl:e.apiBaseUrl||X,debug:e.debug||false,storage:e.storage||"localStorage",locale:e.locale||q,appId:e.appId||""},g.configure(this.config.storage),j(i=>{this._token=i.accessToken;}),F(()=>{this.handleAuthExpired();});let t=g.getJSON(c.TOKEN_DATA);this._user=g.getJSON(c.USER),this._locale=g.get(c.LOCALE)||this.config.locale;let r=Math.floor(Date.now()/1e3);if(t)if(!t.refreshToken||t.refreshExpiresAt<=r)this.handleAuthExpired();else if(t.accessToken&&t.expiresAt>r)this._token=t.accessToken;else try{let i=P();i.configure(this.config),await i.refreshToken();}catch(i){if(!(i instanceof y&&(i.code==="TOKEN_EXPIRED"||i.code==="NOT_LOGGED_IN")))throw i}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,g.clear(),chunkZ2CIDSTP_cjs.b.clear();}get isInitialized(){return this._isInitialized}get isLoggedIn(){return !!this._token}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);let t=P();t.configure(this.config);let r=await t.loginOnly(e);g.setJSON(c.TOKEN_DATA,r),this.config?.debug&&console.log("[PlaysoutSDK] Token saved, expires at:",new Date(r.expiresAt*1e3).toISOString());let i;try{i=await t.getUserInfo();}catch(u){if(u instanceof y&&(u.code==="TOKEN_EXPIRED"||u.code==="NOT_LOGGED_IN"||u.code==="INVALID_TOKEN"))throw u;this.config?.debug&&console.log("[PlaysoutSDK] getUserInfo failed, login still success:",u);}let d=g.getJSON(c.TOKEN_DATA);return this._token=d?.accessToken||r.accessToken,i&&(this._user={userId:String(i.id),username:i.username},g.setJSON(c.USER,this._user)),this.config?.debug&&console.log("[PlaysoutSDK] Login success, user:",i),chunkZ2CIDSTP_cjs.b.emit("login",{user:this._user,token:this._token}),{tokenData:r,user:i}}async getUserInfo(){if(this.ensureInitialized(),!this._token)throw l("NOT_LOGGED_IN","Please login first");let e=P();e.configure(this.config);let t=await e.getUserInfo();return this.config?.debug&&console.log("[PlaysoutSDK] getUserInfo result:",t),t&&(this._user={userId:String(t.id),username:t.username},g.setJSON(c.USER,this._user)),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 l("INVALID_PARAMS",`Unsupported locale: ${e}`);this._locale=e,g.set(c.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=E();if(e?.category&&(t=t.filter(r=>r.category===e.category)),e?.search){let r=e.search.toLowerCase();t=t.filter(i=>i.title.toLowerCase().includes(r)||i.category.toLowerCase().includes(r)||i.description&&i.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=E(),t=new Map;return e.forEach(r=>{let i=t.get(r.category)||0;t.set(r.category,i+1);}),Array.from(t.entries()).map(([r,i],d)=>({id:`category_${d}`,name:r,count:i}))}async getGameById(e){return this.ensureInitialized(),E().find(t=>t.id===e)}mount(e,t){if(this.ensureInitialized(),typeof document>"u")throw l("FEATURE_NOT_SUPPORTED","mount requires DOM environment");let r=document.querySelector(e);if(!r)throw l("INVALID_PARAMS",`Container not found: ${e}`);let i=document.createElement("playsout-widget");this.config?.appId&&i.setAttribute("app-id",this.config.appId),i.setAttribute("locale",t?.locale||this._locale),t?.detailMode&&i.setAttribute("detail-mode",t.detailMode),this._widget=i,t?.onGameClick&&i.addEventListener("game-click",d=>{let u=d;t.onGameClick(u.detail);}),t?.onLoginRequired&&i.addEventListener("login-required",t.onLoginRequired),t?.onLocaleChange&&i.addEventListener("locale-change",d=>{let u=d;t.onLocaleChange(u.detail);}),r.appendChild(i),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 l("NOT_INITIALIZED")}},a=S.getInstance(),fe=a;typeof window<"u"&&(window.__playsout_sdk_instance=a);var Ee=Object.freeze({init:a.init.bind(a),mount:a.mount.bind(a),unmount:a.unmount.bind(a),destroy:a.destroy.bind(a),Login:a.Login.bind(a),logout:a.logout.bind(a),getToken:a.getToken.bind(a),getUserInfo:a.getUserInfo.bind(a),getUser:a.getUser.bind(a),setLocale:a.setLocale.bind(a),getLocale:a.getLocale.bind(a),getGames:a.getGames.bind(a),getCategories:a.getCategories.bind(a),on:a.on.bind(a),off:a.off.bind(a),get isInitialized(){return a.isInitialized},get isLoggedIn(){return a.isLoggedIn},instance:a,PlaysoutSDKClass:S});
2
- exports.a=k;exports.b=y;exports.c=g;exports.d=c;exports.e=S;exports.f=a;exports.g=fe;exports.h=Ee;