@@ -32,12 +32,15 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) {
3232 let amplitude_event_id = 0 ;
3333
3434 /** We redact strings in arg values, unless they are named here */
35- const allowList = {
35+ const allowList : Record < string , AllowedValues > & { "*" : AllowedValues } = {
3636 // applies to all commands
3737 // use camelCase version
38- "*" : [ "format" , "logLevel" ] ,
39- // specific commands
40- tail : [ "status" ] ,
38+ "*" : { format : "*" , logLevel : "*" } ,
39+ "wrangler tail" : { status : "*" } ,
40+ "wrangler types" : {
41+ xIncludeRuntime : [ ".wrangler/types/runtime.d.ts" ] ,
42+ path : [ "worker-configuration.d.ts" ] ,
43+ } ,
4144 } ;
4245
4346 return {
@@ -253,35 +256,50 @@ const sanitiseUserInput = (
253256 return result ;
254257} ;
255258
259+ type AllowedValues = Record < string , string [ ] | "*" > ;
256260const getAllowedArgs = (
257- allowList : Record < string , string [ ] > & { "*" : string [ ] } ,
261+ allowList : Record < string , AllowedValues > & { "*" : AllowedValues } ,
258262 key : string
259263) => {
260264 const commandSpecific = allowList [ key ] ?? [ ] ;
261- return [ ...commandSpecific , ...allowList [ "*" ] ] ;
265+ return { ...commandSpecific , ...allowList [ "*" ] } ;
262266} ;
263267export const redactArgValues = (
264268 args : Record < string , unknown > ,
265- allowedKeys : string [ ]
269+ allowedValues : AllowedValues
266270) => {
267271 const result : Record < string , unknown > = { } ;
268272
269- for ( const [ k , value ] of Object . entries ( args ) ) {
270- const key = normalise ( k ) ;
273+ for ( let [ key , value ] of Object . entries ( args ) ) {
274+ key = normalise ( key ) ;
275+ if ( key === "xIncludeRuntime" && value === "" ) {
276+ value = ".wrangler/types/runtime.d.ts" ;
277+ }
278+ const allowedValuesForArg = allowedValues [ key ] ?? [ ] ;
271279 if ( exclude . has ( key ) ) {
272280 continue ;
273281 }
274282 if (
275283 typeof value === "number" ||
276284 typeof value === "boolean" ||
277- allowedKeys . includes ( normalise ( key ) )
285+ allowedValuesForArg . includes ( key )
278286 ) {
279287 result [ key ] = value ;
280- } else if ( typeof value === "string" ) {
288+ } else if (
289+ // redact if its a string, unless the value is in the allow list
290+ // * is a special value that allows all values for that arg
291+ typeof value === "string" &&
292+ ! ( allowedValuesForArg === "*" || allowedValuesForArg . includes ( value ) )
293+ ) {
281294 result [ key ] = "<REDACTED>" ;
282295 } else if ( Array . isArray ( value ) ) {
283296 result [ key ] = value . map ( ( v ) =>
284- typeof v === "string" ? "<REDACTED>" : v
297+ // redact if its a string, unless the value is in the allow list
298+ // * is a special value that allows all values for that arg
299+ typeof v === "string" &&
300+ ! ( allowedValuesForArg === "*" || allowedValuesForArg . includes ( v ) )
301+ ? "<REDACTED>"
302+ : v
285303 ) ;
286304 } else {
287305 result [ key ] = value ;
0 commit comments