@xiboplayer/pwa 0.7.1 → 0.7.2

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.
Files changed (38) hide show
  1. package/dist/assets/{chunk-config-DqswDQz2.js → chunk-config-BqpCSJ87.js} +2 -2
  2. package/dist/assets/{chunk-config-DqswDQz2.js.map → chunk-config-BqpCSJ87.js.map} +1 -1
  3. package/dist/assets/{index-Bn7yexJC.js → index-BBp7Yeqp.js} +2 -2
  4. package/dist/assets/{index-Bn7yexJC.js.map → index-BBp7Yeqp.js.map} +1 -1
  5. package/dist/assets/{index-DOWqpi1W.js → index-BGzZpdzW.js} +2 -2
  6. package/dist/assets/{index-DOWqpi1W.js.map → index-BGzZpdzW.js.map} +1 -1
  7. package/dist/assets/{index-K17x7fv_.js → index-Bj01q2d4.js} +2 -2
  8. package/dist/assets/{index-K17x7fv_.js.map → index-Bj01q2d4.js.map} +1 -1
  9. package/dist/assets/{index-Bgo3B90-.js → index-BmnGgxhy.js} +2 -2
  10. package/dist/assets/{index-Bgo3B90-.js.map → index-BmnGgxhy.js.map} +1 -1
  11. package/dist/assets/{index-DYMccG7M.js → index-DNyHrXGf.js} +2 -2
  12. package/dist/assets/{index-DYMccG7M.js.map → index-DNyHrXGf.js.map} +1 -1
  13. package/dist/assets/{index--0TbPToz.js → index-DPUPuUO8.js} +2 -2
  14. package/dist/assets/{index--0TbPToz.js.map → index-DPUPuUO8.js.map} +1 -1
  15. package/dist/assets/index-DwQpyIXq.js +2 -0
  16. package/dist/assets/{index-xijlgGv2.js.map → index-DwQpyIXq.js.map} +1 -1
  17. package/dist/assets/{index-CpSQnOTy.js → index-O4mn_OO0.js} +2 -2
  18. package/dist/assets/{index-CpSQnOTy.js.map → index-O4mn_OO0.js.map} +1 -1
  19. package/dist/assets/{index-CdHwqlmo.js → index-mYGuS183.js} +2 -2
  20. package/dist/assets/{index-CdHwqlmo.js.map → index-mYGuS183.js.map} +1 -1
  21. package/dist/assets/{index-9iMTvtYp.js → index-zursmDNN.js} +2 -2
  22. package/dist/assets/{index-9iMTvtYp.js.map → index-zursmDNN.js.map} +1 -1
  23. package/dist/assets/{main-Brs62d3-.js → main-Ddgs1h5h.js} +4 -4
  24. package/dist/assets/main-Ddgs1h5h.js.map +1 -0
  25. package/dist/assets/{protocol-detector-TSZru2q-.js → protocol-detector-UOvkmuFn.js} +2 -2
  26. package/dist/assets/{protocol-detector-TSZru2q-.js.map → protocol-detector-UOvkmuFn.js.map} +1 -1
  27. package/dist/assets/{setup-C2E5DwAO.js → setup-DcthBcbI.js} +2 -2
  28. package/dist/assets/{setup-C2E5DwAO.js.map → setup-DcthBcbI.js.map} +1 -1
  29. package/dist/assets/{sync-manager-C-mx1NcP.js → sync-manager-4de0XUYN.js} +2 -2
  30. package/dist/assets/{sync-manager-C-mx1NcP.js.map → sync-manager-4de0XUYN.js.map} +1 -1
  31. package/dist/assets/{widget-html-7qheOFv5.js → widget-html-p3dC5HGH.js} +2 -2
  32. package/dist/assets/{widget-html-7qheOFv5.js.map → widget-html-p3dC5HGH.js.map} +1 -1
  33. package/dist/index.html +3 -3
  34. package/dist/setup.html +3 -3
  35. package/dist/sw-pwa.js +1 -1
  36. package/package.json +16 -14
  37. package/dist/assets/index-xijlgGv2.js +0 -2
  38. package/dist/assets/main-Brs62d3-.js.map +0 -1
@@ -1,5 +1,5 @@
1
- const O="0.7.1",U={version:O},u={DEBUG:0,INFO:1,WARNING:2,ERROR:3,NONE:4},m=[];class q{constructor(e,t=null){this.name=e,this.useGlobal=t===null,this.useGlobal||this.setLevel(t)}_ts(){const e=new Date;return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}.${String(e.getMilliseconds()).padStart(3,"0")}`}setLevel(e){this.useGlobal=!1,typeof e=="string"?this.level=u[e.toUpperCase()]??u.INFO:this.level=e}getEffectiveLevel(){return this.useGlobal?d.level:this.level}debug(...e){this.getEffectiveLevel()<=u.DEBUG&&console.log(`${this._ts()} [${this.name}] DEBUG:`,...e),w("debug",this.name,e)}info(...e){this.getEffectiveLevel()<=u.INFO&&console.log(`${this._ts()} [${this.name}]`,...e),w("info",this.name,e)}warn(...e){this.getEffectiveLevel()<=u.WARNING&&console.warn(`${this._ts()} [${this.name}]`,...e),w("warning",this.name,e)}error(...e){this.getEffectiveLevel()<=u.ERROR&&console.error(`${this._ts()} [${this.name}]`,...e),w("error",this.name,e)}log(e,...t){switch(e.toUpperCase()){case"DEBUG":return this.debug(...t);case"INFO":return this.info(...t);case"WARNING":case"WARN":return this.warn(...t);case"ERROR":return this.error(...t)}}}const d={level:u.WARNING,setGlobalLevel(r){typeof r=="string"?this.level=u[r.toUpperCase()]??u.INFO:this.level=r,console.log(`[Logger] Global log level set to: ${this.getLevelName(this.level)}`)},getLevelName(r){return Object.keys(u).find(e=>u[e]===r)||"UNKNOWN"}};let C=!1;if(typeof window<"u"){const e=new URLSearchParams(window.location.search).get("logLevel"),t=localStorage.getItem("xibo_log_level");e?(d.setGlobalLevel(e),C=!0):t?(d.setGlobalLevel(t),C=!0):d.setGlobalLevel("WARNING")}else typeof self<"u"&&self.swLogLevel&&d.setGlobalLevel(self.swLogLevel);function D(r,e=null){return new q(r,e)}function V(r){d.setGlobalLevel(r),typeof window<"u"&&localStorage.setItem("xibo_log_level",r.toUpperCase())}function Z(){return d.getLevelName(d.level)}function Q(){return d.level<=u.DEBUG}function ee(r){if(C||!r)return!1;const e=G(r);return d.setGlobalLevel(e),!0}function G(r){switch((r||"").toLowerCase()){case"debug":return"DEBUG";case"info":case"notice":case"audit":return"INFO";case"warning":return"WARNING";case"error":case"critical":case"alert":case"emergency":return"ERROR";default:return"INFO"}}function w(r,e,t){if(m.length!==0)for(const s of m)try{s({level:r,name:e,args:t})}catch{}}function te(r){m.push(r)}function se(r){const e=m.indexOf(r);e>=0&&m.splice(e,1)}class ae{constructor(){this.events=new Map}on(e,t){this.events.has(e)||this.events.set(e,[]),this.events.get(e).push(t)}once(e,t){const s=(...a)=>{t(...a),this.off(e,s)};this.on(e,s)}off(e,t){if(!this.events.has(e))return;const s=this.events.get(e),a=s.indexOf(t);a!==-1&&s.splice(a,1)}emit(e,...t){if(!this.events.has(e))return;const s=this.events.get(e).slice();for(const a of s)a(...t)}removeAllListeners(e){e?this.events.delete(e):this.events.clear()}}function T(r,e){const t=new Uint8Array(r);let s="";for(let n=0;n<t.length;n++)s+=String.fromCharCode(t[n]);const a=btoa(s),i=[];for(let n=0;n<a.length;n+=64)i.push(a.substring(n,n+64));return`-----BEGIN ${e}-----
1
+ const O="0.7.2",U={version:O},u={DEBUG:0,INFO:1,WARNING:2,ERROR:3,NONE:4},m=[];class q{constructor(e,t=null){this.name=e,this.useGlobal=t===null,this.useGlobal||this.setLevel(t)}_ts(){const e=new Date;return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}.${String(e.getMilliseconds()).padStart(3,"0")}`}setLevel(e){this.useGlobal=!1,typeof e=="string"?this.level=u[e.toUpperCase()]??u.INFO:this.level=e}getEffectiveLevel(){return this.useGlobal?d.level:this.level}debug(...e){this.getEffectiveLevel()<=u.DEBUG&&console.log(`${this._ts()} [${this.name}] DEBUG:`,...e),w("debug",this.name,e)}info(...e){this.getEffectiveLevel()<=u.INFO&&console.log(`${this._ts()} [${this.name}]`,...e),w("info",this.name,e)}warn(...e){this.getEffectiveLevel()<=u.WARNING&&console.warn(`${this._ts()} [${this.name}]`,...e),w("warning",this.name,e)}error(...e){this.getEffectiveLevel()<=u.ERROR&&console.error(`${this._ts()} [${this.name}]`,...e),w("error",this.name,e)}log(e,...t){switch(e.toUpperCase()){case"DEBUG":return this.debug(...t);case"INFO":return this.info(...t);case"WARNING":case"WARN":return this.warn(...t);case"ERROR":return this.error(...t)}}}const d={level:u.WARNING,setGlobalLevel(r){typeof r=="string"?this.level=u[r.toUpperCase()]??u.INFO:this.level=r,console.log(`[Logger] Global log level set to: ${this.getLevelName(this.level)}`)},getLevelName(r){return Object.keys(u).find(e=>u[e]===r)||"UNKNOWN"}};let C=!1;if(typeof window<"u"){const e=new URLSearchParams(window.location.search).get("logLevel"),t=localStorage.getItem("xibo_log_level");e?(d.setGlobalLevel(e),C=!0):t?(d.setGlobalLevel(t),C=!0):d.setGlobalLevel("WARNING")}else typeof self<"u"&&self.swLogLevel&&d.setGlobalLevel(self.swLogLevel);function D(r,e=null){return new q(r,e)}function V(r){d.setGlobalLevel(r),typeof window<"u"&&localStorage.setItem("xibo_log_level",r.toUpperCase())}function Z(){return d.getLevelName(d.level)}function Q(){return d.level<=u.DEBUG}function ee(r){if(C||!r)return!1;const e=G(r);return d.setGlobalLevel(e),!0}function G(r){switch((r||"").toLowerCase()){case"debug":return"DEBUG";case"info":case"notice":case"audit":return"INFO";case"warning":return"WARNING";case"error":case"critical":case"alert":case"emergency":return"ERROR";default:return"INFO"}}function w(r,e,t){if(m.length!==0)for(const s of m)try{s({level:r,name:e,args:t})}catch{}}function te(r){m.push(r)}function se(r){const e=m.indexOf(r);e>=0&&m.splice(e,1)}class ae{constructor(){this.events=new Map}on(e,t){this.events.has(e)||this.events.set(e,[]),this.events.get(e).push(t)}once(e,t){const s=(...a)=>{t(...a),this.off(e,s)};this.on(e,s)}off(e,t){if(!this.events.has(e))return;const s=this.events.get(e),a=s.indexOf(t);a!==-1&&s.splice(a,1)}emit(e,...t){if(!this.events.has(e))return;const s=this.events.get(e).slice();for(const a of s)a(...t)}removeAllListeners(e){e?this.events.delete(e):this.events.clear()}}function T(r,e){const t=new Uint8Array(r);let s="";for(let n=0;n<t.length;n++)s+=String.fromCharCode(t[n]);const a=btoa(s),i=[];for(let n=0;n<a.length;n+=64)i.push(a.substring(n,n+64));return`-----BEGIN ${e}-----
2
2
  ${i.join(`
3
3
  `)}
4
4
  -----END ${e}-----`}async function M(){const r=await crypto.subtle.generateKey({name:"RSA-OAEP",modulusLength:1024,publicExponent:new Uint8Array([1,0,1]),hash:"SHA-256"},!0,["encrypt","decrypt"]),e=await crypto.subtle.exportKey("spki",r.publicKey),t=await crypto.subtle.exportKey("pkcs8",r.privateKey);return{publicKeyPem:T(e,"PUBLIC KEY"),privateKeyPem:T(t,"PRIVATE KEY")}}function B(r){return!r||typeof r!="string"?!1:/^-----BEGIN (PUBLIC KEY|PRIVATE KEY)-----\n[A-Za-z0-9+/=\n]+\n-----END \1-----$/.test(r.trim())}function E(r,e,t,s={}){return typeof indexedDB>"u"?Promise.reject(new Error("IndexedDB not available")):new Promise((a,i)=>{const n=indexedDB.open(r,e);n.onupgradeneeded=()=>{const o=n.result;if(!o.objectStoreNames.contains(t)){const l=s.keyPath?{keyPath:s.keyPath,autoIncrement:!0}:void 0,c=o.createObjectStore(t,l);s.indexName&&s.indexKey&&c.createIndex(s.indexName,s.indexKey,{unique:!1})}},n.onsuccess=()=>a(n.result),n.onerror=()=>i(n.error)})}var P={};const $="xibo_global",g="xibo_cms:",S="xibo_active_cms",L="xibo-hw-backup",_=1,j=new Set(["hardwareKey","xmrPubKey","xmrPrivKey"]);function k(r){let e=2166136261;for(let s=0;s<r.length;s++)e^=r.charCodeAt(s),e+=(e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24);e=e>>>0;let t=e+1234567;for(let s=0;s<r.length;s++)t^=r.charCodeAt(s)+1,t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24);return t=t>>>0,(e.toString(16).padStart(8,"0")+t.toString(16).padStart(8,"0")).substring(0,12)}function x(r){if(!r)return null;try{const e=new URL(r),t=e.origin;return`${e.hostname}-${k(t)}`}catch{return`unknown-${k(r)}`}}function F(){const r=typeof process<"u"&&P?P:{},e={cmsUrl:r.CMS_URL||"",cmsKey:r.CMS_KEY||"",displayName:r.DISPLAY_NAME||"",hardwareKey:r.HARDWARE_KEY||"",xmrChannel:r.XMR_CHANNEL||"",googleGeoApiKey:r.GOOGLE_GEO_API_KEY||""};return Object.values(e).some(s=>s!=="")?e:null}class H{constructor(){this._activeCmsId=null,this.data=this.load(),this._fromEnv||this._restoreHardwareKeyFromBackup()}load(){const e=F();return e?(this._fromEnv=!0,e):typeof localStorage>"u"?{cmsUrl:"",cmsKey:"",displayName:"",hardwareKey:"",xmrChannel:""}:localStorage.getItem($)?this._loadSplit():this._loadFresh()}_loadSplit(){let e={};try{e=JSON.parse(localStorage.getItem($)||"{}")}catch(i){console.error("[Config] Failed to parse xibo_global:",i)}const t=localStorage.getItem(S)||null;this._activeCmsId=t;let s={};if(t)try{const i=localStorage.getItem(g+t);i&&(s=JSON.parse(i))}catch(i){console.error("[Config] Failed to parse CMS config:",i)}const a={...e,...s};return this._validateConfig(a)}_loadFresh(){const e={};return this._validateConfig(e)}_validateConfig(e){let t=!1;return!e.hardwareKey||e.hardwareKey.length<10?(console.warn("[Config] Missing/invalid hardwareKey — generating"),e.hardwareKey=this.generateStableHardwareKey(),this._backupHardwareKey(e.hardwareKey),t=!0):console.log("[Config] ✓ Loaded existing hardwareKey:",e.hardwareKey),e.xmrChannel||(console.warn("[Config] Missing xmrChannel — generating"),e.xmrChannel=this.generateXmrChannel(),t=!0),e.cmsUrl=e.cmsUrl||"",e.cmsKey=e.cmsKey||"",e.displayName=e.displayName||"",t&&typeof localStorage<"u"&&this._saveSplit(e),e}save(){typeof localStorage>"u"||this._saveSplit(this.data)}_saveSplit(e){if(typeof localStorage>"u")return;const t={},s={};for(const[i,n]of Object.entries(e))j.has(i)?t[i]=n:s[i]=n;localStorage.setItem($,JSON.stringify(t));const a=x(e.cmsUrl);a&&(localStorage.setItem(g+a,JSON.stringify(s)),localStorage.setItem(S,a),this._activeCmsId=a),localStorage.setItem("xibo_config",JSON.stringify(e))}switchCms(e){if(typeof localStorage>"u")throw new Error("switchCms requires localStorage (browser only)");this.save();const t=x(e);if(!t)throw new Error("Invalid CMS URL");const s=localStorage.getItem(g+t);let a={},i=!0;if(s)try{a=JSON.parse(s),i=!1,console.log(`[Config] Switching to existing CMS profile: ${t}`)}catch(o){console.error("[Config] Failed to parse target CMS config:",o)}else console.log(`[Config] Creating new CMS profile: ${t}`),a={cmsUrl:e,cmsKey:"",displayName:"",xmrChannel:this.generateXmrChannel()},localStorage.setItem(g+t,JSON.stringify(a));localStorage.setItem(S,t),this._activeCmsId=t;let n={};try{n=JSON.parse(localStorage.getItem($)||"{}")}catch{}return this.data={...n,...a},this.data.cmsUrl||(this.data.cmsUrl=e),{cmsId:t,isNew:i}}listCmsProfiles(){if(typeof localStorage>"u")return[];const e=[],t=localStorage.getItem(S)||null;for(let s=0;s<localStorage.length;s++){const a=localStorage.key(s);if(!a.startsWith(g))continue;const i=a.slice(g.length);try{const n=JSON.parse(localStorage.getItem(a));e.push({cmsId:i,cmsUrl:n.cmsUrl||"",displayName:n.displayName||"",isActive:i===t})}catch{}}return e}get activeCmsId(){var t;if(this._activeCmsId)return this._activeCmsId;const e=x((t=this.data)==null?void 0:t.cmsUrl);return this._activeCmsId=e,e}isConfigured(){return!!(this.data.cmsUrl&&this.data.cmsKey&&this.data.displayName)}async _backupKeys(e){try{const t=await E(L,_,"keys"),s=t.transaction("keys","readwrite"),a=s.objectStore("keys");for(const[i,n]of Object.entries(e))a.put(n,i);s.oncomplete=()=>{console.log("[Config] Keys backed up to IndexedDB:",Object.keys(e).join(", ")),t.close()}}catch{}}_backupHardwareKey(e){this._backupKeys({hardwareKey:e})}async _restoreHardwareKeyFromBackup(){try{const e=await E(L,_,"keys"),s=e.transaction("keys","readonly").objectStore("keys"),a=await new Promise(i=>{const n=s.get("hardwareKey");n.onsuccess=()=>i(n.result),n.onerror=()=>i(null)});e.close(),a&&a!==this.data.hardwareKey?(console.log("[Config] Restoring hardware key from IndexedDB backup:",a),console.log("[Config] (was:",this.data.hardwareKey,")"),this.data.hardwareKey=a,this.save()):!a&&this.data.hardwareKey&&this._backupHardwareKey(this.data.hardwareKey)}catch{}}generateStableHardwareKey(){if(typeof crypto<"u"&&crypto.randomUUID){const a="pwa-"+crypto.randomUUID().replace(/-/g,"").substring(0,28);return console.log("[Config] Generated new UUID-based hardware key:",a),a}const t="pwa-"+Array.from({length:28},()=>Math.floor(Math.random()*16).toString(16)).join("");return console.log("[Config] Generated new random hardware key:",t),t}generateXmrChannel(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}async ensureXmrKeyPair(){if(this.data.xmrPubKey&&B(this.data.xmrPubKey))return;console.log("[Config] Generating RSA key pair for XMR registration...");const{publicKeyPem:e,privateKeyPem:t}=await M();this.data.xmrPubKey=e,this.data.xmrPrivKey=t,this.save(),typeof indexedDB<"u"&&this._backupKeys({xmrPubKey:e,xmrPrivKey:t}),console.log("[Config] RSA key pair generated and saved")}get cmsUrl(){return this.data.cmsUrl}set cmsUrl(e){this.data.cmsUrl=e,this.save()}get cmsKey(){return this.data.cmsKey}set cmsKey(e){this.data.cmsKey=e,this.save()}get displayName(){return this.data.displayName}set displayName(e){this.data.displayName=e,this.save()}get hardwareKey(){return this.data.hardwareKey||(console.error("[Config] CRITICAL: hardwareKey missing! Generating emergency key."),this.data.hardwareKey=this.generateStableHardwareKey(),this.save()),this.data.hardwareKey}get xmrChannel(){return this.data.xmrChannel||(console.warn("[Config] xmrChannel missing at access time — generating"),this.data.xmrChannel=this.generateXmrChannel(),this.save()),this.data.xmrChannel}get xmrPubKey(){return this.data.xmrPubKey||""}get xmrPrivKey(){return this.data.xmrPrivKey||""}get googleGeoApiKey(){return this.data.googleGeoApiKey||""}set googleGeoApiKey(e){this.data.googleGeoApiKey=e,this.save()}get controls(){return this.data.controls||{}}get transport(){return this.data.transport||"auto"}get debug(){return this.data.debug||{}}}const W=new H,Y={kioskMode:["electron","chromium"],autoLaunch:["electron"],allowShellCommands:["electron","chromium"],browser:["chromium"],extraBrowserFlags:["chromium"]};function re(r,e){if(!r||!e)return;const t=e.toLowerCase();for(const[s,a]of Object.entries(Y))s in r&&!a.includes(t)&&console.warn(`[Config] Key "${s}" is only supported on ${a.join("/")}, but current platform is ${t} — this key will be ignored`)}const z=new Set(["serverPort","kioskMode","fullscreen","hideMouseCursor","preventSleep","allowShellCommands","width","height","relaxSslCerts"]);function ne(r,e){const t=new Set([...z,...e||[]]),s={};for(const[a,i]of Object.entries(r))t.has(a)||(s[a]=i);return Object.keys(s).length>0?s:void 0}const b=D("FetchRetry"),A=3e4,K=12e4;function R(r){if(!r)return A;const e=Number(r);if(!isNaN(e)&&e>=0)return Math.min(e*1e3,K);const t=new Date(r);if(!isNaN(t.getTime())){const s=t.getTime()-Date.now();return Math.min(Math.max(s,0),K)}return A}async function ie(r,e={},t={}){const{maxRetries:s=3,baseDelayMs:a=1e3,maxDelayMs:i=3e4}=t;let n,o;for(let l=0;l<=s;l++){try{const c=await fetch(r,e);if(c.status===429){const y=R(c.headers.get("Retry-After"));if(b.debug(`429 Rate limited, waiting ${y}ms (Retry-After: ${c.headers.get("Retry-After")})`),o=c,n=new Error("HTTP 429: Too Many Requests"),n.status=429,l<s){await new Promise(p=>setTimeout(p,y));continue}break}if(c.status<500)return c;if(o=c,n=new Error(`HTTP ${c.status}: ${c.statusText}`),n.status=c.status,c.status===503&&l<s){const y=c.headers.get("Retry-After");if(y){const p=R(y);b.debug(`503 Service Unavailable, Retry-After: ${y} (${p}ms)`),await new Promise(N=>setTimeout(N,p));continue}}}catch(c){b.warn(`Fetch error (attempt ${l+1}/${s+1}):`,c.message||c,String(r).slice(0,80)),n=c,o=null}if(l<s){const y=Math.min(a*Math.pow(2,l),i)*(.5+Math.random()*.5);b.debug(`Retry ${l+1}/${s} in ${Math.round(y)}ms:`,String(r).slice(0,80)),await new Promise(p=>setTimeout(p,y))}}if(o)return o;throw n}const h=D("CmsApi");class oe{constructor({baseUrl:e,clientId:t,clientSecret:s,apiToken:a}={}){this.baseUrl=(e||"").replace(/\/+$/,""),this.clientId=t||null,this.clientSecret=s||null,this.accessToken=a||null,this.tokenExpiry=a?1/0:0}async authenticate(){h.info("Authenticating with CMS API...");const e=await fetch(`${this.baseUrl}/api/authorize/access_token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"client_credentials",client_id:this.clientId,client_secret:this.clientSecret})});if(!e.ok){const s=await e.text();throw new Error(`OAuth2 authentication failed (${e.status}): ${s}`)}const t=await e.json();return this.accessToken=t.access_token,this.tokenExpiry=Date.now()+(t.expires_in||3600)*1e3,h.info("Authenticated successfully, token expires in",t.expires_in,"s"),this.accessToken}async ensureToken(){if(!(this.accessToken&&Date.now()<this.tokenExpiry-6e4)){if(!this.clientId||!this.clientSecret){if(this.accessToken)return;throw new f("AUTH","/authorize",0,"No valid token and no OAuth2 credentials")}await this.authenticate()}}async request(e,t,s={}){await this.ensureToken();const a=new URL(`${this.baseUrl}/api${t}`),i={method:e,headers:{Authorization:`Bearer ${this.accessToken}`}};if(e==="GET")for(const[l,c]of Object.entries(s))c!=null&&a.searchParams.set(l,String(c));else i.headers["Content-Type"]="application/x-www-form-urlencoded",i.body=new URLSearchParams(s);const n=await fetch(a,i);return n.ok||await this._handleErrorResponse(n,e,t),(n.headers.get("Content-Type")||"").includes("application/json")?n.json():null}get(e,t){return this.request("GET",e,t)}post(e,t){return this.request("POST",e,t)}put(e,t){return this.request("PUT",e,t)}del(e){return this.request("DELETE",e)}async _listRequest(e,t={}){const s=await this.request("GET",e,t);return Array.isArray(s)?s:[]}async _handleErrorResponse(e,t,s){var n;const a=await e.text();let i;try{const o=JSON.parse(a);i=((n=o.error)==null?void 0:n.message)||o.message||a}catch{i=a}throw new f(t,s,e.status,i)}async findDisplay(e){h.info("Looking up display by hardwareKey:",e);const t=await this._listRequest("/display",{hardwareKey:e});if(t.length===0)return h.info("No display found for hardwareKey:",e),null;const s=t[0];return h.info(`Found display: ${s.display} (ID: ${s.displayId}, licensed: ${s.licensed})`),s}async authorizeDisplay(e){h.info("Authorizing display:",e),await this.request("PUT",`/display/authorise/${e}`),h.info("Display authorized successfully")}async editDisplay(e,t){return h.info("Editing display:",e,t),this.request("PUT",`/display/${e}`,t)}async listDisplays(e={}){return this._listRequest("/display",e)}async requestScreenshot(e){await this.request("PUT",`/display/requestscreenshot/${e}`)}async getDisplayStatus(e){return this.request("GET",`/display/status/${e}`)}async requestMultipart(e,t,s){await this.ensureToken();const a=`${this.baseUrl}/api${t}`,i=await fetch(a,{method:e,headers:{Authorization:`Bearer ${this.accessToken}`},body:s});return i.ok||await this._handleErrorResponse(i,e,t),(i.headers.get("Content-Type")||"").includes("application/json")?i.json():null}async createLayout({name:e,resolutionId:t,description:s}){const a={name:e,resolutionId:t};return s&&(a.description=s),this.request("POST","/layout",a)}async listLayouts(e={}){return this._listRequest("/layout",e)}async getLayout(e){return this.request("GET",`/layout/${e}`)}async deleteLayout(e){await this.request("DELETE",`/layout/${e}`)}async publishLayout(e){await this.request("PUT",`/layout/publish/${e}`,{publishNow:1})}async checkoutLayout(e){return this.request("PUT",`/layout/checkout/${e}`)}async getDraftLayout(e){const t=await this.listLayouts({parentId:e});return t.length>0?t[0]:null}async editLayoutBackground(e,t){return this.request("PUT",`/layout/background/${e}`,t)}async addRegion(e,t){return this.request("POST",`/region/${e}`,t)}async editRegion(e,t){return this.request("PUT",`/region/${e}`,t)}async deleteRegion(e){await this.request("DELETE",`/region/${e}`)}async addWidget(e,t,s={}){const{templateId:a,displayOrder:i,...n}=s,o={};a!==void 0&&(o.templateId=a),i!==void 0&&(o.displayOrder=i);const l=await this.request("POST",`/playlist/widget/${e}/${t}`,o);return Object.keys(n).length>0?(n.duration!==void 0&&n.useDuration===void 0&&(n.useDuration=1),this.request("PUT",`/playlist/widget/${l.widgetId}`,n)):l}async editWidget(e,t){return this.request("PUT",`/playlist/widget/${e}`,t)}async deleteWidget(e){await this.request("DELETE",`/playlist/widget/${e}`)}async uploadMedia(e){return this.requestMultipart("POST","/library",e)}async listMedia(e={}){return this._listRequest("/library",e)}async getMedia(e){return this.request("GET",`/library/${e}`)}async deleteMedia(e){await this.request("DELETE",`/library/${e}`)}async createCampaign(e){return this.request("POST","/campaign",{name:e})}async listCampaigns(e={}){return this._listRequest("/campaign",e)}async deleteCampaign(e){await this.request("DELETE",`/campaign/${e}`)}async assignLayoutToCampaign(e,t,s){const a={layoutId:t};s!==void 0&&(a.displayOrder=s),await this.request("POST",`/campaign/layout/assign/${e}`,a)}async createSchedule(e){const t={...e};Array.isArray(t.displayGroupIds)&&delete t.displayGroupIds,await this.ensureToken();const s=`${this.baseUrl}/api/schedule`,a=new URLSearchParams;for(const[o,l]of Object.entries(t))l!=null&&a.set(o,String(l));if(Array.isArray(e.displayGroupIds))for(const o of e.displayGroupIds)a.append("displayGroupIds[]",String(o));const i=await fetch(s,{method:"POST",headers:{Authorization:`Bearer ${this.accessToken}`,"Content-Type":"application/x-www-form-urlencoded"},body:a});if(!i.ok){const o=await i.text();throw new Error(`CMS API POST /schedule failed (${i.status}): ${o}`)}return(i.headers.get("Content-Type")||"").includes("application/json")?i.json():null}async deleteSchedule(e){await this.request("DELETE",`/schedule/${e}`)}async listSchedules(e={}){const t=await this.request("GET","/schedule/data/events",e);return Array.isArray(t)?t:(t==null?void 0:t.events)||[]}async listDisplayGroups(e={}){return this._listRequest("/displaygroup",e)}async createDisplayGroup(e,t){const s={displayGroup:e};return t&&(s.description=t),this.request("POST","/displaygroup",s)}async deleteDisplayGroup(e){await this.request("DELETE",`/displaygroup/${e}`)}async assignDisplayToGroup(e,t){await this.ensureToken();const s=`${this.baseUrl}/api/displaygroup/${e}/display/assign`,a=new URLSearchParams;a.append("displayId[]",String(t));const i=await fetch(s,{method:"POST",headers:{Authorization:`Bearer ${this.accessToken}`,"Content-Type":"application/x-www-form-urlencoded"},body:a});if(!i.ok){const n=await i.text();throw new Error(`CMS API assign display to group failed (${i.status}): ${n}`)}}async unassignDisplayFromGroup(e,t){await this.ensureToken();const s=`${this.baseUrl}/api/displaygroup/${e}/display/unassign`,a=new URLSearchParams;a.append("displayId[]",String(t));const i=await fetch(s,{method:"POST",headers:{Authorization:`Bearer ${this.accessToken}`,"Content-Type":"application/x-www-form-urlencoded"},body:a});if(!i.ok){const n=await i.text();throw new Error(`CMS API unassign display from group failed (${i.status}): ${n}`)}}async listResolutions(){return this._listRequest("/resolution")}async listTemplates(e={}){return this._listRequest("/template",e)}async assignMediaToPlaylist(e,t){const s=Array.isArray(t)?t:[t];await this.ensureToken();const a=`${this.baseUrl}/api/playlist/library/assign/${e}`,i=new URLSearchParams;for(const l of s)i.append("media[]",String(l));const n=await fetch(a,{method:"POST",headers:{Authorization:`Bearer ${this.accessToken}`,"Content-Type":"application/x-www-form-urlencoded"},body:i});if(!n.ok){const l=await n.text();throw new f("POST",`/playlist/library/assign/${e}`,n.status,l)}return(n.headers.get("Content-Type")||"").includes("application/json")?n.json():null}async editLayout(e,t){return this.request("PUT",`/layout/${e}`,t)}async copyLayout(e,t={}){return this.post(`/layout/copy/${e}`,t)}async discardLayout(e){await this.put(`/layout/discard/${e}`)}async editCampaign(e,t){return this.put(`/campaign/${e}`,t)}async getCampaign(e){return this.get(`/campaign/${e}`)}async unassignLayoutFromCampaign(e,t){await this.post(`/campaign/layout/unassign/${e}`,{layoutId:t})}async editSchedule(e,t){return this.put(`/schedule/${e}`,t)}async retireLayout(e){await this.put(`/layout/retire/${e}`)}async unretireLayout(e){await this.put(`/layout/unretire/${e}`)}async getLayoutStatus(e){return this.get(`/layout/status/${e}`)}async tagLayout(e,t){await this.post(`/layout/${e}/tag`,{tag:t.join(",")})}async untagLayout(e,t){await this.post(`/layout/${e}/untag`,{tag:t.join(",")})}async listCommands(e={}){return this._listRequest("/command",e)}async createCommand(e){return this.post("/command",e)}async editCommand(e,t){return this.put(`/command/${e}`,t)}async deleteCommand(e){await this.del(`/command/${e}`)}async deleteDisplay(e){await this.del(`/display/${e}`)}async wolDisplay(e){await this.post(`/display/wol/${e}`)}async setDefaultLayout(e,t){return this.put(`/display/${e}`,{defaultLayoutId:t})}async purgeDisplay(e){await this.post(`/display/purge/${e}`)}async listDayParts(e={}){return this._listRequest("/daypart",e)}async createDayPart(e){return this.post("/daypart",e)}async editDayPart(e,t){return this.put(`/daypart/${e}`,t)}async deleteDayPart(e){await this.del(`/daypart/${e}`)}async uploadMediaUrl(e,t){return this.post("/library",{url:e,name:t,type:"uri"})}async copyMedia(e){return this.post(`/library/copy/${e}`)}async downloadMedia(e){await this.ensureToken();const t=`${this.baseUrl}/api/library/download/${e}`,s=await fetch(t,{headers:{Authorization:`Bearer ${this.accessToken}`}});if(!s.ok){const a=await s.text();throw new f("GET",`/library/download/${e}`,s.status,a)}return s}async editMedia(e,t){return this.put(`/library/${e}`,t)}async getMediaUsage(e){return this.get(`/library/usage/${e}`)}async tidyLibrary(){await this.post("/library/tidy")}async listPlaylists(e={}){return this._listRequest("/playlist",e)}async createPlaylist(e){return this.post("/playlist",{name:e})}async getPlaylist(e){return this.get(`/playlist/${e}`)}async editPlaylist(e,t){return this.put(`/playlist/${e}`,t)}async deletePlaylist(e){await this.del(`/playlist/${e}`)}async reorderPlaylist(e,t){await this.ensureToken();const s=`${this.baseUrl}/api/playlist/order/${e}`,a=new URLSearchParams;for(const n of t)a.append("widgets[]",String(n));const i=await fetch(s,{method:"POST",headers:{Authorization:`Bearer ${this.accessToken}`,"Content-Type":"application/x-www-form-urlencoded"},body:a});if(!i.ok){const n=await i.text();throw new f("POST",`/playlist/order/${e}`,i.status,n)}}async copyPlaylist(e){return this.post(`/playlist/copy/${e}`)}async setWidgetTransition(e,t,s={}){return this.put(`/playlist/widget/transition/${e}`,{type:t,...s})}async setWidgetAudio(e,t){return this.put(`/playlist/widget/${e}/audio`,t)}async removeWidgetAudio(e){await this.del(`/playlist/widget/${e}/audio`)}async setWidgetExpiry(e,t){return this.put(`/playlist/widget/${e}/expiry`,t)}async saveAsTemplate(e,t){return this.post(`/template/${e}`,t)}async getTemplate(e){return this.get(`/template/${e}`)}async deleteTemplate(e){await this.del(`/template/${e}`)}async listDatasets(e={}){return this._listRequest("/dataset",e)}async createDataset(e){return this.post("/dataset",e)}async editDataset(e,t){return this.put(`/dataset/${e}`,t)}async deleteDataset(e){await this.del(`/dataset/${e}`)}async listDatasetColumns(e){return this._listRequest(`/dataset/${e}/column`)}async createDatasetColumn(e,t){return this.post(`/dataset/${e}/column`,t)}async editDatasetColumn(e,t,s){return this.put(`/dataset/${e}/column/${t}`,s)}async deleteDatasetColumn(e,t){await this.del(`/dataset/${e}/column/${t}`)}async listDatasetData(e,t={}){return this._listRequest(`/dataset/data/${e}`,t)}async addDatasetRow(e,t){return this.post(`/dataset/data/${e}`,t)}async editDatasetRow(e,t,s){return this.put(`/dataset/data/${e}/${t}`,s)}async deleteDatasetRow(e,t){await this.del(`/dataset/data/${e}/${t}`)}async importDatasetCsv(e,t){return this.requestMultipart("POST",`/dataset/import/${e}`,t)}async clearDataset(e){await this.del(`/dataset/data/${e}`)}async listNotifications(e={}){return this._listRequest("/notification",e)}async createNotification(e){return this.post("/notification",e)}async editNotification(e,t){return this.put(`/notification/${e}`,t)}async deleteNotification(e){await this.del(`/notification/${e}`)}async listFolders(e={}){return this._listRequest("/folder",e)}async createFolder(e){return this.post("/folder",e)}async editFolder(e,t){return this.put(`/folder/${e}`,t)}async deleteFolder(e){await this.del(`/folder/${e}`)}async listTags(e={}){return this._listRequest("/tag",e)}async createTag(e){return this.post("/tag",e)}async editTag(e,t){return this.put(`/tag/${e}`,t)}async deleteTag(e){await this.del(`/tag/${e}`)}async tagEntity(e,t,s){await this.post(`/${e}/${t}/tag`,{tag:s.join(",")})}async untagEntity(e,t,s){await this.post(`/${e}/${t}/untag`,{tag:s.join(",")})}async dgChangeLayout(e,t){await this.post(`/displaygroup/${e}/action/changeLayout`,{layoutId:t})}async dgOverlayLayout(e,t){await this.post(`/displaygroup/${e}/action/overlayLayout`,{layoutId:t})}async dgRevertToSchedule(e){await this.post(`/displaygroup/${e}/action/revertToSchedule`)}async dgCollectNow(e){await this.post(`/displaygroup/${e}/action/collectNow`)}async dgSendCommand(e,t){await this.post(`/displaygroup/${e}/action/command`,{commandId:t})}async editDisplayGroup(e,t){return this.put(`/displaygroup/${e}`,t)}}class f extends Error{constructor(e,t,s,a){super(`CMS API ${e} ${t} → ${s}: ${a}`),this.name="CmsApiError",this.method=e,this.path=t,this.status=s,this.detail=a}}const le=U.version,J="/player/api/v2";var I;let v=((I=W.data)==null?void 0:I.playerApiBase)||J,X=v;function ce(r){v=r.replace(/\/+$/,""),X=v}export{oe as CmsApiClient,f as CmsApiError,ae as EventEmitter,u as LOG_LEVELS,X as PLAYER_API,z as SHELL_ONLY_KEYS,le as VERSION,ee as applyCmsLogLevel,x as computeCmsId,W as config,D as createLogger,ne as extractPwaConfig,ie as fetchWithRetry,k as fnvHash,Z as getLogLevel,Q as isDebug,G as mapCmsLogLevel,E as openIDB,te as registerLogSink,V as setLogLevel,ce as setPlayerApi,se as unregisterLogSink,re as warnPlatformMismatch};
5
- //# sourceMappingURL=index-Bgo3B90-.js.map
5
+ //# sourceMappingURL=index-BmnGgxhy.js.map