google-ads-api 23.0.1 → 24.1.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.
@@ -18,7 +18,7 @@ class Client {
18
18
  refresh_token: refreshToken,
19
19
  });
20
20
  // @ts-expect-error Protected usage is fine here
21
- const customerService = await service.loadService("CustomerServiceClient");
21
+ const customerService = service.loadService("CustomerServiceClient", { skipCache: true });
22
22
  try {
23
23
  // @ts-expect-error Type definition is incorrect, response is an array
24
24
  const [response] = await customerService.listAccessibleCustomers({}, {
@@ -35,6 +35,10 @@ class Client {
35
35
  // @ts-expect-error Protected usage is fine here
36
36
  throw service.getGoogleAdsError(err);
37
37
  }
38
+ finally {
39
+ // @ts-expect-error close() exists on the gax client but not on the proto type
40
+ await customerService.close().catch(() => null);
41
+ }
38
42
  }
39
43
  }
40
44
  exports.Client = Client;
@@ -337,21 +337,28 @@ class Customer extends serviceFactory_1.default {
337
337
  });
338
338
  const pipeline = (0, stream_chain_1.chain)([stream, parser, (0, StreamArray_1.streamArray)()]);
339
339
  let count = 0;
340
- for await (const data of pipeline) {
341
- const results = data.value.results ??
342
- (data.value.summaryRow ? [data.value.summaryRow] : undefined) ??
343
- [];
344
- count += results.length;
345
- if (this.clientOptions.max_reporting_rows &&
346
- count > this.clientOptions.max_reporting_rows &&
347
- !this.gaqlQueryStringIncludesLimit(gaqlQuery)) {
348
- throw this.generateTooManyRowsError();
349
- }
350
- for (const row of results) {
351
- const parsed = this.decamelizeKeysIfNeeded(row);
352
- yield parsed;
340
+ try {
341
+ for await (const data of pipeline) {
342
+ const results = data.value.results ??
343
+ (data.value.summaryRow ? [data.value.summaryRow] : undefined) ??
344
+ [];
345
+ count += results.length;
346
+ if (this.clientOptions.max_reporting_rows &&
347
+ count > this.clientOptions.max_reporting_rows &&
348
+ !this.gaqlQueryStringIncludesLimit(gaqlQuery)) {
349
+ throw this.generateTooManyRowsError();
350
+ }
351
+ for (const row of results) {
352
+ const parsed = this.decamelizeKeysIfNeeded(row);
353
+ yield parsed;
354
+ }
353
355
  }
354
356
  }
357
+ finally {
358
+ pipeline.destroy();
359
+ parser.destroy();
360
+ stream.destroy();
361
+ }
355
362
  return;
356
363
  }
357
364
  catch (e) {
@@ -87,6 +87,27 @@ function parseRows(rows, fields) {
87
87
  }
88
88
  return newRows;
89
89
  }
90
+ function convertLongsToNumbers(value) {
91
+ const isPrimitive = value === null || typeof value !== "object";
92
+ if (isPrimitive) {
93
+ return value;
94
+ }
95
+ if (long_1.default.isLong(value)) {
96
+ return value.toNumber();
97
+ }
98
+ if (Array.isArray(value)) {
99
+ return value.map(convertLongsToNumbers);
100
+ }
101
+ const isBytesField = ArrayBuffer.isView(value);
102
+ if (isBytesField) {
103
+ return value;
104
+ }
105
+ const converted = {};
106
+ for (const [key, nestedValue] of Object.entries(value)) {
107
+ converted[key] = convertLongsToNumbers(nestedValue);
108
+ }
109
+ return converted;
110
+ }
90
111
  function parseNestedValues(row, data, field, paths) {
91
112
  if (!data)
92
113
  return null;
@@ -94,11 +115,7 @@ function parseNestedValues(row, data, field, paths) {
94
115
  if (!row)
95
116
  row = {};
96
117
  if (childFields.length === 0) {
97
- const rawVal = data[parentField];
98
- const parsedVal = long_1.default.isLong(rawVal)
99
- ? new long_1.default(rawVal.low, rawVal.high, rawVal.unsigned).toNumber()
100
- : rawVal;
101
- row[parentField] = parsedVal;
118
+ row[parentField] = convertLongsToNumbers(data[parentField]);
102
119
  return row;
103
120
  }
104
121
  row[parentField] = parseNestedValues(row[parentField], data[parentField], parentField, childFields);