1
>
/*---------------------------------------------------------------------------------------------
managedSettings.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
>
/**
7
>
* A single enterprise-managed marketplace entry, preserving the marketplace
8
>
* name (used as `displayLabel`) and the original `source` discriminator.
9
>
*/
10
>
export type IExtraKnownMarketplaceEntry =
11
>
| { readonly name: string; readonly source: { readonly source: 'github'; readonly repo: string; readonly ref?: string } }
12
>
| { readonly name: string; readonly source: { readonly source: 'git'; readonly url: string; readonly ref?: string } };
13
>
14
>
/**
15
>
* A single entry in the enterprise-managed `strictKnownMarketplaces` allowlist
16
>
* (the `chat.plugins.strictMarketplaces` setting), a discriminated union on
17
>
* `source`. Delivered as JSON via managed settings (the server endpoint or
18
>
* native MDM) and validated at match time, so the optional fields are only
19
>
* meaningful for their corresponding `source`.
20
>
*/
21
>
export interface IStrictMarketplaceSource {
22
>
readonly source: 'github' | 'git' | 'url' | 'npm' | 'file' | 'directory' | 'hostPattern' | 'pathPattern';
23
>
readonly repo?: string;
24
>
readonly url?: string;
25
>
readonly ref?: string;
26
>
readonly path?: string;
27
>
readonly package?: string;
28
>
readonly hostPattern?: string;
29
>
readonly pathPattern?: string;
30
>
readonly headers?: Readonly<Record<string, string>>;
31
>
}
32
>
33
>
/**
34
>
* Converts an {@link IExtraKnownMarketplaceEntry} array into the
35
>
* `{ [name]: url-or-shorthand }` dict stored on the `chat.plugins.extraMarketplaces`
36
>
* setting (and carried as the canonical JSON value of the `extraKnownMarketplaces`
37
>
* managed setting across both the server endpoint and native MDM delivery).
38
>
*
39
>
* Plain-string entries (allowed by the policy schema but unnamed) are stored with
40
>
* the value used as both key and value so they survive the round-trip intact.
41
>
*
42
>
* Marketplace names come from managed settings (untrusted input) and are written as object keys,
43
>
* so `__proto__` / `constructor` / `prototype` keys are skipped to avoid prototype pollution
44
>
* (mirroring the guard in the managed-settings normalizer's string-map encoder).
45
>
*/
46
>
export function extraKnownMarketplacesToConfigDict(entries: readonly (string | IExtraKnownMarketplaceEntry)[] | undefined): Record<string, string> | undefined {
47
if (!entries?.length) {
48
return undefined;