artifact-engine 1.2.0 → 1.4.0
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/Engine/artifactEngine.d.ts +12 -12
- package/Engine/artifactEngine.js +166 -166
- package/Engine/artifactEngineOptions.d.ts +8 -8
- package/Engine/artifactEngineOptions.js +13 -15
- package/Engine/cilogger.d.ts +6 -6
- package/Engine/cilogger.js +44 -46
- package/Engine/index.d.ts +2 -2
- package/Engine/index.js +6 -8
- package/Engine/logger.d.ts +13 -13
- package/Engine/logger.js +109 -112
- package/Engine/worker.d.ts +10 -10
- package/Engine/worker.js +49 -51
- package/Models/artifactDownloadTicket.d.ts +11 -11
- package/Models/artifactDownloadTicket.js +5 -7
- package/Models/artifactItem.d.ts +12 -12
- package/Models/artifactItem.js +8 -10
- package/Models/artifactprovider.d.ts +10 -11
- package/Models/artifactprovider.js +2 -3
- package/Models/constants.d.ts +3 -3
- package/Models/constants.js +6 -8
- package/Models/index.d.ts +6 -6
- package/Models/index.js +12 -14
- package/Models/itemType.d.ts +5 -5
- package/Models/itemType.js +8 -10
- package/Models/ticketState.d.ts +7 -7
- package/Models/ticketState.js +10 -12
- package/Providers/filesystemProvider.d.ts +14 -15
- package/Providers/filesystemProvider.js +123 -123
- package/Providers/index.d.ts +4 -4
- package/Providers/index.js +10 -12
- package/Providers/stubProvider.d.ts +20 -21
- package/Providers/stubProvider.js +85 -88
- package/Providers/typed-rest-client/Handlers.d.ts +4 -4
- package/Providers/typed-rest-client/Handlers.js +10 -12
- package/Providers/typed-rest-client/HttpClient.d.ts +84 -77
- package/Providers/typed-rest-client/HttpClient.js +351 -328
- package/Providers/typed-rest-client/Index.d.ts +0 -1
- package/Providers/typed-rest-client/Index.js +2 -3
- package/Providers/typed-rest-client/Interfaces.d.ts +39 -38
- package/Providers/typed-rest-client/Interfaces.js +3 -4
- package/Providers/typed-rest-client/RestClient.d.ts +73 -27
- package/Providers/typed-rest-client/RestClient.js +186 -134
- package/Providers/typed-rest-client/Util.d.ts +7 -1
- package/Providers/typed-rest-client/Util.js +24 -18
- package/Providers/typed-rest-client/handlers/basiccreds.d.ts +9 -9
- package/Providers/typed-rest-client/handlers/basiccreds.js +23 -20
- package/Providers/typed-rest-client/handlers/bearertoken.d.ts +8 -8
- package/Providers/typed-rest-client/handlers/bearertoken.js +22 -19
- package/Providers/typed-rest-client/handlers/ntlm.d.ts +13 -13
- package/Providers/typed-rest-client/handlers/ntlm.js +115 -96
- package/Providers/typed-rest-client/handlers/personalaccesstoken.d.ts +8 -8
- package/Providers/typed-rest-client/handlers/personalaccesstoken.js +22 -19
- package/Providers/typed-rest-client/opensource/node-http-ntlm/readme.txt +6 -0
- package/Providers/webClient.d.ts +8 -8
- package/Providers/webClient.js +60 -60
- package/Providers/webClientFactory.d.ts +5 -5
- package/Providers/webClientFactory.js +59 -55
- package/Providers/webProvider.d.ts +22 -22
- package/Providers/webProvider.js +128 -116
- package/Providers/zipProvider.d.ts +15 -16
- package/Providers/zipProvider.js +53 -55
- package/Store/artifactItemStore.d.ts +18 -18
- package/Store/artifactItemStore.js +94 -96
- package/Store/index.d.ts +1 -1
- package/Store/index.js +4 -6
- package/Strings/resources.resjson/de-DE/resources.resjson +11 -11
- package/Strings/resources.resjson/en-US/resources.resjson +11 -11
- package/Strings/resources.resjson/es-ES/resources.resjson +11 -11
- package/Strings/resources.resjson/fr-FR/resources.resjson +11 -11
- package/Strings/resources.resjson/it-IT/resources.resjson +11 -11
- package/Strings/resources.resjson/ja-JP/resources.resjson +11 -11
- package/Strings/resources.resjson/ko-KR/resources.resjson +11 -11
- package/Strings/resources.resjson/ru-RU/resources.resjson +11 -11
- package/Strings/resources.resjson/zh-CN/resources.resjson +11 -11
- package/Strings/resources.resjson/zh-TW/resources.resjson +11 -11
- package/npm-shrinkwrap.json +176 -68
- package/package.json +2 -2
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//# sourceMappingURL=Index.js.map
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
export interface IHeaders {
|
|
2
|
-
[key: string]: any;
|
|
3
|
-
}
|
|
4
|
-
export interface IBasicCredentials {
|
|
5
|
-
username: string;
|
|
6
|
-
password: string;
|
|
7
|
-
}
|
|
8
|
-
export interface IRequestHandler {
|
|
9
|
-
prepareRequest(options: any): void;
|
|
10
|
-
canHandleAuthentication(res: IHttpResponse): boolean;
|
|
11
|
-
handleAuthentication(httpClient: any, protocol: any, options: any, objs: any, finalCallback: any): void;
|
|
12
|
-
}
|
|
13
|
-
export interface IHttpResponse {
|
|
14
|
-
statusCode?: number;
|
|
15
|
-
headers: any;
|
|
16
|
-
}
|
|
17
|
-
export interface IRequestOptions {
|
|
18
|
-
socketTimeout?: number;
|
|
19
|
-
ignoreSslError?: boolean;
|
|
20
|
-
proxy?: IProxyConfiguration;
|
|
21
|
-
cert?: ICertConfiguration;
|
|
22
|
-
allowRedirects?: boolean;
|
|
23
|
-
maxRedirects?: number;
|
|
24
|
-
maxSockets?: number;
|
|
25
|
-
keepAlive?: boolean;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
export interface IHeaders {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}
|
|
4
|
+
export interface IBasicCredentials {
|
|
5
|
+
username: string;
|
|
6
|
+
password: string;
|
|
7
|
+
}
|
|
8
|
+
export interface IRequestHandler {
|
|
9
|
+
prepareRequest(options: any): void;
|
|
10
|
+
canHandleAuthentication(res: IHttpResponse): boolean;
|
|
11
|
+
handleAuthentication(httpClient: any, protocol: any, options: any, objs: any, finalCallback: any): void;
|
|
12
|
+
}
|
|
13
|
+
export interface IHttpResponse {
|
|
14
|
+
statusCode?: number;
|
|
15
|
+
headers: any;
|
|
16
|
+
}
|
|
17
|
+
export interface IRequestOptions {
|
|
18
|
+
socketTimeout?: number;
|
|
19
|
+
ignoreSslError?: boolean;
|
|
20
|
+
proxy?: IProxyConfiguration;
|
|
21
|
+
cert?: ICertConfiguration;
|
|
22
|
+
allowRedirects?: boolean;
|
|
23
|
+
maxRedirects?: number;
|
|
24
|
+
maxSockets?: number;
|
|
25
|
+
keepAlive?: boolean;
|
|
26
|
+
requestCompressionForDownloads?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface IProxyConfiguration {
|
|
29
|
+
proxyUrl: string;
|
|
30
|
+
proxyUsername?: string;
|
|
31
|
+
proxyPassword?: string;
|
|
32
|
+
proxyBypassHosts?: string[];
|
|
33
|
+
}
|
|
34
|
+
export interface ICertConfiguration {
|
|
35
|
+
caFile?: string;
|
|
36
|
+
certFile?: string;
|
|
37
|
+
keyFile?: string;
|
|
38
|
+
passphrase?: string;
|
|
39
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
;
|
|
4
|
-
//# sourceMappingURL=Interfaces.js.map
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
;
|
|
@@ -1,27 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import httpm = require('./HttpClient');
|
|
2
|
+
import ifm = require("./Interfaces");
|
|
3
|
+
export interface IRestResponse<T> {
|
|
4
|
+
statusCode: number;
|
|
5
|
+
result: T;
|
|
6
|
+
}
|
|
7
|
+
export interface IRequestOptions {
|
|
8
|
+
acceptHeader?: string;
|
|
9
|
+
additionalHeaders?: ifm.IHeaders;
|
|
10
|
+
responseProcessor?: Function;
|
|
11
|
+
}
|
|
12
|
+
export declare class RestClient {
|
|
13
|
+
client: httpm.HttpClient;
|
|
14
|
+
versionParam: string;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of the RestClient
|
|
17
|
+
* @constructor
|
|
18
|
+
* @param {string} userAgent - userAgent for requests
|
|
19
|
+
* @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
|
|
20
|
+
* @param {ifm.IRequestHandler[]} handlers - handlers are typically auth handlers (basic, bearer, ntlm supplied)
|
|
21
|
+
* @param {ifm.IRequestOptions} requestOptions - options for each http requests (http proxy setting, socket timeout)
|
|
22
|
+
*/
|
|
23
|
+
constructor(userAgent: string, baseUrl?: string, handlers?: ifm.IRequestHandler[], requestOptions?: ifm.IRequestOptions);
|
|
24
|
+
private _baseUrl;
|
|
25
|
+
/**
|
|
26
|
+
* Gets a resource from an endpoint
|
|
27
|
+
* Be aware that not found returns a null. Other error conditions reject the promise
|
|
28
|
+
* @param {string} requestUrl - fully qualified or relative url
|
|
29
|
+
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
|
30
|
+
*/
|
|
31
|
+
options<T>(requestUrl: string, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
|
32
|
+
/**
|
|
33
|
+
* Gets a resource from an endpoint
|
|
34
|
+
* Be aware that not found returns a null. Other error conditions reject the promise
|
|
35
|
+
* @param {string} requestUrl - fully qualified or relative url
|
|
36
|
+
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
|
37
|
+
*/
|
|
38
|
+
get<T>(requestUrl: string, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
|
39
|
+
/**
|
|
40
|
+
* Deletes a resource from an endpoint
|
|
41
|
+
* Be aware that not found returns a null. Other error conditions reject the promise
|
|
42
|
+
* @param {string} requestUrl - fully qualified or relative url
|
|
43
|
+
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
|
44
|
+
*/
|
|
45
|
+
del<T>(requestUrl: string, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates resource(s) from an endpoint
|
|
48
|
+
* T type of object returned.
|
|
49
|
+
* Be aware that not found returns a null. Other error conditions reject the promise
|
|
50
|
+
* @param {string} requestUrl - fully qualified or relative url
|
|
51
|
+
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
|
52
|
+
*/
|
|
53
|
+
create<T>(requestUrl: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
|
54
|
+
/**
|
|
55
|
+
* Updates resource(s) from an endpoint
|
|
56
|
+
* T type of object returned.
|
|
57
|
+
* Be aware that not found returns a null. Other error conditions reject the promise
|
|
58
|
+
* @param {string} requestUrl - fully qualified or relative url
|
|
59
|
+
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
|
60
|
+
*/
|
|
61
|
+
update<T>(requestUrl: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
|
62
|
+
/**
|
|
63
|
+
* Replaces resource(s) from an endpoint
|
|
64
|
+
* T type of object returned.
|
|
65
|
+
* Be aware that not found returns a null. Other error conditions reject the promise
|
|
66
|
+
* @param {string} requestUrl - fully qualified or relative url
|
|
67
|
+
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
|
68
|
+
*/
|
|
69
|
+
replace<T>(requestUrl: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
|
70
|
+
uploadStream<T>(verb: string, requestUrl: string, stream: NodeJS.ReadableStream, options?: IRequestOptions): Promise<IRestResponse<T>>;
|
|
71
|
+
private _headersFromOptions(options, contentType?);
|
|
72
|
+
private _processResponse<T>(res, options);
|
|
73
|
+
}
|
|
@@ -1,134 +1,186 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function
|
|
7
|
-
function
|
|
8
|
-
step(
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
exports
|
|
13
|
-
const httpm = require("./HttpClient");
|
|
14
|
-
const util = require("./Util");
|
|
15
|
-
class RestClient {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
let url = util.getUrl(requestUrl, this._baseUrl);
|
|
39
|
-
let res = yield this.client.
|
|
40
|
-
return this._processResponse(res, options);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
let
|
|
65
|
-
let
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft. All rights reserved.
|
|
3
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
const httpm = require("./HttpClient");
|
|
14
|
+
const util = require("./Util");
|
|
15
|
+
class RestClient {
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instance of the RestClient
|
|
18
|
+
* @constructor
|
|
19
|
+
* @param {string} userAgent - userAgent for requests
|
|
20
|
+
* @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
|
|
21
|
+
* @param {ifm.IRequestHandler[]} handlers - handlers are typically auth handlers (basic, bearer, ntlm supplied)
|
|
22
|
+
* @param {ifm.IRequestOptions} requestOptions - options for each http requests (http proxy setting, socket timeout)
|
|
23
|
+
*/
|
|
24
|
+
constructor(userAgent, baseUrl, handlers, requestOptions) {
|
|
25
|
+
this.client = new httpm.HttpClient(userAgent, handlers, requestOptions);
|
|
26
|
+
if (baseUrl) {
|
|
27
|
+
this._baseUrl = baseUrl;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets a resource from an endpoint
|
|
32
|
+
* Be aware that not found returns a null. Other error conditions reject the promise
|
|
33
|
+
* @param {string} requestUrl - fully qualified or relative url
|
|
34
|
+
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
|
35
|
+
*/
|
|
36
|
+
options(requestUrl, options) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
let url = util.getUrl(requestUrl, this._baseUrl);
|
|
39
|
+
let res = yield this.client.options(url, this._headersFromOptions(options));
|
|
40
|
+
return this._processResponse(res, options);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gets a resource from an endpoint
|
|
45
|
+
* Be aware that not found returns a null. Other error conditions reject the promise
|
|
46
|
+
* @param {string} requestUrl - fully qualified or relative url
|
|
47
|
+
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
|
48
|
+
*/
|
|
49
|
+
get(requestUrl, options) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
let url = util.getUrl(requestUrl, this._baseUrl);
|
|
52
|
+
let res = yield this.client.get(url, this._headersFromOptions(options));
|
|
53
|
+
return this._processResponse(res, options);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Deletes a resource from an endpoint
|
|
58
|
+
* Be aware that not found returns a null. Other error conditions reject the promise
|
|
59
|
+
* @param {string} requestUrl - fully qualified or relative url
|
|
60
|
+
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
|
61
|
+
*/
|
|
62
|
+
del(requestUrl, options) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
let url = util.getUrl(requestUrl, this._baseUrl);
|
|
65
|
+
let res = yield this.client.del(url, this._headersFromOptions(options));
|
|
66
|
+
return this._processResponse(res, options);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates resource(s) from an endpoint
|
|
71
|
+
* T type of object returned.
|
|
72
|
+
* Be aware that not found returns a null. Other error conditions reject the promise
|
|
73
|
+
* @param {string} requestUrl - fully qualified or relative url
|
|
74
|
+
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
|
75
|
+
*/
|
|
76
|
+
create(requestUrl, resources, options) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
let url = util.getUrl(requestUrl, this._baseUrl);
|
|
79
|
+
let headers = this._headersFromOptions(options, true);
|
|
80
|
+
let data = JSON.stringify(resources, null, 2);
|
|
81
|
+
let res = yield this.client.post(url, data, headers);
|
|
82
|
+
return this._processResponse(res, options);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Updates resource(s) from an endpoint
|
|
87
|
+
* T type of object returned.
|
|
88
|
+
* Be aware that not found returns a null. Other error conditions reject the promise
|
|
89
|
+
* @param {string} requestUrl - fully qualified or relative url
|
|
90
|
+
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
|
91
|
+
*/
|
|
92
|
+
update(requestUrl, resources, options) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
let url = util.getUrl(requestUrl, this._baseUrl);
|
|
95
|
+
let headers = this._headersFromOptions(options, true);
|
|
96
|
+
let data = JSON.stringify(resources, null, 2);
|
|
97
|
+
let res = yield this.client.patch(url, data, headers);
|
|
98
|
+
return this._processResponse(res, options);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Replaces resource(s) from an endpoint
|
|
103
|
+
* T type of object returned.
|
|
104
|
+
* Be aware that not found returns a null. Other error conditions reject the promise
|
|
105
|
+
* @param {string} requestUrl - fully qualified or relative url
|
|
106
|
+
* @param {IRequestOptions} requestOptions - (optional) requestOptions object
|
|
107
|
+
*/
|
|
108
|
+
replace(requestUrl, resources, options) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
let url = util.getUrl(requestUrl, this._baseUrl);
|
|
111
|
+
let headers = this._headersFromOptions(options, true);
|
|
112
|
+
let data = JSON.stringify(resources, null, 2);
|
|
113
|
+
let res = yield this.client.put(url, data, headers);
|
|
114
|
+
return this._processResponse(res, options);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
uploadStream(verb, requestUrl, stream, options) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
let url = util.getUrl(requestUrl, this._baseUrl);
|
|
120
|
+
let headers = this._headersFromOptions(options, true);
|
|
121
|
+
let res = yield this.client.sendStream(verb, url, stream, headers);
|
|
122
|
+
return this._processResponse(res, options);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
_headersFromOptions(options, contentType) {
|
|
126
|
+
options = options || {};
|
|
127
|
+
let headers = options.additionalHeaders || {};
|
|
128
|
+
headers["Accept"] = options.acceptHeader || "application/json";
|
|
129
|
+
if (contentType) {
|
|
130
|
+
headers["Content-Type"] = headers["Content-Type"] || 'application/json; charset=utf-8';
|
|
131
|
+
}
|
|
132
|
+
return headers;
|
|
133
|
+
}
|
|
134
|
+
_processResponse(res, options) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
let rres = {};
|
|
138
|
+
let statusCode = res.message.statusCode;
|
|
139
|
+
rres.statusCode = statusCode;
|
|
140
|
+
// not found leads to null obj returned
|
|
141
|
+
if (statusCode == httpm.HttpCodes.NotFound) {
|
|
142
|
+
resolve(rres);
|
|
143
|
+
}
|
|
144
|
+
let obj;
|
|
145
|
+
// get the result from the body
|
|
146
|
+
try {
|
|
147
|
+
let contents = yield res.readBody();
|
|
148
|
+
if (contents && contents.length > 0) {
|
|
149
|
+
obj = JSON.parse(contents);
|
|
150
|
+
if (options && options.responseProcessor) {
|
|
151
|
+
rres.result = options.responseProcessor(obj);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
rres.result = obj;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
// Invalid resource (contents not json); leaving result obj null
|
|
160
|
+
}
|
|
161
|
+
// note that 3xx redirects are handled by the http layer.
|
|
162
|
+
if (statusCode > 299) {
|
|
163
|
+
let msg;
|
|
164
|
+
// if exception/error in body, attempt to get better error
|
|
165
|
+
if (obj && obj.message) {
|
|
166
|
+
msg = obj.message;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
msg = "Failed request: (" + statusCode + ")";
|
|
170
|
+
}
|
|
171
|
+
let err = new Error(msg);
|
|
172
|
+
// attach statusCode and body obj (if available) to the error object
|
|
173
|
+
err['statusCode'] = statusCode;
|
|
174
|
+
if (rres.result) {
|
|
175
|
+
err['result'] = rres.result;
|
|
176
|
+
}
|
|
177
|
+
reject(err);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
resolve(rres);
|
|
181
|
+
}
|
|
182
|
+
}));
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.RestClient = RestClient;
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* creates an url from a request url and optional base url (http://server:8080)
|
|
3
|
+
* @param {string} requestUrl - a fully qualified url or relative url
|
|
4
|
+
* @param {string} baseUrl - an optional baseUrl (http://server:8080)
|
|
5
|
+
* @return {string} - resultant url
|
|
6
|
+
*/
|
|
7
|
+
export declare function getUrl(requestUrl: string, baseUrl?: string): string;
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const url = require("url");
|
|
4
|
+
/**
|
|
5
|
+
* creates an url from a request url and optional base url (http://server:8080)
|
|
6
|
+
* @param {string} requestUrl - a fully qualified url or relative url
|
|
7
|
+
* @param {string} baseUrl - an optional baseUrl (http://server:8080)
|
|
8
|
+
* @return {string} - resultant url
|
|
9
|
+
*/
|
|
10
|
+
function getUrl(requestUrl, baseUrl) {
|
|
11
|
+
if (!baseUrl) {
|
|
12
|
+
return requestUrl;
|
|
13
|
+
}
|
|
14
|
+
let base = url.parse(baseUrl);
|
|
15
|
+
// requestUrl (specific per request) always wins
|
|
16
|
+
let combined = url.parse(requestUrl);
|
|
17
|
+
combined.protocol = combined.protocol || base.protocol;
|
|
18
|
+
combined.auth = combined.auth || base.auth;
|
|
19
|
+
combined.host = combined.host || base.host;
|
|
20
|
+
// path from requestUrl always wins
|
|
21
|
+
let res = url.format(combined);
|
|
22
|
+
return res;
|
|
23
|
+
}
|
|
24
|
+
exports.getUrl = getUrl;
|
|
@@ -1,9 +1,9 @@
|
|
|
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(res: ifm.IHttpResponse): boolean;
|
|
8
|
-
handleAuthentication(httpClient: any, protocol: any, options: any, objs: any, finalCallback: any): void;
|
|
9
|
-
}
|
|
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(res: ifm.IHttpResponse): boolean;
|
|
8
|
+
handleAuthentication(httpClient: any, protocol: any, options: any, objs: any, finalCallback: any): void;
|
|
9
|
+
}
|