Node modules removed
This commit is contained in:
parent
339120c6a5
commit
51c273cb85
222 changed files with 0 additions and 27237 deletions
4
node_modules/typed-rest-client/Handlers.d.ts
generated
vendored
4
node_modules/typed-rest-client/Handlers.d.ts
generated
vendored
|
@ -1,4 +0,0 @@
|
|||
export { BasicCredentialHandler } from "./handlers/basiccreds";
|
||||
export { BearerCredentialHandler } from "./handlers/bearertoken";
|
||||
export { NtlmCredentialHandler } from "./handlers/ntlm";
|
||||
export { PersonalAccessTokenCredentialHandler } from "./handlers/personalaccesstoken";
|
10
node_modules/typed-rest-client/Handlers.js
generated
vendored
10
node_modules/typed-rest-client/Handlers.js
generated
vendored
|
@ -1,10 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var basiccreds_1 = require("./handlers/basiccreds");
|
||||
exports.BasicCredentialHandler = basiccreds_1.BasicCredentialHandler;
|
||||
var bearertoken_1 = require("./handlers/bearertoken");
|
||||
exports.BearerCredentialHandler = bearertoken_1.BearerCredentialHandler;
|
||||
var ntlm_1 = require("./handlers/ntlm");
|
||||
exports.NtlmCredentialHandler = ntlm_1.NtlmCredentialHandler;
|
||||
var personalaccesstoken_1 = require("./handlers/personalaccesstoken");
|
||||
exports.PersonalAccessTokenCredentialHandler = personalaccesstoken_1.PersonalAccessTokenCredentialHandler;
|
103
node_modules/typed-rest-client/HttpClient.d.ts
generated
vendored
103
node_modules/typed-rest-client/HttpClient.d.ts
generated
vendored
|
@ -1,103 +0,0 @@
|
|||
/// <reference types="node" />
|
||||
import url = require("url");
|
||||
import http = require("http");
|
||||
import ifm = require('./Interfaces');
|
||||
export declare enum HttpCodes {
|
||||
OK = 200,
|
||||
MultipleChoices = 300,
|
||||
MovedPermanently = 301,
|
||||
ResourceMoved = 302,
|
||||
SeeOther = 303,
|
||||
NotModified = 304,
|
||||
UseProxy = 305,
|
||||
SwitchProxy = 306,
|
||||
TemporaryRedirect = 307,
|
||||
PermanentRedirect = 308,
|
||||
BadRequest = 400,
|
||||
Unauthorized = 401,
|
||||
PaymentRequired = 402,
|
||||
Forbidden = 403,
|
||||
NotFound = 404,
|
||||
MethodNotAllowed = 405,
|
||||
NotAcceptable = 406,
|
||||
ProxyAuthenticationRequired = 407,
|
||||
RequestTimeout = 408,
|
||||
Conflict = 409,
|
||||
Gone = 410,
|
||||
InternalServerError = 500,
|
||||
NotImplemented = 501,
|
||||
BadGateway = 502,
|
||||
ServiceUnavailable = 503,
|
||||
GatewayTimeout = 504,
|
||||
}
|
||||
export declare class HttpClientResponse implements ifm.IHttpClientResponse {
|
||||
constructor(message: http.IncomingMessage);
|
||||
message: http.IncomingMessage;
|
||||
readBody(): Promise<string>;
|
||||
}
|
||||
export interface RequestInfo {
|
||||
options: http.RequestOptions;
|
||||
parsedUrl: url.Url;
|
||||
httpModule: any;
|
||||
}
|
||||
export declare function isHttps(requestUrl: string): boolean;
|
||||
export declare class HttpClient implements ifm.IHttpClient {
|
||||
userAgent: string;
|
||||
handlers: ifm.IRequestHandler[];
|
||||
requestOptions: ifm.IRequestOptions;
|
||||
private _ignoreSslError;
|
||||
private _socketTimeout;
|
||||
private _httpProxy;
|
||||
private _httpProxyBypassHosts;
|
||||
private _allowRedirects;
|
||||
private _maxRedirects;
|
||||
private _allowRetries;
|
||||
private _maxRetries;
|
||||
private _agent;
|
||||
private _proxyAgent;
|
||||
private _keepAlive;
|
||||
private _disposed;
|
||||
private _certConfig;
|
||||
private _ca;
|
||||
private _cert;
|
||||
private _key;
|
||||
constructor(userAgent: string, handlers?: ifm.IRequestHandler[], requestOptions?: ifm.IRequestOptions);
|
||||
options(requestUrl: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
||||
get(requestUrl: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
||||
del(requestUrl: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
||||
post(requestUrl: string, data: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
||||
patch(requestUrl: string, data: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
||||
put(requestUrl: string, data: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
||||
head(requestUrl: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
||||
sendStream(verb: string, requestUrl: string, stream: NodeJS.ReadableStream, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
||||
/**
|
||||
* Makes a raw http request.
|
||||
* All other methods such as get, post, patch, and request ultimately call this.
|
||||
* Prefer get, del, post and patch
|
||||
*/
|
||||
request(verb: string, requestUrl: string, data: string | NodeJS.ReadableStream, headers: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
||||
/**
|
||||
* Needs to be called if keepAlive is set to true in request options.
|
||||
*/
|
||||
dispose(): void;
|
||||
/**
|
||||
* Raw request.
|
||||
* @param info
|
||||
* @param data
|
||||
*/
|
||||
requestRaw(info: ifm.IRequestInfo, data: string | NodeJS.ReadableStream): Promise<ifm.IHttpClientResponse>;
|
||||
/**
|
||||
* Raw request with callback.
|
||||
* @param info
|
||||
* @param data
|
||||
* @param onResult
|
||||
*/
|
||||
requestRawWithCallback(info: ifm.IRequestInfo, data: string | NodeJS.ReadableStream, onResult: (err: any, res: ifm.IHttpClientResponse) => void): void;
|
||||
private _prepareRequest(method, requestUrl, headers);
|
||||
private _isPresigned(requestUrl);
|
||||
private _mergeHeaders(headers);
|
||||
private _getAgent(requestUrl);
|
||||
private _getProxy(requestUrl);
|
||||
private _isBypassProxy(requestUrl);
|
||||
private _performExponentialBackoff(retryNumber);
|
||||
}
|
455
node_modules/typed-rest-client/HttpClient.js
generated
vendored
455
node_modules/typed-rest-client/HttpClient.js
generated
vendored
|
@ -1,455 +0,0 @@
|
|||
"use strict";
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const url = require("url");
|
||||
const http = require("http");
|
||||
const https = require("https");
|
||||
let fs;
|
||||
let tunnel;
|
||||
var HttpCodes;
|
||||
(function (HttpCodes) {
|
||||
HttpCodes[HttpCodes["OK"] = 200] = "OK";
|
||||
HttpCodes[HttpCodes["MultipleChoices"] = 300] = "MultipleChoices";
|
||||
HttpCodes[HttpCodes["MovedPermanently"] = 301] = "MovedPermanently";
|
||||
HttpCodes[HttpCodes["ResourceMoved"] = 302] = "ResourceMoved";
|
||||
HttpCodes[HttpCodes["SeeOther"] = 303] = "SeeOther";
|
||||
HttpCodes[HttpCodes["NotModified"] = 304] = "NotModified";
|
||||
HttpCodes[HttpCodes["UseProxy"] = 305] = "UseProxy";
|
||||
HttpCodes[HttpCodes["SwitchProxy"] = 306] = "SwitchProxy";
|
||||
HttpCodes[HttpCodes["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
||||
HttpCodes[HttpCodes["PermanentRedirect"] = 308] = "PermanentRedirect";
|
||||
HttpCodes[HttpCodes["BadRequest"] = 400] = "BadRequest";
|
||||
HttpCodes[HttpCodes["Unauthorized"] = 401] = "Unauthorized";
|
||||
HttpCodes[HttpCodes["PaymentRequired"] = 402] = "PaymentRequired";
|
||||
HttpCodes[HttpCodes["Forbidden"] = 403] = "Forbidden";
|
||||
HttpCodes[HttpCodes["NotFound"] = 404] = "NotFound";
|
||||
HttpCodes[HttpCodes["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
||||
HttpCodes[HttpCodes["NotAcceptable"] = 406] = "NotAcceptable";
|
||||
HttpCodes[HttpCodes["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
||||
HttpCodes[HttpCodes["RequestTimeout"] = 408] = "RequestTimeout";
|
||||
HttpCodes[HttpCodes["Conflict"] = 409] = "Conflict";
|
||||
HttpCodes[HttpCodes["Gone"] = 410] = "Gone";
|
||||
HttpCodes[HttpCodes["InternalServerError"] = 500] = "InternalServerError";
|
||||
HttpCodes[HttpCodes["NotImplemented"] = 501] = "NotImplemented";
|
||||
HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway";
|
||||
HttpCodes[HttpCodes["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
||||
HttpCodes[HttpCodes["GatewayTimeout"] = 504] = "GatewayTimeout";
|
||||
})(HttpCodes = exports.HttpCodes || (exports.HttpCodes = {}));
|
||||
const HttpRedirectCodes = [HttpCodes.MovedPermanently, HttpCodes.ResourceMoved, HttpCodes.SeeOther, HttpCodes.TemporaryRedirect, HttpCodes.PermanentRedirect];
|
||||
const HttpResponseRetryCodes = [HttpCodes.BadGateway, HttpCodes.ServiceUnavailable, HttpCodes.GatewayTimeout];
|
||||
const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD'];
|
||||
const ExponentialBackoffCeiling = 10;
|
||||
const ExponentialBackoffTimeSlice = 5;
|
||||
class HttpClientResponse {
|
||||
constructor(message) {
|
||||
this.message = message;
|
||||
}
|
||||
readBody() {
|
||||
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
||||
let output = '';
|
||||
this.message.on('data', (chunk) => {
|
||||
output += chunk;
|
||||
});
|
||||
this.message.on('end', () => {
|
||||
resolve(output);
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
exports.HttpClientResponse = HttpClientResponse;
|
||||
function isHttps(requestUrl) {
|
||||
let parsedUrl = url.parse(requestUrl);
|
||||
return parsedUrl.protocol === 'https:';
|
||||
}
|
||||
exports.isHttps = isHttps;
|
||||
var EnvironmentVariables;
|
||||
(function (EnvironmentVariables) {
|
||||
EnvironmentVariables["HTTP_PROXY"] = "HTTP_PROXY";
|
||||
EnvironmentVariables["HTTPS_PROXY"] = "HTTPS_PROXY";
|
||||
})(EnvironmentVariables || (EnvironmentVariables = {}));
|
||||
class HttpClient {
|
||||
constructor(userAgent, handlers, requestOptions) {
|
||||
this._ignoreSslError = false;
|
||||
this._allowRedirects = true;
|
||||
this._maxRedirects = 50;
|
||||
this._allowRetries = false;
|
||||
this._maxRetries = 1;
|
||||
this._keepAlive = false;
|
||||
this._disposed = false;
|
||||
this.userAgent = userAgent;
|
||||
this.handlers = handlers || [];
|
||||
this.requestOptions = requestOptions;
|
||||
if (requestOptions) {
|
||||
if (requestOptions.ignoreSslError != null) {
|
||||
this._ignoreSslError = requestOptions.ignoreSslError;
|
||||
}
|
||||
this._socketTimeout = requestOptions.socketTimeout;
|
||||
this._httpProxy = requestOptions.proxy;
|
||||
if (requestOptions.proxy && requestOptions.proxy.proxyBypassHosts) {
|
||||
this._httpProxyBypassHosts = [];
|
||||
requestOptions.proxy.proxyBypassHosts.forEach(bypass => {
|
||||
this._httpProxyBypassHosts.push(new RegExp(bypass, 'i'));
|
||||
});
|
||||
}
|
||||
this._certConfig = requestOptions.cert;
|
||||
if (this._certConfig) {
|
||||
// If using cert, need fs
|
||||
fs = require('fs');
|
||||
// cache the cert content into memory, so we don't have to read it from disk every time
|
||||
if (this._certConfig.caFile && fs.existsSync(this._certConfig.caFile)) {
|
||||
this._ca = fs.readFileSync(this._certConfig.caFile, 'utf8');
|
||||
}
|
||||
if (this._certConfig.certFile && fs.existsSync(this._certConfig.certFile)) {
|
||||
this._cert = fs.readFileSync(this._certConfig.certFile, 'utf8');
|
||||
}
|
||||
if (this._certConfig.keyFile && fs.existsSync(this._certConfig.keyFile)) {
|
||||
this._key = fs.readFileSync(this._certConfig.keyFile, 'utf8');
|
||||
}
|
||||
}
|
||||
if (requestOptions.allowRedirects != null) {
|
||||
this._allowRedirects = requestOptions.allowRedirects;
|
||||
}
|
||||
if (requestOptions.maxRedirects != null) {
|
||||
this._maxRedirects = Math.max(requestOptions.maxRedirects, 0);
|
||||
}
|
||||
if (requestOptions.keepAlive != null) {
|
||||
this._keepAlive = requestOptions.keepAlive;
|
||||
}
|
||||
if (requestOptions.allowRetries != null) {
|
||||
this._allowRetries = requestOptions.allowRetries;
|
||||
}
|
||||
if (requestOptions.maxRetries != null) {
|
||||
this._maxRetries = requestOptions.maxRetries;
|
||||
}
|
||||
}
|
||||
}
|
||||
options(requestUrl, additionalHeaders) {
|
||||
return this.request('OPTIONS', requestUrl, null, additionalHeaders || {});
|
||||
}
|
||||
get(requestUrl, additionalHeaders) {
|
||||
return this.request('GET', requestUrl, null, additionalHeaders || {});
|
||||
}
|
||||
del(requestUrl, additionalHeaders) {
|
||||
return this.request('DELETE', requestUrl, null, additionalHeaders || {});
|
||||
}
|
||||
post(requestUrl, data, additionalHeaders) {
|
||||
return this.request('POST', requestUrl, data, additionalHeaders || {});
|
||||
}
|
||||
patch(requestUrl, data, additionalHeaders) {
|
||||
return this.request('PATCH', requestUrl, data, additionalHeaders || {});
|
||||
}
|
||||
put(requestUrl, data, additionalHeaders) {
|
||||
return this.request('PUT', requestUrl, data, additionalHeaders || {});
|
||||
}
|
||||
head(requestUrl, additionalHeaders) {
|
||||
return this.request('HEAD', requestUrl, null, additionalHeaders || {});
|
||||
}
|
||||
sendStream(verb, requestUrl, stream, additionalHeaders) {
|
||||
return this.request(verb, requestUrl, stream, additionalHeaders);
|
||||
}
|
||||
/**
|
||||
* Makes a raw http request.
|
||||
* All other methods such as get, post, patch, and request ultimately call this.
|
||||
* Prefer get, del, post and patch
|
||||
*/
|
||||
request(verb, requestUrl, data, headers) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (this._disposed) {
|
||||
throw new Error("Client has already been disposed.");
|
||||
}
|
||||
let info = this._prepareRequest(verb, requestUrl, headers);
|
||||
// Only perform retries on reads since writes may not be idempotent.
|
||||
let maxTries = (this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1) ? this._maxRetries + 1 : 1;
|
||||
let numTries = 0;
|
||||
let response;
|
||||
while (numTries < maxTries) {
|
||||
response = yield this.requestRaw(info, data);
|
||||
// Check if it's an authentication challenge
|
||||
if (response && response.message && response.message.statusCode === HttpCodes.Unauthorized) {
|
||||
let authenticationHandler;
|
||||
for (let i = 0; i < this.handlers.length; i++) {
|
||||
if (this.handlers[i].canHandleAuthentication(response)) {
|
||||
authenticationHandler = this.handlers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (authenticationHandler) {
|
||||
return authenticationHandler.handleAuthentication(this, info, data);
|
||||
}
|
||||
else {
|
||||
// We have received an unauthorized response but have no handlers to handle it.
|
||||
// Let the response return to the caller.
|
||||
return response;
|
||||
}
|
||||
}
|
||||
let redirectsRemaining = this._maxRedirects;
|
||||
while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1
|
||||
&& this._allowRedirects
|
||||
&& redirectsRemaining > 0) {
|
||||
const redirectUrl = response.message.headers["location"];
|
||||
if (!redirectUrl) {
|
||||
// if there's no location to redirect to, we won't
|
||||
break;
|
||||
}
|
||||
// we need to finish reading the response before reassigning response
|
||||
// which will leak the open socket.
|
||||
yield response.readBody();
|
||||
// let's make the request with the new redirectUrl
|
||||
info = this._prepareRequest(verb, redirectUrl, headers);
|
||||
response = yield this.requestRaw(info, data);
|
||||
redirectsRemaining--;
|
||||
}
|
||||
if (HttpResponseRetryCodes.indexOf(response.message.statusCode) == -1) {
|
||||
// If not a retry code, return immediately instead of retrying
|
||||
return response;
|
||||
}
|
||||
numTries += 1;
|
||||
if (numTries < maxTries) {
|
||||
yield response.readBody();
|
||||
yield this._performExponentialBackoff(numTries);
|
||||
}
|
||||
}
|
||||
return response;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Needs to be called if keepAlive is set to true in request options.
|
||||
*/
|
||||
dispose() {
|
||||
if (this._agent) {
|
||||
this._agent.destroy();
|
||||
}
|
||||
this._disposed = true;
|
||||
}
|
||||
/**
|
||||
* Raw request.
|
||||
* @param info
|
||||
* @param data
|
||||
*/
|
||||
requestRaw(info, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let callbackForResult = function (err, res) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
resolve(res);
|
||||
};
|
||||
this.requestRawWithCallback(info, data, callbackForResult);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Raw request with callback.
|
||||
* @param info
|
||||
* @param data
|
||||
* @param onResult
|
||||
*/
|
||||
requestRawWithCallback(info, data, onResult) {
|
||||
let socket;
|
||||
let isDataString = typeof (data) === 'string';
|
||||
if (typeof (data) === 'string') {
|
||||
info.options.headers["Content-Length"] = Buffer.byteLength(data, 'utf8');
|
||||
}
|
||||
let callbackCalled = false;
|
||||
let handleResult = (err, res) => {
|
||||
if (!callbackCalled) {
|
||||
callbackCalled = true;
|
||||
onResult(err, res);
|
||||
}
|
||||
};
|
||||
let req = info.httpModule.request(info.options, (msg) => {
|
||||
let res = new HttpClientResponse(msg);
|
||||
handleResult(null, res);
|
||||
});
|
||||
req.on('socket', (sock) => {
|
||||
socket = sock;
|
||||
});
|
||||
// If we ever get disconnected, we want the socket to timeout eventually
|
||||
req.setTimeout(this._socketTimeout || 3 * 60000, () => {
|
||||
if (socket) {
|
||||
socket.end();
|
||||
}
|
||||
handleResult(new Error('Request timeout: ' + info.options.path), null);
|
||||
});
|
||||
req.on('error', function (err) {
|
||||
// err has statusCode property
|
||||
// res should have headers
|
||||
handleResult(err, null);
|
||||
});
|
||||
if (data && typeof (data) === 'string') {
|
||||
req.write(data, 'utf8');
|
||||
}
|
||||
if (data && typeof (data) !== 'string') {
|
||||
data.on('close', function () {
|
||||
req.end();
|
||||
});
|
||||
data.pipe(req);
|
||||
}
|
||||
else {
|
||||
req.end();
|
||||
}
|
||||
}
|
||||
_prepareRequest(method, requestUrl, headers) {
|
||||
const info = {};
|
||||
info.parsedUrl = url.parse(requestUrl);
|
||||
const usingSsl = info.parsedUrl.protocol === 'https:';
|
||||
info.httpModule = usingSsl ? https : http;
|
||||
const defaultPort = usingSsl ? 443 : 80;
|
||||
info.options = {};
|
||||
info.options.host = info.parsedUrl.hostname;
|
||||
info.options.port = info.parsedUrl.port ? parseInt(info.parsedUrl.port) : defaultPort;
|
||||
info.options.path = (info.parsedUrl.pathname || '') + (info.parsedUrl.search || '');
|
||||
info.options.method = method;
|
||||
info.options.headers = this._mergeHeaders(headers);
|
||||
info.options.headers["user-agent"] = this.userAgent;
|
||||
info.options.agent = this._getAgent(requestUrl);
|
||||
// gives handlers an opportunity to participate
|
||||
if (this.handlers && !this._isPresigned(requestUrl)) {
|
||||
this.handlers.forEach((handler) => {
|
||||
handler.prepareRequest(info.options);
|
||||
});
|
||||
}
|
||||
return info;
|
||||
}
|
||||
_isPresigned(requestUrl) {
|
||||
if (this.requestOptions && this.requestOptions.presignedUrlPatterns) {
|
||||
const patterns = this.requestOptions.presignedUrlPatterns;
|
||||
for (let i = 0; i < patterns.length; i++) {
|
||||
if (requestUrl.match(patterns[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
_mergeHeaders(headers) {
|
||||
const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (c[k.toLowerCase()] = obj[k], c), {});
|
||||
if (this.requestOptions && this.requestOptions.headers) {
|
||||
return Object.assign({}, lowercaseKeys(this.requestOptions.headers), lowercaseKeys(headers));
|
||||
}
|
||||
return lowercaseKeys(headers || {});
|
||||
}
|
||||
_getAgent(requestUrl) {
|
||||
let agent;
|
||||
let proxy = this._getProxy(requestUrl);
|
||||
let useProxy = proxy.proxyUrl && proxy.proxyUrl.hostname && !this._isBypassProxy(requestUrl);
|
||||
if (this._keepAlive && useProxy) {
|
||||
agent = this._proxyAgent;
|
||||
}
|
||||
if (this._keepAlive && !useProxy) {
|
||||
agent = this._agent;
|
||||
}
|
||||
// if agent is already assigned use that agent.
|
||||
if (!!agent) {
|
||||
return agent;
|
||||
}
|
||||
let parsedUrl = url.parse(requestUrl);
|
||||
const usingSsl = parsedUrl.protocol === 'https:';
|
||||
let maxSockets = 100;
|
||||
if (!!this.requestOptions) {
|
||||
maxSockets = this.requestOptions.maxSockets || http.globalAgent.maxSockets;
|
||||
}
|
||||
if (useProxy) {
|
||||
// If using proxy, need tunnel
|
||||
if (!tunnel) {
|
||||
tunnel = require('tunnel');
|
||||
}
|
||||
const agentOptions = {
|
||||
maxSockets: maxSockets,
|
||||
keepAlive: this._keepAlive,
|
||||
proxy: {
|
||||
proxyAuth: proxy.proxyAuth,
|
||||
host: proxy.proxyUrl.hostname,
|
||||
port: proxy.proxyUrl.port
|
||||
},
|
||||
};
|
||||
let tunnelAgent;
|
||||
const overHttps = proxy.proxyUrl.protocol === 'https:';
|
||||
if (usingSsl) {
|
||||
tunnelAgent = overHttps ? tunnel.httpsOverHttps : tunnel.httpsOverHttp;
|
||||
}
|
||||
else {
|
||||
tunnelAgent = overHttps ? tunnel.httpOverHttps : tunnel.httpOverHttp;
|
||||
}
|
||||
agent = tunnelAgent(agentOptions);
|
||||
this._proxyAgent = agent;
|
||||
}
|
||||
// if reusing agent across request and tunneling agent isn't assigned create a new agent
|
||||
if (this._keepAlive && !agent) {
|
||||
const options = { keepAlive: this._keepAlive, maxSockets: maxSockets };
|
||||
agent = usingSsl ? new https.Agent(options) : new http.Agent(options);
|
||||
this._agent = agent;
|
||||
}
|
||||
// if not using private agent and tunnel agent isn't setup then use global agent
|
||||
if (!agent) {
|
||||
agent = usingSsl ? https.globalAgent : http.globalAgent;
|
||||
}
|
||||
if (usingSsl && this._ignoreSslError) {
|
||||
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
|
||||
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
|
||||
// we have to cast it to any and change it directly
|
||||
agent.options = Object.assign(agent.options || {}, { rejectUnauthorized: false });
|
||||
}
|
||||
if (usingSsl && this._certConfig) {
|
||||
agent.options = Object.assign(agent.options || {}, { ca: this._ca, cert: this._cert, key: this._key, passphrase: this._certConfig.passphrase });
|
||||
}
|
||||
return agent;
|
||||
}
|
||||
_getProxy(requestUrl) {
|
||||
const parsedUrl = url.parse(requestUrl);
|
||||
let usingSsl = parsedUrl.protocol === 'https:';
|
||||
let proxyConfig = this._httpProxy;
|
||||
// fallback to http_proxy and https_proxy env
|
||||
let https_proxy = process.env[EnvironmentVariables.HTTPS_PROXY];
|
||||
let http_proxy = process.env[EnvironmentVariables.HTTP_PROXY];
|
||||
if (!proxyConfig) {
|
||||
if (https_proxy && usingSsl) {
|
||||
proxyConfig = {
|
||||
proxyUrl: https_proxy
|
||||
};
|
||||
}
|
||||
else if (http_proxy) {
|
||||
proxyConfig = {
|
||||
proxyUrl: http_proxy
|
||||
};
|
||||
}
|
||||
}
|
||||
let proxyUrl;
|
||||
let proxyAuth;
|
||||
if (proxyConfig) {
|
||||
if (proxyConfig.proxyUrl.length > 0) {
|
||||
proxyUrl = url.parse(proxyConfig.proxyUrl);
|
||||
}
|
||||
if (proxyConfig.proxyUsername || proxyConfig.proxyPassword) {
|
||||
proxyAuth = proxyConfig.proxyUsername + ":" + proxyConfig.proxyPassword;
|
||||
}
|
||||
}
|
||||
return { proxyUrl: proxyUrl, proxyAuth: proxyAuth };
|
||||
}
|
||||
_isBypassProxy(requestUrl) {
|
||||
if (!this._httpProxyBypassHosts) {
|
||||
return false;
|
||||
}
|
||||
let bypass = false;
|
||||
this._httpProxyBypassHosts.forEach(bypassHost => {
|
||||
if (bypassHost.test(requestUrl)) {
|
||||
bypass = true;
|
||||
}
|
||||
});
|
||||
return bypass;
|
||||
}
|
||||
_performExponentialBackoff(retryNumber) {
|
||||
retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber);
|
||||
const ms = ExponentialBackoffTimeSlice * Math.pow(2, retryNumber);
|
||||
return new Promise(resolve => setTimeout(() => resolve(), ms));
|
||||
}
|
||||
}
|
||||
exports.HttpClient = HttpClient;
|
0
node_modules/typed-rest-client/Index.d.ts
generated
vendored
0
node_modules/typed-rest-client/Index.d.ts
generated
vendored
2
node_modules/typed-rest-client/Index.js
generated
vendored
2
node_modules/typed-rest-client/Index.js
generated
vendored
|
@ -1,2 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
62
node_modules/typed-rest-client/Interfaces.d.ts
generated
vendored
62
node_modules/typed-rest-client/Interfaces.d.ts
generated
vendored
|
@ -1,62 +0,0 @@
|
|||
/// <reference types="node" />
|
||||
import http = require("http");
|
||||
import url = require("url");
|
||||
export interface IHeaders {
|
||||
[key: string]: any;
|
||||
}
|
||||
export interface IBasicCredentials {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
export interface IHttpClient {
|
||||
options(requestUrl: string, additionalHeaders?: IHeaders): Promise<IHttpClientResponse>;
|
||||
get(requestUrl: string, additionalHeaders?: IHeaders): Promise<IHttpClientResponse>;
|
||||
del(requestUrl: string, additionalHeaders?: IHeaders): Promise<IHttpClientResponse>;
|
||||
post(requestUrl: string, data: string, additionalHeaders?: IHeaders): Promise<IHttpClientResponse>;
|
||||
patch(requestUrl: string, data: string, additionalHeaders?: IHeaders): Promise<IHttpClientResponse>;
|
||||
put(requestUrl: string, data: string, additionalHeaders?: IHeaders): Promise<IHttpClientResponse>;
|
||||
sendStream(verb: string, requestUrl: string, stream: NodeJS.ReadableStream, additionalHeaders?: IHeaders): Promise<IHttpClientResponse>;
|
||||
request(verb: string, requestUrl: string, data: string | NodeJS.ReadableStream, headers: IHeaders): Promise<IHttpClientResponse>;
|
||||
requestRaw(info: IRequestInfo, data: string | NodeJS.ReadableStream): Promise<IHttpClientResponse>;
|
||||
requestRawWithCallback(info: IRequestInfo, data: string | NodeJS.ReadableStream, onResult: (err: any, res: IHttpClientResponse) => void): void;
|
||||
}
|
||||
export interface IRequestHandler {
|
||||
prepareRequest(options: http.RequestOptions): void;
|
||||
canHandleAuthentication(response: IHttpClientResponse): boolean;
|
||||
handleAuthentication(httpClient: IHttpClient, requestInfo: IRequestInfo, objs: any): Promise<IHttpClientResponse>;
|
||||
}
|
||||
export interface IHttpClientResponse {
|
||||
message: http.IncomingMessage;
|
||||
readBody(): Promise<string>;
|
||||
}
|
||||
export interface IRequestInfo {
|
||||
options: http.RequestOptions;
|
||||
parsedUrl: url.Url;
|
||||
httpModule: any;
|
||||
}
|
||||
export interface IRequestOptions {
|
||||
headers?: IHeaders;
|
||||
socketTimeout?: number;
|
||||
ignoreSslError?: boolean;
|
||||
proxy?: IProxyConfiguration;
|
||||
cert?: ICertConfiguration;
|
||||
allowRedirects?: boolean;
|
||||
maxRedirects?: number;
|
||||
maxSockets?: number;
|
||||
keepAlive?: boolean;
|
||||
presignedUrlPatterns?: RegExp[];
|
||||
allowRetries?: boolean;
|
||||
maxRetries?: number;
|
||||
}
|
||||
export interface IProxyConfiguration {
|
||||
proxyUrl: string;
|
||||
proxyUsername?: string;
|
||||
proxyPassword?: string;
|
||||
proxyBypassHosts?: string[];
|
||||
}
|
||||
export interface ICertConfiguration {
|
||||
caFile?: string;
|
||||
certFile?: string;
|
||||
keyFile?: string;
|
||||
passphrase?: string;
|
||||
}
|
5
node_modules/typed-rest-client/Interfaces.js
generated
vendored
5
node_modules/typed-rest-client/Interfaces.js
generated
vendored
|
@ -1,5 +0,0 @@
|
|||
"use strict";
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
;
|
21
node_modules/typed-rest-client/LICENSE
generated
vendored
21
node_modules/typed-rest-client/LICENSE
generated
vendored
|
@ -1,21 +0,0 @@
|
|||
Typed Rest Client for Node.js
|
||||
|
||||
Copyright (c) Microsoft Corporation
|
||||
|
||||
All rights reserved.
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
100
node_modules/typed-rest-client/README.md
generated
vendored
100
node_modules/typed-rest-client/README.md
generated
vendored
|
@ -1,100 +0,0 @@
|
|||
[](https://dev.azure.com/ms/typed-rest-client/_build/latest?definitionId=42&branchName=master)
|
||||
|
||||
# Typed REST and HTTP Client with TypeScript Typings
|
||||
|
||||
A lightweight REST and HTTP client optimized for use with TypeScript with generics and async await.
|
||||
|
||||
## Features
|
||||
|
||||
- REST and HTTP client with TypeScript generics and async/await/Promises
|
||||
- Typings included so no need to acquire separately (great for intellisense and no versioning drift)
|
||||
- Basic, Bearer and NTLM Support out of the box. Extensible handlers for others.
|
||||
- Proxy support
|
||||
- Certificate support (Self-signed server and client cert)
|
||||
- Redirects supported
|
||||
|
||||
Intellisense and compile support:
|
||||
|
||||

|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
npm install typed-rest-client --save
|
||||
```
|
||||
|
||||
Or to install the latest preview:
|
||||
```
|
||||
npm install typed-rest-client@preview --save
|
||||
```
|
||||
|
||||
## Samples
|
||||
|
||||
See the [samples](./samples) for complete coding examples. Also see the [REST](./test/tests/resttests.ts) and [HTTP](./test/tests/httptests.ts) tests for detailed examples.
|
||||
|
||||
## Errors
|
||||
|
||||
### HTTP
|
||||
|
||||
The HTTP client does not throw unless truly exceptional.
|
||||
|
||||
* A request that successfully executes resulting in a 404, 500 etc... will return a response object with a status code and a body.
|
||||
* Redirects (3xx) will be followed by default.
|
||||
|
||||
|
||||
See [HTTP tests](./test/tests/httptests.ts) for detailed examples.
|
||||
|
||||
### REST
|
||||
|
||||
The REST client is a high-level client which uses the HTTP client. Its responsibility is to turn a body into a typed resource object.
|
||||
|
||||
* A 200 will be success.
|
||||
* Redirects (3xx) will be followed.
|
||||
* A 404 will not throw but the result object will be null and the result statusCode will be set.
|
||||
* Other 4xx and 5xx errors will throw. The status code will be attached to the error object. If a RESTful error object is returned (`{ message: xxx}`), then the error message will be that. Otherwise, it will be a generic, `Failed Request: (xxx)`.
|
||||
|
||||
See [REST tests](./test/tests/resttests.ts) for detailed examples.
|
||||
|
||||
## Debugging
|
||||
|
||||
To enable detailed console logging of all HTTP requests and responses, set the NODE_DEBUG environment varible:
|
||||
|
||||
```
|
||||
export NODE_DEBUG=http
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```
|
||||
set NODE_DEBUG=http
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Node support
|
||||
|
||||
The typed-rest-client is built using the latest LTS version of Node 8. We also support the latest LTS for Node 4 and Node 6.
|
||||
|
||||
## Contributing
|
||||
|
||||
To contribute to this repository, see the [contribution guide](./CONTRIBUTING.md)
|
||||
|
||||
To build:
|
||||
|
||||
```bash
|
||||
$ npm run build
|
||||
```
|
||||
|
||||
To run all tests:
|
||||
```bash
|
||||
$ npm test
|
||||
```
|
||||
|
||||
To just run unit tests:
|
||||
```bash
|
||||
$ npm run units
|
||||
```
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
77
node_modules/typed-rest-client/RestClient.d.ts
generated
vendored
77
node_modules/typed-rest-client/RestClient.d.ts
generated
vendored
|
@ -1,77 +0,0 @@
|
|||
/// <reference types="node" />
|
||||
import httpm = require('./HttpClient');
|
||||
import ifm = require("./Interfaces");
|
||||
export interface IRestResponse<T> {
|
||||
statusCode: number;
|
||||
result: T | null;
|
||||
headers: Object;
|
||||
}
|
||||
export interface IRequestOptions {
|
||||
acceptHeader?: string;
|
||||
additionalHeaders?: ifm.IHeaders;
|
||||
responseProcessor?: Function;
|
||||
deserializeDates?: boolean;
|
||||
}
|
||||
export declare class RestClient {
|
||||
client: httpm.HttpClient;
|
||||
versionParam: string;
|
||||
/**
|
||||
* Creates an instance of the RestClient
|
||||
* @constructor
|
||||
* @param {string} userAgent - userAgent for requests
|
||||
* @param {string} baseUrl - (Optional) If not specified, use full urls per request. If supplied and a function passes a relative url, it will be appended to this
|
||||
* @param {ifm.IRequestHandler[]} handlers - handlers are typically auth handlers (basic, bearer, ntlm supplied)
|
||||
* @param {ifm.IRequestOptions} requestOptions - options for each http requests (http proxy setting, socket timeout)
|
||||
*/
|
||||
constructor(userAgent: string, baseUrl?: string, handlers?: ifm.IRequestHandler[], requestOptions?: ifm.IRequestOptions);
|
||||
private _baseUrl;
|
||||
/**
|
||||
* Gets a resource from an endpoint
|
||||
* Be aware that not found returns a null. Other error conditions reject the promise
|
||||
* @param {string} requestUrl - fully qualified or relative url
|
||||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
||||
*/
|
||||
options<T>(requestUrl: string, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
||||
/**
|
||||
* Gets a resource from an endpoint
|
||||
* Be aware that not found returns a null. Other error conditions reject the promise
|
||||
* @param {string} resource - fully qualified url or relative path
|
||||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
||||
*/
|
||||
get<T>(resource: string, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
||||
/**
|
||||
* Deletes a resource from an endpoint
|
||||
* Be aware that not found returns a null. Other error conditions reject the promise
|
||||
* @param {string} resource - fully qualified or relative url
|
||||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
||||
*/
|
||||
del<T>(resource: string, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
||||
/**
|
||||
* Creates resource(s) from an endpoint
|
||||
* T type of object returned.
|
||||
* Be aware that not found returns a null. Other error conditions reject the promise
|
||||
* @param {string} resource - fully qualified or relative url
|
||||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
||||
*/
|
||||
create<T>(resource: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
||||
/**
|
||||
* Updates resource(s) from an endpoint
|
||||
* T type of object returned.
|
||||
* Be aware that not found returns a null. Other error conditions reject the promise
|
||||
* @param {string} resource - fully qualified or relative url
|
||||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
||||
*/
|
||||
update<T>(resource: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
||||
/**
|
||||
* Replaces resource(s) from an endpoint
|
||||
* T type of object returned.
|
||||
* Be aware that not found returns a null. Other error conditions reject the promise
|
||||
* @param {string} resource - fully qualified or relative url
|
||||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
||||
*/
|
||||
replace<T>(resource: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
||||
uploadStream<T>(verb: string, requestUrl: string, stream: NodeJS.ReadableStream, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
||||
private _headersFromOptions(options, contentType?);
|
||||
private static dateTimeDeserializer(key, value);
|
||||
private _processResponse<T>(res, options);
|
||||
}
|
217
node_modules/typed-rest-client/RestClient.js
generated
vendored
217
node_modules/typed-rest-client/RestClient.js
generated
vendored
|
@ -1,217 +0,0 @@
|
|||
"use strict";
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const httpm = require("./HttpClient");
|
||||
const util = require("./Util");
|
||||
class RestClient {
|
||||
/**
|
||||
* Creates an instance of the RestClient
|
||||
* @constructor
|
||||
* @param {string} userAgent - userAgent for requests
|
||||
* @param {string} baseUrl - (Optional) If not specified, use full urls per request. If supplied and a function passes a relative url, it will be appended to this
|
||||
* @param {ifm.IRequestHandler[]} handlers - handlers are typically auth handlers (basic, bearer, ntlm supplied)
|
||||
* @param {ifm.IRequestOptions} requestOptions - options for each http requests (http proxy setting, socket timeout)
|
||||
*/
|
||||
constructor(userAgent, baseUrl, handlers, requestOptions) {
|
||||
this.client = new httpm.HttpClient(userAgent, handlers, requestOptions);
|
||||
if (baseUrl) {
|
||||
this._baseUrl = baseUrl;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets a resource from an endpoint
|
||||
* Be aware that not found returns a null. Other error conditions reject the promise
|
||||
* @param {string} requestUrl - fully qualified or relative url
|
||||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
||||
*/
|
||||
options(requestUrl, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let url = util.getUrl(requestUrl, this._baseUrl);
|
||||
let res = yield this.client.options(url, this._headersFromOptions(options));
|
||||
return this._processResponse(res, options);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Gets a resource from an endpoint
|
||||
* Be aware that not found returns a null. Other error conditions reject the promise
|
||||
* @param {string} resource - fully qualified url or relative path
|
||||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
||||
*/
|
||||
get(resource, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let url = util.getUrl(resource, this._baseUrl);
|
||||
let res = yield this.client.get(url, this._headersFromOptions(options));
|
||||
return this._processResponse(res, options);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Deletes a resource from an endpoint
|
||||
* Be aware that not found returns a null. Other error conditions reject the promise
|
||||
* @param {string} resource - fully qualified or relative url
|
||||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
||||
*/
|
||||
del(resource, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let url = util.getUrl(resource, this._baseUrl);
|
||||
let res = yield this.client.del(url, this._headersFromOptions(options));
|
||||
return this._processResponse(res, options);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Creates resource(s) from an endpoint
|
||||
* T type of object returned.
|
||||
* Be aware that not found returns a null. Other error conditions reject the promise
|
||||
* @param {string} resource - fully qualified or relative url
|
||||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
||||
*/
|
||||
create(resource, resources, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let url = util.getUrl(resource, this._baseUrl);
|
||||
let headers = this._headersFromOptions(options, true);
|
||||
let data = JSON.stringify(resources, null, 2);
|
||||
let res = yield this.client.post(url, data, headers);
|
||||
return this._processResponse(res, options);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Updates resource(s) from an endpoint
|
||||
* T type of object returned.
|
||||
* Be aware that not found returns a null. Other error conditions reject the promise
|
||||
* @param {string} resource - fully qualified or relative url
|
||||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
||||
*/
|
||||
update(resource, resources, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let url = util.getUrl(resource, this._baseUrl);
|
||||
let headers = this._headersFromOptions(options, true);
|
||||
let data = JSON.stringify(resources, null, 2);
|
||||
let res = yield this.client.patch(url, data, headers);
|
||||
return this._processResponse(res, options);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Replaces resource(s) from an endpoint
|
||||
* T type of object returned.
|
||||
* Be aware that not found returns a null. Other error conditions reject the promise
|
||||
* @param {string} resource - fully qualified or relative url
|
||||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
||||
*/
|
||||
replace(resource, resources, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let url = util.getUrl(resource, this._baseUrl);
|
||||
let headers = this._headersFromOptions(options, true);
|
||||
let data = JSON.stringify(resources, null, 2);
|
||||
let res = yield this.client.put(url, data, headers);
|
||||
return this._processResponse(res, options);
|
||||
});
|
||||
}
|
||||
uploadStream(verb, requestUrl, stream, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let url = util.getUrl(requestUrl, this._baseUrl);
|
||||
let headers = this._headersFromOptions(options, true);
|
||||
let res = yield this.client.sendStream(verb, url, stream, headers);
|
||||
return this._processResponse(res, options);
|
||||
});
|
||||
}
|
||||
_headersFromOptions(options, contentType) {
|
||||
options = options || {};
|
||||
let headers = options.additionalHeaders || {};
|
||||
headers["Accept"] = options.acceptHeader || "application/json";
|
||||
if (contentType) {
|
||||
let found = false;
|
||||
for (let header in headers) {
|
||||
if (header.toLowerCase() == "content-type") {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
headers["Content-Type"] = 'application/json; charset=utf-8';
|
||||
}
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
static dateTimeDeserializer(key, value) {
|
||||
if (typeof value === 'string') {
|
||||
let a = new Date(value);
|
||||
if (!isNaN(a.valueOf())) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
_processResponse(res, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
||||
const statusCode = res.message.statusCode;
|
||||
const response = {
|
||||
statusCode: statusCode,
|
||||
result: null,
|
||||
headers: {}
|
||||
};
|
||||
// not found leads to null obj returned
|
||||
if (statusCode == httpm.HttpCodes.NotFound) {
|
||||
resolve(response);
|
||||
}
|
||||
let obj;
|
||||
let contents;
|
||||
// get the result from the body
|
||||
try {
|
||||
contents = yield res.readBody();
|
||||
if (contents && contents.length > 0) {
|
||||
if (options && options.deserializeDates) {
|
||||
obj = JSON.parse(contents, RestClient.dateTimeDeserializer);
|
||||
}
|
||||
else {
|
||||
obj = JSON.parse(contents);
|
||||
}
|
||||
if (options && options.responseProcessor) {
|
||||
response.result = options.responseProcessor(obj);
|
||||
}
|
||||
else {
|
||||
response.result = obj;
|
||||
}
|
||||
}
|
||||
response.headers = res.message.headers;
|
||||
}
|
||||
catch (err) {
|
||||
// Invalid resource (contents not json); leaving result obj null
|
||||
}
|
||||
// note that 3xx redirects are handled by the http layer.
|
||||
if (statusCode > 299) {
|
||||
let msg;
|
||||
// if exception/error in body, attempt to get better error
|
||||
if (obj && obj.message) {
|
||||
msg = obj.message;
|
||||
}
|
||||
else if (contents && contents.length > 0) {
|
||||
// it may be the case that the exception is in the body message as string
|
||||
msg = contents;
|
||||
}
|
||||
else {
|
||||
msg = "Failed request: (" + statusCode + ")";
|
||||
}
|
||||
let err = new Error(msg);
|
||||
// attach statusCode and body obj (if available) to the error object
|
||||
err['statusCode'] = statusCode;
|
||||
if (response.result) {
|
||||
err['result'] = response.result;
|
||||
}
|
||||
reject(err);
|
||||
}
|
||||
else {
|
||||
resolve(response);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.RestClient = RestClient;
|
1318
node_modules/typed-rest-client/ThirdPartyNotice.txt
generated
vendored
1318
node_modules/typed-rest-client/ThirdPartyNotice.txt
generated
vendored
File diff suppressed because it is too large
Load diff
7
node_modules/typed-rest-client/Util.d.ts
generated
vendored
7
node_modules/typed-rest-client/Util.d.ts
generated
vendored
|
@ -1,7 +0,0 @@
|
|||
/**
|
||||
* creates an url from a request url and optional base url (http://server:8080)
|
||||
* @param {string} resource - a fully qualified url or relative path
|
||||
* @param {string} baseUrl - an optional baseUrl (http://server:8080)
|
||||
* @return {string} - resultant url
|
||||
*/
|
||||
export declare function getUrl(resource: string, baseUrl?: string): string;
|
35
node_modules/typed-rest-client/Util.js
generated
vendored
35
node_modules/typed-rest-client/Util.js
generated
vendored
|
@ -1,35 +0,0 @@
|
|||
"use strict";
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const url = require("url");
|
||||
const path = require("path");
|
||||
/**
|
||||
* creates an url from a request url and optional base url (http://server:8080)
|
||||
* @param {string} resource - a fully qualified url or relative path
|
||||
* @param {string} baseUrl - an optional baseUrl (http://server:8080)
|
||||
* @return {string} - resultant url
|
||||
*/
|
||||
function getUrl(resource, baseUrl) {
|
||||
const pathApi = path.posix || path;
|
||||
if (!baseUrl) {
|
||||
return resource;
|
||||
}
|
||||
else if (!resource) {
|
||||
return baseUrl;
|
||||
}
|
||||
else {
|
||||
const base = url.parse(baseUrl);
|
||||
const resultantUrl = url.parse(resource);
|
||||
// resource (specific per request) elements take priority
|
||||
resultantUrl.protocol = resultantUrl.protocol || base.protocol;
|
||||
resultantUrl.auth = resultantUrl.auth || base.auth;
|
||||
resultantUrl.host = resultantUrl.host || base.host;
|
||||
resultantUrl.pathname = pathApi.resolve(base.pathname, resultantUrl.pathname);
|
||||
if (!resultantUrl.pathname.endsWith('/') && resource.endsWith('/')) {
|
||||
resultantUrl.pathname += '/';
|
||||
}
|
||||
return url.format(resultantUrl);
|
||||
}
|
||||
}
|
||||
exports.getUrl = getUrl;
|
9
node_modules/typed-rest-client/handlers/basiccreds.d.ts
generated
vendored
9
node_modules/typed-rest-client/handlers/basiccreds.d.ts
generated
vendored
|
@ -1,9 +0,0 @@
|
|||
import ifm = require('../Interfaces');
|
||||
export declare class BasicCredentialHandler implements ifm.IRequestHandler {
|
||||
username: string;
|
||||
password: string;
|
||||
constructor(username: string, password: string);
|
||||
prepareRequest(options: any): void;
|
||||
canHandleAuthentication(response: ifm.IHttpClientResponse): boolean;
|
||||
handleAuthentication(httpClient: ifm.IHttpClient, requestInfo: ifm.IRequestInfo, objs: any): Promise<ifm.IHttpClientResponse>;
|
||||
}
|
24
node_modules/typed-rest-client/handlers/basiccreds.js
generated
vendored
24
node_modules/typed-rest-client/handlers/basiccreds.js
generated
vendored
|
@ -1,24 +0,0 @@
|
|||
"use strict";
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class BasicCredentialHandler {
|
||||
constructor(username, password) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
// currently implements pre-authorization
|
||||
// TODO: support preAuth = false where it hooks on 401
|
||||
prepareRequest(options) {
|
||||
options.headers['Authorization'] = 'Basic ' + new Buffer(this.username + ':' + this.password).toString('base64');
|
||||
options.headers['X-TFS-FedAuthRedirect'] = 'Suppress';
|
||||
}
|
||||
// This handler cannot handle 401
|
||||
canHandleAuthentication(response) {
|
||||
return false;
|
||||
}
|
||||
handleAuthentication(httpClient, requestInfo, objs) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.BasicCredentialHandler = BasicCredentialHandler;
|
8
node_modules/typed-rest-client/handlers/bearertoken.d.ts
generated
vendored
8
node_modules/typed-rest-client/handlers/bearertoken.d.ts
generated
vendored
|
@ -1,8 +0,0 @@
|
|||
import ifm = require('../Interfaces');
|
||||
export declare class BearerCredentialHandler implements ifm.IRequestHandler {
|
||||
token: string;
|
||||
constructor(token: string);
|
||||
prepareRequest(options: any): void;
|
||||
canHandleAuthentication(response: ifm.IHttpClientResponse): boolean;
|
||||
handleAuthentication(httpClient: ifm.IHttpClient, requestInfo: ifm.IRequestInfo, objs: any): Promise<ifm.IHttpClientResponse>;
|
||||
}
|
23
node_modules/typed-rest-client/handlers/bearertoken.js
generated
vendored
23
node_modules/typed-rest-client/handlers/bearertoken.js
generated
vendored
|
@ -1,23 +0,0 @@
|
|||
"use strict";
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class BearerCredentialHandler {
|
||||
constructor(token) {
|
||||
this.token = token;
|
||||
}
|
||||
// currently implements pre-authorization
|
||||
// TODO: support preAuth = false where it hooks on 401
|
||||
prepareRequest(options) {
|
||||
options.headers['Authorization'] = 'Bearer ' + this.token;
|
||||
options.headers['X-TFS-FedAuthRedirect'] = 'Suppress';
|
||||
}
|
||||
// This handler cannot handle 401
|
||||
canHandleAuthentication(response) {
|
||||
return false;
|
||||
}
|
||||
handleAuthentication(httpClient, requestInfo, objs) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.BearerCredentialHandler = BearerCredentialHandler;
|
13
node_modules/typed-rest-client/handlers/ntlm.d.ts
generated
vendored
13
node_modules/typed-rest-client/handlers/ntlm.d.ts
generated
vendored
|
@ -1,13 +0,0 @@
|
|||
/// <reference types="node" />
|
||||
import ifm = require('../Interfaces');
|
||||
import http = require("http");
|
||||
export declare class NtlmCredentialHandler implements ifm.IRequestHandler {
|
||||
private _ntlmOptions;
|
||||
constructor(username: string, password: string, workstation?: string, domain?: string);
|
||||
prepareRequest(options: http.RequestOptions): void;
|
||||
canHandleAuthentication(response: ifm.IHttpClientResponse): boolean;
|
||||
handleAuthentication(httpClient: ifm.IHttpClient, requestInfo: ifm.IRequestInfo, objs: any): Promise<ifm.IHttpClientResponse>;
|
||||
private handleAuthenticationPrivate(httpClient, requestInfo, objs, finalCallback);
|
||||
private sendType1Message(httpClient, requestInfo, objs, finalCallback);
|
||||
private sendType3Message(httpClient, requestInfo, objs, res, callback);
|
||||
}
|
137
node_modules/typed-rest-client/handlers/ntlm.js
generated
vendored
137
node_modules/typed-rest-client/handlers/ntlm.js
generated
vendored
|
@ -1,137 +0,0 @@
|
|||
"use strict";
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const http = require("http");
|
||||
const https = require("https");
|
||||
const _ = require("underscore");
|
||||
const ntlm = require("../opensource/node-http-ntlm/ntlm");
|
||||
class NtlmCredentialHandler {
|
||||
constructor(username, password, workstation, domain) {
|
||||
this._ntlmOptions = {};
|
||||
this._ntlmOptions.username = username;
|
||||
this._ntlmOptions.password = password;
|
||||
if (domain !== undefined) {
|
||||
this._ntlmOptions.domain = domain;
|
||||
}
|
||||
else {
|
||||
this._ntlmOptions.domain = '';
|
||||
}
|
||||
if (workstation !== undefined) {
|
||||
this._ntlmOptions.workstation = workstation;
|
||||
}
|
||||
else {
|
||||
this._ntlmOptions.workstation = '';
|
||||
}
|
||||
}
|
||||
prepareRequest(options) {
|
||||
// No headers or options need to be set. We keep the credentials on the handler itself.
|
||||
// If a (proxy) agent is set, remove it as we don't support proxy for NTLM at this time
|
||||
if (options.agent) {
|
||||
delete options.agent;
|
||||
}
|
||||
}
|
||||
canHandleAuthentication(response) {
|
||||
if (response && response.message && response.message.statusCode === 401) {
|
||||
// Ensure that we're talking NTLM here
|
||||
// Once we have the www-authenticate header, split it so we can ensure we can talk NTLM
|
||||
const wwwAuthenticate = response.message.headers['www-authenticate'];
|
||||
if (wwwAuthenticate) {
|
||||
const mechanisms = wwwAuthenticate.split(', ');
|
||||
const index = mechanisms.indexOf("NTLM");
|
||||
if (index >= 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
handleAuthentication(httpClient, requestInfo, objs) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const callbackForResult = function (err, res) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
// We have to readbody on the response before continuing otherwise there is a hang.
|
||||
res.readBody().then(() => {
|
||||
resolve(res);
|
||||
});
|
||||
};
|
||||
this.handleAuthenticationPrivate(httpClient, requestInfo, objs, callbackForResult);
|
||||
});
|
||||
}
|
||||
handleAuthenticationPrivate(httpClient, requestInfo, objs, finalCallback) {
|
||||
// Set up the headers for NTLM authentication
|
||||
requestInfo.options = _.extend(requestInfo.options, {
|
||||
username: this._ntlmOptions.username,
|
||||
password: this._ntlmOptions.password,
|
||||
domain: this._ntlmOptions.domain,
|
||||
workstation: this._ntlmOptions.workstation
|
||||
});
|
||||
if (httpClient.isSsl === true) {
|
||||
requestInfo.options.agent = new https.Agent({ keepAlive: true });
|
||||
}
|
||||
else {
|
||||
requestInfo.options.agent = new http.Agent({ keepAlive: true });
|
||||
}
|
||||
let self = this;
|
||||
// The following pattern of sending the type1 message following immediately (in a setImmediate) is
|
||||
// critical for the NTLM exchange to happen. If we removed setImmediate (or call in a different manner)
|
||||
// the NTLM exchange will always fail with a 401.
|
||||
this.sendType1Message(httpClient, requestInfo, objs, function (err, res) {
|
||||
if (err) {
|
||||
return finalCallback(err, null, null);
|
||||
}
|
||||
/// We have to readbody on the response before continuing otherwise there is a hang.
|
||||
res.readBody().then(() => {
|
||||
// It is critical that we have setImmediate here due to how connection requests are queued.
|
||||
// If setImmediate is removed then the NTLM handshake will not work.
|
||||
// setImmediate allows us to queue a second request on the same connection. If this second
|
||||
// request is not queued on the connection when the first request finishes then node closes
|
||||
// the connection. NTLM requires both requests to be on the same connection so we need this.
|
||||
setImmediate(function () {
|
||||
self.sendType3Message(httpClient, requestInfo, objs, res, finalCallback);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
// The following method is an adaptation of code found at https://github.com/SamDecrock/node-http-ntlm/blob/master/httpntlm.js
|
||||
sendType1Message(httpClient, requestInfo, objs, finalCallback) {
|
||||
const type1msg = ntlm.createType1Message(this._ntlmOptions);
|
||||
const type1options = {
|
||||
headers: {
|
||||
'Connection': 'keep-alive',
|
||||
'Authorization': type1msg
|
||||
},
|
||||
timeout: requestInfo.options.timeout || 0,
|
||||
agent: requestInfo.httpModule,
|
||||
};
|
||||
const type1info = {};
|
||||
type1info.httpModule = requestInfo.httpModule;
|
||||
type1info.parsedUrl = requestInfo.parsedUrl;
|
||||
type1info.options = _.extend(type1options, _.omit(requestInfo.options, 'headers'));
|
||||
return httpClient.requestRawWithCallback(type1info, objs, finalCallback);
|
||||
}
|
||||
// The following method is an adaptation of code found at https://github.com/SamDecrock/node-http-ntlm/blob/master/httpntlm.js
|
||||
sendType3Message(httpClient, requestInfo, objs, res, callback) {
|
||||
if (!res.message.headers && !res.message.headers['www-authenticate']) {
|
||||
throw new Error('www-authenticate not found on response of second request');
|
||||
}
|
||||
const type2msg = ntlm.parseType2Message(res.message.headers['www-authenticate']);
|
||||
const type3msg = ntlm.createType3Message(type2msg, this._ntlmOptions);
|
||||
const type3options = {
|
||||
headers: {
|
||||
'Authorization': type3msg,
|
||||
'Connection': 'Close'
|
||||
},
|
||||
agent: requestInfo.httpModule,
|
||||
};
|
||||
const type3info = {};
|
||||
type3info.httpModule = requestInfo.httpModule;
|
||||
type3info.parsedUrl = requestInfo.parsedUrl;
|
||||
type3options.headers = _.extend(type3options.headers, requestInfo.options.headers);
|
||||
type3info.options = _.extend(type3options, _.omit(requestInfo.options, 'headers'));
|
||||
return httpClient.requestRawWithCallback(type3info, objs, callback);
|
||||
}
|
||||
}
|
||||
exports.NtlmCredentialHandler = NtlmCredentialHandler;
|
8
node_modules/typed-rest-client/handlers/personalaccesstoken.d.ts
generated
vendored
8
node_modules/typed-rest-client/handlers/personalaccesstoken.d.ts
generated
vendored
|
@ -1,8 +0,0 @@
|
|||
import ifm = require('../Interfaces');
|
||||
export declare class PersonalAccessTokenCredentialHandler implements ifm.IRequestHandler {
|
||||
token: string;
|
||||
constructor(token: string);
|
||||
prepareRequest(options: any): void;
|
||||
canHandleAuthentication(response: ifm.IHttpClientResponse): boolean;
|
||||
handleAuthentication(httpClient: ifm.IHttpClient, requestInfo: ifm.IRequestInfo, objs: any): Promise<ifm.IHttpClientResponse>;
|
||||
}
|
23
node_modules/typed-rest-client/handlers/personalaccesstoken.js
generated
vendored
23
node_modules/typed-rest-client/handlers/personalaccesstoken.js
generated
vendored
|
@ -1,23 +0,0 @@
|
|||
"use strict";
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class PersonalAccessTokenCredentialHandler {
|
||||
constructor(token) {
|
||||
this.token = token;
|
||||
}
|
||||
// currently implements pre-authorization
|
||||
// TODO: support preAuth = false where it hooks on 401
|
||||
prepareRequest(options) {
|
||||
options.headers['Authorization'] = 'Basic ' + new Buffer('PAT:' + this.token).toString('base64');
|
||||
options.headers['X-TFS-FedAuthRedirect'] = 'Suppress';
|
||||
}
|
||||
// This handler cannot handle 401
|
||||
canHandleAuthentication(response) {
|
||||
return false;
|
||||
}
|
||||
handleAuthentication(httpClient, requestInfo, objs) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHandler;
|
389
node_modules/typed-rest-client/opensource/node-http-ntlm/ntlm.js
generated
vendored
389
node_modules/typed-rest-client/opensource/node-http-ntlm/ntlm.js
generated
vendored
|
@ -1,389 +0,0 @@
|
|||
var crypto = require('crypto');
|
||||
|
||||
var flags = {
|
||||
NTLM_NegotiateUnicode : 0x00000001,
|
||||
NTLM_NegotiateOEM : 0x00000002,
|
||||
NTLM_RequestTarget : 0x00000004,
|
||||
NTLM_Unknown9 : 0x00000008,
|
||||
NTLM_NegotiateSign : 0x00000010,
|
||||
NTLM_NegotiateSeal : 0x00000020,
|
||||
NTLM_NegotiateDatagram : 0x00000040,
|
||||
NTLM_NegotiateLanManagerKey : 0x00000080,
|
||||
NTLM_Unknown8 : 0x00000100,
|
||||
NTLM_NegotiateNTLM : 0x00000200,
|
||||
NTLM_NegotiateNTOnly : 0x00000400,
|
||||
NTLM_Anonymous : 0x00000800,
|
||||
NTLM_NegotiateOemDomainSupplied : 0x00001000,
|
||||
NTLM_NegotiateOemWorkstationSupplied : 0x00002000,
|
||||
NTLM_Unknown6 : 0x00004000,
|
||||
NTLM_NegotiateAlwaysSign : 0x00008000,
|
||||
NTLM_TargetTypeDomain : 0x00010000,
|
||||
NTLM_TargetTypeServer : 0x00020000,
|
||||
NTLM_TargetTypeShare : 0x00040000,
|
||||
NTLM_NegotiateExtendedSecurity : 0x00080000,
|
||||
NTLM_NegotiateIdentify : 0x00100000,
|
||||
NTLM_Unknown5 : 0x00200000,
|
||||
NTLM_RequestNonNTSessionKey : 0x00400000,
|
||||
NTLM_NegotiateTargetInfo : 0x00800000,
|
||||
NTLM_Unknown4 : 0x01000000,
|
||||
NTLM_NegotiateVersion : 0x02000000,
|
||||
NTLM_Unknown3 : 0x04000000,
|
||||
NTLM_Unknown2 : 0x08000000,
|
||||
NTLM_Unknown1 : 0x10000000,
|
||||
NTLM_Negotiate128 : 0x20000000,
|
||||
NTLM_NegotiateKeyExchange : 0x40000000,
|
||||
NTLM_Negotiate56 : 0x80000000
|
||||
};
|
||||
var typeflags = {
|
||||
NTLM_TYPE1_FLAGS : flags.NTLM_NegotiateUnicode
|
||||
+ flags.NTLM_NegotiateOEM
|
||||
+ flags.NTLM_RequestTarget
|
||||
+ flags.NTLM_NegotiateNTLM
|
||||
+ flags.NTLM_NegotiateOemDomainSupplied
|
||||
+ flags.NTLM_NegotiateOemWorkstationSupplied
|
||||
+ flags.NTLM_NegotiateAlwaysSign
|
||||
+ flags.NTLM_NegotiateExtendedSecurity
|
||||
+ flags.NTLM_NegotiateVersion
|
||||
+ flags.NTLM_Negotiate128
|
||||
+ flags.NTLM_Negotiate56,
|
||||
|
||||
NTLM_TYPE2_FLAGS : flags.NTLM_NegotiateUnicode
|
||||
+ flags.NTLM_RequestTarget
|
||||
+ flags.NTLM_NegotiateNTLM
|
||||
+ flags.NTLM_NegotiateAlwaysSign
|
||||
+ flags.NTLM_NegotiateExtendedSecurity
|
||||
+ flags.NTLM_NegotiateTargetInfo
|
||||
+ flags.NTLM_NegotiateVersion
|
||||
+ flags.NTLM_Negotiate128
|
||||
+ flags.NTLM_Negotiate56
|
||||
};
|
||||
|
||||
function createType1Message(options){
|
||||
var domain = escape(options.domain.toUpperCase());
|
||||
var workstation = escape(options.workstation.toUpperCase());
|
||||
var protocol = 'NTLMSSP\0';
|
||||
|
||||
var BODY_LENGTH = 40;
|
||||
|
||||
var type1flags = typeflags.NTLM_TYPE1_FLAGS;
|
||||
if(!domain || domain === '')
|
||||
type1flags = type1flags - flags.NTLM_NegotiateOemDomainSupplied;
|
||||
|
||||
var pos = 0;
|
||||
var buf = new Buffer(BODY_LENGTH + domain.length + workstation.length);
|
||||
|
||||
|
||||
buf.write(protocol, pos, protocol.length); pos += protocol.length; // protocol
|
||||
buf.writeUInt32LE(1, pos); pos += 4; // type 1
|
||||
buf.writeUInt32LE(type1flags, pos); pos += 4; // TYPE1 flag
|
||||
|
||||
buf.writeUInt16LE(domain.length, pos); pos += 2; // domain length
|
||||
buf.writeUInt16LE(domain.length, pos); pos += 2; // domain max length
|
||||
buf.writeUInt32LE(BODY_LENGTH + workstation.length, pos); pos += 4; // domain buffer offset
|
||||
|
||||
buf.writeUInt16LE(workstation.length, pos); pos += 2; // workstation length
|
||||
buf.writeUInt16LE(workstation.length, pos); pos += 2; // workstation max length
|
||||
buf.writeUInt32LE(BODY_LENGTH, pos); pos += 4; // workstation buffer offset
|
||||
|
||||
buf.writeUInt8(5, pos); pos += 1; //ProductMajorVersion
|
||||
buf.writeUInt8(1, pos); pos += 1; //ProductMinorVersion
|
||||
buf.writeUInt16LE(2600, pos); pos += 2; //ProductBuild
|
||||
|
||||
buf.writeUInt8(0 , pos); pos += 1; //VersionReserved1
|
||||
buf.writeUInt8(0 , pos); pos += 1; //VersionReserved2
|
||||
buf.writeUInt8(0 , pos); pos += 1; //VersionReserved3
|
||||
buf.writeUInt8(15, pos); pos += 1; //NTLMRevisionCurrent
|
||||
|
||||
buf.write(workstation, pos, workstation.length, 'ascii'); pos += workstation.length; // workstation string
|
||||
buf.write(domain , pos, domain.length , 'ascii'); pos += domain.length;
|
||||
|
||||
return 'NTLM ' + buf.toString('base64');
|
||||
}
|
||||
|
||||
function parseType2Message(rawmsg, callback){
|
||||
var match = rawmsg.match(/NTLM (.+)?/);
|
||||
if(!match || !match[1])
|
||||
return callback(new Error("Couldn't find NTLM in the message type2 comming from the server"));
|
||||
|
||||
var buf = new Buffer(match[1], 'base64');
|
||||
|
||||
var msg = {};
|
||||
|
||||
msg.signature = buf.slice(0, 8);
|
||||
msg.type = buf.readInt16LE(8);
|
||||
|
||||
if(msg.type != 2)
|
||||
return callback(new Error("Server didn't return a type 2 message"));
|
||||
|
||||
msg.targetNameLen = buf.readInt16LE(12);
|
||||
msg.targetNameMaxLen = buf.readInt16LE(14);
|
||||
msg.targetNameOffset = buf.readInt32LE(16);
|
||||
msg.targetName = buf.slice(msg.targetNameOffset, msg.targetNameOffset + msg.targetNameMaxLen);
|
||||
|
||||
msg.negotiateFlags = buf.readInt32LE(20);
|
||||
msg.serverChallenge = buf.slice(24, 32);
|
||||
msg.reserved = buf.slice(32, 40);
|
||||
|
||||
if(msg.negotiateFlags & flags.NTLM_NegotiateTargetInfo){
|
||||
msg.targetInfoLen = buf.readInt16LE(40);
|
||||
msg.targetInfoMaxLen = buf.readInt16LE(42);
|
||||
msg.targetInfoOffset = buf.readInt32LE(44);
|
||||
msg.targetInfo = buf.slice(msg.targetInfoOffset, msg.targetInfoOffset + msg.targetInfoLen);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
function createType3Message(msg2, options){
|
||||
var nonce = msg2.serverChallenge;
|
||||
var username = options.username;
|
||||
var password = options.password;
|
||||
var negotiateFlags = msg2.negotiateFlags;
|
||||
|
||||
var isUnicode = negotiateFlags & flags.NTLM_NegotiateUnicode;
|
||||
var isNegotiateExtendedSecurity = negotiateFlags & flags.NTLM_NegotiateExtendedSecurity;
|
||||
|
||||
var BODY_LENGTH = 72;
|
||||
|
||||
var domainName = escape(options.domain.toUpperCase());
|
||||
var workstation = escape(options.workstation.toUpperCase());
|
||||
|
||||
var workstationBytes, domainNameBytes, usernameBytes, encryptedRandomSessionKeyBytes;
|
||||
|
||||
var encryptedRandomSessionKey = "";
|
||||
if(isUnicode){
|
||||
workstationBytes = new Buffer(workstation, 'utf16le');
|
||||
domainNameBytes = new Buffer(domainName, 'utf16le');
|
||||
usernameBytes = new Buffer(username, 'utf16le');
|
||||
encryptedRandomSessionKeyBytes = new Buffer(encryptedRandomSessionKey, 'utf16le');
|
||||
}else{
|
||||
workstationBytes = new Buffer(workstation, 'ascii');
|
||||
domainNameBytes = new Buffer(domainName, 'ascii');
|
||||
usernameBytes = new Buffer(username, 'ascii');
|
||||
encryptedRandomSessionKeyBytes = new Buffer(encryptedRandomSessionKey, 'ascii');
|
||||
}
|
||||
|
||||
var lmChallengeResponse = calc_resp(create_LM_hashed_password_v1(password), nonce);
|
||||
var ntChallengeResponse = calc_resp(create_NT_hashed_password_v1(password), nonce);
|
||||
|
||||
if(isNegotiateExtendedSecurity){
|
||||
var pwhash = create_NT_hashed_password_v1(password);
|
||||
var clientChallenge = "";
|
||||
for(var i=0; i < 8; i++){
|
||||
clientChallenge += String.fromCharCode( Math.floor(Math.random()*256) );
|
||||
}
|
||||
var clientChallengeBytes = new Buffer(clientChallenge, 'ascii');
|
||||
var challenges = ntlm2sr_calc_resp(pwhash, nonce, clientChallengeBytes);
|
||||
lmChallengeResponse = challenges.lmChallengeResponse;
|
||||
ntChallengeResponse = challenges.ntChallengeResponse;
|
||||
}
|
||||
|
||||
var signature = 'NTLMSSP\0';
|
||||
|
||||
var pos = 0;
|
||||
var buf = new Buffer(BODY_LENGTH + domainNameBytes.length + usernameBytes.length + workstationBytes.length + lmChallengeResponse.length + ntChallengeResponse.length + encryptedRandomSessionKeyBytes.length);
|
||||
|
||||
buf.write(signature, pos, signature.length); pos += signature.length;
|
||||
buf.writeUInt32LE(3, pos); pos += 4; // type 1
|
||||
|
||||
buf.writeUInt16LE(lmChallengeResponse.length, pos); pos += 2; // LmChallengeResponseLen
|
||||
buf.writeUInt16LE(lmChallengeResponse.length, pos); pos += 2; // LmChallengeResponseMaxLen
|
||||
buf.writeUInt32LE(BODY_LENGTH + domainNameBytes.length + usernameBytes.length + workstationBytes.length, pos); pos += 4; // LmChallengeResponseOffset
|
||||
|
||||
buf.writeUInt16LE(ntChallengeResponse.length, pos); pos += 2; // NtChallengeResponseLen
|
||||
buf.writeUInt16LE(ntChallengeResponse.length, pos); pos += 2; // NtChallengeResponseMaxLen
|
||||
buf.writeUInt32LE(BODY_LENGTH + domainNameBytes.length + usernameBytes.length + workstationBytes.length + lmChallengeResponse.length, pos); pos += 4; // NtChallengeResponseOffset
|
||||
|
||||
buf.writeUInt16LE(domainNameBytes.length, pos); pos += 2; // DomainNameLen
|
||||
buf.writeUInt16LE(domainNameBytes.length, pos); pos += 2; // DomainNameMaxLen
|
||||
buf.writeUInt32LE(BODY_LENGTH, pos); pos += 4; // DomainNameOffset
|
||||
|
||||
buf.writeUInt16LE(usernameBytes.length, pos); pos += 2; // UserNameLen
|
||||
buf.writeUInt16LE(usernameBytes.length, pos); pos += 2; // UserNameMaxLen
|
||||
buf.writeUInt32LE(BODY_LENGTH + domainNameBytes.length, pos); pos += 4; // UserNameOffset
|
||||
|
||||
buf.writeUInt16LE(workstationBytes.length, pos); pos += 2; // WorkstationLen
|
||||
buf.writeUInt16LE(workstationBytes.length, pos); pos += 2; // WorkstationMaxLen
|
||||
buf.writeUInt32LE(BODY_LENGTH + domainNameBytes.length + usernameBytes.length, pos); pos += 4; // WorkstationOffset
|
||||
|
||||
buf.writeUInt16LE(encryptedRandomSessionKeyBytes.length, pos); pos += 2; // EncryptedRandomSessionKeyLen
|
||||
buf.writeUInt16LE(encryptedRandomSessionKeyBytes.length, pos); pos += 2; // EncryptedRandomSessionKeyMaxLen
|
||||
buf.writeUInt32LE(BODY_LENGTH + domainNameBytes.length + usernameBytes.length + workstationBytes.length + lmChallengeResponse.length + ntChallengeResponse.length, pos); pos += 4; // EncryptedRandomSessionKeyOffset
|
||||
|
||||
buf.writeUInt32LE(typeflags.NTLM_TYPE2_FLAGS, pos); pos += 4; // NegotiateFlags
|
||||
|
||||
buf.writeUInt8(5, pos); pos++; // ProductMajorVersion
|
||||
buf.writeUInt8(1, pos); pos++; // ProductMinorVersion
|
||||
buf.writeUInt16LE(2600, pos); pos += 2; // ProductBuild
|
||||
buf.writeUInt8(0, pos); pos++; // VersionReserved1
|
||||
buf.writeUInt8(0, pos); pos++; // VersionReserved2
|
||||
buf.writeUInt8(0, pos); pos++; // VersionReserved3
|
||||
buf.writeUInt8(15, pos); pos++; // NTLMRevisionCurrent
|
||||
|
||||
domainNameBytes.copy(buf, pos); pos += domainNameBytes.length;
|
||||
usernameBytes.copy(buf, pos); pos += usernameBytes.length;
|
||||
workstationBytes.copy(buf, pos); pos += workstationBytes.length;
|
||||
lmChallengeResponse.copy(buf, pos); pos += lmChallengeResponse.length;
|
||||
ntChallengeResponse.copy(buf, pos); pos += ntChallengeResponse.length;
|
||||
encryptedRandomSessionKeyBytes.copy(buf, pos); pos += encryptedRandomSessionKeyBytes.length;
|
||||
|
||||
return 'NTLM ' + buf.toString('base64');
|
||||
}
|
||||
|
||||
function create_LM_hashed_password_v1(password){
|
||||
// fix the password length to 14 bytes
|
||||
password = password.toUpperCase();
|
||||
var passwordBytes = new Buffer(password, 'ascii');
|
||||
|
||||
var passwordBytesPadded = new Buffer(14);
|
||||
passwordBytesPadded.fill("\0");
|
||||
var sourceEnd = 14;
|
||||
if(passwordBytes.length < 14) sourceEnd = passwordBytes.length;
|
||||
passwordBytes.copy(passwordBytesPadded, 0, 0, sourceEnd);
|
||||
|
||||
// split into 2 parts of 7 bytes:
|
||||
var firstPart = passwordBytesPadded.slice(0,7);
|
||||
var secondPart = passwordBytesPadded.slice(7);
|
||||
|
||||
function encrypt(buf){
|
||||
var key = insertZerosEvery7Bits(buf);
|
||||
var des = crypto.createCipheriv('DES-ECB', key, '');
|
||||
return des.update("KGS!@#$%"); // page 57 in [MS-NLMP]);
|
||||
}
|
||||
|
||||
var firstPartEncrypted = encrypt(firstPart);
|
||||
var secondPartEncrypted = encrypt(secondPart);
|
||||
|
||||
return Buffer.concat([firstPartEncrypted, secondPartEncrypted]);
|
||||
}
|
||||
|
||||
function insertZerosEvery7Bits(buf){
|
||||
var binaryArray = bytes2binaryArray(buf);
|
||||
var newBinaryArray = [];
|
||||
for(var i=0; i<binaryArray.length; i++){
|
||||
newBinaryArray.push(binaryArray[i]);
|
||||
|
||||
if((i+1)%7 === 0){
|
||||
newBinaryArray.push(0);
|
||||
}
|
||||
}
|
||||
return binaryArray2bytes(newBinaryArray);
|
||||
}
|
||||
|
||||
function bytes2binaryArray(buf){
|
||||
var hex2binary = {
|
||||
0: [0,0,0,0],
|
||||
1: [0,0,0,1],
|
||||
2: [0,0,1,0],
|
||||
3: [0,0,1,1],
|
||||
4: [0,1,0,0],
|
||||
5: [0,1,0,1],
|
||||
6: [0,1,1,0],
|
||||
7: [0,1,1,1],
|
||||
8: [1,0,0,0],
|
||||
9: [1,0,0,1],
|
||||
A: [1,0,1,0],
|
||||
B: [1,0,1,1],
|
||||
C: [1,1,0,0],
|
||||
D: [1,1,0,1],
|
||||
E: [1,1,1,0],
|
||||
F: [1,1,1,1]
|
||||
};
|
||||
|
||||
var hexString = buf.toString('hex').toUpperCase();
|
||||
var array = [];
|
||||
for(var i=0; i<hexString.length; i++){
|
||||
var hexchar = hexString.charAt(i);
|
||||
array = array.concat(hex2binary[hexchar]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
function binaryArray2bytes(array){
|
||||
var binary2hex = {
|
||||
'0000': 0,
|
||||
'0001': 1,
|
||||
'0010': 2,
|
||||
'0011': 3,
|
||||
'0100': 4,
|
||||
'0101': 5,
|
||||
'0110': 6,
|
||||
'0111': 7,
|
||||
'1000': 8,
|
||||
'1001': 9,
|
||||
'1010': 'A',
|
||||
'1011': 'B',
|
||||
'1100': 'C',
|
||||
'1101': 'D',
|
||||
'1110': 'E',
|
||||
'1111': 'F'
|
||||
};
|
||||
|
||||
var bufArray = [];
|
||||
|
||||
for(var i=0; i<array.length; i +=8 ){
|
||||
if((i+7) > array.length)
|
||||
break;
|
||||
|
||||
var binString1 = '' + array[i] + '' + array[i+1] + '' + array[i+2] + '' + array[i+3];
|
||||
var binString2 = '' + array[i+4] + '' + array[i+5] + '' + array[i+6] + '' + array[i+7];
|
||||
var hexchar1 = binary2hex[binString1];
|
||||
var hexchar2 = binary2hex[binString2];
|
||||
|
||||
var buf = new Buffer(hexchar1 + '' + hexchar2, 'hex');
|
||||
bufArray.push(buf);
|
||||
}
|
||||
|
||||
return Buffer.concat(bufArray);
|
||||
}
|
||||
|
||||
function create_NT_hashed_password_v1(password){
|
||||
var buf = new Buffer(password, 'utf16le');
|
||||
var md4 = crypto.createHash('md4');
|
||||
md4.update(buf);
|
||||
return new Buffer(md4.digest());
|
||||
}
|
||||
|
||||
function calc_resp(password_hash, server_challenge){
|
||||
// padding with zeros to make the hash 21 bytes long
|
||||
var passHashPadded = new Buffer(21);
|
||||
passHashPadded.fill("\0");
|
||||
password_hash.copy(passHashPadded, 0, 0, password_hash.length);
|
||||
|
||||
var resArray = [];
|
||||
|
||||
var des = crypto.createCipheriv('DES-ECB', insertZerosEvery7Bits(passHashPadded.slice(0,7)), '');
|
||||
resArray.push( des.update(server_challenge.slice(0,8)) );
|
||||
|
||||
des = crypto.createCipheriv('DES-ECB', insertZerosEvery7Bits(passHashPadded.slice(7,14)), '');
|
||||
resArray.push( des.update(server_challenge.slice(0,8)) );
|
||||
|
||||
des = crypto.createCipheriv('DES-ECB', insertZerosEvery7Bits(passHashPadded.slice(14,21)), '');
|
||||
resArray.push( des.update(server_challenge.slice(0,8)) );
|
||||
|
||||
return Buffer.concat(resArray);
|
||||
}
|
||||
|
||||
function ntlm2sr_calc_resp(responseKeyNT, serverChallenge, clientChallenge){
|
||||
// padding with zeros to make the hash 16 bytes longer
|
||||
var lmChallengeResponse = new Buffer(clientChallenge.length + 16);
|
||||
lmChallengeResponse.fill("\0");
|
||||
clientChallenge.copy(lmChallengeResponse, 0, 0, clientChallenge.length);
|
||||
|
||||
var buf = Buffer.concat([serverChallenge, clientChallenge]);
|
||||
var md5 = crypto.createHash('md5');
|
||||
md5.update(buf);
|
||||
var sess = md5.digest();
|
||||
var ntChallengeResponse = calc_resp(responseKeyNT, sess.slice(0,8));
|
||||
|
||||
return {
|
||||
lmChallengeResponse: lmChallengeResponse,
|
||||
ntChallengeResponse: ntChallengeResponse
|
||||
};
|
||||
}
|
||||
|
||||
exports.createType1Message = createType1Message;
|
||||
exports.parseType2Message = parseType2Message;
|
||||
exports.createType3Message = createType3Message;
|
||||
|
||||
|
||||
|
6
node_modules/typed-rest-client/opensource/node-http-ntlm/readme.txt
generated
vendored
6
node_modules/typed-rest-client/opensource/node-http-ntlm/readme.txt
generated
vendored
|
@ -1,6 +0,0 @@
|
|||
// This software (ntlm.js) was copied from a file of the same name at https://github.com/SamDecrock/node-http-ntlm/blob/master/ntlm.js.
|
||||
//
|
||||
// As of this writing, it is a part of the node-http-ntlm module produced by SamDecrock.
|
||||
//
|
||||
// It is used as a part of the NTLM support provided by the vso-node-api library.
|
||||
//
|
73
node_modules/typed-rest-client/package.json
generated
vendored
73
node_modules/typed-rest-client/package.json
generated
vendored
|
@ -1,73 +0,0 @@
|
|||
{
|
||||
"_from": "typed-rest-client@^1.4.0",
|
||||
"_id": "typed-rest-client@1.5.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-DVZRlmsfnTjp6ZJaatcdyvvwYwbWvR4YDNFDqb+qdTxpvaVP99YCpBkA8rxsLtAPjBVoDe4fNsnMIdZTiPuKWg==",
|
||||
"_location": "/typed-rest-client",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "typed-rest-client@^1.4.0",
|
||||
"name": "typed-rest-client",
|
||||
"escapedName": "typed-rest-client",
|
||||
"rawSpec": "^1.4.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.4.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@actions/tool-cache"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/typed-rest-client/-/typed-rest-client-1.5.0.tgz",
|
||||
"_shasum": "c0dda6e775b942fd46a2d99f2160a94953206fc2",
|
||||
"_spec": "typed-rest-client@^1.4.0",
|
||||
"_where": "E:\\k8s-actions\\setup-kubectl\\node_modules\\@actions\\tool-cache",
|
||||
"author": {
|
||||
"name": "Microsoft Corporation"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Microsoft/typed-rest-client/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"tunnel": "0.0.4",
|
||||
"underscore": "1.8.3"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Node Rest and Http Clients for use with TypeScript",
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^2.2.44",
|
||||
"@types/node": "^6.0.92",
|
||||
"@types/shelljs": "0.7.4",
|
||||
"mocha": "^3.5.3",
|
||||
"nock": "9.6.1",
|
||||
"react-scripts": "1.1.5",
|
||||
"semver": "4.3.3",
|
||||
"shelljs": "0.7.6",
|
||||
"typescript": "3.1.5"
|
||||
},
|
||||
"homepage": "https://github.com/Microsoft/typed-rest-client#readme",
|
||||
"keywords": [
|
||||
"rest",
|
||||
"http",
|
||||
"client",
|
||||
"typescript",
|
||||
"node"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./RestClient.js",
|
||||
"name": "typed-rest-client",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Microsoft/typed-rest-client.git"
|
||||
},
|
||||
"scripts": {
|
||||
"bt": "node make.js buildtest",
|
||||
"build": "node make.js build",
|
||||
"samples": "node make.js samples",
|
||||
"test": "node make.js test",
|
||||
"units": "node make.js units",
|
||||
"validate": "node make.js validate"
|
||||
},
|
||||
"version": "1.5.0"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue