@google-cloud/nodejs-common 1.7.0 → 1.7.2-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/bin/install_functions.sh +1 -0
- package/package.json +1 -1
- package/src/apis/dfa_reporting.js +37 -0
- package/src/apis/display_video.js +97 -0
- package/src/apis/index.js +8 -0
- package/src/components/utils.js +21 -0
package/bin/install_functions.sh
CHANGED
|
@@ -1552,6 +1552,7 @@ set_cloud_functions_default_settings() {
|
|
|
1552
1552
|
local -n default_cf_flag=$1
|
|
1553
1553
|
default_cf_flag+=(--region="${REGION}")
|
|
1554
1554
|
default_cf_flag+=(--no-allow-unauthenticated)
|
|
1555
|
+
default_cf_flag+=(--docker-registry=artifact-registry)
|
|
1555
1556
|
default_cf_flag+=(--timeout=540 --memory="${CF_MEMORY}" --runtime="${CF_RUNTIME}")
|
|
1556
1557
|
default_cf_flag+=(--set-env-vars=GCP_PROJECT="${GCP_PROJECT}")
|
|
1557
1558
|
default_cf_flag+=(--set-env-vars=PROJECT_NAMESPACE="${PROJECT_NAMESPACE}")
|
package/package.json
CHANGED
|
@@ -75,6 +75,17 @@ const PICKED_PROPERTIES = [
|
|
|
75
75
|
'quantity',
|
|
76
76
|
];
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Kinds of UserIdentifier.
|
|
80
|
+
* @type {Array<string>}
|
|
81
|
+
*/
|
|
82
|
+
const IDENTIFIERS = [
|
|
83
|
+
'hashedEmail',
|
|
84
|
+
'hashedPhoneNumber',
|
|
85
|
+
'addressInfo',
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
const MAX_IDENTIFIERS_PER_USER = 5;
|
|
78
89
|
/**
|
|
79
90
|
* Google DfaReport API v3.0 stub.
|
|
80
91
|
* see https://developers.google.com/doubleclick-advertisers/service_accounts
|
|
@@ -175,6 +186,32 @@ class DfaReporting {
|
|
|
175
186
|
conversion.customVariables = config.customVariables.map(
|
|
176
187
|
(variable) => ({'type': variable, 'value': record[variable],}));
|
|
177
188
|
}
|
|
189
|
+
// User Identifiers
|
|
190
|
+
if (record.userIdentifiers) {
|
|
191
|
+
const userIdentifiers = [];
|
|
192
|
+
IDENTIFIERS.map((id) => {
|
|
193
|
+
const idValue = record.userIdentifiers[id];
|
|
194
|
+
if (idValue) {
|
|
195
|
+
if (Array.isArray(idValue)) {
|
|
196
|
+
idValue.forEach(
|
|
197
|
+
(user) => void userIdentifiers.push({ [id]: user }));
|
|
198
|
+
} else {
|
|
199
|
+
userIdentifiers.push({ [id]: idValue });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
if (userIdentifiers.length > 0) {
|
|
204
|
+
if (userIdentifiers.length > MAX_IDENTIFIERS_PER_USER) {
|
|
205
|
+
this.logger.warn(
|
|
206
|
+
'There are too many user identifiers:', record.userIdentifiers);
|
|
207
|
+
}
|
|
208
|
+
conversion.userIdentifiers =
|
|
209
|
+
userIdentifiers.slice(0, MAX_IDENTIFIERS_PER_USER);
|
|
210
|
+
} else {
|
|
211
|
+
this.logger.warn(
|
|
212
|
+
'There is no valid user identifier:', record.userIdentifiers);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
178
215
|
return conversion;
|
|
179
216
|
});
|
|
180
217
|
const requestBody = {conversions};
|
|
@@ -0,0 +1,97 @@
|
|
|
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 DoubleClick Search Ads Conversions uploading on Google
|
|
17
|
+
* API Client Library.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
'use strict';
|
|
21
|
+
|
|
22
|
+
const { google } = require('googleapis');
|
|
23
|
+
const AuthClient = require('./auth_client.js');
|
|
24
|
+
const {
|
|
25
|
+
getLogger,
|
|
26
|
+
getObjectByPath,
|
|
27
|
+
SendSingleBatch,
|
|
28
|
+
BatchResult,
|
|
29
|
+
} = require('../components/utils.js');
|
|
30
|
+
|
|
31
|
+
const API_SCOPES = Object.freeze([
|
|
32
|
+
'https://www.googleapis.com/auth/display-video',
|
|
33
|
+
]);
|
|
34
|
+
const API_VERSION = 'v2';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Display and Video 360 API v2 stub.
|
|
38
|
+
* @see https://developers.google.com/display-video/api/reference/rest/v2
|
|
39
|
+
* This is not the same to Reports Display & Video 360 API which is from Google
|
|
40
|
+
* Bid Manager API.
|
|
41
|
+
* @see https://developers.google.com/bid-manager/reference/rest
|
|
42
|
+
*/
|
|
43
|
+
class DisplayVideo {
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @constructor
|
|
47
|
+
* @param {!Object<string,string>=} env The environment object to hold env
|
|
48
|
+
* variables.
|
|
49
|
+
*/
|
|
50
|
+
constructor(env = process.env) {
|
|
51
|
+
this.authClient = new AuthClient(API_SCOPES, env);
|
|
52
|
+
this.logger = getLogger('API.DV3API');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Prepares the Google DV3 instance.
|
|
57
|
+
* @return {!google.displayvideo}
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
async getApiClient_() {
|
|
61
|
+
if (this.displayvideo) return this.displayvideo;
|
|
62
|
+
this.logger.debug(`Initialized ${this.constructor.name} instance.`);
|
|
63
|
+
this.displayvideo = google.displayvideo({
|
|
64
|
+
version: API_VERSION,
|
|
65
|
+
auth: await this.getAuth_(),
|
|
66
|
+
});
|
|
67
|
+
return this.displayvideo;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Gets the auth object.
|
|
72
|
+
* @return {!Promise<{!OAuth2Client|!JWT|!Compute}>}
|
|
73
|
+
*/
|
|
74
|
+
async getAuth_() {
|
|
75
|
+
if (this.auth) return this.auth;
|
|
76
|
+
await this.authClient.prepareCredentials();
|
|
77
|
+
this.auth = this.authClient.getDefaultAuth();
|
|
78
|
+
return this.auth;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Gets the instance of function object based on Google API client library.
|
|
83
|
+
* @param {string|undefined} path
|
|
84
|
+
* @return {Object}
|
|
85
|
+
*/
|
|
86
|
+
async getFunctionObject(path) {
|
|
87
|
+
const instance = await this.getApiClient_();
|
|
88
|
+
return getObjectByPath(instance, path);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = {
|
|
94
|
+
DisplayVideo,
|
|
95
|
+
API_VERSION,
|
|
96
|
+
API_SCOPES,
|
|
97
|
+
};
|
package/src/apis/index.js
CHANGED
|
@@ -30,6 +30,14 @@ exports.AuthClient = require('./auth_client.js');
|
|
|
30
30
|
*/
|
|
31
31
|
exports.dfareporting = require('./dfa_reporting.js');
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* APIs integration class for DV3 API.
|
|
35
|
+
* @const {{
|
|
36
|
+
* DisplayVideo:!DisplayVideo,
|
|
37
|
+
* }}
|
|
38
|
+
*/
|
|
39
|
+
exports.displayvideo = require('./display_video.js');
|
|
40
|
+
|
|
33
41
|
/**
|
|
34
42
|
* APIs integration class for Google Analytics Data Import API.
|
|
35
43
|
* @const {{
|
package/src/components/utils.js
CHANGED
|
@@ -497,6 +497,26 @@ const extractObject = (paths) => {
|
|
|
497
497
|
};
|
|
498
498
|
};
|
|
499
499
|
|
|
500
|
+
/**
|
|
501
|
+
* Returns the embedded object from the given object and path.
|
|
502
|
+
* @param {Object} obj
|
|
503
|
+
* @param {string|undefined} paths
|
|
504
|
+
* @return {Object}
|
|
505
|
+
*/
|
|
506
|
+
const getObjectByPath = (obj, paths) => {
|
|
507
|
+
let instance = obj;
|
|
508
|
+
if (paths) {
|
|
509
|
+
paths.split('.').filter((key) => !!key).forEach((key) => {
|
|
510
|
+
instance = instance[key];
|
|
511
|
+
if (!instance) {
|
|
512
|
+
console.error('Fail to get function containter', paths);
|
|
513
|
+
return instance;
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
return instance;
|
|
518
|
+
};
|
|
519
|
+
|
|
500
520
|
/**
|
|
501
521
|
* For more details, see:
|
|
502
522
|
* https://developers.google.com/google-ads/api/docs/rest/design/json-mappings
|
|
@@ -533,6 +553,7 @@ module.exports = {
|
|
|
533
553
|
replaceParameters,
|
|
534
554
|
getFilterFunction,
|
|
535
555
|
extractObject,
|
|
556
|
+
getObjectByPath,
|
|
536
557
|
changeNamingFromSnakeToUpperCamel,
|
|
537
558
|
changeNamingFromSnakeToLowerCamel,
|
|
538
559
|
};
|