From 45a8d845bde8bf72e7479f7a9b6846a516e3c8af Mon Sep 17 00:00:00 2001 From: Q Date: Thu, 11 Nov 2021 20:48:24 -0700 Subject: [PATCH 01/13] add affiliate endpoints --- package.json | 2 +- src/Services/affiliate.js | 19 +++++++++---------- src/client.js | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 290f461..305c1b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gamebetr/api-client-js", - "version": "1.0.1019", + "version": "1.0.2", "description": "Gamebetr API client library", "main": "index.js", "dependencies": { diff --git a/src/Services/affiliate.js b/src/Services/affiliate.js index f452cea..d4ffecb 100644 --- a/src/Services/affiliate.js +++ b/src/Services/affiliate.js @@ -13,20 +13,19 @@ export default class Affiliate { return token.getCookie('gamebetr_affiliate_id'); } - listMedia() { - // do this with php instead of js? + listClicks(date_start, date_end) { + let client = new Client(this.config); + return client.request('GET', 'affiliate/clicks?filter[created_at]=bt|' + date_start + ';' + date_end + '&page[size]=9999'); } - listReferredUsers() { - // + listSignups(date_start, date_end) { + let client = new Client(this.config); + return client.request('GET', 'affiliate/user/list?filter[created_at]=bt|' + date_start + ';' + date_end + '&page[size]=9999'); } - listTiers() { - // - } - - listRates() { - // + listEarnings(bank_uuid, bank_account_uuid, date_start, date_end) { + let client = new Client(this.config); + return client.request('GET', 'bank/' + bank_uuid + '/reports/win-loss-by-tags?filter[bank-account-uuid]=' + bank_account_uuid + '&filter[tags][0]=win&filter[date-start]=' + date_start + '&filter[date-end]=' + date_end); } } diff --git a/src/client.js b/src/client.js index d1334b4..b209e88 100644 --- a/src/client.js +++ b/src/client.js @@ -3,7 +3,7 @@ import Token from './token'; /** * Example usage: * let client = new Client({'baseUri': 'https://www.site.com'}); - * client.request('GET', '/api/v1/endpoint').then(data => console.log(data)) + * client.request('GET', 'endpoint').then(data => console.log(data)) */ export default class Client { From b9be7407d9c865183d0d5394832300776b98bf29 Mon Sep 17 00:00:00 2001 From: Q Date: Thu, 11 Nov 2021 21:10:13 -0700 Subject: [PATCH 02/13] add affiliate endpoints --- src/Services/affiliate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/affiliate.js b/src/Services/affiliate.js index d4ffecb..b149945 100644 --- a/src/Services/affiliate.js +++ b/src/Services/affiliate.js @@ -23,9 +23,9 @@ export default class Affiliate { return client.request('GET', 'affiliate/user/list?filter[created_at]=bt|' + date_start + ';' + date_end + '&page[size]=9999'); } - listEarnings(bank_uuid, bank_account_uuid, date_start, date_end) { + listEarnings(bank_uuid, bank_account_uuid, tags, date_start, date_end) { let client = new Client(this.config); - return client.request('GET', 'bank/' + bank_uuid + '/reports/win-loss-by-tags?filter[bank-account-uuid]=' + bank_account_uuid + '&filter[tags][0]=win&filter[date-start]=' + date_start + '&filter[date-end]=' + date_end); + return client.request('GET', 'bank/' + bank_uuid + '/reports/win-loss-by-tags?filter[bank-account-uuid]=' + bank_account_uuid + '&' + tags + ' &filter[date-start]=' + date_start + '&filter[date-end]=' + date_end); } } From bf4e0feb45ecf0fdf40bb5e2374c3d54e56e07a1 Mon Sep 17 00:00:00 2001 From: Q Date: Tue, 16 Nov 2021 17:27:29 -0700 Subject: [PATCH 03/13] add vocabulary filter to affiliate earnings --- package.json | 8 ++++---- src/Services/affiliate.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 305c1b5..1f728ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gamebetr/api-client-js", - "version": "1.0.2", + "version": "1.0.3", "description": "Gamebetr API client library", "main": "index.js", "dependencies": { @@ -16,12 +16,12 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/gamebetr/api-client-js.git" + "url": "git+https://github.com/dbd-net/api-client-js.git" }, "author": "", "license": "ISC", "bugs": { - "url": "https://github.com/gamebetr/api-client-js/issues" + "url": "https://github.com/dbd-net/api-client-js/issues" }, - "homepage": "https://github.com/gamebetr/api-client-js#readme" + "homepage": "https://github.com/dbd-net/api-client-js#readme" } diff --git a/src/Services/affiliate.js b/src/Services/affiliate.js index b149945..1ea155b 100644 --- a/src/Services/affiliate.js +++ b/src/Services/affiliate.js @@ -23,9 +23,9 @@ export default class Affiliate { return client.request('GET', 'affiliate/user/list?filter[created_at]=bt|' + date_start + ';' + date_end + '&page[size]=9999'); } - listEarnings(bank_uuid, bank_account_uuid, tags, date_start, date_end) { + listEarnings(bank_uuid, bank_account_uuid, vocabulary, tags, date_start, date_end) { let client = new Client(this.config); - return client.request('GET', 'bank/' + bank_uuid + '/reports/win-loss-by-tags?filter[bank-account-uuid]=' + bank_account_uuid + '&' + tags + ' &filter[date-start]=' + date_start + '&filter[date-end]=' + date_end); + return client.request('GET', 'bank/' + bank_uuid + '/reports/win-loss-by-tags?filter[bank-account-uuid]=' + bank_account_uuid + '&filter[vocabulary]=' + vocabulary + '&' + tags + ' &filter[date-start]=' + date_start + '&filter[date-end]=' + date_end); } } From 1bc0d05a2cb3b66fd10681177fd597f9227310a3 Mon Sep 17 00:00:00 2001 From: Q Date: Thu, 23 Dec 2021 18:18:17 -0700 Subject: [PATCH 04/13] add 2fa, update token cookies --- package.json | 2 +- src/Services/auth.js | 11 ++++++++++- src/Services/event.js | 26 ++++++++++++++++++++------ src/token.js | 39 ++++++++++++++++++++++++++++++++++++--- 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 1f728ac..ba59c6a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gamebetr/api-client-js", - "version": "1.0.3", + "version": "1.0.4", "description": "Gamebetr API client library", "main": "index.js", "dependencies": { diff --git a/src/Services/auth.js b/src/Services/auth.js index 0f736fb..1cf35e3 100644 --- a/src/Services/auth.js +++ b/src/Services/auth.js @@ -1,5 +1,4 @@ import Client from '../client'; -import Token from '../token'; export default class Auth { @@ -34,6 +33,16 @@ export default class Auth { return client.request('POST', 'user/login', data); } + login2fa(email, password, key) { + let client = new Client(this.config); + let data = { + 'email': email, + 'password': password, + 'key': key, + }; + return client.request('POST', 'user/login_2fa', data); + } + forgotPassword(email, new_password) { let client = new Client(this.config); let data = { diff --git a/src/Services/event.js b/src/Services/event.js index 28c6247..90f6906 100644 --- a/src/Services/event.js +++ b/src/Services/event.js @@ -26,7 +26,7 @@ export default class Event { console.log('register start event complete'); } - registerEnd(uuid) { + registerEnd(data) { if (!this.validDomain) { console.log('domain not valid'); return; @@ -35,7 +35,7 @@ export default class Event { fbq("track", "Lead", { currency: 'USD', value: 0, - external_id: uuid + external_id: data.data.id }); console.log('fbq fired'); } @@ -44,7 +44,7 @@ export default class Event { event: "track.user.registration", payload: { action: "complete", - userId: uuid + userId: data.data.id } }); console.log('srtmcommands fired'); @@ -52,13 +52,26 @@ export default class Event { console.log('register end event complete'); } - login(uuid) { + login(data) { + // fire postmessage event for parents listening + let payload = { + 'data': { + 'id': Date.now().toString(), + 'type': 'event', + 'attributes': { + 'event': 'login' + } + } + }; + payload.data.relationships = {'authorizationToken': data}; + window.parent.postMessage(payload, '*'); + if (!this.validDomain) { console.log('domain not valid'); return; } if (typeof fbq === "function") { - fbq("trackCustom", "Login", { external_id: uuid }); + fbq("trackCustom", "Login", { external_id: data.data.id }); console.log('fbq fired'); } if (typeof srtmCommands.push === "function") { @@ -66,11 +79,12 @@ export default class Event { event: "track.user.login", payload: { action: "complete", - userId: uuid + userId: data.data.id } }); console.log('srtmcommands fired'); } + console.log('login event complete'); } diff --git a/src/token.js b/src/token.js index ffcbc13..b703467 100644 --- a/src/token.js +++ b/src/token.js @@ -2,27 +2,52 @@ export default class Token { constructor() { this.tokenName = 'gamebetr_token'; - // set from external source this.baseDomainName = 'gamebetr_base_domain'; this.apiUriName = 'gamebetr_api_uri'; this.webUriName = 'gamebetr_web_uri'; this.domainIdName = 'gamebetr_domain_id'; } + // this will inherit cookies from parent source if this page is embeded in iframe + inheritCookies() { + window.addEventListener('message', e => { + if (typeof e.data.data === 'undefined') { + return; + } + let data = e.data.data; + if (data.type != 'event') { + return; + } + if (data.attributes.event != 'auth_init') { + return; + } + // set cookies + this.setCookie(this.apiUriName, data.attributes.cookies[this.apiUriName]); + this.setCookie(this.webUriName, data.attributes.cookies[this.webUriName]); + this.setCookie(this.domainIdName, data.attributes.cookies[this.domainIdName]); + console.log('cookies inherited'); + }, false); + } + // store the token as a cookie setToken(token, expire) { // use auth api expiration as cookie expiration let expires = new Date(expire).toUTCString(); // use the current domain as wildcard domain for cookie - let domain = '.' + this.getBaseDomain(); + // let domain = '.' + this.getBaseDomain(); - document.cookie = this.tokenName + '=' + token + ';expires=' + expires + ';domain=' + domain + ';path=/'; + // document.cookie = this.tokenName + '=' + token + ';expires=' + expires + ';domain=' + domain + ';path=/'; + document.cookie = this.tokenName + '=' + token + ';expires=' + expires + ';path=/'; // console.log('Cookie token set as: ' + token); // console.log(expires); // console.log(domain); } + setCookie(name, value) { + document.cookie = name + '=' + value + ';path=/'; + } + getToken() { return this.getCookie(this.tokenName); } @@ -77,6 +102,14 @@ export default class Token { return ""; } + getSafeCookies() { + let cookies = {}; + cookies[this.apiUriName] = this.getCookie(this.apiUriName); + cookies[this.webUriName] = this.getCookie(this.webUriName); + cookies[this.domainIdName] = this.getCookie(this.domainIdName); + return cookies; + } + // logout deleteToken() { // From 029486412036e0325a9b20ea49b96481af6f6aa2 Mon Sep 17 00:00:00 2001 From: Q Date: Thu, 23 Dec 2021 18:29:47 -0700 Subject: [PATCH 05/13] remove laravel-mix dependency --- package.json | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/package.json b/package.json index ba59c6a..cdfb016 100644 --- a/package.json +++ b/package.json @@ -1,25 +1,11 @@ { "name": "@gamebetr/api-client-js", - "version": "1.0.4", + "version": "1.0.5", "description": "Gamebetr API client library", - "main": "index.js", - "dependencies": { - "laravel-mix": "^5.0.9" - }, - "scripts": { - "dev": "npm run development", - "development": "NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", - "watch": "npm run development -- --watch", - "hot": "NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", - "prod": "npm run production", - "production": "NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" - }, "repository": { "type": "git", "url": "git+https://github.com/dbd-net/api-client-js.git" }, - "author": "", - "license": "ISC", "bugs": { "url": "https://github.com/dbd-net/api-client-js/issues" }, From 9d9841c3602f058dc9c2b83d720a1b79ef06b494 Mon Sep 17 00:00:00 2001 From: Q Date: Wed, 29 Dec 2021 16:01:47 -0700 Subject: [PATCH 06/13] add safe origins --- package.json | 2 +- src/token.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index cdfb016..c9f69b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gamebetr/api-client-js", - "version": "1.0.5", + "version": "1.0.6", "description": "Gamebetr API client library", "repository": { "type": "git", diff --git a/src/token.js b/src/token.js index b703467..7ffeecb 100644 --- a/src/token.js +++ b/src/token.js @@ -110,6 +110,24 @@ export default class Token { return cookies; } + /** + * These are safe origins to use with window.postMessage() + */ + getSafeOrigins() { + let origins = []; + origins.push('https://www.playbetr.com'); + origins.push('https://www.betcoin.ag'); + origins.push('https://playerapi.playbetr.com'); + origins.push('https://playerapi.betcoin.ag'); + origins.push('https://staging.playbetr.com'); + origins.push('https://staging.betcoin.ag'); + origins.push('https://staging-playerapi.playbetr.com'); + origins.push('https://staging-playerapi.betcoin.ag'); + origins.push('http://playbetr.lndo.site'); + origins.push('http://betcoin.lndo.site'); + return origins; + } + // logout deleteToken() { // From c4bbc507415ab5f3f03cf179449705cf3c04b4da Mon Sep 17 00:00:00 2001 From: Q Date: Wed, 29 Dec 2021 16:30:12 -0700 Subject: [PATCH 07/13] update events to use safe origins --- package.json | 2 +- src/Services/event.js | 4 +++- src/token.js | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c9f69b2..4c5824f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gamebetr/api-client-js", - "version": "1.0.6", + "version": "1.0.7", "description": "Gamebetr API client library", "repository": { "type": "git", diff --git a/src/Services/event.js b/src/Services/event.js index 90f6906..865310e 100644 --- a/src/Services/event.js +++ b/src/Services/event.js @@ -64,7 +64,9 @@ export default class Event { } }; payload.data.relationships = {'authorizationToken': data}; - window.parent.postMessage(payload, '*'); + token.getSafeOrigins().forEach(e => { + window.parent.postMessage(payload, e); + }); if (!this.validDomain) { console.log('domain not valid'); diff --git a/src/token.js b/src/token.js index 7ffeecb..5141044 100644 --- a/src/token.js +++ b/src/token.js @@ -11,6 +11,9 @@ export default class Token { // this will inherit cookies from parent source if this page is embeded in iframe inheritCookies() { window.addEventListener('message', e => { + if (this.getSafeOrigins().indexOf(e.origin) == -1) { + return; + } if (typeof e.data.data === 'undefined') { return; } From 5e8531c41b950fabb7e66210ebf9ea4e73afb18c Mon Sep 17 00:00:00 2001 From: Q Date: Wed, 29 Dec 2021 16:51:00 -0700 Subject: [PATCH 08/13] add more safe origins --- package.json | 2 +- src/token.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 4c5824f..25b49bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gamebetr/api-client-js", - "version": "1.0.7", + "version": "1.0.8", "description": "Gamebetr API client library", "repository": { "type": "git", diff --git a/src/token.js b/src/token.js index 5141044..7cff338 100644 --- a/src/token.js +++ b/src/token.js @@ -126,13 +126,13 @@ export default class Token { origins.push('https://staging.betcoin.ag'); origins.push('https://staging-playerapi.playbetr.com'); origins.push('https://staging-playerapi.betcoin.ag'); + origins.push('http://staging.playbetr.com'); + origins.push('http://staging.betcoin.ag'); + origins.push('http://staging-playerapi.playbetr.com'); + origins.push('http://staging-playerapi.betcoin.ag'); origins.push('http://playbetr.lndo.site'); origins.push('http://betcoin.lndo.site'); return origins; } - // logout - deleteToken() { - // - } } From 93a497869cd28cf77f485502744bb2916f70aaef Mon Sep 17 00:00:00 2001 From: Q Date: Wed, 29 Dec 2021 17:07:05 -0700 Subject: [PATCH 09/13] try catch to prevent errors --- package.json | 2 +- src/Services/event.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 25b49bf..84d5c59 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gamebetr/api-client-js", - "version": "1.0.8", + "version": "1.0.9", "description": "Gamebetr API client library", "repository": { "type": "git", diff --git a/src/Services/event.js b/src/Services/event.js index 865310e..a1a41aa 100644 --- a/src/Services/event.js +++ b/src/Services/event.js @@ -65,7 +65,10 @@ export default class Event { }; payload.data.relationships = {'authorizationToken': data}; token.getSafeOrigins().forEach(e => { - window.parent.postMessage(payload, e); + try { + window.parent.postMessage(payload, e); + } + catch(x) {} }); if (!this.validDomain) { From fa4cd87290a3d9df1c0288453ec2840415ffd4ca Mon Sep 17 00:00:00 2001 From: Q Date: Wed, 29 Dec 2021 18:05:33 -0700 Subject: [PATCH 10/13] event update for origins --- package.json | 2 +- src/Services/event.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 84d5c59..6c827c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gamebetr/api-client-js", - "version": "1.0.9", + "version": "1.0.10", "description": "Gamebetr API client library", "repository": { "type": "git", diff --git a/src/Services/event.js b/src/Services/event.js index a1a41aa..fb30c38 100644 --- a/src/Services/event.js +++ b/src/Services/event.js @@ -65,10 +65,9 @@ export default class Event { }; payload.data.relationships = {'authorizationToken': data}; token.getSafeOrigins().forEach(e => { - try { + if (e == token.getWebUri()) { window.parent.postMessage(payload, e); } - catch(x) {} }); if (!this.validDomain) { From 1a87cdf9786f98afd6a909e2ddd10a60176fd60b Mon Sep 17 00:00:00 2001 From: Q Date: Wed, 29 Dec 2021 18:16:05 -0700 Subject: [PATCH 11/13] token scope update --- package.json | 2 +- src/Services/event.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6c827c8..8ef6459 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gamebetr/api-client-js", - "version": "1.0.10", + "version": "1.0.11", "description": "Gamebetr API client library", "repository": { "type": "git", diff --git a/src/Services/event.js b/src/Services/event.js index fb30c38..66e3e73 100644 --- a/src/Services/event.js +++ b/src/Services/event.js @@ -3,9 +3,9 @@ import Token from '../token'; export default class Event { constructor() { - let token = new Token(); + this.token = new Token(); this.validDomain = false; - if (token.getDomainId() == 1000001) { + if (this.token.getDomainId() == 1000001) { this.validDomain = true; } } @@ -64,8 +64,8 @@ export default class Event { } }; payload.data.relationships = {'authorizationToken': data}; - token.getSafeOrigins().forEach(e => { - if (e == token.getWebUri()) { + this.token.getSafeOrigins().forEach(e => { + if (e == this.token.getWebUri()) { window.parent.postMessage(payload, e); } }); From 3ed60ad1fce85bad7771377b51b59c2eb3b9f894 Mon Sep 17 00:00:00 2001 From: Q Date: Thu, 3 Feb 2022 15:52:28 -0700 Subject: [PATCH 12/13] new leaderboard format --- package.json | 2 +- src/Services/leaderboard.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 8ef6459..c669036 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gamebetr/api-client-js", - "version": "1.0.11", + "version": "1.0.12", "description": "Gamebetr API client library", "repository": { "type": "git", diff --git a/src/Services/leaderboard.js b/src/Services/leaderboard.js index 6ed941f..99c0651 100644 --- a/src/Services/leaderboard.js +++ b/src/Services/leaderboard.js @@ -8,30 +8,30 @@ export default class Leaderboard { list(type, period, currency = '') { let path = ''; - let tag = ''; + let category = ''; switch (type) { case 'most_bets_casino': path = 'most-bets'; - tag = 'casino'; + category = 'casino'; break; case 'top_bet_casino': path = 'top-bet'; - tag = 'casino'; + category = 'casino'; break; case 'most_bets_sports': path = 'most-bets'; - tag = 'sports'; + category = 'sports'; break; case 'top_bet_sports': path = 'top-bet'; - tag = 'sports'; + category = 'sports'; break; } let currency_filter = ''; // if (currency != '') { currency_filter = '&filter[display-currency.display-unit]=' + currency; // } - let endpoint ='leaderboard/reports/' + path + '?page[size]=50&filter[tags][]=' + tag + '&filter[period]=' + period + currency_filter; + let endpoint ='leaderboard/reports/' + path + '?page[size]=50&filter[service-category]=' + category + '&filter[period]=' + period + currency_filter; let client = new Client(this.config); return client.request('GET', endpoint); } From dfd093ff8ec62ba46d9b2bb0c6ac91b9e6a524c6 Mon Sep 17 00:00:00 2001 From: Q Date: Fri, 4 Mar 2022 16:22:53 -0700 Subject: [PATCH 13/13] add affiliate conversions --- package.json | 2 +- src/Services/affiliate.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c669036..fc559ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gamebetr/api-client-js", - "version": "1.0.12", + "version": "1.0.13", "description": "Gamebetr API client library", "repository": { "type": "git", diff --git a/src/Services/affiliate.js b/src/Services/affiliate.js index 1ea155b..24783ed 100644 --- a/src/Services/affiliate.js +++ b/src/Services/affiliate.js @@ -13,6 +13,19 @@ export default class Affiliate { return token.getCookie('gamebetr_affiliate_id'); } + createConversion(domain_id, player_id, affiliate_id = 0, template_id = '', custom_id = '', promo_code = '') { + let client = new Client(this.config); + let data = { + 'domain_id': domain_id, + 'player_id': player_id, + 'affiliate_id': affiliate_id, + 'template_id': template_id, + 'custom_id': custom_id, + 'promo_code': promo_code + }; + return client.request('POST', 'affiliate/conversions', data); + } + listClicks(date_start, date_end) { let client = new Client(this.config); return client.request('GET', 'affiliate/clicks?filter[created_at]=bt|' + date_start + ';' + date_end + '&page[size]=9999');