@jolibox/sdk 1.0.6 → 1.0.7-beta.1

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/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var L=(i,o)=>{for(var e in o)f(i,e,{get:o[e],enumerable:!0})},k=(i,o,e,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of j(o))!J.call(i,t)&&t!==e&&f(i,t,{get:()=>o[t],enumerable:!(a=S(o,t))||a.enumerable});return i};var _=i=>k(f({},"__esModule",{value:!0}),i);var p=(i,o,e)=>new Promise((a,t)=>{var d=n=>{try{r(e.next(n))}catch(l){t(l)}},s=n=>{try{r(e.throw(n))}catch(l){t(l)}},r=n=>n.done?a(n.value):Promise.resolve(n.value).then(d,s);r((e=e.apply(i,o)).next())});var A={};L(A,{JoliboxSDK:()=>c,default:()=>v});module.exports=_(A);var b=i=>{var r,n,l;let o=i.split("-")[1];o&&(i=i.replace(`-${o}`,""));let e=i.split("+")[1];e&&(i=i.replace(`+${e}`,""));let a=i.split(".").slice(0,3),[t,d,s]=[(r=a[0])!=null?r:"0",(n=a[1])!=null?n:"0",(l=a[2])!=null?l:"0"];return{major:t,minor:d,patch:s,prerelease:o,build:e}},m=i=>parseInt(b(i).major,10),h=(i,o)=>{let{major:e,minor:a,patch:t}=b(i),{major:d,minor:s,patch:r}=b(o);return e!==d?e>d?1:-1:a!==s?a>s?1:-1:t!==r?t>r?1:-1:0};var y="jolibox-sdk-loader-metadata",x=class{constructor({loaderMetadata:o}={}){this.computeLoaderMetaData=()=>{var t,d;let o=this.currentVersion,e=null;try{if(e=JSON.parse((t=localStorage.getItem(y))!=null?t:"null"),!e||!e.version)throw new Error("Invalid loader metadata")}catch(s){e=this.defaultMetadata}let a=(d=e==null?void 0:e.version)!=null?d:o;return m(a)!==m(o)?e=this.defaultMetadata:h(a,o)<0&&(e=this.defaultMetadata),e};this.loadScript=()=>{if(this.loaderMetadata.syncScriptUrl){let o=new XMLHttpRequest;o.open("GET",this.loaderMetadata.syncScriptUrl,!1),o.send();let e=document.createElement("script");e.type="text/javascript",e.innerHTML=o.responseText,document.head.appendChild(e)}if(this.loaderMetadata.asyncScriptUrl){let o=document.createElement("script");o.type="text/javascript",o.src=this.loaderMetadata.asyncScriptUrl,o.async=!0,document.head.appendChild(o)}};this.fetchUpdateLoaderMetadata=(...d)=>p(this,[...d],function*(o=this.currentVersion,e=this.loaderMetadata.version,a=(t=>(t=window.JOLIBOX_ENV)!=null?t:"WEB")()){var r,n,l;let s=`${(n=(r=window.joliboxenv)==null?void 0:r.apiBaseURL)!=null?n:"https://api.jolibox.com"}/frontend/js-sdk/loader-metadata`;try{let w=yield(yield fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({installedSDKVersion:o,localSDKVersion:e,env:a})})).json();if(w.code!=="SUCCESS")throw new Error(w.message);this.loaderMetadata=(l=w.data)!=null?l:this.defaultMetadata,localStorage.setItem(y,JSON.stringify(this.loaderMetadata))}catch(g){console.warn("Failed to fetch loader metadata: ",g)}});console.log("Loading Jolibox SDK..."),this.loaderMetadata=o!=null?o:this.computeLoaderMetaData(),this.loadScript(),this.fetchUpdateLoaderMetadata(),console.log("Jolibox SDK loaded.")}get currentVersion(){return window.__JOLIBOX_LOCAL_SDK_VERSION__}get defaultMetadata(){let o=this.currentVersion,e=m(o);return{version:o,syncScriptUrl:`https://cdn.jsdelivr.net/npm/@jolibox/web-sync-sdk@${e}/dist/index.iife.js`,asyncScriptUrl:`https://cdn.jsdelivr.net/npm/@jolibox/web-async-sdk@${e}/dist/index.iife.js`}}};window.JoliboxSDKLoader=x;var u=class{constructor(){this.init=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.init",params:o})};this.adConfig=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.adConfig",params:o})};this.adBreak=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.adBreak",params:o})};this.adUnit=o=>p(this,null,function*(){window.joliboxsdk._commandPipe.push({cmd:"ads.adUnit",params:o})})}};window.JoliboxAds=u;var I=class{constructor(){this.trackEvent=(o,e)=>{if(typeof o!="string")throw new Error("eventName must be a string");if(e!==null&&typeof e!="object"&&e!==void 0)throw new Error("extra must be an object or null or undefined");if(e){for(let a in e)if(typeof e[a]=="object")throw new Error("extra must not have nested objects")}window.joliboxsdk._commandPipe.push({cmd:"analytics.trackEvent",params:[o,e]})}}};window.JoliboxAnalytics=I;var N=require("@jolibox/web-sync-sdk");window.__JOLIBOX_LOCAL_SDK_VERSION__="1.0.6";var c=class{constructor({useRuntimeSDK:o=!0,loaderConfig:e,testMode:a,apiBaseURL:t}={}){this.setJoliboxEnv=(o,e)=>{let t=typeof window<"u"?new URLSearchParams(window.location.search):null,d=(t==null?void 0:t.get("testMode"))==="true",s=o!=null?o:d,r=t==null?void 0:t.get("apiBaseURL"),n;e?n=e:r?n=r:n=s?"https://test-api.jolibox.com":"https://api.jolibox.com",window.joliboxenv={testMode:s,apiBaseURL:n}};var d,s,r,n;this.setJoliboxEnv(a,t),o&&window.joliboxsdk?(this.loader=(d=window.joliboxsdk.loader)!=null?d:new window.JoliboxSDKLoader(e),this.ads=(s=window.joliboxsdk.ads)!=null?s:new window.JoliboxAds,this.anaytics=(r=window.joliboxsdk.anaytics)!=null?r:new window.JoliboxAnalytics,this.runtime=(n=window.joliboxsdk.runtime)!=null?n:new window.JoliboxRuntime):(window.joliboxsdk||(window.joliboxsdk={_commandPipe:[]}),this.loader=new window.JoliboxSDKLoader(e),this.ads=new window.JoliboxAds,this.anaytics=new window.JoliboxAnalytics,this.runtime=new window.JoliboxRuntime,window.joliboxsdk=Object.assign(this,window.joliboxsdk)),window.joliboxsdk._commandPipe||(window.joliboxsdk._commandPipe=[])}};window.JoliboxSDK||(window.JoliboxSDK=c);var v=c;0&&(module.exports={JoliboxSDK});
1
+ "use strict";var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var L=(i,o)=>{for(var e in o)f(i,e,{get:o[e],enumerable:!0})},k=(i,o,e,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of j(o))!J.call(i,t)&&t!==e&&f(i,t,{get:()=>o[t],enumerable:!(a=S(o,t))||a.enumerable});return i};var _=i=>k(f({},"__esModule",{value:!0}),i);var p=(i,o,e)=>new Promise((a,t)=>{var d=n=>{try{r(e.next(n))}catch(l){t(l)}},s=n=>{try{r(e.throw(n))}catch(l){t(l)}},r=n=>n.done?a(n.value):Promise.resolve(n.value).then(d,s);r((e=e.apply(i,o)).next())});var A={};L(A,{JoliboxSDK:()=>c,default:()=>v});module.exports=_(A);var b=i=>{var r,n,l;let o=i.split("-")[1];o&&(i=i.replace(`-${o}`,""));let e=i.split("+")[1];e&&(i=i.replace(`+${e}`,""));let a=i.split(".").slice(0,3),[t,d,s]=[(r=a[0])!=null?r:"0",(n=a[1])!=null?n:"0",(l=a[2])!=null?l:"0"];return{major:t,minor:d,patch:s,prerelease:o,build:e}},m=i=>parseInt(b(i).major,10),h=(i,o)=>{let{major:e,minor:a,patch:t}=b(i),{major:d,minor:s,patch:r}=b(o);return e!==d?e>d?1:-1:a!==s?a>s?1:-1:t!==r?t>r?1:-1:0};var y="jolibox-sdk-loader-metadata",x=class{constructor({loaderMetadata:o}={}){this.computeLoaderMetaData=()=>{var t,d;let o=this.currentVersion,e=null;try{if(e=JSON.parse((t=localStorage.getItem(y))!=null?t:"null"),!e||!e.version)throw new Error("Invalid loader metadata")}catch(s){e=this.defaultMetadata}let a=(d=e==null?void 0:e.version)!=null?d:o;return m(a)!==m(o)?e=this.defaultMetadata:h(a,o)<0&&(e=this.defaultMetadata),e};this.loadScript=()=>{if(this.loaderMetadata.syncScriptUrl){let o=new XMLHttpRequest;o.open("GET",this.loaderMetadata.syncScriptUrl,!1),o.send();let e=document.createElement("script");e.type="text/javascript",e.innerHTML=o.responseText,document.head.appendChild(e)}if(this.loaderMetadata.asyncScriptUrl){let o=document.createElement("script");o.type="text/javascript",o.src=this.loaderMetadata.asyncScriptUrl,o.async=!0,document.head.appendChild(o)}};this.fetchUpdateLoaderMetadata=(...d)=>p(this,[...d],function*(o=this.currentVersion,e=this.loaderMetadata.version,a=(t=>(t=window.JOLIBOX_ENV)!=null?t:"WEB")()){var r,n,l;let s=`${(n=(r=window.joliboxenv)==null?void 0:r.apiBaseURL)!=null?n:"https://api.jolibox.com"}/frontend/js-sdk/loader-metadata`;try{let w=yield(yield fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({installedSDKVersion:o,localSDKVersion:e,env:a})})).json();if(w.code!=="SUCCESS")throw new Error(w.message);this.loaderMetadata=(l=w.data)!=null?l:this.defaultMetadata,localStorage.setItem(y,JSON.stringify(this.loaderMetadata))}catch(g){console.warn("Failed to fetch loader metadata: ",g)}});console.log("Loading Jolibox SDK..."),this.loaderMetadata=o!=null?o:this.computeLoaderMetaData(),this.loadScript(),this.fetchUpdateLoaderMetadata(),console.log("Jolibox SDK loaded.")}get currentVersion(){return window.__JOLIBOX_LOCAL_SDK_VERSION__}get defaultMetadata(){let o=this.currentVersion,e=m(o);return{version:o,syncScriptUrl:`https://cdn.jsdelivr.net/npm/@jolibox/web-sync-sdk@${e}/dist/index.iife.js`,asyncScriptUrl:`https://cdn.jsdelivr.net/npm/@jolibox/web-async-sdk@${e}/dist/index.iife.js`}}};window.JoliboxSDKLoader=x;var u=class{constructor(){this.init=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.init",params:o})};this.adConfig=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.adConfig",params:o})};this.adBreak=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.adBreak",params:o})};this.adUnit=o=>p(this,null,function*(){window.joliboxsdk._commandPipe.push({cmd:"ads.adUnit",params:o})})}};window.JoliboxAds=u;var I=class{constructor(){this.trackEvent=(o,e)=>{if(typeof o!="string")throw new Error("eventName must be a string");if(e!==null&&typeof e!="object"&&e!==void 0)throw new Error("extra must be an object or null or undefined");if(e){for(let a in e)if(typeof e[a]=="object")throw new Error("extra must not have nested objects")}window.joliboxsdk._commandPipe.push({cmd:"analytics.trackEvent",params:[o,e]})}}};window.JoliboxAnalytics=I;var N=require("@jolibox/web-sync-sdk");window.__JOLIBOX_LOCAL_SDK_VERSION__="1.0.7-beta.1";var c=class{constructor({useRuntimeSDK:o=!0,loaderConfig:e,testMode:a,apiBaseURL:t}={}){this.setJoliboxEnv=(o,e)=>{let t=typeof window<"u"?new URLSearchParams(window.location.search):null,d=(t==null?void 0:t.get("testMode"))==="true",s=o!=null?o:d,r=t==null?void 0:t.get("apiBaseURL"),n;e?n=e:r?n=r:n=s?"https://test-api.jolibox.com":"https://api.jolibox.com",window.joliboxenv={testMode:s,apiBaseURL:n}};var d,s,r,n;this.setJoliboxEnv(a,t),o&&window.joliboxsdk?(this.loader=(d=window.joliboxsdk.loader)!=null?d:new window.JoliboxSDKLoader(e),this.ads=(s=window.joliboxsdk.ads)!=null?s:new window.JoliboxAds,this.anaytics=(r=window.joliboxsdk.anaytics)!=null?r:new window.JoliboxAnalytics,this.runtime=(n=window.joliboxsdk.runtime)!=null?n:new window.JoliboxRuntime):(window.joliboxsdk||(window.joliboxsdk={_commandPipe:[]}),this.loader=new window.JoliboxSDKLoader(e),this.ads=new window.JoliboxAds,this.anaytics=new window.JoliboxAnalytics,this.runtime=new window.JoliboxRuntime,window.joliboxsdk=Object.assign(this,window.joliboxsdk)),window.joliboxsdk._commandPipe||(window.joliboxsdk._commandPipe=[])}};window.JoliboxSDK||(window.JoliboxSDK=c);var v=c;0&&(module.exports={JoliboxSDK});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/loader/utils.ts","../src/loader/index.ts","../src/ads/index.ts","../src/analytics/index.ts"],"sourcesContent":["import \"./loader\";\nimport \"./ads\";\nimport \"./analytics\";\nimport \"@jolibox/web-sync-sdk\";\nimport type { JoliboxSDKLoader, IJoliboxSDKLoaderConfig } from \"./loader\";\nimport type { JoliboxAds } from \"./ads\";\nimport type { JoliboxAnalytics } from \"./analytics\";\nimport type { JoliboxRuntime } from \"./runtime\";\n\ndeclare global {\n interface IJoliboxSDK extends JoliboxSDK {\n _commandPipe: ICommandPipe[];\n }\n interface Window {\n __JOLIBOX_LOCAL_SDK_VERSION__: string;\n joliboxenv?: {\n testMode: boolean;\n apiBaseURL: string;\n };\n joliboxsdk: IJoliboxSDK;\n JoliboxSDK: typeof JoliboxSDK;\n }\n interface ImportMeta {\n env: {\n JOLIBOX_SDK_VERSION: string;\n };\n }\n}\n\nwindow.__JOLIBOX_LOCAL_SDK_VERSION__ = import.meta.env.JOLIBOX_SDK_VERSION;\n\nexport interface IJoliboxConfig {\n useRuntimeSDK?: boolean;\n loaderConfig?: IJoliboxSDKLoaderConfig;\n testMode?: boolean;\n apiBaseURL?: string;\n}\n\ninterface ICommandPipe {\n cmd: string;\n params: any;\n}\n\nclass JoliboxSDK {\n private loader: JoliboxSDKLoader;\n ads: JoliboxAds;\n anaytics: JoliboxAnalytics;\n runtime: JoliboxRuntime;\n\n setJoliboxEnv = (inputTestMode?: boolean, inputApiBaseURL?: string) => {\n const isBrowser = typeof window !== \"undefined\";\n const urlSearchParams = isBrowser\n ? new URLSearchParams(window.location.search)\n : null;\n const testModeParam = urlSearchParams?.get(\"testMode\") === \"true\";\n const testMode = inputTestMode ?? testModeParam;\n\n const apiBaseURLParam = urlSearchParams?.get(\"apiBaseURL\");\n let apiBaseURL;\n if (inputApiBaseURL) {\n apiBaseURL = inputApiBaseURL;\n } else if (apiBaseURLParam) {\n apiBaseURL = apiBaseURLParam;\n } else {\n apiBaseURL = testMode\n ? \"https://test-api.jolibox.com\"\n : \"https://api.jolibox.com\";\n }\n window.joliboxenv = {\n testMode,\n apiBaseURL,\n };\n };\n\n constructor({\n useRuntimeSDK = true,\n loaderConfig,\n testMode,\n apiBaseURL,\n }: IJoliboxConfig = {}) {\n this.setJoliboxEnv(testMode, apiBaseURL);\n if (useRuntimeSDK && window.joliboxsdk) {\n this.loader =\n window.joliboxsdk.loader ?? new window.JoliboxSDKLoader(loaderConfig);\n this.ads = window.joliboxsdk.ads ?? new window.JoliboxAds();\n this.anaytics =\n window.joliboxsdk.anaytics ?? new window.JoliboxAnalytics();\n this.runtime = window.joliboxsdk.runtime ?? new window.JoliboxRuntime();\n } else {\n if (!window.joliboxsdk) {\n window.joliboxsdk = {\n _commandPipe: [], // This is to avoid the error \"Cannot read property 'push' of undefined\" if any command is called before the SDK is initialized\n } as any;\n }\n\n this.loader = new window.JoliboxSDKLoader(loaderConfig);\n this.ads = new window.JoliboxAds();\n this.anaytics = new window.JoliboxAnalytics();\n this.runtime = new window.JoliboxRuntime();\n window.joliboxsdk = Object.assign(this, window.joliboxsdk);\n }\n if (!window.joliboxsdk._commandPipe) {\n window.joliboxsdk._commandPipe = [];\n }\n }\n}\n\nif (!window.JoliboxSDK) {\n window.JoliboxSDK = JoliboxSDK;\n}\n\nexport default JoliboxSDK;\nexport { JoliboxSDK };\n","const splitSemver = (\n version: string\n): {\n major: string;\n minor: string;\n patch: string;\n prerelease?: string;\n build?: string;\n} => {\n const prerelease = version.split(\"-\")[1] as string | undefined;\n if (prerelease) {\n version = version.replace(`-${prerelease}`, \"\");\n }\n\n const build = version.split(\"+\")[1] as string | undefined;\n if (build) {\n version = version.replace(`+${build}`, \"\");\n }\n\n const splitted = version.split(\".\").slice(0, 3);\n const [major, minor, patch] = [\n splitted[0] ?? \"0\",\n splitted[1] ?? \"0\",\n splitted[2] ?? \"0\",\n ];\n return { major, minor, patch, prerelease, build };\n};\n\nexport const major = (version: string): number =>\n parseInt(splitSemver(version).major, 10);\n\nexport const compare = (v1: string, v2: string): -1 | 0 | 1 => {\n const { major: major1, minor: minor1, patch: patch1 } = splitSemver(v1);\n const { major: major2, minor: minor2, patch: patch2 } = splitSemver(v2);\n\n if (major1 !== major2) {\n return major1 > major2 ? 1 : -1;\n }\n\n if (minor1 !== minor2) {\n return minor1 > minor2 ? 1 : -1;\n }\n\n if (patch1 !== patch2) {\n return patch1 > patch2 ? 1 : -1;\n }\n\n return 0;\n};\n","import { major, compare } from \"./utils\";\n\ndeclare global {\n interface Window {\n JOLIBOX_ENV: \"WEB\" | \"IOS\" | \"ANDROID\" | \"WINDOWS\" | \"MACOS\" | \"LINUX\";\n JoliboxSDKLoader: typeof JoliboxSDKLoader;\n }\n}\n\nconst joliboxLoaderKey = \"jolibox-sdk-loader-metadata\";\n\nexport interface IVersionMetadata {\n version: string;\n syncScriptUrl?: string; // By default, the sync script is bundled with the sdk\n asyncScriptUrl?: string;\n}\n\nexport interface IRemoteVersionMetadata {\n code: \"SUCCESS\" | string;\n message?: string;\n data?: IVersionMetadata;\n}\n\nexport interface IJoliboxSDKLoaderConfig {\n loaderMetadata?: IVersionMetadata;\n}\n\nexport class JoliboxSDKLoader {\n loaderMetadata: IVersionMetadata;\n\n constructor({ loaderMetadata }: IJoliboxSDKLoaderConfig = {}) {\n console.log(\"Loading Jolibox SDK...\");\n\n this.loaderMetadata = loaderMetadata ?? this.computeLoaderMetaData();\n this.loadScript();\n this.fetchUpdateLoaderMetadata();\n console.log(\"Jolibox SDK loaded.\");\n }\n\n private get currentVersion() {\n return window.__JOLIBOX_LOCAL_SDK_VERSION__;\n }\n\n private get defaultMetadata(): IVersionMetadata {\n const version = this.currentVersion;\n const majorVersion = major(version);\n return {\n version,\n syncScriptUrl: `https://cdn.jsdelivr.net/npm/@jolibox/web-sync-sdk@${majorVersion}/dist/index.iife.js`,\n asyncScriptUrl: `https://cdn.jsdelivr.net/npm/@jolibox/web-async-sdk@${majorVersion}/dist/index.iife.js`,\n };\n }\n\n computeLoaderMetaData = () => {\n const version = this.currentVersion;\n let loaderMetadata: IVersionMetadata | null = null;\n try {\n loaderMetadata = JSON.parse(\n localStorage.getItem(joliboxLoaderKey) ?? \"null\"\n ) as IVersionMetadata | null;\n if (!loaderMetadata || !loaderMetadata.version) {\n throw new Error(\"Invalid loader metadata\");\n }\n } catch (error) {\n loaderMetadata = this.defaultMetadata;\n }\n\n const versionFromLocalStorage = loaderMetadata?.version ?? version;\n\n if (major(versionFromLocalStorage) !== major(version)) {\n // if major version is different, must follow the version from package.json\n loaderMetadata = this.defaultMetadata;\n } else {\n // if major version is the same, follow the larger version\n if (compare(versionFromLocalStorage, version) < 0) {\n loaderMetadata = this.defaultMetadata;\n }\n }\n\n return loaderMetadata;\n };\n\n loadScript = () => {\n if (this.loaderMetadata.syncScriptUrl) {\n // The only way to load a script synchronously is to use XMLHttpRequest\n const xhr = new XMLHttpRequest();\n xhr.open(\"GET\", this.loaderMetadata.syncScriptUrl, false);\n xhr.send();\n // eval(xhr.responseText);\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.innerHTML = xhr.responseText;\n document.head.appendChild(script);\n }\n\n if (this.loaderMetadata.asyncScriptUrl) {\n const asyncScript = document.createElement(\"script\");\n asyncScript.type = \"text/javascript\";\n asyncScript.src = this.loaderMetadata.asyncScriptUrl;\n asyncScript.async = true;\n document.head.appendChild(asyncScript);\n }\n };\n\n fetchUpdateLoaderMetadata = async (\n installedSDKVersion = this.currentVersion,\n localSDKVersion = this.loaderMetadata.version,\n env = window.JOLIBOX_ENV ?? \"WEB\"\n ) => {\n const path = `${\n window.joliboxenv?.apiBaseURL ?? \"https://api.jolibox.com\"\n }/frontend/js-sdk/loader-metadata`;\n try {\n const response = await fetch(path, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n installedSDKVersion,\n localSDKVersion,\n env,\n }),\n });\n const data: IRemoteVersionMetadata = await response.json();\n if (data.code !== \"SUCCESS\") {\n throw new Error(data.message);\n } else {\n this.loaderMetadata = data.data ?? this.defaultMetadata;\n localStorage.setItem(\n joliboxLoaderKey,\n JSON.stringify(this.loaderMetadata)\n );\n // reload happens next time the page is loaded\n }\n } catch (error) {\n console.warn(\"Failed to fetch loader metadata: \", error);\n }\n };\n}\n\nwindow.JoliboxSDKLoader = JoliboxSDKLoader;\n","declare global {\n interface Window {\n JoliboxAds: typeof JoliboxAds;\n }\n}\n\nexport interface IAdsInitParams {\n /**\n * (OPTIONAL) Game ID provided by Jolibox\n */\n gameId?: string;\n}\n\nexport interface IAdConfigParams {\n /**\n * (OPTIONAL) Whether ads should always be preloaded before the first call to adBreak()\n *\n * The default value of auto leaves the decision up to the Ad Placement API. preloadAdBreaks can be set only once with adConfig(), and further values passed to preloadAdBreaks have no effect.\n *\n * Setting preloadAdBreaks after the first call to adBreak() has no effect.\n */\n preloadAdBreaks?: \"on\" | \"auto\"; // default: 'auto'\n\n /**\n * (OPTIONAL) Whether the game is currently playing sound.\n *\n * This call specifies whether your game is capable of sound, and whether the sound was enabled (ie unmuted) before the call to adBreak(). This helps the Ad Placement API to select the right kind of ad for your game.\n *\n * Call this function as soon as the sound state of your game changes, as the Ad Placement API may have to request new creatives, and this gives it the maximum amount of time to do so.\n *\n * The default value is sound on. So most games will need to make a call to adConfig() when they start to declare that they have sound enabled.\n */\n sound?: \"on\" | \"off\"; // default: 'on'\n\n /**\n * (OPTIONAL) Called when the API has initialized and has finished preloading ads (if you requested preloading using the preloadAdBreaks above).\n * @returns\n */\n onReady?: () => void;\n}\n\n/**\n * PlacementInfo object passed by **adBreakDone** function\n */\nexport interface IPlacementInfo {\n /**\n * the type argument passed to adBreak()\n */\n breakType: string;\n /**\n * the name argument passed to adBreak()\n */\n breakName: string;\n breakFormat: \"interstitial\" | \"reward\";\n /**\n * the status of this placement and can be one of the following values:\n *\n * | breakStatus | Reason |\n * | -------- | ------- |\n * | 'notReady'\t| The Ad Placement API had not initialised |\n * | 'timeout' | A placement timed out because the Ad Placement API took too long to respond |\n * | 'invalid' | The placement was invalid and was ignored–for instance there should only be one preroll placement per page load, subsequent prerolls are failed with this status |\n * | 'error' | There was a JavaScript error in a callback |\n * | 'noAdPreloaded' |\tAn ad had not been preloaded yet so this placement was skipped |\n * | 'frequencyCapped' |\tAn ad wasn't shown because the frequency cap was applied to this placement |\n * | 'ignored' |\tThe user didn't click on a reward prompt before they reached the next placement, that is showAdFn() wasn't called before the next adBreak(). |\n * | 'other' |\tThe ad was not shown for another reason. (e.g., The ad was still being fetched, or a previously cached ad was disposed because the screen was resized/rotated.) |\n * | 'dismissed' |\tThe user dismissed a rewarded ad before viewing it to completion |\n * | 'viewed' |\tThe ad was viewed by the user |\n */\n breakStatus:\n | \"notReady\"\n | \"timeout\"\n | \"error\"\n | \"noAdPreloaded\"\n | \"frequencyCapped\"\n | \"ignored\"\n | \"other\"\n | \"dismissed\"\n | \"viewed\";\n}\n\n/**\n * Parameter when calling adBreak\n */\nexport type IAdBreakParams =\n | IPrerollParams\n | IInterstitialsParams\n | IRewardParams;\n\n/**\n * Parameter when calling preroll type adBreak\n */\nexport interface IPrerollParams {\n /**\n * 'preroll' before the game loads (before UI has rendered)\n */\n type: \"preroll\";\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n}\n\nexport interface IInterstitialsParams {\n /**\n * 'start' before the gameplay starts (after UI has rendered)\n * 'pause' the player pauses the game\n * 'next' player navigates to the next level\n * 'browse' the player explores options outside of the gameplay\n */\n type: \"start\" | \"pause\" | \"next\" | \"browse\";\n\n /**\n * (OPTIONAL) a name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. In future releases this identifier may be used to enable additional reporting and optimization features.\n *\n * We recommend you name all of your placements.\n */\n name?: string;\n\n /**\n * (OPTIONAL) Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes.\n *\n * @returns\n */\n beforeAd?: () => void;\n\n /**\n * (OPTIONAL) Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actions. This function should be used to resume game flow. For example, use to unmute the sound and start the next level.\n * @returns\n */\n afterAd?: () => void;\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object\n *\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n}\n\nexport interface IRewardParams {\n /**\n * 'reward' a rewarded ad\n */\n type: \"reward\";\n\n /**\n * (OPTIONAL) a name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. In future releases this identifier may be used to enable additional reporting and optimization features.\n *\n * We recommend you name all of your placements.\n */\n name?: string;\n\n /**\n * (OPTIONAL) Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes.\n * @returns\n */\n beforeAd?: () => void;\n\n /**\n * (OPTIONAL) Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actions. This function should be used to resume game flow. For example, use to unmute the sound and start the next level.\n * @returns\n */\n afterAd?: () => void;\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object defined\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n\n /**\n * Called if a rewarded ad is available. The function should take a single argument–showAdFn() which must be called to display the rewarded ad.\n * @param showAdFn\n * @returns\n */\n beforeReward: (showAdFn: () => void) => void;\n\n /**\n * Called only for rewarded ads when the player dismisses the ad. It is only called if the player dismisses the ad before it completes. In this case the reward should not be granted.\n * @returns\n */\n adDismissed: () => void;\n\n /**\n * Called only for rewarded ads when the player completes the ad and should be granted the reward.\n * @returns\n */\n adViewed: () => void;\n}\n\n/**\n * Ad unit format, can be 'rectangle', 'vertical', 'horizontal'\n */\nexport type AdUnitFormat = \"rectangle\" | \"vertical\" | \"horizontal\";\n\nexport interface IAdUnitParams {\n /**\n * The element to attach the ad unit to, either an HTMLElement or a string selector. Should be the parent element of the ad unit (<ins> tag).\n */\n el: HTMLElement | string;\n\n /**\n * (OPTIONAL) Reserved for future usage. The slot ID of the ad unit. Currently the slot ID is automatically set by the SDK.\n */\n slot?: string;\n\n // /**\n // * (OPTIONAL) The position of the ad unit. Can be 'TOP', 'BOTTOM', 'LEFT', 'RIGHT', 'CENTER'. Default is 'TOP'. Either position or slot should be set.\n // */\n // position?: AdUnitPosition;\n\n // /**\n // * (OPTIONAL) Channel ID for the ad unit. We will set the Channel ID automatically if not provided. Default is empty.\n // */\n // channelId?: string;\n\n /**\n * (OPTIONAL) Ad format for the ad unit. Can be 'auto' or a single format or an array of formats. Default is 'auto'. If passed as an array, the array will be joined by ', ' and pass to the data-ad-format attribute.\n */\n adFormat?: \"auto\" | AdUnitFormat | AdUnitFormat[];\n\n /**\n * (OPTIONAL) Whether the ad unit should be full width and responsive. Default is false.\n */\n fullWidthResponsive?: \"true\" | \"false\";\n\n /**\n * (OPTIONAL) Custom style for the ad unit. Default is empty.\n */\n style?: string;\n}\n\n/**\n * Jolibox Ads SDK\n */\nexport class JoliboxAds {\n /**\n * Internal constructor, should not be called directly\n */\n constructor() {}\n\n /**\n * Init JoliboxAds. Must be called before any other ads functions.\n * @param config\n * @returns\n */\n public init = (config?: IAdsInitParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.init\",\n params: config,\n });\n };\n\n /**\n * The adConfig() call communicates the game's current configuration to the Ad Placement API. The Ad Placement API can use this to tune the way it preloads ads and to filter the kinds of ads it requests so they're suitable (eg. video ads that require sound).\n * @param params\n */\n public adConfig = (params: IAdConfigParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adConfig\",\n params,\n });\n };\n\n /**\n * adBreak() is the key function for placing ads within your game. It defines an ad placement and takes an object called a placement config that specifies everything required to show an ad.\n *\n * The adBreak() function defines a placement where an ad could be shown. Whether an ad actually shows depends on factors such as the following:\n *\n * - The type of ad placement that you declared\n * - Is this ad at the start of the game? Between levels? At a moment when the player has paused the game?\n * - Whether a suitable ad exists for the current player\n * - Is this ad relevant to them?\n * - Is it consistent with their data privacy and consent settings?\n * - The number of ads the player has seen recently\n * - The control settings—for example, ad frequency, you've configured for this game\n * - Either as hints in the tag, or,\n * - Within AdSense—note that the controls available in AdSense will evolve over time.\n *\n * The kind of ad that shows also depends on similar factors.\n *\n * Note that a call to adBreak() might not show an ad at all. It simply declares a place where an ad could be shown.\n *\n * This is unlike traditional APIs in which your code always knows if an ad is available, and you decide within the game whether to show it. This approach of letting the Ad Placement API decide if an ad shows in a particular placement is a pattern that is sometimes referred to as \"inversion of control\".\n *\n * The reason we're transitioning our games API to this model is firstly, it shortens the code you have to write within your game. Secondly, it makes it easier to deliver policy compliant placements with a great user experience, which in turn has allowed us to deliver some of our highest performing formats to games publishers. Lastly, it more cleanly separates the process of placing ads in your game from the monetization decisions about the type and number of ads to show.\n *\n * We want you to be able to change your monetization settings and control the user experience without having to edit and release a new version of your game, initially by specifying hints in the tag. But in future releases, we will be able to provide controls directly in the AdSense and AdMob frontends.\n * @param params\n */\n public adBreak = (params: IAdBreakParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adBreak\",\n params,\n });\n };\n\n /**\n * adUnit() is a function that creates an ad unit and attaches it to a parent element. The ad unit is a single ad placement that can be used to show ads.\n *\n * Currently we only provide support for creating ad units as `<ins>` tags with the class 'adsbygoogle'. This is the standard way to create ad units with Google AdSense.\n *\n * After calling this method, the ad unit is attached to the parent element you specify as el in the params object.\n *\n * By default, the client ID and channel ID are automatically set by the SDK. And the slot name is set to the position of the ad unit. You can override these values by passing the slot and channelId in the params object.\n *\n * @param params\n * @returns\n */\n public adUnit = async (params: IAdUnitParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adUnit\",\n params,\n });\n };\n}\n\nwindow.JoliboxAds = JoliboxAds;\n\nexport default JoliboxAds;\n","declare global {\n interface Window {\n JoliboxAnalytics: typeof JoliboxAnalytics;\n }\n}\n\n/**\n * Jolibox Analytics SDK\n */\nexport class JoliboxAnalytics {\n constructor() {}\n\n /**\n * Track an event, will be sent to the analytics server\n *\n * @param eventName event name, must be a string\n * @param extra (OPTIONAL) extra data, must be an object or null or undefined, must not have nested objects\n */\n public trackEvent = (\n eventName: string,\n extra?: Record<string, string | boolean | number | null> | null\n ) => {\n // assert eventName is a string\n if (typeof eventName !== \"string\") {\n throw new Error(\"eventName must be a string\");\n }\n\n // assert extra is an object or null or undefined\n if (extra !== null && typeof extra !== \"object\" && extra !== undefined) {\n throw new Error(\"extra must be an object or null or undefined\");\n }\n\n // assert extra has no nested objects\n if (extra) {\n for (const key in extra) {\n if (typeof extra[key] === \"object\") {\n throw new Error(\"extra must not have nested objects\");\n }\n }\n }\n\n window.joliboxsdk._commandPipe.push({\n cmd: \"analytics.trackEvent\",\n params: [eventName, extra],\n });\n };\n}\n\nwindow.JoliboxAnalytics = JoliboxAnalytics;\n\nexport default JoliboxAnalytics;\n"],"mappings":"snBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GCAA,IAAMK,EACJC,GAOG,CARL,IAAAC,EAAAC,EAAAC,EASE,IAAMC,EAAaJ,EAAQ,MAAM,GAAG,EAAE,CAAC,EACnCI,IACFJ,EAAUA,EAAQ,QAAQ,IAAII,CAAU,GAAI,EAAE,GAGhD,IAAMC,EAAQL,EAAQ,MAAM,GAAG,EAAE,CAAC,EAC9BK,IACFL,EAAUA,EAAQ,QAAQ,IAAIK,CAAK,GAAI,EAAE,GAG3C,IAAMC,EAAWN,EAAQ,MAAM,GAAG,EAAE,MAAM,EAAG,CAAC,EACxC,CAACO,EAAOC,EAAOC,CAAK,EAAI,EAC5BR,EAAAK,EAAS,CAAC,IAAV,KAAAL,EAAe,KACfC,EAAAI,EAAS,CAAC,IAAV,KAAAJ,EAAe,KACfC,EAAAG,EAAS,CAAC,IAAV,KAAAH,EAAe,GACjB,EACA,MAAO,CAAE,MAAAI,EAAO,MAAAC,EAAO,MAAAC,EAAO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C,EAAG,CA9BxB,mBAAgB,CAACC,EAAyBC,IAA6B,CAErE,IAAMC,EADY,OAAO,OAAW,IAEhC,IAAI,gBAAgB,OAAO,SAAS,MAAM,EAC1C,KACEC,GAAgBD,GAAA,YAAAA,EAAiB,IAAI,eAAgB,OACrDJ,EAAWE,GAAA,KAAAA,EAAiBG,EAE5BC,EAAkBF,GAAA,YAAAA,EAAiB,IAAI,cACzCH,EACAE,EACFF,EAAaE,EACJG,EACTL,EAAaK,EAEbL,EAAaD,EACT,+BACA,0BAEN,OAAO,WAAa,CAClB,SAAAA,EACA,WAAAC,CACF,CACF,EAxEF,IAAAM,EAAAC,EAAAC,EAAAC,EAgFI,KAAK,cAAcV,EAAUC,CAAU,EACnCH,GAAiB,OAAO,YAC1B,KAAK,QACHS,EAAA,OAAO,WAAW,SAAlB,KAAAA,EAA4B,IAAI,OAAO,iBAAiBR,CAAY,EACtE,KAAK,KAAMS,EAAA,OAAO,WAAW,MAAlB,KAAAA,EAAyB,IAAI,OAAO,WAC/C,KAAK,UACHC,EAAA,OAAO,WAAW,WAAlB,KAAAA,EAA8B,IAAI,OAAO,iBAC3C,KAAK,SAAUC,EAAA,OAAO,WAAW,UAAlB,KAAAA,EAA6B,IAAI,OAAO,iBAElD,OAAO,aACV,OAAO,WAAa,CAClB,aAAc,CAAC,CACjB,GAGF,KAAK,OAAS,IAAI,OAAO,iBAAiBX,CAAY,EACtD,KAAK,IAAM,IAAI,OAAO,WACtB,KAAK,SAAW,IAAI,OAAO,iBAC3B,KAAK,QAAU,IAAI,OAAO,eAC1B,OAAO,WAAa,OAAO,OAAO,KAAM,OAAO,UAAU,GAEtD,OAAO,WAAW,eACrB,OAAO,WAAW,aAAe,CAAC,EAEtC,CACF,EAEK,OAAO,aACV,OAAO,WAAaF,GAGtB,IAAOc,EAAQd","names":["src_exports","__export","JoliboxSDK","src_default","__toCommonJS","splitSemver","version","_a","_b","_c","prerelease","build","splitted","major","minor","patch","compare","v1","v2","major1","minor1","patch1","major2","minor2","patch2","joliboxLoaderKey","JoliboxSDKLoader","loaderMetadata","_a","_b","version","error","versionFromLocalStorage","major","compare","xhr","script","asyncScript","_0","__async","installedSDKVersion","localSDKVersion","env","_c","path","data","majorVersion","JoliboxAds","config","params","__async","JoliboxAnalytics","eventName","extra","key","import_web_sync_sdk","JoliboxSDK","useRuntimeSDK","loaderConfig","testMode","apiBaseURL","inputTestMode","inputApiBaseURL","urlSearchParams","testModeParam","apiBaseURLParam","_a","_b","_c","_d","src_default"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/loader/utils.ts","../src/loader/index.ts","../src/ads/index.ts","../src/analytics/index.ts"],"sourcesContent":["import \"./loader\";\nimport \"./ads\";\nimport \"./analytics\";\nimport \"@jolibox/web-sync-sdk\";\nimport type { JoliboxSDKLoader, IJoliboxSDKLoaderConfig } from \"./loader\";\nimport type { JoliboxAds } from \"./ads\";\nimport type { JoliboxAnalytics } from \"./analytics\";\nimport type { JoliboxRuntime } from \"./runtime\";\n\ndeclare global {\n interface IJoliboxSDK extends JoliboxSDK {\n _commandPipe: ICommandPipe[];\n }\n interface Window {\n __JOLIBOX_LOCAL_SDK_VERSION__: string;\n joliboxenv?: {\n testMode: boolean;\n apiBaseURL: string;\n };\n joliboxsdk: IJoliboxSDK;\n JoliboxSDK: typeof JoliboxSDK;\n }\n interface ImportMeta {\n env: {\n JOLIBOX_SDK_VERSION: string;\n };\n }\n}\n\nwindow.__JOLIBOX_LOCAL_SDK_VERSION__ = import.meta.env.JOLIBOX_SDK_VERSION;\n\nexport interface IJoliboxConfig {\n useRuntimeSDK?: boolean;\n loaderConfig?: IJoliboxSDKLoaderConfig;\n testMode?: boolean;\n apiBaseURL?: string;\n}\n\ninterface ICommandPipe {\n cmd: string;\n params: any;\n}\n\nclass JoliboxSDK {\n private loader: JoliboxSDKLoader;\n ads: JoliboxAds;\n anaytics: JoliboxAnalytics;\n runtime: JoliboxRuntime;\n\n setJoliboxEnv = (inputTestMode?: boolean, inputApiBaseURL?: string) => {\n const isBrowser = typeof window !== \"undefined\";\n const urlSearchParams = isBrowser\n ? new URLSearchParams(window.location.search)\n : null;\n const testModeParam = urlSearchParams?.get(\"testMode\") === \"true\";\n const testMode = inputTestMode ?? testModeParam;\n\n const apiBaseURLParam = urlSearchParams?.get(\"apiBaseURL\");\n let apiBaseURL;\n if (inputApiBaseURL) {\n apiBaseURL = inputApiBaseURL;\n } else if (apiBaseURLParam) {\n apiBaseURL = apiBaseURLParam;\n } else {\n apiBaseURL = testMode\n ? \"https://test-api.jolibox.com\"\n : \"https://api.jolibox.com\";\n }\n window.joliboxenv = {\n testMode,\n apiBaseURL,\n };\n };\n\n constructor({\n useRuntimeSDK = true,\n loaderConfig,\n testMode,\n apiBaseURL,\n }: IJoliboxConfig = {}) {\n this.setJoliboxEnv(testMode, apiBaseURL);\n if (useRuntimeSDK && window.joliboxsdk) {\n this.loader =\n window.joliboxsdk.loader ?? new window.JoliboxSDKLoader(loaderConfig);\n this.ads = window.joliboxsdk.ads ?? new window.JoliboxAds();\n this.anaytics =\n window.joliboxsdk.anaytics ?? new window.JoliboxAnalytics();\n this.runtime = window.joliboxsdk.runtime ?? new window.JoliboxRuntime();\n } else {\n if (!window.joliboxsdk) {\n window.joliboxsdk = {\n _commandPipe: [], // This is to avoid the error \"Cannot read property 'push' of undefined\" if any command is called before the SDK is initialized\n } as any;\n }\n\n this.loader = new window.JoliboxSDKLoader(loaderConfig);\n this.ads = new window.JoliboxAds();\n this.anaytics = new window.JoliboxAnalytics();\n this.runtime = new window.JoliboxRuntime();\n window.joliboxsdk = Object.assign(this, window.joliboxsdk);\n }\n if (!window.joliboxsdk._commandPipe) {\n window.joliboxsdk._commandPipe = [];\n }\n }\n}\n\nif (!window.JoliboxSDK) {\n window.JoliboxSDK = JoliboxSDK;\n}\n\nexport default JoliboxSDK;\nexport { JoliboxSDK };\n","const splitSemver = (\n version: string\n): {\n major: string;\n minor: string;\n patch: string;\n prerelease?: string;\n build?: string;\n} => {\n const prerelease = version.split(\"-\")[1] as string | undefined;\n if (prerelease) {\n version = version.replace(`-${prerelease}`, \"\");\n }\n\n const build = version.split(\"+\")[1] as string | undefined;\n if (build) {\n version = version.replace(`+${build}`, \"\");\n }\n\n const splitted = version.split(\".\").slice(0, 3);\n const [major, minor, patch] = [\n splitted[0] ?? \"0\",\n splitted[1] ?? \"0\",\n splitted[2] ?? \"0\",\n ];\n return { major, minor, patch, prerelease, build };\n};\n\nexport const major = (version: string): number =>\n parseInt(splitSemver(version).major, 10);\n\nexport const compare = (v1: string, v2: string): -1 | 0 | 1 => {\n const { major: major1, minor: minor1, patch: patch1 } = splitSemver(v1);\n const { major: major2, minor: minor2, patch: patch2 } = splitSemver(v2);\n\n if (major1 !== major2) {\n return major1 > major2 ? 1 : -1;\n }\n\n if (minor1 !== minor2) {\n return minor1 > minor2 ? 1 : -1;\n }\n\n if (patch1 !== patch2) {\n return patch1 > patch2 ? 1 : -1;\n }\n\n return 0;\n};\n","import { major, compare } from \"./utils\";\n\ndeclare global {\n interface Window {\n JOLIBOX_ENV: \"WEB\" | \"IOS\" | \"ANDROID\" | \"WINDOWS\" | \"MACOS\" | \"LINUX\";\n JoliboxSDKLoader: typeof JoliboxSDKLoader;\n }\n}\n\nconst joliboxLoaderKey = \"jolibox-sdk-loader-metadata\";\n\nexport interface IVersionMetadata {\n version: string;\n syncScriptUrl?: string; // By default, the sync script is bundled with the sdk\n asyncScriptUrl?: string;\n}\n\nexport interface IRemoteVersionMetadata {\n code: \"SUCCESS\" | string;\n message?: string;\n data?: IVersionMetadata;\n}\n\nexport interface IJoliboxSDKLoaderConfig {\n loaderMetadata?: IVersionMetadata;\n}\n\nexport class JoliboxSDKLoader {\n loaderMetadata: IVersionMetadata;\n\n constructor({ loaderMetadata }: IJoliboxSDKLoaderConfig = {}) {\n console.log(\"Loading Jolibox SDK...\");\n\n this.loaderMetadata = loaderMetadata ?? this.computeLoaderMetaData();\n this.loadScript();\n this.fetchUpdateLoaderMetadata();\n console.log(\"Jolibox SDK loaded.\");\n }\n\n private get currentVersion() {\n return window.__JOLIBOX_LOCAL_SDK_VERSION__;\n }\n\n private get defaultMetadata(): IVersionMetadata {\n const version = this.currentVersion;\n const majorVersion = major(version);\n return {\n version,\n syncScriptUrl: `https://cdn.jsdelivr.net/npm/@jolibox/web-sync-sdk@${majorVersion}/dist/index.iife.js`,\n asyncScriptUrl: `https://cdn.jsdelivr.net/npm/@jolibox/web-async-sdk@${majorVersion}/dist/index.iife.js`,\n };\n }\n\n computeLoaderMetaData = () => {\n const version = this.currentVersion;\n let loaderMetadata: IVersionMetadata | null = null;\n try {\n loaderMetadata = JSON.parse(\n localStorage.getItem(joliboxLoaderKey) ?? \"null\"\n ) as IVersionMetadata | null;\n if (!loaderMetadata || !loaderMetadata.version) {\n throw new Error(\"Invalid loader metadata\");\n }\n } catch (error) {\n loaderMetadata = this.defaultMetadata;\n }\n\n const versionFromLocalStorage = loaderMetadata?.version ?? version;\n\n if (major(versionFromLocalStorage) !== major(version)) {\n // if major version is different, must follow the version from package.json\n loaderMetadata = this.defaultMetadata;\n } else {\n // if major version is the same, follow the larger version\n if (compare(versionFromLocalStorage, version) < 0) {\n loaderMetadata = this.defaultMetadata;\n }\n }\n\n return loaderMetadata;\n };\n\n loadScript = () => {\n if (this.loaderMetadata.syncScriptUrl) {\n // The only way to load a script synchronously is to use XMLHttpRequest\n const xhr = new XMLHttpRequest();\n xhr.open(\"GET\", this.loaderMetadata.syncScriptUrl, false);\n xhr.send();\n // eval(xhr.responseText);\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.innerHTML = xhr.responseText;\n document.head.appendChild(script);\n }\n\n if (this.loaderMetadata.asyncScriptUrl) {\n const asyncScript = document.createElement(\"script\");\n asyncScript.type = \"text/javascript\";\n asyncScript.src = this.loaderMetadata.asyncScriptUrl;\n asyncScript.async = true;\n document.head.appendChild(asyncScript);\n }\n };\n\n fetchUpdateLoaderMetadata = async (\n installedSDKVersion = this.currentVersion,\n localSDKVersion = this.loaderMetadata.version,\n env = window.JOLIBOX_ENV ?? \"WEB\"\n ) => {\n const path = `${\n window.joliboxenv?.apiBaseURL ?? \"https://api.jolibox.com\"\n }/frontend/js-sdk/loader-metadata`;\n try {\n const response = await fetch(path, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n installedSDKVersion,\n localSDKVersion,\n env,\n }),\n });\n const data: IRemoteVersionMetadata = await response.json();\n if (data.code !== \"SUCCESS\") {\n throw new Error(data.message);\n } else {\n this.loaderMetadata = data.data ?? this.defaultMetadata;\n localStorage.setItem(\n joliboxLoaderKey,\n JSON.stringify(this.loaderMetadata)\n );\n // reload happens next time the page is loaded\n }\n } catch (error) {\n console.warn(\"Failed to fetch loader metadata: \", error);\n }\n };\n}\n\nwindow.JoliboxSDKLoader = JoliboxSDKLoader;\n","declare global {\n interface Window {\n JoliboxAds: typeof JoliboxAds;\n }\n}\n\nexport interface IAdsInitParams {\n /**\n * (OPTIONAL) Game ID provided by Jolibox\n */\n gameId?: string;\n}\n\nexport interface IAdConfigParams {\n /**\n * (OPTIONAL) Whether ads should always be preloaded before the first call to adBreak()\n *\n * The default value of auto leaves the decision up to the Ad Placement API. preloadAdBreaks can be set only once with adConfig(), and further values passed to preloadAdBreaks have no effect.\n *\n * Setting preloadAdBreaks after the first call to adBreak() has no effect.\n */\n preloadAdBreaks?: \"on\" | \"auto\"; // default: 'auto'\n\n /**\n * (OPTIONAL) Whether the game is currently playing sound.\n *\n * This call specifies whether your game is capable of sound, and whether the sound was enabled (ie unmuted) before the call to adBreak(). This helps the Ad Placement API to select the right kind of ad for your game.\n *\n * Call this function as soon as the sound state of your game changes, as the Ad Placement API may have to request new creatives, and this gives it the maximum amount of time to do so.\n *\n * The default value is sound on. So most games will need to make a call to adConfig() when they start to declare that they have sound enabled.\n */\n sound?: \"on\" | \"off\"; // default: 'on'\n\n /**\n * (OPTIONAL) Called when the API has initialized and has finished preloading ads (if you requested preloading using the preloadAdBreaks above).\n * @returns\n */\n onReady?: () => void;\n}\n\n/**\n * PlacementInfo object passed by **adBreakDone** function\n */\nexport interface IPlacementInfo {\n /**\n * the type argument passed to adBreak()\n */\n breakType: string;\n /**\n * the name argument passed to adBreak()\n */\n breakName: string;\n breakFormat: \"interstitial\" | \"reward\";\n /**\n * the status of this placement and can be one of the following values:\n *\n * | breakStatus | Reason |\n * | -------- | ------- |\n * | 'notReady'\t| The Ad Placement API had not initialised |\n * | 'timeout' | A placement timed out because the Ad Placement API took too long to respond |\n * | 'invalid' | The placement was invalid and was ignored–for instance there should only be one preroll placement per page load, subsequent prerolls are failed with this status |\n * | 'error' | There was a JavaScript error in a callback |\n * | 'noAdPreloaded' |\tAn ad had not been preloaded yet so this placement was skipped |\n * | 'frequencyCapped' |\tAn ad wasn't shown because the frequency cap was applied to this placement |\n * | 'ignored' |\tThe user didn't click on a reward prompt before they reached the next placement, that is showAdFn() wasn't called before the next adBreak(). |\n * | 'other' |\tThe ad was not shown for another reason. (e.g., The ad was still being fetched, or a previously cached ad was disposed because the screen was resized/rotated.) |\n * | 'dismissed' |\tThe user dismissed a rewarded ad before viewing it to completion |\n * | 'viewed' |\tThe ad was viewed by the user |\n */\n breakStatus:\n | \"notReady\"\n | \"timeout\"\n | \"error\"\n | \"noAdPreloaded\"\n | \"frequencyCapped\"\n | \"ignored\"\n | \"other\"\n | \"dismissed\"\n | \"viewed\";\n}\n\n/**\n * Parameter when calling adBreak\n */\nexport type IAdBreakParams =\n | IPrerollParams\n | IInterstitialsParams\n | IRewardParams;\n\n/**\n * Parameter when calling preroll type adBreak\n */\nexport interface IPrerollParams {\n /**\n * 'preroll' before the game loads (before UI has rendered)\n */\n type: \"preroll\";\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n}\n\nexport interface IInterstitialsParams {\n /**\n * 'start' before the gameplay starts (after UI has rendered)\n * 'pause' the player pauses the game\n * 'next' player navigates to the next level\n * 'browse' the player explores options outside of the gameplay\n */\n type: \"start\" | \"pause\" | \"next\" | \"browse\";\n\n /**\n * (OPTIONAL) a name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. In future releases this identifier may be used to enable additional reporting and optimization features.\n *\n * We recommend you name all of your placements.\n */\n name?: string;\n\n /**\n * (OPTIONAL) Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes.\n *\n * @returns\n */\n beforeAd?: () => void;\n\n /**\n * (OPTIONAL) Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actions. This function should be used to resume game flow. For example, use to unmute the sound and start the next level.\n * @returns\n */\n afterAd?: () => void;\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object\n *\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n}\n\nexport interface IRewardParams {\n /**\n * 'reward' a rewarded ad\n */\n type: \"reward\";\n\n /**\n * (OPTIONAL) a name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. In future releases this identifier may be used to enable additional reporting and optimization features.\n *\n * We recommend you name all of your placements.\n */\n name?: string;\n\n /**\n * (OPTIONAL) Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes.\n * @returns\n */\n beforeAd?: () => void;\n\n /**\n * (OPTIONAL) Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actions. This function should be used to resume game flow. For example, use to unmute the sound and start the next level.\n * @returns\n */\n afterAd?: () => void;\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object defined\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n\n /**\n * Called if a rewarded ad is available. The function should take a single argument–showAdFn() which must be called to display the rewarded ad.\n * @param showAdFn\n * @returns\n */\n beforeReward: (showAdFn: () => void) => void;\n\n /**\n * Called only for rewarded ads when the player dismisses the ad. It is only called if the player dismisses the ad before it completes. In this case the reward should not be granted.\n * @returns\n */\n adDismissed: () => void;\n\n /**\n * Called only for rewarded ads when the player completes the ad and should be granted the reward.\n * @returns\n */\n adViewed: () => void;\n}\n\n/**\n * Ad unit format, can be 'rectangle', 'vertical', 'horizontal'\n */\nexport type AdUnitFormat = \"rectangle\" | \"vertical\" | \"horizontal\";\n\nexport interface IAdUnitParams {\n /**\n * The element to attach the ad unit to, either an HTMLElement or a string selector. Should be the parent element of the ad unit (<ins> tag).\n */\n el: HTMLElement | string;\n\n /**\n * (OPTIONAL) Reserved for future usage. The slot ID of the ad unit. Currently the slot ID is automatically set by the SDK.\n */\n slot?: string;\n\n // /**\n // * (OPTIONAL) The position of the ad unit. Can be 'TOP', 'BOTTOM', 'LEFT', 'RIGHT', 'CENTER'. Default is 'TOP'. Either position or slot should be set.\n // */\n // position?: AdUnitPosition;\n\n // /**\n // * (OPTIONAL) Channel ID for the ad unit. We will set the Channel ID automatically if not provided. Default is empty.\n // */\n // channelId?: string;\n\n /**\n * (OPTIONAL) Ad format for the ad unit. Can be 'auto' or a single format or an array of formats. Default is 'auto'. If passed as an array, the array will be joined by ', ' and pass to the data-ad-format attribute.\n */\n adFormat?: \"auto\" | AdUnitFormat | AdUnitFormat[];\n\n /**\n * (OPTIONAL) Whether the ad unit should be full width and responsive. Default is false.\n */\n fullWidthResponsive?: \"true\" | \"false\";\n\n /**\n * (OPTIONAL) Custom style for the ad unit. Default is empty.\n */\n style?: string;\n}\n\n/**\n * Jolibox Ads SDK\n */\nexport class JoliboxAds {\n /**\n * Internal constructor, should not be called directly\n */\n constructor() {}\n\n /**\n * Init JoliboxAds. Must be called before any other ads functions.\n * @param config\n * @returns\n */\n public init = (config?: IAdsInitParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.init\",\n params: config,\n });\n };\n\n /**\n * The adConfig() call communicates the game's current configuration to the Ad Placement API. The Ad Placement API can use this to tune the way it preloads ads and to filter the kinds of ads it requests so they're suitable (eg. video ads that require sound).\n * @param params\n */\n public adConfig = (params: IAdConfigParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adConfig\",\n params,\n });\n };\n\n /**\n * adBreak() is the key function for placing ads within your game. It defines an ad placement and takes an object called a placement config that specifies everything required to show an ad.\n *\n * The adBreak() function defines a placement where an ad could be shown. Whether an ad actually shows depends on factors such as the following:\n *\n * - The type of ad placement that you declared\n * - Is this ad at the start of the game? Between levels? At a moment when the player has paused the game?\n * - Whether a suitable ad exists for the current player\n * - Is this ad relevant to them?\n * - Is it consistent with their data privacy and consent settings?\n * - The number of ads the player has seen recently\n * - The control settings—for example, ad frequency, you've configured for this game\n * - Either as hints in the tag, or,\n * - Within AdSense—note that the controls available in AdSense will evolve over time.\n *\n * The kind of ad that shows also depends on similar factors.\n *\n * Note that a call to adBreak() might not show an ad at all. It simply declares a place where an ad could be shown.\n *\n * This is unlike traditional APIs in which your code always knows if an ad is available, and you decide within the game whether to show it. This approach of letting the Ad Placement API decide if an ad shows in a particular placement is a pattern that is sometimes referred to as \"inversion of control\".\n *\n * The reason we're transitioning our games API to this model is firstly, it shortens the code you have to write within your game. Secondly, it makes it easier to deliver policy compliant placements with a great user experience, which in turn has allowed us to deliver some of our highest performing formats to games publishers. Lastly, it more cleanly separates the process of placing ads in your game from the monetization decisions about the type and number of ads to show.\n *\n * We want you to be able to change your monetization settings and control the user experience without having to edit and release a new version of your game, initially by specifying hints in the tag. But in future releases, we will be able to provide controls directly in the AdSense and AdMob frontends.\n * @param params\n */\n public adBreak = (params: IAdBreakParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adBreak\",\n params,\n });\n };\n\n /**\n * adUnit() is a function that creates an ad unit and attaches it to a parent element. The ad unit is a single ad placement that can be used to show ads.\n *\n * Currently we only provide support for creating ad units as `<ins>` tags with the class 'adsbygoogle'. This is the standard way to create ad units with Google AdSense.\n *\n * After calling this method, the ad unit is attached to the parent element you specify as el in the params object.\n *\n * By default, the client ID and channel ID are automatically set by the SDK. And the slot name is set to the position of the ad unit. You can override these values by passing the slot and channelId in the params object.\n *\n * @param params\n * @returns\n */\n public adUnit = async (params: IAdUnitParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adUnit\",\n params,\n });\n };\n}\n\nwindow.JoliboxAds = JoliboxAds;\n\nexport default JoliboxAds;\n","declare global {\n interface Window {\n JoliboxAnalytics: typeof JoliboxAnalytics;\n }\n}\n\n/**\n * Jolibox Analytics SDK\n */\nexport class JoliboxAnalytics {\n constructor() {}\n\n /**\n * Track an event, will be sent to the analytics server\n *\n * @param eventName event name, must be a string\n * @param extra (OPTIONAL) extra data, must be an object or null or undefined, must not have nested objects\n */\n public trackEvent = (\n eventName: string,\n extra?: Record<string, string | boolean | number | null> | null\n ) => {\n // assert eventName is a string\n if (typeof eventName !== \"string\") {\n throw new Error(\"eventName must be a string\");\n }\n\n // assert extra is an object or null or undefined\n if (extra !== null && typeof extra !== \"object\" && extra !== undefined) {\n throw new Error(\"extra must be an object or null or undefined\");\n }\n\n // assert extra has no nested objects\n if (extra) {\n for (const key in extra) {\n if (typeof extra[key] === \"object\") {\n throw new Error(\"extra must not have nested objects\");\n }\n }\n }\n\n window.joliboxsdk._commandPipe.push({\n cmd: \"analytics.trackEvent\",\n params: [eventName, extra],\n });\n };\n}\n\nwindow.JoliboxAnalytics = JoliboxAnalytics;\n\nexport default JoliboxAnalytics;\n"],"mappings":"snBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GCAA,IAAMK,EACJC,GAOG,CARL,IAAAC,EAAAC,EAAAC,EASE,IAAMC,EAAaJ,EAAQ,MAAM,GAAG,EAAE,CAAC,EACnCI,IACFJ,EAAUA,EAAQ,QAAQ,IAAII,CAAU,GAAI,EAAE,GAGhD,IAAM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F,KAAK,OAAS,IAAI,OAAO,iBAAiBX,CAAY,EACtD,KAAK,IAAM,IAAI,OAAO,WACtB,KAAK,SAAW,IAAI,OAAO,iBAC3B,KAAK,QAAU,IAAI,OAAO,eAC1B,OAAO,WAAa,OAAO,OAAO,KAAM,OAAO,UAAU,GAEtD,OAAO,WAAW,eACrB,OAAO,WAAW,aAAe,CAAC,EAEtC,CACF,EAEK,OAAO,aACV,OAAO,WAAaF,GAGtB,IAAOc,EAAQd","names":["src_exports","__export","JoliboxSDK","src_default","__toCommonJS","splitSemver","version","_a","_b","_c","prerelease","build","splitted","major","minor","patch","compare","v1","v2","major1","minor1","patch1","major2","minor2","patch2","joliboxLoaderKey","JoliboxSDKLoader","loaderMetadata","_a","_b","version","error","versionFromLocalStorage","major","compare","xhr","script","asyncScript","_0","__async","installedSDKVersion","localSDKVersion","env","_c","path","data","majorVersion","JoliboxAds","config","params","__async","JoliboxAnalytics","eventName","extra","key","import_web_sync_sdk","JoliboxSDK","useRuntimeSDK","loaderConfig","testMode","apiBaseURL","inputTestMode","inputApiBaseURL","urlSearchParams","testModeParam","apiBaseURLParam","_a","_b","_c","_d","src_default"]}
@@ -1,2 +1,2 @@
1
- "use strict";(()=>{var c=(t,o,e)=>new Promise((n,i)=>{var d=a=>{try{r(e.next(a))}catch(l){i(l)}},s=a=>{try{r(e.throw(a))}catch(l){i(l)}},r=a=>a.done?n(a.value):Promise.resolve(a.value).then(d,s);r((e=e.apply(t,o)).next())});var b=t=>{var r,a,l;let o=t.split("-")[1];o&&(t=t.replace(`-${o}`,""));let e=t.split("+")[1];e&&(t=t.replace(`+${e}`,""));let n=t.split(".").slice(0,3),[i,d,s]=[(r=n[0])!=null?r:"0",(a=n[1])!=null?a:"0",(l=n[2])!=null?l:"0"];return{major:i,minor:d,patch:s,prerelease:o,build:e}},p=t=>parseInt(b(t).major,10),h=(t,o)=>{let{major:e,minor:n,patch:i}=b(t),{major:d,minor:s,patch:r}=b(o);return e!==d?e>d?1:-1:n!==s?n>s?1:-1:i!==r?i>r?1:-1:0};var g="jolibox-sdk-loader-metadata",f=class{constructor({loaderMetadata:o}={}){this.computeLoaderMetaData=()=>{var i,d;let o=this.currentVersion,e=null;try{if(e=JSON.parse((i=localStorage.getItem(g))!=null?i:"null"),!e||!e.version)throw new Error("Invalid loader metadata")}catch(s){e=this.defaultMetadata}let n=(d=e==null?void 0:e.version)!=null?d:o;return p(n)!==p(o)?e=this.defaultMetadata:h(n,o)<0&&(e=this.defaultMetadata),e};this.loadScript=()=>{if(this.loaderMetadata.syncScriptUrl){let o=new XMLHttpRequest;o.open("GET",this.loaderMetadata.syncScriptUrl,!1),o.send();let e=document.createElement("script");e.type="text/javascript",e.innerHTML=o.responseText,document.head.appendChild(e)}if(this.loaderMetadata.asyncScriptUrl){let o=document.createElement("script");o.type="text/javascript",o.src=this.loaderMetadata.asyncScriptUrl,o.async=!0,document.head.appendChild(o)}};this.fetchUpdateLoaderMetadata=(...d)=>c(this,[...d],function*(o=this.currentVersion,e=this.loaderMetadata.version,n=(i=>(i=window.JOLIBOX_ENV)!=null?i:"WEB")()){var r,a,l;let s=`${(a=(r=window.joliboxenv)==null?void 0:r.apiBaseURL)!=null?a:"https://api.jolibox.com"}/frontend/js-sdk/loader-metadata`;try{let w=yield(yield fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({installedSDKVersion:o,localSDKVersion:e,env:n})})).json();if(w.code!=="SUCCESS")throw new Error(w.message);this.loaderMetadata=(l=w.data)!=null?l:this.defaultMetadata,localStorage.setItem(g,JSON.stringify(this.loaderMetadata))}catch(u){console.warn("Failed to fetch loader metadata: ",u)}});console.log("Loading Jolibox SDK..."),this.loaderMetadata=o!=null?o:this.computeLoaderMetaData(),this.loadScript(),this.fetchUpdateLoaderMetadata(),console.log("Jolibox SDK loaded.")}get currentVersion(){return window.__JOLIBOX_LOCAL_SDK_VERSION__}get defaultMetadata(){let o=this.currentVersion,e=p(o);return{version:o,syncScriptUrl:`https://cdn.jsdelivr.net/npm/@jolibox/web-sync-sdk@${e}/dist/index.iife.js`,asyncScriptUrl:`https://cdn.jsdelivr.net/npm/@jolibox/web-async-sdk@${e}/dist/index.iife.js`}}};window.JoliboxSDKLoader=f;var x=class{constructor(){this.init=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.init",params:o})};this.adConfig=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.adConfig",params:o})};this.adBreak=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.adBreak",params:o})};this.adUnit=o=>c(this,null,function*(){window.joliboxsdk._commandPipe.push({cmd:"ads.adUnit",params:o})})}};window.JoliboxAds=x;var I=class{constructor(){this.trackEvent=(o,e)=>{if(typeof o!="string")throw new Error("eventName must be a string");if(e!==null&&typeof e!="object"&&e!==void 0)throw new Error("extra must be an object or null or undefined");if(e){for(let n in e)if(typeof e[n]=="object")throw new Error("extra must not have nested objects")}window.joliboxsdk._commandPipe.push({cmd:"analytics.trackEvent",params:[o,e]})}}};window.JoliboxAnalytics=I;var S=(t=>(t.LOAD_START="JOLIBOX_RUNTIME_LOAD_START",t.LOAD_FINISHED="JOLIBOX_RUNTIME_LOAD_FINISHED",t.LOAD_PROGRESS="JOLIBOX_RUNTIME_LOAD_PROGRESS",t))(S||{});window.dispatchEvent(new Event("JOLIBOX_RUNTIME_LOAD_START"));var y=class{constructor(){this.loadFinished=()=>{let t=new Event("JOLIBOX_RUNTIME_LOAD_FINISHED");window.dispatchEvent(t),window.joliboxsdk._commandPipe.push({cmd:"analytics.trackSystemEvent",params:["CallRuntimeLoadFinished"]})},this.notifyLoadProgress=t=>{let o=Math.ceil(t),e=new CustomEvent("JOLIBOX_RUNTIME_LOAD_PROGRESS",{detail:o});window.dispatchEvent(e)}}};window.JoliboxRuntime=y;window.__JOLIBOX_LOCAL_SDK_VERSION__="1.0.6";var m=class{constructor({useRuntimeSDK:o=!0,loaderConfig:e,testMode:n,apiBaseURL:i}={}){this.setJoliboxEnv=(o,e)=>{let i=typeof window<"u"?new URLSearchParams(window.location.search):null,d=(i==null?void 0:i.get("testMode"))==="true",s=o!=null?o:d,r=i==null?void 0:i.get("apiBaseURL"),a;e?a=e:r?a=r:a=s?"https://test-api.jolibox.com":"https://api.jolibox.com",window.joliboxenv={testMode:s,apiBaseURL:a}};var d,s,r,a;this.setJoliboxEnv(n,i),o&&window.joliboxsdk?(this.loader=(d=window.joliboxsdk.loader)!=null?d:new window.JoliboxSDKLoader(e),this.ads=(s=window.joliboxsdk.ads)!=null?s:new window.JoliboxAds,this.anaytics=(r=window.joliboxsdk.anaytics)!=null?r:new window.JoliboxAnalytics,this.runtime=(a=window.joliboxsdk.runtime)!=null?a:new window.JoliboxRuntime):(window.joliboxsdk||(window.joliboxsdk={_commandPipe:[]}),this.loader=new window.JoliboxSDKLoader(e),this.ads=new window.JoliboxAds,this.anaytics=new window.JoliboxAnalytics,this.runtime=new window.JoliboxRuntime,window.joliboxsdk=Object.assign(this,window.joliboxsdk)),window.joliboxsdk._commandPipe||(window.joliboxsdk._commandPipe=[])}};window.JoliboxSDK||(window.JoliboxSDK=m);var B=m;})();
1
+ "use strict";(()=>{var c=(t,o,e)=>new Promise((n,i)=>{var d=a=>{try{r(e.next(a))}catch(l){i(l)}},s=a=>{try{r(e.throw(a))}catch(l){i(l)}},r=a=>a.done?n(a.value):Promise.resolve(a.value).then(d,s);r((e=e.apply(t,o)).next())});var b=t=>{var r,a,l;let o=t.split("-")[1];o&&(t=t.replace(`-${o}`,""));let e=t.split("+")[1];e&&(t=t.replace(`+${e}`,""));let n=t.split(".").slice(0,3),[i,d,s]=[(r=n[0])!=null?r:"0",(a=n[1])!=null?a:"0",(l=n[2])!=null?l:"0"];return{major:i,minor:d,patch:s,prerelease:o,build:e}},p=t=>parseInt(b(t).major,10),h=(t,o)=>{let{major:e,minor:n,patch:i}=b(t),{major:d,minor:s,patch:r}=b(o);return e!==d?e>d?1:-1:n!==s?n>s?1:-1:i!==r?i>r?1:-1:0};var g="jolibox-sdk-loader-metadata",f=class{constructor({loaderMetadata:o}={}){this.computeLoaderMetaData=()=>{var i,d;let o=this.currentVersion,e=null;try{if(e=JSON.parse((i=localStorage.getItem(g))!=null?i:"null"),!e||!e.version)throw new Error("Invalid loader metadata")}catch(s){e=this.defaultMetadata}let n=(d=e==null?void 0:e.version)!=null?d:o;return p(n)!==p(o)?e=this.defaultMetadata:h(n,o)<0&&(e=this.defaultMetadata),e};this.loadScript=()=>{if(this.loaderMetadata.syncScriptUrl){let o=new XMLHttpRequest;o.open("GET",this.loaderMetadata.syncScriptUrl,!1),o.send();let e=document.createElement("script");e.type="text/javascript",e.innerHTML=o.responseText,document.head.appendChild(e)}if(this.loaderMetadata.asyncScriptUrl){let o=document.createElement("script");o.type="text/javascript",o.src=this.loaderMetadata.asyncScriptUrl,o.async=!0,document.head.appendChild(o)}};this.fetchUpdateLoaderMetadata=(...d)=>c(this,[...d],function*(o=this.currentVersion,e=this.loaderMetadata.version,n=(i=>(i=window.JOLIBOX_ENV)!=null?i:"WEB")()){var r,a,l;let s=`${(a=(r=window.joliboxenv)==null?void 0:r.apiBaseURL)!=null?a:"https://api.jolibox.com"}/frontend/js-sdk/loader-metadata`;try{let w=yield(yield fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({installedSDKVersion:o,localSDKVersion:e,env:n})})).json();if(w.code!=="SUCCESS")throw new Error(w.message);this.loaderMetadata=(l=w.data)!=null?l:this.defaultMetadata,localStorage.setItem(g,JSON.stringify(this.loaderMetadata))}catch(u){console.warn("Failed to fetch loader metadata: ",u)}});console.log("Loading Jolibox SDK..."),this.loaderMetadata=o!=null?o:this.computeLoaderMetaData(),this.loadScript(),this.fetchUpdateLoaderMetadata(),console.log("Jolibox SDK loaded.")}get currentVersion(){return window.__JOLIBOX_LOCAL_SDK_VERSION__}get defaultMetadata(){let o=this.currentVersion,e=p(o);return{version:o,syncScriptUrl:`https://cdn.jsdelivr.net/npm/@jolibox/web-sync-sdk@${e}/dist/index.iife.js`,asyncScriptUrl:`https://cdn.jsdelivr.net/npm/@jolibox/web-async-sdk@${e}/dist/index.iife.js`}}};window.JoliboxSDKLoader=f;var x=class{constructor(){this.init=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.init",params:o})};this.adConfig=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.adConfig",params:o})};this.adBreak=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.adBreak",params:o})};this.adUnit=o=>c(this,null,function*(){window.joliboxsdk._commandPipe.push({cmd:"ads.adUnit",params:o})})}};window.JoliboxAds=x;var I=class{constructor(){this.trackEvent=(o,e)=>{if(typeof o!="string")throw new Error("eventName must be a string");if(e!==null&&typeof e!="object"&&e!==void 0)throw new Error("extra must be an object or null or undefined");if(e){for(let n in e)if(typeof e[n]=="object")throw new Error("extra must not have nested objects")}window.joliboxsdk._commandPipe.push({cmd:"analytics.trackEvent",params:[o,e]})}}};window.JoliboxAnalytics=I;var S=(t=>(t.LOAD_START="JOLIBOX_RUNTIME_LOAD_START",t.LOAD_FINISHED="JOLIBOX_RUNTIME_LOAD_FINISHED",t.LOAD_PROGRESS="JOLIBOX_RUNTIME_LOAD_PROGRESS",t))(S||{});window.dispatchEvent(new Event("JOLIBOX_RUNTIME_LOAD_START"));var y=class{constructor(){this.loadFinished=()=>{let t=new Event("JOLIBOX_RUNTIME_LOAD_FINISHED");window.dispatchEvent(t),window.joliboxsdk._commandPipe.push({cmd:"analytics.trackSystemEvent",params:["CallRuntimeLoadFinished"]})},this.notifyLoadProgress=t=>{let o=Math.ceil(t),e=new CustomEvent("JOLIBOX_RUNTIME_LOAD_PROGRESS",{detail:o});window.dispatchEvent(e)}}};window.JoliboxRuntime=y;window.__JOLIBOX_LOCAL_SDK_VERSION__="1.0.7-beta.1";var m=class{constructor({useRuntimeSDK:o=!0,loaderConfig:e,testMode:n,apiBaseURL:i}={}){this.setJoliboxEnv=(o,e)=>{let i=typeof window<"u"?new URLSearchParams(window.location.search):null,d=(i==null?void 0:i.get("testMode"))==="true",s=o!=null?o:d,r=i==null?void 0:i.get("apiBaseURL"),a;e?a=e:r?a=r:a=s?"https://test-api.jolibox.com":"https://api.jolibox.com",window.joliboxenv={testMode:s,apiBaseURL:a}};var d,s,r,a;this.setJoliboxEnv(n,i),o&&window.joliboxsdk?(this.loader=(d=window.joliboxsdk.loader)!=null?d:new window.JoliboxSDKLoader(e),this.ads=(s=window.joliboxsdk.ads)!=null?s:new window.JoliboxAds,this.anaytics=(r=window.joliboxsdk.anaytics)!=null?r:new window.JoliboxAnalytics,this.runtime=(a=window.joliboxsdk.runtime)!=null?a:new window.JoliboxRuntime):(window.joliboxsdk||(window.joliboxsdk={_commandPipe:[]}),this.loader=new window.JoliboxSDKLoader(e),this.ads=new window.JoliboxAds,this.anaytics=new window.JoliboxAnalytics,this.runtime=new window.JoliboxRuntime,window.joliboxsdk=Object.assign(this,window.joliboxsdk)),window.joliboxsdk._commandPipe||(window.joliboxsdk._commandPipe=[])}};window.JoliboxSDK||(window.JoliboxSDK=m);var B=m;})();
2
2
  //# sourceMappingURL=index.iife.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/loader/utils.ts","../src/loader/index.ts","../src/ads/index.ts","../src/analytics/index.ts","../../web-sync-sdk/src/index.ts","../src/index.ts"],"sourcesContent":["const splitSemver = (\n version: string\n): {\n major: string;\n minor: string;\n patch: string;\n prerelease?: string;\n build?: string;\n} => {\n const prerelease = version.split(\"-\")[1] as string | undefined;\n if (prerelease) {\n version = version.replace(`-${prerelease}`, \"\");\n }\n\n const build = version.split(\"+\")[1] as string | undefined;\n if (build) {\n version = version.replace(`+${build}`, \"\");\n }\n\n const splitted = version.split(\".\").slice(0, 3);\n const [major, minor, patch] = [\n splitted[0] ?? \"0\",\n splitted[1] ?? \"0\",\n splitted[2] ?? \"0\",\n ];\n return { major, minor, patch, prerelease, build };\n};\n\nexport const major = (version: string): number =>\n parseInt(splitSemver(version).major, 10);\n\nexport const compare = (v1: string, v2: string): -1 | 0 | 1 => {\n const { major: major1, minor: minor1, patch: patch1 } = splitSemver(v1);\n const { major: major2, minor: minor2, patch: patch2 } = splitSemver(v2);\n\n if (major1 !== major2) {\n return major1 > major2 ? 1 : -1;\n }\n\n if (minor1 !== minor2) {\n return minor1 > minor2 ? 1 : -1;\n }\n\n if (patch1 !== patch2) {\n return patch1 > patch2 ? 1 : -1;\n }\n\n return 0;\n};\n","import { major, compare } from \"./utils\";\n\ndeclare global {\n interface Window {\n JOLIBOX_ENV: \"WEB\" | \"IOS\" | \"ANDROID\" | \"WINDOWS\" | \"MACOS\" | \"LINUX\";\n JoliboxSDKLoader: typeof JoliboxSDKLoader;\n }\n}\n\nconst joliboxLoaderKey = \"jolibox-sdk-loader-metadata\";\n\nexport interface IVersionMetadata {\n version: string;\n syncScriptUrl?: string; // By default, the sync script is bundled with the sdk\n asyncScriptUrl?: string;\n}\n\nexport interface IRemoteVersionMetadata {\n code: \"SUCCESS\" | string;\n message?: string;\n data?: IVersionMetadata;\n}\n\nexport interface IJoliboxSDKLoaderConfig {\n loaderMetadata?: IVersionMetadata;\n}\n\nexport class JoliboxSDKLoader {\n loaderMetadata: IVersionMetadata;\n\n constructor({ loaderMetadata }: IJoliboxSDKLoaderConfig = {}) {\n console.log(\"Loading Jolibox SDK...\");\n\n this.loaderMetadata = loaderMetadata ?? this.computeLoaderMetaData();\n this.loadScript();\n this.fetchUpdateLoaderMetadata();\n console.log(\"Jolibox SDK loaded.\");\n }\n\n private get currentVersion() {\n return window.__JOLIBOX_LOCAL_SDK_VERSION__;\n }\n\n private get defaultMetadata(): IVersionMetadata {\n const version = this.currentVersion;\n const majorVersion = major(version);\n return {\n version,\n syncScriptUrl: `https://cdn.jsdelivr.net/npm/@jolibox/web-sync-sdk@${majorVersion}/dist/index.iife.js`,\n asyncScriptUrl: `https://cdn.jsdelivr.net/npm/@jolibox/web-async-sdk@${majorVersion}/dist/index.iife.js`,\n };\n }\n\n computeLoaderMetaData = () => {\n const version = this.currentVersion;\n let loaderMetadata: IVersionMetadata | null = null;\n try {\n loaderMetadata = JSON.parse(\n localStorage.getItem(joliboxLoaderKey) ?? \"null\"\n ) as IVersionMetadata | null;\n if (!loaderMetadata || !loaderMetadata.version) {\n throw new Error(\"Invalid loader metadata\");\n }\n } catch (error) {\n loaderMetadata = this.defaultMetadata;\n }\n\n const versionFromLocalStorage = loaderMetadata?.version ?? version;\n\n if (major(versionFromLocalStorage) !== major(version)) {\n // if major version is different, must follow the version from package.json\n loaderMetadata = this.defaultMetadata;\n } else {\n // if major version is the same, follow the larger version\n if (compare(versionFromLocalStorage, version) < 0) {\n loaderMetadata = this.defaultMetadata;\n }\n }\n\n return loaderMetadata;\n };\n\n loadScript = () => {\n if (this.loaderMetadata.syncScriptUrl) {\n // The only way to load a script synchronously is to use XMLHttpRequest\n const xhr = new XMLHttpRequest();\n xhr.open(\"GET\", this.loaderMetadata.syncScriptUrl, false);\n xhr.send();\n // eval(xhr.responseText);\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.innerHTML = xhr.responseText;\n document.head.appendChild(script);\n }\n\n if (this.loaderMetadata.asyncScriptUrl) {\n const asyncScript = document.createElement(\"script\");\n asyncScript.type = \"text/javascript\";\n asyncScript.src = this.loaderMetadata.asyncScriptUrl;\n asyncScript.async = true;\n document.head.appendChild(asyncScript);\n }\n };\n\n fetchUpdateLoaderMetadata = async (\n installedSDKVersion = this.currentVersion,\n localSDKVersion = this.loaderMetadata.version,\n env = window.JOLIBOX_ENV ?? \"WEB\"\n ) => {\n const path = `${\n window.joliboxenv?.apiBaseURL ?? \"https://api.jolibox.com\"\n }/frontend/js-sdk/loader-metadata`;\n try {\n const response = await fetch(path, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n installedSDKVersion,\n localSDKVersion,\n env,\n }),\n });\n const data: IRemoteVersionMetadata = await response.json();\n if (data.code !== \"SUCCESS\") {\n throw new Error(data.message);\n } else {\n this.loaderMetadata = data.data ?? this.defaultMetadata;\n localStorage.setItem(\n joliboxLoaderKey,\n JSON.stringify(this.loaderMetadata)\n );\n // reload happens next time the page is loaded\n }\n } catch (error) {\n console.warn(\"Failed to fetch loader metadata: \", error);\n }\n };\n}\n\nwindow.JoliboxSDKLoader = JoliboxSDKLoader;\n","declare global {\n interface Window {\n JoliboxAds: typeof JoliboxAds;\n }\n}\n\nexport interface IAdsInitParams {\n /**\n * (OPTIONAL) Game ID provided by Jolibox\n */\n gameId?: string;\n}\n\nexport interface IAdConfigParams {\n /**\n * (OPTIONAL) Whether ads should always be preloaded before the first call to adBreak()\n *\n * The default value of auto leaves the decision up to the Ad Placement API. preloadAdBreaks can be set only once with adConfig(), and further values passed to preloadAdBreaks have no effect.\n *\n * Setting preloadAdBreaks after the first call to adBreak() has no effect.\n */\n preloadAdBreaks?: \"on\" | \"auto\"; // default: 'auto'\n\n /**\n * (OPTIONAL) Whether the game is currently playing sound.\n *\n * This call specifies whether your game is capable of sound, and whether the sound was enabled (ie unmuted) before the call to adBreak(). This helps the Ad Placement API to select the right kind of ad for your game.\n *\n * Call this function as soon as the sound state of your game changes, as the Ad Placement API may have to request new creatives, and this gives it the maximum amount of time to do so.\n *\n * The default value is sound on. So most games will need to make a call to adConfig() when they start to declare that they have sound enabled.\n */\n sound?: \"on\" | \"off\"; // default: 'on'\n\n /**\n * (OPTIONAL) Called when the API has initialized and has finished preloading ads (if you requested preloading using the preloadAdBreaks above).\n * @returns\n */\n onReady?: () => void;\n}\n\n/**\n * PlacementInfo object passed by **adBreakDone** function\n */\nexport interface IPlacementInfo {\n /**\n * the type argument passed to adBreak()\n */\n breakType: string;\n /**\n * the name argument passed to adBreak()\n */\n breakName: string;\n breakFormat: \"interstitial\" | \"reward\";\n /**\n * the status of this placement and can be one of the following values:\n *\n * | breakStatus | Reason |\n * | -------- | ------- |\n * | 'notReady'\t| The Ad Placement API had not initialised |\n * | 'timeout' | A placement timed out because the Ad Placement API took too long to respond |\n * | 'invalid' | The placement was invalid and was ignored–for instance there should only be one preroll placement per page load, subsequent prerolls are failed with this status |\n * | 'error' | There was a JavaScript error in a callback |\n * | 'noAdPreloaded' |\tAn ad had not been preloaded yet so this placement was skipped |\n * | 'frequencyCapped' |\tAn ad wasn't shown because the frequency cap was applied to this placement |\n * | 'ignored' |\tThe user didn't click on a reward prompt before they reached the next placement, that is showAdFn() wasn't called before the next adBreak(). |\n * | 'other' |\tThe ad was not shown for another reason. (e.g., The ad was still being fetched, or a previously cached ad was disposed because the screen was resized/rotated.) |\n * | 'dismissed' |\tThe user dismissed a rewarded ad before viewing it to completion |\n * | 'viewed' |\tThe ad was viewed by the user |\n */\n breakStatus:\n | \"notReady\"\n | \"timeout\"\n | \"error\"\n | \"noAdPreloaded\"\n | \"frequencyCapped\"\n | \"ignored\"\n | \"other\"\n | \"dismissed\"\n | \"viewed\";\n}\n\n/**\n * Parameter when calling adBreak\n */\nexport type IAdBreakParams =\n | IPrerollParams\n | IInterstitialsParams\n | IRewardParams;\n\n/**\n * Parameter when calling preroll type adBreak\n */\nexport interface IPrerollParams {\n /**\n * 'preroll' before the game loads (before UI has rendered)\n */\n type: \"preroll\";\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n}\n\nexport interface IInterstitialsParams {\n /**\n * 'start' before the gameplay starts (after UI has rendered)\n * 'pause' the player pauses the game\n * 'next' player navigates to the next level\n * 'browse' the player explores options outside of the gameplay\n */\n type: \"start\" | \"pause\" | \"next\" | \"browse\";\n\n /**\n * (OPTIONAL) a name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. In future releases this identifier may be used to enable additional reporting and optimization features.\n *\n * We recommend you name all of your placements.\n */\n name?: string;\n\n /**\n * (OPTIONAL) Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes.\n *\n * @returns\n */\n beforeAd?: () => void;\n\n /**\n * (OPTIONAL) Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actions. This function should be used to resume game flow. For example, use to unmute the sound and start the next level.\n * @returns\n */\n afterAd?: () => void;\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object\n *\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n}\n\nexport interface IRewardParams {\n /**\n * 'reward' a rewarded ad\n */\n type: \"reward\";\n\n /**\n * (OPTIONAL) a name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. In future releases this identifier may be used to enable additional reporting and optimization features.\n *\n * We recommend you name all of your placements.\n */\n name?: string;\n\n /**\n * (OPTIONAL) Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes.\n * @returns\n */\n beforeAd?: () => void;\n\n /**\n * (OPTIONAL) Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actions. This function should be used to resume game flow. For example, use to unmute the sound and start the next level.\n * @returns\n */\n afterAd?: () => void;\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object defined\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n\n /**\n * Called if a rewarded ad is available. The function should take a single argument–showAdFn() which must be called to display the rewarded ad.\n * @param showAdFn\n * @returns\n */\n beforeReward: (showAdFn: () => void) => void;\n\n /**\n * Called only for rewarded ads when the player dismisses the ad. It is only called if the player dismisses the ad before it completes. In this case the reward should not be granted.\n * @returns\n */\n adDismissed: () => void;\n\n /**\n * Called only for rewarded ads when the player completes the ad and should be granted the reward.\n * @returns\n */\n adViewed: () => void;\n}\n\n/**\n * Ad unit format, can be 'rectangle', 'vertical', 'horizontal'\n */\nexport type AdUnitFormat = \"rectangle\" | \"vertical\" | \"horizontal\";\n\nexport interface IAdUnitParams {\n /**\n * The element to attach the ad unit to, either an HTMLElement or a string selector. Should be the parent element of the ad unit (<ins> tag).\n */\n el: HTMLElement | string;\n\n /**\n * (OPTIONAL) Reserved for future usage. The slot ID of the ad unit. Currently the slot ID is automatically set by the SDK.\n */\n slot?: string;\n\n // /**\n // * (OPTIONAL) The position of the ad unit. Can be 'TOP', 'BOTTOM', 'LEFT', 'RIGHT', 'CENTER'. Default is 'TOP'. Either position or slot should be set.\n // */\n // position?: AdUnitPosition;\n\n // /**\n // * (OPTIONAL) Channel ID for the ad unit. We will set the Channel ID automatically if not provided. Default is empty.\n // */\n // channelId?: string;\n\n /**\n * (OPTIONAL) Ad format for the ad unit. Can be 'auto' or a single format or an array of formats. Default is 'auto'. If passed as an array, the array will be joined by ', ' and pass to the data-ad-format attribute.\n */\n adFormat?: \"auto\" | AdUnitFormat | AdUnitFormat[];\n\n /**\n * (OPTIONAL) Whether the ad unit should be full width and responsive. Default is false.\n */\n fullWidthResponsive?: \"true\" | \"false\";\n\n /**\n * (OPTIONAL) Custom style for the ad unit. Default is empty.\n */\n style?: string;\n}\n\n/**\n * Jolibox Ads SDK\n */\nexport class JoliboxAds {\n /**\n * Internal constructor, should not be called directly\n */\n constructor() {}\n\n /**\n * Init JoliboxAds. Must be called before any other ads functions.\n * @param config\n * @returns\n */\n public init = (config?: IAdsInitParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.init\",\n params: config,\n });\n };\n\n /**\n * The adConfig() call communicates the game's current configuration to the Ad Placement API. The Ad Placement API can use this to tune the way it preloads ads and to filter the kinds of ads it requests so they're suitable (eg. video ads that require sound).\n * @param params\n */\n public adConfig = (params: IAdConfigParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adConfig\",\n params,\n });\n };\n\n /**\n * adBreak() is the key function for placing ads within your game. It defines an ad placement and takes an object called a placement config that specifies everything required to show an ad.\n *\n * The adBreak() function defines a placement where an ad could be shown. Whether an ad actually shows depends on factors such as the following:\n *\n * - The type of ad placement that you declared\n * - Is this ad at the start of the game? Between levels? At a moment when the player has paused the game?\n * - Whether a suitable ad exists for the current player\n * - Is this ad relevant to them?\n * - Is it consistent with their data privacy and consent settings?\n * - The number of ads the player has seen recently\n * - The control settings—for example, ad frequency, you've configured for this game\n * - Either as hints in the tag, or,\n * - Within AdSense—note that the controls available in AdSense will evolve over time.\n *\n * The kind of ad that shows also depends on similar factors.\n *\n * Note that a call to adBreak() might not show an ad at all. It simply declares a place where an ad could be shown.\n *\n * This is unlike traditional APIs in which your code always knows if an ad is available, and you decide within the game whether to show it. This approach of letting the Ad Placement API decide if an ad shows in a particular placement is a pattern that is sometimes referred to as \"inversion of control\".\n *\n * The reason we're transitioning our games API to this model is firstly, it shortens the code you have to write within your game. Secondly, it makes it easier to deliver policy compliant placements with a great user experience, which in turn has allowed us to deliver some of our highest performing formats to games publishers. Lastly, it more cleanly separates the process of placing ads in your game from the monetization decisions about the type and number of ads to show.\n *\n * We want you to be able to change your monetization settings and control the user experience without having to edit and release a new version of your game, initially by specifying hints in the tag. But in future releases, we will be able to provide controls directly in the AdSense and AdMob frontends.\n * @param params\n */\n public adBreak = (params: IAdBreakParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adBreak\",\n params,\n });\n };\n\n /**\n * adUnit() is a function that creates an ad unit and attaches it to a parent element. The ad unit is a single ad placement that can be used to show ads.\n *\n * Currently we only provide support for creating ad units as `<ins>` tags with the class 'adsbygoogle'. This is the standard way to create ad units with Google AdSense.\n *\n * After calling this method, the ad unit is attached to the parent element you specify as el in the params object.\n *\n * By default, the client ID and channel ID are automatically set by the SDK. And the slot name is set to the position of the ad unit. You can override these values by passing the slot and channelId in the params object.\n *\n * @param params\n * @returns\n */\n public adUnit = async (params: IAdUnitParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adUnit\",\n params,\n });\n };\n}\n\nwindow.JoliboxAds = JoliboxAds;\n\nexport default JoliboxAds;\n","declare global {\n interface Window {\n JoliboxAnalytics: typeof JoliboxAnalytics;\n }\n}\n\n/**\n * Jolibox Analytics SDK\n */\nexport class JoliboxAnalytics {\n constructor() {}\n\n /**\n * Track an event, will be sent to the analytics server\n *\n * @param eventName event name, must be a string\n * @param extra (OPTIONAL) extra data, must be an object or null or undefined, must not have nested objects\n */\n public trackEvent = (\n eventName: string,\n extra?: Record<string, string | boolean | number | null> | null\n ) => {\n // assert eventName is a string\n if (typeof eventName !== \"string\") {\n throw new Error(\"eventName must be a string\");\n }\n\n // assert extra is an object or null or undefined\n if (extra !== null && typeof extra !== \"object\" && extra !== undefined) {\n throw new Error(\"extra must be an object or null or undefined\");\n }\n\n // assert extra has no nested objects\n if (extra) {\n for (const key in extra) {\n if (typeof extra[key] === \"object\") {\n throw new Error(\"extra must not have nested objects\");\n }\n }\n }\n\n window.joliboxsdk._commandPipe.push({\n cmd: \"analytics.trackEvent\",\n params: [eventName, extra],\n });\n };\n}\n\nwindow.JoliboxAnalytics = JoliboxAnalytics;\n\nexport default JoliboxAnalytics;\n","interface ICommandPipe {\n cmd: string;\n params: any;\n}\n\ndeclare global {\n interface IJoliboxSDK {\n _commandPipe: ICommandPipe[];\n }\n interface Window {\n joliboxsdk: IJoliboxSDK;\n JoliboxRuntime: typeof JoliboxRuntime;\n JoliboxRuntimeEvents: typeof JoliboxRuntimeEvents;\n }\n}\n\nexport enum JoliboxRuntimeEvents {\n /**\n * Event dispatched when the loading starts\n */\n LOAD_START = \"JOLIBOX_RUNTIME_LOAD_START\",\n\n /**\n * Event dispatched when the loading is finished\n */\n LOAD_FINISHED = \"JOLIBOX_RUNTIME_LOAD_FINISHED\",\n\n /**\n * Event dispatched when the loading progress is updated\n */\n LOAD_PROGRESS = \"JOLIBOX_RUNTIME_LOAD_PROGRESS\",\n}\n\nwindow.dispatchEvent(new Event(JoliboxRuntimeEvents.LOAD_START));\n\n/**\n * Jolibox Runtime, a set of utilities to interact with the Jolibox runtime\n * @class\n */\nexport class JoliboxRuntime {\n /**\n * Notify the end of the loading, will close the loading splash screen\n */\n loadFinished = () => {\n const loadFinishedEvent = new Event(JoliboxRuntimeEvents.LOAD_FINISHED);\n window.dispatchEvent(loadFinishedEvent);\n window.joliboxsdk._commandPipe.push({\n cmd: \"analytics.trackSystemEvent\",\n params: [\"CallRuntimeLoadFinished\"],\n });\n };\n\n /**\n * Notify the progress of the loading, will update the loading splash screen\n * @param progress - The progress of the loading, should be an integer between 0 and 100\n */\n notifyLoadProgress = (progress: number) => {\n const detail = Math.ceil(progress);\n const event = new CustomEvent(JoliboxRuntimeEvents.LOAD_PROGRESS, {\n detail,\n });\n window.dispatchEvent(event);\n };\n}\n\nwindow.JoliboxRuntime = JoliboxRuntime;\n\nexport default JoliboxRuntime;\n","import \"./loader\";\nimport \"./ads\";\nimport \"./analytics\";\nimport \"@jolibox/web-sync-sdk\";\nimport type { JoliboxSDKLoader, IJoliboxSDKLoaderConfig } from \"./loader\";\nimport type { JoliboxAds } from \"./ads\";\nimport type { JoliboxAnalytics } from \"./analytics\";\nimport type { JoliboxRuntime } from \"./runtime\";\n\ndeclare global {\n interface IJoliboxSDK extends JoliboxSDK {\n _commandPipe: ICommandPipe[];\n }\n interface Window {\n __JOLIBOX_LOCAL_SDK_VERSION__: string;\n joliboxenv?: {\n testMode: boolean;\n apiBaseURL: string;\n };\n joliboxsdk: IJoliboxSDK;\n JoliboxSDK: typeof JoliboxSDK;\n }\n interface ImportMeta {\n env: {\n JOLIBOX_SDK_VERSION: string;\n };\n }\n}\n\nwindow.__JOLIBOX_LOCAL_SDK_VERSION__ = import.meta.env.JOLIBOX_SDK_VERSION;\n\nexport interface IJoliboxConfig {\n useRuntimeSDK?: boolean;\n loaderConfig?: IJoliboxSDKLoaderConfig;\n testMode?: boolean;\n apiBaseURL?: string;\n}\n\ninterface ICommandPipe {\n cmd: string;\n params: any;\n}\n\nclass JoliboxSDK {\n private loader: JoliboxSDKLoader;\n ads: JoliboxAds;\n anaytics: JoliboxAnalytics;\n runtime: JoliboxRuntime;\n\n setJoliboxEnv = (inputTestMode?: boolean, inputApiBaseURL?: string) => {\n const isBrowser = typeof window !== \"undefined\";\n const urlSearchParams = isBrowser\n ? new URLSearchParams(window.location.search)\n : null;\n const testModeParam = urlSearchParams?.get(\"testMode\") === \"true\";\n const testMode = inputTestMode ?? testModeParam;\n\n const apiBaseURLParam = urlSearchParams?.get(\"apiBaseURL\");\n let apiBaseURL;\n if (inputApiBaseURL) {\n apiBaseURL = inputApiBaseURL;\n } else if (apiBaseURLParam) {\n apiBaseURL = apiBaseURLParam;\n } else {\n apiBaseURL = testMode\n ? \"https://test-api.jolibox.com\"\n : \"https://api.jolibox.com\";\n }\n window.joliboxenv = {\n testMode,\n apiBaseURL,\n };\n };\n\n constructor({\n useRuntimeSDK = true,\n loaderConfig,\n testMode,\n apiBaseURL,\n }: IJoliboxConfig = {}) {\n this.setJoliboxEnv(testMode, apiBaseURL);\n if (useRuntimeSDK && window.joliboxsdk) {\n this.loader =\n window.joliboxsdk.loader ?? new window.JoliboxSDKLoader(loaderConfig);\n this.ads = window.joliboxsdk.ads ?? new window.JoliboxAds();\n this.anaytics =\n window.joliboxsdk.anaytics ?? new window.JoliboxAnalytics();\n this.runtime = window.joliboxsdk.runtime ?? new window.JoliboxRuntime();\n } else {\n if (!window.joliboxsdk) {\n window.joliboxsdk = {\n _commandPipe: [], // This is to avoid the error \"Cannot read property 'push' of undefined\" if any command is called before the SDK is initialized\n } as any;\n }\n\n this.loader = new window.JoliboxSDKLoader(loaderConfig);\n this.ads = new window.JoliboxAds();\n this.anaytics = new window.JoliboxAnalytics();\n this.runtime = new window.JoliboxRuntime();\n window.joliboxsdk = Object.assign(this, window.joliboxsdk);\n }\n if (!window.joliboxsdk._commandPipe) {\n window.joliboxsdk._commandPipe = [];\n }\n }\n}\n\nif (!window.JoliboxSDK) {\n window.JoliboxSDK = JoliboxSDK;\n}\n\nexport default JoliboxSDK;\nexport { JoliboxSDK };\n"],"mappings":"gOAAA,IAAMA,EACJC,GAOG,CARL,IAAAC,EAAAC,EAAAC,EASE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AiB,IAAI,eAAgB,OACrDJ,EAAWE,GAAA,KAAAA,EAAiBG,EAE5BC,EAAkBF,GAAA,YAAAA,EAAiB,IAAI,cACzCH,EACAE,EACFF,EAAaE,EACJG,EACTL,EAAaK,EAEbL,EAAaD,EACT,+BACA,0BAEN,OAAO,WAAa,CAClB,SAAAA,EACA,WAAAC,CACF,CACF,EAxEF,IAAAM,EAAAC,EAAAC,EAAAC,EAgFI,KAAK,cAAcV,EAAUC,CAAU,EACnCH,GAAiB,OAAO,YAC1B,KAAK,QACHS,EAAA,OAAO,WAAW,SAAlB,KAAAA,EAA4B,IAAI,OAAO,iBAAiBR,CAAY,EACtE,KAAK,KAAMS,EAAA,OAAO,WAAW,MAAlB,KAAAA,EAAyB,IAAI,OAAO,WAC/C,KAAK,UACHC,EAAA,OAAO,WAAW,WAAlB,KAAAA,EAA8B,IAAI,OAAO,iBAC3C,KAAK,SAAUC,EAAA,OAAO,WAAW,UAAlB,KAAAA,EAA6B,IAAI,OAAO,iBAElD,OAAO,aACV,OAAO,WAAa,CAClB,aAAc,CAAC,CACjB,GAGF,KAAK,OAAS,IAAI,OAAO,iBAAiBX,CAAY,EACtD,KAAK,IAAM,IAAI,OAAO,WACtB,KAAK,SAAW,IAAI,OAAO,iBAC3B,KAAK,QAAU,IAAI,OAAO,eAC1B,OAAO,WAAa,OAAO,OAAO,KAAM,OAAO,UAAU,GAEtD,OAAO,WAAW,eACrB,OAAO,WAAW,aAAe,CAAC,EAEtC,CACF,EAEK,OAAO,aACV,OAAO,WAAaF,GAGtB,IAAOc,EAAQd","names":["splitSemver","version","_a","_b","_c","prerelease","build","splitted","major","minor","patch","compare","v1","v2","major1","minor1","patch1","major2","minor2","patch2","joliboxLoaderKey","JoliboxSDKLoader","loaderMetadata","_a","_b","version","error","versionFromLocalStorage","major","compare","xhr","script","asyncScript","_0","__async","installedSDKVersion","localSDKVersion","env","_c","path","data","majorVersion","JoliboxAds","config","params","__async","JoliboxAnalytics","eventName","extra","key","JoliboxRuntimeEvents","JoliboxRuntime","loadFinishedEvent","progress","detail","event","JoliboxSDK","useRuntimeSDK","loaderConfig","testMode","apiBaseURL","inputTestMode","inputApiBaseURL","urlSearchParams","testModeParam","apiBaseURLParam","_a","_b","_c","_d","src_default"]}
1
+ {"version":3,"sources":["../src/loader/utils.ts","../src/loader/index.ts","../src/ads/index.ts","../src/analytics/index.ts","../../web-sync-sdk/src/index.ts","../src/index.ts"],"sourcesContent":["const splitSemver = (\n version: string\n): {\n major: string;\n minor: string;\n patch: string;\n prerelease?: string;\n build?: string;\n} => {\n const prerelease = version.split(\"-\")[1] as string | undefined;\n if (prerelease) {\n version = version.replace(`-${prerelease}`, \"\");\n }\n\n const build = version.split(\"+\")[1] as string | undefined;\n if (build) {\n version = version.replace(`+${build}`, \"\");\n }\n\n const splitted = version.split(\".\").slice(0, 3);\n const [major, minor, patch] = [\n splitted[0] ?? \"0\",\n splitted[1] ?? \"0\",\n splitted[2] ?? \"0\",\n ];\n return { major, minor, patch, prerelease, build };\n};\n\nexport const major = (version: string): number =>\n parseInt(splitSemver(version).major, 10);\n\nexport const compare = (v1: string, v2: string): -1 | 0 | 1 => {\n const { major: major1, minor: minor1, patch: patch1 } = splitSemver(v1);\n const { major: major2, minor: minor2, patch: patch2 } = splitSemver(v2);\n\n if (major1 !== major2) {\n return major1 > major2 ? 1 : -1;\n }\n\n if (minor1 !== minor2) {\n return minor1 > minor2 ? 1 : -1;\n }\n\n if (patch1 !== patch2) {\n return patch1 > patch2 ? 1 : -1;\n }\n\n return 0;\n};\n","import { major, compare } from \"./utils\";\n\ndeclare global {\n interface Window {\n JOLIBOX_ENV: \"WEB\" | \"IOS\" | \"ANDROID\" | \"WINDOWS\" | \"MACOS\" | \"LINUX\";\n JoliboxSDKLoader: typeof JoliboxSDKLoader;\n }\n}\n\nconst joliboxLoaderKey = \"jolibox-sdk-loader-metadata\";\n\nexport interface IVersionMetadata {\n version: string;\n syncScriptUrl?: string; // By default, the sync script is bundled with the sdk\n asyncScriptUrl?: string;\n}\n\nexport interface IRemoteVersionMetadata {\n code: \"SUCCESS\" | string;\n message?: string;\n data?: IVersionMetadata;\n}\n\nexport interface IJoliboxSDKLoaderConfig {\n loaderMetadata?: IVersionMetadata;\n}\n\nexport class JoliboxSDKLoader {\n loaderMetadata: IVersionMetadata;\n\n constructor({ loaderMetadata }: IJoliboxSDKLoaderConfig = {}) {\n console.log(\"Loading Jolibox SDK...\");\n\n this.loaderMetadata = loaderMetadata ?? this.computeLoaderMetaData();\n this.loadScript();\n this.fetchUpdateLoaderMetadata();\n console.log(\"Jolibox SDK loaded.\");\n }\n\n private get currentVersion() {\n return window.__JOLIBOX_LOCAL_SDK_VERSION__;\n }\n\n private get defaultMetadata(): IVersionMetadata {\n const version = this.currentVersion;\n const majorVersion = major(version);\n return {\n version,\n syncScriptUrl: `https://cdn.jsdelivr.net/npm/@jolibox/web-sync-sdk@${majorVersion}/dist/index.iife.js`,\n asyncScriptUrl: `https://cdn.jsdelivr.net/npm/@jolibox/web-async-sdk@${majorVersion}/dist/index.iife.js`,\n };\n }\n\n computeLoaderMetaData = () => {\n const version = this.currentVersion;\n let loaderMetadata: IVersionMetadata | null = null;\n try {\n loaderMetadata = JSON.parse(\n localStorage.getItem(joliboxLoaderKey) ?? \"null\"\n ) as IVersionMetadata | null;\n if (!loaderMetadata || !loaderMetadata.version) {\n throw new Error(\"Invalid loader metadata\");\n }\n } catch (error) {\n loaderMetadata = this.defaultMetadata;\n }\n\n const versionFromLocalStorage = loaderMetadata?.version ?? version;\n\n if (major(versionFromLocalStorage) !== major(version)) {\n // if major version is different, must follow the version from package.json\n loaderMetadata = this.defaultMetadata;\n } else {\n // if major version is the same, follow the larger version\n if (compare(versionFromLocalStorage, version) < 0) {\n loaderMetadata = this.defaultMetadata;\n }\n }\n\n return loaderMetadata;\n };\n\n loadScript = () => {\n if (this.loaderMetadata.syncScriptUrl) {\n // The only way to load a script synchronously is to use XMLHttpRequest\n const xhr = new XMLHttpRequest();\n xhr.open(\"GET\", this.loaderMetadata.syncScriptUrl, false);\n xhr.send();\n // eval(xhr.responseText);\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.innerHTML = xhr.responseText;\n document.head.appendChild(script);\n }\n\n if (this.loaderMetadata.asyncScriptUrl) {\n const asyncScript = document.createElement(\"script\");\n asyncScript.type = \"text/javascript\";\n asyncScript.src = this.loaderMetadata.asyncScriptUrl;\n asyncScript.async = true;\n document.head.appendChild(asyncScript);\n }\n };\n\n fetchUpdateLoaderMetadata = async (\n installedSDKVersion = this.currentVersion,\n localSDKVersion = this.loaderMetadata.version,\n env = window.JOLIBOX_ENV ?? \"WEB\"\n ) => {\n const path = `${\n window.joliboxenv?.apiBaseURL ?? \"https://api.jolibox.com\"\n }/frontend/js-sdk/loader-metadata`;\n try {\n const response = await fetch(path, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n installedSDKVersion,\n localSDKVersion,\n env,\n }),\n });\n const data: IRemoteVersionMetadata = await response.json();\n if (data.code !== \"SUCCESS\") {\n throw new Error(data.message);\n } else {\n this.loaderMetadata = data.data ?? this.defaultMetadata;\n localStorage.setItem(\n joliboxLoaderKey,\n JSON.stringify(this.loaderMetadata)\n );\n // reload happens next time the page is loaded\n }\n } catch (error) {\n console.warn(\"Failed to fetch loader metadata: \", error);\n }\n };\n}\n\nwindow.JoliboxSDKLoader = JoliboxSDKLoader;\n","declare global {\n interface Window {\n JoliboxAds: typeof JoliboxAds;\n }\n}\n\nexport interface IAdsInitParams {\n /**\n * (OPTIONAL) Game ID provided by Jolibox\n */\n gameId?: string;\n}\n\nexport interface IAdConfigParams {\n /**\n * (OPTIONAL) Whether ads should always be preloaded before the first call to adBreak()\n *\n * The default value of auto leaves the decision up to the Ad Placement API. preloadAdBreaks can be set only once with adConfig(), and further values passed to preloadAdBreaks have no effect.\n *\n * Setting preloadAdBreaks after the first call to adBreak() has no effect.\n */\n preloadAdBreaks?: \"on\" | \"auto\"; // default: 'auto'\n\n /**\n * (OPTIONAL) Whether the game is currently playing sound.\n *\n * This call specifies whether your game is capable of sound, and whether the sound was enabled (ie unmuted) before the call to adBreak(). This helps the Ad Placement API to select the right kind of ad for your game.\n *\n * Call this function as soon as the sound state of your game changes, as the Ad Placement API may have to request new creatives, and this gives it the maximum amount of time to do so.\n *\n * The default value is sound on. So most games will need to make a call to adConfig() when they start to declare that they have sound enabled.\n */\n sound?: \"on\" | \"off\"; // default: 'on'\n\n /**\n * (OPTIONAL) Called when the API has initialized and has finished preloading ads (if you requested preloading using the preloadAdBreaks above).\n * @returns\n */\n onReady?: () => void;\n}\n\n/**\n * PlacementInfo object passed by **adBreakDone** function\n */\nexport interface IPlacementInfo {\n /**\n * the type argument passed to adBreak()\n */\n breakType: string;\n /**\n * the name argument passed to adBreak()\n */\n breakName: string;\n breakFormat: \"interstitial\" | \"reward\";\n /**\n * the status of this placement and can be one of the following values:\n *\n * | breakStatus | Reason |\n * | -------- | ------- |\n * | 'notReady'\t| The Ad Placement API had not initialised |\n * | 'timeout' | A placement timed out because the Ad Placement API took too long to respond |\n * | 'invalid' | The placement was invalid and was ignored–for instance there should only be one preroll placement per page load, subsequent prerolls are failed with this status |\n * | 'error' | There was a JavaScript error in a callback |\n * | 'noAdPreloaded' |\tAn ad had not been preloaded yet so this placement was skipped |\n * | 'frequencyCapped' |\tAn ad wasn't shown because the frequency cap was applied to this placement |\n * | 'ignored' |\tThe user didn't click on a reward prompt before they reached the next placement, that is showAdFn() wasn't called before the next adBreak(). |\n * | 'other' |\tThe ad was not shown for another reason. (e.g., The ad was still being fetched, or a previously cached ad was disposed because the screen was resized/rotated.) |\n * | 'dismissed' |\tThe user dismissed a rewarded ad before viewing it to completion |\n * | 'viewed' |\tThe ad was viewed by the user |\n */\n breakStatus:\n | \"notReady\"\n | \"timeout\"\n | \"error\"\n | \"noAdPreloaded\"\n | \"frequencyCapped\"\n | \"ignored\"\n | \"other\"\n | \"dismissed\"\n | \"viewed\";\n}\n\n/**\n * Parameter when calling adBreak\n */\nexport type IAdBreakParams =\n | IPrerollParams\n | IInterstitialsParams\n | IRewardParams;\n\n/**\n * Parameter when calling preroll type adBreak\n */\nexport interface IPrerollParams {\n /**\n * 'preroll' before the game loads (before UI has rendered)\n */\n type: \"preroll\";\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n}\n\nexport interface IInterstitialsParams {\n /**\n * 'start' before the gameplay starts (after UI has rendered)\n * 'pause' the player pauses the game\n * 'next' player navigates to the next level\n * 'browse' the player explores options outside of the gameplay\n */\n type: \"start\" | \"pause\" | \"next\" | \"browse\";\n\n /**\n * (OPTIONAL) a name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. In future releases this identifier may be used to enable additional reporting and optimization features.\n *\n * We recommend you name all of your placements.\n */\n name?: string;\n\n /**\n * (OPTIONAL) Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes.\n *\n * @returns\n */\n beforeAd?: () => void;\n\n /**\n * (OPTIONAL) Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actions. This function should be used to resume game flow. For example, use to unmute the sound and start the next level.\n * @returns\n */\n afterAd?: () => void;\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object\n *\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n}\n\nexport interface IRewardParams {\n /**\n * 'reward' a rewarded ad\n */\n type: \"reward\";\n\n /**\n * (OPTIONAL) a name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. In future releases this identifier may be used to enable additional reporting and optimization features.\n *\n * We recommend you name all of your placements.\n */\n name?: string;\n\n /**\n * (OPTIONAL) Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes.\n * @returns\n */\n beforeAd?: () => void;\n\n /**\n * (OPTIONAL) Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actions. This function should be used to resume game flow. For example, use to unmute the sound and start the next level.\n * @returns\n */\n afterAd?: () => void;\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object defined\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n\n /**\n * Called if a rewarded ad is available. The function should take a single argument–showAdFn() which must be called to display the rewarded ad.\n * @param showAdFn\n * @returns\n */\n beforeReward: (showAdFn: () => void) => void;\n\n /**\n * Called only for rewarded ads when the player dismisses the ad. It is only called if the player dismisses the ad before it completes. In this case the reward should not be granted.\n * @returns\n */\n adDismissed: () => void;\n\n /**\n * Called only for rewarded ads when the player completes the ad and should be granted the reward.\n * @returns\n */\n adViewed: () => void;\n}\n\n/**\n * Ad unit format, can be 'rectangle', 'vertical', 'horizontal'\n */\nexport type AdUnitFormat = \"rectangle\" | \"vertical\" | \"horizontal\";\n\nexport interface IAdUnitParams {\n /**\n * The element to attach the ad unit to, either an HTMLElement or a string selector. Should be the parent element of the ad unit (<ins> tag).\n */\n el: HTMLElement | string;\n\n /**\n * (OPTIONAL) Reserved for future usage. The slot ID of the ad unit. Currently the slot ID is automatically set by the SDK.\n */\n slot?: string;\n\n // /**\n // * (OPTIONAL) The position of the ad unit. Can be 'TOP', 'BOTTOM', 'LEFT', 'RIGHT', 'CENTER'. Default is 'TOP'. Either position or slot should be set.\n // */\n // position?: AdUnitPosition;\n\n // /**\n // * (OPTIONAL) Channel ID for the ad unit. We will set the Channel ID automatically if not provided. Default is empty.\n // */\n // channelId?: string;\n\n /**\n * (OPTIONAL) Ad format for the ad unit. Can be 'auto' or a single format or an array of formats. Default is 'auto'. If passed as an array, the array will be joined by ', ' and pass to the data-ad-format attribute.\n */\n adFormat?: \"auto\" | AdUnitFormat | AdUnitFormat[];\n\n /**\n * (OPTIONAL) Whether the ad unit should be full width and responsive. Default is false.\n */\n fullWidthResponsive?: \"true\" | \"false\";\n\n /**\n * (OPTIONAL) Custom style for the ad unit. Default is empty.\n */\n style?: string;\n}\n\n/**\n * Jolibox Ads SDK\n */\nexport class JoliboxAds {\n /**\n * Internal constructor, should not be called directly\n */\n constructor() {}\n\n /**\n * Init JoliboxAds. Must be called before any other ads functions.\n * @param config\n * @returns\n */\n public init = (config?: IAdsInitParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.init\",\n params: config,\n });\n };\n\n /**\n * The adConfig() call communicates the game's current configuration to the Ad Placement API. The Ad Placement API can use this to tune the way it preloads ads and to filter the kinds of ads it requests so they're suitable (eg. video ads that require sound).\n * @param params\n */\n public adConfig = (params: IAdConfigParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adConfig\",\n params,\n });\n };\n\n /**\n * adBreak() is the key function for placing ads within your game. It defines an ad placement and takes an object called a placement config that specifies everything required to show an ad.\n *\n * The adBreak() function defines a placement where an ad could be shown. Whether an ad actually shows depends on factors such as the following:\n *\n * - The type of ad placement that you declared\n * - Is this ad at the start of the game? Between levels? At a moment when the player has paused the game?\n * - Whether a suitable ad exists for the current player\n * - Is this ad relevant to them?\n * - Is it consistent with their data privacy and consent settings?\n * - The number of ads the player has seen recently\n * - The control settings—for example, ad frequency, you've configured for this game\n * - Either as hints in the tag, or,\n * - Within AdSense—note that the controls available in AdSense will evolve over time.\n *\n * The kind of ad that shows also depends on similar factors.\n *\n * Note that a call to adBreak() might not show an ad at all. It simply declares a place where an ad could be shown.\n *\n * This is unlike traditional APIs in which your code always knows if an ad is available, and you decide within the game whether to show it. This approach of letting the Ad Placement API decide if an ad shows in a particular placement is a pattern that is sometimes referred to as \"inversion of control\".\n *\n * The reason we're transitioning our games API to this model is firstly, it shortens the code you have to write within your game. Secondly, it makes it easier to deliver policy compliant placements with a great user experience, which in turn has allowed us to deliver some of our highest performing formats to games publishers. Lastly, it more cleanly separates the process of placing ads in your game from the monetization decisions about the type and number of ads to show.\n *\n * We want you to be able to change your monetization settings and control the user experience without having to edit and release a new version of your game, initially by specifying hints in the tag. But in future releases, we will be able to provide controls directly in the AdSense and AdMob frontends.\n * @param params\n */\n public adBreak = (params: IAdBreakParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adBreak\",\n params,\n });\n };\n\n /**\n * adUnit() is a function that creates an ad unit and attaches it to a parent element. The ad unit is a single ad placement that can be used to show ads.\n *\n * Currently we only provide support for creating ad units as `<ins>` tags with the class 'adsbygoogle'. This is the standard way to create ad units with Google AdSense.\n *\n * After calling this method, the ad unit is attached to the parent element you specify as el in the params object.\n *\n * By default, the client ID and channel ID are automatically set by the SDK. And the slot name is set to the position of the ad unit. You can override these values by passing the slot and channelId in the params object.\n *\n * @param params\n * @returns\n */\n public adUnit = async (params: IAdUnitParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adUnit\",\n params,\n });\n };\n}\n\nwindow.JoliboxAds = JoliboxAds;\n\nexport default JoliboxAds;\n","declare global {\n interface Window {\n JoliboxAnalytics: typeof JoliboxAnalytics;\n }\n}\n\n/**\n * Jolibox Analytics SDK\n */\nexport class JoliboxAnalytics {\n constructor() {}\n\n /**\n * Track an event, will be sent to the analytics server\n *\n * @param eventName event name, must be a string\n * @param extra (OPTIONAL) extra data, must be an object or null or undefined, must not have nested objects\n */\n public trackEvent = (\n eventName: string,\n extra?: Record<string, string | boolean | number | null> | null\n ) => {\n // assert eventName is a string\n if (typeof eventName !== \"string\") {\n throw new Error(\"eventName must be a string\");\n }\n\n // assert extra is an object or null or undefined\n if (extra !== null && typeof extra !== \"object\" && extra !== undefined) {\n throw new Error(\"extra must be an object or null or undefined\");\n }\n\n // assert extra has no nested objects\n if (extra) {\n for (const key in extra) {\n if (typeof extra[key] === \"object\") {\n throw new Error(\"extra must not have nested objects\");\n }\n }\n }\n\n window.joliboxsdk._commandPipe.push({\n cmd: \"analytics.trackEvent\",\n params: [eventName, extra],\n });\n };\n}\n\nwindow.JoliboxAnalytics = JoliboxAnalytics;\n\nexport default JoliboxAnalytics;\n","interface ICommandPipe {\n cmd: string;\n params: any;\n}\n\ndeclare global {\n interface IJoliboxSDK {\n _commandPipe: ICommandPipe[];\n }\n interface Window {\n joliboxsdk: IJoliboxSDK;\n JoliboxRuntime: typeof JoliboxRuntime;\n JoliboxRuntimeEvents: typeof JoliboxRuntimeEvents;\n }\n}\n\nexport enum JoliboxRuntimeEvents {\n /**\n * Event dispatched when the loading starts\n */\n LOAD_START = \"JOLIBOX_RUNTIME_LOAD_START\",\n\n /**\n * Event dispatched when the loading is finished\n */\n LOAD_FINISHED = \"JOLIBOX_RUNTIME_LOAD_FINISHED\",\n\n /**\n * Event dispatched when the loading progress is updated\n */\n LOAD_PROGRESS = \"JOLIBOX_RUNTIME_LOAD_PROGRESS\",\n}\n\nwindow.dispatchEvent(new Event(JoliboxRuntimeEvents.LOAD_START));\n\n/**\n * Jolibox Runtime, a set of utilities to interact with the Jolibox runtime\n * @class\n */\nexport class JoliboxRuntime {\n /**\n * Notify the end of the loading, will close the loading splash screen\n */\n loadFinished = () => {\n const loadFinishedEvent = new Event(JoliboxRuntimeEvents.LOAD_FINISHED);\n window.dispatchEvent(loadFinishedEvent);\n window.joliboxsdk._commandPipe.push({\n cmd: \"analytics.trackSystemEvent\",\n params: [\"CallRuntimeLoadFinished\"],\n });\n };\n\n /**\n * Notify the progress of the loading, will update the loading splash screen\n * @param progress - The progress of the loading, should be an integer between 0 and 100\n */\n notifyLoadProgress = (progress: number) => {\n const detail = Math.ceil(progress);\n const event = new CustomEvent(JoliboxRuntimeEvents.LOAD_PROGRESS, {\n detail,\n });\n window.dispatchEvent(event);\n };\n}\n\nwindow.JoliboxRuntime = JoliboxRuntime;\n\nexport default JoliboxRuntime;\n","import \"./loader\";\nimport \"./ads\";\nimport \"./analytics\";\nimport \"@jolibox/web-sync-sdk\";\nimport type { JoliboxSDKLoader, IJoliboxSDKLoaderConfig } from \"./loader\";\nimport type { JoliboxAds } from \"./ads\";\nimport type { JoliboxAnalytics } from \"./analytics\";\nimport type { JoliboxRuntime } from \"./runtime\";\n\ndeclare global {\n interface IJoliboxSDK extends JoliboxSDK {\n _commandPipe: ICommandPipe[];\n }\n interface Window {\n __JOLIBOX_LOCAL_SDK_VERSION__: string;\n joliboxenv?: {\n testMode: boolean;\n apiBaseURL: string;\n };\n joliboxsdk: IJoliboxSDK;\n JoliboxSDK: typeof JoliboxSDK;\n }\n interface ImportMeta {\n env: {\n JOLIBOX_SDK_VERSION: string;\n };\n }\n}\n\nwindow.__JOLIBOX_LOCAL_SDK_VERSION__ = import.meta.env.JOLIBOX_SDK_VERSION;\n\nexport interface IJoliboxConfig {\n useRuntimeSDK?: boolean;\n loaderConfig?: IJoliboxSDKLoaderConfig;\n testMode?: boolean;\n apiBaseURL?: string;\n}\n\ninterface ICommandPipe {\n cmd: string;\n params: any;\n}\n\nclass JoliboxSDK {\n private loader: JoliboxSDKLoader;\n ads: JoliboxAds;\n anaytics: JoliboxAnalytics;\n runtime: JoliboxRuntime;\n\n setJoliboxEnv = (inputTestMode?: boolean, inputApiBaseURL?: string) => {\n const isBrowser = typeof window !== \"undefined\";\n const urlSearchParams = isBrowser\n ? new URLSearchParams(window.location.search)\n : null;\n const testModeParam = urlSearchParams?.get(\"testMode\") === \"true\";\n const testMode = inputTestMode ?? testModeParam;\n\n const apiBaseURLParam = urlSearchParams?.get(\"apiBaseURL\");\n let apiBaseURL;\n if (inputApiBaseURL) {\n apiBaseURL = inputApiBaseURL;\n } else if (apiBaseURLParam) {\n apiBaseURL = apiBaseURLParam;\n } else {\n apiBaseURL = testMode\n ? \"https://test-api.jolibox.com\"\n : \"https://api.jolibox.com\";\n }\n window.joliboxenv = {\n testMode,\n apiBaseURL,\n };\n };\n\n constructor({\n useRuntimeSDK = true,\n loaderConfig,\n testMode,\n apiBaseURL,\n }: IJoliboxConfig = {}) {\n this.setJoliboxEnv(testMode, apiBaseURL);\n if (useRuntimeSDK && window.joliboxsdk) {\n this.loader =\n window.joliboxsdk.loader ?? new window.JoliboxSDKLoader(loaderConfig);\n this.ads = window.joliboxsdk.ads ?? new window.JoliboxAds();\n this.anaytics =\n window.joliboxsdk.anaytics ?? new window.JoliboxAnalytics();\n this.runtime = window.joliboxsdk.runtime ?? new window.JoliboxRuntime();\n } else {\n if (!window.joliboxsdk) {\n window.joliboxsdk = {\n _commandPipe: [], // This is to avoid the error \"Cannot read property 'push' of undefined\" if any command is called before the SDK is initialized\n } as any;\n }\n\n this.loader = new window.JoliboxSDKLoader(loaderConfig);\n this.ads = new window.JoliboxAds();\n this.anaytics = new window.JoliboxAnalytics();\n this.runtime = new window.JoliboxRuntime();\n window.joliboxsdk = Object.assign(this, window.joliboxsdk);\n }\n if (!window.joliboxsdk._commandPipe) {\n window.joliboxsdk._commandPipe = [];\n }\n }\n}\n\nif (!window.JoliboxSDK) {\n window.JoliboxSDK = JoliboxSDK;\n}\n\nexport default JoliboxSDK;\nexport { JoliboxSDK };\n"],"mappings":"gOAAA,IAAMA,EACJC,GAOG,CARL,IAAAC,EAAAC,EAAAC,EASE,IAAMC,EAAaJ,EAAQ,MAAM,GAAG,EAAE,CAAC,EACnCI,IACFJ,EAAUA,EAAQ,QAAQ,IAAII,CAAU,GAAI,EAAE,GAGhD,IAAMC,EAAQL,EAAQ,MAAM,GAAG,EAAE,CAAC,EAC9BK,IACFL,EAAUA,EAAQ,QAAQ,IAAIK,CAAK,GAAI,EAAE,GAG3C,IAAMC,EAAWN,EAAQ,MAAM,GAAG,EAAE,MAAM,EAAG,CAAC,EACxC,CAACO,EAAOC,EAAOC,CAAK,EAAI,EAC5BR,EAAAK,EAAS,CAAC,IAAV,KAAAL,EAAe,KACfC,EAAAI,EAAS,CAAC,IAAV,KAAAJ,EAAe,KACfC,EAAAG,EAAS,CAAC,IAAV,KAAAH,EAAe,GACjB,EACA,MAAO,CAAE,MAAAI,EAAO,MAAAC,EAAO,MAAA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AAAA,EAA8B,IAAI,OAAO,iBAC3C,KAAK,SAAUC,EAAA,OAAO,WAAW,UAAlB,KAAAA,EAA6B,IAAI,OAAO,iBAElD,OAAO,aACV,OAAO,WAAa,CAClB,aAAc,CAAC,CACjB,GAGF,KAAK,OAAS,IAAI,OAAO,iBAAiBX,CAAY,EACtD,KAAK,IAAM,IAAI,OAAO,WACtB,KAAK,SAAW,IAAI,OAAO,iBAC3B,KAAK,QAAU,IAAI,OAAO,eAC1B,OAAO,WAAa,OAAO,OAAO,KAAM,OAAO,UAAU,GAEtD,OAAO,WAAW,eACrB,OAAO,WAAW,aAAe,CAAC,EAEtC,CACF,EAEK,OAAO,aACV,OAAO,WAAaF,GAGtB,IAAOc,EAAQd","names":["splitSemver","version","_a","_b","_c","prerelease","build","splitted","major","minor","patch","compare","v1","v2","major1","minor1","patch1","major2","minor2","patch2","joliboxLoaderKey","JoliboxSDKLoader","loaderMetadata","_a","_b","version","error","versionFromLocalStorage","major","compare","xhr","script","asyncScript","_0","__async","installedSDKVersion","localSDKVersion","env","_c","path","data","majorVersion","JoliboxAds","config","params","__async","JoliboxAnalytics","eventName","extra","key","JoliboxRuntimeEvents","JoliboxRuntime","loadFinishedEvent","progress","detail","event","JoliboxSDK","useRuntimeSDK","loaderConfig","testMode","apiBaseURL","inputTestMode","inputApiBaseURL","urlSearchParams","testModeParam","apiBaseURLParam","_a","_b","_c","_d","src_default"]}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var c=(r,o,e)=>new Promise((a,t)=>{var d=i=>{try{n(e.next(i))}catch(l){t(l)}},s=i=>{try{n(e.throw(i))}catch(l){t(l)}},n=i=>i.done?a(i.value):Promise.resolve(i.value).then(d,s);n((e=e.apply(r,o)).next())});var f=r=>{var n,i,l;let o=r.split("-")[1];o&&(r=r.replace(`-${o}`,""));let e=r.split("+")[1];e&&(r=r.replace(`+${e}`,""));let a=r.split(".").slice(0,3),[t,d,s]=[(n=a[0])!=null?n:"0",(i=a[1])!=null?i:"0",(l=a[2])!=null?l:"0"];return{major:t,minor:d,patch:s,prerelease:o,build:e}},p=r=>parseInt(f(r).major,10),g=(r,o)=>{let{major:e,minor:a,patch:t}=f(r),{major:d,minor:s,patch:n}=f(o);return e!==d?e>d?1:-1:a!==s?a>s?1:-1:t!==n?t>n?1:-1:0};var h="jolibox-sdk-loader-metadata",b=class{constructor({loaderMetadata:o}={}){this.computeLoaderMetaData=()=>{var t,d;let o=this.currentVersion,e=null;try{if(e=JSON.parse((t=localStorage.getItem(h))!=null?t:"null"),!e||!e.version)throw new Error("Invalid loader metadata")}catch(s){e=this.defaultMetadata}let a=(d=e==null?void 0:e.version)!=null?d:o;return p(a)!==p(o)?e=this.defaultMetadata:g(a,o)<0&&(e=this.defaultMetadata),e};this.loadScript=()=>{if(this.loaderMetadata.syncScriptUrl){let o=new XMLHttpRequest;o.open("GET",this.loaderMetadata.syncScriptUrl,!1),o.send();let e=document.createElement("script");e.type="text/javascript",e.innerHTML=o.responseText,document.head.appendChild(e)}if(this.loaderMetadata.asyncScriptUrl){let o=document.createElement("script");o.type="text/javascript",o.src=this.loaderMetadata.asyncScriptUrl,o.async=!0,document.head.appendChild(o)}};this.fetchUpdateLoaderMetadata=(...d)=>c(this,[...d],function*(o=this.currentVersion,e=this.loaderMetadata.version,a=(t=>(t=window.JOLIBOX_ENV)!=null?t:"WEB")()){var n,i,l;let s=`${(i=(n=window.joliboxenv)==null?void 0:n.apiBaseURL)!=null?i:"https://api.jolibox.com"}/frontend/js-sdk/loader-metadata`;try{let w=yield(yield fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({installedSDKVersion:o,localSDKVersion:e,env:a})})).json();if(w.code!=="SUCCESS")throw new Error(w.message);this.loaderMetadata=(l=w.data)!=null?l:this.defaultMetadata,localStorage.setItem(h,JSON.stringify(this.loaderMetadata))}catch(I){console.warn("Failed to fetch loader metadata: ",I)}});console.log("Loading Jolibox SDK..."),this.loaderMetadata=o!=null?o:this.computeLoaderMetaData(),this.loadScript(),this.fetchUpdateLoaderMetadata(),console.log("Jolibox SDK loaded.")}get currentVersion(){return window.__JOLIBOX_LOCAL_SDK_VERSION__}get defaultMetadata(){let o=this.currentVersion,e=p(o);return{version:o,syncScriptUrl:`https://cdn.jsdelivr.net/npm/@jolibox/web-sync-sdk@${e}/dist/index.iife.js`,asyncScriptUrl:`https://cdn.jsdelivr.net/npm/@jolibox/web-async-sdk@${e}/dist/index.iife.js`}}};window.JoliboxSDKLoader=b;var x=class{constructor(){this.init=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.init",params:o})};this.adConfig=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.adConfig",params:o})};this.adBreak=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.adBreak",params:o})};this.adUnit=o=>c(this,null,function*(){window.joliboxsdk._commandPipe.push({cmd:"ads.adUnit",params:o})})}};window.JoliboxAds=x;var u=class{constructor(){this.trackEvent=(o,e)=>{if(typeof o!="string")throw new Error("eventName must be a string");if(e!==null&&typeof e!="object"&&e!==void 0)throw new Error("extra must be an object or null or undefined");if(e){for(let a in e)if(typeof e[a]=="object")throw new Error("extra must not have nested objects")}window.joliboxsdk._commandPipe.push({cmd:"analytics.trackEvent",params:[o,e]})}}};window.JoliboxAnalytics=u;import"@jolibox/web-sync-sdk";window.__JOLIBOX_LOCAL_SDK_VERSION__="1.0.6";var m=class{constructor({useRuntimeSDK:o=!0,loaderConfig:e,testMode:a,apiBaseURL:t}={}){this.setJoliboxEnv=(o,e)=>{let t=typeof window<"u"?new URLSearchParams(window.location.search):null,d=(t==null?void 0:t.get("testMode"))==="true",s=o!=null?o:d,n=t==null?void 0:t.get("apiBaseURL"),i;e?i=e:n?i=n:i=s?"https://test-api.jolibox.com":"https://api.jolibox.com",window.joliboxenv={testMode:s,apiBaseURL:i}};var d,s,n,i;this.setJoliboxEnv(a,t),o&&window.joliboxsdk?(this.loader=(d=window.joliboxsdk.loader)!=null?d:new window.JoliboxSDKLoader(e),this.ads=(s=window.joliboxsdk.ads)!=null?s:new window.JoliboxAds,this.anaytics=(n=window.joliboxsdk.anaytics)!=null?n:new window.JoliboxAnalytics,this.runtime=(i=window.joliboxsdk.runtime)!=null?i:new window.JoliboxRuntime):(window.joliboxsdk||(window.joliboxsdk={_commandPipe:[]}),this.loader=new window.JoliboxSDKLoader(e),this.ads=new window.JoliboxAds,this.anaytics=new window.JoliboxAnalytics,this.runtime=new window.JoliboxRuntime,window.joliboxsdk=Object.assign(this,window.joliboxsdk)),window.joliboxsdk._commandPipe||(window.joliboxsdk._commandPipe=[])}};window.JoliboxSDK||(window.JoliboxSDK=m);var M=m;export{m as JoliboxSDK,M as default};
1
+ var c=(r,o,e)=>new Promise((a,t)=>{var d=i=>{try{n(e.next(i))}catch(l){t(l)}},s=i=>{try{n(e.throw(i))}catch(l){t(l)}},n=i=>i.done?a(i.value):Promise.resolve(i.value).then(d,s);n((e=e.apply(r,o)).next())});var f=r=>{var n,i,l;let o=r.split("-")[1];o&&(r=r.replace(`-${o}`,""));let e=r.split("+")[1];e&&(r=r.replace(`+${e}`,""));let a=r.split(".").slice(0,3),[t,d,s]=[(n=a[0])!=null?n:"0",(i=a[1])!=null?i:"0",(l=a[2])!=null?l:"0"];return{major:t,minor:d,patch:s,prerelease:o,build:e}},p=r=>parseInt(f(r).major,10),g=(r,o)=>{let{major:e,minor:a,patch:t}=f(r),{major:d,minor:s,patch:n}=f(o);return e!==d?e>d?1:-1:a!==s?a>s?1:-1:t!==n?t>n?1:-1:0};var h="jolibox-sdk-loader-metadata",b=class{constructor({loaderMetadata:o}={}){this.computeLoaderMetaData=()=>{var t,d;let o=this.currentVersion,e=null;try{if(e=JSON.parse((t=localStorage.getItem(h))!=null?t:"null"),!e||!e.version)throw new Error("Invalid loader metadata")}catch(s){e=this.defaultMetadata}let a=(d=e==null?void 0:e.version)!=null?d:o;return p(a)!==p(o)?e=this.defaultMetadata:g(a,o)<0&&(e=this.defaultMetadata),e};this.loadScript=()=>{if(this.loaderMetadata.syncScriptUrl){let o=new XMLHttpRequest;o.open("GET",this.loaderMetadata.syncScriptUrl,!1),o.send();let e=document.createElement("script");e.type="text/javascript",e.innerHTML=o.responseText,document.head.appendChild(e)}if(this.loaderMetadata.asyncScriptUrl){let o=document.createElement("script");o.type="text/javascript",o.src=this.loaderMetadata.asyncScriptUrl,o.async=!0,document.head.appendChild(o)}};this.fetchUpdateLoaderMetadata=(...d)=>c(this,[...d],function*(o=this.currentVersion,e=this.loaderMetadata.version,a=(t=>(t=window.JOLIBOX_ENV)!=null?t:"WEB")()){var n,i,l;let s=`${(i=(n=window.joliboxenv)==null?void 0:n.apiBaseURL)!=null?i:"https://api.jolibox.com"}/frontend/js-sdk/loader-metadata`;try{let w=yield(yield fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({installedSDKVersion:o,localSDKVersion:e,env:a})})).json();if(w.code!=="SUCCESS")throw new Error(w.message);this.loaderMetadata=(l=w.data)!=null?l:this.defaultMetadata,localStorage.setItem(h,JSON.stringify(this.loaderMetadata))}catch(I){console.warn("Failed to fetch loader metadata: ",I)}});console.log("Loading Jolibox SDK..."),this.loaderMetadata=o!=null?o:this.computeLoaderMetaData(),this.loadScript(),this.fetchUpdateLoaderMetadata(),console.log("Jolibox SDK loaded.")}get currentVersion(){return window.__JOLIBOX_LOCAL_SDK_VERSION__}get defaultMetadata(){let o=this.currentVersion,e=p(o);return{version:o,syncScriptUrl:`https://cdn.jsdelivr.net/npm/@jolibox/web-sync-sdk@${e}/dist/index.iife.js`,asyncScriptUrl:`https://cdn.jsdelivr.net/npm/@jolibox/web-async-sdk@${e}/dist/index.iife.js`}}};window.JoliboxSDKLoader=b;var x=class{constructor(){this.init=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.init",params:o})};this.adConfig=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.adConfig",params:o})};this.adBreak=o=>{window.joliboxsdk._commandPipe.push({cmd:"ads.adBreak",params:o})};this.adUnit=o=>c(this,null,function*(){window.joliboxsdk._commandPipe.push({cmd:"ads.adUnit",params:o})})}};window.JoliboxAds=x;var u=class{constructor(){this.trackEvent=(o,e)=>{if(typeof o!="string")throw new Error("eventName must be a string");if(e!==null&&typeof e!="object"&&e!==void 0)throw new Error("extra must be an object or null or undefined");if(e){for(let a in e)if(typeof e[a]=="object")throw new Error("extra must not have nested objects")}window.joliboxsdk._commandPipe.push({cmd:"analytics.trackEvent",params:[o,e]})}}};window.JoliboxAnalytics=u;import"@jolibox/web-sync-sdk";window.__JOLIBOX_LOCAL_SDK_VERSION__="1.0.7-beta.1";var m=class{constructor({useRuntimeSDK:o=!0,loaderConfig:e,testMode:a,apiBaseURL:t}={}){this.setJoliboxEnv=(o,e)=>{let t=typeof window<"u"?new URLSearchParams(window.location.search):null,d=(t==null?void 0:t.get("testMode"))==="true",s=o!=null?o:d,n=t==null?void 0:t.get("apiBaseURL"),i;e?i=e:n?i=n:i=s?"https://test-api.jolibox.com":"https://api.jolibox.com",window.joliboxenv={testMode:s,apiBaseURL:i}};var d,s,n,i;this.setJoliboxEnv(a,t),o&&window.joliboxsdk?(this.loader=(d=window.joliboxsdk.loader)!=null?d:new window.JoliboxSDKLoader(e),this.ads=(s=window.joliboxsdk.ads)!=null?s:new window.JoliboxAds,this.anaytics=(n=window.joliboxsdk.anaytics)!=null?n:new window.JoliboxAnalytics,this.runtime=(i=window.joliboxsdk.runtime)!=null?i:new window.JoliboxRuntime):(window.joliboxsdk||(window.joliboxsdk={_commandPipe:[]}),this.loader=new window.JoliboxSDKLoader(e),this.ads=new window.JoliboxAds,this.anaytics=new window.JoliboxAnalytics,this.runtime=new window.JoliboxRuntime,window.joliboxsdk=Object.assign(this,window.joliboxsdk)),window.joliboxsdk._commandPipe||(window.joliboxsdk._commandPipe=[])}};window.JoliboxSDK||(window.JoliboxSDK=m);var M=m;export{m as JoliboxSDK,M as default};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/loader/utils.ts","../src/loader/index.ts","../src/ads/index.ts","../src/analytics/index.ts","../src/index.ts"],"sourcesContent":["const splitSemver = (\n version: string\n): {\n major: string;\n minor: string;\n patch: string;\n prerelease?: string;\n build?: string;\n} => {\n const prerelease = version.split(\"-\")[1] as string | undefined;\n if (prerelease) {\n version = version.replace(`-${prerelease}`, \"\");\n }\n\n const build = version.split(\"+\")[1] as string | undefined;\n if (build) {\n version = version.replace(`+${build}`, \"\");\n }\n\n const splitted = version.split(\".\").slice(0, 3);\n const [major, minor, patch] = [\n splitted[0] ?? \"0\",\n splitted[1] ?? \"0\",\n splitted[2] ?? \"0\",\n ];\n return { major, minor, patch, prerelease, build };\n};\n\nexport const major = (version: string): number =>\n parseInt(splitSemver(version).major, 10);\n\nexport const compare = (v1: string, v2: string): -1 | 0 | 1 => {\n const { major: major1, minor: minor1, patch: patch1 } = splitSemver(v1);\n const { major: major2, minor: minor2, patch: patch2 } = splitSemver(v2);\n\n if (major1 !== major2) {\n return major1 > major2 ? 1 : -1;\n }\n\n if (minor1 !== minor2) {\n return minor1 > minor2 ? 1 : -1;\n }\n\n if (patch1 !== patch2) {\n return patch1 > patch2 ? 1 : -1;\n }\n\n return 0;\n};\n","import { major, compare } from \"./utils\";\n\ndeclare global {\n interface Window {\n JOLIBOX_ENV: \"WEB\" | \"IOS\" | \"ANDROID\" | \"WINDOWS\" | \"MACOS\" | \"LINUX\";\n JoliboxSDKLoader: typeof JoliboxSDKLoader;\n }\n}\n\nconst joliboxLoaderKey = \"jolibox-sdk-loader-metadata\";\n\nexport interface IVersionMetadata {\n version: string;\n syncScriptUrl?: string; // By default, the sync script is bundled with the sdk\n asyncScriptUrl?: string;\n}\n\nexport interface IRemoteVersionMetadata {\n code: \"SUCCESS\" | string;\n message?: string;\n data?: IVersionMetadata;\n}\n\nexport interface IJoliboxSDKLoaderConfig {\n loaderMetadata?: IVersionMetadata;\n}\n\nexport class JoliboxSDKLoader {\n loaderMetadata: IVersionMetadata;\n\n constructor({ loaderMetadata }: IJoliboxSDKLoaderConfig = {}) {\n console.log(\"Loading Jolibox SDK...\");\n\n this.loaderMetadata = loaderMetadata ?? this.computeLoaderMetaData();\n this.loadScript();\n this.fetchUpdateLoaderMetadata();\n console.log(\"Jolibox SDK loaded.\");\n }\n\n private get currentVersion() {\n return window.__JOLIBOX_LOCAL_SDK_VERSION__;\n }\n\n private get defaultMetadata(): IVersionMetadata {\n const version = this.currentVersion;\n const majorVersion = major(version);\n return {\n version,\n syncScriptUrl: `https://cdn.jsdelivr.net/npm/@jolibox/web-sync-sdk@${majorVersion}/dist/index.iife.js`,\n asyncScriptUrl: `https://cdn.jsdelivr.net/npm/@jolibox/web-async-sdk@${majorVersion}/dist/index.iife.js`,\n };\n }\n\n computeLoaderMetaData = () => {\n const version = this.currentVersion;\n let loaderMetadata: IVersionMetadata | null = null;\n try {\n loaderMetadata = JSON.parse(\n localStorage.getItem(joliboxLoaderKey) ?? \"null\"\n ) as IVersionMetadata | null;\n if (!loaderMetadata || !loaderMetadata.version) {\n throw new Error(\"Invalid loader metadata\");\n }\n } catch (error) {\n loaderMetadata = this.defaultMetadata;\n }\n\n const versionFromLocalStorage = loaderMetadata?.version ?? version;\n\n if (major(versionFromLocalStorage) !== major(version)) {\n // if major version is different, must follow the version from package.json\n loaderMetadata = this.defaultMetadata;\n } else {\n // if major version is the same, follow the larger version\n if (compare(versionFromLocalStorage, version) < 0) {\n loaderMetadata = this.defaultMetadata;\n }\n }\n\n return loaderMetadata;\n };\n\n loadScript = () => {\n if (this.loaderMetadata.syncScriptUrl) {\n // The only way to load a script synchronously is to use XMLHttpRequest\n const xhr = new XMLHttpRequest();\n xhr.open(\"GET\", this.loaderMetadata.syncScriptUrl, false);\n xhr.send();\n // eval(xhr.responseText);\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.innerHTML = xhr.responseText;\n document.head.appendChild(script);\n }\n\n if (this.loaderMetadata.asyncScriptUrl) {\n const asyncScript = document.createElement(\"script\");\n asyncScript.type = \"text/javascript\";\n asyncScript.src = this.loaderMetadata.asyncScriptUrl;\n asyncScript.async = true;\n document.head.appendChild(asyncScript);\n }\n };\n\n fetchUpdateLoaderMetadata = async (\n installedSDKVersion = this.currentVersion,\n localSDKVersion = this.loaderMetadata.version,\n env = window.JOLIBOX_ENV ?? \"WEB\"\n ) => {\n const path = `${\n window.joliboxenv?.apiBaseURL ?? \"https://api.jolibox.com\"\n }/frontend/js-sdk/loader-metadata`;\n try {\n const response = await fetch(path, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n installedSDKVersion,\n localSDKVersion,\n env,\n }),\n });\n const data: IRemoteVersionMetadata = await response.json();\n if (data.code !== \"SUCCESS\") {\n throw new Error(data.message);\n } else {\n this.loaderMetadata = data.data ?? this.defaultMetadata;\n localStorage.setItem(\n joliboxLoaderKey,\n JSON.stringify(this.loaderMetadata)\n );\n // reload happens next time the page is loaded\n }\n } catch (error) {\n console.warn(\"Failed to fetch loader metadata: \", error);\n }\n };\n}\n\nwindow.JoliboxSDKLoader = JoliboxSDKLoader;\n","declare global {\n interface Window {\n JoliboxAds: typeof JoliboxAds;\n }\n}\n\nexport interface IAdsInitParams {\n /**\n * (OPTIONAL) Game ID provided by Jolibox\n */\n gameId?: string;\n}\n\nexport interface IAdConfigParams {\n /**\n * (OPTIONAL) Whether ads should always be preloaded before the first call to adBreak()\n *\n * The default value of auto leaves the decision up to the Ad Placement API. preloadAdBreaks can be set only once with adConfig(), and further values passed to preloadAdBreaks have no effect.\n *\n * Setting preloadAdBreaks after the first call to adBreak() has no effect.\n */\n preloadAdBreaks?: \"on\" | \"auto\"; // default: 'auto'\n\n /**\n * (OPTIONAL) Whether the game is currently playing sound.\n *\n * This call specifies whether your game is capable of sound, and whether the sound was enabled (ie unmuted) before the call to adBreak(). This helps the Ad Placement API to select the right kind of ad for your game.\n *\n * Call this function as soon as the sound state of your game changes, as the Ad Placement API may have to request new creatives, and this gives it the maximum amount of time to do so.\n *\n * The default value is sound on. So most games will need to make a call to adConfig() when they start to declare that they have sound enabled.\n */\n sound?: \"on\" | \"off\"; // default: 'on'\n\n /**\n * (OPTIONAL) Called when the API has initialized and has finished preloading ads (if you requested preloading using the preloadAdBreaks above).\n * @returns\n */\n onReady?: () => void;\n}\n\n/**\n * PlacementInfo object passed by **adBreakDone** function\n */\nexport interface IPlacementInfo {\n /**\n * the type argument passed to adBreak()\n */\n breakType: string;\n /**\n * the name argument passed to adBreak()\n */\n breakName: string;\n breakFormat: \"interstitial\" | \"reward\";\n /**\n * the status of this placement and can be one of the following values:\n *\n * | breakStatus | Reason |\n * | -------- | ------- |\n * | 'notReady'\t| The Ad Placement API had not initialised |\n * | 'timeout' | A placement timed out because the Ad Placement API took too long to respond |\n * | 'invalid' | The placement was invalid and was ignored–for instance there should only be one preroll placement per page load, subsequent prerolls are failed with this status |\n * | 'error' | There was a JavaScript error in a callback |\n * | 'noAdPreloaded' |\tAn ad had not been preloaded yet so this placement was skipped |\n * | 'frequencyCapped' |\tAn ad wasn't shown because the frequency cap was applied to this placement |\n * | 'ignored' |\tThe user didn't click on a reward prompt before they reached the next placement, that is showAdFn() wasn't called before the next adBreak(). |\n * | 'other' |\tThe ad was not shown for another reason. (e.g., The ad was still being fetched, or a previously cached ad was disposed because the screen was resized/rotated.) |\n * | 'dismissed' |\tThe user dismissed a rewarded ad before viewing it to completion |\n * | 'viewed' |\tThe ad was viewed by the user |\n */\n breakStatus:\n | \"notReady\"\n | \"timeout\"\n | \"error\"\n | \"noAdPreloaded\"\n | \"frequencyCapped\"\n | \"ignored\"\n | \"other\"\n | \"dismissed\"\n | \"viewed\";\n}\n\n/**\n * Parameter when calling adBreak\n */\nexport type IAdBreakParams =\n | IPrerollParams\n | IInterstitialsParams\n | IRewardParams;\n\n/**\n * Parameter when calling preroll type adBreak\n */\nexport interface IPrerollParams {\n /**\n * 'preroll' before the game loads (before UI has rendered)\n */\n type: \"preroll\";\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n}\n\nexport interface IInterstitialsParams {\n /**\n * 'start' before the gameplay starts (after UI has rendered)\n * 'pause' the player pauses the game\n * 'next' player navigates to the next level\n * 'browse' the player explores options outside of the gameplay\n */\n type: \"start\" | \"pause\" | \"next\" | \"browse\";\n\n /**\n * (OPTIONAL) a name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. In future releases this identifier may be used to enable additional reporting and optimization features.\n *\n * We recommend you name all of your placements.\n */\n name?: string;\n\n /**\n * (OPTIONAL) Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes.\n *\n * @returns\n */\n beforeAd?: () => void;\n\n /**\n * (OPTIONAL) Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actions. This function should be used to resume game flow. For example, use to unmute the sound and start the next level.\n * @returns\n */\n afterAd?: () => void;\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object\n *\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n}\n\nexport interface IRewardParams {\n /**\n * 'reward' a rewarded ad\n */\n type: \"reward\";\n\n /**\n * (OPTIONAL) a name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. In future releases this identifier may be used to enable additional reporting and optimization features.\n *\n * We recommend you name all of your placements.\n */\n name?: string;\n\n /**\n * (OPTIONAL) Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes.\n * @returns\n */\n beforeAd?: () => void;\n\n /**\n * (OPTIONAL) Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actions. This function should be used to resume game flow. For example, use to unmute the sound and start the next level.\n * @returns\n */\n afterAd?: () => void;\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object defined\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n\n /**\n * Called if a rewarded ad is available. The function should take a single argument–showAdFn() which must be called to display the rewarded ad.\n * @param showAdFn\n * @returns\n */\n beforeReward: (showAdFn: () => void) => void;\n\n /**\n * Called only for rewarded ads when the player dismisses the ad. It is only called if the player dismisses the ad before it completes. In this case the reward should not be granted.\n * @returns\n */\n adDismissed: () => void;\n\n /**\n * Called only for rewarded ads when the player completes the ad and should be granted the reward.\n * @returns\n */\n adViewed: () => void;\n}\n\n/**\n * Ad unit format, can be 'rectangle', 'vertical', 'horizontal'\n */\nexport type AdUnitFormat = \"rectangle\" | \"vertical\" | \"horizontal\";\n\nexport interface IAdUnitParams {\n /**\n * The element to attach the ad unit to, either an HTMLElement or a string selector. Should be the parent element of the ad unit (<ins> tag).\n */\n el: HTMLElement | string;\n\n /**\n * (OPTIONAL) Reserved for future usage. The slot ID of the ad unit. Currently the slot ID is automatically set by the SDK.\n */\n slot?: string;\n\n // /**\n // * (OPTIONAL) The position of the ad unit. Can be 'TOP', 'BOTTOM', 'LEFT', 'RIGHT', 'CENTER'. Default is 'TOP'. Either position or slot should be set.\n // */\n // position?: AdUnitPosition;\n\n // /**\n // * (OPTIONAL) Channel ID for the ad unit. We will set the Channel ID automatically if not provided. Default is empty.\n // */\n // channelId?: string;\n\n /**\n * (OPTIONAL) Ad format for the ad unit. Can be 'auto' or a single format or an array of formats. Default is 'auto'. If passed as an array, the array will be joined by ', ' and pass to the data-ad-format attribute.\n */\n adFormat?: \"auto\" | AdUnitFormat | AdUnitFormat[];\n\n /**\n * (OPTIONAL) Whether the ad unit should be full width and responsive. Default is false.\n */\n fullWidthResponsive?: \"true\" | \"false\";\n\n /**\n * (OPTIONAL) Custom style for the ad unit. Default is empty.\n */\n style?: string;\n}\n\n/**\n * Jolibox Ads SDK\n */\nexport class JoliboxAds {\n /**\n * Internal constructor, should not be called directly\n */\n constructor() {}\n\n /**\n * Init JoliboxAds. Must be called before any other ads functions.\n * @param config\n * @returns\n */\n public init = (config?: IAdsInitParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.init\",\n params: config,\n });\n };\n\n /**\n * The adConfig() call communicates the game's current configuration to the Ad Placement API. The Ad Placement API can use this to tune the way it preloads ads and to filter the kinds of ads it requests so they're suitable (eg. video ads that require sound).\n * @param params\n */\n public adConfig = (params: IAdConfigParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adConfig\",\n params,\n });\n };\n\n /**\n * adBreak() is the key function for placing ads within your game. It defines an ad placement and takes an object called a placement config that specifies everything required to show an ad.\n *\n * The adBreak() function defines a placement where an ad could be shown. Whether an ad actually shows depends on factors such as the following:\n *\n * - The type of ad placement that you declared\n * - Is this ad at the start of the game? Between levels? At a moment when the player has paused the game?\n * - Whether a suitable ad exists for the current player\n * - Is this ad relevant to them?\n * - Is it consistent with their data privacy and consent settings?\n * - The number of ads the player has seen recently\n * - The control settings—for example, ad frequency, you've configured for this game\n * - Either as hints in the tag, or,\n * - Within AdSense—note that the controls available in AdSense will evolve over time.\n *\n * The kind of ad that shows also depends on similar factors.\n *\n * Note that a call to adBreak() might not show an ad at all. It simply declares a place where an ad could be shown.\n *\n * This is unlike traditional APIs in which your code always knows if an ad is available, and you decide within the game whether to show it. This approach of letting the Ad Placement API decide if an ad shows in a particular placement is a pattern that is sometimes referred to as \"inversion of control\".\n *\n * The reason we're transitioning our games API to this model is firstly, it shortens the code you have to write within your game. Secondly, it makes it easier to deliver policy compliant placements with a great user experience, which in turn has allowed us to deliver some of our highest performing formats to games publishers. Lastly, it more cleanly separates the process of placing ads in your game from the monetization decisions about the type and number of ads to show.\n *\n * We want you to be able to change your monetization settings and control the user experience without having to edit and release a new version of your game, initially by specifying hints in the tag. But in future releases, we will be able to provide controls directly in the AdSense and AdMob frontends.\n * @param params\n */\n public adBreak = (params: IAdBreakParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adBreak\",\n params,\n });\n };\n\n /**\n * adUnit() is a function that creates an ad unit and attaches it to a parent element. The ad unit is a single ad placement that can be used to show ads.\n *\n * Currently we only provide support for creating ad units as `<ins>` tags with the class 'adsbygoogle'. This is the standard way to create ad units with Google AdSense.\n *\n * After calling this method, the ad unit is attached to the parent element you specify as el in the params object.\n *\n * By default, the client ID and channel ID are automatically set by the SDK. And the slot name is set to the position of the ad unit. You can override these values by passing the slot and channelId in the params object.\n *\n * @param params\n * @returns\n */\n public adUnit = async (params: IAdUnitParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adUnit\",\n params,\n });\n };\n}\n\nwindow.JoliboxAds = JoliboxAds;\n\nexport default JoliboxAds;\n","declare global {\n interface Window {\n JoliboxAnalytics: typeof JoliboxAnalytics;\n }\n}\n\n/**\n * Jolibox Analytics SDK\n */\nexport class JoliboxAnalytics {\n constructor() {}\n\n /**\n * Track an event, will be sent to the analytics server\n *\n * @param eventName event name, must be a string\n * @param extra (OPTIONAL) extra data, must be an object or null or undefined, must not have nested objects\n */\n public trackEvent = (\n eventName: string,\n extra?: Record<string, string | boolean | number | null> | null\n ) => {\n // assert eventName is a string\n if (typeof eventName !== \"string\") {\n throw new Error(\"eventName must be a string\");\n }\n\n // assert extra is an object or null or undefined\n if (extra !== null && typeof extra !== \"object\" && extra !== undefined) {\n throw new Error(\"extra must be an object or null or undefined\");\n }\n\n // assert extra has no nested objects\n if (extra) {\n for (const key in extra) {\n if (typeof extra[key] === \"object\") {\n throw new Error(\"extra must not have nested objects\");\n }\n }\n }\n\n window.joliboxsdk._commandPipe.push({\n cmd: \"analytics.trackEvent\",\n params: [eventName, extra],\n });\n };\n}\n\nwindow.JoliboxAnalytics = JoliboxAnalytics;\n\nexport default JoliboxAnalytics;\n","import \"./loader\";\nimport \"./ads\";\nimport \"./analytics\";\nimport \"@jolibox/web-sync-sdk\";\nimport type { JoliboxSDKLoader, IJoliboxSDKLoaderConfig } from \"./loader\";\nimport type { JoliboxAds } from \"./ads\";\nimport type { JoliboxAnalytics } from \"./analytics\";\nimport type { JoliboxRuntime } from \"./runtime\";\n\ndeclare global {\n interface IJoliboxSDK extends JoliboxSDK {\n _commandPipe: ICommandPipe[];\n }\n interface Window {\n __JOLIBOX_LOCAL_SDK_VERSION__: string;\n joliboxenv?: {\n testMode: boolean;\n apiBaseURL: string;\n };\n joliboxsdk: IJoliboxSDK;\n JoliboxSDK: typeof JoliboxSDK;\n }\n interface ImportMeta {\n env: {\n JOLIBOX_SDK_VERSION: string;\n };\n }\n}\n\nwindow.__JOLIBOX_LOCAL_SDK_VERSION__ = import.meta.env.JOLIBOX_SDK_VERSION;\n\nexport interface IJoliboxConfig {\n useRuntimeSDK?: boolean;\n loaderConfig?: IJoliboxSDKLoaderConfig;\n testMode?: boolean;\n apiBaseURL?: string;\n}\n\ninterface ICommandPipe {\n cmd: string;\n params: any;\n}\n\nclass JoliboxSDK {\n private loader: JoliboxSDKLoader;\n ads: JoliboxAds;\n anaytics: JoliboxAnalytics;\n runtime: JoliboxRuntime;\n\n setJoliboxEnv = (inputTestMode?: boolean, inputApiBaseURL?: string) => {\n const isBrowser = typeof window !== \"undefined\";\n const urlSearchParams = isBrowser\n ? new URLSearchParams(window.location.search)\n : null;\n const testModeParam = urlSearchParams?.get(\"testMode\") === \"true\";\n const testMode = inputTestMode ?? testModeParam;\n\n const apiBaseURLParam = urlSearchParams?.get(\"apiBaseURL\");\n let apiBaseURL;\n if (inputApiBaseURL) {\n apiBaseURL = inputApiBaseURL;\n } else if (apiBaseURLParam) {\n apiBaseURL = apiBaseURLParam;\n } else {\n apiBaseURL = testMode\n ? \"https://test-api.jolibox.com\"\n : \"https://api.jolibox.com\";\n }\n window.joliboxenv = {\n testMode,\n apiBaseURL,\n };\n };\n\n constructor({\n useRuntimeSDK = true,\n loaderConfig,\n testMode,\n apiBaseURL,\n }: IJoliboxConfig = {}) {\n this.setJoliboxEnv(testMode, apiBaseURL);\n if (useRuntimeSDK && window.joliboxsdk) {\n this.loader =\n window.joliboxsdk.loader ?? new window.JoliboxSDKLoader(loaderConfig);\n this.ads = window.joliboxsdk.ads ?? new window.JoliboxAds();\n this.anaytics =\n window.joliboxsdk.anaytics ?? new window.JoliboxAnalytics();\n this.runtime = window.joliboxsdk.runtime ?? new window.JoliboxRuntime();\n } else {\n if (!window.joliboxsdk) {\n window.joliboxsdk = {\n _commandPipe: [], // This is to avoid the error \"Cannot read property 'push' of undefined\" if any command is called before the SDK is initialized\n } as any;\n }\n\n this.loader = new window.JoliboxSDKLoader(loaderConfig);\n this.ads = new window.JoliboxAds();\n this.anaytics = new window.JoliboxAnalytics();\n this.runtime = new window.JoliboxRuntime();\n window.joliboxsdk = Object.assign(this, window.joliboxsdk);\n }\n if (!window.joliboxsdk._commandPipe) {\n window.joliboxsdk._commandPipe = [];\n }\n }\n}\n\nif (!window.JoliboxSDK) {\n window.JoliboxSDK = JoliboxSDK;\n}\n\nexport default JoliboxSDK;\nexport { JoliboxSDK };\n"],"mappings":"6MAAA,IAAMA,EACJC,GAOG,CARL,IAAAC,EAAAC,EAAAC,EASE,IAAMC,EAAaJ,EAAQ,MAAM,GAAG,EAAE,CAAC,EACnCI,IACFJ,EAAUA,EAAQ,QAAQ,IAAII,CAAU,GAAI,EAAE,GAGhD,IAAMC,EAAQL,EAAQ,MAAM,GAAG,EAAE,CAAC,EAC9BK,IACFL,EAAUA,EAAQ,QAAQ,IAAIK,CAAK,GAAI,EAAE,GAG3C,IAAMC,EAAWN,EAAQ,MAAM,GAAG,EAAE,MAAM,EAAG,CAAC,EACxC,CAACO,EAAOC,EAAOC,CAAK,EAAI,EAC5BR,EAAAK,EAAS,CAAC,IAAV,KAAAL,EAAe,KACfC,EAAAI,EAAS,CAAC,IAAV,KAAAJ,EAAe,KACfC,EAAAG,EAAS,CAAC,IAAV,KAAAH,EAAe,GACjB,EACA,MAAO,CAAE,MAAAI,EAAO,MAAAC,EAAO,MAAAC,EA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G,CA9BxB,mBAAgB,CAACC,EAAyBC,IAA6B,CAErE,IAAMC,EADY,OAAO,OAAW,IAEhC,IAAI,gBAAgB,OAAO,SAAS,MAAM,EAC1C,KACEC,GAAgBD,GAAA,YAAAA,EAAiB,IAAI,eAAgB,OACrDJ,EAAWE,GAAA,KAAAA,EAAiBG,EAE5BC,EAAkBF,GAAA,YAAAA,EAAiB,IAAI,cACzCH,EACAE,EACFF,EAAaE,EACJG,EACTL,EAAaK,EAEbL,EAAaD,EACT,+BACA,0BAEN,OAAO,WAAa,CAClB,SAAAA,EACA,WAAAC,CACF,CACF,EAxEF,IAAAM,EAAAC,EAAAC,EAAAC,EAgFI,KAAK,cAAcV,EAAUC,CAAU,EACnCH,GAAiB,OAAO,YAC1B,KAAK,QACHS,EAAA,OAAO,WAAW,SAAlB,KAAAA,EAA4B,IAAI,OAAO,iBAAiBR,CAAY,EACtE,KAAK,KAAMS,EAAA,OAAO,WAAW,MAAlB,KAAAA,EAAyB,IAAI,OAAO,WAC/C,KAAK,UACHC,EAAA,OAAO,WAAW,WAAlB,KAAAA,EAA8B,IAAI,OAAO,iBAC3C,KAAK,SAAUC,EAAA,OAAO,WAAW,UAAlB,KAAAA,EAA6B,IAAI,OAAO,iBAElD,OAAO,aACV,OAAO,WAAa,CAClB,aAAc,CAAC,CACjB,GAGF,KAAK,OAAS,IAAI,OAAO,iBAAiBX,CAAY,EACtD,KAAK,IAAM,IAAI,OAAO,WACtB,KAAK,SAAW,IAAI,OAAO,iBAC3B,KAAK,QAAU,IAAI,OAAO,eAC1B,OAAO,WAAa,OAAO,OAAO,KAAM,OAAO,UAAU,GAEtD,OAAO,WAAW,eACrB,OAAO,WAAW,aAAe,CAAC,EAEtC,CACF,EAEK,OAAO,aACV,OAAO,WAAaF,GAGtB,IAAOc,EAAQd","names":["splitSemver","version","_a","_b","_c","prerelease","build","splitted","major","minor","patch","compare","v1","v2","major1","minor1","patch1","major2","minor2","patch2","joliboxLoaderKey","JoliboxSDKLoader","loaderMetadata","_a","_b","version","error","versionFromLocalStorage","major","compare","xhr","script","asyncScript","_0","__async","installedSDKVersion","localSDKVersion","env","_c","path","data","majorVersion","JoliboxAds","config","params","__async","JoliboxAnalytics","eventName","extra","key","JoliboxSDK","useRuntimeSDK","loaderConfig","testMode","apiBaseURL","inputTestMode","inputApiBaseURL","urlSearchParams","testModeParam","apiBaseURLParam","_a","_b","_c","_d","src_default"]}
1
+ {"version":3,"sources":["../src/loader/utils.ts","../src/loader/index.ts","../src/ads/index.ts","../src/analytics/index.ts","../src/index.ts"],"sourcesContent":["const splitSemver = (\n version: string\n): {\n major: string;\n minor: string;\n patch: string;\n prerelease?: string;\n build?: string;\n} => {\n const prerelease = version.split(\"-\")[1] as string | undefined;\n if (prerelease) {\n version = version.replace(`-${prerelease}`, \"\");\n }\n\n const build = version.split(\"+\")[1] as string | undefined;\n if (build) {\n version = version.replace(`+${build}`, \"\");\n }\n\n const splitted = version.split(\".\").slice(0, 3);\n const [major, minor, patch] = [\n splitted[0] ?? \"0\",\n splitted[1] ?? \"0\",\n splitted[2] ?? \"0\",\n ];\n return { major, minor, patch, prerelease, build };\n};\n\nexport const major = (version: string): number =>\n parseInt(splitSemver(version).major, 10);\n\nexport const compare = (v1: string, v2: string): -1 | 0 | 1 => {\n const { major: major1, minor: minor1, patch: patch1 } = splitSemver(v1);\n const { major: major2, minor: minor2, patch: patch2 } = splitSemver(v2);\n\n if (major1 !== major2) {\n return major1 > major2 ? 1 : -1;\n }\n\n if (minor1 !== minor2) {\n return minor1 > minor2 ? 1 : -1;\n }\n\n if (patch1 !== patch2) {\n return patch1 > patch2 ? 1 : -1;\n }\n\n return 0;\n};\n","import { major, compare } from \"./utils\";\n\ndeclare global {\n interface Window {\n JOLIBOX_ENV: \"WEB\" | \"IOS\" | \"ANDROID\" | \"WINDOWS\" | \"MACOS\" | \"LINUX\";\n JoliboxSDKLoader: typeof JoliboxSDKLoader;\n }\n}\n\nconst joliboxLoaderKey = \"jolibox-sdk-loader-metadata\";\n\nexport interface IVersionMetadata {\n version: string;\n syncScriptUrl?: string; // By default, the sync script is bundled with the sdk\n asyncScriptUrl?: string;\n}\n\nexport interface IRemoteVersionMetadata {\n code: \"SUCCESS\" | string;\n message?: string;\n data?: IVersionMetadata;\n}\n\nexport interface IJoliboxSDKLoaderConfig {\n loaderMetadata?: IVersionMetadata;\n}\n\nexport class JoliboxSDKLoader {\n loaderMetadata: IVersionMetadata;\n\n constructor({ loaderMetadata }: IJoliboxSDKLoaderConfig = {}) {\n console.log(\"Loading Jolibox SDK...\");\n\n this.loaderMetadata = loaderMetadata ?? this.computeLoaderMetaData();\n this.loadScript();\n this.fetchUpdateLoaderMetadata();\n console.log(\"Jolibox SDK loaded.\");\n }\n\n private get currentVersion() {\n return window.__JOLIBOX_LOCAL_SDK_VERSION__;\n }\n\n private get defaultMetadata(): IVersionMetadata {\n const version = this.currentVersion;\n const majorVersion = major(version);\n return {\n version,\n syncScriptUrl: `https://cdn.jsdelivr.net/npm/@jolibox/web-sync-sdk@${majorVersion}/dist/index.iife.js`,\n asyncScriptUrl: `https://cdn.jsdelivr.net/npm/@jolibox/web-async-sdk@${majorVersion}/dist/index.iife.js`,\n };\n }\n\n computeLoaderMetaData = () => {\n const version = this.currentVersion;\n let loaderMetadata: IVersionMetadata | null = null;\n try {\n loaderMetadata = JSON.parse(\n localStorage.getItem(joliboxLoaderKey) ?? \"null\"\n ) as IVersionMetadata | null;\n if (!loaderMetadata || !loaderMetadata.version) {\n throw new Error(\"Invalid loader metadata\");\n }\n } catch (error) {\n loaderMetadata = this.defaultMetadata;\n }\n\n const versionFromLocalStorage = loaderMetadata?.version ?? version;\n\n if (major(versionFromLocalStorage) !== major(version)) {\n // if major version is different, must follow the version from package.json\n loaderMetadata = this.defaultMetadata;\n } else {\n // if major version is the same, follow the larger version\n if (compare(versionFromLocalStorage, version) < 0) {\n loaderMetadata = this.defaultMetadata;\n }\n }\n\n return loaderMetadata;\n };\n\n loadScript = () => {\n if (this.loaderMetadata.syncScriptUrl) {\n // The only way to load a script synchronously is to use XMLHttpRequest\n const xhr = new XMLHttpRequest();\n xhr.open(\"GET\", this.loaderMetadata.syncScriptUrl, false);\n xhr.send();\n // eval(xhr.responseText);\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.innerHTML = xhr.responseText;\n document.head.appendChild(script);\n }\n\n if (this.loaderMetadata.asyncScriptUrl) {\n const asyncScript = document.createElement(\"script\");\n asyncScript.type = \"text/javascript\";\n asyncScript.src = this.loaderMetadata.asyncScriptUrl;\n asyncScript.async = true;\n document.head.appendChild(asyncScript);\n }\n };\n\n fetchUpdateLoaderMetadata = async (\n installedSDKVersion = this.currentVersion,\n localSDKVersion = this.loaderMetadata.version,\n env = window.JOLIBOX_ENV ?? \"WEB\"\n ) => {\n const path = `${\n window.joliboxenv?.apiBaseURL ?? \"https://api.jolibox.com\"\n }/frontend/js-sdk/loader-metadata`;\n try {\n const response = await fetch(path, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n installedSDKVersion,\n localSDKVersion,\n env,\n }),\n });\n const data: IRemoteVersionMetadata = await response.json();\n if (data.code !== \"SUCCESS\") {\n throw new Error(data.message);\n } else {\n this.loaderMetadata = data.data ?? this.defaultMetadata;\n localStorage.setItem(\n joliboxLoaderKey,\n JSON.stringify(this.loaderMetadata)\n );\n // reload happens next time the page is loaded\n }\n } catch (error) {\n console.warn(\"Failed to fetch loader metadata: \", error);\n }\n };\n}\n\nwindow.JoliboxSDKLoader = JoliboxSDKLoader;\n","declare global {\n interface Window {\n JoliboxAds: typeof JoliboxAds;\n }\n}\n\nexport interface IAdsInitParams {\n /**\n * (OPTIONAL) Game ID provided by Jolibox\n */\n gameId?: string;\n}\n\nexport interface IAdConfigParams {\n /**\n * (OPTIONAL) Whether ads should always be preloaded before the first call to adBreak()\n *\n * The default value of auto leaves the decision up to the Ad Placement API. preloadAdBreaks can be set only once with adConfig(), and further values passed to preloadAdBreaks have no effect.\n *\n * Setting preloadAdBreaks after the first call to adBreak() has no effect.\n */\n preloadAdBreaks?: \"on\" | \"auto\"; // default: 'auto'\n\n /**\n * (OPTIONAL) Whether the game is currently playing sound.\n *\n * This call specifies whether your game is capable of sound, and whether the sound was enabled (ie unmuted) before the call to adBreak(). This helps the Ad Placement API to select the right kind of ad for your game.\n *\n * Call this function as soon as the sound state of your game changes, as the Ad Placement API may have to request new creatives, and this gives it the maximum amount of time to do so.\n *\n * The default value is sound on. So most games will need to make a call to adConfig() when they start to declare that they have sound enabled.\n */\n sound?: \"on\" | \"off\"; // default: 'on'\n\n /**\n * (OPTIONAL) Called when the API has initialized and has finished preloading ads (if you requested preloading using the preloadAdBreaks above).\n * @returns\n */\n onReady?: () => void;\n}\n\n/**\n * PlacementInfo object passed by **adBreakDone** function\n */\nexport interface IPlacementInfo {\n /**\n * the type argument passed to adBreak()\n */\n breakType: string;\n /**\n * the name argument passed to adBreak()\n */\n breakName: string;\n breakFormat: \"interstitial\" | \"reward\";\n /**\n * the status of this placement and can be one of the following values:\n *\n * | breakStatus | Reason |\n * | -------- | ------- |\n * | 'notReady'\t| The Ad Placement API had not initialised |\n * | 'timeout' | A placement timed out because the Ad Placement API took too long to respond |\n * | 'invalid' | The placement was invalid and was ignored–for instance there should only be one preroll placement per page load, subsequent prerolls are failed with this status |\n * | 'error' | There was a JavaScript error in a callback |\n * | 'noAdPreloaded' |\tAn ad had not been preloaded yet so this placement was skipped |\n * | 'frequencyCapped' |\tAn ad wasn't shown because the frequency cap was applied to this placement |\n * | 'ignored' |\tThe user didn't click on a reward prompt before they reached the next placement, that is showAdFn() wasn't called before the next adBreak(). |\n * | 'other' |\tThe ad was not shown for another reason. (e.g., The ad was still being fetched, or a previously cached ad was disposed because the screen was resized/rotated.) |\n * | 'dismissed' |\tThe user dismissed a rewarded ad before viewing it to completion |\n * | 'viewed' |\tThe ad was viewed by the user |\n */\n breakStatus:\n | \"notReady\"\n | \"timeout\"\n | \"error\"\n | \"noAdPreloaded\"\n | \"frequencyCapped\"\n | \"ignored\"\n | \"other\"\n | \"dismissed\"\n | \"viewed\";\n}\n\n/**\n * Parameter when calling adBreak\n */\nexport type IAdBreakParams =\n | IPrerollParams\n | IInterstitialsParams\n | IRewardParams;\n\n/**\n * Parameter when calling preroll type adBreak\n */\nexport interface IPrerollParams {\n /**\n * 'preroll' before the game loads (before UI has rendered)\n */\n type: \"preroll\";\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n}\n\nexport interface IInterstitialsParams {\n /**\n * 'start' before the gameplay starts (after UI has rendered)\n * 'pause' the player pauses the game\n * 'next' player navigates to the next level\n * 'browse' the player explores options outside of the gameplay\n */\n type: \"start\" | \"pause\" | \"next\" | \"browse\";\n\n /**\n * (OPTIONAL) a name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. In future releases this identifier may be used to enable additional reporting and optimization features.\n *\n * We recommend you name all of your placements.\n */\n name?: string;\n\n /**\n * (OPTIONAL) Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes.\n *\n * @returns\n */\n beforeAd?: () => void;\n\n /**\n * (OPTIONAL) Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actions. This function should be used to resume game flow. For example, use to unmute the sound and start the next level.\n * @returns\n */\n afterAd?: () => void;\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object\n *\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n}\n\nexport interface IRewardParams {\n /**\n * 'reward' a rewarded ad\n */\n type: \"reward\";\n\n /**\n * (OPTIONAL) a name for this particular ad placement within your game. It is an internal identifier, and is not shown to the player. In future releases this identifier may be used to enable additional reporting and optimization features.\n *\n * We recommend you name all of your placements.\n */\n name?: string;\n\n /**\n * (OPTIONAL) Called before the ad is displayed. The game should pause and mute the sound. These actions must be done synchronously. The ad will be displayed immediately after this callback finishes.\n * @returns\n */\n beforeAd?: () => void;\n\n /**\n * (OPTIONAL) Called after the ad is finished (for any reason). For rewarded ads, it is called after either adDismissed or adViewed, depending on player actions. This function should be used to resume game flow. For example, use to unmute the sound and start the next level.\n * @returns\n */\n afterAd?: () => void;\n\n /**\n * (OPTIONAL) Always called as the last step in an adBreak(), even if there was no ad shown. Function takes as argument a placementInfo object defined\n * @param placementInfo\n * @returns\n */\n adBreakDone?: (placementInfo: IPlacementInfo) => void;\n\n /**\n * Called if a rewarded ad is available. The function should take a single argument–showAdFn() which must be called to display the rewarded ad.\n * @param showAdFn\n * @returns\n */\n beforeReward: (showAdFn: () => void) => void;\n\n /**\n * Called only for rewarded ads when the player dismisses the ad. It is only called if the player dismisses the ad before it completes. In this case the reward should not be granted.\n * @returns\n */\n adDismissed: () => void;\n\n /**\n * Called only for rewarded ads when the player completes the ad and should be granted the reward.\n * @returns\n */\n adViewed: () => void;\n}\n\n/**\n * Ad unit format, can be 'rectangle', 'vertical', 'horizontal'\n */\nexport type AdUnitFormat = \"rectangle\" | \"vertical\" | \"horizontal\";\n\nexport interface IAdUnitParams {\n /**\n * The element to attach the ad unit to, either an HTMLElement or a string selector. Should be the parent element of the ad unit (<ins> tag).\n */\n el: HTMLElement | string;\n\n /**\n * (OPTIONAL) Reserved for future usage. The slot ID of the ad unit. Currently the slot ID is automatically set by the SDK.\n */\n slot?: string;\n\n // /**\n // * (OPTIONAL) The position of the ad unit. Can be 'TOP', 'BOTTOM', 'LEFT', 'RIGHT', 'CENTER'. Default is 'TOP'. Either position or slot should be set.\n // */\n // position?: AdUnitPosition;\n\n // /**\n // * (OPTIONAL) Channel ID for the ad unit. We will set the Channel ID automatically if not provided. Default is empty.\n // */\n // channelId?: string;\n\n /**\n * (OPTIONAL) Ad format for the ad unit. Can be 'auto' or a single format or an array of formats. Default is 'auto'. If passed as an array, the array will be joined by ', ' and pass to the data-ad-format attribute.\n */\n adFormat?: \"auto\" | AdUnitFormat | AdUnitFormat[];\n\n /**\n * (OPTIONAL) Whether the ad unit should be full width and responsive. Default is false.\n */\n fullWidthResponsive?: \"true\" | \"false\";\n\n /**\n * (OPTIONAL) Custom style for the ad unit. Default is empty.\n */\n style?: string;\n}\n\n/**\n * Jolibox Ads SDK\n */\nexport class JoliboxAds {\n /**\n * Internal constructor, should not be called directly\n */\n constructor() {}\n\n /**\n * Init JoliboxAds. Must be called before any other ads functions.\n * @param config\n * @returns\n */\n public init = (config?: IAdsInitParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.init\",\n params: config,\n });\n };\n\n /**\n * The adConfig() call communicates the game's current configuration to the Ad Placement API. The Ad Placement API can use this to tune the way it preloads ads and to filter the kinds of ads it requests so they're suitable (eg. video ads that require sound).\n * @param params\n */\n public adConfig = (params: IAdConfigParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adConfig\",\n params,\n });\n };\n\n /**\n * adBreak() is the key function for placing ads within your game. It defines an ad placement and takes an object called a placement config that specifies everything required to show an ad.\n *\n * The adBreak() function defines a placement where an ad could be shown. Whether an ad actually shows depends on factors such as the following:\n *\n * - The type of ad placement that you declared\n * - Is this ad at the start of the game? Between levels? At a moment when the player has paused the game?\n * - Whether a suitable ad exists for the current player\n * - Is this ad relevant to them?\n * - Is it consistent with their data privacy and consent settings?\n * - The number of ads the player has seen recently\n * - The control settings—for example, ad frequency, you've configured for this game\n * - Either as hints in the tag, or,\n * - Within AdSense—note that the controls available in AdSense will evolve over time.\n *\n * The kind of ad that shows also depends on similar factors.\n *\n * Note that a call to adBreak() might not show an ad at all. It simply declares a place where an ad could be shown.\n *\n * This is unlike traditional APIs in which your code always knows if an ad is available, and you decide within the game whether to show it. This approach of letting the Ad Placement API decide if an ad shows in a particular placement is a pattern that is sometimes referred to as \"inversion of control\".\n *\n * The reason we're transitioning our games API to this model is firstly, it shortens the code you have to write within your game. Secondly, it makes it easier to deliver policy compliant placements with a great user experience, which in turn has allowed us to deliver some of our highest performing formats to games publishers. Lastly, it more cleanly separates the process of placing ads in your game from the monetization decisions about the type and number of ads to show.\n *\n * We want you to be able to change your monetization settings and control the user experience without having to edit and release a new version of your game, initially by specifying hints in the tag. But in future releases, we will be able to provide controls directly in the AdSense and AdMob frontends.\n * @param params\n */\n public adBreak = (params: IAdBreakParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adBreak\",\n params,\n });\n };\n\n /**\n * adUnit() is a function that creates an ad unit and attaches it to a parent element. The ad unit is a single ad placement that can be used to show ads.\n *\n * Currently we only provide support for creating ad units as `<ins>` tags with the class 'adsbygoogle'. This is the standard way to create ad units with Google AdSense.\n *\n * After calling this method, the ad unit is attached to the parent element you specify as el in the params object.\n *\n * By default, the client ID and channel ID are automatically set by the SDK. And the slot name is set to the position of the ad unit. You can override these values by passing the slot and channelId in the params object.\n *\n * @param params\n * @returns\n */\n public adUnit = async (params: IAdUnitParams) => {\n window.joliboxsdk._commandPipe.push({\n cmd: \"ads.adUnit\",\n params,\n });\n };\n}\n\nwindow.JoliboxAds = JoliboxAds;\n\nexport default JoliboxAds;\n","declare global {\n interface Window {\n JoliboxAnalytics: typeof JoliboxAnalytics;\n }\n}\n\n/**\n * Jolibox Analytics SDK\n */\nexport class JoliboxAnalytics {\n constructor() {}\n\n /**\n * Track an event, will be sent to the analytics server\n *\n * @param eventName event name, must be a string\n * @param extra (OPTIONAL) extra data, must be an object or null or undefined, must not have nested objects\n */\n public trackEvent = (\n eventName: string,\n extra?: Record<string, string | boolean | number | null> | null\n ) => {\n // assert eventName is a string\n if (typeof eventName !== \"string\") {\n throw new Error(\"eventName must be a string\");\n }\n\n // assert extra is an object or null or undefined\n if (extra !== null && typeof extra !== \"object\" && extra !== undefined) {\n throw new Error(\"extra must be an object or null or undefined\");\n }\n\n // assert extra has no nested objects\n if (extra) {\n for (const key in extra) {\n if (typeof extra[key] === \"object\") {\n throw new Error(\"extra must not have nested objects\");\n }\n }\n }\n\n window.joliboxsdk._commandPipe.push({\n cmd: \"analytics.trackEvent\",\n params: [eventName, extra],\n });\n };\n}\n\nwindow.JoliboxAnalytics = JoliboxAnalytics;\n\nexport default JoliboxAnalytics;\n","import \"./loader\";\nimport \"./ads\";\nimport \"./analytics\";\nimport \"@jolibox/web-sync-sdk\";\nimport type { JoliboxSDKLoader, IJoliboxSDKLoaderConfig } from \"./loader\";\nimport type { JoliboxAds } from \"./ads\";\nimport type { JoliboxAnalytics } from \"./analytics\";\nimport type { JoliboxRuntime } from \"./runtime\";\n\ndeclare global {\n interface IJoliboxSDK extends JoliboxSDK {\n _commandPipe: ICommandPipe[];\n }\n interface Window {\n __JOLIBOX_LOCAL_SDK_VERSION__: string;\n joliboxenv?: {\n testMode: boolean;\n apiBaseURL: string;\n };\n joliboxsdk: IJoliboxSDK;\n JoliboxSDK: typeof JoliboxSDK;\n }\n interface ImportMeta {\n env: {\n JOLIBOX_SDK_VERSION: string;\n };\n }\n}\n\nwindow.__JOLIBOX_LOCAL_SDK_VERSION__ = import.meta.env.JOLIBOX_SDK_VERSION;\n\nexport interface IJoliboxConfig {\n useRuntimeSDK?: boolean;\n loaderConfig?: IJoliboxSDKLoaderConfig;\n testMode?: boolean;\n apiBaseURL?: string;\n}\n\ninterface ICommandPipe {\n cmd: string;\n params: any;\n}\n\nclass JoliboxSDK {\n private loader: JoliboxSDKLoader;\n ads: JoliboxAds;\n anaytics: JoliboxAnalytics;\n runtime: JoliboxRuntime;\n\n setJoliboxEnv = (inputTestMode?: boolean, inputApiBaseURL?: string) => {\n const isBrowser = typeof window !== \"undefined\";\n const urlSearchParams = isBrowser\n ? new URLSearchParams(window.location.search)\n : null;\n const testModeParam = urlSearchParams?.get(\"testMode\") === \"true\";\n const testMode = inputTestMode ?? testModeParam;\n\n const apiBaseURLParam = urlSearchParams?.get(\"apiBaseURL\");\n let apiBaseURL;\n if (inputApiBaseURL) {\n apiBaseURL = inputApiBaseURL;\n } else if (apiBaseURLParam) {\n apiBaseURL = apiBaseURLParam;\n } else {\n apiBaseURL = testMode\n ? \"https://test-api.jolibox.com\"\n : \"https://api.jolibox.com\";\n }\n window.joliboxenv = {\n testMode,\n apiBaseURL,\n };\n };\n\n constructor({\n useRuntimeSDK = true,\n loaderConfig,\n testMode,\n apiBaseURL,\n }: IJoliboxConfig = {}) {\n this.setJoliboxEnv(testMode, apiBaseURL);\n if (useRuntimeSDK && window.joliboxsdk) {\n this.loader =\n window.joliboxsdk.loader ?? new window.JoliboxSDKLoader(loaderConfig);\n this.ads = window.joliboxsdk.ads ?? new window.JoliboxAds();\n this.anaytics =\n window.joliboxsdk.anaytics ?? new window.JoliboxAnalytics();\n this.runtime = window.joliboxsdk.runtime ?? new window.JoliboxRuntime();\n } else {\n if (!window.joliboxsdk) {\n window.joliboxsdk = {\n _commandPipe: [], // This is to avoid the error \"Cannot read property 'push' of undefined\" if any command is called before the SDK is initialized\n } as any;\n }\n\n this.loader = new window.JoliboxSDKLoader(loaderConfig);\n this.ads = new window.JoliboxAds();\n this.anaytics = new window.JoliboxAnalytics();\n this.runtime = new window.JoliboxRuntime();\n window.joliboxsdk = Object.assign(this, window.joliboxsdk);\n }\n if (!window.joliboxsdk._commandPipe) {\n window.joliboxsdk._commandPipe = [];\n }\n }\n}\n\nif (!window.JoliboxSDK) {\n window.JoliboxSDK = JoliboxSDK;\n}\n\nexport default JoliboxSDK;\nexport { JoliboxSDK };\n"],"mappings":"6MAAA,IAAMA,EACJC,GAOG,CARL,IAAAC,EAAAC,EAAAC,EASE,IAAMC,EAAaJ,EAAQ,MAAM,GAAG,EAAE,CAAC,EACnCI,IACFJ,EAAUA,EAAQ,QAAQ,IAAII,CAAU,GAAI,EAAE,GAGhD,IAAMC,EAAQL,EAAQ,MAAM,GAAG,EAAE,CAAC,EAC9BK,IACFL,EAAUA,EAAQ,QAAQ,IAAIK,CAAK,GAAI,EAAE,GAG3C,IAAMC,EAAWN,EAAQ,MAAM,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O,WAAa,OAAO,OAAO,KAAM,OAAO,UAAU,GAEtD,OAAO,WAAW,eACrB,OAAO,WAAW,aAAe,CAAC,EAEtC,CACF,EAEK,OAAO,aACV,OAAO,WAAaF,GAGtB,IAAOc,EAAQd","names":["splitSemver","version","_a","_b","_c","prerelease","build","splitted","major","minor","patch","compare","v1","v2","major1","minor1","patch1","major2","minor2","patch2","joliboxLoaderKey","JoliboxSDKLoader","loaderMetadata","_a","_b","version","error","versionFromLocalStorage","major","compare","xhr","script","asyncScript","_0","__async","installedSDKVersion","localSDKVersion","env","_c","path","data","majorVersion","JoliboxAds","config","params","__async","JoliboxAnalytics","eventName","extra","key","JoliboxSDK","useRuntimeSDK","loaderConfig","testMode","apiBaseURL","inputTestMode","inputApiBaseURL","urlSearchParams","testModeParam","apiBaseURLParam","_a","_b","_c","_d","src_default"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jolibox/sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.7-beta.1",
4
4
  "description": "Jolibox JavaScript SDK for Ads",
5
5
  "homepage": "https://sdk-docs.jolibox.com",
6
6
  "repository": {
@@ -28,7 +28,7 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@jolibox/web-sync-sdk": "1.0.6"
31
+ "@jolibox/web-sync-sdk": "1.0.7-beta.1"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "tsup",