@ideal-postcodes/core-node
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -1,20 +0,19 @@ | ||
# [1.1.0](https://github.com/ideal-postcodes/core-node/compare/1.0.0...1.1.0) (2019-07-18) | ||
# [1.2.0](https://github.com/ideal-postcodes/core-node/compare/1.1.0...1.2.0) (2019-12-06) | ||
### Bug Fixes | ||
### Features | ||
* **README:** Check against Markdown lint rules and correct grammar ([1c31977](https://github.com/ideal-postcodes/core-node/commit/1c31977)) | ||
* **Core-Interface:** Upgrade to 1.4.0 ([984e916](https://github.com/ideal-postcodes/core-node/commit/984e916)) | ||
# [1.1.0](https://github.com/ideal-postcodes/core-node/compare/1.0.0...1.1.0) (2019-07-18) | ||
### Features | ||
* **Agent Configuration:** Allow GOT config ([7d367f7](https://github.com/ideal-postcodes/core-node/commit/7d367f7)) | ||
### Docs | ||
# 1.0.0 (2019-06-09) | ||
* **Readme:** Check against Markdown lint rules and correct grammar ([1c31977](https://github.com/ideal-postcodes/core-node/commit/1c31977)) | ||
### Bug Fixes | ||
### Features | ||
* **Error Handling:** HTTP Errors ([79f6021](https://github.com/ideal-postcodes/core-node/commit/79f6021)) | ||
* **Test:** Use nock beta ([7354cc8](https://github.com/ideal-postcodes/core-node/commit/7354cc8)) | ||
* **Agent Configuration:** Allow GOT config ([7d367f7](https://github.com/ideal-postcodes/core-node/commit/7d367f7)) | ||
@@ -21,0 +20,0 @@ # 1.0.0 (2019-06-09) |
@@ -6,13 +6,31 @@ import { GotInstance, GotJSONOptions } from "got"; | ||
} | ||
interface StringMap { | ||
[key: string]: string; | ||
} | ||
/** | ||
* GotConfig | ||
* | ||
* An optional configuration object which is passed to the underlying got http | ||
* client | ||
* | ||
* `got` is the underlying HTTP client that powers core-node. Be careful when | ||
* configuring `gotConfig` so as not to manually override critical request | ||
* attributes like method, query, header, etc. `got` confirmation options | ||
* available here: [github.com/sindresorhus/got#options](https://github.com/sindresorhus/got#options) | ||
*/ | ||
export declare type GotConfig = Partial<GotJSONOptions>; | ||
export declare const toHeader: (gotHeaders: GotHeaders) => StringMap; | ||
/** | ||
* @hidden | ||
*/ | ||
interface ToHeader { | ||
(gotHeaders: GotHeaders): Record<string, string>; | ||
} | ||
/** | ||
* Converts a Got header object to one that can be used by the client | ||
* | ||
* @hidden | ||
*/ | ||
export declare const toHeader: ToHeader; | ||
/** | ||
* Agent | ||
* | ||
* Implements node.js HTTP agent for core-interface client | ||
* | ||
* @hidden | ||
*/ | ||
export declare class Agent implements IAgent { | ||
@@ -19,0 +37,0 @@ got: GotInstance; |
@@ -19,4 +19,12 @@ "use strict"; | ||
var core_interface_1 = require("@ideal-postcodes/core-interface"); | ||
var IdealPostcodesError = core_interface_1.errors.IdealPostcodesError; | ||
// Converts a Got header object to one that can be used by the client | ||
var | ||
/** | ||
* Ideal Postcodes base error class implemented in [core-interface](https://core-interface.ideal-postcodes.dev/classes/idealpostcodeserror.html) | ||
*/ | ||
IdealPostcodesError = core_interface_1.errors.IdealPostcodesError; | ||
/** | ||
* Converts a Got header object to one that can be used by the client | ||
* | ||
* @hidden | ||
*/ | ||
exports.toHeader = function (gotHeaders) { | ||
@@ -34,11 +42,20 @@ return Object.keys(gotHeaders).reduce(function (headers, key) { | ||
}; | ||
var toHttpResponse = function (httpRequest, response) { | ||
return { | ||
httpRequest: httpRequest, | ||
body: response.body, | ||
httpStatus: response.statusCode || 0, | ||
header: exports.toHeader(response.headers), | ||
metadata: { response: response }, | ||
}; | ||
}; | ||
/** | ||
* Adapts got responses to a format consumable by core-interface | ||
* | ||
* @hidden | ||
*/ | ||
var toHttpResponse = function (httpRequest, response) { return ({ | ||
httpRequest: httpRequest, | ||
body: response.body, | ||
httpStatus: response.statusCode || 0, | ||
header: exports.toHeader(response.headers), | ||
metadata: { response: response }, | ||
}); }; | ||
/** | ||
* Catch non-response errors (e.g. network failure, DNS failure, timeout) | ||
* wrap in our Error class and return | ||
* | ||
* @hidden | ||
*/ | ||
var handleError = function (error) { | ||
@@ -52,2 +69,9 @@ var idpcError = new IdealPostcodesError({ | ||
}; | ||
/** | ||
* Agent | ||
* | ||
* Implements node.js HTTP agent for core-interface client | ||
* | ||
* @hidden | ||
*/ | ||
var Agent = /** @class */ (function () { | ||
@@ -54,0 +78,0 @@ function Agent(gotConfig) { |
@@ -1,5 +0,32 @@ | ||
import { Client as CoreInterface, Config as CoreConfig } from "@ideal-postcodes/core-interface"; | ||
import { Client as CoreInterface } from "@ideal-postcodes/core-interface"; | ||
import { GotConfig } from "./agent"; | ||
interface Config extends Partial<CoreConfig> { | ||
export interface Config { | ||
/** | ||
* Use TLS. Defaults to `true` | ||
*/ | ||
tls?: boolean; | ||
/** | ||
* API Key. Used in API helper methods | ||
*/ | ||
api_key: string; | ||
/** | ||
* Target API hostname. Defaults to `'api.ideal-postcodes.co.uk'` | ||
*/ | ||
baseUrl?: string; | ||
/** | ||
* API version. Defaults to `'v1'` | ||
*/ | ||
version?: string; | ||
/** | ||
* Force autocomplete authorisation via HTTP headers only. Defaults to `false` | ||
*/ | ||
strictAuthorisation?: boolean; | ||
/** | ||
* Default time in ms before HTTP request timeout. Defaults to 10s (`10000`) | ||
*/ | ||
timeout?: number; | ||
/** | ||
* String map specifying default headers | ||
*/ | ||
header?: Record<string, string>; | ||
} | ||
@@ -11,8 +38,8 @@ export declare class Client extends CoreInterface { | ||
* | ||
* got is the underlying HTTP client that powers core-node. Be careful when | ||
* configuring gotConfig so as not to manually override critical request | ||
* attributes like method, query, header, etc. | ||
* `got` is the underlying HTTP client that powers core-node. Be careful when | ||
* configuring `gotConfig` so as not to manually override critical request | ||
* attributes like method, query, header, etc. `got` confirmation options | ||
* available here: [github.com/sindresorhus/got#options](https://github.com/sindresorhus/got#options) | ||
*/ | ||
constructor(config: Config, gotConfig?: GotConfig); | ||
} | ||
export {}; |
@@ -29,3 +29,6 @@ "use strict"; | ||
var agent_1 = require("./agent"); | ||
var userAgent = "IdealPostcodes ideal-postcodes/core-node"; | ||
/** | ||
* Default user agent string | ||
*/ | ||
var USER_AGENT = "IdealPostcodes ideal-postcodes/core-node"; | ||
var Client = /** @class */ (function (_super) { | ||
@@ -37,5 +40,6 @@ __extends(Client, _super); | ||
* | ||
* got is the underlying HTTP client that powers core-node. Be careful when | ||
* configuring gotConfig so as not to manually override critical request | ||
* attributes like method, query, header, etc. | ||
* `got` is the underlying HTTP client that powers core-node. Be careful when | ||
* configuring `gotConfig` so as not to manually override critical request | ||
* attributes like method, query, header, etc. `got` confirmation options | ||
* available here: [github.com/sindresorhus/got#options](https://github.com/sindresorhus/got#options) | ||
*/ | ||
@@ -46,3 +50,3 @@ function Client(config, gotConfig) { | ||
var agent = new agent_1.Agent(gotConfig); | ||
var header = { "User-Agent": userAgent }; | ||
var header = { "User-Agent": USER_AGENT }; | ||
var tls = config.tls === undefined ? core_interface_1.TLS : config.tls; | ||
@@ -63,3 +67,3 @@ var baseUrl = config.baseUrl === undefined ? core_interface_1.API_URL : config.baseUrl; | ||
timeout: timeout, | ||
header: __assign({}, header, config.header), | ||
header: __assign(__assign({}, header), config.header), | ||
}; | ||
@@ -66,0 +70,0 @@ _this = _super.call(this, __assign({ agent: agent, header: header }, interfaceConfig)) || this; |
{ | ||
"name": "@ideal-postcodes/core-node", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Node.js client for api.ideal-postcodes.co.uk", | ||
@@ -22,10 +22,10 @@ "author": { | ||
"scripts": { | ||
"semantic-release": "node_modules/.bin/semantic-release --no-ci", | ||
"test:watch": "NODE_ENV=test node_modules/.bin/mocha --watch", | ||
"test:nock:reload": "NODE_ENV=test RECORD=true node_modules/.bin/mocha", | ||
"test": "npm run lint && NODE_ENV=test node_modules/.bin/nyc node_modules/.bin/mocha", | ||
"lint": "node_modules/.bin/tslint -c tslint.json -p tsconfig.json lib/**/*.ts", | ||
"build": "npm run lint && node_modules/.bin/tsc", | ||
"coverage": "node_modules/.bin/nyc report --reporter=text-lcov | node_modules/.bin/coveralls || true", | ||
"docs": "./node_modules/.bin/typedoc --mode file --target ES3 --out docs/ --name 'Ideal Postcodes Node.js Client' --theme minimal --excludePrivate --hideGenerator --excludeExternals lib/", | ||
"semantic-release": "semantic-release --no-ci", | ||
"test:watch": "NODE_ENV=test mocha --watch", | ||
"test:nock:reload": "NODE_ENV=test RECORD=true mocha", | ||
"test": "npm run lint && NODE_ENV=test nyc mocha", | ||
"lint": "eslint lib/**/*.ts", | ||
"build": "npm run lint && tsc", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", | ||
"docs": "typedoc --mode file --out docs/ --name 'Ideal Postcodes Node.js Client' --theme minimal --excludePrivate --hideGenerator lib/", | ||
"prepublishOnly": "npm run test && npm run build" | ||
@@ -37,2 +37,3 @@ }, | ||
"prettier": { | ||
"editorconfig": true, | ||
"trailingComma": "es5" | ||
@@ -91,32 +92,32 @@ }, | ||
"dependencies": { | ||
"@ideal-postcodes/core-interface": "~1.3.0", | ||
"@ideal-postcodes/core-interface": "~1.4.0", | ||
"got": "~9.6.0" | ||
}, | ||
"devDependencies": { | ||
"@cablanchard/semantic-release": "~1.2.1", | ||
"@cablanchard/eslint-config": "~1.1.1", | ||
"@cablanchard/semantic-release": "~1.3.0", | ||
"@cablanchard/tsconfig": "1.0.0", | ||
"@cablanchard/tslint": "0.0.1", | ||
"@ideal-postcodes/api-fixtures": "~0.1.0", | ||
"@ideal-postcodes/api-typings": "~1.1.0", | ||
"@types/chai": "~4.1.7", | ||
"@types/chai": "~4.2.0", | ||
"@types/got": "~9.6.1", | ||
"@types/mocha": "~5.2.7", | ||
"@types/nock": "~10.0.3", | ||
"@types/node": "~12.6.6", | ||
"@types/prettier": "~1.16.4", | ||
"@types/sinon": "~7.0.12", | ||
"@types/nock": "~11.1.0", | ||
"@types/node": "~12.12.0", | ||
"@types/prettier": "~1.19.0", | ||
"@types/sinon": "~7.5.0", | ||
"chai": "~4.2.0", | ||
"coveralls": "~3.0.2", | ||
"mocha": "~6.1.1", | ||
"nock": "11.0.0-beta.27", | ||
"codecov": "~3.6.1", | ||
"eslint": "~6.7.1", | ||
"mocha": "~6.2.0", | ||
"nock": "11.7.0", | ||
"nyc": "~14.1.1", | ||
"prettier": "~1.18.2", | ||
"prettier": "~1.19.1", | ||
"semantic-release": "~15.13.12", | ||
"sinon": "~7.3.2", | ||
"sinon": "~7.5.0", | ||
"source-map-support": "~0.5.10", | ||
"ts-node": "~8.3.0", | ||
"tslint": "~5.18.0", | ||
"typedoc": "~0.14.2", | ||
"typescript": "~3.5.1" | ||
"ts-node": "~8.5.0", | ||
"typedoc": "~0.15.0", | ||
"typescript": "~3.7.2" | ||
} | ||
} |
@@ -8,5 +8,5 @@ <h1 align="center"> | ||
[![CircleCI](https://circleci.com/gh/ideal-postcodes/core-node/tree/master.svg?style=svg)](https://circleci.com/gh/ideal-postcodes/core-node/tree/master) | ||
[![Coverage Status](https://coveralls.io/repos/github/ideal-postcodes/core-node/badge.svg?branch=master&t=nyUaqN)](https://coveralls.io/github/ideal-postcodes/core-node?branch=master) | ||
![Dependency Status](https://david-dm.org/ideal-postcodes/core-node.svg) | ||
[![npm version](https://badge.fury.io/js/%40ideal-postcodes%2Fcore-node.svg)](https://badge.fury.io/js/%40ideal-postcodes%2Fcore-node) | ||
[![codecov](https://codecov.io/gh/ideal-postcodes/core-node/branch/master/graph/badge.svg)](https://codecov.io/gh/ideal-postcodes/core-node) | ||
[![Dependency Status](https://david-dm.org/ideal-postcodes/core-node.svg)](https://david-dm.org/ideal-postcodes/core-node) | ||
[![npm version](https://badge.fury.io/js/%40ideal-postcodes%2Fcore-node.svg)](https://www.npmjs.com/package/@ideal-postcodes/core-node) | ||
[![install size](https://packagephobia.now.sh/badge?p=@ideal-postcodes/core-node)](https://packagephobia.now.sh/result?p=@ideal-postcodes/core-node) | ||
@@ -16,10 +16,10 @@ | ||
Our JavaScript client implements a common interface which is implemented at [`@ideal-postcodes/core-interface`](https://github.com/ideal-postcodes/core-interface). In depth client documentation can be found at [core-interface.ideal-postcodes.dev](https://core-interface.ideal-postcodes.dev). | ||
Our JavaScript client implements a common interface defined at [@ideal-postcodes/core-interface](https://github.com/ideal-postcodes/core-interface). | ||
`@ideal-postcodes/core-node` is tested against [all maintained, stable releases](https://nodejs.org/en/about/releases/). [CI test suite](.circleci/config.yml) targets: | ||
High level client documentation can be found at [core-interface](https://github.com/ideal-postcodes/core-interface/blob/master/README.md). | ||
- Node.js 12 | ||
- Node.js 10 | ||
- Node.js 8 | ||
In depth client documentation can be found at [core-interface.ideal-postcodes.dev](https://core-interface.ideal-postcodes.dev). | ||
`@ideal-postcodes/core-node` is tested against [all maintained, stable releases](https://nodejs.org/en/about/releases/). | ||
## Links | ||
@@ -29,4 +29,4 @@ | ||
- [Quickstart](#quickstart) | ||
- [Client Documentation](https://core-interface.ideal-postcodes.dev/#documentation) | ||
- [Core JS API Client Documentation](https://core-interface.ideal-postcodes.dev/) | ||
- [Client Documentation](https://github.com/ideal-postcodes/core-interface/blob/master/README.md) | ||
- [In Depth Client Documentation](https://core-interface.ideal-postcodes.dev/#documentation) | ||
- [npm Module](https://www.npmjs.com/package/@ideal-postcodes/core-node) | ||
@@ -47,4 +47,4 @@ - [GitHub Repository](https://github.com/ideal-postcodes/core-node) | ||
- [Catch Errors](#catch-errors) | ||
- [Configure Agent](#configure-agent) | ||
- [Proxy HTTP Requests](#proxy-requests) | ||
- [Configure Agent](#configure-http-agent) | ||
- [Proxy HTTP Requests](#proxy-requests) | ||
@@ -102,2 +102,3 @@ #### Install | ||
afterResponse: response => { | ||
modify(response); | ||
log(response); | ||
@@ -110,3 +111,3 @@ return response; | ||
#### Proxy HTTP Requests | ||
##### Proxy HTTP Requests | ||
@@ -175,12 +176,6 @@ You can [proxy requests](https://github.com/sindresorhus/got#proxies) by configuring the underlying [got](https://github.com/sindresorhus/got) HTTP client. | ||
[Method options](https://core-interface.ideal-postcodes.dev/interfaces/lookupumprnoptions.html) | ||
[Method options](https://core-interface.ideal-postcodes.dev/interfaces/lookupudprnoptions.html) | ||
## Test | ||
`@ideal-postcodes/core-node` is tested on: | ||
- Node 8 | ||
- Node 10 | ||
- Node 12 | ||
```bash | ||
@@ -187,0 +182,0 @@ npm test |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
24439
268
181
+ Added@ideal-postcodes/core-interface@1.4.0(transitive)
- Removed@ideal-postcodes/core-interface@1.3.0(transitive)