google-ads-api 24.1.0 → 25.1.0-beta.1
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.
- package/README.md +9 -1
- package/build/{src → cjs}/client.d.ts +6 -4
- package/build/{src → cjs}/client.js +4 -4
- package/build/{src → cjs}/customer.d.ts +5 -5
- package/build/{src → cjs}/customer.js +24 -20
- package/build/{src → cjs}/hooks.d.ts +2 -2
- package/build/cjs/index.d.ts +9 -0
- package/build/{src → cjs}/index.js +22 -20
- package/build/{src → cjs}/parser.d.ts +2 -2
- package/build/{src → cjs}/parser.js +5 -5
- package/build/{src → cjs}/parserRest.js +7 -7
- package/build/{src → cjs}/protos/autogen/enums.d.ts +932 -433
- package/build/{src → cjs}/protos/autogen/enums.js +949 -430
- package/build/cjs/protos/autogen/fields.d.ts +1191 -0
- package/build/cjs/protos/autogen/fields.js +681 -0
- package/build/{src → cjs}/protos/autogen/resourceNames.d.ts +74 -15
- package/build/{src → cjs}/protos/autogen/resourceNames.js +90 -19
- package/build/{src → cjs}/protos/autogen/serviceFactory.d.ts +206 -215
- package/build/{src → cjs}/protos/autogen/serviceFactory.js +321 -392
- package/build/cjs/protos/index.d.ts +14 -0
- package/build/{src → cjs}/protos/index.js +12 -12
- package/build/{src → cjs}/query.d.ts +2 -2
- package/build/{src → cjs}/query.js +5 -5
- package/build/{src → cjs}/service.d.ts +5 -5
- package/build/cjs/service.js +263 -0
- package/build/{src → cjs}/types.d.ts +1 -1
- package/build/{src → cjs}/utils.d.ts +1 -1
- package/build/{src → cjs}/utils.js +2 -2
- package/build/cjs/version.d.ts +1 -0
- package/build/{src → cjs}/version.js +1 -1
- package/build/esm/client.d.ts +19 -0
- package/build/esm/client.js +40 -0
- package/build/esm/customer.d.ts +71 -0
- package/build/esm/customer.js +502 -0
- package/build/esm/hooks.d.ts +160 -0
- package/build/esm/hooks.js +1 -0
- package/build/esm/index.d.ts +9 -0
- package/build/esm/index.js +10 -0
- package/build/esm/package.json +1 -0
- package/build/esm/parser.d.ts +21 -0
- package/build/esm/parser.js +113 -0
- package/build/esm/parserRest.d.ts +1 -0
- package/build/esm/parserRest.js +112 -0
- package/build/esm/protos/autogen/enums.d.ts +6002 -0
- package/build/esm/protos/autogen/enums.js +6401 -0
- package/build/esm/protos/autogen/fields.d.ts +1191 -0
- package/build/esm/protos/autogen/fields.js +678 -0
- package/build/esm/protos/autogen/resourceNames.d.ts +1668 -0
- package/build/esm/protos/autogen/resourceNames.js +1859 -0
- package/build/esm/protos/autogen/serviceFactory.d.ts +1825 -0
- package/build/esm/protos/autogen/serviceFactory.js +18795 -0
- package/build/esm/protos/index.d.ts +14 -0
- package/build/esm/protos/index.js +19 -0
- package/build/esm/query.d.ts +62 -0
- package/build/esm/query.js +304 -0
- package/build/esm/service.d.ts +47 -0
- package/build/{src → esm}/service.js +42 -41
- package/build/esm/types.d.ts +75 -0
- package/build/esm/types.js +14 -0
- package/build/esm/utils.d.ts +49 -0
- package/build/esm/utils.js +108 -0
- package/build/esm/version.d.ts +1 -0
- package/build/esm/version.js +1 -0
- package/package.json +54 -13
- package/build/src/index.d.ts +0 -8
- package/build/src/protos/autogen/fields.d.ts +0 -1122
- package/build/src/protos/autogen/fields.js +0 -644
- package/build/src/protos/index.d.ts +0 -14
- package/build/src/testUtils.d.ts +0 -107
- package/build/src/testUtils.js +0 -333
- package/build/src/version.d.ts +0 -1
- /package/build/{src → cjs}/hooks.js +0 -0
- /package/build/{src → cjs}/parserRest.d.ts +0 -0
- /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
|
|
5
|
+
const version_js_1 = require("../version.js");
|
|
6
6
|
// "as vN" is required to avoid type issues later on
|
|
7
|
-
exports.VERSION =
|
|
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.
|
|
11
|
-
exports.errors = google_ads_node_1.protos.google.ads.googleads.
|
|
12
|
-
exports.resources = google_ads_node_1.protos.google.ads.googleads.
|
|
13
|
-
exports.services = google_ads_node_1.protos.google.ads.googleads.
|
|
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.
|
|
16
|
-
var
|
|
17
|
-
Object.defineProperty(exports, "enums", { enumerable: true, get: function () { return
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "fields", { enumerable: true, get: function () { return
|
|
20
|
-
Object.defineProperty(exports, "fieldDataTypes", { enumerable: true, get: function () { return
|
|
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
|
|
21
|
-
const
|
|
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 (
|
|
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 (
|
|
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 =
|
|
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.
|
|
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;
|
|
@@ -0,0 +1,263 @@
|
|
|
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
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.Service = exports.serviceCache = exports.FAILURE_KEY = void 0;
|
|
40
|
+
exports.disposeService = disposeService;
|
|
41
|
+
const google_gax_1 = require("google-gax");
|
|
42
|
+
const googleAdsNode = __importStar(require("google-ads-node"));
|
|
43
|
+
const google_auth_library_1 = require("google-auth-library");
|
|
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");
|
|
47
|
+
const ttlcache_1 = __importDefault(require("@isaacs/ttlcache"));
|
|
48
|
+
// Make sure to update this version number when upgrading
|
|
49
|
+
exports.FAILURE_KEY = `google.ads.googleads.${version_js_1.googleAdsVersion}.errors.googleadsfailure-bin`;
|
|
50
|
+
// Close connections when services are removed from the cache
|
|
51
|
+
function disposeService(service) {
|
|
52
|
+
Promise.resolve()
|
|
53
|
+
.then(() => service.close())
|
|
54
|
+
.catch(() => null);
|
|
55
|
+
}
|
|
56
|
+
// A global service cache to avoid re-initialising services
|
|
57
|
+
exports.serviceCache = new ttlcache_1.default({
|
|
58
|
+
max: 1_000,
|
|
59
|
+
ttl: 10 * 60 * 1000, // 10 minutes
|
|
60
|
+
checkAgeOnGet: true,
|
|
61
|
+
dispose: disposeService,
|
|
62
|
+
});
|
|
63
|
+
// A global access token cache used by REST calls. Issued tokens expire after 1 hour, so we cache them for 50 minutes.
|
|
64
|
+
const accessTokenCache = new ttlcache_1.default({
|
|
65
|
+
max: 100_000,
|
|
66
|
+
ttl: 50 * 60 * 1000, // 50 minutes
|
|
67
|
+
});
|
|
68
|
+
class Service {
|
|
69
|
+
clientOptions;
|
|
70
|
+
customerOptions;
|
|
71
|
+
hooks;
|
|
72
|
+
constructor(clientOptions, customerOptions, hooks) {
|
|
73
|
+
this.clientOptions = clientOptions;
|
|
74
|
+
this.customerOptions = customerOptions;
|
|
75
|
+
this.hooks = hooks ?? {};
|
|
76
|
+
// @ts-expect-error All fields don't need to be set here
|
|
77
|
+
this.serviceCache = {};
|
|
78
|
+
}
|
|
79
|
+
get credentials() {
|
|
80
|
+
return {
|
|
81
|
+
customer_id: this.customerOptions.customer_id,
|
|
82
|
+
login_customer_id: this.customerOptions.login_customer_id,
|
|
83
|
+
linked_customer_id: this.customerOptions.linked_customer_id,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
get callHeaders() {
|
|
87
|
+
const headers = {
|
|
88
|
+
"developer-token": this.clientOptions.developer_token,
|
|
89
|
+
};
|
|
90
|
+
if (this.customerOptions.login_customer_id) {
|
|
91
|
+
headers["login-customer-id"] = this.customerOptions.login_customer_id;
|
|
92
|
+
}
|
|
93
|
+
if (this.customerOptions.linked_customer_id) {
|
|
94
|
+
headers["linked-customer-id"] = this.customerOptions.linked_customer_id;
|
|
95
|
+
}
|
|
96
|
+
return headers;
|
|
97
|
+
}
|
|
98
|
+
// Used only by gRPC calls
|
|
99
|
+
getCredentials() {
|
|
100
|
+
const sslCreds = google_gax_1.grpc.credentials.createSsl();
|
|
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
|
+
}));
|
|
109
|
+
return credentials;
|
|
110
|
+
}
|
|
111
|
+
// Used only by REST calls
|
|
112
|
+
async getAccessToken() {
|
|
113
|
+
const cachedToken = accessTokenCache.get(this.customerOptions.refresh_token);
|
|
114
|
+
if (cachedToken) {
|
|
115
|
+
return cachedToken;
|
|
116
|
+
}
|
|
117
|
+
const oAuth2Client = new google_auth_library_1.OAuth2Client({
|
|
118
|
+
clientId: this.clientOptions.client_id,
|
|
119
|
+
clientSecret: this.clientOptions.client_secret,
|
|
120
|
+
});
|
|
121
|
+
oAuth2Client.setCredentials({
|
|
122
|
+
refresh_token: this.customerOptions.refresh_token,
|
|
123
|
+
});
|
|
124
|
+
const { token } = await oAuth2Client.getAccessToken();
|
|
125
|
+
if (typeof token !== "string") {
|
|
126
|
+
throw new Error("Failed to retrieve access token");
|
|
127
|
+
}
|
|
128
|
+
accessTokenCache.set(this.customerOptions.refresh_token, token);
|
|
129
|
+
return token;
|
|
130
|
+
}
|
|
131
|
+
loadService(service, options) {
|
|
132
|
+
const serviceCacheKey = `${service}_${this.clientOptions.client_id}_${this.customerOptions.refresh_token}_${JSON.stringify(this.clientOptions.grpc_channel_options ?? null)}`;
|
|
133
|
+
if (!options?.skipCache) {
|
|
134
|
+
const cachedService = exports.serviceCache.get(serviceCacheKey);
|
|
135
|
+
if (cachedService) {
|
|
136
|
+
return cachedService;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const protoService = googleAdsNode[service];
|
|
140
|
+
if (typeof protoService === "undefined") {
|
|
141
|
+
throw new Error(`Service "${String(service)}" could not be found`);
|
|
142
|
+
}
|
|
143
|
+
// Initialising services can take a few ms, so we cache when possible.
|
|
144
|
+
const client = new protoService({
|
|
145
|
+
...this.clientOptions.grpc_channel_options,
|
|
146
|
+
sslCreds: this.getCredentials(),
|
|
147
|
+
universeDomain: "googleapis.com",
|
|
148
|
+
});
|
|
149
|
+
if (!options?.skipCache) {
|
|
150
|
+
exports.serviceCache.set(serviceCacheKey, client);
|
|
151
|
+
}
|
|
152
|
+
return client;
|
|
153
|
+
}
|
|
154
|
+
getGoogleAdsError(error) {
|
|
155
|
+
const trailer = error?.metadata?.internalRepr?.get?.(exports.FAILURE_KEY);
|
|
156
|
+
if (typeof trailer?.[0] === "undefined") {
|
|
157
|
+
return error;
|
|
158
|
+
}
|
|
159
|
+
return this.decodeGoogleAdsFailureBuffer(trailer[0]);
|
|
160
|
+
}
|
|
161
|
+
decodeGoogleAdsFailureBuffer(buffer) {
|
|
162
|
+
const googleAdsFailure = index_js_1.errors.GoogleAdsFailure.decode(buffer);
|
|
163
|
+
return googleAdsFailure;
|
|
164
|
+
}
|
|
165
|
+
decodePartialFailureError(response) {
|
|
166
|
+
if (typeof response?.partial_failure_error === "undefined" ||
|
|
167
|
+
!response?.partial_failure_error) {
|
|
168
|
+
return response;
|
|
169
|
+
}
|
|
170
|
+
const { details } = response.partial_failure_error;
|
|
171
|
+
const buffer = details?.find((d) => d.type_url.includes("errors.GoogleAdsFailure"))?.value;
|
|
172
|
+
if (typeof buffer === "undefined") {
|
|
173
|
+
return response;
|
|
174
|
+
}
|
|
175
|
+
// Update the partial failure field with the decoded error details
|
|
176
|
+
return {
|
|
177
|
+
...response,
|
|
178
|
+
partial_failure_error: this.decodeGoogleAdsFailureBuffer(buffer),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
buildSearchRequestAndService(gaql, options) {
|
|
182
|
+
const service = this.loadService("GoogleAdsServiceClient");
|
|
183
|
+
const request = new index_js_1.services.SearchGoogleAdsRequest({
|
|
184
|
+
customer_id: this.customerOptions.customer_id,
|
|
185
|
+
query: gaql,
|
|
186
|
+
...options,
|
|
187
|
+
});
|
|
188
|
+
return { service, request };
|
|
189
|
+
}
|
|
190
|
+
buildSearchStreamRequestAndService(gaql, options) {
|
|
191
|
+
const service = this.loadService("GoogleAdsServiceClient");
|
|
192
|
+
const request = new index_js_1.services.SearchGoogleAdsStreamRequest({
|
|
193
|
+
customer_id: this.customerOptions.customer_id,
|
|
194
|
+
query: gaql,
|
|
195
|
+
...options,
|
|
196
|
+
});
|
|
197
|
+
return { service, request };
|
|
198
|
+
}
|
|
199
|
+
buildMutationRequestAndService(mutations, options) {
|
|
200
|
+
const service = this.loadService("GoogleAdsServiceClient");
|
|
201
|
+
const mutateOperations = mutations.map((mutation) => {
|
|
202
|
+
const opKey = (0, utils_js_1.toSnakeCase)(`${mutation.entity}Operation`);
|
|
203
|
+
const operation = {
|
|
204
|
+
[mutation.operation ?? "create"]: mutation.resource,
|
|
205
|
+
};
|
|
206
|
+
if (mutation.operation === "create" &&
|
|
207
|
+
//@ts-ignore
|
|
208
|
+
mutation?.exempt_policy_violation_keys?.length) {
|
|
209
|
+
//@ts-ignore
|
|
210
|
+
operation.exempt_policy_violation_keys =
|
|
211
|
+
mutation.exempt_policy_violation_keys;
|
|
212
|
+
}
|
|
213
|
+
else if (mutation.operation === "update") {
|
|
214
|
+
// @ts-expect-error Resource operations should have updateMask defined
|
|
215
|
+
operation.update_mask = (0, utils_js_1.getFieldMask)(mutation.resource);
|
|
216
|
+
}
|
|
217
|
+
const mutateOperation = new index_js_1.services.MutateOperation({
|
|
218
|
+
[opKey]: operation,
|
|
219
|
+
});
|
|
220
|
+
return mutateOperation;
|
|
221
|
+
});
|
|
222
|
+
const request = new index_js_1.services.MutateGoogleAdsRequest({
|
|
223
|
+
customer_id: this.customerOptions.customer_id,
|
|
224
|
+
mutate_operations: mutateOperations,
|
|
225
|
+
...options,
|
|
226
|
+
});
|
|
227
|
+
return { service, request };
|
|
228
|
+
}
|
|
229
|
+
buildOperations(type, entities, message) {
|
|
230
|
+
const ops = entities.map((e) => {
|
|
231
|
+
const op = {
|
|
232
|
+
[type]: e,
|
|
233
|
+
operation: type,
|
|
234
|
+
};
|
|
235
|
+
//@ts-ignore
|
|
236
|
+
if (type === "create" && e?.exempt_policy_violation_keys?.length) {
|
|
237
|
+
// @ts-expect-error Field required for policy violation exemptions
|
|
238
|
+
op.exempt_policy_violation_keys = e.exempt_policy_violation_keys;
|
|
239
|
+
//@ts-ignore
|
|
240
|
+
delete e.exempt_policy_violation_keys;
|
|
241
|
+
}
|
|
242
|
+
else if (type === "update") {
|
|
243
|
+
// @ts-expect-error Field required for updates
|
|
244
|
+
op.update_mask = (0, utils_js_1.getFieldMask)(
|
|
245
|
+
// @ts-expect-error Message types have a toObject method
|
|
246
|
+
message.toObject(e, {
|
|
247
|
+
defaults: false,
|
|
248
|
+
}));
|
|
249
|
+
}
|
|
250
|
+
return op;
|
|
251
|
+
});
|
|
252
|
+
return ops;
|
|
253
|
+
}
|
|
254
|
+
buildRequest(operations, options) {
|
|
255
|
+
const request = {
|
|
256
|
+
customer_id: this.customerOptions.customer_id,
|
|
257
|
+
operations,
|
|
258
|
+
...options,
|
|
259
|
+
};
|
|
260
|
+
return request;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.Service = Service;
|
|
@@ -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
|
|
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
|
|
118
|
+
return new index_js_1.protobuf.FieldMask({
|
|
119
119
|
paths,
|
|
120
120
|
});
|
|
121
121
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const 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
|
+
}
|