@actions/http-client 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RELEASES.md +4 -0
- package/auth.d.ts +23 -0
- package/auth.js +58 -0
- package/index.d.ts +124 -0
- package/index.js +537 -0
- package/interfaces.d.ts +49 -0
- package/interfaces.js +2 -0
- package/package.json +1 -1
- package/proxy.d.ts +2 -0
- package/proxy.js +57 -0
- package/.github/workflows/test.yml +0 -51
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -11
- package/__tests__/auth.test.ts +0 -61
- package/__tests__/basics.test.ts +0 -375
- package/__tests__/headers.test.ts +0 -115
- package/__tests__/keepalive.test.ts +0 -79
- package/__tests__/proxy.test.ts +0 -228
- package/auth.ts +0 -86
- package/index.ts +0 -768
- package/interfaces.ts +0 -98
- package/jest.config.js +0 -10
- package/proxy.ts +0 -60
- package/tsconfig.json +0 -15
package/RELEASES.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
## Releases
|
|
2
2
|
|
|
3
|
+
## 1.0.10
|
|
4
|
+
|
|
5
|
+
Contains a bug fix where proxy is defined without a user and password. see [PR here](https://github.com/actions/http-client/pull/42)
|
|
6
|
+
|
|
3
7
|
## 1.0.9
|
|
4
8
|
Throw HttpClientError instead of a generic Error from the \<verb>Json() helper methods when the server responds with a non-successful status code.
|
|
5
9
|
|
package/auth.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ifm = require('./interfaces');
|
|
2
|
+
export declare class BasicCredentialHandler implements ifm.IRequestHandler {
|
|
3
|
+
username: string;
|
|
4
|
+
password: string;
|
|
5
|
+
constructor(username: string, password: string);
|
|
6
|
+
prepareRequest(options: any): void;
|
|
7
|
+
canHandleAuthentication(response: ifm.IHttpClientResponse): boolean;
|
|
8
|
+
handleAuthentication(httpClient: ifm.IHttpClient, requestInfo: ifm.IRequestInfo, objs: any): Promise<ifm.IHttpClientResponse>;
|
|
9
|
+
}
|
|
10
|
+
export declare class BearerCredentialHandler implements ifm.IRequestHandler {
|
|
11
|
+
token: string;
|
|
12
|
+
constructor(token: string);
|
|
13
|
+
prepareRequest(options: any): void;
|
|
14
|
+
canHandleAuthentication(response: ifm.IHttpClientResponse): boolean;
|
|
15
|
+
handleAuthentication(httpClient: ifm.IHttpClient, requestInfo: ifm.IRequestInfo, objs: any): Promise<ifm.IHttpClientResponse>;
|
|
16
|
+
}
|
|
17
|
+
export declare class PersonalAccessTokenCredentialHandler implements ifm.IRequestHandler {
|
|
18
|
+
token: string;
|
|
19
|
+
constructor(token: string);
|
|
20
|
+
prepareRequest(options: any): void;
|
|
21
|
+
canHandleAuthentication(response: ifm.IHttpClientResponse): boolean;
|
|
22
|
+
handleAuthentication(httpClient: ifm.IHttpClient, requestInfo: ifm.IRequestInfo, objs: any): Promise<ifm.IHttpClientResponse>;
|
|
23
|
+
}
|
package/auth.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class BasicCredentialHandler {
|
|
4
|
+
constructor(username, password) {
|
|
5
|
+
this.username = username;
|
|
6
|
+
this.password = password;
|
|
7
|
+
}
|
|
8
|
+
prepareRequest(options) {
|
|
9
|
+
options.headers['Authorization'] =
|
|
10
|
+
'Basic ' +
|
|
11
|
+
Buffer.from(this.username + ':' + this.password).toString('base64');
|
|
12
|
+
}
|
|
13
|
+
// This handler cannot handle 401
|
|
14
|
+
canHandleAuthentication(response) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
handleAuthentication(httpClient, requestInfo, objs) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.BasicCredentialHandler = BasicCredentialHandler;
|
|
22
|
+
class BearerCredentialHandler {
|
|
23
|
+
constructor(token) {
|
|
24
|
+
this.token = token;
|
|
25
|
+
}
|
|
26
|
+
// currently implements pre-authorization
|
|
27
|
+
// TODO: support preAuth = false where it hooks on 401
|
|
28
|
+
prepareRequest(options) {
|
|
29
|
+
options.headers['Authorization'] = 'Bearer ' + this.token;
|
|
30
|
+
}
|
|
31
|
+
// This handler cannot handle 401
|
|
32
|
+
canHandleAuthentication(response) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
handleAuthentication(httpClient, requestInfo, objs) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.BearerCredentialHandler = BearerCredentialHandler;
|
|
40
|
+
class PersonalAccessTokenCredentialHandler {
|
|
41
|
+
constructor(token) {
|
|
42
|
+
this.token = token;
|
|
43
|
+
}
|
|
44
|
+
// currently implements pre-authorization
|
|
45
|
+
// TODO: support preAuth = false where it hooks on 401
|
|
46
|
+
prepareRequest(options) {
|
|
47
|
+
options.headers['Authorization'] =
|
|
48
|
+
'Basic ' + Buffer.from('PAT:' + this.token).toString('base64');
|
|
49
|
+
}
|
|
50
|
+
// This handler cannot handle 401
|
|
51
|
+
canHandleAuthentication(response) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
handleAuthentication(httpClient, requestInfo, objs) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHandler;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import http = require('http');
|
|
3
|
+
import ifm = require('./interfaces');
|
|
4
|
+
export declare enum HttpCodes {
|
|
5
|
+
OK = 200,
|
|
6
|
+
MultipleChoices = 300,
|
|
7
|
+
MovedPermanently = 301,
|
|
8
|
+
ResourceMoved = 302,
|
|
9
|
+
SeeOther = 303,
|
|
10
|
+
NotModified = 304,
|
|
11
|
+
UseProxy = 305,
|
|
12
|
+
SwitchProxy = 306,
|
|
13
|
+
TemporaryRedirect = 307,
|
|
14
|
+
PermanentRedirect = 308,
|
|
15
|
+
BadRequest = 400,
|
|
16
|
+
Unauthorized = 401,
|
|
17
|
+
PaymentRequired = 402,
|
|
18
|
+
Forbidden = 403,
|
|
19
|
+
NotFound = 404,
|
|
20
|
+
MethodNotAllowed = 405,
|
|
21
|
+
NotAcceptable = 406,
|
|
22
|
+
ProxyAuthenticationRequired = 407,
|
|
23
|
+
RequestTimeout = 408,
|
|
24
|
+
Conflict = 409,
|
|
25
|
+
Gone = 410,
|
|
26
|
+
TooManyRequests = 429,
|
|
27
|
+
InternalServerError = 500,
|
|
28
|
+
NotImplemented = 501,
|
|
29
|
+
BadGateway = 502,
|
|
30
|
+
ServiceUnavailable = 503,
|
|
31
|
+
GatewayTimeout = 504
|
|
32
|
+
}
|
|
33
|
+
export declare enum Headers {
|
|
34
|
+
Accept = "accept",
|
|
35
|
+
ContentType = "content-type"
|
|
36
|
+
}
|
|
37
|
+
export declare enum MediaTypes {
|
|
38
|
+
ApplicationJson = "application/json"
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns the proxy URL, depending upon the supplied url and proxy environment variables.
|
|
42
|
+
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
|
|
43
|
+
*/
|
|
44
|
+
export declare function getProxyUrl(serverUrl: string): string;
|
|
45
|
+
export declare class HttpClientError extends Error {
|
|
46
|
+
constructor(message: string, statusCode: number);
|
|
47
|
+
statusCode: number;
|
|
48
|
+
result?: any;
|
|
49
|
+
}
|
|
50
|
+
export declare class HttpClientResponse implements ifm.IHttpClientResponse {
|
|
51
|
+
constructor(message: http.IncomingMessage);
|
|
52
|
+
message: http.IncomingMessage;
|
|
53
|
+
readBody(): Promise<string>;
|
|
54
|
+
}
|
|
55
|
+
export declare function isHttps(requestUrl: string): boolean;
|
|
56
|
+
export declare class HttpClient {
|
|
57
|
+
userAgent: string | undefined;
|
|
58
|
+
handlers: ifm.IRequestHandler[];
|
|
59
|
+
requestOptions: ifm.IRequestOptions;
|
|
60
|
+
private _ignoreSslError;
|
|
61
|
+
private _socketTimeout;
|
|
62
|
+
private _allowRedirects;
|
|
63
|
+
private _allowRedirectDowngrade;
|
|
64
|
+
private _maxRedirects;
|
|
65
|
+
private _allowRetries;
|
|
66
|
+
private _maxRetries;
|
|
67
|
+
private _agent;
|
|
68
|
+
private _proxyAgent;
|
|
69
|
+
private _keepAlive;
|
|
70
|
+
private _disposed;
|
|
71
|
+
constructor(userAgent?: string, handlers?: ifm.IRequestHandler[], requestOptions?: ifm.IRequestOptions);
|
|
72
|
+
options(requestUrl: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
|
73
|
+
get(requestUrl: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
|
74
|
+
del(requestUrl: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
|
75
|
+
post(requestUrl: string, data: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
|
76
|
+
patch(requestUrl: string, data: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
|
77
|
+
put(requestUrl: string, data: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
|
78
|
+
head(requestUrl: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
|
79
|
+
sendStream(verb: string, requestUrl: string, stream: NodeJS.ReadableStream, additionalHeaders?: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
|
80
|
+
/**
|
|
81
|
+
* Gets a typed object from an endpoint
|
|
82
|
+
* Be aware that not found returns a null. Other errors (4xx, 5xx) reject the promise
|
|
83
|
+
*/
|
|
84
|
+
getJson<T>(requestUrl: string, additionalHeaders?: ifm.IHeaders): Promise<ifm.ITypedResponse<T>>;
|
|
85
|
+
postJson<T>(requestUrl: string, obj: any, additionalHeaders?: ifm.IHeaders): Promise<ifm.ITypedResponse<T>>;
|
|
86
|
+
putJson<T>(requestUrl: string, obj: any, additionalHeaders?: ifm.IHeaders): Promise<ifm.ITypedResponse<T>>;
|
|
87
|
+
patchJson<T>(requestUrl: string, obj: any, additionalHeaders?: ifm.IHeaders): Promise<ifm.ITypedResponse<T>>;
|
|
88
|
+
/**
|
|
89
|
+
* Makes a raw http request.
|
|
90
|
+
* All other methods such as get, post, patch, and request ultimately call this.
|
|
91
|
+
* Prefer get, del, post and patch
|
|
92
|
+
*/
|
|
93
|
+
request(verb: string, requestUrl: string, data: string | NodeJS.ReadableStream, headers: ifm.IHeaders): Promise<ifm.IHttpClientResponse>;
|
|
94
|
+
/**
|
|
95
|
+
* Needs to be called if keepAlive is set to true in request options.
|
|
96
|
+
*/
|
|
97
|
+
dispose(): void;
|
|
98
|
+
/**
|
|
99
|
+
* Raw request.
|
|
100
|
+
* @param info
|
|
101
|
+
* @param data
|
|
102
|
+
*/
|
|
103
|
+
requestRaw(info: ifm.IRequestInfo, data: string | NodeJS.ReadableStream): Promise<ifm.IHttpClientResponse>;
|
|
104
|
+
/**
|
|
105
|
+
* Raw request with callback.
|
|
106
|
+
* @param info
|
|
107
|
+
* @param data
|
|
108
|
+
* @param onResult
|
|
109
|
+
*/
|
|
110
|
+
requestRawWithCallback(info: ifm.IRequestInfo, data: string | NodeJS.ReadableStream, onResult: (err: any, res: ifm.IHttpClientResponse) => void): void;
|
|
111
|
+
/**
|
|
112
|
+
* Gets an http agent. This function is useful when you need an http agent that handles
|
|
113
|
+
* routing through a proxy server - depending upon the url and proxy environment variables.
|
|
114
|
+
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
|
|
115
|
+
*/
|
|
116
|
+
getAgent(serverUrl: string): http.Agent;
|
|
117
|
+
private _prepareRequest;
|
|
118
|
+
private _mergeHeaders;
|
|
119
|
+
private _getExistingOrDefaultHeader;
|
|
120
|
+
private _getAgent;
|
|
121
|
+
private _performExponentialBackoff;
|
|
122
|
+
private static dateTimeDeserializer;
|
|
123
|
+
private _processResponse;
|
|
124
|
+
}
|