core-outline 1.0.1 → 1.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/package.json CHANGED
@@ -1,27 +1,51 @@
1
1
  {
2
2
  "name": "core-outline",
3
- "version": "1.0.1",
4
- "description": "Connect your React JS application to Core&Outline",
5
- "main": "index.js",
3
+ "version": "1.1.1",
4
+ "description": "A React component for Core&Outline",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.es.js",
6
7
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/TomiTsuma/core-outline-npm.git"
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "storybook": "storybook dev -p 6006",
10
+ "build-storybook": "storybook build",
11
+ "build-lib": "rollup -c",
12
+ "format": "prettier --write .",
13
+ "lint": "eslint . "
12
14
  },
13
15
  "keywords": [
14
- "core",
15
- "outline"
16
+ "Core",
17
+ "Outline"
16
18
  ],
17
- "author": "Tsuma Thomas",
18
- "license": "ISC",
19
- "bugs": {
20
- "url": "https://github.com/TomiTsuma/core-outline-npm/issues"
19
+ "author": "Core&Outline",
20
+ "license": "MIT",
21
+ "devDependencies": {
22
+ "@babel/core": "^7.12.10",
23
+ "@babel/preset-react": "^7.12.10",
24
+ "@rollup/plugin-node-resolve": "^11.1.1",
25
+ "@storybook/addon-actions": "^6.1.16",
26
+ "@storybook/addon-essentials": "^6.1.16",
27
+ "@storybook/addon-links": "^6.1.16",
28
+ "@storybook/react": "^6.1.16",
29
+ "babel-loader": "^8.2.2",
30
+ "eslint": "^9.17.0",
31
+ "eslint-config-prettier": "^9.1.0",
32
+ "eslint-plugin-react": "^7.37.3",
33
+ "prettier": "^3.4.2",
34
+ "react": "^17.0.1",
35
+ "react-dom": "^17.0.1",
36
+ "rollup": "^2.38.4",
37
+ "rollup-plugin-babel": "^4.4.0",
38
+ "rollup-plugin-peer-deps-external": "^2.2.4",
39
+ "rollup-plugin-postcss": "^4.0.0",
40
+ "rollup-plugin-terser": "^7.0.2"
41
+ },
42
+ "peerDependencies": {
43
+ "react": "^17.0.1",
44
+ "react-dom": "^17.0.1"
21
45
  },
22
- "homepage": "https://github.com/TomiTsuma/core-outline-npm#readme",
23
46
  "dependencies": {
24
- "axios": "^1.6.7",
25
- "react-router-dom": "^6.22.1"
47
+ "react-error-boundary": "^5.0.0",
48
+ "react-tracking": "^9.3.2",
49
+ "rrweb": "^2.0.0-alpha.4"
26
50
  }
27
51
  }
@@ -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/components/CoreOutline/CoreOutline.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,70 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { record } from 'rrweb';
3
+
4
+ const CoreOutline = ({ children }) => {
5
+ const [events, setEvents] = useState([]);
6
+ const recorderActive = useRef(false);
7
+ const [currentPage, setCurrentPage] = useState(window.location.href);
8
+
9
+ useEffect(() => {
10
+ console.log(currentPage);
11
+ const handleNavigation = () => {
12
+ setCurrentPage(window.location.href);
13
+ saveEvents(events);
14
+ };
15
+
16
+ window.addEventListener('popstate', handleNavigation);
17
+ const originalPushState = window.history.pushState;
18
+ window.history.pushState = function (...args) {
19
+ originalPushState.apply(this, args);
20
+ handleNavigation();
21
+ };
22
+
23
+ return () => {
24
+ window.removeEventListener('popstate', handleNavigation);
25
+ window.history.pushState = originalPushState;
26
+ };
27
+ }, [currentPage]);
28
+
29
+ useEffect(() => {
30
+ let stopFn;
31
+ if (!recorderActive.current) {
32
+ stopFn = record({
33
+ emit(event) {
34
+ setEvents((prevEvents) => [...prevEvents, event]);
35
+ },
36
+ });
37
+
38
+ recorderActive.current = true;
39
+ }
40
+
41
+ return () => {
42
+ if (stopFn) {
43
+ stopFn();
44
+
45
+ recorderActive.current = false;
46
+ }
47
+ };
48
+ }, []);
49
+
50
+ function saveEvents(events) {
51
+ const requestOptions = {
52
+ method: 'PUT',
53
+ headers: {
54
+ 'Content-Type': 'application/json',
55
+ },
56
+ body: events,
57
+ };
58
+
59
+ fetch('http://localhost:8000/generate-s3-url')
60
+ .then((response) => response.json())
61
+ .then((data) => {
62
+ const uploadURL = data.signed_url;
63
+ return fetch(uploadURL, requestOptions);
64
+ });
65
+ }
66
+
67
+ return <div>{children}</div>;
68
+ };
69
+
70
+ export default CoreOutline;
@@ -0,0 +1,26 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { record } from 'rrweb';
3
+
4
+ const useRRWebRecorder = () => {
5
+ const eventsRef = useRef([]);
6
+
7
+ useEffect(() => {
8
+ const stopRecording = record({
9
+ emit(event) {
10
+ if (event) {
11
+ eventsRef.current.push(event);
12
+ }
13
+ },
14
+ });
15
+
16
+ return () => {
17
+ if (stopRecording) {
18
+ stopRecording();
19
+ }
20
+ };
21
+ }, []);
22
+
23
+ return eventsRef;
24
+ };
25
+
26
+ export default useRRWebRecorder;
@@ -0,0 +1 @@
1
+ export * from './CoreOutline';
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './components/CoreOutline';
package/README.md DELETED
@@ -1,2 +0,0 @@
1
- # core-outline-npm
2
- This repo is an npm package for core and outline. It is compatible with node js
@@ -1,3 +0,0 @@
1
- const app_configs = {
2
- BASE_URL: `https://api.coreoutline.com`,
3
- }
@@ -1,10 +0,0 @@
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
- }
package/config/index.js DELETED
@@ -1,8 +0,0 @@
1
- const trackingConfigs = require('./components/tracking.js')
2
- const appConfigs = require('./components/app.js')
3
-
4
-
5
- module.exports = {
6
- trackingConfigs,
7
- appConfigs
8
- }
package/index.js DELETED
File without changes
package/lib/axios/app.js DELETED
File without changes
package/lib/index.js DELETED
@@ -1,5 +0,0 @@
1
- const { request } = require('axios/app.js')
2
-
3
- module.exports = {
4
- request
5
- }
File without changes
package/services/index.js DELETED
@@ -1,7 +0,0 @@
1
- const updatePage = require('./page/update-page.js')
2
- const startSession = require('./session/start-session.js')
3
- const endSession = require('./session/end-session.js')
4
- const targetReached = require('./target/update-target.js')
5
-
6
-
7
- module.exports = {updatePage, startSession, endSession, targetReached}
@@ -1,22 +0,0 @@
1
- const request = reqire('../../lib/index.js')
2
- const { trackingConfigs, appConfigs } = require('../../config/index.js')
3
-
4
- const updatePage = async(time_in, session_id, time_out) =>{
5
- const res = await(
6
- request({
7
- url: appConfigs.BASE_URL,
8
- service: trackingConfigs.UPDATE_PAGE,
9
- body: {
10
- 'session_id':session_id,
11
- 'time_in':time_in,
12
- 'time_out':time_out
13
- },
14
- method:'POST',
15
- params:{
16
- Authorization: `Bearer ${token}`
17
- }
18
- })
19
- )
20
- }
21
-
22
- module.exports = updatePage
@@ -1,20 +0,0 @@
1
- const request = reqire('../../lib/index.js')
2
- const { trackingConfigs, appConfigs } = require('../../config/index.js')
3
-
4
- const endSession = async(session_id) =>{
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
- module.exports = endSession
@@ -1,24 +0,0 @@
1
- const request = reqire('../../lib/index.js')
2
- const { trackingConfigs } = require('../../config/index.js')
3
-
4
- const startSession = async(device, browser, latitude, longitude) =>{
5
- const res = await(
6
- request({
7
- url:`https://api.coreoutline.com`,
8
- service: trackingConfigs.START_SESSION,
9
- body: {
10
- 'device':device,
11
- 'browser':browser,
12
- 'latitude':latitude,
13
- 'longitude':longitude
14
- },
15
- method:'POST',
16
- params:{
17
- Authorization: `Bearer ${token}`
18
- }
19
- })
20
- )
21
- }
22
-
23
-
24
- module.exports = startSession
@@ -1,20 +0,0 @@
1
- const request = reqire('../../lib/index.js')
2
- const { trackingConfigs, appConfigs } = require('../../config/index.js')
3
-
4
- const targetReached = async(session_id) =>{
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
- module.exports = targetReached
File without changes