fix: enabled strict null checks and made changes to deal with this compiler change. fix: modified endpoint factory methods to not need baseURL to be passed in. instead just return endpoint because the axios client with already have a default url set as part of constructing a new onspring client instance
This commit is contained in:
+4
-12
@@ -29,7 +29,7 @@ export class OnspringClient {
|
||||
baseUrl: string | undefined | null,
|
||||
apiKey: string | undefined | null
|
||||
) {
|
||||
if (ArgumentValidator.isValidUrl(baseUrl) === false) {
|
||||
if (ArgumentValidator.isValidUrl(baseUrl) === false || baseUrl === null) {
|
||||
throw new Error('baseUrl must be an absolute and well-formed URI.');
|
||||
}
|
||||
|
||||
@@ -48,9 +48,7 @@ export class OnspringClient {
|
||||
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating if the client can connect to the Onspring API.
|
||||
*/
|
||||
public async canConnect(): Promise<boolean> {
|
||||
const endpoint = EndpointFactory.getPingEndpoint(
|
||||
this._client.defaults.baseURL
|
||||
);
|
||||
const endpoint = EndpointFactory.getPingEndpoint();
|
||||
|
||||
const response = await this.get<any>(endpoint);
|
||||
return response.isSuccessful;
|
||||
@@ -64,10 +62,7 @@ export class OnspringClient {
|
||||
public async getApps(
|
||||
pagingRequest: PagingRequest = new PagingRequest(1, 50)
|
||||
): Promise<ApiResponse<GetPagedAppsResponse>> {
|
||||
const endpoint = EndpointFactory.getAppsEndpoint(
|
||||
this._client.defaults.baseURL,
|
||||
pagingRequest
|
||||
);
|
||||
const endpoint = EndpointFactory.getAppsEndpoint(pagingRequest);
|
||||
|
||||
var apiResponse = await this.get<any>(endpoint);
|
||||
|
||||
@@ -79,10 +74,7 @@ export class OnspringClient {
|
||||
}
|
||||
|
||||
public async getAppById(appId: number): Promise<ApiResponse<App>> {
|
||||
const endpoint = EndpointFactory.getAppByIdEndpoint(
|
||||
this._client.defaults.baseURL,
|
||||
appId
|
||||
);
|
||||
const endpoint = EndpointFactory.getAppByIdEndpoint(appId);
|
||||
|
||||
var apiResponse = await this.get<any>(endpoint);
|
||||
|
||||
|
||||
@@ -23,16 +23,16 @@ export class ApiResponse<T> {
|
||||
/**
|
||||
* @property {T} data - The data of the response.
|
||||
*/
|
||||
public data: T;
|
||||
public data: T | null;
|
||||
|
||||
/**
|
||||
* @constructor - Creates a new instance of the ApiResponse class.
|
||||
* @param {number} statusCode - The status code of the response.
|
||||
* @param {string} message - The message of the response.
|
||||
* @param {T} data - The data of the response.
|
||||
* @param {T | null} data - The data of the response.
|
||||
* @returns {ApiResponse<T>} - A new instance of the ApiResponse class.
|
||||
*/
|
||||
constructor(statusCode: number, message: string, data: T) {
|
||||
constructor(statusCode: number, message: string, data: T | null) {
|
||||
this.statusCode = statusCode;
|
||||
this.isSuccessful = statusCode < 400;
|
||||
this.message = message;
|
||||
|
||||
@@ -17,6 +17,10 @@ export class ArgumentValidator {
|
||||
public static isValidUrl(value: string | null | undefined): boolean {
|
||||
let url: URL;
|
||||
|
||||
if (value === null || value === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
url = new URL(value);
|
||||
} catch (error) {
|
||||
@@ -32,6 +36,10 @@ export class ArgumentValidator {
|
||||
* @remarks - A valid page size is a number greater than 0 and less than or equal to 1000.
|
||||
*/
|
||||
public static isValidPageSize(value: number | null | undefined): boolean {
|
||||
if (value === null || value === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return value > 0 && value <= 1000;
|
||||
}
|
||||
|
||||
@@ -41,6 +49,10 @@ export class ArgumentValidator {
|
||||
* @remarks - A valid page number is a number greater than 0.
|
||||
*/
|
||||
public static isValidPageNumber(value: number | null | undefined): boolean {
|
||||
if (value === null || value === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return value > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,242 +5,197 @@ import { PagingRequest } from './PagingRequest';
|
||||
*/
|
||||
export class EndpointFactory {
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the ping endpoint.
|
||||
* @returns {string} - The ping endpoint.
|
||||
*/
|
||||
public static getPingEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Ping`;
|
||||
public static getPingEndpoint(): string {
|
||||
return '/Ping';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the apps endpoint.
|
||||
* @param {PagingRequest} pagingRequest - Pagination information to use as query params in the endpoint string.
|
||||
* @returns {string} - The apps endpoint.
|
||||
*/
|
||||
public static getAppsEndpoint(
|
||||
baseUrl: string,
|
||||
pagingRequest: PagingRequest
|
||||
): string {
|
||||
return `${baseUrl}/Apps?pageSize=${pagingRequest.pageSize}&pageNumber=${pagingRequest.pageNumber}`;
|
||||
public static getAppsEndpoint(pagingRequest: PagingRequest): string {
|
||||
return `/Apps?pageSize=${pagingRequest.pageSize}&pageNumber=${pagingRequest.pageNumber}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the app by id endpoint.
|
||||
* @param {number} id - The id of the app.
|
||||
* @returns {string} - The app by id endpoint.
|
||||
*/
|
||||
public static getAppByIdEndpoint(baseUrl: string, id: number): string {
|
||||
return `${baseUrl}/Apps/id/${id}`;
|
||||
public static getAppByIdEndpoint(id: number): string {
|
||||
return `/Apps/id/${id}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the apps by ids endpoint.
|
||||
* @returns {string} - The apps by ids endpoint.
|
||||
*/
|
||||
public static getAppsByIdsEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Apps/batch-get`;
|
||||
public static getAppsByIdsEndpoint(): string {
|
||||
return '/Apps/batch-get';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the field by id endpoint.
|
||||
* @param {number} id - The id of the field.
|
||||
* @returns {string} - The field by id endpoint.
|
||||
*/
|
||||
public static getFieldByIdEndpoint(baseUrl: string, id: number): string {
|
||||
return `${baseUrl}/Fields/id/${id}`;
|
||||
public static getFieldByIdEndpoint(id: number): string {
|
||||
return `/Fields/id/${id}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the fields by ids endpoint.
|
||||
* @returns {string} - The fields by ids endpoint.
|
||||
*/
|
||||
public static getFieldsByIdsEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Fields/batch-get`;
|
||||
public static getFieldsByIdsEndpoint(): string {
|
||||
return '/Fields/batch-get';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the fields by app id endpoint.
|
||||
* @param {number} id - The id of the app.
|
||||
* @returns {string} - The fields by app id endpoint.
|
||||
*/
|
||||
public static getFieldsByAppIdEndpoint(baseUrl: string, id: number): string {
|
||||
return `${baseUrl}/Fields/appId/${id}`;
|
||||
public static getFieldsByAppIdEndpoint(id: number): string {
|
||||
return `/Fields/appId/${id}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the file info by id endpoint.
|
||||
* @param {number} recordId - The id of the record.
|
||||
* @param {number} fieldId - The id of the field.
|
||||
* @param {number} fileId - The id of the file.
|
||||
* @returns {string} - The file info by id endpoint.
|
||||
*/
|
||||
public static getFileInfoByIdEndpoint(
|
||||
baseUrl: string,
|
||||
recordId: number,
|
||||
fieldId: number,
|
||||
fileId: number
|
||||
): string {
|
||||
return `${baseUrl}/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}`;
|
||||
return `/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the delete file by id endpoint.
|
||||
* @param {number} recordId - The id of the record.
|
||||
* @param {number} fieldId - The id of the field.
|
||||
* @param {number} fileId - The id of the file.
|
||||
* @returns {string} - The delete file by id endpoint.
|
||||
*/
|
||||
public static getDeleteFileByIdEndpoint(
|
||||
baseUrl: string,
|
||||
recordId: number,
|
||||
fieldId: number,
|
||||
fileId: number
|
||||
): string {
|
||||
return `${baseUrl}/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}/file`;
|
||||
return `/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}/file`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the get file by id endpoint.
|
||||
* @param {number} recordId - The id of the record.
|
||||
* @param {number} fieldId - The id of the field.
|
||||
* @param {number} fileId - The id of the file.
|
||||
* @returns {string} - The file by id endpoint.
|
||||
*/
|
||||
public static getFileByIdEndpoint(
|
||||
baseUrl: string,
|
||||
recordId: number,
|
||||
fieldId: number,
|
||||
fileId: number
|
||||
): string {
|
||||
return `${baseUrl}/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}/file`;
|
||||
return `/Files/recordId/${recordId}/fieldId/${fieldId}/fileId/${fileId}/file`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the save file endpoint.
|
||||
* @returns {string} - The save file endpoint.
|
||||
*/
|
||||
public static getSaveFileEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Files`;
|
||||
public static getSaveFileEndpoint(): string {
|
||||
return '/Files';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the add or update list item endpoint.
|
||||
* @param {number} listId - The id of the list.
|
||||
* @returns {string} - The add or update list item endpoint.
|
||||
*/
|
||||
public static getAddOrUpdateListItemEndpoint(
|
||||
baseUrl: string,
|
||||
listId: number
|
||||
): string {
|
||||
return `${baseUrl}/Lists/id/${listId}/items`;
|
||||
public static getAddOrUpdateListItemEndpoint(listId: number): string {
|
||||
return `/Lists/id/${listId}/items`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the delete list item endpoint.
|
||||
* @param {number} listId - The id of the list.
|
||||
* @param {string} itemId - The id of the list item.
|
||||
* @returns {string} - The delete list item endpoint.
|
||||
*/
|
||||
public static getDeleteListItemEndpoint(
|
||||
baseUrl: string,
|
||||
listId: number,
|
||||
itemId: string
|
||||
): string {
|
||||
return `${baseUrl}/Lists/id/${listId}/itemId/${itemId}`;
|
||||
return `/Lists/id/${listId}/itemId/${itemId}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the get records by app id endpoint.
|
||||
* @param {number} appId - The id of the app.
|
||||
* @returns {string} - The get records by app id endpoint.
|
||||
*/
|
||||
public static getRecordsByAppIdEndpoint(
|
||||
baseUrl: string,
|
||||
appId: number
|
||||
): string {
|
||||
return `${baseUrl}/Records/appId/${appId}`;
|
||||
public static getRecordsByAppIdEndpoint(appId: number): string {
|
||||
return `/Records/appId/${appId}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the get record by id endpoint.
|
||||
* @param {number} appId - The id of the app.
|
||||
* @param {number} recordId - The id of the record.
|
||||
* @returns {string} - The get record by id endpoint.
|
||||
*/
|
||||
public static getRecordByIdEndpoint(
|
||||
baseUrl: string,
|
||||
appId: number,
|
||||
recordId: number
|
||||
): string {
|
||||
return `${baseUrl}/Records/appId/${appId}/recordId/${recordId}`;
|
||||
public static getRecordByIdEndpoint(appId: number, recordId: number): string {
|
||||
return `/Records/appId/${appId}/recordId/${recordId}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the delete record by id endpoint.
|
||||
* @param {number} appId - The id of the app.
|
||||
* @param {number} recordId - The id of the record.
|
||||
* @returns {string} - The delete record by id endpoint.
|
||||
*/
|
||||
public static getDeleteRecordByIdEndpoint(
|
||||
baseUrl: string,
|
||||
appId: number,
|
||||
recordId: number
|
||||
): string {
|
||||
return `${baseUrl}/Records/appId/${appId}/recordId/${recordId}`;
|
||||
return `/Records/appId/${appId}/recordId/${recordId}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the get records by ids endpoint.
|
||||
* @returns {string} - The get records by ids endpoint.
|
||||
*/
|
||||
public static getRecordsByIdsEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Records/batch-get`;
|
||||
public static getRecordsByIdsEndpoint(): string {
|
||||
return '/Records/batch-get';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the query records endpoint.
|
||||
* @returns {string} - The query records endpoint.
|
||||
*/
|
||||
public static getQueryRecordsEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Records/query`;
|
||||
public static getQueryRecordsEndpoint(): string {
|
||||
return '/Records/query';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the add or update record endpoint.
|
||||
* @returns {string} - The add or update record endpoint.
|
||||
*/
|
||||
public static getAddOrUpdateRecordEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Records`;
|
||||
public static getAddOrUpdateRecordEndpoint(): string {
|
||||
return '/Records';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the delete records by ids endpoint.
|
||||
* @returns {string} - The delete records by ids endpoint.
|
||||
*/
|
||||
public static getDeleteRecordsByIdsEndpoint(baseUrl: string): string {
|
||||
return `${baseUrl}/Records/batch-delete`;
|
||||
public static getDeleteRecordsByIdsEndpoint(): string {
|
||||
return '/Records/batch-delete';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the get report by id endpoint.
|
||||
* @param {number} reportId - The id of the report.
|
||||
* @returns {string} - The get report by id endpoint.
|
||||
*/
|
||||
public static getReportByIdEndpoint(
|
||||
baseUrl: string,
|
||||
reportId: number
|
||||
): string {
|
||||
return `${baseUrl}/Reports/id/${reportId}`;
|
||||
public static getReportByIdEndpoint(reportId: number): string {
|
||||
return `/Reports/id/${reportId}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} baseUrl - The base url that will be used to create the get reports by app id endpoint.
|
||||
* @param {number} appId - The id of the app.
|
||||
* @returns {string} - The get reports by app id endpoint.
|
||||
*/
|
||||
public static getReportsByAppIdEndpoint(
|
||||
baseUrl: string,
|
||||
appId: number
|
||||
): string {
|
||||
return `${baseUrl}/Reports/appId/${appId}`;
|
||||
public static getReportsByAppIdEndpoint(appId: number): string {
|
||||
return `/Reports/appId/${appId}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user