google-ads-api 10.0.2 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  import allProtos, { protos } from "google-ads-node";
2
- export declare const VERSION: "v10";
3
- export import common = protos.google.ads.googleads.v10.common;
4
- export import errors = protos.google.ads.googleads.v10.errors;
5
- export import resources = protos.google.ads.googleads.v10.resources;
6
- export import services = protos.google.ads.googleads.v10.services;
7
- export import internalEnums = protos.google.ads.googleads.v10.enums;
2
+ export declare const VERSION: "v11";
3
+ export import common = protos.google.ads.googleads.v11.common;
4
+ export import errors = protos.google.ads.googleads.v11.errors;
5
+ export import resources = protos.google.ads.googleads.v11.resources;
6
+ export import services = protos.google.ads.googleads.v11.services;
7
+ export import internalEnums = protos.google.ads.googleads.v11.enums;
8
8
  export { enums } from "./autogen/enums";
9
9
  export { fields } from "./autogen/fields";
10
10
  export { GoogleAdsServiceClient } from "google-ads-node";
@@ -1,18 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.longrunning = exports.protobuf = exports.GoogleAdsServiceClient = exports.fields = exports.enums = exports.internalEnums = exports.services = exports.resources = exports.errors = exports.common = exports.VERSION = void 0;
4
- var google_ads_node_1 = require("google-ads-node");
5
- var version_1 = require("../version");
4
+ const google_ads_node_1 = require("google-ads-node");
5
+ const version_1 = require("../version");
6
6
  // "as vN" is required to avoid type issues later on
7
7
  exports.VERSION = version_1.googleAdsVersion;
8
8
  // -- Expose the googleads generated types --
9
9
  // The namespace path is shortened for ease of use
10
- exports.common = google_ads_node_1.protos.google.ads.googleads.v10.common;
11
- exports.errors = google_ads_node_1.protos.google.ads.googleads.v10.errors;
12
- exports.resources = google_ads_node_1.protos.google.ads.googleads.v10.resources;
13
- exports.services = google_ads_node_1.protos.google.ads.googleads.v10.services;
10
+ exports.common = google_ads_node_1.protos.google.ads.googleads.v11.common;
11
+ exports.errors = google_ads_node_1.protos.google.ads.googleads.v11.errors;
12
+ exports.resources = google_ads_node_1.protos.google.ads.googleads.v11.resources;
13
+ exports.services = google_ads_node_1.protos.google.ads.googleads.v11.services;
14
14
  // We compile enums ourselves, the Google ones should be used internally only
15
- exports.internalEnums = google_ads_node_1.protos.google.ads.googleads.v10.enums;
15
+ exports.internalEnums = google_ads_node_1.protos.google.ads.googleads.v11.enums;
16
16
  var enums_1 = require("./autogen/enums");
17
17
  Object.defineProperty(exports, "enums", { enumerable: true, get: function () { return enums_1.enums; } });
18
18
  var fields_1 = require("./autogen/fields");
@@ -1,15 +1,8 @@
1
1
  "use strict";
2
- var __spreadArrays = (this && this.__spreadArrays) || function () {
3
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
- r[k] = a[j];
7
- return r;
8
- };
9
2
  Object.defineProperty(exports, "__esModule", { value: true });
10
3
  exports.buildQuery = exports.buildRequestOptions = exports.buildOrderClause = exports.buildOrderClauseNew = exports.buildOrderClauseOld = exports.completeOrderly = exports.buildLimitClause = exports.buildWhereClause = exports.extractDateConditions = exports.extractDateConstantConditions = exports.extractConstraintConditions = exports.convertNumericEnumToString = exports.validateConstraintKeyAndValue = exports.buildFromClause = exports.buildSelectClause = exports.QueryError = void 0;
11
- var protos_1 = require("./protos");
12
- var types_1 = require("./types");
4
+ const protos_1 = require("./protos");
5
+ const types_1 = require("./types");
13
6
  var QueryKeywords;
14
7
  (function (QueryKeywords) {
15
8
  QueryKeywords["SELECT"] = "SELECT";
@@ -23,25 +16,18 @@ var QueryKeywords;
23
16
  exports.QueryError = {
24
17
  INVALID_CONSTRAINTS_FORMAT: "Constraints must be an array of objects or a singular object.",
25
18
  INVALID_CONSTRAINT_KEY: "A constraint key must have a string value.",
26
- INVALID_CONSTRAINT_VALUE: function (key, val) {
27
- // @ts-ignore
28
- return "The value of the constraint " + key + " must be a string, number, boolean, or an array of these types. Here, typeof " + key + " is " + typeof val + ".";
29
- },
19
+ INVALID_CONSTRAINT_VALUE: (key, val) =>
20
+ // @ts-ignore
21
+ `The value of the constraint ${key} must be a string, number, boolean, or an array of these types. Here, typeof ${key} is ${typeof val}.`,
30
22
  INVALID_CONSTRAINT_OBJECT_FORMAT: "Must specify { key, op, val } or { key: value } when using object-style constraints.",
31
- INVALID_DATE_CONSTANT_TYPE: function (dateConstant) {
32
- return "Date constant must be a string. Here, typeof date constant is " + typeof dateConstant;
33
- },
34
- INVALID_FROM_DATE_TYPE: function (fromDate) {
35
- return "From date must be a string. Here, typeof from date is " + typeof fromDate;
36
- },
37
- INVALID_TO_DATE_TYPE: function (toDate) {
38
- return "To date must be a string. Here, typeof to date is " + typeof toDate;
39
- },
23
+ INVALID_DATE_CONSTANT_TYPE: (dateConstant) => `Date constant must be a string. Here, typeof date constant is ${typeof dateConstant}`,
24
+ INVALID_FROM_DATE_TYPE: (fromDate) => `From date must be a string. Here, typeof from date is ${typeof fromDate}`,
25
+ INVALID_TO_DATE_TYPE: (toDate) => `To date must be a string. Here, typeof to date is ${typeof toDate}`,
40
26
  INVALID_LIMIT: "Limit must be a positive integer.",
41
27
  INVALID_ORDER: "Order must be an array.",
42
28
  INVALID_ORDERLY: "OrderBy arrays must only contain strings.",
43
29
  INVALID_ORDERBY: "OrderBy must be a string or an array of strings.",
44
- INVALID_SORT_ORDER: "Sort order must be \"ASC\" or \"DESC\".",
30
+ INVALID_SORT_ORDER: `Sort order must be "ASC" or "DESC".`,
45
31
  MISSING_FIELDS: 'Must specify at least one field in ("attributes","metrics","segments").',
46
32
  MISSING_FROM_DATE: 'Expected start date range is missing - "from_date".',
47
33
  UNDEFINED_ENTITY: "The entity of the query must be defined.",
@@ -50,15 +36,19 @@ function buildSelectClause(attributes, metrics, segments) {
50
36
  if (!(attributes === null || attributes === void 0 ? void 0 : attributes.length) && !(metrics === null || metrics === void 0 ? void 0 : metrics.length) && !(segments === null || segments === void 0 ? void 0 : segments.length)) {
51
37
  throw new Error(exports.QueryError.MISSING_FIELDS);
52
38
  }
53
- var selections = __spreadArrays((attributes || []), (metrics || []), (segments || [])).join(", ");
54
- return QueryKeywords.SELECT + " " + selections;
39
+ const selections = [
40
+ ...(attributes || []),
41
+ ...(metrics || []),
42
+ ...(segments || []),
43
+ ].join(", ");
44
+ return `${QueryKeywords.SELECT} ${selections}`;
55
45
  }
56
46
  exports.buildSelectClause = buildSelectClause;
57
47
  function buildFromClause(entity) {
58
48
  if (typeof entity === "undefined") {
59
49
  throw new Error(exports.QueryError.UNDEFINED_ENTITY);
60
50
  }
61
- return " " + QueryKeywords.FROM + " " + entity;
51
+ return ` ${QueryKeywords.FROM} ${entity}`;
62
52
  }
63
53
  exports.buildFromClause = buildFromClause;
64
54
  function validateConstraintKeyAndValue(key, op, val) {
@@ -67,25 +57,25 @@ function validateConstraintKeyAndValue(key, op, val) {
67
57
  }
68
58
  if (typeof val === "string") {
69
59
  if (types_1.dateConstants.includes(val)) {
70
- return { op: op, val: val };
60
+ return { op, val };
71
61
  }
72
62
  return {
73
63
  op: "=",
74
- val: new RegExp(/^'.*'$|^".*"$/g).test(val) ? val : "\"" + val + "\"",
64
+ val: new RegExp(/^'.*'$|^".*"$/g).test(val) ? val : `"${val}"`,
75
65
  }; // must start and end in either single or double quotation marks
76
66
  }
77
67
  if (Array.isArray(val)) {
78
- var stringifiedValue = val
79
- .map(function (v) {
68
+ const stringifiedValue = val
69
+ .map((v) => {
80
70
  if (typeof v === "string") {
81
- return "\"" + v + "\"";
71
+ return `"${v}"`;
82
72
  }
83
73
  else {
84
74
  return convertNumericEnumToString(key, v);
85
75
  }
86
76
  })
87
- .join(", ");
88
- return { op: "IN", val: "(" + stringifiedValue + ")" };
77
+ .join(`, `);
78
+ return { op: "IN", val: `(${stringifiedValue})` };
89
79
  }
90
80
  throw new Error(exports.QueryError.INVALID_CONSTRAINT_VALUE(key, val));
91
81
  }
@@ -94,9 +84,9 @@ function convertNumericEnumToString(key, val) {
94
84
  // @ts-expect-error key does not always match an enum field
95
85
  if (protos_1.fields.enumFields[key] && typeof val === "number") {
96
86
  // @ts-expect-error typescript doesn't like accessing items in a namespace with a string
97
- var enumStringValue = protos_1.enums[protos_1.fields.enumFields[key]][val]; // e.g. enums['CampaignStatus'][2] = "ENABLED"
87
+ const enumStringValue = protos_1.enums[protos_1.fields.enumFields[key]][val]; // e.g. enums['CampaignStatus'][2] = "ENABLED"
98
88
  if (enumStringValue) {
99
- return "\"" + enumStringValue + "\"";
89
+ return `"${enumStringValue}"`;
100
90
  }
101
91
  }
102
92
  return val;
@@ -107,22 +97,22 @@ function extractConstraintConditions(constraints) {
107
97
  return [];
108
98
  }
109
99
  else if (Array.isArray(constraints)) {
110
- return constraints.map(function (con) {
100
+ return constraints.map((con) => {
111
101
  if (typeof con === "object" && !Array.isArray(con) && con !== null) {
112
102
  // @ts-ignore
113
103
  if (con.key && con.op && typeof con.val !== "undefined") {
114
- var _a = con, key = _a.key, op = _a.op, val = _a.val;
104
+ const { key, op, val } = con;
115
105
  if (typeof key !== "string") {
116
106
  throw new Error(exports.QueryError.INVALID_CONSTRAINT_KEY);
117
107
  }
118
- var validatedValue = validateConstraintKeyAndValue(key, op, val);
108
+ const validatedValue = validateConstraintKeyAndValue(key, op, val);
119
109
  // @ts-ignore
120
- return key + " " + op + " " + validatedValue.val;
110
+ return `${key} ${op} ${validatedValue.val}`;
121
111
  }
122
112
  else if (Object.keys(con).length === 1) {
123
- var _b = Object.entries(con)[0], key = _b[0], val = _b[1];
124
- var validatedValue = validateConstraintKeyAndValue(key, "=", val);
125
- return key + " " + validatedValue.op + " " + validatedValue.val;
113
+ const [[key, val]] = Object.entries(con);
114
+ const validatedValue = validateConstraintKeyAndValue(key, "=", val);
115
+ return `${key} ${validatedValue.op} ${validatedValue.val}`;
126
116
  }
127
117
  else {
128
118
  throw new Error(exports.QueryError.INVALID_CONSTRAINT_OBJECT_FORMAT);
@@ -137,10 +127,9 @@ function extractConstraintConditions(constraints) {
137
127
  });
138
128
  }
139
129
  else if (typeof constraints === "object" && constraints !== null) {
140
- return Object.entries(constraints).map(function (_a) {
141
- var key = _a[0], val = _a[1];
142
- var validatedValue = validateConstraintKeyAndValue(key, "=", val);
143
- return key + " " + validatedValue.op + " " + validatedValue.val;
130
+ return Object.entries(constraints).map(([key, val]) => {
131
+ const validatedValue = validateConstraintKeyAndValue(key, "=", val);
132
+ return `${key} ${validatedValue.op} ${validatedValue.val}`;
144
133
  });
145
134
  }
146
135
  else {
@@ -155,7 +144,7 @@ function extractDateConstantConditions(dateConstant) {
155
144
  else if (typeof dateConstant !== "string") {
156
145
  throw new Error(exports.QueryError.INVALID_DATE_CONSTANT_TYPE(dateConstant));
157
146
  }
158
- return ["segments.date DURING " + dateConstant];
147
+ return [`segments.date DURING ${dateConstant}`];
159
148
  }
160
149
  exports.extractDateConstantConditions = extractDateConstantConditions;
161
150
  function extractDateConditions(fromDate, toDate) {
@@ -166,8 +155,8 @@ function extractDateConditions(fromDate, toDate) {
166
155
  throw new Error(exports.QueryError.MISSING_FROM_DATE);
167
156
  }
168
157
  if (typeof fromDate !== "undefined" && typeof toDate === "undefined") {
169
- var d = new Date();
170
- toDate = d.getFullYear() + "-" + ("0" + (d.getMonth() + 1)).slice(-2) + "-" + ("0" + d.getDate()).slice(-2);
158
+ const d = new Date();
159
+ toDate = `${d.getFullYear()}-${("0" + (d.getMonth() + 1)).slice(-2)}-${("0" + d.getDate()).slice(-2)}`;
171
160
  }
172
161
  if (typeof fromDate !== "string") {
173
162
  throw new Error(exports.QueryError.INVALID_FROM_DATE_TYPE(fromDate));
@@ -176,29 +165,33 @@ function extractDateConditions(fromDate, toDate) {
176
165
  throw new Error(exports.QueryError.INVALID_TO_DATE_TYPE(toDate));
177
166
  }
178
167
  return [
179
- "segments.date >= \"" + fromDate + "\"",
180
- "segments.date <= \"" + toDate + "\"",
168
+ `segments.date >= "${fromDate}"`,
169
+ `segments.date <= "${toDate}"`,
181
170
  ];
182
171
  }
183
172
  exports.extractDateConditions = extractDateConditions;
184
173
  function buildWhereClause(constraints, dateConstant, fromDate, toDate) {
185
- var constraintClauses = extractConstraintConditions(constraints);
186
- var dateConstantClauses = extractDateConstantConditions(dateConstant);
187
- var dateClauses = extractDateConditions(fromDate, toDate);
188
- var whereClauses = __spreadArrays(constraintClauses, dateConstantClauses, dateClauses).join(" " + QueryKeywords.AND + " ");
174
+ const constraintClauses = extractConstraintConditions(constraints);
175
+ const dateConstantClauses = extractDateConstantConditions(dateConstant);
176
+ const dateClauses = extractDateConditions(fromDate, toDate);
177
+ const whereClauses = [
178
+ ...constraintClauses,
179
+ ...dateConstantClauses,
180
+ ...dateClauses,
181
+ ].join(` ${QueryKeywords.AND} `);
189
182
  return whereClauses.length
190
- ? " " + QueryKeywords.WHERE + " " + whereClauses
191
- : "";
183
+ ? ` ${QueryKeywords.WHERE} ${whereClauses}`
184
+ : ``;
192
185
  }
193
186
  exports.buildWhereClause = buildWhereClause;
194
187
  function buildLimitClause(limit) {
195
188
  if (typeof limit === "undefined") {
196
- return "";
189
+ return ``;
197
190
  }
198
191
  if (typeof limit !== "number" || limit < 1 || !Number.isInteger(limit)) {
199
192
  throw new Error(exports.QueryError.INVALID_LIMIT);
200
193
  }
201
- return " " + QueryKeywords.LIMIT + " " + limit;
194
+ return ` ${QueryKeywords.LIMIT} ${limit}`;
202
195
  }
203
196
  exports.buildLimitClause = buildLimitClause;
204
197
  function completeOrderly(orderly, entity) {
@@ -211,7 +204,7 @@ function completeOrderly(orderly, entity) {
211
204
  }
212
205
  else if (new RegExp(/^[^.\s]+$/g).test(orderly)) {
213
206
  // text without a full stop (e.g. resource_name)
214
- return entity + "." + orderly;
207
+ return `${entity}.${orderly}`;
215
208
  }
216
209
  else {
217
210
  throw new Error(exports.QueryError.INVALID_ORDERLY);
@@ -220,7 +213,7 @@ function completeOrderly(orderly, entity) {
220
213
  exports.completeOrderly = completeOrderly;
221
214
  function buildOrderClauseOld(orderBy, sortOrder, entity) {
222
215
  if (typeof orderBy === "undefined") {
223
- return "";
216
+ return ``;
224
217
  }
225
218
  else if (typeof sortOrder === "undefined") {
226
219
  sortOrder = "DESC";
@@ -229,8 +222,8 @@ function buildOrderClauseOld(orderBy, sortOrder, entity) {
229
222
  throw new Error(exports.QueryError.INVALID_SORT_ORDER);
230
223
  }
231
224
  if (Array.isArray(orderBy)) {
232
- var orders = orderBy
233
- .map(function (orderly) {
225
+ const orders = orderBy
226
+ .map((orderly) => {
234
227
  if (typeof orderly !== "string") {
235
228
  throw new Error(exports.QueryError.INVALID_ORDERLY);
236
229
  }
@@ -239,10 +232,10 @@ function buildOrderClauseOld(orderBy, sortOrder, entity) {
239
232
  }
240
233
  })
241
234
  .join(", ");
242
- return " " + QueryKeywords.ORDER_BY + " " + orders + " " + sortOrder;
235
+ return ` ${QueryKeywords.ORDER_BY} ${orders} ${sortOrder}`;
243
236
  }
244
237
  else if (typeof orderBy === "string") {
245
- return " " + QueryKeywords.ORDER_BY + " " + completeOrderly(orderBy, entity) + " " + sortOrder;
238
+ return ` ${QueryKeywords.ORDER_BY} ${completeOrderly(orderBy, entity)} ${sortOrder}`;
246
239
  }
247
240
  else {
248
241
  throw new Error(exports.QueryError.INVALID_ORDERBY);
@@ -256,14 +249,14 @@ function buildOrderClauseNew(order, entity) {
256
249
  if (!order.length) {
257
250
  return "";
258
251
  }
259
- var orders = order
260
- .map(function (o) {
261
- var orderly = completeOrderly(o.field, entity);
262
- var sortOrder = o.sort_order ? o.sort_order : "DESC";
263
- return orderly + " " + sortOrder;
252
+ const orders = order
253
+ .map((o) => {
254
+ const orderly = completeOrderly(o.field, entity);
255
+ const sortOrder = o.sort_order ? o.sort_order : "DESC";
256
+ return `${orderly} ${sortOrder}`;
264
257
  })
265
258
  .join(", ");
266
- return " " + QueryKeywords.ORDER_BY + " " + orders;
259
+ return ` ${QueryKeywords.ORDER_BY} ${orders}`;
267
260
  }
268
261
  exports.buildOrderClauseNew = buildOrderClauseNew;
269
262
  function buildOrderClause(order, orderBy, sortOrder, entity) {
@@ -276,20 +269,20 @@ function buildOrderClause(order, orderBy, sortOrder, entity) {
276
269
  }
277
270
  exports.buildOrderClause = buildOrderClause;
278
271
  function buildRequestOptions(reportOptions) {
279
- var page_size = reportOptions.page_size, page_token = reportOptions.page_token, validate_only = reportOptions.validate_only, summary_row_setting = reportOptions.summary_row_setting;
280
- return { page_size: page_size, page_token: page_token, validate_only: validate_only, summary_row_setting: summary_row_setting };
272
+ const { page_size, page_token, validate_only, summary_row_setting } = reportOptions;
273
+ return { page_size, page_token, validate_only, summary_row_setting };
281
274
  }
282
275
  exports.buildRequestOptions = buildRequestOptions;
283
276
  function buildQuery(reportOptions) {
284
- var SELECT = buildSelectClause(reportOptions.attributes, reportOptions.metrics, reportOptions.segments);
285
- var FROM = buildFromClause(reportOptions.entity);
286
- var WHERE = buildWhereClause(reportOptions.constraints, reportOptions.date_constant, reportOptions.from_date, reportOptions.to_date);
287
- var LIMIT = buildLimitClause(reportOptions.limit);
288
- var ORDER = buildOrderClause(reportOptions.order, reportOptions.order_by, reportOptions.sort_order, reportOptions.entity);
289
- var requestOptions = buildRequestOptions(reportOptions);
277
+ const SELECT = buildSelectClause(reportOptions.attributes, reportOptions.metrics, reportOptions.segments);
278
+ const FROM = buildFromClause(reportOptions.entity);
279
+ const WHERE = buildWhereClause(reportOptions.constraints, reportOptions.date_constant, reportOptions.from_date, reportOptions.to_date);
280
+ const LIMIT = buildLimitClause(reportOptions.limit);
281
+ const ORDER = buildOrderClause(reportOptions.order, reportOptions.order_by, reportOptions.sort_order, reportOptions.entity);
282
+ const requestOptions = buildRequestOptions(reportOptions);
290
283
  return {
291
- gaqlQuery: "" + SELECT + FROM + WHERE + ORDER + LIMIT,
292
- requestOptions: requestOptions,
284
+ gaqlQuery: `${SELECT}${FROM}${WHERE}${ORDER}${LIMIT}`,
285
+ requestOptions,
293
286
  };
294
287
  }
295
288
  exports.buildQuery = buildQuery;
@@ -1,148 +1,140 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.Service = exports.FAILURE_KEY = void 0;
15
- var google_gax_1 = require("google-gax");
16
- var google_auth_library_1 = require("google-auth-library");
17
- var protos_1 = require("./protos");
18
- var utils_1 = require("./utils");
19
- var version_1 = require("./version");
4
+ const google_gax_1 = require("google-gax");
5
+ const google_auth_library_1 = require("google-auth-library");
6
+ const protos_1 = require("./protos");
7
+ const utils_1 = require("./utils");
8
+ const version_1 = require("./version");
20
9
  // Make sure to update this version number when upgrading
21
- exports.FAILURE_KEY = "google.ads.googleads." + version_1.googleAdsVersion + ".errors.googleadsfailure-bin";
22
- var Service = /** @class */ (function () {
23
- function Service(clientOptions, customerOptions, hooks) {
10
+ exports.FAILURE_KEY = `google.ads.googleads.${version_1.googleAdsVersion}.errors.googleadsfailure-bin`;
11
+ class Service {
12
+ constructor(clientOptions, customerOptions, hooks) {
24
13
  this.clientOptions = clientOptions;
25
14
  this.customerOptions = customerOptions;
26
15
  this.hooks = hooks !== null && hooks !== void 0 ? hooks : {};
27
16
  // @ts-expect-error All fields don't need to be set here
28
17
  this.serviceCache = {};
29
18
  }
30
- Object.defineProperty(Service.prototype, "credentials", {
31
- get: function () {
32
- return {
33
- customer_id: this.customerOptions.customer_id,
34
- login_customer_id: this.customerOptions.login_customer_id,
35
- linked_customer_id: this.customerOptions.linked_customer_id,
36
- };
37
- },
38
- enumerable: false,
39
- configurable: true
40
- });
41
- Object.defineProperty(Service.prototype, "callHeaders", {
42
- get: function () {
43
- var headers = {
44
- "developer-token": this.clientOptions.developer_token,
45
- };
46
- if (this.customerOptions.login_customer_id) {
47
- headers["login-customer-id"] = this.customerOptions.login_customer_id;
48
- }
49
- if (this.customerOptions.linked_customer_id) {
50
- headers["linked-customer-id"] = this.customerOptions.linked_customer_id;
51
- }
52
- return headers;
53
- },
54
- enumerable: false,
55
- configurable: true
56
- });
57
- Service.prototype.getCredentials = function () {
58
- var sslCreds = google_gax_1.grpc.credentials.createSsl();
59
- var authClient = new google_auth_library_1.UserRefreshClient(this.clientOptions.client_id, this.clientOptions.client_secret, this.customerOptions.refresh_token);
60
- var credentials = google_gax_1.grpc.credentials.combineChannelCredentials(sslCreds, google_gax_1.grpc.credentials.createFromGoogleCredential(authClient));
19
+ get credentials() {
20
+ return {
21
+ customer_id: this.customerOptions.customer_id,
22
+ login_customer_id: this.customerOptions.login_customer_id,
23
+ linked_customer_id: this.customerOptions.linked_customer_id,
24
+ };
25
+ }
26
+ get callHeaders() {
27
+ const headers = {
28
+ "developer-token": this.clientOptions.developer_token,
29
+ };
30
+ if (this.customerOptions.login_customer_id) {
31
+ headers["login-customer-id"] = this.customerOptions.login_customer_id;
32
+ }
33
+ if (this.customerOptions.linked_customer_id) {
34
+ headers["linked-customer-id"] = this.customerOptions.linked_customer_id;
35
+ }
36
+ return headers;
37
+ }
38
+ getCredentials() {
39
+ const sslCreds = google_gax_1.grpc.credentials.createSsl();
40
+ const authClient = new google_auth_library_1.UserRefreshClient(this.clientOptions.client_id, this.clientOptions.client_secret, this.customerOptions.refresh_token);
41
+ const credentials = google_gax_1.grpc.credentials.combineChannelCredentials(sslCreds, google_gax_1.grpc.credentials.createFromGoogleCredential(authClient));
61
42
  return credentials;
62
- };
63
- Service.prototype.loadService = function (service) {
43
+ }
44
+ loadService(service) {
64
45
  if (this.serviceCache[service]) {
65
46
  return this.serviceCache[service];
66
47
  }
67
48
  // eslint-disable-next-line @typescript-eslint/no-var-requires
68
- var _a = require("google-ads-node"), _b = service, protoService = _a[_b];
49
+ const { [service]: protoService } = require("google-ads-node");
69
50
  if (typeof protoService === "undefined") {
70
- throw new Error("Service \"" + service + "\" could not be found");
51
+ throw new Error(`Service "${service}" could not be found`);
71
52
  }
72
- var client = new protoService({
53
+ const client = new protoService({
73
54
  sslCreds: this.getCredentials(),
74
55
  });
75
56
  this.serviceCache[service] = client;
76
57
  return client;
77
- };
78
- Service.prototype.getGoogleAdsError = function (error) {
58
+ }
59
+ getGoogleAdsError(error) {
79
60
  var _a;
80
61
  // @ts-expect-error No type exists for GA query error
81
62
  if (typeof ((_a = error === null || error === void 0 ? void 0 : error.metadata) === null || _a === void 0 ? void 0 : _a.internalRepr.get(exports.FAILURE_KEY)) === "undefined") {
82
63
  return error;
83
64
  }
84
65
  // @ts-expect-error No type exists for GA query error
85
- var buffer = error.metadata.internalRepr.get(exports.FAILURE_KEY)[0];
66
+ const [buffer] = error.metadata.internalRepr.get(exports.FAILURE_KEY);
86
67
  return this.decodeGoogleAdsFailureBuffer(buffer);
87
- };
88
- Service.prototype.decodeGoogleAdsFailureBuffer = function (buffer) {
89
- var googleAdsFailure = protos_1.errors.GoogleAdsFailure.decode(buffer);
68
+ }
69
+ decodeGoogleAdsFailureBuffer(buffer) {
70
+ const googleAdsFailure = protos_1.errors.GoogleAdsFailure.decode(buffer);
90
71
  return googleAdsFailure;
91
- };
92
- Service.prototype.decodePartialFailureError = function (response) {
72
+ }
73
+ decodePartialFailureError(response) {
93
74
  var _a, _b, _c;
94
75
  if (typeof ((_a = response) === null || _a === void 0 ? void 0 : _a.partial_failure_error) === "undefined" ||
95
76
  !((_b = response) === null || _b === void 0 ? void 0 : _b.partial_failure_error)) {
96
77
  return response;
97
78
  }
98
- var details = response.partial_failure_error.details;
99
- var buffer = (_c = details === null || details === void 0 ? void 0 : details.find(function (d) {
100
- return d.type_url.includes("errors.GoogleAdsFailure");
101
- })) === null || _c === void 0 ? void 0 : _c.value;
79
+ const { details } = response.partial_failure_error;
80
+ const buffer = (_c = details === null || details === void 0 ? void 0 : details.find((d) => d.type_url.includes("errors.GoogleAdsFailure"))) === null || _c === void 0 ? void 0 : _c.value;
102
81
  if (typeof buffer === "undefined") {
103
82
  return response;
104
83
  }
105
84
  // Update the partial failure field with the decoded error details
106
- return __assign(__assign({}, response), { partial_failure_error: this.decodeGoogleAdsFailureBuffer(buffer) });
107
- };
108
- Service.prototype.buildSearchRequestAndService = function (gaql, options) {
109
- var service = this.loadService("GoogleAdsServiceClient");
110
- var request = new protos_1.services.SearchGoogleAdsRequest(__assign({ customer_id: this.customerOptions.customer_id, query: gaql }, options));
111
- return { service: service, request: request };
112
- };
113
- Service.prototype.buildSearchStreamRequestAndService = function (gaql, options) {
114
- var service = this.loadService("GoogleAdsServiceClient");
115
- var request = new protos_1.services.SearchGoogleAdsStreamRequest(__assign({ customer_id: this.customerOptions.customer_id, query: gaql }, options));
116
- return { service: service, request: request };
117
- };
118
- Service.prototype.buildMutationRequestAndService = function (mutations, options) {
119
- var service = this.loadService("GoogleAdsServiceClient");
120
- var mutateOperations = mutations.map(function (mutation) {
121
- var _a, _b;
122
- var _c;
123
- var opKey = utils_1.toSnakeCase(mutation.entity + "Operation");
124
- var operation = (_a = {},
125
- _a[(_c = mutation.operation) !== null && _c !== void 0 ? _c : "create"] = mutation.resource,
126
- _a);
85
+ return {
86
+ ...response,
87
+ partial_failure_error: this.decodeGoogleAdsFailureBuffer(buffer),
88
+ };
89
+ }
90
+ buildSearchRequestAndService(gaql, options) {
91
+ const service = this.loadService("GoogleAdsServiceClient");
92
+ const request = new protos_1.services.SearchGoogleAdsRequest({
93
+ customer_id: this.customerOptions.customer_id,
94
+ query: gaql,
95
+ ...options,
96
+ });
97
+ return { service, request };
98
+ }
99
+ buildSearchStreamRequestAndService(gaql, options) {
100
+ const service = this.loadService("GoogleAdsServiceClient");
101
+ const request = new protos_1.services.SearchGoogleAdsStreamRequest({
102
+ customer_id: this.customerOptions.customer_id,
103
+ query: gaql,
104
+ ...options,
105
+ });
106
+ return { service, request };
107
+ }
108
+ buildMutationRequestAndService(mutations, options) {
109
+ const service = this.loadService("GoogleAdsServiceClient");
110
+ const mutateOperations = mutations.map((mutation) => {
111
+ var _a;
112
+ const opKey = utils_1.toSnakeCase(`${mutation.entity}Operation`);
113
+ const operation = {
114
+ [(_a = mutation.operation) !== null && _a !== void 0 ? _a : "create"]: mutation.resource,
115
+ };
127
116
  if (mutation.operation === "update") {
128
117
  // @ts-expect-error Resource operations should have updateMask defined
129
118
  operation.update_mask = utils_1.getFieldMask(mutation.resource);
130
119
  }
131
- var mutateOperation = new protos_1.services.MutateOperation((_b = {},
132
- _b[opKey] = operation,
133
- _b));
120
+ const mutateOperation = new protos_1.services.MutateOperation({
121
+ [opKey]: operation,
122
+ });
134
123
  return mutateOperation;
135
124
  });
136
- var request = new protos_1.services.MutateGoogleAdsRequest(__assign({ customer_id: this.customerOptions.customer_id, mutate_operations: mutateOperations }, options));
137
- return { service: service, request: request };
138
- };
139
- Service.prototype.buildOperations = function (type, entities, message) {
140
- var ops = entities.map(function (e) {
141
- var _a;
142
- var op = (_a = {},
143
- _a[type] = e,
144
- _a.operation = type,
145
- _a);
125
+ const request = new protos_1.services.MutateGoogleAdsRequest({
126
+ customer_id: this.customerOptions.customer_id,
127
+ mutate_operations: mutateOperations,
128
+ ...options,
129
+ });
130
+ return { service, request };
131
+ }
132
+ buildOperations(type, entities, message) {
133
+ const ops = entities.map((e) => {
134
+ const op = {
135
+ [type]: e,
136
+ operation: type,
137
+ };
146
138
  if (type === "update") {
147
139
  // @ts-expect-error Field required for updates
148
140
  op.update_mask = utils_1.getFieldMask(
@@ -154,11 +146,14 @@ var Service = /** @class */ (function () {
154
146
  return op;
155
147
  });
156
148
  return ops;
157
- };
158
- Service.prototype.buildRequest = function (operations, options) {
159
- var request = __assign({ customer_id: this.customerOptions.customer_id, operations: operations }, options);
149
+ }
150
+ buildRequest(operations, options) {
151
+ const request = {
152
+ customer_id: this.customerOptions.customer_id,
153
+ operations,
154
+ ...options,
155
+ };
160
156
  return request;
161
- };
162
- return Service;
163
- }());
157
+ }
158
+ }
164
159
  exports.Service = Service;