Updating NPM dependencies
This commit is contained in:
61
node_modules/gaxios/build/src/gaxios.js
generated
vendored
61
node_modules/gaxios/build/src/gaxios.js
generated
vendored
@@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
// Copyright 2018, Google, LLC.
|
||||
// Copyright 2018 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
|
||||
@@ -15,26 +15,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Gaxios = void 0;
|
||||
const extend_1 = __importDefault(require("extend"));
|
||||
const node_fetch_1 = __importDefault(require("node-fetch"));
|
||||
const querystring_1 = __importDefault(require("querystring"));
|
||||
const is_stream_1 = __importDefault(require("is-stream"));
|
||||
const url_1 = __importDefault(require("url"));
|
||||
const common_1 = require("./common");
|
||||
const retry_1 = require("./retry");
|
||||
// tslint:disable no-any
|
||||
const URL = hasURL() ? window.URL : url_1.default.URL;
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable node/no-unsupported-features/node-builtins */
|
||||
const fetch = hasFetch() ? window.fetch : node_fetch_1.default;
|
||||
function hasWindow() {
|
||||
return typeof window !== 'undefined' && !!window;
|
||||
}
|
||||
function hasURL() {
|
||||
return hasWindow() && !!window.URL;
|
||||
}
|
||||
function hasFetch() {
|
||||
return hasWindow() && !!window.fetch;
|
||||
}
|
||||
// tslint:disable-next-line variable-name
|
||||
let HttpsProxyAgent;
|
||||
// Figure out if we should be using a proxy. Only if it's required, load
|
||||
// the https-proxy-agent module as it adds startup cost.
|
||||
@@ -66,6 +62,11 @@ class Gaxios {
|
||||
opts = this.validateOpts(opts);
|
||||
return this._request(opts);
|
||||
}
|
||||
async _defaultAdapter(opts) {
|
||||
const res = await fetch(opts.url, opts);
|
||||
const data = await this.getResponseData(opts, res);
|
||||
return this.translateResponse(opts, res, data);
|
||||
}
|
||||
/**
|
||||
* Internal, retryable version of the `request` method.
|
||||
* @param opts Set of HTTP options that will be used for this HTTP request.
|
||||
@@ -74,12 +75,10 @@ class Gaxios {
|
||||
try {
|
||||
let translatedResponse;
|
||||
if (opts.adapter) {
|
||||
translatedResponse = await opts.adapter(opts);
|
||||
translatedResponse = await opts.adapter(opts, this._defaultAdapter.bind(this));
|
||||
}
|
||||
else {
|
||||
const res = await fetch(opts.url, opts);
|
||||
const data = await this.getResponseData(opts, res);
|
||||
translatedResponse = this.translateResponse(opts, res, data);
|
||||
translatedResponse = await this._defaultAdapter(opts);
|
||||
}
|
||||
if (!opts.validateStatus(translatedResponse.status)) {
|
||||
throw new common_1.GaxiosError(`Request failed with status code ${translatedResponse.status}`, opts, translatedResponse);
|
||||
@@ -101,13 +100,16 @@ class Gaxios {
|
||||
switch (opts.responseType) {
|
||||
case 'stream':
|
||||
return res.body;
|
||||
case 'json':
|
||||
case 'json': {
|
||||
let data = await res.text();
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
}
|
||||
catch (e) { }
|
||||
catch (_a) {
|
||||
// continue
|
||||
}
|
||||
return data;
|
||||
}
|
||||
case 'arraybuffer':
|
||||
return res.arrayBuffer();
|
||||
case 'blob':
|
||||
@@ -130,15 +132,15 @@ class Gaxios {
|
||||
if (baseUrl) {
|
||||
opts.url = baseUrl + opts.url;
|
||||
}
|
||||
const parsedUrl = new URL(opts.url);
|
||||
opts.url = `${parsedUrl.origin}${parsedUrl.pathname}`;
|
||||
opts.params = extend_1.default(querystring_1.default.parse(parsedUrl.search.substr(1)), // removes leading ?
|
||||
opts.params);
|
||||
opts.paramsSerializer = opts.paramsSerializer || this.paramsSerializer;
|
||||
if (opts.params) {
|
||||
parsedUrl.search = opts.paramsSerializer(opts.params);
|
||||
if (opts.params && Object.keys(opts.params).length > 0) {
|
||||
let additionalQueryParams = opts.paramsSerializer(opts.params);
|
||||
if (additionalQueryParams.startsWith('?')) {
|
||||
additionalQueryParams = additionalQueryParams.slice(1);
|
||||
}
|
||||
const prefix = opts.url.includes('?') ? '&' : '?';
|
||||
opts.url = opts.url + prefix + additionalQueryParams;
|
||||
}
|
||||
opts.url = parsedUrl.href;
|
||||
if (typeof options.maxContentLength === 'number') {
|
||||
opts.size = options.maxContentLength;
|
||||
}
|
||||
@@ -152,7 +154,18 @@ class Gaxios {
|
||||
}
|
||||
else if (typeof opts.data === 'object') {
|
||||
opts.body = JSON.stringify(opts.data);
|
||||
opts.headers['Content-Type'] = 'application/json';
|
||||
// Allow the user to specifiy their own content type,
|
||||
// such as application/json-patch+json; for historical reasons this
|
||||
// content type must currently be a json type, as we are relying on
|
||||
// application/x-www-form-urlencoded (which is incompatible with
|
||||
// upstream GCP APIs) being rewritten to application/json.
|
||||
//
|
||||
// TODO: refactor upstream dependencies to stop relying on this
|
||||
// side-effect.
|
||||
if (!opts.headers['Content-Type'] ||
|
||||
!opts.headers['Content-Type'].includes('json')) {
|
||||
opts.headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
}
|
||||
else {
|
||||
opts.body = opts.data;
|
||||
@@ -202,6 +215,10 @@ class Gaxios {
|
||||
headers,
|
||||
status: res.status,
|
||||
statusText: res.statusText,
|
||||
// XMLHttpRequestLike
|
||||
request: {
|
||||
responseURL: res.url,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user