@google-cloud/nodejs-common 2.0.4-alpha → 2.0.6-alpha

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google-cloud/nodejs-common",
3
- "version": "2.0.4-alpha",
3
+ "version": "2.0.6-alpha",
4
4
  "description": "A NodeJs common library for solutions based on Cloud Functions",
5
5
  "author": "Google Inc.",
6
6
  "license": "Apache-2.0",
@@ -16,23 +16,24 @@
16
16
  },
17
17
  "homepage": "https://github.com/GoogleCloudPlatform/cloud-for-marketing/blob/master/marketing-analytics/activation/common-libs/nodejs-common/README.md",
18
18
  "dependencies": {
19
- "@google-cloud/aiplatform": "^3.0.0",
20
- "@google-cloud/automl": "^4.0.0",
21
- "@google-cloud/bigquery": "^7.2.0",
22
- "@google-cloud/datastore": "^8.2.2",
23
- "@google-cloud/firestore": "^6.7.0",
19
+ "@google-cloud/aiplatform": "^3.10.0",
20
+ "@google-cloud/automl": "^4.0.1",
21
+ "@google-cloud/bigquery": "^7.3.0",
22
+ "@google-cloud/datastore": "^8.4.0",
23
+ "@google-cloud/firestore": "^7.2.0",
24
24
  "@google-cloud/logging-winston": "^6.0.0",
25
- "@google-cloud/pubsub": "^4.0.2",
26
- "@google-cloud/storage": "^7.0.1",
27
- "@google-cloud/scheduler": "^4.0.0",
28
- "@google-cloud/secret-manager": "^5.0.0",
29
- "gaxios": "^6.1.0",
25
+ "@google-cloud/pubsub": "^4.1.1",
26
+ "@google-cloud/storage": "^7.7.0",
27
+ "@google-cloud/scheduler": "^4.0.1",
28
+ "@google-cloud/secret-manager": "^5.0.1",
29
+ "gaxios": "^6.1.1",
30
+ "google-ads-nodejs-client": "15.0.0",
30
31
  "google-ads-api": "^14.1.0",
31
32
  "google-ads-node": "^12.0.2",
32
- "google-auth-library": "^9.0.0",
33
- "googleapis": "^126.0.1",
33
+ "google-auth-library": "^9.4.2",
34
+ "googleapis": "^131.0.0",
34
35
  "winston": "^3.10.0",
35
- "@grpc/grpc-js": "1.9.5",
36
+ "@grpc/grpc-js": "1.9.14",
36
37
  "lodash": "^4.17.21"
37
38
  },
38
39
  "devDependencies": {
@@ -67,7 +67,7 @@ class Analytics {
67
67
  }
68
68
 
69
69
  /**
70
- * Prepares the Google Analytics instace.
70
+ * Prepares the Google Analytics instance.
71
71
  * @return {!google.analytics}
72
72
  * @private
73
73
  */
@@ -21,7 +21,13 @@
21
21
 
22
22
  const fs = require('fs');
23
23
  const path = require('path');
24
- const {GoogleAuth, OAuth2Client, JWT, Compute} = require('google-auth-library');
24
+ const {
25
+ GoogleAuth,
26
+ OAuth2Client,
27
+ UserRefreshClient,
28
+ JWT,
29
+ Compute,
30
+ } = require('google-auth-library');
25
31
  const { SecretManager } = require('../components/secret_manager.js');
26
32
  const { getLogger } = require('../components/utils.js');
27
33
 
@@ -77,6 +83,7 @@ class AuthClient {
77
83
  this.logger = getLogger('AUTH');
78
84
  this.scopes = scopes;
79
85
  this.env = Object.assign({}, process.env, overwrittenEnv);
86
+ this.initialized = false;
80
87
  }
81
88
 
82
89
  /**
@@ -88,6 +95,10 @@ class AuthClient {
88
95
  * and service account key file if there is no secret name was set in the env.
89
96
  */
90
97
  async prepareCredentials() {
98
+ if (this.initialized === true) {
99
+ this.logger.info(`This authClient has been initialized.`);
100
+ return;
101
+ }
91
102
  if (this.env[DEFAULT_ENV_SECRET]) {
92
103
  const secretmanager = new SecretManager({
93
104
  projectId: this.env.GCP_PROJECT,
@@ -95,26 +106,24 @@ class AuthClient {
95
106
  const secret = await secretmanager.access(this.env[DEFAULT_ENV_SECRET]);
96
107
  if (secret) {
97
108
  const secretObj = JSON.parse(secret);
98
- if (secretObj.token) {
99
- this.oauthToken = secretObj;
100
- } else {
101
- this.serviceAccountKey = secretObj;
102
- }
109
+ if (secretObj.token) this.oauthToken = secretObj;
110
+ else this.serviceAccountKey = secretObj;
103
111
  this.logger.info(`Get secret from SM ${this.env[DEFAULT_ENV_SECRET]}.`);
104
- return;
112
+ } else {
113
+ this.logger.warn(`Cannot find SM ${this.env[DEFAULT_ENV_SECRET]}.`);
114
+ }
115
+ } else {// To be compatible with previous solution.
116
+ const oauthTokenFile = this.getContentFromEnvVar(DEFAULT_ENV_OAUTH);
117
+ if (oauthTokenFile) {
118
+ this.oauthToken = JSON.parse(oauthTokenFile);
119
+ }
120
+ const serviceAccountKeyFile =
121
+ this.getContentFromEnvVar(DEFAULT_ENV_KEYFILE);
122
+ if (serviceAccountKeyFile) {
123
+ this.serviceAccountKey = JSON.parse(serviceAccountKeyFile);
105
124
  }
106
- this.logger.warn(`Cannot find SM ${this.env[DEFAULT_ENV_SECRET]}.`);
107
- }
108
- // To be compatible with previous solution.
109
- const oauthTokenFile = this.getContentFromEnvVar(DEFAULT_ENV_OAUTH);
110
- if (oauthTokenFile) {
111
- this.oauthToken = JSON.parse(oauthTokenFile);
112
- }
113
- const serviceAccountKeyFile =
114
- this.getContentFromEnvVar(DEFAULT_ENV_KEYFILE);
115
- if (serviceAccountKeyFile) {
116
- this.serviceAccountKey = JSON.parse(serviceAccountKeyFile);
117
125
  }
126
+ this.initialized = true;
118
127
  }
119
128
 
120
129
  /**
@@ -137,7 +146,7 @@ class AuthClient {
137
146
  * 1. OAuth, return an OAuth token if available.
138
147
  * 2. JWT, return JWT client if a service account key is available.
139
148
  * 3. ADC if none of these files exists.
140
- * @return {!OAuth2Client|!JWT|!Compute}
149
+ * @return {!UserRefreshClient|!JWT|!Compute}
141
150
  */
142
151
  getDefaultAuth() {
143
152
  if (typeof this.oauthToken !== 'undefined') {
@@ -167,13 +176,14 @@ class AuthClient {
167
176
 
168
177
  /**
169
178
  * Returns an OAuth2 client based on the given key file.
170
- * @return {!OAuth2Client}
179
+ * @return {!UserRefreshClient}
171
180
  */
172
181
  getOAuth2Client() {
173
182
  this.ensureCredentialExists_(this.oauthToken, 'OAuth token');
174
- const { client_id, client_secret, token } = this.oauthToken;
175
- const oAuth2Client = new OAuth2Client(client_id, client_secret);
176
- oAuth2Client.setCredentials({ refresh_token: token.refresh_token });
183
+ const { client_id, client_secret, token: { refresh_token } }
184
+ = this.oauthToken;
185
+ const oAuth2Client =
186
+ new UserRefreshClient(client_id, client_secret, refresh_token);
177
187
  return oAuth2Client;
178
188
  }
179
189
 
@@ -31,7 +31,7 @@ const {
31
31
  const API_SCOPES = Object.freeze([
32
32
  'https://www.googleapis.com/auth/display-video',
33
33
  ]);
34
- const API_VERSION = 'v2';
34
+ const API_VERSION = 'v3';
35
35
 
36
36
  /**
37
37
  * Display and Video 360 API v2 stub.
@@ -370,7 +370,9 @@ class DoubleClickSearch {
370
370
  const doubleclicksearch = await this.getApiClient_();
371
371
  const response = await doubleclicksearch.reports.getFile(
372
372
  {reportId, reportFragment});
373
- if (response.status === 200) return response.data;
373
+ if (response.status === 200) {
374
+ return Buffer.from(await response.data.arrayBuffer()).toString();
375
+ }
374
376
  const errorMsg =
375
377
  `Error in get file from reports: ${reportFragment}@${reportId}`;
376
378
  this.logger.error(errorMsg, response);
@@ -96,6 +96,7 @@ const PICKED_PROPERTIES = [
96
96
  'adjustment_date_time',
97
97
  'user_agent',
98
98
  'gclid_date_time_pair',
99
+ 'consent',
99
100
  ];
100
101
 
101
102
  /**