@mablhq/mabl-cli 2.31.41 → 2.34.5

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/util/analytics.js CHANGED
@@ -26,17 +26,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.trackMablTestsRunnerEvent = exports.trackCliEvent = void 0;
27
27
  const env_1 = require("../env/env");
28
28
  const cliConfigProvider_1 = require("../providers/cliConfigProvider");
29
+ const axiosProxyConfig_1 = require("../http/axiosProxyConfig");
29
30
  const pureUtil_1 = require("./pureUtil");
30
31
  const os = __importStar(require("os"));
31
32
  const types_1 = require("../api/types");
32
33
  const loggingProvider_1 = require("../providers/logging/loggingProvider");
34
+ const configKeys_1 = require("../commands/config/config_cmds/configKeys");
33
35
  const Analytics = require('analytics-node');
34
- const analytics = new Analytics('ghbAXZbk8fqWROgMscPdkQMoqEjwsKRa', {
35
- flushAt: 1,
36
- flushInterval: 1,
37
- });
38
36
  async function getTrackingInfo() {
39
- var _a, _b, _c;
37
+ var _a, _b, _c, _d;
40
38
  const config = await cliConfigProvider_1.CliConfigProvider.getCliConfig();
41
39
  if (config.authentication.authType === undefined) {
42
40
  return {};
@@ -48,9 +46,13 @@ async function getTrackingInfo() {
48
46
  else {
49
47
  userId = config.userId;
50
48
  }
49
+ const scmDetectionEnabled = (_c = (await cliConfigProvider_1.CliConfigProvider.getConfigProperty(configKeys_1.configKeys.enableSourceControlMetadataCollection))) !== null && _c !== void 0 ? _c : false;
51
50
  return {
52
51
  userId,
53
- workspaceId: (_c = config.workspace) === null || _c === void 0 ? void 0 : _c.id,
52
+ workspaceId: (_d = config.workspace) === null || _d === void 0 ? void 0 : _d.id,
53
+ features: {
54
+ scm_metadata: scmDetectionEnabled,
55
+ },
54
56
  };
55
57
  }
56
58
  async function trackCliEvent(commands, argumentCountMap) {
@@ -64,8 +66,9 @@ async function trackCliEvent(commands, argumentCountMap) {
64
66
  workspaceId: trackingInfo.workspaceId,
65
67
  environment: env_1.ENV,
66
68
  argumentCountMap,
69
+ features: trackingInfo.features,
67
70
  };
68
- trackEvent(event, trackingInfo.userId, properties);
71
+ await trackEvent(event, trackingInfo.userId, properties);
69
72
  }
70
73
  catch (error) {
71
74
  if (env_1.ENV === 'local' || env_1.ENV === 'dev') {
@@ -85,7 +88,7 @@ async function trackMablTestsRunnerEvent(eventName, resultsMap) {
85
88
  environment: env_1.ENV,
86
89
  resultsMap,
87
90
  };
88
- trackEvent(eventName, trackingInfo.userId, properties);
91
+ await trackEvent(eventName, trackingInfo.userId, properties);
89
92
  }
90
93
  catch (error) {
91
94
  if (env_1.ENV === 'local' || env_1.ENV === 'dev') {
@@ -94,10 +97,10 @@ async function trackMablTestsRunnerEvent(eventName, resultsMap) {
94
97
  }
95
98
  }
96
99
  exports.trackMablTestsRunnerEvent = trackMablTestsRunnerEvent;
97
- function trackEvent(event, userId, properties) {
100
+ async function trackEvent(event, userId, properties) {
98
101
  var _a, _b, _c;
99
102
  const cpuInfo = (_a = os.cpus()) !== null && _a !== void 0 ? _a : [];
100
- analytics.track({
103
+ (await getAnalytics()).track({
101
104
  userId,
102
105
  event,
103
106
  context: {
@@ -124,6 +127,18 @@ function trackEvent(event, userId, properties) {
124
127
  properties,
125
128
  });
126
129
  }
130
+ async function getAnalytics() {
131
+ return new Analytics('ghbAXZbk8fqWROgMscPdkQMoqEjwsKRa', {
132
+ axiosConfig: await (0, axiosProxyConfig_1.currentProxyConfig)(),
133
+ errorHandler: (error) => {
134
+ if (env_1.ENV === 'local' || env_1.ENV === 'dev') {
135
+ loggingProvider_1.logger.error('Error with Segment event', error);
136
+ }
137
+ },
138
+ flushAt: 1,
139
+ flushInterval: 1,
140
+ });
141
+ }
127
142
  function getUserAgent() {
128
143
  var _a, _b;
129
144
  const nodeName = (_b = (_a = process === null || process === void 0 ? void 0 : process.release) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'node';