1
>
/*---------------------------------------------------------------------------------------------
policy.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { IStringDictionary } from '../../../base/common/collections.js';
7
>
import { IPolicyData } from '../../../base/common/defaultAccount.js';
8
>
import { Emitter, Event } from '../../../base/common/event.js';
9
>
import { Iterable } from '../../../base/common/iterator.js';
10
>
import { Disposable } from '../../../base/common/lifecycle.js';
11
>
import { IManagedSettingsPolicyDefinitions, PolicyName } from '../../../base/common/policy.js';
12
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
13
>
14
>
export type PolicyValue = string | number | boolean;
15
>
export type PolicyDefinition = {
16
>
type: 'string' | 'number' | 'boolean';
17
>
value?: (policyData: IPolicyData) => string | number | boolean | undefined;
18
>
managedSettings?: IManagedSettingsPolicyDefinitions;
19
>
restrictedValue?: PolicyValue;
20
>
};
21
>
22
>
/** Returns a structured-clone-safe copy of `definition`, dropping the non-cloneable `value` callback. */
23
>
export function toSerializablePolicyDefinition(definition: PolicyDefinition): PolicyDefinition {
24
return { type: definition.type, managedSettings: definition.managedSettings, restrictedValue: definition.restrictedValue };
25
}
27
>
/**
28
>
* Returns the value to apply for `definition` when the account-policy gate is active
29
>
* but not satisfied. Uses `definition.restrictedValue` when specified, otherwise falls
30
>
* back to a type-driven safe default.
31
>
*/
32
>
export function getRestrictedPolicyValue(definition: PolicyDefinition): PolicyValue {
33
if (definition.restrictedValue !== undefined) {
34
return definition.restrictedValue;