1- import { ManagedPolicyDocument } from "@t3tools/contracts" ;
1+ import { ManagedPolicyClient , ManagedPolicyDocument } from "@t3tools/contracts" ;
22import * as Cause from "effect/Cause" ;
33import * as Context from "effect/Context" ;
44import * as Duration from "effect/Duration" ;
@@ -369,6 +369,7 @@ const dwordBoolean = (value: RegistryValue) =>
369369 */
370370function windowsPolicyDocument (
371371 values : ReadonlyArray < PolicyRegistryValue > ,
372+ knownDrivers : ReadonlyArray < string > ,
372373) : { readonly document : unknown } | { readonly error : string } {
373374 // Registry names ignore case; a hand-written `organization` is still Organization.
374375 const canonical = new Map (
@@ -407,7 +408,12 @@ function windowsPolicyDocument(
407408 if ( checked === undefined ) return { error : `${ where } must be a DWORD of 0 or 1` } ;
408409 const list = lists . get ( value . key ) ?? [ ] ;
409410 lists . set ( value . key , list ) ;
410- if ( checked ) list . push ( value . name ) ;
411+ if ( checked ) {
412+ const names = value . key === "Clients" ? ManagedPolicyClient . literals : knownDrivers ;
413+ list . push (
414+ names . find ( ( name ) => name . toLowerCase ( ) === value . name . toLowerCase ( ) ) ?? value . name ,
415+ ) ;
416+ }
411417 continue ;
412418 }
413419 if ( Object . hasOwn ( WINDOWS_POLICY_GROUPS , value . name ) ) continue ;
@@ -476,7 +482,10 @@ function unwrapForced(json: string): unknown {
476482}
477483
478484/** Read the policy a configuration profile or Group Policy set; absent means no such policy. */
479- const readPlatformPolicy = Effect . fnUntraced ( function * ( platform : NodeJS . Platform ) {
485+ const readPlatformPolicy = Effect . fnUntraced ( function * (
486+ platform : NodeJS . Platform ,
487+ knownDrivers : ReadonlyArray < string > ,
488+ ) {
480489 if ( platform === "darwin" ) {
481490 const path = MACOS_MANAGED_PREFERENCES_PATH ;
482491 const exists = yield * ( yield * FileSystem . FileSystem )
@@ -543,7 +552,7 @@ const readPlatformPolicy = Effect.fnUntraced(function* (platform: NodeJS.Platfor
543552 }
544553 values . push ( ...checkboxes . values . map ( ( value ) => ( { ...value , key : list } ) ) ) ;
545554 }
546- const built = windowsPolicyDocument ( values ) ;
555+ const built = windowsPolicyDocument ( values , knownDrivers ) ;
547556 if ( "error" in built ) return yield * refuse ( built . error ) ;
548557 // An empty key, or one holding only policies set to Disabled, sets nothing.
549558 if ( built . document === undefined ) return undefined ;
@@ -559,10 +568,11 @@ const readPlatformPolicy = Effect.fnUntraced(function* (platform: NodeJS.Platfor
559568 */
560569export const readManagedPolicy = Effect . fn ( "readManagedPolicy" ) ( function * (
561570 platform : NodeJS . Platform ,
571+ knownDrivers : ReadonlyArray < string > = [ ] ,
562572) {
563573 const filePath = managedPolicyPath ( platform ) ;
564574 const [ platformPolicy , file ] = yield * Effect . all ( [
565- readPlatformPolicy ( platform ) ,
575+ readPlatformPolicy ( platform , knownDrivers ) ,
566576 readManagedPolicyFile ( filePath ) ,
567577 ] ) ;
568578 if ( platformPolicy !== undefined && file !== undefined ) {
0 commit comments