UNPKG

google-ads-api-client

Version:

A friendly and exhaustive client to the google-ads-api, code generated directly from google's published protobuf schema.

31 lines 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAuthenticatedGoogleAdsApiGrpcTransport = void 0; const grpc_js_1 = require("@grpc/grpc-js"); const grpc_transport_1 = require("@protobuf-ts/grpc-transport"); const google_auth_library_1 = require("google-auth-library"); /** * creates an authenticated google-ads-api grcp transport, ready for use in making api calls * * ref: * - https://developers.google.com/google-ads/api/docs/concepts/call-structure#cid */ const getAuthenticatedGoogleAdsApiGrpcTransport = ({ clientId, clientSecret, refreshToken, developerToken, loginCustomerId, linkedCustomerId, }) => { const authClient = new google_auth_library_1.UserRefreshClient(clientId, clientSecret, refreshToken); const sslCreds = grpc_js_1.credentials.createSsl(); const transport = new grpc_transport_1.GrpcTransport({ host: 'googleads.googleapis.com', channelCredentials: grpc_js_1.credentials.combineChannelCredentials(sslCreds, grpc_js_1.credentials.createFromGoogleCredential(authClient), grpc_js_1.credentials.createFromMetadataGenerator((_, callback) => { const metadata = new grpc_js_1.Metadata(); metadata.add('developer-token', developerToken); if (loginCustomerId) metadata.add('login-customer-id', loginCustomerId); if (linkedCustomerId) metadata.add('linked-customer-id', linkedCustomerId); callback(null, metadata); })), }); return transport; }; exports.getAuthenticatedGoogleAdsApiGrpcTransport = getAuthenticatedGoogleAdsApiGrpcTransport; //# sourceMappingURL=getAuthenticatedGoogleAdsApiGrpcTransport.js.map