@google-cloud/nodejs-common 2.4.4 → 2.5.0-rc.1

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 CHANGED
@@ -40,9 +40,11 @@ and [Data Tasks Coordinator]. This library includes:
40
40
  interface to operate data objects within or not a transaction on either
41
41
  Firestore Native mode or Firestore Datastore mode.
42
42
 
43
- - **AutoMl Tables API**: Offers a unified entry to use this API based on
43
+ - ~~**AutoMl Tables API**: Offers a unified entry to use this API based on
44
44
  Google Cloud client library combined with REST requests to service
45
- directly due to some functionalities missed in the client library.
45
+ directly due to some functionalities missed in the client library.~~(Google
46
+ Cloud AutoML Tables was retired on April 30, 2024. Please migrate to Vertex
47
+ AI instead.)
46
48
 
47
49
  - **Vertex AI API**: Offers a unified entry to use this API based on Google
48
50
  Cloud client library.
@@ -1553,7 +1553,6 @@ set_cloud_functions_default_settings() {
1553
1553
  local -n default_cf_flag=$1
1554
1554
  default_cf_flag+=(--region="${REGION}")
1555
1555
  default_cf_flag+=(--no-allow-unauthenticated)
1556
- default_cf_flag+=(--docker-registry=artifact-registry)
1557
1556
  default_cf_flag+=(--timeout=540 --memory="${CF_MEMORY}" --runtime="${CF_RUNTIME}")
1558
1557
  default_cf_flag+=(--set-env-vars=GCP_PROJECT="${GCP_PROJECT}")
1559
1558
  default_cf_flag+=(--set-env-vars=PROJECT_NAMESPACE="${PROJECT_NAMESPACE}")
package/index.js CHANGED
@@ -20,7 +20,6 @@
20
20
 
21
21
  exports.api = require('./src/apis/index.js');
22
22
  exports.cloudfunctions = require('./src/components/cloudfunctions_utils.js');
23
- exports.automl = require('./src/components/automl.js');
24
23
  exports.firestore = require('./src/components/firestore/index.js');
25
24
  exports.pubsub = require('./src/components/pubsub.js');
26
25
  exports.scheduler = require('./src/components/scheduler.js');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google-cloud/nodejs-common",
3
- "version": "2.4.4",
3
+ "version": "2.5.0-rc.1",
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,20 +16,20 @@
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.35.0",
20
- "@google-cloud/automl": "4.0.1",
21
- "@google-cloud/bigquery": "^7.9.4",
19
+ "@google-cloud/aiplatform": "^4.2.0",
20
+ "@google-cloud/bigquery": "^8.1.0",
22
21
  "@google-cloud/datastore": "^9.2.1",
23
- "@google-cloud/firestore": "^7.11.0",
24
- "@google-cloud/logging-winston": "^6.0.0",
25
- "@google-cloud/pubsub": "4.11.0",
26
- "@google-cloud/secret-manager": "5.6.0",
27
- "@google-cloud/scheduler": "4.3.0",
22
+ "@google-cloud/firestore": "^7.11.1",
23
+ "@google-cloud/logging-winston": "^6.0.1",
24
+ "@google-cloud/pubsub": "^5.1.0",
25
+ "@google-cloud/scheduler": "^5.2.0",
26
+ "@google-cloud/secret-manager": "^6.0.1",
28
27
  "@google-cloud/storage": "^7.16.0",
29
- "@grpc/grpc-js": "^1.13.3",
30
- "gaxios": "^6.7.1",
31
- "google-ads-nodejs-client": "18.0.1",
32
- "googleapis": "^148.0.0",
28
+ "@grpc/grpc-js": "^1.13.4",
29
+ "gaxios": "^7.0.0",
30
+ "google-ads-nodejs-client": "^20.0.0",
31
+ "google-auth-library": "^10.0.0",
32
+ "googleapis": "^150.0.1",
33
33
  "lodash": "^4.17.21",
34
34
  "winston": "^3.17.0"
35
35
  },
@@ -62,8 +62,10 @@ class AuthRestfulApi extends RestfulApiBase {
62
62
  */
63
63
  async getDefaultHeaders() {
64
64
  const auth = await this.getAuth();
65
- const headers = await auth.getRequestHeaders();
66
- return Object.assign({}, super.getDefaultHeaders(), headers);
65
+ const authHeaders = await auth.getRequestHeaders();
66
+ const mergedHeaders = new Headers(await super.getDefaultHeaders());
67
+ authHeaders.forEach((value, key) => void mergedHeaders.set(key, value));
68
+ return mergedHeaders;
67
69
  }
68
70
 
69
71
  }
@@ -53,10 +53,10 @@ class RestfulApiBase {
53
53
 
54
54
  /**
55
55
  * Returns default HTTP headers.
56
- * @return {object} HTTP headers.
56
+ * @return {!Headers} HTTP headers.
57
57
  */
58
58
  async getDefaultHeaders() {
59
- return {};
59
+ return new Headers();
60
60
  }
61
61
 
62
62
  /**
@@ -33,6 +33,7 @@ const {
33
33
  UserListServiceClient,
34
34
  protos: { google: { ads: { googleads } } },
35
35
  } = require('google-ads-nodejs-client');
36
+ const { AuthRestfulApi } = require('./base/auth_restful_api.js');
36
37
 
37
38
  const API_VERSION = Object.keys(googleads)[0];
38
39
  const {
@@ -335,24 +336,30 @@ let CustomerMatchRecord;
335
336
  /**
336
337
  * Google Ads API class based on Google Ads API library.
337
338
  */
338
- class GoogleAdsApi {
339
+ class GoogleAdsApi extends AuthRestfulApi {
339
340
  /**
340
341
  * Note: Rate limits is set by the access level of Developer token.
341
- * @param {string} developerToken Developer token to access the API.
342
- * @param {boolean=} debugMode This is used to set ONLY validate conversions
343
- * but not real uploading.
344
342
  * @param {!Object<string,string>=} env The environment object to hold env
345
343
  * variables.
344
+ * @param {object} options
345
+ * @param {string} options.developerToken Developer token to access the API.
346
+ * @param {boolean} options.debugMode This is used to set ONLY validate
347
+ * conversions but not real uploading.
346
348
  */
347
- constructor(developerToken, debugMode = false, env = process.env) {
348
- this.developerToken = developerToken;
349
- this.debugMode = debugMode;
350
- this.authClient = new AuthClient(API_SCOPES, env);
349
+ constructor(env = process.env, options = {}) {
350
+ super(env, options);
351
+ this.developerToken = options.developerToken;
352
+ this.debugMode = options.debugMode || false;
351
353
  this.logger = getLogger('API.ADS.N');
352
354
  this.logger.info(
353
355
  `Init ${this.constructor.name} with Debug Mode?`, this.debugMode);
354
356
  }
355
357
 
358
+ /** @override */
359
+ getScope() {
360
+ return API_SCOPES;
361
+ }
362
+
356
363
  /**
357
364
  * Gets a Google Ads report based on a Google Ads Query Language(GAQL) query
358
365
  * with pagination automatically handled. It returns an array of
@@ -486,11 +493,9 @@ class GoogleAdsApi {
486
493
  * @return {!Promise<stream>}
487
494
  */
488
495
  async restStreamReport(customerId, loginCustomerId, query) {
489
- await this.authClient.prepareCredentials();
490
- const headers = Object.assign(
491
- await this.authClient.getDefaultAuth().getRequestHeaders(),
492
- this.getGoogleAdsHeaders_(loginCustomerId)
493
- );
496
+ const headers = await this.getDefaultHeaders();
497
+ const extra = new Headers(this.getGoogleAdsHeaders_(loginCustomerId));
498
+ extra.forEach((value, key) => void headers.set(key, value));
494
499
  const options = {
495
500
  baseURL: `${API_ENDPOINT}/${API_VERSION}/`,
496
501
  url: `customers/${getCleanCid(customerId)}/googleAds:searchStream`,
@@ -1332,12 +1337,17 @@ class GoogleAdsApi {
1332
1337
  /**
1333
1338
  * Returns a HTTP header object contains the authentication information for
1334
1339
  * Google Ads API, include: `developer-token` and `login-customer-id`.
1340
+ * `grpc` only takes plain objects as valid values of the object `otherArgs`,
1341
+ * so here can not use 'Headers' type yet.
1335
1342
  * @param {string} loginCustomerId
1336
1343
  * @return {object} The HTTP header object.
1337
1344
  * @private
1338
1345
  */
1339
1346
  getGoogleAdsHeaders_(loginCustomerId) {
1340
- const headers = { 'developer-token': this.developerToken };
1347
+ const headers = {};
1348
+ if (this.developerToken) {
1349
+ headers['developer-token'] = this.developerToken;
1350
+ }
1341
1351
  if (loginCustomerId) {
1342
1352
  headers['login-customer-id'] = getCleanCid(loginCustomerId);
1343
1353
  }
@@ -1366,9 +1376,8 @@ class GoogleAdsApi {
1366
1376
  */
1367
1377
  async getGoogleAdsServiceClient_() {
1368
1378
  if (this.googleAdsClient) return this.googleAdsClient;
1369
- await this.authClient.prepareCredentials();
1370
1379
  this.googleAdsClient = new GoogleAdsServiceClient({
1371
- authClient: this.authClient.getDefaultAuth(),
1380
+ authClient: await this.getAuth(),
1372
1381
  });
1373
1382
  return this.googleAdsClient;
1374
1383
  }
@@ -1379,9 +1388,8 @@ class GoogleAdsApi {
1379
1388
  * @private
1380
1389
  */
1381
1390
  async getGoogleAdsFieldServiceClient_() {
1382
- await this.authClient.prepareCredentials();
1383
1391
  return new GoogleAdsFieldServiceClient({
1384
- authClient: this.authClient.getDefaultAuth(),
1392
+ authClient: await this.getAuth(),
1385
1393
  });
1386
1394
  }
1387
1395
 
@@ -1391,9 +1399,8 @@ class GoogleAdsApi {
1391
1399
  * @private
1392
1400
  */
1393
1401
  async getConversionUploadServiceClient_() {
1394
- await this.authClient.prepareCredentials();
1395
1402
  return new ConversionUploadServiceClient({
1396
- authClient: this.authClient.getDefaultAuth(),
1403
+ authClient: await this.getAuth(),
1397
1404
  });
1398
1405
  }
1399
1406
 
@@ -1403,9 +1410,8 @@ class GoogleAdsApi {
1403
1410
  * @private
1404
1411
  */
1405
1412
  async getConversionAdjustmentUploadServiceClient_() {
1406
- await this.authClient.prepareCredentials();
1407
1413
  return new ConversionAdjustmentUploadServiceClient({
1408
- authClient: this.authClient.getDefaultAuth(),
1414
+ authClient: await this.getAuth(),
1409
1415
  });
1410
1416
  }
1411
1417
 
@@ -1415,9 +1421,8 @@ class GoogleAdsApi {
1415
1421
  * @private
1416
1422
  */
1417
1423
  async getUserListServiceClient_() {
1418
- await this.authClient.prepareCredentials();
1419
1424
  return new UserListServiceClient({
1420
- authClient: this.authClient.getDefaultAuth(),
1425
+ authClient: await this.getAuth(),
1421
1426
  });
1422
1427
  }
1423
1428
 
@@ -1427,9 +1432,8 @@ class GoogleAdsApi {
1427
1432
  * @private
1428
1433
  */
1429
1434
  async getUserDataServiceClient_() {
1430
- await this.authClient.prepareCredentials();
1431
1435
  return new UserDataServiceClient({
1432
- authClient: this.authClient.getDefaultAuth(),
1436
+ authClient: await this.getAuth(),
1433
1437
  });
1434
1438
  }
1435
1439
 
@@ -1439,9 +1443,8 @@ class GoogleAdsApi {
1439
1443
  * @private
1440
1444
  */
1441
1445
  async getOfflineUserDataJobServiceClient_() {
1442
- await this.authClient.prepareCredentials();
1443
1446
  return new OfflineUserDataJobServiceClient({
1444
- authClient: this.authClient.getDefaultAuth(),
1447
+ authClient: await this.getAuth(),
1445
1448
  });
1446
1449
  }
1447
1450
  }
@@ -19,7 +19,6 @@
19
19
  'use strict';
20
20
 
21
21
  const { request: gaxiosRequest } = require('gaxios');
22
- const { google } = require('googleapis');
23
22
  const { GoogleApiClient } = require('./base/google_api_client.js');
24
23
  const { changeStringToBigQuerySafe, getLogger }
25
24
  = require('../components/utils.js');
@@ -119,11 +118,8 @@ class SearchAds extends GoogleApiClient {
119
118
  * @see https://developers.google.com/search-ads/reporting/api/reference/rest/search
120
119
  */
121
120
  async restStreamReport(customerId, loginCustomerId, query) {
122
- const auth = await this.getAuth();
123
- const headers = Object.assign(
124
- await auth.getRequestHeaders(), {
125
- 'login-customer-id': getCleanCid(loginCustomerId),
126
- });
121
+ const headers = await this.getDefaultHeaders();
122
+ headers.set('login-customer-id', getCleanCid(loginCustomerId));
127
123
  const options = {
128
124
  baseURL: `${API_ENDPOINT}/${API_VERSION}/`,
129
125
  url: `customers/${getCleanCid(customerId)}/searchAds360:searchStream`,
@@ -64,11 +64,18 @@ class SendGrid extends RestfulApiBase {
64
64
 
65
65
  /** @override */
66
66
  async getDefaultHeaders() {
67
- return Object.assign({}, super.getDefaultHeaders(), {
68
- Authorization: `Bearer ${this.apiKey}`,
69
- });
67
+ const headers = await super.getDefaultHeaders();
68
+ headers.set('Authorization', `Bearer ${this.apiKey}`);
69
+ return headers;
70
70
  }
71
71
 
72
+ /**
73
+ * No responseType is required for empty body response.
74
+ * @override
75
+ */
76
+ getRequesterOptions() {
77
+ return {};
78
+ }
72
79
  /**
73
80
  * Generates an email object for Sendgrid.
74
81
  * @param {!EmailOptions} options
@@ -1,103 +0,0 @@
1
- // Copyright 2019 Google Inc.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- /**
16
- * @fileoverview Google Cloud AutoML helper.
17
- */
18
-
19
- 'use strict';
20
- const { ClientOptions } = require('google-gax');
21
- const automl = require('@google-cloud/automl');
22
- const google = automl.protos.google;
23
-
24
- /**
25
- * For version `v1beta1`, BigQuery can be the source and destination.
26
- * https://googleapis.dev/nodejs/automl/latest/google.cloud.automl.v1beta1.IBatchPredictInputConfig.html
27
- * https://googleapis.dev/nodejs/automl/latest/google.cloud.automl.v1beta1.IBatchPredictOutputConfig.html
28
- *
29
- * For version `v1`, currently only Cloud Storage are allowed.
30
- * https://googleapis.dev/nodejs/automl/latest/google.cloud.automl.v1.IBatchPredictInputConfig.html
31
- * https://googleapis.dev/nodejs/automl/latest/google.cloud.automl.v1.IBatchPredictOutputConfig.html
32
- *
33
- * NOTE: currently use `v1beta1`
34
- * @type {string}
35
- */
36
- const API_VERSION = 'v1beta1';
37
- const { PredictionServiceClient } = automl[API_VERSION];
38
-
39
- /**
40
- * AutoML Tables API class for:
41
- * 1. start a batch predict job:
42
- * @see https://cloud.google.com/nodejs/docs/reference/automl/latest/automl/v1beta1.predictionserviceclient#_google_cloud_automl_v1beta1_PredictionServiceClient_batchPredict_member_3_
43
- * 2. get the status of an operation:
44
- * @see https://cloud.google.com/nodejs/docs/reference/automl/latest/automl/v1beta1.predictionserviceclient#_google_cloud_automl_v1beta1_PredictionServiceClient_checkBatchPredictProgress_member_1_
45
- */
46
- class AutoMl {
47
- /**
48
- * Initialize an instance.
49
- * @param {ClientOptions=} options
50
- */
51
- constructor(options = {}) {
52
- this.client = new PredictionServiceClient(options);
53
- }
54
-
55
- /**
56
- * Batch predicts based on Google Cloud Client Library.
57
- * @param {string} projectId
58
- * @param {string} computeRegion
59
- * @param {string} modelId
60
- * @param {google.cloud.automl.v1beta1.IBatchPredictInputConfig} inputConfig
61
- * @param {google.cloud.automl.v1beta1.IBatchPredictOutputConfig} outputConfig
62
- * @return {Promise<string>} Predict operation name.
63
- */
64
- async batchPredict(
65
- projectId,
66
- computeRegion,
67
- modelId,
68
- inputConfig,
69
- outputConfig
70
- ) {
71
- const modelFullId = this.client.modelPath(
72
- projectId,
73
- computeRegion,
74
- modelId
75
- );
76
- const responses = await this.client.batchPredict({
77
- name: modelFullId,
78
- inputConfig,
79
- outputConfig,
80
- });
81
- const operation = responses[1];
82
- console.log(`Operation name: ${operation.name}`);
83
- return operation.name;
84
- }
85
-
86
- /**
87
- * Gets status of an operation.
88
- * @param {string} operationName
89
- * @return {Promise<{{
90
- * done: boolean,
91
- * error: Error|undefined,
92
- * metadata: OperationMetadata,
93
- * name: string,
94
- * }}>}
95
- */
96
- async getOperation(operationName) {
97
- const response = await this.client.checkBatchPredictProgress(operationName);
98
- const { done, error, metadata, name } = response;
99
- return { done, error, metadata, name };
100
- }
101
- }
102
-
103
- exports.AutoMl = AutoMl;