import * as gax from 'google-gax' ; import { Callback , CallOptions , Descriptors , ClientOptions } from 'google-gax' ; import * as protos from '../../protos/protos' ; import jsonProtos = require ( '../../protos/protos.json' ) ; /**
 * Client JSON configuration object, loaded from
 * `src/v1alpha/alpha_analytics_data_client_config.json`.
 * This file defines retry strategy and timeouts for all API methods in this library.
 */ import * as gapicConfig from './alpha_analytics_data_client_config.json' ; const version = require ( '../../../package.json' ) . version ; class memberof export class AlphaAnalyticsDataClient { private _terminated = false ; private _opts : ClientOptions ; private _providedCustomServicePath : boolean ; private _gaxModule : typeof gax | typeof gax . fallback ; private _gaxGrpc : gax . GrpcClient | gax . fallback . GrpcClient ; private _protos : { } ; private _defaults : { [ method ] : gax . CallSettings ; } ; auth : gax . GoogleAuth ; descriptors : Descriptors = { page : { } , stream : { } , longrunning : { } , batching : { } , } ; warn : ( code : string , message : string , warnType ? : string ) => void ; innerApiCalls : { [ name ] : Function ; } ; pathTemplates : { [ name ] : gax . PathTemplate ; } ; alphaAnalyticsDataStub ? : Promise < { [ name ] : Function ; } > ; param options param options . credentials param { string } options . credentials . client_email param { string } options . credentials . private_key param { string } options . email param { string } options . keyFilename param { number } options . port param { string } options . projectId - The project ID from the Google
     *     Developer's Console, e.g. 'grape-spaceship-123'. We will also check
     *     the environment variable GCLOUD_PROJECT for your project ID. If your
     *     app is running in an environment which supports
     *      https ,
     *     your project ID will be detected automatically.
     *  param { string } options . apiEndpoint param { gax . ClientConfig } options . clientConfig - Client configuration override.
     *     Follows the structure of  gapicConfig .
     *  param { boolean } options . fallback constructor ( opts ? ) { const staticMembers = this . constructor as typeof AlphaAnalyticsDataClient ; const servicePath = opts ?. servicePath || opts ?. apiEndpoint || staticMembers . servicePath ; this . _providedCustomServicePath = ! ! ( opts ?. servicePath || opts ?. apiEndpoint ) ; const port = opts ?. port || staticMembers . port ; const clientConfig = opts ?. clientConfig ?? { } ; const fallback = opts ?. fallback ?? ( typeof window !== 'undefined' && typeof window ?. fetch === 'function' ) ; opts = Object . assign ( { servicePath , port , clientConfig , fallback } , opts ) ; if ( servicePath !== staticMembers . servicePath && ! ( 'scopes' in opts ) ) { opts [ 'scopes' ] = staticMembers . scopes ; } this . _gaxModule = opts . fallback ? gax . fallback : gax ; this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ; this . _opts = opts ; this . auth = this . _gaxGrpc . auth as gax . GoogleAuth ; this . auth . useJWTAccessWithScope = true ; this . auth . defaultServicePath = staticMembers . servicePath ; if ( servicePath === staticMembers . servicePath ) { this . auth . defaultScopes = staticMembers . scopes ; } const clientHeader = [ `gax/${ this . _gaxModule . version }` , `gapic/${ version }` ] ; if ( typeof process !== 'undefined' && 'versions' in process ) { clientHeader . push ( `gl-node/${ process . versions . node }` ) ; } else { clientHeader . push ( `gl-web/${ this . _gaxModule . version }` ) ; } if ( ! opts . fallback ) { clientHeader . push ( `grpc/${ this . _gaxGrpc . grpcVersion }` ) ; } else if ( opts . fallback === 'rest' ) { clientHeader . push ( `rest/${ this . _gaxGrpc . grpcVersion }` ) ; } if ( opts . libName && opts . libVersion ) { clientHeader . push ( `${ opts . libName }/${ opts . libVersion }` ) ; } this . _protos = this . _gaxGrpc . loadProtoJSON ( jsonProtos ) ; this . pathTemplates = { metadataPathTemplate : new this . _gaxModule . PathTemplate ( 'properties/{property}/metadata' ) , } ; this . _defaults = this . _gaxGrpc . constructSettings ( 'google.analytics.data.v1alpha.AlphaAnalyticsData' , gapicConfig as gax . ClientConfig , opts . clientConfig || { } , { 'x-goog-api-client' : clientHeader . join ( ' ' ) } ) ; this . innerApiCalls = { } ; this . warn = gax . warn ; } returns { Promise } initialize ( ) { if ( this . alphaAnalyticsDataStub ) { return this . alphaAnalyticsDataStub ; } this . alphaAnalyticsDataStub = this . _gaxGrpc . createStub ( this . _opts . fallback ? ( this . _protos as protobuf . Root ) . lookupService ( 'google.analytics.data.v1alpha.AlphaAnalyticsData' ) : ( this . _protos as any ) . google . analytics . data . v1alpha . AlphaAnalyticsData , this . _opts , this . _providedCustomServicePath ) as Promise < { [ method ] : Function ; } > ; const alphaAnalyticsDataStubMethods = [ 'runReport' , 'runPivotReport' , 'batchRunReports' , 'batchRunPivotReports' , 'getMetadata' , 'runRealtimeReport' , ] ; for ( const methodName of alphaAnalyticsDataStubMethods ) { const callPromise = this . alphaAnalyticsDataStub . then ( stub => ( ... args ) => { if ( this . _terminated ) { return Promise . reject ( 'The client has already been closed.' ) ; } const func = stub [ methodName ] ; return func . apply ( stub , args ) ; } , ( err ) => ( ) => { throw err ; } ) ; const descriptor = undefined ; const apiCall = this . _gaxModule . createApiCall ( callPromise , this . _defaults [ methodName ] , descriptor ) ; this . innerApiCalls [ methodName ] = apiCall ; } return this . alphaAnalyticsDataStub ; } returns { string } static get servicePath ( ) { return 'analyticsdata.googleapis.com' ; } returns { string } static get apiEndpoint ( ) { return 'analyticsdata.googleapis.com' ; } returns { number } static get port ( ) { return 443 ; } returns { string [ ] } static get scopes ( ) { return [ 'https://www.googleapis.com/auth/analytics' , 'https://www.googleapis.com/auth/analytics.readonly' , ] ; } getProjectId ( ) ; getProjectId ( callback ) ; returns { Promise } getProjectId ( callback ? ) { if ( callback ) { this . auth . getProjectId ( callback ) ; return ; } return this . auth . getProjectId ( ) ; } runReport ( request ? , options ? ) ; runReport ( request , options , callback ) ; runReport ( request , callback ) ; param request param { google . analytics . data . v1alpha . Entity } request . entity param { number [ ] } request . dimensions param { number [ ] } request . metrics param { number [ ] } request . dateRanges param { number } request . offset param { number } request . limit param { number [ ] } request . metricAggregations param { google . analytics . data . v1alpha . FilterExpression } request . dimensionFilter param { google . analytics . data . v1alpha . FilterExpression } request . metricFilter param { number [ ] } request . orderBys param { string } request . currencyCode param { google . analytics . data . v1alpha . CohortSpec } request . cohortSpec param { boolean } request . keepEmptyRows param { boolean } request . returnPropertyQuota param { object } options Call options. See  https for more details.
     *  returns { Promise } - The promise which resolves to an array.
     *   The first element of the array is an object representing [RunReportResponse] google . analytics . data . v1alpha . RunReportResponse .
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
     *   for more details and examples.
     *  example runReport ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; if ( typeof optionsOrCallback === 'function' && callback === undefined ) { callback = optionsOrCallback ; options = { } ; } else { options = optionsOrCallback as CallOptions ; } options = options || { } ; this . initialize ( ) ; return this . innerApiCalls . runReport ( request , options , callback ) ; } runPivotReport ( request ? , options ? ) ; runPivotReport ( request , options , callback ) ; runPivotReport ( request , callback ) ; param request param { google . analytics . data . v1alpha . Entity } request . entity param { number [ ] } request . dimensions param { number [ ] } request . metrics param { google . analytics . data . v1alpha . FilterExpression } request . dimensionFilter param { google . analytics . data . v1alpha . FilterExpression } request . metricFilter param { number [ ] } request . pivots param { number [ ] } request . dateRanges param { string } request . currencyCode param { google . analytics . data . v1alpha . CohortSpec } request . cohortSpec param { boolean } request . keepEmptyRows param { boolean } request . returnPropertyQuota param { object } options Call options. See  https for more details.
     *  returns { Promise } - The promise which resolves to an array.
     *   The first element of the array is an object representing [RunPivotReportResponse] google . analytics . data . v1alpha . RunPivotReportResponse .
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
     *   for more details and examples.
     *  example runPivotReport ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; if ( typeof optionsOrCallback === 'function' && callback === undefined ) { callback = optionsOrCallback ; options = { } ; } else { options = optionsOrCallback as CallOptions ; } options = options || { } ; this . initialize ( ) ; return this . innerApiCalls . runPivotReport ( request , options , callback ) ; } batchRunReports ( request ? , options ? ) ; batchRunReports ( request , options , callback ) ; batchRunReports ( request , callback ) ; param request param { google . analytics . data . v1alpha . Entity } request . entity param { number [ ] } request . requests param { object } options Call options. See  https for more details.
     *  returns { Promise } - The promise which resolves to an array.
     *   The first element of the array is an object representing [BatchRunReportsResponse] google . analytics . data . v1alpha . BatchRunReportsResponse .
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
     *   for more details and examples.
     *  example batchRunReports ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; if ( typeof optionsOrCallback === 'function' && callback === undefined ) { callback = optionsOrCallback ; options = { } ; } else { options = optionsOrCallback as CallOptions ; } options = options || { } ; this . initialize ( ) ; return this . innerApiCalls . batchRunReports ( request , options , callback ) ; } batchRunPivotReports ( request ? , options ? ) ; batchRunPivotReports ( request , options , callback ) ; batchRunPivotReports ( request , callback ) ; param request param { google . analytics . data . v1alpha . Entity } request . entity param { number [ ] } request . requests param { object } options Call options. See  https for more details.
     *  returns { Promise } - The promise which resolves to an array.
     *   The first element of the array is an object representing [BatchRunPivotReportsResponse] google . analytics . data . v1alpha . BatchRunPivotReportsResponse .
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
     *   for more details and examples.
     *  example batchRunPivotReports ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; if ( typeof optionsOrCallback === 'function' && callback === undefined ) { callback = optionsOrCallback ; options = { } ; } else { options = optionsOrCallback as CallOptions ; } options = options || { } ; this . initialize ( ) ; return this . innerApiCalls . batchRunPivotReports ( request , options , callback ) ; } getMetadata ( request ? , options ? ) ; getMetadata ( request , options , callback ) ; getMetadata ( request , callback ) ; param request param { string } request . name param { object } options Call options. See  https for more details.
     *  returns { Promise } - The promise which resolves to an array.
     *   The first element of the array is an object representing [Metadata] google . analytics . data . v1alpha . Metadata .
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
     *   for more details and examples.
     *  example getMetadata ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; if ( typeof optionsOrCallback === 'function' && callback === undefined ) { callback = optionsOrCallback ; options = { } ; } else { options = optionsOrCallback as CallOptions ; } options = options || { } ; options . otherArgs = options . otherArgs || { } ; options . otherArgs . headers = options . otherArgs . headers || { } ; options . otherArgs . headers [ 'x-goog-request-params' ] = gax . routingHeader . fromParams ( { name : request . name || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . getMetadata ( request , options , callback ) ; } runRealtimeReport ( request ? , options ? ) ; runRealtimeReport ( request , options , callback ) ; runRealtimeReport ( request , callback ) ; param request param { string } request . property param { number [ ] } request . dimensions param { number [ ] } request . metrics param { number } request . limit param { google . analytics . data . v1alpha . FilterExpression } request . dimensionFilter param { google . analytics . data . v1alpha . FilterExpression } request . metricFilter param { number [ ] } request . metricAggregations param { number [ ] } request . orderBys param { boolean } request . returnPropertyQuota param { object } options Call options. See  https for more details.
     *  returns { Promise } - The promise which resolves to an array.
     *   The first element of the array is an object representing [RunRealtimeReportResponse] google . analytics . data . v1alpha . RunRealtimeReportResponse .
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
     *   for more details and examples.
     *  example runRealtimeReport ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; if ( typeof optionsOrCallback === 'function' && callback === undefined ) { callback = optionsOrCallback ; options = { } ; } else { options = optionsOrCallback as CallOptions ; } options = options || { } ; options . otherArgs = options . otherArgs || { } ; options . otherArgs . headers = options . otherArgs . headers || { } ; options . otherArgs . headers [ 'x-goog-request-params' ] = gax . routingHeader . fromParams ( { property : request . property || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . runRealtimeReport ( request , options , callback ) ; } param { string } property returns { string } metadataPath ( property ) { return this . pathTemplates . metadataPathTemplate . render ( { property : property , } ) ; } param { string } metadataName returns { string } matchPropertyFromMetadataName ( metadataName ) { return this . pathTemplates . metadataPathTemplate . match ( metadataName ) . property ; } returns { Promise } close ( ) { this . initialize ( ) ; if ( ! this . _terminated ) { return this . alphaAnalyticsDataStub ! . then ( stub => { this . _terminated = true ; stub . close ( ) ; } ) ; } return Promise . resolve ( ) ; } }