UNPKG

@htdangkhoa/google-ads

Version:
47 lines (46 loc) 2.29 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Service = void 0; const ServiceProvider_js_1 = require("./ServiceProvider.js"); const utils_js_1 = require("./utils.js"); const LoggingInterceptor_js_1 = require("./LoggingInterceptor.js"); const constants_js_1 = require("./constants.js"); const index_js_1 = require("./generated/index.js"); class Service extends ServiceProvider_js_1.ServiceProvider { constructor(options) { super(); this.cachedClients = {}; this.options = options; } get callMetadata() { throw new Error('Not implemented'); } loadService(serviceName) { if (this.cachedClients[serviceName]) return this.cachedClients[serviceName]; const ProtoService = index_js_1.google.ads.googleads[constants_js_1.VERSION].services[serviceName]; if (!ProtoService) { throw new Error(`Service ${serviceName} not found.`); } const _a = this.options, { auth, developer_token, logging, interceptors = [], callInvocationTransformer } = _a, opts = __rest(_a, ["auth", "developer_token", "logging", "interceptors", "callInvocationTransformer"]); const credentials = (0, utils_js_1.getCredentials)(auth); const logger = new LoggingInterceptor_js_1.LoggingInterceptor(logging || false); const client = new ProtoService(constants_js_1.HOST, credentials, Object.assign(Object.assign({}, opts), { interceptors: [logger.interceptCall.bind(logger), ...interceptors], callInvocationTransformer: (properties) => { return logger.callInvocationTransformer(properties, callInvocationTransformer); } })); this.cachedClients[serviceName] = client; return client; } } exports.Service = Service;