Updating NPM dependencies

This commit is contained in:
Drew Heavner
2020-11-11 13:30:52 +00:00
committed by GitHub
parent 7a6fb66c63
commit bd487ef324
9068 changed files with 1400893 additions and 587661 deletions

View File

@@ -1,20 +1,18 @@
"use strict";
/**
* Copyright 2016 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2020 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.createAPIRequest = void 0;
const google_auth_library_1 = require("google-auth-library");
const qs = require("qs");
const stream = require("stream");
@@ -22,10 +20,18 @@ const urlTemplate = require("url-template");
const uuid = require("uuid");
const extend = require("extend");
const isbrowser_1 = require("./isbrowser");
// tslint:disable-next-line no-var-requires
const h2 = require("./http2");
const resolve = require("url");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../../package.json');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isReadableStream(obj) {
return obj instanceof stream.Readable && typeof obj._read === 'function';
return (obj !== null &&
typeof obj === 'object' &&
typeof obj.pipe === 'function' &&
obj.readable !== false &&
typeof obj._read === 'function' &&
typeof obj._readableState === 'object');
}
function getMissingParams(params, required) {
const missing = new Array();
@@ -49,21 +55,20 @@ function createAPIRequest(parameters, callback) {
}
exports.createAPIRequest = createAPIRequest;
async function createAPIRequestAsync(parameters) {
let params = parameters.params;
const options = Object.assign({}, parameters.options);
// Create a new params object so it can no longer be modified from outside
// code Also support global and per-client params, but allow them to be
// overriden per-request
const topOptions = parameters.context.google &&
parameters.context.google._options &&
parameters.context.google._options.params
? parameters.context.google._options.params
: {};
params = Object.assign({}, // New base object
topOptions, // Global params
parameters.context._options.params, // Per-client params
params // API call params
var _a;
// Combine the GaxiosOptions options passed with this specific
// API call with the global options configured at the API Context
// level, or at the global level.
const options = extend(true, {}, // Ensure we don't leak settings upstream
((_a = parameters.context.google) === null || _a === void 0 ? void 0 : _a._options) || {}, // Google level options
parameters.context._options || {}, // Per-API options
parameters.options // API call params
);
const params = extend(true, {}, // New base object
options.params, // Combined global/per-api params
parameters.params // API call params
);
options.userAgentDirectives = options.userAgentDirectives || [];
const media = params.media || {};
/**
* In a previous version of this API, the request body was stuffed in a field
@@ -88,11 +93,7 @@ async function createAPIRequestAsync(parameters) {
delete params.resource;
}
delete params.requestBody;
let authClient = params.auth ||
parameters.context._options.auth ||
(parameters.context.google
? parameters.context.google._options.auth
: null);
let authClient = params.auth || options.auth;
const defaultMime = typeof media.body === 'string' ? 'text/plain' : 'application/octet-stream';
delete params.media;
delete params.auth;
@@ -122,6 +123,12 @@ async function createAPIRequestAsync(parameters) {
if (parameters.mediaUrl) {
parameters.mediaUrl = urlTemplate.parse(parameters.mediaUrl).expand(params);
}
// Rewrite url if rootUrl is globally set
if (parameters.context._options.rootUrl !== undefined &&
options.url !== undefined) {
const path = options.url.slice(parameters.context._options.rootUrl.length);
options.url = resolve.resolve(parameters.context._options.rootUrl, path);
}
// When forming the querystring, override the serializer so that array
// values are serialized like this:
// myParams: ['one', 'two'] ---> 'myParams=one&myParams=two'
@@ -130,74 +137,90 @@ async function createAPIRequestAsync(parameters) {
options.paramsSerializer = params => {
return qs.stringify(params, { arrayFormat: 'repeat' });
};
// delete path parameters from the params object so they do not end up in
// query
parameters.pathParams.forEach(param => {
delete params[param];
if (parameters.context &&
parameters.context._options &&
parameters.context._options.params) {
delete parameters.context._options.params[param];
}
});
// delete path params from the params object so they do not end up in query
parameters.pathParams.forEach(param => delete params[param]);
// if authClient is actually a string, use it as an API KEY
if (typeof authClient === 'string') {
params.key = params.key || authClient;
authClient = undefined;
}
function multipartUpload(multipart) {
const boundary = uuid.v4();
const finale = `--${boundary}--`;
const rStream = new stream.PassThrough({
flush(callback) {
this.push('\r\n');
this.push(finale);
callback();
},
});
const pStream = new ProgressStream();
const isStream = isReadableStream(multipart[1].body);
headers['content-type'] = `multipart/related; boundary=${boundary}`;
for (const part of multipart) {
const preamble = `--${boundary}\r\ncontent-type: ${part['content-type']}\r\n\r\n`;
rStream.push(preamble);
if (typeof part.body === 'string') {
rStream.push(part.body);
rStream.push('\r\n');
}
else {
// Gaxios does not natively support onUploadProgress in node.js.
// Pipe through the pStream first to read the number of bytes read
// for the purpose of tracking progress.
pStream.on('progress', bytesRead => {
if (options.onUploadProgress) {
options.onUploadProgress({ bytesRead });
}
});
part.body.pipe(pStream).pipe(rStream);
}
}
if (!isStream) {
rStream.push(finale);
rStream.push(null);
}
options.data = rStream;
}
function browserMultipartUpload(multipart) {
const boundary = uuid.v4();
const finale = `--${boundary}--`;
headers['content-type'] = `multipart/related; boundary=${boundary}`;
let content = '';
for (const part of multipart) {
const preamble = `--${boundary}\r\ncontent-type: ${part['content-type']}\r\n\r\n`;
content += preamble;
if (typeof part.body === 'string') {
content += part.body;
content += '\r\n';
}
}
content += finale;
options.data = content;
}
if (parameters.mediaUrl && media.body) {
options.url = parameters.mediaUrl;
if (resource) {
// gaxios doesn't support multipart/related uploads, so it has to
// be implemented here.
params.uploadType = 'multipart';
const multipart = [
{ 'Content-Type': 'application/json', body: JSON.stringify(resource) },
{ 'content-type': 'application/json', body: JSON.stringify(resource) },
{
'Content-Type': media.mimeType || (resource && resource.mimeType) || defaultMime,
'content-type': media.mimeType || (resource && resource.mimeType) || defaultMime,
body: media.body,
},
];
const boundary = uuid.v4();
const finale = `--${boundary}--`;
const rStream = new stream.PassThrough({
flush(callback) {
this.push('\r\n');
this.push(finale);
callback();
},
});
const pStream = new ProgressStream();
const isStream = isReadableStream(multipart[1].body);
headers['Content-Type'] = `multipart/related; boundary=${boundary}`;
for (const part of multipart) {
const preamble = `--${boundary}\r\nContent-Type: ${part['Content-Type']}\r\n\r\n`;
rStream.push(preamble);
if (typeof part.body === 'string') {
rStream.push(part.body);
rStream.push('\r\n');
}
else {
// Gaxios does not natively support onUploadProgress in node.js.
// Pipe through the pStream first to read the number of bytes read
// for the purpose of tracking progress.
pStream.on('progress', bytesRead => {
if (options.onUploadProgress) {
options.onUploadProgress({ bytesRead });
}
});
part.body.pipe(pStream).pipe(rStream);
}
if (!isbrowser_1.isBrowser()) {
// gaxios doesn't support multipart/related uploads, so it has to
// be implemented here.
multipartUpload(multipart);
}
if (!isStream) {
rStream.push(finale);
rStream.push(null);
else {
browserMultipartUpload(multipart);
}
options.data = rStream;
}
else {
params.uploadType = 'media';
Object.assign(headers, { 'Content-Type': media.mimeType || defaultMime });
Object.assign(headers, { 'content-type': media.mimeType || defaultMime });
options.data = media.body;
}
}
@@ -208,13 +231,12 @@ async function createAPIRequestAsync(parameters) {
options.params = params;
if (!isbrowser_1.isBrowser()) {
options.headers['Accept-Encoding'] = 'gzip';
const directives = options.userAgentDirectives || [];
directives.push({
options.userAgentDirectives.push({
product: 'google-api-nodejs-client',
version: pkg.version,
comment: 'gzip',
});
const userAgent = directives
const userAgent = options.userAgentDirectives
.map(d => {
let line = `${d.product}/${d.version}`;
if (d.comment) {
@@ -235,20 +257,24 @@ async function createAPIRequestAsync(parameters) {
}
// Retry by default
options.retry = options.retry === undefined ? true : options.retry;
// Combine the GaxiosOptions options passed with this specific
// API call witht the global options configured at the API Context
// level, or at the global level.
const mergedOptions = extend(true, {}, parameters.context.google ? parameters.context.google._options : {}, parameters.context._options, options);
delete mergedOptions.auth; // is overridden by our auth code
delete options.auth; // is overridden by our auth code
// Perform the HTTP request. NOTE: this function used to return a
// mikeal/request object. Since the transition to Axios, the method is
// now void. This may be a source of confusion for users upgrading from
// version 24.0 -> 25.0 or up.
if (authClient && typeof authClient === 'object') {
return authClient.request(mergedOptions);
if (options.http2) {
const authHeaders = await authClient.getRequestHeaders(options.url);
const mooOpts = Object.assign({}, options);
mooOpts.headers = Object.assign(mooOpts.headers, authHeaders);
return h2.request(mooOpts);
}
else {
return authClient.request(options);
}
}
else {
return new google_auth_library_1.DefaultTransporter().request(mergedOptions);
return new google_auth_library_1.DefaultTransporter().request(options);
}
}
/**
@@ -260,7 +286,7 @@ class ProgressStream extends stream.Transform {
super(...arguments);
this.bytesRead = 0;
}
// tslint:disable-next-line: no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_transform(chunk, encoding, callback) {
this.bytesRead += chunk.length;
this.emit('progress', this.bytesRead);