@salesforce/telemetry 4.0.16 → 4.1.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.
@@ -0,0 +1,9 @@
1
+ import { ConfigAggregator } from '@salesforce/core/lib/config/configAggregator';
2
+ /**
3
+ *
4
+ * Check ConfigAggregator once for telemetry opt-out. Returns true unless config/env has opt-out
5
+ * If you don't pass in a ConfigAggregator, one will be constructed for you
6
+ * memoized: only runs once
7
+ *
8
+ * */
9
+ export declare const isEnabled: (configAggregator?: ConfigAggregator) => Promise<boolean>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isEnabled = void 0;
10
+ // deep imports to avoid requiring the ENTIRE package (which will also pull in jsforce) until we get ESM done
11
+ const configAggregator_1 = require("@salesforce/core/lib/config/configAggregator");
12
+ const config_1 = require("@salesforce/core/lib/config/config");
13
+ // store the result to reduce checks
14
+ let enabled;
15
+ /**
16
+ *
17
+ * Check ConfigAggregator once for telemetry opt-out. Returns true unless config/env has opt-out
18
+ * If you don't pass in a ConfigAggregator, one will be constructed for you
19
+ * memoized: only runs once
20
+ *
21
+ * */
22
+ const isEnabled = async (configAggregator) => {
23
+ if (enabled === undefined) {
24
+ const agg = configAggregator ?? (await configAggregator_1.ConfigAggregator.create({}));
25
+ enabled = agg.getPropertyValue(config_1.SfConfigProperties.DISABLE_TELEMETRY) !== 'true';
26
+ }
27
+ return enabled;
28
+ };
29
+ exports.isEnabled = isEnabled;
30
+ //# sourceMappingURL=enabledCheck.js.map
package/lib/exported.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { TelemetryReporter } from './telemetryReporter';
2
2
  export * from './telemetryReporter';
3
+ export { isEnabled } from './enabledCheck';
3
4
  export default TelemetryReporter;
package/lib/exported.js CHANGED
@@ -20,7 +20,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
20
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.isEnabled = void 0;
23
24
  const telemetryReporter_1 = require("./telemetryReporter");
24
25
  __exportStar(require("./telemetryReporter"), exports);
26
+ var enabledCheck_1 = require("./enabledCheck");
27
+ Object.defineProperty(exports, "isEnabled", { enumerable: true, get: function () { return enabledCheck_1.isEnabled; } });
25
28
  exports.default = telemetryReporter_1.TelemetryReporter;
26
29
  //# sourceMappingURL=exported.js.map
@@ -1,18 +1,18 @@
1
1
  import { AsyncCreatable } from '@salesforce/kit';
2
- import { Attributes, Properties, TelemetryOptions } from './appInsights';
2
+ import { type Attributes, type Properties, type TelemetryOptions } from './appInsights';
3
3
  import { TelemetryClient } from './exported';
4
4
  export { TelemetryOptions, Attributes, Properties, TelemetryClient } from './appInsights';
5
5
  /**
6
6
  * Reports telemetry events to app insights. We do not send if the config 'disableTelemetry' is set.
7
7
  */
8
8
  export declare class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
9
- private static config;
9
+ private enabled;
10
10
  private options;
11
11
  private logger;
12
- private config;
13
12
  private reporter;
14
13
  constructor(options: TelemetryOptions);
15
14
  /**
15
+ * @deprecated Use the standalone function isEnabled() instead.
16
16
  * Determine if the telemetry event should be logged.
17
17
  * Setting the disableTelemetry config var to true will disable insights for errors and diagnostics.
18
18
  */
@@ -39,6 +39,7 @@ const kit_1 = require("@salesforce/kit");
39
39
  const got_1 = __importDefault(require("got"));
40
40
  const proxy_agent_1 = require("proxy-agent");
41
41
  const appInsights_1 = require("./appInsights");
42
+ const enabledCheck_1 = require("./enabledCheck");
42
43
  var appInsights_2 = require("./appInsights");
43
44
  Object.defineProperty(exports, "TelemetryClient", { enumerable: true, get: function () { return appInsights_2.TelemetryClient; } });
44
45
  /**
@@ -47,27 +48,20 @@ Object.defineProperty(exports, "TelemetryClient", { enumerable: true, get: funct
47
48
  class TelemetryReporter extends kit_1.AsyncCreatable {
48
49
  constructor(options) {
49
50
  super(options);
51
+ this.enabled = false;
50
52
  this.options = options;
51
53
  }
52
54
  /**
55
+ * @deprecated Use the standalone function isEnabled() instead.
53
56
  * Determine if the telemetry event should be logged.
54
57
  * Setting the disableTelemetry config var to true will disable insights for errors and diagnostics.
55
58
  */
56
59
  static async determineSfdxTelemetryEnabled() {
57
- if (!TelemetryReporter.config) {
58
- TelemetryReporter.config = await core_1.ConfigAggregator.create({});
59
- }
60
- const configValue = TelemetryReporter.config.getPropertyValue(core_1.SfConfigProperties.DISABLE_TELEMETRY);
61
- // SF_DISABLE_TELEMETRY is the proper name for this env that will be cheked by config.getPropertyValue. SFDX_DISABLE_INSIGHTS is present for backwards compatibility
62
- const sfdxDisableInsights = configValue === 'true' || kit_1.env.getBoolean('SFDX_DISABLE_INSIGHTS');
63
- return !sfdxDisableInsights;
60
+ return (0, enabledCheck_1.isEnabled)();
64
61
  }
65
62
  async init() {
63
+ this.enabled = await (0, enabledCheck_1.isEnabled)();
66
64
  this.logger = await core_1.Logger.child('TelemetryReporter');
67
- if (!TelemetryReporter.config) {
68
- TelemetryReporter.config = await core_1.ConfigAggregator.create({});
69
- }
70
- this.config = TelemetryReporter.config;
71
65
  if (this.options.waitForConnection)
72
66
  await this.waitForConnection();
73
67
  this.reporter = await appInsights_1.AppInsights.create(this.options);
@@ -173,14 +167,10 @@ class TelemetryReporter extends kit_1.AsyncCreatable {
173
167
  * Setting the disableTelemetry config var to true will disable insights for errors and diagnostics.
174
168
  */
175
169
  isSfdxTelemetryEnabled() {
176
- const configValue = this.config.getPropertyValue(core_1.SfConfigProperties.DISABLE_TELEMETRY);
177
- const sfdxDisableInsights = configValue === 'true' || kit_1.env.getBoolean('SFDX_DISABLE_INSIGHTS');
178
- // isEnabled = !sfdxDisableInsights
179
- return !sfdxDisableInsights;
170
+ return this.enabled;
180
171
  }
181
172
  logTelemetryStatus() {
182
- const isEnabled = this.isSfdxTelemetryEnabled();
183
- if (isEnabled) {
173
+ if (this.enabled) {
184
174
  this.logger.warn(`Telemetry is enabled. This can be disabled by running sfdx force:config:set ${core_1.SfConfigProperties.DISABLE_TELEMETRY}=true`);
185
175
  }
186
176
  else {
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@salesforce/telemetry",
3
- "version": "4.0.16",
3
+ "version": "4.1.0",
4
4
  "description": "Library for application insights",
5
5
  "main": "lib/exported",
6
+ "exports": {
7
+ "./enabledCheck": "./lib/enabledCheck.js",
8
+ ".": "./lib/exported.js"
9
+ },
6
10
  "repository": "forcedotcom/telemetry",
7
11
  "author": "Salesforce",
8
12
  "license": "BSD-3-Clause",
@@ -43,14 +47,14 @@
43
47
  },
44
48
  "devDependencies": {
45
49
  "@salesforce/dev-config": "^4.0.1",
46
- "@salesforce/dev-scripts": "^5.4.3",
50
+ "@salesforce/dev-scripts": "^5.7.0",
47
51
  "@salesforce/prettier-config": "^0.0.3",
48
- "@salesforce/ts-sinon": "^1.4.12",
52
+ "@salesforce/ts-sinon": "^1.4.14",
49
53
  "@typescript-eslint/eslint-plugin": "^5.62.0",
50
54
  "@typescript-eslint/parser": "^5.62.0",
51
55
  "chai": "^4.3.7",
52
- "eslint": "^8.46.0",
53
- "eslint-config-prettier": "^8.9.0",
56
+ "eslint": "^8.47.0",
57
+ "eslint-config-prettier": "^8.10.0",
54
58
  "eslint-config-salesforce": "^2.0.2",
55
59
  "eslint-config-salesforce-license": "^0.2.0",
56
60
  "eslint-config-salesforce-typescript": "^1.1.2",