Comparing version 1.0.0 to 1.0.1
@@ -10,3 +10,3 @@ declare enum AgRuSdkMethods { | ||
declare type IAgRuSdkOptions = Record<AgRuSdkMethods, string>; | ||
declare type IAgRuSdkOptions = Partial<Record<AgRuSdkMethods, string>>; | ||
interface ISetSizeProps { | ||
@@ -13,0 +13,0 @@ width?: number; |
@@ -1,188 +0,180 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.agru = {})); | ||
})(this, (function (exports) { 'use strict'; | ||
'use strict'; | ||
var AgRuSdkMethods = /* @__PURE__ */ ((AgRuSdkMethods2) => { | ||
AgRuSdkMethods2["ShowCampaign"] = "sdkShowCampaign"; | ||
AgRuSdkMethods2["SayHello"] = "sdkSayHello"; | ||
AgRuSdkMethods2["SdkGetGameInfo"] = "sdkGetGameInfo"; | ||
AgRuSdkMethods2["SdkGetUserProfile"] = "sdkGetUserProfile"; | ||
AgRuSdkMethods2["SdkIsAppUser"] = "sdkIsAppUser"; | ||
AgRuSdkMethods2["SdkSetSize"] = "sdkSetSize"; | ||
return AgRuSdkMethods2; | ||
})(AgRuSdkMethods || {}); | ||
var InstanceParams = /* @__PURE__ */ ((InstanceParams2) => { | ||
InstanceParams2["AgUser"] = "ag_user"; | ||
InstanceParams2["AppId"] = "app_id"; | ||
InstanceParams2["GameSid"] = "game_sid"; | ||
return InstanceParams2; | ||
})(InstanceParams || {}); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const DEBUG_PLACEHOLDERS = { | ||
[AgRuSdkMethods.ShowCampaign]: { | ||
closed: false, | ||
error: null, | ||
success: true | ||
}, | ||
[AgRuSdkMethods.SdkGetUserProfile]: { | ||
id: 1, | ||
username: "gary", | ||
avatar: "https://via.placeholder.com/150", | ||
success: true | ||
}, | ||
[AgRuSdkMethods.SdkGetGameInfo]: { | ||
app_id: 1, | ||
game_sid: 0, | ||
success: true | ||
}, | ||
[AgRuSdkMethods.SdkSetSize]: { | ||
success: true | ||
}, | ||
[AgRuSdkMethods.SayHello]: { | ||
message: `And here's Johnny`, | ||
success: true | ||
}, | ||
[AgRuSdkMethods.SdkIsAppUser]: { | ||
success: true | ||
var AgRuSdkMethods = /* @__PURE__ */ ((AgRuSdkMethods2) => { | ||
AgRuSdkMethods2["ShowCampaign"] = "sdkShowCampaign"; | ||
AgRuSdkMethods2["SayHello"] = "sdkSayHello"; | ||
AgRuSdkMethods2["SdkGetGameInfo"] = "sdkGetGameInfo"; | ||
AgRuSdkMethods2["SdkGetUserProfile"] = "sdkGetUserProfile"; | ||
AgRuSdkMethods2["SdkIsAppUser"] = "sdkIsAppUser"; | ||
AgRuSdkMethods2["SdkSetSize"] = "sdkSetSize"; | ||
return AgRuSdkMethods2; | ||
})(AgRuSdkMethods || {}); | ||
var InstanceParams = /* @__PURE__ */ ((InstanceParams2) => { | ||
InstanceParams2["AgUser"] = "ag_user"; | ||
InstanceParams2["AppId"] = "app_id"; | ||
InstanceParams2["GameSid"] = "game_sid"; | ||
return InstanceParams2; | ||
})(InstanceParams || {}); | ||
const DEBUG_PLACEHOLDERS = { | ||
[AgRuSdkMethods.ShowCampaign]: { | ||
closed: false, | ||
error: null, | ||
success: true | ||
}, | ||
[AgRuSdkMethods.SdkGetUserProfile]: { | ||
id: 1, | ||
username: "gary", | ||
avatar: "https://via.placeholder.com/150", | ||
success: true | ||
}, | ||
[AgRuSdkMethods.SdkGetGameInfo]: { | ||
app_id: 1, | ||
game_sid: 0, | ||
success: true | ||
}, | ||
[AgRuSdkMethods.SdkSetSize]: { | ||
success: true | ||
}, | ||
[AgRuSdkMethods.SayHello]: { | ||
message: `And here's Johnny`, | ||
success: true | ||
}, | ||
[AgRuSdkMethods.SdkIsAppUser]: { | ||
success: true | ||
} | ||
}; | ||
const METHODS_KEYS = Object.values(AgRuSdkMethods).reduce((acc, key) => { | ||
acc[key] = true; | ||
return acc; | ||
}, {}); | ||
class AgRuSdk { | ||
props; | ||
isDebug; | ||
ag_user; | ||
game_sid; | ||
app_id; | ||
auth_key; | ||
constructor(props, isDebug = false) { | ||
this.props = props; | ||
this.isDebug = isDebug; | ||
} | ||
mount() { | ||
window.addEventListener("message", this.messagesHandler.bind(this)); | ||
const params = this.parseQueryString(window.location.search); | ||
if (params.auth_key) { | ||
this.auth_key = params.auth_key; | ||
} | ||
}; | ||
const METHODS_KEYS = Object.values(AgRuSdkMethods).reduce((acc, key) => { | ||
acc[key] = true; | ||
return acc; | ||
}, {}); | ||
class AgRuSdk { | ||
props; | ||
isDebug; | ||
ag_user; | ||
game_sid; | ||
app_id; | ||
auth_key; | ||
constructor(props, isDebug = false) { | ||
this.props = props; | ||
this.isDebug = isDebug; | ||
Object.keys(InstanceParams).forEach((key) => { | ||
const fieldName = InstanceParams[key]; | ||
if (typeof params[fieldName] !== "undefined") { | ||
const value = parseInt(params[fieldName]); | ||
if (value > 0) { | ||
this[fieldName] = value; | ||
} | ||
} | ||
}); | ||
} | ||
unmount() { | ||
window.removeEventListener("message", this.messagesHandler.bind(this)); | ||
} | ||
sdkSayHello() { | ||
top?.postMessage({ type: AgRuSdkMethods.SayHello, data: `And here's Johnny` }, "*"); | ||
if (!this.isDebug) { | ||
return; | ||
} | ||
mount() { | ||
window.addEventListener("message", this.messagesHandler.bind(this)); | ||
const params = this.parseQueryString(window.location.search); | ||
if (params.auth_key) { | ||
this.auth_key = params.auth_key; | ||
this.messagesHandler({ | ||
data: { | ||
type: AgRuSdkMethods.SayHello, | ||
data: DEBUG_PLACEHOLDERS[AgRuSdkMethods.SayHello] | ||
} | ||
Object.keys(InstanceParams).forEach((key) => { | ||
const fieldName = InstanceParams[key]; | ||
if (typeof params[fieldName] !== "undefined") { | ||
const value = parseInt(params[fieldName]); | ||
if (value > 0) { | ||
this[fieldName] = value; | ||
} | ||
}); | ||
} | ||
sdkSetSize(props) { | ||
top?.postMessage({ type: AgRuSdkMethods.SdkSetSize, data: props }, "*"); | ||
if (this.isDebug) { | ||
this.messagesHandler({ | ||
data: { | ||
type: AgRuSdkMethods.SdkSetSize, | ||
data: DEBUG_PLACEHOLDERS[AgRuSdkMethods.SdkSetSize] | ||
} | ||
}); | ||
} | ||
unmount() { | ||
window.removeEventListener("message", this.messagesHandler.bind(this)); | ||
} | ||
sdkGetGameInfo() { | ||
top?.postMessage({ type: AgRuSdkMethods.SdkGetGameInfo }, "*"); | ||
if (this.isDebug) { | ||
this.messagesHandler({ | ||
data: { | ||
type: AgRuSdkMethods.SdkGetGameInfo, | ||
data: DEBUG_PLACEHOLDERS[AgRuSdkMethods.SdkGetGameInfo] | ||
} | ||
}); | ||
} | ||
sdkSayHello() { | ||
top?.postMessage({ type: AgRuSdkMethods.SayHello, data: `And here's Johnny` }, "*"); | ||
if (!this.isDebug) { | ||
return; | ||
} | ||
} | ||
sdkGetUserProfile() { | ||
top?.postMessage({ type: AgRuSdkMethods.SdkGetUserProfile }, "*"); | ||
if (this.isDebug) { | ||
this.messagesHandler({ | ||
data: { | ||
type: AgRuSdkMethods.SayHello, | ||
data: DEBUG_PLACEHOLDERS[AgRuSdkMethods.SayHello] | ||
type: AgRuSdkMethods.SdkGetUserProfile, | ||
data: DEBUG_PLACEHOLDERS[AgRuSdkMethods.SdkGetUserProfile] | ||
} | ||
}); | ||
} | ||
sdkSetSize(props) { | ||
top?.postMessage({ type: AgRuSdkMethods.SdkSetSize, data: props }, "*"); | ||
if (this.isDebug) { | ||
this.messagesHandler({ | ||
data: { | ||
type: AgRuSdkMethods.SdkSetSize, | ||
data: DEBUG_PLACEHOLDERS[AgRuSdkMethods.SdkSetSize] | ||
} | ||
}); | ||
} | ||
} | ||
sdkIsAppUser(params) { | ||
top?.postMessage({ type: AgRuSdkMethods.SdkIsAppUser, data: params }, "*"); | ||
if (this.isDebug) { | ||
this.messagesHandler({ | ||
data: { | ||
type: AgRuSdkMethods.SdkIsAppUser, | ||
data: DEBUG_PLACEHOLDERS[AgRuSdkMethods.SdkIsAppUser] | ||
} | ||
}); | ||
} | ||
sdkGetGameInfo() { | ||
top?.postMessage({ type: AgRuSdkMethods.SdkGetGameInfo }, "*"); | ||
if (this.isDebug) { | ||
this.messagesHandler({ | ||
data: { | ||
type: AgRuSdkMethods.SdkGetGameInfo, | ||
data: DEBUG_PLACEHOLDERS[AgRuSdkMethods.SdkGetGameInfo] | ||
} | ||
}); | ||
} | ||
sdkShowCampaign() { | ||
top?.postMessage({ type: AgRuSdkMethods.ShowCampaign, data: this.auth_key }, "*"); | ||
} | ||
getInstanceParams() { | ||
return { | ||
ag_user: this.ag_user, | ||
game_sid: this.game_sid, | ||
app_id: this.app_id, | ||
auth_key: this.auth_key | ||
}; | ||
} | ||
messagesHandler(event) { | ||
const { type, data } = event.data; | ||
const execute = (key, data2) => { | ||
if (typeof window[this.props[key] || key] !== "function") { | ||
return; | ||
} | ||
window[this.props[key] || key](key, data2); | ||
}; | ||
if (METHODS_KEYS[type]) { | ||
return execute(type, data); | ||
} | ||
sdkGetUserProfile() { | ||
top?.postMessage({ type: AgRuSdkMethods.SdkGetUserProfile }, "*"); | ||
if (this.isDebug) { | ||
this.messagesHandler({ | ||
data: { | ||
type: AgRuSdkMethods.SdkGetUserProfile, | ||
data: DEBUG_PLACEHOLDERS[AgRuSdkMethods.SdkGetUserProfile] | ||
} | ||
}); | ||
} | ||
} | ||
sdkIsAppUser(params) { | ||
top?.postMessage({ type: AgRuSdkMethods.SdkIsAppUser, data: params }, "*"); | ||
if (this.isDebug) { | ||
this.messagesHandler({ | ||
data: { | ||
type: AgRuSdkMethods.SdkIsAppUser, | ||
data: DEBUG_PLACEHOLDERS[AgRuSdkMethods.SdkIsAppUser] | ||
} | ||
}); | ||
} | ||
} | ||
sdkShowCampaign() { | ||
top?.postMessage({ type: AgRuSdkMethods.ShowCampaign, data: this.auth_key }, "*"); | ||
} | ||
getInstanceParams() { | ||
return { | ||
ag_user: this.ag_user, | ||
game_sid: this.game_sid, | ||
app_id: this.app_id, | ||
auth_key: this.auth_key | ||
}; | ||
} | ||
messagesHandler(event) { | ||
const { type, data } = event.data; | ||
const execute = (key, data2) => { | ||
if (typeof window[this.props[key] || key] !== "function") { | ||
return; | ||
console.warn("Event type not available in ADK"); | ||
} | ||
parseQueryString(strQuery) { | ||
let tmp = []; | ||
let tmp2 = []; | ||
const objRes = {}; | ||
if (strQuery !== "") { | ||
tmp = strQuery.substr(1).split("&"); | ||
for (let i = 0; i < tmp.length; i += 1) { | ||
tmp2 = tmp[i].split("="); | ||
if (tmp2[0]) { | ||
objRes[tmp2[0]] = tmp2[1]; | ||
} | ||
window[this.props[key] || key](key, data2); | ||
}; | ||
if (METHODS_KEYS[type]) { | ||
return execute(type, data); | ||
} | ||
console.warn("Event type not available in ADK"); | ||
} | ||
parseQueryString(strQuery) { | ||
let tmp = []; | ||
let tmp2 = []; | ||
const objRes = {}; | ||
if (strQuery !== "") { | ||
tmp = strQuery.substr(1).split("&"); | ||
for (let i = 0; i < tmp.length; i += 1) { | ||
tmp2 = tmp[i].split("="); | ||
if (tmp2[0]) { | ||
objRes[tmp2[0]] = tmp2[1]; | ||
} | ||
} | ||
} | ||
return objRes; | ||
} | ||
return objRes; | ||
} | ||
} | ||
exports.AgRuSdk = AgRuSdk; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
window.AgRuSdk = agru.AgRuSdk | ||
})); | ||
exports.AgRuSdk = AgRuSdk; |
@@ -1,1 +0,1 @@ | ||
!function(e,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((e="undefined"!=typeof globalThis?globalThis:e||self).agru={})}(this,(function(e){"use strict";var s=(e=>(e.ShowCampaign="sdkShowCampaign",e.SayHello="sdkSayHello",e.SdkGetGameInfo="sdkGetGameInfo",e.SdkGetUserProfile="sdkGetUserProfile",e.SdkIsAppUser="sdkIsAppUser",e.SdkSetSize="sdkSetSize",e))(s||{}),t=(e=>(e.AgUser="ag_user",e.AppId="app_id",e.GameSid="game_sid",e))(t||{});const a={[s.ShowCampaign]:{closed:!1,error:null,success:!0},[s.SdkGetUserProfile]:{id:1,username:"gary",avatar:"https://via.placeholder.com/150",success:!0},[s.SdkGetGameInfo]:{app_id:1,game_sid:0,success:!0},[s.SdkSetSize]:{success:!0},[s.SayHello]:{message:"And here's Johnny",success:!0},[s.SdkIsAppUser]:{success:!0}},i=Object.values(s).reduce(((e,s)=>(e[s]=!0,e)),{});e.AgRuSdk=class{props;isDebug;ag_user;game_sid;app_id;auth_key;constructor(e,s=!1){this.props=e,this.isDebug=s}mount(){window.addEventListener("message",this.messagesHandler.bind(this));const e=this.parseQueryString(window.location.search);e.auth_key&&(this.auth_key=e.auth_key),Object.keys(t).forEach((s=>{const a=t[s];if(void 0!==e[a]){const s=parseInt(e[a]);s>0&&(this[a]=s)}}))}unmount(){window.removeEventListener("message",this.messagesHandler.bind(this))}sdkSayHello(){top?.postMessage({type:s.SayHello,data:"And here's Johnny"},"*"),this.isDebug&&this.messagesHandler({data:{type:s.SayHello,data:a[s.SayHello]}})}sdkSetSize(e){top?.postMessage({type:s.SdkSetSize,data:e},"*"),this.isDebug&&this.messagesHandler({data:{type:s.SdkSetSize,data:a[s.SdkSetSize]}})}sdkGetGameInfo(){top?.postMessage({type:s.SdkGetGameInfo},"*"),this.isDebug&&this.messagesHandler({data:{type:s.SdkGetGameInfo,data:a[s.SdkGetGameInfo]}})}sdkGetUserProfile(){top?.postMessage({type:s.SdkGetUserProfile},"*"),this.isDebug&&this.messagesHandler({data:{type:s.SdkGetUserProfile,data:a[s.SdkGetUserProfile]}})}sdkIsAppUser(e){top?.postMessage({type:s.SdkIsAppUser,data:e},"*"),this.isDebug&&this.messagesHandler({data:{type:s.SdkIsAppUser,data:a[s.SdkIsAppUser]}})}sdkShowCampaign(){top?.postMessage({type:s.ShowCampaign,data:this.auth_key},"*")}getInstanceParams(){return{ag_user:this.ag_user,game_sid:this.game_sid,app_id:this.app_id,auth_key:this.auth_key}}messagesHandler(e){const{type:s,data:t}=e.data,a=(e,s)=>{"function"==typeof window[this.props[e]||e]&&window[this.props[e]||e](e,s)};if(i[s])return a(s,t);console.warn("Event type not available in ADK")}parseQueryString(e){let s=[],t=[];const a={};if(""!==e){s=e.substr(1).split("&");for(let e=0;e<s.length;e+=1)t=s[e].split("="),t[0]&&(a[t[0]]=t[1])}return a}},Object.defineProperty(e,"__esModule",{value:!0}),window.AgRuSdk=agru.AgRuSdk})); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=(e=>(e.ShowCampaign="sdkShowCampaign",e.SayHello="sdkSayHello",e.SdkGetGameInfo="sdkGetGameInfo",e.SdkGetUserProfile="sdkGetUserProfile",e.SdkIsAppUser="sdkIsAppUser",e.SdkSetSize="sdkSetSize",e))(e||{}),s=(e=>(e.AgUser="ag_user",e.AppId="app_id",e.GameSid="game_sid",e))(s||{});const t={[e.ShowCampaign]:{closed:!1,error:null,success:!0},[e.SdkGetUserProfile]:{id:1,username:"gary",avatar:"https://via.placeholder.com/150",success:!0},[e.SdkGetGameInfo]:{app_id:1,game_sid:0,success:!0},[e.SdkSetSize]:{success:!0},[e.SayHello]:{message:"And here's Johnny",success:!0},[e.SdkIsAppUser]:{success:!0}},a=Object.values(e).reduce(((e,s)=>(e[s]=!0,e)),{});exports.AgRuSdk=class{props;isDebug;ag_user;game_sid;app_id;auth_key;constructor(e,s=!1){this.props=e,this.isDebug=s}mount(){window.addEventListener("message",this.messagesHandler.bind(this));const e=this.parseQueryString(window.location.search);e.auth_key&&(this.auth_key=e.auth_key),Object.keys(s).forEach((t=>{const a=s[t];if(void 0!==e[a]){const s=parseInt(e[a]);s>0&&(this[a]=s)}}))}unmount(){window.removeEventListener("message",this.messagesHandler.bind(this))}sdkSayHello(){top?.postMessage({type:e.SayHello,data:"And here's Johnny"},"*"),this.isDebug&&this.messagesHandler({data:{type:e.SayHello,data:t[e.SayHello]}})}sdkSetSize(s){top?.postMessage({type:e.SdkSetSize,data:s},"*"),this.isDebug&&this.messagesHandler({data:{type:e.SdkSetSize,data:t[e.SdkSetSize]}})}sdkGetGameInfo(){top?.postMessage({type:e.SdkGetGameInfo},"*"),this.isDebug&&this.messagesHandler({data:{type:e.SdkGetGameInfo,data:t[e.SdkGetGameInfo]}})}sdkGetUserProfile(){top?.postMessage({type:e.SdkGetUserProfile},"*"),this.isDebug&&this.messagesHandler({data:{type:e.SdkGetUserProfile,data:t[e.SdkGetUserProfile]}})}sdkIsAppUser(s){top?.postMessage({type:e.SdkIsAppUser,data:s},"*"),this.isDebug&&this.messagesHandler({data:{type:e.SdkIsAppUser,data:t[e.SdkIsAppUser]}})}sdkShowCampaign(){top?.postMessage({type:e.ShowCampaign,data:this.auth_key},"*")}getInstanceParams(){return{ag_user:this.ag_user,game_sid:this.game_sid,app_id:this.app_id,auth_key:this.auth_key}}messagesHandler(e){const{type:s,data:t}=e.data,i=(e,s)=>{"function"==typeof window[this.props[e]||e]&&window[this.props[e]||e](e,s)};if(a[s])return i(s,t);console.warn("Event type not available in ADK")}parseQueryString(e){let s=[],t=[];const a={};if(""!==e){s=e.substr(1).split("&");for(let e=0;e<s.length;e+=1)t=s[e].split("="),t[0]&&(a[t[0]]=t[1])}return a}}; |
{ | ||
"name": "@agru/sdk", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "AG RU SDK for the games integration", | ||
"module": "dist/esm/index.js", | ||
"main": "dist/cjs/index.js", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
@@ -8,0 +8,0 @@ "type": "module", |
@@ -28,3 +28,3 @@ import dts from 'rollup-plugin-dts'; | ||
{ | ||
file: pkg.types.replace('.d', '').replace('.ts', '.js'), | ||
file: pkg.module.replace('esm', 'umd'), | ||
@@ -31,0 +31,0 @@ name: 'agru', |
import { AgRuSdkMethods, InstanceParams } from './constants'; | ||
import type { IAgRuSdkOptions, IEventData, ISetSizeProps, ISdkIsAppUser } from './types'; | ||
import type { | ||
IAgRuSdkOptions, | ||
IEventData, | ||
ISetSizeProps, | ||
ISdkIsAppUser, | ||
IGetGameInfoData, | ||
IGetUserProfile, | ||
IBaseResponse, | ||
ISdkCampaign, | ||
} from './types'; | ||
// Placeholders for debug | ||
@@ -15,0 +5,0 @@ const DEBUG_PLACEHOLDERS: Partial<Record<AgRuSdkMethods, unknown>> = { |
import type { AgRuSdkMethods } from './constants'; | ||
export type IAgRuSdkOptions = Record<AgRuSdkMethods, string>; | ||
export type IAgRuSdkOptions = Partial<Record<AgRuSdkMethods, string>>; | ||
@@ -5,0 +5,0 @@ export interface IBaseResponse { |
42823
1086