google-ads-api 10.0.1 → 11.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.
- package/README.md +80 -23
- package/build/src/client.js +31 -80
- package/build/src/customer.d.ts +10 -0
- package/build/src/customer.js +313 -472
- package/build/src/hooks.d.ts +38 -3
- package/build/src/index.d.ts +1 -1
- package/build/src/index.js +5 -1
- package/build/src/parser.js +29 -36
- package/build/src/protos/autogen/enums.d.ts +514 -300
- package/build/src/protos/autogen/enums.js +805 -583
- package/build/src/protos/autogen/fields.d.ts +172 -153
- package/build/src/protos/autogen/fields.js +12 -1
- package/build/src/protos/autogen/resourceNames.d.ts +16 -0
- package/build/src/protos/autogen/resourceNames.js +177 -157
- package/build/src/protos/autogen/serviceFactory.d.ts +197 -147
- package/build/src/protos/autogen/serviceFactory.js +18483 -17447
- package/build/src/protos/index.d.ts +6 -6
- package/build/src/protos/index.js +7 -7
- package/build/src/query.js +74 -81
- package/build/src/service.js +107 -112
- package/build/src/testUtils.js +52 -53
- package/build/src/utils.js +19 -21
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/package.json +6 -5
package/build/src/testUtils.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -20,17 +24,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
24
|
};
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
26
|
exports.newCustomer = exports.failTestIfExecuted = exports.mockMethod = exports.noopParser = exports.mockParse = exports.mockQuery = exports.mockGetGoogleAdsError = exports.mockBuildMutateRequestAndService = exports.mockBuildSearchRequestAndService = exports.mockBuildSearchStreamRequestAndService = exports.mockSearchOnce = exports.mockPaginatedSearch = 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;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
const stream_1 = require("stream");
|
|
28
|
+
const customer_1 = require("./customer");
|
|
29
|
+
const parser = __importStar(require("./parser"));
|
|
30
|
+
const protos_1 = require("./protos");
|
|
27
31
|
exports.MOCK_CLIENT_ID = "MOCK CLIENT ID";
|
|
28
32
|
exports.MOCK_CLIENT_SECRET = "MOCK CLIENT SECRET";
|
|
29
33
|
exports.MOCK_DEVELOPER_TOKEN = "MOCK DEVELOPER TOKEN";
|
|
30
34
|
exports.MOCK_REFRESH_TOKEN = "MOCK REFRESH TOKEN";
|
|
31
35
|
exports.MOCK_CID = "MOCK CID";
|
|
32
36
|
exports.MOCK_LOGIN_CID = "MOCK LOGIN CID";
|
|
33
|
-
exports.mockGaqlQuery =
|
|
37
|
+
exports.mockGaqlQuery = `SELECT campaign.resource_name FROM campaign LIMIT 1`;
|
|
34
38
|
exports.mockReportOptions = {
|
|
35
39
|
entity: "campaign",
|
|
36
40
|
attributes: ["campaign.resource_name"],
|
|
@@ -50,7 +54,7 @@ exports.mockSummaryRow = {
|
|
|
50
54
|
exports.mockTotalResultsCount = 23;
|
|
51
55
|
exports.mockMutationReturnValue = {
|
|
52
56
|
mutate_operation_responses: [],
|
|
53
|
-
toJSON:
|
|
57
|
+
toJSON: () => {
|
|
54
58
|
return {};
|
|
55
59
|
},
|
|
56
60
|
};
|
|
@@ -71,33 +75,31 @@ exports.mockParsedValues = [
|
|
|
71
75
|
exports.mockParseValue,
|
|
72
76
|
exports.mockParseValue,
|
|
73
77
|
];
|
|
74
|
-
function mockPaginatedSearch(customer, includeTotalResultsCount) {
|
|
75
|
-
if (includeTotalResultsCount === void 0) { includeTotalResultsCount = false; }
|
|
78
|
+
function mockPaginatedSearch(customer, includeTotalResultsCount = false) {
|
|
76
79
|
return (jest
|
|
77
80
|
// @ts-expect-error private method
|
|
78
81
|
.spyOn(customer, "paginatedSearch")
|
|
79
82
|
// @ts-expect-error
|
|
80
|
-
.mockImplementation(
|
|
81
|
-
|
|
83
|
+
.mockImplementation((gaqlQuery, requestOptions, _parser) => {
|
|
84
|
+
const totalResultsCount = includeTotalResultsCount
|
|
82
85
|
? exports.mockTotalResultsCount
|
|
83
86
|
: undefined;
|
|
84
87
|
return {
|
|
85
88
|
response: _parser(exports.mockQueryReturnValue),
|
|
86
|
-
totalResultsCount
|
|
89
|
+
totalResultsCount,
|
|
87
90
|
};
|
|
88
91
|
}));
|
|
89
92
|
}
|
|
90
93
|
exports.mockPaginatedSearch = mockPaginatedSearch;
|
|
91
|
-
function mockSearchOnce(
|
|
92
|
-
var customer = _a.customer, response = _a.response, nextPageToken = _a.nextPageToken, includeTotalResultsCount = _a.includeTotalResultsCount;
|
|
94
|
+
function mockSearchOnce({ customer, response, nextPageToken, includeTotalResultsCount, }) {
|
|
93
95
|
return (jest
|
|
94
96
|
// @ts-expect-error private method
|
|
95
97
|
.spyOn(customer, "search")
|
|
96
98
|
// @ts-expect-error
|
|
97
|
-
.mockImplementationOnce(
|
|
99
|
+
.mockImplementationOnce(() => {
|
|
98
100
|
return {
|
|
99
|
-
response
|
|
100
|
-
nextPageToken
|
|
101
|
+
response,
|
|
102
|
+
nextPageToken,
|
|
101
103
|
totalResultsCount: includeTotalResultsCount
|
|
102
104
|
? exports.mockTotalResultsCount
|
|
103
105
|
: undefined,
|
|
@@ -106,52 +108,51 @@ function mockSearchOnce(_a) {
|
|
|
106
108
|
}
|
|
107
109
|
exports.mockSearchOnce = mockSearchOnce;
|
|
108
110
|
function mockBuildSearchStreamRequestAndService(customer) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
const mockStream = new stream_1.Readable({ objectMode: true });
|
|
112
|
+
const mockStreamData = (results) => {
|
|
113
|
+
const chunk = { results };
|
|
112
114
|
mockStream.push(chunk);
|
|
113
115
|
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
const mockStreamSummaryRow = () => {
|
|
117
|
+
const chunk = {
|
|
116
118
|
summary_row: exports.mockSummaryRow,
|
|
117
119
|
};
|
|
118
120
|
mockStream.push(chunk);
|
|
119
121
|
};
|
|
120
|
-
|
|
122
|
+
const mockStreamError = (error) => {
|
|
121
123
|
mockStream.destroy(error);
|
|
122
124
|
};
|
|
123
|
-
|
|
125
|
+
const mockStreamEnd = () => {
|
|
124
126
|
mockStream.push(null);
|
|
125
127
|
};
|
|
126
|
-
|
|
128
|
+
const spyBuild = jest
|
|
127
129
|
// @ts-expect-error protected method
|
|
128
130
|
.spyOn(customer, "buildSearchStreamRequestAndService")
|
|
129
131
|
// @ts-expect-error
|
|
130
|
-
.mockImplementation(
|
|
132
|
+
.mockImplementation(() => {
|
|
131
133
|
return {
|
|
132
134
|
service: {
|
|
133
|
-
searchStream:
|
|
135
|
+
searchStream: () => mockStream,
|
|
134
136
|
},
|
|
135
137
|
request: {},
|
|
136
138
|
};
|
|
137
139
|
});
|
|
138
140
|
return {
|
|
139
|
-
spyBuild
|
|
140
|
-
mockStreamData
|
|
141
|
-
mockStreamSummaryRow
|
|
142
|
-
mockStreamError
|
|
143
|
-
mockStreamEnd
|
|
141
|
+
spyBuild,
|
|
142
|
+
mockStreamData,
|
|
143
|
+
mockStreamSummaryRow,
|
|
144
|
+
mockStreamError,
|
|
145
|
+
mockStreamEnd,
|
|
144
146
|
};
|
|
145
147
|
}
|
|
146
148
|
exports.mockBuildSearchStreamRequestAndService = mockBuildSearchStreamRequestAndService;
|
|
147
|
-
function mockBuildSearchRequestAndService(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
search: function () {
|
|
149
|
+
function mockBuildSearchRequestAndService({ customer, shouldThrow = false, includeSummaryRow = false, includeTotalResultsCount = false, }) {
|
|
150
|
+
const mockService = {
|
|
151
|
+
search: () => {
|
|
151
152
|
if (shouldThrow) {
|
|
152
153
|
throw new Error(exports.mockErrorMessage);
|
|
153
154
|
}
|
|
154
|
-
|
|
155
|
+
const searchGoogleAdsResponse = {
|
|
155
156
|
summary_row: includeSummaryRow ? exports.mockSummaryRow : undefined,
|
|
156
157
|
total_results_count: includeTotalResultsCount
|
|
157
158
|
? exports.mockTotalResultsCount
|
|
@@ -160,40 +161,39 @@ function mockBuildSearchRequestAndService(_a) {
|
|
|
160
161
|
return [exports.mockQueryReturnValue, null, searchGoogleAdsResponse];
|
|
161
162
|
},
|
|
162
163
|
};
|
|
163
|
-
|
|
164
|
+
const spyBuild = jest
|
|
164
165
|
// @ts-expect-error protected method
|
|
165
166
|
.spyOn(customer, "buildSearchRequestAndService")
|
|
166
167
|
// @ts-expect-error
|
|
167
|
-
.mockImplementation(
|
|
168
|
+
.mockImplementation(() => {
|
|
168
169
|
return {
|
|
169
170
|
service: mockService,
|
|
170
171
|
request: {},
|
|
171
172
|
};
|
|
172
173
|
});
|
|
173
|
-
return { mockService
|
|
174
|
+
return { mockService, spyBuild };
|
|
174
175
|
}
|
|
175
176
|
exports.mockBuildSearchRequestAndService = mockBuildSearchRequestAndService;
|
|
176
|
-
function mockBuildMutateRequestAndService(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
mutate: function () {
|
|
177
|
+
function mockBuildMutateRequestAndService({ customer, shouldThrow = false, request, response, }) {
|
|
178
|
+
const mockService = {
|
|
179
|
+
mutate() {
|
|
180
180
|
if (shouldThrow) {
|
|
181
181
|
throw new Error(exports.mockErrorMessage);
|
|
182
182
|
}
|
|
183
183
|
return [response !== null && response !== void 0 ? response : exports.mockMutationReturnValue];
|
|
184
184
|
},
|
|
185
185
|
};
|
|
186
|
-
|
|
186
|
+
const spyBuild = jest
|
|
187
187
|
// @ts-expect-error protected method
|
|
188
188
|
.spyOn(customer, "buildMutationRequestAndService")
|
|
189
189
|
// @ts-expect-error
|
|
190
|
-
.mockImplementation(
|
|
190
|
+
.mockImplementation(() => {
|
|
191
191
|
return {
|
|
192
192
|
service: mockService,
|
|
193
193
|
request: request !== null && request !== void 0 ? request : {},
|
|
194
194
|
};
|
|
195
195
|
});
|
|
196
|
-
return { mockService
|
|
196
|
+
return { mockService, spyBuild };
|
|
197
197
|
}
|
|
198
198
|
exports.mockBuildMutateRequestAndService = mockBuildMutateRequestAndService;
|
|
199
199
|
function mockGetGoogleAdsError(customer) {
|
|
@@ -201,7 +201,7 @@ function mockGetGoogleAdsError(customer) {
|
|
|
201
201
|
// @ts-expect-error protected method
|
|
202
202
|
.spyOn(customer, "getGoogleAdsError")
|
|
203
203
|
// @ts-expect-error
|
|
204
|
-
.mockImplementation(
|
|
204
|
+
.mockImplementation(() => exports.mockError));
|
|
205
205
|
}
|
|
206
206
|
exports.mockGetGoogleAdsError = mockGetGoogleAdsError;
|
|
207
207
|
function mockQuery(customer) {
|
|
@@ -209,7 +209,7 @@ function mockQuery(customer) {
|
|
|
209
209
|
// @ts-expect-error private method
|
|
210
210
|
.spyOn(customer, "querier")
|
|
211
211
|
// @ts-expect-error
|
|
212
|
-
.mockImplementation(
|
|
212
|
+
.mockImplementation(() => {
|
|
213
213
|
return {
|
|
214
214
|
response: exports.mockQueryReturnValue,
|
|
215
215
|
totalResultsCount: exports.mockTotalResultsCount,
|
|
@@ -218,7 +218,7 @@ function mockQuery(customer) {
|
|
|
218
218
|
}
|
|
219
219
|
exports.mockQuery = mockQuery;
|
|
220
220
|
function mockParse(mockParsedValues) {
|
|
221
|
-
return jest.spyOn(parser, "parse").mockImplementation(
|
|
221
|
+
return jest.spyOn(parser, "parse").mockImplementation(() => mockParsedValues);
|
|
222
222
|
}
|
|
223
223
|
exports.mockParse = mockParse;
|
|
224
224
|
function noopParser(rows) {
|
|
@@ -227,7 +227,7 @@ function noopParser(rows) {
|
|
|
227
227
|
exports.noopParser = noopParser;
|
|
228
228
|
function mockMethod() {
|
|
229
229
|
return {
|
|
230
|
-
method
|
|
230
|
+
method() {
|
|
231
231
|
return;
|
|
232
232
|
},
|
|
233
233
|
};
|
|
@@ -237,8 +237,7 @@ function failTestIfExecuted() {
|
|
|
237
237
|
expect(true).toBeFalsy();
|
|
238
238
|
}
|
|
239
239
|
exports.failTestIfExecuted = failTestIfExecuted;
|
|
240
|
-
function newCustomer(hooks, disableParsing) {
|
|
241
|
-
if (disableParsing === void 0) { disableParsing = false; }
|
|
240
|
+
function newCustomer(hooks, disableParsing = false) {
|
|
242
241
|
return new customer_1.Customer({
|
|
243
242
|
client_id: exports.MOCK_CLIENT_ID,
|
|
244
243
|
client_secret: exports.MOCK_CLIENT_SECRET,
|
package/build/src/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createNextChunkArrivedPromise = exports.getFieldMask = exports.recursiveFieldMaskSearch = exports.toSnakeCase = exports.toCamelCase = exports.capitaliseFirstLetter = exports.normaliseQuery = exports.toMicros = exports.fromMicros = void 0;
|
|
4
|
-
|
|
4
|
+
const protos_1 = require("./protos");
|
|
5
5
|
/**
|
|
6
6
|
* @param micros Money value in micros format
|
|
7
7
|
* @description Converts a micro amount to a normalised value
|
|
@@ -19,7 +19,7 @@ exports.fromMicros = fromMicros;
|
|
|
19
19
|
* const costMicros = toMicros(12.5) // 12,500,000
|
|
20
20
|
*/
|
|
21
21
|
function toMicros(value) {
|
|
22
|
-
return value * 1000000;
|
|
22
|
+
return Math.round(value * 1000000);
|
|
23
23
|
}
|
|
24
24
|
exports.toMicros = toMicros;
|
|
25
25
|
/**
|
|
@@ -33,7 +33,7 @@ exports.toMicros = toMicros;
|
|
|
33
33
|
* const normalisedQuery = normaliseQuery(gaqlQuery) // "SELECT campaign.name FROM campaign LIMIT 10"
|
|
34
34
|
*/
|
|
35
35
|
function normaliseQuery(query) {
|
|
36
|
-
return
|
|
36
|
+
return `${query.replace(/\s{2,}/g, " ")}`;
|
|
37
37
|
}
|
|
38
38
|
exports.normaliseQuery = normaliseQuery;
|
|
39
39
|
/**
|
|
@@ -55,8 +55,8 @@ exports.capitaliseFirstLetter = capitaliseFirstLetter;
|
|
|
55
55
|
function toCamelCase(str) {
|
|
56
56
|
return str
|
|
57
57
|
.replace(/\s+/g, "_") // convert spaces to underscores
|
|
58
|
-
.replace(/(_)([A-Za-z])/g,
|
|
59
|
-
.replace(/^([A-Z])/g,
|
|
58
|
+
.replace(/(_)([A-Za-z])/g, (pattern) => pattern[1].toUpperCase()) // replace "_x" patterns with "X"
|
|
59
|
+
.replace(/^([A-Z])/g, (pattern) => pattern.toLowerCase()); // capitalises the first letter of the string
|
|
60
60
|
}
|
|
61
61
|
exports.toCamelCase = toCamelCase;
|
|
62
62
|
/**
|
|
@@ -68,24 +68,22 @@ exports.toCamelCase = toCamelCase;
|
|
|
68
68
|
function toSnakeCase(str) {
|
|
69
69
|
return str
|
|
70
70
|
.replace(/\s+/g, "_") // convert spaces to underscores
|
|
71
|
-
.replace(/(?<!(^|_))([A-Z])/g,
|
|
71
|
+
.replace(/(?<!(^|_))([A-Z])/g, (pattern) => "_" + pattern) // places an underscore before any capital chars, unless there is already an underscore or it is the first char of the string
|
|
72
72
|
.toLowerCase();
|
|
73
73
|
}
|
|
74
74
|
exports.toSnakeCase = toSnakeCase;
|
|
75
75
|
function recursiveFieldMaskSearch(data) {
|
|
76
|
-
|
|
77
|
-
for (
|
|
78
|
-
var key = _a[_i];
|
|
76
|
+
const paths = [];
|
|
77
|
+
for (const key of Object.keys(data)) {
|
|
79
78
|
if (key === "resourceName") {
|
|
80
79
|
continue;
|
|
81
80
|
}
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
const fieldKey = toSnakeCase(key);
|
|
82
|
+
const value = data[key];
|
|
84
83
|
if (typeof value === "object" && !Array.isArray(value)) {
|
|
85
|
-
|
|
86
|
-
for (
|
|
87
|
-
|
|
88
|
-
paths.push(fieldKey + "." + child);
|
|
84
|
+
const children = recursiveFieldMaskSearch(value);
|
|
85
|
+
for (const child of children) {
|
|
86
|
+
paths.push(`${fieldKey}.${child}`);
|
|
89
87
|
}
|
|
90
88
|
continue;
|
|
91
89
|
}
|
|
@@ -96,24 +94,24 @@ function recursiveFieldMaskSearch(data) {
|
|
|
96
94
|
exports.recursiveFieldMaskSearch = recursiveFieldMaskSearch;
|
|
97
95
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
96
|
function getFieldMask(data) {
|
|
99
|
-
|
|
97
|
+
const paths = recursiveFieldMaskSearch(data);
|
|
100
98
|
return new protos_1.protobuf.FieldMask({
|
|
101
|
-
paths
|
|
99
|
+
paths,
|
|
102
100
|
});
|
|
103
101
|
}
|
|
104
102
|
exports.getFieldMask = getFieldMask;
|
|
105
103
|
function createNextChunkArrivedPromise() {
|
|
106
|
-
|
|
104
|
+
let resolvePromise = () => {
|
|
107
105
|
return;
|
|
108
106
|
};
|
|
109
|
-
|
|
107
|
+
let rejectPromise = (error) => {
|
|
110
108
|
throw error;
|
|
111
109
|
};
|
|
112
|
-
|
|
110
|
+
const newPromise = new Promise((resolve, reject) => {
|
|
113
111
|
// @ts-ignore
|
|
114
112
|
resolvePromise = resolve;
|
|
115
113
|
rejectPromise = reject;
|
|
116
114
|
});
|
|
117
|
-
return { newPromise
|
|
115
|
+
return { newPromise, resolve: resolvePromise, reject: rejectPromise };
|
|
118
116
|
}
|
|
119
117
|
exports.createNextChunkArrivedPromise = createNextChunkArrivedPromise;
|
package/build/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const googleAdsVersion = "
|
|
1
|
+
export declare const googleAdsVersion = "v11";
|
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": "11.1.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",
|
|
@@ -17,19 +17,20 @@
|
|
|
17
17
|
"author": "Opteo",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"google-ads-node": "^
|
|
20
|
+
"google-ads-node": "^9.1.0",
|
|
21
21
|
"google-auth-library": "^7.1.0",
|
|
22
|
-
"google-gax": "^
|
|
22
|
+
"google-gax": "^3.5.1",
|
|
23
23
|
"long": "^4.0.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"@types/jest": "^29.0.1",
|
|
26
27
|
"@types/pluralize": "^0.0.29",
|
|
27
28
|
"@typescript-eslint/eslint-plugin": "^4.8.2",
|
|
28
29
|
"@typescript-eslint/parser": "^4.8.2",
|
|
29
30
|
"eslint": "^7.14.0",
|
|
30
|
-
"jest": "^
|
|
31
|
+
"jest": "^29.0.3",
|
|
31
32
|
"pluralize": "^8.0.0",
|
|
32
|
-
"ts-jest": "^
|
|
33
|
+
"ts-jest": "^29.0.0",
|
|
33
34
|
"typescript": "^4.1.2"
|
|
34
35
|
},
|
|
35
36
|
"keywords": [
|