google-ads-api 16.0.0-rest-beta0 → 16.0.0-rest-beta2
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/build/src/client.js +1 -0
- package/build/src/customer.js +15 -15
- package/build/src/hooks.d.ts +23 -23
- package/build/src/protos/autogen/enums.d.ts +2807 -2807
- package/build/src/protos/autogen/enums.js +1 -1
- package/build/src/protos/autogen/fields.js +1 -1
- package/build/src/protos/autogen/resourceNames.d.ts +178 -178
- package/build/src/protos/autogen/serviceFactory.js +1 -1
- package/build/src/protos/index.d.ts +2 -2
- package/build/src/query.d.ts +9 -9
- package/build/src/query.js +1 -1
- package/build/src/service.d.ts +1 -1
- package/build/src/service.js +15 -17
- package/build/src/testUtils.js +2 -2
- package/build/src/types.d.ts +14 -14
- package/package.json +3 -2
package/build/src/client.js
CHANGED
package/build/src/customer.js
CHANGED
|
@@ -13,7 +13,7 @@ const protos_1 = require("./protos");
|
|
|
13
13
|
const serviceFactory_1 = __importDefault(require("./protos/autogen/serviceFactory"));
|
|
14
14
|
const query_1 = require("./query");
|
|
15
15
|
const version_1 = require("./version");
|
|
16
|
-
const ROWS_PER_STREAMED_CHUNK =
|
|
16
|
+
const ROWS_PER_STREAMED_CHUNK = 10_000; // From experience, this is what can be expected from the API.
|
|
17
17
|
/**
|
|
18
18
|
* TODO:
|
|
19
19
|
* - rename querierRest to streamRest. Add hooks support to it. OK
|
|
@@ -31,7 +31,7 @@ const ROWS_PER_STREAMED_CHUNK = 10000; // From experience, this is what can be e
|
|
|
31
31
|
*/
|
|
32
32
|
class Customer extends serviceFactory_1.default {
|
|
33
33
|
constructor(clientOptions, customerOptions, hooks) {
|
|
34
|
-
super(clientOptions, customerOptions, hooks
|
|
34
|
+
super(clientOptions, customerOptions, hooks ?? {});
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
@description Single query using a raw GAQL string.
|
|
@@ -132,7 +132,6 @@ class Customer extends serviceFactory_1.default {
|
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
async search(gaqlQuery, requestOptions) {
|
|
135
|
-
var _a, _b;
|
|
136
135
|
const accessToken = await this.getAccessToken();
|
|
137
136
|
try {
|
|
138
137
|
const rawResponse = await (0, axios_1.default)(this.prepareGoogleAdsServicePostRequestArgs("search", accessToken, {
|
|
@@ -142,7 +141,7 @@ class Customer extends serviceFactory_1.default {
|
|
|
142
141
|
},
|
|
143
142
|
}));
|
|
144
143
|
const searchResponse = rawResponse.data;
|
|
145
|
-
const results =
|
|
144
|
+
const results = searchResponse.results ?? [];
|
|
146
145
|
const response = results.map((row) => this.decamelizeKeysIfNeeded(row));
|
|
147
146
|
const summaryRow = this.decamelizeKeysIfNeeded(searchResponse.summaryRow);
|
|
148
147
|
const nextPageToken = searchResponse.nextPageToken;
|
|
@@ -152,7 +151,7 @@ class Customer extends serviceFactory_1.default {
|
|
|
152
151
|
return { response, nextPageToken, totalResultsCount, summaryRow };
|
|
153
152
|
}
|
|
154
153
|
catch (e) {
|
|
155
|
-
if (
|
|
154
|
+
if (e.response?.data.error.details[0]) {
|
|
156
155
|
throw new protos_1.errors.GoogleAdsFailure(this.decamelizeKeysIfNeeded(e.response.data.error.details[0]));
|
|
157
156
|
}
|
|
158
157
|
throw e;
|
|
@@ -231,7 +230,7 @@ class Customer extends serviceFactory_1.default {
|
|
|
231
230
|
if (summaryRow) {
|
|
232
231
|
foundSummaryRow = this.decamelizeKeysIfNeeded(summaryRow);
|
|
233
232
|
}
|
|
234
|
-
accumulator.push(...(results
|
|
233
|
+
accumulator.push(...(results ?? []).map((row) => {
|
|
235
234
|
return this.decamelizeKeysIfNeeded(row);
|
|
236
235
|
}));
|
|
237
236
|
if (foundSummaryRow) {
|
|
@@ -300,7 +299,6 @@ class Customer extends serviceFactory_1.default {
|
|
|
300
299
|
}
|
|
301
300
|
}
|
|
302
301
|
async *streamer(gaqlQuery, requestOptions = {}, reportOptions) {
|
|
303
|
-
var _a;
|
|
304
302
|
const baseHookArguments = {
|
|
305
303
|
credentials: this.credentials,
|
|
306
304
|
query: gaqlQuery,
|
|
@@ -345,7 +343,7 @@ class Customer extends serviceFactory_1.default {
|
|
|
345
343
|
const pipeline = (0, stream_chain_1.chain)([stream, parser, (0, StreamArray_1.streamArray)()]);
|
|
346
344
|
let count = 0;
|
|
347
345
|
for await (const data of pipeline) {
|
|
348
|
-
const results =
|
|
346
|
+
const results = data.value.results ?? [data.value.summaryRow];
|
|
349
347
|
count += results.length;
|
|
350
348
|
if (this.clientOptions.max_reporting_rows &&
|
|
351
349
|
count > this.clientOptions.max_reporting_rows &&
|
|
@@ -375,17 +373,22 @@ class Customer extends serviceFactory_1.default {
|
|
|
375
373
|
}
|
|
376
374
|
}
|
|
377
375
|
async handleStreamError(e) {
|
|
378
|
-
|
|
379
|
-
if (!((_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
376
|
+
if (!e?.response?.data) {
|
|
380
377
|
throw e;
|
|
381
378
|
}
|
|
382
379
|
// The error is a stream, so some effort is required to parse it.
|
|
383
380
|
const stream = e.response.data;
|
|
384
381
|
const pipeline = (0, stream_chain_1.chain)([stream, (0, stream_json_1.parser)(), (0, StreamArray_1.streamArray)()]);
|
|
385
|
-
|
|
382
|
+
const defaultErrorMessage = "Unknown GoogleAdsFailure";
|
|
383
|
+
let googleAdsFailure = new Error(defaultErrorMessage);
|
|
386
384
|
// Only throw the first error.
|
|
387
385
|
pipeline.once("data", (data) => {
|
|
388
|
-
|
|
386
|
+
if (data?.value?.error?.details?.[0]) {
|
|
387
|
+
googleAdsFailure = new protos_1.errors.GoogleAdsFailure(this.decamelizeKeysIfNeeded(data.value.error.details[0]));
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
googleAdsFailure = new Error(data?.value?.error?.message ?? defaultErrorMessage, { cause: data?.value?.error ?? data?.value });
|
|
391
|
+
}
|
|
389
392
|
});
|
|
390
393
|
// Must always reject.
|
|
391
394
|
await new Promise((_, reject) => {
|
|
@@ -472,15 +475,12 @@ class Customer extends serviceFactory_1.default {
|
|
|
472
475
|
};
|
|
473
476
|
}
|
|
474
477
|
prepareGoogleAdsServicePostRequestArgs(functionName, accessToken, extra) {
|
|
475
|
-
var _a, _b;
|
|
476
478
|
return {
|
|
477
479
|
method: "POST",
|
|
478
480
|
url: `https://googleads.googleapis.com/${version_1.googleAdsVersion}/customers/${this.customerOptions.customer_id}/googleAds:${functionName}`,
|
|
479
481
|
headers: {
|
|
480
482
|
Authorization: `Bearer ${accessToken}`,
|
|
481
483
|
...this.callHeaders,
|
|
482
|
-
"developer-token": (_a = this.clientOptions.developer_token) !== null && _a !== void 0 ? _a : "",
|
|
483
|
-
"login-customer-id": (_b = this.credentials.login_customer_id) !== null && _b !== void 0 ? _b : "",
|
|
484
484
|
},
|
|
485
485
|
...extra,
|
|
486
486
|
};
|
package/build/src/hooks.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { errors, services } from "./protos";
|
|
2
2
|
import { CustomerCredentials, MutateOperation, ReportOptions, RequestOptions, MutateOptions } from "./types";
|
|
3
|
-
export
|
|
3
|
+
export type BaseRequestHookArgs = {
|
|
4
4
|
credentials: CustomerCredentials;
|
|
5
5
|
query: string;
|
|
6
6
|
reportOptions?: ReportOptions;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type BaseMutationHookArgs = {
|
|
9
9
|
credentials: CustomerCredentials;
|
|
10
10
|
method: `${keyof typeof services}.${string}`;
|
|
11
11
|
} & (// Mutation was executed with customer.mutateResources
|
|
@@ -16,37 +16,37 @@ export declare type BaseMutationHookArgs = {
|
|
|
16
16
|
mutation: any;
|
|
17
17
|
isServiceCall: true;
|
|
18
18
|
});
|
|
19
|
-
export
|
|
19
|
+
export type BaseServiceHookArgs = {
|
|
20
20
|
credentials: CustomerCredentials;
|
|
21
21
|
method: `${keyof typeof services}.${string}`;
|
|
22
22
|
requestOptions: any;
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
type StartHookArgs<T = RequestOptions | MutateOptions | any, A = void> = {
|
|
25
25
|
cancel: A extends void ? () => void : (args?: A) => void;
|
|
26
26
|
editOptions: (options: Partial<T>) => void;
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
type ErrorHookArgs = {
|
|
29
29
|
error: errors.GoogleAdsFailure | Error;
|
|
30
30
|
};
|
|
31
|
-
|
|
31
|
+
type EndHookArgs<T = services.IGoogleAdsRow[] | services.MutateGoogleAdsResponse> = {
|
|
32
32
|
response?: T;
|
|
33
33
|
resolve: (args: any) => void;
|
|
34
34
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export
|
|
40
|
-
export
|
|
41
|
-
export
|
|
42
|
-
export
|
|
43
|
-
export
|
|
44
|
-
export
|
|
45
|
-
export
|
|
46
|
-
export
|
|
47
|
-
export
|
|
48
|
-
export
|
|
49
|
-
export
|
|
35
|
+
type HookArgs = StartHookArgs | ErrorHookArgs | EndHookArgs;
|
|
36
|
+
type RequestHook<H extends HookArgs> = (a: BaseRequestHookArgs & H) => void;
|
|
37
|
+
type MutationHook<H extends HookArgs> = (a: BaseMutationHookArgs & H) => void;
|
|
38
|
+
type ServiceHook<H extends HookArgs> = (a: BaseServiceHookArgs & H) => void;
|
|
39
|
+
export type OnQueryStart = RequestHook<StartHookArgs<RequestOptions, any>>;
|
|
40
|
+
export type OnQueryError = RequestHook<ErrorHookArgs>;
|
|
41
|
+
export type OnQueryEnd = RequestHook<EndHookArgs<services.IGoogleAdsRow[]>>;
|
|
42
|
+
export type OnStreamStart = RequestHook<StartHookArgs<RequestOptions, void>>;
|
|
43
|
+
export type OnStreamError = RequestHook<ErrorHookArgs>;
|
|
44
|
+
export type OnMutationStart = MutationHook<StartHookArgs<MutateOptions, any>>;
|
|
45
|
+
export type OnMutationError = MutationHook<ErrorHookArgs>;
|
|
46
|
+
export type OnMutationEnd = MutationHook<EndHookArgs<services.MutateGoogleAdsResponse>>;
|
|
47
|
+
export type OnServiceStart = ServiceHook<StartHookArgs<any, any>>;
|
|
48
|
+
export type OnServiceError = ServiceHook<ErrorHookArgs>;
|
|
49
|
+
export type OnServiceEnd = ServiceHook<EndHookArgs<any>>;
|
|
50
50
|
export interface Hooks {
|
|
51
51
|
/**
|
|
52
52
|
* @description Hook called before execution of a query in the `query` and `report` methods
|
|
@@ -149,11 +149,11 @@ export interface Hooks {
|
|
|
149
149
|
*/
|
|
150
150
|
onServiceEnd?: OnServiceEnd;
|
|
151
151
|
}
|
|
152
|
-
export
|
|
152
|
+
export type HookedCancellation = {
|
|
153
153
|
cancelled: boolean;
|
|
154
154
|
res?: any;
|
|
155
155
|
};
|
|
156
|
-
export
|
|
156
|
+
export type HookedResolution = {
|
|
157
157
|
resolved: boolean;
|
|
158
158
|
res?: any;
|
|
159
159
|
};
|