feat: added nyc for test coverage reporting. fix: add jsdoc comments

This commit is contained in:
StevanFreeborn
2023-01-26 13:58:25 -06:00
parent b36d9445bd
commit 8b6e5ccefc
10 changed files with 2993 additions and 27 deletions
+27 -10
View File
@@ -1,25 +1,42 @@
import { AxiosInstance } from "axios";
import axios from "axios";
import { ArgumentValidator } from "./models/ArgumentValidator";
import { AxiosInstance } from 'axios';
import axios from 'axios';
import { ArgumentValidator } from './models/ArgumentValidator';
/**
* @class OnspringClient - A client that can communicate with the Onspring API.
*/
export class OnspringClient {
/**
* @property {AxiosInstance} client - The axios instance that will be used to make requests to the Onspring API.
*/
protected readonly client: AxiosInstance;
constructor(baseUrl: string | undefined | null, apiKey: string | undefined | null) {
/**
* @constructor - Creates a new instance of the OnspringClient class.
* @param {string} baseUrl - The base url that will be used to make requests to the Onspring API.
* @param {string} apiKey - The api key that will be used to authorize requests made by this client.
* @throws {Error} - Thrown when the baseUrl is not a valid url.
* @throws {Error} - Thrown when the apiKey is null/undefined/empty/whitespace.
* @returns {OnspringClient} - A new instance of the OnspringClient class.
*/
constructor(
baseUrl: string | undefined | null,
apiKey: string | undefined | null
) {
if (ArgumentValidator.isValidUrl(baseUrl) === false) {
throw new Error("baseUrl must be an absolute and well-formed URI.");
throw new Error('baseUrl must be an absolute and well-formed URI.');
}
if (ArgumentValidator.isNullOrWhiteSpace(apiKey)) {
throw new Error("apiKey cannot be null/empty/whitespace.");
if (ArgumentValidator.isNullOrWhiteSpace(apiKey)) {
throw new Error('apiKey cannot be null/empty/whitespace.');
}
this.client = axios.create({
baseURL: baseUrl,
headers: {
"x-apikey": apiKey,
"x-api-version": "2",
'x-apikey': apiKey,
'x-api-version': '2',
},
});
}
}
}