apps-sdk 1.0.13 → 1.0.14
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 +1 -1
- package/package.json +2 -1
- package/src/libraries/Networking.js +19 -10
- package/src/libraries/Session.js +6 -1
- package/types/index.d.ts +3 -1
package/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export var ENDPOINTS = {
|
|
2
2
|
INIT : 'https://ap0404.gways.org/v6/init',
|
|
3
3
|
NOTIFICATION_TOKEN: 'https://ap0404.gways.org/user/set_expo_id',
|
|
4
|
-
TRACKING: 'https://ap0404.gways.org/v3/',
|
|
4
|
+
TRACKING: 'https://ap0404.gways.org/v3/log-event',
|
|
5
5
|
GET_USER_ID: 'https://ap0404.gways.org/user/generate_public_id',
|
|
6
6
|
CHECK_SUBSCRIPTION: 'https://ap0404.gways.org/create-sub',
|
|
7
7
|
SET_ATTRIBUTION: 'https://ap0404.gways.org/user/set_attribution_data',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apps-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "Apps SDK",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@react-native-async-storage/async-storage": "^1.21.0",
|
|
13
13
|
"crypto-es": "^2.1.0",
|
|
14
|
+
"encode-utf8": "^2.0.0",
|
|
14
15
|
"expo-constants": "^15.4.5",
|
|
15
16
|
"expo-device": "^5.9.3",
|
|
16
17
|
"expo-localization": "^14.8.3",
|
|
@@ -2,6 +2,7 @@ import * as config from '../../config';
|
|
|
2
2
|
import { default as storage } from './Storage';
|
|
3
3
|
import Session from './Session';
|
|
4
4
|
import CryptoES from "crypto-es";
|
|
5
|
+
import encodeUtf8 from "encode-utf8";
|
|
5
6
|
|
|
6
7
|
class Networking {
|
|
7
8
|
constructor() {
|
|
@@ -9,11 +10,7 @@ class Networking {
|
|
|
9
10
|
this.DEFAULT_ENCRYPT_VALUE = false;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
setEncryptKey() {
|
|
13
|
-
return this.ENCRYPT_KEY;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
getEncryptKey(value) {
|
|
13
|
+
setEncryptKey(value) {
|
|
17
14
|
this.ENCRYPT_KEY = value;
|
|
18
15
|
}
|
|
19
16
|
|
|
@@ -89,16 +86,23 @@ class Networking {
|
|
|
89
86
|
|
|
90
87
|
async request(url, data = {}, encrypt = this.DEFAULT_ENCRYPT_VALUE) {
|
|
91
88
|
data = { ...Session.sessionData, ...data };
|
|
89
|
+
Object.keys(data).map(key => {
|
|
90
|
+
if (typeof data[key] === 'string') {
|
|
91
|
+
data[key] = encodeUtf8(data[key]);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
92
94
|
config.DEBUG_MODE && console.debug("request data: ", url, data);
|
|
93
95
|
|
|
94
96
|
let headers = { Accept: 'application/json', 'Content-Type': 'application/json' };
|
|
95
97
|
|
|
96
98
|
if (encrypt) {
|
|
97
|
-
const secretKey = this.ENCRYPT_KEY;
|
|
99
|
+
const secretKey = CryptoES.enc.Utf8.parse(this.ENCRYPT_KEY); // ensure key is 32 bytes
|
|
98
100
|
const iv = CryptoES.lib.WordArray.random(128/8);
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
const cipherParams = CryptoES.AES.encrypt(JSON.stringify(data), secretKey, { iv: iv, mode: CryptoES.mode.CBC, padding: CryptoES.pad.Pkcs7 });
|
|
102
|
+
const base64IV = CryptoES.enc.Base64.stringify(iv);
|
|
103
|
+
const base64Ciphertext = cipherParams.ciphertext.toString(CryptoES.enc.Base64);
|
|
104
|
+
data = { data: base64IV + '$' + base64Ciphertext };
|
|
105
|
+
headers['Content-Type'] = 'application/octet-stream; charset=utf-8';
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
try {
|
|
@@ -135,11 +139,15 @@ class Networking {
|
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
setEndpoints(domains) {
|
|
138
|
-
|
|
142
|
+
domains.contents && (config.ENDPOINTS.CONTENTS = domains.contents);
|
|
139
143
|
// domains.audiences && (config.ENDPOINTS.SET_ATTRIBUTION = domains.audiences);
|
|
140
144
|
// domains.notification_token && (config.ENDPOINTS.NOTIFICATION_TOKEN = domains.notification_token);
|
|
141
145
|
}
|
|
142
146
|
|
|
147
|
+
getEndpoints() {
|
|
148
|
+
return config.ENDPOINTS;
|
|
149
|
+
}
|
|
150
|
+
|
|
143
151
|
setEvents(events) {
|
|
144
152
|
events && (config.EVENTS = events);
|
|
145
153
|
}
|
|
@@ -149,6 +157,7 @@ class Networking {
|
|
|
149
157
|
try {
|
|
150
158
|
let eventResponse = await this.request(config.ENDPOINTS.TRACKING, {
|
|
151
159
|
event_name: eventType,
|
|
160
|
+
event_type: eventType,
|
|
152
161
|
action: eventKeyword,
|
|
153
162
|
data: eventData,
|
|
154
163
|
...Session.sessionData,
|
package/src/libraries/Session.js
CHANGED
|
@@ -56,6 +56,7 @@ class Session {
|
|
|
56
56
|
this.sessionData.isFirstOpen = !(await Storage.getData("FirstOpenAlreadyExecuted"));
|
|
57
57
|
if (this.sessionData.isFirstOpen) {
|
|
58
58
|
config.DEBUG_MODE && console.debug("checkFirstOpen - First Open");
|
|
59
|
+
await this.sendFirstOpen();
|
|
59
60
|
await Storage.storeData("FirstOpenAlreadyExecuted", true);
|
|
60
61
|
} else {
|
|
61
62
|
config.DEBUG_MODE && console.debug("checkFirstOpen - Not First Open");
|
|
@@ -84,9 +85,9 @@ class Session {
|
|
|
84
85
|
userID = await Networking.getUserID();
|
|
85
86
|
if (userID) {
|
|
86
87
|
await Storage.storeData("userID", userID);
|
|
87
|
-
this.setUserID(userID);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
+
this.setUserID(userID);
|
|
90
91
|
config.DEBUG_MODE && console.debug("checkUserID - userID: ", userID);
|
|
91
92
|
return userID;
|
|
92
93
|
}
|
|
@@ -123,6 +124,10 @@ class Session {
|
|
|
123
124
|
this.sessionData.user_id = userID;
|
|
124
125
|
}
|
|
125
126
|
|
|
127
|
+
getUserID = () => {
|
|
128
|
+
return this.sessionData.user_id;
|
|
129
|
+
}
|
|
130
|
+
|
|
126
131
|
sendFirstOpen = async () => {
|
|
127
132
|
config.DEBUG_MODE && console.debug("sendFirstOpen");
|
|
128
133
|
try {
|
package/types/index.d.ts
CHANGED
|
@@ -41,17 +41,19 @@ declare module 'apps-sdk' {
|
|
|
41
41
|
getIsDevUser(): boolean;
|
|
42
42
|
setIsSubscribed(isSubscribed: boolean): void;
|
|
43
43
|
setIsDevUser(isDevUser: boolean): void;
|
|
44
|
+
setUserID(userID: string): void;
|
|
45
|
+
getUserID(): string | null;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
export class Networking {
|
|
47
49
|
setEncryptKey(key: string): void;
|
|
48
|
-
getEncryptKey(): string;
|
|
49
50
|
setDefaultEncryptValue(value: boolean): void;
|
|
50
51
|
trackEvent(wid: string, event: string, user_id?: string | null): Promise<void>;
|
|
51
52
|
executeInit(): Promise<void>;
|
|
52
53
|
setToken(token: string): Promise<boolean | null>;
|
|
53
54
|
request(url: string, data?: any): Promise<any>;
|
|
54
55
|
setEndpoints(endpoints: any): void;
|
|
56
|
+
getEndpoints(): any;
|
|
55
57
|
setEvents(events: any): void;
|
|
56
58
|
sendEvent(eventType: string, eventKeyword:string, eventData?: object): Promise<void>;
|
|
57
59
|
}
|