@webiny/telemetry 0.0.0-unstable.e53eceafb5 β†’ 0.0.0-unstable.e6f0dc8ca7

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/README.md CHANGED
@@ -1 +1,11 @@
1
1
  # @webiny/telemetry
2
+
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
6
+
7
+ πŸ“˜ **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
8
+
9
+ ---
10
+
11
+ _This README file is automatically generated during the publish process._
package/cli.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export declare interface SendEventParams {
2
+ event: string;
3
+ user?: string;
4
+ version?: string;
5
+ properties: Record<string, any>;
6
+ }
7
+
8
+ export declare function sendEvent(params: SendEventParams): Promise<void>;
9
+
10
+ export declare function isEnabled(): boolean;
11
+ export declare function enable(): boolean;
12
+ export declare function disable(): boolean;
package/cli.js CHANGED
@@ -1,9 +1,11 @@
1
- const { globalConfig } = require("@webiny/global-config");
2
- const { isCI } = require("ci-info");
3
- const { WTS } = require("wts-client/node");
4
- const baseSendEvent = require("./sendEvent");
1
+ import { globalConfig } from "@webiny/global-config";
2
+ import { isCI } from "ci-info";
3
+ import { WTS } from "wts-client/node.js";
4
+ import baseSendEvent from "./sendEvent.js";
5
+ import { loadJsonFileSync } from "load-json-file";
6
+ import path from "path";
5
7
 
6
- const sendEvent = async ({ event, user, version, properties }) => {
8
+ export const sendEvent = async ({ event, user, version, properties }) => {
7
9
  const shouldSend = isEnabled();
8
10
  if (!shouldSend) {
9
11
  return;
@@ -18,13 +20,16 @@ const sendEvent = async ({ event, user, version, properties }) => {
18
20
  wcpProperties.wcpProjectId = wcpProjectId;
19
21
  }
20
22
 
23
+ const packageJsonPath = path.join(import.meta.dirname, "package.json");
24
+ const packageJson = loadJsonFileSync(packageJsonPath);
25
+
21
26
  return baseSendEvent({
22
27
  event,
23
28
  user: user || globalConfig.get("id"),
24
29
  properties: {
25
30
  ...properties,
26
31
  ...wcpProperties,
27
- version: version || require("./package.json").version,
32
+ version: version || packageJson.version,
28
33
  ci: isCI,
29
34
  newUser: Boolean(globalConfig.get("newUser"))
30
35
  },
@@ -33,23 +38,23 @@ const sendEvent = async ({ event, user, version, properties }) => {
33
38
  };
34
39
 
35
40
  const getWcpOrgProjectId = () => {
36
- // In CLI, WCP project ID is stored in the `WCP_PROJECT_ID` environment variable.
37
- const id = process.env.WCP_PROJECT_ID;
41
+ // In CLI, project ID is stored in the `WEBINY_PROJECT_ID` or `WCP_PROJECT_ID` environment variable.
42
+ const id = process.env.WEBINY_PROJECT_ID || process.env.WCP_PROJECT_ID;
38
43
  if (typeof id === "string") {
39
44
  return id.split("/");
40
45
  }
41
46
  return [];
42
47
  };
43
48
 
44
- const enable = () => {
49
+ export const enable = () => {
45
50
  globalConfig.set("telemetry", true);
46
51
  };
47
52
 
48
- const disable = () => {
53
+ export const disable = () => {
49
54
  globalConfig.set("telemetry", false);
50
55
  };
51
56
 
52
- const isEnabled = () => {
57
+ export const isEnabled = () => {
53
58
  const config = globalConfig.get();
54
59
 
55
60
  if (config.telemetry === false) {
@@ -59,5 +64,3 @@ const isEnabled = () => {
59
64
  // `tracking` is left here for backwards compatibility with previous versions of Webiny.
60
65
  return config.tracking !== false;
61
66
  };
62
-
63
- module.exports = { sendEvent, enable, disable, isEnabled };
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@webiny/telemetry",
3
- "version": "0.0.0-unstable.e53eceafb5",
3
+ "version": "0.0.0-unstable.e6f0dc8ca7",
4
+ "type": "module",
4
5
  "license": "MIT",
5
6
  "dependencies": {
6
- "@webiny/global-config": "0.0.0-unstable.e53eceafb5",
7
- "ci-info": "4.2.0",
8
- "jsesc": "3.0.2",
9
- "strip-ansi": "6.0.1",
10
- "wts-client": "1.0.1"
7
+ "@webiny/global-config": "0.0.0-unstable.e6f0dc8ca7",
8
+ "ci-info": "4.4.0",
9
+ "jsesc": "3.1.0",
10
+ "load-json-file": "7.0.1",
11
+ "strip-ansi": "7.2.0",
12
+ "wts-client": "2.0.0"
11
13
  },
12
14
  "publishConfig": {
13
15
  "access": "public",
14
16
  "directory": "."
15
17
  },
16
- "gitHead": "e53eceafb5ce1a3872c9b4548939bb2eae5b1aef"
18
+ "gitHead": "e6f0dc8ca741c1fcc3fec9a5b9e86fdd49544641"
17
19
  }
package/react.js CHANGED
@@ -1,7 +1,7 @@
1
- const baseSendEvent = require("./sendEvent");
2
- const { WTS } = require("wts-client/admin");
1
+ import baseSendEvent from "./sendEvent.js";
2
+ import { WTS } from "wts-client/admin.js";
3
3
 
4
- const sendEvent = async (event, properties = {}) => {
4
+ export const sendEvent = async (event, properties = {}) => {
5
5
  const shouldSend = process.env.REACT_APP_WEBINY_TELEMETRY !== "false";
6
6
  if (!shouldSend) {
7
7
  return;
@@ -31,12 +31,10 @@ const sendEvent = async (event, properties = {}) => {
31
31
  };
32
32
 
33
33
  const getWcpOrgProjectId = () => {
34
- // In React applications, WCP project ID is stored in the `REACT_APP_WCP_PROJECT_ID` environment variable.
35
- const id = process.env.REACT_APP_WCP_PROJECT_ID;
34
+ // In React applications, project ID is stored in the `REACT_APP_WEBINY_PROJECT_ID` or `REACT_APP_WCP_PROJECT_ID` environment variable.
35
+ const id = process.env.REACT_APP_WEBINY_PROJECT_ID || process.env.REACT_APP_WCP_PROJECT_ID;
36
36
  if (typeof id === "string") {
37
37
  return id.split("/");
38
38
  }
39
39
  return [];
40
40
  };
41
-
42
- module.exports = { sendEvent };
package/sendEvent.js CHANGED
@@ -1,11 +1,12 @@
1
- const stripAnsi = require("strip-ansi");
2
- const jsesc = require("jsesc");
1
+ import stripAnsi from "strip-ansi";
2
+ import jsesc from "jsesc";
3
+
3
4
  /**
4
5
  * The main `sendEvent` function.
5
6
  * NOTE: don't use this in your app directly. Instead, use the one from `cli.js` or `react.js` files accordingly.
6
7
  */
7
- module.exports = ({ event, user, properties, wts } = {}) => {
8
- // 1. Check for existence of required base parameters.
8
+ export default ({ event, user, properties, wts } = {}) => {
9
+ // 1. Check for the existence of required base parameters.
9
10
  if (!event) {
10
11
  throw new Error(`Cannot send event - missing "event" name.`);
11
12
  }