-
Notifications
You must be signed in to change notification settings - Fork 3
/
enabledCheck.ts
28 lines (25 loc) · 1.05 KB
/
enabledCheck.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
// deep imports to avoid requiring the ENTIRE package (which will also pull in jsforce) until we get ESM done
import { ConfigAggregator } from '@salesforce/core/configAggregator';
import { SfConfigProperties } from '@salesforce/core/config';
// store the result to reduce checks
let enabled: boolean | undefined;
/**
*
* Check ConfigAggregator once for telemetry opt-out. Returns true unless config/env has opt-out
* If you don't pass in a ConfigAggregator, one will be constructed for you
* memoized: only runs once
*
* */
export const isEnabled = async (configAggregator?: ConfigAggregator): Promise<boolean> => {
if (enabled === undefined) {
const agg = configAggregator ?? (await ConfigAggregator.create({}));
enabled = agg.getPropertyValue<string>(SfConfigProperties.DISABLE_TELEMETRY) !== 'true';
}
return enabled;
};