google-ads-api 24.1.0 → 25.1.0-beta.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.
Files changed (76) hide show
  1. package/README.md +9 -1
  2. package/build/{src → cjs}/client.d.ts +6 -4
  3. package/build/{src → cjs}/client.js +4 -4
  4. package/build/{src → cjs}/customer.d.ts +5 -5
  5. package/build/{src → cjs}/customer.js +24 -20
  6. package/build/{src → cjs}/hooks.d.ts +2 -2
  7. package/build/cjs/index.d.ts +9 -0
  8. package/build/{src → cjs}/index.js +22 -20
  9. package/build/{src → cjs}/parser.d.ts +2 -2
  10. package/build/{src → cjs}/parser.js +5 -5
  11. package/build/{src → cjs}/parserRest.js +7 -7
  12. package/build/{src → cjs}/protos/autogen/enums.d.ts +1679 -1180
  13. package/build/{src → cjs}/protos/autogen/enums.js +1696 -1177
  14. package/build/cjs/protos/autogen/fields.d.ts +1191 -0
  15. package/build/cjs/protos/autogen/fields.js +205 -0
  16. package/build/cjs/protos/autogen/resourceNames.d.ts +1668 -0
  17. package/build/cjs/protos/autogen/resourceNames.js +1669 -0
  18. package/build/{src → cjs}/protos/autogen/serviceFactory.d.ts +206 -215
  19. package/build/{src → cjs}/protos/autogen/serviceFactory.js +483 -554
  20. package/build/cjs/protos/index.d.ts +14 -0
  21. package/build/{src → cjs}/protos/index.js +12 -12
  22. package/build/{src → cjs}/query.d.ts +2 -2
  23. package/build/{src → cjs}/query.js +5 -5
  24. package/build/{src → cjs}/service.d.ts +5 -5
  25. package/build/{src → cjs}/service.js +64 -22
  26. package/build/{src → cjs}/types.d.ts +1 -1
  27. package/build/{src → cjs}/utils.d.ts +1 -1
  28. package/build/{src → cjs}/utils.js +2 -2
  29. package/build/cjs/version.d.ts +1 -0
  30. package/build/{src → cjs}/version.js +1 -1
  31. package/build/esm/client.d.ts +19 -0
  32. package/build/esm/client.js +40 -0
  33. package/build/esm/customer.d.ts +71 -0
  34. package/build/esm/customer.js +502 -0
  35. package/build/esm/hooks.d.ts +160 -0
  36. package/build/esm/hooks.js +1 -0
  37. package/build/esm/index.d.ts +9 -0
  38. package/build/esm/index.js +10 -0
  39. package/build/esm/package.json +1 -0
  40. package/build/esm/parser.d.ts +21 -0
  41. package/build/esm/parser.js +113 -0
  42. package/build/esm/parserRest.d.ts +1 -0
  43. package/build/esm/parserRest.js +112 -0
  44. package/build/esm/protos/autogen/enums.d.ts +6002 -0
  45. package/build/esm/protos/autogen/enums.js +6401 -0
  46. package/build/esm/protos/autogen/fields.d.ts +1191 -0
  47. package/build/esm/protos/autogen/fields.js +202 -0
  48. package/build/esm/protos/autogen/resourceNames.d.ts +1668 -0
  49. package/build/esm/protos/autogen/resourceNames.js +1475 -0
  50. package/build/esm/protos/autogen/serviceFactory.d.ts +1825 -0
  51. package/build/esm/protos/autogen/serviceFactory.js +18795 -0
  52. package/build/esm/protos/index.d.ts +14 -0
  53. package/build/esm/protos/index.js +19 -0
  54. package/build/esm/query.d.ts +62 -0
  55. package/build/esm/query.js +304 -0
  56. package/build/esm/service.d.ts +47 -0
  57. package/build/esm/service.js +222 -0
  58. package/build/esm/types.d.ts +75 -0
  59. package/build/esm/types.js +14 -0
  60. package/build/esm/utils.d.ts +49 -0
  61. package/build/esm/utils.js +108 -0
  62. package/build/esm/version.d.ts +1 -0
  63. package/build/esm/version.js +1 -0
  64. package/package.json +50 -11
  65. package/build/src/index.d.ts +0 -8
  66. package/build/src/protos/autogen/fields.d.ts +0 -1122
  67. package/build/src/protos/autogen/fields.js +0 -644
  68. package/build/src/protos/autogen/resourceNames.d.ts +0 -1609
  69. package/build/src/protos/autogen/resourceNames.js +0 -1982
  70. package/build/src/protos/index.d.ts +0 -14
  71. package/build/src/testUtils.d.ts +0 -107
  72. package/build/src/testUtils.js +0 -333
  73. package/build/src/version.d.ts +0 -1
  74. /package/build/{src → cjs}/hooks.js +0 -0
  75. /package/build/{src → cjs}/parserRest.d.ts +0 -0
  76. /package/build/{src → cjs}/types.js +0 -0
@@ -0,0 +1,14 @@
1
+ import allProtos, { protos } from "google-ads-node";
2
+ export declare const VERSION: "v25";
3
+ export import common = protos.google.ads.googleads.v25.common;
4
+ export import errors = protos.google.ads.googleads.v25.errors;
5
+ export import resources = protos.google.ads.googleads.v25.resources;
6
+ export import services = protos.google.ads.googleads.v25.services;
7
+ export import internalEnums = protos.google.ads.googleads.v25.enums;
8
+ export { enums } from "./autogen/enums.js";
9
+ export { fields, fieldDataTypes } from "./autogen/fields.js";
10
+ export { GoogleAdsServiceClient } from "google-ads-node";
11
+ export type AllServices = Omit<typeof allProtos, typeof VERSION>;
12
+ export type ServiceName = keyof Omit<typeof allProtos, typeof VERSION>;
13
+ export import protobuf = protos.google.protobuf;
14
+ export import longrunning = protos.google.longrunning;
@@ -2,22 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.longrunning = exports.protobuf = exports.GoogleAdsServiceClient = exports.fieldDataTypes = exports.fields = exports.enums = exports.internalEnums = exports.services = exports.resources = exports.errors = exports.common = exports.VERSION = void 0;
4
4
  const google_ads_node_1 = require("google-ads-node");
5
- const version_1 = require("../version");
5
+ const version_js_1 = require("../version.js");
6
6
  // "as vN" is required to avoid type issues later on
7
- exports.VERSION = version_1.googleAdsVersion;
7
+ exports.VERSION = version_js_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.v24.common;
11
- exports.errors = google_ads_node_1.protos.google.ads.googleads.v24.errors;
12
- exports.resources = google_ads_node_1.protos.google.ads.googleads.v24.resources;
13
- exports.services = google_ads_node_1.protos.google.ads.googleads.v24.services;
10
+ exports.common = google_ads_node_1.protos.google.ads.googleads.v25.common;
11
+ exports.errors = google_ads_node_1.protos.google.ads.googleads.v25.errors;
12
+ exports.resources = google_ads_node_1.protos.google.ads.googleads.v25.resources;
13
+ exports.services = google_ads_node_1.protos.google.ads.googleads.v25.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.v24.enums;
16
- var enums_1 = require("./autogen/enums");
17
- Object.defineProperty(exports, "enums", { enumerable: true, get: function () { return enums_1.enums; } });
18
- var fields_1 = require("./autogen/fields");
19
- Object.defineProperty(exports, "fields", { enumerable: true, get: function () { return fields_1.fields; } });
20
- Object.defineProperty(exports, "fieldDataTypes", { enumerable: true, get: function () { return fields_1.fieldDataTypes; } });
15
+ exports.internalEnums = google_ads_node_1.protos.google.ads.googleads.v25.enums;
16
+ var enums_js_1 = require("./autogen/enums.js");
17
+ Object.defineProperty(exports, "enums", { enumerable: true, get: function () { return enums_js_1.enums; } });
18
+ var fields_js_1 = require("./autogen/fields.js");
19
+ Object.defineProperty(exports, "fields", { enumerable: true, get: function () { return fields_js_1.fields; } });
20
+ Object.defineProperty(exports, "fieldDataTypes", { enumerable: true, get: function () { return fields_js_1.fieldDataTypes; } });
21
21
  // Common service used for report/query methods
22
22
  var google_ads_node_2 = require("google-ads-node");
23
23
  Object.defineProperty(exports, "GoogleAdsServiceClient", { enumerable: true, get: function () { return google_ads_node_2.GoogleAdsServiceClient; } });
@@ -1,5 +1,5 @@
1
- import { fields } from "./protos";
2
- import { ConstraintKey, ConstraintOperation, ConstraintValue, ReportOptions, RequestOptions, RequestOptionsWithTotalResults, SortOrder } from "./types";
1
+ import { fields } from "./protos/index.js";
2
+ import { ConstraintKey, ConstraintOperation, ConstraintValue, ReportOptions, RequestOptions, RequestOptionsWithTotalResults, SortOrder } from "./types.js";
3
3
  declare enum QueryKeywords {
4
4
  SELECT = "SELECT",
5
5
  FROM = "FROM",
@@ -17,8 +17,8 @@ exports.buildOrderClauseNew = buildOrderClauseNew;
17
17
  exports.buildOrderClause = buildOrderClause;
18
18
  exports.buildRequestOptions = buildRequestOptions;
19
19
  exports.buildQuery = buildQuery;
20
- const protos_1 = require("./protos");
21
- const types_1 = require("./types");
20
+ const index_js_1 = require("./protos/index.js");
21
+ const types_js_1 = require("./types.js");
22
22
  var QueryKeywords;
23
23
  (function (QueryKeywords) {
24
24
  QueryKeywords["SELECT"] = "SELECT";
@@ -97,7 +97,7 @@ function validateConstraintKeyAndValue(key, op, val) {
97
97
  return { op: "=", val: convertNumericEnumToString(key, val) };
98
98
  }
99
99
  if (typeof val === "string") {
100
- if (types_1.dateConstants.includes(val)) {
100
+ if (types_js_1.dateConstants.includes(val)) {
101
101
  return { op, val };
102
102
  }
103
103
  return { op: "=", val: formatGaqlString(val) };
@@ -119,9 +119,9 @@ function validateConstraintKeyAndValue(key, op, val) {
119
119
  }
120
120
  function convertNumericEnumToString(key, val) {
121
121
  // @ts-expect-error key does not always match an enum field
122
- if (protos_1.fields.enumFields[key] && typeof val === "number") {
122
+ if (index_js_1.fields.enumFields[key] && typeof val === "number") {
123
123
  // @ts-expect-error typescript doesn't like accessing items in a namespace with a string
124
- const enumStringValue = protos_1.enums[protos_1.fields.enumFields[key]][val]; // e.g. enums['CampaignStatus'][2] = "ENABLED"
124
+ const enumStringValue = index_js_1.enums[index_js_1.fields.enumFields[key]][val]; // e.g. enums['CampaignStatus'][2] = "ENABLED"
125
125
  if (enumStringValue) {
126
126
  return `"${enumStringValue}"`;
127
127
  }
@@ -1,9 +1,9 @@
1
- import { ClientOptions } from "./client";
2
- import { AllServices, errors, GoogleAdsServiceClient, ServiceName, services } from "./protos";
3
- import { CustomerOptions, CustomerCredentials, RequestOptions, MutateOperation, MutateOptions } from "./types";
4
- import { Hooks } from "./hooks";
1
+ import { ClientOptions } from "./client.js";
2
+ import { AllServices, errors, GoogleAdsServiceClient, ServiceName, services } from "./protos/index.js";
3
+ import { CustomerOptions, CustomerCredentials, RequestOptions, MutateOperation, MutateOptions } from "./types.js";
4
+ import { Hooks } from "./hooks.js";
5
5
  import TTLCache from "@isaacs/ttlcache";
6
- export declare const FAILURE_KEY = "google.ads.googleads.v24.errors.googleadsfailure-bin";
6
+ export declare const FAILURE_KEY = "google.ads.googleads.v25.errors.googleadsfailure-bin";
7
7
  export interface CallHeaders {
8
8
  "developer-token": string;
9
9
  "login-customer-id"?: string;
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
@@ -6,13 +39,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
39
  exports.Service = exports.serviceCache = exports.FAILURE_KEY = void 0;
7
40
  exports.disposeService = disposeService;
8
41
  const google_gax_1 = require("google-gax");
42
+ const googleAdsNode = __importStar(require("google-ads-node"));
9
43
  const google_auth_library_1 = require("google-auth-library");
10
- const protos_1 = require("./protos");
11
- const utils_1 = require("./utils");
12
- const version_1 = require("./version");
44
+ const index_js_1 = require("./protos/index.js");
45
+ const utils_js_1 = require("./utils.js");
46
+ const version_js_1 = require("./version.js");
13
47
  const ttlcache_1 = __importDefault(require("@isaacs/ttlcache"));
14
48
  // Make sure to update this version number when upgrading
15
- exports.FAILURE_KEY = `google.ads.googleads.${version_1.googleAdsVersion}.errors.googleadsfailure-bin`;
49
+ exports.FAILURE_KEY = `google.ads.googleads.${version_js_1.googleAdsVersion}.errors.googleadsfailure-bin`;
16
50
  // Close connections when services are removed from the cache
17
51
  function disposeService(service) {
18
52
  Promise.resolve()
@@ -64,8 +98,14 @@ class Service {
64
98
  // Used only by gRPC calls
65
99
  getCredentials() {
66
100
  const sslCreds = google_gax_1.grpc.credentials.createSsl();
67
- const authClient = new google_auth_library_1.UserRefreshClient(this.clientOptions.client_id, this.clientOptions.client_secret, this.customerOptions.refresh_token);
68
- const credentials = google_gax_1.grpc.credentials.combineChannelCredentials(sslCreds, google_gax_1.grpc.credentials.createFromGoogleCredential(authClient));
101
+ const authClient = new google_auth_library_1.UserRefreshClient({
102
+ clientId: this.clientOptions.client_id,
103
+ clientSecret: this.clientOptions.client_secret,
104
+ refreshToken: this.customerOptions.refresh_token,
105
+ });
106
+ const credentials = google_gax_1.grpc.credentials.combineChannelCredentials(sslCreds, google_gax_1.grpc.credentials.createFromGoogleCredential({
107
+ getRequestHeaders: async (url) => Object.fromEntries(await authClient.getRequestHeaders(url)),
108
+ }));
69
109
  return credentials;
70
110
  }
71
111
  // Used only by REST calls
@@ -74,7 +114,10 @@ class Service {
74
114
  if (cachedToken) {
75
115
  return cachedToken;
76
116
  }
77
- const oAuth2Client = new google_auth_library_1.OAuth2Client(this.clientOptions.client_id, this.clientOptions.client_secret);
117
+ const oAuth2Client = new google_auth_library_1.OAuth2Client({
118
+ clientId: this.clientOptions.client_id,
119
+ clientSecret: this.clientOptions.client_secret,
120
+ });
78
121
  oAuth2Client.setCredentials({
79
122
  refresh_token: this.customerOptions.refresh_token,
80
123
  });
@@ -93,14 +136,15 @@ class Service {
93
136
  return cachedService;
94
137
  }
95
138
  }
96
- // eslint-disable-next-line @typescript-eslint/no-var-requires
97
- const { [service]: protoService } = require("google-ads-node");
139
+ const protoService = googleAdsNode[service];
98
140
  if (typeof protoService === "undefined") {
99
141
  throw new Error(`Service "${String(service)}" could not be found`);
100
142
  }
101
143
  // Initialising services can take a few ms, so we cache when possible.
102
144
  const client = new protoService({
103
145
  sslCreds: this.getCredentials(),
146
+ universeDomain: "googleapis.com",
147
+ ...this.clientOptions.grpc_channel_options,
104
148
  });
105
149
  if (!options?.skipCache) {
106
150
  exports.serviceCache.set(serviceCacheKey, client);
@@ -108,16 +152,14 @@ class Service {
108
152
  return client;
109
153
  }
110
154
  getGoogleAdsError(error) {
111
- // @ts-expect-error No type exists for GA query error
112
- if (typeof error?.metadata?.internalRepr.get(exports.FAILURE_KEY) === "undefined") {
155
+ const trailer = error?.metadata?.internalRepr?.get?.(exports.FAILURE_KEY);
156
+ if (typeof trailer?.[0] === "undefined") {
113
157
  return error;
114
158
  }
115
- // @ts-expect-error No type exists for GA query error
116
- const [buffer] = error.metadata.internalRepr.get(exports.FAILURE_KEY);
117
- return this.decodeGoogleAdsFailureBuffer(buffer);
159
+ return this.decodeGoogleAdsFailureBuffer(trailer[0]);
118
160
  }
119
161
  decodeGoogleAdsFailureBuffer(buffer) {
120
- const googleAdsFailure = protos_1.errors.GoogleAdsFailure.decode(buffer);
162
+ const googleAdsFailure = index_js_1.errors.GoogleAdsFailure.decode(buffer);
121
163
  return googleAdsFailure;
122
164
  }
123
165
  decodePartialFailureError(response) {
@@ -138,7 +180,7 @@ class Service {
138
180
  }
139
181
  buildSearchRequestAndService(gaql, options) {
140
182
  const service = this.loadService("GoogleAdsServiceClient");
141
- const request = new protos_1.services.SearchGoogleAdsRequest({
183
+ const request = new index_js_1.services.SearchGoogleAdsRequest({
142
184
  customer_id: this.customerOptions.customer_id,
143
185
  query: gaql,
144
186
  ...options,
@@ -147,7 +189,7 @@ class Service {
147
189
  }
148
190
  buildSearchStreamRequestAndService(gaql, options) {
149
191
  const service = this.loadService("GoogleAdsServiceClient");
150
- const request = new protos_1.services.SearchGoogleAdsStreamRequest({
192
+ const request = new index_js_1.services.SearchGoogleAdsStreamRequest({
151
193
  customer_id: this.customerOptions.customer_id,
152
194
  query: gaql,
153
195
  ...options,
@@ -157,7 +199,7 @@ class Service {
157
199
  buildMutationRequestAndService(mutations, options) {
158
200
  const service = this.loadService("GoogleAdsServiceClient");
159
201
  const mutateOperations = mutations.map((mutation) => {
160
- const opKey = (0, utils_1.toSnakeCase)(`${mutation.entity}Operation`);
202
+ const opKey = (0, utils_js_1.toSnakeCase)(`${mutation.entity}Operation`);
161
203
  const operation = {
162
204
  [mutation.operation ?? "create"]: mutation.resource,
163
205
  };
@@ -170,14 +212,14 @@ class Service {
170
212
  }
171
213
  else if (mutation.operation === "update") {
172
214
  // @ts-expect-error Resource operations should have updateMask defined
173
- operation.update_mask = (0, utils_1.getFieldMask)(mutation.resource);
215
+ operation.update_mask = (0, utils_js_1.getFieldMask)(mutation.resource);
174
216
  }
175
- const mutateOperation = new protos_1.services.MutateOperation({
217
+ const mutateOperation = new index_js_1.services.MutateOperation({
176
218
  [opKey]: operation,
177
219
  });
178
220
  return mutateOperation;
179
221
  });
180
- const request = new protos_1.services.MutateGoogleAdsRequest({
222
+ const request = new index_js_1.services.MutateGoogleAdsRequest({
181
223
  customer_id: this.customerOptions.customer_id,
182
224
  mutate_operations: mutateOperations,
183
225
  ...options,
@@ -199,7 +241,7 @@ class Service {
199
241
  }
200
242
  else if (type === "update") {
201
243
  // @ts-expect-error Field required for updates
202
- op.update_mask = (0, utils_1.getFieldMask)(
244
+ op.update_mask = (0, utils_js_1.getFieldMask)(
203
245
  // @ts-expect-error Message types have a toObject method
204
246
  message.toObject(e, {
205
247
  defaults: false,
@@ -1,4 +1,4 @@
1
- import { services, fields } from "./protos";
1
+ import { services, fields } from "./protos/index.js";
2
2
  export interface CustomerOptions {
3
3
  customer_id: string;
4
4
  refresh_token: string;
@@ -1,4 +1,4 @@
1
- import { protobuf } from "./protos";
1
+ import { protobuf } from "./protos/index.js";
2
2
  /**
3
3
  * @param micros Money value in micros format
4
4
  * @description Converts a micro amount to a normalised value
@@ -12,7 +12,7 @@ exports.toSnakeCase = toSnakeCase;
12
12
  exports.recursiveFieldMaskSearch = recursiveFieldMaskSearch;
13
13
  exports.getFieldMask = getFieldMask;
14
14
  const long_1 = __importDefault(require("long"));
15
- const protos_1 = require("./protos");
15
+ const index_js_1 = require("./protos/index.js");
16
16
  /**
17
17
  * @param micros Money value in micros format
18
18
  * @description Converts a micro amount to a normalised value
@@ -115,7 +115,7 @@ ancestors = new Set()) {
115
115
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
116
116
  function getFieldMask(data) {
117
117
  const paths = recursiveFieldMaskSearch(data);
118
- return new protos_1.protobuf.FieldMask({
118
+ return new index_js_1.protobuf.FieldMask({
119
119
  paths,
120
120
  });
121
121
  }
@@ -0,0 +1 @@
1
+ export declare const googleAdsVersion = "v25";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.googleAdsVersion = void 0;
4
- exports.googleAdsVersion = "v24";
4
+ exports.googleAdsVersion = "v25";
@@ -0,0 +1,19 @@
1
+ import type { grpc } from "google-gax";
2
+ import { Customer } from "./customer.js";
3
+ import { CustomerOptions } from "./types.js";
4
+ import { Hooks } from "./hooks.js";
5
+ import { services } from "./protos/index.js";
6
+ export interface ClientOptions {
7
+ client_id: string;
8
+ client_secret: string;
9
+ developer_token: string;
10
+ disable_parsing?: boolean;
11
+ max_reporting_rows?: number;
12
+ grpc_channel_options?: grpc.ChannelOptions;
13
+ }
14
+ export declare class Client {
15
+ private readonly options;
16
+ constructor(options: ClientOptions);
17
+ Customer(customerOptions: CustomerOptions, hooks?: Hooks): Customer;
18
+ listAccessibleCustomers(refreshToken: string): Promise<services.ListAccessibleCustomersResponse>;
19
+ }
@@ -0,0 +1,40 @@
1
+ import { Customer } from "./customer.js";
2
+ import { Service } from "./service.js";
3
+ export class Client {
4
+ options;
5
+ constructor(options) {
6
+ this.options = options;
7
+ }
8
+ Customer(customerOptions, hooks) {
9
+ const cus = new Customer(this.options, customerOptions, hooks);
10
+ return cus;
11
+ }
12
+ async listAccessibleCustomers(refreshToken) {
13
+ const service = new Service(this.options, {
14
+ customer_id: "",
15
+ refresh_token: refreshToken,
16
+ });
17
+ // @ts-expect-error Protected usage is fine here
18
+ const customerService = service.loadService("CustomerServiceClient", { skipCache: true });
19
+ try {
20
+ // @ts-expect-error Type definition is incorrect, response is an array
21
+ const [response] = await customerService.listAccessibleCustomers({}, {
22
+ // @ts-expect-error Field not included in type definitions
23
+ otherArgs: {
24
+ // @ts-expect-error Protected usage is fine here
25
+ headers: service.callHeaders,
26
+ },
27
+ });
28
+ return response;
29
+ }
30
+ catch (err) {
31
+ console.log(err);
32
+ // @ts-expect-error Protected usage is fine here
33
+ throw service.getGoogleAdsError(err);
34
+ }
35
+ finally {
36
+ // @ts-expect-error close() exists on the gax client but not on the proto type
37
+ await customerService.close().catch(() => null);
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,71 @@
1
+ import { CancellableStream } from "google-gax";
2
+ import { ClientOptions } from "./client.js";
3
+ import { Hooks } from "./hooks.js";
4
+ import { services } from "./protos/index.js";
5
+ import ServiceFactory from "./protos/autogen/serviceFactory.js";
6
+ import { CustomerOptions, MutateOperation, MutateOptions, ReportOptions, RequestOptions } from "./types.js";
7
+ export declare class Customer extends ServiceFactory {
8
+ constructor(clientOptions: ClientOptions, customerOptions: CustomerOptions, hooks?: Hooks);
9
+ /**
10
+ @description Single query using a raw GAQL string.
11
+ @hooks onQueryStart, onQueryError, onQueryEnd
12
+ */
13
+ query<T = services.IGoogleAdsRow[]>(gaqlQuery: string, requestOptions?: Readonly<RequestOptions>): Promise<T>;
14
+ /**
15
+ @description Stream query using a raw GAQL string. If a generic type is provided, it must be the type of a single row.
16
+ If a summary row is requested then this will be the last emitted row of the stream.
17
+ @hooks onStreamStart, onStreamError
18
+ @example
19
+ const stream = queryStream<T>(gaqlQuery)
20
+ for await (const row of stream) { ... }
21
+ */
22
+ queryStream<T = services.IGoogleAdsRow>(gaqlQuery: string, requestOptions?: Readonly<RequestOptions>): AsyncGenerator<T>;
23
+ /**
24
+ @description Single query using ReportOptions.
25
+ If a summary row is requested then this will be the first row of the results.
26
+ @hooks onQueryStart, onQueryError, onQueryEnd
27
+ */
28
+ report<T = services.IGoogleAdsRow[]>(options: Readonly<ReportOptions>): Promise<T>;
29
+ /**
30
+ @description Get the total row count of a report.
31
+ @hooks none
32
+ */
33
+ reportCount(options: Readonly<ReportOptions>): Promise<number | undefined>;
34
+ /**
35
+ @description Stream query using ReportOptions. If a generic type is provided, it must be the type of a single row.
36
+ If a summary row is requested then this will be the last emitted row of the stream.
37
+ @hooks onStreamStart, onStreamError
38
+ @example
39
+ const stream = reportStream<T>(reportOptions)
40
+ for await (const row of stream) { ... }
41
+ */
42
+ reportStream<T = services.IGoogleAdsRow>(reportOptions: Readonly<ReportOptions>): AsyncGenerator<T>;
43
+ /**
44
+ @description Retreive the raw stream using ReportOptions.
45
+ @hooks onStreamStart
46
+ @example
47
+ const stream = reportStreamRaw(reportOptions)
48
+ stream.on('data', (chunk) => { ... }) // a chunk contains up to 10,000 un-parsed rows
49
+ stream.on('error', (error) => { ... })
50
+ stream.on('end', () => { ... })
51
+ */
52
+ reportStreamRaw(reportOptions: Readonly<ReportOptions>): Promise<CancellableStream | void>;
53
+ private search;
54
+ private paginatedSearch;
55
+ private useStreamToImitateRegularSearch;
56
+ private querier;
57
+ private streamer;
58
+ private handleStreamError;
59
+ /**
60
+ * @description Creates, updates, or removes resources. This method supports atomic transactions
61
+ * with multiple types of resources. For example, you can atomically create a campaign and a
62
+ * campaign budget, or perform up to thousands of mutates atomically.
63
+ * @hooks onMutationStart, onMutationError, onMutationEnd
64
+ */
65
+ mutateResources<T>(mutations: MutateOperation<T>[], mutateOptions?: MutateOptions): Promise<services.MutateGoogleAdsResponse>;
66
+ private get googleAdsFields();
67
+ private prepareGoogleAdsServicePostRequestArgs;
68
+ private decamelizeKeysIfNeeded;
69
+ private gaqlQueryStringIncludesLimit;
70
+ private generateTooManyRowsError;
71
+ }