googleapis-common
Advanced tools
Comparing version 7.0.1 to 7.1.0-experimental
@@ -25,4 +25,7 @@ import { GaxiosOptions, GaxiosResponse } from 'gaxios'; | ||
auth?: GoogleAuth | OAuth2Client | BaseExternalAccountClient | string; | ||
universeDomain?: string; | ||
universe_domain?: string; | ||
} | ||
export interface MethodOptions extends GaxiosOptions { | ||
apiVersion?: string; | ||
rootUrl?: string; | ||
@@ -29,0 +32,0 @@ http2?: boolean; |
@@ -57,3 +57,3 @@ "use strict"; | ||
async function createAPIRequestAsync(parameters) { | ||
var _a; | ||
var _a, _b, _c, _d; | ||
// Combine the GaxiosOptions options passed with this specific | ||
@@ -102,3 +102,3 @@ // API call with the global options configured at the API Context | ||
const headers = params.headers || {}; | ||
populateAPIHeader(headers); | ||
populateAPIHeader(headers, options.apiVersion); | ||
delete params.headers; | ||
@@ -122,3 +122,7 @@ // Un-alias parameters that were modified due to conflicts with reserved names | ||
if (options.url) { | ||
options.url = urlTemplate.parse(options.url).expand(params); | ||
let url = options.url; | ||
if (typeof url === 'object') { | ||
url = url.toString(); | ||
} | ||
options.url = urlTemplate.parse(url).expand(params); | ||
} | ||
@@ -264,2 +268,20 @@ if (parameters.mediaUrl) { | ||
delete options.auth; // is overridden by our auth code | ||
// Determine TPC universe | ||
if (options.universeDomain && | ||
options.universe_domain && | ||
options.universeDomain !== options.universe_domain) { | ||
throw new Error('Please set either universe_domain or universeDomain, but not both.'); | ||
} | ||
const universeDomainEnvVar = typeof process === 'object' && typeof process.env === 'object' | ||
? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] | ||
: undefined; | ||
const universeDomain = (_d = (_c = (_b = options.universeDomain) !== null && _b !== void 0 ? _b : options.universe_domain) !== null && _c !== void 0 ? _c : universeDomainEnvVar) !== null && _d !== void 0 ? _d : 'googleapis.com'; | ||
// Update URL to point to the given TPC universe | ||
if (universeDomain !== 'googleapis.com' && options.url) { | ||
const url = new URL(options.url); | ||
if (url.hostname.endsWith('.googleapis.com')) { | ||
url.hostname = url.hostname.replace(/googleapis\.com$/, universeDomain); | ||
options.url = url.toString(); | ||
} | ||
} | ||
// Perform the HTTP request. NOTE: this function used to return a | ||
@@ -270,2 +292,10 @@ // mikeal/request object. Since the transition to Axios, the method is | ||
if (authClient && typeof authClient === 'object') { | ||
// Validate TPC universe | ||
const universeFromAuth = typeof authClient.getUniverseDomain === 'function' | ||
? await authClient.getUniverseDomain() | ||
: undefined; | ||
if (universeFromAuth && universeDomain !== universeFromAuth) { | ||
throw new Error(`The configured universe domain (${universeDomain}) does not match the universe domain found in the credentials (${universeFromAuth}). ` + | ||
"If you haven't configured the universe domain explicitly, googleapis.com is the default."); | ||
} | ||
if (options.http2) { | ||
@@ -302,3 +332,3 @@ const authHeaders = await authClient.getRequestHeaders(options.url); | ||
} | ||
function populateAPIHeader(headers) { | ||
function populateAPIHeader(headers, apiVersion) { | ||
// TODO: we should eventually think about adding browser support for this | ||
@@ -310,3 +340,6 @@ // populating the gl-web header (web support should also be added to | ||
} | ||
if (apiVersion) { | ||
headers['x-goog-api-version'] = apiVersion; | ||
} | ||
} | ||
//# sourceMappingURL=apirequest.js.map |
@@ -34,2 +34,3 @@ "use strict"; | ||
this._cachedAuth = new google_auth_library_1.GoogleAuth(options); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return this._cachedAuth.getClient(); | ||
@@ -36,0 +37,0 @@ } |
@@ -84,2 +84,3 @@ "use strict"; | ||
method: method.httpMethod, | ||
apiVersion: method.apiVersion, | ||
}, | ||
@@ -86,0 +87,0 @@ params, |
@@ -117,2 +117,3 @@ /** | ||
supportsMediaDownload?: boolean; | ||
apiVersion?: string; | ||
} | ||
@@ -119,0 +120,0 @@ export interface FragmentResponse { |
@@ -7,2 +7,9 @@ # Changelog | ||
## [7.1.0](https://github.com/googleapis/nodejs-googleapis-common/compare/v7.0.1...v7.1.0) (2024-03-21) | ||
### Features | ||
* Add universe support to googleapis libraries ([#548](https://github.com/googleapis/nodejs-googleapis-common/issues/548)) ([dfd4b0d](https://github.com/googleapis/nodejs-googleapis-common/commit/dfd4b0d0a37fa9cf3f6599ba28bac817d28c96c8)) | ||
## [7.0.1](https://github.com/googleapis/nodejs-googleapis-common/compare/v7.0.0...v7.0.1) (2023-10-31) | ||
@@ -9,0 +16,0 @@ |
{ | ||
"name": "googleapis-common", | ||
"version": "7.0.1", | ||
"version": "7.1.0-experimental", | ||
"description": "A common tooling library used by the googleapis npm module. You probably don't want to use this directly.", | ||
@@ -39,3 +39,3 @@ "repository": "googleapis/nodejs-googleapis-common", | ||
"gaxios": "^6.0.3", | ||
"google-auth-library": "^9.0.0", | ||
"google-auth-library": "^9.7.0", | ||
"qs": "^6.7.0", | ||
@@ -53,7 +53,7 @@ "url-template": "^2.0.8", | ||
"@types/ncp": "^2.0.1", | ||
"@types/nock": "^10.0.3", | ||
"@types/nock": "^11.0.0", | ||
"@types/proxyquire": "^1.3.28", | ||
"@types/qs": "^6.5.3", | ||
"@types/sinon": "^10.0.0", | ||
"@types/tmp": "0.2.5", | ||
"@types/sinon": "^17.0.0", | ||
"@types/tmp": "0.2.6", | ||
"@types/url-template": "^2.0.28", | ||
@@ -74,3 +74,3 @@ "@types/uuid": "^9.0.0", | ||
"karma-sourcemap-loader": "^0.4.0", | ||
"karma-webpack": "^5.0.0", | ||
"karma-webpack": "^4.0.0", | ||
"linkinator": "^3.1.0", | ||
@@ -84,7 +84,7 @@ "mocha": "^9.2.2", | ||
"puppeteer": "^18.2.1", | ||
"sinon": "^15.0.0", | ||
"sinon": "^17.0.0", | ||
"tmp": "^0.2.0", | ||
"ts-loader": "^8.0.0", | ||
"typescript": "5.1.6", | ||
"webpack": "^5.30.0", | ||
"webpack": "^4.0.0", | ||
"webpack-cli": "^4.0.0" | ||
@@ -91,0 +91,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94916
1366
2
5
Updatedgoogle-auth-library@^9.7.0