Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@agru/sdk

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agru/sdk - npm Package Compare versions

Comparing version 1.0.16 to 1.0.17

7

dist/esm/index.js

@@ -8,2 +8,3 @@ var AgRuSdkMethods = /* @__PURE__ */ ((AgRuSdkMethods2) => {

AgRuSdkMethods2["ShowCampaign"] = "agru-showCampaign";
AgRuSdkMethods2["ShowPayment"] = "agru-showPayment";
AgRuSdkMethods2["SetSaveData"] = "agru-setSaveData";

@@ -145,2 +146,8 @@ return AgRuSdkMethods2;

}
showPayment(paymentToken, callback) {
this._sendMessage(AgRuSdkMethods.ShowPayment, paymentToken, () => {
this._emitter.emit(AgRuSdkMethods.ShowPayment, [null, null]);
});
return this._handleEvent(AgRuSdkMethods.ShowPayment, callback);
}
setSaveData(data, callback) {

@@ -147,0 +154,0 @@ this._sendMessage(

2

dist/esm/index.min.js

@@ -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.SetSaveData="agru-setSaveData",e))(e||{});class t{constructor(e={}){if(this.options=e,t._instance)return t._instance;for(const[e,t]of new URLSearchParams(location.search).entries())this.options[e]=t;return e.debug?console.info("SDK is running in DEBUG mode!"):this.options.auth_key||console.warn('You need to pass the "auth_key" in options, to be able to use the SDK.'),t._instance=this,t._instance._emitter=this._createEmitter(),t._instance.options=e,this._listen(),this}_createEmitter(){const e={all:t=t||new Map,on:function(e,s){var a=t.get(e);a?a.push(s):t.set(e,[s])},off:function(e,s){var a=t.get(e);a&&(s?a.splice(a.indexOf(s)>>>0,1):t.set(e,[]))},emit:function(e,s){var a=t.get(e);a&&a.slice().map((function(e){e(s)})),(a=t.get("*"))&&a.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,a)=>{const n=(...s)=>{e.off(t,n),"function"==typeof a&&a.apply(null,...s)};s(t,n)},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,s){return this.options.debug?setTimeout(s):null==top?void 0:top.postMessage({data:t,type:e},"*")}authorize(t){return this._sendMessage(e.Authorize,void 0,(()=>{this._emitter.emit(e.Authorize,[!0,null])})),this._handleEvent(e.Authorize,t)}getSaveData(t){return this._sendMessage(e.GetSaveData,this.options,(()=>{this._emitter.emit(e.GetSaveData,[{a:!0,b:!1,c:1},null])})),this._handleEvent(e.GetSaveData,t)}getUsers(t,s){return this._sendMessage(e.GetUsers,t,(()=>{this._emitter.emit(e.GetUsers,[t.map((e=>({avatar:`https://api.lorem.space/image/face?w=150&h=150&hash=${e}`,id:e,name:Math.random().toString(16).substring(2)}))),null])})),this._handleEvent(e.GetUsers,s)}isAppUser(t,s){return this._sendMessage(e.IsAppUser,t,(()=>{this._emitter.emit(e.IsAppUser,[!0,null])})),this._handleEvent(e.IsAppUser,s)}on(e,t){return this._emitter.on(e,t)}once(e,t){return this._emitter.once(e,t)}sayHello(t){const s="And here's Johnny";return this._sendMessage(e.SayHello,s,(()=>{this._emitter.emit(e.SayHello,[s,null])})),this._handleEvent(e.SayHello,t)}showCampaign(t="default",s){return this._sendMessage(e.ShowCampaign,{options:this.options,type:t},(()=>{this._emitter.emit(e.ShowCampaign,[{reward:"rewarded"===t,type:t,status:!0},null])})),this._handleEvent(e.ShowCampaign,s)}setSaveData(t,s){return this._sendMessage(e.SetSaveData,{data:t,options:this.options},(()=>{this._emitter.emit(e.SetSaveData,[!0,null])})),this._handleEvent(e.SetSaveData,s)}}export{t as AgRuSdk,e as AgRuSdkMethods};
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))(e||{});class t{constructor(e={}){if(this.options=e,t._instance)return t._instance;for(const[e,t]of new URLSearchParams(location.search).entries())this.options[e]=t;return e.debug?console.info("SDK is running in DEBUG mode!"):this.options.auth_key||console.warn('You need to pass the "auth_key" in options, to be able to use the SDK.'),t._instance=this,t._instance._emitter=this._createEmitter(),t._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,s){return this.options.debug?setTimeout(s):null==top?void 0:top.postMessage({data:t,type:e},"*")}authorize(t){return this._sendMessage(e.Authorize,void 0,(()=>{this._emitter.emit(e.Authorize,[!0,null])})),this._handleEvent(e.Authorize,t)}getSaveData(t){return this._sendMessage(e.GetSaveData,this.options,(()=>{this._emitter.emit(e.GetSaveData,[{a:!0,b:!1,c:1},null])})),this._handleEvent(e.GetSaveData,t)}getUsers(t,s){return this._sendMessage(e.GetUsers,t,(()=>{this._emitter.emit(e.GetUsers,[t.map((e=>({avatar:`https://api.lorem.space/image/face?w=150&h=150&hash=${e}`,id:e,name:Math.random().toString(16).substring(2)}))),null])})),this._handleEvent(e.GetUsers,s)}isAppUser(t,s){return this._sendMessage(e.IsAppUser,t,(()=>{this._emitter.emit(e.IsAppUser,[!0,null])})),this._handleEvent(e.IsAppUser,s)}on(e,t){return this._emitter.on(e,t)}once(e,t){return this._emitter.once(e,t)}sayHello(t){const s="And here's Johnny";return this._sendMessage(e.SayHello,s,(()=>{this._emitter.emit(e.SayHello,[s,null])})),this._handleEvent(e.SayHello,t)}showCampaign(t="default",s){return this._sendMessage(e.ShowCampaign,{options:this.options,type:t},(()=>{this._emitter.emit(e.ShowCampaign,[{reward:"rewarded"===t,type:t,status:!0},null])})),this._handleEvent(e.ShowCampaign,s)}showPayment(t,s){return this._sendMessage(e.ShowPayment,t,(()=>{this._emitter.emit(e.ShowPayment,[null,null])})),this._handleEvent(e.ShowPayment,s)}setSaveData(t,s){return this._sendMessage(e.SetSaveData,{data:t,options:this.options},(()=>{this._emitter.emit(e.SetSaveData,[!0,null])})),this._handleEvent(e.SetSaveData,s)}}export{t as AgRuSdk,e as AgRuSdkMethods};

@@ -10,2 +10,3 @@ import { Emitter } from 'mitt';

ShowCampaign = "agru-showCampaign",
ShowPayment = "agru-showPayment",
SetSaveData = "agru-setSaveData"

@@ -30,2 +31,3 @@ }

};
[AgRuSdkMethods.ShowPayment]: string;
[AgRuSdkMethods.SetSaveData]: {

@@ -52,2 +54,13 @@ data: Record<string, unknown>;

};
[AgRuSdkMethods.ShowPayment]: {
info: Partial<{
discount: string;
email: string;
invoice: number;
status: 'delivering' | 'done' | 'invoice' | 'troubled';
userId: string;
virtualCurrencyAmount: number;
}> | null;
status: boolean;
};
[AgRuSdkMethods.SetSaveData]: boolean;

@@ -142,2 +155,6 @@ };

/**
* Show payment modal.
*/
showPayment(paymentToken: string, callback?: AgRuCallback<AgRuSdkMethods.ShowPayment>): void | AgRuPromise<AgRuSdkMethods.ShowPayment>;
/**
* Save user data on the server.

@@ -144,0 +161,0 @@ * @param data Valid object.

@@ -12,2 +12,3 @@ 'use strict';

AgRuSdkMethods2["ShowCampaign"] = "agru-showCampaign";
AgRuSdkMethods2["ShowPayment"] = "agru-showPayment";
AgRuSdkMethods2["SetSaveData"] = "agru-setSaveData";

@@ -149,2 +150,8 @@ return AgRuSdkMethods2;

}
showPayment(paymentToken, callback) {
this._sendMessage(AgRuSdkMethods.ShowPayment, paymentToken, () => {
this._emitter.emit(AgRuSdkMethods.ShowPayment, [null, null]);
});
return this._handleEvent(AgRuSdkMethods.ShowPayment, callback);
}
setSaveData(data, callback) {

@@ -151,0 +158,0 @@ this._sendMessage(

@@ -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.SetSaveData="agru-setSaveData",e))(e||{});class t{constructor(e={}){if(this.options=e,t._instance)return t._instance;for(const[e,t]of new URLSearchParams(location.search).entries())this.options[e]=t;return e.debug?console.info("SDK is running in DEBUG mode!"):this.options.auth_key||console.warn('You need to pass the "auth_key" in options, to be able to use the SDK.'),t._instance=this,t._instance._emitter=this._createEmitter(),t._instance.options=e,this._listen(),this}_createEmitter(){const e={all:t=t||new Map,on:function(e,s){var a=t.get(e);a?a.push(s):t.set(e,[s])},off:function(e,s){var a=t.get(e);a&&(s?a.splice(a.indexOf(s)>>>0,1):t.set(e,[]))},emit:function(e,s){var a=t.get(e);a&&a.slice().map((function(e){e(s)})),(a=t.get("*"))&&a.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,a)=>{const n=(...s)=>{e.off(t,n),"function"==typeof a&&a.apply(null,...s)};s(t,n)},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,s){return this.options.debug?setTimeout(s):null==top?void 0:top.postMessage({data:t,type:e},"*")}authorize(t){return this._sendMessage(e.Authorize,void 0,(()=>{this._emitter.emit(e.Authorize,[!0,null])})),this._handleEvent(e.Authorize,t)}getSaveData(t){return this._sendMessage(e.GetSaveData,this.options,(()=>{this._emitter.emit(e.GetSaveData,[{a:!0,b:!1,c:1},null])})),this._handleEvent(e.GetSaveData,t)}getUsers(t,s){return this._sendMessage(e.GetUsers,t,(()=>{this._emitter.emit(e.GetUsers,[t.map((e=>({avatar:`https://api.lorem.space/image/face?w=150&h=150&hash=${e}`,id:e,name:Math.random().toString(16).substring(2)}))),null])})),this._handleEvent(e.GetUsers,s)}isAppUser(t,s){return this._sendMessage(e.IsAppUser,t,(()=>{this._emitter.emit(e.IsAppUser,[!0,null])})),this._handleEvent(e.IsAppUser,s)}on(e,t){return this._emitter.on(e,t)}once(e,t){return this._emitter.once(e,t)}sayHello(t){const s="And here's Johnny";return this._sendMessage(e.SayHello,s,(()=>{this._emitter.emit(e.SayHello,[s,null])})),this._handleEvent(e.SayHello,t)}showCampaign(t="default",s){return this._sendMessage(e.ShowCampaign,{options:this.options,type:t},(()=>{this._emitter.emit(e.ShowCampaign,[{reward:"rewarded"===t,type:t,status:!0},null])})),this._handleEvent(e.ShowCampaign,s)}setSaveData(t,s){return this._sendMessage(e.SetSaveData,{data:t,options:this.options},(()=>{this._emitter.emit(e.SetSaveData,[!0,null])})),this._handleEvent(e.SetSaveData,s)}}exports.AgRuSdk=t,exports.AgRuSdkMethods=e;
"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))(e||{});class t{constructor(e={}){if(this.options=e,t._instance)return t._instance;for(const[e,t]of new URLSearchParams(location.search).entries())this.options[e]=t;return e.debug?console.info("SDK is running in DEBUG mode!"):this.options.auth_key||console.warn('You need to pass the "auth_key" in options, to be able to use the SDK.'),t._instance=this,t._instance._emitter=this._createEmitter(),t._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,s){return this.options.debug?setTimeout(s):null==top?void 0:top.postMessage({data:t,type:e},"*")}authorize(t){return this._sendMessage(e.Authorize,void 0,(()=>{this._emitter.emit(e.Authorize,[!0,null])})),this._handleEvent(e.Authorize,t)}getSaveData(t){return this._sendMessage(e.GetSaveData,this.options,(()=>{this._emitter.emit(e.GetSaveData,[{a:!0,b:!1,c:1},null])})),this._handleEvent(e.GetSaveData,t)}getUsers(t,s){return this._sendMessage(e.GetUsers,t,(()=>{this._emitter.emit(e.GetUsers,[t.map((e=>({avatar:`https://api.lorem.space/image/face?w=150&h=150&hash=${e}`,id:e,name:Math.random().toString(16).substring(2)}))),null])})),this._handleEvent(e.GetUsers,s)}isAppUser(t,s){return this._sendMessage(e.IsAppUser,t,(()=>{this._emitter.emit(e.IsAppUser,[!0,null])})),this._handleEvent(e.IsAppUser,s)}on(e,t){return this._emitter.on(e,t)}once(e,t){return this._emitter.once(e,t)}sayHello(t){const s="And here's Johnny";return this._sendMessage(e.SayHello,s,(()=>{this._emitter.emit(e.SayHello,[s,null])})),this._handleEvent(e.SayHello,t)}showCampaign(t="default",s){return this._sendMessage(e.ShowCampaign,{options:this.options,type:t},(()=>{this._emitter.emit(e.ShowCampaign,[{reward:"rewarded"===t,type:t,status:!0},null])})),this._handleEvent(e.ShowCampaign,s)}showPayment(t,s){return this._sendMessage(e.ShowPayment,t,(()=>{this._emitter.emit(e.ShowPayment,[null,null])})),this._handleEvent(e.ShowPayment,s)}setSaveData(t,s){return this._sendMessage(e.SetSaveData,{data:t,options:this.options},(()=>{this._emitter.emit(e.SetSaveData,[!0,null])})),this._handleEvent(e.SetSaveData,s)}}exports.AgRuSdk=t,exports.AgRuSdkMethods=e;

@@ -14,2 +14,3 @@ (function (global, factory) {

AgRuSdkMethods2["ShowCampaign"] = "agru-showCampaign";
AgRuSdkMethods2["ShowPayment"] = "agru-showPayment";
AgRuSdkMethods2["SetSaveData"] = "agru-setSaveData";

@@ -151,2 +152,8 @@ return AgRuSdkMethods2;

}
showPayment(paymentToken, callback) {
this._sendMessage(AgRuSdkMethods.ShowPayment, paymentToken, () => {
this._emitter.emit(AgRuSdkMethods.ShowPayment, [null, null]);
});
return this._handleEvent(AgRuSdkMethods.ShowPayment, callback);
}
setSaveData(data, callback) {

@@ -153,0 +160,0 @@ this._sendMessage(

@@ -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.SetSaveData="agru-setSaveData",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 e.debug?console.info("SDK is running in DEBUG mode!"):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,s){return this.options.debug?setTimeout(s):null==top?void 0:top.postMessage({data:t,type:e},"*")}authorize(e){return this._sendMessage(t.Authorize,void 0,(()=>{this._emitter.emit(t.Authorize,[!0,null])})),this._handleEvent(t.Authorize,e)}getSaveData(e){return this._sendMessage(t.GetSaveData,this.options,(()=>{this._emitter.emit(t.GetSaveData,[{a:!0,b:!1,c:1},null])})),this._handleEvent(t.GetSaveData,e)}getUsers(e,s){return this._sendMessage(t.GetUsers,e,(()=>{this._emitter.emit(t.GetUsers,[e.map((e=>({avatar:`https://api.lorem.space/image/face?w=150&h=150&hash=${e}`,id:e,name:Math.random().toString(16).substring(2)}))),null])})),this._handleEvent(t.GetUsers,s)}isAppUser(e,s){return this._sendMessage(t.IsAppUser,e,(()=>{this._emitter.emit(t.IsAppUser,[!0,null])})),this._handleEvent(t.IsAppUser,s)}on(e,t){return this._emitter.on(e,t)}once(e,t){return this._emitter.once(e,t)}sayHello(e){const s="And here's Johnny";return this._sendMessage(t.SayHello,s,(()=>{this._emitter.emit(t.SayHello,[s,null])})),this._handleEvent(t.SayHello,e)}showCampaign(e="default",s){return this._sendMessage(t.ShowCampaign,{options:this.options,type:e},(()=>{this._emitter.emit(t.ShowCampaign,[{reward:"rewarded"===e,type:e,status:!0},null])})),this._handleEvent(t.ShowCampaign,s)}setSaveData(e,s){return this._sendMessage(t.SetSaveData,{data:e,options:this.options},(()=>{this._emitter.emit(t.SetSaveData,[!0,null])})),this._handleEvent(t.SetSaveData,s)}}e.AgRuSdk=s,e.AgRuSdkMethods=t,Object.defineProperty(e,"__esModule",{value:!0}),window.AgRuSdk=agru.AgRuSdk,window.AgRuSdkMethods=agru.AgRuSdkMethods}));
!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))(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 e.debug?console.info("SDK is running in DEBUG mode!"):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,s){return this.options.debug?setTimeout(s):null==top?void 0:top.postMessage({data:t,type:e},"*")}authorize(e){return this._sendMessage(t.Authorize,void 0,(()=>{this._emitter.emit(t.Authorize,[!0,null])})),this._handleEvent(t.Authorize,e)}getSaveData(e){return this._sendMessage(t.GetSaveData,this.options,(()=>{this._emitter.emit(t.GetSaveData,[{a:!0,b:!1,c:1},null])})),this._handleEvent(t.GetSaveData,e)}getUsers(e,s){return this._sendMessage(t.GetUsers,e,(()=>{this._emitter.emit(t.GetUsers,[e.map((e=>({avatar:`https://api.lorem.space/image/face?w=150&h=150&hash=${e}`,id:e,name:Math.random().toString(16).substring(2)}))),null])})),this._handleEvent(t.GetUsers,s)}isAppUser(e,s){return this._sendMessage(t.IsAppUser,e,(()=>{this._emitter.emit(t.IsAppUser,[!0,null])})),this._handleEvent(t.IsAppUser,s)}on(e,t){return this._emitter.on(e,t)}once(e,t){return this._emitter.once(e,t)}sayHello(e){const s="And here's Johnny";return this._sendMessage(t.SayHello,s,(()=>{this._emitter.emit(t.SayHello,[s,null])})),this._handleEvent(t.SayHello,e)}showCampaign(e="default",s){return this._sendMessage(t.ShowCampaign,{options:this.options,type:e},(()=>{this._emitter.emit(t.ShowCampaign,[{reward:"rewarded"===e,type:e,status:!0},null])})),this._handleEvent(t.ShowCampaign,s)}showPayment(e,s){return this._sendMessage(t.ShowPayment,e,(()=>{this._emitter.emit(t.ShowPayment,[null,null])})),this._handleEvent(t.ShowPayment,s)}setSaveData(e,s){return this._sendMessage(t.SetSaveData,{data:e,options:this.options},(()=>{this._emitter.emit(t.SetSaveData,[!0,null])})),this._handleEvent(t.SetSaveData,s)}}e.AgRuSdk=s,e.AgRuSdkMethods=t,Object.defineProperty(e,"__esModule",{value:!0}),window.AgRuSdk=agru.AgRuSdk,window.AgRuSdkMethods=agru.AgRuSdkMethods}));
{
"name": "@agru/sdk",
"version": "1.0.16",
"version": "1.0.17",
"description": "AG RU SDK for the games integration",

@@ -5,0 +5,0 @@ "module": "dist/esm/index.js",

@@ -281,2 +281,58 @@ [![Bundle Size](https://img.shields.io/bundlephobia/min/@agru/sdk?style=for-the-badge)](https://www.npmjs.com/package/@agru/sdk)

### `showPayment`
Показать окно оплаты.
```typescript
const [data, error] = await sdk.showPayment('token');
```
или
```typescript
sdk.showPayment('token', (data, error) => {
// ...
});
```
Пример ответа:
```typescript
{
info: {
discount: string;
email: string;
invoice: number;
// подробнее о статусах: https://developers.xsolla.com/doc/pay-station/integration-guide/open-payment-ui/
status: 'delivering' | 'done' | 'invoice' | 'troubled';
userId: string;
virtualCurrencyAmount: number;
} | null;
// статус отображения окна оплаты.
status: true,
};
```
Пример отслеживания состояния:
```typescript
let isPaymentVisible = false;
sdk.on(AgRuSdkMethods.ShowPayment, ({ info, status }) => {
isPaymentVisible = status;
// Не выполняем код ниже, пока окно оплаты отображается.
if (status) {
return;
}
// Если человек закрыл окно оплаты, то не выполняем код ниже.
if (info == null) {
return;
}
if (info.invoiceId) {
// проверяем у себя на сервере прошла оплата или нет.
}
});
sdk.showPayment('token');
```
### `setSaveData`

@@ -316,4 +372,5 @@ Сохранить игровые данные пользователя на сервер.

ShowCampaign = 'agru-showCampaign',
ShowPayment = 'agru-showPayment',
SetSaveData = 'agru-setSaveData',
}
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc