core-outline 0.0.1 → 0.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/dist/index.es.js CHANGED
@@ -1,96 +1 @@
1
- const uuid = require('uuid');
2
- function createSessionUUID() {
3
- return uuid.v4();
4
- }
5
- const makeRequest = async ({
6
- url,
7
- service,
8
- body,
9
- params,
10
- method
11
- }) => {
12
- const res = await fetch(url).then(function (response) {
13
- return response.json();
14
- }).then(function (json) {
15
- console.log(json);
16
- return json;
17
- });
18
- return res;
19
- };
20
- async function getSessionLocation() {
21
- const res = await makeRequest({
22
- url: "http://ip-api.com/json",
23
- method: 'get'
24
- });
25
- return res;
26
- }
27
- const {
28
- userAgent
29
- } = navigator;
30
- let device = "mobile";
31
- const setDevice = dev => {
32
- device = dev;
33
- };
34
- userAgent.includes("Mobi") ? setDevice("mobile") : setDevice("desktop");
35
- const getDeviceInfo = () => {
36
- return device;
37
- };
38
- const startSession = async () => {
39
- let loc = await getSessionLocation();
40
- let session = {
41
- "session_id": createSessionUUID(),
42
- "start_time": Date.now(),
43
- "end_time": null,
44
- "device": getDeviceInfo()
45
- };
46
- session = {
47
- ...session,
48
- ...loc
49
- };
50
- console.log(session);
51
- return session;
52
- };
53
-
54
- const {
55
- io
56
- } = require('socket.io-client');
57
- const socket = io('http://localhost:4000');
58
- function streamData(data) {
59
- socket.emit('dataEvent', data);
60
- }
61
- const updatePage = async (session_id, pageDetails, location) => {
62
- let page = {};
63
- if (!pageDetails) {
64
- page = {
65
- "session_id": session_id,
66
- "start_date": Date.now(),
67
- "end_date": null,
68
- "page_name": location.pathname
69
- };
70
- return page;
71
- } else {
72
- pageDetails['end_date'] = Date.now();
73
- streamData({
74
- "topic": "page-data",
75
- "data": pageDetails
76
- });
77
- page = {
78
- "session_id": session_id,
79
- "start_date": Date.now(),
80
- "end_date": null,
81
- "page_name": location.pathname
82
- };
83
- return page;
84
- }
85
- };
86
-
87
- class CoreOutline {
88
- constructor(access_key, secret_id) {
89
- this.access_key = access_key;
90
- this.secret_id = secret_id;
91
- this.startSession = startSession;
92
- this.updatePage = updatePage;
93
- }
94
- }
95
-
96
- export { CoreOutline as default };
1
+ const t=require("uuid");async function e(){return await(async({url:t,service:e,body:s,params:i,method:n})=>await fetch(t).then((function(t){return t.json()})).then((function(t){return console.log(t),t})))({url:"http://ip-api.com/json",method:"get"})}const{userAgent:s}=navigator;let i="mobile";const n=t=>{i=t};s.includes("Mobi")?n("mobile"):n("desktop");const a=async()=>{let s=await e(),n={session_id:t.v4(),start_time:Date.now(),end_time:null,device:i};return n={...n,...s},console.log(n),n},{io:o}=require("socket.io-client"),c=o("http://localhost:4000");const r=async(t,e)=>{let s={};var i;return s={session_id:t,start_date:Date.now(),end_date:null,page_name:e},i={topic:"page-data",data:s},c.emit("dataEvent",i),s},{io:l}=require("socket.io-client"),d=l("http://localhost:4000");function u(t){d.emit("dataEvent",t)}const h=async t=>{u({topic:"target-data",session_id:t})},p=async(t,e)=>{u({topic:"click-data",session_id:t,item_id:e})};class _{constructor(t,e){this.access_key=t,this.secret_id=e,this.sessionDetails=a(),this.startSession=a,this.pageDetails=r(sessionDetails?.session_id,{}),this.updatePage=r,this.targetReached=h,this.registerClick=p}endSession(){this.sessionDetails.end_time=Date.now()}}export{_ as default};
package/dist/index.js CHANGED
@@ -1,98 +1 @@
1
- 'use strict';
2
-
3
- const uuid = require('uuid');
4
- function createSessionUUID() {
5
- return uuid.v4();
6
- }
7
- const makeRequest = async ({
8
- url,
9
- service,
10
- body,
11
- params,
12
- method
13
- }) => {
14
- const res = await fetch(url).then(function (response) {
15
- return response.json();
16
- }).then(function (json) {
17
- console.log(json);
18
- return json;
19
- });
20
- return res;
21
- };
22
- async function getSessionLocation() {
23
- const res = await makeRequest({
24
- url: "http://ip-api.com/json",
25
- method: 'get'
26
- });
27
- return res;
28
- }
29
- const {
30
- userAgent
31
- } = navigator;
32
- let device = "mobile";
33
- const setDevice = dev => {
34
- device = dev;
35
- };
36
- userAgent.includes("Mobi") ? setDevice("mobile") : setDevice("desktop");
37
- const getDeviceInfo = () => {
38
- return device;
39
- };
40
- const startSession = async () => {
41
- let loc = await getSessionLocation();
42
- let session = {
43
- "session_id": createSessionUUID(),
44
- "start_time": Date.now(),
45
- "end_time": null,
46
- "device": getDeviceInfo()
47
- };
48
- session = {
49
- ...session,
50
- ...loc
51
- };
52
- console.log(session);
53
- return session;
54
- };
55
-
56
- const {
57
- io
58
- } = require('socket.io-client');
59
- const socket = io('http://localhost:4000');
60
- function streamData(data) {
61
- socket.emit('dataEvent', data);
62
- }
63
- const updatePage = async (session_id, pageDetails, location) => {
64
- let page = {};
65
- if (!pageDetails) {
66
- page = {
67
- "session_id": session_id,
68
- "start_date": Date.now(),
69
- "end_date": null,
70
- "page_name": location.pathname
71
- };
72
- return page;
73
- } else {
74
- pageDetails['end_date'] = Date.now();
75
- streamData({
76
- "topic": "page-data",
77
- "data": pageDetails
78
- });
79
- page = {
80
- "session_id": session_id,
81
- "start_date": Date.now(),
82
- "end_date": null,
83
- "page_name": location.pathname
84
- };
85
- return page;
86
- }
87
- };
88
-
89
- class CoreOutline {
90
- constructor(access_key, secret_id) {
91
- this.access_key = access_key;
92
- this.secret_id = secret_id;
93
- this.startSession = startSession;
94
- this.updatePage = updatePage;
95
- }
96
- }
97
-
98
- module.exports = CoreOutline;
1
+ "use strict";const t=require("uuid");async function e(){return await(async({url:t,service:e,body:s,params:i,method:n})=>await fetch(t).then((function(t){return t.json()})).then((function(t){return console.log(t),t})))({url:"http://ip-api.com/json",method:"get"})}const{userAgent:s}=navigator;let i="mobile";const n=t=>{i=t};s.includes("Mobi")?n("mobile"):n("desktop");const o=async()=>{let s=await e(),n={session_id:t.v4(),start_time:Date.now(),end_time:null,device:i};return n={...n,...s},console.log(n),n},{io:a}=require("socket.io-client"),c=a("http://localhost:4000");const r=async(t,e)=>{let s={};var i;return s={session_id:t,start_date:Date.now(),end_date:null,page_name:e},i={topic:"page-data",data:s},c.emit("dataEvent",i),s},{io:l}=require("socket.io-client"),d=l("http://localhost:4000");function u(t){d.emit("dataEvent",t)}const h=async t=>{u({topic:"target-data",session_id:t})},p=async(t,e)=>{u({topic:"click-data",session_id:t,item_id:e})};module.exports=class{constructor(t,e){this.access_key=t,this.secret_id=e,this.sessionDetails=o(),this.startSession=o,this.pageDetails=r(sessionDetails?.session_id,{}),this.updatePage=r,this.targetReached=h,this.registerClick=p}endSession(){this.sessionDetails.end_time=Date.now()}};
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "core-outline",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "NPM package for react",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.es.js",
6
7
  "scripts": {
7
8
  "build-lib": "rollup -c",
8
9
  "test": "echo \"Error: no test specified\" && exit 1"
package/rollup.config.js CHANGED
@@ -29,7 +29,7 @@ export default [
29
29
  }),
30
30
  external(),
31
31
  resolve(),
32
- // terser(),
32
+ terser(),
33
33
  ]
34
34
  }
35
35
  ];
package/src/index.js CHANGED
@@ -1,13 +1,20 @@
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
4
  class CoreOutline {
5
5
  constructor(access_key, secret_id) {
6
6
  this.access_key = access_key;
7
7
  this.secret_id = secret_id;
8
+ this.sessionDetails = startSession();
8
9
  this.startSession = startSession;
10
+ this.pageDetails = updatePage(sessionDetails?.session_id, {}, "");
9
11
  this.updatePage = updatePage;
12
+ this.targetReached = targetReached;
13
+ this.registerClick = registerClick;
10
14
  }
15
+ endSession(){
16
+ this.sessionDetails.end_time = Date.now()
17
+ }
11
18
  }
12
19
 
13
20
  export default CoreOutline
@@ -0,0 +1,17 @@
1
+ const PouchDB = require('pouchdb');
2
+
3
+ const db = new PouchDB('core_outline_db');
4
+
5
+ const authentication=(access_id, secret_key)=>{
6
+ db.put({
7
+ access_id,
8
+ secret_key
9
+ }).then(function (response) {
10
+ return response
11
+ }).catch(function (err) {
12
+ return err
13
+ });
14
+ }
15
+
16
+ module.exports = authentication
17
+
package/src/lib/index.js CHANGED
@@ -3,3 +3,4 @@ export * from './uuid/createUUID.js'
3
3
  export * from './location/get-location.js'
4
4
  export * from './device/device.js'
5
5
  export * from './streams/producer.js'
6
+ export * from './database/database-operations.js'
@@ -3,4 +3,5 @@ export * from './session/start-session.js'
3
3
  export * from './session/end-session.js'
4
4
  export * from './target/update-target.js'
5
5
  export * from './time/get-time.js'
6
+ export * from './target/update-target.js'
6
7
 
@@ -5,29 +5,18 @@ function streamData(data){
5
5
  socket.emit('dataEvent', data);
6
6
  }
7
7
 
8
- const updatePage = async(session_id, pageDetails, location) =>{
8
+ const updatePage = async(session_id, location) =>{
9
9
  let page = {}
10
- if(!pageDetails){
11
- page = {
12
- "session_id": session_id,
13
- "start_date": Date.now(),
14
- "end_date": null,
15
- "page_name": location.pathname,
16
- }
17
- return page
18
- }
19
- else{
20
- pageDetails['end_date'] = Date.now()
21
- streamData({"topic":"page-data", "data" :pageDetails })
22
10
 
23
- page = {
24
- "session_id": session_id,
25
- "start_date": Date.now(),
26
- "end_date": null,
27
- "page_name": location.pathname,
28
- }
29
- return page
30
- }
11
+ page = {
12
+ "session_id": session_id,
13
+ "start_date": Date.now(),
14
+ "end_date": null,
15
+ "page_name": location,
16
+ }
17
+
18
+ streamData({"topic":"page-data", "data" : page })
19
+ return page
31
20
 
32
21
  }
33
22
 
@@ -1,20 +1,15 @@
1
- const request = require('../../lib/index.js')
2
- const { trackingConfigs, appConfigs } = require('../../config/index.js')
1
+ const { io} = require('socket.io-client');
2
+ const socket = io('http://localhost:4000');
3
3
 
4
- const targetReached = async(session_id, token) =>{
5
- const res = await(
6
- request({
7
- url: appConfigs.BASE_URL,
8
- service: trackingConfigs.TARGET_REACHED,
9
- body: {
10
- 'session_id':session_id
11
- },
12
- method:'POST',
13
- params:{
14
- Authorization: `Bearer ${token}`
15
- }
16
- })
17
- )
4
+ function streamData(data){
5
+ socket.emit('dataEvent', data);
6
+ }
7
+
8
+ export const targetReached = async(session_id) =>{
9
+ streamData({"topic":"target-data", "session_id" : session_id })
10
+ }
11
+
12
+ export const registerClick = async(session_id, item_id) =>{
13
+ streamData({"topic":"click-data", "session_id" : session_id, "item_id": item_id })
18
14
  }
19
15
 
20
- export default targetReached