apps-sdk 1.0.0 → 1.0.2

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,3 +1,10 @@
1
- export const INIT_URL = 'https://eu-an6009.gways.org/apps/init?domain=[DOMAIN]&install_id=[INSTALL_ID]';
2
- export const NOTIFICATION_TOKEN_URL = 'https://eu-an6009.gways.org/apps/token?token=[TOKEN]&install_id=[INSTALL_ID]';
3
- export const TRACKING_URL = 'https://eu-an6009.gways.org/event/send';
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 = true;
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import {NotificationsPush, Networking, Storage} from "./src/libraries";
1
+ import {NotificationsPush, Networking, Storage, Session} from "./src/libraries";
2
2
 
3
3
  class WebappsSDK {
4
4
  initializePushNotifications = async() => {
@@ -15,5 +15,6 @@ const Core = new WebappsSDK();
15
15
  export default {
16
16
  initializePushNotifications: Core.initializePushNotifications,
17
17
  networking: Networking,
18
- storage: Storage
18
+ storage: Storage,
19
+ session: Session
19
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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.18.2",
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-notifications": "^0.23.0"
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 getConfig(domain) {
29
+ async executeInit() {
30
+ config.DEBUG_MODE && console.debug("executeInit");
29
31
  try {
30
- let installID = await storage.getData('install_id');
31
- const response = await fetch(config.INIT_URL.replace('[DOMAIN]', domain).replace('[INSTALL_ID]', installID));
32
- const json = await response.json();
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,106 @@
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
+ }
105
+
106
+ export default new Session();
@@ -1,4 +1,5 @@
1
1
  export { default as NotificationsPush } from './Notifications';
2
2
  export { default as Networking } from './Networking';
3
3
  export { default as Storage } from './Storage';
4
+ export { default as Session } from './Session';
4
5
 
@@ -0,0 +1,36 @@
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 class Session {
15
+ sessionData: any;
16
+ sessionID: string | null;
17
+ isFirstOpen: boolean;
18
+ isSubscribed: boolean;
19
+ isDevUser: boolean;
20
+ init(): Promise<void>;
21
+ storeSessionStructure(): Promise<void>;
22
+ checkFirstOpen(): Promise<void>;
23
+ generateSessionID(): string;
24
+ getSessionData(): any;
25
+ getSessionID(): string | null;
26
+ getIsFirstOpen(): boolean;
27
+ getIsSubscribed(): boolean;
28
+ getIsDevUser(): boolean;
29
+ setIsSubscribed(isSubscribed: boolean): void;
30
+ setIsDevUser(isDevUser: boolean): void;
31
+ }
32
+
33
+ export function initializePushNotifications(): Promise<string>;
34
+ export const networking: Networking;
35
+ export const storage: Storage;
36
+ }