Comparing version 1.0.25 to 1.0.26
var AgRuSdkMethods = /* @__PURE__ */ ((AgRuSdkMethods2) => { | ||
AgRuSdkMethods2["Authorize"] = "agru-authorize"; | ||
AgRuSdkMethods2["AuthorizeAndWait"] = "agru-authorizeAndWait"; | ||
AgRuSdkMethods2["GetSaveData"] = "agru-getSaveData"; | ||
@@ -50,3 +51,3 @@ AgRuSdkMethods2["GetUsers"] = "agru-getUsers"; | ||
if (typeof handler === "function") { | ||
handler.apply(null, ...args); | ||
handler.call(null, ...args); | ||
} | ||
@@ -77,2 +78,6 @@ }; | ||
} | ||
authorizeAndWait(callback) { | ||
this._sendMessage(AgRuSdkMethods.AuthorizeAndWait, void 0); | ||
return this._handleEvent(AgRuSdkMethods.AuthorizeAndWait, callback); | ||
} | ||
getSaveData(callback) { | ||
@@ -79,0 +84,0 @@ this._sendMessage(AgRuSdkMethods.GetSaveData, this.options); |
@@ -1,1 +0,1 @@ | ||
var e=(e=>(e.Authorize="agru-authorize",e.GetSaveData="agru-getSaveData",e.GetUsers="agru-getUsers",e.IsAppUser="agru-isAppUser",e.SayHello="agru-sayHello",e.ShowCampaign="agru-showCampaign",e.ShowPayment="agru-showPayment",e.SetSaveData="agru-setSaveData",e.ToggleFullscreen="agru-toggleFullscreen",e))(e||{}),t=(e=>(e.OptionsUpdates="agru-optionsUpdates",e))(t||{});class s{constructor(e={}){if(this.options=e,s._instance)return s._instance;for(const[e,t]of new URLSearchParams(location.search).entries())this.options[e]=t;return this.options.auth_key||console.warn('You need to pass the "auth_key" in options, to be able to use the SDK.'),s._instance=this,s._instance._emitter=this._createEmitter(),s._instance.options=e,this._listen(),this}_createEmitter(){const e={all:t=t||new Map,on:function(e,s){var n=t.get(e);n?n.push(s):t.set(e,[s])},off:function(e,s){var n=t.get(e);n&&(s?n.splice(n.indexOf(s)>>>0,1):t.set(e,[]))},emit:function(e,s){var n=t.get(e);n&&n.slice().map((function(e){e(s)})),(n=t.get("*"))&&n.slice().map((function(t){t(e,s)}))}};var t;const s=e.on;return e.on=(e,t)=>{"function"==typeof t&&s(e,(e=>t.call(null,...e)))},e.once=(t,n)=>{const a=(...s)=>{e.off(t,a),"function"==typeof n&&n.apply(null,...s)};s(t,a)},e}_handleEvent(e,t){return t?this._emitter.once(e,t):new Promise((t=>this._emitter.once(e,((...e)=>t(e)))))}_listen(){window.addEventListener("message",(e=>{const{data:t,type:s}=e.data;this._emitter.emit(s,t)}))}_sendMessage(e,t){return null==top?void 0:top.postMessage({data:t,type:e},"*")}authorize(t){return this._sendMessage(e.Authorize,void 0),this._handleEvent(e.Authorize,t)}getSaveData(t){return this._sendMessage(e.GetSaveData,this.options),this._handleEvent(e.GetSaveData,t)}getUsers(t,s){return this._sendMessage(e.GetUsers,t.join(",")),this._handleEvent(e.GetUsers,s)}isAppUser(t,s){return this._sendMessage(e.IsAppUser,t),this._handleEvent(e.IsAppUser,s)}off(e,t){return this._emitter.off(e,t)}on(e,s){this._emitter.on(e,s);return Object.values(t).includes(e)&&this._sendMessage("event",e),()=>this._emitter.off(e,s)}once(e,t){return this._emitter.once(e,t)}sayHello(t){return this._sendMessage(e.SayHello,"And here's Johnny"),this._handleEvent(e.SayHello,t)}showCampaign(t="default",s){return this._sendMessage(e.ShowCampaign,{options:this.options,type:t}),this._handleEvent(e.ShowCampaign,s)}showPayment(t,s){return this._sendMessage(e.ShowPayment,t),this._handleEvent(e.ShowPayment,s)}toggleFullscreen(t){return this._sendMessage(e.ToggleFullscreen,null),this._handleEvent(e.ToggleFullscreen,t)}setSaveData(t,s){return this._sendMessage(e.SetSaveData,{data:t,options:this.options}),this._handleEvent(e.SetSaveData,s)}}export{s as AgRuSdk,t as AgRuSdkEvents,e as AgRuSdkMethods}; | ||
var e=(e=>(e.Authorize="agru-authorize",e.AuthorizeAndWait="agru-authorizeAndWait",e.GetSaveData="agru-getSaveData",e.GetUsers="agru-getUsers",e.IsAppUser="agru-isAppUser",e.SayHello="agru-sayHello",e.ShowCampaign="agru-showCampaign",e.ShowPayment="agru-showPayment",e.SetSaveData="agru-setSaveData",e.ToggleFullscreen="agru-toggleFullscreen",e))(e||{}),t=(e=>(e.OptionsUpdates="agru-optionsUpdates",e))(t||{});class s{constructor(e={}){if(this.options=e,s._instance)return s._instance;for(const[e,t]of new URLSearchParams(location.search).entries())this.options[e]=t;return this.options.auth_key||console.warn('You need to pass the "auth_key" in options, to be able to use the SDK.'),s._instance=this,s._instance._emitter=this._createEmitter(),s._instance.options=e,this._listen(),this}_createEmitter(){const e={all:t=t||new Map,on:function(e,s){var n=t.get(e);n?n.push(s):t.set(e,[s])},off:function(e,s){var n=t.get(e);n&&(s?n.splice(n.indexOf(s)>>>0,1):t.set(e,[]))},emit:function(e,s){var n=t.get(e);n&&n.slice().map((function(e){e(s)})),(n=t.get("*"))&&n.slice().map((function(t){t(e,s)}))}};var t;const s=e.on;return e.on=(e,t)=>{"function"==typeof t&&s(e,(e=>t.call(null,...e)))},e.once=(t,n)=>{const a=(...s)=>{e.off(t,a),"function"==typeof n&&n.call(null,...s)};s(t,a)},e}_handleEvent(e,t){return t?this._emitter.once(e,t):new Promise((t=>this._emitter.once(e,((...e)=>t(e)))))}_listen(){window.addEventListener("message",(e=>{const{data:t,type:s}=e.data;this._emitter.emit(s,t)}))}_sendMessage(e,t){return null==top?void 0:top.postMessage({data:t,type:e},"*")}authorize(t){return this._sendMessage(e.Authorize,void 0),this._handleEvent(e.Authorize,t)}authorizeAndWait(t){return this._sendMessage(e.AuthorizeAndWait,void 0),this._handleEvent(e.AuthorizeAndWait,t)}getSaveData(t){return this._sendMessage(e.GetSaveData,this.options),this._handleEvent(e.GetSaveData,t)}getUsers(t,s){return this._sendMessage(e.GetUsers,t.join(",")),this._handleEvent(e.GetUsers,s)}isAppUser(t,s){return this._sendMessage(e.IsAppUser,t),this._handleEvent(e.IsAppUser,s)}off(e,t){return this._emitter.off(e,t)}on(e,s){this._emitter.on(e,s);return Object.values(t).includes(e)&&this._sendMessage("event",e),()=>this._emitter.off(e,s)}once(e,t){return this._emitter.once(e,t)}sayHello(t){return this._sendMessage(e.SayHello,"And here's Johnny"),this._handleEvent(e.SayHello,t)}showCampaign(t="default",s){return this._sendMessage(e.ShowCampaign,{options:this.options,type:t}),this._handleEvent(e.ShowCampaign,s)}showPayment(t,s){return this._sendMessage(e.ShowPayment,t),this._handleEvent(e.ShowPayment,s)}toggleFullscreen(t){return this._sendMessage(e.ToggleFullscreen,null),this._handleEvent(e.ToggleFullscreen,t)}setSaveData(t,s){return this._sendMessage(e.SetSaveData,{data:t,options:this.options}),this._handleEvent(e.SetSaveData,s)}}export{s as AgRuSdk,t as AgRuSdkEvents,e as AgRuSdkMethods}; |
@@ -5,2 +5,3 @@ import { Emitter } from 'mitt'; | ||
Authorize = "agru-authorize", | ||
AuthorizeAndWait = "agru-authorizeAndWait", | ||
GetSaveData = "agru-getSaveData", | ||
@@ -29,2 +30,3 @@ GetUsers = "agru-getUsers", | ||
[AgRuSdkMethods.Authorize]: string; | ||
[AgRuSdkMethods.AuthorizeAndWait]: string; | ||
[AgRuSdkMethods.GetSaveData]: Record<string, unknown>; | ||
@@ -55,2 +57,3 @@ [AgRuSdkMethods.GetUsers]: string; | ||
[AgRuSdkMethods.Authorize]: boolean; | ||
[AgRuSdkMethods.AuthorizeAndWait]: boolean; | ||
[AgRuSdkMethods.GetSaveData]: Record<string, any>; | ||
@@ -79,3 +82,6 @@ [AgRuSdkMethods.GetUsers]: AgRuUser[]; | ||
}; | ||
declare type AgRuCallback<T extends keyof AgRuSdkResponse> = (data: AgRuSdkResponse[T], error: Error | null) => void; | ||
declare type AgRuCallback<T extends keyof AgRuSdkResponse> = ([data, error]: [ | ||
data: AgRuSdkResponse[T], | ||
error: Error | null | ||
]) => void; | ||
declare type AgRuPromise<T extends keyof AgRuSdkResponse> = Promise<[ | ||
@@ -131,2 +137,7 @@ AgRuSdkResponse[T], | ||
/** | ||
* Show the authorization and wait for user to authorize. | ||
*/ | ||
authorizeAndWait(): AgRuPromise<AgRuSdkMethods.Authorize>; | ||
authorizeAndWait(callback: AgRuCallback<AgRuSdkMethods.Authorize>): void; | ||
/** | ||
* Returns player saved data from the server. | ||
@@ -153,3 +164,3 @@ */ | ||
*/ | ||
off<T extends AgRuSdkMethods | AgRuSdkEvents>(type: T, handler: AgRuCallback<T>): void; | ||
off<T extends AgRuSdkMethods | AgRuSdkEvents, D = Parameters<AgRuCallback<T>>[0][0], E = Parameters<AgRuCallback<T>>[0][1]>(type: T, handler: (data: D, error: E) => unknown): void; | ||
/** | ||
@@ -160,3 +171,3 @@ * Listen for the event. | ||
*/ | ||
on<T extends AgRuSdkMethods | AgRuSdkEvents>(type: T, handler: AgRuCallback<T>): () => void; | ||
on<T extends AgRuSdkMethods | AgRuSdkEvents, D = Parameters<AgRuCallback<T>>[0][0], E = Parameters<AgRuCallback<T>>[0][1]>(type: T, handler: (data: D, error: E) => unknown): () => void; | ||
/** | ||
@@ -167,3 +178,3 @@ * Listen for the event only once. | ||
*/ | ||
once<T extends AgRuSdkMethods | AgRuSdkEvents>(type: T, handler: AgRuCallback<T>): void; | ||
once<T extends AgRuSdkMethods | AgRuSdkEvents, D = Parameters<AgRuCallback<T>>[0][0], E = Parameters<AgRuCallback<T>>[0][1]>(type: T, handler: (data: D, error: E) => unknown): void; | ||
/** | ||
@@ -170,0 +181,0 @@ * Returns a message from the origin. Only for setup purposes. |
@@ -7,2 +7,3 @@ 'use strict'; | ||
AgRuSdkMethods2["Authorize"] = "agru-authorize"; | ||
AgRuSdkMethods2["AuthorizeAndWait"] = "agru-authorizeAndWait"; | ||
AgRuSdkMethods2["GetSaveData"] = "agru-getSaveData"; | ||
@@ -55,3 +56,3 @@ AgRuSdkMethods2["GetUsers"] = "agru-getUsers"; | ||
if (typeof handler === "function") { | ||
handler.apply(null, ...args); | ||
handler.call(null, ...args); | ||
} | ||
@@ -82,2 +83,6 @@ }; | ||
} | ||
authorizeAndWait(callback) { | ||
this._sendMessage(AgRuSdkMethods.AuthorizeAndWait, void 0); | ||
return this._handleEvent(AgRuSdkMethods.AuthorizeAndWait, callback); | ||
} | ||
getSaveData(callback) { | ||
@@ -84,0 +89,0 @@ this._sendMessage(AgRuSdkMethods.GetSaveData, this.options); |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=(e=>(e.Authorize="agru-authorize",e.GetSaveData="agru-getSaveData",e.GetUsers="agru-getUsers",e.IsAppUser="agru-isAppUser",e.SayHello="agru-sayHello",e.ShowCampaign="agru-showCampaign",e.ShowPayment="agru-showPayment",e.SetSaveData="agru-setSaveData",e.ToggleFullscreen="agru-toggleFullscreen",e))(e||{}),t=(e=>(e.OptionsUpdates="agru-optionsUpdates",e))(t||{});class s{constructor(e={}){if(this.options=e,s._instance)return s._instance;for(const[e,t]of new URLSearchParams(location.search).entries())this.options[e]=t;return this.options.auth_key||console.warn('You need to pass the "auth_key" in options, to be able to use the SDK.'),s._instance=this,s._instance._emitter=this._createEmitter(),s._instance.options=e,this._listen(),this}_createEmitter(){const e={all:t=t||new Map,on:function(e,s){var n=t.get(e);n?n.push(s):t.set(e,[s])},off:function(e,s){var n=t.get(e);n&&(s?n.splice(n.indexOf(s)>>>0,1):t.set(e,[]))},emit:function(e,s){var n=t.get(e);n&&n.slice().map((function(e){e(s)})),(n=t.get("*"))&&n.slice().map((function(t){t(e,s)}))}};var t;const s=e.on;return e.on=(e,t)=>{"function"==typeof t&&s(e,(e=>t.call(null,...e)))},e.once=(t,n)=>{const a=(...s)=>{e.off(t,a),"function"==typeof n&&n.apply(null,...s)};s(t,a)},e}_handleEvent(e,t){return t?this._emitter.once(e,t):new Promise((t=>this._emitter.once(e,((...e)=>t(e)))))}_listen(){window.addEventListener("message",(e=>{const{data:t,type:s}=e.data;this._emitter.emit(s,t)}))}_sendMessage(e,t){return null==top?void 0:top.postMessage({data:t,type:e},"*")}authorize(t){return this._sendMessage(e.Authorize,void 0),this._handleEvent(e.Authorize,t)}getSaveData(t){return this._sendMessage(e.GetSaveData,this.options),this._handleEvent(e.GetSaveData,t)}getUsers(t,s){return this._sendMessage(e.GetUsers,t.join(",")),this._handleEvent(e.GetUsers,s)}isAppUser(t,s){return this._sendMessage(e.IsAppUser,t),this._handleEvent(e.IsAppUser,s)}off(e,t){return this._emitter.off(e,t)}on(e,s){this._emitter.on(e,s);return Object.values(t).includes(e)&&this._sendMessage("event",e),()=>this._emitter.off(e,s)}once(e,t){return this._emitter.once(e,t)}sayHello(t){return this._sendMessage(e.SayHello,"And here's Johnny"),this._handleEvent(e.SayHello,t)}showCampaign(t="default",s){return this._sendMessage(e.ShowCampaign,{options:this.options,type:t}),this._handleEvent(e.ShowCampaign,s)}showPayment(t,s){return this._sendMessage(e.ShowPayment,t),this._handleEvent(e.ShowPayment,s)}toggleFullscreen(t){return this._sendMessage(e.ToggleFullscreen,null),this._handleEvent(e.ToggleFullscreen,t)}setSaveData(t,s){return this._sendMessage(e.SetSaveData,{data:t,options:this.options}),this._handleEvent(e.SetSaveData,s)}}exports.AgRuSdk=s,exports.AgRuSdkEvents=t,exports.AgRuSdkMethods=e; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=(e=>(e.Authorize="agru-authorize",e.AuthorizeAndWait="agru-authorizeAndWait",e.GetSaveData="agru-getSaveData",e.GetUsers="agru-getUsers",e.IsAppUser="agru-isAppUser",e.SayHello="agru-sayHello",e.ShowCampaign="agru-showCampaign",e.ShowPayment="agru-showPayment",e.SetSaveData="agru-setSaveData",e.ToggleFullscreen="agru-toggleFullscreen",e))(e||{}),t=(e=>(e.OptionsUpdates="agru-optionsUpdates",e))(t||{});class s{constructor(e={}){if(this.options=e,s._instance)return s._instance;for(const[e,t]of new URLSearchParams(location.search).entries())this.options[e]=t;return this.options.auth_key||console.warn('You need to pass the "auth_key" in options, to be able to use the SDK.'),s._instance=this,s._instance._emitter=this._createEmitter(),s._instance.options=e,this._listen(),this}_createEmitter(){const e={all:t=t||new Map,on:function(e,s){var n=t.get(e);n?n.push(s):t.set(e,[s])},off:function(e,s){var n=t.get(e);n&&(s?n.splice(n.indexOf(s)>>>0,1):t.set(e,[]))},emit:function(e,s){var n=t.get(e);n&&n.slice().map((function(e){e(s)})),(n=t.get("*"))&&n.slice().map((function(t){t(e,s)}))}};var t;const s=e.on;return e.on=(e,t)=>{"function"==typeof t&&s(e,(e=>t.call(null,...e)))},e.once=(t,n)=>{const a=(...s)=>{e.off(t,a),"function"==typeof n&&n.call(null,...s)};s(t,a)},e}_handleEvent(e,t){return t?this._emitter.once(e,t):new Promise((t=>this._emitter.once(e,((...e)=>t(e)))))}_listen(){window.addEventListener("message",(e=>{const{data:t,type:s}=e.data;this._emitter.emit(s,t)}))}_sendMessage(e,t){return null==top?void 0:top.postMessage({data:t,type:e},"*")}authorize(t){return this._sendMessage(e.Authorize,void 0),this._handleEvent(e.Authorize,t)}authorizeAndWait(t){return this._sendMessage(e.AuthorizeAndWait,void 0),this._handleEvent(e.AuthorizeAndWait,t)}getSaveData(t){return this._sendMessage(e.GetSaveData,this.options),this._handleEvent(e.GetSaveData,t)}getUsers(t,s){return this._sendMessage(e.GetUsers,t.join(",")),this._handleEvent(e.GetUsers,s)}isAppUser(t,s){return this._sendMessage(e.IsAppUser,t),this._handleEvent(e.IsAppUser,s)}off(e,t){return this._emitter.off(e,t)}on(e,s){this._emitter.on(e,s);return Object.values(t).includes(e)&&this._sendMessage("event",e),()=>this._emitter.off(e,s)}once(e,t){return this._emitter.once(e,t)}sayHello(t){return this._sendMessage(e.SayHello,"And here's Johnny"),this._handleEvent(e.SayHello,t)}showCampaign(t="default",s){return this._sendMessage(e.ShowCampaign,{options:this.options,type:t}),this._handleEvent(e.ShowCampaign,s)}showPayment(t,s){return this._sendMessage(e.ShowPayment,t),this._handleEvent(e.ShowPayment,s)}toggleFullscreen(t){return this._sendMessage(e.ToggleFullscreen,null),this._handleEvent(e.ToggleFullscreen,t)}setSaveData(t,s){return this._sendMessage(e.SetSaveData,{data:t,options:this.options}),this._handleEvent(e.SetSaveData,s)}}exports.AgRuSdk=s,exports.AgRuSdkEvents=t,exports.AgRuSdkMethods=e; |
@@ -9,2 +9,3 @@ (function (global, factory) { | ||
AgRuSdkMethods2["Authorize"] = "agru-authorize"; | ||
AgRuSdkMethods2["AuthorizeAndWait"] = "agru-authorizeAndWait"; | ||
AgRuSdkMethods2["GetSaveData"] = "agru-getSaveData"; | ||
@@ -57,3 +58,3 @@ AgRuSdkMethods2["GetUsers"] = "agru-getUsers"; | ||
if (typeof handler === "function") { | ||
handler.apply(null, ...args); | ||
handler.call(null, ...args); | ||
} | ||
@@ -84,2 +85,6 @@ }; | ||
} | ||
authorizeAndWait(callback) { | ||
this._sendMessage(AgRuSdkMethods.AuthorizeAndWait, void 0); | ||
return this._handleEvent(AgRuSdkMethods.AuthorizeAndWait, callback); | ||
} | ||
getSaveData(callback) { | ||
@@ -86,0 +91,0 @@ this._sendMessage(AgRuSdkMethods.GetSaveData, this.options); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).agru={})}(this,(function(e){"use strict";var t=(e=>(e.Authorize="agru-authorize",e.GetSaveData="agru-getSaveData",e.GetUsers="agru-getUsers",e.IsAppUser="agru-isAppUser",e.SayHello="agru-sayHello",e.ShowCampaign="agru-showCampaign",e.ShowPayment="agru-showPayment",e.SetSaveData="agru-setSaveData",e.ToggleFullscreen="agru-toggleFullscreen",e))(t||{}),s=(e=>(e.OptionsUpdates="agru-optionsUpdates",e))(s||{});class n{constructor(e={}){if(this.options=e,n._instance)return n._instance;for(const[e,t]of new URLSearchParams(location.search).entries())this.options[e]=t;return this.options.auth_key||console.warn('You need to pass the "auth_key" in options, to be able to use the SDK.'),n._instance=this,n._instance._emitter=this._createEmitter(),n._instance.options=e,this._listen(),this}_createEmitter(){const e={all:t=t||new Map,on:function(e,s){var n=t.get(e);n?n.push(s):t.set(e,[s])},off:function(e,s){var n=t.get(e);n&&(s?n.splice(n.indexOf(s)>>>0,1):t.set(e,[]))},emit:function(e,s){var n=t.get(e);n&&n.slice().map((function(e){e(s)})),(n=t.get("*"))&&n.slice().map((function(t){t(e,s)}))}};var t;const s=e.on;return e.on=(e,t)=>{"function"==typeof t&&s(e,(e=>t.call(null,...e)))},e.once=(t,n)=>{const a=(...s)=>{e.off(t,a),"function"==typeof n&&n.apply(null,...s)};s(t,a)},e}_handleEvent(e,t){return t?this._emitter.once(e,t):new Promise((t=>this._emitter.once(e,((...e)=>t(e)))))}_listen(){window.addEventListener("message",(e=>{const{data:t,type:s}=e.data;this._emitter.emit(s,t)}))}_sendMessage(e,t){return null==top?void 0:top.postMessage({data:t,type:e},"*")}authorize(e){return this._sendMessage(t.Authorize,void 0),this._handleEvent(t.Authorize,e)}getSaveData(e){return this._sendMessage(t.GetSaveData,this.options),this._handleEvent(t.GetSaveData,e)}getUsers(e,s){return this._sendMessage(t.GetUsers,e.join(",")),this._handleEvent(t.GetUsers,s)}isAppUser(e,s){return this._sendMessage(t.IsAppUser,e),this._handleEvent(t.IsAppUser,s)}off(e,t){return this._emitter.off(e,t)}on(e,t){this._emitter.on(e,t);return Object.values(s).includes(e)&&this._sendMessage("event",e),()=>this._emitter.off(e,t)}once(e,t){return this._emitter.once(e,t)}sayHello(e){return this._sendMessage(t.SayHello,"And here's Johnny"),this._handleEvent(t.SayHello,e)}showCampaign(e="default",s){return this._sendMessage(t.ShowCampaign,{options:this.options,type:e}),this._handleEvent(t.ShowCampaign,s)}showPayment(e,s){return this._sendMessage(t.ShowPayment,e),this._handleEvent(t.ShowPayment,s)}toggleFullscreen(e){return this._sendMessage(t.ToggleFullscreen,null),this._handleEvent(t.ToggleFullscreen,e)}setSaveData(e,s){return this._sendMessage(t.SetSaveData,{data:e,options:this.options}),this._handleEvent(t.SetSaveData,s)}}e.AgRuSdk=n,e.AgRuSdkEvents=s,e.AgRuSdkMethods=t,Object.defineProperty(e,"__esModule",{value:!0}),window.AgRuSdk=agru.AgRuSdk,window.AgRuSdkMethods=agru.AgRuSdkMethods,window.AgRuSdkEvents=agru.AgRuSdkEvents})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).agru={})}(this,(function(e){"use strict";var t=(e=>(e.Authorize="agru-authorize",e.AuthorizeAndWait="agru-authorizeAndWait",e.GetSaveData="agru-getSaveData",e.GetUsers="agru-getUsers",e.IsAppUser="agru-isAppUser",e.SayHello="agru-sayHello",e.ShowCampaign="agru-showCampaign",e.ShowPayment="agru-showPayment",e.SetSaveData="agru-setSaveData",e.ToggleFullscreen="agru-toggleFullscreen",e))(t||{}),s=(e=>(e.OptionsUpdates="agru-optionsUpdates",e))(s||{});class n{constructor(e={}){if(this.options=e,n._instance)return n._instance;for(const[e,t]of new URLSearchParams(location.search).entries())this.options[e]=t;return this.options.auth_key||console.warn('You need to pass the "auth_key" in options, to be able to use the SDK.'),n._instance=this,n._instance._emitter=this._createEmitter(),n._instance.options=e,this._listen(),this}_createEmitter(){const e={all:t=t||new Map,on:function(e,s){var n=t.get(e);n?n.push(s):t.set(e,[s])},off:function(e,s){var n=t.get(e);n&&(s?n.splice(n.indexOf(s)>>>0,1):t.set(e,[]))},emit:function(e,s){var n=t.get(e);n&&n.slice().map((function(e){e(s)})),(n=t.get("*"))&&n.slice().map((function(t){t(e,s)}))}};var t;const s=e.on;return e.on=(e,t)=>{"function"==typeof t&&s(e,(e=>t.call(null,...e)))},e.once=(t,n)=>{const a=(...s)=>{e.off(t,a),"function"==typeof n&&n.call(null,...s)};s(t,a)},e}_handleEvent(e,t){return t?this._emitter.once(e,t):new Promise((t=>this._emitter.once(e,((...e)=>t(e)))))}_listen(){window.addEventListener("message",(e=>{const{data:t,type:s}=e.data;this._emitter.emit(s,t)}))}_sendMessage(e,t){return null==top?void 0:top.postMessage({data:t,type:e},"*")}authorize(e){return this._sendMessage(t.Authorize,void 0),this._handleEvent(t.Authorize,e)}authorizeAndWait(e){return this._sendMessage(t.AuthorizeAndWait,void 0),this._handleEvent(t.AuthorizeAndWait,e)}getSaveData(e){return this._sendMessage(t.GetSaveData,this.options),this._handleEvent(t.GetSaveData,e)}getUsers(e,s){return this._sendMessage(t.GetUsers,e.join(",")),this._handleEvent(t.GetUsers,s)}isAppUser(e,s){return this._sendMessage(t.IsAppUser,e),this._handleEvent(t.IsAppUser,s)}off(e,t){return this._emitter.off(e,t)}on(e,t){this._emitter.on(e,t);return Object.values(s).includes(e)&&this._sendMessage("event",e),()=>this._emitter.off(e,t)}once(e,t){return this._emitter.once(e,t)}sayHello(e){return this._sendMessage(t.SayHello,"And here's Johnny"),this._handleEvent(t.SayHello,e)}showCampaign(e="default",s){return this._sendMessage(t.ShowCampaign,{options:this.options,type:e}),this._handleEvent(t.ShowCampaign,s)}showPayment(e,s){return this._sendMessage(t.ShowPayment,e),this._handleEvent(t.ShowPayment,s)}toggleFullscreen(e){return this._sendMessage(t.ToggleFullscreen,null),this._handleEvent(t.ToggleFullscreen,e)}setSaveData(e,s){return this._sendMessage(t.SetSaveData,{data:e,options:this.options}),this._handleEvent(t.SetSaveData,s)}}e.AgRuSdk=n,e.AgRuSdkEvents=s,e.AgRuSdkMethods=t,Object.defineProperty(e,"__esModule",{value:!0}),window.AgRuSdk=agru.AgRuSdk,window.AgRuSdkMethods=agru.AgRuSdkMethods,window.AgRuSdkEvents=agru.AgRuSdkEvents})); |
{ | ||
"name": "@agru/sdk", | ||
"version": "1.0.25", | ||
"version": "1.0.26", | ||
"description": "AG RU SDK for the games integration", | ||
@@ -5,0 +5,0 @@ "module": "dist/esm/index.js", |
@@ -88,7 +88,7 @@ [![Bundle Size](https://img.shields.io/bundlephobia/min/@agru/sdk?style=for-the-badge)](https://www.npmjs.com/package/@agru/sdk) | ||
```typescript | ||
const [data, error] = await sdk.authorize(); | ||
const [[data, error]] = await sdk.authorize(); | ||
``` | ||
или | ||
```typescript | ||
sdk.authorize((data, error) => { | ||
sdk.authorize(([data, error]) => { | ||
// ... | ||
@@ -103,2 +103,20 @@ }); | ||
### `authorizeAndWait` | ||
Вызвать диалоговое окно авторизации и ждать ответа. | ||
```typescript | ||
const [[data, error]] = await sdk.authorizeAndWait(); | ||
``` | ||
или | ||
```typescript | ||
sdk.authorizeAndWait(([data, error]) => { | ||
// ... | ||
}); | ||
``` | ||
Пример ответа: | ||
```json | ||
true | ||
``` | ||
### `getSaveData` | ||
@@ -108,7 +126,7 @@ Получить игровые данные пользователя с сервера. | ||
```typescript | ||
const [data, error] = await sdk.getSaveData(); | ||
const [[data, error]] = await sdk.getSaveData(); | ||
``` | ||
или | ||
```typescript | ||
sdk.getSaveData((data, error) => { | ||
sdk.getSaveData(([data, error]) => { | ||
// ... | ||
@@ -131,7 +149,7 @@ }); | ||
```typescript | ||
const [data, error] = await sdk.getUsers(['aa6b41ff51004c3890321606db6d4c69', '33c1c11404fcda000000000', '56bc75e2d63100000']); | ||
const [[data, error]] = await sdk.getUsers(['aa6b41ff51004c3890321606db6d4c69', '33c1c11404fcda000000000', '56bc75e2d63100000']); | ||
``` | ||
или | ||
```typescript | ||
sdk.getUsers(['aa6b41ff51004c3890321606db6d4c69', '33c1c11404fcda000000000', '56bc75e2d63100000'], (data, error) => { | ||
sdk.getUsers(['aa6b41ff51004c3890321606db6d4c69', '33c1c11404fcda000000000', '56bc75e2d63100000'], ([data, error]) => { | ||
// ... | ||
@@ -172,7 +190,7 @@ }); | ||
```typescript | ||
const [data, error] = await sdk.isAppUser(1001); | ||
const [[data, error]] = await sdk.isAppUser(1001); | ||
``` | ||
или | ||
```typescript | ||
sdk.isAppUser(1001, (data, error) => { | ||
sdk.isAppUser(1001, ([data, error]) => { | ||
// ... | ||
@@ -190,3 +208,3 @@ }); | ||
Необходимо передать [ключ метода](#методы-sdk) и обработчик. | ||
Необходимо передать [ключ метода](#методы-sdk) или [ключ события](#события-sdk) и обработчик. | ||
@@ -218,3 +236,3 @@ ```typescript | ||
Необходимо передать [ключ метода](#методы-sdk) и обработчик. | ||
Необходимо передать [ключ метода](#методы-sdk) или [ключ события](#события-sdk) и обработчик. | ||
@@ -253,3 +271,3 @@ ```typescript | ||
Необходимо передать [ключ метода](#методы-sdk) и обработчик. | ||
Необходимо передать [ключ метода](#методы-sdk) или [ключ события](#события-sdk) и обработчик. | ||
@@ -274,7 +292,7 @@ ```typescript | ||
```typescript | ||
const [data, error] = await sdk.sayHello(); | ||
const [[data, error]] = await sdk.sayHello(); | ||
``` | ||
или | ||
```typescript | ||
sdk.sayHello((data, error) => { | ||
sdk.sayHello(([data, error]) => { | ||
// ... | ||
@@ -293,7 +311,7 @@ }); | ||
```typescript | ||
const [data, error] = await sdk.showCampaign('default'); | ||
const [[data, error]] = await sdk.showCampaign('default'); | ||
``` | ||
или | ||
```typescript | ||
sdk.showCampaign('default', (data, error) => { | ||
sdk.showCampaign('default', ([data, error]) => { | ||
// ... | ||
@@ -313,7 +331,7 @@ }); | ||
```typescript | ||
const [data, error] = await sdk.showCampaign('rewarded'); | ||
const [[data, error]] = await sdk.showCampaign('rewarded'); | ||
``` | ||
или | ||
```typescript | ||
sdk.showCampaign('rewarded', (data, error) => { | ||
sdk.showCampaign('rewarded', ([data, error]) => { | ||
// ... | ||
@@ -357,7 +375,7 @@ }); | ||
```typescript | ||
const [data, error] = await sdk.showPayment('token'); | ||
const [[data, error]] = await sdk.showPayment('token'); | ||
``` | ||
или | ||
```typescript | ||
sdk.showPayment('token', (data, error) => { | ||
sdk.showPayment('token', ([data, error]) => { | ||
// ... | ||
@@ -414,3 +432,3 @@ }); | ||
```typescript | ||
const [data, error] = await sdk.setSaveData({ | ||
const [[data, error]] = await sdk.setSaveData({ | ||
ключ: 'значение', | ||
@@ -425,3 +443,3 @@ }); | ||
}, | ||
(data, error) => { | ||
([data, error]) => { | ||
// ... | ||
@@ -481,5 +499,5 @@ } | ||
// Если ID поменялся, получаем новые данные и обновляем. | ||
const [data] = await sdk.getUsers([sdk.options.player_id]); | ||
const [[data]] = await sdk.getUsers([sdk.options.player_id]); | ||
state.user = data[0]; | ||
}); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44337
652
489