@webiny/telemetry 5.22.0 → 5.23.0-beta.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/CHANGELOG.md CHANGED
@@ -3,6 +3,41 @@
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.23.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.23.0-beta.0...v5.23.0-beta.1) (2022-02-14)
7
+
8
+ **Note:** Version bump only for package @webiny/telemetry
9
+
10
+
11
+
12
+
13
+
14
+ # [5.23.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.22.1...v5.23.0-beta.0) (2022-02-13)
15
+
16
+ **Note:** Version bump only for package @webiny/telemetry
17
+
18
+
19
+
20
+
21
+
22
+ ## [5.22.1](https://github.com/webiny/webiny-js/compare/v5.22.1-beta.0...v5.22.1) (2022-01-29)
23
+
24
+ **Note:** Version bump only for package @webiny/telemetry
25
+
26
+
27
+
28
+
29
+
30
+ ## [5.22.1-beta.0](https://github.com/webiny/webiny-js/compare/v5.22.0...v5.22.1-beta.0) (2022-01-29)
31
+
32
+
33
+ ### Bug Fixes
34
+
35
+ * **telemetry:** add Buffer polyfill and improve telemetry code ([e078a2d](https://github.com/webiny/webiny-js/commit/e078a2d3659c979683a98c3c2f2aa769a5c7b56e))
36
+
37
+
38
+
39
+
40
+
6
41
  # [5.22.0](https://github.com/webiny/webiny-js/compare/v5.22.0-beta.3...v5.22.0) (2022-01-24)
7
42
 
8
43
  **Note:** Version bump only for package @webiny/telemetry
package/cli.js CHANGED
@@ -1,18 +1,29 @@
1
- const baseSendEvent = require("./sendEvent");
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
- if (!isEnabled()) {
6
- return;
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.23.0-beta.1",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
- "@webiny/global-config": "5.22.0",
6
+ "@webiny/global-config": "5.23.0-beta.1",
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": "ab2ca1af058fdec3aa1bed3f30afd51f4592dbb6"
14
+ "gitHead": "04f2d5e43684b9086251e2a6370b3c085e6d51cb"
15
15
  }
package/react.js CHANGED
@@ -1,14 +1,10 @@
1
- const baseSendEvent = require("./sendEvent");
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
- return baseSendEvent({
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
- * Note: it's recommended the one from `cli.js` and `react.js` files is used instead.
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 = async ({ event, user, version, properties, extraPayload } = {}) => {
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
- return fetch(API_URL + "/capture/", {
54
- body,
55
- method: "POST"
56
- }).catch(() => {
57
- // Ignore errors
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
  };