@go1/beam 1.0.4 → 1.0.7
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/index.js +28 -32
- package/package.json +15 -21
package/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
const axios = require(
|
|
4
|
-
const axiosRetry = require(
|
|
5
|
-
const version = require(
|
|
3
|
+
const axios = require("axios");
|
|
4
|
+
const axiosRetry = require("axios-retry");
|
|
5
|
+
const version = require("./package.json").version;
|
|
6
6
|
|
|
7
7
|
const setImmediate = global.setImmediate || process.nextTick.bind(process);
|
|
8
|
-
const noop = () => {
|
|
8
|
+
const noop = () => {};
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
|
|
12
11
|
Options Params: {
|
|
13
12
|
flushAt?: int // How many items in queue before flush
|
|
14
13
|
flushInterval?: int // Batch window in MS
|
|
@@ -20,11 +19,12 @@ const getTrackingEndpoint = (env) => {
|
|
|
20
19
|
switch (env) {
|
|
21
20
|
case "prod":
|
|
22
21
|
case "production":
|
|
23
|
-
|
|
22
|
+
case "k8s-prod":
|
|
23
|
+
return "https://beam.go1.co/v1";
|
|
24
24
|
default:
|
|
25
25
|
return "https://track.qa.go1.cloud/v1";
|
|
26
26
|
}
|
|
27
|
-
}
|
|
27
|
+
};
|
|
28
28
|
|
|
29
29
|
class Beam {
|
|
30
30
|
constructor(options = {}) {
|
|
@@ -53,11 +53,7 @@ class Beam {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
setContext(newContext) {
|
|
56
|
-
this.internalContext = Object.assign(
|
|
57
|
-
{},
|
|
58
|
-
this.context,
|
|
59
|
-
newContext,
|
|
60
|
-
);
|
|
56
|
+
this.internalContext = Object.assign({}, this.context, newContext);
|
|
61
57
|
}
|
|
62
58
|
|
|
63
59
|
identify(user, portal) {
|
|
@@ -74,15 +70,18 @@ class Beam {
|
|
|
74
70
|
}
|
|
75
71
|
|
|
76
72
|
this.setContext({
|
|
77
|
-
user: user &&
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
73
|
+
user: user &&
|
|
74
|
+
user.id && {
|
|
75
|
+
id: parseInt(user.id, 10) || null,
|
|
76
|
+
},
|
|
77
|
+
account: account &&
|
|
78
|
+
account.id && {
|
|
79
|
+
id: parseInt(account.id, 10) || null,
|
|
80
|
+
},
|
|
81
|
+
portal: portal &&
|
|
82
|
+
portal.id && {
|
|
83
|
+
id: parseInt(portal.id, 10) || null,
|
|
84
|
+
},
|
|
86
85
|
});
|
|
87
86
|
}
|
|
88
87
|
|
|
@@ -99,9 +98,9 @@ class Beam {
|
|
|
99
98
|
this.internalContext,
|
|
100
99
|
{
|
|
101
100
|
library: {
|
|
102
|
-
name:
|
|
103
|
-
version
|
|
104
|
-
}
|
|
101
|
+
name: "beam-node",
|
|
102
|
+
version,
|
|
103
|
+
},
|
|
105
104
|
},
|
|
106
105
|
event.context
|
|
107
106
|
);
|
|
@@ -110,9 +109,7 @@ class Beam {
|
|
|
110
109
|
event.created = new Date().getTime();
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
this.queue.push(
|
|
114
|
-
event,
|
|
115
|
-
});
|
|
112
|
+
this.queue.push(event);
|
|
116
113
|
|
|
117
114
|
if (!this.flushed) {
|
|
118
115
|
this.flushed = true;
|
|
@@ -148,17 +145,16 @@ class Beam {
|
|
|
148
145
|
BatchData.push(eventEntry);
|
|
149
146
|
}
|
|
150
147
|
|
|
151
|
-
const done = err => {
|
|
148
|
+
const done = (err) => {
|
|
152
149
|
callback(err, BatchData);
|
|
153
150
|
};
|
|
154
|
-
|
|
155
151
|
axios({
|
|
156
|
-
method:
|
|
152
|
+
method: "POST",
|
|
157
153
|
url: this.endpoint,
|
|
158
154
|
data: BatchData,
|
|
159
155
|
})
|
|
160
156
|
.then(() => done())
|
|
161
|
-
.catch(err => {
|
|
157
|
+
.catch((err) => {
|
|
162
158
|
if (err.response) {
|
|
163
159
|
const error = new Error(err.response.statusText);
|
|
164
160
|
return done(error);
|
package/package.json
CHANGED
|
@@ -1,40 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@go1/beam",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Tracking / Analytics Tooling",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"private": false,
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"axios": "^0.
|
|
9
|
-
"axios-retry": "^3.
|
|
8
|
+
"axios": "^0.26.1",
|
|
9
|
+
"axios-retry": "^3.2.4"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"babel-eslint": "^10.0.1",
|
|
13
|
-
"eslint": "^
|
|
13
|
+
"eslint": "^8.12.0",
|
|
14
14
|
"eslint-config-airbnb-es5": "^1.2.0",
|
|
15
|
-
"eslint-config-standard": "^
|
|
16
|
-
"eslint-plugin-es5": "^1.
|
|
17
|
-
"eslint-plugin-standard": "^4.
|
|
18
|
-
"husky": "^
|
|
19
|
-
"jest": "^
|
|
20
|
-
"uglify-js": "^3.
|
|
15
|
+
"eslint-config-standard": "^16.0.3",
|
|
16
|
+
"eslint-plugin-es5": "^1.5.0",
|
|
17
|
+
"eslint-plugin-standard": "^4.1.0",
|
|
18
|
+
"husky": "^7.0.4",
|
|
19
|
+
"jest": "^27.5.1",
|
|
20
|
+
"uglify-js": "^3.15.3"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build:browser": "uglifyjs --compress --mangle -o ./build/browser/analytics.js -- index.js",
|
|
24
|
-
"build:node": "rm -
|
|
24
|
+
"build:node": "rm -rf ./build/node && mkdir -p ./build/node && cp node.js ./build/node/index.js",
|
|
25
25
|
"lint:browser": "eslint index.js",
|
|
26
|
-
"test": "jest --runInBand"
|
|
26
|
+
"test": "jest --runInBand --coverage"
|
|
27
27
|
},
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
30
|
-
"url": "git@code.go1.com.au:
|
|
30
|
+
"url": "git@code.go1.com.au:team-ai2/telemetry/beam.git"
|
|
31
31
|
},
|
|
32
|
-
"author": "",
|
|
33
|
-
"license": "ISC"
|
|
34
|
-
"husky": {
|
|
35
|
-
"hooks": {
|
|
36
|
-
"pre-commit": "npm run lint:browser",
|
|
37
|
-
"pre-push": "npm run lint:browser"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
32
|
+
"author": "Team AI2",
|
|
33
|
+
"license": "ISC"
|
|
40
34
|
}
|