core-outline 0.0.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.
@@ -0,0 +1,96 @@
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 };
package/dist/index.js ADDED
@@ -0,0 +1,98 @@
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;
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "core-outline",
3
+ "version": "0.0.1",
4
+ "description": "NPM package for react",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build-lib": "rollup -c",
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Core-Outline/core-outline-npm.git"
13
+ },
14
+ "keywords": [
15
+ "core",
16
+ "outline"
17
+ ],
18
+ "author": "Core&Outline",
19
+ "license": "ISC",
20
+ "bugs": {
21
+ "url": "https://github.com/Core-Outline/core-outline-npm/issues"
22
+ },
23
+ "homepage": "https://github.com/Core-Outline/core-outline-npm#readme",
24
+ "devDependencies": {
25
+ "@babel/preset-react": "^7.24.6",
26
+ "@rollup/plugin-node-resolve": "^15.2.3",
27
+ "pouchdb": "^8.0.1",
28
+ "rollup": "^2.79.1",
29
+ "rollup-plugin-babel": "^4.4.0",
30
+ "rollup-plugin-peer-deps-external": "^2.2.4",
31
+ "rollup-plugin-postcss": "^4.0.2",
32
+ "rollup-plugin-terser": "^7.0.2",
33
+ "socket.io-client": "^4.7.5",
34
+ "uuid": "^9.0.1"
35
+ }
36
+ }
@@ -0,0 +1,35 @@
1
+ import babel from 'rollup-plugin-babel';
2
+ import resolve from '@rollup/plugin-node-resolve';
3
+ import external from 'rollup-plugin-peer-deps-external';
4
+ import { terser } from 'rollup-plugin-terser';
5
+ import postcss from 'rollup-plugin-postcss';
6
+
7
+ export default [
8
+ {
9
+ input: './src/index.js',
10
+ output: [
11
+ {
12
+ file: 'dist/index.js',
13
+ format: 'cjs',
14
+ },
15
+ {
16
+ file: 'dist/index.es.js',
17
+ format: 'es',
18
+ exports: 'named',
19
+ }
20
+ ],
21
+ plugins: [
22
+ postcss({
23
+ plugins: [],
24
+ minimize: true,
25
+ }),
26
+ babel({
27
+ exclude: 'node_modules/**',
28
+ presets: ['@babel/preset-react']
29
+ }),
30
+ external(),
31
+ resolve(),
32
+ // terser(),
33
+ ]
34
+ }
35
+ ];
@@ -0,0 +1,3 @@
1
+ const app_configs = {
2
+ BASE_URL: `https://api.coreoutline.com`,
3
+ }
@@ -0,0 +1,7 @@
1
+
2
+ const LOCATION_ENDPOINT = "http://ip-api.com/json"
3
+
4
+
5
+ module.exports = {
6
+ LOCATION_ENDPOINT
7
+ }
@@ -0,0 +1,10 @@
1
+ const tracking_endpoints = {
2
+ START_SESSION: "/start-session",
3
+ END_SESSION: "/end-session",
4
+ UPDATE_PAGE: "/update-session",
5
+ TARGET_REACHED:"/update-target"
6
+ }
7
+
8
+ module.exports = {
9
+ tracking_endpoints,
10
+ }
@@ -0,0 +1,10 @@
1
+ const trackingConfigs = require('./components/tracking.js')
2
+ const appConfigs = require('./components/app.js')
3
+ const locationConfigs = require('./components/location.js')
4
+
5
+
6
+ module.exports = {
7
+ trackingConfigs,
8
+ appConfigs,
9
+ locationConfigs
10
+ }
package/src/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import startSession from "./services/session/start-session";
2
+ import updatePage from "./services/page/update-page";
3
+
4
+ class CoreOutline {
5
+ constructor(access_key, secret_id) {
6
+ this.access_key = access_key;
7
+ this.secret_id = secret_id;
8
+ this.startSession = startSession;
9
+ this.updatePage = updatePage;
10
+ }
11
+ }
12
+
13
+ export default CoreOutline
File without changes
@@ -0,0 +1,7 @@
1
+
2
+
3
+ const getCurrentDate =()=> new Date().toJSON().slice(0, 10);
4
+
5
+ module.exports = {
6
+ getCurrentDate
7
+ }
@@ -0,0 +1,17 @@
1
+ const { userAgent } = navigator;
2
+ let device="mobile"
3
+
4
+ const setDevice=(dev)=>{
5
+ device=dev
6
+ }
7
+
8
+ userAgent.includes("Mobi") ? setDevice("mobile") : setDevice("desktop");
9
+
10
+
11
+ const getDeviceInfo=()=>{
12
+ console.log(userAgent);
13
+ return device
14
+ }
15
+
16
+
17
+ module.exports = getDeviceInfo
@@ -0,0 +1,5 @@
1
+ export * from './request/app.js'
2
+ export * from './uuid/createUUID.js'
3
+ export * from './location/get-location.js'
4
+ export * from './device/device.js'
5
+ export * from './streams/producer.js'
@@ -0,0 +1,27 @@
1
+ const { locationConfigs } = require("../../config/index.js")
2
+ // const { makeRequest } = require("../index.js")
3
+
4
+ const makeRequest = async ({
5
+ url, service, body, params, method,
6
+ }) => {
7
+ const res = await fetch(url)
8
+ .then(function(response) {
9
+ return response.json();
10
+ })
11
+ .then(function(json) {
12
+ console.log(json)
13
+ return json
14
+ });
15
+ return res
16
+ }
17
+
18
+ async function getSessionLocation()
19
+ {
20
+ const res = await makeRequest({
21
+ url: locationConfigs.LOCATION_ENDPOINT,
22
+ method: 'get'
23
+ })
24
+ console.log('Loc', res)
25
+ return res
26
+ }
27
+ module.exports = getSessionLocation
File without changes
@@ -0,0 +1,13 @@
1
+ const makeRequest = async ({
2
+ url, service, body, params, method,
3
+ }) => {
4
+ return await fetch(url)
5
+ .then(function(response) {
6
+ return response.json();
7
+ })
8
+ .then(function(json) {
9
+ console.log(json)
10
+ });
11
+ }
12
+
13
+ module.exports = makeRequest;
@@ -0,0 +1,8 @@
1
+ const { io} = require('socket.io-client');
2
+ const socket = io('http://localhost:4000');
3
+
4
+ function streamData(data){
5
+ socket.emit('dataEvent', data);
6
+ }
7
+
8
+ module.exports = streamData
@@ -0,0 +1,7 @@
1
+ const uuid = require('uuid')
2
+
3
+ function createSessionUUID()
4
+ {
5
+ return uuid.v4()
6
+ }
7
+ module.exports = createSessionUUID
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ export * from "./page/update-page.js"
2
+ export * from './session/start-session.js'
3
+ export * from './session/end-session.js'
4
+ export * from './target/update-target.js'
5
+ export * from './time/get-time.js'
6
+
@@ -0,0 +1,35 @@
1
+ const { io} = require('socket.io-client');
2
+ const socket = io('http://localhost:4000');
3
+
4
+ function streamData(data){
5
+ socket.emit('dataEvent', data);
6
+ }
7
+
8
+ const updatePage = async(session_id, pageDetails, location) =>{
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
+
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
+ }
31
+
32
+ }
33
+
34
+
35
+ export default updatePage
@@ -0,0 +1,20 @@
1
+ const request = require('../../lib/index.js')
2
+ const { trackingConfigs, appConfigs } = require('../../config/index.js')
3
+
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
+ )
18
+ }
19
+
20
+ export default endSession
@@ -0,0 +1,59 @@
1
+ const uuid = require('uuid')
2
+
3
+ function createSessionUUID()
4
+ {
5
+ return uuid.v4()
6
+ }
7
+
8
+ const makeRequest = async ({
9
+ url, service, body, params, method,
10
+ }) => {
11
+ const res = await fetch(url)
12
+ .then(function(response) {
13
+ return response.json();
14
+ })
15
+ .then(function(json) {
16
+ console.log(json)
17
+ return json
18
+ });
19
+ return res
20
+ }
21
+
22
+ async function getSessionLocation()
23
+ {
24
+ const res = await makeRequest({
25
+ url: "http://ip-api.com/json",
26
+ method: 'get'
27
+ })
28
+ return res
29
+ }
30
+
31
+ const { userAgent } = navigator;
32
+ let device="mobile"
33
+
34
+ const setDevice=(dev)=>{
35
+ device=dev
36
+ }
37
+
38
+ userAgent.includes("Mobi") ? setDevice("mobile") : setDevice("desktop");
39
+
40
+
41
+ const getDeviceInfo=()=>{
42
+ return device
43
+ }
44
+
45
+ const startSession = async() =>{
46
+ let loc = await getSessionLocation()
47
+ let session = {
48
+ "session_id": createSessionUUID(),
49
+ "start_time": Date.now(),
50
+ "end_time" : null,
51
+ "device": getDeviceInfo(),
52
+ }
53
+ session = { ...session, ...loc}
54
+ console.log(session)
55
+
56
+ return session
57
+ }
58
+
59
+ export default startSession
@@ -0,0 +1,20 @@
1
+ const request = require('../../lib/index.js')
2
+ const { trackingConfigs, appConfigs } = require('../../config/index.js')
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
+ )
18
+ }
19
+
20
+ export default targetReached
@@ -0,0 +1,5 @@
1
+ function getCurrentTimeStamp()
2
+ {
3
+ return Date.now()
4
+ }
5
+ export default getCurrentTimeStamp
File without changes
File without changes