apps-sdk 1.0.12 → 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 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.12",
3
+ "version": "1.0.14",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,8 +10,9 @@
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "@react-native-async-storage/async-storage": "^1.21.0",
13
+ "crypto-es": "^2.1.0",
14
+ "encode-utf8": "^2.0.0",
13
15
  "expo-constants": "^15.4.5",
14
- "expo-crypto": "^12.8.0",
15
16
  "expo-device": "^5.9.3",
16
17
  "expo-localization": "^14.8.3",
17
18
  "expo-notifications": "^0.23.0",
@@ -1,7 +1,8 @@
1
1
  import * as config from '../../config';
2
2
  import { default as storage } from './Storage';
3
3
  import Session from './Session';
4
- import * as Crypto from 'expo-crypto';
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,19 +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;
98
- const encryptedData = await Crypto.digestStringAsync(
99
- Crypto.CryptoDigestAlgorithm.SHA256,
100
- JSON.stringify(data),
101
- { encoding: Crypto.CryptoEncoding.BASE64 }
102
- );
103
- data = { data: encryptedData };
104
- headers['Content-Type'] = 'application/octet-stream';
99
+ const secretKey = CryptoES.enc.Utf8.parse(this.ENCRYPT_KEY); // ensure key is 32 bytes
100
+ const iv = CryptoES.lib.WordArray.random(128/8);
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';
105
106
  }
106
107
 
107
108
  try {
@@ -138,11 +139,15 @@ class Networking {
138
139
  }
139
140
 
140
141
  setEndpoints(domains) {
141
- // domains.events && (config.ENDPOINTS.TRACKING = domains.events);
142
+ domains.contents && (config.ENDPOINTS.CONTENTS = domains.contents);
142
143
  // domains.audiences && (config.ENDPOINTS.SET_ATTRIBUTION = domains.audiences);
143
144
  // domains.notification_token && (config.ENDPOINTS.NOTIFICATION_TOKEN = domains.notification_token);
144
145
  }
145
146
 
147
+ getEndpoints() {
148
+ return config.ENDPOINTS;
149
+ }
150
+
146
151
  setEvents(events) {
147
152
  events && (config.EVENTS = events);
148
153
  }
@@ -152,6 +157,7 @@ class Networking {
152
157
  try {
153
158
  let eventResponse = await this.request(config.ENDPOINTS.TRACKING, {
154
159
  event_name: eventType,
160
+ event_type: eventType,
155
161
  action: eventKeyword,
156
162
  data: eventData,
157
163
  ...Session.sessionData,
@@ -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
  }