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.24 to 1.0.25

13

dist/esm/index.js

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

})(AgRuSdkMethods || {});
var AgRuSdkEvents = /* @__PURE__ */ ((AgRuSdkEvents2) => {
AgRuSdkEvents2["OptionsUpdates"] = "agru-optionsUpdates";
return AgRuSdkEvents2;
})(AgRuSdkEvents || {});

@@ -89,3 +93,8 @@ function mitt(n){return {all:n=n||new Map,on:function(t,e){var i=n.get(t);i?i.push(e):n.set(t,[e]);},off:function(t,e){var i=n.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):n.set(t,[]));},emit:function(t,e){var i=n.get(t);i&&i.slice().map(function(n){n(e);}),(i=n.get("*"))&&i.slice().map(function(n){n(t,e);});}}}

on(type, handler) {
return this._emitter.on(type, handler);
this._emitter.on(type, handler);
const events = Object.values(AgRuSdkEvents);
if (events.includes(type)) {
this._sendMessage("event", type);
}
return () => this._emitter.off(type, handler);
}

@@ -124,2 +133,2 @@ once(type, handler) {

export { AgRuSdk, AgRuSdkMethods };
export { AgRuSdk, AgRuSdkEvents, AgRuSdkMethods };

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.ShowPayment="agru-showPayment",e.SetSaveData="agru-setSaveData",e.ToggleFullscreen="agru-toggleFullscreen",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 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){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,t){return this._emitter.on(e,t)}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{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.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};

@@ -14,2 +14,5 @@ import { Emitter } from 'mitt';

}
declare enum AgRuSdkEvents {
OptionsUpdates = "agru-optionsUpdates"
}

@@ -23,3 +26,4 @@ declare type AgRuCampaignType = 'default' | 'rewarded';

};
declare type AgRuSdkMethodsData = {
declare type AgRuSdkData = {
event: string;
[AgRuSdkMethods.Authorize]: string;

@@ -41,9 +45,11 @@ [AgRuSdkMethods.GetSaveData]: Record<string, unknown>;

};
declare type AgRuSdkEmitter = Emitter<AgRuSdkMethodsResponse> & {
emit<Key extends keyof AgRuSdkMethodsResponse>(type: Key, event: [AgRuSdkMethodsResponse[Key], Error | null]): void;
off<Key extends keyof AgRuSdkMethodsResponse>(type: Key, handler: AgRuCallback<Key>): void;
on<Key extends keyof AgRuSdkMethodsResponse>(type: Key, handler: AgRuCallback<Key>): void;
once<Key extends keyof AgRuSdkMethodsResponse>(type: Key, handler: AgRuCallback<Key>): void;
declare type AgRuSdkEmitter = Emitter<AgRuSdkResponse> & {
emit<Key extends keyof AgRuSdkResponse>(type: Key, event: [AgRuSdkResponse[Key], Error | null]): void;
off<Key extends keyof AgRuSdkResponse>(type: Key, handler: AgRuCallback<Key>): void;
on<Key extends keyof AgRuSdkResponse>(type: Key, handler: AgRuCallback<Key>): void;
once<Key extends keyof AgRuSdkResponse>(type: Key, handler: AgRuCallback<Key>): void;
};
declare type AgRuSdkMethodsResponse = {
declare type AgRuSdkResponse = {
event: string;
[AgRuSdkEvents.OptionsUpdates]: AgRuSdkOptions;
[AgRuSdkMethods.Authorize]: boolean;

@@ -73,5 +79,5 @@ [AgRuSdkMethods.GetSaveData]: Record<string, any>;

};
declare type AgRuCallback<T extends keyof AgRuSdkMethodsResponse> = (data: AgRuSdkMethodsResponse[T], error: Error | null) => void;
declare type AgRuPromise<T extends keyof AgRuSdkMethodsResponse> = Promise<[
AgRuSdkMethodsResponse[T],
declare type AgRuCallback<T extends keyof AgRuSdkResponse> = (data: AgRuSdkResponse[T], error: Error | null) => void;
declare type AgRuPromise<T extends keyof AgRuSdkResponse> = Promise<[
AgRuSdkResponse[T],
Error | null

@@ -139,4 +145,4 @@ ]>;

*/
isAppUser(userId: AgRuSdkMethodsData[AgRuSdkMethods.IsAppUser]): AgRuPromise<AgRuSdkMethods.IsAppUser>;
isAppUser(userId: AgRuSdkMethodsData[AgRuSdkMethods.IsAppUser], callback: AgRuCallback<AgRuSdkMethods.IsAppUser>): void;
isAppUser(userId: AgRuSdkData[AgRuSdkMethods.IsAppUser]): AgRuPromise<AgRuSdkMethods.IsAppUser>;
isAppUser(userId: AgRuSdkData[AgRuSdkMethods.IsAppUser], callback: AgRuCallback<AgRuSdkMethods.IsAppUser>): void;
/**

@@ -147,3 +153,3 @@ * Unlisten the event.

*/
off<T extends AgRuSdkMethods>(type: T, handler: AgRuCallback<T>): void;
off<T extends AgRuSdkMethods | AgRuSdkEvents>(type: T, handler: AgRuCallback<T>): void;
/**

@@ -154,3 +160,3 @@ * Listen for the event.

*/
on<T extends AgRuSdkMethods>(type: T, handler: AgRuCallback<T>): void;
on<T extends AgRuSdkMethods | AgRuSdkEvents>(type: T, handler: AgRuCallback<T>): () => void;
/**

@@ -161,3 +167,3 @@ * Listen for the event only once.

*/
once<T extends AgRuSdkMethods>(type: T, handler: AgRuCallback<T>): void;
once<T extends AgRuSdkMethods | AgRuSdkEvents>(type: T, handler: AgRuCallback<T>): void;
/**

@@ -192,2 +198,2 @@ * Returns a message from the origin. Only for setup purposes.

export { AgRuCallback, AgRuCampaignType, AgRuPromise, AgRuSdk, AgRuSdkEmitter, AgRuSdkMethods, AgRuSdkMethodsData, AgRuSdkMethodsResponse, AgRuSdkOptions, AgRuUser };
export { AgRuCallback, AgRuCampaignType, AgRuPromise, AgRuSdk, AgRuSdkData, AgRuSdkEmitter, AgRuSdkEvents, AgRuSdkMethods, AgRuSdkOptions, AgRuSdkResponse, AgRuUser };

@@ -17,2 +17,6 @@ 'use strict';

})(AgRuSdkMethods || {});
var AgRuSdkEvents = /* @__PURE__ */ ((AgRuSdkEvents2) => {
AgRuSdkEvents2["OptionsUpdates"] = "agru-optionsUpdates";
return AgRuSdkEvents2;
})(AgRuSdkEvents || {});

@@ -93,3 +97,8 @@ function mitt(n){return {all:n=n||new Map,on:function(t,e){var i=n.get(t);i?i.push(e):n.set(t,[e]);},off:function(t,e){var i=n.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):n.set(t,[]));},emit:function(t,e){var i=n.get(t);i&&i.slice().map(function(n){n(e);}),(i=n.get("*"))&&i.slice().map(function(n){n(t,e);});}}}

on(type, handler) {
return this._emitter.on(type, handler);
this._emitter.on(type, handler);
const events = Object.values(AgRuSdkEvents);
if (events.includes(type)) {
this._sendMessage("event", type);
}
return () => this._emitter.off(type, handler);
}

@@ -129,2 +138,3 @@ once(type, handler) {

exports.AgRuSdk = AgRuSdk;
exports.AgRuSdkEvents = AgRuSdkEvents;
exports.AgRuSdkMethods = AgRuSdkMethods;

@@ -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||{});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 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){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,t){return this._emitter.on(e,t)}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=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.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;

@@ -19,2 +19,6 @@ (function (global, factory) {

})(AgRuSdkMethods || {});
var AgRuSdkEvents = /* @__PURE__ */ ((AgRuSdkEvents2) => {
AgRuSdkEvents2["OptionsUpdates"] = "agru-optionsUpdates";
return AgRuSdkEvents2;
})(AgRuSdkEvents || {});

@@ -95,3 +99,8 @@ function mitt(n){return {all:n=n||new Map,on:function(t,e){var i=n.get(t);i?i.push(e):n.set(t,[e]);},off:function(t,e){var i=n.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):n.set(t,[]));},emit:function(t,e){var i=n.get(t);i&&i.slice().map(function(n){n(e);}),(i=n.get("*"))&&i.slice().map(function(n){n(t,e);});}}}

on(type, handler) {
return this._emitter.on(type, handler);
this._emitter.on(type, handler);
const events = Object.values(AgRuSdkEvents);
if (events.includes(type)) {
this._sendMessage("event", type);
}
return () => this._emitter.off(type, handler);
}

@@ -131,2 +140,3 @@ once(type, handler) {

exports.AgRuSdk = AgRuSdk;
exports.AgRuSdkEvents = AgRuSdkEvents;
exports.AgRuSdkMethods = AgRuSdkMethods;

@@ -138,3 +148,4 @@

window.AgRuSdkMethods = agru.AgRuSdkMethods
window.AgRuSdkEvents = agru.AgRuSdkEvents
}));

@@ -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||{});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(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){return this._emitter.on(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=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.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}));
{
"name": "@agru/sdk",
"version": "1.0.24",
"version": "1.0.25",
"description": "AG RU SDK for the games integration",

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

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

## Методы SDK
```typescript
enum AgRuSdkMethods {
Authorize = 'agru-authorize',
GetSaveData = 'agru-getSaveData',
GetUsers = 'agru-getUsers',
IsAppUser = 'agru-isAppUser',
SayHello = 'agru-sayHello',
ShowCampaign = 'agru-showCampaign',
ShowPayment = 'agru-showPayment',
SetSaveData = 'agru-setSaveData',
ToggleFullscreen = 'agru-toggleFullscreen',
}
```
### `authorize`

@@ -214,2 +229,17 @@ Вызвать диалоговое окно авторизации.

Возвращает метод отписки от прослушивания события.
```typescript
const unlistenHello = sdk.on(AgRuSdkMethods.SayHello, (data, error) => {
// ...
});
sdk.on(AgRuSdkMethods.SayHello, (data, error) => {
// этот код продолжит выполняться
});
// в любом месте в коде
unlistenHello() // перестаем слушать SayHello
```
### `once`

@@ -411,15 +441,33 @@ Слушать событие и обработать один раз.

## Методы SDK
## События SDK
```typescript
enum AgRuSdkMethods {
Authorize = 'agru-authorize',
GetSaveData = 'agru-getSaveData',
GetUsers = 'agru-getUsers',
IsAppUser = 'agru-isAppUser',
SayHello = 'agru-sayHello',
ShowCampaign = 'agru-showCampaign',
ShowPayment = 'agru-showPayment',
SetSaveData = 'agru-setSaveData',
ToggleFullscreen = 'agru-toggleFullscreen',
enum AgRuSdkEvents {
OptionsUpdates = 'agru-optionsUpdates',
}
```
### `OptionsUpdates`
Вызывается, когда AG обновляет параметры игры в реальном времени, к примеру после авторизации.
Пример использования:
```typescript
// Какое-то глобальное состояние игры.
const state = {
user: { ... },
};
sdk.on(AgRuSdkEvents.OptionsUpdates, async (newOptions) => {
// Обновляем параметры SDK.
sdk.options = { ...sdk.options, ...newOptions };
// Проверяем поменялся ли ID игрока.
if (sdk.options.player_id == state.user.id) {
return;
}
// Если ID поменялся, получаем новые данные и обновляем.
const [data] = await sdk.getUsers([sdk.options.player_id]);
state.user = data[0];
});
```
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