google-ads-api 19.0.4-rest-beta → 20.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.
- package/README.md +2 -2
- package/build/src/client.d.ts +0 -1
- package/build/src/client.js +0 -1
- package/build/src/customer.d.ts +0 -6
- package/build/src/customer.js +73 -203
- package/build/src/index.js +17 -7
- package/build/src/protos/autogen/enums.d.ts +1162 -978
- package/build/src/protos/autogen/enums.js +1166 -967
- package/build/src/protos/autogen/fields.d.ts +107 -101
- package/build/src/protos/autogen/fields.js +8 -3
- package/build/src/protos/autogen/serviceFactory.d.ts +180 -168
- package/build/src/protos/autogen/serviceFactory.js +358 -169
- package/build/src/protos/index.d.ts +7 -7
- package/build/src/protos/index.js +6 -7
- package/build/src/query.js +1 -1
- package/build/src/service.d.ts +1 -2
- package/build/src/service.js +14 -35
- package/build/src/testUtils.d.ts +0 -38
- package/build/src/testUtils.js +22 -83
- package/build/src/utils.d.ts +5 -0
- package/build/src/utils.js +15 -0
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/package.json +12 -18
- package/build/src/parserRest.d.ts +0 -4
- package/build/src/parserRest.js +0 -88
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import allProtos, { protos } from "google-ads-node";
|
|
2
|
-
export declare const VERSION: "
|
|
3
|
-
export import common = protos.google.ads.googleads.
|
|
4
|
-
export import errors = protos.google.ads.googleads.
|
|
5
|
-
export import resources = protos.google.ads.googleads.
|
|
6
|
-
export import services = protos.google.ads.googleads.
|
|
7
|
-
export import internalEnums = protos.google.ads.googleads.
|
|
2
|
+
export declare const VERSION: "v20";
|
|
3
|
+
export import common = protos.google.ads.googleads.v20.common;
|
|
4
|
+
export import errors = protos.google.ads.googleads.v20.errors;
|
|
5
|
+
export import resources = protos.google.ads.googleads.v20.resources;
|
|
6
|
+
export import services = protos.google.ads.googleads.v20.services;
|
|
7
|
+
export import internalEnums = protos.google.ads.googleads.v20.enums;
|
|
8
8
|
export { enums } from "./autogen/enums";
|
|
9
|
-
export { fields
|
|
9
|
+
export { fields } from "./autogen/fields";
|
|
10
10
|
export { GoogleAdsServiceClient } from "google-ads-node";
|
|
11
11
|
export type AllServices = Omit<typeof allProtos, typeof VERSION>;
|
|
12
12
|
export type ServiceName = keyof Omit<typeof allProtos, typeof VERSION>;
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.longrunning = exports.protobuf = exports.GoogleAdsServiceClient = exports.
|
|
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
4
|
const google_ads_node_1 = require("google-ads-node");
|
|
5
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.
|
|
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.v20.common;
|
|
11
|
+
exports.errors = google_ads_node_1.protos.google.ads.googleads.v20.errors;
|
|
12
|
+
exports.resources = google_ads_node_1.protos.google.ads.googleads.v20.resources;
|
|
13
|
+
exports.services = google_ads_node_1.protos.google.ads.googleads.v20.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.
|
|
15
|
+
exports.internalEnums = google_ads_node_1.protos.google.ads.googleads.v20.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");
|
|
19
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; } });
|
|
21
20
|
// Common service used for report/query methods
|
|
22
21
|
var google_ads_node_2 = require("google-ads-node");
|
|
23
22
|
Object.defineProperty(exports, "GoogleAdsServiceClient", { enumerable: true, get: function () { return google_ads_node_2.GoogleAdsServiceClient; } });
|
package/build/src/query.js
CHANGED
|
@@ -51,7 +51,7 @@ exports.QueryError = {
|
|
|
51
51
|
UNDEFINED_ENTITY: "The entity of the query must be defined.",
|
|
52
52
|
};
|
|
53
53
|
function buildSelectClause(attributes, metrics, segments) {
|
|
54
|
-
if (!attributes
|
|
54
|
+
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)) {
|
|
55
55
|
throw new Error(exports.QueryError.MISSING_FIELDS);
|
|
56
56
|
}
|
|
57
57
|
const selections = [
|
package/build/src/service.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ClientOptions } from "./client";
|
|
|
2
2
|
import { AllServices, errors, GoogleAdsServiceClient, ServiceName, services } from "./protos";
|
|
3
3
|
import { CustomerOptions, CustomerCredentials, RequestOptions, MutateOperation, MutateOptions } from "./types";
|
|
4
4
|
import { Hooks } from "./hooks";
|
|
5
|
-
export declare const FAILURE_KEY = "google.ads.googleads.
|
|
5
|
+
export declare const FAILURE_KEY = "google.ads.googleads.v20.errors.googleadsfailure-bin";
|
|
6
6
|
export interface CallHeaders {
|
|
7
7
|
"developer-token": string;
|
|
8
8
|
"login-customer-id"?: string;
|
|
@@ -16,7 +16,6 @@ export declare class Service {
|
|
|
16
16
|
get credentials(): CustomerCredentials;
|
|
17
17
|
protected get callHeaders(): CallHeaders;
|
|
18
18
|
private getCredentials;
|
|
19
|
-
getAccessToken(): Promise<string>;
|
|
20
19
|
protected loadService<T = AllServices>(service: ServiceName): T;
|
|
21
20
|
protected getGoogleAdsError(error: Error): errors.GoogleAdsFailure | Error;
|
|
22
21
|
private decodeGoogleAdsFailureBuffer;
|
package/build/src/service.js
CHANGED
|
@@ -14,26 +14,18 @@ const ttlcache_1 = __importDefault(require("@isaacs/ttlcache"));
|
|
|
14
14
|
exports.FAILURE_KEY = `google.ads.googleads.${version_1.googleAdsVersion}.errors.googleadsfailure-bin`;
|
|
15
15
|
// A global service cache to avoid re-initialising services
|
|
16
16
|
const serviceCache = new ttlcache_1.default({
|
|
17
|
-
max:
|
|
17
|
+
max: 1000,
|
|
18
18
|
ttl: 10 * 60 * 1000, // 10 minutes
|
|
19
19
|
dispose: async (service) => {
|
|
20
20
|
// Close connections when services are removed from the cache
|
|
21
21
|
await service.close();
|
|
22
22
|
},
|
|
23
23
|
});
|
|
24
|
-
// A global access token cache used by REST calls. Issued tokens expire after 1 hour, so we cache them for 50 minutes.
|
|
25
|
-
const accessTokenCache = new ttlcache_1.default({
|
|
26
|
-
max: 100_000,
|
|
27
|
-
ttl: 50 * 60 * 1000, // 50 minutes
|
|
28
|
-
});
|
|
29
24
|
class Service {
|
|
30
|
-
clientOptions;
|
|
31
|
-
customerOptions;
|
|
32
|
-
hooks;
|
|
33
25
|
constructor(clientOptions, customerOptions, hooks) {
|
|
34
26
|
this.clientOptions = clientOptions;
|
|
35
27
|
this.customerOptions = customerOptions;
|
|
36
|
-
this.hooks = hooks
|
|
28
|
+
this.hooks = hooks !== null && hooks !== void 0 ? hooks : {};
|
|
37
29
|
// @ts-expect-error All fields don't need to be set here
|
|
38
30
|
this.serviceCache = {};
|
|
39
31
|
}
|
|
@@ -56,30 +48,12 @@ class Service {
|
|
|
56
48
|
}
|
|
57
49
|
return headers;
|
|
58
50
|
}
|
|
59
|
-
// Used only by gRPC calls
|
|
60
51
|
getCredentials() {
|
|
61
52
|
const sslCreds = google_gax_1.grpc.credentials.createSsl();
|
|
62
53
|
const authClient = new google_auth_library_1.UserRefreshClient(this.clientOptions.client_id, this.clientOptions.client_secret, this.customerOptions.refresh_token);
|
|
63
54
|
const credentials = google_gax_1.grpc.credentials.combineChannelCredentials(sslCreds, google_gax_1.grpc.credentials.createFromGoogleCredential(authClient));
|
|
64
55
|
return credentials;
|
|
65
56
|
}
|
|
66
|
-
// Used only by REST calls
|
|
67
|
-
async getAccessToken() {
|
|
68
|
-
const cachedToken = accessTokenCache.get(this.customerOptions.refresh_token);
|
|
69
|
-
if (cachedToken) {
|
|
70
|
-
return cachedToken;
|
|
71
|
-
}
|
|
72
|
-
const oAuth2Client = new google_auth_library_1.OAuth2Client(this.clientOptions.client_id, this.clientOptions.client_secret);
|
|
73
|
-
oAuth2Client.setCredentials({
|
|
74
|
-
refresh_token: this.customerOptions.refresh_token,
|
|
75
|
-
});
|
|
76
|
-
const { token } = await oAuth2Client.getAccessToken();
|
|
77
|
-
if (typeof token !== "string") {
|
|
78
|
-
throw new Error("Failed to retrieve access token");
|
|
79
|
-
}
|
|
80
|
-
accessTokenCache.set(this.customerOptions.refresh_token, token);
|
|
81
|
-
return token;
|
|
82
|
-
}
|
|
83
57
|
loadService(service) {
|
|
84
58
|
const serviceCacheKey = `${service}_${this.customerOptions.refresh_token}`;
|
|
85
59
|
if (serviceCache.has(serviceCacheKey)) {
|
|
@@ -98,8 +72,9 @@ class Service {
|
|
|
98
72
|
return client;
|
|
99
73
|
}
|
|
100
74
|
getGoogleAdsError(error) {
|
|
75
|
+
var _a;
|
|
101
76
|
// @ts-expect-error No type exists for GA query error
|
|
102
|
-
if (typeof error
|
|
77
|
+
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") {
|
|
103
78
|
return error;
|
|
104
79
|
}
|
|
105
80
|
// @ts-expect-error No type exists for GA query error
|
|
@@ -111,12 +86,13 @@ class Service {
|
|
|
111
86
|
return googleAdsFailure;
|
|
112
87
|
}
|
|
113
88
|
decodePartialFailureError(response) {
|
|
114
|
-
|
|
115
|
-
|
|
89
|
+
var _a;
|
|
90
|
+
if (typeof (response === null || response === void 0 ? void 0 : response.partial_failure_error) === "undefined" ||
|
|
91
|
+
!(response === null || response === void 0 ? void 0 : response.partial_failure_error)) {
|
|
116
92
|
return response;
|
|
117
93
|
}
|
|
118
94
|
const { details } = response.partial_failure_error;
|
|
119
|
-
const buffer = details
|
|
95
|
+
const buffer = (_a = details === null || details === void 0 ? void 0 : details.find((d) => d.type_url.includes("errors.GoogleAdsFailure"))) === null || _a === void 0 ? void 0 : _a.value;
|
|
120
96
|
if (typeof buffer === "undefined") {
|
|
121
97
|
return response;
|
|
122
98
|
}
|
|
@@ -147,13 +123,15 @@ class Service {
|
|
|
147
123
|
buildMutationRequestAndService(mutations, options) {
|
|
148
124
|
const service = this.loadService("GoogleAdsServiceClient");
|
|
149
125
|
const mutateOperations = mutations.map((mutation) => {
|
|
126
|
+
var _a, _b;
|
|
150
127
|
const opKey = (0, utils_1.toSnakeCase)(`${mutation.entity}Operation`);
|
|
151
128
|
const operation = {
|
|
152
|
-
[mutation.operation
|
|
129
|
+
[(_a = mutation.operation) !== null && _a !== void 0 ? _a : "create"]: mutation.resource,
|
|
153
130
|
};
|
|
154
131
|
if (mutation.operation === "create" &&
|
|
132
|
+
(
|
|
155
133
|
//@ts-ignore
|
|
156
|
-
mutation
|
|
134
|
+
(_b = mutation === null || mutation === void 0 ? void 0 : mutation.exempt_policy_violation_keys) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
157
135
|
//@ts-ignore
|
|
158
136
|
operation.exempt_policy_violation_keys =
|
|
159
137
|
mutation.exempt_policy_violation_keys;
|
|
@@ -176,12 +154,13 @@ class Service {
|
|
|
176
154
|
}
|
|
177
155
|
buildOperations(type, entities, message) {
|
|
178
156
|
const ops = entities.map((e) => {
|
|
157
|
+
var _a;
|
|
179
158
|
const op = {
|
|
180
159
|
[type]: e,
|
|
181
160
|
operation: type,
|
|
182
161
|
};
|
|
183
162
|
//@ts-ignore
|
|
184
|
-
if (type === "create" && e
|
|
163
|
+
if (type === "create" && ((_a = e === null || e === void 0 ? void 0 : e.exempt_policy_violation_keys) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
185
164
|
// @ts-expect-error Field required for policy violation exemptions
|
|
186
165
|
op.exempt_policy_violation_keys = e.exempt_policy_violation_keys;
|
|
187
166
|
//@ts-ignore
|
package/build/src/testUtils.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Readable } from "stream";
|
|
2
1
|
import { Customer } from "./customer";
|
|
3
2
|
import { Hooks } from "./hooks";
|
|
4
3
|
import { errors, GoogleAdsServiceClient, services } from "./protos";
|
|
@@ -12,39 +11,7 @@ export declare const MOCK_LOGIN_CID = "MOCK LOGIN CID";
|
|
|
12
11
|
export declare const mockGaqlQuery = "SELECT campaign.resource_name FROM campaign LIMIT 1";
|
|
13
12
|
export declare const mockReportOptions: ReportOptions;
|
|
14
13
|
export declare const mockMutations: MutateOperation<any>[];
|
|
15
|
-
export declare const mockSearchRawResult: {
|
|
16
|
-
totalResultsCount: number;
|
|
17
|
-
results: {
|
|
18
|
-
campaign: {
|
|
19
|
-
resourceName: string;
|
|
20
|
-
};
|
|
21
|
-
}[];
|
|
22
|
-
}[];
|
|
23
|
-
export declare const mockSearchRawResultWithSummaryRow: ({
|
|
24
|
-
totalResultsCount: number;
|
|
25
|
-
results: {
|
|
26
|
-
campaign: {
|
|
27
|
-
resourceName: string;
|
|
28
|
-
};
|
|
29
|
-
}[];
|
|
30
|
-
summaryRow?: undefined;
|
|
31
|
-
} | {
|
|
32
|
-
summaryRow: {
|
|
33
|
-
metrics: {
|
|
34
|
-
clicks: number;
|
|
35
|
-
impressions: number;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
totalResultsCount?: undefined;
|
|
39
|
-
results?: undefined;
|
|
40
|
-
})[];
|
|
41
14
|
export declare const mockQueryReturnValue: services.IGoogleAdsRow[];
|
|
42
|
-
export declare const mockQueryReturnValueWithSummaryRow: services.IGoogleAdsRow[];
|
|
43
|
-
export declare const mockQueryReturnValueUnparsed: {
|
|
44
|
-
campaign: {
|
|
45
|
-
resourceName: string;
|
|
46
|
-
};
|
|
47
|
-
}[];
|
|
48
15
|
export declare const mockSummaryRow: services.IGoogleAdsRow;
|
|
49
16
|
export declare const mockTotalResultsCount = 23;
|
|
50
17
|
export declare const mockMutationReturnValue: services.MutateGoogleAdsResponse;
|
|
@@ -59,10 +26,6 @@ export declare const mockError: {
|
|
|
59
26
|
export declare const mockErrorMessage = "mock error message";
|
|
60
27
|
export declare const mockParseValue: services.IGoogleAdsRow;
|
|
61
28
|
export declare const mockParsedValues: services.IGoogleAdsRow[];
|
|
62
|
-
export declare const mockStream: (data?: any) => Readable;
|
|
63
|
-
export declare function mockGetAccessToken(customer: Customer): jest.SpyInstance;
|
|
64
|
-
export declare const mockStreamWithSummaryRow: () => Readable;
|
|
65
|
-
export declare const mockStreamWithBadData: () => Readable;
|
|
66
29
|
export declare function mockPaginatedSearch(customer: Customer, includeTotalResultsCount?: boolean): jest.SpyInstance;
|
|
67
30
|
export declare function mockSearchOnce({ customer, response, nextPageToken, includeTotalResultsCount, }: {
|
|
68
31
|
customer: Customer;
|
|
@@ -98,7 +61,6 @@ export declare function mockBuildMutateRequestAndService({ customer, shouldThrow
|
|
|
98
61
|
export declare function mockGetGoogleAdsError(customer: Customer): jest.SpyInstance;
|
|
99
62
|
export declare function mockQuery(customer: Customer): jest.SpyInstance;
|
|
100
63
|
export declare function mockParse(mockParsedValues: services.IGoogleAdsRow[]): jest.SpyInstance;
|
|
101
|
-
export declare function mockParseRest(mockParsedValues: services.IGoogleAdsRow[]): jest.SpyInstance;
|
|
102
64
|
export declare function noopParser(rows: services.IGoogleAdsRow[]): services.IGoogleAdsRow[];
|
|
103
65
|
export declare function mockMethod(): {
|
|
104
66
|
method(): void;
|
package/build/src/testUtils.js
CHANGED
|
@@ -15,19 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
})();
|
|
28
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
exports.mockGetAccessToken = mockGetAccessToken;
|
|
36
|
+
exports.mockParsedValues = exports.mockParseValue = exports.mockErrorMessage = exports.mockError = exports.mockMutationReturnValue = exports.mockTotalResultsCount = exports.mockSummaryRow = exports.mockQueryReturnValue = exports.mockMutations = exports.mockReportOptions = exports.mockGaqlQuery = exports.MOCK_LOGIN_CID = exports.MOCK_CID = exports.MOCK_REFRESH_TOKEN = exports.MOCK_DEVELOPER_TOKEN = exports.MOCK_CLIENT_SECRET = exports.MOCK_CLIENT_ID = void 0;
|
|
31
37
|
exports.mockPaginatedSearch = mockPaginatedSearch;
|
|
32
38
|
exports.mockSearchOnce = mockSearchOnce;
|
|
33
39
|
exports.mockBuildSearchStreamRequestAndService = mockBuildSearchStreamRequestAndService;
|
|
@@ -36,7 +42,6 @@ exports.mockBuildMutateRequestAndService = mockBuildMutateRequestAndService;
|
|
|
36
42
|
exports.mockGetGoogleAdsError = mockGetGoogleAdsError;
|
|
37
43
|
exports.mockQuery = mockQuery;
|
|
38
44
|
exports.mockParse = mockParse;
|
|
39
|
-
exports.mockParseRest = mockParseRest;
|
|
40
45
|
exports.noopParser = noopParser;
|
|
41
46
|
exports.mockMethod = mockMethod;
|
|
42
47
|
exports.failTestIfExecuted = failTestIfExecuted;
|
|
@@ -44,9 +49,7 @@ exports.newCustomer = newCustomer;
|
|
|
44
49
|
const stream_1 = require("stream");
|
|
45
50
|
const customer_1 = require("./customer");
|
|
46
51
|
const parser = __importStar(require("./parser"));
|
|
47
|
-
const parserRest = __importStar(require("./parserRest"));
|
|
48
52
|
const protos_1 = require("./protos");
|
|
49
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
50
53
|
exports.MOCK_CLIENT_ID = "MOCK CLIENT ID";
|
|
51
54
|
exports.MOCK_CLIENT_SECRET = "MOCK CLIENT SECRET";
|
|
52
55
|
exports.MOCK_DEVELOPER_TOKEN = "MOCK DEVELOPER TOKEN";
|
|
@@ -62,45 +65,11 @@ exports.mockReportOptions = {
|
|
|
62
65
|
exports.mockMutations = [
|
|
63
66
|
{ resource: "abc", entity: "campaign", operation: "create" },
|
|
64
67
|
];
|
|
65
|
-
exports.mockSearchRawResult = [
|
|
66
|
-
{
|
|
67
|
-
totalResultsCount: 23,
|
|
68
|
-
results: [
|
|
69
|
-
{ campaign: { resourceName: "customers/1/campaigns/11" } },
|
|
70
|
-
{ campaign: { resourceName: "customers/2/campaigns/22" } },
|
|
71
|
-
{ campaign: { resourceName: "customers/3/campaigns/33" } },
|
|
72
|
-
],
|
|
73
|
-
},
|
|
74
|
-
];
|
|
75
|
-
exports.mockSearchRawResultWithSummaryRow = [
|
|
76
|
-
{
|
|
77
|
-
totalResultsCount: 23,
|
|
78
|
-
results: [
|
|
79
|
-
{ campaign: { resourceName: "customers/1/campaigns/11" } },
|
|
80
|
-
{ campaign: { resourceName: "customers/2/campaigns/22" } },
|
|
81
|
-
{ campaign: { resourceName: "customers/3/campaigns/33" } },
|
|
82
|
-
],
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
summaryRow: { metrics: { clicks: 90, impressions: 153 } },
|
|
86
|
-
},
|
|
87
|
-
];
|
|
88
68
|
exports.mockQueryReturnValue = [
|
|
89
69
|
{ campaign: { resource_name: "customers/1/campaigns/11" } },
|
|
90
70
|
{ campaign: { resource_name: "customers/2/campaigns/22" } },
|
|
91
71
|
{ campaign: { resource_name: "customers/3/campaigns/33" } },
|
|
92
72
|
];
|
|
93
|
-
exports.mockQueryReturnValueWithSummaryRow = [
|
|
94
|
-
{ campaign: { resource_name: "customers/1/campaigns/11" } },
|
|
95
|
-
{ campaign: { resource_name: "customers/2/campaigns/22" } },
|
|
96
|
-
{ campaign: { resource_name: "customers/3/campaigns/33" } },
|
|
97
|
-
{ metrics: { clicks: 90, impressions: 153 } },
|
|
98
|
-
];
|
|
99
|
-
exports.mockQueryReturnValueUnparsed = [
|
|
100
|
-
{ campaign: { resourceName: "customers/1/campaigns/11" } },
|
|
101
|
-
{ campaign: { resourceName: "customers/2/campaigns/22" } },
|
|
102
|
-
{ campaign: { resourceName: "customers/3/campaigns/33" } },
|
|
103
|
-
];
|
|
104
73
|
exports.mockSummaryRow = {
|
|
105
74
|
metrics: { clicks: 90, impressions: 153 },
|
|
106
75
|
};
|
|
@@ -128,42 +97,17 @@ exports.mockParsedValues = [
|
|
|
128
97
|
exports.mockParseValue,
|
|
129
98
|
exports.mockParseValue,
|
|
130
99
|
];
|
|
131
|
-
// Returns a stream that emits the provided values
|
|
132
|
-
const mockStream = function (data = exports.mockSearchRawResult) {
|
|
133
|
-
const chunks = lodash_1.default.chunk(JSON.stringify(data), 10).map((c) => c.join("")); // random splits
|
|
134
|
-
const stream = new stream_1.Readable({ objectMode: true });
|
|
135
|
-
chunks.forEach((value) => stream.push(new Buffer(value)));
|
|
136
|
-
stream.push(null);
|
|
137
|
-
return stream;
|
|
138
|
-
};
|
|
139
|
-
exports.mockStream = mockStream;
|
|
140
|
-
function mockGetAccessToken(customer) {
|
|
141
|
-
return (jest
|
|
142
|
-
.spyOn(customer, "getAccessToken")
|
|
143
|
-
// ts-expect-error
|
|
144
|
-
.mockImplementation(async () => {
|
|
145
|
-
return "mockedAccessTokenHere";
|
|
146
|
-
}));
|
|
147
|
-
}
|
|
148
|
-
const mockStreamWithSummaryRow = function () {
|
|
149
|
-
return (0, exports.mockStream)(exports.mockSearchRawResultWithSummaryRow);
|
|
150
|
-
};
|
|
151
|
-
exports.mockStreamWithSummaryRow = mockStreamWithSummaryRow;
|
|
152
|
-
const mockStreamWithBadData = function () {
|
|
153
|
-
return (0, exports.mockStream)({ results: 66 });
|
|
154
|
-
};
|
|
155
|
-
exports.mockStreamWithBadData = mockStreamWithBadData;
|
|
156
100
|
function mockPaginatedSearch(customer, includeTotalResultsCount = false) {
|
|
157
101
|
return (jest
|
|
158
102
|
// @ts-expect-error private method
|
|
159
103
|
.spyOn(customer, "paginatedSearch")
|
|
160
104
|
// @ts-expect-error
|
|
161
|
-
.mockImplementation((gaqlQuery, requestOptions) => {
|
|
105
|
+
.mockImplementation((gaqlQuery, requestOptions, _parser) => {
|
|
162
106
|
const totalResultsCount = includeTotalResultsCount
|
|
163
107
|
? exports.mockTotalResultsCount
|
|
164
108
|
: undefined;
|
|
165
109
|
return {
|
|
166
|
-
response: exports.mockQueryReturnValue,
|
|
110
|
+
response: _parser(exports.mockQueryReturnValue),
|
|
167
111
|
totalResultsCount,
|
|
168
112
|
};
|
|
169
113
|
}));
|
|
@@ -254,7 +198,7 @@ function mockBuildMutateRequestAndService({ customer, shouldThrow = false, reque
|
|
|
254
198
|
if (shouldThrow) {
|
|
255
199
|
throw new Error(exports.mockErrorMessage);
|
|
256
200
|
}
|
|
257
|
-
return [response
|
|
201
|
+
return [response !== null && response !== void 0 ? response : exports.mockMutationReturnValue];
|
|
258
202
|
},
|
|
259
203
|
};
|
|
260
204
|
const spyBuild = jest
|
|
@@ -264,7 +208,7 @@ function mockBuildMutateRequestAndService({ customer, shouldThrow = false, reque
|
|
|
264
208
|
.mockImplementation(() => {
|
|
265
209
|
return {
|
|
266
210
|
service: mockService,
|
|
267
|
-
request: request
|
|
211
|
+
request: request !== null && request !== void 0 ? request : {},
|
|
268
212
|
};
|
|
269
213
|
});
|
|
270
214
|
return { mockService, spyBuild };
|
|
@@ -291,11 +235,6 @@ function mockQuery(customer) {
|
|
|
291
235
|
function mockParse(mockParsedValues) {
|
|
292
236
|
return jest.spyOn(parser, "parse").mockImplementation(() => mockParsedValues);
|
|
293
237
|
}
|
|
294
|
-
function mockParseRest(mockParsedValues) {
|
|
295
|
-
return jest
|
|
296
|
-
.spyOn(parserRest, "decamelizeKeys")
|
|
297
|
-
.mockImplementation(() => mockParsedValues);
|
|
298
|
-
}
|
|
299
238
|
function noopParser(rows) {
|
|
300
239
|
return rows;
|
|
301
240
|
}
|
package/build/src/utils.d.ts
CHANGED
|
@@ -47,3 +47,8 @@ export declare function toCamelCase(str: string): string;
|
|
|
47
47
|
export declare function toSnakeCase(str: string): string;
|
|
48
48
|
export declare function recursiveFieldMaskSearch(data: Record<string, any>): string[];
|
|
49
49
|
export declare function getFieldMask(data: Record<string, any>): protobuf.FieldMask;
|
|
50
|
+
export declare function createNextChunkArrivedPromise(): {
|
|
51
|
+
newPromise: Promise<unknown>;
|
|
52
|
+
resolve: () => void;
|
|
53
|
+
reject: (error: Error) => void;
|
|
54
|
+
};
|
package/build/src/utils.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.toCamelCase = toCamelCase;
|
|
|
8
8
|
exports.toSnakeCase = toSnakeCase;
|
|
9
9
|
exports.recursiveFieldMaskSearch = recursiveFieldMaskSearch;
|
|
10
10
|
exports.getFieldMask = getFieldMask;
|
|
11
|
+
exports.createNextChunkArrivedPromise = createNextChunkArrivedPromise;
|
|
11
12
|
const protos_1 = require("./protos");
|
|
12
13
|
/**
|
|
13
14
|
* @param micros Money value in micros format
|
|
@@ -99,3 +100,17 @@ function getFieldMask(data) {
|
|
|
99
100
|
paths,
|
|
100
101
|
});
|
|
101
102
|
}
|
|
103
|
+
function createNextChunkArrivedPromise() {
|
|
104
|
+
let resolvePromise = () => {
|
|
105
|
+
return;
|
|
106
|
+
};
|
|
107
|
+
let rejectPromise = (error) => {
|
|
108
|
+
throw error;
|
|
109
|
+
};
|
|
110
|
+
const newPromise = new Promise((resolve, reject) => {
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
resolvePromise = resolve;
|
|
113
|
+
rejectPromise = reject;
|
|
114
|
+
});
|
|
115
|
+
return { newPromise, resolve: resolvePromise, reject: rejectPromise };
|
|
116
|
+
}
|
package/build/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const googleAdsVersion = "
|
|
1
|
+
export declare const googleAdsVersion = "v20";
|
package/build/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "google-ads-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20.0.0",
|
|
4
4
|
"description": "Google Ads API Client Library for Node.js",
|
|
5
5
|
"repository": "https://github.com/Opteo/google-ads-api",
|
|
6
6
|
"main": "build/src/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"test": "jest",
|
|
12
12
|
"lint": "eslint . --ext .ts",
|
|
13
13
|
"build": "tsc",
|
|
14
|
-
"compile": "
|
|
14
|
+
"compile": "tsc && node build/scripts/index.js",
|
|
15
15
|
"prepare": "rm -rf build && npm run build",
|
|
16
16
|
"node": "tsx"
|
|
17
17
|
},
|
|
@@ -19,31 +19,22 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@isaacs/ttlcache": "^1.2.2",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"google-
|
|
25
|
-
"
|
|
26
|
-
"google-gax": "^4.4.1",
|
|
27
|
-
"long": "^4.0.0",
|
|
28
|
-
"map-obj": "^4.0.0",
|
|
29
|
-
"stream-json": "^1.8.0"
|
|
22
|
+
"google-ads-node": "17.0.0",
|
|
23
|
+
"google-auth-library": "^9.15.1",
|
|
24
|
+
"google-gax": "^5.1.1-rc.1",
|
|
25
|
+
"long": "^4.0.0"
|
|
30
26
|
},
|
|
31
27
|
"devDependencies": {
|
|
32
28
|
"@types/jest": "^29.0.1",
|
|
33
|
-
"@types/
|
|
29
|
+
"@types/long": "^4.0.0",
|
|
34
30
|
"@types/node": "^22.5.4",
|
|
35
31
|
"@types/pluralize": "^0.0.29",
|
|
36
|
-
"@types/stream-json": "^1.7.7",
|
|
37
32
|
"@typescript-eslint/eslint-plugin": "^4.8.2",
|
|
38
33
|
"@typescript-eslint/parser": "^4.8.2",
|
|
39
|
-
"axios-mock-adapter": "^1.22.0",
|
|
40
|
-
"esbuild": "^0.20.1",
|
|
41
34
|
"eslint": "^7.14.0",
|
|
42
|
-
"jest": "^29.
|
|
43
|
-
"lodash": "^4.17.21",
|
|
35
|
+
"jest": "^29.0.3",
|
|
44
36
|
"pluralize": "^8.0.0",
|
|
45
|
-
"
|
|
46
|
-
"ts-jest": "^29.1.2",
|
|
37
|
+
"ts-jest": "^29.0.0",
|
|
47
38
|
"tsx": "^4.19.3",
|
|
48
39
|
"typescript": "^5.5.4"
|
|
49
40
|
},
|
|
@@ -59,5 +50,8 @@
|
|
|
59
50
|
"adwords javascript",
|
|
60
51
|
"gads"
|
|
61
52
|
],
|
|
53
|
+
"resolutions": {
|
|
54
|
+
"google-auth-library": "^9.15.1"
|
|
55
|
+
},
|
|
62
56
|
"packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
|
|
63
57
|
}
|
package/build/src/parserRest.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* JSON Rest parsing
|
|
4
|
-
*/
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.decamelizeKeys = void 0;
|
|
10
|
-
const map_obj_1 = __importDefault(require("map-obj"));
|
|
11
|
-
const circ_json_1 = require("circ-json");
|
|
12
|
-
const utils_1 = require("./utils");
|
|
13
|
-
const fields_1 = require("./protos/autogen/fields");
|
|
14
|
-
const enums_1 = require("./protos/autogen/enums");
|
|
15
|
-
const fieldDataTypes = (0, circ_json_1.parse)(fields_1.fieldDataTypes);
|
|
16
|
-
const decamelizeCache = new Map();
|
|
17
|
-
const fieldTypeCache = new Map();
|
|
18
|
-
const isObject = (value) => typeof value === "object" && value !== null;
|
|
19
|
-
const decamelizeKeys = (input) => {
|
|
20
|
-
if (!isObject(input)) {
|
|
21
|
-
return input;
|
|
22
|
-
}
|
|
23
|
-
const makeMapper = (parentPath) => (key, value) => {
|
|
24
|
-
key = cachedDecamelize(key);
|
|
25
|
-
if (isObject(value)) {
|
|
26
|
-
const path = parentPath === undefined ? key : `${parentPath}.${key}`;
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
value = (0, map_obj_1.default)(value, makeMapper(path));
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
value = cachedValueParser(key, parentPath, value);
|
|
32
|
-
}
|
|
33
|
-
return [key, value];
|
|
34
|
-
};
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
return (0, map_obj_1.default)(input, makeMapper());
|
|
37
|
-
};
|
|
38
|
-
exports.decamelizeKeys = decamelizeKeys;
|
|
39
|
-
const cachedDecamelize = (key) => {
|
|
40
|
-
const cachedResult = decamelizeCache.get(key);
|
|
41
|
-
if (cachedResult) {
|
|
42
|
-
return cachedResult;
|
|
43
|
-
}
|
|
44
|
-
const newKey = (0, utils_1.toSnakeCase)(key);
|
|
45
|
-
decamelizeCache.set(key, newKey);
|
|
46
|
-
return newKey;
|
|
47
|
-
};
|
|
48
|
-
const cachedValueParser = (key, parentPath, value) => {
|
|
49
|
-
let newValue = value;
|
|
50
|
-
const fullPath = parentPath ? `${parentPath}.${key}` : key;
|
|
51
|
-
const megaDataType = getTypeFromPath(fullPath);
|
|
52
|
-
if (megaDataType === undefined && !fullPath.startsWith("@")) {
|
|
53
|
-
console.warn(`No data type found for ${fullPath}`);
|
|
54
|
-
}
|
|
55
|
-
else if (typeof megaDataType === "object") {
|
|
56
|
-
newValue = megaDataType[value];
|
|
57
|
-
}
|
|
58
|
-
else if (megaDataType === "INT64") {
|
|
59
|
-
newValue = Number(value);
|
|
60
|
-
}
|
|
61
|
-
else if (megaDataType === "ENUM") {
|
|
62
|
-
// Some enums aren't embedded in megaDataType, so we need this fallback.
|
|
63
|
-
// @ts-expect-error typescript doesn't like accessing items in a namespace with a string
|
|
64
|
-
newValue = enums_1.enums[fields_1.fields.enumFields[fullPath]][value]; // e.g. enums['CampaignStatus'][ENABLED] = "2"
|
|
65
|
-
}
|
|
66
|
-
return newValue;
|
|
67
|
-
};
|
|
68
|
-
const getTypeFromPath = (path) => {
|
|
69
|
-
const cachedResult = fieldTypeCache.get(path);
|
|
70
|
-
if (cachedResult) {
|
|
71
|
-
return cachedResult;
|
|
72
|
-
}
|
|
73
|
-
const t = get(fieldDataTypes, path);
|
|
74
|
-
fieldTypeCache.set(path, t);
|
|
75
|
-
return t;
|
|
76
|
-
};
|
|
77
|
-
// Copied from youmightnotneed.com
|
|
78
|
-
const get = (obj, path) => {
|
|
79
|
-
if (!path)
|
|
80
|
-
return undefined;
|
|
81
|
-
// Check if path is string or array. Regex : ensure that we do not have '.' and brackets.
|
|
82
|
-
// Regex explained: https://regexr.com/58j0k
|
|
83
|
-
const pathArray = path.match(/([^[.\]])+/g);
|
|
84
|
-
if (!pathArray)
|
|
85
|
-
return undefined;
|
|
86
|
-
// Find value
|
|
87
|
-
return pathArray.reduce((prevObj, key) => prevObj && prevObj[key], obj);
|
|
88
|
-
};
|