@google-cloud/nodejs-common 2.5.0 → 2.6.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/package.json +15 -15
- package/src/apis/dfa_reporting.js +10 -10
- package/src/apis/display_video.js +3 -3
- package/src/apis/google_ads_api.js +3 -1
- package/src/apis/search_ads.js +1 -1
- package/src/components/pubsub.js +44 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@google-cloud/nodejs-common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.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,25 +16,25 @@
|
|
|
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/bigquery": "^8.1.
|
|
19
|
+
"@google-cloud/aiplatform": "^6.0.0",
|
|
20
|
+
"@google-cloud/bigquery": "^8.1.1",
|
|
21
21
|
"@google-cloud/datastore": "^9.2.1",
|
|
22
|
-
"@google-cloud/firestore": "^
|
|
22
|
+
"@google-cloud/firestore": "^8.0.0",
|
|
23
23
|
"@google-cloud/logging-winston": "^6.0.1",
|
|
24
|
-
"@google-cloud/pubsub": "^5.
|
|
25
|
-
"@google-cloud/scheduler": "^5.
|
|
26
|
-
"@google-cloud/secret-manager": "^6.
|
|
27
|
-
"@google-cloud/storage": "^7.
|
|
28
|
-
"@grpc/grpc-js": "^1.
|
|
29
|
-
"gaxios": "^7.
|
|
30
|
-
"google-ads-nodejs-client": "
|
|
31
|
-
"google-auth-library": "^10.
|
|
32
|
-
"googleapis": "^
|
|
24
|
+
"@google-cloud/pubsub": "^5.2.0",
|
|
25
|
+
"@google-cloud/scheduler": "^5.3.1",
|
|
26
|
+
"@google-cloud/secret-manager": "^6.1.1",
|
|
27
|
+
"@google-cloud/storage": "^7.18.0",
|
|
28
|
+
"@grpc/grpc-js": "^1.14.3",
|
|
29
|
+
"gaxios": "^7.1.3",
|
|
30
|
+
"google-ads-nodejs-client": "22.0.0",
|
|
31
|
+
"google-auth-library": "^10.5.0",
|
|
32
|
+
"googleapis": "^168.0.0",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
34
|
-
"winston": "^3.
|
|
34
|
+
"winston": "^3.19.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"jasmine": "^5.
|
|
37
|
+
"jasmine": "^5.13.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"test": "node node_modules/jasmine/bin/jasmine"
|
|
@@ -33,7 +33,7 @@ const API_SCOPES = Object.freeze([
|
|
|
33
33
|
'https://www.googleapis.com/auth/dfareporting',
|
|
34
34
|
'https://www.googleapis.com/auth/dfatrafficking',
|
|
35
35
|
]);
|
|
36
|
-
const API_VERSION = '
|
|
36
|
+
const API_VERSION = 'v5';
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Configuration for preparing conversions for Campaign Manager, includes:
|
|
@@ -41,8 +41,8 @@ const API_VERSION = 'v4';
|
|
|
41
41
|
* The 'idType' can be one of the values: 'encryptedUserId', 'gclid' or
|
|
42
42
|
* 'mobileDeviceId'.
|
|
43
43
|
* The 'operation' can be 'insert' or 'update'. The default value is 'insert'.
|
|
44
|
-
* 'insert' stands for https://developers.google.com/doubleclick-advertisers/rest/
|
|
45
|
-
* 'update' stands for https://developers.google.com/doubleclick-advertisers/rest/
|
|
44
|
+
* 'insert' stands for https://developers.google.com/doubleclick-advertisers/rest/v5/conversions/batchinsert
|
|
45
|
+
* 'update' stands for https://developers.google.com/doubleclick-advertisers/rest/v5/conversions/batchupdate
|
|
46
46
|
* For other properties, see
|
|
47
47
|
* https://developers.google.com/doubleclick-advertisers/guides/conversions_update
|
|
48
48
|
*
|
|
@@ -69,7 +69,7 @@ let ConversionsConfig;
|
|
|
69
69
|
/**
|
|
70
70
|
* List of properties that will be take from the data file as elements of a
|
|
71
71
|
* conversion.
|
|
72
|
-
* See https://developers.google.com/doubleclick-advertisers/rest/
|
|
72
|
+
* See https://developers.google.com/doubleclick-advertisers/rest/v5/Conversion
|
|
73
73
|
* @type {Array<string>}
|
|
74
74
|
*/
|
|
75
75
|
const PICKED_PROPERTIES = [
|
|
@@ -92,7 +92,7 @@ const IDENTIFIERS = [
|
|
|
92
92
|
|
|
93
93
|
const MAX_IDENTIFIERS_PER_USER = 5;
|
|
94
94
|
/**
|
|
95
|
-
* Google DfaReport API
|
|
95
|
+
* Google DfaReport API v5 stub.
|
|
96
96
|
* see https://developers.google.com/doubleclick-advertisers/service_accounts
|
|
97
97
|
*/
|
|
98
98
|
class DfaReporting extends GoogleApiClient {
|
|
@@ -164,7 +164,7 @@ class DfaReporting extends GoogleApiClient {
|
|
|
164
164
|
const operation =
|
|
165
165
|
config.operation === 'update' ? 'batchupdate' : 'batchinsert';
|
|
166
166
|
// customVariables is not supported by batchupdate.
|
|
167
|
-
// https://developers.google.com/doubleclick-advertisers/rest/
|
|
167
|
+
// https://developers.google.com/doubleclick-advertisers/rest/v5/Conversion#CustomFloodlightVariable
|
|
168
168
|
if (operation === 'batchupdate' &&
|
|
169
169
|
typeof config.customVariables !== 'undefined') {
|
|
170
170
|
this.logger.warn('customVariables is not supported by batchupdate');
|
|
@@ -252,9 +252,9 @@ class DfaReporting extends GoogleApiClient {
|
|
|
252
252
|
* ConversionStatus object. This function extras failed lines and error
|
|
253
253
|
* messages based on the 'errors'.
|
|
254
254
|
* For 'ConversionStatus', see:
|
|
255
|
-
* https://developers.google.com/doubleclick-advertisers/rest/
|
|
255
|
+
* https://developers.google.com/doubleclick-advertisers/rest/v5/ConversionStatus
|
|
256
256
|
* For 'ConversionError', see:
|
|
257
|
-
* https://developers.google.com/doubleclick-advertisers/rest/
|
|
257
|
+
* https://developers.google.com/doubleclick-advertisers/rest/v5/ConversionStatus#ConversionError
|
|
258
258
|
* @param {!BatchResult} batchResult
|
|
259
259
|
* @param {!Array<!Schema$ConversionStatus>} statuses
|
|
260
260
|
* @param {!Array<string>} lines The original input data.
|
|
@@ -324,7 +324,7 @@ class DfaReporting extends GoogleApiClient {
|
|
|
324
324
|
* has a relative date range, e.g. YESTERDAY. To solve this, if there are
|
|
325
325
|
* `startDate` and `endDate` available in the given `config`, they will be
|
|
326
326
|
* used to update the report before the report is started to run.
|
|
327
|
-
* @see https://developers.google.com/doubleclick-advertisers/rest/
|
|
327
|
+
* @see https://developers.google.com/doubleclick-advertisers/rest/v5/reports/run
|
|
328
328
|
*
|
|
329
329
|
* @param {{
|
|
330
330
|
* accountId:(string|undefined),
|
|
@@ -366,7 +366,7 @@ class DfaReporting extends GoogleApiClient {
|
|
|
366
366
|
* Returns file url from a report. If the report status is 'REPORT_AVAILABLE',
|
|
367
367
|
* then return the apiUrl from the response; if the status is 'PROCESSING' or
|
|
368
368
|
* 'QUEUED', returns undefined as it is unfinished; otherwise throws an error.
|
|
369
|
-
* @see https://developers.google.com/doubleclick-advertisers/rest/
|
|
369
|
+
* @see https://developers.google.com/doubleclick-advertisers/rest/v5/reports/get
|
|
370
370
|
*
|
|
371
371
|
* @param {{
|
|
372
372
|
* accountId:(string|undefined),
|
|
@@ -25,11 +25,11 @@ const { getLogger } = require('../components/utils.js');
|
|
|
25
25
|
const API_SCOPES = Object.freeze([
|
|
26
26
|
'https://www.googleapis.com/auth/display-video',
|
|
27
27
|
]);
|
|
28
|
-
const API_VERSION = '
|
|
28
|
+
const API_VERSION = 'v4';
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Display and Video 360 API
|
|
32
|
-
* @see https://developers.google.com/display-video/api/reference/rest/
|
|
31
|
+
* Display and Video 360 API v4 stub.
|
|
32
|
+
* @see https://developers.google.com/display-video/api/reference/rest/v4
|
|
33
33
|
* This is not the same to Reports Display & Video 360 API which is from Google
|
|
34
34
|
* Bid Manager API.
|
|
35
35
|
* @see https://developers.google.com/bid-manager/reference/rest
|
|
@@ -238,6 +238,7 @@ const MAX_IDENTIFIERS = {
|
|
|
238
238
|
*
|
|
239
239
|
* @see https://developers.google.com/google-ads/api/reference/rpc/latest/ClickConversion
|
|
240
240
|
* @typedef {{
|
|
241
|
+
* jobId: (number|undefined),
|
|
241
242
|
* externalAttributionData: (GoogleAdsApi.ExternalAttributionData|undefined),
|
|
242
243
|
* cartData: (object|undefined),
|
|
243
244
|
* gclid: (string|undefined),
|
|
@@ -867,7 +868,7 @@ class GoogleAdsApi extends AuthRestfulApi {
|
|
|
867
868
|
* @return {!Promise<!UploadClickConversionsResponse>}
|
|
868
869
|
*/
|
|
869
870
|
async uploadClickConversions(lines, config) {
|
|
870
|
-
const { customerId, loginCustomerId } = config;
|
|
871
|
+
const { customerId, loginCustomerId, jobId } = config;
|
|
871
872
|
this.logger.debug('Upload click conversions for:', config);
|
|
872
873
|
const conversions = buildConversionJsonList(lines, config,
|
|
873
874
|
CONVERSION_FIELDS.CLICK, IDENTIFIERS.CLICK_CONVERSION, MAX_IDENTIFIERS.CONVERSION);
|
|
@@ -877,6 +878,7 @@ class GoogleAdsApi extends AuthRestfulApi {
|
|
|
877
878
|
const request = new UploadClickConversionsRequest({
|
|
878
879
|
conversions: clickConversions,
|
|
879
880
|
customerId,
|
|
881
|
+
jobId,
|
|
880
882
|
validateOnly: this.debugMode, // when true makes no changes
|
|
881
883
|
partialFailure: true, // Will still create the non-failed entities
|
|
882
884
|
});
|
package/src/apis/search_ads.js
CHANGED
|
@@ -90,7 +90,7 @@ class SearchAds extends GoogleApiClient {
|
|
|
90
90
|
* @param {string} query
|
|
91
91
|
* @param {object=} options Options for `SearchSearchAds360Request`.
|
|
92
92
|
* @see https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#searchsearchads360request
|
|
93
|
-
* @return {!
|
|
93
|
+
* @return {!SearchSearchAds360Response}
|
|
94
94
|
* @see https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#searchsearchads360response
|
|
95
95
|
*/
|
|
96
96
|
async getPaginatedReport(customerId, loginCustomerId, query, options = {}) {
|
package/src/components/pubsub.js
CHANGED
|
@@ -34,7 +34,15 @@ const {
|
|
|
34
34
|
* 1. gets or creates a topic.
|
|
35
35
|
* 2. gets or creates a subscription.
|
|
36
36
|
* 3. publishes a message after confirms the topic exists.
|
|
37
|
-
* 4.
|
|
37
|
+
* 4. pull message(s).
|
|
38
|
+
* 5. acknowledge message(s).
|
|
39
|
+
*
|
|
40
|
+
* The 'pull' and 'acknowledge' are built on 'v1.SubscriberClient` which is
|
|
41
|
+
* considered as 'low-level', auto-generated gRPC API class. This class offers
|
|
42
|
+
* more direct control over the request-response cycle. Tentacles' queuing
|
|
43
|
+
* mechanism is built on this kind of precise control.
|
|
44
|
+
* There is also a high-level 'Pubsub' client, which automatically handles
|
|
45
|
+
* message streaming and flow control.
|
|
38
46
|
*/
|
|
39
47
|
class EnhancedPubSub {
|
|
40
48
|
/**
|
|
@@ -127,23 +135,53 @@ class EnhancedPubSub {
|
|
|
127
135
|
}
|
|
128
136
|
};
|
|
129
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Pulls and returns message(s) from a pull subscription.
|
|
140
|
+
*
|
|
141
|
+
* @param {string} subscriptionName Subscription name.
|
|
142
|
+
* @param {number=} maxMessages
|
|
143
|
+
* @return {!Array<ReceivedMessage>}
|
|
144
|
+
*/
|
|
145
|
+
async pull(subscriptionName, maxMessages = 1) {
|
|
146
|
+
const subscriptionPath = await this.getSubscriptionPath_(subscriptionName);
|
|
147
|
+
const [response] = await this.subClient.pull({
|
|
148
|
+
subscription: subscriptionPath,
|
|
149
|
+
maxMessages,
|
|
150
|
+
});
|
|
151
|
+
return response.receivedMessages ? response.receivedMessages : [];
|
|
152
|
+
}
|
|
153
|
+
|
|
130
154
|
/**
|
|
131
155
|
* Using `SubscriberClient` to acknowledge messages.
|
|
132
156
|
* 2022.11.02 The method `ack()` in Message doesn't work properly due to a
|
|
133
157
|
* unknown reason. Use this function to acknowledge a message for now.
|
|
158
|
+
* 2025.08.20 This function can't properly acknowledge messages pulled through
|
|
159
|
+
* 'Pubsub' object. Use a new 'pull' method to get the message and ack.
|
|
134
160
|
*
|
|
135
|
-
* @param {string}
|
|
161
|
+
* @param {string} subscriptionName Subscription name.
|
|
136
162
|
* @param {(string|!Array<string>)} ackIds Message ackIds.
|
|
137
163
|
*/
|
|
138
|
-
async acknowledge(
|
|
139
|
-
const
|
|
164
|
+
async acknowledge(subscriptionName, ackIds) {
|
|
165
|
+
const subscriptionPath = await this.getSubscriptionPath_(subscriptionName);
|
|
140
166
|
const ackRequest = {
|
|
141
|
-
subscription:
|
|
167
|
+
subscription: subscriptionPath,
|
|
142
168
|
ackIds: Array.isArray(ackIds) ? ackIds : [ackIds],
|
|
143
169
|
};
|
|
144
170
|
await this.subClient.acknowledge(ackRequest);
|
|
145
171
|
}
|
|
146
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Returns the complete subscription path for the `SubscriberClient` object.
|
|
175
|
+
* @see https://cloud.google.com/nodejs/docs/reference/pubsub/latest/pubsub/v1.subscriberclient
|
|
176
|
+
* @param {string} subscriptionName Subscription name.
|
|
177
|
+
* @return {string}
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
180
|
+
async getSubscriptionPath_(subscriptionName) {
|
|
181
|
+
const projectId = await this.subClient.getProjectId();
|
|
182
|
+
return this.subClient.subscriptionPath(projectId, subscriptionName);
|
|
183
|
+
}
|
|
184
|
+
|
|
147
185
|
/**
|
|
148
186
|
* Returns a new instance of this class. Using this function to replace
|
|
149
187
|
* constructor to be more friendly to unit tests.
|
|
@@ -163,7 +201,7 @@ class EnhancedPubSub {
|
|
|
163
201
|
* @return {string} The decoded message.
|
|
164
202
|
*/
|
|
165
203
|
const getMessage = (message) => {
|
|
166
|
-
return Buffer.from(message.data, 'base64').toString();
|
|
204
|
+
return Buffer.from(message.data || '', 'base64').toString();
|
|
167
205
|
};
|
|
168
206
|
|
|
169
207
|
module.exports = {
|