44 REQUIRED_ENV_VARS ,
55 REQUIRED_INVOKE_HEADERS ,
66 W3C_ALLOWED_FIELDS ,
7+ W3CFields ,
78 W3CFieldName ,
89} from "./constants.js" ;
910import { InvokeContext , InvokeHeaders } from "./types.js" ;
@@ -54,33 +55,33 @@ export class ContextBuilder {
5455 getRemainingTimeInMillis : function ( ) {
5556 return deadline - Date . now ( ) ;
5657 } ,
57- w3c : function ( ) : Partial < Record < W3CFieldName , string > > {
58- return { ... w3cFields } ;
58+ w3c : function ( ) : W3CFields {
59+ return w3cFields ;
5960 } ,
6061 } ;
6162 }
6263
6364 /**
64- * Pulls `w3c` out of the parsed `clientContext` and returns a normalized
65- * copy of the allowlisted string fields (see `W3C_ALLOWED_FIELDS`). The
66- * `w3c` key is removed from `clientContext` itself so callers cannot read
67- * the source through `context.clientContext`.
65+ * Pulls `w3c` out of the parsed `clientContext` and returns a frozen,
66+ * normalized copy of the allowlisted string fields (see
67+ * `W3C_ALLOWED_FIELDS`). The ` w3c` key is removed from `clientContext`
68+ * itself so callers cannot read the source through `context.clientContext`.
6869 */
6970 private static extractAndStripW3c (
7071 clientContext : Record < string , unknown > | undefined ,
71- ) : Partial < Record < W3CFieldName , string > > {
72+ ) : W3CFields {
7273 if ( ! clientContext || typeof clientContext !== "object" ) {
73- return { } ;
74+ return Object . freeze ( { } ) ;
7475 }
7576 if ( ! ( "w3c" in clientContext ) ) {
76- return { } ;
77+ return Object . freeze ( { } ) ;
7778 }
7879
7980 const rawW3c = clientContext . w3c ;
8081 delete clientContext . w3c ;
8182
8283 if ( ! rawW3c || typeof rawW3c !== "object" || Array . isArray ( rawW3c ) ) {
83- return { } ;
84+ return Object . freeze ( { } ) ;
8485 }
8586
8687 const source = rawW3c as Record < string , unknown > ;
@@ -91,7 +92,7 @@ export class ContextBuilder {
9192 fields [ key ] = value ;
9293 }
9394 }
94- return fields ;
95+ return Object . freeze ( fields ) ;
9596 }
9697
9798 private static parseDeadline ( invokeHeaders : InvokeHeaders ) {
0 commit comments