typed-rest-client
Advanced tools
Comparing version 1.0.9 to 1.0.11
@@ -7,4 +7,4 @@ "use strict"; | ||
const https = require("https"); | ||
var _ = require("underscore"); | ||
var ntlm = require("../opensource/node-http-ntlm/ntlm"); | ||
const _ = require("underscore"); | ||
const ntlm = require("../opensource/node-http-ntlm/ntlm"); | ||
class NtlmCredentialHandler { | ||
@@ -18,5 +18,11 @@ constructor(username, password, workstation, domain) { | ||
} | ||
else { | ||
this._ntlmOptions.domain = ''; | ||
} | ||
if (workstation !== undefined) { | ||
this._ntlmOptions.workstation = workstation; | ||
} | ||
else { | ||
this._ntlmOptions.workstation = ''; | ||
} | ||
} | ||
@@ -47,3 +53,3 @@ prepareRequest(options) { | ||
return new Promise((resolve, reject) => { | ||
var callbackForResult = function (err, res) { | ||
const callbackForResult = function (err, res) { | ||
if (err) { | ||
@@ -50,0 +56,0 @@ reject(err); |
{ | ||
"name": "typed-rest-client", | ||
"version": "1.0.9", | ||
"version": "1.0.11", | ||
"description": "Node Rest and Http Clients for use with TypeScript", | ||
@@ -11,2 +11,3 @@ "main": "./RestClient.js", | ||
"samples": "node make.js samples", | ||
"units": "node make.js units", | ||
"validate": "node make.js validate" | ||
@@ -36,2 +37,3 @@ }, | ||
"mocha": "^3.5.3", | ||
"react-scripts": "1.1.5", | ||
"shelljs": "0.7.6", | ||
@@ -42,2 +44,3 @@ "semver": "4.3.3", | ||
"dependencies": { | ||
"nock": "9.6.1", | ||
"tunnel": "0.0.4", | ||
@@ -44,0 +47,0 @@ "underscore": "1.8.3" |
@@ -28,2 +28,21 @@ # Typed Rest and Http Client with TypeScript Typings | ||
# Build | ||
Build: | ||
```bash | ||
$ npm run build | ||
``` | ||
# Test | ||
To run all tests: | ||
```bash | ||
$ npm test | ||
``` | ||
To just run unit tests: | ||
```bash | ||
$ npm run units | ||
``` | ||
## Samples | ||
@@ -33,3 +52,3 @@ | ||
Also see [rest](./test/resttests.ts) and [http](./test/httptests.ts) tests for detailed examples. | ||
Also see [rest](./test/tests/resttests.ts) and [http](./test/tests/httptests.ts) tests for detailed examples. | ||
@@ -41,3 +60,3 @@ ## Errors | ||
See [http tests](./test/httptests.ts) for detailed examples. | ||
See [http tests](./test/tests/httptests.ts) for detailed examples. | ||
@@ -53,3 +72,3 @@ ### rest | ||
See [rest tests](./test/resttests.ts) for detailed examples. | ||
See [rest tests](./test/tests/resttests.ts) for detailed examples. | ||
@@ -56,0 +75,0 @@ ## Node Support |
@@ -12,2 +12,3 @@ /// <reference types="node" /> | ||
responseProcessor?: Function; | ||
deserializeDates?: boolean; | ||
} | ||
@@ -74,3 +75,4 @@ export declare class RestClient { | ||
private _headersFromOptions(options, contentType?); | ||
private static dateTimeDeserializer(key, value); | ||
private _processResponse<T>(res, options); | ||
} |
@@ -130,6 +130,23 @@ "use strict"; | ||
if (contentType) { | ||
headers["Content-Type"] = headers["Content-Type"] || 'application/json; charset=utf-8'; | ||
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) { | ||
@@ -152,3 +169,8 @@ return __awaiter(this, void 0, void 0, function* () { | ||
if (contents && contents.length > 0) { | ||
obj = JSON.parse(contents); | ||
if (options && options.deserializeDates) { | ||
obj = JSON.parse(contents, RestClient.dateTimeDeserializer); | ||
} | ||
else { | ||
obj = JSON.parse(contents); | ||
} | ||
if (options && options.responseProcessor) { | ||
@@ -155,0 +177,0 @@ response.result = options.responseProcessor(obj); |
24
Util.js
@@ -17,15 +17,19 @@ "use strict"; | ||
} | ||
if (!resource) { | ||
else if (!resource) { | ||
return baseUrl; | ||
} | ||
let base = url.parse(baseUrl); | ||
// resource (specific per request) eliments take priority | ||
let resultantUrl = url.parse(resource); | ||
resultantUrl.protocol = resultantUrl.protocol || base.protocol; | ||
resultantUrl.auth = resultantUrl.auth || base.auth; | ||
resultantUrl.host = resultantUrl.host || base.host; | ||
resultantUrl.pathname = path.posix.resolve(base.pathname, resultantUrl.pathname); | ||
let res = url.format(resultantUrl); | ||
return res; | ||
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 = path.posix.resolve(base.pathname, resultantUrl.pathname); | ||
if (!resultantUrl.pathname.endsWith('/') && resource.endsWith('/')) { | ||
resultantUrl.pathname += '/'; | ||
} | ||
return url.format(resultantUrl); | ||
} | ||
} | ||
exports.getUrl = getUrl; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
143856
1463
82
3
8
+ Addednock@9.6.1
+ Addedassertion-error@1.1.0(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedchai@4.5.0(transitive)
+ Addedcheck-error@1.0.3(transitive)
+ Addeddebug@3.2.7(transitive)
+ Addeddeep-eql@4.1.4(transitive)
+ Addeddeep-equal@1.1.2(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-func-name@2.0.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-arguments@1.1.1(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-regex@1.1.4(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedloupe@2.3.7(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedms@2.1.3(transitive)
+ Addednock@9.6.1(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedobject-is@1.1.6(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedpathval@1.1.1(transitive)
+ Addedpropagate@1.0.0(transitive)
+ Addedqs@6.13.0(transitive)
+ Addedregexp.prototype.flags@1.5.3(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedtype-detect@4.1.0(transitive)