core-outline 0.0.9 → 0.1.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/README.md CHANGED
@@ -9,7 +9,7 @@ npm i core-outline
9
9
 
10
10
  ### Starting a new instance
11
11
 
12
- var core = new CoreOutline(<access_id>, <secret_key>)
12
+ var core = new CoreOutline(<app_id>)
13
13
 
14
14
  ### To get the session details
15
15
  var session_details = core.sessionDetails()
@@ -19,24 +19,27 @@ var session_details = core.sessionDetails()
19
19
  "session_id":"<session_id>",
20
20
  }
21
21
  """
22
+ ### End current session
23
+ endCurrentSession()
24
+
22
25
  # Tracking user actions
23
26
  ### Update current page
24
27
 
25
28
  Use this function when a user enters a page:
26
29
 
27
- core.updatePage(session_details.session_id, <current_page_name>)
30
+ core.setCurrentPage(<current_page_name>, <is_terminal>)
28
31
 
29
32
  ### Register a made purchase
30
33
 
31
34
  Add this function to an onclick listener for when a user completes a transaction
32
35
 
33
- core.targetReached(session_details.session_id)
36
+ core.recordPurchase()
34
37
 
35
38
  ### Register an action item click
36
39
 
37
40
  This function is to be used when a user clicks on one of the recommended actions items
38
41
 
39
- core.registerClick(session_details.session_id, <recommended_action_item_name>)
42
+ core.recordItemClick(<recommended_action_item_id>)
40
43
 
41
44
 
42
45
 
package/dist/index.es.js CHANGED
@@ -1,10 +1,10 @@
1
1
  const uuid = require('uuid');
2
2
  const {
3
- io: io$2
3
+ io: io$3
4
4
  } = require('socket.io-client');
5
- const socket$2 = io$2('http://localhost:4000');
6
- function streamData$2(data) {
7
- socket$2.emit('dataEvent', data);
5
+ const socket$3 = io$3('http://52.35.48.129:4000');
6
+ function streamData$3(data) {
7
+ socket$3.emit('dataEvent', data);
8
8
  }
9
9
  const makeRequest = async ({
10
10
  url,
@@ -13,12 +13,26 @@ const makeRequest = async ({
13
13
  params,
14
14
  method
15
15
  }) => {
16
- const res = await fetch(url).then(function (response) {
17
- return response.json();
18
- }).then(function (json) {
19
- console.log(json);
20
- return json;
21
- });
16
+ let res;
17
+ console.log(url);
18
+ console.log(params);
19
+ if (params) {
20
+ res = await fetch(`${url}${params}`).then(function (response) {
21
+ console.log(response);
22
+ return response.json();
23
+ }).then(function (json) {
24
+ console.log(json);
25
+ return json;
26
+ });
27
+ } else {
28
+ res = await fetch(`${url}`).then(function (response) {
29
+ console.log(response);
30
+ return response.json();
31
+ }).then(function (json) {
32
+ console.log(json);
33
+ return json;
34
+ });
35
+ }
22
36
  return res;
23
37
  };
24
38
  async function getSessionLocation() {
@@ -28,82 +42,115 @@ async function getSessionLocation() {
28
42
  });
29
43
  return res;
30
44
  }
31
- const startSession = async () => {
45
+ async function getAppDetails(app_id) {
46
+ const res = await makeRequest({
47
+ url: "http://52.35.48.129:5000/data-source/get-data-source",
48
+ method: 'get',
49
+ params: `?type=saas&app_id=${app_id}`
50
+ });
51
+ return res;
52
+ }
53
+ const startSession = async app_id => {
32
54
  let loc = await getSessionLocation();
55
+ console.log(loc);
56
+ data_source = await getAppDetails(app_id);
57
+ console.log(data_source);
33
58
  let session = {
59
+ "topic": "session-data",
60
+ "data_source_id": data_source?.data_source_id,
34
61
  "session_id": uuid.v4(),
35
- "start_time": Date.now(),
36
- "end_time": null,
37
- "device": "getDeviceInfo()"
38
- };
39
- session = {
40
- ...session,
41
- ...loc
62
+ "start_date": new Date(Date.now()).toDateString(),
63
+ "latitude": loc?.lat,
64
+ "longitude": loc?.lon,
65
+ "country": loc?.country,
66
+ "region": loc?.regionName,
67
+ "city": loc?.city,
68
+ "device": "getDeviceInfo"
42
69
  };
43
70
  console.log(session);
44
- streamData$2({
45
- "topic": "session-data",
46
- "data": session
47
- });
71
+ streamData$3(session);
48
72
  return session;
49
73
  };
50
74
 
51
75
  const {
52
- io: io$1
76
+ io: io$2
53
77
  } = require('socket.io-client');
54
- const socket$1 = io$1('http://localhost:4000');
55
- function streamData$1(data) {
56
- socket$1.emit('dataEvent', data);
78
+ const socket$2 = io$2('http://52.35.48.129:4000');
79
+ function streamData$2(data) {
80
+ socket$2.emit('dataEvent', data);
57
81
  }
58
- const updatePage = async (session_id, location) => {
82
+ const updatePage = async (session_id, location, is_terminal = false) => {
59
83
  let page = {};
60
84
  page = {
85
+ "topic": "page-data",
61
86
  "session_id": session_id,
62
- "start_date": Date.now(),
63
- "end_date": null,
64
- "page_name": location
87
+ "start_date": new Date(Date.now()).toDateString(),
88
+ "page_name": location,
89
+ "is_terminal": is_terminal
65
90
  };
66
- streamData$1({
67
- "topic": "page-data",
68
- "data": page
69
- });
91
+ streamData$2(page);
70
92
  return page;
71
93
  };
72
94
 
73
95
  const {
74
- io
96
+ io: io$1
75
97
  } = require('socket.io-client');
76
- const socket = io('http://localhost:4000');
77
- function streamData(data) {
78
- socket.emit('dataEvent', data);
98
+ const socket$1 = io$1('http://52.35.48.129:4000');
99
+ function streamData$1(data) {
100
+ socket$1.emit('dataEvent', data);
79
101
  }
80
102
  const targetReached = async session_id => {
81
- streamData({
82
- "topic": "target-data",
83
- "session_id": session_id
103
+ streamData$1({
104
+ "topic": "update-session-data",
105
+ "session_id": session_id,
106
+ "click_through": true
84
107
  });
85
108
  };
86
109
  const registerClick = async (session_id, item_id) => {
87
- streamData({
88
- "topic": "click-data",
110
+ streamData$1({
111
+ "topic": "update-session-data",
89
112
  "session_id": session_id,
90
- "item_id": item_id
113
+ "item_clicked": item_id
114
+ });
115
+ };
116
+
117
+ const {
118
+ io
119
+ } = require('socket.io-client');
120
+ const socket = io('http://52.35.48.129:4000');
121
+ function streamData(data) {
122
+ socket.emit('dataEvent', data);
123
+ }
124
+ const endSession = async (session_id, end_date) => {
125
+ streamData({
126
+ topic: "update-session-data",
127
+ session_id,
128
+ end_date
91
129
  });
92
130
  };
93
131
 
94
132
  class CoreOutline {
95
- constructor(access_key, secret_id) {
96
- this.access_key = access_key;
97
- this.secret_id = secret_id;
98
- this.sessionDetails = startSession();
133
+ constructor(app_id) {
134
+ this.sessionDetails = startSession(app_id);
99
135
  this.startSession = startSession;
100
- this.pageDetails = updatePage(this.sessionDetails?.session_id, {});
136
+ this.endSession = endSession;
137
+ this.pageDetails = updatePage(this.sessionDetails?.session_id, "");
101
138
  this.updatePage = updatePage;
102
139
  this.targetReached = targetReached;
103
140
  this.registerClick = registerClick;
104
141
  }
105
- endSession() {
106
- this.sessionDetails.end_time = Date.now();
142
+ endCurrentSession() {
143
+ this.sessionDetails.end_time = new Date(Date.now()).toDateString();
144
+ this.endSession(this.sessionDetails?.session_id, this.sessionDetails.end_time);
145
+ }
146
+ setCurrentPage(page_name, is_terminal = false) {
147
+ this.updatePage(this.sessionDetails?.session_id, page_name, is_terminal);
148
+ }
149
+ recordPurchase() {
150
+ this.targetReached(this.sessionDetails?.session_id);
151
+ }
152
+ recordItemClick(item_id) {
153
+ this.registerClick(this.sessionDetails?.session_id, item_id);
107
154
  }
108
155
  }
109
156
 
package/dist/index.js CHANGED
@@ -4,11 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const uuid = require('uuid');
6
6
  const {
7
- io: io$2
7
+ io: io$3
8
8
  } = require('socket.io-client');
9
- const socket$2 = io$2('http://localhost:4000');
10
- function streamData$2(data) {
11
- socket$2.emit('dataEvent', data);
9
+ const socket$3 = io$3('http://52.35.48.129:4000');
10
+ function streamData$3(data) {
11
+ socket$3.emit('dataEvent', data);
12
12
  }
13
13
  const makeRequest = async ({
14
14
  url,
@@ -17,12 +17,26 @@ const makeRequest = async ({
17
17
  params,
18
18
  method
19
19
  }) => {
20
- const res = await fetch(url).then(function (response) {
21
- return response.json();
22
- }).then(function (json) {
23
- console.log(json);
24
- return json;
25
- });
20
+ let res;
21
+ console.log(url);
22
+ console.log(params);
23
+ if (params) {
24
+ res = await fetch(`${url}${params}`).then(function (response) {
25
+ console.log(response);
26
+ return response.json();
27
+ }).then(function (json) {
28
+ console.log(json);
29
+ return json;
30
+ });
31
+ } else {
32
+ res = await fetch(`${url}`).then(function (response) {
33
+ console.log(response);
34
+ return response.json();
35
+ }).then(function (json) {
36
+ console.log(json);
37
+ return json;
38
+ });
39
+ }
26
40
  return res;
27
41
  };
28
42
  async function getSessionLocation() {
@@ -32,82 +46,115 @@ async function getSessionLocation() {
32
46
  });
33
47
  return res;
34
48
  }
35
- const startSession = async () => {
49
+ async function getAppDetails(app_id) {
50
+ const res = await makeRequest({
51
+ url: "http://52.35.48.129:5000/data-source/get-data-source",
52
+ method: 'get',
53
+ params: `?type=saas&app_id=${app_id}`
54
+ });
55
+ return res;
56
+ }
57
+ const startSession = async app_id => {
36
58
  let loc = await getSessionLocation();
59
+ console.log(loc);
60
+ data_source = await getAppDetails(app_id);
61
+ console.log(data_source);
37
62
  let session = {
63
+ "topic": "session-data",
64
+ "data_source_id": data_source?.data_source_id,
38
65
  "session_id": uuid.v4(),
39
- "start_time": Date.now(),
40
- "end_time": null,
41
- "device": "getDeviceInfo()"
42
- };
43
- session = {
44
- ...session,
45
- ...loc
66
+ "start_date": new Date(Date.now()).toDateString(),
67
+ "latitude": loc?.lat,
68
+ "longitude": loc?.lon,
69
+ "country": loc?.country,
70
+ "region": loc?.regionName,
71
+ "city": loc?.city,
72
+ "device": "getDeviceInfo"
46
73
  };
47
74
  console.log(session);
48
- streamData$2({
49
- "topic": "session-data",
50
- "data": session
51
- });
75
+ streamData$3(session);
52
76
  return session;
53
77
  };
54
78
 
55
79
  const {
56
- io: io$1
80
+ io: io$2
57
81
  } = require('socket.io-client');
58
- const socket$1 = io$1('http://localhost:4000');
59
- function streamData$1(data) {
60
- socket$1.emit('dataEvent', data);
82
+ const socket$2 = io$2('http://52.35.48.129:4000');
83
+ function streamData$2(data) {
84
+ socket$2.emit('dataEvent', data);
61
85
  }
62
- const updatePage = async (session_id, location) => {
86
+ const updatePage = async (session_id, location, is_terminal = false) => {
63
87
  let page = {};
64
88
  page = {
89
+ "topic": "page-data",
65
90
  "session_id": session_id,
66
- "start_date": Date.now(),
67
- "end_date": null,
68
- "page_name": location
91
+ "start_date": new Date(Date.now()).toDateString(),
92
+ "page_name": location,
93
+ "is_terminal": is_terminal
69
94
  };
70
- streamData$1({
71
- "topic": "page-data",
72
- "data": page
73
- });
95
+ streamData$2(page);
74
96
  return page;
75
97
  };
76
98
 
77
99
  const {
78
- io
100
+ io: io$1
79
101
  } = require('socket.io-client');
80
- const socket = io('http://localhost:4000');
81
- function streamData(data) {
82
- socket.emit('dataEvent', data);
102
+ const socket$1 = io$1('http://52.35.48.129:4000');
103
+ function streamData$1(data) {
104
+ socket$1.emit('dataEvent', data);
83
105
  }
84
106
  const targetReached = async session_id => {
85
- streamData({
86
- "topic": "target-data",
87
- "session_id": session_id
107
+ streamData$1({
108
+ "topic": "update-session-data",
109
+ "session_id": session_id,
110
+ "click_through": true
88
111
  });
89
112
  };
90
113
  const registerClick = async (session_id, item_id) => {
91
- streamData({
92
- "topic": "click-data",
114
+ streamData$1({
115
+ "topic": "update-session-data",
93
116
  "session_id": session_id,
94
- "item_id": item_id
117
+ "item_clicked": item_id
118
+ });
119
+ };
120
+
121
+ const {
122
+ io
123
+ } = require('socket.io-client');
124
+ const socket = io('http://52.35.48.129:4000');
125
+ function streamData(data) {
126
+ socket.emit('dataEvent', data);
127
+ }
128
+ const endSession = async (session_id, end_date) => {
129
+ streamData({
130
+ topic: "update-session-data",
131
+ session_id,
132
+ end_date
95
133
  });
96
134
  };
97
135
 
98
136
  class CoreOutline {
99
- constructor(access_key, secret_id) {
100
- this.access_key = access_key;
101
- this.secret_id = secret_id;
102
- this.sessionDetails = startSession();
137
+ constructor(app_id) {
138
+ this.sessionDetails = startSession(app_id);
103
139
  this.startSession = startSession;
104
- this.pageDetails = updatePage(this.sessionDetails?.session_id, {});
140
+ this.endSession = endSession;
141
+ this.pageDetails = updatePage(this.sessionDetails?.session_id, "");
105
142
  this.updatePage = updatePage;
106
143
  this.targetReached = targetReached;
107
144
  this.registerClick = registerClick;
108
145
  }
109
- endSession() {
110
- this.sessionDetails.end_time = Date.now();
146
+ endCurrentSession() {
147
+ this.sessionDetails.end_time = new Date(Date.now()).toDateString();
148
+ this.endSession(this.sessionDetails?.session_id, this.sessionDetails.end_time);
149
+ }
150
+ setCurrentPage(page_name, is_terminal = false) {
151
+ this.updatePage(this.sessionDetails?.session_id, page_name, is_terminal);
152
+ }
153
+ recordPurchase() {
154
+ this.targetReached(this.sessionDetails?.session_id);
155
+ }
156
+ recordItemClick(item_id) {
157
+ this.registerClick(this.sessionDetails?.session_id, item_id);
111
158
  }
112
159
  }
113
160
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-outline",
3
- "version": "0.0.9",
3
+ "version": "0.1.1",
4
4
  "description": "NPM package for react",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.es.js",
package/src/index.js CHANGED
@@ -1,20 +1,31 @@
1
1
  import startSession from "./services/session/start-session";
2
2
  import updatePage from "./services/page/update-page";
3
3
  import { targetReached, registerClick } from "./services/target/update-target"
4
+ import endSession from "./services/session/end-session";
5
+
4
6
 
5
7
  export class CoreOutline {
6
- constructor(access_key, secret_id) {
7
- this.access_key = access_key;
8
- this.secret_id = secret_id;
9
- this.sessionDetails = startSession();
8
+ constructor(app_id) {
9
+ this.sessionDetails = startSession(app_id);
10
10
  this.startSession = startSession;
11
- this.pageDetails = updatePage(this.sessionDetails?.session_id, {}, "");
11
+ this.endSession = endSession;
12
+ this.pageDetails = updatePage(this.sessionDetails?.session_id, "");
12
13
  this.updatePage = updatePage;
13
14
  this.targetReached = targetReached;
14
15
  this.registerClick = registerClick;
15
16
  }
16
- endSession(){
17
- this.sessionDetails.end_time = Date.now()
17
+ endCurrentSession(){
18
+ this.sessionDetails.end_time =new Date(Date.now()).toDateString()
19
+ this.endSession(this.sessionDetails?.session_id, this.sessionDetails.end_time)
20
+ }
21
+ setCurrentPage(page_name, is_terminal=false){
22
+ this.updatePage(this.sessionDetails?.session_id, page_name, is_terminal)
23
+ }
24
+ recordPurchase(){
25
+ this.targetReached(this.sessionDetails?.session_id)
26
+ }
27
+ recordItemClick(item_id){
28
+ this.registerClick(this.sessionDetails?.session_id, item_id)
18
29
  }
19
30
  }
20
31
 
@@ -1,7 +1,7 @@
1
- const makeRequest = async ({
1
+ const makeRequest = async (
2
2
  url, service, body, params, method,
3
- }) => {
4
- return await fetch(url)
3
+ ) => {
4
+ return await fetch(`${url}`)
5
5
  .then(function(response) {
6
6
  return response.json();
7
7
  })
@@ -1,5 +1,5 @@
1
1
  const { io} = require('socket.io-client');
2
- const socket = io('http://localhost:4000');
2
+ const socket = io('http://52.35.48.129:4000');
3
3
 
4
4
  function streamData(data){
5
5
  socket.emit('dataEvent', data);
@@ -1,24 +1,26 @@
1
1
  const { io} = require('socket.io-client');
2
- const socket = io('http://localhost:4000');
2
+ const socket = io('http://52.35.48.129:4000');
3
3
 
4
4
  function streamData(data){
5
5
  socket.emit('dataEvent', data);
6
6
  }
7
7
 
8
- const updatePage = async(session_id, location) =>{
8
+ const updatePage = async(session_id, location, is_terminal=false) =>{
9
9
  let page = {}
10
10
 
11
11
  page = {
12
+ "topic":"page-data",
12
13
  "session_id": session_id,
13
- "start_date": Date.now(),
14
- "end_date": null,
14
+ "start_date": new Date(Date.now()).toDateString(),
15
15
  "page_name": location,
16
+ "is_terminal": is_terminal
16
17
  }
17
18
 
18
- streamData({"topic":"page-data", "data" : page })
19
+ streamData(page)
19
20
  return page
20
21
 
21
22
  }
22
23
 
23
24
 
25
+
24
26
  export default updatePage
@@ -1,20 +1,19 @@
1
- const request = require('../../lib/index.js')
2
- const { trackingConfigs, appConfigs } = require('../../config/index.js')
3
1
 
4
- const endSession = async(session_id, token) =>{
5
- const res = await(
6
- request({
7
- url: appConfigs.BASE_URL,
8
- service: trackingConfigs.END_SESSION,
9
- body: {
10
- 'session_id':session_id
11
- },
12
- method:'POST',
13
- params:{
14
- Authorization: `Bearer ${token}`
15
- }
16
- })
17
- )
2
+ const { io} = require('socket.io-client');
3
+ const socket = io('http://52.35.48.129:4000');
4
+
5
+ function streamData(data){
6
+ socket.emit('dataEvent', data);
7
+ }
8
+
9
+ const endSession = async(session_id, end_date) =>{
10
+ streamData({
11
+ topic:"update-session-data",
12
+ session_id,
13
+ end_date
14
+ })
18
15
  }
19
16
 
17
+
18
+ // endSession('41d600e4-6c17-4626-bff4-8c173f904104', new Date(Date.now()).toLocaleString())
20
19
  export default endSession
@@ -1,6 +1,6 @@
1
1
  const uuid = require('uuid')
2
2
  const { io} = require('socket.io-client');
3
- const socket = io('http://localhost:4000');
3
+ const socket = io('http://52.35.48.129:4000');
4
4
 
5
5
  function streamData(data){
6
6
  socket.emit('dataEvent', data);
@@ -9,14 +9,32 @@ function streamData(data){
9
9
  const makeRequest = async ({
10
10
  url, service, body, params, method,
11
11
  }) => {
12
- const res = await fetch(url)
12
+ let res
13
+ console.log(url)
14
+ console.log(params)
15
+ if(params){
16
+ res = await fetch(`${url}${params}`)
13
17
  .then(function(response) {
14
- return response.json();
18
+ console.log(response)
19
+ return response.json();
15
20
  })
16
21
  .then(function(json) {
17
22
  console.log(json)
18
23
  return json
19
- });
24
+ });
25
+ }
26
+ else{
27
+ res = await fetch(`${url}`)
28
+ .then(function(response) {
29
+ console.log(response)
30
+ return response.json();
31
+ })
32
+ .then(function(json) {
33
+ console.log(json)
34
+ return json
35
+ });
36
+ }
37
+
20
38
  return res
21
39
  }
22
40
 
@@ -29,21 +47,40 @@ async function getSessionLocation()
29
47
  return res
30
48
  }
31
49
 
50
+ async function getAppDetails(app_id)
51
+ {
52
+ const res = await makeRequest({
53
+ url: "http://52.35.48.129:5000/data-source/get-data-source",
54
+ method: 'get',
55
+ params: `?type=saas&app_id=${app_id}`
56
+ })
57
+ return res
58
+ }
59
+
32
60
 
33
- const startSession = async() =>{
61
+
62
+ const startSession = async(app_id) =>{
34
63
  let loc = await getSessionLocation()
64
+ console.log(loc)
65
+ data_source = await getAppDetails(app_id)
66
+ console.log(data_source)
67
+
35
68
  let session = {
69
+ "topic":"session-data",
70
+ "data_source_id": data_source?.data_source_id,
36
71
  "session_id": uuid.v4(),
37
- "start_time": Date.now(),
38
- "end_time" : null,
39
- "device": "getDeviceInfo()",
72
+ "start_date": new Date(Date.now()).toDateString(),
73
+ "latitude": loc?.lat,
74
+ "longitude": loc?.lon,
75
+ "country": loc?.country,
76
+ "region": loc?.regionName,
77
+ "city": loc?.city,
78
+ "device": "getDeviceInfo",
40
79
  }
41
- session = { ...session, ...loc}
42
80
  console.log(session)
43
81
 
44
- streamData({"topic":"session-data", "data" : session })
82
+ streamData(session)
45
83
 
46
84
  return session
47
85
  }
48
-
49
86
  export default startSession
@@ -1,15 +1,15 @@
1
1
  const { io} = require('socket.io-client');
2
- const socket = io('http://localhost:4000');
2
+ const socket = io('http://52.35.48.129:4000');
3
3
 
4
4
  function streamData(data){
5
5
  socket.emit('dataEvent', data);
6
6
  }
7
7
 
8
8
  export const targetReached = async(session_id) =>{
9
- streamData({"topic":"target-data", "session_id" : session_id })
9
+ streamData({"topic":"update-session-data", "session_id" : session_id, "click_through": true })
10
10
  }
11
11
 
12
12
  export const registerClick = async(session_id, item_id) =>{
13
- streamData({"topic":"click-data", "session_id" : session_id, "item_id": item_id })
13
+ streamData({"topic":"update-session-data", "session_id" : session_id, "item_clicked": item_id })
14
14
  }
15
15