@@ -2,6 +2,7 @@ import type {
22 GoogleAdsAdPerformanceParams ,
33 GoogleAdsAdPerformanceResponse ,
44} from '@/tools/google_ads/types'
5+ import { validateDate , validateDateRange , validateNumericId } from '@/tools/google_ads/types'
56import type { ToolConfig } from '@/tools/types'
67
78export const googleAdsAdPerformanceTool : ToolConfig <
@@ -83,8 +84,10 @@ export const googleAdsAdPerformanceTool: ToolConfig<
8384 } ,
8485
8586 request : {
86- url : ( params ) =>
87- `https://googleads.googleapis.com/v19/customers/${ params . customerId } /googleAds:search` ,
87+ url : ( params ) => {
88+ const customerId = validateNumericId ( params . customerId , 'customerId' )
89+ return `https://googleads.googleapis.com/v19/customers/${ customerId } /googleAds:search`
90+ } ,
8891 method : 'POST' ,
8992 headers : ( params ) => {
9093 const headers : Record < string , string > = {
@@ -104,17 +107,19 @@ export const googleAdsAdPerformanceTool: ToolConfig<
104107 const conditions : string [ ] = [ "ad_group_ad.status != 'REMOVED'" ]
105108
106109 if ( params . campaignId ) {
107- conditions . push ( `campaign.id = ${ params . campaignId } ` )
110+ conditions . push ( `campaign.id = ${ validateNumericId ( params . campaignId , 'campaignId' ) } ` )
108111 }
109112
110113 if ( params . adGroupId ) {
111- conditions . push ( `ad_group.id = ${ params . adGroupId } ` )
114+ conditions . push ( `ad_group.id = ${ validateNumericId ( params . adGroupId , 'adGroupId' ) } ` )
112115 }
113116
114117 if ( params . startDate && params . endDate ) {
115- conditions . push ( `segments.date BETWEEN '${ params . startDate } ' AND '${ params . endDate } '` )
118+ const start = validateDate ( params . startDate , 'startDate' )
119+ const end = validateDate ( params . endDate , 'endDate' )
120+ conditions . push ( `segments.date BETWEEN '${ start } ' AND '${ end } '` )
116121 } else {
117- const dateRange = params . dateRange || 'LAST_30_DAYS'
122+ const dateRange = validateDateRange ( params . dateRange || 'LAST_30_DAYS' )
118123 conditions . push ( `segments.date DURING ${ dateRange } ` )
119124 }
120125
0 commit comments