google-ads-api 10.0.2 → 11.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 +67 -10
- 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/parser.js +29 -36
- package/build/src/protos/autogen/enums.d.ts +410 -300
- package/build/src/protos/autogen/enums.js +699 -583
- package/build/src/protos/autogen/fields.d.ts +167 -151
- package/build/src/protos/autogen/fields.js +9 -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 +193 -147
- package/build/src/protos/autogen/serviceFactory.js +18420 -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 +102 -107
- package/build/src/testUtils.js +47 -52
- package/build/src/utils.js +18 -20
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/package.json +3 -3
package/build/src/testUtils.js
CHANGED
|
@@ -20,17 +20,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
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
|
-
|
|
23
|
+
const stream_1 = require("stream");
|
|
24
|
+
const customer_1 = require("./customer");
|
|
25
|
+
const parser = __importStar(require("./parser"));
|
|
26
|
+
const protos_1 = require("./protos");
|
|
27
27
|
exports.MOCK_CLIENT_ID = "MOCK CLIENT ID";
|
|
28
28
|
exports.MOCK_CLIENT_SECRET = "MOCK CLIENT SECRET";
|
|
29
29
|
exports.MOCK_DEVELOPER_TOKEN = "MOCK DEVELOPER TOKEN";
|
|
30
30
|
exports.MOCK_REFRESH_TOKEN = "MOCK REFRESH TOKEN";
|
|
31
31
|
exports.MOCK_CID = "MOCK CID";
|
|
32
32
|
exports.MOCK_LOGIN_CID = "MOCK LOGIN CID";
|
|
33
|
-
exports.mockGaqlQuery =
|
|
33
|
+
exports.mockGaqlQuery = `SELECT campaign.resource_name FROM campaign LIMIT 1`;
|
|
34
34
|
exports.mockReportOptions = {
|
|
35
35
|
entity: "campaign",
|
|
36
36
|
attributes: ["campaign.resource_name"],
|
|
@@ -50,7 +50,7 @@ exports.mockSummaryRow = {
|
|
|
50
50
|
exports.mockTotalResultsCount = 23;
|
|
51
51
|
exports.mockMutationReturnValue = {
|
|
52
52
|
mutate_operation_responses: [],
|
|
53
|
-
toJSON:
|
|
53
|
+
toJSON: () => {
|
|
54
54
|
return {};
|
|
55
55
|
},
|
|
56
56
|
};
|
|
@@ -71,33 +71,31 @@ exports.mockParsedValues = [
|
|
|
71
71
|
exports.mockParseValue,
|
|
72
72
|
exports.mockParseValue,
|
|
73
73
|
];
|
|
74
|
-
function mockPaginatedSearch(customer, includeTotalResultsCount) {
|
|
75
|
-
if (includeTotalResultsCount === void 0) { includeTotalResultsCount = false; }
|
|
74
|
+
function mockPaginatedSearch(customer, includeTotalResultsCount = false) {
|
|
76
75
|
return (jest
|
|
77
76
|
// @ts-expect-error private method
|
|
78
77
|
.spyOn(customer, "paginatedSearch")
|
|
79
78
|
// @ts-expect-error
|
|
80
|
-
.mockImplementation(
|
|
81
|
-
|
|
79
|
+
.mockImplementation((gaqlQuery, requestOptions, _parser) => {
|
|
80
|
+
const totalResultsCount = includeTotalResultsCount
|
|
82
81
|
? exports.mockTotalResultsCount
|
|
83
82
|
: undefined;
|
|
84
83
|
return {
|
|
85
84
|
response: _parser(exports.mockQueryReturnValue),
|
|
86
|
-
totalResultsCount
|
|
85
|
+
totalResultsCount,
|
|
87
86
|
};
|
|
88
87
|
}));
|
|
89
88
|
}
|
|
90
89
|
exports.mockPaginatedSearch = mockPaginatedSearch;
|
|
91
|
-
function mockSearchOnce(
|
|
92
|
-
var customer = _a.customer, response = _a.response, nextPageToken = _a.nextPageToken, includeTotalResultsCount = _a.includeTotalResultsCount;
|
|
90
|
+
function mockSearchOnce({ customer, response, nextPageToken, includeTotalResultsCount, }) {
|
|
93
91
|
return (jest
|
|
94
92
|
// @ts-expect-error private method
|
|
95
93
|
.spyOn(customer, "search")
|
|
96
94
|
// @ts-expect-error
|
|
97
|
-
.mockImplementationOnce(
|
|
95
|
+
.mockImplementationOnce(() => {
|
|
98
96
|
return {
|
|
99
|
-
response
|
|
100
|
-
nextPageToken
|
|
97
|
+
response,
|
|
98
|
+
nextPageToken,
|
|
101
99
|
totalResultsCount: includeTotalResultsCount
|
|
102
100
|
? exports.mockTotalResultsCount
|
|
103
101
|
: undefined,
|
|
@@ -106,52 +104,51 @@ function mockSearchOnce(_a) {
|
|
|
106
104
|
}
|
|
107
105
|
exports.mockSearchOnce = mockSearchOnce;
|
|
108
106
|
function mockBuildSearchStreamRequestAndService(customer) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
const mockStream = new stream_1.Readable({ objectMode: true });
|
|
108
|
+
const mockStreamData = (results) => {
|
|
109
|
+
const chunk = { results };
|
|
112
110
|
mockStream.push(chunk);
|
|
113
111
|
};
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
const mockStreamSummaryRow = () => {
|
|
113
|
+
const chunk = {
|
|
116
114
|
summary_row: exports.mockSummaryRow,
|
|
117
115
|
};
|
|
118
116
|
mockStream.push(chunk);
|
|
119
117
|
};
|
|
120
|
-
|
|
118
|
+
const mockStreamError = (error) => {
|
|
121
119
|
mockStream.destroy(error);
|
|
122
120
|
};
|
|
123
|
-
|
|
121
|
+
const mockStreamEnd = () => {
|
|
124
122
|
mockStream.push(null);
|
|
125
123
|
};
|
|
126
|
-
|
|
124
|
+
const spyBuild = jest
|
|
127
125
|
// @ts-expect-error protected method
|
|
128
126
|
.spyOn(customer, "buildSearchStreamRequestAndService")
|
|
129
127
|
// @ts-expect-error
|
|
130
|
-
.mockImplementation(
|
|
128
|
+
.mockImplementation(() => {
|
|
131
129
|
return {
|
|
132
130
|
service: {
|
|
133
|
-
searchStream:
|
|
131
|
+
searchStream: () => mockStream,
|
|
134
132
|
},
|
|
135
133
|
request: {},
|
|
136
134
|
};
|
|
137
135
|
});
|
|
138
136
|
return {
|
|
139
|
-
spyBuild
|
|
140
|
-
mockStreamData
|
|
141
|
-
mockStreamSummaryRow
|
|
142
|
-
mockStreamError
|
|
143
|
-
mockStreamEnd
|
|
137
|
+
spyBuild,
|
|
138
|
+
mockStreamData,
|
|
139
|
+
mockStreamSummaryRow,
|
|
140
|
+
mockStreamError,
|
|
141
|
+
mockStreamEnd,
|
|
144
142
|
};
|
|
145
143
|
}
|
|
146
144
|
exports.mockBuildSearchStreamRequestAndService = mockBuildSearchStreamRequestAndService;
|
|
147
|
-
function mockBuildSearchRequestAndService(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
search: function () {
|
|
145
|
+
function mockBuildSearchRequestAndService({ customer, shouldThrow = false, includeSummaryRow = false, includeTotalResultsCount = false, }) {
|
|
146
|
+
const mockService = {
|
|
147
|
+
search: () => {
|
|
151
148
|
if (shouldThrow) {
|
|
152
149
|
throw new Error(exports.mockErrorMessage);
|
|
153
150
|
}
|
|
154
|
-
|
|
151
|
+
const searchGoogleAdsResponse = {
|
|
155
152
|
summary_row: includeSummaryRow ? exports.mockSummaryRow : undefined,
|
|
156
153
|
total_results_count: includeTotalResultsCount
|
|
157
154
|
? exports.mockTotalResultsCount
|
|
@@ -160,40 +157,39 @@ function mockBuildSearchRequestAndService(_a) {
|
|
|
160
157
|
return [exports.mockQueryReturnValue, null, searchGoogleAdsResponse];
|
|
161
158
|
},
|
|
162
159
|
};
|
|
163
|
-
|
|
160
|
+
const spyBuild = jest
|
|
164
161
|
// @ts-expect-error protected method
|
|
165
162
|
.spyOn(customer, "buildSearchRequestAndService")
|
|
166
163
|
// @ts-expect-error
|
|
167
|
-
.mockImplementation(
|
|
164
|
+
.mockImplementation(() => {
|
|
168
165
|
return {
|
|
169
166
|
service: mockService,
|
|
170
167
|
request: {},
|
|
171
168
|
};
|
|
172
169
|
});
|
|
173
|
-
return { mockService
|
|
170
|
+
return { mockService, spyBuild };
|
|
174
171
|
}
|
|
175
172
|
exports.mockBuildSearchRequestAndService = mockBuildSearchRequestAndService;
|
|
176
|
-
function mockBuildMutateRequestAndService(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
mutate: function () {
|
|
173
|
+
function mockBuildMutateRequestAndService({ customer, shouldThrow = false, request, response, }) {
|
|
174
|
+
const mockService = {
|
|
175
|
+
mutate() {
|
|
180
176
|
if (shouldThrow) {
|
|
181
177
|
throw new Error(exports.mockErrorMessage);
|
|
182
178
|
}
|
|
183
179
|
return [response !== null && response !== void 0 ? response : exports.mockMutationReturnValue];
|
|
184
180
|
},
|
|
185
181
|
};
|
|
186
|
-
|
|
182
|
+
const spyBuild = jest
|
|
187
183
|
// @ts-expect-error protected method
|
|
188
184
|
.spyOn(customer, "buildMutationRequestAndService")
|
|
189
185
|
// @ts-expect-error
|
|
190
|
-
.mockImplementation(
|
|
186
|
+
.mockImplementation(() => {
|
|
191
187
|
return {
|
|
192
188
|
service: mockService,
|
|
193
189
|
request: request !== null && request !== void 0 ? request : {},
|
|
194
190
|
};
|
|
195
191
|
});
|
|
196
|
-
return { mockService
|
|
192
|
+
return { mockService, spyBuild };
|
|
197
193
|
}
|
|
198
194
|
exports.mockBuildMutateRequestAndService = mockBuildMutateRequestAndService;
|
|
199
195
|
function mockGetGoogleAdsError(customer) {
|
|
@@ -201,7 +197,7 @@ function mockGetGoogleAdsError(customer) {
|
|
|
201
197
|
// @ts-expect-error protected method
|
|
202
198
|
.spyOn(customer, "getGoogleAdsError")
|
|
203
199
|
// @ts-expect-error
|
|
204
|
-
.mockImplementation(
|
|
200
|
+
.mockImplementation(() => exports.mockError));
|
|
205
201
|
}
|
|
206
202
|
exports.mockGetGoogleAdsError = mockGetGoogleAdsError;
|
|
207
203
|
function mockQuery(customer) {
|
|
@@ -209,7 +205,7 @@ function mockQuery(customer) {
|
|
|
209
205
|
// @ts-expect-error private method
|
|
210
206
|
.spyOn(customer, "querier")
|
|
211
207
|
// @ts-expect-error
|
|
212
|
-
.mockImplementation(
|
|
208
|
+
.mockImplementation(() => {
|
|
213
209
|
return {
|
|
214
210
|
response: exports.mockQueryReturnValue,
|
|
215
211
|
totalResultsCount: exports.mockTotalResultsCount,
|
|
@@ -218,7 +214,7 @@ function mockQuery(customer) {
|
|
|
218
214
|
}
|
|
219
215
|
exports.mockQuery = mockQuery;
|
|
220
216
|
function mockParse(mockParsedValues) {
|
|
221
|
-
return jest.spyOn(parser, "parse").mockImplementation(
|
|
217
|
+
return jest.spyOn(parser, "parse").mockImplementation(() => mockParsedValues);
|
|
222
218
|
}
|
|
223
219
|
exports.mockParse = mockParse;
|
|
224
220
|
function noopParser(rows) {
|
|
@@ -227,7 +223,7 @@ function noopParser(rows) {
|
|
|
227
223
|
exports.noopParser = noopParser;
|
|
228
224
|
function mockMethod() {
|
|
229
225
|
return {
|
|
230
|
-
method
|
|
226
|
+
method() {
|
|
231
227
|
return;
|
|
232
228
|
},
|
|
233
229
|
};
|
|
@@ -237,8 +233,7 @@ function failTestIfExecuted() {
|
|
|
237
233
|
expect(true).toBeFalsy();
|
|
238
234
|
}
|
|
239
235
|
exports.failTestIfExecuted = failTestIfExecuted;
|
|
240
|
-
function newCustomer(hooks, disableParsing) {
|
|
241
|
-
if (disableParsing === void 0) { disableParsing = false; }
|
|
236
|
+
function newCustomer(hooks, disableParsing = false) {
|
|
242
237
|
return new customer_1.Customer({
|
|
243
238
|
client_id: exports.MOCK_CLIENT_ID,
|
|
244
239
|
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
|
|
@@ -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.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",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"author": "Opteo",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"google-ads-node": "^
|
|
20
|
+
"google-ads-node": "^9.0.0",
|
|
21
21
|
"google-auth-library": "^7.1.0",
|
|
22
|
-
"google-gax": "^
|
|
22
|
+
"google-gax": "^3.1.1",
|
|
23
23
|
"long": "^4.0.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|