artifact-engine 1.2.0 → 1.3.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.
Files changed (77) hide show
  1. package/Engine/artifactEngine.d.ts +12 -12
  2. package/Engine/artifactEngine.js +166 -166
  3. package/Engine/artifactEngineOptions.d.ts +8 -8
  4. package/Engine/artifactEngineOptions.js +13 -15
  5. package/Engine/cilogger.d.ts +6 -6
  6. package/Engine/cilogger.js +44 -46
  7. package/Engine/index.d.ts +2 -2
  8. package/Engine/index.js +6 -8
  9. package/Engine/logger.d.ts +13 -13
  10. package/Engine/logger.js +109 -112
  11. package/Engine/worker.d.ts +10 -10
  12. package/Engine/worker.js +49 -51
  13. package/Models/artifactDownloadTicket.d.ts +11 -11
  14. package/Models/artifactDownloadTicket.js +5 -7
  15. package/Models/artifactItem.d.ts +12 -12
  16. package/Models/artifactItem.js +8 -10
  17. package/Models/artifactprovider.d.ts +10 -11
  18. package/Models/artifactprovider.js +2 -3
  19. package/Models/constants.d.ts +3 -3
  20. package/Models/constants.js +6 -8
  21. package/Models/index.d.ts +6 -6
  22. package/Models/index.js +12 -14
  23. package/Models/itemType.d.ts +5 -5
  24. package/Models/itemType.js +8 -10
  25. package/Models/ticketState.d.ts +7 -7
  26. package/Models/ticketState.js +10 -12
  27. package/Providers/filesystemProvider.d.ts +14 -15
  28. package/Providers/filesystemProvider.js +123 -123
  29. package/Providers/index.d.ts +4 -4
  30. package/Providers/index.js +10 -12
  31. package/Providers/stubProvider.d.ts +20 -21
  32. package/Providers/stubProvider.js +85 -88
  33. package/Providers/typed-rest-client/Handlers.d.ts +4 -4
  34. package/Providers/typed-rest-client/Handlers.js +10 -12
  35. package/Providers/typed-rest-client/HttpClient.d.ts +84 -77
  36. package/Providers/typed-rest-client/HttpClient.js +351 -328
  37. package/Providers/typed-rest-client/Index.d.ts +0 -1
  38. package/Providers/typed-rest-client/Index.js +2 -3
  39. package/Providers/typed-rest-client/Interfaces.d.ts +38 -38
  40. package/Providers/typed-rest-client/Interfaces.js +3 -4
  41. package/Providers/typed-rest-client/RestClient.d.ts +73 -27
  42. package/Providers/typed-rest-client/RestClient.js +186 -134
  43. package/Providers/typed-rest-client/Util.d.ts +7 -1
  44. package/Providers/typed-rest-client/Util.js +24 -18
  45. package/Providers/typed-rest-client/handlers/basiccreds.d.ts +9 -9
  46. package/Providers/typed-rest-client/handlers/basiccreds.js +23 -20
  47. package/Providers/typed-rest-client/handlers/bearertoken.d.ts +8 -8
  48. package/Providers/typed-rest-client/handlers/bearertoken.js +22 -19
  49. package/Providers/typed-rest-client/handlers/ntlm.d.ts +13 -13
  50. package/Providers/typed-rest-client/handlers/ntlm.js +115 -96
  51. package/Providers/typed-rest-client/handlers/personalaccesstoken.d.ts +8 -8
  52. package/Providers/typed-rest-client/handlers/personalaccesstoken.js +22 -19
  53. package/Providers/typed-rest-client/opensource/node-http-ntlm/readme.txt +6 -0
  54. package/Providers/webClient.d.ts +8 -8
  55. package/Providers/webClient.js +60 -60
  56. package/Providers/webClientFactory.d.ts +5 -5
  57. package/Providers/webClientFactory.js +59 -55
  58. package/Providers/webProvider.d.ts +21 -22
  59. package/Providers/webProvider.js +120 -116
  60. package/Providers/zipProvider.d.ts +15 -16
  61. package/Providers/zipProvider.js +53 -55
  62. package/Store/artifactItemStore.d.ts +18 -18
  63. package/Store/artifactItemStore.js +94 -96
  64. package/Store/index.d.ts +1 -1
  65. package/Store/index.js +4 -6
  66. package/Strings/resources.resjson/de-DE/resources.resjson +11 -11
  67. package/Strings/resources.resjson/en-US/resources.resjson +11 -11
  68. package/Strings/resources.resjson/es-ES/resources.resjson +11 -11
  69. package/Strings/resources.resjson/fr-FR/resources.resjson +11 -11
  70. package/Strings/resources.resjson/it-IT/resources.resjson +11 -11
  71. package/Strings/resources.resjson/ja-JP/resources.resjson +11 -11
  72. package/Strings/resources.resjson/ko-KR/resources.resjson +11 -11
  73. package/Strings/resources.resjson/ru-RU/resources.resjson +11 -11
  74. package/Strings/resources.resjson/zh-CN/resources.resjson +11 -11
  75. package/Strings/resources.resjson/zh-TW/resources.resjson +11 -11
  76. package/npm-shrinkwrap.json +1 -1
  77. package/package.json +1 -1
@@ -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,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
- }
27
- export interface IProxyConfiguration {
28
- proxyUrl: string;
29
- proxyUsername?: string;
30
- proxyPassword?: string;
31
- proxyBypassHosts?: string[];
32
- }
33
- export interface ICertConfiguration {
34
- caFile?: string;
35
- certFile?: string;
36
- keyFile?: string;
37
- passphrase?: string;
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
+ }
27
+ export interface IProxyConfiguration {
28
+ proxyUrl: string;
29
+ proxyUsername?: string;
30
+ proxyPassword?: string;
31
+ proxyBypassHosts?: string[];
32
+ }
33
+ export interface ICertConfiguration {
34
+ caFile?: string;
35
+ certFile?: string;
36
+ keyFile?: string;
37
+ passphrase?: string;
38
+ }
@@ -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
- /// <reference types="node" />
2
- import httpm = require('./HttpClient');
3
- import ifm = require("./Interfaces");
4
- export interface IRestResponse<T> {
5
- statusCode: number;
6
- result: T;
7
- }
8
- export interface IRequestOptions {
9
- acceptHeader?: string;
10
- additionalHeaders?: ifm.IHeaders;
11
- responseProcessor?: Function;
12
- }
13
- export declare class RestClient {
14
- client: httpm.HttpClient;
15
- versionParam: string;
16
- constructor(userAgent: string, baseUrl?: string, handlers?: ifm.IRequestHandler[], requestOptions?: ifm.IRequestOptions);
17
- private _baseUrl;
18
- options<T>(requestUrl: string, options?: IRequestOptions): Promise<IRestResponse<T>>;
19
- get<T>(requestUrl: string, options?: IRequestOptions): Promise<IRestResponse<T>>;
20
- del<T>(requestUrl: string, options?: IRequestOptions): Promise<IRestResponse<T>>;
21
- create<T>(requestUrl: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>;
22
- update<T>(requestUrl: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>;
23
- replace<T>(requestUrl: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>;
24
- uploadStream<T>(verb: string, requestUrl: string, stream: NodeJS.ReadableStream, options?: IRequestOptions): Promise<IRestResponse<T>>;
25
- private _headersFromOptions;
26
- private _processResponse;
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.RestClient = void 0;
13
- const httpm = require("./HttpClient");
14
- const util = require("./Util");
15
- class RestClient {
16
- constructor(userAgent, baseUrl, handlers, requestOptions) {
17
- this.client = new httpm.HttpClient(userAgent, handlers, requestOptions);
18
- if (baseUrl) {
19
- this._baseUrl = baseUrl;
20
- }
21
- }
22
- options(requestUrl, options) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- let url = util.getUrl(requestUrl, this._baseUrl);
25
- let res = yield this.client.options(url, this._headersFromOptions(options));
26
- return this._processResponse(res, options);
27
- });
28
- }
29
- get(requestUrl, options) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- let url = util.getUrl(requestUrl, this._baseUrl);
32
- let res = yield this.client.get(url, this._headersFromOptions(options));
33
- return this._processResponse(res, options);
34
- });
35
- }
36
- del(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.del(url, this._headersFromOptions(options));
40
- return this._processResponse(res, options);
41
- });
42
- }
43
- create(requestUrl, resources, options) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- let url = util.getUrl(requestUrl, this._baseUrl);
46
- let headers = this._headersFromOptions(options, true);
47
- let data = JSON.stringify(resources, null, 2);
48
- let res = yield this.client.post(url, data, headers);
49
- return this._processResponse(res, options);
50
- });
51
- }
52
- update(requestUrl, resources, options) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- let url = util.getUrl(requestUrl, this._baseUrl);
55
- let headers = this._headersFromOptions(options, true);
56
- let data = JSON.stringify(resources, null, 2);
57
- let res = yield this.client.patch(url, data, headers);
58
- return this._processResponse(res, options);
59
- });
60
- }
61
- replace(requestUrl, resources, options) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- let url = util.getUrl(requestUrl, this._baseUrl);
64
- let headers = this._headersFromOptions(options, true);
65
- let data = JSON.stringify(resources, null, 2);
66
- let res = yield this.client.put(url, data, headers);
67
- return this._processResponse(res, options);
68
- });
69
- }
70
- uploadStream(verb, requestUrl, stream, options) {
71
- return __awaiter(this, void 0, void 0, function* () {
72
- let url = util.getUrl(requestUrl, this._baseUrl);
73
- let headers = this._headersFromOptions(options, true);
74
- let res = yield this.client.sendStream(verb, url, stream, headers);
75
- return this._processResponse(res, options);
76
- });
77
- }
78
- _headersFromOptions(options, contentType) {
79
- options = options || {};
80
- let headers = options.additionalHeaders || {};
81
- headers["Accept"] = options.acceptHeader || "application/json";
82
- if (contentType) {
83
- headers["Content-Type"] = headers["Content-Type"] || 'application/json; charset=utf-8';
84
- }
85
- return headers;
86
- }
87
- _processResponse(res, options) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
90
- let rres = {};
91
- let statusCode = res.message.statusCode;
92
- rres.statusCode = statusCode;
93
- if (statusCode == httpm.HttpCodes.NotFound) {
94
- resolve(rres);
95
- }
96
- let obj;
97
- try {
98
- let contents = yield res.readBody();
99
- if (contents && contents.length > 0) {
100
- obj = JSON.parse(contents);
101
- if (options && options.responseProcessor) {
102
- rres.result = options.responseProcessor(obj);
103
- }
104
- else {
105
- rres.result = obj;
106
- }
107
- }
108
- }
109
- catch (err) {
110
- }
111
- if (statusCode > 299) {
112
- let msg;
113
- if (obj && obj.message) {
114
- msg = obj.message;
115
- }
116
- else {
117
- msg = "Failed request: (" + statusCode + ")";
118
- }
119
- let err = new Error(msg);
120
- err['statusCode'] = statusCode;
121
- if (rres.result) {
122
- err['result'] = rres.result;
123
- }
124
- reject(err);
125
- }
126
- else {
127
- resolve(rres);
128
- }
129
- }));
130
- });
131
- }
132
- }
133
- exports.RestClient = RestClient;
134
- //# sourceMappingURL=RestClient.js.map
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
- export declare function getUrl(requestUrl: string, baseUrl?: string): string;
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
- exports.getUrl = void 0;
4
- const url = require("url");
5
- function getUrl(requestUrl, baseUrl) {
6
- if (!baseUrl) {
7
- return requestUrl;
8
- }
9
- let base = url.parse(baseUrl);
10
- let combined = url.parse(requestUrl);
11
- combined.protocol = combined.protocol || base.protocol;
12
- combined.auth = combined.auth || base.auth;
13
- combined.host = combined.host || base.host;
14
- let res = url.format(combined);
15
- return res;
16
- }
17
- exports.getUrl = getUrl;
18
- //# sourceMappingURL=Util.js.map
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
+ }