@webiny/telemetry 5.22.0 → 5.22.1-beta.0
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/CHANGELOG.md +11 -0
- package/cli.js +23 -11
- package/package.json +3 -3
- package/react.js +6 -6
- package/sendEvent.js +11 -14
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.22.1-beta.0](https://github.com/webiny/webiny-js/compare/v5.22.0...v5.22.1-beta.0) (2022-01-29)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **telemetry:** add Buffer polyfill and improve telemetry code ([e078a2d](https://github.com/webiny/webiny-js/commit/e078a2d3659c979683a98c3c2f2aa769a5c7b56e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [5.22.0](https://github.com/webiny/webiny-js/compare/v5.22.0-beta.3...v5.22.0) (2022-01-24)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @webiny/telemetry
|
package/cli.js
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
|
-
const
|
|
1
|
+
const createSendEvent = require("./sendEvent");
|
|
2
2
|
const { globalConfig } = require("@webiny/global-config");
|
|
3
3
|
|
|
4
4
|
const sendEvent = ({ event, user, version, properties, extraPayload }) => {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const shouldSend = isEnabled();
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const sendTelemetry = createSendEvent({
|
|
9
|
+
event,
|
|
10
|
+
user: user || globalConfig.get("id"),
|
|
11
|
+
version: version || require("./package.json").version,
|
|
12
|
+
properties,
|
|
13
|
+
extraPayload
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
if (shouldSend) {
|
|
17
|
+
return sendTelemetry();
|
|
18
|
+
}
|
|
19
|
+
} catch (err) {
|
|
20
|
+
// Ignore errors if telemetry is disabled.
|
|
21
|
+
if (!shouldSend) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
throw err;
|
|
7
26
|
}
|
|
8
|
-
|
|
9
|
-
return baseSendEvent({
|
|
10
|
-
event,
|
|
11
|
-
user: user || globalConfig.get("id"),
|
|
12
|
-
version: version || require("./package.json").version,
|
|
13
|
-
properties,
|
|
14
|
-
extraPayload
|
|
15
|
-
});
|
|
16
27
|
};
|
|
17
28
|
|
|
18
29
|
const enable = () => {
|
|
@@ -30,6 +41,7 @@ const isEnabled = () => {
|
|
|
30
41
|
return false;
|
|
31
42
|
}
|
|
32
43
|
|
|
44
|
+
// `tracking` is left here for backwards compatibility with previous versions of Webiny.
|
|
33
45
|
return config.tracking !== false;
|
|
34
46
|
};
|
|
35
47
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/telemetry",
|
|
3
|
-
"version": "5.22.0",
|
|
3
|
+
"version": "5.22.1-beta.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@webiny/global-config": "5.22.0",
|
|
6
|
+
"@webiny/global-config": "5.22.1-beta.0",
|
|
7
7
|
"form-data": "3.0.0",
|
|
8
8
|
"node-fetch": "2.6.1"
|
|
9
9
|
},
|
|
@@ -11,5 +11,5 @@
|
|
|
11
11
|
"access": "public",
|
|
12
12
|
"directory": "."
|
|
13
13
|
},
|
|
14
|
-
"gitHead": "
|
|
14
|
+
"gitHead": "37f7c3d99baa1793fe29221b5eca40fe92cfe190"
|
|
15
15
|
}
|
package/react.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
const
|
|
1
|
+
const createSendEvent = require("./sendEvent");
|
|
2
2
|
|
|
3
3
|
const setProperties = data => {
|
|
4
4
|
return sendEvent("$identify", data);
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
const sendEvent = (event, data = {}) => {
|
|
8
|
-
if (process.env.REACT_APP_WEBINY_TELEMETRY === "false") {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
8
|
let properties = {};
|
|
13
9
|
let extraPayload = {};
|
|
14
10
|
if (event !== "$identify") {
|
|
@@ -19,13 +15,17 @@ const sendEvent = (event, data = {}) => {
|
|
|
19
15
|
};
|
|
20
16
|
}
|
|
21
17
|
|
|
22
|
-
|
|
18
|
+
const shouldSend = process.env.REACT_APP_WEBINY_TELEMETRY !== "false";
|
|
19
|
+
|
|
20
|
+
const sendTelemetry = createSendEvent({
|
|
23
21
|
event,
|
|
24
22
|
properties,
|
|
25
23
|
extraPayload,
|
|
26
24
|
user: process.env.REACT_APP_USER_ID,
|
|
27
25
|
version: process.env.REACT_APP_WEBINY_VERSION
|
|
28
26
|
});
|
|
27
|
+
|
|
28
|
+
return shouldSend ? sendTelemetry() : Promise.resolve();
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
module.exports = { setProperties, sendEvent };
|
package/sendEvent.js
CHANGED
|
@@ -6,15 +6,9 @@ const API_URL = "https://t.webiny.com";
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The main `sendEvent` function.
|
|
9
|
-
*
|
|
10
|
-
* @param event
|
|
11
|
-
* @param user
|
|
12
|
-
* @param version
|
|
13
|
-
* @param properties
|
|
14
|
-
* @param extraPayload
|
|
15
|
-
* @returns {Promise<T>}
|
|
9
|
+
* NOTE: don't use this in your app directly. Instead, use the one from `cli.js` or `react.js` files accordingly.
|
|
16
10
|
*/
|
|
17
|
-
module.exports =
|
|
11
|
+
module.exports = ({ event, user, version, properties, extraPayload } = {}) => {
|
|
18
12
|
if (!event) {
|
|
19
13
|
throw new Error(`Cannot send event - missing "event" name.`);
|
|
20
14
|
}
|
|
@@ -50,10 +44,13 @@ module.exports = async ({ event, user, version, properties, extraPayload } = {})
|
|
|
50
44
|
const body = new FormData();
|
|
51
45
|
body.append("data", Buffer.from(JSON.stringify(payload)).toString("base64"));
|
|
52
46
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
// Return a function which will send the prepared body when invoked.
|
|
48
|
+
return () => {
|
|
49
|
+
return fetch(API_URL + "/capture/", {
|
|
50
|
+
body,
|
|
51
|
+
method: "POST"
|
|
52
|
+
}).catch(() => {
|
|
53
|
+
// Ignore errors
|
|
54
|
+
});
|
|
55
|
+
};
|
|
59
56
|
};
|