@google-cloud/nodejs-common 2.4.4 → 2.5.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 +4 -2
- package/bin/install_functions.sh +0 -1
- package/index.js +0 -1
- package/package.json +13 -13
- package/src/apis/base/auth_restful_api.js +4 -2
- package/src/apis/base/restful_api_base.js +2 -2
- package/src/apis/google_ads_api.js +34 -28
- package/src/apis/search_ads.js +2 -6
- package/src/apis/sendgrid.js +10 -3
- package/src/components/automl.js +0 -103
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
|
-
-
|
|
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.
|
package/bin/install_functions.sh
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "2.5.0",
|
|
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": "
|
|
20
|
-
"@google-cloud/
|
|
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.
|
|
24
|
-
"@google-cloud/logging-winston": "^6.0.
|
|
25
|
-
"@google-cloud/pubsub": "
|
|
26
|
-
"@google-cloud/
|
|
27
|
-
"@google-cloud/
|
|
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.
|
|
30
|
-
"gaxios": "^
|
|
31
|
-
"google-ads-nodejs-client": "
|
|
32
|
-
"
|
|
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
|
|
66
|
-
|
|
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
|
}
|
|
@@ -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 {
|
|
@@ -143,6 +144,9 @@ CONVERSION_FIELDS.CLICK = [
|
|
|
143
144
|
'conversionValue',
|
|
144
145
|
'currencyCode',
|
|
145
146
|
'orderId',
|
|
147
|
+
'userIpAddress',
|
|
148
|
+
'sessionAttributesEncoded',
|
|
149
|
+
'sessionAttributesKeyValuePairs',
|
|
146
150
|
];
|
|
147
151
|
/**
|
|
148
152
|
* @see ConversionAdjustment
|
|
@@ -335,24 +339,30 @@ let CustomerMatchRecord;
|
|
|
335
339
|
/**
|
|
336
340
|
* Google Ads API class based on Google Ads API library.
|
|
337
341
|
*/
|
|
338
|
-
class GoogleAdsApi {
|
|
342
|
+
class GoogleAdsApi extends AuthRestfulApi {
|
|
339
343
|
/**
|
|
340
344
|
* 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
345
|
* @param {!Object<string,string>=} env The environment object to hold env
|
|
345
346
|
* variables.
|
|
347
|
+
* @param {object} options
|
|
348
|
+
* @param {string} options.developerToken Developer token to access the API.
|
|
349
|
+
* @param {boolean} options.debugMode This is used to set ONLY validate
|
|
350
|
+
* conversions but not real uploading.
|
|
346
351
|
*/
|
|
347
|
-
constructor(
|
|
348
|
-
|
|
349
|
-
this.
|
|
350
|
-
this.
|
|
352
|
+
constructor(env = process.env, options = {}) {
|
|
353
|
+
super(env, options);
|
|
354
|
+
this.developerToken = options.developerToken;
|
|
355
|
+
this.debugMode = options.debugMode || false;
|
|
351
356
|
this.logger = getLogger('API.ADS.N');
|
|
352
357
|
this.logger.info(
|
|
353
358
|
`Init ${this.constructor.name} with Debug Mode?`, this.debugMode);
|
|
354
359
|
}
|
|
355
360
|
|
|
361
|
+
/** @override */
|
|
362
|
+
getScope() {
|
|
363
|
+
return API_SCOPES;
|
|
364
|
+
}
|
|
365
|
+
|
|
356
366
|
/**
|
|
357
367
|
* Gets a Google Ads report based on a Google Ads Query Language(GAQL) query
|
|
358
368
|
* with pagination automatically handled. It returns an array of
|
|
@@ -486,11 +496,9 @@ class GoogleAdsApi {
|
|
|
486
496
|
* @return {!Promise<stream>}
|
|
487
497
|
*/
|
|
488
498
|
async restStreamReport(customerId, loginCustomerId, query) {
|
|
489
|
-
await this.
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
this.getGoogleAdsHeaders_(loginCustomerId)
|
|
493
|
-
);
|
|
499
|
+
const headers = await this.getDefaultHeaders();
|
|
500
|
+
const extra = new Headers(this.getGoogleAdsHeaders_(loginCustomerId));
|
|
501
|
+
extra.forEach((value, key) => void headers.set(key, value));
|
|
494
502
|
const options = {
|
|
495
503
|
baseURL: `${API_ENDPOINT}/${API_VERSION}/`,
|
|
496
504
|
url: `customers/${getCleanCid(customerId)}/googleAds:searchStream`,
|
|
@@ -1332,12 +1340,17 @@ class GoogleAdsApi {
|
|
|
1332
1340
|
/**
|
|
1333
1341
|
* Returns a HTTP header object contains the authentication information for
|
|
1334
1342
|
* Google Ads API, include: `developer-token` and `login-customer-id`.
|
|
1343
|
+
* `grpc` only takes plain objects as valid values of the object `otherArgs`,
|
|
1344
|
+
* so here can not use 'Headers' type yet.
|
|
1335
1345
|
* @param {string} loginCustomerId
|
|
1336
1346
|
* @return {object} The HTTP header object.
|
|
1337
1347
|
* @private
|
|
1338
1348
|
*/
|
|
1339
1349
|
getGoogleAdsHeaders_(loginCustomerId) {
|
|
1340
|
-
const headers = {
|
|
1350
|
+
const headers = {};
|
|
1351
|
+
if (this.developerToken) {
|
|
1352
|
+
headers['developer-token'] = this.developerToken;
|
|
1353
|
+
}
|
|
1341
1354
|
if (loginCustomerId) {
|
|
1342
1355
|
headers['login-customer-id'] = getCleanCid(loginCustomerId);
|
|
1343
1356
|
}
|
|
@@ -1366,9 +1379,8 @@ class GoogleAdsApi {
|
|
|
1366
1379
|
*/
|
|
1367
1380
|
async getGoogleAdsServiceClient_() {
|
|
1368
1381
|
if (this.googleAdsClient) return this.googleAdsClient;
|
|
1369
|
-
await this.authClient.prepareCredentials();
|
|
1370
1382
|
this.googleAdsClient = new GoogleAdsServiceClient({
|
|
1371
|
-
authClient: this.
|
|
1383
|
+
authClient: await this.getAuth(),
|
|
1372
1384
|
});
|
|
1373
1385
|
return this.googleAdsClient;
|
|
1374
1386
|
}
|
|
@@ -1379,9 +1391,8 @@ class GoogleAdsApi {
|
|
|
1379
1391
|
* @private
|
|
1380
1392
|
*/
|
|
1381
1393
|
async getGoogleAdsFieldServiceClient_() {
|
|
1382
|
-
await this.authClient.prepareCredentials();
|
|
1383
1394
|
return new GoogleAdsFieldServiceClient({
|
|
1384
|
-
authClient: this.
|
|
1395
|
+
authClient: await this.getAuth(),
|
|
1385
1396
|
});
|
|
1386
1397
|
}
|
|
1387
1398
|
|
|
@@ -1391,9 +1402,8 @@ class GoogleAdsApi {
|
|
|
1391
1402
|
* @private
|
|
1392
1403
|
*/
|
|
1393
1404
|
async getConversionUploadServiceClient_() {
|
|
1394
|
-
await this.authClient.prepareCredentials();
|
|
1395
1405
|
return new ConversionUploadServiceClient({
|
|
1396
|
-
authClient: this.
|
|
1406
|
+
authClient: await this.getAuth(),
|
|
1397
1407
|
});
|
|
1398
1408
|
}
|
|
1399
1409
|
|
|
@@ -1403,9 +1413,8 @@ class GoogleAdsApi {
|
|
|
1403
1413
|
* @private
|
|
1404
1414
|
*/
|
|
1405
1415
|
async getConversionAdjustmentUploadServiceClient_() {
|
|
1406
|
-
await this.authClient.prepareCredentials();
|
|
1407
1416
|
return new ConversionAdjustmentUploadServiceClient({
|
|
1408
|
-
authClient: this.
|
|
1417
|
+
authClient: await this.getAuth(),
|
|
1409
1418
|
});
|
|
1410
1419
|
}
|
|
1411
1420
|
|
|
@@ -1415,9 +1424,8 @@ class GoogleAdsApi {
|
|
|
1415
1424
|
* @private
|
|
1416
1425
|
*/
|
|
1417
1426
|
async getUserListServiceClient_() {
|
|
1418
|
-
await this.authClient.prepareCredentials();
|
|
1419
1427
|
return new UserListServiceClient({
|
|
1420
|
-
authClient: this.
|
|
1428
|
+
authClient: await this.getAuth(),
|
|
1421
1429
|
});
|
|
1422
1430
|
}
|
|
1423
1431
|
|
|
@@ -1427,9 +1435,8 @@ class GoogleAdsApi {
|
|
|
1427
1435
|
* @private
|
|
1428
1436
|
*/
|
|
1429
1437
|
async getUserDataServiceClient_() {
|
|
1430
|
-
await this.authClient.prepareCredentials();
|
|
1431
1438
|
return new UserDataServiceClient({
|
|
1432
|
-
authClient: this.
|
|
1439
|
+
authClient: await this.getAuth(),
|
|
1433
1440
|
});
|
|
1434
1441
|
}
|
|
1435
1442
|
|
|
@@ -1439,9 +1446,8 @@ class GoogleAdsApi {
|
|
|
1439
1446
|
* @private
|
|
1440
1447
|
*/
|
|
1441
1448
|
async getOfflineUserDataJobServiceClient_() {
|
|
1442
|
-
await this.authClient.prepareCredentials();
|
|
1443
1449
|
return new OfflineUserDataJobServiceClient({
|
|
1444
|
-
authClient: this.
|
|
1450
|
+
authClient: await this.getAuth(),
|
|
1445
1451
|
});
|
|
1446
1452
|
}
|
|
1447
1453
|
}
|
package/src/apis/search_ads.js
CHANGED
|
@@ -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
|
|
123
|
-
|
|
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`,
|
package/src/apis/sendgrid.js
CHANGED
|
@@ -64,11 +64,18 @@ class SendGrid extends RestfulApiBase {
|
|
|
64
64
|
|
|
65
65
|
/** @override */
|
|
66
66
|
async getDefaultHeaders() {
|
|
67
|
-
|
|
68
|
-
|
|
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
|
package/src/components/automl.js
DELETED
|
@@ -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;
|