google-ads-api 23.0.1 → 24.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.
@@ -1,10 +1,10 @@
1
1
  import allProtos, { protos } from "google-ads-node";
2
- export declare const VERSION: "v23";
3
- export import common = protos.google.ads.googleads.v23.common;
4
- export import errors = protos.google.ads.googleads.v23.errors;
5
- export import resources = protos.google.ads.googleads.v23.resources;
6
- export import services = protos.google.ads.googleads.v23.services;
7
- export import internalEnums = protos.google.ads.googleads.v23.enums;
2
+ export declare const VERSION: "v24";
3
+ export import common = protos.google.ads.googleads.v24.common;
4
+ export import errors = protos.google.ads.googleads.v24.errors;
5
+ export import resources = protos.google.ads.googleads.v24.resources;
6
+ export import services = protos.google.ads.googleads.v24.services;
7
+ export import internalEnums = protos.google.ads.googleads.v24.enums;
8
8
  export { enums } from "./autogen/enums";
9
9
  export { fields, fieldDataTypes } from "./autogen/fields";
10
10
  export { GoogleAdsServiceClient } from "google-ads-node";
@@ -7,12 +7,12 @@ const version_1 = require("../version");
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.v23.common;
11
- exports.errors = google_ads_node_1.protos.google.ads.googleads.v23.errors;
12
- exports.resources = google_ads_node_1.protos.google.ads.googleads.v23.resources;
13
- exports.services = google_ads_node_1.protos.google.ads.googleads.v23.services;
10
+ exports.common = google_ads_node_1.protos.google.ads.googleads.v24.common;
11
+ exports.errors = google_ads_node_1.protos.google.ads.googleads.v24.errors;
12
+ exports.resources = google_ads_node_1.protos.google.ads.googleads.v24.resources;
13
+ exports.services = google_ads_node_1.protos.google.ads.googleads.v24.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.v23.enums;
15
+ exports.internalEnums = google_ads_node_1.protos.google.ads.googleads.v24.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");
@@ -2,12 +2,19 @@ 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.v23.errors.googleadsfailure-bin";
5
+ import TTLCache from "@isaacs/ttlcache";
6
+ export declare const FAILURE_KEY = "google.ads.googleads.v24.errors.googleadsfailure-bin";
6
7
  export interface CallHeaders {
7
8
  "developer-token": string;
8
9
  "login-customer-id"?: string;
9
10
  "linked-customer-id"?: string;
10
11
  }
12
+ export declare function disposeService(service: {
13
+ close: () => Promise<void>;
14
+ }): void;
15
+ export declare const serviceCache: TTLCache<unknown, {
16
+ close: () => Promise<void>;
17
+ }>;
11
18
  export declare class Service {
12
19
  protected readonly clientOptions: ClientOptions;
13
20
  protected readonly customerOptions: CustomerOptions;
@@ -17,7 +24,9 @@ export declare class Service {
17
24
  protected get callHeaders(): CallHeaders;
18
25
  private getCredentials;
19
26
  getAccessToken(): Promise<string>;
20
- protected loadService<T = AllServices>(service: ServiceName): T;
27
+ protected loadService<T = AllServices>(service: ServiceName, options?: {
28
+ skipCache?: boolean;
29
+ }): T;
21
30
  protected getGoogleAdsError(error: Error): errors.GoogleAdsFailure | Error;
22
31
  private decodeGoogleAdsFailureBuffer;
23
32
  protected decodePartialFailureError<T>(response: T): T;
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Service = exports.FAILURE_KEY = void 0;
6
+ exports.Service = exports.serviceCache = exports.FAILURE_KEY = void 0;
7
+ exports.disposeService = disposeService;
7
8
  const google_gax_1 = require("google-gax");
8
9
  const google_auth_library_1 = require("google-auth-library");
9
10
  const protos_1 = require("./protos");
@@ -12,14 +13,18 @@ const version_1 = require("./version");
12
13
  const ttlcache_1 = __importDefault(require("@isaacs/ttlcache"));
13
14
  // Make sure to update this version number when upgrading
14
15
  exports.FAILURE_KEY = `google.ads.googleads.${version_1.googleAdsVersion}.errors.googleadsfailure-bin`;
16
+ // Close connections when services are removed from the cache
17
+ function disposeService(service) {
18
+ Promise.resolve()
19
+ .then(() => service.close())
20
+ .catch(() => null);
21
+ }
15
22
  // A global service cache to avoid re-initialising services
16
- const serviceCache = new ttlcache_1.default({
23
+ exports.serviceCache = new ttlcache_1.default({
17
24
  max: 1_000,
18
25
  ttl: 10 * 60 * 1000, // 10 minutes
19
- dispose: async (service) => {
20
- // Close connections when services are removed from the cache
21
- await service.close();
22
- },
26
+ checkAgeOnGet: true,
27
+ dispose: disposeService,
23
28
  });
24
29
  // A global access token cache used by REST calls. Issued tokens expire after 1 hour, so we cache them for 50 minutes.
25
30
  const accessTokenCache = new ttlcache_1.default({
@@ -80,10 +85,13 @@ class Service {
80
85
  accessTokenCache.set(this.customerOptions.refresh_token, token);
81
86
  return token;
82
87
  }
83
- loadService(service) {
88
+ loadService(service, options) {
84
89
  const serviceCacheKey = `${service}_${this.clientOptions.client_id}_${this.customerOptions.refresh_token}`;
85
- if (serviceCache.has(serviceCacheKey)) {
86
- return serviceCache.get(serviceCacheKey);
90
+ if (!options?.skipCache) {
91
+ const cachedService = exports.serviceCache.get(serviceCacheKey);
92
+ if (cachedService) {
93
+ return cachedService;
94
+ }
87
95
  }
88
96
  // eslint-disable-next-line @typescript-eslint/no-var-requires
89
97
  const { [service]: protoService } = require("google-ads-node");
@@ -94,7 +102,9 @@ class Service {
94
102
  const client = new protoService({
95
103
  sslCreds: this.getCredentials(),
96
104
  });
97
- serviceCache.set(serviceCacheKey, client);
105
+ if (!options?.skipCache) {
106
+ exports.serviceCache.set(serviceCacheKey, client);
107
+ }
98
108
  return client;
99
109
  }
100
110
  getGoogleAdsError(error) {
@@ -45,5 +45,5 @@ export declare function toCamelCase(str: string): string;
45
45
  * const snakeCaseString = toSnakeCase("adGroupCriterionSimulation") // "ad_group_criterion_simulation"
46
46
  */
47
47
  export declare function toSnakeCase(str: string): string;
48
- export declare function recursiveFieldMaskSearch(data: Record<string, any>): string[];
48
+ export declare function recursiveFieldMaskSearch(data: Record<string, any>, ancestors?: Set<object>): string[];
49
49
  export declare function getFieldMask(data: Record<string, any>): protobuf.FieldMask;
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fromMicros = fromMicros;
4
7
  exports.toMicros = toMicros;
@@ -8,6 +11,7 @@ exports.toCamelCase = toCamelCase;
8
11
  exports.toSnakeCase = toSnakeCase;
9
12
  exports.recursiveFieldMaskSearch = recursiveFieldMaskSearch;
10
13
  exports.getFieldMask = getFieldMask;
14
+ const long_1 = __importDefault(require("long"));
11
15
  const protos_1 = require("./protos");
12
16
  /**
13
17
  * @param micros Money value in micros format
@@ -73,7 +77,13 @@ function toSnakeCase(str) {
73
77
  .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
74
78
  .toLowerCase();
75
79
  }
76
- function recursiveFieldMaskSearch(data) {
80
+ function recursiveFieldMaskSearch(data,
81
+ // eslint-disable-next-line @typescript-eslint/ban-types
82
+ ancestors = new Set()) {
83
+ if (ancestors.has(data)) {
84
+ throw new Error("Cannot build a field mask from an object containing a circular reference");
85
+ }
86
+ ancestors.add(data);
77
87
  const paths = [];
78
88
  for (const key of Object.keys(data)) {
79
89
  if (key === "resourceName") {
@@ -81,12 +91,16 @@ function recursiveFieldMaskSearch(data) {
81
91
  }
82
92
  const fieldKey = toSnakeCase(key);
83
93
  const value = data[key];
84
- if (typeof value === "object" && !Array.isArray(value) && value !== null) {
94
+ if (typeof value === "object" &&
95
+ !Array.isArray(value) &&
96
+ !ArrayBuffer.isView(value) &&
97
+ !long_1.default.isLong(value) &&
98
+ value !== null) {
85
99
  if (Object.keys(value).length === 0) {
86
100
  paths.push(fieldKey);
87
101
  }
88
102
  else {
89
- const children = recursiveFieldMaskSearch(value);
103
+ const children = recursiveFieldMaskSearch(value, ancestors);
90
104
  for (const child of children) {
91
105
  paths.push(`${fieldKey}.${child}`);
92
106
  }
@@ -95,6 +109,7 @@ function recursiveFieldMaskSearch(data) {
95
109
  }
96
110
  paths.push(fieldKey);
97
111
  }
112
+ ancestors.delete(data);
98
113
  return paths;
99
114
  }
100
115
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1 +1 @@
1
- export declare const googleAdsVersion = "v23";
1
+ export declare const googleAdsVersion = "v24";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.googleAdsVersion = void 0;
4
- exports.googleAdsVersion = "v23";
4
+ exports.googleAdsVersion = "v24";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "google-ads-api",
3
- "version": "23.0.1",
3
+ "version": "24.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",
@@ -18,12 +18,12 @@
18
18
  "author": "Opteo",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@isaacs/ttlcache": "^1.2.2",
21
+ "@isaacs/ttlcache": "^1.4.0",
22
22
  "axios": "^1.6.7",
23
23
  "circ-json": "^1.0.4",
24
- "google-ads-node": "23.0.0",
24
+ "google-ads-node": "24.1.0",
25
25
  "google-auth-library": "^9.15.1",
26
- "google-gax": "^5.0.6",
26
+ "google-gax": "^5.0.7",
27
27
  "long": "^4.0.0",
28
28
  "stream-json": "^1.8.0"
29
29
  },