apps-sdk 1.0.0 → 1.0.1
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.
- package/config.js +10 -3
- package/package.json +8 -4
- package/src/libraries/Networking.js +21 -12
- package/src/libraries/Session.js +104 -0
- package/types/index.d.ts +17 -0
package/config.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
export const
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export const ENDPOINTS = {
|
|
2
|
+
INIT : 'https://ap0404.gways.org/v6/init',
|
|
3
|
+
NOTIFICATION_TOKEN: 'https://ap0404.gways.org/user/set_expo_id',
|
|
4
|
+
TRACKING: 'https://ap0404.gways.org/v3/',
|
|
5
|
+
GET_USER_ID: 'https://ap0404.gways.org/user/generate_public_id',
|
|
6
|
+
CHECK_SUBSCRIPTION: 'https://ap0404.gways.org/create-sub',
|
|
7
|
+
SET_ATTRIBUTION: 'https://ap0404.gways.org/user/set_attribution_data',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const DEBUG_MODE = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apps-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Apps SDK",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,8 +9,12 @@
|
|
|
9
9
|
"author": "ASD",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@react-native-async-storage/async-storage": "^1.
|
|
12
|
+
"@react-native-async-storage/async-storage": "^1.21.0",
|
|
13
|
+
"expo-constants": "^15.4.5",
|
|
13
14
|
"expo-device": "^5.9.3",
|
|
14
|
-
"expo-
|
|
15
|
-
|
|
15
|
+
"expo-localization": "^14.8.3",
|
|
16
|
+
"expo-notifications": "^0.23.0",
|
|
17
|
+
"react-native": "^0.73.2"
|
|
18
|
+
},
|
|
19
|
+
"types": "./types/index.d.ts"
|
|
16
20
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as config from '../../config';
|
|
2
2
|
import { default as storage } from './Storage';
|
|
3
|
+
import Session from './Session';
|
|
3
4
|
|
|
4
5
|
class Networking {
|
|
5
6
|
|
|
@@ -25,19 +26,12 @@ class Networking {
|
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
async
|
|
29
|
+
async executeInit() {
|
|
30
|
+
config.DEBUG_MODE && console.debug("executeInit");
|
|
29
31
|
try {
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if(json.success){
|
|
34
|
-
try {
|
|
35
|
-
installID = json.data.install_id;
|
|
36
|
-
await storage.storeData('install_id', installID);
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.error('InstallID Error: ', error);
|
|
39
|
-
}
|
|
40
|
-
return json.data;
|
|
32
|
+
let initData = await this.request(config.ENDPOINTS.INIT);
|
|
33
|
+
if (initData) {
|
|
34
|
+
config.DEBUG_MODE && console.debug("initData", initData);
|
|
41
35
|
}
|
|
42
36
|
} catch (error) {
|
|
43
37
|
console.error(error);
|
|
@@ -58,6 +52,21 @@ class Networking {
|
|
|
58
52
|
return null;
|
|
59
53
|
}
|
|
60
54
|
}
|
|
55
|
+
|
|
56
|
+
async request(url, data={}) {
|
|
57
|
+
data = { ...Session.sessionData, ...data };
|
|
58
|
+
config.DEBUG_MODE && console.debug("request data: ", url, data);
|
|
59
|
+
try{
|
|
60
|
+
const response = await fetch(url, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
|
63
|
+
body: JSON.stringify(data)
|
|
64
|
+
});
|
|
65
|
+
return await response.json();
|
|
66
|
+
} catch (error){
|
|
67
|
+
console.log(error)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
export default new Networking();
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import Constants from 'expo-constants';
|
|
2
|
+
import * as Device from 'expo-device';
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import * as Localization from 'expo-localization'
|
|
5
|
+
import Storage from './Storage';
|
|
6
|
+
import Networking from './Networking';
|
|
7
|
+
import * as config from "../../config";
|
|
8
|
+
|
|
9
|
+
class session {
|
|
10
|
+
sessionData = {};
|
|
11
|
+
sessionID = null;
|
|
12
|
+
isFirstOpen = false;
|
|
13
|
+
isSubscribed = false;
|
|
14
|
+
isDevUser = false;
|
|
15
|
+
|
|
16
|
+
init = async () => {
|
|
17
|
+
await this.storeSessionStructure();
|
|
18
|
+
this.sessionID = this.generateSessionID();
|
|
19
|
+
await this.checkFirstOpen();
|
|
20
|
+
// await Networking.executeInit();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
storeSessionStructure = async () => {
|
|
24
|
+
this.sessionData = {
|
|
25
|
+
app: {
|
|
26
|
+
shortVersion: Constants.expoConfig.version,
|
|
27
|
+
package: Constants.expoConfig.android.package,
|
|
28
|
+
languageCode: 'es',
|
|
29
|
+
regionCode: 'ES',
|
|
30
|
+
buildVersionNumber: Constants.expoConfig.version,
|
|
31
|
+
},
|
|
32
|
+
device: {
|
|
33
|
+
name: Device.deviceName,
|
|
34
|
+
systemName: Device.osName,
|
|
35
|
+
systemVersion: Device.osVersion,
|
|
36
|
+
model: Device.modelName,
|
|
37
|
+
},
|
|
38
|
+
sandbox: {
|
|
39
|
+
"domains": "0"
|
|
40
|
+
},
|
|
41
|
+
adjust : {
|
|
42
|
+
|
|
43
|
+
},
|
|
44
|
+
dev : true,
|
|
45
|
+
lowPower : false,
|
|
46
|
+
lang : Localization.getLocales()[0].languageCode || 'en',
|
|
47
|
+
package : Platform.OS === 'android' ? Constants.expoConfig.android.package : Constants.expoConfig.ios.bundleIdentifier,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
checkFirstOpen = async () => {
|
|
52
|
+
this.sessionData.isFirstOpen = !(await Storage.getData("FirstOpen"));
|
|
53
|
+
if (this.sessionData.isFirstOpen) {
|
|
54
|
+
config.DEBUG_MODE && console.debug("checkFirstOpen - First Open");
|
|
55
|
+
await Storage.storeData("FirstOpen", true);
|
|
56
|
+
} else {
|
|
57
|
+
config.DEBUG_MODE && console.debug("checkFirstOpen - Not First Open");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
generateSessionID = () => {
|
|
62
|
+
config.DEBUG_MODE && console.debug("generateSessionID");
|
|
63
|
+
const dateNow = new Date();
|
|
64
|
+
const sessionID =
|
|
65
|
+
'' +
|
|
66
|
+
dateNow.getFullYear() +
|
|
67
|
+
('0' + (dateNow.getMonth() + 1)).slice(-2) +
|
|
68
|
+
('0' + dateNow.getDate()).slice(-2) +
|
|
69
|
+
dateNow.getHours() +
|
|
70
|
+
dateNow.getMinutes() +
|
|
71
|
+
dateNow.getSeconds()
|
|
72
|
+
;
|
|
73
|
+
config.DEBUG_MODE && console.debug("generateSessionID - sessionID: ", sessionID);
|
|
74
|
+
return sessionID;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getSessionData = () => {
|
|
78
|
+
return this.sessionData;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getSessionID = () => {
|
|
82
|
+
return this.sessionID;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getIsFirstOpen = () => {
|
|
86
|
+
return this.isFirstOpen;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getIsSubscribed = () => {
|
|
90
|
+
return this.isSubscribed;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getIsDevUser = () => {
|
|
94
|
+
return this.isDevUser;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
setIsSubscribed = (isSubscribed) => {
|
|
98
|
+
this.isSubscribed = isSubscribed;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
setIsDevUser = (isDevUser) => {
|
|
102
|
+
this.isDevUser = isDevUser;
|
|
103
|
+
}
|
|
104
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'apps-sdk' {
|
|
2
|
+
export class Networking {
|
|
3
|
+
trackEvent(wid: any, event: any, user_id?: any): Promise<void>;
|
|
4
|
+
executeInit(): Promise<void>;
|
|
5
|
+
setToken(token: any): Promise<boolean | null>;
|
|
6
|
+
request(url: string, data?: any): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class Storage {
|
|
10
|
+
storeData(key: string, value: any): Promise<void>;
|
|
11
|
+
getData(key: string): Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function initializePushNotifications(): Promise<string>;
|
|
15
|
+
export const networking: Networking;
|
|
16
|
+
export const storage: Storage;
|
|
17
|
+
}
|