Socket
Socket
Sign inDemoInstall

@ideal-postcodes/core-interface

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ideal-postcodes/core-interface - npm Package Compare versions

Comparing version 1.7.0 to 1.8.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [1.8.0](https://github.com/ideal-postcodes/core-interface/compare/1.7.0...1.8.0) (2020-10-22)
### Features
* **ESM:** Target ESNext in ESM builds ([d44f960](https://github.com/ideal-postcodes/core-interface/commit/d44f960b314a89881b6afd67f9c8f44cc0a7621a))
# [1.7.0](https://github.com/ideal-postcodes/core-interface/compare/1.6.0...1.7.0) (2020-10-21)

@@ -2,0 +9,0 @@

145

esm/client.js

@@ -1,12 +0,1 @@

var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { IdpcPostcodeNotFoundError, IdpcUmprnNotFoundError, IdpcUdprnNotFoundError, } from "./error";

@@ -21,4 +10,4 @@ import * as errors from "./error";

import { create as createAutocompleteResource, } from "./resources/autocomplete";
var Client = /** @class */ (function () {
function Client(config) {
export class Client {
constructor(config) {
this.tls = config.tls;

@@ -31,3 +20,3 @@ this.api_key = config.api_key;

this.agent = config.agent;
this.header = __assign(__assign({}, Client.defaults.header), config.header);
this.header = { ...Client.defaults.header, ...config.header };
this.postcodes = createPostcodeResource(this);

@@ -43,8 +32,8 @@ this.addresses = createAddressResource(this);

*/
Client.prototype.url = function () {
return this.protocol() + "://" + this.baseUrl + "/" + this.version;
};
Client.prototype.protocol = function () {
url() {
return `${this.protocol()}://${this.baseUrl}/${this.version}`;
}
protocol() {
return this.tls ? "https" : "http";
};
}
/**

@@ -55,8 +44,8 @@ * Ping API base (`/`)

*/
Client.prototype.ping = function () {
var method = "GET";
var url = this.protocol() + "://" + this.baseUrl + "/";
ping() {
const method = "GET";
const url = `${this.protocol()}://${this.baseUrl}/`;
return this.agent.http({
method: method,
url: url,
method,
url,
header: {},

@@ -66,3 +55,3 @@ query: {},

});
};
}
/**

@@ -77,5 +66,5 @@ * Lookup Postcode

*/
Client.prototype.lookupPostcode = function (options) {
var queryOptions = this.toAddressIdQuery(options);
var page = options.page;
lookupPostcode(options) {
const queryOptions = this.toAddressIdQuery(options);
const { page } = options;
if (page !== undefined)

@@ -85,4 +74,4 @@ queryOptions.query.page = page.toString();

.retrieve(options.postcode, queryOptions)
.then(function (response) { return response.body.result; })
.catch(function (error) {
.then((response) => response.body.result)
.catch((error) => {
if (error instanceof IdpcPostcodeNotFoundError)

@@ -92,3 +81,3 @@ return [];

});
};
}
/**

@@ -101,11 +90,11 @@ * Lookup Address

*/
Client.prototype.lookupAddress = function (options) {
var header = {};
var query = { query: options.query };
appendAuthorization({ client: this, header: header, options: options });
appendIp({ header: header, options: options });
appendFilter({ query: query, options: options });
appendTags({ query: query, options: options });
appendPage({ query: query, options: options });
var queryOptions = { header: header, query: query };
lookupAddress(options) {
const header = {};
const query = { query: options.query };
appendAuthorization({ client: this, header, options });
appendIp({ header, options });
appendFilter({ query, options });
appendTags({ query, options });
appendPage({ query, options });
const queryOptions = { header, query };
if (options.timeout !== undefined)

@@ -115,4 +104,4 @@ queryOptions.timeout = options.timeout;

.list(queryOptions)
.then(function (response) { return response.body.result.hits; });
};
.then((response) => response.body.result.hits);
}
/**

@@ -125,14 +114,14 @@ * Generates a request object. Bundles together commonly used header/query extractions:

*/
Client.prototype.toAddressIdQuery = function (options) {
var header = {};
var query = {};
appendAuthorization({ client: this, header: header, options: options });
appendIp({ header: header, options: options });
appendFilter({ query: query, options: options });
appendTags({ query: query, options: options });
var request = { header: header, query: query };
toAddressIdQuery(options) {
const header = {};
const query = {};
appendAuthorization({ client: this, header, options });
appendIp({ header, options });
appendFilter({ query, options });
appendTags({ query, options });
const request = { header, query };
if (options.timeout !== undefined)
request.timeout = options.timeout;
return request;
};
}
/**

@@ -147,8 +136,8 @@ * Lookup UDPRN

*/
Client.prototype.lookupUdprn = function (options) {
var queryOptions = this.toAddressIdQuery(options);
lookupUdprn(options) {
const queryOptions = this.toAddressIdQuery(options);
return this.udprn
.retrieve(options.udprn.toString(), queryOptions)
.then(function (response) { return response.body.result; })
.catch(function (error) {
.then((response) => response.body.result)
.catch((error) => {
if (error instanceof IdpcUdprnNotFoundError)

@@ -158,3 +147,3 @@ return null;

});
};
}
/**

@@ -169,8 +158,8 @@ * Lookup UMPRN

*/
Client.prototype.lookupUmprn = function (options) {
var queryOptions = this.toAddressIdQuery(options);
lookupUmprn(options) {
const queryOptions = this.toAddressIdQuery(options);
return this.umprn
.retrieve(options.umprn.toString(), queryOptions)
.then(function (response) { return response.body.result; })
.catch(function (error) {
.then((response) => response.body.result)
.catch((error) => {
if (error instanceof IdpcUmprnNotFoundError)

@@ -180,3 +169,3 @@ return null;

});
};
}
/**

@@ -189,6 +178,6 @@ * Check Key Availability

*/
Client.prototype.checkKeyUsability = function (options) {
var _a = options.api_key, api_key = _a === void 0 ? this.api_key : _a, timeout = options.timeout;
var licensee = options.licensee;
var query;
checkKeyUsability(options) {
const { api_key = this.api_key, timeout } = options;
const { licensee } = options;
let query;
if (licensee === undefined) {

@@ -198,5 +187,5 @@ query = {};

else {
query = { licensee: licensee };
query = { licensee };
}
var queryOptions = { query: query, header: {} };
const queryOptions = { query, header: {} };
if (timeout !== undefined)

@@ -206,14 +195,12 @@ queryOptions.timeout = timeout;

.retrieve(api_key, queryOptions)
.then(function (response) { return response.body.result; }); // Assert that we're retrieving public key information as no user_token provided
};
Client.defaults = {
header: {
Accept: "application/json",
"Content-Type": "application/json",
},
};
Client.errors = errors;
return Client;
}());
export { Client };
.then((response) => response.body.result); // Assert that we're retrieving public key information as no user_token provided
}
}
Client.defaults = {
header: {
Accept: "application/json",
"Content-Type": "application/json",
},
};
Client.errors = errors;
//# sourceMappingURL=client.js.map

@@ -1,14 +0,1 @@

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// Take note of https://github.com/Microsoft/TypeScript/issues/13965

@@ -22,26 +9,20 @@ /**

*/
var IdealPostcodesError = /** @class */ (function (_super) {
__extends(IdealPostcodesError, _super);
export class IdealPostcodesError extends Error {
/**
* Instantiate IdealPostcodesError
*/
function IdealPostcodesError(options) {
var _newTarget = this.constructor;
var _this = this;
var trueProto = _newTarget.prototype;
_this = _super.call(this) || this;
_this.__proto__ = trueProto;
var message = options.message, httpStatus = options.httpStatus, _a = options.metadata, metadata = _a === void 0 ? {} : _a;
_this.message = message;
_this.name = "Ideal Postcodes Error";
_this.httpStatus = httpStatus;
_this.metadata = metadata;
constructor(options) {
const trueProto = new.target.prototype;
super();
this.__proto__ = trueProto;
const { message, httpStatus, metadata = {} } = options;
this.message = message;
this.name = "Ideal Postcodes Error";
this.httpStatus = httpStatus;
this.metadata = metadata;
if (Error.captureStackTrace) {
Error.captureStackTrace(_this, IdealPostcodesError);
Error.captureStackTrace(this, IdealPostcodesError);
}
return _this;
}
return IdealPostcodesError;
}(Error));
export { IdealPostcodesError };
}
/**

@@ -53,18 +34,14 @@ * IdpcApiError

*/
var IdpcApiError = /** @class */ (function (_super) {
__extends(IdpcApiError, _super);
export class IdpcApiError extends IdealPostcodesError {
/**
* Returns an API error instance
*/
function IdpcApiError(httpResponse) {
var _this = _super.call(this, {
constructor(httpResponse) {
super({
httpStatus: httpResponse.httpStatus,
message: httpResponse.body.message,
}) || this;
_this.response = httpResponse;
return _this;
});
this.response = httpResponse;
}
return IdpcApiError;
}(IdealPostcodesError));
export { IdpcApiError };
}
/**

@@ -80,10 +57,4 @@ * IdpcBadRequestError

*/
var IdpcBadRequestError = /** @class */ (function (_super) {
__extends(IdpcBadRequestError, _super);
function IdpcBadRequestError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return IdpcBadRequestError;
}(IdpcApiError));
export { IdpcBadRequestError };
export class IdpcBadRequestError extends IdpcApiError {
}
/**

@@ -99,10 +70,4 @@ * IdpcUnauthorisedError

*/
var IdpcUnauthorisedError = /** @class */ (function (_super) {
__extends(IdpcUnauthorisedError, _super);
function IdpcUnauthorisedError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return IdpcUnauthorisedError;
}(IdpcApiError));
export { IdpcUnauthorisedError };
export class IdpcUnauthorisedError extends IdpcApiError {
}
/**

@@ -113,10 +78,4 @@ * IpdcInvalidKeyError

*/
var IdpcInvalidKeyError = /** @class */ (function (_super) {
__extends(IdpcInvalidKeyError, _super);
function IdpcInvalidKeyError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return IdpcInvalidKeyError;
}(IdpcUnauthorisedError));
export { IdpcInvalidKeyError };
export class IdpcInvalidKeyError extends IdpcUnauthorisedError {
}
/**

@@ -131,10 +90,4 @@ * IdpcRequestFailedError

*/
var IdpcRequestFailedError = /** @class */ (function (_super) {
__extends(IdpcRequestFailedError, _super);
function IdpcRequestFailedError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return IdpcRequestFailedError;
}(IdpcApiError));
export { IdpcRequestFailedError };
export class IdpcRequestFailedError extends IdpcApiError {
}
/**

@@ -145,10 +98,4 @@ * IdpcBalanceDepleted

*/
var IdpcBalanceDepletedError = /** @class */ (function (_super) {
__extends(IdpcBalanceDepletedError, _super);
function IdpcBalanceDepletedError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return IdpcBalanceDepletedError;
}(IdpcRequestFailedError));
export { IdpcBalanceDepletedError };
export class IdpcBalanceDepletedError extends IdpcRequestFailedError {
}
/**

@@ -162,10 +109,4 @@ * IdpcLimitReachedError

*/
var IdpcLimitReachedError = /** @class */ (function (_super) {
__extends(IdpcLimitReachedError, _super);
function IdpcLimitReachedError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return IdpcLimitReachedError;
}(IdpcRequestFailedError));
export { IdpcLimitReachedError };
export class IdpcLimitReachedError extends IdpcRequestFailedError {
}
/**

@@ -181,10 +122,4 @@ * IdpcResourceNotFoundError

*/
var IdpcResourceNotFoundError = /** @class */ (function (_super) {
__extends(IdpcResourceNotFoundError, _super);
function IdpcResourceNotFoundError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return IdpcResourceNotFoundError;
}(IdpcApiError));
export { IdpcResourceNotFoundError };
export class IdpcResourceNotFoundError extends IdpcApiError {
}
/**

@@ -195,10 +130,4 @@ * IdpcPostcodeNotFoundError

*/
var IdpcPostcodeNotFoundError = /** @class */ (function (_super) {
__extends(IdpcPostcodeNotFoundError, _super);
function IdpcPostcodeNotFoundError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return IdpcPostcodeNotFoundError;
}(IdpcResourceNotFoundError));
export { IdpcPostcodeNotFoundError };
export class IdpcPostcodeNotFoundError extends IdpcResourceNotFoundError {
}
/**

@@ -209,10 +138,4 @@ * IdpcKeyNotFoundError

*/
var IdpcKeyNotFoundError = /** @class */ (function (_super) {
__extends(IdpcKeyNotFoundError, _super);
function IdpcKeyNotFoundError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return IdpcKeyNotFoundError;
}(IdpcResourceNotFoundError));
export { IdpcKeyNotFoundError };
export class IdpcKeyNotFoundError extends IdpcResourceNotFoundError {
}
/**

@@ -223,10 +146,4 @@ * IdpcUdprnNotFoundError

*/
var IdpcUdprnNotFoundError = /** @class */ (function (_super) {
__extends(IdpcUdprnNotFoundError, _super);
function IdpcUdprnNotFoundError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return IdpcUdprnNotFoundError;
}(IdpcResourceNotFoundError));
export { IdpcUdprnNotFoundError };
export class IdpcUdprnNotFoundError extends IdpcResourceNotFoundError {
}
/**

@@ -237,10 +154,4 @@ * IdpcUmprnNotFoundError

*/
var IdpcUmprnNotFoundError = /** @class */ (function (_super) {
__extends(IdpcUmprnNotFoundError, _super);
function IdpcUmprnNotFoundError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return IdpcUmprnNotFoundError;
}(IdpcResourceNotFoundError));
export { IdpcUmprnNotFoundError };
export class IdpcUmprnNotFoundError extends IdpcResourceNotFoundError {
}
/**

@@ -251,32 +162,26 @@ * IdpcServerError

*/
var IdpcServerError = /** @class */ (function (_super) {
__extends(IdpcServerError, _super);
function IdpcServerError() {
return _super !== null && _super.apply(this, arguments) || this;
}
return IdpcServerError;
}(IdpcApiError));
export { IdpcServerError };
export class IdpcServerError extends IdpcApiError {
}
// 200 Responses
var OK = 200;
const OK = 200;
// 300 Responses
var REDIRECT = 300;
const REDIRECT = 300;
// 400 Responses
var BAD_REQUEST = 400;
const BAD_REQUEST = 400;
// 401 Responses
var UNAUTHORISED = 401;
var INVALID_KEY = 4010;
const UNAUTHORISED = 401;
const INVALID_KEY = 4010;
// 402 Responses
var PAYMENT_REQUIRED = 402;
var BALANCE_DEPLETED = 4020;
var LIMIT_REACHED = 4021;
const PAYMENT_REQUIRED = 402;
const BALANCE_DEPLETED = 4020;
const LIMIT_REACHED = 4021;
// 404 Responses
var NOT_FOUND = 404;
var POSTCODE_NOT_FOUND = 4040;
var KEY_NOT_FOUND = 4042;
var UDPRN_NOT_FOUND = 4044;
var UMPRN_NOT_FOUND = 4046;
const NOT_FOUND = 404;
const POSTCODE_NOT_FOUND = 4040;
const KEY_NOT_FOUND = 4042;
const UDPRN_NOT_FOUND = 4044;
const UMPRN_NOT_FOUND = 4046;
// 500 Responses
var SERVER_ERROR = 500;
var isSuccess = function (code) {
const SERVER_ERROR = 500;
const isSuccess = (code) => {
if (code < OK)

@@ -288,3 +193,3 @@ return false;

};
var isObject = function (o) {
const isObject = (o) => {
if (o === null)

@@ -296,3 +201,3 @@ return false;

};
var isErrorResponse = function (body) {
const isErrorResponse = (body) => {
if (!isObject(body))

@@ -313,4 +218,4 @@ return false;

*/
export var parse = function (response) {
var httpStatus = response.httpStatus, body = response.body;
export const parse = (response) => {
const { httpStatus, body } = response;
if (isSuccess(httpStatus))

@@ -320,3 +225,3 @@ return;

// Test for specific API errors of interest
var code = body.code;
const { code } = body;
if (code === INVALID_KEY)

@@ -349,4 +254,4 @@ return new IdpcInvalidKeyError(response);

// Generate generic error (backstop)
return new IdealPostcodesError({ httpStatus: httpStatus, message: JSON.stringify(body) });
return new IdealPostcodesError({ httpStatus, message: JSON.stringify(body) });
};
//# sourceMappingURL=error.js.map

@@ -7,15 +7,15 @@ /**

*/
export var API_URL = "api.ideal-postcodes.co.uk";
export const API_URL = "api.ideal-postcodes.co.uk";
/**
* Use TLS by default. Set to `true`
*/
export var TLS = true;
export const TLS = true;
/**
* Default API Version number. Defaults to "v1"
*/
export var VERSION = "v1";
export const VERSION = "v1";
/**
* Default HTTP timeout in milliseconds. Defaults to 10s
*/
export var TIMEOUT = 10000;
export const TIMEOUT = 10000;
/*

@@ -26,3 +26,3 @@ * STRICT_AUTHORISATION forces authorization header usage on

*/
export var STRICT_AUTHORISATION = false;
export const STRICT_AUTHORISATION = false;
export { Client } from "./client";

@@ -29,0 +29,0 @@ import * as errors from "./error";

import { listMethod } from "./resource";
var resource = "addresses";
export var create = function (client) {
var list = listMethod({ resource: resource, client: client });
return { list: list };
const resource = "addresses";
export const create = (client) => {
const list = listMethod({ resource, client });
return { list };
};
//# sourceMappingURL=addresses.js.map
import { listMethod } from "./resource";
var resource = "autocomplete/addresses";
export var create = function (client) {
var list = listMethod({
resource: resource,
client: client,
const resource = "autocomplete/addresses";
export const create = (client) => {
const list = listMethod({
resource,
client,
});
return { list: list };
return { list };
};
//# sourceMappingURL=autocomplete.js.map
import { retrieveMethod } from "./resource";
var resource = "keys";
export var create = function (client) {
var retrieve = retrieveMethod({
resource: resource,
client: client,
const resource = "keys";
export const create = (client) => {
const retrieve = retrieveMethod({
resource,
client,
});
var usage = retrieveMethod({
resource: resource,
client: client,
const usage = retrieveMethod({
resource,
client,
action: "usage",
});
return { retrieve: retrieve, usage: usage };
return { retrieve, usage };
};
//# sourceMappingURL=keys.js.map
import { retrieveMethod } from "./resource";
var resource = "postcodes";
export var create = function (client) {
var retrieve = retrieveMethod({
resource: resource,
client: client,
const resource = "postcodes";
export const create = (client) => {
const retrieve = retrieveMethod({
resource,
client,
});
return { retrieve: retrieve };
return { retrieve };
};
//# sourceMappingURL=postcodes.js.map
import { toStringMap, toTimeout, toHeader } from "../util";
import { parse } from "../error";
// Writes a resource to URL string
var toRetrieveUrl = function (options, id) {
return [
options.client.url(),
options.resource,
encodeURIComponent(id),
options.action,
]
.filter(function (e) { return e !== undefined; })
.join("/");
const toRetrieveUrl = (options, id) => [
options.client.url(),
options.resource,
encodeURIComponent(id),
options.action,
]
.filter((e) => e !== undefined)
.join("/");
export const retrieveMethod = (options) => {
const { client } = options;
return (id, request) => client.agent
.http({
method: "GET",
url: toRetrieveUrl(options, id),
query: toStringMap(request.query),
header: toHeader(request, client),
timeout: toTimeout(request, client),
})
.then((response) => {
const error = parse(response);
if (error)
throw error;
return response;
});
};
export var retrieveMethod = function (options) {
var client = options.client;
return function (id, request) {
return client.agent
.http({
method: "GET",
url: toRetrieveUrl(options, id),
query: toStringMap(request.query),
header: toHeader(request, client),
timeout: toTimeout(request, client),
})
.then(function (response) {
var error = parse(response);
if (error)
throw error;
return response;
});
};
export const listMethod = (options) => {
const { client, resource } = options;
return (request) => client.agent
.http({
method: "GET",
url: `${client.url()}/${resource}`,
query: toStringMap(request.query),
header: toHeader(request, client),
timeout: toTimeout(request, client),
})
.then((response) => {
const error = parse(response);
if (error)
throw error;
return response;
});
};
export var listMethod = function (options) {
var client = options.client, resource = options.resource;
return function (request) {
return client.agent
.http({
method: "GET",
url: client.url() + "/" + resource,
query: toStringMap(request.query),
header: toHeader(request, client),
timeout: toTimeout(request, client),
})
.then(function (response) {
var error = parse(response);
if (error)
throw error;
return response;
});
};
};
//# sourceMappingURL=resource.js.map
import { retrieveMethod } from "./resource";
var resource = "udprn";
export var create = function (client) {
var retrieve = retrieveMethod({ resource: resource, client: client });
return { retrieve: retrieve };
const resource = "udprn";
export const create = (client) => {
const retrieve = retrieveMethod({ resource, client });
return { retrieve };
};
//# sourceMappingURL=udprn.js.map
import { retrieveMethod } from "./resource";
var resource = "umprn";
export var create = function (client) {
var retrieve = retrieveMethod({ resource: resource, client: client });
return { retrieve: retrieve };
const resource = "umprn";
export const create = (client) => {
const retrieve = retrieveMethod({ resource, client });
return { retrieve };
};
//# sourceMappingURL=umprn.js.map

@@ -1,12 +0,1 @@

var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/**

@@ -17,8 +6,8 @@ * toQuery

*/
export var toStringMap = function (optional) {
export const toStringMap = (optional) => {
if (optional === undefined)
return {};
return Object.keys(optional).reduce(function (result, key) {
var value = optional[key];
var reduce = reduceStringMap(value);
return Object.keys(optional).reduce((result, key) => {
const value = optional[key];
const reduce = reduceStringMap(value);
if (reduce.length > 0)

@@ -29,8 +18,8 @@ result[key] = reduce;

};
var isString = function (i) { return typeof i === "string"; };
var isArray = function (i) { return Array.isArray(i); };
var reduceStringMap = function (value) {
var result = [];
const isString = (i) => typeof i === "string";
const isArray = (i) => Array.isArray(i);
const reduceStringMap = (value) => {
const result = [];
if (isArray(value)) {
value.forEach(function (val) {
value.forEach((val) => {
if (isNumber(val))

@@ -49,3 +38,3 @@ result.push(val.toString());

};
var isNumber = function (n) { return typeof n === "number"; };
const isNumber = (n) => typeof n === "number";
/**

@@ -57,4 +46,3 @@ * toTimeout

*/
export var toTimeout = function (_a, client) {
var timeout = _a.timeout;
export const toTimeout = ({ timeout }, client) => {
if (isNumber(timeout))

@@ -71,5 +59,4 @@ return timeout;

*/
export var toHeader = function (_a, client) {
var _b = _a.header, header = _b === void 0 ? {} : _b;
return __assign(__assign({}, client.header), toStringMap(header));
export const toHeader = ({ header = {} }, client) => {
return { ...client.header, ...toStringMap(header) };
};

@@ -81,13 +68,13 @@ /**

*/
export var toAuthHeader = function (client, options) {
var credentials = [];
var api_key = options.api_key || client.api_key;
export const toAuthHeader = (client, options) => {
const credentials = [];
const api_key = options.api_key || client.api_key;
credentials.push(["api_key", api_key]);
var licensee = options.licensee;
const licensee = options.licensee;
if (licensee !== undefined)
credentials.push(["licensee", licensee]);
var user_token = options.user_token;
const user_token = options.user_token;
if (user_token !== undefined)
credentials.push(["user_token", user_token]);
return "IDEALPOSTCODES " + toCredentialString(credentials);
return `IDEALPOSTCODES ${toCredentialString(credentials)}`;
};

@@ -102,17 +89,12 @@ /**

*/
export var appendAuthorization = function (_a) {
var header = _a.header, options = _a.options, client = _a.client;
export const appendAuthorization = ({ header, options, client, }) => {
header.Authorization = toAuthHeader(client, options);
return header;
};
var toCredentialString = function (credentials) {
return credentials.map(function (_a) {
var key = _a[0], value = _a[1];
return key + "=\"" + value + "\"";
}).join(" ");
const toCredentialString = (credentials) => {
return credentials.map(([key, value]) => `${key}="${value}"`).join(" ");
};
// Adds source IP to headers
export var appendIp = function (_a) {
var header = _a.header, options = _a.options;
var sourceIp = options.sourceIp;
export const appendIp = ({ header, options }) => {
const { sourceIp } = options;
if (sourceIp !== undefined)

@@ -123,5 +105,4 @@ header["IDPC-Source-IP"] = sourceIp;

// Adds filters to query
export var appendFilter = function (_a) {
var query = _a.query, options = _a.options;
var filter = options.filter;
export const appendFilter = ({ query, options, }) => {
const { filter } = options;
if (filter !== undefined)

@@ -132,5 +113,4 @@ query.filter = filter.join(",");

// Adds tags to query
export var appendTags = function (_a) {
var query = _a.query, options = _a.options;
var tags = options.tags;
export const appendTags = ({ query, options, }) => {
const { tags } = options;
if (tags !== undefined)

@@ -141,5 +121,4 @@ query.tags = tags.join(",");

// Adds pagination attributes to query
export var appendPage = function (_a) {
var query = _a.query, options = _a.options;
var page = options.page, limit = options.limit;
export const appendPage = ({ query, options, }) => {
const { page, limit } = options;
if (page !== undefined)

@@ -146,0 +125,0 @@ query.page = page.toString();

{
"name": "@ideal-postcodes/core-interface",
"version": "1.7.0",
"version": "1.8.0",
"description": "Interface specification for javascript based API Clients to api.ideal-postcodes.co.uk",

@@ -5,0 +5,0 @@ "author": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc