be-components 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/lib/commonjs/ApiOverrides/index.js +22 -8
  2. package/lib/commonjs/ApiOverrides/index.js.map +1 -1
  3. package/lib/commonjs/Authenticator/Components/LoginForm.js +8 -2
  4. package/lib/commonjs/Authenticator/Components/LoginForm.js.map +1 -1
  5. package/lib/commonjs/Authenticator/Components/StrategyForm.js +8 -2
  6. package/lib/commonjs/Authenticator/Components/StrategyForm.js.map +1 -1
  7. package/lib/commonjs/Authenticator/api/index.js +1 -1
  8. package/lib/commonjs/Authenticator/api/index.js.map +1 -1
  9. package/lib/commonjs/Authenticator/index.js +5 -3
  10. package/lib/commonjs/Authenticator/index.js.map +1 -1
  11. package/lib/commonjs/Observer/Observer.js +84 -0
  12. package/lib/commonjs/Observer/Observer.js.map +1 -0
  13. package/lib/commonjs/Observer/api/index.js +154 -0
  14. package/lib/commonjs/Observer/api/index.js.map +1 -0
  15. package/lib/commonjs/Observer/api/types.d.js +2 -0
  16. package/lib/commonjs/Observer/api/types.d.js.map +1 -0
  17. package/lib/commonjs/Observer/index.js +23 -0
  18. package/lib/commonjs/Observer/index.js.map +1 -0
  19. package/lib/commonjs/index.js +19 -0
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/module/ApiOverrides/index.js +22 -8
  22. package/lib/module/ApiOverrides/index.js.map +1 -1
  23. package/lib/module/Authenticator/Components/LoginForm.js +8 -2
  24. package/lib/module/Authenticator/Components/LoginForm.js.map +1 -1
  25. package/lib/module/Authenticator/Components/StrategyForm.js +8 -2
  26. package/lib/module/Authenticator/Components/StrategyForm.js.map +1 -1
  27. package/lib/module/Authenticator/api/index.js +1 -1
  28. package/lib/module/Authenticator/api/index.js.map +1 -1
  29. package/lib/module/Authenticator/index.js +5 -3
  30. package/lib/module/Authenticator/index.js.map +1 -1
  31. package/lib/module/Observer/Observer.js +77 -0
  32. package/lib/module/Observer/Observer.js.map +1 -0
  33. package/lib/module/Observer/api/index.js +148 -0
  34. package/lib/module/Observer/api/index.js.map +1 -0
  35. package/lib/module/Observer/api/types.d.js +2 -0
  36. package/lib/module/Observer/api/types.d.js.map +1 -0
  37. package/lib/module/Observer/index.js +5 -0
  38. package/lib/module/Observer/index.js.map +1 -0
  39. package/lib/module/index.js +2 -1
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/typescript/src/ApiOverrides/index.d.ts +6 -8
  42. package/lib/typescript/src/ApiOverrides/index.d.ts.map +1 -1
  43. package/lib/typescript/src/Authenticator/Components/LoginForm.d.ts +2 -1
  44. package/lib/typescript/src/Authenticator/Components/LoginForm.d.ts.map +1 -1
  45. package/lib/typescript/src/Authenticator/Components/StrategyForm.d.ts +2 -1
  46. package/lib/typescript/src/Authenticator/Components/StrategyForm.d.ts.map +1 -1
  47. package/lib/typescript/src/Authenticator/api/index.d.ts +2 -0
  48. package/lib/typescript/src/Authenticator/api/index.d.ts.map +1 -1
  49. package/lib/typescript/src/Authenticator/index.d.ts +2 -1
  50. package/lib/typescript/src/Authenticator/index.d.ts.map +1 -1
  51. package/lib/typescript/src/Observer/Observer.d.ts +9 -0
  52. package/lib/typescript/src/Observer/Observer.d.ts.map +1 -0
  53. package/lib/typescript/src/Observer/api/index.d.ts +20 -0
  54. package/lib/typescript/src/Observer/api/index.d.ts.map +1 -0
  55. package/lib/typescript/src/Observer/index.d.ts +5 -0
  56. package/lib/typescript/src/Observer/index.d.ts.map +1 -0
  57. package/lib/typescript/src/index.d.ts +2 -1
  58. package/lib/typescript/src/index.d.ts.map +1 -1
  59. package/package.json +2 -1
  60. package/src/ApiOverrides/index.ts +15 -8
  61. package/src/ApiOverrides/types.d.ts +2 -0
  62. package/src/Authenticator/Components/LoginForm.tsx +10 -4
  63. package/src/Authenticator/Components/StrategyForm.tsx +10 -5
  64. package/src/Authenticator/api/index.ts +3 -3
  65. package/src/Authenticator/api/types.d.ts +8 -0
  66. package/src/Authenticator/index.tsx +6 -6
  67. package/src/Observer/Observer.tsx +77 -0
  68. package/src/Observer/api/index.ts +134 -0
  69. package/src/Observer/api/types.d.ts +38 -0
  70. package/src/Observer/index.ts +7 -0
  71. package/src/index.tsx +5 -0
@@ -23,23 +23,25 @@ let ENDPOINTS:{ [key:string]: string } = {}
23
23
 
24
24
  let auth_state:AuthStateProps = {
25
25
  authenticated:false,
26
- distinct_id: ''
26
+ distinct_id: '',
27
+ session_id:''
27
28
  }
28
29
 
29
30
  export { APIOverrides }
30
31
 
31
32
  const APIOverrides = {
32
- start: async(env:'PRODUCTION'|'STAGING'|'DEVELOPMENT', no_cache?:boolean):Promise<{ authenticated:boolean, access_token?:string, refresh_token?:string, expire_datetime?:any, distinct_id:string }> => {
33
+ start: async({ env, no_cache }: { env:'PRODUCTION'|'STAGING'|'DEVELOPMENT', no_cache:boolean }):Promise<AuthStateProps> => {
33
34
  APIOverrides.setEnvironment(env);
34
35
  let distinct_id = await APIOverrides.getDistinctID();
35
- auth_state = { authenticated: false, distinct_id }
36
+ const session_id = v4();
37
+ auth_state = { authenticated: false, distinct_id, session_id }
36
38
  if(no_cache){ return auth_state }
37
39
  let cached_token = await AsyncStorage.getItem('access_token');
38
- if(!cached_token){ return { authenticated: false, distinct_id } }
40
+ if(!cached_token){ return { authenticated: false, distinct_id, session_id } }
39
41
  let cached_refresh_token = await AsyncStorage.getItem('refresh_token');
40
- if(!cached_refresh_token){ return { authenticated: false, distinct_id } }
42
+ if(!cached_refresh_token){ return { authenticated: false, distinct_id, session_id } }
41
43
  let expire_datetime = await AsyncStorage.getItem('auth_expire_time');
42
- if(!expire_datetime){ return { authenticated:false, distinct_id } }
44
+ if(!expire_datetime){ return { authenticated:false, distinct_id, session_id } }
43
45
  if(moment().isAfter(moment(expire_datetime))){
44
46
  //Try to get a new one
45
47
  const refresh_resp = await APIOverrides.refreshToken(cached_refresh_token, distinct_id);
@@ -48,7 +50,7 @@ const APIOverrides = {
48
50
  await AsyncStorage.removeItem('access_token');
49
51
  await AsyncStorage.removeItem('refresh_token');
50
52
  await AsyncStorage.removeItem('auth_expire_time');
51
- return { authenticated: false, distinct_id }
53
+ return { authenticated: false, distinct_id, session_id }
52
54
  }
53
55
  cached_token = refresh_resp.access_token
54
56
  cached_refresh_token = refresh_resp.refresh_token
@@ -57,11 +59,15 @@ const APIOverrides = {
57
59
  await AsyncStorage.setItem('refresh_token', cached_refresh_token);
58
60
  await AsyncStorage.setItem('auth_expire_time', expire_datetime);
59
61
  }
62
+ const player_id = await AsyncStorage.getItem('player_id');
60
63
  APIOverrides.setBearerToken(cached_token);
61
64
  APIOverrides.setRefreshTokenInterceptor(cached_refresh_token, distinct_id)
65
+
62
66
  auth_state = {
63
67
  authenticated: true,
64
68
  distinct_id,
69
+ player_id,
70
+ session_id,
65
71
  access_token: cached_token,
66
72
  refresh_token: cached_refresh_token,
67
73
  expire_datetime
@@ -74,8 +80,9 @@ const APIOverrides = {
74
80
  getEndpoints: () => {
75
81
  return ENDPOINTS
76
82
  },
77
- cacheTokens: async(access_token:string, refresh_token?:string, expire_datetime?:any) => {
83
+ cacheTokens: async(access_token:string, player_id:string, refresh_token?:string, expire_datetime?:any) => {
78
84
  await AsyncStorage.setItem('access_token', access_token);
85
+ await AsyncStorage.setItem('player_id', player_id);
79
86
  if(refresh_token){ await AsyncStorage.setItem('refresh_token', refresh_token) }
80
87
  if(expire_datetime){ await AsyncStorage.setItem('auth_expire_time', expire_datetime) }
81
88
  },
@@ -1,6 +1,8 @@
1
1
  export interface AuthStateProps {
2
2
  authenticated:boolean,
3
3
  distinct_id:string,
4
+ session_id:string,
5
+ player_id?:string|null,
4
6
  access_token?:string,
5
7
  refresh_token?:string,
6
8
  expire_datetime?:any
@@ -3,13 +3,14 @@ import { View, TouchableOpacity } from "react-native"
3
3
  import { Button, Icons, Text, TextInput } from '../../Components';
4
4
  import Colors from '../../constants/colors';
5
5
  import { AuthenticateApi, AuthenticateHelpers } from '../api';
6
+ import type { AuthenticatedProps } from '../api/types';
6
7
 
7
8
 
8
9
  type LoginFormProps = {
9
10
  visible:boolean,
10
11
  width:number,
11
12
  onRegister: () => void,
12
- onAuthenticated: (access_token:string, refresh_token:string, expire_datetime:any) => void
13
+ onAuthenticated: (auth_response:AuthenticatedProps) => void
13
14
  }
14
15
 
15
16
 
@@ -80,8 +81,8 @@ const LoginForm = ({ width, visible, onRegister, onAuthenticated }:LoginFormProp
80
81
 
81
82
  const handleLogin = async() => {
82
83
  setLoginTry({ ...login_try, loading:true })
83
- const { result, message, access_token, refresh_token, expire_datetime } = await AuthenticateApi.authLogin(attribute, value, pass_token, verification_session_id)
84
- if(result == 'fail' || !access_token || !refresh_token){
84
+ const { result, player_id, message, access_token, refresh_token, expire_datetime } = await AuthenticateApi.authLogin(attribute, value, pass_token, verification_session_id)
85
+ if(result == 'fail' || !access_token || !refresh_token || !player_id){
85
86
  setLoginTry({ ...login_try, error:message, loading:false })
86
87
  setHalted(true)
87
88
  return setTimeout(() => {
@@ -90,7 +91,12 @@ const LoginForm = ({ width, visible, onRegister, onAuthenticated }:LoginFormProp
90
91
  }
91
92
  setLoginTry({ ...login_try, loading:false, error:undefined })
92
93
  setAuthenticated(true)
93
- return onAuthenticated(access_token, refresh_token, expire_datetime)
94
+ return onAuthenticated({
95
+ player_id,
96
+ access_token,
97
+ refresh_token,
98
+ expire_datetime
99
+ })
94
100
  }
95
101
 
96
102
  const getAttributeIcon = () => {
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
  import { Button, Checkbox, Icons, Text, TextInput } from "../../Components";
3
3
  import Colors from "../../constants/colors";
4
- import type { AuthExecutionRequestProps, AuthStrategyIdentifierProps, AuthStrategyProps } from '../api/types';
4
+ import type { AuthExecutionRequestProps, AuthStrategyIdentifierProps, AuthStrategyProps, AuthenticatedProps } from '../api/types';
5
5
  import { AuthenticateApi, AuthenticateHelpers } from '../api';
6
6
  import { Linking, TouchableOpacity, View , FlatList} from 'react-native';
7
7
 
@@ -15,7 +15,7 @@ type StrategyFormProps = {
15
15
  opt_in_url?:string,
16
16
  referral_code?:string,
17
17
  onLogin:() => void,
18
- onAuthenticated: (access_token:string, refresh_token:string, expire_datetime:any) => void
18
+ onAuthenticated: (auth_response:AuthenticatedProps) => void
19
19
  }
20
20
 
21
21
  const StrategyForm = ({ visible, auth_strategy_id, distinct_id, source, referral_code, width, opt_in_url, onAuthenticated, onLogin }:StrategyFormProps) => {
@@ -98,8 +98,8 @@ const StrategyForm = ({ visible, auth_strategy_id, distinct_id, source, referral
98
98
  if(!verify_attempt_allowed){ return }
99
99
  setVeryAttemptAllowed(false);
100
100
  setActionLoading(true);
101
- const { result, access_token, refresh_token, expire_datetime } = await AuthenticateApi.verifyAuthStrategyIdentifier(verify_state.auth_strategy_identifier_id, verify_state.verification_session_id, token, distinct_id);
102
- if(result == 'fail' || !access_token || !refresh_token){
101
+ const { result, player_id, access_token, refresh_token, expire_datetime } = await AuthenticateApi.verifyAuthStrategyIdentifier(verify_state.auth_strategy_identifier_id, verify_state.verification_session_id, token, distinct_id);
102
+ if(result == 'fail' || !access_token || !refresh_token || !player_id || !auth_strategy_id){
103
103
  setVerifyError(`Invalid code / password. Please try again after 10 seconds`)
104
104
  setTimeout(() => {
105
105
  setVeryAttemptAllowed(true);
@@ -109,7 +109,12 @@ const StrategyForm = ({ visible, auth_strategy_id, distinct_id, source, referral
109
109
  } else {
110
110
  setAuthenticated(true);
111
111
  setTimeout(() => {
112
- onAuthenticated(access_token, refresh_token, expire_datetime);
112
+ onAuthenticated({
113
+ player_id,
114
+ access_token,
115
+ refresh_token,
116
+ expire_datetime
117
+ });
113
118
  setActionLoading(false);
114
119
  }, 1500);
115
120
  }
@@ -13,7 +13,6 @@ export {
13
13
  const AuthenticateApi = {
14
14
  setEnvironment: () => {
15
15
  const endpoints = APIOverrides.getEndpoints();
16
- console.log('setting env!!!')
17
16
  AUTH_SVC_API = endpoints['AUTH_SVC_API'] as string;
18
17
  },
19
18
  authCheck: async(attribute:'email'|'phone'|'username', value:string):Promise<AuthCheckResponseProps> => {
@@ -24,7 +23,7 @@ const AuthenticateApi = {
24
23
  const resp = await axios.post(`${AUTH_SVC_API}/v1/authenticate/forgot`, { attribute, value })
25
24
  return resp.data.auth_response
26
25
  },
27
- authLogin: async(attribute:'email'|'phone'|'username', value:string, token:string, verification_session_id?:string):Promise<{ result:'success'|'fail', message:string, access_token?:string, refresh_token?:string, expire_datetime?:any }> => {
26
+ authLogin: async(attribute:'email'|'phone'|'username', value:string, token:string, verification_session_id?:string):Promise<{ result:'success'|'fail', message:string, player_id?:string, access_token?:string, refresh_token?:string, expire_datetime?:any }> => {
28
27
  const resp = await axios.post(`${AUTH_SVC_API}/v1/authenticate/login`, { attribute, verification_session_id }, {
29
28
  auth: {
30
29
  username: value,
@@ -61,8 +60,9 @@ const AuthenticateApi = {
61
60
  const resp = await axios.post(`${AUTH_SVC_API}/v1/authenticate/strategy/try`, { auth_execution_request })
62
61
  return resp.data
63
62
  },
64
- verifyAuthStrategyIdentifier: async(auth_strategy_identifier_id:string, verification_session_id:string, token:string, device_id:string):Promise<{ result: 'success'|'fail', access_token?:string, refresh_token?:string, expire_datetime?:any }> => {
63
+ verifyAuthStrategyIdentifier: async(auth_strategy_identifier_id:string, verification_session_id:string, token:string, device_id:string):Promise<{ result: 'success'|'fail', player_id?:string, access_token?:string, refresh_token?:string, expire_datetime?:any }> => {
65
64
  const resp = await axios.post(`${AUTH_SVC_API}/v1/authenticate/strategy/identifier/verify`, { auth_strategy_identifier_id, verification_session_id, token, device_id });
65
+ console.log(resp.data)
66
66
  return resp.data
67
67
  },
68
68
  getCompanyById: async(company_id:string):Promise<{ company:CompanyProps, company_members:CompanyMemberProps[] }> => {
@@ -72,12 +72,20 @@ export interface AuthExecutionRequestProps {
72
72
 
73
73
  export interface AuthExecutionResponseProps {
74
74
  auth_strategy_id: string,
75
+ player_id:string,
75
76
  result: 'authenticated' | 'verify' | 'failed',
76
77
  access_token?:string,
77
78
  refresh_token?:string,
78
79
  expire_datetime?:any
79
80
  }
80
81
 
82
+ export interface AuthenticatedProps {
83
+ player_id:string,
84
+ access_token:string,
85
+ refresh_token:string,
86
+ expire_datetime:any
87
+ }
88
+
81
89
 
82
90
  export interface CompanyProps {
83
91
  company_id:string,
@@ -5,11 +5,10 @@ import { View, Image } from 'react-native';
5
5
  import LoginForm from './Components/LoginForm';
6
6
  import { Text } from '../Components';
7
7
  import Colors from '../constants/colors';
8
- import type { CompanyProps } from './api/types';
8
+ import type { AuthenticatedProps, CompanyProps } from './api/types';
9
9
  import { APIOverrides } from '../ApiOverrides';
10
10
 
11
11
 
12
-
13
12
  type AuthenticateWizardProps = {
14
13
  auth_strategy_id:string,
15
14
  width:number,
@@ -19,7 +18,7 @@ type AuthenticateWizardProps = {
19
18
  opt_in_url?:string,
20
19
  referral_code?:string,
21
20
  visible?:boolean,
22
- onAuthenticated: (access_token:string, refresh_token:string, expire_datetime:any) => void
21
+ onAuthenticated: (auth_response:AuthenticatedProps) => void
23
22
  }
24
23
 
25
24
  const Authenticator = ({ auth_strategy_id, default_view, company_id, source, referral_code, width, opt_in_url, onAuthenticated }:AuthenticateWizardProps) => {
@@ -39,17 +38,18 @@ const Authenticator = ({ auth_strategy_id, default_view, company_id, source, ref
39
38
  setCompany(company_resp.company)
40
39
  }
41
40
  const distinct_id = await APIOverrides.getDistinctID()
41
+ console.log(distinct_id)
42
42
  setDistinctID(distinct_id)
43
43
  setLoaded(true);
44
44
  }
45
45
 
46
- const handleAuthenticated = async(access_token:string, refresh_token:string, expire_datetime:any) => {
47
- return onAuthenticated(access_token, refresh_token, expire_datetime)
46
+ const handleAuthenticated = async(auth_response:AuthenticatedProps) => {
47
+ return onAuthenticated(auth_response)
48
48
  }
49
49
 
50
50
  if(!loaded || !distinct_id){ return <></> }
51
51
  return (
52
- <View style={{ flex:1 }}>
52
+ <View style={{ flex:1, width }}>
53
53
  {company ?
54
54
  <View style={{ padding:20, flexDirection:'row', alignItems:'center', borderTopRightRadius:22, borderTopLeftRadius:22, borderBottomWidth:1, borderColor:Colors.accents.accent200 }}>
55
55
  <View style={{ flex:1, marginRight:10 }}>
@@ -0,0 +1,77 @@
1
+ import React from 'react';
2
+ import { useEffect, useState } from 'react';
3
+ import { deviceDetect } from 'react-device-detect';
4
+ import { BEEventApi } from './api';
5
+
6
+ type BEAnalyticsObserverProps = {
7
+ source:string;
8
+ session_id:string;
9
+ distinct_id:string;
10
+ }
11
+
12
+ const BEAnalyticsObserver = ({ source, session_id, distinct_id }:BEAnalyticsObserverProps) => {
13
+ const [ init_loaded, setInitLoaded ] = useState(false);
14
+
15
+ const device_data = deviceDetect(undefined);
16
+
17
+ useEffect(() => {
18
+ updateAnalytics()
19
+ },[device_data])
20
+
21
+ const updateAnalytics = async() => {
22
+ //Get
23
+ BEEventApi.setDistinctId(distinct_id)
24
+ BEEventApi.setSource(source)
25
+ const is_pwa = isPWA();
26
+ const notification_permission = getNotificationPermissions();
27
+ BEEventApi.setDevice({ ...device_data, is_pwa, notification_permission })
28
+ BEEventApi.setSessionId(session_id)
29
+ if(!init_loaded){
30
+ let url = window?.location?.href
31
+ sendIncomingUserEvent(url)
32
+ setInitLoaded(true)
33
+ }
34
+ }
35
+ return <></>
36
+ }
37
+
38
+ const getNotificationPermissions = () => {
39
+ if (!("Notification" in window)) {
40
+ return 'not_allowed'
41
+ }
42
+ return window.Notification.permission
43
+ }
44
+
45
+ const isPWA = () => {
46
+ const mqStandAlone = '(display-mode: standalone)';
47
+ const new_nav = navigator as any
48
+ if (new_nav.standalone || window.matchMedia(mqStandAlone).matches) {
49
+ return true
50
+ }
51
+ return false
52
+ }
53
+
54
+
55
+ const sendIncomingUserEvent = (url:string) => {
56
+ const parsed_url = url.split(/[?&]/)
57
+ const new_data:any = {
58
+ href: url
59
+ };
60
+ parsed_url.map(p => {
61
+ let vars = p.split('=')
62
+ if(vars.length !== 2){ return }
63
+ if(!vars[0]){ return }
64
+ new_data[vars[0]] = vars[1]
65
+ })
66
+ let reference_id = new_data['eid']
67
+ let referrer = document?.referrer
68
+ if(referrer){ new_data['referrer'] = referrer }
69
+ BEEventApi.saveEvent({
70
+ event_name: 'incoming_user',
71
+ reference_id,
72
+ event_data: new_data,
73
+ level:1
74
+ })
75
+ }
76
+
77
+ export default BEAnalyticsObserver
@@ -0,0 +1,134 @@
1
+ import axios from 'axios';
2
+ import type { BEEventProps, GeneratedLinkProps } from './types';
3
+ export { BEEventApi, BELinkApi }
4
+
5
+ const ANALYTICS_SVC_API = 'https://be-analytics-svc.herokuapp.com';
6
+
7
+ let my_device:any
8
+ let my_source:string
9
+ let my_player_id:string
10
+ let my_session_id:string
11
+ let my_distinct_id:string
12
+
13
+ const delayed_events:BEEventProps[] = [];
14
+
15
+ const BEEventApi = {
16
+ setDevice: (device:any) => {
17
+ const is_crawler = BEEventApi.detectCrawler(device.userAgent)
18
+ my_device = { ...device, is_crawler }
19
+ },
20
+ detectCrawler: (user_agent:string) => {
21
+ var botPattern = "(googlebot\/|bot|Googlebot-Mobile|Googlebot-Image|Google favicon|Mediapartners-Google|bingbot|slurp|java|wget|curl|Commons-HttpClient|Python-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sitebot|linkdex|Adidxbot|blekkobot|ezooms|dotbot|Mail.RU_Bot|discobot|heritrix|findthatfile|europarchive.org|NerdByNature.Bot|sistrix crawler|ahrefsbot|Aboundex|domaincrawler|wbsearchbot|summify|ccbot|edisterbot|seznambot|ec2linkfinder|gslfbot|aihitbot|intelium_bot|facebookexternalhit|yeti|RetrevoPageAnalyzer|lb-spider|sogou|lssbot|careerbot|wotbox|wocbot|ichiro|DuckDuckBot|lssrocketcrawler|drupact|webcompanycrawler|acoonbot|openindexspider|gnam gnam spider|web-archive-net.com.bot|backlinkcrawler|coccoc|integromedb|content crawler spider|toplistbot|seokicks-robot|it2media-domain-crawler|ip-web-crawler.com|siteexplorer.info|elisabot|proximic|changedetection|blexbot|arabot|WeSEE:Search|niki-bot|CrystalSemanticsBot|rogerbot|360Spider|psbot|InterfaxScanBot|Lipperhey SEO Service|CC Metadata Scaper|g00g1e.net|GrapeshotCrawler|urlappendbot|brainobot|fr-crawler|binlar|SimpleCrawler|Livelapbot|Twitterbot|cXensebot|smtbot|bnf.fr_bot|A6-Indexer|ADmantX|Facebot|Twitterbot|OrangeBot|memorybot|AdvBot|MegaIndex|SemanticScholarBot|ltx71|nerdybot|xovibot|BUbiNG|Qwantify|archive.org_bot|Applebot|TweetmemeBot|crawler4j|findxbot|SemrushBot|yoozBot|lipperhey|y!j-asr|Domain Re-Animator Bot|AddThis)";
22
+ var re = new RegExp(botPattern, 'i');
23
+ if (re.test(user_agent)) {
24
+ return true
25
+ }
26
+ return false
27
+ },
28
+ setSource: (source:string) => {
29
+ my_source = source
30
+ },
31
+ setDistinctId:(distinct_id:string) => {
32
+ my_distinct_id = distinct_id
33
+ BEEventHelpers.addDistinctHeader(distinct_id);
34
+ },
35
+ setSessionId: (session_id:string) => {
36
+ my_session_id = session_id
37
+ BEEventHelpers.addSessionHeader(session_id);
38
+ if(delayed_events.length > 0){
39
+ delayed_events.map(e => BEEventApi.saveEvent(e))
40
+ }
41
+ },
42
+ saveEvent: async(be_event:BEEventProps):Promise<string|undefined> => {
43
+ try {
44
+ be_event.source_type = 'client';
45
+ be_event.source = my_source
46
+ be_event.device_data = my_device;
47
+ be_event.player_id = my_player_id;
48
+ //let pos = await LocationApi.getMyPosition();
49
+ be_event.coords = { }
50
+ be_event.distinct_id = my_distinct_id;
51
+ be_event.session_id = my_session_id;
52
+ const resp = await axios.post(`${ANALYTICS_SVC_API}/v1/events/event/create`, { be_event });
53
+ return resp.data.be_event_id
54
+ } catch (e) {
55
+ return
56
+ }
57
+ },
58
+ pageHit: async(page:string, url?:string):Promise<string|undefined> => {
59
+ try {
60
+ let be_event:BEEventProps = {
61
+ event_name: 'page_hit',
62
+ source_type: 'client',
63
+ source: my_source,
64
+ device_data: my_device,
65
+ distinct_id: my_distinct_id,
66
+ session_id: my_session_id,
67
+ player_id: my_player_id,
68
+ event_data: {
69
+ screen: page,
70
+ url
71
+ },
72
+ level:2
73
+ }
74
+ const resp = await axios.post(`${ANALYTICS_SVC_API}/v1/events/event/create`, { be_event });
75
+ return resp.data.be_event_id
76
+ } catch (e) {
77
+ return
78
+ }
79
+ },
80
+ identify: async(player_id:string) => {
81
+ try {
82
+ if(!player_id){ return }
83
+ my_player_id = player_id
84
+ await axios.post(`${ANALYTICS_SVC_API}/v1/events/identify`, { player_id, distinct_id:my_distinct_id });
85
+ return
86
+ } catch (e) {
87
+ console.log(e)
88
+ return
89
+ }
90
+ }
91
+ }
92
+
93
+ const BEEventHelpers = {
94
+ addSessionHeader: (session_id:string) => {
95
+ axios.defaults.headers.common['SessionId'] = session_id;
96
+ },
97
+ addDistinctHeader: (distinct_id:string) => {
98
+ axios.defaults.headers.common['DistinctId'] = distinct_id;
99
+ }
100
+ }
101
+
102
+ const BELinkApi = {
103
+ generateShortLink: async(generated_link:GeneratedLinkProps):Promise<{ generated_link:GeneratedLinkProps, url:string }> => {
104
+ try {
105
+ const resp = await axios.post(`${ANALYTICS_SVC_API}/v1/links/redirect/generate`, { generated_link })
106
+ return { generated_link:resp.data.generated_link, url: `https://share.mybe.app/id/${resp.data.generated_link.visible_id}` }
107
+ } catch (e) {
108
+ console.log(e)
109
+ return { generated_link, url: generated_link.redirect_url }
110
+ }
111
+ },
112
+ share: async(title:string, text?:string, link?:string, generated_link_id?:string):Promise<void> => {
113
+ if(navigator.share){
114
+ try {
115
+ await navigator.share({
116
+ title,
117
+ text:text,
118
+ url: link
119
+ })
120
+ } catch (e) {
121
+ return
122
+ }
123
+ } else {
124
+ alert(`Your browser does not support native sharing. Copy the following link and share: ${link}`)
125
+ }
126
+ BEEventApi.saveEvent({
127
+ event_name: 'generated_link',
128
+ event_data: {
129
+ generated_link_id
130
+ },
131
+ level:1
132
+ })
133
+ }
134
+ }
@@ -0,0 +1,38 @@
1
+ export type EventNameTypes = 'generated_link' |'incoming_user' |'identify_user' |'visibility_on' |'visibility_off'|
2
+ 'page_hit'|'sign_up'|'game_view'|'game_join'|'game_result'|'order_create'|'order_result'|'vouch_start'|'vouch_attempt'|
3
+ 'account_add_start'|'account_add_result'|'transaction_attempt'|'transaction_result'|'message_support'|'room_view'|'view_social'|
4
+ 'view_market'|'interact_social'|'wallet_view'|'redeem_code'|'viewed_notification_prompt'|'notification_enabled'|'viewed_pwa_prompt'|'pwa_installed'
5
+
6
+ export interface BEEventProps {
7
+ //be_event_id?:string,
8
+ event_name:EventNameTypes,
9
+ distinct_id?:string,
10
+ session_id?:string,
11
+ reference_id?:string,
12
+ player_id?:string,
13
+ event_data:any,
14
+ source?:string,
15
+ source_type?:'client'|'server'
16
+ device_data?:any,
17
+ ip_address?:string,
18
+ coords?: any,
19
+ level:number,
20
+ //create_datetime?:any,
21
+ //last_update_datetime?:any
22
+ }
23
+
24
+ export interface GeneratedLinkProps {
25
+ generated_link_id?:string,
26
+ visible_id?:string,
27
+ redirect_url: string,
28
+ generator_id?:string,
29
+ generator:'player'|'company'|'tool'
30
+ link_type: 'user_generated_link'|'brand_generated_link'|'bettoredge_tool'|'marketing'|'widget',
31
+ link_sub_type: 'user_referral_link'|'h2h_share_link'|'social_post_link'|'podcast_link'|'competition_link'|'bracket_link'|'squares_link'|'room_link'|'poll_link'
32
+ company_id?:string,
33
+ type_id?:string,
34
+ status?:string,
35
+ distinct_id?:string,
36
+ create_datetime?:any,
37
+ last_update_datetime?:any
38
+ }
@@ -0,0 +1,7 @@
1
+
2
+
3
+ import Observer from './Observer';
4
+ import { BEEventApi, BELinkApi } from './api';
5
+
6
+ export default Observer
7
+ export { BEEventApi, BELinkApi }
package/src/index.tsx CHANGED
@@ -4,9 +4,14 @@ import * as Components from './Components';
4
4
  import { APIOverrides } from "./ApiOverrides";
5
5
  import LinearGradient from "react-native-linear-gradient";
6
6
  import Colors from "./constants/colors";
7
+ import Observer, { BEEventApi, BELinkApi } from './Observer';
8
+
7
9
 
8
10
  export {
9
11
  Authenticator,
12
+ Observer,
13
+ BEEventApi,
14
+ BELinkApi,
10
15
  ProfileManager,
11
16
  Components,
12
17
  APIOverrides,