@@ -38,9 +38,17 @@ const FIREBASE_DATA_CONNECT_EMULATOR_BASE_URL_FORMAT =
3838const EXECUTE_GRAPH_QL_ENDPOINT = 'executeGraphql' ;
3939const EXECUTE_GRAPH_QL_READ_ENDPOINT = 'executeGraphqlRead' ;
4040
41- const DATA_CONNECT_CONFIG_HEADERS = {
42- 'X-Firebase-Client' : `fire-admin-node/${ utils . getSdkVersion ( ) } `
43- } ;
41+
42+ function getHeaders ( isUsingGen : boolean ) : { [ key : string ] : string } {
43+ const headerValue = {
44+ 'X-Firebase-Client' : `fire-admin-node/${ utils . getSdkVersion ( ) } ` ,
45+ 'X-Goog-Api-Client' : utils . getMetricsHeader ( ) ,
46+ } ;
47+ if ( isUsingGen ) {
48+ headerValue [ 'X-Goog-Api-Client' ] += ' admin-js/gen' ;
49+ }
50+ return headerValue ;
51+ }
4452
4553/**
4654 * Class that facilitates sending requests to the Firebase Data Connect backend API.
@@ -50,6 +58,7 @@ const DATA_CONNECT_CONFIG_HEADERS = {
5058export class DataConnectApiClient {
5159 private readonly httpClient : HttpClient ;
5260 private projectId ?: string ;
61+ private isUsingGen = false ;
5362
5463 constructor ( private readonly connectorConfig : ConnectorConfig , private readonly app : App ) {
5564 if ( ! validator . isNonNullObject ( app ) || ! ( 'options' in app ) ) {
@@ -59,6 +68,14 @@ export class DataConnectApiClient {
5968 }
6069 this . httpClient = new DataConnectHttpClient ( app as FirebaseApp ) ;
6170 }
71+
72+ /**
73+ * Update whether the SDK is using a generated one or not.
74+ * @param isUsingGen
75+ */
76+ setIsUsingGen ( isUsingGen : boolean ) : void {
77+ this . isUsingGen = isUsingGen ;
78+ }
6279
6380 /**
6481 * Execute arbitrary GraphQL, including both read and write queries
@@ -117,7 +134,7 @@ export class DataConnectApiClient {
117134 const request : HttpRequestConfig = {
118135 method : 'POST' ,
119136 url,
120- headers : DATA_CONNECT_CONFIG_HEADERS ,
137+ headers : getHeaders ( this . isUsingGen ) ,
121138 data,
122139 } ;
123140 const resp = await this . httpClient . send ( request ) ;
0 commit comments